X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/88a8b04e9c387b5e5295d42f2ed23afcf37e3c2e..d66c3960d541cf9e3ba10519a49a9e34b4ddfc81:/contrib/src/stc/ScintillaWX.cpp diff --git a/contrib/src/stc/ScintillaWX.cpp b/contrib/src/stc/ScintillaWX.cpp index f294cd6ba2..a324274b7c 100644 --- a/contrib/src/stc/ScintillaWX.cpp +++ b/contrib/src/stc/ScintillaWX.cpp @@ -19,6 +19,7 @@ #include "ExternalLexer.h" #include "wx/stc/stc.h" #include "PlatWX.h" +#include //---------------------------------------------------------------------- // Helper classes @@ -136,6 +137,7 @@ END_EVENT_TABLE() ScintillaWX::ScintillaWX(wxStyledTextCtrl* win) { capturedMouse = false; + focusEvent = false; wMain = win; stc = win; wheelRotation = 0; @@ -144,7 +146,7 @@ ScintillaWX::ScintillaWX(wxStyledTextCtrl* win) { ScintillaWX::~ScintillaWX() { - SetTicking(false); + Finalise(); } //---------------------------------------------------------------------- @@ -163,6 +165,8 @@ void ScintillaWX::Initialise() { void ScintillaWX::Finalise() { ScintillaBase::Finalise(); + SetTicking(false); + SetIdle(false); } @@ -197,6 +201,19 @@ void ScintillaWX::StartDrag() { } +bool ScintillaWX::SetIdle(bool on) { + if (idler.state != on) { + // connect or disconnect the EVT_IDLE handler + if (on) + stc->Connect(-1, wxEVT_IDLE, (wxObjectEventFunction)&wxStyledTextCtrl::OnIdle); + else + stc->Disconnect(-1, wxEVT_IDLE, (wxObjectEventFunction)&wxStyledTextCtrl::OnIdle); + idler.state = on; + } + return idler.state; +} + + void ScintillaWX::SetTicking(bool on) { wxSTCTimer* steTimer; if (timer.ticking != on) { @@ -217,11 +234,13 @@ void ScintillaWX::SetTicking(bool on) { void ScintillaWX::SetMouseCapture(bool on) { - if (on && !capturedMouse) - stc->CaptureMouse(); - else if (!on && capturedMouse && stc->HasCapture()) - stc->ReleaseMouse(); - capturedMouse = on; + if (mouseDownCaptures) { + if (on && !capturedMouse) + stc->CaptureMouse(); + else if (!on && capturedMouse && stc->HasCapture()) + stc->ReleaseMouse(); + capturedMouse = on; + } } @@ -333,6 +352,18 @@ void ScintillaWX::NotifyParent(SCNotification 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) { @@ -371,7 +402,7 @@ void ScintillaWX::Paste() { void ScintillaWX::CopyToClipboard(const SelectionText& st) { if (wxTheClipboard->Open()) { wxTheClipboard->UsePrimarySelection(FALSE); - wxString text = stc2wx(st.s, st.len); + wxString text = wxTextBuffer::Translate(stc2wx(st.s, st.len)); wxTheClipboard->SetData(new wxTextDataObject(text)); wxTheClipboard->Close(); } @@ -409,7 +440,7 @@ void ScintillaWX::AddToPopUp(const char *label, int cmd, bool enabled) { if (!label[0]) ((wxMenu*)popup.GetID())->AppendSeparator(); else - ((wxMenu*)popup.GetID())->Append(cmd, stc2wx(label)); + ((wxMenu*)popup.GetID())->Append(cmd, wxGetTranslation(stc2wx(label))); if (!enabled) ((wxMenu*)popup.GetID())->Enable(cmd, enabled); @@ -514,7 +545,7 @@ void ScintillaWX::DoPaint(wxDC* dc, wxRect rect) { delete surfaceWindow; if (paintState == paintAbandoned) { // Painting area was insufficient to cover new styling or brace highlight positions - FullPaint(); + FullPaint(dc); } paintState = notPainting; } @@ -606,11 +637,15 @@ void ScintillaWX::DoSize(int WXUNUSED(width), int WXUNUSED(height)) { } void ScintillaWX::DoLoseFocus(){ + focusEvent = true; SetFocusState(false); + focusEvent = false; } void ScintillaWX::DoGainFocus(){ + focusEvent = true; SetFocusState(true); + focusEvent = false; } void ScintillaWX::DoSysColourChange() { @@ -634,7 +669,7 @@ void ScintillaWX::DoMiddleButtonUp(Point pt) { // Set the current position to the mouse click point and // then paste in the PRIMARY selection, if any. wxGTK only. int newPos = PositionFromLocation(pt); - MovePositionTo(newPos, 0, 1); + MovePositionTo(newPos, noSel, true); pdoc->BeginUndoAction(); wxTextDataObject data; @@ -677,7 +712,11 @@ void ScintillaWX::DoAddChar(int key) { } +#ifdef __WXMAC__ int ScintillaWX::DoKeyDown(int key, bool shift, bool ctrl, bool alt, bool meta, bool* consumed) { +#else +int ScintillaWX::DoKeyDown(int key, bool shift, bool ctrl, bool alt, bool WXUNUSED(meta), bool* consumed) { +#endif #if defined(__WXGTK__) || defined(__WXMAC__) // Ctrl chars (A-Z) end up with the wrong keycode on wxGTK // TODO: Check this, it shouldn't be true any longer. @@ -726,7 +765,8 @@ int ScintillaWX::DoKeyDown(int key, bool shift, bool ctrl, bool alt, bool meta, case 'A': // Select All ctrl = true; break; - } + } + } #endif int rv = KeyDown(key, shift, ctrl, alt, consumed); @@ -752,6 +792,15 @@ void ScintillaWX::DoOnListBox() { AutoCompleteCompleted(); } + +void ScintillaWX::DoOnIdle(wxIdleEvent& evt) { + + if ( Idle() ) + evt.RequestMore(); + else + SetIdle(false); +} + //---------------------------------------------------------------------- #if wxUSE_DRAG_AND_DROP @@ -810,18 +859,18 @@ void ScintillaWX::DoDragLeave() { //---------------------------------------------------------------------- // Redraw all of text area. This paint will not be abandoned. -void ScintillaWX::FullPaint() { +void ScintillaWX::FullPaint(wxDC *dc) { + wxCHECK_RET(dc != NULL, wxT("Invalid wxDC in ScintillaWX::FillPaint")); paintState = painting; rcPaint = GetClientRectangle(); paintingAllText = true; - wxClientDC dc(stc); Surface* surfaceWindow = Surface::Allocate(); - surfaceWindow->Init(&dc, wMain.GetID()); + surfaceWindow->Init(dc, wMain.GetID()); - dc.BeginDrawing(); - ClipChildren(dc, rcPaint); + dc->BeginDrawing(); + ClipChildren(*dc, rcPaint); Paint(surfaceWindow, rcPaint); - dc.EndDrawing(); + dc->EndDrawing(); delete surfaceWindow; paintState = notPainting;