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

📄 stctest.cpp

📁 wxGTK 是 wxWidgets 的 linux GTK+ (>2.2.3)版本。wxWidgets 是一个跨平台的 GUI 框架
💻 CPP
📖 第 1 页 / 共 2 页
字号:
}void AppFrame::OnExit (wxCommandEvent &WXUNUSED(event)) {    Close (true);}// file event handlersvoid AppFrame::OnFileOpen (wxCommandEvent &WXUNUSED(event)) {    if (!m_edit) return;#if wxUSE_FILEDLG    wxString fname;    wxFileDialog dlg (this, _T("Open file"), wxEmptyString, wxEmptyString, _T("Any file (*)|*"),                      wxFD_OPEN | wxFD_FILE_MUST_EXIST | wxFD_CHANGE_DIR);    if (dlg.ShowModal() != wxID_OK) return;    fname = dlg.GetPath ();    FileOpen (fname);#endif // wxUSE_FILEDLG}void AppFrame::OnFileSave (wxCommandEvent &WXUNUSED(event)) {    if (!m_edit) return;    if (!m_edit->Modified()) {        wxMessageBox (_("There is nothing to save!"), _("Save file"),                      wxOK | wxICON_EXCLAMATION);        return;    }    m_edit->SaveFile ();}void AppFrame::OnFileSaveAs (wxCommandEvent &WXUNUSED(event)) {    if (!m_edit) return;#if wxUSE_FILEDLG    wxString filename = wxEmptyString;    wxFileDialog dlg (this, _T("Save file"), wxEmptyString, wxEmptyString, _T("Any file (*)|*"), wxFD_SAVE|wxFD_OVERWRITE_PROMPT);    if (dlg.ShowModal() != wxID_OK) return;    filename = dlg.GetPath();    m_edit->SaveFile (filename);#endif // wxUSE_FILEDLG}void AppFrame::OnFileClose (wxCommandEvent &WXUNUSED(event)) {    if (!m_edit) return;    if (m_edit->Modified()) {        if (wxMessageBox (_("Text is not saved, save before closing?"), _("Close"),                          wxYES_NO | wxICON_QUESTION) == wxYES) {            m_edit->SaveFile();            if (m_edit->Modified()) {                wxMessageBox (_("Text could not be saved!"), _("Close abort"),                              wxOK | wxICON_EXCLAMATION);                return;            }        }    }    m_edit->SetFilename (wxEmptyString);    m_edit->ClearAll();    m_edit->SetSavePoint();}// properties event handlersvoid AppFrame::OnProperties (wxCommandEvent &WXUNUSED(event)) {    if (!m_edit) return;    EditProperties dlg(m_edit, 0);}// print event handlersvoid AppFrame::OnPrintSetup (wxCommandEvent &WXUNUSED(event)) {#if wxUSE_PRINTING_ARCHITECTURE    (*g_pageSetupData) = * g_printData;    wxPageSetupDialog pageSetupDialog(this, g_pageSetupData);    pageSetupDialog.ShowModal();    (*g_printData) = pageSetupDialog.GetPageSetupData().GetPrintData();    (*g_pageSetupData) = pageSetupDialog.GetPageSetupData();#endif // wxUSE_PRINTING_ARCHITECTURE}void AppFrame::OnPrintPreview (wxCommandEvent &WXUNUSED(event)) {#if wxUSE_PRINTING_ARCHITECTURE    wxPrintDialogData printDialogData( *g_printData);    wxPrintPreview *preview =        new wxPrintPreview (new EditPrint (m_edit),                            new EditPrint (m_edit),                            &printDialogData);    if (!preview->Ok()) {        delete preview;        wxMessageBox (_("There was a problem with previewing.\n\                         Perhaps your current printer is not correctly?"),                      _("Previewing"), wxOK);        return;    }    wxRect rect = DeterminePrintSize();    wxPreviewFrame *frame = new wxPreviewFrame (preview, this, _("Print Preview"));    frame->SetSize (rect);    frame->Centre(wxBOTH);    frame->Initialize();    frame->Show(true);#endif // wxUSE_PRINTING_ARCHITECTURE}void AppFrame::OnPrint (wxCommandEvent &WXUNUSED(event)) {#if wxUSE_PRINTING_ARCHITECTURE    wxPrintDialogData printDialogData( *g_printData);    wxPrinter printer (&printDialogData);    EditPrint printout (m_edit);    if (!printer.Print (this, &printout, true)) {        if (wxPrinter::GetLastError() == wxPRINTER_ERROR) {        wxMessageBox (_("There was a problem with printing.\n\                         Perhaps your current printer is not correctly?"),                      _("Previewing"), wxOK);            return;        }    }    (*g_printData) = printer.GetPrintDialogData().GetPrintData();#endif // wxUSE_PRINTING_ARCHITECTURE}// edit eventsvoid AppFrame::OnEdit (wxCommandEvent &event) {    if (m_edit) m_edit->ProcessEvent (event);}// private functionsvoid AppFrame::CreateMenu (){    // File menu    wxMenu *menuFile = new wxMenu;    menuFile->Append (wxID_OPEN, _("&Open ..\tCtrl+O"));    menuFile->Append (wxID_SAVE, _("&Save\tCtrl+S"));    menuFile->Append (wxID_SAVEAS, _("Save &as ..\tCtrl+Shift+S"));    menuFile->Append (wxID_CLOSE, _("&Close\tCtrl+W"));    menuFile->AppendSeparator();    menuFile->Append (myID_PROPERTIES, _("Proper&ties ..\tCtrl+I"));    menuFile->AppendSeparator();    menuFile->Append (wxID_PRINT_SETUP, _("Print Set&up .."));    menuFile->Append (wxID_PREVIEW, _("Print Pre&view\tCtrl+Shift+P"));    menuFile->Append (wxID_PRINT, _("&Print ..\tCtrl+P"));    menuFile->AppendSeparator();    menuFile->Append (wxID_EXIT, _("&Quit\tCtrl+Q"));    // Edit menu    wxMenu *menuEdit = new wxMenu;    menuEdit->Append (wxID_UNDO, _("&Undo\tCtrl+Z"));    menuEdit->Append (wxID_REDO, _("&Redo\tCtrl+Shift+Z"));    menuEdit->AppendSeparator();    menuEdit->Append (wxID_CUT, _("Cu&t\tCtrl+X"));    menuEdit->Append (wxID_COPY, _("&Copy\tCtrl+C"));    menuEdit->Append (wxID_PASTE, _("&Paste\tCtrl+V"));    menuEdit->Append (wxID_CLEAR, _("&Delete\tDel"));    menuEdit->AppendSeparator();    menuEdit->Append (wxID_FIND, _("&Find\tCtrl+F"));    menuEdit->Enable (wxID_FIND, false);    menuEdit->Append (myID_FINDNEXT, _("Find &next\tF3"));    menuEdit->Enable (myID_FINDNEXT, false);    menuEdit->Append (myID_REPLACE, _("&Replace\tCtrl+H"));    menuEdit->Enable (myID_REPLACE, false);    menuEdit->Append (myID_REPLACENEXT, _("Replace &again\tShift+F4"));    menuEdit->Enable (myID_REPLACENEXT, false);    menuEdit->AppendSeparator();    menuEdit->Append (myID_BRACEMATCH, _("&Match brace\tCtrl+M"));    menuEdit->Append (myID_GOTO, _("&Goto\tCtrl+G"));    menuEdit->Enable (myID_GOTO, false);    menuEdit->AppendSeparator();    menuEdit->Append (myID_INDENTINC, _("&Indent increase\tTab"));    menuEdit->Append (myID_INDENTRED, _("I&ndent reduce\tBksp"));    menuEdit->AppendSeparator();    menuEdit->Append (wxID_SELECTALL, _("&Select all\tCtrl+A"));    menuEdit->Append (myID_SELECTLINE, _("Select &line\tCtrl+L"));    // hilight submenu    wxMenu *menuHilight = new wxMenu;    int Nr;    for (Nr = 0; Nr < g_LanguagePrefsSize; Nr++) {        menuHilight->Append (myID_HILIGHTFIRST + Nr,                             g_LanguagePrefs [Nr].name);    }    // charset submenu    wxMenu *menuCharset = new wxMenu;    menuCharset->Append (myID_CHARSETANSI, _("&ANSI (Windows)"));    menuCharset->Append (myID_CHARSETMAC, _("&MAC (Macintosh)"));    // View menu    wxMenu *menuView = new wxMenu;    menuView->Append (myID_HILIGHTLANG, _("&Hilight language .."), menuHilight);    menuView->AppendSeparator();    menuView->AppendCheckItem (myID_FOLDTOGGLE, _("&Toggle current fold\tCtrl+T"));    menuView->AppendCheckItem (myID_OVERTYPE, _("&Overwrite mode\tIns"));    menuView->AppendCheckItem (myID_WRAPMODEON, _("&Wrap mode\tCtrl+U"));    menuView->AppendSeparator();    menuView->AppendCheckItem (myID_DISPLAYEOL, _("Show line &endings"));    menuView->AppendCheckItem (myID_INDENTGUIDE, _("Show &indent guides"));    menuView->AppendCheckItem (myID_LINENUMBER, _("Show line &numbers"));    menuView->AppendCheckItem (myID_LONGLINEON, _("Show &long line marker"));    menuView->AppendCheckItem (myID_WHITESPACE, _("Show white&space"));    menuView->AppendSeparator();    menuView->Append (myID_USECHARSET, _("Use &code page of .."), menuCharset);    // change case submenu    wxMenu *menuChangeCase = new wxMenu;    menuChangeCase->Append (myID_CHANGEUPPER, _("&Upper case"));    menuChangeCase->Append (myID_CHANGELOWER, _("&Lower case"));    // convert EOL submenu    wxMenu *menuConvertEOL = new wxMenu;    menuConvertEOL->Append (myID_CONVERTCR, _("CR (&Linux)"));    menuConvertEOL->Append (myID_CONVERTCRLF, _("CR+LF (&Windows)"));    menuConvertEOL->Append (myID_CONVERTLF, _("LF (&Macintosh)"));    // Extra menu    wxMenu *menuExtra = new wxMenu;    menuExtra->AppendCheckItem (myID_READONLY, _("&Readonly mode"));    menuExtra->AppendSeparator();    menuExtra->Append (myID_CHANGECASE, _("Change &case to .."), menuChangeCase);    menuExtra->AppendSeparator();    menuExtra->Append (myID_CONVERTEOL, _("Convert line &endings to .."), menuConvertEOL);    // Window menu    wxMenu *menuWindow = new wxMenu;    menuWindow->Append (myID_PAGEPREV, _("&Previous\tCtrl+Shift+Tab"));    menuWindow->Append (myID_PAGENEXT, _("&Next\tCtrl+Tab"));    // Help menu    wxMenu *menuHelp = new wxMenu;    menuHelp->Append (wxID_ABOUT, _("&About ..\tShift+F1"));    // construct menu    m_menuBar->Append (menuFile, _("&File"));    m_menuBar->Append (menuEdit, _("&Edit"));    m_menuBar->Append (menuView, _("&View"));    m_menuBar->Append (menuExtra, _("E&xtra"));    m_menuBar->Append (menuWindow, _("&Window"));    m_menuBar->Append (menuHelp, _("&Help"));    SetMenuBar (m_menuBar);}void AppFrame::FileOpen (wxString fname){    wxFileName w(fname); w.Normalize(); fname = w.GetFullPath();    m_edit->LoadFile (fname);}wxRect AppFrame::DeterminePrintSize () {    wxSize scr = wxGetDisplaySize();    // determine position and size (shifting 16 left and down)    wxRect rect = GetRect();    rect.x += 16;    rect.y += 16;    rect.width = wxMin (rect.width, (scr.x - rect.x));    rect.height = wxMin (rect.height, (scr.x - rect.y));    return rect;}//----------------------------------------------------------------------------// AppAbout//----------------------------------------------------------------------------BEGIN_EVENT_TABLE (AppAbout, wxDialog)    EVT_TIMER (myID_ABOUTTIMER, AppAbout::OnTimerEvent)END_EVENT_TABLE ()AppAbout::AppAbout (wxWindow *parent,                    int milliseconds,                    long style)        : wxDialog (parent, wxID_ANY, wxEmptyString,                    wxDefaultPosition, wxDefaultSize,                    style | wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER) {    // set timer if any    m_timer = NULL;    if (milliseconds > 0) {        m_timer = new wxTimer (this, myID_ABOUTTIMER);        m_timer->Start (milliseconds, wxTIMER_ONE_SHOT);    }    // sets the application title    SetTitle (_("About .."));    // about info    wxGridSizer *aboutinfo = new wxGridSizer (2, 0, 2);    aboutinfo->Add (new wxStaticText(this, wxID_ANY, _("Written by: ")),                    0, wxALIGN_LEFT);    aboutinfo->Add (new wxStaticText(this, wxID_ANY, APP_MAINT),                    1, wxEXPAND | wxALIGN_LEFT);    aboutinfo->Add (new wxStaticText(this, wxID_ANY, _("Version: ")),                    0, wxALIGN_LEFT);    aboutinfo->Add (new wxStaticText(this, wxID_ANY, APP_VERSION),                    1, wxEXPAND | wxALIGN_LEFT);    aboutinfo->Add (new wxStaticText(this, wxID_ANY, _("Licence type: ")),                    0, wxALIGN_LEFT);    aboutinfo->Add (new wxStaticText(this, wxID_ANY, APP_LICENCE),                    1, wxEXPAND | wxALIGN_LEFT);    aboutinfo->Add (new wxStaticText(this, wxID_ANY, _("Copyright: ")),                    0, wxALIGN_LEFT);    aboutinfo->Add (new wxStaticText(this, wxID_ANY, APP_COPYRIGTH),                    1, wxEXPAND | wxALIGN_LEFT);    // about icontitle//info    wxBoxSizer *aboutpane = new wxBoxSizer (wxHORIZONTAL);    wxBitmap bitmap = wxBitmap(wxICON (mondrian));    aboutpane->Add (new wxStaticBitmap (this, wxID_ANY, bitmap),                    0, wxALIGN_LEFT|wxALIGN_CENTER_VERTICAL|wxLEFT|wxRIGHT, 20);    aboutpane->Add (aboutinfo, 1, wxEXPAND);    aboutpane->Add (60, 0);    // about complete    wxBoxSizer *totalpane = new wxBoxSizer (wxVERTICAL);    totalpane->Add (0, 20);    wxStaticText *appname = new wxStaticText(this, wxID_ANY, *g_appname);    appname->SetFont (wxFont (24, wxDEFAULT, wxNORMAL, wxBOLD));    totalpane->Add (appname, 0, wxALIGN_CENTER | wxLEFT | wxRIGHT, 40);    totalpane->Add (0, 10);    totalpane->Add (aboutpane, 0, wxEXPAND | wxALL, 4);    totalpane->Add (new wxStaticText(this, wxID_ANY, APP_DESCR),                    0, wxALIGN_CENTER | wxALL, 10);    wxButton *okButton = new wxButton (this, wxID_OK, _("OK"));    okButton->SetDefault();    totalpane->Add (okButton, 0, wxALIGN_CENTER | wxLEFT | wxRIGHT | wxBOTTOM, 10);    SetSizerAndFit (totalpane);    CenterOnScreen();    ShowModal();}AppAbout::~AppAbout () {    if (m_timer)  {        delete m_timer;        m_timer = NULL;    }}//----------------------------------------------------------------------------// event handlersvoid AppAbout::OnTimerEvent (wxTimerEvent &WXUNUSED(event)) {    if (m_timer) delete m_timer;    m_timer = NULL;    EndModal (wxID_OK);}

⌨️ 快捷键说明

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