wxArt2D
docmdiref.h
Go to the documentation of this file.
1 /*! \file wx/docview/docmdiref.h
2  \brief Frame classes for MDI document/view applications
3 
4  MSW way of having application with one wxFrame and several draggable
5  sub windows in that frame is called MDI. In here are the classes to be able to
6  connect views and documents into such a GUI.
7 
8  \author Julian Smart
9  \date Created 01/02/97
10 
11  Copyright: (c)
12 
13  Licence: wxWidgets licence
14 
15  RCS-ID: $Id: docmdiref.h,v 1.14 2009/09/29 20:06:46 titato Exp $
16 */
17 
18 #ifndef _WX_DOCMDIREF_H_
19 #define _WX_DOCMDIREF_H_
20 
21 #include "wx/defs.h"
22 
23 #if wxUSE_MDI_ARCHITECTURE && wxUSE_DOC_VIEW_ARCHITECTURE
24 
25 #include "wx/docview/docviewref.h"
26 #include "wx/mdi.h"
27 
28 //! Use wxDocMDIParentFrame instead of wxDocMDIParentFrame
29 /*!
30  This class is the replacement for the standard wxWindow wxDocMDIParentFrame
31 
32  \ingroup docview
33 
34 */
35 class A2DDOCVIEWDLLEXP a2dDocumentMDIParentFrame: public wxMDIParentFrame
36 
37 {
38 public:
39  //! Constructor.
40  /*!
41  \param parent The parent frame. This should be <code>NULL</code>
42  \param id The window identifier.
43  It may take a value of -1 to indicate a default value.
44  \param title The caption to be displayed on the frame's title bar.
45  \param pos The window position.
46  \param size The window size.
47  \param style Window style, please look into wxWindows docs for an overview.
48  \param name The name of the window.
49  */
50  a2dDocumentMDIParentFrame( wxFrame* parent, wxWindowID id,
51  const wxString& title, const wxPoint& pos = wxDefaultPosition,
52  const wxSize& size = wxDefaultSize, long style = wxDEFAULT_FRAME_STYLE, const wxString& name = wxT( "frame" ) );
53 
55 
56  //! Constructor for two-step creation (2nd step).
57  /*!
58  \param frame The parent frame. This should not be <code>NULL</code>
59  \param id The window identifier.
60  It may take a value of -1 to indicate a default value.
61  \param title The caption to be displayed on the frame's title bar.
62  \param pos The window position.
63  \param size The window size.
64  \param style Window style, please look into wxWindows docs for an overview.
65  \param name The name of the window.
66  */
67  bool Create(
68  wxWindow* frame,
69  wxWindowID id = -1,
70  const wxString& title = wxT( "frame" ),
71  const wxPoint& pos = wxDefaultPosition,
72  const wxSize& size = wxDefaultSize,
73  long style = wxDEFAULT_FRAME_STYLE,
74  const wxString& name = wxT( "frame" ) );
75 
76  //! Extend event processing to search the document manager's event table
77  virtual bool ProcessEvent( wxEvent& event );
78 
79  //! Does a call to Close()
80  void OnExit( wxCommandEvent& event );
81 
82  //! Creates a new view for a file from file-history (a new MDI child will be created)
83  void OnMRUFile( wxCommandEvent& event );
84 
85  //! Closes the this window, if not vetoed.
86  void OnCloseWindow( wxCloseEvent& event );
87 
88  //! add a command menu to the parent menu, and connect it to the eventhandler of the frame
89  /*!
90  Many commands which can be submitted to a commandprocessor in the following manner:
91  \code
92  commandprocessor->Submit( new a2dCommand_SomeCommand() )
93  \endcode
94  Submitting the command makes it possible to undo the action.
95  To issue such a command from a menu requires an Id. Therefore wxDocview defines many predefined
96  menus items in the form of a2dMenuIdItem. They produce a unique Id to be handled in
97  the commandprocessor. Like in:
98  \code
99  void a2dDocumentCommandProcessor::OnMenu( wxCommandEvent& event )
100  \endcode
101  Several modules in wxDocview extend, in the derived a2dDocumentCommandProcessor, the set of handled
102  menu Id's. The OnMenu intercepts the menu event, and sets up a new a2dCommand to be submitted.
103  Understand that a2dDocumentFrame and a2dDocumentMDIParentFrame already redirect non handled events to
104  the commandprocessor of the application.
105  An a2dMenuIdItem defined menu text and helpstring, therefore all you need to do to add a command to
106  your application is AddCmdMenu().
107  Many commands have parameters, and a a2dMenuIdItem its Id, can only be coupled to one a2dCommand with
108  some predefined set of parameters.
109  If you need a different implementation of the same command you can extend in the same manner
110  in your derived commandprocessor. But you can always use the standard way of wxWidgets to add a menu,
111  and add a handler in the frame. In the handler setsup the a2dCommand and submits it.
112  Exactly the same behaviour, only not predefined.
113 
114  \remark a2dMenuIdItem uses Id my name ready to be used by XRC files.
115  */
116  void AddCmdMenu( wxMenu* parentMenu, const a2dMenuIdItem& cmdId );
117 
118  //! same as for a2dMenuIdItem, Id in wxMenuItem must be a valid id from one a2dMenuIdItem
119  //! used in XRC files
120  void AddCmdMenu( wxMenu* parentMenu, wxMenuItem* item );
121 
122  //! remove a command menu from the parent menu.
123  /*!
124  See AddCmdMenu()
125  */
126  void RemoveCmdMenu( wxMenu* parentMenu, const a2dMenuIdItem& cmdId );
127 
128  //! add items to toolbar using a predefined command ID.
129  void AddCmdToToolbar( const a2dMenuIdItem& cmdId );
130 
131 protected:
132 
133  //! used by AddCmdMenu() to dynamically connect menu to function.
134  //! The function just Skippes the event, so it will be handled by a command processor in the end.
135  void OnCmdMenuId( wxCommandEvent& event );
136 
137 private:
138 
139  DECLARE_CLASS( a2dDocumentMDIParentFrame )
140  DECLARE_EVENT_TABLE()
141 };
142 
143 //!The a2dDocumentMDIChildFrame class provides a default frame for displaying documents
144 /*!
145  In case of a wxEVT_CLOSE_WINDOW event, it is first redirected to the window, and
146  if not vetod to the view.
147 
148  \ingroup docview
149 */
150 class A2DDOCVIEWDLLEXP a2dDocumentMDIChildFrame: public wxMDIChildFrame
151 {
152 
153 public:
154 
155  //! Constructor for two-step creation. Call a2dDocumentMDIChildFrame::Create later
157 
158  //! Constructor
159  /*!
160  \param frame The parent frame. This should not be <code>NULL</code>
161  \param view The view for the document ( can be <code>NULL</code> )
162  \param id The window identifier.
163  It may take a value of -1 to indicate a default value.
164  \param title The caption to be displayed on the frame's title bar.
165  \param pos The window position.
166  \param size The window size.
167  \param style Window style, please look into wxWindows docs for an overview.
168  \param name The name of the window.
169  */
171  wxMDIParentFrame* frame,
172  a2dView* view = NULL,
173  wxWindowID id = -1,
174  const wxString& title = wxT( "a2dDocumentMDIChildFrame" ),
175  const wxPoint& pos = wxDefaultPosition,
176  const wxSize& size = wxDefaultSize,
177  long style = wxDEFAULT_FRAME_STYLE,
178  const wxString& name = wxT( "a2dDocumentMDIChildFrame" ) );
179 
180  //! Constructor for two-step creation (2nd step).
181  /*!
182  \param frame The parent frame. This should not be <code>NULL</code>
183  \param view The view for the document ( can be <code>NULL</code> )
184  \param id The window identifier.
185  It may take a value of -1 to indicate a default value.
186  \param title The caption to be displayed on the frame's title bar.
187  \param pos The window position.
188  \param size The window size.
189  \param style Window style, please look into wxWindows docs for an overview.
190  \param name The name of the window.
191  */
192  bool Create(
193  wxMDIParentFrame* frame,
194  a2dView* view = NULL,
195  wxWindowID id = -1,
196  const wxString& title = wxT( "a2dDocumentMDIChildFrame" ),
197  const wxPoint& pos = wxDefaultPosition,
198  const wxSize& size = wxDefaultSize,
199  long style = wxDEFAULT_FRAME_STYLE,
200  const wxString& name = wxT( "a2dDocumentMDIChildFrame" ) );
201 
202  //! Destructor
204 
205  //! set a pointer to a a2dView to sent view events to.
206  /*!
207  Normally set via OnActivateViewSentFromChild()
208 
209  The m_view is used to redirect the frame event for closing the window,
210  and the activate event for the frame, to the view.
211  Only if the m_view->GetDisplayWindow() is the a2dDocumentFrame itself, it will also be used for
212  drawing the view ( See OnDraw() )
213  */
214  void SetView( a2dView* view );
215 
216  //! get the pointer to a a2dView to which view events are sent
217  inline a2dView* GetView( void ) const { return m_view; }
218 
219  void SetDestroyOnCloseView( bool destroyOnCloseView ) { m_destroyOnCloseView = destroyOnCloseView; }
220 
221  //! Extend event processing to search the view's event table
222  virtual bool ProcessEvent( wxEvent& event );
223 
224  void OnActivate( wxActivateEvent& event );
225  void OnCloseWindow( wxCloseEvent& event );
226 
227  bool Destroy();
228 
229  //! Override this function to draw the graphic (or just process EVT_PAINT)
230  /*!
231  The default handler for EVT_PAINT is OnPaint, and it calls OnDraw().
232  OnDraw its default implementation is calling the m_view its OnDraw().
233  */
234  virtual void OnDraw( wxDC& dc );
235 
236  //! add a command menu to the parent menu, and connect it to the eventhandler of the frame
237  /*!
238  Many commands which can be submitted to a commandprocessor in the following manner:
239  \code
240  commandprocessor->Submit( new a2dCommand_SomeCommand() )
241  \endcode
242  Submitting the command makes it possible to undo the action.
243  To issue such a command from a menu requires an Id. Therefore wxDocview defines many predefined
244  menus items in the form of a2dMenuIdItem. They produce a unique Id to be handled in
245  the commandprocessor. Like in:
246  \code
247  void a2dDocumentCommandProcessor::OnMenu( wxCommandEvent& event )
248  \endcode
249  Several modules in wxDocview extend, in the derived a2dDocumentCommandProcessor, the set of handled
250  menu Id's. The OnMenu intercepts the menu event, and sets up a new a2dCommand to be submitted.
251  Understand that a2dDocumentFrame and a2dDocumentMDIParentFrame already redirect non handled events to
252  the commandprocessor of the application.
253  An a2dMenuIdItem defined menu text and helpstring, therefore all you need to do to add a command to
254  your application is AddCmdMenu().
255  Many commands have parameters, and a a2dMenuIdItem its Id, can only be coupled to one a2dCommand with
256  some predefined set of parameters.
257  If you need a different implementation of the same command you can extend in the same manner
258  in your derived commandprocessor. But you can always use the standard way of wxWidgets to add a menu,
259  and add a handler in the frame. In the handler setsup the a2dCommand and submits it.
260  Exactly the same behaviour, only not predefined.
261 
262  \remark a2dMenuIdItem uses Id my name ready to be used by XRC files.
263  */
264  void AddCmdMenu( wxMenu* parentMenu, const a2dMenuIdItem& cmdId );
265 
266  //! same as for a2dMenuIdItem, Id in wxMenuItem must be a valid id from one a2dMenuIdItem
267  //! used in XRC files
268  void AddCmdMenu( wxMenu* parentMenu, wxMenuItem* item );
269 
270  //! remove a command menu from the parent menu.
271  /*!
272  See AddCmdMenu()
273  */
274  void RemoveCmdMenu( wxMenu* parentMenu, const a2dMenuIdItem& cmdId );
275 
276  //! add items to toolbar using a predefined command ID.
277  void AddCmdToToolbar( const a2dMenuIdItem& cmdId );
278 
279 protected:
280 
281  //! used by AddCmdMenu() to dynamically connect menu to function.
282  //! The function just Skippes the event, so it will be handled by a command processor in the end.
283  void OnCmdMenuId( wxCommandEvent& event );
284 
285  //! default handler for paint events, it calls OnDraw().
286  void OnPaint( wxPaintEvent& event );
287 
288  //! default for closing a view in this frame
289  /*!
290  Close the view of the current m_window and destroy the frame.
291  */
292  void OnCloseView( a2dCloseViewEvent& event );
293 
294  //! sets m_view to the current active view, generate by a2dView::Activate()
295  void OnActivateViewSentFromChild( a2dViewEvent& viewevent );
296 
297  //! used for redirecting close and activate events to the view which has the focus.
298  //! See SetView()
300 
301  //! when closing the view the frame will be destroyed.
303 
304 private:
305 
306  DECLARE_EVENT_TABLE()
307  DECLARE_CLASS( a2dDocumentMDIChildFrame )
308 };
309 
310 #endif /* wxUSE_MDI_ARCHITECTURE && wxUSE_DOC_VIEW_ARCHITECTURE */
311 
312 #endif /* _WX_DOCMDIREF_H_ */
313 
314 
The a2dDocumentMDIChildFrame class provides a default frame for displaying documents.
Definition: docmdiref.h:150
a2dView * GetView(void) const
get the pointer to a a2dView to which view events are sent
Definition: docmdiref.h:217
store a menu Id generated by XRCID( menuIdString ) plus a menustring and helpstring ...
Definition: comevt.h:1563
a2dView event, to report events in the a2dView class
Definition: docviewref.h:424
Holds a view on a a2dDocument.
Definition: docviewref.h:1804
Docview classes for document view, window and frame.
bool m_destroyOnCloseView
when closing the view the frame will be destroyed.
Definition: docmdiref.h:302
see a2dDocumentEvent
Definition: docviewref.h:356
Use wxDocMDIParentFrame instead of wxDocMDIParentFrame.
Definition: docmdiref.h:35
a2dSmrtPtr< a2dView > m_view
Definition: docmdiref.h:299
docmdiref.h Source File -- Sun Oct 12 2014 17:04:15 -- Sun Oct 12 2014 -- 1.8.5 -- wxArt2D -- . -- Main Page Reference Documentation