]> git.saurik.com Git - wxWidgets.git/blame - src/gtk/utilsgtk.cpp
corrected painting implementation for wxDFB
[wxWidgets.git] / src / gtk / utilsgtk.cpp
CommitLineData
c801d85f 1/////////////////////////////////////////////////////////////////////////////
dbd25330 2// Name: src/gtk/utilsgtk.cpp
c801d85f
KB
3// Purpose:
4// Author: Robert Roebling
dfcb1ae0 5// Id: $Id$
6c9a19aa 6// Copyright: (c) 1998 Robert Roebling
65571936 7// Licence: wxWindows licence
c801d85f
KB
8/////////////////////////////////////////////////////////////////////////////
9
14f355c2
VS
10// For compilers that support precompilation, includes "wx.h".
11#include "wx/wxprec.h"
12
c801d85f 13#include "wx/utils.h"
df91131c
WS
14
15#ifndef WX_PRECOMP
16 #include "wx/string.h"
88a7a4e1 17 #include "wx/intl.h"
e4db172a 18 #include "wx/log.h"
df91131c 19#endif
c801d85f 20
46446cc2 21#include "wx/apptrait.h"
02847e59 22
5336ece4
VZ
23#include "wx/process.h"
24
518b5d2f
VZ
25#include "wx/unix/execute.h"
26
c801d85f 27#include <stdarg.h>
c801d85f
KB
28#include <string.h>
29#include <sys/stat.h>
30#include <sys/types.h>
dbd25330 31#include <sys/wait.h> // for WNOHANG
c801d85f 32#include <unistd.h>
91b8de8d
RR
33
34#include "glib.h"
35#include "gdk/gdk.h"
36#include "gtk/gtk.h"
91b8de8d 37#include "gdk/gdkx.h"
88ac883a 38
27933891 39#ifdef HAVE_X11_XKBLIB_H
154c4aa1
VZ
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. */
88ac883a 43 #define explicit __wx_explicit
ec5d7799 44
154c4aa1 45 #include "X11/XKBlib.h"
ec5d7799 46
88ac883a 47 #undef explicit
27933891 48#endif // HAVE_X11_XKBLIB_H
dfcb1ae0 49
d76fe38b
RR
50//-----------------------------------------------------------------------------
51// data
52//-----------------------------------------------------------------------------
53
c2fa61e8 54extern GtkWidget *wxGetRootWindow();
d76fe38b
RR
55
56//----------------------------------------------------------------------------
c801d85f 57// misc.
d76fe38b 58//----------------------------------------------------------------------------
189d1ae7
SN
59#ifndef __EMX__
60// on OS/2, we use the wxBell from wxBase library
c801d85f 61
518b5d2f 62void wxBell()
c801d85f 63{
e52f60e6
RR
64 gdk_beep();
65}
189d1ae7 66#endif
c801d85f 67
27933891
RR
68/* Don't synthesize KeyUp events holding down a key and producing
69 KeyDown events with autorepeat. */
70#ifdef HAVE_X11_XKBLIB_H
f0492f7d
RR
71bool wxSetDetectableAutoRepeat( bool flag )
72{
73 Bool result;
74 XkbSetDetectableAutoRepeat( GDK_DISPLAY(), flag, &result );
df91131c 75 return result; /* true if keyboard hardware supports this mode */
27933891
RR
76}
77#else
78bool wxSetDetectableAutoRepeat( bool WXUNUSED(flag) )
79{
df91131c 80 return false;
f0492f7d 81}
27933891 82#endif
f0492f7d 83
66bd83b4
VS
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}
66bd83b4
VS
117
118
518b5d2f
VZ
119// ----------------------------------------------------------------------------
120// display characterstics
121// ----------------------------------------------------------------------------
82052aff 122
d111a89a
VZ
123void *wxGetDisplay()
124{
27df579a 125 return GDK_DISPLAY();
d111a89a
VZ
126}
127
c0392997
RR
128void wxDisplaySize( int *width, int *height )
129{
e52f60e6
RR
130 if (width) *width = gdk_screen_width();
131 if (height) *height = gdk_screen_height();
c0392997
RR
132}
133
904a68b6
RL
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
ec5d7799
RD
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
6de97a3b
RR
151void wxGetMousePosition( int* x, int* y )
152{
bbe0af5b 153 gdk_window_get_pointer( (GdkWindow*) NULL, x, y, (GdkModifierType*) NULL );
e52f60e6 154}
6de97a3b 155
518b5d2f 156bool wxColourDisplay()
6de97a3b 157{
df91131c 158 return true;
6de97a3b
RR
159}
160
518b5d2f 161int wxDisplayDepth()
6de97a3b 162{
22a3bce4 163 return gdk_drawable_get_visual( wxGetRootWindow()->window )->depth;
6de97a3b
RR
164}
165
57591e0e
JS
166wxWindow* wxFindWindowAtPoint(const wxPoint& pt)
167{
168 return wxGenericFindWindowAtPoint(pt);
169}
170
5f11fef5
VZ
171#if !wxUSE_UNICODE
172
173wxCharBuffer wxConvertToGTK(const wxString& s, wxFontEncoding enc)
174{
27dee9ae 175 wxCharBuffer buf;
5f11fef5
VZ
176 if ( enc == wxFONTENCODING_UTF8 )
177 {
27dee9ae
VZ
178 // no need for conversion at all, but do check that we have a valid
179 // UTF-8 string because passing invalid UTF-8 to GTK+ is going to
180 // result in a GTK+ error message and, especially, loss of data which
181 // was supposed to be shown in the GUI
182 if ( wxConvUTF8.ToWChar(NULL, 0, s, s.length()) == wxCONV_FAILED )
183 {
184 // warn the programmer that something is probably wrong in his code
185 //
186 // NB: don't include the string in output because chances are that
187 // this invalid UTF-8 string could result in more errors itself
188 // if the application shows logs in the GUI and so we get into
189 // an infinite loop
190 wxLogDebug(_T("Invalid UTF-8 string in wxConvertToGTK()"));
191
192 // but still try to show at least something on the screen
193 wxMBConvUTF8 utf8permissive(wxMBConvUTF8::MAP_INVALID_UTF8_TO_OCTAL);
194 wxWCharBuffer wbuf(utf8permissive.cMB2WC(s));
195 buf = wxConvUTF8.cWC2MB(wbuf);
196 }
197 else // valid UTF-8 string, no need to convert
198 {
199 buf = wxCharBuffer(s);
200 }
12bc5f9a 201 }
27dee9ae 202 else // !UTF-8
12bc5f9a 203 {
27dee9ae
VZ
204 wxWCharBuffer wbuf;
205 if ( enc == wxFONTENCODING_SYSTEM || enc == wxFONTENCODING_DEFAULT )
206 {
207 wbuf = wxConvUI->cMB2WC(s);
208 }
209 else // another encoding, use generic conversion class
210 {
211 wbuf = wxCSConv(enc).cMB2WC(s);
212 }
12bc5f9a 213
27dee9ae
VZ
214 if ( wbuf )
215 buf = wxConvUTF8.cWC2MB(wbuf);
216 }
5f11fef5
VZ
217
218 return buf;
219}
220
221#endif // !wxUSE_UNICODE
57591e0e 222
518b5d2f 223// ----------------------------------------------------------------------------
c801d85f 224// subprocess routines
518b5d2f 225// ----------------------------------------------------------------------------
cf447356 226
865bb325
VZ
227extern "C" {
228static
90350682
VZ
229void GTK_EndProcessDetector(gpointer data, gint source,
230 GdkInputCondition WXUNUSED(condition) )
cf447356 231{
ab857a4e 232 wxEndProcessData *proc_data = (wxEndProcessData *)data;
dbd25330
VZ
233
234 // has the process really terminated? unfortunately GDK (or GLib) seem to
235 // generate G_IO_HUP notification even when it simply tries to read from a
236 // closed fd and hasn't terminated at all
237 int pid = (proc_data->pid > 0) ? proc_data->pid : -(proc_data->pid);
447f908a
VZ
238 int status = 0;
239 int rc = waitpid(pid, &status, WNOHANG);
240
241 if ( rc == 0 )
dbd25330
VZ
242 {
243 // no, it didn't exit yet, continue waiting
244 return;
245 }
246
447f908a
VZ
247 // set exit code to -1 if something bad happened
248 proc_data->exitcode = rc != -1 && WIFEXITED(status) ? WEXITSTATUS(status)
249 : -1;
250
dbd25330 251 // child exited, end waiting
ab857a4e 252 close(source);
dbd25330
VZ
253
254 // don't call us again!
ab857a4e
KB
255 gdk_input_remove(proc_data->tag);
256
ab857a4e 257 wxHandleProcessTermination(proc_data);
3069ac4e 258}
865bb325 259}
cf447356 260
518b5d2f 261int wxAddProcessCallback(wxEndProcessData *proc_data, int fd)
c801d85f 262{
518b5d2f
VZ
263 int tag = gdk_input_add(fd,
264 GDK_INPUT_READ,
265 GTK_EndProcessDetector,
266 (gpointer)proc_data);
c801d85f 267
518b5d2f 268 return tag;
3069ac4e 269}
8bb6b2c0
VZ
270
271
272
273// ----------------------------------------------------------------------------
274// wxPlatformInfo-related
275// ----------------------------------------------------------------------------
276
277wxPortId wxGUIAppTraits::GetToolkitVersion(int *verMaj, int *verMin) const
278{
279 if ( verMaj )
280 *verMaj = gtk_major_version;
281 if ( verMin )
282 *verMin = gtk_minor_version;
283
284 return wxPORT_GTK;
285}