]> git.saurik.com Git - wxWidgets.git/blame - src/msw/dcmemory.cpp
Some more Unicode changes.
[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>
25889d3c 30#include "wx/msw/winundef.h"
2bda0e17
KB
31
32#if !USE_SHARED_LIBRARY
33IMPLEMENT_DYNAMIC_CLASS(wxMemoryDC, wxDC)
34#endif
35
36/*
37 * Memory DC
38 *
39 */
40
41wxMemoryDC::wxMemoryDC(void)
42{
57c208c5 43 m_hDC = (WXHDC) ::CreateCompatibleDC((HDC) NULL);
2bda0e17 44 m_ok = (m_hDC != 0);
1c089c47 45 m_bOwnsDC = TRUE;
2bda0e17
KB
46
47 SetBrush(*wxWHITE_BRUSH);
48 SetPen(*wxBLACK_PEN);
49}
50
51wxMemoryDC::wxMemoryDC(wxDC *old_dc)
52{
53 old_dc->BeginDrawing();
54
55 m_hDC = (WXHDC) ::CreateCompatibleDC((HDC) old_dc->GetHDC());
56 m_ok = (m_hDC != 0);
57
58 old_dc->EndDrawing();
59
60 SetBrush(*wxWHITE_BRUSH);
61 SetPen(*wxBLACK_PEN);
62}
63
64wxMemoryDC::~wxMemoryDC(void)
65{
66}
67
68void wxMemoryDC::SelectObject(const wxBitmap& bitmap)
69{
70 // Select old bitmap out of the device context
71 if (m_oldBitmap)
72 {
73 ::SelectObject((HDC) m_hDC, (HBITMAP) m_oldBitmap);
74 if (m_selectedBitmap.Ok())
75 {
76 m_selectedBitmap.SetSelectedInto(NULL);
77 m_selectedBitmap = wxNullBitmap;
78 }
79 }
80
81 // Do own check for whether the bitmap is already selected into
82 // a device context
83 if (bitmap.GetSelectedInto() && (bitmap.GetSelectedInto() != this))
84 {
85 wxFatalError("Error in wxMemoryDC::SelectObject\nBitmap is selected in another wxMemoryDC.\nDelete the first wxMemoryDC or use SelectObject(NULL)");
86 return;
87 }
7b46ecac
JS
88
89 // Check if the bitmap has the correct depth for this device context
16553659
JS
90// if (bitmap.Ok() && (bitmap.GetDepth() != GetDepth()))
91 // JACS 11/12/98: disabling this since the Forty Thieves sample
92 // shows this not working properly. In fact, if loading from a resource,
93 // the depth should become the screen depth, so why was it being called?
2917e920
BM
94// if (0)
95// {
96// // Make a new bitmap that has the correct depth.
97// wxBitmap newBitmap = bitmap.GetBitmapForDC(* this);
98//
99// m_selectedBitmap = newBitmap ;
100// }
101// else
102// {
7b46ecac 103 m_selectedBitmap = bitmap;
2917e920 104// }
2bda0e17
KB
105
106 if (!m_selectedBitmap.Ok())
107 return;
108
109 m_selectedBitmap.SetSelectedInto(this);
c4e7c2aa 110 HBITMAP bm = (HBITMAP) ::SelectObject((HDC) m_hDC, (HBITMAP) m_selectedBitmap.GetHBITMAP());
2bda0e17
KB
111
112 if (bm == ERROR)
113 {
114 wxFatalError("Error in wxMemoryDC::SelectObject\nBitmap may not be loaded, or may be selected in another wxMemoryDC.\nDelete the first wxMemoryDC to deselect bitmap.");
115 }
116 else if (!m_oldBitmap)
117 m_oldBitmap = (WXHBITMAP) bm;
118}
119
953ccd3d 120void wxMemoryDC::DoGetSize(int *width, int *height) const
2bda0e17
KB
121{
122 if (!m_selectedBitmap.Ok())
123 {
124 *width = 0; *height = 0;
125 return;
126 }
127 *width = m_selectedBitmap.GetWidth();
128 *height = m_selectedBitmap.GetHeight();
129}
130