]> git.saurik.com Git - wxWidgets.git/blame - src/gtk/utilsgtk.cpp
added wxRegEx::GetMatchCount (patch 938995)
[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
518b5d2f 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
518b5d2f
VZ
84// ----------------------------------------------------------------------------
85// display characterstics
86// ----------------------------------------------------------------------------
82052aff 87
d111a89a
VZ
88void *wxGetDisplay()
89{
27df579a 90 return GDK_DISPLAY();
d111a89a
VZ
91}
92
c0392997
RR
93void wxDisplaySize( int *width, int *height )
94{
e52f60e6
RR
95 if (width) *width = gdk_screen_width();
96 if (height) *height = gdk_screen_height();
c0392997
RR
97}
98
904a68b6
RL
99void wxDisplaySizeMM( int *width, int *height )
100{
101 if (width) *width = gdk_screen_width_mm();
102 if (height) *height = gdk_screen_height_mm();
103}
104
ec5d7799
RD
105void wxClientDisplayRect(int *x, int *y, int *width, int *height)
106{
107 // This is supposed to return desktop dimensions minus any window
108 // manager panels, menus, taskbars, etc. If there is a way to do that
109 // for this platform please fix this function, otherwise it defaults
110 // to the entire desktop.
111 if (x) *x = 0;
112 if (y) *y = 0;
113 wxDisplaySize(width, height);
114}
115
6de97a3b
RR
116void wxGetMousePosition( int* x, int* y )
117{
bbe0af5b 118 gdk_window_get_pointer( (GdkWindow*) NULL, x, y, (GdkModifierType*) NULL );
e52f60e6 119}
6de97a3b 120
518b5d2f 121bool wxColourDisplay()
6de97a3b 122{
e52f60e6 123 return TRUE;
6de97a3b
RR
124}
125
518b5d2f 126int wxDisplayDepth()
6de97a3b 127{
c2fa61e8 128 return gdk_window_get_visual( wxGetRootWindow()->window )->depth;
6de97a3b
RR
129}
130
324899f6 131wxToolkitInfo& wxGUIAppTraits::GetToolkitInfo()
bbe0af5b 132{
a8eaaeb2
VS
133 static wxToolkitInfo info;
134#ifdef __WXGTK20__
135 info.shortName = _T("gtk2");
136#else
137 info.shortName = _T("gtk");
138#endif
139 info.name = _T("wxGTK");
140#ifdef __WXUNIVERSAL__
141 info.shortName << _T("univ");
142 info.name << _T("/wxUniversal");
143#endif
a5441ce3
VS
144 info.versionMajor = gtk_major_version;
145 info.versionMinor = gtk_minor_version;
a8eaaeb2 146 info.os = wxGTK;
324899f6 147 return info;
bbe0af5b
RR
148}
149
57591e0e
JS
150wxWindow* wxFindWindowAtPoint(const wxPoint& pt)
151{
152 return wxGenericFindWindowAtPoint(pt);
153}
154
155
518b5d2f 156// ----------------------------------------------------------------------------
c801d85f 157// subprocess routines
518b5d2f 158// ----------------------------------------------------------------------------
cf447356 159
90350682
VZ
160extern "C"
161void GTK_EndProcessDetector(gpointer data, gint source,
162 GdkInputCondition WXUNUSED(condition) )
cf447356 163{
ab857a4e 164 wxEndProcessData *proc_data = (wxEndProcessData *)data;
dbd25330
VZ
165
166 // has the process really terminated? unfortunately GDK (or GLib) seem to
167 // generate G_IO_HUP notification even when it simply tries to read from a
168 // closed fd and hasn't terminated at all
169 int pid = (proc_data->pid > 0) ? proc_data->pid : -(proc_data->pid);
447f908a
VZ
170 int status = 0;
171 int rc = waitpid(pid, &status, WNOHANG);
172
173 if ( rc == 0 )
dbd25330
VZ
174 {
175 // no, it didn't exit yet, continue waiting
176 return;
177 }
178
447f908a
VZ
179 // set exit code to -1 if something bad happened
180 proc_data->exitcode = rc != -1 && WIFEXITED(status) ? WEXITSTATUS(status)
181 : -1;
182
dbd25330 183 // child exited, end waiting
ab857a4e 184 close(source);
dbd25330
VZ
185
186 // don't call us again!
ab857a4e
KB
187 gdk_input_remove(proc_data->tag);
188
ab857a4e 189 wxHandleProcessTermination(proc_data);
3069ac4e 190}
cf447356 191
518b5d2f 192int wxAddProcessCallback(wxEndProcessData *proc_data, int fd)
c801d85f 193{
518b5d2f
VZ
194 int tag = gdk_input_add(fd,
195 GDK_INPUT_READ,
196 GTK_EndProcessDetector,
197 (gpointer)proc_data);
c801d85f 198
518b5d2f 199 return tag;
3069ac4e 200}
c801d85f 201