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

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

Second round of fixes for 0.9.19.

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