]> git.saurik.com Git - wxWidgets.git/blame_incremental - src/gtk1/utilsgtk.cpp
create lib\...\setup.h from setup.h, not setup0.h which is not meant to be edited
[wxWidgets.git] / src / gtk1 / utilsgtk.cpp
... / ...
CommitLineData
1/////////////////////////////////////////////////////////////////////////////
2// Name: src/gtk/utilsgtk.cpp
3// Purpose:
4// Author: Robert Roebling
5// Id: $Id$
6// Copyright: (c) 1998 Robert Roebling, Julian Smart and Markus Holzem
7// Licence: wxWindows licence
8/////////////////////////////////////////////////////////////////////////////
9
10#include "wx/utils.h"
11#include "wx/string.h"
12
13#include "wx/intl.h"
14#include "wx/log.h"
15
16#include "wx/process.h"
17
18#include "wx/unix/execute.h"
19
20#include <stdarg.h>
21#include <string.h>
22#include <sys/stat.h>
23#include <sys/types.h>
24#include <sys/wait.h> // for WNOHANG
25#include <unistd.h>
26
27#include "glib.h"
28#include "gdk/gdk.h"
29#include "gtk/gtk.h"
30#ifndef __WXGTK20__
31#include "gtk/gtkfeatures.h"
32#endif
33#include "gdk/gdkx.h"
34
35#ifdef HAVE_X11_XKBLIB_H
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. */
39 #define explicit __wx_explicit
40
41 #include "X11/XKBlib.h"
42
43 #undef explicit
44#endif // HAVE_X11_XKBLIB_H
45
46//-----------------------------------------------------------------------------
47// data
48//-----------------------------------------------------------------------------
49
50extern GtkWidget *wxGetRootWindow();
51
52//----------------------------------------------------------------------------
53// misc.
54//----------------------------------------------------------------------------
55
56void wxBell()
57{
58 gdk_beep();
59}
60
61/* Don't synthesize KeyUp events holding down a key and producing
62 KeyDown events with autorepeat. */
63#ifdef HAVE_X11_XKBLIB_H
64bool wxSetDetectableAutoRepeat( bool flag )
65{
66 Bool result;
67 XkbSetDetectableAutoRepeat( GDK_DISPLAY(), flag, &result );
68 return result; /* TRUE if keyboard hardware supports this mode */
69}
70#else
71bool wxSetDetectableAutoRepeat( bool WXUNUSED(flag) )
72{
73 return FALSE;
74}
75#endif
76
77// ----------------------------------------------------------------------------
78// display characterstics
79// ----------------------------------------------------------------------------
80
81void *wxGetDisplay()
82{
83 return GDK_DISPLAY();
84}
85
86void wxDisplaySize( int *width, int *height )
87{
88 if (width) *width = gdk_screen_width();
89 if (height) *height = gdk_screen_height();
90}
91
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
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
109void wxGetMousePosition( int* x, int* y )
110{
111 gdk_window_get_pointer( (GdkWindow*) NULL, x, y, (GdkModifierType*) NULL );
112}
113
114bool wxColourDisplay()
115{
116 return TRUE;
117}
118
119int wxDisplayDepth()
120{
121 return gdk_window_get_visual( wxGetRootWindow()->window )->depth;
122}
123
124int wxGetOsVersion(int *majorVsn, int *minorVsn)
125{
126 if (majorVsn) *majorVsn = GTK_MAJOR_VERSION;
127 if (minorVsn) *minorVsn = GTK_MINOR_VERSION;
128
129 return wxGTK;
130}
131
132wxWindow* wxFindWindowAtPoint(const wxPoint& pt)
133{
134 return wxGenericFindWindowAtPoint(pt);
135}
136
137
138// ----------------------------------------------------------------------------
139// subprocess routines
140// ----------------------------------------------------------------------------
141
142static void GTK_EndProcessDetector(gpointer data, gint source,
143 GdkInputCondition WXUNUSED(condition) )
144{
145 wxEndProcessData *proc_data = (wxEndProcessData *)data;
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);
151 int status = 0;
152 int rc = waitpid(pid, &status, WNOHANG);
153
154 if ( rc == 0 )
155 {
156 // no, it didn't exit yet, continue waiting
157 return;
158 }
159
160 // set exit code to -1 if something bad happened
161 proc_data->exitcode = rc != -1 && WIFEXITED(status) ? WEXITSTATUS(status)
162 : -1;
163
164 // child exited, end waiting
165 close(source);
166
167 // don't call us again!
168 gdk_input_remove(proc_data->tag);
169
170 wxHandleProcessTermination(proc_data);
171}
172
173int wxAddProcessCallback(wxEndProcessData *proc_data, int fd)
174{
175 int tag = gdk_input_add(fd,
176 GDK_INPUT_READ,
177 GTK_EndProcessDetector,
178 (gpointer)proc_data);
179
180 return tag;
181}
182