-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathCheckbox.prg
More file actions
288 lines (197 loc) · 7 KB
/
Checkbox.prg
File metadata and controls
288 lines (197 loc) · 7 KB
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
#include "FiveWin.Ch"
#include "Constant.ch"
#ifdef __CLIPPER__
#define BM_SETCHECK ( WM_USER + 1 )
#else
#define BM_SETCHECK 241
#endif
#define CB_RESETCONTENT ( WM_USER + 11 )
#define GWL_EXSTYLE (-20)
#define WS_EX_TRANSPARENT 32
#ifdef __XPP__
#define Super ::TControl
#define New _New
#endif
//----------------------------------------------------------------------------//
CLASS TCheckBox FROM TControl
DATA bOldWhen
METHOD New( nRow, nCol, cCaption, bSetGet, oWnd, nWidth, nHeight,;
nHelpTopic, bChange, oFont, bValid, nClrFore, nClrBack,;
lDesign, lPixel, cMsg, lUpdate, bWhen ) CONSTRUCTOR
METHOD ReDefine( nId, bSetGet, oWnd, nHelpId, bChange, bValid,;
nClrFore, nClrBack, cMsg, lUpdate, bWhen ) CONSTRUCTOR
METHOD Click()
METHOD Default()
METHOD cToChar() INLINE Super:cToChar( "CHECKBOX" )
#ifndef __CLIPPER__
METHOD EraseBkGnd( hDC )
METHOD LostFocus( hCtl )
#endif
METHOD Initiate( hDlg ) INLINE Super:Initiate( hDlg ),;
::cCaption := GetWindowText( ::hWnd ),;
::SendMsg( BM_SETCHECK, If( Eval( ::bSetGet ), 1, 0 ) )
METHOD MouseMove( nRow, nCol, nKeyFlags )
METHOD Refresh() INLINE ;
::SendMsg( BM_SETCHECK, If( Eval( ::bSetGet ), 1, 0 ) )
METHOD Reset() INLINE Eval( ::bSetGet,;
If( ValType( Eval( ::bSetGet ) ) == "N", 0, "" ) ),;
::SendMsg( CB_RESETCONTENT )
METHOD cGenPrg()
METHOD Check() INLINE Eval( ::bSetGet, .T. ), ::SendMsg( BM_SETCHECK, 1 )
METHOD UnCheck() INLINE Eval( ::bSetGet, .F. ), ::SendMsg( BM_SETCHECK, 0 )
METHOD SetCheck( lOnOff ) INLINE If( lOnOff, ::Check(), ::UnCheck() )
METHOD SetText( cText )
METHOD HardEnable()
METHOD HardDisable()
ENDCLASS
//----------------------------------------------------------------------------//
METHOD New( nRow, nCol, cCaption, bSetGet, oWnd, nWidth, nHeight, nHelpTopic,;
bChange, oFont, bValid, nClrFore, nClrBack, lDesign, lPixel,;
cMsg, lUpdate, bWhen ) CLASS TCheckBox
#ifdef __XPP__
#undef New
#endif
local lTemp := .f.
DEFAULT nRow := 0, nCol := 0,;
cCaption := "&CheckBox",;
oWnd := GetWndDefault(),;
nWidth := Len( cCaption ) * CHB_CHARPIX_W,;
nHeight := CHB_CHARPIX_H + Int( CHB_CHARPIX_H / 2 ),;
nHelpTopic := 100,;
nClrFore := oWnd:nClrText, nClrBack := oWnd:nClrPane,;
lPixel := .f., lDesign := .f., lUpdate := .f.,;
bSetGet := bSETGET( lTemp )
if ValType( Eval( bSetGet ) ) != "L"
Eval( bSetGet, .f. )
endif
::nTop = nRow * If( lPixel, 1, CHB_CHARPIX_H )
::nLeft = nCol * If( lPixel, 1, CHB_CHARPIX_W )
::nBottom = ::nTop + nHeight
::nRight = ::nLeft + nWidth - If( lPixel, 0, 24 )
::cCaption = cCaption
::nStyle = nOR( WS_CHILD, WS_VISIBLE, BS_AUTOCHECKBOX,;
WS_TABSTOP,;
If( lDesign, WS_CLIPSIBLINGS, 0 ) )
::nId = ::GetNewId()
::nHelpId = nHelpTopic
::bSetGet = bSetGet
::bChange = bChange
::oWnd = oWnd
::oFont = oFont
::bValid = bValid
::lDrag = lDesign
::lCaptured = .f.
::cMsg = cMsg
::lUpdate = lUpdate
::bWhen = bWhen
::SetColor( nClrFore, nClrBack )
if ! Empty( oWnd:hWnd )
::Create( "BUTTON" )
::Default()
oWnd:AddControl( Self )
else
oWnd:DefControl( Self )
endif
if lDesign
::CheckDots()
endif
return Self
//----------------------------------------------------------------------------//
METHOD Click( lValue ) CLASS TCheckBox
DEFAULT lValue := !Eval( ::bSetGet )
if ::bSetGet != nil
Eval( ::bSetGet, lValue )
::Refresh()
endif
if ::bChange != nil
Eval( ::bChange, Eval( ::bSetGet ), Self )
endif
Super:Click() // keep it here, the latest !!!
return ( Self )
//----------------------------------------------------------------------------//
METHOD ReDefine( nId, bSetGet, oWnd, nHelpId, bChange, bValid, nClrFore,;
nClrBack, cMsg, lUpdate, bWhen ) CLASS TCheckBox
DEFAULT oWnd := GetWndDefault(), nClrFore := oWnd:nClrText, nClrBack := oWnd:nClrPane
if ValType( Eval( bSetGet ) ) != "L"
Eval( bSetGet, .f. )
endif
::nId = nId
::bSetGet = bSetGet
::bChange = bChange
::oWnd = oWnd
::nHelpId = nHelpId
::bValid = bValid
::lDrag = .f.
::lCaptured = .f.
::cMsg = cMsg
::lUpdate = lUpdate
::bWhen = bWhen
::SetColor( nClrFore, nClrBack )
oWnd:DefControl( Self )
return Self
//----------------------------------------------------------------------------//
#ifndef __CLIPPER__
METHOD EraseBkGnd( hDC ) CLASS TCheckBox
if IsAppThemed()
return 1
endif
return Super:EraseBkGnd( hDC )
METHOD LostFocus( hCtl ) CLASS TCheckBox
if IsAppThemed()
CheckFocus( ::hWnd, hCtl )
endif
return Super:LostFocus( hCtl )
#endif
//----------------------------------------------------------------------------//
METHOD MouseMove( nRow, nCol, nKeyFlags ) CLASS TCheckBox
if ::lDrag
return Super:MouseMove( nRow, nCol, nKeyFlags )
else
Super:MouseMove( nRow, nCol, nKeyFlags )
endif
return nil // We want standard behavior !!!
//----------------------------------------------------------------------------//
METHOD Default() CLASS TCheckBox
::SendMsg( BM_SETCHECK, If( Eval( ::bSetGet ), 1, 0 ) )
if ::oFont != nil
::SetFont( ::oFont )
else
::SetFont( ::oWnd:oFont )
endif
return nil
//----------------------------------------------------------------------------//
METHOD cGenPRG() CLASS TCheckBox
local cPrg := ""
::CoorsUpdate()
if ::cCaption == nil
::cCaption = GetWindowText( ::hWnd )
endif
cPrg += CRLF + ;
" @ " + LTrim( Str( ::nTop ) ) + ", " + ;
LTrim( Str( ::nLeft ) ) + ;
' CHECKBOX lVar PROMPT "' + ::cCaption + '" SIZE ' + ;
LTrim( Str( ::nRight - ::nLeft + 1 ) ) + ", " + ;
LTrim( Str( ::nBottom - ::nTop + 1 ) ) + ;
" PIXEL OF oWnd " + CRLF
return cPrg
//----------------------------------------------------------------------------//
METHOD SetText( cText ) CLASS TCheckBox
local hDC
#ifndef __CLIPPER__
if IsAppThemed()
DrawPBack( ::hWnd, hDC := GetDC( ::hWnd ) )
ReleaseDC( ::hWnd, hDC )
endif
#endif
SetWindowText( ::hWnd, ::cCaption := cText )
return nil
//----------------------------------------------------------------------------//
Method HardEnable() CLASS TCheckBox
::bWhen := ::bOldWhen
Return ( ::Enable() )
//---------------------------------------------------------------------------//
Method HardDisable() CLASS TCheckBox
::bOldWhen := ::bWhen
::bWhen := {|| .f. }
return ( ::Disable() )
//---------------------------------------------------------------------------//