]> git.saurik.com Git - wxWidgets.git/blobdiff - samples/mdi/mdi.cpp
Fix broken and missing DataView interface items for Phoenix
[wxWidgets.git] / samples / mdi / mdi.cpp
index f923e543dab9e18682bcc5e6f9d566b8a76d3153..e68364cf01216c0a07ed7fa32ffb912aa0a3b1d8 100644 (file)
@@ -7,7 +7,7 @@
 // RCS-ID:      $Id$
 // Copyright:   (c) 1997 Julian Smart
 //              (c) 2008 Vadim Zeitlin
 // RCS-ID:      $Id$
 // Copyright:   (c) 1997 Julian Smart
 //              (c) 2008 Vadim Zeitlin
-// Licence:     wxWindows license
+// Licence:     wxWindows licence
 /////////////////////////////////////////////////////////////////////////////
 
 // ===========================================================================
 /////////////////////////////////////////////////////////////////////////////
 
 // ===========================================================================
@@ -32,7 +32,7 @@
 
 #include "wx/toolbar.h"
 
 
 #include "wx/toolbar.h"
 
-#if !defined(__WXMSW__)
+#ifndef wxHAS_IMAGES_IN_RESOURCES
     #include "../sample.xpm"
     #include "chart.xpm"
 #endif
     #include "../sample.xpm"
     #include "chart.xpm"
 #endif
@@ -66,8 +66,11 @@ IMPLEMENT_APP(MyApp)
 BEGIN_EVENT_TABLE(MyFrame, wxMDIParentFrame)
     EVT_MENU(wxID_ABOUT, MyFrame::OnAbout)
     EVT_MENU(wxID_NEW, MyFrame::OnNewWindow)
 BEGIN_EVENT_TABLE(MyFrame, wxMDIParentFrame)
     EVT_MENU(wxID_ABOUT, MyFrame::OnAbout)
     EVT_MENU(wxID_NEW, MyFrame::OnNewWindow)
+    EVT_MENU(MDI_FULLSCREEN, MyFrame::OnFullScreen)
     EVT_MENU(wxID_EXIT, MyFrame::OnQuit)
 
     EVT_MENU(wxID_EXIT, MyFrame::OnQuit)
 
+    EVT_MENU(wxID_CLOSE_ALL, MyFrame::OnCloseAll)
+
     EVT_CLOSE(MyFrame::OnClose)
 END_EVENT_TABLE()
 
     EVT_CLOSE(MyFrame::OnClose)
 END_EVENT_TABLE()
 
@@ -96,6 +99,10 @@ BEGIN_EVENT_TABLE(MyCanvas, wxScrolledWindow)
     EVT_MOUSE_EVENTS(MyCanvas::OnEvent)
 END_EVENT_TABLE()
 
     EVT_MOUSE_EVENTS(MyCanvas::OnEvent)
 END_EVENT_TABLE()
 
+BEGIN_EVENT_TABLE(MyChild::EventHandler, wxEvtHandler)
+    EVT_MENU(MDI_REFRESH, MyChild::EventHandler::OnRefresh)
+END_EVENT_TABLE()
+
 // ===========================================================================
 // implementation
 // ===========================================================================
 // ===========================================================================
 // implementation
 // ===========================================================================
@@ -132,28 +139,36 @@ MyFrame::MyFrame()
 
     // Make a menubar
 #if wxUSE_MENUS
 
     // Make a menubar
 #if wxUSE_MENUS
-    wxMenu *file_menu = new wxMenu;
-
-    file_menu->Append(wxID_NEW, "&New window\tCtrl-N", "Create a new child window");
-    file_menu->Append(wxID_EXIT, "&Exit\tAlt-X", "Quit the program");
-
-    wxMenu *help_menu = new wxMenu;
-    help_menu->Append(wxID_ABOUT, "&About\tF1");
-
-    wxMenuBar *menu_bar = new wxMenuBar;
-
-    menu_bar->Append(file_menu, "&File");
-    menu_bar->Append(help_menu, "&Help");
-
     // Associate the menu bar with the frame
     // Associate the menu bar with the frame
