1. moved fontenum.cpp to unix because implementation is common to X and GTK+
[wxWidgets.git] / src / gtk / utilsgtk.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: utils.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 <unistd.h>
25
26 #include "glib.h"
27 #include "gdk/gdk.h"
28 #include "gtk/gtk.h"
29 #include "gtk/gtkfeatures.h"
30 #include "gdk/gdkx.h"
31
32 #ifdef HAVE_X11_XKBLIB_H
33 /* under HP-UX and Solaris 2.6, at least, XKBlib.h defines structures with
34 * field named "explicit" - which is, of course, an error for a C++
35 * compiler. To be on the safe side, just redefine it everywhere. */
36 #define explicit __wx_explicit
37
38 #include "X11/XKBlib.h"
39
40 #undef explicit
41 #endif // HAVE_X11_XKBLIB_H
42
43 // ----------------------------------------------------------------------------
44 // misc.
45 // ----------------------------------------------------------------------------
46
47 void wxBell()
48 {
49 gdk_beep();
50 }
51
52 /* Don't synthesize KeyUp events holding down a key and producing
53 KeyDown events with autorepeat. */
54 #ifdef HAVE_X11_XKBLIB_H
55 bool wxSetDetectableAutoRepeat( bool flag )
56 {
57 Bool result;
58 XkbSetDetectableAutoRepeat( GDK_DISPLAY(), flag, &result );
59 return result; /* TRUE if keyboard hardware supports this mode */
60 }
61 #else
62 bool wxSetDetectableAutoRepeat( bool WXUNUSED(flag) )
63 {
64 return FALSE;
65 }
66 #endif
67
68 // ----------------------------------------------------------------------------
69 // display characterstics
70 // ----------------------------------------------------------------------------
71
72 void *wxGetDisplay()
73 {
74 return gdk_display;
75 }
76
77 void wxDisplaySize( int *width, int *height )
78 {
79 if (width) *width = gdk_screen_width();
80 if (height) *height = gdk_screen_height();
81 }
82
83 void wxGetMousePosition( int* x, int* y )
84 {
85 gdk_window_get_pointer( (GdkWindow*) NULL, x, y, (GdkModifierType*) NULL );
86 }
87
88 bool wxColourDisplay()
89 {
90 return TRUE;
91 }
92
93 int wxDisplayDepth()
94 {
95 return gdk_window_get_visual( (GdkWindow*) &gdk_root_parent )->depth;
96 }
97
98 int wxGetOsVersion(int *majorVsn, int *minorVsn)
99 {
100 if (majorVsn) *majorVsn = GTK_MAJOR_VERSION;
101 if (minorVsn) *minorVsn = GTK_MINOR_VERSION;
102
103 return wxGTK;
104 }
105
106 // ----------------------------------------------------------------------------
107 // subprocess routines
108 // ----------------------------------------------------------------------------
109
110 static void GTK_EndProcessDetector(gpointer data, gint source,
111 GdkInputCondition WXUNUSED(condition) )
112 {
113 wxEndProcessData *proc_data = (wxEndProcessData *)data;
114
115 wxHandleProcessTermination(proc_data);
116
117 close(source);
118 gdk_input_remove(proc_data->tag);
119 }
120
121 int wxAddProcessCallback(wxEndProcessData *proc_data, int fd)
122 {
123 int tag = gdk_input_add(fd,
124 GDK_INPUT_READ,
125 GTK_EndProcessDetector,
126 (gpointer)proc_data);
127
128 return tag;
129 }
130