I've no idea here...
[gtkD.git] / demos / duit / TestWindow.d
blob6eebba51ad048fc9421311abc793e53b73c04f2d
1 /*
2 * This file is part of dui.
3 *
4 * dui 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 2.1 of the License, or
7 * (at your option) any later version.
8 *
9 * dui 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.
14 * You should have received a copy of the GNU Lesser General Public License
15 * along with dui; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 module duit.TestWindow;
21 //debug = 1;
23 private import cairo.clock;
25 private import gtk.Version;
26 private import gtk.Table;
29 private import gtk.gtktypes;
30 private import gtk.Duit;
31 private import gtk.MainWindow;
32 private import gtk.Adjustment;
33 private import duit.TestEntries;
35 //private import duit.DUITree;
36 private import duit.TestStock;
37 private import duit.TestDrawingArea;
38 private import duit.TestScales;
39 private import duit.TestText;
40 //private import duit.TestTree;
41 private import duit.TestTreeView;
42 private import duit.TestTreeView1;
43 private import duit.TestImage;
44 private import duit.TestThemes;
45 private import duit.TestAspectFrame;
46 private import duit.TestIdle;
47 private import duit.TTextView;
48 //private import duit.TEditableCells;
50 private import gtk.MenuItem;
51 private import gtk.Widget;
52 private import gtk.MenuBar;
53 private import gtk.Notebook;
54 //private import gtk.ComboBoxTextEntry;
55 private import gtk.FileChooserDialog;
56 private import gtk.FileSelection;
57 private import gtk.FontSelectionDialog;
58 private import gtk.ColorSelectionDialog;
59 private import gtk.InputDialog;
60 private import gtk.Button;
61 private import gtk.VBox;
62 private import gtk.MessageDialog;
63 private import gtk.Frame;
64 private import gtk.ObjectGtk;
65 private import gtk.HButtonBox;
66 private import gtk.Statusbar;
67 private import gtk.Menu;
68 private import gtk.HandleBox;
69 private import gtk.Toolbar;
70 private import gtk.RadioButton;
71 private import gtk.CheckButton;
72 private import gtk.ToggleButton;
73 //private import gtk.ListItem;
74 private import gtk.HBox;
75 private import gtk.Arrow;
76 //private import gtk.ListG;
77 //private import gtk.OptionMenu;
78 private import gtk.ButtonBox;
79 private import gtk.Calendar;
80 private import gtk.VButtonBox;
81 private import gtk.SpinButton;
82 private import gtk.ListStore;
83 private import gtk.TreeIter;
84 private import gtk.TreeView;
85 private import gtk.TreeViewColumn;
86 private import gtk.CellRendererText;
87 //private import gtk.SListG;
88 //private import ddi.Drawable;
89 private import gtk.Window;
91 private import gtk.ScrolledWindow;
92 private import gtk.MessageDialog;
95 private import std.gc;
96 private import glib.ListSG;
98 private import gtk.Label;
99 private import glib.ListG;
100 private import gtk.ComboBoxEntry;
101 private import gtk.Paned;
102 private import gtk.HPaned;
103 private import gtk.VPaned;
105 private import gtk.Calendar;
106 private import std.stdio;
107 private import gtk.VButtonBox;
108 private import gtk.FileChooserButton;
109 private import gdk.Drawable;
111 private import gtk.AboutDialog;
113 private import gtk.TreeStore;
114 private import gdk.Pixbuf;
115 private import gtk.ComboBox;
117 private import gtk.TreePath;
118 private import gtk.CellRenderer;
119 private import gtk.CellRendererPixbuf;
122 * This tests the DUI widgets
126 class TestWindow : MainWindow
129 * Executed when the user tries to close the window
130 * @return true to refuse to close the window
132 public: int windowDelete(GdkEvent* event, Widget widget)
135 debug(events) printf("TestWindow.widgetDelete : this and widget to delete %X %X\n",this,window);
136 MessageDialog d = new MessageDialog(
137 this,
138 GtkDialogFlags.MODAL,
139 MessageType.QUESTION,
140 ButtonsType.YES_NO,
141 "Are you sure you want' to exit these DUITests?");
142 int responce = d.run();
143 if ( responce == ResponseType.GTK_RESPONSE_YES )
145 Duit.exit(0);
147 d.destroy();
148 return true;
151 void anyButtonExits(Button button)
153 Duit.exit(0);
156 void popupAbout(MenuItem item)
158 MessageDialog d = new MessageDialog(
159 this,
160 GtkDialogFlags.MODAL,
161 MessageType.INFO,
162 ButtonsType.OK,
163 "Duit D (graphic) User Interface\n"
164 "D OO wrapper for GTK+\n"
165 "by Antonio Monteiro.\n"
166 "Duit is released under the LGPL license\n"
167 "\n"
168 "Send comments and suggestions to duitoolkit@yahoo.ca\n"
169 "or go to the Dui group on dsource.org\n"
171 d.run();
172 d.destroy();
176 this()
178 debug(1) writefln("instantiating TestWindow 1");
179 super("Duit tests");
180 debug(1) writefln("instantiating TestWindow 2");
181 setup();
182 debug(1) writefln("instantiating TestWindow 3");
183 showAll();
184 debug(1) writefln("instantiating TestWindow 4");
186 char[] versionCompare = Version.checkVersion(2,8,0);
187 debug(1) writefln("instantiating TestWindow 5");
188 if ( versionCompare.length > 0 )
190 MessageDialog d = new MessageDialog(this,
191 GtkDialogFlags.MODAL,
192 MessageType.WARNING,
193 ButtonsType.OK,
194 "Duit : Gtk+ version missmatch\n" ~ versionCompare ~
195 "\nYou might run into problems!"
196 "\n\nPress OK to continue");
197 debug(1) writefln("instantiating TestWindow 6");
198 d.run();
199 debug(1) writefln("instantiating TestWindow 7");
200 d.destroy();
202 debug(1) writefln("instantiating TestWindow 8");
206 void setup()
208 debug(1)writefln("TestWindow.setup 1");
209 //Frame.defaultBorder = 7;
211 VBox mainBox = new VBox(false,3);
212 //Table table = new Table(1,5,false);
213 //table.attach(getMenuBar(),0,1,0,1,AttachOptions.EXPAND,AttachOptions.SHRINK,0,0); // adding to the window
214 mainBox.packStart(getMenuBar(),false,false,0);
215 //table.attach(getToolbar(),0,1,1,2,AttachOptions.EXPAND,AttachOptions.SHRINK,0,0);
216 mainBox.packStart(getToolbar(),false,false,0);
218 debug(1)writefln("TestWindow.setup 2");
220 Notebook notebook = setNotebook();
221 notebook.setBorderWidth(10);
222 //table.attach(notebook,0,1,2,3,AttachOptions.EXPAND,AttachOptions.FILL,4,4);
223 mainBox.packStart(notebook,true,true,0);
225 Button cancelButton = new Button(StockID.CANCEL, &anyButtonExits);
226 Button exitButton = new Button(StockID.QUIT, &anyButtonExits);
227 Button quitButton = new Button(StockID.OK, &anyButtonExits);
229 ButtonBox bBox = HButtonBox.createActionBox();
231 debug(1)writefln("TestWindow.setup 3");
233 bBox.packEnd(exitButton,0,0,10);
234 bBox.packEnd(cancelButton,0,0,10);
235 bBox.packEnd(quitButton,0,0,10);
236 //table.attach(bBox,0,1,3,4,AttachOptions.EXPAND,AttachOptions.SHRINK,0,0);
237 mainBox.packStart(bBox,false,false,0);
239 debug(1)writefln("TestWindow.setup 4");
241 Statusbar statusbar = new Statusbar();
243 debug(1)writefln("TestWindow.setup 5");
245 //table.attach(statusbar,0,1,4,5,AttachOptions.EXPAND,AttachOptions.EXPAND,0,0);
246 //add(table);
247 //mainBox.packStart(table,true,true,0);
249 mainBox.packStart(statusbar,false,true,0);
250 add(mainBox);
251 debug(1)writefln("TestWindow.setup 5.1");
252 notebook.appendPage(new TestEntries,"Entry");
253 testEventBox(notebook);
254 testButtons(notebook);
255 debug(1)writefln("TestWindow.setup 5.2");
256 notebook.appendPage(new TestStock,"Stock");
257 testLists(notebook);
258 testNotebook(notebook);
259 debug(1)writefln("TestWindow.setup 5.3");
260 testPaned(notebook);
261 testDialogs(notebook);
262 testViewport(notebook);
263 version(Win32)
265 // todo - threads are still broken on windows
267 else
269 testThreads(notebook);
271 debug(1)writefln("TestWindow.setup 5.4");
272 notebook.appendPage(new TestScales,"Scales");
273 testSpinButton(notebook);
274 debug(1)writefln("TestWindow.setup 5.5");
275 notebook.appendPage(new Label("Deprecated,\nuse TreeView\ninstead"),"Tree");
276 notebook.appendPage(new TestTreeView,"TreeView");
277 notebook.appendPage(new TestTreeView1,"TreeView 1");
278 debug(1)writefln("TestWindow.setup 5.6");
279 testList(notebook);
280 notebook.appendPage(new Frame(new TestDrawingArea,"Drawing Area"),"Drawing");
281 debug(1)writefln("TestWindow.setup 5.7");
282 notebook.appendPage(new TestText,"Text");
283 notebook.appendPage(new TestImage(this),"Image");
284 //notebook.appendPage(new TestThemes(this),"Themes");
285 debug(1)writefln("TestWindow.setup 5.8");
286 notebook.appendPage(new TestAspectFrame(),"Aspect Frame");
287 notebook.appendPage(new TestIdle(),"Idle");
289 notebook.appendPage(new Clock(), "Cairo");
291 gtkDemo(notebook);
292 debug(1)writefln("TestWindow.setup 6");
296 MenuBar getMenuBar()
298 MenuBar menuBar = new MenuBar();
300 Menu menu = menuBar.append("_File");;
301 menu.append(new MenuItem(&onMenuActivate, "_New","file.new"));
302 menu.append(new MenuItem(&onMenuActivate, "_Open","file.open"));
303 menu.append(new MenuItem(&onMenuActivate, "_Close","file.close"));
304 menu.append(new MenuItem(&onMenuActivate, "E_xit","file.exit"));
307 menu = menuBar.append("_Edit");
308 menu.append(new MenuItem(&onMenuActivate,"_Find","edit.find"));
309 menu.append(new MenuItem(&onMenuActivate,"_Search","edit.search"));
311 menu = menuBar.append("_Help");
312 menu.append(new MenuItem(&onMenuActivate,"_About","help.about"));
314 return menuBar;
317 class DuitAbout : AboutDialog
319 this()
321 char** names = (new char*[2]).ptr;
322 int i = 0;
323 names[i++] = cast(char*)"Antonio Monteiro (binding/wrapping/proxying/decorating for D)";
324 names[i++] = cast(char*)"www.gtk.org (base C library)";
325 setAuthors(names);
326 setDocumenters(names);
327 setArtists(names);
328 setLicense("License is LGPL");
329 setWebsite("http://lisdev.com");
333 void onMenuActivate(MenuItem menuItem)
335 char[] action = menuItem.getActionName();
336 switch( action )
338 case "help.about":
339 (new AboutDialog()).showAll();
340 // MessageDialog d = new MessageDialog(
341 // this,
342 // GtkDialogFlags.MODAL,
343 // MessageType.INFO,
344 // ButtonsType.OK,
345 // "DUI D (graphic) User Interface\n"
346 // "an implementation through GTK+\n"
347 // "by Antonio Monteiro.\n"
348 // "DUI is released under the LGPL license\n"
349 // "\n"
350 // "Send comments and suggestions to duitoolkit@yahoo.ca\n"
351 // "or go to the yahoo group\n"
352 // "http://groups.yahoo.com/group/duitoolkit\n"
353 // "(Group email: duitoolkit@yahoogroups.com)\n"
354 // "\n"
355 // "See detailed information at DUI home page\n"
356 // "http://ca.geocities.com/duitoolkit\n"
357 // );
358 // d.run();
359 // d.destroy();
360 break;
361 default:
362 MessageDialog d = new MessageDialog(
363 this,
364 GtkDialogFlags.MODAL,
365 MessageType.INFO,
366 ButtonsType.OK,
367 "You pressed menu item "~action);
368 d.run();
369 d.destroy();
370 break;
375 Widget getToolbar()
377 HandleBox handleBox = new HandleBox();
378 Toolbar toolbar = new Toolbar();
379 toolbar.appendWidget(new Button(StockID.OPEN, true),"Toolbar button 1","Private text 1");
380 toolbar.appendWidget(new Button(StockID.CLOSE, true),"Toolbar button 2","Private text 2");
381 toolbar.appendSpace();
382 toolbar.appendWidget(new Button(StockID.SAVE, true),"Toolbar button 3","Private text 3");
383 toolbar.appendWidget(new Button(StockID.SAVE_AS, true),"Toolbar button 4","Private text 4");
385 handleBox.add(toolbar);
387 return handleBox;
391 Notebook setNotebook()
393 Notebook notebook = new Notebook();
394 notebook.addOnSwitchPage(&onNotebookSwitchPage);
395 notebook.setTabPos(PositionType.LEFT);
396 return notebook;
399 void onNotebookSwitchPage(GtkNotebookPage *notePage, uint pageNumber, Notebook notebook)
401 //writefln("Notebook switch to page %s", pageNumber);
402 // fullCollect helps finding objects that shouldn't have been collected
403 std.gc.fullCollect();
404 //writefln("exiting Notebook switch to page %s", pageNumber);
407 //private import dui.EventBox;
409 void testEventBox(Notebook notebook)
412 // EventBox eventBox = new EventBox();
413 // eventBox.add(new Label("label on event box"));
414 // notebook.appendPage(eventBox,"Buttons");
416 //EventBox eventBox = new EventBox();
417 //eventBox.add(new Label("label on event box"));
418 notebook.appendPage(new Label("just a simple label"),new Label("label"));
422 void testButtons(Notebook notebook)
425 Table table = new Table(2,12,0);
427 //ListSG listSG = new ListSG();
429 RadioButton radio1Button = new RadioButton(cast(ListSG)null,"Option 1");
430 RadioButton radio2Button = new RadioButton(radio1Button,"Option 2");
431 RadioButton radio3Button = new RadioButton(radio2Button,"Option 3");
432 RadioButton radio4Button = new RadioButton(radio3Button,"Option 4");
433 RadioButton radio5Button = new RadioButton(radio4Button,"Option 5");
434 RadioButton radio6Button = new RadioButton(radio5Button,"Option 6");
435 RadioButton radio7Button = new RadioButton(radio6Button,"Option 7");
436 RadioButton radio8Button = new RadioButton(radio7Button,"Option 8");
437 RadioButton radio9Button = new RadioButton(radio8Button,"Option 9");
438 table.attach(radio1Button,0,1,0,1,AttachOptions.FILL,AttachOptions.FILL,4,4);
439 table.attach(radio2Button,0,1,1,2,AttachOptions.FILL,AttachOptions.FILL,4,4);
440 table.attach(radio3Button,0,1,2,3,AttachOptions.FILL,AttachOptions.FILL,4,4);
441 table.attach(radio4Button,0,1,3,4,AttachOptions.FILL,AttachOptions.FILL,4,4);
442 table.attach(radio5Button,0,1,4,5,AttachOptions.FILL,AttachOptions.FILL,4,4);
443 table.attach(radio6Button,0,1,5,6,AttachOptions.FILL,AttachOptions.FILL,4,4);
444 table.attach(radio7Button,0,1,6,7,AttachOptions.FILL,AttachOptions.FILL,4,4);
445 table.attach(radio8Button,0,1,7,8,AttachOptions.FILL,AttachOptions.FILL,4,4);
446 table.attach(radio9Button,0,1,8,9,AttachOptions.FILL,AttachOptions.FILL,4,4);
448 CheckButton editableButton = new CheckButton("editable");
449 CheckButton visibleButton = new CheckButton("visible");
450 table.attach(editableButton,0,1,9,10,AttachOptions.FILL,AttachOptions.FILL,4,4);
451 table.attach(visibleButton,0,1,10,11,AttachOptions.FILL,AttachOptions.FILL,4,4);
453 ToggleButton toggleButton = new ToggleButton("Toggle this");
454 table.attach(toggleButton,0,1,11,12,AttachOptions.FILL,AttachOptions.FILL,4,4);
456 Button button = new Button("test events");
457 table.attach(button,0,1,12,13,AttachOptions.FILL,AttachOptions.FILL,4,4);
459 void bActivate(Button button)
461 printf("button Activate\n");
463 void bClicked(Button button)
465 printf("button Clicked\n");
467 void bEnter(Button button)
469 printf("button Enter\n");
471 void bLeave(Button button)
473 printf("button Leave\n");
475 void bPressed(Button button)
477 printf("button Pressed\n");
479 void bReleased(Button button)
481 printf("button Released\n");
483 button.addOnActivate(&bActivate);
484 button.addOnClicked(&bClicked);
485 button.addOnEnter(&bEnter);
486 button.addOnLeave(&bLeave);
487 button.addOnPressed(&bPressed);
488 button.addOnReleased(&bReleased);
490 // for ( ShadowType shadow = 0; shadow<=ShadowType.max ; shadow ++)
491 // {
492 // for ( DirectionType direction = 0 ; direction<=DirectionType.max ; direction++)
493 // {
494 // table.attach(new Arrow(direction,shadow),direction+1,direction+2,shadow,shadow+1,AttachOptions.FILL,AttachOptions.FILL,4,4);
495 // table.attach(new Arrow(direction,shadow),direction+1,direction+2,shadow,shadow+1,AttachOptions.FILL,AttachOptions.FILL,4,4);
496 // table.attach(new Arrow(direction,shadow),direction+1,direction+2,shadow,shadow+1,AttachOptions.FILL,AttachOptions.FILL,4,4);
497 // table.attach(new Arrow(direction,shadow),direction+1,direction+2,shadow,shadow+1,AttachOptions.FILL,AttachOptions.FILL,4,4);
498 // }
499 // }
502 notebook.appendPage(new Frame(table,"Buttons"),"Buttons");
506 class ComboStore : TreeStore
508 this()
510 //int* i = cast(int*)pixbufGetType();
512 GType[] columns;
513 columns ~= GType.STRING;
514 columns ~= GType.STRING;
515 super(columns);
521 void testLists(Notebook notebook)
523 VBox mainBox = new VBox(false,3);
525 // comboBoxTextEntry from a list of strings
526 mainBox.packStart(new Label("String combo"),false,true,0);
527 static char[][] cbList = ["item 1","item 2","item 3","item 4","item 5","item 6","item 7","item 8","item 9"];
528 comboText = new ComboBoxEntry();
529 char[] entry3 = "Combo box text entry 3";
530 comboText.appendText("Combo box text entry 1");
531 comboText.appendText("Combo box text entry 2");
532 comboText.appendText(entry3);
533 comboText.appendText("Combo box text entry 4");
534 comboText.appendText("Combo box text entry 5");
535 comboText.setActive(2);
537 ButtonBox actionBox1 = HButtonBox.createActionBox();
538 actionBox1.packStart(comboText,false,false,0);
540 Button showCombo1 = new Button("ShowCombo", &showTextCombo);
541 actionBox1.packStart(showCombo1,false,false,0);
543 mainBox.packStart(new Frame(actionBox1, "Text entry ComboBox"),false,false,0);
547 // TODO combo with widgets
550 // new ComboBox + TreeModel
552 ComboStore comboStore = new ComboStore();
554 TreeIter iterFirst; // to set the first active iter
555 TreeIter iterChild;
556 TreeIter iterTop = comboStore.append(null);
557 comboStore.setValue(iterTop, 0, "Paganini" );
558 iterFirst = comboStore.append(iterTop);
559 comboStore.setValue(iterFirst, 0, "Nicolo" );
561 iterTop = comboStore.append(null);
562 comboStore.setValue(iterTop, 0, "List" );
563 iterChild = comboStore.append(iterTop);
564 comboStore.setValue(iterChild, 0, "Franz" );
566 iterTop = comboStore.append(null);
567 comboStore.setValue(iterTop, 0, "Beethoven" );
568 iterChild = comboStore.append(iterTop);
569 comboStore.setValue(iterChild, 0, "Ludwic" );
570 iterChild = comboStore.append(iterTop);
571 comboStore.setValue(iterChild, 0, "Maria" );
572 iterChild = comboStore.append(iterTop);
573 comboStore.setValue(iterChild, 0, "Van" );
575 iterTop = comboStore.append(null);
576 comboStore.setValue(iterTop, 0, "Bach" );
577 iterChild = comboStore.append(iterTop);
578 comboStore.setValue(iterChild, 0, "Johann" );
579 iterChild = comboStore.append(iterTop);
580 comboStore.setValue(iterChild, 0, "Sebastian" );
582 ComboBox treeCombo = new ComboBox(comboStore);
583 treeCombo.setWrapWidth(1);
584 CellRenderer renderer = new CellRendererText();
585 treeCombo.packStart(renderer, true);
586 treeCombo.addAttribute(renderer, "text",0);
588 // TODO something is wrong gettign the ier from the path
589 //TreePath path = new TreePath("0,0");
590 //comboStore.getIter(iterChild, path);
591 //treeCombo.setActiveIter(iterChild);
592 // use a previously set iter
593 treeCombo.setActiveIter(iterFirst);
595 mainBox.packStart(new Frame(treeCombo,"Tree Combo box"),false,true,0);
597 simpleCombo = new ComboBox();
598 simpleCombo.appendText("Top");
599 simpleCombo.appendText("Bottom");
600 simpleCombo.appendText("Left");
601 simpleCombo.appendText("Right");
602 simpleCombo.setActive(0);
604 // actions
606 ButtonBox actionBox = HButtonBox.createActionBox();
607 actionBox.packStart(simpleCombo,false,false,0);
609 Button showCombo = new Button("ShowCombo", &showSimpleCombo);
610 actionBox.packStart(showCombo,false,false,0);
612 mainBox.packStart(new Frame(actionBox, "Simple text list"),false,false,0);
614 notebook.appendPage(new Frame(mainBox,"Lists"),"Lists");
617 ComboBox simpleCombo;
618 ComboBoxEntry comboText;
620 void showTextCombo(Button button)
622 printf("Combo selected text = %.*s\n",comboText.getActiveText());
625 void showSimpleCombo(Button button)
627 printf("Combo selected text = %.*s\n",simpleCombo.getActiveText());
630 class NB : Notebook
632 void itemActivated(MenuItem menu_item)
634 printf("NB.activateCallback\n");
636 void buttonClicked(Button button)
638 setCurrentPage(2);
641 void switchPage(Notebook notebook, /*NotebookPage page,*/ guint pageNumber)
643 printf("new page = %d\n",pageNumber);
648 NB nb;
650 void posLeft(Button button)
652 nb.setTabPos(PositionType.LEFT);
654 void posRight(Button button)
656 nb.setTabPos(PositionType.RIGHT);
658 void posTop(Button button)
660 nb.setTabPos(PositionType.TOP);
662 void posBottom(Button button)
664 nb.setTabPos(PositionType.BOTTOM);
668 * tests notebook
669 * @param nodebook
671 void testNotebook(Notebook notebook)
674 nb = new NB();
675 nb.setTabPos(PositionType.min);
676 nb.popupEnable();
677 nb.setShowBorder(false);
678 nb.setBorderWidth(0);
680 class PageMove
682 Notebook notebook;
683 PositionType toPos;
684 this(Notebook notebook,PositionType toPos)
686 this.notebook = notebook;
687 this.toPos = toPos;
689 void buttonClickedCallback()
691 notebook.setTabPos(toPos);
695 PageMove toLeft = new PageMove(nb,PositionType.LEFT);
696 PageMove toRight = new PageMove(nb,PositionType.RIGHT);
697 PageMove toTop = new PageMove(nb,PositionType.TOP);
698 PageMove toBottom = new PageMove(nb,PositionType.BOTTOM);
701 notebook.appendPage(nb,new Label("Notebook"));
703 for( char i = '1' ; i<'5' ; i++ )
705 Table table = new Table(2,2,true);
706 Button left = new Button("Left "~ i);
707 left.addOnClicked(&posLeft);
708 Button right = new Button("Right "~ i);
709 right.addOnClicked(&posRight);
710 Button top = new Button("top "~ i);
711 top.addOnClicked(&posTop);
712 Button bottom = new Button("bottom "~ i);
713 bottom.addOnClicked(&posBottom);
715 table.attach(top,0,1,0,1,AttachOptions.SHRINK,AttachOptions.SHRINK,4,4);
716 table.attach(right,1,2,0,1,AttachOptions.SHRINK,AttachOptions.SHRINK,4,4);
717 table.attach(left,0,1,1,2,AttachOptions.SHRINK,AttachOptions.SHRINK,4,4);
718 table.attach(bottom,1,2,1,2,AttachOptions.SHRINK,AttachOptions.SHRINK,4,4);
719 if ( i == 3 )
722 // MenuItem menuItem = new MenuItem("menu page 3",&nb.itemActivated);
724 // Menu menu = new Menu();
725 // menu.append(new MenuItem("page 3.1",&nb.itemActivated));
726 // menu.append(new MenuItem("page 3.2",&nb.itemActivated));
727 // menu.append(new MenuItem("page 3.3",&nb.itemActivated));
728 // menu.append(new MenuItem("page 3.4",&nb.itemActivated));
730 // menuItem.setSubmenu(menu);
732 HBox box = new HBox(false,0);
733 box.setBorderWidth(0);
734 Button button = new Button("Page " ~ i ~ "\0");
735 button.addOnClicked(&nb.buttonClicked);
736 button.setBorderWidth(0);
737 button.setRelief(ReliefStyle.NONE);
738 CheckButton checkButton = new CheckButton();
739 checkButton.setBorderWidth(0);
740 box.packStart(checkButton,false,false,0);
741 box.packStart(button,false,false,0);
742 //nb.appendPageMenu(table,box,menuItem);
743 //nb.appendPage(table,box);
745 else
747 nb.appendPage(table,new Label("Page " ~ i ~ "\0"));
750 //nb.addOnSwitchPage(&nb.switchPage);
753 void testPaned(Notebook notebook)
756 Paned mainPaned = new VPaned();
757 Paned p0 = mainPaned;
758 Button p1;
759 Paned p2;
761 bit h = true;
762 for ( char c='1' ; c<='5' ; c++ )
764 p1 = new Button("Pane "~c);
765 if ( h ) p2 = new HPaned();
766 else p2 = new VPaned();
768 p0.add1(p1);
769 p0.add2(p2);
770 p0 = p2;
771 h = !h;
774 notebook.appendPage(mainPaned,new Label("Paned"));
778 FileChooserDialog fcd;
779 FileSelection fs;
780 FontSelectionDialog f;
781 ColorSelectionDialog d;
782 InputDialog id;
784 void showFileChooser(Button button)
786 char[][] a;
787 ResponseType[] r;
788 a ~= "Lets go!";
789 a ~= "Please don't";
790 r ~= ResponseType.GTK_RESPONSE_OK;
791 r ~= ResponseType.GTK_RESPONSE_CANCEL;
792 if ( fcd is null )
794 fcd = new FileChooserDialog("File Chooser", this, FileChooserAction.OPEN, a, r);
797 fcd.getFileChooser().setSelectMultiple(true);
798 fcd.run();
799 // writefln("file selected = %s",fcd.getFileName());
801 // foreach ( int i, char[] selection ; fs.getSelections())
802 // {
803 // printf("File(s) selected [%d] %.*s\n",i,selection);
804 // }
805 fcd.hide();
810 void showFileSel(Button button)
812 if ( fs is null )
814 fs = new FileSelection("File Selection");
816 //fs.showAll();
817 //fs.setMultiple(true);
818 fs.run();
819 //printf("file selected = %.*s\n",fs.getFileName());
820 // char[][] selections = fs.getSelections();
821 // for ( int i=0 ;i<selections.length ; i++)
822 // {
823 // printf("File(s) selected [%d] %.*s\n",i,selections[i]);
824 // }
825 fs.hide();
828 void showColor(Button button)
830 if ( d is null )
832 d = new ColorSelectionDialog("Select the color");
834 d.run();
835 d.hide();
838 void showInput(Button button)
840 if ( id is null )
842 id = new InputDialog();
844 id.run();
845 id.hide();
848 void showCalendar(Button button)
850 Window calWin = new Window("Calendar");
851 Calendar calendar = new Calendar();
852 //calendar.setTitle("No Title");
853 calWin.add(calendar);
854 calWin.showAll();
857 void showFont(Button button)
859 if ( f is null )
861 f = new FontSelectionDialog("Select the font");
863 f.run();
864 char[] fontName = f.getFontName();
865 f.hide();
868 Button fontButton;
870 void testDialogs(Notebook notebook)
873 ButtonBox bBox = VButtonBox.createActionBox();
875 if ( fcd is null )
877 fcd = new FileChooserDialog("File Chooser", this, FileChooserAction.OPEN);
881 Button fileChooser = new Button("File Chooser", &showFileChooser);
882 FileChooserButton fcb = new FileChooserButton(fcd);
884 Button fileSel = new Button("File Selection", &showFileSel);
885 Button color = new Button("Color Dialog", &showColor);
886 Button input = new Button("Input Dialog", &showInput);
887 Button calendar = new Button("Calendar Dialog", &showCalendar);
888 fontButton = new Button("Font Dialog", &showFont);
889 //fontButton.modifyFont("[Newspaper][16]");
891 bBox.packStart(fileChooser,0,0,10);
892 bBox.packStart(fcb,0,0,10);
893 bBox.packStart(fileSel,0,0,10);
894 bBox.packStart(color,0,0,10);
895 bBox.packStart(input,0,0,10);
896 bBox.packStart(calendar,0,0,10);
897 bBox.packStart(fontButton,0,0,10);
899 notebook.appendPage(new Frame(bBox,"Dialogs"),new Label("Dialogs"));
903 Button[] threadTestButtons;
904 private import std.thread;
905 private import std.random;
906 private import gdk.Threads;
907 static T1[] t1s;
908 class T1 : Thread
910 int num;
911 this(int num)
913 super(&run);
914 this.num = num;
917 int run()
919 while(1)
921 int buttonNum = rand()%threadTestButtons.length;
922 Button button = threadTestButtons[buttonNum];
923 gdkThreadsEnter();
924 button.removeAll();
925 button.setLabel(std.string.format("%s", num));
926 gdkThreadsLeave();
927 yield();
929 return 1;
933 void testThreads(Notebook notebook)
936 Table grid = new Table(8,8,0);
937 for ( int i = 0 ; i<8 ; i++)
939 for ( int j = 0 ; j<8; j++)
941 Button button = new Button(std.string.format("%s",(j+8*i)));
942 threadTestButtons ~= button;
943 grid.attach( button,
944 i,i+1,
945 j,j+1,
946 AttachOptions.SHRINK,AttachOptions.SHRINK,4,4);
948 t1s ~= new T1(j+8*i);
952 void stop(Button button)
954 foreach ( T1 t ; t1s )
956 switch( t.getState() )
958 case Thread.TS.RUNNING:
959 t.pause();
960 break;
962 default:
963 break;
968 void go(Button button)
970 foreach ( T1 t ; t1s )
972 switch( t.getState() )
974 case Thread.TS.INITIAL:
975 t.start();
976 break;
978 default:
979 t.resume();
980 break;
985 VBox vbox = new VBox(false, 2);
986 vbox.packStart(grid, true, true,2);
987 ButtonBox actions = HButtonBox.createActionBox();
989 Button button = new Button(StockID.STOP, &stop);
990 actions.packStart(button, false, false, 7);
991 button = new Button(StockID.OK, &go);
992 actions.packStart(button, false, false, 7);
994 vbox.packStart(actions, false, false, 2);
996 notebook.appendPage(vbox,new Label("Threads"));
1001 void testViewport(Notebook notebook)
1004 Table grid = new Table(21,21,0);
1005 for ( int i = 0 ; i<21 ; i++)
1007 for ( int j = 0 ; j<21; j++)
1009 if ( (i == j) || (i+j==20) || (i==10) || (j==10))
1011 grid.attach(
1012 new Button("Button"),
1013 i,i+1,
1014 j,j+1,
1015 AttachOptions.SHRINK,AttachOptions.SHRINK,4,4);
1020 ScrolledWindow sw = new ScrolledWindow(null,null);
1021 sw.addWithViewport(grid);
1022 notebook.appendPage(sw,new Label("Viewport"));
1025 void testSpinButton(Notebook notebook)
1027 Table table = new Table(2,1,false);
1029 SpinButton spin = new SpinButton(new Adjustment(1.0, 0.0, 100.0, 1.0, 10.0, 10.0),1,0);
1030 table.attach(new Label("Sping this:"),0,1,0,1,AttachOptions.FILL,AttachOptions.FILL,4,4);
1031 table.attach(spin,1,2,0,1,AttachOptions.FILL,AttachOptions.FILL,4,4);
1033 notebook.appendPage(table,"Spin Buttons");
1037 void testList(Notebook notebook)
1039 class TestListStore : ListStore
1041 this()
1043 static GType [3] columns = [
1044 GType.STRING,
1045 GType.STRING,
1046 GType.STRING
1048 super(columns);
1052 TestListStore testListStore = new TestListStore();
1054 TreeIter iterTop = testListStore.createIter();
1056 static int [3] cols = [0,1,2];
1057 char[][] vals;
1058 vals ~= "Antonio";
1059 vals ~= "Canada";
1060 vals ~= "Ontario";
1061 testListStore.set(iterTop,cols,vals);
1063 testListStore.append(iterTop);
1064 char[][] vals1;
1065 vals1 ~= "John Reimer";
1066 vals1 ~= "Canada";
1067 vals1 ~= "BC";
1068 testListStore.set(iterTop,cols,vals1);
1070 testListStore.append(iterTop);
1071 char[][] vals2;
1072 vals2 ~= "Friend of Duit 2";
1073 vals2 ~= "Poland";
1074 vals2 ~= "Torun";
1075 testListStore.set(iterTop,cols,vals2);
1077 testListStore.append(iterTop);
1078 char[][] vals3;
1079 vals3 ~= "Friend of Duit 3";
1080 vals3 ~= "Norway";
1081 vals3 ~= "Norway";
1082 testListStore.set(iterTop,cols,vals3);
1084 TreeView treeView = new TreeView(testListStore);
1085 treeView.setHeadersClickable(true);
1086 treeView.setRulesHint(true);
1088 //CellRendererText cellText = new CellRendererText();
1089 TreeViewColumn column = new TreeViewColumn("Author",new CellRendererText(),"text", 0);
1090 treeView.appendColumn(column);
1091 column.setResizable(true);
1092 column.setReorderable(true);
1093 column.setSortColumnId(0);
1094 column.setSortIndicator(true);
1096 column = new TreeViewColumn("Country",new CellRendererText(),"text", 1);
1097 treeView.appendColumn(column);
1098 column.setResizable(true);
1099 column.setReorderable(true);
1100 column.setSortColumnId(1);
1101 column.setSortIndicator(true);
1103 column = new TreeViewColumn("Province",new CellRendererText(),"text", 2);
1104 treeView.appendColumn(column);
1105 column.setResizable(true);
1106 column.setReorderable(true);
1107 column.setSortColumnId(2);
1108 column.setSortIndicator(true);
1110 //notebook.appendPage(treeView,"ListView");
1111 ScrolledWindow sw = new ScrolledWindow(null,null);
1112 sw.addWithViewport(treeView);
1113 notebook.appendPage(sw,"ListView");
1117 void testDelete(Notebook notebook)
1119 // ulong l = 0;
1120 // while(true)
1121 // {
1122 // int i =0;
1123 // while(i<1 )
1124 // {
1125 // //Button b = new Button("Button");
1126 // Drawable d = getDrawable();
1127 // delete d;
1128 // ++i;
1129 // }
1130 // ++l;
1131 // printf("testDelete count = %d\n\0",l*i);
1132 // }
1136 void gtkDemo(Notebook notebook)
1138 void showTTextView(Button button)
1140 new TTextView();
1143 void showTEditableCells(Button button)
1145 // new TEditableCells();
1148 ButtonBox vBBox = VButtonBox.createActionBox();
1150 Button button = new Button("Text View");
1151 button.addOnClicked(&showTTextView);
1152 vBBox.packStart(button,false,false,4);
1154 button = new Button("Editable Cells");
1155 button.addOnClicked(&showTEditableCells);
1156 vBBox.packStart(button,false,false,4);
1158 notebook.appendPage(vBBox,"gtk-demo");
1164 private import lib.Loader;
1166 void main(char[][] args)
1169 Linker.dumpFailedLoads();
1171 version(Win32)
1173 // todo threads are still broken on windows...
1174 Duit.init(args);
1176 else
1178 Duit.initMultiThread(args);
1181 TestWindow window = new TestWindow();
1183 debug(1)writefln("before Duit.main");
1184 Duit.main();
1185 debug(1)writefln("after Duit.main");