1 |
|
---|
2 | /*
|
---|
3 | *@@sourcefile comctl.c:
|
---|
4 | * contains various window procedures for implementing
|
---|
5 | * common controls. The source file name has nothing to do
|
---|
6 | * with the Windoze DLL of the same name.
|
---|
7 | *
|
---|
8 | * Usage: All PM programs.
|
---|
9 | *
|
---|
10 | * Function prefixes (new with V0.81):
|
---|
11 | * -- ctl* common control helper functions
|
---|
12 | *
|
---|
13 | * The functionality of this code is accessed with the use
|
---|
14 | * of a special helper function. Sometimes that function
|
---|
15 | * registers a new window class, sometimes a static control
|
---|
16 | * needs to be subclassed. See the respective functions for
|
---|
17 | * details.
|
---|
18 | *
|
---|
19 | * In detail, we have:
|
---|
20 | *
|
---|
21 | * -- a "menu button" control, which displays a menu when
|
---|
22 | * pressed (see ctlMakeMenuButton for details);
|
---|
23 | *
|
---|
24 | * -- progress bar support (see ctlProgressBarFromStatic for
|
---|
25 | * details);
|
---|
26 | *
|
---|
27 | * -- a "chart" control for displaying pie charts (all new
|
---|
28 | * with V0.9.0; see ctlChartFromStatic for details);
|
---|
29 | *
|
---|
30 | * -- split windows support (all new with V0.9.0; see
|
---|
31 | * ctlCreateSplitWindow for details);
|
---|
32 | *
|
---|
33 | * -- a subclassed static control for enhanced bitmap and
|
---|
34 | * and icon display (see ctl_fnwpBitmapStatic for details).
|
---|
35 | * This used to be in animate.c and has been enhanced
|
---|
36 | * with V0.9.0;
|
---|
37 | *
|
---|
38 | * -- a "tooltip" control, which shows fly-over ("bubble")
|
---|
39 | * help over any window, including controls. This is
|
---|
40 | * largely API-compatible with the Win95 tooltip control.
|
---|
41 | * See ctl_fnwpTooltip for details;
|
---|
42 | *
|
---|
43 | * -- a "checkbox container" control, which is a subclassed
|
---|
44 | * container which uses checkboxes as record icons.
|
---|
45 | * See ctlMakeCheckboxContainer for details.
|
---|
46 | *
|
---|
47 | * Note: Version numbering in this file relates to XWorkplace version
|
---|
48 | * numbering.
|
---|
49 | *
|
---|
50 | *@@header "helpers\comctl.h"
|
---|
51 | */
|
---|
52 |
|
---|
53 | /*
|
---|
54 | * Copyright (C) 1997-2000 Ulrich Mller.
|
---|
55 | * This file is part of the "XWorkplace helpers" source package.
|
---|
56 | * This is free software; you can redistribute it and/or modify
|
---|
57 | * it under the terms of the GNU General Public License as published
|
---|
58 | * by the Free Software Foundation, in version 2 as it comes in the
|
---|
59 | * "COPYING" file of the XWorkplace main distribution.
|
---|
60 | * This program is distributed in the hope that it will be useful,
|
---|
61 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
62 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
63 | * GNU General Public License for more details.
|
---|
64 | */
|
---|
65 |
|
---|
66 | #define OS2EMX_PLAIN_CHAR
|
---|
67 | // this is needed for "os2emx.h"; if this is defined,
|
---|
68 | // emx will define PSZ as _signed_ char, otherwise
|
---|
69 | // as unsigned char
|
---|
70 |
|
---|
71 | #define INCL_DOSEXCEPTIONS
|
---|
72 | #define INCL_DOSPROCESS
|
---|
73 | #define INCL_DOSSEMAPHORES
|
---|
74 | #define INCL_DOSERRORS
|
---|
75 |
|
---|
76 | #define INCL_WINWINDOWMGR
|
---|
77 | #define INCL_WINFRAMEMGR
|
---|
78 | #define INCL_WINMESSAGEMGR
|
---|
79 | #define INCL_WININPUT
|
---|
80 | #define INCL_WINPOINTERS
|
---|
81 | #define INCL_WINTRACKRECT
|
---|
82 | #define INCL_WINTIMER
|
---|
83 | #define INCL_WINSYS
|
---|
84 |
|
---|
85 | #define INCL_WINRECTANGLES /// xxx temporary
|
---|
86 |
|
---|
87 | #define INCL_WINMENUS
|
---|
88 | #define INCL_WINSTATICS
|
---|
89 | #define INCL_WINBUTTONS
|
---|
90 | #define INCL_WINSTDCNR
|
---|
91 |
|
---|
92 | #define INCL_GPIPRIMITIVES
|
---|
93 | #define INCL_GPILOGCOLORTABLE
|
---|
94 | #define INCL_GPILCIDS
|
---|
95 | #define INCL_GPIPATHS
|
---|
96 | #define INCL_GPIREGIONS
|
---|
97 | #define INCL_GPIBITMAPS // added V0.9.1 (2000-01-04) [umoeller]: needed for EMX headers
|
---|
98 | #include <os2.h>
|
---|
99 |
|
---|
100 | #include <stdlib.h>
|
---|
101 | #include <stdio.h>
|
---|
102 | #include <string.h>
|
---|
103 | #include <setjmp.h> // needed for except.h
|
---|
104 | #include <assert.h> // needed for except.h
|
---|
105 |
|
---|
106 | #include "setup.h" // code generation and debugging options
|
---|
107 |
|
---|
108 | #include "helpers\cnrh.h"
|
---|
109 | #include "helpers\except.h" // exception handling
|
---|
110 | #include "helpers\gpih.h"
|
---|
111 | #include "helpers\linklist.h"
|
---|
112 | #include "helpers\winh.h"
|
---|
113 |
|
---|
114 | #include "helpers\comctl.h"
|
---|
115 |
|
---|
116 | #pragma hdrstop
|
---|
117 |
|
---|
118 | /* ******************************************************************
|
---|
119 | *
|
---|
120 | * "XButton" control
|
---|
121 | *
|
---|
122 | ********************************************************************/
|
---|
123 |
|
---|
124 | /*
|
---|
125 | *@@ ctlPaintXButton:
|
---|
126 | * paints an X-button control. Can be called externally
|
---|
127 | * for just painting a button even if this is not really
|
---|
128 | * a window.
|
---|
129 | *
|
---|
130 | * WARNING: this is work in progress and will change into
|
---|
131 | * the future. Eventually this will turn into a full
|
---|
132 | * button control replacement.
|
---|
133 | *
|
---|
134 | *@@added V0.9.13 (2001-06-21) [umoeller]
|
---|
135 | *@@changed V0.9.16 (2001-10-24) [umoeller]: fixed wrong hatch color and paint offset
|
---|
136 | *@@changed V0.9.16 (2001-10-28) [umoeller]: added bitmap support, fixed bad clip rectangle
|
---|
137 | */
|
---|
138 |
|
---|
139 | VOID ctlPaintXButton(HPS hps, // in: presentation space (RGB mode)
|
---|
140 | ULONG fl, // in: XBF_* flags
|
---|
141 | PXBUTTONDATA pxbd) // in: button data
|
---|
142 | {
|
---|
143 | ULONG ulBorder = 0,
|
---|
144 | cx,
|
---|
145 | cy,
|
---|
146 | ulOfs = 0;
|
---|
147 | LONG lLeft,
|
---|
148 | lRight;
|
---|
149 | RECTL rclWin;
|
---|
150 | memcpy(&rclWin, &pxbd->rcl, sizeof(RECTL));
|
---|
151 |
|
---|
152 | if (0 == (fl & XBF_FLAT))
|
---|
153 | ulBorder = 2;
|
---|
154 |
|
---|
155 | gpihSwitchToRGB(hps);
|
---|
156 |
|
---|
157 | if (fl & XBF_PRESSED)
|
---|
158 | {
|
---|
159 | // paint button "down":
|
---|
160 | lLeft = pxbd->lcol3DDark;
|
---|
161 | lRight = pxbd->lcol3DLight;
|
---|
162 | // add offset for icon painting at the bottom
|
---|
163 | ulOfs += 1;
|
---|
164 | if (ulBorder == 0)
|
---|
165 | ulBorder = 1;
|
---|
166 | }
|
---|
167 | else
|
---|
168 | {
|
---|
169 | lLeft = pxbd->lcol3DLight;
|
---|
170 | lRight = pxbd->lcol3DDark;
|
---|
171 | }
|
---|
172 |
|
---|
173 | if (ulBorder)
|
---|
174 | {
|
---|
175 | // button border:
|
---|
176 | // now paint button frame
|
---|
177 |
|
---|
178 | // make rcl inclusive
|
---|
179 | rclWin.xRight--;
|
---|
180 | rclWin.yTop--;
|
---|
181 | gpihDraw3DFrame(hps,
|
---|
182 | &rclWin, // inclusive
|
---|
183 | ulBorder,
|
---|
184 | lLeft,
|
---|
185 | lRight);
|
---|
186 |
|
---|
187 | // now paint button middle
|
---|
188 | rclWin.xLeft += ulBorder;
|
---|
189 | rclWin.yBottom += ulBorder;
|
---|
190 | rclWin.xRight -= ulBorder - 1; // make exclusive again
|
---|
191 | rclWin.yTop -= ulBorder - 1; // make exclusive again
|
---|
192 | }
|
---|
193 |
|
---|
194 | if (fl & XBF_BACKGROUND)
|
---|
195 | WinFillRect(hps,
|
---|
196 | &rclWin, // exclusive
|
---|
197 | pxbd->lMiddle);
|
---|
198 |
|
---|
199 | // get icon
|
---|
200 | if (pxbd->hptr)
|
---|
201 | {
|
---|
202 | // calculate x and y to be centered in rectangle
|
---|
203 | POINTL ptl;
|
---|
204 |
|
---|
205 | cx = rclWin.xRight - rclWin.xLeft;
|
---|
206 | cy = rclWin.yTop - rclWin.yBottom;
|
---|
207 |
|
---|
208 | ptl.x = rclWin.xLeft + ((cx - pxbd->cxIconOrBitmap) / 2);
|
---|
209 | ptl.y = rclWin.yBottom + ((cy - pxbd->cyIconOrBitmap) / 2);
|
---|
210 |
|
---|
211 | if (fl & XBF_INUSE)
|
---|
212 | {
|
---|
213 | // caller wants in-use (hatched) emphasis:
|
---|
214 | // draw a box then
|
---|
215 | POINTL ptl2;
|
---|
216 | ptl2.x = ptl.x - 2;
|
---|
217 | ptl2.y = ptl.y - 2;
|
---|
218 | GpiMove(hps,
|
---|
219 | &ptl2); // &ptl
|
---|
220 | // duh, typo V0.9.16 (2001-10-24) [umoeller]
|
---|
221 | GpiSetPattern(hps, PATSYM_DIAG1);
|
---|
222 | GpiSetColor(hps, RGBCOL_BLACK); // V0.9.16 (2001-10-24) [umoeller]
|
---|
223 | ptl2.x = ptl.x + pxbd->cxIconOrBitmap + 1; // inclusive!
|
---|
224 | ptl2.y = ptl.y + pxbd->cyIconOrBitmap + 1; // inclusive!
|
---|
225 | GpiBox(hps,
|
---|
226 | DRO_FILL,
|
---|
227 | &ptl2,
|
---|
228 | 0,
|
---|
229 | 0);
|
---|
230 | }
|
---|
231 |
|
---|
232 | // now paint icon
|
---|
233 |
|
---|
234 | // make rcl inclusive // V0.9.16 (2001-10-28) [umoeller]
|
---|
235 | rclWin.xRight--;
|
---|
236 | rclWin.yTop--;
|
---|
237 | GpiIntersectClipRectangle(hps,
|
---|
238 | &rclWin); // inclusive!
|
---|
239 |
|
---|
240 | // center this in remaining rectl
|
---|
241 | ptl.x += ulOfs;
|
---|
242 | ptl.y -= ulOfs;
|
---|
243 | if (fl & XBF_BITMAP)
|
---|
244 | // V0.9.16 (2001-10-28) [umoeller]
|
---|
245 | WinDrawBitmap(hps,
|
---|
246 | pxbd->hptr, // a bitmap really
|
---|
247 | NULL, // entire bitmap
|
---|
248 | &ptl,
|
---|
249 | 0,
|
---|
250 | 0,
|
---|
251 | DBM_NORMAL);
|
---|
252 | else
|
---|
253 | WinDrawPointer(hps,
|
---|
254 | // center this in remaining rectl
|
---|
255 | ptl.x + ulOfs,
|
---|
256 | ptl.y - ulOfs,
|
---|
257 | pxbd->hptr,
|
---|
258 | DP_MINI);
|
---|
259 | }
|
---|
260 | }
|
---|
261 |
|
---|
262 | /*
|
---|
263 | *@@category: Helpers\PM helpers\Window classes\Menu buttons
|
---|
264 | * See comctl.c and ctlMakeMenuButton.
|
---|
265 | */
|
---|
266 |
|
---|
267 | /* ******************************************************************
|
---|
268 | *
|
---|
269 | * "Menu button" control
|
---|
270 | *
|
---|
271 | ********************************************************************/
|
---|
272 |
|
---|
273 | /*
|
---|
274 | *@@ MENUBUTTONDATA:
|
---|
275 | * internal data for "menu button"
|
---|
276 | *
|
---|
277 | *@@added V0.9.0 [umoeller]
|
---|
278 | */
|
---|
279 |
|
---|
280 | typedef struct _MENUBUTTONDATA
|
---|
281 | {
|
---|
282 | PFNWP pfnwpButtonOriginal;
|
---|
283 | HMODULE hmodMenu;
|
---|
284 | ULONG idMenu;
|
---|
285 | BOOL fMouseCaptured, // TRUE if WinSetCapture
|
---|
286 | fMouseButton1Down, // TRUE in between WM_BUTTON1DOWN and WM_BUTTON1UP
|
---|
287 | fButtonSunk; // toggle state of the button
|
---|
288 | HWND hwndMenu;
|
---|
289 | } MENUBUTTONDATA, *PMENUBUTTONDATA;
|
---|
290 |
|
---|
291 | /*
|
---|
292 | *@@ ctlDisplayButtonMenu:
|
---|
293 | * displays the specified menu above the button.
|
---|
294 | *
|
---|
295 | *@@added V0.9.7 (2000-11-29) [umoeller]
|
---|
296 | */
|
---|
297 |
|
---|
298 | VOID ctlDisplayButtonMenu(HWND hwndButton,
|
---|
299 | HWND hwndMenu)
|
---|
300 | {
|
---|
301 | SWP swpButton;
|
---|
302 | POINTL ptlMenu;
|
---|
303 | WinQueryWindowPos(hwndButton, &swpButton);
|
---|
304 | ptlMenu.x = swpButton.x;
|
---|
305 | ptlMenu.y = swpButton.y;
|
---|
306 |
|
---|
307 | // ptlMenu now has button coordinates
|
---|
308 | // relative to the button's parent;
|
---|
309 | // convert this to screen coordinates:
|
---|
310 | WinMapWindowPoints(WinQueryWindow(hwndButton, QW_PARENT),
|
---|
311 | HWND_DESKTOP,
|
---|
312 | &ptlMenu,
|
---|
313 | 1);
|
---|
314 |
|
---|
315 | // now show the menu on top of the button
|
---|
316 | WinPopupMenu(HWND_DESKTOP, // menu parent
|
---|
317 | hwndButton, // owner
|
---|
318 | hwndMenu,
|
---|
319 | (SHORT)(ptlMenu.x),
|
---|
320 | (SHORT)(ptlMenu.y + swpButton.cy - 1),
|
---|
321 | 0, // ID
|
---|
322 | PU_NONE
|
---|
323 | | PU_MOUSEBUTTON1
|
---|
324 | | PU_KEYBOARD
|
---|
325 | | PU_HCONSTRAIN
|
---|
326 | | PU_VCONSTRAIN);
|
---|
327 | }
|
---|
328 |
|
---|
329 | /*
|
---|
330 | *@@ ctl_fnwpSubclassedMenuButton:
|
---|
331 | * subclassed window proc for "menu button".
|
---|
332 | * See ctlMakeMenuButton for details.
|
---|
333 | *
|
---|
334 | *@@added V0.9.0 [umoeller]
|
---|
335 | *@@changed V0.9.2 (2000-02-28) [umoeller]: menu was displayed even if button was disabled; fixed
|
---|
336 | *@@changed V0.9.14 (2001-07-31) [umoeller]: fixed WM_MENUEND submenu quirk
|
---|
337 | */
|
---|
338 |
|
---|
339 | MRESULT EXPENTRY ctl_fnwpSubclassedMenuButton(HWND hwndButton, ULONG msg, MPARAM mp1, MPARAM mp2)
|
---|
340 | {
|
---|
341 | MRESULT mrc = 0;
|
---|
342 | PMENUBUTTONDATA pmbd = (PMENUBUTTONDATA)WinQueryWindowULong(hwndButton, QWL_USER);
|
---|
343 |
|
---|
344 | switch (msg)
|
---|
345 | {
|
---|
346 | /*
|
---|
347 | * WM_BUTTON1DOWN:
|
---|
348 | * WM_BUTTON1UP:
|
---|
349 | * these show/hide the menu.
|
---|
350 | *
|
---|
351 | * Showing the menu follows these steps:
|
---|
352 | * a) first WM_BUTTON1DOWN hilites the button;
|
---|
353 | * b) first WM_BUTTON1UP shows the menu.
|
---|
354 | *
|
---|
355 | * When the button is pressed again, the open
|
---|
356 | * menu loses focus, which results in WM_MENUEND
|
---|
357 | * and destroys the window automatically.
|
---|
358 | */
|
---|
359 |
|
---|
360 | case WM_BUTTON1DOWN:
|
---|
361 | case WM_BUTTON1DBLCLK:
|
---|
362 | // only do this if the button is enabled
|
---|
363 | // V0.9.2 (2000-02-28) [umoeller]
|
---|
364 | if (WinIsWindowEnabled(hwndButton))
|
---|
365 | {
|
---|
366 | // _Pmpf(("WM_BUTTON1DOWN"));
|
---|
367 | // since we're not passing the message
|
---|
368 | // to WinDefWndProc, we need to give
|
---|
369 | // ourselves the focus
|
---|
370 | WinSetFocus(HWND_DESKTOP, hwndButton);
|
---|
371 |
|
---|
372 | if (!pmbd->fMouseCaptured)
|
---|
373 | {
|
---|
374 | // capture mouse events while the
|
---|
375 | // mouse button is down
|
---|
376 | WinSetCapture(HWND_DESKTOP, hwndButton);
|
---|
377 | pmbd->fMouseCaptured = TRUE;
|
---|
378 | }
|
---|
379 |
|
---|
380 | pmbd->fMouseButton1Down = TRUE;
|
---|
381 |
|
---|
382 | if (!pmbd->fButtonSunk)
|
---|
383 | {
|
---|
384 | // button not hilited yet (first click):
|
---|
385 | // do it now
|
---|
386 | // _Pmpf((" Sinking menu WM_BUTTON1DOWN "));
|
---|
387 | pmbd->fButtonSunk = TRUE;
|
---|
388 | WinSendMsg(hwndButton,
|
---|
389 | BM_SETHILITE,
|
---|
390 | (MPARAM)TRUE,
|
---|
391 | (MPARAM)0);
|
---|
392 | }
|
---|
393 |
|
---|
394 | // else: the menu has just been destroyed
|
---|
395 | // (WM_MENUEND below)
|
---|
396 | }
|
---|
397 |
|
---|
398 | mrc = (MPARAM)TRUE; // message processed
|
---|
399 | break;
|
---|
400 |
|
---|
401 | /*
|
---|
402 | * WM_BUTTON1UP:
|
---|
403 | *
|
---|
404 | */
|
---|
405 |
|
---|
406 | case WM_BUTTON1UP:
|
---|
407 | // only do this if the button is enabled
|
---|
408 | // V0.9.2 (2000-02-28) [umoeller]
|
---|
409 | if (WinIsWindowEnabled(hwndButton))
|
---|
410 | {
|
---|
411 | // _Pmpf(("WM_BUTTON1UP sunk %d hwndMenu 0x%lX", pmbd->fButtonSunk, pmbd->hwndMenu));
|
---|
412 |
|
---|
413 | // un-capture the mouse first
|
---|
414 | if (pmbd->fMouseCaptured)
|
---|
415 | {
|
---|
416 | WinSetCapture(HWND_DESKTOP, NULLHANDLE);
|
---|
417 | pmbd->fMouseCaptured = FALSE;
|
---|
418 | }
|
---|
419 |
|
---|
420 | pmbd->fMouseButton1Down = FALSE;
|
---|
421 |
|
---|
422 | if ( (pmbd->fButtonSunk) // set by WM_BUTTON1DOWN above
|
---|
423 | && (pmbd->hwndMenu) // menu currently showing
|
---|
424 | )
|
---|
425 | {
|
---|
426 | // button currently depressed:
|
---|
427 | // un-hilite button
|
---|
428 | // _Pmpf((" Unsinking menu WM_BUTTON1UP 1"));
|
---|
429 | pmbd->fButtonSunk = FALSE;
|
---|
430 | WinSendMsg(hwndButton,
|
---|
431 | BM_SETHILITE,
|
---|
432 | (MPARAM)FALSE,
|
---|
433 | (MPARAM)0);
|
---|
434 | }
|
---|
435 | else
|
---|
436 | {
|
---|
437 | // first button up:
|
---|
438 | // show menu
|
---|
439 |
|
---|
440 | if (pmbd->idMenu)
|
---|
441 | {
|
---|
442 | // _Pmpf((" Loading menu hmod %lX id %lX", pmbd->hmodMenu, pmbd->idMenu));
|
---|
443 | // menu specified: load from
|
---|
444 | // specified resources
|
---|
445 | pmbd->hwndMenu = WinLoadMenu(hwndButton,
|
---|
446 | pmbd->hmodMenu,
|
---|
447 | pmbd->idMenu);
|
---|
448 | }
|
---|
449 | else
|
---|
450 | {
|
---|
451 | HWND hwndOwner = WinQueryWindow(hwndButton, QW_OWNER);
|
---|
452 | // _Pmpf((" Querying menu WM_COMMAND from owner 0x%lX", hwndOwner));
|
---|
453 | // send WM_COMMAND to owner
|
---|
454 | pmbd->hwndMenu
|
---|
455 | = (HWND)WinSendMsg(hwndOwner,
|
---|
456 | WM_COMMAND,
|
---|
457 | (MPARAM)(ULONG)WinQueryWindowUShort(hwndButton,
|
---|
458 | QWS_ID),
|
---|
459 | (MPARAM)0);
|
---|
460 | }
|
---|
461 |
|
---|
462 | // _Pmpf((" Loaded menu, hwnd: 0x%lX", pmbd->hwndMenu));
|
---|
463 |
|
---|
464 | if (pmbd->hwndMenu)
|
---|
465 | {
|
---|
466 | // menu successfully loaded:
|
---|
467 | // find out where to put it
|
---|
468 | ctlDisplayButtonMenu(hwndButton,
|
---|
469 | pmbd->hwndMenu);
|
---|
470 | } // end if (pmbd->hwndMenu)
|
---|
471 | else
|
---|
472 | {
|
---|
473 | // menu not loaded:
|
---|
474 | // _Pmpf((" Unsinking menu WM_BUTTON1UP 2"));
|
---|
475 | pmbd->fButtonSunk = FALSE;
|
---|
476 | WinSendMsg(hwndButton,
|
---|
477 | BM_SETHILITE,
|
---|
478 | (MPARAM)FALSE,
|
---|
479 | (MPARAM)0);
|
---|
480 | }
|
---|
481 | }
|
---|
482 | }
|
---|
483 |
|
---|
484 | mrc = (MPARAM)TRUE; // message processed
|
---|
485 | break;
|
---|
486 |
|
---|
487 | /*
|
---|
488 | * WM_BUTTON1CLICK:
|
---|
489 | * swallow this
|
---|
490 | */
|
---|
491 |
|
---|
492 | case WM_BUTTON1CLICK:
|
---|
493 | mrc = (MPARAM)TRUE;
|
---|
494 | break;
|
---|
495 |
|
---|
496 | /*
|
---|
497 | * WM_SETFOCUS:
|
---|
498 | * swallow this, the button keeps painting
|
---|
499 | * itself otherwise
|
---|
500 | */
|
---|
501 |
|
---|
502 | case WM_SETFOCUS:
|
---|
503 | break;
|
---|
504 |
|
---|
505 | /*
|
---|
506 | * WM_MENUEND:
|
---|
507 | * menu is destroyed; we get this
|
---|
508 | * because we're the owner
|
---|
509 | */
|
---|
510 |
|
---|
511 | case WM_MENUEND:
|
---|
512 | if ((HWND)mp2 == pmbd->hwndMenu) // V0.9.14 (2001-07-31) [umoeller]
|
---|
513 | {
|
---|
514 | BOOL fUnHilite = TRUE;
|
---|
515 | // _Pmpf(("WM_MENUEND"));
|
---|
516 | // At this point, the menu has been
|
---|
517 | // destroyed already.
|
---|
518 | // Since WM_BUTTON1UP handles the
|
---|
519 | // default case that the user presses
|
---|
520 | // the menu button a second time while
|
---|
521 | // the menu is open, we only need
|
---|
522 | // to handle the case that the user
|
---|
523 | // c) presses some key on the menu (ESC, menu selection) or
|
---|
524 | // a) selects a menu item (which
|
---|
525 | // dismisses the menu) or
|
---|
526 | // b) clicks anywhere else.
|
---|
527 |
|
---|
528 | // Case a) if mouse button 1 is not currently down
|
---|
529 | if ((WinGetKeyState(HWND_DESKTOP, VK_BUTTON1) & 0x8000) == 0)
|
---|
530 | // button 1 _not_ down:
|
---|
531 | // must be keyboard
|
---|
532 | fUnHilite = TRUE;
|
---|
533 | else
|
---|
534 | // button 1 _is_ down:
|
---|
535 | // query window under mouse pointer
|
---|
536 | ;
|
---|
537 |
|
---|
538 | if (fUnHilite)
|
---|
539 | {
|
---|
540 | // _Pmpf((" Unsinking menu WM_MENUEND"));
|
---|
541 | pmbd->fButtonSunk = FALSE;
|
---|
542 | WinSendMsg(hwndButton,
|
---|
543 | BM_SETHILITE,
|
---|
544 | (MPARAM)FALSE,
|
---|
545 | (MPARAM)0);
|
---|
546 | }
|
---|
547 | pmbd->hwndMenu = NULLHANDLE;
|
---|
548 | } // end if ((HWND)mp1 == pmbd->pmbd->hwndMenu) // V0.9.14 (2001-07-31) [umoeller]
|
---|
549 | break;
|
---|
550 |
|
---|
551 | /*
|
---|
552 | * WM_COMMAND:
|
---|
553 | * this must be from the menu, so
|
---|
554 | * forward this to the button's owner
|
---|
555 | */
|
---|
556 |
|
---|
557 | case WM_COMMAND:
|
---|
558 | WinPostMsg(WinQueryWindow(hwndButton, QW_OWNER),
|
---|
559 | msg,
|
---|
560 | mp1,
|
---|
561 | mp2);
|
---|
562 | break;
|
---|
563 |
|
---|
564 | /*
|
---|
565 | * WM_DESTROY:
|
---|
566 | * clean up allocated data
|
---|
567 | */
|
---|
568 |
|
---|
569 | case WM_DESTROY:
|
---|
570 | mrc = pmbd->pfnwpButtonOriginal(hwndButton, msg, mp1, mp2);
|
---|
571 | free(pmbd);
|
---|
572 | break;
|
---|
573 |
|
---|
574 | default:
|
---|
575 | mrc = pmbd->pfnwpButtonOriginal(hwndButton, msg, mp1, mp2);
|
---|
576 | }
|
---|
577 |
|
---|
578 | return mrc;
|
---|
579 | }
|
---|
580 |
|
---|
581 | /*
|
---|
582 | *@@ ctlMakeMenuButton:
|
---|
583 | * this turns the specified button into a "menu button",
|
---|
584 | * which shows a popup menu when the button is depressed.
|
---|
585 | * This is done by subclassing the menu button with
|
---|
586 | * ctl_fnwpSubclassedMenuButton.
|
---|
587 | *
|
---|
588 | * Simply call this function upon any button, and it'll
|
---|
589 | * turn in to a menu button.
|
---|
590 | *
|
---|
591 | * When the user presses the button, the specified menu
|
---|
592 | * is loaded from the resources. The button will then
|
---|
593 | * be set as the owner, but it will forward all WM_COMMAND
|
---|
594 | * messages from the menu to its own owner (probably your
|
---|
595 | * dialog), so you can handle WM_COMMAND messages just as
|
---|
596 | * if the menu was owned by your dialog.
|
---|
597 | *
|
---|
598 | * Alternatively, if you don't want to load a menu from
|
---|
599 | * the resources, you can specify idMenu == 0. In that case,
|
---|
600 | * when the menu button is pressed, it sends (!) a WM_COMMAND
|
---|
601 | * message to its owner with its ID in mp1 (as usual). The
|
---|
602 | * difference is that the return value from that message will
|
---|
603 | * be interpreted as a menu handle (HWND) to use for the button
|
---|
604 | * menu.
|
---|
605 | *
|
---|
606 | * The subclassed button also handles menu destruction etc.
|
---|
607 | * by itself.
|
---|
608 | *
|
---|
609 | *@@added V0.9.0 [umoeller]
|
---|
610 | */
|
---|
611 |
|
---|
612 | BOOL ctlMakeMenuButton(HWND hwndButton, // in: button to subclass
|
---|
613 | HMODULE hmodMenu, // in: resource module (can be NULLHANDLE for
|
---|
614 | // current EXE)
|
---|
615 | ULONG idMenu) // in: resource menu ID (or 0)
|
---|
616 | {
|
---|
617 | BOOL brc = FALSE;
|
---|
618 | PMENUBUTTONDATA pmbd;
|
---|
619 | if (pmbd = (PMENUBUTTONDATA)malloc(sizeof(MENUBUTTONDATA)))
|
---|
620 | {
|
---|
621 | memset(pmbd, 0, sizeof(MENUBUTTONDATA));
|
---|
622 | if (pmbd->pfnwpButtonOriginal = WinSubclassWindow(hwndButton,
|
---|
623 | ctl_fnwpSubclassedMenuButton))
|
---|
624 | {
|
---|
625 | pmbd->hmodMenu = hmodMenu;
|
---|
626 | pmbd->idMenu = idMenu;
|
---|
627 | WinSetWindowULong(hwndButton, QWL_USER, (ULONG)pmbd);
|
---|
628 | brc = TRUE;
|
---|
629 | }
|
---|
630 | else
|
---|
631 | free(pmbd);
|
---|
632 | }
|
---|
633 | return brc;
|
---|
634 | }
|
---|
635 |
|
---|
636 | /*
|
---|
637 | *@@category: Helpers\PM helpers\Window classes\Static bitmaps
|
---|
638 | * See comctl.c and ctl_fnwpBitmapStatic.
|
---|
639 | */
|
---|
640 |
|
---|
641 | /* ******************************************************************
|
---|
642 | *
|
---|
643 | * Subclassed Static Bitmap Control
|
---|
644 | *
|
---|
645 | ********************************************************************/
|
---|
646 |
|
---|
647 | /*
|
---|
648 | *@@ ctl_fnwpBitmapStatic:
|
---|
649 | * subclassed wnd proc for both static controls which
|
---|
650 | * should display icons and stretched bitmaps.
|
---|
651 | *
|
---|
652 | * This is not a stand-alone window procedure, but must only
|
---|
653 | * be used with static controls subclassed by the functions
|
---|
654 | * listed below.
|
---|
655 | *
|
---|
656 | * This is now (V0.9.0) used in two contexts:
|
---|
657 | * -- when subclassed from ctlPrepareStaticIcon,
|
---|
658 | * this displays transparent icons properly
|
---|
659 | * (for regular icons or icon animations);
|
---|
660 | * -- when subclassed from ctlPrepareStretchedBitmap,
|
---|
661 | * this displays a stretched bitmap.
|
---|
662 | *
|
---|
663 | * The behavior depends on ANIMATIONDATA.ulFlags,
|
---|
664 | * which is set by both of these functions (either to
|
---|
665 | * ANF_ICON or ANF_BITMAP).
|
---|
666 | *
|
---|
667 | * Only one msg is of interest to the "user" application
|
---|
668 | * of this control, which is SM_SETHANDLE,
|
---|
669 | * the normal message sent to a static icon control to change
|
---|
670 | * its icon or bitmap.
|
---|
671 | * The new handle (HPOINTER or HBITMAP) is
|
---|
672 | * in mp1; mp2 must be null.
|
---|
673 | *
|
---|
674 | * Depending on ANIMATIONDATA.ulFlags, we do the following:
|
---|
675 | *
|
---|
676 | * -- ANF_ICON: Unfortunately, the
|
---|
677 | * standard static control paints garbage if
|
---|
678 | * the icons contain transparent areas, and the
|
---|
679 | * display often flickers too.
|
---|
680 | * We improve this by creating one bitmap from
|
---|
681 | * the icon that we were given which we can then
|
---|
682 | * simply copy to the screen in one step in
|
---|
683 | * WM_PAINT.
|
---|
684 | *
|
---|
685 | * -- ANF_BITMAP: we create a bitmap which is
|
---|
686 | * stretched to the size of the static control,
|
---|
687 | * using gpihStretchBitmap.
|
---|
688 | *
|
---|
689 | * In any case, a new bitmap is produced internally and
|
---|
690 | * stored so that it can easily be painted when WM_PAINT
|
---|
691 | * comes in. The source icon/bitmap can therefore
|
---|
692 | * be safely destroyed by the caller after sending
|
---|
693 | * SM_SETHANDLE. This bitmap is automatically deleted when
|
---|
694 | * the window is destroyed.
|
---|
695 | *
|
---|
696 | *@@changed V0.9.0 [umoeller]: function renamed
|
---|
697 | *@@changed V0.9.0 [umoeller]: added support for stretched bitmaps
|
---|
698 | *@@changed V0.9.0 [umoeller]: added halftoned display for WS_DISABLED
|
---|
699 | *@@changed V0.9.0 [umoeller]: exported gpihIcon2Bitmap function to gpih.c
|
---|
700 | *@@changed V0.9.0 [umoeller]: fixed paint errors when SM_SETHANDLE had NULL argument in mp1
|
---|
701 | *@@changed V0.9.16 (2001-10-15) [umoeller]: now centering icon in static properly
|
---|
702 | *@@changed V0.9.16 (2001-10-15) [umoeller]: this always used the presparam colors of the parent instead of its own ones
|
---|
703 | */
|
---|
704 |
|
---|
705 | MRESULT EXPENTRY ctl_fnwpBitmapStatic(HWND hwndStatic, ULONG msg, MPARAM mp1, MPARAM mp2)
|
---|
706 | {
|
---|
707 | PANIMATIONDATA pa = (PANIMATIONDATA)WinQueryWindowULong(hwndStatic, QWL_USER);
|
---|
708 | // animation data which was stored in window words
|
---|
709 |
|
---|
710 | PFNWP OldStaticProc = NULL;
|
---|
711 | MRESULT mrc = NULL;
|
---|
712 |
|
---|
713 | if (pa)
|
---|
714 | {
|
---|
715 | OldStaticProc = pa->OldStaticProc;
|
---|
716 |
|
---|
717 | switch(msg)
|
---|
718 | {
|
---|
719 | /*
|
---|
720 | * WM_TIMER:
|
---|
721 | * this timer is started by the ctl* funcs
|
---|
722 | * below. Proceed to the next animation step.
|
---|
723 | *
|
---|
724 | * Note: this timer is only used with
|
---|
725 | * ANF_ICON, and even then, it
|
---|
726 | * is not necessarily running.
|
---|
727 | */
|
---|
728 |
|
---|
729 | case WM_TIMER:
|
---|
730 | pa->usAniCurrent++;
|
---|
731 | if (pa->usAniCurrent >= pa->usAniCount)
|
---|
732 | pa->usAniCurrent = 0;
|
---|
733 |
|
---|
734 | WinSendMsg(hwndStatic,
|
---|
735 | SM_SETHANDLE,
|
---|
736 | (MPARAM)pa->ahptrAniIcons[pa->usAniCurrent],
|
---|
737 | (MPARAM)NULL);
|
---|
738 | break;
|
---|
739 |
|
---|
740 | /*
|
---|
741 | * SM_SETHANDLE:
|
---|
742 | *
|
---|
743 | */
|
---|
744 |
|
---|
745 | case SM_SETHANDLE:
|
---|
746 | {
|
---|
747 | HDC hdcMem;
|
---|
748 | HPS hpsMem;
|
---|
749 | SIZEL szlPage;
|
---|
750 |
|
---|
751 | LONG lBkgndColor
|
---|
752 | /* = winhQueryPresColor(WinQueryWindow(hwndStatic, QW_PARENT),
|
---|
753 | PP_BACKGROUNDCOLOR,
|
---|
754 | FALSE,
|
---|
755 | SYSCLR_DIALOGBACKGROUND); */
|
---|
756 | // fixed this... V0.9.16 (2001-10-15) [umoeller]
|
---|
757 | = winhQueryPresColor(hwndStatic,
|
---|
758 | PP_BACKGROUNDCOLOR,
|
---|
759 | TRUE,
|
---|
760 | SYSCLR_DIALOGBACKGROUND);
|
---|
761 |
|
---|
762 | HPS hps = WinGetPS(hwndStatic);
|
---|
763 |
|
---|
764 | // if we have created bitmaps previously, delete them
|
---|
765 | if (pa->hbm)
|
---|
766 | {
|
---|
767 | GpiDeleteBitmap(pa->hbm);
|
---|
768 | pa->hbm = NULLHANDLE;
|
---|
769 | }
|
---|
770 | if (pa->hbmHalftoned)
|
---|
771 | {
|
---|
772 | GpiDeleteBitmap(pa->hbmHalftoned);
|
---|
773 | pa->hbmHalftoned = NULLHANDLE;
|
---|
774 | }
|
---|
775 |
|
---|
776 | // switch to RGB mode
|
---|
777 | gpihSwitchToRGB(hps);
|
---|
778 |
|
---|
779 | // create a memory PS
|
---|
780 | szlPage.cx = pa->rclIcon.xRight - pa->rclIcon.xLeft;
|
---|
781 | szlPage.cy = pa->rclIcon.yTop - pa->rclIcon.yBottom;
|
---|
782 | if (gpihCreateMemPS(pa->hab,
|
---|
783 | &szlPage,
|
---|
784 | &hdcMem,
|
---|
785 | &hpsMem))
|
---|
786 | {
|
---|
787 | // switch the memory PS to RGB mode too
|
---|
788 | gpihSwitchToRGB(hpsMem);
|
---|
789 |
|
---|
790 | // create a suitable bitmap w/ the size of the
|
---|
791 | // static control
|
---|
792 | if ( ((pa->hbm = gpihCreateBitmap(hpsMem,
|
---|
793 | szlPage.cx,
|
---|
794 | szlPage.cy)))
|
---|
795 | // associate the bit map with the memory PS
|
---|
796 | && (GpiSetBitmap(hpsMem, pa->hbm) != HBM_ERROR)
|
---|
797 | )
|
---|
798 | {
|
---|
799 | // fill the bitmap with the current static
|
---|
800 | // background color
|
---|
801 | POINTL ptl = {0, 0};
|
---|
802 | GpiMove(hpsMem, &ptl);
|
---|
803 | ptl.x = pa->rclIcon.xRight;
|
---|
804 | ptl.y = pa->rclIcon.yTop;
|
---|
805 | GpiSetColor(hpsMem,
|
---|
806 | lBkgndColor);
|
---|
807 | GpiBox(hpsMem,
|
---|
808 | DRO_FILL, // interior only
|
---|
809 | &ptl,
|
---|
810 | 0, 0); // no corner rounding
|
---|
811 |
|
---|
812 | /*
|
---|
813 | * ANF_ICON:
|
---|
814 | *
|
---|
815 | */
|
---|
816 |
|
---|
817 | if (pa->ulFlags & ANF_ICON)
|
---|
818 | {
|
---|
819 | // store new icon in our own structure
|
---|
820 | if (pa->hptr = (HPOINTER)mp1)
|
---|
821 | {
|
---|
822 | // center the icon in the bitmap
|
---|
823 | // V0.9.16 (2001-10-15) [umoeller]
|
---|
824 | POINTL ptlOfs;
|
---|
825 | ptlOfs.x = ( (pa->rclIcon.xRight - pa->rclIcon.xLeft)
|
---|
826 | - pa->lIconSize
|
---|
827 | ) / 2;
|
---|
828 | ptlOfs.y = ( (pa->rclIcon.yTop - pa->rclIcon.yBottom)
|
---|
829 | - pa->lIconSize
|
---|
830 | ) / 2;
|
---|
831 |
|
---|
832 | // paint icon into bitmap
|
---|
833 | gpihIcon2Bitmap(hpsMem,
|
---|
834 | pa->hptr,
|
---|
835 | lBkgndColor,
|
---|
836 | &ptlOfs,
|
---|
837 | pa->lIconSize);
|
---|
838 | }
|
---|
839 |
|
---|
840 | } // end if (pa->ulFlags & ANF_ICON)
|
---|
841 |
|
---|
842 | /*
|
---|
843 | * ANF_BITMAP:
|
---|
844 | *
|
---|
845 | */
|
---|
846 |
|
---|
847 | else if (pa->ulFlags & ANF_BITMAP)
|
---|
848 | {
|
---|
849 | // store passed bitmap
|
---|
850 | HBITMAP hbmSource;
|
---|
851 | if (hbmSource = (HBITMAP)mp1)
|
---|
852 | gpihStretchBitmap(hpsMem, // target
|
---|
853 | hbmSource, // source
|
---|
854 | NULL, // use size of bitmap
|
---|
855 | &pa->rclIcon,
|
---|
856 | ((pa->ulFlags & ANF_PROPORTIONAL)
|
---|
857 | != 0));
|
---|
858 |
|
---|
859 | } // end if (pa->ulFlags & ANF_BITMAP)
|
---|
860 |
|
---|
861 | } // end if (GpiSetBitmap(...
|
---|
862 | // && (pa->hbm = gpihCreateBitmap(hpsMem, &(pa->rclIcon)))
|
---|
863 |
|
---|
864 | // in any case, clean up now
|
---|
865 | GpiDestroyPS(hpsMem);
|
---|
866 | DevCloseDC(hdcMem);
|
---|
867 | } // end if (gpihCreateMemPS(hab, &hdcMem, &hpsMem))
|
---|
868 |
|
---|
869 | WinReleasePS(hps);
|
---|
870 |
|
---|
871 | // enforce WM_PAINT
|
---|
872 | WinInvalidateRect(hwndStatic, NULL, FALSE);
|
---|
873 | }
|
---|
874 | break;
|
---|
875 |
|
---|
876 | /*
|
---|
877 | * WM_PAINT:
|
---|
878 | * "normal" paint; this only arrives here if the
|
---|
879 | * icon needs to be repainted. We simply paint
|
---|
880 | * the bitmap we created in WM_SETHANDLE.
|
---|
881 | */
|
---|
882 |
|
---|
883 | case WM_PAINT:
|
---|
884 | {
|
---|
885 | RECTL rcl;
|
---|
886 | HPS hps = WinBeginPaint(hwndStatic, NULLHANDLE, &rcl);
|
---|
887 | POINTL ptl = {0, 0};
|
---|
888 |
|
---|
889 | if (pa->hbm)
|
---|
890 | {
|
---|
891 | if (WinQueryWindowULong(hwndStatic, QWL_STYLE)
|
---|
892 | & WS_DISABLED)
|
---|
893 | {
|
---|
894 | // if the control is currently disabled,
|
---|
895 | // draw in half-toned (grayed)
|
---|
896 |
|
---|
897 | LONG lBkgndColor = winhQueryPresColor(
|
---|
898 | WinQueryWindow(hwndStatic, QW_PARENT),
|
---|
899 | PP_BACKGROUNDCOLOR,
|
---|
900 | FALSE,
|
---|
901 | SYSCLR_DIALOGBACKGROUND);
|
---|
902 |
|
---|
903 | // 1) check if we created the half-tone
|
---|
904 | // bitmap already (WinDrawBitmap doesn't
|
---|
905 | // work with half-toned color bitmaps, so
|
---|
906 | // here's yet another thing we have to do
|
---|
907 | // all alone)
|
---|
908 | if (pa->hbmHalftoned == NULLHANDLE)
|
---|
909 | pa->hbmHalftoned = gpihCreateHalftonedBitmap(pa->hab,
|
---|
910 | pa->hbm,
|
---|
911 | lBkgndColor);
|
---|
912 |
|
---|
913 | if (pa->hbmHalftoned)
|
---|
914 | WinDrawBitmap(hps,
|
---|
915 | pa->hbmHalftoned,
|
---|
916 | NULL, // whole bmp
|
---|
917 | &ptl, // lower left corner
|
---|
918 | 0, 0, // no colors
|
---|
919 | DBM_NORMAL);
|
---|
920 | }
|
---|
921 | else
|
---|
922 | {
|
---|
923 | // not disabled: draw regular bitmap
|
---|
924 | // we created previously
|
---|
925 | // draw the bitmap that we created previously
|
---|
926 | WinDrawBitmap(hps,
|
---|
927 | pa->hbm,
|
---|
928 | NULL, // whole bmp
|
---|
929 | &ptl, // lower left corner
|
---|
930 | 0, 0, // no colors
|
---|
931 | DBM_NORMAL);
|
---|
932 | }
|
---|
933 | }
|
---|
934 |
|
---|
935 | WinEndPaint(hps);
|
---|
936 | }
|
---|
937 | break;
|
---|
938 |
|
---|
939 | /*
|
---|
940 | * WM_DESTROY:
|
---|
941 | * clean up.
|
---|
942 | */
|
---|
943 |
|
---|
944 | case WM_DESTROY:
|
---|
945 | // undo subclassing in case more WM_TIMERs come in
|
---|
946 | WinSubclassWindow(hwndStatic, OldStaticProc);
|
---|
947 |
|
---|
948 | if (pa->hbm)
|
---|
949 | GpiDeleteBitmap(pa->hbm);
|
---|
950 | if (pa->hbmHalftoned)
|
---|
951 | GpiDeleteBitmap(pa->hbm);
|
---|
952 |
|
---|
953 | // clean up ANIMATIONDATA struct
|
---|
954 | WinSetWindowULong(hwndStatic, QWL_USER, (ULONG)NULL);
|
---|
955 | free(pa);
|
---|
956 |
|
---|
957 | mrc = OldStaticProc(hwndStatic, msg, mp1, mp2);
|
---|
958 | break;
|
---|
959 |
|
---|
960 | default:
|
---|
961 | mrc = OldStaticProc(hwndStatic, msg, mp1, mp2);
|
---|
962 | }
|
---|
963 | }
|
---|
964 | return mrc;
|
---|
965 | }
|
---|
966 |
|
---|
967 | /* ******************************************************************
|
---|
968 | *
|
---|
969 | * Icon animation
|
---|
970 | *
|
---|
971 | ********************************************************************/
|
---|
972 |
|
---|
973 | /*
|
---|
974 | *@@ CreateAnimationData:
|
---|
975 | *
|
---|
976 | *@@added V0.9.16 (2001-10-15) [umoeller]
|
---|
977 | */
|
---|
978 |
|
---|
979 | static PANIMATIONDATA CreateAnimationData(HAB hab,
|
---|
980 | HWND hwndStatic,
|
---|
981 | USHORT cAnimations)
|
---|
982 | {
|
---|
983 | PANIMATIONDATA pa = NULL;
|
---|
984 |
|
---|
985 | if (cAnimations >= 1)
|
---|
986 | {
|
---|
987 | // create the ANIMATIONDATA structure,
|
---|
988 | // initialize some fields,
|
---|
989 | // and store it in QWL_USER of the static control
|
---|
990 | ULONG cbStruct = sizeof(ANIMATIONDATA)
|
---|
991 | + ((cAnimations - 1) * sizeof(HPOINTER));
|
---|
992 |
|
---|
993 | if (pa = (PANIMATIONDATA)malloc(cbStruct))
|
---|
994 | {
|
---|
995 | memset(pa, 0, cbStruct);
|
---|
996 |
|
---|
997 | WinSetWindowULong(hwndStatic, QWL_USER, (ULONG)pa);
|
---|
998 |
|
---|
999 | pa->hab = hab;
|
---|
1000 | WinQueryWindowRect(hwndStatic, &pa->rclIcon);
|
---|
1001 | pa->OldStaticProc = WinSubclassWindow(hwndStatic, ctl_fnwpBitmapStatic);
|
---|
1002 | pa->lIconSize = WinQuerySysValue(HWND_DESKTOP, SV_CXICON);
|
---|
1003 | }
|
---|
1004 | }
|
---|
1005 |
|
---|
1006 | return (pa);
|
---|
1007 | }
|
---|
1008 |
|
---|
1009 | /*
|
---|
1010 | *@@ ctlPrepareStaticIcon:
|
---|
1011 | * turns a static control into one which properly
|
---|
1012 | * displays transparent icons when given a
|
---|
1013 | * SM_SETHANDLE msg.
|
---|
1014 | * This is done by subclassing the static control
|
---|
1015 | * with ctl_fnwpBitmapStatic.
|
---|
1016 | *
|
---|
1017 | * This function gets called automatically by
|
---|
1018 | * ctlPrepareAnimation, so you need not call it
|
---|
1019 | * independently for animations. See the notes there
|
---|
1020 | * how this can be done.
|
---|
1021 | *
|
---|
1022 | * You can, however, call this function if you
|
---|
1023 | * have some static control with transparent icons
|
---|
1024 | * which is not animated but changes sometimes
|
---|
1025 | * (because you have the same repaint problems there).
|
---|
1026 | *
|
---|
1027 | * This func does _not_ start an animation yet.
|
---|
1028 | *
|
---|
1029 | * To change the icon being displayed, send the control
|
---|
1030 | * a SM_SETHANDLE msg with the icon handle in (HPOINTER)mp1.
|
---|
1031 | *
|
---|
1032 | * Returns a PANIMATIONDATA if subclassing succeeded or
|
---|
1033 | * NULL upon errors. If you only call this function, you
|
---|
1034 | * do not need this structure; it is needed by
|
---|
1035 | * ctlPrepareAnimation though.
|
---|
1036 | *
|
---|
1037 | * The subclassed static icon func above automatically
|
---|
1038 | * cleans up resources, so you don't have to worry about
|
---|
1039 | * that either.
|
---|
1040 | *
|
---|
1041 | *@@changed V0.9.0 [umoeller]: adjusted for ctl_fnwpBitmapStatic changes
|
---|
1042 | */
|
---|
1043 |
|
---|
1044 | PANIMATIONDATA ctlPrepareStaticIcon(HWND hwndStatic,
|
---|
1045 | USHORT usAnimCount) // needed for allocating extra memory,
|
---|
1046 | // this must be at least 1
|
---|
1047 | {
|
---|
1048 | PANIMATIONDATA pa;
|
---|
1049 | HAB hab;
|
---|
1050 | if ( (hwndStatic)
|
---|
1051 | && (hab = WinQueryAnchorBlock(hwndStatic))
|
---|
1052 | && (WinIsWindow(hab, hwndStatic))
|
---|
1053 | && (pa = CreateAnimationData(hab,
|
---|
1054 | hwndStatic,
|
---|
1055 | usAnimCount))
|
---|
1056 | )
|
---|
1057 | {
|
---|
1058 | // switch static to icon mode
|
---|
1059 | pa->ulFlags = ANF_ICON;
|
---|
1060 | return (pa);
|
---|
1061 | }
|
---|
1062 |
|
---|
1063 | return (NULL);
|
---|
1064 | }
|
---|
1065 |
|
---|
1066 | /*
|
---|
1067 | *@@ ctlPrepareAnimation:
|
---|
1068 | * this function turns a regular static icon
|
---|
1069 | * control an animated one. This is the one-shot
|
---|
1070 | * function for animating static icon controls.
|
---|
1071 | *
|
---|
1072 | * It calls ctlPrepareStaticIcon first, then uses
|
---|
1073 | * the passed parameters to prepare an animation:
|
---|
1074 | *
|
---|
1075 | * pahptr must point to an array of HPOINTERs
|
---|
1076 | * which must contain usAnimCount icon handles.
|
---|
1077 | * If (fStartAnimation == TRUE), the animation
|
---|
1078 | * is started already. Otherwise you'll have
|
---|
1079 | * to call ctlStartAnimation yourself.
|
---|
1080 | *
|
---|
1081 | * To create an animated icon, simply create a static
|
---|
1082 | * control with the dialog editor (can be any static,
|
---|
1083 | * e.g. a text control). Then do the following in your code:
|
---|
1084 | *
|
---|
1085 | * 1) load the dlg box template (using WinLoadDlg);
|
---|
1086 | *
|
---|
1087 | * 2) load all the icons for the animation in an array of
|
---|
1088 | * HPOINTERs (check xsdLoadAnimation in shutdown.c for an
|
---|
1089 | * example);
|
---|
1090 | *
|
---|
1091 | * 3) call ctlPrepareAnimation, e.g.:
|
---|
1092 | + ctlPrepareAnimation(WinWindowFromID(hwndDlg, ID_ICON), // get icon hwnd
|
---|
1093 | + 8, // no. of icons for the anim
|
---|
1094 | + &ahptr[0], // ptr to first icon in the array
|
---|
1095 | + 150, // delay
|
---|
1096 | + TRUE); // start animation now
|
---|
1097 | *
|
---|
1098 | * 4) call WinProcessDlg(hwndDlg);
|
---|
1099 | *
|
---|
1100 | * 5) stop the animation, e.g.:
|
---|
1101 | + ctlStopAnimation(WinWindowFromID(hwndDlg, ID_ICON));
|
---|
1102 | *
|
---|
1103 | * 6) destroy the dlg window;
|
---|
1104 | *
|
---|
1105 | * 7) free all the HPOINTERS loaded above (check xsdFreeAnimation
|
---|
1106 | * in shutdown.c for an example).
|
---|
1107 | *
|
---|
1108 | * When the icon control is destroyed, the
|
---|
1109 | * subclassed window proc (ctl_fnwpBitmapStatic)
|
---|
1110 | * automatically cleans up resources. However,
|
---|
1111 | * the icons in *pahptr are not freed.
|
---|
1112 | */
|
---|
1113 |
|
---|
1114 | BOOL ctlPrepareAnimation(HWND hwndStatic, // icon hwnd
|
---|
1115 | USHORT usAnimCount, // no. of anim steps
|
---|
1116 | HPOINTER *pahptr, // array of HPOINTERs
|
---|
1117 | ULONG ulDelay, // delay per anim step (in ms)
|
---|
1118 | BOOL fStartAnimation) // TRUE: start animation now
|
---|
1119 | {
|
---|
1120 | PANIMATIONDATA paNew;
|
---|
1121 | if (paNew = ctlPrepareStaticIcon(hwndStatic, usAnimCount))
|
---|
1122 | {
|
---|
1123 | paNew->ulDelay = ulDelay;
|
---|
1124 | // paNew->OldStaticProc already set
|
---|
1125 | paNew->hptr = NULLHANDLE;
|
---|
1126 | // paNew->rclIcon already set
|
---|
1127 | paNew->usAniCurrent = 0;
|
---|
1128 | paNew->usAniCount = usAnimCount;
|
---|
1129 | memcpy(&paNew->ahptrAniIcons,
|
---|
1130 | pahptr,
|
---|
1131 | (usAnimCount * sizeof(HPOINTER)));
|
---|
1132 |
|
---|
1133 | if (fStartAnimation)
|
---|
1134 | {
|
---|
1135 | WinStartTimer(paNew->hab,
|
---|
1136 | hwndStatic,
|
---|
1137 | 1,
|
---|
1138 | ulDelay);
|
---|
1139 | WinPostMsg(hwndStatic, WM_TIMER, (MPARAM)1, NULL);
|
---|
1140 | }
|
---|
1141 | }
|
---|
1142 | return (paNew != NULL);
|
---|
1143 | }
|
---|
1144 |
|
---|
1145 | /*
|
---|
1146 | *@@ ctlStartAnimation:
|
---|
1147 | * starts an animation that not currently running. You
|
---|
1148 | * must prepare the animation by calling ctlPrepareAnimation
|
---|
1149 | * first.
|
---|
1150 | */
|
---|
1151 |
|
---|
1152 | BOOL ctlStartAnimation(HWND hwndStatic)
|
---|
1153 | {
|
---|
1154 | BOOL brc = FALSE;
|
---|
1155 | PANIMATIONDATA pa;
|
---|
1156 | if ( (pa = (PANIMATIONDATA)WinQueryWindowULong(hwndStatic, QWL_USER))
|
---|
1157 | && (WinStartTimer(pa->hab,
|
---|
1158 | hwndStatic,
|
---|
1159 | 1,
|
---|
1160 | pa->ulDelay))
|
---|
1161 | )
|
---|
1162 | {
|
---|
1163 | brc = TRUE;
|
---|
1164 | WinPostMsg(hwndStatic, WM_TIMER, (MPARAM)1, NULL);
|
---|
1165 | }
|
---|
1166 |
|
---|
1167 | return brc;
|
---|
1168 | }
|
---|
1169 |
|
---|
1170 | /*
|
---|
1171 | *@@ ctlStopAnimation:
|
---|
1172 | * stops an animation that is currently running.
|
---|
1173 | * This does not free any resources.
|
---|
1174 | */
|
---|
1175 |
|
---|
1176 | BOOL ctlStopAnimation(HWND hwndStatic)
|
---|
1177 | {
|
---|
1178 | return (WinStopTimer(WinQueryAnchorBlock(hwndStatic), hwndStatic, 1));
|
---|
1179 | }
|
---|
1180 |
|
---|
1181 | /*
|
---|
1182 | *@@category: Helpers\PM helpers\Window classes\Stretched bitmaps
|
---|
1183 | * See comctl.c and ctlPrepareStretchedBitmap.
|
---|
1184 | */
|
---|
1185 |
|
---|
1186 | /* ******************************************************************
|
---|
1187 | *
|
---|
1188 | * Bitmap functions
|
---|
1189 | *
|
---|
1190 | ********************************************************************/
|
---|
1191 |
|
---|
1192 | /*
|
---|
1193 | *@@ ctlPrepareStretchedBitmap:
|
---|
1194 | * turns a static control into a bitmap control
|
---|
1195 | * which stretches the bitmap to the size of the
|
---|
1196 | * control when given an SM_SETHANDLE msg.
|
---|
1197 | *
|
---|
1198 | * If (fPreserveProportions == TRUE), the control
|
---|
1199 | * will size the bitmap proportionally only. Otherwise,
|
---|
1200 | * it will always stretch the bitmap to the whole
|
---|
1201 | * size of the static control (possibly distorting
|
---|
1202 | * the proportions). See gpihStretchBitmap for
|
---|
1203 | * details.
|
---|
1204 | *
|
---|
1205 | * This function subclasses the static control
|
---|
1206 | * with ctl_fnwpBitmapStatic, setting the flags as
|
---|
1207 | * necessary. However, this does not set the bitmap
|
---|
1208 | * to display yet.
|
---|
1209 | * To have a bitmap displayed, send the control
|
---|
1210 | * a SM_SETHANDLE message with the bitmap to be
|
---|
1211 | * displayed in (HBITMAP)mp1 after having used this
|
---|
1212 | * function.
|
---|
1213 | *
|
---|
1214 | * ctl_fnwpBitmapStatic will then create a private
|
---|
1215 | * copy of that bitmap, stretched to its own size.
|
---|
1216 | * You can therefore delete the "source" bitmap
|
---|
1217 | * after sending SM_SETHANDLE.
|
---|
1218 | *
|
---|
1219 | * You can also send SM_SETHANDLE several times.
|
---|
1220 | * The control will then readjust itself and delete
|
---|
1221 | * its old bitmap.
|
---|
1222 | * But note that GpiWCBitBlt is invoked on that new
|
---|
1223 | * bitmap with every new message, so this is not
|
---|
1224 | * terribly fast.
|
---|
1225 | *
|
---|
1226 | * Also note that you should not resize the static
|
---|
1227 | * control after creation, because the bitmap will
|
---|
1228 | * _not_ be adjusted.
|
---|
1229 | *
|
---|
1230 | * This returns a PANIMATIONDATA if subclassing succeeded or
|
---|
1231 | * NULL upon errors. You do not need to save this structure;
|
---|
1232 | * it is cleaned up automatically when the control is destroyed.
|
---|
1233 | *
|
---|
1234 | *@@added V0.9.0 [umoeller]
|
---|
1235 | *@@changed V0.9.16 (2001-10-15) [umoeller]: some cleanup
|
---|
1236 | */
|
---|
1237 |
|
---|
1238 | PANIMATIONDATA ctlPrepareStretchedBitmap(HWND hwndStatic,
|
---|
1239 | BOOL fPreserveProportions)
|
---|
1240 | {
|
---|
1241 | PANIMATIONDATA pa;
|
---|
1242 | HAB hab;
|
---|
1243 | if ( (hwndStatic)
|
---|
1244 | && (hab = WinQueryAnchorBlock(hwndStatic))
|
---|
1245 | && (WinIsWindow(hab, hwndStatic))
|
---|
1246 | && (pa = CreateAnimationData(hab, hwndStatic, 1))
|
---|
1247 | )
|
---|
1248 | {
|
---|
1249 | // switch static to bitmap mode
|
---|
1250 | pa->ulFlags = ANF_BITMAP;
|
---|
1251 | if (fPreserveProportions)
|
---|
1252 | pa->ulFlags |= ANF_PROPORTIONAL;
|
---|
1253 | return (pa);
|
---|
1254 | }
|
---|
1255 |
|
---|
1256 | return NULL;
|
---|
1257 | }
|
---|
1258 |
|
---|
1259 | /*
|
---|
1260 | *@@category: Helpers\PM helpers\Window classes\Hotkey entry field
|
---|
1261 | * See comctl.c and ctl_fnwpObjectHotkeyEntryField.
|
---|
1262 | */
|
---|
1263 |
|
---|
1264 | /* ******************************************************************
|
---|
1265 | *
|
---|
1266 | * Hotkey entry field
|
---|
1267 | *
|
---|
1268 | ********************************************************************/
|
---|
1269 |
|
---|
1270 | /*
|
---|
1271 | *@@ ctl_fnwpHotkeyEntryField:
|
---|
1272 | * this is the window proc for a subclassed entry
|
---|
1273 | * field which displays a description of a keyboard
|
---|
1274 | * combination upon receiving WM_CHAR.
|
---|
1275 | *
|
---|
1276 | * Use ctlMakeHotkeyEntryField to turn any existing
|
---|
1277 | * entry field into such an "hotkey entry field".
|
---|
1278 | *
|
---|
1279 | * The entry field is deleted on every WM_CHAR that
|
---|
1280 | * comes in.
|
---|
1281 | *
|
---|
1282 | * For this to work, this window proc needs the
|
---|
1283 | * cooperation of its owner. Whenever a WM_CHAR
|
---|
1284 | * message is received by the entry field which
|
---|
1285 | * looks like a meaningful key or key combination
|
---|
1286 | * (some filtering is done by this func), then
|
---|
1287 | * the owner of the entry field receives a WM_CONTROL
|
---|
1288 | * message with the new EN_HOTKEY notification code
|
---|
1289 | * (see comctl.h for details).
|
---|
1290 | *
|
---|
1291 | * It is then the responsibility of the owner to
|
---|
1292 | * check whether the HOTKEYNOTIFY structure pointed
|
---|
1293 | * to by WM_CONTROL's mp2 is a meaningful keyboard
|
---|
1294 | * combination.
|
---|
1295 | *
|
---|
1296 | * If not, the owner must return FALSE, and the
|
---|
1297 | * entry field's contents are deleted.
|
---|
1298 | *
|
---|
1299 | * If yes however, the owner must fill the szDescription
|
---|
1300 | * field with a description of the keyboard combination
|
---|
1301 | * (e.g. "Shift+Alt+C") and return TRUE. The entry field
|
---|
1302 | * will then be set to that description.
|
---|
1303 | *
|
---|
1304 | *@@added V0.9.1 (99-12-19) [umoeller]
|
---|
1305 | *@@changed V0.9.16 (2001-12-08) [umoeller]: fixed empty entry field on tab key
|
---|
1306 | */
|
---|
1307 |
|
---|
1308 | MRESULT EXPENTRY ctl_fnwpObjectHotkeyEntryField(HWND hwndEdit, ULONG msg, MPARAM mp1, MPARAM mp2)
|
---|
1309 | {
|
---|
1310 | MRESULT mrc = (MPARAM)FALSE; // WM_CHAR not-processed flag
|
---|
1311 |
|
---|
1312 | // get object window data; this was stored in QWL_USER by
|
---|
1313 | // WM_INITDLG of obj_fnwpSettingsObjDetails
|
---|
1314 | // PXFOBJWINDATA pWinData = (PXFOBJWINDATA)WinQueryWindowULong(hwndEdit, QWL_USER);
|
---|
1315 | PFNWP pfnwpOrig = (PFNWP)WinQueryWindowULong(hwndEdit, QWL_USER);
|
---|
1316 |
|
---|
1317 | switch (msg)
|
---|
1318 | {
|
---|
1319 | case WM_CHAR:
|
---|
1320 | {
|
---|
1321 | /*
|
---|
1322 | #define KC_CHAR 0x0001
|
---|
1323 | #define KC_VIRTUALKEY 0x0002
|
---|
1324 | #define KC_SCANCODE 0x0004
|
---|
1325 | #define KC_SHIFT 0x0008
|
---|
1326 | #define KC_CTRL 0x0010
|
---|
1327 | #define KC_ALT 0x0020
|
---|
1328 | #define KC_KEYUP 0x0040
|
---|
1329 | #define KC_PREVDOWN 0x0080
|
---|
1330 | #define KC_LONEKEY 0x0100
|
---|
1331 | #define KC_DEADKEY 0x0200
|
---|
1332 | #define KC_COMPOSITE 0x0400
|
---|
1333 | #define KC_INVALIDCOMP 0x0800
|
---|
1334 | */
|
---|
1335 |
|
---|
1336 | /*
|
---|
1337 | Examples: usFlags usKeyCode
|
---|
1338 | F3 02 22
|
---|
1339 | Ctrl+F4 12 23
|
---|
1340 | Ctrl+Shift+F4 1a 23
|
---|
1341 | Ctrl 12 0a
|
---|
1342 | Alt 22 0b
|
---|
1343 | Shift 0a 09
|
---|
1344 | */
|
---|
1345 |
|
---|
1346 | // USHORT usCommand;
|
---|
1347 | // USHORT usKeyCode;
|
---|
1348 | USHORT usFlags = SHORT1FROMMP(mp1);
|
---|
1349 | // UCHAR ucRepeat = CHAR3FROMMP(mp1);
|
---|
1350 | UCHAR ucScanCode = CHAR4FROMMP(mp1);
|
---|
1351 | USHORT usch = SHORT1FROMMP(mp2);
|
---|
1352 | USHORT usvk = SHORT2FROMMP(mp2);
|
---|
1353 |
|
---|
1354 | if (
|
---|
1355 | // process only key-down messages
|
---|
1356 | ((usFlags & KC_KEYUP) == 0)
|
---|
1357 | // check flags:
|
---|
1358 | // filter out those ugly composite key (accents etc.)
|
---|
1359 | && ((usFlags & (KC_DEADKEY | KC_COMPOSITE | KC_INVALIDCOMP)) == 0)
|
---|
1360 | )
|
---|
1361 | {
|
---|
1362 | HOTKEYNOTIFY hkn;
|
---|
1363 | ULONG flReturned;
|
---|
1364 | HWND hwndOwner = WinQueryWindow(hwndEdit, QW_OWNER);
|
---|
1365 |
|
---|
1366 | usFlags &= (KC_VIRTUALKEY | KC_CTRL | KC_ALT | KC_SHIFT);
|
---|
1367 |
|
---|
1368 | hkn.usFlags = usFlags;
|
---|
1369 | hkn.usvk = usvk;
|
---|
1370 | hkn.usch = usch;
|
---|
1371 | hkn.ucScanCode = ucScanCode;
|
---|
1372 |
|
---|
1373 | if (usFlags & KC_VIRTUALKEY)
|
---|
1374 | hkn.usKeyCode = usvk;
|
---|
1375 | else
|
---|
1376 | hkn.usKeyCode = usch;
|
---|
1377 |
|
---|
1378 | hkn.szDescription[0] = 0;
|
---|
1379 |
|
---|
1380 | flReturned = (ULONG)WinSendMsg(hwndOwner,
|
---|
1381 | WM_CONTROL,
|
---|
1382 | MPFROM2SHORT(WinQueryWindowUShort(hwndEdit,
|
---|
1383 | QWS_ID),
|
---|
1384 | EN_HOTKEY), // new notification code
|
---|
1385 | (MPARAM)&hkn);
|
---|
1386 | if (flReturned & HEFL_SETTEXT)
|
---|
1387 | WinSetWindowText(hwndEdit, hkn.szDescription);
|
---|
1388 | else if (flReturned & HEFL_FORWARD2OWNER)
|
---|
1389 | WinPostMsg(hwndOwner,
|
---|
1390 | WM_CHAR,
|
---|
1391 | mp1, mp2);
|
---|
1392 | else
|
---|
1393 | // fixed V0.9.16 (2001-12-06) [umoeller]:
|
---|
1394 | // do not clear the entry field if we had HEFL_FORWARD2OWNER
|
---|
1395 | WinSetWindowText(hwndEdit, "");
|
---|
1396 |
|
---|
1397 | mrc = (MPARAM)TRUE; // WM_CHAR processed flag;
|
---|
1398 | }
|
---|
1399 | }
|
---|
1400 | break;
|
---|
1401 |
|
---|
1402 | default:
|
---|
1403 | mrc = pfnwpOrig(hwndEdit, msg, mp1, mp2);
|
---|
1404 | }
|
---|
1405 | return mrc;
|
---|
1406 | }
|
---|
1407 |
|
---|
1408 | /*
|
---|
1409 | *@@ ctlMakeHotkeyEntryField:
|
---|
1410 | * this turns any entry field into a "hotkey entry field"
|
---|
1411 | * by subclassing it with ctl_fnwpObjectHotkeyEntryField.
|
---|
1412 | * See remarks there for details.
|
---|
1413 | *
|
---|
1414 | * Returns FALSE upon errors, TRUE otherwise.
|
---|
1415 | *
|
---|
1416 | *@@added V0.9.1 (99-12-19) [umoeller]
|
---|
1417 | */
|
---|
1418 |
|
---|
1419 | BOOL ctlMakeHotkeyEntryField(HWND hwndHotkeyEntryField)
|
---|
1420 | {
|
---|
1421 | PFNWP pfnwpOrig = WinSubclassWindow(hwndHotkeyEntryField,
|
---|
1422 | ctl_fnwpObjectHotkeyEntryField);
|
---|
1423 | if (pfnwpOrig)
|
---|
1424 | {
|
---|
1425 | WinSetWindowPtr(hwndHotkeyEntryField, QWL_USER, (PVOID)pfnwpOrig);
|
---|
1426 | return (TRUE);
|
---|
1427 | }
|
---|
1428 |
|
---|
1429 | return (FALSE);
|
---|
1430 | }
|
---|
1431 |
|
---|