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