]> git.saurik.com Git - wxWidgets.git/blame_incremental - src/gtk/utilsgtk.cpp
Declarations missing from VC++ 5
[wxWidgets.git] / src / gtk / utilsgtk.cpp
... / ...
CommitLineData
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// For compilers that support precompilation, includes "wx.h".
11#include "wx/wxprec.h"
12
13#include "wx/utils.h"
14
15#ifndef WX_PRECOMP
16 #include "wx/string.h"
17 #include "wx/intl.h"
18 #include "wx/log.h"
19#endif
20
21#include "wx/apptrait.h"
22
23#include "wx/process.h"
24
25#include "wx/unix/execute.h"
26
27#include <stdarg.h>
28#include <string.h>
29#include <sys/stat.h>
30#include <sys/types.h>
31#include <sys/wait.h> // for WNOHANG
32#include <unistd.h>
33
34#include "glib.h"
35#include "gdk/gdk.h"
36#include "gtk/gtk.h"
37#include "gdk/gdkx.h"
38
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
44
45 #include "X11/XKBlib.h"
46
47 #undef explicit
48#endif // HAVE_X11_XKBLIB_H
49
50//-----------------------------------------------------------------------------
51// data
52//-----------------------------------------------------------------------------
53
54extern GtkWidget *wxGetRootWindow();
55
56//----------------------------------------------------------------------------
57// misc.
58//----------------------------------------------------------------------------
59#ifndef __EMX__
60// on OS/2, we use the wxBell from wxBase library
61
62void wxBell()
63{
64 gdk_beep();
65}
66#endif
67
68/* Don't synthesize KeyUp events holding down a key and producing
69 KeyDown events with autorepeat. */
70#ifdef HAVE_X11_XKBLIB_H
71bool wxSetDetectableAutoRepeat( bool flag )
72{
73 Bool result;
74 XkbSetDetectableAutoRepeat( GDK_DISPLAY(), flag, &result );
75 return result; /* true if keyboard hardware supports this mode */
76}
77#else
78bool wxSetDetectableAutoRepeat( bool WXUNUSED(flag) )
79{
80 return false;
81}
82#endif
83
84// Escapes string so that it is valid Pango markup XML string:
85wxString wxEscapeStringForPangoMarkup(const wxString& str)
86{
87 size_t len = str.length();
88 wxString out;
89 out.Alloc(len);
90 for (size_t i = 0; i < len; i++)
91 {
92 wxChar c = str[i];
93 switch (c)
94 {
95 case _T('&'):
96 out << _T("&amp;");
97 break;
98 case _T('<'):
99 out << _T("&lt;");
100 break;
101 case _T('>'):
102 out << _T("&gt;");
103 break;
104 case _T('\''):
105 out << _T("&apos;");
106 break;
107 case _T('"'):
108 out << _T("&quot;");
109 break;
110 default:
111 out << c;
112 break;
113 }
114 }
115 return out;
116}
117
118
119// ----------------------------------------------------------------------------
120// display characterstics
121// ----------------------------------------------------------------------------
122
123void *wxGetDisplay()
124{
125 return GDK_DISPLAY();
126}
127
128void wxDisplaySize( int *width, int *height )
129{
130 if (width) *width = gdk_screen_width();
131 if (height) *height = gdk_screen_height();
132}
133
134void wxDisplaySizeMM( int *width, int *height )
135{
136 if (width) *width = gdk_screen_width_mm();
137 if (height) *height = gdk_screen_height_mm();
138}
139
140void wxClientDisplayRect(int *x, int *y, int *width, int *height)
141{
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.
146 if (x) *x = 0;
147 if (y) *y = 0;
148 wxDisplaySize(width, height);
149}
150
151void wxGetMousePosition( int* x, int* y )
152{
153 gdk_window_get_pointer( (GdkWindow*) NULL, x, y, (GdkModifierType*) NULL );
154}
155
156bool wxColourDisplay()
157{
158 return true;
159}
160
161int wxDisplayDepth()
162{
163 return gdk_drawable_get_visual( wxGetRootWindow()->window )->depth;
164}
165
166wxWindow* wxFindWindowAtPoint(const wxPoint& pt)
167{
168 return wxGenericFindWindowAtPoint(pt);
169}
170
171#if !wxUSE_UNICODE
172
173wxCharBuffer wxConvertToGTK(const wxString& s, wxFontEncoding enc)
174{
175 if ( enc == wxFONTENCODING_UTF8 )
176 {
177 // no need for conversion at all
178 return wxCharBuffer(s);
179 }
180
181 wxWCharBuffer wbuf;
182 if ( enc == wxFONTENCODING_SYSTEM || enc == wxFONTENCODING_DEFAULT )
183 {
184 wbuf = wxConvUI->cMB2WC(s);
185 }
186 else // another encoding, use generic conversion class
187 {
188 wbuf = wxCSConv(enc).cMB2WC(s);
189 }
190
191 wxCharBuffer buf;
192 if ( wbuf )
193 buf = wxConvUTF8.cWC2MB(wbuf);
194
195 return buf;
196}
197
198#endif // !wxUSE_UNICODE
199
200// ----------------------------------------------------------------------------
201// subprocess routines
202// ----------------------------------------------------------------------------
203
204extern "C" {
205static
206void GTK_EndProcessDetector(gpointer data, gint source,
207 GdkInputCondition WXUNUSED(condition) )
208{
209 wxEndProcessData *proc_data = (wxEndProcessData *)data;
210
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);
215 int status = 0;
216 int rc = waitpid(pid, &status, WNOHANG);
217
218 if ( rc == 0 )
219 {
220 // no, it didn't exit yet, continue waiting
221 return;
222 }
223
224 // set exit code to -1 if something bad happened
225 proc_data->exitcode = rc != -1 && WIFEXITED(status) ? WEXITSTATUS(status)
226 : -1;
227
228 // child exited, end waiting
229 close(source);
230
231 // don't call us again!
232 gdk_input_remove(proc_data->tag);
233
234 wxHandleProcessTermination(proc_data);
235}
236}
237
238int wxAddProcessCallback(wxEndProcessData *proc_data, int fd)
239{
240 int tag = gdk_input_add(fd,
241 GDK_INPUT_READ,
242 GTK_EndProcessDetector,
243 (gpointer)proc_data);
244
245 return tag;
246}
247
248
249
250// ----------------------------------------------------------------------------
251// wxPlatformInfo-related
252// ----------------------------------------------------------------------------
253
254wxPortId wxGUIAppTraits::GetToolkitVersion(int *verMaj, int *verMin) const
255{
256 if ( verMaj )
257 *verMaj = gtk_major_version;
258 if ( verMin )
259 *verMin = gtk_minor_version;
260
261 return wxPORT_GTK;
262}