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