]>
git.saurik.com Git - wxWidgets.git/blob - src/motif/utils.cpp
1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: Various utilities
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
13 // Note: this is done in utilscmn.cpp now.
14 // #pragma implementation
15 // #pragma implementation "utils.h"
31 #include "wx/motif/private.h"
33 // Get full hostname (eg. DoDo.BSn-Germany.crg.de)
34 bool wxGetHostName(char *buf
, int maxSize
)
40 // Get user ID e.g. jacs
41 bool wxGetUserId(char *buf
, int maxSize
)
47 // Get user name e.g. Julian Smart
48 bool wxGetUserName(char *buf
, int maxSize
)
54 int wxKill(long pid
, int sig
)
61 // Execute a program in an Interactive Shell
63 bool wxShell(const wxString
& command
)
69 // Get free memory in bytes, or -1 if cannot determine amount (e.g. on UNIX)
70 long wxGetFreeMemory()
76 void wxSleep(int nSecs
)
81 // Consume all events until no more left
86 // Output a debug message, in a system dependent fashion.
87 void wxDebugMsg(const char *fmt
...)
90 static char buffer
[512];
92 if (!wxTheApp
->GetWantDebugOutput())
97 // wvsprintf(buffer,fmt,ap) ;
98 // TODO: output buffer
103 // Non-fatal error: pop up message box and (possibly) continue
104 void wxError(const wxString
& msg
, const wxString
& title
)
110 // Fatal error: pop up message box and abort
111 void wxFatalError(const wxString
& msg
, const wxString
& title
)
122 int wxGetOsVersion(int *majorVsn
, int *minorVsn
)
128 // Reading and writing resources (eg WIN.INI, .Xdefaults)
130 bool wxWriteResource(const wxString
& section
, const wxString
& entry
, const wxString
& value
, const wxString
& file
)
136 bool wxWriteResource(const wxString
& section
, const wxString
& entry
, float value
, const wxString
& file
)
139 sprintf(buf
, "%.4f", value
);
140 return wxWriteResource(section
, entry
, buf
, file
);
143 bool wxWriteResource(const wxString
& section
, const wxString
& entry
, long value
, const wxString
& file
)
146 sprintf(buf
, "%ld", value
);
147 return wxWriteResource(section
, entry
, buf
, file
);
150 bool wxWriteResource(const wxString
& section
, const wxString
& entry
, int value
, const wxString
& file
)
153 sprintf(buf
, "%d", value
);
154 return wxWriteResource(section
, entry
, buf
, file
);
157 bool wxGetResource(const wxString
& section
, const wxString
& entry
, char **value
, const wxString
& file
)
163 bool wxGetResource(const wxString
& section
, const wxString
& entry
, float *value
, const wxString
& file
)
166 bool succ
= wxGetResource(section
, entry
, (char **)&s
, file
);
169 *value
= (float)strtod(s
, NULL
);
176 bool wxGetResource(const wxString
& section
, const wxString
& entry
, long *value
, const wxString
& file
)
179 bool succ
= wxGetResource(section
, entry
, (char **)&s
, file
);
182 *value
= strtol(s
, NULL
, 10);
189 bool wxGetResource(const wxString
& section
, const wxString
& entry
, int *value
, const wxString
& file
)
192 bool succ
= wxGetResource(section
, entry
, (char **)&s
, file
);
195 *value
= (int)strtol(s
, NULL
, 10);
201 #endif // wxUSE_RESOURCES
203 static int wxBusyCursorCount
= 0;
205 // Set the cursor to the busy cursor for all windows
206 void wxBeginBusyCursor(wxCursor
*cursor
)
208 wxBusyCursorCount
++;
209 if (wxBusyCursorCount
== 1)
219 // Restore cursor to normal
220 void wxEndBusyCursor()
222 if (wxBusyCursorCount
== 0)
225 wxBusyCursorCount
--;
226 if (wxBusyCursorCount
== 0)
232 // TRUE if we're between the above two calls
235 return (wxBusyCursorCount
> 0);
238 char *wxGetUserHome (const wxString
& user
)
244 // Check whether this window wants to process messages, e.g. Stop button
245 // in long calculations.
246 bool wxCheckForInterrupt(wxWindow
*wnd
)
252 void wxGetMousePosition( int* x
, int* y
)
257 // Return TRUE if we have a colour display
258 bool wxColourDisplay()
260 Display
*dpy
= (Display
*) wxGetDisplay();
262 if (DefaultDepth (dpy
, DefaultScreen (dpy
)) < 2)
268 // Returns depth of screen
271 Display
*dpy
= (Display
*) wxGetDisplay();
272 return DefaultDepth (dpy
, DefaultScreen (dpy
));
275 // Get size of display
276 void wxDisplaySize(int *width
, int *height
)
278 Display
*dpy
= (Display
*) wxGetDisplay();
280 *width
= DisplayWidth (dpy
, DefaultScreen (dpy
));
281 *height
= DisplayHeight (dpy
, DefaultScreen (dpy
));
284 /* Configurable display in Motif */
285 static WXDisplay
*gs_currentDisplay
= NULL
;
286 static wxString gs_displayName
;
288 WXDisplay
*wxGetDisplay()
290 if (gs_currentDisplay
)
291 return gs_currentDisplay
;
293 return XtDisplay ((Widget
) wxTheApp
->GetTopLevelWidget());
296 bool wxSetDisplay(const wxString
& display_name
)
298 gs_displayName
= display_name
;
300 if (display_name
.IsNull() || display_name
.IsEmpty())
302 gs_currentDisplay
= NULL
;
309 Display
*display
= XtOpenDisplay((XtAppContext
) wxTheApp
->GetAppContext(),
310 (const char*) display_name
,
311 (const char*) wxTheApp
->GetAppName(),
312 (const char*) wxTheApp
->GetClassName(),
314 # if XtSpecificationRelease < 5
317 0, (int *)&argc
, NULL
);
322 gs_currentDisplay
= (WXDisplay
*) display
;
330 wxString
wxGetDisplayName()
332 return gs_displayName
;
335 // Find the letter corresponding to the mnemonic, for Motif
336 char wxFindMnemonic (const char *s
)
339 int len
= strlen (s
);
341 for (i
= 0; i
< len
; i
++)
345 // Carefully handle &&
346 if ((i
+ 1) <= len
&& s
[i
+ 1] == '&')
358 char * wxFindAccelerator (char *s
)
360 // The accelerator text is after the \t char.
361 while (*s
&& *s
!= '\t')
367 Now we need to format it as X standard:
372 Ctrl+N --> Ctrl<Key>N
374 Ctrl+Shift+A --> Ctrl Shift<Key>A
379 char *tmp
= copystring (s
);
385 while (*p
&& *p
!= '+')
391 strcat (wxBuffer
, " ");
392 if (strcmp (s
, "Alt"))
393 strcat (wxBuffer
, s
);
395 strcat (wxBuffer
, "Meta");
401 strcat (wxBuffer
, "<Key>");
402 strcat (wxBuffer
, s
);
410 XmString
wxFindAcceleratorText (char *s
)
412 // The accelerator text is after the \t char.
413 while (*s
&& *s
!= '\t')
418 XmString text
= XmStringCreateSimple (s
);
422 #include <X11/keysym.h>
424 int wxCharCodeXToWX(KeySym keySym
)
430 id
= WXK_SHIFT
; break;
433 id
= WXK_CONTROL
; break;
435 id
= WXK_BACK
; break;
437 id
= WXK_DELETE
; break;
439 id
= WXK_CLEAR
; break;
445 id
= WXK_RETURN
; break;
447 id
= WXK_ESCAPE
; break;
450 id
= WXK_PAUSE
; break;
452 id
= WXK_NUMLOCK
; break;
454 id
= WXK_SCROLL
; break;
457 id
= WXK_HOME
; break;
461 id
= WXK_LEFT
; break;
463 id
= WXK_RIGHT
; break;
467 id
= WXK_DOWN
; break;
469 id
= WXK_NEXT
; break;
471 id
= WXK_PRIOR
; break;
473 id
= WXK_MENU
; break;
475 id
= WXK_SELECT
; break;
477 id
= WXK_CANCEL
; break;
479 id
= WXK_PRINT
; break;
481 id
= WXK_EXECUTE
; break;
483 id
= WXK_INSERT
; break;
485 id
= WXK_HELP
; break;
488 id
= WXK_MULTIPLY
; break;
492 id
= WXK_SUBTRACT
; break;
494 id
= WXK_DIVIDE
; break;
496 id
= WXK_DECIMAL
; break;
504 id
= WXK_RETURN
; break;
506 id
= WXK_NUMPAD0
; break;
508 id
= WXK_NUMPAD1
; break;
510 id
= WXK_NUMPAD2
; break;
512 id
= WXK_NUMPAD3
; break;
514 id
= WXK_NUMPAD4
; break;
516 id
= WXK_NUMPAD5
; break;
518 id
= WXK_NUMPAD6
; break;
520 id
= WXK_NUMPAD7
; break;
522 id
= WXK_NUMPAD8
; break;
524 id
= WXK_NUMPAD9
; break;
574 id
= (keySym
<= 255) ? (int)keySym
: -1;
579 KeySym
wxCharCodeWXToX(int id
)
584 case WXK_CANCEL
: keySym
= XK_Cancel
; break;
585 case WXK_BACK
: keySym
= XK_BackSpace
; break;
586 case WXK_TAB
: keySym
= XK_Tab
; break;
587 case WXK_CLEAR
: keySym
= XK_Clear
; break;
588 case WXK_RETURN
: keySym
= XK_Return
; break;
589 case WXK_SHIFT
: keySym
= XK_Shift_L
; break;
590 case WXK_CONTROL
: keySym
= XK_Control_L
; break;
591 case WXK_MENU
: keySym
= XK_Menu
; break;
592 case WXK_PAUSE
: keySym
= XK_Pause
; break;
593 case WXK_ESCAPE
: keySym
= XK_Escape
; break;
594 case WXK_SPACE
: keySym
= ' '; break;
595 case WXK_PRIOR
: keySym
= XK_Prior
; break;
596 case WXK_NEXT
: keySym
= XK_Next
; break;
597 case WXK_END
: keySym
= XK_End
; break;
598 case WXK_HOME
: keySym
= XK_Home
; break;
599 case WXK_LEFT
: keySym
= XK_Left
; break;
600 case WXK_UP
: keySym
= XK_Up
; break;
601 case WXK_RIGHT
: keySym
= XK_Right
; break;
602 case WXK_DOWN
: keySym
= XK_Down
; break;
603 case WXK_SELECT
: keySym
= XK_Select
; break;
604 case WXK_PRINT
: keySym
= XK_Print
; break;
605 case WXK_EXECUTE
: keySym
= XK_Execute
; break;
606 case WXK_INSERT
: keySym
= XK_Insert
; break;
607 case WXK_DELETE
: keySym
= XK_Delete
; break;
608 case WXK_HELP
: keySym
= XK_Help
; break;
609 case WXK_NUMPAD0
: keySym
= XK_KP_0
; break;
610 case WXK_NUMPAD1
: keySym
= XK_KP_1
; break;
611 case WXK_NUMPAD2
: keySym
= XK_KP_2
; break;
612 case WXK_NUMPAD3
: keySym
= XK_KP_3
; break;
613 case WXK_NUMPAD4
: keySym
= XK_KP_4
; break;
614 case WXK_NUMPAD5
: keySym
= XK_KP_5
; break;
615 case WXK_NUMPAD6
: keySym
= XK_KP_6
; break;
616 case WXK_NUMPAD7
: keySym
= XK_KP_7
; break;
617 case WXK_NUMPAD8
: keySym
= XK_KP_8
; break;
618 case WXK_NUMPAD9
: keySym
= XK_KP_9
; break;
619 case WXK_MULTIPLY
: keySym
= XK_KP_Multiply
; break;
620 case WXK_ADD
: keySym
= XK_KP_Add
; break;
621 case WXK_SUBTRACT
: keySym
= XK_KP_Subtract
; break;
622 case WXK_DECIMAL
: keySym
= XK_KP_Decimal
; break;
623 case WXK_DIVIDE
: keySym
= XK_KP_Divide
; break;
624 case WXK_F1
: keySym
= XK_F1
; break;
625 case WXK_F2
: keySym
= XK_F2
; break;
626 case WXK_F3
: keySym
= XK_F3
; break;
627 case WXK_F4
: keySym
= XK_F4
; break;
628 case WXK_F5
: keySym
= XK_F5
; break;
629 case WXK_F6
: keySym
= XK_F6
; break;
630 case WXK_F7
: keySym
= XK_F7
; break;
631 case WXK_F8
: keySym
= XK_F8
; break;
632 case WXK_F9
: keySym
= XK_F9
; break;
633 case WXK_F10
: keySym
= XK_F10
; break;
634 case WXK_F11
: keySym
= XK_F11
; break;
635 case WXK_F12
: keySym
= XK_F12
; break;
636 case WXK_F13
: keySym
= XK_F13
; break;
637 case WXK_F14
: keySym
= XK_F14
; break;
638 case WXK_F15
: keySym
= XK_F15
; break;
639 case WXK_F16
: keySym
= XK_F16
; break;
640 case WXK_F17
: keySym
= XK_F17
; break;
641 case WXK_F18
: keySym
= XK_F18
; break;
642 case WXK_F19
: keySym
= XK_F19
; break;
643 case WXK_F20
: keySym
= XK_F20
; break;
644 case WXK_F21
: keySym
= XK_F21
; break;
645 case WXK_F22
: keySym
= XK_F22
; break;
646 case WXK_F23
: keySym
= XK_F23
; break;
647 case WXK_F24
: keySym
= XK_F24
; break;
648 case WXK_NUMLOCK
: keySym
= XK_Num_Lock
; break;
649 case WXK_SCROLL
: keySym
= XK_Scroll_Lock
; break;
650 default: keySym
= id
<= 255 ? (KeySym
)id
: 0;