]> git.saurik.com Git - wxWidgets.git/blame - utils/configtool/src/mainframe.cpp
Updated version to 2.5.5
[wxWidgets.git] / utils / configtool / src / mainframe.cpp
CommitLineData
d7463f75
JS
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
71ada1a5 12#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
f8105809
JS
13#pragma implementation "mainframe.h"
14#endif
15
d9ab621e
WS
16// For compilers that support precompilation, includes "wx/wx.h".
17#include "wx/wxprec.h"
d7463f75
JS
18
19#ifdef __BORLANDC__
20#pragma hdrstop
21#endif
22
d9ab621e
WS
23#ifndef WX_PRECOMP
24
25#include "wx/splitter.h"
26
27#endif
28
29#include "wx/cshelp.h"
d7463f75
JS
30#include "wx/html/htmlwin.h"
31#include "wx/notebook.h"
917ad696 32#include "wx/dataobj.h"
d9ab621e 33#include "wx/clipbrd.h"
677ded95 34#include "wx/stockitem.h"
d7463f75
JS
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"
61775320 43#include "configbrowser.h"
d7463f75
JS
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"
d7463f75
JS
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"
afc51590 57#include "bitmaps/go.xpm"
d7463f75
JS
58
59IMPLEMENT_CLASS(ctMainFrame, wxDocParentFrame)
60
61BEGIN_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)
e7767867
JS
92
93 EVT_UPDATE_UI(wxID_FIND, ctMainFrame::OnUpdateDisable)
afc51590
JS
94
95 EVT_UPDATE_UI(ctID_GO, ctMainFrame::OnUpdateDisable)
d7463f75
JS
96END_EVENT_TABLE()
97
98// Define my frame constructor
4fe30bce 99ctMainFrame::ctMainFrame(wxDocManager *manager, wxFrame *parent, wxWindowID id, const wxString& title, const wxPoint& pos, const wxSize& size, long style):
d7463f75
JS
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;
79830320 106#ifdef USE_CONFIG_BROWSER_PAGE
61775320 107 m_configBrowserPage = NULL;
79830320 108#endif
d7463f75 109 m_mainNotebook = NULL;
e7767867 110 m_findDialog = NULL;
d7463f75 111
4fe30bce 112 m_treeSplitterWindow = new wxSplitterWindow(this, wxID_ANY, wxDefaultPosition, wxSize(400, 300),
61775320 113 wxSP_3DSASH|wxSP_3DBORDER|wxNO_FULL_REPAINT_ON_RESIZE|wxCLIP_CHILDREN);
d7463f75 114
4fe30bce 115 m_configTreeCtrl = new ctConfigTreeCtrl(m_treeSplitterWindow, wxID_ANY, wxDefaultPosition, wxDefaultSize,
61775320 116 wxTR_HAS_BUTTONS|wxNO_BORDER|wxNO_FULL_REPAINT_ON_RESIZE|wxCLIP_CHILDREN);
d7463f75 117
4fe30bce 118 m_mainNotebook = new wxNotebook(m_treeSplitterWindow, wxID_ANY, wxDefaultPosition, wxSize(300, 300),
61775320 119 wxNO_FULL_REPAINT_ON_RESIZE|wxCLIP_CHILDREN);
d7463f75 120
4fe30bce 121 m_propertyEditor = new ctPropertyEditor(m_mainNotebook, wxID_ANY, wxDefaultPosition, wxSize(300, 200),
61775320 122 wxNO_BORDER|wxNO_FULL_REPAINT_ON_RESIZE|wxCLIP_CHILDREN);
4fe30bce 123 m_setupPage = new ctOutputWindow(m_mainNotebook, wxID_ANY, wxDefaultPosition, wxSize(300, 200),
61775320 124 wxNO_BORDER|wxNO_FULL_REPAINT_ON_RESIZE|wxCLIP_CHILDREN);
4fe30bce 125 m_configurePage = new ctOutputWindow(m_mainNotebook, wxID_ANY, wxDefaultPosition, wxSize(300, 200),
61775320
JS
126 wxNO_BORDER|wxNO_FULL_REPAINT_ON_RESIZE|wxCLIP_CHILDREN);
127
79830320 128#ifdef USE_CONFIG_BROWSER_PAGE
4fe30bce 129 m_configBrowserPage = new ctConfigurationBrowserWindow(m_mainNotebook, wxID_ANY, wxDefaultPosition, wxSize(300, 200),
61775320
JS
130 wxNO_BORDER|wxNO_FULL_REPAINT_ON_RESIZE|wxCLIP_CHILDREN);
131#endif
132
d7463f75 133 m_mainNotebook->AddPage(m_propertyEditor, _T("Properties"));
79830320 134#ifdef USE_CONFIG_BROWSER_PAGE
61775320
JS
135 m_mainNotebook->AddPage(m_configBrowserPage, _T("Configuration Browser"));
136#endif
d7463f75
JS
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
d96cdd4a 149#if wxUSE_STATUSBAR
d7463f75 150 CreateStatusBar(2);
d96cdd4a 151#endif // wxUSE_STATUSBAR
d7463f75
JS
152
153 wxMenuBar* menuBar = CreateMenuBar();
154 SetMenuBar(menuBar);
155
61775320 156 CreateToolBar(wxNO_BORDER|wxTB_FLAT|wxTB_HORIZONTAL|wxNO_FULL_REPAINT_ON_RESIZE|wxCLIP_CHILDREN);
d7463f75
JS
157 InitToolBar(GetToolBar());
158
159 if (wxGetApp().GetSettings().m_showToolBar)
160 {
4fe30bce 161 menuBar->Check(ctID_SHOW_TOOLBAR, true);
d7463f75
JS
162 }
163 else
164 {
4fe30bce
WS
165 menuBar->Check(ctID_SHOW_TOOLBAR, false);
166 GetToolBar()->Show(false);
d7463f75
JS
167 ResizeFrame();
168 }
169}
170
171void ctMainFrame::OnCloseWindow(wxCloseEvent& event)
172{
173 if (GetDocument())
174 {
175 if (!GetDocument()->DeleteAllViews() && event.CanVeto())
176 {
177 event.Veto();
178 return;
179 }
180 }
181
e7767867
JS
182 if (m_findDialog)
183 {
184 m_findDialog->Destroy();
185 m_findDialog = NULL;
186 }
187
4fe30bce 188 Show(false);
d7463f75
JS
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 ;
254a2129 196
d7463f75
JS
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();
254a2129 200
d7463f75
JS
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
69da0d99 210void ctMainFrame::OnAbout(wxCommandEvent& WXUNUSED(event))
d7463f75
JS
211{
212 wxString msg = wxGetApp().GetSettings().GetAppName() + wxT(" (c) Julian Smart");
213 wxString caption = wxT("About ") + wxGetApp().GetSettings().GetAppName();
eac703e9 214 wxMessageBox(msg, caption, wxOK|wxICON_INFORMATION);
d7463f75
JS
215}
216
217void ctMainFrame::OnOpen(wxCommandEvent& event)
218{
219 wxGetApp().GetDocManager()->OnFileOpen(event);
220}
221
222void ctMainFrame::OnNew(wxCommandEvent& event)
223{
224 wxGetApp().GetDocManager()->OnFileNew(event);
225}
226
69da0d99 227void ctMainFrame::OnExit(wxCommandEvent& WXUNUSED(event))
d7463f75
JS
228{
229 Close();
230}
231
69da0d99 232void ctMainFrame::OnSettings(wxCommandEvent& WXUNUSED(event))
d7463f75
JS
233{
234 wxGetApp().GetSettings().ShowSettingsDialog();
235}
236
237void 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);
afc51590 250 toolBarBitmaps[6] = wxBitmap(go_xpm);
d7463f75
JS
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
422d0ff0
WS
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"));
d7463f75
JS
260
261 toolBar->AddSeparator();
677ded95
WS
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));
d7463f75 265 toolBar->AddSeparator();
677ded95
WS
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));
d7463f75 268 toolBar->AddSeparator();
422d0ff0 269 toolBar->AddTool(ctID_GO, toolBarBitmaps[6], wxNullBitmap, false, wxDefaultCoord, wxDefaultCoord, (wxObject *) NULL, wxT("Save setup.h or configurewx.sh"));
afc51590 270 toolBar->AddSeparator();
422d0ff0
WS
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"));
d7463f75
JS
273
274 // after adding the buttons to the toolbar, must call Realize() to reflect
275 // the changes
276 toolBar->Realize();
277}
278
279wxMenuBar* ctMainFrame::CreateMenuBar()
280{
281 // Make a menubar
282 wxMenu *fileMenu = new wxMenu;
254a2129 283
d7463f75 284 wxGetApp().GetFileHistory().UseMenu(fileMenu);
254a2129 285
677ded95
WS
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"));
d7463f75 289 fileMenu->AppendSeparator();
677ded95
WS
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"));
d7463f75
JS
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();
afc51590
JS
296 fileMenu->Append(ctID_GO, wxT("&Go\tF5"), wxT("Quick-save the setup.h or configure.sh file"));
297 fileMenu->AppendSeparator();
677ded95 298 fileMenu->Append(wxID_EXIT, wxGetStockLabel(wxID_EXIT, true, wxT("Alt+F4")), wxT("Exit the application"));
d7463f75
JS
299
300 wxGetApp().GetDocManager()->FileHistoryUseMenu(fileMenu);
254a2129 301
d7463f75
JS
302 wxMenu *editMenu = new wxMenu;
303
677ded95
WS
304 editMenu->Append(wxID_UNDO, wxGetStockLabel(wxID_UNDO, true, wxT("Ctrl+Z")));
305 editMenu->Append(wxID_REDO, wxGetStockLabel(wxID_REDO, true, wxT("Ctrl+Y")));
d7463f75 306 editMenu->AppendSeparator();
677ded95
WS
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")));
d7463f75
JS
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"));
e7767867 334 editMenu->AppendSeparator();
677ded95 335 editMenu->Append(wxID_FIND, wxGetStockLabel(wxID_FIND, true, wxT("Ctrl+F")), _("Search for a string in the settings document"));
d7463f75
JS
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"));
be5a51fb 347 helpMenu->Append(ctID_REFERENCE_CONTENTS, wxT("&wxWidgets Help Contents"), wxT("Show wxWidgets reference"));
d7463f75
JS
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"));
254a2129 353
d7463f75 354 wxMenuBar *menuBar = new wxMenuBar;
254a2129 355
d7463f75
JS
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 {
be5a51fb 362 wxConfig config(wxGetApp().GetSettings().GetAppName(), wxT("wxWidgets"));
d7463f75
JS
363 config.SetPath(wxT("FileHistory/"));
364 wxGetApp().GetDocManager()->FileHistoryLoad(config);
254a2129 365 }
d7463f75
JS
366
367 return menuBar;
368}
369
370/// Handles the Show Toolbar menu event.
69da0d99 371void ctMainFrame::OnShowToolbar(wxCommandEvent& WXUNUSED(event))
d7463f75
JS
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.
69da0d99 379void ctMainFrame::OnHelp(wxCommandEvent& WXUNUSED(event))
d7463f75
JS
380{
381 wxGetApp().GetHelpController().DisplayContents();
382}
383
384/// Handles context help
69da0d99 385void ctMainFrame::OnContextHelp(wxCommandEvent& WXUNUSED(event))
d7463f75
JS
386{
387 wxContextHelp contextHelp;
388}
389
390/// Handles the Help Contents menu event for the reference manual.
69da0d99 391void ctMainFrame::OnReferenceHelp(wxCommandEvent& WXUNUSED(event))
d7463f75
JS
392{
393 wxGetApp().GetReferenceHelpController().DisplayContents();
394}
395
396/// Resizes the main frame according to the
397/// state of the toolbar
398void ctMainFrame::ResizeFrame()
399{
400 PositionToolBar();
401 wxSizeEvent event(GetSize(), GetId());
402 this->ProcessEvent(event);
403}
404
405/// Update the frame title.
406void ctMainFrame::UpdateFrameTitle()
407{
408 // TODO
409}
410
411// General disabler
412void ctMainFrame::OnUpdateDisable(wxUpdateUIEvent& event)
413{
4fe30bce 414 event.Enable( false );
d7463f75
JS
415}
416
417/*!
418 * ctOutputWindow represents a page showing a setup.h file or config command.
419 */
420
421IMPLEMENT_CLASS(ctOutputWindow, wxPanel)
422
423BEGIN_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)
430END_EVENT_TABLE()
431
432ctOutputWindow::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
d7463f75
JS
442/// Initialise the windows.
443void 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
4fe30bce 459 m_filenameCtrl = new wxTextCtrl(this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxSUNKEN_BORDER|wxTE_READONLY);
d7463f75
JS
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
4fe30bce 467 m_codeCtrl = new wxTextCtrl(this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxSize(100, 100), wxTE_RICH|wxTE_MULTILINE|wxSUNKEN_BORDER);
d7463f75
JS
468 item0->Add( m_codeCtrl, 1, wxGROW|wxALIGN_CENTER_VERTICAL|wxLEFT|wxRIGHT|wxBOTTOM, 5 );
469
4fe30bce 470 SetAutoLayout( true );
d7463f75
JS
471 SetSizer( item0 );
472}
473
474/// Copies the text to the clipboard.
69da0d99 475void ctOutputWindow::OnCopyToClipboard(wxCommandEvent& WXUNUSED(event))
d7463f75
JS
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 }
254a2129 492
d7463f75
JS
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 );
254a2129 498
d7463f75
JS
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.
511void ctOutputWindow::SetText(const wxString& text)
512{
513 if (m_codeCtrl)
514 m_codeCtrl->SetValue(text);
515}
516
517/// Sets the filename.
518void ctOutputWindow::SetFilename(const wxString& filename)
519{
520 if (m_filenameCtrl)
521 m_filenameCtrl->SetValue(filename);
522}
523
524/// Saves the file.
69da0d99 525void ctOutputWindow::OnSaveText(wxCommandEvent& WXUNUSED(event))
d7463f75
JS
526{
527 if (m_codeCtrl->IsModified())
528 {
529 wxString filename(m_filenameCtrl->GetValue());
677ded95 530 if (!filename.empty())
d7463f75
JS
531 {
532 m_codeCtrl->SaveFile(filename);
533 m_codeCtrl->DiscardEdits();
534 }
535 }
536}
537
538void ctOutputWindow::OnUpdateSaveText(wxUpdateUIEvent& event)
539{
540 event.Enable(m_doc && m_codeCtrl && m_codeCtrl->IsModified());
541}
542
69da0d99 543void ctOutputWindow::OnRegenerate(wxCommandEvent& WXUNUSED(event))
d7463f75
JS
544{
545 if (m_doc)
546 {
547 ctConfigToolView* view = (ctConfigToolView*) m_doc->GetFirstView();
548 view->RegenerateSetup();
549 }
550}
551
552void ctOutputWindow::OnUpdateRegenerate(wxUpdateUIEvent& event)
553{
554 event.Enable( m_doc != NULL );
555}
556
557void ctOutputWindow::OnUpdateCopy(wxUpdateUIEvent& event)
558{
559 event.Enable( m_doc != NULL );
560}