1998-05-20 10:01:55 -04:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Name: mdi.cpp
|
|
|
|
// Purpose: MDI sample
|
|
|
|
// Author: Julian Smart
|
|
|
|
// Modified by:
|
|
|
|
// Created: 04/01/98
|
|
|
|
// RCS-ID: $Id$
|
2003-03-17 06:55:54 -05:00
|
|
|
// Copyright: (c) Julian Smart
|
1999-05-23 19:45:47 -04:00
|
|
|
// Licence: wxWindows license
|
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"
|
|
|
|
|
|
|
|
#ifdef __BORLANDC__
|
1999-05-23 19:45:47 -04:00
|
|
|
#pragma hdrstop
|
1998-05-20 10:01:55 -04:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#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
|
|
|
|
2003-11-06 13:36:49 -05:00
|
|
|
#if !defined(__WXMSW__)
|
1999-05-23 19:45:47 -04:00
|
|
|
#include "mondrian.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"
|
|
|
|
|
|
|
|
|
1998-05-20 10:01:55 -04:00
|
|
|
#include "mdi.h"
|
|
|
|
|
1999-05-23 19:45:47 -04:00
|
|
|
IMPLEMENT_APP(MyApp)
|
|
|
|
|
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
// global variables
|
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
1998-08-22 23:22:56 -04:00
|
|
|
MyFrame *frame = (MyFrame *) NULL;
|
1998-05-20 10:01:55 -04:00
|
|
|
wxList my_children;
|
|
|
|
|
|
|
|
// For drawing lines in a canvas
|
1999-05-23 19:45:47 -04:00
|
|
|
static long xpos = -1;
|
|
|
|
static long ypos = -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)
|
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
|
|
|
|
|
|
|
EVT_CLOSE(MyChild::OnClose)
|
|
|
|
END_EVENT_TABLE()
|
|
|
|
|
|
|
|
BEGIN_EVENT_TABLE(MyCanvas, wxScrolledWindow)
|
|
|
|
EVT_MOUSE_EVENTS(MyCanvas::OnEvent)
|
|
|
|
END_EVENT_TABLE()
|
|
|
|
|
|
|
|
// ===========================================================================
|
|
|
|
// 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
|
|
|
{
|
1999-05-23 19:45:47 -04:00
|
|
|
// Create the main frame window
|
1998-05-20 10:01:55 -04:00
|
|
|
|
2004-06-01 12:09:27 -04:00
|
|
|
frame = new MyFrame((wxFrame *)NULL, wxID_ANY, _T("MDI Demo"),
|
|
|
|
wxDefaultPosition, wxSize(500, 400),
|
1999-05-23 19:45:47 -04:00
|
|
|
wxDEFAULT_FRAME_STYLE | wxHSCROLL | wxVSCROLL);
|
2000-02-01 10:48:44 -05:00
|
|
|
#ifdef __WXMSW__
|
|
|
|
#if 0
|
|
|
|
// Experimental: change the window menu
|
|
|
|
wxMenu* windowMenu = new wxMenu;
|
2002-12-15 05:23:11 -05:00
|
|
|
windowMenu->Append(5000, _T("My menu item!"));
|
2000-02-01 10:48:44 -05:00
|
|
|
frame->SetWindowMenu(windowMenu);
|
|
|
|
#endif
|
|
|
|
#endif
|
1998-05-20 10:01:55 -04:00
|
|
|
|
1999-05-23 19:45:47 -04:00
|
|
|
// Give it an icon
|
1998-07-10 10:15:17 -04:00
|
|
|
#ifdef __WXMSW__
|
2002-12-15 05:23:11 -05:00
|
|
|
frame->SetIcon(wxIcon(_T("mdi_icn")));
|
1998-08-17 10:29:53 -04:00
|
|
|
#else
|
1999-05-23 19:45:47 -04:00
|
|
|
frame->SetIcon(wxIcon( mondrian_xpm ));
|
1998-05-20 10:01:55 -04:00
|
|
|
#endif
|
|
|
|
|
1999-05-23 19:45:47 -04:00
|
|
|
// Make a menubar
|
|
|
|
wxMenu *file_menu = new wxMenu;
|
1998-05-20 10:01:55 -04:00
|
|
|
|
2002-12-15 05:23:11 -05:00
|
|
|
file_menu->Append(MDI_NEW_WINDOW, _T("&New window\tCtrl-N"), _T("Create a new child window"));
|
|
|
|
file_menu->Append(MDI_QUIT, _T("&Exit\tAlt-X"), _T("Quit the program"));
|
1998-05-20 10:01:55 -04:00
|
|
|
|
1999-05-23 19:45:47 -04:00
|
|
|
wxMenu *help_menu = new wxMenu;
|
2002-12-15 05:23:11 -05:00
|
|
|
help_menu->Append(MDI_ABOUT, _T("&About\tF1"));
|
1998-05-20 10:01:55 -04:00
|
|
|
|
1999-05-23 19:45:47 -04:00
|
|
|
wxMenuBar *menu_bar = new wxMenuBar;
|
1998-05-20 10:01:55 -04:00
|
|
|
|
2002-12-15 05:23:11 -05:00
|
|
|
menu_bar->Append(file_menu, _T("&File"));
|
|
|
|
menu_bar->Append(help_menu, _T("&Help"));
|
1998-05-20 10:01:55 -04:00
|
|
|
|
1999-05-23 19:45:47 -04:00
|
|
|
// Associate the menu bar with the frame
|
|
|
|
frame->SetMenuBar(menu_bar);
|
1998-05-20 10:01:55 -04:00
|
|
|
|
2004-07-19 11:36:01 -04:00
|
|
|
#if wxUSE_STATUSBAR
|
1999-05-23 19:45:47 -04:00
|
|
|
frame->CreateStatusBar();
|
2004-07-19 11:36:01 -04:00
|
|
|
#endif // wxUSE_STATUSBAR
|
1998-05-20 10:01:55 -04:00
|
|
|
|
2004-06-01 12:09:27 -04:00
|
|
|
frame->Show(true);
|
1998-05-20 10:01:55 -04:00
|
|
|
|
1999-05-23 19:45:47 -04:00
|
|
|
SetTopWindow(frame);
|
1998-05-20 10:01:55 -04:00
|
|
|
|
2004-06-01 12:09:27 -04:00
|
|
|
return true;
|
1998-05-20 10:01:55 -04:00
|
|
|
}
|
|
|
|
|
1999-05-23 19:45:47 -04:00
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
// MyFrame
|
|
|
|
// ---------------------------------------------------------------------------
|
1998-05-20 10:01:55 -04:00
|
|
|
|
|
|
|
// Define my frame constructor
|
1999-05-23 19:45:47 -04:00
|
|
|
MyFrame::MyFrame(wxWindow *parent,
|
|
|
|
const wxWindowID id,
|
|
|
|
const wxString& title,
|
|
|
|
const wxPoint& pos,
|
|
|
|
const wxSize& size,
|
|
|
|
const long style)
|
2001-06-15 21:36:35 -04:00
|
|
|
: wxMDIParentFrame(parent, id, title, pos, size,
|
|
|
|
style | wxNO_FULL_REPAINT_ON_RESIZE)
|
1998-05-20 10:01:55 -04:00
|
|
|
{
|
2004-06-01 12:09:27 -04:00
|
|
|
textWindow = new wxTextCtrl(this, wxID_ANY, _T("A help window"),
|
1999-05-23 19:45:47 -04:00
|
|
|
wxDefaultPosition, wxDefaultSize,
|
|
|
|
wxTE_MULTILINE | wxSUNKEN_BORDER);
|
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];
|
|
|
|
entries[0].Set(wxACCEL_CTRL, (int) 'N', MDI_NEW_WINDOW);
|
|
|
|
entries[1].Set(wxACCEL_CTRL, (int) 'X', MDI_QUIT);
|
|
|
|
entries[2].Set(wxACCEL_CTRL, (int) 'A', MDI_ABOUT);
|
|
|
|
wxAcceleratorTable accel(3, entries);
|
|
|
|
SetAcceleratorTable(accel);
|
2006-01-16 11:05:58 -05:00
|
|
|
#endif // wxUSE_ACCEL
|
1998-05-20 10:01:55 -04:00
|
|
|
}
|
|
|
|
|
1999-05-23 19:45:47 -04:00
|
|
|
void MyFrame::OnClose(wxCloseEvent& event)
|
|
|
|
{
|
|
|
|
if ( event.CanVeto() && (gs_nFrames > 0) )
|
|
|
|
{
|
|
|
|
wxString msg;
|
1999-05-30 12:20:42 -04:00
|
|
|
msg.Printf(_T("%d windows still open, close anyhow?"), gs_nFrames);
|
2002-12-15 05:23:11 -05:00
|
|
|
if ( wxMessageBox(msg, _T("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
|
|
|
{
|
2004-05-25 07:20:37 -04:00
|
|
|
(void)wxMessageBox(_T("wxWidgets 2.0 MDI Demo\n")
|
2002-12-15 05:23:11 -05:00
|
|
|
_T("Author: Julian Smart (c) 1997\n")
|
|
|
|
_T("Usage: mdi.exe"), _T("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
|
|
|
{
|
1999-05-23 19:45:47 -04:00
|
|
|
// Make another frame, containing a canvas
|
2004-06-01 12:09:27 -04:00
|
|
|
MyChild *subframe = new MyChild(frame, _T("Canvas Frame"));
|
1998-05-20 10:01:55 -04:00
|
|
|
|
1999-05-23 19:45:47 -04:00
|
|
|
wxString title;
|
1999-05-30 12:20:42 -04:00
|
|
|
title.Printf(_T("Canvas Frame %d"), ++gs_nFrames);
|
1998-05-20 10:01:55 -04:00
|
|
|
|
1999-05-23 19:45:47 -04:00
|
|
|
subframe->SetTitle(title);
|
|
|
|
|
|
|
|
// Give it an icon
|
1998-07-10 10:15:17 -04:00
|
|
|
#ifdef __WXMSW__
|
2002-12-15 05:23:11 -05:00
|
|
|
subframe->SetIcon(wxIcon(_T("chrt_icn")));
|
1998-10-19 17:51:15 -04:00
|
|
|
#else
|
1999-05-23 19:45:47 -04:00
|
|
|
subframe->SetIcon(wxIcon( mondrian_xpm ));
|
1998-05-20 10:01:55 -04:00
|
|
|
#endif
|
|
|
|
|
2006-01-06 20:12:49 -05:00
|
|
|
#if wxUSE_MENUS
|
1999-05-23 19:45:47 -04:00
|
|
|
// Make a menubar
|
|
|
|
wxMenu *file_menu = new wxMenu;
|
|
|
|
|
2002-12-15 05:23:11 -05:00
|
|
|
file_menu->Append(MDI_NEW_WINDOW, _T("&New window"));
|
|
|
|
file_menu->Append(MDI_CHILD_QUIT, _T("&Close child"), _T("Close this window"));
|
|
|
|
file_menu->Append(MDI_QUIT, _T("&Exit"));
|
1998-05-20 10:01:55 -04:00
|
|
|
|
1999-05-23 19:45:47 -04:00
|
|
|
wxMenu *option_menu = new wxMenu;
|
1998-05-20 10:01:55 -04:00
|
|
|
|
2002-12-15 05:23:11 -05:00
|
|
|
option_menu->Append(MDI_REFRESH, _T("&Refresh picture"));
|
|
|
|
option_menu->Append(MDI_CHANGE_TITLE, _T("Change &title...\tCtrl-T"));
|
2000-12-18 10:50:03 -05:00
|
|
|
option_menu->AppendSeparator();
|
2002-12-15 05:23:11 -05:00
|
|
|
option_menu->Append(MDI_CHANGE_POSITION, _T("Move frame\tCtrl-M"));
|
|
|
|
option_menu->Append(MDI_CHANGE_SIZE, _T("Resize frame\tCtrl-S"));
|
2006-07-24 09:36:22 -04:00
|
|
|
#if wxUSE_CLIPBOARD
|
|
|
|
option_menu->AppendSeparator();
|
|
|
|
option_menu->Append(wxID_PASTE, _T("Copy text from clipboard\tCtrl-V"));
|
|
|
|
#endif // wxUSE_CLIPBOARD
|
1998-05-20 10:01:55 -04:00
|
|
|
|
1999-05-23 19:45:47 -04:00
|
|
|
wxMenu *help_menu = new wxMenu;
|
2002-12-15 05:23:11 -05:00
|
|
|
help_menu->Append(MDI_ABOUT, _T("&About"));
|
1998-05-20 10:01:55 -04:00
|
|
|
|
1999-05-23 19:45:47 -04:00
|
|
|
wxMenuBar *menu_bar = new wxMenuBar;
|
1998-05-20 10:01:55 -04:00
|
|
|
|
2002-12-15 05:23:11 -05:00
|
|
|
menu_bar->Append(file_menu, _T("&File"));
|
|
|
|
menu_bar->Append(option_menu, _T("&Child"));
|
|
|
|
menu_bar->Append(help_menu, _T("&Help"));
|
1998-05-20 10:01:55 -04:00
|
|
|
|
1999-05-23 19:45:47 -04:00
|
|
|
// Associate the menu bar with the frame
|
|
|
|
subframe->SetMenuBar(menu_bar);
|
2006-01-06 20:12:49 -05:00
|
|
|
#endif // wxUSE_MENUS
|
1998-05-20 10:01:55 -04:00
|
|
|
|
2004-07-19 11:36:01 -04:00
|
|
|
#if wxUSE_STATUSBAR
|
2000-02-24 18:40:42 -05:00
|
|
|
subframe->CreateStatusBar();
|
|
|
|
subframe->SetStatusText(title);
|
2004-07-19 11:36:01 -04:00
|
|
|
#endif // wxUSE_STATUSBAR
|
2000-02-24 18:40:42 -05:00
|
|
|
|
1999-05-23 19:45:47 -04:00
|
|
|
int width, height;
|
|
|
|
subframe->GetClientSize(&width, &height);
|
|
|
|
MyCanvas *canvas = new MyCanvas(subframe, wxPoint(0, 0), wxSize(width, height));
|
|
|
|
canvas->SetCursor(wxCursor(wxCURSOR_PENCIL));
|
|
|
|
subframe->canvas = canvas;
|
1998-05-20 10:01:55 -04:00
|
|
|
|
1999-05-23 19:45:47 -04:00
|
|
|
// Give it scrollbars
|
|
|
|
canvas->SetScrollbars(20, 20, 50, 50);
|
1998-05-20 10:01:55 -04:00
|
|
|
|
2004-06-01 12:09:27 -04:00
|
|
|
subframe->Show(true);
|
1998-05-20 10:01:55 -04:00
|
|
|
}
|
|
|
|
|
2006-01-16 11:05:58 -05:00
|
|
|
void MyFrame::OnSize(wxSizeEvent&
|
2003-09-11 03:18:26 -04:00
|
|
|
#ifdef __WXUNIVERSAL__
|
|
|
|
event
|
|
|
|
#else
|
|
|
|
WXUNUSED(event)
|
|
|
|
#endif
|
|
|
|
)
|
1999-05-23 19:45:47 -04:00
|
|
|
{
|
|
|
|
int w, h;
|
|
|
|
GetClientSize(&w, &h);
|
|
|
|
|
|
|
|
textWindow->SetSize(0, 0, 200, h);
|
|
|
|
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();
|
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)
|
|
|
|
{
|
|
|
|
wxBitmap* bitmaps[8];
|
|
|
|
|
|
|
|
bitmaps[0] = new wxBitmap( new_xpm );
|
|
|
|
bitmaps[1] = new wxBitmap( open_xpm );
|
|
|
|
bitmaps[2] = new wxBitmap( save_xpm );
|
|
|
|
bitmaps[3] = new wxBitmap( copy_xpm );
|
|
|
|
bitmaps[4] = new wxBitmap( cut_xpm );
|
|
|
|
bitmaps[5] = new wxBitmap( paste_xpm );
|
|
|
|
bitmaps[6] = new wxBitmap( print_xpm );
|
|
|
|
bitmaps[7] = new wxBitmap( help_xpm );
|
|
|
|
|
|
|
|
int width = 24;
|
|
|
|
int currentX = 5;
|
|
|
|
|
2004-07-20 06:09:47 -04:00
|
|
|
toolBar->AddTool( MDI_NEW_WINDOW, *(bitmaps[0]), wxNullBitmap, false, currentX, wxDefaultCoord, (wxObject *) NULL, _T("New file"));
|
1999-05-23 19:45:47 -04:00
|
|
|
currentX += width + 5;
|
2004-07-20 06:09:47 -04:00
|
|
|
toolBar->AddTool(1, *bitmaps[1], wxNullBitmap, false, currentX, wxDefaultCoord, (wxObject *) NULL, _T("Open file"));
|
1999-05-23 19:45:47 -04:00
|
|
|
currentX += width + 5;
|
2004-07-20 06:09:47 -04:00
|
|
|
toolBar->AddTool(2, *bitmaps[2], wxNullBitmap, false, currentX, wxDefaultCoord, (wxObject *) NULL, _T("Save file"));
|
1999-05-23 19:45:47 -04:00
|
|
|
currentX += width + 5;
|
|
|
|
toolBar->AddSeparator();
|
2004-07-20 06:09:47 -04:00
|
|
|
toolBar->AddTool(3, *bitmaps[3], wxNullBitmap, false, currentX, wxDefaultCoord, (wxObject *) NULL, _T("Copy"));
|
1999-05-23 19:45:47 -04:00
|
|
|
currentX += width + 5;
|
2004-07-20 06:09:47 -04:00
|
|
|
toolBar->AddTool(4, *bitmaps[4], wxNullBitmap, false, currentX, wxDefaultCoord, (wxObject *) NULL, _T("Cut"));
|
1999-05-23 19:45:47 -04:00
|
|
|
currentX += width + 5;
|
2004-07-20 06:09:47 -04:00
|
|
|
toolBar->AddTool(5, *bitmaps[5], wxNullBitmap, false, currentX, wxDefaultCoord, (wxObject *) NULL, _T("Paste"));
|
1999-05-23 19:45:47 -04:00
|
|
|
currentX += width + 5;
|
|
|
|
toolBar->AddSeparator();
|
2004-07-20 06:09:47 -04:00
|
|
|
toolBar->AddTool(6, *bitmaps[6], wxNullBitmap, false, currentX, wxDefaultCoord, (wxObject *) NULL, _T("Print"));
|
1999-05-23 19:45:47 -04:00
|
|
|
currentX += width + 5;
|
|
|
|
toolBar->AddSeparator();
|
2004-07-20 06:09:47 -04:00
|
|
|
toolBar->AddTool( MDI_ABOUT, *bitmaps[7], wxNullBitmap, true, currentX, wxDefaultCoord, (wxObject *) NULL, _T("Help"));
|
1999-05-23 19:45:47 -04:00
|
|
|
|
|
|
|
toolBar->Realize();
|
|
|
|
|
|
|
|
int i;
|
|
|
|
for (i = 0; i < 8; i++)
|
|
|
|
delete bitmaps[i];
|
|
|
|
}
|
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
|
1999-05-23 19:45:47 -04:00
|
|
|
MyCanvas::MyCanvas(wxWindow *parent, const wxPoint& pos, const wxSize& size)
|
2004-06-01 12:09:27 -04:00
|
|
|
: wxScrolledWindow(parent, wxID_ANY, pos, size,
|
2001-06-15 21:36:35 -04:00
|
|
|
wxSUNKEN_BORDER |
|
|
|
|
wxNO_FULL_REPAINT_ON_RESIZE |
|
|
|
|
wxVSCROLL | wxHSCROLL)
|
1998-05-20 10:01:55 -04:00
|
|
|
{
|
2002-12-15 05:23:11 -05:00
|
|
|
SetBackgroundColour(wxColour(_T("WHITE")));
|
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);
|
2002-12-15 05:23:11 -05:00
|
|
|
dc.DrawText(_T("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
|
|
|
|
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
|
|
|
}
|
1998-05-20 10:01:55 -04:00
|
|
|
|
1999-05-23 19:45:47 -04:00
|
|
|
xpos = pt.x;
|
|
|
|
ypos = pt.y;
|
|
|
|
}
|
|
|
|
|
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
// MyChild
|
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
2004-06-01 12:09:27 -04:00
|
|
|
MyChild::MyChild(wxMDIParentFrame *parent, const wxString& title)
|
|
|
|
: wxMDIChildFrame(parent, wxID_ANY, title, wxDefaultPosition, wxDefaultSize,
|
|
|
|
wxDEFAULT_FRAME_STYLE | wxNO_FULL_REPAINT_ON_RESIZE)
|
1998-05-20 10:01:55 -04:00
|
|
|
{
|
1999-05-23 19:45:47 -04:00
|
|
|
canvas = (MyCanvas *) NULL;
|
|
|
|
my_children.Append(this);
|
2001-06-15 21:36:35 -04:00
|
|
|
|
|
|
|
// this should work for MDI frames as well as for normal ones
|
|
|
|
SetSizeHints(100, 100);
|
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
|
|
|
{
|
1999-05-23 19:45:47 -04:00
|
|
|
my_children.DeleteObject(this);
|
1998-05-20 10:01:55 -04:00
|
|
|
}
|
|
|
|
|
1998-07-13 19:30:59 -04:00
|
|
|
void MyChild::OnQuit(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))
|
|
|
|
{
|
|
|
|
if ( canvas )
|
|
|
|
canvas->Refresh();
|
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
2002-12-04 09:11:26 -05:00
|
|
|
//#if wxUSE_TEXTDLG
|
2000-07-15 15:51:35 -04:00
|
|
|
static wxString s_title = _T("Canvas Frame");
|
|
|
|
|
|
|
|
wxString title = wxGetTextFromUser(_T("Enter the new title for MDI child"),
|
|
|
|
_T("MDI sample question"),
|
|
|
|
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);
|
2002-12-04 09:11:26 -05:00
|
|
|
//#endif
|
1998-05-20 10:01:55 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void MyChild::OnActivate(wxActivateEvent& event)
|
|
|
|
{
|
1999-05-23 19:45:47 -04:00
|
|
|
if ( event.GetActive() && canvas )
|
|
|
|
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();
|
2001-09-21 16:21:44 -04:00
|
|
|
wxLogStatus(wxT("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();
|
2001-09-21 16:21:44 -04:00
|
|
|
wxLogStatus(wxT("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();
|
|
|
|
}
|
|
|
|
|
1999-05-23 19:45:47 -04:00
|
|
|
void MyChild::OnClose(wxCloseEvent& event)
|
1998-05-20 10:01:55 -04:00
|
|
|
{
|
1999-05-23 19:45:47 -04:00
|
|
|
if ( canvas && canvas->IsDirty() )
|
|
|
|
{
|
2002-12-15 05:23:11 -05:00
|
|
|
if ( wxMessageBox(_T("Really close?"), _T("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
|
|
|
gs_nFrames--;
|
|
|
|
|
|
|
|
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;
|
2006-07-25 02:48:03 -04:00
|
|
|
canvas->SetText(wxTheClipboard->GetData(data) ? data.GetText().c_str()
|
2006-07-24 09:36:22 -04:00
|
|
|
: _T("No text on clipboard"));
|
|
|
|
}
|
|
|
|
|
|
|
|
void MyChild::OnUpdatePaste(wxUpdateUIEvent& event)
|
|
|
|
{
|
|
|
|
wxClipboardLocker lock;
|
|
|
|
event.Enable( wxTheClipboard->IsSupported(wxDF_TEXT) );
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif // wxUSE_CLIPBOARD
|