?? visualfx.cpp
字號:
ResizeTab();
return 0;
}
// Handle resize
void TTabWnd::OnSize(UINT nType, int cx, int cy)
{
CWnd::OnSize(nType, cx, cy);
ResizeTab(cx,cy);
}
// Create a CView derived class as a tab
TTabItem *TTabWnd::CreatePane(LPCTSTR lpszLabel, CRuntimeClass *pViewClass,
CCreateContext *pContext)
{
CRect rect, client;
ASSERT(pViewClass && pContext);
CWnd *pWnd = (CWnd*)pViewClass->CreateObject();
if (!pWnd)
return NULL;
GetClientRect(&client);
rect.left = 0;
rect.top = TABWND_HEIGHT+2;
rect.right = client.right;
rect.bottom = client.bottom;
int dwStyle = AFX_WS_DEFAULT_VIEW;
if (GetParent()->IsKindOf(RUNTIME_CLASS(CSplitterWnd))) {
dwStyle &= ~WS_BORDER;
}
if (!pWnd->Create(NULL, NULL, dwStyle, rect, this, 13576+m_TabList.size(), pContext))
{
TRACE0("Warning: couldn't create client area for tab view\n");
// pWnd will be cleaned up by PostNcDestroy
return NULL;
}
// Insert new tab object into the list
TTabItem *pTab = addTab(pWnd,lpszLabel);
ASSERT(pTab);
if (m_TabList.size() != 1) {
pWnd->EnableWindow(FALSE);
pWnd->ShowWindow(SW_HIDE);
/*
// Framework is responsible to set the active view
} else {
CWnd *pParent = GetParent();
if (pParent->IsKindOf(RUNTIME_CLASS(CFrameWnd))) {
((CFrameWnd*)pParent)->SetActiveView((CView*)pWnd);
} else if (pParent->IsKindOf(RUNTIME_CLASS(CSplitterWnd))) {
((CSplitterWnd*)pParent)->SetActivePane(0,0,pWnd);
}
*/
}
return pTab;
}
// Create a splitter window as a tab
TTabItem *TTabWnd::CreatePane(LPCTSTR lpszLabel, int nRows, int nCols,
CWnd *pWnd, UINT nID)
{
ASSERT(pWnd);
ASSERT(pWnd->IsKindOf(RUNTIME_CLASS(CSplitterWnd)));
// Moved to TVisualFramework to handle creation of CSplitterWnd derived classes
//CSplitterWnd *pWnd = new CSplitterWnd;
//if (!pWnd)
// return NULL;
int dwStyle = AFX_WS_DEFAULT_VIEW;
dwStyle &= ~WS_BORDER;
CSplitterWnd *pSplitter = (CSplitterWnd*)pWnd;
if (!pSplitter->CreateStatic(this, nRows, nCols, dwStyle, nID)) {
TRACE0("Warning: couldn't create client area for tab view\n");
// pWnd will be cleaned up by PostNcDestroy
return NULL;
}
TTabItem *pTab = addTab(pWnd,lpszLabel);
ASSERT(pTab);
if (m_TabList.size() != 1) {
pWnd->EnableWindow(FALSE);
pWnd->ShowWindow(SW_HIDE);
}
/*
// Framework will set the active view
CWnd *paneWnd = pWnd->GetActivePane();
if (paneWnd) {
((CFrameWnd*)GetParent())->SetActiveView((CView*)paneWnd);
} else {
paneWnd = pWnd->GetPane(0,0);
pWnd->SetActivePane(0,0);
((CFrameWnd*)GetParent())->SetActiveView((CView*)paneWnd);
}
*/
return pTab;
}
//=============================================================================
// class TVisualObject
//
//=============================================================================
// Private constructor
TVisualObject::TVisualObject()
{
}
// Create a plain view
TVisualObject::TVisualObject(DWORD dwId, CCreateContext *pContext,
CRuntimeClass *pClass)
{
ASSERT(pContext);
ASSERT(pClass);
ASSERT(pClass->IsDerivedFrom(RUNTIME_CLASS(CView)));
zeroAll();
m_dwId = dwId;
m_nObjectType = OT_VIEW;
m_pContext = pContext;
m_pRuntimeClass = pClass;
checkStyle();
}
// Create a view within a tab window or a tab window
TVisualObject::TVisualObject(DWORD dwId, LPCTSTR szTitle, CCreateContext *pContext,
CRuntimeClass *pClass, DWORD dwStyle)
{
ASSERT(szTitle);
ASSERT(pContext);
ASSERT(pClass);
zeroAll();
m_dwId = dwId;
if (pClass->IsDerivedFrom(RUNTIME_CLASS(TTabWnd))) {
m_nObjectType = OT_TAB;
} else if (pClass->IsDerivedFrom(RUNTIME_CLASS(CView))) {
m_nObjectType = OT_TABVIEW;
} else {
ASSERT(FALSE);
}
m_strTitle = szTitle;
m_pContext = pContext;
m_pRuntimeClass = pClass;
m_dwStyle = dwStyle;
checkStyle();
}
// Create a splitter window
TVisualObject::TVisualObject(DWORD dwId, LPCTSTR szTitle, int nRows, int nCols,
CCreateContext *pContext, DWORD dwStyle)
{
ASSERT(szTitle);
ASSERT(pContext);
ASSERT(nRows);
ASSERT(nCols);
zeroAll();
m_dwId = dwId;
m_nObjectType = OT_SPLITTER;
m_strTitle = szTitle;
m_pContext = pContext;
m_nRows = nRows;
m_nCols = nCols;
m_dwStyle = dwStyle;
checkStyle();
}
// Create a view within a splitter window
TVisualObject::TVisualObject(DWORD dwId, int nRow, int nCol, CCreateContext *pContext,
CRuntimeClass *pClass, CSize size, DWORD dwStyle)
{
ASSERT(pContext);
ASSERT(pClass);
ASSERT(pClass->IsDerivedFrom(RUNTIME_CLASS(CView)) ||
pClass->IsDerivedFrom(RUNTIME_CLASS(TTabWnd)));
zeroAll();
m_dwId = dwId;
m_nObjectType = OT_SPLITTERVIEW;
m_pContext = pContext;
m_pRuntimeClass = pClass;
m_nRowIndex = nRow;
m_nColIndex = nCol;
m_Size = size;
m_dwStyle = dwStyle;
checkStyle();
}
// Create a splitter within a splitter window
TVisualObject::TVisualObject(DWORD dwId, int nRow, int nCol, int nRows, int nCols,
CCreateContext *pContext, DWORD dwStyle)
{
ASSERT(pContext);
ASSERT(nRows);
ASSERT(nCols);
zeroAll();
m_dwId = dwId;
m_nObjectType = OT_SPLITTERSPLITTER;
m_pContext = pContext;
m_nRowIndex = nRow;
m_nColIndex = nCol;
m_nRows = nRows;
m_nCols = nCols;
m_dwStyle = dwStyle;
checkStyle();
}
TVisualObject::TVisualObject(const TVisualObject& obj)
{
zeroAll();
*this = obj;
}
TVisualObject::~TVisualObject()
{
if (m_hIcon) {
::DestroyIcon(m_hIcon);
m_hIcon = NULL;
}
}
TVisualObject& TVisualObject::operator=(const TVisualObject& obj)
{
// No need to copy m_ObjectList since it is populated after
// this code is executed in STL container
m_nObjectType = obj.m_nObjectType;
m_dwId = obj.m_dwId;
m_pWnd = obj.m_pWnd;
m_pParent = obj.m_pParent;
m_strTitle = obj.m_strTitle;
m_nRows = obj.m_nRows;
m_nCols = obj.m_nCols;
m_nRowIndex = obj.m_nRowIndex;
m_nColIndex = obj.m_nColIndex;
m_pContext = obj.m_pContext;
m_pRuntimeClass = obj.m_pRuntimeClass;
m_Size = obj.m_Size;
m_bEnabled = obj.m_bEnabled;
m_dwStyle = obj.m_dwStyle;
m_cHotKey = obj.m_cHotKey;
m_hIcon = obj.m_hIcon;
m_pOwner = obj.m_pOwner;
m_pFramework = obj.m_pFramework;
return *this;
}
void TVisualObject::zeroAll(void)
{
// No need to zero m_ObjectList since it is already empty
m_nObjectType = OT_UNKNOWN;
m_dwId = 0;
m_pWnd = NULL;
m_pParent = NULL;
m_strTitle = _T("");
m_nRows = 0;
m_nCols = 0;
m_nRowIndex = 0;
m_nColIndex = 0;
m_pContext = NULL;
m_pRuntimeClass = NULL;
m_Size = CSize(0,0);
m_bEnabled = TRUE;
m_dwStyle = 0;
m_cHotKey = 0;
m_pOwner = NULL;
m_pFramework = NULL;
m_hIcon = NULL;
}
// Check if style is valid
void TVisualObject::checkStyle(void)
{
if ((m_dwStyle & TOS_TABTOP) || (m_dwStyle & TOS_TABBOTTOM)) {
ASSERT(m_pRuntimeClass);
// Tab position valid only for tab window derived classes
ASSERT(m_pRuntimeClass->IsDerivedFrom(RUNTIME_CLASS(TTabWnd)));
}
if (m_dwStyle & TOS_SELECTED) {
// Selected valid only for tab panes that are not splitters and tabs
// In this case, use TVisualFramework::SetActivePane() to set the active pane
// once the framework is created
if (m_pRuntimeClass == NULL) {
// Splitters canot be dynamically create (m_pRuntimeClass is NULL)
ASSERT((m_nObjectType != OT_SPLITTER) && (m_nObjectType != OT_SPLITTERVIEW));
} else {
ASSERT(!m_pRuntimeClass->IsDerivedFrom(RUNTIME_CLASS(TTabWnd)));
}
}
}
// Delete the window pointer and optionally destroy the window
void TVisualObject::Destroy(BOOL bDestroyWindow)
{
if (m_pWnd) {
if (bDestroyWindow)
m_pWnd->DestroyWindow();
delete m_pWnd;
m_pWnd = NULL;
}
}
// If this object is a tab window or splitter window that it
// cannot be focused
BOOL TVisualObject::CanFocus(void)
{
ASSERT(m_pWnd);
if (m_pWnd->IsKindOf(RUNTIME_CLASS(CSplitterWnd)) ||
m_pWnd->IsKindOf(RUNTIME_CLASS(TTabWnd)))
{
return FALSE;
}
return TRUE;
}
// Set hot key for this tab object
void TVisualObject::SetHotKey(CHAR cHotKey)
{
m_cHotKey = cHotKey;
}
// Optional: Set description
void TVisualObject::SetDescription(LPCTSTR szDesc)
{
m_strDescription = szDesc;
}
// Optional: Set icon for tab and load it from the resource
BOOL TVisualObject::SetIcon(UINT nIconId)
{
// Cannot specify icon if already specified
// if (m_hIcon)
// return FALSE;
// Load icon if possible
if (nIconId == 0) {
m_hIcon = NULL;
} else {
m_hIcon = (HICON)::LoadImage(::AfxGetResourceHandle(),
MAKEINTRESOURCE(nIconId),
IMAGE_ICON, 16, 16, LR_DEFAULTCOLOR);
if (m_hIcon == NULL)
return FALSE;
}
return TRUE;
}
// Optional: Return icon handle for tab
HICON TVisualObject::GetIcon(void)
{
return m_hIcon;
}
// Set this object as active pane
BOOL TVisualObject::SetActivePane(void)
{
ASSERT(m_pFramework);
return m_pFramework->SetActivePane(this);
}
// Set this tab to be active tab (not the active pane)
BOOL TVisualObject::SetActiveTab(void)
{
ASSERT(m_pFramework);
return m_pFramework->SetActiveTab(this);
}
// Enable/disable this object
BOOL TVisualObject::Enable(BOOL bEnable)
{
ASSERT(m_pFramework);
return m_pFramework->Enable(this,bEnable);
}
// Enable/disable tab
BOOL TVisualObject::EnableTab(BOOL bEnable)
{
ASSERT(m_pFramework);
return m_pFramework->EnableTab(this,bEnable);
}
// SHow/hide this object
BOOL TVisualObject::ShowTab(BOOL bShow)
{
ASSERT(m_pFramework);
return m_pFramework->ShowTab(this,bShow);
}
// Is this object enabled
BOOL TVisualObject::IsEnabled(BOOL& bEnabled)
{
ASSERT(m_pFramework);
return m_pFramework->IsEnabled(this,bEnabled);
}
// Is this object enabled
BOOL TVisualObject::IsTabEnabled(BOOL& bEnabled)
{
ASSERT(m_pFramework);
return m_pFramework->IsTabEnabled(this,bEnabled);
}
// Is this object visible
BOOL TVisualObject::IsTabVisible(BOOL& bVisible)
{
ASSERT(m_pFramework);
return m_pFramework->IsTabVisible(this,bVisible);
}
// Returns TRUE if this object is a tab within a tab window
BOOL TVisualObject::IsTabPane(void)
{
ASSERT(m_pFramework);
return m_pFramework->IsTabPane(this);
}
// Returns TRUE if this object is a tab window
BOOL TVisualObject::IsTabWindow(void)
{
ASSERT(m_pFramework);
return m_pFramework->IsTabWindow(this);
}
// Returns TRUE if this object is a pane within a splitter window
BOOL TVisualObject::IsSplitterPane(void)
{
ASSERT(m_pFramework);
return m_pFramework->IsSplitterPane(this);
}
// Returns TRUE if this object is a splitter window
BOOL TVisualObject::IsSplitterWindow(void)
{
ASSERT(m_pFramework);
return m_pFramework->IsSplitterWindow(this);
}
// Returns TRUE if this object is derived from CView
BOOL TVisualObject::IsView(void)
{
ASSERT(m_pFramework);
return m_pFramework->IsView(this);
}
// Get object ID
#ifdef _DEBUG
DWORD TVisualObject::GetID(void)
{
return m_dwId;
}
#endif
// Get object window
#ifdef _DEBUG
CWnd *TVisualObject::GetWnd(void)
{
return m_pWnd;
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -