📄 mainframe.cpp
字号:
/////////////////////////////////////////////////////////////////////////////
// Name: mainframe.cpp
// Purpose: Main frame
// Author: Julian Smart
// Modified by:
// Created: 2002-09-04
// RCS-ID: $Id: mainframe.cpp,v 1.21 2005/09/23 12:56:23 MR Exp $
// Copyright: (c) Julian Smart
// Licence:
/////////////////////////////////////////////////////////////////////////////
// For compilers that support precompilation, includes "wx/wx.h".
#include "wx/wxprec.h"
#ifdef __BORLANDC__
#pragma hdrstop
#endif
#ifndef WX_PRECOMP
#include "wx/splitter.h"
#endif
#include "wx/cshelp.h"
#include "wx/html/htmlwin.h"
#include "wx/notebook.h"
#include "wx/dataobj.h"
#include "wx/clipbrd.h"
#include "wx/stockitem.h"
#include "wxconfigtool.h"
#include "mainframe.h"
#include "appsettings.h"
#include "symbols.h"
#include "configtree.h"
#include "propeditor.h"
#include "configtooldoc.h"
#include "configtoolview.h"
#include "configbrowser.h"
#include "bitmaps/wxconfigtool.xpm"
#include "bitmaps/copy.xpm"
#include "bitmaps/cut.xpm"
#include "bitmaps/paste.xpm"
#include "bitmaps/open.xpm"
#include "bitmaps/save.xpm"
#include "bitmaps/new.xpm"
#include "bitmaps/help.xpm"
#include "bitmaps/undo.xpm"
#include "bitmaps/redo.xpm"
#include "bitmaps/helpcs.xpm"
#include "bitmaps/go.xpm"
IMPLEMENT_CLASS(ctMainFrame, wxDocParentFrame)
BEGIN_EVENT_TABLE(ctMainFrame, wxDocParentFrame)
EVT_CLOSE(ctMainFrame::OnCloseWindow)
EVT_MENU(wxID_ABOUT, ctMainFrame::OnAbout)
EVT_MENU(wxID_OPEN, ctMainFrame::OnOpen)
EVT_MENU(wxID_NEW, ctMainFrame::OnNew)
EVT_MENU(wxID_EXIT, ctMainFrame::OnExit)
EVT_MENU(ctID_SETTINGS, ctMainFrame::OnSettings)
EVT_MENU(ctID_SHOW_TOOLBAR, ctMainFrame::OnShowToolbar)
EVT_MENU(wxID_HELP, ctMainFrame::OnHelp)
EVT_MENU(ctID_REFERENCE_CONTENTS, ctMainFrame::OnReferenceHelp)
EVT_MENU(wxID_HELP_CONTEXT, ctMainFrame::OnContextHelp)
EVT_UPDATE_UI(ctID_ADD_ITEM_CHECKBOX, ctMainFrame::OnUpdateDisable)
EVT_UPDATE_UI(ctID_ADD_ITEM_RADIOBUTTON, ctMainFrame::OnUpdateDisable)
EVT_UPDATE_UI(ctID_ADD_ITEM_GROUP, ctMainFrame::OnUpdateDisable)
EVT_UPDATE_UI(ctID_ADD_ITEM_CHECK_GROUP, ctMainFrame::OnUpdateDisable)
EVT_UPDATE_UI(ctID_ADD_ITEM_RADIO_GROUP, ctMainFrame::OnUpdateDisable)
EVT_UPDATE_UI(ctID_ADD_ITEM_STRING, ctMainFrame::OnUpdateDisable)
EVT_UPDATE_UI(ctID_DELETE_ITEM, ctMainFrame::OnUpdateDisable)
EVT_UPDATE_UI(ctID_RENAME_ITEM, ctMainFrame::OnUpdateDisable)
EVT_UPDATE_UI(wxID_COPY, ctMainFrame::OnUpdateDisable)
EVT_UPDATE_UI(wxID_CUT, ctMainFrame::OnUpdateDisable)
EVT_UPDATE_UI(wxID_PASTE, ctMainFrame::OnUpdateDisable)
EVT_UPDATE_UI(ctID_ITEM_HELP, ctMainFrame::OnUpdateDisable)
EVT_UPDATE_UI(ctID_ADD_CUSTOM_PROPERTY, ctMainFrame::OnUpdateDisable)
EVT_UPDATE_UI(ctID_EDIT_CUSTOM_PROPERTY, ctMainFrame::OnUpdateDisable)
EVT_UPDATE_UI(ctID_DELETE_CUSTOM_PROPERTY, ctMainFrame::OnUpdateDisable)
EVT_UPDATE_UI(ctID_SAVE_SETUP_FILE, ctMainFrame::OnUpdateDisable)
EVT_UPDATE_UI(ctID_SAVE_CONFIGURE_COMMAND, ctMainFrame::OnUpdateDisable)
EVT_UPDATE_UI(wxID_FIND, ctMainFrame::OnUpdateDisable)
EVT_UPDATE_UI(ctID_GO, ctMainFrame::OnUpdateDisable)
END_EVENT_TABLE()
// Define my frame constructor
ctMainFrame::ctMainFrame(wxDocManager *manager, wxFrame *parent, wxWindowID id, const wxString& title, const wxPoint& pos, const wxSize& size, long style):
wxDocParentFrame(manager, parent, id, title, pos, size, style)
{
m_document = NULL;
m_editMenu = NULL;
m_configurePage = NULL;
m_setupPage = NULL;
#ifdef USE_CONFIG_BROWSER_PAGE
m_configBrowserPage = NULL;
#endif
m_mainNotebook = NULL;
m_findDialog = NULL;
m_treeSplitterWindow = new wxSplitterWindow(this, wxID_ANY, wxDefaultPosition, wxSize(400, 300),
wxSP_3DSASH|wxSP_3DBORDER|wxNO_FULL_REPAINT_ON_RESIZE|wxCLIP_CHILDREN|wxSP_NO_XP_THEME);
m_configTreeCtrl = new ctConfigTreeCtrl(m_treeSplitterWindow, wxID_ANY, wxDefaultPosition, wxDefaultSize,
wxTR_HAS_BUTTONS|wxNO_BORDER|wxNO_FULL_REPAINT_ON_RESIZE|wxCLIP_CHILDREN);
m_mainNotebook = new wxNotebook(m_treeSplitterWindow, wxID_ANY, wxDefaultPosition, wxSize(300, 300),
wxNO_FULL_REPAINT_ON_RESIZE|wxCLIP_CHILDREN);
m_propertyEditor = new ctPropertyEditor(m_mainNotebook, wxID_ANY, wxDefaultPosition, wxSize(300, 200),
wxNO_BORDER|wxNO_FULL_REPAINT_ON_RESIZE|wxCLIP_CHILDREN);
m_setupPage = new ctOutputWindow(m_mainNotebook, wxID_ANY, wxDefaultPosition, wxSize(300, 200),
wxNO_BORDER|wxNO_FULL_REPAINT_ON_RESIZE|wxCLIP_CHILDREN);
m_configurePage = new ctOutputWindow(m_mainNotebook, wxID_ANY, wxDefaultPosition, wxSize(300, 200),
wxNO_BORDER|wxNO_FULL_REPAINT_ON_RESIZE|wxCLIP_CHILDREN);
#ifdef USE_CONFIG_BROWSER_PAGE
m_configBrowserPage = new ctConfigurationBrowserWindow(m_mainNotebook, wxID_ANY, wxDefaultPosition, wxSize(300, 200),
wxNO_BORDER|wxNO_FULL_REPAINT_ON_RESIZE|wxCLIP_CHILDREN);
#endif
m_mainNotebook->AddPage(m_propertyEditor, _T("Properties"));
#ifdef USE_CONFIG_BROWSER_PAGE
m_mainNotebook->AddPage(m_configBrowserPage, _T("Configuration Browser"));
#endif
m_mainNotebook->AddPage(m_setupPage, _T("setup.h"));
m_mainNotebook->AddPage(m_configurePage, _T("configure"));
// Need to do this afterwards since wxWin sets the XP background
// in AddPage
m_propertyEditor->GetDescriptionWindow()->SetBackgroundColour(ctDESCRIPTION_BACKGROUND_COLOUR);
int sashPos = wxGetApp().GetSettings().m_mainSashSize;
m_treeSplitterWindow->SplitVertically(m_configTreeCtrl, m_mainNotebook, sashPos);
SetIcon(wxIcon(wxconfigtool_xpm));
#if wxUSE_STATUSBAR
CreateStatusBar(2);
#endif // wxUSE_STATUSBAR
wxMenuBar* menuBar = CreateMenuBar();
SetMenuBar(menuBar);
CreateToolBar(wxNO_BORDER|wxTB_FLAT|wxTB_HORIZONTAL|wxNO_FULL_REPAINT_ON_RESIZE|wxCLIP_CHILDREN);
InitToolBar(GetToolBar());
if (wxGetApp().GetSettings().m_showToolBar)
{
menuBar->Check(ctID_SHOW_TOOLBAR, true);
}
else
{
menuBar->Check(ctID_SHOW_TOOLBAR, false);
GetToolBar()->Show(false);
ResizeFrame();
}
}
void ctMainFrame::OnCloseWindow(wxCloseEvent& event)
{
if (GetDocument())
{
if (!GetDocument()->DeleteAllViews() && event.CanVeto())
{
event.Veto();
return;
}
}
if (m_findDialog)
{
m_findDialog->Destroy();
m_findDialog = NULL;
}
Show(false);
if (IsMaximized())
wxGetApp().GetSettings().m_frameStatus = ctSHOW_STATUS_MAXIMIZED ;
else if (IsIconized())
wxGetApp().GetSettings().m_frameStatus = ctSHOW_STATUS_MINIMIZED ;
else
wxGetApp().GetSettings().m_frameStatus = ctSHOW_STATUS_NORMAL ;
// Must delete this now since the DLL loading library will be
// uninitialised by the time the app object is deleted
wxGetApp().ClearHelpControllers();
if (!IsMaximized() && !IsIconized())
{
wxGetApp().GetSettings().m_frameSize = GetRect();
wxGetApp().GetSettings().m_mainSashSize = m_treeSplitterWindow->GetSashPosition();
}
Destroy();
}
void ctMainFrame::OnAbout(wxCommandEvent& WXUNUSED(event))
{
wxString msg = wxGetApp().GetSettings().GetAppName() + wxT(" (c) Julian Smart");
wxString caption = wxT("About ") + wxGetApp().GetSettings().GetAppName();
wxMessageBox(msg, caption, wxOK|wxICON_INFORMATION);
}
void ctMainFrame::OnOpen(wxCommandEvent& event)
{
wxGetApp().GetDocManager()->OnFileOpen(event);
}
void ctMainFrame::OnNew(wxCommandEvent& event)
{
wxGetApp().GetDocManager()->OnFileNew(event);
}
void ctMainFrame::OnExit(wxCommandEvent& WXUNUSED(event))
{
Close();
}
void ctMainFrame::OnSettings(wxCommandEvent& WXUNUSED(event))
{
wxGetApp().GetSettings().ShowSettingsDialog();
}
void ctMainFrame::InitToolBar(wxToolBar* toolBar)
{
toolBar->SetHelpText(wxT("The toolbar gives you easy access to commonly used commands."));
// Set up toolbar
wxBitmap toolBarBitmaps[20];
toolBarBitmaps[0] = wxBitmap(new_xpm);
toolBarBitmaps[1] = wxBitmap(open_xpm);
toolBarBitmaps[2] = wxBitmap(save_xpm);
toolBarBitmaps[3] = wxBitmap(copy_xpm);
toolBarBitmaps[4] = wxBitmap(cut_xpm);
toolBarBitmaps[5] = wxBitmap(paste_xpm);
toolBarBitmaps[6] = wxBitmap(go_xpm);
toolBarBitmaps[7] = wxBitmap(help_xpm);
toolBarBitmaps[10] = wxBitmap(undo_xpm);
toolBarBitmaps[11] = wxBitmap(redo_xpm);
toolBarBitmaps[12] = wxBitmap(help_xpm);
toolBarBitmaps[13] = wxBitmap(helpcs_xpm);
toolBar->AddTool(wxID_NEW, toolBarBitmaps[0], wxNullBitmap, false, wxDefaultCoord, wxDefaultCoord, (wxObject *) NULL, wxT("New project"));
toolBar->AddTool(wxID_OPEN, toolBarBitmaps[1], wxNullBitmap, false, wxDefaultCoord, wxDefaultCoord, (wxObject *) NULL, wxT("Open project"));
toolBar->AddTool(wxID_SAVE, toolBarBitmaps[2], wxNullBitmap, false, wxDefaultCoord, wxDefaultCoord, (wxObject *) NULL, wxT("Save project"));
toolBar->AddSeparator();
toolBar->AddTool(wxID_CUT, toolBarBitmaps[4], wxNullBitmap, false, wxDefaultCoord, wxDefaultCoord, (wxObject *) NULL, wxGetStockLabel(wxID_CUT, false));
toolBar->AddTool(wxID_COPY, toolBarBitmaps[3], wxNullBitmap, false, wxDefaultCoord, wxDefaultCoord, (wxObject *) NULL, wxGetStockLabel(wxID_COPY, false));
toolBar->AddTool(wxID_PASTE, toolBarBitmaps[5], wxNullBitmap, false, wxDefaultCoord, wxDefaultCoord, (wxObject *) NULL, wxGetStockLabel(wxID_PASTE, false));
toolBar->AddSeparator();
toolBar->AddTool(wxID_UNDO, toolBarBitmaps[10], wxNullBitmap, false, wxDefaultCoord, wxDefaultCoord, (wxObject *) NULL, wxGetStockLabel(wxID_UNDO, false));
toolBar->AddTool(wxID_REDO, toolBarBitmaps[11], wxNullBitmap, false, wxDefaultCoord, wxDefaultCoord, (wxObject *) NULL, wxGetStockLabel(wxID_REDO, false));
toolBar->AddSeparator();
toolBar->AddTool(ctID_GO, toolBarBitmaps[6], wxNullBitmap, false, wxDefaultCoord, wxDefaultCoord, (wxObject *) NULL, wxT("Save setup.h or configurewx.sh"));
toolBar->AddSeparator();
toolBar->AddTool(ctID_ITEM_HELP, toolBarBitmaps[12], wxNullBitmap, false, wxDefaultCoord, wxDefaultCoord, (wxObject *) NULL, wxT("Show help for this option"));
toolBar->AddTool(wxID_HELP_CONTEXT, toolBarBitmaps[13], wxNullBitmap, false, wxDefaultCoord, wxDefaultCoord, (wxObject *) NULL, wxT("Show help on the clicked item"));
// after adding the buttons to the toolbar, must call Realize() to reflect
// the changes
toolBar->Realize();
}
wxMenuBar* ctMainFrame::CreateMenuBar()
{
// Make a menubar
wxMenu *fileMenu = new wxMenu;
wxGetApp().GetFileHistory().UseMenu(fileMenu);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -