📄 splitterwndex.cpp
字号:
}
else if (m_eDirection == Vertical)
{
ASSERT((ePane == Left || ePane == Right));
if (ePane == Left)
iIndex = 0;
else
iIndex = 1;
}
// Make sure the index is valid
if (uiViewIndex >= (UINT)m_listViews[iIndex].size())
return FALSE;
// Switch the view
CWnd *pWnd = m_listViews[iIndex][uiViewIndex];
int iRow, iCol;
PaneToRowCol(ePane, iRow, iCol);
if (!HideView(iRow, iCol) || !ShowView(iRow, iCol, pWnd))
return FALSE;
RecalcLayout();
RedrawWindow();
return TRUE;
}
//----------------------------------------------------------------------------
//
// Function: CSplitterWndEx::Split
//
// Description: Splits a window horizontally or vertically
//
// Scope: public
//
// Parameters:
// [in] ESplitPane ePane Pane to split
// [in] CCreateContext *pContext Pointer to the context in which to
// create the window
// [in] ESplitDirection eDirection Direction to split the window
//
// Return Values:
// CSplitterWndEx * A pointer to the newly created splitter on success
// or NULL on failure
//
// Remarks:
// If the window is split horizontally, the split pane must be Top or
// Bottom. If split vertically, the pane must be Left or Right.
//
// If the window is already split, a pointer to the existing splitter is
// returned instead.
//
//----------------------------------------------------------------------------
CSplitterWndEx *CSplitterWndEx::Split(ESplitPane ePane,
CCreateContext *pContext, ESplitDirection eDirection)
{
// Make sure a proper pane was passed
int iIndex = -1;
if (m_eDirection == Horizontal)
{
ASSERT((ePane == Top || ePane == Bottom));
if (ePane == Top)
iIndex = 0;
else
iIndex = 1;
}
else if (m_eDirection == Vertical)
{
ASSERT((ePane == Left || ePane == Right));
if (ePane == Left)
iIndex = 0;
else
iIndex = 1;
}
// If the pane is already split, just return the existing pointer
if (m_pSubSplitter[iIndex] != NULL)
return m_pSubSplitter[iIndex];
// Get the ID for the pane
int iRow, iCol;
PaneToRowCol(ePane, iRow, iCol);
int iID = IdFromRowCol(iRow, iCol);
// Create the new splitter
m_pSubSplitter[iIndex] = new CSplitterWndEx();
m_pSubSplitter[iIndex]->Create(this, pContext, eDirection , iID);
return m_pSubSplitter[iIndex];
}
//----------------------------------------------------------------------------
//
// Function: CSplitterWndEx::PaneToRowCol
//
// Description: Finds the row and column of the specified pane
//
// Scope: protected
//
// Parameters:
// [in] ESplitPane ePane Pane to get row/col info for
// [in/out] int& iRow Row number
// [in/out] int& iCol Column number
//
// Return Values:
// None
//
// Remarks:
// If the window is split horizontally, the split pane must be Top or
// Bottom. If split vertically, the pane must be Left or Right.
//
//----------------------------------------------------------------------------
void CSplitterWndEx::PaneToRowCol(ESplitPane ePane, int& iRow, int& iCol)
{
if (m_eDirection == Horizontal)
{
ASSERT((ePane == Top || ePane == Bottom));
if (ePane == Top)
{
iRow = 0;
iCol = 0;
}
else
{
iRow = 1;
iCol = 0;
}
}
else if (m_eDirection == Vertical)
{
ASSERT((ePane == Left || ePane == Right));
if (ePane == Left)
{
iRow = 0;
iCol = 0;
}
else
{
iRow = 0;
iCol = 1;
}
}
}
//----------------------------------------------------------------------------
//
// Function: CSplitterWndEx::HideView
//
// Description: Hides the view on a pane; Used by SwitchView() function
//
// Scope: protected
//
// Parameters:
// [in] int iRow Row number of pane
// [in] int iCol Column number of pane
//
// Return Values:
// BOOL TRUE on success or FALSE on failure
//
// Remarks:
// None
//
//----------------------------------------------------------------------------
BOOL CSplitterWndEx::HideView(int iRow, int iCol)
{
CWnd *pWnd = GetPane(iRow, iCol);
if (pWnd == NULL)
return FALSE;
pWnd->SetDlgCtrlID(0);
pWnd->ShowWindow(SW_HIDE);
return TRUE;
}
//----------------------------------------------------------------------------
//
// Function: CSplitterWndEx::ShowView
//
// Description: Shows the view on a pane; Used by SwitchView() function
//
// Scope: protected
//
// Parameters:
// [in] int iRow Row number of pane
// [in] int iCol Column number of pane
// [in] CWnd *pWnd Pointer to the view to show
//
// Return Values:
// BOOL TRUE on success or FALSE on failure
//
// Remarks:
// None
//
//----------------------------------------------------------------------------
BOOL CSplitterWndEx::ShowView(int iRow, int iCol, CWnd *pWnd)
{
if (pWnd == NULL)
return FALSE;
pWnd->SetDlgCtrlID(IdFromRowCol(iRow, iCol));
pWnd->ShowWindow(SW_SHOW);
return TRUE;
}
//----------------------------------------------------------------------------
//
// Function: CSplitterWndEx::ShowPane
//
// Description: Shows a pane; Used by ShowPane() public function
//
// Scope: protected
//
// Parameters:
// [in] ESplitPane ePane Pane to show
//
// Return Values:
// None
//
// Remarks:
// If the window is split horizontally, the split pane must be Top or
// Bottom. If split vertically, the pane must be Left or Right.
//
//----------------------------------------------------------------------------
void CSplitterWndEx::ShowPane(ESplitPane ePane)
{
// Make sure a proper pane was passed
int iIndex, iOuterMax, iInnerStart;
if (m_eDirection == Horizontal)
{
ASSERT((ePane == Top || ePane == Bottom));
if (ePane == Top)
iIndex = 0;
else
iIndex = 1;
m_nRows++;
iOuterMax = m_nCols;
iInnerStart = m_nRows - 2;
}
else if (m_eDirection == Vertical)
{
ASSERT((ePane == Left || ePane == Right));
if (ePane == Left)
iIndex = 0;
else
iIndex = 1;
m_nCols++;
iOuterMax = m_nRows;
iInnerStart = m_nCols - 2;
}
// Show the row/column
for (int i = 0; i < iOuterMax; i++)
{
CWnd *pPaneShow;
if (m_eDirection == Horizontal)
pPaneShow = GetDlgItem(AFX_IDW_PANE_FIRST + m_nRows * 16 + i);
else
pPaneShow = GetDlgItem(AFX_IDW_PANE_FIRST + i * 16 + m_nCols);
if (pPaneShow == NULL)
continue;
pPaneShow->ShowWindow(SW_SHOWNA);
for (int j = iInnerStart; j >= iIndex; j--)
{
if (m_eDirection == Horizontal)
{
CWnd *pPane = GetPane(j, i);
if (pPane != NULL)
pPane->SetDlgCtrlID(IdFromRowCol(j + 1, i));
}
else
{
CWnd *pPane = GetPane(i, j);
if (pPane != NULL)
pPane->SetDlgCtrlID(IdFromRowCol(j, i + 1));
}
}
if (m_eDirection == Horizontal)
pPaneShow->SetDlgCtrlID(IdFromRowCol(iIndex, i));
else
pPaneShow->SetDlgCtrlID(IdFromRowCol(i, iIndex));
}
RecalcLayout();
}
//----------------------------------------------------------------------------
//
// Function: CSplitterWndEx::HidePane
//
// Description: Hides a pane; Used by ShowPane() public function
//
// Scope: protected
//
// Parameters:
// [in] ESplitPane ePane Pane to hide
//
// Return Values:
// None
//
// Remarks:
// If the window is split horizontally, the split pane must be Top or
// Bottom. If split vertically, the pane must be Left or Right.
//
//----------------------------------------------------------------------------
void CSplitterWndEx::HidePane(ESplitPane ePane)
{
// Make sure a proper pane was passed
int iIndex, iOuterMax, iInnerMax;
if (m_eDirection == Horizontal)
{
ASSERT((ePane == Top || ePane == Bottom));
if (ePane == Top)
iIndex = 0;
else
iIndex = 1;
iOuterMax = m_nCols;
iInnerMax = m_nRows;
}
else if (m_eDirection == Vertical)
{
ASSERT((ePane == Left || ePane == Right));
if (ePane == Left)
iIndex = 0;
else
iIndex = 1;
iOuterMax = m_nRows;
iInnerMax = m_nCols;
}
// Change the active window if there is one
int iActiveRow, iActiveCol;
if (GetActivePane(&iActiveRow, &iActiveCol) != NULL)
{
if (m_eDirection == Horizontal && iActiveRow == iIndex)
{
if (++iActiveRow >= m_nRows)
iActiveRow = 0;
}
else if (m_eDirection == Vertical && iActiveCol == iIndex)
{
if (++iActiveCol >= m_nCols)
iActiveCol = 0;
}
SetActivePane(iActiveRow, iActiveCol);
}
// Hide the row/column
for (int i = 0; i < iOuterMax; i++)
{
CWnd *pPaneHide;
int iCtrlID;
if (m_eDirection == Horizontal)
{
pPaneHide = GetPane(iIndex, i);
iCtrlID = AFX_IDW_PANE_FIRST + m_nRows * 16;
}
else
{
pPaneHide = GetPane(i, iIndex);
iCtrlID = AFX_IDW_PANE_FIRST + i * 16 + m_nCols;
}
pPaneHide->ShowWindow(SW_HIDE);
pPaneHide->SetDlgCtrlID(iCtrlID);
for (int j = iIndex + 1; j < iInnerMax; j++)
{
CWnd *pPane;
if (m_eDirection == Horizontal)
{
pPane = GetPane(j, i);
if (pPane != NULL)
pPane->SetDlgCtrlID(IdFromRowCol(j - 1, i));
}
else
{
pPane = GetPane(i, j);
if (pPane != NULL)
pPane->SetDlgCtrlID(IdFromRowCol(i, j - 1));
}
}
}
// Update the layout
if (m_eDirection == Horizontal)
{
m_nRows--;
m_pRowInfo[m_nRows].nCurSize = m_pRowInfo[iIndex].nCurSize;
}
else
{
m_nCols--;
m_pColInfo[m_nCols].nCurSize = m_pColInfo[iIndex].nCurSize;
}
RecalcLayout();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -