1 /***********************************************************
2 * K O U L E S *
3 *----------------------------------------------------------*
4 * C1995 JAHUSOFT *
5 * Jan Hubicka *
6 * Dukelskych Bojovniku 1944 *
7 * 390 03 Tabor *
8 * Czech Republic *
9 * Telefon: (048-I think) (0361) 32613 *
10 * eMail: hubicka@limax.paru.cas.cz *
11 *----------------------------------------------------------*
12 * Copyright(c)1996 by Thomas A. K. Kjaer *
13 * See README for license details. *
14 *----------------------------------------------------------*
15 * newbuttons.c New animated button-class for OS/2 Koules *
16 ***********************************************************/
17 #define ID_TIMER 1
18
19 static HPOINTER hIcon[16];
20 static ULONG ulIconIdx = 0;
21 static ULONG ulIconMax = 2;
22
23
24 typedef struct
25 {
26 BOOL fHaveCapture ;
27 BOOL fHaveFocus ;
28 BOOL fInsideRect ;
29 BOOL fSpaceDown ;
30 }
31 NEWBTN ;
32
33 typedef NEWBTN *PNEWBTN ;
34
35 MRESULT EXPENTRY NewBtnWndProc (HWND, ULONG, MPARAM, MPARAM) ;
36
RegisterNewBtnClass(HAB hab)37 BOOL APIENTRY RegisterNewBtnClass (HAB hab)
38 {
39 return WinRegisterClass (hab, "NewBtn", NewBtnWndProc,
40 CS_SIZEREDRAW, sizeof (PNEWBTN)) ;
41 }
42
NewBtnWndProc(HWND hwnd,ULONG msg,MPARAM mp1,MPARAM mp2)43 MRESULT EXPENTRY NewBtnWndProc (HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
44 {
45 BOOL fTestInsideRect ;
46 HPS hps ;
47 POINTL ptl ;
48 NEWBTN *pNewBtn ;
49 RECTL rcl ;
50
51 pNewBtn = WinQueryWindowPtr (hwnd, 0) ;
52
53 switch (msg)
54 {
55 case WM_CREATE:
56 pNewBtn = malloc (sizeof (NEWBTN)) ;
57
58 pNewBtn->fHaveCapture = FALSE ;
59 pNewBtn->fHaveFocus = FALSE ;
60 pNewBtn->fInsideRect = FALSE ;
61 pNewBtn->fSpaceDown = FALSE ;
62
63 WinSetWindowPtr(hwnd, 0, pNewBtn) ;
64
65 WinStartTimer(hab, hwnd, ID_TIMER, 333);
66
67 hps = WinBeginPaint(hwnd, NULLHANDLE, NULL);
68 hIcon[0] = WinLoadPointer(HWND_DESKTOP, 0, ID_KOULES);
69 hIcon[1] = WinLoadPointer(HWND_DESKTOP, 0, ID_KOULES2);
70 WinEndPaint(hps);
71
72 return 0 ;
73
74 case WM_SETWINDOWPARAMS:
75
76 return MRFROMSHORT (1) ;
77
78 case WM_QUERYWINDOWPARAMS:
79
80 return MRFROMSHORT (1) ;
81
82 case WM_BUTTON1DOWN:
83 WinSetFocus (HWND_DESKTOP, hwnd) ;
84 WinSetCapture (HWND_DESKTOP, hwnd) ;
85 pNewBtn->fHaveCapture = TRUE ;
86 pNewBtn->fInsideRect = TRUE ;
87 WinInvalidateRect (hwnd, NULL, FALSE) ;
88 return 0 ;
89
90 case WM_MOUSEMOVE:
91 if (!pNewBtn->fHaveCapture)
92 break ;
93
94 WinQueryWindowRect (hwnd, &rcl) ;
95 ptl.x = MOUSEMSG(&msg)->x ;
96 ptl.y = MOUSEMSG(&msg)->y ;
97
98 fTestInsideRect = WinPtInRect (WinQueryAnchorBlock (hwnd),
99 &rcl, &ptl) ;
100
101 hps = WinBeginPaint(hwnd, NULLHANDLE, NULL);
102 if (pNewBtn->fInsideRect != fTestInsideRect)
103 {
104 pNewBtn->fInsideRect = fTestInsideRect ;
105 WinInvalidateRect (hwnd, NULL, FALSE) ;
106 }
107 WinEndPaint(hps);
108
109 break ;
110
111 case WM_BUTTON1UP:
112 if (!pNewBtn->fHaveCapture)
113 break ;
114
115 WinSetCapture (HWND_DESKTOP, NULLHANDLE) ;
116 pNewBtn->fHaveCapture = FALSE ;
117 pNewBtn->fInsideRect = FALSE ;
118
119 WinQueryWindowRect (hwnd, &rcl) ;
120 ptl.x = MOUSEMSG(&msg)->x ;
121 ptl.y = MOUSEMSG(&msg)->y ;
122
123 if (WinPtInRect (WinQueryAnchorBlock (hwnd), &rcl, &ptl))
124 WinPostMsg (WinQueryWindow (hwnd, QW_OWNER),
125 WM_COMMAND,
126 MPFROMSHORT (WinQueryWindowUShort (hwnd, QWS_ID)),
127 MPFROM2SHORT (CMDSRC_OTHER, TRUE)) ;
128
129 WinInvalidateRect (hwnd, NULL, FALSE) ;
130 return 0 ;
131
132 case WM_ENABLE:
133 WinInvalidateRect (hwnd, NULL, FALSE) ;
134 return 0 ;
135
136 case WM_SETFOCUS:
137 pNewBtn->fHaveFocus = SHORT1FROMMP (mp2) ;
138 WinInvalidateRect (hwnd, NULL, FALSE) ;
139 return 0 ;
140
141 case WM_CHAR:
142 if (!(CHARMSG(&msg)->fs & KC_VIRTUALKEY) ||
143 CHARMSG(&msg)->vkey != VK_SPACE ||
144 CHARMSG(&msg)->fs & KC_PREVDOWN)
145 break ;
146
147 if (!(CHARMSG(&msg)->fs & KC_KEYUP))
148 pNewBtn->fSpaceDown = TRUE ;
149 else
150 {
151 pNewBtn->fSpaceDown = FALSE ;
152 WinPostMsg (WinQueryWindow (hwnd, QW_OWNER),
153 WM_COMMAND,
154 MPFROMSHORT (WinQueryWindowUShort (hwnd, QWS_ID)),
155 MPFROM2SHORT (CMDSRC_OTHER, FALSE)) ;
156 }
157 WinInvalidateRect (hwnd, NULL, FALSE) ;
158 return 0 ;
159
160 case WM_TIMER:
161 WinInvalidateRect (hwnd, NULL, FALSE);
162 if (++ulIconIdx == ulIconMax) ulIconIdx = 0;
163
164 return 0;
165
166 case WM_PAINT:
167
168 hps = WinBeginPaint(hwnd, NULLHANDLE, NULL);
169 if (pNewBtn->fInsideRect || pNewBtn->fSpaceDown)
170 /* WinDrawPointer(hps, 0, 0, hIcon[ulIconIdx], DP_INVERTED) */;
171 else
172 WinDrawPointer(hps, 0, 0, hIcon[ulIconIdx], DP_NORMAL);
173 WinEndPaint(hps);
174
175 return 0 ;
176
177 case WM_DESTROY:
178 free (pNewBtn);
179 WinDestroyPointer(hIcon[0]);
180 WinDestroyPointer(hIcon[1]);
181 WinStopTimer(hab, hwnd, ID_TIMER);
182 WinEndPaint(hps);
183 return 0;
184 }
185 return WinDefWindowProc (hwnd, msg, mp1, mp2) ;
186 }
187