-    SetMenuBar(menu_bar);
+    SetMenuBar(CreateMainMenubar());
 
 
-#if 0
-    // Experimental: change the window menu
-    wxMenu* windowMenu = new wxMenu;
-    windowMenu->Append(5000, "My menu item!");
-    frame->SetWindowMenu(windowMenu);
-#endif
+
+    // This shows that the standard window menu may be customized:
+    wxMenu * const windowMenu = GetWindowMenu();
+    if ( windowMenu )
+    {
+        // we can change the labels of standard items (which also means we can
+        // set up accelerators for them as they're part of the label)
+        windowMenu->SetLabel(wxID_MDI_WINDOW_TILE_HORZ,
+                             "&Tile horizontally\tCtrl-Shift-H");
+        windowMenu->SetLabel(wxID_MDI_WINDOW_TILE_VERT,
+                             "&Tile vertically\tCtrl-Shift-V");
+
+        // we can also change the help string
+        windowMenu->SetHelpString(wxID_MDI_WINDOW_CASCADE,
+                                  "Arrange windows in cascade");
+
+        // we can remove some items
+        windowMenu->Delete(wxID_MDI_WINDOW_ARRANGE_ICONS);
+
+        // and we can add completely custom commands -- but then we must handle
+        // them ourselves, see OnCloseAll()
+        windowMenu->AppendSeparator();
+        windowMenu->Append(wxID_CLOSE_ALL, "&Close all windows\tCtrl-Shift-C",
+                           "Close all open windows");
+
+        SetWindowMenu(windowMenu);
+    }
 #endif // wxUSE_MENUS
 
 #if wxUSE_STATUSBAR
 #endif // wxUSE_MENUS
 
 #if wxUSE_STATUSBAR
@@ -191,6 +206,27 @@ MyFrame::~MyFrame()
     Disconnect(wxEVT_SIZE, wxSizeEventHandler(MyFrame::OnSize));
 }
 
     Disconnect(wxEVT_SIZE, wxSizeEventHandler(MyFrame::OnSize));
 }
 
+#if wxUSE_MENUS
+/* static */
+wxMenuBar *MyFrame::CreateMainMenubar()
+{
+    wxMenu *menuFile = new wxMenu;
+
+    menuFile->Append(wxID_NEW, "&New window\tCtrl-N", "Create a new child window");
+    menuFile->AppendCheckItem(MDI_FULLSCREEN, "Show &full screen\tCtrl-F");
+    menuFile->Append(wxID_EXIT, "&Exit\tAlt-X", "Quit the program");
+
+    wxMenu *menuHelp = new wxMenu;
+    menuHelp->Append(wxID_ABOUT, "&About\tF1");
+
+    wxMenuBar *mbar = new wxMenuBar;
+    mbar->Append(menuFile, "&File");
+    mbar->Append(menuHelp, "&Help");
+
+    return mbar;
+}
+#endif // wxUSE_MENUS
+
 void MyFrame::OnClose(wxCloseEvent& event)
 {
     unsigned numChildren = MyChild::GetChildrenCount();
 void MyFrame::OnClose(wxCloseEvent& event)
 {
     unsigned numChildren = MyChild::GetChildrenCount();
@@ -229,13 +265,23 @@ void MyFrame::OnNewWindow(wxCommandEvent& WXUNUSED(event) )
     subframe->Show(true);
 }
 
     subframe->Show(true);
 }
 
