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