📄 epbindoc.cpp
字号:
///////////////////////////////////////////////////////////////////////////
// File: epbindoc.h
// Version: 1.6.0.9
// Updated: 18-Oct-1999
//
// Binary 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
////////////////////////////////////////////////////////////////////////////
// epbindoc.cpp : implementation of the CEditPadBinDoc class
//
#include "stdafx.h"
#include "editpad.h"
#include "epbindoc.h"
#include "editcmd.h"
#include "filesup.h"
#include "mainfrm.h"
#include "epbinvw.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CEditPadBinDoc
IMPLEMENT_DYNCREATE (CEditPadBinDoc, CDocument)
BEGIN_MESSAGE_MAP (CEditPadBinDoc, CDocument)
//{{AFX_MSG_MAP(CEditPadBinDoc)
ON_COMMAND (ID_READ_ONLY, OnReadOnly)
ON_UPDATE_COMMAND_UI (ID_READ_ONLY, OnUpdateReadOnly)
//}}AFX_MSG_MAP
END_MESSAGE_MAP ()
/////////////////////////////////////////////////////////////////////////////
// CEditPadBinDoc construction/destruction
#pragma warning(disable:4355)
CEditPadBinDoc::CEditPadBinDoc ()
{
#if !defined(DEMO)
m_pData = NULL; // pointer to data
m_length = 0; // length of data
#else
m_pData = (LPBYTE) malloc(0x40);
for(int i = 0; i < 0x40; i++)
m_pData[i] = i;
#endif
}
#pragma warning(default:4355)
CEditPadBinDoc:: ~ CEditPadBinDoc ()
{
if (m_pData)
free (m_pData);
}
/////////////////////////////////////////////////////////////////////////////
// CEditPadBinDoc serialization
void CEditPadBinDoc::
Serialize (CArchive & ar)
{
if (ar.IsStoring ())
{
// TODO: add storing code here
}
else
{
// TODO: add loading code here
}
}
/////////////////////////////////////////////////////////////////////////////
// CEditPadBinDoc diagnostics
#ifdef _DEBUG
void CEditPadBinDoc::
AssertValid ()
const
{
CDocument::AssertValid ();
}
void CEditPadBinDoc::Dump (CDumpContext & dc)
const
{
CDocument::Dump (dc);
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CEditPadBinDoc commands
bool CEditPadBinDoc::LoadFromFile (LPCTSTR pszName)
{
struct _stat status;
if (_tstat (pszName, &status))
return false;
FILE *file = _tfopen (pszName, _T ("rb"));
if (!file)
return false;
if (m_pData)
free (m_pData);
m_length = 0;
m_pData = (LPBYTE) malloc (status.st_size);
if (!m_pData)
{
fclose (file);
return false;
}
m_length = status.st_size;
fread (m_pData, 1, m_length, file);
fclose (file);
return true;
}
bool CEditPadBinDoc::SaveToFile (LPCTSTR pszName)
{
FILE *file = _tfopen (pszName, _T ("wb"));
if (!file)
return false;
fwrite (m_pData, 1, m_length, file);
fclose (file);
return true;
}
BOOL CEditPadBinDoc::SaveModified()
{
return CDocument::SaveModified();
}
void CEditPadBinDoc::DeleteContents ()
{
CDocument::DeleteContents ();
if (m_pData)
{
free (m_pData);
m_pData = NULL;
}
m_length = NULL;
}
void CEditPadBinDoc::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 ();
CView *pView = (CView*) m_viewList.GetHead ();
if(pwndMain->IsKindOf (RUNTIME_CLASS (CMainFrame)))
{
((CMainFrame*) pwndMain)->MDIActivate (pView->GetParent ());
((CMainFrame*) pwndMain)->FlashUntilFocus ();
}
else
{
((CMainFrame2*) pwndMain)->MDIActivate (pView->GetParent ());
((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);
CEditPadBinView *pView;
do
{
pView = (CEditPadBinView*) GetNextView (pos);
// do pushcursor
}
while (pos);
LoadFromFile (pszPathName);
pos = GetFirstViewPosition ();
ASSERT (pos);
do
{
pView = (CEditPadBinView*) GetNextView (pos);
// do 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 CEditPadBinDoc::
OnNewDocument ()
{
if (!CDocument::OnNewDocument ())
return FALSE;
return TRUE;
}
BOOL CEditPadBinDoc::
OnOpenDocument (LPCTSTR lpszPathName)
{
if (!CDocument::OnOpenDocument (lpszPathName))
{
if (!OnNewDocument ())
{
return FALSE;
}
SetPathName (lpszPathName, TRUE);
return TRUE;
}
if (LoadFromFile (lpszPathName))
{
if (theApp.m_dwFlags & EP_NOTIFY_CHANGES)
{
AddFile (lpszPathName);
StartWatching ();
}
return TRUE;
}
return FALSE;
}
BOOL CEditPadBinDoc::
OnSaveDocument (LPCTSTR lpszPathName)
{
if (theApp.m_dwFlags & EP_NOTIFY_CHANGES)
{
StopWatching ();
RemoveFile (lpszPathName);
}
BOOL bResult = SaveToFile (lpszPathName);
if (theApp.m_dwFlags & EP_NOTIFY_CHANGES)
{
AddFile (lpszPathName);
StartWatching ();
}
return bResult; // Note - we didn't call inherited member!
}
void CEditPadBinDoc::
OnReadOnly ()
{
POSITION pos = GetFirstViewPosition ();
CHexEditView *pView;
while (pos)
{
pView = (CHexEditView*) GetNextView (pos);
ASSERT_VALID (pView);
pView->SendMessage (WM_COMMAND, ID_READ_ONLY);
/*m_dwFlags ^= HVW_READ_ONLY;
pView->m_dwFlags |= HVW_UPDATE;
pView->RedrawWindow ();*/
}
}
void CEditPadBinDoc::
OnUpdateReadOnly (CCmdUI * pCmdUI)
{
POSITION pos = GetFirstViewPosition ();
if (pos)
{
CHexEditView *pView = (CHexEditView*) GetNextView (pos);
ASSERT_VALID (pView);
pCmdUI->SetCheck ((pView->m_dwFlags & HVW_READ_ONLY) != 0);
}
}
void CEditPadBinDoc::OnCloseDocument()
{
CString sDoc = GetPathName ();
if (!sDoc.IsEmpty () && (theApp.m_dwFlags & EP_NOTIFY_CHANGES))
{
StopWatching ();
RemoveFile (sDoc);
}
CDocTemplate *pDocTemplate = GetDocTemplate ();
POSITION pos = pDocTemplate->GetFirstDocPosition ();
ASSERT (pos);
pDocTemplate->GetNextDoc (pos);
if (!pos)
{
CWnd *pWnd = AfxGetMainWnd ();
if(pWnd->IsKindOf (RUNTIME_CLASS (CMainFrame)))
((CMainFrame*) pWnd)->ChooseStatusBar (FALSE);
else
((CMainFrame2*) pWnd)->ChooseStatusBar (FALSE);
}
CDocument::OnCloseDocument();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -