////////////////////////////////////////////////////////////////////////////
-// 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
// 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".
#include "wx/clipbrd.h"
#include "wx/dnd.h"
+#if !wxUSE_STD_CONTAINERS && !wxUSE_STD_IOSTREAM && !wxUSE_STD_STRING
+ #include "wx/beforestd.h"
+ #include <string>
+ #include "wx/afterstd.h"
+#endif
+
#include "ScintillaWX.h"
#include "ExternalLexer.h"
#include "wx/stc/stc.h"
| 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)
{
void OnPaint(wxPaintEvent& WXUNUSED(evt))
{
wxAutoBufferedPaintDC dc(this);
- Surface* surfaceWindow = Surface::Allocate();
+ Surface* surfaceWindow = Surface::Allocate(0);
surfaceWindow->Init(&dc, m_ct->wDraw.GetID());
m_ct->PaintCT(surfaceWindow);
surfaceWindow->Release();
return rv;
}
#endif
-
+
wxPoint GetMyPosition()
{
return wxPoint(m_cx, m_cy);
dropTarget->SetScintilla(this);
stc->SetDropTarget(dropTarget);
#endif // wxUSE_DRAG_AND_DROP
-#ifdef __WXMAC__
- vs.extraFontFlag = false; // UseAntiAliasing
-#else
vs.extraFontFlag = true; // UseAntiAliasing
-#endif
}
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;
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
}
void ScintillaWX::ScrollText(int linesToMove) {
int dy = vs.lineHeight * (linesToMove);
stc->ScrollWindow(0, dy);
- stc->Update();
}
void ScintillaWX::SetVerticalScrollPos() {
void ScintillaWX::Copy() {
- if (currentPos != anchor) {
+ if (!sel.Empty()) {
SelectionText st;
CopySelectionRange(&st);
CopyToClipboard(st);
#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
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);
DestroySystemCaret();
CreateSystemCaret();
}
- Point pos = LocationFromPosition(currentPos);
+ Point pos = PointMainCaret();
::SetCaretPos(pos.x, pos.y);
}
#endif
sptr_t ScintillaWX::WndProc(unsigned int iMessage, uptr_t wParam, sptr_t lParam) {
switch (iMessage) {
+#if 0 // TODO: check this
+
case SCI_CALLTIPSHOW: {
// NOTE: This is copied here from scintilla/src/ScintillaBase.cxx
// because of the little tweak that needs done below for wxGTK.
char* defn = reinterpret_cast<char *>(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.
ct.wCallTip.Show();
break;
}
+#endif
#ifdef SCI_LEXER
case SCI_LOADLEXERLIBRARY:
void 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);
+ AutoSurface surfaceWindow(dc, this);
+ if (surfaceWindow) {
+ rcPaint = PRectangleFromwxRect(rect);
+ PRectangle rcClient = GetClientRectangle();
+ paintingAllText = rcPaint.Contains(rcClient);
+
+ ClipChildren(*dc, rcPaint);
+ Paint(surfaceWindow, rcPaint);
+ surfaceWindow->Release();
+ }
- delete surfaceWindow;
if (paintState == paintAbandoned) {
// Painting area was insufficient to cover new styling or brace
- // highlight positions
- FullPaint();
+ // highlight positions. So trigger a new paint event that will
+ // repaint the whole window.
+ stc->Refresh(false);
+
+#if defined(__WXOSX__)
+ // On Mac we also need to finish the current paint to make sure that
+ // everything is on the screen that needs to be there between now and
+ // when the next paint event arrives.
+ FullPaintDC(dc);
+#endif
+ }
+ paintState = notPainting;
+}
+
+
+// Force the whole window to be repainted
+void ScintillaWX::FullPaint() {
+ stc->Refresh(false);
+ stc->Update();
+}
+
+
+void ScintillaWX::FullPaintDC(wxDC* dc) {
+ paintState = painting;
+ rcPaint = GetClientRectangle();
+ paintingAllText = true;
+ AutoSurface surfaceWindow(dc, this);
+ if (surfaceWindow) {
+ Paint(surfaceWindow, rcPaint);
+ surfaceWindow->Release();
}
paintState = notPainting;
}
+
void ScintillaWX::DoHScroll(int type, int pos) {
int xPos = xOffset;
PRectangle rcText = GetTextRectangle();
int lines;
if (ctrlDown) { // Zoom the fonts if Ctrl key down
- if (rotation < 0) {
+ if (rotation > 0) {
KeyCommand(SCI_ZOOMIN);
}
else {
// 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;
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();
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();
case WXK_CONTROL: key = 0; break;
case WXK_ALT: key = 0; break;
case WXK_SHIFT: key = 0; break;
- case WXK_MENU: key = 0; break;
+ case WXK_MENU: key = SCK_MENU; break;
}
#ifdef __WXMAC__
#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));
dragResult = evt.GetDragResult();
if (dragResult == wxDragMove || dragResult == wxDragCopy) {
- DropAt(evt.GetPosition(),
+ DropAt(SelectionPosition(evt.GetPosition()),
wx2stc(evt.GetDragText()),
dragResult == wxDragMove,
false); // TODO: rectangular?
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());
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();
-}
-
-
void ScintillaWX::DoScrollToLine(int line) {
ScrollTo(line);
}
}
bool ScintillaWX::GetUseAntiAliasing() {
- return vs.extraFontFlag;
+ return vs.extraFontFlag != 0;
}
//----------------------------------------------------------------------