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
SelectionTest2.C
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 #include "gtkInterface.H"
18 #include "Selection.H"
19 
20 #include "xpm/play.xpm"
21 
22 static void quit(void *wid, gpointer data) {
23  gtk_main_quit();
24 }
25 
26 static void selectionCallback(void *wid, gpointer data){
27  char text[128];
28  Selection *s=(Selection *)data;
29  s->getSelection(text);
30  std::cout<<"you selected : "<<text<<std::endl;
31 }
32 
33 int main(int argc, char *argv[]) {
34  gtk_init( &argc, &argv );
35 
36  GtkInterface topWindow;
37  HBox hBox;
38 
39  Selection selection; // construct a Selection class
40  SelectionColumn sct("text column", 0); // create the columns class with a new column which handles text
41  sct<<pair<string*, GtkCellRendererText*>(new string("text"), GTK_CELL_RENDERER_TEXT(gtk_cell_renderer_text_new())); // create a column for text
42  SelectionColumn scp("pixmap col", 1); // create the pixmap column
43  scp<<pair<string*, GtkCellRendererPixbuf*>(new string("pixbuf"), GTK_CELL_RENDERER_PIXBUF(gtk_cell_renderer_pixbuf_new())); // create a second column which handles pixbufs
44  selection<<&sct; // setup the Selection with the columns
45  selection<<&scp; // setup the Selection with the columns
46 
47  selection.setSelectionCallback(G_CALLBACK(selectionCallback)); // add the callback
48 
49  GdkPixbuf *testPixBuf = gdk_pixbuf_new_from_xpm_data(static_cast<const char**>(playXPM)); // get the pixbuf
50 
51  selection.grab(1); // get the first column
52  selection<<"test col 1"; // add some text to the column
53  selection.grab(2); // get the second column - the pixbuf column
54  selection<<testPixBuf; // add the pix buf to the column
55 
56  // add a third row with both text and a pixbuf
57  selection.grab(1); // get the text column
58  selection<<"test row 2";
59  selection.grab(2); // get the second pixbuf
60  selection.add(testPixBuf, true); // add to the same row
61 
62  // or add the pixbuf first and then the text
63  selection.grab(2); // get the second column - the pixbuf column
64  selection.add(testPixBuf); // add to the same row
65  selection.grab(1); // get the second column - the pixbuf column
66  selection.add("test row 3", true);
67 
68  selection.show();
69 
70  selection.grab(1); // ensure callbacks are referencing the first column
71 
72 
73  hBox<<BoxIS(TRUE, TRUE)<<selection.getWidget(); // the 'getWidget' method is present in most classses - in future, Selection will find a way to get rid of the 'getWidget' requirement.
74  hBox.show();
75  topWindow<< hBox;
76 
77  gtk_main();
78 }