00001 /*! \file wx/docview/docmdiref.h 00002 \brief Frame classes for MDI document/view applications 00003 00004 MSW way of having application with one wxFrame and several draggable 00005 sub windows in that frame is called MDI. In here are the classes to be able to 00006 connect views and documents into such a GUI. 00007 00008 \author Julian Smart 00009 \date Created 01/02/97 00010 00011 Copyright: (c) 00012 00013 Licence: wxWidgets licence 00014 00015 RCS-ID: $Id: docmdiref.h,v 1.14 2009/09/29 20:06:46 titato Exp $ 00016 */ 00017 00018 #ifndef _WX_DOCMDIREF_H_ 00019 #define _WX_DOCMDIREF_H_ 00020 00021 #include "wx/defs.h" 00022 00023 #if wxUSE_MDI_ARCHITECTURE && wxUSE_DOC_VIEW_ARCHITECTURE 00024 00025 #include "wx/docview/docviewref.h" 00026 #include "wx/mdi.h" 00027 00028 //! Use wxDocMDIParentFrame instead of wxDocMDIParentFrame 00029 /*! 00030 This class is the replacement for the standard wxWindow wxDocMDIParentFrame 00031 00032 \ingroup docview 00033 00034 */ 00035 class A2DDOCVIEWDLLEXP a2dDocumentMDIParentFrame: public wxMDIParentFrame 00036 00037 { 00038 public: 00039 //! Constructor. 00040 /*! 00041 \param parent The parent frame. This should be <code>NULL</code> 00042 \param id The window identifier. 00043 It may take a value of -1 to indicate a default value. 00044 \param title The caption to be displayed on the frame's title bar. 00045 \param pos The window position. 00046 \param size The window size. 00047 \param style Window style, please look into wxWindows docs for an overview. 00048 \param name The name of the window. 00049 */ 00050 a2dDocumentMDIParentFrame( wxFrame *parent, wxWindowID id, 00051 const wxString& title, const wxPoint& pos = wxDefaultPosition, 00052 const wxSize& size = wxDefaultSize, long style = wxDEFAULT_FRAME_STYLE, const wxString& name = wxT("frame")); 00053 00054 a2dDocumentMDIParentFrame(); 00055 00056 //! Constructor for two-step creation (2nd step). 00057 /*! 00058 \param frame The parent frame. This should not be <code>NULL</code> 00059 \param id The window identifier. 00060 It may take a value of -1 to indicate a default value. 00061 \param title The caption to be displayed on the frame's title bar. 00062 \param pos The window position. 00063 \param size The window size. 00064 \param style Window style, please look into wxWindows docs for an overview. 00065 \param name The name of the window. 00066 */ 00067 bool Create( 00068 wxWindow* frame, 00069 wxWindowID id = -1, 00070 const wxString& title = wxT("frame"), 00071 const wxPoint& pos = wxDefaultPosition, 00072 const wxSize& size = wxDefaultSize, 00073 long style = wxDEFAULT_FRAME_STYLE, 00074 const wxString& name = wxT("frame")); 00075 00076 //! Extend event processing to search the document manager's event table 00077 virtual bool ProcessEvent(wxEvent& event); 00078 00079 //! Does a call to Close() 00080 void OnExit(wxCommandEvent& event); 00081 00082 //! Creates a new view for a file from file-history (a new MDI child will be created) 00083 void OnMRUFile(wxCommandEvent& event); 00084 00085 //! Closes the this window, if not vetoed. 00086 void OnCloseWindow(wxCloseEvent& event); 00087 00088 //! add a command menu to the parent menu, and connect it to the eventhandler of the frame 00089 /*! 00090 Many commands which can be submitted to a commandprocessor in the following manner: 00091 \code 00092 commandprocessor->Submit( new a2dCommand_SomeCommand() ) 00093 \endcode 00094 Submitting the command makes it possible to undo the action. 00095 To issue such a command from a menu requires an Id. Therefore wxDocview defines many predefined 00096 menus items in the form of a2dMenuIdItem. They produce a unique Id to be handled in 00097 the commandprocessor. Like in: 00098 \code 00099 void a2dDocumentCommandProcessor::OnMenu( wxCommandEvent& event ) 00100 \endcode 00101 Several modules in wxDocview extend, in the derived a2dDocumentCommandProcessor, the set of handled 00102 menu Id's. The OnMenu intercepts the menu event, and sets up a new a2dCommand to be submitted. 00103 Understand that a2dDocumentFrame and a2dDocumentMDIParentFrame already redirect non handled events to 00104 the commandprocessor of the application. 00105 An a2dMenuIdItem defined menu text and helpstring, therefore all you need to do to add a command to 00106 your application is AddCmdMenu(). 00107 Many commands have parameters, and a a2dMenuIdItem its Id, can only be coupled to one a2dCommand with 00108 some predefined set of parameters. 00109 If you need a different implementation of the same command you can extend in the same manner 00110 in your derived commandprocessor. But you can always use the standard way of wxWidgets to add a menu, 00111 and add a handler in the frame. In the handler setsup the a2dCommand and submits it. 00112 Exactly the same behaviour, only not predefined. 00113 00114 \remark a2dMenuIdItem uses Id my name ready to be used by XRC files. 00115 */ 00116 void AddCmdMenu( wxMenu* parentMenu, const a2dMenuIdItem& cmdId ); 00117 00118 //! same as for a2dMenuIdItem, Id in wxMenuItem must be a valid id from one a2dMenuIdItem 00119 //! used in XRC files 00120 void AddCmdMenu( wxMenu* parentMenu, wxMenuItem* item ); 00121 00122 //! remove a command menu from the parent menu. 00123 /*! 00124 See AddCmdMenu() 00125 */ 00126 void RemoveCmdMenu( wxMenu* parentMenu, const a2dMenuIdItem& cmdId ); 00127 00128 //! add items to toolbar using a predefined command ID. 00129 void AddCmdToToolbar( const a2dMenuIdItem& cmdId ); 00130 00131 protected: 00132 00133 //! used by AddCmdMenu() to dynamically connect menu to function. 00134 //! The function just Skippes the event, so it will be handled by a command processor in the end. 00135 void OnCmdMenuId(wxCommandEvent &event); 00136 00137 private: 00138 00139 DECLARE_CLASS(a2dDocumentMDIParentFrame) 00140 DECLARE_EVENT_TABLE() 00141 }; 00142 00143 //!The a2dDocumentMDIChildFrame class provides a default frame for displaying documents 00144 /*! 00145 In case of a wxEVT_CLOSE_WINDOW event, it is first redirected to the window, and 00146 if not vetod to the view. 00147 00148 \ingroup docview 00149 */ 00150 class A2DDOCVIEWDLLEXP a2dDocumentMDIChildFrame: public wxMDIChildFrame 00151 { 00152 00153 public: 00154 00155 //! Constructor for two-step creation. Call a2dDocumentMDIChildFrame::Create later 00156 a2dDocumentMDIChildFrame(); 00157 00158 //! Constructor 00159 /*! 00160 \param frame The parent frame. This should not be <code>NULL</code> 00161 \param view The view for the document ( can be <code>NULL</code> ) 00162 \param id The window identifier. 00163 It may take a value of -1 to indicate a default value. 00164 \param title The caption to be displayed on the frame's title bar. 00165 \param pos The window position. 00166 \param size The window size. 00167 \param style Window style, please look into wxWindows docs for an overview. 00168 \param name The name of the window. 00169 */ 00170 a2dDocumentMDIChildFrame( 00171 wxMDIParentFrame* frame, 00172 a2dView* view = NULL, 00173 wxWindowID id = -1, 00174 const wxString& title = wxT("a2dDocumentMDIChildFrame"), 00175 const wxPoint& pos = wxDefaultPosition, 00176 const wxSize& size = wxDefaultSize, 00177 long style = wxDEFAULT_FRAME_STYLE, 00178 const wxString& name = wxT("a2dDocumentMDIChildFrame")); 00179 00180 //! Constructor for two-step creation (2nd step). 00181 /*! 00182 \param frame The parent frame. This should not be <code>NULL</code> 00183 \param view The view for the document ( can be <code>NULL</code> ) 00184 \param id The window identifier. 00185 It may take a value of -1 to indicate a default value. 00186 \param title The caption to be displayed on the frame's title bar. 00187 \param pos The window position. 00188 \param size The window size. 00189 \param style Window style, please look into wxWindows docs for an overview. 00190 \param name The name of the window. 00191 */ 00192 bool Create( 00193 wxMDIParentFrame* frame, 00194 a2dView* view = NULL, 00195 wxWindowID id = -1, 00196 const wxString& title = wxT("a2dDocumentMDIChildFrame"), 00197 const wxPoint& pos = wxDefaultPosition, 00198 const wxSize& size = wxDefaultSize, 00199 long style = wxDEFAULT_FRAME_STYLE, 00200 const wxString& name = wxT("a2dDocumentMDIChildFrame")); 00201 00202 //! Destructor 00203 ~a2dDocumentMDIChildFrame(); 00204 00205 //! set a pointer to a a2dView to sent view events to. 00206 /*! 00207 Normally set via OnActivateViewSentFromChild() 00208 00209 The m_view is used to redirect the frame event for closing the window, 00210 and the activate event for the frame, to the view. 00211 Only if the m_view->GetDisplayWindow() is the a2dDocumentFrame itself, it will also be used for 00212 drawing the view ( See OnDraw() ) 00213 */ 00214 void SetView( a2dView* view ); 00215 00216 //! get the pointer to a a2dView to which view events are sent 00217 inline a2dView *GetView(void) const { return m_view; } 00218 00219 void SetDestroyOnCloseView( bool destroyOnCloseView ) { m_destroyOnCloseView = destroyOnCloseView; } 00220 00221 //! Extend event processing to search the view's event table 00222 virtual bool ProcessEvent(wxEvent& event); 00223 00224 void OnActivate(wxActivateEvent& event); 00225 void OnCloseWindow(wxCloseEvent& event); 00226 00227 bool Destroy(); 00228 00229 //! Override this function to draw the graphic (or just process EVT_PAINT) 00230 /*! 00231 The default handler for EVT_PAINT is OnPaint, and it calls OnDraw(). 00232 OnDraw its default implementation is calling the m_view its OnDraw(). 00233 */ 00234 virtual void OnDraw(wxDC& dc); 00235 00236 //! add a command menu to the parent menu, and connect it to the eventhandler of the frame 00237 /*! 00238 Many commands which can be submitted to a commandprocessor in the following manner: 00239 \code 00240 commandprocessor->Submit( new a2dCommand_SomeCommand() ) 00241 \endcode 00242 Submitting the command makes it possible to undo the action. 00243 To issue such a command from a menu requires an Id. Therefore wxDocview defines many predefined 00244 menus items in the form of a2dMenuIdItem. They produce a unique Id to be handled in 00245 the commandprocessor. Like in: 00246 \code 00247 void a2dDocumentCommandProcessor::OnMenu( wxCommandEvent& event ) 00248 \endcode 00249 Several modules in wxDocview extend, in the derived a2dDocumentCommandProcessor, the set of handled 00250 menu Id's. The OnMenu intercepts the menu event, and sets up a new a2dCommand to be submitted. 00251 Understand that a2dDocumentFrame and a2dDocumentMDIParentFrame already redirect non handled events to 00252 the commandprocessor of the application. 00253 An a2dMenuIdItem defined menu text and helpstring, therefore all you need to do to add a command to 00254 your application is AddCmdMenu(). 00255 Many commands have parameters, and a a2dMenuIdItem its Id, can only be coupled to one a2dCommand with 00256 some predefined set of parameters. 00257 If you need a different implementation of the same command you can extend in the same manner 00258 in your derived commandprocessor. But you can always use the standard way of wxWidgets to add a menu, 00259 and add a handler in the frame. In the handler setsup the a2dCommand and submits it. 00260 Exactly the same behaviour, only not predefined. 00261 00262 \remark a2dMenuIdItem uses Id my name ready to be used by XRC files. 00263 */ 00264 void AddCmdMenu( wxMenu* parentMenu, const a2dMenuIdItem& cmdId ); 00265 00266 //! same as for a2dMenuIdItem, Id in wxMenuItem must be a valid id from one a2dMenuIdItem 00267 //! used in XRC files 00268 void AddCmdMenu( wxMenu* parentMenu, wxMenuItem* item ); 00269 00270 //! remove a command menu from the parent menu. 00271 /*! 00272 See AddCmdMenu() 00273 */ 00274 void RemoveCmdMenu( wxMenu* parentMenu, const a2dMenuIdItem& cmdId ); 00275 00276 //! add items to toolbar using a predefined command ID. 00277 void AddCmdToToolbar( const a2dMenuIdItem& cmdId ); 00278 00279 protected: 00280 00281 //! used by AddCmdMenu() to dynamically connect menu to function. 00282 //! The function just Skippes the event, so it will be handled by a command processor in the end. 00283 void OnCmdMenuId(wxCommandEvent &event); 00284 00285 //! default handler for paint events, it calls OnDraw(). 00286 void OnPaint( wxPaintEvent &event ); 00287 00288 //! default for closing a view in this frame 00289 /*! 00290 Close the view of the current m_window and destroy the frame. 00291 */ 00292 void OnCloseView( a2dCloseViewEvent& event ); 00293 00294 //! sets m_view to the current active view, generate by a2dView::Activate() 00295 void OnActivateViewSentFromChild( a2dViewEvent& viewevent ); 00296 00297 //! used for redirecting close and activate events to the view which has the focus. 00298 //! See SetView() 00299 a2dSmrtPtr<a2dView> m_view; 00300 00301 //! when closing the view the frame will be destroyed. 00302 bool m_destroyOnCloseView; 00303 00304 private: 00305 00306 DECLARE_EVENT_TABLE() 00307 DECLARE_CLASS(a2dDocumentMDIChildFrame) 00308 }; 00309 00310 #endif /* wxUSE_MDI_ARCHITECTURE && wxUSE_DOC_VIEW_ARCHITECTURE */ 00311 00312 #endif /* _WX_DOCMDIREF_H_ */ 00313 00314