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)
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
@@ -9,14 +9,14 @@
|
|||||||
// 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"
|
||||||
|
|
||||||
// Plots a line from one point to the other
|
// Plots a line from one point to the other
|
||||||
class DoodleLine: public wxObject
|
class DoodleLine : public wxObject
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
wxInt32 x1;
|
wxInt32 x1;
|
||||||
@@ -26,14 +26,14 @@ public:
|
|||||||
};
|
};
|
||||||
|
|
||||||
// Contains a list of lines: represents a mouse-down doodle
|
// Contains a list of lines: represents a mouse-down doodle
|
||||||
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
|
||||||
@@ -46,15 +46,15 @@ public:
|
|||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
class DrawingDocument: public wxDocument
|
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,42 +64,43 @@ 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
|
||||||
#define DOODLE_ADD 2
|
#define DOODLE_ADD 2
|
||||||
|
|
||||||
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 TextEditDocument: public wxDocument
|
class TextEditView;
|
||||||
|
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) {}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@@ -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,22 +67,22 @@ 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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//// 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(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' ) ;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (singleWindowMode)
|
if (singleWindowMode)
|
||||||
{
|
{
|
||||||
// If we've only got one window, we only get to edit
|
// If we've only got one window, we only get to edit
|
||||||
@@ -90,72 +93,72 @@ 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' ) ;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
//// 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);
|
||||||
|
|
||||||
frame->Centre(wxBOTH);
|
frame->Centre(wxBOTH);
|
||||||
frame->Show(true);
|
frame->Show(true);
|
||||||
|
|
||||||
SetTopWindow(frame);
|
SetTopWindow(frame);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -175,58 +178,62 @@ 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);
|
||||||
|
|
||||||
subframe->Centre(wxBOTH);
|
subframe->Centre(wxBOTH);
|
||||||
|
|
||||||
return subframe;
|
return subframe;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -244,32 +251,38 @@ 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
|
||||||
canvas->SetScrollbars(20, 20, 50, 50);
|
canvas->SetScrollbars(20, 20, 50, 50);
|
||||||
canvas->SetBackgroundColour(*wxWHITE);
|
canvas->SetBackgroundColour(*wxWHITE);
|
||||||
canvas->ClearBackground();
|
canvas->ClearBackground();
|
||||||
|
|
||||||
return canvas;
|
return canvas;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -9,23 +9,23 @@
|
|||||||
// Licence: wxWindows license
|
// Licence: wxWindows license
|
||||||
/////////////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
#ifndef __DOCVIEWSAMPLEH__
|
#ifndef __DOCVIEW_H__
|
||||||
#define __DOCVIEWSAMPLEH__
|
#define __DOCVIEW_H__
|
||||||
|
|
||||||
#include "wx/docview.h"
|
#include "wx/docview.h"
|
||||||
|
|
||||||
class wxDocManager;
|
class wxDocManager;
|
||||||
|
|
||||||
// Define a new application
|
// Define a new application
|
||||||
class MyApp: public wxApp
|
class MyApp : public wxApp
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
MyApp(void);
|
MyApp(void);
|
||||||
bool OnInit(void);
|
bool OnInit(void);
|
||||||
int OnExit(void);
|
int OnExit(void);
|
||||||
|
|
||||||
wxFrame *CreateChildFrame(wxDocument *doc, wxView *view, bool isCanvas);
|
wxFrame *CreateChildFrame(wxDocument *doc, wxView *view, bool isCanvas);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
wxDocManager* m_docManager;
|
wxDocManager* m_docManager;
|
||||||
};
|
};
|
||||||
@@ -34,25 +34,27 @@ DECLARE_APP(MyApp)
|
|||||||
|
|
||||||
// Define a new frame
|
// Define a new frame
|
||||||
class MyCanvas;
|
class MyCanvas;
|
||||||
class MyFrame: public wxDocParentFrame
|
class DrawingView;
|
||||||
|
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);
|
||||||
|
|
||||||
|
MyCanvas* CreateCanvas(DrawingView*, wxFrame *parent);
|
||||||
|
|
||||||
|
protected:
|
||||||
void OnAbout(wxCommandEvent& event);
|
void OnAbout(wxCommandEvent& event);
|
||||||
MyCanvas *CreateCanvas(wxView *view, wxFrame *parent);
|
|
||||||
|
|
||||||
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
|
||||||
|
@@ -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,37 +45,37 @@ 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();
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -85,8 +85,8 @@ 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,11 +95,16 @@ 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__
|
||||||
if (canvas)
|
if (canvas)
|
||||||
@@ -120,24 +125,24 @@ bool DrawingView::OnClose(bool deleteWindow)
|
|||||||
{
|
{
|
||||||
if (!GetDocument()->Close())
|
if (!GetDocument()->Close())
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
// 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,31 +150,30 @@ 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);
|
frame->GetSize(&x, &y);
|
||||||
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -186,17 +190,32 @@ bool TextEditView::OnClose(bool deleteWindow)
|
|||||||
{
|
{
|
||||||
if (!GetDocument()->Close())
|
if (!GetDocument()->Close())
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
Activate(false);
|
Activate(false);
|
||||||
|
|
||||||
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,66 +225,66 @@ 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);
|
||||||
|
|
||||||
dc.SetPen(*wxBLACK_PEN);
|
dc.SetPen(*wxBLACK_PEN);
|
||||||
|
|
||||||
wxPoint pt(event.GetLogicalPosition(dc));
|
wxPoint pt(event.GetLogicalPosition(dc));
|
||||||
|
|
||||||
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;
|
||||||
|
|
||||||
DoodleLine *newLine = new DoodleLine;
|
DoodleLine *newLine = new DoodleLine;
|
||||||
newLine->x1 = (long)xpos;
|
newLine->x1 = (long)xpos;
|
||||||
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);
|
||||||
}
|
}
|
||||||
xpos = pt.x;
|
xpos = pt.x;
|
||||||
@@ -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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@@ -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 MyCanvas: public wxScrolledWindow
|
class DrawingView;
|
||||||
|
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);
|
||||||
|
|
||||||
|
protected:
|
||||||
void OnMouseEvent(wxMouseEvent& event);
|
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
|
||||||
|
@@ -37,291 +37,285 @@ 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
|
||||||
wxSTD ostream& DrawingDocument::SaveObject(wxSTD ostream& stream)
|
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
|
||||||
wxOutputStream& DrawingDocument::SaveObject(wxOutputStream& stream)
|
wxOutputStream& DrawingDocument::SaveObject(wxOutputStream& stream)
|
||||||
{
|
{
|
||||||
wxDocument::SaveObject(stream);
|
wxDocument::SaveObject(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();
|
||||||
}
|
}
|
||||||
|
|
||||||
return stream;
|
return stream;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if wxUSE_STD_IOSTREAM
|
#if wxUSE_STD_IOSTREAM
|
||||||
wxSTD istream& DrawingDocument::LoadObject(wxSTD istream& stream)
|
wxSTD istream& DrawingDocument::LoadObject(wxSTD istream& stream)
|
||||||
{
|
{
|
||||||
wxDocument::LoadObject(stream);
|
wxDocument::LoadObject(stream);
|
||||||
|
|
||||||
wxInt32 n = 0;
|
wxInt32 n = 0;
|
||||||
stream >> n;
|
stream >> n;
|
||||||
|
|
||||||
for (int i = 0; i < n; i++)
|
for (int i = 0; i < n; i++)
|
||||||
{
|
{
|
||||||
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;
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
wxInputStream& DrawingDocument::LoadObject(wxInputStream& stream)
|
wxInputStream& DrawingDocument::LoadObject(wxInputStream& stream)
|
||||||
{
|
{
|
||||||
wxDocument::LoadObject(stream);
|
wxDocument::LoadObject(stream);
|
||||||
|
|
||||||
wxTextInputStream text_stream( stream );
|
wxTextInputStream text_stream( stream );
|
||||||
|
|
||||||
wxInt32 n = 0;
|
wxInt32 n = 0;
|
||||||
text_stream >> n;
|
text_stream >> n;
|
||||||
|
|
||||||
for (int i = 0; i < n; i++)
|
for (int i = 0; i < n; i++)
|
||||||
{
|
{
|
||||||
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();
|
||||||
DoodleLine *newLine = new DoodleLine;
|
DoodleLine* newLine = new DoodleLine;
|
||||||
newLine->x1 = line->x1;
|
newLine->x1 = line->x1;
|
||||||
newLine->y1 = line->y1;
|
newLine->y1 = line->y1;
|
||||||
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();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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();
|
||||||
}
|
}
|
||||||
|
|
||||||
return stream;
|
return stream;
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
wxOutputStream &DoodleSegment::SaveObject(wxOutputStream& stream)
|
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();
|
||||||
}
|
}
|
||||||
|
|
||||||
return stream;
|
return stream;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if wxUSE_STD_IOSTREAM
|
#if wxUSE_STD_IOSTREAM
|
||||||
wxSTD istream& DoodleSegment::LoadObject(wxSTD istream& stream)
|
wxSTD istream& DoodleSegment::LoadObject(wxSTD istream& stream)
|
||||||
{
|
{
|
||||||
wxInt32 n = 0;
|
wxInt32 n = 0;
|
||||||
stream >> n;
|
stream >> n;
|
||||||
|
|
||||||
for (int i = 0; i < n; i++)
|
for (int i = 0; i < n; i++)
|
||||||
{
|
{
|
||||||
DoodleLine *line = new DoodleLine;
|
DoodleLine *line = new DoodleLine;
|
||||||
stream >> line->x1 >>
|
stream >> line->x1 >>
|
||||||
line->y1 >>
|
line->y1 >>
|
||||||
line->x2 >>
|
line->x2 >>
|
||||||
line->y2;
|
line->y2;
|
||||||
lines.Append(line);
|
m_lines.Append(line);
|
||||||
}
|
}
|
||||||
|
|
||||||
return stream;
|
return stream;
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
wxInputStream &DoodleSegment::LoadObject(wxInputStream& stream)
|
wxInputStream &DoodleSegment::LoadObject(wxInputStream& stream)
|
||||||
{
|
{
|
||||||
wxTextInputStream text_stream( stream );
|
wxTextInputStream text_stream( stream );
|
||||||
|
|
||||||
wxInt32 n = 0;
|
wxInt32 n = 0;
|
||||||
text_stream >> n;
|
text_stream >> n;
|
||||||
|
|
||||||
for (int i = 0; i < n; i++)
|
for (int i = 0; i < n; i++)
|
||||||
{
|
{
|
||||||
DoodleLine *line = new DoodleLine;
|
DoodleLine* line = new DoodleLine;
|
||||||
text_stream >> line->x1 >>
|
text_stream >> line->x1 >>
|
||||||
line->y1 >>
|
line->y1 >>
|
||||||
line->x2 >>
|
line->x2 >>
|
||||||
line->y2;
|
line->y2;
|
||||||
lines.Append(line);
|
m_lines.Append(line);
|
||||||
}
|
}
|
||||||
|
|
||||||
return stream;
|
return 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();
|
||||||
dc->DrawLine(line->x1, line->y1, line->x2, line->y2);
|
dc->DrawLine(line->x1, line->y1, line->x2, line->y2);
|
||||||
node = node->GetNext();
|
node = node->GetNext();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* 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:
|
|
||||||
{
|
{
|
||||||
// Cut the last segment
|
case DOODLE_CUT:
|
||||||
if (doc->GetDoodleSegments().GetCount() > 0)
|
// Cut the last segment
|
||||||
{
|
if (m_doc->GetDoodleSegments().GetCount() > 0)
|
||||||
wxList::compatibility_iterator node = doc->GetDoodleSegments().GetLast();
|
{
|
||||||
if (segment)
|
wxList::compatibility_iterator node = m_doc->GetDoodleSegments().GetLast();
|
||||||
delete segment;
|
if (m_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:
|
||||||
|
m_doc->GetDoodleSegments().Append(new DoodleSegment(*m_segment));
|
||||||
|
m_doc->Modify(true);
|
||||||
|
m_doc->UpdateAllViews();
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
case DOODLE_ADD:
|
return true;
|
||||||
{
|
|
||||||
doc->GetDoodleSegments().Append(new DoodleSegment(*segment));
|
|
||||||
doc->Modify(true);
|
|
||||||
doc->UpdateAllViews();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool DrawingCommand::Undo(void)
|
bool DrawingCommand::Undo(void)
|
||||||
{
|
{
|
||||||
switch (cmd)
|
switch (m_cmd)
|
||||||
{
|
|
||||||
case DOODLE_CUT:
|
|
||||||
{
|
{
|
||||||
// Paste the segment
|
case DOODLE_CUT:
|
||||||
if (segment)
|
{
|
||||||
{
|
// Paste the segment
|
||||||
doc->GetDoodleSegments().Append(segment);
|
if (m_segment)
|
||||||
doc->Modify(true);
|
{
|
||||||
doc->UpdateAllViews();
|
m_doc->GetDoodleSegments().Append(m_segment);
|
||||||
segment = (DoodleSegment *) NULL;
|
m_doc->Modify(true);
|
||||||
}
|
m_doc->UpdateAllViews();
|
||||||
doc->Modify(true);
|
m_segment = NULL;
|
||||||
doc->UpdateAllViews();
|
}
|
||||||
break;
|
m_doc->Modify(true);
|
||||||
}
|
m_doc->UpdateAllViews();
|
||||||
case DOODLE_ADD:
|
break;
|
||||||
{
|
}
|
||||||
// Cut the last segment
|
case DOODLE_ADD:
|
||||||
if (doc->GetDoodleSegments().GetCount() > 0)
|
{
|
||||||
{
|
// Cut the last segment
|
||||||
wxList::compatibility_iterator node = doc->GetDoodleSegments().GetLast();
|
if (m_doc->GetDoodleSegments().GetCount() > 0)
|
||||||
DoodleSegment *seg = (DoodleSegment *)node->GetData();
|
{
|
||||||
delete seg;
|
wxList::compatibility_iterator node = m_doc->GetDoodleSegments().GetLast();
|
||||||
doc->GetDoodleSegments().Erase(node);
|
DoodleSegment* seg = (DoodleSegment*)node->GetData();
|
||||||
|
delete seg;
|
||||||
|
m_doc->GetDoodleSegments().Erase(node);
|
||||||
|
|
||||||
doc->Modify(true);
|
m_doc->Modify(true);
|
||||||
doc->UpdateAllViews();
|
m_doc->UpdateAllViews();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
return true;
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
IMPLEMENT_DYNAMIC_CLASS(TextEditDocument, wxDocument)
|
IMPLEMENT_DYNAMIC_CLASS(TextEditDocument, wxDocument)
|
||||||
@@ -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;
|
||||||
|
}
|
||||||
|
|
||||||
|
@@ -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"
|
||||||
@@ -18,88 +18,89 @@
|
|||||||
// Plots a line from one point to the other
|
// Plots a line from one point to the other
|
||||||
class DoodleLine: public wxObject
|
class DoodleLine: public wxObject
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
wxInt32 x1;
|
wxInt32 x1;
|
||||||
wxInt32 y1;
|
wxInt32 y1;
|
||||||
wxInt32 x2;
|
wxInt32 x2;
|
||||||
wxInt32 y2;
|
wxInt32 y2;
|
||||||
};
|
};
|
||||||
|
|
||||||
// Contains a list of lines: represents a mouse-down doodle
|
// Contains a list of lines: represents a mouse-down doodle
|
||||||
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 m_doodleSegments;
|
||||||
wxList 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
|
||||||
#define DOODLE_ADD 2
|
#define DOODLE_ADD 2
|
||||||
|
|
||||||
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 TextEditDocument: public wxDocument
|
class TextEditView;
|
||||||
|
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&);
|
||||||
*/
|
*/
|
||||||
virtual bool OnSaveDocument(const wxString& filename);
|
TextEditView* GetFirstView() const;
|
||||||
virtual bool OnOpenDocument(const wxString& filename);
|
|
||||||
virtual bool IsModified(void) const;
|
|
||||||
virtual void Modify(bool mod);
|
|
||||||
|
|
||||||
TextEditDocument(void) {}
|
virtual bool OnSaveDocument(const wxString& filename);
|
||||||
~TextEditDocument(void) {}
|
virtual bool OnOpenDocument(const wxString& filename);
|
||||||
|
virtual bool IsModified() const;
|
||||||
|
virtual void Modify(bool mod);
|
||||||
|
|
||||||
|
TextEditDocument() {}
|
||||||
|
virtual ~TextEditDocument() {}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@@ -36,80 +36,86 @@
|
|||||||
#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)
|
||||||
{
|
{
|
||||||
//// Create a document manager
|
if ( !wxApp::OnInit() )
|
||||||
m_docManager = new wxDocManager;
|
return false;
|
||||||
|
//// Create a document manager
|
||||||
|
SetAppName(wxT("DocView Demo"));
|
||||||
|
|
||||||
//// Create a template relating drawing documents to their views
|
//// Create a document manager
|
||||||
(void) new wxDocTemplate((wxDocManager *) m_docManager, _T("Drawing"), _T("*.drw"), _T(""), _T("drw"), _T("Drawing Doc"), _T("Drawing View"),
|
m_docManager = new wxDocManager;
|
||||||
|
|
||||||
|
//// Create a template relating drawing documents to their views
|
||||||
|
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.
|
|
||||||
m_docManager->FileHistoryUseMenu(file_menu);
|
|
||||||
|
|
||||||
wxMenu *help_menu = new wxMenu;
|
// A nice touch: a history of files visited. Use this menu.
|
||||||
help_menu->Append(DOCVIEW_ABOUT, _T("&About\tF1"));
|
m_docManager->FileHistoryUseMenu(file_menu);
|
||||||
|
|
||||||
wxMenuBar *menu_bar = new wxMenuBar;
|
wxMenu *help_menu = new wxMenu;
|
||||||
|
help_menu->Append(DOCVIEW_ABOUT);
|
||||||
|
|
||||||
menu_bar->Append(file_menu, _T("&File"));
|
wxMenuBar *menu_bar = new wxMenuBar;
|
||||||
if (edit_menu)
|
|
||||||
menu_bar->Append(edit_menu, _T("&Edit"));
|
menu_bar->Append(file_menu, wxGetStockLabel(wxID_FILE));
|
||||||
menu_bar->Append(help_menu, _T("&Help"));
|
if (edit_menu)
|
||||||
|
menu_bar->Append(edit_menu, wxGetStockLabel(wxID_EDIT));
|
||||||
|
menu_bar->Append(help_menu, wxGetStockLabel(wxID_HELP));
|
||||||
|
|
||||||
#ifdef __WXMAC__
|
#ifdef __WXMAC__
|
||||||
wxMenuBar::MacSetCommonMenuBar(menu_bar);
|
wxMenuBar::MacSetCommonMenuBar(menu_bar);
|
||||||
#endif //def __WXMAC__
|
#endif //def __WXMAC__
|
||||||
//// Associate the menu bar with the frame
|
//// Associate the menu bar with the frame
|
||||||
frame->SetMenuBar(menu_bar);
|
frame->SetMenuBar(menu_bar);
|
||||||
|
|
||||||
frame->Centre(wxBOTH);
|
frame->Centre(wxBOTH);
|
||||||
#ifndef __WXMAC__
|
#ifndef __WXMAC__
|
||||||
frame->Show(true);
|
frame->Show(true);
|
||||||
#endif //ndef __WXMAC__
|
#endif //ndef __WXMAC__
|
||||||
|
|
||||||
SetTopWindow(frame);
|
SetTopWindow(frame);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
int MyApp::OnExit(void)
|
int MyApp::OnExit(void)
|
||||||
{
|
{
|
||||||
delete m_docManager;
|
wxDELETE(m_docManager)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -117,76 +123,78 @@ int MyApp::OnExit(void)
|
|||||||
* Centralised code for creating a document frame.
|
* Centralised code for creating a document frame.
|
||||||
* Called from view.cpp, when a view is created.
|
* Called from view.cpp, when a view is created.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
wxMDIChildFrame *MyApp::CreateChildFrame(wxDocument *doc, wxView *view, bool isCanvas)
|
wxMDIChildFrame *MyApp::CreateChildFrame(wxDocument *doc, wxView *view, bool isCanvas)
|
||||||
{
|
{
|
||||||
//// 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)
|
||||||
|
{
|
||||||
|
file_menu->AppendSeparator();
|
||||||
|
file_menu->Append(wxID_PRINT);
|
||||||
|
file_menu->Append(wxID_PRINT_SETUP, wxT("Print &Setup..."));
|
||||||
|
file_menu->Append(wxID_PREVIEW);
|
||||||
|
}
|
||||||
|
|
||||||
if (isCanvas)
|
|
||||||
{
|
|
||||||
file_menu->AppendSeparator();
|
file_menu->AppendSeparator();
|
||||||
file_menu->Append(wxID_PRINT, _T("&Print..."));
|
file_menu->Append(wxID_EXIT);
|
||||||
file_menu->Append(wxID_PRINT_SETUP, _T("Print &Setup..."));
|
|
||||||
file_menu->Append(wxID_PREVIEW, _T("Print Pre&view"));
|
|
||||||
}
|
|
||||||
|
|
||||||
file_menu->AppendSeparator();
|
wxMenu *edit_menu = new wxMenu;
|
||||||
file_menu->Append(wxID_EXIT, _T("E&xit"));
|
if (isCanvas)
|
||||||
|
{
|
||||||
|
edit_menu->Append(wxID_UNDO);
|
||||||
|
edit_menu->Append(wxID_REDO);
|
||||||
|
edit_menu->AppendSeparator();
|
||||||
|
edit_menu->Append(DOCVIEW_CUT, wxT("&Cut last segment"));
|
||||||
|
|
||||||
wxMenu *edit_menu = (wxMenu *) NULL;
|
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);
|
||||||
|
|
||||||
if (isCanvas)
|
wxMenuBar *menu_bar = new wxMenuBar;
|
||||||
{
|
|
||||||
edit_menu = new wxMenu;
|
|
||||||
edit_menu->Append(wxID_UNDO, _T("&Undo"));
|
|
||||||
edit_menu->Append(wxID_REDO, _T("&Redo"));
|
|
||||||
edit_menu->AppendSeparator();
|
|
||||||
edit_menu->Append(DOCVIEW_CUT, _T("&Cut last segment"));
|
|
||||||
|
|
||||||
doc->GetCommandProcessor()->SetEditMenu(edit_menu);
|
menu_bar->Append(file_menu, wxGetStockLabel(wxID_FILE));
|
||||||
}
|
menu_bar->Append(edit_menu, wxGetStockLabel(wxID_EDIT));
|
||||||
|
menu_bar->Append(help_menu, wxGetStockLabel(wxID_HELP));
|
||||||
|
|
||||||
wxMenu *help_menu = new wxMenu;
|
//// Associate the menu bar with the frame
|
||||||
help_menu->Append(DOCVIEW_ABOUT, _T("&About"));
|
subframe->SetMenuBar(menu_bar);
|
||||||
|
|
||||||
wxMenuBar *menu_bar = new wxMenuBar;
|
return subframe;
|
||||||
|
|
||||||
menu_bar->Append(file_menu, _T("&File"));
|
|
||||||
if (isCanvas)
|
|
||||||
menu_bar->Append(edit_menu, _T("&Edit"));
|
|
||||||
menu_bar->Append(help_menu, _T("&Help"));
|
|
||||||
|
|
||||||
//// Associate the menu bar with the frame
|
|
||||||
subframe->SetMenuBar(menu_bar);
|
|
||||||
|
|
||||||
return subframe;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This is the top-level window of the application.
|
* This is the top-level window of the application.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
IMPLEMENT_CLASS(MyFrame, wxDocMDIParentFrame)
|
IMPLEMENT_CLASS(MyFrame, wxDocMDIParentFrame)
|
||||||
BEGIN_EVENT_TABLE(MyFrame, wxDocMDIParentFrame)
|
BEGIN_EVENT_TABLE(MyFrame, wxDocMDIParentFrame)
|
||||||
EVT_MENU(DOCVIEW_ABOUT, MyFrame::OnAbout)
|
EVT_MENU(DOCVIEW_ABOUT, MyFrame::OnAbout)
|
||||||
@@ -194,35 +202,41 @@ 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
|
||||||
canvas->SetScrollbars(20, 20, 50, 50);
|
canvas->SetScrollbars(20, 20, 50, 50);
|
||||||
|
|
||||||
return canvas;
|
return canvas;
|
||||||
}
|
}
|
||||||
|
|
||||||
MyFrame *GetMainFrame(void)
|
MyFrame* GetMainFrame()
|
||||||
{
|
{
|
||||||
return frame;
|
return frame;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -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"
|
||||||
@@ -21,14 +21,14 @@ class wxDocManager;
|
|||||||
// Define a new application
|
// Define a new application
|
||||||
class MyApp: public wxApp
|
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* m_editMenu;
|
||||||
wxMenu *editMenu;
|
|
||||||
|
|
||||||
MyFrame(wxDocManager *manager, wxFrame *frame, const wxString& title, const wxPoint& pos, const wxSize& size,
|
|
||||||
long type);
|
|
||||||
|
|
||||||
void OnAbout(wxCommandEvent& event);
|
MyFrame(wxDocManager*, wxFrame*, const wxString& title, const wxPoint&, const wxSize&, long type);
|
||||||
MyCanvas *CreateCanvas(wxView *view, wxMDIChildFrame *parent);
|
|
||||||
|
|
||||||
DECLARE_EVENT_TABLE()
|
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_CUT 1
|
||||||
#define DOCVIEW_ABOUT wxID_ABOUT
|
#define DOCVIEW_ABOUT wxID_ABOUT
|
||||||
|
@@ -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,53 +42,58 @@ 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)
|
||||||
{
|
{
|
||||||
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();
|
||||||
seg->Draw(dc);
|
seg->Draw(dc);
|
||||||
node = node->GetNext();
|
node = node->GetNext();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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__
|
||||||
if (canvas)
|
if (canvas)
|
||||||
canvas->Refresh();
|
canvas->Refresh();
|
||||||
#else
|
#else
|
||||||
if (canvas)
|
if (canvas)
|
||||||
{
|
{
|
||||||
wxClientDC dc(canvas);
|
wxClientDC dc(canvas);
|
||||||
dc.Clear();
|
dc.Clear();
|
||||||
OnDraw(& dc);
|
OnDraw(& dc);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
*/
|
*/
|
||||||
@@ -97,59 +102,58 @@ void DrawingView::OnUpdate(wxView *WXUNUSED(sender), wxObject *WXUNUSED(hint))
|
|||||||
// Clean up windows used for displaying the view.
|
// Clean up windows used for displaying the view.
|
||||||
bool DrawingView::OnClose(bool deleteWindow)
|
bool DrawingView::OnClose(bool deleteWindow)
|
||||||
{
|
{
|
||||||
if (!GetDocument()->Close())
|
if (!GetDocument()->Close())
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
// 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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Handled by wxTextWindow
|
// Handled by wxTextWindow
|
||||||
@@ -163,17 +167,32 @@ void TextEditView::OnUpdate(wxView *WXUNUSED(sender), wxObject *WXUNUSED(hint) )
|
|||||||
|
|
||||||
bool TextEditView::OnClose(bool deleteWindow)
|
bool TextEditView::OnClose(bool deleteWindow)
|
||||||
{
|
{
|
||||||
if (!GetDocument()->Close())
|
if (!GetDocument()->Close())
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
Activate(false);
|
Activate(false);
|
||||||
|
|
||||||
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -185,77 +204,76 @@ 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);
|
||||||
|
|
||||||
dc.SetPen(*wxBLACK_PEN);
|
dc.SetPen(*wxBLACK_PEN);
|
||||||
|
|
||||||
wxPoint pt(event.GetLogicalPosition(dc));
|
wxPoint pt(event.GetLogicalPosition(dc));
|
||||||
|
|
||||||
if (currentSegment && event.LeftUp())
|
if (currentSegment && event.LeftUp())
|
||||||
{
|
|
||||||
if (currentSegment->lines.GetCount() == 0)
|
|
||||||
{
|
{
|
||||||
delete currentSegment;
|
if (currentSegment->m_lines.GetCount() == 0)
|
||||||
currentSegment = (DoodleSegment *) NULL;
|
{
|
||||||
|
delete currentSegment;
|
||||||
|
currentSegment = NULL;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// We've got a valid segment on mouse left up, so store it.
|
||||||
|
DrawingDocument* doc = m_view->GetDocument();
|
||||||
|
|
||||||
|
doc->GetCommandProcessor()->Submit(new DrawingCommand(wxT("Add Segment"), DOODLE_ADD, doc, currentSegment));
|
||||||
|
|
||||||
|
m_view->GetDocument()->Modify(true);
|
||||||
|
currentSegment = NULL;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
|
||||||
|
if ( (xpos > -1) && (ypos > -1) && event.Dragging())
|
||||||
{
|
{
|
||||||
// We've got a valid segment on mouse left up, so store it.
|
if (!currentSegment)
|
||||||
DrawingDocument *doc = (DrawingDocument *)view->GetDocument();
|
currentSegment = new DoodleSegment;
|
||||||
|
|
||||||
doc->GetCommandProcessor()->Submit(new DrawingCommand(_T("Add Segment"), DOODLE_ADD, doc, currentSegment));
|
DoodleLine *newLine = new DoodleLine;
|
||||||
|
newLine->x1 = (long)xpos;
|
||||||
|
newLine->y1 = (long)ypos;
|
||||||
|
newLine->x2 = pt.x;
|
||||||
|
newLine->y2 = pt.y;
|
||||||
|
currentSegment->m_lines.Append(newLine);
|
||||||
|
|
||||||
view->GetDocument()->Modify(true);
|
dc.DrawLine( (long)xpos, (long)ypos, pt.x, pt.y);
|
||||||
currentSegment = (DoodleSegment *) NULL;
|
|
||||||
}
|
}
|
||||||
}
|
xpos = pt.x;
|
||||||
|
ypos = pt.y;
|
||||||
if (xpos > -1 && ypos > -1 && event.Dragging())
|
|
||||||
{
|
|
||||||
if (!currentSegment)
|
|
||||||
currentSegment = new DoodleSegment;
|
|
||||||
|
|
||||||
DoodleLine *newLine = new DoodleLine;
|
|
||||||
newLine->x1 = (long)xpos;
|
|
||||||
newLine->y1 = (long)ypos;
|
|
||||||
newLine->x2 = pt.x;
|
|
||||||
newLine->y2 = pt.y;
|
|
||||||
currentSegment->lines.Append(newLine);
|
|
||||||
|
|
||||||
dc.DrawLine( (long)xpos, (long)ypos, pt.x, pt.y);
|
|
||||||
}
|
|
||||||
xpos = pt.x;
|
|
||||||
ypos = pt.y;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@@ -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 MyCanvas: public wxScrolledWindow
|
class DrawingView;
|
||||||
|
class MyCanvas : public wxScrolledWindow
|
||||||
{
|
{
|
||||||
public:
|
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()
|
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 DrawingView: public wxView
|
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)
|
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
|
||||||
{
|
{
|
||||||
|
DECLARE_DYNAMIC_CLASS(TextEditView)
|
||||||
public:
|
public:
|
||||||
wxMDIChildFrame *frame;
|
wxMDIChildFrame* m_frame;
|
||||||
MyTextWindow *textsw;
|
MyTextWindow* m_textsw;
|
||||||
|
|
||||||
TextEditView(): wxView() { frame = (wxMDIChildFrame *) NULL; textsw = (MyTextWindow *) NULL; }
|
|
||||||
~TextEditView() {}
|
|
||||||
|
|
||||||
bool OnCreate(wxDocument *doc, long flags);
|
TextEditView() : wxView() { m_frame = NULL; m_textsw = NULL; }
|
||||||
void OnDraw(wxDC *dc);
|
virtual ~TextEditView() {}
|
||||||
void OnUpdate(wxView *sender, wxObject *hint = (wxObject *) NULL);
|
|
||||||
bool OnClose(bool deleteWindow = true);
|
virtual bool OnCreate(wxDocument*, long flags);
|
||||||
|
virtual void OnDraw(wxDC* dc);
|
||||||
private:
|
virtual void OnUpdate(wxView *sender, wxObject *hint = NULL);
|
||||||
DECLARE_DYNAMIC_CLASS(TextEditView)
|
virtual bool OnClose(bool deleteWindow = true);
|
||||||
|
virtual bool ProcessEvent(wxEvent&);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
Reference in New Issue
Block a user