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 gtk.OtherTests; 20 21 private import gtk.AboutDialog; 22 private import gtk.Dialog; 23 private import gtk.Widget; 24 private import gtk.Window; 25 private import gtk.Label; 26 private import gtk.Button; 27 private import gtk.VBox; 28 private import gtk.Main; 29 private import gtk.Image; 30 31 private import glib.Timeout; 32 private import gdk.Event; 33 34 import std.stdio; 35 import core.stdc.stdlib : exit; 36 37 public class OtherTests : Window 38 { 39 40 Label byeLabel; 41 Timeout timeout; 42 43 this() 44 { 45 super("GtkD"); 46 setDecorated(true); 47 VBox box = new VBox(false, 2); 48 box.add(new Label("Hello World")); 49 Button button = new Button("About"); 50 button.addOnClicked(&onClicked); 51 button.addOnClicked(&popupAbout); 52 button.addOnClicked(delegate void(Button b){ 53 writefln("\nliterally clicked"); 54 }); 55 56 button.addOnPressed(&mousePressed); 57 //addOnButtonPress(&mousePressed); 58 59 box.add(button); 60 byeLabel = new Label("Bye-bye World"); 61 box.add(byeLabel); 62 add(box); 63 setBorderWidth(10); 64 move(0,400); 65 showAll(); 66 67 addOnDelete(&onDeleteEvent); 68 69 timeout = new Timeout(1000, &changeLabel); 70 } 71 72 void mousePressed(Button widget) 73 { 74 writefln("mousePressed"); 75 } 76 77 bool changeLabel() 78 { 79 switch ( byeLabel.getText() ) 80 { 81 case "Bye-bye World": byeLabel.setText("still here"); break; 82 case "still here": byeLabel.setText("close window"); break; 83 case "close window": byeLabel.setText("to terminate"); break; 84 default : byeLabel.setText("Bye-bye World"); break; 85 } 86 return true; 87 } 88 89 void onClicked(Button button) 90 { 91 writefln("\nOn click from Hello World %s", button); 92 } 93 94 void popupAbout(Button button) 95 { 96 with (new AboutDialog()) 97 { 98 99 string[] names; 100 names ~= "Antonio Monteiro (binding/wrapping/proxying/decorating for D)"; 101 names ~= "www.gtk.org (base C library)"; 102 setAuthors(names); 103 setDocumenters(names); 104 setArtists(names); 105 setLicense("License is LGPL"); 106 setWebsite("http://lisdev.com"); 107 addOnResponse(&onDialogResponse); 108 showAll(); 109 } 110 } 111 112 void onDialogResponse(int response, Dialog dlg) 113 { 114 if(response == ResponseType.CANCEL) 115 dlg.destroy(); 116 } 117 118 bool onDeleteEvent(Event event, Widget widget) 119 { 120 destroy(); 121 writefln("Exit by request from HelloWorld"); 122 exit(0); 123 return false; 124 } 125 126 override string toString() 127 { 128 return "I Am HelloWorld"; 129 } 130 131 } 132 133 void main(string[] args) 134 { 135 Main.init(args); 136 new OtherTests(); 137 Main.run(); 138 } 139