]> git.saurik.com Git - wxWidgets.git/blob - src/os2/utilsgui.cpp
#include order with correct PCH support.
[wxWidgets.git] / src / os2 / utilsgui.cpp
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: src/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/utils.h"
29 #include "wx/app.h"
30 #include "wx/cursor.h"
31 #endif //WX_PRECOMP
32
33 #include "wx/apptrait.h"
34 #include "wx/timer.h"
35
36 #include "wx/os2/private.h" // includes <windows.h>
37
38 // ============================================================================
39 // implementation
40 // ============================================================================
41
42 // ----------------------------------------------------------------------------
43 // functions to work with .INI files
44 // ----------------------------------------------------------------------------
45
46 // Sleep for nSecs seconds. Attempt a Windows implementation using timers.
47 static bool inTimer = FALSE;
48
49 class wxSleepTimer: public wxTimer
50 {
51 public:
52 inline void Notify()
53 {
54 inTimer = FALSE;
55 Stop();
56 }
57 };
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.empty())
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.empty())
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(const wxCursor* pCursor)
293 {
294 if ( gs_wxBusyCursorCount++ == 0 )
295 {
296 gs_wxBusyCursor = (HCURSOR)pCursor->GetHCURSOR();
297 ::WinSetPointer(HWND_DESKTOP, (HPOINTER)gs_wxBusyCursor);
298 }
299 //else: nothing to do, already set
300 }
301
302 // Restore cursor to normal
303 void wxEndBusyCursor()
304 {
305 wxCHECK_RET( gs_wxBusyCursorCount > 0
306 ,_T("no matching wxBeginBusyCursor() for wxEndBusyCursor()")
307 );
308
309 if (--gs_wxBusyCursorCount == 0)
310 {
311 ::WinSetPointer(HWND_DESKTOP, (HPOINTER)gs_wxBusyCursorOld);
312 gs_wxBusyCursorOld = 0;
313 }
314 }
315
316 // TRUE if we're between the above two calls
317 bool wxIsBusy()
318 {
319 return (gs_wxBusyCursorCount > 0);
320 }
321
322 // Check whether this window wants to process messages, e.g. Stop button
323 // in long calculations.
324 bool wxCheckForInterrupt(
325 wxWindow* pWnd
326 )
327 {
328 if(pWnd)
329 {
330 QMSG vMsg;
331 HAB hab = 0;
332 HWND hwndFilter = NULLHANDLE;
333
334 while(::WinPeekMsg(hab, &vMsg, hwndFilter, 0, 0, PM_REMOVE))
335 {
336 ::WinDispatchMsg(hab, &vMsg);
337 }
338 return TRUE;//*** temporary?
339 }
340 else
341 {
342 wxFAIL_MSG(_T("pWnd==NULL !!!"));
343 return FALSE;//*** temporary?
344 }
345 }
346
347 // ----------------------------------------------------------------------------
348 // get display info
349 // ----------------------------------------------------------------------------
350
351 // See also the wxGetMousePosition in window.cpp
352 // Deprecated: use wxPoint wxGetMousePosition() instead
353 void wxGetMousePosition(
354 int* pX
355 , int* pY
356 )
357 {
358 POINTL vPt;
359
360 ::WinQueryPointerPos(HWND_DESKTOP, &vPt);
361 *pX = vPt.x;
362 *pY = vPt.y;
363 };
364
365 // Return TRUE if we have a colour display
366 bool wxColourDisplay()
367 {
368 #if 0
369 HPS hpsScreen;
370 HDC hdcScreen;
371 LONG lColors;
372
373 hpsScreen = ::WinGetScreenPS(HWND_DESKTOP);
374 hdcScreen = ::GpiQueryDevice(hpsScreen);
375 ::DevQueryCaps(hdcScreen, CAPS_COLORS, 1L, &lColors);
376 return(lColors > 1L);
377 #else
378 // I don't see how the PM display could not be color. Besides, this
379 // was leaking DCs and PSs!!! MN
380 return TRUE;
381 #endif
382 }
383
384 // Returns depth of screen
385 int wxDisplayDepth()
386 {
387 HPS hpsScreen;
388 HDC hdcScreen;
389 LONG lPlanes;
390 LONG lBitsPerPixel;
391 static LONG nDepth = 0;
392
393 // The screen colordepth ain't gonna change. No reason to query
394 // it over and over!
395 if (!nDepth) {
396 hpsScreen = ::WinGetScreenPS(HWND_DESKTOP);
397 hdcScreen = ::GpiQueryDevice(hpsScreen);
398 ::DevQueryCaps(hdcScreen, CAPS_COLOR_PLANES, 1L, &lPlanes);
399 ::DevQueryCaps(hdcScreen, CAPS_COLOR_BITCOUNT, 1L, &lBitsPerPixel);
400
401 nDepth = (int)(lPlanes * lBitsPerPixel);
402 ::DevCloseDC(hdcScreen);
403 ::WinReleasePS(hpsScreen);
404 }
405 return (nDepth);
406 }
407
408 // Get size of display
409 void wxDisplaySize(
410 int* pWidth
411 , int* pHeight
412 )
413 {
414 HPS hpsScreen;
415 HDC hdcScreen;
416 static LONG lWidth = 0;
417 static LONG lHeight = 0;
418
419 // The screen size ain't gonna change either so just cache the values
420 if (!lWidth) {
421 hpsScreen = ::WinGetScreenPS(HWND_DESKTOP);
422 hdcScreen = ::GpiQueryDevice(hpsScreen);
423 ::DevQueryCaps(hdcScreen, CAPS_WIDTH, 1L, &lWidth);
424 ::DevQueryCaps(hdcScreen, CAPS_HEIGHT, 1L, &lHeight);
425 ::DevCloseDC(hdcScreen);
426 ::WinReleasePS(hpsScreen);
427 }
428 if (pWidth)
429 *pWidth = (int)lWidth;
430 if (pHeight)
431 *pHeight = (int)lHeight;
432 }
433
434 void wxDisplaySizeMM(
435 int* pWidth
436 , int* pHeight
437 )
438 {
439 HPS hpsScreen;
440 HDC hdcScreen;
441
442 hpsScreen = ::WinGetScreenPS(HWND_DESKTOP);
443 hdcScreen = ::GpiQueryDevice(hpsScreen);
444
445 if (pWidth)
446 ::DevQueryCaps( hdcScreen
447 ,CAPS_HORIZONTAL_RESOLUTION
448 ,1L
449 ,(PLONG)pWidth
450 );
451 if (pHeight)
452 ::DevQueryCaps( hdcScreen
453 ,CAPS_VERTICAL_RESOLUTION
454 ,1L
455 ,(PLONG)pHeight
456 );
457 ::DevCloseDC(hdcScreen);
458 ::WinReleasePS(hpsScreen);
459 }
460
461 void wxClientDisplayRect(int *x, int *y, int *width, int *height)
462 {
463 // This is supposed to return desktop dimensions minus any window
464 // manager panels, menus, taskbars, etc. If there is a way to do that
465 // for this platform please fix this function, otherwise it defaults
466 // to the entire desktop.
467 if (x) *x = 0;
468 if (y) *y = 0;
469 wxDisplaySize(width, height);
470 }
471
472 void wxGUIAppTraits::InitializeGui(unsigned long &ulHab)
473 {
474 ulHab = ::WinInitialize(0);
475 }
476
477 void wxGUIAppTraits::TerminateGui(unsigned long ulHab)
478 {
479 ::WinTerminate(ulHab);
480 }
481
482 wxToolkitInfo & wxGUIAppTraits::GetToolkitInfo()
483 {
484 static wxToolkitInfo vInfo;
485 ULONG ulSysInfo[QSV_MAX] = {0};
486 APIRET ulrc;
487
488 vInfo.shortName = _T("PM");
489 vInfo.name = _T("wxOS2");
490 #ifdef __WXUNIVERSAL__
491 vInfo.shortName << _T("univ");
492 vInfo.name << _T("/wxUniversal");
493 #endif
494 ulrc = ::DosQuerySysInfo( 1L
495 ,QSV_MAX
496 ,(PVOID)ulSysInfo
497 ,sizeof(ULONG) * QSV_MAX
498 );
499 if (ulrc == 0L)
500 {
501 vInfo.versionMajor = ulSysInfo[QSV_VERSION_MAJOR] / 10;
502 vInfo.versionMinor = ulSysInfo[QSV_VERSION_MINOR];
503 }
504 vInfo.os = wxOS2_PM;
505 return vInfo;
506 }
507
508 // ---------------------------------------------------------------------------
509 // window information functions
510 // ---------------------------------------------------------------------------
511
512 wxString WXDLLEXPORT wxGetWindowText( WXHWND hWnd )
513 {
514 wxString vStr;
515
516 if ( hWnd )
517 {
518 long lLen = ::WinQueryWindowTextLength((HWND)hWnd) + 1;
519 ::WinQueryWindowText((HWND)hWnd, lLen, (PSZ)(wxChar*)wxStringBuffer(vStr, lLen));
520 }
521
522 return vStr;
523 }
524
525 wxString WXDLLEXPORT wxGetWindowClass( WXHWND hWnd )
526 {
527 wxString vStr;
528 if ( hWnd )
529 {
530 int nLen = 256; // some starting value
531
532 for ( ;; )
533 {
534 int nCount = ::WinQueryClassName((HWND)hWnd, nLen, (PSZ)(wxChar*)wxStringBuffer(vStr, nLen));
535
536 if (nCount == nLen )
537 {
538 // the class name might have been truncated, retry with larger
539 // buffer
540 nLen *= 2;
541 }
542 else
543 {
544 break;
545 }
546 }
547 }
548 return vStr;
549 }
550
551 WXWORD WXDLLEXPORT wxGetWindowId(
552 WXHWND hWnd
553 )
554 {
555 return ::WinQueryWindowUShort((HWND)hWnd, QWS_ID);
556 }
557
558 void wxDrawBorder(
559 HPS hPS
560 , RECTL& rRect
561 , WXDWORD dwStyle
562 )
563 {
564 POINTL vPoint[2];
565
566 vPoint[0].x = rRect.xLeft;
567 vPoint[0].y = rRect.yBottom;
568 ::GpiMove(hPS, &vPoint[0]);
569 if (dwStyle & wxSIMPLE_BORDER ||
570 dwStyle & wxSTATIC_BORDER)
571 {
572 vPoint[1].x = rRect.xRight - 1;
573 vPoint[1].y = rRect.yTop - 1;
574 ::GpiBox( hPS
575 ,DRO_OUTLINE
576 ,&vPoint[1]
577 ,0L
578 ,0L
579 );
580 }
581 if (dwStyle & wxSUNKEN_BORDER)
582 {
583 LINEBUNDLE vLineBundle;
584
585 vLineBundle.lColor = 0x00FFFFFF; // WHITE
586 vLineBundle.usMixMode = FM_OVERPAINT;
587 vLineBundle.fxWidth = 2;
588 vLineBundle.lGeomWidth = 2;
589 vLineBundle.usType = LINETYPE_SOLID;
590 vLineBundle.usEnd = 0;
591 vLineBundle.usJoin = 0;
592 ::GpiSetAttrs( hPS
593 ,PRIM_LINE
594 ,LBB_COLOR | LBB_MIX_MODE | LBB_WIDTH | LBB_GEOM_WIDTH | LBB_TYPE
595 ,0L
596 ,&vLineBundle
597 );
598 vPoint[1].x = rRect.xRight - 1;
599 vPoint[1].y = rRect.yTop - 1;
600 ::GpiBox( hPS
601 ,DRO_OUTLINE
602 ,&vPoint[1]
603 ,0L
604 ,0L
605 );
606 vPoint[0].x = rRect.xLeft + 1;
607 vPoint[0].y = rRect.yBottom + 1;
608 ::GpiMove(hPS, &vPoint[0]);
609 vPoint[1].x = rRect.xRight - 2;
610 vPoint[1].y = rRect.yTop - 2;
611 ::GpiBox( hPS
612 ,DRO_OUTLINE
613 ,&vPoint[1]
614 ,0L
615 ,0L
616 );
617
618 vLineBundle.lColor = 0x00000000; // BLACK
619 vLineBundle.usMixMode = FM_OVERPAINT;
620 vLineBundle.fxWidth = 2;
621 vLineBundle.lGeomWidth = 2;
622 vLineBundle.usType = LINETYPE_SOLID;
623 vLineBundle.usEnd = 0;
624 vLineBundle.usJoin = 0;
625 ::GpiSetAttrs( hPS
626 ,PRIM_LINE
627 ,LBB_COLOR | LBB_MIX_MODE | LBB_WIDTH | LBB_GEOM_WIDTH | LBB_TYPE
628 ,0L
629 ,&vLineBundle
630 );
631 vPoint[0].x = rRect.xLeft + 2;
632 vPoint[0].y = rRect.yBottom + 2;
633 ::GpiMove(hPS, &vPoint[0]);
634 vPoint[1].x = rRect.xLeft + 2;
635 vPoint[1].y = rRect.yTop - 3;
636 ::GpiLine(hPS, &vPoint[1]);
637 vPoint[1].x = rRect.xRight - 3;
638 vPoint[1].y = rRect.yTop - 3;
639 ::GpiLine(hPS, &vPoint[1]);
640
641 vPoint[0].x = rRect.xLeft + 3;
642 vPoint[0].y = rRect.yBottom + 3;
643 ::GpiMove(hPS, &vPoint[0]);
644 vPoint[1].x = rRect.xLeft + 3;
645 vPoint[1].y = rRect.yTop - 4;
646 ::GpiLine(hPS, &vPoint[1]);
647 vPoint[1].x = rRect.xRight - 4;
648 vPoint[1].y = rRect.yTop - 4;
649 ::GpiLine(hPS, &vPoint[1]);
650 }
651 if (dwStyle & wxDOUBLE_BORDER)
652 {
653 LINEBUNDLE vLineBundle;
654
655 vLineBundle.lColor = 0x00FFFFFF; // WHITE
656 vLineBundle.usMixMode = FM_OVERPAINT;
657 vLineBundle.fxWidth = 2;
658 vLineBundle.lGeomWidth = 2;
659 vLineBundle.usType = LINETYPE_SOLID;
660 vLineBundle.usEnd = 0;
661 vLineBundle.usJoin = 0;
662 ::GpiSetAttrs( hPS
663 ,PRIM_LINE
664 ,LBB_COLOR | LBB_MIX_MODE | LBB_WIDTH | LBB_GEOM_WIDTH | LBB_TYPE
665 ,0L
666 ,&vLineBundle
667 );
668 vPoint[1].x = rRect.xRight - 1;
669 vPoint[1].y = rRect.yTop - 1;
670 ::GpiBox( hPS
671 ,DRO_OUTLINE
672 ,&vPoint[1]
673 ,0L
674 ,0L
675 );
676 vLineBundle.lColor = 0x00000000; // WHITE
677 vLineBundle.usMixMode = FM_OVERPAINT;
678 vLineBundle.fxWidth = 2;
679 vLineBundle.lGeomWidth = 2;
680 vLineBundle.usType = LINETYPE_SOLID;
681 vLineBundle.usEnd = 0;
682 vLineBundle.usJoin = 0;
683 ::GpiSetAttrs( hPS
684 ,PRIM_LINE
685 ,LBB_COLOR | LBB_MIX_MODE | LBB_WIDTH | LBB_GEOM_WIDTH | LBB_TYPE
686 ,0L
687 ,&vLineBundle
688 );
689 vPoint[0].x = rRect.xLeft + 2;
690 vPoint[0].y = rRect.yBottom + 2;
691 ::GpiMove(hPS, &vPoint[0]);
692 vPoint[1].x = rRect.xRight - 2;
693 vPoint[1].y = rRect.yTop - 2;
694 ::GpiBox( hPS
695 ,DRO_OUTLINE
696 ,&vPoint[1]
697 ,0L
698 ,0L
699 );
700 vLineBundle.lColor = 0x00FFFFFF; // BLACK
701 vLineBundle.usMixMode = FM_OVERPAINT;
702 vLineBundle.fxWidth = 2;
703 vLineBundle.lGeomWidth = 2;
704 vLineBundle.usType = LINETYPE_SOLID;
705 vLineBundle.usEnd = 0;
706 vLineBundle.usJoin = 0;
707 ::GpiSetAttrs( hPS
708 ,PRIM_LINE
709 ,LBB_COLOR | LBB_MIX_MODE | LBB_WIDTH | LBB_GEOM_WIDTH | LBB_TYPE
710 ,0L
711 ,&vLineBundle
712 );
713 vPoint[0].x = rRect.xLeft + 3;
714 vPoint[0].y = rRect.yBottom + 3;
715 ::GpiMove(hPS, &vPoint[0]);
716 vPoint[1].x = rRect.xRight - 3;
717 vPoint[1].y = rRect.yTop - 3;
718 ::GpiBox( hPS
719 ,DRO_OUTLINE
720 ,&vPoint[1]
721 ,0L
722 ,0L
723 );
724 }
725 if (dwStyle & wxRAISED_BORDER)
726 {
727 LINEBUNDLE vLineBundle;
728
729 vLineBundle.lColor = 0x00000000; // BLACK
730 vLineBundle.usMixMode = FM_OVERPAINT;
731 vLineBundle.fxWidth = 2;
732 vLineBundle.lGeomWidth = 2;
733 vLineBundle.usType = LINETYPE_SOLID;
734 vLineBundle.usEnd = 0;
735 vLineBundle.usJoin = 0;
736 ::GpiSetAttrs( hPS
737 ,PRIM_LINE
738 ,LBB_COLOR | LBB_MIX_MODE | LBB_WIDTH | LBB_GEOM_WIDTH | LBB_TYPE
739 ,0L
740 ,&vLineBundle
741 );
742 vPoint[1].x = rRect.xRight - 1;
743 vPoint[1].y = rRect.yTop - 1;
744 ::GpiBox( hPS
745 ,DRO_OUTLINE
746 ,&vPoint[1]
747 ,0L
748 ,0L
749 );
750 vPoint[0].x = rRect.xLeft + 1;
751 vPoint[0].y = rRect.yBottom + 1;
752 ::GpiMove(hPS, &vPoint[0]);
753 vPoint[1].x = rRect.xRight - 2;
754 vPoint[1].y = rRect.yTop - 2;
755 ::GpiBox( hPS
756 ,DRO_OUTLINE
757 ,&vPoint[1]
758 ,0L
759 ,0L
760 );
761
762 vLineBundle.lColor = 0x00FFFFFF; // WHITE
763 vLineBundle.usMixMode = FM_OVERPAINT;
764 vLineBundle.fxWidth = 2;
765 vLineBundle.lGeomWidth = 2;
766 vLineBundle.usType = LINETYPE_SOLID;
767 vLineBundle.usEnd = 0;
768 vLineBundle.usJoin = 0;
769 ::GpiSetAttrs( hPS
770 ,PRIM_LINE
771 ,LBB_COLOR | LBB_MIX_MODE | LBB_WIDTH | LBB_GEOM_WIDTH | LBB_TYPE
772 ,0L
773 ,&vLineBundle
774 );
775 vPoint[0].x = rRect.xLeft + 2;
776 vPoint[0].y = rRect.yBottom + 2;
777 ::GpiMove(hPS, &vPoint[0]);
778 vPoint[1].x = rRect.xLeft + 2;
779 vPoint[1].y = rRect.yTop - 3;
780 ::GpiLine(hPS, &vPoint[1]);
781 vPoint[1].x = rRect.xRight - 3;
782 vPoint[1].y = rRect.yTop - 3;
783 ::GpiLine(hPS, &vPoint[1]);
784
785 vPoint[0].x = rRect.xLeft + 3;
786 vPoint[0].y = rRect.yBottom + 3;
787 ::GpiMove(hPS, &vPoint[0]);
788 vPoint[1].x = rRect.xLeft + 3;
789 vPoint[1].y = rRect.yTop - 4;
790 ::GpiLine(hPS, &vPoint[1]);
791 vPoint[1].x = rRect.xRight - 4;
792 vPoint[1].y = rRect.yTop - 4;
793 ::GpiLine(hPS, &vPoint[1]);
794 }
795 } // end of wxDrawBorder
796
797 void wxOS2SetFont(
798 HWND hWnd
799 , const wxFont& rFont
800 )
801 {
802 char zFont[128];
803 char zFacename[30];
804 char zWeight[30];
805 char zStyle[30];
806
807 if (hWnd == NULLHANDLE)
808 return;
809
810 //
811 // The fonts available for Presentation Params are just a few
812 // outline fonts, the rest are available to the GPI, so we must
813 // map the families to one of these three
814 //
815 switch(rFont.GetFamily())
816 {
817 case wxSCRIPT:
818 strcpy(zFacename, "Script");
819 break;
820
821 case wxDECORATIVE:
822 strcpy(zFacename, "WarpSans");
823 break;
824
825 case wxROMAN:
826 strcpy(zFacename,"Times New Roman");
827 break;
828
829 case wxTELETYPE:
830 strcpy(zFacename, "Courier New");
831 break;
832
833 case wxMODERN:
834 strcpy(zFacename, "Courier New");
835 break;
836
837 case wxDEFAULT:
838 default:
839 case wxSWISS:
840 strcpy(zFacename, "Helvetica");
841 break;
842 }
843
844 switch(rFont.GetWeight())
845 {
846 default:
847 case wxNORMAL:
848 case wxLIGHT:
849 zWeight[0] = '\0';
850 break;
851
852 case wxBOLD:
853 case wxFONTWEIGHT_MAX:
854 strcpy(zWeight, "Bold");
855 break;
856 }
857
858 switch(rFont.GetStyle())
859 {
860 case wxITALIC:
861 case wxSLANT:
862 strcpy(zStyle, "Italic");
863 break;
864
865 default:
866 zStyle[0] = '\0';
867 break;
868 }
869 sprintf(zFont, "%d.%s", rFont.GetPointSize(), zFacename);
870 if (zWeight[0] != '\0')
871 {
872 strcat(zFont, " ");
873 strcat(zFont, zWeight);
874 }
875 if (zStyle[0] != '\0')
876 {
877 strcat(zFont, " ");
878 strcat(zFont, zStyle);
879 }
880 ::WinSetPresParam(hWnd, PP_FONTNAMESIZE, strlen(zFont) + 1, (PVOID)zFont);
881 } // end of wxOS2SetFont
882
883 // ---------------------------------------------------------------------------
884 // Helper for taking a regular bitmap and giving it a disabled look
885 // ---------------------------------------------------------------------------
886 wxBitmap wxDisableBitmap(
887 const wxBitmap& rBmp
888 , long lColor
889 )
890 {
891 wxMask* pMask = rBmp.GetMask();
892
893 if (!pMask)
894 return(wxNullBitmap);
895
896 DEVOPENSTRUC vDop = {0L, "DISPLAY", NULL, 0L, 0L, 0L, 0L, 0L, 0L};
897 SIZEL vSize = {0, 0};
898 HDC hDC = ::DevOpenDC(vHabmain, OD_MEMORY, "*", 5L, (PDEVOPENDATA)&vDop, NULLHANDLE);
899 HPS hPS = ::GpiCreatePS(vHabmain, hDC, &vSize, PU_PELS | GPIA_ASSOC);
900 BITMAPINFOHEADER2 vHeader;
901 BITMAPINFO2 vInfo;
902 ERRORID vError;
903 wxString sError;
904 HBITMAP hBitmap = (HBITMAP)rBmp.GetHBITMAP();
905 HBITMAP hOldBitmap = NULLHANDLE;
906 HBITMAP hOldMask = NULLHANDLE;
907 HBITMAP hMask = (HBITMAP)rBmp.GetMask()->GetMaskBitmap();
908 unsigned char* pucBits; // buffer that will contain the bitmap data
909 unsigned char* pucData; // pointer to use to traverse bitmap data
910 unsigned char* pucBitsMask; // buffer that will contain the mask data
911 unsigned char* pucDataMask; // pointer to use to traverse mask data
912 LONG lScans = 0L;
913 LONG lScansSet = 0L;
914 bool bpp16 = (wxDisplayDepth() == 16);
915
916 memset(&vHeader, '\0', 16);
917 vHeader.cbFix = 16;
918
919 memset(&vInfo, '\0', 16);
920 vInfo.cbFix = 16;
921 vInfo.cx = (ULONG)rBmp.GetWidth();
922 vInfo.cy = (ULONG)rBmp.GetHeight();
923 vInfo.cPlanes = 1;
924 vInfo.cBitCount = 24; // Set to desired count going in
925
926 //
927 // Create the buffers for data....all wxBitmaps are 24 bit internally
928 //
929 int nBytesPerLine = rBmp.GetWidth() * 3;
930 int nSizeDWORD = sizeof(DWORD);
931 int nLineBoundary = nBytesPerLine % nSizeDWORD;
932 int nPadding = 0;
933 int i;
934 int j;
935
936 //
937 // Bitmap must be in a double-word aligned address so we may
938 // have some padding to worry about
939 //
940 if (nLineBoundary > 0)
941 {
942 nPadding = nSizeDWORD - nLineBoundary;
943 nBytesPerLine += nPadding;
944 }
945 pucBits = (unsigned char *)malloc(nBytesPerLine * rBmp.GetHeight());
946 memset(pucBits, '\0', (nBytesPerLine * rBmp.GetHeight()));
947 pucBitsMask = (unsigned char *)malloc(nBytesPerLine * rBmp.GetHeight());
948 memset(pucBitsMask, '\0', (nBytesPerLine * rBmp.GetHeight()));
949
950 //
951 // Extract the bitmap and mask data
952 //
953 if ((hOldBitmap = ::GpiSetBitmap(hPS, hBitmap)) == HBM_ERROR)
954 {
955 vError = ::WinGetLastError(vHabmain);
956 sError = wxPMErrorToStr(vError);
957 }
958 ::GpiQueryBitmapInfoHeader(hBitmap, &vHeader);
959 vInfo.cBitCount = 24;
960 if ((lScans = ::GpiQueryBitmapBits( hPS
961 ,0L
962 ,(LONG)rBmp.GetHeight()
963 ,(PBYTE)pucBits
964 ,&vInfo
965 )) == GPI_ALTERROR)
966 {
967 vError = ::WinGetLastError(vHabmain);
968 sError = wxPMErrorToStr(vError);
969 }
970 if ((hOldMask = ::GpiSetBitmap(hPS, hMask)) == HBM_ERROR)
971 {
972 vError = ::WinGetLastError(vHabmain);
973 sError = wxPMErrorToStr(vError);
974 }
975 ::GpiQueryBitmapInfoHeader(hMask, &vHeader);
976 vInfo.cBitCount = 24;
977 if ((lScans = ::GpiQueryBitmapBits( hPS
978 ,0L
979 ,(LONG)rBmp.GetHeight()
980 ,(PBYTE)pucBitsMask
981 ,&vInfo
982 )) == GPI_ALTERROR)
983 {
984 vError = ::WinGetLastError(vHabmain);
985 sError = wxPMErrorToStr(vError);
986 }
987 if (( hMask = ::GpiSetBitmap(hPS, hOldMask)) == HBM_ERROR)
988 {
989 vError = ::WinGetLastError(vHabmain);
990 sError = wxPMErrorToStr(vError);
991 }
992 pucData = pucBits;
993 pucDataMask = pucBitsMask;
994
995 //
996 // Get the mask value
997 //
998 for (i = 0; i < rBmp.GetHeight(); i++)
999 {
1000 for (j = 0; j < rBmp.GetWidth(); j++)
1001 {
1002 // Byte 1
1003 if (bpp16 && *pucDataMask == 0xF8) // 16 bit display gobblygook
1004 {
1005 *pucData = 0x7F;
1006 pucData++;
1007 }
1008 else if (*pucDataMask == 0xFF) // set to grey
1009 {
1010 *pucData = 0x7F;
1011 pucData++;
1012 }
1013 else
1014 {
1015 *pucData = ((unsigned char)(lColor >> 16));
1016 pucData++;
1017 }
1018
1019 // Byte 2
1020 if (bpp16 && *(pucDataMask + 1) == 0xFC) // 16 bit display gobblygook
1021 {
1022 *pucData = 0x7F;
1023 pucData++;
1024 }
1025 else if (*(pucDataMask + 1) == 0xFF) // set to grey
1026 {
1027 *pucData = 0x7F;
1028 pucData++;
1029 }
1030 else
1031 {
1032 *pucData = ((unsigned char)(lColor >> 8));
1033 pucData++;
1034 }
1035
1036 // Byte 3
1037 if (bpp16 && *(pucDataMask + 2) == 0xF8) // 16 bit display gobblygook
1038 {
1039 *pucData = 0x7F;
1040 pucData++;
1041 }
1042 else if (*(pucDataMask + 2) == 0xFF) // set to grey
1043 {
1044 *pucData = 0x7F;
1045 pucData++;
1046 }
1047 else
1048 {
1049 *pucData = ((unsigned char)lColor);
1050 pucData++;
1051 }
1052 pucDataMask += 3;
1053 }
1054 for (j = 0; j < nPadding; j++)
1055 {
1056 pucData++;
1057 pucDataMask++;
1058 }
1059 }
1060
1061 //
1062 // Create a new bitmap and set the modified bits
1063 //
1064 wxBitmap vNewBmp( rBmp.GetWidth()
1065 ,rBmp.GetHeight()
1066 ,24
1067 );
1068 HBITMAP hNewBmp = (HBITMAP)vNewBmp.GetHBITMAP();
1069
1070 if ((hOldBitmap = ::GpiSetBitmap(hPS, hNewBmp)) == HBM_ERROR)
1071 {
1072 vError = ::WinGetLastError(vHabmain);
1073 sError = wxPMErrorToStr(vError);
1074 }
1075 if ((lScansSet = ::GpiSetBitmapBits( hPS
1076 ,0L
1077 ,(LONG)rBmp.GetHeight()
1078 ,(PBYTE)pucBits
1079 ,&vInfo
1080 )) == GPI_ALTERROR)
1081
1082 {
1083 vError = ::WinGetLastError(vHabmain);
1084 sError = wxPMErrorToStr(vError);
1085 }
1086 wxMask* pNewMask;
1087
1088 pNewMask = new wxMask(pMask->GetMaskBitmap());
1089 vNewBmp.SetMask(pNewMask);
1090 free(pucBits);
1091 ::GpiSetBitmap(hPS, NULLHANDLE);
1092 ::GpiDestroyPS(hPS);
1093 ::DevCloseDC(hDC);
1094 if (vNewBmp.Ok())
1095 return(vNewBmp);
1096 return(wxNullBitmap);
1097 } // end of wxDisableBitmap
1098
1099 COLORREF wxColourToRGB(
1100 const wxColour& rColor
1101 )
1102 {
1103 return(OS2RGB(rColor.Red(), rColor.Green(), rColor.Blue()));
1104 } // end of wxColourToRGB