Got rid of fSelected, no need to maintain a separate variable to check

if we have a selection. Now there's a "HasSelection()" method which just 
checks if fSelStart and fSelEnd are different. 


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@21520 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Stefano Ceccherini
2007-06-28 12:58:03 +00:00
parent ba416ad375
commit 645b01f225
2 changed files with 22 additions and 21 deletions
+17 -16
View File
@@ -94,7 +94,6 @@ TermView::TermView(BRect frame, CodeConv *inCodeConv, int fd)
fScrBot(fTermRows - 1),
fScrBufSize(gTermPref->getInt32(PREF_HISTORY_SIZE)),
fScrRegionSet(0),
fSelected(false),
fMouseTracking(false),
fViewThread(-1),
fMouseThread(-1),
@@ -851,7 +850,7 @@ TermView::MouseTracking(void *data)
if (!has_data(find_thread(NULL))) {
BRect r;
if (theObj->fSelected
if (theObj->HasSelection()
&& ( gTermPref->getInt32(PREF_DRAGN_COPY)
|| modifiers() & B_CONTROL_KEY)) {
@@ -886,7 +885,7 @@ TermView::MouseTracking(void *data)
if (code != MOUSE_THR_CODE)
continue;
selected = theObj->fSelected;
selected = theObj->HasSelection();
edpoint.Set(-1, -1);
stpos = theObj->BPointToCurPos(stpoint);
@@ -1099,7 +1098,7 @@ void
TermView::UpdateSIGWINCH()
{
if (fFrameResized) {
if (fSelected)
if (HasSelection())
TermDrawSelectedRegion(fSelStart, fSelEnd);
ScrollTo(0, fTop);
ResizeScrBarRange();
@@ -1575,7 +1574,7 @@ TermView::DoFileDrop(entry_ref &ref)
void
TermView::DoCopy()
{
if (!fSelected)
if (!HasSelection())
return;
BString copyStr;
@@ -1667,10 +1666,7 @@ TermView::DoClearAll(void)
// reset cursor pos
SetCurPos(0, 0);
// reset selection.
fSelected = false;
fScrollBar->SetRange(0, 0);
fScrollBar->SetProportion(1);
}
@@ -1702,7 +1698,7 @@ TermView::MouseDown(BPoint where)
// paste button
if ((buttons & (B_SECONDARY_MOUSE_BUTTON | B_TERTIARY_MOUSE_BUTTON)) != 0) {
if (fSelected) {
if (HasSelection()) {
// copy text from region
BString copy;
fTextBuffer->GetStringFromRegion(copy);
@@ -1720,7 +1716,7 @@ TermView::MouseDown(BPoint where)
Window()->CurrentMessage()->FindInt32("modifiers", &mod);
Window()->CurrentMessage()->FindInt32("clicks", &clicks);
if (fSelected) {
if (HasSelection()) {
CurPos inPos, stPos, edPos;
if (fSelStart < fSelEnd) {
stPos = fSelStart;
@@ -1855,7 +1851,6 @@ TermView::Select(CurPos start, CurPos end)
fTextBuffer->Select(fSelStart, fSelEnd);
TermDrawSelectedRegion(fSelStart, fSelEnd);
fSelected = true;
}
// Add select region(shift + mouse click)
@@ -1866,7 +1861,7 @@ TermView::AddSelectRegion(CurPos pos)
ushort attr;
CurPos start, end, inPos;
if (!fSelected)
if (!HasSelection())
return;
// error check, and if mouse point to a plase full width character,
@@ -1979,7 +1974,7 @@ TermView::DeSelect(void)
{
CurPos start, end;
if (!fSelected)
if (!HasSelection())
return;
fTextBuffer->DeSelect();
@@ -1991,10 +1986,16 @@ TermView::DeSelect(void)
fSelEnd.Set(-1, -1);
TermDrawSelectedRegion(start, end);
fSelected = false;
}
bool
TermView::HasSelection() const
{
return fSelStart != fSelEnd;
}
void
TermView::SelectWord(BPoint where, int mod)
{
+5 -5
View File
@@ -208,11 +208,12 @@ class TermView : public BView {
int32 GetWidthFromUTF8String (const char *);
// Mouse select
void Select(CurPos start, CurPos end);
void AddSelectRegion(CurPos);
void ResizeSelectRegion(CurPos);
void Select(CurPos start, CurPos end);
void AddSelectRegion(CurPos);
void ResizeSelectRegion(CurPos);
void DeSelect();
void DeSelect();
bool HasSelection() const;
// select word function
void SelectWord(BPoint where, int mod);
@@ -307,7 +308,6 @@ class TermView : public BView {
// view selection
CurPos fSelStart;
CurPos fSelEnd;
bool fSelected;
bool fMouseTracking;
// thread ID / flags.