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