-
Notifications
You must be signed in to change notification settings - Fork 3
/
vfpstretch.prg
277 lines (260 loc) · 8.58 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
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
define class vfpStretch as Custom
*========================================================================*
* Function Init
*========================================================================*
Function Init
If Type('_screen.CurrentZoom') = 'U'
=AddProperty(_screen, 'CurrentZoom', 0)
EndIf
EndFunc
Function Do(toThisform)
local lcPropName as String
lcPropName = sys(2015)
=AddProperty(toThisform, lcPropName, createobject("Stretcher"))
toThisform. &lcPropName..Do(toThisform)
Endfunc
enddefine
*====================================================================
* Stretcher Class
*====================================================================
Define Class Stretcher As Custom
nOriginalHeight = 0
nOriginalWidth = 0
oForm = .Null.
*========================================================================*
* function Do
*========================================================================*
Function Do(toThisform)
With This
.oForm = toThisform
If Type(".oForm") != 'O'
.oForm = Iif(Type('_Screen.ActiveForm') == 'O', _Screen.ActiveForm, .Null.)
If Isnull(.oForm)
Messagebox("You must create VfpStretch object inside a form!", 48, "Warning!")
Return .F.
Endif
Endif
* IRODG 2024-07-19: allow forms to be reduces up to 25% of their original size
.oForm.MinHeight = .oForm.Height/4
.oForm.MinWidth = .oForm.Width/4
* IRODG 2024-07-19: allow forms to be reduces up to 25% of their original size
.nOriginalHeight = .oForm.Height
.nOriginalWidth = .oForm.Width
.SaveContainer(.oForm)
=Bindevent(.oForm, "Resize", This, "Stretch", 1)
.Zoom()
Endwith
Endfunc
*========================================================================*
* Function ResetSize
*========================================================================*
Function ResetSize
With This.oForm
.Height = This.nOriginalHeight
.Width = This.nOriginalWidth
Endwith
Endfunc
*========================================================================*
* Function SaveContainer
*========================================================================*
Function 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
Case m.oThis.BaseClass == 'Listbox'
.SaveOriginalSize(m.oThis)
Endcase
Endif
Endfor
Endwith
Endfunc
*========================================================================*
* Function SaveOriginalSize
*========================================================================*
Function 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
* Support for listboxes with columnWidths
If m.oObject.BaseClass == 'Listbox' And !Empty(m.oObject.ColumnWidths)
If !Pemstatus(m.oObject, '_nOriginalColumnWidths', 5)
=AddProperty(m.oObject, "_nOriginalColumnWidths", m.oObject.ColumnWidths)
Endif
Endif
Endfunc
*========================================================================*
* Function Stretch
*========================================================================*
Function 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
Case m.oThis.BaseClass == 'Listbox'
.AdjustSize(m.oThis)
Endcase
Endfor
If m.oContainer.BaseClass == 'Form'
m.oContainer.LockScreen = .F.
Endif
Endwith
Endfunc
*========================================================================*
* Function AdjustSize
*========================================================================*
Function 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
* support for listboxes with columnWidths
If .BaseClass == 'Listbox' And !Empty(.ColumnWidths) AND PEMSTATUS(m.oObject, '_nOriginalWidth', 5) AND PEMSTATUS(m.oObject, '_nOriginalColumnWidths', 5)
*_nOriginalColumnWidths
Local lnWidth, lcWidths, lnCalculatedWidth, lnOriginalRate, lnIndex
lnWidth = .Width
lcWidths = ''
lnCalculatedWidth = 0
lnOriginalRate = 0
lnIndex = 0
If lnWidth <> ._nOriginalWidth
For lnIndex = 1 To Getwordcount(._nOriginalColumnWidths, ',')
lnOriginalRate = Val(Getwordnum(._nOriginalColumnWidths, lnIndex, ',')) / ._nOriginalWidth * 100
lnCalculatedWidth = Int(lnOriginalRate * lnWidth / 100)
If Empty(lcWidths)
lcWidths = Alltrim(Str(lnCalculatedWidth))
Else
lcWidths = lcWidths + ',' + Alltrim(Str(lnCalculatedWidth))
Endif
Endfor
If !Empty(lcWidths)
.ColumnWidths = lcWidths
Endif
Endif
EndIf
* end
EndWith
Endfunc
*========================================================================*
* Function Zoom
*========================================================================*
Function Zoom
local loForm
loForm = this.oForm
If Type('_screen.CurrentZoom') == 'N' and Type('loForm') = 'O'
Do Case
Case _Screen.CurrentZoom > 0 And _Screen.CurrentZoom < 100
*-- Width
nDisp = _Screen.Width - loForm.MinWidth
nWidth = Int(nDisp * (_Screen.CurrentZoom / 100))
loForm.Width = loForm.MinWidth + nWidth
*-- Height
nScrHei = _Screen.Height - 25
nDisp = nScrHei - loForm.MinHeight
nHeight = Int(nDisp * (_Screen.CurrentZoom / 100))
loForm.Height = loForm.MinHeight + nHeight
Case _Screen.CurrentZoom = 100
loForm.WindowState = 2
Otherwise
*-- Normal (Zoom = 0)
loForm.Width = loForm.MinWidth
loForm.Height = loForm.MinHeight
Endcase
loForm.AutoCenter = .T.
Endif
Endfunc
Enddefine