📄 toolbar.cpp
字号:
// Find the maximum tool width and height wxToolBarToolsList::Node *node = m_tools.GetFirst(); while ( node ) { wxToolBarTool *tool = (wxToolBarTool *)node->GetData(); wxSize sz = tool->GetSize() ; if ( sz.x > maxToolWidth ) maxToolWidth = sz.x ; if (sz.y> maxToolHeight) maxToolHeight = sz.y; node = node->GetNext(); } node = m_tools.GetFirst(); while (node) { wxToolBarTool *tool = (wxToolBarTool *)node->GetData(); wxSize cursize = tool->GetSize() ; // for the moment we just do a single row/column alignement if ( x + cursize.x > maxWidth ) maxWidth = x + cursize.x ; if ( y + cursize.y > maxHeight ) maxHeight = y + cursize.y ; tool->SetPosition( wxPoint( x , y ) ) ; if ( GetWindowStyleFlag() & wxTB_VERTICAL ) { y += cursize.y ; } else { x += cursize.x ; } node = node->GetNext(); } if ( GetWindowStyleFlag() & wxTB_HORIZONTAL ) { if ( m_maxRows == 0 ) { // if not set yet, only one row SetRows(1); } maxWidth = tw ; maxHeight += m_yMargin + kwxMacToolBarTopMargin; m_maxHeight = maxHeight ; } else { if ( GetToolsCount() > 0 && m_maxRows == 0 ) { // if not set yet, have one column SetRows(GetToolsCount()); } maxHeight = th ; maxWidth += m_xMargin + kwxMacToolBarLeftMargin; m_maxWidth = maxWidth ; } SetSize(maxWidth, maxHeight); InvalidateBestSize(); return true;}void wxToolBar::SetToolBitmapSize(const wxSize& size){ m_defaultWidth = size.x+4; m_defaultHeight = size.y+4;}// The button size is bigger than the bitmap sizewxSize wxToolBar::GetToolSize() const{ return wxSize(m_defaultWidth + 4, m_defaultHeight + 4);}void wxToolBar::MacHandleControlClick( WXWidget control , wxInt16 controlpart , bool WXUNUSED( mouseStillDown ) ){ wxToolBarToolsList::Node *node; for ( node = m_tools.GetFirst(); node; node = node->GetNext() ) { wxToolBarTool* tool = (wxToolBarTool*) node->GetData() ; if ( tool->IsButton() ) { if( (WXWidget) tool->GetControlHandle() == control ) { if ( tool->CanBeToggled() ) { tool->Toggle( GetControl32BitValue( (ControlHandle) control ) ) ; } OnLeftClick( tool->GetId() , tool -> IsToggled() ) ; break ; } } }}void wxToolBar::SetRows(int nRows){ if ( nRows == m_maxRows ) { // avoid resizing the frame uselessly return; } m_maxRows = nRows;}void wxToolBar::MacSuperChangedPosition(){ wxWindow::MacSuperChangedPosition() ; Realize() ;}wxToolBarToolBase *wxToolBar::FindToolForPosition(wxCoord x, wxCoord y) const{ wxToolBarToolsList::Node *node = m_tools.GetFirst(); while (node) { wxToolBarTool *tool = (wxToolBarTool *)node->GetData() ; wxRect2DInt r( tool->GetPosition() , tool->GetSize() ) ; if ( r.Contains( wxPoint( x , y ) ) ) { return tool; } node = node->GetNext(); } return (wxToolBarToolBase *)NULL;}wxString wxToolBar::MacGetToolTipString( wxPoint &pt ){ wxToolBarToolBase* tool = FindToolForPosition( pt.x , pt.y ) ; if ( tool ) { return tool->GetShortHelp() ; } return wxEmptyString ;}void wxToolBar::DoEnableTool(wxToolBarToolBase *t, bool enable){ if (!IsShown()) return ; wxToolBarTool *tool = (wxToolBarTool *)t; if ( tool->IsControl() ) { tool->GetControl()->Enable( enable ) ; } else if ( tool->IsButton() ) { if ( enable ) UMAActivateControl( tool->GetControlHandle() ) ; else UMADeactivateControl( tool->GetControlHandle() ) ; }}void wxToolBar::DoToggleTool(wxToolBarToolBase *t, bool toggle){ if (!IsShown()) return ; wxToolBarTool *tool = (wxToolBarTool *)t; if ( tool->IsButton() ) { ::SetControl32BitValue( tool->GetControlHandle() , toggle ) ; }}bool wxToolBar::DoInsertTool(size_t WXUNUSED(pos), wxToolBarToolBase *tool){ // nothing special to do here - we relayout in Realize() later tool->Attach(this); InvalidateBestSize(); return true;}void wxToolBar::DoSetToggle(wxToolBarToolBase *WXUNUSED(tool), bool WXUNUSED(toggle)){ wxFAIL_MSG( _T("not implemented") );}bool wxToolBar::DoDeleteTool(size_t WXUNUSED(pos), wxToolBarToolBase *tool){ wxToolBarToolsList::Node *node; for ( node = m_tools.GetFirst(); node; node = node->GetNext() ) { wxToolBarToolBase *tool2 = node->GetData(); if ( tool2 == tool ) { // let node point to the next node in the list node = node->GetNext(); break; } } wxSize sz = ((wxToolBarTool*)tool)->GetSize() ; tool->Detach(); // and finally reposition all the controls after this one for ( /* node -> first after deleted */ ; node; node = node->GetNext() ) { wxToolBarTool *tool2 = (wxToolBarTool*) node->GetData(); wxPoint pt = tool2->GetPosition() ; if ( GetWindowStyleFlag() & wxTB_VERTICAL ) { pt.y -= sz.y ; } else { pt.x -= sz.x ; } tool2->SetPosition( pt ) ; } InvalidateBestSize(); return true ;}void wxToolBar::OnPaint(wxPaintEvent& event){ wxPaintDC dc(this) ; wxMacPortSetter helper(&dc) ; Rect toolbarrect = { dc.YLOG2DEVMAC(0) , dc.XLOG2DEVMAC(0) , dc.YLOG2DEVMAC(m_height) , dc.XLOG2DEVMAC(m_width) } ; UMADrawThemePlacard( &toolbarrect , IsEnabled() ? kThemeStateActive : kThemeStateInactive) ; { wxToolBarToolsList::Node *node; for ( node = m_tools.GetFirst(); node; node = node->GetNext() ) { wxToolBarTool* tool = (wxToolBarTool*) node->GetData() ; if ( tool->IsButton() ) { UMADrawControl( tool->GetControlHandle() ) ; } } }}void wxToolBar::OnMouse( wxMouseEvent &event ){ if (event.GetEventType() == wxEVT_LEFT_DOWN || event.GetEventType() == wxEVT_LEFT_DCLICK ) { int x = event.m_x ; int y = event.m_y ; MacClientToRootWindow( &x , &y ) ; ControlHandle control ; Point localwhere ; SInt16 controlpart ; WindowRef window = (WindowRef) MacGetRootWindow() ; localwhere.h = x ; localwhere.v = y ; short modifiers = 0; if ( !event.m_leftDown && !event.m_rightDown ) modifiers |= btnState ; if ( event.m_shiftDown ) modifiers |= shiftKey ; if ( event.m_controlDown ) modifiers |= controlKey ; if ( event.m_altDown ) modifiers |= optionKey ; if ( event.m_metaDown ) modifiers |= cmdKey ; controlpart = ::FindControl( localwhere , window , &control ) ; { if ( control && ::IsControlActive( control ) ) { { controlpart = ::HandleControlClick( control , localwhere , modifiers , (ControlActionUPP) -1 ) ; wxTheApp->s_lastMouseDown = 0 ; if ( control && controlpart != kControlNoPart ) // otherwise we will get the event twice { MacHandleControlClick( (WXWidget) control , controlpart , false /* not down anymore */ ) ; } } } } }}#endif // wxUSE_TOOLBAR
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -