Fixed AppTraits handling on OS/2.
[wxWidgets.git] / src / os2 / utilsgui.cpp
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: os2/utilsgui.cpp
3 // Purpose: Various utility functions only available in GUI
4 // Author: David Webster
5 // Modified by:
6 // Created: 20.08.2003 (extracted from os2/utils.cpp)
7 // RCS-ID: $Id$
8 // Copyright: (c) David Webster
9 // License: wxWindows licence
10 ///////////////////////////////////////////////////////////////////////////////
11
12 // ============================================================================
13 // declarations
14 // ============================================================================
15
16 // ----------------------------------------------------------------------------
17 // headers
18 // ----------------------------------------------------------------------------
19
20 // for compilers that support precompilation, includes "wx.h".
21 #include "wx/wxprec.h"
22
23 #ifdef __BORLANDC__
24 #pragma hdrstop
25 #endif
26
27 #ifndef WX_PRECOMP
28 #include "wx/setup.h"
29 #include "wx/utils.h"
30 #include "wx/app.h"
31 #include "wx/cursor.h"
32 #endif //WX_PRECOMP
33
34 #include "wx/os2/private.h" // includes <windows.h>
35
36 // ============================================================================
37 // implementation
38 // ============================================================================
39
40 // ----------------------------------------------------------------------------
41 // functions to work with .INI files
42 // ----------------------------------------------------------------------------
43
44 // Sleep for nSecs seconds. Attempt a Windows implementation using timers.
45 static bool inTimer = FALSE;
46
47 class wxSleepTimer: public wxTimer
48 {
49 public:
50 inline void Notify()
51 {
52 inTimer = FALSE;
53 Stop();
54 }
55 };
56
57 static wxTimer* wxTheSleepTimer = NULL;
58
59 // Reading and writing resources (eg WIN.INI, .Xdefaults)
60 #if wxUSE_RESOURCES
61 bool wxWriteResource(
62 const wxString& rSection
63 , const wxString& rEntry
64 , const wxString& rValue
65 , const wxString& rFile
66 )
67 {
68 HAB hab = 0;
69 HINI hIni = 0;
70
71 if (rFile != "")
72 {
73 hIni = ::PrfOpenProfile(hab, (PSZ)WXSTRINGCAST rFile);
74 if (hIni != 0L)
75 {
76 return (::PrfWriteProfileString( hIni
77 ,(PSZ)WXSTRINGCAST rSection
78 ,(PSZ)WXSTRINGCAST rEntry
79 ,(PSZ)WXSTRINGCAST rValue
80 ));
81 }
82 }
83 else
84 return (::PrfWriteProfileString( HINI_PROFILE
85 ,(PSZ)WXSTRINGCAST rSection
86 ,(PSZ)WXSTRINGCAST rEntry
87 ,(PSZ)WXSTRINGCAST rValue
88 ));
89 return FALSE;
90 }
91
92 bool wxWriteResource(
93 const wxString& rSection
94 , const wxString& rEntry
95 , float fValue
96 , const wxString& rFile
97 )
98 {
99 wxChar zBuf[50];
100
101 wxSprintf(zBuf, "%.4f", fValue);
102 return wxWriteResource( rSection
103 ,rEntry
104 ,zBuf
105 ,rFile
106 );
107 }
108
109 bool wxWriteResource(
110 const wxString& rSection
111 , const wxString& rEntry
112 , long lValue
113 , const wxString& rFile
114 )
115 {
116 wxChar zBuf[50];
117
118 wxSprintf(zBuf, "%ld", lValue);
119 return wxWriteResource( rSection
120 ,rEntry
121 ,zBuf
122 ,rFile
123 );
124 }
125
126 bool wxWriteResource(
127 const wxString& rSection
128 , const wxString& rEntry
129 , int lValue
130 , const wxString& rFile
131 )
132 {
133 wxChar zBuf[50];
134
135 wxSprintf(zBuf, "%d", lValue);
136 return wxWriteResource( rSection
137 ,rEntry
138 ,zBuf
139 ,rFile
140 );
141 }
142
143 bool wxGetResource(
144 const wxString& rSection
145 , const wxString& rEntry
146 , wxChar** ppValue
147 , const wxString& rFile
148 )
149 {
150 HAB hab = 0;
151 HINI hIni = 0;
152 wxChar zDefunkt[] = _T("$$default");
153 char zBuf[1000];
154
155 if (rFile != "")
156 {
157 hIni = ::PrfOpenProfile(hab, (PSZ)WXSTRINGCAST rFile);
158 if (hIni != 0L)
159 {
160 ULONG n = ::PrfQueryProfileString( hIni
161 ,(PSZ)WXSTRINGCAST rSection
162 ,(PSZ)WXSTRINGCAST rEntry
163 ,(PSZ)zDefunkt
164 ,(PVOID)zBuf
165 ,1000
166 );
167 if (zBuf == NULL)
168 return FALSE;
169 if (n == 0L || wxStrcmp(zBuf, zDefunkt) == 0)
170 return FALSE;
171 zBuf[n-1] = '\0';
172 }
173 else
174 return FALSE;
175 }
176 else
177 {
178 ULONG n = ::PrfQueryProfileString( HINI_PROFILE
179 ,(PSZ)WXSTRINGCAST rSection
180 ,(PSZ)WXSTRINGCAST rEntry
181 ,(PSZ)zDefunkt
182 ,(PVOID)zBuf
183 ,1000
184 );
185 if (zBuf == NULL)
186 return FALSE;
187 if (n == 0L || wxStrcmp(zBuf, zDefunkt) == 0)
188 return FALSE;
189 zBuf[n-1] = '\0';
190 }
191 strcpy((char*)*ppValue, zBuf);
192 return TRUE;
193 }
194
195 bool wxGetResource(
196 const wxString& rSection
197 , const wxString& rEntry
198 , float* pValue
199 , const wxString& rFile
200 )
201 {
202 wxChar* zStr = NULL;
203
204 zStr = new wxChar[1000];
205 bool bSucc = wxGetResource( rSection
206 ,rEntry
207 ,(wxChar **)&zStr
208 ,rFile
209 );
210
211 if (bSucc)
212 {
213 *pValue = (float)wxStrtod(zStr, NULL);
214 delete[] zStr;
215 return TRUE;
216 }
217 else
218 {
219 delete[] zStr;
220 return FALSE;
221 }
222 }
223
224 bool wxGetResource(
225 const wxString& rSection
226 , const wxString& rEntry
227 , long* pValue
228 , const wxString& rFile
229 )
230 {
231 wxChar* zStr = NULL;
232
233 zStr = new wxChar[1000];
234 bool bSucc = wxGetResource( rSection
235 ,rEntry
236 ,(wxChar **)&zStr
237 ,rFile
238 );
239
240 if (bSucc)
241 {
242 *pValue = wxStrtol(zStr, NULL, 10);
243 delete[] zStr;
244 return TRUE;
245 }
246 else
247 {
248 delete[] zStr;
249 return FALSE;
250 }
251 }
252
253 bool wxGetResource(
254 const wxString& rSection
255 , const wxString& rEntry
256 , int* pValue
257 , const wxString& rFile
258 )
259 {
260 wxChar* zStr = NULL;
261
262 zStr = new wxChar[1000];
263 bool bSucc = wxGetResource( rSection
264 ,rEntry
265 ,(wxChar **)&zStr
266 ,rFile
267 );
268
269 if (bSucc)
270 {
271 *pValue = (int)wxStrtol(zStr, NULL, 10);
272 delete[] zStr;
273 return TRUE;
274 }
275 else
276 {
277 delete[] zStr;
278 return FALSE;
279 }
280 }
281 #endif // wxUSE_RESOURCES
282
283 // ---------------------------------------------------------------------------
284 // helper functions for showing a "busy" cursor
285 // ---------------------------------------------------------------------------
286
287 HCURSOR gs_wxBusyCursor = 0; // new, busy cursor
288 HCURSOR gs_wxBusyCursorOld = 0; // old cursor
289 static int gs_wxBusyCursorCount = 0;
290
291 // Set the cursor to the busy cursor for all windows
292 void wxBeginBusyCursor(
293 wxCursor* pCursor
294 )
295 {
296 if ( gs_wxBusyCursorCount++ == 0 )
297 {
298 gs_wxBusyCursor = (HCURSOR)pCursor->GetHCURSOR();
299 ::WinSetPointer(HWND_DESKTOP, (HPOINTER)gs_wxBusyCursor);
300 }
301 //else: nothing to do, already set
302 }
303
304 // Restore cursor to normal
305 void wxEndBusyCursor()
306 {
307 wxCHECK_RET( gs_wxBusyCursorCount > 0
308 ,_T("no matching wxBeginBusyCursor() for wxEndBusyCursor()")
309 );
310
311 if (--gs_wxBusyCursorCount == 0)
312 {
313 ::WinSetPointer(HWND_DESKTOP, (HPOINTER)gs_wxBusyCursorOld);
314 gs_wxBusyCursorOld = 0;
315 }
316 }
317
318 // TRUE if we're between the above two calls
319 bool wxIsBusy()
320 {
321 return (gs_wxBusyCursorCount > 0);
322 }
323
324 // Check whether this window wants to process messages, e.g. Stop button
325 // in long calculations.
326 bool wxCheckForInterrupt(
327 wxWindow* pWnd
328 )
329 {
330 if(pWnd)
331 {
332 QMSG vMsg;
333 HAB hab = 0;
334 HWND hwndFilter = NULLHANDLE;
335 HWND hwndWin= (HWND) pWnd->GetHWND();
336
337 while(::WinPeekMsg(hab, &vMsg, hwndFilter, 0, 0, PM_REMOVE))
338 {
339 ::WinDispatchMsg(hab, &vMsg);
340 }
341 return TRUE;//*** temporary?
342 }
343 else
344 {
345 wxFAIL_MSG(_T("pWnd==NULL !!!"));
346 return FALSE;//*** temporary?
347 }
348 }
349
350 // ----------------------------------------------------------------------------
351 // get display info
352 // ----------------------------------------------------------------------------
353
354 // See also the wxGetMousePosition in window.cpp
355 // Deprecated: use wxPoint wxGetMousePosition() instead
356 void wxGetMousePosition(
357 int* pX
358 , int* pY
359 )
360 {
361 POINTL vPt;
362
363 ::WinQueryPointerPos(HWND_DESKTOP, &vPt);
364 *pX = vPt.x;
365 *pY = vPt.y;
366 };
367
368 // Return TRUE if we have a colour display
369 bool wxColourDisplay()
370 {
371 #if 0
372 HPS hpsScreen;
373 HDC hdcScreen;
374 LONG lColors;
375
376 hpsScreen = ::WinGetScreenPS(HWND_DESKTOP);
377 hdcScreen = ::GpiQueryDevice(hpsScreen);
378 ::DevQueryCaps(hdcScreen, CAPS_COLORS, 1L, &lColors);
379 return(lColors > 1L);
380 #else
381 // I don't see how the PM display could not be color. Besides, this
382 // was leaking DCs and PSs!!! MN
383 return TRUE;
384 #endif
385 }
386
387 // Returns depth of screen
388 int wxDisplayDepth()
389 {
390 HPS hpsScreen;
391 HDC hdcScreen;
392 LONG lPlanes;
393 LONG lBitsPerPixel;
394 static LONG nDepth = 0;
395
396 // The screen colordepth ain't gonna change. No reason to query
397 // it over and over!
398 if (!nDepth) {
399 hpsScreen = ::WinGetScreenPS(HWND_DESKTOP);
400 hdcScreen = ::GpiQueryDevice(hpsScreen);
401 ::DevQueryCaps(hdcScreen, CAPS_COLOR_PLANES, 1L, &lPlanes);
402 ::DevQueryCaps(hdcScreen, CAPS_COLOR_BITCOUNT, 1L, &lBitsPerPixel);
403
404 nDepth = (int)(lPlanes * lBitsPerPixel);
405 ::DevCloseDC(hdcScreen);
406 ::WinReleasePS(hpsScreen);
407 }
408 return (nDepth);
409 }
410
411 // Get size of display
412 void wxDisplaySize(
413 int* pWidth
414 , int* pHeight
415 )
416 {
417 HPS hpsScreen;
418 HDC hdcScreen;
419 static LONG lWidth = 0;
420 static LONG lHeight = 0;
421
422 // The screen size ain't gonna change either so just cache the values
423 if (!lWidth) {
424 hpsScreen = ::WinGetScreenPS(HWND_DESKTOP);
425 hdcScreen = ::GpiQueryDevice(hpsScreen);
426 ::DevQueryCaps(hdcScreen, CAPS_WIDTH, 1L, &lWidth);
427 ::DevQueryCaps(hdcScreen, CAPS_HEIGHT, 1L, &lHeight);
428 ::DevCloseDC(hdcScreen);
429 ::WinReleasePS(hpsScreen);
430 }
431 *pWidth = (int)lWidth;
432 *pHeight = (int)lHeight;
433 }
434
435 void wxDisplaySizeMM(
436 int* pWidth
437 , int* pHeight
438 )
439 {
440 HPS hpsScreen;
441 HDC hdcScreen;
442
443 hpsScreen = ::WinGetScreenPS(HWND_DESKTOP);
444 hdcScreen = ::GpiQueryDevice(hpsScreen);
445
446 if (pWidth)
447 ::DevQueryCaps( hdcScreen
448 ,CAPS_HORIZONTAL_RESOLUTION
449 ,1L
450 ,(PLONG)pWidth
451 );
452 if (pHeight)
453 ::DevQueryCaps( hdcScreen
454 ,CAPS_VERTICAL_RESOLUTION
455 ,1L
456 ,(PLONG)pHeight
457 );
458 ::DevCloseDC(hdcScreen);
459 ::WinReleasePS(hpsScreen);
460 }
461
462 void wxClientDisplayRect(int *x, int *y, int *width, int *height)
463 {
464 // This is supposed to return desktop dimensions minus any window
465 // manager panels, menus, taskbars, etc. If there is a way to do that
466 // for this platform please fix this function, otherwise it defaults
467 // to the entire desktop.
468 if (x) *x = 0;
469 if (y) *y = 0;
470 wxDisplaySize(width, height);
471 }
472
473 wxToolkitInfo & wxGUIAppTraits::GetToolkitInfo()
474 {
475 static wxToolkitInfo vInfo;
476 ULONG ulSysInfo[QSV_MAX] = {0};
477 APIRET ulrc;
478
479 vInfo.shortName = _T("PM");
480 vInfo.name = _T("wxOS2");
481 #ifdef __WXUNIVERSAL__
482 vInfo.shortName << _T("univ");
483 vInfo.name << _T("/wxUniversal");
484 #endif
485 ulrc = ::DosQuerySysInfo( 1L
486 ,QSV_MAX
487 ,(PVOID)ulSysInfo
488 ,sizeof(ULONG) * QSV_MAX
489 );
490 if (ulrc == 0L)
491 {
492 vInfo.versionMajor = ulSysInfo[QSV_VERSION_MAJOR] / 10;
493 vInfo.versionMinor = ulSysInfo[QSV_VERSION_MINOR];
494 }
495 vInfo.os = wxOS2_PM;
496 return vInfo;
497 }
498
499 // ---------------------------------------------------------------------------
500 // window information functions
501 // ---------------------------------------------------------------------------
502
503 wxString WXDLLEXPORT wxGetWindowText(
504 WXHWND hWnd
505 )
506 {
507 wxString vStr;
508 long lLen = ::WinQueryWindowTextLength((HWND)hWnd) + 1;
509
510 ::WinQueryWindowText((HWND)hWnd, lLen, vStr.GetWriteBuf((int)lLen));
511 vStr.UngetWriteBuf();
512
513 return vStr;
514 }
515
516 wxString WXDLLEXPORT wxGetWindowClass(
517 WXHWND hWnd
518 )
519 {
520 wxString vStr;
521 int nLen = 256; // some starting value
522
523 for ( ;; )
524 {
525 int nCount = ::WinQueryClassName((HWND)hWnd, nLen, vStr.GetWriteBuf(nLen));
526
527 vStr.UngetWriteBuf();
528 if (nCount == nLen )
529 {
530 // the class name might have been truncated, retry with larger
531 // buffer
532 nLen *= 2;
533 }
534 else
535 {
536 break;
537 }
538 }
539 return vStr;
540 }
541
542 WXWORD WXDLLEXPORT wxGetWindowId(
543 WXHWND hWnd
544 )
545 {
546 return ::WinQueryWindowUShort((HWND)hWnd, QWS_ID);
547 }
548
549 void wxDrawBorder(
550 HPS hPS
551 , RECTL& rRect
552 , WXDWORD dwStyle
553 )
554 {
555 POINTL vPoint[2];
556
557 vPoint[0].x = rRect.xLeft;
558 vPoint[0].y = rRect.yBottom;
559 ::GpiMove(hPS, &vPoint[0]);
560 if (dwStyle & wxSIMPLE_BORDER ||
561 dwStyle & wxSTATIC_BORDER)
562 {
563 vPoint[1].x = rRect.xRight - 1;
564 vPoint[1].y = rRect.yTop - 1;
565 ::GpiBox( hPS
566 ,DRO_OUTLINE
567 ,&vPoint[1]
568 ,0L
569 ,0L
570 );
571 }
572 if (dwStyle & wxSUNKEN_BORDER)
573 {
574 LINEBUNDLE vLineBundle;
575
576 vLineBundle.lColor = 0x00FFFFFF; // WHITE
577 vLineBundle.usMixMode = FM_OVERPAINT;
578 vLineBundle.fxWidth = 2;
579 vLineBundle.lGeomWidth = 2;
580 vLineBundle.usType = LINETYPE_SOLID;
581 vLineBundle.usEnd = 0;
582 vLineBundle.usJoin = 0;
583 ::GpiSetAttrs( hPS
584 ,PRIM_LINE
585 ,LBB_COLOR | LBB_MIX_MODE | LBB_WIDTH | LBB_GEOM_WIDTH | LBB_TYPE
586 ,0L
587 ,&vLineBundle
588 );
589 vPoint[1].x = rRect.xRight - 1;
590 vPoint[1].y = rRect.yTop - 1;
591 ::GpiBox( hPS
592 ,DRO_OUTLINE
593 ,&vPoint[1]
594 ,0L
595 ,0L
596 );
597 vPoint[0].x = rRect.xLeft + 1;
598 vPoint[0].y = rRect.yBottom + 1;
599 ::GpiMove(hPS, &vPoint[0]);
600 vPoint[1].x = rRect.xRight - 2;
601 vPoint[1].y = rRect.yTop - 2;
602 ::GpiBox( hPS
603 ,DRO_OUTLINE
604 ,&vPoint[1]
605 ,0L
606 ,0L
607 );
608
609 vLineBundle.lColor = 0x00000000; // BLACK
610 vLineBundle.usMixMode = FM_OVERPAINT;
611 vLineBundle.fxWidth = 2;
612 vLineBundle.lGeomWidth = 2;
613 vLineBundle.usType = LINETYPE_SOLID;
614 vLineBundle.usEnd = 0;
615 vLineBundle.usJoin = 0;
616 ::GpiSetAttrs( hPS
617 ,PRIM_LINE
618 ,LBB_COLOR | LBB_MIX_MODE | LBB_WIDTH | LBB_GEOM_WIDTH | LBB_TYPE
619 ,0L
620 ,&vLineBundle
621 );
622 vPoint[0].x = rRect.xLeft + 2;
623 vPoint[0].y = rRect.yBottom + 2;
624 ::GpiMove(hPS, &vPoint[0]);
625 vPoint[1].x = rRect.xLeft + 2;
626 vPoint[1].y = rRect.yTop - 3;
627 ::GpiLine(hPS, &vPoint[1]);
628 vPoint[1].x = rRect.xRight - 3;
629 vPoint[1].y = rRect.yTop - 3;
630 ::GpiLine(hPS, &vPoint[1]);
631
632 vPoint[0].x = rRect.xLeft + 3;
633 vPoint[0].y = rRect.yBottom + 3;
634 ::GpiMove(hPS, &vPoint[0]);
635 vPoint[1].x = rRect.xLeft + 3;
636 vPoint[1].y = rRect.yTop - 4;
637 ::GpiLine(hPS, &vPoint[1]);
638 vPoint[1].x = rRect.xRight - 4;
639 vPoint[1].y = rRect.yTop - 4;
640 ::GpiLine(hPS, &vPoint[1]);
641 }
642 if (dwStyle & wxDOUBLE_BORDER)
643 {
644 LINEBUNDLE vLineBundle;
645
646 vLineBundle.lColor = 0x00FFFFFF; // WHITE
647 vLineBundle.usMixMode = FM_OVERPAINT;
648 vLineBundle.fxWidth = 2;
649 vLineBundle.lGeomWidth = 2;
650 vLineBundle.usType = LINETYPE_SOLID;
651 vLineBundle.usEnd = 0;
652 vLineBundle.usJoin = 0;
653 ::GpiSetAttrs( hPS
654 ,PRIM_LINE
655 ,LBB_COLOR | LBB_MIX_MODE | LBB_WIDTH | LBB_GEOM_WIDTH | LBB_TYPE
656 ,0L
657 ,&vLineBundle
658 );
659 vPoint[1].x = rRect.xRight - 1;
660 vPoint[1].y = rRect.yTop - 1;
661 ::GpiBox( hPS
662 ,DRO_OUTLINE
663 ,&vPoint[1]
664 ,0L
665 ,0L
666 );
667 vLineBundle.lColor = 0x00000000; // WHITE
668 vLineBundle.usMixMode = FM_OVERPAINT;
669 vLineBundle.fxWidth = 2;
670 vLineBundle.lGeomWidth = 2;
671 vLineBundle.usType = LINETYPE_SOLID;
672 vLineBundle.usEnd = 0;
673 vLineBundle.usJoin = 0;
674 ::GpiSetAttrs( hPS
675 ,PRIM_LINE
676 ,LBB_COLOR | LBB_MIX_MODE | LBB_WIDTH | LBB_GEOM_WIDTH | LBB_TYPE
677 ,0L
678 ,&vLineBundle
679 );
680 vPoint[0].x = rRect.xLeft + 2;
681 vPoint[0].y = rRect.yBottom + 2;
682 ::GpiMove(hPS, &vPoint[0]);
683 vPoint[1].x = rRect.xRight - 2;
684 vPoint[1].y = rRect.yTop - 2;
685 ::GpiBox( hPS
686 ,DRO_OUTLINE
687 ,&vPoint[1]
688 ,0L
689 ,0L
690 );
691 vLineBundle.lColor = 0x00FFFFFF; // BLACK
692 vLineBundle.usMixMode = FM_OVERPAINT;
693 vLineBundle.fxWidth = 2;
694 vLineBundle.lGeomWidth = 2;
695 vLineBundle.usType = LINETYPE_SOLID;
696 vLineBundle.usEnd = 0;
697 vLineBundle.usJoin = 0;
698 ::GpiSetAttrs( hPS
699 ,PRIM_LINE
700 ,LBB_COLOR | LBB_MIX_MODE | LBB_WIDTH | LBB_GEOM_WIDTH | LBB_TYPE
701 ,0L
702 ,&vLineBundle
703 );
704 vPoint[0].x = rRect.xLeft + 3;
705 vPoint[0].y = rRect.yBottom + 3;
706 ::GpiMove(hPS, &vPoint[0]);
707 vPoint[1].x = rRect.xRight - 3;
708 vPoint[1].y = rRect.yTop - 3;
709 ::GpiBox( hPS
710 ,DRO_OUTLINE
711 ,&vPoint[1]
712 ,0L
713 ,0L
714 );
715 }
716 if (dwStyle & wxRAISED_BORDER)
717 {
718 LINEBUNDLE vLineBundle;
719
720 vLineBundle.lColor = 0x00000000; // BLACK
721 vLineBundle.usMixMode = FM_OVERPAINT;
722 vLineBundle.fxWidth = 2;
723 vLineBundle.lGeomWidth = 2;
724 vLineBundle.usType = LINETYPE_SOLID;
725 vLineBundle.usEnd = 0;
726 vLineBundle.usJoin = 0;
727 ::GpiSetAttrs( hPS
728 ,PRIM_LINE
729 ,LBB_COLOR | LBB_MIX_MODE | LBB_WIDTH | LBB_GEOM_WIDTH | LBB_TYPE
730 ,0L
731 ,&vLineBundle
732 );
733 vPoint[1].x = rRect.xRight - 1;
734 vPoint[1].y = rRect.yTop - 1;
735 ::GpiBox( hPS
736 ,DRO_OUTLINE
737 ,&vPoint[1]
738 ,0L
739 ,0L
740 );
741 vPoint[0].x = rRect.xLeft + 1;
742 vPoint[0].y = rRect.yBottom + 1;
743 ::GpiMove(hPS, &vPoint[0]);
744 vPoint[1].x = rRect.xRight - 2;
745 vPoint[1].y = rRect.yTop - 2;
746 ::GpiBox( hPS
747 ,DRO_OUTLINE
748 ,&vPoint[1]
749 ,0L
750 ,0L
751 );
752
753 vLineBundle.lColor = 0x00FFFFFF; // WHITE
754 vLineBundle.usMixMode = FM_OVERPAINT;
755 vLineBundle.fxWidth = 2;
756 vLineBundle.lGeomWidth = 2;
757 vLineBundle.usType = LINETYPE_SOLID;
758 vLineBundle.usEnd = 0;
759 vLineBundle.usJoin = 0;
760 ::GpiSetAttrs( hPS
761 ,PRIM_LINE
762 ,LBB_COLOR | LBB_MIX_MODE | LBB_WIDTH | LBB_GEOM_WIDTH | LBB_TYPE
763 ,0L
764 ,&vLineBundle
765 );
766 vPoint[0].x = rRect.xLeft + 2;
767 vPoint[0].y = rRect.yBottom + 2;
768 ::GpiMove(hPS, &vPoint[0]);
769 vPoint[1].x = rRect.xLeft + 2;
770 vPoint[1].y = rRect.yTop - 3;
771 ::GpiLine(hPS, &vPoint[1]);
772 vPoint[1].x = rRect.xRight - 3;
773 vPoint[1].y = rRect.yTop - 3;
774 ::GpiLine(hPS, &vPoint[1]);
775
776 vPoint[0].x = rRect.xLeft + 3;
777 vPoint[0].y = rRect.yBottom + 3;
778 ::GpiMove(hPS, &vPoint[0]);
779 vPoint[1].x = rRect.xLeft + 3;
780 vPoint[1].y = rRect.yTop - 4;
781 ::GpiLine(hPS, &vPoint[1]);
782 vPoint[1].x = rRect.xRight - 4;
783 vPoint[1].y = rRect.yTop - 4;
784 ::GpiLine(hPS, &vPoint[1]);
785 }
786 } // end of wxDrawBorder
787
788 void wxOS2SetFont(
789 HWND hWnd
790 , const wxFont& rFont
791 )
792 {
793 char zFont[128];
794 char zFacename[30];
795 char zWeight[30];
796 char zStyle[30];
797
798 if (hWnd == NULLHANDLE)
799 return;
800
801 //
802 // The fonts available for Presentation Params are just a few
803 // outline fonts, the rest are available to the GPI, so we must
804 // map the families to one of these three
805 //
806 switch(rFont.GetFamily())
807 {
808 case wxSCRIPT:
809 strcpy(zFacename, "Script");
810 break;
811
812 case wxDECORATIVE:
813 strcpy(zFacename, "WarpSans");
814 break;
815
816 case wxROMAN:
817 strcpy(zFacename,"Times New Roman");
818 break;
819
820 case wxTELETYPE:
821 strcpy(zFacename, "Courier New");
822 break;
823
824 case wxMODERN:
825 strcpy(zFacename, "Courier New");
826 break;
827
828 case wxDEFAULT:
829 default:
830 case wxSWISS:
831 strcpy(zFacename, "Helvetica");
832 break;
833 }
834
835 switch(rFont.GetWeight())
836 {
837 default:
838 case wxNORMAL:
839 case wxLIGHT:
840 zWeight[0] = '\0';
841 break;
842
843 case wxBOLD:
844 case wxFONTWEIGHT_MAX:
845 strcpy(zWeight, "Bold");
846 break;
847 }
848
849 switch(rFont.GetStyle())
850 {
851 case wxITALIC:
852 case wxSLANT:
853 strcpy(zStyle, "Italic");
854 break;
855
856 default:
857 zStyle[0] = '\0';
858 break;
859 }
860 sprintf(zFont, "%d.%s", rFont.GetPointSize(), zFacename);
861 if (zWeight[0] != '\0')
862 {
863 strcat(zFont, " ");
864 strcat(zFont, zWeight);
865 }
866 if (zStyle[0] != '\0')
867 {
868 strcat(zFont, " ");
869 strcat(zFont, zStyle);
870 }
871 ::WinSetPresParam(hWnd, PP_FONTNAMESIZE, strlen(zFont) + 1, (PVOID)zFont);
872 } // end of wxOS2SetFont
873
874 // ---------------------------------------------------------------------------
875 // Helper for taking a regular bitmap and giving it a disabled look
876 // ---------------------------------------------------------------------------
877 wxBitmap wxDisableBitmap(
878 const wxBitmap& rBmp
879 , long lColor
880 )
881 {
882 wxMask* pMask = rBmp.GetMask();
883
884 if (!pMask)
885 return(wxNullBitmap);
886
887 DEVOPENSTRUC vDop = {0L, "DISPLAY", NULL, 0L, 0L, 0L, 0L, 0L, 0L};
888 SIZEL vSize = {0, 0};
889 HDC hDC = ::DevOpenDC(vHabmain, OD_MEMORY, "*", 5L, (PDEVOPENDATA)&vDop, NULLHANDLE);
890 HPS hPS = ::GpiCreatePS(vHabmain, hDC, &vSize, PU_PELS | GPIA_ASSOC);
891 BITMAPINFOHEADER2 vHeader;
892 BITMAPINFO2 vInfo;
893 ERRORID vError;
894 wxString sError;
895 HBITMAP hBitmap = (HBITMAP)rBmp.GetHBITMAP();
896 HBITMAP hOldBitmap = NULLHANDLE;
897 HBITMAP hOldMask = NULLHANDLE;
898 HBITMAP hMask = (HBITMAP)rBmp.GetMask()->GetMaskBitmap();
899 unsigned char* pucBits; // buffer that will contain the bitmap data
900 unsigned char* pucData; // pointer to use to traverse bitmap data
901 unsigned char* pucBitsMask; // buffer that will contain the mask data
902 unsigned char* pucDataMask; // pointer to use to traverse mask data
903 LONG lScans = 0L;
904 LONG lScansSet = 0L;
905 bool bpp16 = (wxDisplayDepth() == 16);
906
907 memset(&vHeader, '\0', 16);
908 vHeader.cbFix = 16;
909
910 memset(&vInfo, '\0', 16);
911 vInfo.cbFix = 16;
912 vInfo.cx = (ULONG)rBmp.GetWidth();
913 vInfo.cy = (ULONG)rBmp.GetHeight();
914 vInfo.cPlanes = 1;
915 vInfo.cBitCount = 24; // Set to desired count going in
916
917 //
918 // Create the buffers for data....all wxBitmaps are 24 bit internally
919 //
920 int nBytesPerLine = rBmp.GetWidth() * 3;
921 int nSizeDWORD = sizeof(DWORD);
922 int nLineBoundary = nBytesPerLine % nSizeDWORD;
923 int nPadding = 0;
924 int i;
925 int j;
926
927 //
928 // Bitmap must be ina double-word alligned address so we may
929 // have some padding to worry about
930 //
931 if (nLineBoundary > 0)
932 {
933 nPadding = nSizeDWORD - nLineBoundary;
934 nBytesPerLine += nPadding;
935 }
936 pucBits = (unsigned char *)malloc(nBytesPerLine * rBmp.GetHeight());
937 memset(pucBits, '\0', (nBytesPerLine * rBmp.GetHeight()));
938 pucBitsMask = (unsigned char *)malloc(nBytesPerLine * rBmp.GetHeight());
939 memset(pucBitsMask, '\0', (nBytesPerLine * rBmp.GetHeight()));
940
941 //
942 // Extract the bitmap and mask data
943 //
944 if ((hOldBitmap = ::GpiSetBitmap(hPS, hBitmap)) == HBM_ERROR)
945 {
946 vError = ::WinGetLastError(vHabmain);
947 sError = wxPMErrorToStr(vError);
948 }
949 ::GpiQueryBitmapInfoHeader(hBitmap, &vHeader);
950 vInfo.cBitCount = 24;
951 if ((lScans = ::GpiQueryBitmapBits( hPS
952 ,0L
953 ,(LONG)rBmp.GetHeight()
954 ,(PBYTE)pucBits
955 ,&vInfo
956 )) == GPI_ALTERROR)
957 {
958 vError = ::WinGetLastError(vHabmain);
959 sError = wxPMErrorToStr(vError);
960 }
961 if ((hOldMask = ::GpiSetBitmap(hPS, hMask)) == HBM_ERROR)
962 {
963 vError = ::WinGetLastError(vHabmain);
964 sError = wxPMErrorToStr(vError);
965 }
966 ::GpiQueryBitmapInfoHeader(hMask, &vHeader);
967 vInfo.cBitCount = 24;
968 if ((lScans = ::GpiQueryBitmapBits( hPS
969 ,0L
970 ,(LONG)rBmp.GetHeight()
971 ,(PBYTE)pucBitsMask
972 ,&vInfo
973 )) == GPI_ALTERROR)
974 {
975 vError = ::WinGetLastError(vHabmain);
976 sError = wxPMErrorToStr(vError);
977 }
978 if (( hMask = ::GpiSetBitmap(hPS, hOldMask)) == HBM_ERROR)
979 {
980 vError = ::WinGetLastError(vHabmain);
981 sError = wxPMErrorToStr(vError);
982 }
983 pucData = pucBits;
984 pucDataMask = pucBitsMask;
985
986 //
987 // Get the mask value
988 //
989 for (i = 0; i < rBmp.GetHeight(); i++)
990 {
991 for (j = 0; j < rBmp.GetWidth(); j++)
992 {
993 // Byte 1
994 if (bpp16 && *pucDataMask == 0xF8) // 16 bit display gobblygook
995 {
996 *pucData = 0x7F;
997 pucData++;
998 }
999 else if (*pucDataMask == 0xFF) // set to grey
1000 {
1001 *pucData = 0x7F;
1002 pucData++;
1003 }
1004 else
1005 {
1006 *pucData = ((unsigned char)(lColor >> 16));
1007 pucData++;
1008 }
1009
1010 // Byte 2
1011 if (bpp16 && *(pucDataMask + 1) == 0xFC) // 16 bit display gobblygook
1012 {
1013 *pucData = 0x7F;
1014 pucData++;
1015 }
1016 else if (*(pucDataMask + 1) == 0xFF) // set to grey
1017 {
1018 *pucData = 0x7F;
1019 pucData++;
1020 }
1021 else
1022 {
1023 *pucData = ((unsigned char)(lColor >> 8));
1024 pucData++;
1025 }
1026
1027 // Byte 3
1028 if (bpp16 && *(pucDataMask + 2) == 0xF8) // 16 bit display gobblygook
1029 {
1030 *pucData = 0x7F;
1031 pucData++;
1032 }
1033 else if (*(pucDataMask + 2) == 0xFF) // set to grey
1034 {
1035 *pucData = 0x7F;
1036 pucData++;
1037 }
1038 else
1039 {
1040 *pucData = ((unsigned char)lColor);
1041 pucData++;
1042 }
1043 pucDataMask += 3;
1044 }
1045 for (j = 0; j < nPadding; j++)
1046 {
1047 pucData++;
1048 pucDataMask++;
1049 }
1050 }
1051
1052 //
1053 // Create a new bitmap and set the modified bits
1054 //
1055 wxBitmap vNewBmp( rBmp.GetWidth()
1056 ,rBmp.GetHeight()
1057 ,24
1058 );
1059 HBITMAP hNewBmp = (HBITMAP)vNewBmp.GetHBITMAP();
1060
1061 if ((hOldBitmap = ::GpiSetBitmap(hPS, hNewBmp)) == HBM_ERROR)
1062 {
1063 vError = ::WinGetLastError(vHabmain);
1064 sError = wxPMErrorToStr(vError);
1065 }
1066 if ((lScansSet = ::GpiSetBitmapBits( hPS
1067 ,0L
1068 ,(LONG)rBmp.GetHeight()
1069 ,(PBYTE)pucBits
1070 ,&vInfo
1071 )) == GPI_ALTERROR)
1072
1073 {
1074 vError = ::WinGetLastError(vHabmain);
1075 sError = wxPMErrorToStr(vError);
1076 }
1077 wxMask* pNewMask;
1078
1079 pNewMask = new wxMask(pMask->GetMaskBitmap());
1080 vNewBmp.SetMask(pNewMask);
1081 free(pucBits);
1082 ::GpiSetBitmap(hPS, NULLHANDLE);
1083 ::GpiDestroyPS(hPS);
1084 ::DevCloseDC(hDC);
1085 if (vNewBmp.Ok())
1086 return(vNewBmp);
1087 return(wxNullBitmap);
1088 } // end of wxDisableBitmap
1089
1090 COLORREF wxColourToRGB(
1091 const wxColour& rColor
1092 )
1093 {
1094 return(OS2RGB(rColor.Red(), rColor.Green(), rColor.Blue()));
1095 } // end of wxColourToRGB