1 /////////////////////////////////////////////////////////////////////////////
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart
10 /////////////////////////////////////////////////////////////////////////////
12 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
13 #pragma implementation "mainframe.h"
16 // For compilers that support precompilation, includes "wx/wx.h".
17 #include "wx/wxprec.h"
25 #include "wx/splitter.h"
29 #include "wx/cshelp.h"
30 #include "wx/html/htmlwin.h"
31 #include "wx/notebook.h"
32 #include "wx/dataobj.h"
33 #include "wx/clipbrd.h"
34 #include "wx/stockitem.h"
35 #include "wxconfigtool.h"
36 #include "mainframe.h"
37 #include "appsettings.h"
39 #include "configtree.h"
40 #include "propeditor.h"
41 #include "configtooldoc.h"
42 #include "configtoolview.h"
43 #include "configbrowser.h"
45 #include "bitmaps/wxconfigtool.xpm"
47 #include "bitmaps/copy.xpm"
48 #include "bitmaps/cut.xpm"
49 #include "bitmaps/paste.xpm"
50 #include "bitmaps/open.xpm"
51 #include "bitmaps/save.xpm"
52 #include "bitmaps/new.xpm"
53 #include "bitmaps/help.xpm"
54 #include "bitmaps/undo.xpm"
55 #include "bitmaps/redo.xpm"
56 #include "bitmaps/helpcs.xpm"
57 #include "bitmaps/go.xpm"
59 IMPLEMENT_CLASS(ctMainFrame
, wxDocParentFrame
)
61 BEGIN_EVENT_TABLE(ctMainFrame
, wxDocParentFrame
)
62 EVT_CLOSE(ctMainFrame::OnCloseWindow
)
63 EVT_MENU(wxID_ABOUT
, ctMainFrame::OnAbout
)
64 EVT_MENU(wxID_OPEN
, ctMainFrame::OnOpen
)
65 EVT_MENU(wxID_NEW
, ctMainFrame::OnNew
)
66 EVT_MENU(wxID_EXIT
, ctMainFrame::OnExit
)
67 EVT_MENU(ctID_SETTINGS
, ctMainFrame::OnSettings
)
68 EVT_MENU(ctID_SHOW_TOOLBAR
, ctMainFrame::OnShowToolbar
)
69 EVT_MENU(wxID_HELP
, ctMainFrame::OnHelp
)
70 EVT_MENU(ctID_REFERENCE_CONTENTS
, ctMainFrame::OnReferenceHelp
)
71 EVT_MENU(wxID_HELP_CONTEXT
, ctMainFrame::OnContextHelp
)
73 EVT_UPDATE_UI(ctID_ADD_ITEM_CHECKBOX
, ctMainFrame::OnUpdateDisable
)
74 EVT_UPDATE_UI(ctID_ADD_ITEM_RADIOBUTTON
, ctMainFrame::OnUpdateDisable
)
75 EVT_UPDATE_UI(ctID_ADD_ITEM_GROUP
, ctMainFrame::OnUpdateDisable
)
76 EVT_UPDATE_UI(ctID_ADD_ITEM_CHECK_GROUP
, ctMainFrame::OnUpdateDisable
)
77 EVT_UPDATE_UI(ctID_ADD_ITEM_RADIO_GROUP
, ctMainFrame::OnUpdateDisable
)
78 EVT_UPDATE_UI(ctID_ADD_ITEM_STRING
, ctMainFrame::OnUpdateDisable
)
79 EVT_UPDATE_UI(ctID_DELETE_ITEM
, ctMainFrame::OnUpdateDisable
)
80 EVT_UPDATE_UI(ctID_RENAME_ITEM
, ctMainFrame::OnUpdateDisable
)
81 EVT_UPDATE_UI(wxID_COPY
, ctMainFrame::OnUpdateDisable
)
82 EVT_UPDATE_UI(wxID_CUT
, ctMainFrame::OnUpdateDisable
)
83 EVT_UPDATE_UI(wxID_PASTE
, ctMainFrame::OnUpdateDisable
)
84 EVT_UPDATE_UI(ctID_ITEM_HELP
, ctMainFrame::OnUpdateDisable
)
86 EVT_UPDATE_UI(ctID_ADD_CUSTOM_PROPERTY
, ctMainFrame::OnUpdateDisable
)
87 EVT_UPDATE_UI(ctID_EDIT_CUSTOM_PROPERTY
, ctMainFrame::OnUpdateDisable
)
88 EVT_UPDATE_UI(ctID_DELETE_CUSTOM_PROPERTY
, ctMainFrame::OnUpdateDisable
)
90 EVT_UPDATE_UI(ctID_SAVE_SETUP_FILE
, ctMainFrame::OnUpdateDisable
)
91 EVT_UPDATE_UI(ctID_SAVE_CONFIGURE_COMMAND
, ctMainFrame::OnUpdateDisable
)
93 EVT_UPDATE_UI(wxID_FIND
, ctMainFrame::OnUpdateDisable
)
95 EVT_UPDATE_UI(ctID_GO
, ctMainFrame::OnUpdateDisable
)
98 // Define my frame constructor
99 ctMainFrame::ctMainFrame(wxDocManager
*manager
, wxFrame
*parent
, wxWindowID id
, const wxString
& title
, const wxPoint
& pos
, const wxSize
& size
, long style
):
100 wxDocParentFrame(manager
, parent
, id
, title
, pos
, size
, style
)
104 m_configurePage
= NULL
;
106 #ifdef USE_CONFIG_BROWSER_PAGE
107 m_configBrowserPage
= NULL
;
109 m_mainNotebook
= NULL
;
112 m_treeSplitterWindow
= new wxSplitterWindow(this, wxID_ANY
, wxDefaultPosition
, wxSize(400, 300),
113 wxSP_3DSASH
|wxSP_3DBORDER
|wxNO_FULL_REPAINT_ON_RESIZE
|wxCLIP_CHILDREN
);
115 m_configTreeCtrl
= new ctConfigTreeCtrl(m_treeSplitterWindow
, wxID_ANY
, wxDefaultPosition
, wxDefaultSize
,
116 wxTR_HAS_BUTTONS
|wxNO_BORDER
|wxNO_FULL_REPAINT_ON_RESIZE
|wxCLIP_CHILDREN
);
118 m_mainNotebook
= new wxNotebook(m_treeSplitterWindow
, wxID_ANY
, wxDefaultPosition
, wxSize(300, 300),
119 wxNO_FULL_REPAINT_ON_RESIZE
|wxCLIP_CHILDREN
);
121 m_propertyEditor
= new ctPropertyEditor(m_mainNotebook
, wxID_ANY
, wxDefaultPosition
, wxSize(300, 200),
122 wxNO_BORDER
|wxNO_FULL_REPAINT_ON_RESIZE
|wxCLIP_CHILDREN
);
123 m_setupPage
= new ctOutputWindow(m_mainNotebook
, wxID_ANY
, wxDefaultPosition
, wxSize(300, 200),
124 wxNO_BORDER
|wxNO_FULL_REPAINT_ON_RESIZE
|wxCLIP_CHILDREN
);
125 m_configurePage
= new ctOutputWindow(m_mainNotebook
, wxID_ANY
, wxDefaultPosition
, wxSize(300, 200),
126 wxNO_BORDER
|wxNO_FULL_REPAINT_ON_RESIZE
|wxCLIP_CHILDREN
);
128 #ifdef USE_CONFIG_BROWSER_PAGE
129 m_configBrowserPage
= new ctConfigurationBrowserWindow(m_mainNotebook
, wxID_ANY
, wxDefaultPosition
, wxSize(300, 200),
130 wxNO_BORDER
|wxNO_FULL_REPAINT_ON_RESIZE
|wxCLIP_CHILDREN
);
133 m_mainNotebook
->AddPage(m_propertyEditor
, _T("Properties"));
134 #ifdef USE_CONFIG_BROWSER_PAGE
135 m_mainNotebook
->AddPage(m_configBrowserPage
, _T("Configuration Browser"));
137 m_mainNotebook
->AddPage(m_setupPage
, _T("setup.h"));
138 m_mainNotebook
->AddPage(m_configurePage
, _T("configure"));
140 // Need to do this afterwards since wxWin sets the XP background
142 m_propertyEditor
->GetDescriptionWindow()->SetBackgroundColour(ctDESCRIPTION_BACKGROUND_COLOUR
);
144 int sashPos
= wxGetApp().GetSettings().m_mainSashSize
;
145 m_treeSplitterWindow
->SplitVertically(m_configTreeCtrl
, m_mainNotebook
, sashPos
);
147 SetIcon(wxIcon(wxconfigtool_xpm
));
151 #endif // wxUSE_STATUSBAR
153 wxMenuBar
* menuBar
= CreateMenuBar();
156 CreateToolBar(wxNO_BORDER
|wxTB_FLAT
|wxTB_HORIZONTAL
|wxNO_FULL_REPAINT_ON_RESIZE
|wxCLIP_CHILDREN
);
157 InitToolBar(GetToolBar());
159 if (wxGetApp().GetSettings().m_showToolBar
)
161 menuBar
->Check(ctID_SHOW_TOOLBAR
, true);
165 menuBar
->Check(ctID_SHOW_TOOLBAR
, false);
166 GetToolBar()->Show(false);
171 void ctMainFrame::OnCloseWindow(wxCloseEvent
& event
)
175 if (!GetDocument()->DeleteAllViews() && event
.CanVeto())
184 m_findDialog
->Destroy();
191 wxGetApp().GetSettings().m_frameStatus
= ctSHOW_STATUS_MAXIMIZED
;
192 else if (IsIconized())
193 wxGetApp().GetSettings().m_frameStatus
= ctSHOW_STATUS_MINIMIZED
;
195 wxGetApp().GetSettings().m_frameStatus
= ctSHOW_STATUS_NORMAL
;
197 // Must delete this now since the DLL loading library will be
198 // uninitialised by the time the app object is deleted
199 wxGetApp().ClearHelpControllers();
201 if (!IsMaximized() && !IsIconized())
203 wxGetApp().GetSettings().m_frameSize
= GetRect();
204 wxGetApp().GetSettings().m_mainSashSize
= m_treeSplitterWindow
->GetSashPosition();
210 void ctMainFrame::OnAbout(wxCommandEvent
& WXUNUSED(event
))
212 wxString msg
= wxGetApp().GetSettings().GetAppName() + wxT(" (c) Julian Smart");
213 wxString caption
= wxT("About ") + wxGetApp().GetSettings().GetAppName();
214 wxMessageBox(msg
, caption
, wxOK
|wxICON_INFORMATION
);
217 void ctMainFrame::OnOpen(wxCommandEvent
& event
)
219 wxGetApp().GetDocManager()->OnFileOpen(event
);
222 void ctMainFrame::OnNew(wxCommandEvent
& event
)
224 wxGetApp().GetDocManager()->OnFileNew(event
);
227 void ctMainFrame::OnExit(wxCommandEvent
& WXUNUSED(event
))
232 void ctMainFrame::OnSettings(wxCommandEvent
& WXUNUSED(event
))
234 wxGetApp().GetSettings().ShowSettingsDialog();
237 void ctMainFrame::InitToolBar(wxToolBar
* toolBar
)
239 toolBar
->SetHelpText(wxT("The toolbar gives you easy access to commonly used commands."));
242 wxBitmap toolBarBitmaps
[20];
244 toolBarBitmaps
[0] = wxBitmap(new_xpm
);
245 toolBarBitmaps
[1] = wxBitmap(open_xpm
);
246 toolBarBitmaps
[2] = wxBitmap(save_xpm
);
247 toolBarBitmaps
[3] = wxBitmap(copy_xpm
);
248 toolBarBitmaps
[4] = wxBitmap(cut_xpm
);
249 toolBarBitmaps
[5] = wxBitmap(paste_xpm
);
250 toolBarBitmaps
[6] = wxBitmap(go_xpm
);
251 toolBarBitmaps
[7] = wxBitmap(help_xpm
);
252 toolBarBitmaps
[10] = wxBitmap(undo_xpm
);
253 toolBarBitmaps
[11] = wxBitmap(redo_xpm
);
254 toolBarBitmaps
[12] = wxBitmap(help_xpm
);
255 toolBarBitmaps
[13] = wxBitmap(helpcs_xpm
);
257 toolBar
->AddTool(wxID_NEW
, toolBarBitmaps
[0], wxNullBitmap
, false, wxDefaultCoord
, wxDefaultCoord
, (wxObject
*) NULL
, wxT("New project"));
258 toolBar
->AddTool(wxID_OPEN
, toolBarBitmaps
[1], wxNullBitmap
, false, wxDefaultCoord
, wxDefaultCoord
, (wxObject
*) NULL
, wxT("Open project"));
259 toolBar
->AddTool(wxID_SAVE
, toolBarBitmaps
[2], wxNullBitmap
, false, wxDefaultCoord
, wxDefaultCoord
, (wxObject
*) NULL
, wxT("Save project"));
261 toolBar
->AddSeparator();
262 toolBar
->AddTool(wxID_CUT
, toolBarBitmaps
[4], wxNullBitmap
, false, wxDefaultCoord
, wxDefaultCoord
, (wxObject
*) NULL
, wxGetStockLabel(wxID_CUT
, false));
263 toolBar
->AddTool(wxID_COPY
, toolBarBitmaps
[3], wxNullBitmap
, false, wxDefaultCoord
, wxDefaultCoord
, (wxObject
*) NULL
, wxGetStockLabel(wxID_COPY
, false));
264 toolBar
->AddTool(wxID_PASTE
, toolBarBitmaps
[5], wxNullBitmap
, false, wxDefaultCoord
, wxDefaultCoord
, (wxObject
*) NULL
, wxGetStockLabel(wxID_PASTE
, false));
265 toolBar
->AddSeparator();
266 toolBar
->AddTool(wxID_UNDO
, toolBarBitmaps
[10], wxNullBitmap
, false, wxDefaultCoord
, wxDefaultCoord
, (wxObject
*) NULL
, wxGetStockLabel(wxID_UNDO
, false));
267 toolBar
->AddTool(wxID_REDO
, toolBarBitmaps
[11], wxNullBitmap
, false, wxDefaultCoord
, wxDefaultCoord
, (wxObject
*) NULL
, wxGetStockLabel(wxID_REDO
, false));
268 toolBar
->AddSeparator();
269 toolBar
->AddTool(ctID_GO
, toolBarBitmaps
[6], wxNullBitmap
, false, wxDefaultCoord
, wxDefaultCoord
, (wxObject
*) NULL
, wxT("Save setup.h or configurewx.sh"));
270 toolBar
->AddSeparator();
271 toolBar
->AddTool(ctID_ITEM_HELP
, toolBarBitmaps
[12], wxNullBitmap
, false, wxDefaultCoord
, wxDefaultCoord
, (wxObject
*) NULL
, wxT("Show help for this option"));
272 toolBar
->AddTool(wxID_HELP_CONTEXT
, toolBarBitmaps
[13], wxNullBitmap
, false, wxDefaultCoord
, wxDefaultCoord
, (wxObject
*) NULL
, wxT("Show help on the clicked item"));
274 // after adding the buttons to the toolbar, must call Realize() to reflect
279 wxMenuBar
* ctMainFrame::CreateMenuBar()
282 wxMenu
*fileMenu
= new wxMenu
;
284 wxGetApp().GetFileHistory().UseMenu(fileMenu
);
286 fileMenu
->Append(wxID_NEW
, wxGetStockLabel(wxID_NEW
, true, wxT("Ctrl+N")), wxT("Create a new settings document"));
287 fileMenu
->Append(wxID_OPEN
, wxGetStockLabel(wxID_OPEN
, true, wxT("Ctrl+O")), wxT("Open a settings document"));
288 fileMenu
->Append(wxID_CLOSE
, wxGetStockLabel(wxID_CLOSE
, true, wxT("Ctrl+W")), wxT("Close the current settings document"));
289 fileMenu
->AppendSeparator();
290 fileMenu
->Append(wxID_SAVE
, wxGetStockLabel(wxID_SAVE
, true, wxT("Ctrl+S")), wxT("Save the settings document"));
291 fileMenu
->Append(wxID_SAVEAS
, wxGetStockLabel(wxID_SAVEAS
), wxT("Save the settings document under a new filename"));
292 fileMenu
->AppendSeparator();
293 fileMenu
->Append(ctID_SAVE_SETUP_FILE
, wxT("Save Setup.&h...\tCtrl+H"), wxT("Save the setup.h file"));
294 fileMenu
->Append(ctID_SAVE_CONFIGURE_COMMAND
, wxT("Save Configure Script...\tCtrl+G"), wxT("Save the configure script file"));
295 fileMenu
->AppendSeparator();
296 fileMenu
->Append(ctID_GO
, wxT("&Go\tF5"), wxT("Quick-save the setup.h or configure.sh file"));
297 fileMenu
->AppendSeparator();
298 fileMenu
->Append(wxID_EXIT
, wxGetStockLabel(wxID_EXIT
, true, wxT("Alt+F4")), wxT("Exit the application"));
300 wxGetApp().GetDocManager()->FileHistoryUseMenu(fileMenu
);
302 wxMenu
*editMenu
= new wxMenu
;
304 editMenu
->Append(wxID_UNDO
, wxGetStockLabel(wxID_UNDO
, true, wxT("Ctrl+Z")));
305 editMenu
->Append(wxID_REDO
, wxGetStockLabel(wxID_REDO
, true, wxT("Ctrl+Y")));
306 editMenu
->AppendSeparator();
307 editMenu
->Append(wxID_COPY
, wxGetStockLabel(wxID_CLOSE
, true, wxT("Ctrl+C")));
308 editMenu
->Append(wxID_CUT
, wxGetStockLabel(wxID_CUT
, true, wxT("Ctrl+X")));
309 editMenu
->Append(wxID_PASTE
, wxGetStockLabel(wxID_PASTE
, true, wxT("Ctrl+V")));
310 editMenu
->AppendSeparator();
312 wxMenu
* itemMenu
= new wxMenu
;
313 itemMenu
->Append(ctID_ADD_ITEM_CHECKBOX
, _("Add &Checkbox Option"), _("Add a checkbox configuration option"));
314 itemMenu
->Append(ctID_ADD_ITEM_RADIOBUTTON
, _("Add &Radio Button Option"), _("Add a radio button configuration option"));
315 // TODO. However we can also simply use custom properties;
316 // but then the C++ code has to be special-cased.
317 // itemMenu->Append(ctID_ADD_ITEM_STRING, _("Add &String Option"), _("Add a string configuration option"));
318 itemMenu
->Append(ctID_ADD_ITEM_GROUP
, _("Add &Group Option"), _("Add a group configuration option"));
319 itemMenu
->Append(ctID_ADD_ITEM_CHECK_GROUP
, _("Add Chec&k Group Option"), _("Add a check group configuration option"));
320 itemMenu
->Append(ctID_ADD_ITEM_RADIO_GROUP
, _("Add Rad&io Group Option"), _("Add a radio group configuration option"));
322 editMenu
->Append(ctID_ADD_ITEM
, wxT("Add &Option"), itemMenu
, _("Add a configuration option"));
323 editMenu
->AppendSeparator();
325 wxMenu
* propertyMenu
= new wxMenu
;
326 propertyMenu
->Append(ctID_ADD_CUSTOM_PROPERTY
, _("&Add Custom Property"), _("Adds a custom property to the current option"));
327 propertyMenu
->Append(ctID_EDIT_CUSTOM_PROPERTY
, _("&Edit Custom Property"), _("Edits the currently selected custom property"));
328 propertyMenu
->Append(ctID_DELETE_CUSTOM_PROPERTY
, _("&Delete Custom Property"), _("Deletes the currently selected custom property"));
329 editMenu
->Append(ctID_CUSTOM_PROPERTY
, _("Custom P&roperty"), propertyMenu
, _("Custom property commands"));
331 editMenu
->AppendSeparator();
332 editMenu
->Append(ctID_DELETE_ITEM
, _("&Delete Option"), _("Delete a configuration option"));
333 editMenu
->Append(ctID_RENAME_ITEM
, _("&Rename Option"), _("Rename a configuration option"));
334 editMenu
->AppendSeparator();
335 editMenu
->Append(wxID_FIND
, wxGetStockLabel(wxID_FIND
, true, wxT("Ctrl+F")), _("Search for a string in the settings document"));
337 // Save for the command processor.
338 m_editMenu
= editMenu
;
340 wxMenu
*viewMenu
= new wxMenu
;
341 viewMenu
->Append(ctID_SHOW_TOOLBAR
, wxT("Show &Toolbar"), wxT("Toggle the toolbar on and off"),
343 viewMenu
->Append(ctID_SETTINGS
, wxT("&Settings...\tCtrl+T"), wxT("Show application settings"));
345 wxMenu
*helpMenu
= new wxMenu
;
346 helpMenu
->Append(wxID_HELP
, wxT("&Help Contents"), wxT("Show Configuration Tool help"));
347 helpMenu
->Append(ctID_REFERENCE_CONTENTS
, wxT("&wxWidgets Help Contents"), wxT("Show wxWidgets reference"));
348 helpMenu
->AppendSeparator();
349 helpMenu
->Append(ctID_ITEM_HELP
, wxT("&Configuration Option Help\tF1"), wxT("Show help for the selected option"));
350 helpMenu
->Append(wxID_HELP_CONTEXT
, wxT("&What's this?"), wxT("Show help on the clicked item"));
351 helpMenu
->AppendSeparator();
352 helpMenu
->Append(wxID_ABOUT
, wxT("&About..."), wxT("Show details about this application"));
354 wxMenuBar
*menuBar
= new wxMenuBar
;
356 menuBar
->Append(fileMenu
, wxT("&File"));
357 menuBar
->Append(editMenu
, wxT("&Edit"));
358 menuBar
->Append(viewMenu
, wxT("&View"));
359 menuBar
->Append(helpMenu
, wxT("&Help"));
362 wxConfig
config(wxGetApp().GetSettings().GetAppName(), wxT("wxWidgets"));
363 config
.SetPath(wxT("FileHistory/"));
364 wxGetApp().GetDocManager()->FileHistoryLoad(config
);
370 /// Handles the Show Toolbar menu event.
371 void ctMainFrame::OnShowToolbar(wxCommandEvent
& WXUNUSED(event
))
373 wxGetApp().GetSettings().m_showToolBar
= !wxGetApp().GetSettings().m_showToolBar
;
374 GetToolBar()->Show(wxGetApp().GetSettings().m_showToolBar
);
378 /// Handles the Help Contents menu event.
379 void ctMainFrame::OnHelp(wxCommandEvent
& WXUNUSED(event
))
381 wxGetApp().GetHelpController().DisplayContents();
384 /// Handles context help
385 void ctMainFrame::OnContextHelp(wxCommandEvent
& WXUNUSED(event
))
387 wxContextHelp contextHelp
;
390 /// Handles the Help Contents menu event for the reference manual.
391 void ctMainFrame::OnReferenceHelp(wxCommandEvent
& WXUNUSED(event
))
393 wxGetApp().GetReferenceHelpController().DisplayContents();
396 /// Resizes the main frame according to the
397 /// state of the toolbar
398 void ctMainFrame::ResizeFrame()
401 wxSizeEvent
event(GetSize(), GetId());
402 this->ProcessEvent(event
);
405 /// Update the frame title.
406 void ctMainFrame::UpdateFrameTitle()
412 void ctMainFrame::OnUpdateDisable(wxUpdateUIEvent
& event
)
414 event
.Enable( false );
418 * ctOutputWindow represents a page showing a setup.h file or config command.
421 IMPLEMENT_CLASS(ctOutputWindow
, wxPanel
)
423 BEGIN_EVENT_TABLE(ctOutputWindow
, wxPanel
)
425 EVT_BUTTON(wxID_COPY
, ctOutputWindow::OnCopyToClipboard
)
426 #endif // wxUSE_CLIPBOARD
427 EVT_BUTTON(wxID_SAVE
, ctOutputWindow::OnSaveText
)
428 EVT_BUTTON(ctID_REGENERATE
, ctOutputWindow::OnRegenerate
)
429 EVT_UPDATE_UI(wxID_SAVE
, ctOutputWindow::OnUpdateSaveText
)
430 EVT_UPDATE_UI(ctID_REGENERATE
, ctOutputWindow::OnUpdateRegenerate
)
431 EVT_UPDATE_UI(wxID_COPY
, ctOutputWindow::OnUpdateCopy
)
434 ctOutputWindow::ctOutputWindow(wxWindow
* parent
, wxWindowID id
,
435 const wxPoint
& pos
, const wxSize
& size
, long style
):
436 wxPanel(parent
, id
, pos
, size
, style
)
439 m_filenameCtrl
= NULL
;
444 /// Initialise the windows.
445 void ctOutputWindow::CreateWindows()
447 wxBoxSizer
*item0
= new wxBoxSizer( wxVERTICAL
);
449 wxBoxSizer
*item2
= new wxBoxSizer( wxHORIZONTAL
);
450 item0
->Add( item2
, 0, wxGROW
|wxALIGN_CENTER_VERTICAL
, 5 );
452 wxButton
*item4
= new wxButton( this, wxID_COPY
, _("&Copy"), wxDefaultPosition
, wxDefaultSize
, 0 );
453 item2
->Add( item4
, 0, wxGROW
|wxALIGN_CENTER_VERTICAL
|wxLEFT
|wxTOP
|wxBOTTOM
|wxRIGHT
, 5 );
454 item4
->SetHelpText(_("Copies the selection or whole file to the clipboard."));
456 wxButton
*item5
= new wxButton( this, ctID_REGENERATE
, _("Re&generate"), wxDefaultPosition
, wxDefaultSize
, 0 );
457 item2
->Add( item5
, 0, wxGROW
|wxALIGN_CENTER_VERTICAL
|wxTOP
|wxBOTTOM
|wxRIGHT
, 5 );
458 item5
->SetHelpText(_("Regenerates the code."));
461 m_filenameCtrl
= new wxTextCtrl(this, wxID_ANY
, wxEmptyString
, wxDefaultPosition
, wxDefaultSize
, wxSUNKEN_BORDER
|wxTE_READONLY
);
462 item2
->Add( m_filenameCtrl
, 1, wxGROW
|wxALIGN_CENTER_VERTICAL
|wxTOP
|wxBOTTOM
|wxRIGHT
, 5 );
463 m_filenameCtrl
->SetHelpText(_("Shows the filename where the code is being saved."));
465 m_filenameCtrl
= NULL
;
469 m_codeCtrl
= new wxTextCtrl(this, wxID_ANY
, wxEmptyString
, wxDefaultPosition
, wxSize(100, 100), wxTE_RICH
|wxTE_MULTILINE
|wxSUNKEN_BORDER
);
470 item0
->Add( m_codeCtrl
, 1, wxGROW
|wxALIGN_CENTER_VERTICAL
|wxLEFT
|wxRIGHT
|wxBOTTOM
, 5 );
472 SetAutoLayout( true );
477 /// Copies the text to the clipboard.
478 void ctOutputWindow::OnCopyToClipboard(wxCommandEvent
& WXUNUSED(event
))
480 // Try to copy the selection first
481 long int selFrom
, selTo
;
482 m_codeCtrl
->GetSelection(& selFrom
, & selTo
);
483 if (selFrom
!= selTo
)
489 // Copy the whole amount
490 if (!wxTheClipboard
->Open())
492 wxMessageBox(_("Sorry, could not open the clipboard."), _("Clipboard problem"), wxICON_EXCLAMATION
|wxOK
);
496 wxString
value(m_codeCtrl
->GetValue());
498 value
.Replace(_T("\n"), _T("\r\n"));
500 wxTextDataObject
*data
= new wxTextDataObject( value
);
502 if (!wxTheClipboard
->SetData( data
))
504 wxTheClipboard
->Close();
505 wxMessageBox(_("Sorry, could not copy to the clipboard."), _("Clipboard problem"), wxICON_EXCLAMATION
|wxOK
);
509 wxTheClipboard
->Close();
512 #endif // wxUSE_CLIPBOARD
514 /// Sets the code in the text control.
515 void ctOutputWindow::SetText(const wxString
& text
)
518 m_codeCtrl
->SetValue(text
);
521 /// Sets the filename.
522 void ctOutputWindow::SetFilename(const wxString
& filename
)
525 m_filenameCtrl
->SetValue(filename
);
529 void ctOutputWindow::OnSaveText(wxCommandEvent
& WXUNUSED(event
))
531 if (m_codeCtrl
->IsModified())
533 wxString
filename(m_filenameCtrl
->GetValue());
534 if (!filename
.empty())
536 m_codeCtrl
->SaveFile(filename
);
537 m_codeCtrl
->DiscardEdits();
542 void ctOutputWindow::OnUpdateSaveText(wxUpdateUIEvent
& event
)
544 event
.Enable(m_doc
&& m_codeCtrl
&& m_codeCtrl
->IsModified());
547 void ctOutputWindow::OnRegenerate(wxCommandEvent
& WXUNUSED(event
))
551 ctConfigToolView
* view
= (ctConfigToolView
*) m_doc
->GetFirstView();
552 view
->RegenerateSetup();
556 void ctOutputWindow::OnUpdateRegenerate(wxUpdateUIEvent
& event
)
558 event
.Enable( m_doc
!= NULL
);
561 void ctOutputWindow::OnUpdateCopy(wxUpdateUIEvent
& event
)
563 event
.Enable( m_doc
!= NULL
);