no changes, just some cleanup (patch 1918720)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@53042 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -39,7 +39,7 @@ IMPLEMENT_DYNAMIC_CLASS(DrawingDocument, wxDocument)
|
||||
|
||||
DrawingDocument::~DrawingDocument(void)
|
||||
{
|
||||
WX_CLEAR_LIST(wxList, doodleSegments);
|
||||
WX_CLEAR_LIST(wxList, m_doodleSegments)
|
||||
}
|
||||
|
||||
#if wxUSE_STD_IOSTREAM
|
||||
@@ -47,10 +47,10 @@ wxSTD ostream& DrawingDocument::SaveObject(wxSTD ostream& stream)
|
||||
{
|
||||
wxDocument::SaveObject(stream);
|
||||
|
||||
wxInt32 n = doodleSegments.GetCount();
|
||||
wxInt32 n = m_doodleSegments.GetCount();
|
||||
stream << n << '\n';
|
||||
|
||||
wxList::compatibility_iterator node = doodleSegments.GetFirst();
|
||||
wxList::compatibility_iterator node = m_doodleSegments.GetFirst();
|
||||
while (node)
|
||||
{
|
||||
DoodleSegment *segment = (DoodleSegment *)node->GetData();
|
||||
@@ -69,10 +69,10 @@ wxOutputStream& DrawingDocument::SaveObject(wxOutputStream& stream)
|
||||
|
||||
wxTextOutputStream text_stream( stream );
|
||||
|
||||
wxInt32 n = doodleSegments.GetCount();
|
||||
wxInt32 n = m_doodleSegments.GetCount();
|
||||
text_stream << n << '\n';
|
||||
|
||||
wxList::compatibility_iterator node = doodleSegments.GetFirst();
|
||||
wxList::compatibility_iterator node = m_doodleSegments.GetFirst();
|
||||
while (node)
|
||||
{
|
||||
DoodleSegment *segment = (DoodleSegment *)node->GetData();
|
||||
@@ -98,7 +98,7 @@ wxSTD istream& DrawingDocument::LoadObject(wxSTD istream& stream)
|
||||
{
|
||||
DoodleSegment *segment = new DoodleSegment;
|
||||
segment->LoadObject(stream);
|
||||
doodleSegments.Append(segment);
|
||||
m_doodleSegments.Append(segment);
|
||||
}
|
||||
|
||||
return stream;
|
||||
@@ -117,7 +117,7 @@ wxInputStream& DrawingDocument::LoadObject(wxInputStream& stream)
|
||||
{
|
||||
DoodleSegment *segment = new DoodleSegment;
|
||||
segment->LoadObject(stream);
|
||||
doodleSegments.Append(segment);
|
||||
m_doodleSegments.Append(segment);
|
||||
}
|
||||
|
||||
return stream;
|
||||
@@ -126,7 +126,7 @@ wxInputStream& DrawingDocument::LoadObject(wxInputStream& stream)
|
||||
|
||||
DoodleSegment::DoodleSegment(const DoodleSegment& seg):wxObject()
|
||||
{
|
||||
wxList::compatibility_iterator node = seg.lines.GetFirst();
|
||||
wxList::compatibility_iterator node = seg.m_lines.GetFirst();
|
||||
while (node)
|
||||
{
|
||||
DoodleLine *line = (DoodleLine *)node->GetData();
|
||||
@@ -136,7 +136,7 @@ DoodleSegment::DoodleSegment(const DoodleSegment& seg):wxObject()
|
||||
newLine->x2 = line->x2;
|
||||
newLine->y2 = line->y2;
|
||||
|
||||
lines.Append(newLine);
|
||||
m_lines.Append(newLine);
|
||||
|
||||
node = node->GetNext();
|
||||
}
|
||||
@@ -144,16 +144,16 @@ DoodleSegment::DoodleSegment(const DoodleSegment& seg):wxObject()
|
||||
|
||||
DoodleSegment::~DoodleSegment(void)
|
||||
{
|
||||
WX_CLEAR_LIST(wxList, lines);
|
||||
WX_CLEAR_LIST(wxList, m_lines)
|
||||
}
|
||||
|
||||
#if wxUSE_STD_IOSTREAM
|
||||
wxSTD ostream& DoodleSegment::SaveObject(wxSTD ostream& stream)
|
||||
{
|
||||
wxInt32 n = lines.GetCount();
|
||||
wxInt32 n = m_lines.GetCount();
|
||||
stream << n << '\n';
|
||||
|
||||
wxList::compatibility_iterator node = lines.GetFirst();
|
||||
wxList::compatibility_iterator node = m_lines.GetFirst();
|
||||
while (node)
|
||||
{
|
||||
DoodleLine *line = (DoodleLine *)node->GetData();
|
||||
@@ -171,17 +171,17 @@ wxOutputStream &DoodleSegment::SaveObject(wxOutputStream& stream)
|
||||
{
|
||||
wxTextOutputStream text_stream( stream );
|
||||
|
||||
wxInt32 n = lines.GetCount();
|
||||
text_stream << n << _T("\n");
|
||||
wxInt32 n = m_lines.GetCount();
|
||||
text_stream << n << wxT("\n");
|
||||
|
||||
wxList::compatibility_iterator node = lines.GetFirst();
|
||||
wxList::compatibility_iterator node = m_lines.GetFirst();
|
||||
while (node)
|
||||
{
|
||||
DoodleLine* line = (DoodleLine*)node->GetData();
|
||||
text_stream << line->x1 << _T(" ") <<
|
||||
line->y1 << _T(" ") <<
|
||||
line->x2 << _T(" ") <<
|
||||
line->y2 << _T("\n");
|
||||
text_stream << line->x1 << wxT(" ") <<
|
||||
line->y1 << wxT(" ") <<
|
||||
line->x2 << wxT(" ") <<
|
||||
line->y2 << wxT("\n");
|
||||
node = node->GetNext();
|
||||
}
|
||||
|
||||
@@ -202,7 +202,7 @@ wxSTD istream& DoodleSegment::LoadObject(wxSTD istream& stream)
|
||||
line->y1 >>
|
||||
line->x2 >>
|
||||
line->y2;
|
||||
lines.Append(line);
|
||||
m_lines.Append(line);
|
||||
}
|
||||
|
||||
return stream;
|
||||
@@ -222,7 +222,7 @@ wxInputStream &DoodleSegment::LoadObject(wxInputStream& stream)
|
||||
line->y1 >>
|
||||
line->x2 >>
|
||||
line->y2;
|
||||
lines.Append(line);
|
||||
m_lines.Append(line);
|
||||
}
|
||||
|
||||
return stream;
|
||||
@@ -231,7 +231,7 @@ wxInputStream &DoodleSegment::LoadObject(wxInputStream& stream)
|
||||
|
||||
void DoodleSegment::Draw(wxDC *dc)
|
||||
{
|
||||
wxList::compatibility_iterator node = lines.GetFirst();
|
||||
wxList::compatibility_iterator node = m_lines.GetFirst();
|
||||
while (node)
|
||||
{
|
||||
DoodleLine *line = (DoodleLine *)node->GetData();
|
||||
@@ -244,46 +244,46 @@ void DoodleSegment::Draw(wxDC *dc)
|
||||
* Implementation of drawing command
|
||||
*/
|
||||
|
||||
DrawingCommand::DrawingCommand(const wxString& name, int command, DrawingDocument *ddoc, DoodleSegment *seg):
|
||||
DrawingCommand::DrawingCommand(const wxString& name, int command, DrawingDocument* doc, DoodleSegment* seg) :
|
||||
wxCommand(true, name)
|
||||
{
|
||||
doc = ddoc;
|
||||
segment = seg;
|
||||
cmd = command;
|
||||
m_doc = doc;
|
||||
m_segment = seg;
|
||||
m_cmd = command;
|
||||
}
|
||||
|
||||
DrawingCommand::~DrawingCommand(void)
|
||||
{
|
||||
if (segment)
|
||||
delete segment;
|
||||
if (m_segment)
|
||||
delete m_segment;
|
||||
}
|
||||
|
||||
bool DrawingCommand::Do(void)
|
||||
{
|
||||
switch (cmd)
|
||||
switch (m_cmd)
|
||||
{
|
||||
case DOODLE_CUT:
|
||||
{
|
||||
// Cut the last segment
|
||||
if (doc->GetDoodleSegments().GetCount() > 0)
|
||||
if (m_doc->GetDoodleSegments().GetCount() > 0)
|
||||
{
|
||||
wxList::compatibility_iterator node = doc->GetDoodleSegments().GetLast();
|
||||
if (segment)
|
||||
delete segment;
|
||||
wxList::compatibility_iterator node = m_doc->GetDoodleSegments().GetLast();
|
||||
if (m_segment)
|
||||
delete m_segment;
|
||||
|
||||
segment = (DoodleSegment *)node->GetData();
|
||||
doc->GetDoodleSegments().Erase(node);
|
||||
m_segment = (DoodleSegment*)node->GetData();
|
||||
m_doc->GetDoodleSegments().Erase(node);
|
||||
|
||||
doc->Modify(true);
|
||||
doc->UpdateAllViews();
|
||||
m_doc->Modify(true);
|
||||
m_doc->UpdateAllViews();
|
||||
}
|
||||
break;
|
||||
}
|
||||
case DOODLE_ADD:
|
||||
{
|
||||
doc->GetDoodleSegments().Append(new DoodleSegment(*segment));
|
||||
doc->Modify(true);
|
||||
doc->UpdateAllViews();
|
||||
m_doc->GetDoodleSegments().Append(new DoodleSegment(*m_segment));
|
||||
m_doc->Modify(true);
|
||||
m_doc->UpdateAllViews();
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -292,34 +292,34 @@ bool DrawingCommand::Do(void)
|
||||
|
||||
bool DrawingCommand::Undo(void)
|
||||
{
|
||||
switch (cmd)
|
||||
switch (m_cmd)
|
||||
{
|
||||
case DOODLE_CUT:
|
||||
{
|
||||
// Paste the segment
|
||||
if (segment)
|
||||
if (m_segment)
|
||||
{
|
||||
doc->GetDoodleSegments().Append(segment);
|
||||
doc->Modify(true);
|
||||
doc->UpdateAllViews();
|
||||
segment = (DoodleSegment *) NULL;
|
||||
m_doc->GetDoodleSegments().Append(m_segment);
|
||||
m_doc->Modify(true);
|
||||
m_doc->UpdateAllViews();
|
||||
m_segment = NULL;
|
||||
}
|
||||
doc->Modify(true);
|
||||
doc->UpdateAllViews();
|
||||
m_doc->Modify(true);
|
||||
m_doc->UpdateAllViews();
|
||||
break;
|
||||
}
|
||||
case DOODLE_ADD:
|
||||
{
|
||||
// Cut the last segment
|
||||
if (doc->GetDoodleSegments().GetCount() > 0)
|
||||
if (m_doc->GetDoodleSegments().GetCount() > 0)
|
||||
{
|
||||
wxList::compatibility_iterator node = doc->GetDoodleSegments().GetLast();
|
||||
wxList::compatibility_iterator node = m_doc->GetDoodleSegments().GetLast();
|
||||
DoodleSegment* seg = (DoodleSegment*)node->GetData();
|
||||
delete seg;
|
||||
doc->GetDoodleSegments().Erase(node);
|
||||
m_doc->GetDoodleSegments().Erase(node);
|
||||
|
||||
doc->Modify(true);
|
||||
doc->UpdateAllViews();
|
||||
m_doc->Modify(true);
|
||||
m_doc->UpdateAllViews();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -332,9 +332,9 @@ IMPLEMENT_DYNAMIC_CLASS(TextEditDocument, wxDocument)
|
||||
// we override OnSave/OpenDocument instead of Save/LoadObject
|
||||
bool TextEditDocument::OnSaveDocument(const wxString& filename)
|
||||
{
|
||||
TextEditView *view = (TextEditView *)GetFirstView();
|
||||
TextEditView* view = GetFirstView();
|
||||
|
||||
if (!view->textsw->SaveFile(filename))
|
||||
if (!view->m_textsw->SaveFile(filename))
|
||||
return false;
|
||||
Modify(false);
|
||||
#ifdef __WXMAC__
|
||||
@@ -346,8 +346,8 @@ bool TextEditDocument::OnSaveDocument(const wxString& filename)
|
||||
|
||||
bool TextEditDocument::OnOpenDocument(const wxString& filename)
|
||||
{
|
||||
TextEditView *view = (TextEditView *)GetFirstView();
|
||||
if (!view->textsw->LoadFile(filename))
|
||||
TextEditView* view = GetFirstView();
|
||||
if (!view->m_textsw->LoadFile(filename))
|
||||
return false;
|
||||
|
||||
SetFilename(filename, true);
|
||||
@@ -358,21 +358,23 @@ bool TextEditDocument::OnOpenDocument(const wxString& filename)
|
||||
|
||||
bool TextEditDocument::IsModified(void) const
|
||||
{
|
||||
TextEditView *view = (TextEditView *)GetFirstView();
|
||||
if (view)
|
||||
{
|
||||
return (wxDocument::IsModified() || view->textsw->IsModified());
|
||||
}
|
||||
else
|
||||
return wxDocument::IsModified();
|
||||
TextEditView* view = GetFirstView();
|
||||
return (wxDocument::IsModified() || (view && view->m_textsw->IsModified()));
|
||||
}
|
||||
|
||||
void TextEditDocument::Modify(bool mod)
|
||||
{
|
||||
TextEditView *view = (TextEditView *)GetFirstView();
|
||||
TextEditView* view = GetFirstView();
|
||||
|
||||
wxDocument::Modify(mod);
|
||||
|
||||
if (!mod && view && view->textsw)
|
||||
view->textsw->DiscardEdits();
|
||||
if (!mod && view && view->m_textsw)
|
||||
view->m_textsw->DiscardEdits();
|
||||
}
|
||||
|
||||
TextEditView* TextEditDocument::GetFirstView() const
|
||||
{
|
||||
wxView* view = wxDocument::GetFirstView();
|
||||
return view ? wxStaticCast(view, TextEditView) : NULL;
|
||||
}
|
||||
|
||||
|
@@ -9,8 +9,8 @@
|
||||
// Licence: wxWindows license
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef __DOCSAMPLEH__
|
||||
#define __DOCSAMPLEH__
|
||||
#ifndef __DOC_H__
|
||||
#define __DOC_H__
|
||||
|
||||
#include "wx/docview.h"
|
||||
#include "wx/cmdproc.h"
|
||||
@@ -29,11 +29,11 @@ public:
|
||||
class DoodleSegment : public wxObject
|
||||
{
|
||||
public:
|
||||
wxList lines;
|
||||
wxList m_lines;
|
||||
|
||||
DoodleSegment(void){};
|
||||
DoodleSegment() : wxObject() {}
|
||||
DoodleSegment(const DoodleSegment& seg);
|
||||
~DoodleSegment(void);
|
||||
virtual ~DoodleSegment();
|
||||
|
||||
void Draw(wxDC *dc);
|
||||
#if wxUSE_STD_IOSTREAM
|
||||
@@ -51,10 +51,10 @@ class DrawingDocument: public wxDocument
|
||||
DECLARE_DYNAMIC_CLASS(DrawingDocument)
|
||||
private:
|
||||
public:
|
||||
wxList doodleSegments;
|
||||
wxList m_doodleSegments;
|
||||
|
||||
DrawingDocument(void){};
|
||||
~DrawingDocument(void);
|
||||
DrawingDocument() : wxDocument() {}
|
||||
virtual ~DrawingDocument();
|
||||
|
||||
#if wxUSE_STD_IOSTREAM
|
||||
wxSTD ostream& SaveObject(wxSTD ostream& text_stream);
|
||||
@@ -64,7 +64,7 @@ public:
|
||||
wxInputStream& LoadObject(wxInputStream& stream);
|
||||
#endif
|
||||
|
||||
inline wxList& GetDoodleSegments(void) const { return (wxList&) doodleSegments; };
|
||||
inline wxList& GetDoodleSegments() const { return (wxList&) m_doodleSegments; };
|
||||
};
|
||||
|
||||
#define DOODLE_CUT 1
|
||||
@@ -73,33 +73,34 @@ public:
|
||||
class DrawingCommand : public wxCommand
|
||||
{
|
||||
protected:
|
||||
DoodleSegment *segment;
|
||||
DrawingDocument *doc;
|
||||
int cmd;
|
||||
DoodleSegment* m_segment;
|
||||
DrawingDocument* m_doc;
|
||||
int m_cmd;
|
||||
public:
|
||||
DrawingCommand(const wxString& name, int cmd, DrawingDocument *ddoc, DoodleSegment *seg);
|
||||
~DrawingCommand(void);
|
||||
DrawingCommand(const wxString& name, int cmd, DrawingDocument*, DoodleSegment*);
|
||||
virtual ~DrawingCommand();
|
||||
|
||||
bool Do(void);
|
||||
bool Undo(void);
|
||||
};
|
||||
|
||||
class TextEditView;
|
||||
class TextEditDocument : public wxDocument
|
||||
{
|
||||
DECLARE_DYNAMIC_CLASS(TextEditDocument)
|
||||
private:
|
||||
public:
|
||||
TextEditDocument() : wxDocument() {}
|
||||
virtual ~TextEditDocument() {}
|
||||
/*
|
||||
wxSTD ostream& SaveObject(wxSTD ostream& stream);
|
||||
wxSTD istream& LoadObject(wxSTD istream& stream);
|
||||
wxSTD ostream& SaveObject(wxSTD ostream&);
|
||||
wxSTD istream& LoadObject(wxSTD istream&);
|
||||
*/
|
||||
TextEditView* GetFirstView() const;
|
||||
|
||||
virtual bool OnSaveDocument(const wxString& filename);
|
||||
virtual bool OnOpenDocument(const wxString& filename);
|
||||
virtual bool IsModified(void) const;
|
||||
virtual void Modify(bool mod);
|
||||
|
||||
TextEditDocument(void) {}
|
||||
~TextEditDocument(void) {}
|
||||
};
|
||||
|
||||
|
||||
|
@@ -39,8 +39,9 @@
|
||||
#ifdef __WXMAC__
|
||||
#include "wx/filename.h"
|
||||
#endif
|
||||
#include "wx/stockitem.h"
|
||||
|
||||
MyFrame *frame = (MyFrame *) NULL;
|
||||
static MyFrame* frame = NULL;
|
||||
|
||||
// In single window mode, don't have any child windows; use
|
||||
// main window.
|
||||
@@ -50,13 +51,15 @@ IMPLEMENT_APP(MyApp)
|
||||
|
||||
MyApp::MyApp(void)
|
||||
{
|
||||
m_docManager = (wxDocManager *) NULL;
|
||||
m_docManager = NULL;
|
||||
}
|
||||
|
||||
bool MyApp::OnInit(void)
|
||||
{
|
||||
if ( !wxApp::OnInit() )
|
||||
return false;
|
||||
SetAppName(wxT("DocView Demo"));
|
||||
|
||||
|
||||
//// Find out if we're:
|
||||
//// multiple window: multiple windows, each view in a separate frame
|
||||
@@ -64,7 +67,7 @@ bool MyApp::OnInit(void)
|
||||
//// In single window mode, we only allow one document type
|
||||
if (argc > 1)
|
||||
{
|
||||
if (wxStrcmp(argv[1], _T("-single")) == 0)
|
||||
if (wxStrcmp(argv[1], wxT("-single")) == 0)
|
||||
{
|
||||
singleWindowMode = true;
|
||||
}
|
||||
@@ -74,7 +77,7 @@ bool MyApp::OnInit(void)
|
||||
m_docManager = new wxDocManager;
|
||||
|
||||
//// Create a template relating drawing documents to their views
|
||||
(void) new wxDocTemplate(m_docManager, _T("Drawing"), _T("*.drw"), _T(""), _T("drw"), _T("Drawing Doc"), _T("Drawing View"),
|
||||
new wxDocTemplate(m_docManager, wxT("Drawing"), wxT("*.drw"), wxT(""), wxT("drw"), wxT("Drawing Doc"), wxT("Drawing View"),
|
||||
CLASSINFO(DrawingDocument), CLASSINFO(DrawingView));
|
||||
#ifdef __WXMAC__
|
||||
wxFileName::MacRegisterDefaultTypeAndCreator( wxT("drw") , 'WXMB' , 'WXMA' ) ;
|
||||
@@ -90,7 +93,7 @@ bool MyApp::OnInit(void)
|
||||
else
|
||||
{
|
||||
//// Create a template relating text documents to their views
|
||||
(void) new wxDocTemplate(m_docManager, _T("Text"), _T("*.txt;*.text"), _T(""), _T("txt;text"), _T("Text Doc"), _T("Text View"),
|
||||
new wxDocTemplate(m_docManager, wxT("Text"), wxT("*.txt;*.text"), wxT(""), wxT("txt;text"), wxT("Text Doc"), wxT("Text View"),
|
||||
CLASSINFO(TextEditDocument), CLASSINFO(TextEditView));
|
||||
#ifdef __WXMAC__
|
||||
wxFileName::MacRegisterDefaultTypeAndCreator( wxT("txt") , 'TEXT' , 'WXMA' ) ;
|
||||
@@ -98,57 +101,57 @@ bool MyApp::OnInit(void)
|
||||
}
|
||||
|
||||
//// Create the main frame window
|
||||
frame = new MyFrame(m_docManager, (wxFrame *) NULL, wxID_ANY, _T("DocView Demo"), wxPoint(0, 0), wxSize(500, 400), wxDEFAULT_FRAME_STYLE);
|
||||
frame = new MyFrame(m_docManager, NULL, wxID_ANY, GetAppDisplayName(), wxPoint(0, 0), wxSize(500, 400), wxDEFAULT_FRAME_STYLE);
|
||||
|
||||
//// Give it an icon (this is ignored in MDI mode: uses resources)
|
||||
#ifdef __WXMSW__
|
||||
frame->SetIcon(wxIcon(_T("doc_icn")));
|
||||
frame->SetIcon(wxIcon(wxT("doc_icn")));
|
||||
#endif
|
||||
|
||||
//// Make a menubar
|
||||
wxMenu *file_menu = new wxMenu;
|
||||
wxMenu *edit_menu = (wxMenu *) NULL;
|
||||
wxMenu *edit_menu = NULL;
|
||||
|
||||
file_menu->Append(wxID_NEW, _T("&New..."));
|
||||
file_menu->Append(wxID_OPEN, _T("&Open..."));
|
||||
file_menu->Append(wxID_NEW);
|
||||
file_menu->Append(wxID_OPEN);
|
||||
|
||||
if (singleWindowMode)
|
||||
{
|
||||
file_menu->Append(wxID_CLOSE, _T("&Close"));
|
||||
file_menu->Append(wxID_SAVE, _T("&Save"));
|
||||
file_menu->Append(wxID_SAVEAS, _T("Save &As..."));
|
||||
file_menu->Append(wxID_CLOSE);
|
||||
file_menu->Append(wxID_SAVE);
|
||||
file_menu->Append(wxID_SAVEAS);
|
||||
file_menu->AppendSeparator();
|
||||
file_menu->Append(wxID_PRINT, _T("&Print..."));
|
||||
file_menu->Append(wxID_PRINT_SETUP, _T("Print &Setup..."));
|
||||
file_menu->Append(wxID_PREVIEW, _T("Print Pre&view"));
|
||||
file_menu->Append(wxID_PRINT);
|
||||
file_menu->Append(wxID_PRINT_SETUP, wxT("Print &Setup..."));
|
||||
file_menu->Append(wxID_PREVIEW);
|
||||
|
||||
edit_menu = new wxMenu;
|
||||
edit_menu->Append(wxID_UNDO, _T("&Undo"));
|
||||
edit_menu->Append(wxID_REDO, _T("&Redo"));
|
||||
edit_menu->Append(wxID_UNDO);
|
||||
edit_menu->Append(wxID_REDO);
|
||||
edit_menu->AppendSeparator();
|
||||
edit_menu->Append(DOCVIEW_CUT, _T("&Cut last segment"));
|
||||
edit_menu->Append(DOCVIEW_CUT, wxT("&Cut last segment"));
|
||||
|
||||
frame->editMenu = edit_menu;
|
||||
frame->m_editMenu = edit_menu;
|
||||
}
|
||||
|
||||
file_menu->AppendSeparator();
|
||||
file_menu->Append(wxID_EXIT, _T("E&xit"));
|
||||
file_menu->Append(wxID_EXIT);
|
||||
|
||||
// A nice touch: a history of files visited. Use this menu.
|
||||
m_docManager->FileHistoryUseMenu(file_menu);
|
||||
|
||||
wxMenu *help_menu = new wxMenu;
|
||||
help_menu->Append(DOCVIEW_ABOUT, _T("&About"));
|
||||
help_menu->Append(DOCVIEW_ABOUT);
|
||||
|
||||
wxMenuBar *menu_bar = new wxMenuBar;
|
||||
|
||||
menu_bar->Append(file_menu, _T("&File"));
|
||||
menu_bar->Append(file_menu, wxGetStockLabel(wxID_FILE));
|
||||
if (edit_menu)
|
||||
menu_bar->Append(edit_menu, _T("&Edit"));
|
||||
menu_bar->Append(help_menu, _T("&Help"));
|
||||
menu_bar->Append(edit_menu, wxGetStockLabel(wxID_EDIT));
|
||||
menu_bar->Append(help_menu, wxGetStockLabel(wxID_HELP));
|
||||
|
||||
if (singleWindowMode)
|
||||
frame->canvas = frame->CreateCanvas((wxView *) NULL, frame);
|
||||
frame->m_canvas = frame->CreateCanvas(NULL, frame);
|
||||
|
||||
//// Associate the menu bar with the frame
|
||||
frame->SetMenuBar(menu_bar);
|
||||
@@ -175,52 +178,56 @@ int MyApp::OnExit(void)
|
||||
wxFrame *MyApp::CreateChildFrame(wxDocument *doc, wxView *view, bool isCanvas)
|
||||
{
|
||||
//// Make a child frame
|
||||
wxDocChildFrame *subframe = new wxDocChildFrame(doc, view, GetMainFrame(), wxID_ANY, _T("Child Frame"),
|
||||
wxDocChildFrame *subframe = new wxDocChildFrame(doc, view, GetMainFrame(), wxID_ANY, wxT("Child Frame"),
|
||||
wxPoint(10, 10), wxSize(300, 300), wxDEFAULT_FRAME_STYLE);
|
||||
|
||||
#ifdef __WXMSW__
|
||||
subframe->SetIcon(wxString(isCanvas ? _T("chrt_icn") : _T("notepad_icn")));
|
||||
subframe->SetIcon(wxString(isCanvas ? wxT("chrt_icn") : wxT("notepad_icn")));
|
||||
#endif
|
||||
|
||||
//// Make a menubar
|
||||
wxMenu *file_menu = new wxMenu;
|
||||
|
||||
file_menu->Append(wxID_NEW, _T("&New..."));
|
||||
file_menu->Append(wxID_OPEN, _T("&Open..."));
|
||||
file_menu->Append(wxID_CLOSE, _T("&Close"));
|
||||
file_menu->Append(wxID_SAVE, _T("&Save"));
|
||||
file_menu->Append(wxID_SAVEAS, _T("Save &As..."));
|
||||
file_menu->Append(wxID_NEW);
|
||||
file_menu->Append(wxID_OPEN);
|
||||
file_menu->Append(wxID_CLOSE);
|
||||
file_menu->Append(wxID_SAVE);
|
||||
file_menu->Append(wxID_SAVEAS);
|
||||
|
||||
if (isCanvas)
|
||||
{
|
||||
file_menu->AppendSeparator();
|
||||
file_menu->Append(wxID_PRINT, _T("&Print..."));
|
||||
file_menu->Append(wxID_PRINT_SETUP, _T("Print &Setup..."));
|
||||
file_menu->Append(wxID_PREVIEW, _T("Print Pre&view"));
|
||||
file_menu->Append(wxID_PRINT);
|
||||
file_menu->Append(wxID_PRINT_SETUP, wxT("Print &Setup..."));
|
||||
file_menu->Append(wxID_PREVIEW);
|
||||
}
|
||||
|
||||
wxMenu *edit_menu = (wxMenu *) NULL;
|
||||
wxMenu *edit_menu = new wxMenu;
|
||||
|
||||
if (isCanvas)
|
||||
{
|
||||
edit_menu = new wxMenu;
|
||||
edit_menu->Append(wxID_UNDO, _T("&Undo"));
|
||||
edit_menu->Append(wxID_REDO, _T("&Redo"));
|
||||
edit_menu->Append(wxID_UNDO);
|
||||
edit_menu->Append(wxID_REDO);
|
||||
edit_menu->AppendSeparator();
|
||||
edit_menu->Append(DOCVIEW_CUT, _T("&Cut last segment"));
|
||||
edit_menu->Append(DOCVIEW_CUT, wxT("&Cut last segment"));
|
||||
|
||||
doc->GetCommandProcessor()->SetEditMenu(edit_menu);
|
||||
}
|
||||
else
|
||||
{
|
||||
edit_menu->Append(wxID_COPY);
|
||||
edit_menu->Append(wxID_PASTE);
|
||||
edit_menu->Append(wxID_SELECTALL);
|
||||
}
|
||||
|
||||
wxMenu *help_menu = new wxMenu;
|
||||
help_menu->Append(DOCVIEW_ABOUT, _T("&About"));
|
||||
help_menu->Append(DOCVIEW_ABOUT);
|
||||
|
||||
wxMenuBar *menu_bar = new wxMenuBar;
|
||||
|
||||
menu_bar->Append(file_menu, _T("&File"));
|
||||
if (isCanvas)
|
||||
menu_bar->Append(edit_menu, _T("&Edit"));
|
||||
menu_bar->Append(help_menu, _T("&Help"));
|
||||
menu_bar->Append(file_menu, wxGetStockLabel(wxID_FILE));
|
||||
menu_bar->Append(edit_menu, wxGetStockLabel(wxID_EDIT));
|
||||
menu_bar->Append(help_menu, wxGetStockLabel(wxID_HELP));
|
||||
|
||||
//// Associate the menu bar with the frame
|
||||
subframe->SetMenuBar(menu_bar);
|
||||
@@ -244,25 +251,31 @@ MyFrame::MyFrame(wxDocManager *manager, wxFrame *frame, wxWindowID id, const wxS
|
||||
wxDocParentFrame(manager, frame, id, title, pos, size, type)
|
||||
{
|
||||
// This pointer only needed if in single window mode
|
||||
canvas = (MyCanvas *) NULL;
|
||||
editMenu = (wxMenu *) NULL;
|
||||
m_canvas = NULL;
|
||||
m_editMenu = NULL;
|
||||
}
|
||||
|
||||
void MyFrame::OnAbout(wxCommandEvent& WXUNUSED(event) )
|
||||
{
|
||||
(void)wxMessageBox(_T("DocView Demo\nAuthor: Julian Smart\nUsage: docview.exe [-single]"), _T("About DocView"));
|
||||
wxMessageBox(wxT("DocView Demo\nAuthor: Julian Smart\nUsage: docview.exe [-single]"), wxT("About DocView"));
|
||||
/*
|
||||
Better, but brings in adv lib
|
||||
wxAboutDialogInfo info;
|
||||
info.SetName(wxTheApp->GetAppDisplayName());
|
||||
info.AddDeveloper(wxT("Julian Smart"));
|
||||
wxAboutBox(info);
|
||||
*/
|
||||
}
|
||||
|
||||
// Creates a canvas. Called either from view.cc when a new drawing
|
||||
// view is created, or in OnInit as a child of the main window,
|
||||
// if in 'single window' mode.
|
||||
MyCanvas *MyFrame::CreateCanvas(wxView *view, wxFrame *parent)
|
||||
MyCanvas *MyFrame::CreateCanvas(DrawingView* view, wxFrame *parent)
|
||||
{
|
||||
int width, height;
|
||||
parent->GetClientSize(&width, &height);
|
||||
wxSize size = parent->GetClientSize();
|
||||
|
||||
// Non-retained canvas
|
||||
MyCanvas *canvas = new MyCanvas(view, parent, wxPoint(0, 0), wxSize(width, height), 0);
|
||||
MyCanvas* canvas = new MyCanvas(view, parent, wxPoint(0, 0), size, 0);
|
||||
canvas->SetCursor(wxCursor(wxCURSOR_PENCIL));
|
||||
|
||||
// Give it scrollbars
|
||||
|
@@ -9,8 +9,8 @@
|
||||
// Licence: wxWindows license
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef __DOCVIEWSAMPLEH__
|
||||
#define __DOCVIEWSAMPLEH__
|
||||
#ifndef __DOCVIEW_H__
|
||||
#define __DOCVIEW_H__
|
||||
|
||||
#include "wx/docview.h"
|
||||
|
||||
@@ -34,25 +34,27 @@ DECLARE_APP(MyApp)
|
||||
|
||||
// Define a new frame
|
||||
class MyCanvas;
|
||||
class DrawingView;
|
||||
class MyFrame : public wxDocParentFrame
|
||||
{
|
||||
DECLARE_CLASS(MyFrame)
|
||||
public:
|
||||
wxMenu *editMenu;
|
||||
wxMenu* m_editMenu;
|
||||
|
||||
// This pointer only needed if in single window mode
|
||||
MyCanvas *canvas;
|
||||
MyCanvas* m_canvas;
|
||||
|
||||
MyFrame(wxDocManager *manager, wxFrame *frame, wxWindowID id, const wxString& title, const wxPoint& pos, const wxSize& size,
|
||||
const long type);
|
||||
|
||||
void OnAbout(wxCommandEvent& event);
|
||||
MyCanvas *CreateCanvas(wxView *view, wxFrame *parent);
|
||||
MyCanvas* CreateCanvas(DrawingView*, wxFrame *parent);
|
||||
|
||||
protected:
|
||||
void OnAbout(wxCommandEvent& event);
|
||||
DECLARE_EVENT_TABLE()
|
||||
};
|
||||
|
||||
extern MyFrame *GetMainFrame(void);
|
||||
extern MyFrame *GetMainFrame();
|
||||
|
||||
#define DOCVIEW_CUT 1
|
||||
#define DOCVIEW_ABOUT wxID_ABOUT
|
||||
|
@@ -31,8 +31,8 @@
|
||||
IMPLEMENT_DYNAMIC_CLASS(DrawingView, wxView)
|
||||
|
||||
// For drawing lines in a canvas
|
||||
float xpos = -1;
|
||||
float ypos = -1;
|
||||
static float xpos = -1;
|
||||
static float ypos = -1;
|
||||
|
||||
BEGIN_EVENT_TABLE(DrawingView, wxView)
|
||||
EVT_MENU(DOODLE_CUT, DrawingView::OnCut)
|
||||
@@ -45,34 +45,34 @@ bool DrawingView::OnCreate(wxDocument *doc, long WXUNUSED(flags) )
|
||||
if (!singleWindowMode)
|
||||
{
|
||||
// Multiple windows
|
||||
frame = wxGetApp().CreateChildFrame(doc, this, true);
|
||||
frame->SetTitle(_T("DrawingView"));
|
||||
m_frame = wxGetApp().CreateChildFrame(doc, this, true);
|
||||
m_frame->SetTitle(wxT("DrawingView"));
|
||||
|
||||
canvas = GetMainFrame()->CreateCanvas(this, frame);
|
||||
m_canvas = GetMainFrame()->CreateCanvas(this, m_frame);
|
||||
#ifdef __X__
|
||||
// X seems to require a forced resize
|
||||
int x, y;
|
||||
frame->GetSize(&x, &y);
|
||||
frame->SetSize(wxDefaultCoord, wxDefaultCoord, x, y);
|
||||
m_frame->GetSize(&x, &y);
|
||||
m_frame->SetSize(wxDefaultCoord, wxDefaultCoord, x, y);
|
||||
#endif
|
||||
frame->Show(true);
|
||||
m_frame->Show(true);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Single-window mode
|
||||
frame = GetMainFrame();
|
||||
canvas = GetMainFrame()->canvas;
|
||||
canvas->view = this;
|
||||
m_frame = GetMainFrame();
|
||||
m_canvas = GetMainFrame()->m_canvas;
|
||||
m_canvas->m_view = this;
|
||||
|
||||
// Associate the appropriate frame with this view.
|
||||
SetFrame(frame);
|
||||
SetFrame(m_frame);
|
||||
|
||||
// Make sure the document manager knows that this is the
|
||||
// current view.
|
||||
Activate(true);
|
||||
|
||||
// Initialize the edit menu Undo and Redo items
|
||||
doc->GetCommandProcessor()->SetEditMenu(((MyFrame *)frame)->editMenu);
|
||||
doc->GetCommandProcessor()->SetEditMenu(((MyFrame*)m_frame)->m_editMenu);
|
||||
doc->GetCommandProcessor()->Initialize();
|
||||
}
|
||||
|
||||
@@ -86,7 +86,7 @@ void DrawingView::OnDraw(wxDC *dc)
|
||||
dc->SetFont(*wxNORMAL_FONT);
|
||||
dc->SetPen(*wxBLACK_PEN);
|
||||
|
||||
wxList::compatibility_iterator node = ((DrawingDocument *)GetDocument())->GetDoodleSegments().GetFirst();
|
||||
wxList::compatibility_iterator node = GetDocument()->GetDoodleSegments().GetFirst();
|
||||
while (node)
|
||||
{
|
||||
DoodleSegment *seg = (DoodleSegment *)node->GetData();
|
||||
@@ -95,10 +95,15 @@ void DrawingView::OnDraw(wxDC *dc)
|
||||
}
|
||||
}
|
||||
|
||||
DrawingDocument* DrawingView::GetDocument()
|
||||
{
|
||||
return wxStaticCast(wxView::GetDocument(), DrawingDocument);
|
||||
}
|
||||
|
||||
void DrawingView::OnUpdate(wxView *WXUNUSED(sender), wxObject *WXUNUSED(hint))
|
||||
{
|
||||
if (canvas)
|
||||
canvas->Refresh();
|
||||
if (m_canvas)
|
||||
m_canvas->Refresh();
|
||||
|
||||
/* Is the following necessary?
|
||||
#ifdef __WXMSW__
|
||||
@@ -123,21 +128,21 @@ bool DrawingView::OnClose(bool deleteWindow)
|
||||
|
||||
// Clear the canvas in case we're in single-window mode,
|
||||
// and the canvas stays.
|
||||
canvas->ClearBackground();
|
||||
canvas->view = (wxView *) NULL;
|
||||
canvas = (MyCanvas *) NULL;
|
||||
m_canvas->ClearBackground();
|
||||
m_canvas->m_view = NULL;
|
||||
m_canvas = NULL;
|
||||
|
||||
wxString s(wxTheApp->GetAppDisplayName());
|
||||
if (frame)
|
||||
frame->SetTitle(s);
|
||||
if (m_frame)
|
||||
m_frame->SetTitle(s);
|
||||
|
||||
SetFrame((wxFrame *) NULL);
|
||||
SetFrame(NULL);
|
||||
|
||||
Activate(false);
|
||||
|
||||
if (deleteWindow && !singleWindowMode)
|
||||
{
|
||||
delete frame;
|
||||
delete m_frame;
|
||||
return true;
|
||||
}
|
||||
return true;
|
||||
@@ -145,20 +150,19 @@ bool DrawingView::OnClose(bool deleteWindow)
|
||||
|
||||
void DrawingView::OnCut(wxCommandEvent& WXUNUSED(event) )
|
||||
{
|
||||
DrawingDocument *doc = (DrawingDocument *)GetDocument();
|
||||
doc->GetCommandProcessor()->Submit(new DrawingCommand(_T("Cut Last Segment"), DOODLE_CUT, doc, (DoodleSegment *) NULL));
|
||||
DrawingDocument* doc = GetDocument();
|
||||
doc->GetCommandProcessor()->Submit(new DrawingCommand(wxT("Cut Last Segment"), DOODLE_CUT, doc, NULL));
|
||||
}
|
||||
|
||||
IMPLEMENT_DYNAMIC_CLASS(TextEditView, wxView)
|
||||
|
||||
bool TextEditView::OnCreate(wxDocument *doc, long WXUNUSED(flags) )
|
||||
{
|
||||
frame = wxGetApp().CreateChildFrame(doc, this, false);
|
||||
m_frame = wxGetApp().CreateChildFrame(doc, this, false);
|
||||
|
||||
int width, height;
|
||||
frame->GetClientSize(&width, &height);
|
||||
textsw = new MyTextWindow(this, frame, wxPoint(0, 0), wxSize(width, height), wxTE_MULTILINE);
|
||||
frame->SetTitle(_T("TextEditView"));
|
||||
wxSize size = m_frame->GetClientSize();
|
||||
m_textsw = new MyTextWindow(this, m_frame, wxPoint(0, 0), size, wxTE_MULTILINE);
|
||||
m_frame->SetTitle(wxT("TextEditView"));
|
||||
|
||||
#ifdef __X__
|
||||
// X seems to require a forced resize
|
||||
@@ -167,7 +171,7 @@ bool TextEditView::OnCreate(wxDocument *doc, long WXUNUSED(flags) )
|
||||
frame->SetSize(wxDefaultCoord, wxDefaultCoord, x, y);
|
||||
#endif
|
||||
|
||||
frame->Show(true);
|
||||
m_frame->Show(true);
|
||||
Activate(true);
|
||||
|
||||
return true;
|
||||
@@ -191,12 +195,27 @@ bool TextEditView::OnClose(bool deleteWindow)
|
||||
|
||||
if (deleteWindow)
|
||||
{
|
||||
delete frame;
|
||||
wxDELETE(m_frame)
|
||||
return true;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool TextEditView::ProcessEvent(wxEvent& event)
|
||||
{
|
||||
bool processed = false;
|
||||
if (!processed) switch (event.GetId())
|
||||
{
|
||||
case wxID_COPY:
|
||||
case wxID_PASTE:
|
||||
case wxID_SELECTALL:
|
||||
processed = m_textsw->ProcessEvent(event);
|
||||
break;
|
||||
}
|
||||
if (!processed) processed = wxView::ProcessEvent(event);
|
||||
return processed;
|
||||
}
|
||||
|
||||
/*
|
||||
* Window implementations
|
||||
*/
|
||||
@@ -206,27 +225,27 @@ BEGIN_EVENT_TABLE(MyCanvas, wxScrolledWindow)
|
||||
END_EVENT_TABLE()
|
||||
|
||||
// Define a constructor for my canvas
|
||||
MyCanvas::MyCanvas(wxView *v, wxFrame *frame, const wxPoint& pos, const wxSize& size, const long style):
|
||||
MyCanvas::MyCanvas(DrawingView* view, wxFrame* frame, const wxPoint& pos, const wxSize& size, const long style):
|
||||
wxScrolledWindow(frame, wxID_ANY, pos, size, style)
|
||||
{
|
||||
view = v;
|
||||
m_view = view;
|
||||
}
|
||||
|
||||
// Define the repainting behaviour
|
||||
void MyCanvas::OnDraw(wxDC& dc)
|
||||
{
|
||||
if (view)
|
||||
view->OnDraw(& dc);
|
||||
if (m_view)
|
||||
m_view->OnDraw(& dc);
|
||||
}
|
||||
|
||||
// This implements a tiny doodling program. Drag the mouse using
|
||||
// the left button.
|
||||
void MyCanvas::OnMouseEvent(wxMouseEvent& event)
|
||||
{
|
||||
if (!view)
|
||||
if (!m_view)
|
||||
return;
|
||||
|
||||
static DoodleSegment *currentSegment = (DoodleSegment *) NULL;
|
||||
static DoodleSegment *currentSegment = NULL;
|
||||
|
||||
wxClientDC dc(this);
|
||||
PrepareDC(dc);
|
||||
@@ -237,24 +256,24 @@ void MyCanvas::OnMouseEvent(wxMouseEvent& event)
|
||||
|
||||
if (currentSegment && event.LeftUp())
|
||||
{
|
||||
if (currentSegment->lines.GetCount() == 0)
|
||||
if (currentSegment->m_lines.GetCount() == 0)
|
||||
{
|
||||
delete currentSegment;
|
||||
currentSegment = (DoodleSegment *) NULL;
|
||||
currentSegment = NULL;
|
||||
}
|
||||
else
|
||||
{
|
||||
// We've got a valid segment on mouse left up, so store it.
|
||||
DrawingDocument *doc = (DrawingDocument *)view->GetDocument();
|
||||
DrawingDocument* doc = m_view->GetDocument();
|
||||
|
||||
doc->GetCommandProcessor()->Submit(new DrawingCommand(_T("Add Segment"), DOODLE_ADD, doc, currentSegment));
|
||||
doc->GetCommandProcessor()->Submit(new DrawingCommand(wxT("Add Segment"), DOODLE_ADD, doc, currentSegment));
|
||||
|
||||
view->GetDocument()->Modify(true);
|
||||
currentSegment = (DoodleSegment *) NULL;
|
||||
m_view->GetDocument()->Modify(true);
|
||||
currentSegment = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
if (xpos > -1 && ypos > -1 && event.Dragging())
|
||||
if ( (xpos > -1) && (ypos > -1) && event.Dragging())
|
||||
{
|
||||
if (!currentSegment)
|
||||
currentSegment = new DoodleSegment;
|
||||
@@ -264,7 +283,7 @@ void MyCanvas::OnMouseEvent(wxMouseEvent& event)
|
||||
newLine->y1 = (long)ypos;
|
||||
newLine->x2 = pt.x;
|
||||
newLine->y2 = pt.y;
|
||||
currentSegment->lines.Append(newLine);
|
||||
currentSegment->m_lines.Append(newLine);
|
||||
|
||||
dc.DrawLine( (long)xpos, (long)ypos, pt.x, pt.y);
|
||||
}
|
||||
@@ -273,10 +292,10 @@ void MyCanvas::OnMouseEvent(wxMouseEvent& event)
|
||||
}
|
||||
|
||||
// Define a constructor for my text subwindow
|
||||
MyTextWindow::MyTextWindow(wxView *v, wxFrame *frame, const wxPoint& pos, const wxSize& size, const long style):
|
||||
wxTextCtrl(frame, wxID_ANY, _T(""), pos, size, style)
|
||||
MyTextWindow::MyTextWindow(wxView* view, wxFrame* frame, const wxPoint& pos, const wxSize& size, const long style):
|
||||
wxTextCtrl(frame, wxID_ANY, wxEmptyString, pos, size, style)
|
||||
{
|
||||
view = v;
|
||||
m_view = view;
|
||||
}
|
||||
|
||||
|
||||
|
@@ -9,67 +9,74 @@
|
||||
// Licence: wxWindows license
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef __VIEWSAMPLEH__
|
||||
#define __VIEWSAMPLEH__
|
||||
#ifndef __VIEW_H__
|
||||
#define __VIEW_H__
|
||||
|
||||
#include "wx/docview.h"
|
||||
|
||||
class DrawingView;
|
||||
class MyCanvas : public wxScrolledWindow
|
||||
{
|
||||
public:
|
||||
wxView *view;
|
||||
DrawingView* m_view;
|
||||
|
||||
MyCanvas(wxView *v, wxFrame *frame, const wxPoint& pos, const wxSize& size, const long style);
|
||||
MyCanvas(DrawingView*, wxFrame*, const wxPoint& pos, const wxSize& size, const long style);
|
||||
virtual void OnDraw(wxDC& dc);
|
||||
void OnMouseEvent(wxMouseEvent& event);
|
||||
|
||||
protected:
|
||||
void OnMouseEvent(wxMouseEvent& event);
|
||||
DECLARE_EVENT_TABLE()
|
||||
};
|
||||
|
||||
class MyTextWindow: public wxTextCtrl
|
||||
{
|
||||
public:
|
||||
wxView *view;
|
||||
wxView* m_view;
|
||||
|
||||
MyTextWindow(wxView *v, wxFrame *frame, const wxPoint& pos, const wxSize& size, const long style);
|
||||
};
|
||||
|
||||
class DrawingView : public wxView
|
||||
{
|
||||
DECLARE_DYNAMIC_CLASS(DrawingView)
|
||||
private:
|
||||
public:
|
||||
wxFrame *frame;
|
||||
MyCanvas *canvas;
|
||||
wxFrame* m_frame;
|
||||
MyCanvas* m_canvas;
|
||||
|
||||
DrawingView(void) { canvas = (MyCanvas *) NULL; frame = (wxFrame *) NULL; };
|
||||
~DrawingView(void) {};
|
||||
DrawingView() { m_canvas = NULL; m_frame = NULL; };
|
||||
virtual ~DrawingView() {};
|
||||
|
||||
bool OnCreate(wxDocument *doc, long flags);
|
||||
void OnDraw(wxDC *dc);
|
||||
void OnUpdate(wxView *sender, wxObject *hint = (wxObject *) NULL);
|
||||
bool OnClose(bool deleteWindow = true);
|
||||
virtual bool OnCreate(wxDocument *doc, long flags);
|
||||
virtual void OnDraw(wxDC *dc);
|
||||
virtual void OnUpdate(wxView *sender, wxObject *hint = NULL);
|
||||
virtual bool OnClose(bool deleteWindow = true);
|
||||
|
||||
DrawingDocument* GetDocument();
|
||||
|
||||
protected:
|
||||
void OnCut(wxCommandEvent& event);
|
||||
|
||||
private:
|
||||
DECLARE_EVENT_TABLE()
|
||||
DECLARE_DYNAMIC_CLASS(DrawingView)
|
||||
};
|
||||
|
||||
class TextEditView : public wxView
|
||||
{
|
||||
DECLARE_DYNAMIC_CLASS(TextEditView)
|
||||
private:
|
||||
public:
|
||||
wxFrame *frame;
|
||||
MyTextWindow *textsw;
|
||||
wxFrame* m_frame;
|
||||
MyTextWindow* m_textsw;
|
||||
|
||||
TextEditView(): wxView() { frame = (wxFrame *) NULL; textsw = (MyTextWindow *) NULL; }
|
||||
~TextEditView(void) {}
|
||||
TextEditView(): wxView() { m_frame = NULL; m_textsw = NULL; }
|
||||
virtual ~TextEditView() {}
|
||||
|
||||
bool OnCreate(wxDocument *doc, long flags);
|
||||
void OnDraw(wxDC *dc);
|
||||
void OnUpdate(wxView *sender, wxObject *hint = (wxObject *) NULL);
|
||||
bool OnClose(bool deleteWindow = true);
|
||||
virtual bool OnCreate(wxDocument *doc, long flags);
|
||||
virtual void OnDraw(wxDC *dc);
|
||||
virtual void OnUpdate(wxView *sender, wxObject *hint = NULL);
|
||||
virtual bool OnClose(bool deleteWindow = true);
|
||||
virtual bool ProcessEvent(wxEvent&);
|
||||
|
||||
private:
|
||||
DECLARE_DYNAMIC_CLASS(TextEditView)
|
||||
};
|
||||
|
||||
#endif
|
||||
|
@@ -37,7 +37,7 @@ IMPLEMENT_DYNAMIC_CLASS(DrawingDocument, wxDocument)
|
||||
|
||||
DrawingDocument::~DrawingDocument(void)
|
||||
{
|
||||
WX_CLEAR_LIST(wxList, doodleSegments);
|
||||
WX_CLEAR_LIST(wxList, m_doodleSegments)
|
||||
}
|
||||
|
||||
#if wxUSE_STD_IOSTREAM
|
||||
@@ -45,19 +45,18 @@ wxSTD ostream& DrawingDocument::SaveObject(wxSTD ostream& stream)
|
||||
{
|
||||
wxDocument::SaveObject(stream);
|
||||
|
||||
wxInt32 n = doodleSegments.GetCount();
|
||||
stream << n << _T('\n');
|
||||
wxInt32 n = m_doodleSegments.GetCount();
|
||||
stream << n << wxT('\n');
|
||||
|
||||
wxList::compatibility_iterator node = doodleSegments.GetFirst();
|
||||
wxList::compatibility_iterator node = m_doodleSegments.GetFirst();
|
||||
while (node)
|
||||
{
|
||||
DoodleSegment *segment = (DoodleSegment*)node->GetData();
|
||||
segment->SaveObject(stream);
|
||||
stream << _T('\n');
|
||||
stream << wxT('\n');
|
||||
|
||||
node = node->GetNext();
|
||||
}
|
||||
|
||||
return stream;
|
||||
}
|
||||
#else
|
||||
@@ -67,15 +66,15 @@ wxOutputStream& DrawingDocument::SaveObject(wxOutputStream& stream)
|
||||
|
||||
wxTextOutputStream text_stream( stream );
|
||||
|
||||
wxInt32 n = doodleSegments.GetCount();
|
||||
text_stream << n << _T('\n');
|
||||
wxInt32 n = m_doodleSegments.GetCount();
|
||||
text_stream << n << wxT('\n');
|
||||
|
||||
wxList::compatibility_iterator node = doodleSegments.GetFirst();
|
||||
wxList::compatibility_iterator node = m_doodleSegments.GetFirst();
|
||||
while (node)
|
||||
{
|
||||
DoodleSegment* segment = (DoodleSegment*)node->GetData();
|
||||
segment->SaveObject(stream);
|
||||
text_stream << _T('\n');
|
||||
text_stream << wxT('\n');
|
||||
|
||||
node = node->GetNext();
|
||||
}
|
||||
@@ -96,7 +95,7 @@ wxSTD istream& DrawingDocument::LoadObject(wxSTD istream& stream)
|
||||
{
|
||||
DoodleSegment *segment = new DoodleSegment;
|
||||
segment->LoadObject(stream);
|
||||
doodleSegments.Append(segment);
|
||||
m_doodleSegments.Append(segment);
|
||||
}
|
||||
|
||||
return stream;
|
||||
@@ -115,17 +114,16 @@ wxInputStream& DrawingDocument::LoadObject(wxInputStream& stream)
|
||||
{
|
||||
DoodleSegment* segment = new DoodleSegment;
|
||||
segment->LoadObject(stream);
|
||||
doodleSegments.Append(segment);
|
||||
m_doodleSegments.Append(segment);
|
||||
}
|
||||
|
||||
return stream;
|
||||
}
|
||||
#endif
|
||||
|
||||
DoodleSegment::DoodleSegment(const DoodleSegment& seg)
|
||||
:wxObject()
|
||||
DoodleSegment::DoodleSegment(const DoodleSegment& seg) : wxObject()
|
||||
{
|
||||
wxList::compatibility_iterator node = seg.lines.GetFirst();
|
||||
wxList::compatibility_iterator node = seg.m_lines.GetFirst();
|
||||
while (node)
|
||||
{
|
||||
DoodleLine* line = (DoodleLine*)node->GetData();
|
||||
@@ -135,7 +133,7 @@ DoodleSegment::DoodleSegment(const DoodleSegment& seg)
|
||||
newLine->x2 = line->x2;
|
||||
newLine->y2 = line->y2;
|
||||
|
||||
lines.Append(newLine);
|
||||
m_lines.Append(newLine);
|
||||
|
||||
node = node->GetNext();
|
||||
}
|
||||
@@ -143,23 +141,23 @@ DoodleSegment::DoodleSegment(const DoodleSegment& seg)
|
||||
|
||||
DoodleSegment::~DoodleSegment(void)
|
||||
{
|
||||
WX_CLEAR_LIST(wxList, lines);
|
||||
WX_CLEAR_LIST(wxList, m_lines)
|
||||
}
|
||||
|
||||
#if wxUSE_STD_IOSTREAM
|
||||
wxSTD ostream& DoodleSegment::SaveObject(wxSTD ostream& stream)
|
||||
{
|
||||
wxInt32 n = lines.GetCount();
|
||||
stream << n << _T('\n');
|
||||
wxInt32 n = m_lines.GetCount();
|
||||
stream << n << wxT('\n');
|
||||
|
||||
wxList::compatibility_iterator node = lines.GetFirst();
|
||||
wxList::compatibility_iterator node = m_lines.GetFirst();
|
||||
while (node)
|
||||
{
|
||||
DoodleLine *line = (DoodleLine *)node->GetData();
|
||||
stream << line->x1 << _T(" ") <<
|
||||
line->y1 << _T(" ") <<
|
||||
line->x2 << _T(" ") <<
|
||||
line->y2 << _T("\n");
|
||||
stream << line->x1 << wxT(" ") <<
|
||||
line->y1 << wxT(" ") <<
|
||||
line->x2 << wxT(" ") <<
|
||||
line->y2 << wxT("\n");
|
||||
node = node->GetNext();
|
||||
}
|
||||
|
||||
@@ -170,17 +168,17 @@ wxOutputStream &DoodleSegment::SaveObject(wxOutputStream& stream)
|
||||
{
|
||||
wxTextOutputStream text_stream( stream );
|
||||
|
||||
wxInt32 n = lines.GetCount();
|
||||
text_stream << n << _T('\n');
|
||||
wxInt32 n = m_lines.GetCount();
|
||||
text_stream << n << wxT('\n');
|
||||
|
||||
wxList::compatibility_iterator node = lines.GetFirst();
|
||||
wxList::compatibility_iterator node = m_lines.GetFirst();
|
||||
while (node)
|
||||
{
|
||||
DoodleLine* line = (DoodleLine*)node->GetData();
|
||||
text_stream << line->x1 << _T(" ") <<
|
||||
line->y1 << _T(" ") <<
|
||||
line->x2 << _T(" ") <<
|
||||
line->y2 << _T("\n");
|
||||
text_stream << line->x1 << wxT(" ") <<
|
||||
line->y1 << wxT(" ") <<
|
||||
line->x2 << wxT(" ") <<
|
||||
line->y2 << wxT("\n");
|
||||
node = node->GetNext();
|
||||
}
|
||||
|
||||
@@ -201,7 +199,7 @@ wxSTD istream& DoodleSegment::LoadObject(wxSTD istream& stream)
|
||||
line->y1 >>
|
||||
line->x2 >>
|
||||
line->y2;
|
||||
lines.Append(line);
|
||||
m_lines.Append(line);
|
||||
}
|
||||
|
||||
return stream;
|
||||
@@ -221,7 +219,7 @@ wxInputStream &DoodleSegment::LoadObject(wxInputStream& stream)
|
||||
line->y1 >>
|
||||
line->x2 >>
|
||||
line->y2;
|
||||
lines.Append(line);
|
||||
m_lines.Append(line);
|
||||
}
|
||||
|
||||
return stream;
|
||||
@@ -229,7 +227,7 @@ wxInputStream &DoodleSegment::LoadObject(wxInputStream& stream)
|
||||
#endif
|
||||
void DoodleSegment::Draw(wxDC *dc)
|
||||
{
|
||||
wxList::compatibility_iterator node = lines.GetFirst();
|
||||
wxList::compatibility_iterator node = m_lines.GetFirst();
|
||||
while (node)
|
||||
{
|
||||
DoodleLine* line = (DoodleLine*)node->GetData();
|
||||
@@ -242,82 +240,78 @@ void DoodleSegment::Draw(wxDC *dc)
|
||||
* Implementation of drawing command
|
||||
*/
|
||||
|
||||
DrawingCommand::DrawingCommand(const wxString& name, int command, DrawingDocument *ddoc, DoodleSegment *seg):
|
||||
DrawingCommand::DrawingCommand(const wxString& name, int command, DrawingDocument* doc, DoodleSegment* seg) :
|
||||
wxCommand(true, name)
|
||||
{
|
||||
doc = ddoc;
|
||||
segment = seg;
|
||||
cmd = command;
|
||||
m_doc = doc;
|
||||
m_segment = seg;
|
||||
m_cmd = command;
|
||||
}
|
||||
|
||||
DrawingCommand::~DrawingCommand(void)
|
||||
{
|
||||
if (segment)
|
||||
delete segment;
|
||||
if (m_segment)
|
||||
delete m_segment;
|
||||
}
|
||||
|
||||
bool DrawingCommand::Do(void)
|
||||
{
|
||||
switch (cmd)
|
||||
switch (m_cmd)
|
||||
{
|
||||
case DOODLE_CUT:
|
||||
{
|
||||
// Cut the last segment
|
||||
if (doc->GetDoodleSegments().GetCount() > 0)
|
||||
if (m_doc->GetDoodleSegments().GetCount() > 0)
|
||||
{
|
||||
wxList::compatibility_iterator node = doc->GetDoodleSegments().GetLast();
|
||||
if (segment)
|
||||
delete segment;
|
||||
wxList::compatibility_iterator node = m_doc->GetDoodleSegments().GetLast();
|
||||
if (m_segment)
|
||||
delete m_segment;
|
||||
|
||||
segment = (DoodleSegment *)node->GetData();
|
||||
doc->GetDoodleSegments().Erase(node);
|
||||
m_segment = (DoodleSegment*)node->GetData();
|
||||
m_doc->GetDoodleSegments().Erase(node);
|
||||
|
||||
doc->Modify(true);
|
||||
doc->UpdateAllViews();
|
||||
m_doc->Modify(true);
|
||||
m_doc->UpdateAllViews();
|
||||
}
|
||||
break;
|
||||
}
|
||||
case DOODLE_ADD:
|
||||
{
|
||||
doc->GetDoodleSegments().Append(new DoodleSegment(*segment));
|
||||
doc->Modify(true);
|
||||
doc->UpdateAllViews();
|
||||
m_doc->GetDoodleSegments().Append(new DoodleSegment(*m_segment));
|
||||
m_doc->Modify(true);
|
||||
m_doc->UpdateAllViews();
|
||||
break;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool DrawingCommand::Undo(void)
|
||||
{
|
||||
switch (cmd)
|
||||
switch (m_cmd)
|
||||
{
|
||||
case DOODLE_CUT:
|
||||
{
|
||||
// Paste the segment
|
||||
if (segment)
|
||||
if (m_segment)
|
||||
{
|
||||
doc->GetDoodleSegments().Append(segment);
|
||||
doc->Modify(true);
|
||||
doc->UpdateAllViews();
|
||||
segment = (DoodleSegment *) NULL;
|
||||
m_doc->GetDoodleSegments().Append(m_segment);
|
||||
m_doc->Modify(true);
|
||||
m_doc->UpdateAllViews();
|
||||
m_segment = NULL;
|
||||
}
|
||||
doc->Modify(true);
|
||||
doc->UpdateAllViews();
|
||||
m_doc->Modify(true);
|
||||
m_doc->UpdateAllViews();
|
||||
break;
|
||||
}
|
||||
case DOODLE_ADD:
|
||||
{
|
||||
// Cut the last segment
|
||||
if (doc->GetDoodleSegments().GetCount() > 0)
|
||||
if (m_doc->GetDoodleSegments().GetCount() > 0)
|
||||
{
|
||||
wxList::compatibility_iterator node = doc->GetDoodleSegments().GetLast();
|
||||
wxList::compatibility_iterator node = m_doc->GetDoodleSegments().GetLast();
|
||||
DoodleSegment* seg = (DoodleSegment*)node->GetData();
|
||||
delete seg;
|
||||
doc->GetDoodleSegments().Erase(node);
|
||||
m_doc->GetDoodleSegments().Erase(node);
|
||||
|
||||
doc->Modify(true);
|
||||
doc->UpdateAllViews();
|
||||
m_doc->Modify(true);
|
||||
m_doc->UpdateAllViews();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -330,9 +324,9 @@ IMPLEMENT_DYNAMIC_CLASS(TextEditDocument, wxDocument)
|
||||
// we override OnSave/OpenDocument instead of Save/LoadObject
|
||||
bool TextEditDocument::OnSaveDocument(const wxString& filename)
|
||||
{
|
||||
TextEditView *view = (TextEditView *)GetFirstView();
|
||||
TextEditView* view = GetFirstView();
|
||||
|
||||
if (!view->textsw->SaveFile(filename))
|
||||
if (!view->m_textsw->SaveFile(filename))
|
||||
return false;
|
||||
Modify(false);
|
||||
return true;
|
||||
@@ -340,8 +334,8 @@ bool TextEditDocument::OnSaveDocument(const wxString& filename)
|
||||
|
||||
bool TextEditDocument::OnOpenDocument(const wxString& filename)
|
||||
{
|
||||
TextEditView *view = (TextEditView *)GetFirstView();
|
||||
if (!view->textsw->LoadFile(filename))
|
||||
TextEditView *view = GetFirstView();
|
||||
if (!view->m_textsw->LoadFile(filename))
|
||||
return false;
|
||||
|
||||
SetFilename(filename, true);
|
||||
@@ -352,21 +346,25 @@ bool TextEditDocument::OnOpenDocument(const wxString& filename)
|
||||
|
||||
bool TextEditDocument::IsModified(void) const
|
||||
{
|
||||
TextEditView *view = (TextEditView *)GetFirstView();
|
||||
if (view)
|
||||
{
|
||||
return (wxDocument::IsModified() || view->textsw->IsModified());
|
||||
}
|
||||
else
|
||||
return wxDocument::IsModified();
|
||||
TextEditView* view = GetFirstView();
|
||||
return (wxDocument::IsModified() || (view && view->m_textsw->IsModified()));
|
||||
}
|
||||
|
||||
void TextEditDocument::Modify(bool mod)
|
||||
{
|
||||
TextEditView *view = (TextEditView *)GetFirstView();
|
||||
TextEditView* view = GetFirstView();
|
||||
|
||||
wxDocument::Modify(mod);
|
||||
|
||||
if (!mod && view && view->textsw)
|
||||
view->textsw->DiscardEdits();
|
||||
if ((!mod) && view && view->m_textsw)
|
||||
{
|
||||
view->m_textsw->DiscardEdits();
|
||||
}
|
||||
}
|
||||
|
||||
TextEditView* TextEditDocument::GetFirstView() const
|
||||
{
|
||||
wxView* view = wxDocument::GetFirstView();
|
||||
return view ? wxStaticCast(view, TextEditView) : NULL;
|
||||
}
|
||||
|
||||
|
@@ -9,8 +9,8 @@
|
||||
// Licence: wxWindows license
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef __DOCSAMPLEH__
|
||||
#define __DOCSAMPLEH__
|
||||
#ifndef __DOC_H__
|
||||
#define __DOC_H__
|
||||
|
||||
#include "wx/docview.h"
|
||||
#include "wx/cmdproc.h"
|
||||
@@ -29,42 +29,41 @@ class DoodleLine: public wxObject
|
||||
class DoodleSegment: public wxObject
|
||||
{
|
||||
public:
|
||||
wxList lines;
|
||||
wxList m_lines;
|
||||
|
||||
DoodleSegment(void){};
|
||||
DoodleSegment(const DoodleSegment& seg);
|
||||
~DoodleSegment(void);
|
||||
DoodleSegment() : wxObject() {}
|
||||
DoodleSegment(const DoodleSegment&);
|
||||
virtual ~DoodleSegment();
|
||||
|
||||
void Draw(wxDC* dc);
|
||||
|
||||
#if wxUSE_STD_IOSTREAM
|
||||
wxSTD ostream& SaveObject(wxSTD ostream& text_stream);
|
||||
wxSTD istream& LoadObject(wxSTD istream& text_stream);
|
||||
wxSTD ostream& SaveObject(wxSTD ostream&);
|
||||
wxSTD istream& LoadObject(wxSTD istream&);
|
||||
#else
|
||||
wxOutputStream& SaveObject(wxOutputStream& stream);
|
||||
wxInputStream& LoadObject(wxInputStream& stream);
|
||||
wxOutputStream& SaveObject(wxOutputStream&);
|
||||
wxInputStream& LoadObject(wxInputStream&);
|
||||
#endif
|
||||
};
|
||||
|
||||
class DrawingDocument: public wxDocument
|
||||
{
|
||||
DECLARE_DYNAMIC_CLASS(DrawingDocument)
|
||||
private:
|
||||
public:
|
||||
wxList doodleSegments;
|
||||
wxList m_doodleSegments;
|
||||
|
||||
DrawingDocument(void){};
|
||||
~DrawingDocument(void);
|
||||
DrawingDocument() : wxDocument() {}
|
||||
virtual ~DrawingDocument();
|
||||
|
||||
#if wxUSE_STD_IOSTREAM
|
||||
wxSTD ostream& SaveObject(wxSTD ostream& text_stream);
|
||||
wxSTD istream& LoadObject(wxSTD istream& text_stream);
|
||||
wxSTD ostream& SaveObject(wxSTD ostream&);
|
||||
wxSTD istream& LoadObject(wxSTD istream&);
|
||||
#else
|
||||
wxOutputStream& SaveObject(wxOutputStream& stream);
|
||||
wxInputStream& LoadObject(wxInputStream& stream);
|
||||
wxOutputStream& SaveObject(wxOutputStream&);
|
||||
wxInputStream& LoadObject(wxInputStream&);
|
||||
#endif
|
||||
|
||||
inline wxList& GetDoodleSegments(void) const { return (wxList&) doodleSegments; };
|
||||
inline wxList& GetDoodleSegments() const { return (wxList&) m_doodleSegments; };
|
||||
};
|
||||
|
||||
#define DOODLE_CUT 1
|
||||
@@ -73,33 +72,35 @@ class DrawingDocument: public wxDocument
|
||||
class DrawingCommand : public wxCommand
|
||||
{
|
||||
protected:
|
||||
DoodleSegment *segment;
|
||||
DrawingDocument *doc;
|
||||
int cmd;
|
||||
DoodleSegment* m_segment;
|
||||
DrawingDocument* m_doc;
|
||||
int m_cmd;
|
||||
public:
|
||||
DrawingCommand(const wxString& name, int cmd, DrawingDocument *ddoc, DoodleSegment *seg);
|
||||
~DrawingCommand(void);
|
||||
DrawingCommand(const wxString& name, int cmd, DrawingDocument*, DoodleSegment*);
|
||||
virtual ~DrawingCommand();
|
||||
|
||||
bool Do(void);
|
||||
bool Undo(void);
|
||||
bool Do();
|
||||
bool Undo();
|
||||
};
|
||||
|
||||
class TextEditView;
|
||||
class TextEditDocument : public wxDocument
|
||||
{
|
||||
DECLARE_DYNAMIC_CLASS(TextEditDocument)
|
||||
private:
|
||||
public:
|
||||
/*
|
||||
wxSTD ostream& SaveObject(wxSTD ostream& stream);
|
||||
wxSTD istream& LoadObject(wxSTD istream& stream);
|
||||
wxSTD ostream& SaveObject(wxSTD ostream&);
|
||||
wxSTD istream& LoadObject(wxSTD istream&);
|
||||
*/
|
||||
TextEditView* GetFirstView() const;
|
||||
|
||||
virtual bool OnSaveDocument(const wxString& filename);
|
||||
virtual bool OnOpenDocument(const wxString& filename);
|
||||
virtual bool IsModified(void) const;
|
||||
virtual bool IsModified() const;
|
||||
virtual void Modify(bool mod);
|
||||
|
||||
TextEditDocument(void) {}
|
||||
~TextEditDocument(void) {}
|
||||
TextEditDocument() {}
|
||||
virtual ~TextEditDocument() {}
|
||||
};
|
||||
|
||||
|
||||
|
@@ -36,61 +36,67 @@
|
||||
#include "docview.h"
|
||||
#include "doc.h"
|
||||
#include "view.h"
|
||||
#include "wx/stockitem.h"
|
||||
|
||||
MyFrame *frame = (MyFrame *) NULL;
|
||||
static MyFrame* frame = NULL;
|
||||
|
||||
IMPLEMENT_APP(MyApp)
|
||||
|
||||
MyApp::MyApp(void)
|
||||
{
|
||||
m_docManager = (wxDocManager *) NULL;
|
||||
m_docManager = NULL;
|
||||
}
|
||||
|
||||
bool MyApp::OnInit(void)
|
||||
{
|
||||
if ( !wxApp::OnInit() )
|
||||
return false;
|
||||
//// Create a document manager
|
||||
SetAppName(wxT("DocView Demo"));
|
||||
|
||||
//// Create a document manager
|
||||
m_docManager = new wxDocManager;
|
||||
|
||||
//// Create a template relating drawing documents to their views
|
||||
(void) new wxDocTemplate((wxDocManager *) m_docManager, _T("Drawing"), _T("*.drw"), _T(""), _T("drw"), _T("Drawing Doc"), _T("Drawing View"),
|
||||
new wxDocTemplate(m_docManager, wxT("Drawing"), wxT("*.drw"), wxT(""), wxT("drw"), wxT("Drawing Doc"), wxT("Drawing View"),
|
||||
CLASSINFO(DrawingDocument), CLASSINFO(DrawingView));
|
||||
|
||||
//// Create a template relating text documents to their views
|
||||
(void) new wxDocTemplate(m_docManager, _T("Text"), _T("*.txt"), _T(""), _T("txt"), _T("Text Doc"), _T("Text View"),
|
||||
new wxDocTemplate(m_docManager, wxT("Text"), wxT("*.txt"), wxT(""), wxT("txt"), wxT("Text Doc"), wxT("Text View"),
|
||||
CLASSINFO(TextEditDocument), CLASSINFO(TextEditView));
|
||||
|
||||
//// Create the main frame window
|
||||
frame = new MyFrame((wxDocManager *) m_docManager, (wxFrame *) NULL,
|
||||
_T("DocView Demo"), wxPoint(0, 0), wxSize(500, 400),
|
||||
frame = new MyFrame(m_docManager, NULL,
|
||||
GetAppDisplayName(), wxPoint(0, 0), wxSize(500, 400),
|
||||
wxDEFAULT_FRAME_STYLE | wxNO_FULL_REPAINT_ON_RESIZE);
|
||||
|
||||
//// Give it an icon (this is ignored in MDI mode: uses resources)
|
||||
#ifdef __WXMSW__
|
||||
frame->SetIcon(wxIcon(_T("doc")));
|
||||
frame->SetIcon(wxIcon(wxT("doc")));
|
||||
#endif
|
||||
|
||||
//// Make a menubar
|
||||
wxMenu *file_menu = new wxMenu;
|
||||
wxMenu *edit_menu = (wxMenu *) NULL;
|
||||
wxMenu *edit_menu = NULL;
|
||||
|
||||
file_menu->Append(wxID_NEW, _T("&New...\tCtrl-N"));
|
||||
file_menu->Append(wxID_OPEN, _T("&Open...\tCtrl-X"));
|
||||
file_menu->Append(wxID_NEW);
|
||||
file_menu->Append(wxID_OPEN);
|
||||
|
||||
file_menu->AppendSeparator();
|
||||
file_menu->Append(wxID_EXIT, _T("E&xit\tAlt-X"));
|
||||
file_menu->Append(wxID_EXIT);
|
||||
|
||||
// A nice touch: a history of files visited. Use this menu.
|
||||
m_docManager->FileHistoryUseMenu(file_menu);
|
||||
|
||||
wxMenu *help_menu = new wxMenu;
|
||||
help_menu->Append(DOCVIEW_ABOUT, _T("&About\tF1"));
|
||||
help_menu->Append(DOCVIEW_ABOUT);
|
||||
|
||||
wxMenuBar *menu_bar = new wxMenuBar;
|
||||
|
||||
menu_bar->Append(file_menu, _T("&File"));
|
||||
menu_bar->Append(file_menu, wxGetStockLabel(wxID_FILE));
|
||||
if (edit_menu)
|
||||
menu_bar->Append(edit_menu, _T("&Edit"));
|
||||
menu_bar->Append(help_menu, _T("&Help"));
|
||||
menu_bar->Append(edit_menu, wxGetStockLabel(wxID_EDIT));
|
||||
menu_bar->Append(help_menu, wxGetStockLabel(wxID_HELP));
|
||||
|
||||
#ifdef __WXMAC__
|
||||
wxMenuBar::MacSetCommonMenuBar(menu_bar);
|
||||
@@ -109,7 +115,7 @@ bool MyApp::OnInit(void)
|
||||
|
||||
int MyApp::OnExit(void)
|
||||
{
|
||||
delete m_docManager;
|
||||
wxDELETE(m_docManager)
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -122,60 +128,62 @@ wxMDIChildFrame *MyApp::CreateChildFrame(wxDocument *doc, wxView *view, bool isC
|
||||
{
|
||||
//// Make a child frame
|
||||
wxDocMDIChildFrame *subframe =
|
||||
new wxDocMDIChildFrame(doc, view, GetMainFrame(), wxID_ANY, _T("Child Frame"),
|
||||
new wxDocMDIChildFrame(doc, view, GetMainFrame(), wxID_ANY, wxT("Child Frame"),
|
||||
wxPoint(10, 10), wxSize(300, 300),
|
||||
wxDEFAULT_FRAME_STYLE |
|
||||
wxNO_FULL_REPAINT_ON_RESIZE);
|
||||
|
||||
#ifdef __WXMSW__
|
||||
subframe->SetIcon(wxString(isCanvas ? _T("chart") : _T("notepad")));
|
||||
subframe->SetIcon(wxString(isCanvas ? wxT("chart") : wxT("notepad")));
|
||||
#endif
|
||||
#ifdef __X__
|
||||
subframe->SetIcon(wxIcon(_T("doc.xbm")));
|
||||
subframe->SetIcon(wxIcon(wxT("doc.xbm")));
|
||||
#endif
|
||||
|
||||
//// Make a menubar
|
||||
wxMenu *file_menu = new wxMenu;
|
||||
|
||||
file_menu->Append(wxID_NEW, _T("&New..."));
|
||||
file_menu->Append(wxID_OPEN, _T("&Open..."));
|
||||
file_menu->Append(wxID_CLOSE, _T("&Close"));
|
||||
file_menu->Append(wxID_SAVE, _T("&Save"));
|
||||
file_menu->Append(wxID_SAVEAS, _T("Save &As..."));
|
||||
file_menu->Append(wxID_NEW);
|
||||
file_menu->Append(wxID_OPEN);
|
||||
file_menu->Append(wxID_CLOSE);
|
||||
file_menu->Append(wxID_SAVE);
|
||||
file_menu->Append(wxID_SAVEAS);
|
||||
|
||||
if (isCanvas)
|
||||
{
|
||||
file_menu->AppendSeparator();
|
||||
file_menu->Append(wxID_PRINT, _T("&Print..."));
|
||||
file_menu->Append(wxID_PRINT_SETUP, _T("Print &Setup..."));
|
||||
file_menu->Append(wxID_PREVIEW, _T("Print Pre&view"));
|
||||
file_menu->Append(wxID_PRINT);
|
||||
file_menu->Append(wxID_PRINT_SETUP, wxT("Print &Setup..."));
|
||||
file_menu->Append(wxID_PREVIEW);
|
||||
}
|
||||
|
||||
file_menu->AppendSeparator();
|
||||
file_menu->Append(wxID_EXIT, _T("E&xit"));
|
||||
|
||||
wxMenu *edit_menu = (wxMenu *) NULL;
|
||||
file_menu->Append(wxID_EXIT);
|
||||
|
||||
wxMenu *edit_menu = new wxMenu;
|
||||
if (isCanvas)
|
||||
{
|
||||
edit_menu = new wxMenu;
|
||||
edit_menu->Append(wxID_UNDO, _T("&Undo"));
|
||||
edit_menu->Append(wxID_REDO, _T("&Redo"));
|
||||
edit_menu->Append(wxID_UNDO);
|
||||
edit_menu->Append(wxID_REDO);
|
||||
edit_menu->AppendSeparator();
|
||||
edit_menu->Append(DOCVIEW_CUT, _T("&Cut last segment"));
|
||||
edit_menu->Append(DOCVIEW_CUT, wxT("&Cut last segment"));
|
||||
|
||||
doc->GetCommandProcessor()->SetEditMenu(edit_menu);
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
edit_menu->Append(wxID_COPY);
|
||||
edit_menu->Append(wxID_PASTE);
|
||||
edit_menu->Append(wxID_SELECTALL);
|
||||
}
|
||||
wxMenu *help_menu = new wxMenu;
|
||||
help_menu->Append(DOCVIEW_ABOUT, _T("&About"));
|
||||
help_menu->Append(DOCVIEW_ABOUT);
|
||||
|
||||
wxMenuBar *menu_bar = new wxMenuBar;
|
||||
|
||||
menu_bar->Append(file_menu, _T("&File"));
|
||||
if (isCanvas)
|
||||
menu_bar->Append(edit_menu, _T("&Edit"));
|
||||
menu_bar->Append(help_menu, _T("&Help"));
|
||||
menu_bar->Append(file_menu, wxGetStockLabel(wxID_FILE));
|
||||
menu_bar->Append(edit_menu, wxGetStockLabel(wxID_EDIT));
|
||||
menu_bar->Append(help_menu, wxGetStockLabel(wxID_HELP));
|
||||
|
||||
//// Associate the menu bar with the frame
|
||||
subframe->SetMenuBar(menu_bar);
|
||||
@@ -194,25 +202,31 @@ END_EVENT_TABLE()
|
||||
|
||||
MyFrame::MyFrame(wxDocManager *manager, wxFrame *frame, const wxString& title,
|
||||
const wxPoint& pos, const wxSize& size, long type):
|
||||
wxDocMDIParentFrame(manager, frame, wxID_ANY, title, pos, size, type, _T("myFrame"))
|
||||
wxDocMDIParentFrame(manager, frame, wxID_ANY, title, pos, size, type, wxT("myFrame"))
|
||||
{
|
||||
editMenu = (wxMenu *) NULL;
|
||||
m_editMenu = NULL;
|
||||
}
|
||||
|
||||
void MyFrame::OnAbout(wxCommandEvent& WXUNUSED(event) )
|
||||
{
|
||||
(void)wxMessageBox(_T("DocView Demo\nAuthor: Julian Smart\nUsage: docview.exe"), _T("About DocView"));
|
||||
wxMessageBox(wxT("DocView Demo\nAuthor: Julian Smart\nUsage: docview.exe"), wxT("About DocView"));
|
||||
/*
|
||||
Better, but brings in adv lib
|
||||
wxAboutDialogInfo info;
|
||||
info.SetName(wxTheApp->GetAppDisplayName());
|
||||
info.AddDeveloper(wxT("Julian Smart"));
|
||||
wxAboutBox(info);
|
||||
*/
|
||||
}
|
||||
|
||||
// Creates a canvas. Called from view.cpp when a new drawing
|
||||
// view is created.
|
||||
MyCanvas *MyFrame::CreateCanvas(wxView *view, wxMDIChildFrame *parent)
|
||||
MyCanvas* MyFrame::CreateCanvas(DrawingView* view, wxMDIChildFrame* parent)
|
||||
{
|
||||
int width, height;
|
||||
parent->GetClientSize(&width, &height);
|
||||
wxSize size = parent->GetClientSize();
|
||||
|
||||
// Non-retained canvas
|
||||
MyCanvas *canvas = new MyCanvas(view, parent, wxPoint(0, 0), wxSize(width, height), 0);
|
||||
MyCanvas *canvas = new MyCanvas(view, parent, wxPoint(0, 0), size, 0);
|
||||
canvas->SetCursor(wxCursor(wxCURSOR_PENCIL));
|
||||
|
||||
// Give it scrollbars
|
||||
@@ -221,7 +235,7 @@ MyCanvas *MyFrame::CreateCanvas(wxView *view, wxMDIChildFrame *parent)
|
||||
return canvas;
|
||||
}
|
||||
|
||||
MyFrame *GetMainFrame(void)
|
||||
MyFrame* GetMainFrame()
|
||||
{
|
||||
return frame;
|
||||
}
|
||||
|
@@ -9,8 +9,8 @@
|
||||
// Licence: wxWindows license
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef __DOCVIEWSAMPLEH__
|
||||
#define __DOCVIEWSAMPLEH__
|
||||
#ifndef __DOCVIEW_H__
|
||||
#define __DOCVIEW_H__
|
||||
|
||||
#include "wx/mdi.h"
|
||||
#include "wx/docview.h"
|
||||
@@ -23,10 +23,10 @@ class MyApp: public wxApp
|
||||
{
|
||||
public:
|
||||
MyApp(void);
|
||||
bool OnInit(void);
|
||||
int OnExit(void);
|
||||
virtual bool OnInit();
|
||||
virtual int OnExit();
|
||||
|
||||
wxMDIChildFrame *CreateChildFrame(wxDocument *doc, wxView *view, bool isCanvas);
|
||||
wxMDIChildFrame* CreateChildFrame(wxDocument*, wxView*, bool isCanvas);
|
||||
|
||||
protected:
|
||||
wxDocManager* m_docManager;
|
||||
@@ -36,22 +36,24 @@ DECLARE_APP(MyApp)
|
||||
|
||||
// Define a new frame
|
||||
class MyCanvas;
|
||||
class DrawingView;
|
||||
class MyFrame: public wxDocMDIParentFrame
|
||||
{
|
||||
DECLARE_CLASS(MyFrame)
|
||||
public:
|
||||
wxMenu *editMenu;
|
||||
wxMenu* m_editMenu;
|
||||
|
||||
MyFrame(wxDocManager *manager, wxFrame *frame, const wxString& title, const wxPoint& pos, const wxSize& size,
|
||||
long type);
|
||||
MyFrame(wxDocManager*, wxFrame*, const wxString& title, const wxPoint&, const wxSize&, long type);
|
||||
|
||||
void OnAbout(wxCommandEvent& event);
|
||||
MyCanvas *CreateCanvas(wxView *view, wxMDIChildFrame *parent);
|
||||
MyCanvas* CreateCanvas(DrawingView*, wxMDIChildFrame*);
|
||||
|
||||
protected:
|
||||
void OnAbout(wxCommandEvent&);
|
||||
|
||||
DECLARE_EVENT_TABLE()
|
||||
DECLARE_CLASS(MyFrame)
|
||||
};
|
||||
|
||||
extern MyFrame *GetMainFrame(void);
|
||||
extern MyFrame* GetMainFrame();
|
||||
|
||||
#define DOCVIEW_CUT 1
|
||||
#define DOCVIEW_ABOUT wxID_ABOUT
|
||||
|
@@ -31,8 +31,8 @@
|
||||
IMPLEMENT_DYNAMIC_CLASS(DrawingView, wxView)
|
||||
|
||||
// For drawing lines in a canvas
|
||||
float xpos = -1;
|
||||
float ypos = -1;
|
||||
static float xpos = -1;
|
||||
static float ypos = -1;
|
||||
|
||||
BEGIN_EVENT_TABLE(DrawingView, wxView)
|
||||
EVT_MENU(DOODLE_CUT, DrawingView::OnCut)
|
||||
@@ -42,22 +42,27 @@ END_EVENT_TABLE()
|
||||
// windows for displaying the view.
|
||||
bool DrawingView::OnCreate(wxDocument *doc, long WXUNUSED(flags) )
|
||||
{
|
||||
frame = wxGetApp().CreateChildFrame(doc, this, true);
|
||||
frame->SetTitle(_T("DrawingView"));
|
||||
m_frame = wxGetApp().CreateChildFrame(doc, this, true);
|
||||
m_frame->SetTitle(wxT("DrawingView"));
|
||||
|
||||
canvas = GetMainFrame()->CreateCanvas(this, frame);
|
||||
m_canvas = GetMainFrame()->CreateCanvas(this, m_frame);
|
||||
#ifdef __X__
|
||||
// X seems to require a forced resize
|
||||
int x, y;
|
||||
frame->GetSize(&x, &y);
|
||||
frame->SetSize(wxDefaultCoord, wxDefaultCoord, x, y);
|
||||
m_frame->GetSize(&x, &y);
|
||||
m_frame->SetSize(wxDefaultCoord, wxDefaultCoord, x, y);
|
||||
#endif
|
||||
frame->Show(true);
|
||||
m_frame->Show(true);
|
||||
Activate(true);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
DrawingDocument* DrawingView::GetDocument()
|
||||
{
|
||||
return wxStaticCast(wxView::GetDocument(), DrawingDocument);
|
||||
}
|
||||
|
||||
// Sneakily gets used for default print/preview
|
||||
// as well as drawing on the screen.
|
||||
void DrawingView::OnDraw(wxDC *dc)
|
||||
@@ -65,7 +70,7 @@ void DrawingView::OnDraw(wxDC *dc)
|
||||
dc->SetFont(*wxNORMAL_FONT);
|
||||
dc->SetPen(*wxBLACK_PEN);
|
||||
|
||||
wxList::compatibility_iterator node = ((DrawingDocument *)GetDocument())->GetDoodleSegments().GetFirst();
|
||||
wxList::compatibility_iterator node = GetDocument()->GetDoodleSegments().GetFirst();
|
||||
while (node)
|
||||
{
|
||||
DoodleSegment* seg = (DoodleSegment*)node->GetData();
|
||||
@@ -76,8 +81,8 @@ void DrawingView::OnDraw(wxDC *dc)
|
||||
|
||||
void DrawingView::OnUpdate(wxView *WXUNUSED(sender), wxObject *WXUNUSED(hint))
|
||||
{
|
||||
if (canvas)
|
||||
canvas->Refresh();
|
||||
if (m_canvas)
|
||||
m_canvas->Refresh();
|
||||
|
||||
/* Is the following necessary?
|
||||
#ifdef __WXMSW__
|
||||
@@ -102,21 +107,21 @@ bool DrawingView::OnClose(bool deleteWindow)
|
||||
|
||||
// Clear the canvas in case we're in single-window mode,
|
||||
// and the canvas stays.
|
||||
canvas->ClearBackground();
|
||||
canvas->view = (wxView *) NULL;
|
||||
canvas = (MyCanvas *) NULL;
|
||||
m_canvas->ClearBackground();
|
||||
m_canvas->m_view = NULL;
|
||||
m_canvas = NULL;
|
||||
|
||||
wxString s(wxTheApp->GetAppDisplayName());
|
||||
if (frame)
|
||||
frame->SetTitle(s);
|
||||
if (m_frame)
|
||||
m_frame->SetTitle(s);
|
||||
|
||||
SetFrame((wxFrame*)NULL);
|
||||
SetFrame(NULL);
|
||||
|
||||
Activate(false);
|
||||
|
||||
if (deleteWindow)
|
||||
{
|
||||
delete frame;
|
||||
delete m_frame;
|
||||
return true;
|
||||
}
|
||||
return true;
|
||||
@@ -124,29 +129,28 @@ bool DrawingView::OnClose(bool deleteWindow)
|
||||
|
||||
void DrawingView::OnCut(wxCommandEvent& WXUNUSED(event) )
|
||||
{
|
||||
DrawingDocument *doc = (DrawingDocument *)GetDocument();
|
||||
doc->GetCommandProcessor()->Submit(new DrawingCommand(_T("Cut Last Segment"), DOODLE_CUT, doc, (DoodleSegment *) NULL));
|
||||
DrawingDocument* doc = GetDocument();
|
||||
doc->GetCommandProcessor()->Submit(new DrawingCommand(wxT("Cut Last Segment"), DOODLE_CUT, doc, NULL));
|
||||
}
|
||||
|
||||
IMPLEMENT_DYNAMIC_CLASS(TextEditView, wxView)
|
||||
|
||||
bool TextEditView::OnCreate(wxDocument* doc, long WXUNUSED(flags) )
|
||||
{
|
||||
frame = wxGetApp().CreateChildFrame(doc, this, false);
|
||||
m_frame = wxGetApp().CreateChildFrame(doc, this, false);
|
||||
|
||||
int width, height;
|
||||
frame->GetClientSize(&width, &height);
|
||||
textsw = new MyTextWindow(this, frame, wxPoint(0, 0), wxSize(width, height), wxTE_MULTILINE);
|
||||
frame->SetTitle(_T("TextEditView"));
|
||||
wxSize size = m_frame->GetClientSize();
|
||||
m_textsw = new MyTextWindow(this, m_frame, wxPoint(0, 0), size, wxTE_MULTILINE);
|
||||
m_frame->SetTitle(wxT("TextEditView"));
|
||||
|
||||
#ifdef __X__
|
||||
// X seems to require a forced resize
|
||||
int x, y;
|
||||
frame->GetSize(&x, &y);
|
||||
frame->SetSize(wxDefaultCoord, wxDefaultCoord, x, y);
|
||||
m_frame->GetSize(&x, &y);
|
||||
m_frame->SetSize(wxDefaultCoord, wxDefaultCoord, x, y);
|
||||
#endif
|
||||
|
||||
frame->Show(true);
|
||||
m_frame->Show(true);
|
||||
Activate(true);
|
||||
|
||||
return true;
|
||||
@@ -170,12 +174,27 @@ bool TextEditView::OnClose(bool deleteWindow)
|
||||
|
||||
if (deleteWindow)
|
||||
{
|
||||
delete frame;
|
||||
delete m_frame;
|
||||
return true;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool TextEditView::ProcessEvent(wxEvent& event)
|
||||
{
|
||||
bool processed = false;
|
||||
if (!processed) switch (event.GetId())
|
||||
{
|
||||
case wxID_COPY:
|
||||
case wxID_PASTE:
|
||||
case wxID_SELECTALL:
|
||||
processed = m_textsw->ProcessEvent(event);
|
||||
break;
|
||||
}
|
||||
if (!processed) processed = wxView::ProcessEvent(event);
|
||||
return processed;
|
||||
}
|
||||
|
||||
/*
|
||||
* Window implementations
|
||||
*/
|
||||
@@ -185,27 +204,27 @@ BEGIN_EVENT_TABLE(MyCanvas, wxScrolledWindow)
|
||||
END_EVENT_TABLE()
|
||||
|
||||
// Define a constructor for my canvas
|
||||
MyCanvas::MyCanvas(wxView *v, wxMDIChildFrame *frame, const wxPoint& pos, const wxSize& size, long style):
|
||||
MyCanvas::MyCanvas(DrawingView* view, wxMDIChildFrame* frame, const wxPoint& pos, const wxSize& size, long style):
|
||||
wxScrolledWindow(frame, wxID_ANY, pos, size, style)
|
||||
{
|
||||
view = v;
|
||||
m_view = view;
|
||||
}
|
||||
|
||||
// Define the repainting behaviour
|
||||
void MyCanvas::OnDraw(wxDC& dc)
|
||||
{
|
||||
if (view)
|
||||
view->OnDraw(& dc);
|
||||
if (m_view)
|
||||
m_view->OnDraw(& dc);
|
||||
}
|
||||
|
||||
// This implements a tiny doodling program. Drag the mouse using
|
||||
// the left button.
|
||||
void MyCanvas::OnMouseEvent(wxMouseEvent& event)
|
||||
{
|
||||
if (!view)
|
||||
if (!m_view)
|
||||
return;
|
||||
|
||||
static DoodleSegment *currentSegment = (DoodleSegment *) NULL;
|
||||
static DoodleSegment* currentSegment = NULL;
|
||||
|
||||
wxClientDC dc(this);
|
||||
PrepareDC(dc);
|
||||
@@ -216,24 +235,24 @@ void MyCanvas::OnMouseEvent(wxMouseEvent& event)
|
||||
|
||||
if (currentSegment && event.LeftUp())
|
||||
{
|
||||
if (currentSegment->lines.GetCount() == 0)
|
||||
if (currentSegment->m_lines.GetCount() == 0)
|
||||
{
|
||||
delete currentSegment;
|
||||
currentSegment = (DoodleSegment *) NULL;
|
||||
currentSegment = NULL;
|
||||
}
|
||||
else
|
||||
{
|
||||
// We've got a valid segment on mouse left up, so store it.
|
||||
DrawingDocument *doc = (DrawingDocument *)view->GetDocument();
|
||||
DrawingDocument* doc = m_view->GetDocument();
|
||||
|
||||
doc->GetCommandProcessor()->Submit(new DrawingCommand(_T("Add Segment"), DOODLE_ADD, doc, currentSegment));
|
||||
doc->GetCommandProcessor()->Submit(new DrawingCommand(wxT("Add Segment"), DOODLE_ADD, doc, currentSegment));
|
||||
|
||||
view->GetDocument()->Modify(true);
|
||||
currentSegment = (DoodleSegment *) NULL;
|
||||
m_view->GetDocument()->Modify(true);
|
||||
currentSegment = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
if (xpos > -1 && ypos > -1 && event.Dragging())
|
||||
if ( (xpos > -1) && (ypos > -1) && event.Dragging())
|
||||
{
|
||||
if (!currentSegment)
|
||||
currentSegment = new DoodleSegment;
|
||||
@@ -243,7 +262,7 @@ void MyCanvas::OnMouseEvent(wxMouseEvent& event)
|
||||
newLine->y1 = (long)ypos;
|
||||
newLine->x2 = pt.x;
|
||||
newLine->y2 = pt.y;
|
||||
currentSegment->lines.Append(newLine);
|
||||
currentSegment->m_lines.Append(newLine);
|
||||
|
||||
dc.DrawLine( (long)xpos, (long)ypos, pt.x, pt.y);
|
||||
}
|
||||
@@ -252,10 +271,9 @@ void MyCanvas::OnMouseEvent(wxMouseEvent& event)
|
||||
}
|
||||
|
||||
// Define a constructor for my text subwindow
|
||||
MyTextWindow::MyTextWindow(wxView *v, wxMDIChildFrame *frame, const wxPoint& pos, const wxSize& size, long style):
|
||||
wxTextCtrl(frame, wxID_ANY, _T(""), pos, size, style)
|
||||
MyTextWindow::MyTextWindow(wxView* view, wxMDIChildFrame* frame, const wxPoint& pos, const wxSize& size, long style):
|
||||
wxTextCtrl(frame, wxID_ANY, wxEmptyString, pos, size, style)
|
||||
{
|
||||
view = v;
|
||||
m_view = view;
|
||||
}
|
||||
|
||||
|
||||
|
@@ -9,69 +9,70 @@
|
||||
// Licence: wxWindows license
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef __VIEWSAMPLEH__
|
||||
#define __VIEWSAMPLEH__
|
||||
#ifndef __VIEW_H__
|
||||
#define __VIEW_H__
|
||||
|
||||
#include "wx/docview.h"
|
||||
|
||||
class DrawingView;
|
||||
class MyCanvas : public wxScrolledWindow
|
||||
{
|
||||
public:
|
||||
wxView *view;
|
||||
DrawingView* m_view;
|
||||
|
||||
MyCanvas(wxView *v, wxMDIChildFrame *frame, const wxPoint& pos, const wxSize& size, long style);
|
||||
virtual void OnDraw(wxDC& dc);
|
||||
void OnMouseEvent(wxMouseEvent& event);
|
||||
|
||||
private:
|
||||
MyCanvas(DrawingView*, wxMDIChildFrame*, const wxPoint&, const wxSize&, long style);
|
||||
virtual void OnDraw(wxDC&);
|
||||
protected:
|
||||
void OnMouseEvent(wxMouseEvent&);
|
||||
DECLARE_EVENT_TABLE()
|
||||
};
|
||||
|
||||
class MyTextWindow: public wxTextCtrl
|
||||
{
|
||||
public:
|
||||
wxView *view;
|
||||
wxView* m_view;
|
||||
|
||||
MyTextWindow(wxView *v, wxMDIChildFrame *frame, const wxPoint& pos, const wxSize& size, long style);
|
||||
MyTextWindow(wxView*, wxMDIChildFrame*, const wxPoint&, const wxSize&, long style);
|
||||
};
|
||||
|
||||
class DrawingDocument;
|
||||
class DrawingView : public wxView
|
||||
{
|
||||
public:
|
||||
wxMDIChildFrame *frame;
|
||||
MyCanvas *canvas;
|
||||
|
||||
DrawingView() { canvas = (MyCanvas *) NULL; frame = (wxMDIChildFrame *) NULL; }
|
||||
~DrawingView() {}
|
||||
|
||||
bool OnCreate(wxDocument *doc, long flags);
|
||||
void OnDraw(wxDC *dc);
|
||||
void OnUpdate(wxView *sender, wxObject *hint = (wxObject *) NULL);
|
||||
bool OnClose(bool deleteWindow = true);
|
||||
|
||||
void OnCut(wxCommandEvent& event);
|
||||
|
||||
private:
|
||||
DECLARE_DYNAMIC_CLASS(DrawingView)
|
||||
public:
|
||||
wxMDIChildFrame* m_frame;
|
||||
MyCanvas* m_canvas;
|
||||
|
||||
DrawingView() { m_canvas = NULL; m_frame = NULL; }
|
||||
virtual ~DrawingView() {}
|
||||
|
||||
virtual bool OnCreate(wxDocument *doc, long flags);
|
||||
virtual void OnDraw(wxDC *dc);
|
||||
virtual void OnUpdate(wxView *sender, wxObject *hint = NULL);
|
||||
virtual bool OnClose(bool deleteWindow = true);
|
||||
|
||||
DrawingDocument* GetDocument();
|
||||
|
||||
protected:
|
||||
void OnCut(wxCommandEvent& event);
|
||||
DECLARE_EVENT_TABLE()
|
||||
};
|
||||
|
||||
class TextEditView: public wxView
|
||||
{
|
||||
public:
|
||||
wxMDIChildFrame *frame;
|
||||
MyTextWindow *textsw;
|
||||
|
||||
TextEditView(): wxView() { frame = (wxMDIChildFrame *) NULL; textsw = (MyTextWindow *) NULL; }
|
||||
~TextEditView() {}
|
||||
|
||||
bool OnCreate(wxDocument *doc, long flags);
|
||||
void OnDraw(wxDC *dc);
|
||||
void OnUpdate(wxView *sender, wxObject *hint = (wxObject *) NULL);
|
||||
bool OnClose(bool deleteWindow = true);
|
||||
|
||||
private:
|
||||
DECLARE_DYNAMIC_CLASS(TextEditView)
|
||||
public:
|
||||
wxMDIChildFrame* m_frame;
|
||||
MyTextWindow* m_textsw;
|
||||
|
||||
TextEditView() : wxView() { m_frame = NULL; m_textsw = NULL; }
|
||||
virtual ~TextEditView() {}
|
||||
|
||||
virtual bool OnCreate(wxDocument*, long flags);
|
||||
virtual void OnDraw(wxDC* dc);
|
||||
virtual void OnUpdate(wxView *sender, wxObject *hint = NULL);
|
||||
virtual bool OnClose(bool deleteWindow = true);
|
||||
virtual bool ProcessEvent(wxEvent&);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
Reference in New Issue
Block a user