]>
Commit | Line | Data |
---|---|---|
1 | ///////////////////////////////////////////////////////////////////////////// | |
2 | // Name: utils.cpp | |
3 | // Purpose: Various utilities | |
4 | // Author: David Webster | |
5 | // Modified by: | |
6 | // Created: 09/17/99 | |
7 | // RCS-ID: $Id$ | |
8 | // Copyright: (c) David Webster | |
9 | // Licence: wxWindows license | |
10 | ///////////////////////////////////////////////////////////////////////////// | |
11 | ||
12 | // For compilers that support precompilation, includes "wx.h". | |
13 | #include "wx/wxprec.h" | |
14 | ||
15 | #ifndef WX_PRECOMP | |
16 | #include "wx/setup.h" | |
17 | #include "wx/utils.h" | |
18 | #include "wx/app.h" | |
19 | #include "wx/cursor.h" | |
20 | #endif //WX_PRECOMP | |
21 | ||
22 | #include "wx/os2/private.h" | |
23 | #include "wx/timer.h" | |
24 | #include "wx/intl.h" | |
25 | ||
26 | #include <ctype.h> | |
27 | #ifdef __EMX__ | |
28 | #include <dirent.h> | |
29 | #endif | |
30 | ||
31 | #include "wx/log.h" | |
32 | ||
33 | #include <io.h> | |
34 | ||
35 | #include <stdio.h> | |
36 | #include <stdlib.h> | |
37 | #include <string.h> | |
38 | #include <errno.h> | |
39 | #include <stdarg.h> | |
40 | ||
41 | #define PURE_32 | |
42 | ||
43 | #ifndef __EMX__ | |
44 | #include <upm.h> | |
45 | #include <netcons.h> | |
46 | #include <netbios.h> | |
47 | #endif | |
48 | ||
49 | static const wxChar WX_SECTION[] = _T("wxWindows"); | |
50 | static const wxChar eHOSTNAME[] = _T("HostName"); | |
51 | static const wxChar eUSERID[] = _T("UserId"); | |
52 | static const wxChar eUSERNAME[] = _T("UserName"); | |
53 | ||
54 | // For the following functions we SHOULD fill in support | |
55 | // for Windows-NT (which I don't know) as I assume it begin | |
56 | // a POSIX Unix (so claims MS) that it has some special | |
57 | // functions beyond those provided by WinSock | |
58 | ||
59 | // Get full hostname (eg. DoDo.BSn-Germany.crg.de) | |
60 | bool wxGetHostName( | |
61 | wxChar* zBuf | |
62 | , int nMaxSize | |
63 | ) | |
64 | { | |
65 | #if wxUSE_NET_API | |
66 | char zServer[256]; | |
67 | char zComputer[256]; | |
68 | unsigned long ulLevel = 0; | |
69 | unsigned char* zBuffer = NULL; | |
70 | unsigned long ulBuffer = 256; | |
71 | unsigned long* pulTotalAvail = NULL; | |
72 | ||
73 | NetBios32GetInfo( (const unsigned char*)zServer | |
74 | ,(const unsigned char*)zComputer | |
75 | ,ulLevel | |
76 | ,zBuffer | |
77 | ,ulBuffer | |
78 | ,pulTotalAvail | |
79 | ); | |
80 | strcpy(zBuf, zServer); | |
81 | #else | |
82 | wxChar* zSysname; | |
83 | const wxChar* zDefaultHost = _T("noname"); | |
84 | ||
85 | if ((zSysname = wxGetenv(_T("SYSTEM_NAME"))) == NULL) | |
86 | { | |
87 | ULONG n = ::PrfQueryProfileString( HINI_PROFILE | |
88 | ,(PSZ)WX_SECTION | |
89 | ,(PSZ)eHOSTNAME | |
90 | ,(PSZ)zDefaultHost | |
91 | ,(void*)zBuf | |
92 | ,(ULONG)nMaxSize - 1 | |
93 | ); | |
94 | } | |
95 | else | |
96 | wxStrncpy(zBuf, zSysname, nMaxSize - 1); | |
97 | zBuf[nMaxSize] = _T('\0'); | |
98 | #endif | |
99 | return *zBuf ? TRUE : FALSE; | |
100 | } | |
101 | ||
102 | // Get user ID e.g. jacs | |
103 | bool wxGetUserId( | |
104 | wxChar* zBuf | |
105 | , int nType | |
106 | ) | |
107 | { | |
108 | #if defined(__VISAGECPP__) | |
109 | long lrc; | |
110 | // UPM procs return 0 on success | |
111 | lrc = U32ELOCU((unsigned char*)zBuf, (unsigned long *)&nType); | |
112 | if (lrc == 0) return TRUE; | |
113 | #endif | |
114 | return FALSE; | |
115 | } | |
116 | ||
117 | bool wxGetUserName( | |
118 | wxChar* zBuf | |
119 | , int nMaxSize | |
120 | ) | |
121 | { | |
122 | #ifdef USE_NET_API | |
123 | wxGetUserId( zBuf | |
124 | ,nMaxSize | |
125 | ); | |
126 | #else | |
127 | wxStrncpy(zBuf, _T("Unknown User"), nMaxSize); | |
128 | #endif | |
129 | return TRUE; | |
130 | } | |
131 | ||
132 | int wxKill( | |
133 | long lPid | |
134 | , wxSignal eSig | |
135 | , wxKillError* peError | |
136 | ) | |
137 | { | |
138 | return((int)::DosKillProcess(0, (PID)lPid)); | |
139 | } | |
140 | ||
141 | // | |
142 | // Execute a program in an Interactive Shell | |
143 | // | |
144 | bool wxShell( | |
145 | const wxString& rCommand | |
146 | ) | |
147 | { | |
148 | wxChar* zShell = _T("CMD.EXE"); | |
149 | wxString sInputs; | |
150 | wxChar zTmp[255]; | |
151 | STARTDATA SData = {0}; | |
152 | PSZ PgmTitle = "Command Shell"; | |
153 | APIRET rc; | |
154 | PID vPid = 0; | |
155 | ULONG ulSessID = 0; | |
156 | UCHAR achObjBuf[256] = {0}; //error data if DosStart fails | |
157 | RESULTCODES vResult; | |
158 | ||
159 | SData.Length = sizeof(STARTDATA); | |
160 | SData.Related = SSF_RELATED_INDEPENDENT; | |
161 | SData.FgBg = SSF_FGBG_FORE; | |
162 | SData.TraceOpt = SSF_TRACEOPT_NONE; | |
163 | SData.PgmTitle = PgmTitle; | |
164 | SData.PgmName = zShell; | |
165 | ||
166 | sInputs = "/C " + rCommand; | |
167 | SData.PgmInputs = (BYTE*)sInputs.c_str(); | |
168 | SData.TermQ = 0; | |
169 | SData.Environment = 0; | |
170 | SData.InheritOpt = SSF_INHERTOPT_SHELL; | |
171 | SData.SessionType = SSF_TYPE_WINDOWABLEVIO; | |
172 | SData.IconFile = 0; | |
173 | SData.PgmHandle = 0; | |
174 | SData.PgmControl = SSF_CONTROL_VISIBLE | SSF_CONTROL_MAXIMIZE; | |
175 | SData.InitXPos = 30; | |
176 | SData.InitYPos = 40; | |
177 | SData.InitXSize = 200; | |
178 | SData.InitYSize = 140; | |
179 | SData.Reserved = 0; | |
180 | SData.ObjectBuffer = (char*)achObjBuf; | |
181 | SData.ObjectBuffLen = (ULONG)sizeof(achObjBuf); | |
182 | ||
183 | rc = ::DosStartSession(&SData, &ulSessID, &vPid); | |
184 | if (rc == 0 || rc == 457) // NO_ERROR or SMG_START_IN_BACKGROUND | |
185 | { | |
186 | PTIB ptib; | |
187 | PPIB ppib; | |
188 | ||
189 | ::DosGetInfoBlocks(&ptib, &ppib); | |
190 | ||
191 | ::DosWaitChild( DCWA_PROCESS | |
192 | ,DCWW_WAIT | |
193 | ,&vResult | |
194 | ,&ppib->pib_ulpid | |
195 | ,vPid | |
196 | ); | |
197 | } | |
198 | return (rc != 0); | |
199 | } | |
200 | ||
201 | // Get free memory in bytes, or -1 if cannot determine amount (e.g. on UNIX) | |
202 | long wxGetFreeMemory() | |
203 | { | |
204 | void* pMemptr = NULL; | |
205 | ULONG lSize; | |
206 | ULONG lMemFlags; | |
207 | APIRET rc; | |
208 | ||
209 | lMemFlags = PAG_FREE; | |
210 | rc = ::DosQueryMem(pMemptr, &lSize, &lMemFlags); | |
211 | if (rc != 0) | |
212 | return -1L; | |
213 | return (long)lSize; | |
214 | } | |
215 | ||
216 | // ---------------------------------------------------------------------------- | |
217 | // env vars | |
218 | // ---------------------------------------------------------------------------- | |
219 | ||
220 | bool wxGetEnv(const wxString& var, wxString *value) | |
221 | { | |
222 | // wxGetenv is defined as getenv() | |
223 | wxChar *p = wxGetenv(var); | |
224 | if ( !p ) | |
225 | return FALSE; | |
226 | ||
227 | if ( value ) | |
228 | { | |
229 | *value = p; | |
230 | } | |
231 | ||
232 | return TRUE; | |
233 | } | |
234 | ||
235 | bool wxSetEnv(const wxString& variable, const wxChar *value) | |
236 | { | |
237 | #if defined(HAVE_SETENV) | |
238 | return setenv(variable.mb_str(), value ? wxString(value).mb_str().data() | |
239 | : NULL, 1 /* overwrite */) == 0; | |
240 | #elif defined(HAVE_PUTENV) | |
241 | wxString s = variable; | |
242 | if ( value ) | |
243 | s << _T('=') << value; | |
244 | ||
245 | // transform to ANSI | |
246 | const char *p = s.mb_str(); | |
247 | ||
248 | // the string will be free()d by libc | |
249 | char *buf = (char *)malloc(strlen(p) + 1); | |
250 | strcpy(buf, p); | |
251 | ||
252 | return putenv(buf) == 0; | |
253 | #else // no way to set an env var | |
254 | return FALSE; | |
255 | #endif | |
256 | } | |
257 | ||
258 | ||
259 | // Sleep for nSecs seconds. Attempt a Windows implementation using timers. | |
260 | static bool inTimer = FALSE; | |
261 | ||
262 | class wxSleepTimer: public wxTimer | |
263 | { | |
264 | public: | |
265 | inline void Notify() | |
266 | { | |
267 | inTimer = FALSE; | |
268 | Stop(); | |
269 | } | |
270 | }; | |
271 | ||
272 | static wxTimer* wxTheSleepTimer = NULL; | |
273 | ||
274 | void wxUsleep( | |
275 | unsigned long ulMilliseconds | |
276 | ) | |
277 | { | |
278 | ::DosSleep(ulMilliseconds/1000l); | |
279 | } | |
280 | ||
281 | void wxSleep( | |
282 | int nSecs | |
283 | ) | |
284 | { | |
285 | ::DosSleep(1000 * nSecs); | |
286 | } | |
287 | ||
288 | // Consume all events until no more left | |
289 | void wxFlushEvents() | |
290 | { | |
291 | // wxYield(); | |
292 | } | |
293 | ||
294 | #if WXWIN_COMPATIBILITY_2_2 | |
295 | ||
296 | // Output a debug mess., in a system dependent fashion. | |
297 | void wxDebugMsg( | |
298 | const wxChar* zFmt ... | |
299 | ) | |
300 | { | |
301 | va_list vAp; | |
302 | static wxChar zBuffer[512]; | |
303 | ||
304 | if (!wxTheApp->GetWantDebugOutput()) | |
305 | return ; | |
306 | va_start(vAp, zFmt); | |
307 | sprintf(zBuffer, zFmt, vAp) ; | |
308 | va_end(vAp); | |
309 | } | |
310 | ||
311 | // Non-fatal error: pop up message box and (possibly) continue | |
312 | void wxError( | |
313 | const wxString& rMsg | |
314 | , const wxString& rTitle | |
315 | ) | |
316 | { | |
317 | wxBuffer = new wxChar[256]; | |
318 | wxSprintf(wxBuffer, "%s\nContinue?", WXSTRINGCAST rMsg); | |
319 | if (::WinMessageBox( HWND_DESKTOP | |
320 | ,NULL | |
321 | ,(PSZ)wxBuffer | |
322 | ,(PSZ)WXSTRINGCAST rTitle | |
323 | ,0 | |
324 | ,MB_ICONEXCLAMATION | MB_YESNO | |
325 | ) == MBID_YES) | |
326 | delete[] wxBuffer; | |
327 | wxExit(); | |
328 | } | |
329 | ||
330 | // Fatal error: pop up message box and abort | |
331 | void wxFatalError( | |
332 | const wxString& rMsg | |
333 | , const wxString& rTitle | |
334 | ) | |
335 | { | |
336 | unsigned long ulRc; | |
337 | ||
338 | ulRc = ::WinMessageBox( HWND_DESKTOP | |
339 | ,NULL | |
340 | ,WXSTRINGCAST rMsg | |
341 | ,WXSTRINGCAST rTitle | |
342 | ,0 | |
343 | ,MB_NOICON | MB_OK | |
344 | ); | |
345 | DosExit(EXIT_PROCESS, ulRc); | |
346 | } | |
347 | ||
348 | #endif // WXWIN_COMPATIBILITY_2_2 | |
349 | ||
350 | // Emit a beeeeeep | |
351 | void wxBell() | |
352 | { | |
353 | DosBeep(1000,1000); // 1kHz during 1 sec. | |
354 | } | |
355 | ||
356 | // Chris Breeze 27/5/98: revised WIN32 code to | |
357 | // detect WindowsNT correctly | |
358 | int wxGetOsVersion( | |
359 | int* pMajorVsn | |
360 | , int* pMinorVsn | |
361 | ) | |
362 | { | |
363 | ULONG ulSysInfo[QSV_MAX] = {0}; | |
364 | APIRET ulrc; | |
365 | ||
366 | ulrc = ::DosQuerySysInfo( 1L | |
367 | ,QSV_MAX | |
368 | ,(PVOID)ulSysInfo | |
369 | ,sizeof(ULONG) * QSV_MAX | |
370 | ); | |
371 | if (ulrc == 0L) | |
372 | { | |
373 | *pMajorVsn = ulSysInfo[QSV_VERSION_MAJOR]; | |
374 | *pMajorVsn = *pMajorVsn/10; | |
375 | *pMinorVsn = ulSysInfo[QSV_VERSION_MINOR]; | |
376 | return wxWINDOWS_OS2; | |
377 | } | |
378 | return wxWINDOWS; // error if we get here, return generic value | |
379 | } | |
380 | ||
381 | // Reading and writing resources (eg WIN.INI, .Xdefaults) | |
382 | #if wxUSE_RESOURCES | |
383 | bool wxWriteResource( | |
384 | const wxString& rSection | |
385 | , const wxString& rEntry | |
386 | , const wxString& rValue | |
387 | , const wxString& rFile | |
388 | ) | |
389 | { | |
390 | HAB hab = 0; | |
391 | HINI hIni = 0; | |
392 | ||
393 | if (rFile != "") | |
394 | { | |
395 | hIni = ::PrfOpenProfile(hab, (PSZ)WXSTRINGCAST rFile); | |
396 | if (hIni != 0L) | |
397 | { | |
398 | return (::PrfWriteProfileString( hIni | |
399 | ,(PSZ)WXSTRINGCAST rSection | |
400 | ,(PSZ)WXSTRINGCAST rEntry | |
401 | ,(PSZ)WXSTRINGCAST rValue | |
402 | )); | |
403 | } | |
404 | } | |
405 | else | |
406 | return (::PrfWriteProfileString( HINI_PROFILE | |
407 | ,(PSZ)WXSTRINGCAST rSection | |
408 | ,(PSZ)WXSTRINGCAST rEntry | |
409 | ,(PSZ)WXSTRINGCAST rValue | |
410 | )); | |
411 | return FALSE; | |
412 | } | |
413 | ||
414 | bool wxWriteResource( | |
415 | const wxString& rSection | |
416 | , const wxString& rEntry | |
417 | , float fValue | |
418 | , const wxString& rFile | |
419 | ) | |
420 | { | |
421 | wxChar zBuf[50]; | |
422 | ||
423 | wxSprintf(zBuf, "%.4f", fValue); | |
424 | return wxWriteResource( rSection | |
425 | ,rEntry | |
426 | ,zBuf | |
427 | ,rFile | |
428 | ); | |
429 | } | |
430 | ||
431 | bool wxWriteResource( | |
432 | const wxString& rSection | |
433 | , const wxString& rEntry | |
434 | , long lValue | |
435 | , const wxString& rFile | |
436 | ) | |
437 | { | |
438 | wxChar zBuf[50]; | |
439 | ||
440 | wxSprintf(zBuf, "%ld", lValue); | |
441 | return wxWriteResource( rSection | |
442 | ,rEntry | |
443 | ,zBuf | |
444 | ,rFile | |
445 | ); | |
446 | } | |
447 | ||
448 | bool wxWriteResource( | |
449 | const wxString& rSection | |
450 | , const wxString& rEntry | |
451 | , int lValue | |
452 | , const wxString& rFile | |
453 | ) | |
454 | { | |
455 | wxChar zBuf[50]; | |
456 | ||
457 | wxSprintf(zBuf, "%d", lValue); | |
458 | return wxWriteResource( rSection | |
459 | ,rEntry | |
460 | ,zBuf | |
461 | ,rFile | |
462 | ); | |
463 | } | |
464 | ||
465 | bool wxGetResource( | |
466 | const wxString& rSection | |
467 | , const wxString& rEntry | |
468 | , wxChar** ppValue | |
469 | , const wxString& rFile | |
470 | ) | |
471 | { | |
472 | HAB hab = 0; | |
473 | HINI hIni = 0; | |
474 | wxChar zDefunkt[] = _T("$$default"); | |
475 | char zBuf[1000]; | |
476 | ||
477 | if (rFile != "") | |
478 | { | |
479 | hIni = ::PrfOpenProfile(hab, (PSZ)WXSTRINGCAST rFile); | |
480 | if (hIni != 0L) | |
481 | { | |
482 | ULONG n = ::PrfQueryProfileString( hIni | |
483 | ,(PSZ)WXSTRINGCAST rSection | |
484 | ,(PSZ)WXSTRINGCAST rEntry | |
485 | ,(PSZ)zDefunkt | |
486 | ,(PVOID)zBuf | |
487 | ,1000 | |
488 | ); | |
489 | if (zBuf == NULL) | |
490 | return FALSE; | |
491 | if (n == 0L || wxStrcmp(zBuf, zDefunkt) == 0) | |
492 | return FALSE; | |
493 | zBuf[n-1] = '\0'; | |
494 | } | |
495 | else | |
496 | return FALSE; | |
497 | } | |
498 | else | |
499 | { | |
500 | ULONG n = ::PrfQueryProfileString( HINI_PROFILE | |
501 | ,(PSZ)WXSTRINGCAST rSection | |
502 | ,(PSZ)WXSTRINGCAST rEntry | |
503 | ,(PSZ)zDefunkt | |
504 | ,(PVOID)zBuf | |
505 | ,1000 | |
506 | ); | |
507 | if (zBuf == NULL) | |
508 | return FALSE; | |
509 | if (n == 0L || wxStrcmp(zBuf, zDefunkt) == 0) | |
510 | return FALSE; | |
511 | zBuf[n-1] = '\0'; | |
512 | } | |
513 | strcpy((char*)*ppValue, zBuf); | |
514 | return TRUE; | |
515 | } | |
516 | ||
517 | bool wxGetResource( | |
518 | const wxString& rSection | |
519 | , const wxString& rEntry | |
520 | , float* pValue | |
521 | , const wxString& rFile | |
522 | ) | |
523 | { | |
524 | wxChar* zStr = NULL; | |
525 | ||
526 | zStr = new wxChar[1000]; | |
527 | bool bSucc = wxGetResource( rSection | |
528 | ,rEntry | |
529 | ,(wxChar **)&zStr | |
530 | ,rFile | |
531 | ); | |
532 | ||
533 | if (bSucc) | |
534 | { | |
535 | *pValue = (float)wxStrtod(zStr, NULL); | |
536 | delete[] zStr; | |
537 | return TRUE; | |
538 | } | |
539 | else | |
540 | { | |
541 | delete[] zStr; | |
542 | return FALSE; | |
543 | } | |
544 | } | |
545 | ||
546 | bool wxGetResource( | |
547 | const wxString& rSection | |
548 | , const wxString& rEntry | |
549 | , long* pValue | |
550 | , const wxString& rFile | |
551 | ) | |
552 | { | |
553 | wxChar* zStr = NULL; | |
554 | ||
555 | zStr = new wxChar[1000]; | |
556 | bool bSucc = wxGetResource( rSection | |
557 | ,rEntry | |
558 | ,(wxChar **)&zStr | |
559 | ,rFile | |
560 | ); | |
561 | ||
562 | if (bSucc) | |
563 | { | |
564 | *pValue = wxStrtol(zStr, NULL, 10); | |
565 | delete[] zStr; | |
566 | return TRUE; | |
567 | } | |
568 | else | |
569 | { | |
570 | delete[] zStr; | |
571 | return FALSE; | |
572 | } | |
573 | } | |
574 | ||
575 | bool wxGetResource( | |
576 | const wxString& rSection | |
577 | , const wxString& rEntry | |
578 | , int* pValue | |
579 | , const wxString& rFile | |
580 | ) | |
581 | { | |
582 | wxChar* zStr = NULL; | |
583 | ||
584 | zStr = new wxChar[1000]; | |
585 | bool bSucc = wxGetResource( rSection | |
586 | ,rEntry | |
587 | ,(wxChar **)&zStr | |
588 | ,rFile | |
589 | ); | |
590 | ||
591 | if (bSucc) | |
592 | { | |
593 | *pValue = (int)wxStrtol(zStr, NULL, 10); | |
594 | delete[] zStr; | |
595 | return TRUE; | |
596 | } | |
597 | else | |
598 | { | |
599 | delete[] zStr; | |
600 | return FALSE; | |
601 | } | |
602 | } | |
603 | #endif // wxUSE_RESOURCES | |
604 | ||
605 | // --------------------------------------------------------------------------- | |
606 | // helper functions for showing a "busy" cursor | |
607 | // --------------------------------------------------------------------------- | |
608 | ||
609 | HCURSOR gs_wxBusyCursor = 0; // new, busy cursor | |
610 | HCURSOR gs_wxBusyCursorOld = 0; // old cursor | |
611 | static int gs_wxBusyCursorCount = 0; | |
612 | ||
613 | // Set the cursor to the busy cursor for all windows | |
614 | void wxBeginBusyCursor( | |
615 | wxCursor* pCursor | |
616 | ) | |
617 | { | |
618 | if ( gs_wxBusyCursorCount++ == 0 ) | |
619 | { | |
620 | gs_wxBusyCursor = (HCURSOR)pCursor->GetHCURSOR(); | |
621 | ::WinSetPointer(HWND_DESKTOP, (HPOINTER)gs_wxBusyCursor); | |
622 | } | |
623 | //else: nothing to do, already set | |
624 | } | |
625 | ||
626 | // Restore cursor to normal | |
627 | void wxEndBusyCursor() | |
628 | { | |
629 | wxCHECK_RET( gs_wxBusyCursorCount > 0 | |
630 | ,_T("no matching wxBeginBusyCursor() for wxEndBusyCursor()") | |
631 | ); | |
632 | ||
633 | if (--gs_wxBusyCursorCount == 0) | |
634 | { | |
635 | ::WinSetPointer(HWND_DESKTOP, (HPOINTER)gs_wxBusyCursorOld); | |
636 | gs_wxBusyCursorOld = 0; | |
637 | } | |
638 | } | |
639 | ||
640 | // TRUE if we're between the above two calls | |
641 | bool wxIsBusy() | |
642 | { | |
643 | return (gs_wxBusyCursorCount > 0); | |
644 | } | |
645 | ||
646 | // --------------------------------------------------------------------------- | |
647 | const wxChar* wxGetHomeDir( | |
648 | wxString* pStr | |
649 | ) | |
650 | { | |
651 | wxString& rStrDir = *pStr; | |
652 | ||
653 | // OS/2 has no idea about home, | |
654 | // so use the working directory instead? | |
655 | ||
656 | // 256 was taken from os2def.h | |
657 | #ifndef MAX_PATH | |
658 | # define MAX_PATH 256 | |
659 | #endif | |
660 | ||
661 | char zDirName[256]; | |
662 | ULONG ulDirLen; | |
663 | ||
664 | ::DosQueryCurrentDir(0, zDirName, &ulDirLen); | |
665 | rStrDir = zDirName; | |
666 | return rStrDir.c_str(); | |
667 | } | |
668 | ||
669 | // Hack for OS/2 | |
670 | wxChar* wxGetUserHome ( | |
671 | const wxString& rUser | |
672 | ) | |
673 | { | |
674 | wxChar* zHome; | |
675 | wxString sUser1(rUser); | |
676 | ||
677 | wxBuffer = new wxChar[256]; | |
678 | #ifndef __EMX__ | |
679 | if (sUser1 != _T("")) | |
680 | { | |
681 | wxChar zTmp[64]; | |
682 | ||
683 | if (wxGetUserId( zTmp | |
684 | ,sizeof(zTmp)/sizeof(char) | |
685 | )) | |
686 | { | |
687 | // Guests belong in the temp dir | |
688 | if (wxStricmp(zTmp, _T("annonymous")) == 0) | |
689 | { | |
690 | if ((zHome = wxGetenv(_T("TMP"))) != NULL || | |
691 | (zHome = wxGetenv(_T("TMPDIR"))) != NULL || | |
692 | (zHome = wxGetenv(_T("TEMP"))) != NULL) | |
693 | delete[] wxBuffer; | |
694 | return *zHome ? zHome : (wxChar*)_T("\\"); | |
695 | } | |
696 | if (wxStricmp(zTmp, WXSTRINGCAST sUser1) == 0) | |
697 | sUser1 = _T(""); | |
698 | } | |
699 | } | |
700 | #endif | |
701 | if (sUser1 == _T("")) | |
702 | { | |
703 | if ((zHome = wxGetenv(_T("HOME"))) != NULL) | |
704 | { | |
705 | wxStrcpy(wxBuffer, zHome); | |
706 | Unix2DosFilename(wxBuffer); | |
707 | wxStrcpy(zHome, wxBuffer); | |
708 | delete[] wxBuffer; | |
709 | return zHome; | |
710 | } | |
711 | } | |
712 | delete[] wxBuffer; | |
713 | return NULL; // No home known! | |
714 | } | |
715 | ||
716 | // Check whether this window wants to process messages, e.g. Stop button | |
717 | // in long calculations. | |
718 | bool wxCheckForInterrupt( | |
719 | wxWindow* pWnd | |
720 | ) | |
721 | { | |
722 | if(pWnd) | |
723 | { | |
724 | QMSG vMsg; | |
725 | HAB hab = 0; | |
726 | HWND hwndFilter = NULLHANDLE; | |
727 | HWND hwndWin= (HWND) pWnd->GetHWND(); | |
728 | ||
729 | while(::WinPeekMsg(hab, &vMsg, hwndFilter, 0, 0, PM_REMOVE)) | |
730 | { | |
731 | ::WinDispatchMsg(hab, &vMsg); | |
732 | } | |
733 | return TRUE;//*** temporary? | |
734 | } | |
735 | else | |
736 | { | |
737 | wxFAIL_MSG(_T("pWnd==NULL !!!")); | |
738 | return FALSE;//*** temporary? | |
739 | } | |
740 | } | |
741 | ||
742 | void wxGetMousePosition( | |
743 | int* pX | |
744 | , int* pY | |
745 | ) | |
746 | { | |
747 | POINTL vPt; | |
748 | ||
749 | ::WinQueryPointerPos(HWND_DESKTOP, &vPt); | |
750 | *pX = vPt.x; | |
751 | *pY = vPt.y; | |
752 | }; | |
753 | ||
754 | // Return TRUE if we have a colour display | |
755 | bool wxColourDisplay() | |
756 | { | |
757 | #if 0 | |
758 | HPS hpsScreen; | |
759 | HDC hdcScreen; | |
760 | LONG lColors; | |
761 | ||
762 | hpsScreen = ::WinGetScreenPS(HWND_DESKTOP); | |
763 | hdcScreen = ::GpiQueryDevice(hpsScreen); | |
764 | ::DevQueryCaps(hdcScreen, CAPS_COLORS, 1L, &lColors); | |
765 | return(lColors > 1L); | |
766 | #else | |
767 | // I don't see how the PM display could not be color. Besides, this | |
768 | // was leaking DCs and PSs!!! MN | |
769 | return TRUE; | |
770 | #endif | |
771 | } | |
772 | ||
773 | // Returns depth of screen | |
774 | int wxDisplayDepth() | |
775 | { | |
776 | HPS hpsScreen; | |
777 | HDC hdcScreen; | |
778 | LONG lPlanes; | |
779 | LONG lBitsPerPixel; | |
780 | static LONG nDepth = 0; | |
781 | ||
782 | // The screen colordepth ain't gonna change. No reason to query | |
783 | // it over and over! | |
784 | if (!nDepth) { | |
785 | hpsScreen = ::WinGetScreenPS(HWND_DESKTOP); | |
786 | hdcScreen = ::GpiQueryDevice(hpsScreen); | |
787 | ::DevQueryCaps(hdcScreen, CAPS_COLOR_PLANES, 1L, &lPlanes); | |
788 | ::DevQueryCaps(hdcScreen, CAPS_COLOR_BITCOUNT, 1L, &lBitsPerPixel); | |
789 | ||
790 | nDepth = (int)(lPlanes * lBitsPerPixel); | |
791 | ::DevCloseDC(hdcScreen); | |
792 | ::WinReleasePS(hpsScreen); | |
793 | } | |
794 | return (nDepth); | |
795 | } | |
796 | ||
797 | // Get size of display | |
798 | void wxDisplaySize( | |
799 | int* pWidth | |
800 | , int* pHeight | |
801 | ) | |
802 | { | |
803 | HPS hpsScreen; | |
804 | HDC hdcScreen; | |
805 | static LONG lWidth = 0; | |
806 | static LONG lHeight = 0; | |
807 | ||
808 | // The screen size ain't gonna change either so just cache the values | |
809 | if (!lWidth) { | |
810 | hpsScreen = ::WinGetScreenPS(HWND_DESKTOP); | |
811 | hdcScreen = ::GpiQueryDevice(hpsScreen); | |
812 | ::DevQueryCaps(hdcScreen, CAPS_WIDTH, 1L, &lWidth); | |
813 | ::DevQueryCaps(hdcScreen, CAPS_HEIGHT, 1L, &lHeight); | |
814 | ::DevCloseDC(hdcScreen); | |
815 | ::WinReleasePS(hpsScreen); | |
816 | } | |
817 | *pWidth = (int)lWidth; | |
818 | *pHeight = (int)lHeight; | |
819 | } | |
820 | ||
821 | void wxDisplaySizeMM( | |
822 | int* pWidth | |
823 | , int* pHeight | |
824 | ) | |
825 | { | |
826 | HPS hpsScreen; | |
827 | HDC hdcScreen; | |
828 | ||
829 | hpsScreen = ::WinGetScreenPS(HWND_DESKTOP); | |
830 | hdcScreen = ::GpiQueryDevice(hpsScreen); | |
831 | ||
832 | if (pWidth) | |
833 | ::DevQueryCaps( hdcScreen | |
834 | ,CAPS_HORIZONTAL_RESOLUTION | |
835 | ,1L | |
836 | ,(PLONG)pWidth | |
837 | ); | |
838 | if (pHeight) | |
839 | ::DevQueryCaps( hdcScreen | |
840 | ,CAPS_VERTICAL_RESOLUTION | |
841 | ,1L | |
842 | ,(PLONG)pHeight | |
843 | ); | |
844 | ::DevCloseDC(hdcScreen); | |
845 | ::WinReleasePS(hpsScreen); | |
846 | } | |
847 | ||
848 | void wxClientDisplayRect(int *x, int *y, int *width, int *height) | |
849 | { | |
850 | // This is supposed to return desktop dimensions minus any window | |
851 | // manager panels, menus, taskbars, etc. If there is a way to do that | |
852 | // for this platform please fix this function, otherwise it defaults | |
853 | // to the entire desktop. | |
854 | if (x) *x = 0; | |
855 | if (y) *y = 0; | |
856 | wxDisplaySize(width, height); | |
857 | } | |
858 | ||
859 | ||
860 | bool wxDirExists( | |
861 | const wxString& rDir | |
862 | ) | |
863 | { | |
864 | return (::DosSetCurrentDir(WXSTRINGCAST rDir)); | |
865 | } | |
866 | ||
867 | // --------------------------------------------------------------------------- | |
868 | // window information functions | |
869 | // --------------------------------------------------------------------------- | |
870 | ||
871 | wxString WXDLLEXPORT wxGetWindowText( | |
872 | WXHWND hWnd | |
873 | ) | |
874 | { | |
875 | wxString vStr; | |
876 | long lLen = ::WinQueryWindowTextLength((HWND)hWnd) + 1; | |
877 | ||
878 | ::WinQueryWindowText((HWND)hWnd, lLen, vStr.GetWriteBuf((int)lLen)); | |
879 | vStr.UngetWriteBuf(); | |
880 | ||
881 | return vStr; | |
882 | } | |
883 | ||
884 | wxString WXDLLEXPORT wxGetWindowClass( | |
885 | WXHWND hWnd | |
886 | ) | |
887 | { | |
888 | wxString vStr; | |
889 | int nLen = 256; // some starting value | |
890 | ||
891 | for ( ;; ) | |
892 | { | |
893 | int nCount = ::WinQueryClassName((HWND)hWnd, nLen, vStr.GetWriteBuf(nLen)); | |
894 | ||
895 | vStr.UngetWriteBuf(); | |
896 | if (nCount == nLen ) | |
897 | { | |
898 | // the class name might have been truncated, retry with larger | |
899 | // buffer | |
900 | nLen *= 2; | |
901 | } | |
902 | else | |
903 | { | |
904 | break; | |
905 | } | |
906 | } | |
907 | return vStr; | |
908 | } | |
909 | ||
910 | WXWORD WXDLLEXPORT wxGetWindowId( | |
911 | WXHWND hWnd | |
912 | ) | |
913 | { | |
914 | return ::WinQueryWindowUShort((HWND)hWnd, QWS_ID); | |
915 | } | |
916 | ||
917 | wxString WXDLLEXPORT wxPMErrorToStr( | |
918 | ERRORID vError | |
919 | ) | |
920 | { | |
921 | wxString sError; | |
922 | ||
923 | // | |
924 | // Remove the high order byte -- it is useless | |
925 | // | |
926 | vError &= 0x0000ffff; | |
927 | switch(vError) | |
928 | { | |
929 | case PMERR_INVALID_HWND: | |
930 | sError = wxT("Invalid window handle specified"); | |
931 | break; | |
932 | ||
933 | case PMERR_INVALID_FLAG: | |
934 | sError = wxT("Invalid flag bit set"); | |
935 | break; | |
936 | ||
937 | case PMERR_NO_MSG_QUEUE: | |
938 | sError = wxT("No message queue available"); | |
939 | break; | |
940 | ||
941 | case PMERR_INVALID_PARM: | |
942 | sError = wxT("Parameter contained invalid data"); | |
943 | break; | |
944 | ||
945 | case PMERR_INVALID_PARAMETERS: | |
946 | sError = wxT("Parameter value is out of range"); | |
947 | break; | |
948 | ||
949 | case PMERR_PARAMETER_OUT_OF_RANGE: | |
950 | sError = wxT("Parameter value is out of range"); | |
951 | break; | |
952 | ||
953 | case PMERR_INVALID_INTEGER_ATOM: | |
954 | sError = wxT("Not a valid atom"); | |
955 | break; | |
956 | ||
957 | case PMERR_INVALID_HATOMTBL: | |
958 | sError = wxT("Atom table handle is invalid"); | |
959 | break; | |
960 | ||
961 | case PMERR_INVALID_ATOM_NAME: | |
962 | sError = wxT("Not a valid atom name"); | |
963 | break; | |
964 | ||
965 | case PMERR_ATOM_NAME_NOT_FOUND: | |
966 | sError = wxT("Valid name format, but cannot find name in atom table"); | |
967 | break; | |
968 | ||
969 | default: | |
970 | sError = wxT("Unknown error"); | |
971 | } | |
972 | return(sError); | |
973 | } // end of wxPMErrorToStr | |
974 | ||
975 | void wxDrawBorder( | |
976 | HPS hPS | |
977 | , RECTL& rRect | |
978 | , WXDWORD dwStyle | |
979 | ) | |
980 | { | |
981 | POINTL vPoint[2]; | |
982 | ||
983 | vPoint[0].x = rRect.xLeft; | |
984 | vPoint[0].y = rRect.yBottom; | |
985 | ::GpiMove(hPS, &vPoint[0]); | |
986 | if (dwStyle & wxSIMPLE_BORDER || | |
987 | dwStyle & wxSTATIC_BORDER) | |
988 | { | |
989 | vPoint[1].x = rRect.xRight - 1; | |
990 | vPoint[1].y = rRect.yTop - 1; | |
991 | ::GpiBox( hPS | |
992 | ,DRO_OUTLINE | |
993 | ,&vPoint[1] | |
994 | ,0L | |
995 | ,0L | |
996 | ); | |
997 | } | |
998 | if (dwStyle & wxSUNKEN_BORDER) | |
999 | { | |
1000 | LINEBUNDLE vLineBundle; | |
1001 | ||
1002 | vLineBundle.lColor = 0x00FFFFFF; // WHITE | |
1003 | vLineBundle.usMixMode = FM_OVERPAINT; | |
1004 | vLineBundle.fxWidth = 2; | |
1005 | vLineBundle.lGeomWidth = 2; | |
1006 | vLineBundle.usType = LINETYPE_SOLID; | |
1007 | vLineBundle.usEnd = 0; | |
1008 | vLineBundle.usJoin = 0; | |
1009 | ::GpiSetAttrs( hPS | |
1010 | ,PRIM_LINE | |
1011 | ,LBB_COLOR | LBB_MIX_MODE | LBB_WIDTH | LBB_GEOM_WIDTH | LBB_TYPE | |
1012 | ,0L | |
1013 | ,&vLineBundle | |
1014 | ); | |
1015 | vPoint[1].x = rRect.xRight - 1; | |
1016 | vPoint[1].y = rRect.yTop - 1; | |
1017 | ::GpiBox( hPS | |
1018 | ,DRO_OUTLINE | |
1019 | ,&vPoint[1] | |
1020 | ,0L | |
1021 | ,0L | |
1022 | ); | |
1023 | vPoint[0].x = rRect.xLeft + 1; | |
1024 | vPoint[0].y = rRect.yBottom + 1; | |
1025 | ::GpiMove(hPS, &vPoint[0]); | |
1026 | vPoint[1].x = rRect.xRight - 2; | |
1027 | vPoint[1].y = rRect.yTop - 2; | |
1028 | ::GpiBox( hPS | |
1029 | ,DRO_OUTLINE | |
1030 | ,&vPoint[1] | |
1031 | ,0L | |
1032 | ,0L | |
1033 | ); | |
1034 | ||
1035 | vLineBundle.lColor = 0x00000000; // BLACK | |
1036 | vLineBundle.usMixMode = FM_OVERPAINT; | |
1037 | vLineBundle.fxWidth = 2; | |
1038 | vLineBundle.lGeomWidth = 2; | |
1039 | vLineBundle.usType = LINETYPE_SOLID; | |
1040 | vLineBundle.usEnd = 0; | |
1041 | vLineBundle.usJoin = 0; | |
1042 | ::GpiSetAttrs( hPS | |
1043 | ,PRIM_LINE | |
1044 | ,LBB_COLOR | LBB_MIX_MODE | LBB_WIDTH | LBB_GEOM_WIDTH | LBB_TYPE | |
1045 | ,0L | |
1046 | ,&vLineBundle | |
1047 | ); | |
1048 | vPoint[0].x = rRect.xLeft + 2; | |
1049 | vPoint[0].y = rRect.yBottom + 2; | |
1050 | ::GpiMove(hPS, &vPoint[0]); | |
1051 | vPoint[1].x = rRect.xLeft + 2; | |
1052 | vPoint[1].y = rRect.yTop - 3; | |
1053 | ::GpiLine(hPS, &vPoint[1]); | |
1054 | vPoint[1].x = rRect.xRight - 3; | |
1055 | vPoint[1].y = rRect.yTop - 3; | |
1056 | ::GpiLine(hPS, &vPoint[1]); | |
1057 | ||
1058 | vPoint[0].x = rRect.xLeft + 3; | |
1059 | vPoint[0].y = rRect.yBottom + 3; | |
1060 | ::GpiMove(hPS, &vPoint[0]); | |
1061 | vPoint[1].x = rRect.xLeft + 3; | |
1062 | vPoint[1].y = rRect.yTop - 4; | |
1063 | ::GpiLine(hPS, &vPoint[1]); | |
1064 | vPoint[1].x = rRect.xRight - 4; | |
1065 | vPoint[1].y = rRect.yTop - 4; | |
1066 | ::GpiLine(hPS, &vPoint[1]); | |
1067 | } | |
1068 | if (dwStyle & wxDOUBLE_BORDER) | |
1069 | { | |
1070 | LINEBUNDLE vLineBundle; | |
1071 | ||
1072 | vLineBundle.lColor = 0x00FFFFFF; // WHITE | |
1073 | vLineBundle.usMixMode = FM_OVERPAINT; | |
1074 | vLineBundle.fxWidth = 2; | |
1075 | vLineBundle.lGeomWidth = 2; | |
1076 | vLineBundle.usType = LINETYPE_SOLID; | |
1077 | vLineBundle.usEnd = 0; | |
1078 | vLineBundle.usJoin = 0; | |
1079 | ::GpiSetAttrs( hPS | |
1080 | ,PRIM_LINE | |
1081 | ,LBB_COLOR | LBB_MIX_MODE | LBB_WIDTH | LBB_GEOM_WIDTH | LBB_TYPE | |
1082 | ,0L | |
1083 | ,&vLineBundle | |
1084 | ); | |
1085 | vPoint[1].x = rRect.xRight - 1; | |
1086 | vPoint[1].y = rRect.yTop - 1; | |
1087 | ::GpiBox( hPS | |
1088 | ,DRO_OUTLINE | |
1089 | ,&vPoint[1] | |
1090 | ,0L | |
1091 | ,0L | |
1092 | ); | |
1093 | vLineBundle.lColor = 0x00000000; // WHITE | |
1094 | vLineBundle.usMixMode = FM_OVERPAINT; | |
1095 | vLineBundle.fxWidth = 2; | |
1096 | vLineBundle.lGeomWidth = 2; | |
1097 | vLineBundle.usType = LINETYPE_SOLID; | |
1098 | vLineBundle.usEnd = 0; | |
1099 | vLineBundle.usJoin = 0; | |
1100 | ::GpiSetAttrs( hPS | |
1101 | ,PRIM_LINE | |
1102 | ,LBB_COLOR | LBB_MIX_MODE | LBB_WIDTH | LBB_GEOM_WIDTH | LBB_TYPE | |
1103 | ,0L | |
1104 | ,&vLineBundle | |
1105 | ); | |
1106 | vPoint[0].x = rRect.xLeft + 2; | |
1107 | vPoint[0].y = rRect.yBottom + 2; | |
1108 | ::GpiMove(hPS, &vPoint[0]); | |
1109 | vPoint[1].x = rRect.xRight - 2; | |
1110 | vPoint[1].y = rRect.yTop - 2; | |
1111 | ::GpiBox( hPS | |
1112 | ,DRO_OUTLINE | |
1113 | ,&vPoint[1] | |
1114 | ,0L | |
1115 | ,0L | |
1116 | ); | |
1117 | vLineBundle.lColor = 0x00FFFFFF; // BLACK | |
1118 | vLineBundle.usMixMode = FM_OVERPAINT; | |
1119 | vLineBundle.fxWidth = 2; | |
1120 | vLineBundle.lGeomWidth = 2; | |
1121 | vLineBundle.usType = LINETYPE_SOLID; | |
1122 | vLineBundle.usEnd = 0; | |
1123 | vLineBundle.usJoin = 0; | |
1124 | ::GpiSetAttrs( hPS | |
1125 | ,PRIM_LINE | |
1126 | ,LBB_COLOR | LBB_MIX_MODE | LBB_WIDTH | LBB_GEOM_WIDTH | LBB_TYPE | |
1127 | ,0L | |
1128 | ,&vLineBundle | |
1129 | ); | |
1130 | vPoint[0].x = rRect.xLeft + 3; | |
1131 | vPoint[0].y = rRect.yBottom + 3; | |
1132 | ::GpiMove(hPS, &vPoint[0]); | |
1133 | vPoint[1].x = rRect.xRight - 3; | |
1134 | vPoint[1].y = rRect.yTop - 3; | |
1135 | ::GpiBox( hPS | |
1136 | ,DRO_OUTLINE | |
1137 | ,&vPoint[1] | |
1138 | ,0L | |
1139 | ,0L | |
1140 | ); | |
1141 | } | |
1142 | if (dwStyle & wxRAISED_BORDER) | |
1143 | { | |
1144 | LINEBUNDLE vLineBundle; | |
1145 | ||
1146 | vLineBundle.lColor = 0x00000000; // BLACK | |
1147 | vLineBundle.usMixMode = FM_OVERPAINT; | |
1148 | vLineBundle.fxWidth = 2; | |
1149 | vLineBundle.lGeomWidth = 2; | |
1150 | vLineBundle.usType = LINETYPE_SOLID; | |
1151 | vLineBundle.usEnd = 0; | |
1152 | vLineBundle.usJoin = 0; | |
1153 | ::GpiSetAttrs( hPS | |
1154 | ,PRIM_LINE | |
1155 | ,LBB_COLOR | LBB_MIX_MODE | LBB_WIDTH | LBB_GEOM_WIDTH | LBB_TYPE | |
1156 | ,0L | |
1157 | ,&vLineBundle | |
1158 | ); | |
1159 | vPoint[1].x = rRect.xRight - 1; | |
1160 | vPoint[1].y = rRect.yTop - 1; | |
1161 | ::GpiBox( hPS | |
1162 | ,DRO_OUTLINE | |
1163 | ,&vPoint[1] | |
1164 | ,0L | |
1165 | ,0L | |
1166 | ); | |
1167 | vPoint[0].x = rRect.xLeft + 1; | |
1168 | vPoint[0].y = rRect.yBottom + 1; | |
1169 | ::GpiMove(hPS, &vPoint[0]); | |
1170 | vPoint[1].x = rRect.xRight - 2; | |
1171 | vPoint[1].y = rRect.yTop - 2; | |
1172 | ::GpiBox( hPS | |
1173 | ,DRO_OUTLINE | |
1174 | ,&vPoint[1] | |
1175 | ,0L | |
1176 | ,0L | |
1177 | ); | |
1178 | ||
1179 | vLineBundle.lColor = 0x00FFFFFF; // WHITE | |
1180 | vLineBundle.usMixMode = FM_OVERPAINT; | |
1181 | vLineBundle.fxWidth = 2; | |
1182 | vLineBundle.lGeomWidth = 2; | |
1183 | vLineBundle.usType = LINETYPE_SOLID; | |
1184 | vLineBundle.usEnd = 0; | |
1185 | vLineBundle.usJoin = 0; | |
1186 | ::GpiSetAttrs( hPS | |
1187 | ,PRIM_LINE | |
1188 | ,LBB_COLOR | LBB_MIX_MODE | LBB_WIDTH | LBB_GEOM_WIDTH | LBB_TYPE | |
1189 | ,0L | |
1190 | ,&vLineBundle | |
1191 | ); | |
1192 | vPoint[0].x = rRect.xLeft + 2; | |
1193 | vPoint[0].y = rRect.yBottom + 2; | |
1194 | ::GpiMove(hPS, &vPoint[0]); | |
1195 | vPoint[1].x = rRect.xLeft + 2; | |
1196 | vPoint[1].y = rRect.yTop - 3; | |
1197 | ::GpiLine(hPS, &vPoint[1]); | |
1198 | vPoint[1].x = rRect.xRight - 3; | |
1199 | vPoint[1].y = rRect.yTop - 3; | |
1200 | ::GpiLine(hPS, &vPoint[1]); | |
1201 | ||
1202 | vPoint[0].x = rRect.xLeft + 3; | |
1203 | vPoint[0].y = rRect.yBottom + 3; | |
1204 | ::GpiMove(hPS, &vPoint[0]); | |
1205 | vPoint[1].x = rRect.xLeft + 3; | |
1206 | vPoint[1].y = rRect.yTop - 4; | |
1207 | ::GpiLine(hPS, &vPoint[1]); | |
1208 | vPoint[1].x = rRect.xRight - 4; | |
1209 | vPoint[1].y = rRect.yTop - 4; | |
1210 | ::GpiLine(hPS, &vPoint[1]); | |
1211 | } | |
1212 | } // end of wxDrawBorder | |
1213 | ||
1214 | void wxOS2SetFont( | |
1215 | HWND hWnd | |
1216 | , const wxFont& rFont | |
1217 | ) | |
1218 | { | |
1219 | char zFont[128]; | |
1220 | char zFacename[30]; | |
1221 | char zWeight[30]; | |
1222 | char zStyle[30]; | |
1223 | ||
1224 | if (hWnd == NULLHANDLE) | |
1225 | return; | |
1226 | ||
1227 | // | |
1228 | // The fonts available for Presentation Params are just three | |
1229 | // outline fonts, the rest are available to the GPI, so we must | |
1230 | // map the families to one of these three | |
1231 | // | |
1232 | switch(rFont.GetFamily()) | |
1233 | { | |
1234 | case wxSCRIPT: | |
1235 | strcpy(zFacename, "Script"); | |
1236 | break; | |
1237 | ||
1238 | case wxDECORATIVE: | |
1239 | case wxROMAN: | |
1240 | strcpy(zFacename,"Tms Rmn"); | |
1241 | break; | |
1242 | ||
1243 | case wxTELETYPE: | |
1244 | strcpy(zFacename, "Courier"); | |
1245 | break; | |
1246 | ||
1247 | case wxMODERN: | |
1248 | strcpy(zFacename, "System VIO"); | |
1249 | break; | |
1250 | ||
1251 | case wxSWISS: | |
1252 | strcpy(zFacename, "Helv"); | |
1253 | break; | |
1254 | ||
1255 | case wxDEFAULT: | |
1256 | default: | |
1257 | strcpy(zFacename, "System VIO"); | |
1258 | break; | |
1259 | } | |
1260 | ||
1261 | switch(rFont.GetWeight()) | |
1262 | { | |
1263 | default: | |
1264 | case wxNORMAL: | |
1265 | case wxLIGHT: | |
1266 | zWeight[0] = '\0'; | |
1267 | break; | |
1268 | ||
1269 | case wxBOLD: | |
1270 | case wxFONTWEIGHT_MAX: | |
1271 | strcpy(zWeight, "Bold"); | |
1272 | break; | |
1273 | } | |
1274 | ||
1275 | switch(rFont.GetStyle()) | |
1276 | { | |
1277 | case wxITALIC: | |
1278 | case wxSLANT: | |
1279 | strcpy(zStyle, "Italic"); | |
1280 | break; | |
1281 | ||
1282 | default: | |
1283 | zStyle[0] = '\0'; | |
1284 | break; | |
1285 | } | |
1286 | sprintf(zFont, "%d.%s", rFont.GetPointSize(), zFacename); | |
1287 | if (zWeight[0] != '\0') | |
1288 | { | |
1289 | strcat(zFont, " "); | |
1290 | strcat(zFont, zWeight); | |
1291 | } | |
1292 | if (zStyle[0] != '\0') | |
1293 | { | |
1294 | strcat(zFont, " "); | |
1295 | strcat(zFont, zStyle); | |
1296 | } | |
1297 | ::WinSetPresParam(hWnd, PP_FONTNAMESIZE, strlen(zFont) + 1, (PVOID)zFont); | |
1298 | } // end of wxOS2SetFont |