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