source: trunk/src/helpers/comctl.c@ 242

Last change on this file since 242 was 242, checked in by umoeller, 23 years ago

First attempt at new container contol.

  • Property svn:eol-style set to CRLF
  • Property svn:keywords set to Author Date Id Revision
File size: 58.7 KB
Line 
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-2002 Ulrich M”ller.
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#define INCL_WINENTRYFIELDS
92#define INCL_WINSHELLDATA
93
94#define INCL_GPIPRIMITIVES
95#define INCL_GPILOGCOLORTABLE
96#define INCL_GPILCIDS
97#define INCL_GPIPATHS
98#define INCL_GPIREGIONS
99#define INCL_GPIBITMAPS // added V0.9.1 (2000-01-04) [umoeller]: needed for EMX headers
100#include <os2.h>
101
102#include <stdlib.h>
103#include <stdio.h>
104#include <string.h>
105#include <setjmp.h> // needed for except.h
106#include <assert.h> // needed for except.h
107
108#include "setup.h" // code generation and debugging options
109
110#include "helpers\cnrh.h"
111#include "helpers\except.h" // exception handling
112#include "helpers\gpih.h"
113#include "helpers\linklist.h"
114#include "helpers\winh.h"
115#include "helpers\standards.h"
116
117#include "helpers\comctl.h"
118
119#pragma hdrstop
120
121/* ******************************************************************
122 *
123 * Shared stuff
124 *
125 ********************************************************************/
126
127/*
128 *@@ ctlSendWmControl:
129 * little helper that post a WM_CONTROL message to
130 * a control's owner.
131 *
132 *@@added V1.0.1 (2002-11-30) [umoeller]
133 */
134
135MRESULT ctlSendWmControl(HWND hwndControl, // in: control who's posting
136 USHORT usCode, // in: code for SHORT2FROMMP(mp1)
137 MPARAM mp2) // in: mp2 from WM_CONTROL
138{
139 HWND hwndOwner;
140
141 if (hwndOwner = WinQueryWindow(hwndControl, QW_OWNER))
142 return WinSendMsg(hwndOwner,
143 WM_CONTROL,
144 MPFROM2SHORT(WinQueryWindowUShort(hwndControl, QWS_ID),
145 usCode),
146 mp2);
147
148 return NULL;
149}
150
151/*
152 *@@ ctlPostWmControl:
153 * little helper that post a WM_CONTROL message to
154 * a control's owner.
155 *
156 *@@added V1.0.1 (2002-11-30) [umoeller]
157 */
158
159BOOL ctlPostWmControl(HWND hwndControl, // in: control who's posting
160 USHORT usCode, // in: code for SHORT2FROMMP(mp1)
161 MPARAM mp2) // in: mp2 from WM_CONTROL
162{
163 HWND hwndOwner;
164
165 if (hwndOwner = WinQueryWindow(hwndControl, QW_OWNER))
166 return WinPostMsg(hwndOwner,
167 WM_CONTROL,
168 MPFROM2SHORT(WinQueryWindowUShort(hwndControl, QWS_ID),
169 usCode),
170 mp2);
171
172 return FALSE;
173}
174
175/*
176 *@@ ctlInitDWD:
177 * ininitializes the DEFWINDATA struct for the
178 * given window. This must be called in WM_CREATE
179 * of a window proc if it intends to use
180 * ctlDefWindowProc as its default window procedure.
181 *
182 *@@added V1.0.1 (2002-11-30) [umoeller]
183 */
184
185VOID ctlInitDWD(HWND hwnd,
186 MPARAM mp2,
187 PDEFWINDATA pdwd,
188 PFNWP pDefWindowProc,
189 const SYSCOLORSET *pSysColorSet)
190{
191 pdwd->hwnd = hwnd;
192 pdwd->szlWin.cx = ((PCREATESTRUCT)mp2)->cx;
193 pdwd->szlWin.cy = ((PCREATESTRUCT)mp2)->cy;
194 pdwd->hab = WinQueryAnchorBlock(hwnd);
195 pdwd->pDefWindowProc = pDefWindowProc;
196 pdwd->pSysColorSet = pSysColorSet;
197
198 ctlRefreshColors(pdwd);
199}
200
201/*
202 *@@ ctlRefreshColors:
203 *
204 *@@added V1.0.1 (2002-11-30) [umoeller]
205 */
206
207VOID ctlRefreshColors(PDEFWINDATA pdwd)
208{
209 pdwd->lcolBackground = winhQueryPresColor2(pdwd->hwnd,
210 PP_BACKGROUNDCOLOR,
211 PP_BACKGROUNDCOLORINDEX,
212 pdwd->pSysColorSet->fInheritPP,
213 pdwd->pSysColorSet->lBackIndex);
214 pdwd->lcolForeground = winhQueryPresColor2(pdwd->hwnd,
215 PP_FOREGROUNDCOLOR,
216 PP_FOREGROUNDCOLORINDEX,
217 pdwd->pSysColorSet->fInheritPP,
218 pdwd->pSysColorSet->lForeIndex);
219}
220
221/*
222 *@@ ctlDefWindowProc:
223 * replacement default window procedure for controls that
224 * have a custom window class and do not inherit from
225 * standard OS/2 controls.
226 *
227 * If a window proc wishes to use this, it must allocate
228 * its own private window data in WM_CREATE (preferrably in
229 * QWL_USER + 1) and have room for a DEFWINDATA struct in
230 * there. It must call ctlInitDWD in WM_CREATE also which
231 * initializes that structure. It can then safely pass
232 * messages to this function.
233 *
234 *@@added V1.0.1 (2002-11-30) [umoeller]
235 */
236
237MRESULT ctlDefWindowProc(PDEFWINDATA pdwd, ULONG msg, MPARAM mp1, MPARAM mp2)
238{
239 MRESULT mrc = 0;
240
241 switch (msg)
242 {
243 case WM_SYSCOLORCHANGE:
244 case WM_PRESPARAMCHANGED:
245 ctlRefreshColors(pdwd);
246 break;
247
248 case WM_ENABLE:
249 WinInvalidateRect(pdwd->hwnd, NULL, TRUE);
250 break;
251
252 case WM_WINDOWPOSCHANGED:
253 if (((PSWP)mp1)->fl & SWP_SIZE)
254 {
255 pdwd->szlWin.cx = ((PSWP)mp1)->cx;
256 pdwd->szlWin.cy = ((PSWP)mp1)->cy;
257 }
258 break;
259
260 default:
261 mrc = pdwd->pDefWindowProc(pdwd->hwnd, msg, mp1, mp2);
262 }
263
264 return mrc;
265}
266
267/* ******************************************************************
268 *
269 * "Separator line" control
270 *
271 ********************************************************************/
272
273PFNWP G_pfnwpSepStatic = NULL;
274
275/*
276 *@@ fnwpSeparatorLine:
277 * window proc for the subclassed static control that makes
278 * the "separator line" control.
279 *
280 *@@added V0.9.20 (2002-08-10) [umoeller]
281 *@@changed V1.0.1 (2002-11-30) [umoeller]: added SEPS_VERTICAL
282 *@@changed V1.0.1 (2002-11-30) [umoeller]: fixed default background color
283 */
284
285STATIC MRESULT EXPENTRY fnwpSeparatorLine(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
286{
287 MRESULT mrc = 0;
288
289 switch (msg)
290 {
291 case WM_PAINT:
292 {
293 RECTL rcl;
294 HPS hps;
295 WinQueryWindowRect(hwnd, &rcl);
296 if (hps = WinBeginPaint(hwnd, NULLHANDLE, NULL))
297 {
298 POINTL ptl;
299
300 gpihSwitchToRGB(hps);
301
302 WinFillRect(hps,
303 &rcl,
304 winhQueryPresColor2(hwnd,
305 PP_BACKGROUNDCOLOR,
306 PP_BACKGROUNDCOLORINDEX,
307 TRUE,
308 SYSCLR_DIALOGBACKGROUND)); // SYSCLR_WINDOW));
309 // fixed V1.0.1 (2002-11-30) [umoeller]
310
311 if (WinQueryWindowULong(hwnd, QWL_STYLE) & SEPS_VERTICAL)
312 {
313 GpiSetColor(hps, G_lcol3DDark);
314
315 ptl.x = (rcl.xRight - rcl.xLeft) / 2 - 1;
316 ptl.y = rcl.yBottom;
317 GpiMove(hps, &ptl);
318 ptl.y = rcl.yTop;
319 GpiLine(hps, &ptl);
320
321 GpiSetColor(hps, G_lcol3DLight);
322
323 ptl.y = rcl.yBottom;
324 ++ptl.x;
325 GpiMove(hps, &ptl);
326 ptl.y = rcl.yTop;
327 GpiLine(hps, &ptl);
328 }
329 else
330 {
331 GpiSetColor(hps, G_lcol3DLight);
332
333 ptl.x = rcl.xLeft;
334 ptl.y = (rcl.yTop - rcl.yBottom) / 2 - 1;
335 GpiMove(hps, &ptl);
336 ptl.x = rcl.xRight;
337 GpiLine(hps, &ptl);
338
339 GpiSetColor(hps, G_lcol3DDark);
340
341 ptl.x = rcl.xLeft;
342 ++ptl.y;
343 GpiMove(hps, &ptl);
344 ptl.x = rcl.xRight;
345 GpiLine(hps, &ptl);
346 }
347
348 WinEndPaint(hps);
349 }
350 }
351 break;
352
353 default:
354 mrc = G_pfnwpSepStatic(hwnd, msg, mp1, mp2);
355 }
356
357 return mrc;
358}
359
360/*
361 *@@ ctlRegisterSeparatorLine:
362 * registers the separator line control, which is a dull
363 * static displaying a 3D line for use as a separator
364 * in dialogs.
365 *
366 * In addition to the standard WS_* styles, the control
367 * supports the SEPS_VERTICAL style bit. If set, the
368 * separator is vertical; if not, it is horizontal.
369 *
370 *@@added V1.0.0 (2002-08-12) [umoeller]
371 */
372
373BOOL ctlRegisterSeparatorLine(HAB hab)
374{
375 CLASSINFO ciStatic;
376 if (WinQueryClassInfo(hab,
377 WC_STATIC,
378 &ciStatic))
379 {
380 G_pfnwpSepStatic = ciStatic.pfnWindowProc;
381
382 return WinRegisterClass(hab,
383 WC_CCTL_SEPARATOR,
384 fnwpSeparatorLine,
385 (ciStatic.flClassStyle & ~CS_PUBLIC),
386 ciStatic.cbWindowData);
387
388 }
389
390 return FALSE;
391}
392
393/*
394 *@@category: Helpers\PM helpers\Window classes\Menu buttons
395 * See comctl.c and ctlMakeMenuButton.
396 */
397
398/* ******************************************************************
399 *
400 * "Menu button" control
401 *
402 ********************************************************************/
403
404/*
405 *@@ MENUBUTTONDATA:
406 * internal data for "menu button"
407 *
408 *@@added V0.9.0 [umoeller]
409 */
410
411typedef struct _MENUBUTTONDATA
412{
413 PFNWP pfnwpButtonOriginal;
414 HMODULE hmodMenu;
415 ULONG idMenu;
416 BOOL fMouseCaptured, // TRUE if WinSetCapture
417 fMouseButton1Down, // TRUE in between WM_BUTTON1DOWN and WM_BUTTON1UP
418 fButtonSunk; // toggle state of the button
419 HWND hwndMenu;
420} MENUBUTTONDATA, *PMENUBUTTONDATA;
421
422/*
423 *@@ ctlDisplayButtonMenu:
424 * displays the specified menu above the button.
425 *
426 *@@added V0.9.7 (2000-11-29) [umoeller]
427 */
428
429VOID ctlDisplayButtonMenu(HWND hwndButton,
430 HWND hwndMenu)
431{
432 SWP swpButton;
433 POINTL ptlMenu;
434 WinQueryWindowPos(hwndButton, &swpButton);
435 ptlMenu.x = swpButton.x;
436 ptlMenu.y = swpButton.y;
437
438 // ptlMenu now has button coordinates
439 // relative to the button's parent;
440 // convert this to screen coordinates:
441 WinMapWindowPoints(WinQueryWindow(hwndButton, QW_PARENT),
442 HWND_DESKTOP,
443 &ptlMenu,
444 1);
445
446 // now show the menu on top of the button
447 WinPopupMenu(HWND_DESKTOP, // menu parent
448 hwndButton, // owner
449 hwndMenu,
450 (SHORT)(ptlMenu.x),
451 (SHORT)(ptlMenu.y + swpButton.cy - 1),
452 0, // ID
453 PU_NONE
454 | PU_MOUSEBUTTON1
455 | PU_KEYBOARD
456 | PU_HCONSTRAIN
457 | PU_VCONSTRAIN);
458}
459
460/*
461 *@@ ctl_fnwpSubclassedMenuButton:
462 * subclassed window proc for "menu button".
463 * See ctlMakeMenuButton for details.
464 *
465 *@@added V0.9.0 [umoeller]
466 *@@changed V0.9.2 (2000-02-28) [umoeller]: menu was displayed even if button was disabled; fixed
467 *@@changed V0.9.14 (2001-07-31) [umoeller]: fixed WM_MENUEND submenu quirk
468 */
469
470MRESULT EXPENTRY ctl_fnwpSubclassedMenuButton(HWND hwndButton, ULONG msg, MPARAM mp1, MPARAM mp2)
471{
472 MRESULT mrc = 0;
473 PMENUBUTTONDATA pmbd = (PMENUBUTTONDATA)WinQueryWindowULong(hwndButton, QWL_USER);
474
475 switch (msg)
476 {
477 /*
478 * WM_BUTTON1DOWN:
479 * WM_BUTTON1UP:
480 * these show/hide the menu.
481 *
482 * Showing the menu follows these steps:
483 * a) first WM_BUTTON1DOWN hilites the button;
484 * b) first WM_BUTTON1UP shows the menu.
485 *
486 * When the button is pressed again, the open
487 * menu loses focus, which results in WM_MENUEND
488 * and destroys the window automatically.
489 */
490
491 case WM_BUTTON1DOWN:
492 case WM_BUTTON1DBLCLK:
493 // only do this if the button is enabled
494 // V0.9.2 (2000-02-28) [umoeller]
495 if (WinIsWindowEnabled(hwndButton))
496 {
497 // _Pmpf(("WM_BUTTON1DOWN"));
498 // since we're not passing the message
499 // to WinDefWndProc, we need to give
500 // ourselves the focus
501 WinSetFocus(HWND_DESKTOP, hwndButton);
502
503 if (!pmbd->fMouseCaptured)
504 {
505 // capture mouse events while the
506 // mouse button is down
507 WinSetCapture(HWND_DESKTOP, hwndButton);
508 pmbd->fMouseCaptured = TRUE;
509 }
510
511 pmbd->fMouseButton1Down = TRUE;
512
513 if (!pmbd->fButtonSunk)
514 {
515 // button not hilited yet (first click):
516 // do it now
517 // _Pmpf((" Sinking menu WM_BUTTON1DOWN "));
518 pmbd->fButtonSunk = TRUE;
519 WinSendMsg(hwndButton,
520 BM_SETHILITE,
521 (MPARAM)TRUE,
522 (MPARAM)0);
523 }
524
525 // else: the menu has just been destroyed
526 // (WM_MENUEND below)
527 }
528
529 mrc = (MPARAM)TRUE; // message processed
530 break;
531
532 /*
533 * WM_BUTTON1UP:
534 *
535 */
536
537 case WM_BUTTON1UP:
538 // only do this if the button is enabled
539 // V0.9.2 (2000-02-28) [umoeller]
540 if (WinIsWindowEnabled(hwndButton))
541 {
542 // _Pmpf(("WM_BUTTON1UP sunk %d hwndMenu 0x%lX", pmbd->fButtonSunk, pmbd->hwndMenu));
543
544 // un-capture the mouse first
545 if (pmbd->fMouseCaptured)
546 {
547 WinSetCapture(HWND_DESKTOP, NULLHANDLE);
548 pmbd->fMouseCaptured = FALSE;
549 }
550
551 pmbd->fMouseButton1Down = FALSE;
552
553 if ( (pmbd->fButtonSunk) // set by WM_BUTTON1DOWN above
554 && (pmbd->hwndMenu) // menu currently showing
555 )
556 {
557 // button currently depressed:
558 // un-hilite button
559 // _Pmpf((" Unsinking menu WM_BUTTON1UP 1"));
560 pmbd->fButtonSunk = FALSE;
561 WinSendMsg(hwndButton,
562 BM_SETHILITE,
563 (MPARAM)FALSE,
564 (MPARAM)0);
565 }
566 else
567 {
568 // first button up:
569 // show menu
570
571 if (pmbd->idMenu)
572 {
573 // _Pmpf((" Loading menu hmod %lX id %lX", pmbd->hmodMenu, pmbd->idMenu));
574 // menu specified: load from
575 // specified resources
576 pmbd->hwndMenu = WinLoadMenu(hwndButton,
577 pmbd->hmodMenu,
578 pmbd->idMenu);
579 }
580 else
581 {
582 HWND hwndOwner = WinQueryWindow(hwndButton, QW_OWNER);
583 // _Pmpf((" Querying menu WM_COMMAND from owner 0x%lX", hwndOwner));
584 // send WM_COMMAND to owner
585 pmbd->hwndMenu
586 = (HWND)WinSendMsg(hwndOwner,
587 WM_COMMAND,
588 (MPARAM)(ULONG)WinQueryWindowUShort(hwndButton,
589 QWS_ID),
590 (MPARAM)0);
591 }
592
593 // _Pmpf((" Loaded menu, hwnd: 0x%lX", pmbd->hwndMenu));
594
595 if (pmbd->hwndMenu)
596 {
597 // menu successfully loaded:
598 // find out where to put it
599 ctlDisplayButtonMenu(hwndButton,
600 pmbd->hwndMenu);
601 } // end if (pmbd->hwndMenu)
602 else
603 {
604 // menu not loaded:
605 // _Pmpf((" Unsinking menu WM_BUTTON1UP 2"));
606 pmbd->fButtonSunk = FALSE;
607 WinSendMsg(hwndButton,
608 BM_SETHILITE,
609 (MPARAM)FALSE,
610 (MPARAM)0);
611 }
612 }
613 }
614
615 mrc = (MPARAM)TRUE; // message processed
616 break;
617
618 /*
619 * WM_BUTTON1CLICK:
620 * swallow this
621 */
622
623 case WM_BUTTON1CLICK:
624 mrc = (MPARAM)TRUE;
625 break;
626
627 /*
628 * WM_SETFOCUS:
629 * swallow this, the button keeps painting
630 * itself otherwise
631 */
632
633 case WM_SETFOCUS:
634 break;
635
636 /*
637 * WM_MENUEND:
638 * menu is destroyed; we get this
639 * because we're the owner
640 */
641
642 case WM_MENUEND:
643 if ((HWND)mp2 == pmbd->hwndMenu) // V0.9.14 (2001-07-31) [umoeller]
644 {
645 BOOL fUnHilite = TRUE;
646 // _Pmpf(("WM_MENUEND"));
647 // At this point, the menu has been
648 // destroyed already.
649 // Since WM_BUTTON1UP handles the
650 // default case that the user presses
651 // the menu button a second time while
652 // the menu is open, we only need
653 // to handle the case that the user
654 // c) presses some key on the menu (ESC, menu selection) or
655 // a) selects a menu item (which
656 // dismisses the menu) or
657 // b) clicks anywhere else.
658
659 // Case a) if mouse button 1 is not currently down
660 if ((WinGetKeyState(HWND_DESKTOP, VK_BUTTON1) & 0x8000) == 0)
661 // button 1 _not_ down:
662 // must be keyboard
663 fUnHilite = TRUE;
664 else
665 // button 1 _is_ down:
666 // query window under mouse pointer
667 ;
668
669 if (fUnHilite)
670 {
671 // _Pmpf((" Unsinking menu WM_MENUEND"));
672 pmbd->fButtonSunk = FALSE;
673 WinSendMsg(hwndButton,
674 BM_SETHILITE,
675 (MPARAM)FALSE,
676 (MPARAM)0);
677 }
678 pmbd->hwndMenu = NULLHANDLE;
679 } // end if ((HWND)mp1 == pmbd->pmbd->hwndMenu) // V0.9.14 (2001-07-31) [umoeller]
680 break;
681
682 /*
683 * WM_COMMAND:
684 * this must be from the menu, so
685 * forward this to the button's owner
686 */
687
688 case WM_COMMAND:
689 WinPostMsg(WinQueryWindow(hwndButton, QW_OWNER),
690 msg,
691 mp1,
692 mp2);
693 break;
694
695 /*
696 * WM_DESTROY:
697 * clean up allocated data
698 */
699
700 case WM_DESTROY:
701 mrc = pmbd->pfnwpButtonOriginal(hwndButton, msg, mp1, mp2);
702 free(pmbd);
703 break;
704
705 default:
706 mrc = pmbd->pfnwpButtonOriginal(hwndButton, msg, mp1, mp2);
707 }
708
709 return mrc;
710}
711
712/*
713 *@@ ctlMakeMenuButton:
714 * this turns the specified button into a "menu button",
715 * which shows a popup menu when the button is depressed.
716 * This is done by subclassing the menu button with
717 * ctl_fnwpSubclassedMenuButton.
718 *
719 * Simply call this function upon any button, and it'll
720 * turn in to a menu button.
721 *
722 * When the user presses the button, the specified menu
723 * is loaded from the resources. The button will then
724 * be set as the owner, but it will forward all WM_COMMAND
725 * messages from the menu to its own owner (probably your
726 * dialog), so you can handle WM_COMMAND messages just as
727 * if the menu was owned by your dialog.
728 *
729 * Alternatively, if you don't want to load a menu from
730 * the resources, you can specify idMenu == 0. In that case,
731 * when the menu button is pressed, it sends (!) a WM_COMMAND
732 * message to its owner with its ID in mp1 (as usual). The
733 * difference is that the return value from that message will
734 * be interpreted as a menu handle (HWND) to use for the button
735 * menu.
736 *
737 * The subclassed button also handles menu destruction etc.
738 * by itself.
739 *
740 *@@added V0.9.0 [umoeller]
741 */
742
743BOOL ctlMakeMenuButton(HWND hwndButton, // in: button to subclass
744 HMODULE hmodMenu, // in: resource module (can be NULLHANDLE for
745 // current EXE)
746 ULONG idMenu) // in: resource menu ID (or 0)
747{
748 BOOL brc = FALSE;
749 PMENUBUTTONDATA pmbd;
750 if (pmbd = (PMENUBUTTONDATA)malloc(sizeof(MENUBUTTONDATA)))
751 {
752 memset(pmbd, 0, sizeof(MENUBUTTONDATA));
753 if (pmbd->pfnwpButtonOriginal = WinSubclassWindow(hwndButton,
754 ctl_fnwpSubclassedMenuButton))
755 {
756 pmbd->hmodMenu = hmodMenu;
757 pmbd->idMenu = idMenu;
758 WinSetWindowULong(hwndButton, QWL_USER, (ULONG)pmbd);
759 brc = TRUE;
760 }
761 else
762 free(pmbd);
763 }
764
765 return brc;
766}
767
768/*
769 *@@category: Helpers\PM helpers\Window classes\Static bitmaps
770 * See comctl.c and ctl_fnwpBitmapStatic.
771 */
772
773/* ******************************************************************
774 *
775 * Subclassed Static Bitmap Control
776 *
777 ********************************************************************/
778
779/*
780 *@@ ctl_fnwpBitmapStatic:
781 * subclassed wnd proc for both static controls which
782 * should display icons and stretched bitmaps.
783 *
784 * This is not a stand-alone window procedure, but must only
785 * be used with static controls subclassed by the functions
786 * listed below.
787 *
788 * This is now (V0.9.0) used in two contexts:
789 * -- when subclassed from ctlPrepareStaticIcon,
790 * this displays transparent icons properly
791 * (for regular icons or icon animations);
792 * -- when subclassed from ctlPrepareStretchedBitmap,
793 * this displays a stretched bitmap.
794 *
795 * The behavior depends on ANIMATIONDATA.ulFlags,
796 * which is set by both of these functions (either to
797 * ANF_ICON or ANF_BITMAP).
798 *
799 * Only one msg is of interest to the "user" application
800 * of this control, which is SM_SETHANDLE,
801 * the normal message sent to a static icon control to change
802 * its icon or bitmap.
803 * The new handle (HPOINTER or HBITMAP) is
804 * in mp1; mp2 must be null.
805 *
806 * Depending on ANIMATIONDATA.ulFlags, we do the following:
807 *
808 * -- ANF_ICON: Unfortunately, the
809 * standard static control paints garbage if
810 * the icons contain transparent areas, and the
811 * display often flickers too.
812 * We improve this by creating one bitmap from
813 * the icon that we were given which we can then
814 * simply copy to the screen in one step in
815 * WM_PAINT.
816 *
817 * -- ANF_BITMAP: we create a bitmap which is
818 * stretched to the size of the static control,
819 * using gpihStretchBitmap.
820 *
821 * In any case, a new bitmap is produced internally and
822 * stored so that it can easily be painted when WM_PAINT
823 * comes in. The source icon/bitmap can therefore
824 * be safely destroyed by the caller after sending
825 * SM_SETHANDLE. This bitmap is automatically deleted when
826 * the window is destroyed.
827 *
828 *@@changed V0.9.0 [umoeller]: function renamed
829 *@@changed V0.9.0 [umoeller]: added support for stretched bitmaps
830 *@@changed V0.9.0 [umoeller]: added halftoned display for WS_DISABLED
831 *@@changed V0.9.0 [umoeller]: exported gpihIcon2Bitmap function to gpih.c
832 *@@changed V0.9.0 [umoeller]: fixed paint errors when SM_SETHANDLE had NULL argument in mp1
833 *@@changed V0.9.16 (2001-10-15) [umoeller]: now centering icon in static properly
834 *@@changed V0.9.16 (2001-10-15) [umoeller]: this always used the presparam colors of the parent instead of its own ones
835 */
836
837MRESULT EXPENTRY ctl_fnwpBitmapStatic(HWND hwndStatic, ULONG msg, MPARAM mp1, MPARAM mp2)
838{
839 PANIMATIONDATA pa = (PANIMATIONDATA)WinQueryWindowULong(hwndStatic, QWL_USER);
840 // animation data which was stored in window words
841
842 PFNWP OldStaticProc = NULL;
843 MRESULT mrc = NULL;
844
845 if (pa)
846 {
847 OldStaticProc = pa->OldStaticProc;
848
849 switch(msg)
850 {
851 /*
852 * WM_TIMER:
853 * this timer is started by the ctl* funcs
854 * below. Proceed to the next animation step.
855 *
856 * Note: this timer is only used with
857 * ANF_ICON, and even then, it
858 * is not necessarily running.
859 */
860
861 case WM_TIMER:
862 pa->usAniCurrent++;
863 if (pa->usAniCurrent >= pa->usAniCount)
864 pa->usAniCurrent = 0;
865
866 WinSendMsg(hwndStatic,
867 SM_SETHANDLE,
868 (MPARAM)pa->ahptrAniIcons[pa->usAniCurrent],
869 (MPARAM)NULL);
870 break;
871
872 /*
873 * SM_SETHANDLE:
874 *
875 */
876
877 case SM_SETHANDLE:
878 {
879 HDC hdcMem;
880 HPS hpsMem;
881 SIZEL szlPage;
882
883 LONG lBkgndColor
884 /* = winhQueryPresColor(WinQueryWindow(hwndStatic, QW_PARENT),
885 PP_BACKGROUNDCOLOR,
886 FALSE,
887 SYSCLR_DIALOGBACKGROUND); */
888 // fixed this... V0.9.16 (2001-10-15) [umoeller]
889 = winhQueryPresColor(hwndStatic,
890 PP_BACKGROUNDCOLOR,
891 TRUE,
892 SYSCLR_DIALOGBACKGROUND);
893
894 HPS hps = WinGetPS(hwndStatic);
895
896 // if we have created bitmaps previously, delete them
897 if (pa->hbm)
898 {
899 GpiDeleteBitmap(pa->hbm);
900 pa->hbm = NULLHANDLE;
901 }
902 if (pa->hbmHalftoned)
903 {
904 GpiDeleteBitmap(pa->hbmHalftoned);
905 pa->hbmHalftoned = NULLHANDLE;
906 }
907
908 // switch to RGB mode
909 gpihSwitchToRGB(hps);
910
911 // create a memory PS
912 szlPage.cx = pa->rclIcon.xRight - pa->rclIcon.xLeft;
913 szlPage.cy = pa->rclIcon.yTop - pa->rclIcon.yBottom;
914 if (gpihCreateMemPS(pa->hab,
915 &szlPage,
916 &hdcMem,
917 &hpsMem))
918 {
919 // switch the memory PS to RGB mode too
920 gpihSwitchToRGB(hpsMem);
921
922 // create a suitable bitmap w/ the size of the
923 // static control
924 if ( ((pa->hbm = gpihCreateBitmap(hpsMem,
925 szlPage.cx,
926 szlPage.cy)))
927 // associate the bit map with the memory PS
928 && (GpiSetBitmap(hpsMem, pa->hbm) != HBM_ERROR)
929 )
930 {
931 // fill the bitmap with the current static
932 // background color
933 POINTL ptl = {0, 0};
934 GpiMove(hpsMem, &ptl);
935 ptl.x = pa->rclIcon.xRight;
936 ptl.y = pa->rclIcon.yTop;
937 GpiSetColor(hpsMem,
938 lBkgndColor);
939 GpiBox(hpsMem,
940 DRO_FILL, // interior only
941 &ptl,
942 0, 0); // no corner rounding
943
944 /*
945 * ANF_ICON:
946 *
947 */
948
949 if (pa->ulFlags & ANF_ICON)
950 {
951 // store new icon in our own structure
952 if (pa->hptr = (HPOINTER)mp1)
953 {
954 // center the icon in the bitmap
955 // V0.9.16 (2001-10-15) [umoeller]
956
957 // replaced call V0.9.19 (2002-06-18) [umoeller]
958 gpihDrawPointer(hpsMem,
959 ( (pa->rclIcon.xRight - pa->rclIcon.xLeft)
960 - pa->szlIcon.cx
961 ) / 2,
962 ( (pa->rclIcon.yTop - pa->rclIcon.yBottom)
963 - pa->szlIcon.cy
964 ) / 2,
965 pa->hptr,
966 &pa->szlIcon,
967 NULL, // no clipping
968 0); // no mini
969 }
970
971 } // end if (pa->ulFlags & ANF_ICON)
972
973 /*
974 * ANF_BITMAP:
975 *
976 */
977
978 else if (pa->ulFlags & ANF_BITMAP)
979 {
980 // store passed bitmap
981 HBITMAP hbmSource;
982 if (hbmSource = (HBITMAP)mp1)
983 gpihStretchBitmap(hpsMem, // target
984 hbmSource, // source
985 NULL, // use size of bitmap
986 &pa->rclIcon,
987 ((pa->ulFlags & ANF_PROPORTIONAL)
988 != 0));
989
990 } // end if (pa->ulFlags & ANF_BITMAP)
991
992 } // end if (GpiSetBitmap(...
993 // && (pa->hbm = gpihCreateBitmap(hpsMem, &(pa->rclIcon)))
994
995 // in any case, clean up now
996 GpiDestroyPS(hpsMem);
997 DevCloseDC(hdcMem);
998 } // end if (gpihCreateMemPS(hab, &hdcMem, &hpsMem))
999
1000 WinReleasePS(hps);
1001
1002 // enforce WM_PAINT
1003 WinInvalidateRect(hwndStatic, NULL, FALSE);
1004 }
1005 break;
1006
1007 /*
1008 * WM_PAINT:
1009 * "normal" paint; this only arrives here if the
1010 * icon needs to be repainted. We simply paint
1011 * the bitmap we created in WM_SETHANDLE.
1012 */
1013
1014 case WM_PAINT:
1015 {
1016 RECTL rcl;
1017 HPS hps = WinBeginPaint(hwndStatic, NULLHANDLE, &rcl);
1018 POINTL ptl = {0, 0};
1019
1020 if (pa->hbm)
1021 {
1022 if (WinQueryWindowULong(hwndStatic, QWL_STYLE)
1023 & WS_DISABLED)
1024 {
1025 // if the control is currently disabled,
1026 // draw in half-toned (grayed)
1027
1028 LONG lBkgndColor = winhQueryPresColor(
1029 WinQueryWindow(hwndStatic, QW_PARENT),
1030 PP_BACKGROUNDCOLOR,
1031 FALSE,
1032 SYSCLR_DIALOGBACKGROUND);
1033
1034 // 1) check if we created the half-tone
1035 // bitmap already (WinDrawBitmap doesn't
1036 // work with half-toned color bitmaps, so
1037 // here's yet another thing we have to do
1038 // all alone)
1039 if (pa->hbmHalftoned == NULLHANDLE)
1040 pa->hbmHalftoned = gpihCreateHalftonedBitmap(pa->hab,
1041 pa->hbm,
1042 lBkgndColor);
1043
1044 if (pa->hbmHalftoned)
1045 WinDrawBitmap(hps,
1046 pa->hbmHalftoned,
1047 NULL, // whole bmp
1048 &ptl, // lower left corner
1049 0, 0, // no colors
1050 DBM_NORMAL);
1051 }
1052 else
1053 {
1054 // not disabled: draw regular bitmap
1055 // we created previously
1056 // draw the bitmap that we created previously
1057 WinDrawBitmap(hps,
1058 pa->hbm,
1059 NULL, // whole bmp
1060 &ptl, // lower left corner
1061 0, 0, // no colors
1062 DBM_NORMAL);
1063 }
1064 }
1065
1066 WinEndPaint(hps);
1067 }
1068 break;
1069
1070 /*
1071 * WM_DESTROY:
1072 * clean up.
1073 */
1074
1075 case WM_DESTROY:
1076 // undo subclassing in case more WM_TIMERs come in
1077 WinSubclassWindow(hwndStatic, OldStaticProc);
1078
1079 if (pa->hbm)
1080 GpiDeleteBitmap(pa->hbm);
1081 if (pa->hbmHalftoned)
1082 GpiDeleteBitmap(pa->hbm);
1083
1084 // clean up ANIMATIONDATA struct
1085 WinSetWindowULong(hwndStatic, QWL_USER, (ULONG)NULL);
1086 free(pa);
1087
1088 mrc = OldStaticProc(hwndStatic, msg, mp1, mp2);
1089 break;
1090
1091 default:
1092 mrc = OldStaticProc(hwndStatic, msg, mp1, mp2);
1093 }
1094 }
1095 return mrc;
1096}
1097
1098/* ******************************************************************
1099 *
1100 * Icon animation
1101 *
1102 ********************************************************************/
1103
1104/*
1105 *@@ CreateAnimationData:
1106 *
1107 *@@added V0.9.16 (2001-10-15) [umoeller]
1108 */
1109
1110STATIC PANIMATIONDATA CreateAnimationData(HAB hab,
1111 HWND hwndStatic,
1112 USHORT cAnimations)
1113{
1114 PANIMATIONDATA pa = NULL;
1115
1116 if (cAnimations >= 1)
1117 {
1118 // create the ANIMATIONDATA structure,
1119 // initialize some fields,
1120 // and store it in QWL_USER of the static control
1121 ULONG cbStruct = sizeof(ANIMATIONDATA)
1122 + ((cAnimations - 1) * sizeof(HPOINTER));
1123
1124 if (pa = (PANIMATIONDATA)malloc(cbStruct))
1125 {
1126 memset(pa, 0, cbStruct);
1127
1128 WinSetWindowULong(hwndStatic, QWL_USER, (ULONG)pa);
1129
1130 pa->hab = hab;
1131 WinQueryWindowRect(hwndStatic, &pa->rclIcon);
1132 pa->OldStaticProc = WinSubclassWindow(hwndStatic, ctl_fnwpBitmapStatic);
1133 pa->szlIcon.cx = G_cxIcon;
1134 pa->szlIcon.cy = G_cyIcon;
1135 }
1136 }
1137
1138 return pa;
1139}
1140
1141/*
1142 *@@ ctlPrepareStaticIcon:
1143 * turns a static control into one which properly
1144 * displays transparent icons when given a
1145 * SM_SETHANDLE msg.
1146 * This is done by subclassing the static control
1147 * with ctl_fnwpBitmapStatic.
1148 *
1149 * This function gets called automatically by
1150 * ctlPrepareAnimation, so you need not call it
1151 * independently for animations. See the notes there
1152 * how this can be done.
1153 *
1154 * You can, however, call this function if you
1155 * have some static control with transparent icons
1156 * which is not animated but changes sometimes
1157 * (because you have the same repaint problems there).
1158 *
1159 * This func does _not_ start an animation yet.
1160 *
1161 * To change the icon being displayed, send the control
1162 * a SM_SETHANDLE msg with the icon handle in (HPOINTER)mp1.
1163 *
1164 * Returns a PANIMATIONDATA if subclassing succeeded or
1165 * NULL upon errors. If you only call this function, you
1166 * do not need this structure; it is needed by
1167 * ctlPrepareAnimation though.
1168 *
1169 * The subclassed static icon func above automatically
1170 * cleans up resources, so you don't have to worry about
1171 * that either.
1172 *
1173 *@@changed V0.9.0 [umoeller]: adjusted for ctl_fnwpBitmapStatic changes
1174 */
1175
1176PANIMATIONDATA ctlPrepareStaticIcon(HWND hwndStatic,
1177 USHORT usAnimCount) // needed for allocating extra memory,
1178 // this must be at least 1
1179{
1180 PANIMATIONDATA pa;
1181 HAB hab;
1182 if ( (hwndStatic)
1183 && (hab = WinQueryAnchorBlock(hwndStatic))
1184 && (WinIsWindow(hab, hwndStatic))
1185 && (pa = CreateAnimationData(hab,
1186 hwndStatic,
1187 usAnimCount))
1188 )
1189 {
1190 // switch static to icon mode
1191 pa->ulFlags = ANF_ICON;
1192 return pa;
1193 }
1194
1195 return NULL;
1196}
1197
1198/*
1199 *@@ ctlPrepareAnimation:
1200 * this function turns a regular static icon
1201 * control an animated one. This is the one-shot
1202 * function for animating static icon controls.
1203 *
1204 * It calls ctlPrepareStaticIcon first, then uses
1205 * the passed parameters to prepare an animation:
1206 *
1207 * pahptr must point to an array of HPOINTERs
1208 * which must contain usAnimCount icon handles.
1209 * If (fStartAnimation == TRUE), the animation
1210 * is started already. Otherwise you'll have
1211 * to call ctlStartAnimation yourself.
1212 *
1213 * To create an animated icon, simply create a static
1214 * control with the dialog editor (can be any static,
1215 * e.g. a text control). Then do the following in your code:
1216 *
1217 * 1) load the dlg box template (using WinLoadDlg);
1218 *
1219 * 2) load all the icons for the animation in an array of
1220 * HPOINTERs (check xsdLoadAnimation in shutdown.c for an
1221 * example);
1222 *
1223 * 3) call ctlPrepareAnimation, e.g.:
1224 + ctlPrepareAnimation(WinWindowFromID(hwndDlg, ID_ICON), // get icon hwnd
1225 + 8, // no. of icons for the anim
1226 + &ahptr[0], // ptr to first icon in the array
1227 + 150, // delay
1228 + TRUE); // start animation now
1229 *
1230 * 4) call WinProcessDlg(hwndDlg);
1231 *
1232 * 5) stop the animation, e.g.:
1233 + ctlStopAnimation(WinWindowFromID(hwndDlg, ID_ICON));
1234 *
1235 * 6) destroy the dlg window;
1236 *
1237 * 7) free all the HPOINTERS loaded above (check xsdFreeAnimation
1238 * in shutdown.c for an example).
1239 *
1240 * When the icon control is destroyed, the
1241 * subclassed window proc (ctl_fnwpBitmapStatic)
1242 * automatically cleans up resources. However,
1243 * the icons in *pahptr are not freed.
1244 */
1245
1246BOOL ctlPrepareAnimation(HWND hwndStatic, // icon hwnd
1247 USHORT usAnimCount, // no. of anim steps
1248 HPOINTER *pahptr, // array of HPOINTERs
1249 ULONG ulDelay, // delay per anim step (in ms)
1250 BOOL fStartAnimation) // TRUE: start animation now
1251{
1252 PANIMATIONDATA paNew;
1253 if (paNew = ctlPrepareStaticIcon(hwndStatic, usAnimCount))
1254 {
1255 paNew->ulDelay = ulDelay;
1256 // paNew->OldStaticProc already set
1257 paNew->hptr = NULLHANDLE;
1258 // paNew->rclIcon already set
1259 paNew->usAniCurrent = 0;
1260 paNew->usAniCount = usAnimCount;
1261 memcpy(&paNew->ahptrAniIcons,
1262 pahptr,
1263 (usAnimCount * sizeof(HPOINTER)));
1264
1265 if (fStartAnimation)
1266 {
1267 WinStartTimer(paNew->hab,
1268 hwndStatic,
1269 1,
1270 ulDelay);
1271 WinPostMsg(hwndStatic, WM_TIMER, (MPARAM)1, NULL);
1272 }
1273 }
1274
1275 return (paNew != NULL);
1276}
1277
1278/*
1279 *@@ ctlStartAnimation:
1280 * starts an animation that not currently running. You
1281 * must prepare the animation by calling ctlPrepareAnimation
1282 * first.
1283 */
1284
1285BOOL ctlStartAnimation(HWND hwndStatic)
1286{
1287 BOOL brc = FALSE;
1288 PANIMATIONDATA pa;
1289 if ( (pa = (PANIMATIONDATA)WinQueryWindowULong(hwndStatic, QWL_USER))
1290 && (WinStartTimer(pa->hab,
1291 hwndStatic,
1292 1,
1293 pa->ulDelay))
1294 )
1295 {
1296 brc = TRUE;
1297 WinPostMsg(hwndStatic, WM_TIMER, (MPARAM)1, NULL);
1298 }
1299
1300 return brc;
1301}
1302
1303/*
1304 *@@ ctlStopAnimation:
1305 * stops an animation that is currently running.
1306 * This does not free any resources.
1307 */
1308
1309BOOL ctlStopAnimation(HWND hwndStatic)
1310{
1311 return WinStopTimer(WinQueryAnchorBlock(hwndStatic), hwndStatic, 1);
1312}
1313
1314/*
1315 *@@category: Helpers\PM helpers\Window classes\Stretched bitmaps
1316 * See comctl.c and ctlPrepareStretchedBitmap.
1317 */
1318
1319/* ******************************************************************
1320 *
1321 * Bitmap functions
1322 *
1323 ********************************************************************/
1324
1325/*
1326 *@@ ctlPrepareStretchedBitmap:
1327 * turns a static control into a bitmap control
1328 * which stretches the bitmap to the size of the
1329 * control when given an SM_SETHANDLE msg.
1330 *
1331 * If (fPreserveProportions == TRUE), the control
1332 * will size the bitmap proportionally only. Otherwise,
1333 * it will always stretch the bitmap to the whole
1334 * size of the static control (possibly distorting
1335 * the proportions). See gpihStretchBitmap for
1336 * details.
1337 *
1338 * This function subclasses the static control
1339 * with ctl_fnwpBitmapStatic, setting the flags as
1340 * necessary. However, this does not set the bitmap
1341 * to display yet.
1342 * To have a bitmap displayed, send the control
1343 * a SM_SETHANDLE message with the bitmap to be
1344 * displayed in (HBITMAP)mp1 after having used this
1345 * function.
1346 *
1347 * ctl_fnwpBitmapStatic will then create a private
1348 * copy of that bitmap, stretched to its own size.
1349 * You can therefore delete the "source" bitmap
1350 * after sending SM_SETHANDLE.
1351 *
1352 * You can also send SM_SETHANDLE several times.
1353 * The control will then readjust itself and delete
1354 * its old bitmap.
1355 * But note that GpiWCBitBlt is invoked on that new
1356 * bitmap with every new message, so this is not
1357 * terribly fast.
1358 *
1359 * Also note that you should not resize the static
1360 * control after creation, because the bitmap will
1361 * _not_ be adjusted.
1362 *
1363 * This returns a PANIMATIONDATA if subclassing succeeded or
1364 * NULL upon errors. You do not need to save this structure;
1365 * it is cleaned up automatically when the control is destroyed.
1366 *
1367 *@@added V0.9.0 [umoeller]
1368 *@@changed V0.9.16 (2001-10-15) [umoeller]: some cleanup
1369 */
1370
1371PANIMATIONDATA ctlPrepareStretchedBitmap(HWND hwndStatic,
1372 BOOL fPreserveProportions)
1373{
1374 PANIMATIONDATA pa;
1375 HAB hab;
1376 if ( (hwndStatic)
1377 && (hab = WinQueryAnchorBlock(hwndStatic))
1378 && (WinIsWindow(hab, hwndStatic))
1379 && (pa = CreateAnimationData(hab, hwndStatic, 1))
1380 )
1381 {
1382 // switch static to bitmap mode
1383 pa->ulFlags = ANF_BITMAP;
1384 if (fPreserveProportions)
1385 pa->ulFlags |= ANF_PROPORTIONAL;
1386 return pa;
1387 }
1388
1389 return NULL;
1390}
1391
1392/*
1393 *@@category: Helpers\PM helpers\Window classes\Hotkey entry field
1394 * See comctl.c and ctl_fnwpObjectHotkeyEntryField.
1395 */
1396
1397/* ******************************************************************
1398 *
1399 * Hotkey entry field
1400 *
1401 ********************************************************************/
1402
1403/*
1404 *@@ ctl_fnwpHotkeyEntryField:
1405 * this is the window proc for a subclassed entry
1406 * field which displays a description of a keyboard
1407 * combination upon receiving WM_CHAR.
1408 *
1409 * Use ctlMakeHotkeyEntryField to turn any existing
1410 * entry field into such an "hotkey entry field".
1411 *
1412 * The entry field is deleted on every WM_CHAR that
1413 * comes in.
1414 *
1415 * For this to work, this window proc needs the
1416 * cooperation of its owner. Whenever a WM_CHAR
1417 * message is received by the entry field which
1418 * looks like a meaningful key or key combination
1419 * (some filtering is done by this func), then
1420 * the owner of the entry field receives a WM_CONTROL
1421 * message with the new EN_HOTKEY notification code
1422 * (see comctl.h for details).
1423 *
1424 * It is then the responsibility of the owner to
1425 * check whether the HOTKEYNOTIFY structure pointed
1426 * to by WM_CONTROL's mp2 is a meaningful keyboard
1427 * combination.
1428 *
1429 * If not, the owner must return FALSE, and the
1430 * entry field's contents are deleted.
1431 *
1432 * If yes however, the owner must fill the szDescription
1433 * field with a description of the keyboard combination
1434 * (e.g. "Shift+Alt+C") and return TRUE. The entry field
1435 * will then be set to that description.
1436 *
1437 *@@added V0.9.1 (99-12-19) [umoeller]
1438 *@@changed V0.9.16 (2001-12-08) [umoeller]: fixed empty entry field on tab key
1439 */
1440
1441MRESULT EXPENTRY ctl_fnwpObjectHotkeyEntryField(HWND hwndEdit, ULONG msg, MPARAM mp1, MPARAM mp2)
1442{
1443 MRESULT mrc = (MPARAM)FALSE; // WM_CHAR not-processed flag
1444
1445 // get object window data; this was stored in QWL_USER by
1446 // WM_INITDLG of obj_fnwpSettingsObjDetails
1447 // PXFOBJWINDATA pWinData = (PXFOBJWINDATA)WinQueryWindowULong(hwndEdit, QWL_USER);
1448 PFNWP pfnwpOrig = (PFNWP)WinQueryWindowULong(hwndEdit, QWL_USER);
1449
1450 switch (msg)
1451 {
1452 case WM_CHAR:
1453 {
1454 /*
1455 #define KC_CHAR 0x0001
1456 #define KC_VIRTUALKEY 0x0002
1457 #define KC_SCANCODE 0x0004
1458 #define KC_SHIFT 0x0008
1459 #define KC_CTRL 0x0010
1460 #define KC_ALT 0x0020
1461 #define KC_KEYUP 0x0040
1462 #define KC_PREVDOWN 0x0080
1463 #define KC_LONEKEY 0x0100
1464 #define KC_DEADKEY 0x0200
1465 #define KC_COMPOSITE 0x0400
1466 #define KC_INVALIDCOMP 0x0800
1467 */
1468
1469 /*
1470 Examples: usFlags usKeyCode
1471 F3 02 22
1472 Ctrl+F4 12 23
1473 Ctrl+Shift+F4 1a 23
1474 Ctrl 12 0a
1475 Alt 22 0b
1476 Shift 0a 09
1477 */
1478
1479 // USHORT usCommand;
1480 // USHORT usKeyCode;
1481 USHORT usFlags = SHORT1FROMMP(mp1);
1482 // UCHAR ucRepeat = CHAR3FROMMP(mp1);
1483 UCHAR ucScanCode = CHAR4FROMMP(mp1);
1484 USHORT usch = SHORT1FROMMP(mp2);
1485 USHORT usvk = SHORT2FROMMP(mp2);
1486
1487 if (
1488 // process only key-down messages
1489 ((usFlags & KC_KEYUP) == 0)
1490 // check flags:
1491 // filter out those ugly composite key (accents etc.)
1492 && ((usFlags & (KC_DEADKEY | KC_COMPOSITE | KC_INVALIDCOMP)) == 0)
1493 )
1494 {
1495 HOTKEYNOTIFY hkn;
1496 ULONG flReturned;
1497 HWND hwndOwner = WinQueryWindow(hwndEdit, QW_OWNER);
1498
1499 usFlags &= (KC_VIRTUALKEY | KC_CTRL | KC_ALT | KC_SHIFT);
1500
1501 hkn.usFlags = usFlags;
1502 hkn.usvk = usvk;
1503 hkn.usch = usch;
1504 hkn.ucScanCode = ucScanCode;
1505
1506 if (usFlags & KC_VIRTUALKEY)
1507 hkn.usKeyCode = usvk;
1508 else
1509 hkn.usKeyCode = usch;
1510
1511 hkn.szDescription[0] = 0;
1512
1513 flReturned = (ULONG)WinSendMsg(hwndOwner,
1514 WM_CONTROL,
1515 MPFROM2SHORT(WinQueryWindowUShort(hwndEdit,
1516 QWS_ID),
1517 EN_HOTKEY), // new notification code
1518 (MPARAM)&hkn);
1519 if (flReturned & HEFL_SETTEXT)
1520 WinSetWindowText(hwndEdit, hkn.szDescription);
1521 else if (flReturned & HEFL_FORWARD2OWNER)
1522 WinPostMsg(hwndOwner,
1523 WM_CHAR,
1524 mp1, mp2);
1525 else
1526 // fixed V0.9.16 (2001-12-06) [umoeller]:
1527 // do not clear the entry field if we had HEFL_FORWARD2OWNER
1528 WinSetWindowText(hwndEdit, "");
1529
1530 mrc = (MPARAM)TRUE; // WM_CHAR processed flag;
1531 }
1532 }
1533 break;
1534
1535 default:
1536 mrc = pfnwpOrig(hwndEdit, msg, mp1, mp2);
1537 }
1538 return mrc;
1539}
1540
1541/*
1542 *@@ ctlMakeHotkeyEntryField:
1543 * this turns any entry field into a "hotkey entry field"
1544 * by subclassing it with ctl_fnwpObjectHotkeyEntryField.
1545 * See remarks there for details.
1546 *
1547 * Returns FALSE upon errors, TRUE otherwise.
1548 *
1549 *@@added V0.9.1 (99-12-19) [umoeller]
1550 */
1551
1552BOOL ctlMakeHotkeyEntryField(HWND hwndHotkeyEntryField)
1553{
1554 PFNWP pfnwpOrig;
1555 if (pfnwpOrig = WinSubclassWindow(hwndHotkeyEntryField,
1556 ctl_fnwpObjectHotkeyEntryField))
1557 {
1558 WinSetWindowPtr(hwndHotkeyEntryField, QWL_USER, (PVOID)pfnwpOrig);
1559 return TRUE;
1560 }
1561
1562 return FALSE;
1563}
1564
1565/* ******************************************************************
1566 *
1567 * Color rectangle
1568 *
1569 ********************************************************************/
1570
1571STATIC PFNWP G_pfnwpColorRectOrigStatic = NULL;
1572
1573/*
1574 *@@ ctl_fnwpSubclassedColorRect:
1575 * window procedure for subclassed static frames representing
1576 * a color.
1577 *
1578 * The control simply paints itself as a rectangle with the
1579 * color specified in its PP_BACKGROUNDCOLOR presentation
1580 * parameter. If a window text is set for the control, it is
1581 * painted with the PP_FOREGROUNDCOLOR color.
1582 *
1583 * If the user drags a color onto the control, it notifies
1584 * its owner with the WM_CONTROL message and the EN_CHANGE
1585 * notification code, as with any entry field (since the
1586 * static control knows no notifications, we use that code
1587 * instead).
1588 *
1589 *@@added V0.9.16 (2002-01-05) [umoeller]
1590 *@@changed V0.9.19 (2002-06-02) [umoeller]: moved this here from w_pulse.c
1591 */
1592
1593STATIC MRESULT EXPENTRY ctl_fnwpSubclassedColorRect(HWND hwndStatic, ULONG msg, MPARAM mp1, MPARAM mp2)
1594{
1595 MRESULT mrc = 0;
1596
1597 switch (msg)
1598 {
1599 case WM_PAINT:
1600 {
1601 LONG lColor;
1602 RECTL rclPaint;
1603 PSZ pszText;
1604
1605 HPS hps = WinBeginPaint(hwndStatic,
1606 NULLHANDLE, // HPS
1607 NULL); // PRECTL
1608 gpihSwitchToRGB(hps);
1609 WinQueryWindowRect(hwndStatic,
1610 &rclPaint); // exclusive
1611 lColor = winhQueryPresColor(hwndStatic,
1612 PP_BACKGROUNDCOLOR,
1613 FALSE, // no inherit
1614 SYSCLR_DIALOGBACKGROUND);
1615
1616 // make rect inclusive
1617 rclPaint.xRight--;
1618 rclPaint.yTop--;
1619
1620 // draw interior
1621 GpiSetColor(hps, lColor);
1622 gpihBox(hps,
1623 DRO_FILL,
1624 &rclPaint);
1625
1626 // draw frame
1627 GpiSetColor(hps, RGBCOL_BLACK);
1628 gpihBox(hps,
1629 DRO_OUTLINE,
1630 &rclPaint);
1631
1632 if (pszText = winhQueryWindowText(hwndStatic))
1633 {
1634 GpiSetColor(hps,
1635 winhQueryPresColor(hwndStatic,
1636 PP_FOREGROUNDCOLOR,
1637 FALSE,
1638 -1));
1639 WinDrawText(hps,
1640 strlen(pszText),
1641 pszText,
1642 &rclPaint,
1643 0,
1644 0,
1645 DT_CENTER | DT_VCENTER | DT_TEXTATTRS);
1646
1647 free(pszText);
1648 }
1649
1650 WinEndPaint(hps);
1651 }
1652 break;
1653
1654 case WM_PRESPARAMCHANGED:
1655 switch ((ULONG)mp1)
1656 {
1657 case PP_BACKGROUNDCOLOR:
1658 WinInvalidateRect(hwndStatic,
1659 NULL,
1660 FALSE);
1661 // notify owner; since the static control
1662 // doesn't send any notifications, we
1663 // use EN_CHANGED
1664 ctlSendWmControl(hwndStatic,
1665 EN_CHANGE,
1666 (MPARAM)hwndStatic);
1667 break;
1668 }
1669 break;
1670
1671 default:
1672 mrc = G_pfnwpColorRectOrigStatic(hwndStatic, msg, mp1, mp2);
1673 break;
1674 }
1675
1676 return mrc;
1677}
1678
1679/*
1680 *@@ ctlMakeColorRect:
1681 * turns a static rectangle into a color rectangle.
1682 *
1683 *@@added V0.9.19 (2002-06-02) [umoeller]
1684 */
1685
1686BOOL ctlMakeColorRect(HWND hwndStatic)
1687{
1688 PFNWP pfnwp;
1689
1690 if (pfnwp = WinSubclassWindow(hwndStatic,
1691 ctl_fnwpSubclassedColorRect))
1692 {
1693 G_pfnwpColorRectOrigStatic = pfnwp;
1694 return TRUE;
1695 }
1696
1697 return FALSE;
1698}
1699
1700
Note: See TracBrowser for help on using the repository browser.