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