]> git.saurik.com Git - wxWidgets.git/blame - src/cocoa/frame.mm
regenerated makefiles
[wxWidgets.git] / src / cocoa / frame.mm
CommitLineData
fb896a32
DE
1/////////////////////////////////////////////////////////////////////////////
2// Name: cocoa/frame.mm
3// Purpose: wxFrame
4// Author: David Elliott
5// Modified by:
6// Created: 2003/03/16
7// RCS-ID: $Id:
8// Copyright: (c) 2003 David Elliott
9// Licence: wxWindows license
10/////////////////////////////////////////////////////////////////////////////
11
12#include "wx/frame.h"
13#include "wx/menu.h"
14#include "wx/menuitem.h"
15#include "wx/app.h"
16#include "wx/log.h"
a58a6614 17#include "wx/statusbr.h"
448cbf1d 18#include "wx/toolbar.h"
fb896a32 19
7fc77f30
DE
20#include "wx/cocoa/autorelease.h"
21
fb896a32
DE
22#import <AppKit/NSWindow.h>
23#import <AppKit/NSApplication.h>
448cbf1d 24#import <AppKit/NSView.h>
fb896a32
DE
25
26// wxFrame
27
28BEGIN_EVENT_TABLE(wxFrame, wxFrameBase)
29END_EVENT_TABLE()
30
31IMPLEMENT_DYNAMIC_CLASS(wxFrame, wxTopLevelWindow)
32
33void wxFrame::Init()
34{
448cbf1d 35 m_frameNSView = nil;
fb896a32
DE
36}
37
38bool wxFrame::Create(wxWindow *parent,
39 wxWindowID winid,
40 const wxString& title,
41 const wxPoint& pos,
42 const wxSize& size,
43 long style,
44 const wxString& name)
45{
46 bool rt = wxTopLevelWindow::Create(parent,winid,title,pos,size,style,name);
47
48 return rt;
49}
50
51wxFrame::~wxFrame()
52{
448cbf1d 53 [m_frameNSView release];
fb896a32
DE
54}
55
56void wxFrame::Cocoa_wxMenuItemAction(wxMenuItem& item)
57{
58 Command(item.GetId());
59}
60
61void wxFrame::AttachMenuBar(wxMenuBar *mbar)
62{
63 wxFrameBase::AttachMenuBar(mbar);
64 if(m_frameMenuBar)
65 {
66 wxLogDebug("Attached menu");
67 [m_cocoaNSWindow setMenu:m_frameMenuBar->GetNSMenu()];
68 }
69}
70
71void wxFrame::DetachMenuBar()
72{
73 if(m_frameMenuBar)
74 {
75 [m_cocoaNSWindow setMenu:nil];
76 }
77 wxFrameBase::DetachMenuBar();
78}
79
80bool wxFrame::Show(bool show)
81{
7fc77f30 82 wxAutoNSAutoreleasePool pool;
fb896a32
DE
83 bool ret = wxFrameBase::Show(show);
84 if(show && GetMenuBar())
85 [wxTheApp->GetNSApplication() setMenu:GetMenuBar()->GetNSMenu() ];
86 return ret;
87}
88
89wxPoint wxFrame::GetClientAreaOrigin() const
90{
91 return wxPoint(0,0);
92}
93
e08efb8d 94void wxFrame::CocoaSetWxWindowSize(int width, int height)
a58a6614 95{
e08efb8d 96 if(m_frameStatusBar)
a58a6614 97 height += m_frameStatusBar->GetSize().y;
e08efb8d
DE
98 if(m_frameToolBar)
99 height += m_frameToolBar->GetSize().y;
100 wxTopLevelWindow::CocoaSetWxWindowSize(width,height);
a58a6614
DE
101}
102
448cbf1d
DE
103void wxFrame::CocoaReplaceView(WX_NSView oldView, WX_NSView newView)
104{
105 // If we have the additional toolbar/statbar view, then the
106 // default replaceSubview will work. Otherwise, the old view
107 // should be the content view and should be replaced that way
108 if(m_frameNSView)
109 wxWindow::CocoaReplaceView(oldView, newView);
110 else
111 wxTopLevelWindow::CocoaReplaceView(oldView, newView);
112}
113
114void wxFrame::UpdateFrameNSView()
115{
116 if(!m_frameNSView)
117 {
118 m_frameNSView = [[NSView alloc] initWithFrame:[[m_cocoaNSWindow contentView] frame]];
119 [m_cocoaNSWindow setContentView: m_frameNSView];
120 [m_frameNSView addSubview:m_cocoaNSView];
121 }
122 NSRect frameRect = [m_frameNSView frame];
123 float tbarheight = 0.0;
124 if(m_frameToolBar)
125 {
126 NSView *tbarNSView = m_frameToolBar->GetNSViewForSuperview();
127 if(![tbarNSView superview])
128 [m_frameNSView addSubview: tbarNSView];
129 NSRect tbarRect = [tbarNSView frame];
130 tbarRect.size.width = frameRect.size.width;
131 tbarRect.origin.x = 0.0;
132 tbarRect.origin.y = frameRect.size.height - tbarRect.size.height;
133 [tbarNSView setFrame:tbarRect];
134 // width expands, bottom margin expands
135 [tbarNSView setAutoresizingMask: NSViewWidthSizable|NSViewMinYMargin];
136 tbarheight = tbarRect.size.height;
137 }
138 float sbarheight = 0.0;
139 if(m_frameStatusBar)
140 {
141 NSView *sbarNSView = m_frameStatusBar->GetNSViewForSuperview();
142 if(![sbarNSView superview])
143 [m_frameNSView addSubview: sbarNSView];
144 NSRect sbarRect = [sbarNSView frame];
145 sbarRect.size.width = frameRect.size.width;
146 sbarRect.origin.x = 0.0;
147 sbarRect.origin.y = 0.0;
148 [sbarNSView setFrame:sbarRect];
149 // width expands, top margin expands
150 [sbarNSView setAutoresizingMask: NSViewWidthSizable|NSViewMaxYMargin];
151 sbarheight = sbarRect.size.height;
152 }
153 wxLogDebug("frame height=%f, tbar=%f, sbar=%f",frameRect.size.height,tbarheight,sbarheight);
154 NSRect innerRect = [m_cocoaNSView frame];
155 innerRect.size.height = frameRect.size.height - tbarheight - sbarheight;
156 innerRect.origin.y = sbarheight;
157 [m_cocoaNSView setFrame:innerRect];
158 [m_cocoaNSView setAutoresizingMask: NSViewWidthSizable|NSViewHeightSizable];
159 // Don't let the frame get smaller than the toolbar+statusbar height
160 NSRect frameMinRect = [NSWindow frameRectForContentRect:
161 NSMakeRect(0.0,0.0,0.0,tbarheight+sbarheight)
162 styleMask: [m_cocoaNSWindow styleMask]];
163 [m_cocoaNSWindow setMinSize:frameMinRect.size];
164}
165
166void wxFrame::SetStatusBar(wxStatusBar *statusbar)
167{
168 if(m_frameStatusBar)
169 {
170 [m_frameStatusBar->GetNSViewForSuperview() removeFromSuperview];
c5bd9191 171 [m_frameStatusBar->GetNSViewForSuperview() setAutoresizingMask: NSViewMinYMargin];
448cbf1d
DE
172 if(m_frameStatusBar->GetParent())
173 m_frameStatusBar->GetParent()->CocoaAddChild(m_frameToolBar);
174 }
175 m_frameStatusBar = statusbar;
176 if(m_frameStatusBar)
177 {
178 m_frameStatusBar->CocoaRemoveFromParent();
179 }
180 UpdateFrameNSView();
181}
182
183wxStatusBar* wxFrame::CreateStatusBar(int number,
184 long style,
185 wxWindowID winid,
186 const wxString& name)
a58a6614 187{
448cbf1d
DE
188 wxFrameBase::CreateStatusBar(number,style,winid,name);
189 if(m_frameStatusBar)
190 {
191 m_frameStatusBar->CocoaRemoveFromParent();
192 }
193 UpdateFrameNSView();
194 return m_frameStatusBar;
195}
a58a6614 196
448cbf1d
DE
197void wxFrame::SetToolBar(wxToolBar *toolbar)
198{
199 if(m_frameToolBar)
200 {
201 [m_frameToolBar->GetNSViewForSuperview() removeFromSuperview];
c5bd9191 202 [m_frameToolBar->GetNSViewForSuperview() setAutoresizingMask: NSViewMinYMargin];
448cbf1d
DE
203 if(m_frameToolBar->GetParent())
204 m_frameToolBar->GetParent()->CocoaAddChild(m_frameToolBar);
205 }
206 m_frameToolBar = toolbar;
207 if(m_frameToolBar)
208 {
209 m_frameToolBar->CocoaRemoveFromParent();
210 }
211 UpdateFrameNSView();
212}
a58a6614 213
448cbf1d
DE
214wxToolBar* wxFrame::CreateToolBar(long style,
215 wxWindowID winid,
216 const wxString& name)
217{
218 wxFrameBase::CreateToolBar(style,winid,name);
219 if(m_frameToolBar)
220 {
221 m_frameToolBar->CocoaRemoveFromParent();
222 }
223 UpdateFrameNSView();
224 return m_frameToolBar;
225}
a58a6614 226
448cbf1d
DE
227void wxFrame::PositionStatusBar()
228{
a58a6614
DE
229}
230