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 TestEntries;
20 
21 private import gtk.Table;
22 
23 private import gtk.Entry;
24 private import gtk.CheckButton;
25 private import gtk.Button;
26 private import gtk.Label;
27 
28 private import glib.Str;
29 
30 version(Tango) private import tango.io.Stdout;
31 else private import std.stdio;
32 /**
33  * This tests the GtkD Entry widget
34  */
35 class TestEntries : Table
36 {
37 	/**
38 	 * Out main widget to test
39 	 */
40 	Entry entry;
41 
42 	/**
43 	 * Creates a new TestEntries
44 	 */
45 	this()
46 	{
47 		super(3,2,false);
48 
49 		// create the main test widget
50 		entry = new Entry("Change me!");
51 		attach(new Label("Input text"),0,1,0,1,AttachOptions.SHRINK,AttachOptions.SHRINK,4,4);
52 		attach(entry,1,2,0,1,AttachOptions.EXPAND,AttachOptions.EXPAND,4,4);
53 
54 		// create a button that will print the content of the entry to stdout
55 		Button testButton = new Button("Show entry", &showEntry);
56 		attach(testButton,2,3,0,1,AttachOptions.SHRINK,AttachOptions.SHRINK,4,4);
57 		//testButton.setTooltip("This is just a test",null);
58 
59 		// create a button that will change the entry display mode to invisible
60 		// i.e. like a password entry
61 		CheckButton entryVisible = new CheckButton("Visible", &entryVisible);
62 		entryVisible.setActive(true);
63 		attach(entryVisible,2,3,1,2,AttachOptions.SHRINK,AttachOptions.SHRINK,4,4);
64 
65 		// create a button that will change the entry mode to not editable
66 		CheckButton entryEditable = new CheckButton("Editable", &entryEditable);
67 		entryEditable.setActive(true);
68 		attach(entryEditable,1,2,1,2,AttachOptions.SHRINK,AttachOptions.SHRINK,4,4);
69 	}
70 
71 	void showEntry(Button button)
72 	{
73 		version(Tango) Stdout.format("text field contains '{}'\n",entry.getText()).newline;
74 		else writef("text field contains '%s'\n",Str.toStringz(entry.getText()));
75 	}
76 
77 	void entryEditable(CheckButton button)
78 	{
79 		entry.setEditable(button.getActive());
80 	}
81 
82 	void entryVisible(CheckButton button)
83 	{
84 		entry.setVisibility(button.getActive());
85 	}
86 
87 }