]> git.saurik.com Git - wxWidgets.git/blame - src/gtk/dcscreen.cpp
fixed bug in GetMimeType under win
[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 16
83624f79
RR
17#include "gdk/gdk.h"
18#include "gtk/gtk.h"
19
dbf858b5
RR
20//-----------------------------------------------------------------------------
21// global data initialization
22//-----------------------------------------------------------------------------
23
24GdkWindow *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
33extern "C" {
34
35#include "gdk/gdk.h"
36#include "gdk/gdkprivate.h"
c801d85f 37#include "gdk/gdkx.h"
dbf858b5
RR
38#include <netinet/in.h>
39
0208334d
RR
40int my_nevent_masks = 17;
41int my_event_masks_table[19] =
dbf858b5
RR
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
64GdkWindow*
65gdk_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;
38c7b3d3
RR
128
129#ifndef NEW_GTK_DND_CODE
dbf858b5
RR
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;
38c7b3d3 138#endif
dbf858b5
RR
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;
0208334d 152 for (i = 0; i < my_nevent_masks; i++)
dbf858b5
RR
153 {
154 if (attributes->event_mask & (1 << (i + 1)))
0208334d 155 xattributes.event_mask |= my_event_masks_table[i];
dbf858b5
RR
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
84b46c35
GL
218#if (GTK_MINOR_VERSION == 1)
219 title = "Unknown"; // GLH: Well I don't know for the moment what to write here.
220#else
dbf858b5 221 title = gdk_progname;
84b46c35 222#endif
dbf858b5
RR
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"
c801d85f
KB
242
243//-----------------------------------------------------------------------------
244// wxScreenDC
245//-----------------------------------------------------------------------------
246
247IMPLEMENT_DYNAMIC_CLASS(wxScreenDC,wxPaintDC)
248
249wxScreenDC::wxScreenDC(void)
250{
4bc67cc5
RR
251 m_ok = FALSE;
252 m_window = (GdkWindow *) NULL;
253 m_cmap = gdk_colormap_get_system();
c801d85f 254
4bc67cc5
RR
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 }
c801d85f 265
4bc67cc5 266 SetUpDC();
c801d85f 267
4bc67cc5
RR
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 );
ff7b1510 272}
c801d85f
KB
273
274wxScreenDC::~wxScreenDC(void)
275{
4bc67cc5 276 EndDrawingOnTop();
ff7b1510 277}
c801d85f 278
dbf858b5 279bool wxScreenDC::StartDrawingOnTop( wxWindow *window )
c801d85f 280{
4bc67cc5 281 if (!window) return StartDrawingOnTop();
dbf858b5 282
4bc67cc5
RR
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 );
dbf858b5 290
4bc67cc5
RR
291 wxRect rect;
292 rect.x = x;
293 rect.y = y;
294 rect.width = 0;
295 rect.height = 0;
dbf858b5 296
4bc67cc5 297 return StartDrawingOnTop( &rect );
ff7b1510 298}
c801d85f 299
16e93305 300bool wxScreenDC::StartDrawingOnTop( wxRect *rect )
c801d85f 301{
c801d85f
KB
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;
ff7b1510 312 }
c801d85f 313
dbf858b5
RR
314 sm_overlayWindowX = x;
315 sm_overlayWindowY = y;
c801d85f
KB
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;
c801d85f 326
dbf858b5
RR
327 // GTK cannot set transparent backgrounds. :-(
328 sm_overlayWindow = gdk_window_transparent_new( NULL, &attr, GDK_WA_NOREDIR | GDK_WA_X | GDK_WA_Y );
c801d85f 329
dbf858b5 330 if (sm_overlayWindow) gdk_window_show( sm_overlayWindow );
c801d85f 331
8fc613f1 332 return (sm_overlayWindow != NULL);
ff7b1510 333}
c801d85f
KB
334
335bool wxScreenDC::EndDrawingOnTop(void)
336{
4bc67cc5 337 if (sm_overlayWindow) gdk_window_destroy( sm_overlayWindow );
dbf858b5 338
4bc67cc5
RR
339 sm_overlayWindow = NULL;
340 sm_overlayWindowX = 0;
341 sm_overlayWindowY = 0;
dbf858b5 342
4bc67cc5 343 return TRUE;
ff7b1510
RR
344}
345