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