]> git.saurik.com Git - wxWidgets.git/blob - src/gtk1/utilsgtk.cpp
fixed make uninstall
[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, Julian Smart and Markus Holzem
7 // Licence: wxWindows licence
8 /////////////////////////////////////////////////////////////////////////////
9
10 #include "wx/utils.h"
11 #include "wx/string.h"
12
13 #include "wx/intl.h"
14 #include "wx/log.h"
15
16 #include "wx/process.h"
17
18 #include "wx/unix/execute.h"
19
20 #include <stdarg.h>
21 #include <string.h>
22 #include <sys/stat.h>
23 #include <sys/types.h>
24 #include <sys/wait.h> // for WNOHANG
25 #include <unistd.h>
26
27 #include "glib.h"
28 #include "gdk/gdk.h"
29 #include "gtk/gtk.h"
30 #ifndef __WXGTK20__
31 #include "gtk/gtkfeatures.h"
32 #endif
33 #include "gdk/gdkx.h"
34
35 #ifdef HAVE_X11_XKBLIB_H
36 /* under HP-UX and Solaris 2.6, at least, XKBlib.h defines structures with
37 * field named "explicit" - which is, of course, an error for a C++
38 * compiler. To be on the safe side, just redefine it everywhere. */
39 #define explicit __wx_explicit
40
41 #include "X11/XKBlib.h"
42
43 #undef explicit
44 #endif // HAVE_X11_XKBLIB_H
45
46 //-----------------------------------------------------------------------------
47 // data
48 //-----------------------------------------------------------------------------
49
50 extern GtkWidget *wxGetRootWindow();
51
52 //----------------------------------------------------------------------------
53 // misc.
54 //----------------------------------------------------------------------------
55
56 void wxBell()
57 {
58 gdk_beep();
59 }
60
61 /* Don't synthesize KeyUp events holding down a key and producing
62 KeyDown events with autorepeat. */
63 #ifdef HAVE_X11_XKBLIB_H
64 bool wxSetDetectableAutoRepeat( bool flag )
65 {
66 Bool result;
67 XkbSetDetectableAutoRepeat( GDK_DISPLAY(), flag, &result );
68 return result; /* TRUE if keyboard hardware supports this mode */
69 }
70 #else
71 bool wxSetDetectableAutoRepeat( bool WXUNUSED(flag) )
72 {
73 return FALSE;
74 }
75 #endif
76
77 // ----------------------------------------------------------------------------
78 // display characterstics
79 // ----------------------------------------------------------------------------
80
81 void *wxGetDisplay()
82 {
83 return GDK_DISPLAY();
84 }
85
86 void wxDisplaySize( int *width, int *height )
87 {
88 if (width) *width = gdk_screen_width();
89 if (height) *height = gdk_screen_height();
90 }
91
92 void wxDisplaySizeMM( int *width, int *height )
93 {
94 if (width) *width = gdk_screen_width_mm();
95 if (height) *height = gdk_screen_height_mm();
96 }
97
98 void wxClientDisplayRect(int *x, int *y, int *width, int *height)
99 {
100 // This is supposed to return desktop dimensions minus any window
101 // manager panels, menus, taskbars, etc. If there is a way to do that
102 // for this platform please fix this function, otherwise it defaults
103 // to the entire desktop.
104 if (x) *x = 0;
105 if (y) *y = 0;
106 wxDisplaySize(width, height);
107 }
108
109 void wxGetMousePosition( int* x, int* y )
110 {
111 gdk_window_get_pointer( (GdkWindow*) NULL, x, y, (GdkModifierType*) NULL );
112 }
113
114 bool wxColourDisplay()
115 {
116 return TRUE;
117 }
118
119 int wxDisplayDepth()
120 {
121 return gdk_window_get_visual( wxGetRootWindow()->window )->depth;
122 }
123
124 int wxGetOsVersion(int *majorVsn, int *minorVsn)
125 {
126 if (majorVsn) *majorVsn = GTK_MAJOR_VERSION;
127 if (minorVsn) *minorVsn = GTK_MINOR_VERSION;
128
129 return wxGTK;
130 }
131
132 wxWindow* wxFindWindowAtPoint(const wxPoint& pt)
133 {
134 return wxGenericFindWindowAtPoint(pt);
135 }
136
137
138 // ----------------------------------------------------------------------------
139 // subprocess routines
140 // ----------------------------------------------------------------------------
141
142 extern "C"
143 void GTK_EndProcessDetector(gpointer data, gint source,
144 GdkInputCondition WXUNUSED(condition) )
145 {
146 wxEndProcessData *proc_data = (wxEndProcessData *)data;
147
148 // has the process really terminated? unfortunately GDK (or GLib) seem to
149 // generate G_IO_HUP notification even when it simply tries to read from a
150 // closed fd and hasn't terminated at all
151 int pid = (proc_data->pid > 0) ? proc_data->pid : -(proc_data->pid);
152 int status = 0;
153 int rc = waitpid(pid, &status, WNOHANG);
154
155 if ( rc == 0 )
156 {
157 // no, it didn't exit yet, continue waiting
158 return;
159 }
160
161 // set exit code to -1 if something bad happened
162 proc_data->exitcode = rc != -1 && WIFEXITED(status) ? WEXITSTATUS(status)
163 : -1;
164
165 // child exited, end waiting
166 close(source);
167
168 // don't call us again!
169 gdk_input_remove(proc_data->tag);
170
171 wxHandleProcessTermination(proc_data);
172 }
173
174 int wxAddProcessCallback(wxEndProcessData *proc_data, int fd)
175 {
176 int tag = gdk_input_add(fd,
177 GDK_INPUT_READ,
178 GTK_EndProcessDetector,
179 (gpointer)proc_data);
180
181 return tag;
182 }
183