]> git.saurik.com Git - wxWidgets.git/blame - src/motif/dcmemory.cpp
#ifdefed out Ole... functions for Cygwin.
[wxWidgets.git] / src / motif / dcmemory.cpp
CommitLineData
4bb6408c
JS
1/////////////////////////////////////////////////////////////////////////////
2// Name: dcmemory.cpp
3// Purpose: wxMemoryDC class
4// Author: Julian Smart
5// Modified by:
6// Created: 01/02/97
7// RCS-ID: $Id$
8// Copyright: (c) Julian Smart
9// Licence: wxWindows licence
10/////////////////////////////////////////////////////////////////////////////
11
12#ifdef __GNUG__
13#pragma implementation "dcmemory.h"
14#endif
15
16#include "wx/dcmemory.h"
a4294b78
JS
17#include "wx/utils.h"
18
19#include <Xm/Xm.h>
20
21#include "wx/motif/private.h"
4bb6408c
JS
22
23//-----------------------------------------------------------------------------
24// wxMemoryDC
25//-----------------------------------------------------------------------------
26
16c1f7f3 27IMPLEMENT_DYNAMIC_CLASS(wxMemoryDC, wxWindowDC)
4bb6408c
JS
28
29wxMemoryDC::wxMemoryDC(void)
30{
a4294b78
JS
31 m_ok = TRUE;
32 m_display = wxGetDisplay();
33
34 Display* display = (Display*) m_display;
35
36 XGCValues gcvalues;
37 gcvalues.foreground = BlackPixel (display, DefaultScreen (display));
38 gcvalues.background = WhitePixel (display, DefaultScreen (display));
39 gcvalues.graphics_exposures = False;
40 gcvalues.line_width = 1;
41 m_gc = (WXGC) XCreateGC (display, RootWindow (display, DefaultScreen (display)),
42 GCForeground | GCBackground | GCGraphicsExposures | GCLineWidth,
43 &gcvalues);
44
45 m_backgroundPixel = (int) gcvalues.background;
46
47 // Get the current Font so we can set it back later
48 XGCValues valReturn;
49 XGetGCValues((Display*) m_display, (GC) m_gc, GCFont, &valReturn);
50 m_oldFont = (WXFont) valReturn.font;
c0ed460c
JS
51 SetBrush (* wxWHITE_BRUSH);
52 SetPen (* wxBLACK_PEN);
4bb6408c
JS
53};
54
a4294b78 55wxMemoryDC::wxMemoryDC( wxDC* dc )
4bb6408c 56{
a4294b78
JS
57 m_ok = TRUE;
58 if (dc && dc->IsKindOf(CLASSINFO(wxWindowDC)))
59 m_display = ((wxWindowDC*)dc)->GetDisplay();
60 else
61 m_display = wxGetDisplay();
62
63 Display* display = (Display*) m_display;
64
65 XGCValues gcvalues;
66 gcvalues.foreground = BlackPixel (display, DefaultScreen (display));
67 gcvalues.background = WhitePixel (display, DefaultScreen (display));
68 gcvalues.graphics_exposures = False;
69 gcvalues.line_width = 1;
70 m_gc = (WXGC) XCreateGC (display, RootWindow (display, DefaultScreen (display)),
71 GCForeground | GCBackground | GCGraphicsExposures | GCLineWidth,
72 &gcvalues);
73
74 m_backgroundPixel = (int) gcvalues.background;
75
76 // Get the current Font so we can set it back later
77 XGCValues valReturn;
78 XGetGCValues((Display*) m_display, (GC) m_gc, GCFont, &valReturn);
79 m_oldFont = (WXFont) valReturn.font;
c0ed460c
JS
80 SetBrush (* wxWHITE_BRUSH);
81 SetPen (* wxBLACK_PEN);
4bb6408c
JS
82};
83
84wxMemoryDC::~wxMemoryDC(void)
85{
86};
87
88void wxMemoryDC::SelectObject( const wxBitmap& bitmap )
89{
16c1f7f3 90 m_bitmap = bitmap;
a4294b78
JS
91
92 if (m_gc)
93 XFreeGC((Display*) m_display, (GC) m_gc);
94 m_gc = (WXGC) NULL;
95
96 if (m_bitmap.Ok() && (bitmap.GetDisplay() == m_display))
4bb6408c 97 {
16c1f7f3 98 m_pixmap = m_bitmap.GetPixmap();
a4294b78
JS
99 Display* display = (Display*) m_display;
100
101 XGCValues gcvalues;
102 gcvalues.foreground = BlackPixel (display, DefaultScreen (display));
103 gcvalues.background = WhitePixel (display, DefaultScreen (display));
104 gcvalues.graphics_exposures = False;
105 gcvalues.line_width = 1;
106 m_gc = (WXGC) XCreateGC (display, RootWindow (display, DefaultScreen (display)),
107 GCForeground | GCBackground | GCGraphicsExposures | GCLineWidth,
108 &gcvalues);
109
110 m_backgroundPixel = (int) gcvalues.background;
111
112 // Get the current Font so we can set it back later
113 XGCValues valReturn;
114 XGetGCValues((Display*) m_display, (GC) m_gc, GCFont, &valReturn);
115 m_oldFont = (WXFont) valReturn.font;
116
117 bool oldOpt = GetOptimization();
118 SetOptimization(FALSE);
119
c0ed460c
JS
120 SetBrush (* wxWHITE_BRUSH);
121 SetPen (* wxBLACK_PEN);
a4294b78
JS
122
123 SetOptimization(oldOpt);
124
125 m_ok = TRUE;
4bb6408c
JS
126 }
127 else
128 {
129 m_ok = FALSE;
a4294b78 130 m_pixmap = (WXPixmap) 0;
4bb6408c
JS
131 };
132};
133
134void wxMemoryDC::GetSize( int *width, int *height ) const
135{
16c1f7f3 136 if (m_bitmap.Ok())
4bb6408c 137 {
16c1f7f3
JS
138 if (width) (*width) = m_bitmap.GetWidth();
139 if (height) (*height) = m_bitmap.GetHeight();
4bb6408c
JS
140 }
141 else
142 {
143 if (width) (*width) = 0;
144 if (height) (*height) = 0;
145 };
146};
147
148