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