📄 undoredolistbox.cpp
字号:
// UndoRedoListBox.cpp : implementation file
//
#include "stdafx.h"
#include "UndoRedoListBox.h"
#include "WndController.h"
#include "WndMsgHandler.h"
#include "UndoRedoBar.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
namespace SbjCore
{
namespace Mvc
{
struct UndoRedoListBoxImpl : public SbjCore::Mvc::WndController
{
SbjCore::Mvc::UndoRedoBar* pTheBar;
UINT nTheID;
class LButtonUpHandler : public SbjCore::Mvc::WndMsgHandler
{
virtual LRESULT OnHandleWndMsg(WPARAM wParam, LPARAM lParam, LRESULT* pResult)
{
wParam;
CPoint pt(GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam));
*pResult = 0;
LRESULT lRslt = 0; // let the default process after us
SbjCore::Mvc::UndoRedoListBoxImpl* pCtrlr = dynamic_cast<SbjCore::Mvc::UndoRedoListBoxImpl*>(GetController());
CListBox* pListBox = dynamic_cast<CListBox*>(pCtrlr->GetWnd());
BOOL bOutside;
pListBox->ItemFromPoint(pt, bOutside);
if (!bOutside)
{
SbjCore::Mvc::UndoRedoBar* pBar = dynamic_cast<SbjCore::Mvc::UndoRedoBar*>(pListBox->GetParent());
ASSERT_VALID(pBar);
if (pBar != NULL)
{
pBar->DoUndo();
}
}
return lRslt;
}
} theLButtonUpHandler;
friend LButtonUpHandler;
class MouseMoveHandler : public SbjCore::Mvc::WndMsgHandler
{
CALL_DEFAULT_FIRST() // comment out to handle message before default
virtual LRESULT OnHandleWndMsg(WPARAM wParam, LPARAM lParam, LRESULT* pResult)
{
wParam;
CPoint pt(GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam));
*pResult = 1;
LRESULT lRslt = 1;
SbjCore::Mvc::UndoRedoListBoxImpl* pCtrlr = dynamic_cast<SbjCore::Mvc::UndoRedoListBoxImpl*>(GetController());
CListBox* pListBox = dynamic_cast<CListBox*>(pCtrlr->GetWnd());
BOOL bOutside;
int nItem = pListBox->ItemFromPoint(pt, bOutside);
if (!bOutside)
{
pListBox->SelItemRange (FALSE, nItem + 1, pListBox->GetCount () - 1);
if (nItem == 0)
{
pListBox->SetSel(0);
}
else
{
pListBox->SelItemRange(TRUE, 0, nItem);
}
SbjCore::Mvc::UndoRedoBar* pBar = dynamic_cast<SbjCore::Mvc::UndoRedoBar*>(pListBox->GetParent());
ASSERT_VALID(pBar);
if (pBar != NULL)
{
pCtrlr->pTheBar->SetLabelCount(nItem + 1);
}
}
return lRslt;
}
} theMouseMoveHandler;
friend MouseMoveHandler;
UndoRedoListBoxImpl() :
pTheBar(NULL),
nTheID(0)
{
AddHandler(WM_LBUTTONUP, &theLButtonUpHandler);
AddHandler(WM_MOUSEMOVE, &theMouseMoveHandler);
}
virtual ~UndoRedoListBoxImpl()
{
}
};
///////////////////////////////////////////////////////////////////
UndoRedoListBox::UndoRedoListBox() :
m_pImpl(new UndoRedoListBoxImpl)
{
SetController(m_pImpl);
}
UndoRedoListBox::~UndoRedoListBox()
{
try
{
delete m_pImpl;
}
catch(...)
{
ASSERT(FALSE);
}
}
BOOL UndoRedoListBox::PreTranslateMessage( MSG* pMsg )
{
if (pMsg->message == WM_LBUTTONDOWN)
{
return TRUE;
}
return CListBox::PreTranslateMessage(pMsg);
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -