?? view.cpp
字號:
/*
View.cpp : implementation of the CSnaggerView class
Implements the view class which is responsible for most of the user
interface presentation.
Author: Steven E. Sipe
*/
#include "stdafx.h"
#include <afxadv.h>
#include <io.h>
#include <direct.h>
#include "SiteSnag.h"
#include "Document.h"
#include "View.h"
#include "urldlg.h"
#include "options.h"
#include "progress.h"
#include "wait.h"
#include "project.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
const CString g_strProjDir = "Projects\\";
/////////////////////////////////////////////////////////////////////////////
// CSnaggerView
IMPLEMENT_DYNCREATE(CSnaggerView, CView)
BEGIN_MESSAGE_MAP(CSnaggerView, CView)
//{{AFX_MSG_MAP(CSnaggerView)
ON_WM_SIZE()
ON_NOTIFY(NM_DBLCLK, IDC_TREE, OnDblclkTree)
ON_COMMAND(ID_STOP, OnStop)
ON_UPDATE_COMMAND_UI(ID_STOP, OnUpdateStop)
ON_UPDATE_COMMAND_UI(ID_FILE_OPTIONS, OnUpdateFileOptions)
ON_UPDATE_COMMAND_UI(ID_FILE_REMOVEALL, OnUpdateFileRemoveall)
ON_UPDATE_COMMAND_UI(ID_APP_EXIT, OnUpdateAppExit)
ON_UPDATE_COMMAND_UI(ID_FILE_NEW, OnUpdateFileNew)
ON_UPDATE_COMMAND_UI(ID_FILE_OPEN, OnUpdateFileOpen)
ON_UPDATE_COMMAND_UI(ID_FILE_SAVE, OnUpdateFileSave)
ON_UPDATE_COMMAND_UI(ID_FILE_SAVE_AS, OnUpdateFileSaveAs)
ON_COMMAND(ID_FILE_NEW, OnFileNew)
ON_COMMAND(ID_FILE_OPEN, OnFileOpen)
ON_COMMAND(ID_FILE_RENAME, OnFileRename)
ON_UPDATE_COMMAND_UI(ID_FILE_RENAME, OnUpdateFileRename)
ON_COMMAND(ID_FILE_CLOSE, OnFileClose)
ON_UPDATE_COMMAND_UI(ID_FILE_CLOSE, OnUpdateFileClose)
ON_COMMAND(ID_SITEINPUT, OnSiteinput)
ON_COMMAND(ID_PARA, OnPara)
ON_COMMAND(ID_DELETE, OnDelete)
ON_COMMAND(ID_RENAME, OnRename)
//}}AFX_MSG_MAP
ON_MESSAGE(UM_END_WAIT,OnHandleEndWait)
ON_MESSAGE(UM_SHOW_PROMPT,OnShowPrompt)
ON_UPDATE_COMMAND_UI_RANGE(ID_FILE_MRU_FIRST, ID_FILE_MRU_LAST, OnUpdateFileMRU)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CSnaggerView construction/destruction
// Constructor
CSnaggerView::CSnaggerView()
{
m_pProgress = NULL;
m_pWait = NULL;
m_bSnagging = FALSE;
}
// Destructor
CSnaggerView::~CSnaggerView()
{
delete m_pProgress;
}
// Called to modify window creation characteristics
BOOL CSnaggerView::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return CView::PreCreateWindow(cs);
}
/////////////////////////////////////////////////////////////////////////////
// CSnaggerView drawing
// Draws the view -- not used
void CSnaggerView::OnDraw(CDC* pDC)
{
}
/////////////////////////////////////////////////////////////////////////////
// CSnaggerView diagnostics
#ifdef _DEBUG
void CSnaggerView::AssertValid() const
{
CView::AssertValid();
}
void CSnaggerView::Dump(CDumpContext& dc) const
{
CView::Dump(dc);
}
CSnaggerDoc* CSnaggerView::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CSnaggerDoc)));
return (CSnaggerDoc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CSnaggerView message handlers
// Called when a new view is created -- for SDI applications this is called
// multiple times. Therefore, we set a static flag and create the tree
// control the first time the view is initialized.
void CSnaggerView::OnInitialUpdate()
{
static BOOL bFirstTime = TRUE;
CView::OnInitialUpdate();
// Is this the first time?
if(bFirstTime)
{
// Yes, create the tree control
CRect rc;
GetClientRect(&rc);
m_Tree.Create(TVS_HASLINES|TVS_HASBUTTONS|TVS_LINESATROOT|WS_VISIBLE,
rc,this,IDC_TREE);
bFirstTime = FALSE;
// Cyan is the transparent color in this bitmap
m_ImageList.Create(IDB_TREE,16,1,RGB(0,128,128));
m_Tree.SetImageList(&m_ImageList,TVSIL_NORMAL);
// Create the child progress window too
CRect rcProg;
m_pProgress = new CProgress(this);
m_pProgress->GetClientRect(rcProg);
m_pProgress->MoveWindow(rc.left,rc.bottom-rcProg.Height(),
rc.Width(),rcProg.Height());
m_pProgress->ShowWindow(SW_SHOWNORMAL);
m_pProgress->UpdateWindow();
}
}
// Intializes the tree control by removing all of the items and adding
// TOC, Multimedia and page items based on the current option settings
void CSnaggerView::InitTree(CString& strSite)
{
CSnaggerDoc* pDoc = GetDocument();
// Initialize the tree
m_htreeRoot = m_htreeMedia = m_htreePages = 0;
m_Tree.DeleteAllItems();
// Add the main node types based on the options settings
m_htreeRoot = m_Tree.AddRootItem(strSite,0);
if(pDoc->GetOptions()->bContents)
m_htreeContents = m_Tree.AddChildItem("SiteSnagger Table of Contents",
m_htreeRoot,CTree::TOC_NODE);
if(pDoc->GetOptions()->bMultimedia)
m_htreeMedia = m_Tree.AddChildItem("Multimedia",m_htreeRoot,
CTree::MEDIA_NODE);
m_htreePages = m_Tree.AddChildItem("Pages",m_htreeRoot,
CTree::PAGES_NODE);
}
// Returns a list of all of the child items under the specified node. This
// is used during serialization
void CSnaggerView::GetChildren(HTREEITEM htreeParent, CStringArray& arrstrEntries)
{
int nIndex = 0;
// Empty the list
arrstrEntries.RemoveAll();
if(htreeParent == NULL) return;
// Iterate through the list of child items
HTREEITEM htreeItem = m_Tree.GetNextItem(htreeParent,TVGN_CHILD);
while(htreeItem)
{
arrstrEntries.Add(m_Tree.GetItemText(htreeItem));
htreeItem = m_Tree.GetNextSiblingItem(htreeItem);
nIndex++;
}
}
// Adds the list of child items to the specified node
void CSnaggerView::AddChildren(HTREEITEM htreeParent, CStringArray& arrstrEntries,
int nPageType)
{
if(htreeParent == NULL) return;
BOOL bPageAdjust = (nPageType == CTree::PAGE_NODE);
// Add each of the items to the tree
for(int i = 0; i < arrstrEntries.GetSize(); i++)
{
if(bPageAdjust)
{
if(arrstrEntries[i].Left(4) == "http")
nPageType = CTree::OFFSITE_PAGE_NODE;
else nPageType = CTree::PAGE_NODE;
}
else nPageType = CTree::GetMediaType(arrstrEntries[i]);
m_Tree.AddChildItem(arrstrEntries[i],htreeParent,nPageType);
}
}
// Removes everything from the tree control
void CSnaggerView::ClearTree()
{
if(::IsWindow(m_Tree.GetSafeHwnd()))
m_Tree.DeleteAllItems();
m_htreeRoot = NULL;
m_htreeContents = NULL;
m_htreeMedia = NULL;
m_htreePages = NULL;
}
// Handles storing or loading the contents of the tree control
void CSnaggerView::SerializeTree(CArchive& ar)
{
CString strSite;
CSnaggerDoc* pDoc = (CSnaggerDoc *) ar.m_pDocument;
CStringArray arrstrEntries;
// Storing??
if(ar.IsStoring())
{
// Get the site name
strSite = pDoc->GetStartPage();
ar << strSite;
// Contents
GetChildren(m_htreeContents,arrstrEntries);
arrstrEntries.Serialize(ar);
// Media
GetChildren(m_htreeMedia,arrstrEntries);
arrstrEntries.Serialize(ar);
// Pages
GetChildren(m_htreePages,arrstrEntries);
arrstrEntries.Serialize(ar);
}
else
{
// Get the site
ar >> strSite;
pDoc->SetStartPage(strSite);
// Initialize an empty tree
if(!strSite.IsEmpty())
InitTree(strSite);
// Contents
arrstrEntries.Serialize(ar);
AddChildren(m_htreeContents,arrstrEntries,CTree::TOC_PAGE_NODE);
// Media
arrstrEntries.Serialize(ar);
AddChildren(m_htreeMedia,arrstrEntries,CTree::IMAGE_NODE);
// Pages
arrstrEntries.Serialize(ar);
AddChildren(m_htreePages,arrstrEntries,CTree::PAGE_NODE);
}
}
// Adds media to the tree
HTREEITEM CSnaggerView::AddTreeMedia(CString strMedia, int nMediaType)
{
return m_Tree.AddChildItem(strMedia,m_htreeMedia,nMediaType);
}
// Adds a page to the tree
HTREEITEM CSnaggerView::AddTreePage(CString& strPage, BOOL bOffsite)
{
int nPageType = bOffsite?CTree::OFFSITE_PAGE_NODE:
CTree::PAGE_NODE;
return m_Tree.AddChildItem(strPage,m_htreePages,nPageType);
}
// Adds a TOC page to the tree
HTREEITEM CSnaggerView::AddTreeContent(CString& strPage)
{
return m_Tree.AddChildItem(strPage,m_htreeContents,CTree::TOC_PAGE_NODE);
}
// Displays the please wait message box
// Handles the please wait termination message
LONG CSnaggerView::OnHandleEndWait(WPARAM,LPARAM)
{
if(m_pWait)
{
m_pWait->DestroyWindow();
delete m_pWait;
m_pWait = NULL;
}
return(0L);
}
// Ends the please wait message by posting a message -- this is done because
// the please wait message is ended from another thread so we can't call the
// DestroyWindow() directly
void CSnaggerView::EndWait()
{
SendMessage(UM_END_WAIT);
}
// Handles resize of the view -- also resizes the child statistics window
void CSnaggerView::OnSize(UINT nType, int cx, int cy)
{
CView::OnSize(nType, cx, cy);
CRect rcProg, rc;
// Is the stats window there yet??
if(m_pProgress)
{
// Yep...resize it and the tree control
m_pProgress->GetWindowRect(rcProg);
m_pProgress->MoveWindow(0,cy-rcProg.Height(),cx,rcProg.Height());
m_Tree.MoveWindow(0,0,cx,cy-rcProg.Height());
}
}
// Handles the double-click message for the tree control -- invokes the appropriate
// handler based on the object type
void CSnaggerView::OnDblclkTree(NMHDR* pNMHDR, LRESULT* pResult)
{
// Get the URL and open it in the web browser
CPoint pt;
UINT uFlags = TVHT_ONITEMLABEL;
CString strText;
GetCursorPos(&pt);
m_Tree.ScreenToClient(&pt);
HTREEITEM htreeItem = m_Tree.HitTest(pt,&uFlags);
// Make sure it's not just a category entry that the user clicked on
if(htreeItem && htreeItem != m_htreeRoot && htreeItem != m_htreeContents &&
htreeItem != m_htreeMedia && htreeItem != m_htreePages)
{
// It's a valid file so get its name
strText = m_Tree.GetItemText(htreeItem);
int nIndex = strText.ReverseFind('(');
if(nIndex >= 0)
{
strText = strText.Mid(nIndex+1);
strText = strText.Left(strText.GetLength()-1);
}
CSnaggerDoc *pDoc = GetDocument();
// Don't pre-pend the path for an EMAIL entry
if(strText.Left(7) != "mailto:")
strText = pDoc->GetDirectory()+strText;
// Let the shell invoke the proper handler for this file
ShellExecute(NULL,"open",strText,NULL,NULL,SW_SHOWNORMAL);
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -