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