]> git.saurik.com Git - wxWidgets.git/blob - src/cocoa/frame.mm
Added headers that didn't get installed.
[wxWidgets.git] / src / cocoa / frame.mm
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"
17 #include "wx/statusbr.h"
18
19 #include "wx/cocoa/autorelease.h"
20
21 #import <AppKit/NSWindow.h>
22 #import <AppKit/NSApplication.h>
23
24 // wxFrame
25
26 BEGIN_EVENT_TABLE(wxFrame, wxFrameBase)
27 END_EVENT_TABLE()
28
29 IMPLEMENT_DYNAMIC_CLASS(wxFrame, wxTopLevelWindow)
30
31 void wxFrame::Init()
32 {
33 }
34
35 bool wxFrame::Create(wxWindow *parent,
36 wxWindowID winid,
37 const wxString& title,
38 const wxPoint& pos,
39 const wxSize& size,
40 long style,
41 const wxString& name)
42 {
43 bool rt = wxTopLevelWindow::Create(parent,winid,title,pos,size,style,name);
44
45 return rt;
46 }
47
48 wxFrame::~wxFrame()
49 {
50 }
51
52 void wxFrame::Cocoa_wxMenuItemAction(wxMenuItem& item)
53 {
54 Command(item.GetId());
55 }
56
57 void wxFrame::AttachMenuBar(wxMenuBar *mbar)
58 {
59 wxFrameBase::AttachMenuBar(mbar);
60 if(m_frameMenuBar)
61 {
62 wxLogDebug("Attached menu");
63 [m_cocoaNSWindow setMenu:m_frameMenuBar->GetNSMenu()];
64 }
65 }
66
67 void wxFrame::DetachMenuBar()
68 {
69 if(m_frameMenuBar)
70 {
71 [m_cocoaNSWindow setMenu:nil];
72 }
73 wxFrameBase::DetachMenuBar();
74 }
75
76 bool wxFrame::Show(bool show)
77 {
78 wxAutoNSAutoreleasePool pool;
79 bool ret = wxFrameBase::Show(show);
80 if(show && GetMenuBar())
81 [wxTheApp->GetNSApplication() setMenu:GetMenuBar()->GetNSMenu() ];
82 return ret;
83 }
84
85 void wxFrame::Cocoa_FrameChanged(void)
86 {
87 PositionStatusBar();
88 wxFrameBase::Cocoa_FrameChanged();
89 }
90
91 wxPoint wxFrame::GetClientAreaOrigin() const
92 {
93 return wxPoint(0,0);
94 }
95
96 void wxFrame::DoGetClientSize(int *width, int *height) const
97 {
98 wxFrameBase::DoGetClientSize(width,height);
99 if(height)
100 {
101 if(m_frameStatusBar && m_frameStatusBar->IsShown())
102 *height -= m_frameStatusBar->GetSize().y;
103 }
104 }
105
106 void wxFrame::DoSetClientSize(int width, int height)
107 {
108 if(m_frameStatusBar && m_frameStatusBar->IsShown())
109 height += m_frameStatusBar->GetSize().y;
110 wxFrameBase::DoSetClientSize(width,height);
111 }
112
113 void wxFrame::PositionStatusBar()
114 {
115 if( !m_frameStatusBar || !m_frameStatusBar->IsShown() )
116 return;
117
118 // Get the client size. Since it excludes the StatusBar area we want
119 // the top of the status bar to be directly under it (thus located at h)
120 // The width of the statusbar should then match the client width
121 int w, h;
122 GetClientSize(&w, &h);
123
124 int sh;
125 m_frameStatusBar->GetSize(NULL, &sh);
126
127 m_frameStatusBar->SetSize(0, h, w, sh);
128 }
129