1 (* coded by Ketmar // Invisible Vector <ketmar@ketmar.no-ip.org>
2 * Understanding is not required. Only obedience.
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU 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.
9 * This program 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 General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 {$INCLUDE ../shared/a_modes.inc}
27 fui_common
, fui_events
, fui_style
,
32 // ////////////////////////////////////////////////////////////////////////// //
34 TUIControlClass
= class of TUIControl
;
38 type TActionCB
= procedure (me
: TUIControl
);
39 type TCloseRequestCB
= function (me
: TUIControl
): Boolean; // top-level windows will call this before closing with icon/keyboard
41 // return `true` to stop
42 type TCtlEnumCB
= function (ctl
: TUIControl
): Boolean is nested
;
45 const ClrIdxActive
= 0;
46 const ClrIdxDisabled
= 1;
47 const ClrIdxInactive
= 2;
55 mWidth
, mHeight
: Integer;
56 mFrameWidth
, mFrameHeight
: Integer;
57 mScrollX
, mScrollY
: Integer;
60 mChildren
: array of TUIControl
;
61 mFocused
: TUIControl
; // valid only for top-level controls
62 mEscClose
: Boolean; // valid only for top-level controls
67 mStyleLoaded
: Boolean;
68 mCtl4Style
: AnsiString;
69 mBackColor
: array[0..ClrIdxMax
] of TGxRGBA
;
70 mTextColor
: array[0..ClrIdxMax
] of TGxRGBA
;
71 mFrameColor
: array[0..ClrIdxMax
] of TGxRGBA
;
72 mFrameTextColor
: array[0..ClrIdxMax
] of TGxRGBA
;
73 mFrameIconColor
: array[0..ClrIdxMax
] of TGxRGBA
;
74 mSBarFullColor
: array[0..ClrIdxMax
] of TGxRGBA
;
75 mSBarEmptyColor
: array[0..ClrIdxMax
] of TGxRGBA
;
76 mDarken
: array[0..ClrIdxMax
] of Integer; // >255: none
79 procedure updateStyle (); virtual;
80 procedure cacheStyle (root
: TUIStyle
); virtual;
81 function getColorIndex (): Integer; inline;
84 function getEnabled (): Boolean;
85 procedure setEnabled (v
: Boolean); inline;
87 function getFocused (): Boolean; inline;
88 procedure setFocused (v
: Boolean); inline;
90 function getActive (): Boolean; inline;
92 function getCanFocus (): Boolean; inline;
94 function isMyChild (ctl
: TUIControl
): Boolean;
96 function findFirstFocus (): TUIControl
;
97 function findLastFocus (): TUIControl
;
99 function findNextFocus (cur
: TUIControl
; wrap
: Boolean): TUIControl
;
100 function findPrevFocus (cur
: TUIControl
; wrap
: Boolean): TUIControl
;
102 function findCancelControl (): TUIControl
;
103 function findDefaulControl (): TUIControl
;
105 function findControlById (const aid
: AnsiString): TUIControl
;
107 procedure activated (); virtual;
108 procedure blurred (); virtual;
110 procedure calcFullClientSize ();
112 procedure drawFrame (gx
, gy
, resx
, thalign
: Integer; const text: AnsiString; dbl
: Boolean);
115 var savedClip
: TGxRect
; // valid only in `draw*()` calls
116 //WARNING! do not call scissor functions outside `.draw*()` API!
117 // set scissor to this rect (in local coords)
118 procedure setScissor (lx
, ly
, lw
, lh
: Integer); // valid only in `draw*()` calls
119 procedure resetScissor (); inline; // only client area, w/o frame
120 procedure resetScissorNC (); inline; // full drawing area, with frame
124 closeRequestCB
: TCloseRequestCB
;
127 mDefSize
: TLaySize
; // default size
128 mMaxSize
: TLaySize
; // maximum size
135 mLayDefSize
: TLaySize
;
136 mLayMaxSize
: TLaySize
;
142 // layouter interface
143 function getDefSize (): TLaySize
; inline; // default size; <0: use max size
144 //procedure setDefSize (const sz: TLaySize); inline; // default size; <0: use max size
145 function getMargins (): TLayMargins
; inline;
146 function getPadding (): TLaySize
; inline; // children padding (each non-first child will get this on left/top)
147 function getMaxSize (): TLaySize
; inline; // max size; <0: set to some huge value
148 //procedure setMaxSize (const sz: TLaySize); inline; // max size; <0: set to some huge value
149 function getFlex (): Integer; inline; // <=0: not flexible
150 function isHorizBox (): Boolean; inline; // horizontal layout for children?
151 function noPad (): Boolean; inline; // ignore padding in box direction for this control
152 function getAlign (): Integer; inline; // aligning in non-main direction: <0: left/up; 0: center; >0: right/down
153 function getExpand (): Boolean; inline; // expanding in non-main direction: `true` will ignore align and eat all available space
154 function getHGroup (): AnsiString; inline; // empty: not grouped
155 function getVGroup (): AnsiString; inline; // empty: not grouped
157 procedure setActualSizePos (constref apos
: TLayPos
; constref asize
: TLaySize
); inline;
159 procedure layPrepare (); virtual; // called before registering control in layouter
162 property flex
: Integer read mFlex write mFlex
;
163 property flDefaultSize
: TLaySize read mDefSize write mDefSize
;
164 property flMaxSize
: TLaySize read mMaxSize write mMaxSize
;
165 property flPadding
: TLaySize read mPadding write mPadding
;
166 property flHoriz
: Boolean read mHoriz write mHoriz
;
167 property flAlign
: Integer read mAlign write mAlign
;
168 property flExpand
: Boolean read mExpand write mExpand
;
169 property flHGroup
: AnsiString read mHGroup write mHGroup
;
170 property flVGroup
: AnsiString read mVGroup write mVGroup
;
171 property flNoPad
: Boolean read mNoPad write mNoPad
;
172 property fullSize
: TLaySize read mFullSize
;
175 function parsePos (par
: TTextParser
): TLayPos
;
176 function parseSize (par
: TTextParser
): TLaySize
;
177 function parsePadding (par
: TTextParser
): TLaySize
;
178 function parseHPadding (par
: TTextParser
; def
: Integer): TLaySize
;
179 function parseVPadding (par
: TTextParser
; def
: Integer): TLaySize
;
180 function parseBool (par
: TTextParser
): Boolean;
181 function parseAnyAlign (par
: TTextParser
): Integer;
182 function parseHAlign (par
: TTextParser
): Integer;
183 function parseVAlign (par
: TTextParser
): Integer;
184 function parseOrientation (const prname
: AnsiString; par
: TTextParser
): Boolean;
185 procedure parseTextAlign (par
: TTextParser
; var h
, v
: Integer);
186 procedure parseChildren (par
: TTextParser
); // par should be on '{'; final '}' is eaten
189 // par is on property data
190 // there may be more data in text stream, don't eat it!
191 // return `true` if property name is valid and value was parsed
192 // return `false` if property name is invalid; don't advance parser in this case
193 // throw on property data errors
194 function parseProperty (const prname
: AnsiString; par
: TTextParser
): Boolean; virtual;
196 // par should be on '{'; final '}' is eaten
197 procedure parseProperties (par
: TTextParser
);
200 constructor Create ();
201 destructor Destroy (); override;
203 procedure AfterConstruction (); override; // so it will be correctly initialized when created from parser
205 // `sx` and `sy` are screen coordinates
206 procedure drawControl (gx
, gy
: Integer); virtual;
208 // called after all children drawn
209 procedure drawControlPost (gx
, gy
: Integer); virtual;
211 procedure draw (); virtual;
213 function topLevel (): TUIControl
; inline;
215 // returns `true` if global coords are inside this control
216 function toLocal (var x
, y
: Integer): Boolean;
217 function toLocal (gx
, gy
: Integer; out x
, y
: Integer): Boolean; inline;
218 procedure toGlobal (var x
, y
: Integer);
219 procedure toGlobal (lx
, ly
: Integer; out x
, y
: Integer); inline;
221 procedure getDrawRect (out gx
, gy
, wdt
, hgt
: Integer);
223 // x and y are global coords
224 function controlAtXY (x
, y
: Integer; allowDisabled
: Boolean=false): TUIControl
;
226 function parentScrollX (): Integer; inline;
227 function parentScrollY (): Integer; inline;
229 procedure makeVisibleInParent ();
231 procedure doAction (); virtual; // so user controls can override it
233 procedure mouseEvent (var ev
: TFUIMouseEvent
); virtual; // returns `true` if event was eaten
234 procedure keyEvent (var ev
: TFUIKeyEvent
); virtual; // returns `true` if event was eaten
235 procedure keyEventPre (var ev
: TFUIKeyEvent
); virtual; // will be called before dispatching the event
236 procedure keyEventPost (var ev
: TFUIKeyEvent
); virtual; // will be called after if nobody processed the event
238 function prevSibling (): TUIControl
;
239 function nextSibling (): TUIControl
;
240 function firstChild (): TUIControl
; inline;
241 function lastChild (): TUIControl
; inline;
243 procedure appendChild (ctl
: TUIControl
); virtual;
245 function setActionCBFor (const aid
: AnsiString; cb
: TActionCB
): TActionCB
; // returns previous cb
247 function forEachChildren (cb
: TCtlEnumCB
): TUIControl
; // doesn't recurse
248 function forEachControl (cb
: TCtlEnumCB
; includeSelf
: Boolean=true): TUIControl
;
250 procedure close (); // this closes *top-level* control
253 property id
: AnsiString read mId write mId
;
254 property styleId
: AnsiString read mStyleId
;
255 property scrollX
: Integer read mScrollX write mScrollX
;
256 property scrollY
: Integer read mScrollY write mScrollY
;
257 property x0
: Integer read mX write mX
;
258 property y0
: Integer read mY write mY
;
259 property width
: Integer read mWidth write mWidth
;
260 property height
: Integer read mHeight write mHeight
;
261 property enabled
: Boolean read getEnabled write setEnabled
;
262 property parent
: TUIControl read mParent
;
263 property focused
: Boolean read getFocused write setFocused
;
264 property active
: Boolean read getActive
;
265 property escClose
: Boolean read mEscClose write mEscClose
;
266 property cancel
: Boolean read mCancel write mCancel
;
267 property defctl
: Boolean read mDefault write mDefault
;
268 property canFocus
: Boolean read getCanFocus write mCanFocus
;
269 property ctlById
[const aid
: AnsiString]: TUIControl read findControlById
; default
;
273 TUITopWindow
= class(TUIControl
)
275 type TXMode
= (None
, Drag
, VScroll
, HScroll
);
280 mDragStartX
, mDragStartY
: Integer;
281 mWaitingClose
: Boolean;
283 mFreeOnClose
: Boolean; // default: false
284 mDoCenter
: Boolean; // after layouting
285 mFitToScreen
: Boolean;
288 procedure activated (); override;
289 procedure blurred (); override;
292 closeCB
: TActionCB
; // called after window was removed from ui window list
295 constructor Create (const atitle
: AnsiString);
297 procedure AfterConstruction (); override; // so it will be correctly initialized when created from parser
299 function parseProperty (const prname
: AnsiString; par
: TTextParser
): Boolean; override;
301 procedure flFitToScreen (); // call this before layouting
303 procedure centerInScreen ();
305 // `sx` and `sy` are screen coordinates
306 procedure drawControl (gx
, gy
: Integer); override;
307 procedure drawControlPost (gx
, gy
: Integer); override;
309 procedure keyEvent (var ev
: TFUIKeyEvent
); override; // returns `true` if event was eaten
310 procedure mouseEvent (var ev
: TFUIMouseEvent
); override; // returns `true` if event was eaten
313 property freeOnClose
: Boolean read mFreeOnClose write mFreeOnClose
;
314 property fitToScreen
: Boolean read mFitToScreen write mFitToScreen
;
317 // ////////////////////////////////////////////////////////////////////// //
318 TUIBox
= class(TUIControl
)
321 mCaption
: AnsiString;
322 mHAlign
: Integer; // -1: left; 0: center; 1: right; default: left
325 procedure setCaption (const acap
: AnsiString);
326 procedure setHasFrame (v
: Boolean);
329 constructor Create (ahoriz
: Boolean);
331 procedure AfterConstruction (); override; // so it will be correctly initialized when created from parser
333 function parseProperty (const prname
: AnsiString; par
: TTextParser
): Boolean; override;
335 procedure drawControl (gx
, gy
: Integer); override;
337 procedure mouseEvent (var ev
: TFUIMouseEvent
); override;
338 procedure keyEvent (var ev
: TFUIKeyEvent
); override;
341 property caption
: AnsiString read mCaption write setCaption
;
342 property hasFrame
: Boolean read mHasFrame write setHasFrame
;
343 property captionAlign
: Integer read mHAlign write mHAlign
;
346 TUIHBox
= class(TUIBox
)
348 constructor Create ();
350 procedure AfterConstruction (); override; // so it will be correctly initialized when created from parser
353 TUIVBox
= class(TUIBox
)
355 constructor Create ();
357 procedure AfterConstruction (); override; // so it will be correctly initialized when created from parser
360 // ////////////////////////////////////////////////////////////////////// //
361 TUISpan
= class(TUIControl
)
363 procedure AfterConstruction (); override; // so it will be correctly initialized when created from parser
365 function parseProperty (const prname
: AnsiString; par
: TTextParser
): Boolean; override;
368 // ////////////////////////////////////////////////////////////////////// //
369 TUILine
= class(TUIControl
)
371 procedure AfterConstruction (); override; // so it will be correctly initialized when created from parser
373 function parseProperty (const prname
: AnsiString; par
: TTextParser
): Boolean; override;
375 procedure layPrepare (); override; // called before registering control in layouter
377 procedure drawControl (gx
, gy
: Integer); override;
380 // ////////////////////////////////////////////////////////////////////// //
381 TUIStaticText
= class(TUIControl
)
384 mHAlign
: Integer; // -1: left; 0: center; 1: right; default: left
385 mVAlign
: Integer; // -1: top; 0: center; 1: bottom; default: center
386 mHeader
: Boolean; // true: draw with frame text color
387 mLine
: Boolean; // true: draw horizontal line
390 procedure setText (const atext
: AnsiString);
393 procedure AfterConstruction (); override; // so it will be correctly initialized when created from parser
395 function parseProperty (const prname
: AnsiString; par
: TTextParser
): Boolean; override;
397 procedure drawControl (gx
, gy
: Integer); override;
400 property text: AnsiString read mText write setText
;
401 property halign
: Integer read mHAlign write mHAlign
;
402 property valign
: Integer read mVAlign write mVAlign
;
403 property header
: Boolean read mHeader write mHeader
;
404 property line
: Boolean read mLine write mLine
;
407 // ////////////////////////////////////////////////////////////////////// //
408 TUITextLabel
= class(TUIControl
)
411 mHAlign
: Integer; // -1: left; 0: center; 1: right; default: left
412 mVAlign
: Integer; // -1: top; 0: center; 1: bottom; default: center
414 mHotOfs
: Integer; // from text start, in pixels
415 mHotColor
: array[0..ClrIdxMax
] of TGxRGBA
;
416 mLinkId
: AnsiString; // linked control
419 procedure cacheStyle (root
: TUIStyle
); override;
421 procedure setText (const s
: AnsiString); virtual;
424 procedure AfterConstruction (); override; // so it will be correctly initialized when created from parser
426 function parseProperty (const prname
: AnsiString; par
: TTextParser
): Boolean; override;
428 procedure doAction (); override;
430 procedure drawControl (gx
, gy
: Integer); override;
432 procedure mouseEvent (var ev
: TFUIMouseEvent
); override;
433 procedure keyEventPost (var ev
: TFUIKeyEvent
); override;
436 property text: AnsiString read mText write setText
;
437 property halign
: Integer read mHAlign write mHAlign
;
438 property valign
: Integer read mVAlign write mVAlign
;
441 // ////////////////////////////////////////////////////////////////////// //
442 TUIButton
= class(TUITextLabel
)
444 mSkipLayPrepare
: Boolean;
445 mShadowSize
: Integer;
446 mAddMarkers
: Boolean;
447 mHideMarkers
: Boolean;
451 procedure setText (const s
: AnsiString); override;
453 procedure cacheStyle (root
: TUIStyle
); override;
455 procedure blurred (); override;
458 procedure AfterConstruction (); override; // so it will be correctly initialized when created from parser
460 procedure layPrepare (); override; // called before registering control in layouter
462 procedure drawControl (gx
, gy
: Integer); override;
464 procedure mouseEvent (var ev
: TFUIMouseEvent
); override;
465 procedure keyEvent (var ev
: TFUIKeyEvent
); override;
468 // ////////////////////////////////////////////////////////////////////// //
469 TUIButtonRound
= class(TUIButton
)
471 procedure setText (const s
: AnsiString); override;
474 procedure AfterConstruction (); override; // so it will be correctly initialized when created from parser
476 procedure layPrepare (); override; // called before registering control in layouter
478 procedure drawControl (gx
, gy
: Integer); override;
481 // ////////////////////////////////////////////////////////////////////// //
482 TUISwitchBox
= class(TUITextLabel
)
486 mIcon
: TGxContext
.TMarkIcon
;
487 mSwitchColor
: array[0..ClrIdxMax
] of TGxRGBA
;
490 procedure cacheStyle (root
: TUIStyle
); override;
492 procedure setText (const s
: AnsiString); override;
494 function getChecked (): Boolean; virtual;
495 procedure setChecked (v
: Boolean); virtual; abstract;
498 procedure AfterConstruction (); override; // so it will be correctly initialized when created from parser
500 function parseProperty (const prname
: AnsiString; par
: TTextParser
): Boolean; override;
502 procedure drawControl (gx
, gy
: Integer); override;
504 procedure mouseEvent (var ev
: TFUIMouseEvent
); override;
505 procedure keyEvent (var ev
: TFUIKeyEvent
); override;
507 procedure setVar (pvar
: PBoolean);
510 property checked
: Boolean read getChecked write setChecked
;
513 TUICheckBox
= class(TUISwitchBox
)
515 procedure setChecked (v
: Boolean); override;
518 procedure AfterConstruction (); override; // so it will be correctly initialized when created from parser
520 procedure doAction (); override;
523 TUIRadioBox
= class(TUISwitchBox
)
525 mRadioGroup
: AnsiString;
528 procedure setChecked (v
: Boolean); override;
531 procedure AfterConstruction (); override; // so it will be correctly initialized when created from parser
533 function parseProperty (const prname
: AnsiString; par
: TTextParser
): Boolean; override;
535 procedure doAction (); override;
538 property radioGroup
: AnsiString read mRadioGroup write mRadioGroup
; //FIXME
542 // ////////////////////////////////////////////////////////////////////////// //
543 procedure uiMouseEvent (var evt
: TFUIMouseEvent
);
544 procedure uiKeyEvent (var evt
: TFUIKeyEvent
);
547 procedure uiFocus ();
551 // ////////////////////////////////////////////////////////////////////////// //
552 procedure uiAddWindow (ctl
: TUIControl
);
553 procedure uiRemoveWindow (ctl
: TUIControl
); // will free window if `mFreeOnClose` is `true`
554 function uiVisibleWindow (ctl
: TUIControl
): Boolean;
556 procedure uiUpdateStyles ();
559 // ////////////////////////////////////////////////////////////////////////// //
561 procedure uiLayoutCtl (ctl
: TUIControl
);
564 // ////////////////////////////////////////////////////////////////////////// //
565 procedure uiInitialize ();
566 procedure uiDeinitialize ();
569 // ////////////////////////////////////////////////////////////////////////// //
571 fuiRenderScale
: Single = 1.0;
572 uiContext
: TGxContext
= nil;
582 // ////////////////////////////////////////////////////////////////////////// //
583 procedure uiDeinitialize ();
585 FreeAndNil(uiContext
);
589 procedure uiInitialize ();
591 if (uiContext
<> nil) then raise Exception
.Create('FlexUI already initialized');
592 uiContext
:= TGxContext
.Create();
596 // ////////////////////////////////////////////////////////////////////////// //
598 ctlsToKill
: array of TUIControl
= nil;
601 procedure scheduleKill (ctl
: TUIControl
);
605 if (ctl
= nil) then exit
;
607 for f
:= 0 to High(ctlsToKill
) do
609 if (ctlsToKill
[f
] = ctl
) then exit
;
610 if (ctlsToKill
[f
] = nil) then begin ctlsToKill
[f
] := ctl
; exit
; end;
612 SetLength(ctlsToKill
, Length(ctlsToKill
)+1);
613 ctlsToKill
[High(ctlsToKill
)] := ctl
;
617 procedure processKills ();
622 for f
:= 0 to High(ctlsToKill
) do
624 ctl
:= ctlsToKill
[f
];
625 if (ctl
= nil) then break
;
626 ctlsToKill
[f
] := nil;
629 if (Length(ctlsToKill
) > 0) then ctlsToKill
[0] := nil; // just in case
633 // ////////////////////////////////////////////////////////////////////////// //
635 knownCtlClasses
: array of record
636 klass
: TUIControlClass
;
641 procedure registerCtlClass (aklass
: TUIControlClass
; const aname
: AnsiString);
643 assert(aklass
<> nil);
644 assert(Length(aname
) > 0);
645 SetLength(knownCtlClasses
, Length(knownCtlClasses
)+1);
646 knownCtlClasses
[High(knownCtlClasses
)].klass
:= aklass
;
647 knownCtlClasses
[High(knownCtlClasses
)].name
:= aname
;
651 function findCtlClass (const aname
: AnsiString): TUIControlClass
;
655 for f
:= 0 to High(knownCtlClasses
) do
657 if (strEquCI1251(aname
, knownCtlClasses
[f
].name
)) then
659 result
:= knownCtlClasses
[f
].klass
;
667 // ////////////////////////////////////////////////////////////////////////// //
669 TFlexLayouter
= specialize TFlexLayouterBase
<TUIControl
>;
671 procedure uiLayoutCtl (ctl
: TUIControl
);
675 if (ctl
= nil) then exit
;
676 lay
:= TFlexLayouter
.Create();
678 if (not ctl
.mStyleLoaded
) then ctl
.updateStyle();
679 if (ctl
is TUITopWindow
) and (TUITopWindow(ctl
).fitToScreen
) then TUITopWindow(ctl
).flFitToScreen();
684 //writeln('============================'); lay.dumpFlat();
686 //writeln('=== initial ==='); lay.dump();
688 //lay.calcMaxSizeInternal(0);
691 writeln('=== after first pass ===');
695 writeln('=== after second pass ===');
700 //writeln('=== final ==='); lay.dump();
702 if (ctl
.mParent
= nil) and (ctl
is TUITopWindow
) and (TUITopWindow(ctl
).mDoCenter
) then
704 TUITopWindow(ctl
).centerInScreen();
707 // calculate full size
708 ctl
.calcFullClientSize();
711 if (ctl
.mParent
= nil) then
713 if (ctl
.mFocused
= nil) or (ctl
.mFocused
= ctl
) or (not ctl
.mFocused
.enabled
) then
715 ctl
.mFocused
:= ctl
.findFirstFocus();
725 // ////////////////////////////////////////////////////////////////////////// //
727 uiTopList
: array of TUIControl
= nil;
728 uiGrabCtl
: TUIControl
= nil;
731 procedure uiUpdateStyles ();
735 for ctl
in uiTopList
do ctl
.updateStyle();
739 procedure uiMouseEvent (var evt
: TFUIMouseEvent
);
747 if (not evt
.alive
) then exit
;
749 ev
.x
:= trunc(ev
.x
/fuiRenderScale
);
750 ev
.y
:= trunc(ev
.y
/fuiRenderScale
);
751 ev
.dx
:= trunc(ev
.dx
/fuiRenderScale
); //FIXME
752 ev
.dy
:= trunc(ev
.dy
/fuiRenderScale
); //FIXME
754 if (uiGrabCtl
<> nil) then
756 uiGrabCtl
.mouseEvent(ev
);
757 if (ev
.release
) and ((ev
.bstate
and (not ev
.but
)) = 0) then uiGrabCtl
:= nil;
761 if (Length(uiTopList
) > 0) and (uiTopList
[High(uiTopList
)].enabled
) then uiTopList
[High(uiTopList
)].mouseEvent(ev
);
762 if (ev
.alive
) and (ev
.press
) then
764 for f
:= High(uiTopList
) downto 0 do
766 if uiTopList
[f
].toLocal(ev
.x
, ev
.y
, lx
, ly
) then
768 if (uiTopList
[f
].enabled
) and (f
<> High(uiTopList
)) then
770 if (Length(uiTopList
) > 0) and (uiTopList
[High(uiTopList
)].enabled
) then uiTopList
[High(uiTopList
)].blurred();
771 ctmp
:= uiTopList
[f
];
773 for c
:= f
+1 to High(uiTopList
) do uiTopList
[c
-1] := uiTopList
[c
];
774 uiTopList
[High(uiTopList
)] := ctmp
;
784 if (ev
.eaten
) then evt
.eat();
785 if (ev
.cancelled
) then evt
.cancel();
790 procedure uiKeyEvent (var evt
: TFUIKeyEvent
);
795 if (not evt
.alive
) then exit
;
797 ev
.x
:= trunc(ev
.x
/fuiRenderScale
);
798 ev
.y
:= trunc(ev
.y
/fuiRenderScale
);
800 if (Length(uiTopList
) > 0) and (uiTopList
[High(uiTopList
)].enabled
) then uiTopList
[High(uiTopList
)].keyEvent(ev
);
801 //if (ev.release) then begin ev.eat(); exit; end;
803 if (ev
.eaten
) then evt
.eat();
804 if (ev
.cancelled
) then evt
.cancel();
809 procedure uiFocus ();
811 if (Length(uiTopList
) > 0) and (uiTopList
[High(uiTopList
)].enabled
) then uiTopList
[High(uiTopList
)].activated();
817 if (Length(uiTopList
) > 0) and (uiTopList
[High(uiTopList
)].enabled
) then uiTopList
[High(uiTopList
)].blurred();
827 //if (uiContext = nil) then uiContext := TGxContext.Create();
828 gxSetContext(uiContext
, fuiRenderScale
);
829 uiContext
.resetClip();
831 for f
:= 0 to High(uiTopList
) do
835 if (f
<> High(uiTopList
)) then
837 cidx
:= ctl
.getColorIndex
;
838 uiContext
.darkenRect(ctl
.x0
, ctl
.y0
, ctl
.width
, ctl
.height
, ctl
.mDarken
[cidx
]);
847 procedure uiAddWindow (ctl
: TUIControl
);
851 if (ctl
= nil) then exit
;
853 if not (ctl
is TUITopWindow
) then exit
; // alas
854 for f
:= 0 to High(uiTopList
) do
856 if (uiTopList
[f
] = ctl
) then
858 if (f
<> High(uiTopList
)) then
860 if (Length(uiTopList
) > 0) and (uiTopList
[High(uiTopList
)].enabled
) then uiTopList
[High(uiTopList
)].blurred();
861 for c
:= f
+1 to High(uiTopList
) do uiTopList
[c
-1] := uiTopList
[c
];
862 uiTopList
[High(uiTopList
)] := ctl
;
868 if (Length(uiTopList
) > 0) and (uiTopList
[High(uiTopList
)].enabled
) then uiTopList
[High(uiTopList
)].blurred();
869 SetLength(uiTopList
, Length(uiTopList
)+1);
870 uiTopList
[High(uiTopList
)] := ctl
;
871 if (not ctl
.mStyleLoaded
) then ctl
.updateStyle();
876 procedure uiRemoveWindow (ctl
: TUIControl
);
880 if (ctl
= nil) then exit
;
882 if not (ctl
is TUITopWindow
) then exit
; // alas
883 for f
:= 0 to High(uiTopList
) do
885 if (uiTopList
[f
] = ctl
) then
888 for c
:= f
+1 to High(uiTopList
) do uiTopList
[c
-1] := uiTopList
[c
];
889 SetLength(uiTopList
, Length(uiTopList
)-1);
890 if (Length(uiTopList
) > 0) and (uiTopList
[High(uiTopList
)].enabled
) then uiTopList
[High(uiTopList
)].activated();
891 if (ctl
is TUITopWindow
) then
894 if assigned(TUITopWindow(ctl
).closeCB
) then TUITopWindow(ctl
).closeCB(ctl
);
896 if (TUITopWindow(ctl
).mFreeOnClose
) then scheduleKill(ctl
);
905 function uiVisibleWindow (ctl
: TUIControl
): Boolean;
910 if (ctl
= nil) then exit
;
912 if not (ctl
is TUITopWindow
) then exit
; // alas
913 for f
:= 0 to High(uiTopList
) do
915 if (uiTopList
[f
] = ctl
) then begin result
:= true; exit
; end;
920 // ////////////////////////////////////////////////////////////////////////// //
921 constructor TUIControl
.Create ();
926 procedure TUIControl
.AfterConstruction ();
934 mHeight
:= uiContext
.charHeight(' ');
942 mDrawShadow
:= false;
944 // layouter interface
945 //mDefSize := TLaySize.Create(64, uiContext.charHeight(' ')); // default size
946 mDefSize
:= TLaySize
.Create(0, 0); // default size: hidden control
947 mMaxSize
:= TLaySize
.Create(-1, -1); // maximum size
948 mPadding
:= TLaySize
.Create(0, 0);
956 mAlign
:= -1; // left/top
958 mStyleLoaded
:= false;
962 destructor TUIControl
.Destroy ();
966 if (mParent
<> nil) then
969 for f
:= 0 to High(mParent
.mChildren
) do
971 if (mParent
.mChildren
[f
] = self
) then
973 for c
:= f
+1 to High(mParent
.mChildren
) do mParent
.mChildren
[c
-1] := mParent
.mChildren
[c
];
974 SetLength(mParent
.mChildren
, Length(mParent
.mChildren
)-1);
978 for f
:= 0 to High(mChildren
) do
980 mChildren
[f
].mParent
:= nil;
987 function TUIControl
.getColorIndex (): Integer; inline;
989 if (not enabled
) then begin result
:= ClrIdxDisabled
; exit
; end;
990 // top windows: no focus hack
991 if (self
is TUITopWindow
) then
993 if (getActive
) then begin result
:= ClrIdxActive
; exit
; end;
997 // if control cannot be focused, take "active" color scheme for it (it is easier this way)
998 if (not canFocus
) or (getActive
) then begin result
:= ClrIdxActive
; exit
; end;
1000 result
:= ClrIdxInactive
;
1003 procedure TUIControl
.updateStyle ();
1005 stl
: TUIStyle
= nil;
1009 while (ctl
<> nil) do
1011 if (Length(ctl
.mStyleId
) <> 0) then begin stl
:= uiFindStyle(ctl
.mStyleId
); break
; end;
1014 if (stl
= nil) then stl
:= uiFindStyle(''); // default
1016 for ctl
in mChildren
do ctl
.updateStyle();
1017 mStyleLoaded
:= true;
1020 procedure TUIControl
.cacheStyle (root
: TUIStyle
);
1024 //writeln('caching style for <', className, '> (', mCtl4Style, ')...');
1027 mBackColor
[ClrIdxActive
] := root
.get('back-color', 'active', cst
).asRGBADef(TGxRGBA
.Create(0, 0, 128));
1028 mTextColor
[ClrIdxActive
] := root
.get('text-color', 'active', cst
).asRGBADef(TGxRGBA
.Create(255, 255, 255));
1029 mFrameColor
[ClrIdxActive
] := root
.get('frame-color', 'active', cst
).asRGBADef(TGxRGBA
.Create(255, 255, 255));
1030 mFrameTextColor
[ClrIdxActive
] := root
.get('frame-text-color', 'active', cst
).asRGBADef(TGxRGBA
.Create(255, 255, 255));
1031 mFrameIconColor
[ClrIdxActive
] := root
.get('frame-icon-color', 'active', cst
).asRGBADef(TGxRGBA
.Create(0, 255, 0));
1032 mSBarFullColor
[ClrIdxActive
] := root
.get('scrollbar-full-color', 'active', cst
).asRGBADef(TGxRGBA
.Create(255, 255, 255));
1033 mSBarEmptyColor
[ClrIdxActive
] := root
.get('scrollbar-empty-color', 'active', cst
).asRGBADef(TGxRGBA
.Create(128, 128, 128));
1034 mDarken
[ClrIdxActive
] := root
.get('darken', 'active', cst
).asInt(666);
1036 mBackColor
[ClrIdxDisabled
] := root
.get('back-color', 'disabled', cst
).asRGBADef(TGxRGBA
.Create(0, 0, 128));
1037 mTextColor
[ClrIdxDisabled
] := root
.get('text-color', 'disabled', cst
).asRGBADef(TGxRGBA
.Create(127, 127, 127));
1038 mFrameColor
[ClrIdxDisabled
] := root
.get('frame-color', 'disabled', cst
).asRGBADef(TGxRGBA
.Create(127, 127, 127));
1039 mFrameTextColor
[ClrIdxDisabled
] := root
.get('frame-text-color', 'disabled', cst
).asRGBADef(TGxRGBA
.Create(127, 127, 127));
1040 mFrameIconColor
[ClrIdxDisabled
] := root
.get('frame-icon-color', 'disabled', cst
).asRGBADef(TGxRGBA
.Create(0, 127, 0));
1041 mSBarFullColor
[ClrIdxDisabled
] := root
.get('scrollbar-full-color', 'disabled', cst
).asRGBADef(TGxRGBA
.Create(127, 127, 127));
1042 mSBarEmptyColor
[ClrIdxDisabled
] := root
.get('scrollbar-empty-color', 'disabled', cst
).asRGBADef(TGxRGBA
.Create(98, 98, 98));
1043 mDarken
[ClrIdxDisabled
] := root
.get('darken', 'disabled', cst
).asInt(666);
1045 mBackColor
[ClrIdxInactive
] := root
.get('back-color', 'inactive', cst
).asRGBADef(TGxRGBA
.Create(0, 0, 128));
1046 mTextColor
[ClrIdxInactive
] := root
.get('text-color', 'inactive', cst
).asRGBADef(TGxRGBA
.Create(255, 255, 255));
1047 mFrameColor
[ClrIdxInactive
] := root
.get('frame-color', 'inactive', cst
).asRGBADef(TGxRGBA
.Create(255, 255, 255));
1048 mFrameTextColor
[ClrIdxInactive
] := root
.get('frame-text-color', 'inactive', cst
).asRGBADef(TGxRGBA
.Create(255, 255, 255));
1049 mFrameIconColor
[ClrIdxInactive
] := root
.get('frame-icon-color', 'inactive', cst
).asRGBADef(TGxRGBA
.Create(0, 255, 0));
1050 mSBarFullColor
[ClrIdxInactive
] := root
.get('scrollbar-full-color', 'inactive', cst
).asRGBADef(TGxRGBA
.Create(255, 255, 255));
1051 mSBarEmptyColor
[ClrIdxInactive
] := root
.get('scrollbar-empty-color', 'inactive', cst
).asRGBADef(TGxRGBA
.Create(128, 128, 128));
1052 mDarken
[ClrIdxInactive
] := root
.get('darken', 'inactive', cst
).asInt(666);
1056 // ////////////////////////////////////////////////////////////////////////// //
1057 function TUIControl
.getDefSize (): TLaySize
; inline; begin result
:= mLayDefSize
; end;
1058 function TUIControl
.getMaxSize (): TLaySize
; inline; begin result
:= mLayMaxSize
; end;
1059 function TUIControl
.getPadding (): TLaySize
; inline; begin result
:= mPadding
; end;
1060 function TUIControl
.getFlex (): Integer; inline; begin result
:= mFlex
; end;
1061 function TUIControl
.isHorizBox (): Boolean; inline; begin result
:= mHoriz
; end;
1062 function TUIControl
.noPad (): Boolean; inline; begin result
:= mNoPad
; end;
1063 function TUIControl
.getAlign (): Integer; inline; begin result
:= mAlign
; end;
1064 function TUIControl
.getExpand (): Boolean; inline; begin result
:= mExpand
; end;
1065 function TUIControl
.getHGroup (): AnsiString; inline; begin result
:= mHGroup
; end;
1066 function TUIControl
.getVGroup (): AnsiString; inline; begin result
:= mVGroup
; end;
1067 function TUIControl
.getMargins (): TLayMargins
; inline; begin result
:= TLayMargins
.Create(mFrameHeight
, mFrameWidth
, mFrameHeight
, mFrameWidth
); end;
1069 procedure TUIControl
.setActualSizePos (constref apos
: TLayPos
; constref asize
: TLaySize
); inline;
1071 //writeln(self.className, '; pos=', apos.toString, '; size=', asize.toString);
1072 if (mParent
<> nil) then
1079 if (mLayMaxSize
.w
>= 0) then mWidth
:= nmin(mWidth
, mLayMaxSize
.w
);
1080 if (mLayMaxSize
.h
>= 0) then mHeight
:= nmin(mHeight
, mLayMaxSize
.h
);
1083 procedure TUIControl
.layPrepare ();
1085 mLayDefSize
:= mDefSize
;
1086 if (mLayDefSize
.w
<> 0) or (mLayDefSize
.h
<> 0) then
1088 mLayMaxSize
:= mMaxSize
;
1089 if (mLayMaxSize
.w
>= 0) then begin mLayDefSize
.w
+= mFrameWidth
*2; mLayMaxSize
.w
+= mFrameWidth
*2; end;
1090 if (mLayMaxSize
.h
>= 0) then begin mLayDefSize
.h
+= mFrameHeight
*2; mLayMaxSize
.h
+= mFrameHeight
*2; end;
1094 mLayMaxSize
:= TLaySize
.Create(0, 0);
1099 // ////////////////////////////////////////////////////////////////////////// //
1100 function TUIControl
.parsePos (par
: TTextParser
): TLayPos
;
1102 ech
: AnsiChar = ')';
1104 if (par
.eatDelim('[')) then ech
:= ']' else par
.expectDelim('(');
1105 result
.x
:= par
.expectInt();
1106 par
.eatDelim(','); // optional comma
1107 result
.y
:= par
.expectInt();
1108 par
.eatDelim(','); // optional comma
1109 par
.expectDelim(ech
);
1112 function TUIControl
.parseSize (par
: TTextParser
): TLaySize
;
1114 ech
: AnsiChar = ')';
1116 if (par
.eatDelim('[')) then ech
:= ']' else par
.expectDelim('(');
1117 result
.w
:= par
.expectInt();
1118 par
.eatDelim(','); // optional comma
1119 result
.h
:= par
.expectInt();
1120 par
.eatDelim(','); // optional comma
1121 par
.expectDelim(ech
);
1124 function TUIControl
.parsePadding (par
: TTextParser
): TLaySize
;
1126 result
:= parseSize(par
);
1129 function TUIControl
.parseHPadding (par
: TTextParser
; def
: Integer): TLaySize
;
1134 result
.w
:= par
.expectInt();
1138 result
:= parsePadding(par
);
1142 function TUIControl
.parseVPadding (par
: TTextParser
; def
: Integer): TLaySize
;
1147 result
.h
:= par
.expectInt();
1151 result
:= parsePadding(par
);
1155 function TUIControl
.parseBool (par
: TTextParser
): Boolean;
1158 par
.eatIdOrStrCI('true') or
1159 par
.eatIdOrStrCI('yes') or
1160 par
.eatIdOrStrCI('tan');
1163 if (not par
.eatIdOrStrCI('false')) and (not par
.eatIdOrStrCI('no')) and (not par
.eatIdOrStrCI('ona')) then
1165 par
.error('boolean value expected');
1170 function TUIControl
.parseAnyAlign (par
: TTextParser
): Integer;
1172 if (par
.eatIdOrStrCI('left')) or (par
.eatIdOrStrCI('top')) then result
:= -1
1173 else if (par
.eatIdOrStrCI('right')) or (par
.eatIdOrStrCI('bottom')) then result
:= 1
1174 else if (par
.eatIdOrStrCI('center')) then result
:= 0
1175 else par
.error('invalid align value');
1178 function TUIControl
.parseHAlign (par
: TTextParser
): Integer;
1180 if (par
.eatIdOrStrCI('left')) then result
:= -1
1181 else if (par
.eatIdOrStrCI('right')) then result
:= 1
1182 else if (par
.eatIdOrStrCI('center')) then result
:= 0
1183 else par
.error('invalid horizontal align value');
1186 function TUIControl
.parseVAlign (par
: TTextParser
): Integer;
1188 if (par
.eatIdOrStrCI('top')) then result
:= -1
1189 else if (par
.eatIdOrStrCI('bottom')) then result
:= 1
1190 else if (par
.eatIdOrStrCI('center')) then result
:= 0
1191 else par
.error('invalid vertical align value');
1194 procedure TUIControl
.parseTextAlign (par
: TTextParser
; var h
, v
: Integer);
1196 wasH
: Boolean = false;
1197 wasV
: Boolean = false;
1201 if (par
.eatIdOrStrCI('left')) then
1203 if wasH
then par
.error('too many align directives');
1208 if (par
.eatIdOrStrCI('right')) then
1210 if wasH
then par
.error('too many align directives');
1215 if (par
.eatIdOrStrCI('hcenter')) then
1217 if wasH
then par
.error('too many align directives');
1222 if (par
.eatIdOrStrCI('top')) then
1224 if wasV
then par
.error('too many align directives');
1229 if (par
.eatIdOrStrCI('bottom')) then
1231 if wasV
then par
.error('too many align directives');
1236 if (par
.eatIdOrStrCI('vcenter')) then
1238 if wasV
then par
.error('too many align directives');
1243 if (par
.eatIdOrStrCI('center')) then
1245 if wasV
or wasH
then par
.error('too many align directives');
1254 if not wasV
and not wasH
then par
.error('invalid align value');
1257 function TUIControl
.parseOrientation (const prname
: AnsiString; par
: TTextParser
): Boolean;
1259 if (strEquCI1251(prname
, 'orientation')) or (strEquCI1251(prname
, 'orient')) then
1261 if (par
.eatIdOrStrCI('horizontal')) or (par
.eatIdOrStrCI('horiz')) then mHoriz
:= true
1262 else if (par
.eatIdOrStrCI('vertical')) or (par
.eatIdOrStrCI('vert')) then mHoriz
:= false
1263 else par
.error('`horizontal` or `vertical` expected');
1272 // par should be on '{'; final '}' is eaten
1273 procedure TUIControl
.parseProperties (par
: TTextParser
);
1277 if (not par
.eatDelim('{')) then exit
;
1278 while (not par
.eatDelim('}')) do
1280 if (not par
.isIdOrStr
) then par
.error('property name expected');
1283 par
.eatDelim(':'); // optional
1284 if not parseProperty(pn
, par
) then par
.errorfmt('invalid property name ''%s''', [pn
]);
1285 par
.eatDelim(','); // optional
1289 // par should be on '{'
1290 procedure TUIControl
.parseChildren (par
: TTextParser
);
1292 cc
: TUIControlClass
;
1295 par
.expectDelim('{');
1296 while (not par
.eatDelim('}')) do
1298 if (not par
.isIdOrStr
) then par
.error('control name expected');
1299 cc
:= findCtlClass(par
.tokStr
);
1300 if (cc
= nil) then par
.errorfmt('unknown control name: ''%s''', [par
.tokStr
]);
1301 //writeln('children for <', par.tokStr, '>: <', cc.className, '>');
1303 par
.eatDelim(':'); // optional
1305 //writeln(' mHoriz=', ctl.mHoriz);
1307 ctl
.parseProperties(par
);
1312 //writeln(': ', ctl.mDefSize.toString);
1314 par
.eatDelim(','); // optional
1319 function TUIControl
.parseProperty (const prname
: AnsiString; par
: TTextParser
): Boolean;
1322 if (strEquCI1251(prname
, 'id')) then begin mId
:= par
.expectIdOrStr(true); exit
; end; // allow empty strings
1323 if (strEquCI1251(prname
, 'style')) then begin mStyleId
:= par
.expectIdOrStr(); exit
; end; // no empty strings
1324 if (strEquCI1251(prname
, 'flex')) then begin flex
:= par
.expectInt(); exit
; end;
1326 if (strEquCI1251(prname
, 'defsize')) or (strEquCI1251(prname
, 'size')) then begin mDefSize
:= parseSize(par
); exit
; end;
1327 if (strEquCI1251(prname
, 'maxsize')) then begin mMaxSize
:= parseSize(par
); exit
; end;
1328 if (strEquCI1251(prname
, 'defwidth')) or (strEquCI1251(prname
, 'width')) then begin mDefSize
.w
:= par
.expectInt(); exit
; end;
1329 if (strEquCI1251(prname
, 'defheight')) or (strEquCI1251(prname
, 'height')) then begin mDefSize
.h
:= par
.expectInt(); exit
; end;
1330 if (strEquCI1251(prname
, 'maxwidth')) then begin mMaxSize
.w
:= par
.expectInt(); exit
; end;
1331 if (strEquCI1251(prname
, 'maxheight')) then begin mMaxSize
.h
:= par
.expectInt(); exit
; end;
1333 if (strEquCI1251(prname
, 'padding')) then begin mPadding
:= parsePadding(par
); exit
; end;
1334 if (strEquCI1251(prname
, 'nopad')) then begin mNoPad
:= true; exit
; end;
1336 if (strEquCI1251(prname
, 'expand')) then begin mExpand
:= parseBool(par
); exit
; end;
1338 if (strEquCI1251(prname
, 'align')) then begin mAlign
:= parseAnyAlign(par
); exit
; end;
1339 if (strEquCI1251(prname
, 'hgroup')) then begin mHGroup
:= par
.expectIdOrStr(true); exit
; end; // allow empty strings
1340 if (strEquCI1251(prname
, 'vgroup')) then begin mVGroup
:= par
.expectIdOrStr(true); exit
; end; // allow empty strings
1342 if (strEquCI1251(prname
, 'canfocus')) then begin mCanFocus
:= true; exit
; end;
1343 if (strEquCI1251(prname
, 'nofocus')) then begin mCanFocus
:= false; exit
; end;
1344 if (strEquCI1251(prname
, 'disabled')) then begin mEnabled
:= false; exit
; end;
1345 if (strEquCI1251(prname
, 'enabled')) then begin mEnabled
:= true; exit
; end;
1346 if (strEquCI1251(prname
, 'escclose')) then begin mEscClose
:= not parseBool(par
); exit
; end;
1347 if (strEquCI1251(prname
, 'default')) then begin mDefault
:= true; exit
; end;
1348 if (strEquCI1251(prname
, 'cancel')) then begin mCancel
:= true; exit
; end;
1353 // ////////////////////////////////////////////////////////////////////////// //
1354 procedure TUIControl
.activated ();
1356 makeVisibleInParent();
1360 procedure TUIControl
.blurred ();
1362 if (uiGrabCtl
= self
) then uiGrabCtl
:= nil;
1366 procedure TUIControl
.calcFullClientSize ();
1370 mFullSize
:= TLaySize
.Create(0, 0);
1371 if (mWidth
< 1) or (mHeight
< 1) then exit
;
1372 for ctl
in mChildren
do
1374 ctl
.calcFullClientSize();
1375 mFullSize
.w
:= nmax(mFullSize
.w
, ctl
.mX
-mFrameWidth
+ctl
.mFullSize
.w
);
1376 mFullSize
.h
:= nmax(mFullSize
.h
, ctl
.mY
-mFrameHeight
+ctl
.mFullSize
.h
);
1378 mFullSize
.w
:= nmax(mFullSize
.w
, mWidth
-mFrameWidth
*2);
1379 mFullSize
.h
:= nmax(mFullSize
.h
, mHeight
-mFrameHeight
*2);
1383 function TUIControl
.topLevel (): TUIControl
; inline;
1386 while (result
.mParent
<> nil) do result
:= result
.mParent
;
1390 function TUIControl
.getEnabled (): Boolean;
1395 if (not mEnabled
) then exit
;
1397 while (ctl
<> nil) do
1399 if (not ctl
.mEnabled
) then exit
;
1406 procedure TUIControl
.setEnabled (v
: Boolean); inline;
1408 if (mEnabled
= v
) then exit
;
1410 if (not v
) and focused
then setFocused(false);
1414 function TUIControl
.getFocused (): Boolean; inline;
1416 if (mParent
= nil) then
1418 result
:= (Length(uiTopList
) > 0) and (uiTopList
[High(uiTopList
)] = self
);
1422 result
:= (topLevel
.mFocused
= self
);
1423 if (result
) then result
:= (Length(uiTopList
) > 0) and (uiTopList
[High(uiTopList
)] = topLevel
);
1428 function TUIControl
.getActive (): Boolean; inline;
1432 if (mParent
= nil) then
1434 result
:= (Length(uiTopList
) > 0) and (uiTopList
[High(uiTopList
)] = self
);
1438 ctl
:= topLevel
.mFocused
;
1439 while (ctl
<> nil) and (ctl
<> self
) do ctl
:= ctl
.mParent
;
1440 result
:= (ctl
= self
);
1441 if (result
) then result
:= (Length(uiTopList
) > 0) and (uiTopList
[High(uiTopList
)] = topLevel
);
1446 procedure TUIControl
.setFocused (v
: Boolean); inline;
1453 if (tl
.mFocused
= self
) then
1455 blurred(); // this will reset grab, but still...
1456 if (uiGrabCtl
= self
) then uiGrabCtl
:= nil;
1457 tl
.mFocused
:= tl
.findNextFocus(self
, true);
1458 if (tl
.mFocused
= self
) then tl
.mFocused
:= nil;
1459 if (tl
.mFocused
<> nil) then tl
.mFocused
.activated();
1463 if (not canFocus
) then exit
;
1464 if (tl
.mFocused
<> self
) then
1466 if (tl
.mFocused
<> nil) then tl
.mFocused
.blurred();
1467 tl
.mFocused
:= self
;
1468 if (uiGrabCtl
<> self
) then uiGrabCtl
:= nil;
1474 function TUIControl
.getCanFocus (): Boolean; inline;
1476 result
:= (getEnabled
) and (mCanFocus
) and (mWidth
> 0) and (mHeight
> 0);
1480 function TUIControl
.isMyChild (ctl
: TUIControl
): Boolean;
1483 while (ctl
<> nil) do
1485 if (ctl
.mParent
= self
) then exit
;
1492 // returns `true` if global coords are inside this control
1493 function TUIControl
.toLocal (var x
, y
: Integer): Boolean;
1495 if (mParent
= nil) then
1499 result
:= true; // hack
1503 result
:= mParent
.toLocal(x
, y
);
1504 Inc(x
, mParent
.mScrollX
);
1505 Inc(y
, mParent
.mScrollY
);
1508 if result
then result
:= (x
>= 0) and (y
>= 0) and (x
< mParent
.mWidth
) and (y
< mParent
.mHeight
);
1510 if result
then result
:= (x
>= 0) and (y
>= 0) and (x
< mWidth
) and (y
< mHeight
);
1513 function TUIControl
.toLocal (gx
, gy
: Integer; out x
, y
: Integer): Boolean; inline;
1517 result
:= toLocal(x
, y
);
1521 procedure TUIControl
.toGlobal (var x
, y
: Integer);
1525 if (mParent
<> nil) then
1527 Dec(x
, mParent
.mScrollX
);
1528 Dec(y
, mParent
.mScrollY
);
1529 mParent
.toGlobal(x
, y
);
1533 procedure TUIControl
.toGlobal (lx
, ly
: Integer; out x
, y
: Integer); inline;
1540 procedure TUIControl
.getDrawRect (out gx
, gy
, wdt
, hgt
: Integer);
1544 if (mParent
= nil) then
1553 toGlobal(0, 0, cgx
, cgy
);
1554 mParent
.getDrawRect(gx
, gy
, wdt
, hgt
);
1555 if (wdt
> 0) and (hgt
> 0) then
1557 if (not intersectRect(gx
, gy
, wdt
, hgt
, cgx
, cgy
, mWidth
, mHeight
)) then
1567 // x and y are global coords
1568 function TUIControl
.controlAtXY (x
, y
: Integer; allowDisabled
: Boolean=false): TUIControl
;
1574 if (not allowDisabled
) and (not enabled
) then exit
;
1575 if (mWidth
< 1) or (mHeight
< 1) then exit
;
1576 if not toLocal(x
, y
, lx
, ly
) then exit
;
1577 for f
:= High(mChildren
) downto 0 do
1579 result
:= mChildren
[f
].controlAtXY(x
, y
, allowDisabled
);
1580 if (result
<> nil) then exit
;
1586 function TUIControl
.parentScrollX (): Integer; inline; begin if (mParent
<> nil) then result
:= mParent
.mScrollX
else result
:= 0; end;
1587 function TUIControl
.parentScrollY (): Integer; inline; begin if (mParent
<> nil) then result
:= mParent
.mScrollY
else result
:= 0; end;
1590 procedure TUIControl
.makeVisibleInParent ();
1592 sy
, ey
, cy
: Integer;
1595 if (mWidth
< 1) or (mHeight
< 1) then exit
;
1597 if (p
= nil) then exit
;
1598 if (p
.mFullSize
.w
< 1) or (p
.mFullSize
.h
< 1) then
1604 p
.makeVisibleInParent();
1605 cy
:= mY
-p
.mFrameHeight
;
1607 ey
:= sy
+(p
.mHeight
-p
.mFrameHeight
*2);
1610 p
.mScrollY
:= nmax(0, cy
);
1612 else if (cy
+mHeight
> ey
) then
1614 p
.mScrollY
:= nmax(0, cy
+mHeight
-(p
.mHeight
-p
.mFrameHeight
*2));
1619 // ////////////////////////////////////////////////////////////////////////// //
1620 function TUIControl
.prevSibling (): TUIControl
;
1624 if (mParent
<> nil) then
1626 for f
:= 1 to High(mParent
.mChildren
) do
1628 if (mParent
.mChildren
[f
] = self
) then begin result
:= mParent
.mChildren
[f
-1]; exit
; end;
1634 function TUIControl
.nextSibling (): TUIControl
;
1638 if (mParent
<> nil) then
1640 for f
:= 0 to High(mParent
.mChildren
)-1 do
1642 if (mParent
.mChildren
[f
] = self
) then begin result
:= mParent
.mChildren
[f
+1]; exit
; end;
1648 function TUIControl
.firstChild (): TUIControl
; inline;
1650 if (Length(mChildren
) <> 0) then result
:= mChildren
[0] else result
:= nil;
1653 function TUIControl
.lastChild (): TUIControl
; inline;
1655 if (Length(mChildren
) <> 0) then result
:= mChildren
[High(mChildren
)] else result
:= nil;
1659 function TUIControl
.findFirstFocus (): TUIControl
;
1666 for f
:= 0 to High(mChildren
) do
1668 result
:= mChildren
[f
].findFirstFocus();
1669 if (result
<> nil) then exit
;
1671 if (canFocus
) then result
:= self
;
1676 function TUIControl
.findLastFocus (): TUIControl
;
1683 for f
:= High(mChildren
) downto 0 do
1685 result
:= mChildren
[f
].findLastFocus();
1686 if (result
<> nil) then exit
;
1688 if (canFocus
) then result
:= self
;
1693 function TUIControl
.findNextFocus (cur
: TUIControl
; wrap
: Boolean): TUIControl
;
1695 curHit
: Boolean = false;
1697 function checkFocus (ctl
: TUIControl
): Boolean;
1701 result
:= (ctl
.canFocus
);
1705 curHit
:= (ctl
= cur
);
1706 result
:= false; // don't stop
1714 if not isMyChild(cur
) then
1716 result
:= findFirstFocus();
1720 result
:= forEachControl(checkFocus
);
1721 if (result
= nil) and (wrap
) then result
:= findFirstFocus();
1727 function TUIControl
.findPrevFocus (cur
: TUIControl
; wrap
: Boolean): TUIControl
;
1729 lastCtl
: TUIControl
= nil;
1731 function checkFocus (ctl
: TUIControl
): Boolean;
1740 if (ctl
.canFocus
) then lastCtl
:= ctl
;
1748 if not isMyChild(cur
) then
1750 result
:= findLastFocus();
1754 forEachControl(checkFocus
);
1755 if (lastCtl
= nil) and (wrap
) then lastCtl
:= findLastFocus();
1757 //if (lastCtl <> nil) then writeln('ctl<', lastCtl.className, '>: {', lastCtl.id, '}');
1763 function TUIControl
.findDefaulControl (): TUIControl
;
1769 if (mDefault
) then begin result
:= self
; exit
; end;
1770 for ctl
in mChildren
do
1772 result
:= ctl
.findDefaulControl();
1773 if (result
<> nil) then exit
;
1779 function TUIControl
.findCancelControl (): TUIControl
;
1785 if (mCancel
) then begin result
:= self
; exit
; end;
1786 for ctl
in mChildren
do
1788 result
:= ctl
.findCancelControl();
1789 if (result
<> nil) then exit
;
1796 function TUIControl
.findControlById (const aid
: AnsiString): TUIControl
;
1800 if (strEquCI1251(aid
, mId
)) then begin result
:= self
; exit
; end;
1801 for ctl
in mChildren
do
1803 result
:= ctl
.findControlById(aid
);
1804 if (result
<> nil) then exit
;
1810 procedure TUIControl
.appendChild (ctl
: TUIControl
);
1812 if (ctl
= nil) then exit
;
1813 if (ctl
.mParent
<> nil) then exit
;
1814 SetLength(mChildren
, Length(mChildren
)+1);
1815 mChildren
[High(mChildren
)] := ctl
;
1816 ctl
.mParent
:= self
;
1817 Inc(ctl
.mX
, mFrameWidth
);
1818 Inc(ctl
.mY
, mFrameHeight
);
1819 if (ctl
.mWidth
> 0) and (ctl
.mHeight
> 0) and
1820 (ctl
.mX
+ctl
.mWidth
> mFrameWidth
) and (ctl
.mY
+ctl
.mHeight
> mFrameHeight
) then
1822 if (mWidth
+mFrameWidth
< ctl
.mX
+ctl
.mWidth
) then mWidth
:= ctl
.mX
+ctl
.mWidth
+mFrameWidth
;
1823 if (mHeight
+mFrameHeight
< ctl
.mY
+ctl
.mHeight
) then mHeight
:= ctl
.mY
+ctl
.mHeight
+mFrameHeight
;
1828 function TUIControl
.setActionCBFor (const aid
: AnsiString; cb
: TActionCB
): TActionCB
;
1833 if (ctl
<> nil) then
1835 result
:= ctl
.actionCB
;
1845 function TUIControl
.forEachChildren (cb
: TCtlEnumCB
): TUIControl
;
1850 if (not assigned(cb
)) then exit
;
1851 for ctl
in mChildren
do
1853 if cb(ctl
) then begin result
:= ctl
; exit
; end;
1858 function TUIControl
.forEachControl (cb
: TCtlEnumCB
; includeSelf
: Boolean=true): TUIControl
;
1860 function forChildren (p
: TUIControl
; incSelf
: Boolean): TUIControl
;
1865 if (p
= nil) then exit
;
1866 if (incSelf
) and (cb(p
)) then begin result
:= p
; exit
; end;
1867 for ctl
in p
.mChildren
do
1869 result
:= forChildren(ctl
, true);
1870 if (result
<> nil) then break
;
1876 if (not assigned(cb
)) then exit
;
1877 result
:= forChildren(self
, includeSelf
);
1881 procedure TUIControl
.close (); // this closes *top-level* control
1886 uiRemoveWindow(ctl
);
1887 if (ctl
is TUITopWindow
) and (TUITopWindow(ctl
).mFreeOnClose
) then scheduleKill(ctl
); // just in case
1891 procedure TUIControl
.doAction ();
1893 if assigned(actionCB
) then actionCB(self
);
1897 // ////////////////////////////////////////////////////////////////////////// //
1898 procedure TUIControl
.setScissor (lx
, ly
, lw
, lh
: Integer);
1900 gx
, gy
, wdt
, hgt
, cgx
, cgy
: Integer;
1902 if (not intersectRect(lx
, ly
, lw
, lh
, 0, 0, mWidth
, mHeight
)) then
1904 uiContext
.clip
:= TGxRect
.Create(0, 0, 0, 0);
1908 getDrawRect(gx
, gy
, wdt
, hgt
);
1910 toGlobal(lx
, ly
, cgx
, cgy
);
1911 if (not intersectRect(gx
, gy
, wdt
, hgt
, cgx
, cgy
, lw
, lh
)) then
1913 uiContext
.clip
:= TGxRect
.Create(0, 0, 0, 0);
1917 uiContext
.clip
:= savedClip
;
1918 uiContext
.combineClip(TGxRect
.Create(gx
, gy
, wdt
, hgt
));
1919 //uiContext.clip := TGxRect.Create(gx, gy, wdt, hgt);
1922 procedure TUIControl
.resetScissorNC (); inline;
1924 setScissor(0, 0, mWidth
, mHeight
);
1927 procedure TUIControl
.resetScissor (); inline;
1929 if ((mFrameWidth
<= 0) and (mFrameHeight
<= 0)) then
1935 setScissor(mFrameWidth
, mFrameHeight
, mWidth
-mFrameWidth
*2, mHeight
-mFrameHeight
*2);
1940 // ////////////////////////////////////////////////////////////////////////// //
1941 procedure TUIControl
.drawFrame (gx
, gy
, resx
, thalign
: Integer; const text: AnsiString; dbl
: Boolean);
1943 cidx
, tx
, tw
: Integer;
1945 if (mFrameWidth
< 1) or (mFrameHeight
< 1) then exit
;
1946 cidx
:= getColorIndex
;
1947 uiContext
.color
:= mFrameColor
[cidx
];
1948 case mFrameHeight
of
1953 uiContext
.rect(gx
+3, gy
+3, mWidth
-6, mHeight
-6);
1954 uiContext
.rect(gx
+5, gy
+5, mWidth
-10, mHeight
-10);
1958 uiContext
.rect(gx
+4, gy
+4, mWidth
-8, mHeight
-8);
1965 uiContext
.rect(gx
+3, gy
+3+3, mWidth
-6, mHeight
-6-6);
1966 uiContext
.rect(gx
+5, gy
+5+3, mWidth
-10, mHeight
-10-6);
1970 uiContext
.rect(gx
+4, gy
+4+3, mWidth
-8, mHeight
-8-6);
1977 uiContext
.rect(gx
+3, gy
+3+4, mWidth
-6, mHeight
-6-8);
1978 uiContext
.rect(gx
+5, gy
+5+4, mWidth
-10, mHeight
-10-8);
1982 uiContext
.rect(gx
+4, gy
+4+4, mWidth
-8, mHeight
-8-8);
1998 if (Length(text) > 0) then
2000 if (resx
< 0) then resx
:= 0;
2001 tw
:= uiContext
.textWidth(text);
2002 setScissor(mFrameWidth
+resx
, 0, mWidth
-mFrameWidth
*2-resx
, mFrameHeight
);
2003 if (thalign
< 0) then tx
:= gx
+resx
+mFrameWidth
+2
2004 else if (thalign
> 0) then tx
:= gx
+mWidth
-mFrameWidth
-1-tw
2005 else tx
:= (gx
+resx
+mFrameWidth
)+(mWidth
-mFrameWidth
*2-resx
-tw
) div 2;
2006 uiContext
.color
:= mBackColor
[cidx
];
2007 uiContext
.fillRect(tx
-2, gy
, tw
+4, mFrameHeight
);
2008 uiContext
.color
:= mFrameTextColor
[cidx
];
2009 uiContext
.drawText(tx
, gy
, text);
2014 procedure TUIControl
.draw ();
2020 if (mWidth
< 1) or (mHeight
< 1) or (uiContext
= nil) or (not uiContext
.active
) then exit
;
2021 toGlobal(0, 0, gx
, gy
);
2023 savedClip
:= uiContext
.clip
;
2026 drawControl(gx
, gy
);
2028 for f
:= 0 to High(mChildren
) do mChildren
[f
].draw();
2030 drawControlPost(gx
, gy
);
2032 uiContext
.clip
:= savedClip
;
2036 procedure TUIControl
.drawControl (gx
, gy
: Integer);
2040 procedure TUIControl
.drawControlPost (gx
, gy
: Integer);
2042 // shadow for top-level controls
2043 if (mParent
= nil) and (mDrawShadow
) and (mWidth
> 0) and (mHeight
> 0) then
2045 uiContext
.resetClip();
2046 uiContext
.darkenRect(gx
+mWidth
, gy
+8, 8, mHeight
, 128);
2047 uiContext
.darkenRect(gx
+8, gy
+mHeight
, mWidth
-8, 8, 128);
2052 // ////////////////////////////////////////////////////////////////////////// //
2053 procedure TUIControl
.mouseEvent (var ev
: TFUIMouseEvent
);
2057 if (not enabled
) then exit
;
2058 if (mWidth
< 1) or (mHeight
< 1) then exit
;
2059 ctl
:= controlAtXY(ev
.x
, ev
.y
);
2060 if (ctl
= nil) then exit
;
2061 if (ctl
.canFocus
) and (ev
.press
) then
2063 if (ctl
<> topLevel
.mFocused
) then ctl
.setFocused(true);
2066 if (ctl
<> self
) then ctl
.mouseEvent(ev
);
2071 procedure TUIControl
.keyEvent (var ev
: TFUIKeyEvent
);
2073 function doPreKey (ctl
: TUIControl
): Boolean;
2075 if (not ctl
.enabled
) then begin result
:= false; exit
; end;
2076 ctl
.keyEventPre(ev
);
2077 result
:= (not ev
.alive
); // stop if event was consumed
2080 function doPostKey (ctl
: TUIControl
): Boolean;
2082 if (not ctl
.enabled
) then begin result
:= false; exit
; end;
2083 ctl
.keyEventPost(ev
);
2084 result
:= (not ev
.alive
); // stop if event was consumed
2090 if (not enabled
) then exit
;
2091 if (not ev
.alive
) then exit
;
2093 if (mParent
= nil) then
2095 forEachControl(doPreKey
);
2096 if (not ev
.alive
) then exit
;
2098 // focused control should process keyboard first
2099 if (topLevel
.mFocused
<> self
) and isMyChild(topLevel
.mFocused
) and (topLevel
.mFocused
.enabled
) then
2101 // bubble keyboard event
2102 ctl
:= topLevel
.mFocused
;
2103 while (ctl
<> nil) and (ctl
<> self
) do
2106 if (not ev
.alive
) then exit
;
2110 // for top-level controls
2111 if (mParent
= nil) then
2113 if (ev
= 'S-Tab') then
2115 ctl
:= findPrevFocus(mFocused
, true);
2116 if (ctl
<> nil) and (ctl
<> mFocused
) then ctl
.setFocused(true);
2120 if (ev
= 'Tab') then
2122 ctl
:= findNextFocus(mFocused
, true);
2123 if (ctl
<> nil) and (ctl
<> mFocused
) then ctl
.setFocused(true);
2127 if (ev
= 'Enter') or (ev
= 'C-Enter') then
2129 ctl
:= findDefaulControl();
2130 if (ctl
<> nil) then
2137 if (ev
= 'Escape') then
2139 ctl
:= findCancelControl();
2140 if (ctl
<> nil) then
2147 if mEscClose
and (ev
= 'Escape') then
2149 if (not assigned(closeRequestCB
)) or (closeRequestCB(self
)) then
2151 uiRemoveWindow(self
);
2157 if (not ev
.alive
) then exit
;
2158 forEachControl(doPostKey
);
2163 procedure TUIControl
.keyEventPre (var ev
: TFUIKeyEvent
);
2168 procedure TUIControl
.keyEventPost (var ev
: TFUIKeyEvent
);
2173 // ////////////////////////////////////////////////////////////////////////// //
2174 constructor TUITopWindow
.Create (const atitle
: AnsiString);
2181 procedure TUITopWindow
.AfterConstruction ();
2184 mFitToScreen
:= true;
2186 mFrameHeight
:= uiContext
.charHeight(#184);
2187 if (mWidth
< mFrameWidth
*2+uiContext
.iconWinWidth(TGxContext
.TWinIcon
.Close
)) then mWidth
:= mFrameWidth
*2+uiContext
.iconWinWidth(TGxContext
.TWinIcon
.Close
);
2188 if (mHeight
< mFrameHeight
*2) then mHeight
:= mFrameHeight
*2;
2189 if (Length(mTitle
) > 0) then
2191 if (mWidth
< uiContext
.textWidth(mTitle
)+mFrameWidth
*2+uiContext
.iconWinWidth(TGxContext
.TWinIcon
.Close
)) then
2193 mWidth
:= uiContext
.textWidth(mTitle
)+mFrameWidth
*2+uiContext
.iconWinWidth(TGxContext
.TWinIcon
.Close
);
2197 mDragScroll
:= TXMode
.None
;
2198 mDrawShadow
:= true;
2199 mWaitingClose
:= false;
2202 mCtl4Style
:= 'window';
2203 mDefSize
.w
:= nmax(1, mDefSize
.w
);
2204 mDefSize
.h
:= nmax(1, mDefSize
.h
);
2208 function TUITopWindow
.parseProperty (const prname
: AnsiString; par
: TTextParser
): Boolean;
2210 if (strEquCI1251(prname
, 'title')) or (strEquCI1251(prname
, 'caption')) then
2212 mTitle
:= par
.expectIdOrStr(true);
2216 if (strEquCI1251(prname
, 'children')) then
2222 if (strEquCI1251(prname
, 'position')) then
2224 if (par
.eatIdOrStrCI('default')) then mDoCenter
:= false
2225 else if (par
.eatIdOrStrCI('center')) then mDoCenter
:= true
2226 else par
.error('`center` or `default` expected');
2230 if (parseOrientation(prname
, par
)) then begin result
:= true; exit
; end;
2231 result
:= inherited parseProperty(prname
, par
);
2235 procedure TUITopWindow
.flFitToScreen ();
2239 nsz
:= TLaySize
.Create(trunc(fuiScrWdt
/fuiRenderScale
)-mFrameWidth
*2-6, trunc(fuiScrHgt
/fuiRenderScale
)-mFrameHeight
*2-6);
2240 if (mMaxSize
.w
< 1) then mMaxSize
.w
:= nsz
.w
;
2241 if (mMaxSize
.h
< 1) then mMaxSize
.h
:= nsz
.h
;
2245 procedure TUITopWindow
.centerInScreen ();
2247 if (mWidth
> 0) and (mHeight
> 0) then
2249 mX
:= trunc((fuiScrWdt
/fuiRenderScale
-mWidth
)/2);
2250 mY
:= trunc((fuiScrHgt
/fuiRenderScale
-mHeight
)/2);
2255 // ////////////////////////////////////////////////////////////////////////// //
2256 procedure TUITopWindow
.drawControl (gx
, gy
: Integer);
2258 uiContext
.color
:= mBackColor
[getColorIndex
];
2259 uiContext
.fillRect(gx
, gy
, mWidth
, mHeight
);
2262 procedure TUITopWindow
.drawControlPost (gx
, gy
: Integer);
2264 cidx
, iwdt
, ihgt
: Integer;
2265 ybot
, xend
, vhgt
, vwdt
: Integer;
2267 cidx
:= getColorIndex
;
2268 iwdt
:= uiContext
.iconWinWidth(TGxContext
.TWinIcon
.Close
);
2269 if (mDragScroll
= TXMode
.Drag
) then
2271 drawFrame(gx
, gy
, iwdt
, 0, mTitle
, false);
2275 ihgt
:= uiContext
.iconWinHeight(TGxContext
.TWinIcon
.Close
);
2276 drawFrame(gx
, gy
, iwdt
, 0, mTitle
, true);
2277 // vertical scroll bar
2278 vhgt
:= mHeight
-mFrameHeight
*2;
2279 if (mFullSize
.h
> vhgt
) then
2281 ybot
:= mScrollY
+vhgt
;
2283 uiContext
.drawVSBar(gx
+mWidth
-mFrameWidth
+1, gy
+mFrameHeight
-1, mFrameWidth
-3, vhgt
+2, ybot
, 0, mFullSize
.h
, mSBarFullColor
[cidx
], mSBarEmptyColor
[cidx
]);
2285 // horizontal scroll bar
2286 vwdt
:= mWidth
-mFrameWidth
*2;
2287 if (mFullSize
.w
> vwdt
) then
2289 xend
:= mScrollX
+vwdt
;
2291 uiContext
.drawHSBar(gx
+mFrameWidth
+1, gy
+mHeight
-mFrameHeight
+1, vwdt
-2, mFrameHeight
-3, xend
, 0, mFullSize
.w
, mSBarFullColor
[cidx
], mSBarEmptyColor
[cidx
]);
2294 setScissor(mFrameWidth
, 0, iwdt
, ihgt
);
2295 uiContext
.color
:= mBackColor
[cidx
];
2296 uiContext
.fillRect(gx
+mFrameWidth
, gy
, iwdt
, ihgt
);
2297 uiContext
.color
:= mFrameIconColor
[cidx
];
2298 uiContext
.drawIconWin(TGxContext
.TWinIcon
.Close
, gx
+mFrameWidth
, gy
, mInClose
);
2300 // shadow (no need to reset scissor, as draw should do it)
2301 inherited drawControlPost(gx
, gy
);
2305 // ////////////////////////////////////////////////////////////////////////// //
2306 procedure TUITopWindow
.activated ();
2308 if (mFocused
= nil) or (mFocused
= self
) then
2310 mFocused
:= findFirstFocus();
2312 if (mFocused
<> nil) and (mFocused
<> self
) then mFocused
.activated();
2317 procedure TUITopWindow
.blurred ();
2319 mDragScroll
:= TXMode
.None
;
2320 mWaitingClose
:= false;
2322 if (mFocused
<> nil) and (mFocused
<> self
) then mFocused
.blurred();
2327 procedure TUITopWindow
.keyEvent (var ev
: TFUIKeyEvent
);
2329 inherited keyEvent(ev
);
2330 if (not ev
.alive
) or (not enabled
) {or (not getFocused)} then exit
;
2331 if (ev
= 'M-F3') then
2333 if (not assigned(closeRequestCB
)) or (closeRequestCB(self
)) then
2335 uiRemoveWindow(self
);
2343 procedure TUITopWindow
.mouseEvent (var ev
: TFUIMouseEvent
);
2346 vhgt
, ytop
: Integer;
2347 vwdt
, xend
: Integer;
2349 if (not enabled
) then exit
;
2350 if (mWidth
< 1) or (mHeight
< 1) then exit
;
2352 if (mDragScroll
= TXMode
.Drag
) then
2354 mX
+= ev
.x
-mDragStartX
;
2355 mY
+= ev
.y
-mDragStartY
;
2356 mDragStartX
:= ev
.x
;
2357 mDragStartY
:= ev
.y
;
2358 if (ev
.release
) and (ev
.but
= ev
.Left
) then mDragScroll
:= TXMode
.None
;
2363 if (mDragScroll
= TXMode
.VScroll
) then
2366 vhgt
:= mHeight
-mFrameHeight
*2;
2367 ytop
:= uiContext
.sbarPos(ly
, mFrameHeight
-1, vhgt
+2, 0, mFullSize
.h
)-vhgt
;
2368 mScrollY
:= nmax(0, ytop
);
2369 if (ev
.release
) and (ev
.but
= ev
.Left
) then mDragScroll
:= TXMode
.None
;
2374 if (mDragScroll
= TXMode
.HScroll
) then
2377 vwdt
:= mWidth
-mFrameWidth
*2;
2378 xend
:= uiContext
.sbarPos(lx
, mFrameWidth
+1, vwdt
-2, 0, mFullSize
.w
)-vwdt
;
2379 mScrollX
:= nmax(0, xend
);
2380 if (ev
.release
) and (ev
.but
= ev
.Left
) then mDragScroll
:= TXMode
.None
;
2385 if toLocal(ev
.x
, ev
.y
, lx
, ly
) then
2389 if (ly
< mFrameHeight
) then
2392 if (lx
>= mFrameWidth
) and (lx
< mFrameWidth
+uiContext
.iconWinWidth(TGxContext
.TWinIcon
.Close
)) then
2394 //uiRemoveWindow(self);
2395 mWaitingClose
:= true;
2400 mDragScroll
:= TXMode
.Drag
;
2401 mDragStartX
:= ev
.x
;
2402 mDragStartY
:= ev
.y
;
2407 // check for vertical scrollbar
2408 if (lx
>= mWidth
-mFrameWidth
+1) and (ly
>= mFrameHeight
-1) and (ly
< mHeight
-mFrameHeight
+2) then
2410 vhgt
:= mHeight
-mFrameHeight
*2;
2411 if (mFullSize
.h
> vhgt
) then
2414 mDragScroll
:= TXMode
.VScroll
;
2416 ytop
:= uiContext
.sbarPos(ly
, mFrameHeight
-1, vhgt
+2, 0, mFullSize
.h
)-vhgt
;
2417 mScrollY
:= nmax(0, ytop
);
2421 // check for horizontal scrollbar
2422 if (ly
>= mHeight
-mFrameHeight
+1) and (lx
>= mFrameWidth
+1) and (lx
< mWidth
-mFrameWidth
-1) then
2424 vwdt
:= mWidth
-mFrameWidth
*2;
2425 if (mFullSize
.w
> vwdt
) then
2428 mDragScroll
:= TXMode
.HScroll
;
2430 xend
:= uiContext
.sbarPos(lx
, mFrameWidth
+1, vwdt
-2, 0, mFullSize
.w
)-vwdt
;
2431 mScrollX
:= nmax(0, xend
);
2436 if (lx
< mFrameWidth
) or (lx
>= mWidth
-mFrameWidth
) or (ly
>= mHeight
-mFrameHeight
) then
2439 mDragScroll
:= TXMode
.Drag
;
2440 mDragStartX
:= ev
.x
;
2441 mDragStartY
:= ev
.y
;
2447 if (ev
.release
) then
2449 if mWaitingClose
then
2451 if (lx
>= mFrameWidth
) and (lx
< mFrameWidth
+uiContext
.iconWinWidth(TGxContext
.TWinIcon
.Close
)) then
2453 if (not assigned(closeRequestCB
)) or (closeRequestCB(self
)) then
2455 uiRemoveWindow(self
);
2458 mWaitingClose
:= false;
2467 if mWaitingClose
then
2469 mInClose
:= (lx
>= mFrameWidth
) and (lx
< mFrameWidth
+uiContext
.iconWinWidth(TGxContext
.TWinIcon
.Close
));
2475 inherited mouseEvent(ev
);
2480 if (not ev
.motion
) and (mWaitingClose
) then begin ev
.eat(); mWaitingClose
:= false; exit
; end;
2485 // ////////////////////////////////////////////////////////////////////////// //
2486 constructor TUIBox
.Create (ahoriz
: Boolean);
2493 procedure TUIBox
.AfterConstruction ();
2497 mHAlign
:= -1; // left
2498 mCtl4Style
:= 'box';
2499 mDefSize
:= TLaySize
.Create(-1, -1);
2503 procedure TUIBox
.setCaption (const acap
: AnsiString);
2506 mDefSize
:= TLaySize
.Create(uiContext
.textWidth(mCaption
)+3, uiContext
.textHeight(mCaption
));
2510 procedure TUIBox
.setHasFrame (v
: Boolean);
2513 if (mHasFrame
) then begin mFrameWidth
:= 8; mFrameHeight
:= uiContext
.charHeight(#184); end else begin mFrameWidth
:= 0; mFrameHeight
:= 0; end;
2514 if (mHasFrame
) then mNoPad
:= true;
2518 function TUIBox
.parseProperty (const prname
: AnsiString; par
: TTextParser
): Boolean;
2520 if (parseOrientation(prname
, par
)) then begin result
:= true; exit
; end;
2521 if (strEquCI1251(prname
, 'padding')) then
2523 if (mHoriz
) then mPadding
:= parseHPadding(par
, 0) else mPadding
:= parseVPadding(par
, 0);
2527 if (strEquCI1251(prname
, 'frame')) then
2529 setHasFrame(parseBool(par
));
2533 if (strEquCI1251(prname
, 'title')) or (strEquCI1251(prname
, 'caption')) then
2535 setCaption(par
.expectIdOrStr(true));
2539 if (strEquCI1251(prname
, 'textalign')) or (strEquCI1251(prname
, 'text-align')) then
2541 mHAlign
:= parseHAlign(par
);
2545 if (strEquCI1251(prname
, 'children')) then
2551 result
:= inherited parseProperty(prname
, par
);
2555 procedure TUIBox
.drawControl (gx
, gy
: Integer);
2560 cidx
:= getColorIndex
;
2561 uiContext
.color
:= mBackColor
[cidx
];
2562 uiContext
.fillRect(gx
, gy
, mWidth
, mHeight
);
2566 drawFrame(gx
, gy
, 0, mHAlign
, mCaption
, false);
2568 // no frame -- no caption
2570 else if (Length(mCaption) > 0) then
2573 if (mHAlign < 0) then xpos := 3
2574 else if (mHAlign > 0) then xpos := mWidth-mFrameWidth*2-uiContext.textWidth(mCaption)
2575 else xpos := (mWidth-mFrameWidth*2-uiContext.textWidth(mCaption)) div 2;
2576 xpos += gx+mFrameWidth;
2578 setScissor(mFrameWidth+1, 0, mWidth-mFrameWidth-2, uiContext.textHeight(mCaption));
2579 uiContext.color := mFrameTextColor[cidx];
2580 uiContext.drawText(xpos, gy, mCaption);
2586 procedure TUIBox
.mouseEvent (var ev
: TFUIMouseEvent
);
2590 inherited mouseEvent(ev
);
2591 if (ev
.alive
) and (enabled
) and toLocal(ev
.x
, ev
.y
, lx
, ly
) then
2598 procedure TUIBox
.keyEvent (var ev
: TFUIKeyEvent
);
2601 cur
, ctl
: TUIControl
;
2603 inherited keyEvent(ev
);
2604 if (not ev
.alive
) or (not ev
.press
) or (not enabled
) or (not getActive
) then exit
;
2605 if (Length(mChildren
) = 0) then exit
;
2606 if (mHoriz
) and (ev
= 'Left') then dir
:= -1
2607 else if (mHoriz
) and (ev
= 'Right') then dir
:= 1
2608 else if (not mHoriz
) and (ev
= 'Up') then dir
:= -1
2609 else if (not mHoriz
) and (ev
= 'Down') then dir
:= 1;
2610 if (dir
= 0) then exit
;
2612 cur
:= topLevel
.mFocused
;
2613 while (cur
<> nil) and (cur
.mParent
<> self
) do cur
:= cur
.mParent
;
2614 //if (cur = nil) then writeln('CUR: nil') else writeln('CUR: ', cur.className, '#', cur.id);
2615 if (dir
< 0) then ctl
:= findPrevFocus(cur
, true) else ctl
:= findNextFocus(cur
, true);
2616 //if (ctl = nil) then writeln('CTL: nil') else writeln('CTL: ', ctl.className, '#', ctl.id);
2617 if (ctl
<> nil) and (ctl
<> self
) then
2619 ctl
.focused
:= true;
2624 // ////////////////////////////////////////////////////////////////////////// //
2625 constructor TUIHBox
.Create ();
2630 procedure TUIHBox
.AfterConstruction ();
2637 // ////////////////////////////////////////////////////////////////////////// //
2638 constructor TUIVBox
.Create ();
2643 procedure TUIVBox
.AfterConstruction ();
2650 // ////////////////////////////////////////////////////////////////////////// //
2651 procedure TUISpan
.AfterConstruction ();
2657 mCtl4Style
:= 'span';
2658 mDefSize
:= TLaySize
.Create(-1, -1);
2662 function TUISpan
.parseProperty (const prname
: AnsiString; par
: TTextParser
): Boolean;
2664 if (parseOrientation(prname
, par
)) then begin result
:= true; exit
; end;
2665 result
:= inherited parseProperty(prname
, par
);
2669 // ////////////////////////////////////////////////////////////////////// //
2670 procedure TUILine
.AfterConstruction ();
2676 mCtl4Style
:= 'line';
2677 mDefSize
:= TLaySize
.Create(-1, -1);
2681 function TUILine
.parseProperty (const prname
: AnsiString; par
: TTextParser
): Boolean;
2683 if (parseOrientation(prname
, par
)) then begin result
:= true; exit
; end;
2684 result
:= inherited parseProperty(prname
, par
);
2688 procedure TUILine
.layPrepare ();
2690 inherited layPrepare();
2691 if (mParent
<> nil) then mHoriz
:= not mParent
.mHoriz
;
2694 if (mLayDefSize
.w
< 0) then mLayDefSize
.w
:= 1;
2695 if (mLayDefSize
.h
< 0) then mLayDefSize
.h
:= 7;
2699 if (mLayDefSize
.w
< 0) then mLayDefSize
.w
:= 7;
2700 if (mLayDefSize
.h
< 0) then mLayDefSize
.h
:= 1;
2705 procedure TUILine
.drawControl (gx
, gy
: Integer);
2709 cidx
:= getColorIndex
;
2710 uiContext
.color
:= mTextColor
[cidx
];
2711 if mHoriz
then uiContext
.hline(gx
, gy
+(mHeight
div 2), mWidth
)
2712 else uiContext
.vline(gx
+(mWidth
div 2), gy
, mHeight
);
2716 // ////////////////////////////////////////////////////////////////////////// //
2717 procedure TUIStaticText
.AfterConstruction ();
2723 mHoriz
:= true; // nobody cares
2726 mCtl4Style
:= 'static';
2730 procedure TUIStaticText
.setText (const atext
: AnsiString);
2733 mDefSize
:= TLaySize
.Create(uiContext
.textWidth(mText
), uiContext
.textHeight(mText
));
2737 function TUIStaticText
.parseProperty (const prname
: AnsiString; par
: TTextParser
): Boolean;
2739 if (strEquCI1251(prname
, 'title')) or (strEquCI1251(prname
, 'caption')) or (strEquCI1251(prname
, 'text')) then
2741 setText(par
.expectIdOrStr(true));
2745 if (strEquCI1251(prname
, 'textalign')) or (strEquCI1251(prname
, 'text-align')) then
2747 parseTextAlign(par
, mHAlign
, mVAlign
);
2751 if (strEquCI1251(prname
, 'header')) then
2757 if (strEquCI1251(prname
, 'line')) then
2763 result
:= inherited parseProperty(prname
, par
);
2767 procedure TUIStaticText
.drawControl (gx
, gy
: Integer);
2769 xpos
, ypos
: Integer;
2772 cidx
:= getColorIndex
;
2773 uiContext
.color
:= mBackColor
[cidx
];
2774 uiContext
.fillRect(gx
, gy
, mWidth
, mHeight
);
2776 if (mHAlign
< 0) then xpos
:= 0
2777 else if (mHAlign
> 0) then xpos
:= mWidth
-uiContext
.textWidth(mText
)
2778 else xpos
:= (mWidth
-uiContext
.textWidth(mText
)) div 2;
2780 if (Length(mText
) > 0) then
2782 if (mHeader
) then uiContext
.color
:= mFrameTextColor
[cidx
] else uiContext
.color
:= mTextColor
[cidx
];
2784 if (mVAlign
< 0) then ypos
:= 0
2785 else if (mVAlign
> 0) then ypos
:= mHeight
-uiContext
.textHeight(mText
)
2786 else ypos
:= (mHeight
-uiContext
.textHeight(mText
)) div 2;
2788 uiContext
.drawText(gx
+xpos
, gy
+ypos
, mText
);
2793 if (mHeader
) then uiContext
.color
:= mFrameColor
[cidx
] else uiContext
.color
:= mTextColor
[cidx
];
2795 if (mVAlign
< 0) then ypos
:= 0
2796 else if (mVAlign
> 0) then ypos
:= mHeight
-1
2797 else ypos
:= (mHeight
div 2);
2800 if (Length(mText
) = 0) then
2802 uiContext
.hline(gx
, ypos
, mWidth
);
2806 uiContext
.hline(gx
, ypos
, xpos
-1);
2807 uiContext
.hline(gx
+xpos
+uiContext
.textWidth(mText
), ypos
, mWidth
);
2813 // ////////////////////////////////////////////////////////////////////////// //
2814 procedure TUITextLabel
.AfterConstruction ();
2820 mCtl4Style
:= 'label';
2825 procedure TUITextLabel
.cacheStyle (root
: TUIStyle
);
2827 inherited cacheStyle(root
);
2829 mHotColor
[ClrIdxActive
] := root
.get('hot-color', 'active', mCtl4Style
).asRGBADef(TGxRGBA
.Create(0, 128, 0));
2831 mHotColor
[ClrIdxDisabled
] := root
.get('hot-color', 'disabled', mCtl4Style
).asRGBADef(TGxRGBA
.Create(0, 64, 0));
2833 mHotColor
[ClrIdxInactive
] := root
.get('hot-color', 'inactive', mCtl4Style
).asRGBADef(TGxRGBA
.Create(0, 64, 0));
2837 procedure TUITextLabel
.setText (const s
: AnsiString);
2845 while (f
<= Length(s
)) do
2847 if (s
[f
] = '\\') then
2850 if (f
<= Length(s
)) then mText
+= s
[f
];
2853 else if (s
[f
] = '~') then
2856 if (f
<= Length(s
)) then
2858 if (mHotChar
= #0) then
2861 mHotOfs
:= Length(mText
);
2873 // fix hotchar offset
2874 if (mHotChar
<> #0) and (mHotOfs
> 0) then
2876 mHotOfs
:= uiContext
.textWidth(Copy(mText
, 1, mHotOfs
+1))-uiContext
.charWidth(mText
[mHotOfs
+1]);
2879 mDefSize
:= TLaySize
.Create(uiContext
.textWidth(mText
), uiContext
.textHeight(mText
));
2883 function TUITextLabel
.parseProperty (const prname
: AnsiString; par
: TTextParser
): Boolean;
2885 if (strEquCI1251(prname
, 'title')) or (strEquCI1251(prname
, 'caption')) or (strEquCI1251(prname
, 'text')) then
2887 setText(par
.expectIdOrStr(true));
2891 if (strEquCI1251(prname
, 'link')) then
2893 mLinkId
:= par
.expectIdOrStr(true);
2897 if (strEquCI1251(prname
, 'textalign')) or (strEquCI1251(prname
, 'text-align')) then
2899 parseTextAlign(par
, mHAlign
, mVAlign
);
2903 result
:= inherited parseProperty(prname
, par
);
2907 procedure TUITextLabel
.drawControl (gx
, gy
: Integer);
2909 xpos
, ypos
: Integer;
2912 cidx
:= getColorIndex
;
2913 uiContext
.color
:= mBackColor
[cidx
];
2914 uiContext
.fillRect(gx
, gy
, mWidth
, mHeight
);
2915 if (Length(mText
) > 0) then
2917 if (mHAlign
< 0) then xpos
:= 0
2918 else if (mHAlign
> 0) then xpos
:= mWidth
-uiContext
.textWidth(mText
)
2919 else xpos
:= (mWidth
-uiContext
.textWidth(mText
)) div 2;
2921 if (mVAlign
< 0) then ypos
:= 0
2922 else if (mVAlign
> 0) then ypos
:= mHeight
-uiContext
.textHeight(mText
)
2923 else ypos
:= (mHeight
-uiContext
.textHeight(mText
)) div 2;
2925 uiContext
.color
:= mTextColor
[cidx
];
2926 uiContext
.drawText(gx
+xpos
, gy
+ypos
, mText
);
2928 if (Length(mLinkId
) > 0) and (mHotChar
<> #0) and (mHotChar
<> ' ') then
2930 uiContext
.color
:= mHotColor
[cidx
];
2931 uiContext
.drawChar(gx
+xpos
+mHotOfs
, gy
+ypos
, mHotChar
);
2937 procedure TUITextLabel
.mouseEvent (var ev
: TFUIMouseEvent
);
2941 inherited mouseEvent(ev
);
2942 if (ev
.alive
) and (enabled
) and toLocal(ev
.x
, ev
.y
, lx
, ly
) then
2949 procedure TUITextLabel
.doAction ();
2953 if (assigned(actionCB
)) then
2959 ctl
:= topLevel
[mLinkId
];
2960 if (ctl
<> nil) then
2962 if (ctl
.canFocus
) then ctl
.focused
:= true;
2968 procedure TUITextLabel
.keyEventPost (var ev
: TFUIKeyEvent
);
2970 if (not enabled
) then exit
;
2971 if (mHotChar
= #0) then exit
;
2972 if (not ev
.alive
) or (not ev
.press
) then exit
;
2973 if (ev
.kstate
<> ev
.ModAlt
) then exit
;
2974 if (not ev
.isHot(mHotChar
)) then exit
;
2976 if (canFocus
) then focused
:= true;
2981 // ////////////////////////////////////////////////////////////////////////// //
2982 procedure TUIButton
.AfterConstruction ();
2989 mDefSize
:= TLaySize
.Create(uiContext
.textWidth(mText
)+uiContext
.textWidth('[ ]'), uiContext
.textHeight(mText
));
2990 mCtl4Style
:= 'button';
2991 mSkipLayPrepare
:= false;
2992 mAddMarkers
:= false;
2993 mHideMarkers
:= false;
2997 procedure TUIButton
.cacheStyle (root
: TUIStyle
);
3001 inherited cacheStyle(root
);
3003 sz
:= nmax(0, root
.get('shadow-size', 'active', mCtl4Style
).asInt(0));
3004 sz
:= nmax(sz
, root
.get('shadow-size', 'disabled', mCtl4Style
).asInt(0));
3005 sz
:= nmax(sz
, root
.get('shadow-size', 'inactive', mCtl4Style
).asInt(0));
3008 mAddMarkers
:= root
.get('add-markers', 'active', mCtl4Style
).asBool(false);
3009 mAddMarkers
:= mAddMarkers
or root
.get('add-markers', 'disabled', mCtl4Style
).asBool(false);
3010 mAddMarkers
:= mAddMarkers
or root
.get('add-markers', 'inactive', mCtl4Style
).asBool(false);
3012 mHideMarkers
:= root
.get('hide-markers', 'active', mCtl4Style
).asBool(false);
3013 mHideMarkers
:= mHideMarkers
or root
.get('hide-markers', 'disabled', mCtl4Style
).asBool(false);
3014 mHideMarkers
:= mHideMarkers
or root
.get('hide-markers', 'inactive', mCtl4Style
).asBool(false);
3018 procedure TUIButton
.setText (const s
: AnsiString);
3020 inherited setText(s
);
3021 if (mHideMarkers
) then
3023 mDefSize
:= TLaySize
.Create(uiContext
.textWidth(mText
)+10, uiContext
.textHeight(mText
));
3025 else if (mAddMarkers
) then
3027 mDefSize
:= TLaySize
.Create(uiContext
.textWidth(mText
)+uiContext
.textWidth('[<>]'), uiContext
.textHeight(mText
));
3031 mDefSize
:= TLaySize
.Create(uiContext
.textWidth(mText
)+uiContext
.textWidth('<>'), uiContext
.textHeight(mText
));
3036 procedure TUIButton
.layPrepare ();
3041 if (not mSkipLayPrepare
) then
3044 if (ods
.w
<> 0) or (ods
.h
<> 0) then
3046 mDefSize
:= TLaySize
.Create(uiContext
.textWidth(mText
), uiContext
.textHeight(mText
));
3047 if (mHideMarkers
) then
3051 else if (mAddMarkers
) then
3053 if (mDefault
) then ww
:= uiContext
.textWidth('[< >]')
3054 else if (mCancel
) then ww
:= uiContext
.textWidth('[{ }]')
3055 else ww
:= uiContext
.textWidth('[ ]');
3059 ww
:= nmax(0, uiContext
.textWidth('< >'));
3060 ww
:= nmax(ww
, uiContext
.textWidth('{ }'));
3061 ww
:= nmax(ww
, uiContext
.textWidth('[ ]'));
3063 mDefSize
.w
+= ww
+mShadowSize
;
3064 mDefSize
.h
+= mShadowSize
;
3069 ods
:= TLaySize
.Create(0, 0); // fpc is dumb!
3071 inherited layPrepare();
3072 if (not mSkipLayPrepare
) then mDefSize
:= ods
;
3076 procedure TUIButton
.blurred ();
3082 procedure TUIButton
.drawControl (gx
, gy
: Integer);
3085 xpos
, ypos
, xofsl
, xofsr
, sofs
: Integer;
3088 lstr
, rstr
: AnsiString;
3090 cidx
:= getColorIndex
;
3092 wdt
:= mWidth
-mShadowSize
;
3093 hgt
:= mHeight
-mShadowSize
;
3094 if (mPushed
) {or (cidx = ClrIdxActive)} then
3096 sofs
:= mShadowSize
;
3103 if (mShadowSize
> 0) then
3105 uiContext
.darkenRect(gx
+mShadowSize
, gy
+hgt
, wdt
, mShadowSize
, 96);
3106 uiContext
.darkenRect(gx
+wdt
, gy
+mShadowSize
, mShadowSize
, hgt
-mShadowSize
, 96);
3110 uiContext
.color
:= mBackColor
[cidx
];
3111 uiContext
.fillRect(gx
, gy
, wdt
, hgt
);
3113 if (mVAlign
< 0) then ypos
:= 0
3114 else if (mVAlign
> 0) then ypos
:= hgt
-uiContext
.textHeight(mText
)
3115 else ypos
:= (hgt
-uiContext
.textHeight(mText
)) div 2;
3118 uiContext
.color
:= mTextColor
[cidx
];
3120 if (mHideMarkers
) then
3127 if (mAddMarkers
) then
3129 if (mDefault
) then begin lstr
:= '[< '; rstr
:= ' >]'; end
3130 else if (mCancel
) then begin lstr
:= '[{ '; rstr
:= ' }]'; end
3131 else begin lstr
:= '[ '; rstr
:= ' ]'; end;
3132 xofsl
:= uiContext
.textWidth(lstr
);
3133 xofsr
:= uiContext
.textWidth(rstr
);
3134 uiContext
.drawText(gx
, ypos
, lstr
);
3135 uiContext
.drawText(gx
+wdt
-uiContext
.textWidth(rstr
), ypos
, rstr
);
3139 xofsl
:= nmax(0, uiContext
.textWidth('< '));
3140 xofsl
:= nmax(xofsl
, uiContext
.textWidth('{ '));
3141 xofsl
:= nmax(xofsl
, uiContext
.textWidth('[ '));
3142 xofsr
:= nmax(0, uiContext
.textWidth(' >'));
3143 xofsr
:= nmax(xofsr
, uiContext
.textWidth(' }'));
3144 xofsr
:= nmax(xofsr
, uiContext
.textWidth(' ]'));
3145 if (mDefault
) then begin lch
:= '<'; rch
:= '>'; end
3146 else if (mCancel
) then begin lch
:= '{'; rch
:= '}'; end
3147 else begin lch
:= '['; rch
:= ']'; end;
3148 uiContext
.drawChar(gx
, ypos
, lch
);
3149 uiContext
.drawChar(gx
+wdt
-uiContext
.charWidth(rch
), ypos
, rch
);
3153 if (Length(mText
) > 0) then
3155 if (mHAlign
< 0) then xpos
:= 0
3156 else begin xpos
:= wdt
-xofsl
-xofsr
-uiContext
.textWidth(mText
); if (mHAlign
= 0) then xpos
:= xpos
div 2; end;
3159 setScissor(sofs
+xofsl
, sofs
, wdt
-xofsl
-xofsr
, hgt
);
3160 uiContext
.drawText(gx
+xpos
, ypos
, mText
);
3162 if (mHotChar
<> #0) and (mHotChar
<> ' ') then
3164 uiContext
.color
:= mHotColor
[cidx
];
3165 uiContext
.drawChar(gx
+xpos
+mHotOfs
, ypos
, mHotChar
);
3171 procedure TUIButton
.mouseEvent (var ev
: TFUIMouseEvent
);
3175 inherited mouseEvent(ev
);
3176 if (uiGrabCtl
= self
) then
3179 mPushed
:= toLocal(ev
.x
, ev
.y
, lx
, ly
);
3180 if (ev
= '-lmb') and focused
and mPushed
then
3187 if (not ev
.alive
) or (not enabled
) or (not focused
) then exit
;
3193 procedure TUIButton
.keyEvent (var ev
: TFUIKeyEvent
);
3195 inherited keyEvent(ev
);
3196 if (ev
.alive
) and (enabled
) then
3198 if (ev
= '+Enter') or (ev
= '+Space') then
3205 if (focused
) and ((ev
= '-Enter') or (ev
= '-Space')) then
3223 // ////////////////////////////////////////////////////////////////////////// //
3224 procedure TUIButtonRound
.AfterConstruction ();
3230 mDefSize
:= TLaySize
.Create(uiContext
.textWidth(mText
)+8*2, uiContext
.textHeight(mText
)+2);
3231 mCtl4Style
:= 'button-round';
3232 mSkipLayPrepare
:= true;
3236 procedure TUIButtonRound
.setText (const s
: AnsiString);
3238 inherited setText(s
);
3239 mDefSize
:= TLaySize
.Create(uiContext
.textWidth(mText
)+8*2, uiContext
.textHeight(mText
)+2);
3243 procedure TUIButtonRound
.layPrepare ();
3248 if (ods
.w
<> 0) or (ods
.h
<> 0) then
3250 mDefSize
:= TLaySize
.Create(uiContext
.textWidth(mText
)+8*2, uiContext
.textHeight(mText
)+2);
3252 inherited layPrepare();
3257 procedure TUIButtonRound
.drawControl (gx
, gy
: Integer);
3259 xpos
, ypos
: Integer;
3262 cidx
:= getColorIndex
;
3264 uiContext
.color
:= mBackColor
[cidx
];
3265 uiContext
.fillRect(gx
+1, gy
, mWidth
-2, mHeight
);
3266 uiContext
.fillRect(gx
, gy
+1, 1, mHeight
-2);
3267 uiContext
.fillRect(gx
+mWidth
-1, gy
+1, 1, mHeight
-2);
3269 if (Length(mText
) > 0) then
3271 if (mHAlign
< 0) then xpos
:= 0
3272 else if (mHAlign
> 0) then xpos
:= mWidth
-uiContext
.textWidth(mText
)
3273 else xpos
:= (mWidth
-uiContext
.textWidth(mText
)) div 2;
3275 if (mVAlign
< 0) then ypos
:= 0
3276 else if (mVAlign
> 0) then ypos
:= mHeight
-uiContext
.textHeight(mText
)
3277 else ypos
:= (mHeight
-uiContext
.textHeight(mText
)) div 2;
3279 setScissor(8, 0, mWidth
-16, mHeight
);
3280 uiContext
.color
:= mTextColor
[cidx
];
3281 uiContext
.drawText(gx
+xpos
+8, gy
+ypos
, mText
);
3283 if (mHotChar
<> #0) and (mHotChar
<> ' ') then
3285 uiContext
.color
:= mHotColor
[cidx
];
3286 uiContext
.drawChar(gx
+xpos
+8+mHotOfs
, gy
+ypos
, mHotChar
);
3292 // ////////////////////////////////////////////////////////////////////////// //
3293 procedure TUISwitchBox
.AfterConstruction ();
3299 mIcon
:= TGxContext
.TMarkIcon
.Checkbox
;
3300 mDefSize
:= TLaySize
.Create(uiContext
.textWidth(mText
)+3+uiContext
.iconMarkWidth(mIcon
), nmax(uiContext
.iconMarkHeight(mIcon
), uiContext
.textHeight(mText
)));
3301 mCtl4Style
:= 'switchbox';
3303 mBoolVar
:= @mChecked
;
3307 procedure TUISwitchBox
.cacheStyle (root
: TUIStyle
);
3309 inherited cacheStyle(root
);
3311 mSwitchColor
[ClrIdxActive
] := root
.get('switch-color', 'active', mCtl4Style
).asRGBADef(TGxRGBA
.Create(255, 255, 255));
3313 mSwitchColor
[ClrIdxDisabled
] := root
.get('switch-color', 'disabled', mCtl4Style
).asRGBADef(TGxRGBA
.Create(255, 255, 255));
3315 mSwitchColor
[ClrIdxInactive
] := root
.get('switch-color', 'inactive', mCtl4Style
).asRGBADef(TGxRGBA
.Create(255, 255, 255));
3319 procedure TUISwitchBox
.setText (const s
: AnsiString);
3321 inherited setText(s
);
3322 mDefSize
:= TLaySize
.Create(uiContext
.textWidth(mText
)+3+uiContext
.iconMarkWidth(mIcon
), nmax(uiContext
.iconMarkHeight(mIcon
), uiContext
.textHeight(mText
)));
3326 function TUISwitchBox
.parseProperty (const prname
: AnsiString; par
: TTextParser
): Boolean;
3328 if (strEquCI1251(prname
, 'checked')) then
3334 result
:= inherited parseProperty(prname
, par
);
3338 function TUISwitchBox
.getChecked (): Boolean;
3340 if (mBoolVar
<> nil) then result
:= mBoolVar
^ else result
:= false;
3344 procedure TUISwitchBox
.setVar (pvar
: PBoolean);
3346 if (pvar
= nil) then pvar
:= @mChecked
;
3347 if (pvar
<> mBoolVar
) then
3350 setChecked(mBoolVar
^);
3355 procedure TUISwitchBox
.drawControl (gx
, gy
: Integer);
3357 xpos
, ypos
, iwdt
, dy
: Integer;
3360 cidx
:= getColorIndex
;
3362 iwdt
:= uiContext
.iconMarkWidth(mIcon
);
3363 if (mHAlign
< 0) then xpos
:= 0
3364 else if (mHAlign
> 0) then xpos
:= mWidth
-(uiContext
.textWidth(mText
)+3+iwdt
)
3365 else xpos
:= (mWidth
-(uiContext
.textWidth(mText
)+3+iwdt
)) div 2;
3367 if (mVAlign
< 0) then ypos
:= 0
3368 else if (mVAlign
> 0) then ypos
:= mHeight
-uiContext
.textHeight(mText
)
3369 else ypos
:= (mHeight
-uiContext
.textHeight(mText
)) div 2;
3371 uiContext
.color
:= mBackColor
[cidx
];
3372 uiContext
.fillRect(gx
, gy
, mWidth
, mHeight
);
3374 uiContext
.color
:= mSwitchColor
[cidx
];
3375 if (uiContext
.iconMarkHeight(mIcon
) < uiContext
.textHeight(mText
)) then
3377 case uiContext
.textHeight(mText
) of
3382 uiContext
.drawIconMark(mIcon
, gx
, gy
+ypos
+uiContext
.textHeight(mText
)-uiContext
.iconMarkHeight(mIcon
)-dy
, checked
);
3386 uiContext
.drawIconMark(mIcon
, gx
, gy
, checked
);
3389 uiContext
.color
:= mTextColor
[cidx
];
3390 uiContext
.drawText(gx
+xpos
+3+iwdt
, gy
+ypos
, mText
);
3392 if (mHotChar
<> #0) and (mHotChar
<> ' ') then
3394 uiContext
.color
:= mHotColor
[cidx
];
3395 uiContext
.drawChar(gx
+xpos
+3+iwdt
+mHotOfs
, gy
+ypos
, mHotChar
);
3400 procedure TUISwitchBox
.mouseEvent (var ev
: TFUIMouseEvent
);
3404 inherited mouseEvent(ev
);
3405 if (uiGrabCtl
= self
) then
3408 if (ev
= '-lmb') and focused
and toLocal(ev
.x
, ev
.y
, lx
, ly
) then
3414 if (not ev
.alive
) or (not enabled
) or not focused
then exit
;
3419 procedure TUISwitchBox
.keyEvent (var ev
: TFUIKeyEvent
);
3421 inherited keyEvent(ev
);
3422 if (ev
.alive
) and (enabled
) then
3424 if (ev
= 'Space') then
3434 // ////////////////////////////////////////////////////////////////////////// //
3435 procedure TUICheckBox
.AfterConstruction ();
3439 mBoolVar
:= @mChecked
;
3440 mIcon
:= TGxContext
.TMarkIcon
.Checkbox
;
3445 procedure TUICheckBox
.setChecked (v
: Boolean);
3451 procedure TUICheckBox
.doAction ();
3453 if (assigned(actionCB
)) then
3459 setChecked(not getChecked
);
3464 // ////////////////////////////////////////////////////////////////////////// //
3465 procedure TUIRadioBox
.AfterConstruction ();
3469 mBoolVar
:= @mChecked
;
3471 mIcon
:= TGxContext
.TMarkIcon
.Radiobox
;
3476 function TUIRadioBox
.parseProperty (const prname
: AnsiString; par
: TTextParser
): Boolean;
3478 if (strEquCI1251(prname
, 'group')) then
3480 mRadioGroup
:= par
.expectIdOrStr(true);
3481 if (getChecked
) then setChecked(true);
3485 if (strEquCI1251(prname
, 'checked')) then
3491 result
:= inherited parseProperty(prname
, par
);
3495 procedure TUIRadioBox
.setChecked (v
: Boolean);
3497 function resetGroup (ctl
: TUIControl
): Boolean;
3500 if (ctl
<> self
) and (ctl
is TUIRadioBox
) and (TUIRadioBox(ctl
).mRadioGroup
= mRadioGroup
) then
3502 TUIRadioBox(ctl
).mBoolVar
^ := false;
3508 if v
then topLevel
.forEachControl(resetGroup
);
3512 procedure TUIRadioBox
.doAction ();
3514 if (assigned(actionCB
)) then
3525 // ////////////////////////////////////////////////////////////////////////// //
3527 oldFocus
: procedure () = nil;
3528 oldBlur
: procedure () = nil;
3530 procedure onWinFocus (); begin uiFocus(); if (assigned(oldFocus
)) then oldFocus(); end;
3531 procedure onWinBlur (); begin fuiResetKMState(true); uiBlur(); if (assigned(oldBlur
)) then oldBlur(); end;
3534 registerCtlClass(TUIHBox
, 'hbox');
3535 registerCtlClass(TUIVBox
, 'vbox');
3536 registerCtlClass(TUISpan
, 'span');
3537 registerCtlClass(TUILine
, 'line');
3538 registerCtlClass(TUITextLabel
, 'label');
3539 registerCtlClass(TUIStaticText
, 'static');
3540 registerCtlClass(TUIButtonRound
, 'round-button');
3541 registerCtlClass(TUIButton
, 'button');
3542 registerCtlClass(TUICheckBox
, 'checkbox');
3543 registerCtlClass(TUIRadioBox
, 'radiobox');
3545 oldFocus
:= winFocusCB
;
3546 oldBlur
:= winBlurCB
;
3547 winFocusCB
:= onWinFocus
;
3548 winBlurCB
:= onWinBlur
;