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