⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mainframe.cpp

📁 Wxpython Implemented on Windows CE, Source code
💻 CPP
📖 第 1 页 / 共 2 页
字号:
    fileMenu->Append(wxID_NEW, wxGetStockLabel(wxID_NEW, true, wxT("Ctrl+N")), wxT("Create a new settings document"));
    fileMenu->Append(wxID_OPEN, wxGetStockLabel(wxID_OPEN, true, wxT("Ctrl+O")), wxT("Open a settings document"));
    fileMenu->Append(wxID_CLOSE, wxGetStockLabel(wxID_CLOSE, true, wxT("Ctrl+W")), wxT("Close the current settings document"));
    fileMenu->AppendSeparator();
    fileMenu->Append(wxID_SAVE, wxGetStockLabel(wxID_SAVE, true, wxT("Ctrl+S")), wxT("Save the settings document"));
    fileMenu->Append(wxID_SAVEAS, wxGetStockLabel(wxID_SAVEAS), wxT("Save the settings document under a new filename"));
    fileMenu->AppendSeparator();
    fileMenu->Append(ctID_SAVE_SETUP_FILE, wxT("Save Setup.&h...\tCtrl+H"), wxT("Save the setup.h file"));
    fileMenu->Append(ctID_SAVE_CONFIGURE_COMMAND, wxT("Save Configure Script...\tCtrl+G"), wxT("Save the configure script file"));
    fileMenu->AppendSeparator();
    fileMenu->Append(ctID_GO, wxT("&Go\tF5"), wxT("Quick-save the setup.h or configure.sh file"));
    fileMenu->AppendSeparator();
    fileMenu->Append(wxID_EXIT, wxGetStockLabel(wxID_EXIT, true, wxT("Alt+F4")), wxT("Exit the application"));

    wxGetApp().GetDocManager()->FileHistoryUseMenu(fileMenu);

    wxMenu *editMenu = new wxMenu;

    editMenu->Append(wxID_UNDO, wxGetStockLabel(wxID_UNDO, true, wxT("Ctrl+Z")));
    editMenu->Append(wxID_REDO, wxGetStockLabel(wxID_REDO, true, wxT("Ctrl+Y")));
    editMenu->AppendSeparator();
    editMenu->Append(wxID_COPY, wxGetStockLabel(wxID_CLOSE, true, wxT("Ctrl+C")));
    editMenu->Append(wxID_CUT, wxGetStockLabel(wxID_CUT, true, wxT("Ctrl+X")));
    editMenu->Append(wxID_PASTE, wxGetStockLabel(wxID_PASTE, true, wxT("Ctrl+V")));
    editMenu->AppendSeparator();

    wxMenu* itemMenu = new wxMenu;
    itemMenu->Append(ctID_ADD_ITEM_CHECKBOX, _("Add &Checkbox Option"), _("Add a checkbox configuration option"));
    itemMenu->Append(ctID_ADD_ITEM_RADIOBUTTON, _("Add &Radio Button Option"), _("Add a radio button configuration option"));
