Support precompiled headers
[wxWidgets.git] / src / cocoa / statbox.mm
1 /////////////////////////////////////////////////////////////////////////////
2 // Name:        cocoa/statbox.mm
3 // Purpose:     wxStaticBox
4 // Author:      David Elliott
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/app.h"
15     #include "wx/statbox.h"
16 #endif //WX_PRECOMP
17
18 #include "wx/cocoa/autorelease.h"
19
20 #import <AppKit/NSBox.h>
21 #import <Foundation/NSString.h>
22
23 IMPLEMENT_DYNAMIC_CLASS(wxStaticBox, wxControl)
24 BEGIN_EVENT_TABLE(wxStaticBox, wxStaticBoxBase)
25 END_EVENT_TABLE()
26 WX_IMPLEMENT_COCOA_OWNER(wxStaticBox,NSBox,NSView,NSView)
27
28 bool wxStaticBox::Create(wxWindow *parent, wxWindowID winid,
29            const wxString& title,
30            const wxPoint& pos,
31            const wxSize& size,
32            long style, const wxValidator& validator,
33            const wxString& name)
34 {
35     wxAutoNSAutoreleasePool pool;
36     if(!CreateControl(parent,winid,pos,size,style,validator,name))
37         return false;
38     m_cocoaNSView = NULL;
39     SetNSBox([[NSBox alloc] initWithFrame:MakeDefaultNSRect(size)]);
40     [GetNSBox() setTitle:[NSString stringWithCString:title.c_str()]];
41     if(m_parent)
42         m_parent->CocoaAddChild(this);
43     SetInitialFrameRect(pos,size);
44
45     return true;
46 }
47
48 wxStaticBox::~wxStaticBox()
49 {
50     DisassociateNSBox(m_cocoaNSView);
51 }
52
53 void wxStaticBox::GetBordersForSizer(int *borderTop, int *borderOther) const
54 {
55     NSRect contentRect = [[GetNSBox() contentView] frame];
56     NSRect thisRect = [m_cocoaNSView frame];
57     *borderTop = (int)(thisRect.size.height - (contentRect.origin.y+contentRect.size.height));
58     *borderOther = (int)(thisRect.size.width - (contentRect.origin.x+contentRect.size.width));
59     int nextBorder = (int)contentRect.origin.y;
60     if(nextBorder > *borderOther)
61         *borderOther = nextBorder;
62     nextBorder = (int)contentRect.origin.x;
63     if(nextBorder > *borderOther)
64         *borderOther = nextBorder;
65 }
66