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
Table.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 TABLE_H_
18 #define TABLE_H_
19 
20 #include "Container.H"
21 
41 class Table : public Container {
42  short int xStart;
43  short int xEnd;
44  short int yStart;
45  short int yEnd;
46  guint xPadding;
47  guint yPadding;
48  GtkAttachOptions xOptions;
49  GtkAttachOptions yOptions;
50 public:
51 
55  Table(void){
56  initialise();
57  }
58 
68  Table(short int rows, short int cols, bool homogeneous=true, GtkAttachOptions xOpt=GTK_EXPAND, GtkAttachOptions yOpt=GTK_EXPAND, uint xPad=0, uint yPad=0){
69  initialise(rows, cols, homogeneous, xOpt, yOpt, xPad, yPad);
70  }
71 
82  void initialise(short int rows=2, short int cols=2, bool homogeneous=true, GtkAttachOptions xOpt=GTK_FILL, GtkAttachOptions yOpt=GTK_FILL, uint xPad=0, uint yPad=0){
83  widget=gtk_table_new(rows, cols, homogeneous); // create the table
84  setOptions(xOpt, yOpt); // store the default values
85  setPadding(xPad, yPad);
86  xStart=yStart=0; xEnd=yEnd=1; // default the first placement to the top left
87  }
88 
92  void setHomogeneous(bool homogeneous){
93  gtk_table_set_homogeneous(GTK_TABLE(widget),homogeneous);
94  }
95 
100  void setOptions(GtkAttachOptions xOpt, GtkAttachOptions yOpt){
101  xOptions=xOpt; // store the default values
102  yOptions=yOpt;
103  }
104 
111  void setRegion(short int x_s, short int x_e, short int y_s, short int y_e){
112  xStart=x_s; xEnd=x_e;
113  yStart=y_s; yEnd=y_e;
114  }
115 
121  void placeWidget(GtkWidget *obj, GtkAttachOptions xOpt, GtkAttachOptions yOpt){
122  xOptions=xOpt; yOptions=yOpt;
123  placeWidget(obj);
124  }
125 
134  void placeWidget(GtkWidget *obj){
135  gtk_table_attach(GTK_TABLE(widget), obj, xStart, xEnd, yStart, yEnd, xOptions, yOptions, xPadding, yPadding);
136  // step to the next cell
137  // check we haven't exceeded our boundaries.
138  uint rows, cols; // update the table size
139  getSize(&rows, &cols);
140  xEnd++;
141  if (++xStart==(int)cols){
142  xStart=0; xEnd=1;
143  yEnd++;
144  if (++yStart==(int)rows){
145  yStart=0; yEnd=1;
146  }
147  }
148  }
149 
154  void getSize(uint *rows, uint *cols){
155  if ((gtk_major_version<=2) & (gtk_minor_version<22))
156  g_object_get (GTK_TABLE(widget), "n-rows", rows, "n-columns", cols, NULL);
157  else
158  gtk_table_get_size(GTK_TABLE(widget), rows, cols);
159  }
160 
165  void setPadding(uint xPad, uint yPad){
166  xPadding = xPad; yPadding = yPad;
167  }
168 
173  void resize(uint rows, uint cols){
174  gtk_table_resize(GTK_TABLE(widget), rows, cols);
175  }
176 
181  Table &operator<<(int *region){
182  setRegion(region[0], region[1], region[2], region[3]);
183  return *this;
184  }
185 
192  Table &operator<<(GtkWidget *obj){
193  placeWidget(obj);
194  return *this;
195  }
196 
201  Table& operator <<(LinkList<GtkWidget *> &ll) {
202  ll.grab(1); ll.prev();
203  for (int i=0;i<ll.getCount();i++)
204  placeWidget(ll.next());
205  }
206 
207  Table &operator>>(GtkWidget *obj){
208  gtk_container_remove(GTK_CONTAINER(widget),obj);
209  return *this;
210  }
211 };
212 
213 #endif // TABLE_H_