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