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