]> git.saurik.com Git - wxWidgets.git/blob - src/os2/utilsgui.cpp
moved all wxDialog event handlers to wxDialogBase to avoid code duplication
[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 // TODO: how to get version of PM ?
443 return wxPORT_OS2;
444 }
445
446
447 // ---------------------------------------------------------------------------
448 // window information functions
449 // ---------------------------------------------------------------------------
450
451 wxString WXDLLEXPORT wxGetWindowText( WXHWND hWnd )
452 {
453 wxString vStr;
454
455 if ( hWnd )
456 {
457 long lLen = ::WinQueryWindowTextLength((HWND)hWnd) + 1;
458 ::WinQueryWindowText((HWND)hWnd, lLen, (PSZ)(wxChar*)wxStringBuffer(vStr, lLen));
459 }
460
461 return vStr;
462 }
463
464 wxString WXDLLEXPORT wxGetWindowClass( WXHWND hWnd )
465 {
466 wxString vStr;
467 if ( hWnd )
468 {
469 int nLen = 256; // some starting value
470
471 for ( ;; )
472 {
473 int nCount = ::WinQueryClassName((HWND)hWnd, nLen, (PSZ)(wxChar*)wxStringBuffer(vStr, nLen));
474
475 if (nCount == nLen )
476 {
477 // the class name might have been truncated, retry with larger
478 // buffer
479 nLen *= 2;
480 }
481 else
482 {
483 break;
484 }
485 }
486 }
487 return vStr;
488 }
489
490 WXWORD WXDLLEXPORT wxGetWindowId(
491 WXHWND hWnd
492 )
493 {
494 return ::WinQueryWindowUShort((HWND)hWnd, QWS_ID);
495 }
496
497 void wxDrawBorder(
498 HPS hPS
499 , RECTL& rRect
500 , WXDWORD dwStyle
501 )
502 {
503 POINTL vPoint[2];
504
505 vPoint[0].x = rRect.xLeft;
506 vPoint[0].y = rRect.yBottom;
507 ::GpiMove(hPS, &vPoint[0]);
508 if (dwStyle & wxSIMPLE_BORDER ||
509 dwStyle & wxSTATIC_BORDER)
510 {
511 vPoint[1].x = rRect.xRight - 1;
512 vPoint[1].y = rRect.yTop - 1;
513 ::GpiBox( hPS
514 ,DRO_OUTLINE
515 ,&vPoint[1]
516 ,0L
517 ,0L
518 );
519 }
520 if (dwStyle & wxSUNKEN_BORDER)
521 {
522 LINEBUNDLE vLineBundle;
523
524 vLineBundle.lColor = 0x00FFFFFF; // WHITE
525 vLineBundle.usMixMode = FM_OVERPAINT;
526 vLineBundle.fxWidth = 2;
527 vLineBundle.lGeomWidth = 2;
528 vLineBundle.usType = LINETYPE_SOLID;
529 vLineBundle.usEnd = 0;
530 vLineBundle.usJoin = 0;
531 ::GpiSetAttrs( hPS
532 ,PRIM_LINE
533 ,LBB_COLOR | LBB_MIX_MODE | LBB_WIDTH | LBB_GEOM_WIDTH | LBB_TYPE
534 ,0L
535 ,&vLineBundle
536 );
537 vPoint[1].x = rRect.xRight - 1;
538 vPoint[1].y = rRect.yTop - 1;
539 ::GpiBox( hPS
540 ,DRO_OUTLINE
541 ,&vPoint[1]
542 ,0L
543 ,0L
544 );
545 vPoint[0].x = rRect.xLeft + 1;
546 vPoint[0].y = rRect.yBottom + 1;
547 ::GpiMove(hPS, &vPoint[0]);
548 vPoint[1].x = rRect.xRight - 2;
549 vPoint[1].y = rRect.yTop - 2;
550 ::GpiBox( hPS
551 ,DRO_OUTLINE
552 ,&vPoint[1]
553 ,0L
554 ,0L
555 );
556
557 vLineBundle.lColor = 0x00000000; // BLACK
558 vLineBundle.usMixMode = FM_OVERPAINT;
559 vLineBundle.fxWidth = 2;
560 vLineBundle.lGeomWidth = 2;
561 vLineBundle.usType = LINETYPE_SOLID;
562 vLineBundle.usEnd = 0;
563 vLineBundle.usJoin = 0;
564 ::GpiSetAttrs( hPS
565 ,PRIM_LINE
566 ,LBB_COLOR | LBB_MIX_MODE | LBB_WIDTH | LBB_GEOM_WIDTH | LBB_TYPE
567 ,0L
568 ,&vLineBundle
569 );
570 vPoint[0].x = rRect.xLeft + 2;
571 vPoint[0].y = rRect.yBottom + 2;
572 ::GpiMove(hPS, &vPoint[0]);
573 vPoint[1].x = rRect.xLeft + 2;
574 vPoint[1].y = rRect.yTop - 3;
575 ::GpiLine(hPS, &vPoint[1]);
576 vPoint[1].x = rRect.xRight - 3;
577 vPoint[1].y = rRect.yTop - 3;
578 ::GpiLine(hPS, &vPoint[1]);
579
580 vPoint[0].x = rRect.xLeft + 3;
581 vPoint[0].y = rRect.yBottom + 3;
582 ::GpiMove(hPS, &vPoint[0]);
583 vPoint[1].x = rRect.xLeft + 3;
584 vPoint[1].y = rRect.yTop - 4;
585 ::GpiLine(hPS, &vPoint[1]);
586 vPoint[1].x = rRect.xRight - 4;
587 vPoint[1].y = rRect.yTop - 4;
588 ::GpiLine(hPS, &vPoint[1]);
589 }
590 if (dwStyle & wxDOUBLE_BORDER)
591 {
592 LINEBUNDLE vLineBundle;
593
594 vLineBundle.lColor = 0x00FFFFFF; // WHITE
595 vLineBundle.usMixMode = FM_OVERPAINT;
596 vLineBundle.fxWidth = 2;
597 vLineBundle.lGeomWidth = 2;
598 vLineBundle.usType = LINETYPE_SOLID;
599 vLineBundle.usEnd = 0;
600 vLineBundle.usJoin = 0;
601 ::GpiSetAttrs( hPS
602 ,PRIM_LINE
603 ,LBB_COLOR | LBB_MIX_MODE | LBB_WIDTH | LBB_GEOM_WIDTH | LBB_TYPE
604 ,0L
605 ,&vLineBundle
606 );
607 vPoint[1].x = rRect.xRight - 1;
608 vPoint[1].y = rRect.yTop - 1;
609 ::GpiBox( hPS
610 ,DRO_OUTLINE
611 ,&vPoint[1]
612 ,0L
613 ,0L
614 );
615 vLineBundle.lColor = 0x00000000; // WHITE
616 vLineBundle.usMixMode = FM_OVERPAINT;
617 vLineBundle.fxWidth = 2;
618 vLineBundle.lGeomWidth = 2;
619 vLineBundle.usType = LINETYPE_SOLID;
620 vLineBundle.usEnd = 0;
621 vLineBundle.usJoin = 0;
622 ::GpiSetAttrs( hPS
623 ,PRIM_LINE
624 ,LBB_COLOR | LBB_MIX_MODE | LBB_WIDTH | LBB_GEOM_WIDTH | LBB_TYPE
625 ,0L
626 ,&vLineBundle
627 );
628 vPoint[0].x = rRect.xLeft + 2;
629 vPoint[0].y = rRect.yBottom + 2;
630 ::GpiMove(hPS, &vPoint[0]);
631 vPoint[1].x = rRect.xRight - 2;
632 vPoint[1].y = rRect.yTop - 2;
633 ::GpiBox( hPS
634 ,DRO_OUTLINE
635 ,&vPoint[1]
636 ,0L
637 ,0L
638 );
639 vLineBundle.lColor = 0x00FFFFFF; // BLACK
640 vLineBundle.usMixMode = FM_OVERPAINT;
641 vLineBundle.fxWidth = 2;
642 vLineBundle.lGeomWidth = 2;
643 vLineBundle.usType = LINETYPE_SOLID;
644 vLineBundle.usEnd = 0;
645 vLineBundle.usJoin = 0;
646 ::GpiSetAttrs( hPS
647 ,PRIM_LINE
648 ,LBB_COLOR | LBB_MIX_MODE | LBB_WIDTH | LBB_GEOM_WIDTH | LBB_TYPE
649 ,0L
650 ,&vLineBundle
651 );
652 vPoint[0].x = rRect.xLeft + 3;
653 vPoint[0].y = rRect.yBottom + 3;
654 ::GpiMove(hPS, &vPoint[0]);
655 vPoint[1].x = rRect.xRight - 3;
656 vPoint[1].y = rRect.yTop - 3;
657 ::GpiBox( hPS
658 ,DRO_OUTLINE
659 ,&vPoint[1]
660 ,0L
661 ,0L
662 );
663 }
664 if (dwStyle & wxRAISED_BORDER)
665 {
666 LINEBUNDLE vLineBundle;
667
668 vLineBundle.lColor = 0x00000000; // BLACK
669 vLineBundle.usMixMode = FM_OVERPAINT;
670 vLineBundle.fxWidth = 2;
671 vLineBundle.lGeomWidth = 2;
672 vLineBundle.usType = LINETYPE_SOLID;
673 vLineBundle.usEnd = 0;
674 vLineBundle.usJoin = 0;
675 ::GpiSetAttrs( hPS
676 ,PRIM_LINE
677 ,LBB_COLOR | LBB_MIX_MODE | LBB_WIDTH | LBB_GEOM_WIDTH | LBB_TYPE
678 ,0L
679 ,&vLineBundle
680 );
681 vPoint[1].x = rRect.xRight - 1;
682 vPoint[1].y = rRect.yTop - 1;
683 ::GpiBox( hPS
684 ,DRO_OUTLINE
685 ,&vPoint[1]
686 ,0L
687 ,0L
688 );
689 vPoint[0].x = rRect.xLeft + 1;
690 vPoint[0].y = rRect.yBottom + 1;
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
701 vLineBundle.lColor = 0x00FFFFFF; // WHITE
702 vLineBundle.usMixMode = FM_OVERPAINT;
703 vLineBundle.fxWidth = 2;
704 vLineBundle.lGeomWidth = 2;
705 vLineBundle.usType = LINETYPE_SOLID;
706 vLineBundle.usEnd = 0;
707 vLineBundle.usJoin = 0;
708 ::GpiSetAttrs( hPS
709 ,PRIM_LINE
710 ,LBB_COLOR | LBB_MIX_MODE | LBB_WIDTH | LBB_GEOM_WIDTH | LBB_TYPE
711 ,0L
712 ,&vLineBundle
713 );
714 vPoint[0].x = rRect.xLeft + 2;
715 vPoint[0].y = rRect.yBottom + 2;
716 ::GpiMove(hPS, &vPoint[0]);
717 vPoint[1].x = rRect.xLeft + 2;
718 vPoint[1].y = rRect.yTop - 3;
719 ::GpiLine(hPS, &vPoint[1]);
720 vPoint[1].x = rRect.xRight - 3;
721 vPoint[1].y = rRect.yTop - 3;
722 ::GpiLine(hPS, &vPoint[1]);
723
724 vPoint[0].x = rRect.xLeft + 3;
725 vPoint[0].y = rRect.yBottom + 3;
726 ::GpiMove(hPS, &vPoint[0]);
727 vPoint[1].x = rRect.xLeft + 3;
728 vPoint[1].y = rRect.yTop - 4;
729 ::GpiLine(hPS, &vPoint[1]);
730 vPoint[1].x = rRect.xRight - 4;
731 vPoint[1].y = rRect.yTop - 4;
732 ::GpiLine(hPS, &vPoint[1]);
733 }
734 } // end of wxDrawBorder
735
736 void wxOS2SetFont(
737 HWND hWnd
738 , const wxFont& rFont
739 )
740 {
741 char zFont[128];
742 char zFacename[30];
743 char zWeight[30];
744 char zStyle[30];
745
746 if (hWnd == NULLHANDLE)
747 return;
748
749 //
750 // The fonts available for Presentation Params are just a few
751 // outline fonts, the rest are available to the GPI, so we must
752 // map the families to one of these three
753 //
754 switch(rFont.GetFamily())
755 {
756 case wxSCRIPT:
757 strcpy(zFacename, "Script");
758 break;
759
760 case wxDECORATIVE:
761 strcpy(zFacename, "WarpSans");
762 break;
763
764 case wxROMAN:
765 strcpy(zFacename,"Times New Roman");
766 break;
767
768 case wxTELETYPE:
769 strcpy(zFacename, "Courier New");
770 break;
771
772 case wxMODERN:
773 strcpy(zFacename, "Courier New");
774 break;
775
776 case wxDEFAULT:
777 default:
778 case wxSWISS:
779 strcpy(zFacename, "Helvetica");
780 break;
781 }
782
783 switch(rFont.GetWeight())
784 {
785 default:
786 case wxNORMAL:
787 case wxLIGHT:
788 zWeight[0] = '\0';
789 break;
790
791 case wxBOLD:
792 case wxFONTWEIGHT_MAX:
793 strcpy(zWeight, "Bold");
794 break;
795 }
796
797 switch(rFont.GetStyle())
798 {
799 case wxITALIC:
800 case wxSLANT:
801 strcpy(zStyle, "Italic");
802 break;
803
804 default:
805 zStyle[0] = '\0';
806 break;
807 }
808 sprintf(zFont, "%d.%s", rFont.GetPointSize(), zFacename);
809 if (zWeight[0] != '\0')
810 {
811 strcat(zFont, " ");
812 strcat(zFont, zWeight);
813 }
814 if (zStyle[0] != '\0')
815 {
816 strcat(zFont, " ");
817 strcat(zFont, zStyle);
818 }
819 ::WinSetPresParam(hWnd, PP_FONTNAMESIZE, strlen(zFont) + 1, (PVOID)zFont);
820 } // end of wxOS2SetFont
821
822 // ---------------------------------------------------------------------------
823 // Helper for taking a regular bitmap and giving it a disabled look
824 // ---------------------------------------------------------------------------
825 wxBitmap wxDisableBitmap(
826 const wxBitmap& rBmp
827 , long lColor
828 )
829 {
830 wxMask* pMask = rBmp.GetMask();
831
832 if (!pMask)
833 return(wxNullBitmap);
834
835 DEVOPENSTRUC vDop = {0L, "DISPLAY", NULL, 0L, 0L, 0L, 0L, 0L, 0L};
836 SIZEL vSize = {0, 0};
837 HDC hDC = ::DevOpenDC(vHabmain, OD_MEMORY, "*", 5L, (PDEVOPENDATA)&vDop, NULLHANDLE);
838 HPS hPS = ::GpiCreatePS(vHabmain, hDC, &vSize, PU_PELS | GPIA_ASSOC);
839 BITMAPINFOHEADER2 vHeader;
840 BITMAPINFO2 vInfo;
841 ERRORID vError;
842 wxString sError;
843 HBITMAP hBitmap = (HBITMAP)rBmp.GetHBITMAP();
844 HBITMAP hOldBitmap = NULLHANDLE;
845 HBITMAP hOldMask = NULLHANDLE;
846 HBITMAP hMask = (HBITMAP)rBmp.GetMask()->GetMaskBitmap();
847 unsigned char* pucBits; // buffer that will contain the bitmap data
848 unsigned char* pucData; // pointer to use to traverse bitmap data
849 unsigned char* pucBitsMask; // buffer that will contain the mask data
850 unsigned char* pucDataMask; // pointer to use to traverse mask data
851 LONG lScans = 0L;
852 LONG lScansSet = 0L;
853 bool bpp16 = (wxDisplayDepth() == 16);
854
855 memset(&vHeader, '\0', 16);
856 vHeader.cbFix = 16;
857
858 memset(&vInfo, '\0', 16);
859 vInfo.cbFix = 16;
860 vInfo.cx = (ULONG)rBmp.GetWidth();
861 vInfo.cy = (ULONG)rBmp.GetHeight();
862 vInfo.cPlanes = 1;
863 vInfo.cBitCount = 24; // Set to desired count going in
864
865 //
866 // Create the buffers for data....all wxBitmaps are 24 bit internally
867 //
868 int nBytesPerLine = rBmp.GetWidth() * 3;
869 int nSizeDWORD = sizeof(DWORD);
870 int nLineBoundary = nBytesPerLine % nSizeDWORD;
871 int nPadding = 0;
872 int i;
873 int j;
874
875 //
876 // Bitmap must be in a double-word aligned address so we may
877 // have some padding to worry about
878 //
879 if (nLineBoundary > 0)
880 {
881 nPadding = nSizeDWORD - nLineBoundary;
882 nBytesPerLine += nPadding;
883 }
884 pucBits = (unsigned char *)malloc(nBytesPerLine * rBmp.GetHeight());
885 memset(pucBits, '\0', (nBytesPerLine * rBmp.GetHeight()));
886 pucBitsMask = (unsigned char *)malloc(nBytesPerLine * rBmp.GetHeight());
887 memset(pucBitsMask, '\0', (nBytesPerLine * rBmp.GetHeight()));
888
889 //
890 // Extract the bitmap and mask data
891 //
892 if ((hOldBitmap = ::GpiSetBitmap(hPS, hBitmap)) == HBM_ERROR)
893 {
894 vError = ::WinGetLastError(vHabmain);
895 sError = wxPMErrorToStr(vError);
896 }
897 ::GpiQueryBitmapInfoHeader(hBitmap, &vHeader);
898 vInfo.cBitCount = 24;
899 if ((lScans = ::GpiQueryBitmapBits( hPS
900 ,0L
901 ,(LONG)rBmp.GetHeight()
902 ,(PBYTE)pucBits
903 ,&vInfo
904 )) == GPI_ALTERROR)
905 {
906 vError = ::WinGetLastError(vHabmain);
907 sError = wxPMErrorToStr(vError);
908 }
909 if ((hOldMask = ::GpiSetBitmap(hPS, hMask)) == HBM_ERROR)
910 {
911 vError = ::WinGetLastError(vHabmain);
912 sError = wxPMErrorToStr(vError);
913 }
914 ::GpiQueryBitmapInfoHeader(hMask, &vHeader);
915 vInfo.cBitCount = 24;
916 if ((lScans = ::GpiQueryBitmapBits( hPS
917 ,0L
918 ,(LONG)rBmp.GetHeight()
919 ,(PBYTE)pucBitsMask
920 ,&vInfo
921 )) == GPI_ALTERROR)
922 {
923 vError = ::WinGetLastError(vHabmain);
924 sError = wxPMErrorToStr(vError);
925 }
926 if (( hMask = ::GpiSetBitmap(hPS, hOldMask)) == HBM_ERROR)
927 {
928 vError = ::WinGetLastError(vHabmain);
929 sError = wxPMErrorToStr(vError);
930 }
931 pucData = pucBits;
932 pucDataMask = pucBitsMask;
933
934 //
935 // Get the mask value
936 //
937 for (i = 0; i < rBmp.GetHeight(); i++)
938 {
939 for (j = 0; j < rBmp.GetWidth(); j++)
940 {
941 // Byte 1
942 if (bpp16 && *pucDataMask == 0xF8) // 16 bit display gobblygook
943 {
944 *pucData = 0x7F;
945 pucData++;
946 }
947 else if (*pucDataMask == 0xFF) // set to grey
948 {
949 *pucData = 0x7F;
950 pucData++;
951 }
952 else
953 {
954 *pucData = ((unsigned char)(lColor >> 16));
955 pucData++;
956 }
957
958 // Byte 2
959 if (bpp16 && *(pucDataMask + 1) == 0xFC) // 16 bit display gobblygook
960 {
961 *pucData = 0x7F;
962 pucData++;
963 }
964 else if (*(pucDataMask + 1) == 0xFF) // set to grey
965 {
966 *pucData = 0x7F;
967 pucData++;
968 }
969 else
970 {
971 *pucData = ((unsigned char)(lColor >> 8));
972 pucData++;
973 }
974
975 // Byte 3
976 if (bpp16 && *(pucDataMask + 2) == 0xF8) // 16 bit display gobblygook
977 {
978 *pucData = 0x7F;
979 pucData++;
980 }
981 else if (*(pucDataMask + 2) == 0xFF) // set to grey
982 {
983 *pucData = 0x7F;
984 pucData++;
985 }
986 else
987 {
988 *pucData = ((unsigned char)lColor);
989 pucData++;
990 }
991 pucDataMask += 3;
992 }
993 for (j = 0; j < nPadding; j++)
994 {
995 pucData++;
996 pucDataMask++;
997 }
998 }
999
1000 //
1001 // Create a new bitmap and set the modified bits
1002 //
1003 wxBitmap vNewBmp( rBmp.GetWidth()
1004 ,rBmp.GetHeight()
1005 ,24
1006 );
1007 HBITMAP hNewBmp = (HBITMAP)vNewBmp.GetHBITMAP();
1008
1009 if ((hOldBitmap = ::GpiSetBitmap(hPS, hNewBmp)) == HBM_ERROR)
1010 {
1011 vError = ::WinGetLastError(vHabmain);
1012 sError = wxPMErrorToStr(vError);
1013 }
1014 if ((lScansSet = ::GpiSetBitmapBits( hPS
1015 ,0L
1016 ,(LONG)rBmp.GetHeight()
1017 ,(PBYTE)pucBits
1018 ,&vInfo
1019 )) == GPI_ALTERROR)
1020
1021 {
1022 vError = ::WinGetLastError(vHabmain);
1023 sError = wxPMErrorToStr(vError);
1024 }
1025 wxMask* pNewMask;
1026
1027 pNewMask = new wxMask(pMask->GetMaskBitmap());
1028 vNewBmp.SetMask(pNewMask);
1029 free(pucBits);
1030 ::GpiSetBitmap(hPS, NULLHANDLE);
1031 ::GpiDestroyPS(hPS);
1032 ::DevCloseDC(hDC);
1033 if (vNewBmp.Ok())
1034 return(vNewBmp);
1035 return(wxNullBitmap);
1036 } // end of wxDisableBitmap
1037
1038 COLORREF wxColourToRGB(
1039 const wxColour& rColor
1040 )
1041 {
1042 return(OS2RGB(rColor.Red(), rColor.Green(), rColor.Blue()));
1043 } // end of wxColourToRGB