Made it compile with latest Tango and dsss. Also gtkDTests work now. Couple of change...
[gtkD.git] / gtkD / demos / gtkD / TestWindow.d
bloba7aadeafa8ab6c1b7fa9ee142a2e9b1058a0973e
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 2.1 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.
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 module gtkD.TestWindow;
21 //debug = 1;
23 //version=cairo;
25 version(cairo)private import cairo.clock;
27 private import gtk.Version;
28 private import gtk.Table;
30 version(Tango)private import tango.text.convert.Layout;
31 version(Tango) private import tango.core.Thread;
32 else private import std.thread;
33 version(Tango) private import tango.math.Random;
34 else private import std.random;
36 import gdk.Threads;
39 private import gtkc.gtktypes;
40 private import gtk.GtkD;
41 private import gtk.MainWindow;
42 private import gtk.Adjustment;
43 private import gtk.AccelGroup;
45 private import gtkD.TestEntries;
47 //private import gtkD.gtkDTree;
48 private import gtkD.TestStock;
49 private import gtkD.TestDrawingArea;
50 private import gtkD.TestScales;
51 private import gtkD.TestText;
52 //private import gtkD.TestTree;
53 private import gtkD.TestTreeView;
54 private import gtkD.TestTreeView1;
55 private import gtkD.TestImage;
56 private import gtkD.TestThemes;
57 private import gtkD.TestAspectFrame;
58 private import gtkD.TestIdle;
59 private import gtkD.TTextView;
60 //private import gtkD.TEditableCells;
62 private import gtk.MenuItem;
63 private import gtk.Widget;
64 private import gtk.MenuBar;
65 private import gtk.Notebook;
66 //private import gtk.ComboBoxTextEntry;
67 private import gtk.FileChooserDialog;
68 private import gtk.FileSelection;
69 private import gtk.FontSelectionDialog;
70 private import gtk.ColorSelectionDialog;
71 private import gtk.InputDialog;
72 private import gtk.Button;
73 private import gtk.VBox;
74 private import gtk.MessageDialog;
75 private import gtk.Frame;
76 private import gtk.ObjectGtk;
77 private import gtk.HButtonBox;
78 private import gtk.Statusbar;
79 private import gtk.Menu;
80 private import gtk.HandleBox;
81 private import gtk.Toolbar;
82 private import gtk.RadioButton;
83 private import gtk.CheckButton;
84 private import gtk.ToggleButton;
85 //private import gtk.ListItem;
86 private import gtk.HBox;
87 private import gtk.Arrow;
88 //private import gtk.ListG;
89 //private import gtk.OptionMenu;
90 private import gtk.ButtonBox;
91 private import gtk.Calendar;
92 private import gtk.VButtonBox;
93 private import gtk.SpinButton;
94 private import gtk.ListStore;
95 private import gtk.TreeIter;
96 private import gtk.TreeView;
97 private import gtk.TreeViewColumn;
98 private import gtk.CellRendererText;
99 //private import gtk.SListG;
100 //private import ddi.Drawable;
101 private import gtk.Window;
103 private import gtk.ScrolledWindow;
104 private import gtk.MessageDialog;
108 version(Tango) private import tango.core.Memory;
109 else private import std.gc;
110 private import glib.ListSG;
112 private import gtk.Label;
113 private import glib.ListG;
114 private import gtk.ComboBoxEntry;
115 private import gtk.Paned;
116 private import gtk.HPaned;
117 private import gtk.VPaned;
119 private import gtk.Calendar;
120 version(Tango) private import tango.io.Stdout;
121 version(Tango) private import tango.stdc.stdio;
122 else private import std.stdio;
123 private import gtk.VButtonBox;
124 private import gtk.FileChooserButton;
125 private import gdk.Drawable;
127 private import gtk.AboutDialog;
129 private import gtk.TreeStore;
130 private import gdk.Pixbuf;
131 private import gtk.ComboBox;
133 private import gtk.TreePath;
134 private import gtk.CellRenderer;
135 private import gtk.CellRendererPixbuf;
138 * This tests the DUI widgets
142 class TestWindow : MainWindow
145 * Executed when the user tries to close the window
146 * @return true to refuse to close the window
148 public: int windowDelete(GdkEvent* event, Widget widget)
151 debug(events) printf("TestWindow.widgetDelete : this and widget to delete %X %X\n",this,window);
152 MessageDialog d = new MessageDialog(
153 this,
154 GtkDialogFlags.MODAL,
155 MessageType.QUESTION,
156 ButtonsType.YES_NO,
157 "Are you sure you want' to exit these GtkDTests?");
158 int responce = d.run();
159 if ( responce == ResponseType.GTK_RESPONSE_YES )
161 GtkD.exit(0);
163 d.destroy();
164 return true;
167 void anyButtonExits(Button button)
169 GtkD.exit(0);
172 void popupAbout(MenuItem item)
174 MessageDialog d = new MessageDialog(
175 this,
176 GtkDialogFlags.MODAL,
177 MessageType.INFO,
178 ButtonsType.OK,
179 "GtkD D (graphic) User Interface\n"
180 "D OO wrapper for GTK+\n"
181 "by Antonio Monteiro.\n"
182 "GtkD is released under the LGPL license\n"
183 "\n"
184 "Send comments and suggestions to gtkDoolkit@yahoo.ca\n"
185 "or go to the Dui group on dsource.org\n"
187 d.run();
188 d.destroy();
192 this()
194 debug(Tango) Stdout("Instantiating TestWindow 1.").newline;
195 debug(1) writefln("instantiating TestWindow 1");
196 super("GtkD tests");
197 debug(Tango) Stdout("Instantiating TestWindow 2.").newline;
198 debug(1) writefln("instantiating TestWindow 2");
199 setup();
200 debug(Tango) Stdout("Instantiating TestWindow 3.").newline;
201 debug(1) writefln("instantiating TestWindow 3");
202 showAll();
203 debug(Tango) Stdout("Instantiating TestWindow 4.").newline;
204 debug(1) writefln("instantiating TestWindow 4");
206 char[] versionCompare = Version.checkVersion(2,8,0);
207 debug(Tango) Stdout("Instantiating TestWindow 5.").newline;
208 debug(1) writefln("instantiating TestWindow 5");
209 if ( versionCompare.length > 0 )
211 MessageDialog d = new MessageDialog(this,
212 GtkDialogFlags.MODAL,
213 MessageType.WARNING,
214 ButtonsType.OK,
215 "GtkD : Gtk+ version missmatch\n" ~ versionCompare ~
216 "\nYou might run into problems!"
217 "\n\nPress OK to continue");
218 debug(Tango) Stdout("Instantiating TestWindow 6.").newline;
219 debug(1) writefln("instantiating TestWindow 6");
220 d.run();
221 debug(Tango) Stdout("Instantiating TestWindow 7.").newline;
222 debug(1) writefln("instantiating TestWindow 7");
223 d.destroy();
225 debug(Tango) Stdout("Instantiating TestWindow 8.").newline;
226 debug(1) writefln("instantiating TestWindow 8");
230 void setup()
232 debug(Tango) Stdout("TestWindow.setup 1").newline;
233 debug(1)writefln("TestWindow.setup 1");
234 //Frame.defaultBorder = 7;
237 VBox mainBox = new VBox(false,3);
238 //Table table = new Table(1,5,false);
239 //table.attach(getMenuBar(),0,1,0,1,AttachOptions.EXPAND,AttachOptions.SHRINK,0,0); // adding to the window
240 mainBox.packStart(getMenuBar(),false,false,0);
241 //table.attach(getToolbar(),0,1,1,2,AttachOptions.EXPAND,AttachOptions.SHRINK,0,0);
242 mainBox.packStart(getToolbar(),false,false,0);
244 debug(Tango) Stdout("TestWindow.setup 2").newline;
245 debug(1)writefln("TestWindow.setup 2");
247 Notebook notebook = setNotebook();
248 notebook.setBorderWidth(10);
249 //table.attach(notebook,0,1,2,3,AttachOptions.EXPAND,AttachOptions.FILL,4,4);
250 mainBox.packStart(notebook,true,true,0);
252 Button cancelButton = new Button(StockID.CANCEL, &anyButtonExits);
253 Button exitButton = new Button(StockID.QUIT, &anyButtonExits);
254 Button quitButton = new Button(StockID.OK, &anyButtonExits);
256 ButtonBox bBox = HButtonBox.createActionBox();
258 debug(Tango) Stdout("TestWindow.setup 3").newline;
259 debug(1)writefln("TestWindow.setup 3");
261 bBox.packEnd(exitButton,0,0,10);
262 bBox.packEnd(cancelButton,0,0,10);
263 bBox.packEnd(quitButton,0,0,10);
264 //table.attach(bBox,0,1,3,4,AttachOptions.EXPAND,AttachOptions.SHRINK,0,0);
265 mainBox.packStart(bBox,false,false,0);
267 debug(Tango) Stdout("TestWindow.setup 4").newline;
268 debug(1)writefln("TestWindow.setup 4");
270 Statusbar statusbar = new Statusbar();
272 debug(Tango) Stdout("TestWindow.setup 5").newline;
273 debug(1)writefln("TestWindow.setup 5");
275 //table.attach(statusbar,0,1,4,5,AttachOptions.EXPAND,AttachOptions.EXPAND,0,0);
276 //add(table);
277 //mainBox.packStart(table,true,true,0);
279 mainBox.packStart(statusbar,false,true,0);
280 add(mainBox);
281 debug(Tango) Stdout("TestWindow.setup 5.1").newline;
282 debug(1)writefln("TestWindow.setup 5.1");
283 notebook.appendPage(new TestEntries,"Entry");
284 testEventBox(notebook);
285 testButtons(notebook);
286 debug(Tango) Stdout("TestWindow.setup 5.2").newline;
287 debug(1)writefln("TestWindow.setup 5.2");
288 notebook.appendPage(new TestStock,"Stock");
289 testLists(notebook);
290 testNotebook(notebook);
291 debug(Tango) Stdout("TestWindow.setup 5.3").newline;
292 debug(1)writefln("TestWindow.setup 5.3");
293 testPaned(notebook);
294 testDialogs(notebook);
295 testViewport(notebook);
296 version(Win32)
298 // todo - threads are still broken on windows
300 else
302 testThreads(notebook);
304 debug(Tango) Stdout("TestWindow.setup 5.4").newline;
305 debug(1)writefln("TestWindow.setup 5.4");
306 notebook.appendPage(new TestScales,"Scales");
307 testSpinButton(notebook);
308 debug(Tango) Stdout("TestWindow.setup 5.5").newline;
309 debug(1)writefln("TestWindow.setup 5.5");
310 notebook.appendPage(new Label("Deprecated,\nuse TreeView\ninstead"),"Tree");
311 notebook.appendPage(new TestTreeView,"TreeView");
312 notebook.appendPage(new TestTreeView1,"TreeView 1");
313 debug(Tango) Stdout("TestWindow.setup 5.6").newline;
314 debug(1)writefln("TestWindow.setup 5.6");
315 testList(notebook);
316 debug(Tango) Stdout("TestWindow.setup 5.6.1").newline;
317 notebook.appendPage(new Frame(new TestDrawingArea,"Drawing Area"),"Drawing");
318 debug(Tango) Stdout("TestWindow.setup 5.7").newline;
319 debug(1)writefln("TestWindow.setup 5.7");
320 notebook.appendPage(new TestText,"Text");
321 notebook.appendPage(new TestImage(this),"Image");
322 //notebook.appendPage(new TestThemes(this),"Themes");
323 debug(Tango) Stdout("TestWindow.setup 5.8").newline;
324 debug(1)writefln("TestWindow.setup 5.8");
325 notebook.appendPage(new TestAspectFrame(),"Aspect Frame");
326 notebook.appendPage(new TestIdle(),"Idle");
328 version(cairo)notebook.appendPage(new Clock(), "Cairo");
330 gtkDemo(notebook);
331 debug(Tango) Stdout("TestWindow.setup 6").newline;
332 debug(1)writefln("TestWindow.setup 6");
336 MenuBar getMenuBar()
339 AccelGroup accelGroup = new AccelGroup();
341 addAccelGroup(accelGroup);
344 MenuBar menuBar = new MenuBar();
346 Menu menu = menuBar.append("_File");;
348 MenuItem item = new MenuItem(&onMenuActivate, "_New","file.new", true, accelGroup, 'n');
349 //item.addAccelerator("activate",accelGroup,'n',GdkModifierType.CONTROL_MASK,GtkAccelFlags.VISIBLE);
351 menu.append(item);
352 menu.append(new MenuItem(&onMenuActivate, "_Open","file.open", true, accelGroup, 'o'));
353 menu.append(new MenuItem(&onMenuActivate, "_Close","file.close", true, accelGroup, 'c'));
354 menu.append(new MenuItem(&onMenuActivate, "E_xit","file.exit", true, accelGroup, 'x'));
357 menu = menuBar.append("_Edit");
358 menu.append(new MenuItem(&onMenuActivate,"_Find","edit.find", true, accelGroup, 'f'));
359 menu.append(new MenuItem(&onMenuActivate,"_Search","edit.search", true, accelGroup, 's'));
361 menu = menuBar.append("_Help");
362 menu.append(new MenuItem(&onMenuActivate,"_About","help.about", true, accelGroup, 'a',GdkModifierType.CONTROL_MASK|GdkModifierType.SHIFT_MASK));
367 return menuBar;
370 class GtkDAbout : AboutDialog
372 this()
374 char** names = (new char*[2]).ptr;
375 int i = 0;
376 names[i++] = cast(char*)"Antonio Monteiro (binding/wrapping/proxying/decorating for D)";
377 names[i++] = cast(char*)"www.gtk.org (base C library)";
378 setAuthors(names);
379 setDocumenters(names);
380 setArtists(names);
381 setLicense("License is LGPL");
382 setWebsite("http://lisdev.com");
386 void onMenuActivate(MenuItem menuItem)
388 char[] action = menuItem.getActionName();
389 switch( action )
391 case "help.about":
392 (new AboutDialog()).showAll();
393 // MessageDialog d = new MessageDialog(
394 // this,
395 // GtkDialogFlags.MODAL,
396 // MessageType.INFO,
397 // ButtonsType.OK,
398 // "DUI D (graphic) User Interface\n"
399 // "an implementation through GTK+\n"
400 // "by Antonio Monteiro.\n"
401 // "DUI is released under the LGPL license\n"
402 // "\n"
403 // "Send comments and suggestions to gtkDoolkit@yahoo.ca\n"
404 // "or go to the yahoo group\n"
405 // "http://groups.yahoo.com/group/gtkDoolkit\n"
406 // "(Group email: gtkDoolkit@yahoogroups.com)\n"
407 // "\n"
408 // "See detailed information at DUI home page\n"
409 // "http://ca.geocities.com/gtkDoolkit\n"
410 // );
411 // d.run();
412 // d.destroy();
413 break;
414 default:
415 MessageDialog d = new MessageDialog(
416 this,
417 GtkDialogFlags.MODAL,
418 MessageType.INFO,
419 ButtonsType.OK,
420 "You pressed menu item "~action);
421 d.run();
422 d.destroy();
423 break;
428 Widget getToolbar()
430 HandleBox handleBox = new HandleBox();
431 Toolbar toolbar = new Toolbar();
432 toolbar.appendWidget(new Button(StockID.OPEN, true),"Toolbar button 1","Private text 1");
433 toolbar.appendWidget(new Button(StockID.CLOSE, true),"Toolbar button 2","Private text 2");
434 toolbar.appendSpace();
435 toolbar.appendWidget(new Button(StockID.SAVE, true),"Toolbar button 3","Private text 3");
436 toolbar.appendWidget(new Button(StockID.SAVE_AS, true),"Toolbar button 4","Private text 4");
438 handleBox.add(toolbar);
440 return handleBox;
444 Notebook setNotebook()
446 Notebook notebook = new Notebook();
447 notebook.addOnSwitchPage(&onNotebookSwitchPage);
448 notebook.setTabPos(PositionType.LEFT);
449 return notebook;
452 void onNotebookSwitchPage(GtkNotebookPage *notePage, uint pageNumber, Notebook notebook)
454 //writefln("Notebook switch to page %s", pageNumber);
455 // fullCollect helps finding objects that shouldn't have been collected
456 version(Tango) { /*??? no fullCollect on tango ???*/}
457 else std.gc.fullCollect();
458 //writefln("exiting Notebook switch to page %s", pageNumber);
461 //private import gtkD.EventBox;
463 void testEventBox(Notebook notebook)
466 // EventBox eventBox = new EventBox();
467 // eventBox.add(new Label("label on event box"));
468 // notebook.appendPage(eventBox,"Buttons");
470 //EventBox eventBox = new EventBox();
471 //eventBox.add(new Label("label on event box"));
472 notebook.appendPage(new Label("just a simple label"),new Label("label"));
476 void testButtons(Notebook notebook)
479 Table table = new Table(2,12,0);
481 //ListSG listSG = new ListSG();
483 RadioButton radio1Button = new RadioButton(cast(ListSG)null,"Option 1");
484 RadioButton radio2Button = new RadioButton(radio1Button,"Option 2");
485 RadioButton radio3Button = new RadioButton(radio2Button,"Option 3");
486 RadioButton radio4Button = new RadioButton(radio3Button,"Option 4");
487 RadioButton radio5Button = new RadioButton(radio4Button,"Option 5");
488 RadioButton radio6Button = new RadioButton(radio5Button,"Option 6");
489 RadioButton radio7Button = new RadioButton(radio6Button,"Option 7");
490 RadioButton radio8Button = new RadioButton(radio7Button,"Option 8");
491 RadioButton radio9Button = new RadioButton(radio8Button,"Option 9");
492 table.attach(radio1Button,0,1,0,1,AttachOptions.FILL,AttachOptions.FILL,4,4);
493 table.attach(radio2Button,0,1,1,2,AttachOptions.FILL,AttachOptions.FILL,4,4);
494 table.attach(radio3Button,0,1,2,3,AttachOptions.FILL,AttachOptions.FILL,4,4);
495 table.attach(radio4Button,0,1,3,4,AttachOptions.FILL,AttachOptions.FILL,4,4);
496 table.attach(radio5Button,0,1,4,5,AttachOptions.FILL,AttachOptions.FILL,4,4);
497 table.attach(radio6Button,0,1,5,6,AttachOptions.FILL,AttachOptions.FILL,4,4);
498 table.attach(radio7Button,0,1,6,7,AttachOptions.FILL,AttachOptions.FILL,4,4);
499 table.attach(radio8Button,0,1,7,8,AttachOptions.FILL,AttachOptions.FILL,4,4);
500 table.attach(radio9Button,0,1,8,9,AttachOptions.FILL,AttachOptions.FILL,4,4);
502 CheckButton editableButton = new CheckButton("editable");
503 CheckButton visibleButton = new CheckButton("visible");
504 table.attach(editableButton,0,1,9,10,AttachOptions.FILL,AttachOptions.FILL,4,4);
505 table.attach(visibleButton,0,1,10,11,AttachOptions.FILL,AttachOptions.FILL,4,4);
507 ToggleButton toggleButton = new ToggleButton("Toggle this");
508 table.attach(toggleButton,0,1,11,12,AttachOptions.FILL,AttachOptions.FILL,4,4);
510 Button button = new Button("test events");
511 table.attach(button,0,1,12,13,AttachOptions.FILL,AttachOptions.FILL,4,4);
513 void bActivate(Button button)
515 printf("button Activate\n");
517 void bClicked(Button button)
519 printf("button Clicked\n");
521 void bEnter(Button button)
523 printf("button Enter\n");
525 void bLeave(Button button)
527 printf("button Leave\n");
529 void bPressed(Button button)
531 printf("button Pressed\n");
533 void bReleased(Button button)
535 printf("button Released\n");
537 button.addOnActivate(&bActivate);
538 button.addOnClicked(&bClicked);
539 button.addOnEnter(&bEnter);
540 button.addOnLeave(&bLeave);
541 button.addOnPressed(&bPressed);
542 button.addOnReleased(&bReleased);
544 // for ( ShadowType shadow = 0; shadow<=ShadowType.max ; shadow ++)
545 // {
546 // for ( DirectionType direction = 0 ; direction<=DirectionType.max ; direction++)
547 // {
548 // table.attach(new Arrow(direction,shadow),direction+1,direction+2,shadow,shadow+1,AttachOptions.FILL,AttachOptions.FILL,4,4);
549 // table.attach(new Arrow(direction,shadow),direction+1,direction+2,shadow,shadow+1,AttachOptions.FILL,AttachOptions.FILL,4,4);
550 // table.attach(new Arrow(direction,shadow),direction+1,direction+2,shadow,shadow+1,AttachOptions.FILL,AttachOptions.FILL,4,4);
551 // table.attach(new Arrow(direction,shadow),direction+1,direction+2,shadow,shadow+1,AttachOptions.FILL,AttachOptions.FILL,4,4);
552 // }
553 // }
556 notebook.appendPage(new Frame(table,"Buttons"),"Buttons");
560 class ComboStore : TreeStore
562 this()
564 //int* i = cast(int*)pixbufGetType();
566 GType[] columns;
567 columns ~= GType.STRING;
568 columns ~= GType.STRING;
569 super(columns);
575 void testLists(Notebook notebook)
577 VBox mainBox = new VBox(false,3);
579 // comboBoxTextEntry from a list of strings
580 mainBox.packStart(new Label("String combo"),false,true,0);
581 static char[][] cbList = ["item 1","item 2","item 3","item 4","item 5","item 6","item 7","item 8","item 9"];
582 comboText = new ComboBoxEntry();
583 char[] entry3 = "Combo box text entry 3";
584 comboText.appendText("Combo box text entry 1");
585 comboText.appendText("Combo box text entry 2");
586 comboText.appendText(entry3);
587 comboText.appendText("Combo box text entry 4");
588 comboText.appendText("Combo box text entry 5");
589 comboText.setActive(2);
591 ButtonBox actionBox1 = HButtonBox.createActionBox();
592 actionBox1.packStart(comboText,false,false,0);
594 Button showCombo1 = new Button("ShowCombo", &showTextCombo);
595 actionBox1.packStart(showCombo1,false,false,0);
597 mainBox.packStart(new Frame(actionBox1, "Text entry ComboBox"),false,false,0);
601 // TODO combo with widgets
604 // new ComboBox + TreeModel
606 ComboStore comboStore = new ComboStore();
608 TreeIter iterFirst; // to set the first active iter
609 TreeIter iterChild;
610 TreeIter iterTop = comboStore.append(null);
611 comboStore.setValue(iterTop, 0, "Paganini" );
612 iterFirst = comboStore.append(iterTop);
613 comboStore.setValue(iterFirst, 0, "Nicolo" );
615 iterTop = comboStore.append(null);
616 comboStore.setValue(iterTop, 0, "List" );
617 iterChild = comboStore.append(iterTop);
618 comboStore.setValue(iterChild, 0, "Franz" );
620 iterTop = comboStore.append(null);
621 comboStore.setValue(iterTop, 0, "Beethoven" );
622 iterChild = comboStore.append(iterTop);
623 comboStore.setValue(iterChild, 0, "Ludwic" );
624 iterChild = comboStore.append(iterTop);
625 comboStore.setValue(iterChild, 0, "Maria" );
626 iterChild = comboStore.append(iterTop);
627 comboStore.setValue(iterChild, 0, "Van" );
629 iterTop = comboStore.append(null);
630 comboStore.setValue(iterTop, 0, "Bach" );
631 iterChild = comboStore.append(iterTop);
632 comboStore.setValue(iterChild, 0, "Johann" );
633 iterChild = comboStore.append(iterTop);
634 comboStore.setValue(iterChild, 0, "Sebastian" );
636 ComboBox treeCombo = new ComboBox(comboStore);
637 treeCombo.setWrapWidth(1);
638 CellRenderer renderer = new CellRendererText();
639 treeCombo.packStart(renderer, true);
640 treeCombo.addAttribute(renderer, "text",0);
642 // TODO something is wrong gettign the ier from the path
643 //TreePath path = new TreePath("0,0");
644 //comboStore.getIter(iterChild, path);
645 //treeCombo.setActiveIter(iterChild);
646 // use a previously set iter
647 treeCombo.setActiveIter(iterFirst);
649 mainBox.packStart(new Frame(treeCombo,"Tree Combo box"),false,true,0);
651 simpleCombo = new ComboBox();
652 simpleCombo.appendText("Top");
653 simpleCombo.appendText("Bottom");
654 simpleCombo.appendText("Left");
655 simpleCombo.appendText("Right");
656 simpleCombo.setActive(0);
658 // actions
660 ButtonBox actionBox = HButtonBox.createActionBox();
661 actionBox.packStart(simpleCombo,false,false,0);
663 Button showCombo = new Button("ShowCombo", &showSimpleCombo);
664 actionBox.packStart(showCombo,false,false,0);
666 mainBox.packStart(new Frame(actionBox, "Simple text list"),false,false,0);
668 notebook.appendPage(new Frame(mainBox,"Lists"),"Lists");
671 ComboBox simpleCombo;
672 ComboBoxEntry comboText;
674 void showTextCombo(Button button)
676 printf("Combo selected text = %.*s\n",comboText.getActiveText());
679 void showSimpleCombo(Button button)
681 printf("Combo selected text = %.*s\n",simpleCombo.getActiveText());
684 class NB : Notebook
686 void itemActivated(MenuItem menu_item)
688 printf("NB.activateCallback\n");
690 void buttonClicked(Button button)
692 setCurrentPage(2);
695 void switchPage(Notebook notebook, /*NotebookPage page,*/ guint pageNumber)
697 printf("new page = %d\n",pageNumber);
702 NB nb;
704 void posLeft(Button button)
706 nb.setTabPos(PositionType.LEFT);
708 void posRight(Button button)
710 nb.setTabPos(PositionType.RIGHT);
712 void posTop(Button button)
714 nb.setTabPos(PositionType.TOP);
716 void posBottom(Button button)
718 nb.setTabPos(PositionType.BOTTOM);
722 * tests notebook
723 * @param nodebook
725 void testNotebook(Notebook notebook)
728 nb = new NB();
729 nb.setTabPos(PositionType.min);
730 nb.popupEnable();
731 nb.setShowBorder(false);
732 nb.setBorderWidth(0);
734 class PageMove
736 Notebook notebook;
737 PositionType toPos;
738 this(Notebook notebook,PositionType toPos)
740 this.notebook = notebook;
741 this.toPos = toPos;
743 void buttonClickedCallback()
745 notebook.setTabPos(toPos);
749 PageMove toLeft = new PageMove(nb,PositionType.LEFT);
750 PageMove toRight = new PageMove(nb,PositionType.RIGHT);
751 PageMove toTop = new PageMove(nb,PositionType.TOP);
752 PageMove toBottom = new PageMove(nb,PositionType.BOTTOM);
755 notebook.appendPage(nb,new Label("Notebook"));
757 for( char i = '1' ; i<'5' ; i++ )
759 Table table = new Table(2,2,true);
760 Button left = new Button("Left "~ i);
761 left.addOnClicked(&posLeft);
762 Button right = new Button("Right "~ i);
763 right.addOnClicked(&posRight);
764 Button top = new Button("top "~ i);
765 top.addOnClicked(&posTop);
766 Button bottom = new Button("bottom "~ i);
767 bottom.addOnClicked(&posBottom);
769 table.attach(top,0,1,0,1,AttachOptions.SHRINK,AttachOptions.SHRINK,4,4);
770 table.attach(right,1,2,0,1,AttachOptions.SHRINK,AttachOptions.SHRINK,4,4);
771 table.attach(left,0,1,1,2,AttachOptions.SHRINK,AttachOptions.SHRINK,4,4);
772 table.attach(bottom,1,2,1,2,AttachOptions.SHRINK,AttachOptions.SHRINK,4,4);
773 if ( i == 3 )
776 // MenuItem menuItem = new MenuItem("menu page 3",&nb.itemActivated);
778 // Menu menu = new Menu();
779 // menu.append(new MenuItem("page 3.1",&nb.itemActivated));
780 // menu.append(new MenuItem("page 3.2",&nb.itemActivated));
781 // menu.append(new MenuItem("page 3.3",&nb.itemActivated));
782 // menu.append(new MenuItem("page 3.4",&nb.itemActivated));
784 // menuItem.setSubmenu(menu);
786 HBox box = new HBox(false,0);
787 box.setBorderWidth(0);
788 Button button = new Button("Page " ~ i ~ "\0");
789 button.addOnClicked(&nb.buttonClicked);
790 button.setBorderWidth(0);
791 button.setRelief(ReliefStyle.NONE);
792 CheckButton checkButton = new CheckButton();
793 checkButton.setBorderWidth(0);
794 box.packStart(checkButton,false,false,0);
795 box.packStart(button,false,false,0);
796 //nb.appendPageMenu(table,box,menuItem);
797 //nb.appendPage(table,box);
799 else
801 nb.appendPage(table,new Label("Page " ~ i ~ "\0"));
804 //nb.addOnSwitchPage(&nb.switchPage);
807 void testPaned(Notebook notebook)
810 Paned mainPaned = new VPaned();
811 Paned p0 = mainPaned;
812 Button p1;
813 Paned p2;
815 bool h = true;
816 for ( char c='1' ; c<='5' ; c++ )
818 p1 = new Button("Pane "~c);
819 if ( h ) p2 = new HPaned();
820 else p2 = new VPaned();
822 p0.add1(p1);
823 p0.add2(p2);
824 p0 = p2;
825 h = !h;
828 notebook.appendPage(mainPaned,new Label("Paned"));
832 FileChooserDialog fcd;
833 FileSelection fs;
834 FontSelectionDialog f;
835 ColorSelectionDialog d;
836 InputDialog id;
838 void showFileChooser(Button button)
840 char[][] a;
841 ResponseType[] r;
842 a ~= "Lets go!";
843 a ~= "Please don't";
844 r ~= ResponseType.GTK_RESPONSE_OK;
845 r ~= ResponseType.GTK_RESPONSE_CANCEL;
846 if ( fcd is null )
848 fcd = new FileChooserDialog("File Chooser", this, FileChooserAction.OPEN, a, r);
851 fcd.getFileChooser().setSelectMultiple(true);
852 fcd.run();
853 // writefln("file selected = %s",fcd.getFileName());
855 // foreach ( int i, char[] selection ; fs.getSelections())
856 // {
857 // printf("File(s) selected [%d] %.*s\n",i,selection);
858 // }
859 fcd.hide();
864 void showFileSel(Button button)
866 if ( fs is null )
868 fs = new FileSelection("File Selection");
870 //fs.showAll();
871 //fs.setMultiple(true);
872 fs.run();
873 //printf("file selected = %.*s\n",fs.getFileName());
874 // char[][] selections = fs.getSelections();
875 // for ( int i=0 ;i<selections.length ; i++)
876 // {
877 // printf("File(s) selected [%d] %.*s\n",i,selections[i]);
878 // }
879 fs.hide();
882 void showColor(Button button)
884 if ( d is null )
886 d = new ColorSelectionDialog("Select the color");
888 d.run();
889 d.hide();
892 void showInput(Button button)
894 if ( id is null )
896 id = new InputDialog();
898 id.run();
899 id.hide();
902 void showCalendar(Button button)
904 Window calWin = new Window("Calendar");
905 Calendar calendar = new Calendar();
906 //calendar.setTitle("No Title");
907 calWin.add(calendar);
908 calWin.showAll();
911 void showFont(Button button)
913 if ( f is null )
915 f = new FontSelectionDialog("Select the font");
917 f.run();
918 char[] fontName = f.getFontName();
919 f.hide();
922 Button fontButton;
924 void testDialogs(Notebook notebook)
927 ButtonBox bBox = VButtonBox.createActionBox();
929 if ( fcd is null )
931 fcd = new FileChooserDialog("File Chooser", this, FileChooserAction.OPEN);
935 Button fileChooser = new Button("File Chooser", &showFileChooser);
936 FileChooserButton fcb = new FileChooserButton(fcd);
938 Button fileSel = new Button("File Selection", &showFileSel);
939 Button color = new Button("Color Dialog", &showColor);
940 Button input = new Button("Input Dialog", &showInput);
941 Button calendar = new Button("Calendar Dialog", &showCalendar);
942 fontButton = new Button("Font Dialog", &showFont);
943 //fontButton.modifyFont("[Newspaper][16]");
945 bBox.packStart(fileChooser,0,0,10);
946 bBox.packStart(fcb,0,0,10);
947 bBox.packStart(fileSel,0,0,10);
948 bBox.packStart(color,0,0,10);
949 bBox.packStart(input,0,0,10);
950 bBox.packStart(calendar,0,0,10);
951 bBox.packStart(fontButton,0,0,10);
953 notebook.appendPage(new Frame(bBox,"Dialogs"),new Label("Dialogs"));
957 Button[] threadTestButtons;
958 static T1[] t1s;
960 class T1 : Thread
962 int num;
964 this(int num)
966 super(&run);
967 this.num = num;
970 version(Tango) void run()
972 runCommon();
974 else int run()
976 return runCommon();
980 int runCommon()
982 version(Tango) Random random = new Random();
983 while(1)
985 version(Tango) int buttonNum = random.next(threadTestButtons.length);
986 else int buttonNum = rand()%threadTestButtons.length;
987 Button button = threadTestButtons[buttonNum];
988 gdkThreadsEnter();
989 button.removeAll();
990 version(Tango) button.setLabel( (new Layout!(char))("{}", num));
991 else button.setLabel(std.string.format("%s", num));
992 gdkThreadsLeave();
993 yield();
995 return 1;
999 void testThreads(Notebook notebook)
1002 Table grid = new Table(8,8,0);
1003 for ( int i = 0 ; i<8 ; i++)
1005 for ( int j = 0 ; j<8; j++)
1007 version(Tango) Button button = new Button((new Layout!(char))("{}",(j+8*i)));
1008 else Button button = new Button(std.string.format("%s",(j+8*i)));
1009 threadTestButtons ~= button;
1010 grid.attach( button,
1011 i,i+1,
1012 j,j+1,
1013 AttachOptions.SHRINK,AttachOptions.SHRINK,4,4);
1015 t1s ~= new T1(j+8*i);
1019 void stop(Button button)
1021 foreach ( T1 t ; t1s )
1023 version(Tango)
1025 if ( t.isRunning() )
1027 t.sleep(100.0);
1030 else switch( t.getState() )
1032 case Thread.TS.RUNNING:
1033 t.pause();
1034 break;
1036 default:
1037 break;
1042 void go(Button button)
1044 foreach ( T1 t ; t1s )
1046 version(Tango)
1048 if ( !t.isRunning() )
1050 // todo t.go();
1051 // just send a interruped - how?
1054 else switch( t.getState() )
1056 case Thread.TS.INITIAL:
1057 t.start();
1058 break;
1060 default:
1061 t.resume();
1062 break;
1067 VBox vbox = new VBox(false, 2);
1068 vbox.packStart(grid, true, true,2);
1069 ButtonBox actions = HButtonBox.createActionBox();
1071 Button button = new Button(StockID.STOP, &stop);
1072 actions.packStart(button, false, false, 7);
1073 button = new Button(StockID.OK, &go);
1074 actions.packStart(button, false, false, 7);
1076 vbox.packStart(actions, false, false, 2);
1078 notebook.appendPage(vbox,new Label("Threads"));
1083 void testViewport(Notebook notebook)
1086 Table grid = new Table(21,21,0);
1087 for ( int i = 0 ; i<21 ; i++)
1089 for ( int j = 0 ; j<21; j++)
1091 if ( (i == j) || (i+j==20) || (i==10) || (j==10))
1093 grid.attach(
1094 new Button("Button"),
1095 i,i+1,
1096 j,j+1,
1097 AttachOptions.SHRINK,AttachOptions.SHRINK,4,4);
1102 ScrolledWindow sw = new ScrolledWindow(null,null);
1103 sw.addWithViewport(grid);
1104 notebook.appendPage(sw,new Label("Viewport"));
1107 void testSpinButton(Notebook notebook)
1109 Table table = new Table(2,1,false);
1111 SpinButton spin = new SpinButton(new Adjustment(1.0, 0.0, 100.0, 1.0, 10.0, 10.0),1,0);
1112 table.attach(new Label("Sping this:"),0,1,0,1,AttachOptions.FILL,AttachOptions.FILL,4,4);
1113 table.attach(spin,1,2,0,1,AttachOptions.FILL,AttachOptions.FILL,4,4);
1115 notebook.appendPage(table,"Spin Buttons");
1119 void testList(Notebook notebook)
1121 debug(Tango) Stdout("TestWindow.testList 1").newline;
1123 class TestListStore : ListStore
1125 this()
1127 static GType [3] columns = [
1128 GType.STRING,
1129 GType.STRING,
1130 GType.STRING
1132 super(columns);
1136 TestListStore testListStore = new TestListStore();
1138 TreeIter iterTop = testListStore.createIter();
1140 static int [3] cols = [0,1,2];
1141 char[][] vals;
1142 vals ~= "Antonio";
1143 vals ~= "Canada";
1144 vals ~= "Ontario";
1145 testListStore.set(iterTop,cols,vals);
1147 testListStore.append(iterTop);
1148 char[][] vals1;
1149 vals1 ~= "John Reimer";
1150 vals1 ~= "Canada";
1151 vals1 ~= "BC";
1152 testListStore.set(iterTop,cols,vals1);
1154 testListStore.append(iterTop);
1155 char[][] vals2;
1156 vals2 ~= "Friend of GtkD 2";
1157 vals2 ~= "Poland";
1158 vals2 ~= "Torun";
1159 testListStore.set(iterTop,cols,vals2);
1161 testListStore.append(iterTop);
1162 char[][] vals3;
1163 vals3 ~= "Friend of GtkD 3";
1164 vals3 ~= "Norway";
1165 vals3 ~= "Norway";
1166 testListStore.set(iterTop,cols,vals3);
1168 TreeView treeView = new TreeView(testListStore);
1169 treeView.setHeadersClickable(true);
1170 treeView.setRulesHint(true);
1172 //CellRendererText cellText = new CellRendererText();
1173 TreeViewColumn column = new TreeViewColumn("Author",new CellRendererText(),"text", 0);
1174 treeView.appendColumn(column);
1175 column.setResizable(true);
1176 column.setReorderable(true);
1177 column.setSortColumnId(0);
1178 column.setSortIndicator(true);
1180 column = new TreeViewColumn("Country",new CellRendererText(),"text", 1);
1181 treeView.appendColumn(column);
1182 column.setResizable(true);
1183 column.setReorderable(true);
1184 column.setSortColumnId(1);
1185 column.setSortIndicator(true);
1187 column = new TreeViewColumn("Province",new CellRendererText(),"text", 2);
1188 treeView.appendColumn(column);
1189 column.setResizable(true);
1190 column.setReorderable(true);
1191 column.setSortColumnId(2);
1192 column.setSortIndicator(true);
1194 //notebook.appendPage(treeView,"ListView");
1195 ScrolledWindow sw = new ScrolledWindow(null,null);
1196 sw.addWithViewport(treeView);
1197 notebook.appendPage(sw,"ListView");
1199 debug(Tango) Stdout("TestWindow.testList END").newline;
1202 void testDelete(Notebook notebook)
1204 // ulong l = 0;
1205 // while(true)
1206 // {
1207 // int i =0;
1208 // while(i<1 )
1209 // {
1210 // //Button b = new Button("Button");
1211 // Drawable d = getDrawable();
1212 // delete d;
1213 // ++i;
1214 // }
1215 // ++l;
1216 // printf("testDelete count = %d\n\0",l*i);
1217 // }
1221 void gtkDemo(Notebook notebook)
1223 debug(Tango) Stdout("TestWindow.gtkDemo 1").newline;
1224 void showTTextView(Button button)
1226 new TTextView();
1229 debug(Tango) Stdout("TestWindow.gtkDemo 2").newline;
1230 void showTEditableCells(Button button)
1232 // new TEditableCells();
1235 debug(Tango) Stdout("TestWindow.gtkDemo 3").newline;
1236 ButtonBox vBBox = VButtonBox.createActionBox();
1238 debug(Tango) Stdout("TestWindow.gtkDemo 4").newline;
1239 Button button = new Button("Text View");
1240 button.addOnClicked(&showTTextView);
1241 vBBox.packStart(button,false,false,4);
1243 debug(Tango) Stdout("TestWindow.gtkDemo 5").newline;
1244 button = new Button("Editable Cells");
1245 button.addOnClicked(&showTEditableCells);
1246 vBBox.packStart(button,false,false,4);
1248 debug(Tango) Stdout("TestWindow.gtkDemo 6").newline;
1249 notebook.appendPage(vBBox,"gtk-demo");
1251 debug(Tango) Stdout("TestWindow.gtkDemo 7").newline;
1257 private import gtkc.Loader;
1259 void main(char[][] args)
1262 Linker.dumpFailedLoads();
1264 version(Win32)
1266 // todo threads are still broken on windows...
1267 Gtk.init(args);
1269 else
1271 Gtk.initMultiThread(args);
1274 TestWindow window = new TestWindow();
1276 debug(1)writefln("before GtkD.main");
1277 Gtk.main();
1278 debug(1)writefln("after GtkD.main");