1 /*
2  * This file is part of gtkD.
3  *
4  * gtkD is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU Lesser General Public License as published by
6  * the Free Software Foundation; either version 3 of the License, or
7  * (at your option) any later version.
8  *
9  * gtkD 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 Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public License
15  * along with gtkD; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA
17  */
18 
19 module TestTreeView1;
20 
21 //debug = trace;
22 
23 private import gtk.VBox;
24 
25 private import gobject.Value;
26 
27 private import gtk.Image;
28 private import gtk.TreeView;
29 private import gtk.TreeStore;
30 private import gtk.TreePath;
31 private import gtk.TreeViewColumn;
32 private import gtk.TreeIter;
33 private import gtk.TreeSelection;
34 private import gtk.CellRendererPixbuf;
35 private import gtk.CellRendererText;
36 private import gtk.ScrolledWindow;
37 private import gdk.Pixbuf;
38 private import glib.Str;
39 version(Tango) private import tango.io.Stdout;
40 version(Tango) private import tango.stdc.stdio;
41 else private import std.stdio;
42 
43 /**
44  * This tests the gtkD tree widget
45  */
46 public class TestTreeView1 : VBox
47 {
48 //	enum columns
49 //	{
50 //		gtkDObject = pixbufGetType(),
51 //		desc = gtkDType.STRING,
52 //	}
53 
54 	Image image;
55 	Pixbuf pixbuf;
56 	Pixbuf pixbufTest;
57 
58 	TreeStore testTreeStore1;
59 	TreeStore testTreeStore2;
60 
61 	this()
62 	{
63 
64 		debug(trace) version(Tango) Stdout("TestTreeView1.this 1").newline;
65 		else writefln("TestTreeView1.this 1");
66 		super(false, 0);
67 		debug(trace) version(Tango) Stdout("TestTreeView1.this 2").newline;
68 		else writefln("TestTreeView1.this 2");
69 
70 		pixbuf = new Pixbuf(greenClass_xpm);
71 		debug(trace) version(Tango) Stdout("TestTreeView1.this 2.1").newline;
72 		else writefln("TestTreeView1.this 2.1");
73 		pixbufTest = new Pixbuf(book_closed_xpm);
74 		debug(trace) version(Tango) Stdout("TestTreeView1.this 2.2").newline;
75 		else writefln("TestTreeView1.this 2.2");
76 		image = new Image(pixbufTest);
77 
78 		debug(trace) version(Tango) Stdout("TestTreeView1.this 3").newline;
79 		else writefln("TestTreeView1.this 3");
80 		TreeView treeView1 = setup1();
81 		populate(testTreeStore1);
82 
83 		debug(trace) version(Tango) Stdout("TestTreeView1.this 4").newline;
84 		else writefln("TestTreeView1.this 4");
85 		TreeView treeView2 = setup2();
86 		populate(testTreeStore2);
87 
88 		debug(trace) version(Tango) Stdout("TestTreeView1.this 5").newline;
89 		else writefln("TestTreeView1.this 5");
90 		treeView2.addOnMoveCursor(&moveCursorCallback);
91 		packStart(image, false, false, 1);
92 		ScrolledWindow sw = new ScrolledWindow(null, null);
93 		sw.add(treeView1);
94 		packStart(sw, true, true, 1);
95 		sw = new ScrolledWindow(null, null);
96 		sw.add(treeView2);
97 		packStart(sw, true, true, 1);
98 
99 		debug(trace) version(Tango) Stdout("TestTreeView1.this 6").newline;
100 		else writefln("TestTreeView1.this 6");
101 		//addWithViewport(treeView);
102 
103 
104 
105 	}
106 
107 	bool moveCursorCallback(GtkMovementStep step, int i, TreeView tree)
108 	{
109 		TreeIter iter = tree.getSelectedIter();
110 		iter.setModel(tree.getModel());
111 		Value v = new Value();
112 		iter.getValue(1, v);
113 		debug(trace) version(Tango) Stdout("cursor on {}", v).newline;
114 		else writefln("cursor on %s", v);
115 		return false;
116 	}
117 
118 
119 
120 	void populate(TreeStore treeStore)
121 	{
122 		TreeIter iterChild;
123 		TreeIter iterTop = treeStore.createIter();
124 		treeStore.setValue(iterTop, 0, new Pixbuf(package_xpm) );
125 		treeStore.setValue(iterTop, 1, "Icon for packages" );
126 
127 		iterChild = treeStore.append(iterTop);
128 		treeStore.setValue(iterChild, 0,new Pixbuf(greenTemplate_xpm) );
129 		treeStore.setValue(iterChild, 1, "Icon for templates" );
130 
131 		iterChild = treeStore.append(iterTop);
132 		treeStore.setValue(iterChild, 0, new Pixbuf(greenInterface_xpm) );
133 		treeStore.setValue(iterChild, 1, "Icon for interfaces" );
134 
135 		iterChild = treeStore.append(iterTop);
136 		treeStore.setValue(iterChild, 0, new Pixbuf(greenClass_xpm) );
137 		treeStore.setValue(iterChild, 1, "Icon for classes" );
138 
139 	}
140 
141 	/**
142 	 * Creates the treeView and treeStore
143 	 * @return
144 	 */
145 	TreeView setup1()
146 	{
147 		class TTreeStore : TreeStore
148 		{
149 			this()
150 			{
151 				//int* i = cast(int*)pixbufGetType();
152 
153 				GType[] columns;
154 				columns ~= Pixbuf.getType();
155 				columns ~= GType.STRING;
156 				super(columns);
157 
158 			}
159 		}
160 
161 		testTreeStore1 = new TTreeStore();
162 		TreeView treeView = new TreeView(testTreeStore1);
163 		treeView.setRulesHint(true);
164 
165 		TreeSelection ts = treeView.getSelection();
166 		ts.setMode(SelectionMode.MULTIPLE);
167 		TreeViewColumn column;
168 		int col = 0;
169 		column = new TreeViewColumn("Icon",new CellRendererPixbuf(),"pixbuf", col);
170 		treeView.appendColumn(column);
171 		++col;
172 
173 		column = new TreeViewColumn("Description",new CellRendererText(),"text", col);
174 		treeView.appendColumn(column);
175 		column.setResizable(true);
176 		column.setReorderable(true);
177 		column.setSortColumnId(col);
178 		column.setSortIndicator(true);
179 		++col;
180 
181 		return treeView;
182 
183 	}
184 
185 		/**
186 	 * Creates the treeView and treeStore
187 	 * @return
188 	 */
189 	TreeView setup2()
190 	{
191 		class TTreeStore : TreeStore
192 		{
193 			this()
194 			{
195 				//int* i = cast(int*)pixbufGetType();
196 
197 				GType[] columns;
198 				columns ~= Pixbuf.getType();
199 				columns ~= GType.STRING;
200 				super(columns);
201 
202 			}
203 		}
204 
205 		testTreeStore2 = new TTreeStore();
206 		TreeView treeView = new TreeView(testTreeStore2);
207 		treeView.setRulesHint(true);
208 
209 		TreeSelection ts = treeView.getSelection();
210 		ts.setMode(SelectionMode.MULTIPLE);
211 		TreeViewColumn column;
212 		int col = 0;
213 
214 		column = new TreeViewColumn();
215 
216 		CellRendererPixbuf cellPixbuf = new CellRendererPixbuf();
217 		CellRendererText cellText = new CellRendererText();
218 
219 		column.packStart(cellPixbuf, false);
220 		column.addAttribute(cellPixbuf, "pixbuf", col);
221 		++col;
222 
223 		column.packEnd(cellText, true);
224 		column.addAttribute(cellText, "text", col);
225 
226 		column.setTitle("Types");
227 
228 		treeView.appendColumn(column);
229 
230 		column.setResizable(true);
231 		column.setReorderable(true);
232 		column.setSortColumnId(col);
233 		column.setSortIndicator(true);
234 		++col;
235 
236 		return treeView;
237 
238 	}
239 
240 
241 	void rowActivatedCallback(TreeView treeView, TreePath path, TreeViewColumn column)
242 	{
243 		printf("rowActivateCallback for %X \n",treeView);
244 		printf("rowActivateCallback for path %.*s\n",path.toString());
245 	}
246 
247 
248 	/* XPM */
249 	static string[] greenClass_xpm = [
250 	"16 16 67 1",
251 	" 	c None",
252 	".	c #00CF2E",
253 	"+	c #005D14",
254 	"@	c #005A16",
255 	"#	c #005217",
256 	"$	c #004B15",
257 	"%	c #004413",
258 	"&	c #00BC23",
259 	"*	c #00BB23",
260 	"=	c #006A14",
261 	"-	c #000000",
262 	";	c #00B721",
263 	">	c #00BF25",
264 	",	c #006F17",
265 	"'	c #00821C",
266 	")	c #00801A",
267 	"!	c #007B17",
268 	"~	c #00C126",
269 	"{	c #FFFFFF",
270 	"]	c #00761A",
271 	"^	c #008B21",
272 	"/	c #00821B",
273 	"(	c #007316",
274 	"_	c #00BA22",
275 	":	c #A9EBB6",
276 	"<	c #007B1D",
277 	"[	c #009426",
278 	"}	c #A9F5BC",
279 	"|	c #A9F2BA",
280 	"1	c #00BA23",
281 	"2	c #00D935",
282 	"3	c #00BE25",
283 	"4	c #A9EDB7",
284 	"5	c #007F1F",
285 	"6	c #009C2A",
286 	"7	c #00ED3E",
287 	"8	c #00E339",
288 	"9	c #A9F1B9",
289 	"0	c #00CB2C",
290 	"a	c #00BE24",
291 	"b	c #00C729",
292 	"c	c #00BF26",
293 	"d	c #008120",
294 	"e	c #00A52E",
295 	"f	c #00F241",
296 	"g	c #00E53A",
297 	"h	c #00D933",
298 	"i	c #00841D",
299 	"j	c #007B18",
300 	"k	c #007F20",
301 	"l	c #009928",
302 	"m	c #009224",
303 	"n	c #008B20",
304 	"o	c #A9EFB8",
305 	"p	c #00801F",
306 	"q	c #00BC24",
307 	"r	c #00C82A",
308 	"s	c #007A1C",
309 	"t	c #00791C",
310 	"u	c #007117",
311 	"v	c #006B14",
312 	"w	c #00B822",
313 	"x	c #00C629",
314 	"y	c #A9E9B5",
315 	"z	c #A9E7B4",
316 	"A	c #00C127",
317 	"B	c #00CF2C",
318 	"                ",
319 	"      .+@#$%    ",
320 	"    &*=-----    ",
321 	"   ;>,--')!--   ",
322 	"  ~>{]-^{{/!(   ",
323 	"  _:{<-[}|{{1   ",
324 	" 234{5-67890a2  ",
325 	" bc4{d-efghij.  ",
326 	" 234{k--lmn--2  ",
327 	"  1:o{p-----_   ",
328 	"  q>ro{st]uv&   ",
329 	"   w>x4{{{{;    ",
330 	"    ~13yyzA     ",
331 	"      Bbh       ",
332 	"                ",
333 	"                "];
334 
335 
336 	/* XPM */
337 	static string[] greenInterface_xpm = [
338 	"16 16 62 1",
339 	" 	c None",
340 	".	c #00CF2E",
341 	"+	c #008A1E",
342 	"@	c #009023",
343 	"#	c #00BC23",
344 	"$	c #00BB23",
345 	"%	c #FFFFFF",
346 	"&	c #007F18",
347 	"*	c #000000",
348 	"=	c #00B721",
349 	"-	c #00BF25",
350 	";	c #AAECB7",
351 	">	c #00881D",
352 	",	c #00861D",
353 	"'	c #007A16",
354 	")	c #00C126",
355 	"!	c #00C82A",
356 	"~	c #AAEFB9",
357 	"{	c #008F21",
358 	"]	c #00861C",
359 	"^	c #00BA22",
360 	"/	c #00C629",
361 	"(	c #00D12F",
362 	"_	c #AAF3BB",
363 	":	c #AAF5BC",
364 	"<	c #009726",
365 	"[	c #008B1F",
366 	"}	c #00C529",
367 	"|	c #00BA23",
368 	"1	c #00D935",
369 	"2	c #00BE25",
370 	"3	c #00CA2C",
371 	"4	c #00D732",
372 	"5	c #00E238",
373 	"6	c #AAF8BF",
374 	"7	c #009E29",
375 	"8	c #00CB2C",
376 	"9	c #00BE24",
377 	"0	c #00C729",
378 	"a	c #00BF26",
379 	"b	c #00CC2C",
380 	"c	c #00D933",
381 	"d	c #00E53A",
382 	"e	c #AAFABF",
383 	"f	c #00A12B",
384 	"g	c #009022",
385 	"h	c #00CC2D",
386 	"i	c #00CA2B",
387 	"j	c #00D632",
388 	"k	c #00E239",
389 	"l	c #AAF9BE",
390 	"m	c #009E2A",
391 	"n	c #00BD25",
392 	"o	c #009927",
393 	"p	c #009626",
394 	"q	c #008A1F",
395 	"r	c #00841A",
396 	"s	c #00BC24",
397 	"t	c #00B822",
398 	"u	c #00841B",
399 	"v	c #AAE8B5",
400 	"w	c #00CF2C",
401 	"                ",
402 	"      .+@       ",
403 	"    #$%&***     ",
404 	"   =-;%>,*&'    ",
405 	"  )-!~%%{*]-)   ",
406 	"  ^/(_:%<*[}|   ",
407 	" 123456%7*{891  ",
408 	" 0abcde%f*gha.  ",
409 	" 12ijkl%m*{in1  ",
410 	"  |/(_%op*qr^   ",
411 	"  s-!~%g***&#   ",
412 	"   t-;%>,u&'    ",
413 	"    )v%%%%%     ",
414 	"      w0c       ",
415 	"                ",
416 	"                "];
417 
418 
419 	/* XPM */
420 	static string[] greenTemplate_xpm = [
421 	"16 16 63 1",
422 	" 	c None",
423 	".	c #008A1E",
424 	"+	c #009023",
425 	"@	c #007D17",
426 	"#	c #000000",
427 	"$	c #FFFFFF",
428 	"%	c #007F18",
429 	"&	c #003B0C",
430 	"*	c #003C0C",
431 	"=	c #00380A",
432 	"-	c #003609",
433 	";	c #A9EAB5",
434 	">	c #00851C",
435 	",	c #008F21",
436 	"'	c #00861C",
437 	")	c #A9E7B4",
438 	"!	c #A9F5BB",
439 	"~	c #009726",
440 	"{	c #008B1F",
441 	"]	c #A9EBB6",
442 	"^	c #00D935",
443 	"/	c #A9E9B5",
444 	"(	c #A9EDB7",
445 	"_	c #A9F1B9",
446 	":	c #00EC3F",
447 	"<	c #009E29",
448 	"[	c #00CB2C",
449 	"}	c #00BE24",
450 	"|	c #00C729",
451 	"1	c #00BF26",
452 	"2	c #00CC2C",
453 	"3	c #00D933",
454 	"4	c #00E53A",
455 	"5	c #A9FABE",
456 	"6	c #00A12B",
457 	"7	c #009022",
458 	"8	c #00CC2D",
459 	"9	c #00CF2E",
460 	"0	c #00BE25",
461 	"a	c #00CA2B",
462 	"b	c #00D632",
463 	"c	c #00E239",
464 	"d	c #A9F8BD",
465 	"e	c #009E2A",
466 	"f	c #00BD25",
467 	"g	c #00BA23",
468 	"h	c #00C629",
469 	"i	c #00D12F",
470 	"j	c #00DB34",
471 	"k	c #009626",
472 	"l	c #008A1F",
473 	"m	c #00C628",
474 	"n	c #00BA22",
475 	"o	c #00BC24",
476 	"p	c #00BF25",
477 	"q	c #00C82A",
478 	"r	c #00BC23",
479 	"s	c #00B822",
480 	"t	c #00841B",
481 	"u	c #00B721",
482 	"v	c #00C126",
483 	"w	c #00C127",
484 	"x	c #00CF2C",
485 	"                ",
486 	"      ..+       ",
487 	"    @#########  ",
488 	"   $%#&*&#=-##  ",
489 	"  ;$>#$$,#'$$#  ",
490 	"  )$$$!$~#{])   ",
491 	" ^/(_!:$<#,[}^  ",
492 	" |12345$6#7819  ",
493 	" ^0abcd$e#,af^  ",
494 	"  ghij!$k#lmn   ",
495 	"  opqi_$,#'pr   ",
496 	"   sph(($tpu    ",
497 	"    vg0//gw     ",
498 	"      x|3       ",
499 	"                ",
500 	"                "];
501 
502 	/* XPM */
503 	static string[] package_xpm = [
504 	"16 16 25 1",
505 	" 	c None",
506 	".	c #713C17",
507 	"+	c #BF8231",
508 	"@	c #C17A2D",
509 	"#	c #93551F",
510 	"$	c #C1772B",
511 	"%	c #DBBF9E",
512 	"&	c #E5C9A1",
513 	"*	c #CEAB8B",
514 	"=	c #9E7058",
515 	"-	c #BF752A",
516 	";	c #F9F1BB",
517 	">	c #EDD1A6",
518 	",	c #D7B897",
519 	"'	c #BB712A",
520 	")	c #D7B998",
521 	"!	c #B76D28",
522 	"~	c #C7A082",
523 	"{	c #794F40",
524 	"]	c #AE6325",
525 	"^	c #A96023",
526 	"/	c #A55C22",
527 	"(	c #A25922",
528 	"_	c #C58332",
529 	":	c #A05921",
530 	"                ",
531 	"       .        ",
532 	"  +@@@@#@@@@+   ",
533 	"  $%&&*=%&&*$   ",
534 	"  -&;>,=&;>,-   ",
535 	"  '&>>)=&>>)'   ",
536 	"  !*,)~{*,)~!   ",
537 	" .#==={{{===#.  ",
538 	"  ]%&&*{%&&*]   ",
539 	"  ^&;>,=&;>,^   ",
540 	"  /&>>)=&>>)/   ",
541 	"  (*,)~=*,)~(   ",
542 	"  _::::#::::_   ",
543 	"       .        ",
544 	"                ",
545 	"                "];
546 
547 	/* Don't copy this bad example; inline RGB data is always a better
548 	 * idea than inline XPMs.
549 	 */
550 	static string[]  book_closed_xpm = [
551 	"16 16 7 1",
552 	"       c None s None",
553 	".      c black",
554 	"X      c red",
555 	"B      c blue",
556 	"o      c yellow",
557 	"O      c #808080",
558 	"#      c white",
559 	"                ",
560 	"       ..       ",
561 	"     ..XB.      ",
562 	"   ..XXXXB.     ",
563 	" ..XXXXXXXB.    ",
564 	".ooXXBBBBBXB.   ",
565 	"..ooXBBBBBBXB.  ",
566 	".X.ooXBBBBBBXB. ",
567 	".XX.ooXBBBXX..  ",
568 	" .XX.ooXBX..#O  ",
569 	"  .XX.oo..##OO. ",
570 	"   .XX..##OO..  ",
571 	"    .X.#OO..    ",
572 	"     ..O..      ",
573 	"      ..        ",
574 	"                "
575 	];
576 
577 
578 }
579 
580 
581