]>
Commit | Line | Data |
---|---|---|
2bda0e17 | 1 | ///////////////////////////////////////////////////////////////////////////// |
7c0ea335 | 2 | // Name: msw/frame.cpp |
0d53fc34 | 3 | // Purpose: wxFrame |
2bda0e17 KB |
4 | // Author: Julian Smart |
5 | // Modified by: | |
6 | // Created: 01/02/97 | |
7 | // RCS-ID: $Id$ | |
6c9a19aa | 8 | // Copyright: (c) Julian Smart |
2bda0e17 KB |
9 | // Licence: wxWindows licence |
10 | ///////////////////////////////////////////////////////////////////////////// | |
11 | ||
7c0ea335 VZ |
12 | // ============================================================================ |
13 | // declarations | |
14 | // ============================================================================ | |
15 | ||
16 | // ---------------------------------------------------------------------------- | |
17 | // headers | |
18 | // ---------------------------------------------------------------------------- | |
19 | ||
14f355c2 | 20 | #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA) |
7c0ea335 | 21 | #pragma implementation "frame.h" |
2bda0e17 KB |
22 | #endif |
23 | ||
24 | // For compilers that support precompilation, includes "wx.h". | |
25 | #include "wx/wxprec.h" | |
26 | ||
27 | #ifdef __BORLANDC__ | |
9f3362c4 | 28 | #pragma hdrstop |
2bda0e17 KB |
29 | #endif |
30 | ||
31 | #ifndef WX_PRECOMP | |
9f3362c4 | 32 | #include "wx/frame.h" |
9f3362c4 | 33 | #include "wx/app.h" |
1e6feb95 | 34 | #include "wx/menu.h" |
9f3362c4 VZ |
35 | #include "wx/utils.h" |
36 | #include "wx/dialog.h" | |
37 | #include "wx/settings.h" | |
38 | #include "wx/dcclient.h" | |
d3cc7c65 | 39 | #include "wx/mdi.h" |
f6bcfd97 | 40 | #include "wx/panel.h" |
9f3362c4 | 41 | #endif // WX_PRECOMP |
2bda0e17 KB |
42 | |
43 | #include "wx/msw/private.h" | |
7c0ea335 | 44 | |
4676948b JS |
45 | #ifdef __WXWINCE__ |
46 | #include <commctrl.h> | |
47 | #endif | |
48 | ||
7c0ea335 VZ |
49 | #if wxUSE_STATUSBAR |
50 | #include "wx/statusbr.h" | |
ed791986 | 51 | #include "wx/generic/statusbr.h" |
7c0ea335 VZ |
52 | #endif // wxUSE_STATUSBAR |
53 | ||
54 | #if wxUSE_TOOLBAR | |
55 | #include "wx/toolbar.h" | |
56 | #endif // wxUSE_TOOLBAR | |
57 | ||
2bda0e17 | 58 | #include "wx/menuitem.h" |
6776a0b2 | 59 | #include "wx/log.h" |
2bda0e17 | 60 | |
1e6feb95 VZ |
61 | #ifdef __WXUNIVERSAL__ |
62 | #include "wx/univ/theme.h" | |
63 | #include "wx/univ/colschem.h" | |
64 | #endif // __WXUNIVERSAL__ | |
65 | ||
7c0ea335 VZ |
66 | // ---------------------------------------------------------------------------- |
67 | // globals | |
68 | // ---------------------------------------------------------------------------- | |
2bda0e17 | 69 | |
1e6feb95 | 70 | #if wxUSE_MENUS_NATIVE |
03baf031 | 71 | extern wxMenu *wxCurrentPopupMenu; |
1e6feb95 | 72 | #endif // wxUSE_MENUS_NATIVE |
2bda0e17 | 73 | |
7c0ea335 VZ |
74 | // ---------------------------------------------------------------------------- |
75 | // event tables | |
76 | // ---------------------------------------------------------------------------- | |
77 | ||
0d53fc34 | 78 | BEGIN_EVENT_TABLE(wxFrame, wxFrameBase) |
0d53fc34 | 79 | EVT_SYS_COLOUR_CHANGED(wxFrame::OnSysColourChanged) |
2bda0e17 KB |
80 | END_EVENT_TABLE() |
81 | ||
51596bcb | 82 | #if wxUSE_EXTENDED_RTTI |
bc9fb572 JS |
83 | WX_DEFINE_FLAGS( wxFrameStyle ) |
84 | ||
3ff066a4 | 85 | wxBEGIN_FLAGS( wxFrameStyle ) |
bc9fb572 JS |
86 | // new style border flags, we put them first to |
87 | // use them for streaming out | |
3ff066a4 SC |
88 | wxFLAGS_MEMBER(wxBORDER_SIMPLE) |
89 | wxFLAGS_MEMBER(wxBORDER_SUNKEN) | |
90 | wxFLAGS_MEMBER(wxBORDER_DOUBLE) | |
91 | wxFLAGS_MEMBER(wxBORDER_RAISED) | |
92 | wxFLAGS_MEMBER(wxBORDER_STATIC) | |
93 | wxFLAGS_MEMBER(wxBORDER_NONE) | |
bc9fb572 JS |
94 | |
95 | // old style border flags | |
3ff066a4 SC |
96 | wxFLAGS_MEMBER(wxSIMPLE_BORDER) |
97 | wxFLAGS_MEMBER(wxSUNKEN_BORDER) | |
98 | wxFLAGS_MEMBER(wxDOUBLE_BORDER) | |
99 | wxFLAGS_MEMBER(wxRAISED_BORDER) | |
100 | wxFLAGS_MEMBER(wxSTATIC_BORDER) | |
cb0afb26 | 101 | wxFLAGS_MEMBER(wxBORDER) |
bc9fb572 JS |
102 | |
103 | // standard window styles | |
3ff066a4 SC |
104 | wxFLAGS_MEMBER(wxTAB_TRAVERSAL) |
105 | wxFLAGS_MEMBER(wxCLIP_CHILDREN) | |
106 | wxFLAGS_MEMBER(wxTRANSPARENT_WINDOW) | |
107 | wxFLAGS_MEMBER(wxWANTS_CHARS) | |
cb0afb26 | 108 | wxFLAGS_MEMBER(wxFULL_REPAINT_ON_RESIZE) |
3ff066a4 SC |
109 | wxFLAGS_MEMBER(wxALWAYS_SHOW_SB ) |
110 | wxFLAGS_MEMBER(wxVSCROLL) | |
111 | wxFLAGS_MEMBER(wxHSCROLL) | |
bc9fb572 JS |
112 | |
113 | // frame styles | |
3ff066a4 SC |
114 | wxFLAGS_MEMBER(wxSTAY_ON_TOP) |
115 | wxFLAGS_MEMBER(wxCAPTION) | |
116 | wxFLAGS_MEMBER(wxTHICK_FRAME) | |
117 | wxFLAGS_MEMBER(wxSYSTEM_MENU) | |
118 | wxFLAGS_MEMBER(wxRESIZE_BORDER) | |
119 | wxFLAGS_MEMBER(wxRESIZE_BOX) | |
120 | wxFLAGS_MEMBER(wxCLOSE_BOX) | |
121 | wxFLAGS_MEMBER(wxMAXIMIZE_BOX) | |
122 | wxFLAGS_MEMBER(wxMINIMIZE_BOX) | |
bc9fb572 | 123 | |
3ff066a4 SC |
124 | wxFLAGS_MEMBER(wxFRAME_TOOL_WINDOW) |
125 | wxFLAGS_MEMBER(wxFRAME_FLOAT_ON_PARENT) | |
bc9fb572 | 126 | |
3ff066a4 | 127 | wxFLAGS_MEMBER(wxFRAME_SHAPED) |
bc9fb572 | 128 | |
3ff066a4 | 129 | wxEND_FLAGS( wxFrameStyle ) |
bc9fb572 | 130 | |
51596bcb SC |
131 | IMPLEMENT_DYNAMIC_CLASS_XTI(wxFrame, wxTopLevelWindow,"wx/frame.h") |
132 | ||
3ff066a4 SC |
133 | wxBEGIN_PROPERTIES_TABLE(wxFrame) |
134 | wxEVENT_PROPERTY( Menu , wxEVT_COMMAND_MENU_SELECTED , wxCommandEvent) | |
c5ca409b | 135 | |
3ff066a4 SC |
136 | wxPROPERTY( Title,wxString, SetTitle, GetTitle, wxString() , 0 /*flags*/ , wxT("Helpstring") , wxT("group")) |
137 | wxPROPERTY_FLAGS( WindowStyle , wxFrameStyle , long , SetWindowStyleFlag , GetWindowStyleFlag , , 0 /*flags*/ , wxT("Helpstring") , wxT("group")) // style | |
138 | wxPROPERTY( MenuBar , wxMenuBar * , SetMenuBar , GetMenuBar , , 0 /*flags*/ , wxT("Helpstring") , wxT("group")) | |
139 | wxEND_PROPERTIES_TABLE() | |
51596bcb | 140 | |
3ff066a4 SC |
141 | wxBEGIN_HANDLERS_TABLE(wxFrame) |
142 | wxEND_HANDLERS_TABLE() | |
51596bcb | 143 | |
3ff066a4 | 144 | wxCONSTRUCTOR_6( wxFrame , wxWindow* , Parent , wxWindowID , Id , wxString , Title , wxPoint , Position , wxSize , Size , long , WindowStyle) |
51596bcb SC |
145 | |
146 | #else | |
58b43418 | 147 | IMPLEMENT_DYNAMIC_CLASS(wxFrame, wxTopLevelWindow) |
51596bcb | 148 | #endif |
2bda0e17 | 149 | |
7c0ea335 VZ |
150 | // ============================================================================ |
151 | // implementation | |
152 | // ============================================================================ | |
153 | ||
154 | // ---------------------------------------------------------------------------- | |
155 | // static class members | |
156 | // ---------------------------------------------------------------------------- | |
157 | ||
1e6feb95 VZ |
158 | #if wxUSE_STATUSBAR |
159 | #if wxUSE_NATIVE_STATUSBAR | |
0d53fc34 | 160 | bool wxFrame::m_useNativeStatusBar = TRUE; |
1e6feb95 | 161 | #else |
0d53fc34 | 162 | bool wxFrame::m_useNativeStatusBar = FALSE; |
1e6feb95 VZ |
163 | #endif |
164 | #endif // wxUSE_NATIVE_STATUSBAR | |
2bda0e17 | 165 | |
7c0ea335 VZ |
166 | // ---------------------------------------------------------------------------- |
167 | // creation/destruction | |
168 | // ---------------------------------------------------------------------------- | |
2bda0e17 | 169 | |
0d53fc34 | 170 | void wxFrame::Init() |
2bda0e17 | 171 | { |
9f3362c4 VZ |
172 | #if wxUSE_TOOLTIPS |
173 | m_hwndToolTip = 0; | |
174 | #endif | |
a2327a9f JS |
175 | |
176 | // Data to save/restore when calling ShowFullScreen | |
a2327a9f JS |
177 | m_fsStatusBarFields = 0; |
178 | m_fsStatusBarHeight = 0; | |
179 | m_fsToolBarHeight = 0; | |
f6bcfd97 | 180 | |
9327c3aa | 181 | m_wasMinimized = FALSE; |
7c0ea335 | 182 | } |
9f3362c4 | 183 | |
0d53fc34 | 184 | bool wxFrame::Create(wxWindow *parent, |
7c0ea335 VZ |
185 | wxWindowID id, |
186 | const wxString& title, | |
187 | const wxPoint& pos, | |
188 | const wxSize& size, | |
189 | long style, | |
190 | const wxString& name) | |
191 | { | |
82c9f85c VZ |
192 | if ( !wxTopLevelWindow::Create(parent, id, title, pos, size, style, name) ) |
193 | return FALSE; | |
d2aef312 | 194 | |
a756f210 | 195 | SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE)); |
2bda0e17 | 196 | |
82c9f85c | 197 | wxModelessWindows.Append(this); |
f6bcfd97 | 198 | |
82c9f85c | 199 | return TRUE; |
2bda0e17 KB |
200 | } |
201 | ||
0d53fc34 | 202 | wxFrame::~wxFrame() |
2bda0e17 | 203 | { |
82c9f85c | 204 | m_isBeingDeleted = TRUE; |
82c9f85c | 205 | DeleteAllBars(); |
2bda0e17 KB |
206 | } |
207 | ||
d4597e13 VZ |
208 | // ---------------------------------------------------------------------------- |
209 | // wxFrame client size calculations | |
210 | // ---------------------------------------------------------------------------- | |
2bda0e17 | 211 | |
0d53fc34 | 212 | void wxFrame::DoSetClientSize(int width, int height) |
2bda0e17 | 213 | { |
82c9f85c | 214 | // leave enough space for the status bar if we have (and show) it |
7c0ea335 | 215 | #if wxUSE_STATUSBAR |
8d8bd249 VZ |
216 | wxStatusBar *statbar = GetStatusBar(); |
217 | if ( statbar && statbar->IsShown() ) | |
218 | { | |
8d8bd249 VZ |
219 | height += statbar->GetSize().y; |
220 | } | |
7c0ea335 | 221 | #endif // wxUSE_STATUSBAR |
2bda0e17 | 222 | |
68d02db3 VZ |
223 | // call GetClientAreaOrigin() to take the toolbar into account |
224 | wxPoint pt = GetClientAreaOrigin(); | |
225 | width += pt.x; | |
226 | height += pt.y; | |
227 | ||
82c9f85c | 228 | wxTopLevelWindow::DoSetClientSize(width, height); |
2bda0e17 KB |
229 | } |
230 | ||
d4597e13 VZ |
231 | // Get size *available for subwindows* i.e. excluding menu bar, toolbar etc. |
232 | void wxFrame::DoGetClientSize(int *x, int *y) const | |
233 | { | |
234 | wxTopLevelWindow::DoGetClientSize(x, y); | |
235 | ||
68d02db3 VZ |
236 | // account for the possible toolbar |
237 | wxPoint pt = GetClientAreaOrigin(); | |
238 | if ( x ) | |
239 | *x -= pt.x; | |
240 | ||
241 | if ( y ) | |
242 | *y -= pt.y; | |
243 | ||
d4597e13 VZ |
244 | #if wxUSE_STATUSBAR |
245 | // adjust client area height to take the status bar into account | |
246 | if ( y ) | |
247 | { | |
248 | wxStatusBar *statbar = GetStatusBar(); | |
249 | if ( statbar && statbar->IsShown() ) | |
250 | { | |
251 | *y -= statbar->GetClientSize().y; | |
252 | } | |
253 | } | |
254 | #endif // wxUSE_STATUSBAR | |
255 | } | |
256 | ||
7c0ea335 | 257 | // ---------------------------------------------------------------------------- |
0d53fc34 | 258 | // wxFrame: various geometry-related functions |
7c0ea335 VZ |
259 | // ---------------------------------------------------------------------------- |
260 | ||
0d53fc34 | 261 | void wxFrame::Raise() |
c48926e1 | 262 | { |
c48926e1 | 263 | ::SetForegroundWindow(GetHwnd()); |
c48926e1 VZ |
264 | } |
265 | ||
67bd5bad | 266 | // generate an artificial resize event |
0d53fc34 | 267 | void wxFrame::SendSizeEvent() |
67bd5bad | 268 | { |
67bd5bad GT |
269 | if ( !m_iconized ) |
270 | { | |
82c9f85c VZ |
271 | RECT r = wxGetWindowRect(GetHwnd()); |
272 | ||
67bd5bad GT |
273 | (void)::PostMessage(GetHwnd(), WM_SIZE, |
274 | IsMaximized() ? SIZE_MAXIMIZED : SIZE_RESTORED, | |
275 | MAKELPARAM(r.right - r.left, r.bottom - r.top)); | |
276 | } | |
277 | } | |
278 | ||
d427503c | 279 | #if wxUSE_STATUSBAR |
0d53fc34 | 280 | wxStatusBar *wxFrame::OnCreateStatusBar(int number, |
7c0ea335 VZ |
281 | long style, |
282 | wxWindowID id, | |
283 | const wxString& name) | |
2bda0e17 KB |
284 | { |
285 | wxStatusBar *statusBar = NULL; | |
286 | ||
47d67540 | 287 | #if wxUSE_NATIVE_STATUSBAR |
1f0500b3 | 288 | if ( !UsesNativeStatusBar() ) |
2bda0e17 | 289 | { |
1f0500b3 | 290 | statusBar = (wxStatusBar *)new wxStatusBarGeneric(this, id, style); |
2bda0e17 KB |
291 | } |
292 | else | |
293 | #endif | |
294 | { | |
1f0500b3 VZ |
295 | statusBar = new wxStatusBar(this, id, style, name); |
296 | } | |
ed791986 | 297 | |
1f0500b3 | 298 | statusBar->SetFieldsCount(number); |
2bda0e17 | 299 | |
7c0ea335 | 300 | return statusBar; |
2bda0e17 KB |
301 | } |
302 | ||
0d53fc34 | 303 | void wxFrame::PositionStatusBar() |
2bda0e17 | 304 | { |
d4597e13 | 305 | if ( !m_frameStatusBar || !m_frameStatusBar->IsShown() ) |
ed791986 VZ |
306 | return; |
307 | ||
cbc66a27 VZ |
308 | int w, h; |
309 | GetClientSize(&w, &h); | |
310 | int sw, sh; | |
311 | m_frameStatusBar->GetSize(&sw, &sh); | |
312 | ||
313 | // Since we wish the status bar to be directly under the client area, | |
314 | // we use the adjusted sizes without using wxSIZE_NO_ADJUSTMENTS. | |
315 | m_frameStatusBar->SetSize(0, h, w, sh); | |
2bda0e17 | 316 | } |
d427503c | 317 | #endif // wxUSE_STATUSBAR |
2bda0e17 | 318 | |
6522713c | 319 | #if wxUSE_MENUS_NATIVE |
ea9a4296 | 320 | |
0d53fc34 | 321 | void wxFrame::AttachMenuBar(wxMenuBar *menubar) |
2bda0e17 | 322 | { |
f008af16 | 323 | wxFrameBase::AttachMenuBar(menubar); |
6beb85c0 | 324 | |
f6bcfd97 | 325 | if ( !menubar ) |
c2dcfdef | 326 | { |
f6bcfd97 BP |
327 | // actually remove the menu from the frame |
328 | m_hMenu = (WXHMENU)0; | |
329 | InternalSetMenuBar(); | |
065de612 | 330 | } |
f6bcfd97 | 331 | else // set new non NULL menu bar |
065de612 | 332 | { |
39d2f9a7 | 333 | #ifndef __WXWINCE__ |
f6bcfd97 | 334 | // Can set a menubar several times. |
f6bcfd97 BP |
335 | if ( menubar->GetHMenu() ) |
336 | { | |
337 | m_hMenu = menubar->GetHMenu(); | |
338 | } | |
f008af16 | 339 | else // no HMENU yet |
f6bcfd97 | 340 | { |
f6bcfd97 | 341 | m_hMenu = menubar->Create(); |
065de612 | 342 | |
f6bcfd97 | 343 | if ( !m_hMenu ) |
f008af16 VZ |
344 | { |
345 | wxFAIL_MSG( _T("failed to create menu bar") ); | |
f6bcfd97 | 346 | return; |
f008af16 | 347 | } |
f6bcfd97 | 348 | } |
39d2f9a7 | 349 | #endif |
f6bcfd97 | 350 | InternalSetMenuBar(); |
1e6feb95 | 351 | } |
2bda0e17 KB |
352 | } |
353 | ||
0d53fc34 | 354 | void wxFrame::InternalSetMenuBar() |
2bda0e17 | 355 | { |
4676948b JS |
356 | #ifdef __WXMICROWIN__ |
357 | // Nothing | |
358 | #elif defined(__WXWINCE__) | |
92f1a59c | 359 | |
39d2f9a7 | 360 | if (!GetToolBar()) |
4676948b | 361 | { |
39d2f9a7 JS |
362 | wxToolBar* toolBar = new wxToolBar(this, -1, |
363 | wxDefaultPosition, wxDefaultSize, | |
364 | wxBORDER_NONE | wxTB_HORIZONTAL, | |
365 | wxToolBarNameStr, GetMenuBar()); | |
366 | SetToolBar(toolBar); | |
4676948b JS |
367 | } |
368 | #else | |
42e69d6b | 369 | if ( !::SetMenu(GetHwnd(), (HMENU)m_hMenu) ) |
2bda0e17 | 370 | { |
f6bcfd97 | 371 | wxLogLastError(wxT("SetMenu")); |
2bda0e17 | 372 | } |
04ef50df | 373 | #endif |
2bda0e17 KB |
374 | } |
375 | ||
1e6feb95 VZ |
376 | #endif // wxUSE_MENUS_NATIVE |
377 | ||
2bda0e17 | 378 | // Responds to colour changes, and passes event on to children. |
0d53fc34 | 379 | void wxFrame::OnSysColourChanged(wxSysColourChangedEvent& event) |
2bda0e17 | 380 | { |
a756f210 | 381 | SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE)); |
2bda0e17 KB |
382 | Refresh(); |
383 | ||
1e6feb95 | 384 | #if wxUSE_STATUSBAR |
2bda0e17 KB |
385 | if ( m_frameStatusBar ) |
386 | { | |
387 | wxSysColourChangedEvent event2; | |
388 | event2.SetEventObject( m_frameStatusBar ); | |
02800301 | 389 | m_frameStatusBar->GetEventHandler()->ProcessEvent(event2); |
2bda0e17 | 390 | } |
1e6feb95 | 391 | #endif // wxUSE_STATUSBAR |
2bda0e17 KB |
392 | |
393 | // Propagate the event to the non-top-level children | |
394 | wxWindow::OnSysColourChanged(event); | |
395 | } | |
396 | ||
a2327a9f | 397 | // Pass TRUE to show full screen, FALSE to restore. |
0d53fc34 | 398 | bool wxFrame::ShowFullScreen(bool show, long style) |
a2327a9f | 399 | { |
085ad686 | 400 | if ( IsFullScreen() == show ) |
c641b1d2 VS |
401 | return FALSE; |
402 | ||
a2327a9f JS |
403 | if (show) |
404 | { | |
1e6feb95 | 405 | #if wxUSE_TOOLBAR |
09785dd3 JS |
406 | #ifdef __WXWINCE__ |
407 | // TODO: hide commandbar | |
408 | #else | |
f6bcfd97 | 409 | wxToolBar *theToolBar = GetToolBar(); |
a2327a9f | 410 | if (theToolBar) |
1e6feb95 | 411 | theToolBar->GetSize(NULL, &m_fsToolBarHeight); |
a2327a9f JS |
412 | |
413 | // zap the toolbar, menubar, and statusbar | |
414 | ||
415 | if ((style & wxFULLSCREEN_NOTOOLBAR) && theToolBar) | |
416 | { | |
417 | theToolBar->SetSize(-1,0); | |
418 | theToolBar->Show(FALSE); | |
419 | } | |
09785dd3 | 420 | #endif // __WXWINCE__ |
1e6feb95 | 421 | #endif // wxUSE_TOOLBAR |
a2327a9f | 422 | |
4676948b JS |
423 | // TODO: make it work for WinCE |
424 | #if !defined(__WXMICROWIN__) && !defined(__WXWINCE__) | |
a2327a9f JS |
425 | if (style & wxFULLSCREEN_NOMENUBAR) |
426 | SetMenu((HWND)GetHWND(), (HMENU) NULL); | |
04ef50df | 427 | #endif |
a2327a9f | 428 | |
1e6feb95 VZ |
429 | #if wxUSE_STATUSBAR |
430 | wxStatusBar *theStatusBar = GetStatusBar(); | |
431 | if (theStatusBar) | |
432 | theStatusBar->GetSize(NULL, &m_fsStatusBarHeight); | |
433 | ||
a2327a9f JS |
434 | // Save the number of fields in the statusbar |
435 | if ((style & wxFULLSCREEN_NOSTATUSBAR) && theStatusBar) | |
436 | { | |
579b10c2 JS |
437 | //m_fsStatusBarFields = theStatusBar->GetFieldsCount(); |
438 | //SetStatusBar((wxStatusBar*) NULL); | |
439 | //delete theStatusBar; | |
440 | theStatusBar->Show(FALSE); | |
a2327a9f JS |
441 | } |
442 | else | |
443 | m_fsStatusBarFields = 0; | |
1e6feb95 | 444 | #endif // wxUSE_STATUSBAR |
a2327a9f JS |
445 | } |
446 | else | |
447 | { | |
1e6feb95 | 448 | #if wxUSE_TOOLBAR |
09785dd3 JS |
449 | #ifdef __WXWINCE__ |
450 | // TODO: show commandbar | |
451 | #else | |
a2327a9f JS |
452 | wxToolBar *theToolBar = GetToolBar(); |
453 | ||
454 | // restore the toolbar, menubar, and statusbar | |
455 | if (theToolBar && (m_fsStyle & wxFULLSCREEN_NOTOOLBAR)) | |
456 | { | |
457 | theToolBar->SetSize(-1, m_fsToolBarHeight); | |
458 | theToolBar->Show(TRUE); | |
459 | } | |
09785dd3 | 460 | #endif // __WXWINCE__ |
1e6feb95 | 461 | #endif // wxUSE_TOOLBAR |
a2327a9f | 462 | |
1e6feb95 VZ |
463 | #if wxUSE_STATUSBAR |
464 | if ( m_fsStyle & wxFULLSCREEN_NOSTATUSBAR ) | |
a2327a9f | 465 | { |
579b10c2 JS |
466 | //CreateStatusBar(m_fsStatusBarFields); |
467 | if (GetStatusBar()) | |
468 | { | |
469 | GetStatusBar()->Show(TRUE); | |
470 | PositionStatusBar(); | |
471 | } | |
a2327a9f | 472 | } |
1e6feb95 | 473 | #endif // wxUSE_STATUSBAR |
a2327a9f | 474 | |
4676948b JS |
475 | // TODO: make it work for WinCE |
476 | #if !defined(__WXMICROWIN__) && !defined(__WXWINCE__) | |
a2327a9f JS |
477 | if ((m_fsStyle & wxFULLSCREEN_NOMENUBAR) && (m_hMenu != 0)) |
478 | SetMenu((HWND)GetHWND(), (HMENU)m_hMenu); | |
04ef50df | 479 | #endif |
a2327a9f | 480 | } |
f6bcfd97 | 481 | |
085ad686 | 482 | return wxFrameBase::ShowFullScreen(show, style); |
2bda0e17 KB |
483 | } |
484 | ||
7c0ea335 VZ |
485 | // ---------------------------------------------------------------------------- |
486 | // tool/status bar stuff | |
487 | // ---------------------------------------------------------------------------- | |
488 | ||
d427503c | 489 | #if wxUSE_TOOLBAR |
7c0ea335 | 490 | |
0d53fc34 | 491 | wxToolBar* wxFrame::CreateToolBar(long style, wxWindowID id, const wxString& name) |
81d66cf3 | 492 | { |
39d2f9a7 JS |
493 | #ifdef __WXWINCE__ |
494 | // We may already have a toolbar from calling SetMenuBar. | |
495 | if (GetToolBar()) | |
496 | return GetToolBar(); | |
497 | #endif | |
7c0ea335 | 498 | if ( wxFrameBase::CreateToolBar(style, id, name) ) |
81d66cf3 | 499 | { |
81d66cf3 | 500 | PositionToolBar(); |
81d66cf3 | 501 | } |
81d66cf3 | 502 | |
7c0ea335 | 503 | return m_frameToolBar; |
81d66cf3 JS |
504 | } |
505 | ||
0d53fc34 | 506 | void wxFrame::PositionToolBar() |
81d66cf3 | 507 | { |
d4597e13 VZ |
508 | wxToolBar *toolbar = GetToolBar(); |
509 | if ( toolbar && toolbar->IsShown() ) | |
510 | { | |
09785dd3 JS |
511 | #ifdef __WXWINCE__ |
512 | // We want to do something different in WinCE, because | |
513 | // the toolbar should be associated with the commandbar, | |
514 | // and not an independent window. | |
515 | // TODO | |
516 | #else | |
d4597e13 VZ |
517 | // don't call our (or even wxTopLevelWindow) version because we want |
518 | // the real (full) client area size, not excluding the tool/status bar | |
519 | int width, height; | |
520 | wxWindow::DoGetClientSize(&width, &height); | |
81d66cf3 | 521 | |
7c0ea335 | 522 | #if wxUSE_STATUSBAR |
d4597e13 VZ |
523 | wxStatusBar *statbar = GetStatusBar(); |
524 | if ( statbar && statbar->IsShown() ) | |
525 | { | |
526 | height -= statbar->GetClientSize().y; | |
527 | } | |
7c0ea335 | 528 | #endif // wxUSE_STATUSBAR |
81d66cf3 | 529 | |
229de929 | 530 | int tx, ty; |
81d66cf3 | 531 | int tw, th; |
229de929 | 532 | toolbar->GetPosition(&tx, &ty); |
d4597e13 | 533 | toolbar->GetSize(&tw, &th); |
229de929 JS |
534 | |
535 | // Adjust | |
536 | if (ty < 0 && (-ty == th)) | |
537 | ty = 0; | |
538 | if (tx < 0 && (-tx == tw)) | |
539 | tx = 0; | |
540 | ||
541 | int desiredW = tw; | |
542 | int desiredH = th; | |
81d66cf3 | 543 | |
d4597e13 | 544 | if ( toolbar->GetWindowStyleFlag() & wxTB_VERTICAL ) |
81d66cf3 | 545 | { |
229de929 | 546 | desiredH = height; |
81d66cf3 JS |
547 | } |
548 | else | |
549 | { | |
229de929 JS |
550 | desiredW = width; |
551 | // if ( toolbar->GetWindowStyleFlag() & wxTB_FLAT ) | |
552 | // desiredW -= 3; | |
553 | } | |
7c0ea335 | 554 | |
d4597e13 VZ |
555 | // use the 'real' MSW position here, don't offset relativly to the |
556 | // client area origin | |
229de929 JS |
557 | |
558 | // Optimise such that we don't have to always resize the toolbar | |
559 | // when the frame changes, otherwise we'll get a lot of flicker. | |
560 | bool heightChanging = TRUE; | |
561 | bool widthChanging = TRUE; | |
562 | ||
563 | if ( toolbar->GetWindowStyleFlag() & wxTB_VERTICAL ) | |
564 | { | |
565 | // It's OK if the current height is greater than what can be shown. | |
566 | heightChanging = (desiredH > th) ; | |
567 | widthChanging = (desiredW != tw) ; | |
568 | ||
569 | // The next time around, we may not have to set the size | |
570 | if (heightChanging) | |
571 | desiredH = desiredH + 200; | |
572 | } | |
573 | else | |
574 | { | |
575 | // It's OK if the current width is greater than what can be shown. | |
576 | widthChanging = (desiredW > tw) ; | |
577 | heightChanging = (desiredH != th) ; | |
578 | ||
579 | // The next time around, we may not have to set the size | |
580 | if (widthChanging) | |
581 | desiredW = desiredW + 200; | |
582 | } | |
583 | ||
584 | if (tx != 0 || ty != 0 || widthChanging || heightChanging) | |
585 | toolbar->SetSize(0, 0, desiredW, desiredH, wxSIZE_NO_ADJUSTMENTS); | |
586 | ||
09785dd3 | 587 | #endif // __WXWINCE__ |
81d66cf3 JS |
588 | } |
589 | } | |
d4597e13 | 590 | |
d427503c | 591 | #endif // wxUSE_TOOLBAR |
d2aef312 | 592 | |
7c0ea335 VZ |
593 | // ---------------------------------------------------------------------------- |
594 | // frame state (iconized/maximized/...) | |
595 | // ---------------------------------------------------------------------------- | |
596 | ||
a23fd0e1 VZ |
597 | // propagate our state change to all child frames: this allows us to emulate X |
598 | // Windows behaviour where child frames float independently of the parent one | |
599 | // on the desktop, but are iconized/restored with it | |
0d53fc34 | 600 | void wxFrame::IconizeChildFrames(bool bIconize) |
d2aef312 | 601 | { |
222ed1d6 | 602 | for ( wxWindowList::compatibility_iterator node = GetChildren().GetFirst(); |
a23fd0e1 VZ |
603 | node; |
604 | node = node->GetNext() ) | |
605 | { | |
606 | wxWindow *win = node->GetData(); | |
607 | ||
3ca6a5f0 BP |
608 | // iconizing the frames with this style under Win95 shell puts them at |
609 | // the bottom of the screen (as the MDI children) instead of making | |
610 | // them appear in the taskbar because they are, by virtue of this | |
611 | // style, not managed by the taskbar - instead leave Windows take care | |
612 | // of them | |
613 | #ifdef __WIN95__ | |
614 | if ( win->GetWindowStyle() & wxFRAME_TOOL_WINDOW ) | |
615 | continue; | |
616 | #endif // Win95 | |
617 | ||
3f7bc32b VZ |
618 | // the child MDI frames are a special case and should not be touched by |
619 | // the parent frame - instead, they are managed by the user | |
2e9f62da | 620 | wxFrame *frame = wxDynamicCast(win, wxFrame); |
1e6feb95 VZ |
621 | if ( frame |
622 | #if wxUSE_MDI_ARCHITECTURE | |
623 | && !wxDynamicCast(frame, wxMDIChildFrame) | |
624 | #endif // wxUSE_MDI_ARCHITECTURE | |
625 | ) | |
a23fd0e1 | 626 | { |
9327c3aa VZ |
627 | // we don't want to restore the child frames which had been |
628 | // iconized even before we were iconized, so save the child frame | |
629 | // status when iconizing the parent frame and check it when | |
630 | // restoring it | |
631 | if ( bIconize ) | |
632 | { | |
9c72ebec | 633 | frame->m_wasMinimized = frame->IsIconized(); |
9327c3aa VZ |
634 | } |
635 | ||
9c72ebec VZ |
636 | // note that we shouldn't touch the hidden frames neither because |
637 | // iconizing/restoring them would show them as a side effect | |
638 | if ( !frame->m_wasMinimized && frame->IsShown() ) | |
9327c3aa | 639 | frame->Iconize(bIconize); |
a23fd0e1 | 640 | } |
d2aef312 | 641 | } |
d2aef312 VZ |
642 | } |
643 | ||
0d53fc34 | 644 | WXHICON wxFrame::GetDefaultIcon() const |
82c9f85c | 645 | { |
94826170 VZ |
646 | // we don't have any standard icons (any more) |
647 | return (WXHICON)0; | |
82c9f85c VZ |
648 | } |
649 | ||
a23fd0e1 | 650 | // =========================================================================== |
42e69d6b | 651 | // message processing |
a23fd0e1 VZ |
652 | // =========================================================================== |
653 | ||
42e69d6b VZ |
654 | // --------------------------------------------------------------------------- |
655 | // preprocessing | |
656 | // --------------------------------------------------------------------------- | |
657 | ||
0d53fc34 | 658 | bool wxFrame::MSWTranslateMessage(WXMSG* pMsg) |
42e69d6b VZ |
659 | { |
660 | if ( wxWindow::MSWTranslateMessage(pMsg) ) | |
661 | return TRUE; | |
662 | ||
1e6feb95 | 663 | #if wxUSE_MENUS && wxUSE_ACCEL && !defined(__WXUNIVERSAL__) |
42e69d6b VZ |
664 | // try the menu bar accels |
665 | wxMenuBar *menuBar = GetMenuBar(); | |
666 | if ( !menuBar ) | |
667 | return FALSE; | |
668 | ||
669 | const wxAcceleratorTable& acceleratorTable = menuBar->GetAccelTable(); | |
c50f1fb9 | 670 | return acceleratorTable.Translate(this, pMsg); |
1e6feb95 VZ |
671 | #else |
672 | return FALSE; | |
673 | #endif // wxUSE_MENUS && wxUSE_ACCEL | |
42e69d6b VZ |
674 | } |
675 | ||
676 | // --------------------------------------------------------------------------- | |
677 | // our private (non virtual) message handlers | |
678 | // --------------------------------------------------------------------------- | |
679 | ||
0d53fc34 | 680 | bool wxFrame::HandlePaint() |
42e69d6b VZ |
681 | { |
682 | RECT rect; | |
683 | if ( GetUpdateRect(GetHwnd(), &rect, FALSE) ) | |
684 | { | |
4676948b | 685 | #if !defined(__WXMICROWIN__) && !defined(__WXWINCE__) |
42e69d6b VZ |
686 | if ( m_iconized ) |
687 | { | |
f618020a MB |
688 | const wxIcon& icon = GetIcon(); |
689 | HICON hIcon = icon.Ok() ? GetHiconOf(icon) | |
690 | : (HICON)GetDefaultIcon(); | |
42e69d6b VZ |
691 | |
692 | // Hold a pointer to the dc so long as the OnPaint() message | |
693 | // is being processed | |
694 | PAINTSTRUCT ps; | |
695 | HDC hdc = ::BeginPaint(GetHwnd(), &ps); | |
696 | ||
697 | // Erase background before painting or we get white background | |
698 | MSWDefWindowProc(WM_ICONERASEBKGND, (WORD)(LONG)ps.hdc, 0L); | |
699 | ||
700 | if ( hIcon ) | |
701 | { | |
702 | RECT rect; | |
703 | ::GetClientRect(GetHwnd(), &rect); | |
704 | ||
705 | // FIXME: why hardcoded? | |
706 | static const int icon_width = 32; | |
707 | static const int icon_height = 32; | |
708 | ||
709 | int icon_x = (int)((rect.right - icon_width)/2); | |
710 | int icon_y = (int)((rect.bottom - icon_height)/2); | |
711 | ||
712 | ::DrawIcon(hdc, icon_x, icon_y, hIcon); | |
713 | } | |
714 | ||
715 | ::EndPaint(GetHwnd(), &ps); | |
716 | ||
717 | return TRUE; | |
718 | } | |
719 | else | |
04ef50df | 720 | #endif |
42e69d6b | 721 | { |
5d1d2d46 | 722 | return wxWindow::HandlePaint(); |
42e69d6b VZ |
723 | } |
724 | } | |
725 | else | |
726 | { | |
727 | // nothing to paint - processed | |
728 | return TRUE; | |
729 | } | |
730 | } | |
731 | ||
0d53fc34 | 732 | bool wxFrame::HandleSize(int x, int y, WXUINT id) |
42e69d6b VZ |
733 | { |
734 | bool processed = FALSE; | |
4676948b | 735 | #if !defined(__WXMICROWIN__) && !defined(__WXWINCE__) |
42e69d6b VZ |
736 | |
737 | switch ( id ) | |
738 | { | |
739 | case SIZENORMAL: | |
740 | // only do it it if we were iconized before, otherwise resizing the | |
741 | // parent frame has a curious side effect of bringing it under it's | |
742 | // children | |
743 | if ( !m_iconized ) | |
744 | break; | |
745 | ||
746 | // restore all child frames too | |
747 | IconizeChildFrames(FALSE); | |
748 | ||
3dd9b88a VZ |
749 | (void)SendIconizeEvent(FALSE); |
750 | ||
42e69d6b VZ |
751 | // fall through |
752 | ||
753 | case SIZEFULLSCREEN: | |
754 | m_iconized = FALSE; | |
755 | break; | |
756 | ||
757 | case SIZEICONIC: | |
758 | // iconize all child frames too | |
759 | IconizeChildFrames(TRUE); | |
760 | ||
3dd9b88a VZ |
761 | (void)SendIconizeEvent(); |
762 | ||
42e69d6b VZ |
763 | m_iconized = TRUE; |
764 | break; | |
765 | } | |
04ef50df | 766 | #endif |
42e69d6b VZ |
767 | |
768 | if ( !m_iconized ) | |
769 | { | |
1e6feb95 | 770 | #if wxUSE_STATUSBAR |
42e69d6b | 771 | PositionStatusBar(); |
1e6feb95 VZ |
772 | #endif // wxUSE_STATUSBAR |
773 | ||
774 | #if wxUSE_TOOLBAR | |
42e69d6b | 775 | PositionToolBar(); |
1e6feb95 | 776 | #endif // wxUSE_TOOLBAR |
42e69d6b | 777 | |
4e4a5fed | 778 | processed = wxWindow::HandleSize(x, y, id); |
42e69d6b VZ |
779 | } |
780 | ||
781 | return processed; | |
782 | } | |
783 | ||
0d53fc34 | 784 | bool wxFrame::HandleCommand(WXWORD id, WXWORD cmd, WXHWND control) |
42e69d6b VZ |
785 | { |
786 | if ( control ) | |
787 | { | |
788 | // In case it's e.g. a toolbar. | |
789 | wxWindow *win = wxFindWinFromHandle(control); | |
790 | if ( win ) | |
791 | return win->MSWCommand(cmd, id); | |
792 | } | |
793 | ||
794 | // handle here commands from menus and accelerators | |
795 | if ( cmd == 0 || cmd == 1 ) | |
796 | { | |
1e6feb95 | 797 | #if wxUSE_MENUS_NATIVE |
42e69d6b VZ |
798 | if ( wxCurrentPopupMenu ) |
799 | { | |
800 | wxMenu *popupMenu = wxCurrentPopupMenu; | |
801 | wxCurrentPopupMenu = NULL; | |
802 | ||
803 | return popupMenu->MSWCommand(cmd, id); | |
804 | } | |
1e6feb95 | 805 | #endif // wxUSE_MENUS_NATIVE |
42e69d6b VZ |
806 | |
807 | if ( ProcessCommand(id) ) | |
808 | { | |
809 | return TRUE; | |
810 | } | |
811 | } | |
812 | ||
813 | return FALSE; | |
814 | } | |
815 | ||
0d53fc34 | 816 | bool wxFrame::HandleMenuSelect(WXWORD nItem, WXWORD flags, WXHMENU hMenu) |
a23fd0e1 VZ |
817 | { |
818 | int item; | |
c219cecc | 819 | if ( flags == 0xFFFF && hMenu == 0 ) |
a23fd0e1 | 820 | { |
c219cecc | 821 | // menu was removed from screen |
a23fd0e1 VZ |
822 | item = -1; |
823 | } | |
04ef50df | 824 | #ifndef __WXMICROWIN__ |
c219cecc | 825 | else if ( !(flags & MF_POPUP) && !(flags & MF_SEPARATOR) ) |
a23fd0e1 VZ |
826 | { |
827 | item = nItem; | |
828 | } | |
04ef50df | 829 | #endif |
a23fd0e1 VZ |
830 | else |
831 | { | |
c219cecc | 832 | // don't give hints for separators (doesn't make sense) nor for the |
f6bcfd97 BP |
833 | // items opening popup menus (they don't have them anyhow) but do clear |
834 | // the status line - otherwise, we would be left with the help message | |
835 | // for the previous item which doesn't apply any more | |
1f361cdd | 836 | DoGiveHelp(wxEmptyString, FALSE); |
f6bcfd97 | 837 | |
a23fd0e1 VZ |
838 | return FALSE; |
839 | } | |
840 | ||
841 | wxMenuEvent event(wxEVT_MENU_HIGHLIGHT, item); | |
ccef86c7 VZ |
842 | event.SetEventObject(this); |
843 | ||
844 | return GetEventHandler()->ProcessEvent(event); | |
845 | } | |
846 | ||
847 | bool wxFrame::HandleMenuLoop(const wxEventType& evtType, WXWORD isPopup) | |
848 | { | |
849 | // we don't have the menu id here, so we use the id to specify if the event | |
850 | // was from a popup menu or a normal one | |
851 | wxMenuEvent event(evtType, isPopup ? -1 : 0); | |
852 | event.SetEventObject(this); | |
a23fd0e1 VZ |
853 | |
854 | return GetEventHandler()->ProcessEvent(event); | |
855 | } | |
856 | ||
857 | // --------------------------------------------------------------------------- | |
0d53fc34 | 858 | // the window proc for wxFrame |
a23fd0e1 VZ |
859 | // --------------------------------------------------------------------------- |
860 | ||
0d53fc34 | 861 | long wxFrame::MSWWindowProc(WXUINT message, WXWPARAM wParam, WXLPARAM lParam) |
a23fd0e1 VZ |
862 | { |
863 | long rc = 0; | |
864 | bool processed = FALSE; | |
865 | ||
866 | switch ( message ) | |
867 | { | |
42e69d6b VZ |
868 | case WM_CLOSE: |
869 | // if we can't close, tell the system that we processed the | |
870 | // message - otherwise it would close us | |
871 | processed = !Close(); | |
872 | break; | |
873 | ||
ccef86c7 VZ |
874 | case WM_SIZE: |
875 | processed = HandleSize(LOWORD(lParam), HIWORD(lParam), wParam); | |
876 | break; | |
877 | ||
42e69d6b VZ |
878 | case WM_COMMAND: |
879 | { | |
880 | WORD id, cmd; | |
881 | WXHWND hwnd; | |
882 | UnpackCommand((WXWPARAM)wParam, (WXLPARAM)lParam, | |
883 | &id, &hwnd, &cmd); | |
884 | ||
885 | processed = HandleCommand(id, cmd, (WXHWND)hwnd); | |
886 | } | |
887 | break; | |
888 | ||
ccef86c7 VZ |
889 | case WM_PAINT: |
890 | processed = HandlePaint(); | |
891 | break; | |
892 | ||
92f1a59c JS |
893 | case WM_INITMENUPOPUP: |
894 | processed = HandleInitMenuPopup((WXHMENU) wParam); | |
895 | break; | |
896 | ||
4676948b | 897 | #if !defined(__WXMICROWIN__) && !defined(__WXWINCE__) |
a23fd0e1 VZ |
898 | case WM_MENUSELECT: |
899 | { | |
42e69d6b VZ |
900 | WXWORD item, flags; |
901 | WXHMENU hmenu; | |
902 | UnpackMenuSelect(wParam, lParam, &item, &flags, &hmenu); | |
903 | ||
904 | processed = HandleMenuSelect(item, flags, hmenu); | |
a23fd0e1 VZ |
905 | } |
906 | break; | |
bc92cdf9 | 907 | |
ccef86c7 VZ |
908 | case WM_EXITMENULOOP: |
909 | processed = HandleMenuLoop(wxEVT_MENU_CLOSE, wParam); | |
910 | break; | |
ccef86c7 | 911 | |
42e69d6b VZ |
912 | case WM_QUERYDRAGICON: |
913 | { | |
f618020a MB |
914 | const wxIcon& icon = GetIcon(); |
915 | HICON hIcon = icon.Ok() ? GetHiconOf(icon) | |
916 | : (HICON)GetDefaultIcon(); | |
42e69d6b VZ |
917 | rc = (long)hIcon; |
918 | processed = rc != 0; | |
919 | } | |
920 | break; | |
ccef86c7 | 921 | #endif // !__WXMICROWIN__ |
a23fd0e1 VZ |
922 | } |
923 | ||
924 | if ( !processed ) | |
7e25f59e | 925 | rc = wxFrameBase::MSWWindowProc(message, wParam, lParam); |
a23fd0e1 VZ |
926 | |
927 | return rc; | |
928 | } | |
21802234 | 929 | |
92f1a59c JS |
930 | // handle WM_INITMENUPOPUP message |
931 | bool wxFrame::HandleInitMenuPopup(WXHMENU hMenu) | |
e39af974 | 932 | { |
92f1a59c JS |
933 | wxMenu* menu = NULL; |
934 | if (GetMenuBar()) | |
935 | { | |
936 | int nCount = GetMenuBar()->GetMenuCount(); | |
937 | for (int n = 0; n < nCount; n++) | |
938 | { | |
939 | if (GetMenuBar()->GetMenu(n)->GetHMenu() == hMenu) | |
940 | { | |
941 | menu = GetMenuBar()->GetMenu(n); | |
942 | break; | |
943 | } | |
944 | } | |
945 | } | |
946 | ||
947 | wxMenuEvent event(wxEVT_MENU_OPEN, 0, menu); | |
e39af974 JS |
948 | event.SetEventObject(this); |
949 | ||
950 | return GetEventHandler()->ProcessEvent(event); | |
e39af974 | 951 | } |