1 /////////////////////////////////////////////////////////////////////////////
4 // Author: Robert Roebling
6 // Copyright: (c) 1998 Robert Roebling
7 // Licence: wxWindows licence
8 /////////////////////////////////////////////////////////////////////////////
11 #pragma implementation "dcscreen.h"
14 #include "wx/dcscreen.h"
15 #include "wx/window.h"
20 //-----------------------------------------------------------------------------
21 // global data initialization
22 //-----------------------------------------------------------------------------
24 GdkWindow
*wxScreenDC::sm_overlayWindow
= (GdkWindow
*) NULL
;
25 int wxScreenDC::sm_overlayWindowX
= 0;
26 int wxScreenDC::sm_overlayWindowY
= 0;
28 //-----------------------------------------------------------------------------
30 //-----------------------------------------------------------------------------
35 #include "gdk/gdkprivate.h"
37 #include <netinet/in.h>
39 int my_nevent_masks
= 17;
40 int my_event_masks_table
[19] =
44 PointerMotionHintMask
,
49 ButtonPressMask
| OwnerGrabButtonMask
,
50 ButtonReleaseMask
| OwnerGrabButtonMask
,
64 gdk_window_transparent_new ( GdkWindow
*parent
,
65 GdkWindowAttr
*attributes
,
69 GdkWindowPrivate
*gprivate
;
70 GdkWindowPrivate
*parent_private
;
72 Display
*parent_display
;
75 XSetWindowAttributes xattributes
;
76 long xattributes_mask
;
77 XSizeHints size_hints
;
79 XClassHint
*class_hint
;
85 g_return_val_if_fail (attributes
!= NULL
, NULL
);
88 parent
= (GdkWindow
*) &gdk_root_parent
;
90 parent_private
= (GdkWindowPrivate
*) parent
;
91 if (parent_private
->destroyed
)
94 xparent
= parent_private
->xwindow
;
95 parent_display
= parent_private
->xdisplay
;
97 gprivate
= g_new (GdkWindowPrivate
, 1);
98 window
= (GdkWindow
*) gprivate
;
100 gprivate
->parent
= parent
;
102 if (parent_private
!= &gdk_root_parent
)
103 parent_private
->children
= g_list_prepend (parent_private
->children
, window
);
105 gprivate
->xdisplay
= parent_display
;
106 gprivate
->destroyed
= FALSE
;
107 gprivate
->resize_count
= 0;
108 gprivate
->ref_count
= 1;
109 xattributes_mask
= 0;
111 if (attributes_mask
& GDK_WA_X
)
116 if (attributes_mask
& GDK_WA_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
;
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;
139 gprivate
->filters
= NULL
;
140 gprivate
->children
= NULL
;
142 window
->user_data
= NULL
;
144 if (attributes_mask
& GDK_WA_VISUAL
)
145 visual
= attributes
->visual
;
147 visual
= gdk_visual_get_system ();
148 xvisual
= ((GdkVisualPrivate
*) visual
)->xvisual
;
150 xattributes
.event_mask
= StructureNotifyMask
;
151 for (i
= 0; i
< my_nevent_masks
; i
++)
153 if (attributes
->event_mask
& (1 << (i
+ 1)))
154 xattributes
.event_mask
|= my_event_masks_table
[i
];
157 if (xattributes
.event_mask
)
158 xattributes_mask
|= CWEventMask
;
160 if(attributes_mask
& GDK_WA_NOREDIR
) {
161 xattributes
.override_redirect
=
162 (attributes
->override_redirect
== FALSE
)?False
:True
;
163 xattributes_mask
|= CWOverrideRedirect
;
165 xattributes
.override_redirect
= False
;
167 gclass
= InputOutput
;
168 depth
= visual
->depth
;
170 if (attributes_mask
& GDK_WA_COLORMAP
)
171 gprivate
->colormap
= attributes
->colormap
;
173 gprivate
->colormap
= gdk_colormap_get_system ();
175 xattributes
.colormap
= ((GdkColormapPrivate
*) gprivate
->colormap
)->xcolormap
;
176 xattributes_mask
|= CWColormap
;
178 xparent
= gdk_root_window
;
180 xattributes
.save_under
= True
;
181 xattributes
.override_redirect
= True
;
182 xattributes
.cursor
= None
;
183 xattributes_mask
|= CWSaveUnder
| CWOverrideRedirect
;
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
);
192 if (gprivate
->colormap
)
193 gdk_colormap_ref (gprivate
->colormap
);
195 XSetWMProtocols (gprivate
->xdisplay
, gprivate
->xwindow
, gdk_wm_window_protocols
, 2);
197 size_hints
.flags
= PSize
;
198 size_hints
.width
= gprivate
->width
;
199 size_hints
.height
= gprivate
->height
;
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
;
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
210 XSetWMNormalHints (gprivate
->xdisplay
, gprivate
->xwindow
, &size_hints
);
212 XSetWMHints (gprivate
->xdisplay
, gprivate
->xwindow
, &wm_hints
);
214 if (attributes_mask
& GDK_WA_TITLE
)
215 title
= attributes
->title
;
217 #if (GTK_MINOR_VERSION > 0)
218 title
= "Unknown"; // GLH: Well I don't know for the moment what to write here.
220 title
= gdk_progname
;
223 XmbSetWMProperties (gprivate
->xdisplay
, gprivate
->xwindow
,
228 if (attributes_mask
& GDK_WA_WMCLASS
)
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
);
242 //-----------------------------------------------------------------------------
244 //-----------------------------------------------------------------------------
246 IMPLEMENT_DYNAMIC_CLASS(wxScreenDC
,wxPaintDC
)
248 wxScreenDC::wxScreenDC()
251 m_window
= (GdkWindow
*) NULL
;
252 m_cmap
= gdk_colormap_get_system();
254 if (sm_overlayWindow
)
256 m_window
= sm_overlayWindow
;
257 m_deviceOriginX
= - sm_overlayWindowX
;
258 m_deviceOriginY
= - sm_overlayWindowY
;
262 m_window
= GDK_ROOT_PARENT();
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
);
273 wxScreenDC::~wxScreenDC()
278 bool wxScreenDC::StartDrawingOnTop( wxWindow
*window
)
280 if (!window
) return StartDrawingOnTop();
284 window
->GetPosition( &x
, &y
);
287 window
->GetSize( &w
, &h
);
288 window
->ClientToScreen( &x
, &y
);
296 return StartDrawingOnTop( &rect
);
299 bool wxScreenDC::StartDrawingOnTop( wxRect
*rect
)
303 int width
= gdk_screen_width();
304 int height
= gdk_screen_height();
310 height
= rect
->height
;
313 sm_overlayWindowX
= x
;
314 sm_overlayWindowY
= y
;
320 attr
.height
= height
;
321 attr
.override_redirect
= TRUE
;
322 attr
.wclass
= GDK_INPUT_OUTPUT
;
324 attr
.window_type
= GDK_WINDOW_TEMP
;
326 // GTK cannot set transparent backgrounds. :-(
327 sm_overlayWindow
= gdk_window_transparent_new( NULL
, &attr
, GDK_WA_NOREDIR
| GDK_WA_X
| GDK_WA_Y
);
329 if (sm_overlayWindow
) gdk_window_show( sm_overlayWindow
);
331 return (sm_overlayWindow
!= NULL
);
334 bool wxScreenDC::EndDrawingOnTop()
336 if (sm_overlayWindow
) gdk_window_destroy( sm_overlayWindow
);
338 sm_overlayWindow
= NULL
;
339 sm_overlayWindowX
= 0;
340 sm_overlayWindowY
= 0;