]>
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 |
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 KB |
13 | #include "wx/utils.h" |
14 | #include "wx/string.h" | |
15 | ||
46446cc2 | 16 | #include "wx/apptrait.h" |
02847e59 VZ |
17 | #include "wx/intl.h" |
18 | #include "wx/log.h" | |
19 | ||
5336ece4 VZ |
20 | #include "wx/process.h" |
21 | ||
518b5d2f VZ |
22 | #include "wx/unix/execute.h" |
23 | ||
c801d85f | 24 | #include <stdarg.h> |
c801d85f KB |
25 | #include <string.h> |
26 | #include <sys/stat.h> | |
27 | #include <sys/types.h> | |
dbd25330 | 28 | #include <sys/wait.h> // for WNOHANG |
c801d85f | 29 | #include <unistd.h> |
91b8de8d RR |
30 | |
31 | #include "glib.h" | |
32 | #include "gdk/gdk.h" | |
33 | #include "gtk/gtk.h" | |
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 | //---------------------------------------------------------------------------- |
189d1ae7 SN |
56 | #ifndef __EMX__ |
57 | // on OS/2, we use the wxBell from wxBase library | |
c801d85f | 58 | |
518b5d2f | 59 | void wxBell() |
c801d85f | 60 | { |
e52f60e6 RR |
61 | gdk_beep(); |
62 | } | |
189d1ae7 | 63 | #endif |
c801d85f | 64 | |
27933891 RR |
65 | /* Don't synthesize KeyUp events holding down a key and producing |
66 | KeyDown events with autorepeat. */ | |
67 | #ifdef HAVE_X11_XKBLIB_H | |
f0492f7d RR |
68 | bool wxSetDetectableAutoRepeat( bool flag ) |
69 | { | |
70 | Bool result; | |
71 | XkbSetDetectableAutoRepeat( GDK_DISPLAY(), flag, &result ); | |
27933891 RR |
72 | return result; /* TRUE if keyboard hardware supports this mode */ |
73 | } | |
74 | #else | |
75 | bool wxSetDetectableAutoRepeat( bool WXUNUSED(flag) ) | |
76 | { | |
77 | return FALSE; | |
f0492f7d | 78 | } |
27933891 | 79 | #endif |
f0492f7d | 80 | |
66bd83b4 VS |
81 | // Escapes string so that it is valid Pango markup XML string: |
82 | wxString wxEscapeStringForPangoMarkup(const wxString& str) | |
83 | { | |
84 | size_t len = str.length(); | |
85 | wxString out; | |
86 | out.Alloc(len); | |
87 | for (size_t i = 0; i < len; i++) | |
88 | { | |
89 | wxChar c = str[i]; | |
90 | switch (c) | |
91 | { | |
92 | case _T('&'): | |
93 | out << _T("&"); | |
94 | break; | |
95 | case _T('<'): | |
96 | out << _T("<"); | |
97 | break; | |
98 | case _T('>'): | |
99 | out << _T(">"); | |
100 | break; | |
101 | case _T('\''): | |
102 | out << _T("'"); | |
103 | break; | |
104 | case _T('"'): | |
105 | out << _T("""); | |
106 | break; | |
107 | default: | |
108 | out << c; | |
109 | break; | |
110 | } | |
111 | } | |
112 | return out; | |
113 | } | |
66bd83b4 VS |
114 | |
115 | ||
518b5d2f VZ |
116 | // ---------------------------------------------------------------------------- |
117 | // display characterstics | |
118 | // ---------------------------------------------------------------------------- | |
82052aff | 119 | |
d111a89a VZ |
120 | void *wxGetDisplay() |
121 | { | |
27df579a | 122 | return GDK_DISPLAY(); |
d111a89a VZ |
123 | } |
124 | ||
c0392997 RR |
125 | void wxDisplaySize( int *width, int *height ) |
126 | { | |
e52f60e6 RR |
127 | if (width) *width = gdk_screen_width(); |
128 | if (height) *height = gdk_screen_height(); | |
c0392997 RR |
129 | } |
130 | ||
904a68b6 RL |
131 | void wxDisplaySizeMM( int *width, int *height ) |
132 | { | |
133 | if (width) *width = gdk_screen_width_mm(); | |
134 | if (height) *height = gdk_screen_height_mm(); | |
135 | } | |
136 | ||
ec5d7799 RD |
137 | void wxClientDisplayRect(int *x, int *y, int *width, int *height) |
138 | { | |
139 | // This is supposed to return desktop dimensions minus any window | |
140 | // manager panels, menus, taskbars, etc. If there is a way to do that | |
141 | // for this platform please fix this function, otherwise it defaults | |
142 | // to the entire desktop. | |
143 | if (x) *x = 0; | |
144 | if (y) *y = 0; | |
145 | wxDisplaySize(width, height); | |
146 | } | |
147 | ||
6de97a3b RR |
148 | void wxGetMousePosition( int* x, int* y ) |
149 | { | |
bbe0af5b | 150 | gdk_window_get_pointer( (GdkWindow*) NULL, x, y, (GdkModifierType*) NULL ); |
e52f60e6 | 151 | } |
6de97a3b | 152 | |
518b5d2f | 153 | bool wxColourDisplay() |
6de97a3b | 154 | { |
e52f60e6 | 155 | return TRUE; |
6de97a3b RR |
156 | } |
157 | ||
518b5d2f | 158 | int wxDisplayDepth() |
6de97a3b | 159 | { |
22a3bce4 | 160 | return gdk_drawable_get_visual( wxGetRootWindow()->window )->depth; |
6de97a3b RR |
161 | } |
162 | ||
324899f6 | 163 | wxToolkitInfo& wxGUIAppTraits::GetToolkitInfo() |
bbe0af5b | 164 | { |
a8eaaeb2 | 165 | static wxToolkitInfo info; |
a8eaaeb2 | 166 | info.shortName = _T("gtk2"); |
a8eaaeb2 VS |
167 | info.name = _T("wxGTK"); |
168 | #ifdef __WXUNIVERSAL__ | |
169 | info.shortName << _T("univ"); | |
170 | info.name << _T("/wxUniversal"); | |
171 | #endif | |
a5441ce3 VS |
172 | info.versionMajor = gtk_major_version; |
173 | info.versionMinor = gtk_minor_version; | |
a8eaaeb2 | 174 | info.os = wxGTK; |
324899f6 | 175 | return info; |
bbe0af5b RR |
176 | } |
177 | ||
57591e0e JS |
178 | wxWindow* wxFindWindowAtPoint(const wxPoint& pt) |
179 | { | |
180 | return wxGenericFindWindowAtPoint(pt); | |
181 | } | |
182 | ||
183 | ||
518b5d2f | 184 | // ---------------------------------------------------------------------------- |
c801d85f | 185 | // subprocess routines |
518b5d2f | 186 | // ---------------------------------------------------------------------------- |
cf447356 | 187 | |
865bb325 VZ |
188 | extern "C" { |
189 | static | |
90350682 VZ |
190 | void GTK_EndProcessDetector(gpointer data, gint source, |
191 | GdkInputCondition WXUNUSED(condition) ) | |
cf447356 | 192 | { |
ab857a4e | 193 | wxEndProcessData *proc_data = (wxEndProcessData *)data; |
dbd25330 VZ |
194 | |
195 | // has the process really terminated? unfortunately GDK (or GLib) seem to | |
196 | // generate G_IO_HUP notification even when it simply tries to read from a | |
197 | // closed fd and hasn't terminated at all | |
198 | int pid = (proc_data->pid > 0) ? proc_data->pid : -(proc_data->pid); | |
447f908a VZ |
199 | int status = 0; |
200 | int rc = waitpid(pid, &status, WNOHANG); | |
201 | ||
202 | if ( rc == 0 ) | |
dbd25330 VZ |
203 | { |
204 | // no, it didn't exit yet, continue waiting | |
205 | return; | |
206 | } | |
207 | ||
447f908a VZ |
208 | // set exit code to -1 if something bad happened |
209 | proc_data->exitcode = rc != -1 && WIFEXITED(status) ? WEXITSTATUS(status) | |
210 | : -1; | |
211 | ||
dbd25330 | 212 | // child exited, end waiting |
ab857a4e | 213 | close(source); |
dbd25330 VZ |
214 | |
215 | // don't call us again! | |
ab857a4e KB |
216 | gdk_input_remove(proc_data->tag); |
217 | ||
ab857a4e | 218 | wxHandleProcessTermination(proc_data); |
3069ac4e | 219 | } |
865bb325 | 220 | } |
cf447356 | 221 | |
518b5d2f | 222 | int wxAddProcessCallback(wxEndProcessData *proc_data, int fd) |
c801d85f | 223 | { |
518b5d2f VZ |
224 | int tag = gdk_input_add(fd, |
225 | GDK_INPUT_READ, | |
226 | GTK_EndProcessDetector, | |
227 | (gpointer)proc_data); | |
c801d85f | 228 | |
518b5d2f | 229 | return tag; |
3069ac4e | 230 | } |
c801d85f | 231 |