1. added wxStatusBarUniv
[wxWidgets.git] / src / univ / framuniv.cpp
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: univ/frame.cpp
3 // Purpose: wxFrame class for wxUniversal
4 // Author: Vadim Zeitlin
5 // Modified by:
6 // Created: 19.05.01
7 // RCS-ID: $Id$
8 // Copyright: (c) 2001 SciTech Software, Inc. (www.scitechsoft.com)
9 // Licence: wxWindows licence
10 ///////////////////////////////////////////////////////////////////////////////
11
12 // ===========================================================================
13 // declarations
14 // ===========================================================================
15
16 // ---------------------------------------------------------------------------
17 // headers
18 // ---------------------------------------------------------------------------
19
20 #ifdef __GNUG__
21 #pragma implementation "univframe.h"
22 #endif
23
24 // For compilers that support precompilation, includes "wx.h".
25 #include "wx/wxprec.h"
26
27 #ifdef __BORLANDC__
28 #pragma hdrstop
29 #endif
30
31 #include "wx/menu.h"
32 #ifndef WX_PRECOMP
33 #include "wx/frame.h"
34 #include "wx/statusbr.h"
35 #endif // WX_PRECOMP
36
37 // ============================================================================
38 // implementation
39 // ============================================================================
40
41 BEGIN_EVENT_TABLE(wxFrame, wxFrameBase)
42 EVT_SIZE(wxFrame::OnSize)
43 END_EVENT_TABLE()
44
45 IMPLEMENT_DYNAMIC_CLASS(wxFrame, wxTopLevelWindow)
46
47 // ----------------------------------------------------------------------------
48 // ctors
49 // ----------------------------------------------------------------------------
50
51 bool wxFrame::Create(wxWindow *parent,
52 wxWindowID id,
53 const wxString& title,
54 const wxPoint& pos,
55 const wxSize& size,
56 long style,
57 const wxString& name)
58 {
59 return wxTopLevelWindow::Create(parent, id, title, pos, size, style, name);
60 }
61
62
63 // ----------------------------------------------------------------------------
64 // menu support
65 // ----------------------------------------------------------------------------
66
67 void wxFrame::OnSize(wxSizeEvent& event)
68 {
69 #if wxUSE_MENUS
70 PositionMenuBar();
71 #endif // wxUSE_MENUS
72 #if wxUSE_STATUSBAR
73 PositionStatusBar();
74 #endif // wxUSE_STATUSBAR
75
76 event.Skip();
77 }
78
79 void wxFrame::SendSizeEvent()
80 {
81 wxSizeEvent event(GetSize(), GetId());
82 event.SetEventObject(this);
83 GetEventHandler()->ProcessEvent(event);
84 }
85
86 #if wxUSE_MENUS
87
88 void wxFrame::PositionMenuBar()
89 {
90 if ( m_frameMenuBar )
91 {
92 // the menubar is positioned above the client size, hence the negative
93 // y coord
94 wxCoord heightMbar = m_frameMenuBar->GetSize().y;
95 m_frameMenuBar->SetSize(0, -heightMbar,
96 GetClientSize().x, heightMbar);
97 }
98 }
99
100 void wxFrame::DetachMenuBar()
101 {
102 wxFrameBase::DetachMenuBar();
103 SendSizeEvent();
104 }
105
106 void wxFrame::AttachMenuBar(wxMenuBar *menubar)
107 {
108 wxFrameBase::AttachMenuBar(menubar);
109 SendSizeEvent();
110 }
111
112 #endif // wxUSE_MENUS
113
114 #if wxUSE_STATUSBAR
115
116 void wxFrame::PositionStatusBar()
117 {
118 if ( m_frameStatusBar )
119 {
120 wxSize size = GetClientSize();
121 m_frameStatusBar->SetSize(0, size.y, size.x, -1);
122 }
123 }
124
125 wxStatusBar* wxFrame::CreateStatusBar(int number, long style,
126 wxWindowID id, const wxString& name)
127 {
128 wxStatusBar *bar = wxFrameBase::CreateStatusBar(number, style, id, name);
129 SendSizeEvent();
130 return bar;
131 }
132
133 #endif // wxUSE_STATUSBAR
134
135 wxPoint wxFrame::GetClientAreaOrigin() const
136 {
137 wxPoint pt = wxFrameBase::GetClientAreaOrigin();
138
139 #if wxUSE_MENUS
140 if ( m_frameMenuBar )
141 {
142 pt.y += m_frameMenuBar->GetSize().y;
143 }
144 #endif // wxUSE_MENUS
145
146 return pt;
147 }
148
149 void wxFrame::DoGetClientSize(int *width, int *height) const
150 {
151 wxFrameBase::DoGetClientSize(width, height);
152
153 #if wxUSE_MENUS
154 if ( m_frameMenuBar && height )
155 {
156 (*height) -= m_frameMenuBar->GetSize().y;
157 }
158 #endif // wxUSE_MENUS
159
160 #if wxUSE_STATUSBAR
161 if ( m_frameStatusBar && height )
162 {
163 (*height) -= m_frameStatusBar->GetSize().y;
164 }
165 #endif // wxUSE_STATUSBAR
166 }
167
168 void wxFrame::DoSetClientSize(int width, int height)
169 {
170 #if wxUSE_MENUS
171 if ( m_frameMenuBar )
172 {
173 height += m_frameMenuBar->GetSize().y;
174 }
175 #endif // wxUSE_MENUS
176
177 #if wxUSE_STATUSBAR
178 if ( m_frameStatusBar )
179 {
180 height += m_frameStatusBar->GetSize().y;
181 }
182 #endif // wxUSE_STATUSBAR
183
184 wxFrameBase::DoSetClientSize(width, height);
185 }
186
187 bool wxFrame::Enable(bool enable)
188 {
189 if (!wxFrameBase::Enable(enable))
190 return FALSE;
191 #ifdef __WXMICROWIN__
192 if (m_frameMenuBar)
193 m_frameMenuBar->Enable(enable);
194 #endif
195 return TRUE;
196 }