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