1998-05-20 14:01:55 +00:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Name: mdi.cpp
|
|
|
|
// Purpose: MDI sample
|
|
|
|
// Author: Julian Smart
|
|
|
|
// Modified by:
|
|
|
|
// Created: 04/01/98
|
2003-03-17 11:55:54 +00:00
|
|
|
// Copyright: (c) Julian Smart
|
2010-07-13 13:29:13 +00:00
|
|
|
// Licence: wxWindows licence
|
1998-05-20 14:01:55 +00:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2002-01-19 14:50:37 +00:00
|
|
|
#include "wx/toolbar.h"
|
1998-05-27 13:56:59 +00:00
|
|
|
|
1998-05-20 14:01:55 +00:00
|
|
|
// Define a new application
|
1999-05-23 23:45:47 +00:00
|
|
|
class MyApp : public wxApp
|
1998-05-20 14:01:55 +00:00
|
|
|
{
|
1999-05-23 23:45:47 +00:00
|
|
|
public:
|
2014-03-30 00:02:23 +00:00
|
|
|
virtual bool OnInit() wxOVERRIDE;
|
1998-05-20 14:01:55 +00:00
|
|
|
};
|
|
|
|
|
2014-11-11 01:02:31 +00:00
|
|
|
// Helper class logging menu open/close events.
|
|
|
|
class MenuEventLogger
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
MenuEventLogger(const char* label, wxFrame* frame)
|
|
|
|
: m_label(label),
|
|
|
|
m_frame(frame)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
void LogMenuOpenClose(wxMenuEvent& event, const char *action)
|
|
|
|
{
|
|
|
|
event.Skip();
|
|
|
|
|
|
|
|
wxString what;
|
|
|
|
|
|
|
|
wxMenu* const menu = event.GetMenu();
|
|
|
|
if ( menu )
|
2014-12-05 22:17:30 +00:00
|
|
|
what.Printf("Menu \"%s\"", menu->GetTitle());
|
2014-11-11 01:02:31 +00:00
|
|
|
else
|
|
|
|
what = "Unknown menu";
|
|
|
|
|
2014-12-05 22:17:30 +00:00
|
|
|
wxLogMessage(m_frame, "%s %s in %s", what, action, m_label);
|
2014-11-11 01:02:31 +00:00
|
|
|
}
|
|
|
|
|
2014-12-05 22:17:34 +00:00
|
|
|
void LogMenuHighlight(wxMenuEvent& event)
|
|
|
|
{
|
|
|
|
event.Skip();
|
|
|
|
|
|
|
|
wxLogMessage(m_frame, "Item %d selected in %s",
|
|
|
|
event.GetMenuId(), m_label);
|
|
|
|
}
|
|
|
|
|
2014-11-11 01:02:31 +00:00
|
|
|
const wxString m_label;
|
|
|
|
wxFrame* const m_frame;
|
|
|
|
|
|
|
|
wxDECLARE_NO_COPY_CLASS(MenuEventLogger);
|
|
|
|
};
|
|
|
|
|
2014-12-05 22:17:38 +00:00
|
|
|
class MyCanvas : public wxScrolledWindow,
|
|
|
|
private MenuEventLogger
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
MyCanvas(wxFrame *parent, const wxPoint& pos, const wxSize& size);
|
|
|
|
virtual void OnDraw(wxDC& dc) wxOVERRIDE;
|
|
|
|
|
|
|
|
bool IsDirty() const { return m_dirty; }
|
|
|
|
|
|
|
|
void SetText(const wxString& text) { m_text = text; Refresh(); }
|
|
|
|
|
|
|
|
private:
|
|
|
|
void OnMenuOpen(wxMenuEvent& event) { LogMenuOpenClose(event, "opened"); }
|
|
|
|
void OnMenuHighlight(wxMenuEvent& event) { LogMenuHighlight(event); }
|
|
|
|
void OnMenuClose(wxMenuEvent& event) { LogMenuOpenClose(event, "closed"); }
|
|
|
|
|
2016-01-30 20:33:38 +00:00
|
|
|
void OnUpdateUIDisable(wxUpdateUIEvent& event) { event.Enable(false); }
|
|
|
|
|
2014-12-05 22:17:38 +00:00
|
|
|
void OnMenu(wxContextMenuEvent& event);
|
|
|
|
void OnEvent(wxMouseEvent& event);
|
|
|
|
|
|
|
|
wxString m_text;
|
|
|
|
|
|
|
|
bool m_dirty;
|
|
|
|
|
|
|
|
wxDECLARE_EVENT_TABLE();
|
|
|
|
};
|
|
|
|
|
1998-05-20 14:01:55 +00:00
|
|
|
// Define a new frame
|
2014-11-11 01:02:31 +00:00
|
|
|
class MyFrame : public wxMDIParentFrame,
|
|
|
|
private MenuEventLogger
|
1998-05-20 14:01:55 +00:00
|
|
|
{
|
1999-05-23 23:45:47 +00:00
|
|
|
public:
|
2008-11-04 02:46:19 +00:00
|
|
|
MyFrame();
|
|
|
|
virtual ~MyFrame();
|
1998-07-27 09:47:57 +00:00
|
|
|
|
2009-01-28 09:00:49 +00:00
|
|
|
static wxMenuBar *CreateMainMenubar();
|
|
|
|
|
2008-11-04 02:46:19 +00:00
|
|
|
private:
|
1998-07-27 09:47:57 +00:00
|
|
|
void InitToolBar(wxToolBar* toolBar);
|
|
|
|
|
1998-05-20 14:01:55 +00:00
|
|
|
void OnSize(wxSizeEvent& event);
|
|
|
|
void OnAbout(wxCommandEvent& event);
|
|
|
|
void OnNewWindow(wxCommandEvent& event);
|
2009-01-26 23:17:09 +00:00
|
|
|
void OnFullScreen(wxCommandEvent& event);
|
1998-05-20 14:01:55 +00:00
|
|
|
void OnQuit(wxCommandEvent& event);
|
2009-01-27 16:47:41 +00:00
|
|
|
void OnCloseAll(wxCommandEvent& event);
|
|
|
|
|
2014-11-11 01:02:31 +00:00
|
|
|
void OnMenuOpen(wxMenuEvent& event) { LogMenuOpenClose(event, "opened"); }
|
2014-12-05 22:17:34 +00:00
|
|
|
void OnMenuHighlight(wxMenuEvent& event) { LogMenuHighlight(event); }
|
2014-11-11 01:02:31 +00:00
|
|
|
void OnMenuClose(wxMenuEvent& event) { LogMenuOpenClose(event, "closed"); }
|
|
|
|
|
1999-05-23 23:45:47 +00:00
|
|
|
void OnClose(wxCloseEvent& event);
|
1998-05-20 14:01:55 +00:00
|
|
|
|
2008-11-04 02:46:19 +00:00
|
|
|
wxTextCtrl *m_textWindow;
|
|
|
|
|
2014-03-30 07:07:55 +00:00
|
|
|
wxDECLARE_EVENT_TABLE();
|
1998-05-20 14:01:55 +00:00
|
|
|
};
|
|
|
|
|
2014-11-11 01:02:31 +00:00
|
|
|
class MyChild : public wxMDIChildFrame,
|
|
|
|
private MenuEventLogger
|
1998-05-20 14:01:55 +00:00
|
|
|
{
|
1999-05-23 23:45:47 +00:00
|
|
|
public:
|
2008-11-04 02:46:19 +00:00
|
|
|
MyChild(wxMDIParentFrame *parent);
|
|
|
|
virtual ~MyChild();
|
1999-05-23 23:45:47 +00:00
|
|
|
|
2008-11-04 02:46:19 +00:00
|
|
|
static unsigned GetChildrenCount() { return ms_numChildren; }
|
|
|
|
|
|
|
|
private:
|
1998-05-20 14:01:55 +00:00
|
|
|
void OnActivate(wxActivateEvent& event);
|
1999-05-23 23:45:47 +00:00
|
|
|
|
|
|
|
void OnRefresh(wxCommandEvent& event);
|
2000-12-18 15:50:03 +00:00
|
|
|
void OnUpdateRefresh(wxUpdateUIEvent& event);
|
2000-07-15 19:51:35 +00:00
|
|
|
void OnChangeTitle(wxCommandEvent& event);
|
2000-12-18 15:50:03 +00:00
|
|
|
void OnChangePosition(wxCommandEvent& event);
|
|
|
|
void OnChangeSize(wxCommandEvent& event);
|
2008-11-04 02:46:19 +00:00
|
|
|
void OnClose(wxCommandEvent& event);
|
2000-12-18 15:50:03 +00:00
|
|
|
void OnSize(wxSizeEvent& event);
|
|
|
|
void OnMove(wxMoveEvent& event);
|
2014-11-11 01:02:31 +00:00
|
|
|
void OnMenuOpen(wxMenuEvent& event) { LogMenuOpenClose(event, "opened"); }
|
2014-12-05 22:17:34 +00:00
|
|
|
void OnMenuHighlight(wxMenuEvent& event) { LogMenuHighlight(event); }
|
2014-11-11 01:02:31 +00:00
|
|
|
void OnMenuClose(wxMenuEvent& event) { LogMenuOpenClose(event, "closed"); }
|
2016-01-30 20:33:38 +00:00
|
|
|
void OnUpdateUIDisable(wxUpdateUIEvent& event) { event.Enable(false); }
|
2008-11-04 02:46:19 +00:00
|
|
|
void OnCloseWindow(wxCloseEvent& event);
|
1998-05-20 14:01:55 +00:00
|
|
|
|
2006-07-24 13:36:22 +00:00
|
|
|
#if wxUSE_CLIPBOARD
|
|
|
|
void OnPaste(wxCommandEvent& event);
|
|
|
|
void OnUpdatePaste(wxUpdateUIEvent& event);
|
|
|
|
#endif // wxUSE_CLIPBOARD
|
|
|
|
|
2008-11-04 02:46:19 +00:00
|
|
|
static unsigned ms_numChildren;
|
|
|
|
|
|
|
|
MyCanvas *m_canvas;
|
|
|
|
|
2010-05-09 14:55:33 +00:00
|
|
|
// simple test event handler class
|
|
|
|
class EventHandler : public wxEvtHandler
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
EventHandler(unsigned numChild) : m_numChild(numChild) { }
|
|
|
|
|
|
|
|
private:
|
|
|
|
void OnRefresh(wxCommandEvent& event)
|
|
|
|
{
|
|
|
|
wxLogMessage("Child #%u refreshed.", m_numChild);
|
|
|
|
event.Skip();
|
|
|
|
}
|
|
|
|
|
|
|
|
const unsigned m_numChild;
|
|
|
|
|
2014-03-30 07:07:55 +00:00
|
|
|
wxDECLARE_EVENT_TABLE();
|
2010-05-09 14:55:33 +00:00
|
|
|
|
|
|
|
wxDECLARE_NO_COPY_CLASS(EventHandler);
|
|
|
|
};
|
|
|
|
|
2014-03-30 07:07:55 +00:00
|
|
|
wxDECLARE_EVENT_TABLE();
|
1998-05-20 14:01:55 +00:00
|
|
|
};
|
|
|
|
|
1999-05-23 23:45:47 +00:00
|
|
|
// menu items ids
|
|
|
|
enum
|
|
|
|
{
|
2009-03-01 15:03:02 +00:00
|
|
|
MDI_FULLSCREEN = 100,
|
1999-05-23 23:45:47 +00:00
|
|
|
MDI_REFRESH,
|
2016-01-30 20:33:38 +00:00
|
|
|
MDI_DISABLED_FROM_CANVAS,
|
|
|
|
MDI_DISABLED_FROM_CHILD,
|
2000-07-15 19:51:35 +00:00
|
|
|
MDI_CHANGE_TITLE,
|
2000-12-18 15:50:03 +00:00
|
|
|
MDI_CHANGE_POSITION,
|
2008-11-04 02:46:19 +00:00
|
|
|
MDI_CHANGE_SIZE
|
1999-05-23 23:45:47 +00:00
|
|
|
};
|