]>
git.saurik.com Git - wxWidgets.git/blob - src/os2/dcmemory.cpp
   1 ///////////////////////////////////////////////////////////////////////////// 
   3 // Purpose:     wxMemoryDC class 
   4 // Author:      David Webster 
   8 // Copyright:   (c) David Webster 
   9 // Licence:     wxWindows licence 
  10 ///////////////////////////////////////////////////////////////////////////// 
  12 // For compilers that support precompilation, includes "wx.h". 
  13 #include "wx/wxprec.h" 
  21 #include "wx/os2/private.h" 
  23 #include "wx/dcmemory.h" 
  25 IMPLEMENT_DYNAMIC_CLASS(wxMemoryDC
, wxDC
) 
  27 ///////////////////////////////////////////////////////////////////////////// 
  29 ///////////////////////////////////////////////////////////////////////////// 
  31 wxMemoryDC::wxMemoryDC(void) 
  33     CreateCompatible(NULL
); 
  35 } // end of wxMemoryDC::wxMemoryDC 
  37 wxMemoryDC::wxMemoryDC( 
  41     pOldDC
->BeginDrawing(); 
  42     CreateCompatible(pOldDC
); 
  45 } // end of wxMemoryDC::wxMemoryDC 
  47 void wxMemoryDC::Init() 
  51         SetBrush(*wxWHITE_BRUSH
); 
  54         // the background mode is only used for text background and is set in 
  55         // DrawText() to OPAQUE as required, otherwise always TRANSPARENT 
  56         ::GpiSetBackMix( GetHPS(), BM_LEAVEALONE 
); 
  58     memset(&m_vRclPaint
, 0, sizeof(m_vRclPaint
)); 
  59 } // end of wxMemoryDC::Init 
  61 bool wxMemoryDC::CreateCompatible( wxDC
* WXUNUSED(pDC
) ) 
  65     DEVOPENSTRUC  vDOP 
= {0L, "DISPLAY", NULL
, 0L, 0L, 0L, 0L, 0L, 0L}; 
  69     // Create a memory device context 
  71     hDC 
= ::DevOpenDC(vHabmain
, OD_MEMORY
, "*", 5L, (PDEVOPENDATA
)&vDOP
, NULLHANDLE
); 
  74         hPS 
= ::GpiCreatePS(vHabmain
, hDC
, &vSize
, PU_PELS 
| GPIT_MICRO 
| GPIA_ASSOC
); 
  82             // Set the wxWidgets color table 
  84             ::GpiCreateLogColorTable( m_hPS
 
  88                                      ,(LONG
)wxTheColourDatabase
->m_nSize
 
  89                                      ,(PLONG
)wxTheColourDatabase
->m_palTable
 
  91             ::GpiCreateLogColorTable( m_hPS
 
 116     // As we created the DC, we must delete it in the dtor 
 121 } // end of wxMemoryDC::CreateCompatible 
 123 void wxMemoryDC::SelectObject( 
 124   const wxBitmap
&                   rBitmap
 
 128     // Select old bitmap out of the device context 
 132         ::GpiSetBitmap(m_hPS
, NULLHANDLE
); 
 133         if (m_vSelectedBitmap
.Ok()) 
 135             m_vSelectedBitmap
.SetSelectedInto(NULL
); 
 136             m_vSelectedBitmap 
= wxNullBitmap
; 
 141     // Check for whether the bitmap is already selected into a device context 
 143     wxCHECK_RET( !rBitmap
.GetSelectedInto() || 
 144                  (rBitmap
.GetSelectedInto() == this), 
 145                  wxT("Bitmap is selected in another wxMemoryDC, delete the first wxMemoryDC or use SelectObject(NULL)") ); 
 147     WXHBITMAP                       hBmp 
= rBitmap
.GetHBITMAP(); 
 152         // Bmps drawn to are upside down, so flip it before committing 
 154         POINTL                      vPoint
[4] = { {0, m_vSelectedBitmap
.GetHeight()} 
 155                                                  ,{m_vSelectedBitmap
.GetWidth(), 0} 
 157                                                  ,{m_vSelectedBitmap
.GetWidth(), m_vSelectedBitmap
.GetHeight()} 
 168         m_vSelectedBitmap
.SetSelectedInto(NULL
); 
 170     m_vSelectedBitmap 
= rBitmap
; 
 176         m_hOldBitmap 
= (WXHBITMAP
)::GpiSetBitmap(m_hPS
, NULLHANDLE
); 
 179     m_vSelectedBitmap
.SetSelectedInto(this); 
 180     m_hOldBitmap 
= (WXHBITMAP
)::GpiSetBitmap(m_hPS
, (HBITMAP
)hBmp
); 
 182     if (m_hOldBitmap 
== HBM_ERROR
) 
 184         wxLogLastError(wxT("SelectObject(memDC, bitmap)")); 
 185         wxFAIL_MSG(wxT("Couldn't select a bitmap into wxMemoryDC")); 
 187 } // end of wxMemoryDC::SelectObject 
 189 void wxMemoryDC::DoGetSize( 
 194     if (!m_vSelectedBitmap
.Ok()) 
 200     *pWidth 
= m_vSelectedBitmap
.GetWidth(); 
 201     *pHeight 
= m_vSelectedBitmap
.GetHeight(); 
 202 } // end of wxMemoryDC::DoGetSize