]> git.saurik.com Git - wxWidgets.git/blob - src/gtk1/utilsgtk.cpp
multilib mode compilation fix
[wxWidgets.git] / src / gtk1 / utilsgtk.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/gtk/utilsgtk.cpp
3 // Purpose:
4 // Author: Robert Roebling
5 // Id: $Id$
6 // Copyright: (c) 1998 Robert Roebling
7 // Licence: wxWindows licence
8 /////////////////////////////////////////////////////////////////////////////
9
10 #include "wx/utils.h"
11 #include "wx/string.h"
12
13 #include "wx/apptrait.h"
14 #include "wx/intl.h"
15 #include "wx/log.h"
16
17 #include "wx/process.h"
18
19 #include "wx/unix/execute.h"
20
21 #include <stdarg.h>
22 #include <string.h>
23 #include <sys/stat.h>
24 #include <sys/types.h>
25 #include <sys/wait.h> // for WNOHANG
26 #include <unistd.h>
27
28 #include "glib.h"
29 #include "gdk/gdk.h"
30 #include "gtk/gtk.h"
31 #ifndef __WXGTK20__
32 #include "gtk/gtkfeatures.h"
33 #endif
34 #include "gdk/gdkx.h"
35
36 #ifdef HAVE_X11_XKBLIB_H
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. */
40 #define explicit __wx_explicit
41
42 #include "X11/XKBlib.h"
43
44 #undef explicit
45 #endif // HAVE_X11_XKBLIB_H
46
47 //-----------------------------------------------------------------------------
48 // data
49 //-----------------------------------------------------------------------------
50
51 extern GtkWidget *wxGetRootWindow();
52
53 //----------------------------------------------------------------------------
54 // misc.
55 //----------------------------------------------------------------------------
56
57 void wxBell()
58 {
59 gdk_beep();
60 }
61
62 /* Don't synthesize KeyUp events holding down a key and producing
63 KeyDown events with autorepeat. */
64 #ifdef HAVE_X11_XKBLIB_H
65 bool wxSetDetectableAutoRepeat( bool flag )
66 {
67 Bool result;
68 XkbSetDetectableAutoRepeat( GDK_DISPLAY(), flag, &result );
69 return result; /* TRUE if keyboard hardware supports this mode */
70 }
71 #else
72 bool wxSetDetectableAutoRepeat( bool WXUNUSED(flag) )
73 {
74 return FALSE;
75 }
76 #endif
77
78 // ----------------------------------------------------------------------------
79 // display characterstics
80 // ----------------------------------------------------------------------------
81
82 void *wxGetDisplay()
83 {
84 return GDK_DISPLAY();
85 }
86
87 void wxDisplaySize( int *width, int *height )
88 {
89 if (width) *width = gdk_screen_width();
90 if (height) *height = gdk_screen_height();
91 }
92
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
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
110 void wxGetMousePosition( int* x, int* y )
111 {
112 gdk_window_get_pointer( (GdkWindow*) NULL, x, y, (GdkModifierType*) NULL );
113 }
114
115 bool wxColourDisplay()
116 {
117 return TRUE;
118 }
119
120 int wxDisplayDepth()
121 {
122 return gdk_window_get_visual( wxGetRootWindow()->window )->depth;
123 }
124
125 int wxGUIAppTraits::GetOSVersion(int *majorVsn, int *minorVsn)
126 {
127 if (majorVsn)
128 *majorVsn = GTK_MAJOR_VERSION;
129 if (minorVsn)
130 *minorVsn = GTK_MINOR_VERSION;
131
132 return wxGTK;
133 }
134
135 wxWindow* wxFindWindowAtPoint(const wxPoint& pt)
136 {
137 return wxGenericFindWindowAtPoint(pt);
138 }
139
140
141 // ----------------------------------------------------------------------------
142 // subprocess routines
143 // ----------------------------------------------------------------------------
144
145 extern "C"
146 void GTK_EndProcessDetector(gpointer data, gint source,
147 GdkInputCondition WXUNUSED(condition) )
148 {
149 wxEndProcessData *proc_data = (wxEndProcessData *)data;
150
151 // has the process really terminated? unfortunately GDK (or GLib) seem to
152 // generate G_IO_HUP notification even when it simply tries to read from a
153 // closed fd and hasn't terminated at all
154 int pid = (proc_data->pid > 0) ? proc_data->pid : -(proc_data->pid);
155 int status = 0;
156 int rc = waitpid(pid, &status, WNOHANG);
157
158 if ( rc == 0 )
159 {
160 // no, it didn't exit yet, continue waiting
161 return;
162 }
163
164 // set exit code to -1 if something bad happened
165 proc_data->exitcode = rc != -1 && WIFEXITED(status) ? WEXITSTATUS(status)
166 : -1;
167
168 // child exited, end waiting
169 close(source);
170
171 // don't call us again!
172 gdk_input_remove(proc_data->tag);
173
174 wxHandleProcessTermination(proc_data);
175 }
176
177 int wxAddProcessCallback(wxEndProcessData *proc_data, int fd)
178 {
179 int tag = gdk_input_add(fd,
180 GDK_INPUT_READ,
181 GTK_EndProcessDetector,
182 (gpointer)proc_data);
183
184 return tag;
185 }
186