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 TestWindow;
20 
21 //debug = 1;
22 
23 //version=cairo;
24 
25 version(cairo)private import cairo.clock;
26 
27 private import gtk.Version;
28 private import gtk.Table;
29 
30 private import stdlib = core.stdc.stdlib : exit;
31 private import core.thread;
32 private import std.random;
33 
34 import gdk.Threads;
35 
36 private import gtk.Main;
37 private import gtk.MainWindow;
38 private import gtk.Adjustment;
39 private import gtk.AccelGroup;
40 
41 private import TestEntries;
42 
43 //private import gtkDTree;
44 private import TestStock;
45 private import TestDrawingArea;
46 private import TestScales;
47 private import TestText;
48 //private import TestTree;
49 private import TestTreeView;
50 private import TestTreeView1;
51 private import TestImage;
52 private import TestThemes;
53 private import TestAspectFrame;
54 private import TestIdle;
55 private import TTextView;
56 //private import TEditableCells;
57 
58 private import gtk.MenuItem;
59 private import gtk.Widget;
60 private import gtk.MenuBar;
61 private import gtk.Notebook;
62 private import gtk.ComboBoxText;
63 private import gtk.FileChooserDialog;
64 private import gtk.FontSelectionDialog;
65 private import gtk.ColorSelectionDialog;
66 private import gtk.Button;
67 private import gtk.VBox;
68 private import gtk.MessageDialog;
69 private import gtk.Frame;
70 private import gtk.HButtonBox;
71 private import gtk.Statusbar;
72 private import gtk.Menu;
73 private import gtk.HandleBox;
74 private import gtk.Toolbar;
75 private import gtk.SeparatorToolItem;
76 private import gtk.ToolButton;
77 private import gtk.RadioButton;
78 private import gtk.CheckButton;
79 private import gtk.ToggleButton;
80 //private import gtk.ListItem;
81 private import gtk.HBox;
82 private import gtk.Arrow;
83 //private import gtk.ListG;
84 //private import gtk.OptionMenu;
85 private import gtk.ButtonBox;
86 private import gtk.Calendar;
87 private import gtk.VButtonBox;
88 private import gtk.SpinButton;
89 private import gtk.ListStore;
90 private import gtk.TreeIter;
91 private import gtk.TreeView;
92 private import gtk.TreeViewColumn;
93 private import gtk.CellRendererText;
94 //private import gtk.SListG;
95 //private import ddi.Drawable;
96 private import gtk.Window;
97 
98 private import gtk.ScrolledWindow;
99 private import gtk.MessageDialog;
100 
101 private import core.memory;
102 
103 private import glib.ListSG;
104 
105 private import glib.Str;
106 private import gtk.Label;
107 private import glib.ListG;
108 private import gtk.Paned;
109 private import gtk.HPaned;
110 private import gtk.VPaned;
111 
112 private import gtk.Calendar;
113 private import std.stdio;
114 private import gtk.VButtonBox;
115 private import gtk.FileChooserButton;
116 
117 private import gtk.AboutDialog;
118 private import gtk.Dialog;
119 
120 private import gtk.TreeStore;
121 private import gdk.Pixbuf;
122 private import gtk.ComboBox;
123 
124 private import gtk.TreePath;
125 private import gtk.CellRenderer;
126 private import gtk.CellRendererPixbuf;
127 
128 /**
129  * This tests the DUI widgets
130  */
131 
132 
133 class TestWindow : MainWindow
134 {
135 	/**
136 	 * Executed when the user tries to close the window
137 	 * @return true to refuse to close the window
138 	 */
139 	int windowDelete(GdkEvent* event, Widget widget)
140 	{
141 
142 		debug(events) writeln("TestWindow.widgetDelete : this and widget to delete %X %X",this,window);
143 		MessageDialog d = new MessageDialog(
144 										this,
145 										GtkDialogFlags.MODAL,
146 										MessageType.QUESTION,
147 										ButtonsType.YES_NO,
148 										"Are you sure you want' to exit these GtkDTests?");
149 		int responce = d.run();
150 		if ( responce == ResponseType.YES )
151 		{
152 			stdlib.exit(0);
153 		}
154 		d.destroy();
155 		return true;
156 	}
157 
158 	void anyButtonExits(Button button)
159 	{
160 			stdlib.exit(0);
161 	}
162 
163 	this()
164 	{
165 		super("GtkD tests");
166 		setup();
167 		showAll();
168 
169 		string versionCompare = Version.checkVersion(3,0,0);
170 
171 		if ( versionCompare.length > 0 )
172 		{
173 			MessageDialog d = new MessageDialog(this,
174 										GtkDialogFlags.MODAL,
175 										MessageType.WARNING,
176 										ButtonsType.OK,
177 										"GtkD : Gtk+ version missmatch\n" ~ versionCompare ~
178 										"\nYou might run into problems!"
179 										"\n\nPress OK to continue");
180 			d.run();
181 			d.destroy();
182 		}
183 	}
184 
185 	void setup()
186 	{
187 		//Frame.defaultBorder = 7;
188 
189 		VBox mainBox = new VBox(false,0);
190 		mainBox.packStart(getMenuBar(),false,false,0);
191 		mainBox.packStart(getToolbar(),false,false,0);
192 
193 		Notebook notebook = setNotebook();
194 		notebook.setBorderWidth(10);
195 		mainBox.packStart(notebook,true,true,0);
196 
197 		Button cancelButton = new Button(StockID.CANCEL, &anyButtonExits);
198 		Button exitButton = new Button(StockID.QUIT, &anyButtonExits);
199 		Button quitButton = new Button(StockID.OK, &anyButtonExits);
200 
201 		ButtonBox bBox = HButtonBox.createActionBox();
202 
203 		bBox.packEnd(exitButton,0,0,10);
204 		bBox.packEnd(cancelButton,0,0,10);
205 		bBox.packEnd(quitButton,0,0,10);
206 		mainBox.packStart(bBox,false,false,0);
207 
208 		Statusbar statusbar = new Statusbar();
209 
210 		mainBox.packStart(statusbar,false,true,0);
211 		add(mainBox);
212 
213 		notebook.appendPage(new TestEntries,"Entry");
214 		testEventBox(notebook);
215 
216 		testButtons(notebook);
217 
218 		notebook.appendPage(new TestStock,"Stock");
219 		testLists(notebook);
220 		testNotebook(notebook);
221 		testPaned(notebook);
222 		testDialogs(notebook);
223 		testViewport(notebook);
224 
225 		version(Windows)
226 		{
227 			// todo - threads are still broken on windows
228 		}
229 		else
230 		{
231 			testThreads(notebook);
232 		}
233 
234 		notebook.appendPage(new TestScales,"Scales");
235 			testSpinButton(notebook);
236 
237 		notebook.appendPage(new TestTreeView,"TreeView");
238 		notebook.appendPage(new TestTreeView1,"TreeView 1");
239 			testList(notebook);
240 
241 		version(linux) {
242 			// this block crashes gtk+ on win32 for some reason
243 			notebook.appendPage(new Frame(new TestDrawingArea,"Drawing Area"),"Drawing");
244 			notebook.appendPage(new TestText,"Text");
245 			notebook.appendPage(new TestImage(this),"Image");
246 			//TestThemes seems to be unfinished.
247 			//notebook.appendPage(new TestThemes(this),"Themes");
248 			notebook.appendPage(new TestAspectFrame(),"Aspect Frame");
249 			notebook.appendPage(new TestIdle(),"Idle");
250 			version(cairo)notebook.appendPage(new Clock(), "Cairo");
251 			gtkDemo(notebook);
252 		}
253 	}
254 
255 	MenuBar getMenuBar()
256 	{
257 
258 		AccelGroup accelGroup = new AccelGroup();
259 
260 		addAccelGroup(accelGroup);
261 
262 
263 		MenuBar menuBar = new MenuBar();
264 
265 		Menu menu = menuBar.append("_File");;
266 
267 		MenuItem item = new MenuItem(&onMenuActivate, "_New","file.new", true, accelGroup, 'n');
268 		//item.addAccelerator("activate",accelGroup,'n',GdkModifierType.CONTROL_MASK,GtkAccelFlags.VISIBLE);
269 
270 		menu.append(item);
271 		menu.append(new MenuItem(&onMenuActivate, "_Open","file.open", true, accelGroup, 'o'));
272 		menu.append(new MenuItem(&onMenuActivate, "_Close","file.close", true, accelGroup, 'c'));
273 		menu.append(new MenuItem(&onMenuActivate, "E_xit","file.exit", true, accelGroup, 'x'));
274 
275 
276 		menu = menuBar.append("_Edit");
277 
278 		menu.append(new MenuItem(&onMenuActivate,"_Find","edit.find", true, accelGroup, 'f'));
279 		menu.append(new MenuItem(&onMenuActivate,"_Search","edit.search", true, accelGroup, 's'));
280 
281 		menu = menuBar.append("_Help");
282 		menu.append(new MenuItem(&onMenuActivate,"_About","help.about", true, accelGroup, 'a',GdkModifierType.CONTROL_MASK|GdkModifierType.SHIFT_MASK));
283 
284 
285 
286 
287 		return menuBar;
288 	}
289 
290 	class GtkDAbout : AboutDialog
291 	{
292 		this()
293 		{
294 			string[] names;
295 			names ~= "Antonio Monteiro (binding/wrapping/proxying/decorating for D)";
296 			names ~= "www.gtk.org (base C library)";
297 
298 			setAuthors( names );
299 			setDocumenters( names );
300 			setArtists( names );
301 			setLicense("License is LGPL");
302 			setWebsite("http://lisdev.com");
303 		}
304 	}
305 
306 	void onMenuActivate(MenuItem menuItem)
307 	{
308 		string action = menuItem.getActionName();
309 		switch( action )
310 		{
311 			case "help.about":
312 				GtkDAbout dlg = new GtkDAbout();
313 				dlg.addOnResponse(&onDialogResponse);
314 				dlg.showAll();
315 				break;
316 			default:
317 				MessageDialog d = new MessageDialog(
318 					this,
319 					GtkDialogFlags.MODAL,
320 					MessageType.INFO,
321 					ButtonsType.OK,
322 					"You pressed menu item "~action);
323 				d.run();
324 				d.destroy();
325 			break;
326 		}
327 
328 	}
329 
330 	void onDialogResponse(int response, Dialog dlg)
331 	{
332 		if(response == GtkResponseType.CANCEL)
333 			dlg.destroy();
334 	}
335 
336 	Widget getToolbar()
337 	{
338 		HandleBox handleBox = new HandleBox();
339 		Toolbar toolbar = new Toolbar();
340 		toolbar.insert(new ToolButton(StockID.OPEN));
341 		toolbar.insert(new ToolButton(StockID.CLOSE));
342 		toolbar.insert(new SeparatorToolItem());
343 		toolbar.insert(new ToolButton(StockID.SAVE));
344 		toolbar.insert(new ToolButton(StockID.SAVE_AS));
345 
346 		handleBox.add(toolbar);
347 
348 		return handleBox;
349 
350 	}
351 
352 	Notebook setNotebook()
353 	{
354 		Notebook notebook = new Notebook();
355 		notebook.addOnSwitchPage(&onNotebookSwitchPage);
356 		notebook.setTabPos(PositionType.LEFT);
357 		return notebook;
358 	}
359 
360 	void onNotebookSwitchPage(Widget notePage, uint pageNumber, Notebook notebook)
361 	{
362 		//writefln("Notebook switch to page %s", pageNumber);
363 		// fullCollect helps finding objects that shouldn't have been collected
364 		GC.collect();
365 		//writefln("exiting Notebook switch to page %s", pageNumber);
366 	}
367 
368 	//private import EventBox;
369 
370 	void testEventBox(Notebook notebook)
371 	{
372 
373 //		EventBox eventBox = new EventBox();
374 //		eventBox.add(new Label("label on event box"));
375 //		notebook.appendPage(eventBox,"Buttons");
376 
377 		//EventBox eventBox = new EventBox();
378 		//eventBox.add(new Label("label on event box"));
379 		notebook.appendPage(new Label("just a simple label"),new Label("label"));
380 
381 	}
382 
383 	void testButtons(Notebook notebook)
384 	{
385 
386 		Table table = new Table(2,12,0);
387 
388 		//ListSG listSG = new ListSG();
389 
390 		RadioButton radio1Button = new RadioButton(cast(ListSG)null,"Option 1");
391 		RadioButton radio2Button = new RadioButton(radio1Button,"Option 2");
392 		RadioButton radio3Button = new RadioButton(radio2Button,"Option 3");
393 		RadioButton radio4Button = new RadioButton(radio3Button,"Option 4");
394 		RadioButton radio5Button = new RadioButton(radio4Button,"Option 5");
395 		RadioButton radio6Button = new RadioButton(radio5Button,"Option 6");
396 		RadioButton radio7Button = new RadioButton(radio6Button,"Option 7");
397 		RadioButton radio8Button = new RadioButton(radio7Button,"Option 8");
398 		RadioButton radio9Button = new RadioButton(radio8Button,"Option 9");
399 		table.attach(radio1Button,0,1,0,1,AttachOptions.FILL,AttachOptions.FILL,4,4);
400 		table.attach(radio2Button,0,1,1,2,AttachOptions.FILL,AttachOptions.FILL,4,4);
401 		table.attach(radio3Button,0,1,2,3,AttachOptions.FILL,AttachOptions.FILL,4,4);
402 		table.attach(radio4Button,0,1,3,4,AttachOptions.FILL,AttachOptions.FILL,4,4);
403 		table.attach(radio5Button,0,1,4,5,AttachOptions.FILL,AttachOptions.FILL,4,4);
404 		table.attach(radio6Button,0,1,5,6,AttachOptions.FILL,AttachOptions.FILL,4,4);
405 		table.attach(radio7Button,0,1,6,7,AttachOptions.FILL,AttachOptions.FILL,4,4);
406 		table.attach(radio8Button,0,1,7,8,AttachOptions.FILL,AttachOptions.FILL,4,4);
407 		table.attach(radio9Button,0,1,8,9,AttachOptions.FILL,AttachOptions.FILL,4,4);
408 
409 		CheckButton editableButton = new CheckButton("editable");
410 		CheckButton visibleButton = new CheckButton("visible");
411 		table.attach(editableButton,0,1,9,10,AttachOptions.FILL,AttachOptions.FILL,4,4);
412 		table.attach(visibleButton,0,1,10,11,AttachOptions.FILL,AttachOptions.FILL,4,4);
413 
414 		ToggleButton toggleButton = new ToggleButton("Toggle this");
415 		table.attach(toggleButton,0,1,11,12,AttachOptions.FILL,AttachOptions.FILL,4,4);
416 
417 		Button button = new Button("test events");
418 		table.attach(button,0,1,12,13,AttachOptions.FILL,AttachOptions.FILL,4,4);
419 
420 		void bActivate(Button button)
421 		{
422 			writeln("button Activate");
423 		}
424 		void bClicked(Button button)
425 		{
426 			writeln("button Clicked");
427 		}
428 		void bEnter(Button button)
429 		{
430 			writeln("button Enter");
431 		}
432 		void bLeave(Button button)
433 		{
434 			writeln("button Leave");
435 		}
436 		void bPressed(Button button)
437 		{
438 			writeln("button Pressed");
439 		}
440 		void bReleased(Button button)
441 		{
442 			writeln("button Released");
443 		}
444 		button.addOnActivate(&bActivate);
445 		button.addOnClicked(&bClicked);
446 		button.addOnEnter(&bEnter);
447 		button.addOnLeave(&bLeave);
448 		button.addOnPressed(&bPressed);
449 		button.addOnReleased(&bReleased);
450 
451 //		for ( ShadowType shadow = 0; shadow<=ShadowType.max ; shadow ++)
452 //		{
453 //			for ( DirectionType direction = 0 ; direction<=DirectionType.max ; direction++)
454 //			{
455 //				table.attach(new Arrow(direction,shadow),direction+1,direction+2,shadow,shadow+1,AttachOptions.FILL,AttachOptions.FILL,4,4);
456 //				table.attach(new Arrow(direction,shadow),direction+1,direction+2,shadow,shadow+1,AttachOptions.FILL,AttachOptions.FILL,4,4);
457 //				table.attach(new Arrow(direction,shadow),direction+1,direction+2,shadow,shadow+1,AttachOptions.FILL,AttachOptions.FILL,4,4);
458 //				table.attach(new Arrow(direction,shadow),direction+1,direction+2,shadow,shadow+1,AttachOptions.FILL,AttachOptions.FILL,4,4);
459 //			}
460 //		}
461 
462 
463 		notebook.appendPage(new Frame(table,"Buttons"),"Buttons");
464 
465 	}
466 
467 	class ComboStore : TreeStore
468 	{
469 		this()
470 		{
471 			//int* i = cast(int*)pixbufGetType();
472 
473 			GType[] columns;
474 			columns ~= GType.STRING;
475 			columns ~= GType.STRING;
476 			super(columns);
477 		}
478 
479 	}
480 
481 
482 	void testLists(Notebook notebook)
483 	{
484 		VBox mainBox = new VBox(false,3);
485 
486 		// comboBoxTextEntry from a list of strings
487 		mainBox.packStart(new Label("String combo"),false,true,0);
488 		static string[] cbList = ["item 1","item 2","item 3","item 4","item 5","item 6","item 7","item 8","item 9"];
489 		comboText = new ComboBoxText();
490 		string entry3 = "Combo box text entry 3";
491 		comboText.appendText("Combo box text entry 1");
492 		comboText.appendText("Combo box text entry 2");
493 		comboText.appendText(entry3);
494 		comboText.appendText("Combo box text entry 4");
495 		comboText.appendText("Combo box text entry 5");
496 		comboText.setActive(2);
497 
498 		ButtonBox actionBox1 = HButtonBox.createActionBox();
499 		actionBox1.packStart(comboText,false,false,0);
500 
501 		Button showCombo1 = new Button("ShowCombo", &showTextCombo);
502 		actionBox1.packStart(showCombo1,false,false,0);
503 
504 		mainBox.packStart(new Frame(actionBox1, "Text entry ComboBox"),false,false,0);
505 
506 
507 
508 		// TODO combo with widgets
509 
510 
511 		// new ComboBox + TreeModel
512 
513 		ComboStore comboStore = new ComboStore();
514 
515 		TreeIter iterFirst;	// to set the first active iter
516 		TreeIter iterChild;
517 		TreeIter iterTop = comboStore.append(null);
518 		comboStore.setValue(iterTop, 0, "Paganini" );
519 		iterFirst = comboStore.append(iterTop);
520 		comboStore.setValue(iterFirst, 0, "Nicolo" );
521 
522 		iterTop = comboStore.append(null);
523 		comboStore.setValue(iterTop, 0, "List" );
524 		iterChild = comboStore.append(iterTop);
525 		comboStore.setValue(iterChild, 0, "Franz" );
526 
527 		iterTop = comboStore.append(null);
528 		comboStore.setValue(iterTop, 0, "Beethoven" );
529 		iterChild = comboStore.append(iterTop);
530 		comboStore.setValue(iterChild, 0, "Ludwic" );
531 		iterChild = comboStore.append(iterTop);
532 		comboStore.setValue(iterChild, 0, "Maria" );
533 		iterChild = comboStore.append(iterTop);
534 		comboStore.setValue(iterChild, 0, "Van" );
535 
536 		iterTop = comboStore.append(null);
537 		comboStore.setValue(iterTop, 0, "Bach" );
538 		iterChild = comboStore.append(iterTop);
539 		comboStore.setValue(iterChild, 0, "Johann" );
540 		iterChild = comboStore.append(iterTop);
541 		comboStore.setValue(iterChild, 0, "Sebastian" );
542 
543 		ComboBox treeCombo = new ComboBox(comboStore);
544 		treeCombo.setWrapWidth(1);
545 		treeCombo.setProperty("entry-text-column", 0);
546 
547 		// TODO something is wrong gettign the ier from the path
548 		//TreePath path = new TreePath("0,0");
549 		//comboStore.getIter(iterChild, path);
550 		//treeCombo.setActiveIter(iterChild);
551 		// use a previously set iter
552 		treeCombo.setActiveIter(iterFirst);
553 
554 		mainBox.packStart(new Frame(treeCombo,"Tree Combo box"),false,true,0);
555 
556 		simpleCombo = new ComboBoxText();
557 		simpleCombo.appendText("Top");
558 		simpleCombo.appendText("Bottom");
559 		simpleCombo.appendText("Left");
560 		simpleCombo.appendText("Right");
561 		simpleCombo.setActive(0);
562 
563 		// actions
564 
565 		ButtonBox actionBox = HButtonBox.createActionBox();
566 		actionBox.packStart(simpleCombo,false,false,0);
567 
568 		Button showCombo = new Button("ShowCombo", &showSimpleCombo);
569 		actionBox.packStart(showCombo,false,false,0);
570 
571 		mainBox.packStart(new Frame(actionBox, "Simple text list"),false,false,0);
572 
573 		notebook.appendPage(new Frame(mainBox,"Lists"),"Lists");
574 
575 	}
576 	ComboBoxText simpleCombo;
577 	ComboBoxText comboText;
578 
579 	void showTextCombo(Button button)
580 	{
581 		writeln("Combo selected text = %s",comboText.getActiveText());
582 	}
583 
584 	void showSimpleCombo(Button button)
585 	{
586 		writeln("Combo selected text = %s",simpleCombo.getActiveText());
587 	}
588 
589 	class NB : Notebook
590 	{
591 		void itemActivated(MenuItem menu_item)
592 		{
593 			writeln("NB.activateCallback");
594 		}
595 		void buttonClicked(Button button)
596 		{
597 			setCurrentPage(2);
598 		}
599 
600 		void switchPage(Notebook notebook, /*NotebookPage page,*/ uint pageNumber)
601 		{
602 			writeln("new page = %d",pageNumber);
603 		}
604 	}
605 
606 
607 	NB nb;
608 
609 	void posLeft(Button button)
610 	{
611 		nb.setTabPos(PositionType.LEFT);
612 	}
613 	void posRight(Button button)
614 	{
615 		nb.setTabPos(PositionType.RIGHT);
616 	}
617 	void posTop(Button button)
618 	{
619 		nb.setTabPos(PositionType.TOP);
620 	}
621 	void posBottom(Button button)
622 	{
623 		nb.setTabPos(PositionType.BOTTOM);
624 	}
625 
626 	/**
627 	 * tests notebook
628 	 * @param nodebook
629 	 */
630 	void testNotebook(Notebook notebook)
631 	{
632 
633       	nb = new NB();
634       	nb.setTabPos(PositionType.min);
635       	nb.popupEnable();
636 		nb.setShowBorder(false);
637 		nb.setBorderWidth(0);
638 
639       	class PageMove
640       	{
641       		Notebook notebook;
642       		PositionType toPos;
643       		this(Notebook notebook,PositionType toPos)
644       		{
645       			this.notebook = notebook;
646       			this.toPos = toPos;
647       		}
648       		void buttonClickedCallback()
649       		{
650       			notebook.setTabPos(toPos);
651       		}
652       	}
653 
654 		PageMove toLeft = new PageMove(nb,PositionType.LEFT);
655 		PageMove toRight = new PageMove(nb,PositionType.RIGHT);
656 		PageMove toTop = new PageMove(nb,PositionType.TOP);
657 		PageMove toBottom = new PageMove(nb,PositionType.BOTTOM);
658 
659 
660 		notebook.appendPage(nb,new Label("Notebook"));
661 
662       	for( char i = '1' ; i<'5' ; i++ )
663       	{
664       		Table table = new Table(2,2,true);
665 			Button left = new Button("Left "~ i);
666 			left.addOnClicked(&posLeft);
667 			Button right = new Button("Right "~ i);
668 			right.addOnClicked(&posRight);
669 			Button top = new Button("top "~ i);
670 			top.addOnClicked(&posTop);
671 			Button bottom = new Button("bottom "~ i);
672 			bottom.addOnClicked(&posBottom);
673 
674 			table.attach(top,0,1,0,1,AttachOptions.SHRINK,AttachOptions.SHRINK,4,4);
675 			table.attach(right,1,2,0,1,AttachOptions.SHRINK,AttachOptions.SHRINK,4,4);
676 			table.attach(left,0,1,1,2,AttachOptions.SHRINK,AttachOptions.SHRINK,4,4);
677 			table.attach(bottom,1,2,1,2,AttachOptions.SHRINK,AttachOptions.SHRINK,4,4);
678       		if ( i == 3 )
679 			{
680 
681 //				MenuItem menuItem = new MenuItem("menu page 3",&nb.itemActivated);
682 //
683 //				Menu menu = new Menu();
684 //				menu.append(new MenuItem("page 3.1",&nb.itemActivated));
685 //				menu.append(new MenuItem("page 3.2",&nb.itemActivated));
686 //				menu.append(new MenuItem("page 3.3",&nb.itemActivated));
687 //				menu.append(new MenuItem("page 3.4",&nb.itemActivated));
688 //
689 //				menuItem.setSubmenu(menu);
690 
691 				HBox box = new HBox(false,0);
692 				box.setBorderWidth(0);
693 				Button button = new Button("Page " ~ i ~ "\0");
694 				button.addOnClicked(&nb.buttonClicked);
695 				button.setBorderWidth(0);
696 				button.setRelief(ReliefStyle.NONE);
697 				CheckButton checkButton = new CheckButton();
698 				checkButton.setBorderWidth(0);
699 				box.packStart(checkButton,false,false,0);
700 				box.packStart(button,false,false,0);
701 				//nb.appendPageMenu(table,box,menuItem);
702 				//nb.appendPage(table,box);
703 			}
704 			else
705 			{
706 				nb.appendPage(table,new Label("Page " ~ i ~ "\0"));
707 			}
708       	}
709 		//nb.addOnSwitchPage(&nb.switchPage);
710 	}
711 
712 	void testPaned(Notebook notebook)
713 	{
714 
715 		Paned mainPaned = new VPaned();
716 		Paned p0 = mainPaned;
717 		Button p1;
718 		Paned p2;
719 
720 		bool h = true;
721 		for ( char c='1' ; c<='5' ; c++ )
722 		{
723 			p1 = new Button("Pane "~c);
724 			if ( h ) p2 = new HPaned();
725 			else p2 = new VPaned();
726 
727 			p0.add1(p1);
728 			p0.add2(p2);
729 			p0 = p2;
730 			h = !h;
731 		}
732 
733 		notebook.appendPage(mainPaned,new Label("Paned"));
734 
735 	}
736 
737 	FileChooserDialog fcd;
738 	FontSelectionDialog f;
739 	ColorSelectionDialog d;
740 
741 	void showFileChooser(Button button)
742 	{
743 		string[] a;
744 		ResponseType[] r;
745 		a ~= "Lets go!";
746 		a ~= "Please don't";
747 		r ~= ResponseType.OK;
748 		r ~= ResponseType.CANCEL;
749 		if ( fcd  is  null )
750 		{
751 			fcd = new FileChooserDialog("File Chooser", this, FileChooserAction.OPEN, a, r);
752 		}
753 
754 		fcd.setSelectMultiple(true);
755 		fcd.run();
756 //		writefln("file selected = %s",fcd.getFileName());
757 //
758 //		foreach ( int i, string selection ; fs.getSelections())
759 //		{
760 //			writeln("File(s) selected [%d] %s",i,selection);
761 //		}
762 		fcd.hide();
763 	}
764 
765 	void showColor(Button button)
766 	{
767 		if ( d  is  null )
768 		{
769 			d = new ColorSelectionDialog("Select the color");
770 		}
771 		d.run();
772 		d.hide();
773 	}
774 
775 	void showCalendar(Button button)
776 	{
777 		Window calWin = new Window("Calendar");
778 		Calendar calendar = new Calendar();
779 		//calendar.setTitle("No Title");
780 		calWin.add(calendar);
781 		calWin.showAll();
782 	}
783 
784 	void showFont(Button button)
785 	{
786 		if ( f  is  null )
787 		{
788 			f = new FontSelectionDialog("Select the font");
789 		}
790 		f.run();
791 		string fontName = f.getFontName();
792 		f.hide();
793 	}
794 
795 	Button fontButton;
796 
797 	void testDialogs(Notebook notebook)
798 	{
799 
800 		ButtonBox bBox = VButtonBox.createActionBox();
801 
802 		if ( fcd  is  null )
803 		{
804 			fcd = new FileChooserDialog("File Chooser", this, FileChooserAction.OPEN);
805 		}
806 
807 
808 		Button fileChooser = new Button("File Chooser", &showFileChooser);
809 		FileChooserButton fcb = new FileChooserButton(fcd);
810 
811 		Button color = new Button("Color Dialog", &showColor);
812 		Button calendar = new Button("Calendar Dialog", &showCalendar);
813 		fontButton = new Button("Font Dialog", &showFont);
814 		//fontButton.modifyFont("[Newspaper][16]");
815 
816 		bBox.packStart(fileChooser,0,0,10);
817 		bBox.packStart(fcb,0,0,10);
818 		bBox.packStart(color,0,0,10);
819 		bBox.packStart(calendar,0,0,10);
820 		bBox.packStart(fontButton,0,0,10);
821 
822 		notebook.appendPage(new Frame(bBox,"Dialogs"),new Label("Dialogs"));
823 
824 	}
825 
826 	__gshared Button[] threadTestButtons;
827 	static T1[] t1s;
828 
829 	class T1 : Thread
830 	{
831 		int num;
832 
833 		this(int num)
834 		{
835 			super(&run);
836 			this.num = num;
837 		}
838 
839 		void run()
840 		{
841 			runCommon();
842 		}
843 		
844 		int runCommon()
845 		{
846 			while(1)
847 			{
848 				size_t buttonNum = uniform(0, threadTestButtons.length);
849 				Button button = threadTestButtons[buttonNum];
850 
851 				threadsEnter();
852 				button.removeAll();
853 				button.setLabel(std..string.format("%s", num));
854 				threadsLeave();
855 				yield();
856 			}
857 			assert(0);
858 		}
859 	}
860 
861 	void testThreads(Notebook notebook)
862 	{
863 
864 		Table grid = new Table(8,8,0);
865 		for ( int i = 0 ; i<8 ; i++)
866 		{
867 			for ( int j = 0 ; j<8; j++)
868 			{
869 				Button button = new Button(std..string.format("%s",(j+8*i)));
870 				threadTestButtons ~= button;
871 				grid.attach( button,
872 							i,i+1,
873 							j,j+1,
874 							AttachOptions.SHRINK,AttachOptions.SHRINK,4,4);
875 
876 				t1s ~= new T1(j+8*i);
877 			}
878 		}
879 
880 		void stop(Button button)
881 		{
882 			foreach ( T1 t ; t1s )
883 			{
884 				if ( t.isRunning() )
885 				{
886 					t.sleep(dur!("hnsecs")(100));
887 				}
888 			}
889 		}
890 
891 		void go(Button button)
892 		{
893 			foreach ( T1 t ; t1s )
894 			{
895 				if ( !t.isRunning() )
896 				{
897 					t.start();
898 				}
899 			}
900 		}
901 
902 		VBox vbox = new VBox(false, 2);
903 		vbox.packStart(grid, true, true,2);
904 		ButtonBox actions = HButtonBox.createActionBox();
905 
906 		Button button = new Button(StockID.STOP, &stop);
907 		actions.packStart(button, false, false, 7);
908 		button = new Button(StockID.OK, &go);
909 		actions.packStart(button, false, false, 7);
910 
911 		vbox.packStart(actions, false, false, 2);
912 
913 		notebook.appendPage(vbox,new Label("Threads"));
914 	}
915 
916 	void testViewport(Notebook notebook)
917 	{
918 
919 		Table grid = new Table(21,21,0);
920 		for ( int i = 0 ; i<21 ; i++)
921 		{
922 			for ( int j = 0 ; j<21; j++)
923 			{
924 				if ( (i == j) || (i+j==20) || (i==10) || (j==10))
925 				{
926 					grid.attach(
927 						new Button("Button"),
928 							i,i+1,
929 							j,j+1,
930 							AttachOptions.SHRINK,AttachOptions.SHRINK,4,4);
931 				}
932 			}
933 		}
934 
935 		ScrolledWindow sw = new ScrolledWindow(null,null);
936 		sw.addWithViewport(grid);
937 		notebook.appendPage(sw,new Label("Viewport"));
938 	}
939 
940 	void testSpinButton(Notebook notebook)
941 	{
942 		Table table = new Table(2,1,false);
943 
944 		SpinButton spin = new SpinButton(new Adjustment(1.0, 0.0, 100.0, 1.0, 10.0, 0),1,0);
945 		table.attach(new Label("Spin this:"),0,1,0,1,AttachOptions.FILL,AttachOptions.FILL,4,4);
946 		table.attach(spin,1,2,0,1,AttachOptions.FILL,AttachOptions.FILL,4,4);
947 
948 		notebook.appendPage(table,"Spin Buttons");
949 
950 	}
951 
952 	void testList(Notebook notebook)
953 	{
954 		class TestListStore : ListStore
955 		{
956 			this()
957 			{
958 				static GType [3] columns = [
959 								GType.STRING,
960 								GType.STRING,
961 								GType.STRING
962 								];
963 				super(columns);
964 			}
965 		}
966 
967 		TestListStore testListStore = new TestListStore();
968 
969 		TreeIter iterTop = testListStore.createIter();
970 
971 		static int [3] cols = [0,1,2];
972 		string[] vals;
973 		vals ~= "Antonio";
974 		vals ~= "Canada";
975 		vals ~= "Ontario";
976 		testListStore.set(iterTop,cols,vals);
977 
978 		testListStore.append(iterTop);
979 		string[] vals1;
980 		vals1 ~= "John Reimer";
981 		vals1 ~= "Canada";
982 		vals1 ~= "BC";
983 		testListStore.set(iterTop,cols,vals1);
984 
985 		testListStore.append(iterTop);
986 		string[] vals2;
987 		vals2 ~= "Friend of GtkD 2";
988 		vals2 ~= "Poland";
989 		vals2 ~= "Torun";
990 		testListStore.set(iterTop,cols,vals2);
991 
992 		testListStore.append(iterTop);
993 		string[] vals3;
994 		vals3 ~= "Friend of GtkD 3";
995 		vals3 ~= "Norway";
996 		vals3 ~= "Norway";
997 		testListStore.set(iterTop,cols,vals3);
998 
999 		TreeView treeView = new TreeView(testListStore);
1000 		treeView.setHeadersClickable(true);
1001 		treeView.setRulesHint(true);
1002 
1003 		//CellRendererText cellText = new CellRendererText();
1004 		TreeViewColumn column = new TreeViewColumn("Author",new CellRendererText(),"text", 0);
1005 		treeView.appendColumn(column);
1006 		column.setResizable(true);
1007 		column.setReorderable(true);
1008 		column.setSortColumnId(0);
1009 		column.setSortIndicator(true);
1010 
1011 		column = new TreeViewColumn("Country",new CellRendererText(),"text", 1);
1012 		treeView.appendColumn(column);
1013 		column.setResizable(true);
1014 		column.setReorderable(true);
1015 		column.setSortColumnId(1);
1016 		column.setSortIndicator(true);
1017 
1018 		column = new TreeViewColumn("Province",new CellRendererText(),"text", 2);
1019 		treeView.appendColumn(column);
1020 		column.setResizable(true);
1021 		column.setReorderable(true);
1022 		column.setSortColumnId(2);
1023 		column.setSortIndicator(true);
1024 
1025 		//notebook.appendPage(treeView,"ListView");
1026 		ScrolledWindow sw = new ScrolledWindow(null,null);
1027 		sw.addWithViewport(treeView);
1028 		notebook.appendPage(sw,"ListView");
1029 	}
1030 
1031 	void testDelete(Notebook notebook)
1032 	{
1033 //		ulong l = 0;
1034 //		while(true)
1035 //		{
1036 //			int i =0;
1037 //			while(i<1 )
1038 //			{
1039 //				//Button b = new Button("Button");
1040 //				Drawable d = getDrawable();
1041 //				delete d;
1042 //				++i;
1043 //			}
1044 //			++l;
1045 //			write("testDelete count = %d\n\0",l*i);
1046 //		}
1047 
1048 	}
1049 
1050 	void gtkDemo(Notebook notebook)
1051 	{
1052 		void showTTextView(Button button)
1053 		{
1054 			new TTextView();
1055 		}
1056 
1057 		void showTEditableCells(Button button)
1058 		{
1059 		//	new TEditableCells();
1060 		}
1061 
1062 		ButtonBox vBBox = VButtonBox.createActionBox();
1063 
1064 		Button button = new Button("Text View");
1065 		button.addOnClicked(&showTTextView);
1066 		vBBox.packStart(button,false,false,4);
1067 
1068 		button = new Button("Editable Cells");
1069 		button.addOnClicked(&showTEditableCells);
1070 		vBBox.packStart(button,false,false,4);
1071 
1072 		notebook.appendPage(vBBox,"gtk-demo");
1073 	}
1074 }
1075 
1076 private import gtkc.Loader;
1077 
1078 void main(string[] args)
1079 {
1080 	Linker.dumpLoadLibraries();
1081 	Linker.dumpFailedLoads();
1082 
1083 	version(Windows)
1084 	{
1085 		// todo threads are still broken on windows...
1086 		Main.init(args);
1087 	}
1088 	else
1089 	{
1090 		Main.initMultiThread(args);
1091 	}
1092 
1093 	TestWindow window = new TestWindow();
1094 
1095 	debug(1)writefln("before Main.run");
1096 	Main.run();
1097 	debug(1)writefln("after Main.run");
1098 }