]> git.saurik.com Git - wxWidgets.git/blob - src/motif/dcscreen.cpp
use WX_ASSERT_STR/SIZET_EQUAL instead of CPPUNIT_ASSERT_EQUAL with casts
[wxWidgets.git] / src / motif / dcscreen.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/motif/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 // For compilers that support precompilation, includes "wx.h".
13 #include "wx/wxprec.h"
14
15 #include "wx/dcscreen.h"
16
17 #ifndef WX_PRECOMP
18 #include "wx/utils.h"
19 #include "wx/window.h"
20 #include "wx/frame.h"
21 #endif
22
23 #ifdef __VMS__
24 #pragma message disable nosimpint
25 #endif
26 #include <Xm/Xm.h>
27 #ifdef __VMS__
28 #pragma message enable nosimpint
29 #endif
30
31 #include "wx/motif/private.h"
32
33 IMPLEMENT_DYNAMIC_CLASS(wxScreenDC, wxWindowDC)
34
35 WXWindow wxScreenDC::sm_overlayWindow = 0;
36 int wxScreenDC::sm_overlayWindowX = 0;
37 int wxScreenDC::sm_overlayWindowY = 0;
38
39 // Create a DC representing the whole screen
40 wxScreenDC::wxScreenDC()
41 {
42 m_display = wxGetDisplay();
43 Display* display = (Display*) m_display;
44
45 if (sm_overlayWindow)
46 {
47 m_pixmap = sm_overlayWindow;
48 m_deviceOriginX = - sm_overlayWindowX;
49 m_deviceOriginY = - sm_overlayWindowY;
50 }
51 else
52 m_pixmap = (WXPixmap) RootWindow(display, DefaultScreen(display));
53
54 XGCValues gcvalues;
55 gcvalues.foreground = BlackPixel (display, DefaultScreen (display));
56 gcvalues.background = WhitePixel (display, DefaultScreen (display));
57 gcvalues.graphics_exposures = False;
58 gcvalues.subwindow_mode = IncludeInferiors;
59 gcvalues.line_width = 1;
60 m_gc = XCreateGC (display, RootWindow (display, DefaultScreen (display)),
61 GCForeground | GCBackground | GCGraphicsExposures | GCLineWidth | GCSubwindowMode,
62 &gcvalues);
63
64 m_backgroundPixel = gcvalues.background;
65 m_ok = true;
66 }
67
68 wxScreenDC::~wxScreenDC()
69 {
70 EndDrawingOnTop();
71 }
72
73 bool wxScreenDC::StartDrawingOnTop(wxWindow* window)
74 {
75 wxRect rect;
76 int x, y, width, height;
77 window->GetPosition(& x, & y);
78 if (window->GetParent() && !window->IsKindOf(CLASSINFO(wxFrame)))
79 window->GetParent()->ClientToScreen(& x, & y);
80 window->GetSize(& width, & height);
81 rect.x = x; rect.y = y;
82 rect.width = width; rect.height = height;
83
84 return StartDrawingOnTop(& rect);
85 }
86
87 bool wxScreenDC::StartDrawingOnTop(wxRect* rect)
88 {
89 if (sm_overlayWindow)
90 return false;
91
92 Display *dpy = (Display*) wxGetDisplay();
93 Pixmap screenPixmap = RootWindow(dpy, DefaultScreen(dpy));
94
95 int x = 0;
96 int y = 0;
97 int width, height;
98 wxDisplaySize(&width, &height);
99
100 if (rect)
101 {
102 x = rect->x; y = rect->y;
103 width = rect->width; height = rect->height;
104 }
105 sm_overlayWindowX = x;
106 sm_overlayWindowY = y;
107
108 XSetWindowAttributes attributes;
109 attributes.override_redirect = True;
110 unsigned long valueMask = CWOverrideRedirect;
111
112 sm_overlayWindow = (WXWindow) XCreateWindow(dpy, screenPixmap, x, y, width, height, 0,
113 wxDisplayDepth(), InputOutput,
114 DefaultVisual(dpy, 0), valueMask,
115 & attributes);
116
117 if (sm_overlayWindow)
118 {
119 XMapWindow(dpy, (Window) sm_overlayWindow);
120 return true;
121 }
122 else
123 return false;
124 }
125
126 bool wxScreenDC::EndDrawingOnTop()
127 {
128 if (sm_overlayWindow)
129 {
130 XDestroyWindow((Display*) wxGetDisplay(), (Window) sm_overlayWindow);
131 sm_overlayWindow = 0;
132 return true;
133 }
134 else
135 return false;
136 }