bool MyApp::OnInit() { if ( !wxApp::OnInit() ) return false; ::wxInitAllImageHandlers(); // Fill in the application information fields before creating wxConfig. SetVendorName("wxWidgets"); SetAppName("wx_docview_sample"); SetAppDisplayName("wxWidgets DocView Sample"); //// Create a document manager wxDocManager *docManager = new wxDocManager; //// Create a template relating drawing documents to their views new wxDocTemplate(docManager, "Drawing", "*.drw", "", "drw", "Drawing Doc", "Drawing View", CLASSINFO(DrawingDocument), CLASSINFO(DrawingView)); #if defined( __WXMAC__ ) && wxOSX_USE_CARBON wxFileName::MacRegisterDefaultTypeAndCreator("drw" , 'WXMB' , 'WXMA'); #endif if ( m_mode == Mode_Single ) { // If we've only got one window, we only get to edit one document at a // time. Therefore no text editing, just doodling. docManager->SetMaxDocsOpen(1); } else // multiple documents mode: allow documents of different types { // Create a template relating text documents to their views new wxDocTemplate(docManager, "Text", "*.txt;*.text", "", "txt;text", "Text Doc", "Text View", CLASSINFO(TextEditDocument), CLASSINFO(TextEditView)); #if defined( __WXMAC__ ) && wxOSX_USE_CARBON wxFileName::MacRegisterDefaultTypeAndCreator("txt" , 'TEXT' , 'WXMA'); #endif // Create a template relating image documents to their views new wxDocTemplate(docManager, "Image", "*.png;*.jpg", "", "png;jpg", "Image Doc", "Image View", CLASSINFO(ImageDocument), CLASSINFO(ImageView)); } // create the main frame window wxFrame *frame; #if wxUSE_MDI_ARCHITECTURE if ( m_mode == Mode_MDI ) { frame = new wxDocMDIParentFrame(docManager, NULL, wxID_ANY, GetAppDisplayName(), wxDefaultPosition, wxSize(500, 400)); } else #endif // wxUSE_MDI_ARCHITECTURE { frame = new wxDocParentFrame(docManager, NULL, wxID_ANY, GetAppDisplayName(), wxDefaultPosition, wxSize(500, 400)); } // and its menu bar wxMenu *menuFile = new wxMenu; menuFile->Append(wxID_NEW); menuFile->Append(wxID_OPEN); if ( m_mode == Mode_Single ) AppendDocumentFileCommands(menuFile, true); menuFile->AppendSeparator(); menuFile->Append(wxID_EXIT); // A nice touch: a history of files visited. Use this menu. docManager->FileHistoryUseMenu(menuFile); #if wxUSE_CONFIG docManager->FileHistoryLoad(*wxConfig::Get()); #endif // wxUSE_CONFIG if ( m_mode == Mode_Single ) { m_canvas = new MyCanvas(NULL, frame); m_menuEdit = CreateDrawingEditMenu(); } CreateMenuBarForFrame(frame, menuFile, m_menuEdit); frame->SetIcon(wxICON(doc)); frame->Centre(); frame->Show(); if ( m_filesFromCmdLine.empty() ) { docManager->CreateNewDocument(); } else // we have files to open on command line { for ( size_t i = 0; i != m_filesFromCmdLine.size(); ++i ) docManager->CreateDocument(m_filesFromCmdLine[i], wxDOC_SILENT); } return true; }
wxFrame *MyApp::CreateChildFrame(wxView *view, bool isCanvas) { // create a child frame of appropriate class for the current mode wxFrame *subframe; wxDocument *doc = view->GetDocument(); #if wxUSE_MDI_ARCHITECTURE if ( GetMode() == Mode_MDI ) { subframe = new wxDocMDIChildFrame ( doc, view, wxStaticCast(GetTopWindow(), wxDocMDIParentFrame), wxID_ANY, "Child Frame", wxDefaultPosition, wxSize(300, 300) ); } else #endif // wxUSE_MDI_ARCHITECTURE { subframe = new wxDocChildFrame ( doc, view, wxStaticCast(GetTopWindow(), wxDocParentFrame), wxID_ANY, "Child Frame", wxDefaultPosition, wxSize(300, 300) ); subframe->Centre(); } wxMenu *menuFile = new wxMenu; menuFile->Append(wxID_NEW); menuFile->Append(wxID_OPEN); AppendDocumentFileCommands(menuFile, isCanvas); menuFile->AppendSeparator(); menuFile->Append(wxID_EXIT); wxMenu *menuEdit; if ( isCanvas ) { menuEdit = CreateDrawingEditMenu(); doc->GetCommandProcessor()->SetEditMenu(menuEdit); doc->GetCommandProcessor()->Initialize(); } else // text frame { menuEdit = new wxMenu; menuEdit->Append(wxID_COPY); menuEdit->Append(wxID_PASTE); menuEdit->Append(wxID_SELECTALL); } CreateMenuBarForFrame(subframe, menuFile, menuEdit); subframe->SetIcon(isCanvas ? wxICON(chrt) : wxICON(notepad)); return subframe; }
bool MyApp::OnInit() { if ( !wxApp::OnInit() ) return false; SetAppName("DocView Sample"); //// Create a document manager wxDocManager *docManager = new wxDocManager; //// Create a template relating drawing documents to their views new wxDocTemplate(docManager, "Drawing", "*.drw", "", "drw", "Drawing Doc", "Drawing View", CLASSINFO(DrawingDocument), CLASSINFO(DrawingView)); #if defined( __WXMAC__ ) && wxOSX_USE_CARBON wxFileName::MacRegisterDefaultTypeAndCreator("drw" , 'WXMB' , 'WXMA'); #endif if ( m_mode == Mode_Single ) { // If we've only got one window, we only get to edit one document at a // time. Therefore no text editing, just doodling. docManager->SetMaxDocsOpen(1); } else // multiple documents mode: allow documents of different types { // Create a template relating text documents to their views new wxDocTemplate(docManager, "Text", "*.txt;*.text", "", "txt;text", "Text Doc", "Text View", CLASSINFO(TextEditDocument), CLASSINFO(TextEditView)); #if defined( __WXMAC__ ) && wxOSX_USE_CARBON wxFileName::MacRegisterDefaultTypeAndCreator("txt" , 'TEXT' , 'WXMA'); #endif } // create the main frame window wxFrame *frame; #if wxUSE_MDI_ARCHITECTURE if ( m_mode == Mode_MDI ) { frame = new wxDocMDIParentFrame(docManager, NULL, wxID_ANY, GetAppDisplayName(), wxDefaultPosition, wxSize(500, 400)); } else #endif // wxUSE_MDI_ARCHITECTURE { frame = new wxDocParentFrame(docManager, NULL, wxID_ANY, GetAppDisplayName(), wxDefaultPosition, wxSize(500, 400)); } // and its menu bar wxMenu *menuFile = new wxMenu; menuFile->Append(wxID_NEW); menuFile->Append(wxID_OPEN); if ( m_mode == Mode_Single ) AppendDocumentFileCommands(menuFile, true); menuFile->AppendSeparator(); menuFile->Append(wxID_EXIT); // A nice touch: a history of files visited. Use this menu. docManager->FileHistoryUseMenu(menuFile); if ( m_mode == Mode_Single ) { m_canvas = new MyCanvas(NULL, frame); m_menuEdit = CreateDrawingEditMenu(); } CreateMenuBarForFrame(frame, menuFile, m_menuEdit); frame->SetIcon(wxICON(doc)); frame->Centre(wxBOTH); frame->Show(true); SetTopWindow(frame); return true; }