]>
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 | { |
cbe874bd | 212 | m_isBeingDeleted = true; |
82c9f85c | 213 | DeleteAllBars(); |
2bda0e17 KB |
214 | } |
215 | ||
d4597e13 VZ |
216 | // ---------------------------------------------------------------------------- |
217 | // wxFrame client size calculations | |
218 | // ---------------------------------------------------------------------------- | |
2bda0e17 | 219 | |
0d53fc34 | 220 | void wxFrame::DoSetClientSize(int width, int height) |
2bda0e17 | 221 | { |
82c9f85c | 222 | // leave enough space for the status bar if we have (and show) it |
7c0ea335 | 223 | #if wxUSE_STATUSBAR |
8d8bd249 VZ |
224 | wxStatusBar *statbar = GetStatusBar(); |
225 | if ( statbar && statbar->IsShown() ) | |
226 | { | |
8d8bd249 VZ |
227 | height += statbar->GetSize().y; |
228 | } | |
7c0ea335 | 229 | #endif // wxUSE_STATUSBAR |
2bda0e17 | 230 | |
68d02db3 VZ |
231 | // call GetClientAreaOrigin() to take the toolbar into account |
232 | wxPoint pt = GetClientAreaOrigin(); | |
233 | width += pt.x; | |
234 | height += pt.y; | |
3882e746 | 235 | |
7a976304 | 236 | #if wxUSE_TOOLBAR |
3882e746 VZ |
237 | wxToolBar * const toolbar = GetToolBar(); |
238 | if ( toolbar ) | |
7a976304 | 239 | { |
3882e746 | 240 | if ( toolbar->HasFlag(wxTB_RIGHT | wxTB_BOTTOM) ) |
7a976304 | 241 | { |
3882e746 VZ |
242 | const wxSize sizeTB = toolbar->GetSize(); |
243 | if ( toolbar->HasFlag(wxTB_RIGHT) ) | |
244 | width -= sizeTB.x; | |
245 | else // wxTB_BOTTOM | |
246 | height -= sizeTB.y; | |
7a976304 | 247 | } |
3882e746 | 248 | //else: toolbar already taken into account by GetClientAreaOrigin() |
7a976304 | 249 | } |
3882e746 | 250 | #endif // wxUSE_TOOLBAR |
68d02db3 | 251 | |
82c9f85c | 252 | wxTopLevelWindow::DoSetClientSize(width, height); |
2bda0e17 KB |
253 | } |
254 | ||
d4597e13 VZ |
255 | // Get size *available for subwindows* i.e. excluding menu bar, toolbar etc. |
256 | void wxFrame::DoGetClientSize(int *x, int *y) const | |
257 | { | |
258 | wxTopLevelWindow::DoGetClientSize(x, y); | |
259 | ||
68d02db3 VZ |
260 | // account for the possible toolbar |
261 | wxPoint pt = GetClientAreaOrigin(); | |
262 | if ( x ) | |
263 | *x -= pt.x; | |
264 | ||
265 | if ( y ) | |
266 | *y -= pt.y; | |
3882e746 | 267 | |
5b2acc3a | 268 | #if wxUSE_TOOLBAR |
3882e746 VZ |
269 | wxToolBar * const toolbar = GetToolBar(); |
270 | if ( toolbar ) | |
5b2acc3a | 271 | { |
3882e746 | 272 | if ( toolbar->HasFlag(wxTB_RIGHT | wxTB_BOTTOM) ) |
5b2acc3a | 273 | { |
3882e746 VZ |
274 | const wxSize sizeTB = toolbar->GetSize(); |
275 | if ( toolbar->HasFlag(wxTB_RIGHT) ) | |
276 | { | |
277 | if ( x ) | |
278 | *x -= sizeTB.x; | |
279 | } | |
280 | else // wxTB_BOTTOM | |
281 | { | |
282 | if ( y ) | |
283 | *y -= sizeTB.y; | |
284 | } | |
7a976304 | 285 | } |
3882e746 | 286 | //else: toolbar already taken into account by GetClientAreaOrigin() |
7a976304 | 287 | } |
3882e746 VZ |
288 | #endif // wxUSE_TOOLBAR |
289 | ||
d4597e13 VZ |
290 | #if wxUSE_STATUSBAR |
291 | // adjust client area height to take the status bar into account | |
292 | if ( y ) | |
293 | { | |
294 | wxStatusBar *statbar = GetStatusBar(); | |
295 | if ( statbar && statbar->IsShown() ) | |
296 | { | |
297 | *y -= statbar->GetClientSize().y; | |
298 | } | |
299 | } | |
300 | #endif // wxUSE_STATUSBAR | |
301 | } | |
302 | ||
7c0ea335 | 303 | // ---------------------------------------------------------------------------- |
0d53fc34 | 304 | // wxFrame: various geometry-related functions |
7c0ea335 VZ |
305 | // ---------------------------------------------------------------------------- |
306 | ||
0d53fc34 | 307 | void wxFrame::Raise() |
c48926e1 | 308 | { |
c48926e1 | 309 | ::SetForegroundWindow(GetHwnd()); |
c48926e1 VZ |
310 | } |
311 | ||
67bd5bad | 312 | // generate an artificial resize event |
ecdc1183 | 313 | void wxFrame::SendSizeEvent(int flags) |
67bd5bad | 314 | { |
67bd5bad GT |
315 | if ( !m_iconized ) |
316 | { | |
82c9f85c VZ |
317 | RECT r = wxGetWindowRect(GetHwnd()); |
318 | ||
ecdc1183 VZ |
319 | if ( flags & wxSEND_EVENT_POST ) |
320 | { | |
321 | ::PostMessage(GetHwnd(), WM_SIZE, | |
322 | IsMaximized() ? SIZE_MAXIMIZED : SIZE_RESTORED, | |
323 | MAKELPARAM(r.right - r.left, r.bottom - r.top)); | |
324 | } | |
325 | else // send it | |
326 | { | |
327 | ::SendMessage(GetHwnd(), WM_SIZE, | |
328 | IsMaximized() ? SIZE_MAXIMIZED : SIZE_RESTORED, | |
329 | MAKELPARAM(r.right - r.left, r.bottom - r.top)); | |
330 | } | |
67bd5bad GT |
331 | } |
332 | } | |
333 | ||
d427503c | 334 | #if wxUSE_STATUSBAR |
0d53fc34 | 335 | wxStatusBar *wxFrame::OnCreateStatusBar(int number, |
7c0ea335 VZ |
336 | long style, |
337 | wxWindowID id, | |
338 | const wxString& name) | |
2bda0e17 | 339 | { |
5cb598ae | 340 | wxStatusBar *statusBar wxDUMMY_INITIALIZE(NULL); |
2bda0e17 | 341 | |
47d67540 | 342 | #if wxUSE_NATIVE_STATUSBAR |
1f0500b3 | 343 | if ( !UsesNativeStatusBar() ) |
2bda0e17 | 344 | { |
1f0500b3 | 345 | statusBar = (wxStatusBar *)new wxStatusBarGeneric(this, id, style); |
2bda0e17 KB |
346 | } |
347 | else | |
348 | #endif | |
349 | { | |
1f0500b3 VZ |
350 | statusBar = new wxStatusBar(this, id, style, name); |
351 | } | |
ed791986 | 352 | |
1f0500b3 | 353 | statusBar->SetFieldsCount(number); |
2bda0e17 | 354 | |
7c0ea335 | 355 | return statusBar; |
2bda0e17 KB |
356 | } |
357 | ||
0d53fc34 | 358 | void wxFrame::PositionStatusBar() |
2bda0e17 | 359 | { |
d4597e13 | 360 | if ( !m_frameStatusBar || !m_frameStatusBar->IsShown() ) |
ed791986 VZ |
361 | return; |
362 | ||
cbc66a27 VZ |
363 | int w, h; |
364 | GetClientSize(&w, &h); | |
3882e746 | 365 | |
cbc66a27 VZ |
366 | int sw, sh; |
367 | m_frameStatusBar->GetSize(&sw, &sh); | |
368 | ||
8efbb8ad VZ |
369 | int x = 0; |
370 | #if wxUSE_TOOLBAR | |
371 | wxToolBar * const toolbar = GetToolBar(); | |
372 | if ( toolbar && !toolbar->HasFlag(wxTB_TOP) ) | |
373 | { | |
374 | const wxSize sizeTB = toolbar->GetSize(); | |
375 | ||
376 | if ( toolbar->HasFlag(wxTB_LEFT | wxTB_RIGHT) ) | |
377 | { | |
378 | if ( toolbar->HasFlag(wxTB_LEFT) ) | |
379 | x -= sizeTB.x; | |
380 | ||
381 | w += sizeTB.x; | |
382 | } | |
383 | else // wxTB_BOTTOM | |
384 | { | |
385 | // we need to position the status bar below the toolbar | |
386 | h += sizeTB.y; | |
387 | } | |
388 | } | |
389 | //else: no adjustments necessary for the toolbar on top | |
390 | #endif // wxUSE_TOOLBAR | |
391 | ||
cbc66a27 VZ |
392 | // Since we wish the status bar to be directly under the client area, |
393 | // we use the adjusted sizes without using wxSIZE_NO_ADJUSTMENTS. | |
8efbb8ad | 394 | m_frameStatusBar->SetSize(x, h, w, sh); |
2bda0e17 | 395 | } |
3882e746 | 396 | |
d427503c | 397 | #endif // wxUSE_STATUSBAR |
2bda0e17 | 398 | |
6522713c | 399 | #if wxUSE_MENUS_NATIVE |
ea9a4296 | 400 | |
0d53fc34 | 401 | void wxFrame::AttachMenuBar(wxMenuBar *menubar) |
2bda0e17 | 402 | { |
3180bc0e | 403 | #if defined(__SMARTPHONE__) && defined(__WXWINCE__) |
fb8a56b7 | 404 | |
ed679e74 WS |
405 | wxMenu *autoMenu = NULL; |
406 | ||
407 | if( menubar->GetMenuCount() == 1 ) | |
408 | { | |
409 | autoMenu = wxTopLevelWindowMSW::ButtonMenu::DuplicateMenu(menubar->GetMenu(0)); | |
52af3158 | 410 | SetRightMenu(wxID_ANY, menubar->GetMenuLabel(0), autoMenu); |
ed679e74 WS |
411 | } |
412 | else | |
fb8a56b7 | 413 | { |
ed679e74 WS |
414 | autoMenu = new wxMenu; |
415 | ||
416 | for( size_t n = 0; n < menubar->GetMenuCount(); n++ ) | |
417 | { | |
418 | wxMenu *item = menubar->GetMenu(n); | |
52af3158 | 419 | wxString label = menubar->GetMenuLabel(n); |
ed679e74 WS |
420 | wxMenu *new_item = wxTopLevelWindowMSW::ButtonMenu::DuplicateMenu(item); |
421 | autoMenu->Append(wxID_ANY, label, new_item); | |
422 | } | |
423 | ||
424 | SetRightMenu(wxID_ANY, _("Menu"), autoMenu); | |
fb8a56b7 WS |
425 | } |
426 | ||
fb8a56b7 | 427 | #elif defined(WINCE_WITHOUT_COMMANDBAR) |
a96b4743 JS |
428 | if (!GetToolBar()) |
429 | { | |
a9102b36 | 430 | wxToolMenuBar* toolBar = new wxToolMenuBar(this, wxID_ANY, |
a96b4743 JS |
431 | wxDefaultPosition, wxDefaultSize, |
432 | wxBORDER_NONE | wxTB_HORIZONTAL, | |
af5454a4 | 433 | wxToolBarNameStr, menubar); |
a96b4743 JS |
434 | SetToolBar(toolBar); |
435 | menubar->SetToolBar(toolBar); | |
436 | } | |
fb8a56b7 WS |
437 | // Now adjust size for menu bar |
438 | int menuHeight = 26; | |
439 | ||
440 | //When the main window is created using CW_USEDEFAULT the height of the | |
441 | // is created is not taken into account). So we resize the window after | |
442 | // if a menubar is present | |
443 | { | |
444 | RECT rc; | |
445 | ::GetWindowRect((HWND) GetHWND(), &rc); | |
446 | // adjust for menu / titlebar height | |
447 | rc.bottom -= (2*menuHeight-1); | |
448 | ||
cbe874bd | 449 | ::MoveWindow((HWND) GetHWND(), rc.left, rc.top, rc.right, rc.bottom, FALSE); |
fb8a56b7 | 450 | } |
a96b4743 JS |
451 | #endif |
452 | ||
f008af16 | 453 | wxFrameBase::AttachMenuBar(menubar); |
6beb85c0 | 454 | |
f6bcfd97 | 455 | if ( !menubar ) |
c2dcfdef | 456 | { |
f6bcfd97 BP |
457 | // actually remove the menu from the frame |
458 | m_hMenu = (WXHMENU)0; | |
459 | InternalSetMenuBar(); | |
065de612 | 460 | } |
f6bcfd97 | 461 | else // set new non NULL menu bar |
065de612 | 462 | { |
3d487566 | 463 | #if !defined(__WXWINCE__) || defined(WINCE_WITH_COMMANDBAR) |
f6bcfd97 | 464 | // Can set a menubar several times. |
f6bcfd97 BP |
465 | if ( menubar->GetHMenu() ) |
466 | { | |
467 | m_hMenu = menubar->GetHMenu(); | |
468 | } | |
f008af16 | 469 | else // no HMENU yet |
f6bcfd97 | 470 | { |
f6bcfd97 | 471 | m_hMenu = menubar->Create(); |
065de612 | 472 | |
f6bcfd97 | 473 | if ( !m_hMenu ) |
f008af16 VZ |
474 | { |
475 | wxFAIL_MSG( _T("failed to create menu bar") ); | |
f6bcfd97 | 476 | return; |
f008af16 | 477 | } |
f6bcfd97 | 478 | } |
39d2f9a7 | 479 | #endif |
f6bcfd97 | 480 | InternalSetMenuBar(); |
1e6feb95 | 481 | } |
2bda0e17 KB |
482 | } |
483 | ||
0d53fc34 | 484 | void wxFrame::InternalSetMenuBar() |
2bda0e17 | 485 | { |
a96b4743 | 486 | #if defined(__WXMICROWIN__) || defined(__WXWINCE__) |
4676948b | 487 | // Nothing |
4676948b | 488 | #else |
42e69d6b | 489 | if ( !::SetMenu(GetHwnd(), (HMENU)m_hMenu) ) |
2bda0e17 | 490 | { |
f6bcfd97 | 491 | wxLogLastError(wxT("SetMenu")); |
2bda0e17 | 492 | } |
04ef50df | 493 | #endif |
2bda0e17 KB |
494 | } |
495 | ||
1e6feb95 VZ |
496 | #endif // wxUSE_MENUS_NATIVE |
497 | ||
2bda0e17 | 498 | // Responds to colour changes, and passes event on to children. |
0d53fc34 | 499 | void wxFrame::OnSysColourChanged(wxSysColourChangedEvent& event) |
2bda0e17 | 500 | { |
98a02e87 | 501 | SetOwnBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE)); |
2bda0e17 KB |
502 | Refresh(); |
503 | ||
1e6feb95 | 504 | #if wxUSE_STATUSBAR |
2bda0e17 KB |
505 | if ( m_frameStatusBar ) |
506 | { | |
507 | wxSysColourChangedEvent event2; | |
508 | event2.SetEventObject( m_frameStatusBar ); | |
937013e0 | 509 | m_frameStatusBar->HandleWindowEvent(event2); |
2bda0e17 | 510 | } |
1e6feb95 | 511 | #endif // wxUSE_STATUSBAR |
2bda0e17 KB |
512 | |
513 | // Propagate the event to the non-top-level children | |
514 | wxWindow::OnSysColourChanged(event); | |
515 | } | |
516 | ||
cbe874bd | 517 | // Pass true to show full screen, false to restore. |
0d53fc34 | 518 | bool wxFrame::ShowFullScreen(bool show, long style) |
a2327a9f | 519 | { |
b01a88e0 VZ |
520 | // TODO-CE: add support for CE |
521 | #if !defined(__WXMICROWIN__) && !defined(__WXWINCE__) | |
085ad686 | 522 | if ( IsFullScreen() == show ) |
cbe874bd | 523 | return false; |
c641b1d2 | 524 | |
a2327a9f JS |
525 | if (show) |
526 | { | |
b01a88e0 VZ |
527 | // zap the toolbar, menubar, and statusbar if needed |
528 | // | |
529 | // TODO: hide commandbar for WINCE_WITH_COMMANDBAR | |
1e6feb95 | 530 | #if wxUSE_TOOLBAR |
f6bcfd97 | 531 | wxToolBar *theToolBar = GetToolBar(); |
a2327a9f JS |
532 | |
533 | if ((style & wxFULLSCREEN_NOTOOLBAR) && theToolBar) | |
534 | { | |
b01a88e0 VZ |
535 | if ( theToolBar->IsShown() ) |
536 | { | |
537 | theToolBar->SetSize(wxDefaultCoord,0); | |
538 | theToolBar->Show(false); | |
539 | } | |
540 | else // prevent it from being restored later | |
541 | { | |
542 | style &= ~wxFULLSCREEN_NOTOOLBAR; | |
543 | } | |
a2327a9f | 544 | } |
1e6feb95 | 545 | #endif // wxUSE_TOOLBAR |
a2327a9f JS |
546 | |
547 | if (style & wxFULLSCREEN_NOMENUBAR) | |
548 | SetMenu((HWND)GetHWND(), (HMENU) NULL); | |
549 | ||
1e6feb95 VZ |
550 | #if wxUSE_STATUSBAR |
551 | wxStatusBar *theStatusBar = GetStatusBar(); | |
1e6feb95 | 552 | |
a2327a9f JS |
553 | // Save the number of fields in the statusbar |
554 | if ((style & wxFULLSCREEN_NOSTATUSBAR) && theStatusBar) | |
555 | { | |
b01a88e0 VZ |
556 | if ( theStatusBar->IsShown() ) |
557 | theStatusBar->Show(false); | |
558 | else | |
559 | style &= ~wxFULLSCREEN_NOSTATUSBAR; | |
a2327a9f | 560 | } |
1e6feb95 | 561 | #endif // wxUSE_STATUSBAR |
a2327a9f | 562 | } |
b01a88e0 | 563 | else // restore to normal |
a2327a9f | 564 | { |
b01a88e0 | 565 | // restore the toolbar, menubar, and statusbar if we had hid them |
1e6feb95 | 566 | #if wxUSE_TOOLBAR |
a2327a9f JS |
567 | wxToolBar *theToolBar = GetToolBar(); |
568 | ||
b01a88e0 | 569 | if ((m_fsStyle & wxFULLSCREEN_NOTOOLBAR) && theToolBar) |
a2327a9f | 570 | { |
cbe874bd | 571 | theToolBar->Show(true); |
a2327a9f | 572 | } |
1e6feb95 | 573 | #endif // wxUSE_TOOLBAR |
a2327a9f | 574 | |
a8ff046b | 575 | #if wxUSE_MENUS |
bc88602a JS |
576 | if (m_fsStyle & wxFULLSCREEN_NOMENUBAR) |
577 | { | |
578 | WXHMENU menu = m_hMenu; | |
579 | ||
580 | #if wxUSE_MDI_ARCHITECTURE | |
581 | wxMDIParentFrame *frame = wxDynamicCast(this, wxMDIParentFrame); | |
582 | if (frame) | |
583 | { | |
584 | wxMDIChildFrame *child = frame->GetActiveChild(); | |
585 | if (child) | |
586 | { | |
587 | menu = child->GetWinMenu(); | |
588 | } | |
589 | } | |
590 | #endif // wxUSE_MDI_ARCHITECTURE | |
591 | ||
592 | if (menu) | |
593 | { | |
594 | ::SetMenu(GetHwnd(), (HMENU)menu); | |
595 | } | |
596 | } | |
a8ff046b | 597 | #endif // wxUSE_MENUS |
b01a88e0 | 598 | |
1e6feb95 | 599 | #if wxUSE_STATUSBAR |
b01a88e0 VZ |
600 | wxStatusBar *theStatusBar = GetStatusBar(); |
601 | ||
602 | if ((m_fsStyle & wxFULLSCREEN_NOSTATUSBAR) && theStatusBar) | |
a2327a9f | 603 | { |
b01a88e0 VZ |
604 | theStatusBar->Show(true); |
605 | PositionStatusBar(); | |
a2327a9f | 606 | } |
1e6feb95 | 607 | #endif // wxUSE_STATUSBAR |
a2327a9f | 608 | } |
b01a88e0 | 609 | #endif // !defined(__WXMICROWIN__) && !defined(__WXWINCE__) |
f6bcfd97 | 610 | |
085ad686 | 611 | return wxFrameBase::ShowFullScreen(show, style); |
2bda0e17 KB |
612 | } |
613 | ||
7c0ea335 VZ |
614 | // ---------------------------------------------------------------------------- |
615 | // tool/status bar stuff | |
616 | // ---------------------------------------------------------------------------- | |
617 | ||
d427503c | 618 | #if wxUSE_TOOLBAR |
7c0ea335 | 619 | |
0d53fc34 | 620 | wxToolBar* wxFrame::CreateToolBar(long style, wxWindowID id, const wxString& name) |
81d66cf3 | 621 | { |
3d487566 | 622 | #if defined(WINCE_WITHOUT_COMMANDBAR) |
39d2f9a7 JS |
623 | // We may already have a toolbar from calling SetMenuBar. |
624 | if (GetToolBar()) | |
625 | return GetToolBar(); | |
626 | #endif | |
7c0ea335 | 627 | if ( wxFrameBase::CreateToolBar(style, id, name) ) |
81d66cf3 | 628 | { |
81d66cf3 | 629 | PositionToolBar(); |
81d66cf3 | 630 | } |
81d66cf3 | 631 | |
7c0ea335 | 632 | return m_frameToolBar; |
81d66cf3 JS |
633 | } |
634 | ||
0d53fc34 | 635 | void wxFrame::PositionToolBar() |
81d66cf3 | 636 | { |
8898842f VZ |
637 | // TODO: we want to do something different in WinCE, because the toolbar |
638 | // should be associated with the commandbar, instead of being | |
639 | // independent window. | |
640 | #if !defined(WINCE_WITHOUT_COMMANDBAR) | |
d4597e13 VZ |
641 | wxToolBar *toolbar = GetToolBar(); |
642 | if ( toolbar && toolbar->IsShown() ) | |
643 | { | |
644 | // don't call our (or even wxTopLevelWindow) version because we want | |
645 | // the real (full) client area size, not excluding the tool/status bar | |
646 | int width, height; | |
647 | wxWindow::DoGetClientSize(&width, &height); | |
81d66cf3 | 648 | |
7c0ea335 | 649 | #if wxUSE_STATUSBAR |
d4597e13 VZ |
650 | wxStatusBar *statbar = GetStatusBar(); |
651 | if ( statbar && statbar->IsShown() ) | |
652 | { | |
653 | height -= statbar->GetClientSize().y; | |
654 | } | |
7c0ea335 | 655 | #endif // wxUSE_STATUSBAR |
3882e746 VZ |
656 | |
657 | int tx, ty, tw, th; | |
658 | toolbar->GetPosition( &tx, &ty ); | |
659 | toolbar->GetSize( &tw, &th ); | |
660 | ||
dd639a4f | 661 | int x, y; |
3882e746 VZ |
662 | if ( toolbar->HasFlag(wxTB_BOTTOM) ) |
663 | { | |
664 | x = 0; | |
665 | y = height - th; | |
666 | } | |
667 | else if ( toolbar->HasFlag(wxTB_RIGHT) ) | |
668 | { | |
669 | x = width - tw; | |
670 | y = 0; | |
671 | } | |
672 | else // left or top | |
673 | { | |
674 | x = 0; | |
675 | y = 0; | |
676 | } | |
677 | ||
3d487566 | 678 | #if defined(WINCE_WITH_COMMANDBAR) |
fb8a56b7 WS |
679 | // We're using a commandbar - so we have to allow for it. |
680 | if (GetMenuBar() && GetMenuBar()->GetCommandBar()) | |
681 | { | |
682 | RECT rect; | |
683 | ::GetWindowRect((HWND) GetMenuBar()->GetCommandBar(), &rect); | |
684 | y = rect.bottom - rect.top; | |
685 | } | |
3882e746 VZ |
686 | #endif // WINCE_WITH_COMMANDBAR |
687 | ||
688 | if ( toolbar->HasFlag(wxTB_BOTTOM) ) | |
689 | { | |
690 | if ( ty < 0 && ( -ty == th ) ) | |
691 | ty = height - th; | |
692 | if ( tx < 0 && (-tx == tw ) ) | |
693 | tx = 0; | |
694 | } | |
695 | else if ( toolbar->HasFlag(wxTB_RIGHT) ) | |
7a976304 VZ |
696 | { |
697 | if( ty < 0 && ( -ty == th ) ) | |
698 | ty = 0; | |
699 | if( tx < 0 && ( -tx == tw ) ) | |
700 | tx = width - tw; | |
701 | } | |
3882e746 VZ |
702 | else // left or top |
703 | { | |
704 | if (ty < 0 && (-ty == th)) | |
705 | ty = 0; | |
706 | if (tx < 0 && (-tx == tw)) | |
707 | tx = 0; | |
708 | } | |
cbe874bd | 709 | |
229de929 JS |
710 | int desiredW = tw; |
711 | int desiredH = th; | |
81d66cf3 | 712 | |
7a976304 | 713 | if ( toolbar->IsVertical() ) |
81d66cf3 | 714 | { |
229de929 | 715 | desiredH = height; |
81d66cf3 JS |
716 | } |
717 | else | |
718 | { | |
229de929 | 719 | desiredW = width; |
cbe874bd | 720 | } |
7c0ea335 | 721 | |
d4597e13 VZ |
722 | // use the 'real' MSW position here, don't offset relativly to the |
723 | // client area origin | |
229de929 JS |
724 | |
725 | // Optimise such that we don't have to always resize the toolbar | |
cbe874bd | 726 | // when the frame changes, otherwise we'll get a lot of flicker. |
5cb598ae WS |
727 | bool heightChanging wxDUMMY_INITIALIZE(true); |
728 | bool widthChanging wxDUMMY_INITIALIZE(true); | |
cbe874bd | 729 | |
7a976304 | 730 | if ( toolbar->IsVertical() ) |
229de929 JS |
731 | { |
732 | // It's OK if the current height is greater than what can be shown. | |
733 | heightChanging = (desiredH > th) ; | |
734 | widthChanging = (desiredW != tw) ; | |
cbe874bd WS |
735 | |
736 | // The next time around, we may not have to set the size | |
229de929 JS |
737 | if (heightChanging) |
738 | desiredH = desiredH + 200; | |
739 | } | |
740 | else | |
741 | { | |
742 | // It's OK if the current width is greater than what can be shown. | |
743 | widthChanging = (desiredW > tw) ; | |
744 | heightChanging = (desiredH != th) ; | |
745 | ||
cbe874bd | 746 | // The next time around, we may not have to set the size |
229de929 JS |
747 | if (widthChanging) |
748 | desiredW = desiredW + 200; | |
749 | } | |
cbe874bd | 750 | |
229de929 | 751 | if (tx != 0 || ty != 0 || widthChanging || heightChanging) |
45f27284 | 752 | toolbar->SetSize(x, y, desiredW, desiredH, wxSIZE_NO_ADJUSTMENTS); |
cbe874bd | 753 | |
81d66cf3 | 754 | } |
8898842f | 755 | #endif // !WINCE_WITH_COMMANDBAR |
81d66cf3 | 756 | } |
d4597e13 | 757 | |
d427503c | 758 | #endif // wxUSE_TOOLBAR |
d2aef312 | 759 | |
7c0ea335 VZ |
760 | // ---------------------------------------------------------------------------- |
761 | // frame state (iconized/maximized/...) | |
762 | // ---------------------------------------------------------------------------- | |
763 | ||
a23fd0e1 VZ |
764 | // propagate our state change to all child frames: this allows us to emulate X |
765 | // Windows behaviour where child frames float independently of the parent one | |
766 | // on the desktop, but are iconized/restored with it | |
0d53fc34 | 767 | void wxFrame::IconizeChildFrames(bool bIconize) |
d2aef312 | 768 | { |
4bc0f25e VZ |
769 | m_iconized = bIconize; |
770 | ||
222ed1d6 | 771 | for ( wxWindowList::compatibility_iterator node = GetChildren().GetFirst(); |
a23fd0e1 VZ |
772 | node; |
773 | node = node->GetNext() ) | |
774 | { | |
775 | wxWindow *win = node->GetData(); | |
776 | ||
3ca6a5f0 BP |
777 | // iconizing the frames with this style under Win95 shell puts them at |
778 | // the bottom of the screen (as the MDI children) instead of making | |
779 | // them appear in the taskbar because they are, by virtue of this | |
780 | // style, not managed by the taskbar - instead leave Windows take care | |
781 | // of them | |
3ca6a5f0 BP |
782 | if ( win->GetWindowStyle() & wxFRAME_TOOL_WINDOW ) |
783 | continue; | |
3ca6a5f0 | 784 | |
3f7bc32b VZ |
785 | // the child MDI frames are a special case and should not be touched by |
786 | // the parent frame - instead, they are managed by the user | |
2e9f62da | 787 | wxFrame *frame = wxDynamicCast(win, wxFrame); |
1e6feb95 VZ |
788 | if ( frame |
789 | #if wxUSE_MDI_ARCHITECTURE | |
4ab2824c | 790 | && !frame->IsMDIChild() |
1e6feb95 VZ |
791 | #endif // wxUSE_MDI_ARCHITECTURE |
792 | ) | |
a23fd0e1 | 793 | { |
9327c3aa VZ |
794 | // we don't want to restore the child frames which had been |
795 | // iconized even before we were iconized, so save the child frame | |
796 | // status when iconizing the parent frame and check it when | |
797 | // restoring it | |
798 | if ( bIconize ) | |
799 | { | |
9c72ebec | 800 | frame->m_wasMinimized = frame->IsIconized(); |
9327c3aa VZ |
801 | } |
802 | ||
9c72ebec VZ |
803 | // note that we shouldn't touch the hidden frames neither because |
804 | // iconizing/restoring them would show them as a side effect | |
805 | if ( !frame->m_wasMinimized && frame->IsShown() ) | |
9327c3aa | 806 | frame->Iconize(bIconize); |
a23fd0e1 | 807 | } |
d2aef312 | 808 | } |
d2aef312 VZ |
809 | } |
810 | ||
0d53fc34 | 811 | WXHICON wxFrame::GetDefaultIcon() const |
82c9f85c | 812 | { |
94826170 VZ |
813 | // we don't have any standard icons (any more) |
814 | return (WXHICON)0; | |
82c9f85c VZ |
815 | } |
816 | ||
a23fd0e1 | 817 | // =========================================================================== |
42e69d6b | 818 | // message processing |
a23fd0e1 VZ |
819 | // =========================================================================== |
820 | ||
42e69d6b VZ |
821 | // --------------------------------------------------------------------------- |
822 | // preprocessing | |
823 | // --------------------------------------------------------------------------- | |
824 | ||
1ac76609 | 825 | bool wxFrame::MSWDoTranslateMessage(wxFrame *frame, WXMSG *pMsg) |
42e69d6b VZ |
826 | { |
827 | if ( wxWindow::MSWTranslateMessage(pMsg) ) | |
cbe874bd | 828 | return true; |
42e69d6b | 829 | |
1e6feb95 | 830 | #if wxUSE_MENUS && wxUSE_ACCEL && !defined(__WXUNIVERSAL__) |
7802da36 | 831 | // try the menu bar accelerators |
42e69d6b | 832 | wxMenuBar *menuBar = GetMenuBar(); |
7802da36 VZ |
833 | if ( menuBar && menuBar->GetAcceleratorTable()->Translate(frame, pMsg) ) |
834 | return true; | |
a1a1ca89 | 835 | #endif // wxUSE_MENUS && wxUSE_ACCEL |
42e69d6b | 836 | |
cbe874bd | 837 | return false; |
42e69d6b VZ |
838 | } |
839 | ||
840 | // --------------------------------------------------------------------------- | |
841 | // our private (non virtual) message handlers | |
842 | // --------------------------------------------------------------------------- | |
843 | ||
4bc0f25e | 844 | bool wxFrame::HandleSize(int WXUNUSED(x), int WXUNUSED(y), WXUINT id) |
42e69d6b | 845 | { |
4676948b | 846 | #if !defined(__WXMICROWIN__) && !defined(__WXWINCE__) |
42e69d6b VZ |
847 | switch ( id ) |
848 | { | |
4bc0f25e VZ |
849 | case SIZE_RESTORED: |
850 | case SIZE_MAXIMIZED: | |
42e69d6b VZ |
851 | // only do it it if we were iconized before, otherwise resizing the |
852 | // parent frame has a curious side effect of bringing it under it's | |
853 | // children | |
854 | if ( !m_iconized ) | |
855 | break; | |
856 | ||
857 | // restore all child frames too | |
cbe874bd | 858 | IconizeChildFrames(false); |
42e69d6b | 859 | |
cbe874bd | 860 | (void)SendIconizeEvent(false); |
42e69d6b VZ |
861 | break; |
862 | ||
4bc0f25e | 863 | case SIZE_MINIMIZED: |
42e69d6b | 864 | // iconize all child frames too |
cbe874bd | 865 | IconizeChildFrames(true); |
42e69d6b VZ |
866 | break; |
867 | } | |
276c8cfb WS |
868 | #else |
869 | wxUnusedVar(id); | |
4bc0f25e | 870 | #endif // !__WXWINCE__ |
42e69d6b VZ |
871 | |
872 | if ( !m_iconized ) | |
873 | { | |
1e6feb95 | 874 | #if wxUSE_STATUSBAR |
42e69d6b | 875 | PositionStatusBar(); |
1e6feb95 VZ |
876 | #endif // wxUSE_STATUSBAR |
877 | ||
878 | #if wxUSE_TOOLBAR | |
42e69d6b | 879 | PositionToolBar(); |
1e6feb95 | 880 | #endif // wxUSE_TOOLBAR |
42e69d6b | 881 | |
3d487566 | 882 | #if defined(WINCE_WITH_COMMANDBAR) |
fb8a56b7 WS |
883 | // Position the menu command bar |
884 | if (GetMenuBar() && GetMenuBar()->GetCommandBar()) | |
885 | { | |
886 | RECT rect; | |
887 | ::GetWindowRect((HWND) GetMenuBar()->GetCommandBar(), &rect); | |
888 | wxSize clientSz = GetClientSize(); | |
889 | ||
890 | if ( !::MoveWindow((HWND) GetMenuBar()->GetCommandBar(), 0, 0, clientSz.x, rect.bottom - rect.top, true ) ) | |
891 | { | |
892 | wxLogLastError(wxT("MoveWindow")); | |
893 | } | |
894 | ||
895 | } | |
4bc0f25e | 896 | #endif // WINCE_WITH_COMMANDBAR |
42e69d6b VZ |
897 | } |
898 | ||
4bc0f25e VZ |
899 | // call the base class version to generate the appropriate events |
900 | return false; | |
42e69d6b VZ |
901 | } |
902 | ||
660e7fda | 903 | bool wxFrame::HandleCommand(WXWORD id_, WXWORD cmd, WXHWND control) |
42e69d6b | 904 | { |
a6ac49b1 VZ |
905 | // we only need to handle the menu and accelerator commands from the items |
906 | // of our menu bar, base wxWindow class already handles the rest | |
907 | if ( !control && (cmd == 0 /* menu */ || cmd == 1 /* accel */) ) | |
42e69d6b | 908 | { |
1e6feb95 | 909 | #if wxUSE_MENUS_NATIVE |
a6ac49b1 | 910 | if ( !wxCurrentPopupMenu ) |
1e6feb95 | 911 | #endif // wxUSE_MENUS_NATIVE |
fb8a56b7 | 912 | { |
a6ac49b1 VZ |
913 | wxMenuBar * const mbar = GetMenuBar(); |
914 | if ( mbar ) | |
915 | { | |
916 | // sign extend to int from short before comparing with the | |
917 | // other int ids | |
918 | const int id = (signed short)id_; | |
fb8a56b7 | 919 | |
a6ac49b1 VZ |
920 | wxMenuItem * const mitem = mbar->FindItem(id); |
921 | if ( mitem ) | |
922 | return ProcessCommand(mitem); | |
923 | } | |
42e69d6b VZ |
924 | } |
925 | } | |
926 | ||
a6ac49b1 | 927 | return wxFrameBase::HandleCommand(id_, cmd, control);; |
42e69d6b VZ |
928 | } |
929 | ||
a8ff046b VZ |
930 | #if wxUSE_MENUS |
931 | ||
0d53fc34 | 932 | bool wxFrame::HandleMenuSelect(WXWORD nItem, WXWORD flags, WXHMENU hMenu) |
a23fd0e1 VZ |
933 | { |
934 | int item; | |
c219cecc | 935 | if ( flags == 0xFFFF && hMenu == 0 ) |
a23fd0e1 | 936 | { |
c219cecc | 937 | // menu was removed from screen |
a23fd0e1 VZ |
938 | item = -1; |
939 | } | |
04ef50df | 940 | #ifndef __WXMICROWIN__ |
c219cecc | 941 | else if ( !(flags & MF_POPUP) && !(flags & MF_SEPARATOR) ) |
a23fd0e1 VZ |
942 | { |
943 | item = nItem; | |
944 | } | |
04ef50df | 945 | #endif |
a23fd0e1 VZ |
946 | else |
947 | { | |
c219cecc | 948 | // don't give hints for separators (doesn't make sense) nor for the |
f6bcfd97 BP |
949 | // items opening popup menus (they don't have them anyhow) but do clear |
950 | // the status line - otherwise, we would be left with the help message | |
951 | // for the previous item which doesn't apply any more | |
6d99eb3e | 952 | DoGiveHelp(wxEmptyString, true); |
f6bcfd97 | 953 | |
cbe874bd | 954 | return false; |
a23fd0e1 VZ |
955 | } |
956 | ||
957 | wxMenuEvent event(wxEVT_MENU_HIGHLIGHT, item); | |
ccef86c7 VZ |
958 | event.SetEventObject(this); |
959 | ||
937013e0 | 960 | return HandleWindowEvent(event); |
ccef86c7 VZ |
961 | } |
962 | ||
963 | bool wxFrame::HandleMenuLoop(const wxEventType& evtType, WXWORD isPopup) | |
964 | { | |
965 | // we don't have the menu id here, so we use the id to specify if the event | |
966 | // was from a popup menu or a normal one | |
967 | wxMenuEvent event(evtType, isPopup ? -1 : 0); | |
968 | event.SetEventObject(this); | |
a23fd0e1 | 969 | |
937013e0 | 970 | return HandleWindowEvent(event); |
a23fd0e1 VZ |
971 | } |
972 | ||
a8ff046b VZ |
973 | bool wxFrame::HandleInitMenuPopup(WXHMENU hMenu) |
974 | { | |
975 | wxMenu* menu = NULL; | |
976 | if (GetMenuBar()) | |
977 | { | |
978 | int nCount = GetMenuBar()->GetMenuCount(); | |
979 | for (int n = 0; n < nCount; n++) | |
980 | { | |
981 | if (GetMenuBar()->GetMenu(n)->GetHMenu() == hMenu) | |
982 | { | |
983 | menu = GetMenuBar()->GetMenu(n); | |
984 | break; | |
985 | } | |
986 | } | |
987 | } | |
988 | ||
989 | wxMenuEvent event(wxEVT_MENU_OPEN, 0, menu); | |
990 | event.SetEventObject(this); | |
991 | ||
937013e0 | 992 | return HandleWindowEvent(event); |
a8ff046b VZ |
993 | } |
994 | ||
995 | #endif // wxUSE_MENUS | |
996 | ||
a23fd0e1 | 997 | // --------------------------------------------------------------------------- |
0d53fc34 | 998 | // the window proc for wxFrame |
a23fd0e1 VZ |
999 | // --------------------------------------------------------------------------- |
1000 | ||
c140b7e7 | 1001 | WXLRESULT wxFrame::MSWWindowProc(WXUINT message, WXWPARAM wParam, WXLPARAM lParam) |
a23fd0e1 | 1002 | { |
c140b7e7 | 1003 | WXLRESULT rc = 0; |
cbe874bd | 1004 | bool processed = false; |
a23fd0e1 VZ |
1005 | |
1006 | switch ( message ) | |
1007 | { | |
42e69d6b VZ |
1008 | case WM_CLOSE: |
1009 | // if we can't close, tell the system that we processed the | |
1010 | // message - otherwise it would close us | |
1011 | processed = !Close(); | |
1012 | break; | |
1013 | ||
ccef86c7 VZ |
1014 | case WM_SIZE: |
1015 | processed = HandleSize(LOWORD(lParam), HIWORD(lParam), wParam); | |
1016 | break; | |
1017 | ||
42e69d6b VZ |
1018 | case WM_COMMAND: |
1019 | { | |
1020 | WORD id, cmd; | |
1021 | WXHWND hwnd; | |
1022 | UnpackCommand((WXWPARAM)wParam, (WXLPARAM)lParam, | |
1023 | &id, &hwnd, &cmd); | |
1024 | ||
a6ac49b1 VZ |
1025 | HandleCommand(id, cmd, (WXHWND)hwnd); |
1026 | ||
1027 | // don't pass WM_COMMAND to the base class whether we processed | |
1028 | // it or not because we did generate an event for it (our | |
1029 | // HandleCommand() calls the base class version) and we must | |
1030 | // not do it again or the handlers which skip the event would | |
1031 | // be called twice | |
1032 | processed = true; | |
42e69d6b VZ |
1033 | } |
1034 | break; | |
1035 | ||
a8ff046b VZ |
1036 | #if !defined(__WXMICROWIN__) && !defined(__WXWINCE__) |
1037 | #if wxUSE_MENUS | |
92f1a59c JS |
1038 | case WM_INITMENUPOPUP: |
1039 | processed = HandleInitMenuPopup((WXHMENU) wParam); | |
1040 | break; | |
1041 | ||
a23fd0e1 VZ |
1042 | case WM_MENUSELECT: |
1043 | { | |
42e69d6b VZ |
1044 | WXWORD item, flags; |
1045 | WXHMENU hmenu; | |
1046 | UnpackMenuSelect(wParam, lParam, &item, &flags, &hmenu); | |
1047 | ||
1048 | processed = HandleMenuSelect(item, flags, hmenu); | |
a23fd0e1 VZ |
1049 | } |
1050 | break; | |
bc92cdf9 | 1051 | |
ccef86c7 | 1052 | case WM_EXITMENULOOP: |
373a5fb3 | 1053 | processed = HandleMenuLoop(wxEVT_MENU_CLOSE, (WXWORD)wParam); |
ccef86c7 | 1054 | break; |
a8ff046b | 1055 | #endif // wxUSE_MENUS |
ccef86c7 | 1056 | |
42e69d6b VZ |
1057 | case WM_QUERYDRAGICON: |
1058 | { | |
f618020a MB |
1059 | const wxIcon& icon = GetIcon(); |
1060 | HICON hIcon = icon.Ok() ? GetHiconOf(icon) | |
1061 | : (HICON)GetDefaultIcon(); | |
dca0f651 | 1062 | rc = (WXLRESULT)hIcon; |
42e69d6b VZ |
1063 | processed = rc != 0; |
1064 | } | |
1065 | break; | |
ccef86c7 | 1066 | #endif // !__WXMICROWIN__ |
a23fd0e1 VZ |
1067 | } |
1068 | ||
1069 | if ( !processed ) | |
7e25f59e | 1070 | rc = wxFrameBase::MSWWindowProc(message, wParam, lParam); |
a23fd0e1 VZ |
1071 | |
1072 | return rc; | |
1073 | } | |
21802234 | 1074 | |
a9928e9d JS |
1075 | // ---------------------------------------------------------------------------- |
1076 | // wxFrame size management: we exclude the areas taken by menu/status/toolbars | |
1077 | // from the client area, so the client area is what's really available for the | |
1078 | // frame contents | |
1079 | // ---------------------------------------------------------------------------- | |
1080 | ||
1081 | // get the origin of the client area in the client coordinates | |
1082 | wxPoint wxFrame::GetClientAreaOrigin() const | |
1083 | { | |
1084 | wxPoint pt = wxTopLevelWindow::GetClientAreaOrigin(); | |
1085 | ||
1086 | #if wxUSE_TOOLBAR && !defined(__WXUNIVERSAL__) && \ | |
1087 | (!defined(__WXWINCE__) || (_WIN32_WCE >= 400 && !defined(__POCKETPC__) && !defined(__SMARTPHONE__))) | |
3882e746 | 1088 | wxToolBar * const toolbar = GetToolBar(); |
a9928e9d JS |
1089 | if ( toolbar && toolbar->IsShown() ) |
1090 | { | |
3882e746 | 1091 | const wxSize sizeTB = toolbar->GetSize(); |
a9928e9d | 1092 | |
3882e746 | 1093 | if ( toolbar->HasFlag(wxTB_TOP) ) |
a9928e9d | 1094 | { |
3882e746 | 1095 | pt.y += sizeTB.y; |
a9928e9d | 1096 | } |
3882e746 | 1097 | else if ( toolbar->HasFlag(wxTB_LEFT) ) |
a9928e9d | 1098 | { |
3882e746 | 1099 | pt.x += sizeTB.x; |
a9928e9d JS |
1100 | } |
1101 | } | |
1102 | #endif // wxUSE_TOOLBAR | |
1103 | ||
3d487566 | 1104 | #if defined(WINCE_WITH_COMMANDBAR) |
fb8a56b7 WS |
1105 | if (GetMenuBar() && GetMenuBar()->GetCommandBar()) |
1106 | { | |
1107 | RECT rect; | |
1108 | ::GetWindowRect((HWND) GetMenuBar()->GetCommandBar(), &rect); | |
1109 | pt.y += (rect.bottom - rect.top); | |
1110 | } | |
a9928e9d JS |
1111 | #endif |
1112 | ||
1113 | return pt; | |
1114 | } |