]> git.saurik.com Git - wxWidgets.git/blob - src/motif/dcscreen.cpp
1. wxPostEvent added and documented
[wxWidgets.git] / src / motif / dcscreen.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: dcscreen.cpp
3 // Purpose: wxScreenDC class
4 // Author: Julian Smart
5 // Modified by:
6 // Created: 17/09/98
7 // RCS-ID: $Id$
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 #ifdef __GNUG__
13 #pragma implementation "dcscreen.h"
14 #endif
15
16 #include "wx/window.h"
17 #include "wx/dcscreen.h"
18 #include "wx/utils.h"
19
20 #include <Xm/Xm.h>
21
22 #include <wx/motif/private.h>
23
24 #if !USE_SHARED_LIBRARY
25 IMPLEMENT_DYNAMIC_CLASS(wxScreenDC, wxWindowDC)
26 #endif
27
28 WXWindow wxScreenDC::sm_overlayWindow = 0;
29 int wxScreenDC::sm_overlayWindowX = 0;
30 int wxScreenDC::sm_overlayWindowY = 0;
31
32 // Create a DC representing the whole screen
33 wxScreenDC::wxScreenDC()
34 {
35 m_display = wxGetDisplay();
36 Display* display = (Display*) m_display;
37
38 if (sm_overlayWindow)
39 {
40 m_pixmap = sm_overlayWindow;
41 m_deviceOriginX = - sm_overlayWindowX;
42 m_deviceOriginY = - sm_overlayWindowY;
43 }
44 else
45 m_pixmap = (WXPixmap) RootWindow(display, DefaultScreen(display));
46
47 XGCValues gcvalues;
48 gcvalues.foreground = BlackPixel (display, DefaultScreen (display));
49 gcvalues.background = WhitePixel (display, DefaultScreen (display));
50 gcvalues.graphics_exposures = False;
51 gcvalues.subwindow_mode = IncludeInferiors;
52 gcvalues.line_width = 1;
53 m_gc = XCreateGC (display, RootWindow (display, DefaultScreen (display)),
54 GCForeground | GCBackground | GCGraphicsExposures | GCLineWidth | GCSubwindowMode,
55 &gcvalues);
56
57 m_backgroundPixel = (int) gcvalues.background;
58 m_ok = TRUE;
59 }
60
61 wxScreenDC::~wxScreenDC()
62 {
63 }
64
65 bool wxScreenDC::StartDrawingOnTop(wxWindow* window)
66 {
67 wxRect rect;
68 int x, y, width, height;
69 window->GetPosition(& x, & y);
70 if (window->GetParent())
71 window->GetParent()->ClientToScreen(& x, & y);
72 window->GetSize(& width, & height);
73 rect.x = x; rect.y = y;
74 rect.width = width; rect.height = height;
75
76 return StartDrawingOnTop(& rect);
77 }
78
79 bool wxScreenDC::StartDrawingOnTop(wxRect* rect)
80 {
81 if (sm_overlayWindow)
82 return FALSE;
83
84 Display *dpy = (Display*) wxGetDisplay();
85 Pixmap screenPixmap = RootWindow(dpy, DefaultScreen(dpy));
86
87 int x = 0;
88 int y = 0;
89 int width, height;
90 wxDisplaySize(&width, &height);
91
92 if (rect)
93 {
94 x = rect->x; y = rect->y;
95 width = rect->width; height = rect->height;
96 }
97 sm_overlayWindowX = x;
98 sm_overlayWindowY = y;
99
100 XSetWindowAttributes attributes;
101 attributes.override_redirect = True;
102 unsigned long valueMask = CWOverrideRedirect;
103
104 sm_overlayWindow = (WXWindow) XCreateWindow(dpy, screenPixmap, x, y, width, height, 0,
105 wxDisplayDepth(), InputOutput,
106 DefaultVisual(dpy, 0), valueMask,
107 & attributes);
108
109 if (sm_overlayWindow)
110 {
111 XMapWindow(dpy, (Window) sm_overlayWindow);
112 return TRUE;
113 }
114 else
115 return FALSE;
116 }
117
118 bool wxScreenDC::EndDrawingOnTop()
119 {
120 if (sm_overlayWindow)
121 {
122 XDestroyWindow((Display*) wxGetDisplay(), (Window) sm_overlayWindow);
123 sm_overlayWindow = 0;
124 return TRUE;
125 }
126 else
127 return FALSE;
128 }