]>
Commit | Line | Data |
---|---|---|
1 | ///////////////////////////////////////////////////////////////////////////// | |
2 | // Name: mainframe.cpp | |
3 | // Purpose: Main frame | |
4 | // Author: Julian Smart | |
5 | // Modified by: | |
6 | // Created: 2002-09-04 | |
7 | // RCS-ID: $Id$ | |
8 | // Copyright: (c) Julian Smart | |
9 | // Licence: | |
10 | ///////////////////////////////////////////////////////////////////////////// | |
11 | ||
12 | #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA) | |
13 | #pragma implementation "mainframe.h" | |
14 | #endif | |
15 | ||
16 | // For compilers that support precompilation, includes "wx/wx.h". | |
17 | #include "wx/wxprec.h" | |
18 | ||
19 | #ifdef __BORLANDC__ | |
20 | #pragma hdrstop | |
21 | #endif | |
22 | ||
23 | #ifndef WX_PRECOMP | |
24 | ||
25 | #include "wx/splitter.h" | |
26 | ||
27 | #endif | |
28 | ||
29 | #include "wx/cshelp.h" | |
30 | #include "wx/html/htmlwin.h" | |
31 | #include "wx/notebook.h" | |
32 | #include "wx/dataobj.h" | |
33 | #include "wx/clipbrd.h" | |
34 | #include "wx/stockitem.h" | |
35 | #include "wxconfigtool.h" | |
36 | #include "mainframe.h" | |
37 | #include "appsettings.h" | |
38 | #include "symbols.h" | |
39 | #include "configtree.h" | |
40 | #include "propeditor.h" | |
41 | #include "configtooldoc.h" | |
42 | #include "configtoolview.h" | |
43 | #include "configbrowser.h" | |
44 | ||
45 | #include "bitmaps/wxconfigtool.xpm" | |
46 | ||
47 | #include "bitmaps/copy.xpm" | |
48 | #include "bitmaps/cut.xpm" | |
49 | #include "bitmaps/paste.xpm" | |
50 | #include "bitmaps/open.xpm" | |
51 | #include "bitmaps/save.xpm" | |
52 | #include "bitmaps/new.xpm" | |
53 | #include "bitmaps/help.xpm" | |
54 | #include "bitmaps/undo.xpm" | |
55 | #include "bitmaps/redo.xpm" | |
56 | #include "bitmaps/helpcs.xpm" | |
57 | #include "bitmaps/go.xpm" | |
58 | ||
59 | IMPLEMENT_CLASS(ctMainFrame, wxDocParentFrame) | |
60 | ||
61 | BEGIN_EVENT_TABLE(ctMainFrame, wxDocParentFrame) | |
62 | EVT_CLOSE(ctMainFrame::OnCloseWindow) | |
63 | EVT_MENU(wxID_ABOUT, ctMainFrame::OnAbout) | |
64 | EVT_MENU(wxID_OPEN, ctMainFrame::OnOpen) | |
65 | EVT_MENU(wxID_NEW, ctMainFrame::OnNew) | |
66 | EVT_MENU(wxID_EXIT, ctMainFrame::OnExit) | |
67 | EVT_MENU(ctID_SETTINGS, ctMainFrame::OnSettings) | |
68 | EVT_MENU(ctID_SHOW_TOOLBAR, ctMainFrame::OnShowToolbar) | |
69 | EVT_MENU(wxID_HELP, ctMainFrame::OnHelp) | |
70 | EVT_MENU(ctID_REFERENCE_CONTENTS, ctMainFrame::OnReferenceHelp) | |
71 | EVT_MENU(wxID_HELP_CONTEXT, ctMainFrame::OnContextHelp) | |
72 | ||
73 | EVT_UPDATE_UI(ctID_ADD_ITEM_CHECKBOX, ctMainFrame::OnUpdateDisable) | |
74 | EVT_UPDATE_UI(ctID_ADD_ITEM_RADIOBUTTON, ctMainFrame::OnUpdateDisable) | |
75 | EVT_UPDATE_UI(ctID_ADD_ITEM_GROUP, ctMainFrame::OnUpdateDisable) | |
76 | EVT_UPDATE_UI(ctID_ADD_ITEM_CHECK_GROUP, ctMainFrame::OnUpdateDisable) | |
77 | EVT_UPDATE_UI(ctID_ADD_ITEM_RADIO_GROUP, ctMainFrame::OnUpdateDisable) | |
78 | EVT_UPDATE_UI(ctID_ADD_ITEM_STRING, ctMainFrame::OnUpdateDisable) | |
79 | EVT_UPDATE_UI(ctID_DELETE_ITEM, ctMainFrame::OnUpdateDisable) | |
80 | EVT_UPDATE_UI(ctID_RENAME_ITEM, ctMainFrame::OnUpdateDisable) | |
81 | EVT_UPDATE_UI(wxID_COPY, ctMainFrame::OnUpdateDisable) | |
82 | EVT_UPDATE_UI(wxID_CUT, ctMainFrame::OnUpdateDisable) | |
83 | EVT_UPDATE_UI(wxID_PASTE, ctMainFrame::OnUpdateDisable) | |
84 | EVT_UPDATE_UI(ctID_ITEM_HELP, ctMainFrame::OnUpdateDisable) | |
85 | ||
86 | EVT_UPDATE_UI(ctID_ADD_CUSTOM_PROPERTY, ctMainFrame::OnUpdateDisable) | |
87 | EVT_UPDATE_UI(ctID_EDIT_CUSTOM_PROPERTY, ctMainFrame::OnUpdateDisable) | |
88 | EVT_UPDATE_UI(ctID_DELETE_CUSTOM_PROPERTY, ctMainFrame::OnUpdateDisable) | |
89 | ||
90 | EVT_UPDATE_UI(ctID_SAVE_SETUP_FILE, ctMainFrame::OnUpdateDisable) | |
91 | EVT_UPDATE_UI(ctID_SAVE_CONFIGURE_COMMAND, ctMainFrame::OnUpdateDisable) | |
92 | ||
93 | EVT_UPDATE_UI(wxID_FIND, ctMainFrame::OnUpdateDisable) | |
94 | ||
95 | EVT_UPDATE_UI(ctID_GO, ctMainFrame::OnUpdateDisable) | |
96 | END_EVENT_TABLE() | |
97 | ||
98 | // Define my frame constructor | |
99 | ctMainFrame::ctMainFrame(wxDocManager *manager, wxFrame *parent, wxWindowID id, const wxString& title, const wxPoint& pos, const wxSize& size, long style): | |
100 | wxDocParentFrame(manager, parent, id, title, pos, size, style) | |
101 | { | |
102 | m_document = NULL; | |
103 | m_editMenu = NULL; | |
104 | m_configurePage = NULL; | |
105 | m_setupPage = NULL; | |
106 | #ifdef USE_CONFIG_BROWSER_PAGE | |
107 | m_configBrowserPage = NULL; | |
108 | #endif | |
109 | m_mainNotebook = NULL; | |
110 | m_findDialog = NULL; | |
111 | ||
112 | m_treeSplitterWindow = new wxSplitterWindow(this, wxID_ANY, wxDefaultPosition, wxSize(400, 300), | |
113 | wxSP_3DSASH|wxSP_3DBORDER|wxNO_FULL_REPAINT_ON_RESIZE|wxCLIP_CHILDREN); | |
114 | ||
115 | m_configTreeCtrl = new ctConfigTreeCtrl(m_treeSplitterWindow, wxID_ANY, wxDefaultPosition, wxDefaultSize, | |
116 | wxTR_HAS_BUTTONS|wxNO_BORDER|wxNO_FULL_REPAINT_ON_RESIZE|wxCLIP_CHILDREN); | |
117 | ||
118 | m_mainNotebook = new wxNotebook(m_treeSplitterWindow, wxID_ANY, wxDefaultPosition, wxSize(300, 300), | |
119 | wxNO_FULL_REPAINT_ON_RESIZE|wxCLIP_CHILDREN); | |
120 | ||
121 | m_propertyEditor = new ctPropertyEditor(m_mainNotebook, wxID_ANY, wxDefaultPosition, wxSize(300, 200), | |
122 | wxNO_BORDER|wxNO_FULL_REPAINT_ON_RESIZE|wxCLIP_CHILDREN); | |
123 | m_setupPage = new ctOutputWindow(m_mainNotebook, wxID_ANY, wxDefaultPosition, wxSize(300, 200), | |
124 | wxNO_BORDER|wxNO_FULL_REPAINT_ON_RESIZE|wxCLIP_CHILDREN); | |
125 | m_configurePage = new ctOutputWindow(m_mainNotebook, wxID_ANY, wxDefaultPosition, wxSize(300, 200), | |
126 | wxNO_BORDER|wxNO_FULL_REPAINT_ON_RESIZE|wxCLIP_CHILDREN); | |
127 | ||
128 | #ifdef USE_CONFIG_BROWSER_PAGE | |
129 | m_configBrowserPage = new ctConfigurationBrowserWindow(m_mainNotebook, wxID_ANY, wxDefaultPosition, wxSize(300, 200), | |
130 | wxNO_BORDER|wxNO_FULL_REPAINT_ON_RESIZE|wxCLIP_CHILDREN); | |
131 | #endif | |
132 | ||
133 | m_mainNotebook->AddPage(m_propertyEditor, _T("Properties")); | |
134 | #ifdef USE_CONFIG_BROWSER_PAGE | |
135 | m_mainNotebook->AddPage(m_configBrowserPage, _T("Configuration Browser")); | |
136 | #endif | |
137 | m_mainNotebook->AddPage(m_setupPage, _T("setup.h")); | |
138 | m_mainNotebook->AddPage(m_configurePage, _T("configure")); | |
139 | ||
140 | // Need to do this afterwards since wxWin sets the XP background | |
141 | // in AddPage | |
142 | m_propertyEditor->GetDescriptionWindow()->SetBackgroundColour(ctDESCRIPTION_BACKGROUND_COLOUR); | |
143 | ||
144 | int sashPos = wxGetApp().GetSettings().m_mainSashSize; | |
145 | m_treeSplitterWindow->SplitVertically(m_configTreeCtrl, m_mainNotebook, sashPos); | |
146 | ||
147 | SetIcon(wxIcon(wxconfigtool_xpm)); | |
148 | ||
149 | #if wxUSE_STATUSBAR | |
150 | CreateStatusBar(2); | |
151 | #endif // wxUSE_STATUSBAR | |
152 | ||
153 | wxMenuBar* menuBar = CreateMenuBar(); | |
154 | SetMenuBar(menuBar); | |
155 | ||
156 | CreateToolBar(wxNO_BORDER|wxTB_FLAT|wxTB_HORIZONTAL|wxNO_FULL_REPAINT_ON_RESIZE|wxCLIP_CHILDREN); | |
157 | InitToolBar(GetToolBar()); | |
158 | ||
159 | if (wxGetApp().GetSettings().m_showToolBar) | |
160 | { | |
161 | menuBar->Check(ctID_SHOW_TOOLBAR, true); | |
162 | } | |
163 | else | |
164 | { | |
165 | menuBar->Check(ctID_SHOW_TOOLBAR, false); | |
166 | GetToolBar()->Show(false); | |
167 | ResizeFrame(); | |
168 | } | |
169 | } | |
170 | ||
171 | void ctMainFrame::OnCloseWindow(wxCloseEvent& event) | |
172 | { | |
173 | if (GetDocument()) | |
174 | { | |
175 | if (!GetDocument()->DeleteAllViews() && event.CanVeto()) | |
176 | { | |
177 | event.Veto(); | |
178 | return; | |
179 | } | |
180 | } | |
181 | ||
182 | if (m_findDialog) | |
183 | { | |
184 | m_findDialog->Destroy(); | |
185 | m_findDialog = NULL; | |
186 | } | |
187 | ||
188 | Show(false); | |
189 | ||
190 | if (IsMaximized()) | |
191 | wxGetApp().GetSettings().m_frameStatus = ctSHOW_STATUS_MAXIMIZED ; | |
192 | else if (IsIconized()) | |
193 | wxGetApp().GetSettings().m_frameStatus = ctSHOW_STATUS_MINIMIZED ; | |
194 | else | |
195 | wxGetApp().GetSettings().m_frameStatus = ctSHOW_STATUS_NORMAL ; | |
196 | ||
197 | // Must delete this now since the DLL loading library will be | |
198 | // uninitialised by the time the app object is deleted | |
199 | wxGetApp().ClearHelpControllers(); | |
200 | ||
201 | if (!IsMaximized() && !IsIconized()) | |
202 | { | |
203 | wxGetApp().GetSettings().m_frameSize = GetRect(); | |
204 | wxGetApp().GetSettings().m_mainSashSize = m_treeSplitterWindow->GetSashPosition(); | |
205 | } | |
206 | ||
207 | Destroy(); | |
208 | } | |
209 | ||
210 | void ctMainFrame::OnAbout(wxCommandEvent& WXUNUSED(event)) | |
211 | { | |
212 | wxString msg = wxGetApp().GetSettings().GetAppName() + wxT(" (c) Julian Smart"); | |
213 | wxString caption = wxT("About ") + wxGetApp().GetSettings().GetAppName(); | |
214 | wxMessageBox(msg, caption, wxOK|wxICON_INFORMATION); | |
215 | } | |
216 | ||
217 | void ctMainFrame::OnOpen(wxCommandEvent& event) | |
218 | { | |
219 | wxGetApp().GetDocManager()->OnFileOpen(event); | |
220 | } | |
221 | ||
222 | void ctMainFrame::OnNew(wxCommandEvent& event) | |
223 | { | |
224 | wxGetApp().GetDocManager()->OnFileNew(event); | |
225 | } | |
226 | ||
227 | void ctMainFrame::OnExit(wxCommandEvent& WXUNUSED(event)) | |
228 | { | |
229 | Close(); | |
230 | } | |
231 | ||
232 | void ctMainFrame::OnSettings(wxCommandEvent& WXUNUSED(event)) | |
233 | { | |
234 | wxGetApp().GetSettings().ShowSettingsDialog(); | |
235 | } | |
236 | ||
237 | void ctMainFrame::InitToolBar(wxToolBar* toolBar) | |
238 | { | |
239 | toolBar->SetHelpText(wxT("The toolbar gives you easy access to commonly used commands.")); | |
240 | ||
241 | // Set up toolbar | |
242 | wxBitmap toolBarBitmaps[20]; | |
243 | ||
244 | toolBarBitmaps[0] = wxBitmap(new_xpm); | |
245 | toolBarBitmaps[1] = wxBitmap(open_xpm); | |
246 | toolBarBitmaps[2] = wxBitmap(save_xpm); | |
247 | toolBarBitmaps[3] = wxBitmap(copy_xpm); | |
248 | toolBarBitmaps[4] = wxBitmap(cut_xpm); | |
249 | toolBarBitmaps[5] = wxBitmap(paste_xpm); | |
250 | toolBarBitmaps[6] = wxBitmap(go_xpm); | |
251 | toolBarBitmaps[7] = wxBitmap(help_xpm); | |
252 | toolBarBitmaps[10] = wxBitmap(undo_xpm); | |
253 | toolBarBitmaps[11] = wxBitmap(redo_xpm); | |
254 | toolBarBitmaps[12] = wxBitmap(help_xpm); | |
255 | toolBarBitmaps[13] = wxBitmap(helpcs_xpm); | |
256 | ||
257 | toolBar->AddTool(wxID_NEW, toolBarBitmaps[0], wxNullBitmap, false, wxDefaultCoord, wxDefaultCoord, (wxObject *) NULL, wxT("New project")); | |
258 | toolBar->AddTool(wxID_OPEN, toolBarBitmaps[1], wxNullBitmap, false, wxDefaultCoord, wxDefaultCoord, (wxObject *) NULL, wxT("Open project")); | |
259 | toolBar->AddTool(wxID_SAVE, toolBarBitmaps[2], wxNullBitmap, false, wxDefaultCoord, wxDefaultCoord, (wxObject *) NULL, wxT("Save project")); | |
260 | ||
261 | toolBar->AddSeparator(); | |
262 | toolBar->AddTool(wxID_CUT, toolBarBitmaps[4], wxNullBitmap, false, wxDefaultCoord, wxDefaultCoord, (wxObject *) NULL, wxGetStockLabel(wxID_CUT, false)); | |
263 | toolBar->AddTool(wxID_COPY, toolBarBitmaps[3], wxNullBitmap, false, wxDefaultCoord, wxDefaultCoord, (wxObject *) NULL, wxGetStockLabel(wxID_COPY, false)); | |
264 | toolBar->AddTool(wxID_PASTE, toolBarBitmaps[5], wxNullBitmap, false, wxDefaultCoord, wxDefaultCoord, (wxObject *) NULL, wxGetStockLabel(wxID_PASTE, false)); | |
265 | toolBar->AddSeparator(); | |
266 | toolBar->AddTool(wxID_UNDO, toolBarBitmaps[10], wxNullBitmap, false, wxDefaultCoord, wxDefaultCoord, (wxObject *) NULL, wxGetStockLabel(wxID_UNDO, false)); | |
267 | toolBar->AddTool(wxID_REDO, toolBarBitmaps[11], wxNullBitmap, false, wxDefaultCoord, wxDefaultCoord, (wxObject *) NULL, wxGetStockLabel(wxID_REDO, false)); | |
268 | toolBar->AddSeparator(); | |
269 | toolBar->AddTool(ctID_GO, toolBarBitmaps[6], wxNullBitmap, false, wxDefaultCoord, wxDefaultCoord, (wxObject *) NULL, wxT("Save setup.h or configurewx.sh")); | |
270 | toolBar->AddSeparator(); | |
271 | toolBar->AddTool(ctID_ITEM_HELP, toolBarBitmaps[12], wxNullBitmap, false, wxDefaultCoord, wxDefaultCoord, (wxObject *) NULL, wxT("Show help for this option")); | |
272 | toolBar->AddTool(wxID_HELP_CONTEXT, toolBarBitmaps[13], wxNullBitmap, false, wxDefaultCoord, wxDefaultCoord, (wxObject *) NULL, wxT("Show help on the clicked item")); | |
273 | ||
274 | // after adding the buttons to the toolbar, must call Realize() to reflect | |
275 | // the changes | |
276 | toolBar->Realize(); | |
277 | } | |
278 | ||
279 | wxMenuBar* ctMainFrame::CreateMenuBar() | |
280 | { | |
281 | // Make a menubar | |
282 | wxMenu *fileMenu = new wxMenu; | |
283 | ||
284 | wxGetApp().GetFileHistory().UseMenu(fileMenu); | |
285 | ||
286 | fileMenu->Append(wxID_NEW, wxGetStockLabel(wxID_NEW, true, wxT("Ctrl+N")), wxT("Create a new settings document")); | |
287 | fileMenu->Append(wxID_OPEN, wxGetStockLabel(wxID_OPEN, true, wxT("Ctrl+O")), wxT("Open a settings document")); | |
288 | fileMenu->Append(wxID_CLOSE, wxGetStockLabel(wxID_CLOSE, true, wxT("Ctrl+W")), wxT("Close the current settings document")); | |
289 | fileMenu->AppendSeparator(); | |
290 | fileMenu->Append(wxID_SAVE, wxGetStockLabel(wxID_SAVE, true, wxT("Ctrl+S")), wxT("Save the settings document")); | |
291 | fileMenu->Append(wxID_SAVEAS, wxGetStockLabel(wxID_SAVEAS), wxT("Save the settings document under a new filename")); | |
292 | fileMenu->AppendSeparator(); | |
293 | fileMenu->Append(ctID_SAVE_SETUP_FILE, wxT("Save Setup.&h...\tCtrl+H"), wxT("Save the setup.h file")); | |
294 | fileMenu->Append(ctID_SAVE_CONFIGURE_COMMAND, wxT("Save Configure Script...\tCtrl+G"), wxT("Save the configure script file")); | |
295 | fileMenu->AppendSeparator(); | |
296 | fileMenu->Append(ctID_GO, wxT("&Go\tF5"), wxT("Quick-save the setup.h or configure.sh file")); | |
297 | fileMenu->AppendSeparator(); | |
298 | fileMenu->Append(wxID_EXIT, wxGetStockLabel(wxID_EXIT, true, wxT("Alt+F4")), wxT("Exit the application")); | |
299 | ||
300 | wxGetApp().GetDocManager()->FileHistoryUseMenu(fileMenu); | |
301 | ||
302 | wxMenu *editMenu = new wxMenu; | |
303 | ||
304 | editMenu->Append(wxID_UNDO, wxGetStockLabel(wxID_UNDO, true, wxT("Ctrl+Z"))); | |
305 | editMenu->Append(wxID_REDO, wxGetStockLabel(wxID_REDO, true, wxT("Ctrl+Y"))); | |
306 | editMenu->AppendSeparator(); | |
307 | editMenu->Append(wxID_COPY, wxGetStockLabel(wxID_CLOSE, true, wxT("Ctrl+C"))); | |
308 | editMenu->Append(wxID_CUT, wxGetStockLabel(wxID_CUT, true, wxT("Ctrl+X"))); | |
309 | editMenu->Append(wxID_PASTE, wxGetStockLabel(wxID_PASTE, true, wxT("Ctrl+V"))); | |
310 | editMenu->AppendSeparator(); | |
311 | ||
312 | wxMenu* itemMenu = new wxMenu; | |
313 | itemMenu->Append(ctID_ADD_ITEM_CHECKBOX, _("Add &Checkbox Option"), _("Add a checkbox configuration option")); | |
314 | itemMenu->Append(ctID_ADD_ITEM_RADIOBUTTON, _("Add &Radio Button Option"), _("Add a radio button configuration option")); | |
315 | // TODO. However we can also simply use custom properties; | |
316 | // but then the C++ code has to be special-cased. | |
317 | // itemMenu->Append(ctID_ADD_ITEM_STRING, _("Add &String Option"), _("Add a string configuration option")); | |
318 | itemMenu->Append(ctID_ADD_ITEM_GROUP, _("Add &Group Option"), _("Add a group configuration option")); | |
319 | itemMenu->Append(ctID_ADD_ITEM_CHECK_GROUP, _("Add Chec&k Group Option"), _("Add a check group configuration option")); | |
320 | itemMenu->Append(ctID_ADD_ITEM_RADIO_GROUP, _("Add Rad&io Group Option"), _("Add a radio group configuration option")); | |
321 | ||
322 | editMenu->Append(ctID_ADD_ITEM, wxT("Add &Option"), itemMenu, _("Add a configuration option")); | |
323 | editMenu->AppendSeparator(); | |
324 | ||
325 | wxMenu* propertyMenu = new wxMenu; | |
326 | propertyMenu->Append(ctID_ADD_CUSTOM_PROPERTY, _("&Add Custom Property"), _("Adds a custom property to the current option")); | |
327 | propertyMenu->Append(ctID_EDIT_CUSTOM_PROPERTY, _("&Edit Custom Property"), _("Edits the currently selected custom property")); | |
328 | propertyMenu->Append(ctID_DELETE_CUSTOM_PROPERTY, _("&Delete Custom Property"), _("Deletes the currently selected custom property")); | |
329 | editMenu->Append(ctID_CUSTOM_PROPERTY, _("Custom P&roperty"), propertyMenu, _("Custom property commands")); | |
330 | ||
331 | editMenu->AppendSeparator(); | |
332 | editMenu->Append(ctID_DELETE_ITEM, _("&Delete Option"), _("Delete a configuration option")); | |
333 | editMenu->Append(ctID_RENAME_ITEM, _("&Rename Option"), _("Rename a configuration option")); | |
334 | editMenu->AppendSeparator(); | |
335 | editMenu->Append(wxID_FIND, wxGetStockLabel(wxID_FIND, true, wxT("Ctrl+F")), _("Search for a string in the settings document")); | |
336 | ||
337 | // Save for the command processor. | |
338 | m_editMenu = editMenu; | |
339 | ||
340 | wxMenu *viewMenu = new wxMenu; | |
341 | viewMenu->Append(ctID_SHOW_TOOLBAR, wxT("Show &Toolbar"), wxT("Toggle the toolbar on and off"), | |
342 | wxITEM_CHECK); | |
343 | viewMenu->Append(ctID_SETTINGS, wxT("&Settings...\tCtrl+T"), wxT("Show application settings")); | |
344 | ||
345 | wxMenu *helpMenu = new wxMenu; | |
346 | helpMenu->Append(wxID_HELP, wxT("&Help Contents"), wxT("Show Configuration Tool help")); | |
347 | helpMenu->Append(ctID_REFERENCE_CONTENTS, wxT("&wxWidgets Help Contents"), wxT("Show wxWidgets reference")); | |
348 | helpMenu->AppendSeparator(); | |
349 | helpMenu->Append(ctID_ITEM_HELP, wxT("&Configuration Option Help\tF1"), wxT("Show help for the selected option")); | |
350 | helpMenu->Append(wxID_HELP_CONTEXT, wxT("&What's this?"), wxT("Show help on the clicked item")); | |
351 | helpMenu->AppendSeparator(); | |
352 | helpMenu->Append(wxID_ABOUT, wxT("&About..."), wxT("Show details about this application")); | |
353 | ||
354 | wxMenuBar *menuBar = new wxMenuBar; | |
355 | ||
356 | menuBar->Append(fileMenu, wxT("&File")); | |
357 | menuBar->Append(editMenu, wxT("&Edit")); | |
358 | menuBar->Append(viewMenu, wxT("&View")); | |
359 | menuBar->Append(helpMenu, wxT("&Help")); | |
360 | ||
361 | { | |
362 | wxConfig config(wxGetApp().GetSettings().GetAppName(), wxT("wxWidgets")); | |
363 | config.SetPath(wxT("FileHistory/")); | |
364 | wxGetApp().GetDocManager()->FileHistoryLoad(config); | |
365 | } | |
366 | ||
367 | return menuBar; | |
368 | } | |
369 | ||
370 | /// Handles the Show Toolbar menu event. | |
371 | void ctMainFrame::OnShowToolbar(wxCommandEvent& WXUNUSED(event)) | |
372 | { | |
373 | wxGetApp().GetSettings().m_showToolBar = !wxGetApp().GetSettings().m_showToolBar; | |
374 | GetToolBar()->Show(wxGetApp().GetSettings().m_showToolBar); | |
375 | ResizeFrame(); | |
376 | } | |
377 | ||
378 | /// Handles the Help Contents menu event. | |
379 | void ctMainFrame::OnHelp(wxCommandEvent& WXUNUSED(event)) | |
380 | { | |
381 | wxGetApp().GetHelpController().DisplayContents(); | |
382 | } | |
383 | ||
384 | /// Handles context help | |
385 | void ctMainFrame::OnContextHelp(wxCommandEvent& WXUNUSED(event)) | |
386 | { | |
387 | wxContextHelp contextHelp; | |
388 | } | |
389 | ||
390 | /// Handles the Help Contents menu event for the reference manual. | |
391 | void ctMainFrame::OnReferenceHelp(wxCommandEvent& WXUNUSED(event)) | |
392 | { | |
393 | wxGetApp().GetReferenceHelpController().DisplayContents(); | |
394 | } | |
395 | ||
396 | /// Resizes the main frame according to the | |
397 | /// state of the toolbar | |
398 | void ctMainFrame::ResizeFrame() | |
399 | { | |
400 | PositionToolBar(); | |
401 | wxSizeEvent event(GetSize(), GetId()); | |
402 | this->ProcessEvent(event); | |
403 | } | |
404 | ||
405 | /// Update the frame title. | |
406 | void ctMainFrame::UpdateFrameTitle() | |
407 | { | |
408 | // TODO | |
409 | } | |
410 | ||
411 | // General disabler | |
412 | void ctMainFrame::OnUpdateDisable(wxUpdateUIEvent& event) | |
413 | { | |
414 | event.Enable( false ); | |
415 | } | |
416 | ||
417 | /*! | |
418 | * ctOutputWindow represents a page showing a setup.h file or config command. | |
419 | */ | |
420 | ||
421 | IMPLEMENT_CLASS(ctOutputWindow, wxPanel) | |
422 | ||
423 | BEGIN_EVENT_TABLE(ctOutputWindow, wxPanel) | |
424 | EVT_BUTTON(wxID_COPY, ctOutputWindow::OnCopyToClipboard) | |
425 | EVT_BUTTON(wxID_SAVE, ctOutputWindow::OnSaveText) | |
426 | EVT_BUTTON(ctID_REGENERATE, ctOutputWindow::OnRegenerate) | |
427 | EVT_UPDATE_UI(wxID_SAVE, ctOutputWindow::OnUpdateSaveText) | |
428 | EVT_UPDATE_UI(ctID_REGENERATE, ctOutputWindow::OnUpdateRegenerate) | |
429 | EVT_UPDATE_UI(wxID_COPY, ctOutputWindow::OnUpdateCopy) | |
430 | END_EVENT_TABLE() | |
431 | ||
432 | ctOutputWindow::ctOutputWindow(wxWindow* parent, wxWindowID id, | |
433 | const wxPoint& pos, const wxSize& size, long style): | |
434 | wxPanel(parent, id, pos, size, style) | |
435 | { | |
436 | m_codeCtrl = NULL; | |
437 | m_filenameCtrl = NULL; | |
438 | m_doc = NULL; | |
439 | CreateWindows(); | |
440 | } | |
441 | ||
442 | /// Initialise the windows. | |
443 | void ctOutputWindow::CreateWindows() | |
444 | { | |
445 | wxBoxSizer *item0 = new wxBoxSizer( wxVERTICAL ); | |
446 | ||
447 | wxBoxSizer *item2 = new wxBoxSizer( wxHORIZONTAL ); | |
448 | item0->Add( item2, 0, wxGROW|wxALIGN_CENTER_VERTICAL, 5 ); | |
449 | ||
450 | wxButton *item4 = new wxButton( this, wxID_COPY, _("&Copy"), wxDefaultPosition, wxDefaultSize, 0 ); | |
451 | item2->Add( item4, 0, wxGROW|wxALIGN_CENTER_VERTICAL|wxLEFT|wxTOP|wxBOTTOM|wxRIGHT, 5 ); | |
452 | item4->SetHelpText(_("Copies the selection or whole file to the clipboard.")); | |
453 | ||
454 | wxButton *item5 = new wxButton( this, ctID_REGENERATE, _("Re&generate"), wxDefaultPosition, wxDefaultSize, 0 ); | |
455 | item2->Add( item5, 0, wxGROW|wxALIGN_CENTER_VERTICAL|wxTOP|wxBOTTOM|wxRIGHT, 5 ); | |
456 | item5->SetHelpText(_("Regenerates the code.")); | |
457 | ||
458 | #if 0 | |
459 | m_filenameCtrl = new wxTextCtrl(this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxSUNKEN_BORDER|wxTE_READONLY); | |
460 | item2->Add( m_filenameCtrl, 1, wxGROW|wxALIGN_CENTER_VERTICAL|wxTOP|wxBOTTOM|wxRIGHT, 5 ); | |
461 | m_filenameCtrl->SetHelpText(_("Shows the filename where the code is being saved.")); | |
462 | #else | |
463 | m_filenameCtrl = NULL; | |
464 | #endif | |
465 | ||
466 | // The code editor | |
467 | m_codeCtrl = new wxTextCtrl(this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxSize(100, 100), wxTE_RICH|wxTE_MULTILINE|wxSUNKEN_BORDER); | |
468 | item0->Add( m_codeCtrl, 1, wxGROW|wxALIGN_CENTER_VERTICAL|wxLEFT|wxRIGHT|wxBOTTOM, 5 ); | |
469 | ||
470 | SetAutoLayout( true ); | |
471 | SetSizer( item0 ); | |
472 | } | |
473 | ||
474 | /// Copies the text to the clipboard. | |
475 | void ctOutputWindow::OnCopyToClipboard(wxCommandEvent& WXUNUSED(event)) | |
476 | { | |
477 | // Try to copy the selection first | |
478 | long int selFrom, selTo; | |
479 | m_codeCtrl->GetSelection(& selFrom, & selTo); | |
480 | if (selFrom != selTo) | |
481 | { | |
482 | m_codeCtrl->Copy(); | |
483 | return; | |
484 | } | |
485 | ||
486 | // Copy the whole amount | |
487 | if (!wxTheClipboard->Open()) | |
488 | { | |
489 | wxMessageBox(_("Sorry, could not open the clipboard."), _("Clipboard problem"), wxICON_EXCLAMATION|wxOK); | |
490 | return; | |
491 | } | |
492 | ||
493 | wxString value(m_codeCtrl->GetValue()); | |
494 | #ifdef __WXMSW__ | |
495 | value.Replace(_T("\n"), _T("\r\n")); | |
496 | #endif | |
497 | wxTextDataObject *data = new wxTextDataObject( value ); | |
498 | ||
499 | if (!wxTheClipboard->SetData( data )) | |
500 | { | |
501 | wxTheClipboard->Close(); | |
502 | wxMessageBox(_("Sorry, could not copy to the clipboard."), _("Clipboard problem"), wxICON_EXCLAMATION|wxOK); | |
503 | } | |
504 | else | |
505 | { | |
506 | wxTheClipboard->Close(); | |
507 | } | |
508 | } | |
509 | ||
510 | /// Sets the code in the text control. | |
511 | void ctOutputWindow::SetText(const wxString& text) | |
512 | { | |
513 | if (m_codeCtrl) | |
514 | m_codeCtrl->SetValue(text); | |
515 | } | |
516 | ||
517 | /// Sets the filename. | |
518 | void ctOutputWindow::SetFilename(const wxString& filename) | |
519 | { | |
520 | if (m_filenameCtrl) | |
521 | m_filenameCtrl->SetValue(filename); | |
522 | } | |
523 | ||
524 | /// Saves the file. | |
525 | void ctOutputWindow::OnSaveText(wxCommandEvent& WXUNUSED(event)) | |
526 | { | |
527 | if (m_codeCtrl->IsModified()) | |
528 | { | |
529 | wxString filename(m_filenameCtrl->GetValue()); | |
530 | if (!filename.empty()) | |
531 | { | |
532 | m_codeCtrl->SaveFile(filename); | |
533 | m_codeCtrl->DiscardEdits(); | |
534 | } | |
535 | } | |
536 | } | |
537 | ||
538 | void ctOutputWindow::OnUpdateSaveText(wxUpdateUIEvent& event) | |
539 | { | |
540 | event.Enable(m_doc && m_codeCtrl && m_codeCtrl->IsModified()); | |
541 | } | |
542 | ||
543 | void ctOutputWindow::OnRegenerate(wxCommandEvent& WXUNUSED(event)) | |
544 | { | |
545 | if (m_doc) | |
546 | { | |
547 | ctConfigToolView* view = (ctConfigToolView*) m_doc->GetFirstView(); | |
548 | view->RegenerateSetup(); | |
549 | } | |
550 | } | |
551 | ||
552 | void ctOutputWindow::OnUpdateRegenerate(wxUpdateUIEvent& event) | |
553 | { | |
554 | event.Enable( m_doc != NULL ); | |
555 | } | |
556 | ||
557 | void ctOutputWindow::OnUpdateCopy(wxUpdateUIEvent& event) | |
558 | { | |
559 | event.Enable( m_doc != NULL ); | |
560 | } |