]> git.saurik.com Git - wxWidgets.git/blame - src/msw/dcmemory.cpp
Added wxCLIP_CHILDREN style (mainly for getting rid of flicker), other minor mods
[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__
13#pragma implementation
14#pragma implementation "dcmemory.h"
15#endif
16
17// For compilers that support precompilation, includes "wx.h".
18#include "wx/wxprec.h"
19
20#ifdef __BORLANDC__
21#pragma hdrstop
22#endif
23
24#ifndef WX_PRECOMP
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{
42 m_hDC = (WXHDC) ::CreateCompatibleDC(NULL);
43 m_ok = (m_hDC != 0);
44
45 SetBrush(*wxWHITE_BRUSH);
46 SetPen(*wxBLACK_PEN);
47}
48
49wxMemoryDC::wxMemoryDC(wxDC *old_dc)
50{
51 old_dc->BeginDrawing();
52
53 m_hDC = (WXHDC) ::CreateCompatibleDC((HDC) old_dc->GetHDC());
54 m_ok = (m_hDC != 0);
55
56 old_dc->EndDrawing();
57
58 SetBrush(*wxWHITE_BRUSH);
59 SetPen(*wxBLACK_PEN);
60}
61
62wxMemoryDC::~wxMemoryDC(void)
63{
64}
65
66void wxMemoryDC::SelectObject(const wxBitmap& bitmap)
67{
68 // Select old bitmap out of the device context
69 if (m_oldBitmap)
70 {
71 ::SelectObject((HDC) m_hDC, (HBITMAP) m_oldBitmap);
72 if (m_selectedBitmap.Ok())
73 {
74 m_selectedBitmap.SetSelectedInto(NULL);
75 m_selectedBitmap = wxNullBitmap;
76 }
77 }
78
79 // Do own check for whether the bitmap is already selected into
80 // a device context
81 if (bitmap.GetSelectedInto() && (bitmap.GetSelectedInto() != this))
82 {
83 wxFatalError("Error in wxMemoryDC::SelectObject\nBitmap is selected in another wxMemoryDC.\nDelete the first wxMemoryDC or use SelectObject(NULL)");
84 return;
85 }
86
87 m_selectedBitmap = bitmap;
88
89 if (!m_selectedBitmap.Ok())
90 return;
91
92 m_selectedBitmap.SetSelectedInto(this);
93#if DEBUG > 1
94 wxDebugMsg("wxMemoryDC::SelectObject: Selecting HBITMAP %X\n", m_selectedBitmap.GetHBITMAP());
95#endif
96 HBITMAP bm = ::SelectObject((HDC) m_hDC, (HBITMAP) m_selectedBitmap.GetHBITMAP());
97
98 if (bm == ERROR)
99 {
100 wxFatalError("Error in wxMemoryDC::SelectObject\nBitmap may not be loaded, or may be selected in another wxMemoryDC.\nDelete the first wxMemoryDC to deselect bitmap.");
101 }
102 else if (!m_oldBitmap)
103 m_oldBitmap = (WXHBITMAP) bm;
104}
105
106void wxMemoryDC::GetSize(int *width, int *height) const
107{
108 if (!m_selectedBitmap.Ok())
109 {
110 *width = 0; *height = 0;
111 return;
112 }
113 *width = m_selectedBitmap.GetWidth();
114 *height = m_selectedBitmap.GetHeight();
115}
116