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