]> git.saurik.com Git - wxWidgets.git/blob - utils/configtool/src/mainframe.cpp
Regenerate Makefile.in, configure and the VC++ project files after adding rcdefs.h
[wxWidgets.git] / utils / configtool / src / mainframe.cpp
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
12 // For compilers that support precompilation, includes "wx/wx.h".
13 #include "wx/wxprec.h"
14
15 #ifdef __BORLANDC__
16 #pragma hdrstop
17 #endif
18
19 #ifndef WX_PRECOMP
20
21 #include "wx/splitter.h"
22
23 #endif
24
25 #include "wx/cshelp.h"
26 #include "wx/html/htmlwin.h"
27 #include "wx/notebook.h"
28 #include "wx/dataobj.h"
29 #include "wx/clipbrd.h"
30 #include "wx/stockitem.h"
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"
39 #include "configbrowser.h"
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"
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"
53 #include "bitmaps/go.xpm"
54
55 IMPLEMENT_CLASS(ctMainFrame, wxDocParentFrame)
56
57 BEGIN_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)
88
89 EVT_UPDATE_UI(wxID_FIND, ctMainFrame::OnUpdateDisable)
90
91 EVT_UPDATE_UI(ctID_GO, ctMainFrame::OnUpdateDisable)
92 END_EVENT_TABLE()
93
94 // Define my frame constructor
95 ctMainFrame::ctMainFrame(wxDocManager *manager, wxFrame *parent, wxWindowID id, const wxString& title, const wxPoint& pos, const wxSize& size, long style):
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;
102 #ifdef USE_CONFIG_BROWSER_PAGE
103 m_configBrowserPage = NULL;
104 #endif
105 m_mainNotebook = NULL;
106 m_findDialog = NULL;
107
108 m_treeSplitterWindow = new wxSplitterWindow(this, wxID_ANY, wxDefaultPosition, wxSize(400, 300),
109 wxSP_3DSASH|wxSP_3DBORDER|wxNO_FULL_REPAINT_ON_RESIZE|wxCLIP_CHILDREN|wxSP_NO_XP_THEME);
110
111 m_configTreeCtrl = new ctConfigTreeCtrl(m_treeSplitterWindow, wxID_ANY, wxDefaultPosition, wxDefaultSize,
112 wxTR_HAS_BUTTONS|wxNO_BORDER|wxNO_FULL_REPAINT_ON_RESIZE|wxCLIP_CHILDREN);
113
114 m_mainNotebook = new wxNotebook(m_treeSplitterWindow, wxID_ANY, wxDefaultPosition, wxSize(300, 300),
115 wxNO_FULL_REPAINT_ON_RESIZE|wxCLIP_CHILDREN);
116
117 m_propertyEditor = new ctPropertyEditor(m_mainNotebook, wxID_ANY, wxDefaultPosition, wxSize(300, 200),
118 wxNO_BORDER|wxNO_FULL_REPAINT_ON_RESIZE|wxCLIP_CHILDREN);
119 m_setupPage = new ctOutputWindow(m_mainNotebook, wxID_ANY, wxDefaultPosition, wxSize(300, 200),
120 wxNO_BORDER|wxNO_FULL_REPAINT_ON_RESIZE|wxCLIP_CHILDREN);
121 m_configurePage = new ctOutputWindow(m_mainNotebook, wxID_ANY, wxDefaultPosition, wxSize(300, 200),
122 wxNO_BORDER|wxNO_FULL_REPAINT_ON_RESIZE|wxCLIP_CHILDREN);
123
124 #ifdef USE_CONFIG_BROWSER_PAGE
125 m_configBrowserPage = new ctConfigurationBrowserWindow(m_mainNotebook, wxID_ANY, wxDefaultPosition, wxSize(300, 200),
126 wxNO_BORDER|wxNO_FULL_REPAINT_ON_RESIZE|wxCLIP_CHILDREN);
127 #endif
128
129 m_mainNotebook->AddPage(m_propertyEditor, _T("Properties"));
130 #ifdef USE_CONFIG_BROWSER_PAGE
131 m_mainNotebook->AddPage(m_configBrowserPage, _T("Configuration Browser"));
132 #endif
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
145 #if wxUSE_STATUSBAR
146 CreateStatusBar(2);
147 #endif // wxUSE_STATUSBAR
148
149 wxMenuBar* menuBar = CreateMenuBar();
150 SetMenuBar(menuBar);
151
152 CreateToolBar(wxNO_BORDER|wxTB_FLAT|wxTB_HORIZONTAL|wxNO_FULL_REPAINT_ON_RESIZE|wxCLIP_CHILDREN);
153 InitToolBar(GetToolBar());
154
155 if (wxGetApp().GetSettings().m_showToolBar)
156 {
157 menuBar->Check(ctID_SHOW_TOOLBAR, true);
158 }
159 else
160 {
161 menuBar->Check(ctID_SHOW_TOOLBAR, false);
162 GetToolBar()->Show(false);
163 ResizeFrame();
164 }
165 }
166
167 void ctMainFrame::OnCloseWindow(wxCloseEvent& event)
168 {
169 if (GetDocument())
170 {
171 if (!GetDocument()->DeleteAllViews() && event.CanVeto())
172 {
173 event.Veto();
174 return;
175 }
176 }
177
178 if (m_findDialog)
179 {
180 m_findDialog->Destroy();
181 m_findDialog = NULL;
182 }
183
184 Show(false);
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 ;
192
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();
196
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
206 void ctMainFrame::OnAbout(wxCommandEvent& WXUNUSED(event))
207 {
208 wxString msg = wxGetApp().GetSettings().GetAppName() + wxT(" (c) Julian Smart");
209 wxString caption = wxT("About ") + wxGetApp().GetSettings().GetAppName();
210 wxMessageBox(msg, caption, wxOK|wxICON_INFORMATION);
211 }
212
213 void ctMainFrame::OnOpen(wxCommandEvent& event)
214 {
215 wxGetApp().GetDocManager()->OnFileOpen(event);
216 }
217
218 void ctMainFrame::OnNew(wxCommandEvent& event)
219 {
220 wxGetApp().GetDocManager()->OnFileNew(event);
221 }
222
223 void ctMainFrame::OnExit(wxCommandEvent& WXUNUSED(event))
224 {
225 Close();
226 }
227
228 void ctMainFrame::OnSettings(wxCommandEvent& WXUNUSED(event))
229 {
230 wxGetApp().GetSettings().ShowSettingsDialog();
231 }
232
233 void 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);
246 toolBarBitmaps[6] = wxBitmap(go_xpm);
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
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"));
256
257 toolBar->AddSeparator();
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));
261 toolBar->AddSeparator();
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));
264 toolBar->AddSeparator();
265 toolBar->AddTool(ctID_GO, toolBarBitmaps[6], wxNullBitmap, false, wxDefaultCoord, wxDefaultCoord, (wxObject *) NULL, wxT("Save setup.h or configurewx.sh"));
266 toolBar->AddSeparator();
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"));
269
270 // after adding the buttons to the toolbar, must call Realize() to reflect
271 // the changes
272 toolBar->Realize();
273 }
274
275 wxMenuBar* ctMainFrame::CreateMenuBar()
276 {
277 // Make a menubar
278 wxMenu *fileMenu = new wxMenu;
279
280 wxGetApp().GetFileHistory().UseMenu(fileMenu);
281
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"));
285 fileMenu->AppendSeparator();
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"));
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();
292 fileMenu->Append(ctID_GO, wxT("&Go\tF5"), wxT("Quick-save the setup.h or configure.sh file"));
293 fileMenu->AppendSeparator();
294 fileMenu->Append(wxID_EXIT, wxGetStockLabel(wxID_EXIT, true, wxT("Alt+F4")), wxT("Exit the application"));
295
296 wxGetApp().GetDocManager()->FileHistoryUseMenu(fileMenu);
297
298 wxMenu *editMenu = new wxMenu;
299
300 editMenu->Append(wxID_UNDO, wxGetStockLabel(wxID_UNDO, true, wxT("Ctrl+Z")));
301 editMenu->Append(wxID_REDO, wxGetStockLabel(wxID_REDO, true, wxT("Ctrl+Y")));
302 editMenu->AppendSeparator();
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")));
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"));
330 editMenu->AppendSeparator();
331 editMenu->Append(wxID_FIND, wxGetStockLabel(wxID_FIND, true, wxT("Ctrl+F")), _("Search for a string in the settings document"));
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"));
343 helpMenu->Append(ctID_REFERENCE_CONTENTS, wxT("&wxWidgets Help Contents"), wxT("Show wxWidgets reference"));
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"));
349
350 wxMenuBar *menuBar = new wxMenuBar;
351
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 {
358 wxConfig config(wxGetApp().GetSettings().GetAppName(), wxT("wxWidgets"));
359 config.SetPath(wxT("FileHistory/"));
360 wxGetApp().GetDocManager()->FileHistoryLoad(config);
361 }
362
363 return menuBar;
364 }
365
366 /// Handles the Show Toolbar menu event.
367 void ctMainFrame::OnShowToolbar(wxCommandEvent& WXUNUSED(event))
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.
375 void ctMainFrame::OnHelp(wxCommandEvent& WXUNUSED(event))
376 {
377 wxGetApp().GetHelpController().DisplayContents();
378 }
379
380 /// Handles context help
381 void ctMainFrame::OnContextHelp(wxCommandEvent& WXUNUSED(event))
382 {
383 wxContextHelp contextHelp;
384 }
385
386 /// Handles the Help Contents menu event for the reference manual.
387 void ctMainFrame::OnReferenceHelp(wxCommandEvent& WXUNUSED(event))
388 {
389 wxGetApp().GetReferenceHelpController().DisplayContents();
390 }
391
392 /// Resizes the main frame according to the
393 /// state of the toolbar
394 void ctMainFrame::ResizeFrame()
395 {
396 PositionToolBar();
397 wxSizeEvent event(GetSize(), GetId());
398 this->ProcessEvent(event);
399 }
400
401 /// Update the frame title.
402 void ctMainFrame::UpdateFrameTitle()
403 {
404 // TODO
405 }
406
407 // General disabler
408 void ctMainFrame::OnUpdateDisable(wxUpdateUIEvent& event)
409 {
410 event.Enable( false );
411 }
412
413 /*!
414 * ctOutputWindow represents a page showing a setup.h file or config command.
415 */
416
417 IMPLEMENT_CLASS(ctOutputWindow, wxPanel)
418
419 BEGIN_EVENT_TABLE(ctOutputWindow, wxPanel)
420 #if wxUSE_CLIPBOARD
421 EVT_BUTTON(wxID_COPY, ctOutputWindow::OnCopyToClipboard)
422 #endif // wxUSE_CLIPBOARD
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)
428 END_EVENT_TABLE()
429
430 ctOutputWindow::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
440 /// Initialise the windows.
441 void 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
457 m_filenameCtrl = new wxTextCtrl(this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxSUNKEN_BORDER|wxTE_READONLY);
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
465 m_codeCtrl = new wxTextCtrl(this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxSize(100, 100), wxTE_RICH|wxTE_MULTILINE|wxSUNKEN_BORDER);
466 item0->Add( m_codeCtrl, 1, wxGROW|wxALIGN_CENTER_VERTICAL|wxLEFT|wxRIGHT|wxBOTTOM, 5 );
467
468 SetAutoLayout( true );
469 SetSizer( item0 );
470 }
471
472 #if wxUSE_CLIPBOARD
473 /// Copies the text to the clipboard.
474 void ctOutputWindow::OnCopyToClipboard(wxCommandEvent& WXUNUSED(event))
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 }
491
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 );
497
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 }
508 #endif // wxUSE_CLIPBOARD
509
510 /// Sets the code in the text control.
511 void ctOutputWindow::SetText(const wxString& text)
512 {
513 if (m_codeCtrl)
514 m_codeCtrl->SetValue(text);
515 }
516
517 /// Sets the filename.
518 void ctOutputWindow::SetFilename(const wxString& filename)
519 {
520 if (m_filenameCtrl)
521 m_filenameCtrl->SetValue(filename);
522 }
523
524 /// Saves the file.
525 void ctOutputWindow::OnSaveText(wxCommandEvent& WXUNUSED(event))
526 {
527 if (m_codeCtrl->IsModified())
528 {
529 wxString filename(m_filenameCtrl->GetValue());
530 if (!filename.empty())
531 {
532 m_codeCtrl->SaveFile(filename);
533 m_codeCtrl->DiscardEdits();
534 }
535 }
536 }
537
538 void ctOutputWindow::OnUpdateSaveText(wxUpdateUIEvent& event)
539 {
540 event.Enable(m_doc && m_codeCtrl && m_codeCtrl->IsModified());
541 }
542
543 void ctOutputWindow::OnRegenerate(wxCommandEvent& WXUNUSED(event))
544 {
545 if (m_doc)
546 {
547 ctConfigToolView* view = (ctConfigToolView*) m_doc->GetFirstView();
548 view->RegenerateSetup();
549 }
550 }
551
552 void ctOutputWindow::OnUpdateRegenerate(wxUpdateUIEvent& event)
553 {
554 event.Enable( m_doc != NULL );
555 }
556
557 void ctOutputWindow::OnUpdateCopy(wxUpdateUIEvent& event)
558 {
559 event.Enable( m_doc != NULL );
560 }