forked from Irwin1985/VFPStretch
-
Notifications
You must be signed in to change notification settings - Fork 0
/
vfpstretch.prg
181 lines (158 loc) · 4.96 KB
/
vfpstretch.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
*====================================================================
* VfpStretch Class
*====================================================================
Define Class VfpStretch As Custom
nOriginalHeight = 0
nOriginalWidth = 0
oForm = .Null.
Procedure Do
Lparameters toThisform
With This
.oForm = toThisform
If Type(".oForm") != "O"
Messagebox("You must create VfpStretch object inside a form!", 48, "Warning!")
Return .F.
Endif
.oForm.MinHeight = .oForm.Height
.oForm.MinWidth = .oForm.Width
.nOriginalHeight = .oForm.Height
.nOriginalWidth = .oForm.Width
.SaveContainer(.oForm)
=Bindevent(.oForm, "Resize", This, "Stretch", 1)
EndWith
*====================================================================
Procedure ResetSize
With This.oForm
.Height = This.nOriginalHeight
.Width = This.nOriginalWidth
EndWith
*====================================================================
Procedure SaveContainer
Lparameters oContainer
With This
Local oThis
.SaveOriginalSize(m.oContainer)
For Each m.oThis In m.oContainer.Controls
IF m.oThis.Tag <> "NOSTRETCH"
If !m.oThis.BaseClass == 'Custom'
.SaveOriginalSize(m.oThis)
Endif
If Type("m.oThis.Anchor") = "N" And m.oThis.Anchor > 0
m.oThis.Anchor = 0
Endif
Do Case
Case m.oThis.BaseClass == 'Container'
.SaveContainer(m.oThis)
Case m.oThis.BaseClass == 'Pageframe'
Local oPage
For Each oPage In m.oThis.Pages
.SaveContainer(m.oPage)
Endfor
Case m.oThis.BaseClass == 'Grid'
Local oColumn
For Each oColumn In m.oThis.Columns
.SaveOriginalSize(m.oColumn)
Endfor
Case m.oThis.BaseClass $ 'Commandgroup,Optiongroup'
Local oButton
For Each oButton In m.oThis.Buttons
.SaveOriginalSize(m.oButton)
Endfor
ENDCASE
ENDIF
Endfor
EndWith
*====================================================================
Procedure SaveOriginalSize
Lparameters oObject
If Pemstatus(m.oObject, 'Width', 5)
If !Pemstatus(m.oObject, '_nOriginalWidth', 5)
=AddProperty(m.oObject, "_nOriginalWidth", m.oObject.Width)
Endif
If Pemstatus(m.oObject, 'Height', 5)
If !Pemstatus(m.oObject, '_nOriginalHeight', 5)
=AddProperty(m.oObject, "_nOriginalHeight", m.oObject.Height)
Endif
If !Pemstatus(m.oObject, '_nOriginalLeft', 5)
=AddProperty(m.oObject, "_nOriginalLeft", m.oObject.Left)
Endif
If !Pemstatus(m.oObject, '_nOriginalTop', 5)
=AddProperty(m.oObject, "_nOriginalTop", m.oObject.Top)
Endif
Endif
Endif
If Pemstatus(m.oObject, 'Fontsize', 5)
=AddProperty(m.oObject, "_nOriginalFontsize", m.oObject.FontSize)
Endif
If Pemstatus(m.oObject, 'RowHeight', 5)
=AddProperty(m.oObject, "_nOriginalRowheight", m.oObject.RowHeight)
EndIf
*====================================================================
Procedure Stretch
Lparameters oContainer
With This
If Type("oContainer") != "O"
oContainer = .oForm
Endif
Local oThis
If m.oContainer.BaseClass == 'Form'
m.oContainer.LockScreen = .T.
Else
.AdjustSize(m.oContainer)
Endif
For Each m.oThis In m.oContainer.Controls
If !m.oThis.BaseClass == 'Custom'
.AdjustSize(m.oThis)
Endif
Do Case
Case m.oThis.BaseClass == 'Container'
.Stretch(m.oThis)
Case m.oThis.BaseClass == 'Pageframe'
Local oPage
For Each oPage In m.oThis.Pages
.Stretch(m.oPage)
Endfor
Case m.oThis.BaseClass == 'Grid'
Local oColumn
For Each oColumn In m.oThis.Columns
.AdjustSize(m.oColumn)
Endfor
Case m.oThis.BaseClass $ 'Commandgroup,Optiongroup'
Local oButton
For Each oButton In m.oThis.Buttons
.AdjustSize(m.oButton)
Endfor
Endcase
Endfor
If m.oContainer.BaseClass == 'Form'
m.oContainer.LockScreen = .F.
Endif
EndWith
*====================================================================
Procedure AdjustSize
Lparameters oObject
Local nHeightRatio, nWidthRatio
m.nHeightRatio = This.oForm.Height / This.nOriginalHeight
m.nWidthRatio = This.oForm.Width / This.nOriginalWidth
With m.oObject
If Pemstatus(m.oObject, '_nOriginalWidth', 5)
.Width = ._nOriginalWidth * m.nWidthRatio
If Pemstatus(m.oObject, '_nOriginalHeight', 5)
.Height = ._nOriginalHeight * m.nHeightRatio
.Top = ._nOriginalTop * m.nHeightRatio
.Left = ._nOriginalLeft * m.nWidthRatio
Endif
Endif
If Pemstatus(m.oObject, '_nOriginalFontsize', 5)
.FontSize = Max(4, Round(._nOriginalFontsize * ;
IIF(Abs(m.nHeightRatio) < Abs(m.nWidthRatio), m.nHeightRatio, m.nWidthRatio), 0))
Endif
If Pemstatus(m.oObject, '_nOriginalRowheight', 5)
.RowHeight = ._nOriginalRowheight * m.nHeightRatio
Endif
If .BaseClass == 'Control' And Pemstatus(m.oObject, 'RepositionContents', 5)
.RepositionContents()
Endif
EndWith
*====================================================================
Enddefine