GTK+ IOStream  Beta
<< GTK+ >> add C++ IOStream operators to GTK+. Now with extra abilities ... like network serialisation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Box.H
Go to the documentation of this file.
1 /* Copyright 2000-2013 Matt Flax <flatmax@flatmax.org>
2  This file is part of GTK+ IOStream class set
3 
4  GTK+ IOStream is free software; you can redistribute it and/or modify
5  it under the terms of the GNU General Public License as published by
6  the Free Software Foundation; either version 2 of the License, or
7  (at your option) any later version.
8 
9  GTK+ IOStream is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  GNU General Public License for more details.
13 
14  You have received a copy of the GNU General Public License
15  along with GTK+ IOStream
16  */
17 #ifndef BOX_H_
18 #define BOX_H_
19 
20 #include <iostream>
21 using namespace std;
22 #include <gtk/gtk.h>
23 
24 #include <mffm/LinkList.H>
25 #include "Container.H"
26 
27 #ifdef WIN32
28 typedef unsigned int uint;
29 #endif
30 
33 class BoxIS {
34  //bool defaultVal=false;
35  //#define defaultVal false ///< The default value
42 
45  void setDefaults(void){
46  expandDefault=fillDefault=false; //defaultVal; // setup the default behaviour
47  startDefault=true;
48  }
49 public:
51  bool expand;
53  bool fill;
55  bool start;
56 
59  BoxIS(void) {
60  setDefaults(); // load up the default values
61  }
62 
67  BoxIS(bool expandIn, bool fillIn) {
68  setDefaults(); // load up the default values
69  expand=expandIn;
70  fill=fillIn;
71  }
72 
77  BoxIS(bool expandIn, bool fillIn, bool startIn) {
78  setDefaults(); // load up the default values
79  expand=expandIn;
80  fill=fillIn;
81  start=startIn;
82  }
83 
86  void reset(void) {
87  expand=expandDefault;
88  fill=fillDefault;
89  start=startDefault;
90  }
91 
95  void setDefaultStart(bool startIn){
96  startDefault=startIn;
97  start=startDefault;
98  }
99 
103  void setDefaultExpand(bool expandIn){
104  expandDefault=expandIn;
105  expand=expandDefault;
106  }
107 
111  void setDefaultFill(bool fillIn){
112  fillDefault=fillIn;
113  fill=fillDefault;
114  }
115 
119  expand=bis.expand;
120  fill=bis.fill;
121  start=bis.start;
122  return *this;
123  }
124 
127  BoxIS& operator=(const BoxIS bis) {
128  expand=bis.expand;
129  fill=bis.fill;
130  start=bis.start;
131  return *this;
132  }
133 
136  void dump(void){
137  cout<<"BoxIS::expand="<<expand<<", fill="<<fill<<", start="<<start<<endl;
138  }
139 };
140 
141 /*/// The default values of expand and fill
142 bool BoxIS::defaultVal=false;
143 */
144 
148 class Box : public BoxIS, public Container {
149 protected:
150 
157  virtual void pack(GtkWidget *obj) {
158  if (start)
159  gtk_box_pack_start (GTK_BOX (widget), obj, expand, fill, 0);
160  else
161  gtk_box_pack_end (GTK_BOX (widget), obj, expand, fill, 0);
162  BoxIS::reset(); // reset the starting values
163  }
164 public:
165 
168  Box(void) : BoxIS() {
169  }
170 
171 // /** \brief destructor destroys the widget to neatly cleanup.
172 // */
173 // virtual ~Box(void){
174 // }
175 
182  this->BoxIS::operator=((const BoxIS)bis);
183  return *this;
184  }
185 
186 // /** Align the box : this is a bad idea, as it requires
187 // \param a The alignment class
188 // \return Returns a Box reference for further processing.
189 // */
190 // Box& operator<<(Alignment &a) {
191 // Box *b=static_cast<Box*>(&a);
192 // return *this<<BoxIS(true,true,true)<<b->getWidget();
193 // }
194 
199  Box& operator <<(Box& b) {
200  return Box::operator<<(b.getWidget());
201  }
202 
207  Box& operator <<(Box * b) {
208  return Box::operator<<(b->getWidget());
209  }
210 
215  Box& operator <<(Container& b) {
216  return Box::operator<<(b.getWidget());
217  }
218 
223  Box& operator <<(Container * b) {
224  return Box::operator<<(b->getWidget());
225  }
226 
231  Box& operator <<(GtkWidget * b) {
233  return *this;
234  }
235 
240  Box& operator <<(LinkList<GtkWidget *> &ll) {
242  return *this;
243  }
244 
250  Box& operator >>(GtkWidget * b) {
252  return *this;
253  }
254 
260  Box& operator >>(Container * b) {
262  return *this;
263  }
264 
270  Box& operator >>(Container &b) {
272  return *this;
273  }
274 
280  void connectAfter(const char *event, GCallback callback, gpointer data){
281  g_signal_connect_after(widget, event, callback, data);
282  }
283 
284 // /*! Unpack an unknown widget from the box.
285 // Note that removal of the widget can destroy it if the only reference is the box.
286 // \return Returns the widget removed from the box
287 // */
288 // GtkWidget* removeUnknownWidget() {
289 // GtkWidget* wdgt=gtk_container_get_focus_child((GtkContainer *)this->getWidget());
290 // *this>>wdgt;
291 // return wdgt;
292 // }
293 
296  Box& operator=(const Box b){
297  //widget=b.getWidget();
298  Container::operator=(b);
299  BoxIS::operator=(b);
300  return *this;
301  }
302 
303 };
304 
307 class VBox : public Box {
308 public:
311  VBox() {
312  widget = gtk_vbox_new (FALSE, 0);
313  }
314 };
315 
318 class HBox : public Box {
319 public:
322  HBox() {
323  widget = gtk_hbox_new (FALSE, 0);
324  }
325 };
326 
329 class HBBox : public HBox {
330 public:
333  HBBox() {
334  widget = gtk_hbutton_box_new ();
335  }
336 };
337 
340 class VBBox : public VBox {
341 public:
344  VBBox() {
345  widget = gtk_vbutton_box_new ();
346  }
347 };
348 #endif //BOX_H_