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

📄 scintillawx.cpp

📁 wxGTK 是 wxWidgets 的 linux GTK+ (>2.2.3)版本。wxWidgets 是一个跨平台的 GUI 框架
💻 CPP
📖 第 1 页 / 共 3 页
字号:
const int H_SCROLL_STEP = 20;bool ScintillaWX::ModifyScrollBars(int nMax, int nPage) {    bool modified = false;    int vertEnd = nMax;    if (!verticalScrollBarVisible)        vertEnd = 0;    // Check the vertical scrollbar    if (stc->m_vScrollBar == NULL) {  // Use built-in scrollbar        int  sbMax    = stc->GetScrollRange(wxVERTICAL);        int  sbThumb  = stc->GetScrollThumb(wxVERTICAL);        int  sbPos    = stc->GetScrollPos(wxVERTICAL);        if (sbMax != vertEnd || sbThumb != nPage) {            stc->SetScrollbar(wxVERTICAL, sbPos, nPage, vertEnd+1);            modified = true;        }    }    else { // otherwise use the one that's been given to us        int  sbMax    = stc->m_vScrollBar->GetRange();        int  sbPage   = stc->m_vScrollBar->GetPageSize();        int  sbPos    = stc->m_vScrollBar->GetThumbPosition();        if (sbMax != vertEnd || sbPage != nPage) {            stc->m_vScrollBar->SetScrollbar(sbPos, nPage, vertEnd+1, nPage);            modified = true;        }    }    // Check the horizontal scrollbar    PRectangle rcText = GetTextRectangle();    int horizEnd = scrollWidth;    if (horizEnd < 0)        horizEnd = 0;    if (!horizontalScrollBarVisible || (wrapState != eWrapNone))        horizEnd = 0;    int pageWidth = rcText.Width();    if (stc->m_hScrollBar == NULL) {  // Use built-in scrollbar        int sbMax    = stc->GetScrollRange(wxHORIZONTAL);        int sbThumb  = stc->GetScrollThumb(wxHORIZONTAL);        int sbPos    = stc->GetScrollPos(wxHORIZONTAL);        if ((sbMax != horizEnd) || (sbThumb != pageWidth) || (sbPos != 0)) {            stc->SetScrollbar(wxHORIZONTAL, sbPos, pageWidth, horizEnd);            modified = true;            if (scrollWidth < pageWidth) {                HorizontalScrollTo(0);            }        }    }    else { // otherwise use the one that's been given to us        int sbMax    = stc->m_hScrollBar->GetRange();        int sbThumb  = stc->m_hScrollBar->GetPageSize();        int sbPos    = stc->m_hScrollBar->GetThumbPosition();        if ((sbMax != horizEnd) || (sbThumb != pageWidth) || (sbPos != 0)) {            stc->m_hScrollBar->SetScrollbar(sbPos, pageWidth, horizEnd, pageWidth);            modified = true;            if (scrollWidth < pageWidth) {                HorizontalScrollTo(0);            }        }    }    return modified;}void ScintillaWX::NotifyChange() {    stc->NotifyChange();}void ScintillaWX::NotifyParent(SCNotification scn) {    stc->NotifyParent(&scn);}// This method is overloaded from ScintillaBase in order to prevent the// AutoComplete window from being destroyed when it gets the focus.  There is// a side effect that the AutoComp will also not be destroyed when switching// to another window, but I think that is okay.void ScintillaWX::CancelModes() {    if (! focusEvent)        AutoCompleteCancel();    ct.CallTipCancel();    Editor::CancelModes();}void ScintillaWX::Copy() {    if (currentPos != anchor) {        SelectionText st;        CopySelectionRange(&st);        CopyToClipboard(st);    }}void ScintillaWX::Paste() {    pdoc->BeginUndoAction();    ClearSelection();#if wxUSE_DATAOBJ    wxTextDataObject data;    bool gotData = false;    if (wxTheClipboard->Open()) {        wxTheClipboard->UsePrimarySelection(false);        gotData = wxTheClipboard->GetData(data);        wxTheClipboard->Close();    }    if (gotData) {        wxString   text = wxTextBuffer::Translate(data.GetText(),                                                  wxConvertEOLMode(pdoc->eolMode));        wxWX2MBbuf buf = (wxWX2MBbuf)wx2stc(text);#if wxUSE_UNICODE        // free up the old character buffer in case the text is real big        data.SetText(wxEmptyString);         text = wxEmptyString;#endif        int len = strlen(buf);        pdoc->InsertString(currentPos, buf, len);        SetEmptySelection(currentPos + len);    }#endif // wxUSE_DATAOBJ    pdoc->EndUndoAction();    NotifyChange();    Redraw();}void ScintillaWX::CopyToClipboard(const SelectionText& st) {#if wxUSE_CLIPBOARD    if (wxTheClipboard->Open()) {        wxTheClipboard->UsePrimarySelection(false);        wxString text = wxTextBuffer::Translate(stc2wx(st.s, st.len-1));        wxTheClipboard->SetData(new wxTextDataObject(text));        wxTheClipboard->Close();    }#else    wxUnusedVar(st);#endif // wxUSE_CLIPBOARD}bool ScintillaWX::CanPaste() {#if wxUSE_CLIPBOARD    bool canPaste = false;    bool didOpen;    if (Editor::CanPaste()) {        didOpen = !wxTheClipboard->IsOpened();        if ( didOpen )            wxTheClipboard->Open();        if (wxTheClipboard->IsOpened()) {            wxTheClipboard->UsePrimarySelection(false);            canPaste = wxTheClipboard->IsSupported(wxUSE_UNICODE ? wxDF_UNICODETEXT : wxDF_TEXT);            if (didOpen)                wxTheClipboard->Close();        }    }    return canPaste;#else    return false;#endif // wxUSE_CLIPBOARD}void ScintillaWX::CreateCallTipWindow(PRectangle) {    if (! ct.wCallTip.Created() ) {        ct.wCallTip = new wxSTCCallTip(stc, &ct, this);        ct.wDraw = ct.wCallTip;    }}void ScintillaWX::AddToPopUp(const char *label, int cmd, bool enabled) {    if (!label[0])        ((wxMenu*)popup.GetID())->AppendSeparator();    else        ((wxMenu*)popup.GetID())->Append(cmd, wxGetTranslation(stc2wx(label)));    if (!enabled)        ((wxMenu*)popup.GetID())->Enable(cmd, enabled);}// This is called by the Editor base class whenever something is selectedvoid ScintillaWX::ClaimSelection() {#if 0    // Until wxGTK is able to support using both the primary selection and the    // clipboard at the same time I think it causes more problems than it is    // worth to implement this method.  Selecting text should not clear the    // clipboard.  --Robin#ifdef __WXGTK__    // Put the selected text in the PRIMARY selection    if (currentPos != anchor) {        SelectionText st;        CopySelectionRange(&st);        if (wxTheClipboard->Open()) {            wxTheClipboard->UsePrimarySelection(true);            wxString text = stc2wx(st.s, st.len);            wxTheClipboard->SetData(new wxTextDataObject(text));            wxTheClipboard->UsePrimarySelection(false);            wxTheClipboard->Close();        }    }#endif#endif}void ScintillaWX::UpdateSystemCaret() {#ifdef __WXMSW__    if (hasFocus) {        if (HasCaretSizeChanged()) {            DestroySystemCaret();            CreateSystemCaret();        }        Point pos = LocationFromPosition(currentPos);        ::SetCaretPos(pos.x, pos.y);    }#endif}bool ScintillaWX::HasCaretSizeChanged() {#ifdef __WXMSW__    if (( (0 != vs.caretWidth) && (sysCaretWidth != vs.caretWidth) )        || (0 != vs.lineHeight) && (sysCaretHeight != vs.lineHeight)) {        return true;    }#endif    return false;}bool ScintillaWX::CreateSystemCaret() {#ifdef __WXMSW__    sysCaretWidth = vs.caretWidth;    if (0 == sysCaretWidth) {        sysCaretWidth = 1;    }    sysCaretHeight = vs.lineHeight;    int bitmapSize = (((sysCaretWidth + 15) & ~15) >> 3) * sysCaretHeight;    char *bits = new char[bitmapSize];    memset(bits, 0, bitmapSize);    sysCaretBitmap = ::CreateBitmap(sysCaretWidth, sysCaretHeight, 1,                                    1, reinterpret_cast<BYTE *>(bits));    delete [] bits;    BOOL retval = ::CreateCaret(GetHwndOf(stc), sysCaretBitmap,                                sysCaretWidth, sysCaretHeight);    ::ShowCaret(GetHwndOf(stc));    return retval != 0;#else    return false;#endif}bool ScintillaWX::DestroySystemCaret() {#ifdef __WXMSW__    ::HideCaret(GetHwndOf(stc));    BOOL retval = ::DestroyCaret();    if (sysCaretBitmap) {        ::DeleteObject(sysCaretBitmap);        sysCaretBitmap = 0;    }    return retval != 0;#else    return false;#endif}//----------------------------------------------------------------------long ScintillaWX::DefWndProc(unsigned int /*iMessage*/, unsigned long /*wParam*/, long /*lParam*/) {    return 0;}long ScintillaWX::WndProc(unsigned int iMessage, unsigned long wParam, long lParam) {      switch (iMessage) {      case SCI_CALLTIPSHOW: {          // NOTE: This is copied here from scintilla/src/ScintillaBase.cxx          // because of the little tweak that needs done below for wxGTK.          // When updating new versions double check that this is still          // needed, and that any new code there is copied here too.          Point pt = LocationFromPosition(wParam);          char* defn = reinterpret_cast<char *>(lParam);          AutoCompleteCancel();          pt.y += vs.lineHeight;          PRectangle rc = ct.CallTipStart(currentPos, pt,                                          defn,                                          vs.styles[STYLE_DEFAULT].fontName,                                          vs.styles[STYLE_DEFAULT].sizeZoomed,                                          CodePage(),                                          vs.styles[STYLE_DEFAULT].characterSet,                                          wMain);          // If the call-tip window would be out of the client          // space, adjust so it displays above the text.          PRectangle rcClient = GetClientRectangle();          if (rc.bottom > rcClient.bottom) {#ifdef __WXGTK__              int offset = int(vs.lineHeight * 1.25)  + rc.Height();#else              int offset = vs.lineHeight + rc.Height();#endif              rc.top -= offset;              rc.bottom -= offset;          }          // Now display the window.          CreateCallTipWindow(rc);          ct.wCallTip.SetPositionRelative(rc, wMain);          ct.wCallTip.Show();          break;      }#ifdef SCI_LEXER      case SCI_LOADLEXERLIBRARY:            LexerManager::GetInstance()->Load((const char*)lParam);            break;#endif      default:          return ScintillaBase::WndProc(iMessage, wParam, lParam);      }      return 0;}//----------------------------------------------------------------------// Event delegatesvoid ScintillaWX::DoPaint(wxDC* dc, wxRect rect) {    paintState = painting;    Surface* surfaceWindow = Surface::Allocate();    surfaceWindow->Init(dc, wMain.GetID());    rcPaint = PRectangleFromwxRect(rect);    PRectangle rcClient = GetClientRectangle();    paintingAllText = rcPaint.Contains(rcClient);    ClipChildren(*dc, rcPaint);    Paint(surfaceWindow, rcPaint);    delete surfaceWindow;    if (paintState == paintAbandoned) {        // Painting area was insufficient to cover new styling or brace        // highlight positions        FullPaint();    }    paintState = notPainting;}void ScintillaWX::DoHScroll(int type, int pos) {    int xPos = xOffset;    PRectangle rcText = GetTextRectangle();    int pageWidth = rcText.Width() * 2 / 3;    if (type == wxEVT_SCROLLWIN_LINEUP || type == wxEVT_SCROLL_LINEUP)        xPos -= H_SCROLL_STEP;    else if (type == wxEVT_SCROLLWIN_LINEDOWN || type == wxEVT_SCROLL_LINEDOWN)        xPos += H_SCROLL_STEP;    else if (type == wxEVT_SCROLLWIN_PAGEUP || type == wxEVT_SCROLL_PAGEUP)

⌨️ 快捷键说明

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