]> git.saurik.com Git - wxWidgets.git/blame - src/gtk1/dcscreen.cpp
warning in GetItemFromPoint with mingw32 fixed
[wxWidgets.git] / src / gtk1 / 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
72cdf4c9 7// Licence: wxWindows licence
c801d85f
KB
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
071a2d78
RR
17#include <gdk/gdk.h>
18#include <gtk/gtk.h>
83624f79 19
dbf858b5
RR
20//-----------------------------------------------------------------------------
21// global data initialization
22//-----------------------------------------------------------------------------
23
24GdkWindow *wxScreenDC::sm_overlayWindow = (GdkWindow*) NULL;
72cdf4c9
VZ
25int wxScreenDC::sm_overlayWindowX = 0;
26int wxScreenDC::sm_overlayWindowY = 0;
dbf858b5 27
dbf858b5
RR
28//-----------------------------------------------------------------------------
29// create X window
30//-----------------------------------------------------------------------------
31
32extern "C" {
33
071a2d78
RR
34#include <gdk/gdkprivate.h>
35#include <gdk/gdkx.h>
dbf858b5
RR
36#include <netinet/in.h>
37
0208334d
RR
38int my_nevent_masks = 17;
39int my_event_masks_table[19] =
dbf858b5
RR
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,
72cdf4c9
VZ
58 0, /* PROXIMITY_IN */
59 0 /* PROXIMTY_OUT */
dbf858b5
RR
60};
61
62GdkWindow*
63gdk_window_transparent_new ( GdkWindow *parent,
72cdf4c9
VZ
64 GdkWindowAttr *attributes,
65 gint attributes_mask)
dbf858b5
RR
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;
72cdf4c9 126
d345e841 127#if (GTK_MINOR_VERSION == 0)
dbf858b5
RR
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;
38c7b3d3 136#endif
dbf858b5
RR
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;
0208334d 150 for (i = 0; i < my_nevent_masks; i++)
dbf858b5
RR
151 {
152 if (attributes->event_mask & (1 << (i + 1)))
72cdf4c9 153 xattributes.event_mask |= my_event_masks_table[i];
dbf858b5
RR
154 }
155
156 if (xattributes.event_mask)
157 xattributes_mask |= CWEventMask;
158
159 if(attributes_mask & GDK_WA_NOREDIR) {
72cdf4c9
VZ
160 xattributes.override_redirect =
161 (attributes->override_redirect == FALSE)?False:True;
162 xattributes_mask |= CWOverrideRedirect;
dbf858b5
RR
163 } else
164 xattributes.override_redirect = False;
165
166 gclass = InputOutput;
167 depth = visual->depth;
168
169 if (attributes_mask & GDK_WA_COLORMAP)
72cdf4c9 170 gprivate->colormap = attributes->colormap;
dbf858b5 171 else
72cdf4c9 172 gprivate->colormap = gdk_colormap_get_system ();
dbf858b5 173
72cdf4c9
VZ
174 xattributes.colormap = ((GdkColormapPrivate*) gprivate->colormap)->xcolormap;
175 xattributes_mask |= CWColormap;
dbf858b5 176
72cdf4c9 177 xparent = gdk_root_window;
dbf858b5 178
72cdf4c9
VZ
179 xattributes.save_under = True;
180 xattributes.override_redirect = True;
181 xattributes.cursor = None;
182 xattributes_mask |= CWSaveUnder | CWOverrideRedirect;
dbf858b5
RR
183
184 gprivate->xwindow = XCreateWindow (gprivate->xdisplay, xparent,
72cdf4c9
VZ
185 x, y, gprivate->width, gprivate->height,
186 0, depth, gclass, xvisual,
187 xattributes_mask, &xattributes);
dbf858b5
RR
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
d345e841 216#if (GTK_MINOR_VERSION > 0)
84b46c35
GL
217 title = "Unknown"; // GLH: Well I don't know for the moment what to write here.
218#else
dbf858b5 219 title = gdk_progname;
84b46c35 220#endif
dbf858b5
RR
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"
c801d85f
KB
240
241//-----------------------------------------------------------------------------
242// wxScreenDC
243//-----------------------------------------------------------------------------
244
245IMPLEMENT_DYNAMIC_CLASS(wxScreenDC,wxPaintDC)
246
72cdf4c9 247wxScreenDC::wxScreenDC()
c801d85f 248{
4bc67cc5
RR
249 m_ok = FALSE;
250 m_window = (GdkWindow *) NULL;
251 m_cmap = gdk_colormap_get_system();
72cdf4c9 252
4bc67cc5
RR
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 }
72cdf4c9 263
4bc67cc5 264 SetUpDC();
72cdf4c9 265
4bc67cc5
RR
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 );
ff7b1510 270}
c801d85f 271
72cdf4c9 272wxScreenDC::~wxScreenDC()
c801d85f 273{
4bc67cc5 274 EndDrawingOnTop();
ff7b1510 275}
c801d85f 276
dbf858b5 277bool wxScreenDC::StartDrawingOnTop( wxWindow *window )
c801d85f 278{
4bc67cc5 279 if (!window) return StartDrawingOnTop();
72cdf4c9 280
4bc67cc5
RR
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 );
72cdf4c9 288
4bc67cc5
RR
289 wxRect rect;
290 rect.x = x;
291 rect.y = y;
292 rect.width = 0;
293 rect.height = 0;
72cdf4c9 294
4bc67cc5 295 return StartDrawingOnTop( &rect );
ff7b1510 296}
c801d85f 297
16e93305 298bool wxScreenDC::StartDrawingOnTop( wxRect *rect )
c801d85f 299{
c801d85f
KB
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;
ff7b1510 310 }
72cdf4c9 311
dbf858b5
RR
312 sm_overlayWindowX = x;
313 sm_overlayWindowY = y;
c801d85f
KB
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;
72cdf4c9 324
dbf858b5
RR
325 // GTK cannot set transparent backgrounds. :-(
326 sm_overlayWindow = gdk_window_transparent_new( NULL, &attr, GDK_WA_NOREDIR | GDK_WA_X | GDK_WA_Y );
72cdf4c9 327
dbf858b5 328 if (sm_overlayWindow) gdk_window_show( sm_overlayWindow );
c801d85f 329
8fc613f1 330 return (sm_overlayWindow != NULL);
ff7b1510 331}
c801d85f 332
72cdf4c9 333bool wxScreenDC::EndDrawingOnTop()
c801d85f 334{
4bc67cc5 335 if (sm_overlayWindow) gdk_window_destroy( sm_overlayWindow );
72cdf4c9 336
4bc67cc5
RR
337 sm_overlayWindow = NULL;
338 sm_overlayWindowX = 0;
339 sm_overlayWindowY = 0;
72cdf4c9 340
4bc67cc5 341 return TRUE;
ff7b1510
RR
342}
343