-
Notifications
You must be signed in to change notification settings - Fork 4
/
themedtitlebarbase.vca
1236 lines (1180 loc) · 37.7 KB
/
themedtitlebarbase.vca
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
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
SCCTEXT Version 4.0.0.2
PLATFORM C(8,0),UNIQUEID C(10,0),TIMESTAMP N(10,0),CLASS M(4,0),CLASSLOC M(4,0),BASECLASS M(4,0),OBJNAME M(4,0),PARENT M(4,0),PROPERTIES M(4,0),PROTECTED M(4,0),METHODS M(4,0),OBJCODE M(4,0),OLE M(4,0),OLE2 M(4,0),RESERVED1 M(4,0),RESERVED2 M(4,0),RESERVED3 M(4,0),RESERVED4 M(4,0),RESERVED5 M(4,0),RESERVED6 M(4,0),RESERVED7 M(4,0),RESERVED8 M(4,0),USER M(4,0)
1252
[ RECORD]
[PLATFORM] COMMENT
[UNIQUEID] Class
[START RESERVED1]
VERSION = 3.00[END RESERVED1]
[ RECORD]
[PLATFORM] WINDOWS
[UNIQUEID] _48F07AUEM
[CLASS] control
[BASECLASS] control
[OBJNAME] themedtitlebarbase
[START PROPERTIES]
BackColor = 0,0,0
BorderWidth = 0
ForeColor = 255,255,255
Height = 60
Name = "themedtitlebarbase"
Width = 325
cdescriptionproperty = ThemedTitleBarDescription
cimageproperty = ThemedTitleBarImage
csettingsclass = ThemedTitleBarSettingsBase
csettingsclasslib = ThemedTitleBarBase.vcx
ctitleproperty =
lautomoveformcontrols = .T.
lfixedheight = .F.
lrespectautocenter = .T.
[END PROPERTIES]
[START METHODS]
PROCEDURE DblClick
*--------------------------------------------
* Maximize or restore form.
*--------------------------------------------
IF m.Thisform.MaxButton
IF m.Thisform.WindowState == 2 && Maximized.
Thisform.WindowState = 0 && Normal.
ELSE
Thisform.WindowState = 2 && Maximized.
ENDIF
ENDIF
ENDPROC
PROCEDURE Destroy
UNBINDEVENTS( This )
ENDPROC
PROCEDURE Init
*--------------------------------------------
* Prevent this class form beeing instantiated
* directly.
*--------------------------------------------
IF m.This._IsAbstract( m.This.Class, "ThemedTitleBarBase")
RETURN .F.
ENDIF
*--------------------------------------------
* Setup.
*--------------------------------------------
LOCAL lcFormComment, lnFormMinHeight, lnFormMaxHeight, loSettings
*
WITH Thisform
*--------------------------------------------
* Some form properties must have certain
* values, thus removing the default TitleBar
* has no adverse side effects.
*--------------------------------------------
lcFormComment = .Comment
lnFormMinHeight = .MinHeight
lnFormMaxHeight = .MaxHeight
.Comment = "*NORESIZE*" && Switch off mwResize.
.MinHeight = -1
.MaxHeight = -1
*--------------------------------------------
* Remove form title bar.
*--------------------------------------------
.TitleBar = 0 && Off.
*--------------------------------------------
* Restore the form properties we changed.
*--------------------------------------------
.MinHeight = m.lnFormMinHeight
.MaxHeight = m.lnFormMaxHeight
.Comment = m.lcFormComment
*--------------------------------------------
* Without a title bar a vfp form with
* BorderStyle=0 has no border at all. There
* is no way to differ it from a container on
* the underlying form. This might overwhelm
* the user.
*--------------------------------------------
IF .BorderStyle == 0
.BorderStyle = 1
ENDIF
ENDWITH
*--------------------------------------------
* A global settings object speeds things up.
* Did the user create one?
*--------------------------------------------
DO CASE
CASE VARTYPE( _Screen.ThemedTitleBarSettings ) == "O"
loSettings = _Screen.ThemedTitleBarSettings
CASE SET( "DATASESSION" ) == 1
*--------------------------------------------
* Running in the global DataSession. So no
* problem creating a new object on _Screen.
*--------------------------------------------
_Screen.NewObject( "ThemedTitleBarSettings", m.This.cSettingsClass, m.This.cSettingsClassLib )
loSettings = _Screen.ThemedTitleBarSettings
OTHERWISE
*--------------------------------------------
* Private DataSession. Creating a new object
* on _Screen would leave this DataSession
* open when the form is closed. The form's
* cursors would stay open, too. So we have to
* use a temporary copy of the settings
* object.
*--------------------------------------------
loSettings = NEWOBJECT( m.This.cSettingsClass, m.This.cSettingsClassLib )
ENDCASE
*--------------------------------------------
* Set colors and fonts.
*--------------------------------------------
WITH loSettings
This.BackColor = .nTitleBarBackColor
This.lblCaption.ForeColor = .nTitleBarForeColor
This.edtDescription.ForeColor = .nTitleBarForeColor
This.lblCaption.FontName = .cCaptionFontFamily
This.edtDescription.FontName = .cDescriptionFontFamily
ENDWITH
loSettings = .NULL.
RELEASE loSettings
*--------------------------------------------
* Position and anchor our own title bar.
*--------------------------------------------
This.Anchor = 0
This.Left = 0
This.Top = 0
This.Width = m.Thisform.Width
This.Anchor = 10
*--------------------------------------------
* Position and anchor system buttons.
*--------------------------------------------
m.This.cmdClose.Move( m.This.Width - m.This.cmdClose.Width - 1, 1 )
m.This.cmdMaximize.Move( m.This.Width - m.This.cmdClose.Width - m.This.cmdMaximize.Width - 2, 1 )
m.This.cmdMinimize.Move( m.This.Width - m.This.cmdClose.Width - m.This.cmdMaximize.Width - m.This.cmdMaximize.Width - 3, 1 )
STORE 9 TO This.cmdClose.Anchor, This.cmdMaximize.Anchor, This.cmdMinimize.Anchor
*--------------------------------------------
* Set anchoring of caption label. Positioning
* happens in RefreshImage().
*--------------------------------------------
This.lblCaption.Anchor = 10
*--------------------------------------------
* Adjust description width to title bar
* width.
*--------------------------------------------
This.edtDescription.Width = m.This.Width - m.This.edtDescription.Left - 5
This.edtDescription.Anchor = 11
*--------------------------------------------
* Bind all form properties influencing the
* system buttons' state to the Refresh event
* of our title bar.
*--------------------------------------------
LOCAL lnResult
lnResult = BINDEVENT( Thisform, "MinButton", This, "Refresh", 1 )
ASSERT m.lnResult > 0 MESSAGE m.This.Name + ": BindEvent to MinButton did not work"
lnResult = BINDEVENT( Thisform, "MaxButton", This, "Refresh", 1 )
ASSERT m.lnResult > 0 MESSAGE m.This.Name + ": BindEvent to MaxButton did not work"
lnResult = BINDEVENT( Thisform, "WindowState", This, "Refresh", 1 )
ASSERT m.lnResult > 0 MESSAGE m.This.Name + ": BindEvent to WindowState did not work"
lnResult = BINDEVENT( Thisform, "Closable", This, "Refresh", 1 )
ASSERT m.lnResult > 0 MESSAGE m.This.Name + ": BindEvent to Closable did not work"
*--------------------------------------------
*(..)An additional BINDEVENT() to the form's
*(..)Resize() event is necessary because
*(..)BINDEVENT() to WindowState doesn't fire
*(..)in two situations:
*(..)- A minimized form is maximized or
*(..) restored.
*(..)- A maximized form's size is reduced
*(..) using the mouse.
*--------------------------------------------
lnResult = BINDEVENT( Thisform, "Resize", This, "Refresh", 1 )
ASSERT m.lnResult > 0 MESSAGE m.This.Name + ": BindEvent to Resize did not work"
*--------------------------------------------
* Forward changes to form caption or title to
* the caption label.
*--------------------------------------------
lnResult = BINDEVENT( Thisform, "Caption", This, "RefreshCaption", 1 )
ASSERT m.lnResult > 0 MESSAGE m.This.Name + ": BindEvent to Caption did not work"
IF NOT EMPTY( m.This.cTitleProperty ) ;
AND TYPE( "m.Thisform." + m.This.cTitleProperty ) == "C"
lnResult = BINDEVENT( Thisform, m.This.cTitleProperty, This, "RefreshCaption", 1 )
ASSERT m.lnResult > 0 MESSAGE m.This.Name + ": BindEvent to title property did not work"
ENDIF
*--------------------------------------------
* Forward title bar image name changes to the
* image control.
*--------------------------------------------
IF TYPE( "m.Thisform." + m.This.cImageProperty ) == "C"
lnResult = BINDEVENT( Thisform, m.This.cImageProperty, This, "RefreshImage", 1 )
ASSERT m.lnResult > 0 MESSAGE m.This.Name + ": BindEvent to image property did not work"
*--------------------------------------------
* As only the Refresh() event is
* automatically triggered at form start, we
* have to trigger the RefreshImage() event
* ourselves.
* As RefreshImage() positions edtDescription
* we have to do this unconditionally.
*--------------------------------------------
m.This.RefreshImage()
ENDIF
*--------------------------------------------
* As only the Refresh() event is
* automatically triggered at form start, we
* have to trigger the RefreshCaption() event
* ourselves.
* As lblCaption.Caption initially is not
* empty, we have to do this unconditionally.
*--------------------------------------------
m.This.RefreshCaption()
*--------------------------------------------
* Forward title bar description changes to
* the editbox.
*--------------------------------------------
IF TYPE( "m.Thisform." + m.This.cDescriptionProperty ) == "C"
lnResult = BINDEVENT( Thisform, m.This.cDescriptionProperty, This, "RefreshDescription", 1 )
ASSERT m.lnResult > 0 MESSAGE m.This.Name + ": BindEvent to description property did not work"
*--------------------------------------------
* As only the Refresh() event is
* automatically triggered at form start, we
* have to trigger the RefreshDescription()
* event ourselves.
*--------------------------------------------
IF NOT EMPTY(EVALUATE( "m.Thisform." + m.This.cDescriptionProperty ))
m.This.RefreshDescription()
ENDIF
ENDIF
*--------------------------------------------
* Always call This.AutoMoveFormControls() at
* first Form.Show(). It decides if the other
* controls on the form have to by moved
* downward by TitleBar height.
*--------------------------------------------
lnResult = BINDEVENT( Thisform, "Show", This, "AutoMoveFormControls" )
ASSERT m.lnResult > 0 MESSAGE m.This.Name + ": BindEvent to Show did not work"
ENDPROC
PROCEDURE MouseDown
LPARAMETERS tnButton, tnShift, tnXCoord, tnYCoord
*--------------------------------------------
* Left mouse button click?
*--------------------------------------------
IF NOT m.tnButton == 1
RETURN
ENDIF
*--------------------------------------------
* Move form as long as left mouse button is
* clicked.
*--------------------------------------------
* Constants.
*--------------------------------------------
#DEFINE WM_SYSCOMMAND 0x112
#DEFINE WM_LBUTTONUP 0x202
#DEFINE MOUSE_MOVE 0xf012
*--------------------------------------------
* Windows API functions to move the form
* dragging our own title bar.
*--------------------------------------------
DECLARE LONG ReleaseCapture IN Win32API AS ThemedTitleBar_ReleaseCapture
DECLARE LONG SendMessage IN Win32API AS ThemedTitleBar_SendMessage ;
LONG hWnd, LONG wMsg, LONG wParam, LONG lParam
*--------------------------------------------
* No idea what this API call really does...
*--------------------------------------------
ThemedTitleBar_ReleaseCapture()
*--------------------------------------------
* Complete left click by sending 'left button
* up' message.
*--------------------------------------------
ThemedTitleBar_SendMessage( m.Thisform.HWnd, WM_LBUTTONUP, 0x0, 0x0 )
*--------------------------------------------
* Initiate window move.
*--------------------------------------------
ThemedTitleBar_SendMessage( m.Thisform.HWnd, WM_SYSCOMMAND, MOUSE_MOVE, 0x0 )
ENDPROC
PROCEDURE Move
LPARAMETERS tnLeft, tnTop, tnWidth, tnHeight
*--------------------------------------------
* Prevent resizers like mwResize from
* changing This.Height by calling Move()?
*--------------------------------------------
IF m.This.lFixedHeight
NODEFAULT
ENDIF
ENDPROC
PROCEDURE Refresh
*--------------------------------------------
* When this method is called by BINDEVENT()
* the contained controls' Refresh() event
* isn't triggered. So we have to call it
* manually.
*--------------------------------------------
NODEFAULT
m.This.cmdMinimize.Refresh()
m.This.cmdMaximize.Refresh()
m.This.cmdClose.Refresh()
*--------------------------------------------
*(..)After reducing a maximized form's size
*(..)by moving the form's lower left or right
*(..)corner with the mouse sometimes this
*(..)control's anchoring doesn't fire.
*--------------------------------------------
IF NOT m.This.Width == m.Thisform.Width
This.Width = m.Thisform.Width
ENDIF
*--------------------------------------------
* After the form was resized we have to check
* again how many characters of the caption
* can be displayed.
*--------------------------------------------
m.This.RefreshCaption()
ENDPROC
PROCEDURE _isabstract
LPARAMETERS tcClass, tcClassName
IF UPPER( m.tcClass ) == UPPER( m.tcClassName )
#DEFINE MB_OK 0
#DEFINE MB_ICONSTOP 16
MESSAGEBOX( "This class can not be instantiated directly." +CHR(13)+ ;
"Please use a derivative of the class instead.", ;
MB_ICONSTOP + MB_OK, ;
m.tcClassName )
RETURN .T.
ELSE
RETURN .F.
ENDIF
ENDPROC
PROCEDURE automoveformcontrols
LPARAMETERS tnShow
*--------------------------------------------
* Make sure this method is called only once.
*--------------------------------------------
UNBINDEVENTS( Thisform, "Show", This, "AutoMoveFormControls" )
*
IF m.This.lAutoMoveFormControls
*--------------------------------------------
* Check if Form.Show() was called from
* Form.Init().
*--------------------------------------------
IF NOT m.Thisform.Visible
LOCAL laStackInfo[1], lnStackSize
lnStackSize = ASTACKINFO( laStackInfo )
IF m.lnStackSize > 1 ;
AND ".show" $ LOWER( laStackInfo[ m.lnStackSize - 1, 6 ] ) ;
AND LOWER(GETWORDNUM( laStackInfo[ m.lnStackSize, 3 ], 1, "." )) == LOWER(GETWORDNUM( laStackInfo[ m.lnStackSize - 1, 3 ], 1, "." ))
*--------------------------------------------
* By calling Form.Show() from Form.Init() the
* programmer changed the internal order of
* VFP's form events. If she also changed
* Form.Height within Form.Init(), anchoring
* didn't fire yet. I.e., the controls' Height
* and/or Top don't reflect the changed
* Form.Height.
* So let's make sure anchoring has fired at
* least once before MoveFormControls() is
* called. Making the form visible triggers
* VFP's anchoring.
*--------------------------------------------
Thisform.Visible = .T.
Thisform.Visible = .F.
ENDIF
ENDIF
*
m.This.MoveFormControls()
ENDIF
ENDPROC
PROCEDURE moveformcontrols
LPARAMETERS tnTop
*--------------------------------------------
* Check parameters.
*--------------------------------------------
IF PCOUNT() == 0
tnTop = -4
ENDIF
*--------------------------------------------
* Setup.
*--------------------------------------------
LOCAL lnPixel, i, loControl, laControls[1], lnControls, ;
lnAnchor, lnFormHeight, lcFormComment
lnFormHeight = m.Thisform.Height
*--------------------------------------------
* Move all form controls below a certain Top
* downward by n pixels.
*--------------------------------------------
lnPixel = m.This.Height
lnControls = 0
FOR i = 1 TO m.Thisform.ControlCount
loControl = .NULL.
loControl = m.Thisform.Controls[ i ]
*--------------------------------------------
* Ignore controls without a Top property
* (e.g. Collections).
*--------------------------------------------
IF NOT PEMSTATUS( m.loControl, "Top", 5 )
LOOP
ENDIF
*--------------------------------------------
* Do we have to move this control?
*--------------------------------------------
IF m.loControl.Top < m.tnTop
LOOP
ENDIF
*--------------------------------------------
* Remember what we want to do.
* laControls[] has four columns:
* 1 - control's object reference.
* 2 - control's Top value.
* 3 - control's Anchor value.
* 4 - control's _nOriginalTop value
* (this is a mwResize property) or
* .NULL. if this property doesn't exist.
*--------------------------------------------
lnControls = m.lnControls + 1
DIMENSION laControls[ m.lnControls, 4 ]
laControls[ m.lnControls, 1 ] = m.loControl
laControls[ m.lnControls, 2 ] = m.loControl.Top + m.lnPixel
*
IF PEMSTATUS( m.loControl, "Anchor", 5 ) && Timers don't have an Anchor property.
laControls[ m.lnControls, 3 ] = m.loControl.Anchor
IF m.loControl.Anchor > 0
*--------------------------------------------
* Cancel anchoring to make moving possible.
*--------------------------------------------
loControl.Anchor = 0
ENDIF
ELSE
laControls[ m.lnControls, 3 ] = 0
ENDIF
*
IF PEMSTATUS( m.loControl, "_nOriginalTop", 5 ) && Present only after first run of mwResize.Resize().
laControls[ m.lnControls, 4 ] = m.loControl._nOriginalTop + m.lnPixel
ELSE
laControls[ m.lnControls, 4 ] = m.loControl.Top + m.lnPixel
ENDIF
ENDFOR
*--------------------------------------------
* Check if mwResize is present.
*--------------------------------------------
IF NOT PEMSTATUS( m.Thisform, "_nOriginalHeight", 5 )
*--------------------------------------------
* In case mwResize is present but didn't run
* up to now, trigger it once to create the
* above property.
*--------------------------------------------
lcFormComment = m.Thisform.Comment
Thisform.Comment = "*NORESIZE*" && Switch off mwResize temporary.
m.Thisform.Resize() && Force mwResize to save form size.
Thisform.Comment = m.lcFormComment
ENDIF
*--------------------------------------------
* If this form uses mwResize we have to
* inform it about the new height.
*--------------------------------------------
IF PEMSTATUS( m.Thisform, "_nOriginalHeight", 5 )
Thisform._nOriginalHeight = m.Thisform._nOriginalHeight + m.lnPixel
ENDIF
*--------------------------------------------
* MaxHeight must allow the new height.
*--------------------------------------------
IF NOT m.Thisform.MaxHeight == -1 ;
AND m.Thisform.MaxHeight < m.lnFormHeight
Thisform.MaxHeight = m.lnFormHeight
ENDIF
*--------------------------------------------
* Increase form height by title bar height.
* This may trigger a run of mwResize.Resize()
* if this form uses mwResize.
*--------------------------------------------
Thisform.Height = m.lnFormHeight + m.lnPixel
*--------------------------------------------
* Increase MinHeight by title bar height.
* This may trigger a run of mwResize.Resize()
* if this form uses mwResize.
*--------------------------------------------
IF NOT m.Thisform.MinHeight == -1
Thisform.MinHeight = m.Thisform.MinHeight + m.lnPixel
ENDIF
*--------------------------------------------
* Move controls. Restore anchoring and
* mwResize _nOriginalTop.
*--------------------------------------------
FOR i = 1 TO m.lnControls
laControls[ i, 1 ].Top = laControls[ i, 2 ]
IF laControls[ i, 3 ] > 0
laControls[ i, 1 ].Anchor = laControls[ i, 3 ]
ENDIF
IF PEMSTATUS( laControls[ i, 1 ], "_nOriginalTop", 5 ) && Present only after first run of mwResize.Resize().
laControls[ i, 1 ]._nOriginalTop = laControls[ i, 4 ]
ENDIF
laControls[ i, 1 ] = .NULL.
ENDFOR
*--------------------------------------------
* While moving controls we moved this
* control, too. So we have to move it back to
* the upper edge of the form.
*--------------------------------------------
IF m.This.Anchor == 0
This.Top = 0
ELSE
lnAnchor = m.This.Anchor
This.Anchor = 0
This.Top = 0
This.Anchor = m.lnAnchor
ENDIF
IF PEMSTATUS( m.This, "_nOriginalTop", 5 )
This._nOriginalTop = 0
ENDIF
*--------------------------------------------
* As we changed the form's height we have to
* center it again if it was centered before.
*--------------------------------------------
IF m.This.lRespectAutoCenter ;
AND m.Thisform.AutoCenter
Thisform.AutoCenter = .T.
ENDIF
*--------------------------------------------
* Cleanup.
*--------------------------------------------
loControl = .NULL.
RELEASE loControl, laControls
ENDPROC
PROCEDURE refreshcaption
*--------------------------------------------
* Setup.
*--------------------------------------------
LOCAL lcCaption
*--------------------------------------------
* Inherit title property or form caption.
*--------------------------------------------
IF NOT EMPTY( m.This.cTitleProperty ) ;
AND TYPE( "m.Thisform." + m.This.cTitleProperty ) == "C"
lcCaption = EVALUATE( "m.Thisform." + m.This.cTitleProperty )
ELSE
lcCaption = ""
ENDIF
IF EMPTY( m.lcCaption )
lcCaption = m.Thisform.Caption
ENDIF
*--------------------------------------------
* Truncate caption if it's too long.
*--------------------------------------------
lcCaption = m.This.TruncateString( m.lcCaption, ;
m.This.lblCaption.Width, ;
m.This.lblCaption.FontName, ;
m.This.lblCaption.FontSize, ;
m.This.lblCaption.FontBold )
*--------------------------------------------
* Set caption.
*--------------------------------------------
This.lblCaption.Caption = m.lcCaption
ENDPROC
PROCEDURE refreshdescription
*--------------------------------------------
* Setup.
*--------------------------------------------
LOCAL lcDescription, lnCaptionAnchor, lnDescriptionAnchor
lcDescription = EVALUATE( "m.Thisform." + m.This.cDescriptionProperty )
*
WITH This
*--------------------------------------------
* We have to cancel anchoring while moving
* controls.
*--------------------------------------------
lnCaptionAnchor = .lblCaption.Anchor
lnDescriptionAnchor = .edtDescription.Anchor
.lblCaption.Anchor = 0
.edtDescription.Anchor = 0
*--------------------------------------------
* Show description if it's set at the form
* level.
*--------------------------------------------
IF EMPTY( m.lcDescription )
.lblCaption.Top = (.Height - .lblCaption.Height) / 2
.edtDescription.Value = ""
ELSE
.edtDescription.Value = m.lcDescription
*--------------------------------------------
* With a two line description we have to move
* the editbox a bit upward to make the second
* line completely visible.
*--------------------------------------------
IF CHR(13) $ m.lcDescription
.lblCaption.Top = 3
.edtDescription.Top = 28
ELSE
.lblCaption.Top = 4
.edtDescription.Top = 31
ENDIF
ENDIF
*--------------------------------------------
* Restore anchoring.
*--------------------------------------------
.lblCaption.Anchor = m.lnCaptionAnchor
.edtDescription.Anchor = m.lnDescriptionAnchor
ENDWITH
ENDPROC
PROCEDURE refreshimage
*--------------------------------------------
* Setup.
*--------------------------------------------
LOCAL lcImage, lnCaptionAnchor, lnDescriptionAnchor
lcImage = EVALUATE( "m.Thisform." + m.This.cImageProperty )
*
WITH This
*--------------------------------------------
* We have to cancel anchoring while moving
* controls.
*--------------------------------------------
lnCaptionAnchor = .lblCaption.Anchor
lnDescriptionAnchor = .edtDescription.Anchor
.lblCaption.Anchor = 0
.edtDescription.Anchor = 0
*--------------------------------------------
* Show title bar image if it's set at the
* form level.
* If there's no title bar image to show, we
* move caption and description to the left.
*--------------------------------------------
IF EMPTY( m.lcImage )
.imgTitle.Visible = .F.
.imgTitle.Picture = ""
.lblCaption.Left = .imgTitle.Left
.lblCaption.Width = .cmdMinimize.Left - .lblCaption.Left + 5
.edtDescription.Left = .imgTitle.Left + 18
ELSE
.imgTitle.Picture = m.lcImage
.imgTitle.Visible = .T.
.lblCaption.Left = .imgTitle.Left * 2 + .imgTitle.Width
.lblCaption.Width = .cmdMinimize.Left - .lblCaption.Left + 5
.edtDescription.Left = .imgTitle.Left * 2 + .imgTitle.Width + 18
ENDIF
*--------------------------------------------
* Restore anchoring.
*--------------------------------------------
.lblCaption.Anchor = m.lnCaptionAnchor
.edtDescription.Anchor = m.lnDescriptionAnchor
ENDWITH
ENDPROC
PROCEDURE truncatestring
LPARAMETERS tcString, tnMaxLength, tcFontName, tnFontSize, tlFontBold
*--------------------------------------------
* Setup.
*--------------------------------------------
LOCAL lcTruncatedString, llEllipsisAdded, lnLen, lcFontBold, lnAvarageCharacterWidth
lcTruncatedString = m.tcString
lcFontBold = IIF( m.tlFontBold, "B", "" )
lnAvarageCharacterWidth = FONTMETRIC( 6, m.tcFontName, m.tnFontSize, m.lcFontBold )
*--------------------------------------------
* Shorten the given string until it's no
* longer than the maximum lenght.
*--------------------------------------------
lnLen = LEN( m.lcTruncatedString )
llEllipsisAdded = .F.
DO WHILE TXTWIDTH( m.lcTruncatedString, m.tcFontName, m.tnFontSize, m.lcFontBold ) * m.lnAvarageCharacterWidth > m.tnMaxLength
*--------------------------------------------
* Cut the string by one character and add an
* ellipsis.
*--------------------------------------------
lnLen = m.lnLen - 1
IF NOT m.llEllipsisAdded
*--------------------------------------------
* First loop.
*--------------------------------------------
lcTruncatedString = LEFT( m.lcTruncatedString, m.lnLen ) + CHR(133)
llEllipsisAdded = .T.
ELSE
*--------------------------------------------
* All further loops.
*--------------------------------------------
lcTruncatedString = LEFT( m.lcTruncatedString, m.lnLen - 1 ) + CHR(133)
ENDIF
ENDDO
*
RETURN m.lcTruncatedString
ENDPROC
[END METHODS]
[START RESERVED1]
Class[END RESERVED1]
[START RESERVED2]
10[END RESERVED2]
[START RESERVED3]
*_isabstract (internal)
*automoveformcontrols
*moveformcontrols
*refreshcaption
*refreshdescription
*refreshimage
*truncatestring
cdescriptionproperty Name of the form property that holds the text for edtDescription (optional)
cimageproperty Name of the form property that holds the name of the picture shown in imgTitle (optional)
csettingsclass Change this to match your derived class!
csettingsclasslib Change this to match your derived class library!
ctitleproperty Name of the form property that holds the text for lblCaption (optional). If not set, Form.Caption is used.
lautomoveformcontrols Move all other controls on the form downward by This.Height. Makes sense when the TitleBar is added to an existing form.
lfixedheight Issue a NODEFAULT in Move(). This prevents mwResize from changing This.Height.
lrespectautocenter If Form.AutoCenter = .T., center the form again after removing the default TitleBar
[END RESERVED3]
[START RESERVED6]
Pixels[END RESERVED6]
[ RECORD]
[PLATFORM] WINDOWS
[UNIQUEID] _48F07AUF6
[CLASS] container
[BASECLASS] container
[OBJNAME] cmdClose
[PARENT] themedtitlebarbase
[START PROPERTIES]
BackColor = 255,255,255
BorderWidth = 0
Height = 21
Left = 271
Name = "cmdClose"
TabStop = .F.
Top = 12
Width = 40
[END PROPERTIES]
[START METHODS]
PROCEDURE Click
*--------------------------------------------
* Double check if the form is allowed to be
* closed by the "X".
*--------------------------------------------
IF NOT m.Thisform.Closable
RETURN
ENDIF
*--------------------------------------------
* If a button is registered to close the form
* we call its code. Otherwise just release
* the form.
*(..)No idea what to do if the form should be
*(..)hidden instead.
*--------------------------------------------
IF m.Thisform.Visible ;
AND VARTYPE( m.Thisform.cCloseButton ) == "C" ;
AND NOT m.Thisform.cCloseButton == ""
LOCAL lcCmd
lcCmd = "m.Thisform." + m.Thisform.cCloseButton + ".Click()"
&lcCmd.
ELSE
m.Thisform.Release()
ENDIF
ENDPROC
PROCEDURE Init
*--------------------------------------------
* Set colors.
*--------------------------------------------
m.This.MouseLeave()
ENDPROC
PROCEDURE MouseEnter
LPARAMETERS tnButton, tnShift, tnXCoord, tnYCoord
*--------------------------------------------
* Start hover effect.
*--------------------------------------------
IF m.Thisform.Closable
This.BackStyle = 1 && Opaque.
This.lblSymbol.ForeColor = RGB( 0, 0, 0 )
ENDIF
ENDPROC
PROCEDURE MouseLeave
LPARAMETERS tnButton, tnShift, tnXCoord, tnYCoord
*--------------------------------------------
* Stop hover effect.
*--------------------------------------------
This.BackStyle = 0 && Transparent.
This.lblSymbol.ForeColor = RGB( 255, 255, 255 )
ENDPROC
PROCEDURE Refresh
*--------------------------------------------
* Disable/Visible as with a TopLevel form
* with title bar.
* Except: If all three system buttons are
* disabled, the close button will be
* invisible, too. The windows default
* behavior is too ugly to keep it.
*--------------------------------------------
WITH Thisform
This.lblSymbol.Enabled = .Closable
This.Visible = .MinButton OR .MaxButton OR .Closable
ENDWITH
ENDPROC
[END METHODS]
[ RECORD]
[PLATFORM] WINDOWS
[UNIQUEID] _48F07AUF7
[CLASS] label
[BASECLASS] label
[OBJNAME] lblSymbol
[PARENT] themedtitlebarbase.cmdClose
[START PROPERTIES]
Alignment = 1
BackStyle = 0
Caption = "r"
FontName = "Marlett"
Height = 14
Left = 13
Name = "lblSymbol"
Top = 5
Width = 14
[END PROPERTIES]
[START METHODS]
PROCEDURE Click
m.This.Parent.Click()
ENDPROC
[END METHODS]
[ RECORD]
[PLATFORM] WINDOWS
[UNIQUEID] _48F07AUF4
[CLASS] container
[BASECLASS] container
[OBJNAME] cmdMaximize
[PARENT] themedtitlebarbase
[START PROPERTIES]
BackColor = 255,255,255
BorderWidth = 0
Height = 20
Left = 238
Name = "cmdMaximize"
TabStop = .F.
Top = 12
Width = 25
[END PROPERTIES]
[START METHODS]
PROCEDURE Click
IF m.Thisform.MaxButton
IF m.Thisform.WindowState == 2 && Maximized.
Thisform.WindowState = 0 && Normal.
ELSE
Thisform.WindowState = 2 && Maximized.
ENDIF
ENDIF
ENDPROC
PROCEDURE Init
*--------------------------------------------
* Set colors.
*--------------------------------------------
m.This.MouseLeave()
ENDPROC
PROCEDURE MouseEnter
LPARAMETERS tnButton, tnShift, tnXCoord, tnYCoord
*--------------------------------------------
* Start hover effect.
*--------------------------------------------
IF m.Thisform.MaxButton
This.BackStyle = 1 && Opaque.
This.lblSymbol.ForeColor = RGB( 0, 0, 0 )
ENDIF
ENDPROC
PROCEDURE MouseLeave
LPARAMETERS tnButton, tnShift, tnXCoord, tnYCoord
*--------------------------------------------
* Stop hover effect.
*--------------------------------------------
This.BackStyle = 0 && Transparent.
This.lblSymbol.ForeColor = RGB( 255, 255, 255 )
ENDPROC
PROCEDURE Refresh
WITH Thisform
*--------------------------------------------
* Disable/Visible as with a TopLevel form
* with title bar.
*--------------------------------------------
This.lblSymbol.Enabled = .MaxButton
This.Visible = .MinButton OR .MaxButton
*--------------------------------------------
* Switch symbol with maximized form.
*--------------------------------------------
IF .WindowState == 2 && Maximized.
This.lblSymbol.Caption = "2" && Restore.
ELSE && Normal.
This.lblSymbol.Caption = "1" && Maximize.
ENDIF
ENDWITH
ENDPROC
[END METHODS]
[ RECORD]
[PLATFORM] WINDOWS
[UNIQUEID] _48F07AUF5
[CLASS] label
[BASECLASS] label
[OBJNAME] lblSymbol
[PARENT] themedtitlebarbase.cmdMaximize
[START PROPERTIES]
Alignment = 1
BackStyle = 0
Caption = "1"
FontBold = .T.
FontName = "Marlett"
Height = 14
Left = 4
Name = "lblSymbol"
Top = 5
Width = 16
[END PROPERTIES]
[START METHODS]
PROCEDURE Click
m.This.Parent.Click()
ENDPROC
[END METHODS]
[ RECORD]
[PLATFORM] WINDOWS
[UNIQUEID] _48F07AUF2
[CLASS] container
[BASECLASS] container
[OBJNAME] cmdMinimize
[PARENT] themedtitlebarbase
[START PROPERTIES]
BackColor = 255,255,255
BorderWidth = 0
Height = 20
Left = 206
Name = "cmdMinimize"
Top = 12
Width = 25
[END PROPERTIES]
[START METHODS]
PROCEDURE Click
IF m.Thisform.MinButton
Thisform.WindowState = 1 && Minimized.
ENDIF
ENDPROC
PROCEDURE Init
*--------------------------------------------
* Set colors.
*--------------------------------------------
m.This.MouseLeave()
ENDPROC
PROCEDURE MouseEnter
LPARAMETERS tnButton, tnShift, tnXCoord, tnYCoord
*--------------------------------------------
* Start hover effect.
*--------------------------------------------
IF m.Thisform.MinButton
This.BackStyle = 1 && Opaque.
This.lblSymbol.ForeColor = RGB( 0, 0, 0 )
ENDIF
ENDPROC
PROCEDURE MouseLeave
LPARAMETERS tnButton, tnShift, tnXCoord, tnYCoord
*--------------------------------------------
* Stop hover effect.
*--------------------------------------------
This.BackStyle = 0 && Transparent.
This.lblSymbol.ForeColor = RGB( 255, 255, 255 )
ENDPROC
PROCEDURE Refresh
*--------------------------------------------
* Disable/Visible as with a TopLevel form
* with title bar.
*--------------------------------------------
WITH Thisform
This.lblSymbol.Enabled = .MinButton
This.Visible = .MinButton OR .MaxButton
ENDWITH
ENDPROC
[END METHODS]