flexlay2: respect maximum box size
[iv.d.git] / tuing / events.d
blobfa9362fbe05f2338a46906536f4f328c4892e705
1 /* Invisible Vector Library
2 * simple FlexBox-based TUI engine
4 * coded by Ketmar // Invisible Vector <ketmar@ketmar.no-ip.org>
5 * Understanding is not required. Only obedience.
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, version 3 of the License ONLY.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 module iv.tuing.events /*is aliced*/;
21 import iv.alice;
22 import iv.eventbus;
23 import iv.flexlayout : FuiPoint;
24 import iv.rawtty : TtyEvent;
26 import iv.tuing.controls.button : FuiCheckBox, FuiRadio;
27 import iv.tuing.controls.listbox : FuiListBox;
28 import iv.tuing.controls.window : FuiDeskWindow;
29 import iv.tuing.tui : FuiControl;
30 import iv.tuing.ttyeditor : TtyEditor;
33 // ////////////////////////////////////////////////////////////////////////// //
34 public class FuiEvent : Event {
35 this () { super(); }
36 this (FuiControl asrc) { super(asrc); }
37 this (FuiControl asrc, FuiControl adest) { super(asrc, adest); }
39 final @property pure nothrow @trusted @nogc {
40 inout(FuiControl) sourcectl () inout { return cast(typeof(return))osource; }
41 inout(FuiControl) destctl () inout { return cast(typeof(return))odest; }
45 // ////////////////////////////////////////////////////////////////////////// //
46 // broadcast this event to stop event loop
47 public class FuiEventQuit : FuiEvent { this () {} }
50 // ////////////////////////////////////////////////////////////////////////// //
51 // post this event to close current window; `ares` is the control that caused it; may be null
52 public class FuiEventClose : FuiEvent {
53 FuiControl res;
54 this (FuiDeskWindow awin, FuiControl ares=null) { super(awin); res = ares; }
55 final @property pure nothrow @trusted @nogc {
56 inout(FuiDeskWindow) win () inout { return cast(typeof(return))osource; }
61 // ////////////////////////////////////////////////////////////////////////// //
62 // can be unbalanced
63 public class FuiEventHover : FuiEvent { this (FuiControl adest) { super(null, adest); } }
64 public class FuiEventEnter : FuiEventHover { this (FuiControl adest) { super(adest); } }
65 public class FuiEventLeave : FuiEventHover { this (FuiControl adest) { super(adest); } }
67 // can be unbalanced
68 public class FuiEventFocusBlur : FuiEvent { this (FuiControl adest) { super(null, adest); } }
69 public class FuiEventFocus : FuiEventFocusBlur { this (FuiControl adest) { super(adest); } }
70 public class FuiEventBlur : FuiEventFocusBlur { this (FuiControl adest) { super(adest); } }
72 // "active" means "some mouse button pressed, but not released"; can be unbalanced
73 public class FuiEventActiveStateChanged : FuiEvent { this (FuiControl adest) { super(null, adest); } }
74 public class FuiEventActive : FuiEventActiveStateChanged { this (FuiControl adest) { super(adest); } }
75 public class FuiEventInactive : FuiEventActiveStateChanged { this (FuiControl adest) { super(adest); } }
78 // ////////////////////////////////////////////////////////////////////////// //
79 // all other rawtty events
80 public class FuiEventKey : FuiEvent {
81 TtyEvent key;
82 this (FuiControl adest, TtyEvent akey) { key = akey; super(null, adest); }
85 // mouse clicks and doubleclicks
86 public class FuiEventAnyClick : FuiEvent {
87 FuiPoint pt;
88 TtyEvent.MButton bt;
89 this (FuiControl adest, FuiPoint apt, TtyEvent.MButton abt) { super(null, adest); pt = apt; bt = abt; }
90 final @property const pure nothrow @trusted @nogc {
91 int bidx () { return (bt-TtyEvent.MButton.First); }
92 bool left () { return (bt == TtyEvent.MButton.Left); }
93 bool right () { return (bt == TtyEvent.MButton.Right); }
94 bool middle () { return (bt == TtyEvent.MButton.Middle); }
95 bool wheelup () { return (bt == TtyEvent.MButton.WheelUp); }
96 bool wheeldown () { return (bt == TtyEvent.MButton.WheelDown); }
99 public class FuiEventClick : FuiEventAnyClick { this (FuiControl adest, FuiPoint apt, TtyEvent.MButton abt) { super(adest, apt, abt); } }
100 public class FuiEventDouble : FuiEventAnyClick { this (FuiControl adest, FuiPoint apt, TtyEvent.MButton abt) { super(adest, apt, abt); } }
103 // ////////////////////////////////////////////////////////////////////////// //
104 public class FuiEventCheckBoxChanged : FuiEvent {
105 string gid; // group id
106 bool val; // new value
107 this (FuiCheckBox abt, string agid, bool aval) { super(abt); gid = agid; val = aval; }
108 final @property pure nothrow @trusted @nogc {
109 inout(FuiCheckBox) bt () inout { return cast(typeof(return))osource; }
113 public class FuiEventRadioChanged : FuiEvent {
114 string gid; // group id
115 int val; // new value
116 this (FuiRadio abt, string agid, int aval) { super(abt); gid = agid; val = aval; }
117 final @property pure nothrow @trusted @nogc {
118 inout(FuiRadio) bt () inout { return cast(typeof(return))osource; }
123 // ////////////////////////////////////////////////////////////////////////// //
124 public class FuiEventWinFocusNextPrev : FuiEvent {
125 this (FuiDeskWindow awin) { super(awin); }
126 final @property pure nothrow @trusted @nogc {
127 inout(FuiDeskWindow) sourcewin () inout { return cast(typeof(return))osource; }
131 public class FuiEventWinFocusNext : FuiEventWinFocusNextPrev { this (FuiDeskWindow awin) { super(awin); } }
132 public class FuiEventWinFocusPrev : FuiEventWinFocusNextPrev { this (FuiDeskWindow awin) { super(awin); } }
135 // ////////////////////////////////////////////////////////////////////////// //
136 // sent when control wants to show history selection (broadcast)
137 // control should not block (event handler will take care of that)
138 public class FuiEventHistoryQuery : FuiEvent { this (FuiControl asrc) { super(asrc); } }
140 // control should update itself with this new string
141 // this even may be omited if history manager did all the work itself
142 public class FuiEventHistoryReply : FuiEvent {
143 const(char)[] text;
144 this (FuiControl adest, const(char)[] atext) { super(null, adest); text = atext; }
148 // ////////////////////////////////////////////////////////////////////////// //
149 public class FuiEventListBoxEvent : FuiEvent {
150 this (FuiListBox alb) { super(alb); }
151 final @property pure nothrow @trusted @nogc {
152 inout(FuiListBox) sourcelb () inout { return cast(typeof(return))osource; }
156 public class FuiEventListBoxCurIndexChanged : FuiEventListBoxEvent {
157 int idx; // new index (can be negative)
158 this (FuiListBox alb, int aidx) { super(alb); idx = aidx; }
161 public class FuiEventListBoxMarkChanged : FuiEventListBoxEvent {
162 int idx; // item index
163 this (FuiListBox alb, int aidx) { super(alb); idx = aidx; }
167 // ////////////////////////////////////////////////////////////////////////// //
168 public class EventEditorEvent : Event {
169 string msg;
170 this (TtyEditor aed) { super(aed); }
171 final @property pure nothrow @trusted @nogc {
172 inout(TtyEditor) sourceed () inout { return cast(typeof(return))osource; }
173 inout(TtyEditor) ed () inout { return cast(typeof(return))osource; }
177 public class EventEditorMessage : EventEditorEvent {
178 string msg;
179 this (TtyEditor aed, string amsg) { super(aed); msg = amsg; }
182 public class EventEditorQuery : EventEditorEvent {
183 this (TtyEditor aed) { super(aed); }
186 // yes, source
187 public class EventEditorReply : EventEditorEvent {
188 this (TtyEditor aed) { super(aed); }
192 // reply: <0: cancel; =0: no; >0: yes
193 public class EventEditorQueryOverwriteModified : EventEditorQuery { this (TtyEditor aed) { super(aed); } }
194 public class EventEditorReplyOverwriteModified : EventEditorReply { int res; this (TtyEditor aed, int ares) { super(aed); res = ares; } }
196 // reply: <0: cancel; =0: no; >0: yes
197 public class EventEditorQueryReloadModified : EventEditorQuery { this (TtyEditor aed) { super(aed); } }
198 public class EventEditorReplyReloadModified : EventEditorReply { int res; this (TtyEditor aed, int ares) { super(aed); res = ares; } }
200 public class EventEditorQueryAutocompletion : EventEditorQuery {
201 const(char)[][] list;
202 int pos, len;
203 FuiPoint pt;
204 this (TtyEditor aed, int apos, int alen, FuiPoint apt, const(char)[][] alist) { super(aed); pos = apos; len = alen; pt = apt; list = alist; }
206 public class EventEditorReplyAutocompletion : EventEditorReply {
207 const(char)[] res;
208 int pos, len;
209 this (TtyEditor aed, int apos, int alen, const(char)[] ares) { super(aed); pos = apos; len = alen; res = ares; }
212 public class EventEditorQueryReplacement : EventEditorQuery {
213 void* opt; // SROptions
214 this (TtyEditor aed, void* aopt) { super(aed); opt = aopt; }
216 public class EventEditorReplyReplacement : EventEditorReply {
217 void* opt; // SROptions
218 this (TtyEditor aed, void* aopt) { super(aed); opt = aopt; }
221 // show search-and-replace dialog
222 public class EventEditorQuerySR : EventEditorQuery {
223 void* opt; // SROptions
224 this (TtyEditor aed, void* aopt) { super(aed); opt = aopt; }
226 public class EventEditorReplySR : EventEditorReply {
227 void* opt; // SROptions
228 bool proceed;
229 this (TtyEditor aed, void* aopt, bool aproceed) { super(aed); opt = aopt; proceed = aproceed; }
232 public class EventEditorQueryGotoLine : EventEditorQuery {
233 this (TtyEditor aed) { super(aed); }
235 public class EventEditorReplyGotoLine : EventEditorReply {
236 int line;
237 this (TtyEditor aed, int aline) { super(aed); line = aline; }
240 public class EventEditorQueryCodePage : EventEditorQuery {
241 int cp;
242 this (TtyEditor aed, int acp) { super(aed); cp = acp; }
244 public class EventEditorReplyCodePage : EventEditorReply {
245 int cp;
246 this (TtyEditor aed, int acp) { super(aed); cp = acp; }
249 public class EventEditorQueryTabSize : EventEditorQuery {
250 int tabsize;
251 this (TtyEditor aed, int atabsize) { super(aed); tabsize = atabsize; }
253 public class EventEditorReplyTabSize : EventEditorReply {
254 int tabsize;
255 this (TtyEditor aed, int atabsize) { super(aed); tabsize = atabsize; }