DrawingDocument::~DrawingDocument(void)
{
- WX_CLEAR_LIST(wxList, doodleSegments);
+ WX_CLEAR_LIST(wxList, m_doodleSegments)
}
#if wxUSE_STD_IOSTREAM
{
wxDocument::SaveObject(stream);
- wxInt32 n = doodleSegments.GetCount();
+ wxInt32 n = m_doodleSegments.GetCount();
stream << n << '\n';
- wxList::compatibility_iterator node = doodleSegments.GetFirst();
+ wxList::compatibility_iterator node = m_doodleSegments.GetFirst();
while (node)
{
DoodleSegment *segment = (DoodleSegment *)node->GetData();
wxTextOutputStream text_stream( stream );
- wxInt32 n = doodleSegments.GetCount();
+ wxInt32 n = m_doodleSegments.GetCount();
text_stream << n << '\n';
- wxList::compatibility_iterator node = doodleSegments.GetFirst();
+ wxList::compatibility_iterator node = m_doodleSegments.GetFirst();
while (node)
{
DoodleSegment *segment = (DoodleSegment *)node->GetData();
{
DoodleSegment *segment = new DoodleSegment;
segment->LoadObject(stream);
- doodleSegments.Append(segment);
+ m_doodleSegments.Append(segment);
}
return stream;
{
DoodleSegment *segment = new DoodleSegment;
segment->LoadObject(stream);
- doodleSegments.Append(segment);
+ m_doodleSegments.Append(segment);
}
return stream;
DoodleSegment::DoodleSegment(const DoodleSegment& seg):wxObject()
{
- wxList::compatibility_iterator node = seg.lines.GetFirst();
+ wxList::compatibility_iterator node = seg.m_lines.GetFirst();
while (node)
{
DoodleLine *line = (DoodleLine *)node->GetData();
newLine->x2 = line->x2;
newLine->y2 = line->y2;
- lines.Append(newLine);
+ m_lines.Append(newLine);
node = node->GetNext();
}
DoodleSegment::~DoodleSegment(void)
{
- WX_CLEAR_LIST(wxList, lines);
+ WX_CLEAR_LIST(wxList, m_lines)
}
#if wxUSE_STD_IOSTREAM
wxSTD ostream& DoodleSegment::SaveObject(wxSTD ostream& stream)
{
- wxInt32 n = lines.GetCount();
+ wxInt32 n = m_lines.GetCount();
stream << n << '\n';
- wxList::compatibility_iterator node = lines.GetFirst();
+ wxList::compatibility_iterator node = m_lines.GetFirst();
while (node)
{
DoodleLine *line = (DoodleLine *)node->GetData();
{
wxTextOutputStream text_stream( stream );
- wxInt32 n = lines.GetCount();
- text_stream << n << _T("\n");
+ wxInt32 n = m_lines.GetCount();
+ text_stream << n << wxT("\n");
- wxList::compatibility_iterator node = lines.GetFirst();
+ wxList::compatibility_iterator node = m_lines.GetFirst();
while (node)
{
- DoodleLine *line = (DoodleLine *)node->GetData();
- text_stream << line->x1 << _T(" ") <<
- line->y1 << _T(" ") <<
- line->x2 << _T(" ") <<
- line->y2 << _T("\n");
+ DoodleLine* line = (DoodleLine*)node->GetData();
+ text_stream << line->x1 << wxT(" ") <<
+ line->y1 << wxT(" ") <<
+ line->x2 << wxT(" ") <<
+ line->y2 << wxT("\n");
node = node->GetNext();
}
line->y1 >>
line->x2 >>
line->y2;
- lines.Append(line);
+ m_lines.Append(line);
}
return stream;
line->y1 >>
line->x2 >>
line->y2;
- lines.Append(line);
+ m_lines.Append(line);
}
return stream;
void DoodleSegment::Draw(wxDC *dc)
{
- wxList::compatibility_iterator node = lines.GetFirst();
+ wxList::compatibility_iterator node = m_lines.GetFirst();
while (node)
{
DoodleLine *line = (DoodleLine *)node->GetData();
* Implementation of drawing command
*/
-DrawingCommand::DrawingCommand(const wxString& name, int command, DrawingDocument *ddoc, DoodleSegment *seg):
-wxCommand(true, name)
+DrawingCommand::DrawingCommand(const wxString& name, int command, DrawingDocument* doc, DoodleSegment* seg) :
+ wxCommand(true, name)
{
- doc = ddoc;
- segment = seg;
- cmd = command;
+ m_doc = doc;
+ m_segment = seg;
+ m_cmd = command;
}
DrawingCommand::~DrawingCommand(void)
{
- if (segment)
- delete segment;
+ if (m_segment)
+ delete m_segment;
}
bool DrawingCommand::Do(void)
{
- switch (cmd)
+ switch (m_cmd)
{
case DOODLE_CUT:
{
// Cut the last segment
- if (doc->GetDoodleSegments().GetCount() > 0)
+ if (m_doc->GetDoodleSegments().GetCount() > 0)
{
- wxList::compatibility_iterator node = doc->GetDoodleSegments().GetLast();
- if (segment)
- delete segment;
+ wxList::compatibility_iterator node = m_doc->GetDoodleSegments().GetLast();
+ if (m_segment)
+ delete m_segment;
- segment = (DoodleSegment *)node->GetData();
- doc->GetDoodleSegments().Erase(node);
+ m_segment = (DoodleSegment*)node->GetData();
+ m_doc->GetDoodleSegments().Erase(node);
- doc->Modify(true);
- doc->UpdateAllViews();
+ m_doc->Modify(true);
+ m_doc->UpdateAllViews();
}
break;
}
case DOODLE_ADD:
{
- doc->GetDoodleSegments().Append(new DoodleSegment(*segment));
- doc->Modify(true);
- doc->UpdateAllViews();
+ m_doc->GetDoodleSegments().Append(new DoodleSegment(*m_segment));
+ m_doc->Modify(true);
+ m_doc->UpdateAllViews();
break;
}
}
bool DrawingCommand::Undo(void)
{
- switch (cmd)
+ switch (m_cmd)
{
case DOODLE_CUT:
{
// Paste the segment
- if (segment)
+ if (m_segment)
{
- doc->GetDoodleSegments().Append(segment);
- doc->Modify(true);
- doc->UpdateAllViews();
- segment = (DoodleSegment *) NULL;
+ m_doc->GetDoodleSegments().Append(m_segment);
+ m_doc->Modify(true);
+ m_doc->UpdateAllViews();
+ m_segment = NULL;
}
- doc->Modify(true);
- doc->UpdateAllViews();
+ m_doc->Modify(true);
+ m_doc->UpdateAllViews();
break;
}
case DOODLE_ADD:
{
// Cut the last segment
- if (doc->GetDoodleSegments().GetCount() > 0)
+ if (m_doc->GetDoodleSegments().GetCount() > 0)
{
- wxList::compatibility_iterator node = doc->GetDoodleSegments().GetLast();
- DoodleSegment *seg = (DoodleSegment *)node->GetData();
+ wxList::compatibility_iterator node = m_doc->GetDoodleSegments().GetLast();
+ DoodleSegment* seg = (DoodleSegment*)node->GetData();
delete seg;
- doc->GetDoodleSegments().Erase(node);
+ m_doc->GetDoodleSegments().Erase(node);
- doc->Modify(true);
- doc->UpdateAllViews();
+ m_doc->Modify(true);
+ m_doc->UpdateAllViews();
}
}
}
// we override OnSave/OpenDocument instead of Save/LoadObject
bool TextEditDocument::OnSaveDocument(const wxString& filename)
{
- TextEditView *view = (TextEditView *)GetFirstView();
+ TextEditView* view = GetFirstView();
- if (!view->textsw->SaveFile(filename))
+ if (!view->m_textsw->SaveFile(filename))
return false;
Modify(false);
#ifdef __WXMAC__
bool TextEditDocument::OnOpenDocument(const wxString& filename)
{
- TextEditView *view = (TextEditView *)GetFirstView();
- if (!view->textsw->LoadFile(filename))
+ TextEditView* view = GetFirstView();
+ if (!view->m_textsw->LoadFile(filename))
return false;
SetFilename(filename, true);
bool TextEditDocument::IsModified(void) const
{
- TextEditView *view = (TextEditView *)GetFirstView();
- if (view)
- {
- return (wxDocument::IsModified() || view->textsw->IsModified());
- }
- else
- return wxDocument::IsModified();
+ TextEditView* view = GetFirstView();
+ return (wxDocument::IsModified() || (view && view->m_textsw->IsModified()));
}
void TextEditDocument::Modify(bool mod)
{
- TextEditView *view = (TextEditView *)GetFirstView();
+ TextEditView* view = GetFirstView();
wxDocument::Modify(mod);
- if (!mod && view && view->textsw)
- view->textsw->DiscardEdits();
+ if (!mod && view && view->m_textsw)
+ view->m_textsw->DiscardEdits();
}
+
+TextEditView* TextEditDocument::GetFirstView() const
+{
+ wxView* view = wxDocument::GetFirstView();
+ return view ? wxStaticCast(view, TextEditView) : NULL;
+}
+
// Licence: wxWindows license
/////////////////////////////////////////////////////////////////////////////
-#ifndef __DOCSAMPLEH__
-#define __DOCSAMPLEH__
+#ifndef __DOC_H__
+#define __DOC_H__
#include "wx/docview.h"
#include "wx/cmdproc.h"
// Plots a line from one point to the other
-class DoodleLine: public wxObject
+class DoodleLine : public wxObject
{
public:
wxInt32 x1;
};
// Contains a list of lines: represents a mouse-down doodle
-class DoodleSegment: public wxObject
+class DoodleSegment : public wxObject
{
public:
- wxList lines;
+ wxList m_lines;
- DoodleSegment(void){};
+ DoodleSegment() : wxObject() {}
DoodleSegment(const DoodleSegment& seg);
- ~DoodleSegment(void);
+ virtual ~DoodleSegment();
void Draw(wxDC *dc);
#if wxUSE_STD_IOSTREAM
};
-class DrawingDocument: public wxDocument
+class DrawingDocument : public wxDocument
{
DECLARE_DYNAMIC_CLASS(DrawingDocument)
private:
public:
- wxList doodleSegments;
+ wxList m_doodleSegments;
- DrawingDocument(void){};
- ~DrawingDocument(void);
+ DrawingDocument() : wxDocument() {}
+ virtual ~DrawingDocument();
#if wxUSE_STD_IOSTREAM
wxSTD ostream& SaveObject(wxSTD ostream& text_stream);
wxInputStream& LoadObject(wxInputStream& stream);
#endif
- inline wxList& GetDoodleSegments(void) const { return (wxList&) doodleSegments; };
+ inline wxList& GetDoodleSegments() const { return (wxList&) m_doodleSegments; };
};
#define DOODLE_CUT 1
#define DOODLE_ADD 2
-class DrawingCommand: public wxCommand
+class DrawingCommand : public wxCommand
{
protected:
- DoodleSegment *segment;
- DrawingDocument *doc;
- int cmd;
+ DoodleSegment* m_segment;
+ DrawingDocument* m_doc;
+ int m_cmd;
public:
- DrawingCommand(const wxString& name, int cmd, DrawingDocument *ddoc, DoodleSegment *seg);
- ~DrawingCommand(void);
+ DrawingCommand(const wxString& name, int cmd, DrawingDocument*, DoodleSegment*);
+ virtual ~DrawingCommand();
bool Do(void);
bool Undo(void);
};
-class TextEditDocument: public wxDocument
+class TextEditView;
+class TextEditDocument : public wxDocument
{
DECLARE_DYNAMIC_CLASS(TextEditDocument)
-private:
public:
+ TextEditDocument() : wxDocument() {}
+ virtual ~TextEditDocument() {}
/*
-wxSTD ostream& SaveObject(wxSTD ostream& stream);
-wxSTD istream& LoadObject(wxSTD istream& stream);
- */
+ wxSTD ostream& SaveObject(wxSTD ostream&);
+ wxSTD istream& LoadObject(wxSTD istream&);
+*/
+ TextEditView* GetFirstView() const;
+
virtual bool OnSaveDocument(const wxString& filename);
virtual bool OnOpenDocument(const wxString& filename);
virtual bool IsModified(void) const;
virtual void Modify(bool mod);
-
- TextEditDocument(void) {}
- ~TextEditDocument(void) {}
};
#ifdef __WXMAC__
#include "wx/filename.h"
#endif
+#include "wx/stockitem.h"
-MyFrame *frame = (MyFrame *) NULL;
+static MyFrame* frame = NULL;
// In single window mode, don't have any child windows; use
// main window.
MyApp::MyApp(void)
{
- m_docManager = (wxDocManager *) NULL;
+ m_docManager = NULL;
}
bool MyApp::OnInit(void)
{
if ( !wxApp::OnInit() )
return false;
+ SetAppName(wxT("DocView Demo"));
+
//// Find out if we're:
//// multiple window: multiple windows, each view in a separate frame
//// In single window mode, we only allow one document type
if (argc > 1)
{
- if (wxStrcmp(argv[1], _T("-single")) == 0)
+ if (wxStrcmp(argv[1], wxT("-single")) == 0)
{
singleWindowMode = true;
}
}
-
+
//// Create a document manager
m_docManager = new wxDocManager;
//// Create a template relating drawing documents to their views
- (void) new wxDocTemplate(m_docManager, _T("Drawing"), _T("*.drw"), _T(""), _T("drw"), _T("Drawing Doc"), _T("Drawing View"),
+ new wxDocTemplate(m_docManager, wxT("Drawing"), wxT("*.drw"), wxT(""), wxT("drw"), wxT("Drawing Doc"), wxT("Drawing View"),
CLASSINFO(DrawingDocument), CLASSINFO(DrawingView));
#ifdef __WXMAC__
wxFileName::MacRegisterDefaultTypeAndCreator( wxT("drw") , 'WXMB' , 'WXMA' ) ;
#endif
-
+
if (singleWindowMode)
{
// If we've only got one window, we only get to edit
else
{
//// Create a template relating text documents to their views
- (void) new wxDocTemplate(m_docManager, _T("Text"), _T("*.txt;*.text"), _T(""), _T("txt;text"), _T("Text Doc"), _T("Text View"),
+ new wxDocTemplate(m_docManager, wxT("Text"), wxT("*.txt;*.text"), wxT(""), wxT("txt;text"), wxT("Text Doc"), wxT("Text View"),
CLASSINFO(TextEditDocument), CLASSINFO(TextEditView));
#ifdef __WXMAC__
wxFileName::MacRegisterDefaultTypeAndCreator( wxT("txt") , 'TEXT' , 'WXMA' ) ;
#endif
}
-
+
//// Create the main frame window
- frame = new MyFrame(m_docManager, (wxFrame *) NULL, wxID_ANY, _T("DocView Demo"), wxPoint(0, 0), wxSize(500, 400), wxDEFAULT_FRAME_STYLE);
-
+ frame = new MyFrame(m_docManager, NULL, wxID_ANY, GetAppDisplayName(), wxPoint(0, 0), wxSize(500, 400), wxDEFAULT_FRAME_STYLE);
+
//// Give it an icon (this is ignored in MDI mode: uses resources)
#ifdef __WXMSW__
- frame->SetIcon(wxIcon(_T("doc_icn")));
+ frame->SetIcon(wxIcon(wxT("doc_icn")));
#endif
-
+
//// Make a menubar
wxMenu *file_menu = new wxMenu;
- wxMenu *edit_menu = (wxMenu *) NULL;
-
- file_menu->Append(wxID_NEW, _T("&New..."));
- file_menu->Append(wxID_OPEN, _T("&Open..."));
-
+ wxMenu *edit_menu = NULL;
+
+ file_menu->Append(wxID_NEW);
+ file_menu->Append(wxID_OPEN);
+
if (singleWindowMode)
{
- file_menu->Append(wxID_CLOSE, _T("&Close"));
- file_menu->Append(wxID_SAVE, _T("&Save"));
- file_menu->Append(wxID_SAVEAS, _T("Save &As..."));
+ file_menu->Append(wxID_CLOSE);
+ file_menu->Append(wxID_SAVE);
+ file_menu->Append(wxID_SAVEAS);
file_menu->AppendSeparator();
- file_menu->Append(wxID_PRINT, _T("&Print..."));
- file_menu->Append(wxID_PRINT_SETUP, _T("Print &Setup..."));
- file_menu->Append(wxID_PREVIEW, _T("Print Pre&view"));
-
+ file_menu->Append(wxID_PRINT);
+ file_menu->Append(wxID_PRINT_SETUP, wxT("Print &Setup..."));
+ file_menu->Append(wxID_PREVIEW);
+
edit_menu = new wxMenu;
- edit_menu->Append(wxID_UNDO, _T("&Undo"));
- edit_menu->Append(wxID_REDO, _T("&Redo"));
+ edit_menu->Append(wxID_UNDO);
+ edit_menu->Append(wxID_REDO);
edit_menu->AppendSeparator();
- edit_menu->Append(DOCVIEW_CUT, _T("&Cut last segment"));
-
- frame->editMenu = edit_menu;
+ edit_menu->Append(DOCVIEW_CUT, wxT("&Cut last segment"));
+
+ frame->m_editMenu = edit_menu;
}
-
+
file_menu->AppendSeparator();
- file_menu->Append(wxID_EXIT, _T("E&xit"));
-
+ file_menu->Append(wxID_EXIT);
+
// A nice touch: a history of files visited. Use this menu.
m_docManager->FileHistoryUseMenu(file_menu);
-
+
wxMenu *help_menu = new wxMenu;
- help_menu->Append(DOCVIEW_ABOUT, _T("&About"));
-
+ help_menu->Append(DOCVIEW_ABOUT);
+
wxMenuBar *menu_bar = new wxMenuBar;
-
- menu_bar->Append(file_menu, _T("&File"));
+
+ menu_bar->Append(file_menu, wxGetStockLabel(wxID_FILE));
if (edit_menu)
- menu_bar->Append(edit_menu, _T("&Edit"));
- menu_bar->Append(help_menu, _T("&Help"));
-
+ menu_bar->Append(edit_menu, wxGetStockLabel(wxID_EDIT));
+ menu_bar->Append(help_menu, wxGetStockLabel(wxID_HELP));
+
if (singleWindowMode)
- frame->canvas = frame->CreateCanvas((wxView *) NULL, frame);
-
+ frame->m_canvas = frame->CreateCanvas(NULL, frame);
+
//// Associate the menu bar with the frame
frame->SetMenuBar(menu_bar);
-
+
frame->Centre(wxBOTH);
frame->Show(true);
-
+
SetTopWindow(frame);
return true;
}
wxFrame *MyApp::CreateChildFrame(wxDocument *doc, wxView *view, bool isCanvas)
{
//// Make a child frame
- wxDocChildFrame *subframe = new wxDocChildFrame(doc, view, GetMainFrame(), wxID_ANY, _T("Child Frame"),
+ wxDocChildFrame *subframe = new wxDocChildFrame(doc, view, GetMainFrame(), wxID_ANY, wxT("Child Frame"),
wxPoint(10, 10), wxSize(300, 300), wxDEFAULT_FRAME_STYLE);
-
+
#ifdef __WXMSW__
- subframe->SetIcon(wxString(isCanvas ? _T("chrt_icn") : _T("notepad_icn")));
+ subframe->SetIcon(wxString(isCanvas ? wxT("chrt_icn") : wxT("notepad_icn")));
#endif
-
+
//// Make a menubar
wxMenu *file_menu = new wxMenu;
-
- file_menu->Append(wxID_NEW, _T("&New..."));
- file_menu->Append(wxID_OPEN, _T("&Open..."));
- file_menu->Append(wxID_CLOSE, _T("&Close"));
- file_menu->Append(wxID_SAVE, _T("&Save"));
- file_menu->Append(wxID_SAVEAS, _T("Save &As..."));
-
+
+ file_menu->Append(wxID_NEW);
+ file_menu->Append(wxID_OPEN);
+ file_menu->Append(wxID_CLOSE);
+ file_menu->Append(wxID_SAVE);
+ file_menu->Append(wxID_SAVEAS);
+
if (isCanvas)
{
file_menu->AppendSeparator();
- file_menu->Append(wxID_PRINT, _T("&Print..."));
- file_menu->Append(wxID_PRINT_SETUP, _T("Print &Setup..."));
- file_menu->Append(wxID_PREVIEW, _T("Print Pre&view"));
+ file_menu->Append(wxID_PRINT);
+ file_menu->Append(wxID_PRINT_SETUP, wxT("Print &Setup..."));
+ file_menu->Append(wxID_PREVIEW);
}
-
- wxMenu *edit_menu = (wxMenu *) NULL;
-
+
+ wxMenu *edit_menu = new wxMenu;
+
if (isCanvas)
{
- edit_menu = new wxMenu;
- edit_menu->Append(wxID_UNDO, _T("&Undo"));
- edit_menu->Append(wxID_REDO, _T("&Redo"));
+ edit_menu->Append(wxID_UNDO);
+ edit_menu->Append(wxID_REDO);
edit_menu->AppendSeparator();
- edit_menu->Append(DOCVIEW_CUT, _T("&Cut last segment"));
-
+ edit_menu->Append(DOCVIEW_CUT, wxT("&Cut last segment"));
+
doc->GetCommandProcessor()->SetEditMenu(edit_menu);
}
-
+ else
+ {
+ edit_menu->Append(wxID_COPY);
+ edit_menu->Append(wxID_PASTE);
+ edit_menu->Append(wxID_SELECTALL);
+ }
+
wxMenu *help_menu = new wxMenu;
- help_menu->Append(DOCVIEW_ABOUT, _T("&About"));
-
+ help_menu->Append(DOCVIEW_ABOUT);
+
wxMenuBar *menu_bar = new wxMenuBar;
-
- menu_bar->Append(file_menu, _T("&File"));
- if (isCanvas)
- menu_bar->Append(edit_menu, _T("&Edit"));
- menu_bar->Append(help_menu, _T("&Help"));
-
+
+ menu_bar->Append(file_menu, wxGetStockLabel(wxID_FILE));
+ menu_bar->Append(edit_menu, wxGetStockLabel(wxID_EDIT));
+ menu_bar->Append(help_menu, wxGetStockLabel(wxID_HELP));
+
//// Associate the menu bar with the frame
subframe->SetMenuBar(menu_bar);
-
+
subframe->Centre(wxBOTH);
-
+
return subframe;
}
wxDocParentFrame(manager, frame, id, title, pos, size, type)
{
// This pointer only needed if in single window mode
- canvas = (MyCanvas *) NULL;
- editMenu = (wxMenu *) NULL;
+ m_canvas = NULL;
+ m_editMenu = NULL;
}
void MyFrame::OnAbout(wxCommandEvent& WXUNUSED(event) )
{
- (void)wxMessageBox(_T("DocView Demo\nAuthor: Julian Smart\nUsage: docview.exe [-single]"), _T("About DocView"));
+ wxMessageBox(wxT("DocView Demo\nAuthor: Julian Smart\nUsage: docview.exe [-single]"), wxT("About DocView"));
+/*
+ Better, but brings in adv lib
+ wxAboutDialogInfo info;
+ info.SetName(wxTheApp->GetAppDisplayName());
+ info.AddDeveloper(wxT("Julian Smart"));
+ wxAboutBox(info);
+*/
}
// Creates a canvas. Called either from view.cc when a new drawing
// view is created, or in OnInit as a child of the main window,
// if in 'single window' mode.
-MyCanvas *MyFrame::CreateCanvas(wxView *view, wxFrame *parent)
+MyCanvas *MyFrame::CreateCanvas(DrawingView* view, wxFrame *parent)
{
- int width, height;
- parent->GetClientSize(&width, &height);
-
+ wxSize size = parent->GetClientSize();
+
// Non-retained canvas
- MyCanvas *canvas = new MyCanvas(view, parent, wxPoint(0, 0), wxSize(width, height), 0);
+ MyCanvas* canvas = new MyCanvas(view, parent, wxPoint(0, 0), size, 0);
canvas->SetCursor(wxCursor(wxCURSOR_PENCIL));
-
+
// Give it scrollbars
canvas->SetScrollbars(20, 20, 50, 50);
canvas->SetBackgroundColour(*wxWHITE);
canvas->ClearBackground();
-
+
return canvas;
}
// Licence: wxWindows license
/////////////////////////////////////////////////////////////////////////////
-#ifndef __DOCVIEWSAMPLEH__
-#define __DOCVIEWSAMPLEH__
+#ifndef __DOCVIEW_H__
+#define __DOCVIEW_H__
#include "wx/docview.h"
class wxDocManager;
// Define a new application
-class MyApp: public wxApp
+class MyApp : public wxApp
{
public:
MyApp(void);
bool OnInit(void);
int OnExit(void);
-
+
wxFrame *CreateChildFrame(wxDocument *doc, wxView *view, bool isCanvas);
-
+
protected:
wxDocManager* m_docManager;
};
// Define a new frame
class MyCanvas;
-class MyFrame: public wxDocParentFrame
+class DrawingView;
+class MyFrame : public wxDocParentFrame
{
DECLARE_CLASS(MyFrame)
public:
- wxMenu *editMenu;
-
+ wxMenu* m_editMenu;
+
// This pointer only needed if in single window mode
- MyCanvas *canvas;
-
+ MyCanvas* m_canvas;
+
MyFrame(wxDocManager *manager, wxFrame *frame, wxWindowID id, const wxString& title, const wxPoint& pos, const wxSize& size,
const long type);
-
+
+ MyCanvas* CreateCanvas(DrawingView*, wxFrame *parent);
+
+protected:
void OnAbout(wxCommandEvent& event);
- MyCanvas *CreateCanvas(wxView *view, wxFrame *parent);
-
DECLARE_EVENT_TABLE()
};
-extern MyFrame *GetMainFrame(void);
+extern MyFrame *GetMainFrame();
#define DOCVIEW_CUT 1
#define DOCVIEW_ABOUT wxID_ABOUT
IMPLEMENT_DYNAMIC_CLASS(DrawingView, wxView)
// For drawing lines in a canvas
-float xpos = -1;
-float ypos = -1;
+static float xpos = -1;
+static float ypos = -1;
BEGIN_EVENT_TABLE(DrawingView, wxView)
EVT_MENU(DOODLE_CUT, DrawingView::OnCut)
if (!singleWindowMode)
{
// Multiple windows
- frame = wxGetApp().CreateChildFrame(doc, this, true);
- frame->SetTitle(_T("DrawingView"));
-
- canvas = GetMainFrame()->CreateCanvas(this, frame);
+ m_frame = wxGetApp().CreateChildFrame(doc, this, true);
+ m_frame->SetTitle(wxT("DrawingView"));
+
+ m_canvas = GetMainFrame()->CreateCanvas(this, m_frame);
#ifdef __X__
// X seems to require a forced resize
int x, y;
- frame->GetSize(&x, &y);
- frame->SetSize(wxDefaultCoord, wxDefaultCoord, x, y);
+ m_frame->GetSize(&x, &y);
+ m_frame->SetSize(wxDefaultCoord, wxDefaultCoord, x, y);
#endif
- frame->Show(true);
+ m_frame->Show(true);
}
else
{
// Single-window mode
- frame = GetMainFrame();
- canvas = GetMainFrame()->canvas;
- canvas->view = this;
-
+ m_frame = GetMainFrame();
+ m_canvas = GetMainFrame()->m_canvas;
+ m_canvas->m_view = this;
+
// Associate the appropriate frame with this view.
- SetFrame(frame);
-
+ SetFrame(m_frame);
+
// Make sure the document manager knows that this is the
// current view.
Activate(true);
-
+
// Initialize the edit menu Undo and Redo items
- doc->GetCommandProcessor()->SetEditMenu(((MyFrame *)frame)->editMenu);
+ doc->GetCommandProcessor()->SetEditMenu(((MyFrame*)m_frame)->m_editMenu);
doc->GetCommandProcessor()->Initialize();
}
-
+
return true;
}
{
dc->SetFont(*wxNORMAL_FONT);
dc->SetPen(*wxBLACK_PEN);
-
- wxList::compatibility_iterator node = ((DrawingDocument *)GetDocument())->GetDoodleSegments().GetFirst();
+
+ wxList::compatibility_iterator node = GetDocument()->GetDoodleSegments().GetFirst();
while (node)
{
DoodleSegment *seg = (DoodleSegment *)node->GetData();
}
}
+DrawingDocument* DrawingView::GetDocument()
+{
+ return wxStaticCast(wxView::GetDocument(), DrawingDocument);
+}
+
void DrawingView::OnUpdate(wxView *WXUNUSED(sender), wxObject *WXUNUSED(hint))
{
- if (canvas)
- canvas->Refresh();
-
+ if (m_canvas)
+ m_canvas->Refresh();
+
/* Is the following necessary?
#ifdef __WXMSW__
if (canvas)
{
if (!GetDocument()->Close())
return false;
-
+
// Clear the canvas in case we're in single-window mode,
// and the canvas stays.
- canvas->ClearBackground();
- canvas->view = (wxView *) NULL;
- canvas = (MyCanvas *) NULL;
-
+ m_canvas->ClearBackground();
+ m_canvas->m_view = NULL;
+ m_canvas = NULL;
+
wxString s(wxTheApp->GetAppDisplayName());
- if (frame)
- frame->SetTitle(s);
-
- SetFrame((wxFrame *) NULL);
-
+ if (m_frame)
+ m_frame->SetTitle(s);
+
+ SetFrame(NULL);
+
Activate(false);
-
+
if (deleteWindow && !singleWindowMode)
{
- delete frame;
+ delete m_frame;
return true;
}
return true;
void DrawingView::OnCut(wxCommandEvent& WXUNUSED(event) )
{
- DrawingDocument *doc = (DrawingDocument *)GetDocument();
- doc->GetCommandProcessor()->Submit(new DrawingCommand(_T("Cut Last Segment"), DOODLE_CUT, doc, (DoodleSegment *) NULL));
+ DrawingDocument* doc = GetDocument();
+ doc->GetCommandProcessor()->Submit(new DrawingCommand(wxT("Cut Last Segment"), DOODLE_CUT, doc, NULL));
}
IMPLEMENT_DYNAMIC_CLASS(TextEditView, wxView)
bool TextEditView::OnCreate(wxDocument *doc, long WXUNUSED(flags) )
{
- frame = wxGetApp().CreateChildFrame(doc, this, false);
-
- int width, height;
- frame->GetClientSize(&width, &height);
- textsw = new MyTextWindow(this, frame, wxPoint(0, 0), wxSize(width, height), wxTE_MULTILINE);
- frame->SetTitle(_T("TextEditView"));
-
+ m_frame = wxGetApp().CreateChildFrame(doc, this, false);
+
+ wxSize size = m_frame->GetClientSize();
+ m_textsw = new MyTextWindow(this, m_frame, wxPoint(0, 0), size, wxTE_MULTILINE);
+ m_frame->SetTitle(wxT("TextEditView"));
+
#ifdef __X__
// X seems to require a forced resize
int x, y;
frame->GetSize(&x, &y);
frame->SetSize(wxDefaultCoord, wxDefaultCoord, x, y);
#endif
-
- frame->Show(true);
+
+ m_frame->Show(true);
Activate(true);
-
+
return true;
}
{
if (!GetDocument()->Close())
return false;
-
+
Activate(false);
-
+
if (deleteWindow)
{
- delete frame;
+ wxDELETE(m_frame)
return true;
}
return true;
}
+bool TextEditView::ProcessEvent(wxEvent& event)
+{
+ bool processed = false;
+ if (!processed) switch (event.GetId())
+ {
+ case wxID_COPY:
+ case wxID_PASTE:
+ case wxID_SELECTALL:
+ processed = m_textsw->ProcessEvent(event);
+ break;
+ }
+ if (!processed) processed = wxView::ProcessEvent(event);
+ return processed;
+}
+
/*
* Window implementations
*/
END_EVENT_TABLE()
// Define a constructor for my canvas
-MyCanvas::MyCanvas(wxView *v, wxFrame *frame, const wxPoint& pos, const wxSize& size, const long style):
+MyCanvas::MyCanvas(DrawingView* view, wxFrame* frame, const wxPoint& pos, const wxSize& size, const long style):
wxScrolledWindow(frame, wxID_ANY, pos, size, style)
{
- view = v;
+ m_view = view;
}
// Define the repainting behaviour
void MyCanvas::OnDraw(wxDC& dc)
{
- if (view)
- view->OnDraw(& dc);
+ if (m_view)
+ m_view->OnDraw(& dc);
}
// This implements a tiny doodling program. Drag the mouse using
// the left button.
void MyCanvas::OnMouseEvent(wxMouseEvent& event)
{
- if (!view)
+ if (!m_view)
return;
-
- static DoodleSegment *currentSegment = (DoodleSegment *) NULL;
-
+
+ static DoodleSegment *currentSegment = NULL;
+
wxClientDC dc(this);
PrepareDC(dc);
-
+
dc.SetPen(*wxBLACK_PEN);
-
+
wxPoint pt(event.GetLogicalPosition(dc));
-
+
if (currentSegment && event.LeftUp())
{
- if (currentSegment->lines.GetCount() == 0)
+ if (currentSegment->m_lines.GetCount() == 0)
{
delete currentSegment;
- currentSegment = (DoodleSegment *) NULL;
+ currentSegment = NULL;
}
else
{
// We've got a valid segment on mouse left up, so store it.
- DrawingDocument *doc = (DrawingDocument *)view->GetDocument();
-
- doc->GetCommandProcessor()->Submit(new DrawingCommand(_T("Add Segment"), DOODLE_ADD, doc, currentSegment));
-
- view->GetDocument()->Modify(true);
- currentSegment = (DoodleSegment *) NULL;
+ DrawingDocument* doc = m_view->GetDocument();
+
+ doc->GetCommandProcessor()->Submit(new DrawingCommand(wxT("Add Segment"), DOODLE_ADD, doc, currentSegment));
+
+ m_view->GetDocument()->Modify(true);
+ currentSegment = NULL;
}
}
-
- if (xpos > -1 && ypos > -1 && event.Dragging())
+
+ if ( (xpos > -1) && (ypos > -1) && event.Dragging())
{
if (!currentSegment)
currentSegment = new DoodleSegment;
-
+
DoodleLine *newLine = new DoodleLine;
- newLine->x1 = (long)xpos;
+ newLine->x1 = (long)xpos;
newLine->y1 = (long)ypos;
- newLine->x2 = pt.x;
+ newLine->x2 = pt.x;
newLine->y2 = pt.y;
- currentSegment->lines.Append(newLine);
-
+ currentSegment->m_lines.Append(newLine);
+
dc.DrawLine( (long)xpos, (long)ypos, pt.x, pt.y);
}
xpos = pt.x;
}
// Define a constructor for my text subwindow
-MyTextWindow::MyTextWindow(wxView *v, wxFrame *frame, const wxPoint& pos, const wxSize& size, const long style):
- wxTextCtrl(frame, wxID_ANY, _T(""), pos, size, style)
+MyTextWindow::MyTextWindow(wxView* view, wxFrame* frame, const wxPoint& pos, const wxSize& size, const long style):
+ wxTextCtrl(frame, wxID_ANY, wxEmptyString, pos, size, style)
{
- view = v;
+ m_view = view;
}
// Licence: wxWindows license
/////////////////////////////////////////////////////////////////////////////
-#ifndef __VIEWSAMPLEH__
-#define __VIEWSAMPLEH__
+#ifndef __VIEW_H__
+#define __VIEW_H__
#include "wx/docview.h"
-class MyCanvas: public wxScrolledWindow
+class DrawingView;
+class MyCanvas : public wxScrolledWindow
{
public:
- wxView *view;
-
- MyCanvas(wxView *v, wxFrame *frame, const wxPoint& pos, const wxSize& size, const long style);
+ DrawingView* m_view;
+
+ MyCanvas(DrawingView*, wxFrame*, const wxPoint& pos, const wxSize& size, const long style);
virtual void OnDraw(wxDC& dc);
+
+protected:
void OnMouseEvent(wxMouseEvent& event);
-
DECLARE_EVENT_TABLE()
};
class MyTextWindow: public wxTextCtrl
{
public:
- wxView *view;
-
+ wxView* m_view;
+
MyTextWindow(wxView *v, wxFrame *frame, const wxPoint& pos, const wxSize& size, const long style);
};
-class DrawingView: public wxView
+class DrawingView : public wxView
{
- DECLARE_DYNAMIC_CLASS(DrawingView)
-private:
public:
- wxFrame *frame;
- MyCanvas *canvas;
-
- DrawingView(void) { canvas = (MyCanvas *) NULL; frame = (wxFrame *) NULL; };
- ~DrawingView(void) {};
-
- bool OnCreate(wxDocument *doc, long flags);
- void OnDraw(wxDC *dc);
- void OnUpdate(wxView *sender, wxObject *hint = (wxObject *) NULL);
- bool OnClose(bool deleteWindow = true);
-
+ wxFrame* 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);
-
+
+private:
DECLARE_EVENT_TABLE()
+ DECLARE_DYNAMIC_CLASS(DrawingView)
};
-class TextEditView: public wxView
+class TextEditView : public wxView
{
- DECLARE_DYNAMIC_CLASS(TextEditView)
-private:
public:
- wxFrame *frame;
- MyTextWindow *textsw;
-
- TextEditView(): wxView() { frame = (wxFrame *) NULL; textsw = (MyTextWindow *) NULL; }
- ~TextEditView(void) {}
-
- bool OnCreate(wxDocument *doc, long flags);
- void OnDraw(wxDC *dc);
- void OnUpdate(wxView *sender, wxObject *hint = (wxObject *) NULL);
- bool OnClose(bool deleteWindow = true);
+ wxFrame* m_frame;
+ MyTextWindow* m_textsw;
+
+ TextEditView(): wxView() { m_frame = NULL; m_textsw = NULL; }
+ virtual ~TextEditView() {}
+
+ virtual bool OnCreate(wxDocument *doc, long flags);
+ virtual void OnDraw(wxDC *dc);
+ virtual void OnUpdate(wxView *sender, wxObject *hint = NULL);
+ virtual bool OnClose(bool deleteWindow = true);
+ virtual bool ProcessEvent(wxEvent&);
+
+private:
+ DECLARE_DYNAMIC_CLASS(TextEditView)
};
#endif
DrawingDocument::~DrawingDocument(void)
{
- WX_CLEAR_LIST(wxList, doodleSegments);
+ WX_CLEAR_LIST(wxList, m_doodleSegments)
}
#if wxUSE_STD_IOSTREAM
wxSTD ostream& DrawingDocument::SaveObject(wxSTD ostream& stream)
{
- wxDocument::SaveObject(stream);
+ wxDocument::SaveObject(stream);
- wxInt32 n = doodleSegments.GetCount();
- stream << n << _T('\n');
+ wxInt32 n = m_doodleSegments.GetCount();
+ stream << n << wxT('\n');
- wxList::compatibility_iterator node = doodleSegments.GetFirst();
- while (node)
- {
- DoodleSegment *segment = (DoodleSegment *)node->GetData();
- segment->SaveObject(stream);
- stream << _T('\n');
-
- node = node->GetNext();
- }
+ wxList::compatibility_iterator node = m_doodleSegments.GetFirst();
+ while (node)
+ {
+ DoodleSegment *segment = (DoodleSegment*)node->GetData();
+ segment->SaveObject(stream);
+ stream << wxT('\n');
- return stream;
+ node = node->GetNext();
+ }
+ return stream;
}
#else
wxOutputStream& DrawingDocument::SaveObject(wxOutputStream& stream)
{
- wxDocument::SaveObject(stream);
+ wxDocument::SaveObject(stream);
- wxTextOutputStream text_stream( stream );
+ wxTextOutputStream text_stream( stream );
- wxInt32 n = doodleSegments.GetCount();
- text_stream << n << _T('\n');
+ wxInt32 n = m_doodleSegments.GetCount();
+ text_stream << n << wxT('\n');
- wxList::compatibility_iterator node = doodleSegments.GetFirst();
- while (node)
- {
- DoodleSegment *segment = (DoodleSegment *)node->GetData();
- segment->SaveObject(stream);
- text_stream << _T('\n');
+ wxList::compatibility_iterator node = m_doodleSegments.GetFirst();
+ while (node)
+ {
+ DoodleSegment* segment = (DoodleSegment*)node->GetData();
+ segment->SaveObject(stream);
+ text_stream << wxT('\n');
- node = node->GetNext();
- }
+ node = node->GetNext();
+ }
- return stream;
+ return stream;
}
#endif
#if wxUSE_STD_IOSTREAM
wxSTD istream& DrawingDocument::LoadObject(wxSTD istream& stream)
{
- wxDocument::LoadObject(stream);
+ wxDocument::LoadObject(stream);
- wxInt32 n = 0;
- stream >> n;
+ wxInt32 n = 0;
+ stream >> n;
- for (int i = 0; i < n; i++)
- {
- DoodleSegment *segment = new DoodleSegment;
- segment->LoadObject(stream);
- doodleSegments.Append(segment);
- }
+ for (int i = 0; i < n; i++)
+ {
+ DoodleSegment *segment = new DoodleSegment;
+ segment->LoadObject(stream);
+ m_doodleSegments.Append(segment);
+ }
- return stream;
+ return stream;
}
#else
wxInputStream& DrawingDocument::LoadObject(wxInputStream& stream)
{
- wxDocument::LoadObject(stream);
+ wxDocument::LoadObject(stream);
- wxTextInputStream text_stream( stream );
+ wxTextInputStream text_stream( stream );
- wxInt32 n = 0;
- text_stream >> n;
+ wxInt32 n = 0;
+ text_stream >> n;
- for (int i = 0; i < n; i++)
- {
- DoodleSegment *segment = new DoodleSegment;
- segment->LoadObject(stream);
- doodleSegments.Append(segment);
- }
+ for (int i = 0; i < n; i++)
+ {
+ DoodleSegment* segment = new DoodleSegment;
+ segment->LoadObject(stream);
+ m_doodleSegments.Append(segment);
+ }
- return stream;
+ return stream;
}
#endif
-DoodleSegment::DoodleSegment(const DoodleSegment& seg)
- :wxObject()
+DoodleSegment::DoodleSegment(const DoodleSegment& seg) : wxObject()
{
- wxList::compatibility_iterator node = seg.lines.GetFirst();
- while (node)
- {
- DoodleLine *line = (DoodleLine *)node->GetData();
- DoodleLine *newLine = new DoodleLine;
- newLine->x1 = line->x1;
- newLine->y1 = line->y1;
- newLine->x2 = line->x2;
- newLine->y2 = line->y2;
-
- lines.Append(newLine);
-
- node = node->GetNext();
- }
+ wxList::compatibility_iterator node = seg.m_lines.GetFirst();
+ while (node)
+ {
+ DoodleLine* line = (DoodleLine*)node->GetData();
+ DoodleLine* newLine = new DoodleLine;
+ newLine->x1 = line->x1;
+ newLine->y1 = line->y1;
+ newLine->x2 = line->x2;
+ newLine->y2 = line->y2;
+
+ m_lines.Append(newLine);
+
+ node = node->GetNext();
+ }
}
DoodleSegment::~DoodleSegment(void)
{
- WX_CLEAR_LIST(wxList, lines);
+ WX_CLEAR_LIST(wxList, m_lines)
}
#if wxUSE_STD_IOSTREAM
wxSTD ostream& DoodleSegment::SaveObject(wxSTD ostream& stream)
{
- wxInt32 n = lines.GetCount();
- stream << n << _T('\n');
-
- wxList::compatibility_iterator node = lines.GetFirst();
- while (node)
- {
- DoodleLine *line = (DoodleLine *)node->GetData();
- stream << line->x1 << _T(" ") <<
- line->y1 << _T(" ") <<
- line->x2 << _T(" ") <<
- line->y2 << _T("\n");
- node = node->GetNext();
- }
-
- return stream;
+ wxInt32 n = m_lines.GetCount();
+ stream << n << wxT('\n');
+
+ wxList::compatibility_iterator node = m_lines.GetFirst();
+ while (node)
+ {
+ DoodleLine *line = (DoodleLine *)node->GetData();
+ stream << line->x1 << wxT(" ") <<
+ line->y1 << wxT(" ") <<
+ line->x2 << wxT(" ") <<
+ line->y2 << wxT("\n");
+ node = node->GetNext();
+ }
+
+ return stream;
}
#else
wxOutputStream &DoodleSegment::SaveObject(wxOutputStream& stream)
{
- wxTextOutputStream text_stream( stream );
-
- wxInt32 n = lines.GetCount();
- text_stream << n << _T('\n');
-
- wxList::compatibility_iterator node = lines.GetFirst();
- while (node)
- {
- DoodleLine *line = (DoodleLine *)node->GetData();
- text_stream << line->x1 << _T(" ") <<
- line->y1 << _T(" ") <<
- line->x2 << _T(" ") <<
- line->y2 << _T("\n");
- node = node->GetNext();
- }
-
- return stream;
+ wxTextOutputStream text_stream( stream );
+
+ wxInt32 n = m_lines.GetCount();
+ text_stream << n << wxT('\n');
+
+ wxList::compatibility_iterator node = m_lines.GetFirst();
+ while (node)
+ {
+ DoodleLine* line = (DoodleLine*)node->GetData();
+ text_stream << line->x1 << wxT(" ") <<
+ line->y1 << wxT(" ") <<
+ line->x2 << wxT(" ") <<
+ line->y2 << wxT("\n");
+ node = node->GetNext();
+ }
+
+ return stream;
}
#endif
#if wxUSE_STD_IOSTREAM
wxSTD istream& DoodleSegment::LoadObject(wxSTD istream& stream)
{
- wxInt32 n = 0;
- stream >> n;
-
- for (int i = 0; i < n; i++)
- {
- DoodleLine *line = new DoodleLine;
- stream >> line->x1 >>
- line->y1 >>
- line->x2 >>
- line->y2;
- lines.Append(line);
- }
-
- return stream;
+ wxInt32 n = 0;
+ stream >> n;
+
+ for (int i = 0; i < n; i++)
+ {
+ DoodleLine *line = new DoodleLine;
+ stream >> line->x1 >>
+ line->y1 >>
+ line->x2 >>
+ line->y2;
+ m_lines.Append(line);
+ }
+
+ return stream;
}
#else
wxInputStream &DoodleSegment::LoadObject(wxInputStream& stream)
{
- wxTextInputStream text_stream( stream );
-
- wxInt32 n = 0;
- text_stream >> n;
-
- for (int i = 0; i < n; i++)
- {
- DoodleLine *line = new DoodleLine;
- text_stream >> line->x1 >>
- line->y1 >>
- line->x2 >>
- line->y2;
- lines.Append(line);
- }
-
- return stream;
+ wxTextInputStream text_stream( stream );
+
+ wxInt32 n = 0;
+ text_stream >> n;
+
+ for (int i = 0; i < n; i++)
+ {
+ DoodleLine* line = new DoodleLine;
+ text_stream >> line->x1 >>
+ line->y1 >>
+ line->x2 >>
+ line->y2;
+ m_lines.Append(line);
+ }
+
+ return stream;
}
#endif
void DoodleSegment::Draw(wxDC *dc)
{
- wxList::compatibility_iterator node = lines.GetFirst();
- while (node)
- {
- DoodleLine *line = (DoodleLine *)node->GetData();
- dc->DrawLine(line->x1, line->y1, line->x2, line->y2);
- node = node->GetNext();
- }
+ wxList::compatibility_iterator node = m_lines.GetFirst();
+ while (node)
+ {
+ DoodleLine* line = (DoodleLine*)node->GetData();
+ dc->DrawLine(line->x1, line->y1, line->x2, line->y2);
+ node = node->GetNext();
+ }
}
/*
* Implementation of drawing command
*/
-DrawingCommand::DrawingCommand(const wxString& name, int command, DrawingDocument *ddoc, DoodleSegment *seg):
- wxCommand(true, name)
+DrawingCommand::DrawingCommand(const wxString& name, int command, DrawingDocument* doc, DoodleSegment* seg) :
+ wxCommand(true, name)
{
- doc = ddoc;
- segment = seg;
- cmd = command;
+ m_doc = doc;
+ m_segment = seg;
+ m_cmd = command;
}
DrawingCommand::~DrawingCommand(void)
{
- if (segment)
- delete segment;
+ if (m_segment)
+ delete m_segment;
}
bool DrawingCommand::Do(void)
{
- switch (cmd)
- {
- case DOODLE_CUT:
- {
- // Cut the last segment
- if (doc->GetDoodleSegments().GetCount() > 0)
- {
- wxList::compatibility_iterator node = doc->GetDoodleSegments().GetLast();
- if (segment)
- delete segment;
-
- segment = (DoodleSegment *)node->GetData();
- doc->GetDoodleSegments().Erase(node);
-
- doc->Modify(true);
- doc->UpdateAllViews();
- }
- break;
- }
- case DOODLE_ADD:
+ switch (m_cmd)
{
- doc->GetDoodleSegments().Append(new DoodleSegment(*segment));
- doc->Modify(true);
- doc->UpdateAllViews();
- break;
+ case DOODLE_CUT:
+ // Cut the last segment
+ if (m_doc->GetDoodleSegments().GetCount() > 0)
+ {
+ wxList::compatibility_iterator node = m_doc->GetDoodleSegments().GetLast();
+ if (m_segment)
+ delete m_segment;
+
+ m_segment = (DoodleSegment*)node->GetData();
+ m_doc->GetDoodleSegments().Erase(node);
+
+ m_doc->Modify(true);
+ m_doc->UpdateAllViews();
+ }
+ break;
+ case DOODLE_ADD:
+ m_doc->GetDoodleSegments().Append(new DoodleSegment(*m_segment));
+ m_doc->Modify(true);
+ m_doc->UpdateAllViews();
+ break;
}
- }
- return true;
+ return true;
}
bool DrawingCommand::Undo(void)
{
- switch (cmd)
- {
- case DOODLE_CUT:
- {
- // Paste the segment
- if (segment)
- {
- doc->GetDoodleSegments().Append(segment);
- doc->Modify(true);
- doc->UpdateAllViews();
- segment = (DoodleSegment *) NULL;
- }
- doc->Modify(true);
- doc->UpdateAllViews();
- break;
- }
- case DOODLE_ADD:
+ switch (m_cmd)
{
- // Cut the last segment
- if (doc->GetDoodleSegments().GetCount() > 0)
- {
- wxList::compatibility_iterator node = doc->GetDoodleSegments().GetLast();
- DoodleSegment *seg = (DoodleSegment *)node->GetData();
- delete seg;
- doc->GetDoodleSegments().Erase(node);
-
- doc->Modify(true);
- doc->UpdateAllViews();
- }
+ case DOODLE_CUT:
+ {
+ // Paste the segment
+ if (m_segment)
+ {
+ m_doc->GetDoodleSegments().Append(m_segment);
+ m_doc->Modify(true);
+ m_doc->UpdateAllViews();
+ m_segment = NULL;
+ }
+ m_doc->Modify(true);
+ m_doc->UpdateAllViews();
+ break;
+ }
+ case DOODLE_ADD:
+ {
+ // Cut the last segment
+ if (m_doc->GetDoodleSegments().GetCount() > 0)
+ {
+ wxList::compatibility_iterator node = m_doc->GetDoodleSegments().GetLast();
+ DoodleSegment* seg = (DoodleSegment*)node->GetData();
+ delete seg;
+ m_doc->GetDoodleSegments().Erase(node);
+
+ m_doc->Modify(true);
+ m_doc->UpdateAllViews();
+ }
+ }
}
- }
- return true;
+ return true;
}
IMPLEMENT_DYNAMIC_CLASS(TextEditDocument, wxDocument)
// we override OnSave/OpenDocument instead of Save/LoadObject
bool TextEditDocument::OnSaveDocument(const wxString& filename)
{
- TextEditView *view = (TextEditView *)GetFirstView();
+ TextEditView* view = GetFirstView();
- if (!view->textsw->SaveFile(filename))
+ if (!view->m_textsw->SaveFile(filename))
return false;
Modify(false);
return true;
bool TextEditDocument::OnOpenDocument(const wxString& filename)
{
- TextEditView *view = (TextEditView *)GetFirstView();
- if (!view->textsw->LoadFile(filename))
+ TextEditView *view = GetFirstView();
+ if (!view->m_textsw->LoadFile(filename))
return false;
SetFilename(filename, true);
bool TextEditDocument::IsModified(void) const
{
- TextEditView *view = (TextEditView *)GetFirstView();
- if (view)
- {
- return (wxDocument::IsModified() || view->textsw->IsModified());
- }
- else
- return wxDocument::IsModified();
+ TextEditView* view = GetFirstView();
+ return (wxDocument::IsModified() || (view && view->m_textsw->IsModified()));
}
void TextEditDocument::Modify(bool mod)
{
- TextEditView *view = (TextEditView *)GetFirstView();
+ TextEditView* view = GetFirstView();
- wxDocument::Modify(mod);
+ wxDocument::Modify(mod);
- if (!mod && view && view->textsw)
- view->textsw->DiscardEdits();
+ if ((!mod) && view && view->m_textsw)
+ {
+ view->m_textsw->DiscardEdits();
+ }
}
+
+TextEditView* TextEditDocument::GetFirstView() const
+{
+ wxView* view = wxDocument::GetFirstView();
+ return view ? wxStaticCast(view, TextEditView) : NULL;
+}
+
// Licence: wxWindows license
/////////////////////////////////////////////////////////////////////////////
-#ifndef __DOCSAMPLEH__
-#define __DOCSAMPLEH__
+#ifndef __DOC_H__
+#define __DOC_H__
#include "wx/docview.h"
#include "wx/cmdproc.h"
// Plots a line from one point to the other
class DoodleLine: public wxObject
{
- public:
- wxInt32 x1;
- wxInt32 y1;
- wxInt32 x2;
- wxInt32 y2;
+public:
+ wxInt32 x1;
+ wxInt32 y1;
+ wxInt32 x2;
+ wxInt32 y2;
};
// Contains a list of lines: represents a mouse-down doodle
class DoodleSegment: public wxObject
{
- public:
- wxList lines;
+public:
+ wxList m_lines;
- DoodleSegment(void){};
- DoodleSegment(const DoodleSegment& seg);
- ~DoodleSegment(void);
+ DoodleSegment() : wxObject() {}
+ DoodleSegment(const DoodleSegment&);
+ virtual ~DoodleSegment();
- void Draw(wxDC *dc);
+ void Draw(wxDC* dc);
#if wxUSE_STD_IOSTREAM
- wxSTD ostream& SaveObject(wxSTD ostream& text_stream);
- wxSTD istream& LoadObject(wxSTD istream& text_stream);
+ wxSTD ostream& SaveObject(wxSTD ostream&);
+ wxSTD istream& LoadObject(wxSTD istream&);
#else
- wxOutputStream& SaveObject(wxOutputStream& stream);
- wxInputStream& LoadObject(wxInputStream& stream);
+ wxOutputStream& SaveObject(wxOutputStream&);
+ wxInputStream& LoadObject(wxInputStream&);
#endif
};
class DrawingDocument: public wxDocument
{
- DECLARE_DYNAMIC_CLASS(DrawingDocument)
- private:
- public:
- wxList doodleSegments;
+ DECLARE_DYNAMIC_CLASS(DrawingDocument)
+public:
+ wxList m_doodleSegments;
- DrawingDocument(void){};
- ~DrawingDocument(void);
+ DrawingDocument() : wxDocument() {}
+ virtual ~DrawingDocument();
#if wxUSE_STD_IOSTREAM
- wxSTD ostream& SaveObject(wxSTD ostream& text_stream);
- wxSTD istream& LoadObject(wxSTD istream& text_stream);
+ wxSTD ostream& SaveObject(wxSTD ostream&);
+ wxSTD istream& LoadObject(wxSTD istream&);
#else
- wxOutputStream& SaveObject(wxOutputStream& stream);
- wxInputStream& LoadObject(wxInputStream& stream);
+ wxOutputStream& SaveObject(wxOutputStream&);
+ wxInputStream& LoadObject(wxInputStream&);
#endif
- inline wxList& GetDoodleSegments(void) const { return (wxList&) doodleSegments; };
+ inline wxList& GetDoodleSegments() const { return (wxList&) m_doodleSegments; };
};
#define DOODLE_CUT 1
#define DOODLE_ADD 2
-class DrawingCommand: public wxCommand
+class DrawingCommand : public wxCommand
{
- protected:
- DoodleSegment *segment;
- DrawingDocument *doc;
- int cmd;
- public:
- DrawingCommand(const wxString& name, int cmd, DrawingDocument *ddoc, DoodleSegment *seg);
- ~DrawingCommand(void);
-
- bool Do(void);
- bool Undo(void);
+protected:
+ DoodleSegment* m_segment;
+ DrawingDocument* m_doc;
+ int m_cmd;
+public:
+ DrawingCommand(const wxString& name, int cmd, DrawingDocument*, DoodleSegment*);
+ virtual ~DrawingCommand();
+
+ bool Do();
+ bool Undo();
};
-class TextEditDocument: public wxDocument
+class TextEditView;
+class TextEditDocument : public wxDocument
{
DECLARE_DYNAMIC_CLASS(TextEditDocument)
- private:
- public:
+public:
/*
- wxSTD ostream& SaveObject(wxSTD ostream& stream);
- wxSTD istream& LoadObject(wxSTD istream& stream);
+ wxSTD ostream& SaveObject(wxSTD ostream&);
+ wxSTD istream& LoadObject(wxSTD istream&);
*/
- virtual bool OnSaveDocument(const wxString& filename);
- virtual bool OnOpenDocument(const wxString& filename);
- virtual bool IsModified(void) const;
- virtual void Modify(bool mod);
+ TextEditView* GetFirstView() const;
- TextEditDocument(void) {}
- ~TextEditDocument(void) {}
+ virtual bool OnSaveDocument(const wxString& filename);
+ virtual bool OnOpenDocument(const wxString& filename);
+ virtual bool IsModified() const;
+ virtual void Modify(bool mod);
+
+ TextEditDocument() {}
+ virtual ~TextEditDocument() {}
};
#include "docview.h"
#include "doc.h"
#include "view.h"
+#include "wx/stockitem.h"
-MyFrame *frame = (MyFrame *) NULL;
+static MyFrame* frame = NULL;
IMPLEMENT_APP(MyApp)
MyApp::MyApp(void)
{
- m_docManager = (wxDocManager *) NULL;
+ m_docManager = NULL;
}
bool MyApp::OnInit(void)
{
- //// Create a document manager
- m_docManager = new wxDocManager;
+ if ( !wxApp::OnInit() )
+ return false;
+ //// Create a document manager
+ SetAppName(wxT("DocView Demo"));
- //// Create a template relating drawing documents to their views
- (void) new wxDocTemplate((wxDocManager *) m_docManager, _T("Drawing"), _T("*.drw"), _T(""), _T("drw"), _T("Drawing Doc"), _T("Drawing View"),
+ //// Create a document manager
+ 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));
- //// 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"),
+ //// Create a template relating text documents to their views
+ new wxDocTemplate(m_docManager, wxT("Text"), wxT("*.txt"), wxT(""), wxT("txt"), wxT("Text Doc"), wxT("Text View"),
CLASSINFO(TextEditDocument), CLASSINFO(TextEditView));
- //// Create the main frame window
- frame = new MyFrame((wxDocManager *) m_docManager, (wxFrame *) NULL,
- _T("DocView Demo"), wxPoint(0, 0), wxSize(500, 400),
+ //// Create the main frame window
+ frame = new MyFrame(m_docManager, NULL,
+ GetAppDisplayName(), wxPoint(0, 0), wxSize(500, 400),
wxDEFAULT_FRAME_STYLE | wxNO_FULL_REPAINT_ON_RESIZE);
- //// Give it an icon (this is ignored in MDI mode: uses resources)
+ //// Give it an icon (this is ignored in MDI mode: uses resources)
#ifdef __WXMSW__
- frame->SetIcon(wxIcon(_T("doc")));
+ frame->SetIcon(wxIcon(wxT("doc")));
#endif
- //// Make a menubar
- wxMenu *file_menu = new wxMenu;
- wxMenu *edit_menu = (wxMenu *) NULL;
+ //// Make a menubar
+ wxMenu *file_menu = new wxMenu;
+ wxMenu *edit_menu = NULL;
+
+ file_menu->Append(wxID_NEW);
+ file_menu->Append(wxID_OPEN);
- file_menu->Append(wxID_NEW, _T("&New...\tCtrl-N"));
- file_menu->Append(wxID_OPEN, _T("&Open...\tCtrl-X"));
+ file_menu->AppendSeparator();
+ file_menu->Append(wxID_EXIT);
- file_menu->AppendSeparator();
- file_menu->Append(wxID_EXIT, _T("E&xit\tAlt-X"));
-
- // A nice touch: a history of files visited. Use this menu.
- m_docManager->FileHistoryUseMenu(file_menu);
+ // A nice touch: a history of files visited. Use this menu.
+ m_docManager->FileHistoryUseMenu(file_menu);
- wxMenu *help_menu = new wxMenu;
- help_menu->Append(DOCVIEW_ABOUT, _T("&About\tF1"));
+ wxMenu *help_menu = new wxMenu;
+ help_menu->Append(DOCVIEW_ABOUT);
- wxMenuBar *menu_bar = new wxMenuBar;
+ wxMenuBar *menu_bar = new wxMenuBar;
- menu_bar->Append(file_menu, _T("&File"));
- if (edit_menu)
- menu_bar->Append(edit_menu, _T("&Edit"));
- menu_bar->Append(help_menu, _T("&Help"));
+ menu_bar->Append(file_menu, wxGetStockLabel(wxID_FILE));
+ if (edit_menu)
+ menu_bar->Append(edit_menu, wxGetStockLabel(wxID_EDIT));
+ menu_bar->Append(help_menu, wxGetStockLabel(wxID_HELP));
#ifdef __WXMAC__
- wxMenuBar::MacSetCommonMenuBar(menu_bar);
+ wxMenuBar::MacSetCommonMenuBar(menu_bar);
#endif //def __WXMAC__
- //// Associate the menu bar with the frame
- frame->SetMenuBar(menu_bar);
+ //// Associate the menu bar with the frame
+ frame->SetMenuBar(menu_bar);
- frame->Centre(wxBOTH);
+ frame->Centre(wxBOTH);
#ifndef __WXMAC__
- frame->Show(true);
+ frame->Show(true);
#endif //ndef __WXMAC__
- SetTopWindow(frame);
- return true;
+ SetTopWindow(frame);
+ return true;
}
int MyApp::OnExit(void)
{
- delete m_docManager;
+ wxDELETE(m_docManager)
return 0;
}
* Centralised code for creating a document frame.
* Called from view.cpp, when a view is created.
*/
-
+
wxMDIChildFrame *MyApp::CreateChildFrame(wxDocument *doc, wxView *view, bool isCanvas)
{
//// Make a child frame
- wxDocMDIChildFrame *subframe =
- new wxDocMDIChildFrame(doc, view, GetMainFrame(), wxID_ANY, _T("Child Frame"),
+ wxDocMDIChildFrame *subframe =
+ new wxDocMDIChildFrame(doc, view, GetMainFrame(), wxID_ANY, wxT("Child Frame"),
wxPoint(10, 10), wxSize(300, 300),
wxDEFAULT_FRAME_STYLE |
wxNO_FULL_REPAINT_ON_RESIZE);
#ifdef __WXMSW__
- subframe->SetIcon(wxString(isCanvas ? _T("chart") : _T("notepad")));
+ subframe->SetIcon(wxString(isCanvas ? wxT("chart") : wxT("notepad")));
#endif
#ifdef __X__
- subframe->SetIcon(wxIcon(_T("doc.xbm")));
+ subframe->SetIcon(wxIcon(wxT("doc.xbm")));
#endif
- //// Make a menubar
- wxMenu *file_menu = new wxMenu;
-
- file_menu->Append(wxID_NEW, _T("&New..."));
- file_menu->Append(wxID_OPEN, _T("&Open..."));
- file_menu->Append(wxID_CLOSE, _T("&Close"));
- file_menu->Append(wxID_SAVE, _T("&Save"));
- file_menu->Append(wxID_SAVEAS, _T("Save &As..."));
-
- if (isCanvas)
- {
- file_menu->AppendSeparator();
- file_menu->Append(wxID_PRINT, _T("&Print..."));
- file_menu->Append(wxID_PRINT_SETUP, _T("Print &Setup..."));
- file_menu->Append(wxID_PREVIEW, _T("Print Pre&view"));
- }
-
- file_menu->AppendSeparator();
- file_menu->Append(wxID_EXIT, _T("E&xit"));
+ //// Make a menubar
+ wxMenu *file_menu = new wxMenu;
- wxMenu *edit_menu = (wxMenu *) NULL;
+ file_menu->Append(wxID_NEW);
+ file_menu->Append(wxID_OPEN);
+ file_menu->Append(wxID_CLOSE);
+ file_menu->Append(wxID_SAVE);
+ file_menu->Append(wxID_SAVEAS);
- if (isCanvas)
- {
- 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"));
+ if (isCanvas)
+ {
+ file_menu->AppendSeparator();
+ file_menu->Append(wxID_PRINT);
+ file_menu->Append(wxID_PRINT_SETUP, wxT("Print &Setup..."));
+ file_menu->Append(wxID_PREVIEW);
+ }
- doc->GetCommandProcessor()->SetEditMenu(edit_menu);
- }
-
- wxMenu *help_menu = new wxMenu;
- help_menu->Append(DOCVIEW_ABOUT, _T("&About"));
-
- wxMenuBar *menu_bar = new wxMenuBar;
-
- menu_bar->Append(file_menu, _T("&File"));
- if (isCanvas)
- menu_bar->Append(edit_menu, _T("&Edit"));
- menu_bar->Append(help_menu, _T("&Help"));
-
- //// Associate the menu bar with the frame
- subframe->SetMenuBar(menu_bar);
-
- return subframe;
+ file_menu->AppendSeparator();
+ file_menu->Append(wxID_EXIT);
+
+ wxMenu *edit_menu = new wxMenu;
+ if (isCanvas)
+ {
+ edit_menu->Append(wxID_UNDO);
+ edit_menu->Append(wxID_REDO);
+ edit_menu->AppendSeparator();
+ edit_menu->Append(DOCVIEW_CUT, wxT("&Cut last segment"));
+
+ doc->GetCommandProcessor()->SetEditMenu(edit_menu);
+ }
+ else
+ {
+ edit_menu->Append(wxID_COPY);
+ edit_menu->Append(wxID_PASTE);
+ edit_menu->Append(wxID_SELECTALL);
+ }
+ wxMenu *help_menu = new wxMenu;
+ help_menu->Append(DOCVIEW_ABOUT);
+
+ wxMenuBar *menu_bar = new wxMenuBar;
+
+ menu_bar->Append(file_menu, wxGetStockLabel(wxID_FILE));
+ menu_bar->Append(edit_menu, wxGetStockLabel(wxID_EDIT));
+ menu_bar->Append(help_menu, wxGetStockLabel(wxID_HELP));
+
+ //// Associate the menu bar with the frame
+ subframe->SetMenuBar(menu_bar);
+
+ return subframe;
}
/*
* This is the top-level window of the application.
*/
-
+
IMPLEMENT_CLASS(MyFrame, wxDocMDIParentFrame)
BEGIN_EVENT_TABLE(MyFrame, wxDocMDIParentFrame)
EVT_MENU(DOCVIEW_ABOUT, MyFrame::OnAbout)
MyFrame::MyFrame(wxDocManager *manager, wxFrame *frame, const wxString& title,
const wxPoint& pos, const wxSize& size, long type):
- wxDocMDIParentFrame(manager, frame, wxID_ANY, title, pos, size, type, _T("myFrame"))
+ wxDocMDIParentFrame(manager, frame, wxID_ANY, title, pos, size, type, wxT("myFrame"))
{
- editMenu = (wxMenu *) NULL;
+ m_editMenu = NULL;
}
void MyFrame::OnAbout(wxCommandEvent& WXUNUSED(event) )
{
- (void)wxMessageBox(_T("DocView Demo\nAuthor: Julian Smart\nUsage: docview.exe"), _T("About DocView"));
+ wxMessageBox(wxT("DocView Demo\nAuthor: Julian Smart\nUsage: docview.exe"), wxT("About DocView"));
+/*
+ Better, but brings in adv lib
+ wxAboutDialogInfo info;
+ info.SetName(wxTheApp->GetAppDisplayName());
+ info.AddDeveloper(wxT("Julian Smart"));
+ wxAboutBox(info);
+*/
}
// Creates a canvas. Called from view.cpp when a new drawing
// view is created.
-MyCanvas *MyFrame::CreateCanvas(wxView *view, wxMDIChildFrame *parent)
+MyCanvas* MyFrame::CreateCanvas(DrawingView* view, wxMDIChildFrame* parent)
{
- int width, height;
- parent->GetClientSize(&width, &height);
+ wxSize size = parent->GetClientSize();
- // Non-retained canvas
- MyCanvas *canvas = new MyCanvas(view, parent, wxPoint(0, 0), wxSize(width, height), 0);
- canvas->SetCursor(wxCursor(wxCURSOR_PENCIL));
+ // Non-retained canvas
+ MyCanvas *canvas = new MyCanvas(view, parent, wxPoint(0, 0), size, 0);
+ canvas->SetCursor(wxCursor(wxCURSOR_PENCIL));
- // Give it scrollbars
- canvas->SetScrollbars(20, 20, 50, 50);
+ // Give it scrollbars
+ canvas->SetScrollbars(20, 20, 50, 50);
- return canvas;
+ return canvas;
}
-MyFrame *GetMainFrame(void)
+MyFrame* GetMainFrame()
{
- return frame;
+ return frame;
}
// Licence: wxWindows license
/////////////////////////////////////////////////////////////////////////////
-#ifndef __DOCVIEWSAMPLEH__
-#define __DOCVIEWSAMPLEH__
+#ifndef __DOCVIEW_H__
+#define __DOCVIEW_H__
#include "wx/mdi.h"
#include "wx/docview.h"
// Define a new application
class MyApp: public wxApp
{
- public:
+public:
MyApp(void);
- bool OnInit(void);
- int OnExit(void);
+ virtual bool OnInit();
+ virtual int OnExit();
- wxMDIChildFrame *CreateChildFrame(wxDocument *doc, wxView *view, bool isCanvas);
+ wxMDIChildFrame* CreateChildFrame(wxDocument*, wxView*, bool isCanvas);
- protected:
+protected:
wxDocManager* m_docManager;
};
// Define a new frame
class MyCanvas;
+class DrawingView;
class MyFrame: public wxDocMDIParentFrame
{
- DECLARE_CLASS(MyFrame)
- public:
- wxMenu *editMenu;
-
- MyFrame(wxDocManager *manager, wxFrame *frame, const wxString& title, const wxPoint& pos, const wxSize& size,
- long type);
+public:
+ wxMenu* m_editMenu;
- void OnAbout(wxCommandEvent& event);
- MyCanvas *CreateCanvas(wxView *view, wxMDIChildFrame *parent);
+ MyFrame(wxDocManager*, wxFrame*, const wxString& title, const wxPoint&, const wxSize&, long type);
-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_ABOUT wxID_ABOUT
IMPLEMENT_DYNAMIC_CLASS(DrawingView, wxView)
// For drawing lines in a canvas
-float xpos = -1;
-float ypos = -1;
+static float xpos = -1;
+static float ypos = -1;
BEGIN_EVENT_TABLE(DrawingView, wxView)
EVT_MENU(DOODLE_CUT, DrawingView::OnCut)
// windows for displaying the view.
bool DrawingView::OnCreate(wxDocument *doc, long WXUNUSED(flags) )
{
- frame = wxGetApp().CreateChildFrame(doc, this, true);
- frame->SetTitle(_T("DrawingView"));
+ m_frame = wxGetApp().CreateChildFrame(doc, this, true);
+ m_frame->SetTitle(wxT("DrawingView"));
- canvas = GetMainFrame()->CreateCanvas(this, frame);
+ m_canvas = GetMainFrame()->CreateCanvas(this, m_frame);
#ifdef __X__
// X seems to require a forced resize
int x, y;
- frame->GetSize(&x, &y);
- frame->SetSize(wxDefaultCoord, wxDefaultCoord, x, y);
+ m_frame->GetSize(&x, &y);
+ m_frame->SetSize(wxDefaultCoord, wxDefaultCoord, x, y);
#endif
- frame->Show(true);
+ m_frame->Show(true);
Activate(true);
return true;
}
+DrawingDocument* DrawingView::GetDocument()
+{
+ return wxStaticCast(wxView::GetDocument(), DrawingDocument);
+}
+
// Sneakily gets used for default print/preview
// as well as drawing on the screen.
void DrawingView::OnDraw(wxDC *dc)
{
- dc->SetFont(*wxNORMAL_FONT);
- dc->SetPen(*wxBLACK_PEN);
-
- wxList::compatibility_iterator node = ((DrawingDocument *)GetDocument())->GetDoodleSegments().GetFirst();
- while (node)
- {
- DoodleSegment *seg = (DoodleSegment *)node->GetData();
- seg->Draw(dc);
- node = node->GetNext();
- }
+ dc->SetFont(*wxNORMAL_FONT);
+ dc->SetPen(*wxBLACK_PEN);
+
+ wxList::compatibility_iterator node = GetDocument()->GetDoodleSegments().GetFirst();
+ while (node)
+ {
+ DoodleSegment* seg = (DoodleSegment*)node->GetData();
+ seg->Draw(dc);
+ node = node->GetNext();
+ }
}
void DrawingView::OnUpdate(wxView *WXUNUSED(sender), wxObject *WXUNUSED(hint))
{
- if (canvas)
- canvas->Refresh();
+ if (m_canvas)
+ m_canvas->Refresh();
/* Is the following necessary?
#ifdef __WXMSW__
- if (canvas)
- canvas->Refresh();
+ if (canvas)
+ canvas->Refresh();
#else
- if (canvas)
+ if (canvas)
{
- wxClientDC dc(canvas);
- dc.Clear();
- OnDraw(& dc);
+ wxClientDC dc(canvas);
+ dc.Clear();
+ OnDraw(& dc);
}
#endif
*/
// Clean up windows used for displaying the view.
bool DrawingView::OnClose(bool deleteWindow)
{
- if (!GetDocument()->Close())
- return false;
+ if (!GetDocument()->Close())
+ return false;
- // Clear the canvas in case we're in single-window mode,
- // and the canvas stays.
- canvas->ClearBackground();
- canvas->view = (wxView *) NULL;
- canvas = (MyCanvas *) NULL;
+ // Clear the canvas in case we're in single-window mode,
+ // and the canvas stays.
+ m_canvas->ClearBackground();
+ m_canvas->m_view = NULL;
+ m_canvas = NULL;
- wxString s(wxTheApp->GetAppDisplayName());
- if (frame)
- frame->SetTitle(s);
+ wxString s(wxTheApp->GetAppDisplayName());
+ if (m_frame)
+ m_frame->SetTitle(s);
- SetFrame((wxFrame*)NULL);
+ SetFrame(NULL);
- Activate(false);
+ Activate(false);
- if (deleteWindow)
- {
- delete frame;
+ if (deleteWindow)
+ {
+ delete m_frame;
+ return true;
+ }
return true;
- }
- return true;
}
void DrawingView::OnCut(wxCommandEvent& WXUNUSED(event) )
{
- DrawingDocument *doc = (DrawingDocument *)GetDocument();
- doc->GetCommandProcessor()->Submit(new DrawingCommand(_T("Cut Last Segment"), DOODLE_CUT, doc, (DoodleSegment *) NULL));
+ DrawingDocument* doc = GetDocument();
+ doc->GetCommandProcessor()->Submit(new DrawingCommand(wxT("Cut Last Segment"), DOODLE_CUT, doc, NULL));
}
IMPLEMENT_DYNAMIC_CLASS(TextEditView, wxView)
-bool TextEditView::OnCreate(wxDocument *doc, long WXUNUSED(flags) )
+bool TextEditView::OnCreate(wxDocument* doc, long WXUNUSED(flags) )
{
- frame = wxGetApp().CreateChildFrame(doc, this, false);
+ m_frame = wxGetApp().CreateChildFrame(doc, this, false);
- int width, height;
- frame->GetClientSize(&width, &height);
- textsw = new MyTextWindow(this, frame, wxPoint(0, 0), wxSize(width, height), wxTE_MULTILINE);
- frame->SetTitle(_T("TextEditView"));
+ wxSize size = m_frame->GetClientSize();
+ m_textsw = new MyTextWindow(this, m_frame, wxPoint(0, 0), size, wxTE_MULTILINE);
+ m_frame->SetTitle(wxT("TextEditView"));
#ifdef __X__
- // X seems to require a forced resize
- int x, y;
- frame->GetSize(&x, &y);
- frame->SetSize(wxDefaultCoord, wxDefaultCoord, x, y);
+ // X seems to require a forced resize
+ int x, y;
+ m_frame->GetSize(&x, &y);
+ m_frame->SetSize(wxDefaultCoord, wxDefaultCoord, x, y);
#endif
- frame->Show(true);
- Activate(true);
+ m_frame->Show(true);
+ Activate(true);
- return true;
+ return true;
}
// Handled by wxTextWindow
bool TextEditView::OnClose(bool deleteWindow)
{
- if (!GetDocument()->Close())
- return false;
+ if (!GetDocument()->Close())
+ return false;
- Activate(false);
+ Activate(false);
- if (deleteWindow)
- {
- delete frame;
+ if (deleteWindow)
+ {
+ delete m_frame;
+ 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;
}
/*
END_EVENT_TABLE()
// Define a constructor for my canvas
-MyCanvas::MyCanvas(wxView *v, wxMDIChildFrame *frame, const wxPoint& pos, const wxSize& size, long style):
+MyCanvas::MyCanvas(DrawingView* view, wxMDIChildFrame* frame, const wxPoint& pos, const wxSize& size, long style):
wxScrolledWindow(frame, wxID_ANY, pos, size, style)
{
- view = v;
+ m_view = view;
}
// Define the repainting behaviour
void MyCanvas::OnDraw(wxDC& dc)
{
- if (view)
- view->OnDraw(& dc);
+ if (m_view)
+ m_view->OnDraw(& dc);
}
// This implements a tiny doodling program. Drag the mouse using
// the left button.
void MyCanvas::OnMouseEvent(wxMouseEvent& event)
{
- if (!view)
- return;
+ if (!m_view)
+ return;
- static DoodleSegment *currentSegment = (DoodleSegment *) NULL;
+ static DoodleSegment* currentSegment = NULL;
- wxClientDC dc(this);
- PrepareDC(dc);
+ wxClientDC dc(this);
+ 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->lines.GetCount() == 0)
+ if (currentSegment && event.LeftUp())
{
- delete currentSegment;
- currentSegment = (DoodleSegment *) NULL;
+ if (currentSegment->m_lines.GetCount() == 0)
+ {
+ 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.
- DrawingDocument *doc = (DrawingDocument *)view->GetDocument();
+ if (!currentSegment)
+ 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);
- currentSegment = (DoodleSegment *) NULL;
+ dc.DrawLine( (long)xpos, (long)ypos, pt.x, 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;
+ xpos = pt.x;
+ ypos = pt.y;
}
// Define a constructor for my text subwindow
-MyTextWindow::MyTextWindow(wxView *v, wxMDIChildFrame *frame, const wxPoint& pos, const wxSize& size, long style):
- wxTextCtrl(frame, wxID_ANY, _T(""), pos, size, style)
+MyTextWindow::MyTextWindow(wxView* view, wxMDIChildFrame* frame, const wxPoint& pos, const wxSize& size, long style):
+ wxTextCtrl(frame, wxID_ANY, wxEmptyString, pos, size, style)
{
- view = v;
+ m_view = view;
}
-
// Licence: wxWindows license
/////////////////////////////////////////////////////////////////////////////
-#ifndef __VIEWSAMPLEH__
-#define __VIEWSAMPLEH__
+#ifndef __VIEW_H__
+#define __VIEW_H__
#include "wx/docview.h"
-class MyCanvas: public wxScrolledWindow
+class DrawingView;
+class MyCanvas : public wxScrolledWindow
{
public:
- wxView *view;
-
- MyCanvas(wxView *v, wxMDIChildFrame *frame, const wxPoint& pos, const wxSize& size, long style);
- virtual void OnDraw(wxDC& dc);
- void OnMouseEvent(wxMouseEvent& event);
+ DrawingView* m_view;
-private:
+ MyCanvas(DrawingView*, wxMDIChildFrame*, const wxPoint&, const wxSize&, long style);
+ virtual void OnDraw(wxDC&);
+protected:
+ void OnMouseEvent(wxMouseEvent&);
DECLARE_EVENT_TABLE()
};
class MyTextWindow: public wxTextCtrl
{
public:
- wxView *view;
-
- MyTextWindow(wxView *v, wxMDIChildFrame *frame, const wxPoint& pos, const wxSize& size, long style);
+ wxView* m_view;
+
+ MyTextWindow(wxView*, wxMDIChildFrame*, const wxPoint&, const wxSize&, long style);
};
-class DrawingView: public wxView
+class DrawingDocument;
+class DrawingView : public wxView
{
+ DECLARE_DYNAMIC_CLASS(DrawingView)
public:
- wxMDIChildFrame *frame;
- MyCanvas *canvas;
-
- DrawingView() { canvas = (MyCanvas *) NULL; frame = (wxMDIChildFrame *) NULL; }
- ~DrawingView() {}
+ wxMDIChildFrame* m_frame;
+ MyCanvas* m_canvas;
- bool OnCreate(wxDocument *doc, long flags);
- void OnDraw(wxDC *dc);
- void OnUpdate(wxView *sender, wxObject *hint = (wxObject *) NULL);
- bool OnClose(bool deleteWindow = true);
+ DrawingView() { m_canvas = NULL; m_frame = NULL; }
+ virtual ~DrawingView() {}
- void OnCut(wxCommandEvent& event);
+ 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);
-private:
- DECLARE_DYNAMIC_CLASS(DrawingView)
+ DrawingDocument* GetDocument();
+
+protected:
+ void OnCut(wxCommandEvent& event);
DECLARE_EVENT_TABLE()
};
class TextEditView: public wxView
{
+ DECLARE_DYNAMIC_CLASS(TextEditView)
public:
- wxMDIChildFrame *frame;
- MyTextWindow *textsw;
-
- TextEditView(): wxView() { frame = (wxMDIChildFrame *) NULL; textsw = (MyTextWindow *) NULL; }
- ~TextEditView() {}
+ wxMDIChildFrame* m_frame;
+ MyTextWindow* m_textsw;
+
+ TextEditView() : wxView() { m_frame = NULL; m_textsw = NULL; }
+ virtual ~TextEditView() {}
- bool OnCreate(wxDocument *doc, long flags);
- void OnDraw(wxDC *dc);
- void OnUpdate(wxView *sender, wxObject *hint = (wxObject *) NULL);
- bool OnClose(bool deleteWindow = true);
-
-private:
- DECLARE_DYNAMIC_CLASS(TextEditView)
+ virtual bool OnCreate(wxDocument*, long flags);
+ virtual void OnDraw(wxDC* dc);
+ virtual void OnUpdate(wxView *sender, wxObject *hint = NULL);
+ virtual bool OnClose(bool deleteWindow = true);
+ virtual bool ProcessEvent(wxEvent&);
};
#endif