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