1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: Studio main frame
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart
10 /////////////////////////////////////////////////////////////////////////////
12 // For compilers that support precompilation, includes "wx/wx.h".
13 #include "wx/wxprec.h"
24 #include "wx/laywin.h"
29 #include "cspalette.h"
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
)
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"))
58 CreateToolBar(wxNO_BORDER
|wxTB_FLAT
|wxTB_HORIZONTAL
);
59 wxGetApp().InitToolBar(GetToolBar());
62 wxAcceleratorEntry entries
[4];
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
);
69 wxAcceleratorTable
accel(4, entries
);
70 SetAcceleratorTable(accel
);
73 void csFrame::OnHelp(wxCommandEvent
& WXUNUSED(event
))
75 wxHelpControllerBase
* help
;
76 help
= wxGetApp().GetHelpController();
78 help
->DisplayContents();
81 void csFrame::OnSettings(wxCommandEvent
& WXUNUSED(event
))
83 #if wxUSE_WX_RESOURCES
84 csSettingsDialog
* dialog
= new csSettingsDialog(this);
85 /* int ret = */ dialog
->ShowModal();
87 #endif // wxUSE_WX_RESOURCES
90 void csFrame::OnQuit(wxCommandEvent
& WXUNUSED(event
))
95 void csFrame::OnAbout(wxCommandEvent
& WXUNUSED(event
))
97 (void)wxMessageBox(_T("OGL Studio\n(c) 1999, Julian Smart"), _T("About OGL Studio"), wxICON_INFORMATION
);
100 void csFrame::OnSashDragPaletteWindow(wxSashEvent
& event
)
102 if (event
.GetDragStatus() == wxSASH_STATUS_OUT_OF_RANGE
)
105 switch (event
.GetId())
107 case ID_LAYOUT_WINDOW_PALETTE
:
109 wxGetApp().GetDiagramPaletteSashWindow()->SetDefaultSize(wxSize(10000, event
.GetDragRect().height
));
113 wxLayoutAlgorithm layout
;
114 layout
.LayoutMDIFrame(this);
117 void csFrame::OnSashDragProjectWindow(wxSashEvent
& event
)
119 if (event
.GetDragStatus() == wxSASH_STATUS_OUT_OF_RANGE
)
122 switch (event
.GetId())
124 case ID_LAYOUT_WINDOW_PROJECT
:
126 wxGetApp().GetProjectSashWindow()->SetDefaultSize(wxSize(event
.GetDragRect().width
, 10000));
130 wxLayoutAlgorithm layout
;
131 layout
.LayoutMDIFrame(this);
134 // Define the behaviour for the frame closing
135 // - must delete all frames except for the main one.
136 void csFrame::OnCloseWindow(wxCloseEvent
& event
)
139 GetPosition(& x
, & y
);
140 wxGetApp().m_mainFramePos
= wxPoint(x
, y
);
143 wxGetApp().m_mainFrameSize
= wxSize(x
, y
);
145 wxDocMDIParentFrame::OnCloseWindow(event
);
148 void csFrame::OnSize(wxSizeEvent
& event
)
150 wxLayoutAlgorithm layout
;
151 layout
.LayoutMDIFrame(this);
155 // Make sure the correct toolbars are showing for the active view
156 void csFrame::OnIdle(wxIdleEvent
& event
)
158 wxSashLayoutWindow
* paletteWin
= wxGetApp().GetDiagramPaletteSashWindow();
159 wxSashLayoutWindow
* diagramToolBarWin
= wxGetApp().GetDiagramToolBarSashWindow();
160 if (!paletteWin
|| !diagramToolBarWin
)
162 bool doLayout
= false;
163 if (GetActiveChild())
165 if (!paletteWin
->IsShown() || !diagramToolBarWin
->IsShown())
167 paletteWin
->Show(true);
168 diagramToolBarWin
->Show(true);
175 if (paletteWin
->IsShown() || diagramToolBarWin
->IsShown())
177 paletteWin
->Show(false);
178 diagramToolBarWin
->Show(false);
184 wxLayoutAlgorithm layout
;
185 layout
.LayoutMDIFrame(this);
187 #if defined(__WXMSW__) && defined(__WIN95__)
188 // Need to do something else to get it to refresh properly
189 // when a client frame is first displayed; moving the client
190 // window doesn't cause the proper refresh. Just refreshing the
191 // client doesn't work (presumably because it's clipping the
193 // FIXED in wxWidgets, by intercepting wxMDIClientWindow::DoSetSize
194 // and checking if the position has changed, before redrawing the
197 wxMDIChildFrame
* childFrame
= GetActiveChild();
200 HWND hWnd
= (HWND
) childFrame
->GetHWND();
201 ::RedrawWindow(hWnd
, NULL
, NULL
, RDW_FRAME
|RDW_ALLCHILDREN
|RDW_INVALIDATE
);
210 // General handler for disabling items
211 void csFrame::OnUpdateDisable(wxUpdateUIEvent
& event
)
216 void csFrame::OnSaveUpdate(wxUpdateUIEvent
& event
)
218 event
.Enable( (GetActiveChild() != NULL
) );
225 BEGIN_EVENT_TABLE(csMDIChildFrame
, wxDocMDIChildFrame
)
226 EVT_ACTIVATE(csMDIChildFrame::OnActivate
)
229 csMDIChildFrame::csMDIChildFrame(wxDocument
* doc
, wxView
* view
, wxMDIParentFrame
*parent
, wxWindowID id
, const wxString
& title
, const wxPoint
& pos
, const wxSize
& size
, long style
):
230 wxDocMDIChildFrame(doc
, view
, parent
, id
, title
, pos
, size
, style
)
233 wxAcceleratorEntry entries
[18];
235 // Usual editing functions
236 entries
[0].Set(wxACCEL_NORMAL
, WXK_DELETE
, wxID_CLEAR
);
237 entries
[1].Set(wxACCEL_CTRL
, 'X', wxID_CUT
);
238 entries
[2].Set(wxACCEL_CTRL
, 'C', wxID_COPY
);
239 entries
[3].Set(wxACCEL_SHIFT
, WXK_INSERT
, wxID_PASTE
);
240 entries
[4].Set(wxACCEL_CTRL
, 'V', wxID_PASTE
);
241 entries
[5].Set(wxACCEL_CTRL
, 'A', ID_CS_SELECT_ALL
);
244 entries
[6].Set(wxACCEL_CTRL
, 'Z', wxID_UNDO
);
245 entries
[7].Set(wxACCEL_CTRL
, 'Y', wxID_REDO
);
248 entries
[8].Set(wxACCEL_NORMAL
, WXK_RETURN
, ID_CS_EDIT_PROPERTIES
);
249 entries
[9].Set(wxACCEL_ALT
, WXK_RETURN
, ID_CS_EDIT_PROPERTIES
);
250 entries
[10].Set(wxACCEL_CTRL
, 'D', wxID_DUPLICATE
);
251 entries
[11].Set(wxACCEL_NORMAL
, WXK_F1
, wxID_HELP
);
254 entries
[12].Set(wxACCEL_CTRL
, 'S', wxID_SAVE
);
255 entries
[13].Set(wxACCEL_NORMAL
, WXK_F12
, wxID_SAVEAS
);
256 entries
[14].Set(wxACCEL_CTRL
, 'O', wxID_OPEN
);
257 entries
[15].Set(wxACCEL_CTRL
, 'N', wxID_NEW
);
258 entries
[16].Set(wxACCEL_CTRL
, 'P', wxID_PRINT
);
259 entries
[17].Set(wxACCEL_CTRL
, 'W', wxID_CLOSE
);
262 wxAcceleratorTable
accel(18, entries
);
263 SetAcceleratorTable(accel
);
266 void csMDIChildFrame::OnActivate(wxActivateEvent
& event
)
268 wxDocMDIChildFrame::OnActivate(event
);
270 wxSashLayoutWindow* win = wxGetApp().GetDiagramPaletteSashWindow();
274 win->Show(event.GetActive());
276 wxLayoutAlgorithm layout;
277 layout.LayoutMDIFrame((wxMDIParentFrame*) GetParent());