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