123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341 |
- #include "StdAfx.h"
- #include "OOExToolBar.h"
- #include "math.h"
- #include ".\ooextoolbar.h"
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- IMPLEMENT_DYNAMIC( COOExToolBar, CToolBar )
- BEGIN_MESSAGE_MAP( COOExToolBar, CToolBar )
-
- ON_WM_NCCALCSIZE()
- ON_WM_CREATE()
- ON_WM_NCPAINT()
- ON_WM_SYSCOLORCHANGE()
- ON_WM_WINDOWPOSCHANGING()
-
- END_MESSAGE_MAP()
- COOExToolBar::COOExToolBar( void )
- {
-
-
- m_nShowIconMode = 1;
- m_bShowIconText = false;
- m_SmallIconSize = CSize( 16, 16 );
- m_LargeIconSize = CSize( 32, 32 );
- m_bOldFloating=false;
- }
- COOExToolBar::~COOExToolBar( void )
- {
-
-
- for ( int i=0; i<NB_POSSIBLE_MODE; i++ )
- {
- if ( m_ImageList[ i ].GetSafeHandle() )
- m_ImageList[ i ].DeleteImageList();
- }
- }
- void COOExToolBar::SetIconMode(
- UINT _nShowIconMode )
- {
-
-
- m_nShowIconMode = _nShowIconMode;
-
-
- AssignImageList();
-
-
- ResizeToolBar();
- }
- UINT COOExToolBar::GetIconMode( void ) const
- {
- return m_nShowIconMode;
- }
- void COOExToolBar::SetTextMode(
- bool _bShowIconText )
- {
-
-
- m_bShowIconText = _bShowIconText;
-
-
- ResizeToolBar();
- }
- bool COOExToolBar::GetTextMode( void ) const
- {
- return m_bShowIconText;
- }
- BOOL COOExToolBar::LoadToolBar(
- UINT _ResourceId )
- {
-
-
-
- CString lpszResourceName;
- lpszResourceName.Format( "#%d", _ResourceId );
- BOOL bReturn = CToolBar::LoadToolBar( lpszResourceName );
-
-
- if ( bReturn == FALSE )
- {
- return bReturn;
- }
-
-
- CToolBarCtrl& bar = GetToolBarCtrl();
- int nIndex = 0;
- CRect NoTextRc( 0, 0, 0, 0 );
- bar.GetItemRect( 0, NoTextRc );
-
-
-
- TBBUTTON tb;
- for ( nIndex = bar.GetButtonCount(); nIndex >= 0; nIndex-- )
- {
- ZeroMemory(&tb, sizeof(TBBUTTON));
- bar.GetButton(nIndex, &tb);
-
- if ( ( tb.fsStyle & TBSTYLE_SEP ) == TBSTYLE_SEP ) {
- continue;
- }
-
- if ( tb.idCommand == 0 ) {
- continue;
- }
-
- CString strText((LPCSTR)tb.idCommand);
- LPCTSTR lpszButtonText = NULL;
- CString strButtonText(_T(""));
- _TCHAR seps[] = _T("\n");
- if ( !strText.IsEmpty() ) {
- lpszButtonText = _tcstok( ( LPTSTR ) ( LPCTSTR ) strText, seps );
- while( lpszButtonText )
- {
- strButtonText = lpszButtonText;
- lpszButtonText = _tcstok( NULL, seps );
- }
- }
- if ( !strButtonText.IsEmpty() ) {
- SetButtonText( nIndex, strButtonText );
- }
- }
-
-
- CRect rc( 0, 0, 0, 0 );
- CSize sizeMax( 0, 0 );
- for ( nIndex = bar.GetButtonCount(); nIndex >= 0; nIndex-- )
- {
- bar.GetItemRect( nIndex, rc );
- rc.NormalizeRect();
- sizeMax.cx = __max( rc.Size().cx, sizeMax.cx );
- sizeMax.cy = __max( rc.Size().cy, sizeMax.cy );
- }
-
-
-
-
-
-
- m_nTextWidth = sizeMax.cx;
- m_nTextHeight = sizeMax.cy - ( NoTextRc.Size().cy );
- ResizeToolBar();
-
-
-
- CClientDC dc( this );
- int nNbBits = dc.GetDeviceCaps( BITSPIXEL );
- for ( int i=0; i<NB_POSSIBLE_MODE; i++ )
- {
- UINT nColorMode = ILC_COLOR;
- if ( nNbBits > 8 )
- {
- nColorMode = ILC_COLORDDB;
- }
- CSize Size = m_LargeIconSize;
- if ( i < 3 )
- {
- Size = m_SmallIconSize;
- }
-
- m_ImageList[ i ].Create( Size.cx, Size.cy, nColorMode | ILC_MASK, bar.GetButtonCount(), 10 );
- }
- return bReturn;
- }
-
- void COOExToolBar::SetImageList(
- ImageMode_ _Mode,
- CImageList& _rList )
- {
-
-
- m_ImageList[ _Mode ].Attach( _rList.Detach() );
- }
- void COOExToolBar::AssignImageList( void )
- {
-
-
- CImageList* pTempHotList;
- CImageList* pTempNormalList;
- CImageList* pTempDisableList;
- if ( m_nShowIconMode == 0 )
- {
- pTempHotList = &m_ImageList[ SmallHot ];
- pTempNormalList = &m_ImageList[ SmallStandard ];
- pTempDisableList = &m_ImageList[ SmallDisable ];
- }
- if ( m_nShowIconMode == 1 )
- {
- pTempHotList = &m_ImageList[ LargeHot ];
- pTempNormalList = &m_ImageList[ LargeStandard ];
- pTempDisableList = &m_ImageList[ LargeDisable ];
- }
-
-
- SetHotImageList( pTempHotList );
- SetStandardImageList( pTempNormalList );
- SetDisableImageList( pTempDisableList );
- }
- void COOExToolBar::InitImageList( void )
- {
-
-
- AssignImageList();
- }
- CSize COOExToolBar::CalcButtonSize( void )
- {
-
-
- CSize theButtonSize;
- if ( m_nShowIconMode == 0 )
- {
- theButtonSize = CSize( m_SmallIconSize.cx + 8, m_SmallIconSize.cy + 7 );
- }
- else if ( m_nShowIconMode == 1 )
- {
- theButtonSize = CSize( m_LargeIconSize.cx + 8, m_LargeIconSize.cy + 7 );
- }
-
-
- if ( m_bShowIconText )
- {
-
-
- if ( theButtonSize.cx < m_nTextWidth )
- {
- theButtonSize.cx = m_nTextWidth;
- }
-
-
- theButtonSize.cy += m_nTextHeight;
- }
- return theButtonSize;
- }
- void COOExToolBar::SetHotImageList(
- CImageList* pList )
- {
-
-
- CWnd* pWnd = &GetToolBarCtrl();
- pWnd->SendMessage( TB_SETHOTIMAGELIST, 0, ( LPARAM ) ( HIMAGELIST ) *pList );
- }
- void COOExToolBar::SetStandardImageList(
- CImageList* pList )
- {
-
-
- CWnd* pWnd = &GetToolBarCtrl();
- pWnd->SendMessage( TB_SETIMAGELIST, 0, ( LPARAM ) ( HIMAGELIST ) *pList );
- }
- void COOExToolBar::SetDisableImageList(
- CImageList* pList )
- {
-
-
- CWnd* pWnd = &GetToolBarCtrl();
- pWnd->SendMessage( TB_SETDISABLEDIMAGELIST, 0, ( LPARAM ) ( HIMAGELIST ) *pList );
- }
- void COOExToolBar::SetButtonDropDown(
- int nID )
- {
-
-
- DWORD dwStyle = GetButtonStyle( CommandToIndex( nID ) );
- dwStyle |= TBSTYLE_DROPDOWN;
- SetButtonStyle( CommandToIndex( nID ), dwStyle );
-
-
- CToolBarCtrl& bar = GetToolBarCtrl();
- CSize theStdButtonSize = CalcButtonSize();
- CRect rc( 0, 0, 0, 0 );
- bar.GetItemRect( CommandToIndex( nID ), rc );
- m_nDropButtonSize = rc.Width() - theStdButtonSize.cx;
- }
- void COOExToolBar::ResizeToolBar( void )
- {
-
-
- CSize theSize = ( m_nShowIconMode == 0 ) ? m_SmallIconSize : m_LargeIconSize;
- CSize theButtonSize = CalcButtonSize();
-
-
- SetSizes( theButtonSize, theSize );
- MoveWindow( 200, 200, 450, theButtonSize.cy );
- SendMessage( WM_SIZE, SIZE_RESTORED );
- CFrameWnd* pFrameWnd = GetDockingFrame();
- pFrameWnd->DelayRecalcLayout();
- }
- void COOExToolBar::DrawGripper(
- CDC& dc ) const
- {
-
-
- if( m_dwStyle & CBRS_FLOATING )
- {
- return;
- }
-
-
-
- CRect gripper;
- GetWindowRect( gripper );
- ScreenToClient( gripper );
- gripper.OffsetRect( -gripper.left, -gripper.top );
-
-
- COLORREF clrBtnHilight = ::GetSysColor(COLOR_BTNHILIGHT);
- COLORREF clrBtnShadow = ::GetSysColor(COLOR_BTNSHADOW);
- if( m_dwStyle & CBRS_ORIENT_HORZ ) {
-
-
- gripper.DeflateRect( 3, 3 );
- gripper.right = gripper.left+3;
- dc.Draw3dRect( gripper, clrBtnHilight, clrBtnShadow );
-
- gripper.OffsetRect(5, 0);
- dc.Draw3dRect( gripper, clrBtnHilight, clrBtnShadow );
- }
-
- else {
-
-
- gripper.DeflateRect( 3, 3 );
- gripper.bottom = gripper.top+3;
- dc.Draw3dRect( gripper, clrBtnHilight, clrBtnShadow );
-
- gripper.OffsetRect(0, 5);
- dc.Draw3dRect( gripper, clrBtnHilight, clrBtnShadow );
- }
- }
- void COOExToolBar::OnUpdateCmdUI(
- CFrameWnd* pTarget,
- BOOL bDisableIfNoHndler )
- {
- CCoolCmdUI state;
- state.m_pOther = this;
-
- state.m_nIndexMax = ( UINT ) DefWindowProc( TB_BUTTONCOUNT, 0, 0 );
- for ( state.m_nIndex = 0; state.m_nIndex < state.m_nIndexMax; state.m_nIndex++ )
- {
-
- TBBUTTON button;
- VERIFY( DefWindowProc( TB_GETBUTTON, state.m_nIndex, ( LPARAM ) &button ) );
-
- button.fsState ^= TBSTATE_ENABLED;
-
- state.m_nID = button.idCommand;
-
-
- if ( !( button.fsStyle & TBSTYLE_SEP ) )
- {
-
- if ( CWnd::OnCmdMsg( state.m_nID, CN_UPDATE_COMMAND_UI, &state, NULL ) )
- continue;
-
-
- state.DoUpdate( pTarget, bDisableIfNoHndler );
- }
- }
-
-
- UpdateDialogControls( pTarget, bDisableIfNoHndler );
- }
- void COOExToolBar::OnNcPaint( void )
- {
- CControlBar::EraseNonClient();
- CWindowDC dc( this );
- DrawGripper( dc );
-
- CRect pRect;
- GetClientRect( &pRect );
- InvalidateRect( &pRect, TRUE );
-
- CWnd* pWnd = &GetToolBarCtrl();
- pWnd->GetClientRect( &pRect );
- pWnd->InvalidateRect( &pRect, TRUE );
- DeleteObject( dc );
- }
- int COOExToolBar::OnCreate(
- LPCREATESTRUCT lpCreateStruct )
- {
-
-
- if ( CToolBar::OnCreate( lpCreateStruct ) == -1 )
- {
- return -1;
- }
-
-
-
-
-
- ModifyStyle( 0, TBSTYLE_FLAT );
- SendMessage( TB_SETEXTENDEDSTYLE, 0, TBSTYLE_EX_DRAWDDARROWS );
-
-
-
- return 0;
- }
- void COOExToolBar::OnNcCalcSize(
- BOOL bCalcValidRects,
- NCCALCSIZE_PARAMS FAR* lpncsp )
- {
-
-
- if( !( m_dwStyle & CBRS_FLOATING ) )
- {
-
- if( m_dwStyle & CBRS_ORIENT_HORZ ) {
- lpncsp->rgrc[0].left += 5;
- lpncsp->rgrc[0].right += 5;
- }
- else {
- lpncsp->rgrc[0].top += 5;
- lpncsp->rgrc[0].bottom += 5;
- }
- }
-
- CToolBar::OnNcCalcSize( bCalcValidRects, lpncsp );
- }
- void COOExToolBar::OnSysColorChange( void )
- {
-
-
- CToolBar::OnSysColorChange();
- }
- void COOExToolBar::OnWindowPosChanging( LPWINDOWPOS _pWindowPos )
- {
-
-
- if( m_bOldFloating != ( IsFloating()?true:false ) )
- {
- m_bOldFloating = !m_bOldFloating;
- _pWindowPos->flags |= SWP_DRAWFRAME;
- }
- CToolBar::OnWindowPosChanging( _pWindowPos );
- }
- void CCoolCmdUI::Enable( BOOL bOn )
- {
- m_bEnableChanged = TRUE;
- CToolBar* pToolBar = ( CToolBar* ) m_pOther;
- ASSERT( pToolBar != NULL );
- ASSERT_KINDOF( CToolBar, pToolBar );
- ASSERT( m_nIndex < m_nIndexMax );
-
- UINT nNewStyle = pToolBar->GetButtonStyle( m_nIndex ) & ~TBBS_DISABLED;
- if ( !bOn )
- {
- nNewStyle |= TBBS_DISABLED;
-
-
-
-
- nNewStyle &= ~TBBS_PRESSED;
- }
- ASSERT( !( nNewStyle & TBBS_SEPARATOR ) );
- pToolBar->SetButtonStyle( m_nIndex, nNewStyle );
- }
- void CCoolCmdUI::SetCheck( int nCheck )
- {
- ASSERT( nCheck >= 0 && nCheck <= 2 );
- CToolBar* pToolBar = ( CToolBar* ) m_pOther;
- ASSERT( pToolBar != NULL );
- ASSERT_KINDOF( CToolBar, pToolBar );
- ASSERT( m_nIndex < m_nIndexMax );
-
- UINT nOldStyle = pToolBar->GetButtonStyle( m_nIndex );
- UINT nNewStyle = nOldStyle &
- ~( TBBS_PRESSED | TBBS_INDETERMINATE );
- if ( nCheck == 1 )
- nNewStyle |= TBBS_PRESSED;
- else if ( nCheck == 2 )
- nNewStyle |= TBBS_INDETERMINATE;
-
-
-
-
-
- if ( nNewStyle != nOldStyle ) {
- ASSERT( !( nNewStyle & TBBS_SEPARATOR ) );
- pToolBar->SetButtonStyle( m_nIndex, nNewStyle );
- pToolBar->Invalidate();
- }
- }
- CSize COOExToolBar::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);
- }
- CSize COOExToolBar::GetButtonSize(TBBUTTON* pData, int iButton)
- {
-
-
-
-
- CRect rc;
- SendMessage(TB_GETITEMRECT, iButton, (LPARAM)&rc);
- CSize sz = rc.Size();
-
-
-
-
- DWORD dwStyle = pData[iButton].fsStyle;
- if ((pData[iButton].fsState & TBSTATE_WRAP)) {
- if (dwStyle & TBSTYLE_SEP) {
-
-
-
-
- sz.cy = sz.cx;
- sz.cx = 0;
-
- } else if (dwStyle & TBSTYLE_DROPDOWN ) {
-
-
- sz.cx = 0;
- }
- }
- return sz;
- }
- void COOExToolBar::GetButton(int nIndex, TBBUTTON* pButton) const
- {
- CToolBar* pBar = (CToolBar*)this;
- VERIFY(pBar->SendMessage(TB_GETBUTTON, nIndex, (LPARAM)pButton));
-
- pButton->fsState ^= TBSTATE_ENABLED;
- }
- void COOExToolBar::SetButton(int nIndex, TBBUTTON* pButton)
- {
-
- TBBUTTON button;
- VERIFY(SendMessage(TB_GETBUTTON, nIndex, (LPARAM)&button));
-
-
- button.bReserved[0] = 0;
- button.bReserved[1] = 0;
-
- pButton->fsState ^= TBSTATE_ENABLED;
- pButton->bReserved[0] = 0;
- pButton->bReserved[1] = 0;
-
-
- if (memcmp(pButton, &button, sizeof(TBBUTTON)) != 0)
- {
-
- DWORD dwStyle = GetStyle();
- ModifyStyle(WS_VISIBLE, 0);
- VERIFY(SendMessage(TB_DELETEBUTTON, nIndex, 0));
- VERIFY(SendMessage(TB_INSERTBUTTON, nIndex, (LPARAM)pButton));
- ModifyStyle(0, dwStyle & WS_VISIBLE);
-
-
- if (((pButton->fsStyle ^ button.fsStyle) & TBSTYLE_SEP) ||
- ((pButton->fsStyle & TBSTYLE_SEP) && pButton->iBitmap != button.iBitmap))
- {
-
- Invalidate(FALSE);
- }
- else
- {
-
- CRect rect;
- if (SendMessage(TB_GETITEMRECT, nIndex, (LPARAM)&rect))
- InvalidateRect(rect, FALSE);
- }
- }
- }
- #ifdef _MAC
- #define CX_OVERLAP 1
- #else
- #define CX_OVERLAP 0
- #endif
- CSize COOExToolBar::CalcSize(TBBUTTON* pData, int nCount)
- {
- ASSERT(pData != NULL && nCount > 0);
-
- CPoint cur(0,0);
- CSize sizeResult(0,0);
- int cyTallestOnRow = 0;
-
- for (int i = 0; i < nCount; i++)
- {
- if (pData[i].fsState & TBSTATE_HIDDEN)
- continue;
-
-
-
- CSize m_sizeButton = GetButtonSize(pData, i);
-
-
- cyTallestOnRow = max(cyTallestOnRow, m_sizeButton.cy);
- sizeResult.cx = max(cur.x + m_sizeButton.cx, sizeResult.cx);
- sizeResult.cy = max(cur.y + m_sizeButton.cy, sizeResult.cy);
-
- cur.x += m_sizeButton.cx - CX_OVERLAP;
-
- if (pData[i].fsState & TBSTATE_WRAP)
- {
- cur.x = 0;
- cur.y += cyTallestOnRow;
- cyTallestOnRow = 0;
- if (pData[i].fsStyle & TBSTYLE_SEP)
- cur.y += m_sizeButton.cy;
- }
- }
- return sizeResult;
- }
- int COOExToolBar::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;
-
-
-
- CSize m_sizeButton = GetButtonSize(pData, i);
-
- 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--)
- {
-
-
-
- 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--)
- {
-
-
- 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 COOExToolBar::SizeToolBar(TBBUTTON* pData, int nCount, int nLength, BOOL bVert)
- {
- ASSERT(pData != NULL && nCount > 0);
-
- if (!bVert)
- {
- int nMin, nMax, nTarget, nCurrent, nMid;
-
-
- nMax = nLength;
- nTarget = WrapToolBar(pData, nCount, nMax);
-
-
- 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;
-
-
- WrapToolBar(pData, nCount, 0);
- sizeMin = CalcSize(pData, nCount);
-
-
- 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 COOExToolBar::CalcLayout(DWORD dwMode, int nLength)
- {
- ASSERT_VALID(this);
- ASSERT(::IsWindow(m_hWnd));
- if (dwMode & LM_HORZDOCK)
- ASSERT(dwMode & LM_HORZ);
-
- int nCount;
- TBBUTTON* pData;
- CSize sizeResult(0,0);
-
-
- {
- nCount = (int)SendMessage(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 (int 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;
- }
-
-
- {
- 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 COOExToolBar::CalcFixedLayout(BOOL bStretch, BOOL bHorz)
- {
- DWORD dwMode = bStretch ? LM_STRETCH : 0;
- dwMode |= bHorz ? LM_HORZ : 0;
-
- return CalcLayout(dwMode);
- }
- IMPLEMENT_DYNAMIC( COOBmpToolBar, COOExToolBar )
- BEGIN_MESSAGE_MAP( COOBmpToolBar, COOExToolBar )
-
-
- ON_WM_ERASEBKGND()
- END_MESSAGE_MAP()
- COOBmpToolBar::COOBmpToolBar( void )
- {
- }
- COOBmpToolBar::~COOBmpToolBar( void )
- {
- }
- void COOBmpToolBar::InitImageList( void )
- {
-
-
- for ( int i=0; i<NB_POSSIBLE_MODE; i++ )
- {
- BuildImageList( m_ImageList[ i ], m_256Image[ i ] );
- }
-
-
- AssignImageList();
- }
- void COOBmpToolBar::BuildImageList(
- CImageList& _rImageList,
- const CExBitmap& _rBitmap )
- {
- CBitmap bmpImage;
- bmpImage.LoadBitmap( _rBitmap.m_nResourceId );
- _rImageList.Add( &bmpImage, _rBitmap.m_clrTransparent );
- }
- void COOBmpToolBar::SetBitmap(
- UINT _nBitmap,
- ImageMode_ _Mode,
- COLORREF _clrBk,
- bool _b256 )
- {
-
-
- if ( _b256 )
- {
- m_256Image[ _Mode ].m_nResourceId = _nBitmap;
- m_256Image[ _Mode ].m_clrTransparent = _clrBk;
- }
- else
- {
- m_16Image[ _Mode ].m_nResourceId = _nBitmap;
- m_16Image[ _Mode ].m_clrTransparent = _clrBk;
- }
- }
- BOOL COOBmpToolBar::OnEraseBkgnd(CDC* pDC)
- {
-
-
-
-
-
-
-
- return COOExToolBar::OnEraseBkgnd(pDC);
- }
|