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

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

Minor changes.

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