| 1 | ///////////////////////////////////////////////////////////////////////////// |
| 2 | // Name: dcmemory.cpp |
| 3 | // Purpose: wxMemoryDC class |
| 4 | // Author: AUTHOR |
| 5 | // Modified by: |
| 6 | // Created: 01/02/97 |
| 7 | // RCS-ID: $Id$ |
| 8 | // Copyright: (c) AUTHOR |
| 9 | // Licence: wxWindows licence |
| 10 | ///////////////////////////////////////////////////////////////////////////// |
| 11 | |
| 12 | #ifdef __GNUG__ |
| 13 | #pragma implementation "dcmemory.h" |
| 14 | #endif |
| 15 | |
| 16 | #include "wx/dcmemory.h" |
| 17 | #include "wx/mac/private.h" |
| 18 | |
| 19 | //----------------------------------------------------------------------------- |
| 20 | // wxMemoryDC |
| 21 | //----------------------------------------------------------------------------- |
| 22 | |
| 23 | IMPLEMENT_DYNAMIC_CLASS(wxMemoryDC,wxPaintDC) |
| 24 | |
| 25 | wxMemoryDC::wxMemoryDC(void) |
| 26 | : m_selected() |
| 27 | { |
| 28 | m_ok = TRUE; |
| 29 | SetBackground(*wxWHITE_BRUSH); |
| 30 | SetBrush(*wxWHITE_BRUSH); |
| 31 | SetPen(*wxBLACK_PEN); |
| 32 | m_ok = FALSE; |
| 33 | }; |
| 34 | |
| 35 | wxMemoryDC::wxMemoryDC( wxDC *WXUNUSED(dc) ) |
| 36 | : m_selected() |
| 37 | { |
| 38 | m_ok = TRUE; |
| 39 | SetBackground(*wxWHITE_BRUSH); |
| 40 | SetBrush(*wxWHITE_BRUSH); |
| 41 | SetPen(*wxBLACK_PEN); |
| 42 | m_ok = FALSE; |
| 43 | }; |
| 44 | |
| 45 | wxMemoryDC::~wxMemoryDC() |
| 46 | { |
| 47 | if ( m_selected.Ok() ) |
| 48 | { |
| 49 | UnlockPixels( GetGWorldPixMap(MAC_WXHBITMAP(m_selected.GetHBITMAP())) ); |
| 50 | } |
| 51 | }; |
| 52 | |
| 53 | void wxMemoryDC::SelectObject( const wxBitmap& bitmap ) |
| 54 | { |
| 55 | if ( m_selected.Ok() ) |
| 56 | { |
| 57 | UnlockPixels( GetGWorldPixMap(MAC_WXHBITMAP(m_selected.GetHBITMAP())) ); |
| 58 | } |
| 59 | m_selected = bitmap; |
| 60 | if (m_selected.Ok()) |
| 61 | { |
| 62 | if ( m_selected.GetHBITMAP() ) |
| 63 | { |
| 64 | m_macPort = (GrafPtr) m_selected.GetHBITMAP() ; |
| 65 | LockPixels( GetGWorldPixMap( (CGrafPtr) m_macPort ) ) ; |
| 66 | wxMask * mask = bitmap.GetMask() ; |
| 67 | if ( mask ) |
| 68 | { |
| 69 | m_macMask = mask->GetMaskBitmap() ; |
| 70 | } |
| 71 | SetRectRgn( (RgnHandle) m_macBoundaryClipRgn , 0 , 0 , m_selected.GetWidth() , m_selected.GetHeight() ) ; |
| 72 | CopyRgn( (RgnHandle) m_macBoundaryClipRgn ,(RgnHandle) m_macCurrentClipRgn ) ; |
| 73 | m_ok = TRUE ; |
| 74 | } |
| 75 | else |
| 76 | { |
| 77 | m_ok = FALSE; |
| 78 | } |
| 79 | } |
| 80 | else |
| 81 | { |
| 82 | m_ok = FALSE; |
| 83 | } |
| 84 | } |
| 85 | |
| 86 | void wxMemoryDC::DoGetSize( int *width, int *height ) const |
| 87 | { |
| 88 | if (m_selected.Ok()) |
| 89 | { |
| 90 | if (width) (*width) = m_selected.GetWidth(); |
| 91 | if (height) (*height) = m_selected.GetHeight(); |
| 92 | } |
| 93 | else |
| 94 | { |
| 95 | if (width) (*width) = 0; |
| 96 | if (height) (*height) = 0; |
| 97 | } |
| 98 | } |
| 99 | |
| 100 | |