]>
Commit | Line | Data |
---|---|---|
2bda0e17 | 1 | ///////////////////////////////////////////////////////////////////////////// |
08b97268 | 2 | // Name: src/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 |
65571936 | 9 | // Licence: wxWindows licence |
2bda0e17 KB |
10 | ///////////////////////////////////////////////////////////////////////////// |
11 | ||
7c0ea335 VZ |
12 | // ============================================================================ |
13 | // declarations | |
14 | // ============================================================================ | |
15 | ||
16 | // ---------------------------------------------------------------------------- | |
17 | // headers | |
18 | // ---------------------------------------------------------------------------- | |
19 | ||
2bda0e17 KB |
20 | // For compilers that support precompilation, includes "wx.h". |
21 | #include "wx/wxprec.h" | |
22 | ||
23 | #ifdef __BORLANDC__ | |
9f3362c4 | 24 | #pragma hdrstop |
2bda0e17 KB |
25 | #endif |
26 | ||
76b49cf4 WS |
27 | #include "wx/frame.h" |
28 | ||
2bda0e17 | 29 | #ifndef WX_PRECOMP |
57bd4c60 | 30 | #include "wx/msw/wrapcctl.h" // include <commctrl.h> "properly" |
9f3362c4 | 31 | #include "wx/app.h" |
1e6feb95 | 32 | #include "wx/menu.h" |
9f3362c4 VZ |
33 | #include "wx/utils.h" |
34 | #include "wx/dialog.h" | |
35 | #include "wx/settings.h" | |
36 | #include "wx/dcclient.h" | |
d3cc7c65 | 37 | #include "wx/mdi.h" |
f6bcfd97 | 38 | #include "wx/panel.h" |
e4db172a | 39 | #include "wx/log.h" |
4e3e485b | 40 | #include "wx/toolbar.h" |
3304646d | 41 | #include "wx/statusbr.h" |
25466131 | 42 | #include "wx/menuitem.h" |
9f3362c4 | 43 | #endif // WX_PRECOMP |
2bda0e17 KB |
44 | |
45 | #include "wx/msw/private.h" | |
7c0ea335 | 46 | |
afafd942 | 47 | #if defined(__POCKETPC__) || defined(__SMARTPHONE__) |
855ec944 VZ |
48 | #include <ole2.h> |
49 | #include <aygshell.h> | |
50 | #include "wx/msw/winundef.h" | |
afafd942 JS |
51 | #endif |
52 | ||
8f62e633 RD |
53 | #include "wx/generic/statusbr.h" |
54 | ||
1e6feb95 VZ |
55 | #ifdef __WXUNIVERSAL__ |
56 | #include "wx/univ/theme.h" | |
57 | #include "wx/univ/colschem.h" | |
58 | #endif // __WXUNIVERSAL__ | |
59 | ||
7c0ea335 VZ |
60 | // ---------------------------------------------------------------------------- |
61 | // globals | |
62 | // ---------------------------------------------------------------------------- | |
2bda0e17 | 63 | |
1e6feb95 | 64 | #if wxUSE_MENUS_NATIVE |
03baf031 | 65 | extern wxMenu *wxCurrentPopupMenu; |
1e6feb95 | 66 | #endif // wxUSE_MENUS_NATIVE |
2bda0e17 | 67 | |
7c0ea335 VZ |
68 | // ---------------------------------------------------------------------------- |
69 | // event tables | |
70 | // ---------------------------------------------------------------------------- | |
71 | ||
0d53fc34 | 72 | BEGIN_EVENT_TABLE(wxFrame, wxFrameBase) |
0d53fc34 | 73 | EVT_SYS_COLOUR_CHANGED(wxFrame::OnSysColourChanged) |
2bda0e17 KB |
74 | END_EVENT_TABLE() |
75 | ||
51596bcb | 76 | #if wxUSE_EXTENDED_RTTI |
bc9fb572 JS |
77 | WX_DEFINE_FLAGS( wxFrameStyle ) |
78 | ||
3ff066a4 | 79 | wxBEGIN_FLAGS( wxFrameStyle ) |
bc9fb572 JS |
80 | // new style border flags, we put them first to |
81 | // use them for streaming out | |
3ff066a4 SC |
82 | wxFLAGS_MEMBER(wxBORDER_SIMPLE) |
83 | wxFLAGS_MEMBER(wxBORDER_SUNKEN) | |
84 | wxFLAGS_MEMBER(wxBORDER_DOUBLE) | |
85 | wxFLAGS_MEMBER(wxBORDER_RAISED) | |
86 | wxFLAGS_MEMBER(wxBORDER_STATIC) | |
87 | wxFLAGS_MEMBER(wxBORDER_NONE) | |
cbe874bd | 88 | |
bc9fb572 | 89 | // old style border flags |
3ff066a4 SC |
90 | wxFLAGS_MEMBER(wxSIMPLE_BORDER) |
91 | wxFLAGS_MEMBER(wxSUNKEN_BORDER) | |
92 | wxFLAGS_MEMBER(wxDOUBLE_BORDER) | |
93 | wxFLAGS_MEMBER(wxRAISED_BORDER) | |
94 | wxFLAGS_MEMBER(wxSTATIC_BORDER) | |
cb0afb26 | 95 | wxFLAGS_MEMBER(wxBORDER) |
bc9fb572 JS |
96 | |
97 | // standard window styles | |
3ff066a4 SC |
98 | wxFLAGS_MEMBER(wxTAB_TRAVERSAL) |
99 | wxFLAGS_MEMBER(wxCLIP_CHILDREN) | |
100 | wxFLAGS_MEMBER(wxTRANSPARENT_WINDOW) | |
101 | wxFLAGS_MEMBER(wxWANTS_CHARS) | |
cb0afb26 | 102 | wxFLAGS_MEMBER(wxFULL_REPAINT_ON_RESIZE) |
3ff066a4 SC |
103 | wxFLAGS_MEMBER(wxALWAYS_SHOW_SB ) |
104 | wxFLAGS_MEMBER(wxVSCROLL) | |
105 | wxFLAGS_MEMBER(wxHSCROLL) | |
bc9fb572 JS |
106 | |
107 | // frame styles | |
3ff066a4 SC |
108 | wxFLAGS_MEMBER(wxSTAY_ON_TOP) |
109 | wxFLAGS_MEMBER(wxCAPTION) | |
1c067fe3 | 110 | #if WXWIN_COMPATIBILITY_2_6 |
3ff066a4 | 111 | wxFLAGS_MEMBER(wxTHICK_FRAME) |
1c067fe3 | 112 | #endif // WXWIN_COMPATIBILITY_2_6 |
3ff066a4 SC |
113 | wxFLAGS_MEMBER(wxSYSTEM_MENU) |
114 | wxFLAGS_MEMBER(wxRESIZE_BORDER) | |
1c067fe3 | 115 | #if WXWIN_COMPATIBILITY_2_6 |
3ff066a4 | 116 | wxFLAGS_MEMBER(wxRESIZE_BOX) |
1c067fe3 | 117 | #endif // WXWIN_COMPATIBILITY_2_6 |
3ff066a4 SC |
118 | wxFLAGS_MEMBER(wxCLOSE_BOX) |
119 | wxFLAGS_MEMBER(wxMAXIMIZE_BOX) | |
120 | wxFLAGS_MEMBER(wxMINIMIZE_BOX) | |
bc9fb572 | 121 | |
3ff066a4 SC |
122 | wxFLAGS_MEMBER(wxFRAME_TOOL_WINDOW) |
123 | wxFLAGS_MEMBER(wxFRAME_FLOAT_ON_PARENT) | |
bc9fb572 | 124 | |
3ff066a4 | 125 | wxFLAGS_MEMBER(wxFRAME_SHAPED) |
bc9fb572 | 126 | |
3ff066a4 | 127 | wxEND_FLAGS( wxFrameStyle ) |
bc9fb572 | 128 | |
51596bcb SC |
129 | IMPLEMENT_DYNAMIC_CLASS_XTI(wxFrame, wxTopLevelWindow,"wx/frame.h") |
130 | ||
3ff066a4 | 131 | wxBEGIN_PROPERTIES_TABLE(wxFrame) |
fb8a56b7 | 132 | wxEVENT_PROPERTY( Menu , wxEVT_COMMAND_MENU_SELECTED , wxCommandEvent) |
c5ca409b | 133 | |
3ff066a4 | 134 | wxPROPERTY( Title,wxString, SetTitle, GetTitle, wxString() , 0 /*flags*/ , wxT("Helpstring") , wxT("group")) |
af498247 VZ |
135 | wxPROPERTY_FLAGS( WindowStyle , wxFrameStyle , long , SetWindowStyleFlag , GetWindowStyleFlag , EMPTY_MACROVALUE , 0 /*flags*/ , wxT("Helpstring") , wxT("group")) // style |
136 | wxPROPERTY( MenuBar , wxMenuBar * , SetMenuBar , GetMenuBar , EMPTY_MACROVALUE , 0 /*flags*/ , wxT("Helpstring") , wxT("group")) | |
3ff066a4 | 137 | wxEND_PROPERTIES_TABLE() |
51596bcb | 138 | |
3ff066a4 SC |
139 | wxBEGIN_HANDLERS_TABLE(wxFrame) |
140 | wxEND_HANDLERS_TABLE() | |
51596bcb | 141 | |
cbe874bd | 142 | wxCONSTRUCTOR_6( wxFrame , wxWindow* , Parent , wxWindowID , Id , wxString , Title , wxPoint , Position , wxSize , Size , long , WindowStyle) |
51596bcb SC |
143 | |
144 | #else | |
58b43418 | 145 | IMPLEMENT_DYNAMIC_CLASS(wxFrame, wxTopLevelWindow) |
51596bcb | 146 | #endif |
2bda0e17 | 147 | |
7c0ea335 VZ |
148 | // ============================================================================ |
149 | // implementation | |
150 | // ============================================================================ | |
151 | ||
152 | // ---------------------------------------------------------------------------- | |
153 | // static class members | |
154 | // ---------------------------------------------------------------------------- | |
155 | ||
1e6feb95 VZ |
156 | #if wxUSE_STATUSBAR |
157 | #if wxUSE_NATIVE_STATUSBAR | |
cbe874bd | 158 | bool wxFrame::m_useNativeStatusBar = true; |
1e6feb95 | 159 | #else |
cbe874bd | 160 | bool wxFrame::m_useNativeStatusBar = false; |
1e6feb95 VZ |
161 | #endif |
162 | #endif // wxUSE_NATIVE_STATUSBAR | |
2bda0e17 | 163 | |
7c0ea335 VZ |
164 | // ---------------------------------------------------------------------------- |
165 | // creation/destruction | |
166 | // ---------------------------------------------------------------------------- | |
2bda0e17 | 167 | |
0d53fc34 | 168 | void wxFrame::Init() |
2bda0e17 | 169 | { |
cf8ff92f VZ |
170 | #if wxUSE_MENUS |
171 | m_hMenu = NULL; | |
172 | #endif // wxUSE_MENUS | |
173 | ||
9f3362c4 VZ |
174 | #if wxUSE_TOOLTIPS |
175 | m_hwndToolTip = 0; | |
176 | #endif | |
a2327a9f | 177 | |
cbe874bd | 178 | m_wasMinimized = false; |
7c0ea335 | 179 | } |
9f3362c4 | 180 | |
0d53fc34 | 181 | bool wxFrame::Create(wxWindow *parent, |
7c0ea335 VZ |
182 | wxWindowID id, |
183 | const wxString& title, | |
184 | const wxPoint& pos, | |
185 | const wxSize& size, | |
186 | long style, | |
187 | const wxString& name) | |
188 | { | |
82c9f85c | 189 | if ( !wxTopLevelWindow::Create(parent, id, title, pos, size, style, name) ) |
ef6d716b | 190 | return false; |
d2aef312 | 191 | |
98a02e87 | 192 | SetOwnBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE)); |
b9691677 | 193 | |
aaf803e9 | 194 | #if defined(__SMARTPHONE__) |
ef6d716b WS |
195 | SetLeftMenu(wxID_EXIT, _("Done")); |
196 | #endif | |
197 | ||
855ec944 | 198 | #if wxUSE_ACCEL && defined(__POCKETPC__) |
aaf803e9 JS |
199 | // The guidelines state that Ctrl+Q should quit the app. |
200 | // Let's define an accelerator table to send wxID_EXIT. | |
201 | wxAcceleratorEntry entries[1]; | |
202 | entries[0].Set(wxACCEL_CTRL, 'Q', wxID_EXIT); | |
203 | wxAcceleratorTable accel(1, entries); | |
204 | SetAcceleratorTable(accel); | |
855ec944 | 205 | #endif // wxUSE_ACCEL && __POCKETPC__ |
aaf803e9 | 206 | |
ef6d716b | 207 | return true; |
2bda0e17 KB |
208 | } |
209 | ||
0d53fc34 | 210 | wxFrame::~wxFrame() |
2bda0e17 | 211 | { |
c6212a0c VZ |
212 | SendDestroyEvent(); |
213 | ||
82c9f85c | 214 | DeleteAllBars(); |
2bda0e17 KB |
215 | } |
216 | ||
d4597e13 VZ |
217 | // ---------------------------------------------------------------------------- |
218 | // wxFrame client size calculations | |
219 | // ---------------------------------------------------------------------------- | |
2bda0e17 | 220 | |
0d53fc34 | 221 | void wxFrame::DoSetClientSize(int width, int height) |
2bda0e17 | 222 | { |
82c9f85c | 223 | // leave enough space for the status bar if we have (and show) it |
7c0ea335 | 224 | #if wxUSE_STATUSBAR |
8d8bd249 VZ |
225 | wxStatusBar *statbar = GetStatusBar(); |
226 | if ( statbar && statbar->IsShown() ) | |
227 | { | |
8d8bd249 VZ |
228 | height += statbar->GetSize().y; |
229 | } | |
7c0ea335 | 230 | #endif // wxUSE_STATUSBAR |
2bda0e17 | 231 | |
68d02db3 VZ |
232 | // call GetClientAreaOrigin() to take the toolbar into account |
233 | wxPoint pt = GetClientAreaOrigin(); | |
234 | width += pt.x; | |
235 | height += pt.y; | |
3882e746 | 236 | |
7a976304 | 237 | #if wxUSE_TOOLBAR |
3882e746 VZ |
238 | wxToolBar * const toolbar = GetToolBar(); |
239 | if ( toolbar ) | |
7a976304 | 240 | { |
3882e746 | 241 | if ( toolbar->HasFlag(wxTB_RIGHT | wxTB_BOTTOM) ) |
7a976304 | 242 | { |
3882e746 VZ |
243 | const wxSize sizeTB = toolbar->GetSize(); |
244 | if ( toolbar->HasFlag(wxTB_RIGHT) ) | |
245 | width -= sizeTB.x; | |
246 | else // wxTB_BOTTOM | |
247 | height -= sizeTB.y; | |
7a976304 | 248 | } |
3882e746 | 249 | //else: toolbar already taken into account by GetClientAreaOrigin() |
7a976304 | 250 | } |
3882e746 | 251 | #endif // wxUSE_TOOLBAR |
68d02db3 | 252 | |
82c9f85c | 253 | wxTopLevelWindow::DoSetClientSize(width, height); |
2bda0e17 KB |
254 | } |
255 | ||
d4597e13 VZ |
256 | // Get size *available for subwindows* i.e. excluding menu bar, toolbar etc. |
257 | void wxFrame::DoGetClientSize(int *x, int *y) const | |
258 | { | |
259 | wxTopLevelWindow::DoGetClientSize(x, y); | |
260 | ||
68d02db3 VZ |
261 | // account for the possible toolbar |
262 | wxPoint pt = GetClientAreaOrigin(); | |
263 | if ( x ) | |
264 | *x -= pt.x; | |
265 | ||
266 | if ( y ) | |
267 | *y -= pt.y; | |
3882e746 | 268 | |
5b2acc3a | 269 | #if wxUSE_TOOLBAR |
3882e746 VZ |
270 | wxToolBar * const toolbar = GetToolBar(); |
271 | if ( toolbar ) | |
5b2acc3a | 272 | { |
3882e746 | 273 | if ( toolbar->HasFlag(wxTB_RIGHT | wxTB_BOTTOM) ) |
5b2acc3a | 274 | { |
3882e746 VZ |
275 | const wxSize sizeTB = toolbar->GetSize(); |
276 | if ( toolbar->HasFlag(wxTB_RIGHT) ) | |
277 | { | |
278 | if ( x ) | |
279 | *x -= sizeTB.x; | |
280 | } | |
281 | else // wxTB_BOTTOM | |
282 | { | |
283 | if ( y ) | |
284 | *y -= sizeTB.y; | |
285 | } | |
7a976304 | 286 | } |
3882e746 | 287 | //else: toolbar already taken into account by GetClientAreaOrigin() |
7a976304 | 288 | } |
3882e746 VZ |
289 | #endif // wxUSE_TOOLBAR |
290 | ||
d4597e13 VZ |
291 | #if wxUSE_STATUSBAR |
292 | // adjust client area height to take the status bar into account | |
293 | if ( y ) | |
294 | { | |
295 | wxStatusBar *statbar = GetStatusBar(); | |
296 | if ( statbar && statbar->IsShown() ) | |
297 | { | |
298 | *y -= statbar->GetClientSize().y; | |
299 | } | |
300 | } | |
301 | #endif // wxUSE_STATUSBAR | |
302 | } | |
303 | ||
7c0ea335 | 304 | // ---------------------------------------------------------------------------- |
0d53fc34 | 305 | // wxFrame: various geometry-related functions |
7c0ea335 VZ |
306 | // ---------------------------------------------------------------------------- |
307 | ||
0d53fc34 | 308 | void wxFrame::Raise() |
c48926e1 | 309 | { |
c48926e1 | 310 | ::SetForegroundWindow(GetHwnd()); |
c48926e1 VZ |
311 | } |
312 | ||
67bd5bad | 313 | // generate an artificial resize event |
ecdc1183 | 314 | void wxFrame::SendSizeEvent(int flags) |
67bd5bad | 315 | { |
67bd5bad GT |
316 | if ( !m_iconized ) |
317 | { | |
82c9f85c VZ |
318 | RECT r = wxGetWindowRect(GetHwnd()); |
319 | ||
ecdc1183 VZ |
320 | if ( flags & wxSEND_EVENT_POST ) |
321 | { | |
322 | ::PostMessage(GetHwnd(), WM_SIZE, | |
323 | IsMaximized() ? SIZE_MAXIMIZED : SIZE_RESTORED, | |
324 | MAKELPARAM(r.right - r.left, r.bottom - r.top)); | |
325 | } | |
326 | else // send it | |
327 | { | |
328 | ::SendMessage(GetHwnd(), WM_SIZE, | |
329 | IsMaximized() ? SIZE_MAXIMIZED : SIZE_RESTORED, | |
330 | MAKELPARAM(r.right - r.left, r.bottom - r.top)); | |
331 | } | |
67bd5bad GT |
332 | } |
333 | } | |
334 | ||
d427503c | 335 | #if wxUSE_STATUSBAR |
0d53fc34 | 336 | wxStatusBar *wxFrame::OnCreateStatusBar(int number, |
7c0ea335 VZ |
337 | long style, |
338 | wxWindowID id, | |
339 | const wxString& name) | |
2bda0e17 | 340 | { |
5cb598ae | 341 | wxStatusBar *statusBar wxDUMMY_INITIALIZE(NULL); |
2bda0e17 | 342 | |
47d67540 | 343 | #if wxUSE_NATIVE_STATUSBAR |
1f0500b3 | 344 | if ( !UsesNativeStatusBar() ) |
2bda0e17 | 345 | { |
1f0500b3 | 346 | statusBar = (wxStatusBar *)new wxStatusBarGeneric(this, id, style); |
2bda0e17 KB |
347 | } |
348 | else | |
349 | #endif | |
350 | { | |
1f0500b3 VZ |
351 | statusBar = new wxStatusBar(this, id, style, name); |
352 | } | |
ed791986 | 353 | |
1f0500b3 | 354 | statusBar->SetFieldsCount(number); |
2bda0e17 | 355 | |
7c0ea335 | 356 | return statusBar; |
2bda0e17 KB |
357 | } |
358 | ||
0d53fc34 | 359 | void wxFrame::PositionStatusBar() |
2bda0e17 | 360 | { |
d4597e13 | 361 | if ( !m_frameStatusBar || !m_frameStatusBar->IsShown() ) |
ed791986 VZ |
362 | return; |
363 | ||
cbc66a27 VZ |
364 | int w, h; |
365 | GetClientSize(&w, &h); | |
3882e746 | 366 | |
cbc66a27 VZ |
367 | int sw, sh; |
368 | m_frameStatusBar->GetSize(&sw, &sh); | |
369 | ||
8efbb8ad VZ |
370 | int x = 0; |
371 | #if wxUSE_TOOLBAR | |
372 | wxToolBar * const toolbar = GetToolBar(); | |
373 | if ( toolbar && !toolbar->HasFlag(wxTB_TOP) ) | |
374 | { | |
375 | const wxSize sizeTB = toolbar->GetSize(); | |
376 | ||
377 | if ( toolbar->HasFlag(wxTB_LEFT | wxTB_RIGHT) ) | |
378 | { | |
379 | if ( toolbar->HasFlag(wxTB_LEFT) ) | |
380 | x -= sizeTB.x; | |
381 | ||
382 | w += sizeTB.x; | |
383 | } | |
384 | else // wxTB_BOTTOM | |
385 | { | |
386 | // we need to position the status bar below the toolbar | |
387 | h += sizeTB.y; | |
388 | } | |
389 | } | |
390 | //else: no adjustments necessary for the toolbar on top | |
391 | #endif // wxUSE_TOOLBAR | |
392 | ||
cbc66a27 VZ |
393 | // Since we wish the status bar to be directly under the client area, |
394 | // we use the adjusted sizes without using wxSIZE_NO_ADJUSTMENTS. | |
8efbb8ad | 395 | m_frameStatusBar->SetSize(x, h, w, sh); |
2bda0e17 | 396 | } |
3882e746 | 397 | |
d427503c | 398 | #endif // wxUSE_STATUSBAR |
2bda0e17 | 399 | |
6522713c | 400 | #if wxUSE_MENUS_NATIVE |
ea9a4296 | 401 | |
0d53fc34 | 402 | void wxFrame::AttachMenuBar(wxMenuBar *menubar) |
2bda0e17 | 403 | { |
3180bc0e | 404 | #if defined(__SMARTPHONE__) && defined(__WXWINCE__) |
fb8a56b7 | 405 | |
ed679e74 WS |
406 | wxMenu *autoMenu = NULL; |
407 | ||
408 | if( menubar->GetMenuCount() == 1 ) | |
409 | { | |
410 | autoMenu = wxTopLevelWindowMSW::ButtonMenu::DuplicateMenu(menubar->GetMenu(0)); | |
52af3158 | 411 | SetRightMenu(wxID_ANY, menubar->GetMenuLabel(0), autoMenu); |
ed679e74 WS |
412 | } |
413 | else | |
fb8a56b7 | 414 | { |
ed679e74 WS |
415 | autoMenu = new wxMenu; |
416 | ||
417 | for( size_t n = 0; n < menubar->GetMenuCount(); n++ ) | |
418 | { | |
419 | wxMenu *item = menubar->GetMenu(n); | |
52af3158 | 420 | wxString label = menubar->GetMenuLabel(n); |
ed679e74 WS |
421 | wxMenu *new_item = wxTopLevelWindowMSW::ButtonMenu::DuplicateMenu(item); |
422 | autoMenu->Append(wxID_ANY, label, new_item); | |
423 | } | |
424 | ||
425 | SetRightMenu(wxID_ANY, _("Menu"), autoMenu); | |
fb8a56b7 WS |
426 | } |
427 | ||
fb8a56b7 | 428 | #elif defined(WINCE_WITHOUT_COMMANDBAR) |
a96b4743 JS |
429 | if (!GetToolBar()) |
430 | { | |
a9102b36 | 431 | wxToolMenuBar* toolBar = new wxToolMenuBar(this, wxID_ANY, |
a96b4743 JS |
432 | wxDefaultPosition, wxDefaultSize, |
433 | wxBORDER_NONE | wxTB_HORIZONTAL, | |
af5454a4 | 434 | wxToolBarNameStr, menubar); |
a96b4743 JS |
435 | SetToolBar(toolBar); |
436 | menubar->SetToolBar(toolBar); | |
437 | } | |
fb8a56b7 | 438 | |
c0a91b51 VZ |
439 | // When the main window is created using CW_USEDEFAULT the height of the |
440 | // menubar is not taken into account, so we resize it afterwards if a | |
441 | // menubar is present | |
442 | HWND hwndMenuBar = SHFindMenuBar(GetHwnd()); | |
443 | if ( hwndMenuBar ) | |
fb8a56b7 | 444 | { |
c0a91b51 VZ |
445 | RECT mbRect; |
446 | ::GetWindowRect(hwndMenuBar, &mbRect); | |
447 | const int menuHeight = mbRect.bottom - mbRect.top; | |
448 | ||
fb8a56b7 | 449 | RECT rc; |
c0a91b51 | 450 | ::GetWindowRect(GetHwnd(), &rc); |
fb8a56b7 WS |
451 | // adjust for menu / titlebar height |
452 | rc.bottom -= (2*menuHeight-1); | |
453 | ||
c0a91b51 | 454 | ::MoveWindow(Gethwnd(), rc.left, rc.top, rc.right, rc.bottom, FALSE); |
fb8a56b7 | 455 | } |
a96b4743 JS |
456 | #endif |
457 | ||
f008af16 | 458 | wxFrameBase::AttachMenuBar(menubar); |
6beb85c0 | 459 | |
f6bcfd97 | 460 | if ( !menubar ) |
c2dcfdef | 461 | { |
f6bcfd97 BP |
462 | // actually remove the menu from the frame |
463 | m_hMenu = (WXHMENU)0; | |
464 | InternalSetMenuBar(); | |
065de612 | 465 | } |
f6bcfd97 | 466 | else // set new non NULL menu bar |
065de612 | 467 | { |
3d487566 | 468 | #if !defined(__WXWINCE__) || defined(WINCE_WITH_COMMANDBAR) |
f6bcfd97 | 469 | // Can set a menubar several times. |
f6bcfd97 BP |
470 | if ( menubar->GetHMenu() ) |
471 | { | |
472 | m_hMenu = menubar->GetHMenu(); | |
473 | } | |
f008af16 | 474 | else // no HMENU yet |
f6bcfd97 | 475 | { |
f6bcfd97 | 476 | m_hMenu = menubar->Create(); |
065de612 | 477 | |
f6bcfd97 | 478 | if ( !m_hMenu ) |
f008af16 VZ |
479 | { |
480 | wxFAIL_MSG( _T("failed to create menu bar") ); | |
f6bcfd97 | 481 | return; |
f008af16 | 482 | } |
f6bcfd97 | 483 | } |
39d2f9a7 | 484 | #endif |
f6bcfd97 | 485 | InternalSetMenuBar(); |
1e6feb95 | 486 | } |
2bda0e17 KB |
487 | } |
488 | ||
0d53fc34 | 489 | void wxFrame::InternalSetMenuBar() |
2bda0e17 | 490 | { |
a96b4743 | 491 | #if defined(__WXMICROWIN__) || defined(__WXWINCE__) |
4676948b | 492 | // Nothing |
4676948b | 493 | #else |
42e69d6b | 494 | if ( !::SetMenu(GetHwnd(), (HMENU)m_hMenu) ) |
2bda0e17 | 495 | { |
f6bcfd97 | 496 | wxLogLastError(wxT("SetMenu")); |
2bda0e17 | 497 | } |
04ef50df | 498 | #endif |
2bda0e17 KB |
499 | } |
500 | ||
1e6feb95 VZ |
501 | #endif // wxUSE_MENUS_NATIVE |
502 | ||
2bda0e17 | 503 | // Responds to colour changes, and passes event on to children. |
0d53fc34 | 504 | void wxFrame::OnSysColourChanged(wxSysColourChangedEvent& event) |
2bda0e17 | 505 | { |
98a02e87 | 506 | SetOwnBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE)); |
2bda0e17 KB |
507 | Refresh(); |
508 | ||
1e6feb95 | 509 | #if wxUSE_STATUSBAR |
2bda0e17 KB |
510 | if ( m_frameStatusBar ) |
511 | { | |
512 | wxSysColourChangedEvent event2; | |
513 | event2.SetEventObject( m_frameStatusBar ); | |
937013e0 | 514 | m_frameStatusBar->HandleWindowEvent(event2); |
2bda0e17 | 515 | } |
1e6feb95 | 516 | #endif // wxUSE_STATUSBAR |
2bda0e17 KB |
517 | |
518 | // Propagate the event to the non-top-level children | |
519 | wxWindow::OnSysColourChanged(event); | |
520 | } | |
521 | ||
cbe874bd | 522 | // Pass true to show full screen, false to restore. |
0d53fc34 | 523 | bool wxFrame::ShowFullScreen(bool show, long style) |
a2327a9f | 524 | { |
b01a88e0 VZ |
525 | // TODO-CE: add support for CE |
526 | #if !defined(__WXMICROWIN__) && !defined(__WXWINCE__) | |
085ad686 | 527 | if ( IsFullScreen() == show ) |
cbe874bd | 528 | return false; |
c641b1d2 | 529 | |
a2327a9f JS |
530 | if (show) |
531 | { | |
b01a88e0 VZ |
532 | // zap the toolbar, menubar, and statusbar if needed |
533 | // | |
534 | // TODO: hide commandbar for WINCE_WITH_COMMANDBAR | |
1e6feb95 | 535 | #if wxUSE_TOOLBAR |
f6bcfd97 | 536 | wxToolBar *theToolBar = GetToolBar(); |
a2327a9f JS |
537 | |
538 | if ((style & wxFULLSCREEN_NOTOOLBAR) && theToolBar) | |
539 | { | |
b01a88e0 VZ |
540 | if ( theToolBar->IsShown() ) |
541 | { | |
542 | theToolBar->SetSize(wxDefaultCoord,0); | |
543 | theToolBar->Show(false); | |
544 | } | |
545 | else // prevent it from being restored later | |
546 | { | |
547 | style &= ~wxFULLSCREEN_NOTOOLBAR; | |
548 | } | |
a2327a9f | 549 | } |
1e6feb95 | 550 | #endif // wxUSE_TOOLBAR |
a2327a9f JS |
551 | |
552 | if (style & wxFULLSCREEN_NOMENUBAR) | |
553 | SetMenu((HWND)GetHWND(), (HMENU) NULL); | |
554 | ||
1e6feb95 VZ |
555 | #if wxUSE_STATUSBAR |
556 | wxStatusBar *theStatusBar = GetStatusBar(); | |
1e6feb95 | 557 | |
a2327a9f JS |
558 | // Save the number of fields in the statusbar |
559 | if ((style & wxFULLSCREEN_NOSTATUSBAR) && theStatusBar) | |
560 | { | |
b01a88e0 VZ |
561 | if ( theStatusBar->IsShown() ) |
562 | theStatusBar->Show(false); | |
563 | else | |
564 | style &= ~wxFULLSCREEN_NOSTATUSBAR; | |
a2327a9f | 565 | } |
1e6feb95 | 566 | #endif // wxUSE_STATUSBAR |
a2327a9f | 567 | } |
b01a88e0 | 568 | else // restore to normal |
a2327a9f | 569 | { |
b01a88e0 | 570 | // restore the toolbar, menubar, and statusbar if we had hid them |
1e6feb95 | 571 | #if wxUSE_TOOLBAR |
a2327a9f JS |
572 | wxToolBar *theToolBar = GetToolBar(); |
573 | ||
b01a88e0 | 574 | if ((m_fsStyle & wxFULLSCREEN_NOTOOLBAR) && theToolBar) |
a2327a9f | 575 | { |
cbe874bd | 576 | theToolBar->Show(true); |
a2327a9f | 577 | } |
1e6feb95 | 578 | #endif // wxUSE_TOOLBAR |
a2327a9f | 579 | |
a8ff046b | 580 | #if wxUSE_MENUS |
bc88602a JS |
581 | if (m_fsStyle & wxFULLSCREEN_NOMENUBAR) |
582 | { | |
51181d29 VZ |
583 | const WXHMENU hmenu = MSWGetActiveMenu(); |
584 | if ( hmenu ) | |
585 | ::SetMenu(GetHwnd(), (HMENU)hmenu); | |
bc88602a | 586 | } |
a8ff046b | 587 | #endif // wxUSE_MENUS |
b01a88e0 | 588 | |
1e6feb95 | 589 | #if wxUSE_STATUSBAR |
b01a88e0 VZ |
590 | wxStatusBar *theStatusBar = GetStatusBar(); |
591 | ||
592 | if ((m_fsStyle & wxFULLSCREEN_NOSTATUSBAR) && theStatusBar) | |
a2327a9f | 593 | { |
b01a88e0 VZ |
594 | theStatusBar->Show(true); |
595 | PositionStatusBar(); | |
a2327a9f | 596 | } |
1e6feb95 | 597 | #endif // wxUSE_STATUSBAR |
a2327a9f | 598 | } |
b01a88e0 | 599 | #endif // !defined(__WXMICROWIN__) && !defined(__WXWINCE__) |
f6bcfd97 | 600 | |
085ad686 | 601 | return wxFrameBase::ShowFullScreen(show, style); |
2bda0e17 KB |
602 | } |
603 | ||
7c0ea335 VZ |
604 | // ---------------------------------------------------------------------------- |
605 | // tool/status bar stuff | |
606 | // ---------------------------------------------------------------------------- | |
607 | ||
d427503c | 608 | #if wxUSE_TOOLBAR |
7c0ea335 | 609 | |
0d53fc34 | 610 | wxToolBar* wxFrame::CreateToolBar(long style, wxWindowID id, const wxString& name) |
81d66cf3 | 611 | { |
3d487566 | 612 | #if defined(WINCE_WITHOUT_COMMANDBAR) |
39d2f9a7 JS |
613 | // We may already have a toolbar from calling SetMenuBar. |
614 | if (GetToolBar()) | |
615 | return GetToolBar(); | |
616 | #endif | |
7c0ea335 | 617 | if ( wxFrameBase::CreateToolBar(style, id, name) ) |
81d66cf3 | 618 | { |
81d66cf3 | 619 | PositionToolBar(); |
81d66cf3 | 620 | } |
81d66cf3 | 621 | |
7c0ea335 | 622 | return m_frameToolBar; |
81d66cf3 JS |
623 | } |
624 | ||
0d53fc34 | 625 | void wxFrame::PositionToolBar() |
81d66cf3 | 626 | { |
8898842f VZ |
627 | // TODO: we want to do something different in WinCE, because the toolbar |
628 | // should be associated with the commandbar, instead of being | |
629 | // independent window. | |
630 | #if !defined(WINCE_WITHOUT_COMMANDBAR) | |
d4597e13 VZ |
631 | wxToolBar *toolbar = GetToolBar(); |
632 | if ( toolbar && toolbar->IsShown() ) | |
633 | { | |
634 | // don't call our (or even wxTopLevelWindow) version because we want | |
635 | // the real (full) client area size, not excluding the tool/status bar | |
636 | int width, height; | |
637 | wxWindow::DoGetClientSize(&width, &height); | |
81d66cf3 | 638 | |
7c0ea335 | 639 | #if wxUSE_STATUSBAR |
d4597e13 VZ |
640 | wxStatusBar *statbar = GetStatusBar(); |
641 | if ( statbar && statbar->IsShown() ) | |
642 | { | |
643 | height -= statbar->GetClientSize().y; | |
644 | } | |
7c0ea335 | 645 | #endif // wxUSE_STATUSBAR |
3882e746 VZ |
646 | |
647 | int tx, ty, tw, th; | |
648 | toolbar->GetPosition( &tx, &ty ); | |
649 | toolbar->GetSize( &tw, &th ); | |
650 | ||
dd639a4f | 651 | int x, y; |
3882e746 VZ |
652 | if ( toolbar->HasFlag(wxTB_BOTTOM) ) |
653 | { | |
654 | x = 0; | |
655 | y = height - th; | |
656 | } | |
657 | else if ( toolbar->HasFlag(wxTB_RIGHT) ) | |
658 | { | |
659 | x = width - tw; | |
660 | y = 0; | |
661 | } | |
662 | else // left or top | |
663 | { | |
664 | x = 0; | |
665 | y = 0; | |
666 | } | |
667 | ||
3d487566 | 668 | #if defined(WINCE_WITH_COMMANDBAR) |
fb8a56b7 WS |
669 | // We're using a commandbar - so we have to allow for it. |
670 | if (GetMenuBar() && GetMenuBar()->GetCommandBar()) | |
671 | { | |
672 | RECT rect; | |
673 | ::GetWindowRect((HWND) GetMenuBar()->GetCommandBar(), &rect); | |
674 | y = rect.bottom - rect.top; | |
675 | } | |
3882e746 VZ |
676 | #endif // WINCE_WITH_COMMANDBAR |
677 | ||
678 | if ( toolbar->HasFlag(wxTB_BOTTOM) ) | |
679 | { | |
680 | if ( ty < 0 && ( -ty == th ) ) | |
681 | ty = height - th; | |
682 | if ( tx < 0 && (-tx == tw ) ) | |
683 | tx = 0; | |
684 | } | |
685 | else if ( toolbar->HasFlag(wxTB_RIGHT) ) | |
7a976304 VZ |
686 | { |
687 | if( ty < 0 && ( -ty == th ) ) | |
688 | ty = 0; | |
689 | if( tx < 0 && ( -tx == tw ) ) | |
690 | tx = width - tw; | |
691 | } | |
3882e746 VZ |
692 | else // left or top |
693 | { | |
694 | if (ty < 0 && (-ty == th)) | |
695 | ty = 0; | |
696 | if (tx < 0 && (-tx == tw)) | |
697 | tx = 0; | |
698 | } | |
cbe874bd | 699 | |
229de929 JS |
700 | int desiredW = tw; |
701 | int desiredH = th; | |
81d66cf3 | 702 | |
7a976304 | 703 | if ( toolbar->IsVertical() ) |
81d66cf3 | 704 | { |
229de929 | 705 | desiredH = height; |
81d66cf3 JS |
706 | } |
707 | else | |
708 | { | |
229de929 | 709 | desiredW = width; |
cbe874bd | 710 | } |
7c0ea335 | 711 | |
d4597e13 VZ |
712 | // use the 'real' MSW position here, don't offset relativly to the |
713 | // client area origin | |
229de929 JS |
714 | |
715 | // Optimise such that we don't have to always resize the toolbar | |
cbe874bd | 716 | // when the frame changes, otherwise we'll get a lot of flicker. |
5cb598ae WS |
717 | bool heightChanging wxDUMMY_INITIALIZE(true); |
718 | bool widthChanging wxDUMMY_INITIALIZE(true); | |
cbe874bd | 719 | |
7a976304 | 720 | if ( toolbar->IsVertical() ) |
229de929 JS |
721 | { |
722 | // It's OK if the current height is greater than what can be shown. | |
723 | heightChanging = (desiredH > th) ; | |
724 | widthChanging = (desiredW != tw) ; | |
cbe874bd WS |
725 | |
726 | // The next time around, we may not have to set the size | |
229de929 JS |
727 | if (heightChanging) |
728 | desiredH = desiredH + 200; | |
729 | } | |
730 | else | |
731 | { | |
732 | // It's OK if the current width is greater than what can be shown. | |
733 | widthChanging = (desiredW > tw) ; | |
734 | heightChanging = (desiredH != th) ; | |
735 | ||
cbe874bd | 736 | // The next time around, we may not have to set the size |
229de929 JS |
737 | if (widthChanging) |
738 | desiredW = desiredW + 200; | |
739 | } | |
cbe874bd | 740 | |
229de929 | 741 | if (tx != 0 || ty != 0 || widthChanging || heightChanging) |
45f27284 | 742 | toolbar->SetSize(x, y, desiredW, desiredH, wxSIZE_NO_ADJUSTMENTS); |
cbe874bd | 743 | |
81d66cf3 | 744 | } |
8898842f | 745 | #endif // !WINCE_WITH_COMMANDBAR |
81d66cf3 | 746 | } |
d4597e13 | 747 | |
d427503c | 748 | #endif // wxUSE_TOOLBAR |
d2aef312 | 749 | |
7c0ea335 VZ |
750 | // ---------------------------------------------------------------------------- |
751 | // frame state (iconized/maximized/...) | |
752 | // ---------------------------------------------------------------------------- | |
753 | ||
a23fd0e1 VZ |
754 | // propagate our state change to all child frames: this allows us to emulate X |
755 | // Windows behaviour where child frames float independently of the parent one | |
756 | // on the desktop, but are iconized/restored with it | |
0d53fc34 | 757 | void wxFrame::IconizeChildFrames(bool bIconize) |
d2aef312 | 758 | { |
4bc0f25e VZ |
759 | m_iconized = bIconize; |
760 | ||
222ed1d6 | 761 | for ( wxWindowList::compatibility_iterator node = GetChildren().GetFirst(); |
a23fd0e1 VZ |
762 | node; |
763 | node = node->GetNext() ) | |
764 | { | |
765 | wxWindow *win = node->GetData(); | |
766 | ||
3ca6a5f0 BP |
767 | // iconizing the frames with this style under Win95 shell puts them at |
768 | // the bottom of the screen (as the MDI children) instead of making | |
769 | // them appear in the taskbar because they are, by virtue of this | |
770 | // style, not managed by the taskbar - instead leave Windows take care | |
771 | // of them | |
3ca6a5f0 BP |
772 | if ( win->GetWindowStyle() & wxFRAME_TOOL_WINDOW ) |
773 | continue; | |
3ca6a5f0 | 774 | |
3f7bc32b VZ |
775 | // the child MDI frames are a special case and should not be touched by |
776 | // the parent frame - instead, they are managed by the user | |
2e9f62da | 777 | wxFrame *frame = wxDynamicCast(win, wxFrame); |
1e6feb95 VZ |
778 | if ( frame |
779 | #if wxUSE_MDI_ARCHITECTURE | |
4ab2824c | 780 | && !frame->IsMDIChild() |
1e6feb95 VZ |
781 | #endif // wxUSE_MDI_ARCHITECTURE |
782 | ) | |
a23fd0e1 | 783 | { |
9327c3aa VZ |
784 | // we don't want to restore the child frames which had been |
785 | // iconized even before we were iconized, so save the child frame | |
786 | // status when iconizing the parent frame and check it when | |
787 | // restoring it | |
788 | if ( bIconize ) | |
789 | { | |
9c72ebec | 790 | frame->m_wasMinimized = frame->IsIconized(); |
9327c3aa VZ |
791 | } |
792 | ||
9c72ebec VZ |
793 | // note that we shouldn't touch the hidden frames neither because |
794 | // iconizing/restoring them would show them as a side effect | |
795 | if ( !frame->m_wasMinimized && frame->IsShown() ) | |
9327c3aa | 796 | frame->Iconize(bIconize); |
a23fd0e1 | 797 | } |
d2aef312 | 798 | } |
d2aef312 VZ |
799 | } |
800 | ||
0d53fc34 | 801 | WXHICON wxFrame::GetDefaultIcon() const |
82c9f85c | 802 | { |
94826170 VZ |
803 | // we don't have any standard icons (any more) |
804 | return (WXHICON)0; | |
82c9f85c VZ |
805 | } |
806 | ||
a23fd0e1 | 807 | // =========================================================================== |
42e69d6b | 808 | // message processing |
a23fd0e1 VZ |
809 | // =========================================================================== |
810 | ||
42e69d6b VZ |
811 | // --------------------------------------------------------------------------- |
812 | // preprocessing | |
813 | // --------------------------------------------------------------------------- | |
814 | ||
1ac76609 | 815 | bool wxFrame::MSWDoTranslateMessage(wxFrame *frame, WXMSG *pMsg) |
42e69d6b VZ |
816 | { |
817 | if ( wxWindow::MSWTranslateMessage(pMsg) ) | |
cbe874bd | 818 | return true; |
42e69d6b | 819 | |
1e6feb95 | 820 | #if wxUSE_MENUS && wxUSE_ACCEL && !defined(__WXUNIVERSAL__) |
7802da36 | 821 | // try the menu bar accelerators |
42e69d6b | 822 | wxMenuBar *menuBar = GetMenuBar(); |
7802da36 VZ |
823 | if ( menuBar && menuBar->GetAcceleratorTable()->Translate(frame, pMsg) ) |
824 | return true; | |
a1a1ca89 | 825 | #endif // wxUSE_MENUS && wxUSE_ACCEL |
42e69d6b | 826 | |
cbe874bd | 827 | return false; |
42e69d6b VZ |
828 | } |
829 | ||
830 | // --------------------------------------------------------------------------- | |
831 | // our private (non virtual) message handlers | |
832 | // --------------------------------------------------------------------------- | |
833 | ||
4bc0f25e | 834 | bool wxFrame::HandleSize(int WXUNUSED(x), int WXUNUSED(y), WXUINT id) |
42e69d6b | 835 | { |
4676948b | 836 | #if !defined(__WXMICROWIN__) && !defined(__WXWINCE__) |
42e69d6b VZ |
837 | switch ( id ) |
838 | { | |
4bc0f25e VZ |
839 | case SIZE_RESTORED: |
840 | case SIZE_MAXIMIZED: | |
42e69d6b VZ |
841 | // only do it it if we were iconized before, otherwise resizing the |
842 | // parent frame has a curious side effect of bringing it under it's | |
843 | // children | |
844 | if ( !m_iconized ) | |
845 | break; | |
846 | ||
847 | // restore all child frames too | |
cbe874bd | 848 | IconizeChildFrames(false); |
42e69d6b | 849 | |
cbe874bd | 850 | (void)SendIconizeEvent(false); |
42e69d6b VZ |
851 | break; |
852 | ||
4bc0f25e | 853 | case SIZE_MINIMIZED: |
42e69d6b | 854 | // iconize all child frames too |
cbe874bd | 855 | IconizeChildFrames(true); |
42e69d6b VZ |
856 | break; |
857 | } | |
276c8cfb WS |
858 | #else |
859 | wxUnusedVar(id); | |
4bc0f25e | 860 | #endif // !__WXWINCE__ |
42e69d6b VZ |
861 | |
862 | if ( !m_iconized ) | |
863 | { | |
1e6feb95 | 864 | #if wxUSE_STATUSBAR |
42e69d6b | 865 | PositionStatusBar(); |
1e6feb95 VZ |
866 | #endif // wxUSE_STATUSBAR |
867 | ||
868 | #if wxUSE_TOOLBAR | |
42e69d6b | 869 | PositionToolBar(); |
1e6feb95 | 870 | #endif // wxUSE_TOOLBAR |
42e69d6b | 871 | |
3d487566 | 872 | #if defined(WINCE_WITH_COMMANDBAR) |
fb8a56b7 WS |
873 | // Position the menu command bar |
874 | if (GetMenuBar() && GetMenuBar()->GetCommandBar()) | |
875 | { | |
876 | RECT rect; | |
877 | ::GetWindowRect((HWND) GetMenuBar()->GetCommandBar(), &rect); | |
878 | wxSize clientSz = GetClientSize(); | |
879 | ||
880 | if ( !::MoveWindow((HWND) GetMenuBar()->GetCommandBar(), 0, 0, clientSz.x, rect.bottom - rect.top, true ) ) | |
881 | { | |
882 | wxLogLastError(wxT("MoveWindow")); | |
883 | } | |
884 | ||
885 | } | |
4bc0f25e | 886 | #endif // WINCE_WITH_COMMANDBAR |
42e69d6b VZ |
887 | } |
888 | ||
4bc0f25e VZ |
889 | // call the base class version to generate the appropriate events |
890 | return false; | |
42e69d6b VZ |
891 | } |
892 | ||
1483e5db | 893 | bool wxFrame::HandleCommand(WXWORD id, WXWORD cmd, WXHWND control) |
42e69d6b | 894 | { |
1483e5db | 895 | #if wxUSE_MENUS |
a6ac49b1 VZ |
896 | // we only need to handle the menu and accelerator commands from the items |
897 | // of our menu bar, base wxWindow class already handles the rest | |
898 | if ( !control && (cmd == 0 /* menu */ || cmd == 1 /* accel */) ) | |
42e69d6b | 899 | { |
1e6feb95 | 900 | #if wxUSE_MENUS_NATIVE |
a6ac49b1 | 901 | if ( !wxCurrentPopupMenu ) |
1e6feb95 | 902 | #endif // wxUSE_MENUS_NATIVE |
fb8a56b7 | 903 | { |
79f9ea05 | 904 | wxMenuItem * const mitem = FindItemInMenuBar((signed short)id); |
1483e5db VZ |
905 | if ( mitem ) |
906 | return ProcessCommand(mitem); | |
42e69d6b VZ |
907 | } |
908 | } | |
1483e5db | 909 | #endif // wxUSE_MENUS |
42e69d6b | 910 | |
1483e5db | 911 | return wxFrameBase::HandleCommand(id, cmd, control);; |
42e69d6b VZ |
912 | } |
913 | ||
a8ff046b VZ |
914 | #if wxUSE_MENUS |
915 | ||
0d53fc34 | 916 | bool wxFrame::HandleMenuSelect(WXWORD nItem, WXWORD flags, WXHMENU hMenu) |
a23fd0e1 VZ |
917 | { |
918 | int item; | |
c219cecc | 919 | if ( flags == 0xFFFF && hMenu == 0 ) |
a23fd0e1 | 920 | { |
c219cecc | 921 | // menu was removed from screen |
a23fd0e1 VZ |
922 | item = -1; |
923 | } | |
04ef50df | 924 | #ifndef __WXMICROWIN__ |
c219cecc | 925 | else if ( !(flags & MF_POPUP) && !(flags & MF_SEPARATOR) ) |
a23fd0e1 VZ |
926 | { |
927 | item = nItem; | |
928 | } | |
04ef50df | 929 | #endif |
a23fd0e1 VZ |
930 | else |
931 | { | |
c219cecc | 932 | // don't give hints for separators (doesn't make sense) nor for the |
f6bcfd97 BP |
933 | // items opening popup menus (they don't have them anyhow) but do clear |
934 | // the status line - otherwise, we would be left with the help message | |
935 | // for the previous item which doesn't apply any more | |
6d99eb3e | 936 | DoGiveHelp(wxEmptyString, true); |
f6bcfd97 | 937 | |
cbe874bd | 938 | return false; |
a23fd0e1 VZ |
939 | } |
940 | ||
941 | wxMenuEvent event(wxEVT_MENU_HIGHLIGHT, item); | |
ccef86c7 VZ |
942 | event.SetEventObject(this); |
943 | ||
937013e0 | 944 | return HandleWindowEvent(event); |
ccef86c7 VZ |
945 | } |
946 | ||
947 | bool wxFrame::HandleMenuLoop(const wxEventType& evtType, WXWORD isPopup) | |
948 | { | |
949 | // we don't have the menu id here, so we use the id to specify if the event | |
950 | // was from a popup menu or a normal one | |
951 | wxMenuEvent event(evtType, isPopup ? -1 : 0); | |
952 | event.SetEventObject(this); | |
a23fd0e1 | 953 | |
937013e0 | 954 | return HandleWindowEvent(event); |
a23fd0e1 VZ |
955 | } |
956 | ||
a8ff046b VZ |
957 | bool wxFrame::HandleInitMenuPopup(WXHMENU hMenu) |
958 | { | |
959 | wxMenu* menu = NULL; | |
960 | if (GetMenuBar()) | |
961 | { | |
962 | int nCount = GetMenuBar()->GetMenuCount(); | |
963 | for (int n = 0; n < nCount; n++) | |
964 | { | |
965 | if (GetMenuBar()->GetMenu(n)->GetHMenu() == hMenu) | |
966 | { | |
967 | menu = GetMenuBar()->GetMenu(n); | |
968 | break; | |
969 | } | |
970 | } | |
971 | } | |
972 | ||
973 | wxMenuEvent event(wxEVT_MENU_OPEN, 0, menu); | |
974 | event.SetEventObject(this); | |
975 | ||
937013e0 | 976 | return HandleWindowEvent(event); |
a8ff046b VZ |
977 | } |
978 | ||
979 | #endif // wxUSE_MENUS | |
980 | ||
a23fd0e1 | 981 | // --------------------------------------------------------------------------- |
0d53fc34 | 982 | // the window proc for wxFrame |
a23fd0e1 VZ |
983 | // --------------------------------------------------------------------------- |
984 | ||
c140b7e7 | 985 | WXLRESULT wxFrame::MSWWindowProc(WXUINT message, WXWPARAM wParam, WXLPARAM lParam) |
a23fd0e1 | 986 | { |
c140b7e7 | 987 | WXLRESULT rc = 0; |
cbe874bd | 988 | bool processed = false; |
a23fd0e1 VZ |
989 | |
990 | switch ( message ) | |
991 | { | |
42e69d6b VZ |
992 | case WM_CLOSE: |
993 | // if we can't close, tell the system that we processed the | |
994 | // message - otherwise it would close us | |
995 | processed = !Close(); | |
996 | break; | |
997 | ||
ccef86c7 VZ |
998 | case WM_SIZE: |
999 | processed = HandleSize(LOWORD(lParam), HIWORD(lParam), wParam); | |
1000 | break; | |
1001 | ||
42e69d6b VZ |
1002 | case WM_COMMAND: |
1003 | { | |
1004 | WORD id, cmd; | |
1005 | WXHWND hwnd; | |
1006 | UnpackCommand((WXWPARAM)wParam, (WXLPARAM)lParam, | |
1007 | &id, &hwnd, &cmd); | |
1008 | ||
a6ac49b1 VZ |
1009 | HandleCommand(id, cmd, (WXHWND)hwnd); |
1010 | ||
1011 | // don't pass WM_COMMAND to the base class whether we processed | |
1012 | // it or not because we did generate an event for it (our | |
1013 | // HandleCommand() calls the base class version) and we must | |
1014 | // not do it again or the handlers which skip the event would | |
1015 | // be called twice | |
1016 | processed = true; | |
42e69d6b VZ |
1017 | } |
1018 | break; | |
1019 | ||
a8ff046b VZ |
1020 | #if !defined(__WXMICROWIN__) && !defined(__WXWINCE__) |
1021 | #if wxUSE_MENUS | |
92f1a59c JS |
1022 | case WM_INITMENUPOPUP: |
1023 | processed = HandleInitMenuPopup((WXHMENU) wParam); | |
1024 | break; | |
1025 | ||
a23fd0e1 VZ |
1026 | case WM_MENUSELECT: |
1027 | { | |
42e69d6b VZ |
1028 | WXWORD item, flags; |
1029 | WXHMENU hmenu; | |
1030 | UnpackMenuSelect(wParam, lParam, &item, &flags, &hmenu); | |
1031 | ||
1032 | processed = HandleMenuSelect(item, flags, hmenu); | |
a23fd0e1 VZ |
1033 | } |
1034 | break; | |
bc92cdf9 | 1035 | |
ccef86c7 | 1036 | case WM_EXITMENULOOP: |
373a5fb3 | 1037 | processed = HandleMenuLoop(wxEVT_MENU_CLOSE, (WXWORD)wParam); |
ccef86c7 | 1038 | break; |
a8ff046b | 1039 | #endif // wxUSE_MENUS |
ccef86c7 | 1040 | |
42e69d6b VZ |
1041 | case WM_QUERYDRAGICON: |
1042 | { | |
f618020a MB |
1043 | const wxIcon& icon = GetIcon(); |
1044 | HICON hIcon = icon.Ok() ? GetHiconOf(icon) | |
1045 | : (HICON)GetDefaultIcon(); | |
dca0f651 | 1046 | rc = (WXLRESULT)hIcon; |
42e69d6b VZ |
1047 | processed = rc != 0; |
1048 | } | |
1049 | break; | |
ccef86c7 | 1050 | #endif // !__WXMICROWIN__ |
a23fd0e1 VZ |
1051 | } |
1052 | ||
1053 | if ( !processed ) | |
7e25f59e | 1054 | rc = wxFrameBase::MSWWindowProc(message, wParam, lParam); |
a23fd0e1 VZ |
1055 | |
1056 | return rc; | |
1057 | } | |
21802234 | 1058 | |
a9928e9d JS |
1059 | // ---------------------------------------------------------------------------- |
1060 | // wxFrame size management: we exclude the areas taken by menu/status/toolbars | |
1061 | // from the client area, so the client area is what's really available for the | |
1062 | // frame contents | |
1063 | // ---------------------------------------------------------------------------- | |
1064 | ||
1065 | // get the origin of the client area in the client coordinates | |
1066 | wxPoint wxFrame::GetClientAreaOrigin() const | |
1067 | { | |
1068 | wxPoint pt = wxTopLevelWindow::GetClientAreaOrigin(); | |
1069 | ||
1070 | #if wxUSE_TOOLBAR && !defined(__WXUNIVERSAL__) && \ | |
1071 | (!defined(__WXWINCE__) || (_WIN32_WCE >= 400 && !defined(__POCKETPC__) && !defined(__SMARTPHONE__))) | |
3882e746 | 1072 | wxToolBar * const toolbar = GetToolBar(); |
a9928e9d JS |
1073 | if ( toolbar && toolbar->IsShown() ) |
1074 | { | |
3882e746 | 1075 | const wxSize sizeTB = toolbar->GetSize(); |
a9928e9d | 1076 | |
3882e746 | 1077 | if ( toolbar->HasFlag(wxTB_TOP) ) |
a9928e9d | 1078 | { |
3882e746 | 1079 | pt.y += sizeTB.y; |
a9928e9d | 1080 | } |
3882e746 | 1081 | else if ( toolbar->HasFlag(wxTB_LEFT) ) |
a9928e9d | 1082 | { |
3882e746 | 1083 | pt.x += sizeTB.x; |
a9928e9d JS |
1084 | } |
1085 | } | |
1086 | #endif // wxUSE_TOOLBAR | |
1087 | ||
3d487566 | 1088 | #if defined(WINCE_WITH_COMMANDBAR) |
fb8a56b7 WS |
1089 | if (GetMenuBar() && GetMenuBar()->GetCommandBar()) |
1090 | { | |
1091 | RECT rect; | |
1092 | ::GetWindowRect((HWND) GetMenuBar()->GetCommandBar(), &rect); | |
1093 | pt.y += (rect.bottom - rect.top); | |
1094 | } | |
a9928e9d JS |
1095 | #endif |
1096 | ||
1097 | return pt; | |
1098 | } |