]> git.saurik.com Git - wxWidgets.git/blob - utils/ogl/samples/studio/mainfrm.cpp
77c1751ac339454a6529e265e41d959b456b202d
[wxWidgets.git] / utils / ogl / samples / 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,
56 long style):
57 wxDocMDIParentFrame(manager, parent, id, title, pos, size, style, "frame")
58 {
59 CreateToolBar(wxNO_BORDER|wxTB_FLAT|wxTB_HORIZONTAL);
60 wxGetApp().InitToolBar(GetToolBar());
61
62 // Accelerators
63 wxAcceleratorEntry entries[4];
64
65 entries[0].Set(wxACCEL_NORMAL, WXK_F1, wxID_HELP);
66 entries[1].Set(wxACCEL_CTRL, 'O', wxID_OPEN);
67 entries[2].Set(wxACCEL_CTRL, 'N', wxID_NEW);
68 entries[3].Set(wxACCEL_CTRL, 'P', wxID_PRINT);
69
70 wxAcceleratorTable accel(4, entries);
71 SetAcceleratorTable(accel);
72 }
73
74 void csFrame::OnHelp(wxCommandEvent& event)
75 {
76 wxGetApp().GetHelpController().DisplayContents();
77 }
78
79 void csFrame::OnSettings(wxCommandEvent& event)
80 {
81 csSettingsDialog* dialog = new csSettingsDialog(this);
82 int ret = dialog->ShowModal();
83 dialog->Destroy();
84 }
85
86 void csFrame::OnQuit(wxCommandEvent& event)
87 {
88 Close(TRUE);
89 }
90
91 void csFrame::OnAbout(wxCommandEvent& event)
92 {
93 (void)wxMessageBox("OGL Studio\n(c) 1999, Julian Smart", "About OGL Studio", wxICON_INFORMATION);
94 }
95
96 void csFrame::OnSashDragPaletteWindow(wxSashEvent& event)
97 {
98 if (event.GetDragStatus() == wxSASH_STATUS_OUT_OF_RANGE)
99 return;
100
101 switch (event.GetId())
102 {
103 case ID_LAYOUT_WINDOW_PALETTE:
104 {
105 wxGetApp().GetDiagramPaletteSashWindow()->SetDefaultSize(wxSize(10000, event.GetDragRect().height));
106 break;
107 }
108 }
109 wxLayoutAlgorithm layout;
110 layout.LayoutMDIFrame(this);
111 }
112
113 void csFrame::OnSashDragProjectWindow(wxSashEvent& event)
114 {
115 if (event.GetDragStatus() == wxSASH_STATUS_OUT_OF_RANGE)
116 return;
117
118 switch (event.GetId())
119 {
120 case ID_LAYOUT_WINDOW_PROJECT:
121 {
122 wxGetApp().GetProjectSashWindow()->SetDefaultSize(wxSize(event.GetDragRect().width, 10000));
123 break;
124 }
125 }
126 wxLayoutAlgorithm layout;
127 layout.LayoutMDIFrame(this);
128 }
129
130 // Define the behaviour for the frame closing
131 // - must delete all frames except for the main one.
132 void csFrame::OnCloseWindow(wxCloseEvent& event)
133 {
134 int x, y;
135 GetPosition(& x, & y);
136 wxGetApp().m_mainFramePos = wxPoint(x, y);
137
138 GetSize(& x, & y);
139 wxGetApp().m_mainFrameSize = wxSize(x, y);
140
141 wxDocMDIParentFrame::OnCloseWindow(event);
142 }
143
144 void csFrame::OnSize(wxSizeEvent& event)
145 {
146 wxLayoutAlgorithm layout;
147 layout.LayoutMDIFrame(this);
148 }
149
150 // Make sure the correct toolbars are showing for the active view
151 void csFrame::OnIdle(wxIdleEvent& event)
152 {
153 wxDocMDIParentFrame::OnIdle(event);
154
155 wxSashLayoutWindow* paletteWin = wxGetApp().GetDiagramPaletteSashWindow();
156 wxSashLayoutWindow* diagramToolBarWin = wxGetApp().GetDiagramToolBarSashWindow();
157 if (!paletteWin || !diagramToolBarWin)
158 return;
159 bool doLayout = FALSE;
160 if (GetActiveChild())
161 {
162 if (!paletteWin->IsShown() || !diagramToolBarWin->IsShown())
163 {
164 paletteWin->Show(TRUE);
165 diagramToolBarWin->Show(TRUE);
166
167 doLayout = TRUE;
168 }
169 }
170 else
171 {
172 if (paletteWin->IsShown() || diagramToolBarWin->IsShown())
173 {
174 paletteWin->Show(FALSE);
175 diagramToolBarWin->Show(FALSE);
176 doLayout = TRUE;
177 }
178 }
179 if (doLayout)
180 {
181 wxLayoutAlgorithm layout;
182 layout.LayoutMDIFrame(this);
183
184 #if defined(__WXMSW__) && defined(__WIN95__)
185 // Need to do something else to get it to refresh properly
186 // when a client frame is first displayed; moving the client
187 // window doesn't cause the proper refresh. Just refreshing the
188 // client doesn't work (presumably because it's clipping the
189 // children).
190 // TODO: how to put this fix in wxWindows, and not the app.
191 // How about at least having a wxWindow::RedrawWindow?
192 wxMDIChildFrame* childFrame = GetActiveChild();
193 if (childFrame)
194 {
195 HWND hWnd = (HWND) childFrame->GetHWND();
196 ::RedrawWindow(hWnd, NULL, NULL, RDW_FRAME|RDW_ALLCHILDREN|RDW_INVALIDATE );
197
198 }
199 #endif
200 }
201 }
202
203 // General handler for disabling items
204 void csFrame::OnUpdateDisable(wxUpdateUIEvent& event)
205 {
206 event.Enable(FALSE);
207 }
208
209 void csFrame::OnSaveUpdate(wxUpdateUIEvent& event)
210 {
211 event.Enable( (GetActiveChild() != NULL) );
212 }
213
214 /*
215 * Child frame
216 */
217
218 BEGIN_EVENT_TABLE(csMDIChildFrame, wxDocMDIChildFrame)
219 EVT_ACTIVATE(csMDIChildFrame::OnActivate)
220 END_EVENT_TABLE()
221
222 csMDIChildFrame::csMDIChildFrame(wxDocument* doc, wxView* view, wxMDIParentFrame *parent, wxWindowID id, const wxString& title, const wxPoint& pos, const wxSize& size, long style):
223 wxDocMDIChildFrame(doc, view, parent, id, title, pos, size, style)
224 {
225 // Accelerators
226 wxAcceleratorEntry entries[18];
227
228 // Usual editing functions
229 entries[0].Set(wxACCEL_NORMAL, WXK_DELETE, wxID_CLEAR);
230 entries[1].Set(wxACCEL_CTRL, 'X', wxID_CUT);
231 entries[2].Set(wxACCEL_CTRL, 'C', wxID_COPY);
232 entries[3].Set(wxACCEL_SHIFT, WXK_INSERT, wxID_PASTE);
233 entries[4].Set(wxACCEL_CTRL, 'V', wxID_PASTE);
234 entries[5].Set(wxACCEL_CTRL, 'A', ID_CS_SELECT_ALL);
235
236 // Undo/redo
237 entries[6].Set(wxACCEL_CTRL, 'Z', wxID_UNDO);
238 entries[7].Set(wxACCEL_CTRL, 'Y', wxID_REDO);
239
240 // Other
241 entries[8].Set(wxACCEL_NORMAL, WXK_RETURN, ID_CS_EDIT_PROPERTIES);
242 entries[9].Set(wxACCEL_ALT, WXK_RETURN, ID_CS_EDIT_PROPERTIES);
243 entries[10].Set(wxACCEL_CTRL, 'D', wxID_DUPLICATE);
244 entries[11].Set(wxACCEL_NORMAL, WXK_F1, wxID_HELP);
245
246 // File handling
247 entries[12].Set(wxACCEL_CTRL, 'S', wxID_SAVE);
248 entries[13].Set(wxACCEL_NORMAL, WXK_F12, wxID_SAVEAS);
249 entries[14].Set(wxACCEL_CTRL, 'O', wxID_OPEN);
250 entries[15].Set(wxACCEL_CTRL, 'N', wxID_NEW);
251 entries[16].Set(wxACCEL_CTRL, 'P', wxID_PRINT);
252 entries[17].Set(wxACCEL_CTRL, 'W', wxID_CLOSE);
253
254
255 wxAcceleratorTable accel(18, entries);
256 SetAcceleratorTable(accel);
257 }
258
259 void csMDIChildFrame::OnActivate(wxActivateEvent& event)
260 {
261 wxDocMDIChildFrame::OnActivate(event);
262 /*
263 wxSashLayoutWindow* win = wxGetApp().GetDiagramPaletteSashWindow();
264 if (!win)
265 return;
266
267 win->Show(event.GetActive());
268
269 wxLayoutAlgorithm layout;
270 layout.LayoutMDIFrame((wxMDIParentFrame*) GetParent());
271 */
272 }
273