]> git.saurik.com Git - wxWidgets.git/blame - src/cocoa/control.mm
Implement wxChoice including sorting and client data
[wxWidgets.git] / src / cocoa / control.mm
CommitLineData
fb896a32
DE
1/////////////////////////////////////////////////////////////////////////////
2// Name: cocoa/control.mm
3// Purpose: wxControl class
4// Author: David Elliiott
5// Modified by:
6// Created: 2003/02/15
7// RCS-ID: $Id:
8// Copyright: (c) 2003 David Elliott
9// Licence: wxWindows license
10/////////////////////////////////////////////////////////////////////////////
11
12#include "wx/wxprec.h"
13#ifndef WX_PRECOMP
14 #include "wx/defs.h"
15 #include "wx/control.h"
16 #include "wx/log.h"
17#endif
18
71bfb735
DE
19#include "wx/cocoa/autorelease.h"
20
fb896a32
DE
21#import <AppKit/NSControl.h>
22
23IMPLEMENT_ABSTRACT_CLASS(wxControl, wxWindow)
24BEGIN_EVENT_TABLE(wxControl, wxControlBase)
25END_EVENT_TABLE()
26WX_IMPLEMENT_COCOA_OWNER(wxControl,NSControl,NSView,NSView)
27
28bool wxControl::Create(wxWindow *parent, wxWindowID winid,
29 const wxPoint& pos, const wxSize& size, long style,
30 const wxValidator& validator, const wxString& name)
31{
32 wxLogDebug("Creating control with id=%d",winid);
33 if(!CreateControl(parent,winid,pos,size,style,validator,name))
34 return false;
35 wxLogDebug("Created control with id=%d",GetId());
fb896a32 36 m_cocoaNSView = NULL;
8d656ea9 37 SetNSControl([[NSControl alloc] initWithFrame: MakeDefaultNSRect(size)]);
fb896a32
DE
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];
41
42 [GetNSControl() sizeToFit];
43
44 if(m_parent)
45 m_parent->CocoaAddChild(this);
8d656ea9 46 SetInitialFrameRect(pos,size);
fb896a32
DE
47
48 return true;
49}
50
51wxControl::~wxControl()
52{
911e17c6 53 DisassociateNSControl(GetNSControl());
fb896a32
DE
54}
55
56wxSize wxControl::DoGetBestSize() const
57{
71bfb735 58 wxAutoNSAutoreleasePool pool;
fb896a32
DE
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);
66 return size;
67}
68
69bool wxControl::ProcessCommand(wxCommandEvent& event)
70{
fb896a32
DE
71 return GetEventHandler()->ProcessEvent(event);
72}
73
c5172ed1
DE
74void wxControl::CocoaSetEnabled(bool enable)
75{
76 [GetNSControl() setEnabled: enable];
77}
78