// TODO. However we can also simply use custom properties;
// but then the C++ code has to be special-cased.
//    itemMenu->Append(ctID_ADD_ITEM_STRING, _("Add &String Option"), _("Add a string configuration option"));
    itemMenu->Append(ctID_ADD_ITEM_GROUP, _("Add &Group Option"), _("Add a group configuration option"));
    itemMenu->Append(ctID_ADD_ITEM_CHECK_GROUP, _("Add Chec&k Group Option"), _("Add a check group configuration option"));
    itemMenu->Append(ctID_ADD_ITEM_RADIO_GROUP, _("Add Rad&io Group Option"), _("Add a radio group configuration option"));

    editMenu->Append(ctID_ADD_ITEM, wxT("Add &Option"), itemMenu, _("Add a configuration option"));
    editMenu->AppendSeparator();

    wxMenu* propertyMenu = new wxMenu;
    propertyMenu->Append(ctID_ADD_CUSTOM_PROPERTY, _("&Add Custom Property"), _("Adds a custom property to the current option"));
    propertyMenu->Append(ctID_EDIT_CUSTOM_PROPERTY, _("&Edit Custom Property"), _("Edits the currently selected custom property"));
    propertyMenu->Append(ctID_DELETE_CUSTOM_PROPERTY, _("&Delete Custom Property"), _("Deletes the currently selected custom property"));
    editMenu->Append(ctID_CUSTOM_PROPERTY, _("Custom P&roperty"), propertyMenu, _("Custom property commands"));

    editMenu->AppendSeparator();
    editMenu->Append(ctID_DELETE_ITEM, _("&Delete Option"), _("Delete a configuration option"));
    editMenu->Append(ctID_RENAME_ITEM, _("&Rename Option"), _("Rename a configuration option"));
    editMenu->AppendSeparator();
    editMenu->Append(wxID_FIND, wxGetStockLabel(wxID_FIND, true, wxT("Ctrl+F")), _("Search for a string in the settings document"));

    // Save for the command processor.
    m_editMenu = editMenu;

    wxMenu *viewMenu = new wxMenu;
    viewMenu->Append(ctID_SHOW_TOOLBAR, wxT("Show &Toolbar"), wxT("Toggle the toolbar on and off"),
        wxITEM_CHECK);
    viewMenu->Append(ctID_SETTINGS, wxT("&Settings...\tCtrl+T"), wxT("Show application settings"));

    wxMenu *helpMenu = new wxMenu;
    helpMenu->Append(wxID_HELP, wxT("&Help Contents"), wxT("Show Configuration Tool help"));
    helpMenu->Append(ctID_REFERENCE_CONTENTS, wxT("&wxWidgets Help Contents"), wxT("Show wxWidgets reference"));
    helpMenu->AppendSeparator();
    helpMenu->Append(ctID_ITEM_HELP, wxT("&Configuration Option Help\tF1"), wxT("Show help for the selected option"));
    helpMenu->Append(wxID_HELP_CONTEXT, wxT("&What's this?"), wxT("Show help on the clicked item"));
    helpMenu->AppendSeparator();
    helpMenu->Append(wxID_ABOUT, wxT("&About..."), wxT("Show details about this application"));

    wxMenuBar *menuBar = new wxMenuBar;

    menuBar->Append(fileMenu, wxT("&File"));
    menuBar->Append(editMenu, wxT("&Edit"));
    menuBar->Append(viewMenu, wxT("&View"));
    menuBar->Append(helpMenu, wxT("&Help"));

    {
        wxConfig config(wxGetApp().GetSettings().GetAppName(), wxT("wxWidgets"));
        config.SetPath(wxT("FileHistory/"));
        wxGetApp().GetDocManager()->FileHistoryLoad(config);
    }

    return menuBar;
}

/// Handles the Show Toolbar menu event.
void ctMainFrame::OnShowToolbar(wxCommandEvent& WXUNUSED(event))
{
    wxGetApp().GetSettings().m_showToolBar = !wxGetApp().GetSettings().m_showToolBar;
    GetToolBar()->Show(wxGetApp().GetSettings().m_showToolBar);
    ResizeFrame();
}

/// Handles the Help Contents menu event.
void ctMainFrame::OnHelp(wxCommandEvent& WXUNUSED(event))
{
    wxGetApp().GetHelpController().DisplayContents();
}

/// Handles context help
void ctMainFrame::OnContextHelp(wxCommandEvent& WXUNUSED(event))
{
    wxContextHelp contextHelp;
}

/// Handles the Help Contents menu event for the reference manual.
void ctMainFrame::OnReferenceHelp(wxCommandEvent& WXUNUSED(event))
{
    wxGetApp().GetReferenceHelpController().DisplayContents();
}

/// Resizes the main frame according to the
/// state of the toolbar
void ctMainFrame::ResizeFrame()
{
    PositionToolBar();
    wxSizeEvent event(GetSize(), GetId());
    this->ProcessEvent(event);
}

/// Update the frame title.
void ctMainFrame::UpdateFrameTitle()
{
    // TODO
}

// General disabler
void ctMainFrame::OnUpdateDisable(wxUpdateUIEvent& event)
{
    event.Enable( false );
}

/*!
 * ctOutputWindow represents a page showing a setup.h file or config command.
 */

IMPLEMENT_CLASS(ctOutputWindow, wxPanel)

BEGIN_EVENT_TABLE(ctOutputWindow, wxPanel)
#if wxUSE_CLIPBOARD
    EVT_BUTTON(wxID_COPY, ctOutputWindow::OnCopyToClipboard)
#endif // wxUSE_CLIPBOARD
    EVT_BUTTON(wxID_SAVE, ctOutputWindow::OnSaveText)
    EVT_BUTTON(ctID_REGENERATE, ctOutputWindow::OnRegenerate)
    EVT_UPDATE_UI(wxID_SAVE, ctOutputWindow::OnUpdateSaveText)
    EVT_UPDATE_UI(ctID_REGENERATE, ctOutputWindow::OnUpdateRegenerate)
    EVT_UPDATE_UI(wxID_COPY, ctOutputWindow::OnUpdateCopy)
END_EVENT_TABLE()

ctOutputWindow::ctOutputWindow(wxWindow* parent, wxWindowID id,
                                                   const wxPoint& pos, const wxSize& size, long style):
    wxPanel(parent, id, pos, size, style)
{
    m_codeCtrl = NULL;
    m_filenameCtrl = NULL;
    m_doc = NULL;
    CreateWindows();
}

