diff options
author | nyamatongwe <unknown> | 2001-10-28 04:39:23 +0000 |
---|---|---|
committer | nyamatongwe <unknown> | 2001-10-28 04:39:23 +0000 |
commit | 144d8ad47767077a8205eae0a2749be7dab2b407 (patch) | |
tree | 219ef4a2b3d794cebeedb9a0d3baa7e79cb9a1bb /src | |
parent | 19b8b95e52c0c98566819492a6a5bb829314cec9 (diff) | |
download | scintilla-mirror-144d8ad47767077a8205eae0a2749be7dab2b407.tar.gz |
Fixed Platform changes for GTK+ and hid most of the implementation of
Surface.
Diffstat (limited to 'src')
-rw-r--r-- | src/CallTip.cxx | 16 | ||||
-rw-r--r-- | src/Document.cxx | 11 | ||||
-rw-r--r-- | src/DocumentAccessor.cxx | 8 | ||||
-rw-r--r-- | src/Editor.cxx | 216 | ||||
-rw-r--r-- | src/Editor.h | 10 | ||||
-rw-r--r-- | src/UniConversion.cxx | 4 | ||||
-rw-r--r-- | src/WindowAccessor.cxx | 8 |
7 files changed, 140 insertions, 133 deletions
diff --git a/src/CallTip.cxx b/src/CallTip.cxx index 006e2cb51..807b745f6 100644 --- a/src/CallTip.cxx +++ b/src/CallTip.cxx @@ -118,9 +118,11 @@ void CallTip::PaintCT(Surface *surfaceWindow) { PRectangle CallTip::CallTipStart(int pos, Point pt, const char *defn, const char *faceName, int size) { - Surface surfaceMeasure; - surfaceMeasure.Init(); - int deviceHeight = surfaceMeasure.DeviceHeightFont(size); + Surface *surfaceMeasure=Surface::Allocate(); + if (!surfaceMeasure) + return PRectangle(); + surfaceMeasure->Init(); + int deviceHeight = surfaceMeasure->DeviceHeightFont(size); font.Create(faceName, SC_CHARSET_DEFAULT, deviceHeight, false, false); if (val) delete []val; @@ -139,16 +141,16 @@ PRectangle CallTip::CallTipStart(int pos, Point pt, const char *defn, const char *newline; const char *look = val; while ((newline = strchr(look, '\n')) != NULL) { - int thisWidth = surfaceMeasure.WidthText(font, look, newline - look); + int thisWidth = surfaceMeasure->WidthText(font, look, newline - look); width = Platform::Maximum(width, thisWidth); look = newline + 1; numLines++; } - int lastWidth = surfaceMeasure.WidthText(font, look, strlen(look)); + int lastWidth = surfaceMeasure->WidthText(font, look, strlen(look)); width = Platform::Maximum(width, lastWidth) + 10; - int lineHeight = surfaceMeasure.Height(font); + int lineHeight = surfaceMeasure->Height(font); // Extra line for border and an empty line at top and bottom - int height = lineHeight * numLines - surfaceMeasure.InternalLeading(font) + 2 + 2; + int height = lineHeight * numLines - surfaceMeasure->InternalLeading(font) + 2 + 2; return PRectangle(pt.x -5, pt.y + 1, pt.x + width - 5, pt.y + 1 + height); } diff --git a/src/Document.cxx b/src/Document.cxx index 213a72d6a..806f61f19 100644 --- a/src/Document.cxx +++ b/src/Document.cxx @@ -217,7 +217,6 @@ bool Document::IsCrLf(int pos) { return (cb.CharAt(pos) == '\r') && (cb.CharAt(pos + 1) == '\n'); } -#if PLAT_WIN bool Document::IsDBCS(int pos) { if (dbcsCodePage) { if (SC_CP_UTF8 == dbcsCodePage) { @@ -241,13 +240,6 @@ bool Document::IsDBCS(int pos) { } return false; } -#else -// PLAT_GTK or PLAT_WX -// TODO: support DBCS under GTK+ and WX -bool Document::IsDBCS(int) { - return false; -} -#endif int Document::LenChar(int pos) { if (IsCrLf(pos)) { @@ -300,7 +292,6 @@ int Document::MovePositionOutsideChar(int pos, int moveDir, bool checkLineEnd) { // Not between CR and LF -#if PLAT_WIN if (dbcsCodePage) { if (SC_CP_UTF8 == dbcsCodePage) { unsigned char ch = static_cast<unsigned char>(cb.CharAt(pos)); @@ -327,7 +318,6 @@ int Document::MovePositionOutsideChar(int pos, int moveDir, bool checkLineEnd) { else atLeadByte = false; startLine++; - //Platform::DebugPrintf("DBCS %s\n", atlead ? "D" : "-"); } @@ -340,7 +330,6 @@ int Document::MovePositionOutsideChar(int pos, int moveDir, bool checkLineEnd) { } } } -#endif return pos; } diff --git a/src/DocumentAccessor.cxx b/src/DocumentAccessor.cxx index e8930c23d..76530e1de 100644 --- a/src/DocumentAccessor.cxx +++ b/src/DocumentAccessor.cxx @@ -23,7 +23,6 @@ DocumentAccessor::~DocumentAccessor() { } -#if PLAT_WIN bool DocumentAccessor::InternalIsLeadByte(char ch) { if (SC_CP_UTF8 == codePage) // For lexing, all characters >= 0x80 are treated the @@ -32,13 +31,6 @@ bool DocumentAccessor::InternalIsLeadByte(char ch) { else return Platform::IsDBCSLeadByte(codePage, ch); } -#else -// PLAT_GTK or PLAT_WX -// TODO: support DBCS under GTK+ and WX -bool DocumentAccessor::InternalIsLeadByte(char) { - return false; -} -#endif void DocumentAccessor::Fill(int position) { if (lenDoc == -1) diff --git a/src/Editor.cxx b/src/Editor.cxx index 941c05971..039306a41 100644 --- a/src/Editor.cxx +++ b/src/Editor.cxx @@ -82,6 +82,12 @@ Editor::Editor() { xCaretMargin = 50; horizontalScrollBarVisible = true; + pixmapLine = Surface::Allocate(); + pixmapSelMargin = Surface::Allocate(); + pixmapSelPattern = Surface::Allocate(); + pixmapIndentGuide = Surface::Allocate(); + pixmapIndentGuideHighlight = Surface::Allocate(); + currentPos = 0; anchor = 0; @@ -117,6 +123,11 @@ Editor::~Editor() { pdoc->Release(); pdoc = 0; DropGraphics(); + delete pixmapLine; + delete pixmapSelMargin; + delete pixmapSelPattern; + delete pixmapIndentGuide; + delete pixmapIndentGuideHighlight; } void Editor::Finalise() { @@ -124,10 +135,10 @@ void Editor::Finalise() { } void Editor::DropGraphics() { - pixmapLine.Release(); - pixmapSelMargin.Release(); - pixmapSelPattern.Release(); - pixmapIndentGuide.Release(); + pixmapLine->Release(); + pixmapSelMargin->Release(); + pixmapSelPattern->Release(); + pixmapIndentGuide->Release(); } void Editor::InvalidateStyleData() { @@ -148,12 +159,15 @@ void Editor::RefreshColourPalette(Palette &pal, bool want) { void Editor::RefreshStyleData() { if (!stylesValid) { stylesValid = true; - Surface surface; - surface.Init(); - vs.Refresh(surface); - RefreshColourPalette(palette, true); - palette.Allocate(wMain); - RefreshColourPalette(palette, false); + Surface *surface = Surface::Allocate(); + if (surface) { + surface->Init(); + vs.Refresh(*surface); + RefreshColourPalette(palette, true); + palette.Allocate(wMain); + RefreshColourPalette(palette, false); + delete surface; + } SetScrollBars(); } } @@ -221,18 +235,21 @@ Point Editor::LocationFromPosition(int pos) { int line = pdoc->LineFromPosition(pos); int lineVisible = cs.DisplayFromDoc(line); //Platform::DebugPrintf("line=%d\n", line); - Surface surface; - surface.Init(); - surface.SetUnicodeMode(SC_CP_UTF8 == pdoc->dbcsCodePage); - 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 = ll.positions[LineLayout::maxLineLength] + vs.fixedColumnWidth - xOffset; - } else { - pt.x = ll.positions[pos - posLineStart] + vs.fixedColumnWidth - xOffset; + Surface *surface = Surface::Allocate(); + if (surface) { + surface->Init(); + surface->SetUnicodeMode(SC_CP_UTF8 == pdoc->dbcsCodePage); + 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 = ll.positions[LineLayout::maxLineLength] + vs.fixedColumnWidth - xOffset; + } else { + pt.x = ll.positions[pos - posLineStart] + vs.fixedColumnWidth - xOffset; + } + delete surface; } return pt; } @@ -262,21 +279,25 @@ int Editor::PositionFromLocation(Point pt) { return 0; if (line >= pdoc->LinesTotal()) return pdoc->Length(); - Surface surface; - surface.Init(); - surface.SetUnicodeMode(SC_CP_UTF8 == pdoc->dbcsCodePage); - unsigned int posLineStart = pdoc->LineStart(line); - - 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') { - return i + posLineStart; + Surface *surface = Surface::Allocate(); + if (surface) { + surface->Init(); + surface->SetUnicodeMode(SC_CP_UTF8 == pdoc->dbcsCodePage); + unsigned int posLineStart = pdoc->LineStart(line); + + 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') { + delete surface; + return i + posLineStart; + } } + delete surface; + return ll.numCharsInLine + posLineStart; } - - return ll.numCharsInLine + posLineStart; + return 0; } // Like PositionFromLocation but INVALID_POSITION returned when not near any text. @@ -298,18 +319,22 @@ int Editor::PositionFromLocationClose(Point pt) { return INVALID_POSITION; if (line >= pdoc->LinesTotal()) return INVALID_POSITION; - Surface surface; - surface.Init(); - surface.SetUnicodeMode(SC_CP_UTF8 == pdoc->dbcsCodePage); - unsigned int posLineStart = pdoc->LineStart(line); - - 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') { - return i + posLineStart; + Surface *surface = Surface::Allocate(); + if (surface) { + surface->Init(); + surface->SetUnicodeMode(SC_CP_UTF8 == pdoc->dbcsCodePage); + unsigned int posLineStart = pdoc->LineStart(line); + + 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') { + delete surface; + return i + posLineStart; + } } + delete surface; } return INVALID_POSITION; @@ -320,21 +345,26 @@ int Editor::PositionFromLineX(int line, int x) { if (line >= pdoc->LinesTotal()) return pdoc->Length(); //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); - unsigned int posLineStart = pdoc->LineStart(line); - - 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') { - return i + posLineStart; + Surface *surface = Surface::Allocate(); + if (surface) { + surface->Init(); + surface->SetUnicodeMode(SC_CP_UTF8 == pdoc->dbcsCodePage); + unsigned int posLineStart = pdoc->LineStart(line); + + 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') { + delete surface; + return i + posLineStart; + } } + + delete surface; + return ll.numCharsInLine + posLineStart; } - - return ll.numCharsInLine + posLineStart; + return 0; } void Editor::RedrawRect(PRectangle rc) { @@ -712,7 +742,7 @@ void Editor::PaintSelMargin(Surface *surfWindow, PRectangle &rc) { Surface *surface; if (bufferedDraw) { - surface = &pixmapSelMargin; + surface = pixmapSelMargin; } else { surface = surfWindow; } @@ -736,7 +766,7 @@ 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); } else { @@ -874,7 +904,7 @@ void Editor::PaintSelMargin(Surface *surfWindow, PRectangle &rc) { surface->FillRectangle(rcBlankMargin, vs.styles[STYLE_DEFAULT].back.allocated); if (bufferedDraw) { - surfWindow->Copy(rcMargin, Point(), pixmapSelMargin); + surfWindow->Copy(rcMargin, Point(), *pixmapSelMargin); } } @@ -1079,7 +1109,7 @@ void Editor::DrawLine(Surface *surface, ViewStyle &vsDraw, int line, int lineVis 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); + *pixmapIndentGuideHighlight : *pixmapIndentGuide); } } } @@ -1144,7 +1174,7 @@ void Editor::DrawLine(Surface *surface, ViewStyle &vsDraw, int line, int lineVis 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); + *pixmapIndentGuideHighlight : *pixmapIndentGuide); } } } else { @@ -1232,53 +1262,53 @@ void Editor::Paint(Surface *surfaceWindow, PRectangle rcArea) { //Platform::DebugPrintf("Client: (%3d,%3d) ... (%3d,%3d) %d\n", // rcClient.left, rcClient.top, rcClient.right, rcClient.bottom); - if (!pixmapSelPattern.Initialised()) { - pixmapSelPattern.InitPixMap(8, 8, surfaceWindow); + if (!pixmapSelPattern->Initialised()) { + pixmapSelPattern->InitPixMap(8, 8, surfaceWindow); // This complex procedure is to reproduce the checker board dithered pattern used by windows // for scroll bars and Visual Studio for its selection margin. The colour of this pattern is half // way between the chrome colour and the chrome highlight colour making a nice transition // between the window chrome and the content area. And it works in low colour depths. PRectangle rcPattern(0, 0, 8, 8); if (vs.selbarlight.desired == ColourDesired(0xff, 0xff, 0xff)) { - pixmapSelPattern.FillRectangle(rcPattern, vs.selbar.allocated); - pixmapSelPattern.PenColour(vs.selbarlight.allocated); + pixmapSelPattern->FillRectangle(rcPattern, vs.selbar.allocated); + pixmapSelPattern->PenColour(vs.selbarlight.allocated); for (int stripe = 0; stripe < 8; stripe++) { - pixmapSelPattern.MoveTo(0, stripe * 2); - pixmapSelPattern.LineTo(8, stripe * 2 - 8); + pixmapSelPattern->MoveTo(0, stripe * 2); + pixmapSelPattern->LineTo(8, stripe * 2 - 8); } } else { // User has chosen an unusual chrome colour scheme so just use the highlight edge colour. - pixmapSelPattern.FillRectangle(rcPattern, vs.selbarlight.allocated); + pixmapSelPattern->FillRectangle(rcPattern, vs.selbarlight.allocated); } } - if (!pixmapIndentGuide.Initialised()) { + 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); + 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) { - pixmapIndentGuide.MoveTo(0, stripe); - pixmapIndentGuide.LineTo(2, stripe); - pixmapIndentGuideHighlight.MoveTo(0, stripe); - pixmapIndentGuideHighlight.LineTo(2, stripe); + 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(), + if (!pixmapLine->Initialised()) { + pixmapLine->InitPixMap(rcClient.Width(), rcClient.Height(), surfaceWindow); - pixmapSelMargin.InitPixMap(vs.fixedColumnWidth, + pixmapSelMargin->InitPixMap(vs.fixedColumnWidth, rcClient.Height(), surfaceWindow); } } surfaceWindow->SetPalette(&palette, true); - pixmapLine.SetPalette(&palette, !hasFocus); + pixmapLine->SetPalette(&palette, !hasFocus); //Platform::DebugPrintf("Paint: (%3d,%3d) ... (%3d,%3d)\n", // rcArea.left, rcArea.top, rcArea.right, rcArea.bottom); @@ -1327,7 +1357,7 @@ void Editor::Paint(Surface *surfaceWindow, PRectangle rcArea) { Surface *surface = surfaceWindow; if (bufferedDraw) { - surface = &pixmapLine; + surface = pixmapLine; } surface->SetUnicodeMode(SC_CP_UTF8 == pdoc->dbcsCodePage); @@ -1453,7 +1483,7 @@ void Editor::Paint(Surface *surfaceWindow, PRectangle rcArea) { Point from(vs.fixedColumnWidth, 0); PRectangle rcCopyArea(vs.fixedColumnWidth, yposScreen, rcClient.right, yposScreen + vs.lineHeight); - surfaceWindow->Copy(rcCopyArea, from, pixmapLine); + surfaceWindow->Copy(rcCopyArea, from, *pixmapLine); } } @@ -1515,10 +1545,16 @@ long Editor::FormatRange(bool draw, RangeToFormat *pfr) { if (!pfr) return 0; - Surface *surface = new Surface(); + Surface *surface = Surface::Allocate(); + if (!surface) + return 0; surface->Init(pfr->hdc); surface->SetUnicodeMode(SC_CP_UTF8 == pdoc->dbcsCodePage); - Surface *surfaceMeasure = new Surface(); + Surface *surfaceMeasure = Surface::Allocate(); + if (!surfaceMeasure) { + delete surface; + return 0; + } surfaceMeasure->Init(pfr->hdcTarget); surfaceMeasure->SetUnicodeMode(SC_CP_UTF8 == pdoc->dbcsCodePage); diff --git a/src/Editor.h b/src/Editor.h index a51fd86f9..6f4f54e98 100644 --- a/src/Editor.h +++ b/src/Editor.h @@ -107,11 +107,11 @@ protected: // ScintillaBase subclass needs access to much of Editor int xCaretMargin; ///< Ensure this many pixels visible on both sides of caret bool horizontalScrollBarVisible; - Surface pixmapLine; - Surface pixmapSelMargin; - Surface pixmapSelPattern; - Surface pixmapIndentGuide; - Surface pixmapIndentGuideHighlight; + Surface *pixmapLine; + Surface *pixmapSelMargin; + Surface *pixmapSelPattern; + Surface *pixmapIndentGuide; + Surface *pixmapIndentGuideHighlight; KeyMap kmap; diff --git a/src/UniConversion.cxx b/src/UniConversion.cxx index c3f960c62..15cad6382 100644 --- a/src/UniConversion.cxx +++ b/src/UniConversion.cxx @@ -52,9 +52,6 @@ unsigned int UCS2Length(const char *s, unsigned int len) { } unsigned int UCS2FromUTF8(const char *s, unsigned int len, wchar_t *tbuf, unsigned int tlen) { -#ifdef USE_API - return ::MultiByteToWideChar(CP_UTF8, 0, s, len, tbuf, tlen); -#else unsigned int ui=0; const unsigned char *us = reinterpret_cast<const unsigned char *>(s); unsigned int i=0; @@ -76,5 +73,4 @@ unsigned int UCS2FromUTF8(const char *s, unsigned int len, wchar_t *tbuf, unsign ui++; } return ui; -#endif } diff --git a/src/WindowAccessor.cxx b/src/WindowAccessor.cxx index cd419572c..e02bf90e4 100644 --- a/src/WindowAccessor.cxx +++ b/src/WindowAccessor.cxx @@ -20,7 +20,6 @@ WindowAccessor::~WindowAccessor() { } -#if PLAT_WIN bool WindowAccessor::InternalIsLeadByte(char ch) { if (SC_CP_UTF8 == codePage) // For lexing, all characters >= 0x80 are treated the @@ -29,13 +28,6 @@ bool WindowAccessor::InternalIsLeadByte(char ch) { else return Platform::IsDBCSLeadByte(codePage, ch); } -#else -// PLAT_GTK or PLAT_WX -// TODO: support DBCS under GTK+ and WX -bool WindowAccessor::InternalIsLeadByte(char) { - return false; -} -#endif void WindowAccessor::Fill(int position) { if (lenDoc == -1) |