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