From: David Elliott Date: Wed, 17 Nov 2004 18:02:56 +0000 (+0000) Subject: Implement toolbar tool clicks. Get rid of wxNSActionCell stuff because X-Git-Url: https://git.saurik.com/wxWidgets.git/commitdiff_plain/e2eafeff03e55e8af173168ec4d4378f5c9d4630 Implement toolbar tool clicks. Get rid of wxNSActionCell stuff because Cells send their action from the view anyway so we'd have no way of knowing which tool was clicked. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@30592 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- diff --git a/include/wx/cocoa/toolbar.h b/include/wx/cocoa/toolbar.h index d8ccd336b9..da01f719fd 100644 --- a/include/wx/cocoa/toolbar.h +++ b/include/wx/cocoa/toolbar.h @@ -61,6 +61,7 @@ protected: virtual bool Cocoa_mouseDown(WX_NSEvent theEvent); virtual bool Cocoa_mouseDragged(WX_NSEvent theEvent); wxToolBarTool *CocoaFindToolForPosition(const NSPoint& pos) const; + void CocoaToolClickEnded(); // ------------------------------------------------------------------------ // Implementation // ------------------------------------------------------------------------ diff --git a/src/cocoa/toolbar.mm b/src/cocoa/toolbar.mm index 6ad048346d..3688f0e7b3 100644 --- a/src/cocoa/toolbar.mm +++ b/src/cocoa/toolbar.mm @@ -41,54 +41,10 @@ #include -DECLARE_WXCOCOA_OBJC_CLASS(NSActionCell); - -// ======================================================================== -// wxCocoaNSActionCell -// ======================================================================== -WX_DECLARE_OBJC_HASHMAP(NSActionCell); - -class wxCocoaNSActionCell -{ - WX_DECLARE_OBJC_INTERFACE(NSActionCell) -public: - virtual void CocoaTarget_wxNSActionCellAction() {} -protected: - static struct objc_object *sm_cocoaTarget; -}; - -// ============================================================================ -// @class wxNSActionCellTarget -// ============================================================================ -@interface wxNSActionCellTarget : NSObject -{ -} - -- (void)wxNSActionCellAction: (id)sender; -@end //interface wxNSActionCellTarget - -@implementation wxNSActionCellTarget : NSObject - -- (void)wxNSActionCellAction: (id)sender -{ - wxLogTrace(wxTRACE_COCOA,wxT("wxNSActionCellAction")); - wxCocoaNSActionCell *wxcontrol = wxCocoaNSActionCell::GetFromCocoa(sender); - wxCHECK_RET(wxcontrol,wxT("wxNSActionCellAction received but no wxCocoaNSActionCell exists!")); - wxcontrol->CocoaTarget_wxNSActionCellAction(); -} - -@end //implementation wxNSActionCellTarget - -// ======================================================================== -// wxCocoaNSActionCell -// ======================================================================== -struct objc_object *wxCocoaNSActionCell::sm_cocoaTarget = [[wxNSActionCellTarget alloc] init]; -WX_IMPLEMENT_OBJC_INTERFACE(NSActionCell) - // ======================================================================== // wxToolBarTool // ======================================================================== -class wxToolBarTool : public wxToolBarToolBase, protected wxCocoaNSActionCell +class wxToolBarTool : public wxToolBarToolBase { public: wxToolBarTool(wxToolBar *tbar, int toolid, const wxString& label, @@ -139,9 +95,16 @@ void wxToolBarTool::Init() m_frameRect = NSZeroRect; } +void wxToolBar::CocoaToolClickEnded() +{ + wxASSERT(m_mouseDownTool); + wxCommandEvent event(wxEVT_COMMAND_MENU_SELECTED, m_mouseDownTool->GetId()); + InitCommandEvent(event); + Command(event); +} + wxToolBarTool::~wxToolBarTool() { - DisassociateNSActionCell(m_cocoaNSButtonCell); [m_cocoaNSButtonCell release]; } @@ -186,7 +149,6 @@ bool wxToolBarTool::CreateButtonCell() [m_cocoaNSButtonCell setBordered:NO]; // [m_cocoaNSButtonCell setHighlightsBy:NSContentsCellMask|NSPushInCellMask]; // [m_cocoaNSButtonCell setShowsStateBy:NSContentsCellMask|NSPushInCellMask]; - AssociateNSActionCell(m_cocoaNSButtonCell); return true; } @@ -296,6 +258,7 @@ bool wxToolBar::Cocoa_mouseDragged(WX_NSEvent theEvent) inRect:AddToolPadding(m_mouseDownTool->GetFrameRect()) ofView:m_cocoaNSView untilMouseUp:NO]) { + CocoaToolClickEnded(); m_mouseDownTool = NULL; wxLogTrace(wxTRACE_COCOA,wxT("Button was clicked after drag!")); } @@ -319,6 +282,7 @@ bool wxToolBar::Cocoa_mouseDown(WX_NSEvent theEvent) inRect:AddToolPadding(tool->GetFrameRect()) ofView:m_cocoaNSView untilMouseUp:NO]) { + CocoaToolClickEnded(); m_mouseDownTool = NULL; wxLogTrace(wxTRACE_COCOA,wxT("Button was clicked!")); }