1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/cocoa/statbox.mm
3 // Purpose: wxStaticBox
4 // Author: David Elliott
7 // Copyright: (c) 2003 David Elliott
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
11 #include "wx/wxprec.h"
13 #include "wx/statbox.h"
19 #include "wx/cocoa/autorelease.h"
20 #include "wx/cocoa/string.h"
22 #import <AppKit/NSBox.h>
23 #import <Foundation/NSString.h>
25 BEGIN_EVENT_TABLE(wxStaticBox, wxStaticBoxBase)
27 WX_IMPLEMENT_COCOA_OWNER(wxStaticBox,NSBox,NSView,NSView)
29 bool wxStaticBox::Create(wxWindow *parent, wxWindowID winid,
30 const wxString& title, const wxPoint& pos, const wxSize& size,
31 long style, const wxString& name)
33 wxAutoNSAutoreleasePool pool;
34 if(!CreateControl(parent,winid,pos,size,style,wxDefaultValidator,name))
37 SetNSBox([[NSBox alloc] initWithFrame:MakeDefaultNSRect(size)]);
38 CocoaSetLabelForObject(title, GetNSBox());
40 m_parent->CocoaAddChild(this);
41 SetInitialFrameRect(pos,size);
46 wxStaticBox::~wxStaticBox()
48 DisassociateNSBox(GetNSBox());
51 void wxStaticBox::GetBordersForSizer(int *borderTop, int *borderOther) const
53 NSRect contentRect = [[GetNSBox() contentView] frame];
54 NSRect thisRect = [m_cocoaNSView frame];
55 *borderTop = (int)(thisRect.size.height - (contentRect.origin.y+contentRect.size.height));
56 *borderOther = (int)(thisRect.size.width - (contentRect.origin.x+contentRect.size.width));
57 int nextBorder = (int)contentRect.origin.y;
58 if(nextBorder > *borderOther)
59 *borderOther = nextBorder;
60 nextBorder = (int)contentRect.origin.x;
61 if(nextBorder > *borderOther)
62 *borderOther = nextBorder;
65 void wxStaticBox::SetLabel(const wxString& label)
67 wxAutoNSAutoreleasePool pool;
68 CocoaSetLabelForObject(label, GetNSBox());
71 wxString wxStaticBox::GetLabel() const
73 wxAutoNSAutoreleasePool pool;
74 return wxStringWithNSString([GetNSBox() title]);