2 {* TKOLMHUpDown object}
3 // MHUpDown Êîìïîíåíò (MHUpDown Component)
4 // Àâòîð (Author): Æàðîâ Äìèòðèé (Zharov Dmitry) aka Ãýíäàëüô (Gandalf)
5 // Äàòà ñîçäàíèÿ (Create date): 26-àïð(apr)-2002
6 // Äàòà êîððåêöèè (Last correction Date): 5-àâã(aug)-2003
7 // Âåðñèÿ (Version): 1.31
8 // EMail: Gandalf@kol.mastak.ru
9 // WWW: http://kol.mastak.ru
10 // Áëàãîäàðíîñòè (Thanks):
17 // [!] Èñïðàâëåíî "îòúåäàíèå" Buddy (Buddy "eating" FIX) <Great Thanks to dominiko-m> [MCK]
20 // [*] Ïîääåðæêà KOLWrapper âèçóàëèçàöèè (KOLWrapper visualition support) [MCK]
23 // [!] Ñîâìåñòèìîñòü ñ Õèíòàìè (ToolTips compatability) [KOL]
26 // [!] Ïîääåðæêà D7 (D7 Support) [KOLnMCK]
29 // [!] Èñïðàâëåíà îøèáêà BuddySize (Fix BuddySize) [MCK]
32 // [!] Èñïðàâëåíèÿ Buddy (Fixed Buddy) <Great Thanks to Alexander Pravdin> [MCK]
33 // [!] Èñïðàâëåíà îøèáêà Increment=0 (Increment=0 bug fixed) <Great Thanks to Alexander Pravdin> [MCK]
34 // [-] Íàéäåíà îøèáêà BuddySize (Bug BuddySize found) [MCK]
37 // [+~] Ñîáûòèå OnChangingEx (OnChangingEx event) <Thanks to Bogus³aw Brandys> [KOLnMCK]
38 // [+~] Ñâîéñòâî Increment (Increment property) <Thanks to Bogus³aw Brandys> [KOLnMCK]
39 // [*] Òåïåðü ïîääåðæèâàþòñÿ 32áèò çíà÷åíèÿ Position (32bit position support now) [KOLnMCK]
42 // [+] Ïîääåðæêà D6 (D6 Support) <Thanks to Alexander Pravdin> [KOLnMCK]
43 // [+++] Î÷åíü ìíîãî (Very much) [KOLnMCK]
47 // +Optimize Visible (may usefull for all KOL)
54 // +Add Thousands Better
57 // -Some Bug Buddy (Buddy Object Become smaller, and YourSelf can't be Buddy)
59 // +Add Updata Paint (for KOLnMCK 1.30)
81 // +Add Default Values
86 // +Add so-so Paint (MCK)
87 // +Add Min/Max/Position/Wrap/Orientation/Thousands
91 // Ñïèñîê äåë (To-Do list):
93 // 2. Îïòèìèçèðîâàòü (Optimize)
95 // 4. Ñîáûòèÿ (Events)
100 KOL
, Windows
, Messages
{, KOLMHToolTip};
103 REFRESH_PERIOD
: Cardinal = 1;
104 {* Amount of elapsed time, in seconds, before the position
105 change increment is used.}
108 TUpDownAlignButton
= (udLeft
, udRight
);
110 TUpDownOrientation
= (udHorizontal
, udVertical
);
112 TUpDownDirection
= (updNone
, updUp
, updDown
);
114 TOnChangingEx
= procedure(Sender
: PObj
; var Allow
: Boolean; NewValue
:
115 SmallInt
; Direction
: TUpDownDirection
) of object;
119 NM_UPDOWN
= packed record
124 TNMUpDown
= NM_UPDOWN
;
125 PNMUpDown
= ^TNMUpDown
;
128 UDACCEL
= packed record
133 PUDAccel
= ^TUDAccel
;
135 PMHUpDown
= ^TMHUpDown
;
136 TKOLMHUpDown
= PMHUpDown
;
137 TMHUpDown
= object(TControl
)
140 function GetHexBase
: Boolean;
141 procedure SetHexBase(const Value
: Boolean);
143 function GetBuddy
: HWnd
;
144 procedure SetBuddy(const Value
: HWnd
);
146 procedure SetMin(const Value
: Integer);
147 function GetMin
: Integer;
149 procedure SetMax(const Value
: Integer);
150 function GetMax
: Integer;
152 procedure SetPosition(const Value
: Integer);
153 function GetPosition
: Integer;
155 procedure SetIncrement(const Value
: Integer);
156 function GetIncrement
: Integer;
158 procedure SetOnChangingEx(const Value
: TOnChangingEx
);
159 function GetOnChangingEx
: TOnChangingEx
;
161 function GetOrientation
: TUpDownOrientation
;
163 function GetArrowKeys
: Boolean;
165 function GetAlignButton
: TUpDownAlignButton
;
167 function GetAutoBuddy
: Boolean;
169 function GetThousands
: Boolean;
171 function GetWrap
: Boolean;
173 function GetHotTrack
: Boolean;
176 property Min
: Integer read GetMin write SetMin
;
177 {* Specifies the minimum value of the Position property.}
178 property Max
: Integer read GetMax write SetMax
;
179 {* Specifies the maximum value of the Position property.}
180 property Position
: Integer read GetPosition write SetPosition
;
181 {* Current updown value}
182 property Increment
: Integer read GetIncrement write SetIncrement
;
183 {* Specifies the amount the Position value changes each time the up or down button is pressed.}
184 property Buddy
: HWnd read GetBuddy write SetBuddy
;
185 {* Companion control for updown}
186 property Orientation
: TUpDownOrientation read GetOrientation
;
187 {* Orientation of updown arrows}
188 property ArrowKeys
: Boolean read GetArrowKeys
;
189 {* The updown control receives input from the Up arrow and Down arrow keys.}
190 property AlignButton
: TUpDownAlignButton read GetAlignButton
;
191 {* The position of the up-down control can be relative to its companion (buddy) control.
192 Updown button can be placed on right or left side of buddy control}
193 property AutoBuddy
: Boolean read GetAutoBuddy
;
194 {* Automatically arrange to last control in Z-Order}
195 property Thousands
: Boolean read GetThousands
;
196 {* Determines whether a thousands separator appears between every three digits of a decimal string.}
197 property Wrap
: Boolean read GetWrap
;
198 {* Use Wrap to specify whether the up-down control treats the range determined
199 by the Max and Min properties as a continuous loop.}
200 property HexBase
: Boolean read GetHexBase write SetHexBase
;
201 {* Hexadecimal units}
202 property HotTrack
: Boolean read GetHotTrack
;
204 property OnChangingEx
: TOnChangingEx read GetOnChangingEx write
206 {* Event fired when position is about to change.Could be used to disallow change
207 of Position property.}
211 UPDOWN_CLASS
= 'msctls_updown32';
216 UD_MINVAL
= -UD_MAXVAL
;
219 UDS_SETBUDDYINT
= $0002;
220 UDS_ALIGNRIGHT
= $0004;
221 UDS_ALIGNLEFT
= $0008;
222 UDS_AUTOBUDDY
= $0010;
223 UDS_ARROWKEYS
= $0020;
225 UDS_NOTHOUSANDS
= $0080;
226 UDS_HOTTRACK
= $0100;
228 UDM_SETRANGE
= WM_USER
+ 101;
229 UDM_GETRANGE
= WM_USER
+ 102;
230 UDM_SETPOS
= WM_USER
+ 103;
231 UDM_GETPOS
= WM_USER
+ 104;
232 UDM_SETBUDDY
= WM_USER
+ 105;
233 UDM_GETBUDDY
= WM_USER
+ 106;
234 UDM_SETACCEL
= WM_USER
+ 107;
235 UDM_GETACCEL
= WM_USER
+ 108;
236 UDM_SETBASE
= WM_USER
+ 109;
237 UDM_GETBASE
= WM_USER
+ 110;
238 UDM_SETRANGE32
= WM_USER
+ 111;
239 UDM_GETRANGE32
= WM_USER
+ 112;
240 UDM_SETPOS32
= WM_USER
+ 113;
241 UDM_GETPOS32
= WM_USER
+ 114;
242 UDN_DELTAPOS
= UDN_FIRST
- 1;
244 Thousands2Style
: array[Boolean] of DWord
= (UDS_NOTHOUSANDS
, $0);
245 Wrap2Style
: array[Boolean] of DWord
= ($0, UDS_WRAP
);
246 ArrowKeys2Style
: array[Boolean] of DWord
= ($0, UDS_ARROWKEYS
);
247 Orientation2Style
: array[TUpDownOrientation
] of DWord
= (UDS_HORZ
, $0);
248 AlignButton2Style
: array[TUpDownAlignButton
] of DWord
= (UDS_ALIGNLEFT
,
250 AutoBuddy2Style
: array[Boolean] of DWord
= ($0, UDS_AUTOBUDDY
);
251 HotTrack2Style
: array[Boolean] of DWord
= ($0, UDS_HOTTRACK
);
252 Visible2Style
: array[Boolean] of DWord
= ($0, WS_VISIBLE
);
254 function NewMHUpDown(AParent
: PControl
; Orientation
: TUpDownOrientation
; Wrap
,
255 Thousands
, ArrowKeys
, AutoBuddy
, HotTrack
, BuddyInteger
: Boolean; AlignButton
:
256 TUpDownAlignButton
): PControl
;
261 PUpDownData
= ^TUpDownData
;
262 TUpDownData
= packed record
263 FOrientation
: TUpDownOrientation
;
269 FAlignButton
: TUpDownAlignButton
;
270 FOnChangingEx
: TOnChangingEx
;
275 function WndProcUpDown(Sender
: PControl
; var Msg
: TMsg
; var Rslt
: Integer):
278 UpDownNow
: PMHUpDown
;
281 Direction
: TUpDownDirection
;
287 if (Msg
.message = WM_NOTIFY
) and (Msg
.lParam
<> 0) then
289 NMUpDown
:= PNMUpDown(Msg
.lParam
);
290 UpDownNow
:= PMHUpDown(Sender
);
291 Data
:= UpDownNow
.CustomData
;
292 if NMUpDown
.hdr
.code
= UDN_DELTAPOS
then
294 if Assigned(UpDownNow
) then
296 if Assigned(Data
^.FOnChangingEx
) then
298 if NMUpDown
.iDelta
= 0 then
302 if NMUpDown
.iDelta
< 0 then
307 NewValue
:= NMUpDown
.iPos
+ NMUpDown
.iDelta
;
308 if NewValue
> Data
^.FMax
then
309 NewValue
:= Data
^.FMax
;
310 if NewValue
< Data
^.FMin
then
311 NewValue
:= Data
^.FMin
;
312 Data
^.FOnChangingEx(PObj(UpDownNow
), Allow
, NewValue
, Direction
);
324 function WndProcUpDownParent(Sender
: PControl
; var Msg
: TMsg
; var Rslt
:
327 UpDownNow
: PMHUpDown
;
332 if ((Msg
.message = WM_HSCROLL
) or (Msg
.message = WM_VSCROLL
)) and (Msg
.lParam
335 UpDownNow
:= Pointer(GetProp(Msg
.lParam
, ID_SELF
));
336 if UpDownNow
<> nil then
338 if Assigned(UpDownNow
.OnScroll
) then
340 if Msg
.message = WM_VSCROLL
then
344 UpDownNow
.OnScroll(UpDownNow
, Bar
, LoWord(Msg
.wParam
),
351 function NewMHUpDown(AParent
: PControl
; Orientation
: TUpDownOrientation
; Wrap
,
352 Thousands
, ArrowKeys
, AutoBuddy
, HotTrack
, BuddyInteger
: Boolean; AlignButton
:
353 TUpDownAlignButton
): PControl
;
357 DoInitCommonControls(ICC_UPDOWN_CLASS
);
358 Result
:= PMHUpDown(_NewCommonControl(AParent
, UPDOWN_CLASS
, WS_CHILD
or
359 WS_VISIBLE
or Thousands2Style
[Thousands
] or Wrap2Style
[Wrap
] or
360 ArrowKeys2Style
[ArrowKeys
] or Orientation2Style
[Orientation
] or
361 AlignButton2Style
[AlignButton
] or AutoBuddy2Style
[AutoBuddy
] or UDS_SETBUDDYINT
362 or HotTrack2Style
[HotTrack
], False, nil));
363 GetMem(D
, Sizeof(D
^));
364 FillChar(D
^, SizeOf(D
^), 0);
365 Result
.CustomData
:= D
;
368 D
.FOrientation
:= Orientation
;
369 D
.FHotTrack
:= HotTrack
;
371 D
.FThousands
:= Thousands
;
372 D
.FArrowKeys
:= ArrowKeys
;
373 D
.FAutoBuddy
:= AutoBuddy
;
374 D
.FAlignButton
:= AlignButton
;
375 Result
.AttachProc(WndProcUpDown
);
376 AParent
.AttachProc(WndProcUpDownParent
);
380 //----------------------------------------------------------------------------//
382 procedure TMHUpDown
.SetBuddy(const Value
: HWnd
);
384 Perform(UDM_SETBUDDY
, Value
, 0);
387 function TMHUpDown
.GetBuddy
: HWnd
;
389 Result
:= Perform(UDM_GETBUDDY
, 0, 0);
393 //----------------------------------------------------------------------------//
395 procedure TMHUpDown
.SetMin(const Value
: Integer);
399 Perform(UDM_GETRANGE32
, 0, DWord(@TMP
));
400 Perform(UDM_SETRANGE32
, Value
, TMP
);
401 PUpDownData(CustomData
)^.FMin
:= Value
;
404 function TMHUpDown
.GetMin
: Integer;
406 Perform(UDM_GETRANGE
, DWord(@Result
), 0);
410 //----------------------------------------------------------------------------//
412 procedure TMHUpDown
.SetMax(const Value
: Integer);
416 Perform(UDM_GETRANGE
, DWord(@TMP
), 0);
417 Perform(UDM_SETRANGE
, TMP
, Value
);
418 PUpDownData(CustomData
)^.FMax
:= Value
;
421 function TMHUpDown
.GetMax
: Integer;
423 Perform(UDM_GETRANGE32
, 0, DWord(@Result
));
427 //----------------------------------------------------------------------------//
429 procedure TMHUpDown
.SetPosition(const Value
: Integer);
431 Perform(UDM_SETPOS32
, 0, Value
);
434 function TMHUpDown
.GetPosition
: Integer;
436 Result
:= Perform(UDM_GETPOS32
, 0, 0);
440 //----------------------------------------------------------------------------//
442 procedure TMHUpDown
.SetHexBase(const Value
: Boolean);
445 Perform(UDM_SETBASE
, 16, 0)
447 Perform(UDM_SETBASE
, 10, 0);
450 function TMHUpDown
.GetHexBase
: Boolean;
452 if Perform(UDM_GETBASE
, 0, 0) = 16 then
459 //----------------------------------------------------------------------------//
461 procedure TMHUpDown
.SetIncrement(const Value
: Integer);
465 acc
.nSec
:= REFRESH_PERIOD
;
466 acc
.nInc
:= Cardinal(Value
);
467 Perform(UDM_SETACCEL
, 1, LongInt(@acc
));
470 function TMHUpDown
.GetIncrement
: Integer;
475 Perform(UDM_GETACCEL
, LongInt(@tmp
), LongInt(@acc
));
480 //----------------------------------------------------------------------------//
482 function TMHUpDown
.GetOrientation
: TUpDownOrientation
;
484 Result
:= PUpDownData(CustomData
)^.FOrientation
;
488 //----------------------------------------------------------------------------//
490 function TMHUpDown
.GetArrowKeys
: Boolean;
492 Result
:= PUpDownData(CustomData
)^.FArrowKeys
;
496 //----------------------------------------------------------------------------//
498 function TMHUpDown
.GetAlignButton
: TUpDownAlignButton
;
500 Result
:= PUpDownData(CustomData
)^.FAlignButton
;
504 //----------------------------------------------------------------------------//
506 function TMHUpDown
.GetAutoBuddy
: Boolean;
508 Result
:= PUpDownData(CustomData
)^.FAutoBuddy
;
512 //----------------------------------------------------------------------------//
514 function TMHUpDown
.GetThousands
: Boolean;
516 Result
:= PUpDownData(CustomData
)^.FThousands
;
520 //----------------------------------------------------------------------------//
522 function TMHUpDown
.GetWrap
: Boolean;
524 Result
:= PUpDownData(CustomData
)^.FWrap
;
528 //----------------------------------------------------------------------------//
530 function TMHUpDown
.GetHotTrack
: Boolean;
532 Result
:= PUpDownData(CustomData
)^.FHotTrack
;
536 //----------------------------------------------------------------------------//
538 procedure TMHUpDown
.SetOnChangingEx(const Value
: TOnChangingEx
);
540 PUpDownData(CustomData
)^.FOnChangingEx
:= Value
;
543 function TMHUpDown
.GetOnChangingEx
: TOnChangingEx
;
545 Result
:= PUpDownData(CustomData
)^.FOnChangingEx
;