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

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

New toolbar control.

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