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