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