gtkIOStream  1.7.0
GTK+ << C++ IOStream operators for GTK+. Now with ORBing, numerical computation, audio client and more ...
Table.H
Go to the documentation of this file.
1 /* Copyright 2000-2018 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 #include <vector>
22 
43 class Table : public Container {
44  short int xStart;
45  short int xEnd;
46  short int yStart;
47  short int yEnd;
48 
49  std::vector<int> regionTemp;
50 
51  guint xPadding;
52  guint yPadding;
53  GtkAttachOptions xOptions;
54  GtkAttachOptions yOptions;
55 public:
56 
60  Table(void){
61  initialise();
62  }
63 
73  Table(short int rows, short int cols, bool homogeneous=true, GtkAttachOptions xOpt=GTK_EXPAND, GtkAttachOptions yOpt=GTK_EXPAND, uint xPad=0, uint yPad=0){
74  initialise(rows, cols, homogeneous, xOpt, yOpt, xPad, yPad);
75  }
76 
87  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){
88  widget=gtk_table_new(rows, cols, homogeneous); // create the table
89  setOptions(xOpt, yOpt); // store the default values
90  setPadding(xPad, yPad);
91  xStart=yStart=0; xEnd=yEnd=1; // default the first placement to the top left
92  }
93 
97  void setHomogeneous(bool homogeneous){
98  gtk_table_set_homogeneous(GTK_TABLE(widget),homogeneous);
99  }
100 
105  void setOptions(GtkAttachOptions xOpt, GtkAttachOptions yOpt){
106  xOptions=xOpt; // store the default values
107  yOptions=yOpt;
108  }
109 
116  void setRegion(short int x_s, short int x_e, short int y_s, short int y_e){
117  xStart=x_s; xEnd=x_e;
118  yStart=y_s; yEnd=y_e;
119  }
120 
126  void placeWidget(GtkWidget *obj, GtkAttachOptions xOpt, GtkAttachOptions yOpt){
127  xOptions=xOpt; yOptions=yOpt;
128  placeWidget(obj);
129  }
130 
139  void placeWidget(GtkWidget *obj){
140  gtk_table_attach(GTK_TABLE(widget), obj, xStart, xEnd, yStart, yEnd, xOptions, yOptions, xPadding, yPadding);
141  // step to the next cell
142  // check we haven't exceeded our boundaries.
143  uint rows, cols; // update the table size
144  getSize(&rows, &cols);
145  xEnd++;
146  if (++xStart==(int)cols){
147  xStart=0; xEnd=1;
148  yEnd++;
149  if (++yStart==(int)rows){
150  yStart=0; yEnd=1;
151  }
152  }
153  }
154 
159  void getSize(uint *rows, uint *cols){
160  if ((gtk_major_version<=2) & (gtk_minor_version<22))
161  g_object_get (GTK_TABLE(widget), "n-rows", rows, "n-columns", cols, NULL);
162  else
163  gtk_table_get_size(GTK_TABLE(widget), rows, cols);
164  }
165 
170  void setPadding(uint xPad, uint yPad){
171  xPadding = xPad; yPadding = yPad;
172  }
173 
178  void resize(uint rows, uint cols){
179  gtk_table_resize(GTK_TABLE(widget), rows, cols);
180  }
181 
191  Table &operator<<(int i){
192  if (regionTemp.size()<4){
193  regionTemp.push_back(i);
194  if (regionTemp.size()==4){
195  setRegion(regionTemp[0], regionTemp[1], regionTemp[2], regionTemp[3]);
196  regionTemp.clear();
197  }
198  } else // a complete region is defined, alter the table region
199  std::cerr<<"Table region is already specified, try dropping this ',int' variable"<<std::endl;
200  return *this;
201  }
202 
212  Table &operator,(int i){
213  return operator<<(i);
214  }
219  Table &operator<<(int *region){
220  setRegion(region[0], region[1], region[2], region[3]);
221  return *this;
222  }
223 
230  Table &operator<<(GtkWidget *obj){
231  placeWidget(obj);
232  return *this;
233  }
234 
239  Table& operator <<(LinkList<GtkWidget *> &ll) {
240  ll.grab(1); ll.prev();
241  for (int i=0;i<ll.getCount();i++)
242  placeWidget(ll.next());
243  }
244 
250  return operator<<(b.getWidget());
251  }
252 
258  return operator<<(b->getWidget());
259  }
260 
266  return operator<<(b.getWidget());
267  }
268 
274  return operator<<(b->getWidget());
275  }
276 
281  Table &operator>>(GtkWidget *obj){
282  gtk_container_remove(GTK_CONTAINER(widget),obj);
283  return *this;
284  }
285 
291  gtk_container_remove(GTK_CONTAINER(widget),c->getWidget());
292  return *this;
293  }
294 
300  gtk_container_remove(GTK_CONTAINER(widget),c.getWidget());
301  return *this;
302  }
303 
309  ll.grab(1); ll.prev();
310  for (int i=0;i<ll.getCount();i++)
311  operator>>(ll.next());
312  }
313 };
314 
315 #endif // TABLE_H_
guint yPadding
The vertical padding between widgets.
Definition: Table.H:52
std::vector< int > regionTemp
This region starts empty, when it gets 4 elements, it sets the region.
Definition: Table.H:49
Table & operator>>(Container &c)
Definition: Table.H:299
void resize(uint rows, uint cols)
Definition: Table.H:178
short int yEnd
The table row location to end attachment.
Definition: Table.H:47
void setPadding(uint xPad, uint yPad)
Definition: Table.H:170
void getSize(uint *rows, uint *cols)
Definition: Table.H:159
void setOptions(GtkAttachOptions xOpt, GtkAttachOptions yOpt)
Definition: Table.H:105
short int xStart
The table column location to start attachment from.
Definition: Table.H:44
short int xEnd
The table column location to end attachment.
Definition: Table.H:45
GtkAttachOptions yOptions
The vertical fill options, one of : GTK_EXPAND, GTK_SHRINK, GTK_FILL.
Definition: Table.H:54
Table & operator<<(GtkWidget *obj)
Definition: Table.H:230
Table & operator<<(int *region)
Definition: Table.H:219
guint xPadding
The horizontal padding between widgets.
Definition: Table.H:51
Table(void)
Definition: Table.H:60
void placeWidget(GtkWidget *obj)
Definition: Table.H:139
unsigned int uint
Definition: Box.H:28
void setHomogeneous(bool homogeneous)
Definition: Table.H:97
GtkAttachOptions xOptions
The horizontal fill options, one of : GTK_EXPAND, GTK_SHRINK, GTK_FILL.
Definition: Table.H:53
Table & operator>>(GtkWidget *obj)
Definition: Table.H:281
Table & operator>>(Container *c)
Definition: Table.H:290
Table & operator,(int i)
Definition: Table.H:212
void setRegion(short int x_s, short int x_e, short int y_s, short int y_e)
Definition: Table.H:116
GtkWidget * widget
The container based widget.
Definition: Widget.H:33
GtkWidget * getWidget(void)
Definition: Widget.H:91
Table & operator<<(int i)
Definition: Table.H:191
Definition: Widget.H:31
void placeWidget(GtkWidget *obj, GtkAttachOptions xOpt, GtkAttachOptions yOpt)
Definition: Table.H:126
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)
Definition: Table.H:87
short int yStart
The table row location to start attachment from.
Definition: Table.H:46
Definition: Table.H:43
Table(short int rows, short int cols, bool homogeneous=true, GtkAttachOptions xOpt=GTK_EXPAND, GtkAttachOptions yOpt=GTK_EXPAND, uint xPad=0, uint yPad=0)
Definition: Table.H:73
gtkIOStream: /tmp/gtkiostream/include/Table.H Source File
GTK+ IOStream  Beta