-void MyFrame::OnSize(wxSizeEvent&
-                                  #ifdef __WXUNIVERSAL__
-                                  event
-                                  #else
-                                  WXUNUSED(event)
-                                  #endif
-                                  )
+void MyFrame::OnFullScreen(wxCommandEvent& event)
+{
+    ShowFullScreen(event.IsChecked());
+}
+
+void MyFrame::OnCloseAll(wxCommandEvent& WXUNUSED(event))
+{
+    for ( wxWindowList::const_iterator i = GetChildren().begin();
+          i != GetChildren().end();
+          ++i )
+    {
+        if ( wxDynamicCast(*i, wxMDIChildFrame) )
+            (*i)->Close();
+    }
+}
+
+void MyFrame::OnSize(wxSizeEvent& event)
 {
     int w, h;
     GetClientSize(&w, &h);
 {
     int w, h;
     GetClientSize(&w, &h);
@@ -248,6 +294,8 @@ void MyFrame::OnSize(wxSizeEvent&
     // be done.
 #ifdef __WXUNIVERSAL__
     event.Skip();
     // be done.
 #ifdef __WXUNIVERSAL__
     event.Skip();
+#else
+    wxUnusedVar(event);
 #endif
 }
 
 #endif
 }
 
@@ -375,52 +423,48 @@ MyChild::MyChild(wxMDIParentFrame *parent)
 
     const bool canBeResized = !IsAlwaysMaximized();
 
 
     const bool canBeResized = !IsAlwaysMaximized();
 
-    // create our menubar: it will be shown instead of the main frame one when
+    // create our menu bar: it will be shown instead of the main frame one when
     // we're active
 #if wxUSE_MENUS
     // we're active
 #if wxUSE_MENUS
-    // Make a menubar
-    wxMenu *file_menu = new wxMenu;
-
-    file_menu->Append(wxID_NEW, "&New window\tCtrl-N");
-    file_menu->Append(wxID_CLOSE, "&Close child\tCtrl-W", "Close this window");
-    file_menu->Append(wxID_EXIT, "&Exit\tAlt-X", "Quit the program");
+    wxMenuBar *mbar = MyFrame::CreateMainMenubar();
+    mbar->GetMenu(0)->Insert(1, wxID_CLOSE, "&Close child\tCtrl-W",
+                             "Close this window");
 
 
-    wxMenu *option_menu = new wxMenu;
+    wxMenu *menuChild = new wxMenu;
 
 
-    option_menu->Append(MDI_REFRESH, "&Refresh picture");
-    option_menu->Append(MDI_CHANGE_TITLE, "Change &title...\tCtrl-T");
+    menuChild->Append(MDI_REFRESH, "&Refresh picture");
+    menuChild->Append(MDI_CHANGE_TITLE, "Change &title...\tCtrl-T");
     if ( canBeResized )
     {
     if ( canBeResized )
     {
-        option_menu->AppendSeparator();
-        option_menu->Append(MDI_CHANGE_POSITION, "Move frame\tCtrl-M");
-        option_menu->Append(MDI_CHANGE_SIZE, "Resize frame\tCtrl-S");
+        menuChild->AppendSeparator();
+        menuChild->Append(MDI_CHANGE_POSITION, "Move frame\tCtrl-M");
+        menuChild->Append(MDI_CHANGE_SIZE, "Resize frame\tCtrl-S");
     }
 #if wxUSE_CLIPBOARD
     }
 #if wxUSE_CLIPBOARD
-    option_menu->AppendSeparator();
-    option_menu->Append(wxID_PASTE, "Copy text from clipboard\tCtrl-V");
+    menuChild->AppendSeparator();
+    menuChild->Append(wxID_PASTE, "Copy text from clipboard\tCtrl-V");
 #endif // wxUSE_CLIPBOARD
 
 #endif // wxUSE_CLIPBOARD
 
-    wxMenu *help_menu = new wxMenu;
-    help_menu->Append(wxID_ABOUT, "&About");
-
-    wxMenuBar *menu_bar = new wxMenuBar;
-
-    menu_bar->Append(file_menu, "&File");
-    menu_bar->Append(option_menu, "&Child");
-    menu_bar->Append(help_menu, "&Help");
+    mbar->Insert(1, menuChild, "&Child");
 
     // Associate the menu bar with the frame
 
     // Associate the menu bar with the frame
-    SetMenuBar(menu_bar);
+    SetMenuBar(mbar);
 #endif // wxUSE_MENUS
 
     // this should work for MDI frames as well as for normal ones, provided
     // they can be resized at all
     if ( canBeResized )
         SetSizeHints(100, 100);
 #endif // wxUSE_MENUS
 
     // this should work for MDI frames as well as for normal ones, provided
     // they can be resized at all
     if ( canBeResized )
         SetSizeHints(100, 100);
+
+    // test that event handlers pushed on top of MDI children do work (this
+    // used to be broken, see #11225)
+    PushEventHandler(new EventHandler(ms_numChildren));
 }
 
 MyChild::~MyChild()
 {
 }
 
 MyChild::~MyChild()
 {
+    PopEventHandler(true);
+
     ms_numChildren--;
 }
 
     ms_numChildren--;
 }