]>
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); | |
24c7767f | 62 | wxMenuBarManager::GetInstance()->UpdateWindowMenuBar(this); |
fb896a32 DE |
63 | } |
64 | ||
65 | void wxFrame::DetachMenuBar() | |
66 | { | |
fb896a32 | 67 | wxFrameBase::DetachMenuBar(); |
24c7767f | 68 | wxMenuBarManager::GetInstance()->UpdateWindowMenuBar(this); |
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); | |
81 | wxMenuBarManager::GetInstance()->UpdateWindowMenuBar(this); | |
fb896a32 DE |
82 | } |
83 | ||
84 | wxPoint wxFrame::GetClientAreaOrigin() const | |
85 | { | |
86 | return wxPoint(0,0); | |
87 | } | |
88 | ||
e08efb8d | 89 | void wxFrame::CocoaSetWxWindowSize(int width, int height) |
a58a6614 | 90 | { |
e08efb8d | 91 | if(m_frameStatusBar) |
a58a6614 | 92 | height += m_frameStatusBar->GetSize().y; |
26785f01 | 93 | #if wxUSE_TOOLBAR |
e08efb8d DE |
94 | if(m_frameToolBar) |
95 | height += m_frameToolBar->GetSize().y; | |
26785f01 | 96 | #endif //wxUSE_TOOLBAR |
e08efb8d | 97 | wxTopLevelWindow::CocoaSetWxWindowSize(width,height); |
a58a6614 DE |
98 | } |
99 | ||
448cbf1d DE |
100 | void wxFrame::CocoaReplaceView(WX_NSView oldView, WX_NSView newView) |
101 | { | |
102 | // If we have the additional toolbar/statbar view, then the | |
103 | // default replaceSubview will work. Otherwise, the old view | |
104 | // should be the content view and should be replaced that way | |
105 | if(m_frameNSView) | |
106 | wxWindow::CocoaReplaceView(oldView, newView); | |
107 | else | |
108 | wxTopLevelWindow::CocoaReplaceView(oldView, newView); | |
109 | } | |
110 | ||
111 | void wxFrame::UpdateFrameNSView() | |
112 | { | |
113 | if(!m_frameNSView) | |
114 | { | |
115 | m_frameNSView = [[NSView alloc] initWithFrame:[[m_cocoaNSWindow contentView] frame]]; | |
116 | [m_cocoaNSWindow setContentView: m_frameNSView]; | |
117 | [m_frameNSView addSubview:m_cocoaNSView]; | |
118 | } | |
119 | NSRect frameRect = [m_frameNSView frame]; | |
120 | float tbarheight = 0.0; | |
26785f01 | 121 | #if wxUSE_TOOLBAR |
448cbf1d DE |
122 | if(m_frameToolBar) |
123 | { | |
124 | NSView *tbarNSView = m_frameToolBar->GetNSViewForSuperview(); | |
125 | if(![tbarNSView superview]) | |
126 | [m_frameNSView addSubview: tbarNSView]; | |
127 | NSRect tbarRect = [tbarNSView frame]; | |
128 | tbarRect.size.width = frameRect.size.width; | |
129 | tbarRect.origin.x = 0.0; | |
130 | tbarRect.origin.y = frameRect.size.height - tbarRect.size.height; | |
131 | [tbarNSView setFrame:tbarRect]; | |
132 | // width expands, bottom margin expands | |
133 | [tbarNSView setAutoresizingMask: NSViewWidthSizable|NSViewMinYMargin]; | |
134 | tbarheight = tbarRect.size.height; | |
135 | } | |
26785f01 | 136 | #endif //wxUSE_TOOLBAR |
448cbf1d DE |
137 | float sbarheight = 0.0; |
138 | if(m_frameStatusBar) | |
139 | { | |
140 | NSView *sbarNSView = m_frameStatusBar->GetNSViewForSuperview(); | |
141 | if(![sbarNSView superview]) | |
142 | [m_frameNSView addSubview: sbarNSView]; | |
143 | NSRect sbarRect = [sbarNSView frame]; | |
144 | sbarRect.size.width = frameRect.size.width; | |
145 | sbarRect.origin.x = 0.0; | |
146 | sbarRect.origin.y = 0.0; | |
147 | [sbarNSView setFrame:sbarRect]; | |
148 | // width expands, top margin expands | |
149 | [sbarNSView setAutoresizingMask: NSViewWidthSizable|NSViewMaxYMargin]; | |
150 | sbarheight = sbarRect.size.height; | |
151 | } | |
152 | wxLogDebug("frame height=%f, tbar=%f, sbar=%f",frameRect.size.height,tbarheight,sbarheight); | |
153 | NSRect innerRect = [m_cocoaNSView frame]; | |
154 | innerRect.size.height = frameRect.size.height - tbarheight - sbarheight; | |
155 | innerRect.origin.y = sbarheight; | |
156 | [m_cocoaNSView setFrame:innerRect]; | |
157 | [m_cocoaNSView setAutoresizingMask: NSViewWidthSizable|NSViewHeightSizable]; | |
158 | // Don't let the frame get smaller than the toolbar+statusbar height | |
159 | NSRect frameMinRect = [NSWindow frameRectForContentRect: | |
160 | NSMakeRect(0.0,0.0,0.0,tbarheight+sbarheight) | |
161 | styleMask: [m_cocoaNSWindow styleMask]]; | |
162 | [m_cocoaNSWindow setMinSize:frameMinRect.size]; | |
163 | } | |
164 | ||
165 | void wxFrame::SetStatusBar(wxStatusBar *statusbar) | |
166 | { | |
167 | if(m_frameStatusBar) | |
168 | { | |
169 | [m_frameStatusBar->GetNSViewForSuperview() removeFromSuperview]; | |
c5bd9191 | 170 | [m_frameStatusBar->GetNSViewForSuperview() setAutoresizingMask: NSViewMinYMargin]; |
448cbf1d | 171 | if(m_frameStatusBar->GetParent()) |
26785f01 | 172 | m_frameStatusBar->GetParent()->CocoaAddChild(m_frameStatusBar); |
448cbf1d DE |
173 | } |
174 | m_frameStatusBar = statusbar; | |
175 | if(m_frameStatusBar) | |
176 | { | |
177 | m_frameStatusBar->CocoaRemoveFromParent(); | |
178 | } | |
179 | UpdateFrameNSView(); | |
180 | } | |
181 | ||
182 | wxStatusBar* wxFrame::CreateStatusBar(int number, | |
183 | long style, | |
184 | wxWindowID winid, | |
185 | const wxString& name) | |
a58a6614 | 186 | { |
448cbf1d DE |
187 | wxFrameBase::CreateStatusBar(number,style,winid,name); |
188 | if(m_frameStatusBar) | |
189 | { | |
190 | m_frameStatusBar->CocoaRemoveFromParent(); | |
191 | } | |
192 | UpdateFrameNSView(); | |
193 | return m_frameStatusBar; | |
194 | } | |
a58a6614 | 195 | |
26785f01 | 196 | #if wxUSE_TOOLBAR |
448cbf1d DE |
197 | void 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 |
214 | wxToolBar* 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 | } | |
26785f01 | 226 | #endif // wxUSE_TOOLBAR |
a58a6614 | 227 | |
448cbf1d DE |
228 | void wxFrame::PositionStatusBar() |
229 | { | |
a58a6614 DE |
230 | } |
231 |