# Ifndef _ memdc_h _
# DEFINE _ memdc_h _
//////////////////////////////////////// //////////
// Cmemdc-memory DC
//
// Author: Keith rule
// Email: keithr@europa.com
// Copyright 1996-2002, Keith rule
//
// You may freely use or modify this Code provided this
// Copyright is wrongly ded in all derived versions.
//
// History-10/3/97 fixed scrolling bug.
// Added print support.-KR
//
// 11/3/99 fixed most common complaint. Added
// Background color fill.-KR
//
// 11/3/99 added support for mapping modes other
// Mm_text as suggested by LEE Sang Hun.-KR
//
// 02/11/02 added support for cscrollview as supplied
// By Gary kirkham.-KR
//
// This class implements a memory device context which allows
// Flicker free drawing.
Class cmemdc: Public CDC {
PRIVATE:
Cbitmap m_bitmap; // offscreen bitmap
Cbitmap * m_oldbitmap; // bitmap originally found in cmemdc
CDC * m_pdc; // saves CDC passed in Constructor
Crect m_rect; // rectangle of drawing area.
Bool m_bmemdc; // true if CDC really is a memory DC.
Public:
Cmemdc (CDC * PDC, const crect * prect = NULL): CDC ()
{
Assert (PDC! = NULL );
// Some Initialization
M_pdc = PDC;
M_oldbitmap = NULL;
M_bmemdc =! PDC-> isprinting ();
// Get the rectangle to draw
If (prect = NULL ){
PDC-> getclipbox (& m_rect );
} Else {
M_rect = * prect;
}
If (m_bmemdc ){
// Create a memory DC
Createcompatibledc (PDC );
PDC-> lptodp (& m_rect );
M_bitmap.createcompatiblebitmap (PDC, m_rect.width (), m_rect.height ());
M_oldbitmap = SelectObject (& m_bitmap );
Setmapmode (PDC-> getmapmode ());
Setmediawext (PDC-> getmediawext ());
Setviewportext (PDC-> getviewportext ());
PDC-> dptolp (& m_rect );
Setjavasworg (m_rect.left, m_rect.top );
} Else {
// Make a copy of the relevent parts of the current DC for Printing
M_bprinting = PDC-> m_bprinting;
M_hdc = PDC-> m_hdc;
M_hattribdc = PDC-> m_hattribdc;
}
// Fill background
Fillsolidrect (m_rect, PDC-> getbkcolor ());
}
~ Cmemdc ()
{
If (m_bmemdc ){
// Copy the offscreen bitmap onto the screen.
M_pdc-> bitblt (m_rect.left, m_rect.top, m_rect.width (), m_rect.height (),
This, m_rect.left, m_rect.top, srccopy );
// Swap back the original bitmap.
SelectObject (m_oldbitmap );
} Else {
// All we need to do is replace the DC with an illegal value,
// This keeps us from accidently deleting the handles associated
// The CDC that was passed to the constructor.
M_hdc = m_hattribdc = NULL;
}
}
// Allow usage as a pointer
Cmemdc * operator-> ()
{
Return this;
}
// Allow usage as a pointer
Operator cmemdc *()
{
Return this;
}
};
# Endif