(blind) build fix
[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 #include "wx/platinfo.h"
36
37 #include "wx/os2/private.h" // includes <windows.h>
38
39 // ============================================================================
40 // implementation
41 // ============================================================================
42
43 // ----------------------------------------------------------------------------
44 // functions to work with .INI files
45 // ----------------------------------------------------------------------------
46
47 // Sleep for nSecs seconds. Attempt a Windows implementation using timers.
48 static bool inTimer = false;
49
50 class wxSleepTimer: public wxTimer
51 {
52 public:
53 inline void Notify()
54 {
55 inTimer = false;
56 Stop();
57 }
58 };
59
60 // Reading and writing resources (eg WIN.INI, .Xdefaults)
61 #if wxUSE_RESOURCES
62 bool wxWriteResource( const wxString& rSection,
63 const wxString& rEntry,
64 const wxString& rValue,
65 const wxString& rFile )
66 {
67 HAB hab = 0;
68 HINI hIni = 0;
69
70 if (!rFile.empty())
71 {
72 hIni = ::PrfOpenProfile(hab, (PSZ)WXSTRINGCAST rFile);
73 if (hIni != 0L)
74 {
75 return (::PrfWriteProfileString( hIni
76 ,(PSZ)WXSTRINGCAST rSection
77 ,(PSZ)WXSTRINGCAST rEntry
78 ,(PSZ)WXSTRINGCAST rValue
79 ));
80 }
81 }
82 else
83 return (::PrfWriteProfileString( HINI_PROFILE
84 ,(PSZ)WXSTRINGCAST rSection
85 ,(PSZ)WXSTRINGCAST rEntry
86 ,(PSZ)WXSTRINGCAST rValue
87 ));
88 return false;
89 }
90
91 bool wxWriteResource(
92 const wxString& rSection
93 , const wxString& rEntry
94 , float fValue
95 , const wxString& rFile
96 )
97 {
98 wxChar zBuf[50];
99
100 wxSprintf(zBuf, "%.4f", fValue);
101 return wxWriteResource( rSection
102 ,rEntry
103 ,zBuf
104 ,rFile
105 );
106 }
107
108 bool wxWriteResource(
109 const wxString& rSection
110 , const wxString& rEntry
111 , long lValue
112 , const wxString& rFile
113 )
114 {
115 wxChar zBuf[50];
116
117 wxSprintf(zBuf, "%ld", lValue);
118 return wxWriteResource( rSection
119 ,rEntry
120 ,zBuf
121 ,rFile
122 );
123 }
124
125 bool wxWriteResource( const wxString& rSection,
126 const wxString& rEntry,
127 int lValue,
128 const wxString& rFile )
129 {
130 wxChar zBuf[50];
131
132 wxSprintf(zBuf, "%d", lValue);
133 return wxWriteResource( rSection, rEntry, zBuf, rFile );
134 }
135
136 bool wxGetResource( const wxString& rSection,
137 const wxString& rEntry,
138 wxChar** ppValue,
139 const wxString& rFile )
140 {
141 HAB hab = 0;
142 HINI hIni = 0;
143 wxChar zDefunkt[] = _T("$$default");
144 char zBuf[1000];
145
146 if (!rFile.empty())
147 {
148 hIni = ::PrfOpenProfile(hab, (PSZ)WXSTRINGCAST rFile);
149 if (hIni != 0L)
150 {
151 ULONG n = ::PrfQueryProfileString( hIni
152 ,(PSZ)WXSTRINGCAST rSection
153 ,(PSZ)WXSTRINGCAST rEntry
154 ,(PSZ)zDefunkt
155 ,(PVOID)zBuf
156 ,1000
157 );
158 if (zBuf == NULL)
159 return false;
160 if (n == 0L || wxStrcmp(zBuf, zDefunkt) == 0)
161 return false;
162 zBuf[n-1] = '\0';
163 }
164 else
165 return false;
166 }
167 else
168 {
169 ULONG n = ::PrfQueryProfileString( HINI_PROFILE
170 ,(PSZ)WXSTRINGCAST rSection
171 ,(PSZ)WXSTRINGCAST rEntry
172 ,(PSZ)zDefunkt
173 ,(PVOID)zBuf
174 ,1000
175 );
176 if (zBuf == NULL)
177 return false;
178 if (n == 0L || wxStrcmp(zBuf, zDefunkt) == 0)
179 return false;
180 zBuf[n-1] = '\0';
181 }
182 strcpy((char*)*ppValue, zBuf);
183 return true;
184 }
185
186 bool wxGetResource( const wxString& rSection,
187 const wxString& rEntry,
188 float* pValue,
189 const wxString& rFile )
190 {
191 wxChar* zStr = NULL;
192
193 zStr = new wxChar[1000];
194 bool bSucc = wxGetResource( rSection, rEntry, (wxChar **)&zStr, rFile );
195
196 if (bSucc)
197 {
198 *pValue = (float)wxStrtod(zStr, NULL);
199 }
200
201 delete[] zStr;
202 return bSucc;
203 }
204
205 bool wxGetResource( const wxString& rSection,
206 const wxString& rEntry,
207 long* pValue,
208 const wxString& rFile )
209 {
210 wxChar* zStr = NULL;
211
212 zStr = new wxChar[1000];
213 bool bSucc = wxGetResource( rSection, rEntry, (wxChar **)&zStr, rFile );
214
215 if (bSucc)
216 {
217 *pValue = wxStrtol(zStr, NULL, 10);
218 }
219
220 delete[] zStr;
221 return bSucc;
222 }
223
224 bool wxGetResource( const wxString& rSection,
225 const wxString& rEntry,
226 int* pValue,
227 const wxString& rFile )
228 {
229 wxChar* zStr = NULL;
230
231 zStr = new wxChar[1000];
232 bool bSucc = wxGetResource( rSection, rEntry, (wxChar **)&zStr, rFile );
233
234 if (bSucc)
235 {
236 *pValue = (int)wxStrtol(zStr, NULL, 10);
237 }
238
239 delete[] zStr;
240 return bSucc;
241 }
242 #endif // wxUSE_RESOURCES
243
244 // ---------------------------------------------------------------------------
245 // helper functions for showing a "busy" cursor
246 // ---------------------------------------------------------------------------
247
248 HCURSOR gs_wxBusyCursor = 0; // new, busy cursor
249 HCURSOR gs_wxBusyCursorOld = 0; // old cursor
250 static int gs_wxBusyCursorCount = 0;
251
252 // Set the cursor to the busy cursor for all windows
253 void wxBeginBusyCursor(const wxCursor* pCursor)
254 {
255 if ( gs_wxBusyCursorCount++ == 0 )
256 {
257 gs_wxBusyCursor = (HCURSOR)pCursor->GetHCURSOR();
258 ::WinSetPointer(HWND_DESKTOP, (HPOINTER)gs_wxBusyCursor);
259 }
260 //else: nothing to do, already set
261 }
262
263 // Restore cursor to normal
264 void wxEndBusyCursor()
265 {
266 wxCHECK_RET( gs_wxBusyCursorCount > 0
267 ,_T("no matching wxBeginBusyCursor() for wxEndBusyCursor()")
268 );
269
270 if (--gs_wxBusyCursorCount == 0)
271 {
272 ::WinSetPointer(HWND_DESKTOP, (HPOINTER)gs_wxBusyCursorOld);
273 gs_wxBusyCursorOld = 0;
274 }
275 }
276
277 // true if we're between the above two calls
278 bool wxIsBusy()
279 {
280 return (gs_wxBusyCursorCount > 0);
281 }
282
283 // Check whether this window wants to process messages, e.g. Stop button
284 // in long calculations.
285 bool wxCheckForInterrupt( wxWindow* pWnd )
286 {
287 if(pWnd)
288 {
289 QMSG vMsg;
290 HAB hab = 0;
291 HWND hwndFilter = NULLHANDLE;
292
293 while(::WinPeekMsg(hab, &vMsg, hwndFilter, 0, 0, PM_REMOVE))
294 {
295 ::WinDispatchMsg(hab, &vMsg);
296 }
297 return true;//*** temporary?
298 }
299 else
300 {
301 wxFAIL_MSG(_T("pWnd==NULL !!!"));
302 return false;//*** temporary?
303 }
304 }
305
306 // ----------------------------------------------------------------------------
307 // get display info
308 // ----------------------------------------------------------------------------
309
310 // See also the wxGetMousePosition in window.cpp
311 // Deprecated: use wxPoint wxGetMousePosition() instead
312 void wxGetMousePosition(
313 int* pX
314 , int* pY
315 )
316 {
317 POINTL vPt;
318
319 ::WinQueryPointerPos(HWND_DESKTOP, &vPt);
320 *pX = vPt.x;
321 *pY = vPt.y;
322 };
323
324 // Return true if we have a colour display
325 bool wxColourDisplay()
326 {
327 #if 0
328 HPS hpsScreen;
329 HDC hdcScreen;
330 LONG lColors;
331
332 hpsScreen = ::WinGetScreenPS(HWND_DESKTOP);
333 hdcScreen = ::GpiQueryDevice(hpsScreen);
334 ::DevQueryCaps(hdcScreen, CAPS_COLORS, 1L, &lColors);
335 return(lColors > 1L);
336 #else
337 // I don't see how the PM display could not be color. Besides, this
338 // was leaking DCs and PSs!!! MN
339 return true;
340 #endif
341 }
342
343 // Returns depth of screen
344 int wxDisplayDepth()
345 {
346 HPS hpsScreen;
347 HDC hdcScreen;
348 LONG lPlanes;
349 LONG lBitsPerPixel;
350 static LONG nDepth = 0;
351
352 // The screen colordepth ain't gonna change. No reason to query
353 // it over and over!
354 if (!nDepth) {
355 hpsScreen = ::WinGetScreenPS(HWND_DESKTOP);
356 hdcScreen = ::GpiQueryDevice(hpsScreen);
357 ::DevQueryCaps(hdcScreen, CAPS_COLOR_PLANES, 1L, &lPlanes);
358 ::DevQueryCaps(hdcScreen, CAPS_COLOR_BITCOUNT, 1L, &lBitsPerPixel);
359
360 nDepth = (int)(lPlanes * lBitsPerPixel);
361 ::DevCloseDC(hdcScreen);
362 ::WinReleasePS(hpsScreen);
363 }
364 return (nDepth);
365 }
366
367 // Get size of display
368 void wxDisplaySize(
369 int* pWidth
370 , int* pHeight
371 )
372 {
373 HPS hpsScreen;
374 HDC hdcScreen;
375 static LONG lWidth = 0;
376 static LONG lHeight = 0;
377
378 // The screen size ain't gonna change either so just cache the values
379 if (!lWidth) {
380 hpsScreen = ::WinGetScreenPS(HWND_DESKTOP);
381 hdcScreen = ::GpiQueryDevice(hpsScreen);
382 ::DevQueryCaps(hdcScreen, CAPS_WIDTH, 1L, &lWidth);
383 ::DevQueryCaps(hdcScreen, CAPS_HEIGHT, 1L, &lHeight);
384 ::DevCloseDC(hdcScreen);
385 ::WinReleasePS(hpsScreen);
386 }
387 if (pWidth)
388 *pWidth = (int)lWidth;
389 if (pHeight)
390 *pHeight = (int)lHeight;
391 }
392
393 void wxDisplaySizeMM(
394 int* pWidth
395 , int* pHeight
396 )
397 {
398 HPS hpsScreen;
399 HDC hdcScreen;
400
401 hpsScreen = ::WinGetScreenPS(HWND_DESKTOP);
402 hdcScreen = ::GpiQueryDevice(hpsScreen);
403
404 if (pWidth)
405 ::DevQueryCaps( hdcScreen
406 ,CAPS_HORIZONTAL_RESOLUTION
407 ,1L
408 ,(PLONG)pWidth
409 );
410 if (pHeight)
411 ::DevQueryCaps( hdcScreen
412 ,CAPS_VERTICAL_RESOLUTION
413 ,1L
414 ,(PLONG)pHeight
415 );
416 ::DevCloseDC(hdcScreen);
417 ::WinReleasePS(hpsScreen);
418 }
419
420 void wxClientDisplayRect(int *x, int *y, int *width, int *height)
421 {
422 // This is supposed to return desktop dimensions minus any window
423 // manager panels, menus, taskbars, etc. If there is a way to do that
424 // for this platform please fix this function, otherwise it defaults
425 // to the entire desktop.
426 if (x) *x = 0;
427 if (y) *y = 0;
428 wxDisplaySize(width, height);
429 }
430
431 void wxGUIAppTraits::InitializeGui(unsigned long &ulHab)
432 {
433 ulHab = ::WinInitialize(0);
434 }
435
436 void wxGUIAppTraits::TerminateGui(unsigned long ulHab)
437 {
438 ::WinTerminate(ulHab);
439 }
440
441 wxPortId wxGUIAppTraits::GetToolkitVersion(int *verMaj, int *verMin) const
442 {
443 // TODO: how to get version of PM ?
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