diff options
-rw-r--r-- | include/Scintilla.h | 1 | ||||
-rw-r--r-- | src/Editor.cxx | 764 | ||||
-rw-r--r-- | src/Editor.h | 9 | ||||
-rw-r--r-- | src/Style.cxx | 11 | ||||
-rw-r--r-- | src/Style.h | 3 | ||||
-rw-r--r-- | src/ViewStyle.cxx | 5 |
6 files changed, 423 insertions, 370 deletions
diff --git a/include/Scintilla.h b/include/Scintilla.h index 361a73b47..a1494b41a 100644 --- a/include/Scintilla.h +++ b/include/Scintilla.h @@ -157,6 +157,7 @@ typedef long (*SciFnDirect)(long ptr, unsigned int iMessage, unsigned long wPara #define SCI_STYLERESETDEFAULT SCI_START + 58 #define SCI_STYLESETUNDERLINE SCI_START + 59 #define SCI_STYLESETCHARACTERSET SCI_START + 66 +#define SCI_STYLESETVISIBLE SCI_START + 74 #define SCI_SETSELFORE SCI_START + 67 #define SCI_SETSELBACK SCI_START + 68 diff --git a/src/Editor.cxx b/src/Editor.cxx index f70826473..44e28dbc2 100644 --- a/src/Editor.cxx +++ b/src/Editor.cxx @@ -14,7 +14,7 @@ #if PLAT_WX || PLAT_GTK #include "WinDefs.h" -#endif +#endif #include "ContractionState.h" #include "SVector.h" @@ -37,10 +37,10 @@ Editor::Editor() { ctrlID = 0; stylesValid = false; - + printMagnification = 0; printColourMode = SC_PRINT_NORMAL; - + hideSelection = false; inOverstrike = false; @@ -67,46 +67,46 @@ Editor::Editor() { xStartSelect = 0; xEndSelect = 0; primarySelection = true; - + caretPolicy = CARET_SLOP; caretSlop = 0; searchAnchor = 0; - + ucWheelScrollLines = 0; cWheelDelta = 0; //wheel delta from roll xOffset = 0; xCaretMargin = 50; horizontalScrollBarVisible = true; - + currentPos = 0; anchor = 0; topLine = 0; posTopLine = 0; - + needUpdateUI = true; - braces[0]=invalidPosition; - braces[1]=invalidPosition; + braces[0] = invalidPosition; + braces[1] = invalidPosition; bracesMatchStyle = STYLE_BRACEBAD; highlightGuideColumn = 0; theEdge = 0; - + paintState = notPainting; - + modEventMask = SC_MODEVENTMASKALL; displayPopupMenu = true; - + pdoc = new Document(); pdoc ->AddRef(); pdoc->AddWatcher(this, 0); #ifdef MACRO_SUPPORT recordingMacro = 0; -#endif +#endif foldFlags = 0; } @@ -226,12 +226,12 @@ Point Editor::LocationFromPosition(unsigned int pos) { Point pt; pt.y = (lineVisible - topLine) * vs.lineHeight; // + half a lineheight? unsigned int posLineStart = pdoc->LineStart(line); + LineLayout ll; + LayoutLine(line, &surface, vs, ll); if ((pos - posLineStart) > LineLayout::maxLineLength) { // very long line so put x at arbitrary large position - pt.x = 30000 + vs.fixedColumnWidth - xOffset; + pt.x = ll.positions[LineLayout::maxLineLength] + vs.fixedColumnWidth - xOffset; } else { - LineLayout ll; - LayoutLine(line, &surface, vs, ll); pt.x = ll.positions[pos - posLineStart] + vs.fixedColumnWidth - xOffset; } return pt; @@ -241,7 +241,7 @@ int Editor::XFromPosition(unsigned int pos) { Point pt = LocationFromPosition(pos); return pt.x - vs.fixedColumnWidth + xOffset; } - + int Editor::LineFromLocation(Point pt) { return cs.DocFromDisplay(pt.y / vs.lineHeight + topLine); } @@ -262,7 +262,7 @@ int Editor::PositionFromLocation(Point pt) { return 0; if (line >= pdoc->LinesTotal()) return pdoc->Length(); -//Platform::DebugPrintf("Position of (%d,%d) line = %d top=%d\n", pt.x, pt.y, line, topLine); + //Platform::DebugPrintf("Position of (%d,%d) line = %d top=%d\n", pt.x, pt.y, line, topLine); Surface surface; surface.Init(); surface.SetUnicodeMode(SC_CP_UTF8 == pdoc->dbcsCodePage); @@ -271,8 +271,8 @@ int Editor::PositionFromLocation(Point pt) { LineLayout ll; LayoutLine(line, &surface, vs, ll); for (int i = 0; i < ll.numCharsInLine; i++) { - if (pt.x < ((ll.positions[i] + ll.positions[i + 1]) / 2) || - ll.chars[i] == '\r' || ll.chars[i] == '\n') { + if (pt.x < ((ll.positions[i] + ll.positions[i + 1]) / 2) || + ll.chars[i] == '\r' || ll.chars[i] == '\n') { return i + posLineStart; } } @@ -293,8 +293,8 @@ int Editor::PositionFromLineX(int line, int x) { LineLayout ll; LayoutLine(line, &surface, vs, ll); for (int i = 0; i < ll.numCharsInLine; i++) { - if (x < ((ll.positions[i] + ll.positions[i + 1]) / 2) || - ll.chars[i] == '\r' || ll.chars[i] == '\n') { + if (x < ((ll.positions[i] + ll.positions[i + 1]) / 2) || + ll.chars[i] == '\r' || ll.chars[i] == '\n') { return i + posLineStart; } } @@ -373,7 +373,7 @@ int Editor::SelectionStart(int line) { //return PositionFromLineX(line, minX + vs.fixedColumnWidth - xOffset); return PositionFromLineX(line, minX); } - } + } } int Editor::SelectionEnd(int line) { @@ -444,10 +444,26 @@ void Editor::SetEmptySelection(int currentPos_) { SetSelection(currentPos_, currentPos_); } +int Editor::MovePositionOutsideChar(int pos, int moveDir, bool checkLineEnd) { + // Asks document to find a good position and then moves out of any invisible positions + pos = pdoc->MovePositionOutsideChar(pos, moveDir, checkLineEnd); + int mask = pdoc->stylingBitsMask; + if (moveDir > 0) { + while ((pos < pdoc->Length()) && + (!vs.styles[pdoc->StyleAt(pos - 1) & mask].visible)) + pos++; + } else { + while ((pos > 0) && + (!vs.styles[pdoc->StyleAt(pos - 1) & mask].visible)) + pos--; + } + return pos; +} + int Editor::MovePositionTo(int newPos, bool extend) { int delta = newPos - currentPos; newPos = pdoc->ClampPositionIntoDocument(newPos); - newPos = pdoc->MovePositionOutsideChar(newPos, delta); + newPos = MovePositionOutsideChar(newPos, delta); if (extend) { SetSelection(newPos); } else { @@ -460,7 +476,7 @@ int Editor::MovePositionTo(int newPos, bool extend) { int Editor::MovePositionSoVisible(int pos, int moveDir) { pos = pdoc->ClampPositionIntoDocument(pos); - pos = pdoc->MovePositionOutsideChar(pos, moveDir); + pos = MovePositionOutsideChar(pos, moveDir); int lineDoc = pdoc->LineFromPosition(pos); if (cs.GetVisible(lineDoc)) { return pos; @@ -521,7 +537,7 @@ void Editor::MoveCaretInsideView() { MovePositionTo(PositionFromLocation( Point(lastXChosen, rcClient.top))); } else if ((pt.y + vs.lineHeight - 1) > rcClient.bottom) { - int yOfLastLineFullyDisplayed = rcClient.top + (LinesOnScreen()-1) * vs.lineHeight; + int yOfLastLineFullyDisplayed = rcClient.top + (LinesOnScreen() - 1) * vs.lineHeight; MovePositionTo(PositionFromLocation( Point(lastXChosen, rcClient.top + yOfLastLineFullyDisplayed))); } @@ -543,11 +559,11 @@ void Editor::EnsureCaretVisible(bool useMargin) { int xMargin = Platform::Clamp(xCaretMargin, 2, Platform::Maximum(rcClient.Width() - 10, 4) / 2); if (!useMargin) xMargin = 2; - + // Ensure certain amount of text visible on both sides of caretSo move if caret just on edge rcClient.left = rcClient.left + xMargin; rcClient.right = rcClient.right - xMargin; - + if (!rcClient.Contains(pt) || !rcClient.Contains(ptBottomCaret) || (caretPolicy & CARET_STRICT)) { //Platform::DebugPrintf("EnsureCaretVisible move, (%d,%d) (%d,%d)\n", pt.x, pt.y, rcClient.left, rcClient.right); // It should be possible to scroll the window to show the caret, @@ -557,8 +573,8 @@ void Editor::EnsureCaretVisible(bool useMargin) { SetTopLine(Platform::Clamp(lineCaret - caretSlop, 0, MaxScrollPos())); SetVerticalScrollPos(); Redraw(); - } else if ((lineCaret > topLine + LinesOnScreen() - 1) || - ((caretPolicy & CARET_STRICT) && (lineCaret > topLine + LinesOnScreen() - 1 - caretSlop))) { + } else if ((lineCaret > topLine + LinesOnScreen() - 1) || + ((caretPolicy & CARET_STRICT) && (lineCaret > topLine + LinesOnScreen() - 1 - caretSlop))) { SetTopLine(Platform::Clamp(lineCaret - LinesOnScreen() + 1 + caretSlop, 0, MaxScrollPos())); SetVerticalScrollPos(); Redraw(); @@ -595,7 +611,7 @@ void Editor::ShowCaretAtCurrentPosition() { if (!wMain.HasFocus()) { caret.active = false; caret.on = false; - return; + return ; } caret.active = true; caret.on = true; @@ -616,13 +632,13 @@ void Editor::InvalidateCaret() { void Editor::PaintSelMargin(Surface *surfWindow, PRectangle &rc) { if (vs.fixedColumnWidth == 0) - return; + return ; PRectangle rcMargin = GetClientRectangle(); rcMargin.right = vs.fixedColumnWidth; if (!rc.Intersects(rcMargin)) - return; + return ; Surface *surface; if (bufferedDraw) { @@ -634,9 +650,9 @@ void Editor::PaintSelMargin(Surface *surfWindow, PRectangle &rc) { PRectangle rcSelMargin = rcMargin; rcSelMargin.right = rcMargin.left; - for (int margin=0; margin < vs.margins; margin++) { + for (int margin = 0; margin < vs.margins; margin++) { if (vs.ms[margin].width > 0) { - + rcSelMargin.left = rcSelMargin.right; rcSelMargin.right = rcSelMargin.left + vs.ms[margin].width; @@ -650,13 +666,13 @@ void Editor::PaintSelMargin(Surface *surfWindow, PRectangle &rc) { */ if (vs.ms[margin].mask & SC_MASK_FOLDERS) // Required because of special way brush is created for selection margin - surface->FillRectangle(rcSelMargin, pixmapSelPattern); + surface->FillRectangle(rcSelMargin, pixmapSelPattern); else - surface->FillRectangle(rcSelMargin, vs.styles[STYLE_LINENUMBER].back.allocated); + surface->FillRectangle(rcSelMargin, vs.styles[STYLE_LINENUMBER].back.allocated); } else { surface->FillRectangle(rcSelMargin, vs.styles[STYLE_LINENUMBER].back.allocated); } - + int visibleLine = topLine; int line = cs.DocFromDisplay(visibleLine); int yposScreen = 0; @@ -680,7 +696,7 @@ void Editor::PaintSelMargin(Surface *surfWindow, PRectangle &rc) { sprintf(number, "%d", line + 1); if (foldFlags & 64) sprintf(number, "%X", pdoc->GetLevel(line)); - PRectangle rcNumber=rcMarker; + PRectangle rcNumber = rcMarker; // Right justify int width = surface->WidthText(vs.styles[STYLE_LINENUMBER].font, number, strlen(number)); int xpos = rcNumber.right - width - 3; @@ -688,11 +704,11 @@ void Editor::PaintSelMargin(Surface *surfWindow, PRectangle &rc) { if ((visibleLine < cs.LinesDisplayed()) && cs.GetVisible(line)) { surface->DrawText(rcNumber, vs.styles[STYLE_LINENUMBER].font, rcNumber.top + vs.maxAscent, number, strlen(number), - vs.styles[STYLE_LINENUMBER].fore.allocated, - vs.styles[STYLE_LINENUMBER].back.allocated); + vs.styles[STYLE_LINENUMBER].fore.allocated, + vs.styles[STYLE_LINENUMBER].back.allocated); } } - + if (marks) { for (int markBit = 0; (markBit < 32) && marks; markBit++) { if (marks & 1) { @@ -703,7 +719,7 @@ void Editor::PaintSelMargin(Surface *surfWindow, PRectangle &rc) { marks >>= 1; } } - + visibleLine++; line = cs.DocFromDisplay(visibleLine); yposScreen += vs.lineHeight; @@ -713,8 +729,8 @@ void Editor::PaintSelMargin(Surface *surfWindow, PRectangle &rc) { PRectangle rcBlankMargin = rcMargin; rcBlankMargin.left = rcSelMargin.right; - surface->FillRectangle(rcBlankMargin, vs.styles[STYLE_DEFAULT].back.allocated); - + surface->FillRectangle(rcBlankMargin, vs.styles[STYLE_DEFAULT].back.allocated); + if (bufferedDraw) { surfWindow->Copy(rcMargin, Point(), pixmapSelMargin); } @@ -741,10 +757,10 @@ void Editor::LayoutLine(int line, Surface *surface, ViewStyle &vstyle, LineLayou char styleByte = 0; int styleMask = pdoc->stylingBitsMask; ll.xHighlightGuide = 0; - if (posLineEnd >= (posLineStart + LineLayout::maxLineLength)) { - posLineEnd = posLineStart + LineLayout::maxLineLength - 1; - } - for (int charInDoc=posLineStart; charInDoc<posLineEnd; charInDoc++) { + if (posLineEnd > (posLineStart + LineLayout::maxLineLength)) { + posLineEnd = posLineStart + LineLayout::maxLineLength; + } + for (int charInDoc = posLineStart; charInDoc < posLineEnd; charInDoc++) { char chDoc = pdoc->CharAt(charInDoc); styleByte = pdoc->StyleAt(charInDoc); if (vstyle.viewEOL || ((chDoc != '\r') && (chDoc != '\n'))) { @@ -754,40 +770,46 @@ void Editor::LayoutLine(int line, Surface *surface, ViewStyle &vstyle, LineLayou numCharsInLine++; } } - ll.chars[numCharsInLine] = 0; + // Extra element at the end of the line to hold end x position and act as + ll.chars[numCharsInLine] = 0; // Also triggers processing in the loops as this is a control character ll.styles[numCharsInLine] = styleByte; // For eolFilled ll.indicators[numCharsInLine] = 0; - ll.indicators[numCharsInLine+1] = 0; - // Layout the line, determining the position of each character + // Layout the line, determining the position of each character, + // with an extra element at the end for the end of the line. int startseg = 0; int startsegx = 0; ll.positions[0] = 0; - ll.positions[numCharsInLine + 1] = 0; unsigned int tabWidth = vstyle.spaceWidth * pdoc->tabInChars; - + for (int charInLine = 0; charInLine < numCharsInLine; charInLine++) { if ((ll.styles[charInLine] != ll.styles[charInLine + 1]) || IsControlCharacter(ll.chars[charInLine]) || IsControlCharacter(ll.chars[charInLine + 1])) { ll.positions[startseg] = 0; - if (IsControlCharacter(ll.chars[charInLine])) { - if (ll.chars[charInLine] == '\t') { - ll.positions[charInLine + 1] = ((((startsegx + 2) / - tabWidth) + 1) * tabWidth) - startsegx; + if (vstyle.styles[ll.styles[charInLine]].visible) { + if (IsControlCharacter(ll.chars[charInLine])) { + if (ll.chars[charInLine] == '\t') { + ll.positions[charInLine + 1] = ((((startsegx + 2) / + tabWidth) + 1) * tabWidth) - startsegx; + } else { + const char *ctrlChar = ControlCharacterString(ll.chars[charInLine]); + // +3 For a blank on front and rounded edge each side: + ll.positions[charInLine + 1] = surface->WidthText(ctrlCharsFont, ctrlChar, strlen(ctrlChar)) + 3; + } } else { - const char *ctrlChar = ControlCharacterString(ll.chars[charInLine]); - // +3 For a blank on front and rounded edge each side: - ll.positions[charInLine + 1] = surface->WidthText(ctrlCharsFont, ctrlChar, strlen(ctrlChar)) + 3; + int lenSeg = charInLine - startseg + 1; + if ((lenSeg == 1) && (' ' == ll.chars[startseg])) { + // Over half the segments are single characters and of these about half are space characters. + ll.positions[charInLine + 1] = vstyle.styles[ll.styles[charInLine]].spaceWidth; + } else { + surface->MeasureWidths(vstyle.styles[ll.styles[charInLine]].font, ll.chars + startseg, + charInLine - startseg + 1, ll.positions + startseg + 1); + } + } + } else { // invisible + for (int posToZero = startseg; posToZero <= (charInLine + 1); posToZero++) { + ll.positions[posToZero] = 0; } - } else { - int lenSeg = charInLine - startseg + 1; - if ((lenSeg == 1) && (' ' == ll.chars[startseg])) { - // Over half the segments are single characters and of these about half are space characters. - ll.positions[charInLine + 1] = vstyle.styles[ll.styles[charInLine]].spaceWidth; - } else { - surface->MeasureWidths(vstyle.styles[ll.styles[charInLine]].font, ll.chars + startseg, - charInLine - startseg + 1, ll.positions + startseg + 1); - } } for (int posToIncrease = startseg; posToIncrease <= (charInLine + 1); posToIncrease++) { ll.positions[posToIncrease] += startsegx; @@ -799,11 +821,11 @@ void Editor::LayoutLine(int line, Surface *surface, ViewStyle &vstyle, LineLayou ll.numCharsInLine = numCharsInLine; } -void Editor::DrawLine(Surface *surface, ViewStyle &vsDraw, int line, int lineVisible, int xStart, - PRectangle rcLine, LineLayout &ll) { - +void Editor::DrawLine(Surface *surface, ViewStyle &vsDraw, int line, int lineVisible, int xStart, + PRectangle rcLine, LineLayout &ll) { + PRectangle rcSegment = rcLine; - + // Using one font for all control characters so it can be controlled independently to ensure // the box goes around the characters tightly. Seems to be no way to work out what height // is taken by an individual character - internal leading gives varying results. @@ -828,7 +850,7 @@ void Editor::DrawLine(Surface *surface, ViewStyle &vsDraw, int line, int lineVis int indentWidth = pdoc->indentInChars * vsDraw.spaceWidth; if (indentWidth == 0) indentWidth = pdoc->tabInChars * vsDraw.spaceWidth; - + int posLineStart = pdoc->LineStart(line); int posLineEnd = pdoc->LineStart(line + 1); @@ -839,9 +861,9 @@ void Editor::DrawLine(Surface *surface, ViewStyle &vsDraw, int line, int lineVis int iDoc = i + posLineStart; // If there is the end of a style run for any reason if ((ll.styles[i] != ll.styles[i + 1]) || - IsControlCharacter(ll.chars[i]) || IsControlCharacter(ll.chars[i + 1]) || - ((ll.selStart != ll.selEnd) && ((iDoc + 1 == ll.selStart) || (iDoc + 1 == ll.selEnd))) || - (i == (ll.edgeColumn-1))) { + IsControlCharacter(ll.chars[i]) || IsControlCharacter(ll.chars[i + 1]) || + ((ll.selStart != ll.selEnd) && ((iDoc + 1 == ll.selStart) || (iDoc + 1 == ll.selEnd))) || + (i == (ll.edgeColumn - 1))) { int styleMain = ll.styles[i]; Colour textBack = vsDraw.styles[styleMain].back.allocated; Colour textFore = vsDraw.styles[styleMain].fore.allocated; @@ -875,20 +897,21 @@ void Editor::DrawLine(Surface *surface, ViewStyle &vsDraw, int line, int lineVis if (xIG >= ll.positions[i] && xIG > 0) { Point from(0, ((lineVisible & 1) && (vsDraw.lineHeight & 1)) ? 1 : 0); PRectangle rcCopyArea(xIG + xStart + 1, rcSegment.top, xIG + xStart + 2, rcSegment.bottom); - surface->Copy(rcCopyArea, from, (ll.xHighlightGuide == xIG) ? - pixmapIndentGuideHighlight : pixmapIndentGuide); + surface->Copy(rcCopyArea, from, (ll.xHighlightGuide == xIG) ? + pixmapIndentGuideHighlight : pixmapIndentGuide); } } } if (vsDraw.viewWhitespace != wsInvisible) { if (!inIndentation || vsDraw.viewWhitespace == wsVisibleAlways) { PRectangle rcTab(rcSegment.left + 1, rcSegment.top + 4, - rcSegment.right - 1, rcSegment.bottom - vsDraw.maxDescent); + rcSegment.right - 1, rcSegment.bottom - vsDraw.maxDescent); DrawTabArrow(surface, rcTab, rcSegment.top + vsDraw.lineHeight / 2); } } - // Manage control character display - } else if (IsControlCharacter(ll.chars[i])) { + // Manage control character display + } + else if (IsControlCharacter(ll.chars[i])) { inIndentation = false; const char *ctrlChar = ControlCharacterString(ll.chars[i]); rcSegment.left = ll.positions[i] + xStart; @@ -908,20 +931,21 @@ void Editor::DrawLine(Surface *surface, ViewStyle &vsDraw, int line, int lineVis rcChar.left++; rcChar.right--; surface->DrawTextClipped(rcChar, ctrlCharsFont, - rcSegment.top + vsDraw.maxAscent, ctrlChar, strlen(ctrlChar), - textBack, textFore); - // Manage normal display - } else { + rcSegment.top + vsDraw.maxAscent, ctrlChar, strlen(ctrlChar), + textBack, textFore); + // Manage normal display + } + else { rcSegment.left = ll.positions[startseg] + xStart; rcSegment.right = ll.positions[i + 1] + xStart; - // Only try to draw if really visible - enhances performance by not calling environment to + // Only try to draw if really visible - enhances performance by not calling environment to // draw strings that are completely past the right side of the window. if (rcSegment.left <= rcLine.right) { surface->DrawText(rcSegment, textFont, - rcSegment.top + vsDraw.maxAscent, ll.chars + startseg, - i - startseg + 1, textFore, textBack); - if (vsDraw.viewWhitespace != wsInvisible || - (inIndentation && vsDraw.viewIndentationGuides)) { + rcSegment.top + vsDraw.maxAscent, ll.chars + startseg, + i - startseg + 1, textFore, textBack); + if (vsDraw.viewWhitespace != wsInvisible || + (inIndentation && vsDraw.viewIndentationGuides)) { for (int cpos = 0; cpos <= i - startseg; cpos++) { if (ll.chars[cpos + startseg] == ' ') { if (vsDraw.viewWhitespace != wsInvisible) { @@ -938,8 +962,8 @@ void Editor::DrawLine(Surface *surface, ViewStyle &vsDraw, int line, int lineVis if (startSpace > 0 && (startSpace % indentWidth == 0)) { Point from(0, ((lineVisible & 1) && (vsDraw.lineHeight & 1)) ? 1 : 0); PRectangle rcCopyArea(startSpace + xStart + 1, rcSegment.top, startSpace + xStart + 2, rcSegment.bottom); - surface->Copy(rcCopyArea, from, (ll.xHighlightGuide == ll.positions[cpos + startseg]) ? - pixmapIndentGuideHighlight : pixmapIndentGuide); + surface->Copy(rcCopyArea, from, (ll.xHighlightGuide == ll.positions[cpos + startseg]) ? + pixmapIndentGuideHighlight : pixmapIndentGuide); } } } else { @@ -990,7 +1014,7 @@ void Editor::DrawLine(Surface *surface, ViewStyle &vsDraw, int line, int lineVis rcSegment.left = xEol + xStart; rcSegment.right = xEol + vsDraw.aveCharWidth + xStart; bool eolInSelection = (posLineEnd > ll.selStart) && (posLineEnd <= ll.selEnd) && (ll.selStart != ll.selEnd); - if (eolInSelection && vsDraw.selbackset && (line < pdoc->LinesTotal()-1)) { + if (eolInSelection && vsDraw.selbackset && (line < pdoc->LinesTotal() - 1)) { if (primarySelection) surface->FillRectangle(rcSegment, vsDraw.selbackground.allocated); else @@ -1010,7 +1034,7 @@ void Editor::DrawLine(Surface *surface, ViewStyle &vsDraw, int line, int lineVis } else { surface->FillRectangle(rcSegment, vsDraw.styles[STYLE_DEFAULT].back.allocated); } - + if (vsDraw.edgeState == EDGE_LINE) { int edgeX = ll.edgeColumn * vsDraw.spaceWidth; rcSegment.left = edgeX + xStart; @@ -1048,21 +1072,21 @@ void Editor::Paint(Surface *surfaceWindow, PRectangle rcArea) { } if (!pixmapIndentGuide.Initialised()) { // 1 extra pixel in height so can handle odd/even positions and so produce a continuous line - pixmapIndentGuide.InitPixMap(1, vs.lineHeight+1, surfaceWindow); - pixmapIndentGuideHighlight.InitPixMap(1, vs.lineHeight+1, surfaceWindow); + pixmapIndentGuide.InitPixMap(1, vs.lineHeight + 1, surfaceWindow); + pixmapIndentGuideHighlight.InitPixMap(1, vs.lineHeight + 1, surfaceWindow); PRectangle rcIG(0, 0, 1, vs.lineHeight); pixmapIndentGuide.FillRectangle(rcIG, vs.styles[STYLE_INDENTGUIDE].back.allocated); pixmapIndentGuide.PenColour(vs.styles[STYLE_INDENTGUIDE].fore.allocated); pixmapIndentGuideHighlight.FillRectangle(rcIG, vs.styles[STYLE_BRACELIGHT].back.allocated); pixmapIndentGuideHighlight.PenColour(vs.styles[STYLE_BRACELIGHT].fore.allocated); - for (int stripe = 1; stripe < vs.lineHeight+1; stripe+=2) { + for (int stripe = 1; stripe < vs.lineHeight + 1; stripe += 2) { pixmapIndentGuide.MoveTo(0, stripe); pixmapIndentGuide.LineTo(2, stripe); pixmapIndentGuideHighlight.MoveTo(0, stripe); pixmapIndentGuideHighlight.LineTo(2, stripe); } } - + if (bufferedDraw) { if (!pixmapLine.Initialised()) { pixmapLine.InitPixMap(rcClient.Width(), rcClient.Height(), @@ -1081,7 +1105,7 @@ void Editor::Paint(Surface *surfaceWindow, PRectangle rcArea) { int screenLinePaintFirst = rcArea.top / vs.lineHeight; // The area to be painted plus one extra line is styled. // The extra line is to determine when a style change, such as statrting a comment flows on to other lines. - int lineStyleLast = topLine + (rcArea.bottom-1) / vs.lineHeight + 1; + int lineStyleLast = topLine + (rcArea.bottom - 1) / vs.lineHeight + 1; //Platform::DebugPrintf("Paint lines = %d .. %d\n", topLine + screenLinePaintFirst, lineStyleLast); int endPosPaint = pdoc->Length(); if (lineStyleLast < cs.LinesDisplayed()) @@ -1100,20 +1124,20 @@ void Editor::Paint(Surface *surfaceWindow, PRectangle rcArea) { NotifyUpdateUI(); needUpdateUI = false; } - + PaintSelMargin(surfaceWindow, rcArea); PRectangle rcRightMargin = rcClient; rcRightMargin.left = rcRightMargin.right - vs.rightMarginWidth; if (rcArea.Intersects(rcRightMargin)) { - surfaceWindow->FillRectangle(rcRightMargin, vs.styles[STYLE_DEFAULT].back.allocated); + surfaceWindow->FillRectangle(rcRightMargin, vs.styles[STYLE_DEFAULT].back.allocated); } if (paintState == paintAbandoned) { // Either styling or NotifyUpdateUI noticed that painting is needed // outside the current painting rectangle //Platform::DebugPrintf("Abandoning paint\n"); - return; + return ; } //Platform::DebugPrintf("start display %d, offset = %d\n", pdoc->Length(), xOffset); @@ -1156,19 +1180,23 @@ void Editor::Paint(Surface *surfaceWindow, PRectangle rcArea) { // and determine the x position at which each character starts. LineLayout ll; LayoutLine(line, surface, vs, ll); - + // Highlight the current braces if any - if ((braces[0] >= posLineStart) && (braces[0] < posLineEnd)) - ll.styles[braces[0] - posLineStart] = - static_cast<char>(bracesMatchStyle); - if ((braces[1] >= posLineStart) && (braces[1] < posLineEnd)) - ll.styles[braces[1] - posLineStart] = - static_cast<char>(bracesMatchStyle); + if ((braces[0] >= posLineStart) && (braces[0] < posLineEnd)) { + int braceOffset = braces[0] - posLineStart; + if (braceOffset < ll.numCharsInLine) + ll.styles[braceOffset] = static_cast<char>(bracesMatchStyle); + } + if ((braces[1] >= posLineStart) && (braces[1] < posLineEnd)) { + int braceOffset = braces[1] - posLineStart; + if (braceOffset < ll.numCharsInLine) + ll.styles[braceOffset] = static_cast<char>(bracesMatchStyle); + } if ((braces[0] >= posLineStart && braces[1] <= posLineEnd) || - (braces[1] >= posLineStart && braces[0] <= posLineEnd)) { + (braces[1] >= posLineStart && braces[0] <= posLineEnd)) { ll.xHighlightGuide = highlightGuideColumn * vs.spaceWidth; } - + ll.selStart = SelectionStart(line); ll.selEnd = SelectionEnd(line); if (hideSelection) { @@ -1177,7 +1205,7 @@ void Editor::Paint(Surface *surfaceWindow, PRectangle rcArea) { } // Need to fix this up so takes account of Unicode and DBCS ll.edgeColumn = theEdge; - + // Draw the line if (cs.GetVisible(line)) DrawLine(surface, vs, line, visibleLine, xStart, rcLine, ll); @@ -1197,7 +1225,7 @@ void Editor::Paint(Surface *surfaceWindow, PRectangle rcArea) { surface->FillRectangle(rcFoldLine, vs.styles[STYLE_DEFAULT].fore.allocated); } } - + // Draw the Caret if (line == lineCaret) { int offset = Platform::Minimum(posCaret - posLineStart, LineLayout::maxLineLength); @@ -1228,12 +1256,12 @@ void Editor::Paint(Surface *surfaceWindow, PRectangle rcArea) { surface->FillRectangle(rcCaret, vs.caretcolour.allocated); } } - + if (cs.GetVisible(line)) { if (bufferedDraw) { Point from(vs.fixedColumnWidth, 0); PRectangle rcCopyArea(vs.fixedColumnWidth, yposScreen, - rcClient.right, yposScreen + vs.lineHeight); + rcClient.right, yposScreen + vs.lineHeight); surfaceWindow->Copy(rcCopyArea, from, pixmapLine); } } @@ -1250,6 +1278,7 @@ void Editor::Paint(Surface *surfaceWindow, PRectangle rcArea) { //Platform::DebugPrintf("Paint [%0d] took %g\n", line, g_timer_elapsed(tim, 0)); } //g_timer_destroy(tim); + PRectangle rcBeyondEOF = rcClient; rcBeyondEOF.left = vs.fixedColumnWidth; rcBeyondEOF.right = rcBeyondEOF.right; @@ -1276,11 +1305,11 @@ Colour InvertedLight(Colour orig) { unsigned int l = (r + g + b) / 3; // There is a better calculation for this that matches human eye unsigned int il = 0xff - l; if (l == 0) - return Colour(0xff,0xff,0xff); + return Colour(0xff, 0xff, 0xff); r = r * il / l; g = g * il / l; b = b * il / l; - return Colour(Platform::Minimum(r, 0xff),Platform::Minimum(g, 0xff),Platform::Minimum(b, 0xff)); + return Colour(Platform::Minimum(r, 0xff), Platform::Minimum(g, 0xff), Platform::Minimum(b, 0xff)); } // This is mostly copied from the Paint method but with some things omitted @@ -1296,13 +1325,13 @@ long Editor::FormatRange(bool draw, RangeToFormat *pfr) { Surface *surfaceMeasure = new Surface(); surfaceMeasure->Init(pfr->hdcTarget); surfaceMeasure->SetUnicodeMode(SC_CP_UTF8 == pdoc->dbcsCodePage); - + ViewStyle vsPrint(vs); - + // Modify the view style for printing as do not normally want any of the transient features to be printed // Printing supports only the line number margin. int lineNumberIndex = -1; - for (int margin=0; margin < ViewStyle::margins; margin++) { + for (int margin = 0; margin < ViewStyle::margins; margin++) { if ((!vsPrint.ms[margin].symbol) && (vsPrint.ms[margin].width > 0)) { lineNumberIndex = margin; } else { @@ -1317,18 +1346,18 @@ long Editor::FormatRange(bool draw, RangeToFormat *pfr) { vsPrint.selbackset = false; vsPrint.selforeset = false; // White background for the line numbers - vsPrint.styles[STYLE_LINENUMBER].back.desired = Colour(0xff,0xff,0xff); - for (int sty=0;sty<=STYLE_MAX;sty++) { + vsPrint.styles[STYLE_LINENUMBER].back.desired = Colour(0xff, 0xff, 0xff); + for (int sty = 0;sty <= STYLE_MAX;sty++) { if (printColourMode == SC_PRINT_INVERTLIGHT) { - vsPrint.styles[sty].fore.desired = InvertedLight(vsPrint.styles[sty].fore.desired); - vsPrint.styles[sty].back.desired = InvertedLight(vsPrint.styles[sty].back.desired); + vsPrint.styles[sty].fore.desired = InvertedLight(vsPrint.styles[sty].fore.desired); + vsPrint.styles[sty].back.desired = InvertedLight(vsPrint.styles[sty].back.desired); } else if (printColourMode == SC_PRINT_BLACKONWHITE) { - vsPrint.styles[sty].fore.desired = Colour(0,0,0); - vsPrint.styles[sty].back.desired = Colour(0xff,0xff,0xff); + vsPrint.styles[sty].fore.desired = Colour(0, 0, 0); + vsPrint.styles[sty].back.desired = Colour(0xff, 0xff, 0xff); } } - vsPrint.styles[STYLE_LINENUMBER].back.desired = Colour(0xff,0xff,0xff); - + vsPrint.styles[STYLE_LINENUMBER].back.desired = Colour(0xff, 0xff, 0xff); + vsPrint.Refresh(*surfaceMeasure); // Ensure colours are set up vsPrint.RefreshColourPalette(palette, true); @@ -1336,8 +1365,8 @@ long Editor::FormatRange(bool draw, RangeToFormat *pfr) { // Determining width must hapen after fonts have been realised in Refresh int lineNumberWidth = 0; if (lineNumberIndex >= 0) { - lineNumberWidth = surface->WidthText(vsPrint.styles[STYLE_LINENUMBER].font, - "9999" lineNumberPrintSpace, 4 + strlen(lineNumberPrintSpace)); + lineNumberWidth = surface->WidthText(vsPrint.styles[STYLE_LINENUMBER].font, + "9999" lineNumberPrintSpace, 4 + strlen(lineNumberPrintSpace)); vsPrint.ms[lineNumberIndex].width = lineNumberWidth; } @@ -1371,26 +1400,26 @@ long Editor::FormatRange(bool draw, RangeToFormat *pfr) { rcLine.top = ypos; rcLine.right = pfr->rc.right; rcLine.bottom = ypos + vsPrint.lineHeight; - + if (lineNumberWidth) { char number[100]; sprintf(number, "%d" lineNumberPrintSpace, line + 1); PRectangle rcNumber = rcLine; rcNumber.right = rcNumber.left + lineNumberWidth; // Right justify - rcNumber.left -= - surface->WidthText(vsPrint.styles[STYLE_LINENUMBER].font, number, strlen(number)); + rcNumber.left -= + surface->WidthText(vsPrint.styles[STYLE_LINENUMBER].font, number, strlen(number)); surface->DrawText(rcNumber, vsPrint.styles[STYLE_LINENUMBER].font, ypos + vsPrint.maxAscent, number, strlen(number), - vsPrint.styles[STYLE_LINENUMBER].fore.allocated, - vsPrint.styles[STYLE_LINENUMBER].back.allocated); + vsPrint.styles[STYLE_LINENUMBER].fore.allocated, + vsPrint.styles[STYLE_LINENUMBER].back.allocated); } // When printing, the hdc and hdcTarget may be the same, so // changing the state of surfaceMeasure may change the underlying - // state of surface. Therefore, any cached state is discarded before + // state of surface. Therefore, any cached state is discarded before // using each surface. - + // Copy this line and its styles from the document into local arrays // and determine the x position at which each character starts. surfaceMeasure->FlushCachedState(); @@ -1400,7 +1429,7 @@ long Editor::FormatRange(bool draw, RangeToFormat *pfr) { ll.selEnd = -1; // Need to fix this up so takes account of Unicode and DBCS ll.edgeColumn = theEdge; - + // Draw the line surface->FlushCachedState(); DrawLine(surface, vsPrint, line, line, xStart, rcLine, ll); @@ -1417,8 +1446,8 @@ long Editor::FormatRange(bool draw, RangeToFormat *pfr) { } // Empty method is overridden on GTK+ to show / hide scrollbars -void Editor::ReconfigureScrollBars() { -} +void Editor::ReconfigureScrollBars() {} + void Editor::SetScrollBarsTo(PRectangle) { RefreshStyleData(); @@ -1439,6 +1468,7 @@ void Editor::SetScrollBarsTo(PRectangle) { //Platform::DebugPrintf("end max = %d page = %d\n", nMax, nPage); } + void Editor::SetScrollBars() { PRectangle rsClient = GetClientRectangle(); SetScrollBarsTo(rsClient); @@ -1465,7 +1495,7 @@ void Editor::AddCharUTF(char *s, unsigned int len) { SetEmptySelection(currentPos + len); EnsureCaretVisible(); // Avoid blinking during rapid typing: - ShowCaretAtCurrentPosition(); + ShowCaretAtCurrentPosition(); SetLastXChosen(); NotifyChar(s[0]); } @@ -1476,7 +1506,7 @@ void Editor::ClearSelection() { int lineStart = pdoc->LineFromPosition(SelectionStart()); int lineEnd = pdoc->LineFromPosition(SelectionEnd()); int startPos = SelectionStart(); - for (int line=lineEnd; line >= lineStart; line--) { + for (int line = lineEnd; line >= lineStart; line--) { startPos = SelectionStart(line); unsigned int chars = SelectionEnd(line) - startPos; if (0 != chars) { @@ -1511,7 +1541,7 @@ void Editor::ClearDocumentStyle() { pdoc->StartStyling(0, '\377'); pdoc->SetStyleFor(pdoc->Length(), 0); cs.ShowAll(); - pdoc->ClearLevels(); + pdoc->ClearLevels(); } void Editor::Cut() { @@ -1525,9 +1555,9 @@ void Editor::PasteRectangular(int pos, const char *ptr, int len) { int xInsert = XFromPosition(currentPos); int line = pdoc->LineFromPosition(currentPos); bool prevCr = false; - for (int i=0; i<len; i++) { + for (int i = 0; i < len; i++) { if ((ptr[i] == '\r') || (ptr[i] == '\n')) { - if ((ptr[i] == '\r') || (!prevCr)) + if ((ptr[i] == '\r') || (!prevCr)) line++; if (line >= pdoc->LinesTotal()) { if (pdoc->eolMode != SC_EOL_LF) @@ -1538,7 +1568,7 @@ void Editor::PasteRectangular(int pos, const char *ptr, int len) { currentPos = PositionFromLineX(line, xInsert); prevCr = ptr[i] == '\r'; } else { - pdoc->InsertString(currentPos, ptr+i, 1); + pdoc->InsertString(currentPos, ptr + i, 1); currentPos++; insertPos = currentPos; prevCr = false; @@ -1580,7 +1610,7 @@ void Editor::Redo() { void Editor::DelChar() { pdoc->DelChar(currentPos); // Avoid blinking during rapid typing: - ShowCaretAtCurrentPosition(); + ShowCaretAtCurrentPosition(); } void Editor::DelCharBack() { @@ -1592,11 +1622,11 @@ void Editor::DelCharBack() { SetEmptySelection(currentPos); } // Avoid blinking during rapid typing: - ShowCaretAtCurrentPosition(); + ShowCaretAtCurrentPosition(); } -void Editor::NotifyFocus(bool) { -} +void Editor::NotifyFocus(bool) {} + void Editor::NotifyStyleToNeeded(int endStyleNeeded) { SCNotification scn; @@ -1621,7 +1651,7 @@ void Editor::NotifyChar(char ch) { txt[1] = '\0'; NotifyMacroRecord(SCI_REPLACESEL, 0, reinterpret_cast<long>(txt)); } -#endif +#endif } void Editor::NotifySavePoint(bool isSavePoint) { @@ -1655,7 +1685,7 @@ void Editor::NotifyUpdateUI() { bool Editor::NotifyMarginClick(Point pt, bool shift, bool ctrl, bool alt) { int marginClicked = -1; int x = 0; - for (int margin=0; margin < ViewStyle::margins; margin++) { + for (int margin = 0; margin < ViewStyle::margins; margin++) { if ((pt.x > x) && (pt.x < x + vs.ms[margin].width)) marginClicked = margin; x += vs.ms[margin].width; @@ -1751,15 +1781,15 @@ void Editor::NotifyModified(Document*, DocModification mh, void *) { } } } - if (cs.LinesDisplayed() < cs.LinesInDoc()) { - // Some lines are hidden so may need shown. - // TODO: check if the modified area is hidden. - if (mh.modificationType & SC_MOD_BEFOREINSERT) { - NotifyNeedShown(mh.position, 0); - } else if (mh.modificationType & SC_MOD_BEFOREDELETE) { - NotifyNeedShown(mh.position, mh.length); - } - } + if (cs.LinesDisplayed() < cs.LinesInDoc()) { + // Some lines are hidden so may need shown. + // TODO: check if the modified area is hidden. + if (mh.modificationType & SC_MOD_BEFOREINSERT) { + NotifyNeedShown(mh.position, 0); + } else if (mh.modificationType & SC_MOD_BEFOREDELETE) { + NotifyNeedShown(mh.position, mh.length); + } + } if (mh.linesAdded != 0) { // Update contraction state for inserted and removed lines @@ -1778,7 +1808,7 @@ void Editor::NotifyModified(Document*, DocModification mh, void *) { SetVerticalScrollPos(); } } - + //Platform::DebugPrintf("** %x Doc Changed\n", this); // TODO: could invalidate from mh.startModification to end of screen //InvalidateRange(mh.position, mh.position + mh.length); @@ -1798,13 +1828,14 @@ void Editor::NotifyModified(Document*, DocModification mh, void *) { if (mh.modificationType & SC_MOD_CHANGEMARKER) { RedrawSelMargin(); } - + // If client wants to see this modification if (mh.modificationType & modEventMask) { if ((mh.modificationType & SC_MOD_CHANGESTYLE) == 0) { // Real modification made to text of document. NotifyChange(); // Send EN_CHANGE } + SCNotification scn; scn.nmhdr.code = SCN_MODIFIED; scn.position = mh.position; @@ -1884,10 +1915,11 @@ void Editor::NotifyMacroRecord(unsigned int iMessage, unsigned long wParam, long case SCI_UPPERCASE: break; - // Filter out all others (display changes, etc) + // Filter out all others (display changes, etc) default: -// printf("Filtered out %ld of macro recording\n", iMessage); - return; + // printf("Filtered out %ld of macro recording\n", iMessage); + + return ; } // Send notification @@ -1898,13 +1930,13 @@ void Editor::NotifyMacroRecord(unsigned int iMessage, unsigned long wParam, long scn.lParam = lParam; NotifyParent(scn); } -#endif +#endif // Force scroll and keep position relative to top of window void Editor::PageMove(int direction, bool extend) { Point pt = LocationFromPosition(currentPos); int topLineNew = Platform::Clamp( - topLine + direction * LinesToScroll(), 0, MaxScrollPos()); + topLine + direction * LinesToScroll(), 0, MaxScrollPos()); int newPos = PositionFromLocation( Point(lastXChosen, pt.y + direction * (vs.lineHeight * LinesToScroll()))); if (topLineNew != topLine) { @@ -1924,17 +1956,17 @@ void Editor::ChangeCaseOfSelection(bool makeUpperCase) { if (selType == selRectangle) { int lineStart = pdoc->LineFromPosition(SelectionStart()); int lineEnd = pdoc->LineFromPosition(SelectionEnd()); - for (int line=lineEnd; line >= lineStart; line--) { + for (int line = lineEnd; line >= lineStart; line--) { pdoc->ChangeCase( - Range(SelectionStart(line), SelectionEnd(line)), - makeUpperCase); + Range(SelectionStart(line), SelectionEnd(line)), + makeUpperCase); } // Would be nicer to keep the rectangular selection but this is complex selType = selStream; SetSelection(startCurrent, startCurrent); } else { - pdoc->ChangeCase(Range(SelectionStart(), SelectionEnd()), - makeUpperCase); + pdoc->ChangeCase(Range(SelectionStart(), SelectionEnd()), + makeUpperCase); SetSelection(startCurrent, startAnchor); } pdoc->EndUndoAction(); @@ -1944,35 +1976,35 @@ void Editor::ChangeCaseOfSelection(bool makeUpperCase) { void Editor::LineTranspose() { int line = pdoc->LineFromPosition(currentPos); if (line > 0) { - int startPrev = pdoc->LineStart(line-1); - int endPrev = pdoc->LineEnd(line-1); + int startPrev = pdoc->LineStart(line - 1); + int endPrev = pdoc->LineEnd(line - 1); int start = pdoc->LineStart(line); int end = pdoc->LineEnd(line); - int startNext = pdoc->LineStart(line+1); + int startNext = pdoc->LineStart(line + 1); if (end < pdoc->Length()) { end = startNext; char *thisLine = CopyRange(start, end); - pdoc->DeleteChars(start, end-start); - pdoc->InsertString(startPrev, thisLine, end-start); - MovePositionTo(startPrev+end-start); + pdoc->DeleteChars(start, end - start); + pdoc->InsertString(startPrev, thisLine, end - start); + MovePositionTo(startPrev + end - start); delete []thisLine; } else { // Last line so line has no line end char *thisLine = CopyRange(start, end); char *prevEnd = CopyRange(endPrev, start); - pdoc->DeleteChars(endPrev, end-endPrev); - pdoc->InsertString(startPrev, thisLine, end-start); - pdoc->InsertString(startPrev + end-start, prevEnd, start-endPrev); - MovePositionTo(startPrev + end-endPrev); + pdoc->DeleteChars(endPrev, end - endPrev); + pdoc->InsertString(startPrev, thisLine, end - start); + pdoc->InsertString(startPrev + end - start, prevEnd, start - endPrev); + MovePositionTo(startPrev + end - endPrev); delete []thisLine; delete []prevEnd; } - + } } -void Editor::CancelModes() { -} +void Editor::CancelModes() {} + int Editor::KeyCommand(unsigned int iMessage) { Point pt = LocationFromPosition(currentPos); @@ -2091,9 +2123,9 @@ int Editor::KeyCommand(unsigned int iMessage) { DropCaret(); ShowCaretAtCurrentPosition(); break; - case SCI_CANCEL: // Cancel any modes - handled in subclass + case SCI_CANCEL: // Cancel any modes - handled in subclass // Also unselect text - CancelModes(); + CancelModes(); break; case SCI_DELETEBACK: DelCharBack(); @@ -2172,16 +2204,16 @@ int Editor::KeyCommand(unsigned int iMessage) { lineStart = t; } int start = pdoc->LineStart(lineStart); - int end = pdoc->LineStart(lineEnd+1); - SetSelection(start,end); + int end = pdoc->LineStart(lineEnd + 1); + SetSelection(start, end); Cut(); } break; case SCI_LINEDELETE: { int line = pdoc->LineFromPosition(currentPos); int start = pdoc->LineStart(line); - int end = pdoc->LineStart(line+1); - pdoc->DeleteChars(start, end-start); + int end = pdoc->LineStart(line + 1); + pdoc->DeleteChars(start, end - start); MovePositionTo(start); } break; @@ -2230,7 +2262,7 @@ void Editor::Indent(bool forwards) { pdoc->InsertChar(currentPos, '\t'); SetEmptySelection(currentPos + 1); } else { - for (int i=0; i<pdoc->tabInChars; i++){ + for (int i = 0; i < pdoc->tabInChars; i++) { pdoc->InsertChar(currentPos, ' '); } SetEmptySelection(currentPos + pdoc->tabInChars); @@ -2263,7 +2295,7 @@ void Editor::Indent(bool forwards) { long Editor::FindText(unsigned int iMessage, unsigned long wParam, long lParam) { TextToFind *ft = reinterpret_cast<TextToFind *>(lParam); int pos = pdoc->FindText(ft->chrg.cpMin, ft->chrg.cpMax, ft->lpstrText, - wParam & SCFIND_MATCHCASE, wParam & SCFIND_WHOLEWORD); + wParam & SCFIND_MATCHCASE, wParam & SCFIND_WHOLEWORD); if (pos != -1) { if (iMessage != EM_FINDTEXT) { ft->chrgText.cpMin = pos; @@ -2273,8 +2305,8 @@ long Editor::FindText(unsigned int iMessage, unsigned long wParam, long lParam) return pos; } -// Relocatable search support : Searches relative to current selection -// point and sets the selection to the found text range with +// Relocatable search support : Searches relative to current selection +// point and sets the selection to the found text range with // each search. // Anchor following searches at current selection start: This allows @@ -2294,11 +2326,11 @@ long Editor::SearchText(unsigned int iMessage, unsigned long wParam, long lParam int pos; if (iMessage == SCI_SEARCHNEXT) { - pos = pdoc->FindText(searchAnchor, pdoc->Length(), txt, + pos = pdoc->FindText(searchAnchor, pdoc->Length(), txt, wParam & SCFIND_MATCHCASE, wParam & SCFIND_WHOLEWORD); } else { - pos = pdoc->FindText(searchAnchor, 0, txt, + pos = pdoc->FindText(searchAnchor, 0, txt, wParam & SCFIND_MATCHCASE, wParam & SCFIND_WHOLEWORD); } @@ -2348,7 +2380,7 @@ int Editor::SelectionRangeLength() { int lineStart = pdoc->LineFromPosition(SelectionStart()); int lineEnd = pdoc->LineFromPosition(SelectionEnd()); int totalSize = 0; - for (int line=lineStart; line <= lineEnd; line++) { + for (int line = lineStart; line <= lineEnd; line++) { totalSize += SelectionEnd(line) - SelectionStart(line) + 1; if (pdoc->eolMode == SC_EOL_CRLF) totalSize++; @@ -2369,8 +2401,8 @@ char *Editor::CopySelectionRange() { text = new char[totalSize + 1]; if (text) { int j = 0; - for (int line=lineStart; line <= lineEnd; line++) { - for (int i=SelectionStart(line);i<SelectionEnd(line);i++) { + for (int line = lineStart; line <= lineEnd; line++) { + for (int i = SelectionStart(line);i < SelectionEnd(line);i++) { text[j++] = pdoc->CharAt(i); } if (pdoc->eolMode != SC_EOL_LF) @@ -2400,7 +2432,7 @@ void Editor::CopySelectionIntoDrag() { void Editor::SetDragPosition(int newPos) { if (newPos >= 0) { - newPos = pdoc->MovePositionOutsideChar(newPos, 1); + newPos = MovePositionOutsideChar(newPos, 1); posDrop = newPos; } if (posDrag != newPos) { @@ -2418,6 +2450,7 @@ void Editor::StartDrag() { //wDraw.SetCursor(Window::cursorArrow); } + void Editor::DropAt(int position, const char *value, bool moving, bool rectangular) { //Platform::DebugPrintf("DropAt %d\n", inDragDrop); if (inDragDrop) @@ -2425,15 +2458,15 @@ void Editor::DropAt(int position, const char *value, bool moving, bool rectangul int positionWasInSelection = PositionInSelection(position); - bool positionOnEdgeOfSelection = - (position == SelectionStart()) || (position == SelectionEnd()); + bool positionOnEdgeOfSelection = + (position == SelectionStart()) || (position == SelectionEnd()); - if ((!inDragDrop) || !(0 == positionWasInSelection) || - (positionOnEdgeOfSelection && !moving)) { + if ((!inDragDrop) || !(0 == positionWasInSelection) || + (positionOnEdgeOfSelection && !moving)) { int selStart = SelectionStart(); int selEnd = SelectionEnd(); - + pdoc->BeginUndoAction(); int positionAfterDeletion = position; @@ -2442,7 +2475,7 @@ void Editor::DropAt(int position, const char *value, bool moving, bool rectangul if (rectangular) { int lineStart = pdoc->LineFromPosition(SelectionStart()); int lineEnd = pdoc->LineFromPosition(SelectionEnd()); - for (int line=lineStart; line <= lineEnd; line++) { + for (int line = lineStart; line <= lineEnd; line++) { int startPos = SelectionStart(line); int endPos = SelectionEnd(line); if (position >= startPos) { @@ -2461,14 +2494,14 @@ void Editor::DropAt(int position, const char *value, bool moving, bool rectangul ClearSelection(); } position = positionAfterDeletion; - + if (rectangular) { PasteRectangular(position, value, strlen(value)); pdoc->EndUndoAction(); // Should try to select new rectangle but it may not be a rectangle now so just select the drop position - SetSelection(position, position); + SetSelection(position, position); } else { - position = pdoc->MovePositionOutsideChar(position, currentPos - position); + position = MovePositionOutsideChar(position, currentPos - position); pdoc->InsertString(position, value); pdoc->EndUndoAction(); SetSelection(position + strlen(value), position); @@ -2488,7 +2521,7 @@ static int BeforeInOrAfter(int val, int minim, int maxim) { } int Editor::PositionInSelection(int pos) { - pos = pdoc->MovePositionOutsideChar(pos, currentPos - pos); + pos = MovePositionOutsideChar(pos, currentPos - pos); if (selType == selRectangle) { if (pos < SelectionStart()) return -1; @@ -2542,13 +2575,13 @@ void Editor::ButtonDown(Point pt, unsigned int curTime, bool shift, bool ctrl, b //Platform::DebugPrintf("Scintilla:ButtonDown %d %d = %d alt=%d\n", curTime, lastClickTime, curTime - lastClickTime, alt); ptMouseLast = pt; int newPos = PositionFromLocation(pt); - newPos = pdoc->MovePositionOutsideChar(newPos, currentPos - newPos); + newPos = MovePositionOutsideChar(newPos, currentPos - newPos); inDragDrop = false; - + bool processed = NotifyMarginClick(pt, shift, ctrl, alt); if (processed) - return; - + return ; + if (shift) { SetSelection(newPos); } @@ -2594,7 +2627,7 @@ void Editor::ButtonDown(Point pt, unsigned int curTime, bool shift, bool ctrl, b if (ctrl) { SelectAll(); lastClickTime = curTime; - return; + return ; } lineAnchor = LineFromLocation(pt); // While experimenting with folding turn off line selection @@ -2641,7 +2674,7 @@ void Editor::ButtonMove(Point pt) { xEndSelect = pt.x - vs.fixedColumnWidth + xOffset; ptMouseLast = pt; int movePos = PositionFromLocation(pt); - movePos = pdoc->MovePositionOutsideChar(movePos, currentPos - movePos); + movePos = MovePositionOutsideChar(movePos, currentPos - movePos); if (posDrag >= 0) { SetDragPosition(movePos); } else { @@ -2661,10 +2694,10 @@ void Editor::ButtonMove(Point pt) { int lineMove = LineFromLocation(pt); if (lineAnchor < lineMove) { SetSelection(pdoc->LineStart(lineMove + 1), - pdoc->LineStart(lineAnchor)); + pdoc->LineStart(lineAnchor)); } else { SetSelection(pdoc->LineStart(lineMove), - pdoc->LineStart(lineAnchor + 1)); + pdoc->LineStart(lineAnchor + 1)); } } } @@ -2673,8 +2706,9 @@ void Editor::ButtonMove(Point pt) { if (vs.fixedColumnWidth > 0) { // There is a margin if (PointInSelMargin(pt)) { wDraw.SetCursor(Window::cursorReverseArrow); - return; // No need to test for selection + return ; // No need to test for selection } + } // Display regular (drag) cursor over selection if (PointInSelection(pt)) @@ -2697,7 +2731,7 @@ void Editor::ButtonUp(Point pt, unsigned int curTime, bool ctrl) { ptMouseLast = pt; SetMouseCapture(false); int newPos = PositionFromLocation(pt); - newPos = pdoc->MovePositionOutsideChar(newPos, currentPos - newPos); + newPos = MovePositionOutsideChar(newPos, currentPos - newPos); if (inDragDrop) { int selStart = SelectionStart(); int selEnd = SelectionEnd(); @@ -2759,53 +2793,53 @@ static bool IsIn(int a, int minimum, int maximum) { } static bool IsOverlap(int mina, int maxa, int minb, int maxb) { - return - IsIn(mina, minb, maxb) || - IsIn(maxa, minb, maxb) || - IsIn(minb, mina, maxa) || - IsIn(maxb, mina, maxa); + return + IsIn(mina, minb, maxb) || + IsIn(maxa, minb, maxb) || + IsIn(minb, mina, maxa) || + IsIn(maxb, mina, maxa); } void Editor::CheckForChangeOutsidePaint(Range r) { if (paintState == painting && !paintingAllText) { //Platform::DebugPrintf("Checking range in paint %d-%d\n", r.start, r.end); if (!r.Valid()) - return; - + return ; + PRectangle rcText = GetTextRectangle(); // Determine number of lines displayed including a possible partially displayed last line int linesDisplayed = (rcText.bottom - rcText.top - 1) / vs.lineHeight + 1; int bottomLine = topLine + linesDisplayed - 1; - + int lineRangeStart = cs.DisplayFromDoc(pdoc->LineFromPosition(r.start)); int lineRangeEnd = cs.DisplayFromDoc(pdoc->LineFromPosition(r.end)); if (!IsOverlap(topLine, bottomLine, lineRangeStart, lineRangeEnd)) { //Platform::DebugPrintf("No overlap (%d-%d) with window(%d-%d)\n", // lineRangeStart, lineRangeEnd, topLine, bottomLine); - return; + return ; } - + // Assert rcPaint contained within or equal to rcText if (rcPaint.top > rcText.top) { - // does range intersect rcText.top .. rcPaint.top - int paintTopLine = ((rcPaint.top - rcText.top-1) / vs.lineHeight) + topLine; + // does range intersect rcText.top .. rcPaint.top + int paintTopLine = ((rcPaint.top - rcText.top - 1) / vs.lineHeight) + topLine; // paintTopLine is the top line of the paint rectangle or the line just above if that line is completely inside the paint rectangle if (IsOverlap(topLine, paintTopLine, lineRangeStart, lineRangeEnd)) { - //Platform::DebugPrintf("Change (%d-%d) in top npv(%d-%d)\n", + //Platform::DebugPrintf("Change (%d-%d) in top npv(%d-%d)\n", // lineRangeStart, lineRangeEnd, topLine, paintTopLine); paintState = paintAbandoned; - return; + return ; } } if (rcPaint.bottom < rcText.bottom) { // does range intersect rcPaint.bottom .. rcText.bottom - int paintBottomLine = ((rcPaint.bottom - rcText.top-1) / vs.lineHeight + 1) + topLine; + int paintBottomLine = ((rcPaint.bottom - rcText.top - 1) / vs.lineHeight + 1) + topLine; // paintTopLine is the bottom line of the paint rectangle or the line just below if that line is completely inside the paint rectangle if (IsOverlap(paintBottomLine, bottomLine, lineRangeStart, lineRangeEnd)) { - //Platform::DebugPrintf("Change (%d-%d) in bottom npv(%d-%d)\n", + //Platform::DebugPrintf("Change (%d-%d) in bottom npv(%d-%d)\n", // lineRangeStart, lineRangeEnd, paintBottomLine, bottomLine); paintState = paintAbandoned; - return; + return ; } } } @@ -2813,15 +2847,24 @@ void Editor::CheckForChangeOutsidePaint(Range r) { char BraceOpposite(char ch) { switch (ch) { - case '(': return ')'; - case ')': return '('; - case '[': return ']'; - case ']': return '['; - case '{': return '}'; - case '}': return '{'; - case '<': return '>'; - case '>': return '<'; - default: return '\0'; + case '(': + return ')'; + case ')': + return '('; + case '[': + return ']'; + case ']': + return '['; + case '{': + return '}'; + case '}': + return '{'; + case '<': + return '>'; + case '>': + return '<'; + default: + return '\0'; } } @@ -2834,7 +2877,7 @@ int Editor::BraceMatch(int position, int /*maxReStyle*/) { if (chSeek == '\0') return - 1; char styBrace = static_cast<char>( - pdoc->StyleAt(position) & pdoc->stylingBitsMask); + pdoc->StyleAt(position) & pdoc->stylingBitsMask); int direction = -1; if (chBrace == '(' || chBrace == '[' || chBrace == '{' || chBrace == '<') direction = 1; @@ -2858,12 +2901,12 @@ int Editor::BraceMatch(int position, int /*maxReStyle*/) { void Editor::SetBraceHighlight(Position pos0, Position pos1, int matchStyle) { if ((pos0 != braces[0]) || (pos1 != braces[1]) || (matchStyle != bracesMatchStyle)) { - if ((braces[0] != pos0) || (matchStyle != bracesMatchStyle)) { + if ((braces[0] != pos0) || (matchStyle != bracesMatchStyle)) { CheckForChangeOutsidePaint(Range(braces[0])); CheckForChangeOutsidePaint(Range(pos0)); braces[0] = pos0; } - if ((braces[1] != pos1) || (matchStyle != bracesMatchStyle)) { + if ((braces[1] != pos1) || (matchStyle != bracesMatchStyle)) { CheckForChangeOutsidePaint(Range(braces[1])); CheckForChangeOutsidePaint(Range(pos1)); braces[1] = pos1; @@ -2887,7 +2930,7 @@ void Editor::SetDocPointer(Document *document) { pdoc->AddRef(); // Reset the contraction state to fully shown. cs.Clear(); - cs.InsertLines(0, pdoc->LinesTotal()-1); + cs.InsertLines(0, pdoc->LinesTotal() - 1); pdoc->AddWatcher(this, 0); Redraw(); @@ -2920,7 +2963,7 @@ void Editor::ToggleContraction(int line) { int lineMaxSubord = pdoc->GetLastChild(line); cs.SetExpanded(line, 0); if (lineMaxSubord > line) { - cs.SetVisible(line+1, lineMaxSubord, false); + cs.SetVisible(line + 1, lineMaxSubord, false); SetScrollBars(); Redraw(); } @@ -2963,7 +3006,7 @@ long Editor::WndProc(unsigned int iMessage, unsigned long wParam, long lParam) { #ifdef MACRO_SUPPORT if (recordingMacro) NotifyMacroRecord(iMessage, wParam, lParam); -#endif +#endif switch (iMessage) { @@ -2974,7 +3017,7 @@ long Editor::WndProc(unsigned int iMessage, unsigned long wParam, long lParam) { return 0; char *ptr = reinterpret_cast<char *>(lParam); unsigned int iChar = 0; - for (; iChar < wParam-1; iChar++) + for (; iChar < wParam - 1; iChar++) ptr[iChar] = pdoc->CharAt(iChar); ptr[iChar] = '\0'; return iChar; @@ -3145,8 +3188,8 @@ long Editor::WndProc(unsigned int iMessage, unsigned long wParam, long lParam) { if (lParam) *reinterpret_cast<int *>(lParam) = SelectionEnd(); return Platform::LongFromTwoShorts( - static_cast<short>(SelectionStart()), - static_cast<short>(SelectionEnd())); + static_cast<short>(SelectionStart()), + static_cast<short>(SelectionEnd())); case EM_EXGETSEL: { if (lParam == 0) @@ -3157,9 +3200,8 @@ long Editor::WndProc(unsigned int iMessage, unsigned long wParam, long lParam) { } break; - case EM_SETSEL: - case SCI_SETSEL: - { + case EM_SETSEL: + case SCI_SETSEL: { int nStart = static_cast<int>(wParam); int nEnd = static_cast<int>(lParam); if (nEnd < 0) @@ -3230,8 +3272,7 @@ long Editor::WndProc(unsigned int iMessage, unsigned long wParam, long lParam) { // return -1; return pdoc->LineStart(wParam); - case EM_LINELENGTH: - { + case EM_LINELENGTH: { if (static_cast<int>(wParam) < 0) // Who use this anyway? return 0; // Should be... Too complex to describe here, see MS specs! if (static_cast<int>(wParam) > pdoc->Length()) // Useful test, anyway... @@ -3252,9 +3293,8 @@ long Editor::WndProc(unsigned int iMessage, unsigned long wParam, long lParam) { return 0; return pdoc->LineStart(wParam + 1) - pdoc->LineStart(wParam); - case EM_REPLACESEL: - case SCI_REPLACESEL: - { + case EM_REPLACESEL: + case SCI_REPLACESEL: { if (lParam == 0) return 0; pdoc->BeginUndoAction(); @@ -3297,7 +3337,7 @@ long Editor::WndProc(unsigned int iMessage, unsigned long wParam, long lParam) { int pos = PositionFromLocation(*ppt); int line = pdoc->LineFromPosition(pos); return Platform::LongFromTwoShorts( - static_cast<short>(pos), static_cast<short>(line)); + static_cast<short>(pos), static_cast < short > (line)); } case EM_POSFROMCHAR: { @@ -3326,7 +3366,7 @@ long Editor::WndProc(unsigned int iMessage, unsigned long wParam, long lParam) { return 0; } else { Point pt = LocationFromPosition(lParam); - return pt.y; + return pt.y; } case EM_FINDTEXT: @@ -3336,9 +3376,8 @@ long Editor::WndProc(unsigned int iMessage, unsigned long wParam, long lParam) { case SCI_FINDTEXT: return FindText(iMessage, wParam, lParam); - case EM_GETTEXTRANGE: - case SCI_GETTEXTRANGE: - { + case EM_GETTEXTRANGE: + case SCI_GETTEXTRANGE: { if (lParam == 0) return 0; TextRange *tr = reinterpret_cast<TextRange *>(lParam); @@ -3352,15 +3391,16 @@ long Editor::WndProc(unsigned int iMessage, unsigned long wParam, long lParam) { return len; // Not including NUL } + case EM_SELECTIONTYPE: #ifdef SEL_EMPTY if (currentPos == anchor) return SEL_EMPTY; else return SEL_TEXT; -#else +#else return 0; -#endif +#endif case EM_HIDESELECTION: hideSelection = wParam; @@ -3372,15 +3412,15 @@ long Editor::WndProc(unsigned int iMessage, unsigned long wParam, long lParam) { return FormatRange(wParam, reinterpret_cast<RangeToFormat *>(lParam)); case EM_GETMARGINS: - return Platform::LongFromTwoShorts(static_cast<short>(vs.leftMarginWidth), - static_cast<short>(vs.rightMarginWidth)); - + return Platform::LongFromTwoShorts(static_cast<short>(vs.leftMarginWidth), + static_cast<short>(vs.rightMarginWidth)); + case SCI_GETMARGINLEFT: return vs.leftMarginWidth; - + case SCI_GETMARGINRIGHT: return vs.rightMarginWidth; - + case EM_SETMARGINS: #ifdef EC_LEFTMARGIN if (wParam & EC_LEFTMARGIN) { @@ -3394,19 +3434,19 @@ long Editor::WndProc(unsigned int iMessage, unsigned long wParam, long lParam) { vs.rightMarginWidth = vs.aveCharWidth / 2; } InvalidateStyleRedraw(); -#endif +#endif break; - + case SCI_SETMARGINLEFT: vs.leftMarginWidth = lParam; InvalidateStyleRedraw(); break; - + case SCI_SETMARGINRIGHT: vs.rightMarginWidth = lParam; InvalidateStyleRedraw(); break; - + // Control specific mesages case SCI_ADDTEXT: { @@ -3447,11 +3487,11 @@ long Editor::WndProc(unsigned int iMessage, unsigned long wParam, long lParam) { ClearAll(); return 0; - case SCI_CLEARDOCUMENTSTYLE: - ClearDocumentStyle(); - return 0; + case SCI_CLEARDOCUMENTSTYLE: + ClearDocumentStyle(); + return 0; - case SCI_SETUNDOCOLLECTION: + case SCI_SETUNDOCOLLECTION: pdoc->SetUndoCollection(wParam); return 0; @@ -3503,31 +3543,31 @@ long Editor::WndProc(unsigned int iMessage, unsigned long wParam, long lParam) { case SCI_SETSELECTIONSTART: SetSelection(Platform::Maximum(currentPos, wParam), wParam); break; - + case SCI_GETSELECTIONSTART: return Platform::Minimum(anchor, currentPos); - + case SCI_SETSELECTIONEND: SetSelection(wParam, Platform::Minimum(anchor, wParam)); break; - + case SCI_GETSELECTIONEND: return Platform::Maximum(anchor, currentPos); - + case SCI_SETPRINTMAGNIFICATION: printMagnification = wParam; break; - + case SCI_GETPRINTMAGNIFICATION: return printMagnification; - + case SCI_SETPRINTCOLOURMODE: printColourMode = wParam; break; - + case SCI_GETPRINTCOLOURMODE: return printColourMode; - + case SCI_GETSTYLEAT: if (static_cast<short>(wParam) >= pdoc->Length()) return 0; @@ -3578,7 +3618,7 @@ long Editor::WndProc(unsigned int iMessage, unsigned long wParam, long lParam) { vs.viewWhitespace = static_cast<WhiteSpaceVisibility>(wParam); Redraw(); break; - + case SCI_POSITIONFROMPOINT: return PositionFromLocation(Point(wParam, lParam)); @@ -3624,7 +3664,7 @@ long Editor::WndProc(unsigned int iMessage, unsigned long wParam, long lParam) { pdoc->SetStyleFor(wParam, static_cast<char>(lParam)); break; - case SCI_SETSTYLINGEX: // Specify a complete styling buffer + case SCI_SETSTYLINGEX: // Specify a complete styling buffer if (lParam == 0) return 0; pdoc->SetStyles(wParam, reinterpret_cast<char *>(lParam)); @@ -3645,12 +3685,12 @@ long Editor::WndProc(unsigned int iMessage, unsigned long wParam, long lParam) { case SCI_GETTABWIDTH: return pdoc->tabInChars; - + case SCI_SETINDENT: pdoc->indentInChars = wParam; InvalidateStyleRedraw(); break; - + case SCI_GETINDENT: return pdoc->indentInChars; @@ -3661,34 +3701,34 @@ long Editor::WndProc(unsigned int iMessage, unsigned long wParam, long lParam) { case SCI_GETUSETABS: return pdoc->useTabs; - + case SCI_SETLINEINDENTATION: pdoc->SetLineIndentation(wParam, lParam); break; - + case SCI_GETLINEINDENTATION: return pdoc->GetLineIndentation(wParam); - + case SCI_GETLINEINDENTPOSITION: return pdoc->GetLineIndentPosition(wParam); case SCI_GETCOLUMN: return pdoc->GetColumn(wParam); - + case SCI_SETHSCROLLBAR : horizontalScrollBarVisible = wParam; SetScrollBars(); ReconfigureScrollBars(); break; - + case SCI_GETHSCROLLBAR: return horizontalScrollBarVisible; - + case SCI_SETINDENTATIONGUIDES: vs.viewIndentationGuides = wParam; Redraw(); break; - + case SCI_GETINDENTATIONGUIDES: return vs.viewIndentationGuides; @@ -3698,13 +3738,13 @@ long Editor::WndProc(unsigned int iMessage, unsigned long wParam, long lParam) { Redraw(); } break; - + case SCI_GETHIGHLIGHTGUIDE: return highlightGuideColumn; - + case SCI_GETLINEENDPOSITION: return pdoc->LineEnd(wParam); - + case SCI_SETCODEPAGE: pdoc->dbcsCodePage = wParam; break; @@ -3778,48 +3818,48 @@ long Editor::WndProc(unsigned int iMessage, unsigned long wParam, long lParam) { InvalidateStyleRedraw(); } break; - + case SCI_GETMARGINTYPEN: - if (ValidMargin(wParam)) + if (ValidMargin(wParam)) return vs.ms[wParam].symbol ? SC_MARGIN_SYMBOL : SC_MARGIN_NUMBER; else return 0; - + case SCI_SETMARGINWIDTHN: if (ValidMargin(wParam)) { vs.ms[wParam].width = lParam; InvalidateStyleRedraw(); } break; - + case SCI_GETMARGINWIDTHN: - if (ValidMargin(wParam)) + if (ValidMargin(wParam)) return vs.ms[wParam].width; else return 0; - + case SCI_SETMARGINMASKN: if (ValidMargin(wParam)) { vs.ms[wParam].mask = lParam; InvalidateStyleRedraw(); } break; - + case SCI_GETMARGINMASKN: - if (ValidMargin(wParam)) + if (ValidMargin(wParam)) return vs.ms[wParam].mask; else return 0; - + case SCI_SETMARGINSENSITIVEN: if (ValidMargin(wParam)) { vs.ms[wParam].sensitive = lParam; InvalidateStyleRedraw(); } break; - + case SCI_GETMARGINSENSITIVEN: - if (ValidMargin(wParam)) + if (ValidMargin(wParam)) return vs.ms[wParam].sensitive ? 1 : 0; else return 0; @@ -3885,7 +3925,13 @@ long Editor::WndProc(unsigned int iMessage, unsigned long wParam, long lParam) { InvalidateStyleRedraw(); } break; - + case SCI_STYLESETVISIBLE: + if (wParam <= STYLE_MAX) { + vs.styles[wParam].visible = lParam; + InvalidateStyleRedraw(); + } + break; + case SCI_STYLERESETDEFAULT: vs.ResetDefaultStyle(); InvalidateStyleRedraw(); @@ -3893,24 +3939,24 @@ long Editor::WndProc(unsigned int iMessage, unsigned long wParam, long lParam) { case SCI_SETSTYLEBITS: pdoc->SetStylingBits(wParam); break; - + case SCI_GETSTYLEBITS: return pdoc->stylingBits; - + case SCI_SETLINESTATE: return pdoc->SetLineState(wParam, lParam); - + case SCI_GETLINESTATE: return pdoc->GetLineState(wParam); - + case SCI_GETMAXLINESTATE: return pdoc->GetMaxLineState(); - - // Folding messages - + + // Folding messages + case SCI_VISIBLEFROMDOCLINE: return cs.DisplayFromDoc(wParam); - + case SCI_DOCLINEFROMVISIBLE: return cs.DocFromDisplay(wParam); @@ -3920,40 +3966,40 @@ long Editor::WndProc(unsigned int iMessage, unsigned long wParam, long lParam) { RedrawSelMargin(); return prev; } - + case SCI_GETFOLDLEVEL: return pdoc->GetLevel(wParam); - + case SCI_GETLASTCHILD: return pdoc->GetLastChild(wParam, lParam); - + case SCI_GETFOLDPARENT: return pdoc->GetFoldParent(wParam); - + case SCI_SHOWLINES: cs.SetVisible(wParam, lParam, true); SetScrollBars(); Redraw(); break; - + case SCI_HIDELINES: cs.SetVisible(wParam, lParam, false); SetScrollBars(); Redraw(); break; - + case SCI_GETLINEVISIBLE: return cs.GetVisible(wParam); - + case SCI_SETFOLDEXPANDED: if (cs.SetExpanded(wParam, lParam)) { RedrawSelMargin(); } break; - + case SCI_GETFOLDEXPANDED: return cs.GetExpanded(wParam); - + case SCI_SETFOLDFLAGS: foldFlags = wParam; Redraw(); @@ -3962,11 +4008,11 @@ long Editor::WndProc(unsigned int iMessage, unsigned long wParam, long lParam) { case SCI_TOGGLEFOLD: ToggleContraction(wParam); break; - + case SCI_ENSUREVISIBLE: EnsureLineVisible(wParam); break; - + case SCI_SEARCHANCHOR: SearchAnchor(); break; @@ -4008,13 +4054,13 @@ long Editor::WndProc(unsigned int iMessage, unsigned long wParam, long lParam) { return vs.caretcolour.desired.AsLong(); case SCI_ASSIGNCMDKEY: - kmap.AssignCmdKey(Platform::LowShortFromLong(wParam), - Platform::HighShortFromLong(wParam), lParam); + kmap.AssignCmdKey(Platform::LowShortFromLong(wParam), + Platform::HighShortFromLong(wParam), lParam); break; case SCI_CLEARCMDKEY: - kmap.AssignCmdKey(Platform::LowShortFromLong(wParam), - Platform::HighShortFromLong(wParam), WM_NULL); + kmap.AssignCmdKey(Platform::LowShortFromLong(wParam), + Platform::HighShortFromLong(wParam), WM_NULL); break; case SCI_CLEARALLCMDKEYS: @@ -4090,7 +4136,7 @@ long Editor::WndProc(unsigned int iMessage, unsigned long wParam, long lParam) { case SCI_BRACEHIGHLIGHT: SetBraceHighlight(static_cast<int>(wParam), lParam, STYLE_BRACELIGHT); break; - + case SCI_BRACEBADLIGHT: SetBraceHighlight(static_cast<int>(wParam), -1, STYLE_BRACEBAD); break; @@ -4115,31 +4161,31 @@ long Editor::WndProc(unsigned int iMessage, unsigned long wParam, long lParam) { case SCI_GETZOOM: return vs.zoomLevel; - + case SCI_GETEDGECOLUMN: return theEdge; - + case SCI_SETEDGECOLUMN: theEdge = wParam; InvalidateStyleRedraw(); break; - + case SCI_GETEDGEMODE: return vs.edgeState; - + case SCI_SETEDGEMODE: vs.edgeState = wParam; InvalidateStyleRedraw(); break; - + case SCI_GETEDGECOLOUR: return vs.edgecolour.desired.AsLong(); - + case SCI_SETEDGECOLOUR: vs.edgecolour.desired = Colour(wParam); InvalidateStyleRedraw(); break; - + case SCI_GETDOCPOINTER: return reinterpret_cast<long>(pdoc); @@ -4152,22 +4198,22 @@ long Editor::WndProc(unsigned int iMessage, unsigned long wParam, long lParam) { doc->AddRef(); return reinterpret_cast<long>(doc); } - + case SCI_ADDREFDOCUMENT: (reinterpret_cast<Document *>(lParam))->AddRef(); break; - + case SCI_RELEASEDOCUMENT: (reinterpret_cast<Document *>(lParam))->Release(); break; - + case SCI_SETMODEVENTMASK: modEventMask = wParam; return 0; - + case SCI_GETMODEVENTMASK: return modEventMask; - + case SCI_CONVERTEOLS: pdoc->ConvertLineEnds(wParam); SetSelection(currentPos, anchor); // Ensure selection inside document @@ -4184,8 +4230,8 @@ long Editor::WndProc(unsigned int iMessage, unsigned long wParam, long lParam) { case SCI_STOPRECORD: recordingMacro = 0; return 0; -#endif - +#endif + default: return DefWndProc(iMessage, wParam, lParam); } diff --git a/src/Editor.h b/src/Editor.h index e34d38707..5b79f2ede 100644 --- a/src/Editor.h +++ b/src/Editor.h @@ -36,10 +36,10 @@ public: int selStart; int selEnd; int edgeColumn; - char chars[maxLineLength]; - char styles[maxLineLength]; - char indicators[maxLineLength]; - int positions[maxLineLength]; + char chars[maxLineLength+1]; + char styles[maxLineLength+1]; + char indicators[maxLineLength+1]; + int positions[maxLineLength+1]; }; class Editor : public DocWatcher { @@ -178,6 +178,7 @@ protected: // ScintillaBase subclass needs access to much of Editor void SetSelection(int currentPos_, int anchor_); void SetSelection(int currentPos_); void SetEmptySelection(int currentPos_); + int MovePositionOutsideChar(int pos, int moveDir, bool checkLineEnd=true); int MovePositionTo(int newPos, bool extend = false); int MovePositionSoVisible(int pos, int moveDir); void SetLastXChosen(); diff --git a/src/Style.cxx b/src/Style.cxx index 7aa44c0eb..0a52ed41a 100644 --- a/src/Style.cxx +++ b/src/Style.cxx @@ -14,13 +14,13 @@ Style::Style() { aliasOfDefaultFont = true; Clear(Colour(0,0,0), Colour(0xff,0xff,0xff), Platform::DefaultFontSize(), 0, SC_CHARSET_DEFAULT, - false, false, false, false); + false, false, false, false, true); } Style::Style(const Style &source) { Clear(Colour(0,0,0), Colour(0xff,0xff,0xff), 0, 0, 0, - false, false, false, false); + false, false, false, false, true); fore.desired = source.fore.desired; back.desired = source.back.desired; characterSet = source.characterSet; @@ -29,6 +29,7 @@ Style::Style(const Style &source) { size = source.size; eolFilled = source.eolFilled; underline = source.underline; + visible = source.visible; } Style::~Style() { @@ -44,7 +45,7 @@ Style &Style::operator=(const Style &source) { return *this; Clear(Colour(0,0,0), Colour(0xff,0xff,0xff), 0, 0, SC_CHARSET_DEFAULT, - false, false, false, false); + false, false, false, false, true); fore.desired = source.fore.desired; back.desired = source.back.desired; characterSet = source.characterSet; @@ -53,12 +54,13 @@ Style &Style::operator=(const Style &source) { size = source.size; eolFilled = source.eolFilled; underline = source.underline; + visible = source.visible; return *this; } void Style::Clear(Colour fore_, Colour back_, int size_, const char *fontName_, int characterSet_, - bool bold_, bool italic_, bool eolFilled_, bool underline_) { + bool bold_, bool italic_, bool eolFilled_, bool underline_, bool visible_) { fore.desired = fore_; back.desired = back_; characterSet = characterSet_; @@ -68,6 +70,7 @@ void Style::Clear(Colour fore_, Colour back_, int size_, fontName = fontName_; eolFilled = eolFilled_; underline = underline_; + visible = visible_; if (aliasOfDefaultFont) font.SetID(0); else diff --git a/src/Style.h b/src/Style.h index dc643d08d..9a2b4586a 100644 --- a/src/Style.h +++ b/src/Style.h @@ -18,6 +18,7 @@ public: int characterSet; bool eolFilled; bool underline; + bool visible; Font font; unsigned int lineHeight; @@ -34,7 +35,7 @@ public: void Clear(Colour fore_, Colour back_, int size_, const char *fontName_, int characterSet_, - bool bold_, bool italic_, bool eolFilled_, bool underline_); + bool bold_, bool italic_, bool eolFilled_, bool underline_, bool visible_); bool EquivalentFontTo(const Style *other) const; void Realise(Surface &surface, int zoomLevel, Style *defaultStyle=0); }; diff --git a/src/ViewStyle.cxx b/src/ViewStyle.cxx index fae8eb53b..9b7a8535e 100644 --- a/src/ViewStyle.cxx +++ b/src/ViewStyle.cxx @@ -210,7 +210,7 @@ void ViewStyle::ResetDefaultStyle() { styles[STYLE_DEFAULT].Clear(Colour(0,0,0), Colour(0xff,0xff,0xff), Platform::DefaultFontSize(), fontNames.Save(Platform::DefaultFont()), SC_CHARSET_DEFAULT, - false, false, false, false); + false, false, false, false, true); } void ViewStyle::ClearStyles() { @@ -226,7 +226,8 @@ void ViewStyle::ClearStyles() { styles[STYLE_DEFAULT].bold, styles[STYLE_DEFAULT].italic, styles[STYLE_DEFAULT].eolFilled, - styles[STYLE_DEFAULT].underline); + styles[STYLE_DEFAULT].underline, + styles[STYLE_DEFAULT].visible); } } styles[STYLE_LINENUMBER].back.desired = Platform::Chrome(); |