]> git.saurik.com Git - wxWidgets.git/blame - src/motif/dcscreen.cpp
Now works when derived from wxTextCtrlBase, using wxScrollHelper.
[wxWidgets.git] / src / motif / dcscreen.cpp
CommitLineData
4bb6408c
JS
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
65571936 9// Licence: wxWindows licence
4bb6408c
JS
10/////////////////////////////////////////////////////////////////////////////
11
1248b41f
MB
12// For compilers that support precompilation, includes "wx.h".
13#include "wx/wxprec.h"
14
4c151c73 15#include "wx/window.h"
68be9f09 16#include "wx/frame.h"
4bb6408c 17#include "wx/dcscreen.h"
89c7e962
JS
18#include "wx/utils.h"
19
338dd992
JJ
20#ifdef __VMS__
21#pragma message disable nosimpint
22#endif
89c7e962 23#include <Xm/Xm.h>
338dd992
JJ
24#ifdef __VMS__
25#pragma message enable nosimpint
26#endif
89c7e962 27
3096bd2f 28#include "wx/motif/private.h"
4bb6408c 29
dfc54541 30IMPLEMENT_DYNAMIC_CLASS(wxScreenDC, wxWindowDC)
4bb6408c 31
89c7e962
JS
32WXWindow wxScreenDC::sm_overlayWindow = 0;
33int wxScreenDC::sm_overlayWindowX = 0;
34int wxScreenDC::sm_overlayWindowY = 0;
35
4bb6408c
JS
36// Create a DC representing the whole screen
37wxScreenDC::wxScreenDC()
38{
2d120f83
JS
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;
96be256b 62 m_ok = true;
4bb6408c
JS
63}
64
65wxScreenDC::~wxScreenDC()
66{
68be9f09 67 EndDrawingOnTop();
4bb6408c
JS
68}
69
dfc54541
JS
70bool wxScreenDC::StartDrawingOnTop(wxWindow* window)
71{
2d120f83
JS
72 wxRect rect;
73 int x, y, width, height;
74 window->GetPosition(& x, & y);
68be9f09 75 if (window->GetParent() && !window->IsKindOf(CLASSINFO(wxFrame)))
2d120f83
JS
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);
dfc54541
JS
82}
83
7fe7d506 84bool wxScreenDC::StartDrawingOnTop(wxRect* rect)
dfc54541 85{
2d120f83 86 if (sm_overlayWindow)
96be256b 87 return false;
2d120f83
JS
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);
96be256b 117 return true;
2d120f83
JS
118 }
119 else
96be256b 120 return false;
dfc54541
JS
121}
122
123bool wxScreenDC::EndDrawingOnTop()
124{
2d120f83
JS
125 if (sm_overlayWindow)
126 {
127 XDestroyWindow((Display*) wxGetDisplay(), (Window) sm_overlayWindow);
128 sm_overlayWindow = 0;
96be256b 129 return true;
2d120f83
JS
130 }
131 else
96be256b 132 return false;
dfc54541 133}