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