]> git.saurik.com Git - wxWidgets.git/blame - src/msw/dcmemory.cpp
Cured some Latex problems; fixed i declaration; fixed filedlg.cpp
[wxWidgets.git] / src / msw / dcmemory.cpp
CommitLineData
2bda0e17
KB
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 and Markus Holzem
9// Licence: wxWindows licence
10/////////////////////////////////////////////////////////////////////////////
11
12#ifdef __GNUG__
2bda0e17
KB
13#pragma implementation "dcmemory.h"
14#endif
15
16// For compilers that support precompilation, includes "wx.h".
17#include "wx/wxprec.h"
18
19#ifdef __BORLANDC__
20#pragma hdrstop
21#endif
22
23#ifndef WX_PRECOMP
2432b92d 24#include "wx/utils.h"
2bda0e17
KB
25#endif
26
27#include "wx/dcmemory.h"
28
29#include <windows.h>
30
31#if !USE_SHARED_LIBRARY
32IMPLEMENT_DYNAMIC_CLASS(wxMemoryDC, wxDC)
33#endif
34
35/*
36 * Memory DC
37 *
38 */
39
40wxMemoryDC::wxMemoryDC(void)
41{
57c208c5 42 m_hDC = (WXHDC) ::CreateCompatibleDC((HDC) NULL);
2bda0e17 43 m_ok = (m_hDC != 0);
1c089c47 44 m_bOwnsDC = TRUE;
2bda0e17
KB
45
46 SetBrush(*wxWHITE_BRUSH);
47 SetPen(*wxBLACK_PEN);
48}
49
50wxMemoryDC::wxMemoryDC(wxDC *old_dc)
51{
52 old_dc->BeginDrawing();
53
54 m_hDC = (WXHDC) ::CreateCompatibleDC((HDC) old_dc->GetHDC());
55 m_ok = (m_hDC != 0);
56
57 old_dc->EndDrawing();
58
59 SetBrush(*wxWHITE_BRUSH);
60 SetPen(*wxBLACK_PEN);
61}
62
63wxMemoryDC::~wxMemoryDC(void)
64{
65}
66
67void wxMemoryDC::SelectObject(const wxBitmap& bitmap)
68{
69 // Select old bitmap out of the device context
70 if (m_oldBitmap)
71 {
72 ::SelectObject((HDC) m_hDC, (HBITMAP) m_oldBitmap);
73 if (m_selectedBitmap.Ok())
74 {
75 m_selectedBitmap.SetSelectedInto(NULL);
76 m_selectedBitmap = wxNullBitmap;
77 }
78 }
79
80 // Do own check for whether the bitmap is already selected into
81 // a device context
82 if (bitmap.GetSelectedInto() && (bitmap.GetSelectedInto() != this))
83 {
84 wxFatalError("Error in wxMemoryDC::SelectObject\nBitmap is selected in another wxMemoryDC.\nDelete the first wxMemoryDC or use SelectObject(NULL)");
85 return;
86 }
7b46ecac
JS
87
88 // Check if the bitmap has the correct depth for this device context
16553659
JS
89// if (bitmap.Ok() && (bitmap.GetDepth() != GetDepth()))
90 // JACS 11/12/98: disabling this since the Forty Thieves sample
91 // shows this not working properly. In fact, if loading from a resource,
92 // the depth should become the screen depth, so why was it being called?
93 if (0)
7b46ecac
JS
94 {
95 // Make a new bitmap that has the correct depth.
96 wxBitmap newBitmap = bitmap.GetBitmapForDC(* this);
97
98 m_selectedBitmap = newBitmap ;
99 }
100 else
101 {
102 m_selectedBitmap = bitmap;
103 }
2bda0e17
KB
104
105 if (!m_selectedBitmap.Ok())
106 return;
107
108 m_selectedBitmap.SetSelectedInto(this);
c4e7c2aa 109 HBITMAP bm = (HBITMAP) ::SelectObject((HDC) m_hDC, (HBITMAP) m_selectedBitmap.GetHBITMAP());
2bda0e17
KB
110
111 if (bm == ERROR)
112 {
113 wxFatalError("Error in wxMemoryDC::SelectObject\nBitmap may not be loaded, or may be selected in another wxMemoryDC.\nDelete the first wxMemoryDC to deselect bitmap.");
114 }
115 else if (!m_oldBitmap)
116 m_oldBitmap = (WXHBITMAP) bm;
117}
118
119void wxMemoryDC::GetSize(int *width, int *height) const
120{
121 if (!m_selectedBitmap.Ok())
122 {
123 *width = 0; *height = 0;
124 return;
125 }
126 *width = m_selectedBitmap.GetWidth();
127 *height = m_selectedBitmap.GetHeight();
128}
129