undolist.cpp
资源名称:44757463.rar [点击查看]
上传用户:lj3531212
上传日期:2007-06-18
资源大小:346k
文件大小:4k
源码类别:
绘图程序
开发平台:
Visual C++
- // UndoList.cpp :
- //
- #include "stdafx.h"
- #include "GraphSoft.h"
- #include "UndoList.h"
- #include "Und_Base.h"
- #include "CoreLog.h"
- #include "Core.h"
- #include "UndoDlg.h"
- #include "GraphSoftView.h"
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- /////////////////////////////////////////////////////////////////////////////
- // CUndoList
- CUndoList::CUndoList()
- {
- m_pParentDlg = NULL;
- m_nPos = -1;
- m_nToolTip = -1;
- m_bToolTip = false;
- m_pToolTip = NULL;
- }
- CUndoList::~CUndoList()
- {
- if (m_pToolTip != NULL)
- delete m_pToolTip;
- }
- BEGIN_MESSAGE_MAP(CUndoList, CListBox)
- //{{AFX_MSG_MAP(CUndoList)
- ON_WM_MOUSEMOVE()
- ON_WM_LBUTTONDOWN()
- ON_CONTROL_REFLECT(LBN_SELCHANGE, OnSelchange)
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
- /////////////////////////////////////////////////////////////////////////////
- // CUndoList
- void CUndoList::SetContents()
- {
- ResetContent();
- if(m_pToolTip) delete m_pToolTip ;
- m_nPos = -1;
- m_nToolTip = -1;
- m_bToolTip = false;
- m_pToolTip = NULL;
- CCoreLog* pLog = m_pCore->GetCoreLog();
- // Undo/Redo
- if (m_nID == ID_EDIT_UNDO) {
- for (long int nUndoUndo = pLog->m_nUndoUndo-1; nUndoUndo >= 0; nUndoUndo--) {
- CUND_Base* pUndBase = pLog->m_undoInfo[nUndoUndo];
- AddString(pUndBase->GetTitle());
- }
- }
- else if (m_nID == ID_EDIT_REDO) {
- for (long int nUndoUndo = pLog->m_nUndoUndo; nUndoUndo < pLog->m_nUndoInfo; nUndoUndo++) {
- CUND_Base* pUndBase = pLog->m_undoInfo[nUndoUndo];
- AddString(pUndBase->GetTitle());
- }
- }
- //
- if (m_pToolTip == NULL) {
- m_pToolTip = new CToolTipCtrl;
- if (m_pToolTip->Create(this)) {
- m_pToolTip->AddTool(this, "");
- //
- m_pToolTip->SetDelayTime(TTDT_INITIAL, 100); // 100ms
- m_pToolTip->SetDelayTime(TTDT_AUTOPOP, 1000*10); // 10s
- m_pToolTip->SetDelayTime(TTDT_RESHOW, 100); // 100ms
- }
- }
- }
- void CUndoList::OnMouseMove(UINT nFlags, CPoint point)
- {
- BOOL bOutside;
- long int nPos = this->ItemFromPoint(point, bOutside);
- if (! bOutside) {
- SetPos(nPos);
- if (m_pToolTip != NULL) {
- if (m_nToolTip != m_nPos) {
- m_nToolTip = m_nPos;
- m_bToolTip = false;
- CRect rect ;
- GetClientRect(&rect) ;
- long int nTextLen = GetTextLen(nPos) ;
- if (nTextLen > 0) {
- CString text;
- GetText(m_nToolTip, text);
- CFont* pFont = GetParent()->GetFont();
- LOGFONT logFont;
- pFont->GetLogFont(&logFont);
- CFont font;
- font.CreateFontIndirect(&logFont);
- CDC dc;
- dc.CreateCompatibleDC(NULL);
- dc.SelectObject(font);
- SIZE sz;
- ::GetTextExtentPoint32(dc.GetSafeHdc(), text, text.GetLength(), &sz);
- if (sz.cx > rect.Width()) {
- m_pToolTip->UpdateTipText(text, this);
- m_bToolTip = true;
- }
- }
- }
- m_pToolTip->Activate(m_bToolTip);
- }
- }
- CListBox::OnMouseMove(nFlags, point);
- }
- void CUndoList::OnLButtonDown(UINT nFlags, CPoint point)
- {
- OnUndo();
- CListBox::OnLButtonDown(nFlags, point);
- }
- void CUndoList::OnSelchange()
- {
- long int nPos = GetCurSel();
- if (nPos != m_nPos)
- SetPos(nPos);
- }
- void CUndoList::OnUndo()
- {
- int i;
- if(m_nID == ID_EDIT_REDO){
- for (i = 0; i <= m_nPos; i++)
- m_pCore->OnEditRedo();
- }else if(m_nID == ID_EDIT_UNDO){
- for (i = 0; i <= m_nPos; i++)
- m_pCore->OnEditUndo();
- }
- GetParent()->PostMessage(WM_CLOSE);
- }
- void CUndoList::SetPos(long nPos)
- {
- if (m_nPos != nPos) {
- m_nPos = nPos;
- SetCurSel(m_nPos);
- if (m_pParentDlg != NULL) {
- m_pParentDlg->SetStatus(1+m_nPos);
- }
- }
- }
- BOOL CUndoList::PreTranslateMessage(MSG* pMsg)
- {
- if (m_pToolTip != NULL)
- m_pToolTip->RelayEvent(pMsg);
- return CListBox::PreTranslateMessage(pMsg);
- }