📄 viewmanager.cpp
字号:
// VViewManager.cpp : implementation file
//
#include "stdafx.h"
#include "resource.h" // main symbols
#include "ViewManager.h"
//#include "PopupMenu.h"
#include "MainFrm.h"
#include "benbenBrowserDoc.h"
#include "benbenBrowserView.h"
#include "generaldata.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
#define ID_VIEWTAB 1005
#define ID_DEFDOCTIPS _T("A new unsaved file")
#define ID_DEFCAPTION _T("Open File Tabs Bar")
#define ID_TABHEIGHT 26
//
// This function adds a title entry to a popup menu
//
void AddMenuTitle(CMenu* popup, LPCSTR title)
{
// insert a separator item at the top
popup->InsertMenu(0, MF_BYPOSITION | MF_SEPARATOR, 0, title);
// insert title item
// note: item is not selectable (disabled) but not grayed
popup->InsertMenu(0, MF_BYPOSITION | MF_STRING | MF_DISABLED, 0, title);
SetMenuDefaultItem(popup->m_hMenu, 0, TRUE);
}
/////////////////////////////////////////////////////////////////////////////
// CVViewManager
IMPLEMENT_DYNAMIC(CViewManager, CControlBar)
CViewManager::CViewManager()
{
m_bClosing = FALSE;
m_nLMargin = 10;
m_nDockID = 0;
m_bWin2000 = TRUE;
m_beAddLast = TRUE;
}
CViewManager::~CViewManager()
{
m_arViews.RemoveAll();
m_arViewTitles.RemoveAll();
}
BEGIN_MESSAGE_MAP(CViewManager, CControlBar)
//{{AFX_MSG_MAP(CViewManager)
ON_WM_SIZE()
ON_WM_CREATE()
ON_WM_RBUTTONDOWN()
ON_WM_WINDOWPOSCHANGING()
ON_WM_WINDOWPOSCHANGED()
//}}AFX_MSG_MAP
ON_NOTIFY(TTN_NEEDTEXT, 0, OnViewManagerToolTip)
END_MESSAGE_MAP()
void CViewManager::OnUpdateCmdUI(CFrameWnd* pTarget, BOOL bDisableIfNoHndler)
{
try
{
CMDIFrameWnd* pFrame = static_cast<CMDIFrameWnd *>(AfxGetApp()->m_pMainWnd);
if (pFrame == NULL)
return; // this is not meant for us...
// Get the active MDI child window.
CMDIChildWnd* pChild = static_cast<CMDIChildWnd *>(pFrame->GetActiveFrame());
// Get the active view attached to the active MDI child window.
CView* pActiveView = reinterpret_cast<CView *>(pChild->GetActiveView());
if (pActiveView == NULL) //...Is there a view anyway?
{
//...since there is no view hide the tab control, otherwise it looks...guess!
m_ViewTabCtrl.ShowWindow(SW_HIDE);
return;
}
else
{
//...we might have hidden the tab control, show it now
if (!m_ViewTabCtrl.IsWindowVisible())
m_ViewTabCtrl.ShowWindow(SW_SHOW);
}
// Now, we go...
int iSel = -1;
// CString strWin;
// CMainFrame * mainfrm=(CMainFrame * )pFrame;
for (int t = 0; t < m_arViewTitles.GetSize(); t++)
{
CView* pViewAt = static_cast<CView *>(m_arViews.GetAt(t));
ASSERT(pViewAt!=NULL);
// pViewAt->GetParent()->GetWindowText(strWin);
// CFrameWnd * wnd=pViewAt->GetParentFrame();
//benben start
//CString URL;
{
//CBenbenBrowserView *htmlview=(CBenbenBrowserView *) pViewAt;
//if(htmlview->IsPopupWin())
// {
//URL= htmlview->GetLocationURL();
// strWin=htmlview->GetLocationName();
// if(mainfrm->m_lockURLlist.Find(URL)&&wnd)//close the window in the lock list
// {
// ::SendMessage(wnd->m_hWnd,WM_CLOSE,0,0);
// continue;
// }
// }
//if(strWin2!=strWin)// set the title of the window
// wnd->SetWindowText(strWin2);
}
//benben end
// ...if there is window title change since the last update set the new title
//if (strWin != m_arViewTitles.GetAt(t))
// SetViewName(strWin, pViewAt);
// ...find the active view from the view list
if (pActiveView == static_cast<CView *>(m_arViews.GetAt(t)))
iSel = t;
}
m_ViewTabCtrl.SetCurSel(iSel); // set the tab for the active view
}
catch(...)
{
MessageBox("error");
}
// Be polite! update the dialog controls added to the CSizingControlBar
UpdateDialogControls(pTarget, bDisableIfNoHndler);
}
////////////////////////////////////////////////////////////////////////////
// CViewManager operations
void CViewManager::AddView(const TCHAR* csName, CView* pView)
{
if (m_bClosing)
return;
CString cs(csName);
int index=m_ViewTabCtrl.GetCurSel();
if(index==-1||m_beAddLast)
index=m_ViewTabCtrl.GetItemCount();
else
index++;
m_arViews.InsertAt(index,pView);
m_arViewTitles.InsertAt(index,cs);
if (m_ViewTabCtrl.GetSafeHwnd())
{
TCITEM tci;
tci.mask = TCIF_TEXT | TCIF_PARAM | TCIF_IMAGE;
tci.pszText = cs.LockBuffer();
tci.lParam = reinterpret_cast<LPARAM>(pView);
tci.iImage = 0; //TODO
m_ViewTabCtrl.InsertItem(index, &tci);
cs.UnlockBuffer();
}
//benben 11/2002
CToolTipCtrl *pTT=m_ViewTabCtrl.GetToolTips();
for(int i=m_ViewTabCtrl.GetItemCount()-1;i>index;i--)
{
pTT->UpdateTipText(m_arViewTitles.GetAt(i),&m_ViewTabCtrl,i);
}
//end benben
}
void CViewManager::RemoveView(CView* pView)
{
try
{
if (m_bClosing || m_arViews.GetSize() <= 0)
return;
int nTabs;
if (m_ViewTabCtrl.GetSafeHwnd())
{
for (nTabs = 0; nTabs < m_ViewTabCtrl.GetItemCount(); nTabs++)
{
TCITEM tci;
tci.mask = TCIF_PARAM;
m_ViewTabCtrl.GetItem(nTabs, &tci);
if (tci.lParam == reinterpret_cast<LPARAM>(pView))
{
m_ViewTabCtrl.DeleteItem(nTabs);
break;
}
}
}
for (nTabs = 0; nTabs < m_arViews.GetSize(); nTabs++)
{
if (static_cast<CView *>(m_arViews.GetAt(nTabs)) == pView)
{
m_arViewTitles.RemoveAt(nTabs);
m_arViews.RemoveAt(nTabs);
return;
}
}
}
catch(...)
{
}
}
void CViewManager::RemoveAll()
{
m_arViews.RemoveAll();
m_arViewTitles.RemoveAll();
}
void CViewManager::SetViewName(const TCHAR* cs, CView* pView)
{
if (m_bClosing || m_arViews.GetSize() <= 0)
return;
int nTabs;
CString csName(cs);
CString csName2=csName;
if(csName2.GetLength()>24)
csName2=csName2.Left(20)+"...";
if (m_ViewTabCtrl.GetSafeHwnd())
{
for (nTabs = 0; nTabs < m_ViewTabCtrl.GetItemCount(); nTabs++)
{
TCITEM tci;
tci.mask = TCIF_PARAM;
m_ViewTabCtrl.GetItem(nTabs, &tci);
if (tci.lParam == reinterpret_cast<LPARAM>(pView))
{
tci.mask = TCIF_PARAM | TCIF_TEXT;
tci.pszText = csName2.LockBuffer();
m_ViewTabCtrl.SetItem(nTabs, &tci);
csName2.UnlockBuffer();
m_ViewTabCtrl.Invalidate();
m_ViewTabCtrl.GetToolTips()->UpdateTipText(csName,&m_ViewTabCtrl,nTabs);
break;
}
}
}
for (nTabs = 0; nTabs < m_arViews.GetSize(); nTabs++)
{
if (static_cast<CView *>(m_arViews.GetAt(nTabs)) == pView)
{
m_arViewTitles.SetAt(nTabs, csName);
return;
}
}
}
int CViewManager::GetWindowNum()
{
return m_arViews.GetSize();
}
void CViewManager::OnActivateView(const BOOL bActivate, CView* pView)
{
if (bActivate)
{
if (m_ViewTabCtrl.GetSafeHwnd())
{
for (int nTabs = 0; nTabs < m_ViewTabCtrl.GetItemCount(); nTabs++)
{
TCITEM tci;
tci.mask = TCIF_PARAM;
m_ViewTabCtrl.GetItem(nTabs, &tci);
if (tci.lParam == reinterpret_cast<LPARAM>(pView))
{
m_ViewTabCtrl.SetCurSel(nTabs);
m_ViewTabCtrl.Invalidate();
break;
}
}
}
}
}
/////////////////////////////////////////////////////////////////////////////
// CViewManager message handlers
void CViewManager::OnSize(UINT nType, int cx, int cy)
{
CControlBar::OnSize(nType, cx, cy);
try
{
CRect rect, rcClient;
if (m_ViewTabCtrl.GetSafeHwnd())
{
DWORD dwStyle = m_ViewTabCtrl.GetStyle();
if (dwStyle & TCS_BOTTOM)
{
GetClientRect(rect);
GetClientRect(rcClient);
int nxOffset = GetSystemMetrics(SM_CXSIZEFRAME);
m_ViewTabCtrl.SetWindowPos(&wndTop, rcClient.left + nxOffset + m_nLMargin,
rcClient.top, rect.Width() - nxOffset * 5 - m_nLMargin,
ID_TABHEIGHT, SWP_SHOWWINDOW);
m_sizeMRU = CSize(cx, cy);
}
else
{
GetClientRect(rect);
int nxOffset = GetSystemMetrics(SM_CXSIZEFRAME);
m_ViewTabCtrl.SetWindowPos(&wndTop, nxOffset + m_nLMargin, 3,
rect.Width() - nxOffset * 5 - m_nLMargin, ID_TABHEIGHT, SWP_SHOWWINDOW);
m_sizeMRU = CSize(cx, cy);
}
}
}
catch(...)
{
}
}
int CViewManager::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CControlBar::OnCreate(lpCreateStruct) == -1)
return -1;
m_ViewTabImages.Create(16, 16,ILC_COLOR8|ILC_MASK, 5, 5);
m_ViewTabCtrl.Create(WS_CHILD | WS_VISIBLE | WS_EX_NOPARENTNOTIFY |
// pLaY with this!
TCS_TOOLTIPS | TCS_SINGLELINE | TCS_FOCUSNEVER | TCS_FORCELABELLEFT,
CRect(0, 0, 0, 0), this, ID_VIEWTAB);
TabCtrl_SetExtendedStyle(m_ViewTabCtrl.m_hWnd, TCS_EX_FLATSEPARATORS);
m_ViewTabCtrl.SetImageList(&m_ViewTabImages);
// Build the image list here
HICON hIcon = AfxGetApp()->LoadStandardIcon(IDI_APPLICATION);
// HICON hIcon = AfxGetApp()->LoadIcon(IDR_DEMOTYPE);
m_ViewTabImages.Add(hIcon);
// Enable tooltips for all controls
EnableToolTips(TRUE);
return 0;
}
void CViewManager::OnRButtonDown(UINT nFlags, CPoint point)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -