]> git.saurik.com Git - wxWidgets.git/blame - src/motif/dcmemory.cpp
VTK wrapper of vtkRenderWindow for wxPython. Tested on MSW so far.
[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"
0ba1a6f3 17#include "wx/settings.h"
a4294b78
JS
18#include "wx/utils.h"
19
20#include <Xm/Xm.h>
21
22#include "wx/motif/private.h"
4bb6408c
JS
23
24//-----------------------------------------------------------------------------
25// wxMemoryDC
26//-----------------------------------------------------------------------------
27
16c1f7f3 28IMPLEMENT_DYNAMIC_CLASS(wxMemoryDC, wxWindowDC)
4bb6408c
JS
29
30wxMemoryDC::wxMemoryDC(void)
31{
a4294b78
JS
32 m_ok = TRUE;
33 m_display = wxGetDisplay();
2d120f83 34
a4294b78 35 Display* display = (Display*) m_display;
2d120f83 36
a4294b78
JS
37 XGCValues gcvalues;
38 gcvalues.foreground = BlackPixel (display, DefaultScreen (display));
39 gcvalues.background = WhitePixel (display, DefaultScreen (display));
40 gcvalues.graphics_exposures = False;
41 gcvalues.line_width = 1;
42 m_gc = (WXGC) XCreateGC (display, RootWindow (display, DefaultScreen (display)),
43 GCForeground | GCBackground | GCGraphicsExposures | GCLineWidth,
2d120f83
JS
44 &gcvalues);
45
a4294b78 46 m_backgroundPixel = (int) gcvalues.background;
2d120f83 47
a4294b78
JS
48 // Get the current Font so we can set it back later
49 XGCValues valReturn;
50 XGetGCValues((Display*) m_display, (GC) m_gc, GCFont, &valReturn);
51 m_oldFont = (WXFont) valReturn.font;
c0ed460c
JS
52 SetBrush (* wxWHITE_BRUSH);
53 SetPen (* wxBLACK_PEN);
0ba1a6f3 54 SetFont(wxSystemSettings::GetSystemFont(wxSYS_DEFAULT_GUI_FONT));
4bb6408c
JS
55};
56
a4294b78 57wxMemoryDC::wxMemoryDC( wxDC* dc )
4bb6408c 58{
a4294b78
JS
59 m_ok = TRUE;
60 if (dc && dc->IsKindOf(CLASSINFO(wxWindowDC)))
61 m_display = ((wxWindowDC*)dc)->GetDisplay();
62 else
63 m_display = wxGetDisplay();
2d120f83 64
a4294b78 65 Display* display = (Display*) m_display;
2d120f83 66
a4294b78
JS
67 XGCValues gcvalues;
68 gcvalues.foreground = BlackPixel (display, DefaultScreen (display));
69 gcvalues.background = WhitePixel (display, DefaultScreen (display));
70 gcvalues.graphics_exposures = False;
71 gcvalues.line_width = 1;
72 m_gc = (WXGC) XCreateGC (display, RootWindow (display, DefaultScreen (display)),
73 GCForeground | GCBackground | GCGraphicsExposures | GCLineWidth,
2d120f83
JS
74 &gcvalues);
75
a4294b78 76 m_backgroundPixel = (int) gcvalues.background;
2d120f83 77
a4294b78
JS
78 // Get the current Font so we can set it back later
79 XGCValues valReturn;
80 XGetGCValues((Display*) m_display, (GC) m_gc, GCFont, &valReturn);
81 m_oldFont = (WXFont) valReturn.font;
c0ed460c
JS
82 SetBrush (* wxWHITE_BRUSH);
83 SetPen (* wxBLACK_PEN);
4bb6408c
JS
84};
85
86wxMemoryDC::~wxMemoryDC(void)
87{
88};
89
90void wxMemoryDC::SelectObject( const wxBitmap& bitmap )
91{
2d120f83 92 m_bitmap = bitmap;
a4294b78 93
2d120f83
JS
94 if (m_gc)
95 XFreeGC((Display*) m_display, (GC) m_gc);
96 m_gc = (WXGC) NULL;
97
98 if (m_bitmap.Ok() && (bitmap.GetDisplay() == m_display))
99 {
100 m_pixmap = m_bitmap.GetPixmap();
101 Display* display = (Display*) m_display;
102
103 XGCValues gcvalues;
104 gcvalues.foreground = BlackPixel (display, DefaultScreen (display));
105 gcvalues.background = WhitePixel (display, DefaultScreen (display));
106 gcvalues.graphics_exposures = False;
107 gcvalues.line_width = 1;
108 m_gc = (WXGC) XCreateGC (display, RootWindow (display, DefaultScreen (display)),
109 GCForeground | GCBackground | GCGraphicsExposures | GCLineWidth,
110 &gcvalues);
111
112 m_backgroundPixel = (int) gcvalues.background;
113
114 // Get the current Font so we can set it back later
115 XGCValues valReturn;
116 XGetGCValues((Display*) m_display, (GC) m_gc, GCFont, &valReturn);
117 m_oldFont = (WXFont) valReturn.font;
118
119 bool oldOpt = GetOptimization();
120 SetOptimization(FALSE);
121
122 SetBrush (* wxWHITE_BRUSH);
123 SetPen (* wxBLACK_PEN);
124
125 SetOptimization(oldOpt);
126
127 m_ok = TRUE;
128 }
129 else
130 {
131 m_ok = FALSE;
132 m_pixmap = (WXPixmap) 0;
133 };
4bb6408c
JS
134};
135
96f201da 136void wxMemoryDC::DoGetSize( int *width, int *height ) const
4bb6408c 137{
2d120f83
JS
138 if (m_bitmap.Ok())
139 {
140 if (width) (*width) = m_bitmap.GetWidth();
141 if (height) (*height) = m_bitmap.GetHeight();
142 }
143 else
144 {
145 if (width) (*width) = 0;
146 if (height) (*height) = 0;
147 };
4bb6408c
JS
148};
149
150