1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141
|
/*
* This file is part of gtkD.
*
* gtkD is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* gtkD is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with gtkD; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA
*/
module gtk.OtherTests;
import gtk.AboutDialog;
import gio.Application : GioApplication = Application;
import gtk.Application;
import gtk.ApplicationWindow;
import gtk.Dialog;
import gtk.Widget;
import gtk.Label;
import gtk.Button;
import gtk.VBox;
import gtk.Image;
import glib.Timeout;
import gdk.Event;
import std.stdio;
import core.stdc.stdlib : exit;
public class OtherTests : ApplicationWindow
{
Label byeLabel;
Timeout timeout;
this(Application application)
{
super(application);
setTitle("GtkD");
setDecorated(true);
VBox box = new VBox(false, 2);
box.add(new Label("Hello World"));
Button button = new Button("About");
button.addOnClicked(&onClicked);
button.addOnClicked(&popupAbout);
button.addOnClicked(delegate void(Button b){
writefln("\nliterally clicked");
});
button.addOnPressed(&mousePressed);
//addOnButtonPress(&mousePressed);
box.add(button);
byeLabel = new Label("Bye-bye World");
box.add(byeLabel);
add(box);
setBorderWidth(10);
move(0,400);
showAll();
addOnDelete(&onDeleteEvent);
timeout = new Timeout(1000, &changeLabel);
}
void mousePressed(Button widget)
{
writefln("mousePressed");
}
bool changeLabel()
{
switch ( byeLabel.getText() )
{
case "Bye-bye World": byeLabel.setText("still here"); break;
case "still here": byeLabel.setText("close window"); break;
case "close window": byeLabel.setText("to terminate"); break;
default : byeLabel.setText("Bye-bye World"); break;
}
return true;
}
void onClicked(Button button)
{
writefln("\nOn click from Hello World %s", button);
}
void popupAbout(Button button)
{
with (new AboutDialog())
{
string[] names;
names ~= "Antonio Monteiro (binding/wrapping/proxying/decorating for D)";
names ~= "www.gtk.org (base C library)";
setAuthors(names);
setDocumenters(names);
setArtists(names);
setLicense("License is LGPL");
setWebsite("http://lisdev.com");
addOnResponse(&onDialogResponse);
showAll();
}
}
void onDialogResponse(int response, Dialog dlg)
{
if(response == ResponseType.CANCEL)
dlg.destroy();
}
bool onDeleteEvent(Event event, Widget widget)
{
destroy();
writefln("Exit by request from HelloWorld");
exit(0);
return false;
}
override string toString()
{
return "I Am HelloWorld";
}
}
int main(string[] args)
{
auto application = new Application("org.gtkd.demo.othertests", GApplicationFlags.FLAGS_NONE);
application.addOnActivate(delegate void(GioApplication app) { new OtherTests(application); });
return application.run(args);
}
|