00001 /*! \file wx/docview/docviewref.h 00002 \brief Docview classes for document view, window and frame. 00003 00004 All classes for a document view framework are placed in here. Only the controlling 00005 a2dDocumentCommandProcessor is in doccom.h. 00006 00007 One or more documents are used to stor the application data, 00008 and views do display the data in the documents. ViewConnectors are used to couple views 00009 to the windows in the application GUI. Either a connector generates new frames and windows 00010 to achieve this or it used the existing frames or windows. 00011 00012 The view connectors is the key factor for having a separate document view frame work besides 00013 wxWidgets its own. wxDocview needed views which could live seperately from the GUI itself, 00014 and even the application itself. Special designed views like the a2dCanvasView is designed 00015 for displaying a2dCanvasDocument, and is placed in the library to be used where needed. 00016 The view connectors made this possible. 00017 00018 \author Julian Smart 00019 \author Klaas Holwerda 00020 \date Created 01/02/97 00021 00022 Copyright: (c) 00023 00024 Licence: wxWidgets licence 00025 00026 Modified by: Klaas Holwerda 00027 00028 RCS-ID: $Id: docviewref.h,v 1.67 2009/09/29 20:06:47 titato Exp $ 00029 */ 00030 00031 #ifndef _WX_DOCREFH__ 00032 #define _WX_DOCREFH__ 00033 00034 /*! 00035 \defgroup docview Objects in docview frame work. 00036 00037 Classes part of the docview framework. 00038 */ 00039 00040 /*! 00041 \defgroup docviewevents Events used in docview frame work. 00042 00043 \ingroup docview events 00044 */ 00045 00046 00047 #include "wx/defs.h" 00048 #include "wx/list.h" 00049 #include "wx/string.h" 00050 #include "wx/frame.h" 00051 #include "wx/filename.h" 00052 #include <wx/splitter.h> 00053 #include "wx/notebook.h" 00054 00055 00056 #if wxUSE_PRINTING_ARCHITECTURE 00057 #include "wx/print.h" 00058 #endif 00059 00060 #include <wx/listimpl.cpp> 00061 00062 #include "wx/general/genmod.h" 00063 00064 #if wxART2D_USE_CVGIO 00065 #include "wx/xmlparse/genxmlpars.h" 00066 #endif //wxART2D_USE_CVGIO 00067 00068 #if (defined(__WXMSW__) ) 00069 #ifdef A2DDOCVIEWMAKINGDLL 00070 #define A2DDOCVIEWDLLEXP WXEXPORT 00071 #define A2DDOCVIEWDLLEXP_DATA(type) WXEXPORT type 00072 #define A2DDOCVIEWDLLEXP_CTORFN 00073 #elif defined(WXDOCVIEW_USINGDLL) 00074 #define A2DDOCVIEWDLLEXP WXIMPORT 00075 #define A2DDOCVIEWDLLEXP_DATA(type) WXIMPORT type 00076 #define A2DDOCVIEWDLLEXP_CTORFN 00077 #else // not making nor using DLL 00078 #define A2DDOCVIEWDLLEXP 00079 #define A2DDOCVIEWDLLEXP_DATA(type) type 00080 #define A2DDOCVIEWDLLEXP_CTORFN 00081 #endif 00082 #else // (defined(__WXMSW__) )not making nor using DLL 00083 #define A2DDOCVIEWDLLEXP 00084 #define A2DDOCVIEWDLLEXP_DATA(type) type 00085 #define A2DDOCVIEWDLLEXP_CTORFN 00086 #endif //(defined(__WXMSW__) ) 00087 00088 class A2DDOCVIEWDLLEXP a2dDocument; 00089 class A2DDOCVIEWDLLEXP a2dView; 00090 class A2DDOCVIEWDLLEXP a2dDocumentTemplate; 00091 class A2DDOCVIEWDLLEXP a2dViewTemplate; 00092 00093 00094 #if (defined(__WXMSW__) && defined(WXUSINGDLL) ) 00095 template class A2DDOCVIEWDLLEXP a2dSmrtPtr<a2dDocumentTemplate>; 00096 template class A2DDOCVIEWDLLEXP a2dSmrtPtr<a2dViewTemplate>; 00097 template class A2DDOCVIEWDLLEXP a2dSmrtPtr<a2dView>; 00098 template class A2DDOCVIEWDLLEXP a2dSmrtPtr<a2dDocument>; 00099 template class A2DDOCVIEWDLLEXP a2dSmrtPtr<a2dIOHandler>; 00100 template class A2DDOCVIEWDLLEXP a2dSmrtPtr<a2dIOHandlerStrIn>; 00101 template class A2DDOCVIEWDLLEXP a2dSmrtPtr<a2dIOHandlerStrOut>; 00102 00103 template class A2DDOCVIEWDLLEXP std::allocator<class a2dSmrtPtr<class a2dDocument> >; 00104 template class A2DDOCVIEWDLLEXP std::allocator< std::_List_nod<class a2dSmrtPtr<class a2dDocument>, std::allocator<class a2dSmrtPtr<class a2dDocument> > >::_Node >; 00105 template class A2DDOCVIEWDLLEXP std::allocator< std::_List_ptr<class a2dSmrtPtr<class a2dDocument>, std::allocator<class a2dSmrtPtr<class a2dDocument> > >::_Nodeptr >; 00106 template class A2DDOCVIEWDLLEXP std::list<class a2dSmrtPtr<class a2dDocument> >; 00107 template class A2DDOCVIEWDLLEXP a2dlist<class a2dSmrtPtr<class a2dDocument> >; 00108 template class A2DDOCVIEWDLLEXP a2dSmrtPtrList<a2dDocument>; 00109 00110 template class A2DDOCVIEWDLLEXP std::allocator<class a2dSmrtPtr<class a2dView> >; 00111 template class A2DDOCVIEWDLLEXP std::allocator< std::_List_nod<class a2dSmrtPtr<class a2dView>, std::allocator<class a2dSmrtPtr<class a2dView> > >::_Node >; 00112 template class A2DDOCVIEWDLLEXP std::allocator< std::_List_ptr<class a2dSmrtPtr<class a2dView>, std::allocator<class a2dSmrtPtr<class a2dView> > >::_Nodeptr >; 00113 template class A2DDOCVIEWDLLEXP std::list<class a2dSmrtPtr<class a2dView> >; 00114 template class A2DDOCVIEWDLLEXP a2dlist<class a2dSmrtPtr<class a2dView> >; 00115 template class A2DDOCVIEWDLLEXP a2dSmrtPtrList<a2dView>; 00116 00117 template class A2DDOCVIEWDLLEXP std::allocator<class a2dSmrtPtr<class a2dDocumentTemplate> >; 00118 template class A2DDOCVIEWDLLEXP std::allocator< std::_List_nod<class a2dSmrtPtr<class a2dDocumentTemplate>, std::allocator<class a2dSmrtPtr<class a2dDocumentTemplate> > >::_Node >; 00119 template class A2DDOCVIEWDLLEXP std::allocator< std::_List_ptr<class a2dSmrtPtr<class a2dDocumentTemplate>, std::allocator<class a2dSmrtPtr<class a2dDocumentTemplate> > >::_Nodeptr >; 00120 template class A2DDOCVIEWDLLEXP std::list<class a2dSmrtPtr<class a2dDocumentTemplate> >; 00121 template class A2DDOCVIEWDLLEXP a2dlist<class a2dSmrtPtr<class a2dDocumentTemplate> >; 00122 template class A2DDOCVIEWDLLEXP a2dSmrtPtrList<a2dDocumentTemplate>; 00123 00124 template class A2DDOCVIEWDLLEXP std::allocator<class a2dSmrtPtr<class a2dViewTemplate> >; 00125 template class A2DDOCVIEWDLLEXP std::allocator< std::_List_nod<class a2dSmrtPtr<class a2dViewTemplate>, std::allocator<class a2dSmrtPtr<class a2dViewTemplate> > >::_Node >; 00126 template class A2DDOCVIEWDLLEXP std::allocator< std::_List_ptr<class a2dSmrtPtr<class a2dViewTemplate>, std::allocator<class a2dSmrtPtr<class a2dViewTemplate> > >::_Nodeptr >; 00127 template class A2DDOCVIEWDLLEXP std::list<class a2dSmrtPtr<class a2dViewTemplate> >; 00128 template class A2DDOCVIEWDLLEXP a2dlist<class a2dSmrtPtr<class a2dViewTemplate> >; 00129 template class A2DDOCVIEWDLLEXP a2dSmrtPtrList<a2dViewTemplate>; 00130 #endif 00131 00132 //! document smart pointer 00133 typedef a2dSmrtPtr<a2dDocument> a2dDocumentPtr; 00134 //! view smart pointer 00135 typedef a2dSmrtPtr<a2dView> a2dViewPtr; 00136 //! a2dViewTemplate smart pointer 00137 typedef a2dSmrtPtr<a2dViewTemplate> a2dViewTemplatePtr; 00138 //! a2dDocumentTemplate smart pointer 00139 typedef a2dSmrtPtr<a2dDocumentTemplate> a2dDocumentTemplatePtr; 00140 00141 //! list of documents 00142 typedef a2dSmrtPtrList<a2dDocument> a2dDocumentList; 00143 //! list of views 00144 typedef a2dSmrtPtrList<a2dView> a2dViewList; 00145 //! list of document templates 00146 typedef a2dSmrtPtrList<a2dDocumentTemplate> a2dDocumentTemplateList; 00147 //! list of view templates 00148 typedef a2dSmrtPtrList<a2dViewTemplate> a2dViewTemplateList; 00149 00150 //! iterator for list of ... 00151 typedef a2dDocumentList::iterator a2dDocumentListIter; 00152 00153 //! iterator for list of ... 00154 typedef a2dViewList::iterator a2dViewListIter; 00155 00156 //! iterator for list of ... 00157 typedef a2dDocumentTemplateList::iterator a2dDocumentTemplateListIter; 00158 00159 //! iterator for list of ... 00160 typedef a2dViewTemplateList::iterator a2dViewTemplateListIter; 00161 00162 #if wxUSE_STD_IOSTREAM 00163 #include "wx/ioswrap.h" 00164 #if wxUSE_IOSTREAMH 00165 #include <fstream.h> 00166 #else 00167 #include <fstream> 00168 #endif 00169 #else 00170 #include "wx/wfstream.h" 00171 #endif 00172 00173 //! Document manager flags 00174 enum a2dDocumentFlag 00175 { 00176 a2dREFDOC_NON = 0x00000000, /*!< No flag */ 00177 a2dREFDOC_NEW = 0x00000001, /*!< create a New empty document */ 00178 a2dREFDOC_SILENT = 0x00000002, /*!< For adding a document by reading from file given a path as input */ 00179 a2dREFDOC_INIT = 0x00000004, /*!< to initialize new documents when added to the framework */ 00180 a2dREFDOC_ALL = 0xFFFFFFFF, /*!< For Xor ing and all set */ 00181 a2dDEFAULT_DOCUMENT_FLAGS = a2dREFDOC_NON /*!< */ 00182 }; 00183 00184 00185 //! mask flags for a2dDocument::UpdateAllViews() 00186 enum a2dViewUpdateFlags 00187 { 00188 a2dVIEW_UPDATE_ALL = 0x0004, /*!< total area displayed by drawer is added as pending to arealist 00189 (removes all other pending areas) */ 00190 }; 00191 00192 //! mask of flags for a2dDocumentFlag 00193 /*! 00194 \ingroup docview 00195 */ 00196 typedef unsigned int a2dDocumentFlagMask ; 00197 00198 //! mask of flags for a2dTemplateFlag 00199 /*! 00200 \ingroup docview 00201 */ 00202 typedef unsigned int a2dTemplateFlagMask; 00203 00204 //! Template flags 00205 /*! 00206 \ingroup docview 00207 00208 Used to test if a template is visble and for what purpose it is should be. 00209 Mostly used to select appropriate templates from a list of templates. 00210 The a2dDocumentTemplate and the a2dViewTemplate are both using this flags mask. 00211 */ 00212 class a2dTemplateFlag 00213 { 00214 public: 00215 static const a2dTemplateFlagMask NON; /*!< no flags set */ 00216 static const a2dTemplateFlagMask VISIBLE; /*!< is the template visible */ 00217 static const a2dTemplateFlagMask MARK; /*!< for general use to temporary mark a template*/ 00218 static const a2dTemplateFlagMask LOAD; /*!< a template for loading files*/ 00219 static const a2dTemplateFlagMask SAVE; /*!< a template for saving files*/ 00220 static const a2dTemplateFlagMask IMPORTING; /*!< a template for importing files*/ 00221 static const a2dTemplateFlagMask EXPORTING; /*!< a template for exporting files*/ 00222 static const a2dTemplateFlagMask ALL; /*!< all flags set */ 00223 static const a2dTemplateFlagMask DEFAULT; /*!< default */ 00224 static const a2dTemplateFlagMask LOAD_IMPORT; /*!< for load + import */ 00225 static const a2dTemplateFlagMask SAVE_EXPORT; /*!< for save + export */ 00226 00227 00228 a2dTemplateFlag( a2dTemplateFlagMask newmask = NON ); 00229 00230 //! Check if given mask matches (flags in mask, or at least set) 00231 bool CheckMask( a2dTemplateFlagMask mask ); 00232 00233 void SetFlags( a2dTemplateFlagMask which ); 00234 00235 a2dTemplateFlagMask GetFlags() const; 00236 00237 bool GetFlag( a2dTemplateFlagMask which ) const; 00238 00239 //!template is visible 00240 bool m_visible:1; 00241 //!template is marked 00242 bool m_mark:1; 00243 //!template is for loading documents 00244 bool m_load:1; 00245 //!template is for saving documents 00246 bool m_save:1; 00247 //!template is for importing documents 00248 bool m_import:1; 00249 //!template is for exporting documents 00250 bool m_export:1; 00251 }; 00252 00253 #include <wx/listimpl.cpp> 00254 00255 /********************************************** 00256 New events Document and View events. 00257 **********************************************/ 00258 BEGIN_DECLARE_EVENT_TYPES() 00259 //!see a2dDocumentEvent \ingroup eventid 00260 DECLARE_EXPORTED_EVENT_TYPE( A2DDOCVIEWDLLEXP, wxEVT_SAVE_DOCUMENT, 1 ) 00261 //!see a2dDocumentEvent \ingroup eventid 00262 DECLARE_EXPORTED_EVENT_TYPE( A2DDOCVIEWDLLEXP, wxEVT_SAVEAS_DOCUMENT, 1 ) 00263 //!see a2dDocumentEvent \ingroup eventid 00264 DECLARE_EXPORTED_EVENT_TYPE( A2DDOCVIEWDLLEXP, wxEVT_IMPORT_DOCUMENT, 1 ) 00265 //!see a2dDocumentEvent \ingroup eventid 00266 DECLARE_EXPORTED_EVENT_TYPE( A2DDOCVIEWDLLEXP, wxEVT_EXPORT_DOCUMENT, 1 ) 00267 //!see a2dDocumentEvent \ingroup eventid 00268 DECLARE_EXPORTED_EVENT_TYPE( A2DDOCVIEWDLLEXP, wxEVT_CLOSE_DOCUMENT, 1 ) 00269 //!see a2dDocumentEvent \ingroup eventid 00270 DECLARE_EXPORTED_EVENT_TYPE( A2DDOCVIEWDLLEXP, wxEVT_OPEN_DOCUMENT, 1 ) 00271 //!see a2dDocumentEvent \ingroup eventid 00272 DECLARE_EXPORTED_EVENT_TYPE( A2DDOCVIEWDLLEXP, wxEVT_NEW_DOCUMENT, 1 ) 00273 //!see a2dDocumentEvent \ingroup eventid 00274 DECLARE_EXPORTED_EVENT_TYPE( A2DDOCVIEWDLLEXP, wxEVT_CREATE_DOCUMENT, 1 ) 00275 //!see a2dDocumentEvent \ingroup eventid 00276 DECLARE_EXPORTED_EVENT_TYPE( A2DDOCVIEWDLLEXP, wxEVT_ADD_VIEW, 1 ) 00277 //!see a2dDocumentEvent \ingroup eventid 00278 DECLARE_EXPORTED_EVENT_TYPE( A2DDOCVIEWDLLEXP, wxEVT_REMOVE_VIEW, 1 ) 00279 //!see a2dDocumentEvent \ingroup eventid 00280 DECLARE_EXPORTED_EVENT_TYPE( A2DDOCVIEWDLLEXP, wxEVT_DISCONNECT_ALLVIEWS, 1 ) 00281 //!see a2dDocumentEvent \ingroup eventid 00282 DECLARE_EXPORTED_EVENT_TYPE( A2DDOCVIEWDLLEXP, wxEVT_UPDATE_VIEWS, 1 ) 00283 //!see a2dDocumentEvent \ingroup eventid 00284 DECLARE_EXPORTED_EVENT_TYPE( A2DDOCVIEWDLLEXP, wxEVT_ENABLE_VIEWS, 1 ) 00285 //!see a2dDocumentEvent \ingroup eventid 00286 DECLARE_EXPORTED_EVENT_TYPE( A2DDOCVIEWDLLEXP, wxEVT_REPORT_VIEWS, 1 ) 00287 //!see a2dDocumentEvent \ingroup eventid 00288 DECLARE_EXPORTED_EVENT_TYPE( A2DDOCVIEWDLLEXP, wxEVT_CHANGEDFILENAME_DOCUMENT, 1 ) 00289 //!see a2dDocumentEvent \ingroup eventid 00290 DECLARE_EXPORTED_EVENT_TYPE( A2DDOCVIEWDLLEXP, wxEVT_CHANGEDTITLE_DOCUMENT, 1 ) 00291 //!see a2dDocumentEvent \ingroup eventid 00292 DECLARE_EXPORTED_EVENT_TYPE( A2DDOCVIEWDLLEXP, wxEVT_CHANGEDMODIFY_DOCUMENT, 1 ) 00293 //!see a2dDocumentEvent \ingroup eventid 00294 DECLARE_EXPORTED_EVENT_TYPE( A2DDOCVIEWDLLEXP, wxEVT_POST_LOAD_DOCUMENT, 1 ) 00295 00296 //!see a2dViewEvent \ingroup eventid 00297 DECLARE_EXPORTED_EVENT_TYPE( A2DDOCVIEWDLLEXP, wxEVT_ACTIVATE_VIEW, 1 ) 00298 //!see a2dViewEvent \ingroup eventid 00299 DECLARE_EXPORTED_EVENT_TYPE( A2DDOCVIEWDLLEXP, wxEVT_ACTIVATE_VIEW_SENT_FROM_CHILD, 1 ) 00300 //!see a2dViewEvent \ingroup eventid 00301 DECLARE_EXPORTED_EVENT_TYPE( A2DDOCVIEWDLLEXP, wxEVT_CLOSE_VIEW, 1 ) 00302 //!see a2dViewEvent \ingroup eventid 00303 DECLARE_EXPORTED_EVENT_TYPE( A2DDOCVIEWDLLEXP, wxEVT_CREATE_VIEW, 1 ) 00304 //!see a2dViewEvent \ingroup eventid 00305 DECLARE_EXPORTED_EVENT_TYPE( A2DDOCVIEWDLLEXP, wxEVT_SET_DOCUMENT, 1 ) 00306 //!see a2dViewEvent \ingroup eventid 00307 DECLARE_EXPORTED_EVENT_TYPE( A2DDOCVIEWDLLEXP, wxEVT_ENABLE_VIEW, 1 ) 00308 //!see a2dViewEvent \ingroup eventid 00309 DECLARE_EXPORTED_EVENT_TYPE( A2DDOCVIEWDLLEXP, wxEVT_CHANGEDFILENAME_VIEW, 1 ) 00310 00311 //! see a2dTemplateEvent \ingroup eventid 00312 DECLARE_EXPORTED_EVENT_TYPE( A2DDOCVIEWDLLEXP, wxEVT_PRE_ADD_DOCUMENT, 1 ) 00313 //! see a2dTemplateEvent \ingroup eventid 00314 DECLARE_EXPORTED_EVENT_TYPE( A2DDOCVIEWDLLEXP, wxEVT_POST_CREATE_DOCUMENT, 1 ) 00315 //! see a2dTemplateEvent \ingroup eventid 00316 DECLARE_EXPORTED_EVENT_TYPE( A2DDOCVIEWDLLEXP, wxEVT_POST_CREATE_VIEW, 1 ) 00317 //!see a2dTemplateEvent \ingroup eventid 00318 DECLARE_EXPORTED_EVENT_TYPE( A2DDOCVIEWDLLEXP, wxEVT_DISCONNECT_VIEW, 1 ) 00319 00320 END_DECLARE_EVENT_TYPES() 00321 00322 00323 #include <map> 00324 class A2DDOCVIEWDLLEXP a2dMenuIdItem; 00325 typedef std::map< wxString, a2dMenuIdItem* > a2dMenuIdItemMap; 00326 00327 //! store a menu Id generated by XRCID( menuIdString ) plus a menustring and helpstring 00328 /*! 00329 The class instance can be used to add directly to a menu 00330 */ 00331 class A2DDOCVIEWDLLEXP a2dMenuIdItem : public wxObject 00332 { 00333 public: 00334 00335 DECLARE_CLASS(a2dMenuIdItem) 00336 00337 //! constant to defined non valid id. 00338 static const a2dMenuIdItem sm_noCmdMenuId; 00339 00340 //! constructor 00341 a2dMenuIdItem( const wxString& menuIdName = wxEmptyString, 00342 const wxString& text = wxEmptyString, 00343 const wxString& help = wxEmptyString, wxItemKind kind = wxITEM_NORMAL ); 00344 //! destructor 00345 virtual ~a2dMenuIdItem() {}; 00346 00347 // set id 00348 void SetId(int itemid) { m_id = itemid; } 00349 00350 // get id 00351 int GetId() const { return m_id; } 00352 00353 // the item's text (or name) 00354 // 00355 // NB: the item's text includes the accelerators and mnemonics info (if 00356 // any), i.e. it may contain '&' or '_' or "\t..." and thus is 00357 // different from the item's label which only contains the text shown 00358 // in the menu 00359 virtual void SetText(const wxString& str); 00360 00361 //! get label text 00362 wxString GetLabel() const { return GetLabelText(m_text); } 00363 //! get plain text for menu 00364 const wxString& GetText() const { return m_text; } 00365 00366 //! get the label from text (implemented in platform-specific code) 00367 static wxString GetLabelText(const wxString& text); 00368 00369 //! what kind of menu item we are 00370 wxItemKind GetKind() const { return m_kind; } 00371 void SetKind(wxItemKind kind) { m_kind = kind; } 00372 00373 //! set if menu is checkable 00374 virtual void SetCheckable(bool checkable) { m_kind = checkable ? wxITEM_CHECK : wxITEM_NORMAL; } 00375 00376 //! get if menu is checkable 00377 bool IsCheckable() const 00378 { return m_kind == wxITEM_CHECK || m_kind == wxITEM_RADIO; } 00379 00380 //! initial state of menu 00381 virtual void Enable(bool enable = true) { m_isEnabled = enable; } 00382 //! initial state of menu 00383 virtual bool IsEnabled() const { return m_isEnabled; } 00384 00385 //! set initial check state of menu 00386 virtual void Check(bool check = true) { m_isChecked = check; } 00387 //! get initial check state of menu 00388 virtual bool IsChecked() const { return m_isChecked; } 00389 //! toggel initial check state of menu 00390 void Toggle() { Check(!m_isChecked); } 00391 00392 // set help string (displayed in the status bar by default) 00393 void SetHelp(const wxString& str); 00394 // get help string (displayed in the status bar by default) 00395 const wxString& GetHelp() const { return m_help; } 00396 00397 void SetBitmaps(const wxBitmap& bmpChecked, 00398 const wxBitmap& bmpUnchecked = wxNullBitmap); 00399 void SetBitmap(const wxBitmap& bmp) { SetBitmaps(bmp); } 00400 const wxBitmap& GetBitmap(bool checked = true) const 00401 { return checked ? m_bmpChecked : m_bmpUnchecked; } 00402 00403 void SetDisabledBitmap( const wxBitmap& bmpDisabled ) 00404 { m_bmpDisabled = bmpDisabled; } 00405 const wxBitmap& GetDisabledBitmap() const 00406 { return m_bmpDisabled; } 00407 00408 #if wxUSE_ACCEL 00409 // get our accelerator or NULL (caller must delete the pointer) 00410 virtual wxAcceleratorEntry *GetAccel() const; 00411 00412 // set the accel for this item - this may also be done indirectly with 00413 // SetText() 00414 virtual void SetAccel(wxAcceleratorEntry *accel); 00415 #endif // wxUSE_ACCEL 00416 00417 //! name of the menu coupled to unique id 00418 wxString GetIdName() const { return m_name; } 00419 00420 //! search Id given the name of the command 00421 static const a2dMenuIdItem& GetItemByName( const wxString& menuIdName ); 00422 00423 //! stored map of names to get id 00424 static a2dMenuIdItemMap& GetHashMap(); 00425 00426 //! initialize bitmaps associated with found a2dMenuIdItem's from files 00427 static void InitializeBitmaps(); 00428 00429 //! Are the bitmaps for button bar etc. initlialized? 00430 static bool GetInitialized() { return m_bitmapinitialized; } 00431 00432 private: 00433 00434 int m_id; // numeric id of the item >= 0 or wxID_ANY or wxID_SEPARATOR 00435 wxString m_text, // label of the item 00436 m_help; // the help string for the item 00437 wxItemKind m_kind; // separator/normal/check/radio item? 00438 bool m_isChecked; // is checked? 00439 bool m_isEnabled; // is enabled? 00440 00441 // the bitmaps (may be invalid, then they're not used) 00442 wxBitmap m_bmpChecked, 00443 m_bmpUnchecked, 00444 m_bmpDisabled; 00445 00446 //! name of menu id 00447 wxString m_name; 00448 00449 // were bitmaps already initialized? 00450 static bool m_bitmapinitialized; 00451 }; 00452 00453 //! a2dView close event 00454 /*! 00455 Sent when a view needs to be closed. 00456 The event can be vetod. 00457 The event travels up to the parent window, when it is sent to a wxWindow and not processed or skipped. 00458 Therefore if the event is sent to the Display Window (m_display) of a view, the event can eventually 00459 arrive in a wxFrame class containing the wxWindow. 00460 At any place in this hierachy of wxWindows , one will take care of detaching the view from the windows. 00461 00462 When via the a2dDocumentCommandProcessor a view is closed, one is able to also cleanup wxWindow and wxFrames 00463 which use the particular a2dView, this is via a2dDocument. 00464 00465 The a2dView sents this event to the display window, and this window should might directly sent it 00466 back to the a2dView. In case it does, this is not a problem, since the a2dView disables 00467 itself while sending those events. 00468 00469 The event Object is a a2dView. 00470 The type of the event is ::wxEVT_CLOSE_VIEW, and only generated in a2dView::Close(). 00471 The event is first sent to the a2dDocument of the a2dView. 00472 If not vetod, it is next sent to the m_display of the a2dView. 00473 And if not vetod, it will be sent to the a2dView itself. 00474 If not vetod there, the a2dView will be removed from the a2dDocument 00475 its view list, and released. 00476 00477 00478 \ingroup docview docviewevents events 00479 00480 */ 00481 class A2DDOCVIEWDLLEXP a2dCloseViewEvent : public a2dEvent 00482 { 00483 DECLARE_CLASS(a2dCloseViewEvent) 00484 00485 public: 00486 00487 //! Constructor for view event of type ::wxEVT_CLOSE_VIEW 00488 a2dCloseViewEvent(int id = 0) 00489 : a2dEvent( id, wxEVT_CLOSE_VIEW ), 00490 m_veto(false), // should be false by default 00491 m_canVeto(true) 00492 { 00493 m_isCommandEvent = true; //let it go up to parent object in case of a wxWindow. 00494 } 00495 00496 //! constructor 00497 a2dCloseViewEvent(const a2dCloseViewEvent & event) 00498 : a2dEvent(event), 00499 m_veto(event.m_veto), 00500 m_canVeto(event.m_canVeto) 00501 { 00502 } 00503 00504 //! clone the event. 00505 virtual wxEvent *Clone() const { return new a2dCloseViewEvent(*this); } 00506 00507 //! use to veto event when the closing of the view needs to be refused in a handler. 00508 void Veto(bool veto = true) 00509 { 00510 // GetVeto() will return false anyhow... 00511 wxCHECK_RET( m_canVeto, 00512 wxT("call to Veto() ignored (can't veto this event)") ); 00513 00514 m_veto = veto; 00515 } 00516 00517 //! If the event can not be vetod this is set to false. 00518 void SetCanVeto(bool canVeto) { m_canVeto = canVeto; } 00519 00520 //! If the event can be vetod this is set 00521 bool CanVeto() const { return m_canVeto; } 00522 00523 //! If the event can be vetod this return true 00524 bool GetVeto() const { return m_canVeto && m_veto; } 00525 00526 protected: 00527 00528 //! veto flags. 00529 bool m_veto, m_canVeto; 00530 00531 }; 00532 00533 00534 //! a2dView event, to report events in the a2dView class 00535 /*! 00536 The event Object is a a2dView. 00537 00538 The event travels up to the parent window, when it is sent to a wxWindow and not processed or skipped. 00539 Therefore if the event is sent to the Display Window (m_display) of a view, the event can eventually 00540 arive in a wxFrame class containing the wxWindow. 00541 00542 If a2dView sents this event to the display window, this window might directly sent it 00543 back to the a2dView. In case it does, this is not a problem, since the a2dView disables 00544 itself while sending those events upwards. 00545 00546 \ingroup docview docviewevents events 00547 00548 */ 00549 class A2DDOCVIEWDLLEXP a2dViewEvent : public a2dEvent 00550 { 00551 DECLARE_CLASS(a2dViewEvent) 00552 00553 public: 00554 00555 //! for event types 00556 /*! 00557 - ::wxEVT_SET_DOCUMENT 00558 Is sent by the a2dView when a wxDocument is set for it. 00559 Intercepts this to initialize your ( new or existing ) view for that document. 00560 00561 - ::wxEVT_CREATE_VIEW 00562 Is sent by the a2dViewTemplate to the a2dView when the view 00563 was just created. But after the document was set. 00564 Intercepts this to initialize your new view. 00565 */ 00566 a2dViewEvent( wxEventType type, a2dDocumentFlagMask flags, int id ) 00567 : a2dEvent( id, type ) 00568 { 00569 m_bAllow = true; 00570 m_isCommandEvent = true; //let it go up to parent object in case of a wxWindow. 00571 m_flags = flags; 00572 m_activate = false; 00573 m_enable = false; 00574 } 00575 00576 //! for event types 00577 /*! 00578 - ::wxEVT_ENABLE_VIEW 00579 Sent to a2dView and DisplayWindow from a2dView::Enable() or from the a2dDocument. 00580 The last functions is called from a2dView::SetDisplayWindow( wxWindow* display ) 00581 to disable the old display window, and enable the new display window. 00582 00583 - ::wxEVT_ACTIVATE_VIEW 00584 sent from a2dView::Activate() to the event distributer. 00585 ( intercepted at least by a2dDocumentCommandProcessor to set the view as the active 00586 view within the a2dDocumentCommandProcessor ) 00587 Only when the currently active a2dView within the docmanager is different 00588 from this one, it will FIRST sent a second ::wxEVT_ACTIVATE_VIEW to the old active view 00589 to disable it. This event is ignored in a2dDocumentCommandProcessor itself. 00590 The ::wxEVT_ACTIVATE_VIEW is sent to the a2dView itself to disable it. 00591 The ::wxEVT_ACTIVATE_VIEW is sent from the view when the view is set active. 00592 00593 - ::wxEVT_ACTIVATE_VIEW_SENT_FROM_CHILD 00594 event sent from view and its display up the parent chain. The main use is to set in a2dDocumentFrame 00595 the current view, so events from the frame arrive (via a window) at the (new) view when sent down there. 00596 00597 */ 00598 a2dViewEvent( wxEventType type, bool value, int id ) 00599 : a2dEvent( id, type ) 00600 { 00601 m_bAllow = true; 00602 m_isCommandEvent = true; //let it go up to parent object in case of a wxWindow. 00603 m_flags = a2dREFDOC_NON; 00604 m_activate = false; 00605 m_enable = false; 00606 if ( type == wxEVT_ACTIVATE_VIEW || type == wxEVT_ACTIVATE_VIEW_SENT_FROM_CHILD ) 00607 { 00608 m_activate = value; 00609 } 00610 else if ( type == wxEVT_ENABLE_VIEW ) 00611 { 00612 m_enable = value; 00613 } 00614 } 00615 00616 //! constructor 00617 a2dViewEvent( const a2dViewEvent & event ) 00618 : a2dEvent(event) 00619 { 00620 m_bAllow = event.m_bAllow; 00621 m_flags = event.m_flags; 00622 m_activate = event.m_activate; 00623 m_enable = event.m_enable; 00624 } 00625 00626 //! veto the operation (usually it's allowed by default) 00627 void Veto() { m_bAllow = false; } 00628 00629 //! allow the operation if it was disabled by default 00630 void Allow() { m_bAllow = true; } 00631 00632 //! for implementation code only, testing result of handler: is the operation allowed? 00633 bool IsAllowed() const { return m_bAllow; } 00634 00635 //! clone the event 00636 virtual wxEvent *Clone() const { return new a2dViewEvent(*this); } 00637 00638 //! for following event types, get document flags of the event. 00639 /*! 00640 - ::wxEVT_SET_DOCUMENT 00641 - ::wxEVT_CREATE_VIEW 00642 */ 00643 a2dDocumentFlagMask GetFlags() { return m_flags; } 00644 00645 //! when ::wxEVT_ACTIVATE_VIEW get activation value of the event 00646 bool GetActive() { return m_activate; } 00647 00648 //! when ::wxEVT_ENABLE_VIEW get enable value of the event 00649 bool GetEnable() { return m_enable; } 00650 00651 private: 00652 00653 //! to allow or not this event, initiated with true. 00654 bool m_bAllow; 00655 00656 //! document flags ( interesting after a ::wxEVT_CREATE_VIEW event ) 00657 a2dDocumentFlagMask m_flags; 00658 00659 //! activate value ( interesting after a ::wxEVT_ACTIVATE_VIEW event ) 00660 bool m_activate; 00661 00662 //! activate value ( interesting after a ::wxEVT_ENABLE_VIEW event ) 00663 bool m_enable; 00664 }; 00665 00666 00667 //! sent to document before closing 00668 /*! 00669 The event Object is a a2dDocument. 00670 The type of the event is ::wxEVT_CLOSE_DOCUMENT. 00671 This event is sent form bool a2dDocument::Close( bool force ) to the 00672 a2dDocument itself. 00673 00674 The default handler is a2dDocument::OnCloseDocument(). 00675 Which, if not vetod, disconnects ( and maybe closes ) the views on the document using a2dDocument::DisconnectAllViews(). 00676 This will generate a ::wxEVT_DISCONNECT_ALLVIEWS event for the a2dDocument, and 00677 the same event is sent to the a2dEventDistributer for distribution. 00678 Views should either close or detach themselfs from the document. 00679 00680 \ingroup docview docviewevents events 00681 00682 */ 00683 class A2DDOCVIEWDLLEXP a2dCloseDocumentEvent : public wxCloseEvent 00684 { 00685 public: 00686 00687 //! constructor 00688 a2dCloseDocumentEvent(int id = 0) 00689 : wxCloseEvent( wxEVT_CLOSE_DOCUMENT, id ) 00690 { 00691 } 00692 00693 //! constructor 00694 a2dCloseDocumentEvent(const a2dCloseDocumentEvent & event) 00695 : wxCloseEvent(event) 00696 { 00697 } 00698 00699 //! clone the event 00700 virtual wxEvent *Clone() const { return new a2dCloseDocumentEvent(*this); } 00701 00702 private: 00703 DECLARE_CLASS(a2dCloseDocumentEvent) 00704 00705 }; 00706 00707 //! used to report a2dDocument events 00708 /*! 00709 The event Object is a a2dDocument. 00710 00711 a2dDocument does often get this event from the a2dDocumentCommandProcessor. 00712 00713 \ingroup docview docviewevents events 00714 00715 */ 00716 class A2DDOCVIEWDLLEXP a2dDocumentEvent : public a2dEvent 00717 { 00718 DECLARE_CLASS(a2dDocumentEvent) 00719 00720 public: 00721 00722 00723 //! for event types 00724 /*! 00725 - ::wxEVT_SAVE_DOCUMENT 00726 Sent from bool a2dDocument::Save() 00727 00728 - ::wxEVT_SAVEAS_DOCUMENT 00729 Sent from bool a2dDocument::SaveAs() 00730 00731 - ::wxEVT_CREATE_DOCUMENT 00732 Sent from a2dDocumentTemplate::CreateDocument() to a2dDocument() just after 00733 it created a new document. 00734 00735 - ::wxEVT_NEW_DOCUMENT 00736 Sent from bool a2dDocumentCommandProcessor::CreateDocument() when creating a new document 00737 from a a2dDocumentTemplate. 00738 00739 - ::wxEVT_OPEN_DOCUMENT 00740 Sent from bool a2dDocumentCommandProcessor::CreateDocument() after creating a new document 00741 from a a2dDocumentTemplate, which needs to have its contents read from a file. 00742 00743 - ::wxEVT_DISCONNECT_ALLVIEWS 00744 Sent from bool a2dDocument::DisconnectAllViews() 00745 00746 - ::wxEVT_CHANGEDFILENAME_DOCUMENT 00747 Sent indirectly to a2dDocumentCommandProcessor from document after a change in file name by DistributeEvent() 00748 00749 - ::wxEVT_CHANGEDTITLE_DOCUMENT 00750 Sent indirectly to a2dDocumentCommandProcessor from document after a change in title by DistributeEvent() 00751 00752 */ 00753 a2dDocumentEvent( wxEventType type, const wxFileName& filename, a2dDocumentFlagMask flags = a2dREFDOC_NON, int id = 0 ) 00754 : a2dEvent( id, type ) 00755 { 00756 m_bAllow = true; 00757 m_error = a2dError_NoError; 00758 m_filename = filename; 00759 m_flags = flags; 00760 m_view = NULL; 00761 m_doctemplate = NULL; 00762 m_updateHint = 0; 00763 m_objectHint = NULL; 00764 m_reportViews = NULL; 00765 } 00766 00767 00768 //! for event types 00769 /*! 00770 - ::wxEVT_IMPORT_DOCUMENT 00771 Sent from a2dDocument::Import( a2dDocumentTemplate* doctemplate ) 00772 Intercept this event to actually implement the import. 00773 00774 - ::wxEVT_EXPORT_DOCUMENT 00775 Sent from a2dDocument::Export( a2dDocumentTemplate* doctemplate ) 00776 Intercept this event to actually implement the export. 00777 00778 The a2dIOHandlers of the choosen template, should/can be used for 00779 importing/exporting a file. 00780 This is what the default handlers a2dDocument::OnExportDocument 00781 and a2dDocument::OnImportDocument do use. 00782 00783 \param type ::wxEVT_IMPORT_DOCUMENT or ::wxEVT_EXPORT_DOCUMENT 00784 \param doctemplate template choosen for importing or exporting. 00785 \param filename if not empty the file name of the document 00786 \param flags docuemnt flags 00787 \param id event id 00788 00789 */ 00790 a2dDocumentEvent( wxEventType type, a2dDocumentTemplate* doctemplate, const wxFileName& filename = wxFileName( wxT("") ), a2dDocumentFlagMask flags = a2dREFDOC_NON, int id = 0 ) 00791 : a2dEvent( id, type ) 00792 { 00793 m_bAllow = true; 00794 m_error = a2dError_NoError; 00795 m_filename = filename; 00796 m_flags = flags; 00797 m_view = NULL; 00798 m_doctemplate = doctemplate; 00799 m_updateHint = 0; 00800 m_objectHint = NULL; 00801 m_reportViews = NULL; 00802 } 00803 00804 //! for event types 00805 /*! 00806 ::wxEVT_REPORT_VIEWS 00807 Sent from a2dDocument to a2dDocumentmmandProcessor, which will distribute the event 00808 to a2dView's. a2dView will add itself to the reportlist of the event, but only 00809 when this document is indeed used by the a2dView. 00810 */ 00811 a2dDocumentEvent( wxEventType WXUNUSED(type), a2dViewList* reportlist ) 00812 : a2dEvent( 0, wxEVT_REPORT_VIEWS ) 00813 { 00814 m_bAllow = true; 00815 m_error = a2dError_NoError; 00816 m_filename = wxFileName(wxT("")); 00817 m_flags = 0; 00818 m_view = NULL; 00819 m_doctemplate = NULL; 00820 m_updateHint = 0; 00821 m_objectHint = NULL; 00822 m_reportViews = reportlist; 00823 } 00824 00825 //! for event types 00826 /*! 00827 Following event types: 00828 00829 - ::wxEVT_ADD_VIEW 00830 Sent to a2dDocument when a view is added to it. 00831 00832 - ::wxEVT_REMOVE_VIEW 00833 Sent to a2dDocument when a view is removed from it. 00834 00835 - ::wxEVT_UPDATE_VIEWS ( view != NULL is not changed ) 00836 Sent from a2dDocument::UpdateAllViews() 00837 00838 - ::wxEVT_ENABLE_VIEWS ( view != NULL is not changed ) 00839 Sent from a2dDocument::EnableAllViews() 00840 */ 00841 a2dDocumentEvent( wxEventType type, a2dView* view = NULL, bool enable = true, int id = 0 ) 00842 : a2dEvent( id, type ) 00843 { 00844 m_bAllow = true; 00845 m_error = a2dError_NoError; 00846 m_view = view; 00847 m_filename = wxFileName(wxT("")); 00848 m_flags = a2dREFDOC_NON; 00849 m_doctemplate = NULL; 00850 m_updateHint = 0; 00851 m_objectHint = NULL; 00852 m_reportViews = NULL; 00853 m_enable = enable; 00854 } 00855 00856 //! constructor 00857 a2dDocumentEvent(const a2dDocumentEvent & event) 00858 : a2dEvent( event ) 00859 { 00860 m_bAllow = event.m_bAllow; 00861 m_error = event.m_error; 00862 m_filename = event.m_filename; 00863 m_flags = event.m_flags; 00864 m_view = event.m_view; 00865 m_doctemplate = event.m_doctemplate; 00866 m_updateHint = event.m_updateHint; 00867 m_objectHint = event.m_objectHint; 00868 m_reportViews = event.m_reportViews; 00869 m_enable = event.m_enable; 00870 } 00871 00872 //! veto the operation (usually it's allowed by default) 00873 void Veto() { m_bAllow = false; } 00874 00875 //! allow the operation if it was disabled by default 00876 void Allow() { m_bAllow = true; } 00877 00878 //! for implementation code only: is the operation allowed? 00879 bool IsAllowed() const { return m_bAllow; } 00880 00881 //! set filename of file to open, before sending the event. 00882 void SetFileName( const wxFileName& filename ) { m_filename = filename; } 00883 00884 //! get filename of file to open 00885 wxFileName& GetFileName() { return m_filename; } 00886 00887 virtual wxEvent *Clone() const { return new a2dDocumentEvent(*this); } 00888 00889 //! gives the a2dDocumentFlagMask in case of event types concerning a document. 00890 a2dDocumentFlagMask GetFlags() { return m_flags; } 00891 00892 //! Gives the a2dView in case of event types concerning a view. 00893 /*! 00894 Used with ::wxEVT_ADD_VIEW and ::wxEVT_REMOVE_VIEW 00895 */ 00896 a2dView* GetView() { return m_view; } 00897 00898 //! Get the template choosen to import / export. 00899 /*! 00900 Used with ::wxEVT_IMPORT_DOCUMENT and ::wxEVT_EXPORT_DOCUMENT. 00901 */ 00902 a2dDocumentTemplate* GetDocumentTemplate() { return m_doctemplate; } 00903 00904 void SetUpdateHint( unsigned int updateHint ) { m_updateHint = updateHint; } 00905 00906 unsigned int GetUpdateHint() { return m_updateHint; } 00907 00908 void SetUpdateObject( wxObject* objectHint ) { m_objectHint = objectHint; } 00909 00910 wxObject* GetUpdateObject() { return m_objectHint; } 00911 00912 a2dViewList* GetReportList() { return m_reportViews; } 00913 00914 //! when ::wxEVT_ENABLE_VIEWS get enable value of the event 00915 bool GetEnable() { return m_enable; } 00916 00917 //! in case of errors when sending an event, this is to know the reason of failure 00918 a2dError GetError() { return m_error; } 00919 00920 //! in case of errors when sending an event, this can be set to tell the reason of failure 00921 void SetError( a2dError error ) { m_error = error; } 00922 00923 private: 00924 00925 //! list of reported views 00926 a2dViewList* m_reportViews; 00927 00928 //! to allow or not this event, initiated with true. 00929 bool m_bAllow; 00930 00931 //! ::wxEVT_ENABLE_VIEWS ( to enable or diable views ) 00932 bool m_enable; 00933 00934 //! document flags ( interesting after a ::wxEVT_CREATE_VIEW event ) 00935 a2dDocumentFlagMask m_flags; 00936 00937 //! see GetView() 00938 a2dView* m_view; 00939 00940 //! see GetFileName() 00941 wxFileName m_filename; 00942 00943 //! see GetDocumentTemplate() 00944 a2dDocumentTemplate* m_doctemplate; 00945 00946 //! return code in case of errors loading documents etc. 00947 a2dError m_error; 00948 00949 unsigned int m_updateHint; 00950 00951 wxObject* m_objectHint; 00952 }; 00953 00954 00955 //! event sent to a2dViewConnector 00956 /*! 00957 00958 The ::wxEVT_PRE_ADD_DOCUMENT is sent to a viewconnector, after a new document was created 00959 from a a2dDocumentTemplate, but before it is added to the a2dDocumentCommandProcessor. 00960 And also just before ::wxEVT_POST_CREATE_DOCUMENT is sent to the same connector. 00961 If wxEVT_PRE_ADD_DOCUMENT allows you to merge or copy a new created document with an already existing 00962 document. In that case the document will be closed in the event handler, and after return 00963 the ::wxEVT_POST_CREATE_DOCUMENT will not be sent. 00964 The ::wxEVT_PRE_ADD_DOCUMENT gets as input the newly created document, and if merged return in that 00965 the document used for merge, or NULL if document is just closed. 00966 00967 The two events are generated via this template class, when a2dDocumentCommandProcessor creates 00968 new documents. 00969 00970 The default handler a2dViewConnector::OnPostCreateDocument(), will select 00971 a a2dViewTemplate via the a2dDocumentCommandProcessor, and create the first view on the document 00972 using that template. 00973 00974 The ::wxEVT_POST_CREATE_DOCUMENT is sent to a viewconnector, after a new document was created 00975 from a a2dDocumentTemplate. 00976 The default handler a2dViewConnector::OnPostCreateDocument(), will select 00977 a a2dViewTemplate via the a2dDocumentCommandProcessor, and create the first view on the document 00978 using that template. 00979 00980 The ::wxEVT_POST_CREATE_VIEW is sent to the viewconnector, after a new view was created from a a2dViewTemplate 00981 The default handler a2dViewConnector::OnPostCreateView() will tell you that you need 00982 to intercept this event in a derived a2dViewConnector. 00983 The a2dViewConnector does not know how to connect new views into frames or windows etc. 00984 A derived a2dViewConnector should know! 00985 00986 The ::wxEVT_DISCONNECT_VIEW 00987 Is sent from a2dViews via a2dViewTemplate to a2dViewConnector, in order to disconnect a view. 00988 00989 \ingroup docview docviewevents events 00990 00991 */ 00992 class A2DDOCVIEWDLLEXP a2dTemplateEvent : public a2dEvent 00993 { 00994 DECLARE_CLASS(a2dTemplateEvent) 00995 00996 public: 00997 00998 //! constructor 00999 a2dTemplateEvent( a2dDocument* doc, wxEventType type, a2dDocumentFlagMask flags = a2dREFDOC_NON, int id = 0 ) 01000 : a2dEvent( id, type ) 01001 { 01002 m_doc = doc; 01003 m_flags = flags; 01004 m_mask = a2dTemplateFlag::DEFAULT; 01005 } 01006 01007 //! constructor 01008 a2dTemplateEvent( wxEventType type, a2dView* view, a2dDocumentFlagMask flags = a2dREFDOC_NON, int id = 0) 01009 : a2dEvent( id, type ) 01010 { 01011 m_view = view; 01012 m_flags = flags; 01013 } 01014 01015 //! constructor 01016 a2dTemplateEvent( const a2dTemplateEvent & event ) 01017 : a2dEvent(event) 01018 { 01019 m_doc = event.m_doc; 01020 m_flags = event.m_flags; 01021 m_mask = event.m_mask; 01022 } 01023 01024 //! the document created. 01025 a2dDocument* GetDocument() { return m_doc; } 01026 01027 void SetDocument( a2dDocument* doc ) { m_doc = doc; } 01028 01029 //! the document flags as set by a2dDocumentTemplate::CreateDocument() 01030 a2dDocumentFlagMask GetFlags() { return m_flags; } 01031 01032 a2dTemplateFlagMask GetTemplateMaskFlags() { return m_mask; } 01033 01034 //! clone the event 01035 virtual wxEvent *Clone() const { return new a2dTemplateEvent(*this); } 01036 01037 //! Get the view created. 01038 a2dView* GetView() { return m_view; } 01039 01040 //! Set the view created 01041 void SetView( a2dView* view ) { m_view = view; } 01042 01043 private: 01044 01045 //! see GetDocument() 01046 a2dDocument* m_doc; 01047 01048 //! see GetFlags() 01049 a2dDocumentFlagMask m_flags; 01050 01051 a2dTemplateFlagMask m_mask; 01052 01053 //! see GetView() 01054 a2dView* m_view; 01055 }; 01056 01057 /*! \addtogroup eventhandlers 01058 * @{ 01059 */ 01060 01061 //! \cond 01062 typedef void (a2dEvtHandler::*a2dObjectDocumentCloseEventFunction)(a2dCloseDocumentEvent&); 01063 typedef void (a2dEvtHandler::*a2dObjectDocumentEventFunction)(a2dDocumentEvent&); 01064 typedef void (a2dEvtHandler::*a2dObjectViewCloseEventFunction)(a2dCloseViewEvent&); 01065 typedef void (a2dEvtHandler::*a2dObjectViewEventFunction)(a2dViewEvent&); 01066 typedef void (a2dEvtHandler::*a2dObjectTemplateEventFunction)(a2dTemplateEvent&); 01067 01068 #define a2dObjectDocumentCloseEventHandler(func) \ 01069 (a2dObjectEventFunction)(a2dEventFunction)wxStaticCastEvent(a2dObjectDocumentCloseEventFunction, &func) 01070 #define a2dObjectDocumentEventHandler(func) \ 01071 (a2dObjectEventFunction)(a2dEventFunction)wxStaticCastEvent(a2dObjectDocumentEventFunction, &func) 01072 #define a2dObjectViewCloseEventHandler(func) \ 01073 (a2dObjectEventFunction)(a2dEventFunction)wxStaticCastEvent(a2dObjectViewCloseEventFunction, &func) 01074 #define a2dObjectViewEventHandler(func) \ 01075 (a2dObjectEventFunction)(a2dEventFunction)wxStaticCastEvent(a2dObjectViewEventFunction, &func) 01076 #define a2dObjectTemplateEventHandler(func) \ 01077 (a2dObjectEventFunction)(a2dEventFunction)wxStaticCastEvent(a2dObjectTemplateEventFunction, &func) 01078 01079 typedef void (wxEvtHandler::*a2dDocumentCloseEventFunction)(a2dCloseDocumentEvent&); 01080 typedef void (wxEvtHandler::*a2dDocumentEventFunction)(a2dDocumentEvent&); 01081 typedef void (wxEvtHandler::*a2dViewCloseEventFunction)(a2dCloseViewEvent&); 01082 typedef void (wxEvtHandler::*a2dViewEventFunction)(a2dViewEvent&); 01083 typedef void (wxEvtHandler::*a2dTemplateEventFunction)(a2dTemplateEvent&); 01084 //! \endcond 01085 01086 #define a2dDocumentCloseEventHandler(func) \ 01087 (wxObjectEventFunction)(wxEventFunction)wxStaticCastEvent(a2dDocumentCloseEventFunction, &func) 01088 #define a2dDocumentEventHandler(func) \ 01089 (wxObjectEventFunction)(wxEventFunction)wxStaticCastEvent(a2dDocumentEventFunction, &func) 01090 #define a2dViewCloseEventHandler(func) \ 01091 (wxObjectEventFunction)(wxEventFunction)wxStaticCastEvent(a2dViewCloseEventFunction, &func) 01092 #define a2dViewEventHandler(func) \ 01093 (wxObjectEventFunction)(wxEventFunction)wxStaticCastEvent(a2dViewEventFunction, &func) 01094 #define a2dTemplateEventHandler(func) \ 01095 (wxObjectEventFunction)(wxEventFunction)wxStaticCastEvent(a2dTemplateEventFunction, &func) 01096 01097 01098 //! event for document before all view are closed. 01099 #define A2D_EVT_DISCONNECT_ALLVIEWS(func) a2d__DECLARE_EVT0( wxEVT_DISCONNECT_ALLVIEWS, a2dObjectDocumentEventHandler( func )) 01100 //! event for document before a document will be closed ( can veto) 01101 #define A2D_EVT_CLOSE_DOCUMENT(func) a2d__DECLARE_EVT0( wxEVT_CLOSE_DOCUMENT, a2dObjectDocumentCloseEventHandler( func )) 01102 //! event for document when a document has been opened 01103 #define A2D_EVT_OPEN_DOCUMENT(func) a2d__DECLARE_EVT0( wxEVT_OPEN_DOCUMENT, a2dObjectDocumentEventHandler( func )) 01104 //! event for document when a document new document was created 01105 #define A2D_EVT_NEW_DOCUMENT(func) a2d__DECLARE_EVT0( wxEVT_NEW_DOCUMENT, a2dObjectDocumentEventHandler( func )) 01106 //! event sent to document from template when a document has been created 01107 #define A2D_EVT_CREATE_DOCUMENT(func) a2d__DECLARE_EVT0( wxEVT_CREATE_DOCUMENT, a2dObjectDocumentEventHandler( func )) 01108 //! event sent to document when a document needs to be saved 01109 #define A2D_EVT_SAVE_DOCUMENT(func) a2d__DECLARE_EVT0( wxEVT_SAVE_DOCUMENT, a2dObjectDocumentEventHandler( func )) 01110 //! event sent to document when a document needs to be saved in a different file 01111 #define A2D_EVT_SAVEAS_DOCUMENT(func) a2d__DECLARE_EVT0( wxEVT_SAVEAS_DOCUMENT, a2dObjectDocumentEventHandler( func )) 01112 //! event sent to document when a document is modified and the user may save or not 01113 #define A2D_EVT_SAVE_MODIFIED_DIALOG_DOCUMENT(func) a2d__DECLARE_EVT0( wxEVT_SAVE_MODIFIED_DIALOG_DOCUMENT, a2dObjectDocumentEventHandler( func )) 01114 //! event for document when a document will be exported 01115 #define A2D_EVT_EXPORT_DOCUMENT(func) a2d__DECLARE_EVT0( wxEVT_EXPORT_DOCUMENT, a2dObjectDocumentEventHandler( func )) 01116 //! event for document when a document will be imported 01117 #define A2D_EVT_IMPORT_DOCUMENT(func) a2d__DECLARE_EVT0( wxEVT_IMPORT_DOCUMENT, a2dObjectDocumentEventHandler( func )) 01118 //! event from a document when its views need to be updated 01119 #define A2D_EVT_UPDATE_VIEWS(func) a2d__DECLARE_EVT0( wxEVT_UPDATE_VIEWS, a2dObjectDocumentEventHandler( func )) 01120 //! event from a document when its views need to be enabled or disabled 01121 #define A2D_EVT_ENABLE_VIEWS(func) a2d__DECLARE_EVT0( wxEVT_ENABLE_VIEWS, a2dObjectDocumentEventHandler( func )) 01122 //! event from a document when its views need to reported 01123 #define A2D_EVT_REPORT_VIEWS(func) a2d__DECLARE_EVT0( wxEVT_REPORT_VIEWS, a2dObjectDocumentEventHandler( func )) 01124 //! event sent to view when the filename of a document has changed. 01125 #define A2D_EVT_CHANGEDFILENAME_DOCUMENT(func) a2d__DECLARE_EVT0( wxEVT_CHANGEDFILENAME_DOCUMENT, a2dObjectDocumentEventHandler( func )) 01126 //! event sent to view when the title of a document has changed. 01127 #define A2D_EVT_CHANGEDTITLE_DOCUMENT(func) a2d__DECLARE_EVT0( wxEVT_CHANGEDTITLE_DOCUMENT, a2dObjectDocumentEventHandler( func )) 01128 //! event send from a document when modified status changed. 01129 #define A2D_EVT_CHANGEDMODIFY_DOCUMENT(func) a2d__DECLARE_EVT0( wxEVT_CHANGEDMODIFY_DOCUMENT, a2dObjectDocumentEventHandler( func )) 01130 //! event send from a document just after a document was loaded from a file 01131 #define A2D_EVT_POST_LOAD_DOCUMENT(func) a2d__DECLARE_EVT0( wxEVT_POST_LOAD_DOCUMENT, a2dObjectDocumentEventHandler( func )) 01132 //! event sent to document and view when a view needs to be closed ( can veto) 01133 #define A2D_EVT_CLOSE_VIEW(func) a2d__DECLARE_EVT0( wxEVT_CLOSE_VIEW, a2dObjectViewCloseEventHandler( func )) 01134 //! event sent to view from template when a view has been created 01135 #define A2D_EVT_CREATE_VIEW(func) a2d__DECLARE_EVT0( wxEVT_CREATE_VIEW, a2dObjectViewEventHandler( func )) 01136 //! event sent to view when a new document is ser for it. 01137 #define A2D_EVT_SET_DOCUMENT(func) a2d__DECLARE_EVT0( wxEVT_SET_DOCUMENT, a2dObjectViewEventHandler( func )) 01138 //! event sent to view and event distributer 01139 #define A2D_EVT_ACTIVATE_VIEW(func) a2d__DECLARE_EVT0( wxEVT_ACTIVATE_VIEW, a2dObjectViewEventHandler( func )) 01140 //! event sent from view and its display up the parent chain. 01141 #define A2D_EVT_ACTIVATE_VIEW_SENT_FROM_CHILD(func) a2d__DECLARE_EVT0( wxEVT_ACTIVATE_VIEW_SENT_FROM_CHILD, a2dObjectViewEventHandler( func )) 01142 //! event sent to connector to disable or enable for a certain view 01143 #define A2D_EVT_ENABLE_VIEW(func) a2d__DECLARE_EVT0( wxEVT_ENABLE_VIEW, a2dObjectViewEventHandler( func )) 01144 //! event sent to document when a view has been added to the document 01145 #define A2D_EVT_ADD_VIEW(func) a2d__DECLARE_EVT0( wxEVT_ADD_VIEW, a2dObjectDocumentEventHandler( func )) 01146 //! event sent to document when a view will be removed from the document 01147 #define A2D_EVT_REMOVE_VIEW(func) a2d__DECLARE_EVT0( wxEVT_REMOVE_VIEW, a2dObjectDocumentEventHandler( func )) 01148 //! sent from a doc template after it created a document 01149 #define A2D_EVT_PRE_ADD_DOCUMENT(func) a2d__DECLARE_EVT0( wxEVT_PRE_ADD_DOCUMENT, a2dObjectTemplateEventHandler( func )) 01150 //! sent from a doc template after it created a document 01151 #define A2D_EVT_POST_CREATE_DOCUMENT(func) a2d__DECLARE_EVT0( wxEVT_POST_CREATE_DOCUMENT, a2dObjectTemplateEventHandler( func )) 01152 //! sent from a view template after it created a view 01153 #define A2D_EVT_POST_CREATE_VIEW(func) a2d__DECLARE_EVT0( wxEVT_POST_CREATE_VIEW, a2dObjectTemplateEventHandler( func )) 01154 //! event sent to connector to disconnect a certain view from its document 01155 #define A2D_EVT_DISCONNECT_VIEW(func) a2d__DECLARE_EVT0( wxEVT_DISCONNECT_VIEW, a2dObjectTemplateEventHandler( func )) 01156 //! event sent from view upwards to display, when the filename of a document has changed. 01157 #define A2D_EVT_CHANGEDFILENAME_VIEW(func) a2d__DECLARE_EVT0( wxEVT_CHANGEDFILENAME_VIEW, a2dObjectViewEventHandler( func )) 01158 //! event sent from view upwards to display, when the title of a document has changed. 01159 #define A2D_EVT_CHANGEDTITLE_VIEW(func) a2d__DECLARE_EVT0( wxEVT_CHANGEDTITLE_VIEW, a2dObjectViewEventHandler( func )) 01160 01161 //! event for document before all view are closed. 01162 #define EVT_DISCONNECT_ALLVIEWS(func) wx__DECLARE_EVT0( wxEVT_DISCONNECT_ALLVIEWS, a2dDocumentEventHandler( func )) 01163 //! event for document before a document will be closed ( can veto) 01164 #define EVT_CLOSE_DOCUMENT(func) wx__DECLARE_EVT0( wxEVT_CLOSE_DOCUMENT, a2dDocumentCloseEventHandler( func )) 01165 //! event for document when a document has been opened 01166 #define EVT_OPEN_DOCUMENT(func) wx__DECLARE_EVT0( wxEVT_OPEN_DOCUMENT, a2dDocumentEventHandler( func )) 01167 //! event for document when a document new document was created 01168 #define EVT_NEW_DOCUMENT(func) wx__DECLARE_EVT0( wxEVT_NEW_DOCUMENT, a2dDocumentEventHandler( func )) 01169 //! event sent to document from template when a document has been created 01170 #define EVT_CREATE_DOCUMENT(func) wx__DECLARE_EVT0( wxEVT_CREATE_DOCUMENT, a2dDocumentEventHandler( func )) 01171 //! event sent to document when a document needs to be saved 01172 #define EVT_SAVE_DOCUMENT(func) wx__DECLARE_EVT0( wxEVT_SAVE_DOCUMENT, a2dDocumentEventHandler( func )) 01173 //! event sent to document when a document needs to be saved in a different file 01174 #define EVT_SAVEAS_DOCUMENT(func) wx__DECLARE_EVT0( wxEVT_SAVEAS_DOCUMENT, a2dDocumentEventHandler( func )) 01175 //! event sent to document when a document is modified and the user may save or not 01176 #define EVT_SAVE_MODIFIED_DIALOG_DOCUMENT(func) wx__DECLARE_EVT0( wxEVT_SAVE_MODIFIED_DIALOG_DOCUMENT, a2dDocumentEventHandler( func )) 01177 //! event for document when a document will be exported 01178 #define EVT_EXPORT_DOCUMENT(func) wx__DECLARE_EVT0( wxEVT_EXPORT_DOCUMENT, a2dDocumentEventHandler( func )) 01179 //! event for document when a document will be imported 01180 #define EVT_IMPORT_DOCUMENT(func) wx__DECLARE_EVT0( wxEVT_IMPORT_DOCUMENT, a2dDocumentEventHandler( func )) 01181 //! event from a document when its views need to be updated 01182 #define EVT_UPDATE_VIEWS(func) wx__DECLARE_EVT0( wxEVT_UPDATE_VIEWS, a2dDocumentEventHandler( func )) 01183 //! event from a document when its views need to be enabled or disabled 01184 #define EVT_ENABLE_VIEWS(func) wx__DECLARE_EVT0( wxEVT_ENABLE_VIEWS, a2dDocumentEventHandler( func )) 01185 //! event from a document when its views need to reported 01186 #define EVT_REPORT_VIEWS(func) wx__DECLARE_EVT0( wxEVT_REPORT_VIEWS, a2dDocumentEventHandler( func )) 01187 //! event sent to view when the filename of a document has changed. 01188 #define EVT_CHANGEDFILENAME_DOCUMENT(func) wx__DECLARE_EVT0( wxEVT_CHANGEDFILENAME_DOCUMENT, a2dDocumentEventHandler( func )) 01189 //! event sent to view when the title of a document has changed. 01190 #define EVT_CHANGEDTITLE_DOCUMENT(func) wx__DECLARE_EVT0( wxEVT_CHANGEDTITLE_DOCUMENT, a2dDocumentEventHandler( func )) 01191 //! event send from a document when modified status changed. 01192 #define EVT_CHANGEDMODIFY_DOCUMENT(func) wx__DECLARE_EVT0( wxEVT_CHANGEDMODIFY_DOCUMENT, a2dDocumentEventHandler( func )) 01193 //! event send from a document just after a document was loaded from a file 01194 #define EVT_POST_LOAD_DOCUMENT(func) wx__DECLARE_EVT0( wxEVT_POST_LOAD_DOCUMENT, a2dDocumentEventHandler( func )) 01195 //! event sent to document and view when a view needs to be closed ( can veto) 01196 #define EVT_CLOSE_VIEW(func) wx__DECLARE_EVT0( wxEVT_CLOSE_VIEW, a2dViewCloseEventHandler( func)) 01197 //! event sent to view from template when a view has been created 01198 #define EVT_CREATE_VIEW(func) wx__DECLARE_EVT0( wxEVT_CREATE_VIEW, a2dViewEventHandler( func )) 01199 //! event sent to view when a new document is ser for it. 01200 #define EVT_SET_DOCUMENT(func) wx__DECLARE_EVT0( wxEVT_SET_DOCUMENT, a2dViewEventHandler( func )) 01201 //! event sent to view and document manager 01202 #define EVT_ACTIVATE_VIEW(func) wx__DECLARE_EVT0( wxEVT_ACTIVATE_VIEW, a2dViewEventHandler( func )) 01203 //! event sent from view and its display up the parent chain. 01204 #define EVT_ACTIVATE_VIEW_SENT_FROM_CHILD(func) wx__DECLARE_EVT0( wxEVT_ACTIVATE_VIEW_SENT_FROM_CHILD, a2dViewEventHandler( func )) 01205 //! event sent to connector to disable or enable for a certain view 01206 #define EVT_ENABLE_VIEW(func) wx__DECLARE_EVT0( wxEVT_ENABLE_VIEW, a2dViewEventHandler( func )) 01207 //! event sent to document when a view has been added to the document 01208 #define EVT_ADD_VIEW(func) wx__DECLARE_EVT0( wxEVT_ADD_VIEW, a2dDocumentEventHandler( func )) 01209 //! event sent to document when a view will be removed from the document 01210 #define EVT_REMOVE_VIEW(func) wx__DECLARE_EVT0( wxEVT_REMOVE_VIEW, a2dDocumentEventHandler( func )) 01211 //! sent from a doc template after it created a document 01212 #define EVT_POST_CREATE_DOCUMENT(func) wx__DECLARE_EVT0( wxEVT_POST_CREATE_DOCUMENT, a2dTemplateEventHandler( func )) 01213 //! sent from a view template after it created a view 01214 #define EVT_POST_CREATE_VIEW(func) wx__DECLARE_EVT0( wxEVT_POST_CREATE_VIEW, a2dTemplateEventHandler( func )) 01215 //! event sent from view upwards to display, when the filename of a document has changed. 01216 #define EVT_CHANGEDFILENAME_VIEW(func) wx__DECLARE_EVT0( wxEVT_CHANGEDFILENAME_VIEW, a2dViewEventHandler( func )) 01217 //! event sent from view upwards to display, when the title of a document has changed. 01218 #define EVT_CHANGEDTITLE_VIEW(func) wx__DECLARE_EVT0( wxEVT_CHANGEDTITLE_VIEW, a2dViewEventHandler( func )) 01219 01220 //! @} eventhandlers 01221 01222 class A2DDOCVIEWDLLEXP a2dIOHandlerXmlSerIn; 01223 class A2DDOCVIEWDLLEXP a2dIOHandlerXmlSerOut; 01224 01225 //! The document class can be used to model an application's file-based data. 01226 /*! It is part of the document/view framework, 01227 and cooperates with the a2dView, a2dDocumentTemplate, a2dViewTemplate, a2dEventDistributer and a2dDocumentCommandProcessor classes. 01228 01229 a2dDocument can also be used in a setting with just a2dView's and/or templates, so without 01230 a a2dDocumentCommandProcessor controlling most tasks. But events coming from the document meant 01231 for the a2dView (e.g. Update events), will be sent to a wxEvtHandler that is set with SetDistributer(). 01232 If not set, events are sent to a2dDocviewGlobals->GetEventDistributer(). 01233 Therefore if you just want to display the fixed data in the a2dDocument, a a2dDocumentCommandProcessor is not really 01234 needed. 01235 In the general case with several view and documents, it is best to use a a2dDocumentCommandProcessor. 01236 01237 01238 Events types which can be/are intercepted: 01239 01240 - ::wxEVT_CLOSE_VIEW sent when a view wants to be closed ( may veto ) 01241 - ::wxEVT_DISCONNECT_ALLVIEWS sent to document and document manager within DisconnectAllViews(). 01242 - ::wxEVT_CLOSE_DOCUMENT sent to document just after calling Close() 01243 - ::wxEVT_ADD_VIEW sent to document just after a view was added to the document 01244 - ::wxEVT_REMOVE_VIEW sent to document just before a view is removed from the document 01245 - ::wxEVT_OPEN_DOCUMENT sent by docmanager when a document was created and opened from a file. 01246 Default handler loads the file. 01247 - ::wxEVT_NEW_DOCUMENT sent by docmanager when a document was created as new. 01248 See default handler. 01249 - ::wxEVT_CREATE_DOCUMENT sent after creation of document from a template. 01250 - ::wxEVT_SAVE_DOCUMENT sent to save document ( e.g from Save() ) 01251 - ::wxEVT_SAVEAS_DOCUMENT sent to save document under a different name ( e.g from SaveAs() ) 01252 - ::wxEVT_EXPORT_DOCUMENT sent to export a document ( e.g from Export()) 01253 - ::wxEVT_IMPORT_DOCUMENT sent to export a document ( e.g from Import()) 01254 - ::wxEVT_POST_LOAD_DOCUMENT sent just after a document was loaded from a file in LoadObject() 01255 - ::wxEVT_CHANGEDMODIFY_DOCUMENT sent just after a document its modify flag has changed in Modify() 01256 - ::wxEVT_REPORT_VIEWS sent to the event distributer, to assemble all a2dView using the document. 01257 - ::wxEVT_UPDATE_VIEWS sent when all view need to update them selfs ( e.g. after a change in the document ) 01258 \see UpdateAllViews() 01259 - ::wxEVT_ENABLE_VIEWS sent from EnableAllViews(), to disable or enable all views on the document. 01260 - ::wxEVT_CHANGEDFILENAME_DOCUMENT sent from SetFilename(), when the document its fileinfo has changed. 01261 - ::wxEVT_CHANGEDTITLE_DOCUMENT sent from SetTitle(), when the document its title has changed. 01262 01263 \ingroup docview 01264 */ 01265 class A2DDOCVIEWDLLEXP a2dDocument : public a2dEvtHandler 01266 { 01267 DECLARE_ABSTRACT_CLASS(a2dDocument) 01268 01269 A2D_DECLARE_EVENT_TABLE() 01270 01271 public: 01272 01273 //! Constructor. 01274 /*! 01275 The document may have a parent, so a hierachically structure of 01276 documents is possible. 01277 01278 \remark 01279 Current implementation doesn't support a nice access to parent/child 01280 docs. 01281 01282 \param parent The document's parent 01283 */ 01284 a2dDocument( a2dDocument* parent = (a2dDocument*) NULL ); 01285 01286 //! destructor 01287 ~a2dDocument(); 01288 01289 //! constructor with other document 01290 a2dDocument( const a2dDocument& other ); 01291 01292 //!Clone document 01293 a2dObject* Clone( a2dObject::CloneOptions options ) const; 01294 01295 // accessors 01296 01297 //!Sets the filename for this document. Usually called by the framework. 01298 /*! 01299 If notifyViews is true, a a2dDocumentEvent of type ::wxEVT_CHANGEDFILENAME_DOCUMENT 01300 is sent to the event distributer. DistributeEvent() 01301 */ 01302 void SetFilename( const wxFileName& filename, bool notifyViews = false); 01303 01304 //! Get the file name in use for this document. 01305 wxFileName GetFilename() const { return m_documentFile; } 01306 01307 //!Sets the title for this document. 01308 /*! 01309 The document title is used for an associated frame (if any), and is usually 01310 constructed by the framework from the filename. 01311 The title may be changed by the programmer or set by an IOHandler 01312 01313 \param title The title of the document. 01314 \param notifyViews If <code>true</code> a a2dDocumentEvent of type ::wxEVT_CHANGEDTITLE_DOCUMENT 01315 is send to all views via DistributeEvent() 01316 */ 01317 void SetTitle(const wxString& title, bool notifyViews = false); 01318 01319 //! Returns the title for this document. 01320 wxString GetTitle() const { return m_documentTitle; } 01321 01322 //!Sets the document type name for this document. See the comment for documentTypeName. 01323 void SetDocumentTypeName(const wxString& name) { m_documentTypeName = name; }; 01324 01325 //!Gets the document type name of this document. See the comment for documentTypeName. 01326 wxString GetDocumentTypeName() const { return m_documentTypeName; } 01327 01328 //! Returns if the document was saved after a modification. 01329 bool GetDocumentSaved() const { return m_savedYet; } 01330 01331 //! Alias for a2dDocument::GetDocumentSaved 01332 bool IsDocumentSaved() const { return GetDocumentSaved(); } 01333 01334 //! Sets the document saved flag. 01335 /*! 01336 The document saved flag is normally set by the framework, 01337 */ 01338 void SetDocumentSaved(bool saved = true) { m_savedYet = saved; } 01339 01340 //! returns true when document is closed or busy closing. 01341 /*! 01342 Closing a document in general includes closing its views too. 01343 When busy closing a document, this function here can be used to prevent recursive calls elsewhere. 01344 You can savely call Close() anyway, but if other actions depends on the document being closed or not, 01345 you can check it with this here. A typical example is a closing a document and also releasing it from 01346 some higher order class. 01347 \see Close() for more. 01348 */ 01349 bool IsClosed() { return m_isClosed; } 01350 01351 //!Closes the document if not vetod. 01352 /*!Closing a document means that the application does not want the 01353 the document in memory anymore in order to view or modify it. 01354 This function prepares the document for deletion. 01355 01356 Sents a ::wxEVT_CLOSE_DOCUMENT event. 01357 The default handler is OnCloseDocument( a2dCloseDocumentEvent& event ). 01358 01359 Default calls SaveModifiedDialog(), to give the user a change to save his changes. 01360 01361 This does not normally delete the document object, which only happens if the reference 01362 count reaches zero, indicating no more Owners do exist. 01363 01364 \see OnCloseDocument 01365 \see SaveModifiedDialog 01366 */ 01367 bool Close( bool force ); 01368 01369 01370 //!Saves the document by sending a a2dDocumentEvent ::wxEVT_SAVE_DOCUMENT event. 01371 /*! 01372 The method first tests if the document is modified and not saved yet. 01373 If it is modified and not saved, the event is sent. 01374 01375 \see OnSaveDocument 01376 01377 \return true if the document could be saved 01378 */ 01379 bool Save(); 01380 01381 //! Tries to save the document by sending a a2dDocumentEvent ::wxEVT_SAVEAS_DOCUMENT event. 01382 /*! 01383 The default handler asks for a file, to save the document into. 01384 01385 \see OnSaveAsDocument 01386 01387 \return true if the document could be saved 01388 */ 01389 bool SaveAs( const wxFileName& fileTosaveTo = wxFileName( wxT("") ), a2dDocumentFlagMask flags = a2dREFDOC_NON ); 01390 01391 01392 //! Tries to save the document by sending a a2dDocumentEvent ::wxEVT_EXPORT_DOCUMENT event. 01393 /*! 01394 \see OnExportDocument 01395 01396 \return true if the document could be saved 01397 */ 01398 bool Export( a2dDocumentTemplate* doctemplate, const wxFileName& fileTosaveTo = wxFileName( wxT("") ), a2dDocumentFlagMask flags = a2dREFDOC_NON ); 01399 01400 //! Tries to read a file into the document by sending a a2dDocumentEvent ::wxEVT_IMPORT_DOCUMENT event. 01401 /*! 01402 \see OnImportDocument 01403 01404 \return true if the document could be read 01405 */ 01406 bool Import( a2dDocumentTemplate* doctemplate, const wxFileName& fileToImport = wxFileName( wxT("") ), a2dDocumentFlagMask flags = a2dREFDOC_NON ); 01407 01408 //! Normally should undo all changes by rereading the file again. 01409 /*! 01410 \todo 01411 make a default implementation which does do it 01412 ( unless already saved the changes sofar ) 01413 */ 01414 virtual bool Revert(); 01415 01416 //! handling loading of the document from a stream 01417 /*! The given handler is used to load the document from the stream. 01418 01419 Override this function to implement your own version. 01420 LoadObject is called by the framework automatically when 01421 the document contents needs to be loaded. 01422 01423 \note only one of these forms exists, depending on how wxWindows was configured. 01424 */ 01425 virtual a2dDocumentInputStream& LoadObject( a2dDocumentInputStream& stream, a2dIOHandlerStrIn* handler ); 01426 01427 //! handling saving and exporting of the document to a stream 01428 /*! The a2dIOHandler given is used to save the document to the stream. 01429 01430 Override this function to implement your own version. 01431 SaveObject is called by the framework automatically when 01432 the document contents need to be saved. 01433 01434 \note only one of these forms exists, depending on how wxWindows was configured. 01435 */ 01436 virtual a2dDocumentOutputStream& SaveObject(a2dDocumentOutputStream& stream, a2dIOHandlerStrOut* handler ); 01437 01438 //! can be set by a2dIOHandler's by e.g LoadObject(). 01439 /*! 01440 If parsing a document from the stream is incorrect due to formating errors, the handler or LoadObject itself 01441 can set this error code, which result in veto-ing the event. 01442 */ 01443 void SetLastError( a2dError lastError ) { m_lastError = lastError; } 01444 01445 //! is set by a2dIOHandler's and is tested by LoadObject(). 01446 /*! 01447 If parsing a document from the stream is incorrect due to formating errors, the handler or LoadObject itself 01448 can set this error code. 01449 */ 01450 a2dError GetLastError() { return m_lastError; } 01451 01452 #if wxART2D_USE_CVGIO 01453 //! used by CVG parser 01454 /*! 01455 \remark do not use directly 01456 */ 01457 void Load( wxObject* parent, a2dIOHandlerXmlSerIn& parser ); 01458 01459 //! called from a2dIOHandlerXmlSerOut after a SaveObject. 01460 /*! 01461 \param parent parent object from which Save was called 01462 \param out CVG io handler 01463 \param towrite object to write later 01464 */ 01465 void Save( wxObject* parent, a2dIOHandlerXmlSerOut &out, a2dObjectList* towrite ); 01466 01467 //! called from a2dIOHandlerXmlSerOut after a SaveObject. 01468 /*! 01469 \param out CVG io handler 01470 \param start start wrting from this object 01471 */ 01472 void Save( a2dIOHandlerXmlSerOut &out, wxObject* start = NULL ); 01473 #endif //wxART2D_USE_CVGIO 01474 01475 //! dialog when the user needs to confirm saving a document 01476 /*! 01477 If the document has been modified, prompts the user to ask if the 01478 changes should be saved. 01479 If the user replies Yes, the Save function is called and return is wxYES. 01480 If No, the document is marked as unmodified and return is wxNO 01481 If Cancel return is wxCANCEL. 01482 If document was not modified, also wxYES is returned. 01483 */ 01484 virtual int SaveModifiedDialog( bool canCancel = true ); 01485 01486 //! create a command processor and set it for the document. 01487 /*! 01488 If available the existing commandprocessor will be deleted. 01489 A new CommandProcessor will be created and set for the document. 01490 01491 Override if you need a more application specific commandhandler. 01492 */ 01493 virtual void CreateCommandProcessor(); 01494 01495 //!Returns a pointer to the command processor associated with this document 01496 a2dCommandProcessor *GetCommandProcessor() const { return m_commandProcessor; } 01497 01498 //! Sets the command processor to be used for this document. 01499 /*! 01500 Use in case you need one a2dCommandProcessor to be used for several 01501 a2dDocument's, 01502 Make sure you set it to NULL before deleting the document itself, 01503 else the a2dDocument destructor will delete it ( leaving the others 01504 with dangling pointers ). 01505 */ 01506 void SetCommandProcessor(a2dCommandProcessor *proc) { m_commandProcessor = proc; } 01507 01508 //! called when there is a need to clear the contents of the document. 01509 /*! 01510 Override this function to define the way to do this. 01511 */ 01512 virtual void DeleteContents(); 01513 01514 //! Might be used to draw the contents of a document to a a2dView using a wxDc as the drawing context. 01515 /*! 01516 You need to override this method in derived class to do something usefull. 01517 01518 \return default only returns true 01519 */ 01520 virtual bool Draw(wxDC& context); 01521 01522 //! Has the document been modified 01523 bool IsModified() const { return m_documentModified; } 01524 01525 //! set the docuent as modified or not 01526 /*! 01527 If the modified status changes an ::wxEVT_CHANGEDMODIFY_DOCUMENT event will 01528 be send. 01529 01530 \param mod <code>true</code> to set document modified, else <code>false</code> 01531 */ 01532 void Modify(bool mod); 01533 01534 //! Ask to save when document is modified and last view is closed? 01535 /*! 01536 When there are still owners of the document, and the last view is closed 01537 it can either be saved or delayed until the application closes. 01538 Setting AskSaveWhenOwned delayes the saving of the data until later. 01539 */ 01540 void AskSaveWhenOwned( bool askSaveWhenOwned ) { m_askSaveWhenOwned = askSaveWhenOwned; } 01541 01542 01543 //! sent Update events to all a2dView which display or use this document. 01544 /*! 01545 This function is typicaly called when the document its contents has changed, 01546 this in general will result in the a2dView displaying this new information. 01547 Understand that this only informs the views to update themselfs, how and what the view needs 01548 to update can be indicated by the hints, or in more complex situations the views will 01549 read the document contents to see what did change, and only update what changed in its view. 01550 01551 \param sender which view did calls this function ( Non = NULL ). 01552 \param hint update will differ on the hint given and the implementation 01553 \param objecthint more complex way to deliver hints 01554 01555 */ 01556 virtual void UpdateAllViews(a2dView *sender = (a2dView *) NULL, unsigned int hint = a2dVIEW_UPDATE_ALL, wxObject *objecthint = (wxObject *) NULL ); 01557 01558 01559 //! sents a ::wxEVT_REPORT_VIEWS to all views, via the a2dDocumentCommandProcessor. 01560 /*! 01561 The a2dView's using this document will report themself by adding 01562 itself to the allviews list. 01563 */ 01564 void ReportViews( a2dViewList* allviews ); 01565 01566 //! calls Enable( true/false ) for each view. 01567 /*! 01568 Enables or disables all views. If sender is non-NULL, does NOT call it for this view. 01569 The disabling a a2dView means that it will not process any events, until enabled again. 01570 */ 01571 void EnableAllViews( bool enable, a2dView *sender = (a2dView *) NULL ); 01572 01573 //! Disconnect a2dView's using this document. 01574 /*! 01575 It depends on the application if a disconnected view will be closed or not. 01576 In case the views will be resused for another document after disconnecting them, 01577 obviously they should not be closed. Typically thsi will be the case in a one frame application, 01578 where the frame has one or more fixed views, which will be used for the currently open document. 01579 01580 Before starting to disconnect the views, a a2dDocumentEvent type ::wxEVT_DISCONNECT_ALLVIEWS is sent to 01581 this a2dDocument, which can be intercepted to do some general cleanup on the 01582 document. 01583 01584 In case the a2dView::Close() is called on disconnection, . 01585 this generates a a2dCloseViewEvent (type ::wxEVT_CLOSE_VIEW ) sent to the 01586 document and the view. The event can not be vetod for this action. 01587 */ 01588 void DisConnectAllViews(); 01589 01590 //! Gets a2dDocumentTemplate pointer which was used to create the a2dView 01591 a2dDocumentTemplate* GetDocumentTemplate() const { return m_documentTemplate; } 01592 01593 //! Set a2dDocumentTemplate pointer 01594 void SetDocumentTemplate(a2dDocumentTemplate *temp) { m_documentTemplate = temp; } 01595 01596 //! Get title, or filename if no title, else [unnamed] 01597 wxString GetPrintableName() const; 01598 01599 //! Returns a window that can be used as a parent for document-related dialogs. Override if necessary. 01600 virtual wxWindow* GetAssociatedWindow() const; 01601 01602 protected: 01603 01604 //! default handler for ::wxEVT_CREATE_DOCUMENT, Called after creation of document from a template. 01605 /*! Called by framework if the documemt is created automatically by the default document 01606 manager (via a document template). 01607 This gives the document a chance to initialise. 01608 01609 This Default handler does Nothing Yet. 01610 */ 01611 void OnCreateDocument( a2dDocumentEvent& event ); 01612 01613 //! Called by wxWindows when a file needs to be saved 01614 /*! 01615 Default handler for a2dDocumentEvent of type ::wxEVT_SAVE_DOCUMENT. 01616 01617 Save in the file filename of the document, 01618 or call SaveAs if the filename is not set. 01619 01620 Constructs an output file stream for the given filename (which must not be empty), 01621 and calls SaveObject. If SaveObject returns true, the document is 01622 set to unmodified; otherwise, an error message box is displayed. 01623 01624 event is set Allowed if the file could be opened and the document was saved. 01625 01626 \remark the document its a2dDocumentTemplate is used to find the right a2dIOHandlerStrOut via 01627 a2dDocumentTemplate::GetDocumentIOHandlerForSave(). 01628 01629 */ 01630 void OnSaveDocument( a2dDocumentEvent& event ); 01631 01632 01633 //! default handler for a2dDocumentEvent of type ::wxEVT_SAVEAS_DOCUMENT 01634 /*! 01635 Prompts the user for a file to save to. 01636 01637 Notifies the views that the filename has changes by sending ::wxEVT_CHANGEDFILENAME_DOCUMENT 01638 to the event distributer DistributeEvent(). 01639 01640 \remark the document its a2dDocumentTemplate is used to find the right a2dIOHandlerStrOut via 01641 a2dDocumentTemplate::GetDocumentIOHandlerForSave(). 01642 01643 */ 01644 void OnSaveAsDocument( a2dDocumentEvent& event ); 01645 01646 //! load a document from a file into this document 01647 /*! 01648 Default handler for a2dDocumentEvent of type ::wxEVT_OPEN_DOCUMENT. 01649 01650 In the default handler SaveModifiedDialog() is called first, and if the document is modified 01651 the user is asked to save the changes. Cancel will not open the file into the document. 01652 01653 Constructs an input file stream for the given filename (which must not be empty), 01654 and calls LoadObject. If LoadObject returns true, the document is set to unmodified; otherwise, 01655 an error message box is displayed. The document's views are notified that the filename has changed, 01656 to give windows an opportunity to update their titles. 01657 All of the document's views are then updated. 01658 01659 \remark m_documentTemplate must be set for the default handler to work. 01660 01661 \note only one of these forms exists, depending on how wxWindows was configured. 01662 */ 01663 void OnOpenDocument( a2dDocumentEvent& event ); 01664 01665 //! called after creating a new document from a template , in order to initialize it. 01666 /*! 01667 called by: 01668 a2dDocumentCommandProcessor::CreateDocument() 01669 a2dDocumentCommandProcessor::AddCreatedDocument() 01670 01671 Default handler for a2dDocumentEvent of type ::wxEVT_NEW_DOCUMENT. 01672 01673 The default makes a default title for the document, and notifies the views that the filename 01674 (in fact, the title) has changed. 01675 01676 The user can intercept the event to fill new documents if empty, 01677 but do Skip() the event for the base implementation to be called. 01678 01679 Understand that views might already by open on the document. 01680 */ 01681 void OnNewDocument( a2dDocumentEvent& event ); 01682 01683 //! called when document is closed 01684 /*! 01685 Default handler for a2dDocumentEvent of type ::wxEVT_CLOSE_DOCUMENT. 01686 01687 The default implementation, calls SaveModifiedDialog(), and if not canceled, 01688 disconnects and/or closes all views using DisconnectAllViews(). 01689 This leads to sending ::wxEVT_DISCONNECT_ALLVIEWS to the document and ::wxEVT_CLOSE_VIEW 01690 to each view. This enables the program to delete or detach views etc. 01691 Next empties the document by calling DeleteContents setting modified flag to false. 01692 01693 Override this to supply additional behaviour 01694 when the document is closed with Close. 01695 01696 e.g. In a single document and view approach, you very likely want 01697 to call DeleteContents and set the modified flag to false. 01698 01699 Emptying a document while views are using it, is dangerous. 01700 Views may refer to or use objects in the document. 01701 Therefore the default: 01702 - closes all views ( holding and display parts of the document, else maybe dangling pointers ) 01703 - clears the undo stack ( which may hold references to objects within the document ) 01704 - empty the document 01705 01706 \remark Remember a view also Owns a reference to a document, so certainly all views need to be gone 01707 to really get a document deleted. 01708 */ 01709 void OnCloseDocument( a2dCloseDocumentEvent& event ); 01710 01711 01712 //! Intercept to do cleanup/veto closing of a view 01713 /*! 01714 The handler function for EVT_CLOSE_VIEW, it is called when the program tries 01715 to close a View. 01716 01717 The frame or window containing the view sent a EVT_CLOSE_WINDOW, this 01718 results in a EVT_CLOSE_VIEW being sent to the document and to the view. 01719 OR The a2dDocumentCommandProcessor is closing all documents plus views. 01720 01721 The a2dCloseViewEvent is generated via the a2dView::Close function, so that 01722 the application can also invoke the handler programmatically. 01723 01724 \sa a2dCloseViewEvent for the way the event is propegated to the several classes in 01725 the docview framework. 01726 If OnCloseView does not veto the close event, the a2dView will futher 01727 propegate the event. 01728 01729 The Default implementation: 01730 Checks if the view is the last reference for the document; if so, asks user 01731 to confirm save data. 01732 If AskSaveWhenOwned() == true it will always ask to save the data. 01733 */ 01734 void OnCloseView( a2dCloseViewEvent& event ); 01735 01736 //! what to do when a view using this document will stop using it. 01737 /*! When a view is switching its document to another document, or when a view is closed, 01738 this event is sent to the document just before a2dView releases the document. 01739 The default implementation asks to save the document if it was modified, but only if m_askSaveWhenOwned 01740 is true or m_refcount has reached 1, which is when only the view itself Own the document. 01741 In an application where this document is also controlled by a a2dDocumentCommandProcessor, the refcount 01742 would by two. 01743 When an application has a fixed set of views (per Frame) used by any document that is shown, 01744 it of course makes no sence to automatically close a document when the refcount reaches 1. 01745 In a standard "multi child frame+view + document", one can automatically close the document when 01746 a refcount of < 2 is reached. Which means when a document its last view is closed, and the document 01747 is only owned by the controlling a2dDocumentCommandProcessor. 01748 To make this happen intercept the ::wxEVT_REMOVE_VIEW, and implement whatever you need. 01749 In this case you should call a2dDocviewGlobals->GetDocviewCommandProcessor()->FileClose() in order 01750 to Close the document, which leads to the a2dDocumentCommandProcessor releasing the document. 01751 The very last release and therefore deletion will be done in a2dView after returning from the 01752 ::wxEVT_REMOVE_VIEW event. 01753 */ 01754 void OnRemoveView( a2dDocumentEvent& event ); 01755 01756 //! what to do when a view starts using this document 01757 void OnAddView( a2dDocumentEvent& event ); 01758 01759 //! The default handler for ::wxEVT_EXPORT_DOCUMENT. 01760 /*! 01761 This method asks for a file, to export/save the document into, 01762 using the handler of the event its a2dDocumentTemplate. 01763 If a a2dDocumentTemplate was not given as part of the event, the document template 01764 of this document is used to search for possible templates to be used for exporting 01765 this document. The selection is based on GetDocumentTemplate()->GetDocumentTypeName(). 01766 Next a file dialog is presented to select a file to export. 01767 01768 If a filename is part of the event, this is used as initial file to export to in the save dialog. 01769 If a2dDocumentFlagMask contains a2dREFDOC_SILENT, no dialog will be presented. 01770 */ 01771 void OnExportDocument( a2dDocumentEvent& event ); 01772 01773 //! The default handler for ::wxEVT_IMPORT_DOCUMENT. 01774 /*! 01775 This method asks for a file, to read the document from, 01776 using the handler of the event its a2dDocumentTemplate. 01777 If a a2dDocumentTemplate was not given as part of the event, the document template 01778 of this document is used to search for possible templates to be used for importing 01779 into this document. The selection is based on GetDocumentTemplate()->GetDocumentTypeName(). 01780 Next a file dialog is presented to select a file to import. 01781 01782 If as part of the event a path+path was already provided, that will be used. 01783 If a2dREFDOC_SILENT was set as flag in the event, no dialogs will appear, when a file+path is available. 01784 */ 01785 void OnImportDocument( a2dDocumentEvent& event ); 01786 01787 //!Set when Owners become zero and document will be deleted. May also be overruled by user. 01788 bool m_askSaveWhenOwned; 01789 01790 //! Filename associated with this document ("" if none). 01791 wxFileName m_documentFile; 01792 01793 //!Document title. 01794 /*! 01795 The document title is used for an associated 01796 frame (if any), and is usually constructed by the framework from the filename. 01797 */ 01798 wxString m_documentTitle; 01799 01800 //!The document type name given to the a2dDocumentTemplate constructor, 01801 /*!is copied to this variable when the document is created. 01802 01803 In a2dDocumentCommandProcessor::AddCreatedDocument() first set this, to search an appropriate template. 01804 01805 It is used later on to select Views from the a2dViewTemplate's. 01806 a2dViewTemplate uses the same documentTypeName as a2dDocumentTemplate's. 01807 01808 The same a2dDocument derived class instances, can have a different m_documentTypeName. 01809 01810 If several view templates are created that use the same document type, 01811 this variable is used in a2dDocumentCommandProcessor::CreateView to collate a list of 01812 alternative view types that can be used on this kind of document. 01813 01814 */ 01815 wxString m_documentTypeName; 01816 01817 //!A pointer to the template from which this document was created 01818 a2dDocumentTemplatePtr m_documentTemplate; 01819 01820 //! modified flag 01821 bool m_documentModified; 01822 01823 //! parant document if set. 01824 a2dDocument* m_documentParent; 01825 01826 //!A pointer to the command processor associated with this document. 01827 a2dSmrtPtr<a2dCommandProcessor> m_commandProcessor; 01828 01829 //! saved flag 01830 bool m_savedYet; 01831 01832 //! set true when document is closed or when busy closing document. 01833 bool m_isClosed; 01834 01835 //! This identifies the document in event processing 01836 /*! Not sure, if this is really used for something */ 01837 wxUint32 m_id; 01838 01839 //! error code used when LoadObject is returning. 01840 a2dError m_lastError; 01841 01842 private: 01843 01844 virtual a2dObject* SmrtPtrOwn(); 01845 //!To release the object, it is not longer owned by the calling object. 01846 /*! the object itself will be deleted when not Owned (the reference count becomes zero) 01847 01848 \remark AskSaveWhenOwned was false, and this document is not Owned by anyone, 01849 the user will now be asked to save the document (when it was modified). 01850 */ 01851 virtual bool SmrtPtrRelease(); 01852 friend class a2dSmrtPtrBase; 01853 }; 01854 01855 class A2DDOCVIEWDLLEXP a2dViewConnector; 01856 class A2DDOCVIEWDLLEXP a2dViewTemplate; 01857 01858 #if (defined(__WXMSW__) && defined(WXUSINGDLL) ) 01859 template class A2DDOCVIEWDLLEXP a2dSmrtPtr<a2dViewConnector>; 01860 #endif 01861 01862 //! Holds a view on a a2dDocument. 01863 /*! 01864 A a2dView is used for displaying a (part of) a2dDocument its data. 01865 It may display this data in any form it wants to. 01866 Several a2dView's can exist on a a2dDocument, and they can be of different types. 01867 A a2dView displays data stored in wxDocument's. 01868 A document can be set for a view, and this will be used by the view 01869 to check if ::wxEVT_UPDATE_VIEWS events coming from the documents, are meant 01870 for the view or not. 01871 If a view wants to display the data of several documents, this should be arranged 01872 in a derived class. 01873 01874 The views using a document work independent of eachother. 01875 When using a a2dDocumentCommandProcessor class, this will know the currently active view, 01876 in general this is the view which has the focus. Meaning its display window 01877 has the focus. 01878 01879 The a2dDocument class uses the a2dEventDistributer to distribute events. 01880 a2dView's register themselfs to the a2dEventDistributer, and therefore will 01881 receive those events. Any wxEvtHandler derived class may be registered to the 01882 a2dEventDistributer. The document does not know all this, it just sent events. 01883 01884 The view may display the data it found in the document, directly to the device or in a 01885 delayed fashion. In which case it stores the data to display first locally, 01886 and as soon as possible this data is updated to the device ( e.g. a window. ) 01887 If the device is a window, the m_display holds a pointer to it. 01888 01889 Views display the data in a document, and therefore if the document data changes, 01890 the view might change because of that. The wxDocument::UpdateAllViews() is 01891 sending ::wxEVT_UPDATE_VIEWS to the docmanager, and this sents 01892 the event to all registered a2dView's. a2dView::OnUpdate() will handle the event. 01893 It checks if it want to process the event coming from that particular document, 01894 and if so updates its own data from that document. 01895 To update all views at every small change made to the document, is often not desired. 01896 Checking a "pending flag" inside the document when the program becomes idle is a better 01897 way to update the views. 01898 01899 Often the view is a rectangular drawing area. The view can use a wxWindow derived class 01900 to display itself. But this is not a must, a view may be stored anywhere. 01901 A view might also display parts of a document(s) via wxDialogs. 01902 How and what is displayed on a view depends on the derived class. 01903 01904 The way to update what is displayed by the view needs to be defined in the handler 01905 for ::wxEVT_UPDATE_VIEWS event. The default OnUpdate, just calls refresh on the display window. 01906 Changes in the document need to result in calling OnUpdate for each view. 01907 OnUpdate may decide to directly redrawn on the device, or only store the view data locally. 01908 In the last case a flag is set to indicate that the view has changed. 01909 This flag is checked in idle time, resulting in an update of the device eventually. 01910 This is the principle behind calling m_display->Refresh() after 01911 changing a document or a view its display data. 01912 This will result in a wxPaintEvent, which will redraw the view data. 01913 01914 When the display device is a window, the wxPaintEvent event handled in the window, may 01915 request a redraw of certain areas within the view. The view may do this by 01916 actually redrawing directly from the document, or in case of local stored data, 01917 return/redraw only this locally stored data directly on the window. 01918 In some cases the data displayed on the window, is actually stored locally within 01919 the window, and the window handles paint events itself, without asking the view to redisplay 01920 the damaged areas ( e.g. wxTextCtrl. etc. ). Still the window will need to check 01921 if the view or document did change, to keep its contents up to date. 01922 The member a2dView::OnDraw( wxDC* ) can be used by the display window, to have 01923 the view redraw itself on the window. But of course if not using wxDC based views, 01924 any other method can be used. 01925 The important thing to understand, is that the Updating of a a2dView can happen 01926 at time X, while the display of this updated view can happen at time Y. 01927 Therefore several updates on a view might take place before they are actually 01928 redisplayed. 01929 01930 For printing the view in a2dView::OnPrint(wxDC *dc), you may use 01931 Ondraw to print the contents of a view to a wxDC. 01932 For that you should define a way to draw the view its data on a wxDC. 01933 01934 Events which are sent to a2dView: 01935 01936 All events coming from a2dDocviewGlobals->GetEventDistributer() so also DistributeEvent(), 01937 since a a2dView is by default Registered to it. 01938 01939 In general all wxWindow events of m_display or the wxFrame containing the a2dView 01940 - ::wxEVT_SET_FOCUS ::wxEVT_KILL_FOCUS etc. 01941 01942 View specific events. 01943 - a2dViewEvent -> type = ::wxEVT_CLOSE_VIEW 01944 - a2dViewEvent -> type = ::wxEVT_ACTIVATE_VIEW sent to a2dDocviewGlobals->GetEventDistributer() and view itself from Activate() 01945 - a2dViewEvent -> type = ::wxEVT_CREATE_VIEW sent to view from a2dViewTemplate::CreateView() 01946 Called by framework if created automatically by the default document 01947 manager class: gives view a chance to initialise 01948 e.g. void OnCreateView( a2dViewEvent* event ); 01949 - a2dViewEvent -> type = ::wxEVT_SET_DOCUMENT sent to view itself when calling SetDocument() 01950 - a2dDocumentEvent -> type = ::wxEVT_CHANGEDFILENAME_DOCUMENT via DistributeEvent() 01951 - a2dDocumentEvent -> type = ::wxEVT_CLOSE_VIEWS 01952 - a2dViewEvent -> type = ::wxEVT_ENABLE_VIEW sent to m_display and up, when a view is enabled or disabled. 01953 - ::wxEVT_REMOVE_VIEW sent to document when a view is not using the document anymore. \see SetDocument() 01954 - ::wxEVT_ADD_VIEW sent to document when a view start using a document \see SetDocument() 01955 01956 - ::wxEVT_CHANGEDFILENAME_VIEW See OnChangeFilename() 01957 - ::wxEVT_CHANGEDTITLE_VIEW See OnChangeTitle() 01958 01959 \ingroup docview 01960 */ 01961 class A2DDOCVIEWDLLEXP a2dView: public a2dEvtHandler 01962 { 01963 DECLARE_ABSTRACT_CLASS(a2dView) 01964 01965 A2D_DECLARE_EVENT_TABLE() 01966 01967 public: 01968 // a2dView(a2dDocument *doc = (a2dDocument *) NULL); 01969 01970 //! constructor 01971 a2dView(); 01972 01973 //! destructor 01974 ~a2dView(); 01975 01976 //! construct with other view 01977 a2dView( const a2dView& other); 01978 01979 //! A closed flag is set when a view is closed. 01980 /*! This flag is set just before the actual closing will take place. 01981 If the close is vetod, it will be reset at the end of the closing action, 01982 else it will stay true. 01983 The flag is a handy test for associated windows, to see if their 01984 view is already closed or not. 01985 */ 01986 bool IsClosed() { return m_isClosed; } 01987 01988 //! sets closed flag to true, and calls Release() view. 01989 /*! 01990 Normally Close() should be used, but in cases where a view is used temporarely and without 01991 a display window ( e.g using a view for rendering to bitmap ), this 01992 can be used to properly close a view without sending extra events. 01993 */ 01994 void SetClosed(); 01995 01996 //! returns true if view was enabled/disabled, false if nothing done 01997 /*! 01998 Sets the view enabled or disabled, which means that no events will be processed, 01999 except ::wxEVT_ENABLE_VIEW and ::wxEVT_ENABLE_VIEWS. 02000 02001 The ::wxEVT_ENABLE_VIEW event is sent to the view and the display window (if available). 02002 After that the new state is set. 02003 02004 If the view is already in the requested state, nothing is done. 02005 */ 02006 bool Enable(bool enable); 02007 02008 //! return true if the view is enabled. See Enable() 02009 bool GetEnabled() { return m_viewEnabled; } 02010 02011 //!Set the display window. 02012 /*! 02013 The display window can be used to display the view on a wxWindow. 02014 This is \b not a must, since a view might also be displayed into a bitmap etc. 02015 But in that case this needs to be arranged in a derived class. 02016 The default is using a display wxWindow. 02017 02018 The window may be set in a derived view class. 02019 But often it is better to set it from a specialized a2dViewConnector. 02020 If needed in combination with a specialized a2dViewTemplate. 02021 This makes it easier to make general view classes, which can be used 02022 in several types of applications or display windows. 02023 02024 \remark this function has only effect if the view its eventhandler is enabled. 02025 The reason is that some events like a2dCloseViewEvent are set up to the m_display window, 02026 during that time the event handler is disabled to prevent looping. But also the m_display 02027 should stay constant during that time. 02028 */ 02029 virtual void SetDisplayWindow( wxWindow* display ); 02030 02031 //!Get the display window. 02032 wxWindow* GetDisplayWindow() { return m_display; } 02033 02034 //! Get the id of the view (used for identification in event processing 02035 wxUint32 GetId() { return m_id; } 02036 02037 //! get the document of the view 02038 /*! \return NULL if no document is set. */ 02039 a2dDocument *GetDocument() const { return m_viewDocument; } 02040 02041 //! Set the document for the view and add it to the document its viewlist. 02042 /*! 02043 Normally called by the framework. 02044 02045 If the view already has a document set, the view is first removed from 02046 that document, sending a ::wxEVT_REMOVE_VIEW event to the old document, the same event is 02047 distributed application broad via the a2dDocviewGlobals->GetEventDistributer(). 02048 See a2dDocumentCommandProcessor::OnRemoveView() where this event is used to reset the last active view. 02049 02050 02051 Next the new document will be set for the view, and added to the viewlist 02052 of the new document, sending a ::wxEVT_ADD_VIEW event to the new document. 02053 02054 At last a a2dViewEvent event of type ::wxEVT_SET_DOCUMENT is sent to the a2dView. 02055 So if extra administrative tasks for the view are needed when setting a view to a document, 02056 intercept that event to do it. 02057 */ 02058 void SetDocument(a2dDocument *doc); 02059 02060 //! get type name of the view. 02061 /*! 02062 This name is used to couple document types to view types. 02063 See a2dViewTemplate. 02064 */ 02065 wxString GetViewTypeName() const { return m_viewTypeName; } 02066 02067 //! get the a2dViewTemplate with which this view was created 02068 /*! 02069 \see a2dViewTemplate. 02070 */ 02071 a2dViewTemplate* GetViewTemplate() const { return m_viewTemplate; } 02072 02073 //! to set the view template from which this view was created. 02074 void SetViewTemplate( a2dViewTemplate* viewtemplate ) { m_viewTemplate = viewtemplate; } 02075 02076 //! set type name of the view. 02077 /*! 02078 This name is used to couple document types to view types. 02079 See a2dViewTemplate. 02080 */ 02081 void SetViewTypeName(const wxString& name) { m_viewTypeName = name; } 02082 02083 //! needs to be implemented to print a view, also so used for simple redrawing of views. 02084 /*! 02085 Normal updating the data of a view, is via OnUpdate, called from the changed a2dDocument. 02086 Once the view its data is up to data, m_display->Refresh() results in a paint event. 02087 This in a2dDocumentViewScrolledWindow and a2dDocumentViewWindow directly leads to OnDraw(), 02088 redrawing the data of the view on the display window. 02089 In a2dDocumentViewScrolledWindow and a2dDocumentViewWindow the wxPaintEvent is intercepted 02090 and by default redirected via its OnDraw() to the view Ondraw() function here. 02091 If it is a clever implementation, the above refresh should only refresh the areas 02092 in the view which did change. 02093 In m_display->GetUpdateRegion() is where you should get those regions, while the paint 02094 event is being handled. 02095 02096 A more complicated situation is as follows. 02097 Paint events are generated when a wxWindow becomes visible, 02098 or when you draw something to it. The regions needing an update, or reported by the 02099 Paint event. 02100 The view does not need to do a complete re-drawn, only the damaged regions. 02101 In such a case you should Handle the paint event Your self in the m_display 02102 window, and redirect it to the a2dView. 02103 In the a2dView you can iterate over the damaged regions, and only redraw 02104 the view its data in those regions. 02105 */ 02106 virtual void OnDraw(wxDC *dc) = 0; 02107 02108 //! called from a2dDocumentPrintout when printing a view. 02109 /*! 02110 Default calls OnDraw(wxDC *dc) 02111 */ 02112 virtual void OnPrint(wxDC *dc, wxObject *info); 02113 02114 //! force a2dDocumentEvent ::wxEVT_UPDATE_VIEWS event 02115 virtual void Update( unsigned int hint = 0, wxObject* hintObject = NULL ); 02116 02117 //! default handler for a2dDocumentEvent ::wxEVT_UPDATE_VIEWS 02118 /*! 02119 Updates the view data ( e.g the data that the view displays has changed in the document). 02120 The view may hold/display data which should change when the document(s) changes. 02121 Here this data can be updated, the internal data of the view can be updated. 02122 When the view will be redisplayed depends on the derived class. 02123 One can set a dirty flag after changing the view its data, and do the redisplay 02124 in idle time, where this flag is checked. But often there is no need 02125 to do this, since the view can directly update its Display window, or 02126 tell it that it needs to update itself. 02127 Therefore the default here simply calls m_display->Refresh(), which leads to a 02128 paint event on the display window, and that might/should call a2dView::Ondraw(). 02129 */ 02130 void OnUpdate( a2dDocumentEvent& event ); 02131 02132 //! default handler for a2dDocumentEvent of type ::wxEVT_ENABLE_VIEWS 02133 /*! 02134 This enable or disables the view by calling Enable( event.GetEnable() ). 02135 But only if the a2dDocument from which this document was sent, is the 02136 one the a2dView is using. 02137 If the view from which the event originated is specified in the event, 02138 that view will not process the event, all others will. 02139 */ 02140 void OnEnableViews( a2dDocumentEvent& event ); 02141 02142 //! handler for the ::wxEVT_REPORT_VIEWS 02143 /*! 02144 The handlers adds this a2dView to the reportlist of the event, if 02145 it depends on the document sending the event. The default simply 02146 checks that the view its document is the one sending the event, and if so 02147 adds it. In case your view displays info of several documents, you should 02148 intercept this event to implement this behaviour. 02149 */ 02150 void OnReport( a2dDocumentEvent& event ); 02151 02152 //! default handler for EVT_ENABLE_VIEW event. 02153 void OnEnable( a2dViewEvent& event ); 02154 02155 //! default handler for file changed event sent from a2dDocument with type wxEVT_CHANGEDFILENAME_DOCUMENT 02156 /*! 02157 Creates new event of type wxEVT_CHANGEDFILENAME_VIEW, which also knows the view now. 02158 Sends the event to the DisplayWindow, there or in its parent hiearchy it can be intercepted. 02159 */ 02160 void OnChangeFilename( a2dDocumentEvent& event ); 02161 02162 //! default handler for file changed event sent from a2dDocument with type wxEVT_CHANGEDTITLE_DOCUMENT 02163 /*! 02164 Creates new event of type wxEVT_CHANGEDTITLE_VIEW, which also knows the view now. 02165 Sends the event to the DisplayWindow, there or in its parent hiearchy it can be intercepted. 02166 */ 02167 void OnChangeTitle( a2dDocumentEvent& event ); 02168 02169 //! Close a view and remove the view from its document. 02170 /*! 02171 IMPORTANT there are two ways/paths through which a view can be closed. 02172 -# by closing the frame containing the view(s). 02173 -# by the docmanager closing a document and this one closing the views on the document. 02174 02175 The first one will destroy the frames, and it must Close the view(s) it contains. 02176 The second one must make sure that the frames containing the views will be destroyed. 02177 This is why ::wxEVT_CLOSE_VIEW travels up in the hiearchy of windows, starting at m_display window. 02178 02179 Close() generates a ::wxEVT_CLOSE_VIEW event, which is first redirected 02180 to the a2dDocument, and if not vetod there, to the m_display wxWindow. 02181 if not vetod there, the event is sent to a2dView itself. 02182 02183 If not vetod in the ::wxEVT_CLOSE_VIEW handler of the view, 02184 the View Will be removed and released from the document. 02185 The view will be set Inactive. 02186 The m_display wxWindow will be disabled, to prevent it from sending more events. 02187 02188 When the ::wxEVT_CLOSE_VIEW is sent to the m_display window, the 02189 a2dView itself is disabled for handling events, untill the event is 02190 (not)processed by the display and return. 02191 So event coming back to the view will not be handled during that time. 02192 The ::wxEVT_CLOSE_VIEW is sent to m_display, but the event is of the type 02193 that travels up to the parent window if not handled. 02194 So if not handled in the display window, it will go to the parent window. 02195 Eventually it arives in the wxFrame holding the windows. 02196 The idea is thay you do intercept ::wxEVT_CLOSE_VIEW event somewhere in the hierarchy 02197 of windows, and make sure the a2dView is correctly detached from the windows 02198 where it is used. 02199 In case the event is not vetod by the display 02200 window, it is a good habbit that it sets the display window 02201 of this/its view to NULL, this will prevent events coming from this view 02202 to the display window for sure. 02203 02204 This is the clue to having view independent frames and windows. 02205 A specialized frame or window, can use different types of connectors to deal 02206 with different types of attached views. 02207 02208 Always be aware of dangling pointers from the display window, which normally will/should 02209 have a pointer to the view. Also other classes having somehow a pointer to this view 02210 (which will be closed and released soon), should take care of this by intercepting the 02211 ::wxEVT_CLOSE_VIEW event. Therefore the display window, in such cases should 02212 redirect the ::wxEVT_CLOSE_VIEW event to such classes. 02213 Default the event will be redirected to the parent window, if not handled or skipped. 02214 02215 When not vetod Close() \b the DisplayWindow m_display is set to NULL first. 02216 The reason for disabling the display window is to prevent it from 02217 sending more events to this view, which will be deleted soon. 02218 02219 In any case the ::wxEVT_CLOSE_VIEW handler should check whether the view is being deleted forcibly, 02220 using a2dCloseViewEvent::CanVeto(). If so it needs to perform the nessecary cleanup. 02221 Else it may veto. 02222 02223 Example: 02224 02225 \code 02226 02227 //the next class interecepts the ::wxEVT_CLOSE_VIEW 02228 void wxSomeClass::OnCloseView( a2dCloseViewEvent& event ) 02229 { 02230 //test if the frame or windows where not already deleted 02231 // 02232 if ( event.GetForce() && GetViewFrame() ) 02233 { 02234 event.GetView()->SetDisplayWindow( NULL ); 02235 m_display->Disable(); 02236 m_display->Destroy(); 02237 m_display = NULL; 02238 } 02239 } 02240 \endcode 02241 02242 Closing a view recursive, while its busy closing itself is not a problem. 02243 The owning objects may recursively call this function without problem, for that 02244 the m_isClosed flag is set at the beginning which prevents closing twice. 02245 the view object itself will be released only once in the end. 02246 The ::wxEVT_CLOSE_VIEW will be issued only once. 02247 02248 If the view has a document set, the view is first removed from 02249 that document, sending a ::wxEVT_REMOVE_VIEW event to the old document, the same event is 02250 distributed application broad via the a2dDocviewGlobals->GetEventDistributer(). 02251 See a2dDocumentCommandProcessor::OnRemoveView() where this event is used to reset the last active view. 02252 02253 \remark a2dView is reference counted and will only be really deleted when it reaches zero 02254 02255 \remark In wxWindows the handler function for ::wxEVT_CLOSE_WINDOW event is called when the user has tried 02256 to close a frame using the window manager (X) or system menu (Windows). 02257 The ::CLOSE_WINDOW event should normally be intercepted, and ask via 02258 calling a2dView::Close if it is oke to close the view. In a2dDocumentFrame this arranged. 02259 02260 \remark You may call also a2dView::Close() directly, it will generate the same events. 02261 02262 \return true is view was properly closed and not vetod else false 02263 02264 */ 02265 virtual bool Close( bool force = false); 02266 02267 //! ::wxEVT_CLOSE_VIEW event handler to do cleanup/veto Close of the view. 02268 /*! 02269 The default handler does nothing yet. 02270 02271 The Handler for ::wxEVT_CLOSE_VIEW, resulting from view close via 02272 a2dView:Close() ( either via a2dDocument or a wxFrame containing the view) 02273 02274 One may intercept ::wxEVT_CLOSE_VIEW event in a derived class 02275 to Clean up and Destroy windows used for displaying the view. 02276 But it is often better to do this in a wxWindow derived class which contains the view. 02277 Therefore the ::wxEVT_CLOSE_VIEW is first sent to the m_display wxWindow of the a2dView. 02278 02279 The best is to use a a2dViewConnector to create frames and windows to hold a view, 02280 and a2dDocumentFrame derived class to handle Closing of a2dView's. 02281 It will recieve the ::wxEVT_CLOSE_VIEW via the wxWindow 02282 containing the a2dView which is about to be closed. 02283 This makes it easy to use the same view class in other applications. 02284 02285 On closing of a wxFrame, you may decide to Close the window by intercepting 02286 EVT_CLOSE, and from there call a2dView::Close. 02287 It depends on the application how the views are closed. 02288 02289 In any case Windows should be Destroyed, not really deleted. 02290 Destroy only flags for deletion, this means that they will really 02291 be deleted in idle time by wxWindows. 02292 */ 02293 void OnCloseView( a2dCloseViewEvent& event ); 02294 02295 //! handler for ::wxEVT_DISCONNECT_ALLVIEWS 02296 /*! 02297 The ::wxEVT_DISCONNECT_ALLVIEWS is generated by the a2dDocument when it disconnects all views. 02298 This can be when closing the document, or just to attach all views to another document. 02299 */ 02300 void OnDisConnectView( a2dDocumentEvent& event ); 02301 02302 //! Extend event processing to search the view's event table 02303 /*! Some events are handled within the view as if the view is a window within a window. 02304 Therefore the wxWindow containing the view should redirect all its events to 02305 its view(s), when the view does not handle the event it will go to the window itself. 02306 02307 Events handled how: 02308 - ::wxEVT_ENABLE_VIEW & ::wxEVT_ENABLE_VIEWS always processed, sent to GetEventHandler() 02309 - ::wxEVT_ACTIVATE sent from a2dDocumentFrame and derived classes, calls Activate() 02310 - ::wxEVT_SET_FOCUS sent to GetEventHandler() and calls Activate(true) 02311 - ::wxEVT_KILL_FOCUS sent to GetEventHandler() and calls Activate(false) 02312 - ::wxEVT_CLOSE_WINDOW sent from wxWindow containing the a2dView. 02313 calls Close( !closeevent.CanVeto() ) 02314 - ::wxEVT_IDLE sent from wxWindow containing the a2dView, sent to GetEventHandler() 02315 and to the a2dDocument. 02316 */ 02317 virtual bool ProcessEvent(wxEvent& event); 02318 02319 //! is called via ProcessEvent() when the view becomes active 02320 /*! 02321 Generates a ::wxEVT_ACTIVATE_VIEW with active == activate. 02322 This event is distributed if m_DoDistributeActivateEvent is true. 02323 When recieved by a2dDocumentCommandProcessor::OnActivateView() this way, 02324 the last will deactivate its current active view, using this same function. 02325 02326 The event ::wxEVT_ACTIVATE_VIEW_SENT_FROM_CHILD event is sent to the m_display window or frame. 02327 This is the event to catch in order to set the view in the containing frame/windows. 02328 For example a2dDocumentFrame use sthis event to set the view to which it will sent window close events. 02329 02330 Can also be called directly to notify the view that it should go (in)active. 02331 02332 \sa a2dViewEvent. 02333 */ 02334 void Activate(bool activate); 02335 02336 //! return if the view is active/ 02337 /*! 02338 a view is in general active when its m_display window has the focus or is selected. 02339 */ 02340 bool GetActive() { return m_active; } 02341 02342 //! \see m_DoDistributeActivateEvent 02343 void SetDoDistributeActivateEvent( bool doDistributeActivateEvent ) { m_DoDistributeActivateEvent = doDistributeActivateEvent; } 02344 02345 02346 #if wxUSE_PRINTING_ARCHITECTURE 02347 02348 //! called from the a2dDocumentCommandProcessor to create a wxPrintout are derived class 02349 /*! for printing a view 02350 If the printing framework is enabled in the library, this function returns a 02351 wxPrintout object for the purposes of printing. 02352 It should create a new object every time it is called; 02353 the framework will delete objects it creates. 02354 By default, this function returns an instance of wxDocPrintout, 02355 which prints and previews one page by calling wxView::OnDraw. 02356 02357 Override to return an instance of a class other than wxDocPrintout. 02358 02359 \param typeOfPrint When called from a2dDocumentCommandProcessor, the a2dCommand that lead to this call. 02360 */ 02361 virtual wxPrintout *OnCreatePrintout( a2dCommand* typeOfPrint ); 02362 #endif 02363 02364 protected: 02365 02366 //! called on (de)activating (wxWindow) containing the view. 02367 //void OnActivate(wxActivateEvent& event); 02368 02369 //! when a view gets the focus ( when only one view per window 02370 /*! that view gets the focus if the window gets the focus ) 02371 Else the window getting the focus should decide which view gets the focus. 02372 */ 02373 void OnSetFocus( wxFocusEvent &event ); 02374 02375 //! when a view goes out of focus ( when only one view per window 02376 /*! that view goes out of focus if the window goes out of focus ) 02377 Else the window getting the focus should decide which view goes out of focus. 02378 */ 02379 void OnKillFocus( wxFocusEvent &event ); 02380 02381 //! close flag, to indicate that the view is being closed are is closed. 02382 bool m_isClosed; 02383 02384 //! the document to which this view belongs. 02385 a2dSmrtPtr<a2dDocument> m_viewDocument; 02386 02387 //! set via the a2dViewTemplate on generation of this view. 02388 wxString m_viewTypeName; 02389 02390 //! view was created from this view template or if not used NULL 02391 a2dViewTemplatePtr m_viewTemplate; 02392 02393 //! true if this view is activated ( its display window has the focus and recieves mouse events ) 02394 bool m_active; 02395 02396 //! true if this view does distribute the does Distribute the ::wxEVT_ACTIVATE_VIEW event. 02397 /*! 02398 Normally Activate() sents the a2dViewEvent of type ::wxEVT_ACTIVATE_VIEW to the a2dEventDistributer. 02399 This flag is set false to prevent this. 02400 This is needed when you want to prevent this view from being part of the 02401 a2DocumentCommandProcessor maintained/controlled active view. 02402 A situation like this occurs when a view is used standalone within in its m_display window, 02403 and should not influence the current active view inside the a2dDocumentCommandProcessor. 02404 02405 A typical example is: using a wxWindow display windows with a a2dView and its a2dDocument, 02406 where the document will never have more views, and used completely standalone as if its is 02407 a dialog window. 02408 A toolbar like window to show/edit/manipulate some information, is a good example. 02409 The view can still distribute and recieve other distributed events. 02410 */ 02411 bool m_DoDistributeActivateEvent; 02412 02413 //! Is the view enabled? 02414 /*! 02415 true if this view is enabled and will process all events. 02416 else only ::wxEVT_ENABLE_VIEW and ::wxEVT_ENABLE_VIEWS will be processed. 02417 */ 02418 bool m_viewEnabled; 02419 02420 //! In case of using a window for displaying the view, this holds the window. 02421 wxWindow* m_display; 02422 02423 //! This identifies the view in event processing 02424 wxUint32 m_id; 02425 02426 //! this is used to keep the view alive if no other references are there. 02427 //! This untill the view is closed by calling Close() or SetClosed() 02428 a2dSmrtPtr<a2dView> m_keepalive; 02429 02430 private: 02431 02432 virtual a2dObject* SmrtPtrOwn(); 02433 virtual bool SmrtPtrRelease(); 02434 friend class a2dSmrtPtrBase; 02435 }; 02436 02437 02438 //! The a2dDocumentTemplate class is used to model the relationship between a document class and files 02439 /*! 02440 Next to that, a a2dViewConnector class pointer 02441 is used to generate new views for new documents, or whatever the a2dViewConnector finds 02442 appropriate to do when a new document is created by the a2dDocumentCommandProcessor via a a2dDocumentTemplate. 02443 02444 Normally new views are created by the a2dViewConnector class via a a2dViewTemplate. 02445 When and where this new view will be displayed, is up to the a2dViewConnector. 02446 02447 After CreateDocument created a new document, 02448 it sents a ::wxEVT_POST_CREATE_DOCUMENT event to the a2dViewConnector class m_connector. 02449 The a2dViewConnector derived class may intercept the event to 02450 created new a2dView's for the new a2dDocument. 02451 This is what the default handler ::wxEVT_POST_CREATE_DOCUMENT 02452 in a2dViewConnector::OnPostCreateDocument() does do. 02453 It first uses the a2dDocumentCommandProcessor to display the available a2dViewTemplate's 02454 for the new created document type. 02455 The user chooses one, and that a2dViewTemplate will be used 02456 to create the first view on the document with a2dViewTemplate::CreateView(). 02457 But in other situations, one might prefer to hook the new document into an existing view. 02458 The existing view its current document is disconnected from the view, and the new one 02459 is connected to the view. 02460 a2dViewTemplate::CreateView() is what generates the ::wxEVT_POST_CREATE_VIEW which is also 02461 redirected to a a2dViewConnector. This event may or may no be handled by a connector. 02462 It depends on the application, how a connector wants to connect new views into the application. 02463 02464 \remark It is possible that newly created documents do not need a view. 02465 Therefore the connector class pointer may be NULL. 02466 02467 \sa a2dDocumentTemplateEvent 02468 \sa a2dViewTemplateEvent 02469 02470 \ingroup docview 02471 */ 02472 class A2DDOCVIEWDLLEXP a2dDocumentTemplate: public a2dObject 02473 { 02474 02475 DECLARE_CLASS(a2dDocumentTemplate) 02476 02477 public: 02478 02479 //! Associate document and view types. They're for identifying what view is associated with what template/document type 02480 /*! 02481 Constructor. Create instances dynamically near the start of your 02482 application after creating a a2dDocumentCommandProcessor instance, and before doing 02483 any document or view operations. 02484 02485 \param descr is a short description of what the template is for. This string 02486 will be displayed in the file filter list of Windows file selectors. 02487 02488 \param filter is an appropriate file filter such as *.txt OR "*.cal;*.gds" for more the one. 02489 02490 \param dir is the default directory to use for file selectors. 02491 02492 \param ext is the default file extension (such as txt). 02493 02494 \param docTypeName is a name that should be unique for a given type of document, 02495 used for gathering a list of views relevant to a particular document. 02496 02497 \param docClassInfo is a pointer to the run-time document class information as returned 02498 by the CLASSINFO macro, e.g. CLASSINFO(MyDocumentClass). If this is not supplied, 02499 you will need to derive a new a2dDocumentTemplate class and override the CreateDocument 02500 member to return a new document instance on demand. 02501 02502 \param connector connector to use to attach this type of template to GUI. 02503 02504 \param flags is a bit list of the following: 02505 02506 - a2dTemplateFlag::VISIBLE The template may be displayed to the user in dialogs. 02507 - wxREFTEMPLATE_INVISIBLE The template may not be displayed to the user in dialogs. 02508 - a2dTemplateFlag::DEFAULT Defined as a2dTemplateFlag::VISIBLE. 02509 02510 \param handlerIn IO handler needed to read this type of files into the document. 02511 \param handlerOut IO handler needed to write this type of files from the document. 02512 02513 */ 02514 a2dDocumentTemplate( 02515 const wxString& descr, 02516 const wxString& filter, 02517 const wxString& dir, 02518 const wxString& ext, 02519 const wxString& docTypeName, 02520 wxClassInfo *docClassInfo = (wxClassInfo *) NULL, 02521 a2dViewConnector* connector = (a2dViewConnector*) NULL, 02522 long flags = a2dTemplateFlag::DEFAULT, 02523 a2dIOHandlerStrIn* handlerIn = NULL, 02524 a2dIOHandlerStrOut* handlerOut = NULL ); 02525 02526 //! Destructor. 02527 ~a2dDocumentTemplate(); 02528 02529 //! create an exact copy of this property 02530 virtual a2dObject* Clone( CloneOptions options ) const; 02531 02532 //! Creates a new document. 02533 /*! 02534 Creates a new instance of the associated document class. 02535 If you have not supplied a wxClassInfo parameter to the template constructor, 02536 you will need to override this function to return an appropriate document instance. 02537 02538 After creating a new document two event are generated: 02539 02540 - a2dDocumentEvent of type ::wxEVT_CREATE_DOCUMENT sent to document 02541 - a2dDocumentTemplateEvent of type ::wxEVT_POST_CREATE_DOCUMENT sent to a2dViewConnector. 02542 */ 02543 virtual a2dDocument *CreateDocument( const wxFileName& path, a2dDocumentFlagMask flags = a2dREFDOC_NON ); 02544 02545 //! sents a wxEVT_PRE_ADD_DOCUMENT event to m_connector if available elase distributes the event. 02546 /*! 02547 This event is sent to the m_connector a2dViewConnector of the template, and the sender/eventObject is this template. 02548 It is sent just before a new created document is added to the framework. 02549 The a2dViewConnector can react to this action by closings existing documents and disconnect frames and views. 02550 At this stage the a2dDocumentCommandProcessor() its current document has not changed yet. 02551 02552 \param newDoc the new document which was created 02553 \param flags some flags telling for what purpose the new document was created. e.g a2dREFDOC_NEW 02554 */ 02555 a2dDocument* SentPreAddCreatedDocumentEvent( a2dDocument* newDoc, a2dDocumentFlagMask flags ); 02556 02557 //! sents a wxEVT_POST_CREATE_DOCUMENT called in general from a2dDocumentCommandProcessor() when a new document was created. 02558 /*! 02559 This event is sent to the m_connector a2dViewConnector of the template, and the sender/eventObject is this template. 02560 The a2dViewConnector can react in several ways to this action: 02561 - create one or more new a2dView's ( if wanted a a2dViewTemplate can help to choose one ) 02562 - use one or more existing a2dView's 02563 - create no a2dView at all 02564 - merge or copy the contents of the new a2dDocument, and directly close this new document, of course no new views generated then. 02565 - next to creating one or more a2dViews or re-using one or more a2dViews, also the a2dDocumentFrame's and/or 02566 a2dDocumentViewWindow's can be created or reused to connect the views into. 02567 02568 The default implementation see a2dViewConnector::OnPostCreateDocument(). 02569 02570 In a derived a2dViewConnector you can implement your own handler, to treat the new document in ways more 02571 appropriate to your application. 02572 02573 \param newDoc the new document which was created 02574 \param flags some flags telling for what purpose the new document was created. e.g a2dREFDOC_NEW 02575 02576 */ 02577 bool SentPostCreateDocumentEvent( a2dDocument* newDoc, a2dDocumentFlagMask flags ); 02578 02579 //! Returns the default file extension for the document data, as passed to the document template constructor. 02580 wxString GetDefaultExtension() const { return m_defaultExt; } 02581 02582 //! Returns the text description of this template, as passed to the document template constructor 02583 wxString GetDescription() const { return m_description; } 02584 02585 //! Returns the default directory, as passed to the document template constructor. 02586 wxString GetDirectory() const { return m_directory; } 02587 02588 //! Returns the file filter, as passed to the document template constructor. 02589 wxString GetFileFilter() const { return m_fileFilter; } 02590 02591 //! Returns the flags, as passed to the document template constructor. 02592 const a2dTemplateFlag& GetFlags() const { return m_flags; } 02593 02594 //! Sets the internal document template flags (see the constructor description for more details). 02595 void SetFlags( a2dTemplateFlagMask flags) { m_flags.SetFlags( flags ); } 02596 02597 //! Sets the internal document template flags (see the constructor description for more details). 02598 void SetFlags( a2dTemplateFlag flags) { m_flags = flags; } 02599 02600 //! does template mask match 02601 bool CheckMask( a2dTemplateFlagMask mask ) { return m_flags.CheckMask( mask ); } 02602 02603 //! Returns the document type name, as passed to the document template constructor. 02604 wxString GetDocumentTypeName() const { return m_docTypeName; } 02605 02606 //! Sets the file filter. 02607 void SetFileFilter(const wxString& filter) { m_fileFilter = filter; } 02608 02609 //! Sets the default directory. 02610 void SetDirectory(const wxString& dir) { m_directory = dir; } 02611 02612 //! Sets the template description. 02613 void SetDescription(const wxString& descr) { m_description = descr; } 02614 02615 //! Sets the default file extension. 02616 void SetDefaultExtension(const wxString& ext) { m_defaultExt = ext; } 02617 02618 //! Returns true if the document template can be shown in user dialogs, false otherwise. 02619 void SetVisible( bool value ) { m_flags.SetFlags( a2dTemplateFlag::VISIBLE ); } 02620 02621 //! Returns true if the document template is marked , false otherwise. 02622 void SetMarked( bool value ) { m_flags.SetFlags( a2dTemplateFlag::MARK ); } 02623 02624 //! Returns true if the document template can be shown in user dialogs, false otherwise. 02625 bool IsVisible() const { return m_flags.GetFlag( a2dTemplateFlag::VISIBLE ); } 02626 02627 //! Returns true if the document template is marked , false otherwise. 02628 bool IsMarked() const { return m_flags.GetFlag( a2dTemplateFlag::MARK ); } 02629 02630 //! to test if a file that needs to be loaded, is suitable for this template. 02631 /*! 02632 The default implementation is testing the file extension of the template against the 02633 file extension in the path. 02634 When no extension is given in the file and a m_ioHandlerStrIn is set, the a2dIOHandler::CanLoad() 02635 is used to test the file contents for that io handler. 02636 At last the m_fileFilter is search for the path extension, if found return true. 02637 */ 02638 virtual bool FileMatchesTemplate(const wxString& path); 02639 02640 //! Get Input handler used to store the document using this template 02641 virtual a2dIOHandlerStrIn* GetDocumentIOHandlerStrIn() { return m_ioHandlerStrIn; } 02642 02643 //! Get output handler used to save the document using this template 02644 virtual a2dIOHandlerStrOut* GetDocumentIOHandlerStrOut() { return m_ioHandlerStrOut; } 02645 02646 //! if there is an io handler, and it can load the document of this template, return it 02647 virtual a2dIOHandlerStrIn* GetDocumentIOHandlerForLoad( a2dDocumentInputStream& stream, a2dDocument* document ); 02648 02649 //! if there is an io handler, and it can save the document of this template, return it 02650 /*! 02651 \param filename when not empty, it is/can be used to choose io handler also based on the extension of the filename. 02652 \param document the document that needs to be saved. 02653 */ 02654 virtual a2dIOHandlerStrOut* GetDocumentIOHandlerForSave( const wxString& filename, a2dDocument* document ); 02655 02656 //! Set Inputhandler used to load the document using this template 02657 virtual void SetDocumentIOHandlerStrIn( a2dIOHandlerStrIn* handler ) { m_ioHandlerStrIn = handler; } 02658 02659 //! Set output handler used to save the document using this template 02660 virtual void SetDocumentIOHandlerStrOut( a2dIOHandlerStrOut* handler ) { m_ioHandlerStrOut = handler; } 02661 02662 //! return the a2dViewConnector that is used for sending the ::wxEVT_POST_CREATE_DOCUMENT too. 02663 a2dViewConnector* GetViewConnector() { return m_connector; } 02664 02665 #if wxUSE_PRINTING_ARCHITECTURE 02666 wxPageSetupData* GetPageSetupData(void) const { return m_pageSetupData; } 02667 void SetPageSetupData(const wxPageSetupData& pageSetupData) { *m_pageSetupData = pageSetupData; } 02668 #endif 02669 02670 wxClassInfo* GetDocumentClassInfo() const { return m_docClassInfo; } 02671 02672 //! if set this will be used instead of m_docClassInfo to initiate new documents 02673 a2dDocument* GetDocumentCreate() { return m_documentCreate; } 02674 02675 //! if set this will be used instead of m_docClassInfo to initiate new documents 02676 /*! 02677 Id set a clone of this document will be used to create new documents through this 02678 a2dDocumentTemplate. This is handy when a document has a lot of initial settings which 02679 can now be set once here. So for each document type/purpose you can have unique settings. 02680 02681 \remark m_docClassInfo still needs ot be set. 02682 */ 02683 void SetDocumentCreate( a2dDocument* documentCreate ) { m_documentCreate = documentCreate; } 02684 02685 protected: 02686 02687 #if wxART2D_USE_CVGIO 02688 virtual void DoSave( wxObject* parent, a2dIOHandlerXmlSerOut &out, a2dXmlSer_flag xmlparts, a2dObjectList* towrite ); 02689 virtual void DoLoad( wxObject* parent, a2dIOHandlerXmlSerIn& parser, a2dXmlSer_flag xmlparts ); 02690 #endif //wxART2D_USE_CVGIO 02691 02692 //! The flags passed to the constructor. 02693 a2dTemplateFlag m_flags; 02694 02695 //! The file filter (such as *.txt) to be used in file selector dialogs. 02696 wxString m_fileFilter; 02697 02698 //! The default directory for files of this type. 02699 wxString m_directory; 02700 02701 //! A short description of this template 02702 wxString m_description; 02703 02704 //! The default extension for files of this type 02705 wxString m_defaultExt; 02706 02707 //! The named type of the document associated with this template. 02708 wxString m_docTypeName; 02709 02710 //! Run-time class information that allows document instances to be constructed dynamically. 02711 wxClassInfo* m_docClassInfo; 02712 02713 //! if set this will be used instead of m_docClassInfo to initiate new documents 02714 a2dDocumentPtr m_documentCreate; 02715 02716 //! used for reading the document from streams. 02717 a2dSmrtPtr<a2dIOHandlerStrIn> m_ioHandlerStrIn; 02718 02719 //! used for writing the document to streams. 02720 a2dSmrtPtr<a2dIOHandlerStrOut> m_ioHandlerStrOut; 02721 02722 //! class used to connect new views with Frames and windows. 02723 a2dSmrtPtr<a2dViewConnector> m_connector; 02724 02725 #if wxUSE_PRINTING_ARCHITECTURE 02726 //! this is the printer page setup data for all documents with this template 02727 wxPageSetupData* m_pageSetupData; 02728 #endif 02729 02730 private: 02731 02732 virtual a2dObject* SmrtPtrOwn(); 02733 virtual bool SmrtPtrRelease(); 02734 friend class a2dSmrtPtrBase; 02735 }; 02736 02737 02738 //! Automatic template, which searches a suitable handler for the document. 02739 /*! 02740 a2dDocviewGlobals->GetDocviewCommandProcessor()->GetDocTemplates() is used 02741 to find a template which fits the document type of the template. 02742 02743 An extra test is performed in GetDocumentIOHandlerForLoad() GetDocumentIOHandlerForSave(), 02744 to see if that template can be used for saving or loading the document. 02745 02746 This template is handy in use when you what an All Files template. 02747 The document with this template, will automatically choose the right handler for files you choose. 02748 Extension is not important. 02749 02750 */ 02751 class A2DDOCVIEWDLLEXP a2dDocumentTemplateAuto: public a2dDocumentTemplate 02752 { 02753 02754 DECLARE_CLASS(a2dDocumentTemplateAuto) 02755 02756 public: 02757 02758 a2dDocumentTemplateAuto( 02759 const wxString& descr, 02760 const wxString& filter, 02761 const wxString& dir, 02762 const wxString& ext, 02763 const wxString& docTypeName, 02764 wxClassInfo *docClassInfo = (wxClassInfo *) NULL, 02765 a2dViewConnector* connector = (a2dViewConnector*) NULL, 02766 long flags = a2dTemplateFlag::DEFAULT ); 02767 02768 //! Destructor. 02769 ~a2dDocumentTemplateAuto(); 02770 02771 //! if there is an io handler, and it can load the document of this template, return it 02772 virtual a2dIOHandlerStrIn* GetDocumentIOHandlerForLoad( a2dDocumentInputStream& stream, a2dDocument* document ); 02773 02774 //! if there is an io handler, and it can save the document of this template, return it 02775 /*! 02776 \param filename when not empty, it is/can be used to choose io handler also based on the extension of the filename. 02777 \param document the document that needs to be saved. 02778 */ 02779 virtual a2dIOHandlerStrOut* GetDocumentIOHandlerForSave( const wxString& filename, a2dDocument* document ); 02780 02781 }; 02782 02783 //! The a2dViewTemplate class is used to model the relationship between a document class and a view class. 02784 /*! 02785 Next to that, a a2dViewConnector class pointer 02786 is used to connect new views and documents into a wxFrame and/or wxWindow. 02787 The a2dDocumentCommandProcessor can be used to display a dialog with a list of available 02788 a2dViewTemplate's for a certain document type. 02789 Using the choosen a2dViewTemplate, this template will then be used to create 02790 a view on the document. This happens in CreateView(). 02791 02792 When, how and where this new view will be displayed, is up to the a2dViewConnector. 02793 02794 CreateView() sents two events: 02795 - ::wxEVT_CREATE_VIEW event sent to the new view. 02796 - ::wxEVT_POST_CREATE_VIEW event sent to the a2dViewConnector class m_connector. 02797 02798 The a2dViewConnector derived class often intercepts the event to connect 02799 the created a2dView into (newly created or existing) Frames or Windows. 02800 02801 It is possible that newly created view do not need to be plugged into any Window or Frame. 02802 Therefore the connector class pointer may be NULL. 02803 02804 \see a2dDocumentTemplate 02805 02806 \see a2dViewConnector 02807 02808 \ingroup docview 02809 */ 02810 class A2DDOCVIEWDLLEXP a2dViewTemplate: public a2dObject 02811 { 02812 02813 DECLARE_CLASS(a2dViewTemplate) 02814 02815 public: 02816 02817 #if wxART2D_USE_CVGIO 02818 virtual void DoSave( wxObject* parent, a2dIOHandlerXmlSerOut &out, a2dXmlSer_flag xmlparts, a2dObjectList* towrite ); 02819 virtual void DoLoad( wxObject* parent, a2dIOHandlerXmlSerIn& parser, a2dXmlSer_flag xmlparts ); 02820 #endif //wxART2D_USE_CVGIO 02821 02822 //! Associate document and view types. They're for identifying what view is associated with what template/document type 02823 /*! 02824 Constructor. Create instances dynamically near the start of your 02825 application after creating a a2dDocumentCommandProcessor instance, and before doing 02826 any document or view operations. 02827 02828 \param descr is a short description of what the template is for. This string 02829 will be displayed in the file filter list of Windows file selectors. 02830 02831 \param docTypeName is a name that should be unique for a given type of document, 02832 used for gathering a list of views relevant to a particular document. 02833 02834 \param viewTypeName is a name that should be unique for a given view. 02835 02836 \param viewClassInfo is a pointer to the run-time view class information as 02837 returned by the CLASSINFO macro, e.g. CLASSINFO(MyViewClass). 02838 If this is not supplied, you will need to derive a new a2dDocumentTemplate 02839 class and override the CreateView member to return a new view instance on demand. 02840 02841 \param connector is a pointer to a a2dViewConnector class, which will be used in 02842 the default handler for the ::wxEVT_POST_CREATE_VIEW event, OnPostCreateView to redirect 02843 the event to the a2dViewConnector class. If NULL the new view is not plugged into anything. 02844 02845 \param flags is a bit list of the following: 02846 02847 - a2dTemplateFlag::VISIBLE The template may be displayed to the user in dialogs. 02848 - wxREFTEMPLATE_INVISIBLE The template may not be displayed to the user in dialogs. 02849 - a2dTemplateFlag::DEFAULT Defined as a2dTemplateFlag::VISIBLE. 02850 02851 \param size size sets initial size for views generated from this template 02852 02853 */ 02854 a2dViewTemplate( 02855 const wxString& descr, 02856 const wxString& docTypeName, 02857 const wxString& viewTypeName, 02858 wxClassInfo *viewClassInfo = (wxClassInfo *) NULL, 02859 a2dViewConnector* connector = (a2dViewConnector*) NULL, 02860 long flags = a2dTemplateFlag::DEFAULT, 02861 const wxSize& size = wxSize(0,0) ); 02862 02863 //! Destructor. 02864 ~a2dViewTemplate(); 02865 02866 //! create an exact copy of this property 02867 virtual a2dObject* Clone( CloneOptions options ) const; 02868 02869 //! Creates a new view for the given document. 02870 /*! 02871 Creates a new instance of the associated view class. If you have not supplied a 02872 wxClassInfo parameter to the template constructor, you will 02873 need to override this function to return an appropriate view instance. 02874 02875 After creating a new view using wxClassInfo two events are generated: 02876 02877 - a2dViewEvent of type ::wxEVT_CREATE_VIEW 02878 - a2dViewTemplateEvent of type ::wxEVT_POST_CREATE_VIEW 02879 */ 02880 virtual a2dView *CreateView( a2dDocument *doc, a2dDocumentFlagMask flags = a2dREFDOC_NON ); 02881 02882 //! Returns the text description of this template, as passed to the document template constructor 02883 wxString GetDescription() const { return m_description; } 02884 02885 //! Sets the template description. 02886 void SetDescription(const wxString& descr) { m_description = descr; }; 02887 02888 //! Returns the view type name, as passed to the document template constructor. 02889 wxString GetViewTypeName() const { return m_viewTypeName; } 02890 02891 //! Returns the document type name, as passed to the document template constructor. 02892 wxString GetDocumentTypeName() const { return m_docTypeName; } 02893 02894 //! Returns the flags, as passed to the document template constructor. 02895 const a2dTemplateFlag& GetFlags() const { return m_flags; } 02896 02897 //! Sets the internal document template flags (see the constructor description for more details). 02898 void SetFlags( a2dTemplateFlagMask flags) { m_flags.SetFlags( flags ); } 02899 02900 //! Sets the internal document template flags (see the constructor description for more details). 02901 void SetFlags( a2dTemplateFlag flags) { m_flags = flags; } 02902 02903 //! does template mask match 02904 bool CheckMask( a2dTemplateFlagMask mask ) { return m_flags.CheckMask( mask ); } 02905 02906 //! Returns true if the document template can be shown in user dialogs, false otherwise. 02907 void SetVisible( bool value ) { m_flags.SetFlags( a2dTemplateFlag::VISIBLE ); } 02908 02909 //! Returns true if the document template is marked , false otherwise. 02910 void SetMarked( bool value ) { m_flags.SetFlags( a2dTemplateFlag::MARK ); } 02911 02912 //! Returns true if the document template can be shown in user dialogs, false otherwise. 02913 bool IsVisible() const { return m_flags.GetFlag( a2dTemplateFlag::VISIBLE ); } 02914 02915 //! Returns true if the document template is marked , false otherwise. 02916 bool IsMarked() const { return m_flags.GetFlag( a2dTemplateFlag::MARK ); } 02917 02918 a2dViewConnector* GetViewConnector() { return m_connector; } 02919 02920 //! set size to use for new created views 02921 void SetInitialSize( const wxSize& size ) { m_initialSize = size; } 02922 02923 //! Get size used for new created views 02924 wxSize& GetInitialSize() { return m_initialSize; } 02925 02926 #if wxUSE_PRINTING_ARCHITECTURE 02927 wxPageSetupData* GetPageSetupData(void) const { return m_pageSetupData; } 02928 void SetPageSetupData(const wxPageSetupData& pageSetupData) { *m_pageSetupData = pageSetupData; } 02929 #endif 02930 02931 protected: 02932 02933 //! size for new view 02934 wxSize m_initialSize; 02935 02936 //! The flags passed to the constructor. 02937 a2dTemplateFlag m_flags; 02938 02939 //! A short description of this template 02940 wxString m_description; 02941 02942 //! The named type of the document associated with this template. 02943 wxString m_docTypeName; 02944 02945 //! The named type of the view associated with this template. 02946 wxString m_viewTypeName; 02947 02948 //! For dynamic creation of appropriate instances. 02949 wxClassInfo* m_viewClassInfo; 02950 02951 //! class used to connect new views with Frames and windows. 02952 a2dSmrtPtr<a2dViewConnector> m_connector; 02953 02954 #if wxUSE_PRINTING_ARCHITECTURE 02955 //! this is the printer page setup data for all views with this template 02956 wxPageSetupData* m_pageSetupData; 02957 #endif 02958 02959 private: 02960 02961 virtual a2dObject* SmrtPtrOwn(); 02962 virtual bool SmrtPtrRelease(); 02963 friend class a2dSmrtPtrBase; 02964 }; 02965 02966 //! This class is used to connect newly created a2dView's to a wxFrame and/or wxWindow 02967 /*! 02968 a2dDocumentTemplate generates new documents and a2dViewTemplate generate new views 02969 on a document. The new documents and views use the a2dViewConnector to link 02970 themselfs to the windows and/or frames of the application. 02971 The a2dViewConnector is an abstract class, so a new connector class needs 02972 to be derived. This derived class has complete freedom on how to organize new views 02973 into the application. It may decide to use existing frame or windows, or generate 02974 new frames and/or windows. In the end it must set one wxWindow pointer 02975 in the a2dView, which will be used by the view to display itself. 02976 The a2dViewConnector may also decide to use existing views for connecting the new document to. 02977 In that case no new views will be created. 02978 02979 The approach to have a a2dViewConnector decide how to connect views to frames/windows, 02980 is good for making a2dView independent classes. In such clases, the views can be switched 02981 with other views. 02982 Think here of a complete graphical editor wxFrame derived class, 02983 which edits the view which has the focus. 02984 It has all the menu's and tools to do it, but does not know yet if there is one or many views 02985 inside itself. It only knows how to edit one a2dView which is part of the editor frame. 02986 Different types of views can be switched into the editor frame, 02987 where each view type can define a different manner of rendering a drawing. 02988 One might use the standard wxDC based API for drawing in one view type, 02989 and another using an antialiasing rendering engine. The editor does not need to know what 02990 view is used internal. 02991 02992 The a2dViewConnector class is created before setting up a2dDocumentTemplate, and given as a pointer to 02993 a2dDocumentTemplate and a2dViewTemplate. 02994 02995 a2dDocumentTemplate sents a ::wxEVT_POST_CREATE_DOCUMENT event after it created a new a2dDocument. 02996 This event should be catched by the a2dViewConnector. 02997 The default handler calls CreateView on a choosen a2dViewTemplate from a list, 02998 leading to a ::wxEVT_POST_CREATE_VIEW being sent to this or another a2dViewConnector class. 02999 The connector receives this event, and the new view can be plugged into/attached to a window etc. 03000 03001 WxViewTemplateRef sents a ::wxEVT_POST_CREATE_VIEW event after it created a new a2dView. 03002 This event may be catched by the a2dViewConnector. 03003 One can handle this event in a derived a2dViewConnector class, and connect the new a2dView 03004 somehow into the application its wxFrame's or wxWindow's. 03005 The normal action should be to plug the new view into a wxFrame, and/or create a wxWindow 03006 for the a2dView to use as DisplayWindow. 03007 The wxFrame and DisplayWindow may already exist or will be created each time. 03008 This depends on the application and what a2dViewConnector is used. 03009 03010 The new a2dView in the end will have a pointer set to its display window. 03011 It is up to the type of a2dViewConnector ( which the application uses ), to decide what to do 03012 with new a2dView's and/or new a2dDocument's. 03013 03014 A different approach to connect new documents into the application, is to not intercept 03015 ::wxEVT_POST_CREATE_VIEW. The connector will either directly use newly created views or already 03016 existing views to connect the new document to. This should all be arranged in the handler 03017 for ::wxEVT_POST_CREATE_DOCUMENT. In a one wxFrame application with one or more subwindows containing 03018 a view, this is the better way to connect new documents into the application. 03019 03020 The a2dView uses its DisplayWindow to redirect events ( e.g. ::wxEVT_CLOSE_VIEW ) to 03021 the window(s) and frame containing the view. 03022 A special a2dDocumentFrame can be used to interecept such events, and handle them correctly. 03023 But you can decide to use your own frame class. 03024 03025 Events sent to this class: 03026 03027 - ::wxEVT_POST_CREATE_DOCUMENT from template just after creation of a document 03028 - ::wxEVT_POST_CREATE_VIEW from template just after creation of a view 03029 03030 \ingroup docview 03031 */ 03032 class A2DDOCVIEWDLLEXP a2dViewConnector: public a2dEvtHandler 03033 { 03034 03035 DECLARE_ABSTRACT_CLASS(a2dViewConnector) 03036 A2D_DECLARE_EVENT_TABLE() 03037 03038 public: 03039 03040 //! Constructor 03041 a2dViewConnector(); 03042 03043 //! destructor 03044 virtual ~a2dViewConnector() = 0; 03045 03046 a2dViewConnector( const a2dViewConnector &other ); 03047 03048 //! set position to use for new created views or frames or windows 03049 void SetInitialPosition( const wxPoint& position ) { m_initialPos = position; } 03050 03051 //! set size to use for new created views or frames or windows 03052 void SetInitialSize( const wxSize& size ) { m_initialSize = size; } 03053 03054 //! set style to use for new created frames or windows 03055 void SetInitialStyle( long style ) { m_initialStyle = style; } 03056 03057 //! Get position used for new created views or frames or windows 03058 wxPoint& GetInitialPosition() { return m_initialPos; } 03059 03060 //! GGet size used for new created views or frames or windows 03061 wxSize& GetInitialSize() { return m_initialSize; } 03062 03063 //! Get style used for new created a2dDocumentFrame 03064 long GetInitialStyle() { return m_initialStyle; } 03065 03066 a2dViewTemplateList& GetViewTemplates() { return m_viewTemplates; } 03067 03068 //! add a reference to a a2dViewTemplate to the wxViewTemplateReflist 03069 /*! 03070 When Associating a a2dViewTemplate, you are responsible for Disassociating that ViewTemplateRef. 03071 Not doing this will result in a memory leak, since instances of this class will not be deleted. 03072 The reason is that the ViewTemplateRef itself also Owns the connector, and therefore the reference count 03073 will never reach zero, if still associated ViewTemplateRef templates to exist. 03074 */ 03075 void AssociateViewTemplate( a2dViewTemplate *temp ); 03076 03077 //! remove a reference to a a2dViewTemplate from the wxViewTemplateReflist 03078 void DisassociateViewTemplate( a2dViewTemplate *temp ); 03079 03080 //! remove All references to a a2dViewTemplate from the wxViewTemplateReflist 03081 void DisassociateViewTemplates(); 03082 03083 //! create a new view from a list of a2dViewTemplate's 03084 /*! 03085 Creates a a2dDocumentTemplateEvent of type ::wxEVT_POST_CREATE_DOCUMENT to be processed by this connector. 03086 This is handy when one already created/has a document, and wants to create a view for it. 03087 In general document are created via a2dDocumentTemplate. 03088 03089 */ 03090 virtual a2dView* CreateView( a2dDocument* doc, const wxString& viewTypeName = wxT(""), 03091 a2dDocumentFlagMask flags = a2dREFDOC_NON , 03092 a2dTemplateFlagMask mask = a2dTemplateFlag::DEFAULT ); 03093 03094 //! handler for ::wxEVT_DISCONNECT_VIEW 03095 /*! 03096 The ::wxEVT_DISCONNECT_ALLVIEWS is generated by the a2dDocument when it wants to disconnects all views. 03097 This can be when closing the document, or just to attach all views to another document. 03098 a2dView does intercept this event, and sents a ::wxEVT_DISCONNECT_VIEW via its a2dViewTemplate member to the 03099 a2dViewConnector of that specific template. 03100 In short the a2dViewTemplate and a2dViewConnetor which were used to generate the a2dView and connect the view 03101 into the GUI of the application, is also used to disconnect it later. 03102 03103 Here the view connector is responsible for disconnecting view from documents, and if wanted to destroy 03104 the a2dView and/or the a2dDocumentFrame, a2dDocumentViewWindow, a2dDocumentViewScrolledWindow or whatever GUI 03105 interface was used to contain the view. 03106 */ 03107 void OnDisConnectView( a2dTemplateEvent& event ); 03108 03109 //! when view is disconnected is called, 03110 //! the document is only disconnected from the document and kept alive 03111 void SetOnlyDisconnect( bool OnlyDisconnect ) { m_OnlyDisconnect = OnlyDisconnect; } 03112 03113 //! When true, a2dView::OnDisConnectView() only disconnects view from document, and does not close it. 03114 bool GetOnlyDisconnect() { return m_OnlyDisconnect; } 03115 03116 private: 03117 03118 //! Default Handler Creates the first a2dView on the a2dDocument 03119 /*! 03120 Calls a2dDocumentCommandProcessor::SelectViewType() to choose a proper template for the new document. 03121 That uses the m_viewTemplates or the a2dDocviewGlobals->GetDocviewCommandProcessor()->GetViewTemplates() 03122 to display a list of view Templates for the given document. 03123 After that, the choosen view template is used to create a new a2dView via the a2dViewTemplate::CreateView() function. 03124 a2dViewTemplate::CreateView() uses its connector ( in general the same is the connector which created the document ) 03125 to sent a wxEVT_POST_CREATE_VIEW to the connector. Eventually the connector will/can create/reuse windows and frames 03126 for the new views. 03127 */ 03128 void OnPostCreateDocument( a2dTemplateEvent& event ); 03129 03130 //! Gives an error, telling the user to handle this event in a derived connector. 03131 //! default handler for ::wxEVT_POST_CREATE_VIEW 03132 void OnPostCreateView( a2dTemplateEvent& event ); 03133 03134 void OnCloseView( a2dCloseViewEvent& event ); 03135 03136 protected: 03137 03138 //! position for new frames 03139 wxPoint m_initialPos; 03140 03141 //! size for new frames 03142 wxSize m_initialSize; 03143 03144 //! style for new frames 03145 long m_initialStyle; 03146 03147 //! templates for views 03148 a2dViewTemplateList m_viewTemplates; 03149 03150 //! see SetOnlyDisconnect() 03151 bool m_OnlyDisconnect; 03152 03153 }; 03154 03155 //! uses a wxFrame to hold new views or to create child wxFrame's to hold new views. 03156 /*! 03157 03158 If createChildframe == true 03159 Creates for every new view reported by ::wxEVT_POST_CREATE_VIEW a new a2dDocumentFrame as child of GetDocFrame() 03160 else 03161 Switches every new view reported by ::wxEVT_POST_CREATE_VIEW into an existing a2dDocumentFrame GetDocFrame() 03162 The old a2dView for that a2dDocumentFrame stays on the wxDocument. 03163 03164 GetFrame() / m_docframe can be the Top Frame in a window application or Any other Child Frame. 03165 */ 03166 class A2DDOCVIEWDLLEXP a2dFrameViewConnector: public a2dViewConnector 03167 { 03168 03169 DECLARE_ABSTRACT_CLASS(a2dFrameViewConnector) 03170 03171 public: 03172 03173 //! Constructor 03174 a2dFrameViewConnector(); 03175 03176 //! destructor 03177 virtual ~a2dFrameViewConnector() {}; 03178 03179 a2dFrameViewConnector( const a2dFrameViewConnector &other ); 03180 03181 //! The pointer m_docframe will be initialized. 03182 /*! An application can have only one Parent a2dDocumentFrame in the application, which is the Frame which 03183 other Child a2dDocumentFrame(s) have as Parent. The Parent Frame is in general created in 03184 bool wxApp::OnInit(void). 03185 03186 Depending on the derived connector the a2dDocumentFrame may be used in a parent fashion 03187 or in a child fashion. 03188 The derived a2dFrameViewConnector may use the parent frame to generate new child frames for it. 03189 And in another derived a2dFrameViewConnector, the same frame may be used to switch views. 03190 03191 The docframe can display a document using a a2dView. 03192 03193 \param docframe The parent frame of the whole application OR a child frame 03194 03195 \param createChildframe new views will get its own frame as child of m_docframe 03196 */ 03197 void Init( wxFrame* docframe, bool createChildframe = true ); 03198 03199 //! get the frame 03200 wxFrame* GetFrame() { return m_docframe; } 03201 03202 //! set the frame 03203 /*! 03204 The wxFrame can be the parent/top frame in the application or a Child Frame 03205 of this application. See a2dDocumentFrame how to create a parent or child frame. 03206 */ 03207 void SetFrame( wxFrame* docframe ) { m_docframe = docframe; } 03208 03209 void SetCreateChild( bool createChildframe ) { m_createChildframe = createChildframe; } 03210 03211 bool GetCreateChild() { return m_createChildframe; } 03212 03213 private: 03214 03215 void OnPostCreateView( a2dTemplateEvent& event ); 03216 03217 protected: 03218 03219 //! the frame which receives events and often redirect those to the document manager. 03220 wxFrame* m_docframe; 03221 03222 bool m_createChildframe; 03223 }; 03224 03225 class A2DDOCVIEWDLLEXP a2dDocumentViewScrolledWindow; 03226 class A2DDOCVIEWDLLEXP a2dDocumentViewWindow; 03227 03228 // ---------------------------------------------------------------------------- 03229 // a2dWindowConnector 03230 // ---------------------------------------------------------------------------- 03231 03232 //! a connector which holds one pointer to a wxWindow derived class being the template parameter. 03233 /*! 03234 This connector connects new views to a wxWindow derived class which must have a Setview() member. 03235 03236 ::wxEVT_POST_CREATE_VIEW is handled by a2dWindowConnector<Twindow>::OnPostCreateView(), 03237 and just sets the view to the m_display window. 03238 */ 03239 template<class Twindow> 03240 class a2dWindowConnector : public a2dViewConnector 03241 { 03242 A2D_DECLARE_EVENT_TABLE() 03243 03244 public: 03245 typedef Twindow TType; 03246 03247 //! Constructor 03248 a2dWindowConnector(); 03249 03250 ~a2dWindowConnector() {}; 03251 03252 //! window used by view to display itself. 03253 Twindow* GetDisplayWindow() { return m_display; } 03254 03255 //! get window used by view to display itself. 03256 void SetDisplayWindow( Twindow* window ) { m_display = window; } 03257 03258 private: 03259 03260 //! default handler for ::wxEVT_POST_CREATE_VIEW 03261 void OnPostCreateView( a2dTemplateEvent& event ); 03262 03263 protected: 03264 03265 Twindow* m_display; 03266 }; 03267 03268 A2D_BEGIN_EVENT_TABLE_TEMPLATE1( a2dWindowConnector, a2dViewConnector, Twindow ) 03269 A2D_EVT_POST_CREATE_VIEW( a2dWindowConnector<Twindow>::OnPostCreateView ) 03270 A2D_END_EVENT_TABLE() 03271 03272 template<class Twindow> 03273 a2dWindowConnector<Twindow>::a2dWindowConnector(): a2dViewConnector() 03274 { 03275 m_display = NULL; 03276 } 03277 03278 template<class Twindow> 03279 void a2dWindowConnector<Twindow>::OnPostCreateView( a2dTemplateEvent& event ) 03280 { 03281 if ( !m_display ) 03282 return; //view will not be connected to a window ( but document and view already are available). 03283 03284 //next to what is done in base class, set the view to the display. 03285 a2dView* view = event.GetView(); 03286 03287 m_display->SetView( view ); 03288 view->Update(); 03289 } 03290 03291 //! lua wrap 03292 typedef a2dWindowConnector<a2dDocumentViewScrolledWindow> a2dWindowConnectorFora2dDocumentViewScrolledWindow; 03293 03294 //! extend a2dViewConnector to have a a2dDocumentViewScrolledWindow for each view. 03295 /* 03296 03297 */ 03298 class A2DDOCVIEWDLLEXP a2dScrolledWindowViewConnector: public a2dWindowConnector<a2dDocumentViewScrolledWindow> 03299 { 03300 DECLARE_DYNAMIC_CLASS( a2dScrolledWindowViewConnector ) 03301 }; 03302 03303 //! lua wrap 03304 typedef a2dWindowConnector<a2dDocumentViewWindow> a2dWindowConnectorFora2dDocumentViewWindow; 03305 03306 //! extend a2dViewConnector to have a a2dDocumentViewScrolledWindow for each view. 03307 /* 03308 03309 */ 03310 class A2DDOCVIEWDLLEXP a2dWindowViewConnector: public a2dWindowConnector<a2dDocumentViewWindow> 03311 { 03312 DECLARE_DYNAMIC_CLASS( a2dWindowViewConnector ) 03313 }; 03314 03315 // ---------------------------------------------------------------------------- 03316 // a2dSplitterConnector 03317 // ---------------------------------------------------------------------------- 03318 03319 //! extend wxSameFrameViewConnector to connect view into a splitter window 03320 /*! 03321 The two window of the splitter must be of type a2dDocumentViewScrolledWindow* or 03322 a2dDocumentViewWindow or one with equal event handling as those. 03323 */ 03324 template<class Twindow> 03325 class A2DDOCVIEWDLLEXP a2dSplitterConnector: public a2dWindowConnector<Twindow> 03326 { 03327 03328 public: 03329 03330 //! Constructor 03331 a2dSplitterConnector(); 03332 03333 ~a2dSplitterConnector(); 03334 03335 void Init( wxSplitterWindow* splitter, Twindow* connecto ); 03336 03337 wxSplitterWindow* GetSplitter() { return m_splitter; } 03338 03339 protected: 03340 03341 wxSplitterWindow* m_splitter; 03342 }; 03343 03344 template<class Twindow> 03345 a2dSplitterConnector<Twindow>::a2dSplitterConnector(): a2dWindowConnector<Twindow>() 03346 { 03347 m_splitter = (wxSplitterWindow*) NULL; 03348 } 03349 03350 template<class Twindow> 03351 a2dSplitterConnector<Twindow>::~a2dSplitterConnector() 03352 { 03353 } 03354 03355 template<class Twindow> 03356 void a2dSplitterConnector<Twindow>::Init( wxSplitterWindow* splitter, Twindow* connecto ) 03357 { 03358 m_splitter = splitter; 03359 wxASSERT_MSG( connecto == m_splitter->GetWindow1() || connecto == m_splitter->GetWindow2(), wxT("wxDrawingConnector::OnCloseView Not a valid window in splitter") ); 03360 SetDisplayWindow( connecto ); 03361 } 03362 03363 //---------------------------------------------------------------------------- 03364 // wxNotebookConnector 03365 //---------------------------------------------------------------------------- 03366 03367 //! extend a2dWindowConnector to connect views into a wxNotebook window 03368 /*! 03369 Each new a2dView connects as a new page 03370 */ 03371 template<class NoteBook, class Twindow, class Tview = a2dView > 03372 class wxNotebookConnector: public a2dWindowConnector<Twindow> 03373 { 03374 //DECLARE_DYNAMIC_CLASS( wxNotebookConnector ) 03375 //IMPLEMENT_DYNAMIC_CLASS( wxNotebookConnector, a2dScrolledWindowViewConnector ) 03376 03377 A2D_DECLARE_EVENT_TABLE() 03378 03379 public: 03380 03381 //! Constructor 03382 /* 03383 \param documentManager maintaining a pool of a2dDocumentTemplate's, a2dViewTemplate's 03384 a2dDocument's and their a2dView's 03385 */ 03386 wxNotebookConnector( ); 03387 03388 //! destructor 03389 ~wxNotebookConnector(); 03390 03391 //! return pointer to notebook type used 03392 wxNotebook* GetNotebook() { return m_notebook; } 03393 03394 //! initialize with/to this notebook 03395 void Init( NoteBook* notebook ); 03396 03397 protected: 03398 03399 //! what to do after document creation 03400 void OnPostCreateDocument( a2dTemplateEvent& event ); 03401 03402 //! what to do after view creation 03403 void OnPostCreateView( a2dTemplateEvent& event ); 03404 03405 //! the notebook to hook views into. 03406 NoteBook* m_notebook; 03407 }; 03408 03409 A2D_BEGIN_EVENT_TABLE_TEMPLATE3( wxNotebookConnector, a2dWindowConnector<Twindow>, NoteBook, Twindow, Tview ) 03410 A2D_EVT_POST_CREATE_DOCUMENT( wxNotebookConnector::OnPostCreateDocument ) 03411 A2D_EVT_POST_CREATE_VIEW( wxNotebookConnector::OnPostCreateView ) 03412 A2D_END_EVENT_TABLE() 03413 03414 template<class NoteBook, class Twindow, class Tview> 03415 wxNotebookConnector<NoteBook,Twindow,Tview>::wxNotebookConnector(): a2dWindowConnector<Twindow>() 03416 { 03417 m_notebook = (NoteBook*) NULL; 03418 } 03419 03420 template<class NoteBook, class Twindow, class Tview> 03421 wxNotebookConnector<NoteBook,Twindow,Tview>::~wxNotebookConnector() 03422 { 03423 } 03424 03425 template<class NoteBook, class Twindow, class Tview> 03426 void wxNotebookConnector<NoteBook,Twindow,Tview>::Init( NoteBook* notebook ) 03427 { 03428 m_notebook = notebook; 03429 } 03430 03431 template<class NoteBook, class Twindow, class Tview> 03432 void wxNotebookConnector<NoteBook,Twindow,Tview>::OnPostCreateDocument( a2dTemplateEvent& event ) 03433 { 03434 event.GetDocument()->SetTitle(event.GetDocument()->GetFilename().GetFullName() ); 03435 event.Skip(); //to baseclass 03436 } 03437 03438 template<class NoteBook, class Twindow, class Tview> 03439 void wxNotebookConnector<NoteBook,Twindow,Tview>::OnPostCreateView( a2dTemplateEvent& event ) 03440 { 03441 //next to what is done in base class, set the view to the display. 03442 Tview* view = wxDynamicCast( event.GetView(), Tview ); 03443 03444 Twindow* outputwindow; 03445 outputwindow = new Twindow( view, m_notebook, -1, wxDefaultPosition, wxDefaultSize, wxNO_FULL_REPAINT_ON_RESIZE ); 03446 m_notebook->AddPage( outputwindow, view->GetDocument()->GetPrintableName(), true ); 03447 03448 outputwindow->SetCursor( wxCURSOR_PENCIL ); 03449 outputwindow->SetScrollbars(20, 20, 50, 50); 03450 outputwindow->SetBackgroundColour( wxColour( 0,235, 235 ) ); 03451 outputwindow->ClearBackground(); 03452 03453 view->Update(); 03454 } 03455 03456 // ---------------------------------------------------------------------------- 03457 // Provide simple default printing facilities 03458 // ---------------------------------------------------------------------------- 03459 03460 #if wxUSE_PRINTING_ARCHITECTURE 03461 //! print a document 03462 /*! 03463 \ingroup docview 03464 */ 03465 class A2DDOCVIEWDLLEXP a2dDocumentPrintout : public wxPrintout 03466 { 03467 DECLARE_DYNAMIC_CLASS(a2dDocumentPrintout) 03468 03469 public: 03470 a2dDocumentPrintout(a2dView *view = (a2dView *) NULL, const wxString& title = wxT("Printout")); 03471 bool OnPrintPage(int page); 03472 bool HasPage(int page); 03473 bool OnBeginDocument(int startPage, int endPage); 03474 void GetPageInfo(int *minPage, int *maxPage, int *selPageFrom, int *selPageTo); 03475 03476 virtual a2dView *GetView() { return m_printoutView; } 03477 03478 protected: 03479 a2dView* m_printoutView; 03480 }; 03481 #endif // wxUSE_PRINTING_ARCHITECTURE 03482 03483 03484 // ---------------------------------------------------------------------------- 03485 // Special Frame for views in a frame. 03486 // ---------------------------------------------------------------------------- 03487 03488 03489 //!The a2dDocumentFrame class provides a default frame for displaying documents 03490 /*! 03491 Can be parent or child frame. 03492 03493 In case of a ::wxEVT_CLOSE_WINDOW event, it is first redirected to the frame, and 03494 if not vetod askes the view to close. 03495 In a multi frame application the View should Destroy its windows/frame, including this one. 03496 The View may Veto the Close. 03497 03498 The view which belongs to this frame is either set directly when constructing, or 03499 it is set automatically by the view when a2dView::Activate() is sending the 03500 ::wxEVT_ACTIVATE_VIEW_SENT_FROM_CHILD event. 03501 Imagine that this frame would have 4 windows, each having a view on a 3D object. When clicking on one 03502 of those view, that views, its window will be activated, resulting in its view being activated, and that 03503 sents the wanted event. The frame will always know which view is active, and e.g. closing one view/window is 03504 via this chain. 03505 03506 If this frame is the parent all other child frames will close also, 03507 else only the child frame. 03508 03509 \ingroup docview 03510 */ 03511 class A2DDOCVIEWDLLEXP a2dDocumentFrame : public wxFrame 03512 { 03513 DECLARE_CLASS(a2dDocumentFrame) 03514 03515 public: 03516 03517 //! Constructor for two step creation, call a2dDocumentFrame::Create later. 03518 a2dDocumentFrame(); 03519 03520 //! constructor 03521 /*! 03522 \param parentFrame set true if this is to be the parent frame in the application. 03523 \param frame the parent frame for this frame. If topwindow use <code>NULL</code>. 03524 \param view The view for the document ( can be <code>NULL</code> ) 03525 \param id The window identifier. 03526 It may take a value of -1 to indicate a default value. 03527 \param title The caption to be displayed on the frame's title bar. 03528 \param pos The window position. 03529 \param size The window size. 03530 \param style Window style, please look into wxWindows docs for an overview. 03531 \param name The name of the window. 03532 */ 03533 a2dDocumentFrame( 03534 bool parentFrame, 03535 wxWindow* frame, 03536 a2dView* view = NULL, 03537 wxWindowID id = -1, 03538 const wxString& title = wxT("a2dDocumentFrame"), 03539 const wxPoint& pos = wxDefaultPosition, 03540 const wxSize& size = wxDefaultSize, 03541 long style = wxDEFAULT_FRAME_STYLE, 03542 const wxString& name = wxT("frame")); 03543 03544 //! wxFrame compatible constructor 03545 // YOU must set m_view and m_isParentFrame correctly. 03546 a2dDocumentFrame( 03547 wxWindow* frame, 03548 wxWindowID id = -1, 03549 const wxString& title = wxT("a2dDocumentFrame"), 03550 const wxPoint& pos = wxDefaultPosition, 03551 const wxSize& size = wxDefaultSize, 03552 long style = wxDEFAULT_FRAME_STYLE, 03553 const wxString& name = wxT("frame")); 03554 03555 03556 //! Constructor for two-step-creation (2nd step) 03557 /*! 03558 \param parentFrame set true if this is to be the parent frame in the application. 03559 \param frame the parent frame for this frame. If topwindow use <code>NULL</code>. 03560 \param view The view for the document ( can be <code>NULL</code> ) 03561 \param id The window identifier. 03562 It may take a value of -1 to indicate a default value. 03563 \param title The caption to be displayed on the frame's title bar. 03564 \param pos The window position. 03565 \param size The window size. 03566 \param style Window style, please look into wxWindows docs for an overview. 03567 \param name The name of the window. 03568 */ 03569 bool Create( 03570 bool parentFrame, 03571 wxWindow* frame, 03572 a2dView* view = NULL, 03573 wxWindowID id = -1, 03574 const wxString& title = wxT("a2dDocumentFrame"), 03575 const wxPoint& pos = wxDefaultPosition, 03576 const wxSize& size = wxDefaultSize, 03577 long style = wxDEFAULT_FRAME_STYLE, 03578 const wxString& name = wxT("frame")); 03579 03580 //! destructor 03581 ~a2dDocumentFrame(); 03582 03583 void SetDestroyOnCloseView( bool destroyOnCloseView ) { m_destroyOnCloseView = destroyOnCloseView; } 03584 03585 //! set a pointer to a a2dView to sent view events to. 03586 /*! 03587 Normally set via OnActivateViewSentFromChild() 03588 03589 The m_view is used to redirect the frame event for closing the window, 03590 and the activate event for the frame, to the view. 03591 Only if the m_view->GetDisplayWindow() is the a2dDocumentFrame itself, it will also be used for 03592 drawing the view ( See OnDraw() ) 03593 */ 03594 void SetView( a2dView* view ); 03595 03596 //! get the pointer to a a2dView to which view events are sent 03597 a2dView* GetView() { return m_view; } 03598 03599 //! Modified event handler to also sent event to a2dView or wxDocviewCommonEvents 03600 /*! 03601 Events handled how: 03602 - ::wxEVT_CLOSE_WINDOW if this frame is a parent frame, and the event is not vetod by the frame 03603 itself, calls a2dDocviewGlobals->GetDocviewCommandProcessor()->Clear(), this will 03604 eventually close all document and close all child views. And a child view will 03605 sent a ::wxEVT_CLOSE_VIEW to its containing window, and this will end up in the child frame 03606 (if there). So closing the parent frame, will lead to closing the child frames. 03607 If this frame is a childframe, the event is only sent to the view, if not vetod by this frame. 03608 This will lead to calling a2dView::Close(), and this gives you the chance to clean up 03609 by intercepting the ::wxEVT_CLOSE_VIEW event which is generated in there. 03610 03611 - ::wxEVT_ACTIVATE sent to view, and next to the frame itself. 03612 - all others first to frame itself, if not handled to view, and if not handled to 03613 a2dDocviewGlobals->GetDocviewCommonEvents() 03614 03615 */ 03616 bool ProcessEvent(wxEvent& event); 03617 03618 bool GetIsParentFrame() { return m_isParentFrame; } 03619 03620 void SetIsParentFrame( bool parentFrame ) { m_isParentFrame = parentFrame; } 03621 03622 //! Override this function to draw the graphic (or just process EVT_PAINT) 03623 /*! 03624 The default handler for EVT_PAINT is OnPaint, and it calls OnDraw(). 03625 OnDraw its default implementation is calling the m_view its OnDraw(). 03626 03627 If m_view its DisplayWindow, is the frame itself, the m_view->OnDraw() is called. 03628 If not the m_view, is only used for redirecting Close and activate events to the 03629 view which has the focus. 03630 */ 03631 virtual void OnDraw(wxDC& dc); 03632 03633 //! add items to toolbar using a predefined command ID. 03634 void AddCmdToToolbar( const a2dMenuIdItem& cmdId ); 03635 void ConnectCmdId( const a2dMenuIdItem& cmdId ); 03636 03637 //! add a command menu to the parent menu, and connect it to the eventhandler of the frame 03638 /*! 03639 Many commands which can be submitted to a commandprocessor in the following manner: 03640 \code 03641 commandprocessor->Submit( new a2dCommand_SomeCommand() ) 03642 \endcode 03643 Submitting the command makes it possible to undo the action. 03644 To issue such a command from a menu requires an Id. Therefore wxDocview defines many predefined 03645 menus items in the form of a2dMenuIdItem. They produce a unique Id to be handled in 03646 the commandprocessor. Like in: 03647 \code 03648 void a2dDocumentCommandProcessor::OnMenu( wxCommandEvent& event ) 03649 \endcode 03650 Several modules in wxDocview extend, in the derived a2dDocumentCommandProcessor, the set of handled 03651 menu Id's. The OnMenu intercepts the menu event, and sets up a new a2dCommand to be submitted. 03652 Understand that a2dDocumentFrame and a2dDocumentMDIParentFrame already redirect non handled events to 03653 the commandprocessor of the application. 03654 An a2dMenuIdItem defined menu text and helpstring, therefore all you need to do to add a command to 03655 your application is AddCmdMenu(). 03656 Many commands have parameters, and a a2dMenuIdItem its Id, can only be coupled to one a2dCommand with 03657 some predefined set of parameters. 03658 If you need a different implementation of the same command you can extend in the same manner 03659 in your derived commandprocessor. But you can always use the standard way of wxWidgets to add a menu, 03660 and add a handler in the frame. In the handler setsup the a2dCommand and submits it. 03661 Exactly the same behaviour, only not predefined. 03662 03663 \remark a2dMenuIdItem uses Id my name ready to be used by XRC files. 03664 */ 03665 void AddCmdMenu( wxMenu* parentMenu, const a2dMenuIdItem& cmdId ); 03666 03667 //! same as for a2dMenuIdItem, Id in wxMenuItem must be a valid id from one a2dMenuIdItem 03668 //! used in XRC files 03669 void AddCmdMenu( wxMenu* parentMenu, wxMenuItem* item ); 03670 03671 //! remove a command menu from the parent menu. 03672 /*! 03673 See AddCmdMenu() 03674 */ 03675 void RemoveCmdMenu( wxMenu* parentMenu, const a2dMenuIdItem& cmdId ); 03676 03677 //! called for dynamic added menu's via AddCommandToMenu() 03678 //! command will be submitted to a2dDocviewGlobals->GetDocviewCommandProcessor() 03679 void OnExecuteCommand(wxCommandEvent &event); 03680 03681 protected: 03682 03683 //! used by AddCmdMenu() to dynamically connect menu to function. 03684 //! The function just Skipps the event, so it will be handled by a command processor in the end. 03685 void OnCmdMenuId(wxCommandEvent &event); 03686 03687 //! default handler for paint events, it calls OnDraw(). 03688 void OnPaint( wxPaintEvent &event ); 03689 03690 //! default for closing a view in this frame 03691 /*! 03692 Close the view, if set, and destroy the frame. 03693 The view is closed even if it is displayed in a nested subwindow. 03694 Since it Destroys the frame ( if m_destroyOnCloseView is set ), 03695 that will automatically destroy the nested windows too. 03696 03697 /remark m_view is set to the active view if there are more sub windows with 03698 views. So just closing the currently active view is not enough, if there are more. 03699 */ 03700 void OnCloseView( a2dCloseViewEvent& event ); 03701 03702 03703 //! default for closing this frame via close button. 03704 /*! 03705 default handler for wxEVT_CLOSE event. 03706 Give the Frame the right to veto. 03707 The default tries to close the view. 03708 That is the right thing to do if the frame has just a single view. 03709 03710 If there are more views ( even in nested windows ), you need to 03711 handle that yourself. 03712 03713 /remark m_view is set to the active view if there are more sub windows with 03714 views. So just closing the currently active view is not enough, if there are more. 03715 */ 03716 void OnCloseWindow( wxCloseEvent &event ); 03717 03718 //! called by API and only handled if this is the Parent Frame 03719 void OnExit(wxCommandEvent& event); 03720 03721 //! called by API and only handled if this is the Parent Frame 03722 void OnMRUFile(wxCommandEvent& event); 03723 03724 //! default handler for file changed event sent from a2dView 03725 /*! 03726 Sents the event to the DisplayWindow, there or in its parent hiearchy it can be intercepted. 03727 */ 03728 void OnChangeFilename( a2dViewEvent& event ); 03729 03730 //! sets m_view to the current active view, generate by a2dView::Activate() 03731 void OnActivateViewSentFromChild( a2dViewEvent& viewevent ); 03732 03733 //! used for redirecting close and activate events to the view which has the focus. 03734 //! See SetView() 03735 a2dSmrtPtr<a2dView> m_view; 03736 03737 //! is this the docframe or not. 03738 bool m_isParentFrame; 03739 03740 //! when closing the view the frame will be destroyed. 03741 bool m_destroyOnCloseView; 03742 03743 DECLARE_EVENT_TABLE() 03744 }; 03745 03746 03747 03748 //! specialized wxWindow derived template class to handle a2dView events 03749 /*! 03750 The following events are sent up from the a2dView to this window. 03751 03752 ::wxEVT_CLOSE_VIEW 03753 03754 Next one can be recieved from the event distributer DistributeEvent() 03755 03756 ::wxEVT_CHANGEDFILENAME_DOCUMENT 03757 03758 When the a2dView sent this events it disables itself until return, to prevent looping. 03759 03760 ::wxEVT_CLOSE_VIEW should be handled in a derived class, or in some/the parent window of this window. 03761 The handler must call a2dDocumentViewScrolledWindow::SetView( NULL ) 03762 or set m_view to NULL and release it, this Detaches the view from the window, 03763 In case the window gets deleted via a Destroy() this will be done automatically. 03764 03765 These event are of type commandevents, and travel up to the parent of this window if not handled here. 03766 03767 All other events to the window are sent first to the a2dView and if not handled there, 03768 can be handled here. 03769 */ 03770 template<class Twindow> 03771 class A2DDOCVIEWDLLEXP a2dViewWindow: public Twindow 03772 { 03773 03774 public: 03775 //! Constructor for creation with view. 03776 /*! 03777 \param view The view for the document ( can be <code>NULL</code> ) 03778 \param parent the parent window for this window 03779 \param id The window identifier. 03780 It may take a value of -1 to indicate a default value. 03781 \param pos The window position. 03782 \param size The window size. 03783 \param style Window style, please look into wxWindows docs for an overview. 03784 \param name The name of the window. 03785 */ 03786 a2dViewWindow( a2dView* view, 03787 wxWindow* parent, 03788 wxWindowID id = -1, 03789 const wxPoint& pos = wxDefaultPosition, 03790 const wxSize& size = wxDefaultSize, 03791 long style = wxHSCROLL | wxVSCROLL, 03792 const wxString& name = wxT("a2dViewWindow")); 03793 03794 //! Constructor for creation without view. 03795 /*! 03796 \param parent the parent window for this window 03797 \param id The window identifier. 03798 It may take a value of -1 to indicate a default value. 03799 \param pos The window position. 03800 \param size The window size. 03801 \param style Window style, please look into wxWindows docs for an overview. 03802 \param name The name of the window. 03803 */ 03804 a2dViewWindow( wxWindow* parent, 03805 wxWindowID id = -1, 03806 const wxPoint& pos = wxDefaultPosition, 03807 const wxSize& size = wxDefaultSize, 03808 long style = wxHSCROLL | wxVSCROLL, 03809 const wxString& name = wxT("a2dViewWindow")); 03810 03811 //! Destructor. 03812 ~a2dViewWindow(); 03813 03814 //! to switch the view in this window to another view 03815 /*! 03816 Default releases the old view and sets it display to NULL. 03817 Next it sets and owns the new view and sets the view its display to this window. 03818 Override this if more needs to be done to switch the view. 03819 */ 03820 virtual void SetView( a2dView* view ); 03821 03822 //! get the current view 03823 a2dView* GetView() { return m_view; } 03824 03825 //! Extend event processing to search the view's event table 03826 /*! Some events are handled within the view as if the view is a window within a window. 03827 Therefore the wxWindow containing the view should redirect all its events to 03828 its views, when the view does not handle the event it will go to the window itself. 03829 03830 View events ::wxEVT_CLOSE_VIEW from the view are 03831 sent up to this window. 03832 03833 Next one can be recieved from the event distributer DistributeEvent() 03834 ::wxEVT_CHANGEDFILENAME_DOCUMENT 03835 03836 */ 03837 virtual bool ProcessEvent(wxEvent& event); 03838 03839 //! Override this function to draw the graphic (or just process EVT_PAINT) 03840 virtual void OnDraw(wxDC& dc); 03841 03842 //! resets view to NULL when view was closed and skips the event for the parent window/frame. 03843 void OnCloseView( a2dCloseViewEvent& event ); 03844 03845 //! calls OnDraw(dc); 03846 void OnPaint( wxPaintEvent &event ); 03847 03848 protected: 03849 03850 //! the view that uses this window to display itself 03851 a2dSmrtPtr<a2dView> m_view; 03852 03853 //private: 03854 03855 }; 03856 03857 // Define a constructor for my canvas 03858 template<class Twindow> 03859 a2dViewWindow<Twindow>::a2dViewWindow( a2dView* view, wxWindow* parent, wxWindowID id, const wxPoint& pos, const wxSize& size, const long style, const wxString& name ): 03860 Twindow( parent, id, pos, size, style, name ) 03861 { 03862 #if defined(_DEBUG) && defined (SMART_POINTER_DEBUG) 03863 m_view.m_owner = this; 03864 m_view.m_ownertype = a2dSmrtPtr<a2dView>::owner_wxobject; 03865 #endif 03866 m_view = view; 03867 if ( m_view ) 03868 { 03869 //Attach the canvas as the window for the view to display its stuff 03870 m_view->SetDisplayWindow( this ); 03871 } 03872 Twindow::Enable(); 03873 } 03874 03875 // Define a constructor for my canvas 03876 template<class Twindow> 03877 a2dViewWindow<Twindow>::a2dViewWindow( wxWindow* parent, wxWindowID id, const wxPoint& pos, const wxSize& size, const long style, const wxString& name ): 03878 Twindow( parent, id, pos, size, style, name ) 03879 { 03880 #if defined(_DEBUG) && defined (SMART_POINTER_DEBUG) 03881 m_view.m_owner = this; 03882 m_view.m_ownertype = a2dSmrtPtr<a2dView>::owner_wxobject; 03883 #endif 03884 m_view = NULL; 03885 } 03886 03887 template<class Twindow> 03888 a2dViewWindow<Twindow>::~a2dViewWindow() 03889 { 03890 if ( m_view ) 03891 { 03892 m_view->SetDisplayWindow( NULL ); 03893 } 03894 m_view = NULL; 03895 } 03896 03897 template<class Twindow> 03898 void a2dViewWindow<Twindow>::SetView( a2dView* view ) 03899 { 03900 if ( m_view ) 03901 { 03902 m_view->SetDisplayWindow( NULL ); 03903 } 03904 03905 m_view = view; 03906 03907 if ( m_view ) 03908 { 03909 //Attach the canvas as the window for the view to display its stuff 03910 m_view->SetDisplayWindow( this ); 03911 m_view->Activate( true ); 03912 } 03913 } 03914 03915 template<class Twindow> 03916 void a2dViewWindow<Twindow>::OnPaint( wxPaintEvent& WXUNUSED(event) ) 03917 { 03918 wxPaintDC dc( this ); 03919 Twindow::PrepareDC(dc); 03920 03921 OnDraw(dc); 03922 } 03923 03924 // Define the repainting behaviour 03925 template<class Twindow> 03926 void a2dViewWindow<Twindow>::OnDraw(wxDC& dc) 03927 { 03928 if (m_view) 03929 m_view->OnDraw(& dc); 03930 } 03931 03932 template<class Twindow> 03933 void a2dViewWindow<Twindow>::OnCloseView( a2dCloseViewEvent& event ) 03934 { 03935 wxASSERT_MSG( m_view == event.GetEventObject(), wxT("view in a2dCloseViewEvent not equal to m_view") ); 03936 03937 if ( m_view ) 03938 { 03939 //we do not set the m_view->SetDisplayWindow( NULL ); 03940 //This enables parent window to still find the display window via the a2dCloseViewEvent. 03941 //The view itself will set the m_display to NULL. 03942 m_view = NULL; 03943 } 03944 03945 Twindow::Refresh(); 03946 event.Skip(); //to parent window/frame 03947 } 03948 03949 template<class Twindow> 03950 bool a2dViewWindow<Twindow>::ProcessEvent(wxEvent& event) 03951 { 03952 //some wxViewEvents go upstream ( document -> view -> window -> frame ) 03953 //These event are of the commandevent type, so they do get processed by the parent window 03954 //of this window ( when not processed here ). 03955 03956 // Extend event processing to search the view's event table 03957 if ( event.GetEventType() == wxEVT_ACTIVATE_VIEW_SENT_FROM_CHILD ) 03958 { 03959 return wxEvtHandler::ProcessEvent(event); 03960 } 03961 else 03962 { 03963 // most events will be processed first by the view 03964 if ( m_view && !m_view->IsClosed() && 03965 m_view->GetEventHandler()->ProcessEvent(event) ) 03966 return true; 03967 03968 return wxEvtHandler::ProcessEvent(event); 03969 } 03970 return false; 03971 } 03972 03973 //! specialized wxScrolledWindow to handle a2dView events 03974 /*! 03975 The following events are sent up from the a2dView to this window. 03976 03977 ::wxEVT_CLOSE_VIEW 03978 03979 Next one can be recieved from the event distributer DistributeEvent() 03980 03981 ::wxEVT_CHANGEDFILENAME_DOCUMENT 03982 03983 When the a2dView sent this events it disables itself until return, to prevent looping. 03984 03985 ::wxEVT_CLOSE_VIEW should be handled in a derived class, or in some/the parent window of this window. 03986 The handler must call a2dDocumentViewScrolledWindow::SetView( NULL ) 03987 or set m_view to NULL and release it, this Detaches the view from the window, 03988 In case the window gets deleted via a Destroy() this will be done automatically. 03989 03990 These event are of type commandevents, and travel up to the parent of this window if not handled here. 03991 03992 All other events to the window are sent first to the a2dView and if not handled there, 03993 can be handled here. 03994 */ 03995 class A2DDOCVIEWDLLEXP a2dDocumentViewScrolledWindow: public a2dViewWindow<wxScrolledWindow> 03996 { 03997 DECLARE_EVENT_TABLE() 03998 03999 public: 04000 //! Constructor for creation with view. 04001 /*! 04002 \param view The view for the document ( can be <code>NULL</code> ) 04003 \param parent the parent window for this window 04004 \param id The window identifier. 04005 It may take a value of -1 to indicate a default value. 04006 \param pos The window position. 04007 \param size The window size. 04008 \param style Window style, please look into wxWindows docs for an overview. 04009 \param name The name of the window. 04010 */ 04011 a2dDocumentViewScrolledWindow( a2dView* view, 04012 wxWindow* parent, 04013 wxWindowID id = -1, 04014 const wxPoint& pos = wxDefaultPosition, 04015 const wxSize& size = wxDefaultSize, 04016 long style = wxHSCROLL | wxVSCROLL, 04017 const wxString& name = wxT("a2dDocumentViewScrolledWindow")); 04018 04019 //! Constructor for creation without view. 04020 /*! 04021 \param parent the parent window for this window 04022 \param id The window identifier. 04023 It may take a value of -1 to indicate a default value. 04024 \param pos The window position. 04025 \param size The window size. 04026 \param style Window style, please look into wxWindows docs for an overview. 04027 \param name The name of the window. 04028 */ 04029 a2dDocumentViewScrolledWindow( wxWindow* parent, 04030 wxWindowID id = -1, 04031 const wxPoint& pos = wxDefaultPosition, 04032 const wxSize& size = wxDefaultSize, 04033 long style = wxHSCROLL | wxVSCROLL, 04034 const wxString& name = wxT("a2dDocumentViewScrolledWindow")); 04035 04036 //! Destructor. 04037 ~a2dDocumentViewScrolledWindow(); 04038 04039 private: 04040 04041 DECLARE_CLASS(a2dDocumentViewScrolledWindow) 04042 }; 04043 04044 04045 //! specialized wxWindow to handle a2dView events 04046 /*! 04047 The following events are sent up from the a2dView to this window. 04048 04049 ::wxEVT_CLOSE_VIEW 04050 04051 Next one can be recieved from the event distributer DistributeEvent() 04052 ::wxEVT_CHANGEDFILENAME_DOCUMENT 04053 04054 When the a2dView sent this events it disables itself until return, to prevent looping. 04055 04056 ::wxEVT_CLOSE_VIEW should be handled in a derived class, or in some/the parent window of this window. 04057 The handler must call a2dDocumentViewScrolledWindow::SetView( NULL ) 04058 or set m_view to NULL and release it, this Detaches the view from the window, 04059 In case the window gets deleted via a Destroy() this will be done automatically. 04060 04061 These event are of type commandevents, and travel up to the parent of this window if not handled here. 04062 04063 All other events to the window are sent first to the a2dView and if not handled there, 04064 can be handled here. 04065 */ 04066 class a2dDocumentViewWindow: public a2dViewWindow<wxWindow> 04067 { 04068 DECLARE_EVENT_TABLE() 04069 04070 public: 04071 //! Constructor for creation with view. 04072 /*! 04073 \param view The view for the document ( can be <code>NULL</code> ) 04074 \param parent the parent window for this window 04075 \param id The window identifier. 04076 It may take a value of -1 to indicate a default value. 04077 \param pos The window position. 04078 \param size The window size. 04079 \param style Window style, please look into wxWindows docs for an overview. 04080 \param name The name of the window. 04081 */ 04082 a2dDocumentViewWindow( a2dView* view, 04083 wxWindow* parent, 04084 wxWindowID id = -1, 04085 const wxPoint& pos = wxDefaultPosition, 04086 const wxSize& size = wxDefaultSize, 04087 long style = wxHSCROLL | wxVSCROLL, 04088 const wxString& name = wxT("a2dDocumentViewWindow")); 04089 04090 04091 //! Constructor for creation without view. 04092 /*! 04093 \param parent the parent window for this window 04094 \param id The window identifier. 04095 It may take a value of -1 to indicate a default value. 04096 \param pos The window position. 04097 \param size The window size. 04098 \param style Window style, please look into wxWindows docs for an overview. 04099 \param name The name of the window. 04100 */ 04101 a2dDocumentViewWindow( wxWindow* parent, 04102 wxWindowID id = -1, 04103 const wxPoint& pos = wxDefaultPosition, 04104 const wxSize& size = wxDefaultSize, 04105 long style = wxHSCROLL | wxVSCROLL, 04106 const wxString& name = wxT("a2dDocumentViewWindow")); 04107 04108 //! Destructor. 04109 ~a2dDocumentViewWindow(); 04110 04111 DECLARE_CLASS(a2dDocumentViewWindow) 04112 }; 04113 04114 04115 04116 04117 #endif /* _WX_DOCREFH__ */ 04118 04119