]> git.saurik.com Git - wxWidgets.git/blame - src/gtk1/utilsgtk.cpp
Applied patch [ 1435340 ] Add support of wxToggleButton to wxGenericValidator
[wxWidgets.git] / src / gtk1 / utilsgtk.cpp
CommitLineData
c801d85f 1/////////////////////////////////////////////////////////////////////////////
3cbab641 2// Name: src/gtk1/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"
34#include "gtk/gtkfeatures.h"
35#include "gdk/gdkx.h"
88ac883a 36
27933891 37#ifdef HAVE_X11_XKBLIB_H
154c4aa1
VZ
38 /* under HP-UX and Solaris 2.6, at least, XKBlib.h defines structures with
39 * field named "explicit" - which is, of course, an error for a C++
40 * compiler. To be on the safe side, just redefine it everywhere. */
88ac883a 41 #define explicit __wx_explicit
ec5d7799 42
154c4aa1 43 #include "X11/XKBlib.h"
ec5d7799 44
88ac883a 45 #undef explicit
27933891 46#endif // HAVE_X11_XKBLIB_H
dfcb1ae0 47
d76fe38b
RR
48//-----------------------------------------------------------------------------
49// data
50//-----------------------------------------------------------------------------
51
c2fa61e8 52extern GtkWidget *wxGetRootWindow();
d76fe38b
RR
53
54//----------------------------------------------------------------------------
c801d85f 55// misc.
d76fe38b 56//----------------------------------------------------------------------------
189d1ae7
SN
57#ifndef __EMX__
58// on OS/2, we use the wxBell from wxBase library
c801d85f 59
518b5d2f 60void wxBell()
c801d85f 61{
e52f60e6
RR
62 gdk_beep();
63}
189d1ae7 64#endif
c801d85f 65
27933891
RR
66/* Don't synthesize KeyUp events holding down a key and producing
67 KeyDown events with autorepeat. */
68#ifdef HAVE_X11_XKBLIB_H
f0492f7d
RR
69bool wxSetDetectableAutoRepeat( bool flag )
70{
71 Bool result;
72 XkbSetDetectableAutoRepeat( GDK_DISPLAY(), flag, &result );
27933891
RR
73 return result; /* TRUE if keyboard hardware supports this mode */
74}
75#else
76bool wxSetDetectableAutoRepeat( bool WXUNUSED(flag) )
77{
78 return FALSE;
f0492f7d 79}
27933891 80#endif
f0492f7d 81
518b5d2f
VZ
82// ----------------------------------------------------------------------------
83// display characterstics
84// ----------------------------------------------------------------------------
82052aff 85
d111a89a
VZ
86void *wxGetDisplay()
87{
27df579a 88 return GDK_DISPLAY();
d111a89a
VZ
89}
90
c0392997
RR
91void wxDisplaySize( int *width, int *height )
92{
e52f60e6
RR
93 if (width) *width = gdk_screen_width();
94 if (height) *height = gdk_screen_height();
c0392997
RR
95}
96
904a68b6
RL
97void wxDisplaySizeMM( int *width, int *height )
98{
99 if (width) *width = gdk_screen_width_mm();
100 if (height) *height = gdk_screen_height_mm();
101}
102
ec5d7799
RD
103void wxClientDisplayRect(int *x, int *y, int *width, int *height)
104{
105 // This is supposed to return desktop dimensions minus any window
106 // manager panels, menus, taskbars, etc. If there is a way to do that
107 // for this platform please fix this function, otherwise it defaults
108 // to the entire desktop.
109 if (x) *x = 0;
110 if (y) *y = 0;
111 wxDisplaySize(width, height);
112}
113
6de97a3b
RR
114void wxGetMousePosition( int* x, int* y )
115{
bbe0af5b 116 gdk_window_get_pointer( (GdkWindow*) NULL, x, y, (GdkModifierType*) NULL );
e52f60e6 117}
6de97a3b 118
518b5d2f 119bool wxColourDisplay()
6de97a3b 120{
e52f60e6 121 return TRUE;
6de97a3b
RR
122}
123
518b5d2f 124int wxDisplayDepth()
6de97a3b 125{
c2fa61e8 126 return gdk_window_get_visual( wxGetRootWindow()->window )->depth;
6de97a3b
RR
127}
128
324899f6 129wxToolkitInfo& wxGUIAppTraits::GetToolkitInfo()
bbe0af5b 130{
a8eaaeb2 131 static wxToolkitInfo info;
a8eaaeb2 132 info.shortName = _T("gtk");
a8eaaeb2
VS
133 info.name = _T("wxGTK");
134#ifdef __WXUNIVERSAL__
135 info.shortName << _T("univ");
136 info.name << _T("/wxUniversal");
137#endif
a5441ce3
VS
138 info.versionMajor = gtk_major_version;
139 info.versionMinor = gtk_minor_version;
a8eaaeb2 140 info.os = wxGTK;
324899f6 141 return info;
bbe0af5b
RR
142}
143
57591e0e
JS
144wxWindow* wxFindWindowAtPoint(const wxPoint& pt)
145{
146 return wxGenericFindWindowAtPoint(pt);
147}
148
149
518b5d2f 150// ----------------------------------------------------------------------------
c801d85f 151// subprocess routines
518b5d2f 152// ----------------------------------------------------------------------------
cf447356 153
865bb325
VZ
154extern "C" {
155static
90350682
VZ
156void GTK_EndProcessDetector(gpointer data, gint source,
157 GdkInputCondition WXUNUSED(condition) )
cf447356 158{
ab857a4e 159 wxEndProcessData *proc_data = (wxEndProcessData *)data;
dbd25330
VZ
160
161 // has the process really terminated? unfortunately GDK (or GLib) seem to
162 // generate G_IO_HUP notification even when it simply tries to read from a
163 // closed fd and hasn't terminated at all
164 int pid = (proc_data->pid > 0) ? proc_data->pid : -(proc_data->pid);
447f908a
VZ
165 int status = 0;
166 int rc = waitpid(pid, &status, WNOHANG);
167
168 if ( rc == 0 )
dbd25330
VZ
169 {
170 // no, it didn't exit yet, continue waiting
171 return;
172 }
173
447f908a
VZ
174 // set exit code to -1 if something bad happened
175 proc_data->exitcode = rc != -1 && WIFEXITED(status) ? WEXITSTATUS(status)
176 : -1;
177
dbd25330 178 // child exited, end waiting
ab857a4e 179 close(source);
dbd25330
VZ
180
181 // don't call us again!
ab857a4e
KB
182 gdk_input_remove(proc_data->tag);
183
ab857a4e 184 wxHandleProcessTermination(proc_data);
3069ac4e 185}
865bb325 186}
cf447356 187
518b5d2f 188int wxAddProcessCallback(wxEndProcessData *proc_data, int fd)
c801d85f 189{
518b5d2f
VZ
190 int tag = gdk_input_add(fd,
191 GDK_INPUT_READ,
192 GTK_EndProcessDetector,
193 (gpointer)proc_data);
c801d85f 194
518b5d2f 195 return tag;
3069ac4e 196}
c801d85f 197