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