]> git.saurik.com Git - wxWidgets.git/blame - src/motif/utils.cpp
wxUSE_IOSTREAMH changes
[wxWidgets.git] / src / motif / utils.cpp
CommitLineData
4bb6408c
JS
1/////////////////////////////////////////////////////////////////////////////
2// Name: utils.cpp
3// Purpose: Various utilities
4// Author: Julian Smart
5// Modified by:
6// Created: 17/09/98
7// RCS-ID: $Id$
8// Copyright: (c) Julian Smart
9// Licence: wxWindows licence
10/////////////////////////////////////////////////////////////////////////////
11
12#ifdef __GNUG__
13// Note: this is done in utilscmn.cpp now.
14// #pragma implementation
15// #pragma implementation "utils.h"
16#endif
17
18#include "wx/setup.h"
19#include "wx/utils.h"
20#include "wx/app.h"
21
22#include <ctype.h>
23
24#include <stdio.h>
25#include <stdlib.h>
26#include <string.h>
27#include <stdarg.h>
28
29#include <Xm/Xm.h>
30
50414e24
JS
31#include "wx/motif/private.h"
32
4bb6408c
JS
33// Get full hostname (eg. DoDo.BSn-Germany.crg.de)
34bool wxGetHostName(char *buf, int maxSize)
35{
36 // TODO
37 return FALSE;
38}
39
40// Get user ID e.g. jacs
41bool wxGetUserId(char *buf, int maxSize)
42{
43 // TODO
44 return FALSE;
45}
46
47// Get user name e.g. Julian Smart
48bool wxGetUserName(char *buf, int maxSize)
49{
50 // TODO
51 return FALSE;
52}
53
54int wxKill(long pid, int sig)
55{
56 // TODO
57 return 0;
58}
59
60//
61// Execute a program in an Interactive Shell
62//
63bool wxShell(const wxString& command)
64{
65 // TODO
66 return FALSE;
67}
68
69// Get free memory in bytes, or -1 if cannot determine amount (e.g. on UNIX)
70long wxGetFreeMemory()
71{
72 // TODO
73 return 0;
74}
75
76void wxSleep(int nSecs)
77{
78 // TODO
79}
80
81// Consume all events until no more left
82void wxFlushEvents()
83{
84}
85
86// Output a debug message, in a system dependent fashion.
87void wxDebugMsg(const char *fmt ...)
88{
89 va_list ap;
90 static char buffer[512];
91
92 if (!wxTheApp->GetWantDebugOutput())
93 return ;
94
95 va_start(ap, fmt);
96
97 // wvsprintf(buffer,fmt,ap) ;
98 // TODO: output buffer
99
100 va_end(ap);
101}
102
103// Non-fatal error: pop up message box and (possibly) continue
104void wxError(const wxString& msg, const wxString& title)
105{
106 // TODO
107 wxExit();
108}
109
110// Fatal error: pop up message box and abort
111void wxFatalError(const wxString& msg, const wxString& title)
112{
113 // TODO
114}
115
116// Emit a beeeeeep
117void wxBell()
118{
119 // TODO
120}
121
122int wxGetOsVersion(int *majorVsn, int *minorVsn)
123{
124 // TODO
125 return 0;
126}
127
128// Reading and writing resources (eg WIN.INI, .Xdefaults)
47d67540 129#if wxUSE_RESOURCES
4bb6408c
JS
130bool wxWriteResource(const wxString& section, const wxString& entry, const wxString& value, const wxString& file)
131{
132 // TODO
133 return FALSE;
134}
135
136bool wxWriteResource(const wxString& section, const wxString& entry, float value, const wxString& file)
137{
138 char buf[50];
139 sprintf(buf, "%.4f", value);
140 return wxWriteResource(section, entry, buf, file);
141}
142
143bool wxWriteResource(const wxString& section, const wxString& entry, long value, const wxString& file)
144{
145 char buf[50];
146 sprintf(buf, "%ld", value);
147 return wxWriteResource(section, entry, buf, file);
148}
149
150bool wxWriteResource(const wxString& section, const wxString& entry, int value, const wxString& file)
151{
152 char buf[50];
153 sprintf(buf, "%d", value);
154 return wxWriteResource(section, entry, buf, file);
155}
156
157bool wxGetResource(const wxString& section, const wxString& entry, char **value, const wxString& file)
158{
159 // TODO
160 return FALSE;
161}
162
163bool wxGetResource(const wxString& section, const wxString& entry, float *value, const wxString& file)
164{
165 char *s = NULL;
166 bool succ = wxGetResource(section, entry, (char **)&s, file);
167 if (succ)
168 {
169 *value = (float)strtod(s, NULL);
170 delete[] s;
171 return TRUE;
172 }
173 else return FALSE;
174}
175
176bool wxGetResource(const wxString& section, const wxString& entry, long *value, const wxString& file)
177{
178 char *s = NULL;
179 bool succ = wxGetResource(section, entry, (char **)&s, file);
180 if (succ)
181 {
182 *value = strtol(s, NULL, 10);
183 delete[] s;
184 return TRUE;
185 }
186 else return FALSE;
187}
188
189bool wxGetResource(const wxString& section, const wxString& entry, int *value, const wxString& file)
190{
191 char *s = NULL;
192 bool succ = wxGetResource(section, entry, (char **)&s, file);
193 if (succ)
194 {
195 *value = (int)strtol(s, NULL, 10);
196 delete[] s;
197 return TRUE;
198 }
199 else return FALSE;
200}
47d67540 201#endif // wxUSE_RESOURCES
4bb6408c
JS
202
203static int wxBusyCursorCount = 0;
204
205// Set the cursor to the busy cursor for all windows
206void wxBeginBusyCursor(wxCursor *cursor)
207{
208 wxBusyCursorCount ++;
209 if (wxBusyCursorCount == 1)
210 {
211 // TODO
212 }
213 else
214 {
215 // TODO
216 }
217}
218
219// Restore cursor to normal
220void wxEndBusyCursor()
221{
222 if (wxBusyCursorCount == 0)
223 return;
224
225 wxBusyCursorCount --;
226 if (wxBusyCursorCount == 0)
227 {
228 // TODO
229 }
230}
231
232// TRUE if we're between the above two calls
233bool wxIsBusy()
234{
235 return (wxBusyCursorCount > 0);
236}
237
238char *wxGetUserHome (const wxString& user)
239{
240 // TODO
241 return NULL;
242}
243
244// Check whether this window wants to process messages, e.g. Stop button
245// in long calculations.
246bool wxCheckForInterrupt(wxWindow *wnd)
247{
248 // TODO
249 return FALSE;
250}
251
252void wxGetMousePosition( int* x, int* y )
253{
254 // TODO
255};
256
257// Return TRUE if we have a colour display
258bool wxColourDisplay()
259{
dfc54541
JS
260 Display *dpy = (Display*) wxGetDisplay();
261
262 if (DefaultDepth (dpy, DefaultScreen (dpy)) < 2)
263 return FALSE;
264 else
265 return TRUE;
4bb6408c
JS
266}
267
268// Returns depth of screen
269int wxDisplayDepth()
270{
dfc54541
JS
271 Display *dpy = (Display*) wxGetDisplay();
272 return DefaultDepth (dpy, DefaultScreen (dpy));
4bb6408c
JS
273}
274
275// Get size of display
276void wxDisplaySize(int *width, int *height)
277{
dfc54541
JS
278 Display *dpy = (Display*) wxGetDisplay();
279
280 *width = DisplayWidth (dpy, DefaultScreen (dpy));
281 *height = DisplayHeight (dpy, DefaultScreen (dpy));
4bb6408c
JS
282}
283
284/* Configurable display in Motif */
285static WXDisplay *gs_currentDisplay = NULL;
286static wxString gs_displayName;
287
288WXDisplay *wxGetDisplay()
289{
290 if (gs_currentDisplay)
291 return gs_currentDisplay;
292
47bc1060
JS
293 if (wxTheApp && wxTheApp->GetTopLevelWidget())
294 return XtDisplay ((Widget) wxTheApp->GetTopLevelWidget());
295 else if (wxTheApp)
296 return wxTheApp->GetInitialDisplay();
297 else
298 return (WXDisplay*) NULL;
4bb6408c
JS
299}
300
301bool wxSetDisplay(const wxString& display_name)
302{
303 gs_displayName = display_name;
304
305 if (display_name.IsNull() || display_name.IsEmpty())
306 {
307 gs_currentDisplay = NULL;
308 return TRUE;
309 }
310 else
311 {
312 Cardinal argc = 0;
313
314 Display *display = XtOpenDisplay((XtAppContext) wxTheApp->GetAppContext(),
315 (const char*) display_name,
316 (const char*) wxTheApp->GetAppName(),
317 (const char*) wxTheApp->GetClassName(),
318 NULL,
319# if XtSpecificationRelease < 5
320 0, &argc, NULL);
321# else
322 0, (int *)&argc, NULL);
323# endif
324
325 if (display)
326 {
327 gs_currentDisplay = (WXDisplay*) display;
328 return TRUE;
329 } else
330 return FALSE;
331 }
332 return FALSE;
333}
334
335wxString wxGetDisplayName()
336{
337 return gs_displayName;
338}
50414e24
JS
339
340// Find the letter corresponding to the mnemonic, for Motif
341char wxFindMnemonic (const char *s)
342{
343 char mnem = 0;
344 int len = strlen (s);
345 int i;
346 for (i = 0; i < len; i++)
347 {
348 if (s[i] == '&')
349 {
350 // Carefully handle &&
351 if ((i + 1) <= len && s[i + 1] == '&')
352 i++;
353 else
354 {
355 mnem = s[i + 1];
356 break;
357 }
358 }
359 }
360 return mnem;
361}
362
363char * wxFindAccelerator (char *s)
364{
365// The accelerator text is after the \t char.
366 while (*s && *s != '\t')
367 s++;
368 if (*s == '\0')
369 return (NULL);
370 s++;
371/*
372 Now we need to format it as X standard:
373
374 input output
375
376 F7 --> <Key>F7
377 Ctrl+N --> Ctrl<Key>N
378 Alt+k --> Meta<Key>k
379 Ctrl+Shift+A --> Ctrl Shift<Key>A
380
381 */
382
383 wxBuffer[0] = '\0';
384 char *tmp = copystring (s);
385 s = tmp;
386 char *p = s;
387
388 while (1)
389 {
390 while (*p && *p != '+')
391 p++;
392 if (*p)
393 {
394 *p = '\0';
395 if (wxBuffer[0])
396 strcat (wxBuffer, " ");
397 if (strcmp (s, "Alt"))
398 strcat (wxBuffer, s);
399 else
400 strcat (wxBuffer, "Meta");
401 s = p + 1;
402 p = s;
403 }
404 else
405 {
406 strcat (wxBuffer, "<Key>");
407 strcat (wxBuffer, s);
408 break;
409 }
410 }
411 delete[]tmp;
412 return wxBuffer;
413}
414
415XmString wxFindAcceleratorText (char *s)
416{
417// The accelerator text is after the \t char.
418 while (*s && *s != '\t')
419 s++;
420 if (*s == '\0')
421 return (NULL);
422 s++;
423 XmString text = XmStringCreateSimple (s);
424 return text;
425}
426
427#include <X11/keysym.h>
428
429int wxCharCodeXToWX(KeySym keySym)
430{
431 int id;
432 switch (keySym) {
433 case XK_Shift_L:
434 case XK_Shift_R:
435 id = WXK_SHIFT; break;
436 case XK_Control_L:
437 case XK_Control_R:
438 id = WXK_CONTROL; break;
439 case XK_BackSpace:
440 id = WXK_BACK; break;
441 case XK_Delete:
442 id = WXK_DELETE; break;
443 case XK_Clear:
444 id = WXK_CLEAR; break;
445 case XK_Tab:
446 id = WXK_TAB; break;
447 case XK_numbersign:
448 id = '#'; break;
449 case XK_Return:
450 id = WXK_RETURN; break;
451 case XK_Escape:
452 id = WXK_ESCAPE; break;
453 case XK_Pause:
454 case XK_Break:
455 id = WXK_PAUSE; break;
456 case XK_Num_Lock:
457 id = WXK_NUMLOCK; break;
458 case XK_Scroll_Lock:
459 id = WXK_SCROLL; break;
460
461 case XK_Home:
462 id = WXK_HOME; break;
463 case XK_End:
464 id = WXK_END; break;
465 case XK_Left:
466 id = WXK_LEFT; break;
467 case XK_Right:
468 id = WXK_RIGHT; break;
469 case XK_Up:
470 id = WXK_UP; break;
471 case XK_Down:
472 id = WXK_DOWN; break;
473 case XK_Next:
474 id = WXK_NEXT; break;
475 case XK_Prior:
476 id = WXK_PRIOR; break;
477 case XK_Menu:
478 id = WXK_MENU; break;
479 case XK_Select:
480 id = WXK_SELECT; break;
481 case XK_Cancel:
482 id = WXK_CANCEL; break;
483 case XK_Print:
484 id = WXK_PRINT; break;
485 case XK_Execute:
486 id = WXK_EXECUTE; break;
487 case XK_Insert:
488 id = WXK_INSERT; break;
489 case XK_Help:
490 id = WXK_HELP; break;
491
492 case XK_KP_Multiply:
493 id = WXK_MULTIPLY; break;
494 case XK_KP_Add:
495 id = WXK_ADD; break;
496 case XK_KP_Subtract:
497 id = WXK_SUBTRACT; break;
498 case XK_KP_Divide:
499 id = WXK_DIVIDE; break;
500 case XK_KP_Decimal:
501 id = WXK_DECIMAL; break;
502 case XK_KP_Equal:
503 id = '='; break;
504 case XK_KP_Space:
505 id = ' '; break;
506 case XK_KP_Tab:
507 id = WXK_TAB; break;
508 case XK_KP_Enter:
509 id = WXK_RETURN; break;
510 case XK_KP_0:
511 id = WXK_NUMPAD0; break;
512 case XK_KP_1:
513 id = WXK_NUMPAD1; break;
514 case XK_KP_2:
515 id = WXK_NUMPAD2; break;
516 case XK_KP_3:
517 id = WXK_NUMPAD3; break;
518 case XK_KP_4:
519 id = WXK_NUMPAD4; break;
520 case XK_KP_5:
521 id = WXK_NUMPAD5; break;
522 case XK_KP_6:
523 id = WXK_NUMPAD6; break;
524 case XK_KP_7:
525 id = WXK_NUMPAD7; break;
526 case XK_KP_8:
527 id = WXK_NUMPAD8; break;
528 case XK_KP_9:
529 id = WXK_NUMPAD9; break;
530 case XK_F1:
531 id = WXK_F1; break;
532 case XK_F2:
533 id = WXK_F2; break;
534 case XK_F3:
535 id = WXK_F3; break;
536 case XK_F4:
537 id = WXK_F4; break;
538 case XK_F5:
539 id = WXK_F5; break;
540 case XK_F6:
541 id = WXK_F6; break;
542 case XK_F7:
543 id = WXK_F7; break;
544 case XK_F8:
545 id = WXK_F8; break;
546 case XK_F9:
547 id = WXK_F9; break;
548 case XK_F10:
549 id = WXK_F10; break;
550 case XK_F11:
551 id = WXK_F11; break;
552 case XK_F12:
553 id = WXK_F12; break;
554 case XK_F13:
555 id = WXK_F13; break;
556 case XK_F14:
557 id = WXK_F14; break;
558 case XK_F15:
559 id = WXK_F15; break;
560 case XK_F16:
561 id = WXK_F16; break;
562 case XK_F17:
563 id = WXK_F17; break;
564 case XK_F18:
565 id = WXK_F18; break;
566 case XK_F19:
567 id = WXK_F19; break;
568 case XK_F20:
569 id = WXK_F20; break;
570 case XK_F21:
571 id = WXK_F21; break;
572 case XK_F22:
573 id = WXK_F22; break;
574 case XK_F23:
575 id = WXK_F23; break;
576 case XK_F24:
577 id = WXK_F24; break;
578 default:
579 id = (keySym <= 255) ? (int)keySym : -1;
580 } // switch
581 return id;
582}
583
584KeySym wxCharCodeWXToX(int id)
585{
586 KeySym keySym;
587
588 switch (id) {
589 case WXK_CANCEL: keySym = XK_Cancel; break;
590 case WXK_BACK: keySym = XK_BackSpace; break;
591 case WXK_TAB: keySym = XK_Tab; break;
592 case WXK_CLEAR: keySym = XK_Clear; break;
593 case WXK_RETURN: keySym = XK_Return; break;
594 case WXK_SHIFT: keySym = XK_Shift_L; break;
595 case WXK_CONTROL: keySym = XK_Control_L; break;
596 case WXK_MENU : keySym = XK_Menu; break;
597 case WXK_PAUSE: keySym = XK_Pause; break;
598 case WXK_ESCAPE: keySym = XK_Escape; break;
599 case WXK_SPACE: keySym = ' '; break;
600 case WXK_PRIOR: keySym = XK_Prior; break;
601 case WXK_NEXT : keySym = XK_Next; break;
602 case WXK_END: keySym = XK_End; break;
603 case WXK_HOME : keySym = XK_Home; break;
604 case WXK_LEFT : keySym = XK_Left; break;
605 case WXK_UP: keySym = XK_Up; break;
606 case WXK_RIGHT: keySym = XK_Right; break;
607 case WXK_DOWN : keySym = XK_Down; break;
608 case WXK_SELECT: keySym = XK_Select; break;
609 case WXK_PRINT: keySym = XK_Print; break;
610 case WXK_EXECUTE: keySym = XK_Execute; break;
611 case WXK_INSERT: keySym = XK_Insert; break;
612 case WXK_DELETE: keySym = XK_Delete; break;
613 case WXK_HELP : keySym = XK_Help; break;
614 case WXK_NUMPAD0: keySym = XK_KP_0; break;
615 case WXK_NUMPAD1: keySym = XK_KP_1; break;
616 case WXK_NUMPAD2: keySym = XK_KP_2; break;
617 case WXK_NUMPAD3: keySym = XK_KP_3; break;
618 case WXK_NUMPAD4: keySym = XK_KP_4; break;
619 case WXK_NUMPAD5: keySym = XK_KP_5; break;
620 case WXK_NUMPAD6: keySym = XK_KP_6; break;
621 case WXK_NUMPAD7: keySym = XK_KP_7; break;
622 case WXK_NUMPAD8: keySym = XK_KP_8; break;
623 case WXK_NUMPAD9: keySym = XK_KP_9; break;
624 case WXK_MULTIPLY: keySym = XK_KP_Multiply; break;
625 case WXK_ADD: keySym = XK_KP_Add; break;
626 case WXK_SUBTRACT: keySym = XK_KP_Subtract; break;
627 case WXK_DECIMAL: keySym = XK_KP_Decimal; break;
628 case WXK_DIVIDE: keySym = XK_KP_Divide; break;
629 case WXK_F1: keySym = XK_F1; break;
630 case WXK_F2: keySym = XK_F2; break;
631 case WXK_F3: keySym = XK_F3; break;
632 case WXK_F4: keySym = XK_F4; break;
633 case WXK_F5: keySym = XK_F5; break;
634 case WXK_F6: keySym = XK_F6; break;
635 case WXK_F7: keySym = XK_F7; break;
636 case WXK_F8: keySym = XK_F8; break;
637 case WXK_F9: keySym = XK_F9; break;
638 case WXK_F10: keySym = XK_F10; break;
639 case WXK_F11: keySym = XK_F11; break;
640 case WXK_F12: keySym = XK_F12; break;
641 case WXK_F13: keySym = XK_F13; break;
642 case WXK_F14: keySym = XK_F14; break;
643 case WXK_F15: keySym = XK_F15; break;
644 case WXK_F16: keySym = XK_F16; break;
645 case WXK_F17: keySym = XK_F17; break;
646 case WXK_F18: keySym = XK_F18; break;
647 case WXK_F19: keySym = XK_F19; break;
648 case WXK_F20: keySym = XK_F20; break;
649 case WXK_F21: keySym = XK_F21; break;
650 case WXK_F22: keySym = XK_F22; break;
651 case WXK_F23: keySym = XK_F23; break;
652 case WXK_F24: keySym = XK_F24; break;
653 case WXK_NUMLOCK: keySym = XK_Num_Lock; break;
654 case WXK_SCROLL: keySym = XK_Scroll_Lock; break;
655 default: keySym = id <= 255 ? (KeySym)id : 0;
656 } // switch
657 return keySym;
658}