* Small code cleanups, a bigger style cleanup should be done, but I didn't

want to mix too much cleanups into real changes.
* Got rid of the weird lines between rows.
* Tweaked colors (selections are usually dark everywhere else in Haiku).
* Implemented slightly tinting alternating rows.
* Removed the code duplication to figure out the appropriate background
  row color, fixed some inconsistencies between Draw() and RedrawColumn()
  in this regard.

TODO: Default colors should be computed based on current panel color though.

TODO: Figure out why the outline view does not scroll (at least not visibly)
when the vertical scroll bar is used.

TODO: Remove remaining redraw bugs. I observe a column of pixels not being
updated in some cases when resizing columns.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@24033 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Stephan Aßmus
2008-02-20 12:27:36 +00:00
parent 1d9a705ed4
commit da5d970124
+81 -130
View File
@@ -154,15 +154,7 @@ static const unsigned char kDownSortArrow8x8Invert[] = {
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff
}; };
/* static const float kTintedLineTint = 0.7 * B_NO_TINT + 0.3 * B_DARKEN_1_TINT;
static const rgb_color kTitleColor = {215, 215, 215, 255};
static const rgb_color kTitleTextColor = { 0, 0, 0, 255 };
static const rgb_color kDefaultBackgroundColor = {236, 236, 236, 255};
static const rgb_color kRowDividerColor = {148, 148, 148, 255};
static const rgb_color kDefaultSelectionColor = {255, 255, 255, 255};
static const rgb_color kDefaultEditColor = {180, 180, 180, 180};
static const rgb_color kNonFocusSelectionColor = {220, 220, 220, 255};
*/
static const float kTitleHeight = 17.0; static const float kTitleHeight = 17.0;
static const float kLatchWidth = 15.0; static const float kLatchWidth = 15.0;
@@ -173,9 +165,9 @@ static const rgb_color kColor[B_COLOR_TOTAL] =
{236, 236, 236, 255}, // B_COLOR_BACKGROUND {236, 236, 236, 255}, // B_COLOR_BACKGROUND
{ 0, 0, 0, 255}, // B_COLOR_TEXT { 0, 0, 0, 255}, // B_COLOR_TEXT
{148, 148, 148, 255}, // B_COLOR_ROW_DIVIDER {148, 148, 148, 255}, // B_COLOR_ROW_DIVIDER
{255, 255, 255, 255}, // B_COLOR_SELECTION {190, 190, 190, 255}, // B_COLOR_SELECTION
{ 0, 0, 0, 255}, // B_COLOR_SELECTION_TEXT { 0, 0, 0, 255}, // B_COLOR_SELECTION_TEXT
{220, 220, 220, 255}, // B_COLOR_NON_FOCUS_SELECTION {200, 200, 200, 255}, // B_COLOR_NON_FOCUS_SELECTION
{180, 180, 180, 180}, // B_COLOR_EDIT_BACKGROUND {180, 180, 180, 180}, // B_COLOR_EDIT_BACKGROUND
{ 0, 0, 0, 255}, // B_COLOR_EDIT_TEXT { 0, 0, 0, 255}, // B_COLOR_EDIT_TEXT
{215, 215, 215, 255}, // B_COLOR_HEADER_BACKGROUND {215, 215, 215, 255}, // B_COLOR_HEADER_BACKGROUND
@@ -1573,8 +1565,7 @@ void BColumnListView::SetEditMode(bool state)
void BColumnListView::Refresh() void BColumnListView::Refresh()
{ {
if(LockLooper()) if (LockLooper()) {
{
Invalidate(); Invalidate();
fOutlineView->FixScrollBar (true); fOutlineView->FixScrollBar (true);
fOutlineView->Invalidate(); fOutlineView->Invalidate();
@@ -1780,13 +1771,10 @@ void TitleView::MoveColumn(BColumn *column, int32 index)
{ {
fColumns->RemoveItem((void*) column); fColumns->RemoveItem((void*) column);
if (-1 == index) if (-1 == index) {
{
// Re-add the column at the end of the list. // Re-add the column at the end of the list.
fColumns->AddItem((void*) column); fColumns->AddItem((void*) column);
} } else {
else
{
fColumns->AddItem((void*) column, index); fColumns->AddItem((void*) column, index);
} }
} }
@@ -2513,39 +2501,56 @@ void OutlineView::RecursiveDeleteRows(BRowContainer* List, bool IsOwner)
void OutlineView::RedrawColumn(BColumn *column, float leftEdge, bool isFirstColumn) void OutlineView::RedrawColumn(BColumn *column, float leftEdge, bool isFirstColumn)
{ {
if (column) { // TODO: Remove code duplication (private function which takes a view
// pointer, pass "this" in non-double buffered mode)!
// Watch out for sourceRect versus destRect though!
if (!column)
return;
font_height fh; font_height fh;
GetFontHeight(&fh); GetFontHeight(&fh);
float line = 0.0; float line = 0.0;
bool tintedLine = true;
for (RecursiveOutlineIterator iterator(&fRows); iterator.CurrentRow(); for (RecursiveOutlineIterator iterator(&fRows); iterator.CurrentRow();
line += iterator.CurrentRow()->Height() + 1, iterator.GoToNext()) { line += iterator.CurrentRow()->Height() + 1, iterator.GoToNext()) {
BRow *row = iterator.CurrentRow(); BRow *row = iterator.CurrentRow();
float rowHeight = row->Height(); float rowHeight = row->Height();
if (line > fVisibleRect.bottom) if (line > fVisibleRect.bottom)
break; break;
tintedLine = !tintedLine;
if (line + rowHeight >= fVisibleRect.top) { if (line + rowHeight >= fVisibleRect.top) {
BRect sourceRect(0, 0, column->Width(), rowHeight); BRect sourceRect(0, 0, column->Width(), rowHeight);
BRect destRect(leftEdge, line, leftEdge + column->Width(), line + rowHeight); BRect destRect(leftEdge, line, leftEdge + column->Width(), line + rowHeight);
#if DOUBLE_BUFFERED_COLUMN_RESIZE rgb_color highColor;
fDrawBuffer->Lock(); rgb_color lowColor;
if (row->fNextSelected != 0) { if (row->fNextSelected != 0) {
if (fEditMode) { if (fEditMode) {
fDrawBufferView->SetHighColor(fMasterView->Color(B_COLOR_EDIT_BACKGROUND)); highColor = fMasterView->Color(B_COLOR_EDIT_BACKGROUND);
fDrawBufferView->SetLowColor(fMasterView->Color(B_COLOR_EDIT_BACKGROUND)); lowColor = fMasterView->Color(B_COLOR_EDIT_BACKGROUND);
} else { } else {
fDrawBufferView->SetHighColor(fMasterView->Color(B_COLOR_SELECTION)); highColor = fMasterView->Color(B_COLOR_SELECTION);
fDrawBufferView->SetLowColor(fMasterView->Color(B_COLOR_SELECTION)); lowColor = fMasterView->Color(B_COLOR_SELECTION);
} }
} else { } else {
fDrawBufferView->SetHighColor(fMasterView->Color(B_COLOR_BACKGROUND)); highColor = fMasterView->Color(B_COLOR_BACKGROUND);
fDrawBufferView->SetLowColor(fMasterView->Color(B_COLOR_BACKGROUND)); lowColor = fMasterView->Color(B_COLOR_BACKGROUND);
} }
if (tintedLine)
lowColor = tint_color(lowColor, kTintedLineTint);
#if DOUBLE_BUFFERED_COLUMN_RESIZE
fDrawBuffer->Lock();
fDrawBufferView->SetHighColor(highColor);
fDrawBufferView->SetLowColor(lowColor);
BFont font; BFont font;
GetFont(&font); GetFont(&font);
fDrawBufferView->SetFont(&font); fDrawBufferView->SetFont(&font);
fDrawBufferView->FillRect(sourceRect); fDrawBufferView->FillRect(sourceRect, B_SOLID_LOW);
if (isFirstColumn) { if (isFirstColumn) {
// If this is the first column, double buffer drawing the latch too. // If this is the first column, double buffer drawing the latch too.
@@ -2586,40 +2591,22 @@ void OutlineView::RedrawColumn(BColumn *column, float leftEdge, bool isFirstColu
#endif #endif
} }
if (fFocusRow == row) { if (fFocusRow == row && !fEditMode && fMasterView->IsFocus()
if(!fEditMode) { && Window()->IsActive()) {
fDrawBufferView->SetHighColor(fMasterView->Color(B_COLOR_SELECTION_TEXT));
fDrawBufferView->StrokeRect(BRect(-1, sourceRect.top, 10000.0, sourceRect.bottom - 1));
}
}
fDrawBufferView->SetHighColor(fMasterView->Color(B_COLOR_ROW_DIVIDER)); fDrawBufferView->SetHighColor(fMasterView->Color(B_COLOR_ROW_DIVIDER));
// StrokeLine(BPoint(0, line + rowHeight - 2), BPoint(Bounds().Width(), line + rowHeight - 2)); fDrawBufferView->StrokeRect(BRect(-1, sourceRect.top, 10000.0, sourceRect.bottom));
// StrokeLine(BPoint(0, line + rowHeight - 1), BPoint(Bounds().Width(), line + rowHeight - 1)); }
fDrawBufferView->StrokeLine(BPoint(0, rowHeight), BPoint(Bounds().right, rowHeight));
fDrawBufferView->Sync(); fDrawBufferView->Sync();
fDrawBuffer->Unlock(); fDrawBuffer->Unlock();
SetDrawingMode(B_OP_OVER); SetDrawingMode(B_OP_COPY);
DrawBitmap(fDrawBuffer, sourceRect, destRect); DrawBitmap(fDrawBuffer, sourceRect, destRect);
#else #else
if (row->fNextSelected != 0) { SetHighColor(highColor);
if(fEditMode) { SetLowColor(lowColor);
SetHighColor(fMasterView->Color(B_COLOR_EDIT_BACKGROUND)); FillRect(destRect, B_SOLID_LOW);
SetLowColor(fMasterView->Color(B_COLOR_EDIT_BACKGROUND));
}
else {
SetHighColor(fMasterView->Color(B_COLOR_SELECTION));
SetLowColor(fMasterView->Color(B_COLOR_SELECTION));
}
} else {
SetHighColor(fMasterView->Color(B_COLOR_BACKGROUND));
SetLowColor(fMasterView->Color(B_COLOR_BACKGROUND));
}
FillRect(destRect);
BField *field = row->GetField(column->fFieldID); BField *field = row->GetField(column->fFieldID);
if (field) { if (field) {
@@ -2640,24 +2627,15 @@ void OutlineView::RedrawColumn(BColumn *column, float leftEdge, bool isFirstColu
#endif #endif
} }
if (fFocusRow == row) { if (fFocusRow == row && !fEditMode && fMasterView->IsFocus()
if(!fEditMode) { && Window()->IsActive()) {
SetHighColor(fColorList[B_COLOR_SELECTION_TEXT]); SetHighColor(fColorList[B_COLOR_ROW_DIVIDER]);
StrokeRect(BRect(0, destRect.top, 10000.0, destRect.bottom - 1)); StrokeRect(BRect(0, destRect.top, 10000.0, destRect.bottom));
} }
}
rgb_color color = HighColor();
SetHighColor(fMasterView->Color(B_COLOR_ROW_DIVIDER));
// StrokeLine(BPoint(0, line + rowHeight - 2), BPoint(Bounds().Width(), line + rowHeight - 2));
// StrokeLine(BPoint(0, line + rowHeight - 1), BPoint(Bounds().Width(), line + rowHeight - 1));
StrokeLine(BPoint(0, line + rowHeight), BPoint(Bounds().right, line + rowHeight));
SetHighColor(color);
#endif #endif
} }
} }
} }
}
void OutlineView::Draw(BRect invalidBounds) void OutlineView::Draw(BRect invalidBounds)
{ {
@@ -2670,6 +2648,7 @@ void OutlineView::Draw(BRect invalidBounds)
GetFontHeight(&fh); GetFontHeight(&fh);
float line = 0.0; float line = 0.0;
bool tintedLine = true;
int32 numColumns = fColumns->CountItems(); int32 numColumns = fColumns->CountItems();
for (RecursiveOutlineIterator iterator(&fRows); iterator.CurrentRow(); for (RecursiveOutlineIterator iterator(&fRows); iterator.CurrentRow();
iterator.GoToNext()) { iterator.GoToNext()) {
@@ -2677,11 +2656,29 @@ void OutlineView::Draw(BRect invalidBounds)
if (line > invalidBounds.bottom) if (line > invalidBounds.bottom)
break; break;
tintedLine = !tintedLine;
float rowHeight = row->Height(); float rowHeight = row->Height();
if (line > invalidBounds.top - rowHeight) { if (line > invalidBounds.top - rowHeight) {
bool isFirstColumn = true; bool isFirstColumn = true;
float fieldLeftEdge = MAX(kLeftMargin, fMasterView->LatchWidth()); float fieldLeftEdge = MAX(kLeftMargin, fMasterView->LatchWidth());
// setup background color
rgb_color lowColor;
if (row->fNextSelected != 0) {
if (Window()->IsActive()) {
if (fEditMode)
lowColor = fMasterView->Color(B_COLOR_EDIT_BACKGROUND);
else
lowColor = fMasterView->Color(B_COLOR_SELECTION);
}
else
lowColor = fMasterView->Color(B_COLOR_NON_FOCUS_SELECTION);
} else
lowColor = fMasterView->Color(B_COLOR_BACKGROUND);
if (tintedLine)
lowColor = tint_color(lowColor, kTintedLineTint);
for (int columnIndex = 0; columnIndex < numColumns; columnIndex++) { for (int columnIndex = 0; columnIndex < numColumns; columnIndex++) {
BColumn *column = (BColumn*) fColumns->ItemAt(columnIndex); BColumn *column = (BColumn*) fColumns->ItemAt(columnIndex);
if (!column->IsVisible()) if (!column->IsVisible())
@@ -2698,17 +2695,7 @@ void OutlineView::Draw(BRect invalidBounds)
// This happens when a column is indented past the // This happens when a column is indented past the
// beginning of the next column. // beginning of the next column.
if (row->fNextSelected != 0) { SetHighColor(lowColor);
if (Window()->IsActive()) {
if(fEditMode)
SetHighColor(fMasterView->Color(B_COLOR_EDIT_BACKGROUND));
else
SetHighColor(fMasterView->Color(B_COLOR_SELECTION));
}
else
SetHighColor(fMasterView->Color(B_COLOR_NON_FOCUS_SELECTION));
} else
SetHighColor(fMasterView->Color(B_COLOR_BACKGROUND));
BRect destRect(fullRect); BRect destRect(fullRect);
if (isFirstColumn) { if (isFirstColumn) {
@@ -2721,7 +2708,6 @@ void OutlineView::Draw(BRect invalidBounds)
clippedFirstColumn = true; clippedFirstColumn = true;
} }
FillRect(BRect(0, line, MAX(kLeftMargin, fMasterView->LatchWidth()), line + row->Height())); FillRect(BRect(0, line, MAX(kLeftMargin, fMasterView->LatchWidth()), line + row->Height()));
} }
@@ -2761,20 +2747,9 @@ void OutlineView::Draw(BRect invalidBounds)
} }
} }
if (row->fNextSelected != 0) {
if (Window()->IsActive()) {
if(fEditMode)
SetLowColor(fMasterView->Color(B_COLOR_EDIT_BACKGROUND));
else
SetLowColor(fMasterView->Color(B_COLOR_SELECTION));
}
else
SetLowColor(fMasterView->Color(B_COLOR_NON_FOCUS_SELECTION));
} else
SetLowColor(fMasterView->Color(B_COLOR_BACKGROUND));
SetHighColor(fMasterView->HighColor()); SetHighColor(fMasterView->HighColor());
// The master view just holds the high color for us. // The master view just holds the high color for us.
SetLowColor(lowColor);
BField *field = row->GetField(column->fFieldID); BField *field = row->GetField(column->fFieldID);
if (field) { if (field) {
@@ -2802,39 +2777,23 @@ void OutlineView::Draw(BRect invalidBounds)
} }
if (fieldLeftEdge <= invalidBounds.right) { if (fieldLeftEdge <= invalidBounds.right) {
if (row->fNextSelected != 0) { SetHighColor(lowColor);
if (Window()->IsActive()) {
if(fEditMode)
SetHighColor(fMasterView->Color(B_COLOR_EDIT_BACKGROUND));
else
SetHighColor(fMasterView->Color(B_COLOR_SELECTION));
}
else
SetHighColor(fMasterView->Color(B_COLOR_NON_FOCUS_SELECTION));
} else
SetHighColor(fMasterView->Color(B_COLOR_BACKGROUND));
FillRect(BRect(fieldLeftEdge, line, invalidBounds.right, FillRect(BRect(fieldLeftEdge, line, invalidBounds.right,
line + rowHeight)); line + rowHeight));
} }
} }
if (fFocusRow == row && fMasterView->IsFocus() && Window()->IsActive()) { // indicate the keyboard focus row
if(!fEditMode) { if (fFocusRow == row && !fEditMode && fMasterView->IsFocus() && Window()->IsActive()) {
SetHighColor(fMasterView->Color(B_COLOR_SELECTION_TEXT));
StrokeRect(BRect(0, line, 10000.0, line + rowHeight - 1));
}
}
rgb_color color = HighColor();
SetHighColor(fMasterView->Color(B_COLOR_ROW_DIVIDER)); SetHighColor(fMasterView->Color(B_COLOR_ROW_DIVIDER));
// StrokeLine(BPoint(0, line + rowHeight - 2), BPoint(Bounds().Width(), line + rowHeight - 2)); StrokeRect(BRect(0, line, 10000.0, line + rowHeight));
// StrokeLine(BPoint(0, line + rowHeight - 1), BPoint(Bounds().Width(), line + rowHeight - 1)); }
StrokeLine(BPoint(invalidBounds.left, line + rowHeight), BPoint(invalidBounds.right, line + rowHeight));
SetHighColor(color);
line += rowHeight + 1; line += rowHeight + 1;
} }
if (line <= invalidBounds.bottom) { if (line <= invalidBounds.bottom) {
// fill background below last item
SetHighColor(fMasterView->Color(B_COLOR_BACKGROUND)); SetHighColor(fMasterView->Color(B_COLOR_BACKGROUND));
FillRect(BRect(invalidBounds.left, line, invalidBounds.right, invalidBounds.bottom)); FillRect(BRect(invalidBounds.left, line, invalidBounds.right, invalidBounds.bottom));
} }
@@ -3103,8 +3062,7 @@ void OutlineView::MouseMoved(BPoint position, uint32 /*transit*/, const BMessage
if (fCurrentField) { if (fCurrentField) {
if (fFieldRect.Contains(position)) { if (fFieldRect.Contains(position)) {
if (fCurrentCode == B_OUTSIDE_VIEW if (fCurrentCode == B_OUTSIDE_VIEW
|| fCurrentCode == B_EXITED_VIEW || fCurrentCode == B_EXITED_VIEW) {
) {
fCurrentColumn->MouseMoved(fMasterView, fCurrentRow, fCurrentColumn->MouseMoved(fMasterView, fCurrentRow,
fCurrentField, fFieldRect, position, 1, fCurrentCode = B_ENTERED_VIEW); fCurrentField, fFieldRect, position, 1, fCurrentCode = B_ENTERED_VIEW);
} else { } else {
@@ -3113,8 +3071,7 @@ void OutlineView::MouseMoved(BPoint position, uint32 /*transit*/, const BMessage
} }
} else { } else {
if (fCurrentCode == B_INSIDE_VIEW if (fCurrentCode == B_INSIDE_VIEW
|| fCurrentCode == B_ENTERED_VIEW || fCurrentCode == B_ENTERED_VIEW) {
) {
fCurrentColumn->MouseMoved(fMasterView, fCurrentRow, fCurrentColumn->MouseMoved(fMasterView, fCurrentRow,
fCurrentField, fFieldRect, position, 1, fCurrentCode = B_EXITED_VIEW); fCurrentField, fFieldRect, position, 1, fCurrentCode = B_EXITED_VIEW);
} else { } else {
@@ -3182,8 +3139,7 @@ void OutlineView::MouseMoved(BPoint position, uint32 /*transit*/, const BMessage
BRow *target = FindRow(position.y, &indent, &top); BRow *target = FindRow(position.y, &indent, &top);
if(target==fRollOverRow) if(target==fRollOverRow)
break; break;
if(fRollOverRow) if (fRollOverRow) {
{
BRect rect; BRect rect;
FindRect(fRollOverRow, &rect); FindRect(fRollOverRow, &rect);
Invalidate(rect); Invalidate(rect);
@@ -3202,8 +3158,7 @@ void OutlineView::MouseMoved(BPoint position, uint32 /*transit*/, const BMessage
PopState(); PopState();
#endif #endif
} else { } else {
if(fRollOverRow) if (fRollOverRow) {
{
BRect rect; BRect rect;
FindRect(fRollOverRow, &rect); FindRect(fRollOverRow, &rect);
Invalidate(rect); Invalidate(rect);
@@ -3254,7 +3209,7 @@ void OutlineView::MouseUp(BPoint position)
} }
} }
} }
} // end of MouseUp() }
void OutlineView::MessageReceived(BMessage *message) void OutlineView::MessageReceived(BMessage *message)
{ {
@@ -3453,8 +3408,7 @@ void OutlineView::RemoveRow(BRow *row)
if (parentRow) { if (parentRow) {
if (parentRow->fIsExpanded) if (parentRow->fIsExpanded)
fItemsHeight -= subTreeHeight + 1; fItemsHeight -= subTreeHeight + 1;
} } else {
else {
fItemsHeight -= subTreeHeight + 1; fItemsHeight -= subTreeHeight + 1;
} }
FixScrollBar(false); FixScrollBar(false);
@@ -3791,11 +3745,9 @@ bool OutlineView::FindRect(const BRow *row, BRect *out_rect)
void OutlineView::ScrollTo(const BRow* Row) void OutlineView::ScrollTo(const BRow* Row)
{ {
BRect rect; BRect rect;
if( true == FindRect(Row, &rect) ) if (FindRect(Row, &rect))
{
ScrollTo(BPoint(rect.left, rect.top)); ScrollTo(BPoint(rect.left, rect.top));
} }
}
void OutlineView::DeselectAll() void OutlineView::DeselectAll()
@@ -3834,8 +3786,7 @@ BRow* OutlineView::FocusRow() const
void OutlineView::SetFocusRow(BRow* Row, bool Select) void OutlineView::SetFocusRow(BRow* Row, bool Select)
{ {
if (Row) if (Row) {
{
if (Select) if (Select)
AddToSelection(Row); AddToSelection(Row);