more MDI features tested
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@2546 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -9,52 +9,100 @@
|
|||||||
// Licence: wxWindows license
|
// Licence: wxWindows license
|
||||||
/////////////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
// ===========================================================================
|
||||||
|
// declarations
|
||||||
|
// ===========================================================================
|
||||||
|
|
||||||
|
// ---------------------------------------------------------------------------
|
||||||
|
// headers
|
||||||
|
// ---------------------------------------------------------------------------
|
||||||
|
|
||||||
// For compilers that support precompilation, includes "wx/wx.h".
|
// For compilers that support precompilation, includes "wx/wx.h".
|
||||||
#include "wx/wxprec.h"
|
#include "wx/wxprec.h"
|
||||||
|
|
||||||
#ifdef __BORLANDC__
|
#ifdef __BORLANDC__
|
||||||
#pragma hdrstop
|
#pragma hdrstop
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef WX_PRECOMP
|
#ifndef WX_PRECOMP
|
||||||
#include "wx/wx.h"
|
#include "wx/wx.h"
|
||||||
#include "wx/mdi.h"
|
#include "wx/mdi.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <wx/toolbar.h>
|
#include <wx/toolbar.h>
|
||||||
|
|
||||||
#if defined(__WXGTK__) || defined(__WXMOTIF__)
|
#if defined(__WXGTK__) || defined(__WXMOTIF__)
|
||||||
#include "mondrian.xpm"
|
#include "mondrian.xpm"
|
||||||
#include "bitmaps/new.xpm"
|
#include "bitmaps/new.xpm"
|
||||||
#include "bitmaps/open.xpm"
|
#include "bitmaps/open.xpm"
|
||||||
#include "bitmaps/save.xpm"
|
#include "bitmaps/save.xpm"
|
||||||
#include "bitmaps/copy.xpm"
|
#include "bitmaps/copy.xpm"
|
||||||
#include "bitmaps/cut.xpm"
|
#include "bitmaps/cut.xpm"
|
||||||
#include "bitmaps/paste.xpm"
|
#include "bitmaps/paste.xpm"
|
||||||
#include "bitmaps/print.xpm"
|
#include "bitmaps/print.xpm"
|
||||||
#include "bitmaps/help.xpm"
|
#include "bitmaps/help.xpm"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
#include "mdi.h"
|
#include "mdi.h"
|
||||||
|
|
||||||
|
IMPLEMENT_APP(MyApp)
|
||||||
|
|
||||||
|
// ---------------------------------------------------------------------------
|
||||||
|
// global variables
|
||||||
|
// ---------------------------------------------------------------------------
|
||||||
|
|
||||||
MyFrame *frame = (MyFrame *) NULL;
|
MyFrame *frame = (MyFrame *) NULL;
|
||||||
wxList my_children;
|
wxList my_children;
|
||||||
|
|
||||||
IMPLEMENT_APP(MyApp)
|
|
||||||
|
|
||||||
// For drawing lines in a canvas
|
// For drawing lines in a canvas
|
||||||
long xpos = -1;
|
static long xpos = -1;
|
||||||
long ypos = -1;
|
static long ypos = -1;
|
||||||
|
|
||||||
int winNumber = 1;
|
static int gs_nFrames = 0;
|
||||||
|
|
||||||
|
// ---------------------------------------------------------------------------
|
||||||
|
// event tables
|
||||||
|
// ---------------------------------------------------------------------------
|
||||||
|
|
||||||
|
BEGIN_EVENT_TABLE(MyFrame, wxMDIParentFrame)
|
||||||
|
EVT_MENU(MDI_ABOUT, MyFrame::OnAbout)
|
||||||
|
EVT_MENU(MDI_NEW_WINDOW, MyFrame::OnNewWindow)
|
||||||
|
EVT_MENU(MDI_QUIT, MyFrame::OnQuit)
|
||||||
|
|
||||||
|
EVT_CLOSE(MyFrame::OnClose)
|
||||||
|
|
||||||
|
EVT_SIZE(MyFrame::OnSize)
|
||||||
|
END_EVENT_TABLE()
|
||||||
|
|
||||||
|
// Note that MDI_NEW_WINDOW and MDI_ABOUT commands get passed
|
||||||
|
// to the parent window for processing, so no need to
|
||||||
|
// duplicate event handlers here.
|
||||||
|
BEGIN_EVENT_TABLE(MyChild, wxMDIChildFrame)
|
||||||
|
EVT_MENU(MDI_CHILD_QUIT, MyChild::OnQuit)
|
||||||
|
EVT_MENU(MDI_REFRESH, MyChild::OnRefresh)
|
||||||
|
|
||||||
|
EVT_CLOSE(MyChild::OnClose)
|
||||||
|
END_EVENT_TABLE()
|
||||||
|
|
||||||
|
BEGIN_EVENT_TABLE(MyCanvas, wxScrolledWindow)
|
||||||
|
EVT_MOUSE_EVENTS(MyCanvas::OnEvent)
|
||||||
|
END_EVENT_TABLE()
|
||||||
|
|
||||||
|
// ===========================================================================
|
||||||
|
// implementation
|
||||||
|
// ===========================================================================
|
||||||
|
|
||||||
|
// ---------------------------------------------------------------------------
|
||||||
|
// MyApp
|
||||||
|
// ---------------------------------------------------------------------------
|
||||||
|
|
||||||
// Initialise this in OnInit, not statically
|
// Initialise this in OnInit, not statically
|
||||||
bool MyApp::OnInit(void)
|
bool MyApp::OnInit()
|
||||||
{
|
{
|
||||||
// Create the main frame window
|
// Create the main frame window
|
||||||
|
|
||||||
frame = new MyFrame((wxFrame *) NULL, -1, (char *) "MDI Demo", wxPoint(-1, -1), wxSize(500, 400),
|
frame = new MyFrame((wxFrame *)NULL, -1, "MDI Demo",
|
||||||
|
wxPoint(-1, -1), wxSize(500, 400),
|
||||||
wxDEFAULT_FRAME_STYLE | wxHSCROLL | wxVSCROLL);
|
wxDEFAULT_FRAME_STYLE | wxHSCROLL | wxVSCROLL);
|
||||||
|
|
||||||
// Give it an icon
|
// Give it an icon
|
||||||
@@ -67,8 +115,8 @@ bool MyApp::OnInit(void)
|
|||||||
// Make a menubar
|
// Make a menubar
|
||||||
wxMenu *file_menu = new wxMenu;
|
wxMenu *file_menu = new wxMenu;
|
||||||
|
|
||||||
file_menu->Append(MDI_NEW_WINDOW, "&New window");
|
file_menu->Append(MDI_NEW_WINDOW, "&New window", "Create a new child window");
|
||||||
file_menu->Append(MDI_QUIT, "&Exit");
|
file_menu->Append(MDI_QUIT, "&Exit", "Quit the program");
|
||||||
|
|
||||||
wxMenu *help_menu = new wxMenu;
|
wxMenu *help_menu = new wxMenu;
|
||||||
help_menu->Append(MDI_ABOUT, "&About");
|
help_menu->Append(MDI_ABOUT, "&About");
|
||||||
@@ -90,23 +138,24 @@ bool MyApp::OnInit(void)
|
|||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
BEGIN_EVENT_TABLE(MyFrame, wxMDIParentFrame)
|
// ---------------------------------------------------------------------------
|
||||||
EVT_MENU(MDI_ABOUT, MyFrame::OnAbout)
|
// MyFrame
|
||||||
EVT_MENU(MDI_NEW_WINDOW, MyFrame::OnNewWindow)
|
// ---------------------------------------------------------------------------
|
||||||
EVT_SIZE(MyFrame::OnSize)
|
|
||||||
EVT_MENU(MDI_QUIT, MyFrame::OnQuit)
|
|
||||||
END_EVENT_TABLE()
|
|
||||||
|
|
||||||
// Define my frame constructor
|
// Define my frame constructor
|
||||||
MyFrame::MyFrame(wxWindow *parent, const wxWindowID id, const wxString& title, const wxPoint& pos, const wxSize& size,
|
MyFrame::MyFrame(wxWindow *parent,
|
||||||
const long style):
|
const wxWindowID id,
|
||||||
wxMDIParentFrame(parent, id, title, pos, size, style)
|
const wxString& title,
|
||||||
|
const wxPoint& pos,
|
||||||
|
const wxSize& size,
|
||||||
|
const long style)
|
||||||
|
: wxMDIParentFrame(parent, id, title, pos, size, style)
|
||||||
{
|
{
|
||||||
textWindow = new wxTextCtrl(this, -1, "", wxDefaultPosition, wxDefaultSize,
|
textWindow = new wxTextCtrl(this, -1, "A help window",
|
||||||
wxTE_MULTILINE|wxSUNKEN_BORDER);
|
wxDefaultPosition, wxDefaultSize,
|
||||||
textWindow->SetValue("A help window");
|
wxTE_MULTILINE | wxSUNKEN_BORDER);
|
||||||
|
|
||||||
CreateToolBar(wxNO_BORDER|wxTB_FLAT|wxTB_HORIZONTAL);
|
CreateToolBar(wxNO_BORDER | wxTB_FLAT | wxTB_HORIZONTAL);
|
||||||
InitToolBar(GetToolBar());
|
InitToolBar(GetToolBar());
|
||||||
|
|
||||||
// Accelerators
|
// Accelerators
|
||||||
@@ -118,26 +167,47 @@ MyFrame::MyFrame(wxWindow *parent, const wxWindowID id, const wxString& title, c
|
|||||||
SetAcceleratorTable(accel);
|
SetAcceleratorTable(accel);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MyFrame::OnQuit(wxCommandEvent& WXUNUSED(event) )
|
void MyFrame::OnClose(wxCloseEvent& event)
|
||||||
{
|
{
|
||||||
Close(TRUE);
|
if ( event.CanVeto() && (gs_nFrames > 0) )
|
||||||
|
{
|
||||||
|
wxString msg;
|
||||||
|
msg.Printf("%d windows still open, close anyhow?", gs_nFrames);
|
||||||
|
if ( wxMessageBox(msg, "Please confirm",
|
||||||
|
wxICON_QUESTION | wxYES_NO) != wxYES )
|
||||||
|
{
|
||||||
|
event.Veto();
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
event.Skip();
|
||||||
|
}
|
||||||
|
|
||||||
|
void MyFrame::OnQuit(wxCommandEvent& WXUNUSED(event))
|
||||||
|
{
|
||||||
|
Close();
|
||||||
}
|
}
|
||||||
|
|
||||||
void MyFrame::OnAbout(wxCommandEvent& WXUNUSED(event) )
|
void MyFrame::OnAbout(wxCommandEvent& WXUNUSED(event) )
|
||||||
{
|
{
|
||||||
(void)wxMessageBox("wxWindows 2.0 MDI Demo\nAuthor: Julian Smart (c) 1997\nUsage: mdi.exe", "About MDI Demo");
|
(void)wxMessageBox("wxWindows 2.0 MDI Demo\n"
|
||||||
|
"Author: Julian Smart (c) 1997\n"
|
||||||
|
"Usage: mdi.exe", "About MDI Demo");
|
||||||
}
|
}
|
||||||
|
|
||||||
void MyFrame::OnNewWindow(wxCommandEvent& WXUNUSED(event) )
|
void MyFrame::OnNewWindow(wxCommandEvent& WXUNUSED(event) )
|
||||||
{
|
{
|
||||||
// Make another frame, containing a canvas
|
// Make another frame, containing a canvas
|
||||||
MyChild *subframe = new MyChild(frame, "Canvas Frame", wxPoint(-1, -1), wxSize(-1, -1),
|
MyChild *subframe = new MyChild(frame, "Canvas Frame",
|
||||||
|
wxPoint(-1, -1), wxSize(-1, -1),
|
||||||
wxDEFAULT_FRAME_STYLE);
|
wxDEFAULT_FRAME_STYLE);
|
||||||
|
|
||||||
wxString title;
|
wxString title;
|
||||||
title.Printf("Canvas Frame %d", winNumber);
|
title.Printf("Canvas Frame %d", ++gs_nFrames);
|
||||||
|
|
||||||
subframe->SetTitle(title);
|
subframe->SetTitle(title);
|
||||||
winNumber ++;
|
|
||||||
|
|
||||||
// Give it an icon
|
// Give it an icon
|
||||||
#ifdef __WXMSW__
|
#ifdef __WXMSW__
|
||||||
@@ -150,7 +220,7 @@ void MyFrame::OnNewWindow(wxCommandEvent& WXUNUSED(event) )
|
|||||||
wxMenu *file_menu = new wxMenu;
|
wxMenu *file_menu = new wxMenu;
|
||||||
|
|
||||||
file_menu->Append(MDI_NEW_WINDOW, "&New window");
|
file_menu->Append(MDI_NEW_WINDOW, "&New window");
|
||||||
file_menu->Append(MDI_CHILD_QUIT, "&Close child");
|
file_menu->Append(MDI_CHILD_QUIT, "&Close child", "Close this window");
|
||||||
file_menu->Append(MDI_QUIT, "&Exit");
|
file_menu->Append(MDI_QUIT, "&Exit");
|
||||||
|
|
||||||
wxMenu *option_menu = new wxMenu;
|
wxMenu *option_menu = new wxMenu;
|
||||||
@@ -179,64 +249,12 @@ void MyFrame::OnNewWindow(wxCommandEvent& WXUNUSED(event) )
|
|||||||
// Give it scrollbars
|
// Give it scrollbars
|
||||||
canvas->SetScrollbars(20, 20, 50, 50);
|
canvas->SetScrollbars(20, 20, 50, 50);
|
||||||
|
|
||||||
|
subframe->CreateStatusBar();
|
||||||
|
subframe->SetStatusText(title);
|
||||||
|
|
||||||
subframe->Show(TRUE);
|
subframe->Show(TRUE);
|
||||||
}
|
}
|
||||||
|
|
||||||
BEGIN_EVENT_TABLE(MyCanvas, wxScrolledWindow)
|
|
||||||
EVT_MOUSE_EVENTS(MyCanvas::OnEvent)
|
|
||||||
END_EVENT_TABLE()
|
|
||||||
|
|
||||||
// Define a constructor for my canvas
|
|
||||||
MyCanvas::MyCanvas(wxWindow *parent, const wxPoint& pos, const wxSize& size):
|
|
||||||
wxScrolledWindow(parent, -1, pos, size, wxSUNKEN_BORDER|wxVSCROLL|wxHSCROLL)
|
|
||||||
{
|
|
||||||
SetBackgroundColour(wxColour("WHITE"));
|
|
||||||
}
|
|
||||||
|
|
||||||
// Define the repainting behaviour
|
|
||||||
void MyCanvas::OnDraw(wxDC& dc)
|
|
||||||
{
|
|
||||||
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);
|
|
||||||
dc.DrawSpline(50, 200, 50, 100, 200, 10);
|
|
||||||
dc.DrawLine(50, 230, 200, 230);
|
|
||||||
dc.DrawText("This is a test string", 50, 230);
|
|
||||||
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
// This implements a tiny doodling program! Drag the mouse using
|
|
||||||
// the left button.
|
|
||||||
void MyCanvas::OnEvent(wxMouseEvent& event)
|
|
||||||
{
|
|
||||||
wxClientDC dc(this);
|
|
||||||
PrepareDC(dc);
|
|
||||||
|
|
||||||
wxPoint pt(event.GetLogicalPosition(dc));
|
|
||||||
|
|
||||||
if (xpos > -1 && ypos > -1 && event.Dragging())
|
|
||||||
{
|
|
||||||
dc.SetPen(*wxBLACK_PEN);
|
|
||||||
dc.DrawLine(xpos, ypos, pt.x, pt.y);
|
|
||||||
}
|
|
||||||
xpos = pt.x;
|
|
||||||
ypos = pt.y;
|
|
||||||
}
|
|
||||||
|
|
||||||
void MyFrame::OnSize(wxSizeEvent& WXUNUSED(event) )
|
void MyFrame::OnSize(wxSizeEvent& WXUNUSED(event) )
|
||||||
{
|
{
|
||||||
int w, h;
|
int w, h;
|
||||||
@@ -246,38 +264,6 @@ void MyFrame::OnSize(wxSizeEvent& WXUNUSED(event) )
|
|||||||
GetClientWindow()->SetSize(200, 0, w - 200, h);
|
GetClientWindow()->SetSize(200, 0, w - 200, h);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Note that MDI_NEW_WINDOW and MDI_ABOUT commands get passed
|
|
||||||
// to the parent window for processing, so no need to
|
|
||||||
// duplicate event handlers here.
|
|
||||||
|
|
||||||
BEGIN_EVENT_TABLE(MyChild, wxMDIChildFrame)
|
|
||||||
EVT_MENU(MDI_CHILD_QUIT, MyChild::OnQuit)
|
|
||||||
END_EVENT_TABLE()
|
|
||||||
|
|
||||||
MyChild::MyChild(wxMDIParentFrame *parent, const wxString& title, const wxPoint& pos, const wxSize& size,
|
|
||||||
const long style):
|
|
||||||
wxMDIChildFrame(parent, -1, title, pos, size, style)
|
|
||||||
{
|
|
||||||
canvas = (MyCanvas *) NULL;
|
|
||||||
my_children.Append(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
MyChild::~MyChild(void)
|
|
||||||
{
|
|
||||||
my_children.DeleteObject(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
void MyChild::OnQuit(wxCommandEvent& WXUNUSED(event))
|
|
||||||
{
|
|
||||||
Close(TRUE);
|
|
||||||
}
|
|
||||||
|
|
||||||
void MyChild::OnActivate(wxActivateEvent& event)
|
|
||||||
{
|
|
||||||
if (event.GetActive() && canvas)
|
|
||||||
canvas->SetFocus();
|
|
||||||
}
|
|
||||||
|
|
||||||
void MyFrame::InitToolBar(wxToolBar* toolBar)
|
void MyFrame::InitToolBar(wxToolBar* toolBar)
|
||||||
{
|
{
|
||||||
wxBitmap* bitmaps[8];
|
wxBitmap* bitmaps[8];
|
||||||
@@ -335,3 +321,117 @@ void MyFrame::InitToolBar(wxToolBar* toolBar)
|
|||||||
delete bitmaps[i];
|
delete bitmaps[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ---------------------------------------------------------------------------
|
||||||
|
// MyCanvas
|
||||||
|
// ---------------------------------------------------------------------------
|
||||||
|
|
||||||
|
// Define a constructor for my canvas
|
||||||
|
MyCanvas::MyCanvas(wxWindow *parent, const wxPoint& pos, const wxSize& size)
|
||||||
|
: wxScrolledWindow(parent, -1, pos, size,
|
||||||
|
wxSUNKEN_BORDER|wxVSCROLL|wxHSCROLL)
|
||||||
|
{
|
||||||
|
SetBackgroundColour(wxColour("WHITE"));
|
||||||
|
|
||||||
|
m_dirty = FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Define the repainting behaviour
|
||||||
|
void MyCanvas::OnDraw(wxDC& dc)
|
||||||
|
{
|
||||||
|
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);
|
||||||
|
dc.DrawSpline(50, 200, 50, 100, 200, 10);
|
||||||
|
dc.DrawLine(50, 230, 200, 230);
|
||||||
|
dc.DrawText("This is a test string", 50, 230);
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
// This implements a tiny doodling program! Drag the mouse using the left
|
||||||
|
// button.
|
||||||
|
void MyCanvas::OnEvent(wxMouseEvent& event)
|
||||||
|
{
|
||||||
|
wxClientDC dc(this);
|
||||||
|
PrepareDC(dc);
|
||||||
|
|
||||||
|
wxPoint pt(event.GetLogicalPosition(dc));
|
||||||
|
|
||||||
|
if (xpos > -1 && ypos > -1 && event.Dragging())
|
||||||
|
{
|
||||||
|
dc.SetPen(*wxBLACK_PEN);
|
||||||
|
dc.DrawLine(xpos, ypos, pt.x, pt.y);
|
||||||
|
|
||||||
|
m_dirty = TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
xpos = pt.x;
|
||||||
|
ypos = pt.y;
|
||||||
|
}
|
||||||
|
|
||||||
|
// ---------------------------------------------------------------------------
|
||||||
|
// MyChild
|
||||||
|
// ---------------------------------------------------------------------------
|
||||||
|
|
||||||
|
MyChild::MyChild(wxMDIParentFrame *parent, const wxString& title,
|
||||||
|
const wxPoint& pos, const wxSize& size,
|
||||||
|
const long style)
|
||||||
|
: wxMDIChildFrame(parent, -1, title, pos, size, style)
|
||||||
|
{
|
||||||
|
canvas = (MyCanvas *) NULL;
|
||||||
|
my_children.Append(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
MyChild::~MyChild()
|
||||||
|
{
|
||||||
|
my_children.DeleteObject(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
void MyChild::OnQuit(wxCommandEvent& WXUNUSED(event))
|
||||||
|
{
|
||||||
|
Close(TRUE);
|
||||||
|
}
|
||||||
|
|
||||||
|
void MyChild::OnRefresh(wxCommandEvent& event)
|
||||||
|
{
|
||||||
|
Refresh();
|
||||||
|
}
|
||||||
|
|
||||||
|
void MyChild::OnActivate(wxActivateEvent& event)
|
||||||
|
{
|
||||||
|
if ( event.GetActive() && canvas )
|
||||||
|
canvas->SetFocus();
|
||||||
|
}
|
||||||
|
|
||||||
|
void MyChild::OnClose(wxCloseEvent& event)
|
||||||
|
{
|
||||||
|
if ( canvas && canvas->IsDirty() )
|
||||||
|
{
|
||||||
|
if ( wxMessageBox("Really close?", "Please confirm",
|
||||||
|
wxICON_QUESTION | wxYES_NO) != wxYES )
|
||||||
|
{
|
||||||
|
event.Veto();
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
gs_nFrames--;
|
||||||
|
|
||||||
|
event.Skip();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@@ -12,29 +12,36 @@
|
|||||||
#include <wx/toolbar.h>
|
#include <wx/toolbar.h>
|
||||||
|
|
||||||
// Define a new application
|
// Define a new application
|
||||||
class MyApp: public wxApp
|
class MyApp : public wxApp
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
bool OnInit(void);
|
bool OnInit();
|
||||||
};
|
};
|
||||||
|
|
||||||
class MyCanvas: public wxScrolledWindow
|
class MyCanvas : public wxScrolledWindow
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
MyCanvas(wxWindow *parent, const wxPoint& pos, const wxSize& size);
|
MyCanvas(wxWindow *parent, const wxPoint& pos, const wxSize& size);
|
||||||
virtual void OnDraw(wxDC& dc);
|
virtual void OnDraw(wxDC& dc);
|
||||||
|
|
||||||
|
bool IsDirty() const { return m_dirty; }
|
||||||
|
|
||||||
void OnEvent(wxMouseEvent& event);
|
void OnEvent(wxMouseEvent& event);
|
||||||
|
|
||||||
|
private:
|
||||||
|
bool m_dirty;
|
||||||
|
|
||||||
DECLARE_EVENT_TABLE()
|
DECLARE_EVENT_TABLE()
|
||||||
};
|
};
|
||||||
|
|
||||||
// Define a new frame
|
// Define a new frame
|
||||||
class MyFrame: public wxMDIParentFrame
|
class MyFrame : public wxMDIParentFrame
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
wxTextCtrl *textWindow;
|
wxTextCtrl *textWindow;
|
||||||
|
|
||||||
MyFrame(wxWindow *parent, const wxWindowID id, const wxString& title, const wxPoint& pos, const wxSize& size, const long style);
|
MyFrame(wxWindow *parent, const wxWindowID id, const wxString& title,
|
||||||
|
const wxPoint& pos, const wxSize& size, const long style);
|
||||||
|
|
||||||
void InitToolBar(wxToolBar* toolBar);
|
void InitToolBar(wxToolBar* toolBar);
|
||||||
|
|
||||||
@@ -42,24 +49,33 @@ class MyFrame: public wxMDIParentFrame
|
|||||||
void OnAbout(wxCommandEvent& event);
|
void OnAbout(wxCommandEvent& event);
|
||||||
void OnNewWindow(wxCommandEvent& event);
|
void OnNewWindow(wxCommandEvent& event);
|
||||||
void OnQuit(wxCommandEvent& event);
|
void OnQuit(wxCommandEvent& event);
|
||||||
|
void OnClose(wxCloseEvent& event);
|
||||||
|
|
||||||
DECLARE_EVENT_TABLE()
|
DECLARE_EVENT_TABLE()
|
||||||
};
|
};
|
||||||
|
|
||||||
class MyChild: public wxMDIChildFrame
|
class MyChild: public wxMDIChildFrame
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
MyCanvas *canvas;
|
MyCanvas *canvas;
|
||||||
MyChild(wxMDIParentFrame *parent, const wxString& title, const wxPoint& pos, const wxSize& size, const long style);
|
MyChild(wxMDIParentFrame *parent, const wxString& title, const wxPoint& pos, const wxSize& size, const long style);
|
||||||
~MyChild(void);
|
~MyChild();
|
||||||
void OnActivate(wxActivateEvent& event);
|
|
||||||
void OnQuit(wxCommandEvent& event);
|
|
||||||
|
|
||||||
DECLARE_EVENT_TABLE()
|
void OnActivate(wxActivateEvent& event);
|
||||||
|
|
||||||
|
void OnRefresh(wxCommandEvent& event);
|
||||||
|
void OnQuit(wxCommandEvent& event);
|
||||||
|
void OnClose(wxCloseEvent& event);
|
||||||
|
|
||||||
|
DECLARE_EVENT_TABLE()
|
||||||
};
|
};
|
||||||
|
|
||||||
#define MDI_QUIT 1
|
// menu items ids
|
||||||
#define MDI_NEW_WINDOW 2
|
enum
|
||||||
#define MDI_REFRESH 3
|
{
|
||||||
#define MDI_CHILD_QUIT 4
|
MDI_QUIT = 100,
|
||||||
#define MDI_ABOUT 5
|
MDI_NEW_WINDOW,
|
||||||
|
MDI_REFRESH,
|
||||||
|
MDI_CHILD_QUIT,
|
||||||
|
MDI_ABOUT
|
||||||
|
};
|
||||||
|
Reference in New Issue
Block a user