X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/17e05a8e8820139c690bb852dbb7247cd67c4f7a..901504c38303a144615a7f88b328694c6662bbf7:/src/stc/ScintillaWX.cpp diff --git a/src/stc/ScintillaWX.cpp b/src/stc/ScintillaWX.cpp index b68bde05d3..8241114798 100644 --- a/src/stc/ScintillaWX.cpp +++ b/src/stc/ScintillaWX.cpp @@ -1,5 +1,5 @@ //////////////////////////////////////////////////////////////////////////// -// Name: ScintillaWX.cxx +// Name: src/stc/ScintillaWX.cpp // Purpose: A wxWidgets implementation of Scintilla. A class derived // from ScintillaBase that uses the "wx platform" defined in // PlatformWX.cxx This class is one end of a bridge between @@ -11,7 +11,7 @@ // Created: 13-Jan-2000 // RCS-ID: $Id$ // Copyright: (c) 2000 by Total Control Software -// Licence: wxWindows license +// Licence: wxWindows licence ///////////////////////////////////////////////////////////////////////////// // For compilers that support precompilation, includes "wx.h". @@ -34,6 +34,12 @@ #include "wx/clipbrd.h" #include "wx/dnd.h" +#if !wxUSE_STD_CONTAINERS && !wxUSE_STD_IOSTREAM && !wxUSE_STD_STRING + #include "wx/beforestd.h" + #include + #include "wx/afterstd.h" +#endif + #include "ScintillaWX.h" #include "ExternalLexer.h" #include "wx/stc/stc.h" @@ -103,9 +109,9 @@ public: | wxFRAME_FLOAT_ON_PARENT | wxBORDER_NONE #ifdef __WXMAC__ - | wxPOPUP_WINDOW + | wxPOPUP_WINDOW #endif - ), + ), #endif m_ct(ct), m_swx(swx), m_cx(wxDefaultCoord), m_cy(wxDefaultCoord) { @@ -180,7 +186,7 @@ public: return rv; } #endif - + wxPoint GetMyPosition() { return wxPoint(m_cx, m_cy); @@ -263,11 +269,7 @@ void ScintillaWX::Initialise() { dropTarget->SetScintilla(this); stc->SetDropTarget(dropTarget); #endif // wxUSE_DRAG_AND_DROP -#ifdef __WXMAC__ - vs.extraFontFlag = false; // UseAntiAliasing -#else vs.extraFontFlag = true; // UseAntiAliasing -#endif } @@ -287,13 +289,13 @@ void ScintillaWX::StartDrag() { wxStyledTextEvent evt(wxEVT_STC_START_DRAG, stc->GetId()); evt.SetEventObject(stc); evt.SetDragText(dragText); - evt.SetDragAllowMove(true); + evt.SetDragFlags(wxDrag_DefaultMove); evt.SetPosition(wxMin(stc->GetSelectionStart(), stc->GetSelectionEnd())); stc->GetEventHandler()->ProcessEvent(evt); dragText = evt.GetDragText(); - if (dragText.length()) { + if ( !dragText.empty() ) { wxDropSource source(stc); wxTextDataObject data(dragText); wxDragResult result; @@ -301,11 +303,11 @@ void ScintillaWX::StartDrag() { source.SetData(data); dropWentOutside = true; inDragDrop = ddDragging; - result = source.DoDragDrop(evt.GetDragAllowMove()); + result = source.DoDragDrop(evt.GetDragFlags()); if (result == wxDragMove && dropWentOutside) ClearSelection(); inDragDrop = ddNone; - SetDragPosition(invalidPosition); + SetDragPosition(SelectionPosition(invalidPosition)); } #endif // wxUSE_DRAG_AND_DROP } @@ -315,11 +317,9 @@ bool ScintillaWX::SetIdle(bool on) { if (idler.state != on) { // connect or disconnect the EVT_IDLE handler if (on) - stc->Connect(wxID_ANY, wxEVT_IDLE, - (wxObjectEventFunction) (wxEventFunction) (wxIdleEventFunction) &wxStyledTextCtrl::OnIdle); + stc->Connect(wxID_ANY, wxEVT_IDLE, wxIdleEventHandler(wxStyledTextCtrl::OnIdle)); else - stc->Disconnect(wxID_ANY, wxEVT_IDLE, - (wxObjectEventFunction) (wxEventFunction) (wxIdleEventFunction) &wxStyledTextCtrl::OnIdle); + stc->Disconnect(wxID_ANY, wxEVT_IDLE, wxIdleEventHandler(wxStyledTextCtrl::OnIdle)); idler.state = on; } return idler.state; @@ -478,7 +478,7 @@ void ScintillaWX::CancelModes() { void ScintillaWX::Copy() { - if (currentPos != anchor) { + if (!sel.Empty()) { SelectionText st; CopySelectionRange(&st); CopyToClipboard(st); @@ -506,12 +506,13 @@ void ScintillaWX::Paste() { #if wxUSE_UNICODE // free up the old character buffer in case the text is real big - data.SetText(wxEmptyString); + data.SetText(wxEmptyString); text = wxEmptyString; #endif int len = strlen(buf); - pdoc->InsertString(currentPos, buf, len); - SetEmptySelection(currentPos + len); + int caretMain = sel.MainCaret(); + pdoc->InsertString(caretMain, buf, len); + SetEmptySelection(caretMain + len); } #endif // wxUSE_DATAOBJ @@ -523,6 +524,9 @@ void ScintillaWX::Paste() { void ScintillaWX::CopyToClipboard(const SelectionText& st) { #if wxUSE_CLIPBOARD + if ( !st.len ) + return; + wxTheClipboard->UsePrimarySelection(false); if (wxTheClipboard->Open()) { wxString text = wxTextBuffer::Translate(stc2wx(st.s, st.len-1)); @@ -583,7 +587,7 @@ void ScintillaWX::AddToPopUp(const char *label, int cmd, bool enabled) { void ScintillaWX::ClaimSelection() { #ifdef __WXGTK__ // Put the selected text in the PRIMARY selection - if (currentPos != anchor) { + if (!sel.Empty()) { SelectionText st; CopySelectionRange(&st); wxTheClipboard->UsePrimarySelection(true); @@ -605,7 +609,7 @@ void ScintillaWX::UpdateSystemCaret() { DestroySystemCaret(); CreateSystemCaret(); } - Point pos = LocationFromPosition(currentPos); + Point pos = PointMainCaret(); ::SetCaretPos(pos.x, pos.y); } #endif @@ -614,8 +618,8 @@ void ScintillaWX::UpdateSystemCaret() { bool ScintillaWX::HasCaretSizeChanged() { #ifdef __WXMSW__ - if (( (0 != vs.caretWidth) && (sysCaretWidth != vs.caretWidth) ) - || (0 != vs.lineHeight) && (sysCaretHeight != vs.lineHeight)) { + if ( (vs.caretWidth && (sysCaretWidth != vs.caretWidth)) + || (vs.lineHeight && (sysCaretHeight != vs.lineHeight)) ) { return true; } #endif @@ -677,12 +681,18 @@ sptr_t ScintillaWX::WndProc(unsigned int iMessage, uptr_t wParam, sptr_t lParam) char* defn = reinterpret_cast(lParam); AutoCompleteCancel(); pt.y += vs.lineHeight; - PRectangle rc = ct.CallTipStart(currentPos, pt, + int ctStyle = ct.UseStyleCallTip() ? STYLE_CALLTIP : STYLE_DEFAULT; + if (ct.UseStyleCallTip()) + { + ct.SetForeBack(vs.styles[STYLE_CALLTIP].fore, vs.styles[STYLE_CALLTIP].back); + } + int caretMain = sel.MainCaret(); + PRectangle rc = ct.CallTipStart(caretMain, pt, defn, - vs.styles[STYLE_DEFAULT].fontName, - vs.styles[STYLE_DEFAULT].sizeZoomed, + vs.styles[ctStyle].fontName, + vs.styles[ctStyle].sizeZoomed, CodePage(), - vs.styles[STYLE_DEFAULT].characterSet, + vs.styles[ctStyle].characterSet, wMain); // If the call-tip window would be out of the client // space, adjust so it displays above the text. @@ -860,7 +870,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, noSel, true); + MovePositionTo(newPos, Selection::noSel, true); pdoc->BeginUndoAction(); wxTextDataObject data; @@ -876,8 +886,9 @@ void ScintillaWX::DoMiddleButtonUp(Point pt) { wxConvertEOLMode(pdoc->eolMode)); wxWX2MBbuf buf = (wxWX2MBbuf)wx2stc(text); int len = strlen(buf); - pdoc->InsertString(currentPos, buf, len); - SetEmptySelection(currentPos + len); + int caretMain = sel.MainCaret(); + pdoc->InsertString(caretMain, buf, len); + SetEmptySelection(caretMain + len); } pdoc->EndUndoAction(); NotifyChange(); @@ -908,6 +919,14 @@ void ScintillaWX::DoAddChar(int key) { int ScintillaWX::DoKeyDown(const wxKeyEvent& evt, bool* consumed) { int key = evt.GetKeyCode(); + if (key == WXK_NONE) { + // This is a Unicode character not representable in Latin-1 or some key + // without key code at all (e.g. dead key or VK_PROCESSKEY under MSW). + if ( consumed ) + *consumed = false; + return 0; + } + bool shift = evt.ShiftDown(), ctrl = evt.ControlDown(), alt = evt.AltDown(); @@ -1005,7 +1024,7 @@ void ScintillaWX::DoOnIdle(wxIdleEvent& evt) { #if wxUSE_DRAG_AND_DROP bool ScintillaWX::DoDropText(long x, long y, const wxString& data) { - SetDragPosition(invalidPosition); + SetDragPosition(SelectionPosition(invalidPosition)); wxString text = wxTextBuffer::Translate(data, wxConvertEOLMode(pdoc->eolMode)); @@ -1022,7 +1041,7 @@ bool ScintillaWX::DoDropText(long x, long y, const wxString& data) { dragResult = evt.GetDragResult(); if (dragResult == wxDragMove || dragResult == wxDragCopy) { - DropAt(evt.GetPosition(), + DropAt(SelectionPosition(evt.GetPosition()), wx2stc(evt.GetDragText()), dragResult == wxDragMove, false); // TODO: rectangular? @@ -1039,7 +1058,7 @@ wxDragResult ScintillaWX::DoDragEnter(wxCoord WXUNUSED(x), wxCoord WXUNUSED(y), wxDragResult ScintillaWX::DoDragOver(wxCoord x, wxCoord y, wxDragResult def) { - SetDragPosition(PositionFromLocation(Point(x, y))); + SetDragPosition(SelectionPosition(PositionFromLocation(Point(x, y)))); // Send an event to allow the drag result to be changed wxStyledTextEvent evt(wxEVT_STC_DRAG_OVER, stc->GetId()); @@ -1056,16 +1075,14 @@ wxDragResult ScintillaWX::DoDragOver(wxCoord x, wxCoord y, wxDragResult def) { void ScintillaWX::DoDragLeave() { - SetDragPosition(invalidPosition); + SetDragPosition(SelectionPosition(invalidPosition)); } #endif // wxUSE_DRAG_AND_DROP //---------------------------------------------------------------------- // Force the whole window to be repainted void ScintillaWX::FullPaint() { -#ifndef __WXMAC__ stc->Refresh(false); -#endif stc->Update(); } @@ -1106,7 +1123,7 @@ void ScintillaWX::SetUseAntiAliasing(bool useAA) { } bool ScintillaWX::GetUseAntiAliasing() { - return vs.extraFontFlag; + return vs.extraFontFlag != 0; } //----------------------------------------------------------------------