1998-05-20 14:01:55 +00:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Name: mdi.cpp
|
|
|
|
// Purpose: MDI sample
|
|
|
|
// Author: Julian Smart
|
2008-11-04 02:46:19 +00:00
|
|
|
// Modified by: 2008-10-31 Vadim Zeitlin: big clean up
|
1998-05-20 14:01:55 +00:00
|
|
|
// Created: 04/01/98
|
|
|
|
// RCS-ID: $Id$
|
2008-11-04 02:46:19 +00:00
|
|
|
// Copyright: (c) 1997 Julian Smart
|
|
|
|
// (c) 2008 Vadim Zeitlin
|
1999-05-23 23:45:47 +00:00
|
|
|
// Licence: wxWindows license
|
1998-05-20 14:01:55 +00:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
1999-05-23 23:45:47 +00:00
|
|
|
// ===========================================================================
|
|
|
|
// declarations
|
|
|
|
// ===========================================================================
|
|
|
|
|
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
// headers
|
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
1998-05-20 14:01:55 +00:00
|
|
|
// For compilers that support precompilation, includes "wx/wx.h".
|
|
|
|
#include "wx/wxprec.h"
|
|
|
|
|
|
|
|
#ifdef __BORLANDC__
|
1999-05-23 23:45:47 +00:00
|
|
|
#pragma hdrstop
|
1998-05-20 14:01:55 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef WX_PRECOMP
|
1999-05-23 23:45:47 +00:00
|
|
|
#include "wx/wx.h"
|
|
|
|
#include "wx/mdi.h"
|
1998-05-20 14:01:55 +00:00
|
|
|
#endif
|
|
|
|
|
2002-01-19 14:50:37 +00:00
|
|
|
#include "wx/toolbar.h"
|
1998-05-20 14:01:55 +00:00
|
|
|
|
2003-11-06 18:36:49 +00:00
|
|
|
#if !defined(__WXMSW__)
|
2006-11-18 00:08:27 +00:00
|
|
|
#include "../sample.xpm"
|
|
|
|
#include "chart.xpm"
|
1998-07-22 22:13:31 +00:00
|
|
|
#endif
|
|
|
|
|
2002-06-12 11:56:01 +00: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-04 02:46:19 +00: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 11:56:01 +00:00
|
|
|
|
1998-05-20 14:01:55 +00:00
|
|
|
#include "mdi.h"
|
|
|
|
|
1999-05-23 23:45:47 +00:00
|
|
|
IMPLEMENT_APP(MyApp)
|
|
|
|
|
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
// event tables
|
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
BEGIN_EVENT_TABLE(MyFrame, wxMDIParentFrame)
|
2008-11-04 02:46:19 +00:00
|
|
|
EVT_MENU(wxID_ABOUT, MyFrame::OnAbout)
|
|
|
|
EVT_MENU(wxID_NEW, MyFrame::OnNewWindow)
|
2009-01-26 23:17:09 +00:00
|
|
|
EVT_MENU(MDI_FULLSCREEN, MyFrame::OnFullScreen)
|
2008-11-04 02:46:19 +00:00
|
|
|
EVT_MENU(wxID_EXIT, MyFrame::OnQuit)
|
1999-05-23 23:45:47 +00:00
|
|
|
|
|
|
|
EVT_CLOSE(MyFrame::OnClose)
|
|
|
|
END_EVENT_TABLE()
|
|
|
|
|
2008-11-04 02:46:19 +00:00
|
|
|
// Note that wxID_NEW and wxID_ABOUT commands get passed
|
1999-05-23 23:45:47 +00:00
|
|
|
// to the parent window for processing, so no need to
|
|
|
|
// duplicate event handlers here.
|
|
|
|
BEGIN_EVENT_TABLE(MyChild, wxMDIChildFrame)
|
2008-11-04 02:46:19 +00:00
|
|
|
EVT_MENU(wxID_CLOSE, MyChild::OnClose)
|
1999-05-23 23:45:47 +00:00
|
|
|
EVT_MENU(MDI_REFRESH, MyChild::OnRefresh)
|
2000-07-15 19:51:35 +00:00
|
|
|
EVT_MENU(MDI_CHANGE_TITLE, MyChild::OnChangeTitle)
|
2000-12-10 12:04:19 +00:00
|
|
|
EVT_MENU(MDI_CHANGE_POSITION, MyChild::OnChangePosition)
|
|
|
|
EVT_MENU(MDI_CHANGE_SIZE, MyChild::OnChangeSize)
|
|
|
|
|
2006-07-24 13:36:22 +00:00
|
|
|
#if wxUSE_CLIPBOARD
|
|
|
|
EVT_MENU(wxID_PASTE, MyChild::OnPaste)
|
|
|
|
EVT_UPDATE_UI(wxID_PASTE, MyChild::OnUpdatePaste)
|
|
|
|
#endif // wxUSE_CLIPBOARD
|
|
|
|
|
2000-12-10 12:04:19 +00:00
|
|
|
EVT_SIZE(MyChild::OnSize)
|
|
|
|
EVT_MOVE(MyChild::OnMove)
|
1999-05-23 23:45:47 +00:00
|
|
|
|
2008-11-04 02:46:19 +00:00
|
|
|
EVT_CLOSE(MyChild::OnCloseWindow)
|
1999-05-23 23:45:47 +00:00
|
|
|
END_EVENT_TABLE()
|
|
|
|
|
|
|
|
BEGIN_EVENT_TABLE(MyCanvas, wxScrolledWindow)
|
|
|
|
EVT_MOUSE_EVENTS(MyCanvas::OnEvent)
|
|
|
|
END_EVENT_TABLE()
|
|
|
|
|
|
|
|
// ===========================================================================
|
|
|
|
// implementation
|
|
|
|
// ===========================================================================
|
1998-05-20 14:01:55 +00:00
|
|
|
|
1999-05-23 23:45:47 +00:00
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
// MyApp
|
|
|
|
// ---------------------------------------------------------------------------
|
1998-05-20 14:01:55 +00:00
|
|
|
|
|
|
|
// Initialise this in OnInit, not statically
|
1999-05-23 23:45:47 +00:00
|
|
|
bool MyApp::OnInit()
|
1998-05-20 14:01:55 +00:00
|
|
|
{
|
2007-02-04 00:34:18 +00:00
|
|
|
if ( !wxApp::OnInit() )
|
|
|
|
return false;
|
|
|
|
|
1999-05-23 23:45:47 +00:00
|
|
|
// Create the main frame window
|
1998-05-20 14:01:55 +00:00
|
|
|
|
2008-11-04 02:46:19 +00:00
|
|
|
MyFrame *frame = new MyFrame;
|
1998-05-20 14:01:55 +00:00
|
|
|
|
2008-11-04 02:46:19 +00:00
|
|
|
frame->Show(true);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
// MyFrame
|
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
// Define my frame constructor
|
|
|
|
MyFrame::MyFrame()
|
|
|
|
: wxMDIParentFrame(NULL, wxID_ANY, "wxWidgets MDI Sample",
|
|
|
|
wxDefaultPosition, wxSize(500, 400))
|
|
|
|
{
|
|
|
|
SetIcon(wxICON(sample));
|
1998-05-20 14:01:55 +00:00
|
|
|
|
1999-05-23 23:45:47 +00:00
|
|
|
// Make a menubar
|
2008-11-04 02:46:19 +00:00
|
|
|
#if wxUSE_MENUS
|
1999-05-23 23:45:47 +00:00
|
|
|
wxMenu *file_menu = new wxMenu;
|
1998-05-20 14:01:55 +00:00
|
|
|
|
2008-11-04 02:46:19 +00:00
|
|
|
file_menu->Append(wxID_NEW, "&New window\tCtrl-N", "Create a new child window");
|
2009-01-26 23:17:09 +00:00
|
|
|
file_menu->AppendCheckItem(MDI_FULLSCREEN, "Show &fullscreen\tCtrl-F");
|
2008-11-04 02:46:19 +00:00
|
|
|
file_menu->Append(wxID_EXIT, "&Exit\tAlt-X", "Quit the program");
|
1998-05-20 14:01:55 +00:00
|
|
|
|
1999-05-23 23:45:47 +00:00
|
|
|
wxMenu *help_menu = new wxMenu;
|
2008-11-04 02:46:19 +00:00
|
|
|
help_menu->Append(wxID_ABOUT, "&About\tF1");
|
1998-05-20 14:01:55 +00:00
|
|
|
|
1999-05-23 23:45:47 +00:00
|
|
|
wxMenuBar *menu_bar = new wxMenuBar;
|
1998-05-20 14:01:55 +00:00
|
|
|
|
2008-11-04 02:46:19 +00:00
|
|
|
menu_bar->Append(file_menu, "&File");
|
|
|
|
menu_bar->Append(help_menu, "&Help");
|
1998-05-20 14:01:55 +00:00
|
|
|
|
1999-05-23 23:45:47 +00:00
|
|
|
// Associate the menu bar with the frame
|
2008-11-04 02:46:19 +00:00
|
|
|
SetMenuBar(menu_bar);
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
// Experimental: change the window menu
|
|
|
|
wxMenu* windowMenu = new wxMenu;
|
|
|
|
windowMenu->Append(5000, "My menu item!");
|
|
|
|
frame->SetWindowMenu(windowMenu);
|
|
|
|
#endif
|
|
|
|
#endif // wxUSE_MENUS
|
1998-05-20 14:01:55 +00:00
|
|
|
|
2004-07-19 15:36:01 +00:00
|
|
|
#if wxUSE_STATUSBAR
|
2008-11-04 02:46:19 +00:00
|
|
|
CreateStatusBar();
|
2004-07-19 15:36:01 +00:00
|
|
|
#endif // wxUSE_STATUSBAR
|
1998-05-20 14:01:55 +00:00
|
|
|
|
|
|
|
|
2008-11-04 02:46:19 +00:00
|
|
|
m_textWindow = new wxTextCtrl(this, wxID_ANY, "A help window",
|
|
|
|
wxDefaultPosition, wxDefaultSize,
|
|
|
|
wxTE_MULTILINE | wxSUNKEN_BORDER);
|
1998-05-20 14:01:55 +00:00
|
|
|
|
2003-11-06 18:33:09 +00:00
|
|
|
#if wxUSE_TOOLBAR
|
2000-12-18 15:50:03 +00:00
|
|
|
CreateToolBar(wxNO_BORDER | wxTB_FLAT | wxTB_HORIZONTAL);
|
1998-07-27 09:47:57 +00:00
|
|
|
InitToolBar(GetToolBar());
|
2003-11-06 18:33:09 +00:00
|
|
|
#endif // wxUSE_TOOLBAR
|
1998-07-31 13:01:34 +00:00
|
|
|
|
2006-01-16 16:05:58 +00:00
|
|
|
#if wxUSE_ACCEL
|
1998-07-31 13:01:34 +00:00
|
|
|
// Accelerators
|
|
|
|
wxAcceleratorEntry entries[3];
|
2008-11-04 02:46:19 +00: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 13:01:34 +00:00
|
|
|
wxAcceleratorTable accel(3, entries);
|
|
|
|
SetAcceleratorTable(accel);
|
2006-01-16 16:05:58 +00:00
|
|
|
#endif // wxUSE_ACCEL
|
2008-11-04 02:46:19 +00:00
|
|
|
|
|
|
|
// connect it only now, after creating m_textWindow
|
|
|
|
Connect(wxEVT_SIZE, wxSizeEventHandler(MyFrame::OnSize));
|
|
|
|
}
|
|
|
|
|
|
|
|
MyFrame::~MyFrame()
|
|
|
|
{
|
|
|
|
// and disconnect it to prevent accessing already deleted m_textWindow in
|
|
|
|
// the size event handler if it's called during destruction
|
|
|
|
Disconnect(wxEVT_SIZE, wxSizeEventHandler(MyFrame::OnSize));
|
1998-05-20 14:01:55 +00:00
|
|
|
}
|
|
|
|
|
1999-05-23 23:45:47 +00:00
|
|
|
void MyFrame::OnClose(wxCloseEvent& event)
|
|
|
|
{
|
2008-11-04 02:46:19 +00:00
|
|
|
unsigned numChildren = MyChild::GetChildrenCount();
|
|
|
|
if ( event.CanVeto() && (numChildren > 0) )
|
1999-05-23 23:45:47 +00:00
|
|
|
{
|
|
|
|
wxString msg;
|
2008-11-04 02:46:19 +00:00
|
|
|
msg.Printf("%d windows still open, close anyhow?", numChildren);
|
|
|
|
if ( wxMessageBox(msg, "Please confirm",
|
1999-05-23 23:45:47 +00:00
|
|
|
wxICON_QUESTION | wxYES_NO) != wxYES )
|
|
|
|
{
|
|
|
|
event.Veto();
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
event.Skip();
|
|
|
|
}
|
|
|
|
|
|
|
|
void MyFrame::OnQuit(wxCommandEvent& WXUNUSED(event))
|
1998-05-20 14:01:55 +00:00
|
|
|
{
|
1999-05-23 23:45:47 +00:00
|
|
|
Close();
|
1998-05-20 14:01:55 +00:00
|
|
|
}
|
|
|
|
|
1998-07-27 20:50:48 +00:00
|
|
|
void MyFrame::OnAbout(wxCommandEvent& WXUNUSED(event) )
|
1998-05-20 14:01:55 +00:00
|
|
|
{
|
2008-11-04 02:46:19 +00:00
|
|
|
(void)wxMessageBox("wxWidgets 2.0 MDI Demo\n"
|
|
|
|
"Author: Julian Smart (c) 1997\n"
|
|
|
|
"Usage: mdi.exe", "About MDI Demo");
|
1998-05-20 14:01:55 +00:00
|
|
|
}
|
|
|
|
|
1998-07-27 20:50:48 +00:00
|
|
|
void MyFrame::OnNewWindow(wxCommandEvent& WXUNUSED(event) )
|
1998-05-20 14:01:55 +00:00
|
|
|
{
|
2008-11-04 02:46:19 +00:00
|
|
|
// create and show another child frame
|
|
|
|
MyChild *subframe = new MyChild(this);
|
2004-06-01 16:09:27 +00:00
|
|
|
subframe->Show(true);
|
1998-05-20 14:01:55 +00:00
|
|
|
}
|
|
|
|
|
2009-01-26 23:17:09 +00:00
|
|
|
void MyFrame::OnFullScreen(wxCommandEvent& event)
|
|
|
|
{
|
|
|
|
ShowFullScreen(event.IsChecked());
|
|
|
|
}
|
|
|
|
|
2008-12-09 13:36:23 +00:00
|
|
|
void MyFrame::OnSize(wxSizeEvent& event)
|
1999-05-23 23:45:47 +00:00
|
|
|
{
|
|
|
|
int w, h;
|
|
|
|
GetClientSize(&w, &h);
|
|
|
|
|
2008-11-04 02:46:19 +00:00
|
|
|
m_textWindow->SetSize(0, 0, 200, h);
|
1999-05-23 23:45:47 +00:00
|
|
|
GetClientWindow()->SetSize(200, 0, w - 200, h);
|
2002-08-22 15:44:34 +00: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 16:05:58 +00:00
|
|
|
#ifdef __WXUNIVERSAL__
|
2002-08-20 09:09:55 +00:00
|
|
|
event.Skip();
|
2008-12-09 13:36:23 +00:00
|
|
|
#else
|
|
|
|
wxUnusedVar(event);
|
2002-08-22 15:44:34 +00:00
|
|
|
#endif
|
1999-05-23 23:45:47 +00:00
|
|
|
}
|
|
|
|
|
2003-11-06 18:33:09 +00:00
|
|
|
#if wxUSE_TOOLBAR
|
1999-05-23 23:45:47 +00:00
|
|
|
void MyFrame::InitToolBar(wxToolBar* toolBar)
|
|
|
|
{
|
2006-11-17 15:04:05 +00: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-04 02:46:19 +00: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 23:45:47 +00:00
|
|
|
toolBar->AddSeparator();
|
2008-11-04 02:46:19 +00: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 23:45:47 +00:00
|
|
|
toolBar->AddSeparator();
|
2008-11-04 02:46:19 +00:00
|
|
|
toolBar->AddTool(6, "Print", bitmaps[6], "Print");
|
1999-05-23 23:45:47 +00:00
|
|
|
toolBar->AddSeparator();
|
2008-11-04 02:46:19 +00:00
|
|
|
toolBar->AddTool(wxID_ABOUT, "About", bitmaps[7], "Help");
|
1999-05-23 23:45:47 +00:00
|
|
|
|
|
|
|
toolBar->Realize();
|
|
|
|
}
|
2003-11-06 18:33:09 +00:00
|
|
|
#endif // wxUSE_TOOLBAR
|
1999-05-23 23:45:47 +00:00
|
|
|
|
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
// MyCanvas
|
|
|
|
// ---------------------------------------------------------------------------
|
1998-05-20 14:01:55 +00:00
|
|
|
|
|
|
|
// Define a constructor for my canvas
|
1999-05-23 23:45:47 +00:00
|
|
|
MyCanvas::MyCanvas(wxWindow *parent, const wxPoint& pos, const wxSize& size)
|
2004-06-01 16:09:27 +00:00
|
|
|
: wxScrolledWindow(parent, wxID_ANY, pos, size,
|
2001-06-16 01:36:35 +00:00
|
|
|
wxSUNKEN_BORDER |
|
|
|
|
wxNO_FULL_REPAINT_ON_RESIZE |
|
|
|
|
wxVSCROLL | wxHSCROLL)
|
1998-05-20 14:01:55 +00:00
|
|
|
{
|
2008-11-04 02:46:19 +00:00
|
|
|
SetBackgroundColour(wxColour("WHITE"));
|
|
|
|
SetCursor(wxCursor(wxCURSOR_PENCIL));
|
|
|
|
|
|
|
|
SetScrollbars(20, 20, 50, 50);
|
1999-05-23 23:45:47 +00:00
|
|
|
|
2004-06-01 16:09:27 +00:00
|
|
|
m_dirty = false;
|
1998-05-20 14:01:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Define the repainting behaviour
|
|
|
|
void MyCanvas::OnDraw(wxDC& dc)
|
|
|
|
{
|
2006-07-24 13:36:22 +00:00
|
|
|
if ( !m_text.empty() )
|
|
|
|
dc.DrawText(m_text, 10, 10);
|
|
|
|
|
1999-05-23 23:45:47 +00: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 23:40:42 +00:00
|
|
|
#if wxUSE_SPLINES
|
1999-05-23 23:45:47 +00:00
|
|
|
dc.DrawSpline(50, 200, 50, 100, 200, 10);
|
2000-02-24 23:40:42 +00:00
|
|
|
#endif // wxUSE_SPLINES
|
1999-05-23 23:45:47 +00:00
|
|
|
dc.DrawLine(50, 230, 200, 230);
|
2008-11-04 02:46:19 +00:00
|
|
|
dc.DrawText("This is a test string", 50, 230);
|
1999-05-23 23:45:47 +00: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 14:01:55 +00:00
|
|
|
}
|
|
|
|
|
1999-05-23 23:45:47 +00:00
|
|
|
// This implements a tiny doodling program! Drag the mouse using the left
|
|
|
|
// button.
|
1998-05-20 14:01:55 +00:00
|
|
|
void MyCanvas::OnEvent(wxMouseEvent& event)
|
|
|
|
{
|
1999-05-23 23:45:47 +00:00
|
|
|
wxClientDC dc(this);
|
|
|
|
PrepareDC(dc);
|
1998-05-20 14:01:55 +00:00
|
|
|
|
1999-05-23 23:45:47 +00:00
|
|
|
wxPoint pt(event.GetLogicalPosition(dc));
|
1998-05-20 14:01:55 +00:00
|
|
|
|
2008-11-04 02:46:19 +00:00
|
|
|
static long xpos = -1;
|
|
|
|
static long ypos = -1;
|
|
|
|
|
1999-05-23 23:45:47 +00:00
|
|
|
if (xpos > -1 && ypos > -1 && event.Dragging())
|
|
|
|
{
|
|
|
|
dc.SetPen(*wxBLACK_PEN);
|
|
|
|
dc.DrawLine(xpos, ypos, pt.x, pt.y);
|
1998-05-20 14:01:55 +00:00
|
|
|
|
2004-06-01 16:09:27 +00:00
|
|
|
m_dirty = true;
|
1999-05-23 23:45:47 +00:00
|
|
|
}
|
1998-05-20 14:01:55 +00:00
|
|
|
|
1999-05-23 23:45:47 +00:00
|
|
|
xpos = pt.x;
|
|
|
|
ypos = pt.y;
|
|
|
|
}
|
|
|
|
|
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
// MyChild
|
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
2008-11-04 02:46:19 +00:00
|
|
|
unsigned MyChild::ms_numChildren = 0;
|
|
|
|
|
|
|
|
MyChild::MyChild(wxMDIParentFrame *parent)
|
|
|
|
: wxMDIChildFrame
|
|
|
|
(
|
|
|
|
parent,
|
|
|
|
wxID_ANY,
|
|
|
|
wxString::Format("Child %u", ++ms_numChildren)
|
|
|
|
)
|
1998-05-20 14:01:55 +00:00
|
|
|
{
|
2008-11-04 02:46:19 +00:00
|
|
|
m_canvas = new MyCanvas(this, wxPoint(0, 0), GetClientSize());
|
|
|
|
|
|
|
|
SetIcon(wxICON(chart));
|
|
|
|
|
|
|
|
const bool canBeResized = !IsAlwaysMaximized();
|
|
|
|
|
|
|
|
// create our menubar: it will be shown instead of the main frame one when
|
|
|
|
// we're active
|
|
|
|
#if wxUSE_MENUS
|
|
|
|
// Make a menubar
|
|
|
|
wxMenu *file_menu = new wxMenu;
|
2001-06-16 01:36:35 +00:00
|
|
|
|
2008-11-04 02:46:19 +00:00
|
|
|
file_menu->Append(wxID_NEW, "&New window\tCtrl-N");
|
|
|
|
file_menu->Append(wxID_CLOSE, "&Close child\tCtrl-W", "Close this window");
|
2009-01-26 23:17:09 +00:00
|
|
|
file_menu->AppendCheckItem(MDI_FULLSCREEN, "Show &fullscreen\tCtrl-F");
|
2008-11-04 02:46:19 +00:00
|
|
|
file_menu->Append(wxID_EXIT, "&Exit\tAlt-X", "Quit the program");
|
|
|
|
|
|
|
|
wxMenu *option_menu = new wxMenu;
|
|
|
|
|
|
|
|
option_menu->Append(MDI_REFRESH, "&Refresh picture");
|
|
|
|
option_menu->Append(MDI_CHANGE_TITLE, "Change &title...\tCtrl-T");
|
|
|
|
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");
|
|
|
|
}
|
|
|
|
#if wxUSE_CLIPBOARD
|
|
|
|
option_menu->AppendSeparator();
|
|
|
|
option_menu->Append(wxID_PASTE, "Copy text from clipboard\tCtrl-V");
|
|
|
|
#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");
|
|
|
|
|
|
|
|
// Associate the menu bar with the frame
|
|
|
|
SetMenuBar(menu_bar);
|
|
|
|
#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);
|
1998-05-20 14:01:55 +00:00
|
|
|
}
|
|
|
|
|
1999-05-23 23:45:47 +00:00
|
|
|
MyChild::~MyChild()
|
1998-05-20 14:01:55 +00:00
|
|
|
{
|
2008-11-04 02:46:19 +00:00
|
|
|
ms_numChildren--;
|
1998-05-20 14:01:55 +00:00
|
|
|
}
|
|
|
|
|
2008-11-04 02:46:19 +00:00
|
|
|
void MyChild::OnClose(wxCommandEvent& WXUNUSED(event))
|
1998-05-20 14:01:55 +00:00
|
|
|
{
|
2004-06-01 16:09:27 +00:00
|
|
|
Close(true);
|
1999-05-23 23:45:47 +00:00
|
|
|
}
|
|
|
|
|
2000-07-15 19:51:35 +00:00
|
|
|
void MyChild::OnRefresh(wxCommandEvent& WXUNUSED(event))
|
|
|
|
{
|
2008-11-04 02:46:19 +00:00
|
|
|
if ( m_canvas )
|
|
|
|
m_canvas->Refresh();
|
2000-07-15 19:51:35 +00:00
|
|
|
}
|
|
|
|
|
2000-12-18 15:50:03 +00:00
|
|
|
void MyChild::OnChangePosition(wxCommandEvent& WXUNUSED(event))
|
|
|
|
{
|
|
|
|
Move(10, 10);
|
|
|
|
}
|
|
|
|
|
|
|
|
void MyChild::OnChangeSize(wxCommandEvent& WXUNUSED(event))
|
|
|
|
{
|
|
|
|
SetClientSize(100, 100);
|
|
|
|
}
|
|
|
|
|
2000-07-15 19:51:35 +00:00
|
|
|
void MyChild::OnChangeTitle(wxCommandEvent& WXUNUSED(event))
|
1999-05-23 23:45:47 +00:00
|
|
|
{
|
2006-11-17 15:04:05 +00:00
|
|
|
#if wxUSE_TEXTDLG
|
2008-11-04 02:46:19 +00:00
|
|
|
static wxString s_title = "Canvas Frame";
|
2000-07-15 19:51:35 +00:00
|
|
|
|
2008-11-04 02:46:19 +00:00
|
|
|
wxString title = wxGetTextFromUser("Enter the new title for MDI child",
|
|
|
|
"MDI sample question",
|
2000-07-15 19:51:35 +00:00
|
|
|
s_title,
|
2000-12-18 15:50:03 +00:00
|
|
|
GetParent()->GetParent());
|
2000-07-15 19:51:35 +00:00
|
|
|
if ( !title )
|
|
|
|
return;
|
|
|
|
|
|
|
|
s_title = title;
|
|
|
|
SetTitle(s_title);
|
2006-11-17 15:04:05 +00:00
|
|
|
#endif // wxUSE_TEXTDLG
|
1998-05-20 14:01:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void MyChild::OnActivate(wxActivateEvent& event)
|
|
|
|
{
|
2008-11-04 02:46:19 +00:00
|
|
|
if ( event.GetActive() && m_canvas )
|
|
|
|
m_canvas->SetFocus();
|
1998-05-20 14:01:55 +00:00
|
|
|
}
|
|
|
|
|
2000-12-18 15:50:03 +00: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-04 02:46:19 +00:00
|
|
|
wxLogStatus("position from event: (%d, %d), from frame (%d, %d)",
|
2000-12-18 15:50:03 +00: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-04 02:46:19 +00:00
|
|
|
wxLogStatus("size from event: %dx%d, from frame %dx%d, client %dx%d",
|
2000-12-18 15:50:03 +00:00
|
|
|
size1.x, size1.y, size2.x, size2.y, size3.x, size3.y);
|
|
|
|
|
|
|
|
event.Skip();
|
|
|
|
}
|
|
|
|
|
2008-11-04 02:46:19 +00:00
|
|
|
void MyChild::OnCloseWindow(wxCloseEvent& event)
|
1998-05-20 14:01:55 +00:00
|
|
|
{
|
2008-11-04 02:46:19 +00:00
|
|
|
if ( m_canvas && m_canvas->IsDirty() )
|
1999-05-23 23:45:47 +00:00
|
|
|
{
|
2008-11-04 02:46:19 +00:00
|
|
|
if ( wxMessageBox("Really close?", "Please confirm",
|
1999-05-23 23:45:47 +00:00
|
|
|
wxICON_QUESTION | wxYES_NO) != wxYES )
|
|
|
|
{
|
|
|
|
event.Veto();
|
1998-05-20 14:01:55 +00:00
|
|
|
|
1999-05-23 23:45:47 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
1998-05-20 14:01:55 +00:00
|
|
|
|
1999-05-23 23:45:47 +00:00
|
|
|
event.Skip();
|
1998-05-20 14:01:55 +00:00
|
|
|
}
|
2006-07-24 13:36:22 +00:00
|
|
|
|
|
|
|
#if wxUSE_CLIPBOARD
|
|
|
|
|
|
|
|
#include "wx/clipbrd.h"
|
|
|
|
|
|
|
|
void MyChild::OnPaste(wxCommandEvent& WXUNUSED(event))
|
|
|
|
{
|
|
|
|
wxClipboardLocker lock;
|
|
|
|
wxTextDataObject data;
|
2008-11-04 02:46:19 +00:00
|
|
|
m_canvas->SetText(wxTheClipboard->GetData(data)
|
|
|
|
? data.GetText()
|
|
|
|
: wxString("No text on clipboard"));
|
2006-07-24 13:36:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void MyChild::OnUpdatePaste(wxUpdateUIEvent& event)
|
|
|
|
{
|
|
|
|
wxClipboardLocker lock;
|
|
|
|
event.Enable( wxTheClipboard->IsSupported(wxDF_TEXT) );
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif // wxUSE_CLIPBOARD
|