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;
29 //-----------------------------------------------------------------------------
31 //-----------------------------------------------------------------------------
36 #include "gdk/gdkprivate.h"
38 #include <netinet/in.h>
40 int my_nevent_masks
= 17;
41 int my_event_masks_table
[19] =
45 PointerMotionHintMask
,
50 ButtonPressMask
| OwnerGrabButtonMask
,
51 ButtonReleaseMask
| OwnerGrabButtonMask
,
65 gdk_window_transparent_new ( GdkWindow
*parent
,
66 GdkWindowAttr
*attributes
,
70 GdkWindowPrivate
*gprivate
;
71 GdkWindowPrivate
*parent_private
;
73 Display
*parent_display
;
76 XSetWindowAttributes xattributes
;
77 long xattributes_mask
;
78 XSizeHints size_hints
;
80 XClassHint
*class_hint
;
86 g_return_val_if_fail (attributes
!= NULL
, NULL
);
89 parent
= (GdkWindow
*) &gdk_root_parent
;
91 parent_private
= (GdkWindowPrivate
*) parent
;
92 if (parent_private
->destroyed
)
95 xparent
= parent_private
->xwindow
;
96 parent_display
= parent_private
->xdisplay
;
98 gprivate
= g_new (GdkWindowPrivate
, 1);
99 window
= (GdkWindow
*) gprivate
;
101 gprivate
->parent
= parent
;
103 if (parent_private
!= &gdk_root_parent
)
104 parent_private
->children
= g_list_prepend (parent_private
->children
, window
);
106 gprivate
->xdisplay
= parent_display
;
107 gprivate
->destroyed
= FALSE
;
108 gprivate
->resize_count
= 0;
109 gprivate
->ref_count
= 1;
110 xattributes_mask
= 0;
112 if (attributes_mask
& GDK_WA_X
)
117 if (attributes_mask
& GDK_WA_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
;
129 #if (GTK_MINOR_VERSION == 0)
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;
140 gprivate
->filters
= NULL
;
141 gprivate
->children
= NULL
;
143 window
->user_data
= NULL
;
145 if (attributes_mask
& GDK_WA_VISUAL
)
146 visual
= attributes
->visual
;
148 visual
= gdk_visual_get_system ();
149 xvisual
= ((GdkVisualPrivate
*) visual
)->xvisual
;
151 xattributes
.event_mask
= StructureNotifyMask
;
152 for (i
= 0; i
< my_nevent_masks
; i
++)
154 if (attributes
->event_mask
& (1 << (i
+ 1)))
155 xattributes
.event_mask
|= my_event_masks_table
[i
];
158 if (xattributes
.event_mask
)
159 xattributes_mask
|= CWEventMask
;
161 if(attributes_mask
& GDK_WA_NOREDIR
) {
162 xattributes
.override_redirect
=
163 (attributes
->override_redirect
== FALSE
)?False
:True
;
164 xattributes_mask
|= CWOverrideRedirect
;
166 xattributes
.override_redirect
= False
;
168 gclass
= InputOutput
;
169 depth
= visual
->depth
;
171 if (attributes_mask
& GDK_WA_COLORMAP
)
172 gprivate
->colormap
= attributes
->colormap
;
174 gprivate
->colormap
= gdk_colormap_get_system ();
176 xattributes
.colormap
= ((GdkColormapPrivate
*) gprivate
->colormap
)->xcolormap
;
177 xattributes_mask
|= CWColormap
;
179 xparent
= gdk_root_window
;
181 xattributes
.save_under
= True
;
182 xattributes
.override_redirect
= True
;
183 xattributes
.cursor
= None
;
184 xattributes_mask
|= CWSaveUnder
| CWOverrideRedirect
;
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
);
193 if (gprivate
->colormap
)
194 gdk_colormap_ref (gprivate
->colormap
);
196 XSetWMProtocols (gprivate
->xdisplay
, gprivate
->xwindow
, gdk_wm_window_protocols
, 2);
198 size_hints
.flags
= PSize
;
199 size_hints
.width
= gprivate
->width
;
200 size_hints
.height
= gprivate
->height
;
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
;
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
211 XSetWMNormalHints (gprivate
->xdisplay
, gprivate
->xwindow
, &size_hints
);
213 XSetWMHints (gprivate
->xdisplay
, gprivate
->xwindow
, &wm_hints
);
215 if (attributes_mask
& GDK_WA_TITLE
)
216 title
= attributes
->title
;
218 #if (GTK_MINOR_VERSION > 0)
219 title
= "Unknown"; // GLH: Well I don't know for the moment what to write here.
221 title
= gdk_progname
;
224 XmbSetWMProperties (gprivate
->xdisplay
, gprivate
->xwindow
,
229 if (attributes_mask
& GDK_WA_WMCLASS
)
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
);
243 //-----------------------------------------------------------------------------
245 //-----------------------------------------------------------------------------
247 IMPLEMENT_DYNAMIC_CLASS(wxScreenDC
,wxPaintDC
)
249 wxScreenDC::wxScreenDC(void)
252 m_window
= (GdkWindow
*) NULL
;
253 m_cmap
= gdk_colormap_get_system();
255 if (sm_overlayWindow
)
257 m_window
= sm_overlayWindow
;
258 m_deviceOriginX
= - sm_overlayWindowX
;
259 m_deviceOriginY
= - sm_overlayWindowY
;
263 m_window
= GDK_ROOT_PARENT();
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
);
274 wxScreenDC::~wxScreenDC(void)
279 bool wxScreenDC::StartDrawingOnTop( wxWindow
*window
)
281 if (!window
) return StartDrawingOnTop();
285 window
->GetPosition( &x
, &y
);
288 window
->GetSize( &w
, &h
);
289 window
->ClientToScreen( &x
, &y
);
297 return StartDrawingOnTop( &rect
);
300 bool wxScreenDC::StartDrawingOnTop( wxRect
*rect
)
304 int width
= gdk_screen_width();
305 int height
= gdk_screen_height();
311 height
= rect
->height
;
314 sm_overlayWindowX
= x
;
315 sm_overlayWindowY
= y
;
321 attr
.height
= height
;
322 attr
.override_redirect
= TRUE
;
323 attr
.wclass
= GDK_INPUT_OUTPUT
;
325 attr
.window_type
= GDK_WINDOW_TEMP
;
327 // GTK cannot set transparent backgrounds. :-(
328 sm_overlayWindow
= gdk_window_transparent_new( NULL
, &attr
, GDK_WA_NOREDIR
| GDK_WA_X
| GDK_WA_Y
);
330 if (sm_overlayWindow
) gdk_window_show( sm_overlayWindow
);
332 return (sm_overlayWindow
!= NULL
);
335 bool wxScreenDC::EndDrawingOnTop(void)
337 if (sm_overlayWindow
) gdk_window_destroy( sm_overlayWindow
);
339 sm_overlayWindow
= NULL
;
340 sm_overlayWindowX
= 0;
341 sm_overlayWindowY
= 0;