1 /**
2  * Widget module.
3  *
4  * License:
5  *     MIT. See LICENSE for full details.
6  */
7 module tkd.widget.entry;
8 
9 /**
10  * Imports.
11  */
12 import std.string;
13 import tkd.element.uielement;
14 import tkd.widget.common.boundingbox;
15 import tkd.widget.common.cursor;
16 import tkd.widget.common.delete_;
17 import tkd.widget.common.exportselection;
18 import tkd.widget.common.index;
19 import tkd.widget.common.insert;
20 import tkd.widget.common.justify;
21 import tkd.widget.common.selection;
22 import tkd.widget.common.show;
23 import tkd.widget.common.value;
24 import tkd.widget.common.width;
25 import tkd.widget.common.xscrollcommand;
26 import tkd.widget.common.xview;
27 import tkd.widget.widget;
28 
29 /**
30  * An entry widget displays a one-line text string and allows that string to be 
31  * edited by the user. Entry widgets support horizontal scrolling.
32  *
33  * Example:
34  * ---
35  * auto entry = new Entry()
36  * 	.setValue("Text")
37  * 	.pack();
38  * ---
39  *
40  * Common_Commands:
41  *     These are injected common commands that can also be used with this widget.
42  *     $(P
43  *         $(LINK2 ./common/boundingbox.html, BoundingBox) $(BR)
44  *         $(LINK2 ./common/cursor.html, Cursor) $(BR)
45  *         $(LINK2 ./common/delete_.html, Delete) $(BR)
46  *         $(LINK2 ./common/exportselection.html, Exportselection) $(BR)
47  *         $(LINK2 ./common/index.html, Index) $(BR)
48  *         $(LINK2 ./common/insert.html, Insert) $(BR)
49  *         $(LINK2 ./common/justify.html, Justify) $(BR)
50  *         $(LINK2 ./common/selection.html, Selection) $(BR)
51  *         $(LINK2 ./common/show.html, Show) $(BR)
52  *         $(LINK2 ./common/value.html, Value) $(BR)
53  *         $(LINK2 ./common/width.html, Width) $(BR)
54  *         $(LINK2 ./common/xscrollcommand.html, XScrollCommand) $(BR)
55  *         $(LINK2 ./common/xview.html, XView) $(BR)
56  *     )
57  *
58  * Additional_Events:
59  *     Additional events that can also be bound to using the $(LINK2 ../element/uielement.html#UiElement.bind, bind) method.
60  *     $(P
61  *         <<Clear>>,
62  *         <<Copy>>,
63  *         <<Cut>>,
64  *         <<Paste>>,
65  *         <<PasteSelection>>,
66  *         <<PrevWindow>>,
67  *         <<TraverseIn>>,
68  *         <Alt-Key>,
69  *         <B1-Enter>,
70  *         <B1-Leave>,
71  *         <B1-Motion>,
72  *         <B2-Motion>,
73  *         <Button-1>,
74  *         <Button-2>,
75  *         <ButtonRelease-1>,
76  *         <ButtonRelease-2>,
77  *         <Control-Button-1>,
78  *         <Control-Key-Left>,
79  *         <Control-Key-Right>,
80  *         <Control-Key-a>,
81  *         <Control-Key-b>,
82  *         <Control-Key-backslash>,
83  *         <Control-Key-d>,
84  *         <Control-Key-e>,
85  *         <Control-Key-f>,
86  *         <Control-Key-h>,
87  *         <Control-Key-k>,
88  *         <Control-Key-slash>,
89  *         <Control-Key>,
90  *         <Control-Shift-Key-Left>,
91  *         <Control-Shift-Key-Right>,
92  *         <Double-Button-1>,
93  *         <Key-BackSpace>,
94  *         <Key-Delete>,
95  *         <Key-Down>,
96  *         <Key-End>,
97  *         <Key-Escape>,
98  *         <Key-F10>,
99  *         <Key-Home>,
100  *         <Key-KP_Enter>,
101  *         <Key-Left>,
102  *         <Key-Return>,
103  *         <Key-Right>,
104  *         <Key-Tab>,
105  *         <Key-Up>,
106  *         <Key>,
107  *         <Meta-Key>,
108  *         <Shift-Button-1>,
109  *         <Shift-Key-End>,
110  *         <Shift-Key-Home>,
111  *         <Shift-Key-Left>,
112  *         <Shift-Key-Right>,
113  *         <Triple-Button-1>,
114  *     )
115  *
116  * States:
117  *     In the disabled state, the entry cannot be edited and the text cannot be 
118  *     selected. In the readonly state, no insert cursor is displayed and the 
119  *     entry cannot be edited. The disabled state is the same as readonly, and 
120  *     in addition text cannot be selected. Typically, the text is "grayed-out" 
121  *     in the disabled state, and a different background is used in the 
122  *     readonly state.
123  *
124  * See_Also:
125  *     $(LINK2 ./widget.html, tkd.widget.widget)
126  */
127 class Entry : Widget, IXScrollable!(Entry)
128 {
129 	/**
130 	 * The name of the variable that contains the widget's value.
131 	 */
132 	private string _valueVariable;
133 
134 	/**
135 	 * Construct the widget.
136 	 *
137 	 * Params:
138 	 *     parent = The parent of this widget.
139 	 *
140 	 * See_Also:
141 	 *     $(LINK2 ../element/uielement.html, tkd.element.uielement) $(BR)
142 	 */
143 	this(UiElement parent = null)
144 	{
145 		super(parent);
146 		this._elementId = "entry";
147 		this._valueVariable = format("variable-%s", this.generateHash(this.id));
148 
149 		this._tk.eval("ttk::entry %s -textvariable %s", this.id, this._valueVariable);
150 	}
151 
152 	/**
153 	 * Mixin common commands.
154 	 */
155 	mixin BoundingBox;
156 	mixin Cursor;
157 	mixin Delete_;
158 	mixin ExportSelection;
159 	mixin Index;
160 	mixin Insert;
161 	mixin Justify;
162 	mixin Selection;
163 	mixin Show;
164 	mixin Value!(this._valueVariable, string);
165 	mixin Width;
166 	mixin XScrollCommand!(Entry);
167 	mixin XView;
168 }