]> git.saurik.com Git - wxWidgets.git/blame - src/gtk1/utilsgtk.cpp
Fix memory leak when a spacer is added, and crash when a window is added before wxSiz...
[wxWidgets.git] / src / gtk1 / 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
KB
13#include "wx/utils.h"
14#include "wx/string.h"
15
46446cc2 16#include "wx/apptrait.h"
02847e59
VZ
17#include "wx/intl.h"
18#include "wx/log.h"
19
5336ece4
VZ
20#include "wx/process.h"
21
518b5d2f
VZ
22#include "wx/unix/execute.h"
23
c801d85f 24#include <stdarg.h>
c801d85f
KB
25#include <string.h>
26#include <sys/stat.h>
27#include <sys/types.h>
dbd25330 28#include <sys/wait.h> // for WNOHANG
c801d85f 29#include <unistd.h>
91b8de8d
RR
30
31#include "glib.h"
32#include "gdk/gdk.h"
33#include "gtk/gtk.h"
df530a26 34#ifndef __WXGTK20__
91b8de8d 35#include "gtk/gtkfeatures.h"
df530a26 36#endif
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 );
27933891
RR
75 return result; /* TRUE if keyboard hardware supports this mode */
76}
77#else
78bool wxSetDetectableAutoRepeat( bool WXUNUSED(flag) )
79{
80 return FALSE;
f0492f7d 81}
27933891 82#endif
f0492f7d 83
66bd83b4
VS
84#ifdef __WXGTK20__
85// Escapes string so that it is valid Pango markup XML string:
86wxString wxEscapeStringForPangoMarkup(const wxString& str)
87{
88 size_t len = str.length();
89 wxString out;
90 out.Alloc(len);
91 for (size_t i = 0; i < len; i++)
92 {
93 wxChar c = str[i];
94 switch (c)
95 {
96 case _T('&'):
97 out << _T("&amp;");
98 break;
99 case _T('<'):
100 out << _T("&lt;");
101 break;
102 case _T('>'):
103 out << _T("&gt;");
104 break;
105 case _T('\''):
106 out << _T("&apos;");
107 break;
108 case _T('"'):
109 out << _T("&quot;");
110 break;
111 default:
112 out << c;
113 break;
114 }
115 }
116 return out;
117}
118#endif
119
120
518b5d2f
VZ
121// ----------------------------------------------------------------------------
122// display characterstics
123// ----------------------------------------------------------------------------
82052aff 124
d111a89a
VZ
125void *wxGetDisplay()
126{
27df579a 127 return GDK_DISPLAY();
d111a89a
VZ
128}
129
c0392997
RR
130void wxDisplaySize( int *width, int *height )
131{
e52f60e6
RR
132 if (width) *width = gdk_screen_width();
133 if (height) *height = gdk_screen_height();
c0392997
RR
134}
135
904a68b6
RL
136void wxDisplaySizeMM( int *width, int *height )
137{
138 if (width) *width = gdk_screen_width_mm();
139 if (height) *height = gdk_screen_height_mm();
140}
141
ec5d7799
RD
142void wxClientDisplayRect(int *x, int *y, int *width, int *height)
143{
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.
148 if (x) *x = 0;
149 if (y) *y = 0;
150 wxDisplaySize(width, height);
151}
152
6de97a3b
RR
153void wxGetMousePosition( int* x, int* y )
154{
bbe0af5b 155 gdk_window_get_pointer( (GdkWindow*) NULL, x, y, (GdkModifierType*) NULL );
e52f60e6 156}
6de97a3b 157
518b5d2f 158bool wxColourDisplay()
6de97a3b 159{
e52f60e6 160 return TRUE;
6de97a3b
RR
161}
162
518b5d2f 163int wxDisplayDepth()
6de97a3b 164{
c2fa61e8 165 return gdk_window_get_visual( wxGetRootWindow()->window )->depth;
6de97a3b
RR
166}
167
324899f6 168wxToolkitInfo& wxGUIAppTraits::GetToolkitInfo()
bbe0af5b 169{
a8eaaeb2
VS
170 static wxToolkitInfo info;
171#ifdef __WXGTK20__
172 info.shortName = _T("gtk2");
173#else
174 info.shortName = _T("gtk");
175#endif
176 info.name = _T("wxGTK");
177#ifdef __WXUNIVERSAL__
178 info.shortName << _T("univ");
179 info.name << _T("/wxUniversal");
180#endif
a5441ce3
VS
181 info.versionMajor = gtk_major_version;
182 info.versionMinor = gtk_minor_version;
a8eaaeb2 183 info.os = wxGTK;
324899f6 184 return info;
bbe0af5b
RR
185}
186
57591e0e
JS
187wxWindow* wxFindWindowAtPoint(const wxPoint& pt)
188{
189 return wxGenericFindWindowAtPoint(pt);
190}
191
192
518b5d2f 193// ----------------------------------------------------------------------------
c801d85f 194// subprocess routines
518b5d2f 195// ----------------------------------------------------------------------------
cf447356 196
865bb325
VZ
197extern "C" {
198static
90350682
VZ
199void GTK_EndProcessDetector(gpointer data, gint source,
200 GdkInputCondition WXUNUSED(condition) )
cf447356 201{
ab857a4e 202 wxEndProcessData *proc_data = (wxEndProcessData *)data;
dbd25330
VZ
203
204 // has the process really terminated? unfortunately GDK (or GLib) seem to
205 // generate G_IO_HUP notification even when it simply tries to read from a
206 // closed fd and hasn't terminated at all
207 int pid = (proc_data->pid > 0) ? proc_data->pid : -(proc_data->pid);
447f908a
VZ
208 int status = 0;
209 int rc = waitpid(pid, &status, WNOHANG);
210
211 if ( rc == 0 )
dbd25330
VZ
212 {
213 // no, it didn't exit yet, continue waiting
214 return;
215 }
216
447f908a
VZ
217 // set exit code to -1 if something bad happened
218 proc_data->exitcode = rc != -1 && WIFEXITED(status) ? WEXITSTATUS(status)
219 : -1;
220
dbd25330 221 // child exited, end waiting
ab857a4e 222 close(source);
dbd25330
VZ
223
224 // don't call us again!
ab857a4e
KB
225 gdk_input_remove(proc_data->tag);
226
ab857a4e 227 wxHandleProcessTermination(proc_data);
3069ac4e 228}
865bb325 229}
cf447356 230
518b5d2f 231int wxAddProcessCallback(wxEndProcessData *proc_data, int fd)
c801d85f 232{
518b5d2f
VZ
233 int tag = gdk_input_add(fd,
234 GDK_INPUT_READ,
235 GTK_EndProcessDetector,
236 (gpointer)proc_data);
c801d85f 237
518b5d2f 238 return tag;
3069ac4e 239}
c801d85f 240