Ticket #2209: TextView.diff.bad

File TextView.diff.bad, 4.5 KB (added by shinta, 16 years ago)
Line 
1Index: src/kits/interface/TextView.cpp
2===================================================================
3--- src/kits/interface/TextView.cpp (リビジョン 25319)
4+++ src/kits/interface/TextView.cpp (作業コピー)
5@@ -3509,8 +3509,8 @@
6
7
8 void
9-BTextView::_DrawLine(BView *view, const int32 &lineNum, const int32 &startOffset,
10- const bool &erase, BRect &eraseRect, BRegion &inputRegion)
11+BTextView::_DrawLine(BView* view, const int32& lineNum, const int32& startOffset,
12+ const bool& erase, BRect& eraseRect, BRegion& inputRegion)
13 {
14 STELine *line = (*fLines)[lineNum];
15 float startLeft = fTextRect.left;
16@@ -3576,36 +3576,54 @@
17 } while ((tabChars + numTabs) < numBytes);
18 }
19
20- if (inputRegion.CountRects() > 0) {
21+ if (inputRegion.CountRects() > 0 && offset == fInline->Offset()) {
22+ rgb_color viewColor = ViewColor();
23+
24 BRegion textRegion;
25- GetTextRegion(offset, offset + length, &textRegion);
26
27- textRegion.IntersectWith(&inputRegion);
28- view->PushState();
29+ // Highlight in blue the inputted text before the selected part
30+ if (fInline->SelectionOffset() != fInline->Offset()) {
31+ GetTextRegion(fInline->Offset(), fInline->Offset() + fInline->SelectionOffset(),
32+ &textRegion);
33+ textRegion.IntersectWith(&inputRegion);
34+ _DrawInputtedText(view, fInline->Offset(), fInline->SelectionOffset(), *color,
35+ kBlueInputColor, textRegion);
36+ }
37
38- // Highlight in blue the inputted text
39- view->SetHighColor(kBlueInputColor);
40- view->FillRect(textRegion.Frame());
41-
42 // Highlight in red the selected part
43 if (fInline->SelectionLength() > 0) {
44- BRegion selectedRegion;
45 GetTextRegion(fInline->Offset()
46 + fInline->SelectionOffset(), fInline->Offset()
47 + fInline->SelectionOffset()
48- + fInline->SelectionLength(), &selectedRegion);
49+ + fInline->SelectionLength(), &textRegion);
50+ textRegion.IntersectWith(&inputRegion);
51+ _DrawInputtedText(view, fInline->Offset() + fInline->SelectionOffset(),
52+ fInline->SelectionLength(), *color, kRedInputColor, textRegion);
53+ }
54
55- textRegion.IntersectWith(&selectedRegion);
56-
57- view->SetHighColor(kRedInputColor);
58- view->FillRect(textRegion.Frame());
59+ // Highlight in blue the inputted text after the selected part
60+ int32 afterSelectionOffset = fInline->Offset() + fInline->SelectionOffset()
61+ + fInline->SelectionLength();
62+ if (afterSelectionOffset != fInline->Offset() + fInline->Length()) {
63+ GetTextRegion(afterSelectionOffset, fInline->Offset() + fInline->Length(),
64+ &textRegion);
65+ textRegion.IntersectWith(&inputRegion);
66+ _DrawInputtedText(view, afterSelectionOffset,
67+ fInline->Offset() + fInline->Length() - afterSelectionOffset, *color,
68+ kBlueInputColor, textRegion);
69 }
70
71- view->PopState();
72+ offset += fInline->Length();
73+ length -= fInline->Length();
74+ numBytes -= fInline->Length();
75+ tabChars -= fInline->Length();
76+
77+ SetViewColor(viewColor);
78+ SetLowColor(viewColor);
79 }
80
81 int32 returnedBytes = tabChars;
82- const char *stringToDraw = fText->GetString(offset,
83+ const char* stringToDraw = fText->GetString(offset,
84 &returnedBytes);
85
86 view->DrawString(stringToDraw, returnedBytes);
87@@ -3629,6 +3647,20 @@
88 }
89
90
91+void BTextView::_DrawInputtedText(BView* view, int32 offset, int32 length,
92+ const rgb_color& highColor, const rgb_color& bgColor, const BRegion& region)
93+{
94+ view->SetHighColor(bgColor);
95+ view->FillRect(region.Frame());
96+
97+ SetHighColor(highColor);
98+ SetLowColor(bgColor);
99+ SetViewColor(bgColor);
100+ const char* stringToDraw = fText->GetString(offset, &length);
101+ view->DrawString(stringToDraw, length);
102+}
103+
104+
105 void
106 BTextView::_DrawLines(int32 startLine, int32 endLine, int32 startOffset,
107 bool erase)
108Index: headers/os/interface/TextView.h
109===================================================================
110--- headers/os/interface/TextView.h (リビジョン 25300)
111+++ headers/os/interface/TextView.h (作業コピー)
112@@ -251,9 +251,11 @@
113 void _DoDeleteText(int32 fromOffset, int32 toOffset,
114 _BTextChangeResult_* outResult);
115
116- void _DrawLine(BView* view, const int32 &startLine,
117+ void _DrawLine(BView* view, const int32& startLine,
118 const int32& startOffset, const bool& erase, BRect& eraseRect,
119 BRegion& inputRegion);
120+ void _DrawInputtedText(BView* view, int32 offset, int32 length,
121+ const rgb_color& highColor, const rgb_color& bgColor, const BRegion& region);
122
123 void _DrawLines(int32 startLine, int32 endLine, int32 startOffset = -1,
124 bool erase = false);