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
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: _DemoAction_ClearDrawing.cpp $ 

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


#include "StdAfx.h"
#include "_Factory.h"
#include "_Graphic.h"
#include "KisActionDemoDoc.h"
#include "_DemoAction.h"
#include "Resource.h"
#include "MainFrm.h"


using namespace kis;
using namespace std;


namespace
{


class C_DemoAction_ClearDrawing : public C_DemoAction
{

public:
  C_DemoAction_ClearDrawing( CKisActionDemoDoc* a_pDoc )
  :
  m_pDoc( a_pDoc )
  {
    // nop
  }

  C_DemoAction_ClearDrawing( const C_DemoAction_ClearDrawing& a_Src )
  :
  m_pDoc( a_Src.m_pDoc ),
  m_Stream( a_Src.m_Stream )
  {
    // nop
  }

  /*override*/ SP_Action Clone() const
  {
    return SP_Action( new C_DemoAction_ClearDrawing( *this ) );
  }

  /*override*/ bool IsUnexecutable() const
  {
    return true;
  }

  /*override*/ bool IsNull() const
  {
    return m_pDoc->m_Drawing.IsEmpty();
  }

  /*override*/ bool HasInput() const
  {
    return true;
  }

  /*override*/ bool AcquireInput()
  {
    return true;
  }

  /*override*/ bool Execute()
  {
    if ( ! m_Stream )
      return false;
    m_pDoc->m_Drawing.Write( m_Stream );
    m_pDoc->m_Drawing.Delete();
    m_pDoc->UpdateAllViews( 0 );
    return true;
  }

  /*override*/ bool HasUnexecute() const
  {
    return true;//m_Stream.good();
  }

  /*override*/ void Unexecute()
  {
    using namespace std;
    m_Stream.clear();
    m_Stream.seekg( 0 );
    m_pDoc->m_Drawing.Read( m_Stream );
    m_pDoc->UpdateAllViews( 0 );
  }

  /*override*/ bool HasReexecute() const
  {
    return true;
  }

  /*override*/ void Reexecute()
  {
    m_pDoc->m_Drawing.Delete();
    m_pDoc->UpdateAllViews( 0 );
  }

  /*override*/ void GetName( unsigned char* a_Name, const unsigned char a_MaxNameLen ) const
  {
    CString Name;
    Name.LoadString( IDS_CLEAR_DRAWING );
    _tcsncpy( reinterpret_cast<TCHAR*>(a_Name), Name, (a_MaxNameLen - 1) / sizeof( TCHAR ) );
  }

  /*override*/ unsigned int GetBytesCount() const
  {
    return sizeof( *this );
  }

protected:
  CKisActionDemoDoc* m_pDoc;
  C_TmpFStream m_Stream;

  /*override*/ ~C_DemoAction_ClearDrawing()
  {
    // nop
  }

};


} // namespace


SP_Action C_Factory::CreateAction_ClearDrawing( CKisActionDemoDoc* a_pDoc )
{
  return SP_Action( new C_DemoAction_ClearDrawing( a_pDoc ) );
}

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 | Mobile
Web03 | 2.8.140821.2 | Last Updated 16 Feb 2013
Article Copyright 2006 by zdf
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid