-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathsfribbon.vc2
2578 lines (2162 loc) · 80.2 KB
/
sfribbon.vc2
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
*--------------------------------------------------------------------------------------------------------------------------------------------------------
* (ES) AUTOGENERADO - ¡¡ATENCIÓN!! - ¡¡NO PENSADO PARA EJECUTAR!! USAR SOLAMENTE PARA INTEGRAR CAMBIOS Y ALMACENAR CON HERRAMIENTAS SCM!!
* (EN) AUTOGENERATED - ATTENTION!! - NOT INTENDED FOR EXECUTION!! USE ONLY FOR MERGING CHANGES AND STORING WITH SCM TOOLS!!
*--------------------------------------------------------------------------------------------------------------------------------------------------------
*< FOXBIN2PRG: Version="1.20" SourceFile="sfribbon.vcx" CPID="1252" /> (Solo para binarios VFP 9 / Only for VFP 9 binaries)
*
*
DEFINE CLASS sfribbon AS sfribbonbase OF "sfribbon.vcx"
*< CLASSDATA: Baseclass="container" Timestamp="" Scale="Pixels" Uniqueid="" />
*-- OBJECTDATA items order determines ZOrder / El orden de los items OBJECTDATA determina el ZOrder
*< OBJECTDATA: ObjPath="linBottom" UniqueID="" Timestamp="" />
*< OBJECTDATA: ObjPath="Line1" UniqueID="" Timestamp="" />
*< OBJECTDATA: ObjPath="Line2" UniqueID="" Timestamp="" />
*< OBJECTDATA: ObjPath="Line3" UniqueID="" Timestamp="" />
*< OBJECTDATA: ObjPath="Line4" UniqueID="" Timestamp="" />
*< OBJECTDATA: ObjPath="Line5" UniqueID="" Timestamp="" />
*< OBJECTDATA: ObjPath="tmrClick" UniqueID="" Timestamp="" />
*< OBJECTDATA: ObjPath="RibbonDisplayButton" UniqueID="" Timestamp="" />
*< OBJECTDATA: ObjPath="RibbonDisplayButton.imgButton" UniqueID="" Timestamp="" />
*<DefinedPropArrayMethod>
*m: addtab && Adds a tab to the ribbon
*m: adjusttabs && Adjusts the tabs so they align properly
*m: allowshowtabsonly_assign
*m: getlocalizedstring && Gets a localized version of the specified string
*m: gettabs && Returns a collection of tabs
*m: onshowtabsonly && Event raised when lShowTabsOnly is changed
*m: selecttab && Fired when the specified tab is selected
*m: showtabsonly && Display only tabs or the full ribbon
*m: width_assign
*p: allowshowtabsonly && .T. to allow displaying only tabs
*p: cselectedtab && The name of the selected pad
*p: displaytabsonly && .T. if we're displaying tabs only
*p: lclickoutsidemenu && .T. if the user clicked outside a menu
*p: nfullheight && The normal height of the ribbon
*p: tabclass && The default tab class
*p: tablibrary && The default tab library
*p: themes && A collection of theme names
*</DefinedPropArrayMethod>
PROTECTED cselectedtab,nfullheight
*<PropValue>
allowshowtabsonly = .F.
BackColor = 243,242,241
controltype = Tab
cselectedtab =
displaytabsonly = .F.
Height = 130
lclickoutsidemenu = .F.
Name = "sfribbon"
nfullheight = 0
tabclass = SFRibbonTab
tablibrary = SFRibbon.vcx
themes = NULL
type = Ribbon
Width = 450
_memberdata = <VFPData>
<memberdata name="shortcutmenu" display="ShortcutMenu"/>
<memberdata name="showmenu" display="ShowMenu"/>
<memberdata name="omenu" display="oMenu"/>
<memberdata name="addtab" display="AddTab"/>
<memberdata name="adjusttabs" display="AdjustTabs"/>
<memberdata name="gettabs" display="GetTabs"/>
<memberdata name="cselectedtab" display="cSelectedTab"/>
<memberdata name="selecttab" display="SelectTab"/>
<memberdata name="tabclass" display="TabClass"/>
<memberdata name="tablibrary" display="TabLibrary"/>
<memberdata name="themes" display="Themes"/>
<memberdata name="width" display="Width"/>
<memberdata name="width_assign" display="Width_Assign"/>
<memberdata name="showtabsonly" display="ShowTabsOnly"/>
<memberdata name="nfullheight" display="nFullHeight"/>
<memberdata name="onshowtabsonly" display="OnShowTabsOnly"/>
<memberdata name="getlocalizedstring" display="GetLocalizedString"/>
<memberdata name="allowshowtabsonly" display="AllowShowTabsOnly"/>
<memberdata name="allowshowtabsonly_assign" display="AllowShowTabsOnly_Assign"/>
<memberdata name="displaytabsonly" display="DisplayTabsOnly"/>
<memberdata name="lclickoutsidemenu" display="lClickOutsideMenu"/>
</VFPData>
*</PropValue>
ADD OBJECT 'linBottom' AS line WITH ;
BorderColor = 210,208,206, ;
Height = 0, ;
Left = 0, ;
Name = "linBottom", ;
Top = 125, ;
Width = 450
*< END OBJECT: BaseClass="line" />
ADD OBJECT 'Line1' AS line WITH ;
BorderColor = 234,234,234, ;
Height = 0, ;
Left = 0, ;
Name = "Line1", ;
Top = 126, ;
Width = 450
*< END OBJECT: BaseClass="line" />
ADD OBJECT 'Line2' AS line WITH ;
BorderColor = 238,238,238, ;
Height = 0, ;
Left = 0, ;
Name = "Line2", ;
Top = 127, ;
Width = 450
*< END OBJECT: BaseClass="line" />
ADD OBJECT 'Line3' AS line WITH ;
BorderColor = 243,243,243, ;
Height = 0, ;
Left = 0, ;
Name = "Line3", ;
Top = 128, ;
Width = 450
*< END OBJECT: BaseClass="line" />
ADD OBJECT 'Line4' AS line WITH ;
BorderColor = 247,247,247, ;
Height = 0, ;
Left = 0, ;
Name = "Line4", ;
Top = 129, ;
Width = 450
*< END OBJECT: BaseClass="line" />
ADD OBJECT 'Line5' AS line WITH ;
BorderColor = 251,251,251, ;
Height = 0, ;
Left = 0, ;
Name = "Line5", ;
Top = 130, ;
Width = 450
*< END OBJECT: BaseClass="line" />
ADD OBJECT 'RibbonDisplayButton' AS sfribbonbase WITH ;
BackStyle = 0, ;
Height = 16, ;
Left = 430, ;
Name = "RibbonDisplayButton", ;
Top = 105, ;
type = Button, ;
Width = 16
*< END OBJECT: ClassLib="sfribbon.vcx" BaseClass="container" />
ADD OBJECT 'RibbonDisplayButton.imgButton' AS image WITH ;
Height = 16, ;
Name = "imgButton", ;
Picture = sfribbondownlarge.png, ;
Width = 16
*< END OBJECT: BaseClass="image" />
ADD OBJECT 'tmrClick' AS timer WITH ;
Enabled = .F., ;
Height = 23, ;
Interval = 30, ;
Left = 68, ;
Name = "tmrClick", ;
Top = 18, ;
Width = 23
*< END OBJECT: BaseClass="timer" />
PROCEDURE addtab && Adds a tab to the ribbon
*==============================================================================
* Method: AddTab
* Status: Public
* Purpose: Adds a tab to the ribbon
* Author: Doug Hennig
* Last Revision: 12/22/2020
* Parameters: tcName - the name of the tab (optional: if it isn't
* specified, Tab<n> is used
* tcClass - the class for the tab (optional: if it isn't
* specified, the class in This.TabClass is used)
* tcLibrary - the library for the tab class (optional: if it
* isn't specified, the library in This.TabLibrary is
* used)
* Returns: a reference to the new tab
* Environment in: none
* Environment out: a tab was added
*==============================================================================
lparameters tcName, ;
tcClass, ;
tcLibrary
local lcName, ;
lcClass, ;
lcLibrary
* Use defaults if the parameters weren't specified.
lcName = evl(tcName, 'Tab' + transform(This.ControlCount))
lcClass = evl(tcClass, This.TabClass)
lcLibrary = evl(tcLibrary, This.TabLibrary)
* Have AddControl do the work.
return This.AddControl(lcName, lcClass, lcLibrary)
ENDPROC
PROCEDURE adjusttabs && Adjusts the tabs so they align properly
*==============================================================================
* Method: AdjustTabs
* Status: Public
* Purpose: Adjusts the tabs so they align properly
* Author: Doug Hennig
* Last Revision: 12/22/2020
* Parameters: none
* Returns: none
* Environment in: none
* Environment out: the position of the tabs were adjusted
*==============================================================================
local loTabs, ;
lnI, ;
loControl, ;
loPrevTab
This.Controls[1].Left = 0
loTabs = This.GetTabs()
for lnI = 2 to loTabs.Count
loControl = loTabs.Item(lnI)
if pemstatus(loControl, 'Type', 5) and loControl.Type = 'Tab'
loPrevTab = loTabs.Item(lnI - 1)
loControl.Left = loPrevTab.Left + loPrevTab.Width
endif pemstatus(loControl, 'Type', 5) ...
next lnI
ENDPROC
PROCEDURE allowshowtabsonly_assign
lparameters tlAllowShowTabsOnly
This.AllowShowTabsOnly = tlAllowShowTabsOnly
This.RibbonDisplayButton.Visible = tlAllowShowTabsOnly
ENDPROC
PROCEDURE Destroy
* Nuke member objects.
dodefault()
This.Themes = NULL
ENDPROC
PROCEDURE getlocalizedstring && Gets a localized version of the specified string
*==============================================================================
* Method: GetLocalizedString
* Status: Public
* Purpose: Gets a localized version of the specified string
* Author: Doug Hennig
* Last Revision: 04/03/2022
* Parameters: tcString - the string to localize
* Returns: the localized version of the string
* Environment in: none
* Environment out: none
* Note: override this in a subclass as needed
*==============================================================================
lparameters tcString
return tcString
ENDPROC
PROCEDURE gettabs && Returns a collection of tabs
*==============================================================================
* Method: GetTabs
* Status: Public
* Purpose: Returns a collection of tabs
* Author: Doug Hennig
* Last Revision: 12/22/2020
* Parameters: none
* Returns: a collection of tabs
* Environment in: none
* Environment out: none
*==============================================================================
local loTabs, ;
loControl
loTabs = createobject('Collection')
for each loControl in This.Controls foxobject
if pemstatus(loControl, 'Type', 5) and loControl.Type = 'Tab'
loTabs.Add(loControl)
endif pemstatus(loControl, 'Type', 5) ...
next lnI
return loTabs
ENDPROC
PROCEDURE Init
local lnI, ;
lcTheme, ;
lcRibbon
* Match our width to the form.
This.Width = Thisform.Width
This.Anchor = 10
dodefault()
* Create a collection of theme names.
This.Themes = createobject('Collection')
if empty(This.cThemes)
This.Themes.Add('Colorful')
else
for lnI = 1 to occurs('<theme name=', This.cThemes)
lcTheme = strextract(This.cThemes, '<theme name="', '"', lnI, 1)
This.Themes.Add(lcTheme)
next lnI
endif empty(This.cThemes)
* Place the RibbonDisplayButton at the far right and add a menu to show tabs
* only or the full ribbon.
This.RibbonDisplayButton.Left = This.Width - 20
This.RibbonDisplayButton.Visible = This.AllowShowTabsOnly
lcRibbon = 'Thisform.' + This.Name + '.'
This.RibbonDisplayButton.AddBar(This.GetLocalizedString('Show tabs only'), ;
lcRibbon + 'ShowTabsOnly(.T.)', ;
"{iif(" + lcRibbon + "DisplayTabsOnly, 'sfribboncheck.png', '')}")
This.RibbonDisplayButton.AddBar(This.GetLocalizedString('Always show ribbon'), ;
lcRibbon + 'ShowTabsOnly()', ;
"{iif(" + lcRibbon + "DisplayTabsOnly, '', 'sfribboncheck.png')}")
This.nFullHeight = This.Height
* Move to the top of ZOrder so when we redisplay when showing tabs only, we're
* on top of everything else.
This.ZOrder(0)
* Declare the Sleep function.
declare Sleep in Win32API integer nMilliseconds
ENDPROC
PROCEDURE onshowtabsonly && Event raised when lShowTabsOnly is changed
* Event method
lparameters tlShowTabsOnly
ENDPROC
PROCEDURE selecttab && Fired when the specified tab is selected
*==============================================================================
* Method: SelectTab
* Status: Public
* Purpose: Fired when the specified tab is selected
* Author: Doug Hennig
* Last revision: 04/02/2022
* Parameters: toTab - the reference to the selected tab
* Returns: .T.
* Environment in: cSelectedTab contains the name of the formerly selected tab
* Environment out: the toolbar for the formerly selected tab is hidden
* the Selected property for the formerly selected tab is set
* to .F.
* cSelectedTab contains the name of the selected tab
*==============================================================================
* When a tab is selected, deselect the currently selected tab and hide its
* toolbar.
lparameters toTab
local lcOldTab, ;
lcOldToolbar, ;
loOldToolbar, ;
loControl, ;
loParent
lcOldTab = This.cSelectedTab
if not empty(lcOldTab)
This.&lcOldTab..Selected = .F.
lcOldToolbar = lcOldTab + 'Toolbar'
if type('This.' + lcOldToolbar + '.Name') = 'C'
loOldToolbar = This.&lcOldToolbar
loOldToolbar.Visible = .F.
* If one of the controls in the toolbar has focus, hide it or else it'll still
* be visible.
if type('Thisform.ActiveControl.Name') = 'C' and ;
pemstatus(Thisform.ActiveControl, 'Visible', 5)
loControl = Thisform.ActiveControl
loParent = loControl.Parent
do while vartype(loParent) = 'O' and loParent <> loOldToolbar and ;
loParent <> Thisform
loParent = loParent.Parent
enddo while vartype(loParent) = 'O' ...
if vartype(loParent) = 'O' and loParent = loOldToolbar
loControl.Visible = .F.
endif vartype(loParent) = 'O' ...
endif type('Thisform.ActiveControl.Name') = 'C'
endif type('This.' + lcOldToolbar + '.Name') = 'C'
endif not empty(lcOldTab)
This.cSelectedTab = toTab.Name
* If we're displaying tabs only, expand the ribbon to show the toolbar and
* start the timer that checks if the user clicks outside the ribbon.
if This.DisplayTabsOnly
This.ShowTabsOnly(.F., .T.)
This.tmrClick.Enabled = .T.
endif This.DisplayTabsOnly
ENDPROC
PROCEDURE showmenu
lparameters tnRow, ;
tnCol, ;
tcName
dodefault(tnRow, tnCol, 'nothing')
ENDPROC
PROCEDURE showtabsonly && Display only tabs or the full ribbon
*==============================================================================
* Method: ShowTabsOnly
* Status: Public
* Purpose: Display only tabs or the full ribbon
* Author: Doug Hennig
* Last Revision: 04/06/2022
* Parameters: tlShowTabsOnly - .T. to show tabs only
* tlDisplayOnly - .T. if we're being called to update the
* display only
* Returns: none
* Environment in: cSelectedTab contains the name of the selected tab
* nFullHeight contains the normal height of the ribbon
* Environment out: the ribbon height and position of the lines has been
* adjusted and the toolbar for the selected tab has been
* displayed or hidden
* the OnShowTabsOnly event is raised
*==============================================================================
lparameters tlShowTabsOnly, ;
tlDisplayOnly
local lcTab
* Save the setting if we're not just being called to update the display. If we
* are just updated, pause for a bit: needed for multiple timer firing to not
* conflict.
if not tlDisplayOnly
This.DisplayTabsOnly = tlShowTabsOnly
else
Sleep(100)
endif not tlDisplayOnly
* If we're showing tabs only, set the ribbon height to slightly taller than the
* tabs. Otherwise, set it to the normal height.
lcTab = This.cSelectedTab
if tlShowTabsOnly
This.Height = This.&lcTab..Height + 8
This.tmrClick.Enabled = .F.
else
This.Height = This.nFullHeight
endif tlShowTabsOnly
* Move the lines to the bottom of the ribbon.
This.linBottom.Top = This.Height - 5
This.line1.Top = This.Height - 4
This.line2.Top = This.Height - 3
This.line3.Top = This.Height - 2
This.line4.Top = This.Height - 1
This.line5.Top = This.Height
* Show or hide the selected tab's toolbar.
This.&lcTab..Toolbar.Visible = not tlShowTabsOnly
* Raise the OnShowTabsOnly event so the form can do something about it.
if not tlDisplayOnly
raiseevent(This, 'OnShowTabsOnly', tlShowTabsOnly)
endif not tlDisplayOnly
ENDPROC
PROCEDURE theme_assign
lparameters tcTheme
dodefault(tcTheme)
if not empty(This.cThemeColors)
This.BackColor = This.GetThemeColor('ribbonbackcolor')
This.linBottom.BorderColor = This.GetThemeColor('ribbonbordercolor')
This.Line1.BorderColor = This.GetThemeColor('ribbonshadowcolor1')
This.Line2.BorderColor = This.GetThemeColor('ribbonshadowcolor2')
This.Line3.BorderColor = This.GetThemeColor('ribbonshadowcolor3')
This.Line4.BorderColor = This.GetThemeColor('ribbonshadowcolor4')
This.Line5.BorderColor = This.GetThemeColor('ribbonshadowcolor5')
endif not empty(This.cThemeColors)
ENDPROC
PROCEDURE width_assign
lparameters tnWidth
This.Width = tnWidth
store tnWidth to This.linBottom.Width, This.Line1.Width, This.Line2.Width, ;
This.Line3.Width, This.Line4.Width, This.Line5.Width
This.RibbonDisplayButton.Left = tnWidth - 20
ENDPROC
PROCEDURE RibbonDisplayButton.imgButton.Click
This.Parent.ShowMenu()
ENDPROC
PROCEDURE RibbonDisplayButton.MouseEnter
lparameters tnButton, ;
tnShift, ;
tnXCoord, ;
tnYCoord
This.imgButton.BorderStyle = 1
ENDPROC
PROCEDURE RibbonDisplayButton.MouseLeave
lparameters tnButton, ;
tnShift, ;
tnXCoord, ;
tnYCoord
This.imgButton.BorderStyle = 0
ENDPROC
PROCEDURE RibbonDisplayButton.showmenu
* Display the menu below ourselves.
local llInScreen
llInScreen = Thisform.HWnd = _screen.HWnd
*** TODO: the menu isn't quite in the correct position when used in a top-level form
*** but without the IF llInScreen, the timer kills the menu right after it's
*** displayed
*** TODO: if the ribbon is in _SCREEN, the timer kills the menu right after it's displayed
if llInScreen
dodefault(objtoclient(This, 1) + ;
This.Height + Thisform.Top + ;
iif(llInScreen, 0, sysmetric(9) + sysmetric(4)) + ;
iif(Thisform.Desktop or llInScreen, 0, sysmetric(9) + sysmetric(20)), ;
objtoclient(This, 2) + Thisform.Left + iif(llInScreen, 0, sysmetric(3)))
else
dodefault()
endif llInScreen
ENDPROC
PROCEDURE tmrClick.Timer
* If the user clicks outside the ribbon when we're showing tabs only, redisplay
* tabs only.
local llDown, ;
laMouse[1], ;
lnMouse, ;
llClickOutsideRibbon
#define VK_LBUTTON 0x01
declare integer GetAsyncKeyState in user32 integer vKey
llDown = GetAsyncKeyState(VK_LBUTTON) > 0 or mdown()
&& use GetAsyncKeyState because MDOWN() is .F. if click outside form
lnMouse = amouseobj(laMouse, 1)
llClickOutsideRibbon = llDown and (lnMouse = 0 or ;
not between(laMouse[3], This.Parent.Left, This.Parent.Left + This.Parent.Width) or ;
not between(laMouse[4], This.Parent.Top, This.Parent.Top + This.Parent.Height))
if llClickOutsideRibbon
This.Parent.ShowTabsOnly(.T., .T.)
This.Enabled = .F.
endif llClickOutsideRibbon
ENDPROC
ENDDEFINE
DEFINE CLASS sfribbonbase AS container
*< CLASSDATA: Baseclass="container" Timestamp="" Scale="Pixels" Uniqueid="" />
*<DefinedPropArrayMethod>
*m: addbar && Adds a bar to the dropdown menu
*m: addcontrol && Adds a control to the container
*m: enabled_assign
*m: getcolor && Gets the value of the specified color
*m: getthemecolor && Gets the specified color for the current theme
*m: padding_assign
*m: showmenu && Displays a shortcut menu
*m: theme_assign
*p: controltype && The type of control this contains
*p: cthemecolors && The colors for the current theme
*p: cthemes && The XML defining the themes
*p: ogdi && A reference to an SFGDIMeasureString object
*p: padding && The space between the left edge and the first control
*p: theme && The theme to use
*p: type && The type of control this is
*p: _memberdata && XML Metadata for customizable properties
*</DefinedPropArrayMethod>
PROTECTED cthemecolors,cthemes,ogdi
*<PropValue>
BorderWidth = 0
controltype =
cthemecolors =
cthemes =
Enabled = .T.
Height = 65
Name = "sfribbonbase"
ogdi = .NULL.
padding = 0
theme = Colorful
type =
Width = 100
_memberdata = <VFPData>
<memberdata name="showmenu" display="ShowMenu"/>
<memberdata name="ogdi" display="oGDI"/>
<memberdata name="controltype" display="ControlType"/>
<memberdata name="padding" display="Padding"/>
<memberdata name="getcolor" display="GetColor"/>
<memberdata name="padding_assign" display="Padding_Assign"/>
<memberdata name="type" display="Type"/>
<memberdata name="enabled" display="Enabled"/>
<memberdata name="enabled_assign" display="Enabled_Assign"/>
<memberdata name="theme" display="Theme"/>
<memberdata name="theme_assign" display="Theme_Assign"/>
<memberdata name="addcontrol" display="AddControl"/>
<memberdata name="cthemes" display="cThemes"/>
<memberdata name="cthemecolors" display="cThemeColors"/>
<memberdata name="addbar" display="AddBar"/>
<memberdata name="getthemecolor" display="GetThemeColor"/>
</VFPData>
*</PropValue>
PROCEDURE addbar && Adds a bar to the dropdown menu
*==============================================================================
* Method: AddBar
* Status: Public
* Purpose: Adds a bar to the dropdown menu
* Author: Doug Hennig
* Last Revision: 12/27/2020
* Parameters: tcPrompt - the prompt for the bar
* tcCommand - the command to execute
* tcImage - the image for the bar
* tcEnabled - the expression that enables the bar (optional)
* Returns: a reference to the new bar
* Environment in: This.Menu contains an SFRibbonMenu object
* Environment out: a bar was added to the menu
*==============================================================================
lparameters tcPrompt, ;
tcCommand, ;
tcImage, ;
tcEnabled
local loBar
loBar = This.Menu.AddBar(tcPrompt, tcCommand, tcImage, tcEnabled)
return loBar
ENDPROC
PROCEDURE addcontrol && Adds a control to the container
*==============================================================================
* Method: AddControl
* Status: Protected
* Purpose: Adds a control to the container
* Author: Doug Hennig
* Last Revision: 04/03/2022
* Parameters: tcName - the name of the control
* tcClass - the class for the control
* tcLibrary - the library for the control
* Returns: a reference to the new control
* Environment in: none
* Environment out: a control was added
*==============================================================================
lparameters tcName, ;
tcClass, ;
tcLibrary
local lnLeft, ;
lnControls, ;
loControl
* Figure out what position to use.
lnLeft = 0
lnControls = 0
for each loControl in This.Controls foxobject
if pemstatus(loControl, 'Type', 5) and loControl.Type = This.ControlType
lnControls = lnControls + 1
lnLeft = max(lnLeft, loControl.Left + loControl.Width)
endif pemstatus(loControl, 'Type', 5) ...
next loControl
* Add the control and set its properties.
This.NewObject(tcName, tcClass, tcLibrary)
loControl = This.&tcName
with loControl
.Left = max(lnLeft, iif(lnControls = 0, 0, This.Padding))
.Visible = .T.
endwith
return loControl
ENDPROC
PROCEDURE Destroy
* Nuke member objects.
This.oGDI = NULL
loThisform = NULL
ENDPROC
PROCEDURE enabled_assign
lparameters tlEnabled
if This.Enabled <> tlEnabled
This.Enabled = tlEnabled
This.SetAll('Enabled', tlEnabled)
endif This.Enabled <> tlEnabled
ENDPROC
PROCEDURE getcolor && Gets the value of the specified color
*==============================================================================
* Method: GetColor
* Status: Public
* Purpose: Gets the value of the specified color
* Author: Doug Hennig
* Last Revision: 12/25/2020
* Parameters: tuColor - the color as a string (e.g. "255,255,255" or
* "RGB(255, 255, 255)") or a numeric RGB value
* Returns: the color as an RGB value
* Environment in: none
* Environment out: none
*==============================================================================
lparameters tuColor
local lnColor
do case
case vartype(tuColor) = 'N'
lnColor = tuColor
case not ',' $ tuColor
lnColor = val(tuColor)
case upper(left(tuColor, 4)) = 'RGB('
lnColor = evaluate(tuColor)
otherwise
lnColor = evaluate('RGB(' + tuColor + ')')
endcase
return lnColor
ENDPROC
PROCEDURE getthemecolor && Gets the specified color for the current theme
*==============================================================================
* Method: GetThemeColor
* Status: Public
* Purpose: Gets the specified color for the current theme
* Author: Doug Hennig
* Last Revision: 07/23/2023
* Parameters: tcColorName - the name of the color to get
* Returns: the numeric color value for the specified color
* Environment in: This.cThemeColors contains the colors for the current theme
* Environment out: none
*==============================================================================
lparameters tcColorName
local lcColor, ;
lnColor
lcColor = strextract(This.cThemeColors, tcColorName + '="', '"')
lnColor = This.GetColor(lcColor)
return lnColor
ENDPROC
PROCEDURE Init
* Instantiate an SFGDIMeasureString object.
This.oGDI = newobject('SFGDIMeasureString', 'SFGDIMeasureString.prg')
* Create an SFRibbonMenu object.
This.NewObject('Menu', 'SFRibbonMenu', 'SFRibbon.vcx')
* Read in the theme colors.
if file('RibbonThemes.xml')
This.cThemes = filetostr('RibbonThemes.xml')
This.Theme = This.Theme
endif file('RibbonThemes.xml')
ENDPROC
PROCEDURE padding_assign
lparameters tnPadding
This.Padding = tnPadding
ENDPROC
PROCEDURE RightClick
* Display a right-click menu.
This.ShowMenu()
ENDPROC
PROCEDURE showmenu && Displays a shortcut menu
*==============================================================================
* Method: ShowMenu
* Status: Public
* Purpose: Displays a shortcut menu
* Author: Doug Hennig
* Last revision: 04/05/2022
* Parameters: tnRow - the row for the menu (optional: if it isn't
* specified, the mouse position is used)
* tnCol - the column for the menu (optional: if it isn't
* specified, the mouse position is used)
* tcName - the name of the object that fired the menu
* (optional: if it isn't passed, This.Name is used)
* Returns: .T.
* Environment in: This.Menu contains a reference to the menu
* Environment out: a menu was displayed if it has any bars
*==============================================================================
lparameters tnRow, ;
tnCol, ;
tcName
local lnRow, ;
lnCol, ;
lcName
* If the menu is visible, close it.
if This.Menu.Visible
This.Menu.HideMenu()
release loThisform
return
endif This.Menu.Visible
* Put a reference to the form into a variable so we can access it in the
* menu.
if type('loThisform.Name') <> 'C'
public loThisform
loThisform = Thisform
endif type('loThisform.Name') <> 'C'
* Get the row and column to use.
if vartype(tnRow) <> 'N'
lnRow = mrow(0, 3) + Thisform.Top + sysmetric(9) + sysmetric(4) + ;
iif(_screen.Visible, sysmetric(9) + sysmetric(20), 0)
lnCol = mcol(0, 3) + Thisform.Left + sysmetric(3)
else
lnRow = tnRow
lnCol = tnCol
endif vartype(tnRow) <> 'N'
* Display the menu if there are any bars.
if This.Menu.Count > 0
lcName = evl(tcName, This.Name)
This.Menu.ShowMenu(lnRow, lnCol, lcName)
endif This.Menu.Count > 0
ENDPROC
PROCEDURE theme_assign
lparameters tcTheme
local lcColors
lcColors = strextract(This.cThemes, '<theme name="' + tcTheme + '"', ;
'/>', 1, 1)
if not empty(lcColors)
This.Theme = tcTheme
This.cThemeColors = lcColors
This.SetAll('Theme', tcTheme)
This.Menu.Theme = tcTheme
endif not empty(lcColors)
ENDPROC
ENDDEFINE
DEFINE CLASS sfribbonmenu AS custom
*< CLASSDATA: Baseclass="custom" Timestamp="" Scale="Pixels" Uniqueid="" />
*<DefinedPropArrayMethod>
*m: addbar && Adds a bar to the menu
*m: clear && Clears the menu
*m: hidemenu && Hides the menu
*m: showmenu && Displays the menu
*m: visible_access
*p: count && The number of bars in the menu
*p: oform && A reference to an SFRibbonMenuForm object
*p: padding && The spacing to use around bars
*p: theme && The theme to use
*p: visible && .T. if the menu is visible
*p: _memberdata && XML Metadata for customizable properties
*</DefinedPropArrayMethod>
PROTECTED oform
*<PropValue>
count = 0
Name = "sfribbonmenu"
oform = .NULL.
padding = 2
theme = Default
visible = .F.
Width = 17
_memberdata = <VFPData>
<memberdata name="addbar" display="AddBar"/>
<memberdata name="abars[1]" display="aBars[1]"/>
<memberdata name="showmenu" display="ShowMenu"/>
<memberdata name="oform" display="oForm"/>
<memberdata name="count" display="Count"/>
<memberdata name="padding" display="Padding"/>
<memberdata name="visible" display="Visible"/>
<memberdata name="visible_access" display="Visible_Access"/>
<memberdata name="theme" display="Theme"/>
<memberdata name="hidemenu" display="HideMenu"/>
<memberdata name="clear" display="Clear"/>
</VFPData>
*</PropValue>
PROCEDURE addbar && Adds a bar to the menu
*==============================================================================
* Method: AddBar
* Status: Public
* Purpose: Adds a bar to the menu
* Author: Doug Hennig
* Last Revision: 04/03/2022
* Parameters: tcPrompt - the prompt for the bar
* tcCommand - the command to execute
* tcImage - the image for the bar; if it's surrounded with
* curly braces, it's an expression evaluated when the
* menu is dispplayed
* tcEnabled - the expression that enables the bar (optional)
* Returns: a reference to the new bar
* Environment in: none
* Environment out: This.oForm contains a reference to an SFRibbonMenuForm
* object
* a bar was added to the form and Count was incremented
*==============================================================================
lparameters tcPrompt, ;
tcCommand, ;
tcImage, ;
tcEnabled
local lcName, ;
loBar, ;
lcImage
* Create the menu form if it doesn't already exist.
if vartype(This.oForm) <> 'O'
This.oForm = newobject('SFRibbonMenuForm', 'SFRibbon.vcx')
endif vartype(This.oForm) <> 'O'
* Increment the count, assign a name to the bar, and add it to the form.
This.Count = This.Count + 1
lcName = 'Bar' + transform(This.Count)
if empty(tcPrompt)
This.oForm.NewObject(lcName, 'SFRibbonMenuSeparator', 'SFRibbon.vcx')
loBar = This.oForm.&lcName
else
This.oForm.NewObject(lcName, 'SFRibbonMenuBar', 'SFRibbon.vcx')
loBar = This.oForm.&lcName
with loBar
.Caption = tcPrompt
.Command = strtran(evl(tcCommand, ''), 'Thisform', 'loThisform', -1, ;
-1, 1)
&& since the menu bar isn't in the form the ribbon is on,
&& replace any reference to "Thisform" to a variable that contains
&& a reference to the form
* For some reason, Image_Assign is protected so do what that method does.
* .Image = evl(tcImage, '')
lcImage = evl(tcImage, '')
if left(lcImage, 1) = '{'
.cImageExpression = substr(lcImage, 2, len(lcImage) - 2)
else
.imgButton.Picture = lcImage
endif left(lcImage, 1) = '{'
.EnabledExpression = strtran(evl(tcEnabled, ''), 'Thisform', ;
'loThisform', -1, -1, 1)
&& same reason to replace Thisform as above
endwith
endif empty(tcPrompt)
loBar.Visible = .T.
return loBar
ENDPROC
PROCEDURE clear && Clears the menu
*==============================================================================
* Method: Clear
* Status: Public
* Purpose: Clears the menu
* Author: Doug Hennig
* Last Revision: 01/18/2021
* Parameters: none
* Returns: .T.
* Environment in: none
* Environment out: This.oForm is nulled and This.Count is set to 0
*==============================================================================
This.oForm = NULL