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

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

Fixes for ip widget.

  • Property svn:eol-style set to CRLF
  • Property svn:keywords set to Author Date Id Revision
File size: 54.9 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 return brc;
635}
636
637/*
638 *@@category: Helpers\PM helpers\Window classes\Static bitmaps
639 * See comctl.c and ctl_fnwpBitmapStatic.
640 */
641
642/* ******************************************************************
643 *
644 * Subclassed Static Bitmap Control
645 *
646 ********************************************************************/
647
648/*
649 *@@ ctl_fnwpBitmapStatic:
650 * subclassed wnd proc for both static controls which
651 * should display icons and stretched bitmaps.
652 *
653 * This is not a stand-alone window procedure, but must only
654 * be used with static controls subclassed by the functions
655 * listed below.
656 *
657 * This is now (V0.9.0) used in two contexts:
658 * -- when subclassed from ctlPrepareStaticIcon,
659 * this displays transparent icons properly
660 * (for regular icons or icon animations);
661 * -- when subclassed from ctlPrepareStretchedBitmap,
662 * this displays a stretched bitmap.
663 *
664 * The behavior depends on ANIMATIONDATA.ulFlags,
665 * which is set by both of these functions (either to
666 * ANF_ICON or ANF_BITMAP).
667 *
668 * Only one msg is of interest to the "user" application
669 * of this control, which is SM_SETHANDLE,
670 * the normal message sent to a static icon control to change
671 * its icon or bitmap.
672 * The new handle (HPOINTER or HBITMAP) is
673 * in mp1; mp2 must be null.
674 *
675 * Depending on ANIMATIONDATA.ulFlags, we do the following:
676 *
677 * -- ANF_ICON: Unfortunately, the
678 * standard static control paints garbage if
679 * the icons contain transparent areas, and the
680 * display often flickers too.
681 * We improve this by creating one bitmap from
682 * the icon that we were given which we can then
683 * simply copy to the screen in one step in
684 * WM_PAINT.
685 *
686 * -- ANF_BITMAP: we create a bitmap which is
687 * stretched to the size of the static control,
688 * using gpihStretchBitmap.
689 *
690 * In any case, a new bitmap is produced internally and
691 * stored so that it can easily be painted when WM_PAINT
692 * comes in. The source icon/bitmap can therefore
693 * be safely destroyed by the caller after sending
694 * SM_SETHANDLE. This bitmap is automatically deleted when
695 * the window is destroyed.
696 *
697 *@@changed V0.9.0 [umoeller]: function renamed
698 *@@changed V0.9.0 [umoeller]: added support for stretched bitmaps
699 *@@changed V0.9.0 [umoeller]: added halftoned display for WS_DISABLED
700 *@@changed V0.9.0 [umoeller]: exported gpihIcon2Bitmap function to gpih.c
701 *@@changed V0.9.0 [umoeller]: fixed paint errors when SM_SETHANDLE had NULL argument in mp1
702 *@@changed V0.9.16 (2001-10-15) [umoeller]: now centering icon in static properly
703 *@@changed V0.9.16 (2001-10-15) [umoeller]: this always used the presparam colors of the parent instead of its own ones
704 */
705
706MRESULT EXPENTRY ctl_fnwpBitmapStatic(HWND hwndStatic, ULONG msg, MPARAM mp1, MPARAM mp2)
707{
708 PANIMATIONDATA pa = (PANIMATIONDATA)WinQueryWindowULong(hwndStatic, QWL_USER);
709 // animation data which was stored in window words
710
711 PFNWP OldStaticProc = NULL;
712 MRESULT mrc = NULL;
713
714 if (pa)
715 {
716 OldStaticProc = pa->OldStaticProc;
717
718 switch(msg)
719 {
720 /*
721 * WM_TIMER:
722 * this timer is started by the ctl* funcs
723 * below. Proceed to the next animation step.
724 *
725 * Note: this timer is only used with
726 * ANF_ICON, and even then, it
727 * is not necessarily running.
728 */
729
730 case WM_TIMER:
731 pa->usAniCurrent++;
732 if (pa->usAniCurrent >= pa->usAniCount)
733 pa->usAniCurrent = 0;
734
735 WinSendMsg(hwndStatic,
736 SM_SETHANDLE,
737 (MPARAM)pa->ahptrAniIcons[pa->usAniCurrent],
738 (MPARAM)NULL);
739 break;
740
741 /*
742 * SM_SETHANDLE:
743 *
744 */
745
746 case SM_SETHANDLE:
747 {
748 HDC hdcMem;
749 HPS hpsMem;
750 SIZEL szlPage;
751
752 LONG lBkgndColor
753 /* = winhQueryPresColor(WinQueryWindow(hwndStatic, QW_PARENT),
754 PP_BACKGROUNDCOLOR,
755 FALSE,
756 SYSCLR_DIALOGBACKGROUND); */
757 // fixed this... V0.9.16 (2001-10-15) [umoeller]
758 = winhQueryPresColor(hwndStatic,
759 PP_BACKGROUNDCOLOR,
760 TRUE,
761 SYSCLR_DIALOGBACKGROUND);
762
763 HPS hps = WinGetPS(hwndStatic);
764
765 // if we have created bitmaps previously, delete them
766 if (pa->hbm)
767 {
768 GpiDeleteBitmap(pa->hbm);
769 pa->hbm = NULLHANDLE;
770 }
771 if (pa->hbmHalftoned)
772 {
773 GpiDeleteBitmap(pa->hbmHalftoned);
774 pa->hbmHalftoned = NULLHANDLE;
775 }
776
777 // switch to RGB mode
778 gpihSwitchToRGB(hps);
779
780 // create a memory PS
781 szlPage.cx = pa->rclIcon.xRight - pa->rclIcon.xLeft;
782 szlPage.cy = pa->rclIcon.yTop - pa->rclIcon.yBottom;
783 if (gpihCreateMemPS(pa->hab,
784 &szlPage,
785 &hdcMem,
786 &hpsMem))
787 {
788 // switch the memory PS to RGB mode too
789 gpihSwitchToRGB(hpsMem);
790
791 // create a suitable bitmap w/ the size of the
792 // static control
793 if ( ((pa->hbm = gpihCreateBitmap(hpsMem,
794 szlPage.cx,
795 szlPage.cy)))
796 // associate the bit map with the memory PS
797 && (GpiSetBitmap(hpsMem, pa->hbm) != HBM_ERROR)
798 )
799 {
800 // fill the bitmap with the current static
801 // background color
802 POINTL ptl = {0, 0};
803 GpiMove(hpsMem, &ptl);
804 ptl.x = pa->rclIcon.xRight;
805 ptl.y = pa->rclIcon.yTop;
806 GpiSetColor(hpsMem,
807 lBkgndColor);
808 GpiBox(hpsMem,
809 DRO_FILL, // interior only
810 &ptl,
811 0, 0); // no corner rounding
812
813 /*
814 * ANF_ICON:
815 *
816 */
817
818 if (pa->ulFlags & ANF_ICON)
819 {
820 // store new icon in our own structure
821 if (pa->hptr = (HPOINTER)mp1)
822 {
823 // center the icon in the bitmap
824 // V0.9.16 (2001-10-15) [umoeller]
825 POINTL ptlOfs;
826 ptlOfs.x = ( (pa->rclIcon.xRight - pa->rclIcon.xLeft)
827 - pa->lIconSize
828 ) / 2;
829 ptlOfs.y = ( (pa->rclIcon.yTop - pa->rclIcon.yBottom)
830 - pa->lIconSize
831 ) / 2;
832
833 // paint icon into bitmap
834 gpihIcon2Bitmap(hpsMem,
835 pa->hptr,
836 lBkgndColor,
837 &ptlOfs,
838 pa->lIconSize);
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->lIconSize = WinQuerySysValue(HWND_DESKTOP, SV_CXICON);
1004 }
1005 }
1006
1007 return (pa);
1008}
1009
1010/*
1011 *@@ ctlPrepareStaticIcon:
1012 * turns a static control into one which properly
1013 * displays transparent icons when given a
1014 * SM_SETHANDLE msg.
1015 * This is done by subclassing the static control
1016 * with ctl_fnwpBitmapStatic.
1017 *
1018 * This function gets called automatically by
1019 * ctlPrepareAnimation, so you need not call it
1020 * independently for animations. See the notes there
1021 * how this can be done.
1022 *
1023 * You can, however, call this function if you
1024 * have some static control with transparent icons
1025 * which is not animated but changes sometimes
1026 * (because you have the same repaint problems there).
1027 *
1028 * This func does _not_ start an animation yet.
1029 *
1030 * To change the icon being displayed, send the control
1031 * a SM_SETHANDLE msg with the icon handle in (HPOINTER)mp1.
1032 *
1033 * Returns a PANIMATIONDATA if subclassing succeeded or
1034 * NULL upon errors. If you only call this function, you
1035 * do not need this structure; it is needed by
1036 * ctlPrepareAnimation though.
1037 *
1038 * The subclassed static icon func above automatically
1039 * cleans up resources, so you don't have to worry about
1040 * that either.
1041 *
1042 *@@changed V0.9.0 [umoeller]: adjusted for ctl_fnwpBitmapStatic changes
1043 */
1044
1045PANIMATIONDATA ctlPrepareStaticIcon(HWND hwndStatic,
1046 USHORT usAnimCount) // needed for allocating extra memory,
1047 // this must be at least 1
1048{
1049 PANIMATIONDATA pa;
1050 HAB hab;
1051 if ( (hwndStatic)
1052 && (hab = WinQueryAnchorBlock(hwndStatic))
1053 && (WinIsWindow(hab, hwndStatic))
1054 && (pa = CreateAnimationData(hab,
1055 hwndStatic,
1056 usAnimCount))
1057 )
1058 {
1059 // switch static to icon mode
1060 pa->ulFlags = ANF_ICON;
1061 return (pa);
1062 }
1063
1064 return (NULL);
1065}
1066
1067/*
1068 *@@ ctlPrepareAnimation:
1069 * this function turns a regular static icon
1070 * control an animated one. This is the one-shot
1071 * function for animating static icon controls.
1072 *
1073 * It calls ctlPrepareStaticIcon first, then uses
1074 * the passed parameters to prepare an animation:
1075 *
1076 * pahptr must point to an array of HPOINTERs
1077 * which must contain usAnimCount icon handles.
1078 * If (fStartAnimation == TRUE), the animation
1079 * is started already. Otherwise you'll have
1080 * to call ctlStartAnimation yourself.
1081 *
1082 * To create an animated icon, simply create a static
1083 * control with the dialog editor (can be any static,
1084 * e.g. a text control). Then do the following in your code:
1085 *
1086 * 1) load the dlg box template (using WinLoadDlg);
1087 *
1088 * 2) load all the icons for the animation in an array of
1089 * HPOINTERs (check xsdLoadAnimation in shutdown.c for an
1090 * example);
1091 *
1092 * 3) call ctlPrepareAnimation, e.g.:
1093 + ctlPrepareAnimation(WinWindowFromID(hwndDlg, ID_ICON), // get icon hwnd
1094 + 8, // no. of icons for the anim
1095 + &ahptr[0], // ptr to first icon in the array
1096 + 150, // delay
1097 + TRUE); // start animation now
1098 *
1099 * 4) call WinProcessDlg(hwndDlg);
1100 *
1101 * 5) stop the animation, e.g.:
1102 + ctlStopAnimation(WinWindowFromID(hwndDlg, ID_ICON));
1103 *
1104 * 6) destroy the dlg window;
1105 *
1106 * 7) free all the HPOINTERS loaded above (check xsdFreeAnimation
1107 * in shutdown.c for an example).
1108 *
1109 * When the icon control is destroyed, the
1110 * subclassed window proc (ctl_fnwpBitmapStatic)
1111 * automatically cleans up resources. However,
1112 * the icons in *pahptr are not freed.
1113 */
1114
1115BOOL ctlPrepareAnimation(HWND hwndStatic, // icon hwnd
1116 USHORT usAnimCount, // no. of anim steps
1117 HPOINTER *pahptr, // array of HPOINTERs
1118 ULONG ulDelay, // delay per anim step (in ms)
1119 BOOL fStartAnimation) // TRUE: start animation now
1120{
1121 PANIMATIONDATA paNew;
1122 if (paNew = ctlPrepareStaticIcon(hwndStatic, usAnimCount))
1123 {
1124 paNew->ulDelay = ulDelay;
1125 // paNew->OldStaticProc already set
1126 paNew->hptr = NULLHANDLE;
1127 // paNew->rclIcon already set
1128 paNew->usAniCurrent = 0;
1129 paNew->usAniCount = usAnimCount;
1130 memcpy(&paNew->ahptrAniIcons,
1131 pahptr,
1132 (usAnimCount * sizeof(HPOINTER)));
1133
1134 if (fStartAnimation)
1135 {
1136 WinStartTimer(paNew->hab,
1137 hwndStatic,
1138 1,
1139 ulDelay);
1140 WinPostMsg(hwndStatic, WM_TIMER, (MPARAM)1, NULL);
1141 }
1142 }
1143 return (paNew != NULL);
1144}
1145
1146/*
1147 *@@ ctlStartAnimation:
1148 * starts an animation that not currently running. You
1149 * must prepare the animation by calling ctlPrepareAnimation
1150 * first.
1151 */
1152
1153BOOL ctlStartAnimation(HWND hwndStatic)
1154{
1155 BOOL brc = FALSE;
1156 PANIMATIONDATA pa;
1157 if ( (pa = (PANIMATIONDATA)WinQueryWindowULong(hwndStatic, QWL_USER))
1158 && (WinStartTimer(pa->hab,
1159 hwndStatic,
1160 1,
1161 pa->ulDelay))
1162 )
1163 {
1164 brc = TRUE;
1165 WinPostMsg(hwndStatic, WM_TIMER, (MPARAM)1, NULL);
1166 }
1167
1168 return brc;
1169}
1170
1171/*
1172 *@@ ctlStopAnimation:
1173 * stops an animation that is currently running.
1174 * This does not free any resources.
1175 */
1176
1177BOOL ctlStopAnimation(HWND hwndStatic)
1178{
1179 return (WinStopTimer(WinQueryAnchorBlock(hwndStatic), hwndStatic, 1));
1180}
1181
1182/*
1183 *@@category: Helpers\PM helpers\Window classes\Stretched bitmaps
1184 * See comctl.c and ctlPrepareStretchedBitmap.
1185 */
1186
1187/* ******************************************************************
1188 *
1189 * Bitmap functions
1190 *
1191 ********************************************************************/
1192
1193/*
1194 *@@ ctlPrepareStretchedBitmap:
1195 * turns a static control into a bitmap control
1196 * which stretches the bitmap to the size of the
1197 * control when given an SM_SETHANDLE msg.
1198 *
1199 * If (fPreserveProportions == TRUE), the control
1200 * will size the bitmap proportionally only. Otherwise,
1201 * it will always stretch the bitmap to the whole
1202 * size of the static control (possibly distorting
1203 * the proportions). See gpihStretchBitmap for
1204 * details.
1205 *
1206 * This function subclasses the static control
1207 * with ctl_fnwpBitmapStatic, setting the flags as
1208 * necessary. However, this does not set the bitmap
1209 * to display yet.
1210 * To have a bitmap displayed, send the control
1211 * a SM_SETHANDLE message with the bitmap to be
1212 * displayed in (HBITMAP)mp1 after having used this
1213 * function.
1214 *
1215 * ctl_fnwpBitmapStatic will then create a private
1216 * copy of that bitmap, stretched to its own size.
1217 * You can therefore delete the "source" bitmap
1218 * after sending SM_SETHANDLE.
1219 *
1220 * You can also send SM_SETHANDLE several times.
1221 * The control will then readjust itself and delete
1222 * its old bitmap.
1223 * But note that GpiWCBitBlt is invoked on that new
1224 * bitmap with every new message, so this is not
1225 * terribly fast.
1226 *
1227 * Also note that you should not resize the static
1228 * control after creation, because the bitmap will
1229 * _not_ be adjusted.
1230 *
1231 * This returns a PANIMATIONDATA if subclassing succeeded or
1232 * NULL upon errors. You do not need to save this structure;
1233 * it is cleaned up automatically when the control is destroyed.
1234 *
1235 *@@added V0.9.0 [umoeller]
1236 *@@changed V0.9.16 (2001-10-15) [umoeller]: some cleanup
1237 */
1238
1239PANIMATIONDATA ctlPrepareStretchedBitmap(HWND hwndStatic,
1240 BOOL fPreserveProportions)
1241{
1242 PANIMATIONDATA pa;
1243 HAB hab;
1244 if ( (hwndStatic)
1245 && (hab = WinQueryAnchorBlock(hwndStatic))
1246 && (WinIsWindow(hab, hwndStatic))
1247 && (pa = CreateAnimationData(hab, hwndStatic, 1))
1248 )
1249 {
1250 // switch static to bitmap mode
1251 pa->ulFlags = ANF_BITMAP;
1252 if (fPreserveProportions)
1253 pa->ulFlags |= ANF_PROPORTIONAL;
1254 return (pa);
1255 }
1256
1257 return NULL;
1258}
1259
1260/*
1261 *@@category: Helpers\PM helpers\Window classes\Hotkey entry field
1262 * See comctl.c and ctl_fnwpObjectHotkeyEntryField.
1263 */
1264
1265/* ******************************************************************
1266 *
1267 * Hotkey entry field
1268 *
1269 ********************************************************************/
1270
1271/*
1272 *@@ ctl_fnwpHotkeyEntryField:
1273 * this is the window proc for a subclassed entry
1274 * field which displays a description of a keyboard
1275 * combination upon receiving WM_CHAR.
1276 *
1277 * Use ctlMakeHotkeyEntryField to turn any existing
1278 * entry field into such an "hotkey entry field".
1279 *
1280 * The entry field is deleted on every WM_CHAR that
1281 * comes in.
1282 *
1283 * For this to work, this window proc needs the
1284 * cooperation of its owner. Whenever a WM_CHAR
1285 * message is received by the entry field which
1286 * looks like a meaningful key or key combination
1287 * (some filtering is done by this func), then
1288 * the owner of the entry field receives a WM_CONTROL
1289 * message with the new EN_HOTKEY notification code
1290 * (see comctl.h for details).
1291 *
1292 * It is then the responsibility of the owner to
1293 * check whether the HOTKEYNOTIFY structure pointed
1294 * to by WM_CONTROL's mp2 is a meaningful keyboard
1295 * combination.
1296 *
1297 * If not, the owner must return FALSE, and the
1298 * entry field's contents are deleted.
1299 *
1300 * If yes however, the owner must fill the szDescription
1301 * field with a description of the keyboard combination
1302 * (e.g. "Shift+Alt+C") and return TRUE. The entry field
1303 * will then be set to that description.
1304 *
1305 *@@added V0.9.1 (99-12-19) [umoeller]
1306 *@@changed V0.9.16 (2001-12-08) [umoeller]: fixed empty entry field on tab key
1307 */
1308
1309MRESULT EXPENTRY ctl_fnwpObjectHotkeyEntryField(HWND hwndEdit, ULONG msg, MPARAM mp1, MPARAM mp2)
1310{
1311 MRESULT mrc = (MPARAM)FALSE; // WM_CHAR not-processed flag
1312
1313 // get object window data; this was stored in QWL_USER by
1314 // WM_INITDLG of obj_fnwpSettingsObjDetails
1315 // PXFOBJWINDATA pWinData = (PXFOBJWINDATA)WinQueryWindowULong(hwndEdit, QWL_USER);
1316 PFNWP pfnwpOrig = (PFNWP)WinQueryWindowULong(hwndEdit, QWL_USER);
1317
1318 switch (msg)
1319 {
1320 case WM_CHAR:
1321 {
1322 /*
1323 #define KC_CHAR 0x0001
1324 #define KC_VIRTUALKEY 0x0002
1325 #define KC_SCANCODE 0x0004
1326 #define KC_SHIFT 0x0008
1327 #define KC_CTRL 0x0010
1328 #define KC_ALT 0x0020
1329 #define KC_KEYUP 0x0040
1330 #define KC_PREVDOWN 0x0080
1331 #define KC_LONEKEY 0x0100
1332 #define KC_DEADKEY 0x0200
1333 #define KC_COMPOSITE 0x0400
1334 #define KC_INVALIDCOMP 0x0800
1335 */
1336
1337 /*
1338 Examples: usFlags usKeyCode
1339 F3 02 22
1340 Ctrl+F4 12 23
1341 Ctrl+Shift+F4 1a 23
1342 Ctrl 12 0a
1343 Alt 22 0b
1344 Shift 0a 09
1345 */
1346
1347 // USHORT usCommand;
1348 // USHORT usKeyCode;
1349 USHORT usFlags = SHORT1FROMMP(mp1);
1350 // UCHAR ucRepeat = CHAR3FROMMP(mp1);
1351 UCHAR ucScanCode = CHAR4FROMMP(mp1);
1352 USHORT usch = SHORT1FROMMP(mp2);
1353 USHORT usvk = SHORT2FROMMP(mp2);
1354
1355 if (
1356 // process only key-down messages
1357 ((usFlags & KC_KEYUP) == 0)
1358 // check flags:
1359 // filter out those ugly composite key (accents etc.)
1360 && ((usFlags & (KC_DEADKEY | KC_COMPOSITE | KC_INVALIDCOMP)) == 0)
1361 )
1362 {
1363 HOTKEYNOTIFY hkn;
1364 ULONG flReturned;
1365 HWND hwndOwner = WinQueryWindow(hwndEdit, QW_OWNER);
1366
1367 usFlags &= (KC_VIRTUALKEY | KC_CTRL | KC_ALT | KC_SHIFT);
1368
1369 hkn.usFlags = usFlags;
1370 hkn.usvk = usvk;
1371 hkn.usch = usch;
1372 hkn.ucScanCode = ucScanCode;
1373
1374 if (usFlags & KC_VIRTUALKEY)
1375 hkn.usKeyCode = usvk;
1376 else
1377 hkn.usKeyCode = usch;
1378
1379 hkn.szDescription[0] = 0;
1380
1381 flReturned = (ULONG)WinSendMsg(hwndOwner,
1382 WM_CONTROL,
1383 MPFROM2SHORT(WinQueryWindowUShort(hwndEdit,
1384 QWS_ID),
1385 EN_HOTKEY), // new notification code
1386 (MPARAM)&hkn);
1387 if (flReturned & HEFL_SETTEXT)
1388 WinSetWindowText(hwndEdit, hkn.szDescription);
1389 else if (flReturned & HEFL_FORWARD2OWNER)
1390 WinPostMsg(hwndOwner,
1391 WM_CHAR,
1392 mp1, mp2);
1393 else
1394 // fixed V0.9.16 (2001-12-06) [umoeller]:
1395 // do not clear the entry field if we had HEFL_FORWARD2OWNER
1396 WinSetWindowText(hwndEdit, "");
1397
1398 mrc = (MPARAM)TRUE; // WM_CHAR processed flag;
1399 }
1400 }
1401 break;
1402
1403 default:
1404 mrc = pfnwpOrig(hwndEdit, msg, mp1, mp2);
1405 }
1406 return mrc;
1407}
1408
1409/*
1410 *@@ ctlMakeHotkeyEntryField:
1411 * this turns any entry field into a "hotkey entry field"
1412 * by subclassing it with ctl_fnwpObjectHotkeyEntryField.
1413 * See remarks there for details.
1414 *
1415 * Returns FALSE upon errors, TRUE otherwise.
1416 *
1417 *@@added V0.9.1 (99-12-19) [umoeller]
1418 */
1419
1420BOOL ctlMakeHotkeyEntryField(HWND hwndHotkeyEntryField)
1421{
1422 PFNWP pfnwpOrig = WinSubclassWindow(hwndHotkeyEntryField,
1423 ctl_fnwpObjectHotkeyEntryField);
1424 if (pfnwpOrig)
1425 {
1426 WinSetWindowPtr(hwndHotkeyEntryField, QWL_USER, (PVOID)pfnwpOrig);
1427 return (TRUE);
1428 }
1429
1430 return (FALSE);
1431}
1432
1433/* ******************************************************************
1434 *
1435 * Color rectangle
1436 *
1437 ********************************************************************/
1438
1439static PFNWP G_pfnwpOrigStatic = NULL;
1440
1441/*
1442 *@@ ctl_fnwpSubclassedColorRect:
1443 * window procedure for subclassed static frames representing
1444 * a color.
1445 *
1446 * The control simply paints itself as a rectangle with the
1447 * color specified in its PP_BACKGROUNDCOLOR presentation
1448 * parameter. If a window text is set for the control, it is
1449 * painted with the PP_FOREGROUNDCOLOR color.
1450 *
1451 * If the user drags a color onto the control, it notifies
1452 * its owner with the WM_CONTROL message and the EN_CHANGE
1453 * notification code, as with any entry field (since the
1454 * static control knows no notifications, we use that code
1455 * instead).
1456 *
1457 *@@added V0.9.16 (2002-01-05) [umoeller]
1458 *@@changed V0.9.19 (2002-06-02) [umoeller]: moved this here from w_pulse.c
1459 */
1460
1461static MRESULT EXPENTRY ctl_fnwpSubclassedColorRect(HWND hwndStatic, ULONG msg, MPARAM mp1, MPARAM mp2)
1462{
1463 MRESULT mrc = 0;
1464
1465 switch (msg)
1466 {
1467 case WM_PAINT:
1468 {
1469 LONG lColor;
1470 RECTL rclPaint;
1471 PSZ pszText;
1472
1473 HPS hps = WinBeginPaint(hwndStatic,
1474 NULLHANDLE, // HPS
1475 NULL); // PRECTL
1476 gpihSwitchToRGB(hps);
1477 WinQueryWindowRect(hwndStatic,
1478 &rclPaint); // exclusive
1479 lColor = winhQueryPresColor(hwndStatic,
1480 PP_BACKGROUNDCOLOR,
1481 FALSE, // no inherit
1482 SYSCLR_DIALOGBACKGROUND);
1483
1484 // make rect inclusive
1485 rclPaint.xRight--;
1486 rclPaint.yTop--;
1487
1488 // draw interior
1489 GpiSetColor(hps, lColor);
1490 gpihBox(hps,
1491 DRO_FILL,
1492 &rclPaint);
1493
1494 // draw frame
1495 GpiSetColor(hps, RGBCOL_BLACK);
1496 gpihBox(hps,
1497 DRO_OUTLINE,
1498 &rclPaint);
1499
1500 if (pszText = winhQueryWindowText(hwndStatic))
1501 {
1502 GpiSetColor(hps,
1503 winhQueryPresColor(hwndStatic,
1504 PP_FOREGROUNDCOLOR,
1505 FALSE,
1506 -1));
1507 WinDrawText(hps,
1508 strlen(pszText),
1509 pszText,
1510 &rclPaint,
1511 0,
1512 0,
1513 DT_CENTER | DT_VCENTER | DT_TEXTATTRS);
1514
1515 free(pszText);
1516 }
1517
1518 WinEndPaint(hps);
1519 }
1520 break;
1521
1522 case WM_PRESPARAMCHANGED:
1523 switch ((ULONG)mp1)
1524 {
1525 case PP_BACKGROUNDCOLOR:
1526 WinInvalidateRect(hwndStatic,
1527 NULL,
1528 FALSE);
1529 // notify owner; since the static control
1530 // doesn't send any notifications, we
1531 // use EN_CHANGED
1532 WinSendMsg(WinQueryWindow(hwndStatic, QW_OWNER),
1533 WM_CONTROL,
1534 MPFROM2SHORT(WinQueryWindowUShort(hwndStatic, QWS_ID),
1535 EN_CHANGE),
1536 (MPARAM)hwndStatic);
1537 break;
1538 }
1539 break;
1540
1541 default:
1542 mrc = G_pfnwpOrigStatic(hwndStatic, msg, mp1, mp2);
1543 break;
1544 }
1545
1546 return mrc;
1547}
1548
1549/*
1550 *@@ ctlMakeColorRect:
1551 * turns a static rectangle into a color rectangle.
1552 *
1553 *@@added V0.9.19 (2002-06-02) [umoeller]
1554 */
1555
1556BOOL ctlMakeColorRect(HWND hwndStatic)
1557{
1558 PFNWP pfnwp;
1559
1560 if (pfnwp = WinSubclassWindow(hwndStatic,
1561 ctl_fnwpSubclassedColorRect))
1562 {
1563 G_pfnwpOrigStatic = pfnwp;
1564 return TRUE;
1565 }
1566
1567 return FALSE;
1568}
1569
1570
Note: See TracBrowser for help on using the repository browser.