return version of GTK+ library the app links against, not the one it was compiled...
[wxWidgets.git] / src / gtk1 / 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 #ifndef __EMX__
60 // on OS/2, we use the wxBell from wxBase library
61
62 void wxBell()
63 {
64 gdk_beep();
65 }
66 #endif
67
68 /* Don't synthesize KeyUp events holding down a key and producing
69 KeyDown events with autorepeat. */
70 #ifdef HAVE_X11_XKBLIB_H
71 bool wxSetDetectableAutoRepeat( bool flag )
72 {
73 Bool result;
74 XkbSetDetectableAutoRepeat( GDK_DISPLAY(), flag, &result );
75 return result; /* TRUE if keyboard hardware supports this mode */
76 }
77 #else
78 bool wxSetDetectableAutoRepeat( bool WXUNUSED(flag) )
79 {
80 return FALSE;
81 }
82 #endif
83
84 // ----------------------------------------------------------------------------
85 // display characterstics
86 // ----------------------------------------------------------------------------
87
88 void *wxGetDisplay()
89 {
90 return GDK_DISPLAY();
91 }
92
93 void wxDisplaySize( int *width, int *height )
94 {
95 if (width) *width = gdk_screen_width();
96 if (height) *height = gdk_screen_height();
97 }
98
99 void wxDisplaySizeMM( int *width, int *height )
100 {
101 if (width) *width = gdk_screen_width_mm();
102 if (height) *height = gdk_screen_height_mm();
103 }
104
105 void wxClientDisplayRect(int *x, int *y, int *width, int *height)
106 {
107 // This is supposed to return desktop dimensions minus any window
108 // manager panels, menus, taskbars, etc. If there is a way to do that
109 // for this platform please fix this function, otherwise it defaults
110 // to the entire desktop.
111 if (x) *x = 0;
112 if (y) *y = 0;
113 wxDisplaySize(width, height);
114 }
115
116 void wxGetMousePosition( int* x, int* y )
117 {
118 gdk_window_get_pointer( (GdkWindow*) NULL, x, y, (GdkModifierType*) NULL );
119 }
120
121 bool wxColourDisplay()
122 {
123 return TRUE;
124 }
125
126 int wxDisplayDepth()
127 {
128 return gdk_window_get_visual( wxGetRootWindow()->window )->depth;
129 }
130
131 wxToolkitInfo& wxGUIAppTraits::GetToolkitInfo()
132 {
133 static wxToolkitInfo info;
134 #ifdef __WXGTK20__
135 info.shortName = _T("gtk2");
136 #else
137 info.shortName = _T("gtk");
138 #endif
139 info.name = _T("wxGTK");
140 #ifdef __WXUNIVERSAL__
141 info.shortName << _T("univ");
142 info.name << _T("/wxUniversal");
143 #endif
144 info.versionMajor = gtk_major_version;
145 info.versionMinor = gtk_minor_version;
146 info.os = wxGTK;
147 return info;
148 }
149
150 wxWindow* wxFindWindowAtPoint(const wxPoint& pt)
151 {
152 return wxGenericFindWindowAtPoint(pt);
153 }
154
155
156 // ----------------------------------------------------------------------------
157 // subprocess routines
158 // ----------------------------------------------------------------------------
159
160 extern "C"
161 void GTK_EndProcessDetector(gpointer data, gint source,
162 GdkInputCondition WXUNUSED(condition) )
163 {
164 wxEndProcessData *proc_data = (wxEndProcessData *)data;
165
166 // has the process really terminated? unfortunately GDK (or GLib) seem to
167 // generate G_IO_HUP notification even when it simply tries to read from a
168 // closed fd and hasn't terminated at all
169 int pid = (proc_data->pid > 0) ? proc_data->pid : -(proc_data->pid);
170 int status = 0;
171 int rc = waitpid(pid, &status, WNOHANG);
172
173 if ( rc == 0 )
174 {
175 // no, it didn't exit yet, continue waiting
176 return;
177 }
178
179 // set exit code to -1 if something bad happened
180 proc_data->exitcode = rc != -1 && WIFEXITED(status) ? WEXITSTATUS(status)
181 : -1;
182
183 // child exited, end waiting
184 close(source);
185
186 // don't call us again!
187 gdk_input_remove(proc_data->tag);
188
189 wxHandleProcessTermination(proc_data);
190 }
191
192 int wxAddProcessCallback(wxEndProcessData *proc_data, int fd)
193 {
194 int tag = gdk_input_add(fd,
195 GDK_INPUT_READ,
196 GTK_EndProcessDetector,
197 (gpointer)proc_data);
198
199 return tag;
200 }
201