1998-05-20 10:01:55 -04:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Name: mdi.cpp
|
|
|
|
// Purpose: MDI sample
|
|
|
|
// Author: Julian Smart
|
2008-11-03 21:46:19 -05:00
|
|
|
// Modified by: 2008-10-31 Vadim Zeitlin: big clean up
|
1998-05-20 10:01:55 -04:00
|
|
|
// Created: 04/01/98
|
2008-11-03 21:46:19 -05:00
|
|
|
// Copyright: (c) 1997 Julian Smart
|
|
|
|
// (c) 2008 Vadim Zeitlin
|
2010-07-13 09:29:13 -04:00
|
|
|
// Licence: wxWindows licence
|
1998-05-20 10:01:55 -04:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
1999-05-23 19:45:47 -04:00
|
|
|
// ===========================================================================
|
|
|
|
// declarations
|
|
|
|
// ===========================================================================
|
|
|
|
|
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
// headers
|
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
1998-05-20 10:01:55 -04:00
|
|
|
// For compilers that support precompilation, includes "wx/wx.h".
|
|
|
|
#include "wx/wxprec.h"
|
|
|
|
|
|
|
|
|
|
|
|
#ifndef WX_PRECOMP
|
1999-05-23 19:45:47 -04:00
|
|
|
#include "wx/wx.h"
|
|
|
|
#include "wx/mdi.h"
|
1998-05-20 10:01:55 -04:00
|
|
|
#endif
|
|
|
|
|
2002-01-19 09:50:37 -05:00
|
|
|
#include "wx/toolbar.h"
|
1998-05-20 10:01:55 -04:00
|
|
|
|
2012-03-03 19:28:58 -05:00
|
|
|
#ifndef wxHAS_IMAGES_IN_RESOURCES
|
2006-11-17 19:08:27 -05:00
|
|
|
#include "../sample.xpm"
|
|
|
|
#include "chart.xpm"
|
1998-07-22 18:13:31 -04:00
|
|
|
#endif
|
|
|
|
|
2002-06-12 07:56:01 -04:00
|
|
|
#include "bitmaps/new.xpm"
|
|
|
|
#include "bitmaps/open.xpm"
|
|
|
|
#include "bitmaps/save.xpm"
|
|
|
|
#include "bitmaps/copy.xpm"
|
|
|
|
#include "bitmaps/cut.xpm"
|
|
|
|
#include "bitmaps/paste.xpm"
|
|
|
|
#include "bitmaps/print.xpm"
|
|
|
|
#include "bitmaps/help.xpm"
|
|
|
|
|
2008-11-03 21:46:19 -05:00
|
|
|
// replace this 0 with 1 to build the sample using the generic MDI classes (you
|
|
|
|
// may also need to add src/generic/mdig.cpp to the build)
|
|
|
|
#if 0
|
|
|
|
#include "wx/generic/mdig.h"
|
|
|
|
#define wxMDIParentFrame wxGenericMDIParentFrame
|
|
|
|
#define wxMDIChildFrame wxGenericMDIChildFrame
|
|
|
|
#define wxMDIClientWindow wxGenericMDIClientWindow
|
|
|
|
#endif
|
2002-06-12 07:56:01 -04:00
|
|
|
|
1998-05-20 10:01:55 -04:00
|
|
|
#include "mdi.h"
|
|
|
|
|
2015-04-23 07:49:01 -04:00
|
|
|
wxIMPLEMENT_APP(MyApp);
|
1999-05-23 19:45:47 -04:00
|
|
|
|
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
// event tables
|
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
2014-03-30 03:07:55 -04:00
|
|
|
wxBEGIN_EVENT_TABLE(MyFrame, wxMDIParentFrame)
|
2008-11-03 21:46:19 -05:00
|
|
|
EVT_MENU(wxID_ABOUT, MyFrame::OnAbout)
|
|
|
|
EVT_MENU(wxID_NEW, MyFrame::OnNewWindow)
|
2009-01-26 18:17:09 -05:00
|
|
|
EVT_MENU(MDI_FULLSCREEN, MyFrame::OnFullScreen)
|
2008-11-03 21:46:19 -05:00
|
|
|
EVT_MENU(wxID_EXIT, MyFrame::OnQuit)
|
1999-05-23 19:45:47 -04:00
|
|
|
|
2009-01-27 11:47:41 -05:00
|
|
|
EVT_MENU(wxID_CLOSE_ALL, MyFrame::OnCloseAll)
|
|
|
|
|
2014-11-10 20:02:31 -05:00
|
|
|
EVT_MENU_OPEN(MyFrame::OnMenuOpen)
|
2014-12-05 17:17:34 -05:00
|
|
|
EVT_MENU_HIGHLIGHT(wxID_ABOUT, MyFrame::OnMenuHighlight)
|
|
|
|
EVT_MENU_HIGHLIGHT(MDI_REFRESH, MyFrame::OnMenuHighlight)
|
2014-11-10 20:02:31 -05:00
|
|
|
EVT_MENU_CLOSE(MyFrame::OnMenuClose)
|
|
|
|
|
1999-05-23 19:45:47 -04:00
|
|
|
EVT_CLOSE(MyFrame::OnClose)
|
2014-03-30 03:07:55 -04:00
|
|
|
wxEND_EVENT_TABLE()
|
1999-05-23 19:45:47 -04:00
|
|
|
|
2008-11-03 21:46:19 -05:00
|
|
|
// Note that wxID_NEW and wxID_ABOUT commands get passed
|
1999-05-23 19:45:47 -04:00
|
|
|
// to the parent window for processing, so no need to
|
|
|
|
// duplicate event handlers here.
|
2014-03-30 03:07:55 -04:00
|
|
|
wxBEGIN_EVENT_TABLE(MyChild, wxMDIChildFrame)
|
2008-11-03 21:46:19 -05:00
|
|
|
EVT_MENU(wxID_CLOSE, MyChild::OnClose)
|
1999-05-23 19:45:47 -04:00
|
|
|
EVT_MENU(MDI_REFRESH, MyChild::OnRefresh)
|
2000-07-15 15:51:35 -04:00
|
|
|
EVT_MENU(MDI_CHANGE_TITLE, MyChild::OnChangeTitle)
|
2000-12-10 07:04:19 -05:00
|
|
|
EVT_MENU(MDI_CHANGE_POSITION, MyChild::OnChangePosition)
|
|
|
|
EVT_MENU(MDI_CHANGE_SIZE, MyChild::OnChangeSize)
|
|
|
|
|
2006-07-24 09:36:22 -04:00
|
|
|
#if wxUSE_CLIPBOARD
|
|
|
|
EVT_MENU(wxID_PASTE, MyChild::OnPaste)
|
|
|
|
EVT_UPDATE_UI(wxID_PASTE, MyChild::OnUpdatePaste)
|
|
|
|
#endif // wxUSE_CLIPBOARD
|
|
|
|
|
2000-12-10 07:04:19 -05:00
|
|
|
EVT_SIZE(MyChild::OnSize)
|
|
|
|
EVT_MOVE(MyChild::OnMove)
|
1999-05-23 19:45:47 -04:00
|
|
|
|
2014-11-10 20:02:31 -05:00
|
|
|
EVT_MENU_OPEN(MyChild::OnMenuOpen)
|
2014-12-05 17:17:34 -05:00
|
|
|
EVT_MENU_HIGHLIGHT(wxID_ABOUT, MyChild::OnMenuHighlight)
|
|
|
|
EVT_MENU_HIGHLIGHT(MDI_REFRESH, MyChild::OnMenuHighlight)
|
2014-11-10 20:02:31 -05:00
|
|
|
EVT_MENU_CLOSE(MyChild::OnMenuClose)
|
|
|
|
|
2008-11-03 21:46:19 -05:00
|
|
|
EVT_CLOSE(MyChild::OnCloseWindow)
|
2014-03-30 03:07:55 -04:00
|
|
|
wxEND_EVENT_TABLE()
|
1999-05-23 19:45:47 -04:00
|
|
|
|
2014-03-30 03:07:55 -04:00
|
|
|
wxBEGIN_EVENT_TABLE(MyCanvas, wxScrolledWindow)
|
2014-12-05 17:17:38 -05:00
|
|
|
EVT_CONTEXT_MENU(MyCanvas::OnMenu)
|
1999-05-23 19:45:47 -04:00
|
|
|
EVT_MOUSE_EVENTS(MyCanvas::OnEvent)
|
2014-12-05 17:17:38 -05:00
|
|
|
|
|
|
|
EVT_MENU_OPEN(MyCanvas::OnMenuOpen)
|
|
|
|
EVT_MENU_HIGHLIGHT(wxID_ABOUT, MyCanvas::OnMenuHighlight)
|
|
|
|
EVT_MENU_HIGHLIGHT(MDI_REFRESH, MyCanvas::OnMenuHighlight)
|
|
|
|
EVT_MENU_CLOSE(MyCanvas::OnMenuClose)
|
2016-01-30 15:33:38 -05:00
|
|
|
|
|
|
|
EVT_UPDATE_UI(MDI_DISABLED_FROM_CANVAS, MyCanvas::OnUpdateUIDisable)
|
2014-03-30 03:07:55 -04:00
|
|
|
wxEND_EVENT_TABLE()
|
1999-05-23 19:45:47 -04:00
|
|
|
|
2014-03-30 03:07:55 -04:00
|
|
|
wxBEGIN_EVENT_TABLE(MyChild::EventHandler, wxEvtHandler)
|
2010-05-09 10:55:33 -04:00
|
|
|
EVT_MENU(MDI_REFRESH, MyChild::EventHandler::OnRefresh)
|
2016-01-30 15:33:38 -05:00
|
|
|
|
|
|
|
EVT_UPDATE_UI(MDI_DISABLED_FROM_CHILD, MyChild::OnUpdateUIDisable)
|
2014-03-30 03:07:55 -04:00
|
|
|
wxEND_EVENT_TABLE()
|
2010-05-09 10:55:33 -04:00
|
|
|
|
1999-05-23 19:45:47 -04:00
|
|
|
// ===========================================================================
|
|
|
|
// implementation
|
|
|
|
// ===========================================================================
|
1998-05-20 10:01:55 -04:00
|
|
|
|
1999-05-23 19:45:47 -04:00
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
// MyApp
|
|
|
|
// ---------------------------------------------------------------------------
|
1998-05-20 10:01:55 -04:00
|
|
|
|
|
|
|
// Initialise this in OnInit, not statically
|
1999-05-23 19:45:47 -04:00
|
|
|
bool MyApp::OnInit()
|
1998-05-20 10:01:55 -04:00
|
|
|
{
|
2007-02-03 19:34:18 -05:00
|
|
|
if ( !wxApp::OnInit() )
|
|
|
|
return false;
|
|
|
|
|
1999-05-23 19:45:47 -04:00
|
|
|
// Create the main frame window
|
1998-05-20 10:01:55 -04:00
|
|
|
|
2008-11-03 21:46:19 -05:00
|
|
|
MyFrame *frame = new MyFrame;
|
1998-05-20 10:01:55 -04:00
|
|
|
|
2008-11-03 21:46:19 -05:00
|
|
|
frame->Show(true);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
// MyFrame
|
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
// Define my frame constructor
|
|
|
|
MyFrame::MyFrame()
|
|
|
|
: wxMDIParentFrame(NULL, wxID_ANY, "wxWidgets MDI Sample",
|
2014-11-10 20:02:31 -05:00
|
|
|
wxDefaultPosition, wxSize(500, 400)),
|
|
|
|
MenuEventLogger("parent", this)
|
2008-11-03 21:46:19 -05:00
|
|
|
{
|
|
|
|
SetIcon(wxICON(sample));
|
1998-05-20 10:01:55 -04:00
|
|
|
|
1999-05-23 19:45:47 -04:00
|
|
|
// Make a menubar
|
2008-11-03 21:46:19 -05:00
|
|
|
#if wxUSE_MENUS
|
1999-05-23 19:45:47 -04:00
|
|
|
// Associate the menu bar with the frame
|
2009-01-28 04:00:49 -05:00
|
|
|
SetMenuBar(CreateMainMenubar());
|
2008-11-03 21:46:19 -05:00
|
|
|
|
2009-01-27 11:47:41 -05:00
|
|
|
|
|
|
|
// 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);
|
|
|
|
}
|
2008-11-03 21:46:19 -05:00
|
|
|
#endif // wxUSE_MENUS
|
1998-05-20 10:01:55 -04:00
|
|
|
|
2004-07-19 11:36:01 -04:00
|
|
|
#if wxUSE_STATUSBAR
|
2008-11-03 21:46:19 -05:00
|
|
|
CreateStatusBar();
|
2004-07-19 11:36:01 -04:00
|
|
|
#endif // wxUSE_STATUSBAR
|
1998-05-20 10:01:55 -04:00
|
|
|
|
|
|
|
|
2014-11-10 20:02:31 -05:00
|
|
|
m_textWindow = new wxTextCtrl(this, wxID_ANY, "A log window\n",
|
2008-11-03 21:46:19 -05:00
|
|
|
wxDefaultPosition, wxDefaultSize,
|
2014-11-10 20:02:31 -05:00
|
|
|
wxTE_MULTILINE | wxTE_READONLY);
|
|
|
|
|
|
|
|
// don't clutter the text window with time stamps
|
|
|
|
wxLog::DisableTimestamp();
|
|
|
|
delete wxLog::SetActiveTarget(new wxLogTextCtrl(m_textWindow));
|
1998-05-20 10:01:55 -04:00
|
|
|
|
2003-11-06 13:33:09 -05:00
|
|
|
#if wxUSE_TOOLBAR
|
2000-12-18 10:50:03 -05:00
|
|
|
CreateToolBar(wxNO_BORDER | wxTB_FLAT | wxTB_HORIZONTAL);
|
1998-07-27 05:47:57 -04:00
|
|
|
InitToolBar(GetToolBar());
|
2003-11-06 13:33:09 -05:00
|
|
|
#endif // wxUSE_TOOLBAR
|
1998-07-31 09:01:34 -04:00
|
|
|
|
2006-01-16 11:05:58 -05:00
|
|
|
#if wxUSE_ACCEL
|
1998-07-31 09:01:34 -04:00
|
|
|
// Accelerators
|
|
|
|
wxAcceleratorEntry entries[3];
|
2008-11-03 21:46:19 -05:00
|
|
|
entries[0].Set(wxACCEL_CTRL, (int) 'N', wxID_NEW);
|
|
|
|
entries[1].Set(wxACCEL_CTRL, (int) 'X', wxID_EXIT);
|
|
|
|
entries[2].Set(wxACCEL_CTRL, (int) 'A', wxID_ABOUT);
|
1998-07-31 09:01:34 -04:00
|
|
|
wxAcceleratorTable accel(3, entries);
|
|
|
|
SetAcceleratorTable(accel);
|
2006-01-16 11:05:58 -05:00
|
|
|
#endif // wxUSE_ACCEL
|
2008-11-03 21:46:19 -05:00
|
|
|
|
|
|
|
// connect it only now, after creating m_textWindow
|
2018-05-29 11:32:07 -04:00
|
|
|
Bind(wxEVT_SIZE, &MyFrame::OnSize, this);
|
2008-11-03 21:46:19 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
MyFrame::~MyFrame()
|
|
|
|
{
|
|
|
|
// and disconnect it to prevent accessing already deleted m_textWindow in
|
|
|
|
// the size event handler if it's called during destruction
|
2018-05-29 11:32:07 -04:00
|
|
|
Unbind(wxEVT_SIZE, &MyFrame::OnSize, this);
|
2014-11-10 20:02:31 -05:00
|
|
|
|
|
|
|
// also prevent its use as log target
|
|
|
|
delete wxLog::SetActiveTarget(NULL);
|
1998-05-20 10:01:55 -04:00
|
|
|
}
|
|
|
|
|
2009-01-28 04:00:49 -05:00
|
|
|
#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
|
|
|
|
|
1999-05-23 19:45:47 -04:00
|
|
|
void MyFrame::OnClose(wxCloseEvent& event)
|
|
|
|
{
|
2008-11-03 21:46:19 -05:00
|
|
|
unsigned numChildren = MyChild::GetChildrenCount();
|
2016-01-30 15:30:43 -05:00
|
|
|
if ( event.CanVeto() && (numChildren > 1) )
|
1999-05-23 19:45:47 -04:00
|
|
|
{
|
|
|
|
wxString msg;
|
2008-11-03 21:46:19 -05:00
|
|
|
msg.Printf("%d windows still open, close anyhow?", numChildren);
|
|
|
|
if ( wxMessageBox(msg, "Please confirm",
|
1999-05-23 19:45:47 -04:00
|
|
|
wxICON_QUESTION | wxYES_NO) != wxYES )
|
|
|
|
{
|
|
|
|
event.Veto();
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
event.Skip();
|
|
|
|
}
|
|
|
|
|
|
|
|
void MyFrame::OnQuit(wxCommandEvent& WXUNUSED(event))
|
1998-05-20 10:01:55 -04:00
|
|
|
{
|
1999-05-23 19:45:47 -04:00
|
|
|
Close();
|
1998-05-20 10:01:55 -04:00
|
|
|
}
|
|
|
|
|
1998-07-27 16:50:48 -04:00
|
|
|
void MyFrame::OnAbout(wxCommandEvent& WXUNUSED(event) )
|
1998-05-20 10:01:55 -04:00
|
|
|
{
|
2008-11-03 21:46:19 -05:00
|
|
|
(void)wxMessageBox("wxWidgets 2.0 MDI Demo\n"
|
|
|
|
"Author: Julian Smart (c) 1997\n"
|
|
|
|
"Usage: mdi.exe", "About MDI Demo");
|
1998-05-20 10:01:55 -04:00
|
|
|
}
|
|
|
|
|
1998-07-27 16:50:48 -04:00
|
|
|
void MyFrame::OnNewWindow(wxCommandEvent& WXUNUSED(event) )
|
1998-05-20 10:01:55 -04:00
|
|
|
{
|
2008-11-03 21:46:19 -05:00
|
|
|
// create and show another child frame
|
|
|
|
MyChild *subframe = new MyChild(this);
|
2004-06-01 12:09:27 -04:00
|
|
|
subframe->Show(true);
|
1998-05-20 10:01:55 -04:00
|
|
|
}
|
|
|
|
|
2009-01-26 18:17:09 -05:00
|
|
|
void MyFrame::OnFullScreen(wxCommandEvent& event)
|
|
|
|
{
|
|
|
|
ShowFullScreen(event.IsChecked());
|
|
|
|
}
|
|
|
|
|
2009-01-27 11:47:41 -05:00
|
|
|
void MyFrame::OnCloseAll(wxCommandEvent& WXUNUSED(event))
|
|
|
|
{
|
|
|
|
for ( wxWindowList::const_iterator i = GetChildren().begin();
|
|
|
|
i != GetChildren().end();
|
|
|
|
++i )
|
|
|
|
{
|
|
|
|
if ( wxDynamicCast(*i, wxMDIChildFrame) )
|
|
|
|
(*i)->Close();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-12-09 08:36:23 -05:00
|
|
|
void MyFrame::OnSize(wxSizeEvent& event)
|
1999-05-23 19:45:47 -04:00
|
|
|
{
|
|
|
|
int w, h;
|
|
|
|
GetClientSize(&w, &h);
|
|
|
|
|
2008-11-03 21:46:19 -05:00
|
|
|
m_textWindow->SetSize(0, 0, 200, h);
|
1999-05-23 19:45:47 -04:00
|
|
|
GetClientWindow()->SetSize(200, 0, w - 200, h);
|
2002-08-22 11:44:34 -04:00
|
|
|
|
|
|
|
// FIXME: On wxX11, we need the MDI frame to process this
|
|
|
|
// event, but on other platforms this should not
|
|
|
|
// be done.
|
2006-01-16 11:05:58 -05:00
|
|
|
#ifdef __WXUNIVERSAL__
|
2002-08-20 05:09:55 -04:00
|
|
|
event.Skip();
|
2008-12-09 08:36:23 -05:00
|
|
|
#else
|
|
|
|
wxUnusedVar(event);
|
2002-08-22 11:44:34 -04:00
|
|
|
#endif
|
1999-05-23 19:45:47 -04:00
|
|
|
}
|
|
|
|
|
2003-11-06 13:33:09 -05:00
|
|
|
#if wxUSE_TOOLBAR
|
1999-05-23 19:45:47 -04:00
|
|
|
void MyFrame::InitToolBar(wxToolBar* toolBar)
|
|
|
|
{
|
2006-11-17 10:04:05 -05:00
|
|
|
wxBitmap bitmaps[8];
|
|
|
|
|
|
|
|
bitmaps[0] = wxBitmap( new_xpm );
|
|
|
|
bitmaps[1] = wxBitmap( open_xpm );
|
|
|
|
bitmaps[2] = wxBitmap( save_xpm );
|
|
|
|
bitmaps[3] = wxBitmap( copy_xpm );
|
|
|
|
bitmaps[4] = wxBitmap( cut_xpm );
|
|
|
|
bitmaps[5] = wxBitmap( paste_xpm );
|
|
|
|
bitmaps[6] = wxBitmap( print_xpm );
|
|
|
|
bitmaps[7] = wxBitmap( help_xpm );
|
|
|
|
|
2008-11-03 21:46:19 -05:00
|
|
|
toolBar->AddTool(wxID_NEW, "New", bitmaps[0], "New file");
|
|
|
|
toolBar->AddTool(1, "Open", bitmaps[1], "Open file");
|
|
|
|
toolBar->AddTool(2, "Save", bitmaps[2], "Save file");
|
1999-05-23 19:45:47 -04:00
|
|
|
toolBar->AddSeparator();
|
2008-11-03 21:46:19 -05:00
|
|
|
toolBar->AddTool(3, "Copy", bitmaps[3], "Copy");
|
|
|
|
toolBar->AddTool(4, "Cut", bitmaps[4], "Cut");
|
|
|
|
toolBar->AddTool(5, "Paste", bitmaps[5], "Paste");
|
1999-05-23 19:45:47 -04:00
|
|
|
toolBar->AddSeparator();
|
2008-11-03 21:46:19 -05:00
|
|
|
toolBar->AddTool(6, "Print", bitmaps[6], "Print");
|
1999-05-23 19:45:47 -04:00
|
|
|
toolBar->AddSeparator();
|
2008-11-03 21:46:19 -05:00
|
|
|
toolBar->AddTool(wxID_ABOUT, "About", bitmaps[7], "Help");
|
1999-05-23 19:45:47 -04:00
|
|
|
|
|
|
|
toolBar->Realize();
|
|
|
|
}
|
2003-11-06 13:33:09 -05:00
|
|
|
#endif // wxUSE_TOOLBAR
|
1999-05-23 19:45:47 -04:00
|
|
|
|
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
// MyCanvas
|
|
|
|
// ---------------------------------------------------------------------------
|
1998-05-20 10:01:55 -04:00
|
|
|
|
|
|
|
// Define a constructor for my canvas
|
2014-12-05 17:17:38 -05:00
|
|
|
MyCanvas::MyCanvas(wxFrame *parent, const wxPoint& pos, const wxSize& size)
|
2004-06-01 12:09:27 -04:00
|
|
|
: wxScrolledWindow(parent, wxID_ANY, pos, size,
|
2019-10-10 16:29:12 -04:00
|
|
|
wxSUNKEN_BORDER | wxVSCROLL | wxHSCROLL),
|
2014-12-05 17:17:38 -05:00
|
|
|
MenuEventLogger("canvas", parent)
|
|
|
|
|
1998-05-20 10:01:55 -04:00
|
|
|
{
|
2012-12-01 18:06:50 -05:00
|
|
|
SetBackgroundColour(*wxWHITE);
|
2008-11-03 21:46:19 -05:00
|
|
|
SetCursor(wxCursor(wxCURSOR_PENCIL));
|
|
|
|
|
|
|
|
SetScrollbars(20, 20, 50, 50);
|
1999-05-23 19:45:47 -04:00
|
|
|
|
2004-06-01 12:09:27 -04:00
|
|
|
m_dirty = false;
|
1998-05-20 10:01:55 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// Define the repainting behaviour
|
|
|
|
void MyCanvas::OnDraw(wxDC& dc)
|
|
|
|
{
|
2006-07-24 09:36:22 -04:00
|
|
|
if ( !m_text.empty() )
|
|
|
|
dc.DrawText(m_text, 10, 10);
|
|
|
|
|
1999-05-23 19:45:47 -04:00
|
|
|
dc.SetFont(*wxSWISS_FONT);
|
|
|
|
dc.SetPen(*wxGREEN_PEN);
|
|
|
|
dc.DrawLine(0, 0, 200, 200);
|
|
|
|
dc.DrawLine(200, 0, 0, 200);
|
|
|
|
|
|
|
|
dc.SetBrush(*wxCYAN_BRUSH);
|
|
|
|
dc.SetPen(*wxRED_PEN);
|
|
|
|
dc.DrawRectangle(100, 100, 100, 50);
|
|
|
|
dc.DrawRoundedRectangle(150, 150, 100, 50, 20);
|
|
|
|
|
|
|
|
dc.DrawEllipse(250, 250, 100, 50);
|
2000-02-24 18:40:42 -05:00
|
|
|
#if wxUSE_SPLINES
|
1999-05-23 19:45:47 -04:00
|
|
|
dc.DrawSpline(50, 200, 50, 100, 200, 10);
|
2000-02-24 18:40:42 -05:00
|
|
|
#endif // wxUSE_SPLINES
|
1999-05-23 19:45:47 -04:00
|
|
|
dc.DrawLine(50, 230, 200, 230);
|
2008-11-03 21:46:19 -05:00
|
|
|
dc.DrawText("This is a test string", 50, 230);
|
1999-05-23 19:45:47 -04:00
|
|
|
|
|
|
|
wxPoint points[3];
|
|
|
|
points[0].x = 200; points[0].y = 300;
|
|
|
|
points[1].x = 100; points[1].y = 400;
|
|
|
|
points[2].x = 300; points[2].y = 400;
|
|
|
|
|
|
|
|
dc.DrawPolygon(3, points);
|
1998-05-20 10:01:55 -04:00
|
|
|
}
|
|
|
|
|
1999-05-23 19:45:47 -04:00
|
|
|
// This implements a tiny doodling program! Drag the mouse using the left
|
|
|
|
// button.
|
1998-05-20 10:01:55 -04:00
|
|
|
void MyCanvas::OnEvent(wxMouseEvent& event)
|
|
|
|
{
|
1999-05-23 19:45:47 -04:00
|
|
|
wxClientDC dc(this);
|
|
|
|
PrepareDC(dc);
|
1998-05-20 10:01:55 -04:00
|
|
|
|
1999-05-23 19:45:47 -04:00
|
|
|
wxPoint pt(event.GetLogicalPosition(dc));
|
1998-05-20 10:01:55 -04:00
|
|
|
|
2008-11-03 21:46:19 -05:00
|
|
|
static long xpos = -1;
|
|
|
|
static long ypos = -1;
|
|
|
|
|
1999-05-23 19:45:47 -04:00
|
|
|
if (xpos > -1 && ypos > -1 && event.Dragging())
|
|
|
|
{
|
|
|
|
dc.SetPen(*wxBLACK_PEN);
|
|
|
|
dc.DrawLine(xpos, ypos, pt.x, pt.y);
|
1998-05-20 10:01:55 -04:00
|
|
|
|
2004-06-01 12:09:27 -04:00
|
|
|
m_dirty = true;
|
1999-05-23 19:45:47 -04:00
|
|
|
}
|
2014-12-05 17:17:38 -05:00
|
|
|
else
|
|
|
|
{
|
|
|
|
event.Skip();
|
|
|
|
}
|
1998-05-20 10:01:55 -04:00
|
|
|
|
1999-05-23 19:45:47 -04:00
|
|
|
xpos = pt.x;
|
|
|
|
ypos = pt.y;
|
|
|
|
}
|
|
|
|
|
2014-12-05 17:17:38 -05:00
|
|
|
void MyCanvas::OnMenu(wxContextMenuEvent& event)
|
|
|
|
{
|
|
|
|
wxMenu menu;
|
|
|
|
menu.Append(MDI_REFRESH, "&Refresh picture");
|
2016-01-30 15:33:38 -05:00
|
|
|
menu.Append(MDI_DISABLED_FROM_CANVAS, "Item disabled by canvas");
|
|
|
|
menu.Append(MDI_DISABLED_FROM_CHILD, "Item disabled by child");
|
2014-12-05 17:17:38 -05:00
|
|
|
PopupMenu(&menu, ScreenToClient(event.GetPosition()));
|
|
|
|
}
|
|
|
|
|
1999-05-23 19:45:47 -04:00
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
// MyChild
|
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
2008-11-03 21:46:19 -05:00
|
|
|
unsigned MyChild::ms_numChildren = 0;
|
|
|
|
|
|
|
|
MyChild::MyChild(wxMDIParentFrame *parent)
|
|
|
|
: wxMDIChildFrame
|
|
|
|
(
|
|
|
|
parent,
|
|
|
|
wxID_ANY,
|
|
|
|
wxString::Format("Child %u", ++ms_numChildren)
|
2014-11-10 20:02:31 -05:00
|
|
|
),
|
|
|
|
MenuEventLogger("child", this)
|
1998-05-20 10:01:55 -04:00
|
|
|
{
|
2008-11-03 21:46:19 -05:00
|
|
|
m_canvas = new MyCanvas(this, wxPoint(0, 0), GetClientSize());
|
|
|
|
|
|
|
|
SetIcon(wxICON(chart));
|
|
|
|
|
|
|
|
const bool canBeResized = !IsAlwaysMaximized();
|
|
|
|
|
2009-01-28 04:00:49 -05:00
|
|
|
// create our menu bar: it will be shown instead of the main frame one when
|
2008-11-03 21:46:19 -05:00
|
|
|
// we're active
|
|
|
|
#if wxUSE_MENUS
|
2009-01-28 04:00:49 -05:00
|
|
|
wxMenuBar *mbar = MyFrame::CreateMainMenubar();
|
|
|
|
mbar->GetMenu(0)->Insert(1, wxID_CLOSE, "&Close child\tCtrl-W",
|
|
|
|
"Close this window");
|
2008-11-03 21:46:19 -05:00
|
|
|
|
2009-01-28 04:00:49 -05:00
|
|
|
wxMenu *menuChild = new wxMenu;
|
2008-11-03 21:46:19 -05:00
|
|
|
|
2009-01-28 04:00:49 -05:00
|
|
|
menuChild->Append(MDI_REFRESH, "&Refresh picture");
|
|
|
|
menuChild->Append(MDI_CHANGE_TITLE, "Change &title...\tCtrl-T");
|
2008-11-03 21:46:19 -05:00
|
|
|
if ( canBeResized )
|
|
|
|
{
|
2009-01-28 04:00:49 -05:00
|
|
|
menuChild->AppendSeparator();
|
|
|
|
menuChild->Append(MDI_CHANGE_POSITION, "Move frame\tCtrl-M");
|
|
|
|
menuChild->Append(MDI_CHANGE_SIZE, "Resize frame\tCtrl-S");
|
2008-11-03 21:46:19 -05:00
|
|
|
}
|
|
|
|
#if wxUSE_CLIPBOARD
|
2016-01-30 15:33:38 -05:00
|
|
|
menuChild->AppendSeparator();
|
|
|
|
menuChild->Append(MDI_DISABLED_FROM_CANVAS, "Item not disabled by canvas");
|
|
|
|
menuChild->Append(MDI_DISABLED_FROM_CHILD, "Item disabled by child");
|
2009-01-28 04:00:49 -05:00
|
|
|
menuChild->AppendSeparator();
|
|
|
|
menuChild->Append(wxID_PASTE, "Copy text from clipboard\tCtrl-V");
|
2008-11-03 21:46:19 -05:00
|
|
|
#endif // wxUSE_CLIPBOARD
|
|
|
|
|
2009-01-28 04:00:49 -05:00
|
|
|
mbar->Insert(1, menuChild, "&Child");
|
2008-11-03 21:46:19 -05:00
|
|
|
|
|
|
|
// Associate the menu bar with the frame
|
2009-01-28 04:00:49 -05:00
|
|
|
SetMenuBar(mbar);
|
2008-11-03 21:46:19 -05:00
|
|
|
#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);
|
2010-05-09 10:55:33 -04:00
|
|
|
|
|
|
|
// test that event handlers pushed on top of MDI children do work (this
|
|
|
|
// used to be broken, see #11225)
|
|
|
|
PushEventHandler(new EventHandler(ms_numChildren));
|
1998-05-20 10:01:55 -04:00
|
|
|
}
|
|
|
|
|
1999-05-23 19:45:47 -04:00
|
|
|
MyChild::~MyChild()
|
1998-05-20 10:01:55 -04:00
|
|
|
{
|
2010-05-09 10:55:33 -04:00
|
|
|
PopEventHandler(true);
|
|
|
|
|
2008-11-03 21:46:19 -05:00
|
|
|
ms_numChildren--;
|
1998-05-20 10:01:55 -04:00
|
|
|
}
|
|
|
|
|
2008-11-03 21:46:19 -05:00
|
|
|
void MyChild::OnClose(wxCommandEvent& WXUNUSED(event))
|
1998-05-20 10:01:55 -04:00
|
|
|
{
|
2004-06-01 12:09:27 -04:00
|
|
|
Close(true);
|
1999-05-23 19:45:47 -04:00
|
|
|
}
|
|
|
|
|
2000-07-15 15:51:35 -04:00
|
|
|
void MyChild::OnRefresh(wxCommandEvent& WXUNUSED(event))
|
|
|
|
{
|
2008-11-03 21:46:19 -05:00
|
|
|
if ( m_canvas )
|
|
|
|
m_canvas->Refresh();
|
2000-07-15 15:51:35 -04:00
|
|
|
}
|
|
|
|
|
2000-12-18 10:50:03 -05:00
|
|
|
void MyChild::OnChangePosition(wxCommandEvent& WXUNUSED(event))
|
|
|
|
{
|
|
|
|
Move(10, 10);
|
|
|
|
}
|
|
|
|
|
|
|
|
void MyChild::OnChangeSize(wxCommandEvent& WXUNUSED(event))
|
|
|
|
{
|
|
|
|
SetClientSize(100, 100);
|
|
|
|
}
|
|
|
|
|
2000-07-15 15:51:35 -04:00
|
|
|
void MyChild::OnChangeTitle(wxCommandEvent& WXUNUSED(event))
|
1999-05-23 19:45:47 -04:00
|
|
|
{
|
2006-11-17 10:04:05 -05:00
|
|
|
#if wxUSE_TEXTDLG
|
2008-11-03 21:46:19 -05:00
|
|
|
static wxString s_title = "Canvas Frame";
|
2000-07-15 15:51:35 -04:00
|
|
|
|
2008-11-03 21:46:19 -05:00
|
|
|
wxString title = wxGetTextFromUser("Enter the new title for MDI child",
|
|
|
|
"MDI sample question",
|
2000-07-15 15:51:35 -04:00
|
|
|
s_title,
|
2000-12-18 10:50:03 -05:00
|
|
|
GetParent()->GetParent());
|
2000-07-15 15:51:35 -04:00
|
|
|
if ( !title )
|
|
|
|
return;
|
|
|
|
|
|
|
|
s_title = title;
|
|
|
|
SetTitle(s_title);
|
2006-11-17 10:04:05 -05:00
|
|
|
#endif // wxUSE_TEXTDLG
|
1998-05-20 10:01:55 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void MyChild::OnActivate(wxActivateEvent& event)
|
|
|
|
{
|
2008-11-03 21:46:19 -05:00
|
|
|
if ( event.GetActive() && m_canvas )
|
|
|
|
m_canvas->SetFocus();
|
1998-05-20 10:01:55 -04:00
|
|
|
}
|
|
|
|
|
2000-12-18 10:50:03 -05:00
|
|
|
void MyChild::OnMove(wxMoveEvent& event)
|
|
|
|
{
|
|
|
|
// VZ: here everything is totally wrong under MSW, the positions are
|
|
|
|
// different and both wrong (pos2 is off by 2 pixels for me which seems
|
|
|
|
// to be the width of the MDI canvas border)
|
|
|
|
wxPoint pos1 = event.GetPosition(),
|
|
|
|
pos2 = GetPosition();
|
2008-11-03 21:46:19 -05:00
|
|
|
wxLogStatus("position from event: (%d, %d), from frame (%d, %d)",
|
2000-12-18 10:50:03 -05:00
|
|
|
pos1.x, pos1.y, pos2.x, pos2.y);
|
|
|
|
|
|
|
|
event.Skip();
|
|
|
|
}
|
|
|
|
|
|
|
|
void MyChild::OnSize(wxSizeEvent& event)
|
|
|
|
{
|
|
|
|
// VZ: under MSW the size event carries the client size (quite
|
|
|
|
// unexpectedly) *except* for the very first one which has the full
|
|
|
|
// size... what should it really be? TODO: check under wxGTK
|
|
|
|
wxSize size1 = event.GetSize(),
|
|
|
|
size2 = GetSize(),
|
|
|
|
size3 = GetClientSize();
|
2008-11-03 21:46:19 -05:00
|
|
|
wxLogStatus("size from event: %dx%d, from frame %dx%d, client %dx%d",
|
2000-12-18 10:50:03 -05:00
|
|
|
size1.x, size1.y, size2.x, size2.y, size3.x, size3.y);
|
|
|
|
|
|
|
|
event.Skip();
|
|
|
|
}
|
|
|
|
|
2008-11-03 21:46:19 -05:00
|
|
|
void MyChild::OnCloseWindow(wxCloseEvent& event)
|
1998-05-20 10:01:55 -04:00
|
|
|
{
|
2008-11-03 21:46:19 -05:00
|
|
|
if ( m_canvas && m_canvas->IsDirty() )
|
1999-05-23 19:45:47 -04:00
|
|
|
{
|
2008-11-03 21:46:19 -05:00
|
|
|
if ( wxMessageBox("Really close?", "Please confirm",
|
1999-05-23 19:45:47 -04:00
|
|
|
wxICON_QUESTION | wxYES_NO) != wxYES )
|
|
|
|
{
|
|
|
|
event.Veto();
|
1998-05-20 10:01:55 -04:00
|
|
|
|
1999-05-23 19:45:47 -04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
1998-05-20 10:01:55 -04:00
|
|
|
|
1999-05-23 19:45:47 -04:00
|
|
|
event.Skip();
|
1998-05-20 10:01:55 -04:00
|
|
|
}
|
2006-07-24 09:36:22 -04:00
|
|
|
|
|
|
|
#if wxUSE_CLIPBOARD
|
|
|
|
|
|
|
|
#include "wx/clipbrd.h"
|
|
|
|
|
|
|
|
void MyChild::OnPaste(wxCommandEvent& WXUNUSED(event))
|
|
|
|
{
|
|
|
|
wxClipboardLocker lock;
|
|
|
|
wxTextDataObject data;
|
2008-11-03 21:46:19 -05:00
|
|
|
m_canvas->SetText(wxTheClipboard->GetData(data)
|
|
|
|
? data.GetText()
|
|
|
|
: wxString("No text on clipboard"));
|
2006-07-24 09:36:22 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void MyChild::OnUpdatePaste(wxUpdateUIEvent& event)
|
|
|
|
{
|
|
|
|
wxClipboardLocker lock;
|
|
|
|
event.Enable( wxTheClipboard->IsSupported(wxDF_TEXT) );
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif // wxUSE_CLIPBOARD
|