]>
git.saurik.com Git - wxWidgets.git/blob - src/gtk/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"
16 #include "wx/string.h"
21 #include "wx/apptrait.h"
23 #include "wx/process.h"
25 #include "wx/unix/execute.h"
30 #include <sys/types.h>
31 #include <sys/wait.h> // for WNOHANG
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
) )
84 // Escapes string so that it is valid Pango markup XML string:
85 wxString
wxEscapeStringForPangoMarkup(const wxString
& str
)
87 size_t len
= str
.length();
90 for (size_t i
= 0; i
< len
; i
++)
119 // ----------------------------------------------------------------------------
120 // display characterstics
121 // ----------------------------------------------------------------------------
125 return GDK_DISPLAY();
128 void wxDisplaySize( int *width
, int *height
)
130 if (width
) *width
= gdk_screen_width();
131 if (height
) *height
= gdk_screen_height();
134 void wxDisplaySizeMM( int *width
, int *height
)
136 if (width
) *width
= gdk_screen_width_mm();
137 if (height
) *height
= gdk_screen_height_mm();
140 void wxClientDisplayRect(int *x
, int *y
, int *width
, int *height
)
142 // This is supposed to return desktop dimensions minus any window
143 // manager panels, menus, taskbars, etc. If there is a way to do that
144 // for this platform please fix this function, otherwise it defaults
145 // to the entire desktop.
148 wxDisplaySize(width
, height
);
151 void wxGetMousePosition( int* x
, int* y
)
153 gdk_window_get_pointer( (GdkWindow
*) NULL
, x
, y
, (GdkModifierType
*) NULL
);
156 bool wxColourDisplay()
163 return gdk_drawable_get_visual( wxGetRootWindow()->window
)->depth
;
166 wxWindow
* wxFindWindowAtPoint(const wxPoint
& pt
)
168 return wxGenericFindWindowAtPoint(pt
);
173 wxCharBuffer
wxConvertToGTK(const wxString
& s
, wxFontEncoding enc
)
175 if ( enc
== wxFONTENCODING_UTF8
)
177 // no need for conversion at all
178 return wxCharBuffer(s
);
182 if ( enc
== wxFONTENCODING_SYSTEM
|| enc
== wxFONTENCODING_DEFAULT
)
184 wbuf
= wxConvUI
->cMB2WC(s
);
186 else // another encoding, use generic conversion class
188 wbuf
= wxCSConv(enc
).cMB2WC(s
);
193 buf
= wxConvUTF8
.cWC2MB(wbuf
);
198 #endif // !wxUSE_UNICODE
200 // ----------------------------------------------------------------------------
201 // subprocess routines
202 // ----------------------------------------------------------------------------
206 void GTK_EndProcessDetector(gpointer data
, gint source
,
207 GdkInputCondition
WXUNUSED(condition
) )
209 wxEndProcessData
*proc_data
= (wxEndProcessData
*)data
;
211 // has the process really terminated? unfortunately GDK (or GLib) seem to
212 // generate G_IO_HUP notification even when it simply tries to read from a
213 // closed fd and hasn't terminated at all
214 int pid
= (proc_data
->pid
> 0) ? proc_data
->pid
: -(proc_data
->pid
);
216 int rc
= waitpid(pid
, &status
, WNOHANG
);
220 // no, it didn't exit yet, continue waiting
224 // set exit code to -1 if something bad happened
225 proc_data
->exitcode
= rc
!= -1 && WIFEXITED(status
) ? WEXITSTATUS(status
)
228 // child exited, end waiting
231 // don't call us again!
232 gdk_input_remove(proc_data
->tag
);
234 wxHandleProcessTermination(proc_data
);
238 int wxAddProcessCallback(wxEndProcessData
*proc_data
, int fd
)
240 int tag
= gdk_input_add(fd
,
242 GTK_EndProcessDetector
,
243 (gpointer
)proc_data
);
250 // ----------------------------------------------------------------------------
251 // wxPlatformInfo-related
252 // ----------------------------------------------------------------------------
254 wxPortId
wxGUIAppTraits::GetToolkitVersion(int *verMaj
, int *verMin
) const
257 *verMaj
= gtk_major_version
;
259 *verMin
= gtk_minor_version
;