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 		version(Tango)
244 		{
245 			Stdout("rowActivateCallback for {}",treeView).newline;
246 			Stdout("rowActivateCallback for path {}",path.toString()).newline;
247 		}
248 		else
249 		{
250 			writefln("rowActivateCallback for %X",treeView);
251 			writefln("rowActivateCallback for path %s",path.toString());
252 		}
253 	}
254 
255 
256 	/* XPM */
257 	static string[] greenClass_xpm = [
258 	"16 16 67 1",
259 	" 	c None",
260 	".	c #00CF2E",
261 	"+	c #005D14",
262 	"@	c #005A16",
263 	"#	c #005217",
264 	"$	c #004B15",
265 	"%	c #004413",
266 	"&	c #00BC23",
267 	"*	c #00BB23",
268 	"=	c #006A14",
269 	"-	c #000000",
270 	";	c #00B721",
271 	">	c #00BF25",
272 	",	c #006F17",
273 	"'	c #00821C",
274 	")	c #00801A",
275 	"!	c #007B17",
276 	"~	c #00C126",
277 	"{	c #FFFFFF",
278 	"]	c #00761A",
279 	"^	c #008B21",
280 	"/	c #00821B",
281 	"(	c #007316",
282 	"_	c #00BA22",
283 	":	c #A9EBB6",
284 	"<	c #007B1D",
285 	"[	c #009426",
286 	"}	c #A9F5BC",
287 	"|	c #A9F2BA",
288 	"1	c #00BA23",
289 	"2	c #00D935",
290 	"3	c #00BE25",
291 	"4	c #A9EDB7",
292 	"5	c #007F1F",
293 	"6	c #009C2A",
294 	"7	c #00ED3E",
295 	"8	c #00E339",
296 	"9	c #A9F1B9",
297 	"0	c #00CB2C",
298 	"a	c #00BE24",
299 	"b	c #00C729",
300 	"c	c #00BF26",
301 	"d	c #008120",
302 	"e	c #00A52E",
303 	"f	c #00F241",
304 	"g	c #00E53A",
305 	"h	c #00D933",
306 	"i	c #00841D",
307 	"j	c #007B18",
308 	"k	c #007F20",
309 	"l	c #009928",
310 	"m	c #009224",
311 	"n	c #008B20",
312 	"o	c #A9EFB8",
313 	"p	c #00801F",
314 	"q	c #00BC24",
315 	"r	c #00C82A",
316 	"s	c #007A1C",
317 	"t	c #00791C",
318 	"u	c #007117",
319 	"v	c #006B14",
320 	"w	c #00B822",
321 	"x	c #00C629",
322 	"y	c #A9E9B5",
323 	"z	c #A9E7B4",
324 	"A	c #00C127",
325 	"B	c #00CF2C",
326 	"                ",
327 	"      .+@#$%    ",
328 	"    &*=-----    ",
329 	"   ;>,--')!--   ",
330 	"  ~>{]-^{{/!(   ",
331 	"  _:{<-[}|{{1   ",
332 	" 234{5-67890a2  ",
333 	" bc4{d-efghij.  ",
334 	" 234{k--lmn--2  ",
335 	"  1:o{p-----_   ",
336 	"  q>ro{st]uv&   ",
337 	"   w>x4{{{{;    ",
338 	"    ~13yyzA     ",
339 	"      Bbh       ",
340 	"                ",
341 	"                "];
342 
343 
344 	/* XPM */
345 	static string[] greenInterface_xpm = [
346 	"16 16 62 1",
347 	" 	c None",
348 	".	c #00CF2E",
349 	"+	c #008A1E",
350 	"@	c #009023",
351 	"#	c #00BC23",
352 	"$	c #00BB23",
353 	"%	c #FFFFFF",
354 	"&	c #007F18",
355 	"*	c #000000",
356 	"=	c #00B721",
357 	"-	c #00BF25",
358 	";	c #AAECB7",
359 	">	c #00881D",
360 	",	c #00861D",
361 	"'	c #007A16",
362 	")	c #00C126",
363 	"!	c #00C82A",
364 	"~	c #AAEFB9",
365 	"{	c #008F21",
366 	"]	c #00861C",
367 	"^	c #00BA22",
368 	"/	c #00C629",
369 	"(	c #00D12F",
370 	"_	c #AAF3BB",
371 	":	c #AAF5BC",
372 	"<	c #009726",
373 	"[	c #008B1F",
374 	"}	c #00C529",
375 	"|	c #00BA23",
376 	"1	c #00D935",
377 	"2	c #00BE25",
378 	"3	c #00CA2C",
379 	"4	c #00D732",
380 	"5	c #00E238",
381 	"6	c #AAF8BF",
382 	"7	c #009E29",
383 	"8	c #00CB2C",
384 	"9	c #00BE24",
385 	"0	c #00C729",
386 	"a	c #00BF26",
387 	"b	c #00CC2C",
388 	"c	c #00D933",
389 	"d	c #00E53A",
390 	"e	c #AAFABF",
391 	"f	c #00A12B",
392 	"g	c #009022",
393 	"h	c #00CC2D",
394 	"i	c #00CA2B",
395 	"j	c #00D632",
396 	"k	c #00E239",
397 	"l	c #AAF9BE",
398 	"m	c #009E2A",
399 	"n	c #00BD25",
400 	"o	c #009927",
401 	"p	c #009626",
402 	"q	c #008A1F",
403 	"r	c #00841A",
404 	"s	c #00BC24",
405 	"t	c #00B822",
406 	"u	c #00841B",
407 	"v	c #AAE8B5",
408 	"w	c #00CF2C",
409 	"                ",
410 	"      .+@       ",
411 	"    #$%&***     ",
412 	"   =-;%>,*&'    ",
413 	"  )-!~%%{*]-)   ",
414 	"  ^/(_:%<*[}|   ",
415 	" 123456%7*{891  ",
416 	" 0abcde%f*gha.  ",
417 	" 12ijkl%m*{in1  ",
418 	"  |/(_%op*qr^   ",
419 	"  s-!~%g***&#   ",
420 	"   t-;%>,u&'    ",
421 	"    )v%%%%%     ",
422 	"      w0c       ",
423 	"                ",
424 	"                "];
425 
426 
427 	/* XPM */
428 	static string[] greenTemplate_xpm = [
429 	"16 16 63 1",
430 	" 	c None",
431 	".	c #008A1E",
432 	"+	c #009023",
433 	"@	c #007D17",
434 	"#	c #000000",
435 	"$	c #FFFFFF",
436 	"%	c #007F18",
437 	"&	c #003B0C",
438 	"*	c #003C0C",
439 	"=	c #00380A",
440 	"-	c #003609",
441 	";	c #A9EAB5",
442 	">	c #00851C",
443 	",	c #008F21",
444 	"'	c #00861C",
445 	")	c #A9E7B4",
446 	"!	c #A9F5BB",
447 	"~	c #009726",
448 	"{	c #008B1F",
449 	"]	c #A9EBB6",
450 	"^	c #00D935",
451 	"/	c #A9E9B5",
452 	"(	c #A9EDB7",
453 	"_	c #A9F1B9",
454 	":	c #00EC3F",
455 	"<	c #009E29",
456 	"[	c #00CB2C",
457 	"}	c #00BE24",
458 	"|	c #00C729",
459 	"1	c #00BF26",
460 	"2	c #00CC2C",
461 	"3	c #00D933",
462 	"4	c #00E53A",
463 	"5	c #A9FABE",
464 	"6	c #00A12B",
465 	"7	c #009022",
466 	"8	c #00CC2D",
467 	"9	c #00CF2E",
468 	"0	c #00BE25",
469 	"a	c #00CA2B",
470 	"b	c #00D632",
471 	"c	c #00E239",
472 	"d	c #A9F8BD",
473 	"e	c #009E2A",
474 	"f	c #00BD25",
475 	"g	c #00BA23",
476 	"h	c #00C629",
477 	"i	c #00D12F",
478 	"j	c #00DB34",
479 	"k	c #009626",
480 	"l	c #008A1F",
481 	"m	c #00C628",
482 	"n	c #00BA22",
483 	"o	c #00BC24",
484 	"p	c #00BF25",
485 	"q	c #00C82A",
486 	"r	c #00BC23",
487 	"s	c #00B822",
488 	"t	c #00841B",
489 	"u	c #00B721",
490 	"v	c #00C126",
491 	"w	c #00C127",
492 	"x	c #00CF2C",
493 	"                ",
494 	"      ..+       ",
495 	"    @#########  ",
496 	"   $%#&*&#=-##  ",
497 	"  ;$>#$$,#'$$#  ",
498 	"  )$$$!$~#{])   ",
499 	" ^/(_!:$<#,[}^  ",
500 	" |12345$6#7819  ",
501 	" ^0abcd$e#,af^  ",
502 	"  ghij!$k#lmn   ",
503 	"  opqi_$,#'pr   ",
504 	"   sph(($tpu    ",
505 	"    vg0//gw     ",
506 	"      x|3       ",
507 	"                ",
508 	"                "];
509 
510 	/* XPM */
511 	static string[] package_xpm = [
512 	"16 16 25 1",
513 	" 	c None",
514 	".	c #713C17",
515 	"+	c #BF8231",
516 	"@	c #C17A2D",
517 	"#	c #93551F",
518 	"$	c #C1772B",
519 	"%	c #DBBF9E",
520 	"&	c #E5C9A1",
521 	"*	c #CEAB8B",
522 	"=	c #9E7058",
523 	"-	c #BF752A",
524 	";	c #F9F1BB",
525 	">	c #EDD1A6",
526 	",	c #D7B897",
527 	"'	c #BB712A",
528 	")	c #D7B998",
529 	"!	c #B76D28",
530 	"~	c #C7A082",
531 	"{	c #794F40",
532 	"]	c #AE6325",
533 	"^	c #A96023",
534 	"/	c #A55C22",
535 	"(	c #A25922",
536 	"_	c #C58332",
537 	":	c #A05921",
538 	"                ",
539 	"       .        ",
540 	"  +@@@@#@@@@+   ",
541 	"  $%&&*=%&&*$   ",
542 	"  -&;>,=&;>,-   ",
543 	"  '&>>)=&>>)'   ",
544 	"  !*,)~{*,)~!   ",
545 	" .#==={{{===#.  ",
546 	"  ]%&&*{%&&*]   ",
547 	"  ^&;>,=&;>,^   ",
548 	"  /&>>)=&>>)/   ",
549 	"  (*,)~=*,)~(   ",
550 	"  _::::#::::_   ",
551 	"       .        ",
552 	"                ",
553 	"                "];
554 
555 	/* Don't copy this bad example; inline RGB data is always a better
556 	 * idea than inline XPMs.
557 	 */
558 	static string[]  book_closed_xpm = [
559 	"16 16 7 1",
560 	"       c None s None",
561 	".      c black",
562 	"X      c red",
563 	"B      c blue",
564 	"o      c yellow",
565 	"O      c #808080",
566 	"#      c white",
567 	"                ",
568 	"       ..       ",
569 	"     ..XB.      ",
570 	"   ..XXXXB.     ",
571 	" ..XXXXXXXB.    ",
572 	".ooXXBBBBBXB.   ",
573 	"..ooXBBBBBBXB.  ",
574 	".X.ooXBBBBBBXB. ",
575 	".XX.ooXBBBXX..  ",
576 	" .XX.ooXBX..#O  ",
577 	"  .XX.oo..##OO. ",
578 	"   .XX..##OO..  ",
579 	"    .X.#OO..    ",
580 	"     ..O..      ",
581 	"      ..        ",
582 	"                "
583 	];
584 
585 
586 }
587 
588 
589