From 7aed63fdb752ffd3cc8f30b11ba2bd5ab7b12190 Mon Sep 17 00:00:00 2001 From: Julian Smart Date: Sat, 24 Jun 2000 08:05:21 +0000 Subject: [PATCH] Fixed docview crash bug when On... functions return FALSE. Fixed valgen.cpp to cope with strings in wxChoice/wxComboBox. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/branches/WX_2_2_BRANCH@7639 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- docs/html/logo.gif | Bin 3388 -> 3590 bytes docs/latex/wx/conditn.tex | 9 +- docs/latex/wx/sbsizer.tex | 2 +- samples/docview/doc.cpp | 444 ++++++++++++++++++------------------ samples/docview/doc.h | 110 ++++----- samples/docview/docview.cpp | 338 +++++++++++++-------------- samples/docview/docview.h | 36 +-- samples/docview/view.cpp | 304 ++++++++++++------------ samples/docview/view.h | 68 +++--- src/common/docview.cpp | 15 +- src/common/valgen.cpp | 69 +++++- 11 files changed, 727 insertions(+), 668 deletions(-) diff --git a/docs/html/logo.gif b/docs/html/logo.gif index d95a597121d6c1feb462e9470af5a98cb1cd9c91..67ce9957bab31fcbc17589b8734e0164a04f86ad 100644 GIT binary patch delta 2945 zcmW-jdpy&N8^^cVX680yHgjp4yNYN;)Y+Eh5?XQ>Hg^pbCKGnSIi^)3M3m*a#5u*` zp!N&tdrB@#(M`4Feon`w(?#c`pU&s?eqNvFc|HF;&p*%WxrP7Hi09$8-`Rx~4BiI% z1o|%if5HFH_?s1<-?yo$zNVoS`Q$6PSS&9qlh-uL8{6bI$_qBUS`57=+w0=R5K18AFg1K$3Ce;5!JV+O>;05NQUy-7NdehMfM z1L88EtOlrQ1RC3bwoaf^euL!;+4;|kRNBDj^S^Bl_zm>!Kil-pY*WN_C>R97g0^io zLEo1FAvQpE=M7aNcpqlrXf;bW6zOD04acYrg%!Aa_ zvy@aA51B=Phzxx!rXhJFbOqciz7_3FsSZAvWLL`;x`pa-4n#cx<~O0l`0MFnDO#xqcPMk=Acgn-DXFR~nZ zIt|A-D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G8El;BWiN0qn=Pay8biP$F zuOcT%=jZ^0Z;q0CYJuxqs#!|kyo4vf9E`nPYV9@knMaBBcqNGRfHghcW+*BLYz4Ze zf&c`vo=J*Zf0pPlYi!j$j`xtSCaLZ*(V2Yo7_S&BE|RVlSz7)VVL{j00>SogVg9MC z@3DI|rP`=;Fl0}<6fI96L>1tawJroHN<+x&R4%m-l-5T$?kP0Y=@4{Xh1^GzTmmGo zB_wT901yyEC8A6Vry#2%0UtFG3RNb<AiSMf$Nb~>uW6^{{Pp%NQ`^nsz$8Jy8f*ReXmG-Jec7%}8{>M?<4b%-m7n23tF rh>X~Xj`)a>7>SZNiIiB0mUxMnn2DOWiJaJpp7@EN7>bY>5C8x>>UNLe diff --git a/docs/latex/wx/conditn.tex b/docs/latex/wx/conditn.tex index 4238ff370e..a58d8b5ff4 100644 --- a/docs/latex/wx/conditn.tex +++ b/docs/latex/wx/conditn.tex @@ -11,6 +11,9 @@ perfect because in this particular case it would be much better to just \helpref{Wait()}{wxthreadwait} for the worker thread, but if there are several worker threads it already makes much more sense). +Once the thread(s) are signaled, the condition then resets to the not +signaled state, ready to fire again. + \wxheading{Derived from} None. @@ -51,18 +54,16 @@ Signals the object. \membersection{wxCondition::Wait}\label{wxconditionwait} -\func{void}{Wait}{\param{wxMutex\&}{ mutex}} +\func{void}{Wait}{\void} Waits indefinitely. -\func{bool}{Wait}{\param{wxMutex\&}{ mutex}, \param{unsigned long}{ sec}, \param{unsigned long}{ nsec}} +\func{bool}{Wait}{\param{unsigned long}{ sec}, \param{unsigned long}{ nsec}} Waits until a signal is raised or the timeout has elapsed. \wxheading{Parameters} -\docparam{mutex}{wxMutex object.} - \docparam{sec}{Timeout in seconds} \docparam{nsec}{Timeout nanoseconds component (added to {\it sec}).} diff --git a/docs/latex/wx/sbsizer.tex b/docs/latex/wx/sbsizer.tex index df5a8a5e45..3cc226a5b4 100644 --- a/docs/latex/wx/sbsizer.tex +++ b/docs/latex/wx/sbsizer.tex @@ -19,7 +19,7 @@ See also \helpref{wxSizer}{wxsizer}, \helpref{wxStaticBox}{wxstaticbox} and \func{}{wxStaticBoxSizer}{\param{wxStaticBox* }{box}, \param{int }{orient}} -Constructor. It takes an associated static box and the orientation {\it orient} +Constructor. It takes an associated static box and the orientation {\it orient} as parameters - orient can be either of wxVERTICAL or wxHORIZONTAL. \membersection{wxStaticBoxSizer::GetStaticBox}\label{wxstaticboxsizergetstaticbox} diff --git a/samples/docview/doc.cpp b/samples/docview/doc.cpp index d679a53221..864981f878 100644 --- a/samples/docview/doc.cpp +++ b/samples/docview/doc.cpp @@ -40,88 +40,88 @@ DrawingDocument::DrawingDocument(void) DrawingDocument::~DrawingDocument(void) { - doodleSegments.DeleteContents(TRUE); + doodleSegments.DeleteContents(TRUE); } #if wxUSE_STD_IOSTREAM ostream& DrawingDocument::SaveObject(ostream& stream) { - wxDocument::SaveObject(stream); - - wxInt32 n = doodleSegments.Number(); - stream << n << '\n'; - - wxNode *node = doodleSegments.First(); - while (node) - { - DoodleSegment *segment = (DoodleSegment *)node->Data(); - segment->SaveObject(stream); - stream << '\n'; + wxDocument::SaveObject(stream); - node = node->Next(); - } - - return stream; + wxInt32 n = doodleSegments.Number(); + stream << n << '\n'; + + wxNode *node = doodleSegments.First(); + while (node) + { + DoodleSegment *segment = (DoodleSegment *)node->Data(); + segment->SaveObject(stream); + stream << '\n'; + + node = node->Next(); + } + + return stream; } #else wxOutputStream& DrawingDocument::SaveObject(wxOutputStream& stream) { - wxDocument::SaveObject(stream); - - wxTextOutputStream text_stream( stream ); - - wxInt32 n = doodleSegments.Number(); - text_stream << n << '\n'; - - wxNode *node = doodleSegments.First(); - while (node) - { - DoodleSegment *segment = (DoodleSegment *)node->Data(); - segment->SaveObject(stream); - text_stream << '\n'; + wxDocument::SaveObject(stream); - node = node->Next(); - } - - return stream; + wxTextOutputStream text_stream( stream ); + + wxInt32 n = doodleSegments.Number(); + text_stream << n << '\n'; + + wxNode *node = doodleSegments.First(); + while (node) + { + DoodleSegment *segment = (DoodleSegment *)node->Data(); + segment->SaveObject(stream); + text_stream << '\n'; + + node = node->Next(); + } + + return stream; } #endif #if wxUSE_STD_IOSTREAM istream& DrawingDocument::LoadObject(istream& stream) { - wxDocument::LoadObject(stream); - - wxInt32 n = 0; - stream >> n; - - for (int i = 0; i < n; i++) - { - DoodleSegment *segment = new DoodleSegment; - segment->LoadObject(stream); - doodleSegments.Append(segment); - } - - return stream; + wxDocument::LoadObject(stream); + + wxInt32 n = 0; + stream >> n; + + for (int i = 0; i < n; i++) + { + DoodleSegment *segment = new DoodleSegment; + segment->LoadObject(stream); + doodleSegments.Append(segment); + } + + return stream; } #else wxInputStream& DrawingDocument::LoadObject(wxInputStream& stream) { - wxDocument::LoadObject(stream); - - wxTextInputStream text_stream( stream ); - - wxInt32 n = 0; - text_stream >> n; - - for (int i = 0; i < n; i++) - { - DoodleSegment *segment = new DoodleSegment; - segment->LoadObject(stream); - doodleSegments.Append(segment); - } - - return stream; + wxDocument::LoadObject(stream); + + wxTextInputStream text_stream( stream ); + + wxInt32 n = 0; + text_stream >> n; + + for (int i = 0; i < n; i++) + { + DoodleSegment *segment = new DoodleSegment; + segment->LoadObject(stream); + doodleSegments.Append(segment); + } + + return stream; } #endif @@ -131,204 +131,204 @@ DoodleSegment::DoodleSegment(void) DoodleSegment::DoodleSegment(DoodleSegment& seg) { - wxNode *node = seg.lines.First(); - while (node) - { - DoodleLine *line = (DoodleLine *)node->Data(); - 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->Next(); - } + wxNode *node = seg.lines.First(); + while (node) + { + DoodleLine *line = (DoodleLine *)node->Data(); + 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->Next(); + } } DoodleSegment::~DoodleSegment(void) { - lines.DeleteContents(TRUE); + lines.DeleteContents(TRUE); } #if wxUSE_STD_IOSTREAM ostream& DoodleSegment::SaveObject(ostream& stream) { - wxInt32 n = lines.Number(); - stream << n << '\n'; - - wxNode *node = lines.First(); - while (node) - { - DoodleLine *line = (DoodleLine *)node->Data(); - stream << line->x1 << " " << - line->y1 << " " << - line->x2 << " " << - line->y2 << "\n"; - node = node->Next(); - } - - return stream; + wxInt32 n = lines.Number(); + stream << n << '\n'; + + wxNode *node = lines.First(); + while (node) + { + DoodleLine *line = (DoodleLine *)node->Data(); + stream << line->x1 << " " << + line->y1 << " " << + line->x2 << " " << + line->y2 << "\n"; + node = node->Next(); + } + + return stream; } #else wxOutputStream &DoodleSegment::SaveObject(wxOutputStream& stream) { - wxTextOutputStream text_stream( stream ); - - wxInt32 n = lines.Number(); - text_stream << n << '\n'; - - wxNode *node = lines.First(); - while (node) - { - DoodleLine *line = (DoodleLine *)node->Data(); - text_stream << line->x1 << " " << - line->y1 << " " << - line->x2 << " " << - line->y2 << "\n"; - node = node->Next(); - } - - return stream; + wxTextOutputStream text_stream( stream ); + + wxInt32 n = lines.Number(); + text_stream << n << '\n'; + + wxNode *node = lines.First(); + while (node) + { + DoodleLine *line = (DoodleLine *)node->Data(); + text_stream << line->x1 << " " << + line->y1 << " " << + line->x2 << " " << + line->y2 << "\n"; + node = node->Next(); + } + + return stream; } #endif #if wxUSE_STD_IOSTREAM istream& DoodleSegment::LoadObject(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; + 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; + lines.Append(line); + } + + return stream; } #endif void DoodleSegment::Draw(wxDC *dc) { - wxNode *node = lines.First(); - while (node) - { - DoodleLine *line = (DoodleLine *)node->Data(); - dc->DrawLine(line->x1, line->y1, line->x2, line->y2); - node = node->Next(); - } + wxNode *node = lines.First(); + while (node) + { + DoodleLine *line = (DoodleLine *)node->Data(); + dc->DrawLine(line->x1, line->y1, line->x2, line->y2); + node = node->Next(); + } } /* - * Implementation of drawing command - */ +* Implementation of drawing command +*/ DrawingCommand::DrawingCommand(const wxString& name, int command, DrawingDocument *ddoc, DoodleSegment *seg): - wxCommand(TRUE, name) +wxCommand(TRUE, name) { - doc = ddoc; - segment = seg; - cmd = command; + doc = ddoc; + segment = seg; + cmd = command; } DrawingCommand::~DrawingCommand(void) { - if (segment) - delete segment; + if (segment) + delete segment; } bool DrawingCommand::Do(void) { - switch (cmd) - { + switch (cmd) + { case DOODLE_CUT: - { - // Cut the last segment - if (doc->GetDoodleSegments().Number() > 0) - { - wxNode *node = doc->GetDoodleSegments().Last(); - if (segment) - delete segment; - - segment = (DoodleSegment *)node->Data(); - delete node; - - doc->Modify(TRUE); - doc->UpdateAllViews(); - } - break; - } + { + // Cut the last segment + if (doc->GetDoodleSegments().Number() > 0) + { + wxNode *node = doc->GetDoodleSegments().Last(); + if (segment) + delete segment; + + segment = (DoodleSegment *)node->Data(); + delete node; + + doc->Modify(TRUE); + doc->UpdateAllViews(); + } + break; + } case DOODLE_ADD: - { - doc->GetDoodleSegments().Append(new DoodleSegment(*segment)); - doc->Modify(TRUE); - doc->UpdateAllViews(); - break; + { + doc->GetDoodleSegments().Append(new DoodleSegment(*segment)); + doc->Modify(TRUE); + doc->UpdateAllViews(); + break; + } } - } - return TRUE; + return TRUE; } bool DrawingCommand::Undo(void) { - switch (cmd) - { + 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; - } + { + // 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: - { - // Cut the last segment - if (doc->GetDoodleSegments().Number() > 0) - { - wxNode *node = doc->GetDoodleSegments().Last(); - DoodleSegment *seg = (DoodleSegment *)node->Data(); - delete seg; - delete node; - - doc->Modify(TRUE); - doc->UpdateAllViews(); - } + { + // Cut the last segment + if (doc->GetDoodleSegments().Number() > 0) + { + wxNode *node = doc->GetDoodleSegments().Last(); + DoodleSegment *seg = (DoodleSegment *)node->Data(); + delete seg; + delete node; + + doc->Modify(TRUE); + doc->UpdateAllViews(); + } + } } - } - return TRUE; + return TRUE; } IMPLEMENT_DYNAMIC_CLASS(TextEditDocument, wxDocument) @@ -338,7 +338,7 @@ IMPLEMENT_DYNAMIC_CLASS(TextEditDocument, wxDocument) bool TextEditDocument::OnSaveDocument(const wxString& filename) { TextEditView *view = (TextEditView *)GetFirstView(); - + if (!view->textsw->SaveFile(filename)) return FALSE; Modify(FALSE); @@ -350,7 +350,7 @@ bool TextEditDocument::OnOpenDocument(const wxString& filename) TextEditView *view = (TextEditView *)GetFirstView(); if (!view->textsw->LoadFile(filename)) return FALSE; - + SetFilename(filename, TRUE); Modify(FALSE); UpdateAllViews(); @@ -359,21 +359,21 @@ bool TextEditDocument::OnOpenDocument(const wxString& filename) bool TextEditDocument::IsModified(void) const { - TextEditView *view = (TextEditView *)GetFirstView(); - if (view) - { - return (wxDocument::IsModified() || view->textsw->IsModified()); - } - else - return wxDocument::IsModified(); + TextEditView *view = (TextEditView *)GetFirstView(); + if (view) + { + return (wxDocument::IsModified() || view->textsw->IsModified()); + } + else + return wxDocument::IsModified(); } void TextEditDocument::Modify(bool mod) { - TextEditView *view = (TextEditView *)GetFirstView(); - - wxDocument::Modify(mod); - - if (!mod && view && view->textsw) - view->textsw->DiscardEdits(); + TextEditView *view = (TextEditView *)GetFirstView(); + + wxDocument::Modify(mod); + + if (!mod && view && view->textsw) + view->textsw->DiscardEdits(); } diff --git a/samples/docview/doc.h b/samples/docview/doc.h index 2842a32315..06ec872828 100644 --- a/samples/docview/doc.h +++ b/samples/docview/doc.h @@ -21,53 +21,53 @@ // 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; - - DoodleSegment(void); - DoodleSegment(DoodleSegment& seg); - ~DoodleSegment(void); - - void Draw(wxDC *dc); +public: + wxList lines; + + DoodleSegment(void); + DoodleSegment(DoodleSegment& seg); + ~DoodleSegment(void); + + void Draw(wxDC *dc); #if wxUSE_STD_IOSTREAM - ostream& SaveObject(ostream& text_stream); - istream& LoadObject(istream& text_stream); + ostream& SaveObject(ostream& text_stream); + istream& LoadObject(istream& text_stream); #else - wxOutputStream& SaveObject(wxOutputStream& stream); - wxInputStream& LoadObject(wxInputStream& stream); + wxOutputStream& SaveObject(wxOutputStream& stream); + wxInputStream& LoadObject(wxInputStream& stream); #endif - + }; class DrawingDocument: public wxDocument { - DECLARE_DYNAMIC_CLASS(DrawingDocument) - private: - public: - wxList doodleSegments; - - DrawingDocument(void); - ~DrawingDocument(void); - + DECLARE_DYNAMIC_CLASS(DrawingDocument) +private: +public: + wxList doodleSegments; + + DrawingDocument(void); + ~DrawingDocument(void); + #if wxUSE_STD_IOSTREAM - ostream& SaveObject(ostream& text_stream); - istream& LoadObject(istream& text_stream); + ostream& SaveObject(ostream& text_stream); + istream& LoadObject(istream& text_stream); #else - wxOutputStream& SaveObject(wxOutputStream& stream); - wxInputStream& LoadObject(wxInputStream& stream); + wxOutputStream& SaveObject(wxOutputStream& stream); + wxInputStream& LoadObject(wxInputStream& stream); #endif - - inline wxList& GetDoodleSegments(void) const { return (wxList&) doodleSegments; }; + + inline wxList& GetDoodleSegments(void) const { return (wxList&) doodleSegments; }; }; #define DOODLE_CUT 1 @@ -75,34 +75,34 @@ class DrawingDocument: public wxDocument 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 *segment; + DrawingDocument *doc; + int cmd; +public: + DrawingCommand(const wxString& name, int cmd, DrawingDocument *ddoc, DoodleSegment *seg); + ~DrawingCommand(void); + + bool Do(void); + bool Undo(void); }; class TextEditDocument: public wxDocument { - DECLARE_DYNAMIC_CLASS(TextEditDocument) - private: - public: + DECLARE_DYNAMIC_CLASS(TextEditDocument) +private: +public: /* - ostream& SaveObject(ostream& stream); - istream& LoadObject(istream& stream); -*/ - 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) {} +ostream& SaveObject(ostream& stream); +istream& LoadObject(istream& stream); + */ + 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) {} }; diff --git a/samples/docview/docview.cpp b/samples/docview/docview.cpp index b142b5f843..977e9dde6f 100644 --- a/samples/docview/docview.cpp +++ b/samples/docview/docview.cpp @@ -14,10 +14,10 @@ #endif /* - * Purpose: Document/view architecture demo for wxWindows class library - * Run with no arguments for multiple top-level windows, -single - * for a single window. - */ +* Purpose: Document/view architecture demo for wxWindows class library +* Run with no arguments for multiple top-level windows, -single +* for a single window. +*/ // For compilers that support precompilation, includes "wx/wx.h". @@ -56,98 +56,98 @@ MyApp::MyApp(void) bool MyApp::OnInit(void) { - //// Find out if we're: - //// SDI : multiple windows and documents but not MDI - //// MDI : multiple windows and documents with containing frame - MSW only) - /// single window : (one document at a time, only one frame, as in Windows Write) - if (argc > 1) - { - if (wxStrcmp(argv[1], _T("-single")) == 0) + //// Find out if we're: + //// multiple window: multiple windows, each view in a separate frame + //// single window: one view (within the main frame) and one document at a time, as in Windows Write. + //// In single window mode, we only allow one document type + if (argc > 1) { - singleWindowMode = TRUE; + if (wxStrcmp(argv[1], _T("-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, "Drawing", "*.drw", "", "drw", "Drawing Doc", "Drawing View", - CLASSINFO(DrawingDocument), CLASSINFO(DrawingView)); - - if (singleWindowMode) - { - // If we've only got one window, we only get to edit - // one document at a time. Therefore no text editing, just - // doodling. - m_docManager->SetMaxDocsOpen(1); - } - else - //// Create a template relating text documents to their views - (void) new wxDocTemplate(m_docManager, "Text", "*.txt", "", "txt", "Text Doc", "Text View", - CLASSINFO(TextEditDocument), CLASSINFO(TextEditView)); - - //// Create the main frame window - frame = new MyFrame(m_docManager, (wxFrame *) NULL, -1, "DocView Demo", wxPoint(0, 0), wxSize(500, 400), wxDEFAULT_FRAME_STYLE); - - //// Give it an icon (this is ignored in MDI mode: uses resources) + + //// Create a document manager + m_docManager = new wxDocManager; + + //// Create a template relating drawing documents to their views + (void) new wxDocTemplate(m_docManager, "Drawing", "*.drw", "", "drw", "Drawing Doc", "Drawing View", + CLASSINFO(DrawingDocument), CLASSINFO(DrawingView)); + + if (singleWindowMode) + { + // If we've only got one window, we only get to edit + // one document at a time. Therefore no text editing, just + // doodling. + m_docManager->SetMaxDocsOpen(1); + } + else + //// Create a template relating text documents to their views + (void) new wxDocTemplate(m_docManager, "Text", "*.txt", "", "txt", "Text Doc", "Text View", + CLASSINFO(TextEditDocument), CLASSINFO(TextEditView)); + + //// Create the main frame window + frame = new MyFrame(m_docManager, (wxFrame *) NULL, -1, "DocView Demo", 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("doc_icn")); + frame->SetIcon(wxIcon("doc_icn")); #endif - - //// Make a menubar - wxMenu *file_menu = new wxMenu; - wxMenu *edit_menu = (wxMenu *) NULL; - - file_menu->Append(wxID_NEW, "&New..."); - file_menu->Append(wxID_OPEN, "&Open..."); - - if (singleWindowMode) - { - file_menu->Append(wxID_CLOSE, "&Close"); - file_menu->Append(wxID_SAVE, "&Save"); - file_menu->Append(wxID_SAVEAS, "Save &As..."); + + //// Make a menubar + wxMenu *file_menu = new wxMenu; + wxMenu *edit_menu = (wxMenu *) NULL; + + file_menu->Append(wxID_NEW, "&New..."); + file_menu->Append(wxID_OPEN, "&Open..."); + + if (singleWindowMode) + { + file_menu->Append(wxID_CLOSE, "&Close"); + file_menu->Append(wxID_SAVE, "&Save"); + file_menu->Append(wxID_SAVEAS, "Save &As..."); + file_menu->AppendSeparator(); + file_menu->Append(wxID_PRINT, "&Print..."); + file_menu->Append(wxID_PRINT_SETUP, "Print &Setup..."); + file_menu->Append(wxID_PREVIEW, "Print Pre&view"); + + edit_menu = new wxMenu; + edit_menu->Append(wxID_UNDO, "&Undo"); + edit_menu->Append(wxID_REDO, "&Redo"); + edit_menu->AppendSeparator(); + edit_menu->Append(DOCVIEW_CUT, "&Cut last segment"); + + frame->editMenu = edit_menu; + } + file_menu->AppendSeparator(); - file_menu->Append(wxID_PRINT, "&Print..."); - file_menu->Append(wxID_PRINT_SETUP, "Print &Setup..."); - file_menu->Append(wxID_PREVIEW, "Print Pre&view"); - - edit_menu = new wxMenu; - edit_menu->Append(wxID_UNDO, "&Undo"); - edit_menu->Append(wxID_REDO, "&Redo"); - edit_menu->AppendSeparator(); - edit_menu->Append(DOCVIEW_CUT, "&Cut last segment"); - - frame->editMenu = edit_menu; - } - - file_menu->AppendSeparator(); - file_menu->Append(wxID_EXIT, "E&xit"); - - // 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, "&About"); - - wxMenuBar *menu_bar = new wxMenuBar; - - menu_bar->Append(file_menu, "&File"); - if (edit_menu) - menu_bar->Append(edit_menu, "&Edit"); - menu_bar->Append(help_menu, "&Help"); - - if (singleWindowMode) - frame->canvas = frame->CreateCanvas((wxView *) NULL, frame); - - //// Associate the menu bar with the frame - frame->SetMenuBar(menu_bar); - - frame->Centre(wxBOTH); - frame->Show(TRUE); - - SetTopWindow(frame); - return TRUE; + file_menu->Append(wxID_EXIT, "E&xit"); + + // 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, "&About"); + + wxMenuBar *menu_bar = new wxMenuBar; + + menu_bar->Append(file_menu, "&File"); + if (edit_menu) + menu_bar->Append(edit_menu, "&Edit"); + menu_bar->Append(help_menu, "&Help"); + + if (singleWindowMode) + frame->canvas = frame->CreateCanvas((wxView *) NULL, frame); + + //// Associate the menu bar with the frame + frame->SetMenuBar(menu_bar); + + frame->Centre(wxBOTH); + frame->Show(TRUE); + + SetTopWindow(frame); + return TRUE; } int MyApp::OnExit(void) @@ -157,85 +157,85 @@ int MyApp::OnExit(void) } /* - * Centralised code for creating a document frame. - * Called from view.cpp, when a view is created, but not used at all - * in 'single window' mode. - */ - +* Centralised code for creating a document frame. +* Called from view.cpp, when a view is created, but not used at all +* in 'single window' mode. +*/ + wxFrame *MyApp::CreateChildFrame(wxDocument *doc, wxView *view, bool isCanvas) { - //// Make a child frame - wxDocChildFrame *subframe = new wxDocChildFrame(doc, view, GetMainFrame(), -1, "Child Frame", + //// Make a child frame + wxDocChildFrame *subframe = new wxDocChildFrame(doc, view, GetMainFrame(), -1, "Child Frame", wxPoint(10, 10), wxSize(300, 300), wxDEFAULT_FRAME_STYLE); - + #ifdef __WXMSW__ - subframe->SetIcon(wxString(isCanvas ? "chrt_icn" : "notepad_icn")); + subframe->SetIcon(wxString(isCanvas ? "chrt_icn" : "notepad_icn")); #endif - - //// Make a menubar - wxMenu *file_menu = new wxMenu; - - file_menu->Append(wxID_NEW, "&New..."); - file_menu->Append(wxID_OPEN, "&Open..."); - file_menu->Append(wxID_CLOSE, "&Close"); - file_menu->Append(wxID_SAVE, "&Save"); - file_menu->Append(wxID_SAVEAS, "Save &As..."); - - if (isCanvas) - { - file_menu->AppendSeparator(); - file_menu->Append(wxID_PRINT, "&Print..."); - file_menu->Append(wxID_PRINT_SETUP, "Print &Setup..."); - file_menu->Append(wxID_PREVIEW, "Print Pre&view"); - } - - wxMenu *edit_menu = (wxMenu *) NULL; - - if (isCanvas) - { - edit_menu = new wxMenu; - edit_menu->Append(wxID_UNDO, "&Undo"); - edit_menu->Append(wxID_REDO, "&Redo"); - edit_menu->AppendSeparator(); - edit_menu->Append(DOCVIEW_CUT, "&Cut last segment"); - - doc->GetCommandProcessor()->SetEditMenu(edit_menu); - } - - wxMenu *help_menu = new wxMenu; - help_menu->Append(DOCVIEW_ABOUT, "&About"); - - wxMenuBar *menu_bar = new wxMenuBar; - - menu_bar->Append(file_menu, "&File"); - if (isCanvas) - menu_bar->Append(edit_menu, "&Edit"); - menu_bar->Append(help_menu, "&Help"); - - //// Associate the menu bar with the frame - subframe->SetMenuBar(menu_bar); - - subframe->Centre(wxBOTH); - - return subframe; + + //// Make a menubar + wxMenu *file_menu = new wxMenu; + + file_menu->Append(wxID_NEW, "&New..."); + file_menu->Append(wxID_OPEN, "&Open..."); + file_menu->Append(wxID_CLOSE, "&Close"); + file_menu->Append(wxID_SAVE, "&Save"); + file_menu->Append(wxID_SAVEAS, "Save &As..."); + + if (isCanvas) + { + file_menu->AppendSeparator(); + file_menu->Append(wxID_PRINT, "&Print..."); + file_menu->Append(wxID_PRINT_SETUP, "Print &Setup..."); + file_menu->Append(wxID_PREVIEW, "Print Pre&view"); + } + + wxMenu *edit_menu = (wxMenu *) NULL; + + if (isCanvas) + { + edit_menu = new wxMenu; + edit_menu->Append(wxID_UNDO, "&Undo"); + edit_menu->Append(wxID_REDO, "&Redo"); + edit_menu->AppendSeparator(); + edit_menu->Append(DOCVIEW_CUT, "&Cut last segment"); + + doc->GetCommandProcessor()->SetEditMenu(edit_menu); + } + + wxMenu *help_menu = new wxMenu; + help_menu->Append(DOCVIEW_ABOUT, "&About"); + + wxMenuBar *menu_bar = new wxMenuBar; + + menu_bar->Append(file_menu, "&File"); + if (isCanvas) + menu_bar->Append(edit_menu, "&Edit"); + menu_bar->Append(help_menu, "&Help"); + + //// Associate the menu bar with the frame + subframe->SetMenuBar(menu_bar); + + subframe->Centre(wxBOTH); + + return subframe; } /* - * This is the top-level window of the application. - */ - +* This is the top-level window of the application. +*/ + IMPLEMENT_CLASS(MyFrame, wxDocParentFrame) BEGIN_EVENT_TABLE(MyFrame, wxDocParentFrame) EVT_MENU(DOCVIEW_ABOUT, MyFrame::OnAbout) END_EVENT_TABLE() MyFrame::MyFrame(wxDocManager *manager, wxFrame *frame, wxWindowID id, const wxString& title, - const wxPoint& pos, const wxSize& size, const long type): - wxDocParentFrame(manager, frame, id, title, pos, size, type) + const wxPoint& pos, const wxSize& size, const long type): +wxDocParentFrame(manager, frame, id, title, pos, size, type) { - // This pointer only needed if in single window mode - canvas = (MyCanvas *) NULL; - editMenu = (wxMenu *) NULL; + // This pointer only needed if in single window mode + canvas = (MyCanvas *) NULL; + editMenu = (wxMenu *) NULL; } void MyFrame::OnAbout(wxCommandEvent& WXUNUSED(event) ) @@ -248,23 +248,23 @@ void MyFrame::OnAbout(wxCommandEvent& WXUNUSED(event) ) // if in 'single window' mode. MyCanvas *MyFrame::CreateCanvas(wxView *view, wxFrame *parent) { - int width, height; - parent->GetClientSize(&width, &height); - - // Non-retained canvas - MyCanvas *canvas = new MyCanvas(view, parent, wxPoint(0, 0), wxSize(width, height), 0); - canvas->SetCursor(wxCursor(wxCURSOR_PENCIL)); - - // Give it scrollbars - canvas->SetScrollbars(20, 20, 50, 50); - canvas->SetBackgroundColour(*wxWHITE); - canvas->Clear(); - - return canvas; + int width, height; + parent->GetClientSize(&width, &height); + + // Non-retained canvas + MyCanvas *canvas = new MyCanvas(view, parent, wxPoint(0, 0), wxSize(width, height), 0); + canvas->SetCursor(wxCursor(wxCURSOR_PENCIL)); + + // Give it scrollbars + canvas->SetScrollbars(20, 20, 50, 50); + canvas->SetBackgroundColour(*wxWHITE); + canvas->Clear(); + + return canvas; } MyFrame *GetMainFrame(void) { - return frame; + return frame; } diff --git a/samples/docview/docview.h b/samples/docview/docview.h index fb9201406f..473e8b526e 100644 --- a/samples/docview/docview.h +++ b/samples/docview/docview.h @@ -23,14 +23,14 @@ class wxDocManager; // Define a new application class MyApp: public wxApp { - public: +public: MyApp(void); bool OnInit(void); int OnExit(void); - + wxFrame *CreateChildFrame(wxDocument *doc, wxView *view, bool isCanvas); - - protected: + +protected: wxDocManager* m_docManager; }; @@ -40,20 +40,20 @@ DECLARE_APP(MyApp) class MyCanvas; class MyFrame: public wxDocParentFrame { - DECLARE_CLASS(MyFrame) - public: - wxMenu *editMenu; - - // This pointer only needed if in single window mode - MyCanvas *canvas; - - MyFrame(wxDocManager *manager, wxFrame *frame, wxWindowID id, const wxString& title, const wxPoint& pos, const wxSize& size, - const long type); - - void OnAbout(wxCommandEvent& event); - MyCanvas *CreateCanvas(wxView *view, wxFrame *parent); - -DECLARE_EVENT_TABLE() + DECLARE_CLASS(MyFrame) +public: + wxMenu *editMenu; + + // This pointer only needed if in single window mode + MyCanvas *canvas; + + MyFrame(wxDocManager *manager, wxFrame *frame, wxWindowID id, const wxString& title, const wxPoint& pos, const wxSize& size, + const long type); + + void OnAbout(wxCommandEvent& event); + MyCanvas *CreateCanvas(wxView *view, wxFrame *parent); + + DECLARE_EVENT_TABLE() }; extern MyFrame *GetMainFrame(void); diff --git a/samples/docview/view.cpp b/samples/docview/view.cpp index 61cec41421..06e35d3a84 100644 --- a/samples/docview/view.cpp +++ b/samples/docview/view.cpp @@ -46,74 +46,74 @@ END_EVENT_TABLE() // windows for displaying the view. bool DrawingView::OnCreate(wxDocument *doc, long WXUNUSED(flags) ) { - if (!singleWindowMode) - { - // Multiple windows - frame = wxGetApp().CreateChildFrame(doc, this, TRUE); - frame->SetTitle("DrawingView"); - - canvas = GetMainFrame()->CreateCanvas(this, frame); + if (!singleWindowMode) + { + // Multiple windows + frame = wxGetApp().CreateChildFrame(doc, this, TRUE); + frame->SetTitle("DrawingView"); + + canvas = GetMainFrame()->CreateCanvas(this, frame); #ifdef __X__ - // X seems to require a forced resize - int x, y; - frame->GetSize(&x, &y); - frame->SetSize(-1, -1, x, y); + // X seems to require a forced resize + int x, y; + frame->GetSize(&x, &y); + frame->SetSize(-1, -1, x, y); #endif - frame->Show(TRUE); - } - else - { - // Single-window mode - frame = GetMainFrame(); - canvas = GetMainFrame()->canvas; - canvas->view = this; - - // Associate the appropriate frame with this view. - SetFrame(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()->Initialize(); - } - - return TRUE; + frame->Show(TRUE); + } + else + { + // Single-window mode + frame = GetMainFrame(); + canvas = GetMainFrame()->canvas; + canvas->view = this; + + // Associate the appropriate frame with this view. + SetFrame(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()->Initialize(); + } + + return TRUE; } // 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); - - wxNode *node = ((DrawingDocument *)GetDocument())->GetDoodleSegments().First(); - while (node) - { - DoodleSegment *seg = (DoodleSegment *)node->Data(); - seg->Draw(dc); - node = node->Next(); - } + dc->SetFont(*wxNORMAL_FONT); + dc->SetPen(*wxBLACK_PEN); + + wxNode *node = ((DrawingDocument *)GetDocument())->GetDoodleSegments().First(); + while (node) + { + DoodleSegment *seg = (DoodleSegment *)node->Data(); + seg->Draw(dc); + node = node->Next(); + } } void DrawingView::OnUpdate(wxView *WXUNUSED(sender), wxObject *WXUNUSED(hint)) { - if (canvas) - canvas->Refresh(); - + if (canvas) + 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 */ @@ -122,29 +122,29 @@ void DrawingView::OnUpdate(wxView *WXUNUSED(sender), wxObject *WXUNUSED(hint)) // Clean up windows used for displaying the view. bool DrawingView::OnClose(bool deleteWindow) { - if (!GetDocument()->Close()) - return FALSE; - - // Clear the canvas in case we're in single-window mode, - // and the canvas stays. - canvas->Clear(); - canvas->view = (wxView *) NULL; - canvas = (MyCanvas *) NULL; - - wxString s(wxTheApp->GetAppName()); - if (frame) - frame->SetTitle(s); - - SetFrame((wxFrame *) NULL); - - Activate(FALSE); - - if (deleteWindow && !singleWindowMode) - { - delete frame; + if (!GetDocument()->Close()) + return FALSE; + + // Clear the canvas in case we're in single-window mode, + // and the canvas stays. + canvas->Clear(); + canvas->view = (wxView *) NULL; + canvas = (MyCanvas *) NULL; + + wxString s(wxTheApp->GetAppName()); + if (frame) + frame->SetTitle(s); + + SetFrame((wxFrame *) NULL); + + Activate(FALSE); + + if (deleteWindow && !singleWindowMode) + { + delete frame; + return TRUE; + } return TRUE; - } - return TRUE; } void DrawingView::OnCut(wxCommandEvent& WXUNUSED(event) ) @@ -157,24 +157,24 @@ 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("TextEditView"); - + 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("TextEditView"); + #ifdef __X__ - // X seems to require a forced resize - int x, y; - frame->GetSize(&x, &y); - frame->SetSize(-1, -1, x, y); + // X seems to require a forced resize + int x, y; + frame->GetSize(&x, &y); + frame->SetSize(-1, -1, x, y); #endif - - frame->Show(TRUE); - Activate(TRUE); - - return TRUE; + + frame->Show(TRUE); + Activate(TRUE); + + return TRUE; } // Handled by wxTextWindow @@ -188,22 +188,22 @@ void TextEditView::OnUpdate(wxView *WXUNUSED(sender), wxObject *WXUNUSED(hint) ) bool TextEditView::OnClose(bool deleteWindow) { - if (!GetDocument()->Close()) - return FALSE; + if (!GetDocument()->Close()) + return FALSE; - Activate(FALSE); - - if (deleteWindow) - { - delete frame; + Activate(FALSE); + + if (deleteWindow) + { + delete frame; + return TRUE; + } return TRUE; - } - return TRUE; } /* - * Window implementations - */ +* Window implementations +*/ BEGIN_EVENT_TABLE(MyCanvas, wxScrolledWindow) EVT_MOUSE_EVENTS(MyCanvas::OnMouseEvent) @@ -211,76 +211,76 @@ END_EVENT_TABLE() // Define a constructor for my canvas MyCanvas::MyCanvas(wxView *v, wxFrame *frame, const wxPoint& pos, const wxSize& size, const long style): - wxScrolledWindow(frame, -1, pos, size, style) + wxScrolledWindow(frame, -1, pos, size, style) { - view = v; + view = v; } // Define the repainting behaviour void MyCanvas::OnDraw(wxDC& dc) { - if (view) - view->OnDraw(& dc); + if (view) + 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 (!view) + return; - static DoodleSegment *currentSegment = (DoodleSegment *) NULL; - - wxClientDC dc(this); - PrepareDC(dc); - - dc.SetPen(*wxBLACK_PEN); - - wxPoint pt(event.GetLogicalPosition(dc)); - - if (currentSegment && event.LeftUp()) - { - if (currentSegment->lines.Number() == 0) - { - delete currentSegment; - currentSegment = (DoodleSegment *) 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("Add Segment", DOODLE_ADD, doc, currentSegment)); - - view->GetDocument()->Modify(TRUE); - currentSegment = (DoodleSegment *) NULL; - } - } - - 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); + static DoodleSegment *currentSegment = (DoodleSegment *) NULL; - dc.DrawLine( (long)xpos, (long)ypos, pt.x, pt.y); - } - xpos = pt.x; - ypos = pt.y; + wxClientDC dc(this); + PrepareDC(dc); + + dc.SetPen(*wxBLACK_PEN); + + wxPoint pt(event.GetLogicalPosition(dc)); + + if (currentSegment && event.LeftUp()) + { + if (currentSegment->lines.Number() == 0) + { + delete currentSegment; + currentSegment = (DoodleSegment *) 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("Add Segment", DOODLE_ADD, doc, currentSegment)); + + view->GetDocument()->Modify(TRUE); + currentSegment = (DoodleSegment *) NULL; + } + } + + 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 MyTextWindow::MyTextWindow(wxView *v, wxFrame *frame, const wxPoint& pos, const wxSize& size, const long style): - wxTextCtrl(frame, -1, "", pos, size, style) + wxTextCtrl(frame, -1, "", pos, size, style) { - view = v; + view = v; } diff --git a/samples/docview/view.h b/samples/docview/view.h index d69cef8fec..950d8b6dcd 100644 --- a/samples/docview/view.h +++ b/samples/docview/view.h @@ -20,19 +20,19 @@ class MyCanvas: public wxScrolledWindow { - public: +public: wxView *view; MyCanvas(wxView *v, wxFrame *frame, const wxPoint& pos, const wxSize& size, const long style); virtual void OnDraw(wxDC& dc); void OnMouseEvent(wxMouseEvent& event); - -DECLARE_EVENT_TABLE() + + DECLARE_EVENT_TABLE() }; class MyTextWindow: public wxTextCtrl { - public: +public: wxView *view; MyTextWindow(wxView *v, wxFrame *frame, const wxPoint& pos, const wxSize& size, const long style); @@ -40,40 +40,40 @@ class MyTextWindow: public wxTextCtrl 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); - - void OnCut(wxCommandEvent& event); - -DECLARE_EVENT_TABLE() + 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); + + void OnCut(wxCommandEvent& event); + + DECLARE_EVENT_TABLE() }; 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); + 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); }; #endif diff --git a/src/common/docview.cpp b/src/common/docview.cpp index 3e894aa0d1..13fa7316d8 100644 --- a/src/common/docview.cpp +++ b/src/common/docview.cpp @@ -172,6 +172,8 @@ bool wxDocument::OnCloseDocument() // deleted. bool wxDocument::DeleteAllViews() { + wxDocManager* manager = GetDocumentManager(); + wxNode *node = m_documentViews.First(); while (node) { @@ -184,6 +186,11 @@ bool wxDocument::DeleteAllViews() delete view; // Deletes node implicitly node = next; } + // If we haven't yet deleted the document (for example + // if there were no views) then delete it. + if (manager->GetDocuments().Member(this)) + delete this; + return TRUE; } @@ -655,7 +662,8 @@ wxDocument *wxDocTemplate::CreateDocument(const wxString& path, long flags) return doc; else { - delete doc; + if (GetDocumentManager()->GetDocuments().Member(doc)) + doc->DeleteAllViews(); return (wxDocument *) NULL; } } @@ -1096,7 +1104,8 @@ wxDocument *wxDocManager::CreateDocument(const wxString& path, long flags) newDoc->SetDocumentTemplate(temp); if (!newDoc->OnOpenDocument(path2)) { - delete newDoc; + newDoc->DeleteAllViews(); + // delete newDoc; // Implicitly deleted by DeleteAllViews return (wxDocument *) NULL; } AddFileToHistory(path2); @@ -1340,7 +1349,7 @@ wxDocTemplate *wxDocManager::SelectDocumentPath(wxDocTemplate **templates, 0, wxTheApp->GetTopWindow()); - if (!pathTmp.IsEmpty()) + if (!pathTmp.IsEmpty() && wxFileExists(pathTmp)) { m_lastDirectory = wxPathOnly(pathTmp); diff --git a/src/common/valgen.cpp b/src/common/valgen.cpp index 76cd16ca88..175b6a2108 100644 --- a/src/common/valgen.cpp +++ b/src/common/valgen.cpp @@ -214,21 +214,46 @@ bool wxGenericValidator::TransferToWindow(void) if (m_validatorWindow->IsKindOf(CLASSINFO(wxChoice)) ) { wxChoice* pControl = (wxChoice*) m_validatorWindow; - if (m_pInt) - { - pControl->SetSelection(*m_pInt) ; - return TRUE; - } + if (m_pInt) + { + pControl->SetSelection(*m_pInt) ; + return TRUE; + } + else if (m_pString) + { + if (pControl->FindString(* m_pString) > -1) + { + pControl->SetStringSelection(* m_pString); + } + return TRUE; + } } else #endif + if (m_validatorWindow->IsKindOf(CLASSINFO(wxComboBox)) ) + { + wxComboBox* pControl = (wxComboBox*) m_validatorWindow; + if (m_pInt) + { + pControl->SetSelection(*m_pInt) ; + return TRUE; + } + else if (m_pString) + { + if (pControl->FindString(* m_pString) > -1) + { + pControl->SetStringSelection(* m_pString); + } + return TRUE; + } + } else if (m_validatorWindow->IsKindOf(CLASSINFO(wxStaticText)) ) { wxStaticText* pControl = (wxStaticText*) m_validatorWindow; - if (m_pString) - { - pControl->SetLabel(*m_pString) ; - return TRUE; - } + if (m_pString) + { + pControl->SetLabel(*m_pString) ; + return TRUE; + } } else if (m_validatorWindow->IsKindOf(CLASSINFO(wxTextCtrl)) ) { @@ -395,6 +420,11 @@ bool wxGenericValidator::TransferFromWindow(void) *m_pString = pControl->GetValue() ; return TRUE; } + else if (m_pString) + { + *m_pString = pControl->GetStringSelection(); + return TRUE; + } } else #endif #if wxUSE_CHOICE @@ -406,8 +436,27 @@ bool wxGenericValidator::TransferFromWindow(void) *m_pInt = pControl->GetSelection() ; return TRUE; } + else if (m_pString) + { + *m_pString = pControl->GetStringSelection(); + return TRUE; + } } else #endif + if (m_validatorWindow->IsKindOf(CLASSINFO(wxComboBox)) ) + { + wxComboBox* pControl = (wxComboBox*) m_validatorWindow; + if (m_pInt) + { + *m_pInt = pControl->GetSelection() ; + return TRUE; + } + else if (m_pString) + { + *m_pString = pControl->SetStringSelection(* m_pString); + return TRUE; + } + } else if (m_validatorWindow->IsKindOf(CLASSINFO(wxStaticText)) ) { wxStaticText* pControl = (wxStaticText*) m_validatorWindow;