00001 #include <Midad/Gui/GuiMainWindow.h>
00002 #include <Midad/Gui/GuiBox.h>
00003 #include <Midad/Gui/GuiLabel.h>
00004 #include <Midad/Gui/GuiTextEntry.h>
00005 #include <Midad/Gui/GuiTable.h>
00006 #include <Midad/Gui/GuiButton.h>
00007 #include <iostream>
00008 #include <string>
00009 #include <sstream>
00010 #include <cstdlib>
00011 using namespace std;
00012
00013 #include <TROOT.h>
00014 #include <TApplication.h>
00015 #include <sigc++/signal.h>
00016 #include <sigc++/bind.h>
00017 #include <sigc++/object_slot.h>
00018 using namespace SigC;
00019
00020 static const char* numbers[] = {
00021 "zero",
00022 "one",
00023 "two",
00024 "three",
00025 "four",
00026 "five",
00027 "six",
00028 "seven",
00029 "eight",
00030 "nine",
00031 0
00032 };
00033
00034 void remove_it(GuiBox* box, GuiTextEntry* gte, GuiTextButton* but[])
00035 {
00036 int i = atoi(gte->GetText());
00037
00038 if (!but[i]) return;
00039
00040 cerr << "Removing " << i << endl;
00041
00042 box->Remove(*but[i]);
00043 but[i] = 0;
00044 box->GetMainWindow()->Layout();
00045 }
00046 void show_it(GuiBox* box, GuiTextEntry* gte, GuiTextButton* but[])
00047 {
00048 int i = atoi(gte->GetText());
00049
00050 if (!but[i]) return;
00051 cerr << "Showing " << i << endl;
00052
00053 box->Show(*but[i]);
00054 box->GetMainWindow()->Layout();
00055 }
00056 void hide_it(GuiBox* box, GuiTextEntry* gte, GuiTextButton* but[])
00057 {
00058 int i = atoi(gte->GetText());
00059
00060 if (!but[i]) return;
00061 cerr << "Hiding " << i << endl;
00062
00063 box->Hide(*but[i]);
00064 box->GetMainWindow()->Layout();
00065 }
00066 void add_it(GuiBox* box, GuiTextEntry* gte, GuiTextButton* but[])
00067 {
00068 int i = atoi(gte->GetText());
00069 if (i < 0 || i > 9) {
00070 cerr << "Number " << i << " not in [0-9]\n";
00071 return;
00072 }
00073
00074 if (but[i]) {
00075 cerr << "Button " << numbers[i] << " already exists\n";
00076 return;
00077 }
00078
00079 cerr << "Adding " << numbers[i] << endl;
00080
00081 but[i] = manage(new GuiTextButton(*box,numbers[i]));
00082 box->Add(*but[i]);
00083 box->Show(*but[i]);
00084 box->GetMainWindow()->Layout();
00085 }
00086
00087 int main (int argc, char *argv[])
00088 {
00089 TApplication theApp("App", &argc, argv);
00090
00091 GuiMainWindow* mw = manage(new GuiMainWindow(100,100));
00092
00093 GuiBox* box = manage(new GuiBox(*mw, kVerticalFrame));
00094 mw->Add(*box);
00095
00096 GuiTextButton* buts[10];
00097 GuiTextEntry* gte;
00098 GuiLabel* lab;
00099
00100 lab = manage(new GuiLabel(*box,"Number to remove"));
00101 box->Add(*lab);
00102 gte = manage(new GuiTextEntry(*box));
00103 box->Add(*gte);
00104 gte->activated.connect(bind(bind(bind(slot(remove_it),buts),gte),box));
00105
00106
00107 lab = manage(new GuiLabel(*box,"Number to hide"));
00108 box->Add(*lab);
00109 gte = manage(new GuiTextEntry(*box));
00110 box->Add(*gte);
00111 gte->activated.connect(bind(bind(bind(slot(hide_it),buts),gte),box));
00112
00113 lab = manage(new GuiLabel(*box,"Number to show"));
00114 box->Add(*lab);
00115 gte = manage(new GuiTextEntry(*box));
00116 box->Add(*gte);
00117 gte->activated.connect(bind(bind(bind(slot(show_it),buts),gte),box));
00118
00119 lab = manage(new GuiLabel(*box,"Number to add (0-9)"));
00120 box->Add(*lab);
00121 gte = manage(new GuiTextEntry(*box));
00122 box->Add(*gte);
00123 gte->activated.connect(bind(bind(bind(slot(add_it),buts),gte),box));
00124
00125
00126 for (int i=0; numbers[i]; ++i) {
00127 buts[i] = manage(new GuiTextButton(*box,numbers[i]));
00128 box->Add(*buts[i]);
00129 }
00130
00131
00132
00133 mw->ShowAll();
00134 mw->ConnectClose(true);
00135 mw->Resize(mw->GetDefaultWidth(),mw->GetDefaultHeight());
00136
00137 theApp.Run();
00138
00139 return 0;
00140 }