]>
Commit | Line | Data |
---|---|---|
c801d85f | 1 | ///////////////////////////////////////////////////////////////////////////// |
dbd25330 | 2 | // Name: src/gtk/utilsgtk.cpp |
c801d85f KB |
3 | // Purpose: |
4 | // Author: Robert Roebling | |
dfcb1ae0 | 5 | // Id: $Id$ |
6c9a19aa | 6 | // Copyright: (c) 1998 Robert Roebling |
518b5d2f | 7 | // Licence: wxWindows licence |
c801d85f KB |
8 | ///////////////////////////////////////////////////////////////////////////// |
9 | ||
c801d85f KB |
10 | #include "wx/utils.h" |
11 | #include "wx/string.h" | |
12 | ||
46446cc2 | 13 | #include "wx/apptrait.h" |
02847e59 VZ |
14 | #include "wx/intl.h" |
15 | #include "wx/log.h" | |
16 | ||
5336ece4 VZ |
17 | #include "wx/process.h" |
18 | ||
518b5d2f VZ |
19 | #include "wx/unix/execute.h" |
20 | ||
c801d85f | 21 | #include <stdarg.h> |
c801d85f KB |
22 | #include <string.h> |
23 | #include <sys/stat.h> | |
24 | #include <sys/types.h> | |
dbd25330 | 25 | #include <sys/wait.h> // for WNOHANG |
c801d85f | 26 | #include <unistd.h> |
91b8de8d RR |
27 | |
28 | #include "glib.h" | |
29 | #include "gdk/gdk.h" | |
30 | #include "gtk/gtk.h" | |
df530a26 | 31 | #ifndef __WXGTK20__ |
91b8de8d | 32 | #include "gtk/gtkfeatures.h" |
df530a26 | 33 | #endif |
91b8de8d | 34 | #include "gdk/gdkx.h" |
88ac883a | 35 | |
27933891 | 36 | #ifdef HAVE_X11_XKBLIB_H |
154c4aa1 VZ |
37 | /* under HP-UX and Solaris 2.6, at least, XKBlib.h defines structures with |
38 | * field named "explicit" - which is, of course, an error for a C++ | |
39 | * compiler. To be on the safe side, just redefine it everywhere. */ | |
88ac883a | 40 | #define explicit __wx_explicit |
ec5d7799 | 41 | |
154c4aa1 | 42 | #include "X11/XKBlib.h" |
ec5d7799 | 43 | |
88ac883a | 44 | #undef explicit |
27933891 | 45 | #endif // HAVE_X11_XKBLIB_H |
dfcb1ae0 | 46 | |
d76fe38b RR |
47 | //----------------------------------------------------------------------------- |
48 | // data | |
49 | //----------------------------------------------------------------------------- | |
50 | ||
c2fa61e8 | 51 | extern GtkWidget *wxGetRootWindow(); |
d76fe38b RR |
52 | |
53 | //---------------------------------------------------------------------------- | |
c801d85f | 54 | // misc. |
d76fe38b | 55 | //---------------------------------------------------------------------------- |
c801d85f | 56 | |
518b5d2f | 57 | void wxBell() |
c801d85f | 58 | { |
e52f60e6 RR |
59 | gdk_beep(); |
60 | } | |
c801d85f | 61 | |
27933891 RR |
62 | /* Don't synthesize KeyUp events holding down a key and producing |
63 | KeyDown events with autorepeat. */ | |
64 | #ifdef HAVE_X11_XKBLIB_H | |
f0492f7d RR |
65 | bool wxSetDetectableAutoRepeat( bool flag ) |
66 | { | |
67 | Bool result; | |
68 | XkbSetDetectableAutoRepeat( GDK_DISPLAY(), flag, &result ); | |
27933891 RR |
69 | return result; /* TRUE if keyboard hardware supports this mode */ |
70 | } | |
71 | #else | |
72 | bool wxSetDetectableAutoRepeat( bool WXUNUSED(flag) ) | |
73 | { | |
74 | return FALSE; | |
f0492f7d | 75 | } |
27933891 | 76 | #endif |
f0492f7d | 77 | |
518b5d2f VZ |
78 | // ---------------------------------------------------------------------------- |
79 | // display characterstics | |
80 | // ---------------------------------------------------------------------------- | |
82052aff | 81 | |
d111a89a VZ |
82 | void *wxGetDisplay() |
83 | { | |
27df579a | 84 | return GDK_DISPLAY(); |
d111a89a VZ |
85 | } |
86 | ||
c0392997 RR |
87 | void wxDisplaySize( int *width, int *height ) |
88 | { | |
e52f60e6 RR |
89 | if (width) *width = gdk_screen_width(); |
90 | if (height) *height = gdk_screen_height(); | |
c0392997 RR |
91 | } |
92 | ||
904a68b6 RL |
93 | void wxDisplaySizeMM( int *width, int *height ) |
94 | { | |
95 | if (width) *width = gdk_screen_width_mm(); | |
96 | if (height) *height = gdk_screen_height_mm(); | |
97 | } | |
98 | ||
ec5d7799 RD |
99 | void wxClientDisplayRect(int *x, int *y, int *width, int *height) |
100 | { | |
101 | // This is supposed to return desktop dimensions minus any window | |
102 | // manager panels, menus, taskbars, etc. If there is a way to do that | |
103 | // for this platform please fix this function, otherwise it defaults | |
104 | // to the entire desktop. | |
105 | if (x) *x = 0; | |
106 | if (y) *y = 0; | |
107 | wxDisplaySize(width, height); | |
108 | } | |
109 | ||
6de97a3b RR |
110 | void wxGetMousePosition( int* x, int* y ) |
111 | { | |
bbe0af5b | 112 | gdk_window_get_pointer( (GdkWindow*) NULL, x, y, (GdkModifierType*) NULL ); |
e52f60e6 | 113 | } |
6de97a3b | 114 | |
518b5d2f | 115 | bool wxColourDisplay() |
6de97a3b | 116 | { |
e52f60e6 | 117 | return TRUE; |
6de97a3b RR |
118 | } |
119 | ||
518b5d2f | 120 | int wxDisplayDepth() |
6de97a3b | 121 | { |
c2fa61e8 | 122 | return gdk_window_get_visual( wxGetRootWindow()->window )->depth; |
6de97a3b RR |
123 | } |
124 | ||
324899f6 | 125 | wxToolkitInfo& wxGUIAppTraits::GetToolkitInfo() |
bbe0af5b | 126 | { |
a8eaaeb2 VS |
127 | static wxToolkitInfo info; |
128 | #ifdef __WXGTK20__ | |
129 | info.shortName = _T("gtk2"); | |
130 | #else | |
131 | info.shortName = _T("gtk"); | |
132 | #endif | |
133 | info.name = _T("wxGTK"); | |
134 | #ifdef __WXUNIVERSAL__ | |
135 | info.shortName << _T("univ"); | |
136 | info.name << _T("/wxUniversal"); | |
137 | #endif | |
138 | info.versionMajor = GTK_MAJOR_VERSION; | |
139 | info.versionMinor = GTK_MINOR_VERSION; | |
140 | info.os = wxGTK; | |
324899f6 | 141 | return info; |
bbe0af5b RR |
142 | } |
143 | ||
57591e0e JS |
144 | wxWindow* wxFindWindowAtPoint(const wxPoint& pt) |
145 | { | |
146 | return wxGenericFindWindowAtPoint(pt); | |
147 | } | |
148 | ||
149 | ||
518b5d2f | 150 | // ---------------------------------------------------------------------------- |
c801d85f | 151 | // subprocess routines |
518b5d2f | 152 | // ---------------------------------------------------------------------------- |
cf447356 | 153 | |
90350682 VZ |
154 | extern "C" |
155 | void GTK_EndProcessDetector(gpointer data, gint source, | |
156 | GdkInputCondition WXUNUSED(condition) ) | |
cf447356 | 157 | { |
ab857a4e | 158 | wxEndProcessData *proc_data = (wxEndProcessData *)data; |
dbd25330 VZ |
159 | |
160 | // has the process really terminated? unfortunately GDK (or GLib) seem to | |
161 | // generate G_IO_HUP notification even when it simply tries to read from a | |
162 | // closed fd and hasn't terminated at all | |
163 | int pid = (proc_data->pid > 0) ? proc_data->pid : -(proc_data->pid); | |
447f908a VZ |
164 | int status = 0; |
165 | int rc = waitpid(pid, &status, WNOHANG); | |
166 | ||
167 | if ( rc == 0 ) | |
dbd25330 VZ |
168 | { |
169 | // no, it didn't exit yet, continue waiting | |
170 | return; | |
171 | } | |
172 | ||
447f908a VZ |
173 | // set exit code to -1 if something bad happened |
174 | proc_data->exitcode = rc != -1 && WIFEXITED(status) ? WEXITSTATUS(status) | |
175 | : -1; | |
176 | ||
dbd25330 | 177 | // child exited, end waiting |
ab857a4e | 178 | close(source); |
dbd25330 VZ |
179 | |
180 | // don't call us again! | |
ab857a4e KB |
181 | gdk_input_remove(proc_data->tag); |
182 | ||
ab857a4e | 183 | wxHandleProcessTermination(proc_data); |
3069ac4e | 184 | } |
cf447356 | 185 | |
518b5d2f | 186 | int wxAddProcessCallback(wxEndProcessData *proc_data, int fd) |
c801d85f | 187 | { |
518b5d2f VZ |
188 | int tag = gdk_input_add(fd, |
189 | GDK_INPUT_READ, | |
190 | GTK_EndProcessDetector, | |
191 | (gpointer)proc_data); | |
c801d85f | 192 | |
518b5d2f | 193 | return tag; |
3069ac4e | 194 | } |
c801d85f | 195 |