]>
Commit | Line | Data |
---|---|---|
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 | ||
26785f01 DE |
12 | #include "wx/wxprec.h" |
13 | #ifndef WX_PRECOMP | |
14 | #include "wx/log.h" | |
15 | #include "wx/app.h" | |
16 | #include "wx/frame.h" | |
17 | #include "wx/menu.h" | |
18 | #include "wx/toolbar.h" | |
19 | #include "wx/statusbr.h" | |
20 | #endif // WX_PRECOMP | |
21 | ||
7fc77f30 | 22 | #include "wx/cocoa/autorelease.h" |
24c7767f | 23 | #include "wx/cocoa/mbarman.h" |
7fc77f30 | 24 | |
fb896a32 DE |
25 | #import <AppKit/NSWindow.h> |
26 | #import <AppKit/NSApplication.h> | |
448cbf1d | 27 | #import <AppKit/NSView.h> |
fb896a32 DE |
28 | |
29 | // wxFrame | |
30 | ||
31 | BEGIN_EVENT_TABLE(wxFrame, wxFrameBase) | |
32 | END_EVENT_TABLE() | |
33 | ||
34 | IMPLEMENT_DYNAMIC_CLASS(wxFrame, wxTopLevelWindow) | |
35 | ||
36 | void wxFrame::Init() | |
37 | { | |
448cbf1d | 38 | m_frameNSView = nil; |
fb896a32 DE |
39 | } |
40 | ||
41 | bool wxFrame::Create(wxWindow *parent, | |
42 | wxWindowID winid, | |
43 | const wxString& title, | |
44 | const wxPoint& pos, | |
45 | const wxSize& size, | |
46 | long style, | |
47 | const wxString& name) | |
48 | { | |
49 | bool rt = wxTopLevelWindow::Create(parent,winid,title,pos,size,style,name); | |
50 | ||
51 | return rt; | |
52 | } | |
53 | ||
54 | wxFrame::~wxFrame() | |
55 | { | |
448cbf1d | 56 | [m_frameNSView release]; |
fb896a32 DE |
57 | } |
58 | ||
fb896a32 DE |
59 | void wxFrame::AttachMenuBar(wxMenuBar *mbar) |
60 | { | |
61 | wxFrameBase::AttachMenuBar(mbar); | |
243f5c2d | 62 | wxMenuBarManager::GetInstance()->UpdateMenuBar(); |
fb896a32 DE |
63 | } |
64 | ||
65 | void wxFrame::DetachMenuBar() | |
66 | { | |
fb896a32 | 67 | wxFrameBase::DetachMenuBar(); |
243f5c2d | 68 | wxMenuBarManager::GetInstance()->UpdateMenuBar(); |
fb896a32 DE |
69 | } |
70 | ||
24c7767f | 71 | void wxFrame::SetMenuBar(wxMenuBar *menubar) |
fb896a32 | 72 | { |
24c7767f DE |
73 | if ( menubar == GetMenuBar() ) |
74 | { | |
75 | // nothing to do | |
76 | return; | |
77 | } | |
78 | ||
79 | wxFrameBase::DetachMenuBar(); | |
80 | wxFrameBase::AttachMenuBar(menubar); | |
243f5c2d | 81 | wxMenuBarManager::GetInstance()->UpdateMenuBar(); |
fb896a32 DE |
82 | } |
83 | ||
8ded703d | 84 | wxMenuBar* wxFrame::GetAppMenuBar(wxCocoaNSWindow *win) |
3e84f98f DE |
85 | { |
86 | if(GetMenuBar()) | |
87 | return GetMenuBar(); | |
8ded703d | 88 | return wxFrameBase::GetAppMenuBar(win); |
3e84f98f DE |
89 | } |
90 | ||
fb896a32 DE |
91 | wxPoint wxFrame::GetClientAreaOrigin() const |
92 | { | |
93 | return wxPoint(0,0); | |
94 | } | |
95 | ||
e08efb8d | 96 | void wxFrame::CocoaSetWxWindowSize(int width, int height) |
a58a6614 | 97 | { |
e08efb8d | 98 | if(m_frameStatusBar) |
a58a6614 | 99 | height += m_frameStatusBar->GetSize().y; |
26785f01 | 100 | #if wxUSE_TOOLBAR |
e08efb8d DE |
101 | if(m_frameToolBar) |
102 | height += m_frameToolBar->GetSize().y; | |
26785f01 | 103 | #endif //wxUSE_TOOLBAR |
e08efb8d | 104 | wxTopLevelWindow::CocoaSetWxWindowSize(width,height); |
a58a6614 DE |
105 | } |
106 | ||
514e7b7b DE |
107 | WX_NSView wxFrame::GetNonClientNSView() |
108 | { | |
109 | if(m_frameNSView) | |
110 | return m_frameNSView; | |
111 | return GetNSViewForSuperview(); | |
112 | } | |
113 | ||
448cbf1d DE |
114 | void wxFrame::CocoaReplaceView(WX_NSView oldView, WX_NSView newView) |
115 | { | |
116 | // If we have the additional toolbar/statbar view, then the | |
117 | // default replaceSubview will work. Otherwise, the old view | |
118 | // should be the content view and should be replaced that way | |
119 | if(m_frameNSView) | |
120 | wxWindow::CocoaReplaceView(oldView, newView); | |
121 | else | |
122 | wxTopLevelWindow::CocoaReplaceView(oldView, newView); | |
123 | } | |
124 | ||
125 | void wxFrame::UpdateFrameNSView() | |
126 | { | |
127 | if(!m_frameNSView) | |
128 | { | |
129 | m_frameNSView = [[NSView alloc] initWithFrame:[[m_cocoaNSWindow contentView] frame]]; | |
130 | [m_cocoaNSWindow setContentView: m_frameNSView]; | |
131 | [m_frameNSView addSubview:m_cocoaNSView]; | |
132 | } | |
133 | NSRect frameRect = [m_frameNSView frame]; | |
134 | float tbarheight = 0.0; | |
26785f01 | 135 | #if wxUSE_TOOLBAR |
448cbf1d DE |
136 | if(m_frameToolBar) |
137 | { | |
138 | NSView *tbarNSView = m_frameToolBar->GetNSViewForSuperview(); | |
139 | if(![tbarNSView superview]) | |
140 | [m_frameNSView addSubview: tbarNSView]; | |
6613dc3f DE |
141 | // Do this after addSubView so that SetSize can work |
142 | m_frameToolBar->SetSize(m_frameToolBar->DoGetBestSize()); | |
448cbf1d DE |
143 | NSRect tbarRect = [tbarNSView frame]; |
144 | tbarRect.size.width = frameRect.size.width; | |
145 | tbarRect.origin.x = 0.0; | |
146 | tbarRect.origin.y = frameRect.size.height - tbarRect.size.height; | |
147 | [tbarNSView setFrame:tbarRect]; | |
148 | // width expands, bottom margin expands | |
149 | [tbarNSView setAutoresizingMask: NSViewWidthSizable|NSViewMinYMargin]; | |
150 | tbarheight = tbarRect.size.height; | |
151 | } | |
26785f01 | 152 | #endif //wxUSE_TOOLBAR |
448cbf1d DE |
153 | float sbarheight = 0.0; |
154 | if(m_frameStatusBar) | |
155 | { | |
156 | NSView *sbarNSView = m_frameStatusBar->GetNSViewForSuperview(); | |
157 | if(![sbarNSView superview]) | |
158 | [m_frameNSView addSubview: sbarNSView]; | |
159 | NSRect sbarRect = [sbarNSView frame]; | |
160 | sbarRect.size.width = frameRect.size.width; | |
161 | sbarRect.origin.x = 0.0; | |
162 | sbarRect.origin.y = 0.0; | |
163 | [sbarNSView setFrame:sbarRect]; | |
164 | // width expands, top margin expands | |
165 | [sbarNSView setAutoresizingMask: NSViewWidthSizable|NSViewMaxYMargin]; | |
166 | sbarheight = sbarRect.size.height; | |
167 | } | |
2b030203 | 168 | wxLogDebug(wxT("frame height=%f, tbar=%f, sbar=%f"),frameRect.size.height,tbarheight,sbarheight); |
448cbf1d DE |
169 | NSRect innerRect = [m_cocoaNSView frame]; |
170 | innerRect.size.height = frameRect.size.height - tbarheight - sbarheight; | |
171 | innerRect.origin.y = sbarheight; | |
172 | [m_cocoaNSView setFrame:innerRect]; | |
173 | [m_cocoaNSView setAutoresizingMask: NSViewWidthSizable|NSViewHeightSizable]; | |
174 | // Don't let the frame get smaller than the toolbar+statusbar height | |
175 | NSRect frameMinRect = [NSWindow frameRectForContentRect: | |
176 | NSMakeRect(0.0,0.0,0.0,tbarheight+sbarheight) | |
177 | styleMask: [m_cocoaNSWindow styleMask]]; | |
178 | [m_cocoaNSWindow setMinSize:frameMinRect.size]; | |
179 | } | |
180 | ||
181 | void wxFrame::SetStatusBar(wxStatusBar *statusbar) | |
182 | { | |
183 | if(m_frameStatusBar) | |
184 | { | |
185 | [m_frameStatusBar->GetNSViewForSuperview() removeFromSuperview]; | |
c5bd9191 | 186 | [m_frameStatusBar->GetNSViewForSuperview() setAutoresizingMask: NSViewMinYMargin]; |
448cbf1d | 187 | if(m_frameStatusBar->GetParent()) |
26785f01 | 188 | m_frameStatusBar->GetParent()->CocoaAddChild(m_frameStatusBar); |
448cbf1d DE |
189 | } |
190 | m_frameStatusBar = statusbar; | |
191 | if(m_frameStatusBar) | |
192 | { | |
193 | m_frameStatusBar->CocoaRemoveFromParent(); | |
194 | } | |
195 | UpdateFrameNSView(); | |
196 | } | |
197 | ||
198 | wxStatusBar* wxFrame::CreateStatusBar(int number, | |
199 | long style, | |
200 | wxWindowID winid, | |
201 | const wxString& name) | |
a58a6614 | 202 | { |
e1f4ff6d | 203 | wxAutoNSAutoreleasePool pool; |
448cbf1d DE |
204 | wxFrameBase::CreateStatusBar(number,style,winid,name); |
205 | if(m_frameStatusBar) | |
206 | { | |
207 | m_frameStatusBar->CocoaRemoveFromParent(); | |
208 | } | |
209 | UpdateFrameNSView(); | |
210 | return m_frameStatusBar; | |
211 | } | |
a58a6614 | 212 | |
26785f01 | 213 | #if wxUSE_TOOLBAR |
448cbf1d DE |
214 | void wxFrame::SetToolBar(wxToolBar *toolbar) |
215 | { | |
216 | if(m_frameToolBar) | |
217 | { | |
6613dc3f | 218 | m_frameToolBar->SetOwningFrame(NULL); |
448cbf1d | 219 | [m_frameToolBar->GetNSViewForSuperview() removeFromSuperview]; |
c5bd9191 | 220 | [m_frameToolBar->GetNSViewForSuperview() setAutoresizingMask: NSViewMinYMargin]; |
448cbf1d DE |
221 | if(m_frameToolBar->GetParent()) |
222 | m_frameToolBar->GetParent()->CocoaAddChild(m_frameToolBar); | |
223 | } | |
224 | m_frameToolBar = toolbar; | |
225 | if(m_frameToolBar) | |
226 | { | |
227 | m_frameToolBar->CocoaRemoveFromParent(); | |
6613dc3f | 228 | m_frameToolBar->SetOwningFrame(this); |
448cbf1d DE |
229 | } |
230 | UpdateFrameNSView(); | |
231 | } | |
a58a6614 | 232 | |
448cbf1d DE |
233 | wxToolBar* wxFrame::CreateToolBar(long style, |
234 | wxWindowID winid, | |
235 | const wxString& name) | |
236 | { | |
e1f4ff6d | 237 | wxAutoNSAutoreleasePool pool; |
448cbf1d DE |
238 | wxFrameBase::CreateToolBar(style,winid,name); |
239 | if(m_frameToolBar) | |
240 | { | |
241 | m_frameToolBar->CocoaRemoveFromParent(); | |
6613dc3f | 242 | m_frameToolBar->SetOwningFrame(this); |
448cbf1d DE |
243 | } |
244 | UpdateFrameNSView(); | |
245 | return m_frameToolBar; | |
246 | } | |
26785f01 | 247 | #endif // wxUSE_TOOLBAR |
a58a6614 | 248 | |
448cbf1d DE |
249 | void wxFrame::PositionStatusBar() |
250 | { | |
a58a6614 DE |
251 | } |
252 |