/
ComboBox.prg
642 lines (414 loc) · 13.6 KB
/
ComboBox.prg
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
/// <include file="Gui.xml" path="doc/ComboBox/*" />
CLASS ComboBox INHERIT ListBox
/// <exclude />
METHOD __EditChange() AS VOID STRICT
//PP-030923 Update value with control contents on editchange (triggered by window dispatch)
//PP-040508 Update S.Ebert
//RvdH 050509 Set Modified Flag and don't assign self:uValue. The rest is handled by the ListBox class
//SELF:uValue := SELF:__GetText()
SELF:Modified := TRUE
RETURN
/// <exclude />
METHOD __InitTextMetrics() AS VOID STRICT
//PP-030828 Strong typing
//PP-040508 Update S.Ebert
LOCAL strucRect, strucRect1, strucRect2 IS _WinRect
LOCAL liDBUnits AS LONGINT
LOCAL liWidth AS LONGINT
LOCAL liHeight AS LONGINT
LOCAL hHandle AS PTR
hHandle := SELF:Handle()
GetWindowRect(hHandle, @strucRect2)
SendMessage(hHandle, CB_GETDROPPEDCONTROLRECT, 0, LONGINT(_CAST,@strucRect1))
UnionRect(@strucRect, @strucRect1, @strucRect2)
liWidth := strucRect:Right - strucRect:Left
liHeight := strucRect:Bottom - strucRect:Top
liDBUnits := GetDialogBaseUnits()
wXChars := DWORD(liWidth) /LoWord(DWORD(liDBUnits))
wYChars := DWORD(liHeight) /HiWord(DWORD(liDBUnits))
IF wYChars == 0
wYchars := 1
ENDIF
RETURN
/// <include file="Gui.xml" path="doc/ComboBox.CurrentText/*" />
ASSIGN CurrentText(cNewText)
LOCAL cCurrentText AS STRING
IF !IsString(cNewText)
WCError{#CurrentText,#ComboBox,__WCSTypeError,cNewText,1}:Throw()
ENDIF
cCurrentText := SELF:__SetText(cNewText)
IF SELF:FieldSpec IS FieldSpec VAR oFS
uValue := oFS:Val(cCurrentText)
ELSE
uValue := cCurrentText
ENDIF
RETURN
/// <include file="Gui.xml" path="doc/ComboBox.EditHandle/*" />
ACCESS EditHandle
//PP-030902
//SE-060519
IF SELF:ValidateControl()
RETURN GetWindow(hWnd, GW_CHILD)
ENDIF
RETURN NULL_PTR
/// <include file="Gui.xml" path="doc/ComboBox.EditHeight/*" />
ACCESS EditHeight
IF SELF:ValidateControl()
RETURN SendMessage(hWnd, CB_GETITEMHEIGHT, DWORD(_CAST, -1L), 0L)
ENDIF
RETURN 0
/// <include file="Gui.xml" path="doc/ComboBox.EditHeight/*" />
ASSIGN EditHeight(liNewHeight)
IF SELF:ValidateControl()
SendMessage(hWnd, CB_SETITEMHEIGHT, DWORD(_CAST, -1L), liNewHeight)
RETURN liNewHeight
ENDIF
RETURN 0
/// <include file="Gui.xml" path="doc/ComboBox.EnableAutoComplete/*" />
METHOD EnableAutoComplete(dwFlags)
//PP-030902
Default(@dwFlags,SHACF_DEFAULT)
RETURN ShellAutoComplete(SELF:Edithandle, dwFlags)
/// <include file="Gui.xml" path="doc/ComboBox.Font/*" />
METHOD Font(oNewFont, lRescal)
LOCAL uRet AS USUAL
LOCAL hEdit AS PTR
IF SELF:ValidateControl()
uRet := SUPER:Font(oNewFont, lRescal)
//SE-060519
hEdit := SELF:EditHandle
IF (hEdit != NULL_PTR)
SendMessage(hEdit, EM_SETMARGINS, _OR(EC_LEFTMARGIN, EC_RIGHTMARGIN), 0L)
ENDIF
ENDIF
RETURN uRet
/// <include file="Gui.xml" path="doc/ComboBox.ctor/*" />
CONSTRUCTOR(oOwner, xID, oPoint, oDimension, kComboType, kStyle)
LOCAL liComboType AS LONGINT
LOCAL dwStyle AS DWORD
SUPER(oOwner, xID, oPoint, oDimension, kStyle)
IF !IsNil(kComboType)
IF !IsLong(kComboType)
WCError{#Init,#ComboBox,__WCSTypeError,kComboType,5}:Throw()
ENDIF
liComboType := kComboType
ELSE
liComboType := BoxDropDown
ENDIF
IF !(xID IS ResourceID)
IF !IsInstanceOf(SELF, #ComboBoxEx)
SELF:SetStyle(_OR(WS_CLIPSIBLINGS,WS_CLIPCHILDREN), FALSE)
dwStyle := _OR(WS_BORDER, WS_VSCROLL)
ENDIF
DO CASE
CASE (liComboType == BOXSIMPLE)
SELF:SetStyle(_OR(dwStyle, DWORD(_CAST, CBS_SIMPLE)))
CASE (liComboType == BOXDROPDOWN)
SELF:SetStyle(_OR(dwStyle, DWORD(_CAST, CBS_DROPDOWN)))
CASE (liComboType == BOXDROPDOWNLIST)
SELF:SetStyle(_OR(dwStyle, DWORD(_CAST, CBS_DROPDOWNLIST)))
OTHERWISE
WCError{#Init,#ComboBox,__WCSTypeError,liComboType,5}:Throw()
ENDCASE
ENDIF
SELF:__ClassName := "ComboBox"
SELF:MsgGroup := 2
// fpListFiles := @DlgDirListComboBox()
// fpSelectedFile := @DlgDirSelectComboBoxEx()
RETURN
/// <include file="Gui.xml" path="doc/ComboBox.RemoveEditBalloonTip/*" />
METHOD RemoveEditBalloonTip()
//PP-030902
RETURN SUPER:RemoveEditBalloonTip(SELF:EditHandle)
/// <include file="Gui.xml" path="doc/ComboBox.ReadOnly/*" />
ACCESS ReadOnly()
LOCAL hEdit AS PTR
LOCAL liStyle AS LONG
hEdit := GetWindow( SELF:Handle(), GW_CHILD )
liStyle := GetWindowLong( hEdit, GWL_STYLE )
RETURN _AND( liStyle, LONG( ES_READONLY ) ) == ES_READONLY
/// <include file="Gui.xml" path="doc/ComboBox.ReadOnly/*" />
ASSIGN ReadOnly( lReadOnly )
LOCAL hEdit AS PTR
Default(@lReadOnly,TRUE)
IF .NOT. IsLogic(lReadOnly)
lReadOnly := TRUE
ENDIF
hEdit := SELF:EditHandle
IF lReadOnly
SELF:Disable()
IF (hEdit != NULL_PTR)
EnableWindow( hEdit, TRUE )
SendMessage( hEdit, EM_SETREADONLY, 1, 0 )
ENDIF
ELSE
SELF:Enable()
IF (hEdit != NULL_PTR)
SendMessage( hEdit, EM_SETREADONLY, 0, 0 )
ENDIF
ENDIF
RETURN
/// <include file="Gui.xml" path="doc/ComboBox.SetCueBanner/*" />
METHOD SetCueBanner(cTitle)
//PP-030902
RETURN SUPER:SetCueBanner(cTitle,SELF:EditHandle)
/// <include file="Gui.xml" path="doc/ComboBox.ShowEditBalloonTip/*" />
METHOD ShowEditBalloonTip(cTitle,cText,dwIcon)
//PP-030902
RETURN SUPER:ShowEditBalloonTip(cTitle,cText,dwIcon,SELF:EditHandle)
END CLASS
/// <include file="Gui.xml" path="doc/ComboBoxEx/*" />
CLASS ComboBoxEx INHERIT ComboBox
PROTECT oImgList AS ImageList
/// <include file="Gui.xml" path="doc/ComboBoxEx.AddItem/*" />
METHOD AddItem(cItem, nItemNumber, uRetValue, iImageIdx, iSelectedIdx, iOverlayIdx, iIndent)
//SE-060519
Default(@nItemNumber, 0)
Default(@iSelectedIdx, iImageIdx)
RETURN SELF:InsertItem(ComboBoxExItem{cItem, nItemNumber, uRetValue, iImageIdx, iSelectedIdx, iOverlayIdx, iIndent})
/// <include file="Gui.xml" path="doc/ComboBoxEx.DeleteItem/*" />
METHOD DeleteItem(nItemNumber)
//SE-060519
LOCAL lReturnValue AS LOGIC
LOCAL dwPos AS DWORD
IF ! IsNil(nItemNumber)
IF !IsLong(nItemNumber)
WCError{#DeleteItem,#ComboBoxEx,__WCSTypeError,nItemNumber,1}:Throw()
ENDIF
IF (nItemNumber != 0)
dwPos := nItemNumber-1
ENDIF
ELSE
nItemNumber := 0
ENDIF
IF (nItemNumber == 0)
IF ((dwPos := SELF:CurrentItemNo) == 0)
RETURN FALSE
ENDIF
dwPos--
ENDIF
lReturnValue := (SendMessage(SELF:Handle(), CBEM_DELETEITEM, dwPos, 0) != CB_ERR)
IF lReturnValue
dwPos++
ADel(aDisplayValues, dwPos)
ADel(aRetValues, dwPos)
ASize(aDisplayValues, ALen(aDisplayValues) - 1)
ASize(aRetValues, ALen(aRetValues) - 1)
ENDIF
RETURN lReturnValue
// RETURN SUPER:DeleteItem(nItemNumber)
/// <include file="Gui.xml" path="doc/ComboBoxEx.Dispatch/*" />
METHOD Dispatch (oEvent)
//SE-060518
LOCAL oEvt AS @@event
LOCAL hBr AS PTR
oEvt := oEvent
IF oEvt:uMsg == WM_CTLCOLOREDIT //supports Background of ComboBoxEx control
hBr := SendMessage(GetParent(hWnd), WM_CTLCOLOREDIT, oEvt:wParam, oEvt:lParam)
IF (hBr != NULL_PTR)
SELF:EventReturnValue := LONGINT(_CAST, hBr)
RETURN 1L
ENDIF
ENDIF
RETURN SUPER:Dispatch (oEvt)
/// <include file="Gui.xml" path="doc/ComboBoxEx.EditHandle/*" />
ACCESS EditHandle
//SE-060519
IF SELF:ValidateControl()
RETURN PTR(_CAST, SendMessage(hWnd, CBEM_GETEDITCONTROL, 0, 0L))
ENDIF
RETURN NULL_PTR
/// <include file="Gui.xml" path="doc/ComboBoxEx.GetExCBStyle/*" />
METHOD GetExCBStyle(kExStyle)
//SE-060519
LOCAL dwExStyle AS DWORD
dwExStyle := DWORD(_CAST, SendMessage(SELF:handle(), CBEM_GETEXSTYLE,0,0)) //CBEM_GETEXTENDEDSTYLE, 0, 0))
IF IsLong(kExStyle)
RETURN (_AND(dwExStyle, DWORD(kExStyle)) > 0)
ENDIF
RETURN dwExStyle
/// <include file="Gui.xml" path="doc/ComboBoxEx.GetItemAttributes/*" />
METHOD GetItemAttributes(uItemNumber)
//SE-060519
LOCAL oComboBoxExItem AS ComboBoxExItem
LOCAL cbxi IS _winCOMBOBOXEXITEM
IF IsNil(uItemNumber) .OR. uItemNumber = 0
uItemNumber := SELF:CurrentItemNo
ENDIF
IF uItemNumber > 0
cbxi:mask := _OR(CBEIF_IMAGE, CBEIF_SELECTEDIMAGE, CBEIF_OVERLAY, CBEIF_INDENT)
cbxi:iItem := uItemNumber -1l
IF SendMessage(SELF:Handle(), CBEM_GETITEM, 0, LONGINT(_CAST, @cbxi)) != 0
oComboBoxExItem := ComboBoxExItem{aDisplayValues[uItemNumber],uItemNumber,aRetValues[uItemNumber]}
oComboBoxExItem:__GetValues(@cbxi)
ENDIF
ENDIF
RETURN oComboBoxExItem
/// <include file="Gui.xml" path="doc/ComboBoxEx.ImageList/*" />
ACCESS ImageList
RETURN oImgList
/// <include file="Gui.xml" path="doc/ComboBoxEx.ImageList/*" />
ASSIGN ImageList(oNewImageList)
LOCAL oDim AS Dimension
oImgList := oNewImageList
//SE-060520
IF (SELF:Handle() != NULL_PTR)
SendMessage(hWnd, CBEM_SETIMAGELIST, 0, LONGINT(_CAST, oImgList:Handle()))
oDim := SELF:Size
IF oDim:Height < 80
oDim:Height := 80
ENDIF
SetWindowPos(hWnd, NULL_PTR, 0, 0, oDim:width, oDim:height, _OR(SWP_NOACTIVATE, SWP_NOZORDER,SWP_NOMOVE))
ENDIF
RETURN
/// <include file="Gui.xml" path="doc/ComboBoxEx.ctor/*" />
CONSTRUCTOR(oOwner, xID, oPoint, oDimension, kComboType, kStyle)
Default(@kComboType, BOXDROPDOWN)
SUPER(oOwner, xID, oPoint, oDimension, kComboType, kStyle)
SELF:__ClassName := "ComboBoxEx32"
dwExStyle := _AND(dwExStyle, DWORD(_CAST, _NOT(WS_EX_CLIENTEDGE)))
dwStyle := _OR(dwStyle, DWORD(_CAST, CCS_NOMOVEY))
RETURN
/// <inheritdoc />
METHOD Destroy()
if self:oImgList != nil
self:oImgList:Destroy()
SendMessage(hWnd, CBEM_SETIMAGELIST, 0, 0)
self:oImgList := NULL
endif
SUPER:Destroy()
RETURN NIL
/// <include file="Gui.xml" path="doc/ComboBoxEx.InsertItem/*" />
METHOD InsertItem(uComboBoxExItem)
//SE-060519
LOCAL oComboBoxExItem AS ComboBoxExItem
LOCAL cbxi IS _winCOMBOBOXEXITEM
LOCAL lPosition AS INT
oComboBoxExItem := uComboBoxExItem
oComboBoxExItem:__SetValues(@cbxi)
lPosition := SendMessage(SELF:Handle(), CBEM_INSERTITEM, 0, LONGINT(_CAST, @cbxi)) + 1l
//RvdH 070615 Free ptr allocated in __SetValues
IF (cbxi:pszText != NULL_PSZ)
MemFree(cbxi:pszText)
ENDIF
IF (lPosition != 0)
SELF:__AddItem(oComboBoxExItem:TextValue, oComboBoxExItem:Value, DWORD(lPosition))
ENDIF
RETURN lPosition
/// <include file="Gui.xml" path="doc/ComboBoxEx.Length/*" />
ACCESS Length
LOCAL lRetVal AS LONGINT
LOCAL hHandle AS PTR
//SE-060519
IF (hHandle := SELF:EditHandle) != NULL_PTR
lRetVal := GetWindowTextLength(hHandle)
IF (lRetVal == CB_ERR)
lRetVal := 0
ENDIF
ENDIF
RETURN lRetVal
/// <include file="Gui.xml" path="doc/ComboBoxEx.SetExCBStyle/*" />
METHOD SetExCBStyle(kExStyle, lEnable)
//SE-060519
IF !IsLong(kExStyle)
WCError{#SetExCBStyle,#ComboBoxEx,__WCSTypeError,kExStyle,}:Throw()
ENDIF
IF IsNil(lEnable) .OR. !IsLogic(lEnable)
lEnable := TRUE
ENDIF
SendMessage(SELF:Handle(), CBEM_SETEXTENDEDSTYLE, kExStyle, IIF(lEnable, kExStyle, 0l))
RETURN SELF
/// <include file="Gui.xml" path="doc/ComboBoxEx.SetItemAttributes/*" />
METHOD SetItemAttributes(uComboBoxExItem)
//SE-060519
LOCAL oComboBoxExItem AS ComboBoxExItem
LOCAL cbxi IS _winCOMBOBOXEXITEM
oComboBoxExItem := uComboBoxExItem
IF oComboBoxExItem:ItemIndex > 0
oComboBoxExItem:__SetValues(@cbxi)
IF SendMessage(SELF:Handle(), CBEM_SETITEM, 0, LONGINT(_CAST, @cbxi)) != 0
aRetValues[oComboBoxExItem:ItemIndex] := oComboBoxExItem:Value
ENDIF
//RvdH 070615 Free ptr allocated in __SetValues
IF (cbxi:pszText != NULL_PSZ)
MemFree(cbxi:pszText)
ENDIF
ENDIF
RETURN SELF
END CLASS
/// <include file="Gui.xml" path="doc/ComboBoxExItem/*" />
CLASS ComboBoxExItem INHERIT VObject
//SE-060519
EXPORT ItemIndex AS INT
EXPORT ImageIndex AS INT
EXPORT SelectedImageIndex AS INT
EXPORT OverlayImageIndex AS INT
EXPORT TextValue AS STRING
EXPORT Value AS USUAL
EXPORT Indent AS INT
/// <exclude />
METHOD __GetValues(cbxi AS _winCOMBOBOXEXITEM) AS VOID STRICT
//SE-060519
SELF:ItemIndex := cbxi:iItem + 1l
SELF:ImageIndex := cbxi:iImage + IIF(cbxi:iImage >= 0, 1l, 0l)
SELF:SelectedImageIndex := cbxi:iSelectedImage + IIF(cbxi:iSelectedImage >= 0, 1l, 0l)
SELF:OverlayImageIndex := cbxi:iOverlay
SELF:Indent := cbxi:iIndent
RETURN
/// <exclude />
METHOD __SetValues(cbxi AS _winCOMBOBOXEXITEM) AS VOID STRICT
//SE-060519
LOCAL cItem AS STRING
cbxi:mask := _OR(CBEIF_TEXT, CBEIF_INDENT)
cbxi:iItem := Max(SELF:ItemIndex - 1L,-1L) //RvdH 070611 Suggestion from Meinhard
cbxi:iIndent := SELF:Indent
cItem := SELF:TextValue
//RvdH 060608 optimized: cItem is a string
//IF !Empty(cItem)
IF SLen(cItem) > 0
//cbxi.pszText := Cast2Psz(cItem)
cbxi:pszText := StringAlloc(cItem) // RvdH 070615 Cast2Psz is not safe here !
ENDIF
IF SELF:ImageIndex != 0
cbxi:mask := _OR(cbxi:mask, CBEIF_IMAGE)
cbxi:iImage := SELF:ImageIndex
IF cbxi:iImage > 0
cbxi:iImage -=1l
ENDIF
ENDIF
IF SELF:SelectedImageIndex != 0
cbxi:mask := _OR(cbxi:mask, CBEIF_SELECTEDIMAGE)
cbxi:iSelectedImage := SELF:SelectedImageIndex
IF cbxi:iSelectedImage > 0
cbxi:iSelectedImage -=1l
ENDIF
ENDIF
IF SELF:OverlayImageIndex != 0
cbxi:mask := _OR(cbxi:mask, CBEIF_OVERLAY)
cbxi:iOverlay := SELF:OverlayImageIndex
ENDIF
RETURN
/// <include file="Gui.xml" path="doc/ComboBoxExItem.ctor/*" />
CONSTRUCTOR(cItem, nItemNumber, uRetValue, iImageIdx, iSelectedIdx, iOverlayIdx, iIndent)
//SE-060519
IF IsString(cItem)
SELF:TextValue := cItem
ENDIF
IF IsNumeric(nItemNumber)
SELF:ItemIndex := nItemNumber
ENDIF
SELF:Value := uRetValue
IF IsNumeric(iImageIdx)
SELF:ImageIndex := iImageIdx
ENDIF
IF IsNumeric(iSelectedIdx)
SELF:SelectedImageIndex := iSelectedIdx
ENDIF
IF IsNumeric(iOverlayIdx)
SELF:OverlayImageIndex := iOverlayIdx
ENDIF
IF IsNumeric(iIndent)
SELF:Indent := iIndent
ENDIF
RETURN
END CLASS