📄 ooextoolbar.cpp
字号:
void COOExToolBar::SetHotImageList(
CImageList* pList ) // @Parm The hoover image list.
{
// Retrieve the tool bar control and set the list reference.
// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
CWnd* pWnd = &GetToolBarCtrl();
pWnd->SendMessage( TB_SETHOTIMAGELIST, 0, ( LPARAM ) ( HIMAGELIST ) *pList );
}
// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
// @mfunc: (FUNCTIONAL)
// <c COOExToolBar>
// To set the normal image list.
// @end =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
void COOExToolBar::SetStandardImageList(
CImageList* pList ) // @Parm The normal image list.
{
// Retrieve the tool bar control and set the list reference.
// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
CWnd* pWnd = &GetToolBarCtrl();
pWnd->SendMessage( TB_SETIMAGELIST, 0, ( LPARAM ) ( HIMAGELIST ) *pList );
}
// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
// @mfunc: (FUNCTIONAL)
// <c COOExToolBar>
// To set the disable image list.
// @end =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
void COOExToolBar::SetDisableImageList(
CImageList* pList ) // @Parm The normal image list.
{
// Retrieve the tool bar control and set the list reference.
// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
CWnd* pWnd = &GetToolBarCtrl();
pWnd->SendMessage( TB_SETDISABLEDIMAGELIST, 0, ( LPARAM ) ( HIMAGELIST ) *pList );
}
// @end =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
// Start =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
// Usefull protected method.
// ------------------------------------------------------------------------
// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
// @mfunc: (FUNCTIONAL)
// <c COOExToolBar>
// To display the dropdown button for the given button.
// @end =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
void COOExToolBar::SetButtonDropDown(
int nID ) // @Parm The id to show the drop down.
{
// Change button style to dropdown.
// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
DWORD dwStyle = GetButtonStyle( CommandToIndex( nID ) );
dwStyle |= TBSTYLE_DROPDOWN;
SetButtonStyle( CommandToIndex( nID ), dwStyle );
// Calculate the drop button size.
// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
CToolBarCtrl& bar = GetToolBarCtrl();
CSize theStdButtonSize = CalcButtonSize();
CRect rc( 0, 0, 0, 0 );
bar.GetItemRect( CommandToIndex( nID ), rc );
m_nDropButtonSize = rc.Width() - theStdButtonSize.cx;
}
// @end =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
// Start =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
// Usefull protected method.
// ------------------------------------------------------------------------
// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
// @mfunc: (FUNCTIONAL)
// <c COOExToolBar>
// To resieze the toolbar once something change.
// @end =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
void COOExToolBar::ResizeToolBar( void )
{
// Set the size of the toolbar corresponding to the current mode.
// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
CSize theSize = ( m_nShowIconMode == 0 ) ? m_SmallIconSize : m_LargeIconSize;
CSize theButtonSize = CalcButtonSize();
// Resize the toolbar and the dock frame.
// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
SetSizes( theButtonSize, theSize );
MoveWindow( 0, 0, 450, theButtonSize.cy );
SendMessage( WM_SIZE, SIZE_RESTORED );
CFrameWnd* pFrameWnd = GetDockingFrame();
pFrameWnd->DelayRecalcLayout();
}
// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
// @mfunc: (FUNCTIONAL)
// <c COOExToolBar>
// To draw the gripper on the toolbar.
// @end =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
void COOExToolBar::DrawGripper(
CDC& dc ) const // @Parm The device context where to draw the gripper.
{
// No gripper if floating
// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
if( m_dwStyle & CBRS_FLOATING )
{
return;
}
// Retrieve the window coord and calculate the gripper position.
// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
CRect gripper;
GetWindowRect( gripper );
ScreenToClient( gripper );
gripper.OffsetRect( -gripper.left, -gripper.top );
// Draw it accordingly to the orientation of the toolbar.
// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
COLORREF clrBtnHilight = ::GetSysColor(COLOR_BTNHILIGHT);
COLORREF clrBtnShadow = ::GetSysColor(COLOR_BTNSHADOW);
if( m_dwStyle & CBRS_ORIENT_HORZ ) {
// gripper at left
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 at top
gripper.DeflateRect( 3, 3 );
gripper.bottom = gripper.top+3;
dc.Draw3dRect( gripper, clrBtnHilight, clrBtnShadow );
gripper.OffsetRect(0, 5);
dc.Draw3dRect( gripper, clrBtnHilight, clrBtnShadow );
}
}
// @end =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
// Start =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
// MFC Overloaded method.
// ------------------------------------------------------------------------
// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
// @mfunc: (FUNCTIONAL)
// <c COOExToolBar>
// Only overloaded to use our cmdui instead of their. This is
// the same code found in CToolBar::OnUpdateCmdUI, but we
// replace the CCmdUI by CCoolCmdUI.
// @end =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
void COOExToolBar::OnUpdateCmdUI(
CFrameWnd* pTarget, // @Parm ??
BOOL bDisableIfNoHndler ) // @Parm ??
{
CCoolCmdUI state; // this is the only line that's different--PD
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++ )
{
// get button state
TBBUTTON button;
VERIFY( DefWindowProc( TB_GETBUTTON, state.m_nIndex, ( LPARAM ) &button ) );
// TBSTATE_ENABLED == TBBS_DISABLED so invert it
button.fsState ^= TBSTATE_ENABLED;
state.m_nID = button.idCommand;
// ignore separators
if ( !( button.fsStyle & TBSTYLE_SEP ) )
{
// allow the toolbar itself to have update handlers
if ( CWnd::OnCmdMsg( state.m_nID, CN_UPDATE_COMMAND_UI, &state, NULL ) )
continue;
// allow the owner to process the update
state.DoUpdate( pTarget, bDisableIfNoHndler );
}
}
// update the dialog controls added to the toolbar
UpdateDialogControls( pTarget, bDisableIfNoHndler );
}
// @end =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
// Start =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
// MFC Message method.
// ------------------------------------------------------------------------
// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
// @mfunc: (FUNCTIONAL)
// <c COOExToolBar>
// This will draw the gripper on the toolbar then repaints
// client areas.
// @end =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
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 );
}
// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
// @mfunc: (FUNCTIONAL)
// <c COOExToolBar>
// Trap to set the flat bar style.
// @RDesc Nonzero if the toolbar is correctly created.
// @end =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
int COOExToolBar::OnCreate(
LPCREATESTRUCT lpCreateStruct ) // @Parm Toolbar creation information.
{
// Call the base class method.
// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
if ( CToolBar::OnCreate( lpCreateStruct ) == -1 )
{
return -1;
}
// Set the style to flat.
// There is a but when docking vertical. The size of the separator
// is not calculate correctly by MFC. Only in style flat.
// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
ModifyStyle( 0, TBSTYLE_FLAT );
SendMessage( TB_SETEXTENDEDSTYLE, 0, TBSTYLE_EX_DRAWDDARROWS );
// The window is now created.
// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
return 0;
}
// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
// @mfunc: (FUNCTIONAL)
// <c COOExToolBar>
// Trap to size correctly the toolbar with the carret.
// @end =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
void COOExToolBar::OnNcCalcSize(
BOOL bCalcValidRects, // @Parm MFC Specific message.
NCCALCSIZE_PARAMS FAR* lpncsp ) // @Parm MFC Specific message.
{
// No gripper if floating
// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
if( !( m_dwStyle & CBRS_FLOATING ) )
{
// Adjust non-client area for gripper at left or top.
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 );
}
// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
// @mfunc: (FUNCTIONAL)
// <c COOExToolBar>
// Call when ever the system color are changing. Trap to rebuild
// the toolbar image list with the good background color.
// @end =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
void COOExToolBar::OnSysColorChange( void )
{
// Call the base class method.
// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
CToolBar::OnSysColorChange();
}
// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
// @mfunc: (FUNCTIONAL)
// <c COOExToolBar>
// Call when the toolbar is moved. There is a bug when the tool
// bar is in flat mode, and in vertical position. The separator
// are not count in the height, so the last button is not completly
// displayed.
// @end =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
void COOExToolBar::OnWindowPosChanging( LPWINDOWPOS _pWindowPos )
{
// Default processing
// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
if( m_bOldFloating != ( IsFloating()?true:false ) )
{
m_bOldFloating = !m_bOldFloating;
_pWindowPos->flags |= SWP_DRAWFRAME;
}
CToolBar::OnWindowPosChanging( _pWindowPos );
}
// @end =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
// Start =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
// MFC Overloaded method.
// The following stuff is to make the command update UI mechanism
// work properly for flat tool bars. The main idea is to convert
// a "checked" button state into a "pressed" button state. Changed
// lines marked with "PD"
// ------------------------------------------------------------------------
// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
// @mfunc: (FUNCTIONAL)
// <c CCoolCmdUI>
// Came from Paul Dilascia Article.
// @end =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
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;
// WINBUG: If a button is currently pressed and then is disabled
// COMCTL32.DLL does not unpress the button, even after the mouse
// button goes up! We work around this bug by forcing TBBS_PRESSED
// off when a button is disabled.
nNewStyle &= ~TBBS_PRESSED;
}
ASSERT( !( nNewStyle & TBBS_SEPARATOR ) );
pToolBar->SetButtonStyle( m_nIndex, nNewStyle );
}
// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
// @mfunc: (FUNCTIONAL)
// <c CCoolCmdUI>
// Came from Paul Dilascia Article.
// @end =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
void CCoolCmdUI::SetCheck( int nCheck )
{
ASSERT( nCheck >= 0 && nCheck <= 2 ); // 0=>off, 1=>on, 2=>indeterminate
CToolBar* pToolBar = ( CToolBar* ) m_pOther;
ASSERT( pToolBar != NULL );
ASSERT_KINDOF( CToolBar, pToolBar );
ASSERT( m_nIndex < m_nIndexMax );
UINT nOldStyle = pToolBar->GetButtonStyle( m_nIndex ); // PD
UINT nNewStyle = nOldStyle &
~( TBBS_PRESSED | TBBS_INDETERMINATE ); // PD
if ( nCheck == 1 )
nNewStyle |= TBBS_PRESSED; // PD
else if ( nCheck == 2 )
nNewStyle |= TBBS_INDETERMINATE;
// Following is to fix display bug for TBBS_CHECKED:
// If new state is unchecked, repaint--but only if style actually changing.
// (Otherwise will end up with flicker)
//
if ( nNewStyle != nOldStyle ) {
ASSERT( !( nNewStyle & TBBS_SEPARATOR ) );
pToolBar->SetButtonStyle( m_nIndex, nNewStyle );
pToolBar->Invalidate();
}
}
// @end =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
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);
}
//////////////////
// 1998 Microsoft Systems Journal - Paul DiLascia
// This is the all-important function that gets the true size of a button,
// instead of using m_sizeButton. And it's virtual, so you can override if
// my algorithm doesn't work, as will surely be the case in some circumstances.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -