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