]> git.saurik.com Git - wxWidgets.git/blame - src/cocoa/control.mm
mingw compilation fix
[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
19#import <AppKit/NSControl.h>
20
21IMPLEMENT_ABSTRACT_CLASS(wxControl, wxWindow)
22BEGIN_EVENT_TABLE(wxControl, wxControlBase)
23END_EVENT_TABLE()
24WX_IMPLEMENT_COCOA_OWNER(wxControl,NSControl,NSView,NSView)
25
26bool wxControl::Create(wxWindow *parent, wxWindowID winid,
27 const wxPoint& pos, const wxSize& size, long style,
28 const wxValidator& validator, const wxString& name)
29{
30 wxLogDebug("Creating control with id=%d",winid);
31 if(!CreateControl(parent,winid,pos,size,style,validator,name))
32 return false;
33 wxLogDebug("Created control with id=%d",GetId());
34 NSRect cocoaRect = NSMakeRect(10,10,20,20);
35 m_cocoaNSView = NULL;
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];
40
41 [GetNSControl() sizeToFit];
42
43 if(m_parent)
44 m_parent->CocoaAddChild(this);
45
46 return true;
47}
48
49wxControl::~wxControl()
50{
51 CocoaRemoveFromParent();
52 SetNSControl(NULL);
53}
54
55wxSize wxControl::DoGetBestSize() const
56{
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);
64 return size;
65}
66
67bool wxControl::ProcessCommand(wxCommandEvent& event)
68{
69#if WXWIN_COMPATIBILITY
70 if ( m_callback )
71 {
72 (void)(*m_callback)(*this, event);
73
74 return TRUE;
75 }
76 else
77#endif // WXWIN_COMPATIBILITY
78
79 return GetEventHandler()->ProcessEvent(event);
80}
81