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

Last change on this file since 384 was 384, checked in by pr, 15 years ago

Fix variable init. bugs.

  • Property svn:eol-style set to CRLF
  • Property svn:keywords set to Author Date Id Revision
File size: 189.7 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-2010 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 * -- "workarea": the entire data to be displayed, of which the
1866 * "window" can only display a subrectangle, if the workarea
1867 * is larger than the window.
1868 *
1869 * The width or height of this must be passed in ulWorkareaPels.
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 * This value is exclusive in the sense that the maximum
1875 * window offset (below) can be the workarea minus one.
1876 *
1877 * -- "window offset": the zero-based offset of the current
1878 * window within the workarea, whose maximum value is
1879 * the workarea minus one.
1880 *
1881 * [pr]: I disagree with the above "workarea minus one" stuff.
1882 * It is perfectly possible to have the workarea and the
1883 * window area the same size and to display all the content.
1884 * This also means you do NOT get a disabled scroll bar
1885 * any more when they are the same size.
1886 *
1887 * For horizontal scroll bars, this is the X coordinate,
1888 * counting from the left of the window (0 means leftmost).
1889 *
1890 * For vertical scroll bars, this is counted from the _top_
1891 * of the workarea (0 means topmost, as opposed to OS/2
1892 * window coordinates!). This is because for vertical scroll
1893 * bars controls, higher values move the thumb _down_. Yes
1894 * indeed, this conflicts with PM's coordinate system.
1895 *
1896 * The window offset is therefore always positive.
1897 *
1898 * The scroll bar gets disabled if the entire workarea is visible,
1899 * that is, if ulWorkareaPels <= ulWinPels. In that case
1900 * FALSE is returned. If (fAutoHide == TRUE), the scroll
1901 * bar is not only disabled, but also hidden from the display.
1902 * In that case, you will need to reformat your output because
1903 * your workarea becomes larger without the scroll bar.
1904 *
1905 * This function will set the range of the scroll bar to 0 up
1906 * to a value depending on the workarea size. For vertical scroll
1907 * bars, 0 means topmost (which is kinda sick with the OS/2
1908 * coordinate system), for horizontal scroll bars, 0 means leftmost.
1909 *
1910 * The maximum value of the scroll bar will be
1911 *
1912 + (ulWorkareaPels - ulWinPels) / usScrollUnitPels
1913 *
1914 * The thumb size of the scroll bar will also be adjusted
1915 * based on the workarea and window size, as it should be.
1916 *
1917 *@@added V0.9.1 (2000-02-14) [umoeller]
1918 *@@changed V0.9.3 (2000-04-30) [umoeller]: fixed pels/unit confusion
1919 *@@changed V0.9.3 (2000-05-08) [umoeller]: now handling scroll units automatically
1920 *@@changed V1.0.1 (2003-01-25) [umoeller]: fixed max value which caused right/bottommost scroll button to never be disabled
1921 *@@changed V1.0.1 (2003-01-25) [umoeller]: fixed bad thumb position for large offsets
1922 *@@changed WarpIN V1.0.18 (2008-11-16) [pr]: fix rounding errors @@fixes 1086
1923 *@@changed WarpIN V1.0.18 (2008-11-16) [pr]: disable scroll bars when workarea = win area @@fixes 1086
1924 */
1925
1926BOOL winhUpdateScrollBar(HWND hwndScrollBar, // in: scroll bar (vertical or horizontal)
1927 ULONG ulWinPels, // in: vertical or horizontal dimension of
1928 // visible window part (in pixels),
1929 // excluding the scroll bar!
1930 ULONG ulWorkareaPels, // in: dimension of total data part, of
1931 // which ulWinPels is a sub-dimension
1932 // (in pixels);
1933 // if <= ulWinPels, the scrollbar will be
1934 // disabled
1935 ULONG ulCurPelsOfs, // in: current offset of visible part
1936 // (in pixels)
1937 BOOL fAutoHide) // in: hide scroll bar if disabled
1938{
1939 BOOL brc = FALSE;
1940
1941 if (ulWorkareaPels > ulWinPels) // WarpIN V1.0.18
1942 {
1943 // for large workareas, adjust scroll bar units
1944 USHORT usDivisor = 1, usRounder;
1945 USHORT lMaxAllowedUnitOfs;
1946
1947 if (ulWorkareaPels > 10000)
1948 usDivisor = 100;
1949
1950 usRounder = usDivisor - 1; // WarpIN V1.0.18
1951 // scrollbar needed:
1952
1953 // workarea is larger than window:
1954 WinEnableWindow(hwndScrollBar, TRUE);
1955 if (fAutoHide)
1956 WinShowWindow(hwndScrollBar, TRUE);
1957
1958 // calculate limit
1959 lMaxAllowedUnitOfs = (ulWorkareaPels - ulWinPels + usRounder)
1960 / usDivisor;
1961
1962 // set thumb position and limit
1963 WinSendMsg(hwndScrollBar,
1964 SBM_SETSCROLLBAR,
1965 (MPARAM)((ulCurPelsOfs + usRounder) / usDivisor), // position: 0 means top
1966 MPFROM2SHORT(0, // minimum
1967 lMaxAllowedUnitOfs)); // maximum
1968
1969 // set thumb size based on ulWinPels and
1970 // ulWorkareaPels
1971 WinSendMsg(hwndScrollBar,
1972 SBM_SETTHUMBSIZE,
1973 MPFROM2SHORT( (ulWinPels + usRounder) / usDivisor, // visible
1974 (ulWorkareaPels + usRounder) / usDivisor), // total
1975 0);
1976 brc = TRUE;
1977 }
1978 else
1979 {
1980 // entire workarea is visible:
1981 WinEnableWindow(hwndScrollBar, FALSE);
1982 if (fAutoHide)
1983 WinShowWindow(hwndScrollBar, FALSE);
1984 }
1985
1986 // _Pmpf(("End of winhUpdateScrollBar"));
1987
1988 return brc;
1989}
1990
1991/*
1992 *@@ winhHandleScrollMsg:
1993 * this helper handles a WM_VSCROLL or WM_HSCROLL
1994 * message posted to a client window when the user
1995 * has worked on a client scroll bar. Calling this
1996 * function is ALL you need to do to handle those
1997 * two messages.
1998 *
1999 * This is most useful in conjunction with winhUpdateScrollBar.
2000 * See that function for the terminology also.
2001 *
2002 * This function calculates the new scrollbar position
2003 * (from the mp2 value, which can be line up/down,
2004 * page up/down, or slider track) and calls WinScrollWindow
2005 * accordingly. The window part which became invalid
2006 * because of the scrolling is automatically invalidated
2007 * (using WinInvalidateRect), so expect a WM_PAINT after
2008 * calling this function.
2009 *
2010 * This function assumes that the scrollbar operates
2011 * on values starting from zero. The maximum value
2012 * of the scroll bar is:
2013 *
2014 + ulViewportPels - (prcl2Scroll->yTop - prcl2Scroll->yBottom)
2015 *
2016 * This function also automatically changes the scroll bar
2017 * units, should you have a viewport size which doesn't fit
2018 * into the SHORT's that the scroll bar uses internally. As
2019 * a result, this function handles a the complete range of
2020 * a ULONG for the viewport.
2021 *
2022 * Replace "bottom" and "top" with "right" and "left" for
2023 * horizontal scrollbars in the above formula.
2024 *
2025 *@@added V0.9.1 (2000-02-13) [umoeller]
2026 *@@changed V0.9.3 (2000-04-30) [umoeller]: changed prototype, fixed pels/unit confusion
2027 *@@changed V0.9.3 (2000-05-08) [umoeller]: now handling scroll units automatically
2028 *@@changed V0.9.7 (2001-01-17) [umoeller]: changed PLONG to PULONG
2029 *@@changed WarpIN V1.0.18 (2008-11-16) [pr]: fix rounding error @@fixes 1086
2030 */
2031
2032BOOL winhHandleScrollMsg(HWND hwnd2Scroll, // in: client window to scroll
2033 HWND hwndScrollBar, // in: vertical or horizontal scroll bar window
2034 PULONG pulCurPelsOfs, // in/out: current viewport offset;
2035 // this is updated with the proper scroll units
2036 PRECTL prcl2Scroll, // in: hwnd2Scroll rectangle to scroll
2037 // (in window coordinates);
2038 // this is passed to WinScrollWindow,
2039 // which considers this inclusive!
2040 LONG ulViewportPels, // in: total viewport dimension,
2041 // into which *pulCurPelsOfs is an offset
2042 USHORT usLineStepPels, // in: pixels to scroll line-wise
2043 // (scroll bar buttons pressed)
2044 ULONG msg, // in: either WM_VSCROLL or WM_HSCROLL
2045 MPARAM mp2) // in: complete mp2 of WM_VSCROLL/WM_HSCROLL;
2046 // this has two SHORT's (usPos and usCmd),
2047 // see PMREF for details
2048{
2049 ULONG ulOldPelsOfs = *pulCurPelsOfs;
2050 USHORT usPosUnits = SHORT1FROMMP(mp2), // in scroll units
2051 usCmd = SHORT2FROMMP(mp2);
2052 LONG lMaxAllowedUnitOfs;
2053 ULONG ulWinPels;
2054
2055 // for large viewports, adjust scroll bar units
2056 USHORT usScrollUnitPels = 1;
2057 if (ulViewportPels > 10000)
2058 usScrollUnitPels = 100;
2059
2060 // calculate window size (vertical or horizontal)
2061 if (msg == WM_VSCROLL)
2062 ulWinPels = (prcl2Scroll->yTop - prcl2Scroll->yBottom);
2063 else
2064 ulWinPels = (prcl2Scroll->xRight - prcl2Scroll->xLeft);
2065
2066 lMaxAllowedUnitOfs = ((LONG)ulViewportPels - ulWinPels) / usScrollUnitPels;
2067
2068 // _Pmpf(("Entering winhHandleScrollMsg"));
2069
2070 switch (usCmd)
2071 {
2072 case SB_LINEUP:
2073 if (*pulCurPelsOfs > usLineStepPels)
2074 *pulCurPelsOfs -= usLineStepPels; // * usScrollUnitPels);
2075 else
2076 *pulCurPelsOfs = 0;
2077 break;
2078
2079 case SB_LINEDOWN:
2080 *pulCurPelsOfs += usLineStepPels; // * usScrollUnitPels);
2081 break;
2082
2083 case SB_PAGEUP:
2084 if (*pulCurPelsOfs > ulWinPels)
2085 *pulCurPelsOfs -= ulWinPels; // convert to units
2086 else
2087 *pulCurPelsOfs = 0;
2088 break;
2089
2090 case SB_PAGEDOWN:
2091 *pulCurPelsOfs += ulWinPels; // convert to units
2092 break;
2093
2094 case SB_SLIDERTRACK:
2095 *pulCurPelsOfs = (usPosUnits * usScrollUnitPels);
2096 // _Pmpf((" SB_SLIDERTRACK: usUnits = %d", usPosUnits));
2097 break;
2098
2099 case SB_SLIDERPOSITION:
2100 *pulCurPelsOfs = (usPosUnits * usScrollUnitPels);
2101 break;
2102 }
2103
2104 // are we close to the lower limit?
2105 /* if (*plCurUnitOfs < usLineStepUnits) // usScrollUnit)
2106 *plCurUnitOfs = 0;
2107 // are we close to the upper limit?
2108 else if (*plCurUnitOfs + usLineStepUnits > lMaxUnitOfs)
2109 {
2110 _Pmpf((" !!! limiting: %d to %d", *plCurUnitOfs, lMaxUnitOfs));
2111 *plCurUnitOfs = lMaxUnitOfs;
2112 } */
2113
2114 /* if (*plCurPelsOfs < 0)
2115 *plCurPelsOfs = 0; */ // checked above
2116 if (*pulCurPelsOfs > (lMaxAllowedUnitOfs * usScrollUnitPels))
2117 {
2118 *pulCurPelsOfs = (lMaxAllowedUnitOfs * usScrollUnitPels);
2119 }
2120 if ( (*pulCurPelsOfs != ulOldPelsOfs)
2121 || (*pulCurPelsOfs == 0)
2122 || (*pulCurPelsOfs == (lMaxAllowedUnitOfs * usScrollUnitPels))
2123 )
2124 {
2125 RECTL rcl2Scroll,
2126 rcl2Update;
2127
2128 // changed:
2129 WinSendMsg(hwndScrollBar,
2130 SBM_SETPOS,
2131 (MPARAM)((*pulCurPelsOfs + (usScrollUnitPels / 2)) / usScrollUnitPels), // WarpIN V1.0.18
2132 0);
2133 // scroll window rectangle:
2134 rcl2Scroll.xLeft = prcl2Scroll->xLeft;
2135 rcl2Scroll.xRight = prcl2Scroll->xRight;
2136 rcl2Scroll.yBottom = prcl2Scroll->yBottom;
2137 rcl2Scroll.yTop = prcl2Scroll->yTop;
2138
2139 if (msg == WM_VSCROLL)
2140 WinScrollWindow(hwnd2Scroll,
2141 0,
2142 (*pulCurPelsOfs - ulOldPelsOfs) // scroll units changed
2143 , // * usScrollUnitPels, // convert to pels
2144 &rcl2Scroll, // rcl to scroll
2145 prcl2Scroll, // clipping rect
2146 NULLHANDLE, // no region
2147 &rcl2Update,
2148 0);
2149 else
2150 WinScrollWindow(hwnd2Scroll,
2151 -(LONG)(*pulCurPelsOfs - ulOldPelsOfs) // scroll units changed
2152 , // * usScrollUnitPels,
2153 0,
2154 &rcl2Scroll, // rcl to scroll
2155 prcl2Scroll, // clipping rect
2156 NULLHANDLE, // no region
2157 &rcl2Update,
2158 0);
2159
2160 // WinScrollWindow has stored the invalid window
2161 // rectangle which needs to be repainted in rcl2Update:
2162 WinInvalidateRect(hwnd2Scroll, &rcl2Update, FALSE);
2163 }
2164
2165 // _Pmpf(("End of winhHandleScrollMsg"));
2166
2167 return TRUE;
2168}
2169
2170/*
2171 *@@ winhProcessScrollChars:
2172 * helper for processing WM_CHAR messages for
2173 * client windows with scroll bars.
2174 *
2175 * If your window has scroll bars, you normally
2176 * need to process a number of keystrokes to be
2177 * able to scroll the window contents. This is
2178 * tiresome to code, so here is a helper.
2179 *
2180 * When receiving WM_CHAR, call this function.
2181 * If this returns TRUE, the keystroke has been
2182 * a scroll keystroke, and the window has been
2183 * updated (by sending WM_VSCROLL or WM_HSCROLL
2184 * to hwndClient). Otherwise, you should process
2185 * the keystroke as usual because it's not a
2186 * scroll keystroke.
2187 *
2188 * The following keystrokes are processed here:
2189 *
2190 * -- "cursor up, down, right, left": scroll one
2191 * line in the proper direction.
2192 * -- "page up, down": scroll one page up or down.
2193 * -- "Home": scroll leftmost.
2194 * -- "Ctrl+ Home": scroll topmost.
2195 * -- "End": scroll rightmost.
2196 * -- "Ctrl+ End": scroll bottommost.
2197 * -- "Ctrl + page up, down": scroll one screen left or right.
2198 *
2199 * This is CUA behavior.
2200 *
2201 * Returns TRUE if the message has been
2202 * processed.
2203 *
2204 *@@added V0.9.3 (2000-04-29) [umoeller]
2205 *@@changed V0.9.9 (2001-02-01) [lafaix]: Ctrl+PgUp/Dn now do one screen left/right
2206 */
2207
2208BOOL winhProcessScrollChars(HWND hwndClient, // in: client window
2209 HWND hwndVScroll, // in: vertical scroll bar
2210 HWND hwndHScroll, // in: horizontal scroll bar
2211 MPARAM mp1, // in: WM_CHAR mp1
2212 MPARAM mp2, // in: WM_CHAR mp2
2213 ULONG ulVertMax, // in: maximum viewport cy
2214 ULONG ulHorzMax) // in: maximum viewport cx
2215{
2216 BOOL fProcessed = FALSE;
2217 USHORT usFlags = SHORT1FROMMP(mp1);
2218 // USHORT usch = SHORT1FROMMP(mp2);
2219 USHORT usvk = SHORT2FROMMP(mp2);
2220
2221 // _Pmpf(("Entering winhProcessScrollChars"));
2222
2223 if (usFlags & KC_VIRTUALKEY)
2224 {
2225 ULONG ulMsg = 0;
2226 SHORT sPos = 0;
2227 SHORT usCmd = 0;
2228 fProcessed = TRUE;
2229
2230 switch (usvk)
2231 {
2232 case VK_UP:
2233 ulMsg = WM_VSCROLL;
2234 usCmd = SB_LINEUP;
2235 break;
2236
2237 case VK_DOWN:
2238 ulMsg = WM_VSCROLL;
2239 usCmd = SB_LINEDOWN;
2240 break;
2241
2242 case VK_RIGHT:
2243 ulMsg = WM_HSCROLL;
2244 usCmd = SB_LINERIGHT;
2245 break;
2246
2247 case VK_LEFT:
2248 ulMsg = WM_HSCROLL;
2249 usCmd = SB_LINELEFT;
2250 break;
2251
2252 case VK_PAGEUP:
2253 if (usFlags & KC_CTRL)
2254 ulMsg = WM_HSCROLL;
2255 else
2256 ulMsg = WM_VSCROLL;
2257 usCmd = SB_PAGEUP;
2258 break;
2259
2260 case VK_PAGEDOWN:
2261 if (usFlags & KC_CTRL)
2262 ulMsg = WM_HSCROLL;
2263 else
2264 ulMsg = WM_VSCROLL;
2265 usCmd = SB_PAGEDOWN;
2266 break;
2267
2268 case VK_HOME:
2269 if (usFlags & KC_CTRL)
2270 // vertical:
2271 ulMsg = WM_VSCROLL;
2272 else
2273 ulMsg = WM_HSCROLL;
2274
2275 sPos = 0;
2276 usCmd = SB_SLIDERPOSITION;
2277 break;
2278
2279 case VK_END:
2280 if (usFlags & KC_CTRL)
2281 {
2282 // vertical:
2283 ulMsg = WM_VSCROLL;
2284 sPos = ulVertMax;
2285 }
2286 else
2287 {
2288 ulMsg = WM_HSCROLL;
2289 sPos = ulHorzMax;
2290 }
2291
2292 usCmd = SB_SLIDERPOSITION;
2293 break;
2294
2295 default:
2296 // other:
2297 fProcessed = FALSE;
2298 }
2299
2300 if ( ((usFlags & KC_KEYUP) == 0)
2301 && (ulMsg)
2302 )
2303 {
2304 HWND hwndScrollBar = ((ulMsg == WM_VSCROLL)
2305 ? hwndVScroll
2306 : hwndHScroll);
2307 if (WinIsWindowEnabled(hwndScrollBar))
2308 {
2309 USHORT usID = WinQueryWindowUShort(hwndScrollBar,
2310 QWS_ID);
2311 WinSendMsg(hwndClient,
2312 ulMsg,
2313 MPFROMSHORT(usID),
2314 MPFROM2SHORT(sPos,
2315 usCmd));
2316 }
2317 }
2318 }
2319
2320 // _Pmpf(("End of winhProcessScrollChars"));
2321
2322 return fProcessed;
2323}
2324
2325/*
2326 *@@category: Helpers\PM helpers\Window positioning
2327 */
2328
2329/* ******************************************************************
2330 *
2331 * Window positioning helpers
2332 *
2333 ********************************************************************/
2334
2335/*
2336 *@@ winhSaveWindowPos:
2337 * saves the position of a certain window. As opposed
2338 * to the barely documented WinStoreWindowPos API, this
2339 * one only saves one regular SWP structure for the given
2340 * window, as returned by WinQueryWindowPos for hwnd.
2341 *
2342 * If the window is currently maximized or minimized,
2343 * we won't store the current window size and position
2344 * (which wouldn't make much sense), but retrieve the
2345 * "restored" window position from the window words
2346 * instead.
2347 *
2348 * The window should still be visible on the screen
2349 * when calling this function. Do not call it in WM_DESTROY,
2350 * because then the SWP data is no longer valid.
2351 *
2352 * This returns TRUE if saving was successful.
2353 *
2354 *@@changed V0.9.1 (99-12-19) [umoeller]: added minimize/maximize support
2355 */
2356
2357BOOL winhSaveWindowPos(HWND hwnd, // in: window to save
2358 HINI hIni, // in: INI file (or HINI_USER/SYSTEM)
2359 const char *pcszApp, // in: INI application name
2360 const char *pcszKey) // in: INI key name
2361{
2362 BOOL brc = FALSE;
2363 SWP swp;
2364 if (WinQueryWindowPos(hwnd, &swp))
2365 {
2366 if (swp.fl & (SWP_MAXIMIZE | SWP_MINIMIZE))
2367 {
2368 // window currently maximized or minimized:
2369 // retrieve "restore" position from window words
2370 swp.x = WinQueryWindowUShort(hwnd, QWS_XRESTORE);
2371 swp.y = WinQueryWindowUShort(hwnd, QWS_YRESTORE);
2372 swp.cx = WinQueryWindowUShort(hwnd, QWS_CXRESTORE);
2373 swp.cy = WinQueryWindowUShort(hwnd, QWS_CYRESTORE);
2374 }
2375
2376 brc = PrfWriteProfileData(hIni, (PSZ)pcszApp, (PSZ)pcszKey, &swp, sizeof(swp));
2377 }
2378 return brc;
2379}
2380
2381/*
2382 *@@ winhRestoreWindowPos:
2383 * this will retrieve a window position which was
2384 * previously stored using winhSaveWindowPos.
2385 *
2386 * The window should not be visible to avoid flickering.
2387 * "fl" must contain the SWP_flags as in WinSetWindowPos.
2388 *
2389 * Note that only the following may be used:
2390 * -- SWP_MOVE reposition the window
2391 * -- SWP_SIZE also resize the window to
2392 * the stored position; this might
2393 * lead to problems with different
2394 * video resolutions, so be careful.
2395 * -- SWP_SHOW make window visible too
2396 * -- SWP_NOREDRAW changes are not redrawn
2397 * -- SWP_NOADJUST do not send a WM_ADJUSTWINDOWPOS message
2398 * before moving or sizing
2399 * -- SWP_ACTIVATE activate window (make topmost)
2400 * -- SWP_DEACTIVATE deactivate window (make bottommost)
2401 *
2402 * Do not specify any other SWP_* flags.
2403 *
2404 * If SWP_SIZE is not set, the window will be moved only.
2405 *
2406 * This returns TRUE if INI data was found.
2407 *
2408 * This function automatically checks for whether the
2409 * window would be positioned outside the visible screen
2410 * area and will adjust coordinates accordingly. This can
2411 * happen when changing video resolutions.
2412 *
2413 *@@changed V0.9.7 (2000-12-20) [umoeller]: fixed invalid params if INI key not found
2414 */
2415
2416BOOL winhRestoreWindowPos(HWND hwnd, // in: window to restore
2417 HINI hIni, // in: INI file (or HINI_USER/SYSTEM)
2418 const char *pcszApp, // in: INI application name
2419 const char *pcszKey, // in: INI key name
2420 ULONG fl) // in: "fl" parameter for WinSetWindowPos
2421{
2422 BOOL brc = FALSE;
2423 SWP swp;
2424 ULONG cbswp = sizeof(swp);
2425 ULONG fl2 = (fl & ~SWP_ZORDER);
2426
2427 if (PrfQueryProfileData(hIni, (PSZ)pcszApp, (PSZ)pcszKey, &swp, &cbswp))
2428 {
2429 ULONG ulScreenCX = WinQuerySysValue(HWND_DESKTOP, SV_CXSCREEN);
2430 ULONG ulScreenCY = WinQuerySysValue(HWND_DESKTOP, SV_CYSCREEN);
2431
2432 brc = TRUE;
2433
2434 if ((fl & SWP_SIZE) == 0)
2435 {
2436 // if no resize, we need to get the current position
2437 SWP swpNow;
2438 brc = WinQueryWindowPos(hwnd, &swpNow);
2439 swp.cx = swpNow.cx;
2440 swp.cy = swpNow.cy;
2441 }
2442
2443 if (brc)
2444 {
2445 // check for full visibility
2446 if ( (swp.x + swp.cx) > ulScreenCX)
2447 swp.x = ulScreenCX - swp.cx;
2448 if ( (swp.y + swp.cy) > ulScreenCY)
2449 swp.y = ulScreenCY - swp.cy;
2450 }
2451
2452 brc = TRUE;
2453
2454 }
2455 else
2456 {
2457 // window pos not found in INI: unset SWP_MOVE etc.
2458 WinQueryWindowPos(hwnd, &swp);
2459 fl2 &= ~(SWP_MOVE | SWP_SIZE);
2460 }
2461
2462 WinSetWindowPos(hwnd,
2463 NULLHANDLE, // insert-behind window
2464 swp.x,
2465 swp.y,
2466 swp.cx,
2467 swp.cy,
2468 fl2); // SWP_* flags
2469
2470 return brc;
2471}
2472
2473/*
2474 *@@ winhStoreWindowPos:
2475 * saves the position of a certain window in the same format
2476 * as the barely documented WinStoreWindowPos API.
2477 * This uses the completely undocumented calls
2478 * WinGetFrameTreePPSize and WinGetFrameTreePPs imported
2479 * from PMWIN.DLL ordinals 972 and 973.
2480 *
2481 * The window should still be visible on the screen
2482 * when calling this function. Do not call it in WM_DESTROY,
2483 * because then the SWP data is no longer valid.
2484 *
2485 * This returns TRUE if saving was successful.
2486 *
2487 *@@added XWP V1.0.6 (2006-10-31) [pr]: @@fixes 458
2488 *@@changed XWP V1.0.7 (2006-12-16) [pr]: detect screen height/width @@fixes 903
2489 */
2490
2491BOOL winhStoreWindowPos(HWND hwnd, // in: window to save
2492 HINI hIni, // in: INI file (or HINI_USER/SYSTEM)
2493 const char *pcszApp, // in: INI application name
2494 const char *pcszKey) // in: INI key name
2495{
2496 BOOL brc = FALSE;
2497 SWP swp;
2498
2499 if (WinQueryWindowPos(hwnd, &swp))
2500 {
2501 ULONG ulSizePP = WinGetFrameTreePPSize(hwnd);
2502 ULONG ulSize = sizeof(STOREPOS) + ulSizePP;
2503 PSTOREPOS pStorePos;
2504
2505 if ((pStorePos = malloc(ulSize)))
2506 {
2507 // This first bit is guesswork as I don't know what it all means,
2508 // but it always seems to be the same everywhere I've looked.
2509 pStorePos->usMagic = 0x7B6A;
2510 pStorePos->ulRes1 = 1;
2511 pStorePos->ulRes2 = 1;
2512 pStorePos->ulRes3 = 0xFFFFFFFF;
2513 pStorePos->ulRes4 = 0xFFFFFFFF;
2514
2515 pStorePos->ulFlags = swp.fl;
2516 pStorePos->usXPos = pStorePos->usRestoreXPos = swp.x;
2517 pStorePos->usYPos = pStorePos->usRestoreYPos = swp.y;
2518 pStorePos->usWidth = pStorePos->usRestoreWidth = swp.cx;
2519 pStorePos->usHeight = pStorePos->usRestoreHeight = swp.cy;
2520 if (swp.fl & (SWP_MAXIMIZE | SWP_MINIMIZE))
2521 {
2522 pStorePos->usRestoreXPos = WinQueryWindowUShort(hwnd, QWS_XRESTORE);
2523 pStorePos->usRestoreYPos = WinQueryWindowUShort(hwnd, QWS_YRESTORE);
2524 pStorePos->usRestoreWidth = WinQueryWindowUShort(hwnd, QWS_CXRESTORE);
2525 pStorePos->usRestoreHeight = WinQueryWindowUShort(hwnd, QWS_CYRESTORE);
2526 }
2527
2528 pStorePos->usMinXPos = WinQueryWindowUShort(hwnd, QWS_XMINIMIZE);
2529 pStorePos->usMinYPos = WinQueryWindowUShort(hwnd, QWS_YMINIMIZE);
2530 pStorePos->ulScreenWidth = WinQuerySysValue(HWND_DESKTOP, SV_CXSCREEN);;
2531 pStorePos->ulScreenHeight = WinQuerySysValue(HWND_DESKTOP, SV_CYSCREEN);;
2532 pStorePos->ulPPLen = WinGetFrameTreePPs(hwnd, ulSizePP, (PSZ)(pStorePos + 1));
2533 ulSize = pStorePos->ulPPLen + sizeof(STOREPOS);
2534 brc = PrfWriteProfileData(hIni, (PSZ)pcszApp, (PSZ)pcszKey, pStorePos, ulSize);
2535 free(pStorePos);
2536 }
2537 }
2538 return brc;
2539}
2540
2541/*
2542 *@@ winhAdjustControls:
2543 * helper function for dynamically adjusting a window's
2544 * controls when the window is resized.
2545 *
2546 * This is most useful with dialogs loaded from resources
2547 * which should be sizeable. Normally, when the dialog
2548 * frame is resized, the controls stick to their positions,
2549 * and for dialogs with many controls, programming the
2550 * changes can be tiresome.
2551 *
2552 * Enter this function. ;-) Basically, this takes a
2553 * static array of MPARAM's as input (plus one dynamic
2554 * storage area for the window positions).
2555 *
2556 * This function must get called in three contexts:
2557 * during WM_INITDLG, during WM_WINDOWPOSCHANGED, and
2558 * during WM_DESTROY, with varying parameters.
2559 *
2560 * In detail, there are four things you need to do to make
2561 * this work:
2562 *
2563 * 1) Set up a static array (as a global variable) of
2564 * MPARAM's, one for each control in your array.
2565 * Each MPARAM will have the control's ID and the
2566 * XAC_* flags (winh.h) how the control shall be moved.
2567 * Use MPFROM2SHORT to easily create this. Example:
2568 *
2569 + MPARAM ampControlFlags[] =
2570 + { MPFROM2SHORT(ID_CONTROL_1, XAC_MOVEX),
2571 + MPFROM2SHORT(ID_CONTROL_2, XAC_SIZEY),
2572 + ...
2573 + }
2574 *
2575 * This can safely be declared as a global variable
2576 * because this data will only be read and never
2577 * changed by this function.
2578 *
2579 * 2) In WM_INITDLG of your dialog function, set up
2580 * an XADJUSTCTRLS structure, preferrably in your
2581 * window words (QWL_USER).
2582 *
2583 * ZERO THAT STRUCTURE (memset(&xac, 0, sizeof(XADJUSTCTRLS),
2584 * or this func will not work (because it will intialize
2585 * things on the first WM_WINDOWPOSCHANGED).
2586 *
2587 * 3) Intercept WM_WINDOWPOSCHANGED:
2588 *
2589 + case WM_WINDOWPOSCHANGED:
2590 + {
2591 + // this msg is passed two SWP structs:
2592 + // one for the old, one for the new data
2593 + // (from PM docs)
2594 + PSWP pswpNew = PVOIDFROMMP(mp1);
2595 + PSWP pswpOld = pswpNew + 1;
2596 +
2597 + // resizing?
2598 + if (pswpNew->fl & SWP_SIZE)
2599 + {
2600 + PXADJUSTCTRLS pxac = ... // get it from your window words
2601 +
2602 + winhAdjustControls(hwndDlg, // dialog
2603 + ampControlFlags, // MPARAMs array
2604 + sizeof(ampControlFlags) / sizeof(MPARAM),
2605 + // items count
2606 + pswpNew, // mp1
2607 + pxac); // storage area
2608 + }
2609 + mrc = WinDefDlgProc(hwnd, msg, mp1, mp2); ...
2610 *
2611 * 4) In WM_DESTROY, call this function again with pmpFlags,
2612 * pswpNew, and pswpNew set to NULL. This will clean up the
2613 * data which has been allocated internally (pointed to from
2614 * the XADJUSTCTRLS structure).
2615 * Don't forget to free your storage for XADJUSTCTLRS
2616 * _itself_, that's the job of the caller.
2617 *
2618 * This might sound complicated, but it's a lot easier than
2619 * having to write dozens of WinSetWindowPos calls oneself.
2620 *
2621 *@@added V0.9.0 [umoeller]
2622 *@@changed V0.9.19 (2002-04-13) [umoeller]: added correlation for entry field repositioning, this was always off
2623 */
2624
2625BOOL winhAdjustControls(HWND hwndDlg, // in: dialog (req.)
2626 const MPARAM *pmpFlags, // in: init flags or NULL for cleanup
2627 ULONG ulCount, // in: item count (req.)
2628 PSWP pswpNew, // in: pswpNew from WM_WINDOWPOSCHANGED or NULL for cleanup
2629 PXADJUSTCTRLS pxac) // in: adjust-controls storage area (req.)
2630{
2631 BOOL brc = FALSE;
2632 ULONG ul = 0;
2633
2634 /* if (!WinIsWindowVisible(hwndDlg))
2635 return (FALSE); */
2636
2637 if ((pmpFlags) && (pxac))
2638 {
2639 PSWP pswpThis;
2640 const MPARAM *pmpThis;
2641 LONG ldcx, ldcy;
2642 ULONG cWindows = 0;
2643
2644 // V0.9.19 (2002-04-13) [umoeller]
2645 LONG cxMarginEF = 3 * WinQuerySysValue(HWND_DESKTOP, SV_CXBORDER);
2646 LONG cyMarginEF = 3 * WinQuerySysValue(HWND_DESKTOP, SV_CYBORDER);
2647
2648 // setup mode:
2649 if (pxac->fInitialized == FALSE)
2650 {
2651 // first call: get all the SWP's
2652 WinQueryWindowPos(hwndDlg, &pxac->swpMain);
2653 // _Pmpf(("winhAdjustControls: queried main cx = %d, cy = %d",
2654 // pxac->swpMain.cx, pxac->swpMain.cy));
2655
2656 pxac->paswp = (PSWP)malloc(sizeof(SWP) * ulCount);
2657
2658 pswpThis = pxac->paswp;
2659 pmpThis = pmpFlags;
2660
2661 for (ul = 0;
2662 ul < ulCount;
2663 ul++)
2664 {
2665 HWND hwndThis;
2666 CHAR szClass[10];
2667 if (hwndThis = WinWindowFromID(hwndDlg, SHORT1FROMMP(*pmpThis)))
2668 {
2669 WinQueryWindowPos(hwndThis, pswpThis);
2670
2671 // correlate the stupid repositioning of entry fields
2672 // V0.9.19 (2002-04-13) [umoeller]
2673 if ( (WinQueryClassName(hwndThis, sizeof(szClass), szClass)
2674 && (!strcmp(szClass, "#6"))
2675 && (WinQueryWindowULong(hwndThis, QWL_STYLE) & ES_MARGIN))
2676 )
2677 {
2678 pswpThis->x += cxMarginEF;
2679 pswpThis->y += cyMarginEF;
2680 pswpThis->cx -= 2 * cxMarginEF;
2681 pswpThis->cy -= 2 * cyMarginEF;
2682 }
2683
2684 cWindows++;
2685 }
2686
2687 pswpThis++;
2688 pmpThis++;
2689 }
2690
2691 pxac->fInitialized = TRUE;
2692 // _Pmpf(("winhAdjustControls: queried %d controls", cWindows));
2693 }
2694
2695 if (pswpNew)
2696 {
2697 // compute width and height delta
2698 ldcx = (pswpNew->cx - pxac->swpMain.cx);
2699 ldcy = (pswpNew->cy - pxac->swpMain.cy);
2700
2701 // _Pmpf(("winhAdjustControls: new cx = %d, cy = %d",
2702 // pswpNew->cx, pswpNew->cy));
2703
2704 // now adjust the controls
2705 cWindows = 0;
2706 pswpThis = pxac->paswp;
2707 pmpThis = pmpFlags;
2708 for (ul = 0;
2709 ul < ulCount;
2710 ul++)
2711 {
2712 HWND hwndThis;
2713 if (hwndThis = WinWindowFromID(hwndDlg, SHORT1FROMMP(*pmpThis)))
2714 {
2715 LONG x = pswpThis->x,
2716 y = pswpThis->y,
2717 cx = pswpThis->cx,
2718 cy = pswpThis->cy;
2719
2720 ULONG ulSwpFlags = 0;
2721 // get flags for this control
2722 USHORT usFlags = SHORT2FROMMP(*pmpThis);
2723
2724 if (usFlags & XAC_MOVEX)
2725 {
2726 x += ldcx;
2727 ulSwpFlags |= SWP_MOVE;
2728 }
2729 if (usFlags & XAC_MOVEY)
2730 {
2731 y += ldcy;
2732 ulSwpFlags |= SWP_MOVE;
2733 }
2734 if (usFlags & XAC_SIZEX)
2735 {
2736 cx += ldcx;
2737 ulSwpFlags |= SWP_SIZE;
2738 }
2739 if (usFlags & XAC_SIZEY)
2740 {
2741 cy += ldcy;
2742 ulSwpFlags |= SWP_SIZE;
2743 }
2744
2745 if (ulSwpFlags)
2746 {
2747 WinSetWindowPos(hwndThis,
2748 NULLHANDLE, // hwndInsertBehind
2749 x, y, cx, cy,
2750 ulSwpFlags);
2751 cWindows++;
2752 brc = TRUE;
2753 }
2754 }
2755
2756 pswpThis++;
2757 pmpThis++;
2758 }
2759
2760 // _Pmpf(("winhAdjustControls: set %d windows", cWindows));
2761 }
2762 }
2763 else
2764 {
2765 // pxac == NULL:
2766 // cleanup mode
2767 if (pxac->paswp)
2768 free(pxac->paswp);
2769 }
2770
2771 return brc;
2772}
2773
2774/*
2775 *@@ winhCenterWindow:
2776 * centers a window within its parent window. If that's
2777 * the PM desktop, it will be centered according to the
2778 * whole screen.
2779 * For dialog boxes, use WinCenteredDlgBox as a one-shot
2780 * function.
2781 *
2782 * Note: When calling this function, the window should
2783 * not be visible to avoid flickering.
2784 * This func does not show the window either, so call
2785 * WinShowWindow afterwards.
2786 */
2787
2788void winhCenterWindow(HWND hwnd)
2789{
2790 RECTL rclParent;
2791 RECTL rclWindow;
2792
2793 WinQueryWindowRect(hwnd, &rclWindow);
2794 WinQueryWindowRect(WinQueryWindow(hwnd, QW_PARENT), &rclParent);
2795
2796 rclWindow.xLeft = (rclParent.xRight - rclWindow.xRight) / 2;
2797 rclWindow.yBottom = (rclParent.yTop - rclWindow.yTop ) / 2;
2798
2799 WinSetWindowPos(hwnd, NULLHANDLE, rclWindow.xLeft, rclWindow.yBottom,
2800 0, 0, SWP_MOVE);
2801}
2802
2803/*
2804 *@@ winhCenteredDlgBox:
2805 * just like WinDlgBox, but the dlg box is centered on the screen;
2806 * you should mark the dlg template as not visible in the dlg
2807 * editor, or display will flicker.
2808 * As opposed to winhCenterWindow, this _does_ show the window.
2809 */
2810
2811ULONG winhCenteredDlgBox(HWND hwndParent,
2812 HWND hwndOwner,
2813 PFNWP pfnDlgProc,
2814 HMODULE hmod,
2815 ULONG idDlg,
2816 PVOID pCreateParams)
2817{
2818 ULONG ulReply;
2819 HWND hwndDlg = WinLoadDlg(hwndParent,
2820 hwndOwner,
2821 pfnDlgProc,
2822 hmod,
2823 idDlg,
2824 pCreateParams);
2825 winhCenterWindow(hwndDlg);
2826 ulReply = WinProcessDlg(hwndDlg);
2827 WinDestroyWindow(hwndDlg);
2828 return ulReply;
2829}
2830
2831/*
2832 *@@ winhPlaceBesides:
2833 * attempts to place hwnd somewhere besides
2834 * hwndRelative.
2835 *
2836 * fl is presently ignored, but should be
2837 * PLF_SMART for future extensions.
2838 *
2839 * Works only if hwnd is a desktop child.
2840 *
2841 *@@added V0.9.19 (2002-04-17) [umoeller]
2842 *@@changed V1.0.0 (2002-08-26) [umoeller]: fixed cx and cy confusion
2843 */
2844
2845BOOL winhPlaceBesides(HWND hwnd,
2846 HWND hwndRelative,
2847 ULONG fl)
2848{
2849 SWP swpRel,
2850 swpThis;
2851 LONG xNew, yNew;
2852
2853 if ( (WinQueryWindowPos(hwndRelative, &swpRel))
2854 && (WinQueryWindowPos(hwnd, &swpThis))
2855 )
2856 {
2857 HWND hwndRelParent,
2858 hwndThisParent;
2859 POINTL ptlRel = {swpRel.x, swpRel.y};
2860 if ( (hwndRelParent = WinQueryWindow(hwndRelative, QW_PARENT))
2861 && (hwndThisParent = WinQueryWindow(hwnd, QW_PARENT))
2862 && (hwndRelParent != hwndThisParent)
2863 )
2864 {
2865 WinMapWindowPoints(hwndRelParent,
2866 hwndThisParent,
2867 &ptlRel,
2868 1);
2869 }
2870
2871 // place right first
2872 xNew = ptlRel.x + swpRel.cx;
2873 // center vertically
2874 yNew = ptlRel.y + ((swpRel.cy - swpThis.cy) / 2);
2875
2876 // if (xNew + swpThis.cy > WinQuerySysValue(HWND_DESKTOP, SV_CXSCREEN))
2877 // not cy, but cx V1.0.0 (2002-08-26) [umoeller]
2878 if (xNew + swpThis.cx > WinQuerySysValue(HWND_DESKTOP, SV_CXSCREEN))
2879 {
2880 // place left then
2881 xNew = ptlRel.x - swpThis.cx;
2882
2883 if (xNew < 0)
2884 {
2885 // center then
2886 winhCenterWindow(hwnd);
2887 return TRUE;
2888 }
2889 }
2890
2891 return WinSetWindowPos(hwnd,
2892 0,
2893 xNew,
2894 yNew,
2895 0,
2896 0,
2897 SWP_MOVE);
2898 }
2899
2900 return FALSE;
2901}
2902
2903/*
2904 *@@ winhFindWindowBelow:
2905 * finds the window with the same parent
2906 * which sits right below hwndFind in the
2907 * window Z-order.
2908 *
2909 *@@added V0.9.7 (2000-12-04) [umoeller]
2910 */
2911
2912HWND winhFindWindowBelow(HWND hwndFind)
2913{
2914 HWND hwnd = NULLHANDLE,
2915 hwndParent = WinQueryWindow(hwndFind, QW_PARENT);
2916
2917 if (hwndParent)
2918 {
2919 HENUM henum = WinBeginEnumWindows(hwndParent);
2920 HWND hwndThis;
2921 while (hwndThis = WinGetNextWindow(henum))
2922 {
2923 SWP swp;
2924 WinQueryWindowPos(hwndThis, &swp);
2925 if (swp.hwndInsertBehind == hwndFind)
2926 {
2927 hwnd = hwndThis;
2928 break;
2929 }
2930 }
2931 WinEndEnumWindows(henum);
2932 }
2933
2934 return hwnd;
2935}
2936
2937/*
2938 *@@category: Helpers\PM helpers\Presentation parameters
2939 */
2940
2941/* ******************************************************************
2942 *
2943 * Presparams helpers
2944 *
2945 ********************************************************************/
2946
2947/*
2948 *@@ winhQueryWindowFont:
2949 * returns the window font presentation parameter
2950 * in a newly allocated buffer.
2951 *
2952 * Returns NULL on error. Use free()
2953 * to free the return value.
2954 *
2955 *@@added V0.9.1 (2000-02-14) [umoeller]
2956 */
2957
2958PSZ winhQueryWindowFont(HWND hwnd)
2959{
2960 CHAR szNewFont[100] = "";
2961 WinQueryPresParam(hwnd,
2962 PP_FONTNAMESIZE,
2963 0,
2964 NULL,
2965 (ULONG)sizeof(szNewFont),
2966 (PVOID)&szNewFont,
2967 QPF_NOINHERIT);
2968 if (szNewFont[0] != 0)
2969 return strdup(szNewFont);
2970
2971 return NULL;
2972}
2973
2974/*
2975 *@@ winhSetWindowFont:
2976 * this sets a window's font by invoking
2977 * WinSetPresParam on it.
2978 *
2979 * If (pszFont == NULL), a default font will be set
2980 * (on Warp 4, "9.WarpSans", on Warp 3, "8.Helv").
2981 *
2982 * winh.h also defines the winhSetDlgItemFont macro.
2983 *
2984 * Returns TRUE if successful or FALSE otherwise.
2985 *
2986 *@@added V0.9.0 [umoeller]
2987 *@@changed V1.0.4 (2005-09-02) [bvl]: Return 'Combined' fonts on DBCS systems to show DBCS characters properly @@fixes 655
2988 */
2989
2990BOOL winhSetWindowFont(HWND hwnd,
2991 const char *pcszFont)
2992{
2993 CHAR szFont[256];
2994
2995 if (pcszFont == NULL)
2996 {
2997 if (doshIsWarp4())
2998 if(nlsDBCS())
2999 strhncpy0(szFont, "9.WarpSans Combined", sizeof(szFont));
3000 else
3001 strhncpy0(szFont, "9.WarpSans", sizeof(szFont));
3002 else
3003 if(nlsDBCS())
3004 strhncpy0(szFont, "8.Helv Combined", sizeof(szFont));
3005 else
3006 strhncpy0(szFont, "8.Helv", sizeof(szFont));
3007 }
3008 else
3009 strhncpy0(szFont, pcszFont, sizeof(szFont));
3010
3011 return WinSetPresParam(hwnd,
3012 PP_FONTNAMESIZE,
3013 strlen(szFont)+1,
3014 szFont);
3015}
3016
3017/*
3018 *@@ winhSetControlsFont:
3019 * this sets the font for all the controls of hwndDlg
3020 * which have a control ID in the range of usIDMin to
3021 * usIDMax. "Unused" IDs (i.e. -1) will also be set.
3022 *
3023 * If (pszFont == NULL), a default font will be set
3024 * (on Warp 4, "9.WarpSans", on Warp 3, "8.Helv").
3025 *
3026 * Returns the no. of controls set.
3027 *
3028 *@@added V0.9.0 [umoeller]
3029 *@@changed V1.0.4 (2005-09-02) [bvl]: Return 'Combined' fonts on DBCS systems to show DBCS characters properly @@fixes 655
3030 */
3031
3032ULONG winhSetControlsFont(HWND hwndDlg, // in: dlg to set
3033 SHORT usIDMin, // in: minimum control ID to be set (inclusive)
3034 SHORT usIDMax, // in: maximum control ID to be set (inclusive)
3035 const char *pcszFont) // in: font to use (e.g. "9.WarpSans") or NULL
3036{
3037 ULONG ulrc = 0;
3038 HENUM henum;
3039 HWND hwndItem;
3040 CHAR szFont[256];
3041 ULONG cbFont;
3042
3043 if (pcszFont == NULL)
3044 {
3045 if (doshIsWarp4())
3046 if(nlsDBCS())
3047 strhncpy0(szFont, "9.WarpSans Combined", sizeof(szFont));
3048 else
3049 strhncpy0(szFont, "9.WarpSans", sizeof(szFont));
3050 else
3051 if(nlsDBCS())
3052 strhncpy0(szFont, "8.Helv Combined", sizeof(szFont));
3053 else
3054 strhncpy0(szFont, "8.Helv", sizeof(szFont));
3055 }
3056 else
3057 strhncpy0(szFont, pcszFont, sizeof(szFont));
3058
3059 cbFont = strlen(szFont) + 1;
3060
3061 // set font for all the dialog controls
3062 henum = WinBeginEnumWindows(hwndDlg);
3063 while ((hwndItem = WinGetNextWindow(henum)))
3064 {
3065 SHORT sID = WinQueryWindowUShort(hwndItem, QWS_ID);
3066 if ( (sID == -1)
3067 || ((sID >= usIDMin) && (sID <= usIDMax))
3068 )
3069 if (WinSetPresParam(hwndItem,
3070 PP_FONTNAMESIZE,
3071 cbFont,
3072 szFont))
3073 // successful:
3074 ulrc++;
3075 }
3076 WinEndEnumWindows(henum);
3077
3078 return ulrc;
3079}
3080
3081/*
3082 *@@ winhStorePresParam:
3083 * this appends a new presentation parameter to an
3084 * array of presentation parameters which can be
3085 * passed to WinCreateWindow. This is preferred
3086 * over setting the presparams using WinSetPresParams,
3087 * because that call will cause a lot of messages.
3088 *
3089 * On the first call, pppp _must_ be NULL. This
3090 * will allocate memory for storing the given
3091 * data as necessary and modify *pppp to point
3092 * to the new array.
3093 *
3094 * On subsequent calls with the same pppp, memory
3095 * will be reallocated, the old data will be copied,
3096 * and the new given data will be appended.
3097 *
3098 * Use free() on your PPRESPARAMS pointer (whose
3099 * address was passed) after WinCreateWindow.
3100 *
3101 * See winhQueryPresColor for typical presparams
3102 * used in OS/2.
3103 *
3104 * Example:
3105 *
3106 + PPRESPARAMS ppp = NULL;
3107 + CHAR szFont[] = "9.WarpSans";
3108 + LONG lColor = CLR_WHITE;
3109 + winhStorePresParam(&ppp, PP_FONTNAMESIZE, sizeof(szFont), szFont);
3110 + winhStorePresParam(&ppp, PP_BACKGROUNDCOLOR, sizeof(lColor), &lColor);
3111 + WinCreateWindow(...., ppp);
3112 + free(ppp);
3113 *
3114 *@@added V0.9.0 [umoeller]
3115 */
3116
3117BOOL winhStorePresParam(PPRESPARAMS *pppp, // in: data pointer (modified)
3118 ULONG ulAttrType, // in: PP_* index
3119 ULONG cbData, // in: sizeof(*pData), e.g. sizeof(LONG)
3120 PVOID pData) // in: presparam data (e.g. a PLONG to a color)
3121{
3122 BOOL brc = FALSE;
3123 if (pppp)
3124 {
3125 ULONG cbOld = 0,
3126 cbNew;
3127 PBYTE pbTemp = 0;
3128 PPRESPARAMS pppTemp = 0;
3129 PPARAM pppCopyTo = 0;
3130
3131 if (*pppp != NULL)
3132 // subsequent calls:
3133 cbOld = (**pppp).cb;
3134
3135 cbNew = sizeof(ULONG) // PRESPARAMS.cb
3136 + cbOld // old count, which does not include PRESPARAMS.cb
3137 + sizeof(ULONG) // PRESPARAMS.aparam[0].id
3138 + sizeof(ULONG) // PRESPARAMS.aparam[0].cb
3139 + cbData; // PRESPARAMS.aparam[0].ab[]
3140
3141 pbTemp = (PBYTE)malloc(cbNew);
3142 if (pbTemp)
3143 {
3144 pppTemp = (PPRESPARAMS)pbTemp;
3145
3146 if (*pppp != NULL)
3147 {
3148 // copy old data
3149 memcpy(pbTemp, *pppp, cbOld + sizeof(ULONG)); // including PRESPARAMS.cb
3150 pppCopyTo = (PPARAM)(pbTemp // new buffer
3151 + sizeof(ULONG) // skipping PRESPARAMS.cb
3152 + cbOld); // old PARAM array
3153 }
3154 else
3155 // first call:
3156 pppCopyTo = pppTemp->aparam;
3157
3158 pppTemp->cb = cbNew - sizeof(ULONG); // excluding PRESPARAMS.cb
3159 pppCopyTo->id = ulAttrType;
3160 pppCopyTo->cb = cbData; // byte count of PARAM.ab[]
3161 memcpy(pppCopyTo->ab, pData, cbData);
3162
3163 free(*pppp);
3164 *pppp = pppTemp;
3165
3166 brc = TRUE;
3167 }
3168 }
3169 return brc;
3170}
3171
3172/*
3173 *@@ winhQueryPresColor2:
3174 * returns the specified color. This is queried in the
3175 * following order:
3176 *
3177 * 1) hwnd's pres params are searched for ulPP
3178 * (which should be a PP_* index);
3179 * 2) if (fInherit == TRUE), the parent windows
3180 * are searched also;
3181 * 3) if this fails or (fInherit == FALSE), WinQuerySysColor
3182 * is called to get lSysColor (which should be a SYSCLR_*
3183 * index), if lSysColor != -1;
3184 * 4) if (lSysColor == -1), -1 is returned.
3185 *
3186 * The return value is always an RGB LONG, _not_ a color index.
3187 * This is even true for the returned system colors, which are
3188 * converted to RGB.
3189 *
3190 * If you do any painting with this value, you should switch
3191 * the HPS you're using to RGB mode (use gpihSwitchToRGB for that).
3192 *
3193 * Some useful ulPP / lSysColor pairs
3194 * (default values as in PMREF):
3195 *
3196 + -- PP_FOREGROUNDCOLOR SYSCLR_WINDOWTEXT (for most controls also)
3197 + SYSCLR_WINDOWSTATICTEXT (for static controls)
3198 + Foreground color (default: black)
3199 + -- PP_BACKGROUNDCOLOR SYSCLR_BACKGROUND
3200 + SYSCLR_DIALOGBACKGROUND
3201 + SYSCLR_FIELDBACKGROUND (for disabled scrollbars)
3202 + SYSCLR_WINDOW (application surface -- empty clients)
3203 + Background color (default: light gray)
3204 + -- PP_ACTIVETEXTFGNDCOLOR
3205 + -- PP_HILITEFOREGROUNDCOLOR SYSCLR_HILITEFOREGROUND
3206 + Highlighted foreground color, for example for selected menu
3207 + (def.: white)
3208 + -- PP_ACTIVETEXTBGNDCOLOR
3209 + -- PP_HILITEBACKGROUNDCOLOR SYSCLR_HILITEBACKGROUND
3210 + Highlighted background color (def.: dark gray)
3211 + -- PP_INACTIVETEXTFGNDCOLOR
3212 + -- PP_DISABLEDFOREGROUNDCOLOR SYSCLR_MENUDISABLEDTEXT
3213 + Disabled foreground color (dark gray)
3214 + -- PP_INACTIVETEXTBGNDCOLOR
3215 + -- PP_DISABLEDBACKGROUNDCOLOR
3216 + Disabled background color
3217 + -- PP_BORDERCOLOR SYSCLR_WINDOWFRAME
3218 + SYSCLR_INACTIVEBORDER
3219 + Border color (around pushbuttons, in addition to
3220 + the 3D colors)
3221 + -- PP_ACTIVECOLOR SYSCLR_ACTIVETITLE
3222 + Active color
3223 + -- PP_INACTIVECOLOR SYSCLR_INACTIVETITLE
3224 + Inactive color
3225 *
3226 * For menus:
3227 + -- PP_MENUBACKGROUNDCOLOR SYSCLR_MENU
3228 + -- PP_MENUFOREGROUNDCOLOR SYSCLR_MENUTEXT
3229 + -- PP_MENUHILITEBGNDCOLOR SYSCLR_MENUHILITEBGND
3230 + -- PP_MENUHILITEFGNDCOLOR SYSCLR_MENUHILITE
3231 + -- ?? SYSCLR_MENUDISABLEDTEXT
3232 +
3233 * For containers (according to the API ref. at EDM/2):
3234 + -- PP_FOREGROUNDCOLOR SYSCLR_WINDOWTEXT
3235 + -- PP_BACKGROUNDCOLOR SYSCLR_WINDOW
3236 + -- PP_HILITEFOREGROUNDCOLOR SYSCLR_HILITEFOREGROUND
3237 + -- PP_HILITEBACKGROUNDCOLOR SYSCLR_HILITEBACKGROUND
3238 + -- PP_BORDERCOLOR
3239 + (used for separator lines, eg. in Details view)
3240 + -- PP_ICONTEXTBACKGROUNDCOLOR
3241 + (column titles in Details view?!?)
3242 +
3243 * For listboxes / entryfields / MLE's:
3244 + -- PP_BACKGROUNDCOLOR SYSCLR_ENTRYFIELD
3245 *
3246 * PMREF has more of these.
3247 *
3248 *@@changed V0.9.0 [umoeller]: removed INI key query, using SYSCLR_* instead; function prototype changed
3249 *@@changed V0.9.0 [umoeller]: added fInherit parameter
3250 *@@changed V0.9.7 (2000-12-02) [umoeller]: added lSysColor == -1 support
3251 *@@changed V0.9.20 (2002-08-04) [umoeller]: added ulPPIndex, renamed func
3252 */
3253
3254LONG winhQueryPresColor2(HWND hwnd, // in: window to query
3255 ULONG ulppRGB, // in: PP_* index for RGB color
3256 ULONG ulppIndex, // in: PP_* index for color _index_ (can be null)
3257 BOOL fInherit, // in: search parent windows too?
3258 LONG lSysColor) // in: SYSCLR_* index or -1
3259{
3260 ULONG ul,
3261 attrFound;
3262 LONG lColorFound;
3263
3264 if (ulppRGB != (ULONG)-1)
3265 {
3266 ULONG fl = 0;
3267 if (!fInherit)
3268 fl = QPF_NOINHERIT;
3269 if (ulppIndex)
3270 fl |= QPF_ID2COLORINDEX; // convert indexed color 2 to RGB V0.9.20 (2002-08-04) [umoeller]
3271
3272 if ((ul = WinQueryPresParam(hwnd,
3273 ulppRGB,
3274 ulppIndex,
3275 &attrFound,
3276 sizeof(lColorFound),
3277 &lColorFound,
3278 fl)))
3279 return lColorFound;
3280 }
3281
3282 // not found: get system color
3283 if (lSysColor != -1)
3284 return WinQuerySysColor(HWND_DESKTOP, lSysColor, 0);
3285
3286 return -1;
3287}
3288
3289/*
3290 *@@ winhQueryPresColor:
3291 * compatibility function because this one was
3292 * exported.
3293 *
3294 *@@added V0.9.20 (2002-08-04) [umoeller]
3295 */
3296
3297LONG XWPENTRY winhQueryPresColor(HWND hwnd,
3298 ULONG ulPP,
3299 BOOL fInherit,
3300 LONG lSysColor)
3301{
3302 return winhQueryPresColor2(hwnd,
3303 ulPP,
3304 0,
3305 fInherit,
3306 lSysColor);
3307}
3308
3309/*
3310 *@@ winhSetPresColor:
3311 * sets a color presparam. ulIndex specifies
3312 * the presparam to be set and would normally
3313 * be either PP_BACKGROUNDCOLOR or PP_FOREGROUNDCOLOR.
3314 *
3315 *@@added V0.9.16 (2001-10-15) [umoeller]
3316 */
3317
3318BOOL winhSetPresColor(HWND hwnd,
3319 ULONG ulIndex,
3320 LONG lColor)
3321{
3322 return WinSetPresParam(hwnd,
3323 ulIndex,
3324 sizeof(LONG),
3325 &lColor);
3326}
3327
3328/*
3329 *@@category: Helpers\PM helpers\Help (IPF)
3330 */
3331
3332/* ******************************************************************
3333 *
3334 * Help instance helpers
3335 *
3336 ********************************************************************/
3337
3338/*
3339 *@@ winhCreateHelp:
3340 * creates a help instance and connects it with the
3341 * given frame window.
3342 *
3343 * If (pszFileName == NULL), we'll retrieve the
3344 * executable's fully qualified file name and
3345 * replace the extension with .HLP simply. This
3346 * avoids the typical "Help not found" errors if
3347 * the program isn't started in its own directory.
3348 *
3349 * If you have created a help table in memory, specify it
3350 * with pHelpTable. To load a help table from the resources,
3351 * specify hmod (or NULLHANDLE) and set pHelpTable to the
3352 * following:
3353 +
3354 + (PHELPTABLE)MAKELONG(usTableID, 0xffff)
3355 *
3356 * Returns the help window handle or NULLHANDLE on errors.
3357 *
3358 * Based on an EDM/2 code snippet.
3359 *
3360 *@@added V0.9.4 (2000-07-03) [umoeller]
3361 */
3362
3363HWND winhCreateHelp(HWND hwndFrame, // in: app's frame window handle; can be NULLHANDLE
3364 const char *pcszFileName, // in: help file name or NULL
3365 HMODULE hmod, // in: module with help table or NULLHANDLE (current)
3366 PHELPTABLE pHelpTable, // in: help table or resource ID
3367 const char *pcszWindowTitle) // in: help window title or NULL
3368{
3369 HELPINIT hi;
3370 PSZ pszExt;
3371 CHAR szName[CCHMAXPATH] = "";
3372 HWND hwndHelp;
3373
3374 if (pcszFileName == NULL)
3375 {
3376 PPIB ppib;
3377 PTIB ptib;
3378 DosGetInfoBlocks(&ptib, &ppib);
3379 DosQueryModuleName(ppib->pib_hmte, sizeof(szName), szName);
3380
3381 pszExt = strrchr(szName, '.');
3382 if (pszExt)
3383 strcpy(pszExt, ".hlp");
3384 else
3385 strcat(szName, ".hlp");
3386
3387 pcszFileName = szName;
3388 }
3389
3390 hi.cb = sizeof(HELPINIT);
3391 hi.ulReturnCode = 0;
3392 hi.pszTutorialName = NULL;
3393 hi.phtHelpTable = pHelpTable;
3394 hi.hmodHelpTableModule = hmod;
3395 hi.hmodAccelActionBarModule = NULLHANDLE;
3396 hi.idAccelTable = 0;
3397 hi.idActionBar = 0;
3398 hi.pszHelpWindowTitle = (PSZ)pcszWindowTitle;
3399 hi.fShowPanelId = CMIC_HIDE_PANEL_ID;
3400 hi.pszHelpLibraryName = (PSZ)pcszFileName;
3401
3402 hwndHelp = WinCreateHelpInstance(WinQueryAnchorBlock(hwndFrame),
3403 &hi);
3404 if ((hwndFrame) && (hwndHelp))
3405 {
3406 WinAssociateHelpInstance(hwndHelp, hwndFrame);
3407 }
3408
3409 return hwndHelp;
3410}
3411
3412/*
3413 *@@ winhDisplayHelpPanel:
3414 * displays the specified help panel ID.
3415 *
3416 * If (ulHelpPanel == 0), this displays the
3417 * standard OS/2 "Using help" panel.
3418 *
3419 * Returns zero on success or one of the
3420 * help manager error codes on failure.
3421 * See HM_ERROR for those.
3422 *
3423 *@@added V0.9.7 (2001-01-21) [umoeller]
3424 */
3425
3426ULONG winhDisplayHelpPanel(HWND hwndHelpInstance, // in: from winhCreateHelp
3427 ULONG ulHelpPanel) // in: help panel ID
3428{
3429 return (ULONG)WinSendMsg(hwndHelpInstance,
3430 HM_DISPLAY_HELP,
3431 (MPARAM)ulHelpPanel,
3432 (MPARAM)( (ulHelpPanel != 0)
3433 ? HM_RESOURCEID
3434 : 0));
3435}
3436
3437/*
3438 *@@ winhDestroyHelp:
3439 * destroys the help instance created by winhCreateHelp.
3440 *
3441 * Based on an EDM/2 code snippet.
3442 *
3443 *@@added V0.9.4 (2000-07-03) [umoeller]
3444 */
3445
3446void winhDestroyHelp(HWND hwndHelp,
3447 HWND hwndFrame) // can be NULLHANDLE if not used with winhCreateHelp
3448{
3449 if (hwndHelp)
3450 {
3451 if (hwndFrame)
3452 WinAssociateHelpInstance(NULLHANDLE, hwndFrame);
3453 WinDestroyHelpInstance(hwndHelp);
3454 }
3455}
3456
3457/*
3458 *@@category: Helpers\PM helpers\Application control
3459 */
3460
3461/* ******************************************************************
3462 *
3463 * Application control
3464 *
3465 ********************************************************************/
3466
3467/*
3468 *@@ winhAnotherInstance:
3469 * this tests whether another instance of the same
3470 * application is already running.
3471 *
3472 * To identify instances of the same application, the
3473 * application must call this function during startup
3474 * with the unique name of an OS/2 semaphore. As with
3475 * all OS/2 semaphores, the semaphore name must begin
3476 * with "\\SEM32\\". The semaphore isn't really used
3477 * except for testing for its existence, since that
3478 * name is unique among all processes.
3479 *
3480 * If another instance is found, TRUE is returned. If
3481 * (fSwitch == TRUE), that instance is switched to,
3482 * using the tasklist.
3483 *
3484 * If no other instance is found, FALSE is returned only.
3485 *
3486 * Based on an EDM/2 code snippet.
3487 *
3488 *@@added V0.9.0 (99-10-22) [umoeller]
3489 */
3490
3491BOOL winhAnotherInstance(const char *pcszSemName, // in: semaphore ID
3492 BOOL fSwitch) // in: if TRUE, switch to first instance if running
3493{
3494 HMTX hmtx;
3495
3496 if (DosCreateMutexSem((PSZ)pcszSemName,
3497 &hmtx,
3498 DC_SEM_SHARED,
3499 TRUE)
3500 == NO_ERROR)
3501 // semapore created: this doesn't happen if the semaphore
3502 // exists already, so no other instance is running
3503 return FALSE;
3504
3505 // else: instance running
3506 hmtx = NULLHANDLE;
3507
3508 // switch to other instance?
3509 if (fSwitch)
3510 {
3511 // yes: query mutex creator
3512 if (DosOpenMutexSem((PSZ)pcszSemName,
3513 &hmtx)
3514 == NO_ERROR)
3515 {
3516 PID pid = 0;
3517 TID tid = 0; // unused
3518 ULONG ulCount; // unused
3519
3520 if (DosQueryMutexSem(hmtx, &pid, &tid, &ulCount) == NO_ERROR)
3521 {
3522 HSWITCH hswitch = WinQuerySwitchHandle(NULLHANDLE, pid);
3523 if (hswitch != NULLHANDLE)
3524 WinSwitchToProgram(hswitch);
3525 }
3526
3527 DosCloseMutexSem(hmtx);
3528 }
3529 }
3530
3531 return TRUE; // another instance exists
3532}
3533
3534/*
3535 *@@ winhAddToTasklist:
3536 * this adds the specified window to the tasklist
3537 * with hIcon as its program icon (which is also
3538 * set for the main window). This is useful for
3539 * the old "dialog as main window" trick.
3540 *
3541 * Returns the HSWITCH of the added entry.
3542 */
3543
3544HSWITCH winhAddToTasklist(HWND hwnd, // in: window to add
3545 HPOINTER hIcon) // in: icon for main window
3546{
3547 SWCNTRL swctl;
3548 HSWITCH hswitch = 0;
3549 swctl.hwnd = hwnd; // window handle
3550 swctl.hwndIcon = hIcon; // icon handle
3551 swctl.hprog = NULLHANDLE; // program handle (use default)
3552 WinQueryWindowProcess(hwnd, &(swctl.idProcess), NULL);
3553 // process identifier
3554 swctl.idSession = 0; // session identifier ?
3555 swctl.uchVisibility = SWL_VISIBLE; // visibility
3556 swctl.fbJump = SWL_JUMPABLE; // jump indicator
3557 // get window title from window titlebar
3558 if (hwnd)
3559 WinQueryWindowText(hwnd, sizeof(swctl.szSwtitle), swctl.szSwtitle);
3560 swctl.bProgType = PROG_DEFAULT; // program type
3561 hswitch = WinAddSwitchEntry(&swctl);
3562
3563 // give the main window the icon
3564 if ((hwnd) && (hIcon))
3565 WinSendMsg(hwnd,
3566 WM_SETICON,
3567 (MPARAM)hIcon,
3568 NULL);
3569
3570 return hswitch;
3571}
3572
3573/*
3574 *@@category: Helpers\PM helpers\Miscellaneous
3575 */
3576
3577/* ******************************************************************
3578 *
3579 * Miscellaneous
3580 *
3581 ********************************************************************/
3582
3583/*
3584 *@@ winhMyAnchorBlock:
3585 * returns the proper anchor block (HAB)
3586 * for the calling thread.
3587 *
3588 * Many Win* functions require an HAB to be
3589 * passed in. While many of them will work
3590 * when passing in NULLHANDLE, some (such as
3591 * WinGetMsg) won't. If you don't know the
3592 * anchor block of the calling thread, use
3593 * this function.
3594 *
3595 * This creates a temporary object window to
3596 * find out the anchor block. This is quite
3597 * expensive so only use this if there's no
3598 * other way to find out.
3599 *
3600 *@@added V0.9.11 (2001-04-20) [umoeller]
3601 */
3602
3603HAB winhMyAnchorBlock(VOID)
3604{
3605 HAB hab = NULLHANDLE;
3606 HWND hwnd;
3607 if (hwnd = winhCreateObjectWindow(WC_BUTTON, NULL))
3608 {
3609 hab = WinQueryAnchorBlock(hwnd);
3610 WinDestroyWindow(hwnd);
3611 }
3612
3613 return hab;
3614}
3615
3616/*
3617 *@@ winhFree:
3618 * frees a block of memory allocated by the
3619 * winh* functions.
3620 *
3621 * Since the winh* functions use malloc(),
3622 * you can also use free() directly on such
3623 * blocks. However, you must use winhFree
3624 * if the winh* functions are in a module
3625 * with a different C runtime.
3626 *
3627 *@@added V0.9.7 (2000-12-06) [umoeller]
3628 */
3629
3630VOID winhFree(PVOID p)
3631{
3632 if (p)
3633 free(p);
3634}
3635
3636/*
3637 *@@ winhSleep:
3638 * sleeps at least the specified amount of time,
3639 * without blocking the message queue.
3640 *
3641 * NOTE: This function is a bit expensive because
3642 * it creates a temporary object window. If you
3643 * need to sleep several times, you should rather
3644 * use a private timer.
3645 *
3646 *@@added V0.9.4 (2000-07-11) [umoeller]
3647 *@@changed V0.9.9 (2001-03-11) [umoeller]: rewritten
3648 */
3649
3650VOID winhSleep(ULONG ulSleep) // in: sleep time in milliseconds
3651{
3652 HWND hwnd;
3653
3654 if (hwnd = winhCreateObjectWindow(WC_STATIC, NULL))
3655 {
3656 QMSG qmsg;
3657 HAB hab;
3658
3659 if ( (hab = WinQueryAnchorBlock(hwnd))
3660 && (WinStartTimer(hab,
3661 hwnd,
3662 1,
3663 ulSleep))
3664 )
3665 {
3666 while (WinGetMsg(hab, &qmsg, NULLHANDLE, 0, 0))
3667 {
3668 if ( (qmsg.hwnd == hwnd)
3669 && (qmsg.msg == WM_TIMER)
3670 && (qmsg.mp1 == (MPARAM)1) // timer ID
3671 )
3672 break;
3673
3674 WinDispatchMsg(hab, &qmsg);
3675 }
3676 WinStopTimer(hab,
3677 hwnd,
3678 1);
3679 }
3680 else
3681 // timer creation failed:
3682 DosSleep(ulSleep);
3683
3684 WinDestroyWindow(hwnd);
3685 }
3686 else
3687 DosSleep(ulSleep);
3688}
3689
3690/*
3691 *@@ winhFileDlg:
3692 * one-short function for opening an "Open" file
3693 * dialog.
3694 *
3695 * On input, pszFile specifies the directory and
3696 * file specification (e.g. "F:\*.txt").
3697 *
3698 * Returns TRUE if the user pressed OK. In that
3699 * case, the fully qualified filename is written
3700 * into pszFile again.
3701 *
3702 * Returns FALSE if the user pressed Cancel.
3703 *
3704 * Notes about flFlags:
3705 *
3706 * -- WINH_FOD_SAVEDLG: display a "Save As" dialog.
3707 * Otherwise an "Open" dialog is displayed.
3708 *
3709 * -- WINH_FOD_INILOADDIR: load a directory from the
3710 * specified INI key and switch the dlg to it.
3711 * In that case, on input, pszFile must only
3712 * contain the file filter without any path
3713 * specification, because that is loaded from
3714 * the INI key. If the INI key does not exist,
3715 * the current process directory will be used.
3716 *
3717 * -- WINH_FOD_INISAVEDIR: if the user presses OK,
3718 * the directory of the selected file is written
3719 * to the specified INI key so that it can be
3720 * reused later. This flag is independent of
3721 * WINH_FOD_INISAVEDIR: you can specify none,
3722 * one, or both of them.
3723 *
3724 *@@added V0.9.3 (2000-04-29) [umoeller]
3725 *@@changed V0.9.12 (2001-05-21) [umoeller]: this failed if INI data had root dir, fixed
3726 */
3727
3728BOOL winhFileDlg(HWND hwndOwner, // in: owner for file dlg
3729 PSZ pszFile, // in: file mask; out: fully q'd filename
3730 // (should be CCHMAXPATH in size)
3731 ULONG flFlags, // in: any combination of the following:
3732 // -- WINH_FOD_SAVEDLG: save dlg; else open dlg
3733 // -- WINH_FOD_INILOADDIR: load FOD path from INI
3734 // -- WINH_FOD_INISAVEDIR: store FOD path to INI on OK
3735 HINI hini, // in: INI file to load/store last path from (can be HINI_USER)
3736 const char *pcszApplication, // in: INI application to load/store last path from
3737 const char *pcszKey) // in: INI key to load/store last path from
3738{
3739 FILEDLG fd;
3740 FILESTATUS3 fs3;
3741
3742 memset(&fd, 0, sizeof(FILEDLG));
3743 fd.cbSize = sizeof(FILEDLG);
3744 fd.fl = FDS_CENTER;
3745
3746 if (flFlags & WINH_FOD_SAVEDLG)
3747 fd.fl |= FDS_SAVEAS_DIALOG;
3748 else
3749 fd.fl |= FDS_OPEN_DIALOG;
3750
3751 if ( (hini)
3752 && (flFlags & WINH_FOD_INILOADDIR)
3753 && (PrfQueryProfileString(hini,
3754 (PSZ)pcszApplication,
3755 (PSZ)pcszKey,
3756 "", // default string V0.9.9 (2001-02-10) [umoeller]
3757 fd.szFullFile,
3758 sizeof(fd.szFullFile)-10)
3759 > 2)
3760 // added these checks V0.9.12 (2001-05-21) [umoeller]
3761 && (!DosQueryPathInfo(fd.szFullFile,
3762 FIL_STANDARD,
3763 &fs3,
3764 sizeof(fs3)))
3765 && (fs3.attrFile & FILE_DIRECTORY)
3766 )
3767 {
3768 // found: append "\*"
3769 strcat(fd.szFullFile, "\\");
3770 strcat(fd.szFullFile, pszFile);
3771 }
3772 else
3773 // default: copy pszFile
3774 strcpy(fd.szFullFile, pszFile);
3775 // fixed V0.9.12 (2001-05-21) [umoeller]
3776
3777 if ( WinFileDlg(HWND_DESKTOP, // parent
3778 hwndOwner, // owner
3779 &fd)
3780 && (fd.lReturn == DID_OK)
3781 )
3782 {
3783 // save path back?
3784 if ( (hini)
3785 && (flFlags & WINH_FOD_INISAVEDIR)
3786 )
3787 {
3788 // get the directory that was used
3789 PSZ p = strrchr(fd.szFullFile, '\\');
3790 if (p)
3791 {
3792 // contains directory:
3793 // copy to OS2.INI
3794 PSZ pszDir = strhSubstr(fd.szFullFile, p);
3795 if (pszDir)
3796 {
3797 PrfWriteProfileString(hini,
3798 (PSZ)pcszApplication,
3799 (PSZ)pcszKey,
3800 pszDir);
3801 free(pszDir);
3802 }
3803 }
3804 }
3805
3806 strcpy(pszFile, fd.szFullFile);
3807
3808 return TRUE;
3809 }
3810
3811 return FALSE;
3812}
3813
3814/*
3815 *@@ winhSetWaitPointer:
3816 * this sets the mouse pointer to "Wait".
3817 * Returns the previous pointer (HPOINTER),
3818 * which should be stored somewhere to be
3819 * restored later. Example:
3820 + HPOINTER hptrOld = winhSetWaitPointer();
3821 + ...
3822 + WinSetPointer(HWND_DESKTOP, hptrOld);
3823 */
3824
3825HPOINTER winhSetWaitPointer(VOID)
3826{
3827 HPOINTER hptr = WinQueryPointer(HWND_DESKTOP);
3828 WinSetPointer(HWND_DESKTOP,
3829 WinQuerySysPointer(HWND_DESKTOP,
3830 SPTR_WAIT,
3831 FALSE)); // no copy
3832 return hptr;
3833}
3834
3835/*
3836 *@@ winhQueryWindowText:
3837 * this returns the window text of the specified
3838 * HWND in a newly allocated buffer.
3839 *
3840 * Returns NULL on error. Use free()
3841 * to free the return value.
3842 */
3843
3844PSZ winhQueryWindowText(HWND hwnd)
3845{
3846 PSZ pszText = NULL;
3847 ULONG cbText = WinQueryWindowTextLength(hwnd);
3848 // additional null character
3849 if (cbText)
3850 {
3851 if (pszText = (PSZ)malloc(cbText + 1))
3852 WinQueryWindowText(hwnd,
3853 cbText + 1,
3854 pszText);
3855 }
3856 return pszText;
3857}
3858
3859/*
3860 *@@ winhSetWindowText:
3861 * like WinSetWindowText, but this one accepts
3862 * printf-like arguments.
3863 *
3864 * Note that the total string is limited to
3865 * 1000 characters.
3866 *
3867 *@@added V0.9.16 (2001-10-08) [umoeller]
3868 */
3869
3870BOOL winhSetWindowText(HWND hwnd,
3871 const char *pcszFormat,
3872 ...)
3873{
3874 CHAR szBuf[1000];
3875 va_list args;
3876 int i;
3877 va_start(args, pcszFormat);
3878 i = vsprintf(szBuf, pcszFormat, args);
3879 va_end(args);
3880
3881 return WinSetWindowText(hwnd,
3882 szBuf);
3883}
3884
3885/*
3886 *@@ winhReplaceWindowText:
3887 * this is a combination of winhQueryWindowText
3888 * and strhFindReplace to replace substrings in a window.
3889 *
3890 * This is useful for filling in placeholders
3891 * a la "%1" in control windows, e.g. static
3892 * texts.
3893 *
3894 * This replaces only the first occurence of
3895 * pszSearch.
3896 *
3897 * Returns TRUE only if the window exists and
3898 * the search string was replaced.
3899 *
3900 *@@added V0.9.0 [umoeller]
3901 */
3902
3903BOOL winhReplaceWindowText(HWND hwnd, // in: window whose text is to be modified
3904 const char *pcszSearch, // in: search string (e.g. "%1")
3905 const char *pcszReplaceWith) // in: replacement string for pszSearch
3906{
3907 BOOL brc = FALSE;
3908 PSZ pszText = winhQueryWindowText(hwnd);
3909 if (pszText)
3910 {
3911 ULONG ulOfs = 0;
3912 if (strhFindReplace(&pszText, &ulOfs, pcszSearch, pcszReplaceWith) > 0)
3913 {
3914 WinSetWindowText(hwnd, pszText);
3915 brc = TRUE;
3916 }
3917 free(pszText);
3918 }
3919 return brc;
3920}
3921
3922/*
3923 *@@ winhEnableDlgItems:
3924 * this enables/disables a whole range of controls
3925 * in a window by enumerating the child windows
3926 * until usIDFirst is found. If so, that subwindow
3927 * is enabled/disabled and all the following windows
3928 * in the enumeration also, until usIDLast is found.
3929 *
3930 * Note that this affects _all_ controls following
3931 * the usIDFirst window, no matter what ID they have
3932 * (even if "-1"), until usIDLast is found.
3933 *
3934 * Returns the no. of controls which were enabled/disabled
3935 * (null if none).
3936 *
3937 *@@added V0.9.0 [umoeller]
3938 *@@changed V0.9.1 (99-12-20) [umoeller]: renamed from winhEnableDlgItems
3939 */
3940
3941ULONG winhEnableControls(HWND hwndDlg, // in: dialog window
3942 USHORT usIDFirst, // in: first affected control ID
3943 USHORT usIDLast, // in: last affected control ID (inclusive)
3944 BOOL fEnable) // in: enable or disable?
3945{
3946 HENUM henum1 = NULLHANDLE;
3947 HWND hwndThis = NULLHANDLE;
3948 ULONG ulCount = 0;
3949
3950 henum1 = WinBeginEnumWindows(hwndDlg);
3951 while ((hwndThis = WinGetNextWindow(henum1)) != NULLHANDLE)
3952 {
3953 USHORT usIDCheckFirst = WinQueryWindowUShort(hwndThis, QWS_ID),
3954 usIDCheckLast;
3955 if (usIDCheckFirst == usIDFirst)
3956 {
3957 WinEnableWindow(hwndThis, fEnable);
3958 ulCount++;
3959
3960 while ((hwndThis = WinGetNextWindow(henum1)) != NULLHANDLE)
3961 {
3962 WinEnableWindow(hwndThis, fEnable);
3963 ulCount++;
3964 usIDCheckLast = WinQueryWindowUShort(hwndThis, QWS_ID);
3965 if (usIDCheckLast == usIDLast)
3966 break;
3967 }
3968
3969 break; // outer loop
3970 }
3971 }
3972 WinEndEnumWindows(henum1);
3973
3974 return ulCount;
3975}
3976
3977/*
3978 *@@ winhEnableControls2:
3979 * like winhEnableControls, but instead this
3980 * takes an array of ULONGs as input, which
3981 * is assumed to contain the dialog IDs of
3982 * the controls to be enabled/disabled.
3983 *
3984 *@@added V0.9.19 (2002-05-28) [umoeller]
3985 */
3986
3987ULONG winhEnableControls2(HWND hwndDlg, // in: dialog window
3988 const ULONG *paulIDs, // in: array of dialog IDs
3989 ULONG cIDs, // in: array item count (NOT array size)
3990 BOOL fEnable) // in: enable or disable?
3991{
3992 ULONG ul,
3993 ulrc = 0;
3994 for (ul = 0;
3995 ul < cIDs;
3996 ++ul)
3997 {
3998 if (WinEnableControl(hwndDlg, paulIDs[ul], fEnable))
3999 ++ulrc;
4000 }
4001
4002 return ulrc;
4003}
4004
4005/*
4006 *@@ winhCreateStdWindow:
4007 * much like WinCreateStdWindow, but this one
4008 * allows you to have the standard window
4009 * positioned automatically, using a given
4010 * SWP structure (*pswpFrame).
4011 *
4012 * The frame is created with the specified parent
4013 * (usually HWND_DESKTOP), but no owner.
4014 *
4015 * The client window is created with the frame as
4016 * its parent and owner and gets an ID of FID_CLIENT.
4017 *
4018 * Alternatively, you can set pswpFrame to NULL
4019 * and specify FCF_SHELLPOSITION with flFrameCreateFlags.
4020 * If you want the window to be shown, specify
4021 * SWP_SHOW (and maybe SWP_ACTIVATE) in *pswpFrame.
4022 *
4023 *@@added V0.9.0 [umoeller]
4024 *@@changed V0.9.5 (2000-08-13) [umoeller]: flStyleClient never worked, fixed
4025 *@@changed V0.9.7 (2000-12-08) [umoeller]: fixed client calc for invisible window
4026 */
4027
4028HWND winhCreateStdWindow(HWND hwndFrameParent, // in: normally HWND_DESKTOP
4029 PSWP pswpFrame, // in: frame wnd pos (ptr can be NULL)
4030 ULONG flFrameCreateFlags, // in: FCF_* flags
4031 ULONG ulFrameStyle, // in: WS_* flags (e.g. WS_VISIBLE, WS_ANIMATE)
4032 const char *pcszFrameTitle, // in: frame title (title bar)
4033 ULONG ulResourcesID, // in: according to FCF_* flags
4034 const char *pcszClassClient, // in: client class name
4035 ULONG flStyleClient, // in: client style
4036 ULONG ulID, // in: frame window ID
4037 PVOID pClientCtlData, // in: pCtlData structure pointer for client
4038 PHWND phwndClient) // out: created client wnd
4039{
4040 FRAMECDATA fcdata;
4041 HWND hwndFrame;
4042 RECTL rclClient;
4043
4044 fcdata.cb = sizeof(FRAMECDATA);
4045 fcdata.flCreateFlags = flFrameCreateFlags;
4046 fcdata.hmodResources = (HMODULE)NULL;
4047 fcdata.idResources = ulResourcesID;
4048
4049 /* Create the frame and client windows. */
4050 hwndFrame = WinCreateWindow(hwndFrameParent,
4051 WC_FRAME,
4052 (PSZ)pcszFrameTitle,
4053 ulFrameStyle,
4054 0,0,0,0, // size and position = 0
4055 NULLHANDLE, // no owner
4056 HWND_TOP, // z-order
4057 ulID, // frame window ID
4058 &fcdata, // frame class data
4059 NULL); // no presparams
4060
4061 if (hwndFrame)
4062 {
4063 if (*phwndClient = WinCreateWindow(hwndFrame, // parent
4064 (PSZ)pcszClassClient, // class
4065 NULL, // no title
4066 flStyleClient, // style
4067 0,0,0,0, // size and position = 0
4068 hwndFrame, // owner
4069 HWND_BOTTOM, // bottom z-order
4070 FID_CLIENT, // frame window ID
4071 pClientCtlData, // class data
4072 NULL)) // no presparams
4073 {
4074 if (pswpFrame)
4075 {
4076 // position frame
4077 WinSetWindowPos(hwndFrame,
4078 pswpFrame->hwndInsertBehind,
4079 pswpFrame->x,
4080 pswpFrame->y,
4081 pswpFrame->cx,
4082 pswpFrame->cy,
4083 pswpFrame->fl);
4084
4085 // position client
4086 // WinQueryWindowRect(hwndFrame, &rclClient);
4087 // doesn't work because it might be invisible V0.9.7 (2000-12-08) [umoeller]
4088 rclClient.xLeft = 0;
4089 rclClient.yBottom = 0;
4090 rclClient.xRight = pswpFrame->cx;
4091 rclClient.yTop = pswpFrame->cy;
4092 WinCalcFrameRect(hwndFrame,
4093 &rclClient,
4094 TRUE); // calc client from frame
4095 WinSetWindowPos(*phwndClient,
4096 HWND_TOP,
4097 rclClient.xLeft,
4098 rclClient.yBottom,
4099 rclClient.xRight - rclClient.xLeft,
4100 rclClient.yTop - rclClient.yBottom,
4101 SWP_MOVE | SWP_SIZE | SWP_SHOW);
4102 }
4103 }
4104 }
4105
4106 return hwndFrame;
4107}
4108
4109/*
4110 *@@ winhCreateObjectWindow:
4111 * creates an object window of the specified
4112 * window class, which you should have registered
4113 * before calling this. pvCreateParam will be
4114 * given to the window on WM_CREATE.
4115 *
4116 * Returns the HWND of the object window or
4117 * NULLHANDLE on errors.
4118 *
4119 *@@added V0.9.3 (2000-04-17) [umoeller]
4120 *@@changed V0.9.7 (2001-01-17) [umoeller]: made this a function from a macro
4121 */
4122
4123HWND winhCreateObjectWindow(const char *pcszWindowClass, // in: PM window class name
4124 PVOID pvCreateParam) // in: create param
4125{
4126 return WinCreateWindow(HWND_OBJECT,
4127 (PSZ)pcszWindowClass,
4128 (PSZ)"",
4129 0,
4130 0,0,0,0,
4131 0,
4132 HWND_BOTTOM,
4133 0,
4134 pvCreateParam,
4135 NULL);
4136}
4137
4138/*
4139 *@@ winhCreateControl:
4140 * creates a control with a size and position of 0.
4141 *
4142 *@@added V0.9.9 (2001-03-13) [umoeller]
4143 *@@changed V1.0.0 (2002-08-26) [umoeller]: added separate hwndOwner
4144 */
4145
4146HWND winhCreateControl(HWND hwndParent, // in: parent window
4147 HWND hwndOwner, // in: owner window
4148 const char *pcszClass, // in: window class (e.g. WC_BUTTON)
4149 const char *pcszText, // in: window title
4150 ULONG ulStyle, // in: control style
4151 ULONG ulID) // in: control ID
4152{
4153 return WinCreateWindow(hwndParent,
4154 (PSZ)pcszClass,
4155 (PSZ)pcszText,
4156 ulStyle,
4157 0, 0, 0, 0,
4158 hwndOwner,
4159 HWND_TOP,
4160 ulID,
4161 NULL,
4162 NULL);
4163}
4164
4165/*
4166 *@@ winhRepaintWindows:
4167 * this repaints all children of hwndParent.
4168 * If this is passed as HWND_DESKTOP, the
4169 * whole screen is repainted.
4170 *
4171 *@@changed V0.9.7 (2000-12-13) [umoeller]: hwndParent was never respected, fixed
4172 */
4173
4174VOID winhRepaintWindows(HWND hwndParent)
4175{
4176 HWND hwndTop;
4177 HENUM henum = WinBeginEnumWindows(hwndParent);
4178 while ((hwndTop = WinGetNextWindow(henum)))
4179 if (WinIsWindowShowing(hwndTop))
4180 WinInvalidateRect(hwndTop, NULL, TRUE);
4181 WinEndEnumWindows(henum);
4182}
4183
4184/*
4185 *@@ winhFindMsgQueue:
4186 * returns the message queue which matches
4187 * the given process and thread IDs. Since,
4188 * per IBM definition, every thread may only
4189 * have one MQ, this should be unique.
4190 *
4191 *@@added V0.9.2 (2000-03-08) [umoeller]
4192 */
4193
4194HMQ winhFindMsgQueue(PID pid, // in: process ID
4195 TID tid, // in: thread ID
4196 HAB* phab) // out: anchor block
4197{
4198 HWND hwndThis = 0,
4199 rc = 0;
4200 HENUM henum = WinBeginEnumWindows(HWND_OBJECT);
4201 while ((hwndThis = WinGetNextWindow(henum)))
4202 {
4203 CHAR szClass[200];
4204 if (WinQueryClassName(hwndThis, sizeof(szClass), szClass))
4205 {
4206 if (strcmp(szClass, "#32767") == 0)
4207 {
4208 // message queue window:
4209 PID pidWin = 0;
4210 TID tidWin = 0;
4211 WinQueryWindowProcess(hwndThis,
4212 &pidWin,
4213 &tidWin);
4214 if ( (pidWin == pid)
4215 && (tidWin == tid)
4216 )
4217 {
4218 // get HMQ from window words
4219 rc = WinQueryWindowULong(hwndThis, QWL_HMQ);
4220 if (rc)
4221 if (phab)
4222 *phab = WinQueryAnchorBlock(hwndThis);
4223 break;
4224 }
4225 }
4226 }
4227 }
4228 WinEndEnumWindows(henum);
4229
4230 return rc;
4231}
4232
4233/*
4234 *@@ winhFindHardErrorWindow:
4235 * this searches all children of HWND_OBJECT
4236 * for the PM hard error windows, which are
4237 * invisible most of the time. When a hard
4238 * error occurs, that window is made a child
4239 * of HWND_DESKTOP instead.
4240 *
4241 * Stolen from ProgramCommander/2 (C) Roman Stangl.
4242 *
4243 *@@added V0.9.3 (2000-04-27) [umoeller]
4244 */
4245
4246VOID winhFindPMErrorWindows(HWND *phwndHardError, // out: hard error window
4247 HWND *phwndSysError) // out: system error window
4248{
4249 PID pidObject; // HWND_OBJECT's process and thread id
4250 TID tidObject;
4251 PID pidObjectChild; // HWND_OBJECT's child window process and thread id
4252 TID tidObjectChild;
4253 HENUM henumObject; // HWND_OBJECT enumeration handle
4254 HWND hwndObjectChild; // Window handle of current HWND_OBJECT child
4255 UCHAR ucClassName[32]; // Window class e.g. #1 for WC_FRAME
4256 CLASSINFO classinfoWindow; // Class info of current HWND_OBJECT child
4257
4258 *phwndHardError = NULLHANDLE;
4259 *phwndSysError = NULLHANDLE;
4260
4261 // query HWND_OBJECT's window process
4262 WinQueryWindowProcess(WinQueryObjectWindow(HWND_DESKTOP), &pidObject, &tidObject);
4263 // enumerate all child windows of HWND_OBJECT
4264 henumObject = WinBeginEnumWindows(HWND_OBJECT);
4265 while ((hwndObjectChild = WinGetNextWindow(henumObject)) != NULLHANDLE)
4266 {
4267 // see if the current HWND_OBJECT child window runs in the
4268 // process of HWND_OBJECT (PM)
4269 WinQueryWindowProcess(hwndObjectChild, &pidObjectChild, &tidObjectChild);
4270 if (pidObject == pidObjectChild)
4271 {
4272 // get the child window's data
4273 WinQueryClassName(hwndObjectChild,
4274 sizeof(ucClassName),
4275 (PCH)ucClassName);
4276 WinQueryClassInfo(WinQueryAnchorBlock(hwndObjectChild),
4277 (PSZ)ucClassName,
4278 &classinfoWindow);
4279 if ( (!strcmp((PSZ)ucClassName, "#1")
4280 || (classinfoWindow.flClassStyle & CS_FRAME))
4281 )
4282 {
4283 // if the child window is a frame window and running in
4284 // HWND_OBJECT's (PM's) window process, it must be the
4285 // PM Hard Error or System Error window
4286 WinQueryClassName(WinWindowFromID(hwndObjectChild,
4287 FID_CLIENT),
4288 sizeof(ucClassName),
4289 (PSZ)ucClassName);
4290 if (!strcmp((PSZ)ucClassName, "PM Hard Error"))
4291 {
4292 *phwndHardError = hwndObjectChild;
4293 if (*phwndSysError)
4294 // we found the other one already:
4295 // stop searching, we got both
4296 break;
4297 }
4298 else
4299 {
4300 printf("Utility: Found System Error %08X\n", (int)hwndObjectChild);
4301 *phwndSysError = hwndObjectChild;
4302 if (*phwndHardError)
4303 // we found the other one already:
4304 // stop searching, we got both
4305 break;
4306 }
4307 }
4308 } // end if (pidObject == pidObjectChild)
4309 } // end while ((hwndObjectChild = WinGetNextWindow(henumObject)) != NULLHANDLE)
4310 WinEndEnumWindows(henumObject);
4311}
4312
4313/*
4314 *@@ winhCreateFakeDesktop:
4315 * this routine creates and displays a frameless window over
4316 * the whole screen in the color of PM's Desktop to fool the
4317 * user that all windows have been closed (which in fact might
4318 * not be the case).
4319 *
4320 * This window's background color is set to the Desktop's
4321 * (PM's one, not the WPS's one).
4322 *
4323 * Returns the HWND of this window.
4324 */
4325
4326HWND winhCreateFakeDesktop(HWND hwndSibling)
4327{
4328 // presparam for background
4329 typedef struct _BACKGROUND
4330 {
4331 ULONG cb; // length of the aparam parameter, in bytes
4332 ULONG id; // attribute type identity
4333 ULONG cb2; // byte count of the ab parameter
4334 RGB rgb; // attribute value
4335 } BACKGROUND;
4336
4337 BACKGROUND background;
4338 LONG lDesktopColor;
4339
4340 // create fake desktop window = empty window with
4341 // the size of full screen
4342 lDesktopColor = WinQuerySysColor(HWND_DESKTOP,
4343 SYSCLR_BACKGROUND,
4344 0);
4345 background.cb = sizeof(background.id)
4346 + sizeof(background.cb)
4347 + sizeof(background.rgb);
4348 background.id = PP_BACKGROUNDCOLOR;
4349 background.cb2 = sizeof(RGB);
4350 background.rgb.bBlue = (CHAR1FROMMP(lDesktopColor));
4351 background.rgb.bGreen= (CHAR2FROMMP(lDesktopColor));
4352 background.rgb.bRed = (CHAR3FROMMP(lDesktopColor));
4353
4354 return WinCreateWindow(HWND_DESKTOP, // parent window
4355 WC_FRAME, // class name
4356 "", // window text
4357 WS_VISIBLE, // window style
4358 0, 0, // position and size
4359 WinQuerySysValue(HWND_DESKTOP, SV_CXSCREEN),
4360 WinQuerySysValue(HWND_DESKTOP, SV_CYSCREEN),
4361 NULLHANDLE, // owner window
4362 hwndSibling, // sibling window
4363 1, // window id
4364 NULL, // control data
4365 &background); // presentation parms
4366}
4367
4368/*
4369 *@@ winhAssertWarp4Notebook:
4370 * this takes hwndDlg as a notebook dialog page and
4371 * goes thru all its controls. If a control with an
4372 * ID <= udIdThreshold is found, this is assumed to
4373 * be a button which is to be given the BS_NOTEBOOKBUTTON
4374 * style. You should therefore give all your button
4375 * controls which should be moved such an ID.
4376 *
4377 * Note that this function will now automatically
4378 * find out the lowest y coordinate that was used
4379 * for a non-notebook button and move all controls
4380 * down accordingly. As a result, ulDownUnit must
4381 * no longer be specified (V0.9.19).
4382 *
4383 * This function is useful if you wish to create
4384 * notebook pages using dlgedit.exe which are compatible
4385 * with both Warp 3 and Warp 4. This should be executed
4386 * in WM_INITDLG of the notebook dlg function if the app
4387 * has determined that it is running on Warp 4.
4388 *
4389 *@@changed V0.9.16 (2002-02-02) [umoeller]: fixed entry fields
4390 *@@changed V0.9.19 (2002-04-24) [umoeller]: removed ulDownUnits
4391 *@@changed V0.9.19 (2002-05-02) [umoeller]: fix for combobox
4392 */
4393
4394BOOL winhAssertWarp4Notebook(HWND hwndDlg,
4395 USHORT usIdThreshold) // in: ID threshold
4396{
4397 BOOL brc = FALSE;
4398
4399 if (doshIsWarp4())
4400 {
4401 LONG yLowest = 10000;
4402 HWND hwndItem;
4403 HENUM henum = 0;
4404 PSWP paswp,
4405 pswpThis;
4406 ULONG cWindows = 0,
4407 ul;
4408
4409 BOOL fIsVisible;
4410
4411 if (fIsVisible = WinIsWindowVisible(hwndDlg))
4412 // avoid flicker
4413 WinEnableWindowUpdate(hwndDlg, FALSE);
4414
4415 if (paswp = (PSWP)malloc(sizeof(SWP) * 100))
4416 {
4417 pswpThis = paswp;
4418
4419 // loop 1: set notebook buttons, find lowest y used
4420 henum = WinBeginEnumWindows(hwndDlg);
4421 while ((hwndItem = WinGetNextWindow(henum)))
4422 {
4423 USHORT usId = WinQueryWindowUShort(hwndItem, QWS_ID);
4424 // _Pmpf(("hwndItem: 0x%lX, ID: 0x%lX", hwndItem, usId));
4425 if (usId <= usIdThreshold)
4426 {
4427 // pushbutton to change:
4428 WinSetWindowBits(hwndItem,
4429 QWL_STYLE,
4430 BS_NOTEBOOKBUTTON, BS_NOTEBOOKBUTTON);
4431 brc = TRUE;
4432 }
4433 else
4434 {
4435 // no pushbutton to change:
4436 CHAR szClass[10];
4437
4438 WinQueryWindowPos(hwndItem, pswpThis);
4439
4440 // special handling for entry fields
4441 // V0.9.16 (2002-02-02) [umoeller]
4442 WinQueryClassName(hwndItem, sizeof(szClass), szClass);
4443 if (!strcmp(szClass, "#6"))
4444 {
4445 pswpThis->x += 3 * WinQuerySysValue(HWND_DESKTOP, SV_CXBORDER);
4446 pswpThis->y += 3 * WinQuerySysValue(HWND_DESKTOP, SV_CYBORDER);
4447 }
4448
4449 // check lowest y
4450 if ( (pswpThis->y < yLowest)
4451 // ignore combobox, this will distort everything
4452 // AGAIN ... sigh V0.9.19 (2002-05-02) [umoeller]
4453 && (strcmp(szClass, "#2"))
4454 )
4455 yLowest = pswpThis->y ;
4456
4457 ++pswpThis;
4458 if (++cWindows == 100)
4459 break;
4460 }
4461 } // end while ((hwndItem = WinGetNextWindow(henum)))
4462 WinEndEnumWindows(henum);
4463
4464 // now adjust window positions
4465 pswpThis = paswp;
4466 for (ul = 0;
4467 ul < cWindows;
4468 ++ul, ++pswpThis)
4469 {
4470 pswpThis->y -= (yLowest - 8);
4471 // 8 is magic to match the lower border of the
4472 // standard WPS notebook pages V0.9.19 (2002-04-24) [umoeller]
4473 pswpThis->fl = SWP_MOVE;
4474 }
4475
4476 WinSetMultWindowPos(WinQueryAnchorBlock(hwndDlg),
4477 paswp,
4478 cWindows);
4479
4480 free(paswp);
4481 }
4482
4483 if (fIsVisible)
4484 WinShowWindow(hwndDlg, TRUE);
4485 }
4486
4487 return brc;
4488}
4489
4490/*
4491 *@@ winhDrawFormattedText:
4492 * this func takes a rectangle and draws pszText into
4493 * it, breaking the words as neccessary. The line spacing
4494 * is determined from the font currently selected in hps.
4495 *
4496 * As opposed to WinDrawText, this can draw several lines
4497 * at once, and format the _complete_ text according to the
4498 * flCmd parameter, which is like with WinDrawText.
4499 *
4500 * After this function returns, *prcl is modified like this:
4501 *
4502 * -- yTop and yBottom contain the upper and lower boundaries
4503 * which were needed to draw the text. This depends on
4504 * whether DT_TOP etc. were specified.
4505 * To get the height of the rectangle used, calculate the
4506 * delta between yTop and yBottom.
4507 *
4508 * -- xLeft and xRight are modified to contain the outmost
4509 * left and right coordinates which were needed to draw
4510 * the text. This will be set to the longest line which
4511 * was encountered.
4512 *
4513 * You can specify DT_QUERYEXTENT with flDraw to only have
4514 * these text boundaries calculated without actually drawing.
4515 *
4516 * This returns the number of lines drawn.
4517 *
4518 * Note that this calls WinDrawText with DT_TEXTATTRS set,
4519 * that is, the current text primitive attributes will be
4520 * used (fonts and colors).
4521 *
4522 *@@changed V0.9.0 [umoeller]: prcl.xLeft and xRight are now updated too upon return
4523 */
4524
4525ULONG winhDrawFormattedText(HPS hps, // in: presentation space; its settings
4526 // are used, but not altered
4527 PRECTL prcl, // in/out: rectangle to use for drawing
4528 // (modified)
4529 const char *pcszText, // in: text to draw (zero-terminated)
4530 ULONG flCmd) // in: flags like in WinDrawText; I have
4531 // only tested DT_TOP and DT_LEFT though.
4532 // DT_WORDBREAK | DT_TEXTATTRS are always
4533 // set.
4534 // You can specify DT_QUERYEXTENT to only
4535 // have prcl calculated without drawing.
4536{
4537 PSZ p = (PSZ)pcszText;
4538 LONG lDrawn = 1,
4539 lTotalDrawn = 0,
4540 lLineCount = 0,
4541 lOrigYTop = prcl->yTop;
4542 ULONG ulTextLen = strlen(pcszText),
4543 ulCharHeight,
4544 flCmd2,
4545 xLeftmost = prcl->xRight,
4546 xRightmost = prcl->xLeft;
4547 RECTL rcl2;
4548
4549 flCmd2 = flCmd | DT_WORDBREAK | DT_TEXTATTRS;
4550
4551 ulCharHeight = gpihQueryLineSpacing(hps);
4552
4553 while ( (lDrawn)
4554 && (lTotalDrawn < ulTextLen)
4555 )
4556 {
4557 memcpy(&rcl2, prcl, sizeof(rcl2));
4558 lDrawn = WinDrawText(hps,
4559 ulTextLen-lTotalDrawn,
4560 p,
4561 &rcl2,
4562 0, 0, // colors
4563 flCmd2);
4564
4565 // update char counters
4566 p += lDrawn;
4567 lTotalDrawn += lDrawn;
4568
4569 // update x extents
4570 if (rcl2.xLeft < xLeftmost)
4571 xLeftmost = rcl2.xLeft;
4572 if (rcl2.xRight > xRightmost)
4573 xRightmost = rcl2.xRight;
4574
4575 // update y for next line
4576 prcl->yTop -= ulCharHeight;
4577
4578 // increase line count
4579 lLineCount++;
4580 }
4581 prcl->xLeft = xLeftmost;
4582 prcl->xRight = xRightmost;
4583 prcl->yBottom = prcl->yTop;
4584 prcl->yTop = lOrigYTop;
4585
4586 return lLineCount;
4587}
4588
4589/*
4590 *@@ winhQuerySwitchList:
4591 * returns the switch list in a newly
4592 * allocated buffer. This does the
4593 * regular double WinQuerySwitchList
4594 * call to first get the no. of items
4595 * and then get the items.
4596 *
4597 * The no. of items can be found in
4598 * the returned SWBLOCK.cwsentry.
4599 *
4600 * Returns NULL on errors. Use
4601 * free() to free the return value.
4602 *
4603 *@@added V0.9.7 (2000-12-06) [umoeller]
4604 */
4605
4606PSWBLOCK winhQuerySwitchList(HAB hab)
4607{
4608 ULONG cItems = WinQuerySwitchList(hab, NULL, 0);
4609 ULONG ulBufSize = (cItems * sizeof(SWENTRY)) + sizeof(HSWITCH);
4610 PSWBLOCK pSwBlock = (PSWBLOCK)malloc(ulBufSize);
4611 if (pSwBlock)
4612 {
4613 cItems = WinQuerySwitchList(hab, pSwBlock, ulBufSize);
4614 if (!cItems)
4615 {
4616 free(pSwBlock);
4617 pSwBlock = NULL;
4618 }
4619 }
4620
4621 return pSwBlock;
4622}
4623
4624typedef HSWITCH APIENTRY WINHSWITCHFROMHAPP(HAPP happ);
4625
4626/*
4627 *@@ winhHSWITCHfromHAPP:
4628 * resolves and calls the undocumented
4629 * WinHSWITCHfromHAPP API.
4630 *
4631 *@@added V0.9.19 (2002-04-17) [umoeller]
4632 */
4633
4634HSWITCH winhHSWITCHfromHAPP(HAPP happ)
4635{
4636 static WINHSWITCHFROMHAPP *pWinHSWITCHfromHAPP = NULL;
4637
4638 if (!pWinHSWITCHfromHAPP)
4639 // first call: import WinHSWITCHfromHAPP
4640 // WinHSWITCHfromHAPP PMMERGE.5199
4641 doshQueryProcAddr("PMMERGE",
4642 5199,
4643 (PFN*)&pWinHSWITCHfromHAPP);
4644
4645 if (pWinHSWITCHfromHAPP)
4646 return pWinHSWITCHfromHAPP(happ);
4647
4648 return NULLHANDLE;
4649}
4650
4651/*
4652 *@@ winhQueryTasklistWindow:
4653 * returns the window handle of the PM task list.
4654 *
4655 *@@added V0.9.7 (2000-12-07) [umoeller]
4656 */
4657
4658HWND winhQueryTasklistWindow(VOID)
4659{
4660 SWBLOCK swblock;
4661
4662 // the tasklist has entry #0 in the SWBLOCK
4663 WinQuerySwitchList(NULLHANDLE, &swblock, sizeof(SWBLOCK));
4664
4665 return swblock.aswentry[0].swctl.hwnd;
4666}
4667
4668/*
4669 *@@ winhKillTasklist:
4670 * this will destroy the Tasklist (window list) window.
4671 * Note: you will only be able to get it back after a
4672 * reboot, not a WPS restart. Only for use at shutdown and such.
4673 * This trick by Uri J. Stern at
4674 * http://zebra.asta.fh-weingarten.de/os2/Snippets/Howt8881.HTML
4675 */
4676
4677VOID winhKillTasklist(VOID)
4678{
4679 HWND hwndTasklist = winhQueryTasklistWindow();
4680 WinPostMsg(hwndTasklist,
4681 0x0454, // undocumented msg for killing tasklist
4682 NULL, NULL);
4683}
4684
4685// the following must be added for EMX (99-10-22) [umoeller]
4686#ifndef NERR_BufTooSmall
4687 #define NERR_BASE 2100
4688 #define NERR_BufTooSmall (NERR_BASE+23)
4689 // the API return buffer is too small
4690#endif
4691
4692/*
4693 *@@ winhQueryPendingSpoolJobs:
4694 * returns the number of pending print jobs in the spooler
4695 * or 0 if none. Useful for testing before shutdown.
4696 */
4697
4698ULONG winhQueryPendingSpoolJobs(VOID)
4699{
4700 // BOOL rcPending = FALSE;
4701 ULONG ulTotalJobCount = 0;
4702
4703 SPLERR splerr;
4704 USHORT jobCount;
4705 ULONG cbBuf;
4706 ULONG cTotal;
4707 ULONG cReturned;
4708 ULONG cbNeeded;
4709 ULONG ulLevel;
4710 ULONG i,j;
4711 PSZ pszComputerName;
4712 PBYTE pBuf = NULL;
4713 PPRQINFO3 prq;
4714 PPRJINFO2 prj2;
4715
4716 ulLevel = 4L;
4717 pszComputerName = (PSZ)NULL;
4718 splerr = SplEnumQueue(pszComputerName, ulLevel, pBuf, 0L, // cbBuf
4719 &cReturned, &cTotal,
4720 &cbNeeded, NULL);
4721 if ( (splerr == ERROR_MORE_DATA)
4722 || (splerr == NERR_BufTooSmall)
4723 )
4724 {
4725 if (!DosAllocMem((PPVOID)&pBuf,
4726 cbNeeded,
4727 PAG_READ | PAG_WRITE | PAG_COMMIT))
4728 {
4729 cbBuf = cbNeeded;
4730 splerr = SplEnumQueue(pszComputerName, ulLevel, pBuf, cbBuf,
4731 &cReturned, &cTotal,
4732 &cbNeeded, NULL);
4733 if (splerr == NO_ERROR)
4734 {
4735 // set pointer to point to the beginning of the buffer
4736 prq = (PPRQINFO3)pBuf;
4737
4738 // cReturned has the count of the number of PRQINFO3 structures
4739 for (i = 0;
4740 i < cReturned;
4741 i++)
4742 {
4743 // save the count of jobs; there are this many PRJINFO2
4744 // structures following the PRQINFO3 structure
4745 jobCount = prq->cJobs;
4746 // _Pmpf(( "Job count in this queue is %d",jobCount ));
4747
4748 // increment the pointer past the PRQINFO3 structure
4749 prq++;
4750
4751 // set a pointer to point to the first PRJINFO2 structure
4752 prj2=(PPRJINFO2)prq;
4753 for (j = 0;
4754 j < jobCount;
4755 j++)
4756 {
4757 // increment the pointer to point to the next structure
4758 prj2++;
4759 // increase the job count, which we'll return
4760 ulTotalJobCount++;
4761
4762 } // endfor jobCount
4763
4764 // after doing all the job structures, prj2 points to the next
4765 // queue structure; set the pointer for a PRQINFO3 structure
4766 prq = (PPRQINFO3)prj2;
4767 } //endfor cReturned
4768 } // endif NO_ERROR
4769 DosFreeMem(pBuf);
4770 }
4771 } // end if Q level given
4772
4773 return ulTotalJobCount;
4774}
4775
4776/*
4777 *@@ winhSetNumLock:
4778 * this sets the NumLock key on or off, depending
4779 * on fState.
4780 *
4781 * Based on code from WarpEnhancer, (C) Achim Hasenmller.
4782 *
4783 *@@added V0.9.1 (99-12-18) [umoeller]
4784 *@@changed V1.0.6 (2006-09-30) [pr]: Set Keyboard LEDs to match @@fixes 831
4785 */
4786
4787VOID winhSetNumLock(BOOL fState)
4788{
4789 // BOOL fRestoreKBD = FALSE; // Assume we're not going to close Kbd
4790 BYTE KeyStateTable[256];
4791 ULONG ulActionTaken; // Used by DosOpen
4792 HFILE hKbd;
4793
4794 // read keyboard state table
4795 if (WinSetKeyboardStateTable(HWND_DESKTOP, &KeyStateTable[0],
4796 FALSE))
4797 {
4798 // first set the PM state
4799 if (fState)
4800 KeyStateTable[VK_NUMLOCK] |= 0x01; // Turn numlock on
4801 else
4802 KeyStateTable[VK_NUMLOCK] &= 0xFE; // Turn numlock off
4803
4804 // set keyboard state table with new state values
4805 WinSetKeyboardStateTable(HWND_DESKTOP, &KeyStateTable[0], TRUE);
4806 }
4807
4808 // now set the OS/2 keyboard state
4809
4810 // try to open OS/2 keyboard driver
4811 if (!DosOpen("KBD$",
4812 &hKbd, &ulActionTaken,
4813 0, // cbFile
4814 FILE_NORMAL,
4815 OPEN_ACTION_FAIL_IF_NEW | OPEN_ACTION_OPEN_IF_EXISTS,
4816 OPEN_SHARE_DENYNONE | OPEN_ACCESS_READWRITE,
4817 NULL))
4818 {
4819 SHIFTSTATE ShiftState;
4820 USHORT usLEDState;
4821 ULONG DataLen = sizeof(SHIFTSTATE);
4822
4823 memset(&ShiftState, '\0', DataLen);
4824 DosDevIOCtl(hKbd, IOCTL_KEYBOARD, KBD_GETSHIFTSTATE,
4825 NULL, 0L, NULL,
4826 &ShiftState, DataLen, &DataLen);
4827
4828 if (fState)
4829 ShiftState.fsState |= 0x0020; // turn NumLock on
4830 else
4831 ShiftState.fsState &= 0xFFDF; // turn NumLock off
4832
4833 DosDevIOCtl(hKbd, IOCTL_KEYBOARD, KBD_SETSHIFTSTATE,
4834 &ShiftState, DataLen, &DataLen,
4835 NULL, 0L, NULL);
4836
4837 // XWP V1.0.6 (2006-09-30) [pr]: Set Keyboard LEDs to match @@fixes 831
4838 usLEDState = (ShiftState.fsState & (SCROLLLOCK_ON | NUMLOCK_ON | CAPSLOCK_ON)) >> 4;
4839 DataLen = sizeof(usLEDState);
4840 DosDevIOCtl(hKbd, IOCTL_KEYBOARD, KBD_ALTERKBDLED,
4841 &usLEDState, DataLen, &DataLen,
4842 NULL, 0L, NULL);
4843
4844 // now close OS/2 keyboard driver
4845 DosClose(hKbd);
4846 }
4847}
4848
4849/*
4850 *@@ winhSetClipboardText:
4851 * sets the clipboard data to the given text,
4852 * replacing the current clipboard contents.
4853 *
4854 *@@added V1.0.0 (2002-08-28) [umoeller]
4855 */
4856
4857BOOL winhSetClipboardText(HAB hab,
4858 PCSZ pcsz,
4859 ULONG cbSize) // in: size of buffer INCLUDING null byte
4860{
4861 BOOL fSuccess = FALSE;
4862
4863 if (WinOpenClipbrd(hab))
4864 {
4865 PSZ pszDest;
4866 if (!DosAllocSharedMem((PVOID*)&pszDest,
4867 NULL,
4868 cbSize,
4869 PAG_WRITE | PAG_COMMIT | OBJ_GIVEABLE))
4870 {
4871 memcpy(pszDest,
4872 pcsz,
4873 cbSize);
4874
4875 WinEmptyClipbrd(hab);
4876
4877 fSuccess = WinSetClipbrdData(hab, // anchor-block handle
4878 (ULONG)pszDest, // pointer to text data
4879 CF_TEXT, // data is in text format
4880 CFI_POINTER); // passing a pointer
4881
4882 // PMREF says (implicitly) it is not necessary to call
4883 // DosFreeMem. I hope that is correct.
4884 // V0.9.19 (2002-06-02) [umoeller]
4885 }
4886
4887 WinCloseClipbrd(hab);
4888 }
4889
4890 return fSuccess;
4891}
4892
4893/*
4894 *@@category: Helpers\PM helpers\Extended frame windows
4895 */
4896
4897/* ******************************************************************
4898 *
4899 * Extended frame
4900 *
4901 ********************************************************************/
4902
4903/*
4904 *@@ winhCalcExtFrameRect:
4905 * implementation for WM_CALCFRAMERECT in fnwpSubclExtFrame.
4906 * This is exported so it can be used independently
4907 * (XWorkplace status bars).
4908 *
4909 *@@added V1.0.0 (2002-08-28) [umoeller]
4910 */
4911
4912VOID winhCalcExtFrameRect(MPARAM mp1,
4913 MPARAM mp2,
4914 LONG lStatusBarHeight)
4915{
4916 PRECTL prclPassed = (PRECTL)mp1;
4917
4918 // mp2 == TRUE: Frame rectangle provided, calculate client
4919 // mp2 == FALSE: Client area rectangle provided, calculate frame
4920 if (mp2)
4921 {
4922 // TRUE: calculate the rectl of the client;
4923 // call default window procedure to subtract child frame
4924 // controls from the rectangle's height
4925 LONG lClientHeight;
4926
4927 // position the static text frame extension below the client
4928 lClientHeight = prclPassed->yTop - prclPassed->yBottom;
4929 if (lStatusBarHeight > lClientHeight)
4930 // extension is taller than client, so set client height to 0
4931 prclPassed->yTop = prclPassed->yBottom;
4932 else
4933 {
4934 // set the origin of the client and shrink it based upon the
4935 // static text control's height
4936 prclPassed->yBottom += lStatusBarHeight;
4937 prclPassed->yTop -= lStatusBarHeight;
4938 }
4939 }
4940 else
4941 {
4942 // FALSE: calculate the rectl of the frame;
4943 // call default window procedure to subtract child frame
4944 // controls from the rectangle's height;
4945 // set the origin of the frame and increase it based upon the
4946 // static text control's height
4947 prclPassed->yBottom -= lStatusBarHeight;
4948 prclPassed->yTop += lStatusBarHeight;
4949 }
4950}
4951
4952#define STATUS_BAR_HEIGHT 20
4953
4954/*
4955 *@@ fnwpSubclExtFrame:
4956 * subclassed frame window proc.
4957 *
4958 *@@added V0.9.16 (2001-09-29) [umoeller]
4959 */
4960
4961MRESULT EXPENTRY fnwpSubclExtFrame(HWND hwndFrame, ULONG msg, MPARAM mp1, MPARAM mp2)
4962{
4963 MRESULT mrc = 0;
4964
4965 PEXTFRAMEDATA pData = (PEXTFRAMEDATA)WinQueryWindowPtr(hwndFrame, QWL_USER);
4966
4967 switch (msg)
4968 {
4969 case WM_QUERYFRAMECTLCOUNT:
4970 {
4971 // query the standard frame controls count
4972 ULONG ulrc = (ULONG)pData->pfnwpOrig(hwndFrame, msg, mp1, mp2);
4973
4974 // if we have a status bar, increment the count
4975 ulrc++;
4976
4977 mrc = (MPARAM)ulrc;
4978 }
4979 break;
4980
4981 case WM_FORMATFRAME:
4982 {
4983 // query the number of standard frame controls
4984 ULONG ulCount = (ULONG)pData->pfnwpOrig(hwndFrame, msg, mp1, mp2);
4985
4986 // we have a status bar:
4987 // format the frame
4988 ULONG ul;
4989 PSWP swpArr = (PSWP)mp1;
4990
4991 for (ul = 0; ul < ulCount; ul++)
4992 {
4993 if (WinQueryWindowUShort(swpArr[ul].hwnd, QWS_ID) == 0x8008)
4994 // FID_CLIENT
4995 {
4996 POINTL ptlBorderSizes;
4997 WinSendMsg(hwndFrame,
4998 WM_QUERYBORDERSIZE,
4999 (MPARAM)&ptlBorderSizes,
5000 0);
5001
5002 // first initialize the _new_ SWP for the status bar.
5003 // Since the SWP array for the std frame controls is
5004 // zero-based, and the standard frame controls occupy
5005 // indices 0 thru ulCount-1 (where ulCount is the total
5006 // count), we use ulCount for our static text control.
5007 swpArr[ulCount].fl = SWP_MOVE | SWP_SIZE | SWP_NOADJUST | SWP_ZORDER;
5008 swpArr[ulCount].x = ptlBorderSizes.x;
5009 swpArr[ulCount].y = ptlBorderSizes.y;
5010 swpArr[ulCount].cx = swpArr[ul].cx; // same as cnr's width
5011 swpArr[ulCount].cy = STATUS_BAR_HEIGHT;
5012 swpArr[ulCount].hwndInsertBehind = HWND_BOTTOM; // HWND_TOP;
5013 swpArr[ulCount].hwnd = WinWindowFromID(hwndFrame, FID_STATUSBAR);
5014
5015 // adjust the origin and height of the container to
5016 // accomodate our static text control
5017 swpArr[ul].y += swpArr[ulCount].cy;
5018 swpArr[ul].cy -= swpArr[ulCount].cy;
5019 }
5020 }
5021
5022 // increment the number of frame controls
5023 // to include our status bar
5024 mrc = (MRESULT)(ulCount + 1);
5025 }
5026 break;
5027
5028 case WM_CALCFRAMERECT:
5029 mrc = pData->pfnwpOrig(hwndFrame, msg, mp1, mp2);
5030
5031 // we have a status bar: calculate its rectangle
5032 winhCalcExtFrameRect(mp1,
5033 mp2,
5034 STATUS_BAR_HEIGHT);
5035 break;
5036
5037 case WM_DESTROY:
5038 WinSubclassWindow(hwndFrame, pData->pfnwpOrig);
5039 free(pData);
5040 WinSetWindowPtr(hwndFrame, QWL_USER, NULL);
5041 break;
5042
5043 default:
5044 mrc = pData->pfnwpOrig(hwndFrame, msg, mp1, mp2);
5045 }
5046
5047 return mrc;
5048}
5049
5050/*
5051 *@@ winhCreateStatusBar:
5052 * creates a status bar for a frame window.
5053 *
5054 * Normally there's no need to call this manually,
5055 * this gets called by winhCreateExtStdWindow
5056 * automatically.
5057 *
5058 *@@added V0.9.16 (2001-09-29) [umoeller]
5059 */
5060
5061HWND winhCreateStatusBar(HWND hwndFrame,
5062 HWND hwndOwner,
5063 const char *pcszText, // in: initial status bar text
5064 const char *pcszFont, // in: font to use for status bar
5065 LONG lColor) // in: foreground color for status bar
5066{
5067 // create status bar
5068 HWND hwndReturn = NULLHANDLE;
5069 PPRESPARAMS ppp = NULL;
5070
5071 winhStorePresParam(&ppp,
5072 PP_FONTNAMESIZE,
5073 strlen(pcszFont) + 1,
5074 (PVOID)pcszFont);
5075
5076 lColor = WinQuerySysColor(HWND_DESKTOP,
5077 SYSCLR_DIALOGBACKGROUND,
5078 0);
5079 winhStorePresParam(&ppp,
5080 PP_BACKGROUNDCOLOR,
5081 sizeof(lColor),
5082 &lColor);
5083
5084 lColor = CLR_BLACK;
5085 winhStorePresParam(&ppp,
5086 PP_FOREGROUNDCOLOR,
5087 sizeof(lColor),
5088 &lColor);
5089
5090 hwndReturn = WinCreateWindow(hwndFrame,
5091 WC_STATIC,
5092 (PSZ)pcszText,
5093 SS_TEXT | DT_VCENTER | WS_VISIBLE,
5094 0, 0, 0, 0,
5095 hwndOwner,
5096 HWND_TOP,
5097 FID_STATUSBAR,
5098 NULL,
5099 ppp);
5100 free(ppp);
5101
5102 return hwndReturn;
5103}
5104
5105/*
5106 *@@ winhCreateExtStdWindow:
5107 * creates an extended frame window.
5108 *
5109 * pData must point to an EXTFRAMECDATA structure
5110 * which contains a copy of the parameters to be
5111 * passed to winhCreateStdWindow. In addition,
5112 * this contains the flExtFlags field, which allows
5113 * you to automatically create a status bar for
5114 * the window.
5115 *
5116 * Note that we subclass the frame here and require
5117 * QWL_USER for that. The frame's QWL_USER points
5118 * to an EXTFRAMEDATA structure whose pUser parameter
5119 * you may use for additional data, if you want to
5120 * do further subclassing.
5121 *
5122 *@@added V0.9.16 (2001-09-29) [umoeller]
5123 */
5124
5125HWND winhCreateExtStdWindow(PEXTFRAMECDATA pData, // in: extended frame data
5126 PHWND phwndClient) // out: created client wnd
5127{
5128 HWND hwndFrame;
5129
5130 if (hwndFrame = winhCreateStdWindow(HWND_DESKTOP,
5131 pData->pswpFrame,
5132 pData->flFrameCreateFlags,
5133 pData->ulFrameStyle,
5134 pData->pcszFrameTitle,
5135 pData->ulResourcesID,
5136 pData->pcszClassClient,
5137 pData->flStyleClient,
5138 pData->ulID,
5139 pData->pClientCtlData,
5140 phwndClient))
5141 {
5142 if (pData->flExtFlags & XFCF_STATUSBAR)
5143 {
5144 // create status bar as child of the frame
5145 HWND hwndStatusBar = winhCreateStatusBar(hwndFrame,
5146 hwndFrame,
5147 "",
5148 "9.WarpSans",
5149 CLR_BLACK);
5150
5151 // subclass frame for supporting status bar and msgs
5152 PEXTFRAMEDATA pFrameData;
5153 if (pFrameData = NEW(EXTFRAMEDATA))
5154 {
5155 ZERO(pFrameData),
5156 memcpy(&pFrameData->CData, pData, sizeof(pFrameData->CData));
5157 if (pFrameData->pfnwpOrig = WinSubclassWindow(hwndFrame,
5158 fnwpSubclExtFrame))
5159 {
5160 WinSetWindowPtr(hwndFrame, QWL_USER, pFrameData);
5161 }
5162 else
5163 free(pFrameData);
5164 }
5165 }
5166 }
5167
5168 return hwndFrame;
5169}
5170
5171/*
5172 *@@category: Helpers\PM helpers\Workplace Shell\WPS class list
5173 */
5174
5175/* ******************************************************************
5176 *
5177 * WPS Class List helpers
5178 *
5179 ********************************************************************/
5180
5181/*
5182 *@@ winhQueryWPSClassList:
5183 * this returns the WPS class list in a newly
5184 * allocated buffer. This is just a shortcut to
5185 * the usual double WinEnumObjectClasses call.
5186 *
5187 * The return value is actually of the POBJCLASS type,
5188 * so you better cast this manually. We declare this
5189 * this as PBYTE though because POBJCLASS requires
5190 * INCL_WINWORKPLACE.
5191 * See WinEnumObjectClasses() for details.
5192 *
5193 * Returns NULL on error. Use free()
5194 * to free the return value.
5195 *
5196 *@@added V0.9.0 [umoeller]
5197 */
5198
5199PBYTE winhQueryWPSClassList(VOID)
5200{
5201 ULONG ulSize;
5202 POBJCLASS pObjClass = 0;
5203
5204 // get WPS class list size
5205 if (WinEnumObjectClasses(NULL, &ulSize))
5206 {
5207 // allocate buffer
5208 pObjClass = (POBJCLASS)malloc(ulSize + 1);
5209 // and load the classes into it
5210 WinEnumObjectClasses(pObjClass, &ulSize);
5211 }
5212
5213 return (PBYTE)pObjClass;
5214}
5215
5216/*
5217 *@@ winhQueryWPSClass:
5218 * this returns the POBJCLASS item if pszClass is registered
5219 * with the WPS or NULL if the class could not be found.
5220 *
5221 * The return value is actually of the POBJCLASS type,
5222 * so you better cast this manually. We declare this
5223 * this as PBYTE though because POBJCLASS requires
5224 * INCL_WINWORKPLACE.
5225 *
5226 * This takes as input the return value of winhQueryWPSClassList,
5227 * which you must call first.
5228 *
5229 * <B>Usage:</B>
5230 + PBYTE pClassList = winhQueryWPSClassList(),
5231 + pWPFolder;
5232 + if (pClassList)
5233 + {
5234 + if (pWPFolder = winhQueryWPSClass(pClassList, "WPFolder"))
5235 + ...
5236 + free(pClassList);
5237 + }
5238 *
5239 *@@added V0.9.0 [umoeller]
5240 */
5241
5242PBYTE winhQueryWPSClass(PBYTE pObjClass, // in: buffer returned by
5243 // winhQueryWPSClassList
5244 const char *pszClass) // in: class name to query
5245{
5246 PBYTE pbReturn = 0;
5247
5248 POBJCLASS pocThis = (POBJCLASS)pObjClass;
5249 // now go thru the WPS class list
5250 while (pocThis)
5251 {
5252 if (strcmp(pocThis->pszClassName, pszClass) == 0)
5253 {
5254 pbReturn = (PBYTE)pocThis;
5255 break;
5256 }
5257 // next class
5258 pocThis = pocThis->pNext;
5259 } // end while (pocThis)
5260
5261 return pbReturn;
5262}
5263
5264/*
5265 *@@ winhRegisterClass:
5266 * this works just like WinRegisterObjectClass,
5267 * except that it returns a more meaningful
5268 * error code than just FALSE in case registering
5269 * fails.
5270 *
5271 * This returns NO_ERROR if the class was successfully
5272 * registered (WinRegisterObjectClass returned TRUE).
5273 *
5274 * Otherwise, we do a DosLoadModule if maybe the DLL
5275 * couldn't be loaded in the first place. If DosLoadModule
5276 * did not return NO_ERROR, this function returns that
5277 * return code, which can be:
5278 *
5279 * -- 2 ERROR_FILE_NOT_FOUND: pcszModule does not exist
5280 * -- 2 ERROR_FILE_NOT_FOUND
5281 * -- 3 ERROR_PATH_NOT_FOUND
5282 * -- 4 ERROR_TOO_MANY_OPEN_FILES
5283 * -- 5 ERROR_ACCESS_DENIED
5284 * -- 8 ERROR_NOT_ENOUGH_MEMORY
5285 * -- 11 ERROR_BAD_FORMAT
5286 * -- 26 ERROR_NOT_DOS_DISK (unknown media type)
5287 * -- 32 ERROR_SHARING_VIOLATION
5288 * -- 33 ERROR_LOCK_VIOLATION
5289 * -- 36 ERROR_SHARING_BUFFER_EXCEEDED
5290 * -- 95 ERROR_INTERRUPT (interrupted system call)
5291 * -- 108 ERROR_DRIVE_LOCKED (by another process)
5292 * -- 123 ERROR_INVALID_NAME (illegal character or FS name not valid)
5293 * -- 127 ERROR_PROC_NOT_FOUND (DosQueryProcAddr error)
5294 * -- 180 ERROR_INVALID_SEGMENT_NUMBER
5295 * -- 182 ERROR_INVALID_ORDINAL
5296 * -- 190 ERROR_INVALID_MODULETYPE (probably an application)
5297 * -- 191 ERROR_INVALID_EXE_SIGNATURE (probably not LX DLL)
5298 * -- 192 ERROR_EXE_MARKED_INVALID (by linker)
5299 * -- 194 ERROR_ITERATED_DATA_EXCEEDS_64K (in a DLL segment)
5300 * -- 195 ERROR_INVALID_MINALLOCSIZE
5301 * -- 196 ERROR_DYNLINK_FROM_INVALID_RING
5302 * -- 198 ERROR_INVALID_SEGDPL
5303 * -- 199 ERROR_AUTODATASEG_EXCEEDS_64K
5304 * -- 201 ERROR_RELOCSRC_CHAIN_EXCEEDS_SEGLIMIT
5305 * -- 206 ERROR_FILENAME_EXCED_RANGE (not matching 8+3 spec)
5306 * -- 295 ERROR_INIT_ROUTINE_FAILED (DLL init routine failed)
5307 *
5308 * In all these cases, pszBuf may contain a meaningful
5309 * error message from DosLoadModule, especially if an import
5310 * could not be resolved.
5311 *
5312 * Still worse, if DosLoadModule returned NO_ERROR, we
5313 * probably have some SOM internal error. A probable
5314 * reason is that the parent class of pcszClassName
5315 * is not installed, but that's WPS/SOM internal
5316 * and cannot be queried from outside the WPS context.
5317 *
5318 * In that case, ERROR_OPEN_FAILED (110) is returned.
5319 * That one sounded good to me. ;-)
5320 */
5321
5322APIRET winhRegisterClass(const char* pcszClassName, // in: e.g. "XFolder"
5323 const char* pcszModule, // in: e.g. "C:\XFOLDER\XFLDR.DLL"
5324 PSZ pszBuf, // out: error message from DosLoadModule
5325 ULONG cbBuf) // in: sizeof(*pszBuf), passed to DosLoadModule
5326{
5327 APIRET arc = NO_ERROR;
5328
5329 if (!WinRegisterObjectClass((PSZ)pcszClassName, (PSZ)pcszModule))
5330 {
5331 // failed: do more error checking then, try DosLoadModule
5332 HMODULE hmod = NULLHANDLE;
5333 arc = DosLoadModule(pszBuf, cbBuf,
5334 (PSZ)pcszModule,
5335 &hmod);
5336 if (arc == NO_ERROR)
5337 {
5338 // DosLoadModule succeeded:
5339 // some SOM error then
5340 DosFreeModule(hmod);
5341 arc = ERROR_OPEN_FAILED;
5342 }
5343 }
5344 // else: ulrc still 0 (== no error)
5345
5346 return arc;
5347}
5348
5349/*
5350 *@@ winhIsClassRegistered:
5351 * quick one-shot function which checks if
5352 * a class is currently registered. Calls
5353 * winhQueryWPSClassList and winhQueryWPSClass
5354 * in turn.
5355 *
5356 *@@added V0.9.2 (2000-02-26) [umoeller]
5357 */
5358
5359BOOL winhIsClassRegistered(const char *pcszClass)
5360{
5361 BOOL brc = FALSE;
5362 PBYTE pClassList = winhQueryWPSClassList();
5363 if (pClassList)
5364 {
5365 if (winhQueryWPSClass(pClassList, pcszClass))
5366 brc = TRUE;
5367 free(pClassList);
5368 }
5369
5370 return brc;
5371}
5372
5373/*
5374 *@@category: Helpers\PM helpers\Workplace Shell
5375 */
5376
5377/*
5378 *@@ winhResetWPS:
5379 * restarts the WPS using PrfReset. Returns
5380 * one of the following:
5381 *
5382 * -- 0: no error.
5383 * -- 1: PrfReset failed.
5384 * -- 2 or 4: PrfQueryProfile failed.
5385 * -- 3: malloc() failed.
5386 *
5387 *@@added V0.9.4 (2000-07-01) [umoeller]
5388 *@@changed V1.0.5 (2005-02-17) [pr]: replaced this with something less brutal
5389 */
5390
5391ULONG winhResetWPS(HAB hab)
5392{
5393 ULONG ulrc = 0;
5394
5395#if 1
5396 WinRestartWorkplace();
5397#else
5398 // find out current profile names
5399 PRFPROFILE Profiles;
5400 Profiles.cchUserName = Profiles.cchSysName = 0;
5401 // first query their file name lengths
5402 if (PrfQueryProfile(hab, &Profiles))
5403 {
5404 // allocate memory for filenames
5405 Profiles.pszUserName = (PSZ)malloc(Profiles.cchUserName);
5406 Profiles.pszSysName = (PSZ)malloc(Profiles.cchSysName);
5407
5408 if (Profiles.pszSysName)
5409 {
5410 // get filenames
5411 if (PrfQueryProfile(hab, &Profiles))
5412 {
5413
5414 // "change" INIs to these filenames:
5415 // THIS WILL RESET THE WPS
5416 if (PrfReset(hab, &Profiles) == FALSE)
5417 ulrc = 1;
5418 free(Profiles.pszSysName);
5419 free(Profiles.pszUserName);
5420 }
5421 else
5422 ulrc = 2;
5423 }
5424 else
5425 ulrc = 3;
5426 }
5427 else
5428 ulrc = 4;
5429#endif
5430
5431 return ulrc;
5432}
Note: See TracBrowser for help on using the repository browser.