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