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