Initial revision
[silc.git] / apps / silcer / src / silcerbasewin.hh
1 /*
2
3   silcerbasewin.hh 
4
5   Author: Pekka Riikonen <priikone@silcnet.org>
6
7   Copyright (C) 2001 Pekka Riikonen
8
9   This program is free software; you can redistribute it and/or modify
10   it under the terms of the GNU General Public License as published by
11   the Free Software Foundation; version 2 of the License.
12
13   This program is distributed in the hope that it will be useful,
14   but WITHOUT ANY WARRANTY; without even the implied warranty of
15   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16   GNU General Public License for more details.
17
18 */
19
20 #ifndef SILCERBASEWIN_HH
21 #define SILCERBASEWIN_HH
22
23 #include "silcer_gladehelper.hh"
24
25 extern "C" {
26 #define CXX
27 #include "silcincludes.h"
28 #include "clientlibincludes.h"
29 }
30
31 #include <sigc++/signal_system.h>
32 #include <sigc++/object_slot.h>
33 #include <sigc++/marshal.h>
34 #include <glade/glade-xml.h>
35 #include <gtk--/box.h>
36 #include <gtk--/button.h>
37 #include <gtk--/checkbutton.h>
38 #include <gtk--/ctree.h>
39 #include <gtk--/entry.h>
40 #include <gtk--/eventbox.h>
41 #include <gtk--/frame.h>
42 #include <gtk--/label.h>
43 #include <gtk--/menuitem.h>
44 #include <gtk--/optionmenu.h>
45 #include <gtk--/text.h>
46 #include <gtk--/widget.h>
47 #include <gtk--/window.h>
48 #include <gnome--/dialog.h>
49 #include <gnome--/entry.h>
50 #include <gnome--/pixmap.h>
51 #include <gnome--/pixmapmenuitem.h>
52
53 using namespace SigC;
54
55 class SilcerBaseWindow : public SigC::Object
56 {
57 public:
58   SilcerBaseWindow(const char *widgetname);
59   virtual ~SilcerBaseWindow();
60
61   void show() { _thisWindow->show(); }
62   void hide() { _thisWindow->hide(); }
63   virtual void close(); 
64   // Object extender
65   virtual void set_dynamic();
66   // Destruction signal
67   Signal0<void, Marshal<void> > evtDestroy;
68
69 protected:
70   SilcerBaseWindow();
71   // FIXME: Should make this function properly copy
72   SilcerBaseWindow& operator=(const SilcerBaseWindow&) { return *this;}
73   SilcerBaseWindow(const SilcerBaseWindow&) {}
74   
75 public:
76   // Helper functions
77
78   Gtk::Button *getButton(const char *name)
79   { return SilcerGetWidget<Gtk::Button>(_thisGH, name); }
80
81   Gtk::CheckButton *getCheckButton(const char *name)
82   { return SilcerGetWidget<Gtk::CheckButton>(_thisGH, name); }
83
84   Gtk::CTree *getCTree(const char *name)
85   { return SilcerGetWidget<Gtk::CTree>(_thisGH, name); }
86
87   Gtk::Entry *getEntry(const char *name)
88   { return SilcerGetWidget<Gtk::Entry>(_thisGH, name); }
89
90   Gtk::EventBox *getEventBox(const char *name)
91   { return SilcerGetWidget<Gtk::EventBox>(_thisGH, name); }
92
93   Gtk::Frame *getFrame(const char *name)
94   { return SilcerGetWidget<Gtk::Frame>(_thisGH, name); }
95
96   Gtk::HBox *getHBox(const char *name)
97   { return SilcerGetWidget<Gtk::HBox>(_thisGH, name); }
98
99   Gnome::Entry *getGEntry(const char *name)
100   { return SilcerGetWidget<Gnome::Entry>(_thisGH, name); }
101
102   Gtk::Label *getLabel(const char *name)
103   { return SilcerGetWidget<Gtk::Label>(_thisGH, name); }
104
105   Gtk::MenuItem *getMenuItem(const char *name)
106   { return SilcerGetWidget<Gtk::MenuItem>(_thisGH, name); }
107
108   Gtk::OptionMenu *getOptionMenu(const char *name)
109   { return SilcerGetWidget<Gtk::OptionMenu>(_thisGH, name); }
110
111   Gnome::Pixmap *getPixmap(const char *name)
112   { return SilcerGetWidget<Gnome::Pixmap>(_thisGH, name); }
113
114   Gtk::PixmapMenuItem *getPixmapMenuItem(const char *name)
115   { return SilcerGetWidget<Gtk::PixmapMenuItem>(_thisGH, name); }
116
117   Gtk::Text *getText(const char *name)
118   { return SilcerGetWidget<Gtk::Text>(_thisGH, name); }
119
120   Gtk::VBox *getVBox(const char *name)
121   { return SilcerGetWidget<Gtk::VBox>(_thisGH, name); }
122
123   template <class T> T *getWidget(const char *name)
124   { return SilcerGetWidget<T>(_thisGH, name); }
125
126 protected:
127   Gtk::Window *_thisWindow;
128
129 private:
130   GladeXML *_thisGH;
131 };
132
133 class SilcerBaseDialog : public SilcerBaseWindow
134 {
135 public:
136   SilcerBaseDialog(const char *widgetname, gboolean close_hides = false);
137   virtual ~SilcerBaseDialog() {}
138
139 protected:
140   Gnome::Dialog *_thisDialog;
141   gboolean on_Dialog_close();
142 };
143
144 class SilcerBaseWidget : public SigC::Object
145 {
146 public:
147   SilcerBaseWidget(const char* widgetname, const char* filename);
148   virtual ~SilcerBaseWidget();
149   void show() { _thisWidget->show(); }
150   void hide() { _thisWidget->hide(); }
151   Gtk::Widget* get_this_widget() { return _thisWidget; }
152   virtual void close(); 
153   // Object extender
154   virtual void set_dynamic();
155   // Destruction signal
156   Signal0<void, Marshal<void> > evtDestroy;
157 protected:
158   SilcerBaseWidget();
159   // FIXME: Should make this function properly copy
160   SilcerBaseWidget& operator=(const SilcerBaseWidget&) { return *this;}
161   SilcerBaseWidget(const SilcerBaseWidget&) {}
162 public:
163   // Helper functions
164
165   Gtk::Button *getButton(const char *name)
166   { return SilcerGetWidget<Gtk::Button>(_thisGH, name); }
167
168   Gtk::CheckButton *getCheckButton(const char *name)
169   { return SilcerGetWidget<Gtk::CheckButton>(_thisGH, name); }
170
171   Gtk::Entry *getEntry(const char *name)
172   { return SilcerGetWidget<Gtk::Entry>(_thisGH, name); }
173
174   Gtk::Label *getLabel(const char *name)
175   { return SilcerGetWidget<Gtk::Label>(_thisGH, name); }
176
177   Gtk::MenuItem *getMenuItem(const char *name)
178   { return SilcerGetWidget<Gtk::MenuItem>(_thisGH, name); }
179
180   Gtk::OptionMenu *getOptionMenu(const char *name)
181   { return SilcerGetWidget<Gtk::OptionMenu>(_thisGH, name); }
182
183   Gtk::PixmapMenuItem *getPixmapMenuItem(const char *name)
184   { return SilcerGetWidget<Gtk::PixmapMenuItem>(_thisGH, name); }
185
186   Gtk::Text *getText(const char *name)
187   { return SilcerGetWidget<Gtk::Text>(_thisGH, name); }
188
189   template <class T> T *getWidget(const char *name)
190   { return SilcerGetWidget<T>(_thisGH, name); }
191
192 protected:
193   Gtk::Widget *_thisWidget;
194
195 private:
196   GladeXML *_thisGH;
197 };
198
199 #endif /* SILCERBASEWIN_HH */