OSDN Git Service

イニシャルコミット。
[marathon/ShapeFusion.git] / ShapeFusionApp.cpp
1 /*
2  * This file is part of ShapeFusion (Copyright 2000 Tito Dal Canton)
3  *
4  * ShapeFusion is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * ShapeFusion is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with ShapeFusion; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
17 */
18
19 #include "ShapeFusionApp.h"
20 #include "ShapeFusionMenus.h"
21 #include "ShapesDocument.h"
22 #include "ShapesView.h"
23 #include "SoundsDocument.h"
24 #include "SoundsView.h"
25 #include "PhysicsDocument.h"
26 #include "PhysicsView.h"
27
28 ShapeFusionMain *frame = (ShapeFusionMain *)NULL;
29
30 IMPLEMENT_APP(ShapeFusionApp)
31
32 ShapeFusionApp::ShapeFusionApp(void)
33 {
34     m_docManager = (ShapeFusionDocManager *)NULL;
35 }
36
37 bool ShapeFusionApp::OnInit(void)
38 {
39         if (!wxApp::OnInit())
40                 return false;
41         
42         // so that we can import every sort of bitmap format
43         wxInitAllImageHandlers();
44                 
45         // Create a document manager
46         m_docManager = new ShapeFusionDocManager;
47
48         // Create a template relating drawing documents to their views
49         (void) new wxDocTemplate(m_docManager, _T("Shapes"), _T("*"), _T(""), _T(""), _T("Shapes"), _T("Shapes"),
50                 CLASSINFO(ShapesDocument), CLASSINFO(ShapesView));
51         (void) new wxDocTemplate(m_docManager, _T("Sounds"), _T("*"), _T(""), _T(""), _T("Sounds"), _T("Sounds"),
52                 CLASSINFO(SoundsDocument), CLASSINFO(SoundsView));
53
54         (void) new wxDocTemplate(m_docManager, _T("Physics"), _T("*"), _T(""), _T(""), _T("Physics"), _T("Physics"), CLASSINFO(PhysicsDocument), CLASSINFO(PhysicsView));
55
56 #ifdef __WXMAC__
57         //TODO: Put correct file extension values here
58 //    wxFileName::MacRegisterDefaultTypeAndCreator( wxT("*") , 'WXMB' , 'WXMA' );
59 //    wxFileName::MacRegisterDefaultTypeAndCreator( wxT("*") , 'WXMB' , 'WXMA' );
60 #endif
61     
62     // Create the main frame window
63 #ifdef __WXMAC__
64         // a hack to make the frame invisible on MacOS, which is more Mac-like
65         // http://www.wxwidgets.org/wiki/index.php/WxMac_Issues#The_Mac_OS_menu_bar
66         frame = new ShapeFusionMain(m_docManager, (wxFrame *)NULL, wxID_ANY, _T("ShapeFusion Workspace"), wxPoint(5,5), wxSize(0,0), 0);
67 #else
68     frame = new ShapeFusionMain(m_docManager, (wxFrame *)NULL, wxID_ANY, _T("ShapeFusion Workspace"), wxDefaultPosition, wxDefaultSize, wxDEFAULT_FRAME_STYLE);
69 #endif
70
71     // Give it an icon (this is ignored in MDI mode: uses resources)
72 #ifdef __WXMSW__
73     frame->SetIcon(wxIcon(_T("doc_icn")));
74 #endif
75
76     wxMenuBar *menu_bar = new wxMenuBar;
77
78         CreateFileMenu(menu_bar);
79         CreateEditMenu(menu_bar);
80         CreateHelpMenu(menu_bar);
81     
82         // Associate the menu bar with the frame
83         frame->SetMenuBar(menu_bar);
84
85         //FIXME: This doesn't work
86         //wxMenuItem *menuItem = menu_bar->FindItem(FILE_MENU_HISTORY);
87         //m_docManager->FileHistoryUseMenu(menuItem->GetMenu());
88     
89     frame->Centre(wxBOTH);
90     frame->Show(true);
91     
92     SetTopWindow(frame);
93     return true;
94 }
95
96 int ShapeFusionApp::OnExit(void)
97 {
98     delete m_docManager;
99     return 0;
100 }
101
102 /*
103 * Centralised code for creating a document frame.
104 * Called when a new view is created (after a New/Open event)
105 */
106 wxFrame *ShapeFusionApp::CreateChildFrame(wxDocument *doc, wxView *view, const wxString title, wxPoint point, wxSize size, long style)
107 {
108     // Make a child frame
109     wxDocChildFrame *subframe = new wxDocChildFrame(doc, view, GetMainFrame(), wxID_ANY, title,
110         point, size, style);
111     
112     wxMenuBar *menu_bar = new wxMenuBar;
113     
114         CreateFileMenu(menu_bar);
115     CreateEditMenu(menu_bar);
116         CreateHelpMenu(menu_bar);
117         
118     // Associate the menu bar with the frame
119     subframe->SetMenuBar(menu_bar);
120         
121         //FIXME: This doesn't work
122         //wxMenuItem *menuItem = menu_bar->FindItem(FILE_MENU_HISTORY);
123         //m_docManager->FileHistoryUseMenu(menuItem->GetMenu());
124         
125     subframe->Centre(wxBOTH);
126     
127     return subframe;
128 }
129
130 ShapeFusionMain *GetMainFrame(void)
131 {
132     return frame;
133 }