]> git.saurik.com Git - wxWidgets.git/blob - contrib/samples/ogl/studio/mainfrm.cpp
remove unfinished sample for release
[wxWidgets.git] / contrib / samples / ogl / studio / mainfrm.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: mainfrm.cpp
3 // Purpose: Studio main frame
4 // Author: Julian Smart
5 // Modified by:
6 // Created: 27/7/98
7 // RCS-ID: $Id$
8 // Copyright: (c) Julian Smart
9 // Licence:
10 /////////////////////////////////////////////////////////////////////////////
11
12 // For compilers that support precompilation, includes "wx/wx.h".
13 #include "wx/wxprec.h"
14
15 #ifdef __BORLANDC__
16 #pragma hdrstop
17 #endif
18
19 #ifndef WX_PRECOMP
20 #include "wx/wx.h"
21 #include "wx/mdi.h"
22 #endif
23
24 #include "wx/laywin.h"
25
26 #include "studio.h"
27 #include "view.h"
28 #include "doc.h"
29 #include "cspalette.h"
30 #include "mainfrm.h"
31 #include "dialogs.h"
32
33 BEGIN_EVENT_TABLE(csFrame, wxDocMDIParentFrame)
34 EVT_MENU(ID_CS_ABOUT, csFrame::OnAbout)
35 EVT_MENU(wxID_EXIT, csFrame::OnQuit)
36 EVT_MENU(wxID_HELP, csFrame::OnHelp)
37 EVT_MENU(ID_CS_SETTINGS, csFrame::OnSettings)
38 EVT_SIZE(csFrame::OnSize)
39 EVT_SASH_DRAGGED(ID_LAYOUT_WINDOW_PALETTE, csFrame::OnSashDragPaletteWindow)
40 EVT_SASH_DRAGGED(ID_LAYOUT_WINDOW_PROJECT, csFrame::OnSashDragProjectWindow)
41 EVT_IDLE(csFrame::OnIdle)
42 EVT_UPDATE_UI(wxID_PRINT, csFrame::OnUpdateDisable)
43 EVT_UPDATE_UI(wxID_PREVIEW, csFrame::OnUpdateDisable)
44 EVT_UPDATE_UI(wxID_SAVE, csFrame::OnSaveUpdate)
45 EVT_UPDATE_UI(wxID_SAVEAS, csFrame::OnSaveUpdate)
46 EVT_UPDATE_UI(wxID_UNDO, csFrame::OnUpdateDisable)
47 EVT_UPDATE_UI(wxID_REDO, csFrame::OnUpdateDisable)
48 EVT_UPDATE_UI(wxID_CUT, csFrame::OnUpdateDisable)
49 EVT_UPDATE_UI(wxID_COPY, csFrame::OnUpdateDisable)
50 EVT_UPDATE_UI(wxID_PASTE, csFrame::OnUpdateDisable)
51 EVT_CLOSE(csFrame::OnCloseWindow)
52 END_EVENT_TABLE()
53
54 // Define my frame constructor
55 csFrame::csFrame(wxDocManager* manager, wxFrame *parent, wxWindowID id, const wxString& title, const wxPoint& pos, const wxSize& size, long style):
56 wxDocMDIParentFrame(manager, parent, id, title, pos, size, style, _T("frame"))
57 {
58 CreateToolBar(wxNO_BORDER|wxTB_FLAT|wxTB_HORIZONTAL);
59 wxGetApp().InitToolBar(GetToolBar());
60
61 // Accelerators
62 wxAcceleratorEntry entries[4];
63
64 entries[0].Set(wxACCEL_NORMAL, WXK_F1, wxID_HELP);
65 entries[1].Set(wxACCEL_CTRL, 'O', wxID_OPEN);
66 entries[2].Set(wxACCEL_CTRL, 'N', wxID_NEW);
67 entries[3].Set(wxACCEL_CTRL, 'P', wxID_PRINT);
68
69 wxAcceleratorTable accel(4, entries);
70 SetAcceleratorTable(accel);
71 }
72
73 void csFrame::OnHelp(wxCommandEvent& WXUNUSED(event))
74 {
75 wxHelpControllerBase* help;
76 help = wxGetApp().GetHelpController();
77 if (help)
78 help->DisplayContents();
79 }
80
81 void csFrame::OnSettings(wxCommandEvent& WXUNUSED(event))
82 {
83 csSettingsDialog* dialog = new csSettingsDialog(this);
84 /* int ret = */ dialog->ShowModal();
85 dialog->Destroy();
86 }
87
88 void csFrame::OnQuit(wxCommandEvent& WXUNUSED(event))
89 {
90 Close(true);
91 }
92
93 void csFrame::OnAbout(wxCommandEvent& WXUNUSED(event))
94 {
95 (void)wxMessageBox(_T("OGL Studio\n(c) 1999, Julian Smart"), _T("About OGL Studio"), wxICON_INFORMATION);
96 }
97
98 void csFrame::OnSashDragPaletteWindow(wxSashEvent& event)
99 {
100 if (event.GetDragStatus() == wxSASH_STATUS_OUT_OF_RANGE)
101 return;
102
103 switch (event.GetId())
104 {
105 case ID_LAYOUT_WINDOW_PALETTE:
106 {
107 wxGetApp().GetDiagramPaletteSashWindow()->SetDefaultSize(wxSize(10000, event.GetDragRect().height));
108 break;
109 }
110 }
111 wxLayoutAlgorithm layout;
112 layout.LayoutMDIFrame(this);
113 }
114
115 void csFrame::OnSashDragProjectWindow(wxSashEvent& event)
116 {
117 if (event.GetDragStatus() == wxSASH_STATUS_OUT_OF_RANGE)
118 return;
119
120 switch (event.GetId())
121 {
122 case ID_LAYOUT_WINDOW_PROJECT:
123 {
124 wxGetApp().GetProjectSashWindow()->SetDefaultSize(wxSize(event.GetDragRect().width, 10000));
125 break;
126 }
127 }
128 wxLayoutAlgorithm layout;
129 layout.LayoutMDIFrame(this);
130 }
131
132 // Define the behaviour for the frame closing
133 // - must delete all frames except for the main one.
134 void csFrame::OnCloseWindow(wxCloseEvent& event)
135 {
136 int x, y;
137 GetPosition(& x, & y);
138 wxGetApp().m_mainFramePos = wxPoint(x, y);
139
140 GetSize(& x, & y);
141 wxGetApp().m_mainFrameSize = wxSize(x, y);
142
143 wxDocMDIParentFrame::OnCloseWindow(event);
144 }
145
146 void csFrame::OnSize(wxSizeEvent& event)
147 {
148 wxLayoutAlgorithm layout;
149 layout.LayoutMDIFrame(this);
150 event.Skip();
151 }
152
153 // Make sure the correct toolbars are showing for the active view
154 void csFrame::OnIdle(wxIdleEvent& event)
155 {
156 wxSashLayoutWindow* paletteWin = wxGetApp().GetDiagramPaletteSashWindow();
157 wxSashLayoutWindow* diagramToolBarWin = wxGetApp().GetDiagramToolBarSashWindow();
158 if (!paletteWin || !diagramToolBarWin)
159 return;
160 bool doLayout = false;
161 if (GetActiveChild())
162 {
163 if (!paletteWin->IsShown() || !diagramToolBarWin->IsShown())
164 {
165 paletteWin->Show(true);
166 diagramToolBarWin->Show(true);
167
168 doLayout = true;
169 }
170 }
171 else
172 {
173 if (paletteWin->IsShown() || diagramToolBarWin->IsShown())
174 {
175 paletteWin->Show(false);
176 diagramToolBarWin->Show(false);
177 doLayout = true;
178 }
179 }
180 if (doLayout)
181 {
182 wxLayoutAlgorithm layout;
183 layout.LayoutMDIFrame(this);
184
185 #if defined(__WXMSW__) && defined(__WIN95__)
186 // Need to do something else to get it to refresh properly
187 // when a client frame is first displayed; moving the client
188 // window doesn't cause the proper refresh. Just refreshing the
189 // client doesn't work (presumably because it's clipping the
190 // children).
191 // FIXED in wxWidgets, by intercepting wxMDIClientWindow::DoSetSize
192 // and checking if the position has changed, before redrawing the
193 // child windows.
194 #if 0
195 wxMDIChildFrame* childFrame = GetActiveChild();
196 if (childFrame)
197 {
198 HWND hWnd = (HWND) childFrame->GetHWND();
199 ::RedrawWindow(hWnd, NULL, NULL, RDW_FRAME|RDW_ALLCHILDREN|RDW_INVALIDATE );
200
201 }
202 #endif
203 #endif
204 }
205 event.Skip();
206 }
207
208 // General handler for disabling items
209 void csFrame::OnUpdateDisable(wxUpdateUIEvent& event)
210 {
211 event.Enable(false);
212 }
213
214 void csFrame::OnSaveUpdate(wxUpdateUIEvent& event)
215 {
216 event.Enable( (GetActiveChild() != NULL) );
217 }
218
219 /*
220 * Child frame
221 */
222
223 BEGIN_EVENT_TABLE(csMDIChildFrame, wxDocMDIChildFrame)
224 EVT_ACTIVATE(csMDIChildFrame::OnActivate)
225 END_EVENT_TABLE()
226
227 csMDIChildFrame::csMDIChildFrame(wxDocument* doc, wxView* view, wxMDIParentFrame *parent, wxWindowID id, const wxString& title, const wxPoint& pos, const wxSize& size, long style):
228 wxDocMDIChildFrame(doc, view, parent, id, title, pos, size, style)
229 {
230 // Accelerators
231 wxAcceleratorEntry entries[18];
232
233 // Usual editing functions
234 entries[0].Set(wxACCEL_NORMAL, WXK_DELETE, wxID_CLEAR);
235 entries[1].Set(wxACCEL_CTRL, 'X', wxID_CUT);
236 entries[2].Set(wxACCEL_CTRL, 'C', wxID_COPY);
237 entries[3].Set(wxACCEL_SHIFT, WXK_INSERT, wxID_PASTE);
238 entries[4].Set(wxACCEL_CTRL, 'V', wxID_PASTE);
239 entries[5].Set(wxACCEL_CTRL, 'A', ID_CS_SELECT_ALL);
240
241 // Undo/redo
242 entries[6].Set(wxACCEL_CTRL, 'Z', wxID_UNDO);
243 entries[7].Set(wxACCEL_CTRL, 'Y', wxID_REDO);
244
245 // Other
246 entries[8].Set(wxACCEL_NORMAL, WXK_RETURN, ID_CS_EDIT_PROPERTIES);
247 entries[9].Set(wxACCEL_ALT, WXK_RETURN, ID_CS_EDIT_PROPERTIES);
248 entries[10].Set(wxACCEL_CTRL, 'D', wxID_DUPLICATE);
249 entries[11].Set(wxACCEL_NORMAL, WXK_F1, wxID_HELP);
250
251 // File handling
252 entries[12].Set(wxACCEL_CTRL, 'S', wxID_SAVE);
253 entries[13].Set(wxACCEL_NORMAL, WXK_F12, wxID_SAVEAS);
254 entries[14].Set(wxACCEL_CTRL, 'O', wxID_OPEN);
255 entries[15].Set(wxACCEL_CTRL, 'N', wxID_NEW);
256 entries[16].Set(wxACCEL_CTRL, 'P', wxID_PRINT);
257 entries[17].Set(wxACCEL_CTRL, 'W', wxID_CLOSE);
258
259
260 wxAcceleratorTable accel(18, entries);
261 SetAcceleratorTable(accel);
262 }
263
264 void csMDIChildFrame::OnActivate(wxActivateEvent& event)
265 {
266 wxDocMDIChildFrame::OnActivate(event);
267 /*
268 wxSashLayoutWindow* win = wxGetApp().GetDiagramPaletteSashWindow();
269 if (!win)
270 return;
271
272 win->Show(event.GetActive());
273
274 wxLayoutAlgorithm layout;
275 layout.LayoutMDIFrame((wxMDIParentFrame*) GetParent());
276 */
277 }
278