1 /////////////////////////////////////////////////////////////////////////////
2 // Name: cocoa/control.mm
3 // Purpose: wxControl class
4 // Author: David Elliiott
8 // Copyright: (c) 2003 David Elliott
9 // Licence: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
12 #include "wx/wxprec.h"
15 #include "wx/control.h"
19 #include "wx/cocoa/autorelease.h"
21 #import <AppKit/NSControl.h>
23 IMPLEMENT_ABSTRACT_CLASS(wxControl, wxWindow)
24 BEGIN_EVENT_TABLE(wxControl, wxControlBase)
26 WX_IMPLEMENT_COCOA_OWNER(wxControl,NSControl,NSView,NSView)
28 bool wxControl::Create(wxWindow *parent, wxWindowID winid,
29 const wxPoint& pos, const wxSize& size, long style,
30 const wxValidator& validator, const wxString& name)
32 wxLogDebug("Creating control with id=%d",winid);
33 if(!CreateControl(parent,winid,pos,size,style,validator,name))
35 wxLogDebug("Created control with id=%d",GetId());
37 SetNSControl([[NSControl alloc] initWithFrame: MakeDefaultNSRect(size)]);
38 // NOTE: YES we want to release this (to match the alloc).
39 // DoAddChild(this) will retain us again since addSubView doesn't.
40 [m_cocoaNSView release];
42 [GetNSControl() sizeToFit];
45 m_parent->CocoaAddChild(this);
46 SetInitialFrameRect(pos,size);
51 wxControl::~wxControl()
53 DisassociateNSControl(GetNSControl());
56 wxSize wxControl::DoGetBestSize() const
58 wxAutoNSAutoreleasePool pool;
59 wxASSERT(m_cocoaNSView);
60 NSRect storedRect = [m_cocoaNSView frame];
61 [GetNSControl() sizeToFit];
62 NSRect cocoaRect = [m_cocoaNSView frame];
63 wxSize size((int)cocoaRect.size.width+10,(int)cocoaRect.size.height);
64 [m_cocoaNSView setFrame: storedRect];
65 wxLogDebug("wxControl=%p::DoGetBestSize()==(%d,%d)",this,size.x,size.y);
69 bool wxControl::ProcessCommand(wxCommandEvent& event)
71 return GetEventHandler()->ProcessEvent(event);
74 void wxControl::CocoaSetEnabled(bool enable)
76 [GetNSControl() setEnabled: enable];