source: branches/branch-1-0/src/helpers/winh.c@ 338

Last change on this file since 338 was 338, checked in by pr, 19 years ago

Fix warning

  • Property svn:eol-style set to CRLF
  • Property svn:keywords set to Author Date Id Revision
File size: 189.1 KB
Line 
1
2/*
3 *@@sourcefile winh.c:
4 * contains Presentation Manager helper functions that are
5 * independent of a single application, i.e. these can be
6 * used w/out the rest of the XWorkplace source in any PM
7 * program.
8 *
9 * Usage: All PM programs.
10 *
11 * Function prefixes (new with V0.81):
12 * -- winh* Win (Presentation Manager) helper functions
13 *
14 * Note: Version numbering in this file relates to XWorkplace version
15 * numbering.
16 *
17 *@@header "helpers\winh.h"
18 */
19
20/*
21 * Copyright (C) 1997-2006 Ulrich M”ller.
22 * This file is part of the "XWorkplace helpers" source package.
23 * This is free software; you can redistribute it and/or modify
24 * it under the terms of the GNU General Public License as published
25 * by the Free Software Foundation, in version 2 as it comes in the
26 * "COPYING" file of the XWorkplace main distribution.
27 * This program is distributed in the hope that it will be useful,
28 * but WITHOUT ANY WARRANTY; without even the implied warranty of
29 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
30 * GNU General Public License for more details.
31 */
32
33#define OS2EMX_PLAIN_CHAR
34 // this is needed for "os2emx.h"; if this is defined,
35 // emx will define PSZ as _signed_ char, otherwise
36 // as unsigned char
37
38#define INCL_DOSPROCESS
39#define INCL_DOSMODULEMGR
40#define INCL_DOSSEMAPHORES
41#define INCL_DOSDEVICES
42#define INCL_DOSDEVIOCTL
43#define INCL_DOSSESMGR
44#define INCL_DOSERRORS
45
46#define INCL_WINWINDOWMGR
47#define INCL_WINMESSAGEMGR
48#define INCL_WINFRAMEMGR
49#define INCL_WININPUT
50#define INCL_WINDIALOGS
51#define INCL_WINPOINTERS
52#define INCL_WINRECTANGLES
53#define INCL_WINSHELLDATA
54#define INCL_WINTIMER
55#define INCL_WINSYS
56#define INCL_WINHELP
57#define INCL_WINPROGRAMLIST
58#define INCL_WINSWITCHLIST
59#define INCL_WINBUTTONS
60#define INCL_WINSTATICS
61#define INCL_WINMENUS
62#define INCL_WINENTRYFIELDS
63#define INCL_WINSCROLLBARS
64#define INCL_WINLISTBOXES
65#define INCL_WINSTDSPIN
66#define INCL_WINSTDSLIDER
67#define INCL_WINCIRCULARSLIDER
68#define INCL_WINSTDFILE
69#define INCL_WINCLIPBOARD
70
71#define INCL_SPL
72#define INCL_SPLDOSPRINT
73#define INCL_SPLERRORS
74
75#define INCL_GPIBITMAPS
76#define INCL_GPIPRIMITIVES
77#include <os2.h>
78
79#include <stdlib.h>
80#include <string.h>
81#include <stdio.h>
82#include <stdarg.h>
83
84#include "setup.h" // code generation and debugging options
85
86#include "helpers\dosh.h"
87#include "helpers\winh.h"
88#include "helpers\prfh.h"
89#include "helpers\gpih.h"
90#include "helpers\nls.h"
91#include "helpers\standards.h"
92#include "helpers\stringh.h"
93#include "helpers\xstring.h" // extended string helpers
94
95/*
96 *@@category: Helpers\PM helpers\Wrappers
97 */
98
99/* ******************************************************************
100 *
101 * Wrappers
102 *
103 ********************************************************************/
104
105#ifdef WINH_STANDARDWRAPPERS
106
107 /*
108 *@@ winhSendMsg:
109 * wrapper for WinSendMsg.
110 *
111 * If WINH_STANDARDWRAPPERS is #defined before
112 * including win.h, all WinSendMsg calls are
113 * redefined to use this wrapper instead. This
114 * reduces the amount of external fixups required
115 * for loading the module.
116 *
117 *@@added V0.9.12 (2001-05-18) [umoeller]
118 */
119
120 MRESULT winhSendMsg(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
121 {
122 // put the call in brackets so the macro won't apply here
123 return ((WinSendMsg)(hwnd, msg, mp1, mp2));
124 }
125
126 /*
127 *@@ winhSendDlgItemMsg:
128 * wrapper for WinSendDlgItemMsg.
129 *
130 * If WINH_STANDARDWRAPPERS is #defined before
131 * including win.h, all WinSendMsg calls are
132 * redefined to use this wrapper instead. This
133 * reduces the amount of external fixups required
134 * for loading the module.
135 *
136 *@@added V0.9.13 (2001-06-27) [umoeller]
137 */
138
139 MRESULT winhSendDlgItemMsg(HWND hwnd, ULONG id, ULONG msg, MPARAM mp1, MPARAM mp2)
140 {
141 return ((WinSendDlgItemMsg)(hwnd, id, msg, mp1, mp2));
142 }
143
144 /*
145 *@@ winhPostMsg:
146 * wrapper for WinPostMsg.
147 *
148 * If WINH_STANDARDWRAPPERS is #defined before
149 * including win.h, all WinSendMsg calls are
150 * redefined to use this wrapper instead. This
151 * reduces the amount of external fixups required
152 * for loading the module.
153 *
154 *@@added V0.9.12 (2001-05-18) [umoeller]
155 */
156
157 BOOL winhPostMsg(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
158 {
159 // put the call in brackets so the macro won't apply here
160 return ((WinPostMsg)(hwnd, msg, mp1, mp2));
161 }
162
163 /*
164 *@@ winhWindowFromID:
165 *
166 *@@added V0.9.12 (2001-05-18) [umoeller]
167 */
168
169 HWND winhWindowFromID(HWND hwnd, ULONG id)
170 {
171 // put the call in brackets so the macro won't apply here
172 return ((WinWindowFromID)(hwnd, id));
173 }
174
175 /*
176 *@@ winhQueryWindow:
177 *
178 *@@added V0.9.12 (2001-05-18) [umoeller]
179 */
180
181 HWND winhQueryWindow(HWND hwnd, LONG lCode)
182 {
183 // put the call in brackets so the macro won't apply here
184 return ((WinQueryWindow)(hwnd, lCode));
185 }
186
187 /*
188 *@@ winhQueryWindowPtr:
189 *
190 *@@added V0.9.13 (2001-06-21) [umoeller]
191 */
192
193 PVOID winhQueryWindowPtr(HWND hwnd, LONG index)
194 {
195 // put the call in brackets so the macro won't apply here
196 return ((WinQueryWindowPtr)(hwnd, index));
197 }
198
199 /*
200 *@@ winhSetWindowText2:
201 *
202 *@@added V0.9.13 (2001-06-21) [umoeller]
203 */
204
205 BOOL winhSetWindowText2(HWND hwnd, const char *pcsz)
206 {
207 // put the call in brackets so the macro won't apply here
208 return (WinSetWindowText)(hwnd, (PSZ)pcsz);
209 }
210
211 /*
212 *@@ winhSetDlgItemText:
213 *
214 *@@added V0.9.13 (2001-06-21) [umoeller]
215 */
216
217 BOOL winhSetDlgItemText(HWND hwnd, ULONG id, const char *pcsz)
218 {
219 // put the call in brackets so the macro won't apply here
220 return (WinSetDlgItemText)(hwnd, id, (PSZ)pcsz);
221 }
222
223 /*
224 *@@ winhRequestMutexSem:
225 *
226 *@@added V0.9.16 (2002-01-26) [umoeller]
227 */
228
229 APIRET winhRequestMutexSem(HMTX hmtx, ULONG ulTimeout)
230 {
231 // put the call in brackets so the macro won't apply here
232 return (WinRequestMutexSem)(hmtx, ulTimeout);
233 }
234
235#endif // WINH_STANDARDWRAPPERS
236
237/*
238 *@@category: Helpers\PM helpers\Rectangle helpers
239 */
240
241/* ******************************************************************
242 *
243 * Rectangle helpers
244 *
245 ********************************************************************/
246
247/*
248 *@@ winhOffsetRect:
249 * like WinOffsetRect, but doesn't require
250 * an anchor block to be passed in. Why
251 * the original would need an anchor block
252 * for this awfully complicated task is
253 * a mystery to me anyway.
254 *
255 *@@added V0.9.9 (2001-03-13) [umoeller]
256 */
257
258VOID winhOffsetRect(PRECTL prcl,
259 LONG lx,
260 LONG ly)
261{
262 prcl->xLeft += lx;
263 prcl->xRight += lx;
264 prcl->yBottom += ly;
265 prcl->yTop += ly;
266}
267
268/*
269 *@@category: Helpers\PM helpers\Generics
270 */
271
272/* ******************************************************************
273 *
274 * Generics
275 *
276 ********************************************************************/
277
278/*
279 *@@ winhQueryWindowStyle:
280 *
281 *@@added V0.9.13 (2001-07-02) [umoeller]
282 */
283
284ULONG winhQueryWindowStyle(HWND hwnd)
285{
286 return WinQueryWindowULong(hwnd, QWL_STYLE);
287}
288
289/*
290 *@@ winhEnableDlgItem:
291 *
292 *@@added V0.9.12 (2001-05-18) [umoeller]
293 */
294
295BOOL winhEnableDlgItem(HWND hwndDlg,
296 SHORT id,
297 BOOL fEnable)
298{
299 return WinEnableWindow(WinWindowFromID(hwndDlg, id), fEnable);
300}
301
302/*
303 *@@ winhIsDlgItemEnabled:
304 *
305 *@@added V0.9.12 (2001-05-18) [umoeller]
306 */
307
308BOOL winhIsDlgItemEnabled(HWND hwndDlg,
309 SHORT id)
310{
311 return WinIsWindowEnabled(WinWindowFromID(hwndDlg, id));
312}
313
314
315/*
316 *@@category: Helpers\PM helpers\Menu helpers
317 */
318
319/* ******************************************************************
320 *
321 * Menu helpers
322 *
323 ********************************************************************/
324
325/*
326 *@@ winhQueryMenuItem:
327 * wrapper around MM_QUERYITEM.
328 *
329 *@@added V0.9.12 (2001-05-18) [umoeller]
330 */
331
332BOOL winhQueryMenuItem(HWND hwndMenu,
333 USHORT usItemID,
334 BOOL fSearchSubmenus,
335 PMENUITEM pmi) // out: MENUITEM data
336{
337 return (BOOL)WinSendMsg(hwndMenu,
338 MM_QUERYITEM,
339 MPFROM2SHORT(usItemID, fSearchSubmenus),
340 (MPARAM)pmi);
341}
342
343/*
344 *@@ winhQuerySubmenu:
345 * tests whether sID specifies a submenu in
346 * hMenu and returns the submenu window handle
347 * if so.
348 *
349 *@@added V0.9.20 (2002-08-10) [umoeller]
350 */
351
352HWND winhQuerySubmenu(HWND hMenu,
353 SHORT sID)
354{
355 MENUITEM mi = {0};
356 if ( (WinSendMsg(hMenu,
357 MM_QUERYITEM,
358 MPFROM2SHORT(sID,
359 FALSE),
360 (MPARAM)&mi))
361 && (mi.afStyle & MIS_SUBMENU)
362 )
363 return mi.hwndSubMenu;
364
365 return NULLHANDLE;
366}
367
368/*
369 *@@ winhInsertMenuItem:
370 * this inserts one one menu item into a given menu.
371 *
372 * Returns the return value of the MM_INSERTITEM msg:
373 * -- MIT_MEMERROR: space allocation for menu item failed
374 * -- MIT_ERROR: other error
375 * -- other: zero-based index of new item in menu.
376 */
377
378SHORT winhInsertMenuItem(HWND hwndMenu, // in: menu to insert item into
379 SHORT iPosition, // in: zero-based index of where to
380 // insert or MIT_END
381 SHORT sItemId, // in: ID of new menu item
382 const char *pcszItemTitle, // in: title of new menu item
383 SHORT afStyle,
384 // in: MIS_* style flags.
385 // Valid menu item styles are:
386 // -- MIS_SUBMENU
387 // -- MIS_SEPARATOR
388 // -- MIS_BITMAP: the display object is a bit map.
389 // -- MIS_TEXT: the display object is a text string.
390 // -- MIS_BUTTONSEPARATOR:
391 // The item is a menu button. Any menu can have zero,
392 // one, or two items of this type. These are the last
393 // items in a menu and are automatically displayed after
394 // a separator bar. The user cannot move the cursor to
395 // these items, but can select them with the pointing
396 // device or with the appropriate key.
397 // -- MIS_BREAK: the item begins a new row or column.
398 // -- MIS_BREAKSEPARATOR:
399 // Same as MIS_BREAK, except that it draws a separator
400 // between rows or columns of a pull-down menu.
401 // This style can only be used within a submenu.
402 // -- MIS_SYSCOMMAND:
403 // menu posts a WM_SYSCOMMAND message rather than a
404 // WM_COMMAND message.
405 // -- MIS_OWNERDRAW:
406 // WM_DRAWITEM and WM_MEASUREITEM notification messages
407 // are sent to the owner to draw the item or determine its size.
408 // -- MIS_HELP:
409 // menu posts a WM_HELP message rather than a
410 // WM_COMMAND message.
411 // -- MIS_STATIC
412 // This type of item exists for information purposes only.
413 // It cannot be selected with the pointing device or
414 // keyboard.
415 SHORT afAttr)
416 // in: MIA_* attribute flags
417 // Valid menu item attributes (afAttr) are:
418 // -- MIA_HILITED: if and only if, the item is selected.
419 // -- MIA_CHECKED: a check mark appears next to the item (submenu only).
420 // -- MIA_DISABLED: item is disabled and cannot be selected.
421 // The item is drawn in a disabled state (gray).
422 // -- MIA_FRAMED: a frame is drawn around the item (top-level menu only).
423 // -- MIA_NODISMISS:
424 // if the item is selected, the submenu remains down. A menu
425 // with this attribute is not hidden until the application
426 // or user explicitly does so, for example by selecting either
427 // another menu on the action bar or by pressing the escape key.
428{
429 MENUITEM mi;
430
431 mi.iPosition = iPosition;
432 mi.afStyle = afStyle;
433 mi.afAttribute = afAttr;
434 mi.id = sItemId;
435 mi.hwndSubMenu = 0;
436 mi.hItem = 0;
437
438 return SHORT1FROMMR(WinSendMsg(hwndMenu,
439 MM_INSERTITEM,
440 (MPARAM)&mi,
441 (MPARAM)pcszItemTitle));
442}
443
444/*
445 *@@ winhInsertSubmenu:
446 * this inserts a submenu into a given menu and, if
447 * sItemId != 0, inserts one item into this new submenu also.
448 *
449 * See winhInsertMenuItem for valid menu item styles and
450 * attributes.
451 *
452 * Returns the HWND of the new submenu.
453 */
454
455HWND winhInsertSubmenu(HWND hwndMenu, // in: menu to add submenu to
456 ULONG iPosition, // in: index where to add submenu or MIT_END
457 SHORT sMenuId, // in: menu ID of new submenu
458 const char *pcszSubmenuTitle, // in: title of new submenu
459 USHORT afMenuStyle, // in: MIS* style flags for submenu;
460 // MIS_SUBMENU will always be added
461 SHORT sItemId, // in: ID of first item to add to submenu;
462 // if 0, no first item is inserted
463 const char *pcszItemTitle, // in: title of this item
464 // (if sItemID != 0)
465 USHORT afItemStyle, // in: style flags for this item, e.g. MIS_TEXT
466 // (this is ignored if sItemID == 0)
467 USHORT afAttribute) // in: attributes for this item, e.g. MIA_DISABLED
468 // (this is ignored if sItemID == 0)
469{
470 MENUITEM mi;
471 SHORT src = MIT_ERROR;
472 HWND hwndNewMenu;
473
474 // create new, empty menu
475 hwndNewMenu = WinCreateMenu(hwndMenu,
476 NULL); // no menu template
477 if (hwndNewMenu)
478 {
479 // add "submenu item" to this empty menu;
480 // for some reason, PM always needs submenus
481 // to be a menu item
482 mi.iPosition = iPosition;
483 mi.afStyle = afMenuStyle | MIS_SUBMENU;
484 mi.afAttribute = 0;
485 mi.id = sMenuId;
486 mi.hwndSubMenu = hwndNewMenu;
487 mi.hItem = 0;
488 src = SHORT1FROMMR(WinSendMsg(hwndMenu, MM_INSERTITEM, (MPARAM)&mi, (MPARAM)pcszSubmenuTitle));
489 if ( (src != MIT_MEMERROR)
490 && (src != MIT_ERROR)
491 )
492 {
493 // set the new menu's ID to the same as the
494 // submenu item
495 WinSetWindowUShort(hwndNewMenu, QWS_ID, sMenuId);
496
497 if (sItemId)
498 {
499 // item id given: insert first menu item also
500 mi.iPosition = 0;
501 mi.afStyle = afItemStyle;
502 mi.afAttribute = afAttribute;
503 mi.id = sItemId;
504 mi.hwndSubMenu = 0;
505 mi.hItem = 0;
506 WinSendMsg(hwndNewMenu,
507 MM_INSERTITEM,
508 (MPARAM)&mi,
509 (MPARAM)pcszItemTitle);
510 }
511 }
512 }
513 return hwndNewMenu;
514}
515
516/*
517 *@@ winhSetMenuCondCascade:
518 * sets the "conditional cascade" style
519 * on the specified submenu.
520 *
521 * This style must always be enabled manually
522 * because the resource compiler won't handle it.
523 *
524 * Note: Pass in the _submenu_ window handle,
525 * not the one of the parent. With lDefaultItem,
526 * specify the item ID in the submenu which is
527 * to be checked as the default item.
528 *
529 *@@added V0.9.12 (2001-05-22) [umoeller]
530 *@@changed V0.9.20 (2002-08-10) [umoeller]: now supporting calling this more than once
531 */
532
533BOOL winhSetMenuCondCascade(HWND hwndMenu, // in: submenu handle
534 LONG lDefaultItem) // in: item ID of new default item
535{
536 BOOL brc;
537 ULONG ulStyle = WinQueryWindowULong(hwndMenu, QWL_STYLE);
538 LONG lOldDefault = -1;
539
540 if (ulStyle & MS_CONDITIONALCASCADE)
541 {
542 // menu is already conditional cascade:
543 lOldDefault = (LONG)WinSendMsg(hwndMenu,
544 MM_QUERYDEFAULTITEMID,
545 0,
546 0);
547 }
548 else
549 {
550 ulStyle |= MS_CONDITIONALCASCADE;
551 WinSetWindowULong(hwndMenu, QWL_STYLE, ulStyle);
552 }
553
554 // make the first item in the subfolder
555 // the default of cascading submenu
556 brc = (BOOL)WinSendMsg(hwndMenu,
557 MM_SETDEFAULTITEMID,
558 (MPARAM)lDefaultItem,
559 0);
560
561 if ( (lOldDefault != -1)
562 && (lOldDefault != lDefaultItem)
563 )
564 {
565 // unset the "checked" attribute of the old one
566 // or we'll have two in the menu
567 WinSendMsg(hwndMenu,
568 MM_SETITEMATTR,
569 MPFROM2SHORT(lOldDefault,
570 FALSE),
571 MPFROM2SHORT(MIA_CHECKED, 0));
572 }
573
574 return brc;
575}
576
577/*
578 *@@ winhRemoveMenuItems:
579 * removes multiple menu items at once, as
580 * specified in the given array of menu item
581 * IDs.
582 *
583 *@@added V1.0.0 (2002-08-12) [umoeller]
584 */
585
586BOOL XWPENTRY winhRemoveMenuItems(HWND hwndMenu, // in: menu to remove from
587 const SHORT *asItemIDs, // in: array of menu item IDs
588 ULONG cItemIDs) // in: array item count
589{
590 ULONG ul;
591 for (ul = 0;
592 ul < cItemIDs;
593 ++ul)
594 {
595 SHORT s = asItemIDs[ul];
596 winhRemoveMenuItem(hwndMenu,
597 s);
598 }
599
600 return TRUE;
601}
602
603/*
604 *@@ winhInsertMenuSeparator:
605 * this inserts a separator into a given menu at
606 * the given position (which may be MIT_END);
607 * returns the position at which the item was
608 * inserted.
609 */
610
611SHORT winhInsertMenuSeparator(HWND hMenu, // in: menu to add separator to
612 SHORT iPosition, // in: index where to add separator or MIT_END
613 SHORT sId) // in: separator menu ID (doesn't really matter)
614{
615 MENUITEM mi;
616 mi.iPosition = iPosition;
617 mi.afStyle = MIS_SEPARATOR; // append separator
618 mi.afAttribute = 0;
619 mi.id = sId;
620 mi.hwndSubMenu = 0;
621 mi.hItem = 0;
622
623 return SHORT1FROMMR(WinSendMsg(hMenu,
624 MM_INSERTITEM,
625 (MPARAM)&mi,
626 (MPARAM)""));
627}
628
629/*
630 *@@ winhCopyMenuItem2:
631 * copies a menu item from hmenuSource to hmenuTarget.
632 *
633 * This creates a full duplicate. If usID specifies
634 * a submenu, the entire submenu is copied as well
635 * (this will then recurse).
636 *
637 * fl can be any combination of:
638 *
639 * -- COPYFL_STRIPTABS: strip off \t and everything
640 * that follows, if present.
641 *
642 * NOTE: Copying submenus will work only if each item
643 * in the submenu has a unique menu ID. This is due
644 * to the dumb implementation of menus in PM where
645 * it is impossible to query menu items without
646 * knowing their ID.
647 *
648 *@@added V0.9.9 (2001-03-09) [umoeller]
649 *@@changed V0.9.20 (2002-08-10) [umoeller]: renamed, added fl
650 */
651
652BOOL winhCopyMenuItem2(HWND hmenuTarget,
653 HWND hmenuSource,
654 USHORT usID,
655 SHORT sTargetPosition, // in: position to insert at or MIT_END
656 ULONG fl) // in: COPYFL_* flags
657{
658 BOOL brc = FALSE;
659 MENUITEM mi = {0};
660 if (WinSendMsg(hmenuSource,
661 MM_QUERYITEM,
662 MPFROM2SHORT(usID,
663 FALSE),
664 (MPARAM)&mi))
665 {
666 // found in source:
667 // is it a separator?
668 if (mi.afStyle & MIS_SEPARATOR)
669 winhInsertMenuSeparator(hmenuTarget,
670 sTargetPosition,
671 usID);
672 else
673 {
674 // no separator:
675 // get item text
676 PSZ pszSource;
677 if (pszSource = winhQueryMenuItemText(hmenuSource,
678 usID))
679 {
680 PSZ p;
681 // remove the hotkey description
682 // V0.9.20 (2002-08-10) [umoeller]
683 if ( (fl & COPYFL_STRIPTABS)
684 && (p = strchr(pszSource, '\t'))
685 )
686 *p = '\0';
687
688 if ( (mi.afStyle & MIS_SUBMENU)
689 && (mi.hwndSubMenu)
690 )
691 {
692 // this is the top of a submenu:
693 HWND hwndSubMenu;
694 if (hwndSubMenu = winhInsertSubmenu(hmenuTarget,
695 sTargetPosition,
696 mi.id,
697 pszSource,
698 mi.afStyle,
699 0,
700 NULL,
701 0,
702 0))
703 {
704 // now copy all the items in the submenu
705 SHORT cMenuItems = SHORT1FROMMR(WinSendMsg(mi.hwndSubMenu,
706 MM_QUERYITEMCOUNT,
707 0,
708 0));
709 // loop through all entries in the original submenu
710 ULONG i;
711 for (i = 0;
712 i < cMenuItems;
713 i++)
714 {
715 SHORT id = SHORT1FROMMR(WinSendMsg(mi.hwndSubMenu,
716 MM_ITEMIDFROMPOSITION,
717 MPFROMSHORT(i),
718 0));
719 // recurse
720 winhCopyMenuItem2(hwndSubMenu,
721 mi.hwndSubMenu,
722 id,
723 MIT_END,
724 fl);
725 }
726
727 // now check... was the original submenu
728 // "conditional cascade"?
729 if (WinQueryWindowULong(mi.hwndSubMenu,
730 QWL_STYLE)
731 & MS_CONDITIONALCASCADE)
732 // yes:
733 {
734 // get the original default item
735 SHORT sDefID = SHORT1FROMMR(WinSendMsg(mi.hwndSubMenu,
736 MM_QUERYDEFAULTITEMID,
737 0,
738 0));
739 // set "conditional cascade style" on target too
740 winhSetMenuCondCascade(hwndSubMenu, sDefID);
741 }
742 } // end if (hwndSubmenu)
743 } // end if ( (mi.afStyle & MIS_SUBMENU)
744 else
745 {
746 // no submenu:
747 // just copy that item
748 SHORT s;
749 mi.iPosition = sTargetPosition;
750 s = SHORT1FROMMR(WinSendMsg(hmenuTarget,
751 MM_INSERTITEM,
752 MPFROMP(&mi),
753 MPFROMP(pszSource)));
754 if ( (s != MIT_MEMERROR)
755 && (s != MIT_ERROR)
756 )
757 brc = TRUE;
758 }
759
760 free(pszSource);
761
762 } // end if (pszSource)
763 } // end else if (mi.afStyle & MIS_SEPARATOR)
764 } // end if (WinSendMsg(hmenuSource, MM_QUERYITEM,...
765
766 return brc;
767}
768
769/*
770 *@@ winhCopyMenuItem:
771 * wrapper for winhCopyMenuItem2 because it was
772 * exported.
773 *
774 *@@added V0.9.20 (2002-08-10) [umoeller]
775 */
776
777BOOL winhCopyMenuItem(HWND hmenuTarget,
778 HWND hmenuSource,
779 USHORT usID,
780 SHORT sTargetPosition) // in: position to insert at or MIT_END
781{
782 return winhCopyMenuItem2(hmenuTarget, hmenuSource, usID, sTargetPosition, 0);
783}
784
785/*
786 *@@ winhMergeIntoSubMenu:
787 * creates a new submenu in hmenuTarget with the
788 * specified title at the specified position
789 * and copies the entire contents of hmenuSource
790 * into that.
791 *
792 * Returns the window handle of the new submenu
793 * or NULLHANDLE on errors.
794 *
795 * NOTE: Copying submenus will work only if each item
796 * in the submenu has a unique menu ID. This is due
797 * to the dumb implementation of menus in PM where
798 * it is impossible to query menu items without
799 * knowing their ID.
800 *
801 *@@added V0.9.9 (2001-03-09) [umoeller]
802 */
803
804HWND winhMergeIntoSubMenu(HWND hmenuTarget, // in: menu where to create submenu
805 SHORT sTargetPosition, // in: position to insert at or MIT_END
806 const char *pcszTitle, // in: title of new submenu or NULL
807 SHORT sID, // in: ID of new submenu
808 HWND hmenuSource) // in: menu to merge
809{
810 HWND hwndNewSubmenu;
811 if (hwndNewSubmenu = WinCreateMenu(hmenuTarget, NULL))
812 {
813 MENUITEM mi = {0};
814 SHORT src = 0;
815 // SHORT s = 0;
816 mi.iPosition = MIT_END;
817 mi.afStyle = MIS_TEXT | MIS_SUBMENU;
818 mi.id = 2000;
819 mi.hwndSubMenu = hwndNewSubmenu;
820
821 WinSetWindowUShort(hwndNewSubmenu, QWS_ID, sID);
822
823 // insert new submenu into hmenuTarget
824 src = SHORT1FROMMR(WinSendMsg(hmenuTarget,
825 MM_INSERTITEM,
826 (MPARAM)&mi,
827 (MPARAM)pcszTitle));
828 if ( (src != MIT_MEMERROR)
829 && (src != MIT_ERROR)
830 )
831 {
832 int i;
833 SHORT cMenuItems = SHORT1FROMMR(WinSendMsg(hmenuSource,
834 MM_QUERYITEMCOUNT,
835 0, 0));
836
837 // loop through all entries in the original menu
838 for (i = 0; i < cMenuItems; i++)
839 {
840 SHORT id = SHORT1FROMMR(WinSendMsg(hmenuSource,
841 MM_ITEMIDFROMPOSITION,
842 MPFROMSHORT(i),
843 0));
844 winhCopyMenuItem(hwndNewSubmenu,
845 hmenuSource,
846 id,
847 MIT_END);
848 }
849 }
850 else
851 {
852 // error:
853 WinDestroyWindow(hwndNewSubmenu);
854 hwndNewSubmenu = NULLHANDLE;
855 }
856 }
857
858 return hwndNewSubmenu;
859}
860
861/*
862 *@@ winhMergeIntoSubMenu:
863 * copies all items from hmenuSource into hmenuTarget,
864 * starting at the given position.
865 *
866 * Returns the no. of items that were copied.
867 *
868 * NOTE: Copying submenus will work only if each item
869 * in the submenu has a unique menu ID. This is due
870 * to the dumb implementation of menus in PM where
871 * it is impossible to query menu items without
872 * knowing their ID.
873 *
874 *@@added V0.9.20 (2002-08-10) [umoeller]
875 */
876
877ULONG winhMergeMenus(HWND hmenuTarget, // in: menu to copy items to
878 SHORT sTargetPosition, // in: position to insert at or MIT_END
879 HWND hmenuSource, // in: menu to merge
880 ULONG fl) // in: COPYFL_* flags for winhCopyMenuItem2
881{
882 SHORT sTarget = MIT_END;
883
884 int i;
885 SHORT cMenuItems = SHORT1FROMMR(WinSendMsg(hmenuSource,
886 MM_QUERYITEMCOUNT,
887 0, 0));
888
889 // loop through all entries in the original menu
890 for (i = 0; i < cMenuItems; i++)
891 {
892 SHORT id = SHORT1FROMMR(WinSendMsg(hmenuSource,
893 MM_ITEMIDFROMPOSITION,
894 MPFROM2SHORT(i, 0),
895 0));
896 winhCopyMenuItem2(hmenuTarget,
897 hmenuSource,
898 id,
899 MIT_END,
900 fl);
901 }
902
903 return i;
904}
905
906/*
907 *@@ winhClearMenu:
908 * removes all menu items from the given (sub)menu.
909 * The menu itself is not destroyed, but is empty
910 * after calling this function.
911 *
912 *@@added V1.0.0 (2002-08-31) [umoeller]
913 */
914
915ULONG winhClearMenu(HWND hwndMenu)
916{
917 ULONG cDeleted = 0;
918 SHORT sID;
919
920 // what we do is getting the menu item count
921 // and then delete the first item in the menu
922 // x times because there is no "delete menu item
923 // from position" message, and there might be
924 // duplicate IDs in the menu... this should
925 // work always
926
927 SHORT cMenuItems = SHORT1FROMMR(WinSendMsg(hwndMenu,
928 MM_QUERYITEMCOUNT,
929 0,
930 0));
931 while (cMenuItems-- > 0)
932 {
933 sID = SHORT1FROMMR(WinSendMsg(hwndMenu,
934 MM_ITEMIDFROMPOSITION,
935 MPFROMSHORT(0),
936 MPNULL));
937
938 WinSendMsg(hwndMenu,
939 MM_DELETEITEM,
940 MPFROM2SHORT(sID, FALSE),
941 0);
942
943 ++cDeleted;
944 }
945
946 return cDeleted;
947}
948
949/*
950 *@@ winhQueryMenuItemText:
951 * this returns a menu item text as a PSZ
952 * to a newly allocated buffer or NULL if
953 * not found.
954 *
955 * Returns NULL on error. Use free()
956 * to free the return value.
957 *
958 * This uses MM_QUERYITEMTEXT internally.
959 * PMREF doesn't say anything about this,
960 * but from my testing this always recurses
961 * into submenus.
962 *
963 * Use the WinSetMenuItemText macro to
964 * set the menu item text.
965 */
966
967PSZ winhQueryMenuItemText(HWND hwndMenu,
968 USHORT usItemID) // in: menu item ID (not index)
969{
970 PSZ prc = NULL;
971
972 SHORT sLength;
973 if (sLength = SHORT1FROMMR(WinSendMsg(hwndMenu,
974 MM_QUERYITEMTEXTLENGTH,
975 (MPARAM)(ULONG)usItemID,
976 (MPARAM)NULL)))
977 {
978 prc = (PSZ)malloc(sLength + 1);
979 WinSendMsg(hwndMenu,
980 MM_QUERYITEMTEXT,
981 MPFROM2SHORT(usItemID, sLength + 1),
982 (MPARAM)prc);
983 }
984
985 return prc;
986}
987
988/*
989 *@@ winhAppend2MenuItemText:
990 *
991 *@@added V0.9.2 (2000-03-08) [umoeller]
992 */
993
994BOOL winhAppend2MenuItemText(HWND hwndMenu,
995 USHORT usItemID, // in: menu item ID (not index)
996 const char *pcszAppend, // in: text to append
997 BOOL fTab) // in: if TRUE, add \t before pcszAppend
998{
999 BOOL brc = FALSE;
1000 CHAR szItemText[400];
1001 if (WinSendMsg(hwndMenu,
1002 MM_QUERYITEMTEXT,
1003 MPFROM2SHORT(usItemID,
1004 sizeof(szItemText)),
1005 (MPARAM)szItemText))
1006 {
1007 // text copied:
1008 if (fTab)
1009 {
1010 if (strchr(szItemText, '\t'))
1011 // we already have a tab:
1012 strcat(szItemText, " ");
1013 else
1014 strcat(szItemText, "\t");
1015 }
1016 strcat(szItemText, pcszAppend);
1017
1018 brc = (BOOL)WinSendMsg(hwndMenu,
1019 MM_SETITEMTEXT,
1020 MPFROMSHORT(usItemID),
1021 (MPARAM)szItemText);
1022 }
1023
1024 return brc;
1025}
1026
1027/*
1028 *@@ winhMenuRemoveEllipse:
1029 * removes a "..." substring from a menu item
1030 * title, if found. This is useful if confirmations
1031 * have been turned off for a certain menu item, which
1032 * should be reflected in the menu.
1033 */
1034
1035VOID winhMenuRemoveEllipse(HWND hwndMenu,
1036 USHORT usItemId) // in: item to remove "..." from
1037{
1038 CHAR szBuf[255];
1039 CHAR *p;
1040 WinSendMsg(hwndMenu,
1041 MM_QUERYITEMTEXT,
1042 MPFROM2SHORT(usItemId, sizeof(szBuf)-1),
1043 (MPARAM)&szBuf);
1044 if ((p = strstr(szBuf, "...")))
1045 strcpy(p, p+3);
1046 WinSendMsg(hwndMenu,
1047 MM_SETITEMTEXT,
1048 MPFROMSHORT(usItemId),
1049 (MPARAM)&szBuf);
1050}
1051
1052/*
1053 *@@ winhQueryItemUnderMouse:
1054 * this queries the menu item which corresponds
1055 * to the given mouse coordinates.
1056 * Returns the ID of the menu item and stores its
1057 * rectangle in *prtlItem; returns (-1) upon errors.
1058 */
1059
1060SHORT winhQueryItemUnderMouse(HWND hwndMenu, // in: menu handle
1061 POINTL *pptlMouse, // in: mouse coordinates
1062 RECTL *prtlItem) // out: rectangle of menu item
1063{
1064 SHORT s, sItemId, sItemCount;
1065 HAB habDesktop = WinQueryAnchorBlock(HWND_DESKTOP);
1066
1067 sItemCount = SHORT1FROMMR(WinSendMsg(hwndMenu, MM_QUERYITEMCOUNT, MPNULL, MPNULL));
1068
1069 for (s = 0;
1070 s <= sItemCount;
1071 s++)
1072 {
1073 sItemId = SHORT1FROMMR(WinSendMsg(hwndMenu,
1074 MM_ITEMIDFROMPOSITION,
1075 (MPARAM)(ULONG)s, MPNULL));
1076 WinSendMsg(hwndMenu,
1077 MM_QUERYITEMRECT,
1078 MPFROM2SHORT(sItemId, FALSE),
1079 (MPARAM)prtlItem);
1080 if (WinPtInRect(habDesktop, prtlItem, pptlMouse))
1081 return sItemId;
1082 }
1083 /* sItemId = (SHORT)WinSendMsg(hwndMenu, MM_ITEMIDFROMPOSITION, (MPARAM)(sItemCount-1), MPNULL);
1084 return (sItemId); */
1085
1086 return -1; // error: no valid menu item
1087}
1088
1089/*
1090 *@@category: Helpers\PM helpers\Slider helpers
1091 */
1092
1093/* ******************************************************************
1094 *
1095 * Slider helpers
1096 *
1097 ********************************************************************/
1098
1099/*
1100 *@@ winhReplaceWithLinearSlider:
1101 * this destroys the control with the ID ulID in hwndDlg
1102 * and creates a linear slider at the same position with the
1103 * same ID (effectively replacing it).
1104 *
1105 * This is needed because the IBM dialog editor (DLGEDIT.EXE)
1106 * keeps crashing when creating sliders. So the way to do
1107 * this easily is to create some other control with DLGEDIT
1108 * where the slider should be later and call this function
1109 * on that control when the dialog is initialized.
1110 *
1111 * You need to specify _one_ of the following with ulSliderStyle:
1112 * -- SLS_HORIZONTAL: horizontal slider (default)
1113 * -- SLS_VERTICAL: vertical slider
1114 *
1115 * plus _one_ additional common slider style for positioning:
1116 * -- for horizontal sliders: SLS_BOTTOM, SLS_CENTER, or SLS_TOP
1117 * -- for vertical sliders: SLS_LEFT, SLS_CENTER, or SLS_RIGHT
1118 *
1119 * Additional common slider styles are:
1120 * -- SLS_PRIMARYSCALE1: determines the location of the scale
1121 * on the slider shaft by using increment
1122 * and spacing specified for scale 1 as
1123 * the incremental value for positioning
1124 * the slider arm. Scale 1 is displayed
1125 * above the slider shaft of a horizontal
1126 * slider and to the right of the slider
1127 * shaft of a vertical slider. This is
1128 * the default for a slider.
1129 * -- SLS_PRIMARYSCALE2: not supported by this function
1130 * -- SLS_READONLY: creates a read-only slider, which
1131 * presents information to the user but
1132 * allows no interaction with the user.
1133 * -- SLS_RIBBONSTRIP: fills, as the slider arm moves, the
1134 * slider shaft between the home position
1135 * and the slider arm with a color value
1136 * different from slider shaft color,
1137 * similar to mercury in a thermometer.
1138 * -- SLS_OWNERDRAW: notifies the application whenever the
1139 * slider shaft, the ribbon strip, the
1140 * slider arm, and the slider background
1141 * are to be drawn.
1142 * -- SLS_SNAPTOINCREMENT: causes the slider arm, when positioned
1143 * between two values, to be positioned
1144 * to the nearest value and redrawn at
1145 * that position.
1146 *
1147 * Additionally, for horizontal sliders:
1148 * -- SLS_BUTTONSLEFT: specifies that the optional slider
1149 * buttons are to be used and places them
1150 * to the left of the slider shaft. The
1151 * buttons move the slider arm by one
1152 * position, left or right, in the
1153 * direction selected.
1154 * -- SLS_BUTTONSRIGHT: specifies that the optional slider
1155 * buttons are to be used and places them
1156 * to the right of the slider shaft. The
1157 * buttons move the slider arm by one
1158 * position, left or right, in the
1159 * direction selected.
1160 * -- SLS_HOMELEFT: specifies the slider arm's home
1161 * position. The left edge is used as the
1162 * base value for incrementing (default).
1163 * -- SLS_HOMERIGHT: specifies the slider arm's home
1164 * position. The right edge is used as
1165 * the base value for incrementing.
1166 *
1167 * Instead, for vertical sliders:
1168 * -- SLS_BUTTONSBOTTOM: specifies that the optional slider
1169 * buttons are to be used and places them
1170 * at the bottom of the slider shaft. The
1171 * buttons move the slider arm by one
1172 * position, up or down, in the direction
1173 * selected.
1174 * -- SLS_BUTTONSTOP: specifies that the optional slider
1175 * buttons are to be used and places them
1176 * at the top of the slider shaft. The
1177 * buttons move the slider arm by one
1178 * position, up or down, in the direction
1179 * selected.
1180 * -- SLS_HOMEBOTTOM: specifies the slider arm's home
1181 * position. The bottom of the slider is
1182 * used as the base value for
1183 * incrementing.
1184 * -- SLS_HOMETOP: specifies the slider arm's home
1185 * position. The top of the slider is
1186 * used as the base value for
1187 * incrementing.
1188 *
1189 * Notes: This function automatically adds WS_PARENTCLIP,
1190 * WS_TABSTOP, and WS_SYNCPAINT to the specified styles.
1191 * For the WS_TABSTOP style, hwndInsertAfter is important.
1192 * If you specify HWND_TOP, your window will be the first
1193 * in the tab stop list.
1194 *
1195 * It also shows the slider after having done all the
1196 * processing in here by calling WinShowWindow.
1197 *
1198 * Also, we only provide support for scale 1 here, so
1199 * do not specify SLS_PRIMARYSCALE2 with ulSliderStyle,
1200 * and we have the slider calculate all the spacings.
1201 *
1202 * This returns the HWND of the slider or NULLHANDLE upon
1203 * errors.
1204 *
1205 *@@added V0.9.0 [umoeller]
1206 */
1207
1208HWND winhReplaceWithLinearSlider(HWND hwndParent, // in: parent of old control and slider
1209 HWND hwndOwner, // in: owner of old control and slider
1210 HWND hwndInsertAfter, // in: the control after which the slider should
1211 // come up, or HWND_TOP, or HWND_BOTTOM
1212 ULONG ulID, // in: ID of old control and slider
1213 ULONG ulSliderStyle, // in: SLS_* styles
1214 ULONG ulTickCount) // in: number of ticks (scale 1)
1215{
1216 HWND hwndSlider = NULLHANDLE;
1217 HWND hwndKill = WinWindowFromID(hwndParent, ulID);
1218 if (hwndKill)
1219 {
1220 SWP swpControl;
1221 if (WinQueryWindowPos(hwndKill, &swpControl))
1222 {
1223 SLDCDATA slcd;
1224
1225 // destroy the old control
1226 WinDestroyWindow(hwndKill);
1227
1228 // initialize slider control data
1229 slcd.cbSize = sizeof(SLDCDATA);
1230 slcd.usScale1Increments = ulTickCount;
1231 slcd.usScale1Spacing = 0; // have slider calculate it
1232 slcd.usScale2Increments = 0;
1233 slcd.usScale2Spacing = 0;
1234
1235 // create a slider with the same ID at the same
1236 // position
1237 hwndSlider = WinCreateWindow(hwndParent,
1238 WC_SLIDER,
1239 NULL, // no window text
1240 ulSliderStyle
1241 | WS_PARENTCLIP
1242 | WS_SYNCPAINT
1243 | WS_TABSTOP,
1244 swpControl.x,
1245 swpControl.y,
1246 swpControl.cx,
1247 swpControl.cy,
1248 hwndOwner,
1249 hwndInsertAfter,
1250 ulID, // same ID as destroyed control
1251 &slcd, // slider control data
1252 NULL); // presparams
1253
1254 WinSendMsg(hwndSlider,
1255 SLM_SETTICKSIZE,
1256 MPFROM2SHORT(SMA_SETALLTICKS,
1257 6), // 15 pixels high
1258 NULL);
1259
1260 WinShowWindow(hwndSlider, TRUE);
1261 }
1262 }
1263
1264 return hwndSlider;
1265}
1266
1267/*
1268 *@@ winhSetSliderTicks:
1269 * this adds ticks to the given linear slider,
1270 * which are ulPixels pixels high. A useful
1271 * value for this is 4.
1272 *
1273 * This queries the slider for the primary
1274 * scale values. Only the primary scale is
1275 * supported.
1276 *
1277 * This function goes sets the ticks twice,
1278 * once with mpEveryOther1 and ulPixels1,
1279 * and then a second time with mpEveryOther2
1280 * and ulPixels2. This allows you to quickly
1281 * give, say, every tenth item a taller tick.
1282 *
1283 * For every set, if mpEveryOther is 0, this sets
1284 * all ticks on the primary slider scale.
1285 *
1286 * If mpEveryOther is != 0, SHORT1FROMMP
1287 * specifies the first tick to set, and
1288 * SHORT2FROMMP specifies every other tick
1289 * to set from there. For example:
1290 *
1291 + MPFROM2SHORT(9, 10)
1292 *
1293 * would set tick 9, 19, 29, and so forth.
1294 *
1295 * If both mpEveryOther and ulPixels are -1,
1296 * that set is skipped.
1297 *
1298 * Example: Considering a slider with a
1299 * primary scale from 0 to 30, using
1300 *
1301 + winhSetSliderTicks(hwndSlider,
1302 + 0, // every tick
1303 + 3, // to three pixels
1304 + MPFROM2SHORT(9, 10) // then every tenth
1305 + 6); // to six pixels.
1306 *
1307 * Returns FALSE upon errors.
1308 *
1309 *@@added V0.9.1 (99-12-04) [umoeller]
1310 *@@changed V0.9.7 (2001-01-18) [umoeller]: added second set
1311 */
1312
1313BOOL winhSetSliderTicks(HWND hwndSlider, // in: linear slider
1314 MPARAM mpEveryOther1, // in: set 1
1315 ULONG ulPixels1,
1316 MPARAM mpEveryOther2, // in: set 2
1317 ULONG ulPixels2)
1318{
1319 BOOL brc = FALSE;
1320
1321 ULONG ulSet;
1322 MPARAM mpEveryOther = mpEveryOther1;
1323 ULONG ulPixels = ulPixels1;
1324
1325 // do this twice
1326 for (ulSet = 0;
1327 ulSet < 2;
1328 ulSet++)
1329 {
1330 if (mpEveryOther == 0)
1331 {
1332 // set all ticks:
1333 brc = (BOOL)WinSendMsg(hwndSlider,
1334 SLM_SETTICKSIZE,
1335 MPFROM2SHORT(SMA_SETALLTICKS,
1336 ulPixels),
1337 NULL);
1338 }
1339 else if ( (mpEveryOther != (MPARAM)-1) && (ulPixels != -1) )
1340 {
1341 SLDCDATA slcd;
1342 WNDPARAMS wp;
1343 memset(&wp, 0, sizeof(WNDPARAMS));
1344 wp.fsStatus = WPM_CTLDATA;
1345 wp.cbCtlData = sizeof(slcd);
1346 wp.pCtlData = &slcd;
1347 // get primary scale data from the slider
1348 if (WinSendMsg(hwndSlider,
1349 WM_QUERYWINDOWPARAMS,
1350 (MPARAM)&wp,
1351 0))
1352 {
1353 USHORT usStart = SHORT1FROMMP(mpEveryOther),
1354 usEveryOther = SHORT2FROMMP(mpEveryOther);
1355
1356 USHORT usScale1Max = slcd.usScale1Increments,
1357 us;
1358
1359 brc = TRUE;
1360
1361 for (us = usStart; us < usScale1Max; us += usEveryOther)
1362 {
1363 if (!(BOOL)WinSendMsg(hwndSlider,
1364 SLM_SETTICKSIZE,
1365 MPFROM2SHORT(us,
1366 ulPixels),
1367 NULL))
1368 {
1369 brc = FALSE;
1370 break;
1371 }
1372 }
1373 }
1374 }
1375
1376 // for the second loop, use second value set
1377 mpEveryOther = mpEveryOther2;
1378 ulPixels = ulPixels2;
1379 // we only loop twice
1380 } // end for (ulSet = 0; ulSet < 2;
1381
1382 return brc;
1383}
1384
1385/*
1386 *@@ winhReplaceWithCircularSlider:
1387 * this destroys the control with the ID ulID in hwndDlg
1388 * and creates a linear slider at the same position with the
1389 * same ID (effectively replacing it).
1390 *
1391 * This is needed because the IBM dialog editor (DLGEDIT.EXE)
1392 * cannot create circular sliders. So the way to do this
1393 * easily is to create some other control with DLGEDIT
1394 * where the slider should be later and call this function
1395 * on that control when the dialog is initialized.
1396 *
1397 * You need to specify the following with ulSliderStyle:
1398 * -- CSS_CIRCULARVALUE: draws a circular thumb, rather than a line,
1399 * for the value indicator.
1400 * -- CSS_MIDPOINT: makes the mid-point tick mark larger.
1401 * -- CSS_NOBUTTON: does not display value buttons. Per default, the
1402 * slider displays "-" and "+" buttons to the bottom left
1403 * and bottom right of the knob. (BTW, these bitmaps can be
1404 * changed using CSM_SETBITMAPDATA.)
1405 * -- CSS_NONUMBER: does not display the value on the dial.
1406 * -- CSS_NOTEXT: does not display title text under the dial.
1407 * Otherwise, the text in the pszTitle parameter
1408 * will be used.
1409 * -- CSS_NOTICKS (only listed in pmstddlg.h, not in PMREF):
1410 * obviously, this prevents tick marks from being drawn.
1411 * -- CSS_POINTSELECT: permits the values on the circular slider
1412 * to change immediately when dragged.
1413 * Direct manipulation is performed by using a mouse to
1414 * click on and drag the circular slider. There are two
1415 * modes of direct manipulation for the circular slider:
1416 * <BR><B>1)</B> The default direct manipulation mode is to scroll to
1417 * the value indicated by the position of the mouse.
1418 * This could be important if you used a circular slider
1419 * for a volume control, for example. Increasing the volume
1420 * from 0% to 100% too quickly could result in damage to
1421 * both the user's ears and the equipment.
1422 * <BR><B>2)</B>The other mode of direct manipulation permits
1423 * the value on the circular slider to change immediately when dragged.
1424 * This mode is enabled using the CSS_POINTSELECT style bit. When this
1425 * style is used, the value of the dial can be changed by tracking
1426 * the value with the mouse, which changes values quickly.
1427 * -- CSS_PROPORTIONALTICKS: allow the length of the tick marks to be calculated
1428 * as a percentage of the radius (for small sliders).
1429 * -- CSS_360: permits the scroll range to extend 360 degrees.
1430 * CSS_360 forces the CSS_NONUMBER style on. This is necessary
1431 * to keep the value indicator from corrupting the number value.
1432 *
1433 * FYI: The most commonly known circular slider in OS/2, the one in the
1434 * default "Sound" object, has a style of 0x9002018a, meaning
1435 * CSS_NOTEXT | CSS_POINTSELECT | CSS_NOTICKS.
1436 *
1437 * Notes: This function automatically adds WS_PARENTCLIP,
1438 * WS_TABSTOP, and WS_SYNCPAINT to the specified styles.
1439 * For the WS_TABSTOP style, hwndInsertAfter is important.
1440 * If you specify HWND_TOP, your window will be the first
1441 * in the tab stop list.
1442 *
1443 * It also shows the slider after having done all the
1444 * processing in here by calling WinShowWindow.
1445 *
1446 * This returns the HWND of the slider or NULLHANDLE upon
1447 * errors.
1448 *
1449 *@@added V0.9.0 [umoeller]
1450 */
1451
1452HWND winhReplaceWithCircularSlider(HWND hwndParent, // in: parent of old control and slider
1453 HWND hwndOwner, // in: owner of old control and slider
1454 HWND hwndInsertAfter, // in: the control after which the slider should
1455 // come up, or HWND_TOP, or HWND_BOTTOM
1456 ULONG ulID, // in: ID of old control and slider
1457 ULONG ulSliderStyle, // in: SLS_* styles
1458 SHORT sMin, // in: minimum value (e.g. 0)
1459 SHORT sMax, // in: maximum value (e.g. 100)
1460 USHORT usIncrement, // in: minimum increment (e.g. 1)
1461 USHORT usTicksEvery) // in: ticks ever x values (e.g. 20)
1462{
1463 HWND hwndSlider = NULLHANDLE;
1464 HWND hwndKill = WinWindowFromID(hwndParent, ulID);
1465 if (hwndKill)
1466 {
1467 SWP swpControl;
1468 if (WinQueryWindowPos(hwndKill, &swpControl))
1469 {
1470 // destroy the old control
1471 WinDestroyWindow(hwndKill);
1472
1473 // WinRegisterCircularSlider();
1474
1475 // create a slider with the same ID at the same
1476 // position
1477 hwndSlider = WinCreateWindow(hwndParent,
1478 WC_CIRCULARSLIDER,
1479 "dummy", // no window text
1480 ulSliderStyle
1481 // | WS_PARENTCLIP
1482 // | WS_SYNCPAINT
1483 | WS_TABSTOP,
1484 swpControl.x,
1485 swpControl.y,
1486 swpControl.cx,
1487 swpControl.cy,
1488 hwndOwner,
1489 hwndInsertAfter,
1490 ulID, // same ID as destroyed control
1491 NULL, // control data
1492 NULL); // presparams
1493
1494 if (hwndSlider)
1495 {
1496 // set slider range
1497 WinSendMsg(hwndSlider,
1498 CSM_SETRANGE,
1499 (MPARAM)(ULONG)sMin,
1500 (MPARAM)(ULONG)sMax);
1501
1502 // set slider increments
1503 WinSendMsg(hwndSlider,
1504 CSM_SETINCREMENT,
1505 (MPARAM)(ULONG)usIncrement,
1506 (MPARAM)(ULONG)usTicksEvery);
1507
1508 // set slider value
1509 WinSendMsg(hwndSlider,
1510 CSM_SETVALUE,
1511 (MPARAM)0,
1512 (MPARAM)0);
1513
1514 // for some reason, the slider always has
1515 // WS_CLIPSIBLINGS set, even though we don't
1516 // set this; we must unset this now, or
1517 // the slider won't draw itself (%&$&%"$&%!!!)
1518 WinSetWindowBits(hwndSlider,
1519 QWL_STYLE,
1520 0, // unset bit
1521 WS_CLIPSIBLINGS);
1522
1523 WinShowWindow(hwndSlider, TRUE);
1524 }
1525 }
1526 }
1527
1528 return hwndSlider;
1529}
1530
1531/*
1532 *@@category: Helpers\PM helpers\Spin button helpers
1533 */
1534
1535/* ******************************************************************
1536 *
1537 * Spin button helpers
1538 *
1539 ********************************************************************/
1540
1541/*
1542 *@@ winhSetDlgItemSpinData:
1543 * sets a spin button's limits and data within a dialog window.
1544 * This only works for decimal spin buttons.
1545 */
1546
1547VOID winhSetDlgItemSpinData(HWND hwndDlg, // in: dlg window
1548 ULONG idSpinButton, // in: item ID of spin button
1549 ULONG min, // in: minimum allowed value
1550 ULONG max, // in: maximum allowed value
1551 ULONG current) // in: new current value
1552{
1553 HWND hwndSpinButton = WinWindowFromID(hwndDlg, idSpinButton);
1554 if (hwndSpinButton)
1555 {
1556 WinSendMsg(hwndSpinButton,
1557 SPBM_SETLIMITS, // Set limits message
1558 (MPARAM)max, // Spin Button maximum setting
1559 (MPARAM)min); // Spin Button minimum setting
1560
1561 WinSendMsg(hwndSpinButton,
1562 SPBM_SETCURRENTVALUE, // Set current value message
1563 (MPARAM)current,
1564 (MPARAM)NULL);
1565 }
1566}
1567
1568/*
1569 *@@ winhAdjustDlgItemSpinData:
1570 * this can be called on a spin button control to
1571 * have its current data snap to a grid. This only
1572 * works for LONG integer values.
1573 *
1574 * For example, if you specify 100 for the grid and call
1575 * this func after you have received SPBN_UP/DOWNARROW,
1576 * the spin button's value will always in/decrease
1577 * so that the spin button's value is a multiple of 100.
1578 *
1579 * By contrast, if (lGrid < 0), this will not really
1580 * snap the value to a multiple of -lGrid, but instead
1581 * in/decrease the value by -lGrid. The value will not
1582 * necessarily be a multiple of the grid. (0.9.14)
1583 *
1584 * This returns the "snapped" value to which the spin
1585 * button was set.
1586 *
1587 * If you specify lGrid == 0, this returns the spin
1588 * button's value only without snapping (V0.9.0).
1589 *
1590 *@@changed V0.9.0 [umoeller]: added check for lGrid == 0 (caused division by zero previously)
1591 *@@changed V0.9.14 (2001-08-03) [umoeller]: added fixes for age-old problems with wrap around
1592 *@@changed V0.9.14 (2001-08-03) [umoeller]: added lGrid < 0 mode
1593 */
1594
1595LONG winhAdjustDlgItemSpinData(HWND hwndDlg, // in: dlg window
1596 USHORT usItemID, // in: item ID of spin button
1597 LONG lGrid, // in: grid
1598 USHORT usNotifyCode) // in: SPBN_UP* or *DOWNARROW of WM_CONTROL message
1599{
1600 HWND hwndSpin = WinWindowFromID(hwndDlg, usItemID);
1601 LONG lBottom, lTop, lValue;
1602
1603 // get value, which has already increased /
1604 // decreased by 1
1605 WinSendMsg(hwndSpin,
1606 SPBM_QUERYVALUE,
1607 (MPARAM)&lValue,
1608 MPFROM2SHORT(0, SPBQ_ALWAYSUPDATE));
1609
1610 if ((lGrid)
1611 && ( (usNotifyCode == SPBN_UPARROW)
1612 || (usNotifyCode == SPBN_DOWNARROW)
1613 )
1614 )
1615 {
1616 // only if the up/down buttons were pressed,
1617 // snap to the nearest grid; if the user
1618 // manually enters something (SPBN_CHANGE),
1619 // we'll accept that value
1620 LONG lChanged = (usNotifyCode == SPBN_UPARROW)
1621 // if the spin button went up, subtract 1
1622 ? -1
1623 : +1;
1624 LONG lPrev = lValue + lChanged;
1625
1626 // if grid is negative, it is assumed to
1627 // not be a "real" grid but jump in those
1628 // steps only
1629 if (lGrid < 0)
1630 {
1631 // add /subtract grid
1632 if (usNotifyCode == SPBN_UPARROW)
1633 lValue = lPrev - lGrid;
1634 else
1635 lValue = lPrev + lGrid;
1636
1637 // lValue = (lValue / lGrid) * lGrid;
1638 }
1639 else
1640 {
1641 // add /subtract grid
1642 if (usNotifyCode == SPBN_UPARROW)
1643 lValue = lPrev + lGrid;
1644 else
1645 lValue = lPrev - lGrid;
1646
1647 lValue = (lValue / lGrid) * lGrid;
1648 }
1649
1650 // balance with spin button limits
1651 WinSendMsg(hwndSpin,
1652 SPBM_QUERYLIMITS,
1653 (MPARAM)&lTop,
1654 (MPARAM)&lBottom);
1655 if (lValue < lBottom)
1656 lValue = lTop;
1657 else if (lValue > lTop)
1658 lValue = lBottom;
1659
1660 WinSendMsg(hwndSpin,
1661 SPBM_SETCURRENTVALUE,
1662 (MPARAM)(lValue),
1663 MPNULL);
1664 }
1665 return lValue;
1666}
1667
1668/*
1669 *@@category: Helpers\PM helpers\List box helpers
1670 */
1671
1672/* ******************************************************************
1673 *
1674 * List box helpers
1675 *
1676 ********************************************************************/
1677
1678/*
1679 *@@ winhQueryLboxItemText:
1680 * returns the text of the specified
1681 * list box item in a newly allocated
1682 * buffer.
1683 *
1684 * Returns NULL on error. Use fre()
1685 * to free the return value.
1686 *
1687 *@@added V0.9.1 (99-12-14) [umoeller]
1688 */
1689
1690PSZ winhQueryLboxItemText(HWND hwndListbox,
1691 SHORT sIndex)
1692{
1693 PSZ pszReturn = 0;
1694 SHORT cbText = SHORT1FROMMR(WinSendMsg(hwndListbox,
1695 LM_QUERYITEMTEXTLENGTH,
1696 (MPARAM)(ULONG)sIndex,
1697 0));
1698 if ((cbText) && (cbText != LIT_ERROR))
1699 {
1700 pszReturn = (PSZ)malloc(cbText + 1); // add zero terminator
1701 WinSendMsg(hwndListbox,
1702 LM_QUERYITEMTEXT,
1703 MPFROM2SHORT(sIndex,
1704 cbText + 1),
1705 (MPARAM)pszReturn);
1706 }
1707
1708 return pszReturn;
1709}
1710
1711/*
1712 *@@ winhMoveLboxItem:
1713 * this moves one list box item from one
1714 * list box to another, including the
1715 * item text and the item "handle"
1716 * (see LM_QUERYITEMHANDLE).
1717 *
1718 * sTargetIndex can either be a regular
1719 * item index or one of the following
1720 * (as in LM_INSERTITEM):
1721 * -- LIT_END
1722 * -- LIT_SORTASCENDING
1723 * -- LIT_SORTDESCENDING
1724 *
1725 * If (fSelectTarget == TRUE), the new
1726 * item is also selected in the target
1727 * list box.
1728 *
1729 * Returns FALSE if moving failed. In
1730 * that case, the list boxes are unchanged.
1731 *
1732 *@@added V0.9.1 (99-12-14) [umoeller]
1733 */
1734
1735BOOL winhMoveLboxItem(HWND hwndSource,
1736 SHORT sSourceIndex,
1737 HWND hwndTarget,
1738 SHORT sTargetIndex,
1739 BOOL fSelectTarget)
1740{
1741 BOOL brc = FALSE;
1742
1743 PSZ pszItemText = winhQueryLboxItemText(hwndSource, sSourceIndex);
1744 if (pszItemText)
1745 {
1746 ULONG ulItemHandle = winhQueryLboxItemHandle(hwndSource,
1747 sSourceIndex);
1748 // probably 0, if not used
1749 LONG lTargetIndex = WinInsertLboxItem(hwndTarget,
1750 sTargetIndex,
1751 pszItemText);
1752 if ( (lTargetIndex != LIT_ERROR)
1753 && (lTargetIndex != LIT_MEMERROR)
1754 )
1755 {
1756 // successfully inserted:
1757 winhSetLboxItemHandle(hwndTarget, lTargetIndex, ulItemHandle);
1758 if (fSelectTarget)
1759 winhSetLboxSelectedItem(hwndTarget, lTargetIndex, TRUE);
1760
1761 // remove source
1762 WinDeleteLboxItem(hwndSource,
1763 sSourceIndex);
1764
1765 brc = TRUE;
1766 }
1767
1768 free(pszItemText);
1769 }
1770
1771 return brc;
1772}
1773
1774/*
1775 *@@ winhLboxSelectAll:
1776 * this selects or deselects all items in the
1777 * given list box, depending on fSelect.
1778 *
1779 * Returns the number of items in the list box.
1780 */
1781
1782ULONG winhLboxSelectAll(HWND hwndListBox, // in: list box
1783 BOOL fSelect) // in: TRUE = select, FALSE = deselect
1784{
1785 LONG lItemCount = WinQueryLboxCount(hwndListBox);
1786 ULONG ul;
1787
1788 for (ul = 0; ul < lItemCount; ul++)
1789 {
1790 WinSendMsg(hwndListBox,
1791 LM_SELECTITEM,
1792 (MPARAM)ul, // index
1793 (MPARAM)fSelect);
1794 }
1795
1796 return lItemCount;
1797}
1798
1799/*
1800 *@@ winhLboxFindItemFromHandle:
1801 * finds the list box item with the specified
1802 * handle.
1803 *
1804 * Of course this only makes sense if each item
1805 * has a unique handle indeed.
1806 *
1807 * Returns the index of the item found or -1.
1808 *
1809 *@@added V0.9.12 (2001-05-18) [umoeller]
1810 */
1811
1812ULONG winhLboxFindItemFromHandle(HWND hwndListBox,
1813 ULONG ulHandle)
1814{
1815 LONG cItems;
1816 if (cItems = WinQueryLboxCount(hwndListBox))
1817 {
1818 ULONG ul;
1819 for (ul = 0;
1820 ul < cItems;
1821 ul++)
1822 {
1823 if (ulHandle == winhQueryLboxItemHandle(hwndListBox,
1824 ul))
1825 return ul;
1826 }
1827 }
1828
1829 return -1;
1830}
1831
1832/*
1833 *@@category: Helpers\PM helpers\Scroll bar helpers
1834 */
1835
1836/* ******************************************************************
1837 *
1838 * Scroll bar helpers
1839 *
1840 ********************************************************************/
1841
1842/*
1843 *@@ winhUpdateScrollBar:
1844 * updates the given scroll bar according to the given
1845 * values. This updates the scroll bar's thumb size,
1846 * extension, and position, all in one shot.
1847 *
1848 * This function usually gets called when the window is
1849 * created and later when the window is resized.
1850 *
1851 * This simplifies the typical functionality of a scroll
1852 * bar in a client window which is to be scrolled. I am
1853 * wondering why IBM never included such a function, since
1854 * it is so damn basic and still writing it cost me a whole
1855 * day.
1856 *
1857 * Terminology:
1858 *
1859 * -- "window": the actual window with scroll bars which displays
1860 * a subrectangle of the available data. With a typical PM
1861 * application, this will be your client window.
1862 *
1863 * The width or height of this must be passed in ulWinPels.
1864 *
1865 * -- "viewport": the entire data to be displayed, of which the
1866 * "window" can only display a subrectangle, if the viewport
1867 * is larger than the window.
1868 *
1869 * The width or height of this must be passed in ulViewportPels.
1870 * This can be smaller than ulWinPels (if the window is larger
1871 * than the data) or the same or larger than ulWinPels
1872 * (if the window is too small to show all the data).
1873 *
1874 * -- "window offset": the offset of the current window within
1875 * the viewport.
1876 *
1877 * For horizontal scroll bars, this is the X coordinate,
1878 * counting from the left of the window (0 means leftmost).
1879 *
1880 * For vertical scroll bars, this is counted from the _top_
1881 * of the viewport (0 means topmost, as opposed to OS/2
1882 * window coordinates!). This is because for vertical scroll
1883 * bars controls, higher values move the thumb _down_. Yes
1884 * indeed, this conflicts with PM's coordinate system.
1885 *
1886 * The window offset is therefore always positive.
1887 *
1888 * The scroll bar gets disabled if the entire viewport is visible,
1889 * that is, if ulViewportPels <= ulWinPels. In that case
1890 * FALSE is returned. If (fAutoHide == TRUE), the scroll
1891 * bar is not only disabled, but also hidden from the display.
1892 * In that case, you will need to reformat your output because
1893 * your viewport becomes larger without the scroll bar.
1894 *
1895 * This function will set the range of the scroll bar to 0 up
1896 * to a value depending on the viewport size. For vertical scroll
1897 * bars, 0 means topmost (which is kinda sick with the OS/2
1898 * coordinate system), for horizontal scroll bars, 0 means leftmost.
1899 *
1900 * The maximum value of the scroll bar will be
1901 *
1902 + (ulViewportPels - ulWinPels) / usScrollUnitPels
1903 *
1904 * The thumb size of the scroll bar will also be adjusted
1905 * based on the viewport and window size, as it should be.
1906 *
1907 *@@added V0.9.1 (2000-02-14) [umoeller]
1908 *@@changed V0.9.3 (2000-04-30) [umoeller]: fixed pels/unit confusion
1909 *@@changed V0.9.3 (2000-05-08) [umoeller]: now handling scroll units automatically
1910 */
1911
1912BOOL winhUpdateScrollBar(HWND hwndScrollBar, // in: scroll bar (vertical or horizontal)
1913 ULONG ulWinPels, // in: vertical or horizontal dimension of
1914 // visible window part (in pixels),
1915 // excluding the scroll bar!
1916 ULONG ulViewportPels, // in: dimension of total data part, of
1917 // which ulWinPels is a sub-dimension
1918 // (in pixels);
1919 // if <= ulWinPels, the scrollbar will be
1920 // disabled
1921 ULONG ulCurPelsOfs, // in: current offset of visible part
1922 // (in pixels)
1923 BOOL fAutoHide) // in: hide scroll bar if disabled
1924{
1925 BOOL brc = FALSE;
1926
1927 // _Pmpf(("Entering winhUpdateScrollBar"));
1928
1929 // for large viewports, adjust scroll bar units
1930 USHORT usScrollUnitPels = 1;
1931 if (ulViewportPels > 10000)
1932 usScrollUnitPels = 100;
1933
1934 if (ulViewportPels > ulWinPels)
1935 {
1936 // scrollbar needed:
1937 USHORT usThumbDivisorUnits = usScrollUnitPels;
1938 USHORT lMaxAllowedUnitOfs;
1939 // _Pmpf(("winhUpdateScrollBar: ulViewportPels > ulWinPels, enabling scroller"));
1940 // divisor for thumb size (below)
1941 if (ulViewportPels > 10000)
1942 // for very large viewports, we need to
1943 // raise the divisor, because we only
1944 // have a USHORT
1945 usThumbDivisorUnits = usScrollUnitPels * 100;
1946
1947 // viewport is larger than window:
1948 WinEnableWindow(hwndScrollBar, TRUE);
1949 if (fAutoHide)
1950 WinShowWindow(hwndScrollBar, TRUE);
1951
1952 // calculate limit
1953 lMaxAllowedUnitOfs = ((ulViewportPels - ulWinPels + usScrollUnitPels)
1954 // scroll unit is 10
1955 / usScrollUnitPels);
1956
1957 // _Pmpf((" usCurUnitOfs: %d", ulCurUnitOfs));
1958 // _Pmpf((" usMaxUnits: %d", lMaxAllowedUnitOfs));
1959
1960 // set thumb position and limit
1961 WinSendMsg(hwndScrollBar,
1962 SBM_SETSCROLLBAR,
1963 (MPARAM)(ulCurPelsOfs), // / usThumbDivisorUnits), // position: 0 means top
1964 MPFROM2SHORT(0, // minimum
1965 lMaxAllowedUnitOfs)); // maximum
1966
1967 // set thumb size based on ulWinPels and
1968 // ulViewportPels
1969 WinSendMsg(hwndScrollBar,
1970 SBM_SETTHUMBSIZE,
1971 MPFROM2SHORT( ulWinPels / usThumbDivisorUnits, // visible
1972 ulViewportPels / usThumbDivisorUnits), // total
1973 0);
1974 brc = TRUE;
1975 }
1976 else
1977 {
1978 // _Pmpf(("winhUpdateScrollBar: ulViewportPels <= ulWinPels"));
1979 // entire viewport is visible:
1980 WinEnableWindow(hwndScrollBar, FALSE);
1981 if (fAutoHide)
1982 WinShowWindow(hwndScrollBar, FALSE);
1983 }
1984
1985 // _Pmpf(("End of winhUpdateScrollBar"));
1986
1987 return brc;
1988}
1989
1990/*
1991 *@@ winhHandleScrollMsg:
1992 * this helper handles a WM_VSCROLL or WM_HSCROLL
1993 * message posted to a client window when the user
1994 * has worked on a client scroll bar. Calling this
1995 * function is ALL you need to do to handle those
1996 * two messages.
1997 *
1998 * This is most useful in conjunction with winhUpdateScrollBar.
1999 * See that function for the terminology also.
2000 *
2001 * This function calculates the new scrollbar position
2002 * (from the mp2 value, which can be line up/down,
2003 * page up/down, or slider track) and calls WinScrollWindow
2004 * accordingly. The window part which became invalid
2005 * because of the scrolling is automatically invalidated
2006 * (using WinInvalidateRect), so expect a WM_PAINT after
2007 * calling this function.
2008 *
2009 * This function assumes that the scrollbar operates
2010 * on values starting from zero. The maximum value
2011 * of the scroll bar is:
2012 *
2013 + ulViewportPels - (prcl2Scroll->yTop - prcl2Scroll->yBottom)
2014 *
2015 * This function also automatically changes the scroll bar
2016 * units, should you have a viewport size which doesn't fit
2017 * into the SHORT's that the scroll bar uses internally. As
2018 * a result, this function handles a the complete range of
2019 * a ULONG for the viewport.
2020 *
2021 * Replace "bottom" and "top" with "right" and "left" for
2022 * horizontal scrollbars in the above formula.
2023 *
2024 *@@added V0.9.1 (2000-02-13) [umoeller]
2025 *@@changed V0.9.3 (2000-04-30) [umoeller]: changed prototype, fixed pels/unit confusion
2026 *@@changed V0.9.3 (2000-05-08) [umoeller]: now handling scroll units automatically
2027 *@@changed V0.9.7 (2001-01-17) [umoeller]: changed PLONG to PULONG
2028 */
2029
2030BOOL winhHandleScrollMsg(HWND hwnd2Scroll, // in: client window to scroll
2031 HWND hwndScrollBar, // in: vertical or horizontal scroll bar window
2032 PULONG pulCurPelsOfs, // in/out: current viewport offset;
2033 // this is updated with the proper scroll units
2034 PRECTL prcl2Scroll, // in: hwnd2Scroll rectangle to scroll
2035 // (in window coordinates);
2036 // this is passed to WinScrollWindow,
2037 // which considers this inclusive!
2038 LONG ulViewportPels, // in: total viewport dimension,
2039 // into which *pulCurPelsOfs is an offset
2040 USHORT usLineStepPels, // in: pixels to scroll line-wise
2041 // (scroll bar buttons pressed)
2042 ULONG msg, // in: either WM_VSCROLL or WM_HSCROLL
2043 MPARAM mp2) // in: complete mp2 of WM_VSCROLL/WM_HSCROLL;
2044 // this has two SHORT's (usPos and usCmd),
2045 // see PMREF for details
2046{
2047 ULONG ulOldPelsOfs = *pulCurPelsOfs;
2048 USHORT usPosUnits = SHORT1FROMMP(mp2), // in scroll units
2049 usCmd = SHORT2FROMMP(mp2);
2050 LONG lMaxAllowedUnitOfs;
2051 ULONG ulWinPels;
2052
2053 // for large viewports, adjust scroll bar units
2054 USHORT usScrollUnitPels = 1;
2055 if (ulViewportPels > 10000)
2056 usScrollUnitPels = 100;
2057
2058 // calculate window size (vertical or horizontal)
2059 if (msg == WM_VSCROLL)
2060 ulWinPels = (prcl2Scroll->yTop - prcl2Scroll->yBottom);
2061 else
2062 ulWinPels = (prcl2Scroll->xRight - prcl2Scroll->xLeft);
2063
2064 lMaxAllowedUnitOfs = ((LONG)ulViewportPels - ulWinPels) / usScrollUnitPels;
2065
2066 // _Pmpf(("Entering winhHandleScrollMsg"));
2067
2068 switch (usCmd)
2069 {
2070 case SB_LINEUP:
2071 if (*pulCurPelsOfs > usLineStepPels)
2072 *pulCurPelsOfs -= usLineStepPels; // * usScrollUnitPels);
2073 else
2074 *pulCurPelsOfs = 0;
2075 break;
2076
2077 case SB_LINEDOWN:
2078 *pulCurPelsOfs += usLineStepPels; // * usScrollUnitPels);
2079 break;
2080
2081 case SB_PAGEUP:
2082 if (*pulCurPelsOfs > ulWinPels)
2083 *pulCurPelsOfs -= ulWinPels; // convert to units
2084 else
2085 *pulCurPelsOfs = 0;
2086 break;
2087
2088 case SB_PAGEDOWN:
2089 *pulCurPelsOfs += ulWinPels; // convert to units
2090 break;
2091
2092 case SB_SLIDERTRACK:
2093 *pulCurPelsOfs = (usPosUnits * usScrollUnitPels);
2094 // _Pmpf((" SB_SLIDERTRACK: usUnits = %d", usPosUnits));
2095 break;
2096
2097 case SB_SLIDERPOSITION:
2098 *pulCurPelsOfs = (usPosUnits * usScrollUnitPels);
2099 break;
2100 }
2101
2102 // are we close to the lower limit?
2103 /* if (*plCurUnitOfs < usLineStepUnits) // usScrollUnit)
2104 *plCurUnitOfs = 0;
2105 // are we close to the upper limit?
2106 else if (*plCurUnitOfs + usLineStepUnits > lMaxUnitOfs)
2107 {
2108 _Pmpf((" !!! limiting: %d to %d", *plCurUnitOfs, lMaxUnitOfs));
2109 *plCurUnitOfs = lMaxUnitOfs;
2110 } */
2111
2112 /* if (*plCurPelsOfs < 0)
2113 *plCurPelsOfs = 0; */ // checked above
2114 if (*pulCurPelsOfs > (lMaxAllowedUnitOfs * usScrollUnitPels))
2115 {
2116 *pulCurPelsOfs = (lMaxAllowedUnitOfs * usScrollUnitPels);
2117 }
2118 if ( (*pulCurPelsOfs != ulOldPelsOfs)
2119 || (*pulCurPelsOfs == 0)
2120 || (*pulCurPelsOfs == (lMaxAllowedUnitOfs * usScrollUnitPels))
2121 )
2122 {
2123 RECTL rcl2Scroll,
2124 rcl2Update;
2125
2126 // changed:
2127 WinSendMsg(hwndScrollBar,
2128 SBM_SETPOS,
2129 (MPARAM)(*pulCurPelsOfs / usScrollUnitPels), // / usScrollUnit),
2130 0);
2131 // scroll window rectangle:
2132 rcl2Scroll.xLeft = prcl2Scroll->xLeft;
2133 rcl2Scroll.xRight = prcl2Scroll->xRight;
2134 rcl2Scroll.yBottom = prcl2Scroll->yBottom;
2135 rcl2Scroll.yTop = prcl2Scroll->yTop;
2136
2137 if (msg == WM_VSCROLL)
2138 WinScrollWindow(hwnd2Scroll,
2139 0,
2140 (*pulCurPelsOfs - ulOldPelsOfs) // scroll units changed
2141 , // * usScrollUnitPels, // convert to pels
2142 &rcl2Scroll, // rcl to scroll
2143 prcl2Scroll, // clipping rect
2144 NULLHANDLE, // no region
2145 &rcl2Update,
2146 0);
2147 else
2148 WinScrollWindow(hwnd2Scroll,
2149 -(LONG)(*pulCurPelsOfs - ulOldPelsOfs) // scroll units changed
2150 , // * usScrollUnitPels,
2151 0,
2152 &rcl2Scroll, // rcl to scroll
2153 prcl2Scroll, // clipping rect
2154 NULLHANDLE, // no region
2155 &rcl2Update,
2156 0);
2157
2158 // WinScrollWindow has stored the invalid window
2159 // rectangle which needs to be repainted in rcl2Update:
2160 WinInvalidateRect(hwnd2Scroll, &rcl2Update, FALSE);
2161 }
2162
2163 // _Pmpf(("End of winhHandleScrollMsg"));
2164
2165 return TRUE;
2166}
2167
2168/*
2169 *@@ winhProcessScrollChars:
2170 * helper for processing WM_CHAR messages for
2171 * client windows with scroll bars.
2172 *
2173 * If your window has scroll bars, you normally
2174 * need to process a number of keystrokes to be
2175 * able to scroll the window contents. This is
2176 * tiresome to code, so here is a helper.
2177 *
2178 * When receiving WM_CHAR, call this function.
2179 * If this returns TRUE, the keystroke has been
2180 * a scroll keystroke, and the window has been
2181 * updated (by sending WM_VSCROLL or WM_HSCROLL
2182 * to hwndClient). Otherwise, you should process
2183 * the keystroke as usual because it's not a
2184 * scroll keystroke.
2185 *
2186 * The following keystrokes are processed here:
2187 *
2188 * -- "cursor up, down, right, left": scroll one
2189 * line in the proper direction.
2190 * -- "page up, down": scroll one page up or down.
2191 * -- "Home": scroll leftmost.
2192 * -- "Ctrl+ Home": scroll topmost.
2193 * -- "End": scroll rightmost.
2194 * -- "Ctrl+ End": scroll bottommost.
2195 * -- "Ctrl + page up, down": scroll one screen left or right.
2196 *
2197 * This is CUA behavior.
2198 *
2199 * Returns TRUE if the message has been
2200 * processed.
2201 *
2202 *@@added V0.9.3 (2000-04-29) [umoeller]
2203 *@@changed V0.9.9 (2001-02-01) [lafaix]: Ctrl+PgUp/Dn now do one screen left/right
2204 */
2205
2206BOOL winhProcessScrollChars(HWND hwndClient, // in: client window
2207 HWND hwndVScroll, // in: vertical scroll bar
2208 HWND hwndHScroll, // in: horizontal scroll bar
2209 MPARAM mp1, // in: WM_CHAR mp1
2210 MPARAM mp2, // in: WM_CHAR mp2
2211 ULONG ulVertMax, // in: maximum viewport cy
2212 ULONG ulHorzMax) // in: maximum viewport cx
2213{
2214 BOOL fProcessed = FALSE;
2215 USHORT usFlags = SHORT1FROMMP(mp1);
2216 // USHORT usch = SHORT1FROMMP(mp2);
2217 USHORT usvk = SHORT2FROMMP(mp2);
2218
2219 // _Pmpf(("Entering winhProcessScrollChars"));
2220
2221 if (usFlags & KC_VIRTUALKEY)
2222 {
2223 ULONG ulMsg = 0;
2224 SHORT sPos = 0;
2225 SHORT usCmd = 0;
2226 fProcessed = TRUE;
2227
2228 switch (usvk)
2229 {
2230 case VK_UP:
2231 ulMsg = WM_VSCROLL;
2232 usCmd = SB_LINEUP;
2233 break;
2234
2235 case VK_DOWN:
2236 ulMsg = WM_VSCROLL;
2237 usCmd = SB_LINEDOWN;
2238 break;
2239
2240 case VK_RIGHT:
2241 ulMsg = WM_HSCROLL;
2242 usCmd = SB_LINERIGHT;
2243 break;
2244
2245 case VK_LEFT:
2246 ulMsg = WM_HSCROLL;
2247 usCmd = SB_LINELEFT;
2248 break;
2249
2250 case VK_PAGEUP:
2251 if (usFlags & KC_CTRL)
2252 ulMsg = WM_HSCROLL;
2253 else
2254 ulMsg = WM_VSCROLL;
2255 usCmd = SB_PAGEUP;
2256 break;
2257
2258 case VK_PAGEDOWN:
2259 if (usFlags & KC_CTRL)
2260 ulMsg = WM_HSCROLL;
2261 else
2262 ulMsg = WM_VSCROLL;
2263 usCmd = SB_PAGEDOWN;
2264 break;
2265
2266 case VK_HOME:
2267 if (usFlags & KC_CTRL)
2268 // vertical:
2269 ulMsg = WM_VSCROLL;
2270 else
2271 ulMsg = WM_HSCROLL;
2272
2273 sPos = 0;
2274 usCmd = SB_SLIDERPOSITION;
2275 break;
2276
2277 case VK_END:
2278 if (usFlags & KC_CTRL)
2279 {
2280 // vertical:
2281 ulMsg = WM_VSCROLL;
2282 sPos = ulVertMax;
2283 }
2284 else
2285 {
2286 ulMsg = WM_HSCROLL;
2287 sPos = ulHorzMax;
2288 }
2289
2290 usCmd = SB_SLIDERPOSITION;
2291 break;
2292
2293 default:
2294 // other:
2295 fProcessed = FALSE;
2296 }
2297
2298 if ( ((usFlags & KC_KEYUP) == 0)
2299 && (ulMsg)
2300 )
2301 {
2302 HWND hwndScrollBar = ((ulMsg == WM_VSCROLL)
2303 ? hwndVScroll
2304 : hwndHScroll);
2305 if (WinIsWindowEnabled(hwndScrollBar))
2306 {
2307 USHORT usID = WinQueryWindowUShort(hwndScrollBar,
2308 QWS_ID);
2309 WinSendMsg(hwndClient,
2310 ulMsg,
2311 MPFROMSHORT(usID),
2312 MPFROM2SHORT(sPos,
2313 usCmd));
2314 }
2315 }
2316 }
2317
2318 // _Pmpf(("End of winhProcessScrollChars"));
2319
2320 return fProcessed;
2321}
2322
2323/*
2324 *@@category: Helpers\PM helpers\Window positioning
2325 */
2326
2327/* ******************************************************************
2328 *
2329 * Window positioning helpers
2330 *
2331 ********************************************************************/
2332
2333/*
2334 *@@ winhSaveWindowPos:
2335 * saves the position of a certain window. As opposed
2336 * to the barely documented WinStoreWindowPos API, this
2337 * one only saves one regular SWP structure for the given
2338 * window, as returned by WinQueryWindowPos for hwnd.
2339 *
2340 * If the window is currently maximized or minimized,
2341 * we won't store the current window size and position
2342 * (which wouldn't make much sense), but retrieve the
2343 * "restored" window position from the window words
2344 * instead.
2345 *
2346 * The window should still be visible on the screen
2347 * when calling this function. Do not call it in WM_DESTROY,
2348 * because then the SWP data is no longer valid.
2349 *
2350 * This returns TRUE if saving was successful.
2351 *
2352 *@@changed V0.9.1 (99-12-19) [umoeller]: added minimize/maximize support
2353 */
2354
2355BOOL winhSaveWindowPos(HWND hwnd, // in: window to save
2356 HINI hIni, // in: INI file (or HINI_USER/SYSTEM)
2357 const char *pcszApp, // in: INI application name
2358 const char *pcszKey) // in: INI key name
2359{
2360 BOOL brc = FALSE;
2361 SWP swp;
2362 if (WinQueryWindowPos(hwnd, &swp))
2363 {
2364 if (swp.fl & (SWP_MAXIMIZE | SWP_MINIMIZE))
2365 {
2366 // window currently maximized or minimized:
2367 // retrieve "restore" position from window words
2368 swp.x = WinQueryWindowUShort(hwnd, QWS_XRESTORE);
2369 swp.y = WinQueryWindowUShort(hwnd, QWS_YRESTORE);
2370 swp.cx = WinQueryWindowUShort(hwnd, QWS_CXRESTORE);
2371 swp.cy = WinQueryWindowUShort(hwnd, QWS_CYRESTORE);
2372 }
2373
2374 brc = PrfWriteProfileData(hIni, (PSZ)pcszApp, (PSZ)pcszKey, &swp, sizeof(swp));
2375 }
2376 return brc;
2377}
2378
2379/*
2380 *@@ winhRestoreWindowPos:
2381 * this will retrieve a window position which was
2382 * previously stored using winhSaveWindowPos.
2383 *
2384 * The window should not be visible to avoid flickering.
2385 * "fl" must contain the SWP_flags as in WinSetWindowPos.
2386 *
2387 * Note that only the following may be used:
2388 * -- SWP_MOVE reposition the window
2389 * -- SWP_SIZE also resize the window to
2390 * the stored position; this might
2391 * lead to problems with different
2392 * video resolutions, so be careful.
2393 * -- SWP_SHOW make window visible too
2394 * -- SWP_NOREDRAW changes are not redrawn
2395 * -- SWP_NOADJUST do not send a WM_ADJUSTWINDOWPOS message
2396 * before moving or sizing
2397 * -- SWP_ACTIVATE activate window (make topmost)
2398 * -- SWP_DEACTIVATE deactivate window (make bottommost)
2399 *
2400 * Do not specify any other SWP_* flags.
2401 *
2402 * If SWP_SIZE is not set, the window will be moved only.
2403 *
2404 * This returns TRUE if INI data was found.
2405 *
2406 * This function automatically checks for whether the
2407 * window would be positioned outside the visible screen
2408 * area and will adjust coordinates accordingly. This can
2409 * happen when changing video resolutions.
2410 *
2411 *@@changed V0.9.7 (2000-12-20) [umoeller]: fixed invalid params if INI key not found
2412 */
2413
2414BOOL winhRestoreWindowPos(HWND hwnd, // in: window to restore
2415 HINI hIni, // in: INI file (or HINI_USER/SYSTEM)
2416 const char *pcszApp, // in: INI application name
2417 const char *pcszKey, // in: INI key name
2418 ULONG fl) // in: "fl" parameter for WinSetWindowPos
2419{
2420 BOOL brc = FALSE;
2421 SWP swp;
2422 ULONG cbswp = sizeof(swp);
2423 ULONG fl2 = (fl & ~SWP_ZORDER);
2424
2425 if (PrfQueryProfileData(hIni, (PSZ)pcszApp, (PSZ)pcszKey, &swp, &cbswp))
2426 {
2427 ULONG ulScreenCX = WinQuerySysValue(HWND_DESKTOP, SV_CXSCREEN);
2428 ULONG ulScreenCY = WinQuerySysValue(HWND_DESKTOP, SV_CYSCREEN);
2429
2430 brc = TRUE;
2431
2432 if ((fl & SWP_SIZE) == 0)
2433 {
2434 // if no resize, we need to get the current position
2435 SWP swpNow;
2436 brc = WinQueryWindowPos(hwnd, &swpNow);
2437 swp.cx = swpNow.cx;
2438 swp.cy = swpNow.cy;
2439 }
2440
2441 if (brc)
2442 {
2443 // check for full visibility
2444 if ( (swp.x + swp.cx) > ulScreenCX)
2445 swp.x = ulScreenCX - swp.cx;
2446 if ( (swp.y + swp.cy) > ulScreenCY)
2447 swp.y = ulScreenCY - swp.cy;
2448 }
2449
2450 brc = TRUE;
2451
2452 }
2453 else
2454 {
2455 // window pos not found in INI: unset SWP_MOVE etc.
2456 WinQueryWindowPos(hwnd, &swp);
2457 fl2 &= ~(SWP_MOVE | SWP_SIZE);
2458 }
2459
2460 WinSetWindowPos(hwnd,
2461 NULLHANDLE, // insert-behind window
2462 swp.x,
2463 swp.y,
2464 swp.cx,
2465 swp.cy,
2466 fl2); // SWP_* flags
2467
2468 return brc;
2469}
2470
2471/*
2472 *@@ winhStoreWindowPos:
2473 * saves the position of a certain window in the same format
2474 * as the barely documented WinStoreWindowPos API.
2475 * This uses the completely undocumented calls
2476 * WinGetFrameTreePPSize and WinGetFrameTreePPs imported
2477 * from PMWIN.DLL ordinals 972 and 973.
2478 *
2479 * The window should still be visible on the screen
2480 * when calling this function. Do not call it in WM_DESTROY,
2481 * because then the SWP data is no longer valid.
2482 *
2483 * This returns TRUE if saving was successful.
2484 *
2485 *@@added XWP V1.0.6 (2006-10-31) [pr]: @@fixes 458
2486 */
2487
2488BOOL winhStoreWindowPos(HWND hwnd, // in: window to save
2489 HINI hIni, // in: INI file (or HINI_USER/SYSTEM)
2490 const char *pcszApp, // in: INI application name
2491 const char *pcszKey) // in: INI key name
2492{
2493 BOOL brc = FALSE;
2494 SWP swp;
2495
2496 if (WinQueryWindowPos(hwnd, &swp))
2497 {
2498 ULONG ulSizePP = WinGetFrameTreePPSize(hwnd);
2499 ULONG ulSize = sizeof(STOREPOS) + ulSizePP;
2500 PSTOREPOS pStorePos;
2501
2502 if ((pStorePos = malloc(ulSize)))
2503 {
2504 // This first bit is all guesswork as I don't know what it all means,
2505 // but it always seems to be the same everywhere I've looked.
2506 pStorePos->usMagic = 0x7B6A;
2507 pStorePos->ulRes1 = 1;
2508 pStorePos->ulRes2 = 1;
2509 pStorePos->ulRes3 = 0x0400;
2510 pStorePos->ulRes4 = 0x0300;
2511 pStorePos->ulRes5 = 0xFFFFFFFF;
2512 pStorePos->ulRes6 = 0xFFFFFFFF;
2513
2514 pStorePos->ulFlags = swp.fl;
2515 pStorePos->usXPos = pStorePos->usRestoreXPos = swp.x;
2516 pStorePos->usYPos = pStorePos->usRestoreYPos = swp.y;
2517 pStorePos->usWidth = pStorePos->usRestoreWidth = swp.cx;
2518 pStorePos->usHeight = pStorePos->usRestoreHeight = swp.cy;
2519 if (swp.fl & (SWP_MAXIMIZE | SWP_MINIMIZE))
2520 {
2521 pStorePos->usRestoreXPos = WinQueryWindowUShort(hwnd, QWS_XRESTORE);
2522 pStorePos->usRestoreYPos = WinQueryWindowUShort(hwnd, QWS_YRESTORE);
2523 pStorePos->usRestoreWidth = WinQueryWindowUShort(hwnd, QWS_CXRESTORE);
2524 pStorePos->usRestoreHeight = WinQueryWindowUShort(hwnd, QWS_CYRESTORE);
2525 }
2526
2527 pStorePos->usMinXPos = WinQueryWindowUShort(hwnd, QWS_XMINIMIZE);
2528 pStorePos->usMinYPos = WinQueryWindowUShort(hwnd, QWS_YMINIMIZE);
2529 pStorePos->ulPPLen = WinGetFrameTreePPs(hwnd, ulSizePP, (PSZ)(pStorePos + 1));
2530 ulSize = pStorePos->ulPPLen + sizeof(STOREPOS);
2531 brc = PrfWriteProfileData(hIni, (PSZ)pcszApp, (PSZ)pcszKey, pStorePos, ulSize);
2532 free(pStorePos);
2533 }
2534 }
2535 return brc;
2536}
2537
2538/*
2539 *@@ winhAdjustControls:
2540 * helper function for dynamically adjusting a window's
2541 * controls when the window is resized.
2542 *
2543 * This is most useful with dialogs loaded from resources
2544 * which should be sizeable. Normally, when the dialog
2545 * frame is resized, the controls stick to their positions,
2546 * and for dialogs with many controls, programming the
2547 * changes can be tiresome.
2548 *
2549 * Enter this function. ;-) Basically, this takes a
2550 * static array of MPARAM's as input (plus one dynamic
2551 * storage area for the window positions).
2552 *
2553 * This function must get called in three contexts:
2554 * during WM_INITDLG, during WM_WINDOWPOSCHANGED, and
2555 * during WM_DESTROY, with varying parameters.
2556 *
2557 * In detail, there are four things you need to do to make
2558 * this work:
2559 *
2560 * 1) Set up a static array (as a global variable) of
2561 * MPARAM's, one for each control in your array.
2562 * Each MPARAM will have the control's ID and the
2563 * XAC_* flags (winh.h) how the control shall be moved.
2564 * Use MPFROM2SHORT to easily create this. Example:
2565 *
2566 + MPARAM ampControlFlags[] =
2567 + { MPFROM2SHORT(ID_CONTROL_1, XAC_MOVEX),
2568 + MPFROM2SHORT(ID_CONTROL_2, XAC_SIZEY),
2569 + ...
2570 + }
2571 *
2572 * This can safely be declared as a global variable
2573 * because this data will only be read and never
2574 * changed by this function.
2575 *
2576 * 2) In WM_INITDLG of your dialog function, set up
2577 * an XADJUSTCTRLS structure, preferrably in your
2578 * window words (QWL_USER).
2579 *
2580 * ZERO THAT STRUCTURE (memset(&xac, 0, sizeof(XADJUSTCTRLS),
2581 * or this func will not work (because it will intialize
2582 * things on the first WM_WINDOWPOSCHANGED).
2583 *
2584 * 3) Intercept WM_WINDOWPOSCHANGED:
2585 *
2586 + case WM_WINDOWPOSCHANGED:
2587 + {
2588 + // this msg is passed two SWP structs:
2589 + // one for the old, one for the new data
2590 + // (from PM docs)
2591 + PSWP pswpNew = PVOIDFROMMP(mp1);
2592 + PSWP pswpOld = pswpNew + 1;
2593 +
2594 + // resizing?
2595 + if (pswpNew->fl & SWP_SIZE)
2596 + {
2597 + PXADJUSTCTRLS pxac = ... // get it from your window words
2598 +
2599 + winhAdjustControls(hwndDlg, // dialog
2600 + ampControlFlags, // MPARAMs array
2601 + sizeof(ampControlFlags) / sizeof(MPARAM),
2602 + // items count
2603 + pswpNew, // mp1
2604 + pxac); // storage area
2605 + }
2606 + mrc = WinDefDlgProc(hwnd, msg, mp1, mp2); ...
2607 *
2608 * 4) In WM_DESTROY, call this function again with pmpFlags,
2609 * pswpNew, and pswpNew set to NULL. This will clean up the
2610 * data which has been allocated internally (pointed to from
2611 * the XADJUSTCTRLS structure).
2612 * Don't forget to free your storage for XADJUSTCTLRS
2613 * _itself_, that's the job of the caller.
2614 *
2615 * This might sound complicated, but it's a lot easier than
2616 * having to write dozens of WinSetWindowPos calls oneself.
2617 *
2618 *@@added V0.9.0 [umoeller]
2619 *@@changed V0.9.19 (2002-04-13) [umoeller]: added correlation for entry field repositioning, this was always off
2620 */
2621
2622BOOL winhAdjustControls(HWND hwndDlg, // in: dialog (req.)
2623 const MPARAM *pmpFlags, // in: init flags or NULL for cleanup
2624 ULONG ulCount, // in: item count (req.)
2625 PSWP pswpNew, // in: pswpNew from WM_WINDOWPOSCHANGED or NULL for cleanup
2626 PXADJUSTCTRLS pxac) // in: adjust-controls storage area (req.)
2627{
2628 BOOL brc = FALSE;
2629 ULONG ul = 0;
2630
2631 /* if (!WinIsWindowVisible(hwndDlg))
2632 return (FALSE); */
2633
2634 if ((pmpFlags) && (pxac))
2635 {
2636 PSWP pswpThis;
2637 const MPARAM *pmpThis;
2638 LONG ldcx, ldcy;
2639 ULONG cWindows = 0;
2640
2641 // V0.9.19 (2002-04-13) [umoeller]
2642 LONG cxMarginEF = 3 * WinQuerySysValue(HWND_DESKTOP, SV_CXBORDER);
2643 LONG cyMarginEF = 3 * WinQuerySysValue(HWND_DESKTOP, SV_CYBORDER);
2644
2645 // setup mode:
2646 if (pxac->fInitialized == FALSE)
2647 {
2648 // first call: get all the SWP's
2649 WinQueryWindowPos(hwndDlg, &pxac->swpMain);
2650 // _Pmpf(("winhAdjustControls: queried main cx = %d, cy = %d",
2651 // pxac->swpMain.cx, pxac->swpMain.cy));
2652
2653 pxac->paswp = (PSWP)malloc(sizeof(SWP) * ulCount);
2654
2655 pswpThis = pxac->paswp;
2656 pmpThis = pmpFlags;
2657
2658 for (ul = 0;
2659 ul < ulCount;
2660 ul++)
2661 {
2662 HWND hwndThis;
2663 CHAR szClass[10];
2664 if (hwndThis = WinWindowFromID(hwndDlg, SHORT1FROMMP(*pmpThis)))
2665 {
2666 WinQueryWindowPos(hwndThis, pswpThis);
2667
2668 // correlate the stupid repositioning of entry fields
2669 // V0.9.19 (2002-04-13) [umoeller]
2670 if ( (WinQueryClassName(hwndThis, sizeof(szClass), szClass)
2671 && (!strcmp(szClass, "#6"))
2672 && (WinQueryWindowULong(hwndThis, QWL_STYLE) & ES_MARGIN))
2673 )
2674 {
2675 pswpThis->x += cxMarginEF;
2676 pswpThis->y += cyMarginEF;
2677 pswpThis->cx -= 2 * cxMarginEF;
2678 pswpThis->cy -= 2 * cyMarginEF;
2679 }
2680
2681 cWindows++;
2682 }
2683
2684 pswpThis++;
2685 pmpThis++;
2686 }
2687
2688 pxac->fInitialized = TRUE;
2689 // _Pmpf(("winhAdjustControls: queried %d controls", cWindows));
2690 }
2691
2692 if (pswpNew)
2693 {
2694 // compute width and height delta
2695 ldcx = (pswpNew->cx - pxac->swpMain.cx);
2696 ldcy = (pswpNew->cy - pxac->swpMain.cy);
2697
2698 // _Pmpf(("winhAdjustControls: new cx = %d, cy = %d",
2699 // pswpNew->cx, pswpNew->cy));
2700
2701 // now adjust the controls
2702 cWindows = 0;
2703 pswpThis = pxac->paswp;
2704 pmpThis = pmpFlags;
2705 for (ul = 0;
2706 ul < ulCount;
2707 ul++)
2708 {
2709 HWND hwndThis;
2710 if (hwndThis = WinWindowFromID(hwndDlg, SHORT1FROMMP(*pmpThis)))
2711 {
2712 LONG x = pswpThis->x,
2713 y = pswpThis->y,
2714 cx = pswpThis->cx,
2715 cy = pswpThis->cy;
2716
2717 ULONG ulSwpFlags = 0;
2718 // get flags for this control
2719 USHORT usFlags = SHORT2FROMMP(*pmpThis);
2720
2721 if (usFlags & XAC_MOVEX)
2722 {
2723 x += ldcx;
2724 ulSwpFlags |= SWP_MOVE;
2725 }
2726 if (usFlags & XAC_MOVEY)
2727 {
2728 y += ldcy;
2729 ulSwpFlags |= SWP_MOVE;
2730 }
2731 if (usFlags & XAC_SIZEX)
2732 {
2733 cx += ldcx;
2734 ulSwpFlags |= SWP_SIZE;
2735 }
2736 if (usFlags & XAC_SIZEY)
2737 {
2738 cy += ldcy;
2739 ulSwpFlags |= SWP_SIZE;
2740 }
2741
2742 if (ulSwpFlags)
2743 {
2744 WinSetWindowPos(hwndThis,
2745 NULLHANDLE, // hwndInsertBehind
2746 x, y, cx, cy,
2747 ulSwpFlags);
2748 cWindows++;
2749 brc = TRUE;
2750 }
2751 }
2752
2753 pswpThis++;
2754 pmpThis++;
2755 }
2756
2757 // _Pmpf(("winhAdjustControls: set %d windows", cWindows));
2758 }
2759 }
2760 else
2761 {
2762 // pxac == NULL:
2763 // cleanup mode
2764 if (pxac->paswp)
2765 free(pxac->paswp);
2766 }
2767
2768 return brc;
2769}
2770
2771/*
2772 *@@ winhCenterWindow:
2773 * centers a window within its parent window. If that's
2774 * the PM desktop, it will be centered according to the
2775 * whole screen.
2776 * For dialog boxes, use WinCenteredDlgBox as a one-shot
2777 * function.
2778 *
2779 * Note: When calling this function, the window should
2780 * not be visible to avoid flickering.
2781 * This func does not show the window either, so call
2782 * WinShowWindow afterwards.
2783 */
2784
2785void winhCenterWindow(HWND hwnd)
2786{
2787 RECTL rclParent;
2788 RECTL rclWindow;
2789
2790 WinQueryWindowRect(hwnd, &rclWindow);
2791 WinQueryWindowRect(WinQueryWindow(hwnd, QW_PARENT), &rclParent);
2792
2793 rclWindow.xLeft = (rclParent.xRight - rclWindow.xRight) / 2;
2794 rclWindow.yBottom = (rclParent.yTop - rclWindow.yTop ) / 2;
2795
2796 WinSetWindowPos(hwnd, NULLHANDLE, rclWindow.xLeft, rclWindow.yBottom,
2797 0, 0, SWP_MOVE);
2798}
2799
2800/*
2801 *@@ winhCenteredDlgBox:
2802 * just like WinDlgBox, but the dlg box is centered on the screen;
2803 * you should mark the dlg template as not visible in the dlg
2804 * editor, or display will flicker.
2805 * As opposed to winhCenterWindow, this _does_ show the window.
2806 */
2807
2808ULONG winhCenteredDlgBox(HWND hwndParent,
2809 HWND hwndOwner,
2810 PFNWP pfnDlgProc,
2811 HMODULE hmod,
2812 ULONG idDlg,
2813 PVOID pCreateParams)
2814{
2815 ULONG ulReply;
2816 HWND hwndDlg = WinLoadDlg(hwndParent,
2817 hwndOwner,
2818 pfnDlgProc,
2819 hmod,
2820 idDlg,
2821 pCreateParams);
2822 winhCenterWindow(hwndDlg);
2823 ulReply = WinProcessDlg(hwndDlg);
2824 WinDestroyWindow(hwndDlg);
2825 return ulReply;
2826}
2827
2828/*
2829 *@@ winhPlaceBesides:
2830 * attempts to place hwnd somewhere besides
2831 * hwndRelative.
2832 *
2833 * fl is presently ignored, but should be
2834 * PLF_SMART for future extensions.
2835 *
2836 * Works only if hwnd is a desktop child.
2837 *
2838 *@@added V0.9.19 (2002-04-17) [umoeller]
2839 *@@changed V1.0.0 (2002-08-26) [umoeller]: fixed cx and cy confusion
2840 */
2841
2842BOOL winhPlaceBesides(HWND hwnd,
2843 HWND hwndRelative,
2844 ULONG fl)
2845{
2846 SWP swpRel,
2847 swpThis;
2848 LONG xNew, yNew;
2849
2850 if ( (WinQueryWindowPos(hwndRelative, &swpRel))
2851 && (WinQueryWindowPos(hwnd, &swpThis))
2852 )
2853 {
2854 HWND hwndRelParent,
2855 hwndThisParent;
2856 POINTL ptlRel = {swpRel.x, swpRel.y};
2857 if ( (hwndRelParent = WinQueryWindow(hwndRelative, QW_PARENT))
2858 && (hwndThisParent = WinQueryWindow(hwnd, QW_PARENT))
2859 && (hwndRelParent != hwndThisParent)
2860 )
2861 {
2862 WinMapWindowPoints(hwndRelParent,
2863 hwndThisParent,
2864 &ptlRel,
2865 1);
2866 }
2867
2868 // place right first
2869 xNew = ptlRel.x + swpRel.cx;
2870 // center vertically
2871 yNew = ptlRel.y + ((swpRel.cy - swpThis.cy) / 2);
2872
2873 // if (xNew + swpThis.cy > WinQuerySysValue(HWND_DESKTOP, SV_CXSCREEN))
2874 // not cy, but cx V1.0.0 (2002-08-26) [umoeller]
2875 if (xNew + swpThis.cx > WinQuerySysValue(HWND_DESKTOP, SV_CXSCREEN))
2876 {
2877 // place left then
2878 xNew = ptlRel.x - swpThis.cx;
2879
2880 if (xNew < 0)
2881 {
2882 // center then
2883 winhCenterWindow(hwnd);
2884 return TRUE;
2885 }
2886 }
2887
2888 return WinSetWindowPos(hwnd,
2889 0,
2890 xNew,
2891 yNew,
2892 0,
2893 0,
2894 SWP_MOVE);
2895 }
2896
2897 return FALSE;
2898}
2899
2900/*
2901 *@@ winhFindWindowBelow:
2902 * finds the window with the same parent
2903 * which sits right below hwndFind in the
2904 * window Z-order.
2905 *
2906 *@@added V0.9.7 (2000-12-04) [umoeller]
2907 */
2908
2909HWND winhFindWindowBelow(HWND hwndFind)
2910{
2911 HWND hwnd = NULLHANDLE,
2912 hwndParent = WinQueryWindow(hwndFind, QW_PARENT);
2913
2914 if (hwndParent)
2915 {
2916 HENUM henum = WinBeginEnumWindows(hwndParent);
2917 HWND hwndThis;
2918 while (hwndThis = WinGetNextWindow(henum))
2919 {
2920 SWP swp;
2921 WinQueryWindowPos(hwndThis, &swp);
2922 if (swp.hwndInsertBehind == hwndFind)
2923 {
2924 hwnd = hwndThis;
2925 break;
2926 }
2927 }
2928 WinEndEnumWindows(henum);
2929 }
2930
2931 return hwnd;
2932}
2933
2934/*
2935 *@@category: Helpers\PM helpers\Presentation parameters
2936 */
2937
2938/* ******************************************************************
2939 *
2940 * Presparams helpers
2941 *
2942 ********************************************************************/
2943
2944/*
2945 *@@ winhQueryWindowFont:
2946 * returns the window font presentation parameter
2947 * in a newly allocated buffer.
2948 *
2949 * Returns NULL on error. Use free()
2950 * to free the return value.
2951 *
2952 *@@added V0.9.1 (2000-02-14) [umoeller]
2953 */
2954
2955PSZ winhQueryWindowFont(HWND hwnd)
2956{
2957 CHAR szNewFont[100] = "";
2958 WinQueryPresParam(hwnd,
2959 PP_FONTNAMESIZE,
2960 0,
2961 NULL,
2962 (ULONG)sizeof(szNewFont),
2963 (PVOID)&szNewFont,
2964 QPF_NOINHERIT);
2965 if (szNewFont[0] != 0)
2966 return strdup(szNewFont);
2967
2968 return NULL;
2969}
2970
2971/*
2972 *@@ winhSetWindowFont:
2973 * this sets a window's font by invoking
2974 * WinSetPresParam on it.
2975 *
2976 * If (pszFont == NULL), a default font will be set
2977 * (on Warp 4, "9.WarpSans", on Warp 3, "8.Helv").
2978 *
2979 * winh.h also defines the winhSetDlgItemFont macro.
2980 *
2981 * Returns TRUE if successful or FALSE otherwise.
2982 *
2983 *@@added V0.9.0 [umoeller]
2984 *@@changed V1.0.4 (2005-09-02) [bvl]: Return 'Combined' fonts on DBCS systems to show DBCS characters properly @@fixes 655
2985 */
2986
2987BOOL winhSetWindowFont(HWND hwnd,
2988 const char *pcszFont)
2989{
2990 CHAR szFont[256];
2991
2992 if (pcszFont == NULL)
2993 {
2994 if (doshIsWarp4())
2995 if(nlsDBCS())
2996 strhncpy0(szFont, "9.WarpSans Combined", sizeof(szFont));
2997 else
2998 strhncpy0(szFont, "9.WarpSans", sizeof(szFont));
2999 else
3000 if(nlsDBCS())
3001 strhncpy0(szFont, "8.Helv Combined", sizeof(szFont));
3002 else
3003 strhncpy0(szFont, "8.Helv", sizeof(szFont));
3004 }
3005 else
3006 strhncpy0(szFont, pcszFont, sizeof(szFont));
3007
3008 return WinSetPresParam(hwnd,
3009 PP_FONTNAMESIZE,
3010 strlen(szFont)+1,
3011 szFont);
3012}
3013
3014/*
3015 *@@ winhSetControlsFont:
3016 * this sets the font for all the controls of hwndDlg
3017 * which have a control ID in the range of usIDMin to
3018 * usIDMax. "Unused" IDs (i.e. -1) will also be set.
3019 *
3020 * If (pszFont == NULL), a default font will be set
3021 * (on Warp 4, "9.WarpSans", on Warp 3, "8.Helv").
3022 *
3023 * Returns the no. of controls set.
3024 *
3025 *@@added V0.9.0 [umoeller]
3026 *@@changed V1.0.4 (2005-09-02) [bvl]: Return 'Combined' fonts on DBCS systems to show DBCS characters properly @@fixes 655
3027 */
3028
3029ULONG winhSetControlsFont(HWND hwndDlg, // in: dlg to set
3030 SHORT usIDMin, // in: minimum control ID to be set (inclusive)
3031 SHORT usIDMax, // in: maximum control ID to be set (inclusive)
3032 const char *pcszFont) // in: font to use (e.g. "9.WarpSans") or NULL
3033{
3034 ULONG ulrc = 0;
3035 HENUM henum;
3036 HWND hwndItem;
3037 CHAR szFont[256];
3038 ULONG cbFont;
3039
3040 if (pcszFont == NULL)
3041 {
3042 if (doshIsWarp4())
3043 if(nlsDBCS())
3044 strhncpy0(szFont, "9.WarpSans Combined", sizeof(szFont));
3045 else
3046 strhncpy0(szFont, "9.WarpSans", sizeof(szFont));
3047 else
3048 if(nlsDBCS())
3049 strhncpy0(szFont, "8.Helv Combined", sizeof(szFont));
3050 else
3051 strhncpy0(szFont, "8.Helv", sizeof(szFont));
3052 }
3053 else
3054 strhncpy0(szFont, pcszFont, sizeof(szFont));
3055
3056 cbFont = strlen(szFont) + 1;
3057
3058 // set font for all the dialog controls
3059 henum = WinBeginEnumWindows(hwndDlg);
3060 while ((hwndItem = WinGetNextWindow(henum)))
3061 {
3062 SHORT sID = WinQueryWindowUShort(hwndItem, QWS_ID);
3063 if ( (sID == -1)
3064 || ((sID >= usIDMin) && (sID <= usIDMax))
3065 )
3066 if (WinSetPresParam(hwndItem,
3067 PP_FONTNAMESIZE,
3068 cbFont,
3069 szFont))
3070 // successful:
3071 ulrc++;
3072 }
3073 WinEndEnumWindows(henum);
3074
3075 return ulrc;
3076}
3077
3078/*
3079 *@@ winhStorePresParam:
3080 * this appends a new presentation parameter to an
3081 * array of presentation parameters which can be
3082 * passed to WinCreateWindow. This is preferred
3083 * over setting the presparams using WinSetPresParams,
3084 * because that call will cause a lot of messages.
3085 *
3086 * On the first call, pppp _must_ be NULL. This
3087 * will allocate memory for storing the given
3088 * data as necessary and modify *pppp to point
3089 * to the new array.
3090 *
3091 * On subsequent calls with the same pppp, memory
3092 * will be reallocated, the old data will be copied,
3093 * and the new given data will be appended.
3094 *
3095 * Use free() on your PPRESPARAMS pointer (whose
3096 * address was passed) after WinCreateWindow.
3097 *
3098 * See winhQueryPresColor for typical presparams
3099 * used in OS/2.
3100 *
3101 * Example:
3102 *
3103 + PPRESPARAMS ppp = NULL;
3104 + CHAR szFont[] = "9.WarpSans";
3105 + LONG lColor = CLR_WHITE;
3106 + winhStorePresParam(&ppp, PP_FONTNAMESIZE, sizeof(szFont), szFont);
3107 + winhStorePresParam(&ppp, PP_BACKGROUNDCOLOR, sizeof(lColor), &lColor);
3108 + WinCreateWindow(...., ppp);
3109 + free(ppp);
3110 *
3111 *@@added V0.9.0 [umoeller]
3112 */
3113
3114BOOL winhStorePresParam(PPRESPARAMS *pppp, // in: data pointer (modified)
3115 ULONG ulAttrType, // in: PP_* index
3116 ULONG cbData, // in: sizeof(*pData), e.g. sizeof(LONG)
3117 PVOID pData) // in: presparam data (e.g. a PLONG to a color)
3118{
3119 BOOL brc = FALSE;
3120 if (pppp)
3121 {
3122 ULONG cbOld = 0,
3123 cbNew;
3124 PBYTE pbTemp = 0;
3125 PPRESPARAMS pppTemp = 0;
3126 PPARAM pppCopyTo = 0;
3127
3128 if (*pppp != NULL)
3129 // subsequent calls:
3130 cbOld = (**pppp).cb;
3131
3132 cbNew = sizeof(ULONG) // PRESPARAMS.cb
3133 + cbOld // old count, which does not include PRESPARAMS.cb
3134 + sizeof(ULONG) // PRESPARAMS.aparam[0].id
3135 + sizeof(ULONG) // PRESPARAMS.aparam[0].cb
3136 + cbData; // PRESPARAMS.aparam[0].ab[]
3137
3138 pbTemp = (PBYTE)malloc(cbNew);
3139 if (pbTemp)
3140 {
3141 pppTemp = (PPRESPARAMS)pbTemp;
3142
3143 if (*pppp != NULL)
3144 {
3145 // copy old data
3146 memcpy(pbTemp, *pppp, cbOld + sizeof(ULONG)); // including PRESPARAMS.cb
3147 pppCopyTo = (PPARAM)(pbTemp // new buffer
3148 + sizeof(ULONG) // skipping PRESPARAMS.cb
3149 + cbOld); // old PARAM array
3150 }
3151 else
3152 // first call:
3153 pppCopyTo = pppTemp->aparam;
3154
3155 pppTemp->cb = cbNew - sizeof(ULONG); // excluding PRESPARAMS.cb
3156 pppCopyTo->id = ulAttrType;
3157 pppCopyTo->cb = cbData; // byte count of PARAM.ab[]
3158 memcpy(pppCopyTo->ab, pData, cbData);
3159
3160 free(*pppp);
3161 *pppp = pppTemp;
3162
3163 brc = TRUE;
3164 }
3165 }
3166 return brc;
3167}
3168
3169/*
3170 *@@ winhQueryPresColor2:
3171 * returns the specified color. This is queried in the
3172 * following order:
3173 *
3174 * 1) hwnd's pres params are searched for ulPP
3175 * (which should be a PP_* index);
3176 * 2) if (fInherit == TRUE), the parent windows
3177 * are searched also;
3178 * 3) if this fails or (fInherit == FALSE), WinQuerySysColor
3179 * is called to get lSysColor (which should be a SYSCLR_*
3180 * index), if lSysColor != -1;
3181 * 4) if (lSysColor == -1), -1 is returned.
3182 *
3183 * The return value is always an RGB LONG, _not_ a color index.
3184 * This is even true for the returned system colors, which are
3185 * converted to RGB.
3186 *
3187 * If you do any painting with this value, you should switch
3188 * the HPS you're using to RGB mode (use gpihSwitchToRGB for that).
3189 *
3190 * Some useful ulPP / lSysColor pairs
3191 * (default values as in PMREF):
3192 *
3193 + -- PP_FOREGROUNDCOLOR SYSCLR_WINDOWTEXT (for most controls also)
3194 + SYSCLR_WINDOWSTATICTEXT (for static controls)
3195 + Foreground color (default: black)
3196 + -- PP_BACKGROUNDCOLOR SYSCLR_BACKGROUND
3197 + SYSCLR_DIALOGBACKGROUND
3198 + SYSCLR_FIELDBACKGROUND (for disabled scrollbars)
3199 + SYSCLR_WINDOW (application surface -- empty clients)
3200 + Background color (default: light gray)
3201 + -- PP_ACTIVETEXTFGNDCOLOR
3202 + -- PP_HILITEFOREGROUNDCOLOR SYSCLR_HILITEFOREGROUND
3203 + Highlighted foreground color, for example for selected menu
3204 + (def.: white)
3205 + -- PP_ACTIVETEXTBGNDCOLOR
3206 + -- PP_HILITEBACKGROUNDCOLOR SYSCLR_HILITEBACKGROUND
3207 + Highlighted background color (def.: dark gray)
3208 + -- PP_INACTIVETEXTFGNDCOLOR
3209 + -- PP_DISABLEDFOREGROUNDCOLOR SYSCLR_MENUDISABLEDTEXT
3210 + Disabled foreground color (dark gray)
3211 + -- PP_INACTIVETEXTBGNDCOLOR
3212 + -- PP_DISABLEDBACKGROUNDCOLOR
3213 + Disabled background color
3214 + -- PP_BORDERCOLOR SYSCLR_WINDOWFRAME
3215 + SYSCLR_INACTIVEBORDER
3216 + Border color (around pushbuttons, in addition to
3217 + the 3D colors)
3218 + -- PP_ACTIVECOLOR SYSCLR_ACTIVETITLE
3219 + Active color
3220 + -- PP_INACTIVECOLOR SYSCLR_INACTIVETITLE
3221 + Inactive color
3222 *
3223 * For menus:
3224 + -- PP_MENUBACKGROUNDCOLOR SYSCLR_MENU
3225 + -- PP_MENUFOREGROUNDCOLOR SYSCLR_MENUTEXT
3226 + -- PP_MENUHILITEBGNDCOLOR SYSCLR_MENUHILITEBGND
3227 + -- PP_MENUHILITEFGNDCOLOR SYSCLR_MENUHILITE
3228 + -- ?? SYSCLR_MENUDISABLEDTEXT
3229 +
3230 * For containers (according to the API ref. at EDM/2):
3231 + -- PP_FOREGROUNDCOLOR SYSCLR_WINDOWTEXT
3232 + -- PP_BACKGROUNDCOLOR SYSCLR_WINDOW
3233 + -- PP_HILITEFOREGROUNDCOLOR SYSCLR_HILITEFOREGROUND
3234 + -- PP_HILITEBACKGROUNDCOLOR SYSCLR_HILITEBACKGROUND
3235 + -- PP_BORDERCOLOR
3236 + (used for separator lines, eg. in Details view)
3237 + -- PP_ICONTEXTBACKGROUNDCOLOR
3238 + (column titles in Details view?!?)
3239 +
3240 * For listboxes / entryfields / MLE's:
3241 + -- PP_BACKGROUNDCOLOR SYSCLR_ENTRYFIELD
3242 *
3243 * PMREF has more of these.
3244 *
3245 *@@changed V0.9.0 [umoeller]: removed INI key query, using SYSCLR_* instead; function prototype changed
3246 *@@changed V0.9.0 [umoeller]: added fInherit parameter
3247 *@@changed V0.9.7 (2000-12-02) [umoeller]: added lSysColor == -1 support
3248 *@@changed V0.9.20 (2002-08-04) [umoeller]: added ulPPIndex, renamed func
3249 */
3250
3251LONG winhQueryPresColor2(HWND hwnd, // in: window to query
3252 ULONG ulppRGB, // in: PP_* index for RGB color
3253 ULONG ulppIndex, // in: PP_* index for color _index_ (can be null)
3254 BOOL fInherit, // in: search parent windows too?
3255 LONG lSysColor) // in: SYSCLR_* index or -1
3256{
3257 ULONG ul,
3258 attrFound;
3259 LONG lColorFound;
3260
3261 if (ulppRGB != (ULONG)-1)
3262 {
3263 ULONG fl = 0;
3264 if (!fInherit)
3265 fl = QPF_NOINHERIT;
3266 if (ulppIndex)
3267 fl |= QPF_ID2COLORINDEX; // convert indexed color 2 to RGB V0.9.20 (2002-08-04) [umoeller]
3268
3269 if ((ul = WinQueryPresParam(hwnd,
3270 ulppRGB,
3271 ulppIndex,
3272 &attrFound,
3273 sizeof(lColorFound),
3274 &lColorFound,
3275 fl)))
3276 return lColorFound;
3277 }
3278
3279 // not found: get system color
3280 if (lSysColor != -1)
3281 return WinQuerySysColor(HWND_DESKTOP, lSysColor, 0);
3282
3283 return -1;
3284}
3285
3286/*
3287 *@@ winhQueryPresColor:
3288 * compatibility function because this one was
3289 * exported.
3290 *
3291 *@@added V0.9.20 (2002-08-04) [umoeller]
3292 */
3293
3294LONG XWPENTRY winhQueryPresColor(HWND hwnd,
3295 ULONG ulPP,
3296 BOOL fInherit,
3297 LONG lSysColor)
3298{
3299 return winhQueryPresColor2(hwnd,
3300 ulPP,
3301 0,
3302 fInherit,
3303 lSysColor);
3304}
3305
3306/*
3307 *@@ winhSetPresColor:
3308 * sets a color presparam. ulIndex specifies
3309 * the presparam to be set and would normally
3310 * be either PP_BACKGROUNDCOLOR or PP_FOREGROUNDCOLOR.
3311 *
3312 *@@added V0.9.16 (2001-10-15) [umoeller]
3313 */
3314
3315BOOL winhSetPresColor(HWND hwnd,
3316 ULONG ulIndex,
3317 LONG lColor)
3318{
3319 return WinSetPresParam(hwnd,
3320 ulIndex,
3321 sizeof(LONG),
3322 &lColor);
3323}
3324
3325/*
3326 *@@category: Helpers\PM helpers\Help (IPF)
3327 */
3328
3329/* ******************************************************************
3330 *
3331 * Help instance helpers
3332 *
3333 ********************************************************************/
3334
3335/*
3336 *@@ winhCreateHelp:
3337 * creates a help instance and connects it with the
3338 * given frame window.
3339 *
3340 * If (pszFileName == NULL), we'll retrieve the
3341 * executable's fully qualified file name and
3342 * replace the extension with .HLP simply. This
3343 * avoids the typical "Help not found" errors if
3344 * the program isn't started in its own directory.
3345 *
3346 * If you have created a help table in memory, specify it
3347 * with pHelpTable. To load a help table from the resources,
3348 * specify hmod (or NULLHANDLE) and set pHelpTable to the
3349 * following:
3350 +
3351 + (PHELPTABLE)MAKELONG(usTableID, 0xffff)
3352 *
3353 * Returns the help window handle or NULLHANDLE on errors.
3354 *
3355 * Based on an EDM/2 code snippet.
3356 *
3357 *@@added V0.9.4 (2000-07-03) [umoeller]
3358 */
3359
3360HWND winhCreateHelp(HWND hwndFrame, // in: app's frame window handle; can be NULLHANDLE
3361 const char *pcszFileName, // in: help file name or NULL
3362 HMODULE hmod, // in: module with help table or NULLHANDLE (current)
3363 PHELPTABLE pHelpTable, // in: help table or resource ID
3364 const char *pcszWindowTitle) // in: help window title or NULL
3365{
3366 HELPINIT hi;
3367 PSZ pszExt;
3368 CHAR szName[CCHMAXPATH];
3369 HWND hwndHelp;
3370
3371 if (pcszFileName == NULL)
3372 {
3373 PPIB ppib;
3374 PTIB ptib;
3375 DosGetInfoBlocks(&ptib, &ppib);
3376 DosQueryModuleName(ppib->pib_hmte, sizeof(szName), szName);
3377
3378 pszExt = strrchr(szName, '.');
3379 if (pszExt)
3380 strcpy(pszExt, ".hlp");
3381 else
3382 strcat(szName, ".hlp");
3383
3384 pcszFileName = szName;
3385 }
3386
3387 hi.cb = sizeof(HELPINIT);
3388 hi.ulReturnCode = 0;
3389 hi.pszTutorialName = NULL;
3390 hi.phtHelpTable = pHelpTable;
3391 hi.hmodHelpTableModule = hmod;
3392 hi.hmodAccelActionBarModule = NULLHANDLE;
3393 hi.idAccelTable = 0;
3394 hi.idActionBar = 0;
3395 hi.pszHelpWindowTitle = (PSZ)pcszWindowTitle;
3396 hi.fShowPanelId = CMIC_HIDE_PANEL_ID;
3397 hi.pszHelpLibraryName = (PSZ)pcszFileName;
3398
3399 hwndHelp = WinCreateHelpInstance(WinQueryAnchorBlock(hwndFrame),
3400 &hi);
3401 if ((hwndFrame) && (hwndHelp))
3402 {
3403 WinAssociateHelpInstance(hwndHelp, hwndFrame);
3404 }
3405
3406 return hwndHelp;
3407}
3408
3409/*
3410 *@@ winhDisplayHelpPanel:
3411 * displays the specified help panel ID.
3412 *
3413 * If (ulHelpPanel == 0), this displays the
3414 * standard OS/2 "Using help" panel.
3415 *
3416 * Returns zero on success or one of the
3417 * help manager error codes on failure.
3418 * See HM_ERROR for those.
3419 *
3420 *@@added V0.9.7 (2001-01-21) [umoeller]
3421 */
3422
3423ULONG winhDisplayHelpPanel(HWND hwndHelpInstance, // in: from winhCreateHelp
3424 ULONG ulHelpPanel) // in: help panel ID
3425{
3426 return (ULONG)WinSendMsg(hwndHelpInstance,
3427 HM_DISPLAY_HELP,
3428 (MPARAM)ulHelpPanel,
3429 (MPARAM)( (ulHelpPanel != 0)
3430 ? HM_RESOURCEID
3431 : 0));
3432}
3433
3434/*
3435 *@@ winhDestroyHelp:
3436 * destroys the help instance created by winhCreateHelp.
3437 *
3438 * Based on an EDM/2 code snippet.
3439 *
3440 *@@added V0.9.4 (2000-07-03) [umoeller]
3441 */
3442
3443void winhDestroyHelp(HWND hwndHelp,
3444 HWND hwndFrame) // can be NULLHANDLE if not used with winhCreateHelp
3445{
3446 if (hwndHelp)
3447 {
3448 if (hwndFrame)
3449 WinAssociateHelpInstance(NULLHANDLE, hwndFrame);
3450 WinDestroyHelpInstance(hwndHelp);
3451 }
3452}
3453
3454/*
3455 *@@category: Helpers\PM helpers\Application control
3456 */
3457
3458/* ******************************************************************
3459 *
3460 * Application control
3461 *
3462 ********************************************************************/
3463
3464/*
3465 *@@ winhAnotherInstance:
3466 * this tests whether another instance of the same
3467 * application is already running.
3468 *
3469 * To identify instances of the same application, the
3470 * application must call this function during startup
3471 * with the unique name of an OS/2 semaphore. As with
3472 * all OS/2 semaphores, the semaphore name must begin
3473 * with "\\SEM32\\". The semaphore isn't really used
3474 * except for testing for its existence, since that
3475 * name is unique among all processes.
3476 *
3477 * If another instance is found, TRUE is returned. If
3478 * (fSwitch == TRUE), that instance is switched to,
3479 * using the tasklist.
3480 *
3481 * If no other instance is found, FALSE is returned only.
3482 *
3483 * Based on an EDM/2 code snippet.
3484 *
3485 *@@added V0.9.0 (99-10-22) [umoeller]
3486 */
3487
3488BOOL winhAnotherInstance(const char *pcszSemName, // in: semaphore ID
3489 BOOL fSwitch) // in: if TRUE, switch to first instance if running
3490{
3491 HMTX hmtx;
3492
3493 if (DosCreateMutexSem((PSZ)pcszSemName,
3494 &hmtx,
3495 DC_SEM_SHARED,
3496 TRUE)
3497 == NO_ERROR)
3498 // semapore created: this doesn't happen if the semaphore
3499 // exists already, so no other instance is running
3500 return FALSE;
3501
3502 // else: instance running
3503 hmtx = NULLHANDLE;
3504
3505 // switch to other instance?
3506 if (fSwitch)
3507 {
3508 // yes: query mutex creator
3509 if (DosOpenMutexSem((PSZ)pcszSemName,
3510 &hmtx)
3511 == NO_ERROR)
3512 {
3513 PID pid = 0;
3514 TID tid = 0; // unused
3515 ULONG ulCount; // unused
3516
3517 if (DosQueryMutexSem(hmtx, &pid, &tid, &ulCount) == NO_ERROR)
3518 {
3519 HSWITCH hswitch = WinQuerySwitchHandle(NULLHANDLE, pid);
3520 if (hswitch != NULLHANDLE)
3521 WinSwitchToProgram(hswitch);
3522 }
3523
3524 DosCloseMutexSem(hmtx);
3525 }
3526 }
3527
3528 return TRUE; // another instance exists
3529}
3530
3531/*
3532 *@@ winhAddToTasklist:
3533 * this adds the specified window to the tasklist
3534 * with hIcon as its program icon (which is also
3535 * set for the main window). This is useful for
3536 * the old "dialog as main window" trick.
3537 *
3538 * Returns the HSWITCH of the added entry.
3539 */
3540
3541HSWITCH winhAddToTasklist(HWND hwnd, // in: window to add
3542 HPOINTER hIcon) // in: icon for main window
3543{
3544 SWCNTRL swctl;
3545 HSWITCH hswitch = 0;
3546 swctl.hwnd = hwnd; // window handle
3547 swctl.hwndIcon = hIcon; // icon handle
3548 swctl.hprog = NULLHANDLE; // program handle (use default)
3549 WinQueryWindowProcess(hwnd, &(swctl.idProcess), NULL);
3550 // process identifier
3551 swctl.idSession = 0; // session identifier ?
3552 swctl.uchVisibility = SWL_VISIBLE; // visibility
3553 swctl.fbJump = SWL_JUMPABLE; // jump indicator
3554 // get window title from window titlebar
3555 if (hwnd)
3556 WinQueryWindowText(hwnd, sizeof(swctl.szSwtitle), swctl.szSwtitle);
3557 swctl.bProgType = PROG_DEFAULT; // program type
3558 hswitch = WinAddSwitchEntry(&swctl);
3559
3560 // give the main window the icon
3561 if ((hwnd) && (hIcon))
3562 WinSendMsg(hwnd,
3563 WM_SETICON,
3564 (MPARAM)hIcon,
3565 NULL);
3566
3567 return hswitch;
3568}
3569
3570/*
3571 *@@category: Helpers\PM helpers\Miscellaneous
3572 */
3573
3574/* ******************************************************************
3575 *
3576 * Miscellaneous
3577 *
3578 ********************************************************************/
3579
3580/*
3581 *@@ winhMyAnchorBlock:
3582 * returns the proper anchor block (HAB)
3583 * for the calling thread.
3584 *
3585 * Many Win* functions require an HAB to be
3586 * passed in. While many of them will work
3587 * when passing in NULLHANDLE, some (such as
3588 * WinGetMsg) won't. If you don't know the
3589 * anchor block of the calling thread, use
3590 * this function.
3591 *
3592 * This creates a temporary object window to
3593 * find out the anchor block. This is quite
3594 * expensive so only use this if there's no
3595 * other way to find out.
3596 *
3597 *@@added V0.9.11 (2001-04-20) [umoeller]
3598 */
3599
3600HAB winhMyAnchorBlock(VOID)
3601{
3602 HAB hab = NULLHANDLE;
3603 HWND hwnd;
3604 if (hwnd = winhCreateObjectWindow(WC_BUTTON, NULL))
3605 {
3606 hab = WinQueryAnchorBlock(hwnd);
3607 WinDestroyWindow(hwnd);
3608 }
3609
3610 return hab;
3611}
3612
3613/*
3614 *@@ winhFree:
3615 * frees a block of memory allocated by the
3616 * winh* functions.
3617 *
3618 * Since the winh* functions use malloc(),
3619 * you can also use free() directly on such
3620 * blocks. However, you must use winhFree
3621 * if the winh* functions are in a module
3622 * with a different C runtime.
3623 *
3624 *@@added V0.9.7 (2000-12-06) [umoeller]
3625 */
3626
3627VOID winhFree(PVOID p)
3628{
3629 if (p)
3630 free(p);
3631}
3632
3633/*
3634 *@@ winhSleep:
3635 * sleeps at least the specified amount of time,
3636 * without blocking the message queue.
3637 *
3638 * NOTE: This function is a bit expensive because
3639 * it creates a temporary object window. If you
3640 * need to sleep several times, you should rather
3641 * use a private timer.
3642 *
3643 *@@added V0.9.4 (2000-07-11) [umoeller]
3644 *@@changed V0.9.9 (2001-03-11) [umoeller]: rewritten
3645 */
3646
3647VOID winhSleep(ULONG ulSleep) // in: sleep time in milliseconds
3648{
3649 HWND hwnd;
3650
3651 if (hwnd = winhCreateObjectWindow(WC_STATIC, NULL))
3652 {
3653 QMSG qmsg;
3654 HAB hab;
3655
3656 if ( (hab = WinQueryAnchorBlock(hwnd))
3657 && (WinStartTimer(hab,
3658 hwnd,
3659 1,
3660 ulSleep))
3661 )
3662 {
3663 while (WinGetMsg(hab, &qmsg, NULLHANDLE, 0, 0))
3664 {
3665 if ( (qmsg.hwnd == hwnd)
3666 && (qmsg.msg == WM_TIMER)
3667 && (qmsg.mp1 == (MPARAM)1) // timer ID
3668 )
3669 break;
3670
3671 WinDispatchMsg(hab, &qmsg);
3672 }
3673 WinStopTimer(hab,
3674 hwnd,
3675 1);
3676 }
3677 else
3678 // timer creation failed:
3679 DosSleep(ulSleep);
3680
3681 WinDestroyWindow(hwnd);
3682 }
3683 else
3684 DosSleep(ulSleep);
3685}
3686
3687/*
3688 *@@ winhFileDlg:
3689 * one-short function for opening an "Open" file
3690 * dialog.
3691 *
3692 * On input, pszFile specifies the directory and
3693 * file specification (e.g. "F:\*.txt").
3694 *
3695 * Returns TRUE if the user pressed OK. In that
3696 * case, the fully qualified filename is written
3697 * into pszFile again.
3698 *
3699 * Returns FALSE if the user pressed Cancel.
3700 *
3701 * Notes about flFlags:
3702 *
3703 * -- WINH_FOD_SAVEDLG: display a "Save As" dialog.
3704 * Otherwise an "Open" dialog is displayed.
3705 *
3706 * -- WINH_FOD_INILOADDIR: load a directory from the
3707 * specified INI key and switch the dlg to it.
3708 * In that case, on input, pszFile must only
3709 * contain the file filter without any path
3710 * specification, because that is loaded from
3711 * the INI key. If the INI key does not exist,
3712 * the current process directory will be used.
3713 *
3714 * -- WINH_FOD_INISAVEDIR: if the user presses OK,
3715 * the directory of the selected file is written
3716 * to the specified INI key so that it can be
3717 * reused later. This flag is independent of
3718 * WINH_FOD_INISAVEDIR: you can specify none,
3719 * one, or both of them.
3720 *
3721 *@@added V0.9.3 (2000-04-29) [umoeller]
3722 *@@changed V0.9.12 (2001-05-21) [umoeller]: this failed if INI data had root dir, fixed
3723 */
3724
3725BOOL winhFileDlg(HWND hwndOwner, // in: owner for file dlg
3726 PSZ pszFile, // in: file mask; out: fully q'd filename
3727 // (should be CCHMAXPATH in size)
3728 ULONG flFlags, // in: any combination of the following:
3729 // -- WINH_FOD_SAVEDLG: save dlg; else open dlg
3730 // -- WINH_FOD_INILOADDIR: load FOD path from INI
3731 // -- WINH_FOD_INISAVEDIR: store FOD path to INI on OK
3732 HINI hini, // in: INI file to load/store last path from (can be HINI_USER)
3733 const char *pcszApplication, // in: INI application to load/store last path from
3734 const char *pcszKey) // in: INI key to load/store last path from
3735{
3736 FILEDLG fd;
3737 FILESTATUS3 fs3;
3738
3739 memset(&fd, 0, sizeof(FILEDLG));
3740 fd.cbSize = sizeof(FILEDLG);
3741 fd.fl = FDS_CENTER;
3742
3743 if (flFlags & WINH_FOD_SAVEDLG)
3744 fd.fl |= FDS_SAVEAS_DIALOG;
3745 else
3746 fd.fl |= FDS_OPEN_DIALOG;
3747
3748 if ( (hini)
3749 && (flFlags & WINH_FOD_INILOADDIR)
3750 && (PrfQueryProfileString(hini,
3751 (PSZ)pcszApplication,
3752 (PSZ)pcszKey,
3753 "", // default string V0.9.9 (2001-02-10) [umoeller]
3754 fd.szFullFile,
3755 sizeof(fd.szFullFile)-10)
3756 > 2)
3757 // added these checks V0.9.12 (2001-05-21) [umoeller]
3758 && (!DosQueryPathInfo(fd.szFullFile,
3759 FIL_STANDARD,
3760 &fs3,
3761 sizeof(fs3)))
3762 && (fs3.attrFile & FILE_DIRECTORY)
3763 )
3764 {
3765 // found: append "\*"
3766 strcat(fd.szFullFile, "\\");
3767 strcat(fd.szFullFile, pszFile);
3768 }
3769 else
3770 // default: copy pszFile
3771 strcpy(fd.szFullFile, pszFile);
3772 // fixed V0.9.12 (2001-05-21) [umoeller]
3773
3774 if ( WinFileDlg(HWND_DESKTOP, // parent
3775 hwndOwner, // owner
3776 &fd)
3777 && (fd.lReturn == DID_OK)
3778 )
3779 {
3780 // save path back?
3781 if ( (hini)
3782 && (flFlags & WINH_FOD_INISAVEDIR)
3783 )
3784 {
3785 // get the directory that was used
3786 PSZ p = strrchr(fd.szFullFile, '\\');
3787 if (p)
3788 {
3789 // contains directory:
3790 // copy to OS2.INI
3791 PSZ pszDir = strhSubstr(fd.szFullFile, p);
3792 if (pszDir)
3793 {
3794 PrfWriteProfileString(hini,
3795 (PSZ)pcszApplication,
3796 (PSZ)pcszKey,
3797 pszDir);
3798 free(pszDir);
3799 }
3800 }
3801 }
3802
3803 strcpy(pszFile, fd.szFullFile);
3804
3805 return TRUE;
3806 }
3807
3808 return FALSE;
3809}
3810
3811/*
3812 *@@ winhSetWaitPointer:
3813 * this sets the mouse pointer to "Wait".
3814 * Returns the previous pointer (HPOINTER),
3815 * which should be stored somewhere to be
3816 * restored later. Example:
3817 + HPOINTER hptrOld = winhSetWaitPointer();
3818 + ...
3819 + WinSetPointer(HWND_DESKTOP, hptrOld);
3820 */
3821
3822HPOINTER winhSetWaitPointer(VOID)
3823{
3824 HPOINTER hptr = WinQueryPointer(HWND_DESKTOP);
3825 WinSetPointer(HWND_DESKTOP,
3826 WinQuerySysPointer(HWND_DESKTOP,
3827 SPTR_WAIT,
3828 FALSE)); // no copy
3829 return hptr;
3830}
3831
3832/*
3833 *@@ winhQueryWindowText:
3834 * this returns the window text of the specified
3835 * HWND in a newly allocated buffer.
3836 *
3837 * Returns NULL on error. Use free()
3838 * to free the return value.
3839 */
3840
3841PSZ winhQueryWindowText(HWND hwnd)
3842{
3843 PSZ pszText = NULL;
3844 ULONG cbText = WinQueryWindowTextLength(hwnd);
3845 // additional null character
3846 if (cbText)
3847 {
3848 if (pszText = (PSZ)malloc(cbText + 1))
3849 WinQueryWindowText(hwnd,
3850 cbText + 1,
3851 pszText);
3852 }
3853 return pszText;
3854}
3855
3856/*
3857 *@@ winhSetWindowText:
3858 * like WinSetWindowText, but this one accepts
3859 * printf-like arguments.
3860 *
3861 * Note that the total string is limited to
3862 * 1000 characters.
3863 *
3864 *@@added V0.9.16 (2001-10-08) [umoeller]
3865 */
3866
3867BOOL winhSetWindowText(HWND hwnd,
3868 const char *pcszFormat,
3869 ...)
3870{
3871 CHAR szBuf[1000];
3872 va_list args;
3873 int i;
3874 va_start(args, pcszFormat);
3875 i = vsprintf(szBuf, pcszFormat, args);
3876 va_end(args);
3877
3878 return WinSetWindowText(hwnd,
3879 szBuf);
3880}
3881
3882/*
3883 *@@ winhReplaceWindowText:
3884 * this is a combination of winhQueryWindowText
3885 * and strhFindReplace to replace substrings in a window.
3886 *
3887 * This is useful for filling in placeholders
3888 * a la "%1" in control windows, e.g. static
3889 * texts.
3890 *
3891 * This replaces only the first occurence of
3892 * pszSearch.
3893 *
3894 * Returns TRUE only if the window exists and
3895 * the search string was replaced.
3896 *
3897 *@@added V0.9.0 [umoeller]
3898 */
3899
3900BOOL winhReplaceWindowText(HWND hwnd, // in: window whose text is to be modified
3901 const char *pcszSearch, // in: search string (e.g. "%1")
3902 const char *pcszReplaceWith) // in: replacement string for pszSearch
3903{
3904 BOOL brc = FALSE;
3905 PSZ pszText = winhQueryWindowText(hwnd);
3906 if (pszText)
3907 {
3908 ULONG ulOfs = 0;
3909 if (strhFindReplace(&pszText, &ulOfs, pcszSearch, pcszReplaceWith) > 0)
3910 {
3911 WinSetWindowText(hwnd, pszText);
3912 brc = TRUE;
3913 }
3914 free(pszText);
3915 }
3916 return brc;
3917}
3918
3919/*
3920 *@@ winhEnableDlgItems:
3921 * this enables/disables a whole range of controls
3922 * in a window by enumerating the child windows
3923 * until usIDFirst is found. If so, that subwindow
3924 * is enabled/disabled and all the following windows
3925 * in the enumeration also, until usIDLast is found.
3926 *
3927 * Note that this affects _all_ controls following
3928 * the usIDFirst window, no matter what ID they have
3929 * (even if "-1"), until usIDLast is found.
3930 *
3931 * Returns the no. of controls which were enabled/disabled
3932 * (null if none).
3933 *
3934 *@@added V0.9.0 [umoeller]
3935 *@@changed V0.9.1 (99-12-20) [umoeller]: renamed from winhEnableDlgItems
3936 */
3937
3938ULONG winhEnableControls(HWND hwndDlg, // in: dialog window
3939 USHORT usIDFirst, // in: first affected control ID
3940 USHORT usIDLast, // in: last affected control ID (inclusive)
3941 BOOL fEnable) // in: enable or disable?
3942{
3943 HENUM henum1 = NULLHANDLE;
3944 HWND hwndThis = NULLHANDLE;
3945 ULONG ulCount = 0;
3946
3947 henum1 = WinBeginEnumWindows(hwndDlg);
3948 while ((hwndThis = WinGetNextWindow(henum1)) != NULLHANDLE)
3949 {
3950 USHORT usIDCheckFirst = WinQueryWindowUShort(hwndThis, QWS_ID),
3951 usIDCheckLast;
3952 if (usIDCheckFirst == usIDFirst)
3953 {
3954 WinEnableWindow(hwndThis, fEnable);
3955 ulCount++;
3956
3957 while ((hwndThis = WinGetNextWindow(henum1)) != NULLHANDLE)
3958 {
3959 WinEnableWindow(hwndThis, fEnable);
3960 ulCount++;
3961 usIDCheckLast = WinQueryWindowUShort(hwndThis, QWS_ID);
3962 if (usIDCheckLast == usIDLast)
3963 break;
3964 }
3965
3966 break; // outer loop
3967 }
3968 }
3969 WinEndEnumWindows(henum1);
3970
3971 return ulCount;
3972}
3973
3974/*
3975 *@@ winhEnableControls2:
3976 * like winhEnableControls, but instead this
3977 * takes an array of ULONGs as input, which
3978 * is assumed to contain the dialog IDs of
3979 * the controls to be enabled/disabled.
3980 *
3981 *@@added V0.9.19 (2002-05-28) [umoeller]
3982 */
3983
3984ULONG winhEnableControls2(HWND hwndDlg, // in: dialog window
3985 const ULONG *paulIDs, // in: array of dialog IDs
3986 ULONG cIDs, // in: array item count (NOT array size)
3987 BOOL fEnable) // in: enable or disable?
3988{
3989 ULONG ul,
3990 ulrc = 0;
3991 for (ul = 0;
3992 ul < cIDs;
3993 ++ul)
3994 {
3995 if (WinEnableControl(hwndDlg, paulIDs[ul], fEnable))
3996 ++ulrc;
3997 }
3998
3999 return ulrc;
4000}
4001
4002/*
4003 *@@ winhCreateStdWindow:
4004 * much like WinCreateStdWindow, but this one
4005 * allows you to have the standard window
4006 * positioned automatically, using a given
4007 * SWP structure (*pswpFrame).
4008 *
4009 * The frame is created with the specified parent
4010 * (usually HWND_DESKTOP), but no owner.
4011 *
4012 * The client window is created with the frame as
4013 * its parent and owner and gets an ID of FID_CLIENT.
4014 *
4015 * Alternatively, you can set pswpFrame to NULL
4016 * and specify FCF_SHELLPOSITION with flFrameCreateFlags.
4017 * If you want the window to be shown, specify
4018 * SWP_SHOW (and maybe SWP_ACTIVATE) in *pswpFrame.
4019 *
4020 *@@added V0.9.0 [umoeller]
4021 *@@changed V0.9.5 (2000-08-13) [umoeller]: flStyleClient never worked, fixed
4022 *@@changed V0.9.7 (2000-12-08) [umoeller]: fixed client calc for invisible window
4023 */
4024
4025HWND winhCreateStdWindow(HWND hwndFrameParent, // in: normally HWND_DESKTOP
4026 PSWP pswpFrame, // in: frame wnd pos (ptr can be NULL)
4027 ULONG flFrameCreateFlags, // in: FCF_* flags
4028 ULONG ulFrameStyle, // in: WS_* flags (e.g. WS_VISIBLE, WS_ANIMATE)
4029 const char *pcszFrameTitle, // in: frame title (title bar)
4030 ULONG ulResourcesID, // in: according to FCF_* flags
4031 const char *pcszClassClient, // in: client class name
4032 ULONG flStyleClient, // in: client style
4033 ULONG ulID, // in: frame window ID
4034 PVOID pClientCtlData, // in: pCtlData structure pointer for client
4035 PHWND phwndClient) // out: created client wnd
4036{
4037 FRAMECDATA fcdata;
4038 HWND hwndFrame;
4039 RECTL rclClient;
4040
4041 fcdata.cb = sizeof(FRAMECDATA);
4042 fcdata.flCreateFlags = flFrameCreateFlags;
4043 fcdata.hmodResources = (HMODULE)NULL;
4044 fcdata.idResources = ulResourcesID;
4045
4046 /* Create the frame and client windows. */
4047 hwndFrame = WinCreateWindow(hwndFrameParent,
4048 WC_FRAME,
4049 (PSZ)pcszFrameTitle,
4050 ulFrameStyle,
4051 0,0,0,0, // size and position = 0
4052 NULLHANDLE, // no owner
4053 HWND_TOP, // z-order
4054 ulID, // frame window ID
4055 &fcdata, // frame class data
4056 NULL); // no presparams
4057
4058 if (hwndFrame)
4059 {
4060 if (*phwndClient = WinCreateWindow(hwndFrame, // parent
4061 (PSZ)pcszClassClient, // class
4062 NULL, // no title
4063 flStyleClient, // style
4064 0,0,0,0, // size and position = 0
4065 hwndFrame, // owner
4066 HWND_BOTTOM, // bottom z-order
4067 FID_CLIENT, // frame window ID
4068 pClientCtlData, // class data
4069 NULL)) // no presparams
4070 {
4071 if (pswpFrame)
4072 {
4073 // position frame
4074 WinSetWindowPos(hwndFrame,
4075 pswpFrame->hwndInsertBehind,
4076 pswpFrame->x,
4077 pswpFrame->y,
4078 pswpFrame->cx,
4079 pswpFrame->cy,
4080 pswpFrame->fl);
4081
4082 // position client
4083 // WinQueryWindowRect(hwndFrame, &rclClient);
4084 // doesn't work because it might be invisible V0.9.7 (2000-12-08) [umoeller]
4085 rclClient.xLeft = 0;
4086 rclClient.yBottom = 0;
4087 rclClient.xRight = pswpFrame->cx;
4088 rclClient.yTop = pswpFrame->cy;
4089 WinCalcFrameRect(hwndFrame,
4090 &rclClient,
4091 TRUE); // calc client from frame
4092 WinSetWindowPos(*phwndClient,
4093 HWND_TOP,
4094 rclClient.xLeft,
4095 rclClient.yBottom,
4096 rclClient.xRight - rclClient.xLeft,
4097 rclClient.yTop - rclClient.yBottom,
4098 SWP_MOVE | SWP_SIZE | SWP_SHOW);
4099 }
4100 }
4101 }
4102
4103 return hwndFrame;
4104}
4105
4106/*
4107 *@@ winhCreateObjectWindow:
4108 * creates an object window of the specified
4109 * window class, which you should have registered
4110 * before calling this. pvCreateParam will be
4111 * given to the window on WM_CREATE.
4112 *
4113 * Returns the HWND of the object window or
4114 * NULLHANDLE on errors.
4115 *
4116 *@@added V0.9.3 (2000-04-17) [umoeller]
4117 *@@changed V0.9.7 (2001-01-17) [umoeller]: made this a function from a macro
4118 */
4119
4120HWND winhCreateObjectWindow(const char *pcszWindowClass, // in: PM window class name
4121 PVOID pvCreateParam) // in: create param
4122{
4123 return WinCreateWindow(HWND_OBJECT,
4124 (PSZ)pcszWindowClass,
4125 (PSZ)"",
4126 0,
4127 0,0,0,0,
4128 0,
4129 HWND_BOTTOM,
4130 0,
4131 pvCreateParam,
4132 NULL);
4133}
4134
4135/*
4136 *@@ winhCreateControl:
4137 * creates a control with a size and position of 0.
4138 *
4139 *@@added V0.9.9 (2001-03-13) [umoeller]
4140 *@@changed V1.0.0 (2002-08-26) [umoeller]: added separate hwndOwner
4141 */
4142
4143HWND winhCreateControl(HWND hwndParent, // in: parent window
4144 HWND hwndOwner, // in: owner window
4145 const char *pcszClass, // in: window class (e.g. WC_BUTTON)
4146 const char *pcszText, // in: window title
4147 ULONG ulStyle, // in: control style
4148 ULONG ulID) // in: control ID
4149{
4150 return WinCreateWindow(hwndParent,
4151 (PSZ)pcszClass,
4152 (PSZ)pcszText,
4153 ulStyle,
4154 0, 0, 0, 0,
4155 hwndOwner,
4156 HWND_TOP,
4157 ulID,
4158 NULL,
4159 NULL);
4160}
4161
4162/*
4163 *@@ winhRepaintWindows:
4164 * this repaints all children of hwndParent.
4165 * If this is passed as HWND_DESKTOP, the
4166 * whole screen is repainted.
4167 *
4168 *@@changed V0.9.7 (2000-12-13) [umoeller]: hwndParent was never respected, fixed
4169 */
4170
4171VOID winhRepaintWindows(HWND hwndParent)
4172{
4173 HWND hwndTop;
4174 HENUM henum = WinBeginEnumWindows(hwndParent);
4175 while ((hwndTop = WinGetNextWindow(henum)))
4176 if (WinIsWindowShowing(hwndTop))
4177 WinInvalidateRect(hwndTop, NULL, TRUE);
4178 WinEndEnumWindows(henum);
4179}
4180
4181/*
4182 *@@ winhFindMsgQueue:
4183 * returns the message queue which matches
4184 * the given process and thread IDs. Since,
4185 * per IBM definition, every thread may only
4186 * have one MQ, this should be unique.
4187 *
4188 *@@added V0.9.2 (2000-03-08) [umoeller]
4189 */
4190
4191HMQ winhFindMsgQueue(PID pid, // in: process ID
4192 TID tid, // in: thread ID
4193 HAB* phab) // out: anchor block
4194{
4195 HWND hwndThis = 0,
4196 rc = 0;
4197 HENUM henum = WinBeginEnumWindows(HWND_OBJECT);
4198 while ((hwndThis = WinGetNextWindow(henum)))
4199 {
4200 CHAR szClass[200];
4201 if (WinQueryClassName(hwndThis, sizeof(szClass), szClass))
4202 {
4203 if (strcmp(szClass, "#32767") == 0)
4204 {
4205 // message queue window:
4206 PID pidWin = 0;
4207 TID tidWin = 0;
4208 WinQueryWindowProcess(hwndThis,
4209 &pidWin,
4210 &tidWin);
4211 if ( (pidWin == pid)
4212 && (tidWin == tid)
4213 )
4214 {
4215 // get HMQ from window words
4216 rc = WinQueryWindowULong(hwndThis, QWL_HMQ);
4217 if (rc)
4218 if (phab)
4219 *phab = WinQueryAnchorBlock(hwndThis);
4220 break;
4221 }
4222 }
4223 }
4224 }
4225 WinEndEnumWindows(henum);
4226
4227 return rc;
4228}
4229
4230/*
4231 *@@ winhFindHardErrorWindow:
4232 * this searches all children of HWND_OBJECT
4233 * for the PM hard error windows, which are
4234 * invisible most of the time. When a hard
4235 * error occurs, that window is made a child
4236 * of HWND_DESKTOP instead.
4237 *
4238 * Stolen from ProgramCommander/2 (C) Roman Stangl.
4239 *
4240 *@@added V0.9.3 (2000-04-27) [umoeller]
4241 */
4242
4243VOID winhFindPMErrorWindows(HWND *phwndHardError, // out: hard error window
4244 HWND *phwndSysError) // out: system error window
4245{
4246 PID pidObject; // HWND_OBJECT's process and thread id
4247 TID tidObject;
4248 PID pidObjectChild; // HWND_OBJECT's child window process and thread id
4249 TID tidObjectChild;
4250 HENUM henumObject; // HWND_OBJECT enumeration handle
4251 HWND hwndObjectChild; // Window handle of current HWND_OBJECT child
4252 UCHAR ucClassName[32]; // Window class e.g. #1 for WC_FRAME
4253 CLASSINFO classinfoWindow; // Class info of current HWND_OBJECT child
4254
4255 *phwndHardError = NULLHANDLE;
4256 *phwndSysError = NULLHANDLE;
4257
4258 // query HWND_OBJECT's window process
4259 WinQueryWindowProcess(WinQueryObjectWindow(HWND_DESKTOP), &pidObject, &tidObject);
4260 // enumerate all child windows of HWND_OBJECT
4261 henumObject = WinBeginEnumWindows(HWND_OBJECT);
4262 while ((hwndObjectChild = WinGetNextWindow(henumObject)) != NULLHANDLE)
4263 {
4264 // see if the current HWND_OBJECT child window runs in the
4265 // process of HWND_OBJECT (PM)
4266 WinQueryWindowProcess(hwndObjectChild, &pidObjectChild, &tidObjectChild);
4267 if (pidObject == pidObjectChild)
4268 {
4269 // get the child window's data
4270 WinQueryClassName(hwndObjectChild,
4271 sizeof(ucClassName),
4272 (PCH)ucClassName);
4273 WinQueryClassInfo(WinQueryAnchorBlock(hwndObjectChild),
4274 (PSZ)ucClassName,
4275 &classinfoWindow);
4276 if ( (!strcmp((PSZ)ucClassName, "#1")
4277 || (classinfoWindow.flClassStyle & CS_FRAME))
4278 )
4279 {
4280 // if the child window is a frame window and running in
4281 // HWND_OBJECT's (PM's) window process, it must be the
4282 // PM Hard Error or System Error window
4283 WinQueryClassName(WinWindowFromID(hwndObjectChild,
4284 FID_CLIENT),
4285 sizeof(ucClassName),
4286 (PSZ)ucClassName);
4287 if (!strcmp((PSZ)ucClassName, "PM Hard Error"))
4288 {
4289 *phwndHardError = hwndObjectChild;
4290 if (*phwndSysError)
4291 // we found the other one already:
4292 // stop searching, we got both
4293 break;
4294 }
4295 else
4296 {
4297 printf("Utility: Found System Error %08X\n", (int)hwndObjectChild);
4298 *phwndSysError = hwndObjectChild;
4299 if (*phwndHardError)
4300 // we found the other one already:
4301 // stop searching, we got both
4302 break;
4303 }
4304 }
4305 } // end if (pidObject == pidObjectChild)
4306 } // end while ((hwndObjectChild = WinGetNextWindow(henumObject)) != NULLHANDLE)
4307 WinEndEnumWindows(henumObject);
4308}
4309
4310/*
4311 *@@ winhCreateFakeDesktop:
4312 * this routine creates and displays a frameless window over
4313 * the whole screen in the color of PM's Desktop to fool the
4314 * user that all windows have been closed (which in fact might
4315 * not be the case).
4316 *
4317 * This window's background color is set to the Desktop's
4318 * (PM's one, not the WPS's one).
4319 *
4320 * Returns the HWND of this window.
4321 */
4322
4323HWND winhCreateFakeDesktop(HWND hwndSibling)
4324{
4325 // presparam for background
4326 typedef struct _BACKGROUND
4327 {
4328 ULONG cb; // length of the aparam parameter, in bytes
4329 ULONG id; // attribute type identity
4330 ULONG cb2; // byte count of the ab parameter
4331 RGB rgb; // attribute value
4332 } BACKGROUND;
4333
4334 BACKGROUND background;
4335 LONG lDesktopColor;
4336
4337 // create fake desktop window = empty window with
4338 // the size of full screen
4339 lDesktopColor = WinQuerySysColor(HWND_DESKTOP,
4340 SYSCLR_BACKGROUND,
4341 0);
4342 background.cb = sizeof(background.id)
4343 + sizeof(background.cb)
4344 + sizeof(background.rgb);
4345 background.id = PP_BACKGROUNDCOLOR;
4346 background.cb2 = sizeof(RGB);
4347 background.rgb.bBlue = (CHAR1FROMMP(lDesktopColor));
4348 background.rgb.bGreen= (CHAR2FROMMP(lDesktopColor));
4349 background.rgb.bRed = (CHAR3FROMMP(lDesktopColor));
4350
4351 return WinCreateWindow(HWND_DESKTOP, // parent window
4352 WC_FRAME, // class name
4353 "", // window text
4354 WS_VISIBLE, // window style
4355 0, 0, // position and size
4356 WinQuerySysValue(HWND_DESKTOP, SV_CXSCREEN),
4357 WinQuerySysValue(HWND_DESKTOP, SV_CYSCREEN),
4358 NULLHANDLE, // owner window
4359 hwndSibling, // sibling window
4360 1, // window id
4361 NULL, // control data
4362 &background); // presentation parms
4363}
4364
4365/*
4366 *@@ winhAssertWarp4Notebook:
4367 * this takes hwndDlg as a notebook dialog page and
4368 * goes thru all its controls. If a control with an
4369 * ID <= udIdThreshold is found, this is assumed to
4370 * be a button which is to be given the BS_NOTEBOOKBUTTON
4371 * style. You should therefore give all your button
4372 * controls which should be moved such an ID.
4373 *
4374 * Note that this function will now automatically
4375 * find out the lowest y coordinate that was used
4376 * for a non-notebook button and move all controls
4377 * down accordingly. As a result, ulDownUnit must
4378 * no longer be specified (V0.9.19).
4379 *
4380 * This function is useful if you wish to create
4381 * notebook pages using dlgedit.exe which are compatible
4382 * with both Warp 3 and Warp 4. This should be executed
4383 * in WM_INITDLG of the notebook dlg function if the app
4384 * has determined that it is running on Warp 4.
4385 *
4386 *@@changed V0.9.16 (2002-02-02) [umoeller]: fixed entry fields
4387 *@@changed V0.9.19 (2002-04-24) [umoeller]: removed ulDownUnits
4388 *@@changed V0.9.19 (2002-05-02) [umoeller]: fix for combobox
4389 */
4390
4391BOOL winhAssertWarp4Notebook(HWND hwndDlg,
4392 USHORT usIdThreshold) // in: ID threshold
4393{
4394 BOOL brc = FALSE;
4395
4396 if (doshIsWarp4())
4397 {
4398 LONG yLowest = 10000;
4399 HWND hwndItem;
4400 HENUM henum = 0;
4401 PSWP paswp,
4402 pswpThis;
4403 ULONG cWindows = 0,
4404 ul;
4405
4406 BOOL fIsVisible;
4407
4408 if (fIsVisible = WinIsWindowVisible(hwndDlg))
4409 // avoid flicker
4410 WinEnableWindowUpdate(hwndDlg, FALSE);
4411
4412 if (paswp = (PSWP)malloc(sizeof(SWP) * 100))
4413 {
4414 pswpThis = paswp;
4415
4416 // loop 1: set notebook buttons, find lowest y used
4417 henum = WinBeginEnumWindows(hwndDlg);
4418 while ((hwndItem = WinGetNextWindow(henum)))
4419 {
4420 USHORT usId = WinQueryWindowUShort(hwndItem, QWS_ID);
4421 // _Pmpf(("hwndItem: 0x%lX, ID: 0x%lX", hwndItem, usId));
4422 if (usId <= usIdThreshold)
4423 {
4424 // pushbutton to change:
4425 WinSetWindowBits(hwndItem,
4426 QWL_STYLE,
4427 BS_NOTEBOOKBUTTON, BS_NOTEBOOKBUTTON);
4428 brc = TRUE;
4429 }
4430 else
4431 {
4432 // no pushbutton to change:
4433 CHAR szClass[10];
4434
4435 WinQueryWindowPos(hwndItem, pswpThis);
4436
4437 // special handling for entry fields
4438 // V0.9.16 (2002-02-02) [umoeller]
4439 WinQueryClassName(hwndItem, sizeof(szClass), szClass);
4440 if (!strcmp(szClass, "#6"))
4441 {
4442 pswpThis->x += 3 * WinQuerySysValue(HWND_DESKTOP, SV_CXBORDER);
4443 pswpThis->y += 3 * WinQuerySysValue(HWND_DESKTOP, SV_CYBORDER);
4444 }
4445
4446 // check lowest y
4447 if ( (pswpThis->y < yLowest)
4448 // ignore combobox, this will distort everything
4449 // AGAIN ... sigh V0.9.19 (2002-05-02) [umoeller]
4450 && (strcmp(szClass, "#2"))
4451 )
4452 yLowest = pswpThis->y ;
4453
4454 ++pswpThis;
4455 if (++cWindows == 100)
4456 break;
4457 }
4458 } // end while ((hwndItem = WinGetNextWindow(henum)))
4459 WinEndEnumWindows(henum);
4460
4461 // now adjust window positions
4462 pswpThis = paswp;
4463 for (ul = 0;
4464 ul < cWindows;
4465 ++ul, ++pswpThis)
4466 {
4467 pswpThis->y -= (yLowest - 8);
4468 // 8 is magic to match the lower border of the
4469 // standard WPS notebook pages V0.9.19 (2002-04-24) [umoeller]
4470 pswpThis->fl = SWP_MOVE;
4471 }
4472
4473 WinSetMultWindowPos(WinQueryAnchorBlock(hwndDlg),
4474 paswp,
4475 cWindows);
4476
4477 free(paswp);
4478 }
4479
4480 if (fIsVisible)
4481 WinShowWindow(hwndDlg, TRUE);
4482 }
4483
4484 return brc;
4485}
4486
4487/*
4488 *@@ winhDrawFormattedText:
4489 * this func takes a rectangle and draws pszText into
4490 * it, breaking the words as neccessary. The line spacing
4491 * is determined from the font currently selected in hps.
4492 *
4493 * As opposed to WinDrawText, this can draw several lines
4494 * at once, and format the _complete_ text according to the
4495 * flCmd parameter, which is like with WinDrawText.
4496 *
4497 * After this function returns, *prcl is modified like this:
4498 *
4499 * -- yTop and yBottom contain the upper and lower boundaries
4500 * which were needed to draw the text. This depends on
4501 * whether DT_TOP etc. were specified.
4502 * To get the height of the rectangle used, calculate the
4503 * delta between yTop and yBottom.
4504 *
4505 * -- xLeft and xRight are modified to contain the outmost
4506 * left and right coordinates which were needed to draw
4507 * the text. This will be set to the longest line which
4508 * was encountered.
4509 *
4510 * You can specify DT_QUERYEXTENT with flDraw to only have
4511 * these text boundaries calculated without actually drawing.
4512 *
4513 * This returns the number of lines drawn.
4514 *
4515 * Note that this calls WinDrawText with DT_TEXTATTRS set,
4516 * that is, the current text primitive attributes will be
4517 * used (fonts and colors).
4518 *
4519 *@@changed V0.9.0 [umoeller]: prcl.xLeft and xRight are now updated too upon return
4520 */
4521
4522ULONG winhDrawFormattedText(HPS hps, // in: presentation space; its settings
4523 // are used, but not altered
4524 PRECTL prcl, // in/out: rectangle to use for drawing
4525 // (modified)
4526 const char *pcszText, // in: text to draw (zero-terminated)
4527 ULONG flCmd) // in: flags like in WinDrawText; I have
4528 // only tested DT_TOP and DT_LEFT though.
4529 // DT_WORDBREAK | DT_TEXTATTRS are always
4530 // set.
4531 // You can specify DT_QUERYEXTENT to only
4532 // have prcl calculated without drawing.
4533{
4534 PSZ p = (PSZ)pcszText;
4535 LONG lDrawn = 1,
4536 lTotalDrawn = 0,
4537 lLineCount = 0,
4538 lOrigYTop = prcl->yTop;
4539 ULONG ulTextLen = strlen(pcszText),
4540 ulCharHeight,
4541 flCmd2,
4542 xLeftmost = prcl->xRight,
4543 xRightmost = prcl->xLeft;
4544 RECTL rcl2;
4545
4546 flCmd2 = flCmd | DT_WORDBREAK | DT_TEXTATTRS;
4547
4548 ulCharHeight = gpihQueryLineSpacing(hps);
4549
4550 while ( (lDrawn)
4551 && (lTotalDrawn < ulTextLen)
4552 )
4553 {
4554 memcpy(&rcl2, prcl, sizeof(rcl2));
4555 lDrawn = WinDrawText(hps,
4556 ulTextLen-lTotalDrawn,
4557 p,
4558 &rcl2,
4559 0, 0, // colors
4560 flCmd2);
4561
4562 // update char counters
4563 p += lDrawn;
4564 lTotalDrawn += lDrawn;
4565
4566 // update x extents
4567 if (rcl2.xLeft < xLeftmost)
4568 xLeftmost = rcl2.xLeft;
4569 if (rcl2.xRight > xRightmost)
4570 xRightmost = rcl2.xRight;
4571
4572 // update y for next line
4573 prcl->yTop -= ulCharHeight;
4574
4575 // increase line count
4576 lLineCount++;
4577 }
4578 prcl->xLeft = xLeftmost;
4579 prcl->xRight = xRightmost;
4580 prcl->yBottom = prcl->yTop;
4581 prcl->yTop = lOrigYTop;
4582
4583 return lLineCount;
4584}
4585
4586/*
4587 *@@ winhQuerySwitchList:
4588 * returns the switch list in a newly
4589 * allocated buffer. This does the
4590 * regular double WinQuerySwitchList
4591 * call to first get the no. of items
4592 * and then get the items.
4593 *
4594 * The no. of items can be found in
4595 * the returned SWBLOCK.cwsentry.
4596 *
4597 * Returns NULL on errors. Use
4598 * free() to free the return value.
4599 *
4600 *@@added V0.9.7 (2000-12-06) [umoeller]
4601 */
4602
4603PSWBLOCK winhQuerySwitchList(HAB hab)
4604{
4605 ULONG cItems = WinQuerySwitchList(hab, NULL, 0);
4606 ULONG ulBufSize = (cItems * sizeof(SWENTRY)) + sizeof(HSWITCH);
4607 PSWBLOCK pSwBlock = (PSWBLOCK)malloc(ulBufSize);
4608 if (pSwBlock)
4609 {
4610 cItems = WinQuerySwitchList(hab, pSwBlock, ulBufSize);
4611 if (!cItems)
4612 {
4613 free(pSwBlock);
4614 pSwBlock = NULL;
4615 }
4616 }
4617
4618 return pSwBlock;
4619}
4620
4621typedef HSWITCH APIENTRY WINHSWITCHFROMHAPP(HAPP happ);
4622
4623/*
4624 *@@ winhHSWITCHfromHAPP:
4625 * resolves and calls the undocumented
4626 * WinHSWITCHfromHAPP API.
4627 *
4628 *@@added V0.9.19 (2002-04-17) [umoeller]
4629 */
4630
4631HSWITCH winhHSWITCHfromHAPP(HAPP happ)
4632{
4633 static WINHSWITCHFROMHAPP *pWinHSWITCHfromHAPP = NULL;
4634
4635 if (!pWinHSWITCHfromHAPP)
4636 // first call: import WinHSWITCHfromHAPP
4637 // WinHSWITCHfromHAPP PMMERGE.5199
4638 doshQueryProcAddr("PMMERGE",
4639 5199,
4640 (PFN*)&pWinHSWITCHfromHAPP);
4641
4642 if (pWinHSWITCHfromHAPP)
4643 return pWinHSWITCHfromHAPP(happ);
4644
4645 return NULLHANDLE;
4646}
4647
4648/*
4649 *@@ winhQueryTasklistWindow:
4650 * returns the window handle of the PM task list.
4651 *
4652 *@@added V0.9.7 (2000-12-07) [umoeller]
4653 */
4654
4655HWND winhQueryTasklistWindow(VOID)
4656{
4657 SWBLOCK swblock;
4658
4659 // the tasklist has entry #0 in the SWBLOCK
4660 WinQuerySwitchList(NULLHANDLE, &swblock, sizeof(SWBLOCK));
4661
4662 return swblock.aswentry[0].swctl.hwnd;
4663}
4664
4665/*
4666 *@@ winhKillTasklist:
4667 * this will destroy the Tasklist (window list) window.
4668 * Note: you will only be able to get it back after a
4669 * reboot, not a WPS restart. Only for use at shutdown and such.
4670 * This trick by Uri J. Stern at
4671 * http://zebra.asta.fh-weingarten.de/os2/Snippets/Howt8881.HTML
4672 */
4673
4674VOID winhKillTasklist(VOID)
4675{
4676 HWND hwndTasklist = winhQueryTasklistWindow();
4677 WinPostMsg(hwndTasklist,
4678 0x0454, // undocumented msg for killing tasklist
4679 NULL, NULL);
4680}
4681
4682// the following must be added for EMX (99-10-22) [umoeller]
4683#ifndef NERR_BufTooSmall
4684 #define NERR_BASE 2100
4685 #define NERR_BufTooSmall (NERR_BASE+23)
4686 // the API return buffer is too small
4687#endif
4688
4689/*
4690 *@@ winhQueryPendingSpoolJobs:
4691 * returns the number of pending print jobs in the spooler
4692 * or 0 if none. Useful for testing before shutdown.
4693 */
4694
4695ULONG winhQueryPendingSpoolJobs(VOID)
4696{
4697 // BOOL rcPending = FALSE;
4698 ULONG ulTotalJobCount = 0;
4699
4700 SPLERR splerr;
4701 USHORT jobCount;
4702 ULONG cbBuf;
4703 ULONG cTotal;
4704 ULONG cReturned;
4705 ULONG cbNeeded;
4706 ULONG ulLevel;
4707 ULONG i,j;
4708 PSZ pszComputerName;
4709 PBYTE pBuf = NULL;
4710 PPRQINFO3 prq;
4711 PPRJINFO2 prj2;
4712
4713 ulLevel = 4L;
4714 pszComputerName = (PSZ)NULL;
4715 splerr = SplEnumQueue(pszComputerName, ulLevel, pBuf, 0L, // cbBuf
4716 &cReturned, &cTotal,
4717 &cbNeeded, NULL);
4718 if ( (splerr == ERROR_MORE_DATA)
4719 || (splerr == NERR_BufTooSmall)
4720 )
4721 {
4722 if (!DosAllocMem((PPVOID)&pBuf,
4723 cbNeeded,
4724 PAG_READ | PAG_WRITE | PAG_COMMIT))
4725 {
4726 cbBuf = cbNeeded;
4727 splerr = SplEnumQueue(pszComputerName, ulLevel, pBuf, cbBuf,
4728 &cReturned, &cTotal,
4729 &cbNeeded, NULL);
4730 if (splerr == NO_ERROR)
4731 {
4732 // set pointer to point to the beginning of the buffer
4733 prq = (PPRQINFO3)pBuf;
4734
4735 // cReturned has the count of the number of PRQINFO3 structures
4736 for (i = 0;
4737 i < cReturned;
4738 i++)
4739 {
4740 // save the count of jobs; there are this many PRJINFO2
4741 // structures following the PRQINFO3 structure
4742 jobCount = prq->cJobs;
4743 // _Pmpf(( "Job count in this queue is %d",jobCount ));
4744
4745 // increment the pointer past the PRQINFO3 structure
4746 prq++;
4747
4748 // set a pointer to point to the first PRJINFO2 structure
4749 prj2=(PPRJINFO2)prq;
4750 for (j = 0;
4751 j < jobCount;
4752 j++)
4753 {
4754 // increment the pointer to point to the next structure
4755 prj2++;
4756 // increase the job count, which we'll return
4757 ulTotalJobCount++;
4758
4759 } // endfor jobCount
4760
4761 // after doing all the job structures, prj2 points to the next
4762 // queue structure; set the pointer for a PRQINFO3 structure
4763 prq = (PPRQINFO3)prj2;
4764 } //endfor cReturned
4765 } // endif NO_ERROR
4766 DosFreeMem(pBuf);
4767 }
4768 } // end if Q level given
4769
4770 return ulTotalJobCount;
4771}
4772
4773/*
4774 *@@ winhSetNumLock:
4775 * this sets the NumLock key on or off, depending
4776 * on fState.
4777 *
4778 * Based on code from WarpEnhancer, (C) Achim Hasenmller.
4779 *
4780 *@@added V0.9.1 (99-12-18) [umoeller]
4781 *@@changed V1.0.6 (2006-09-30) [pr]: Set Keyboard LEDs to match @@fixes 831
4782 */
4783
4784VOID winhSetNumLock(BOOL fState)
4785{
4786 // BOOL fRestoreKBD = FALSE; // Assume we're not going to close Kbd
4787 BYTE KeyStateTable[256];
4788 ULONG ulActionTaken; // Used by DosOpen
4789 HFILE hKbd;
4790
4791 // read keyboard state table
4792 if (WinSetKeyboardStateTable(HWND_DESKTOP, &KeyStateTable[0],
4793 FALSE))
4794 {
4795 // first set the PM state
4796 if (fState)
4797 KeyStateTable[VK_NUMLOCK] |= 0x01; // Turn numlock on
4798 else
4799 KeyStateTable[VK_NUMLOCK] &= 0xFE; // Turn numlock off
4800
4801 // set keyboard state table with new state values
4802 WinSetKeyboardStateTable(HWND_DESKTOP, &KeyStateTable[0], TRUE);
4803 }
4804
4805 // now set the OS/2 keyboard state
4806
4807 // try to open OS/2 keyboard driver
4808 if (!DosOpen("KBD$",
4809 &hKbd, &ulActionTaken,
4810 0, // cbFile
4811 FILE_NORMAL,
4812 OPEN_ACTION_FAIL_IF_NEW | OPEN_ACTION_OPEN_IF_EXISTS,
4813 OPEN_SHARE_DENYNONE | OPEN_ACCESS_READWRITE,
4814 NULL))
4815 {
4816 SHIFTSTATE ShiftState;
4817 USHORT usLEDState;
4818 ULONG DataLen = sizeof(SHIFTSTATE);
4819
4820 memset(&ShiftState, '\0', DataLen);
4821 DosDevIOCtl(hKbd, IOCTL_KEYBOARD, KBD_GETSHIFTSTATE,
4822 NULL, 0L, NULL,
4823 &ShiftState, DataLen, &DataLen);
4824
4825 if (fState)
4826 ShiftState.fsState |= 0x0020; // turn NumLock on
4827 else
4828 ShiftState.fsState &= 0xFFDF; // turn NumLock off
4829
4830 DosDevIOCtl(hKbd, IOCTL_KEYBOARD, KBD_SETSHIFTSTATE,
4831 &ShiftState, DataLen, &DataLen,
4832 NULL, 0L, NULL);
4833
4834 // XWP V1.0.6 (2006-09-30) [pr]: Set Keyboard LEDs to match @@fixes 831
4835 usLEDState = (ShiftState.fsState & (SCROLLLOCK_ON | NUMLOCK_ON | CAPSLOCK_ON)) >> 4;
4836 DataLen = sizeof(usLEDState);
4837 DosDevIOCtl(hKbd, IOCTL_KEYBOARD, KBD_ALTERKBDLED,
4838 &usLEDState, DataLen, &DataLen,
4839 NULL, 0L, NULL);
4840
4841 // now close OS/2 keyboard driver
4842 DosClose(hKbd);
4843 }
4844}
4845
4846/*
4847 *@@ winhSetClipboardText:
4848 * sets the clipboard data to the given text,
4849 * replacing the current clipboard contents.
4850 *
4851 *@@added V1.0.0 (2002-08-28) [umoeller]
4852 */
4853
4854BOOL winhSetClipboardText(HAB hab,
4855 PCSZ pcsz,
4856 ULONG cbSize) // in: size of buffer INCLUDING null byte
4857{
4858 BOOL fSuccess = FALSE;
4859
4860 if (WinOpenClipbrd(hab))
4861 {
4862 PSZ pszDest;
4863 if (!DosAllocSharedMem((PVOID*)&pszDest,
4864 NULL,
4865 cbSize,
4866 PAG_WRITE | PAG_COMMIT | OBJ_GIVEABLE))
4867 {
4868 memcpy(pszDest,
4869 pcsz,
4870 cbSize);
4871
4872 WinEmptyClipbrd(hab);
4873
4874 fSuccess = WinSetClipbrdData(hab, // anchor-block handle
4875 (ULONG)pszDest, // pointer to text data
4876 CF_TEXT, // data is in text format
4877 CFI_POINTER); // passing a pointer
4878
4879 // PMREF says (implicitly) it is not necessary to call
4880 // DosFreeMem. I hope that is correct.
4881 // V0.9.19 (2002-06-02) [umoeller]
4882 }
4883
4884 WinCloseClipbrd(hab);
4885 }
4886
4887 return fSuccess;
4888}
4889
4890/*
4891 *@@category: Helpers\PM helpers\Extended frame windows
4892 */
4893
4894/* ******************************************************************
4895 *
4896 * Extended frame
4897 *
4898 ********************************************************************/
4899
4900/*
4901 *@@ winhCalcExtFrameRect:
4902 * implementation for WM_CALCFRAMERECT in fnwpSubclExtFrame.
4903 * This is exported so it can be used independently
4904 * (XWorkplace status bars).
4905 *
4906 *@@added V1.0.0 (2002-08-28) [umoeller]
4907 */
4908
4909VOID winhCalcExtFrameRect(MPARAM mp1,
4910 MPARAM mp2,
4911 LONG lStatusBarHeight)
4912{
4913 PRECTL prclPassed = (PRECTL)mp1;
4914
4915 // mp2 == TRUE: Frame rectangle provided, calculate client
4916 // mp2 == FALSE: Client area rectangle provided, calculate frame
4917 if (mp2)
4918 {
4919 // TRUE: calculate the rectl of the client;
4920 // call default window procedure to subtract child frame
4921 // controls from the rectangle's height
4922 LONG lClientHeight;
4923
4924 // position the static text frame extension below the client
4925 lClientHeight = prclPassed->yTop - prclPassed->yBottom;
4926 if (lStatusBarHeight > lClientHeight)
4927 // extension is taller than client, so set client height to 0
4928 prclPassed->yTop = prclPassed->yBottom;
4929 else
4930 {
4931 // set the origin of the client and shrink it based upon the
4932 // static text control's height
4933 prclPassed->yBottom += lStatusBarHeight;
4934 prclPassed->yTop -= lStatusBarHeight;
4935 }
4936 }
4937 else
4938 {
4939 // FALSE: calculate the rectl of the frame;
4940 // call default window procedure to subtract child frame
4941 // controls from the rectangle's height;
4942 // set the origin of the frame and increase it based upon the
4943 // static text control's height
4944 prclPassed->yBottom -= lStatusBarHeight;
4945 prclPassed->yTop += lStatusBarHeight;
4946 }
4947}
4948
4949#define STATUS_BAR_HEIGHT 20
4950
4951/*
4952 *@@ fnwpSubclExtFrame:
4953 * subclassed frame window proc.
4954 *
4955 *@@added V0.9.16 (2001-09-29) [umoeller]
4956 */
4957
4958MRESULT EXPENTRY fnwpSubclExtFrame(HWND hwndFrame, ULONG msg, MPARAM mp1, MPARAM mp2)
4959{
4960 MRESULT mrc = 0;
4961
4962 PEXTFRAMEDATA pData = (PEXTFRAMEDATA)WinQueryWindowPtr(hwndFrame, QWL_USER);
4963
4964 switch (msg)
4965 {
4966 case WM_QUERYFRAMECTLCOUNT:
4967 {
4968 // query the standard frame controls count
4969 ULONG ulrc = (ULONG)pData->pfnwpOrig(hwndFrame, msg, mp1, mp2);
4970
4971 // if we have a status bar, increment the count
4972 ulrc++;
4973
4974 mrc = (MPARAM)ulrc;
4975 }
4976 break;
4977
4978 case WM_FORMATFRAME:
4979 {
4980 // query the number of standard frame controls
4981 ULONG ulCount = (ULONG)pData->pfnwpOrig(hwndFrame, msg, mp1, mp2);
4982
4983 // we have a status bar:
4984 // format the frame
4985 ULONG ul;
4986 PSWP swpArr = (PSWP)mp1;
4987
4988 for (ul = 0; ul < ulCount; ul++)
4989 {
4990 if (WinQueryWindowUShort(swpArr[ul].hwnd, QWS_ID) == 0x8008)
4991 // FID_CLIENT
4992 {
4993 POINTL ptlBorderSizes;
4994 WinSendMsg(hwndFrame,
4995 WM_QUERYBORDERSIZE,
4996 (MPARAM)&ptlBorderSizes,
4997 0);
4998
4999 // first initialize the _new_ SWP for the status bar.
5000 // Since the SWP array for the std frame controls is
5001 // zero-based, and the standard frame controls occupy
5002 // indices 0 thru ulCount-1 (where ulCount is the total
5003 // count), we use ulCount for our static text control.
5004 swpArr[ulCount].fl = SWP_MOVE | SWP_SIZE | SWP_NOADJUST | SWP_ZORDER;
5005 swpArr[ulCount].x = ptlBorderSizes.x;
5006 swpArr[ulCount].y = ptlBorderSizes.y;
5007 swpArr[ulCount].cx = swpArr[ul].cx; // same as cnr's width
5008 swpArr[ulCount].cy = STATUS_BAR_HEIGHT;
5009 swpArr[ulCount].hwndInsertBehind = HWND_BOTTOM; // HWND_TOP;
5010 swpArr[ulCount].hwnd = WinWindowFromID(hwndFrame, FID_STATUSBAR);
5011
5012 // adjust the origin and height of the container to
5013 // accomodate our static text control
5014 swpArr[ul].y += swpArr[ulCount].cy;
5015 swpArr[ul].cy -= swpArr[ulCount].cy;
5016 }
5017 }
5018
5019 // increment the number of frame controls
5020 // to include our status bar
5021 mrc = (MRESULT)(ulCount + 1);
5022 }
5023 break;
5024
5025 case WM_CALCFRAMERECT:
5026 mrc = pData->pfnwpOrig(hwndFrame, msg, mp1, mp2);
5027
5028 // we have a status bar: calculate its rectangle
5029 winhCalcExtFrameRect(mp1,
5030 mp2,
5031 STATUS_BAR_HEIGHT);
5032 break;
5033
5034 case WM_DESTROY:
5035 WinSubclassWindow(hwndFrame, pData->pfnwpOrig);
5036 free(pData);
5037 WinSetWindowPtr(hwndFrame, QWL_USER, NULL);
5038 break;
5039
5040 default:
5041 mrc = pData->pfnwpOrig(hwndFrame, msg, mp1, mp2);
5042 }
5043
5044 return mrc;
5045}
5046
5047/*
5048 *@@ winhCreateStatusBar:
5049 * creates a status bar for a frame window.
5050 *
5051 * Normally there's no need to call this manually,
5052 * this gets called by winhCreateExtStdWindow
5053 * automatically.
5054 *
5055 *@@added V0.9.16 (2001-09-29) [umoeller]
5056 */
5057
5058HWND winhCreateStatusBar(HWND hwndFrame,
5059 HWND hwndOwner,
5060 const char *pcszText, // in: initial status bar text
5061 const char *pcszFont, // in: font to use for status bar
5062 LONG lColor) // in: foreground color for status bar
5063{
5064 // create status bar
5065 HWND hwndReturn = NULLHANDLE;
5066 PPRESPARAMS ppp = NULL;
5067
5068 winhStorePresParam(&ppp,
5069 PP_FONTNAMESIZE,
5070 strlen(pcszFont) + 1,
5071 (PVOID)pcszFont);
5072
5073 lColor = WinQuerySysColor(HWND_DESKTOP,
5074 SYSCLR_DIALOGBACKGROUND,
5075 0);
5076 winhStorePresParam(&ppp,
5077 PP_BACKGROUNDCOLOR,
5078 sizeof(lColor),
5079 &lColor);
5080
5081 lColor = CLR_BLACK;
5082 winhStorePresParam(&ppp,
5083 PP_FOREGROUNDCOLOR,
5084 sizeof(lColor),
5085 &lColor);
5086
5087 hwndReturn = WinCreateWindow(hwndFrame,
5088 WC_STATIC,
5089 (PSZ)pcszText,
5090 SS_TEXT | DT_VCENTER | WS_VISIBLE,
5091 0, 0, 0, 0,
5092 hwndOwner,
5093 HWND_TOP,
5094 FID_STATUSBAR,
5095 NULL,
5096 ppp);
5097 free(ppp);
5098
5099 return hwndReturn;
5100}
5101
5102/*
5103 *@@ winhCreateExtStdWindow:
5104 * creates an extended frame window.
5105 *
5106 * pData must point to an EXTFRAMECDATA structure
5107 * which contains a copy of the parameters to be
5108 * passed to winhCreateStdWindow. In addition,
5109 * this contains the flExtFlags field, which allows
5110 * you to automatically create a status bar for
5111 * the window.
5112 *
5113 * Note that we subclass the frame here and require
5114 * QWL_USER for that. The frame's QWL_USER points
5115 * to an EXTFRAMEDATA structure whose pUser parameter
5116 * you may use for additional data, if you want to
5117 * do further subclassing.
5118 *
5119 *@@added V0.9.16 (2001-09-29) [umoeller]
5120 */
5121
5122HWND winhCreateExtStdWindow(PEXTFRAMECDATA pData, // in: extended frame data
5123 PHWND phwndClient) // out: created client wnd
5124{
5125 HWND hwndFrame;
5126
5127 if (hwndFrame = winhCreateStdWindow(HWND_DESKTOP,
5128 pData->pswpFrame,
5129 pData->flFrameCreateFlags,
5130 pData->ulFrameStyle,
5131 pData->pcszFrameTitle,
5132 pData->ulResourcesID,
5133 pData->pcszClassClient,
5134 pData->flStyleClient,
5135 pData->ulID,
5136 pData->pClientCtlData,
5137 phwndClient))
5138 {
5139 if (pData->flExtFlags & XFCF_STATUSBAR)
5140 {
5141 // create status bar as child of the frame
5142 HWND hwndStatusBar = winhCreateStatusBar(hwndFrame,
5143 hwndFrame,
5144 "",
5145 "9.WarpSans",
5146 CLR_BLACK);
5147
5148 // subclass frame for supporting status bar and msgs
5149 PEXTFRAMEDATA pFrameData;
5150 if (pFrameData = NEW(EXTFRAMEDATA))
5151 {
5152 ZERO(pFrameData),
5153 memcpy(&pFrameData->CData, pData, sizeof(pFrameData->CData));
5154 if (pFrameData->pfnwpOrig = WinSubclassWindow(hwndFrame,
5155 fnwpSubclExtFrame))
5156 {
5157 WinSetWindowPtr(hwndFrame, QWL_USER, pFrameData);
5158 }
5159 else
5160 free(pFrameData);
5161 }
5162 }
5163 }
5164
5165 return hwndFrame;
5166}
5167
5168/*
5169 *@@category: Helpers\PM helpers\Workplace Shell\WPS class list
5170 */
5171
5172/* ******************************************************************
5173 *
5174 * WPS Class List helpers
5175 *
5176 ********************************************************************/
5177
5178/*
5179 *@@ winhQueryWPSClassList:
5180 * this returns the WPS class list in a newly
5181 * allocated buffer. This is just a shortcut to
5182 * the usual double WinEnumObjectClasses call.
5183 *
5184 * The return value is actually of the POBJCLASS type,
5185 * so you better cast this manually. We declare this
5186 * this as PBYTE though because POBJCLASS requires
5187 * INCL_WINWORKPLACE.
5188 * See WinEnumObjectClasses() for details.
5189 *
5190 * Returns NULL on error. Use free()
5191 * to free the return value.
5192 *
5193 *@@added V0.9.0 [umoeller]
5194 */
5195
5196PBYTE winhQueryWPSClassList(VOID)
5197{
5198 ULONG ulSize;
5199 POBJCLASS pObjClass = 0;
5200
5201 // get WPS class list size
5202 if (WinEnumObjectClasses(NULL, &ulSize))
5203 {
5204 // allocate buffer
5205 pObjClass = (POBJCLASS)malloc(ulSize + 1);
5206 // and load the classes into it
5207 WinEnumObjectClasses(pObjClass, &ulSize);
5208 }
5209
5210 return (PBYTE)pObjClass;
5211}
5212
5213/*
5214 *@@ winhQueryWPSClass:
5215 * this returns the POBJCLASS item if pszClass is registered
5216 * with the WPS or NULL if the class could not be found.
5217 *
5218 * The return value is actually of the POBJCLASS type,
5219 * so you better cast this manually. We declare this
5220 * this as PBYTE though because POBJCLASS requires
5221 * INCL_WINWORKPLACE.
5222 *
5223 * This takes as input the return value of winhQueryWPSClassList,
5224 * which you must call first.
5225 *
5226 * <B>Usage:</B>
5227 + PBYTE pClassList = winhQueryWPSClassList(),
5228 + pWPFolder;
5229 + if (pClassList)
5230 + {
5231 + if (pWPFolder = winhQueryWPSClass(pClassList, "WPFolder"))
5232 + ...
5233 + free(pClassList);
5234 + }
5235 *
5236 *@@added V0.9.0 [umoeller]
5237 */
5238
5239PBYTE winhQueryWPSClass(PBYTE pObjClass, // in: buffer returned by
5240 // winhQueryWPSClassList
5241 const char *pszClass) // in: class name to query
5242{
5243 PBYTE pbReturn = 0;
5244
5245 POBJCLASS pocThis = (POBJCLASS)pObjClass;
5246 // now go thru the WPS class list
5247 while (pocThis)
5248 {
5249 if (strcmp(pocThis->pszClassName, pszClass) == 0)
5250 {
5251 pbReturn = (PBYTE)pocThis;
5252 break;
5253 }
5254 // next class
5255 pocThis = pocThis->pNext;
5256 } // end while (pocThis)
5257
5258 return pbReturn;
5259}
5260
5261/*
5262 *@@ winhRegisterClass:
5263 * this works just like WinRegisterObjectClass,
5264 * except that it returns a more meaningful
5265 * error code than just FALSE in case registering
5266 * fails.
5267 *
5268 * This returns NO_ERROR if the class was successfully
5269 * registered (WinRegisterObjectClass returned TRUE).
5270 *
5271 * Otherwise, we do a DosLoadModule if maybe the DLL
5272 * couldn't be loaded in the first place. If DosLoadModule
5273 * did not return NO_ERROR, this function returns that
5274 * return code, which can be:
5275 *
5276 * -- 2 ERROR_FILE_NOT_FOUND: pcszModule does not exist
5277 * -- 2 ERROR_FILE_NOT_FOUND
5278 * -- 3 ERROR_PATH_NOT_FOUND
5279 * -- 4 ERROR_TOO_MANY_OPEN_FILES
5280 * -- 5 ERROR_ACCESS_DENIED
5281 * -- 8 ERROR_NOT_ENOUGH_MEMORY
5282 * -- 11 ERROR_BAD_FORMAT
5283 * -- 26 ERROR_NOT_DOS_DISK (unknown media type)
5284 * -- 32 ERROR_SHARING_VIOLATION
5285 * -- 33 ERROR_LOCK_VIOLATION
5286 * -- 36 ERROR_SHARING_BUFFER_EXCEEDED
5287 * -- 95 ERROR_INTERRUPT (interrupted system call)
5288 * -- 108 ERROR_DRIVE_LOCKED (by another process)
5289 * -- 123 ERROR_INVALID_NAME (illegal character or FS name not valid)
5290 * -- 127 ERROR_PROC_NOT_FOUND (DosQueryProcAddr error)
5291 * -- 180 ERROR_INVALID_SEGMENT_NUMBER
5292 * -- 182 ERROR_INVALID_ORDINAL
5293 * -- 190 ERROR_INVALID_MODULETYPE (probably an application)
5294 * -- 191 ERROR_INVALID_EXE_SIGNATURE (probably not LX DLL)
5295 * -- 192 ERROR_EXE_MARKED_INVALID (by linker)
5296 * -- 194 ERROR_ITERATED_DATA_EXCEEDS_64K (in a DLL segment)
5297 * -- 195 ERROR_INVALID_MINALLOCSIZE
5298 * -- 196 ERROR_DYNLINK_FROM_INVALID_RING
5299 * -- 198 ERROR_INVALID_SEGDPL
5300 * -- 199 ERROR_AUTODATASEG_EXCEEDS_64K
5301 * -- 201 ERROR_RELOCSRC_CHAIN_EXCEEDS_SEGLIMIT
5302 * -- 206 ERROR_FILENAME_EXCED_RANGE (not matching 8+3 spec)
5303 * -- 295 ERROR_INIT_ROUTINE_FAILED (DLL init routine failed)
5304 *
5305 * In all these cases, pszBuf may contain a meaningful
5306 * error message from DosLoadModule, especially if an import
5307 * could not be resolved.
5308 *
5309 * Still worse, if DosLoadModule returned NO_ERROR, we
5310 * probably have some SOM internal error. A probable
5311 * reason is that the parent class of pcszClassName
5312 * is not installed, but that's WPS/SOM internal
5313 * and cannot be queried from outside the WPS context.
5314 *
5315 * In that case, ERROR_OPEN_FAILED (110) is returned.
5316 * That one sounded good to me. ;-)
5317 */
5318
5319APIRET winhRegisterClass(const char* pcszClassName, // in: e.g. "XFolder"
5320 const char* pcszModule, // in: e.g. "C:\XFOLDER\XFLDR.DLL"
5321 PSZ pszBuf, // out: error message from DosLoadModule
5322 ULONG cbBuf) // in: sizeof(*pszBuf), passed to DosLoadModule
5323{
5324 APIRET arc = NO_ERROR;
5325
5326 if (!WinRegisterObjectClass((PSZ)pcszClassName, (PSZ)pcszModule))
5327 {
5328 // failed: do more error checking then, try DosLoadModule
5329 HMODULE hmod = NULLHANDLE;
5330 arc = DosLoadModule(pszBuf, cbBuf,
5331 (PSZ)pcszModule,
5332 &hmod);
5333 if (arc == NO_ERROR)
5334 {
5335 // DosLoadModule succeeded:
5336 // some SOM error then
5337 DosFreeModule(hmod);
5338 arc = ERROR_OPEN_FAILED;
5339 }
5340 }
5341 // else: ulrc still 0 (== no error)
5342
5343 return arc;
5344}
5345
5346/*
5347 *@@ winhIsClassRegistered:
5348 * quick one-shot function which checks if
5349 * a class is currently registered. Calls
5350 * winhQueryWPSClassList and winhQueryWPSClass
5351 * in turn.
5352 *
5353 *@@added V0.9.2 (2000-02-26) [umoeller]
5354 */
5355
5356BOOL winhIsClassRegistered(const char *pcszClass)
5357{
5358 BOOL brc = FALSE;
5359 PBYTE pClassList = winhQueryWPSClassList();
5360 if (pClassList)
5361 {
5362 if (winhQueryWPSClass(pClassList, pcszClass))
5363 brc = TRUE;
5364 free(pClassList);
5365 }
5366
5367 return brc;
5368}
5369
5370/*
5371 *@@category: Helpers\PM helpers\Workplace Shell
5372 */
5373
5374/*
5375 *@@ winhResetWPS:
5376 * restarts the WPS using PrfReset. Returns
5377 * one of the following:
5378 *
5379 * -- 0: no error.
5380 * -- 1: PrfReset failed.
5381 * -- 2 or 4: PrfQueryProfile failed.
5382 * -- 3: malloc() failed.
5383 *
5384 *@@added V0.9.4 (2000-07-01) [umoeller]
5385 *@@changed V1.0.5 (2005-02-17) [pr]: replaced this with something less brutal
5386 */
5387
5388ULONG winhResetWPS(HAB hab)
5389{
5390 ULONG ulrc = 0;
5391
5392#if 1
5393 WinRestartWorkplace();
5394#else
5395 // find out current profile names
5396 PRFPROFILE Profiles;
5397 Profiles.cchUserName = Profiles.cchSysName = 0;
5398 // first query their file name lengths
5399 if (PrfQueryProfile(hab, &Profiles))
5400 {
5401 // allocate memory for filenames
5402 Profiles.pszUserName = (PSZ)malloc(Profiles.cchUserName);
5403 Profiles.pszSysName = (PSZ)malloc(Profiles.cchSysName);
5404
5405 if (Profiles.pszSysName)
5406 {
5407 // get filenames
5408 if (PrfQueryProfile(hab, &Profiles))
5409 {
5410
5411 // "change" INIs to these filenames:
5412 // THIS WILL RESET THE WPS
5413 if (PrfReset(hab, &Profiles) == FALSE)
5414 ulrc = 1;
5415 free(Profiles.pszSysName);
5416 free(Profiles.pszUserName);
5417 }
5418 else
5419 ulrc = 2;
5420 }
5421 else
5422 ulrc = 3;
5423 }
5424 else
5425 ulrc = 4;
5426#endif
5427
5428 return ulrc;
5429}
Note: See TracBrowser for help on using the repository browser.