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