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 #import <AppKit/NSControl.h>
21 IMPLEMENT_ABSTRACT_CLASS(wxControl, wxWindow)
22 BEGIN_EVENT_TABLE(wxControl, wxControlBase)
24 WX_IMPLEMENT_COCOA_OWNER(wxControl,NSControl,NSView,NSView)
26 bool wxControl::Create(wxWindow *parent, wxWindowID winid,
27 const wxPoint& pos, const wxSize& size, long style,
28 const wxValidator& validator, const wxString& name)
30 wxLogDebug("Creating control with id=%d",winid);
31 if(!CreateControl(parent,winid,pos,size,style,validator,name))
33 wxLogDebug("Created control with id=%d",GetId());
34 NSRect cocoaRect = NSMakeRect(10,10,20,20);
36 SetNSControl([[NSControl alloc] initWithFrame: cocoaRect]);
37 // NOTE: YES we want to release this (to match the alloc).
38 // DoAddChild(this) will retain us again since addSubView doesn't.
39 [m_cocoaNSView release];
41 [GetNSControl() sizeToFit];
44 m_parent->CocoaAddChild(this);
49 wxControl::~wxControl()
51 DisassociateNSControl(m_cocoaNSView);
54 wxSize wxControl::DoGetBestSize() const
56 wxASSERT(m_cocoaNSView);
57 NSRect storedRect = [m_cocoaNSView frame];
58 [GetNSControl() sizeToFit];
59 NSRect cocoaRect = [m_cocoaNSView frame];
60 wxSize size((int)cocoaRect.size.width+10,(int)cocoaRect.size.height);
61 [m_cocoaNSView setFrame: storedRect];
62 wxLogDebug("wxControl=%p::DoGetBestSize()==(%d,%d)",this,size.x,size.y);
66 bool wxControl::ProcessCommand(wxCommandEvent& event)
68 #if WXWIN_COMPATIBILITY
71 (void)(*m_callback)(*this, event);
76 #endif // WXWIN_COMPATIBILITY
78 return GetEventHandler()->ProcessEvent(event);