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