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 //----------------------------------------------------------------------------- 
  34 #include <gdk/gdkprivate.h> 
  36 #include <netinet/in.h> 
  38 int my_nevent_masks 
= 17; 
  39 int my_event_masks_table
[19] = 
  43   PointerMotionHintMask
, 
  48   ButtonPressMask 
| OwnerGrabButtonMask
, 
  49   ButtonReleaseMask 
| OwnerGrabButtonMask
, 
  63 gdk_window_transparent_new ( GdkWindow     
*parent
, 
  64                              GdkWindowAttr 
*attributes
, 
  68   GdkWindowPrivate 
*gprivate
; 
  69   GdkWindowPrivate 
*parent_private
; 
  71   Display 
*parent_display
; 
  74   XSetWindowAttributes xattributes
; 
  75   long xattributes_mask
; 
  76   XSizeHints size_hints
; 
  78   XClassHint 
*class_hint
; 
  84   g_return_val_if_fail (attributes 
!= NULL
, NULL
); 
  87     parent 
= (GdkWindow
*) &gdk_root_parent
; 
  89   parent_private 
= (GdkWindowPrivate
*) parent
; 
  90   if (parent_private
->destroyed
) 
  93   xparent 
= parent_private
->xwindow
; 
  94   parent_display 
= parent_private
->xdisplay
; 
  96   gprivate 
= g_new (GdkWindowPrivate
, 1); 
  97   window 
= (GdkWindow
*) gprivate
; 
  99   gprivate
->parent 
= parent
; 
 101   if (parent_private 
!= &gdk_root_parent
) 
 102     parent_private
->children 
= g_list_prepend (parent_private
->children
, window
); 
 104   gprivate
->xdisplay 
= parent_display
; 
 105   gprivate
->destroyed 
= FALSE
; 
 106   gprivate
->resize_count 
= 0; 
 107   gprivate
->ref_count 
= 1; 
 108   xattributes_mask 
= 0; 
 110   if (attributes_mask 
& GDK_WA_X
) 
 115   if (attributes_mask 
& GDK_WA_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
; 
 127 #if (GTK_MINOR_VERSION == 0) 
 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; 
 138   gprivate
->filters 
= NULL
; 
 139   gprivate
->children 
= NULL
; 
 141   window
->user_data 
= NULL
; 
 143   if (attributes_mask 
& GDK_WA_VISUAL
) 
 144     visual 
= attributes
->visual
; 
 146     visual 
= gdk_visual_get_system (); 
 147   xvisual 
= ((GdkVisualPrivate
*) visual
)->xvisual
; 
 149   xattributes
.event_mask 
= StructureNotifyMask
; 
 150   for (i 
= 0; i 
< my_nevent_masks
; i
++) 
 152       if (attributes
->event_mask 
& (1 << (i 
+ 1))) 
 153         xattributes
.event_mask 
|= my_event_masks_table
[i
]; 
 156   if (xattributes
.event_mask
) 
 157     xattributes_mask 
|= CWEventMask
; 
 159   if(attributes_mask 
& GDK_WA_NOREDIR
) { 
 160         xattributes
.override_redirect 
= 
 161                 (attributes
->override_redirect 
== FALSE
)?False
:True
; 
 162         xattributes_mask 
|= CWOverrideRedirect
; 
 164     xattributes
.override_redirect 
= False
; 
 166       gclass 
= InputOutput
; 
 167       depth 
= visual
->depth
; 
 169       if (attributes_mask 
& GDK_WA_COLORMAP
) 
 170         gprivate
->colormap 
= attributes
->colormap
; 
 172         gprivate
->colormap 
= gdk_colormap_get_system (); 
 174           xattributes
.colormap 
= ((GdkColormapPrivate
*) gprivate
->colormap
)->xcolormap
; 
 175           xattributes_mask 
|= CWColormap
; 
 177           xparent 
= gdk_root_window
; 
 179           xattributes
.save_under 
= True
; 
 180           xattributes
.override_redirect 
= True
; 
 181           xattributes
.cursor 
= None
; 
 182           xattributes_mask 
|= CWSaveUnder 
| CWOverrideRedirect
; 
 184   gprivate
->xwindow 
= XCreateWindow (gprivate
->xdisplay
, xparent
, 
 185                                     x
, y
, gprivate
->width
, gprivate
->height
, 
 186                                     0, depth
, gclass
, xvisual
, 
 187                                     xattributes_mask
, &xattributes
); 
 188   gdk_window_ref (window
); 
 189   gdk_xid_table_insert (&gprivate
->xwindow
, window
); 
 191   if (gprivate
->colormap
) 
 192     gdk_colormap_ref (gprivate
->colormap
); 
 194       XSetWMProtocols (gprivate
->xdisplay
, gprivate
->xwindow
, gdk_wm_window_protocols
, 2); 
 196   size_hints
.flags 
= PSize
; 
 197   size_hints
.width 
= gprivate
->width
; 
 198   size_hints
.height 
= gprivate
->height
; 
 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
; 
 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 
 209   XSetWMNormalHints (gprivate
->xdisplay
, gprivate
->xwindow
, &size_hints
); 
 211   XSetWMHints (gprivate
->xdisplay
, gprivate
->xwindow
, &wm_hints
); 
 213   if (attributes_mask 
& GDK_WA_TITLE
) 
 214     title 
= attributes
->title
; 
 216 #if (GTK_MINOR_VERSION > 0) 
 217     title 
= "Unknown"; // GLH: Well I don't know for the moment what to write here. 
 219     title 
= gdk_progname
; 
 222   XmbSetWMProperties (gprivate
->xdisplay
, gprivate
->xwindow
, 
 227   if (attributes_mask 
& GDK_WA_WMCLASS
) 
 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
); 
 241 //----------------------------------------------------------------------------- 
 243 //----------------------------------------------------------------------------- 
 245 IMPLEMENT_DYNAMIC_CLASS(wxScreenDC
,wxPaintDC
) 
 247 wxScreenDC::wxScreenDC() 
 250     m_window 
= (GdkWindow 
*) NULL
; 
 251     m_cmap 
= gdk_colormap_get_system(); 
 253     if (sm_overlayWindow
) 
 255         m_window 
= sm_overlayWindow
; 
 256         m_deviceOriginX 
= - sm_overlayWindowX
; 
 257         m_deviceOriginY 
= - sm_overlayWindowY
; 
 261        m_window 
= GDK_ROOT_PARENT(); 
 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 
); 
 272 wxScreenDC::~wxScreenDC() 
 277 bool wxScreenDC::StartDrawingOnTop( wxWindow 
*window 
) 
 279     if (!window
) return StartDrawingOnTop(); 
 283     window
->GetPosition( &x
, &y 
); 
 286     window
->GetSize( &w
, &h 
); 
 287     window
->ClientToScreen( &x
, &y 
); 
 295     return StartDrawingOnTop( &rect 
); 
 298 bool wxScreenDC::StartDrawingOnTop( wxRect 
*rect 
) 
 302   int width 
= gdk_screen_width(); 
 303   int height 
= gdk_screen_height(); 
 309     height 
= rect
->height
; 
 312   sm_overlayWindowX 
= x
; 
 313   sm_overlayWindowY 
= y
; 
 319   attr
.height 
= height
; 
 320   attr
.override_redirect 
= TRUE
; 
 321   attr
.wclass 
= GDK_INPUT_OUTPUT
; 
 323   attr
.window_type 
= GDK_WINDOW_TEMP
; 
 325   // GTK cannot set transparent backgrounds. :-( 
 326   sm_overlayWindow 
= gdk_window_transparent_new( NULL
, &attr
, GDK_WA_NOREDIR 
| GDK_WA_X 
| GDK_WA_Y 
); 
 328   if (sm_overlayWindow
) gdk_window_show( sm_overlayWindow 
); 
 330   return (sm_overlayWindow 
!= NULL
); 
 333 bool wxScreenDC::EndDrawingOnTop() 
 335     if (sm_overlayWindow
) gdk_window_destroy( sm_overlayWindow 
); 
 337     sm_overlayWindow 
= NULL
; 
 338     sm_overlayWindowX 
= 0; 
 339     sm_overlayWindowY 
= 0;