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