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