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 CocoaRemoveFromParent();
55 wxSize wxControl::DoGetBestSize() const
57 wxASSERT(m_cocoaNSView);
58 NSRect storedRect = [m_cocoaNSView frame];
59 [GetNSControl() sizeToFit];
60 NSRect cocoaRect = [m_cocoaNSView frame];
61 wxSize size((int)cocoaRect.size.width+10,(int)cocoaRect.size.height);
62 [m_cocoaNSView setFrame: storedRect];
63 wxLogDebug("wxControl=%p::DoGetBestSize()==(%d,%d)",this,size.x,size.y);
67 bool wxControl::ProcessCommand(wxCommandEvent& event)
69 #if WXWIN_COMPATIBILITY
72 (void)(*m_callback)(*this, event);
77 #endif // WXWIN_COMPATIBILITY
79 return GetEventHandler()->ProcessEvent(event);