]> git.saurik.com Git - wxWidgets.git/blame - src/os2/utilsgui.cpp
Include wx/settings.h according to precompiled headers of wx/wx.h (with other minor...
[wxWidgets.git] / src / os2 / utilsgui.cpp
CommitLineData
bd3b171d 1///////////////////////////////////////////////////////////////////////////////
521bf4ff 2// Name: src/os2/utilsgui.cpp
bd3b171d
SN
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
65571936 9// License: wxWindows licence
bd3b171d
SN
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
bd3b171d
SN
28 #include "wx/utils.h"
29 #include "wx/app.h"
30 #include "wx/cursor.h"
c0badb70 31 #include "wx/timer.h"
bd3b171d
SN
32#endif //WX_PRECOMP
33
ceb8f94a 34#include "wx/apptrait.h"
ceb8f94a 35
bd3b171d
SN
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.
c0badb70 47static bool inTimer = false;
bd3b171d
SN
48
49class wxSleepTimer: public wxTimer
50{
51public:
52 inline void Notify()
53 {
c0badb70 54 inTimer = false;
bd3b171d
SN
55 Stop();
56 }
57};
58
bd3b171d
SN
59// Reading and writing resources (eg WIN.INI, .Xdefaults)
60#if wxUSE_RESOURCES
c0badb70
WS
61bool wxWriteResource( const wxString& rSection,
62 const wxString& rEntry,
63 const wxString& rValue,
64 const wxString& rFile )
bd3b171d 65{
c0badb70
WS
66 HAB hab = 0;
67 HINI hIni = 0;
bd3b171d 68
521bf4ff 69 if (!rFile.empty())
bd3b171d
SN
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 ));
c0badb70 87 return false;
bd3b171d
SN
88}
89
90bool 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
107bool 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
c0badb70
WS
124bool wxWriteResource( const wxString& rSection,
125 const wxString& rEntry,
126 int lValue,
127 const wxString& rFile )
bd3b171d 128{
c0badb70 129 wxChar zBuf[50];
bd3b171d
SN
130
131 wxSprintf(zBuf, "%d", lValue);
c0badb70 132 return wxWriteResource( rSection, rEntry, zBuf, rFile );
bd3b171d
SN
133}
134
c0badb70
WS
135bool wxGetResource( const wxString& rSection,
136 const wxString& rEntry,
137 wxChar** ppValue,
138 const wxString& rFile )
bd3b171d 139{
c0badb70
WS
140 HAB hab = 0;
141 HINI hIni = 0;
142 wxChar zDefunkt[] = _T("$$default");
143 char zBuf[1000];
bd3b171d 144
521bf4ff 145 if (!rFile.empty())
bd3b171d
SN
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)
c0badb70 158 return false;
bd3b171d 159 if (n == 0L || wxStrcmp(zBuf, zDefunkt) == 0)
c0badb70 160 return false;
bd3b171d
SN
161 zBuf[n-1] = '\0';
162 }
163 else
c0badb70 164 return false;
bd3b171d
SN
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)
c0badb70 176 return false;
bd3b171d 177 if (n == 0L || wxStrcmp(zBuf, zDefunkt) == 0)
c0badb70 178 return false;
bd3b171d
SN
179 zBuf[n-1] = '\0';
180 }
181 strcpy((char*)*ppValue, zBuf);
c0badb70 182 return true;
bd3b171d
SN
183}
184
c0badb70
WS
185bool wxGetResource( const wxString& rSection,
186 const wxString& rEntry,
187 float* pValue,
188 const wxString& rFile )
bd3b171d 189{
c0badb70 190 wxChar* zStr = NULL;
bd3b171d
SN
191
192 zStr = new wxChar[1000];
c0badb70 193 bool bSucc = wxGetResource( rSection, rEntry, (wxChar **)&zStr, rFile );
bd3b171d
SN
194
195 if (bSucc)
196 {
197 *pValue = (float)wxStrtod(zStr, NULL);
bd3b171d 198 }
c0badb70
WS
199
200 delete[] zStr;
201 return bSucc;
bd3b171d
SN
202}
203
c0badb70
WS
204bool wxGetResource( const wxString& rSection,
205 const wxString& rEntry,
206 long* pValue,
207 const wxString& rFile )
bd3b171d 208{
c0badb70 209 wxChar* zStr = NULL;
bd3b171d
SN
210
211 zStr = new wxChar[1000];
c0badb70 212 bool bSucc = wxGetResource( rSection, rEntry, (wxChar **)&zStr, rFile );
bd3b171d
SN
213
214 if (bSucc)
215 {
216 *pValue = wxStrtol(zStr, NULL, 10);
bd3b171d 217 }
c0badb70
WS
218
219 delete[] zStr;
220 return bSucc;
bd3b171d
SN
221}
222
c0badb70
WS
223bool wxGetResource( const wxString& rSection,
224 const wxString& rEntry,
225 int* pValue,
226 const wxString& rFile )
bd3b171d 227{
c0badb70 228 wxChar* zStr = NULL;
bd3b171d
SN
229
230 zStr = new wxChar[1000];
c0badb70 231 bool bSucc = wxGetResource( rSection, rEntry, (wxChar **)&zStr, rFile );
bd3b171d
SN
232
233 if (bSucc)
234 {
235 *pValue = (int)wxStrtol(zStr, NULL, 10);
bd3b171d 236 }
c0badb70
WS
237
238 delete[] zStr;
239 return bSucc;
bd3b171d
SN
240}
241#endif // wxUSE_RESOURCES
242
243// ---------------------------------------------------------------------------
244// helper functions for showing a "busy" cursor
245// ---------------------------------------------------------------------------
246
247HCURSOR gs_wxBusyCursor = 0; // new, busy cursor
248HCURSOR gs_wxBusyCursorOld = 0; // old cursor
249static int gs_wxBusyCursorCount = 0;
250
251// Set the cursor to the busy cursor for all windows
f516d986 252void wxBeginBusyCursor(const wxCursor* pCursor)
bd3b171d
SN
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
263void 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
c0badb70 276// true if we're between the above two calls
bd3b171d
SN
277bool 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.
c0badb70 284bool wxCheckForInterrupt( wxWindow* pWnd )
bd3b171d
SN
285{
286 if(pWnd)
287 {
c0badb70
WS
288 QMSG vMsg;
289 HAB hab = 0;
290 HWND hwndFilter = NULLHANDLE;
bd3b171d
SN
291
292 while(::WinPeekMsg(hab, &vMsg, hwndFilter, 0, 0, PM_REMOVE))
293 {
294 ::WinDispatchMsg(hab, &vMsg);
295 }
c0badb70 296 return true;//*** temporary?
bd3b171d
SN
297 }
298 else
299 {
300 wxFAIL_MSG(_T("pWnd==NULL !!!"));
c0badb70 301 return false;//*** temporary?
bd3b171d
SN
302 }
303}
304
305// ----------------------------------------------------------------------------
306// get display info
307// ----------------------------------------------------------------------------
308
309// See also the wxGetMousePosition in window.cpp
310// Deprecated: use wxPoint wxGetMousePosition() instead
311void 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
c0badb70 323// Return true if we have a colour display
bd3b171d
SN
324bool 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
c0badb70 338 return true;
bd3b171d
SN
339#endif
340}
341
342// Returns depth of screen
343int 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
367void 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 }
42782237
SN
386 if (pWidth)
387 *pWidth = (int)lWidth;
388 if (pHeight)
389 *pHeight = (int)lHeight;
bd3b171d
SN
390}
391
392void 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
419void 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
8329e6c7
SN
430void wxGUIAppTraits::InitializeGui(unsigned long &ulHab)
431{
432 ulHab = ::WinInitialize(0);
433}
434
435void wxGUIAppTraits::TerminateGui(unsigned long ulHab)
436{
437 ::WinTerminate(ulHab);
438}
439
621ccd8a
SN
440wxToolkitInfo & wxGUIAppTraits::GetToolkitInfo()
441{
521bf4ff 442 static wxToolkitInfo vInfo;
621ccd8a
SN
443 ULONG ulSysInfo[QSV_MAX] = {0};
444 APIRET ulrc;
445
446 vInfo.shortName = _T("PM");
447 vInfo.name = _T("wxOS2");
448#ifdef __WXUNIVERSAL__
449 vInfo.shortName << _T("univ");
450 vInfo.name << _T("/wxUniversal");
451#endif
452 ulrc = ::DosQuerySysInfo( 1L
453 ,QSV_MAX
454 ,(PVOID)ulSysInfo
455 ,sizeof(ULONG) * QSV_MAX
456 );
457 if (ulrc == 0L)
458 {
459 vInfo.versionMajor = ulSysInfo[QSV_VERSION_MAJOR] / 10;
460 vInfo.versionMinor = ulSysInfo[QSV_VERSION_MINOR];
461 }
462 vInfo.os = wxOS2_PM;
463 return vInfo;
464}
465
bd3b171d
SN
466// ---------------------------------------------------------------------------
467// window information functions
468// ---------------------------------------------------------------------------
469
521bf4ff 470wxString WXDLLEXPORT wxGetWindowText( WXHWND hWnd )
bd3b171d 471{
521bf4ff 472 wxString vStr;
bd3b171d 473
2461cfa0
SN
474 if ( hWnd )
475 {
521bf4ff
WS
476 long lLen = ::WinQueryWindowTextLength((HWND)hWnd) + 1;
477 ::WinQueryWindowText((HWND)hWnd, lLen, (PSZ)(wxChar*)wxStringBuffer(vStr, lLen));
2461cfa0 478 }
bd3b171d
SN
479
480 return vStr;
481}
482
521bf4ff 483wxString WXDLLEXPORT wxGetWindowClass( WXHWND hWnd )
bd3b171d 484{
521bf4ff 485 wxString vStr;
2461cfa0 486 if ( hWnd )
bd3b171d 487 {
521bf4ff
WS
488 int nLen = 256; // some starting value
489
490 for ( ;; )
491 {
492 int nCount = ::WinQueryClassName((HWND)hWnd, nLen, (PSZ)(wxChar*)wxStringBuffer(vStr, nLen));
493
494 if (nCount == nLen )
495 {
496 // the class name might have been truncated, retry with larger
497 // buffer
498 nLen *= 2;
499 }
500 else
501 {
502 break;
503 }
bd3b171d
SN
504 }
505 }
506 return vStr;
507}
508
509WXWORD WXDLLEXPORT wxGetWindowId(
510 WXHWND hWnd
511)
512{
513 return ::WinQueryWindowUShort((HWND)hWnd, QWS_ID);
514}
515
516void wxDrawBorder(
517 HPS hPS
518, RECTL& rRect
519, WXDWORD dwStyle
520)
521{
522 POINTL vPoint[2];
523
524 vPoint[0].x = rRect.xLeft;
525 vPoint[0].y = rRect.yBottom;
526 ::GpiMove(hPS, &vPoint[0]);
527 if (dwStyle & wxSIMPLE_BORDER ||
528 dwStyle & wxSTATIC_BORDER)
529 {
530 vPoint[1].x = rRect.xRight - 1;
531 vPoint[1].y = rRect.yTop - 1;
532 ::GpiBox( hPS
533 ,DRO_OUTLINE
534 ,&vPoint[1]
535 ,0L
536 ,0L
537 );
538 }
539 if (dwStyle & wxSUNKEN_BORDER)
540 {
541 LINEBUNDLE vLineBundle;
542
543 vLineBundle.lColor = 0x00FFFFFF; // WHITE
544 vLineBundle.usMixMode = FM_OVERPAINT;
545 vLineBundle.fxWidth = 2;
546 vLineBundle.lGeomWidth = 2;
547 vLineBundle.usType = LINETYPE_SOLID;
548 vLineBundle.usEnd = 0;
549 vLineBundle.usJoin = 0;
550 ::GpiSetAttrs( hPS
551 ,PRIM_LINE
552 ,LBB_COLOR | LBB_MIX_MODE | LBB_WIDTH | LBB_GEOM_WIDTH | LBB_TYPE
553 ,0L
554 ,&vLineBundle
555 );
556 vPoint[1].x = rRect.xRight - 1;
557 vPoint[1].y = rRect.yTop - 1;
558 ::GpiBox( hPS
559 ,DRO_OUTLINE
560 ,&vPoint[1]
561 ,0L
562 ,0L
563 );
564 vPoint[0].x = rRect.xLeft + 1;
565 vPoint[0].y = rRect.yBottom + 1;
566 ::GpiMove(hPS, &vPoint[0]);
567 vPoint[1].x = rRect.xRight - 2;
568 vPoint[1].y = rRect.yTop - 2;
569 ::GpiBox( hPS
570 ,DRO_OUTLINE
571 ,&vPoint[1]
572 ,0L
573 ,0L
574 );
575
576 vLineBundle.lColor = 0x00000000; // BLACK
577 vLineBundle.usMixMode = FM_OVERPAINT;
578 vLineBundle.fxWidth = 2;
579 vLineBundle.lGeomWidth = 2;
580 vLineBundle.usType = LINETYPE_SOLID;
581 vLineBundle.usEnd = 0;
582 vLineBundle.usJoin = 0;
583 ::GpiSetAttrs( hPS
584 ,PRIM_LINE
585 ,LBB_COLOR | LBB_MIX_MODE | LBB_WIDTH | LBB_GEOM_WIDTH | LBB_TYPE
586 ,0L
587 ,&vLineBundle
588 );
589 vPoint[0].x = rRect.xLeft + 2;
590 vPoint[0].y = rRect.yBottom + 2;
591 ::GpiMove(hPS, &vPoint[0]);
592 vPoint[1].x = rRect.xLeft + 2;
593 vPoint[1].y = rRect.yTop - 3;
594 ::GpiLine(hPS, &vPoint[1]);
595 vPoint[1].x = rRect.xRight - 3;
596 vPoint[1].y = rRect.yTop - 3;
597 ::GpiLine(hPS, &vPoint[1]);
598
599 vPoint[0].x = rRect.xLeft + 3;
600 vPoint[0].y = rRect.yBottom + 3;
601 ::GpiMove(hPS, &vPoint[0]);
602 vPoint[1].x = rRect.xLeft + 3;
603 vPoint[1].y = rRect.yTop - 4;
604 ::GpiLine(hPS, &vPoint[1]);
605 vPoint[1].x = rRect.xRight - 4;
606 vPoint[1].y = rRect.yTop - 4;
607 ::GpiLine(hPS, &vPoint[1]);
608 }
609 if (dwStyle & wxDOUBLE_BORDER)
610 {
611 LINEBUNDLE vLineBundle;
612
613 vLineBundle.lColor = 0x00FFFFFF; // WHITE
614 vLineBundle.usMixMode = FM_OVERPAINT;
615 vLineBundle.fxWidth = 2;
616 vLineBundle.lGeomWidth = 2;
617 vLineBundle.usType = LINETYPE_SOLID;
618 vLineBundle.usEnd = 0;
619 vLineBundle.usJoin = 0;
620 ::GpiSetAttrs( hPS
621 ,PRIM_LINE
622 ,LBB_COLOR | LBB_MIX_MODE | LBB_WIDTH | LBB_GEOM_WIDTH | LBB_TYPE
623 ,0L
624 ,&vLineBundle
625 );
626 vPoint[1].x = rRect.xRight - 1;
627 vPoint[1].y = rRect.yTop - 1;
628 ::GpiBox( hPS
629 ,DRO_OUTLINE
630 ,&vPoint[1]
631 ,0L
632 ,0L
633 );
634 vLineBundle.lColor = 0x00000000; // WHITE
635 vLineBundle.usMixMode = FM_OVERPAINT;
636 vLineBundle.fxWidth = 2;
637 vLineBundle.lGeomWidth = 2;
638 vLineBundle.usType = LINETYPE_SOLID;
639 vLineBundle.usEnd = 0;
640 vLineBundle.usJoin = 0;
641 ::GpiSetAttrs( hPS
642 ,PRIM_LINE
643 ,LBB_COLOR | LBB_MIX_MODE | LBB_WIDTH | LBB_GEOM_WIDTH | LBB_TYPE
644 ,0L
645 ,&vLineBundle
646 );
647 vPoint[0].x = rRect.xLeft + 2;
648 vPoint[0].y = rRect.yBottom + 2;
649 ::GpiMove(hPS, &vPoint[0]);
650 vPoint[1].x = rRect.xRight - 2;
651 vPoint[1].y = rRect.yTop - 2;
652 ::GpiBox( hPS
653 ,DRO_OUTLINE
654 ,&vPoint[1]
655 ,0L
656 ,0L
657 );
658 vLineBundle.lColor = 0x00FFFFFF; // BLACK
659 vLineBundle.usMixMode = FM_OVERPAINT;
660 vLineBundle.fxWidth = 2;
661 vLineBundle.lGeomWidth = 2;
662 vLineBundle.usType = LINETYPE_SOLID;
663 vLineBundle.usEnd = 0;
664 vLineBundle.usJoin = 0;
665 ::GpiSetAttrs( hPS
666 ,PRIM_LINE
667 ,LBB_COLOR | LBB_MIX_MODE | LBB_WIDTH | LBB_GEOM_WIDTH | LBB_TYPE
668 ,0L
669 ,&vLineBundle
670 );
671 vPoint[0].x = rRect.xLeft + 3;
672 vPoint[0].y = rRect.yBottom + 3;
673 ::GpiMove(hPS, &vPoint[0]);
674 vPoint[1].x = rRect.xRight - 3;
675 vPoint[1].y = rRect.yTop - 3;
676 ::GpiBox( hPS
677 ,DRO_OUTLINE
678 ,&vPoint[1]
679 ,0L
680 ,0L
681 );
682 }
683 if (dwStyle & wxRAISED_BORDER)
684 {
685 LINEBUNDLE vLineBundle;
686
687 vLineBundle.lColor = 0x00000000; // BLACK
688 vLineBundle.usMixMode = FM_OVERPAINT;
689 vLineBundle.fxWidth = 2;
690 vLineBundle.lGeomWidth = 2;
691 vLineBundle.usType = LINETYPE_SOLID;
692 vLineBundle.usEnd = 0;
693 vLineBundle.usJoin = 0;
694 ::GpiSetAttrs( hPS
695 ,PRIM_LINE
696 ,LBB_COLOR | LBB_MIX_MODE | LBB_WIDTH | LBB_GEOM_WIDTH | LBB_TYPE
697 ,0L
698 ,&vLineBundle
699 );
700 vPoint[1].x = rRect.xRight - 1;
701 vPoint[1].y = rRect.yTop - 1;
702 ::GpiBox( hPS
703 ,DRO_OUTLINE
704 ,&vPoint[1]
705 ,0L
706 ,0L
707 );
708 vPoint[0].x = rRect.xLeft + 1;
709 vPoint[0].y = rRect.yBottom + 1;
710 ::GpiMove(hPS, &vPoint[0]);
711 vPoint[1].x = rRect.xRight - 2;
712 vPoint[1].y = rRect.yTop - 2;
713 ::GpiBox( hPS
714 ,DRO_OUTLINE
715 ,&vPoint[1]
716 ,0L
717 ,0L
718 );
719
720 vLineBundle.lColor = 0x00FFFFFF; // WHITE
721 vLineBundle.usMixMode = FM_OVERPAINT;
722 vLineBundle.fxWidth = 2;
723 vLineBundle.lGeomWidth = 2;
724 vLineBundle.usType = LINETYPE_SOLID;
725 vLineBundle.usEnd = 0;
726 vLineBundle.usJoin = 0;
727 ::GpiSetAttrs( hPS
728 ,PRIM_LINE
729 ,LBB_COLOR | LBB_MIX_MODE | LBB_WIDTH | LBB_GEOM_WIDTH | LBB_TYPE
730 ,0L
731 ,&vLineBundle
732 );
733 vPoint[0].x = rRect.xLeft + 2;
734 vPoint[0].y = rRect.yBottom + 2;
735 ::GpiMove(hPS, &vPoint[0]);
736 vPoint[1].x = rRect.xLeft + 2;
737 vPoint[1].y = rRect.yTop - 3;
738 ::GpiLine(hPS, &vPoint[1]);
739 vPoint[1].x = rRect.xRight - 3;
740 vPoint[1].y = rRect.yTop - 3;
741 ::GpiLine(hPS, &vPoint[1]);
742
743 vPoint[0].x = rRect.xLeft + 3;
744 vPoint[0].y = rRect.yBottom + 3;
745 ::GpiMove(hPS, &vPoint[0]);
746 vPoint[1].x = rRect.xLeft + 3;
747 vPoint[1].y = rRect.yTop - 4;
748 ::GpiLine(hPS, &vPoint[1]);
749 vPoint[1].x = rRect.xRight - 4;
750 vPoint[1].y = rRect.yTop - 4;
751 ::GpiLine(hPS, &vPoint[1]);
752 }
753} // end of wxDrawBorder
754
755void wxOS2SetFont(
756 HWND hWnd
757, const wxFont& rFont
758)
759{
760 char zFont[128];
761 char zFacename[30];
762 char zWeight[30];
763 char zStyle[30];
764
765 if (hWnd == NULLHANDLE)
766 return;
767
768 //
769 // The fonts available for Presentation Params are just a few
770 // outline fonts, the rest are available to the GPI, so we must
771 // map the families to one of these three
772 //
773 switch(rFont.GetFamily())
774 {
775 case wxSCRIPT:
776 strcpy(zFacename, "Script");
777 break;
778
779 case wxDECORATIVE:
780 strcpy(zFacename, "WarpSans");
781 break;
782
783 case wxROMAN:
784 strcpy(zFacename,"Times New Roman");
785 break;
786
787 case wxTELETYPE:
788 strcpy(zFacename, "Courier New");
789 break;
790
791 case wxMODERN:
792 strcpy(zFacename, "Courier New");
793 break;
794
795 case wxDEFAULT:
796 default:
797 case wxSWISS:
798 strcpy(zFacename, "Helvetica");
799 break;
800 }
801
802 switch(rFont.GetWeight())
803 {
804 default:
805 case wxNORMAL:
806 case wxLIGHT:
807 zWeight[0] = '\0';
808 break;
809
810 case wxBOLD:
811 case wxFONTWEIGHT_MAX:
812 strcpy(zWeight, "Bold");
813 break;
814 }
815
816 switch(rFont.GetStyle())
817 {
818 case wxITALIC:
819 case wxSLANT:
820 strcpy(zStyle, "Italic");
821 break;
822
823 default:
824 zStyle[0] = '\0';
825 break;
826 }
827 sprintf(zFont, "%d.%s", rFont.GetPointSize(), zFacename);
828 if (zWeight[0] != '\0')
829 {
830 strcat(zFont, " ");
831 strcat(zFont, zWeight);
832 }
833 if (zStyle[0] != '\0')
834 {
835 strcat(zFont, " ");
836 strcat(zFont, zStyle);
837 }
838 ::WinSetPresParam(hWnd, PP_FONTNAMESIZE, strlen(zFont) + 1, (PVOID)zFont);
839} // end of wxOS2SetFont
840
841// ---------------------------------------------------------------------------
842// Helper for taking a regular bitmap and giving it a disabled look
843// ---------------------------------------------------------------------------
844wxBitmap wxDisableBitmap(
845 const wxBitmap& rBmp
846, long lColor
847)
848{
849 wxMask* pMask = rBmp.GetMask();
850
851 if (!pMask)
852 return(wxNullBitmap);
853
854 DEVOPENSTRUC vDop = {0L, "DISPLAY", NULL, 0L, 0L, 0L, 0L, 0L, 0L};
855 SIZEL vSize = {0, 0};
856 HDC hDC = ::DevOpenDC(vHabmain, OD_MEMORY, "*", 5L, (PDEVOPENDATA)&vDop, NULLHANDLE);
857 HPS hPS = ::GpiCreatePS(vHabmain, hDC, &vSize, PU_PELS | GPIA_ASSOC);
858 BITMAPINFOHEADER2 vHeader;
859 BITMAPINFO2 vInfo;
860 ERRORID vError;
861 wxString sError;
862 HBITMAP hBitmap = (HBITMAP)rBmp.GetHBITMAP();
863 HBITMAP hOldBitmap = NULLHANDLE;
864 HBITMAP hOldMask = NULLHANDLE;
865 HBITMAP hMask = (HBITMAP)rBmp.GetMask()->GetMaskBitmap();
866 unsigned char* pucBits; // buffer that will contain the bitmap data
867 unsigned char* pucData; // pointer to use to traverse bitmap data
868 unsigned char* pucBitsMask; // buffer that will contain the mask data
869 unsigned char* pucDataMask; // pointer to use to traverse mask data
870 LONG lScans = 0L;
871 LONG lScansSet = 0L;
872 bool bpp16 = (wxDisplayDepth() == 16);
873
874 memset(&vHeader, '\0', 16);
875 vHeader.cbFix = 16;
876
877 memset(&vInfo, '\0', 16);
878 vInfo.cbFix = 16;
879 vInfo.cx = (ULONG)rBmp.GetWidth();
880 vInfo.cy = (ULONG)rBmp.GetHeight();
881 vInfo.cPlanes = 1;
882 vInfo.cBitCount = 24; // Set to desired count going in
883
884 //
885 // Create the buffers for data....all wxBitmaps are 24 bit internally
886 //
887 int nBytesPerLine = rBmp.GetWidth() * 3;
888 int nSizeDWORD = sizeof(DWORD);
889 int nLineBoundary = nBytesPerLine % nSizeDWORD;
890 int nPadding = 0;
891 int i;
892 int j;
893
894 //
d6922577 895 // Bitmap must be in a double-word aligned address so we may
bd3b171d
SN
896 // have some padding to worry about
897 //
898 if (nLineBoundary > 0)
899 {
900 nPadding = nSizeDWORD - nLineBoundary;
901 nBytesPerLine += nPadding;
902 }
903 pucBits = (unsigned char *)malloc(nBytesPerLine * rBmp.GetHeight());
904 memset(pucBits, '\0', (nBytesPerLine * rBmp.GetHeight()));
905 pucBitsMask = (unsigned char *)malloc(nBytesPerLine * rBmp.GetHeight());
906 memset(pucBitsMask, '\0', (nBytesPerLine * rBmp.GetHeight()));
907
908 //
909 // Extract the bitmap and mask data
910 //
911 if ((hOldBitmap = ::GpiSetBitmap(hPS, hBitmap)) == HBM_ERROR)
912 {
913 vError = ::WinGetLastError(vHabmain);
914 sError = wxPMErrorToStr(vError);
915 }
916 ::GpiQueryBitmapInfoHeader(hBitmap, &vHeader);
917 vInfo.cBitCount = 24;
918 if ((lScans = ::GpiQueryBitmapBits( hPS
919 ,0L
920 ,(LONG)rBmp.GetHeight()
921 ,(PBYTE)pucBits
922 ,&vInfo
923 )) == GPI_ALTERROR)
924 {
925 vError = ::WinGetLastError(vHabmain);
926 sError = wxPMErrorToStr(vError);
927 }
928 if ((hOldMask = ::GpiSetBitmap(hPS, hMask)) == HBM_ERROR)
929 {
930 vError = ::WinGetLastError(vHabmain);
931 sError = wxPMErrorToStr(vError);
932 }
933 ::GpiQueryBitmapInfoHeader(hMask, &vHeader);
934 vInfo.cBitCount = 24;
935 if ((lScans = ::GpiQueryBitmapBits( hPS
936 ,0L
937 ,(LONG)rBmp.GetHeight()
938 ,(PBYTE)pucBitsMask
939 ,&vInfo
940 )) == GPI_ALTERROR)
941 {
942 vError = ::WinGetLastError(vHabmain);
943 sError = wxPMErrorToStr(vError);
944 }
945 if (( hMask = ::GpiSetBitmap(hPS, hOldMask)) == HBM_ERROR)
946 {
947 vError = ::WinGetLastError(vHabmain);
948 sError = wxPMErrorToStr(vError);
949 }
950 pucData = pucBits;
951 pucDataMask = pucBitsMask;
952
953 //
954 // Get the mask value
955 //
956 for (i = 0; i < rBmp.GetHeight(); i++)
957 {
958 for (j = 0; j < rBmp.GetWidth(); j++)
959 {
960 // Byte 1
961 if (bpp16 && *pucDataMask == 0xF8) // 16 bit display gobblygook
962 {
963 *pucData = 0x7F;
964 pucData++;
965 }
966 else if (*pucDataMask == 0xFF) // set to grey
967 {
968 *pucData = 0x7F;
969 pucData++;
970 }
971 else
972 {
973 *pucData = ((unsigned char)(lColor >> 16));
974 pucData++;
975 }
976
977 // Byte 2
978 if (bpp16 && *(pucDataMask + 1) == 0xFC) // 16 bit display gobblygook
979 {
980 *pucData = 0x7F;
981 pucData++;
982 }
983 else if (*(pucDataMask + 1) == 0xFF) // set to grey
984 {
985 *pucData = 0x7F;
986 pucData++;
987 }
988 else
989 {
990 *pucData = ((unsigned char)(lColor >> 8));
991 pucData++;
992 }
993
994 // Byte 3
995 if (bpp16 && *(pucDataMask + 2) == 0xF8) // 16 bit display gobblygook
996 {
997 *pucData = 0x7F;
998 pucData++;
999 }
1000 else if (*(pucDataMask + 2) == 0xFF) // set to grey
1001 {
1002 *pucData = 0x7F;
1003 pucData++;
1004 }
1005 else
1006 {
1007 *pucData = ((unsigned char)lColor);
1008 pucData++;
1009 }
1010 pucDataMask += 3;
1011 }
1012 for (j = 0; j < nPadding; j++)
1013 {
1014 pucData++;
1015 pucDataMask++;
1016 }
1017 }
1018
1019 //
1020 // Create a new bitmap and set the modified bits
1021 //
1022 wxBitmap vNewBmp( rBmp.GetWidth()
1023 ,rBmp.GetHeight()
1024 ,24
1025 );
1026 HBITMAP hNewBmp = (HBITMAP)vNewBmp.GetHBITMAP();
1027
1028 if ((hOldBitmap = ::GpiSetBitmap(hPS, hNewBmp)) == HBM_ERROR)
1029 {
1030 vError = ::WinGetLastError(vHabmain);
1031 sError = wxPMErrorToStr(vError);
1032 }
1033 if ((lScansSet = ::GpiSetBitmapBits( hPS
1034 ,0L
1035 ,(LONG)rBmp.GetHeight()
1036 ,(PBYTE)pucBits
1037 ,&vInfo
1038 )) == GPI_ALTERROR)
1039
1040 {
1041 vError = ::WinGetLastError(vHabmain);
1042 sError = wxPMErrorToStr(vError);
1043 }
1044 wxMask* pNewMask;
1045
1046 pNewMask = new wxMask(pMask->GetMaskBitmap());
1047 vNewBmp.SetMask(pNewMask);
1048 free(pucBits);
1049 ::GpiSetBitmap(hPS, NULLHANDLE);
1050 ::GpiDestroyPS(hPS);
1051 ::DevCloseDC(hDC);
1052 if (vNewBmp.Ok())
1053 return(vNewBmp);
1054 return(wxNullBitmap);
1055} // end of wxDisableBitmap
1056
1057COLORREF wxColourToRGB(
1058 const wxColour& rColor
1059)
1060{
1061 return(OS2RGB(rColor.Red(), rColor.Green(), rColor.Blue()));
1062} // end of wxColourToRGB