]> git.saurik.com Git - wxWidgets.git/blob - src/motif/dcscreen.cpp
Fix another crash when conversion fails in Unix PostScript code.
[wxWidgets.git] / src / motif / dcscreen.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/motif/dcscreen.cpp
3 // Purpose: wxScreenDCImpl class
4 // Author: Julian Smart
5 // Modified by:
6 // Created: 17/09/98
7 // Copyright: (c) Julian Smart
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
10
11 // For compilers that support precompilation, includes "wx.h".
12 #include "wx/wxprec.h"
13
14 #ifndef WX_PRECOMP
15 #include "wx/utils.h"
16 #include "wx/window.h"
17 #include "wx/frame.h"
18 #include "wx/dcscreen.h"
19 #endif
20
21 #ifdef __VMS__
22 #pragma message disable nosimpint
23 #endif
24 #include <Xm/Xm.h>
25 #ifdef __VMS__
26 #pragma message enable nosimpint
27 #endif
28
29 #include "wx/motif/private.h"
30 #include "wx/motif/dcscreen.h"
31
32 IMPLEMENT_ABSTRACT_CLASS(wxScreenDCImpl, wxWindowDCImpl)
33
34 WXWindow wxScreenDCImpl::sm_overlayWindow = 0;
35 int wxScreenDCImpl::sm_overlayWindowX = 0;
36 int wxScreenDCImpl::sm_overlayWindowY = 0;
37
38 // Create a DC representing the whole screen
39 wxScreenDCImpl::wxScreenDCImpl(wxScreenDC *owner)
40 : wxWindowDCImpl(owner)
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 wxScreenDCImpl::~wxScreenDCImpl()
69 {
70 EndDrawingOnTop();
71 }
72
73 bool wxScreenDCImpl::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 wxScreenDCImpl::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 wxScreenDCImpl::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 }