-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathButtonb.prg
More file actions
218 lines (147 loc) · 6.13 KB
/
Buttonb.prg
File metadata and controls
218 lines (147 loc) · 6.13 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
#include "FiveWin.ch"
#define BS_BITMAP 128
#define BM_SETIMAGE 247
#define BM_GETSTATE 0x00F2
#define BS_OWNERDRAW 11
#define BST_PUSHED 0x0004
#define WM_UPDATEUISTATE 0x0128
#ifdef __XPP__
#define Super ::TButton
#define New _New
#endif
//----------------------------------------------------------------------------//
CLASS TButtonBmp FROM TButton
DATA hBitmap
DATA cBitmap
DATA cPosText
DATA lHasAlpha AS LOGICAL INIT .f.
DATA bAlphaLevel
DATA hAlphaLevel
METHOD New( nRow, nCol, cCaption, oWnd, bAction, nWidth, nHeight,;
nHelpId, oFont, lDefault, lPixel, lDesign, cMsg,;
lUpdate, bWhen, bValid, lCancel, cBitmap, cPosText ) CONSTRUCTOR
METHOD ReDefine( nId, bAction, oWnd, nHelpId, cMsg,;
lUpdate, bWhen, bValid, cPrompt, lCancel, cBitmap, cPosText, cToolTip ) CONSTRUCTOR
METHOD HandleEvent( nMsg, nWParam, nLParam )
METHOD KeyDown( nKey, nFlags ) INLINE Super:KeyDown( nKey, nFlags ), ::Refresh()
METHOD LButtonDown( nRow, nCol, nKeyFlags ) INLINE Super:LButtonDown( nRow, nCol, nKeyFlags ), ::Refresh()
METHOD LDblClick( nRow, nCol, nKeyFlags ) INLINE Super:LDblClick( nRow, nCol, nKeyFlags ), ::Refresh()
METHOD LoadBitmap( cBmpName )
if ! SetSkins()
METHOD MouseMove( nRow, nCol, nFlags ) INLINE Super:MouseMove( nRow, nCol, nFlags ), ::oWnd:SetMsg( ::cMsg ), ::Refresh()
METHOD Display() INLINE ::BeginPaint(), ::Paint(), ::EndPaint(), 0
endif
METHOD Destroy() INLINE DeleteObject( ::hBitmap ), Super:Destroy()
METHOD EraseBkGnd( hDC ) INLINE 1
METHOD Paint()
METHOD Enable() INLINE Super:Enable(), ::Refresh()
METHOD Disable() INLINE Super:Disable(), ::Refresh()
METHOD HasAlpha() INLINE ::lHasAlpha := HasAlpha( ::hBitmap )
METHOD nAlphaLevel( nLevel ) SETGET
METHOD SetText( cText ) INLINE Super:SetText( cText ), ::Refresh()
METHOD End()
ENDCLASS
//----------------------------------------------------------------------------//
METHOD New( nRow, nCol, cCaption, oWnd, bAction, nWidth, nHeight,;
nHelpId, oFont, lDefault, lPixel, lDesign, cMsg,;
lUpdate, bWhen, bValid, lCancel, cBitmap, cPosText ) CLASS TButtonBmp
DEFAULT cCaption := "", cPosText := ""
::cBitmap = cBitmap
::hBitmap = If( File( ::cBitmap ), ReadBitmap( 0, ::cBitmap ),;
LoadBitmap( GetResources(), ::cBitmap ) )
::cPosText = Upper( cPosText )
DEFAULT nWidth := nBmpWidth( ::hBitmap ) + 9, nHeight := nBmpHeight( ::hBitmap ) + 9
::HasAlpha()
return Super:New( nRow, nCol, cCaption, oWnd, bAction, nWidth, nHeight,;
nHelpId, oFont, lDefault, lPixel, lDesign, cMsg,;
lUpdate, bWhen, bValid, lCancel, cBitmap )
//----------------------------------------------------------------------------//
METHOD ReDefine( nId, bAction, oWnd, nHelpId, cMsg,;
lUpdate, bWhen, bValid, cPrompt, lCancel, cBitmap, cPosText, cToolTip ) CLASS TButtonBmp
DEFAULT cPrompt := "", cPosText := ""
::cBitmap = cBitmap
::hBitmap = If( File( ::cBitmap ), ReadBitmap( 0, ::cBitmap ),;
LoadBitmap( GetResources(), ::cBitmap ) )
::cPosText = Upper( cPosText )
::cToolTip = cToolTip
::HasAlpha()
return Super:Redefine( nId, bAction, oWnd, nHelpId, cMsg, lUpdate, bWhen,;
bValid, cPrompt, lCancel )
//----------------------------------------------------------------------------//
METHOD LoadBitmap( cBmpName ) CLASS TButtonBmp
if ! Empty( ::hBitmap )
DeleteObject( ::hBitmap )
::hBitmap = nil
endif
::cBitmap = cBmpName
if File( cBmpName )
::hBitmap = ReadBitmap( 0, cBmpName )
else
::hBitmap = LoadBitmap( GetResources(), cBmpName )
endif
::HasAlpha()
return nil
//----------------------------------------------------------------------------//
METHOD Paint() CLASS TButtonBmp
local aInfo
local nTop, nLeft, lPressed
aInfo = ::DispBegin()
CallWindowProc( ::nOldProc, ::hWnd, WM_PAINT, ::hDC, 0 )
lPressed = lAnd( SendMessage( ::hWnd, BM_GETSTATE ), BST_PUSHED )
if ! Empty( ::hBitmap )
if ::cPosText == "TEXTBOTTOM"
nTop = 7
elseif ::cPosText == "TEXTTOP"
nTop = ::nHeight() - 6 - nBmpHeight( ::hBitmap )
else
nTop = ( ::nHeight() / 2 ) - ( nBmpHeight( ::hBitmap ) / 2 )
endif
if ::cPosText == "TEXTRIGHT"
nLeft = 7
elseif ::cPosText == "TEXTLEFT"
nLeft = ::nWidth() - 6 - nBmpWidth( ::hBitmap )
else
nLeft := ( ::nWidth() / 2 ) - ( nBmpWidth( ::hBitmap ) / 2 )
endif
if ::lActive
if SetAlpha() .and. ::lHasAlpha
ABPaint( ::hDC, nLeft + If( lPressed, 1, 0 ), nTop + If( lPressed, 1, 0 ), ::hBitmap, ::nAlphaLevel() )
else
DrawMasked( ::hDC, ::hBitmap, nTop + If( lPressed, 1, 0 ),;
nLeft + If( lPressed, 1, 0 ) )
endif
else
DrawGray( ::hDC, ::hBitmap, nTop + If( lPressed, 1, 0 ),;
nLeft + If( lPressed, 1, 0 ) )
endif
endif
::DispEnd( aInfo )
return 1
//----------------------------------------------------------------------------//
METHOD HandleEvent( nMsg, nWParam, nLParam ) CLASS TButtonBmp
local nResult
do case
case nMsg == WM_UPDATEUISTATE // Buttons were erased when pressing ALT
nResult = Super:HandleEvent( nMsg, nWParam, nLParam )
::Refresh()
return nResult
endcase
return Super:HandleEvent( nMsg, nWParam, nLParam )
//----------------------------------------------------------------------------//
METHOD nAlphaLevel( uNew ) CLASS TButtonBmp
if uNew != NIL
::hAlphaLevel := uNew
else
if ::bAlphaLevel != NIL
::hAlphaLevel = eval( ::bAlphaLevel, Self )
endif
endif
return ::hAlphaLevel
//----------------------------------------------------------------------------//
METHOD End() CLASS TButtonBmp
if !Empty( ::hBitmap )
DeleteObject( ::hBitmap )
::hBitmap = nil
endif
RETURN ( Super:End() )
//----------------------------------------------------------------------------//