diff options
author | nyamatongwe <devnull@localhost> | 2001-12-19 07:18:45 +0000 |
---|---|---|
committer | nyamatongwe <devnull@localhost> | 2001-12-19 07:18:45 +0000 |
commit | ee5c8a4d1d308df0d28a48a19ad60a9f9ebe4a28 (patch) | |
tree | 0c4fd3a097ec839964f6842b1a93c7aac4057eb7 /src | |
parent | d4c8a2940fa1373444e676e0a56731ed7c1898b4 (diff) | |
download | scintilla-mirror-ee5c8a4d1d308df0d28a48a19ad60a9f9ebe4a28.tar.gz |
Hoisted IsUnicodeMode method from ScintillaWin to Editor as it is useful on
all platforms.
Using AutoSurface to simplify allocation of surfaces and ensure they are
always deleted.
Diffstat (limited to 'src')
-rw-r--r-- | src/Editor.cxx | 63 | ||||
-rw-r--r-- | src/Editor.h | 6 |
2 files changed, 26 insertions, 43 deletions
diff --git a/src/Editor.cxx b/src/Editor.cxx index 6c5ba7330..478c20fb2 100644 --- a/src/Editor.cxx +++ b/src/Editor.cxx @@ -160,14 +160,12 @@ void Editor::RefreshColourPalette(Palette &pal, bool want) { void Editor::RefreshStyleData() { if (!stylesValid) { stylesValid = true; - Surface *surface = Surface::Allocate(); + AutoSurface surface(IsUnicodeMode()); if (surface) { - surface->Init(); vs.Refresh(*surface); RefreshColourPalette(palette, true); palette.Allocate(wMain); RefreshColourPalette(palette, false); - delete surface; } SetScrollBars(); } @@ -236,7 +234,7 @@ Point Editor::LocationFromPosition(int pos) { int line = pdoc->LineFromPosition(pos); int lineVisible = cs.DisplayFromDoc(line); //Platform::DebugPrintf("line=%d\n", line); - Surface *surface = Surface::Allocate(); + AutoSurface surface(IsUnicodeMode()); if (surface) { surface->Init(); surface->SetUnicodeMode(SC_CP_UTF8 == pdoc->dbcsCodePage); @@ -250,7 +248,6 @@ Point Editor::LocationFromPosition(int pos) { } else { pt.x = ll.positions[pos - posLineStart] + vs.fixedColumnWidth - xOffset; } - delete surface; } return pt; } @@ -272,30 +269,26 @@ void Editor::SetTopLine(int topLineNew) { int Editor::PositionFromLocation(Point pt) { RefreshStyleData(); pt.x = pt.x - vs.fixedColumnWidth + xOffset; - int line = cs.DocFromDisplay(pt.y / vs.lineHeight + topLine); + int lineDoc = cs.DocFromDisplay(pt.y / vs.lineHeight + topLine); if (pt.y < 0) { // Division rounds towards 0 - line = cs.DocFromDisplay((pt.y - (vs.lineHeight - 1)) / vs.lineHeight + topLine); + lineDoc = cs.DocFromDisplay((pt.y - (vs.lineHeight - 1)) / vs.lineHeight + topLine); } - if (line < 0) + if (lineDoc < 0) return 0; - if (line >= pdoc->LinesTotal()) + if (lineDoc >= pdoc->LinesTotal()) return pdoc->Length(); - Surface *surface = Surface::Allocate(); + AutoSurface surface(IsUnicodeMode()); if (surface) { - surface->Init(); - surface->SetUnicodeMode(SC_CP_UTF8 == pdoc->dbcsCodePage); - unsigned int posLineStart = pdoc->LineStart(line); + unsigned int posLineStart = pdoc->LineStart(lineDoc); LineLayout ll; - LayoutLine(line, surface, vs, ll); + LayoutLine(lineDoc, 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 0; @@ -320,10 +313,8 @@ int Editor::PositionFromLocationClose(Point pt) { return INVALID_POSITION; if (line >= pdoc->LinesTotal()) return INVALID_POSITION; - Surface *surface = Surface::Allocate(); + AutoSurface surface(IsUnicodeMode()); if (surface) { - surface->Init(); - surface->SetUnicodeMode(SC_CP_UTF8 == pdoc->dbcsCodePage); unsigned int posLineStart = pdoc->LineStart(line); LineLayout ll; @@ -331,11 +322,9 @@ int Editor::PositionFromLocationClose(Point pt) { 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; @@ -346,10 +335,8 @@ 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::Allocate(); + AutoSurface surface(IsUnicodeMode()); if (surface) { - surface->Init(); - surface->SetUnicodeMode(SC_CP_UTF8 == pdoc->dbcsCodePage); unsigned int posLineStart = pdoc->LineStart(line); LineLayout ll; @@ -357,12 +344,10 @@ int Editor::PositionFromLineX(int line, int x) { 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 0; @@ -1369,7 +1354,7 @@ void Editor::Paint(Surface *surfaceWindow, PRectangle rcArea) { if (bufferedDraw) { surface = pixmapLine; } - surface->SetUnicodeMode(SC_CP_UTF8 == pdoc->dbcsCodePage); + surface->SetUnicodeMode(IsUnicodeMode()); int visibleLine = topLine + screenLinePaintFirst; int line = cs.DocFromDisplay(visibleLine); @@ -1387,7 +1372,9 @@ void Editor::Paint(Surface *surfaceWindow, PRectangle rcArea) { surfaceWindow->SetClip(rcTextArea); // Loop on visible lines - //GTimer *tim=g_timer_new(); + double durLayout = 0.0; + double durPaint = 0.0; + double durCopy = 0.0; while (visibleLine < cs.LinesDisplayed() && yposScreen < rcArea.bottom) { //g_timer_start(tim); //Platform::DebugPrintf("Painting line %d\n", line); @@ -1505,10 +1492,8 @@ void Editor::Paint(Surface *surfaceWindow, PRectangle rcArea) { visibleLine++; line = cs.DocFromDisplay(visibleLine); //gdk_flush(); - //g_timer_stop(tim); - //Platform::DebugPrintf("Paint [%0d] took %g\n", line, g_timer_elapsed(tim, 0)); } - //g_timer_destroy(tim); + Platform::DebugPrintf("Layout:%9.6g Paint:%9.6g Ratio:%9.6g Copy:%9.6g\n", durLayout, durPaint, durLayout / durPaint, durCopy); // Right column limit indicator @@ -1555,18 +1540,13 @@ long Editor::FormatRange(bool draw, RangeToFormat *pfr) { if (!pfr) return 0; - Surface *surface = Surface::Allocate(); + AutoSurface surface(pfr->hdc, IsUnicodeMode()); if (!surface) return 0; - surface->Init(pfr->hdc); - surface->SetUnicodeMode(SC_CP_UTF8 == pdoc->dbcsCodePage); - Surface *surfaceMeasure = Surface::Allocate(); + AutoSurface surfaceMeasure(pfr->hdcTarget, IsUnicodeMode()); if (!surfaceMeasure) { - delete surface; return 0; } - surfaceMeasure->Init(pfr->hdcTarget); - surfaceMeasure->SetUnicodeMode(SC_CP_UTF8 == pdoc->dbcsCodePage); ViewStyle vsPrint(vs); @@ -1690,9 +1670,6 @@ long Editor::FormatRange(bool draw, RangeToFormat *pfr) { } } - delete surface; - delete surfaceMeasure; - return endPosPrint; } @@ -3557,6 +3534,10 @@ int Editor::ReplaceTarget(bool replacePatterns, const char *text, int length) { return length; } +bool Editor::IsUnicodeMode() const { + return pdoc && (SC_CP_UTF8 == pdoc->dbcsCodePage); +} + static bool ValidMargin(unsigned long wParam) { return wParam < ViewStyle::margins; } diff --git a/src/Editor.h b/src/Editor.h index c58da4ea5..f43332e90 100644 --- a/src/Editor.h +++ b/src/Editor.h @@ -373,9 +373,11 @@ protected: // ScintillaBase subclass needs access to much of Editor virtual sptr_t DefWndProc(unsigned int iMessage, uptr_t wParam, sptr_t lParam) = 0; public: - // Public so scintilla_send_message can use it + // Public so the COM thunks can access it. + bool IsUnicodeMode() const; + // Public so scintilla_send_message can use it. virtual sptr_t WndProc(unsigned int iMessage, uptr_t wParam, sptr_t lParam); - // Public so scintilla_set_id can use it + // Public so scintilla_set_id can use it. int ctrlID; }; |