OSDN Git Service

793f5920aa8c4b21394b9f0cd58896153ab0ebcc
[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         locale.Init(wxLANGUAGE_DEFAULT);
43         locale.AddCatalogLookupPathPrefix(wxT("."));
44         locale.AddCatalogLookupPathPrefix(wxT("./locale/"));
45         locale.AddCatalog(wxT("ShapeFusion"));
46         
47         // so that we can import every sort of bitmap format
48         wxInitAllImageHandlers();
49                 
50         // Create a document manager
51         m_docManager = new ShapeFusionDocManager;
52
53         // Create a template relating drawing documents to their views
54         (void) new wxDocTemplate(m_docManager, wxT("Shapes"), wxT("*"), wxT(""), wxT(""), wxT("Shapes"), wxT("Shapes"),
55                 CLASSINFO(ShapesDocument), CLASSINFO(ShapesView));
56         (void) new wxDocTemplate(m_docManager, wxT("Sounds"), wxT("*"), wxT(""), wxT(""), wxT("Sounds"), wxT("Sounds"),
57                 CLASSINFO(SoundsDocument), CLASSINFO(SoundsView));
58
59         (void) new wxDocTemplate(m_docManager, wxT("Physics"), wxT("*"), wxT(""), wxT(""), wxT("Physics"), wxT("Physics"), CLASSINFO(PhysicsDocument), CLASSINFO(PhysicsView));
60
61 #ifdef __WXMAC__
62         //TODO: Put correct file extension values here
63 //    wxFileName::MacRegisterDefaultTypeAndCreator( wxT("*") , 'WXMB' , 'WXMA' );
64 //    wxFileName::MacRegisterDefaultTypeAndCreator( wxT("*") , 'WXMB' , 'WXMA' );
65 #endif
66     
67     // Create the main frame window
68 #ifdef __WXMAC__
69         // a hack to make the frame invisible on MacOS, which is more Mac-like
70         // http://www.wxwidgets.org/wiki/index.php/WxMac_Issues#The_Mac_OS_menu_bar
71         frame = new ShapeFusionMain(m_docManager, (wxFrame *)NULL, wxID_ANY, _("ShapeFusion Workspace"), wxPoint(5,5), wxSize(0,0), 0);
72 #else
73     frame = new ShapeFusionMain(m_docManager, (wxFrame *)NULL, wxID_ANY, _("ShapeFusion Workspace"), wxDefaultPosition, wxDefaultSize, wxDEFAULT_FRAME_STYLE);
74 #endif
75
76     // Give it an icon (this is ignored in MDI mode: uses resources)
77 #ifdef __WXMSW__
78     frame->SetIcon(wxIcon(wxT("doc_icn")));
79 #endif
80
81     wxMenuBar *menu_bar = new wxMenuBar;
82
83         CreateFileMenu(menu_bar);
84         CreateEditMenu(menu_bar);
85         CreateHelpMenu(menu_bar);
86     
87         // Associate the menu bar with the frame
88         frame->SetMenuBar(menu_bar);
89
90         //FIXME: This doesn't work
91         //wxMenuItem *menuItem = menu_bar->FindItem(FILE_MENU_HISTORY);
92         //m_docManager->FileHistoryUseMenu(menuItem->GetMenu());
93     
94     frame->Centre(wxBOTH);
95     frame->Show(true);
96     
97     SetTopWindow(frame);
98     return true;
99 }
100
101 int ShapeFusionApp::OnExit(void)
102 {
103     delete m_docManager;
104     return 0;
105 }
106
107 /*
108 * Centralised code for creating a document frame.
109 * Called when a new view is created (after a New/Open event)
110 */
111 wxFrame *ShapeFusionApp::CreateChildFrame(wxDocument *doc, wxView *view, const wxString title, wxPoint point, wxSize size, long style)
112 {
113     // Make a child frame
114     wxDocChildFrame *subframe = new wxDocChildFrame(doc, view, GetMainFrame(), wxID_ANY, title,
115         point, size, style);
116     
117     wxMenuBar *menu_bar = new wxMenuBar;
118     
119         CreateFileMenu(menu_bar);
120     CreateEditMenu(menu_bar);
121         CreateHelpMenu(menu_bar);
122         
123     // Associate the menu bar with the frame
124     subframe->SetMenuBar(menu_bar);
125         
126         //FIXME: This doesn't work
127         //wxMenuItem *menuItem = menu_bar->FindItem(FILE_MENU_HISTORY);
128         //m_docManager->FileHistoryUseMenu(menuItem->GetMenu());
129         
130     subframe->Centre(wxBOTH);
131     
132     return subframe;
133 }
134
135 ShapeFusionMain *GetMainFrame(void)
136 {
137     return frame;
138 }