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