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