00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014 #include "docviewprec.h"
00015
00016 #ifdef __BORLANDC__
00017 #pragma hdrstop
00018 #endif
00019
00020 #ifndef WX_PRECOMP
00021 #include "wx/wx.h"
00022 #endif
00023
00024 #if wxUSE_MDI_ARCHITECTURE && wxUSE_DOC_VIEW_ARCHITECTURE
00025
00026 #ifndef WX_PRECOMP
00027 #include "wx/string.h"
00028 #include "wx/utils.h"
00029 #include "wx/app.h"
00030 #include "wx/dc.h"
00031 #include "wx/dialog.h"
00032 #include "wx/menu.h"
00033 #include "wx/list.h"
00034 #include "wx/filedlg.h"
00035 #include "wx/intl.h"
00036 #include "wx/file.h"
00037 #endif
00038
00039 #include "wx/docview/doccom.h"
00040 #include "wx/docview/docmdiref.h"
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056 IMPLEMENT_CLASS(a2dDocumentMDIParentFrame, wxMDIParentFrame)
00057
00058 BEGIN_EVENT_TABLE(a2dDocumentMDIParentFrame, wxMDIParentFrame)
00059 EVT_MENU(wxID_EXIT, a2dDocumentMDIParentFrame::OnExit)
00060 EVT_MENU_RANGE(wxID_FILE1, wxID_FILE9, a2dDocumentMDIParentFrame::OnMRUFile)
00061 EVT_CLOSE(a2dDocumentMDIParentFrame::OnCloseWindow)
00062 END_EVENT_TABLE()
00063
00064 a2dDocumentMDIParentFrame::a2dDocumentMDIParentFrame( wxFrame *frame, wxWindowID id, const wxString& title,
00065 const wxPoint& pos, const wxSize& size, long style, const wxString& name):
00066 wxMDIParentFrame(frame, id, title, pos, size, style, name)
00067 {
00068 }
00069
00070 a2dDocumentMDIParentFrame::a2dDocumentMDIParentFrame()
00071 {
00072 }
00073
00074 bool a2dDocumentMDIParentFrame::Create(
00075 wxWindow* frame,
00076 wxWindowID id,
00077 const wxString& title,
00078 const wxPoint& pos,
00079 const wxSize& size,
00080 long style,
00081 const wxString& name)
00082 {
00083 bool res = wxMDIParentFrame::Create(frame, id, title, pos, size, style, name);
00084 return res;
00085 }
00086
00087
00088 void a2dDocumentMDIParentFrame::OnExit(wxCommandEvent& WXUNUSED(event))
00089 {
00090 Close();
00091 }
00092
00093 void a2dDocumentMDIParentFrame::OnMRUFile(wxCommandEvent& event)
00094 {
00095 int n = event.GetId() - wxID_FILE1;
00096 a2dFileHistoryItem* fileHistItem = a2dDocviewGlobals->GetDocviewCommandProcessor()->GetHistoryFileItem(n);
00097 if ( fileHistItem )
00098 {
00099
00100 if ( wxFile::Exists( fileHistItem->m_filename.GetFullPath() ) )
00101 {
00102
00103 a2dError returncode = a2dDocviewGlobals->GetDocviewCommandProcessor()->CreateDocuments( fileHistItem->m_filename.GetFullPath(), a2dREFDOC_SILENT, fileHistItem->m_docTemplate );
00104 if ( returncode == a2dError_NoDocTemplateRef )
00105 {
00106 a2dDocviewGlobals->ReportError( a2dError_CouldNotCreateDocument, _("No templates to create document, removed from history, a2dDocumentCommandProcessor::OnMRUFile"));
00107 a2dDocviewGlobals->GetDocviewCommandProcessor()->RemoveFileFromHistory(n);
00108 }
00109 }
00110 else
00111 {
00112 a2dDocviewGlobals->ReportErrorF( a2dError_FileHistory, _("The file '%s' doesn't exist and couldn't be opened.\nIt has been removed from the most recently used files list."),
00113 fileHistItem->m_filename.GetFullPath().c_str());
00114
00115
00116
00117 a2dDocviewGlobals->GetDocviewCommandProcessor()->RemoveFileFromHistory(n);
00118 }
00119 }
00120 }
00121
00122 bool a2dDocumentMDIParentFrame::ProcessEvent(wxEvent& event)
00123 {
00124 if ( !wxEvtHandler::ProcessEvent(event) )
00125 {
00126 if ( a2dDocviewGlobals->GetDocviewCommandProcessor() )
00127 return a2dDocviewGlobals->GetDocviewCommandProcessor()->ProcessEvent(event);
00128 return false;
00129 }
00130 return true;
00131 }
00132
00133 void a2dDocumentMDIParentFrame::OnCloseWindow(wxCloseEvent& event)
00134 {
00135 if (a2dDocviewGlobals->GetDocviewCommandProcessor()->Clear(!event.CanVeto()))
00136 {
00137 this->Destroy();
00138 }
00139 else
00140 event.Veto();
00141 }
00142
00143 void a2dDocumentMDIParentFrame::OnCmdMenuId(wxCommandEvent &event)
00144 {
00145 event.Skip();
00146 }
00147
00148 void a2dDocumentMDIParentFrame::AddCmdMenu( wxMenu* parentMenu, wxMenuItem* item )
00149 {
00150 Connect( item->GetId(), wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( a2dDocumentMDIParentFrame::OnCmdMenuId ) );
00151 parentMenu->Append( item );
00152 }
00153
00154 void a2dDocumentMDIParentFrame::AddCmdMenu( wxMenu* parentMenu, const a2dMenuIdItem& cmdId )
00155 {
00156 Connect( cmdId.GetId(), wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( a2dDocumentMDIParentFrame::OnCmdMenuId ) );
00157 parentMenu->Append( cmdId.GetId(), cmdId.GetLabel(), cmdId.GetHelp(), cmdId.IsCheckable() );
00158 }
00159
00160 void a2dDocumentMDIParentFrame::RemoveCmdMenu( wxMenu* parentMenu, const a2dMenuIdItem& cmdId )
00161 {
00162 Disconnect( cmdId.GetId(), wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( a2dDocumentMDIParentFrame::OnCmdMenuId ) );
00163 parentMenu->Delete( cmdId.GetId() );
00164 }
00165
00166 void a2dDocumentMDIParentFrame::AddCmdToToolbar( const a2dMenuIdItem& cmdId )
00167 {
00168 if ( ! GetToolBar() )
00169 return;
00170 Connect( cmdId.GetId(), wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( a2dDocumentMDIParentFrame::OnCmdMenuId ) );
00171 wxString error = _T("No Bitmap for a2dToolCmd found for:") + cmdId.GetIdName();
00172 wxASSERT_MSG( cmdId.GetBitmap(false).Ok(), error );
00173 GetToolBar()->AddTool( cmdId.GetId(), cmdId.GetLabel(), cmdId.GetBitmap(false), cmdId.GetHelp() );
00174 }
00175
00176
00177
00178
00179
00180 IMPLEMENT_CLASS(a2dDocumentMDIChildFrame, wxMDIChildFrame)
00181
00182 BEGIN_EVENT_TABLE( a2dDocumentMDIChildFrame, wxMDIChildFrame)
00183 EVT_ACTIVATE( a2dDocumentMDIChildFrame::OnActivate)
00184 EVT_CLOSE( a2dDocumentMDIChildFrame::OnCloseWindow)
00185 EVT_PAINT( a2dDocumentMDIChildFrame::OnPaint )
00186 EVT_ACTIVATE_VIEW_SENT_FROM_CHILD( a2dDocumentMDIChildFrame::OnActivateViewSentFromChild )
00187 EVT_CLOSE_VIEW( a2dDocumentMDIChildFrame::OnCloseView )
00188 END_EVENT_TABLE()
00189
00190
00191 a2dDocumentMDIChildFrame::a2dDocumentMDIChildFrame()
00192 {
00193 m_destroyOnCloseView = true;
00194 m_view = NULL;
00195 }
00196
00197
00198 a2dDocumentMDIChildFrame::a2dDocumentMDIChildFrame( wxMDIParentFrame *frame, a2dView *view, wxWindowID id,
00199 const wxString& title, const wxPoint& pos, const wxSize& size, long style, const wxString& name):
00200 wxMDIChildFrame(frame, id, title, pos, size, style, name)
00201 {
00202 m_destroyOnCloseView = true;
00203 m_view = view;
00204 if ( m_view )
00205 {
00206 m_view->SetDisplayWindow( this );
00207 }
00208 }
00209
00210 bool a2dDocumentMDIChildFrame::Create(
00211 wxMDIParentFrame* frame,
00212 a2dView* view,
00213 wxWindowID id,
00214 const wxString& title,
00215 const wxPoint& pos,
00216 const wxSize& size,
00217 long style,
00218 const wxString& name)
00219 {
00220 bool res = wxMDIChildFrame::Create(frame, id, title, pos, size, style, name);
00221 m_view = view;
00222 if ( m_view )
00223 {
00224 m_view->SetDisplayWindow( this );
00225 }
00226 return res;
00227 }
00228
00229 a2dDocumentMDIChildFrame::~a2dDocumentMDIChildFrame(void)
00230 {
00231 m_view = (a2dView *) NULL;
00232 }
00233
00234 void a2dDocumentMDIChildFrame::OnCmdMenuId(wxCommandEvent &event)
00235 {
00236 event.Skip();
00237 }
00238
00239 void a2dDocumentMDIChildFrame::AddCmdMenu( wxMenu* parentMenu, wxMenuItem* item )
00240 {
00241 Connect( item->GetId(), wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( a2dDocumentMDIChildFrame::OnCmdMenuId ) );
00242 parentMenu->Append( item );
00243 }
00244
00245 void a2dDocumentMDIChildFrame::AddCmdMenu( wxMenu* parentMenu, const a2dMenuIdItem& cmdId )
00246 {
00247 Connect( cmdId.GetId(), wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( a2dDocumentMDIChildFrame::OnCmdMenuId ) );
00248 parentMenu->Append( cmdId.GetId(), cmdId.GetLabel(), cmdId.GetHelp(), cmdId.IsCheckable() );
00249 }
00250
00251 void a2dDocumentMDIChildFrame::RemoveCmdMenu( wxMenu* parentMenu, const a2dMenuIdItem& cmdId )
00252 {
00253 Disconnect( cmdId.GetId(), wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( a2dDocumentMDIChildFrame::OnCmdMenuId ) );
00254 parentMenu->Delete( cmdId.GetId() );
00255 }
00256
00257 void a2dDocumentMDIChildFrame::AddCmdToToolbar( const a2dMenuIdItem& cmdId )
00258 {
00259 if ( ! GetToolBar() )
00260 return;
00261 Connect( cmdId.GetId(), wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( a2dDocumentMDIChildFrame::OnCmdMenuId ) );
00262 wxString error = _T("No Bitmap for a2dToolCmd found for:") + cmdId.GetIdName();
00263 wxASSERT_MSG( cmdId.GetBitmap(false).Ok(), error );
00264 GetToolBar()->AddTool( cmdId.GetId(), cmdId.GetLabel(), cmdId.GetBitmap(false), cmdId.GetHelp() );
00265 }
00266
00267 void a2dDocumentMDIChildFrame::SetView( a2dView* view )
00268 {
00269 if ( m_view )
00270 {
00271 m_view->SetDisplayWindow( NULL );
00272 }
00273
00274 m_view = view;
00275
00276 if ( m_view )
00277 {
00278
00279 m_view->SetDisplayWindow( this );
00280 }
00281 }
00282
00283
00284 bool a2dDocumentMDIChildFrame::ProcessEvent(wxEvent& event)
00285 {
00286 static wxEvent *ActiveEvent = NULL;
00287
00288
00289 if (ActiveEvent == &event)
00290 return false;
00291
00292 ActiveEvent = &event;
00293
00294 bool ret = false;
00295 if ( event.GetEventType() == wxEVT_CLOSE_WINDOW )
00296 {
00297
00298
00299
00300
00301
00302 wxCloseEvent& closeevent = (wxCloseEvent&) event;
00303
00304
00305 if ( wxEvtHandler::ProcessEvent(event) && !closeevent.GetVeto() )
00306 {
00307 closeevent.SetCanVeto( false );
00308 if ( m_view )
00309 m_view->GetEventHandler()->ProcessEvent(closeevent);
00310 m_view = NULL;
00311 }
00312 else
00313 closeevent.Veto();
00314 ret = true;
00315 }
00316 else if ( event.GetEventType() == wxEVT_ACTIVATE )
00317 {
00318
00319
00320
00321
00322 if ( m_view && !m_view->IsClosed() )
00323 m_view->GetEventHandler()->ProcessEvent(event);
00324
00325 ret = wxEvtHandler::ProcessEvent(event);
00326 }
00327 else
00328 {
00329
00330
00331
00332
00333
00334
00335 if ( !wxEvtHandler::ProcessEvent(event) )
00336 {
00337
00338 if ( a2dDocviewGlobals->GetDocviewCommandProcessor() )
00339 {
00340 ret = a2dDocviewGlobals->GetDocviewCommandProcessor()->ProcessEvent(event);
00341 }
00342 else
00343 ret = false;
00344 }
00345 else
00346 ret = true;
00347 }
00348 ActiveEvent = NULL;
00349 return ret;
00350 }
00351
00352 void a2dDocumentMDIChildFrame::OnActivate(wxActivateEvent& event)
00353 {
00354 wxMDIChildFrame::OnActivate(event);
00355
00356 if (event.GetActive() && m_view)
00357 m_view->Activate(event.GetActive());
00358 }
00359
00360 void a2dDocumentMDIChildFrame::OnActivateViewSentFromChild( a2dViewEvent& viewevent )
00361 {
00362 if ( viewevent.GetActive() )
00363 {
00364 m_view = (a2dView*) viewevent.GetEventObject();
00365 }
00366 }
00367
00368
00369
00370
00371 void a2dDocumentMDIChildFrame::OnCloseView( a2dCloseViewEvent& event )
00372 {
00373 wxASSERT_MSG( m_view || event.GetEventObject(), wxT("not view of frame closed") );
00374
00375
00376
00377
00378
00379 if ( m_destroyOnCloseView )
00380 Destroy();
00381
00382 if ( m_view )
00383 m_view->SetDisplayWindow( NULL );
00384 m_view = NULL;
00385
00386 Refresh();
00387 }
00388
00389 void a2dDocumentMDIChildFrame::OnCloseWindow(wxCloseEvent& event)
00390 {
00391 if ( !m_view )
00392 Destroy();
00393
00394
00395
00396
00397 if ( event.CanVeto() )
00398 {
00399 if ( !m_view || m_view->Close( !event.CanVeto() ) )
00400 Destroy();
00401 else
00402 event.Veto( true );
00403
00404 }
00405 else
00406 Destroy();
00407 }
00408
00409 bool a2dDocumentMDIChildFrame::Destroy()
00410 {
00411 m_view = (a2dView *)NULL;
00412 return wxMDIChildFrame::Destroy();
00413 }
00414
00415 void a2dDocumentMDIChildFrame::OnPaint(wxPaintEvent& WXUNUSED(event) )
00416 {
00417 wxPaintDC dc( this );
00418 PrepareDC(dc);
00419
00420 if ( m_view && m_view->GetDisplayWindow() == this )
00421 OnDraw(dc);
00422 }
00423
00424
00425 void a2dDocumentMDIChildFrame::OnDraw(wxDC& dc)
00426 {
00427 if ( m_view && m_view->GetDisplayWindow() == this )
00428 m_view->OnDraw(& dc);
00429 }
00430
00431 #endif
00432
00433