📄 editpadview.cpp
字号:
///////////////////////////////////////////////////////////////////////////
// File: editpadview.cpp
// Version: 1.3.0.6
// Updated: 19-Jul-1998
//
// View core
//
// Copyright: Ferdinand Prantl, portions by Stcherbatchenko Andrei
// E-mail: prantl@ff.cuni.cz
//
// You are free to use or modify this code to the following restrictions:
// - Acknowledge me somewhere in your about box, simple "Parts of code by.."
// will be enough. If you can't (or don't want to), contact me personally.
// - LEAVE THIS HEADER INTACT
////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////
// 14-Sep-99
// + FIX: GetFileSize stuff causing crash on file size comparings (Hans Eckardt)
////////////////////////////////////////////////////////////////////////////
// editpadview.cpp : implementation of the CEditPadView class
//
#include "stdafx.h"
#include "editpad.h"
#include "editpaddoc.h"
#include "editpadview.h"
#include "editcmd.h"
#include "generpg.h"
#include "editoroptionspage.h"
#include "fontpg.h"
#include "mainfrm.h"
#include "filesup.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CEditPadView
IMPLEMENT_DYNCREATE (CEditPadView, CCrystalEditViewEx)
BEGIN_MESSAGE_MAP (CEditPadView, CCrystalEditViewEx)
//{{AFX_MSG_MAP(CEditPadView)
ON_WM_CONTEXTMENU ()
ON_COMMAND (ID_VIEW_OPTIONS, OnViewOptions)
ON_WM_TIMER()
ON_WM_CREATE()
ON_COMMAND (ID_FILE_RELOAD, OnFileReload)
ON_UPDATE_COMMAND_UI(ID_FILE_RELOAD, OnUpdateFileReload)
//}}AFX_MSG_MAP
// Standard printing commands
// ON_COMMAND(ID_FILE_PRINT, CCrystalEditViewEx::OnFilePrint)
// ON_COMMAND(ID_FILE_PRINT_DIRECT, CCrystalEditViewEx::OnFilePrint)
// ON_COMMAND(ID_FILE_PRINT_PREVIEW, CCrystalEditViewEx::OnFilePrintPreview)
END_MESSAGE_MAP ()
/////////////////////////////////////////////////////////////////////////////
// CEditPadView construction/destruction
CEditPadView::CEditPadView ()
{
m_bRememberLastPos = (theApp.m_dwFlags & EP_REMEMBER_LASTPOS) != 0;
m_bSingle = false;
SetParser (&m_xParser);
}
CEditPadView:: ~ CEditPadView ()
{
}
BOOL CEditPadView::
PreCreateWindow (CREATESTRUCT & cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return CCrystalEditViewEx::PreCreateWindow (cs);
}
/////////////////////////////////////////////////////////////////////////////
// CEditPadView drawing
//void CEditPadView::OnDraw(CDC* pDC)
//{
// CEditPadDoc* pDoc = GetDocument();
// ASSERT_VALID(pDoc);
// // TODO: add draw code for native data here
//}
/////////////////////////////////////////////////////////////////////////////
// CEditPadView printing
//BOOL CEditPadView::OnPreparePrinting(CPrintInfo* pInfo)
//{
// // default preparation
// return DoPreparePrinting(pInfo);
//}
//
//void CEditPadView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
//{
// // TODO: add extra initialization before printing
//}
//
//void CEditPadView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
//{
// // TODO: add cleanup after printing
//}
/////////////////////////////////////////////////////////////////////////////
// CEditPadView diagnostics
#ifdef _DEBUG
void CEditPadView::
AssertValid ()
const
{
CCrystalEditViewEx::AssertValid ();
}
void CEditPadView::Dump (CDumpContext & dc)
const
{
CCrystalEditViewEx::Dump (dc);
}
CEditPadDoc *CEditPadView::GetDocument () // non-debug version is inline
{
ASSERT (m_pDocument->IsKindOf (RUNTIME_CLASS (CEditPadDoc)));
return (CEditPadDoc *) m_pDocument;
}
#endif //_DEBUG
CCrystalTextBuffer *CEditPadView::
LocateTextBuffer ()
{
return &GetDocument ()->m_xTextBuffer;
}
/////////////////////////////////////////////////////////////////////////////
// CEditPadView message handlers
#pragma warning ( disable : 4100 )
void CEditPadView::
OnContextMenu (CWnd * pWnd, CPoint point)
{
if (theApp.m_dwFlags & EP_ADVANCED_UI)
theApp.ShowPopupMenu (IDR_CONTEXT_MENU, point, this);
else
{
CMenu menu;
if (menu.LoadMenu (IDR_EDITPADTYPE))
{
CMenu *pMenu = menu.GetSubMenu (1);
if (pMenu)
// pMenu->TrackPopupMenu (TPM_LEFTBUTTON|TPM_RIGHTBUTTON|TPM_RETURNCMD|TPM_LEFTALIGN|TPM_TOPALIGN, point.x, point.y, this);
pMenu->TrackPopupMenu (TPM_LEFTBUTTON|TPM_RIGHTBUTTON|TPM_LEFTALIGN|TPM_TOPALIGN, point.x, point.y, this);
}
}
}
#pragma warning ( default : 4100 )
void CEditPadView::
OnViewOptions ()
{
CGeneralPage pgGeneral;
CEditorOptionsPage pgEditor (this);
CFontPage pgFont (this);
CString sTitle;
sTitle.LoadString (IDS_SHEET_OPTIONS);
CPropertySheet psOptions (sTitle, AfxGetMainWnd ());
psOptions.AddPage (&pgGeneral);
psOptions.AddPage (&pgEditor);
psOptions.AddPage (&pgFont);
psOptions.DoModal ();
}
void CEditPadView::OnActivateView(BOOL bActivate, CView* pActivateView, CView* pDeactiveView)
{
CCrystalEditViewEx::OnActivateView(bActivate, pActivateView, pDeactiveView);
if (GetDocument ()->IsModified ())
{
CString sTitle;
CWnd *pWnd = AfxGetMainWnd ();
pWnd->GetWindowText (sTitle);
BOOL bMaxi;
((CMDIFrameWnd*) pWnd)->MDIGetActive (&bMaxi);
if (sTitle.Left (2) != _T("* "))
{
sTitle = _T ("* ") + (bMaxi ? sTitle.Left (7) : sTitle);
pWnd->SetWindowText (sTitle);
}
CWnd *pWnd2 = GetParentFrame ();
if (!bMaxi)
{
pWnd2->GetWindowText (sTitle);
if (sTitle.Right (2) != _T(" *"))
{
sTitle += _T (" *");
pWnd2->SetWindowText (sTitle);
}
}
}
else
{
CString sTitle;
CWnd *pWnd = AfxGetMainWnd ();
pWnd->GetWindowText (sTitle);
BOOL bMaxi;
((CMDIFrameWnd*) pWnd)->MDIGetActive (&bMaxi);
if (sTitle.Left (2) == _T("* "))
{
sTitle = bMaxi ? sTitle.Mid (2, 7) : sTitle.Mid (2);
pWnd->SetWindowText (sTitle);
}
CWnd *pWnd2 = GetParentFrame ();
if (!bMaxi)
{
pWnd2->GetWindowText (sTitle);
if (sTitle.Right (2) == _T(" *"))
{
sTitle = sTitle.Left (sTitle.GetLength () - 2);
pWnd2->SetWindowText (sTitle);
}
}
}
if (bActivate)
{
CWnd *pWnd = AfxGetMainWnd ();
if(pWnd->IsKindOf (RUNTIME_CLASS (CMainFrame)))
((CMainFrame*) pWnd)->ChooseStatusBar (TRUE);
else
((CMainFrame2*) pWnd)->ChooseStatusBar (TRUE);
}
}
int CEditPadView::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CCrystalEditViewEx::OnCreate(lpCreateStruct) == -1)
return -1;
if (!(theApp.GetFlags () & EP_DRAG_N_DROP_EDIT))
SetDisableDragAndDrop (TRUE);
return 0;
}
void CEditPadView::
OnFileReload ()
{
CEditPadDoc *pDoc = (CEditPadDoc*) GetDocument ();
ASSERT (pDoc);
CString sFilePath = pDoc->GetPathName ();
if (!FileExist (sFilePath))
{
AfxMessageBox (_T ("File does not exist."));
return;
}
if (theApp.m_dwFlags & EP_NOTIFY_CHANGES)
{
pDoc->StopWatching ();
pDoc->RemoveFile (sFilePath);
}
bool bResult = pDoc->SaveModified () != 0;
if (bResult)
{
POSITION pos = pDoc->GetFirstViewPosition ();
ASSERT (pos);
CCrystalTextView *pView;
do
{
pView = (CCrystalTextView*) pDoc->GetNextView (pos);
pView->PushCursor ();
}
while (pos);
m_pTextBuffer->FreeAll ();
BOOL bResult = m_pTextBuffer->LoadFromFile (sFilePath);
// ->HE display as not modified now (LoadFromFile should do that)
m_pTextBuffer->SetModified (FALSE);
// <-HE
pos = pDoc->GetFirstViewPosition ();
ASSERT (pos);
do
{
pView = (CCrystalTextView*) pDoc->GetNextView (pos);
if (bResult)
pView->PopCursor ();
else
pView->ResetView ();
pView->Invalidate ();
}
while (pos);
// pDoc->UpdateAllViews (this);
}
if (theApp.m_dwFlags & EP_NOTIFY_CHANGES)
{
pDoc->AddFile (sFilePath);
pDoc->StartWatching ();
}
}
// ->HE If no file saved yet, disable cmd
void CEditPadView::OnUpdateFileReload(CCmdUI* pCmdUI)
{
CEditPadDoc *pDoc = (CEditPadDoc*) GetDocument ();
ASSERT (pDoc);
pCmdUI->Enable (!pDoc->GetPathName ().IsEmpty ());
}
// <-HE
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -