]> git.saurik.com Git - wxWidgets.git/blame_incremental - src/gtk1/utilsgtk.cpp
wxUsleep is supposed to sleep _milli_seconds, not _micro_seconds.
[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
7// Licence: wxWindows licence
8/////////////////////////////////////////////////////////////////////////////
9
10#include "wx/utils.h"
11#include "wx/string.h"
12
13#include "wx/apptrait.h"
14#include "wx/intl.h"
15#include "wx/log.h"
16
17#include "wx/process.h"
18
19#include "wx/unix/execute.h"
20
21#include <stdarg.h>
22#include <string.h>
23#include <sys/stat.h>
24#include <sys/types.h>
25#include <sys/wait.h> // for WNOHANG
26#include <unistd.h>
27
28#include "glib.h"
29#include "gdk/gdk.h"
30#include "gtk/gtk.h"
31#ifndef __WXGTK20__
32#include "gtk/gtkfeatures.h"
33#endif
34#include "gdk/gdkx.h"
35
36#ifdef HAVE_X11_XKBLIB_H
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. */
40 #define explicit __wx_explicit
41
42 #include "X11/XKBlib.h"
43
44 #undef explicit
45#endif // HAVE_X11_XKBLIB_H
46
47//-----------------------------------------------------------------------------
48// data
49//-----------------------------------------------------------------------------
50
51extern GtkWidget *wxGetRootWindow();
52
53//----------------------------------------------------------------------------
54// misc.
55//----------------------------------------------------------------------------
56
57void wxBell()
58{
59 gdk_beep();
60}
61
62/* Don't synthesize KeyUp events holding down a key and producing
63 KeyDown events with autorepeat. */
64#ifdef HAVE_X11_XKBLIB_H
65bool wxSetDetectableAutoRepeat( bool flag )
66{
67 Bool result;
68 XkbSetDetectableAutoRepeat( GDK_DISPLAY(), flag, &result );
69 return result; /* TRUE if keyboard hardware supports this mode */
70}
71#else
72bool wxSetDetectableAutoRepeat( bool WXUNUSED(flag) )
73{
74 return FALSE;
75}
76#endif
77
78// ----------------------------------------------------------------------------
79// display characterstics
80// ----------------------------------------------------------------------------
81
82void *wxGetDisplay()
83{
84 return GDK_DISPLAY();
85}
86
87void wxDisplaySize( int *width, int *height )
88{
89 if (width) *width = gdk_screen_width();
90 if (height) *height = gdk_screen_height();
91}
92
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
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
110void wxGetMousePosition( int* x, int* y )
111{
112 gdk_window_get_pointer( (GdkWindow*) NULL, x, y, (GdkModifierType*) NULL );
113}
114
115bool wxColourDisplay()
116{
117 return TRUE;
118}
119
120int wxDisplayDepth()
121{
122 return gdk_window_get_visual( wxGetRootWindow()->window )->depth;
123}
124
125wxToolkitInfo& wxGUIAppTraits::GetToolkitInfo()
126{
127 static wxToolkitInfo info;
128#ifdef __WXGTK20__
129 info.shortName = _T("gtk2");
130#else
131 info.shortName = _T("gtk");
132#endif
133 info.name = _T("wxGTK");
134#ifdef __WXUNIVERSAL__
135 info.shortName << _T("univ");
136 info.name << _T("/wxUniversal");
137#endif
138 info.versionMajor = GTK_MAJOR_VERSION;
139 info.versionMinor = GTK_MINOR_VERSION;
140 info.os = wxGTK;
141 return info;
142}
143
144wxWindow* wxFindWindowAtPoint(const wxPoint& pt)
145{
146 return wxGenericFindWindowAtPoint(pt);
147}
148
149
150// ----------------------------------------------------------------------------
151// subprocess routines
152// ----------------------------------------------------------------------------
153
154extern "C"
155void GTK_EndProcessDetector(gpointer data, gint source,
156 GdkInputCondition WXUNUSED(condition) )
157{
158 wxEndProcessData *proc_data = (wxEndProcessData *)data;
159
160 // has the process really terminated? unfortunately GDK (or GLib) seem to
161 // generate G_IO_HUP notification even when it simply tries to read from a
162 // closed fd and hasn't terminated at all
163 int pid = (proc_data->pid > 0) ? proc_data->pid : -(proc_data->pid);
164 int status = 0;
165 int rc = waitpid(pid, &status, WNOHANG);
166
167 if ( rc == 0 )
168 {
169 // no, it didn't exit yet, continue waiting
170 return;
171 }
172
173 // set exit code to -1 if something bad happened
174 proc_data->exitcode = rc != -1 && WIFEXITED(status) ? WEXITSTATUS(status)
175 : -1;
176
177 // child exited, end waiting
178 close(source);
179
180 // don't call us again!
181 gdk_input_remove(proc_data->tag);
182
183 wxHandleProcessTermination(proc_data);
184}
185
186int wxAddProcessCallback(wxEndProcessData *proc_data, int fd)
187{
188 int tag = gdk_input_add(fd,
189 GDK_INPUT_READ,
190 GTK_EndProcessDetector,
191 (gpointer)proc_data);
192
193 return tag;
194}
195