1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/cocoa/statbox.mm
3 // Purpose: wxStaticBox
4 // Author: David Elliott
8 // Copyright: (c) 2003 David Elliott
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 #include "wx/wxprec.h"
14 #include "wx/statbox.h"
20 #include "wx/cocoa/autorelease.h"
21 #include "wx/cocoa/string.h"
23 #import <AppKit/NSBox.h>
24 #import <Foundation/NSString.h>
26 BEGIN_EVENT_TABLE(wxStaticBox, wxStaticBoxBase)
28 WX_IMPLEMENT_COCOA_OWNER(wxStaticBox,NSBox,NSView,NSView)
30 bool wxStaticBox::Create(wxWindow *parent, wxWindowID winid,
31 const wxString& title, const wxPoint& pos, const wxSize& size,
32 long style, const wxString& name)
34 wxAutoNSAutoreleasePool pool;
35 if(!CreateControl(parent,winid,pos,size,style,wxDefaultValidator,name))
38 SetNSBox([[NSBox alloc] initWithFrame:MakeDefaultNSRect(size)]);
39 CocoaSetLabelForObject(title, GetNSBox());
41 m_parent->CocoaAddChild(this);
42 SetInitialFrameRect(pos,size);
47 wxStaticBox::~wxStaticBox()
49 DisassociateNSBox(GetNSBox());
52 void wxStaticBox::GetBordersForSizer(int *borderTop, int *borderOther) const
54 NSRect contentRect = [[GetNSBox() contentView] frame];
55 NSRect thisRect = [m_cocoaNSView frame];
56 *borderTop = (int)(thisRect.size.height - (contentRect.origin.y+contentRect.size.height));
57 *borderOther = (int)(thisRect.size.width - (contentRect.origin.x+contentRect.size.width));
58 int nextBorder = (int)contentRect.origin.y;
59 if(nextBorder > *borderOther)
60 *borderOther = nextBorder;
61 nextBorder = (int)contentRect.origin.x;
62 if(nextBorder > *borderOther)
63 *borderOther = nextBorder;
66 void wxStaticBox::SetLabel(const wxString& label)
68 wxAutoNSAutoreleasePool pool;
69 CocoaSetLabelForObject(label, GetNSBox());
72 wxString wxStaticBox::GetLabel() const
74 wxAutoNSAutoreleasePool pool;
75 return wxStringWithNSString([GetNSBox() title]);