1 /*
2  * ===========================
3  * VDK Visual Develeopment Kit
4  * Version 0.4
5  * October 1998
6  * ===========================
7  *
8  * Copyright (C) 1998, Mario Motta
9  * Developed by Mario Motta <mmotta@guest.net>
10  *
11  * This library is free software; you can redistribute it and/or
12  * modify it under the terms of the GNU Library General Public
13  * License as published by the Free Software Foundation; either
14  * version 2 of the License, or (at your option) any later version.
15  *
16  * This library is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
19  * Library General Public License for more details.
20  *
21  * You should have received a copy of the GNU Library General Public
22  * License along with this library; if not, write to the Free Software
23  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
24  * 02111-1307, USA.
25  */
26 
27 #ifndef FORMS_H
28 #define FORMS_H
29 
30 #include <vdk/application.h>
31 #include <vdk/dlist.h>
32 #include <vdk/vdktypes.h>
33 #include <vdk/rawobj.h>
34 #include <vdk/vdkprops.h>
35 #include <vdk/vdkutils.h>
36 #include <vdk/vdkustring.h>
37 #include <vdk/vdkobj.h>
38 
39 class VDKObject;
40 
41 class VDKColor;
42 class VDKForm;
43 class VDKFont;
44 class VDKBox;
45 class VDKRawPixmap;
46 
47 typedef VDKList<VDKForm> ChildList;
48 typedef VDKListiterator<VDKForm> ChildListIterator;
49 
50 typedef VDKList<VDKObject> ObjectList;
51 typedef VDKListiterator<VDKObject> ObjectListIterator;
52 
53 
54 /*!
55   \class VDKForm
56   \brief VDKForm widgets, generally the outermost widget container.
57 
58   This class provides a common interface with GTK+ windows that are
59   here called "Forms". VDKForm provides common functionalities for all
60   derived classes.
61 
62   <center>
63   \htmlonly
64   <img align=center src="vdkform.gif"><br>
65   \endhtmlonly
66   </center>
67  */
68 
69 class VDKForm : public VDKObject
70 {
71 
72  private:
73   /*!
74     copy and assignement prohibited
75   */
VDKForm(VDKForm &)76   VDKForm(VDKForm& ):VDKObject( NULL) {}
77   /*!
78     copy and assignement prohibited
79   */
80   VDKForm& operator=(VDKForm& ) { return *this; }
81 
82 protected:
83   /*!
84     \internal
85   */
86   void SignalsConnect();
87   /*!
88     owner application address
89   */
90   VDKApplication* app;
91   /*!
92     child and child garbage list
93   */
94   ChildList childs,childsGarbage;
95   /*!
96     underlaying gtk+ window
97   */
98   GtkWidget *window;
99   /*!
100     default inner box
101   */
102   VDKBox* box;
103   /*!
104     modal flag
105   */
106   bool isModal;
107   /*!
108     never showed flag
109   */
110   bool never_showed;
111   /*
112     position storage
113   */
114   VDKPoint _oldPos;
115   /*!
116     size storage
117   */
118   VDKPoint _oldSize;
119   /*
120     initial position storage
121   */
122   VDKPoint _iniPos;
123   /*!
124     initial size storage
125   */
126   VDKPoint _iniSize;
127   /*!
128     counts how many modal childs we have
129     should be always max 1
130   */
131   int modalCount;
132   /*
133     \internal
134   */
135   static int ConfigureEvent(GtkWidget* ,
136 			     GdkEventConfigure* ev,
137 			     gpointer gp);
138   /*
139     \internal
140   */
141 //#if defined _WIN32 || defined _WIN64
142   static gboolean WindowStateEvent(GtkWidget *widget, GdkEventWindowState *event, gpointer gp);
143 //#else
144 //  static gboolean WindowStateEvent(GtkWidget *widget, GdkEventWindowState *event);
145 //#endif
146   /*
147     \internal
148   */
149   static int DestroyEvent (GtkWidget*, gpointer gp);
150   /*
151     \internal
152   */
153   static int DeleteEvent(GtkWidget* , GdkEvent* , gpointer gp);
154   /*
155     \internal
156   */
157   static int ExposeEvent(GtkWidget* ,
158 			  GdkEventExpose* ev, gpointer gp);
159   /*
160     \internal
161   */
162   static void RealizeSignal(GtkWidget* , gpointer gp);
163   /*
164     \internal
165   */
166   static int MapEvent(GtkWidget* , GdkEvent* ev ,gpointer gp);
167   /*
168     \internal
169   */
170   static int UnmapEvent(GtkWidget* , GdkEvent* ev ,gpointer gp);
171   /*
172     \internal
173   */
174   static int FocusInEvent(GtkWidget* , GdkEvent* ev ,gpointer gp);
175   /*
176     \internal
177   */
178   static int FocusOutEvent(GtkWidget* , GdkEvent* ev ,gpointer gp);
179   /*
180     \internal
181   */
182   static void SizeAllocateSignal(GtkWidget      *widget,
183 			    GtkAllocation  *allocation,
184 			    gpointer gp);
185 public:
186   /*
187     properties
188   */
189   VDKReadWriteValueProp<VDKForm,bool> Visible;
190   VDKReadWriteValueProp<VDKForm,VDKUString> Title;
191   VDKReadWriteValueProp<VDKForm,VDKPoint> Position;
192   VDKReadWriteValueProp<VDKForm,bool> Iconized;
193   VDKReadWriteValueProp<VDKForm,VDKRawPixmap*> BackgroundPixmap;
194   VDKReadWriteValueProp<VDKForm,VDKObject*> FocusWidget;
195   VDKReadWriteValueProp<VDKForm,bool> Sizeable;
196 
197   /*
198     constructors
199   */
200   /*!
201     constructor, makes a main form, application child
202     \param app the application that owns the form
203     \param title
204     \param mode as inner box should be, either vertical (v_box)
205     or horizontal (h_box)
206     \param display display type can be one of the following:
207     - GTK_WINDOW_TOPLEVEL
208     - GTK_WINDOW_DIALOG
209     - GTK_WINDOW_POPUP
210     behavio_ vdksdl_form_hur depends on window manager
211   */
212   VDKForm(VDKApplication* app,
213 	  char* title = (char*) NULL,
214 	  int mode = v_box,
215 	  GtkWindowType display = GTK_WINDOW_TOPLEVEL);
216   /*!
217     constructor, makes a child form
218     \param owner the form that owns the child form
219     \param title
220     \param mode as inner box should be, either vertical (v_box)
221     or horizontal (h_box)
222     \param display display type can be one of the following:
223     - GTK_WINDOW_TOPLEVEL
224     - GTK_WINDOW_DIALOG
225     - GTK_WINDOW_POPUP
226     behaviour depends on window manager
227   */
228   VDKForm(VDKForm* owner,
229 	  char* title = (char*) NULL,
230 	  int mode = v_box,
231 	  GtkWindowType display = GTK_WINDOW_TOPLEVEL);
232   /*!
233     \internal
234   */
235   VDKForm(VDKApplication* app,
236 	  GtkWidget* wid,
237 	  char* title = (char*) NULL);
238 
239 #if HAVE_GNOME
240   /*!
241     \internal
242   */
243 VDKForm(VDKForm* owner,
244 	 GtkWidget* wid,
245 	 char* title = (char*) NULL);
246 #endif
247 /*!
248   Destructor
249  */
250  virtual ~VDKForm();
251  /*!
252    Explicitely destroy a form.
253  */
254  bool                     Destroy();
255  /*!
256    \internal
257  */
isA()258  virtual int              isA() { return form_class; }
259  /*!
260    return inner box
261  */
Box()262  VDKBox*                   Box() { return box; }
263  /*!
264    Shows form.
265    \param pos indicates initial form position, can be one of the
266    following:
267    - GTK_WIN_POS_NONE
268    - GTK_WIN_POS_CENTER
269    - GTK_WIN_POS_MOUSE
270    - GTK_WIN_POS_CENTER_ALWAYS
271  */
272  virtual void              Show(GtkWindowPosition pos = GTK_WIN_POS_NONE);
273  /*!
274    Hides form
275  */
276  virtual void              Hide();
277  /*!
278    Shows a form in modal behaviour
279    \param pos indicates initial form position, can be one of the
280    following:
281    - GTK_WIN_POS_NONE
282    - GTK_WIN_POS_CENTER
283    - GTK_WIN_POS_MOUSE
284    - GTK_WIN_POS_CENTER_ALWAYS
285  */
286  virtual void              ShowModal(GtkWindowPosition pos = GTK_WIN_POS_NONE);
287  /*!
288    Return if a showed window is modal or not
289  */
IsModal()290  bool                      IsModal() { return isModal; }
291  /*!
292    Add an object to the form.
293    Tip: <obj> will be actually added to inner box
294    same as form->Box()->Add();
295    \param obj the object to be added
296    \param justify where the object wil be added, can be:
297    - l_justify packed to end (appended)
298    - r_justify packed to start (prepended)
299    \param expand if true objet will expand from container center
300    \param fill if true object will fill all available space
301    \param padding how many pixels are left around object
302  */
303  virtual void Add(VDKObject* obj, int justify = l_justify,
304 		  int expand = TRUE, int fill = TRUE ,
305 		  int padding = 1);
306  /*!
307    \internal
308  */
309  void              AddChild(VDKForm* child);
310  /*!
311    Return form owner
312    Tip: returns NULL id <this> is main form
313   */
Owner()314  VDKForm*                 Owner() { return owner; }
315  /*!
316    \internal
317  */
318  void                       RemoveChild(VDKForm* child);
319  /*!
320    Placeholder for subclasses.
321    User should override this returning a false (don't close)
322    or true (close) value.
323  */
324  virtual bool               CanClose(void);
325  /*!
326    Closes the form, if form is main application form
327    it quits application as well. Call CanClose()
328    before, if it returns true closes the form otherwise
329    form won't be closed.
330  */
331  virtual void               Close(void);
332 
333  // this makes a VDKForm an abstract class
334  /*!
335    Must be overridden by subclasses, in this
336    method user fills form with useful widgets
337  */
338  virtual void               Setup(void) = 0;
339 
SetTitle(VDKUString title)340  void                       SetTitle(VDKUString title)
341    { gtk_window_set_title(GTK_WINDOW(window),(char*) title); }
342 
GetTitle(void)343  VDKUString                  GetTitle(void)
344    {
345      VDKUString title = Title;
346      return title;
347    }
348 
Window()349  GtkWidget*                  Window() { return window; }
350 
Application()351  VDKApplication*             Application() { return app; }
352 
353  void                        CloseChilds(void);
354 
355  void                        CollectGarbage();
356 
Objects(void)357  ObjectList& Objects(void) { return items; }
358 
Childs(void)359  ChildList&                  Childs(void) { return childs; }
ChildsGarbage(void)360  ChildList&                  ChildsGarbage(void)
361    { return childsGarbage; }
362  /*!
363    Raises form
364  */
365  void                 Raise();
366  /*!
367    Lower form
368  */
369  void                 Lower();
370 
SetVisible(bool flag)371  void                 SetVisible(bool flag)
372    {
373      if(flag) Show();
374      else Hide();
375    }
GetVisible()376  bool                        GetVisible()
377    { return GTK_WIDGET_VISIBLE(window); }
378 
SetSizeable(bool flag)379  void                 SetSizeable(bool flag)
380    {
381       gtk_window_set_resizable(GTK_WINDOW(window), flag);
382    }
GetSizeable()383  bool                    GetSizeable() {
384       gboolean gb = gtk_window_get_resizable(GTK_WINDOW(window));
385       return (gb == TRUE);
386    }
387  /*
388   */
389  void SetIcon(VDKRawPixmap*);
390  void SetIconName(char* name);
391  void SetPosition(VDKPoint p);
392  VDKPoint GetPosition();
393  VDKPoint GetInitialPosition();
394  VDKPoint GetInitialSize();
395  //
396  void SetDefaultSize(VDKPoint p);
SetFormSize(VDKPoint p)397  void SetFormSize(VDKPoint p)
398    { if(window) gdk_window_resize(window->window,p.X(),p.Y()); }
399  bool GetIconized();
400  void SetIconized(bool flag);
401  void SetBackgroundPixmap(VDKRawPixmap* pix);
402  void SetFocusWidget(VDKObject* focuswidget);
403  /*
404 event response (place holders for subclasses)
405 */
406  static void  ButtonPressEvent(GtkWidget* ,
407 			       GdkEventButton* ev,
408 			       gpointer gp);
409 
410  virtual void OnExpose( VDKForm* sender, GdkRectangle area);
411  virtual void OnChildClosing(VDKForm* child);
412  virtual void OnShow(VDKForm* sender);
413  virtual void OnRealize(VDKForm* sender);
414  virtual void OnConfigure(VDKForm* sender);
415  virtual void OnMove(VDKForm* sender);
416  virtual void OnResize(VDKForm* sender, VDKPoint& size);
417  virtual void OnIconize(VDKForm* sender);
418  virtual void OnMaximize(VDKForm* sender);
419  virtual void OnRestore(VDKForm* sender);
420  virtual void OnFormActivate(VDKForm* sender, bool in_out);
421 /*
422   Answers to a MS Windows-like message.
423   Not very useful, just added  to facilitate
424   porting my neural lib from MS Windows to VDK.
425   Casual user should override in his own forms.
426   */
427  virtual int
WindozeMessage(int,unsigned int,long unsigned int)428      WindozeMessage(int /*msg*/,
429 		    unsigned int /*wParam*/,
430 		    long unsigned int /*lParam*/)
431      {
432 	 return 0;
433      }
434 };
435 
436 #endif
437 
438 
439 
440