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