📄 viewmanager.cpp
字号:
// VViewManager.cpp : implementation file
//
#include "stdafx.h"
#include "resource.h" // main symbols
#include "ViewManager.h"
#include "PopupMenu.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
/////////////////////////////////////////////////////////////////////////////
// CVViewManager
IMPLEMENT_DYNAMIC(CViewManager, CControlBar)
CViewManager::CViewManager()
{
m_bClosing = FALSE;
m_nLMargin = 10;
m_nDockID = 0;
}
CViewManager::~CViewManager()
{
m_arViews.RemoveAll();
m_arViewTitles.RemoveAll();
}
BEGIN_MESSAGE_MAP(CViewManager, CControlBar)
ON_NOTIFY_EX(TTN_NEEDTEXT, 0, OnViewManagerToolTip)
//{{AFX_MSG_MAP(CViewManager)
ON_WM_SIZE()
ON_WM_CREATE()
ON_WM_RBUTTONDOWN()
ON_WM_WINDOWPOSCHANGING()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
void CViewManager::OnUpdateCmdUI(CFrameWnd* pTarget, BOOL bDisableIfNoHndler)
{
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 DocPathFileName;
for (int t = 0; t < m_arViewTitles.GetSize(); t++)
{
CView* pViewAt = static_cast<CView *>(m_arViews.GetAt(t));
pViewAt -> GetParent() -> GetWindowText( DocPathFileName );
// ...if there is window title change since the last update set the new title
if (DocPathFileName != m_arViewTitles.GetAt(t)){
CutDocFileName( DocPathFileName );
SetViewName( DocPathFileName, 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
// Be polite! update the dialog controls added to the CSizingControlBar
UpdateDialogControls(pTarget, bDisableIfNoHndler);
}
void CViewManager::CutDocFileName(CString& DocPathFileName)
{
int strLen = DocPathFileName.GetLength( );
char ch;
int strnum = 0;
CString fileName;
for(int i = strLen - 1; i >= 0 && DocPathFileName.GetAt(i) != '\\'; i--){ strnum++; }
for( int j = 0; j < strnum ; j++)
{
ch = DocPathFileName.GetAt( i + j + 1 );
DocPathFileName.SetAt(j, ch);
}
for( j = strnum ; j < strLen; j++)
{
DocPathFileName.SetAt(strnum, '\0');
}
DocPathFileName.TrimRight(".dwg");
}
////////////////////////////////////////////////////////////////////////////
// CViewManager operations
void CViewManager::AddView(const TCHAR* csName, CView* pView)
{
if (m_bClosing)
return;
CString cs(csName);
m_arViews.Add(pView);
m_arViewTitles.Add(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(m_ViewTabCtrl.GetItemCount(), &tci);
cs.UnlockBuffer();
}
}
void CViewManager::RemoveView(CView* pView)
{
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;
}
}
}
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);
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 = csName.LockBuffer();
m_ViewTabCtrl.SetItem(nTabs, &tci);
csName.UnlockBuffer();
m_ViewTabCtrl.Invalidate();
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);
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);
}
}
}
int CViewManager::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CControlBar::OnCreate(lpCreateStruct) == -1)
return -1;
m_ViewTabImages.Create(16, 16, ILC_MASK, 5, 5);
m_ViewTabCtrl.Create(WS_CHILD | WS_VISIBLE | WS_EX_NOPARENTNOTIFY |
// TCS_BUTTONS | TCS_FLATBUTTONS | // pLaY with this!
TCS_TOOLTIPS | TCS_SINGLELINE | TCS_FOCUSNEVER | TCS_FORCELABELLEFT,
CRect(0, 0, 0, 0), this, ID_VIEWTAB);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -