⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 epricdoc.cpp

📁 一个完整的编辑器的代码(很值得参考
💻 CPP
字号:
///////////////////////////////////////////////////////////////////////////
//  File:    epricdoc.h
//  Version: 1.6.0.9
//  Updated: 18-Oct-1999
//
//  RTF Document 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
////////////////////////////////////////////////////////////////////////////

// editpaddoc.cpp : implementation of the CEditPadRichDoc class
//

#include "stdafx.h"
#include "editpad.h"

#include "epricdoc.h"
#include "editcmd.h"
#include "filesup.h"
#include "mainfrm.h"
#include "epricvw.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CEditPadRichDoc

IMPLEMENT_DYNCREATE (CEditPadRichDoc, CRichEditDoc)

BEGIN_MESSAGE_MAP (CEditPadRichDoc, CRichEditDoc)
//{{AFX_MSG_MAP(CEditPadRichDoc)
ON_COMMAND (ID_READ_ONLY, OnReadOnly)
ON_UPDATE_COMMAND_UI (ID_READ_ONLY, OnUpdateReadOnly)
//}}AFX_MSG_MAP
END_MESSAGE_MAP ()

/////////////////////////////////////////////////////////////////////////////
// CEditPadRichDoc construction/destruction

#pragma warning(disable:4355)
CEditPadRichDoc::CEditPadRichDoc ()
{
}
#pragma warning(default:4355)

CEditPadRichDoc:: ~ CEditPadRichDoc ()
{
}

/////////////////////////////////////////////////////////////////////////////
// CEditPadRichDoc serialization

void CEditPadRichDoc::
Serialize (CArchive & ar)
{
  if (ar.IsStoring ())
    {
      // TODO: add storing code here
    }
  else
    {
      // TODO: add loading code here
    }
}

/////////////////////////////////////////////////////////////////////////////
// CEditPadRichDoc diagnostics

#ifdef _DEBUG
void CEditPadRichDoc::
AssertValid ()
const
{
  CRichEditDoc::AssertValid ();
}

void CEditPadRichDoc::Dump (CDumpContext & dc)
const
{
  CRichEditDoc::Dump (dc);
}
#endif                          //_DEBUG

/////////////////////////////////////////////////////////////////////////////
// CEditPadRichDoc commands

CRichEditCntrItem* CEditPadRichDoc::CreateClientItem(REOBJECT* preo) const
{
	return NULL;
}

BOOL CEditPadRichDoc::SaveModified()
{
  return CRichEditDoc::SaveModified();
}

void CEditPadRichDoc::DeleteContents ()
{
  CRichEditDoc::DeleteContents ();
  // do delete
}

void CEditPadRichDoc::OnFileEvent (WPARAM wEvent, LPCTSTR pszPathName)
{
  if (!(theApp.m_dwFlags & EP_NOTIFY_CHANGES))
    return;
	MessageBeep (MB_ICONEXCLAMATION);
	CFrameWnd *pwndMain= (CFrameWnd*) theApp.GetMainWnd ();
	ASSERT (pwndMain);
	if (!pwndMain->IsWindowVisible ())
          if(pwndMain->IsKindOf (RUNTIME_CLASS (CMainFrame)))
		((CMainFrame*) pwndMain)->FlashUntilFocus ();
          else
		((CMainFrame2*) pwndMain)->FlashUntilFocus ();
	if (wEvent & FE_MODIFIED)
  	{
  	  bool bReload = (theApp.m_dwFlags & EP_AUTO_RELOAD) != 0;
  	  if (!bReload)
  	    {
          CString sMsg;
          sMsg.Format (IDS_FILE_CHANGED, pszPathName);
  	      bReload = AfxMessageBox (sMsg, MB_YESNO|MB_ICONQUESTION) == IDYES;
  	    }
  	  if (bReload)
        {
	        POSITION pos = GetFirstViewPosition ();
          ASSERT (pos);
	        CEditPadRichView *pView;
          do
            {
	            pView = (CEditPadRichView*) GetNextView (pos);
              // pView->PushCursor ();
            }
          while (pos);
          // m_xTextBuffer.FreeAll ();
          // m_xTextBuffer.LoadFromFile (pszPathName);
	        pos = GetFirstViewPosition ();
          ASSERT (pos);
          do
            {
	            pView = (CEditPadRichView*) GetNextView (pos);
              // pView->PopCursor ();
              HWND hWnd = pView->GetSafeHwnd ();
              ::RedrawWindow(hWnd, NULL, NULL, RDW_INVALIDATE|RDW_INTERNALPAINT|RDW_ERASE|RDW_ERASENOW|RDW_UPDATENOW|RDW_NOFRAME);
            }
          while (pos);
        }
    }
  else if (wEvent & FE_DELETED)
    {
      if (!(theApp.m_dwFlags & EP_AUTO_RELOAD))
        {
          CString sMsg;
          sMsg.Format (IDS_FILE_DELETED, pszPathName);
        	AfxMessageBox (sMsg, MB_OK|MB_ICONINFORMATION);
        }
    }
}

BOOL CEditPadRichDoc::
OnNewDocument ()
{
  if (!CRichEditDoc::OnNewDocument ())
    return FALSE;

  return TRUE;
}

BOOL CEditPadRichDoc::
OnOpenDocument (LPCTSTR lpszPathName)
{
  if (!CRichEditDoc::OnOpenDocument (lpszPathName))
    {
      if (!OnNewDocument ())
        {
          return FALSE;
        }
      SetPathName (lpszPathName, TRUE);
      return TRUE;
    }
  // do load
  if (FALSE)
    {
      if (theApp.m_dwFlags & EP_NOTIFY_CHANGES)
        {
          AddFile (lpszPathName);
   	  StartWatching ();
        }
      return TRUE;
    }
  return FALSE;
}

BOOL CEditPadRichDoc::
OnSaveDocument (LPCTSTR lpszPathName)
{
  if (theApp.m_dwFlags & EP_NOTIFY_CHANGES)
    {
      StopWatching ();
      RemoveFile (lpszPathName);
    }
  // do save
  if (theApp.m_dwFlags & EP_NOTIFY_CHANGES)
    {
      AddFile (lpszPathName);
      StartWatching ();
    }
  return TRUE;                  //  Note - we didn't call inherited member!

}

void CEditPadRichDoc::
OnReadOnly ()
{
  // do readonly
}

void CEditPadRichDoc::
OnUpdateReadOnly (CCmdUI * pCmdUI)
{
  pCmdUI->SetCheck (FALSE);
}

void CEditPadRichDoc::OnCloseDocument() 
{
  theApp.m_sLastDoc = GetPathName ();
  if (!theApp.m_sLastDoc.IsEmpty () && (theApp.m_dwFlags & EP_NOTIFY_CHANGES))
    {
      StopWatching ();
      RemoveFile ((LPCTSTR) theApp.m_sLastDoc);
    }
	CRichEditDoc::OnCloseDocument();
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -