]> git.saurik.com Git - wxWidgets.git/blob - src/gtk/dcscreen.cpp
Compile fixes for SGI
[wxWidgets.git] / src / gtk / dcscreen.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: dcscreen.cpp
3 // Purpose:
4 // Author: Robert Roebling
5 // Id: $Id$
6 // Copyright: (c) 1998 Robert Roebling
7 // Licence: wxWindows licence
8 /////////////////////////////////////////////////////////////////////////////
9
10 #ifdef __GNUG__
11 #pragma implementation "dcscreen.h"
12 #endif
13
14 #include "wx/dcscreen.h"
15 #include "wx/window.h"
16
17 #include "gdk/gdk.h"
18 #include "gtk/gtk.h"
19
20 //-----------------------------------------------------------------------------
21 // global data initialization
22 //-----------------------------------------------------------------------------
23
24 GdkWindow *wxScreenDC::sm_overlayWindow = (GdkWindow*) NULL;
25 int wxScreenDC::sm_overlayWindowX = 0;
26 int wxScreenDC::sm_overlayWindowY = 0;
27
28
29 //-----------------------------------------------------------------------------
30 // create X window
31 //-----------------------------------------------------------------------------
32
33 extern "C" {
34
35 #include "gdk/gdk.h"
36 #include "gdk/gdkprivate.h"
37 #include "gdk/gdkx.h"
38 #include <netinet/in.h>
39
40 int my_nevent_masks = 17;
41 int my_event_masks_table[19] =
42 {
43 ExposureMask,
44 PointerMotionMask,
45 PointerMotionHintMask,
46 ButtonMotionMask,
47 Button1MotionMask,
48 Button2MotionMask,
49 Button3MotionMask,
50 ButtonPressMask | OwnerGrabButtonMask,
51 ButtonReleaseMask | OwnerGrabButtonMask,
52 KeyPressMask,
53 KeyReleaseMask,
54 EnterWindowMask,
55 LeaveWindowMask,
56 FocusChangeMask,
57 StructureNotifyMask,
58 PropertyChangeMask,
59 VisibilityChangeMask,
60 0, /* PROXIMITY_IN */
61 0 /* PROXIMTY_OUT */
62 };
63
64 GdkWindow*
65 gdk_window_transparent_new ( GdkWindow *parent,
66 GdkWindowAttr *attributes,
67 gint attributes_mask)
68 {
69 GdkWindow *window;
70 GdkWindowPrivate *gprivate;
71 GdkWindowPrivate *parent_private;
72 GdkVisual *visual;
73 Display *parent_display;
74 Window xparent;
75 Visual *xvisual;
76 XSetWindowAttributes xattributes;
77 long xattributes_mask;
78 XSizeHints size_hints;
79 XWMHints wm_hints;
80 XClassHint *class_hint;
81 int x, y, depth;
82 unsigned int gclass;
83 char *title;
84 int i;
85
86 g_return_val_if_fail (attributes != NULL, NULL);
87
88 if (!parent)
89 parent = (GdkWindow*) &gdk_root_parent;
90
91 parent_private = (GdkWindowPrivate*) parent;
92 if (parent_private->destroyed)
93 return NULL;
94
95 xparent = parent_private->xwindow;
96 parent_display = parent_private->xdisplay;
97
98 gprivate = g_new (GdkWindowPrivate, 1);
99 window = (GdkWindow*) gprivate;
100
101 gprivate->parent = parent;
102
103 if (parent_private != &gdk_root_parent)
104 parent_private->children = g_list_prepend (parent_private->children, window);
105
106 gprivate->xdisplay = parent_display;
107 gprivate->destroyed = FALSE;
108 gprivate->resize_count = 0;
109 gprivate->ref_count = 1;
110 xattributes_mask = 0;
111
112 if (attributes_mask & GDK_WA_X)
113 x = attributes->x;
114 else
115 x = 0;
116
117 if (attributes_mask & GDK_WA_Y)
118 y = attributes->y;
119 else
120 y = 0;
121
122 gprivate->x = x;
123 gprivate->y = y;
124 gprivate->width = (attributes->width > 1) ? (attributes->width) : (1);
125 gprivate->height = (attributes->height > 1) ? (attributes->height) : (1);
126 gprivate->window_type = attributes->window_type;
127 gprivate->extension_events = FALSE;
128
129 #if (GTK_MINOR_VERSION == 0)
130 gprivate->dnd_drag_data_type = None;
131 gprivate->dnd_drag_data_typesavail =
132 gprivate->dnd_drop_data_typesavail = NULL;
133 gprivate->dnd_drop_enabled = gprivate->dnd_drag_enabled =
134 gprivate->dnd_drag_accepted = gprivate->dnd_drag_datashow =
135 gprivate->dnd_drop_data_numtypesavail =
136 gprivate->dnd_drag_data_numtypesavail = 0;
137 gprivate->dnd_drag_eventmask = gprivate->dnd_drag_savedeventmask = 0;
138 #endif
139
140 gprivate->filters = NULL;
141 gprivate->children = NULL;
142
143 window->user_data = NULL;
144
145 if (attributes_mask & GDK_WA_VISUAL)
146 visual = attributes->visual;
147 else
148 visual = gdk_visual_get_system ();
149 xvisual = ((GdkVisualPrivate*) visual)->xvisual;
150
151 xattributes.event_mask = StructureNotifyMask;
152 for (i = 0; i < my_nevent_masks; i++)
153 {
154 if (attributes->event_mask & (1 << (i + 1)))
155 xattributes.event_mask |= my_event_masks_table[i];
156 }
157
158 if (xattributes.event_mask)
159 xattributes_mask |= CWEventMask;
160
161 if(attributes_mask & GDK_WA_NOREDIR) {
162 xattributes.override_redirect =
163 (attributes->override_redirect == FALSE)?False:True;
164 xattributes_mask |= CWOverrideRedirect;
165 } else
166 xattributes.override_redirect = False;
167
168 gclass = InputOutput;
169 depth = visual->depth;
170
171 if (attributes_mask & GDK_WA_COLORMAP)
172 gprivate->colormap = attributes->colormap;
173 else
174 gprivate->colormap = gdk_colormap_get_system ();
175
176 xattributes.colormap = ((GdkColormapPrivate*) gprivate->colormap)->xcolormap;
177 xattributes_mask |= CWColormap;
178
179 xparent = gdk_root_window;
180
181 xattributes.save_under = True;
182 xattributes.override_redirect = True;
183 xattributes.cursor = None;
184 xattributes_mask |= CWSaveUnder | CWOverrideRedirect;
185
186 gprivate->xwindow = XCreateWindow (gprivate->xdisplay, xparent,
187 x, y, gprivate->width, gprivate->height,
188 0, depth, gclass, xvisual,
189 xattributes_mask, &xattributes);
190 gdk_window_ref (window);
191 gdk_xid_table_insert (&gprivate->xwindow, window);
192
193 if (gprivate->colormap)
194 gdk_colormap_ref (gprivate->colormap);
195
196 XSetWMProtocols (gprivate->xdisplay, gprivate->xwindow, gdk_wm_window_protocols, 2);
197
198 size_hints.flags = PSize;
199 size_hints.width = gprivate->width;
200 size_hints.height = gprivate->height;
201
202 wm_hints.flags = InputHint | StateHint | WindowGroupHint;
203 wm_hints.window_group = gdk_leader_window;
204 wm_hints.input = True;
205 wm_hints.initial_state = NormalState;
206
207 /* FIXME: Is there any point in doing this? Do any WM's pay
208 * attention to PSize, and even if they do, is this the
209 * correct value???
210 */
211 XSetWMNormalHints (gprivate->xdisplay, gprivate->xwindow, &size_hints);
212
213 XSetWMHints (gprivate->xdisplay, gprivate->xwindow, &wm_hints);
214
215 if (attributes_mask & GDK_WA_TITLE)
216 title = attributes->title;
217 else
218 #if (GTK_MINOR_VERSION > 0)
219 title = "Unknown"; // GLH: Well I don't know for the moment what to write here.
220 #else
221 title = gdk_progname;
222 #endif
223
224 XmbSetWMProperties (gprivate->xdisplay, gprivate->xwindow,
225 title, title,
226 NULL, 0,
227 NULL, NULL, NULL);
228
229 if (attributes_mask & GDK_WA_WMCLASS)
230 {
231 class_hint = XAllocClassHint ();
232 class_hint->res_name = attributes->wmclass_name;
233 class_hint->res_class = attributes->wmclass_class;
234 XSetClassHint (gprivate->xdisplay, gprivate->xwindow, class_hint);
235 XFree (class_hint);
236 }
237
238 return window;
239 }
240
241 } // extern "C"
242
243 //-----------------------------------------------------------------------------
244 // wxScreenDC
245 //-----------------------------------------------------------------------------
246
247 IMPLEMENT_DYNAMIC_CLASS(wxScreenDC,wxPaintDC)
248
249 wxScreenDC::wxScreenDC(void)
250 {
251 m_ok = FALSE;
252 m_window = (GdkWindow *) NULL;
253 m_cmap = gdk_colormap_get_system();
254
255 if (sm_overlayWindow)
256 {
257 m_window = sm_overlayWindow;
258 m_deviceOriginX = - sm_overlayWindowX;
259 m_deviceOriginY = - sm_overlayWindowY;
260 }
261 else
262 {
263 m_window = GDK_ROOT_PARENT();
264 }
265
266 SetUpDC();
267
268 gdk_gc_set_subwindow( m_penGC, GDK_INCLUDE_INFERIORS );
269 gdk_gc_set_subwindow( m_brushGC, GDK_INCLUDE_INFERIORS );
270 gdk_gc_set_subwindow( m_textGC, GDK_INCLUDE_INFERIORS );
271 gdk_gc_set_subwindow( m_bgGC, GDK_INCLUDE_INFERIORS );
272 }
273
274 wxScreenDC::~wxScreenDC(void)
275 {
276 EndDrawingOnTop();
277 }
278
279 bool wxScreenDC::StartDrawingOnTop( wxWindow *window )
280 {
281 if (!window) return StartDrawingOnTop();
282
283 int x = 0;
284 int y = 0;
285 window->GetPosition( &x, &y );
286 int w = 0;
287 int h = 0;
288 window->GetSize( &w, &h );
289 window->ClientToScreen( &x, &y );
290
291 wxRect rect;
292 rect.x = x;
293 rect.y = y;
294 rect.width = 0;
295 rect.height = 0;
296
297 return StartDrawingOnTop( &rect );
298 }
299
300 bool wxScreenDC::StartDrawingOnTop( wxRect *rect )
301 {
302 int x = 0;
303 int y = 0;
304 int width = gdk_screen_width();
305 int height = gdk_screen_height();
306 if (rect)
307 {
308 x = rect->x;
309 y = rect->y;
310 width = rect->width;
311 height = rect->height;
312 }
313
314 sm_overlayWindowX = x;
315 sm_overlayWindowY = y;
316
317 GdkWindowAttr attr;
318 attr.x = x;
319 attr.y = y;
320 attr.width = width;
321 attr.height = height;
322 attr.override_redirect = TRUE;
323 attr.wclass = GDK_INPUT_OUTPUT;
324 attr.event_mask = 0;
325 attr.window_type = GDK_WINDOW_TEMP;
326
327 // GTK cannot set transparent backgrounds. :-(
328 sm_overlayWindow = gdk_window_transparent_new( NULL, &attr, GDK_WA_NOREDIR | GDK_WA_X | GDK_WA_Y );
329
330 if (sm_overlayWindow) gdk_window_show( sm_overlayWindow );
331
332 return (sm_overlayWindow != NULL);
333 }
334
335 bool wxScreenDC::EndDrawingOnTop(void)
336 {
337 if (sm_overlayWindow) gdk_window_destroy( sm_overlayWindow );
338
339 sm_overlayWindow = NULL;
340 sm_overlayWindowX = 0;
341 sm_overlayWindowY = 0;
342
343 return TRUE;
344 }
345