]>
Commit | Line | Data |
---|---|---|
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 | ||
23 | IMPLEMENT_ABSTRACT_CLASS(wxControl, wxWindow) | |
24 | BEGIN_EVENT_TABLE(wxControl, wxControlBase) | |
25 | END_EVENT_TABLE() | |
26 | WX_IMPLEMENT_COCOA_OWNER(wxControl,NSControl,NSView,NSView) | |
27 | ||
28 | bool 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 | ||
51 | wxControl::~wxControl() | |
52 | { | |
570aaadf | 53 | DisassociateNSControl(m_cocoaNSView); |
fb896a32 DE |
54 | } |
55 | ||
56 | wxSize 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 | ||
69 | bool wxControl::ProcessCommand(wxCommandEvent& event) | |
70 | { | |
71 | #if WXWIN_COMPATIBILITY | |
72 | if ( m_callback ) | |
73 | { | |
74 | (void)(*m_callback)(*this, event); | |
75 | ||
76 | return TRUE; | |
77 | } | |
78 | else | |
79 | #endif // WXWIN_COMPATIBILITY | |
80 | ||
81 | return GetEventHandler()->ProcessEvent(event); | |
82 | } | |
83 |