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