]>
git.saurik.com Git - wxWidgets.git/blob - src/gtk1/utilsgtk.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/gtk/utilsgtk.cpp
4 // Author: Robert Roebling
6 // Copyright: (c) 1998 Robert Roebling
7 // Licence: wxWindows licence
8 /////////////////////////////////////////////////////////////////////////////
10 // For compilers that support precompilation, includes "wx.h".
11 #include "wx/wxprec.h"
14 #include "wx/string.h"
16 #include "wx/apptrait.h"
20 #include "wx/process.h"
22 #include "wx/unix/execute.h"
27 #include <sys/types.h>
28 #include <sys/wait.h> // for WNOHANG
35 #include "gtk/gtkfeatures.h"
39 #ifdef HAVE_X11_XKBLIB_H
40 /* under HP-UX and Solaris 2.6, at least, XKBlib.h defines structures with
41 * field named "explicit" - which is, of course, an error for a C++
42 * compiler. To be on the safe side, just redefine it everywhere. */
43 #define explicit __wx_explicit
45 #include "X11/XKBlib.h"
48 #endif // HAVE_X11_XKBLIB_H
50 //-----------------------------------------------------------------------------
52 //-----------------------------------------------------------------------------
54 extern GtkWidget
*wxGetRootWindow();
56 //----------------------------------------------------------------------------
58 //----------------------------------------------------------------------------
60 // on OS/2, we use the wxBell from wxBase library
68 /* Don't synthesize KeyUp events holding down a key and producing
69 KeyDown events with autorepeat. */
70 #ifdef HAVE_X11_XKBLIB_H
71 bool wxSetDetectableAutoRepeat( bool flag
)
74 XkbSetDetectableAutoRepeat( GDK_DISPLAY(), flag
, &result
);
75 return result
; /* TRUE if keyboard hardware supports this mode */
78 bool wxSetDetectableAutoRepeat( bool WXUNUSED(flag
) )
85 // Escapes string so that it is valid Pango markup XML string:
86 wxString
wxEscapeStringForPangoMarkup(const wxString
& str
)
88 size_t len
= str
.length();
91 for (size_t i
= 0; i
< len
; i
++)
121 // ----------------------------------------------------------------------------
122 // display characterstics
123 // ----------------------------------------------------------------------------
127 return GDK_DISPLAY();
130 void wxDisplaySize( int *width
, int *height
)
132 if (width
) *width
= gdk_screen_width();
133 if (height
) *height
= gdk_screen_height();
136 void wxDisplaySizeMM( int *width
, int *height
)
138 if (width
) *width
= gdk_screen_width_mm();
139 if (height
) *height
= gdk_screen_height_mm();
142 void wxClientDisplayRect(int *x
, int *y
, int *width
, int *height
)
144 // This is supposed to return desktop dimensions minus any window
145 // manager panels, menus, taskbars, etc. If there is a way to do that
146 // for this platform please fix this function, otherwise it defaults
147 // to the entire desktop.
150 wxDisplaySize(width
, height
);
153 void wxGetMousePosition( int* x
, int* y
)
155 gdk_window_get_pointer( (GdkWindow
*) NULL
, x
, y
, (GdkModifierType
*) NULL
);
158 bool wxColourDisplay()
165 return gdk_window_get_visual( wxGetRootWindow()->window
)->depth
;
168 wxToolkitInfo
& wxGUIAppTraits::GetToolkitInfo()
170 static wxToolkitInfo info
;
172 info
.shortName
= _T("gtk2");
174 info
.shortName
= _T("gtk");
176 info
.name
= _T("wxGTK");
177 #ifdef __WXUNIVERSAL__
178 info
.shortName
<< _T("univ");
179 info
.name
<< _T("/wxUniversal");
181 info
.versionMajor
= gtk_major_version
;
182 info
.versionMinor
= gtk_minor_version
;
187 wxWindow
* wxFindWindowAtPoint(const wxPoint
& pt
)
189 return wxGenericFindWindowAtPoint(pt
);
193 // ----------------------------------------------------------------------------
194 // subprocess routines
195 // ----------------------------------------------------------------------------
198 void GTK_EndProcessDetector(gpointer data
, gint source
,
199 GdkInputCondition
WXUNUSED(condition
) )
201 wxEndProcessData
*proc_data
= (wxEndProcessData
*)data
;
203 // has the process really terminated? unfortunately GDK (or GLib) seem to
204 // generate G_IO_HUP notification even when it simply tries to read from a
205 // closed fd and hasn't terminated at all
206 int pid
= (proc_data
->pid
> 0) ? proc_data
->pid
: -(proc_data
->pid
);
208 int rc
= waitpid(pid
, &status
, WNOHANG
);
212 // no, it didn't exit yet, continue waiting
216 // set exit code to -1 if something bad happened
217 proc_data
->exitcode
= rc
!= -1 && WIFEXITED(status
) ? WEXITSTATUS(status
)
220 // child exited, end waiting
223 // don't call us again!
224 gdk_input_remove(proc_data
->tag
);
226 wxHandleProcessTermination(proc_data
);
229 int wxAddProcessCallback(wxEndProcessData
*proc_data
, int fd
)
231 int tag
= gdk_input_add(fd
,
233 GTK_EndProcessDetector
,
234 (gpointer
)proc_data
);