X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/7c5fbe2a792c629a297111d03abde5edf6161873..74a8f67d96591cec101def2a7d47c64072aff7fd:/src/cocoa/toolbar.mm diff --git a/src/cocoa/toolbar.mm b/src/cocoa/toolbar.mm index a72e61cde4..7237864f57 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: wxWindows licence ///////////////////////////////////////////////////////////////////////////// // ============================================================================ @@ -21,8 +21,10 @@ #include "wx/wxprec.h" #if wxUSE_TOOLBAR_NATIVE + +#include "wx/toolbar.h" + #ifndef WX_PRECOMP - #include "wx/toolbar.h" #include "wx/frame.h" #include "wx/log.h" #endif // WX_PRECOMP @@ -41,54 +43,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, @@ -102,8 +60,8 @@ public: CreateButtonCell(); } - wxToolBarTool(wxToolBar *tbar, wxControl *control) - : wxToolBarToolBase(tbar, control) + wxToolBarTool(wxToolBar *tbar, wxControl *control, const wxString& label) + : wxToolBarToolBase(tbar, control, label) { Init(); } @@ -139,9 +97,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 +151,6 @@ bool wxToolBarTool::CreateButtonCell() [m_cocoaNSButtonCell setBordered:NO]; // [m_cocoaNSButtonCell setHighlightsBy:NSContentsCellMask|NSPushInCellMask]; // [m_cocoaNSButtonCell setShowsStateBy:NSContentsCellMask|NSPushInCellMask]; - AssociateNSActionCell(m_cocoaNSButtonCell); return true; } @@ -222,7 +186,13 @@ bool wxToolBar::Create( wxWindow *parent, const wxString& name ) { // Call wxControl::Create so we get a wxNonControlNSControl - return wxToolBarBase::Create(parent,winid,pos,size,style,wxDefaultValidator,name); + if ( !wxToolBarBase::Create(parent, winid, pos, size, style, + wxDefaultValidator, name) ) + return false; + + FixupStyle(); + + return true; } wxToolBarToolBase *wxToolBar::CreateTool(int toolid, @@ -238,9 +208,10 @@ wxToolBarToolBase *wxToolBar::CreateTool(int toolid, clientData, shortHelpString, longHelpString); } -wxToolBarToolBase *wxToolBar::CreateTool(wxControl *control) +wxToolBarToolBase * +wxToolBar::CreateTool(wxControl *control, const wxString& label) { - return new wxToolBarTool(this, control); + return new wxToolBarTool(this, control, label); } void wxToolBar::SetWindowStyleFlag( long style ) @@ -259,6 +230,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; @@ -291,15 +267,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); @@ -313,16 +292,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);