]> git.saurik.com Git - wxWidgets.git/blame_incremental - src/motif/dcscreen.cpp
More Motif additions: mdi and sashtest samples now just about work!
[wxWidgets.git] / src / motif / dcscreen.cpp
... / ...
CommitLineData
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
24IMPLEMENT_DYNAMIC_CLASS(wxScreenDC, wxWindowDC)
25#endif
26
27WXWindow wxScreenDC::sm_overlayWindow = 0;
28int wxScreenDC::sm_overlayWindowX = 0;
29int wxScreenDC::sm_overlayWindowY = 0;
30
31// Create a DC representing the whole screen
32wxScreenDC::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.line_width = 1;
51 m_gc = XCreateGC (display, RootWindow (display, DefaultScreen (display)),
52 GCForeground | GCBackground | GCGraphicsExposures | GCLineWidth,
53 &gcvalues);
54
55 m_backgroundPixel = (int) gcvalues.background;
56 m_ok = TRUE;
57}
58
59wxScreenDC::~wxScreenDC()
60{
61}
62
63bool wxScreenDC::StartDrawingOnTop(wxWindow* window)
64{
65 wxRect rect;
66 int x, y, width, height;
67 window->GetPosition(& x, & y);
68 window->ClientToScreen(& x, & y);
69 window->GetSize(& width, & height);
70 rect.x = x; rect.y = y;
71 rect.width = width; rect.height = height;
72
73 return StartDrawingOnTop(& rect);
74}
75
76bool wxScreenDC::StartDrawingOnTop(wxRect* rect = NULL)
77{
78 if (sm_overlayWindow)
79 return FALSE;
80
81 Display *dpy = (Display*) wxGetDisplay();
82 Pixmap screenPixmap = RootWindow(dpy, DefaultScreen(dpy));
83
84 int x = 0;
85 int y = 0;
86 int width, height;
87 wxDisplaySize(&width, &height);
88
89 if (rect)
90 {
91 x = rect->x; y = rect->y;
92 width = rect->width; height = rect->height;
93 }
94 sm_overlayWindowX = x;
95 sm_overlayWindowY = y;
96
97 XSetWindowAttributes attributes;
98 attributes.override_redirect = True;
99 unsigned long valueMask = CWOverrideRedirect;
100
101 sm_overlayWindow = (WXWindow) XCreateWindow(dpy, screenPixmap, x, y, width, height, 0,
102 wxDisplayDepth(), InputOutput,
103 DefaultVisual(dpy, 0), valueMask,
104 & attributes);
105
106 if (sm_overlayWindow)
107 {
108 XMapWindow(dpy, (Window) sm_overlayWindow);
109 return TRUE;
110 }
111 else
112 return FALSE;
113}
114
115bool wxScreenDC::EndDrawingOnTop()
116{
117 if (sm_overlayWindow)
118 {
119 XDestroyWindow((Display*) wxGetDisplay(), (Window) sm_overlayWindow);
120 sm_overlayWindow = 0;
121 return TRUE;
122 }
123 else
124 return FALSE;
125}