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

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


#include "StdAfx.h"
#include "_DemoAction.h"


C_DemoActionWithMouseInput::C_DemoActionWithMouseInput( class CView* a_pView )
:
m_pView( a_pView )
{
  // nop
}

C_DemoActionWithMouseInput::C_DemoActionWithMouseInput( const C_DemoActionWithMouseInput& a_Src )
:
m_pView( a_Src.m_pView )
{
  // nop
}

/*override*/ bool C_DemoActionWithMouseInput::AcquireInput()
{
  // don't handle if capture already set
  if ( GetCapture() )
    return FALSE;

  // protect maps while looping
  AfxLockTempMaps();  

  // set capture 
  m_pView->SetCapture();
  m_pView->UpdateWindow();

  // get first point
  {
    _AFX_THREAD_STATE* pThreadState = _afxThreadState.GetData();
    MSG& Msg = pThreadState->m_lastSentMsg;
    ASSERT( Msg.message == WM_LBUTTONDOWN );
    CPoint Point( (int)(short)LOWORD(Msg.lParam), (int)(short)HIWORD(Msg.lParam) ); 
    _DPToHimetric( &Point );
    TRACE( "FIRST POINT %d %d\n", Point.x, Point.y );
    _OnFirstPoint( Point, (Msg.wParam & MK_SHIFT) != 0 );
  }

  //
  BOOL Canceled = FALSE;

  // get messages until capture lost or cancelled/accepted
  while ( true )
  {
    MSG Msg;
    ::GetMessage( &Msg, 0, 0, 0 );

    if ( ! GetCapture() || m_pView->GetCapture()->GetSafeHwnd() != m_pView->m_hWnd )
    {
      Canceled = TRUE;
      break;
    }

    switch ( Msg.message )
    {
    case WM_MOUSEMOVE:
      {
        CPoint Point( (int)(short)LOWORD(Msg.lParam), (int)(short)HIWORD(Msg.lParam) ); 
        _DPToHimetric( &Point );
        TRACE( "NEXT POINT %d %d\n", Point.x, Point.y );
        _OnNextPoint( Point, (Msg.wParam & MK_SHIFT) != 0 );
      }
      continue;
    case WM_LBUTTONUP:
      {
        CPoint Point( (int)(short)LOWORD(Msg.lParam), (int)(short)HIWORD(Msg.lParam) ); 
        _DPToHimetric( &Point );
        TRACE( "LAST POINT %d %d\n", Point.x, Point.y );
        _OnLastPoint( Point, (Msg.wParam & MK_SHIFT) != 0 );
      }
      break;
    case WM_KEYDOWN:
      if ( Msg.wParam != VK_ESCAPE )
        continue;
    case WM_RBUTTONDOWN:
      Canceled = TRUE;
      break;
    default:
      DispatchMessage( &Msg );
      continue;
    }
    break;
  }
  if ( Canceled )
  {
    TRACE( "CANCELLED\n" );
    _OnCancelled();
  }
  ReleaseCapture();
  AfxUnlockTempMaps( FALSE );
  return ! Canceled;
}

void C_DemoActionWithMouseInput::_DPToHimetric( CPoint* a_pPoint )
{
  CDC* pDC = m_pView->GetDC();
  int OldMM = pDC->SetMapMode( MM_HIMETRIC );
  pDC->DPtoLP( a_pPoint );
  pDC->SetMapMode( OldMM );
  m_pView->ReleaseDC( pDC );
}

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