⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 toolbar.cpp

📁 很牛的GUI源码wxWidgets-2.8.0.zip 可在多种平台下运行.
💻 CPP
📖 第 1 页 / 共 4 页
字号:
/////////////////////////////////////////////////////////////////////////////// Name:        src/mac/carbon/toolbar.cpp// Purpose:     wxToolBar// Author:      Stefan Csomor// Modified by:// Created:     04/01/98// RCS-ID:      $Id: toolbar.cpp,v 1.116 2006/12/10 13:19:50 SC Exp $// Copyright:   (c) Stefan Csomor// Licence:     wxWindows licence/////////////////////////////////////////////////////////////////////////////#include "wx/wxprec.h"#if wxUSE_TOOLBAR#include "wx/toolbar.h"#ifndef WX_PRECOMP    #include "wx/wx.h"#endif#include "wx/app.h"#include "wx/mac/uma.h"#include "wx/geometry.h"#ifdef __WXMAC_OSX__const short kwxMacToolBarToolDefaultWidth = 16;const short kwxMacToolBarToolDefaultHeight = 16;const short kwxMacToolBarTopMargin = 4;const short kwxMacToolBarLeftMargin =  4;const short kwxMacToolBorder = 0;const short kwxMacToolSpacing = 6;#elseconst short kwxMacToolBarToolDefaultWidth = 24;const short kwxMacToolBarToolDefaultHeight = 22;const short kwxMacToolBarTopMargin = 2;const short kwxMacToolBarLeftMargin = 2;const short kwxMacToolBorder = 4;const short kwxMacToolSpacing = 0;#endifIMPLEMENT_DYNAMIC_CLASS(wxToolBar, wxControl)BEGIN_EVENT_TABLE(wxToolBar, wxToolBarBase)    EVT_PAINT( wxToolBar::OnPaint )END_EVENT_TABLE()#pragma mark -#pragma mark Tool Implementation// ----------------------------------------------------------------------------// private classes// ----------------------------------------------------------------------------// We have a dual implementation for each tool, ControlRef and HIToolbarItemRefclass wxToolBarTool : public wxToolBarToolBase{public:    wxToolBarTool(        wxToolBar *tbar,        int id,        const wxString& label,        const wxBitmap& bmpNormal,        const wxBitmap& bmpDisabled,        wxItemKind kind,        wxObject *clientData,        const wxString& shortHelp,        const wxString& longHelp );    wxToolBarTool(wxToolBar *tbar, wxControl *control)        : wxToolBarToolBase(tbar, control)    {        Init();        if (control != NULL)            SetControlHandle( (ControlRef) control->GetHandle() );    }    virtual ~wxToolBarTool()    {        ClearControl();    }    WXWidget GetControlHandle()    {        return (WXWidget) m_controlHandle;    }    void SetControlHandle( ControlRef handle )    {        m_controlHandle = handle;    }    void SetPosition( const wxPoint& position );    void ClearControl()    {        m_control = NULL;        if ( m_controlHandle )        {            if ( !IsControl() )                DisposeControl( m_controlHandle );            else            {                // the embedded control is not under the responsibility of the tool            }            m_controlHandle = NULL ;        }#if wxMAC_USE_NATIVE_TOOLBAR        if ( m_toolbarItemRef )        {            CFIndex count = CFGetRetainCount( m_toolbarItemRef ) ;            wxASSERT_MSG( count == 1 , wxT("Reference Count of native tool was not 1 in wxToolBarTool destructor") );            wxTheApp->MacAddToAutorelease(m_toolbarItemRef);            CFRelease(m_toolbarItemRef);            m_toolbarItemRef = NULL;        }#endif    }    wxSize GetSize() const    {        wxSize curSize;        if ( IsControl() )        {            curSize = GetControl()->GetSize();        }        else if ( IsButton() )        {            curSize = GetToolBar()->GetToolSize();        }        else        {            // separator size            curSize = GetToolBar()->GetToolSize();            if ( GetToolBar()->GetWindowStyleFlag() & wxTB_VERTICAL )                curSize.y /= 4;            else                curSize.x /= 4;        }        return curSize;    }    wxPoint GetPosition() const    {        return wxPoint( m_x, m_y );    }    bool DoEnable( bool enable );    void UpdateToggleImage( bool toggle );#if wxMAC_USE_NATIVE_TOOLBAR    void SetToolbarItemRef( HIToolbarItemRef ref )    {        if ( m_controlHandle )            HideControl( m_controlHandle );        if ( m_toolbarItemRef )            CFRelease( m_toolbarItemRef );        m_toolbarItemRef = ref;        if ( m_toolbarItemRef )        {            HIToolbarItemSetHelpText(                m_toolbarItemRef,                wxMacCFStringHolder( GetShortHelp(), GetToolBar()->GetFont().GetEncoding() ),                wxMacCFStringHolder( GetLongHelp(), GetToolBar()->GetFont().GetEncoding() ) );        }    }    HIToolbarItemRef GetToolbarItemRef() const    {        return m_toolbarItemRef;    }    void SetIndex( CFIndex idx )    {        m_index = idx;    }    CFIndex GetIndex() const    {        return m_index;    }#endifprivate:    void Init()    {        m_controlHandle = NULL;#if wxMAC_USE_NATIVE_TOOLBAR        m_toolbarItemRef = NULL;        m_index = -1;#endif    }    ControlRef m_controlHandle;    wxCoord     m_x;    wxCoord     m_y;#if wxMAC_USE_NATIVE_TOOLBAR    HIToolbarItemRef m_toolbarItemRef;    // position in its toolbar, -1 means not inserted    CFIndex m_index;#endif};static const EventTypeSpec eventList[] ={    { kEventClassControl, kEventControlHit },#ifdef __WXMAC_OSX__    { kEventClassControl, kEventControlHitTest },#endif};static pascal OSStatus wxMacToolBarToolControlEventHandler( EventHandlerCallRef handler, EventRef event, void *data ){    OSStatus result = eventNotHandledErr;    ControlRef controlRef;    wxMacCarbonEvent cEvent( event );    cEvent.GetParameter( kEventParamDirectObject, &controlRef );    switch ( GetEventKind( event ) )    {        case kEventControlHit:            {                wxToolBarTool *tbartool = (wxToolBarTool*)data;                wxToolBar *tbar = tbartool != NULL ? (wxToolBar*) (tbartool->GetToolBar()) : NULL;                if ((tbartool != NULL) && tbartool->CanBeToggled())                {                    bool    shouldToggle;#ifdef __WXMAC_OSX__                    shouldToggle = !tbartool->IsToggled();#else                    shouldToggle = (GetControl32BitValue( (ControlRef)(tbartool->GetControlHandle()) ) != 0);#endif                    tbar->ToggleTool( tbartool->GetId(), shouldToggle );                }                if (tbartool != NULL)                    tbar->OnLeftClick( tbartool->GetId(), tbartool->IsToggled() );                result = noErr;            }            break;#ifdef __WXMAC_OSX__        case kEventControlHitTest:            {                HIPoint pt = cEvent.GetParameter<HIPoint>(kEventParamMouseLocation);                HIRect rect;                HIViewGetBounds( controlRef, &rect );                ControlPartCode pc = kControlNoPart;                if ( CGRectContainsPoint( rect, pt ) )                    pc = kControlIconPart;                cEvent.SetParameter( kEventParamControlPart, typeControlPartCode, pc );                result = noErr;            }            break;#endif        default:            break;    }    return result;}static pascal OSStatus wxMacToolBarToolEventHandler( EventHandlerCallRef handler, EventRef event, void *data ){    OSStatus result = eventNotHandledErr;    switch ( GetEventClass( event ) )    {        case kEventClassControl:            result = wxMacToolBarToolControlEventHandler( handler, event, data );            break;        default:            break;    }    return result;}DEFINE_ONE_SHOT_HANDLER_GETTER( wxMacToolBarToolEventHandler )#if wxMAC_USE_NATIVE_TOOLBARstatic const EventTypeSpec toolBarEventList[] ={    { kEventClassToolbarItem, kEventToolbarItemPerformAction },};static pascal OSStatus wxMacToolBarCommandEventHandler( EventHandlerCallRef handler, EventRef event, void *data ){    OSStatus result = eventNotHandledErr;    switch ( GetEventKind( event ) )    {        case kEventToolbarItemPerformAction:            {                wxToolBarTool* tbartool = (wxToolBarTool*) data;                if ( tbartool != NULL )                {                    wxToolBar *tbar = (wxToolBar*)(tbartool->GetToolBar());                    int toolID = tbartool->GetId();                    if ( tbartool->CanBeToggled() )                    {                        if ( tbar != NULL )                            tbar->ToggleTool(toolID, !tbartool->IsToggled() );                    }                    if ( tbar != NULL )                        tbar->OnLeftClick( toolID, tbartool->IsToggled() );                    result = noErr;                }            }            break;        default:            break;    }    return result;}static pascal OSStatus wxMacToolBarEventHandler( EventHandlerCallRef handler, EventRef event, void *data ){    OSStatus result = eventNotHandledErr;    switch ( GetEventClass( event ) )    {        case kEventClassToolbarItem:            result = wxMacToolBarCommandEventHandler( handler, event, data );            break;        default:            break;    }    return result;}DEFINE_ONE_SHOT_HANDLER_GETTER( wxMacToolBarEventHandler )#endifbool wxToolBarTool::DoEnable( bool enable ){    if ( IsControl() )    {        GetControl()->Enable( enable );    }    else if ( IsButton() )    {#if wxMAC_USE_NATIVE_TOOLBAR        if ( m_toolbarItemRef != NULL )            HIToolbarItemSetEnabled( m_toolbarItemRef, enable );#endif        if ( m_controlHandle != NULL )        {#if TARGET_API_MAC_OSX            if ( enable )                EnableControl( m_controlHandle );            else                DisableControl( m_controlHandle );#else            if ( enable )                ActivateControl( m_controlHandle );            else                DeactivateControl( m_controlHandle );#endif        }    }    return true;}void wxToolBarTool::SetPosition( const wxPoint& position ){    m_x = position.x;    m_y = position.y;    int mac_x = position.x;    int mac_y = position.y;    if ( IsButton() )    {        Rect contrlRect;        GetControlBounds( m_controlHandle, &contrlRect );        int former_mac_x = contrlRect.left;        int former_mac_y = contrlRect.top;        GetToolBar()->GetToolSize();        if ( mac_x != former_mac_x || mac_y != former_mac_y )        {            UMAMoveControl( m_controlHandle, mac_x, mac_y );        }    }    else if ( IsControl() )    {        // embedded native controls are moved by the OS#if wxMAC_USE_NATIVE_TOOLBAR        if ( ((wxToolBar*)GetToolBar())->MacWantsNativeToolbar() == false )#endif        {

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -