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:
Vadim Zeitlin
2008-04-06 13:57:23 +00:00
parent 74bf4e6430
commit 6bdf5153fe
12 changed files with 899 additions and 821 deletions

View File

@@ -39,7 +39,7 @@ IMPLEMENT_DYNAMIC_CLASS(DrawingDocument, wxDocument)
DrawingDocument::~DrawingDocument(void) DrawingDocument::~DrawingDocument(void)
{ {
WX_CLEAR_LIST(wxList, doodleSegments); WX_CLEAR_LIST(wxList, m_doodleSegments)
} }
#if wxUSE_STD_IOSTREAM #if wxUSE_STD_IOSTREAM
@@ -47,10 +47,10 @@ wxSTD ostream& DrawingDocument::SaveObject(wxSTD ostream& stream)
{ {
wxDocument::SaveObject(stream); wxDocument::SaveObject(stream);
wxInt32 n = doodleSegments.GetCount(); wxInt32 n = m_doodleSegments.GetCount();
stream << n << '\n'; stream << n << '\n';
wxList::compatibility_iterator node = doodleSegments.GetFirst(); wxList::compatibility_iterator node = m_doodleSegments.GetFirst();
while (node) while (node)
{ {
DoodleSegment *segment = (DoodleSegment *)node->GetData(); DoodleSegment *segment = (DoodleSegment *)node->GetData();
@@ -69,10 +69,10 @@ wxOutputStream& DrawingDocument::SaveObject(wxOutputStream& stream)
wxTextOutputStream text_stream( stream ); wxTextOutputStream text_stream( stream );
wxInt32 n = doodleSegments.GetCount(); wxInt32 n = m_doodleSegments.GetCount();
text_stream << n << '\n'; text_stream << n << '\n';
wxList::compatibility_iterator node = doodleSegments.GetFirst(); wxList::compatibility_iterator node = m_doodleSegments.GetFirst();
while (node) while (node)
{ {
DoodleSegment *segment = (DoodleSegment *)node->GetData(); DoodleSegment *segment = (DoodleSegment *)node->GetData();
@@ -98,7 +98,7 @@ wxSTD istream& DrawingDocument::LoadObject(wxSTD istream& stream)
{ {
DoodleSegment *segment = new DoodleSegment; DoodleSegment *segment = new DoodleSegment;
segment->LoadObject(stream); segment->LoadObject(stream);
doodleSegments.Append(segment); m_doodleSegments.Append(segment);
} }
return stream; return stream;
@@ -117,7 +117,7 @@ wxInputStream& DrawingDocument::LoadObject(wxInputStream& stream)
{ {
DoodleSegment *segment = new DoodleSegment; DoodleSegment *segment = new DoodleSegment;
segment->LoadObject(stream); segment->LoadObject(stream);
doodleSegments.Append(segment); m_doodleSegments.Append(segment);
} }
return stream; return stream;
@@ -126,7 +126,7 @@ wxInputStream& DrawingDocument::LoadObject(wxInputStream& stream)
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) while (node)
{ {
DoodleLine *line = (DoodleLine *)node->GetData(); DoodleLine *line = (DoodleLine *)node->GetData();
@@ -136,7 +136,7 @@ DoodleSegment::DoodleSegment(const DoodleSegment& seg):wxObject()
newLine->x2 = line->x2; newLine->x2 = line->x2;
newLine->y2 = line->y2; newLine->y2 = line->y2;
lines.Append(newLine); m_lines.Append(newLine);
node = node->GetNext(); node = node->GetNext();
} }
@@ -144,16 +144,16 @@ DoodleSegment::DoodleSegment(const DoodleSegment& seg):wxObject()
DoodleSegment::~DoodleSegment(void) DoodleSegment::~DoodleSegment(void)
{ {
WX_CLEAR_LIST(wxList, lines); WX_CLEAR_LIST(wxList, m_lines)
} }
#if wxUSE_STD_IOSTREAM #if wxUSE_STD_IOSTREAM
wxSTD ostream& DoodleSegment::SaveObject(wxSTD ostream& stream) wxSTD ostream& DoodleSegment::SaveObject(wxSTD ostream& stream)
{ {
wxInt32 n = lines.GetCount(); wxInt32 n = m_lines.GetCount();
stream << n << '\n'; stream << n << '\n';
wxList::compatibility_iterator node = lines.GetFirst(); wxList::compatibility_iterator node = m_lines.GetFirst();
while (node) while (node)
{ {
DoodleLine *line = (DoodleLine *)node->GetData(); DoodleLine *line = (DoodleLine *)node->GetData();
@@ -171,17 +171,17 @@ wxOutputStream &DoodleSegment::SaveObject(wxOutputStream& stream)
{ {
wxTextOutputStream text_stream( stream ); wxTextOutputStream text_stream( stream );
wxInt32 n = lines.GetCount(); wxInt32 n = m_lines.GetCount();
text_stream << n << _T("\n"); text_stream << n << wxT("\n");
wxList::compatibility_iterator node = lines.GetFirst(); wxList::compatibility_iterator node = m_lines.GetFirst();
while (node) while (node)
{ {
DoodleLine* line = (DoodleLine*)node->GetData(); DoodleLine* line = (DoodleLine*)node->GetData();
text_stream << line->x1 << _T(" ") << text_stream << line->x1 << wxT(" ") <<
line->y1 << _T(" ") << line->y1 << wxT(" ") <<
line->x2 << _T(" ") << line->x2 << wxT(" ") <<
line->y2 << _T("\n"); line->y2 << wxT("\n");
node = node->GetNext(); node = node->GetNext();
} }
@@ -202,7 +202,7 @@ wxSTD istream& DoodleSegment::LoadObject(wxSTD istream& stream)
line->y1 >> line->y1 >>
line->x2 >> line->x2 >>
line->y2; line->y2;
lines.Append(line); m_lines.Append(line);
} }
return stream; return stream;
@@ -222,7 +222,7 @@ wxInputStream &DoodleSegment::LoadObject(wxInputStream& stream)
line->y1 >> line->y1 >>
line->x2 >> line->x2 >>
line->y2; line->y2;
lines.Append(line); m_lines.Append(line);
} }
return stream; return stream;
@@ -231,7 +231,7 @@ wxInputStream &DoodleSegment::LoadObject(wxInputStream& stream)
void DoodleSegment::Draw(wxDC *dc) void DoodleSegment::Draw(wxDC *dc)
{ {
wxList::compatibility_iterator node = lines.GetFirst(); wxList::compatibility_iterator node = m_lines.GetFirst();
while (node) while (node)
{ {
DoodleLine *line = (DoodleLine *)node->GetData(); DoodleLine *line = (DoodleLine *)node->GetData();
@@ -244,46 +244,46 @@ void DoodleSegment::Draw(wxDC *dc)
* Implementation of drawing command * 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) wxCommand(true, name)
{ {
doc = ddoc; m_doc = doc;
segment = seg; m_segment = seg;
cmd = command; m_cmd = command;
} }
DrawingCommand::~DrawingCommand(void) DrawingCommand::~DrawingCommand(void)
{ {
if (segment) if (m_segment)
delete segment; delete m_segment;
} }
bool DrawingCommand::Do(void) bool DrawingCommand::Do(void)
{ {
switch (cmd) switch (m_cmd)
{ {
case DOODLE_CUT: case DOODLE_CUT:
{ {
// Cut the last segment // 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();
if (segment) if (m_segment)
delete segment; delete m_segment;
segment = (DoodleSegment *)node->GetData(); m_segment = (DoodleSegment*)node->GetData();
doc->GetDoodleSegments().Erase(node); m_doc->GetDoodleSegments().Erase(node);
doc->Modify(true); m_doc->Modify(true);
doc->UpdateAllViews(); m_doc->UpdateAllViews();
} }
break; break;
} }
case DOODLE_ADD: case DOODLE_ADD:
{ {
doc->GetDoodleSegments().Append(new DoodleSegment(*segment)); m_doc->GetDoodleSegments().Append(new DoodleSegment(*m_segment));
doc->Modify(true); m_doc->Modify(true);
doc->UpdateAllViews(); m_doc->UpdateAllViews();
break; break;
} }
} }
@@ -292,34 +292,34 @@ bool DrawingCommand::Do(void)
bool DrawingCommand::Undo(void) bool DrawingCommand::Undo(void)
{ {
switch (cmd) switch (m_cmd)
{ {
case DOODLE_CUT: case DOODLE_CUT:
{ {
// Paste the segment // Paste the segment
if (segment) if (m_segment)
{ {
doc->GetDoodleSegments().Append(segment); m_doc->GetDoodleSegments().Append(m_segment);
doc->Modify(true); m_doc->Modify(true);
doc->UpdateAllViews(); m_doc->UpdateAllViews();
segment = (DoodleSegment *) NULL; m_segment = NULL;
} }
doc->Modify(true); m_doc->Modify(true);
doc->UpdateAllViews(); m_doc->UpdateAllViews();
break; break;
} }
case DOODLE_ADD: case DOODLE_ADD:
{ {
// Cut the last segment // 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(); DoodleSegment* seg = (DoodleSegment*)node->GetData();
delete seg; delete seg;
doc->GetDoodleSegments().Erase(node); m_doc->GetDoodleSegments().Erase(node);
doc->Modify(true); m_doc->Modify(true);
doc->UpdateAllViews(); m_doc->UpdateAllViews();
} }
} }
} }
@@ -332,9 +332,9 @@ IMPLEMENT_DYNAMIC_CLASS(TextEditDocument, wxDocument)
// we override OnSave/OpenDocument instead of Save/LoadObject // we override OnSave/OpenDocument instead of Save/LoadObject
bool TextEditDocument::OnSaveDocument(const wxString& filename) 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; return false;
Modify(false); Modify(false);
#ifdef __WXMAC__ #ifdef __WXMAC__
@@ -346,8 +346,8 @@ bool TextEditDocument::OnSaveDocument(const wxString& filename)
bool TextEditDocument::OnOpenDocument(const wxString& filename) bool TextEditDocument::OnOpenDocument(const wxString& filename)
{ {
TextEditView *view = (TextEditView *)GetFirstView(); TextEditView* view = GetFirstView();
if (!view->textsw->LoadFile(filename)) if (!view->m_textsw->LoadFile(filename))
return false; return false;
SetFilename(filename, true); SetFilename(filename, true);
@@ -358,21 +358,23 @@ bool TextEditDocument::OnOpenDocument(const wxString& filename)
bool TextEditDocument::IsModified(void) const bool TextEditDocument::IsModified(void) const
{ {
TextEditView *view = (TextEditView *)GetFirstView(); TextEditView* view = GetFirstView();
if (view) return (wxDocument::IsModified() || (view && view->m_textsw->IsModified()));
{
return (wxDocument::IsModified() || view->textsw->IsModified());
}
else
return wxDocument::IsModified();
} }
void TextEditDocument::Modify(bool mod) void TextEditDocument::Modify(bool mod)
{ {
TextEditView *view = (TextEditView *)GetFirstView(); TextEditView* view = GetFirstView();
wxDocument::Modify(mod); wxDocument::Modify(mod);
if (!mod && view && view->textsw) if (!mod && view && view->m_textsw)
view->textsw->DiscardEdits(); view->m_textsw->DiscardEdits();
} }
TextEditView* TextEditDocument::GetFirstView() const
{
wxView* view = wxDocument::GetFirstView();
return view ? wxStaticCast(view, TextEditView) : NULL;
}

View File

@@ -9,8 +9,8 @@
// Licence: wxWindows license // Licence: wxWindows license
///////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////
#ifndef __DOCSAMPLEH__ #ifndef __DOC_H__
#define __DOCSAMPLEH__ #define __DOC_H__
#include "wx/docview.h" #include "wx/docview.h"
#include "wx/cmdproc.h" #include "wx/cmdproc.h"
@@ -29,11 +29,11 @@ public:
class DoodleSegment : public wxObject class DoodleSegment : public wxObject
{ {
public: public:
wxList lines; wxList m_lines;
DoodleSegment(void){}; DoodleSegment() : wxObject() {}
DoodleSegment(const DoodleSegment& seg); DoodleSegment(const DoodleSegment& seg);
~DoodleSegment(void); virtual ~DoodleSegment();
void Draw(wxDC *dc); void Draw(wxDC *dc);
#if wxUSE_STD_IOSTREAM #if wxUSE_STD_IOSTREAM
@@ -51,10 +51,10 @@ class DrawingDocument: public wxDocument
DECLARE_DYNAMIC_CLASS(DrawingDocument) DECLARE_DYNAMIC_CLASS(DrawingDocument)
private: private:
public: public:
wxList doodleSegments; wxList m_doodleSegments;
DrawingDocument(void){}; DrawingDocument() : wxDocument() {}
~DrawingDocument(void); virtual ~DrawingDocument();
#if wxUSE_STD_IOSTREAM #if wxUSE_STD_IOSTREAM
wxSTD ostream& SaveObject(wxSTD ostream& text_stream); wxSTD ostream& SaveObject(wxSTD ostream& text_stream);
@@ -64,7 +64,7 @@ public:
wxInputStream& LoadObject(wxInputStream& stream); wxInputStream& LoadObject(wxInputStream& stream);
#endif #endif
inline wxList& GetDoodleSegments(void) const { return (wxList&) doodleSegments; }; inline wxList& GetDoodleSegments() const { return (wxList&) m_doodleSegments; };
}; };
#define DOODLE_CUT 1 #define DOODLE_CUT 1
@@ -73,33 +73,34 @@ public:
class DrawingCommand : public wxCommand class DrawingCommand : public wxCommand
{ {
protected: protected:
DoodleSegment *segment; DoodleSegment* m_segment;
DrawingDocument *doc; DrawingDocument* m_doc;
int cmd; int m_cmd;
public: public:
DrawingCommand(const wxString& name, int cmd, DrawingDocument *ddoc, DoodleSegment *seg); DrawingCommand(const wxString& name, int cmd, DrawingDocument*, DoodleSegment*);
~DrawingCommand(void); virtual ~DrawingCommand();
bool Do(void); bool Do(void);
bool Undo(void); bool Undo(void);
}; };
class TextEditView;
class TextEditDocument : public wxDocument class TextEditDocument : public wxDocument
{ {
DECLARE_DYNAMIC_CLASS(TextEditDocument) DECLARE_DYNAMIC_CLASS(TextEditDocument)
private:
public: public:
TextEditDocument() : wxDocument() {}
virtual ~TextEditDocument() {}
/* /*
wxSTD ostream& SaveObject(wxSTD ostream& stream); wxSTD ostream& SaveObject(wxSTD ostream&);
wxSTD istream& LoadObject(wxSTD istream& stream); wxSTD istream& LoadObject(wxSTD istream&);
*/ */
TextEditView* GetFirstView() const;
virtual bool OnSaveDocument(const wxString& filename); virtual bool OnSaveDocument(const wxString& filename);
virtual bool OnOpenDocument(const wxString& filename); virtual bool OnOpenDocument(const wxString& filename);
virtual bool IsModified(void) const; virtual bool IsModified(void) const;
virtual void Modify(bool mod); virtual void Modify(bool mod);
TextEditDocument(void) {}
~TextEditDocument(void) {}
}; };

View File

@@ -39,8 +39,9 @@
#ifdef __WXMAC__ #ifdef __WXMAC__
#include "wx/filename.h" #include "wx/filename.h"
#endif #endif
#include "wx/stockitem.h"
MyFrame *frame = (MyFrame *) NULL; static MyFrame* frame = NULL;
// In single window mode, don't have any child windows; use // In single window mode, don't have any child windows; use
// main window. // main window.
@@ -50,13 +51,15 @@ IMPLEMENT_APP(MyApp)
MyApp::MyApp(void) MyApp::MyApp(void)
{ {
m_docManager = (wxDocManager *) NULL; m_docManager = NULL;
} }
bool MyApp::OnInit(void) bool MyApp::OnInit(void)
{ {
if ( !wxApp::OnInit() ) if ( !wxApp::OnInit() )
return false; return false;
SetAppName(wxT("DocView Demo"));
//// Find out if we're: //// Find out if we're:
//// multiple window: multiple windows, each view in a separate frame //// 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 //// In single window mode, we only allow one document type
if (argc > 1) if (argc > 1)
{ {
if (wxStrcmp(argv[1], _T("-single")) == 0) if (wxStrcmp(argv[1], wxT("-single")) == 0)
{ {
singleWindowMode = true; singleWindowMode = true;
} }
@@ -74,7 +77,7 @@ bool MyApp::OnInit(void)
m_docManager = new wxDocManager; m_docManager = new wxDocManager;
//// Create a template relating drawing documents to their views //// 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)); CLASSINFO(DrawingDocument), CLASSINFO(DrawingView));
#ifdef __WXMAC__ #ifdef __WXMAC__
wxFileName::MacRegisterDefaultTypeAndCreator( wxT("drw") , 'WXMB' , 'WXMA' ) ; wxFileName::MacRegisterDefaultTypeAndCreator( wxT("drw") , 'WXMB' , 'WXMA' ) ;
@@ -90,7 +93,7 @@ bool MyApp::OnInit(void)
else else
{ {
//// Create a template relating text documents to their views //// 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)); CLASSINFO(TextEditDocument), CLASSINFO(TextEditView));
#ifdef __WXMAC__ #ifdef __WXMAC__
wxFileName::MacRegisterDefaultTypeAndCreator( wxT("txt") , 'TEXT' , 'WXMA' ) ; wxFileName::MacRegisterDefaultTypeAndCreator( wxT("txt") , 'TEXT' , 'WXMA' ) ;
@@ -98,57 +101,57 @@ bool MyApp::OnInit(void)
} }
//// Create the main frame window //// 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) //// Give it an icon (this is ignored in MDI mode: uses resources)
#ifdef __WXMSW__ #ifdef __WXMSW__
frame->SetIcon(wxIcon(_T("doc_icn"))); frame->SetIcon(wxIcon(wxT("doc_icn")));
#endif #endif
//// Make a menubar //// Make a menubar
wxMenu *file_menu = new wxMenu; 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_NEW);
file_menu->Append(wxID_OPEN, _T("&Open...")); file_menu->Append(wxID_OPEN);
if (singleWindowMode) if (singleWindowMode)
{ {
file_menu->Append(wxID_CLOSE, _T("&Close")); file_menu->Append(wxID_CLOSE);
file_menu->Append(wxID_SAVE, _T("&Save")); file_menu->Append(wxID_SAVE);
file_menu->Append(wxID_SAVEAS, _T("Save &As...")); file_menu->Append(wxID_SAVEAS);
file_menu->AppendSeparator(); file_menu->AppendSeparator();
file_menu->Append(wxID_PRINT, _T("&Print...")); file_menu->Append(wxID_PRINT);
file_menu->Append(wxID_PRINT_SETUP, _T("Print &Setup...")); file_menu->Append(wxID_PRINT_SETUP, wxT("Print &Setup..."));
file_menu->Append(wxID_PREVIEW, _T("Print Pre&view")); file_menu->Append(wxID_PREVIEW);
edit_menu = new wxMenu; edit_menu = new wxMenu;
edit_menu->Append(wxID_UNDO, _T("&Undo")); edit_menu->Append(wxID_UNDO);
edit_menu->Append(wxID_REDO, _T("&Redo")); edit_menu->Append(wxID_REDO);
edit_menu->AppendSeparator(); 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->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. // A nice touch: a history of files visited. Use this menu.
m_docManager->FileHistoryUseMenu(file_menu); m_docManager->FileHistoryUseMenu(file_menu);
wxMenu *help_menu = new wxMenu; wxMenu *help_menu = new wxMenu;
help_menu->Append(DOCVIEW_ABOUT, _T("&About")); help_menu->Append(DOCVIEW_ABOUT);
wxMenuBar *menu_bar = new wxMenuBar; wxMenuBar *menu_bar = new wxMenuBar;
menu_bar->Append(file_menu, _T("&File")); menu_bar->Append(file_menu, wxGetStockLabel(wxID_FILE));
if (edit_menu) if (edit_menu)
menu_bar->Append(edit_menu, _T("&Edit")); menu_bar->Append(edit_menu, wxGetStockLabel(wxID_EDIT));
menu_bar->Append(help_menu, _T("&Help")); menu_bar->Append(help_menu, wxGetStockLabel(wxID_HELP));
if (singleWindowMode) if (singleWindowMode)
frame->canvas = frame->CreateCanvas((wxView *) NULL, frame); frame->m_canvas = frame->CreateCanvas(NULL, frame);
//// Associate the menu bar with the frame //// Associate the menu bar with the frame
frame->SetMenuBar(menu_bar); frame->SetMenuBar(menu_bar);
@@ -175,52 +178,56 @@ int MyApp::OnExit(void)
wxFrame *MyApp::CreateChildFrame(wxDocument *doc, wxView *view, bool isCanvas) wxFrame *MyApp::CreateChildFrame(wxDocument *doc, wxView *view, bool isCanvas)
{ {
//// Make a child frame //// 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); wxPoint(10, 10), wxSize(300, 300), wxDEFAULT_FRAME_STYLE);
#ifdef __WXMSW__ #ifdef __WXMSW__
subframe->SetIcon(wxString(isCanvas ? _T("chrt_icn") : _T("notepad_icn"))); subframe->SetIcon(wxString(isCanvas ? wxT("chrt_icn") : wxT("notepad_icn")));
#endif #endif
//// Make a menubar //// Make a menubar
wxMenu *file_menu = new wxMenu; wxMenu *file_menu = new wxMenu;
file_menu->Append(wxID_NEW, _T("&New...")); file_menu->Append(wxID_NEW);
file_menu->Append(wxID_OPEN, _T("&Open...")); file_menu->Append(wxID_OPEN);
file_menu->Append(wxID_CLOSE, _T("&Close")); file_menu->Append(wxID_CLOSE);
file_menu->Append(wxID_SAVE, _T("&Save")); file_menu->Append(wxID_SAVE);
file_menu->Append(wxID_SAVEAS, _T("Save &As...")); file_menu->Append(wxID_SAVEAS);
if (isCanvas) if (isCanvas)
{ {
file_menu->AppendSeparator(); file_menu->AppendSeparator();
file_menu->Append(wxID_PRINT, _T("&Print...")); file_menu->Append(wxID_PRINT);
file_menu->Append(wxID_PRINT_SETUP, _T("Print &Setup...")); file_menu->Append(wxID_PRINT_SETUP, wxT("Print &Setup..."));
file_menu->Append(wxID_PREVIEW, _T("Print Pre&view")); file_menu->Append(wxID_PREVIEW);
} }
wxMenu *edit_menu = (wxMenu *) NULL; wxMenu *edit_menu = new wxMenu;
if (isCanvas) if (isCanvas)
{ {
edit_menu = new wxMenu; edit_menu->Append(wxID_UNDO);
edit_menu->Append(wxID_UNDO, _T("&Undo")); edit_menu->Append(wxID_REDO);
edit_menu->Append(wxID_REDO, _T("&Redo"));
edit_menu->AppendSeparator(); 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); 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; wxMenu *help_menu = new wxMenu;
help_menu->Append(DOCVIEW_ABOUT, _T("&About")); help_menu->Append(DOCVIEW_ABOUT);
wxMenuBar *menu_bar = new wxMenuBar; wxMenuBar *menu_bar = new wxMenuBar;
menu_bar->Append(file_menu, _T("&File")); menu_bar->Append(file_menu, wxGetStockLabel(wxID_FILE));
if (isCanvas) menu_bar->Append(edit_menu, wxGetStockLabel(wxID_EDIT));
menu_bar->Append(edit_menu, _T("&Edit")); menu_bar->Append(help_menu, wxGetStockLabel(wxID_HELP));
menu_bar->Append(help_menu, _T("&Help"));
//// Associate the menu bar with the frame //// Associate the menu bar with the frame
subframe->SetMenuBar(menu_bar); 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) wxDocParentFrame(manager, frame, id, title, pos, size, type)
{ {
// This pointer only needed if in single window mode // This pointer only needed if in single window mode
canvas = (MyCanvas *) NULL; m_canvas = NULL;
editMenu = (wxMenu *) NULL; m_editMenu = NULL;
} }
void MyFrame::OnAbout(wxCommandEvent& WXUNUSED(event) ) 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 // 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, // view is created, or in OnInit as a child of the main window,
// if in 'single window' mode. // if in 'single window' mode.
MyCanvas *MyFrame::CreateCanvas(wxView *view, wxFrame *parent) MyCanvas *MyFrame::CreateCanvas(DrawingView* view, wxFrame *parent)
{ {
int width, height; wxSize size = parent->GetClientSize();
parent->GetClientSize(&width, &height);
// Non-retained canvas // 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)); canvas->SetCursor(wxCursor(wxCURSOR_PENCIL));
// Give it scrollbars // Give it scrollbars

View File

@@ -9,8 +9,8 @@
// Licence: wxWindows license // Licence: wxWindows license
///////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////
#ifndef __DOCVIEWSAMPLEH__ #ifndef __DOCVIEW_H__
#define __DOCVIEWSAMPLEH__ #define __DOCVIEW_H__
#include "wx/docview.h" #include "wx/docview.h"
@@ -34,25 +34,27 @@ DECLARE_APP(MyApp)
// Define a new frame // Define a new frame
class MyCanvas; class MyCanvas;
class DrawingView;
class MyFrame : public wxDocParentFrame class MyFrame : public wxDocParentFrame
{ {
DECLARE_CLASS(MyFrame) DECLARE_CLASS(MyFrame)
public: public:
wxMenu *editMenu; wxMenu* m_editMenu;
// This pointer only needed if in single window mode // 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, MyFrame(wxDocManager *manager, wxFrame *frame, wxWindowID id, const wxString& title, const wxPoint& pos, const wxSize& size,
const long type); const long type);
void OnAbout(wxCommandEvent& event); MyCanvas* CreateCanvas(DrawingView*, wxFrame *parent);
MyCanvas *CreateCanvas(wxView *view, wxFrame *parent);
protected:
void OnAbout(wxCommandEvent& event);
DECLARE_EVENT_TABLE() DECLARE_EVENT_TABLE()
}; };
extern MyFrame *GetMainFrame(void); extern MyFrame *GetMainFrame();
#define DOCVIEW_CUT 1 #define DOCVIEW_CUT 1
#define DOCVIEW_ABOUT wxID_ABOUT #define DOCVIEW_ABOUT wxID_ABOUT

View File

@@ -31,8 +31,8 @@
IMPLEMENT_DYNAMIC_CLASS(DrawingView, wxView) IMPLEMENT_DYNAMIC_CLASS(DrawingView, wxView)
// For drawing lines in a canvas // For drawing lines in a canvas
float xpos = -1; static float xpos = -1;
float ypos = -1; static float ypos = -1;
BEGIN_EVENT_TABLE(DrawingView, wxView) BEGIN_EVENT_TABLE(DrawingView, wxView)
EVT_MENU(DOODLE_CUT, DrawingView::OnCut) EVT_MENU(DOODLE_CUT, DrawingView::OnCut)
@@ -45,34 +45,34 @@ bool DrawingView::OnCreate(wxDocument *doc, long WXUNUSED(flags) )
if (!singleWindowMode) if (!singleWindowMode)
{ {
// Multiple windows // Multiple windows
frame = wxGetApp().CreateChildFrame(doc, this, true); m_frame = wxGetApp().CreateChildFrame(doc, this, true);
frame->SetTitle(_T("DrawingView")); m_frame->SetTitle(wxT("DrawingView"));
canvas = GetMainFrame()->CreateCanvas(this, frame); m_canvas = GetMainFrame()->CreateCanvas(this, m_frame);
#ifdef __X__ #ifdef __X__
// X seems to require a forced resize // X seems to require a forced resize
int x, y; int x, y;
frame->GetSize(&x, &y); m_frame->GetSize(&x, &y);
frame->SetSize(wxDefaultCoord, wxDefaultCoord, x, y); m_frame->SetSize(wxDefaultCoord, wxDefaultCoord, x, y);
#endif #endif
frame->Show(true); m_frame->Show(true);
} }
else else
{ {
// Single-window mode // Single-window mode
frame = GetMainFrame(); m_frame = GetMainFrame();
canvas = GetMainFrame()->canvas; m_canvas = GetMainFrame()->m_canvas;
canvas->view = this; m_canvas->m_view = this;
// Associate the appropriate frame with this view. // Associate the appropriate frame with this view.
SetFrame(frame); SetFrame(m_frame);
// Make sure the document manager knows that this is the // Make sure the document manager knows that this is the
// current view. // current view.
Activate(true); Activate(true);
// Initialize the edit menu Undo and Redo items // 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(); doc->GetCommandProcessor()->Initialize();
} }
@@ -86,7 +86,7 @@ void DrawingView::OnDraw(wxDC *dc)
dc->SetFont(*wxNORMAL_FONT); dc->SetFont(*wxNORMAL_FONT);
dc->SetPen(*wxBLACK_PEN); dc->SetPen(*wxBLACK_PEN);
wxList::compatibility_iterator node = ((DrawingDocument *)GetDocument())->GetDoodleSegments().GetFirst(); wxList::compatibility_iterator node = GetDocument()->GetDoodleSegments().GetFirst();
while (node) while (node)
{ {
DoodleSegment *seg = (DoodleSegment *)node->GetData(); 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)) void DrawingView::OnUpdate(wxView *WXUNUSED(sender), wxObject *WXUNUSED(hint))
{ {
if (canvas) if (m_canvas)
canvas->Refresh(); m_canvas->Refresh();
/* Is the following necessary? /* Is the following necessary?
#ifdef __WXMSW__ #ifdef __WXMSW__
@@ -123,21 +128,21 @@ bool DrawingView::OnClose(bool deleteWindow)
// Clear the canvas in case we're in single-window mode, // Clear the canvas in case we're in single-window mode,
// and the canvas stays. // and the canvas stays.
canvas->ClearBackground(); m_canvas->ClearBackground();
canvas->view = (wxView *) NULL; m_canvas->m_view = NULL;
canvas = (MyCanvas *) NULL; m_canvas = NULL;
wxString s(wxTheApp->GetAppDisplayName()); wxString s(wxTheApp->GetAppDisplayName());
if (frame) if (m_frame)
frame->SetTitle(s); m_frame->SetTitle(s);
SetFrame((wxFrame *) NULL); SetFrame(NULL);
Activate(false); Activate(false);
if (deleteWindow && !singleWindowMode) if (deleteWindow && !singleWindowMode)
{ {
delete frame; delete m_frame;
return true; return true;
} }
return true; return true;
@@ -145,20 +150,19 @@ bool DrawingView::OnClose(bool deleteWindow)
void DrawingView::OnCut(wxCommandEvent& WXUNUSED(event) ) void DrawingView::OnCut(wxCommandEvent& WXUNUSED(event) )
{ {
DrawingDocument *doc = (DrawingDocument *)GetDocument(); DrawingDocument* doc = GetDocument();
doc->GetCommandProcessor()->Submit(new DrawingCommand(_T("Cut Last Segment"), DOODLE_CUT, doc, (DoodleSegment *) NULL)); doc->GetCommandProcessor()->Submit(new DrawingCommand(wxT("Cut Last Segment"), DOODLE_CUT, doc, NULL));
} }
IMPLEMENT_DYNAMIC_CLASS(TextEditView, wxView) IMPLEMENT_DYNAMIC_CLASS(TextEditView, wxView)
bool TextEditView::OnCreate(wxDocument *doc, long WXUNUSED(flags) ) bool TextEditView::OnCreate(wxDocument *doc, long WXUNUSED(flags) )
{ {
frame = wxGetApp().CreateChildFrame(doc, this, false); m_frame = wxGetApp().CreateChildFrame(doc, this, false);
int width, height; wxSize size = m_frame->GetClientSize();
frame->GetClientSize(&width, &height); m_textsw = new MyTextWindow(this, m_frame, wxPoint(0, 0), size, wxTE_MULTILINE);
textsw = new MyTextWindow(this, frame, wxPoint(0, 0), wxSize(width, height), wxTE_MULTILINE); m_frame->SetTitle(wxT("TextEditView"));
frame->SetTitle(_T("TextEditView"));
#ifdef __X__ #ifdef __X__
// X seems to require a forced resize // 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); frame->SetSize(wxDefaultCoord, wxDefaultCoord, x, y);
#endif #endif
frame->Show(true); m_frame->Show(true);
Activate(true); Activate(true);
return true; return true;
@@ -191,12 +195,27 @@ bool TextEditView::OnClose(bool deleteWindow)
if (deleteWindow) if (deleteWindow)
{ {
delete frame; wxDELETE(m_frame)
return true; return true;
} }
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 * Window implementations
*/ */
@@ -206,27 +225,27 @@ BEGIN_EVENT_TABLE(MyCanvas, wxScrolledWindow)
END_EVENT_TABLE() END_EVENT_TABLE()
// Define a constructor for my canvas // 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) wxScrolledWindow(frame, wxID_ANY, pos, size, style)
{ {
view = v; m_view = view;
} }
// Define the repainting behaviour // Define the repainting behaviour
void MyCanvas::OnDraw(wxDC& dc) void MyCanvas::OnDraw(wxDC& dc)
{ {
if (view) if (m_view)
view->OnDraw(& dc); m_view->OnDraw(& dc);
} }
// This implements a tiny doodling program. Drag the mouse using // This implements a tiny doodling program. Drag the mouse using
// the left button. // the left button.
void MyCanvas::OnMouseEvent(wxMouseEvent& event) void MyCanvas::OnMouseEvent(wxMouseEvent& event)
{ {
if (!view) if (!m_view)
return; return;
static DoodleSegment *currentSegment = (DoodleSegment *) NULL; static DoodleSegment *currentSegment = NULL;
wxClientDC dc(this); wxClientDC dc(this);
PrepareDC(dc); PrepareDC(dc);
@@ -237,24 +256,24 @@ void MyCanvas::OnMouseEvent(wxMouseEvent& event)
if (currentSegment && event.LeftUp()) if (currentSegment && event.LeftUp())
{ {
if (currentSegment->lines.GetCount() == 0) if (currentSegment->m_lines.GetCount() == 0)
{ {
delete currentSegment; delete currentSegment;
currentSegment = (DoodleSegment *) NULL; currentSegment = NULL;
} }
else else
{ {
// We've got a valid segment on mouse left up, so store it. // 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); m_view->GetDocument()->Modify(true);
currentSegment = (DoodleSegment *) NULL; currentSegment = NULL;
} }
} }
if (xpos > -1 && ypos > -1 && event.Dragging()) if ( (xpos > -1) && (ypos > -1) && event.Dragging())
{ {
if (!currentSegment) if (!currentSegment)
currentSegment = new DoodleSegment; currentSegment = new DoodleSegment;
@@ -264,7 +283,7 @@ void MyCanvas::OnMouseEvent(wxMouseEvent& event)
newLine->y1 = (long)ypos; newLine->y1 = (long)ypos;
newLine->x2 = pt.x; newLine->x2 = pt.x;
newLine->y2 = pt.y; newLine->y2 = pt.y;
currentSegment->lines.Append(newLine); currentSegment->m_lines.Append(newLine);
dc.DrawLine( (long)xpos, (long)ypos, pt.x, pt.y); 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 // Define a constructor for my text subwindow
MyTextWindow::MyTextWindow(wxView *v, wxFrame *frame, const wxPoint& pos, const wxSize& size, const long style): MyTextWindow::MyTextWindow(wxView* view, wxFrame* frame, const wxPoint& pos, const wxSize& size, const long style):
wxTextCtrl(frame, wxID_ANY, _T(""), pos, size, style) wxTextCtrl(frame, wxID_ANY, wxEmptyString, pos, size, style)
{ {
view = v; m_view = view;
} }

View File

@@ -9,67 +9,74 @@
// Licence: wxWindows license // Licence: wxWindows license
///////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////
#ifndef __VIEWSAMPLEH__ #ifndef __VIEW_H__
#define __VIEWSAMPLEH__ #define __VIEW_H__
#include "wx/docview.h" #include "wx/docview.h"
class DrawingView;
class MyCanvas : public wxScrolledWindow class MyCanvas : public wxScrolledWindow
{ {
public: 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); virtual void OnDraw(wxDC& dc);
void OnMouseEvent(wxMouseEvent& event);
protected:
void OnMouseEvent(wxMouseEvent& event);
DECLARE_EVENT_TABLE() DECLARE_EVENT_TABLE()
}; };
class MyTextWindow: public wxTextCtrl class MyTextWindow: public wxTextCtrl
{ {
public: public:
wxView *view; wxView* m_view;
MyTextWindow(wxView *v, wxFrame *frame, const wxPoint& pos, const wxSize& size, const long style); MyTextWindow(wxView *v, wxFrame *frame, const wxPoint& pos, const wxSize& size, const long style);
}; };
class DrawingView : public wxView class DrawingView : public wxView
{ {
DECLARE_DYNAMIC_CLASS(DrawingView)
private:
public: public:
wxFrame *frame; wxFrame* m_frame;
MyCanvas *canvas; MyCanvas* m_canvas;
DrawingView(void) { canvas = (MyCanvas *) NULL; frame = (wxFrame *) NULL; }; DrawingView() { m_canvas = NULL; m_frame = NULL; };
~DrawingView(void) {}; virtual ~DrawingView() {};
bool OnCreate(wxDocument *doc, long flags); virtual bool OnCreate(wxDocument *doc, long flags);
void OnDraw(wxDC *dc); virtual void OnDraw(wxDC *dc);
void OnUpdate(wxView *sender, wxObject *hint = (wxObject *) NULL); virtual void OnUpdate(wxView *sender, wxObject *hint = NULL);
bool OnClose(bool deleteWindow = true); virtual bool OnClose(bool deleteWindow = true);
DrawingDocument* GetDocument();
protected:
void OnCut(wxCommandEvent& event); void OnCut(wxCommandEvent& event);
private:
DECLARE_EVENT_TABLE() DECLARE_EVENT_TABLE()
DECLARE_DYNAMIC_CLASS(DrawingView)
}; };
class TextEditView : public wxView class TextEditView : public wxView
{ {
DECLARE_DYNAMIC_CLASS(TextEditView)
private:
public: public:
wxFrame *frame; wxFrame* m_frame;
MyTextWindow *textsw; MyTextWindow* m_textsw;
TextEditView(): wxView() { frame = (wxFrame *) NULL; textsw = (MyTextWindow *) NULL; } TextEditView(): wxView() { m_frame = NULL; m_textsw = NULL; }
~TextEditView(void) {} virtual ~TextEditView() {}
bool OnCreate(wxDocument *doc, long flags); virtual bool OnCreate(wxDocument *doc, long flags);
void OnDraw(wxDC *dc); virtual void OnDraw(wxDC *dc);
void OnUpdate(wxView *sender, wxObject *hint = (wxObject *) NULL); virtual void OnUpdate(wxView *sender, wxObject *hint = NULL);
bool OnClose(bool deleteWindow = true); virtual bool OnClose(bool deleteWindow = true);
virtual bool ProcessEvent(wxEvent&);
private:
DECLARE_DYNAMIC_CLASS(TextEditView)
}; };
#endif #endif

View File

@@ -37,7 +37,7 @@ IMPLEMENT_DYNAMIC_CLASS(DrawingDocument, wxDocument)
DrawingDocument::~DrawingDocument(void) DrawingDocument::~DrawingDocument(void)
{ {
WX_CLEAR_LIST(wxList, doodleSegments); WX_CLEAR_LIST(wxList, m_doodleSegments)
} }
#if wxUSE_STD_IOSTREAM #if wxUSE_STD_IOSTREAM
@@ -45,19 +45,18 @@ wxSTD ostream& DrawingDocument::SaveObject(wxSTD ostream& stream)
{ {
wxDocument::SaveObject(stream); wxDocument::SaveObject(stream);
wxInt32 n = doodleSegments.GetCount(); wxInt32 n = m_doodleSegments.GetCount();
stream << n << _T('\n'); stream << n << wxT('\n');
wxList::compatibility_iterator node = doodleSegments.GetFirst(); wxList::compatibility_iterator node = m_doodleSegments.GetFirst();
while (node) while (node)
{ {
DoodleSegment *segment = (DoodleSegment*)node->GetData(); DoodleSegment *segment = (DoodleSegment*)node->GetData();
segment->SaveObject(stream); segment->SaveObject(stream);
stream << _T('\n'); stream << wxT('\n');
node = node->GetNext(); node = node->GetNext();
} }
return stream; return stream;
} }
#else #else
@@ -67,15 +66,15 @@ wxOutputStream& DrawingDocument::SaveObject(wxOutputStream& stream)
wxTextOutputStream text_stream( stream ); wxTextOutputStream text_stream( stream );
wxInt32 n = doodleSegments.GetCount(); wxInt32 n = m_doodleSegments.GetCount();
text_stream << n << _T('\n'); text_stream << n << wxT('\n');
wxList::compatibility_iterator node = doodleSegments.GetFirst(); wxList::compatibility_iterator node = m_doodleSegments.GetFirst();
while (node) while (node)
{ {
DoodleSegment* segment = (DoodleSegment*)node->GetData(); DoodleSegment* segment = (DoodleSegment*)node->GetData();
segment->SaveObject(stream); segment->SaveObject(stream);
text_stream << _T('\n'); text_stream << wxT('\n');
node = node->GetNext(); node = node->GetNext();
} }
@@ -96,7 +95,7 @@ wxSTD istream& DrawingDocument::LoadObject(wxSTD istream& stream)
{ {
DoodleSegment *segment = new DoodleSegment; DoodleSegment *segment = new DoodleSegment;
segment->LoadObject(stream); segment->LoadObject(stream);
doodleSegments.Append(segment); m_doodleSegments.Append(segment);
} }
return stream; return stream;
@@ -115,17 +114,16 @@ wxInputStream& DrawingDocument::LoadObject(wxInputStream& stream)
{ {
DoodleSegment* segment = new DoodleSegment; DoodleSegment* segment = new DoodleSegment;
segment->LoadObject(stream); segment->LoadObject(stream);
doodleSegments.Append(segment); m_doodleSegments.Append(segment);
} }
return stream; return stream;
} }
#endif #endif
DoodleSegment::DoodleSegment(const DoodleSegment& seg) DoodleSegment::DoodleSegment(const DoodleSegment& seg) : wxObject()
:wxObject()
{ {
wxList::compatibility_iterator node = seg.lines.GetFirst(); wxList::compatibility_iterator node = seg.m_lines.GetFirst();
while (node) while (node)
{ {
DoodleLine* line = (DoodleLine*)node->GetData(); DoodleLine* line = (DoodleLine*)node->GetData();
@@ -135,7 +133,7 @@ DoodleSegment::DoodleSegment(const DoodleSegment& seg)
newLine->x2 = line->x2; newLine->x2 = line->x2;
newLine->y2 = line->y2; newLine->y2 = line->y2;
lines.Append(newLine); m_lines.Append(newLine);
node = node->GetNext(); node = node->GetNext();
} }
@@ -143,23 +141,23 @@ DoodleSegment::DoodleSegment(const DoodleSegment& seg)
DoodleSegment::~DoodleSegment(void) DoodleSegment::~DoodleSegment(void)
{ {
WX_CLEAR_LIST(wxList, lines); WX_CLEAR_LIST(wxList, m_lines)
} }
#if wxUSE_STD_IOSTREAM #if wxUSE_STD_IOSTREAM
wxSTD ostream& DoodleSegment::SaveObject(wxSTD ostream& stream) wxSTD ostream& DoodleSegment::SaveObject(wxSTD ostream& stream)
{ {
wxInt32 n = lines.GetCount(); wxInt32 n = m_lines.GetCount();
stream << n << _T('\n'); stream << n << wxT('\n');
wxList::compatibility_iterator node = lines.GetFirst(); wxList::compatibility_iterator node = m_lines.GetFirst();
while (node) while (node)
{ {
DoodleLine *line = (DoodleLine *)node->GetData(); DoodleLine *line = (DoodleLine *)node->GetData();
stream << line->x1 << _T(" ") << stream << line->x1 << wxT(" ") <<
line->y1 << _T(" ") << line->y1 << wxT(" ") <<
line->x2 << _T(" ") << line->x2 << wxT(" ") <<
line->y2 << _T("\n"); line->y2 << wxT("\n");
node = node->GetNext(); node = node->GetNext();
} }
@@ -170,17 +168,17 @@ wxOutputStream &DoodleSegment::SaveObject(wxOutputStream& stream)
{ {
wxTextOutputStream text_stream( stream ); wxTextOutputStream text_stream( stream );
wxInt32 n = lines.GetCount(); wxInt32 n = m_lines.GetCount();
text_stream << n << _T('\n'); text_stream << n << wxT('\n');
wxList::compatibility_iterator node = lines.GetFirst(); wxList::compatibility_iterator node = m_lines.GetFirst();
while (node) while (node)
{ {
DoodleLine* line = (DoodleLine*)node->GetData(); DoodleLine* line = (DoodleLine*)node->GetData();
text_stream << line->x1 << _T(" ") << text_stream << line->x1 << wxT(" ") <<
line->y1 << _T(" ") << line->y1 << wxT(" ") <<
line->x2 << _T(" ") << line->x2 << wxT(" ") <<
line->y2 << _T("\n"); line->y2 << wxT("\n");
node = node->GetNext(); node = node->GetNext();
} }
@@ -201,7 +199,7 @@ wxSTD istream& DoodleSegment::LoadObject(wxSTD istream& stream)
line->y1 >> line->y1 >>
line->x2 >> line->x2 >>
line->y2; line->y2;
lines.Append(line); m_lines.Append(line);
} }
return stream; return stream;
@@ -221,7 +219,7 @@ wxInputStream &DoodleSegment::LoadObject(wxInputStream& stream)
line->y1 >> line->y1 >>
line->x2 >> line->x2 >>
line->y2; line->y2;
lines.Append(line); m_lines.Append(line);
} }
return stream; return stream;
@@ -229,7 +227,7 @@ wxInputStream &DoodleSegment::LoadObject(wxInputStream& stream)
#endif #endif
void DoodleSegment::Draw(wxDC *dc) void DoodleSegment::Draw(wxDC *dc)
{ {
wxList::compatibility_iterator node = lines.GetFirst(); wxList::compatibility_iterator node = m_lines.GetFirst();
while (node) while (node)
{ {
DoodleLine* line = (DoodleLine*)node->GetData(); DoodleLine* line = (DoodleLine*)node->GetData();
@@ -242,82 +240,78 @@ void DoodleSegment::Draw(wxDC *dc)
* Implementation of drawing command * 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) wxCommand(true, name)
{ {
doc = ddoc; m_doc = doc;
segment = seg; m_segment = seg;
cmd = command; m_cmd = command;
} }
DrawingCommand::~DrawingCommand(void) DrawingCommand::~DrawingCommand(void)
{ {
if (segment) if (m_segment)
delete segment; delete m_segment;
} }
bool DrawingCommand::Do(void) bool DrawingCommand::Do(void)
{ {
switch (cmd) switch (m_cmd)
{ {
case DOODLE_CUT: case DOODLE_CUT:
{
// Cut the last segment // 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();
if (segment) if (m_segment)
delete segment; delete m_segment;
segment = (DoodleSegment *)node->GetData(); m_segment = (DoodleSegment*)node->GetData();
doc->GetDoodleSegments().Erase(node); m_doc->GetDoodleSegments().Erase(node);
doc->Modify(true); m_doc->Modify(true);
doc->UpdateAllViews(); m_doc->UpdateAllViews();
} }
break; break;
}
case DOODLE_ADD: case DOODLE_ADD:
{ m_doc->GetDoodleSegments().Append(new DoodleSegment(*m_segment));
doc->GetDoodleSegments().Append(new DoodleSegment(*segment)); m_doc->Modify(true);
doc->Modify(true); m_doc->UpdateAllViews();
doc->UpdateAllViews();
break; break;
} }
}
return true; return true;
} }
bool DrawingCommand::Undo(void) bool DrawingCommand::Undo(void)
{ {
switch (cmd) switch (m_cmd)
{ {
case DOODLE_CUT: case DOODLE_CUT:
{ {
// Paste the segment // Paste the segment
if (segment) if (m_segment)
{ {
doc->GetDoodleSegments().Append(segment); m_doc->GetDoodleSegments().Append(m_segment);
doc->Modify(true); m_doc->Modify(true);
doc->UpdateAllViews(); m_doc->UpdateAllViews();
segment = (DoodleSegment *) NULL; m_segment = NULL;
} }
doc->Modify(true); m_doc->Modify(true);
doc->UpdateAllViews(); m_doc->UpdateAllViews();
break; break;
} }
case DOODLE_ADD: case DOODLE_ADD:
{ {
// Cut the last segment // 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(); DoodleSegment* seg = (DoodleSegment*)node->GetData();
delete seg; delete seg;
doc->GetDoodleSegments().Erase(node); m_doc->GetDoodleSegments().Erase(node);
doc->Modify(true); m_doc->Modify(true);
doc->UpdateAllViews(); m_doc->UpdateAllViews();
} }
} }
} }
@@ -330,9 +324,9 @@ IMPLEMENT_DYNAMIC_CLASS(TextEditDocument, wxDocument)
// we override OnSave/OpenDocument instead of Save/LoadObject // we override OnSave/OpenDocument instead of Save/LoadObject
bool TextEditDocument::OnSaveDocument(const wxString& filename) 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; return false;
Modify(false); Modify(false);
return true; return true;
@@ -340,8 +334,8 @@ bool TextEditDocument::OnSaveDocument(const wxString& filename)
bool TextEditDocument::OnOpenDocument(const wxString& filename) bool TextEditDocument::OnOpenDocument(const wxString& filename)
{ {
TextEditView *view = (TextEditView *)GetFirstView(); TextEditView *view = GetFirstView();
if (!view->textsw->LoadFile(filename)) if (!view->m_textsw->LoadFile(filename))
return false; return false;
SetFilename(filename, true); SetFilename(filename, true);
@@ -352,21 +346,25 @@ bool TextEditDocument::OnOpenDocument(const wxString& filename)
bool TextEditDocument::IsModified(void) const bool TextEditDocument::IsModified(void) const
{ {
TextEditView *view = (TextEditView *)GetFirstView(); TextEditView* view = GetFirstView();
if (view) return (wxDocument::IsModified() || (view && view->m_textsw->IsModified()));
{
return (wxDocument::IsModified() || view->textsw->IsModified());
}
else
return wxDocument::IsModified();
} }
void TextEditDocument::Modify(bool mod) void TextEditDocument::Modify(bool mod)
{ {
TextEditView *view = (TextEditView *)GetFirstView(); TextEditView* view = GetFirstView();
wxDocument::Modify(mod); wxDocument::Modify(mod);
if (!mod && view && view->textsw) if ((!mod) && view && view->m_textsw)
view->textsw->DiscardEdits(); {
view->m_textsw->DiscardEdits();
} }
}
TextEditView* TextEditDocument::GetFirstView() const
{
wxView* view = wxDocument::GetFirstView();
return view ? wxStaticCast(view, TextEditView) : NULL;
}

View File

@@ -9,8 +9,8 @@
// Licence: wxWindows license // Licence: wxWindows license
///////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////
#ifndef __DOCSAMPLEH__ #ifndef __DOC_H__
#define __DOCSAMPLEH__ #define __DOC_H__
#include "wx/docview.h" #include "wx/docview.h"
#include "wx/cmdproc.h" #include "wx/cmdproc.h"
@@ -29,42 +29,41 @@ class DoodleLine: public wxObject
class DoodleSegment: public wxObject class DoodleSegment: public wxObject
{ {
public: public:
wxList lines; wxList m_lines;
DoodleSegment(void){}; DoodleSegment() : wxObject() {}
DoodleSegment(const DoodleSegment& seg); DoodleSegment(const DoodleSegment&);
~DoodleSegment(void); virtual ~DoodleSegment();
void Draw(wxDC* dc); void Draw(wxDC* dc);
#if wxUSE_STD_IOSTREAM #if wxUSE_STD_IOSTREAM
wxSTD ostream& SaveObject(wxSTD ostream& text_stream); wxSTD ostream& SaveObject(wxSTD ostream&);
wxSTD istream& LoadObject(wxSTD istream& text_stream); wxSTD istream& LoadObject(wxSTD istream&);
#else #else
wxOutputStream& SaveObject(wxOutputStream& stream); wxOutputStream& SaveObject(wxOutputStream&);
wxInputStream& LoadObject(wxInputStream& stream); wxInputStream& LoadObject(wxInputStream&);
#endif #endif
}; };
class DrawingDocument: public wxDocument class DrawingDocument: public wxDocument
{ {
DECLARE_DYNAMIC_CLASS(DrawingDocument) DECLARE_DYNAMIC_CLASS(DrawingDocument)
private:
public: public:
wxList doodleSegments; wxList m_doodleSegments;
DrawingDocument(void){}; DrawingDocument() : wxDocument() {}
~DrawingDocument(void); virtual ~DrawingDocument();
#if wxUSE_STD_IOSTREAM #if wxUSE_STD_IOSTREAM
wxSTD ostream& SaveObject(wxSTD ostream& text_stream); wxSTD ostream& SaveObject(wxSTD ostream&);
wxSTD istream& LoadObject(wxSTD istream& text_stream); wxSTD istream& LoadObject(wxSTD istream&);
#else #else
wxOutputStream& SaveObject(wxOutputStream& stream); wxOutputStream& SaveObject(wxOutputStream&);
wxInputStream& LoadObject(wxInputStream& stream); wxInputStream& LoadObject(wxInputStream&);
#endif #endif
inline wxList& GetDoodleSegments(void) const { return (wxList&) doodleSegments; }; inline wxList& GetDoodleSegments() const { return (wxList&) m_doodleSegments; };
}; };
#define DOODLE_CUT 1 #define DOODLE_CUT 1
@@ -73,33 +72,35 @@ class DrawingDocument: public wxDocument
class DrawingCommand : public wxCommand class DrawingCommand : public wxCommand
{ {
protected: protected:
DoodleSegment *segment; DoodleSegment* m_segment;
DrawingDocument *doc; DrawingDocument* m_doc;
int cmd; int m_cmd;
public: public:
DrawingCommand(const wxString& name, int cmd, DrawingDocument *ddoc, DoodleSegment *seg); DrawingCommand(const wxString& name, int cmd, DrawingDocument*, DoodleSegment*);
~DrawingCommand(void); virtual ~DrawingCommand();
bool Do(void); bool Do();
bool Undo(void); bool Undo();
}; };
class TextEditView;
class TextEditDocument : public wxDocument class TextEditDocument : public wxDocument
{ {
DECLARE_DYNAMIC_CLASS(TextEditDocument) DECLARE_DYNAMIC_CLASS(TextEditDocument)
private:
public: public:
/* /*
wxSTD ostream& SaveObject(wxSTD ostream& stream); wxSTD ostream& SaveObject(wxSTD ostream&);
wxSTD istream& LoadObject(wxSTD istream& stream); wxSTD istream& LoadObject(wxSTD istream&);
*/ */
TextEditView* GetFirstView() const;
virtual bool OnSaveDocument(const wxString& filename); virtual bool OnSaveDocument(const wxString& filename);
virtual bool OnOpenDocument(const wxString& filename); virtual bool OnOpenDocument(const wxString& filename);
virtual bool IsModified(void) const; virtual bool IsModified() const;
virtual void Modify(bool mod); virtual void Modify(bool mod);
TextEditDocument(void) {} TextEditDocument() {}
~TextEditDocument(void) {} virtual ~TextEditDocument() {}
}; };

View File

@@ -36,61 +36,67 @@
#include "docview.h" #include "docview.h"
#include "doc.h" #include "doc.h"
#include "view.h" #include "view.h"
#include "wx/stockitem.h"
MyFrame *frame = (MyFrame *) NULL; static MyFrame* frame = NULL;
IMPLEMENT_APP(MyApp) IMPLEMENT_APP(MyApp)
MyApp::MyApp(void) MyApp::MyApp(void)
{ {
m_docManager = (wxDocManager *) NULL; m_docManager = NULL;
} }
bool MyApp::OnInit(void) bool MyApp::OnInit(void)
{ {
if ( !wxApp::OnInit() )
return false;
//// Create a document manager
SetAppName(wxT("DocView Demo"));
//// Create a document manager //// Create a document manager
m_docManager = new wxDocManager; m_docManager = new wxDocManager;
//// Create a template relating drawing documents to their views //// 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)); CLASSINFO(DrawingDocument), CLASSINFO(DrawingView));
//// Create a template relating text documents to their views //// 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)); CLASSINFO(TextEditDocument), CLASSINFO(TextEditView));
//// Create the main frame window //// Create the main frame window
frame = new MyFrame((wxDocManager *) m_docManager, (wxFrame *) NULL, frame = new MyFrame(m_docManager, NULL,
_T("DocView Demo"), wxPoint(0, 0), wxSize(500, 400), GetAppDisplayName(), wxPoint(0, 0), wxSize(500, 400),
wxDEFAULT_FRAME_STYLE | wxNO_FULL_REPAINT_ON_RESIZE); wxDEFAULT_FRAME_STYLE | wxNO_FULL_REPAINT_ON_RESIZE);
//// Give it an icon (this is ignored in MDI mode: uses resources) //// Give it an icon (this is ignored in MDI mode: uses resources)
#ifdef __WXMSW__ #ifdef __WXMSW__
frame->SetIcon(wxIcon(_T("doc"))); frame->SetIcon(wxIcon(wxT("doc")));
#endif #endif
//// Make a menubar //// Make a menubar
wxMenu *file_menu = new wxMenu; 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_NEW);
file_menu->Append(wxID_OPEN, _T("&Open...\tCtrl-X")); file_menu->Append(wxID_OPEN);
file_menu->AppendSeparator(); 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. // A nice touch: a history of files visited. Use this menu.
m_docManager->FileHistoryUseMenu(file_menu); m_docManager->FileHistoryUseMenu(file_menu);
wxMenu *help_menu = new wxMenu; wxMenu *help_menu = new wxMenu;
help_menu->Append(DOCVIEW_ABOUT, _T("&About\tF1")); help_menu->Append(DOCVIEW_ABOUT);
wxMenuBar *menu_bar = new wxMenuBar; wxMenuBar *menu_bar = new wxMenuBar;
menu_bar->Append(file_menu, _T("&File")); menu_bar->Append(file_menu, wxGetStockLabel(wxID_FILE));
if (edit_menu) if (edit_menu)
menu_bar->Append(edit_menu, _T("&Edit")); menu_bar->Append(edit_menu, wxGetStockLabel(wxID_EDIT));
menu_bar->Append(help_menu, _T("&Help")); menu_bar->Append(help_menu, wxGetStockLabel(wxID_HELP));
#ifdef __WXMAC__ #ifdef __WXMAC__
wxMenuBar::MacSetCommonMenuBar(menu_bar); wxMenuBar::MacSetCommonMenuBar(menu_bar);
@@ -109,7 +115,7 @@ bool MyApp::OnInit(void)
int MyApp::OnExit(void) int MyApp::OnExit(void)
{ {
delete m_docManager; wxDELETE(m_docManager)
return 0; return 0;
} }
@@ -122,60 +128,62 @@ wxMDIChildFrame *MyApp::CreateChildFrame(wxDocument *doc, wxView *view, bool isC
{ {
//// Make a child frame //// Make a child frame
wxDocMDIChildFrame *subframe = 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), wxPoint(10, 10), wxSize(300, 300),
wxDEFAULT_FRAME_STYLE | wxDEFAULT_FRAME_STYLE |
wxNO_FULL_REPAINT_ON_RESIZE); wxNO_FULL_REPAINT_ON_RESIZE);
#ifdef __WXMSW__ #ifdef __WXMSW__
subframe->SetIcon(wxString(isCanvas ? _T("chart") : _T("notepad"))); subframe->SetIcon(wxString(isCanvas ? wxT("chart") : wxT("notepad")));
#endif #endif
#ifdef __X__ #ifdef __X__
subframe->SetIcon(wxIcon(_T("doc.xbm"))); subframe->SetIcon(wxIcon(wxT("doc.xbm")));
#endif #endif
//// Make a menubar //// Make a menubar
wxMenu *file_menu = new wxMenu; wxMenu *file_menu = new wxMenu;
file_menu->Append(wxID_NEW, _T("&New...")); file_menu->Append(wxID_NEW);
file_menu->Append(wxID_OPEN, _T("&Open...")); file_menu->Append(wxID_OPEN);
file_menu->Append(wxID_CLOSE, _T("&Close")); file_menu->Append(wxID_CLOSE);
file_menu->Append(wxID_SAVE, _T("&Save")); file_menu->Append(wxID_SAVE);
file_menu->Append(wxID_SAVEAS, _T("Save &As...")); file_menu->Append(wxID_SAVEAS);
if (isCanvas) if (isCanvas)
{ {
file_menu->AppendSeparator(); file_menu->AppendSeparator();
file_menu->Append(wxID_PRINT, _T("&Print...")); file_menu->Append(wxID_PRINT);
file_menu->Append(wxID_PRINT_SETUP, _T("Print &Setup...")); file_menu->Append(wxID_PRINT_SETUP, wxT("Print &Setup..."));
file_menu->Append(wxID_PREVIEW, _T("Print Pre&view")); file_menu->Append(wxID_PREVIEW);
} }
file_menu->AppendSeparator(); file_menu->AppendSeparator();
file_menu->Append(wxID_EXIT, _T("E&xit")); file_menu->Append(wxID_EXIT);
wxMenu *edit_menu = (wxMenu *) NULL;
wxMenu *edit_menu = new wxMenu;
if (isCanvas) if (isCanvas)
{ {
edit_menu = new wxMenu; edit_menu->Append(wxID_UNDO);
edit_menu->Append(wxID_UNDO, _T("&Undo")); edit_menu->Append(wxID_REDO);
edit_menu->Append(wxID_REDO, _T("&Redo"));
edit_menu->AppendSeparator(); 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); 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; wxMenu *help_menu = new wxMenu;
help_menu->Append(DOCVIEW_ABOUT, _T("&About")); help_menu->Append(DOCVIEW_ABOUT);
wxMenuBar *menu_bar = new wxMenuBar; wxMenuBar *menu_bar = new wxMenuBar;
menu_bar->Append(file_menu, _T("&File")); menu_bar->Append(file_menu, wxGetStockLabel(wxID_FILE));
if (isCanvas) menu_bar->Append(edit_menu, wxGetStockLabel(wxID_EDIT));
menu_bar->Append(edit_menu, _T("&Edit")); menu_bar->Append(help_menu, wxGetStockLabel(wxID_HELP));
menu_bar->Append(help_menu, _T("&Help"));
//// Associate the menu bar with the frame //// Associate the menu bar with the frame
subframe->SetMenuBar(menu_bar); subframe->SetMenuBar(menu_bar);
@@ -194,25 +202,31 @@ END_EVENT_TABLE()
MyFrame::MyFrame(wxDocManager *manager, wxFrame *frame, const wxString& title, MyFrame::MyFrame(wxDocManager *manager, wxFrame *frame, const wxString& title,
const wxPoint& pos, const wxSize& size, long type): 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 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 // Creates a canvas. Called from view.cpp when a new drawing
// view is created. // view is created.
MyCanvas *MyFrame::CreateCanvas(wxView *view, wxMDIChildFrame *parent) MyCanvas* MyFrame::CreateCanvas(DrawingView* view, wxMDIChildFrame* parent)
{ {
int width, height; wxSize size = parent->GetClientSize();
parent->GetClientSize(&width, &height);
// Non-retained canvas // 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)); canvas->SetCursor(wxCursor(wxCURSOR_PENCIL));
// Give it scrollbars // Give it scrollbars
@@ -221,7 +235,7 @@ MyCanvas *MyFrame::CreateCanvas(wxView *view, wxMDIChildFrame *parent)
return canvas; return canvas;
} }
MyFrame *GetMainFrame(void) MyFrame* GetMainFrame()
{ {
return frame; return frame;
} }

View File

@@ -9,8 +9,8 @@
// Licence: wxWindows license // Licence: wxWindows license
///////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////
#ifndef __DOCVIEWSAMPLEH__ #ifndef __DOCVIEW_H__
#define __DOCVIEWSAMPLEH__ #define __DOCVIEW_H__
#include "wx/mdi.h" #include "wx/mdi.h"
#include "wx/docview.h" #include "wx/docview.h"
@@ -23,10 +23,10 @@ class MyApp: public wxApp
{ {
public: public:
MyApp(void); MyApp(void);
bool OnInit(void); virtual bool OnInit();
int OnExit(void); virtual int OnExit();
wxMDIChildFrame *CreateChildFrame(wxDocument *doc, wxView *view, bool isCanvas); wxMDIChildFrame* CreateChildFrame(wxDocument*, wxView*, bool isCanvas);
protected: protected:
wxDocManager* m_docManager; wxDocManager* m_docManager;
@@ -36,22 +36,24 @@ DECLARE_APP(MyApp)
// Define a new frame // Define a new frame
class MyCanvas; class MyCanvas;
class DrawingView;
class MyFrame: public wxDocMDIParentFrame class MyFrame: public wxDocMDIParentFrame
{ {
DECLARE_CLASS(MyFrame)
public: public:
wxMenu *editMenu; wxMenu* m_editMenu;
MyFrame(wxDocManager *manager, wxFrame *frame, const wxString& title, const wxPoint& pos, const wxSize& size, MyFrame(wxDocManager*, wxFrame*, const wxString& title, const wxPoint&, const wxSize&, long type);
long type);
void OnAbout(wxCommandEvent& event); MyCanvas* CreateCanvas(DrawingView*, wxMDIChildFrame*);
MyCanvas *CreateCanvas(wxView *view, wxMDIChildFrame *parent);
protected:
void OnAbout(wxCommandEvent&);
DECLARE_EVENT_TABLE() DECLARE_EVENT_TABLE()
DECLARE_CLASS(MyFrame)
}; };
extern MyFrame *GetMainFrame(void); extern MyFrame* GetMainFrame();
#define DOCVIEW_CUT 1 #define DOCVIEW_CUT 1
#define DOCVIEW_ABOUT wxID_ABOUT #define DOCVIEW_ABOUT wxID_ABOUT

View File

@@ -31,8 +31,8 @@
IMPLEMENT_DYNAMIC_CLASS(DrawingView, wxView) IMPLEMENT_DYNAMIC_CLASS(DrawingView, wxView)
// For drawing lines in a canvas // For drawing lines in a canvas
float xpos = -1; static float xpos = -1;
float ypos = -1; static float ypos = -1;
BEGIN_EVENT_TABLE(DrawingView, wxView) BEGIN_EVENT_TABLE(DrawingView, wxView)
EVT_MENU(DOODLE_CUT, DrawingView::OnCut) EVT_MENU(DOODLE_CUT, DrawingView::OnCut)
@@ -42,22 +42,27 @@ END_EVENT_TABLE()
// windows for displaying the view. // windows for displaying the view.
bool DrawingView::OnCreate(wxDocument *doc, long WXUNUSED(flags) ) bool DrawingView::OnCreate(wxDocument *doc, long WXUNUSED(flags) )
{ {
frame = wxGetApp().CreateChildFrame(doc, this, true); m_frame = wxGetApp().CreateChildFrame(doc, this, true);
frame->SetTitle(_T("DrawingView")); m_frame->SetTitle(wxT("DrawingView"));
canvas = GetMainFrame()->CreateCanvas(this, frame); m_canvas = GetMainFrame()->CreateCanvas(this, m_frame);
#ifdef __X__ #ifdef __X__
// X seems to require a forced resize // X seems to require a forced resize
int x, y; int x, y;
frame->GetSize(&x, &y); m_frame->GetSize(&x, &y);
frame->SetSize(wxDefaultCoord, wxDefaultCoord, x, y); m_frame->SetSize(wxDefaultCoord, wxDefaultCoord, x, y);
#endif #endif
frame->Show(true); m_frame->Show(true);
Activate(true); Activate(true);
return true; return true;
} }
DrawingDocument* DrawingView::GetDocument()
{
return wxStaticCast(wxView::GetDocument(), DrawingDocument);
}
// Sneakily gets used for default print/preview // Sneakily gets used for default print/preview
// as well as drawing on the screen. // as well as drawing on the screen.
void DrawingView::OnDraw(wxDC *dc) void DrawingView::OnDraw(wxDC *dc)
@@ -65,7 +70,7 @@ void DrawingView::OnDraw(wxDC *dc)
dc->SetFont(*wxNORMAL_FONT); dc->SetFont(*wxNORMAL_FONT);
dc->SetPen(*wxBLACK_PEN); dc->SetPen(*wxBLACK_PEN);
wxList::compatibility_iterator node = ((DrawingDocument *)GetDocument())->GetDoodleSegments().GetFirst(); wxList::compatibility_iterator node = GetDocument()->GetDoodleSegments().GetFirst();
while (node) while (node)
{ {
DoodleSegment* seg = (DoodleSegment*)node->GetData(); DoodleSegment* seg = (DoodleSegment*)node->GetData();
@@ -76,8 +81,8 @@ void DrawingView::OnDraw(wxDC *dc)
void DrawingView::OnUpdate(wxView *WXUNUSED(sender), wxObject *WXUNUSED(hint)) void DrawingView::OnUpdate(wxView *WXUNUSED(sender), wxObject *WXUNUSED(hint))
{ {
if (canvas) if (m_canvas)
canvas->Refresh(); m_canvas->Refresh();
/* Is the following necessary? /* Is the following necessary?
#ifdef __WXMSW__ #ifdef __WXMSW__
@@ -102,21 +107,21 @@ bool DrawingView::OnClose(bool deleteWindow)
// Clear the canvas in case we're in single-window mode, // Clear the canvas in case we're in single-window mode,
// and the canvas stays. // and the canvas stays.
canvas->ClearBackground(); m_canvas->ClearBackground();
canvas->view = (wxView *) NULL; m_canvas->m_view = NULL;
canvas = (MyCanvas *) NULL; m_canvas = NULL;
wxString s(wxTheApp->GetAppDisplayName()); wxString s(wxTheApp->GetAppDisplayName());
if (frame) if (m_frame)
frame->SetTitle(s); m_frame->SetTitle(s);
SetFrame((wxFrame*)NULL); SetFrame(NULL);
Activate(false); Activate(false);
if (deleteWindow) if (deleteWindow)
{ {
delete frame; delete m_frame;
return true; return true;
} }
return true; return true;
@@ -124,29 +129,28 @@ bool DrawingView::OnClose(bool deleteWindow)
void DrawingView::OnCut(wxCommandEvent& WXUNUSED(event) ) void DrawingView::OnCut(wxCommandEvent& WXUNUSED(event) )
{ {
DrawingDocument *doc = (DrawingDocument *)GetDocument(); DrawingDocument* doc = GetDocument();
doc->GetCommandProcessor()->Submit(new DrawingCommand(_T("Cut Last Segment"), DOODLE_CUT, doc, (DoodleSegment *) NULL)); doc->GetCommandProcessor()->Submit(new DrawingCommand(wxT("Cut Last Segment"), DOODLE_CUT, doc, NULL));
} }
IMPLEMENT_DYNAMIC_CLASS(TextEditView, wxView) IMPLEMENT_DYNAMIC_CLASS(TextEditView, wxView)
bool TextEditView::OnCreate(wxDocument* doc, long WXUNUSED(flags) ) bool TextEditView::OnCreate(wxDocument* doc, long WXUNUSED(flags) )
{ {
frame = wxGetApp().CreateChildFrame(doc, this, false); m_frame = wxGetApp().CreateChildFrame(doc, this, false);
int width, height; wxSize size = m_frame->GetClientSize();
frame->GetClientSize(&width, &height); m_textsw = new MyTextWindow(this, m_frame, wxPoint(0, 0), size, wxTE_MULTILINE);
textsw = new MyTextWindow(this, frame, wxPoint(0, 0), wxSize(width, height), wxTE_MULTILINE); m_frame->SetTitle(wxT("TextEditView"));
frame->SetTitle(_T("TextEditView"));
#ifdef __X__ #ifdef __X__
// X seems to require a forced resize // X seems to require a forced resize
int x, y; int x, y;
frame->GetSize(&x, &y); m_frame->GetSize(&x, &y);
frame->SetSize(wxDefaultCoord, wxDefaultCoord, x, y); m_frame->SetSize(wxDefaultCoord, wxDefaultCoord, x, y);
#endif #endif
frame->Show(true); m_frame->Show(true);
Activate(true); Activate(true);
return true; return true;
@@ -170,12 +174,27 @@ bool TextEditView::OnClose(bool deleteWindow)
if (deleteWindow) if (deleteWindow)
{ {
delete frame; delete m_frame;
return true; return true;
} }
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 * Window implementations
*/ */
@@ -185,27 +204,27 @@ BEGIN_EVENT_TABLE(MyCanvas, wxScrolledWindow)
END_EVENT_TABLE() END_EVENT_TABLE()
// Define a constructor for my canvas // 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) wxScrolledWindow(frame, wxID_ANY, pos, size, style)
{ {
view = v; m_view = view;
} }
// Define the repainting behaviour // Define the repainting behaviour
void MyCanvas::OnDraw(wxDC& dc) void MyCanvas::OnDraw(wxDC& dc)
{ {
if (view) if (m_view)
view->OnDraw(& dc); m_view->OnDraw(& dc);
} }
// This implements a tiny doodling program. Drag the mouse using // This implements a tiny doodling program. Drag the mouse using
// the left button. // the left button.
void MyCanvas::OnMouseEvent(wxMouseEvent& event) void MyCanvas::OnMouseEvent(wxMouseEvent& event)
{ {
if (!view) if (!m_view)
return; return;
static DoodleSegment *currentSegment = (DoodleSegment *) NULL; static DoodleSegment* currentSegment = NULL;
wxClientDC dc(this); wxClientDC dc(this);
PrepareDC(dc); PrepareDC(dc);
@@ -216,24 +235,24 @@ void MyCanvas::OnMouseEvent(wxMouseEvent& event)
if (currentSegment && event.LeftUp()) if (currentSegment && event.LeftUp())
{ {
if (currentSegment->lines.GetCount() == 0) if (currentSegment->m_lines.GetCount() == 0)
{ {
delete currentSegment; delete currentSegment;
currentSegment = (DoodleSegment *) NULL; currentSegment = NULL;
} }
else else
{ {
// We've got a valid segment on mouse left up, so store it. // 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); m_view->GetDocument()->Modify(true);
currentSegment = (DoodleSegment *) NULL; currentSegment = NULL;
} }
} }
if (xpos > -1 && ypos > -1 && event.Dragging()) if ( (xpos > -1) && (ypos > -1) && event.Dragging())
{ {
if (!currentSegment) if (!currentSegment)
currentSegment = new DoodleSegment; currentSegment = new DoodleSegment;
@@ -243,7 +262,7 @@ void MyCanvas::OnMouseEvent(wxMouseEvent& event)
newLine->y1 = (long)ypos; newLine->y1 = (long)ypos;
newLine->x2 = pt.x; newLine->x2 = pt.x;
newLine->y2 = pt.y; newLine->y2 = pt.y;
currentSegment->lines.Append(newLine); currentSegment->m_lines.Append(newLine);
dc.DrawLine( (long)xpos, (long)ypos, pt.x, pt.y); 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 // Define a constructor for my text subwindow
MyTextWindow::MyTextWindow(wxView *v, wxMDIChildFrame *frame, const wxPoint& pos, const wxSize& size, long style): MyTextWindow::MyTextWindow(wxView* view, wxMDIChildFrame* frame, const wxPoint& pos, const wxSize& size, long style):
wxTextCtrl(frame, wxID_ANY, _T(""), pos, size, style) wxTextCtrl(frame, wxID_ANY, wxEmptyString, pos, size, style)
{ {
view = v; m_view = view;
} }

View File

@@ -9,69 +9,70 @@
// Licence: wxWindows license // Licence: wxWindows license
///////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////
#ifndef __VIEWSAMPLEH__ #ifndef __VIEW_H__
#define __VIEWSAMPLEH__ #define __VIEW_H__
#include "wx/docview.h" #include "wx/docview.h"
class DrawingView;
class MyCanvas : public wxScrolledWindow class MyCanvas : public wxScrolledWindow
{ {
public: public:
wxView *view; DrawingView* m_view;
MyCanvas(wxView *v, wxMDIChildFrame *frame, const wxPoint& pos, const wxSize& size, long style); MyCanvas(DrawingView*, wxMDIChildFrame*, const wxPoint&, const wxSize&, long style);
virtual void OnDraw(wxDC& dc); virtual void OnDraw(wxDC&);
void OnMouseEvent(wxMouseEvent& event); protected:
void OnMouseEvent(wxMouseEvent&);
private:
DECLARE_EVENT_TABLE() DECLARE_EVENT_TABLE()
}; };
class MyTextWindow: public wxTextCtrl class MyTextWindow: public wxTextCtrl
{ {
public: 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 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) 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() DECLARE_EVENT_TABLE()
}; };
class TextEditView: public wxView 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) 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 #endif