X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/7dafb55fdec4ef71567ee1ccbf16d4461df8198f..dc497201eb08e3de1402480e2ab97a6405335ecb:/src/cocoa/toolbar.mm diff --git a/src/cocoa/toolbar.mm b/src/cocoa/toolbar.mm index 03b84d6b63..bf0d2a4d5a 100644 --- a/src/cocoa/toolbar.mm +++ b/src/cocoa/toolbar.mm @@ -6,7 +6,7 @@ // Created: 2003/08/17 // RCS-ID: $Id$ // Copyright: (c) 2003 David Elliott -// Licence: wxWindows licence +// Licence: wxWidgets licence ///////////////////////////////////////////////////////////////////////////// // ============================================================================ @@ -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 -{ - wxLogDebug("wxNSActionCellAction"); - wxCocoaNSActionCell *wxcontrol = wxCocoaNSActionCell::GetFromCocoa(sender); - wxCHECK_RET(wxcontrol,"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,14 +95,23 @@ 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]; } bool wxToolBarTool::CreateButtonCell() { + wxAutoNSAutoreleasePool pool; + NSImage *nsimage = [m_bmpNormal.GetNSImage(true) retain]; m_cocoaNSButtonCell = [[NSButtonCell alloc] initTextCell:nil]; [m_cocoaNSButtonCell setImage:nsimage]; @@ -184,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; } @@ -205,6 +169,7 @@ IMPLEMENT_DYNAMIC_CLASS(wxToolBar, wxControl) void wxToolBar::Init() { m_owningFrame = NULL; + m_mouseDownTool = NULL; } wxToolBar::~wxToolBar() @@ -256,6 +221,11 @@ bool wxToolBar::DoDeleteTool(size_t WXUNUSED(pos), wxToolBarToolBase *toolBase) return true; } +bool wxToolBar::Cocoa_acceptsFirstMouse(bool &acceptsFirstMouse, WX_NSEvent theEvent) +{ + acceptsFirstMouse = true; return true; +} + bool wxToolBar::Cocoa_drawRect(const NSRect &rect) { wxToolBarToolsList::compatibility_iterator node; @@ -288,15 +258,18 @@ bool wxToolBar::Cocoa_mouseDragged(WX_NSEvent theEvent) NSButtonCell *buttonCell = m_mouseDownTool->GetNSButtonCell(); if(buttonCell) { + [buttonCell retain]; [buttonCell setHighlighted: YES]; if([buttonCell trackMouse: theEvent inRect:AddToolPadding(m_mouseDownTool->GetFrameRect()) ofView:m_cocoaNSView untilMouseUp:NO]) { + CocoaToolClickEnded(); m_mouseDownTool = NULL; - wxLogDebug("Button was clicked after drag!"); + wxLogTrace(wxTRACE_COCOA,wxT("Button was clicked after drag!")); } [buttonCell setHighlighted: NO]; + [buttonCell release]; } } return wxToolBarBase::Cocoa_mouseDragged(theEvent); @@ -310,16 +283,19 @@ bool wxToolBar::Cocoa_mouseDown(WX_NSEvent theEvent) NSButtonCell *buttonCell = tool->GetNSButtonCell(); if(buttonCell) { + [buttonCell retain]; m_mouseDownTool = tool; [buttonCell setHighlighted: YES]; if([buttonCell trackMouse: theEvent inRect:AddToolPadding(tool->GetFrameRect()) ofView:m_cocoaNSView untilMouseUp:NO]) { + CocoaToolClickEnded(); m_mouseDownTool = NULL; - wxLogDebug("Button was clicked!"); + wxLogTrace(wxTRACE_COCOA,wxT("Button was clicked!")); } [buttonCell setHighlighted: NO]; + [buttonCell release]; } } return wxToolBarBase::Cocoa_mouseDown(theEvent); @@ -327,6 +303,8 @@ bool wxToolBar::Cocoa_mouseDown(WX_NSEvent theEvent) bool wxToolBar::Realize() { + wxAutoNSAutoreleasePool pool; + wxToolBarToolsList::compatibility_iterator node; NSSize totalSize = NSZeroSize; // This is for horizontal, TODO: vertical