?? guitoolbarwnd.cpp
字號:
CWnd * pWnd =GetDlgItem(pData[i].idCommand);
ASSERT_VALID(pWnd);
pWnd->ShowWindow( SW_HIDE );
pData[i].fsState |= TBSTATE_HIDDEN;
continue;
}
else
{
CWnd * pWnd =GetDlgItem(pData[i].idCommand);
ASSERT_VALID(pWnd);
pData[i].fsState &= ~TBSTATE_HIDDEN;
pWnd->ShowWindow( SW_SHOW );
}
}
int cySep = pData[i].iBitmap;
cySep = cySep * 2 / 3;
CRect rci;
GetItemRect(i, &rci);
int cx=rci.Width();
xSizeMin=min(xSizeMin,cx);
if (pData[i].fsStyle & TBSTYLE_SEP)
{
// a separator represents either a height or width
if (pData[i].fsState & TBSTATE_WRAP)
sizeResult.cy = max(cur.y + m_sizeButton.cy + cySep, sizeResult.cy);
else
sizeResult.cx = max(cur.x + pData[i].iBitmap, sizeResult.cx);
}
else
{
// check for dropdown style, but only if the buttons are being drawn
if ((pData[i].fsStyle & TBSTYLE_DROPDOWN) &&
(dwExtendedStyle & TBSTYLE_EX_DRAWDDARROWS))
{
// add size of drop down
cx += (_afxGuiDropDownWidth);
nNumDrow++;
bDrow=TRUE;
}
sizeResult.cx = max(cur.x + cx, sizeResult.cx);
sizeResult.cy = max(cur.y + m_sizeButton.cy, sizeResult.cy);
}
if (pData[i].fsStyle & TBSTYLE_SEP)
cur.x += pData[i].iBitmap;
else
cur.x += cx - CX_OVERLAP;
if (pData[i].fsState & TBSTATE_WRAP)
{
cur.x = 0;
cur.y += m_sizeButton.cy;
if (pData[i].fsStyle & TBSTYLE_SEP)
cur.y += cySep;
}
}
if (bDrow == TRUE)
{
if (bVertDocked)
{
sizeResult.cx-=_afxGuiDropDownWidth;
sizeResult.cy+=_afxGuiDropDownWidth-2;//*nNumDrow;
}
else
{
sizeResult.cx-=_afxGuiDropDownWidth*nNumDrow;
}
}
else
{
if (bVertDocked)
sizeResult.cy+=_afxGuiDropDownWidth/2;
}
/*if (sizeResult.cx > nSizeHoWid && nSizeHoWid > 0)
sizeResult.cx = nSizeHoWid;
else
{
if(sizeResult.cx < nSizeBarReal)
sizeResult.cx= nSizeBarReal-10;
}*/
return sizeResult;
}
int CGuiToolBarWnd::WrapToolBar(TBBUTTON* pData, int nCount, int nWidth)
{
ASSERT(pData != NULL && nCount > 0);
int nResult = 0;
int x = 0;
for (int i = 0; i < nCount; i++)
{
pData[i].fsState &= ~TBSTATE_WRAP;
if (pData[i].fsState & TBSTATE_HIDDEN)
continue;
int dx, dxNext;
if (pData[i].fsStyle & TBSTYLE_SEP)
{
dx = pData[i].iBitmap;
dxNext = dx;
}
else
{
dx = m_sizeButton.cx;
dxNext = dx - CX_OVERLAP;
}
if (x + dx > nWidth)
{
BOOL bFound = FALSE;
for (int j = i; j >= 0 && !(pData[j].fsState & TBSTATE_WRAP); j--)
{
// Find last separator that isn't hidden
// a separator that has a command ID is not
// a separator, but a custom control.
if ((pData[j].fsStyle & TBSTYLE_SEP) &&
(pData[j].idCommand == 0) &&
!(pData[j].fsState & TBSTATE_HIDDEN))
{
bFound = TRUE; i = j; x = 0;
pData[j].fsState |= TBSTATE_WRAP;
nResult++;
break;
}
}
if (!bFound)
{
for (int j = i - 1; j >= 0 && !(pData[j].fsState & TBSTATE_WRAP); j--)
{
// Never wrap anything that is hidden,
// or any custom controls
if ((pData[j].fsState & TBSTATE_HIDDEN) ||
((pData[j].fsStyle & TBSTYLE_SEP) &&
(pData[j].idCommand != 0)))
continue;
bFound = TRUE; i = j; x = 0;
pData[j].fsState |= TBSTATE_WRAP;
nResult++;
break;
}
if (!bFound)
x += dxNext;
}
}
else
x += dxNext;
}
return nResult + 1;
}
void CGuiToolBarWnd::SizeToolBar(TBBUTTON* pData, int nCount, int nLength, BOOL bVert)
{
ASSERT(pData != NULL && nCount > 0);
bVert;
if (!bVert)
{
int nMin, nMax, nTarget, nCurrent, nMid;
// Wrap ToolBar as specified
nMax = nLength;
nTarget = WrapToolBar(pData, nCount, nMax);
// Wrap ToolBar vertically
nMin = 0;
nCurrent = WrapToolBar(pData, nCount, nMin);
if (nCurrent != nTarget)
{
while (nMin < nMax)
{
nMid = (nMin + nMax) / 2;
nCurrent = WrapToolBar(pData, nCount, nMid);
if (nCurrent == nTarget)
nMax = nMid;
else
{
if (nMin == nMid)
{
WrapToolBar(pData, nCount, nMax);
break;
}
nMin = nMid;
}
}
}
CSize size = CalcSize(pData, nCount);
WrapToolBar(pData, nCount, size.cx);
}
else
{
CSize sizeMax, sizeMin, sizeMid;
// Wrap ToolBar vertically
WrapToolBar(pData, nCount, 0);
sizeMin = CalcSize(pData, nCount);
// Wrap ToolBar horizontally
WrapToolBar(pData, nCount, 32767);
sizeMax = CalcSize(pData, nCount);
while (sizeMin.cx < sizeMax.cx)
{
sizeMid.cx = (sizeMin.cx + sizeMax.cx) / 2;
WrapToolBar(pData, nCount, sizeMid.cx);
sizeMid = CalcSize(pData, nCount);
if (nLength < sizeMid.cy)
{
if (sizeMin == sizeMid)
{
WrapToolBar(pData, nCount, sizeMax.cx);
return;
}
sizeMin = sizeMid;
}
else if (nLength > sizeMid.cy)
sizeMax = sizeMid;
else
return;
}
}
}
struct _AFX_CONTROLPOS
{
int nIndex, nID;
CRect rectOldPos;
};
CSize CGuiToolBarWnd::CalcLayout(DWORD dwMode, int nLength)
{
ASSERT_VALID(this);
ASSERT(::IsWindow(m_hWnd));
if (dwMode & LM_HORZDOCK)
ASSERT(dwMode & LM_HORZ);
if (dwMode & LM_HORZ)
bVertDocked=FALSE;
else
bVertDocked=TRUE;
int nCount;
TBBUTTON* pData = NULL;
CSize sizeResult(0,0);
//BLOCK: Load Buttons
{
nCount = DefWindowProc(TB_BUTTONCOUNT, 0, 0);
if (nCount != 0)
{
int i;
pData = new TBBUTTON[nCount];
for (i = 0; i < nCount; i++)
{
_GetButton(i, &pData[i]);
}
}
}
if (nCount > 0)
{
if (!(m_dwStyle & CBRS_SIZE_FIXED))
{
BOOL bDynamic = m_dwStyle & CBRS_SIZE_DYNAMIC;
if (bDynamic && (dwMode & LM_MRUWIDTH))
SizeToolBar(pData, nCount, m_nMRUWidth);
else if (bDynamic && (dwMode & LM_HORZDOCK))
SizeToolBar(pData, nCount, 32767);
else if (bDynamic && (dwMode & LM_VERTDOCK))
SizeToolBar(pData, nCount, 0);
else if (bDynamic && (nLength != -1))
{
CRect rect; rect.SetRectEmpty();
CalcInsideRect(rect, (dwMode & LM_HORZ));
BOOL bVert = (dwMode & LM_LENGTHY);
int nLen = nLength + (bVert ? rect.Height() : rect.Width());
SizeToolBar(pData, nCount, nLen, bVert);
}
else if (bDynamic && (m_dwStyle & CBRS_FLOATING))
SizeToolBar(pData, nCount, m_nMRUWidth);
else
SizeToolBar(pData, nCount, (dwMode & LM_HORZ) ? 32767 : 0);
}
sizeResult = CalcSize(pData, nCount);
if (dwMode & LM_COMMIT)
{
_AFX_CONTROLPOS* pControl = NULL;
int nControlCount = 0;
BOOL bIsDelayed = m_bDelayedButtonLayout;
m_bDelayedButtonLayout = FALSE;
for (int i = 0; i < nCount; i++)
if ((pData[i].fsStyle & TBSTYLE_SEP) && (pData[i].idCommand != 0))
nControlCount++;
if (nControlCount > 0)
{
pControl = new _AFX_CONTROLPOS[nControlCount];
nControlCount = 0;
for(int i = 0; i < nCount; i++)
{
if ((pData[i].fsStyle & TBSTYLE_SEP) && (pData[i].idCommand != 0))
{
pControl[nControlCount].nIndex = i;
pControl[nControlCount].nID = pData[i].idCommand;
CRect rect;
GetItemRect(i, &rect);
ClientToScreen(&rect);
pControl[nControlCount].rectOldPos = rect;
nControlCount++;
}
}
}
if ((m_dwStyle & CBRS_FLOATING) && (m_dwStyle & CBRS_SIZE_DYNAMIC))
m_nMRUWidth = sizeResult.cx;
for (i = 0; i < nCount; i++)
_SetButton(i, &pData[i]);
if (nControlCount > 0)
{
for (int i = 0; i < nControlCount; i++)
{
CWnd* pWnd = GetDlgItem(pControl[i].nID);
if (pWnd != NULL)
{
CRect rect;
pWnd->GetWindowRect(&rect);
CPoint pt = rect.TopLeft() - pControl[i].rectOldPos.TopLeft();
GetItemRect(pControl[i].nIndex, &rect);
pt = rect.TopLeft() + pt;
pWnd->SetWindowPos(NULL, pt.x, pt.y, 0, 0, SWP_NOACTIVATE | SWP_NOSIZE | SWP_NOZORDER);
}
}
delete[] pControl;
}
m_bDelayedButtonLayout = bIsDelayed;
}
delete[] pData;
}
//BLOCK: Adjust Margins
{
CRect rect; rect.SetRectEmpty();
CalcInsideRect(rect, (dwMode & LM_HORZ));
sizeResult.cy -= rect.Height();
sizeResult.cx -= rect.Width();
CSize size = CControlBar::CalcFixedLayout((dwMode & LM_STRETCH), (dwMode & LM_HORZ));
sizeResult.cx = max(sizeResult.cx, size.cx);
sizeResult.cy = max(sizeResult.cy, size.cy);
}
return sizeResult;
}
CSize CGuiToolBarWnd::CalcFixedLayout(BOOL bStretch, BOOL bHorz)
{
DWORD dwMode = bStretch ? LM_STRETCH : 0;
dwMode |= bHorz ? LM_HORZ : 0;
return CalcLayout(dwMode);
}
CSize CGuiToolBarWnd::CalcDynamicLayout(int nLength, DWORD dwMode)
{
if ((nLength == -1) && !(dwMode & LM_MRUWIDTH) && !(dwMode & LM_COMMIT) &&
((dwMode & LM_HORZDOCK) || (dwMode & LM_VERTDOCK)))
{
return CalcFixedLayout(dwMode & LM_STRETCH, dwMode & LM_HORZDOCK);
}
return CalcLayout(dwMode, nLength);
}
void CGuiToolBarWnd::_GetButton(int nIndex, TBBUTTON* pButton) const
{
CGuiToolBarWnd* pBar = (CGuiToolBarWnd*)this;
VERIFY(pBar->DefWindowProc(TB_GETBUTTON, nIndex, (LPARAM)pButton));
// TBSTATE_ENABLED == TBBS_DISABLED so invert it
pButton->fsState ^= TBSTATE_ENABLED;
}
void CGuiToolBarWnd::_SetButton(int nIndex, TBBUTTON* pButton)
{
// get original button state
TBBUTTON button;
VERIFY(DefWindowProc(TB_GETBUTTON, nIndex, (LPARAM)&button));
// prepare for old/new button comparsion
button.bReserved[0] = 0;
button.bReserved[1] = 0;
// TBSTATE_ENABLED == TBBS_DISABLED so invert it
pButton->fsState ^= TBSTATE_ENABLED;
pButton->bReserved[0] = 0;
pButton->bReserved[1] = 0;
// nothing to do if they are the same
if (memcmp(pButton, &button, sizeof(TBBUTTON)) != 0)
{
// don't redraw everything while setting the button
DWORD dwStyle = GetStyle();
ModifyStyle(WS_VISIBLE, 0);
VERIFY(DefWindowProc(TB_DELETEBUTTON, nIndex, 0));
VERIFY(DefWindowProc(TB_INSERTBUTTON, nIndex, (LPARAM)pButton));
ModifyStyle(0, dwStyle & WS_VISIBLE);
// invalidate appropriate parts
if (((pButton->fsStyle ^ button.fsStyle) & TBSTYLE_SEP) ||
((pButton->fsStyle & TBSTYLE_SEP) && pButton->iBitmap != button.iBitmap))
{
// changing a separator
Invalidate();
}
else
{
// invalidate just the button
CRect rect;
if (DefWindowProc(TB_GETITEMRECT, nIndex, (LPARAM)&rect))
InvalidateRect(rect);
}
}
}
BOOL CGuiToolBarWnd::IsLeft()
{
if (nDockBarAling == AFX_IDW_DOCKBAR_LEFT) return TRUE;
return FALSE;
}
BOOL CGuiToolBarWnd::IsRight()
{
if (nDockBarAling == AFX_IDW_DOCKBAR_RIGHT) return TRUE;
return FALSE;
}
BOOL CGuiToolBarWnd::IsTop()
{
if (nDockBarAling == AFX_IDW_DOCKBAR_TOP) return TRUE;
return FALSE;
}
BOOL CGuiToolBarWnd::IsBottom()
{
if (nDockBarAling == AFX_IDW_DOCKBAR_BOTTOM) return TRUE;
return FALSE;
}
BOOL CGuiToolBarWnd::IsVert()
{
if (IsLeft() || IsRight())
return TRUE;
return FALSE;
}
BOOL CGuiToolBarWnd::IsHorz()
{
if (IsTop() || IsBottom())
return TRUE;
return FALSE;
}
BOOL CGuiToolBarWnd::IsFloating()
{
if (nDockBarAling == AFX_IDW_DOCKBAR_FLOAT)
return TRUE;
return FALSE;
}
void CGuiToolBarWnd::OnMouseMove(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
int nCountBtn= nCountBtn = SendMessage (TB_BUTTONCOUNT, 0, 0);
CRect rc;
if (!IsTopParentActive() || !GetTopLevelParent()->IsWindowEnabled())
return;
for (int i=0; i< nCountBtn; i++)
{
GetItemRect(i,rc);
if (GetButtonStyle(i) == TBBS_SEPARATOR)
continue;
else
{
if (rc.PtInRect(point) && m_ActualBtn != i)
{
m_ActualBtn=i;
InvalidateRect(rc,TRUE);
m_rcBtnGlobal=rc;
m_rcSaveFloat=rc;
}
if (m_ActualBtn == i)
m_rcBtnGlobal=rc;
}
}
SetTimer(1, 250, 0);
CToolBar::OnMouseMove(nFlags, point);
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -