📄 mainframe.cpp
字号:
/* ---------------------------------------------------------------------------- * Copyright (C) 2004-2005 by egnite Software GmbH * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License as published by the Free * Software Foundation; either version 2 of the License, or (at your option) * any later version. * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for * more details. * * You should have received a copy of the GNU General Public License along with * this program; if not, write to the Free Software Foundation, Inc., * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * * ---------------------------------------------------------------------------- * Parts are * * Copyright (C) 1998, 1999, 2000 Red Hat, Inc. * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License as published by the Free * Software Foundation; either version 2 of the License, or (at your option) * any later version. * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for * more details. * * You should have received a copy of the GNU General Public License along with * this program; if not, write to the Free Software Foundation, Inc., * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * * ---------------------------------------------------------------------------- *//* * $Log: mainframe.cpp,v $ * Revision 1.9 2005/11/24 09:44:30 haraldkipp * wxWidget failed to built with unicode support, which results in a number * of compile errors. Fixed by Torben Mikael Hansen. * * Revision 1.8 2005/09/21 10:44:15 christianwelzel * Replaced deprecated commands with newer ones. * * Revision 1.7 2005/07/22 18:46:25 haraldkipp * Added selectable toolbar button sizes, toolbar menu, more toolbar buttons * and online help. * * Revision 1.6 2005/07/20 11:16:00 haraldkipp * Linux application icon added * * Revision 1.5 2005/07/20 09:20:25 haraldkipp * Set application icon * * Revision 1.4 2005/04/22 15:14:43 haraldkipp * Avoid compiler warnings. * * Revision 1.3 2004/08/18 13:34:20 haraldkipp * Now working on Linux * * Revision 1.2 2004/08/03 15:03:25 haraldkipp * Another change of everything * * Revision 1.1 2004/06/07 16:11:22 haraldkipp * Complete redesign based on eCos' configtool * */#include <wx/config.h>#include "ids.h"#include "nutconf.h"#include "settings.h"#include "settingsdlg.h"#include "mainframe.h"#if !defined(__WXMSW__)#include "bitmaps/application.xpm"#include "bitmaps/buildlibrary.xpm"#include "bitmaps/buildlibrary_large.xpm"#include "bitmaps/help.xpm"#include "bitmaps/help_large.xpm"#include "bitmaps/open.xpm"#include "bitmaps/open_large.xpm"#include "bitmaps/save.xpm"#include "bitmaps/save_large.xpm"#include "bitmaps/search.xpm"#include "bitmaps/search_large.xpm"#endifBEGIN_EVENT_TABLE(CMainFrame, wxDocParentFrame) EVT_MENU(wxID_EXIT, CMainFrame::OnQuit) EVT_MENU(ID_BUILD_LIBRARY, CMainFrame::OnBuildLibraries) EVT_MENU(ID_GENERATE_BUILD_TREE, CMainFrame::OnGenerateBuildTree) EVT_MENU(ID_BUILD_NUTOS, CMainFrame::OnBuildNutOS) EVT_MENU(ID_CREATE_SAMPLE_APPS, CMainFrame::OnCreateSampleDir) EVT_SIZE(CMainFrame::OnSize) EVT_SASH_DRAGGED_RANGE(ID_CONFIG_SASH_WINDOW, ID_OUTPUT_SASH_WINDOW, CMainFrame::OnSashDrag) EVT_MENU(ID_SETTINGS, CMainFrame::OnSettings) EVT_MENU(ID_TOOLBARS, CMainFrame::OnToggleToolbar) EVT_MENU(ID_TOOLBARSIZE, CMainFrame::OnToggleToolbarSize) EVT_MENU(ID_NUTOS_HELP, CMainFrame::OnHelp) END_EVENT_TABLE();CMainFrame::CMainFrame(wxDocManager * manager, const wxString & title):wxDocParentFrame(manager, (wxFrame *) NULL, ID_MAIN_FRAME, title), m_smallToolbar(true){ SetIcon(wxICON(application)); CreateNutMenuBar(); CreateNutToolBar(); CreateNutStatusBar(); /* * Restore frame position and size. */ wxConfigBase *pConfig = wxConfigBase::Get(); Move(pConfig->Read(wxT("/MainFrame/x"), 50), pConfig->Read(wxT("/MainFrame/y"), 50)); SetClientSize(pConfig->Read(wxT("/MainFrame/w"), 550), pConfig->Read(wxT("/MainFrame/h"), 350)); CreateNutWindows();}/*! * \brief Destructor. */CMainFrame::~CMainFrame(){ // Save frame size and position. wxConfigBase *pConfig = wxConfigBase::Get(); if (pConfig) { wxString lastPath = pConfig->GetPath(); pConfig->SetPath(wxT("/MainFrame")); /* * Frame window position and client window size. */ int x, y; int w, h; GetPosition(&x, &y); pConfig->Write(wxT("x"), (long) x); pConfig->Write(wxT("y"), (long) y); GetClientSize(&w, &h); pConfig->Write(wxT("w"), (long) w); pConfig->Write(wxT("h"), (long) h); wxSize sz; sz = m_configSashWindow->GetSize(); pConfig->Write(wxT("tree_w"), (long) sz.x); pConfig->Write(wxT("tree_h"), (long) sz.y); sz = m_propertiesSashWindow->GetSize(); pConfig->Write(wxT("prop_w"), (long) sz.x); pConfig->Write(wxT("prop_h"), (long) sz.y); sz = m_infoSashWindow->GetSize(); pConfig->Write(wxT("desc_w"), (long) sz.x); pConfig->Write(wxT("desc_h"), (long) sz.y); sz = m_outputSashWindow->GetSize(); pConfig->Write(wxT("outp_w"), (long) sz.x); pConfig->Write(wxT("outp_h"), (long) sz.y); x = m_splitter->GetSashPosition(); if(x > 0) { pConfig->Write(wxT("split_x"), (long) x); } pConfig->SetPath(lastPath); }}void CMainFrame::CreateNutMenuBar(){ wxMenu *fileMenu = new wxMenu(wxEmptyString, wxMENU_TEAROFF); //td fileMenu->Append(wxID_NEW, wxT("&New\tCtrl+N"), wxT("Creates a new document")); fileMenu->Append(wxID_OPEN, wxT("&Open\tCtrl+O"), wxT("Opens an existing configuration")); fileMenu->Append(wxID_SAVE, wxT("&Save\tCtrl+S"), wxT("Saves the active configuration")); fileMenu->Append(wxID_SAVEAS, wxT("Save &As..."), wxT("Saves the active configuration with a new name")); //td fileMenu->AppendSeparator(); //td fileMenu->Append(ID_IMPORT, wxT("&Import..."), wxT("Imports a minimal configuration exported from another configuration")); //td fileMenu->Append(ID_EXPORT, wxT("&Export..."), wxT("Exports a minimal configuration for importing into another configuration")); //td fileMenu->AppendSeparator(); fileMenu->Append(wxID_EXIT, wxT("E&xit\tAlt+X"), wxT("Quits the application")); wxMenu *editMenu = new wxMenu(wxEmptyString, wxMENU_TEAROFF); editMenu->Append(wxID_FIND, wxT("&Find...\tCtrl+F"), wxT("Finds the specified text")); editMenu->Append(ID_SETTINGS, wxT("&Settings...\tCtrl+T"), wxT("Shows the settings dialog")); //td editMenu->Append(wxID_CUT, wxT("Cu&t\tCtrl+X"), wxT("Cuts the output pane selection and moves it to the Clipboard")); //td editMenu->Append(wxID_COPY, wxT("&Copy\tCtrl+C"), wxT("Copies the output pane selection to the clipboard")); //td editMenu->Append(wxID_PASTE, wxT("&Paste\tCtrl+V"), wxT("Inserts Clipboard contents")); //td editMenu->Append(wxID_CLEAR, wxT("&Clear"), wxT("Erases everything in the output pane")); //td editMenu->AppendSeparator(); //td editMenu->Append(wxID_SELECTALL, wxT("&Select All\tCtrl+A"), wxT("Selects the entire output pane")); //td editMenu->AppendSeparator(); //td editMenu->Append(ID_FIND_NEXT, wxT("Find &Next\tF3"), wxT("Finds the next item matching the Find text")); //td editMenu->AppendSeparator(); //td editMenu->Append(ID_SAVE_OUTPUT, wxT("Sa&ve Output..."), wxT("Saves the contents of the output pane")); wxMenu *viewMenu = new wxMenu(wxT(""), wxMENU_TEAROFF); wxMenu *toolbarMenu = new wxMenu; toolbarMenu->AppendCheckItem(ID_TOOLBARS, wxT("&Show"), wxT("Shows or hides the toolbar")); toolbarMenu->Check(ID_TOOLBARS, true); toolbarMenu->AppendCheckItem(ID_TOOLBARSIZE, wxT("&Large Buttons"), wxT("Toggles toolbar size")); viewMenu->Append(-1, wxT("Toolbar"), toolbarMenu); //td viewMenu->Append(ID_SETTINGS, wxT("&Settings...\tCtrl+T"), wxT("Shows the application settings dialog")); //td viewMenu->AppendSeparator(); //td viewMenu->Append(ID_TOGGLE_PROPERTIES, wxT("&Properties\tAlt+1"), wxT("Shows or hides the properties window"), true); //td viewMenu->Append(ID_TOGGLE_OUTPUT, wxT("&Output\tAlt+2"), wxT("Shows the output window"), true); //td viewMenu->Append(ID_TOGGLE_SHORT_DESCR, wxT("&Short Description\tAlt+3"), wxT("Shows or hides the short description window"), true); wxMenu *buildMenu = new wxMenu(wxEmptyString, wxMENU_TEAROFF); //td buildMenu->Append(ID_BUILD_LIBRARY, wxT("&Library\tF7"), wxT("Builds the library")); //td buildMenu->Append(ID_BUILD_TESTS, wxT("&Tests\tShift+F7"), wxT("Builds the tests")); //td buildMenu->Append(ID_CLEAN, wxT("&Clean"), wxT("Deletes intermediate and output files")); //td buildMenu->Append(ID_STOP_BUILD, wxT("&Stop"), wxT("Stops the build")); //td buildMenu->AppendSeparator(); buildMenu->Append(ID_BUILD_LIBRARY, wxT("Build Nut/OS"), wxT("Builds Nut/OS libraries")); // buildMenu->Append(ID_GENERATE_BUILD_TREE, wxT("&Generate Build Tree"), wxT("Explicitly recreates the build tree")); // buildMenu->Append(ID_BUILD_NUTOS, wxT("Build Nut/OS"), wxT("Builds Nut/OS libraries")); buildMenu->AppendSeparator(); buildMenu->Append(ID_CREATE_SAMPLE_APPS, wxT("Create Sample Directory"), wxT("Creates a directory with Nut/OS sample applications")); //td buildMenu->Append(ID_BUILD_OPTIONS, wxT("&Options..."), wxT("Changes build options")); //td buildMenu->Append(ID_BUILD_REPOSITORY, wxT("&Repository..."), wxT("Selects repository")); //td buildMenu->Append(ID_BUILD_TEMPLATES, wxT("&Templates..."), wxT("Selects the package templates")); //td buildMenu->Append(ID_BUILD_PACKAGES, wxT("&Packages..."), wxT("Selects individual packages")); //td wxMenu *toolsMenu = new wxMenu(wxT(""), wxMENU_TEAROFF); //td wxMenu *pathMenu = new wxMenu; //td pathMenu->Append(ID_PATHS_BUILD_TOOLS, wxT("&Build Tools..."), wxT("Specifies the folder containing the build tools")); //td pathMenu->Append(ID_PATHS_USER_TOOLS, wxT("&User Tools..."), wxT("Specifies the folder containing the user tools")); //td toolsMenu->Append(ID_PATHS, wxT("&Paths"), pathMenu); //td toolsMenu->Append(ID_SHELL, wxT("&Shell..."), wxT("Invokes a command shell")); //td toolsMenu->Append(ID_RUN_TESTS, wxT("&Run Tests...\tCtrl+F5"), wxT("Runs the configuration tests")); //td toolsMenu->Append(ID_PLATFORMS, wxT("&Platforms..."), wxT("Edits the platforms list")); //td toolsMenu->Append(ID_ADMINISTRATION, wxT("&Administration..."), wxT("Performs repository administration tasks")); //td toolsMenu->AppendSeparator(); //td toolsMenu->Append(ID_INDEX_DOCS, wxT("Regenerate Help &Index"), wxT("Regenerates the online help contents")); wxMenu *helpMenu = new wxMenu; helpMenu->Append(ID_NUTOS_HELP, wxT("Help &Contents"), wxT("Displays help contents")); helpMenu->Append(ID_HELP_ABOUT, wxT("About NutConf..."), wxT("Displays version and copyright information")); //td helpMenu->Append(ID_CONFIGTOOL_HELP, wxT("&Configuration Tool Help\tShift+F1"), wxT("Displays help")); //td helpMenu->Append(ID_CONTEXT_HELP, wxT("&Help On..."), wxT("Displays help for clicked-on windows")); //td helpMenu->AppendSeparator(); wxMenuBar *menuBar = new wxMenuBar(); menuBar->Append(fileMenu, wxT("&File")); menuBar->Append(editMenu, wxT("&Edit")); menuBar->Append(viewMenu, wxT("&View")); menuBar->Append(buildMenu, wxT("&Build")); //td menuBar->Append(toolsMenu, wxT("&Tools")); menuBar->Append(helpMenu, wxT("&Help")); SetMenuBar(menuBar);}void CMainFrame::CreateNutToolBar(){ wxToolBarBase *toolBar = CreateToolBar(wxNO_BORDER | wxTB_FLAT | wxTB_HORIZONTAL | wxTB_DOCKABLE, ID_TOOLBAR); toolBar->SetMargins(4, 4); /* Load small toolbar buttons. */ if (m_smallToolbar) { toolBar->AddTool(wxID_OPEN, wxBITMAP(TBB_OPEN), wxNullBitmap, false, -1, -1, (wxObject *) NULL, wxT("Open configuration")); toolBar->AddTool(wxID_SAVE, wxBITMAP(TBB_SAVE), wxNullBitmap, false, -1, -1, (wxObject *) NULL, wxT("Save configuration")); toolBar->AddSeparator(); toolBar->AddTool(wxID_FIND, wxBITMAP(TBB_SEARCH), wxNullBitmap, false, -1, -1, (wxObject *) NULL, wxT("Search")); toolBar->AddTool(ID_BUILD_LIBRARY, wxBITMAP(TBB_BUILDLIBRARY), wxNullBitmap, false, -1, -1, (wxObject *) NULL, wxT("Build Nut/OS")); toolBar->AddSeparator(); toolBar->AddTool(ID_NUTOS_HELP, wxBITMAP(TBB_HELP), wxNullBitmap, false, -1, -1, (wxObject *) NULL, wxT("Show help")); } /* Load large toolbar buttons. */ else { toolBar->AddTool(wxID_OPEN, wxBITMAP(TBB_OPEN_LARGE), wxNullBitmap, false, -1, -1, (wxObject *) NULL, wxT("Open configuration")); toolBar->AddTool(wxID_SAVE, wxBITMAP(TBB_SAVE_LARGE), wxNullBitmap, false, -1, -1, (wxObject *) NULL, wxT("Save configuration")); toolBar->AddSeparator(); toolBar->AddTool(wxID_FIND, wxBITMAP(TBB_SEARCH_LARGE), wxNullBitmap, false, -1, -1, (wxObject *) NULL, wxT("Search")); toolBar->AddTool(ID_BUILD_LIBRARY, wxBITMAP(TBB_BUILDLIBRARY_LARGE), wxNullBitmap, false, -1, -1, (wxObject *) NULL, wxT("Build Nut/OS")); toolBar->AddSeparator(); toolBar->AddTool(ID_NUTOS_HELP, wxBITMAP(TBB_HELP_LARGE), wxNullBitmap, false, -1, -1, (wxObject *) NULL, wxT("Show help")); toolBar->SetToolBitmapSize(wxSize(32, 32)); } toolBar->Realize(); toolBar->SetHelpText(wxT("The toolbar allows quick access to commonly-used commands."));}void CMainFrame::CreateNutStatusBar(){ CreateStatusBar(4, wxST_SIZEGRIP); int widths[] = { -1, 100, 40, 80 }; SetStatusWidths(4, widths); SetStatusText(wxT("Ready"));}void CMainFrame::CreateNutWindows()
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -