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