/// Initialise the windows.
void ctOutputWindow::CreateWindows()
{
    wxBoxSizer *item0 = new wxBoxSizer( wxVERTICAL );

    wxBoxSizer *item2 = new wxBoxSizer( wxHORIZONTAL );
    item0->Add( item2, 0, wxGROW|wxALIGN_CENTER_VERTICAL, 5 );

    wxButton *item4 = new wxButton( this, wxID_COPY, _("&Copy"), wxDefaultPosition, wxDefaultSize, 0 );
    item2->Add( item4, 0, wxGROW|wxALIGN_CENTER_VERTICAL|wxLEFT|wxTOP|wxBOTTOM|wxRIGHT, 5 );
    item4->SetHelpText(_("Copies the selection or whole file to the clipboard."));

    wxButton *item5 = new wxButton( this, ctID_REGENERATE, _("Re&generate"), wxDefaultPosition, wxDefaultSize, 0 );
    item2->Add( item5, 0, wxGROW|wxALIGN_CENTER_VERTICAL|wxTOP|wxBOTTOM|wxRIGHT, 5 );
    item5->SetHelpText(_("Regenerates the code."));

#if 0
    m_filenameCtrl = new wxTextCtrl(this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxSUNKEN_BORDER|wxTE_READONLY);
    item2->Add( m_filenameCtrl, 1, wxGROW|wxALIGN_CENTER_VERTICAL|wxTOP|wxBOTTOM|wxRIGHT, 5 );
    m_filenameCtrl->SetHelpText(_("Shows the filename where the code is being saved."));
#else
    m_filenameCtrl = NULL;
#endif

    // The code editor
    m_codeCtrl = new wxTextCtrl(this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxSize(100, 100), wxTE_RICH|wxTE_MULTILINE|wxSUNKEN_BORDER);
    item0->Add( m_codeCtrl, 1, wxGROW|wxALIGN_CENTER_VERTICAL|wxLEFT|wxRIGHT|wxBOTTOM, 5 );

    SetAutoLayout( true );
    SetSizer( item0 );
}

#if wxUSE_CLIPBOARD
/// Copies the text to the clipboard.
void ctOutputWindow::OnCopyToClipboard(wxCommandEvent& WXUNUSED(event))
{
    // Try to copy the selection first
    long int selFrom, selTo;
    m_codeCtrl->GetSelection(& selFrom, & selTo);
    if (selFrom != selTo)
    {
        m_codeCtrl->Copy();
        return;
    }

    // Copy the whole amount
    if (!wxTheClipboard->Open())
    {
        wxMessageBox(_("Sorry, could not open the clipboard."), _("Clipboard problem"), wxICON_EXCLAMATION|wxOK);
        return;
    }

    wxString value(m_codeCtrl->GetValue());
#ifdef __WXMSW__
    value.Replace(_T("\n"), _T("\r\n"));
#endif
    wxTextDataObject *data = new wxTextDataObject( value );

    if (!wxTheClipboard->SetData( data ))
    {
        wxTheClipboard->Close();
        wxMessageBox(_("Sorry, could not copy to the clipboard."), _("Clipboard problem"), wxICON_EXCLAMATION|wxOK);
    }
    else
    {
        wxTheClipboard->Close();
    }
}
#endif // wxUSE_CLIPBOARD

/// Sets the code in the text control.
void ctOutputWindow::SetText(const wxString& text)
{
    if (m_codeCtrl)
        m_codeCtrl->SetValue(text);
}

/// Sets the filename.
void ctOutputWindow::SetFilename(const wxString& filename)
{
    if (m_filenameCtrl)
        m_filenameCtrl->SetValue(filename);
}

/// Saves the file.
void ctOutputWindow::OnSaveText(wxCommandEvent& WXUNUSED(event))
{
    if (m_codeCtrl->IsModified())
    {
        wxString filename(m_filenameCtrl->GetValue());
        if (!filename.empty())
        {
            m_codeCtrl->SaveFile(filename);
            m_codeCtrl->DiscardEdits();
        }
    }
}

void ctOutputWindow::OnUpdateSaveText(wxUpdateUIEvent& event)
{
    event.Enable(m_doc && m_codeCtrl && m_codeCtrl->IsModified());
}

void ctOutputWindow::OnRegenerate(wxCommandEvent& WXUNUSED(event))
{
    if (m_doc)
    {
        ctConfigToolView* view = (ctConfigToolView*) m_doc->GetFirstView();
        view->RegenerateSetup();
    }
}

void ctOutputWindow::OnUpdateRegenerate(wxUpdateUIEvent& event)
{
    event.Enable( m_doc != NULL );
}

void ctOutputWindow::OnUpdateCopy(wxUpdateUIEvent& event)
{
    event.Enable( m_doc != NULL );
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -