Click here to Skip to main content
Click here to Skip to main content
 
Add your own
alternative version

A Simple, Action Based, Undo/Redo Framework

, 16 Feb 2013 CPOL
How to use a simple, action based, undo/redo framework
kiswinbin_v_1.zip
kis
kis.dll
kis.lib
KisWinBin_v_1_r_1.zip
KisWinBin_v_1_r_1
kis
kis.dll
kis.lib
kiswinsrc_v_1.zip
KisActionDemo
res
KisActionDemo.ico
KisActionDemoDoc.ico
Toolbar.bmp
vssver.scc
KisWinSrc_v_1_r_1.zip
KisWinSrc_v_1_r_1
kis
KisActionDemo
res
KisActionDemo.ico
KisActionDemoDoc.ico
Toolbar.bmp
vssver.scc
/*
***************************************************************************

kis v 1

(c) 2006, Florin DUMITRESCU

mailto: fdproxy@gmail.com

$Workfile: KisActionDemoView.cpp $ 

***************************************************************************
*/


#include "stdafx.h"
#include "KisActionDemo.h"
#include "KisActionDemoDoc.h"
#include "KisActionDemoView.h"
#include ".\kisactiondemoview.h"


#ifdef _DEBUG
#define new DEBUG_NEW
#endif


CBitmap CKisActionDemoView::s_OsbBmp;
CDC CKisActionDemoView::s_OsbDc;

void CKisActionDemoView::_PrepareOsb( CDC* a_pDC, CRect* a_pRect )
{
  BOOL IsOsbBmpRecreated = FALSE;
  
  if ( GetObjectType( s_OsbBmp.m_hObject ) != OBJ_BITMAP )
  {
    s_OsbBmp.CreateCompatibleBitmap( a_pDC, a_pRect->Width(), a_pRect->Height() );
    IsOsbBmpRecreated = TRUE;
  }

  BITMAP OsbBmp;
  s_OsbBmp.GetBitmap( &OsbBmp );
  int Width = OsbBmp.bmWidth;
  if ( Width < a_pRect->Width() )
    Width = a_pRect->Width();
  int Height = OsbBmp.bmHeight;
  if ( Height < a_pRect->Height() )
    Height = a_pRect->Height();
  if ( OsbBmp.bmWidth < Width || OsbBmp.bmHeight < Height )
  {
    s_OsbBmp.DeleteObject();
    s_OsbBmp.CreateCompatibleBitmap( a_pDC, Width, Height );
    IsOsbBmpRecreated = TRUE;
  }

  if ( IsOsbBmpRecreated )
  {
    s_OsbDc.DeleteDC();
    s_OsbDc.CreateCompatibleDC(a_pDC );    
    s_OsbDc.SelectObject( &s_OsbBmp );
  }


  s_OsbDc.FillSolidRect( 0, 0, Width, Height, RGB( 255, 255, 255 ) );
}

IMPLEMENT_DYNCREATE(CKisActionDemoView, CView)

BEGIN_MESSAGE_MAP(CKisActionDemoView, CView)
	ON_COMMAND(ID_FILE_PRINT, CView::OnFilePrint)
	ON_COMMAND(ID_FILE_PRINT_DIRECT, CView::OnFilePrint)
	ON_COMMAND(ID_FILE_PRINT_PREVIEW, CView::OnFilePrintPreview)
  ON_WM_LBUTTONDOWN()
  ON_WM_ERASEBKGND()
END_MESSAGE_MAP()

CKisActionDemoView::CKisActionDemoView()
{
  // nop
}

CKisActionDemoView::~CKisActionDemoView()
{
  // nop
}

void CKisActionDemoView::OnDraw(CDC* pDC)
{
	CKisActionDemoDoc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);
	if (!pDoc)
		return;

  if ( ! pDC->IsPrinting() )
  {
    CRect cr;
    GetClientRect( &cr );
    _PrepareOsb( pDC, &cr );
    pDoc->m_Drawing.Draw( &s_OsbDc );
    pDC->BitBlt( 0, 0, cr.Width(), cr.Height(), &s_OsbDc, 0, 0, SRCCOPY);
  }
  else
  {
    pDoc->m_Drawing.Draw( pDC );
  }

}

BOOL CKisActionDemoView::OnPreparePrinting(CPrintInfo* pInfo)
{
	return DoPreparePrinting(pInfo);
}

void CKisActionDemoView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
	// TODO: add extra initialization before printing
}

void CKisActionDemoView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
	// TODO: add cleanup after printing
}

#ifdef _DEBUG

void CKisActionDemoView::AssertValid() const
{
	CView::AssertValid();
}

void CKisActionDemoView::Dump(CDumpContext& dc) const
{
	CView::Dump(dc);
}

CKisActionDemoDoc* CKisActionDemoView::GetDocument() const // non-debug version is inline
{
	ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CKisActionDemoDoc)));
	return (CKisActionDemoDoc*)m_pDocument;
}

#endif _DEBUG

void CKisActionDemoView::OnInitialUpdate()
{
  CView::OnInitialUpdate();

  EnableToolTips(TRUE);
}

void CKisActionDemoView::OnLButtonDown(UINT nFlags, CPoint point)
{
  CKisActionDemoDoc* pDoc = GetDocument();
  pDoc->OnLButtonDown( this );
}

BOOL CKisActionDemoView::OnEraseBkgnd(CDC* pDC)
{
  return TRUE;
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

zdf

Romania Romania
Just a humble programmer.

| Advertise | Privacy | Terms of Use | Mobile
Web04 | 2.8.141223.1 | Last Updated 16 Feb 2013
Article Copyright 2006 by zdf
Everything else Copyright © CodeProject, 1999-2014
Layout: fixed | fluid