]> git.saurik.com Git - wxWidgets.git/blame - src/gtk/utilsgtk.cpp
fixed missing wxprec.h
[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$
c801d85f 6// Copyright: (c) 1998 Robert Roebling, Julian Smart and Markus Holzem
518b5d2f 7// Licence: wxWindows licence
c801d85f
KB
8/////////////////////////////////////////////////////////////////////////////
9
c801d85f
KB
10#include "wx/utils.h"
11#include "wx/string.h"
12
02847e59
VZ
13#include "wx/intl.h"
14#include "wx/log.h"
15
5336ece4
VZ
16#include "wx/process.h"
17
518b5d2f
VZ
18#include "wx/unix/execute.h"
19
c801d85f 20#include <stdarg.h>
c801d85f
KB
21#include <string.h>
22#include <sys/stat.h>
23#include <sys/types.h>
dbd25330 24#include <sys/wait.h> // for WNOHANG
c801d85f 25#include <unistd.h>
91b8de8d
RR
26
27#include "glib.h"
28#include "gdk/gdk.h"
29#include "gtk/gtk.h"
df530a26 30#ifndef __WXGTK20__
91b8de8d 31#include "gtk/gtkfeatures.h"
df530a26 32#endif
91b8de8d 33#include "gdk/gdkx.h"
88ac883a 34
27933891 35#ifdef HAVE_X11_XKBLIB_H
154c4aa1
VZ
36 /* under HP-UX and Solaris 2.6, at least, XKBlib.h defines structures with
37 * field named "explicit" - which is, of course, an error for a C++
38 * compiler. To be on the safe side, just redefine it everywhere. */
88ac883a 39 #define explicit __wx_explicit
ec5d7799 40
154c4aa1 41 #include "X11/XKBlib.h"
ec5d7799 42
88ac883a 43 #undef explicit
27933891 44#endif // HAVE_X11_XKBLIB_H
dfcb1ae0 45
d76fe38b
RR
46//-----------------------------------------------------------------------------
47// data
48//-----------------------------------------------------------------------------
49
c2fa61e8 50extern GtkWidget *wxGetRootWindow();
d76fe38b
RR
51
52//----------------------------------------------------------------------------
c801d85f 53// misc.
d76fe38b 54//----------------------------------------------------------------------------
c801d85f 55
518b5d2f 56void wxBell()
c801d85f 57{
e52f60e6
RR
58 gdk_beep();
59}
c801d85f 60
27933891
RR
61/* Don't synthesize KeyUp events holding down a key and producing
62 KeyDown events with autorepeat. */
63#ifdef HAVE_X11_XKBLIB_H
f0492f7d
RR
64bool wxSetDetectableAutoRepeat( bool flag )
65{
66 Bool result;
67 XkbSetDetectableAutoRepeat( GDK_DISPLAY(), flag, &result );
27933891
RR
68 return result; /* TRUE if keyboard hardware supports this mode */
69}
70#else
71bool wxSetDetectableAutoRepeat( bool WXUNUSED(flag) )
72{
73 return FALSE;
f0492f7d 74}
27933891 75#endif
f0492f7d 76
518b5d2f
VZ
77// ----------------------------------------------------------------------------
78// display characterstics
79// ----------------------------------------------------------------------------
82052aff 80
d111a89a
VZ
81void *wxGetDisplay()
82{
27df579a 83 return GDK_DISPLAY();
d111a89a
VZ
84}
85
c0392997
RR
86void wxDisplaySize( int *width, int *height )
87{
e52f60e6
RR
88 if (width) *width = gdk_screen_width();
89 if (height) *height = gdk_screen_height();
c0392997
RR
90}
91
904a68b6
RL
92void wxDisplaySizeMM( int *width, int *height )
93{
94 if (width) *width = gdk_screen_width_mm();
95 if (height) *height = gdk_screen_height_mm();
96}
97
ec5d7799
RD
98void wxClientDisplayRect(int *x, int *y, int *width, int *height)
99{
100 // This is supposed to return desktop dimensions minus any window
101 // manager panels, menus, taskbars, etc. If there is a way to do that
102 // for this platform please fix this function, otherwise it defaults
103 // to the entire desktop.
104 if (x) *x = 0;
105 if (y) *y = 0;
106 wxDisplaySize(width, height);
107}
108
6de97a3b
RR
109void wxGetMousePosition( int* x, int* y )
110{
bbe0af5b 111 gdk_window_get_pointer( (GdkWindow*) NULL, x, y, (GdkModifierType*) NULL );
e52f60e6 112}
6de97a3b 113
518b5d2f 114bool wxColourDisplay()
6de97a3b 115{
e52f60e6 116 return TRUE;
6de97a3b
RR
117}
118
518b5d2f 119int wxDisplayDepth()
6de97a3b 120{
c2fa61e8 121 return gdk_window_get_visual( wxGetRootWindow()->window )->depth;
6de97a3b
RR
122}
123
bbe0af5b
RR
124int wxGetOsVersion(int *majorVsn, int *minorVsn)
125{
126 if (majorVsn) *majorVsn = GTK_MAJOR_VERSION;
127 if (minorVsn) *minorVsn = GTK_MINOR_VERSION;
7e84f02d 128
bbe0af5b
RR
129 return wxGTK;
130}
131
57591e0e
JS
132wxWindow* wxFindWindowAtPoint(const wxPoint& pt)
133{
134 return wxGenericFindWindowAtPoint(pt);
135}
136
137
518b5d2f 138// ----------------------------------------------------------------------------
c801d85f 139// subprocess routines
518b5d2f 140// ----------------------------------------------------------------------------
cf447356
GL
141
142static void GTK_EndProcessDetector(gpointer data, gint source,
e3e65dac 143 GdkInputCondition WXUNUSED(condition) )
cf447356 144{
ab857a4e 145 wxEndProcessData *proc_data = (wxEndProcessData *)data;
dbd25330
VZ
146
147 // has the process really terminated? unfortunately GDK (or GLib) seem to
148 // generate G_IO_HUP notification even when it simply tries to read from a
149 // closed fd and hasn't terminated at all
150 int pid = (proc_data->pid > 0) ? proc_data->pid : -(proc_data->pid);
447f908a
VZ
151 int status = 0;
152 int rc = waitpid(pid, &status, WNOHANG);
153
154 if ( rc == 0 )
dbd25330
VZ
155 {
156 // no, it didn't exit yet, continue waiting
157 return;
158 }
159
447f908a
VZ
160 // set exit code to -1 if something bad happened
161 proc_data->exitcode = rc != -1 && WIFEXITED(status) ? WEXITSTATUS(status)
162 : -1;
163
dbd25330 164 // child exited, end waiting
ab857a4e 165 close(source);
dbd25330
VZ
166
167 // don't call us again!
ab857a4e
KB
168 gdk_input_remove(proc_data->tag);
169
ab857a4e 170 wxHandleProcessTermination(proc_data);
3069ac4e 171}
cf447356 172
518b5d2f 173int wxAddProcessCallback(wxEndProcessData *proc_data, int fd)
c801d85f 174{
518b5d2f
VZ
175 int tag = gdk_input_add(fd,
176 GDK_INPUT_READ,
177 GTK_EndProcessDetector,
178 (gpointer)proc_data);
c801d85f 179
518b5d2f 180 return tag;
3069ac4e 181}
c801d85f 182