From 89c9e2b9803a4d462aa46128959d2e8df124be5d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20A=C3=9Fmus?= Date: Tue, 31 Mar 2009 21:35:01 +0000 Subject: [PATCH] Puh... big coding style cleanup. I probably missed a few issues too... but should be much better now. There was like three different styles before. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@29841 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/kits/interface/ColumnListView.cpp | 2667 +++++++++++++++---------- 1 file changed, 1580 insertions(+), 1087 deletions(-) diff --git a/src/kits/interface/ColumnListView.cpp b/src/kits/interface/ColumnListView.cpp index 7684fbb730..7758403971 100644 --- a/src/kits/interface/ColumnListView.cpp +++ b/src/kits/interface/ColumnListView.cpp @@ -43,6 +43,8 @@ All rights reserved. / *******************************************************************************/ +#include "ColumnListView.h" + #include #include @@ -60,14 +62,9 @@ All rights reserved. #include #include -#include "ObjectList.h" -#include "ColumnListView.h" #include "ColorTools.h" -/* -#ifndef _ARCHIVE_DEFS_H -#include -#endif -*/ +#include "ObjectList.h" + #define DOUBLE_BUFFERED_COLUMN_RESIZE 1 #define SMART_REDRAW 1 #define DRAG_TITLE_OUTLINE 1 @@ -211,262 +208,296 @@ class BRowContainer : public BObjectList }; class TitleView : public BView { + typedef BView _inherited; public: - TitleView(BRect, OutlineView*, BList *visibleColumns, BList *sortColumns, - BColumnListView *masterView, uint32 resizingMode); - ~TitleView(); - void ColumnAdded(BColumn*); - void SetColumnVisible(BColumn*, bool); + TitleView(BRect frame, OutlineView* outlineView, + BList* visibleColumns, BList* sortColumns, + BColumnListView* masterView, + uint32 resizingMode); + virtual ~TitleView(); - virtual void Draw(BRect rect); - virtual void ScrollTo(BPoint); - virtual void MessageReceived(BMessage*); - virtual void MouseDown(BPoint); - virtual void MouseMoved(BPoint, uint32, const BMessage*); - virtual void MouseUp(BPoint position); - virtual void FrameResized(float width, float height); + void ColumnAdded(BColumn* column); + void SetColumnVisible(BColumn* column, bool visible); + + virtual void Draw(BRect updateRect); + virtual void ScrollTo(BPoint where); + virtual void MessageReceived(BMessage* message); + virtual void MouseDown(BPoint where); + virtual void MouseMoved(BPoint where, uint32 transit, + const BMessage* dragMessage); + virtual void MouseUp(BPoint where); + virtual void FrameResized(float width, float height); - void MoveColumn(BColumn *column, int32 index); - void SetColumnFlags(column_flags flags); + void MoveColumn(BColumn* column, int32 index); + void SetColumnFlags(column_flags flags); - void SetEditMode(bool state) { fEditMode = state; } + void SetEditMode(bool state) + { fEditMode = state; } private: - void GetTitleRect(BColumn*, BRect *out_rect); - int32 FindColumn(BPoint, float *out_leftEdge); - void FixScrollBar(bool scrollToFit); - void DragSelectedColumn(BPoint); - void ResizeSelectedColumn(BPoint, bool = false); - void ComputeDragBoundries(BColumn*, BPoint); - void DrawTitle(BView*, BRect, BColumn*, bool depressed); + void GetTitleRect(BColumn* column, BRect* _rect); + int32 FindColumn(BPoint where, float* _leftEdge); + void FixScrollBar(bool scrollToFit); + void DragSelectedColumn(BPoint where); + void ResizeSelectedColumn(BPoint where, + bool preferred = false); + void ComputeDragBoundries(BColumn* column, + BPoint where); + void DrawTitle(BView* view, BRect frame, + BColumn* column, bool depressed); - OutlineView *fOutlineView; - BList *fColumns; - BList *fSortColumns; - float fColumnsWidth; - BRect fVisibleRect; + OutlineView* fOutlineView; + BList* fColumns; + BList* fSortColumns; + float fColumnsWidth; + BRect fVisibleRect; #if DOUBLE_BUFFERED_COLUMN_RESIZE - BBitmap *fDrawBuffer; - BView *fDrawBufferView; + BBitmap* fDrawBuffer; + BView* fDrawBufferView; #endif - enum { - INACTIVE, - RESIZING_COLUMN, - PRESSING_COLUMN, - DRAG_COLUMN_INSIDE_TITLE, - DRAG_COLUMN_OUTSIDE_TITLE - } fCurrentState; + enum { + INACTIVE, + RESIZING_COLUMN, + PRESSING_COLUMN, + DRAG_COLUMN_INSIDE_TITLE, + DRAG_COLUMN_OUTSIDE_TITLE + } fCurrentState; - BPopUpMenu *fColumnPop; - BColumnListView *fMasterView; - bool fEditMode; - int32 fColumnFlags; + BPopUpMenu* fColumnPop; + BColumnListView* fMasterView; + bool fEditMode; + int32 fColumnFlags; // State information for resizing/dragging - BColumn *fSelectedColumn; - BRect fSelectedColumnRect; - bool fResizingFirstColumn; - BPoint fClickPoint; // offset within cell - float fLeftDragBoundry; - float fRightDragBoundry; - BPoint fCurrentDragPosition; + BColumn* fSelectedColumn; + BRect fSelectedColumnRect; + bool fResizingFirstColumn; + BPoint fClickPoint; // offset within cell + float fLeftDragBoundry; + float fRightDragBoundry; + BPoint fCurrentDragPosition; - BBitmap *fUpSortArrow; - BBitmap *fDownSortArrow; + BBitmap* fUpSortArrow; + BBitmap* fDownSortArrow; - BCursor *fResizeCursor; - BCursor *fMinResizeCursor; - BCursor *fMaxResizeCursor; - BCursor *fColumnMoveCursor; - - typedef BView _inherited; + BCursor* fResizeCursor; + BCursor* fMinResizeCursor; + BCursor* fMaxResizeCursor; + BCursor* fColumnMoveCursor; }; class OutlineView : public BView { + typedef BView _inherited; public: - OutlineView(BRect, BList *visibleColumns, BList *sortColumns, BColumnListView *listView); - ~OutlineView(); + OutlineView(BRect, BList* visibleColumns, + BList* sortColumns, + BColumnListView* listView); + virtual ~OutlineView(); virtual void Draw(BRect); const BRect& VisibleRect() const; - void RedrawColumn(BColumn *column, float leftEdge, bool isFirstColumn); + void RedrawColumn(BColumn* column, float leftEdge, + bool isFirstColumn); void StartSorting(); - float GetColumnPreferredWidth(BColumn *column); + float GetColumnPreferredWidth(BColumn* column); - void AddRow(BRow*, int32 index, BRow *TheRow); - BRow* CurrentSelection(BRow *lastSelected) const; + void AddRow(BRow*, int32 index, BRow* TheRow); + BRow* CurrentSelection(BRow* lastSelected) const; void ToggleFocusRowSelection(bool selectRange); void ToggleFocusRowOpen(); - void ChangeFocusRow(bool up, bool updateSelection, bool addToCurrentSelection); + void ChangeFocusRow(bool up, bool updateSelection, + bool addToCurrentSelection); void MoveFocusToVisibleRect(); - void ExpandOrCollapse(BRow *parent, bool expand); + void ExpandOrCollapse(BRow* parent, bool expand); void RemoveRow(BRow*); BRowContainer* RowList(); void UpdateRow(BRow*); - bool FindParent(BRow *row, BRow **out_parent, bool *out_isVisible); - int32 IndexOf(BRow *row); + bool FindParent(BRow* row, BRow** _parent, + bool* _isVisible); + int32 IndexOf(BRow* row); void Deselect(BRow*); void AddToSelection(BRow*); void DeselectAll(); BRow* FocusRow() const; - void SetFocusRow(BRow *row, bool select); - BRow* FindRow(float ypos, int32 *out_indent, float *out_top); - bool FindRect(const BRow *row, BRect *out_rect); - void ScrollTo(const BRow* Row); + void SetFocusRow(BRow* row, bool select); + BRow* FindRow(float ypos, int32* _indent, + float* _top); + bool FindRect(const BRow* row, BRect* _rect); + void ScrollTo(const BRow* row); void Clear(); - void SetSelectionMode(list_view_type); + void SetSelectionMode(list_view_type type); list_view_type SelectionMode() const; void SetMouseTrackingEnabled(bool); void FixScrollBar(bool scrollToFit); - void SetEditMode(bool state) { fEditMode = state; } + void SetEditMode(bool state) + { fEditMode = state; } virtual void FrameResized(float width, float height); - virtual void ScrollTo(BPoint pt); - virtual void MouseDown(BPoint); - virtual void MouseMoved(BPoint, uint32, const BMessage*); - virtual void MouseUp(BPoint); - virtual void MessageReceived(BMessage*); + virtual void ScrollTo(BPoint where); + virtual void MouseDown(BPoint where); + virtual void MouseMoved(BPoint where, uint32 transit, + const BMessage* dragMessage); + virtual void MouseUp(BPoint where); + virtual void MessageReceived(BMessage* message); private: - bool SortList(BRowContainer *list, bool isVisible); - static int32 DeepSortThreadEntry(void *outlineView); + bool SortList(BRowContainer* list, bool isVisible); + static int32 DeepSortThreadEntry(void* outlineView); void DeepSort(); - void SelectRange(BRow *start, BRow *end); - int32 CompareRows(BRow *row1, BRow *row2); - void AddSorted(BRowContainer *list, BRow *row); - void RecursiveDeleteRows(BRowContainer *list, bool owner); + void SelectRange(BRow* start, BRow* end); + int32 CompareRows(BRow* row1, BRow* row2); + void AddSorted(BRowContainer* list, BRow* row); + void RecursiveDeleteRows(BRowContainer* list, + bool owner); void InvalidateCachedPositions(); - bool FindVisibleRect(BRow *row, BRect *out_rect); + bool FindVisibleRect(BRow* row, BRect* _rect); - BList* fColumns; - BList* fSortColumns; - float fItemsHeight; - BRowContainer fRows; - BRect fVisibleRect; + BList* fColumns; + BList* fSortColumns; + float fItemsHeight; + BRowContainer fRows; + BRect fVisibleRect; #if DOUBLE_BUFFERED_COLUMN_RESIZE - BBitmap* fDrawBuffer; - BView* fDrawBufferView; + BBitmap* fDrawBuffer; + BView* fDrawBufferView; #endif - BRow* fFocusRow; - BRect fFocusRowRect; - BRow* fRollOverRow; + BRow* fFocusRow; + BRect fFocusRowRect; + BRow* fRollOverRow; - BRow fSelectionListDummyHead; - BRow* fLastSelectedItem; - BRow* fFirstSelectedItem; + BRow fSelectionListDummyHead; + BRow* fLastSelectedItem; + BRow* fFirstSelectedItem; - thread_id fSortThread; - int32 fNumSorted; - bool fSortCancelled; + thread_id fSortThread; + int32 fNumSorted; + bool fSortCancelled; - enum CurrentState - { - INACTIVE, - LATCH_CLICKED, - ROW_CLICKED, - DRAGGING_ROWS - }; + enum CurrentState { + INACTIVE, + LATCH_CLICKED, + ROW_CLICKED, + DRAGGING_ROWS + }; - CurrentState fCurrentState; + CurrentState fCurrentState; - BColumnListView* fMasterView; - list_view_type fSelectionMode; - bool fTrackMouse; - BField* fCurrentField; - BRow* fCurrentRow; - BColumn* fCurrentColumn; - bool fMouseDown; - BRect fFieldRect; - int32 fCurrentCode; - bool fEditMode; + BColumnListView* fMasterView; + list_view_type fSelectionMode; + bool fTrackMouse; + BField* fCurrentField; + BRow* fCurrentRow; + BColumn* fCurrentColumn; + bool fMouseDown; + BRect fFieldRect; + int32 fCurrentCode; + bool fEditMode; // State information for mouse/keyboard interaction - BPoint fClickPoint; - bool fDragging; - int32 fClickCount; - BRow *fTargetRow; - float fTargetRowTop; - BRect fLatchRect; - float fDropHighlightY; + BPoint fClickPoint; + bool fDragging; + int32 fClickCount; + BRow* fTargetRow; + float fTargetRowTop; + BRect fLatchRect; + float fDropHighlightY; friend class RecursiveOutlineIterator; - typedef BView _inherited; }; class RecursiveOutlineIterator { public: - RecursiveOutlineIterator(BRowContainer*, bool openBranchesOnly = true); - BRow *CurrentRow() const; - int32 CurrentLevel() const; - void GoToNext(); + RecursiveOutlineIterator( + BRowContainer* container, + bool openBranchesOnly = true); + + BRow* CurrentRow() const; + int32 CurrentLevel() const; + void GoToNext(); private: - struct { - BRowContainer *fRowSet; - int32 fIndex; - int32 fDepth; - } fStack[kMaxDepth]; + struct { + BRowContainer* fRowSet; + int32 fIndex; + int32 fDepth; + } fStack[kMaxDepth]; - int32 fStackIndex; - BRowContainer *fCurrentList; - int32 fCurrentListIndex; - int32 fCurrentListDepth; - bool fOpenBranchesOnly; + int32 fStackIndex; + BRowContainer* fCurrentList; + int32 fCurrentListIndex; + int32 fCurrentListDepth; + bool fOpenBranchesOnly; }; } // namespace BPrivate + using namespace BPrivate; + BField::BField() { } + BField::~BField() { } -// #pragma mark - - -void BColumn::MouseMoved(BColumnListView */*parent*/, BRow */*row*/, BField */*field*/, - BRect /*field_rect*/, BPoint/*point*/, uint32 /*buttons*/, int32 /*code*/) -{ -} - -void BColumn::MouseDown( BColumnListView */*parent*/, BRow */*row*/, BField */*field*/, - BRect /*field_rect*/, BPoint /*point*/, uint32 /*buttons*/) -{ -} - -void BColumn::MouseUp(BColumnListView */*parent*/, BRow */*row*/, BField */*field*/) -{ -} // #pragma mark - + +void +BColumn::MouseMoved(BColumnListView* /*parent*/, BRow* /*row*/, + BField* /*field*/, BRect /*field_rect*/, BPoint/*point*/, + uint32 /*buttons*/, int32 /*code*/) +{ +} + + +void +BColumn::MouseDown(BColumnListView* /*parent*/, BRow* /*row*/, + BField* /*field*/, BRect /*field_rect*/, BPoint /*point*/, + uint32 /*buttons*/) +{ +} + + +void +BColumn::MouseUp(BColumnListView* /*parent*/, BRow* /*row*/, BField* /*field*/) +{ +} + + +// #pragma mark - + + BRow::BRow(float height) - : fChildList(NULL), - fIsExpanded(false), - fHeight(height), - fNextSelected(NULL), - fPrevSelected(NULL), - fParent(NULL), - fList(NULL) + : + fChildList(NULL), + fIsExpanded(false), + fHeight(height), + fNextSelected(NULL), + fPrevSelected(NULL), + fParent(NULL), + fList(NULL) { } + BRow::~BRow() { while (true) { - BField *field = (BField*) fFields.RemoveItem(0L); + BField* field = (BField*) fFields.RemoveItem(0L); if (field == 0) break; @@ -474,32 +505,42 @@ BRow::~BRow() } } -bool BRow::HasLatch() const + +bool +BRow::HasLatch() const { return fChildList != 0; } -int32 BRow::CountFields() const + +int32 +BRow::CountFields() const { return fFields.CountItems(); } -BField* BRow::GetField(int32 index) + +BField* +BRow::GetField(int32 index) { - return (BField*) fFields.ItemAt(index); + return (BField*)fFields.ItemAt(index); } -const BField* BRow::GetField(int32 index) const + +const BField* +BRow::GetField(int32 index) const { - return (const BField*) fFields.ItemAt(index); + return (const BField*)fFields.ItemAt(index); } -void BRow::SetField(BField *field, int32 logicalFieldIndex) + +void +BRow::SetField(BField* field, int32 logicalFieldIndex) { if (fFields.ItemAt(logicalFieldIndex) != 0) - delete (BField*) fFields.RemoveItem(logicalFieldIndex); + delete (BField*)fFields.RemoveItem(logicalFieldIndex); - if( NULL != fList ) { + if (NULL != fList) { ValidateField(field, logicalFieldIndex); BRect inv; fList->GetRowRect(this, &inv); @@ -509,54 +550,54 @@ void BRow::SetField(BField *field, int32 logicalFieldIndex) fFields.AddItem(field, logicalFieldIndex); } -float BRow::Height() const + +float +BRow::Height() const { return fHeight; } -bool BRow::IsExpanded() const + +bool +BRow::IsExpanded() const { return fIsExpanded; } + void BRow::ValidateFields() const { - for( int32 i = 0; i < CountFields(); i++ ) - { + for (int32 i = 0; i < CountFields(); i++) ValidateField(GetField(i), i); - } } + void -BRow::ValidateField(const BField *field, int32 logicalFieldIndex) const +BRow::ValidateField(const BField* field, int32 logicalFieldIndex) const { // The Fields may be moved by the user, but the logicalFieldIndexes // do not change, so we need to map them over when checking the // Field types. BColumn* col = NULL; int32 items = fList->CountColumns(); - for( int32 i = 0 ; i < items; ++i ) - { + for (int32 i = 0 ; i < items; ++i) { col = fList->ColumnAt(i); if( col->LogicalFieldNum() == logicalFieldIndex ) break; } - if( NULL == col ) - { + if (NULL == col) { BString dbmessage("\n\n\tThe parent BColumnListView does not have " "\n\ta BColumn at the logical field index "); dbmessage << logicalFieldIndex << ".\n\n"; printf(dbmessage.String()); - } - else - { - if( false == col->AcceptsField(field) ) - { + } else { + if (!col->AcceptsField(field)) { BString dbmessage("\n\n\tThe BColumn of type "); dbmessage << typeid(*col).name() << "\n\tat logical field index " - << logicalFieldIndex << "\n\tdoes not support the field type " + << logicalFieldIndex << "\n\tdoes not support the " + "field type " << typeid(*field).name() << ".\n\n"; debugger(dbmessage.String()); } @@ -566,110 +607,150 @@ BRow::ValidateField(const BField *field, int32 logicalFieldIndex) const // #pragma mark - + BColumn::BColumn(float width, float minWidth, float maxWidth, alignment align) - : fWidth(width), - fMinWidth(minWidth), - fMaxWidth(maxWidth), - fVisible(true), - fList(0), - fShowHeading(true), - fAlignment(align) + : + fWidth(width), + fMinWidth(minWidth), + fMaxWidth(maxWidth), + fVisible(true), + fList(0), + fShowHeading(true), + fAlignment(align) { } + BColumn::~BColumn() { } -float BColumn::Width() const + +float +BColumn::Width() const { return fWidth; } -void BColumn::SetWidth(float width) + +void +BColumn::SetWidth(float width) { fWidth = width; } -float BColumn::MinWidth() const + +float +BColumn::MinWidth() const { return fMinWidth; } -float BColumn::MaxWidth() const + +float +BColumn::MaxWidth() const { return fMaxWidth; } -void BColumn::DrawTitle(BRect, BView*) + +void +BColumn::DrawTitle(BRect, BView*) { } -void BColumn::DrawField(BField*, BRect, BView*) + +void +BColumn::DrawField(BField*, BRect, BView*) { } -int BColumn::CompareFields(BField *, BField *) + +int +BColumn::CompareFields(BField*, BField*) { return 0; } -void BColumn::GetColumnName(BString* into) const + +void +BColumn::GetColumnName(BString* into) const { *into = "(Unnamed)"; } -float BColumn::GetPreferredWidth(BField *field, BView *parent) const + +float +BColumn::GetPreferredWidth(BField* field, BView* parent) const { return fWidth; } -bool BColumn::IsVisible() const + +bool +BColumn::IsVisible() const { return fVisible; } -void BColumn::SetVisible(bool visible) + +void +BColumn::SetVisible(bool visible) { if (fList && (fVisible != visible)) fList->SetColumnVisible(this, visible); } -bool BColumn::ShowHeading() const + +bool +BColumn::ShowHeading() const { return fShowHeading; } -void BColumn::SetShowHeading(bool state) + +void +BColumn::SetShowHeading(bool state) { fShowHeading = state; } -alignment BColumn::Alignment() const + +alignment +BColumn::Alignment() const { return fAlignment; } -void BColumn::SetAlignment(alignment align) + +void +BColumn::SetAlignment(alignment align) { fAlignment = align; } -bool BColumn::WantsEvents() const + +bool +BColumn::WantsEvents() const { return fWantsEvents; } -void BColumn::SetWantsEvents(bool state) + +void +BColumn::SetWantsEvents(bool state) { fWantsEvents = state; } -int32 BColumn::LogicalFieldNum() const + +int32 +BColumn::LogicalFieldNum() const { return fFieldID; } + bool BColumn::AcceptsField(const BField*) const { @@ -679,128 +760,52 @@ BColumn::AcceptsField(const BField*) const // #pragma mark - -BColumnListView::BColumnListView(BRect rect, const char *name, uint32 resizingMode, - uint32 drawFlags, border_style border, bool showHorizontalScrollbar) - : BView(rect, name, resizingMode, drawFlags | B_WILL_DRAW | B_FRAME_EVENTS | B_FULL_UPDATE_ON_RESIZE), - fStatusView(0), - fSelectionMessage(0), - fSortingEnabled(true), - fLatchWidth(kLatchWidth), - fBorderStyle(border) + +BColumnListView::BColumnListView(BRect rect, const char* name, + uint32 resizingMode, uint32 flags, border_style border, + bool showHorizontalScrollbar) + : + BView(rect, name, resizingMode, + flags | B_WILL_DRAW | B_FRAME_EVENTS | B_FULL_UPDATE_ON_RESIZE), + fStatusView(0), + fSelectionMessage(0), + fSortingEnabled(true), + fLatchWidth(kLatchWidth), + fBorderStyle(border) { - SetViewColor(B_TRANSPARENT_32_BIT); - - BRect bounds(rect); - bounds.OffsetTo(0, 0); - - for (int i = 0; i < (int)B_COLOR_TOTAL; i++) - fColorList[i] = kColor[i]; - - BRect titleRect(bounds); - titleRect.bottom = titleRect.top + kTitleHeight; -#if !LOWER_SCROLLBAR - titleRect.right -= B_V_SCROLL_BAR_WIDTH + 1; -#endif - - BRect outlineRect(bounds); - outlineRect.top = titleRect.bottom + 1.0; - outlineRect.right -= B_V_SCROLL_BAR_WIDTH + 1; - if(showHorizontalScrollbar) - outlineRect.bottom -= B_H_SCROLL_BAR_HEIGHT + 1; - - BRect vScrollBarRect(bounds); -#if LOWER_SCROLLBAR - vScrollBarRect.top += kTitleHeight; -#endif - - vScrollBarRect.left = vScrollBarRect.right - B_V_SCROLL_BAR_WIDTH; - if(showHorizontalScrollbar) - vScrollBarRect.bottom -= B_H_SCROLL_BAR_HEIGHT; - - BRect hScrollBarRect(bounds); - hScrollBarRect.top = hScrollBarRect.bottom - B_H_SCROLL_BAR_HEIGHT; - hScrollBarRect.right -= B_V_SCROLL_BAR_WIDTH; - - // Adjust stuff so the border will fit. - if (fBorderStyle == B_PLAIN_BORDER) { - titleRect.InsetBy(1, 0); - titleRect.top++; - outlineRect.InsetBy(1, 0); - outlineRect.bottom--; - - vScrollBarRect.OffsetBy(-1, 0); - vScrollBarRect.InsetBy(0, 1); - hScrollBarRect.OffsetBy(0, -1); - hScrollBarRect.InsetBy(1, 0); - } else if (fBorderStyle == B_FANCY_BORDER) { - titleRect.InsetBy(2, 0); - titleRect.top += 2; - outlineRect.InsetBy(2, 0); - outlineRect.bottom -= 2; - - vScrollBarRect.OffsetBy(-2, 0); - vScrollBarRect.InsetBy(0, 2); - hScrollBarRect.OffsetBy(0, -2); - hScrollBarRect.InsetBy(2, 0); - } - - fOutlineView = new OutlineView(outlineRect, &fColumns, &fSortColumns, this); - AddChild(fOutlineView); - - - // Adapt to correct resizing mode - uint32 fParentFlags = resizingMode; - // Always follow LEFT_RIGHT - uint32 fTitleFlags = B_FOLLOW_LEFT_RIGHT; - - if ((fParentFlags & B_FOLLOW_TOP) && (fParentFlags & ~B_FOLLOW_BOTTOM)) { - fTitleFlags |= B_FOLLOW_TOP; - } - else if ((fParentFlags & B_FOLLOW_BOTTOM) && (fParentFlags & ~B_FOLLOW_TOP)) { - fTitleFlags |= B_FOLLOW_BOTTOM; - } - - fTitleView = new TitleView(titleRect, fOutlineView, &fColumns, &fSortColumns, this, fTitleFlags); - - - AddChild(fTitleView); - fVerticalScrollBar = new BScrollBar(vScrollBarRect, "vertical_scroll_bar", - fOutlineView, 0.0, bounds.Height(), B_VERTICAL); - AddChild(fVerticalScrollBar); - fHorizontalScrollBar = new BScrollBar(hScrollBarRect, "horizontal_scroll_bar", - fTitleView, 0.0, bounds.Width(), B_HORIZONTAL); - AddChild(fHorizontalScrollBar); - if(!showHorizontalScrollbar) - fHorizontalScrollBar->Hide(); - fOutlineView->FixScrollBar(true); + _Init(showHorizontalScrollbar); } + BColumnListView::~BColumnListView() { - while (true) { - BColumn *column = (BColumn*) fColumns.RemoveItem(0L); - if (column == 0) - break; - + while (BColumn* column = (BColumn*)fColumns.RemoveItem(0L)) delete column; - } } -bool BColumnListView::InitiateDrag(BPoint, bool) + +bool +BColumnListView::InitiateDrag(BPoint, bool) { return false; } -void BColumnListView::MessageDropped(BMessage*, BPoint) + +void +BColumnListView::MessageDropped(BMessage*, BPoint) { } -void BColumnListView::ExpandOrCollapse(BRow* Row, bool Open) + +void +BColumnListView::ExpandOrCollapse(BRow* row, bool Open) { - fOutlineView->ExpandOrCollapse(Row, Open); + fOutlineView->ExpandOrCollapse(row, Open); } -status_t BColumnListView::Invoke(BMessage *message) + +status_t +BColumnListView::Invoke(BMessage* message) { if (message == 0) message = Message(); @@ -808,78 +813,108 @@ status_t BColumnListView::Invoke(BMessage *message) return BInvoker::Invoke(message); } -void BColumnListView::ItemInvoked() + +void +BColumnListView::ItemInvoked() { Invoke(); } -void BColumnListView::SetInvocationMessage(BMessage *message) + +void +BColumnListView::SetInvocationMessage(BMessage* message) { SetMessage(message); } -BMessage* BColumnListView::InvocationMessage() const + +BMessage* +BColumnListView::InvocationMessage() const { return Message(); } -uint32 BColumnListView::InvocationCommand() const + +uint32 +BColumnListView::InvocationCommand() const { return Command(); } -BRow* BColumnListView::FocusRow() const + +BRow* +BColumnListView::FocusRow() const { return fOutlineView->FocusRow(); } -void BColumnListView::SetFocusRow(int32 Index, bool Select) + +void +BColumnListView::SetFocusRow(int32 Index, bool Select) { SetFocusRow(RowAt(Index), Select); } -void BColumnListView::SetFocusRow(BRow* Row, bool Select) + +void +BColumnListView::SetFocusRow(BRow* row, bool Select) { - fOutlineView->SetFocusRow(Row, Select); + fOutlineView->SetFocusRow(row, Select); } -void BColumnListView::SetMouseTrackingEnabled(bool Enabled) + +void +BColumnListView::SetMouseTrackingEnabled(bool Enabled) { fOutlineView->SetMouseTrackingEnabled(Enabled); } -list_view_type BColumnListView::SelectionMode() const + +list_view_type +BColumnListView::SelectionMode() const { return fOutlineView->SelectionMode(); } -void BColumnListView::Deselect(BRow *row) + +void +BColumnListView::Deselect(BRow* row) { fOutlineView->Deselect(row); } -void BColumnListView::AddToSelection(BRow *row) + +void +BColumnListView::AddToSelection(BRow* row) { fOutlineView->AddToSelection(row); } -void BColumnListView::DeselectAll() + +void +BColumnListView::DeselectAll() { fOutlineView->DeselectAll(); } -BRow* BColumnListView::CurrentSelection(BRow *lastSelected) const + +BRow* +BColumnListView::CurrentSelection(BRow* lastSelected) const { return fOutlineView->CurrentSelection(lastSelected); } -void BColumnListView::SelectionChanged() + +void +BColumnListView::SelectionChanged() { if (fSelectionMessage) Invoke(fSelectionMessage); } -void BColumnListView::SetSelectionMessage(BMessage *message) + +void +BColumnListView::SetSelectionMessage(BMessage* message) { if (fSelectionMessage == message) return; @@ -888,12 +923,16 @@ void BColumnListView::SetSelectionMessage(BMessage *message) fSelectionMessage = message; } -BMessage* BColumnListView::SelectionMessage() + +BMessage* +BColumnListView::SelectionMessage() { return fSelectionMessage; } -uint32 BColumnListView::SelectionCommand() const + +uint32 +BColumnListView::SelectionCommand() const { if (fSelectionMessage) return fSelectionMessage->what; @@ -901,24 +940,32 @@ uint32 BColumnListView::SelectionCommand() const return 0; } -void BColumnListView::SetSelectionMode(list_view_type mode) + +void +BColumnListView::SetSelectionMode(list_view_type mode) { fOutlineView->SetSelectionMode(mode); } -void BColumnListView::SetSortingEnabled(bool enabled) + +void +BColumnListView::SetSortingEnabled(bool enabled) { fSortingEnabled = enabled; fSortColumns.MakeEmpty(); fTitleView->Invalidate(); // Erase sort indicators } -bool BColumnListView::SortingEnabled() const + +bool +BColumnListView::SortingEnabled() const { return fSortingEnabled; } -void BColumnListView::SetSortColumn(BColumn *column, bool add, bool ascending) + +void +BColumnListView::SetSortColumn(BColumn* column, bool add, bool ascending) { if (!SortingEnabled()) return; @@ -934,13 +981,17 @@ void BColumnListView::SetSortColumn(BColumn *column, bool add, bool ascending) fOutlineView->StartSorting(); } -void BColumnListView::ClearSortColumns() + +void +BColumnListView::ClearSortColumns() { fSortColumns.MakeEmpty(); fTitleView->Invalidate(); // Erase sort indicators } -void BColumnListView::AddStatusView(BView *view) + +void +BColumnListView::AddStatusView(BView* view) { BRect bounds = Bounds(); float width = view->Bounds().Width(); @@ -968,7 +1019,9 @@ void BColumnListView::AddStatusView(BView *view) Window()->EndViewTransaction(); } -BView* BColumnListView::RemoveStatusView() + +BView* +BColumnListView::RemoveStatusView() { if (fStatusView) { float width = fStatusView->Bounds().Width(); @@ -979,20 +1032,23 @@ BView* BColumnListView::RemoveStatusView() Window()->EndViewTransaction(); } - BView *view = fStatusView; + BView* view = fStatusView; fStatusView = 0; return view; } -void BColumnListView::AddColumn(BColumn *column, int32 logicalFieldIndex) + + +void +BColumnListView::AddColumn(BColumn* column, int32 logicalFieldIndex) { - ASSERT(column != 0); + ASSERT(column != NULL); column->fList = this; column->fFieldID = logicalFieldIndex; // sanity check. If there is already a field with this ID, remove it. for (int32 index = 0; index < fColumns.CountItems(); index++) { - BColumn *existingColumn = (BColumn*) fColumns.ItemAt(index); + BColumn* existingColumn = (BColumn*) fColumns.ItemAt(index); if (existingColumn && existingColumn->fFieldID == logicalFieldIndex) { RemoveColumn(existingColumn); break; @@ -1008,13 +1064,17 @@ void BColumnListView::AddColumn(BColumn *column, int32 logicalFieldIndex) fTitleView->ColumnAdded(column); } -void BColumnListView::MoveColumn(BColumn *column, int32 index) + +void +BColumnListView::MoveColumn(BColumn* column, int32 index) { - ASSERT(column != 0); + ASSERT(column != NULL); fTitleView->MoveColumn(column, index); } -void BColumnListView::RemoveColumn(BColumn *column) + +void +BColumnListView::RemoveColumn(BColumn* column) { if (fColumns.HasItem(column)) { SetColumnVisible(column, false); @@ -1023,144 +1083,191 @@ void BColumnListView::RemoveColumn(BColumn *column) } } -int32 BColumnListView::CountColumns() const + +int32 +BColumnListView::CountColumns() const { return fColumns.CountItems(); } -BColumn* BColumnListView::ColumnAt(int32 field) const + +BColumn* +BColumnListView::ColumnAt(int32 field) const { return (BColumn*) fColumns.ItemAt(field); } -void BColumnListView::SetColumnVisible(BColumn *column, bool visible) + +void +BColumnListView::SetColumnVisible(BColumn* column, bool visible) { fTitleView->SetColumnVisible(column, visible); } -void BColumnListView::SetColumnVisible(int32 index, bool isVisible) + +void +BColumnListView::SetColumnVisible(int32 index, bool isVisible) { - BColumn *column = ColumnAt(index); + BColumn* column = ColumnAt(index); if (column) column->SetVisible(isVisible); } -bool BColumnListView::IsColumnVisible(int32 index) const + +bool +BColumnListView::IsColumnVisible(int32 index) const { - BColumn *column = ColumnAt(index); + BColumn* column = ColumnAt(index); if (column) return column->IsVisible(); return false; } -void BColumnListView::SetColumnFlags(column_flags flags) + +void +BColumnListView::SetColumnFlags(column_flags flags) { fTitleView->SetColumnFlags(flags); } -const BRow* BColumnListView::RowAt(int32 Index, BRow* ParentRow) const + +const BRow* +BColumnListView::RowAt(int32 Index, BRow* parentRow) const { - if (ParentRow == 0) + if (parentRow == 0) return fOutlineView->RowList()->ItemAt(Index); - return ParentRow->fChildList ? ParentRow->fChildList->ItemAt(Index) : NULL; + return parentRow->fChildList ? parentRow->fChildList->ItemAt(Index) : NULL; } -BRow* BColumnListView::RowAt(int32 Index, BRow* ParentRow) + +BRow* +BColumnListView::RowAt(int32 Index, BRow* parentRow) { - if (ParentRow == 0) + if (parentRow == 0) return fOutlineView->RowList()->ItemAt(Index); - return ParentRow->fChildList ? ParentRow->fChildList->ItemAt(Index) : 0; + return parentRow->fChildList ? parentRow->fChildList->ItemAt(Index) : 0; } -const BRow* BColumnListView::RowAt(BPoint point) const + +const BRow* +BColumnListView::RowAt(BPoint point) const { float top; int32 indent; return fOutlineView->FindRow(point.y, &indent, &top); } -BRow* BColumnListView::RowAt(BPoint point) + +BRow* +BColumnListView::RowAt(BPoint point) { float top; int32 indent; return fOutlineView->FindRow(point.y, &indent, &top); } -bool BColumnListView::GetRowRect(const BRow *row, BRect *outRect) const + +bool +BColumnListView::GetRowRect(const BRow* row, BRect* outRect) const { return fOutlineView->FindRect(row, outRect); } -bool BColumnListView::FindParent(BRow *row, BRow **out_parent, bool *out_isVisible) const + +bool +BColumnListView::FindParent(BRow* row, BRow** _parent, bool* _isVisible) const { - return fOutlineView->FindParent(row, out_parent, out_isVisible); + return fOutlineView->FindParent(row, _parent, _isVisible); } -int32 BColumnListView::IndexOf(BRow *row) + +int32 +BColumnListView::IndexOf(BRow* row) { return fOutlineView->IndexOf(row); } -int32 BColumnListView::CountRows(BRow* ParentRow) const + +int32 +BColumnListView::CountRows(BRow* parentRow) const { - if (ParentRow == 0) + if (parentRow == 0) return fOutlineView->RowList()->CountItems(); - if (ParentRow->fChildList) - return ParentRow->fChildList->CountItems(); + if (parentRow->fChildList) + return parentRow->fChildList->CountItems(); else return 0; } -void BColumnListView::AddRow(BRow *row, BRow* ParentRow) + +void +BColumnListView::AddRow(BRow* row, BRow* parentRow) { - AddRow(row, -1, ParentRow); + AddRow(row, -1, parentRow); } -void BColumnListView::AddRow(BRow *row, int32 index, BRow* ParentRow) + +void +BColumnListView::AddRow(BRow* row, int32 index, BRow* parentRow) { row->fChildList = 0; row->fList = this; row->ValidateFields(); - fOutlineView->AddRow(row, index, ParentRow); + fOutlineView->AddRow(row, index, parentRow); } -void BColumnListView::RemoveRow(BRow *row) + +void +BColumnListView::RemoveRow(BRow* row) { fOutlineView->RemoveRow(row); row->fList = NULL; } -void BColumnListView::UpdateRow(BRow *row) + +void +BColumnListView::UpdateRow(BRow* row) { fOutlineView->UpdateRow(row); } -void BColumnListView::ScrollTo(const BRow* Row) + +void +BColumnListView::ScrollTo(const BRow* row) { - fOutlineView->ScrollTo(Row); + fOutlineView->ScrollTo(row); } -void BColumnListView::ScrollTo(BPoint point) + +void +BColumnListView::ScrollTo(BPoint point) { fOutlineView->ScrollTo(point); } -void BColumnListView::Clear() + +void +BColumnListView::Clear() { fOutlineView->Clear(); } -void BColumnListView::SetFont(const BFont *font, uint32 mask) + +void +BColumnListView::SetFont(const BFont* font, uint32 mask) { // This method is deprecated. fOutlineView->SetFont(font, mask); fTitleView->SetFont(font, mask); } -void BColumnListView::SetFont(ColumnListViewFont font_num, const BFont* font, uint32 mask) + +void +BColumnListView::SetFont(ColumnListViewFont font_num, const BFont* font, + uint32 mask) { switch (font_num) { case B_FONT_ROW: @@ -1174,10 +1281,12 @@ void BColumnListView::SetFont(ColumnListViewFont font_num, const BFont* font, ui default: ASSERT(false); break; - }; + } } -void BColumnListView::GetFont(ColumnListViewFont font_num, BFont* font) const + +void +BColumnListView::GetFont(ColumnListViewFont font_num, BFont* font) const { switch (font_num) { case B_FONT_ROW: @@ -1191,19 +1300,19 @@ void BColumnListView::GetFont(ColumnListViewFont font_num, BFont* font) const default: ASSERT(false); break; - }; + } } -void BColumnListView::SetColor(ColumnListViewColor color_num, const rgb_color color) + +void +BColumnListView::SetColor(ColumnListViewColor color_num, const rgb_color color) { - if ((int)color_num < 0) - { + if ((int)color_num < 0) { ASSERT(false); color_num = (ColumnListViewColor) 0; } - if ((int)color_num >= (int)B_COLOR_TOTAL) - { + if ((int)color_num >= (int)B_COLOR_TOTAL) { ASSERT(false); color_num = (ColumnListViewColor) (B_COLOR_TOTAL - 1); } @@ -1211,16 +1320,16 @@ void BColumnListView::SetColor(ColumnListViewColor color_num, const rgb_color co fColorList[color_num] = color; } -rgb_color BColumnListView::Color(ColumnListViewColor color_num) const + +rgb_color +BColumnListView::Color(ColumnListViewColor color_num) const { - if ((int)color_num < 0) - { + if ((int)color_num < 0) { ASSERT(false); color_num = (ColumnListViewColor) 0; } - if ((int)color_num >= (int)B_COLOR_TOTAL) - { + if ((int)color_num >= (int)B_COLOR_TOTAL) { ASSERT(false); color_num = (ColumnListViewColor) (B_COLOR_TOTAL - 1); } @@ -1228,7 +1337,9 @@ rgb_color BColumnListView::Color(ColumnListViewColor color_num) const return fColorList[color_num]; } -void BColumnListView::SetHighColor(rgb_color color) + +void +BColumnListView::SetHighColor(rgb_color color) { BView::SetHighColor(color); // fOutlineView->Invalidate(); // Redraw things with the new color @@ -1237,45 +1348,60 @@ void BColumnListView::SetHighColor(rgb_color color) // A better solution is needed. } -void BColumnListView::SetSelectionColor(rgb_color color) + +void +BColumnListView::SetSelectionColor(rgb_color color) { fColorList[B_COLOR_SELECTION] = color; } -void BColumnListView::SetBackgroundColor(rgb_color color) + +void +BColumnListView::SetBackgroundColor(rgb_color color) { fColorList[B_COLOR_BACKGROUND] = color; fOutlineView->Invalidate(); // Repaint with new color } -void BColumnListView::SetEditColor(rgb_color color) + +void +BColumnListView::SetEditColor(rgb_color color) { fColorList[B_COLOR_EDIT_BACKGROUND] = color; } -const rgb_color BColumnListView::SelectionColor() const + +const rgb_color +BColumnListView::SelectionColor() const { return fColorList[B_COLOR_SELECTION]; } -const rgb_color BColumnListView::BackgroundColor() const + +const rgb_color +BColumnListView::BackgroundColor() const { return fColorList[B_COLOR_BACKGROUND]; } -const rgb_color BColumnListView::EditColor() const + +const rgb_color +BColumnListView::EditColor() const { return fColorList[B_COLOR_EDIT_BACKGROUND]; } -BPoint BColumnListView::SuggestTextPosition(const BRow* row, const BColumn* inColumn) const + +BPoint +BColumnListView::SuggestTextPosition(const BRow* row, + const BColumn* inColumn) const { BRect rect; GetRowRect(row, &rect); if (inColumn) { float leftEdge = MAX(kLeftMargin, LatchWidth()); for (int index = 0; index < fColumns.CountItems(); index++) { - BColumn *column = (BColumn*) fColumns.ItemAt(index); + BColumn* column = (BColumn*) fColumns.ItemAt(index); if (!column->IsVisible()) continue; @@ -1296,18 +1422,23 @@ BPoint BColumnListView::SuggestTextPosition(const BRow* row, const BColumn* inCo return BPoint(rect.left + 8, baseline); } -void BColumnListView::SetLatchWidth(float width) + +void +BColumnListView::SetLatchWidth(float width) { fLatchWidth = width; Invalidate(); } -float BColumnListView::LatchWidth() const + +float +BColumnListView::LatchWidth() const { return fLatchWidth; } -void BColumnListView::DrawLatch(BView *view, BRect rect, LatchType position, BRow *) +void +BColumnListView::DrawLatch(BView* view, BRect rect, LatchType position, BRow*) { const int32 rectInset = 4; @@ -1315,10 +1446,8 @@ void BColumnListView::DrawLatch(BView *view, BRect rect, LatchType position, BRo // Make Square int32 sideLen = rect.IntegerWidth(); - if( sideLen > rect.IntegerHeight() ) - { + if (sideLen > rect.IntegerHeight()) sideLen = rect.IntegerHeight(); - } // Make Center int32 halfWidth = rect.IntegerWidth() / 2; @@ -1336,34 +1465,48 @@ void BColumnListView::DrawLatch(BView *view, BRect rect, LatchType position, BRo itemRect.InsetBy(rectInset, rectInset); // Make it an odd number of pixels wide, the latch looks better this way - if (1 == (itemRect.IntegerWidth() % 2)) - { - itemRect.right += 1; + if ((itemRect.IntegerWidth() % 2) == 1) { + itemRect.right += 1; itemRect.bottom += 1; } switch (position) { case B_OPEN_LATCH: view->StrokeRect(itemRect); - view->StrokeLine(BPoint(itemRect.left + 2, (itemRect.top + itemRect.bottom) / 2), - BPoint(itemRect.right - 2, (itemRect.top + itemRect.bottom) / 2)); + view->StrokeLine( + BPoint(itemRect.left + 2, + (itemRect.top + itemRect.bottom) / 2), + BPoint(itemRect.right - 2, + (itemRect.top + itemRect.bottom) / 2)); break; case B_PRESSED_LATCH: view->StrokeRect(itemRect); - view->StrokeLine(BPoint(itemRect.left + 2, (itemRect.top + itemRect.bottom) / 2), - BPoint(itemRect.right - 2, (itemRect.top + itemRect.bottom) / 2)); - view->StrokeLine(BPoint((itemRect.left + itemRect.right) / 2, itemRect.top + 2), - BPoint((itemRect.left + itemRect.right) / 2, itemRect.bottom - 2)); + view->StrokeLine( + BPoint(itemRect.left + 2, + (itemRect.top + itemRect.bottom) / 2), + BPoint(itemRect.right - 2, + (itemRect.top + itemRect.bottom) / 2)); + view->StrokeLine( + BPoint((itemRect.left + itemRect.right) / 2, + itemRect.top + 2), + BPoint((itemRect.left + itemRect.right) / 2, + itemRect.bottom - 2)); view->InvertRect(itemRect); break; case B_CLOSED_LATCH: view->StrokeRect(itemRect); - view->StrokeLine(BPoint(itemRect.left + 2, (itemRect.top + itemRect.bottom) / 2), - BPoint(itemRect.right - 2, (itemRect.top + itemRect.bottom) / 2)); - view->StrokeLine(BPoint((itemRect.left + itemRect.right) / 2, itemRect.top + 2), - BPoint((itemRect.left + itemRect.right) / 2, itemRect.bottom - 2)); + view->StrokeLine( + BPoint(itemRect.left + 2, + (itemRect.top + itemRect.bottom) / 2), + BPoint(itemRect.right - 2, + (itemRect.top + itemRect.bottom) / 2)); + view->StrokeLine( + BPoint((itemRect.left + itemRect.right) / 2, + itemRect.top + 2), + BPoint((itemRect.left + itemRect.right) / 2, + itemRect.bottom - 2)); break; case B_NO_LATCH: @@ -1372,13 +1515,17 @@ void BColumnListView::DrawLatch(BView *view, BRect rect, LatchType position, BRo } } -void BColumnListView::MakeFocus(bool isFocus) + +void +BColumnListView::MakeFocus(bool isFocus) { Invalidate(); // Redraw focus marks around view BView::MakeFocus(isFocus); } -void BColumnListView::MessageReceived(BMessage *message) + +void +BColumnListView::MessageReceived(BMessage* message) { // Propagate mouse wheel messages down to child, so that it can // scroll. Note we have done so, so we don't go into infinite @@ -1391,15 +1538,19 @@ void BColumnListView::MessageReceived(BMessage *message) return; } } + BView::MessageReceived(message); } -void BColumnListView::KeyDown(const char *bytes, int32 numBytes) + +void +BColumnListView::KeyDown(const char* bytes, int32 numBytes) { char c = bytes[0]; switch (c) { case B_RIGHT_ARROW: - case B_LEFT_ARROW: { + case B_LEFT_ARROW: + { float minVal, maxVal; fHorizontalScrollBar->GetRange(&minVal, &maxVal); float smallStep, largeStep; @@ -1422,17 +1573,20 @@ void BColumnListView::KeyDown(const char *bytes, int32 numBytes) } case B_DOWN_ARROW: - fOutlineView->ChangeFocusRow(false, (modifiers() & B_CONTROL_KEY) == 0, + fOutlineView->ChangeFocusRow(false, + (modifiers() & B_CONTROL_KEY) == 0, (modifiers() & B_SHIFT_KEY) != 0); break; case B_UP_ARROW: - fOutlineView->ChangeFocusRow(true, (modifiers() & B_CONTROL_KEY) == 0, + fOutlineView->ChangeFocusRow(true, + (modifiers() & B_CONTROL_KEY) == 0, (modifiers() & B_SHIFT_KEY) != 0); break; case B_PAGE_UP: - case B_PAGE_DOWN: { + case B_PAGE_DOWN: + { float minValue, maxValue; fVerticalScrollBar->GetRange(&minValue, &maxValue); float smallStep, largeStep; @@ -1464,7 +1618,8 @@ void BColumnListView::KeyDown(const char *bytes, int32 numBytes) break; case B_SPACE: - fOutlineView->ToggleFocusRowSelection((modifiers() & B_SHIFT_KEY) != 0); + fOutlineView->ToggleFocusRowSelection( + (modifiers() & B_SHIFT_KEY) != 0); break; case '+': @@ -1476,7 +1631,9 @@ void BColumnListView::KeyDown(const char *bytes, int32 numBytes) } } -void BColumnListView::AttachedToWindow() + +void +BColumnListView::AttachedToWindow() { if (!Messenger().IsValid()) SetTarget(Window()); @@ -1484,7 +1641,9 @@ void BColumnListView::AttachedToWindow() if (SortingEnabled()) fOutlineView->StartSorting(); } -void BColumnListView::WindowActivated(bool active) + +void +BColumnListView::WindowActivated(bool active) { fOutlineView->Invalidate(); // Focus and selection appearance changes with focus @@ -1493,13 +1652,15 @@ void BColumnListView::WindowActivated(bool active) BView::WindowActivated(active); } -void BColumnListView::Draw(BRect) + +void +BColumnListView::Draw(BRect) { BRect rect = Bounds(); PushState(); - BRect cornerRect(rect.right - B_V_SCROLL_BAR_WIDTH, rect.bottom - B_H_SCROLL_BAR_HEIGHT, - rect.right, rect.bottom); + BRect cornerRect(rect.right - B_V_SCROLL_BAR_WIDTH, + rect.bottom - B_H_SCROLL_BAR_HEIGHT, rect.right, rect.bottom); if (fBorderStyle == B_PLAIN_BORDER) { BView::SetHighColor(0, 0, 0); StrokeRect(rect); @@ -1507,9 +1668,10 @@ void BColumnListView::Draw(BRect) } else if (fBorderStyle == B_FANCY_BORDER) { bool isFocus = IsFocus() && Window()->IsActive(); - if (isFocus) - BView::SetHighColor(0, 0, 190); // Need to find focus color programatically - else + if (isFocus) { + // TODO: Need to find focus color programatically + BView::SetHighColor(0, 0, 190); + } else BView::SetHighColor(255, 255, 255); StrokeRect(rect); @@ -1523,16 +1685,19 @@ void BColumnListView::Draw(BRect) cornerRect.OffsetBy(-2, -2); } - BView::SetHighColor(215, 215, 215); // fills lower right rect between scroll bars + BView::SetHighColor(ui_color(B_PANEL_BACKGROUND_COLOR)); + // fills lower right rect between scroll bars FillRect(cornerRect); PopState(); } -void BColumnListView::SaveState(BMessage *msg) + +void +BColumnListView::SaveState(BMessage* msg) { msg->MakeEmpty(); - for (int32 i = 0; BColumn *col = (BColumn*)fColumns.ItemAt(i); i++) { + for (int32 i = 0; BColumn* col = (BColumn*)fColumns.ItemAt(i); i++) { msg->AddInt32("ID",col->fFieldID); msg->AddFloat("width", col->fWidth); msg->AddBool("visible", col->fVisible); @@ -1541,7 +1706,7 @@ void BColumnListView::SaveState(BMessage *msg) msg->AddBool("sortingenabled", fSortingEnabled); if (fSortingEnabled) { - for (int32 i = 0; BColumn *col = (BColumn*)fSortColumns.ItemAt(i); + for (int32 i = 0; BColumn* col = (BColumn*)fSortColumns.ItemAt(i); i++) { msg->AddInt32("sortID", col->fFieldID); msg->AddBool("sortascending", col->fSortAscending); @@ -1549,7 +1714,9 @@ void BColumnListView::SaveState(BMessage *msg) } } -void BColumnListView::LoadState(BMessage *msg) + +void +BColumnListView::LoadState(BMessage* msg) { int32 id; for (int i = 0; msg->FindInt32("ID", i, &id) == B_OK; i++) { @@ -1583,13 +1750,17 @@ void BColumnListView::LoadState(BMessage *msg) } } -void BColumnListView::SetEditMode(bool state) + +void +BColumnListView::SetEditMode(bool state) { fOutlineView->SetEditMode(state); fTitleView->SetEditMode(state); } -void BColumnListView::Refresh() + +void +BColumnListView::Refresh() { if (LockLooper()) { Invalidate(); @@ -1600,24 +1771,28 @@ void BColumnListView::Refresh() } } + // #pragma mark - -TitleView::TitleView(BRect rect, OutlineView *horizontalSlave, BList *visibleColumns, - BList *sortColumns, BColumnListView *listView, uint32 resizingMode) - : BView(rect, "title_view", resizingMode, B_WILL_DRAW | B_FRAME_EVENTS), - fOutlineView(horizontalSlave), - fColumns(visibleColumns), - fSortColumns(sortColumns), - fColumnsWidth(0), - fVisibleRect(rect.OffsetToCopy(0, 0)), - fCurrentState(INACTIVE), - fColumnPop(NULL), - fMasterView(listView), - fEditMode(false), - fColumnFlags(B_ALLOW_COLUMN_MOVE|B_ALLOW_COLUMN_RESIZE|B_ALLOW_COLUMN_POPUP|B_ALLOW_COLUMN_REMOVE) +TitleView::TitleView(BRect rect, OutlineView* horizontalSlave, + BList* visibleColumns, BList* sortColumns, BColumnListView* listView, + uint32 resizingMode) + : + BView(rect, "title_view", resizingMode, B_WILL_DRAW | B_FRAME_EVENTS), + fOutlineView(horizontalSlave), + fColumns(visibleColumns), + fSortColumns(sortColumns), + fColumnsWidth(0), + fVisibleRect(rect.OffsetToCopy(0, 0)), + fCurrentState(INACTIVE), + fColumnPop(NULL), + fMasterView(listView), + fEditMode(false), + fColumnFlags(B_ALLOW_COLUMN_MOVE | B_ALLOW_COLUMN_RESIZE + | B_ALLOW_COLUMN_POPUP | B_ALLOW_COLUMN_REMOVE) { - SetViewColor(B_TRANSPARENT_32_BIT); + SetViewColor(B_TRANSPARENT_COLOR); #if DOUBLE_BUFFERED_COLUMN_RESIZE // xxx this needs to be smart about the size of the backbuffer. @@ -1644,6 +1819,7 @@ TitleView::TitleView(BRect rect, OutlineView *horizontalSlave, BList *visibleCol FixScrollBar(true); } + TitleView::~TitleView() { delete fColumnPop; @@ -1663,14 +1839,18 @@ TitleView::~TitleView() delete fColumnMoveCursor; } -void TitleView::ColumnAdded(BColumn *column) + +void +TitleView::ColumnAdded(BColumn* column) { fColumnsWidth += column->Width() + 1; FixScrollBar(false); Invalidate(); } -// Could use a CopyBits here. -void TitleView::SetColumnVisible(BColumn *column, bool visible) + + +void +TitleView::SetColumnVisible(BColumn* column, bool visible) { if (column->fVisible == visible) return; @@ -1699,17 +1879,20 @@ void TitleView::SetColumnVisible(BColumn *column, bool visible) fOutlineView->Invalidate(outlineInvalid); } -void TitleView::GetTitleRect(BColumn *findColumn, BRect *out_rect) + +void +TitleView::GetTitleRect(BColumn* findColumn, BRect* _rect) { float leftEdge = MAX(kLeftMargin, fMasterView->LatchWidth()); int32 numColumns = fColumns->CountItems(); for (int index = 0; index < numColumns; index++) { - BColumn *column = (BColumn*) fColumns->ItemAt(index); + BColumn* column = (BColumn*) fColumns->ItemAt(index); if (!column->IsVisible()) continue; if (column == findColumn) { - out_rect->Set(leftEdge, 0, leftEdge + column->Width(), fVisibleRect.bottom); + _rect->Set(leftEdge, 0, leftEdge + column->Width(), + fVisibleRect.bottom); return; } @@ -1719,20 +1902,23 @@ void TitleView::GetTitleRect(BColumn *findColumn, BRect *out_rect) TRESPASS(); } -int32 TitleView::FindColumn(BPoint position, float *out_leftEdge) + +int32 +TitleView::FindColumn(BPoint position, float* _leftEdge) { float leftEdge = MAX(kLeftMargin, fMasterView->LatchWidth()); int32 numColumns = fColumns->CountItems(); for (int index = 0; index < numColumns; index++) { - BColumn *column = (BColumn*) fColumns->ItemAt(index); + BColumn* column = (BColumn*) fColumns->ItemAt(index); if (!column->IsVisible()) continue; if (leftEdge > position.x) break; - if (position.x >= leftEdge && position.x <= leftEdge + column->Width()) { - *out_leftEdge = leftEdge; + if (position.x >= leftEdge + && position.x <= leftEdge + column->Width()) { + *_leftEdge = leftEdge; return index; } @@ -1742,29 +1928,36 @@ int32 TitleView::FindColumn(BPoint position, float *out_leftEdge) return 0; } -void TitleView::FixScrollBar(bool scrollToFit) + +void +TitleView::FixScrollBar(bool scrollToFit) { - BScrollBar *hScrollBar = ScrollBar(B_HORIZONTAL); - if (hScrollBar) { - float virtualWidth = fColumnsWidth + MAX(kLeftMargin, fMasterView->LatchWidth()) + - kRightMargin * 2; + BScrollBar* hScrollBar = ScrollBar(B_HORIZONTAL); + if (hScrollBar == NULL) + return; - if (virtualWidth > fVisibleRect.Width()) { - hScrollBar->SetProportion(fVisibleRect.Width() / virtualWidth); + float virtualWidth = fColumnsWidth + MAX(kLeftMargin, + fMasterView->LatchWidth()) + kRightMargin * 2; - // Perform the little trick if the user is scrolled over too far. - // See OutlineView::FixScrollBar for a more in depth explanation - float maxScrollBarValue = virtualWidth - fVisibleRect.Width(); - if (scrollToFit || hScrollBar->Value() <= maxScrollBarValue) { - hScrollBar->SetRange(0.0, maxScrollBarValue); - hScrollBar->SetSteps(50, fVisibleRect.Width()); - } - } else if (hScrollBar->Value() == 0.0) - hScrollBar->SetRange(0.0, 0.0); // disable scroll bar. + if (virtualWidth > fVisibleRect.Width()) { + hScrollBar->SetProportion(fVisibleRect.Width() / virtualWidth); + + // Perform the little trick if the user is scrolled over too far. + // See OutlineView::FixScrollBar for a more in depth explanation + float maxScrollBarValue = virtualWidth - fVisibleRect.Width(); + if (scrollToFit || hScrollBar->Value() <= maxScrollBarValue) { + hScrollBar->SetRange(0.0, maxScrollBarValue); + hScrollBar->SetSteps(50, fVisibleRect.Width()); + } + } else if (hScrollBar->Value() == 0.0) { + // disable scroll bar. + hScrollBar->SetRange(0.0, 0.0); } } -void TitleView::DragSelectedColumn(BPoint position) + +void +TitleView::DragSelectedColumn(BPoint position) { float invalidLeft = fSelectedColumnRect.left; float invalidRight = fSelectedColumnRect.right; @@ -1790,7 +1983,9 @@ void TitleView::DragSelectedColumn(BPoint position) DrawTitle(this, fSelectedColumnRect, fSelectedColumn, true); } -void TitleView::MoveColumn(BColumn *column, int32 index) + +void +TitleView::MoveColumn(BColumn* column, int32 index) { fColumns->RemoveItem((void*) column); @@ -1802,13 +1997,16 @@ void TitleView::MoveColumn(BColumn *column, int32 index) } } -void TitleView::SetColumnFlags(column_flags flags) + +void +TitleView::SetColumnFlags(column_flags flags) { fColumnFlags = flags; } -void TitleView::ResizeSelectedColumn(BPoint position, bool preferred) +void +TitleView::ResizeSelectedColumn(BPoint position, bool preferred) { float minWidth = fSelectedColumn->MinWidth(); float maxWidth = fSelectedColumn->MaxWidth(); @@ -1829,7 +2027,8 @@ void TitleView::ResizeSelectedColumn(BPoint position, bool preferred) else fSelectedColumn->SetWidth(position.x - fSelectedColumnRect.left - 1); - float dX = fSelectedColumnRect.left + fSelectedColumn->Width() - originalEdge; + float dX = fSelectedColumnRect.left + fSelectedColumn->Width() + - originalEdge; if (dX != 0) { BRect originalRect(originalEdge, 0, 1000000.0, fVisibleRect.Height()); BRect movedRect(originalRect); @@ -1842,7 +2041,8 @@ void TitleView::ResizeSelectedColumn(BPoint position, bool preferred) #if DOUBLE_BUFFERED_COLUMN_RESIZE fDrawBuffer->Lock(); - fDrawBufferView->SetHighColor(fMasterView->Color(B_COLOR_HEADER_BACKGROUND)); + fDrawBufferView->SetHighColor( + fMasterView->Color(B_COLOR_HEADER_BACKGROUND)); fDrawBufferView->FillRect(sourceRect); DrawTitle(fDrawBufferView, sourceRect, fSelectedColumn, false); fDrawBufferView->Sync(); @@ -1879,7 +2079,9 @@ void TitleView::ResizeSelectedColumn(BPoint position, bool preferred) } } -void TitleView::ComputeDragBoundries(BColumn *findColumn, BPoint ) + +void +TitleView::ComputeDragBoundries(BColumn* findColumn, BPoint) { float previousColumnLeftEdge = -1000000.0; float nextColumnRightEdge = 1000000.0; @@ -1888,7 +2090,7 @@ void TitleView::ComputeDragBoundries(BColumn *findColumn, BPoint ) float leftEdge = MAX(kLeftMargin, fMasterView->LatchWidth()); int32 numColumns = fColumns->CountItems(); for (int index = 0; index < numColumns; index++) { - BColumn *column = (BColumn*) fColumns->ItemAt(index); + BColumn* column = (BColumn*) fColumns->ItemAt(index); if (!column->IsVisible()) continue; @@ -1908,14 +2110,19 @@ void TitleView::ComputeDragBoundries(BColumn *findColumn, BPoint ) float rightEdge = leftEdge + findColumn->Width(); - fLeftDragBoundry = MIN(previousColumnLeftEdge + findColumn->Width(), leftEdge); + fLeftDragBoundry = MIN(previousColumnLeftEdge + findColumn->Width(), + leftEdge); fRightDragBoundry = MAX(nextColumnRightEdge, rightEdge); } -void TitleView::DrawTitle(BView *view, BRect rect, BColumn *column, bool depressed) + +void +TitleView::DrawTitle(BView* view, BRect rect, BColumn* column, bool depressed) { BRect drawRect; - rgb_color borderColor = mix_color(fMasterView->Color(B_COLOR_HEADER_BACKGROUND), make_color(0, 0, 0), 128); + rgb_color borderColor = mix_color( + fMasterView->Color(B_COLOR_HEADER_BACKGROUND), + make_color(0, 0, 0), 128); rgb_color backgroundColor; rgb_color bevelHigh; @@ -1925,7 +2132,9 @@ void TitleView::DrawTitle(BView *view, BRect rect, BColumn *column, bool depress drawRect = rect; drawRect.InsetBy(2, 2); if (depressed) { - backgroundColor = mix_color(fMasterView->Color(B_COLOR_HEADER_BACKGROUND), make_color(0, 0, 0), 64); + backgroundColor = mix_color( + fMasterView->Color(B_COLOR_HEADER_BACKGROUND), + make_color(0, 0, 0), 64); bevelHigh = mix_color(backgroundColor, make_color(0, 0, 0), 64); bevelLow = mix_color(backgroundColor, make_color(255, 255, 255), 128); drawRect.left++; @@ -1941,17 +2150,21 @@ void TitleView::DrawTitle(BView *view, BRect rect, BColumn *column, bool depress view->SetHighColor(borderColor); view->StrokeRect(rect); view->BeginLineArray(4); - view->AddLine(BPoint(rect.left+1, rect.top+1), BPoint(rect.right-1, rect.top+1), bevelHigh); - view->AddLine(BPoint(rect.left+1, rect.top+1), BPoint(rect.left+1, rect.bottom-1), bevelHigh); - view->AddLine(BPoint(rect.right-1, rect.top+1), BPoint(rect.right-1, rect.bottom-1), bevelLow); - view->AddLine(BPoint(rect.left+2, rect.bottom-1), BPoint(rect.right-1, rect.bottom-1), bevelLow); + view->AddLine(BPoint(rect.left + 1, rect.top + 1), + BPoint(rect.right - 1, rect.top + 1), bevelHigh); + view->AddLine(BPoint(rect.left + 1, rect.top + 1), + BPoint(rect.left + 1, rect.bottom - 1), bevelHigh); + view->AddLine(BPoint(rect.right - 1, rect.top + 1), + BPoint(rect.right - 1, rect.bottom - 1), bevelLow); + view->AddLine(BPoint(rect.left + 2, rect.bottom-1), + BPoint(rect.right - 1, rect.bottom - 1), bevelLow); view->EndLineArray(); font_height fh; GetFontHeight(&fh); float baseline = floor(drawRect.top + fh.ascent - + (drawRect.Height()+1-(fh.ascent+fh.descent))/2); + + (drawRect.Height() + 1 - (fh.ascent+fh.descent)) / 2); view->SetHighColor(backgroundColor); view->SetLowColor(backgroundColor); @@ -1972,7 +2185,7 @@ void TitleView::DrawTitle(BView *view, BRect rect, BColumn *column, bool depress int sortIndex = fSortColumns->IndexOf(column); if (sortIndex >= 0) { // Draw sort notation. - BPoint upperLeft(drawRect.right-kSortIndicatorWidth, baseline); + BPoint upperLeft(drawRect.right - kSortIndicatorWidth, baseline); if (fSortColumns->CountItems() > 1) { char str[256]; @@ -1981,7 +2194,8 @@ void TitleView::DrawTitle(BView *view, BRect rect, BColumn *column, bool depress upperLeft.x -= w; view->SetDrawingMode(B_OP_COPY); - view->MovePenTo(BPoint(upperLeft.x + kSortIndicatorWidth, baseline)); + view->MovePenTo(BPoint(upperLeft.x + kSortIndicatorWidth, + baseline)); view->DrawString(str); } @@ -1990,15 +2204,18 @@ void TitleView::DrawTitle(BView *view, BRect rect, BColumn *column, bool depress view->SetDrawingMode(B_OP_OVER); if (column->fSortAscending) { - BPoint leftTop(upperLeft.x, drawRect.top + (drawRect.IntegerHeight()-fDownSortArrow->Bounds().IntegerHeight())/2); + BPoint leftTop(upperLeft.x, drawRect.top + (drawRect.IntegerHeight() + - fDownSortArrow->Bounds().IntegerHeight()) / 2); view->DrawBitmapAsync(fDownSortArrow, leftTop); } else { - BPoint leftTop(upperLeft.x, drawRect.top + (drawRect.IntegerHeight()-fUpSortArrow->Bounds().IntegerHeight())/2); + BPoint leftTop(upperLeft.x, drawRect.top + (drawRect.IntegerHeight() + - fUpSortArrow->Bounds().IntegerHeight()) / 2); view->DrawBitmapAsync(fUpSortArrow, leftTop); } - upperLeft.y = baseline-bmh+floor((fh.ascent+fh.descent-bmh)/2); - if (upperLeft.y < drawRect.top) upperLeft.y = drawRect.top; + upperLeft.y = baseline - bmh + floor((fh.ascent + fh.descent - bmh) / 2); + if (upperLeft.y < drawRect.top) + upperLeft.y = drawRect.top; // Adjust title stuff for sort indicator drawRect.right = upperLeft.x - 2; @@ -2011,7 +2228,7 @@ void TitleView::DrawTitle(BView *view, BRect rect, BColumn *column, bool depress view->ConstrainClippingRegion(&clipRegion); view->PushState(); #endif - view->MovePenTo(BPoint(drawRect.left+8, baseline)); + view->MovePenTo(BPoint(drawRect.left + 8, baseline)); view->SetDrawingMode(B_OP_COPY); view->SetHighColor(fMasterView->Color(B_COLOR_HEADER_TEXT)); column->DrawTitle(drawRect, view); @@ -2023,11 +2240,15 @@ void TitleView::DrawTitle(BView *view, BRect rect, BColumn *column, bool depress } } -void TitleView::Draw(BRect invalidRect) + +void +TitleView::Draw(BRect invalidRect) { float columnLeftEdge = MAX(kLeftMargin, fMasterView->LatchWidth()); - for (int32 columnIndex = 0; columnIndex < fColumns->CountItems(); columnIndex++) { - BColumn *column = (BColumn*) fColumns->ItemAt(columnIndex); + for (int32 columnIndex = 0; columnIndex < fColumns->CountItems(); + columnIndex++) { + + BColumn* column = (BColumn*) fColumns->ItemAt(columnIndex); if (!column->IsVisible()) continue; @@ -2036,9 +2257,10 @@ void TitleView::Draw(BRect invalidRect) if (columnLeftEdge + column->Width() >= invalidRect.left) { BRect titleRect(columnLeftEdge, 0, - columnLeftEdge + column->Width(), fVisibleRect.Height()); + columnLeftEdge + column->Width(), fVisibleRect.Height()); DrawTitle(this, titleRect, column, - (fCurrentState == DRAG_COLUMN_INSIDE_TITLE && fSelectedColumn == column)); + (fCurrentState == DRAG_COLUMN_INSIDE_TITLE + && fSelectedColumn == column)); } columnLeftEdge += column->Width() + 1; @@ -2047,13 +2269,15 @@ void TitleView::Draw(BRect invalidRect) // Bevels for right title margin if (columnLeftEdge <= invalidRect.right) { - BRect titleRect(columnLeftEdge, 0, Bounds().right+2, fVisibleRect.Height()); + BRect titleRect(columnLeftEdge, 0, Bounds().right + 2, + fVisibleRect.Height()); DrawTitle(this, titleRect, NULL, false); } // Bevels for left title margin if (invalidRect.left < MAX(kLeftMargin, fMasterView->LatchWidth())) { - BRect titleRect(0, 0, MAX(kLeftMargin, fMasterView->LatchWidth()) - 1, fVisibleRect.Height()); + BRect titleRect(0, 0, MAX(kLeftMargin, fMasterView->LatchWidth()) - 1, + fVisibleRect.Height()); DrawTitle(this, titleRect, NULL, false); } @@ -2070,16 +2294,18 @@ void TitleView::Draw(BRect invalidRect) #endif } -void TitleView::ScrollTo(BPoint position) + +void +TitleView::ScrollTo(BPoint position) { fOutlineView->ScrollBy(position.x - fVisibleRect.left, 0); fVisibleRect.OffsetTo(position.x, position.y); // Perform the little trick if the user is scrolled over too far. // See OutlineView::ScrollTo for a more in depth explanation - float maxScrollBarValue = fColumnsWidth + MAX(kLeftMargin, fMasterView->LatchWidth()) + - kRightMargin * 2 - fVisibleRect.Width(); - BScrollBar *hScrollBar = ScrollBar(B_HORIZONTAL); + float maxScrollBarValue = fColumnsWidth + MAX(kLeftMargin, + fMasterView->LatchWidth()) + kRightMargin * 2 - fVisibleRect.Width(); + BScrollBar* hScrollBar = ScrollBar(B_HORIZONTAL); float min, max; hScrollBar->GetRange(&min, &max); if (max != maxScrollBarValue && position.x > maxScrollBarValue) @@ -2088,17 +2314,19 @@ void TitleView::ScrollTo(BPoint position) _inherited::ScrollTo(position); } -void TitleView::MessageReceived(BMessage *message) + +void +TitleView::MessageReceived(BMessage* message) { if (message->what == kToggleColumn) { int32 num; if (message->FindInt32("be:field_num", &num) == B_OK) { for (int index = 0; index < fColumns->CountItems(); index++) { - BColumn *column = (BColumn*) fColumns->ItemAt(index); - if (!column) continue; - if (column->LogicalFieldNum() == num) { + BColumn* column = (BColumn*) fColumns->ItemAt(index); + if (!column) + continue; + if (column->LogicalFieldNum() == num) column->SetVisible(!column->IsVisible()); - } } } return; @@ -2107,20 +2335,23 @@ void TitleView::MessageReceived(BMessage *message) } } -void TitleView::MouseDown(BPoint position) + +void +TitleView::MouseDown(BPoint position) { if(fEditMode) return; - int32 buttons=1; + int32 buttons = 1; Window()->CurrentMessage()->FindInt32("buttons", &buttons); - if (buttons == B_SECONDARY_MOUSE_BUTTON && (fColumnFlags & B_ALLOW_COLUMN_POPUP)) { + if (buttons == B_SECONDARY_MOUSE_BUTTON + && (fColumnFlags & B_ALLOW_COLUMN_POPUP)) { // Right mouse button -- bring up menu to show/hide columns. if (!fColumnPop) fColumnPop = new BPopUpMenu("Columns", false, false); fColumnPop->RemoveItems(0, fColumnPop->CountItems(), true); BMessenger me(this); for (int index = 0; index < fColumns->CountItems(); index++) { - BColumn *column = (BColumn*) fColumns->ItemAt(index); + BColumn* column = (BColumn*) fColumns->ItemAt(index); if (!column) continue; BString name; column->GetColumnName(&name); @@ -2141,7 +2372,7 @@ void TitleView::MouseDown(BPoint position) fResizingFirstColumn = true; float leftEdge = MAX(kLeftMargin, fMasterView->LatchWidth()); for (int index = 0; index < fColumns->CountItems(); index++) { - BColumn *column = (BColumn*) fColumns->ItemAt(index); + BColumn* column = (BColumn*) fColumns->ItemAt(index); if (!column->IsVisible()) continue; @@ -2151,11 +2382,12 @@ void TitleView::MouseDown(BPoint position) // Check for resizing a column float rightEdge = leftEdge + column->Width(); - if(column->ShowHeading()) { + if (column->ShowHeading()) { if (position.x > rightEdge - kColumnResizeAreaWidth / 2 && position.x < rightEdge + kColumnResizeAreaWidth / 2 && column->MaxWidth() > column->MinWidth() && (fColumnFlags & B_ALLOW_COLUMN_RESIZE)) { + int32 clicks = 0; Window()->CurrentMessage()->FindInt32("clicks", &clicks); if (clicks == 2) { @@ -2165,9 +2397,10 @@ void TitleView::MouseDown(BPoint position) } fCurrentState = RESIZING_COLUMN; fSelectedColumn = column; - fSelectedColumnRect.Set(leftEdge, 0, rightEdge, fVisibleRect.Height()); - SetMouseEventMask(B_POINTER_EVENTS, B_LOCK_WINDOW_FOCUS | - B_NO_POINTER_HISTORY); + fSelectedColumnRect.Set(leftEdge, 0, rightEdge, + fVisibleRect.Height()); + SetMouseEventMask(B_POINTER_EVENTS, + B_LOCK_WINDOW_FOCUS | B_NO_POINTER_HISTORY); break; } @@ -2177,12 +2410,13 @@ void TitleView::MouseDown(BPoint position) if (position.x > leftEdge && position.x < rightEdge) { fCurrentState = PRESSING_COLUMN; fSelectedColumn = column; - fSelectedColumnRect.Set(leftEdge, 0, rightEdge, fVisibleRect.Height()); + fSelectedColumnRect.Set(leftEdge, 0, rightEdge, + fVisibleRect.Height()); DrawTitle(this, fSelectedColumnRect, fSelectedColumn, true); - fClickPoint = BPoint(position.x - fSelectedColumnRect.left, position.y - - fSelectedColumnRect.top); - SetMouseEventMask(B_POINTER_EVENTS, B_LOCK_WINDOW_FOCUS | - B_NO_POINTER_HISTORY); + fClickPoint = BPoint(position.x - fSelectedColumnRect.left, + position.y - fSelectedColumnRect.top); + SetMouseEventMask(B_POINTER_EVENTS, + B_LOCK_WINDOW_FOCUS | B_NO_POINTER_HISTORY); break; } } @@ -2190,14 +2424,14 @@ void TitleView::MouseDown(BPoint position) } } -void TitleView::MouseMoved(BPoint position, uint32 transit, const BMessage *) -{ - - if(fEditMode) +void +TitleView::MouseMoved(BPoint position, uint32 transit, + const BMessage* dragMessage) +{ + if (fEditMode) return; - - + // Handle column manipulation switch (fCurrentState) { case RESIZING_COLUMN: @@ -2205,8 +2439,10 @@ void TitleView::MouseMoved(BPoint position, uint32 transit, const BMessage *) break; case PRESSING_COLUMN: { - if (abs((int32)(position.x - (fClickPoint.x + fSelectedColumnRect.left))) > kColumnResizeAreaWidth - || abs((int32)(position.y - (fClickPoint.y + fSelectedColumnRect.top))) > kColumnResizeAreaWidth) { + if (abs((int32)(position.x - (fClickPoint.x + + fSelectedColumnRect.left))) > kColumnResizeAreaWidth + || abs((int32)(position.y - (fClickPoint.y + + fSelectedColumnRect.top))) > kColumnResizeAreaWidth) { // User has moved the mouse more than the tolerable amount, // initiate a drag. if (transit == B_INSIDE_VIEW || transit == B_ENTERED_VIEW) { @@ -2228,17 +2464,20 @@ void TitleView::MouseMoved(BPoint position, uint32 transit, const BMessage *) fSelectedColumn->SetVisible(false); BRect dragRect(fSelectedColumnRect); - // There is a race condition where the mouse may have moved by the - // time we get to handle this message. If the user drags a column very - // quickly, this results in the annoying bug where the cursor is outside - // of the rectangle that is being dragged around. - // Call GetMouse with the checkQueue flag set to false so we - // can get the most recent position of the mouse. This minimizes - // this problem (although it is currently not possible to completely - // eliminate it). + // There is a race condition where the mouse may have + // moved by the time we get to handle this message. + // If the user drags a column very quickly, this + // results in the annoying bug where the cursor is + // outside of the rectangle that is being dragged + // around. Call GetMouse with the checkQueue flag set + // to false so we can get the most recent position of + // the mouse. This minimizes this problem (although + // it is currently not possible to completely eliminate + // it). uint32 buttons; GetMouse(&position, &buttons, false); - dragRect.OffsetTo(position.x - fClickPoint.x, position.y - dragRect.Height() / 2); + dragRect.OffsetTo(position.x - fClickPoint.x, + position.y - dragRect.Height() / 2); BeginRectTracking(dragRect, B_TRACK_WHOLE_RECT); } } @@ -2248,7 +2487,8 @@ void TitleView::MouseMoved(BPoint position, uint32 transit, const BMessage *) } case DRAG_COLUMN_INSIDE_TITLE: { - if (transit == B_EXITED_VIEW && (fColumnFlags & B_ALLOW_COLUMN_REMOVE)) { + if (transit == B_EXITED_VIEW + && (fColumnFlags & B_ALLOW_COLUMN_REMOVE)) { // Dragged outside view fCurrentState = DRAG_COLUMN_OUTSIDE_TITLE; fSelectedColumn->SetVisible(false); @@ -2258,14 +2498,17 @@ void TitleView::MouseMoved(BPoint position, uint32 transit, const BMessage *) uint32 buttons; GetMouse(&position, &buttons, false); - dragRect.OffsetTo(position.x - fClickPoint.x, position.y - fClickPoint.y); + dragRect.OffsetTo(position.x - fClickPoint.x, + position.y - fClickPoint.y); BeginRectTracking(dragRect, B_TRACK_WHOLE_RECT); - } else if (position.x < fLeftDragBoundry || position.x > fRightDragBoundry) + } else if (position.x < fLeftDragBoundry + || position.x > fRightDragBoundry) { DragSelectedColumn(position); + } #if DRAG_TITLE_OUTLINE - // Set up the invalid rect to include the rect for the previous position - // of the drag rect, as well as the new one. + // Set up the invalid rect to include the rect for the previous + // position of the drag rect, as well as the new one. BRect invalidRect(fSelectedColumnRect); invalidRect.OffsetTo(fCurrentDragPosition.x - fClickPoint.x, 0); if (position.x < fCurrentDragPosition.x) @@ -2293,10 +2536,10 @@ void TitleView::MouseMoved(BPoint position, uint32 transit, const BMessage *) case INACTIVE: // Check for cursor changes if we are over the resize area for // a column. - BColumn *resizeColumn = 0; + BColumn* resizeColumn = 0; float leftEdge = MAX(kLeftMargin, fMasterView->LatchWidth()); for (int index = 0; index < fColumns->CountItems(); index++) { - BColumn *column = (BColumn*) fColumns->ItemAt(index); + BColumn* column = (BColumn*) fColumns->ItemAt(index); if (!column->IsVisible()) continue; @@ -2328,9 +2571,11 @@ void TitleView::MouseMoved(BPoint position, uint32 transit, const BMessage *) } } -void TitleView::MouseUp(BPoint position) + +void +TitleView::MouseUp(BPoint position) { - if(fEditMode) + if (fEditMode) return; switch (fCurrentState) { @@ -2344,12 +2589,14 @@ void TitleView::MouseUp(BPoint position) case PRESSING_COLUMN: { if (fMasterView->SortingEnabled()) { if (fSortColumns->HasItem(fSelectedColumn)) { - if ((modifiers() & B_CONTROL_KEY) == 0 && fSortColumns->CountItems() > 1) { + if ((modifiers() & B_CONTROL_KEY) == 0 + && fSortColumns->CountItems() > 1) { fSortColumns->MakeEmpty(); fSortColumns->AddItem(fSelectedColumn); } - fSelectedColumn->fSortAscending = !fSelectedColumn->fSortAscending; + fSelectedColumn->fSortAscending + = !fSelectedColumn->fSortAscending; } else { if ((modifiers() & B_CONTROL_KEY) == 0) fSortColumns->MakeEmpty(); @@ -2388,46 +2635,52 @@ void TitleView::MouseUp(BPoint position) } } -void TitleView::FrameResized(float width, float height) + +void +TitleView::FrameResized(float width, float height) { fVisibleRect.right = fVisibleRect.left + width; fVisibleRect.bottom = fVisibleRect.top + height; FixScrollBar(true); } + // #pragma mark - -OutlineView::OutlineView(BRect rect, BList *visibleColumns, BList *sortColumns, - BColumnListView *listView) - : BView(rect, "outline_view", B_FOLLOW_ALL_SIDES, B_WILL_DRAW | B_FRAME_EVENTS), - fColumns(visibleColumns), - fSortColumns(sortColumns), - fItemsHeight(0.0), - fVisibleRect(rect.OffsetToCopy(0, 0)), - fFocusRow(0), - fRollOverRow(0), - fLastSelectedItem(0), - fFirstSelectedItem(0), - fSortThread(B_BAD_THREAD_ID), - fCurrentState(INACTIVE), - fMasterView(listView), - fSelectionMode(B_MULTIPLE_SELECTION_LIST), - fTrackMouse(false), - fCurrentField(0), - fCurrentRow(0), - fCurrentColumn(0), - fMouseDown(false), - fCurrentCode(B_OUTSIDE_VIEW), - fEditMode(false), - fDragging(false), - fClickCount(0), - fDropHighlightY(-1) + +OutlineView::OutlineView(BRect rect, BList* visibleColumns, BList* sortColumns, + BColumnListView* listView) + : + BView(rect, "outline_view", B_FOLLOW_ALL_SIDES, + B_WILL_DRAW | B_FRAME_EVENTS), + fColumns(visibleColumns), + fSortColumns(sortColumns), + fItemsHeight(0.0), + fVisibleRect(rect.OffsetToCopy(0, 0)), + fFocusRow(0), + fRollOverRow(0), + fLastSelectedItem(0), + fFirstSelectedItem(0), + fSortThread(B_BAD_THREAD_ID), + fCurrentState(INACTIVE), + fMasterView(listView), + fSelectionMode(B_MULTIPLE_SELECTION_LIST), + fTrackMouse(false), + fCurrentField(0), + fCurrentRow(0), + fCurrentColumn(0), + fMouseDown(false), + fCurrentCode(B_OUTSIDE_VIEW), + fEditMode(false), + fDragging(false), + fClickCount(0), + fDropHighlightY(-1) { - SetViewColor(B_TRANSPARENT_32_BIT); + SetViewColor(B_TRANSPARENT_COLOR); #if DOUBLE_BUFFERED_COLUMN_RESIZE - // xxx this needs to be smart about the size of the buffer. Also, the buffer can - // be shared with the title's buffer. + // TODO: This needs to be smart about the size of the buffer. + // Also, the buffer can be shared with the title's buffer. BRect doubleBufferRect(0, 0, 600, 35); fDrawBuffer = new BBitmap(doubleBufferRect, B_RGB32, true); fDrawBufferView = new BView(doubleBufferRect, "double_buffer_view", @@ -2442,6 +2695,7 @@ OutlineView::OutlineView(BRect rect, BList *visibleColumns, BList *sortColumns, fSelectionListDummyHead.fPrevSelected = &fSelectionListDummyHead; } + OutlineView::~OutlineView() { fDrawBuffer->Lock(); @@ -2453,79 +2707,96 @@ OutlineView::~OutlineView() Clear(); } -void OutlineView::Clear() + +void +OutlineView::Clear() { - DeselectAll(); // Make sure selection list doesn't point to deleted rows! + DeselectAll(); + // Make sure selection list doesn't point to deleted rows! RecursiveDeleteRows(&fRows, false); Invalidate(); fItemsHeight = 0.0; FixScrollBar(true); } -void OutlineView::SetSelectionMode(list_view_type mode) + +void +OutlineView::SetSelectionMode(list_view_type mode) { DeselectAll(); fSelectionMode = mode; } -list_view_type OutlineView::SelectionMode() const + +list_view_type +OutlineView::SelectionMode() const { return fSelectionMode; } -void OutlineView::Deselect(BRow *row) + +void +OutlineView::Deselect(BRow* row) { - if (row) { - if (row->fNextSelected != 0) { - row->fNextSelected->fPrevSelected = row->fPrevSelected; - row->fPrevSelected->fNextSelected = row->fNextSelected; - row->fNextSelected = 0; - row->fPrevSelected = 0; - Invalidate(); - } + if (row == NULL) + return; + + if (row->fNextSelected != 0) { + row->fNextSelected->fPrevSelected = row->fPrevSelected; + row->fPrevSelected->fNextSelected = row->fNextSelected; + row->fNextSelected = 0; + row->fPrevSelected = 0; + Invalidate(); } } -void OutlineView::AddToSelection(BRow *row) + +void +OutlineView::AddToSelection(BRow* row) { - if (row) { - if (row->fNextSelected == 0) { - if (fSelectionMode == B_SINGLE_SELECTION_LIST) - DeselectAll(); + if (row == NULL) + return; + + if (row->fNextSelected == 0) { + if (fSelectionMode == B_SINGLE_SELECTION_LIST) + DeselectAll(); + + row->fNextSelected = fSelectionListDummyHead.fNextSelected; + row->fPrevSelected = &fSelectionListDummyHead; + row->fNextSelected->fPrevSelected = row; + row->fPrevSelected->fNextSelected = row; + + BRect invalidRect; + if (FindVisibleRect(row, &invalidRect)) + Invalidate(invalidRect); + } +} + + +void +OutlineView::RecursiveDeleteRows(BRowContainer* list, bool isOwner) +{ + if (list == NULL) + return; + + while (true) { + BRow* row = list->RemoveItemAt(0L); + if (row == 0) + break; - row->fNextSelected = fSelectionListDummyHead.fNextSelected; - row->fPrevSelected = &fSelectionListDummyHead; - row->fNextSelected->fPrevSelected = row; - row->fPrevSelected->fNextSelected = row; - - BRect invalidRect; - if (FindVisibleRect(row, &invalidRect)) - Invalidate(invalidRect); - } - } -} + if (row->fChildList) + RecursiveDeleteRows(row->fChildList, true); -void OutlineView::RecursiveDeleteRows(BRowContainer* List, bool IsOwner) -{ - if (List) { - while (true) { - BRow *row = List->RemoveItemAt(0L); - if (row == 0) - break; - - if (row->fChildList) - RecursiveDeleteRows(row->fChildList, true); - - delete row; - } - - if (IsOwner) - delete List; + delete row; } + + if (isOwner) + delete list; } -void OutlineView::RedrawColumn(BColumn *column, float leftEdge, bool isFirstColumn) +void +OutlineView::RedrawColumn(BColumn* column, float leftEdge, bool isFirstColumn) { // TODO: Remove code duplication (private function which takes a view // pointer, pass "this" in non-double buffered mode)! @@ -2539,7 +2810,8 @@ void OutlineView::RedrawColumn(BColumn *column, float leftEdge, bool isFirstColu bool tintedLine = true; for (RecursiveOutlineIterator iterator(&fRows); iterator.CurrentRow(); line += iterator.CurrentRow()->Height() + 1, iterator.GoToNext()) { - BRow *row = iterator.CurrentRow(); + + BRow* row = iterator.CurrentRow(); float rowHeight = row->Height(); if (line > fVisibleRect.bottom) break; @@ -2547,7 +2819,8 @@ void OutlineView::RedrawColumn(BColumn *column, float leftEdge, bool isFirstColu if (line + rowHeight >= fVisibleRect.top) { 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); rgb_color highColor; rgb_color lowColor; @@ -2579,7 +2852,8 @@ void OutlineView::RedrawColumn(BColumn *column, float leftEdge, bool isFirstColu fDrawBufferView->FillRect(sourceRect, B_SOLID_LOW); 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. destRect.left += iterator.CurrentLevel() * kOutlineLevelIndent - fMasterView->LatchWidth(); sourceRect.left += iterator.CurrentLevel() * kOutlineLevelIndent @@ -2594,7 +2868,7 @@ void OutlineView::RedrawColumn(BColumn *column, float leftEdge, bool isFirstColu fMasterView->DrawLatch(fDrawBufferView, latchRect, pos, row); } - BField *field = row->GetField(column->fFieldID); + BField* field = row->GetField(column->fFieldID); if (field) { BRect fieldRect(sourceRect); if (isFirstColumn) @@ -2606,9 +2880,11 @@ void OutlineView::RedrawColumn(BColumn *column, float leftEdge, bool isFirstColu fDrawBufferView->ConstrainClippingRegion(&clipRegion); fDrawBufferView->PushState(); #endif - fDrawBufferView->SetHighColor(fMasterView->Color(row->fNextSelected ? B_COLOR_SELECTION_TEXT : B_COLOR_TEXT)); + fDrawBufferView->SetHighColor(fMasterView->Color( + row->fNextSelected ? B_COLOR_SELECTION_TEXT + : B_COLOR_TEXT)); float baseline = floor(fieldRect.top + fh.ascent - + (fieldRect.Height()+1-(fh.ascent+fh.descent))/2); + + (fieldRect.Height() + 1 - (fh.ascent+fh.descent)) / 2); fDrawBufferView->MovePenTo(fieldRect.left + 8, baseline); column->DrawField(field, fieldRect, fDrawBufferView); #if CONSTRAIN_CLIPPING_REGION @@ -2619,8 +2895,10 @@ void OutlineView::RedrawColumn(BColumn *column, float leftEdge, bool isFirstColu if (fFocusRow == row && !fEditMode && fMasterView->IsFocus() && Window()->IsActive()) { - fDrawBufferView->SetHighColor(fMasterView->Color(B_COLOR_ROW_DIVIDER)); - fDrawBufferView->StrokeRect(BRect(-1, sourceRect.top, 10000.0, sourceRect.bottom)); + fDrawBufferView->SetHighColor(fMasterView->Color( + B_COLOR_ROW_DIVIDER)); + fDrawBufferView->StrokeRect(BRect(-1, sourceRect.top, + 10000.0, sourceRect.bottom)); } fDrawBufferView->Sync(); @@ -2634,7 +2912,7 @@ void OutlineView::RedrawColumn(BColumn *column, float leftEdge, bool isFirstColu SetLowColor(lowColor); FillRect(destRect, B_SOLID_LOW); - BField *field = row->GetField(column->fFieldID); + BField* field = row->GetField(column->fFieldID); if (field) { #if CONSTRAIN_CLIPPING_REGION BRegion clipRegion; @@ -2642,9 +2920,10 @@ void OutlineView::RedrawColumn(BColumn *column, float leftEdge, bool isFirstColu ConstrainClippingRegion(&clipRegion); PushState(); #endif - SetHighColor(fColorList[row->fNextSelected ? B_COLOR_SELECTION_TEXT : B_COLOR_TEXT]); + SetHighColor(fColorList[row->fNextSelected + ? B_COLOR_SELECTION_TEXT : B_COLOR_TEXT]); float baseline = floor(destRect.top + fh.ascent - + (destRect.Height()+1-(fh.ascent+fh.descent))/2); + + (destRect.Height() + 1 - (fh.ascent + fh.descent)) / 2); MovePenTo(destRect.left + 8, baseline); column->DrawField(field, destRect, this); #if CONSTRAIN_CLIPPING_REGION @@ -2663,7 +2942,9 @@ void OutlineView::RedrawColumn(BColumn *column, float leftEdge, bool isFirstColu } } -void OutlineView::Draw(BRect invalidBounds) + +void +OutlineView::Draw(BRect invalidBounds) { #if SMART_REDRAW BRegion invalidRegion; @@ -2678,7 +2959,7 @@ void OutlineView::Draw(BRect invalidBounds) int32 numColumns = fColumns->CountItems(); for (RecursiveOutlineIterator iterator(&fRows); iterator.CurrentRow(); iterator.GoToNext()) { - BRow *row = iterator.CurrentRow(); + BRow* row = iterator.CurrentRow(); if (line > invalidBounds.bottom) break; @@ -2706,7 +2987,7 @@ void OutlineView::Draw(BRect invalidBounds) lowColor = tint_color(lowColor, kTintedLineTint); for (int columnIndex = 0; columnIndex < numColumns; columnIndex++) { - BColumn *column = (BColumn*) fColumns->ItemAt(columnIndex); + BColumn* column = (BColumn*) fColumns->ItemAt(columnIndex); if (!column->IsVisible()) continue; @@ -2726,50 +3007,57 @@ void OutlineView::Draw(BRect invalidBounds) BRect destRect(fullRect); if (isFirstColumn) { fullRect.left -= fMasterView->LatchWidth(); - destRect.left += iterator.CurrentLevel() * kOutlineLevelIndent; + destRect.left += iterator.CurrentLevel() + * kOutlineLevelIndent; if (destRect.left >= destRect.right) { // clipped - FillRect(BRect(0, line, fieldLeftEdge + column->Width(), - line + rowHeight)); + FillRect(BRect(0, line, fieldLeftEdge + + column->Width(), line + rowHeight)); clippedFirstColumn = true; } - FillRect(BRect(0, line, MAX(kLeftMargin, fMasterView->LatchWidth()), line + row->Height())); + FillRect(BRect(0, line, MAX(kLeftMargin, + fMasterView->LatchWidth()), line + row->Height())); } #if SMART_REDRAW - if (!clippedFirstColumn && invalidRegion.Intersects(fullRect)) + if (!clippedFirstColumn + && invalidRegion.Intersects(fullRect)) { #else - if (!clippedFirstColumn) + if (!clippedFirstColumn) { #endif - { FillRect(fullRect); // Using color set above // Draw the latch widget if it has one. if (isFirstColumn) { - if (row == fTargetRow && fCurrentState == LATCH_CLICKED) { - // Note that this only occurs if the user is holding - // down a latch while items are added in the background. + if (row == fTargetRow + && fCurrentState == LATCH_CLICKED) { + // Note that this only occurs if the user is + // holding down a latch while items are added + // in the background. BPoint pos; uint32 buttons; GetMouse(&pos, &buttons); - if (fLatchRect.Contains(pos)) - fMasterView->DrawLatch(this, fLatchRect, B_PRESSED_LATCH, - fTargetRow); - else + if (fLatchRect.Contains(pos)) { fMasterView->DrawLatch(this, fLatchRect, - row->fIsExpanded ? B_OPEN_LATCH : B_CLOSED_LATCH, - fTargetRow); + B_PRESSED_LATCH, fTargetRow); + } else { + fMasterView->DrawLatch(this, fLatchRect, + row->fIsExpanded ? B_OPEN_LATCH + : B_CLOSED_LATCH, fTargetRow); + } } else { LatchType pos = B_NO_LATCH; if (row->HasLatch()) - pos = row->fIsExpanded ? B_OPEN_LATCH : B_CLOSED_LATCH; + pos = row->fIsExpanded ? B_OPEN_LATCH + : B_CLOSED_LATCH; - fMasterView->DrawLatch(this, BRect(destRect.left - - fMasterView->LatchWidth(), - destRect.top, destRect.left, destRect.bottom), pos, - row); + fMasterView->DrawLatch(this, + BRect(destRect.left + - fMasterView->LatchWidth(), + destRect.top, destRect.left, + destRect.bottom), pos, row); } } @@ -2777,7 +3065,7 @@ void OutlineView::Draw(BRect invalidBounds) // 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 CONSTRAIN_CLIPPING_REGION BRegion clipRegion; @@ -2785,9 +3073,12 @@ void OutlineView::Draw(BRect invalidBounds) ConstrainClippingRegion(&clipRegion); PushState(); #endif - SetHighColor(fMasterView->Color(row->fNextSelected ? B_COLOR_SELECTION_TEXT : B_COLOR_TEXT)); + SetHighColor(fMasterView->Color( + row->fNextSelected ? B_COLOR_SELECTION_TEXT + : B_COLOR_TEXT)); float baseline = floor(destRect.top + fh.ascent - + (destRect.Height()+1-(fh.ascent+fh.descent))/2); + + (destRect.Height() + 1 + - (fh.ascent+fh.descent)) / 2); MovePenTo(destRect.left + 8, baseline); column->DrawField(field, destRect, this); #if CONSTRAIN_CLIPPING_REGION @@ -2801,7 +3092,7 @@ void OutlineView::Draw(BRect invalidBounds) isFirstColumn = false; fieldLeftEdge += column->Width() + 1; } - + if (fieldLeftEdge <= invalidBounds.right) { SetHighColor(lowColor); FillRect(BRect(fieldLeftEdge, line, invalidBounds.right, @@ -2810,7 +3101,8 @@ void OutlineView::Draw(BRect invalidBounds) } // indicate the keyboard focus row - if (fFocusRow == row && !fEditMode && fMasterView->IsFocus() && Window()->IsActive()) { + if (fFocusRow == row && !fEditMode && fMasterView->IsFocus() + && Window()->IsActive()) { SetHighColor(fMasterView->Color(B_COLOR_ROW_DIVIDER)); StrokeRect(BRect(0, line, 10000.0, line + rowHeight)); } @@ -2821,44 +3113,50 @@ void OutlineView::Draw(BRect invalidBounds) if (line <= invalidBounds.bottom) { // fill background below last item SetHighColor(fMasterView->Color(B_COLOR_BACKGROUND)); - FillRect(BRect(invalidBounds.left, line, invalidBounds.right, invalidBounds.bottom)); + FillRect(BRect(invalidBounds.left, line, invalidBounds.right, + invalidBounds.bottom)); } // Draw the drop target line - if (fDropHighlightY != -1) - InvertRect(BRect(0, fDropHighlightY - kDropHighlightLineHeight / 2, 1000000, - fDropHighlightY + kDropHighlightLineHeight / 2)); + if (fDropHighlightY != -1) { + InvertRect(BRect(0, fDropHighlightY - kDropHighlightLineHeight / 2, + 1000000, fDropHighlightY + kDropHighlightLineHeight / 2)); + } } -BRow* OutlineView::FindRow(float ypos, int32 *out_rowIndent, float *out_top) + +BRow* +OutlineView::FindRow(float ypos, int32* _rowIndent, float* _top) { - if (out_rowIndent && out_top) { + if (_rowIndent && _top) { float line = 0.0; for (RecursiveOutlineIterator iterator(&fRows); iterator.CurrentRow(); iterator.GoToNext()) { - BRow *row = iterator.CurrentRow(); + + BRow* row = iterator.CurrentRow(); if (line > ypos) break; float rowHeight = row->Height(); if (ypos <= line + rowHeight) { - *out_top = line; - *out_rowIndent = iterator.CurrentLevel(); + *_top = line; + *_rowIndent = iterator.CurrentLevel(); return row; } line += rowHeight + 1; } } - return 0; + return NULL; } void OutlineView::SetMouseTrackingEnabled(bool enabled) { fTrackMouse = enabled; if (!enabled && fDropHighlightY != -1) { - InvertRect(BRect(0, fDropHighlightY - kDropHighlightLineHeight / 2, 1000000, - fDropHighlightY + kDropHighlightLineHeight / 2)); // Erase the old target line + // Erase the old target line + InvertRect(BRect(0, fDropHighlightY - kDropHighlightLineHeight / 2, + 1000000, fDropHighlightY + kDropHighlightLineHeight / 2)); fDropHighlightY = -1; } } @@ -2870,9 +3168,10 @@ void OutlineView::SetMouseTrackingEnabled(bool enabled) // resulting in drawing glitches. The code that adds items needs to be a little smarter // about invalidating state. // -void OutlineView::MouseDown(BPoint position) +void +OutlineView::MouseDown(BPoint position) { - if(!fEditMode) + if (!fEditMode) fMasterView->MakeFocus(true); // Check to see if the user is clicking on a widget to open a section @@ -2880,30 +3179,33 @@ void OutlineView::MouseDown(BPoint position) bool reset_click_count = false; int32 indent; float rowTop; - BRow *row = FindRow(position.y, &indent, &rowTop); - if (row) { + BRow* row = FindRow(position.y, &indent, &rowTop); + if (row != NULL) { // Update fCurrentField bool handle_field = false; - BField *new_field = 0; - BRow *new_row = 0; - BColumn *new_column = 0; + BField* new_field = 0; + BRow* new_row = 0; + BColumn* new_column = 0; BRect new_rect; - if(position.y >=0 ) { - if(position.x >=0 ) { - float x=0; - for(int32 c=0;cCountColumns();c++) { + if (position.y >= 0) { + if (position.x >= 0) { + float x = 0; + for (int32 c = 0; c < fMasterView->CountColumns(); c++) { new_column = fMasterView->ColumnAt(c); if (!new_column->IsVisible()) continue; - if((MAX(kLeftMargin, fMasterView->LatchWidth())+x)+new_column->Width() >= position.x) { - if(new_column->WantsEvents()) { + if ((MAX(kLeftMargin, fMasterView->LatchWidth()) + x) + + new_column->Width() >= position.x) { + if (new_column->WantsEvents()) { new_field = row->GetField(c); new_row = row; FindRect(new_row,&new_rect); - new_rect.left = MAX(kLeftMargin, fMasterView->LatchWidth()) + x; - new_rect.right = new_rect.left + new_column->Width() - 1; + new_rect.left = MAX(kLeftMargin, + fMasterView->LatchWidth()) + x; + new_rect.right = new_rect.left + + new_column->Width() - 1; handle_field = true; } break; @@ -2914,44 +3216,44 @@ void OutlineView::MouseDown(BPoint position) } // Handle mouse down - if(handle_field) { + if (handle_field) { fMouseDown = true; fFieldRect = new_rect; fCurrentColumn = new_column; fCurrentRow = new_row; fCurrentField = new_field; fCurrentCode = B_INSIDE_VIEW; - fCurrentColumn->MouseDown(fMasterView,fCurrentRow,fCurrentField,fFieldRect,position,1); + fCurrentColumn->MouseDown(fMasterView, fCurrentRow, + fCurrentField, fFieldRect, position, 1); } - if(!fEditMode) { + if (!fEditMode) { fTargetRow = row; fTargetRowTop = rowTop; FindVisibleRect(fFocusRow, &fFocusRowRect); - float leftWidgetBoundry = indent * kOutlineLevelIndent + MAX(kLeftMargin, fMasterView->LatchWidth()) - - fMasterView->LatchWidth(); - fLatchRect.Set(leftWidgetBoundry, rowTop, leftWidgetBoundry + - fMasterView->LatchWidth(), rowTop + row->Height()); + float leftWidgetBoundry = indent * kOutlineLevelIndent + + MAX(kLeftMargin, fMasterView->LatchWidth()) + - fMasterView->LatchWidth(); + fLatchRect.Set(leftWidgetBoundry, rowTop, leftWidgetBoundry + + fMasterView->LatchWidth(), rowTop + row->Height()); if (fLatchRect.Contains(position) && row->HasLatch()) { fCurrentState = LATCH_CLICKED; - if (fTargetRow->fNextSelected != 0) { - if(fEditMode) - SetHighColor(fMasterView->Color(B_COLOR_EDIT_BACKGROUND)); - else - SetHighColor(fMasterView->Color(B_COLOR_SELECTION)); - } + if (fTargetRow->fNextSelected != 0) + SetHighColor(fMasterView->Color(B_COLOR_SELECTION)); else SetHighColor(fMasterView->Color(B_COLOR_BACKGROUND)); FillRect(fLatchRect); - if (fLatchRect.Contains(position)) - fMasterView->DrawLatch(this, fLatchRect, B_PRESSED_LATCH, row); - else - fMasterView->DrawLatch(this, fLatchRect, fTargetRow->fIsExpanded - ? B_OPEN_LATCH : B_CLOSED_LATCH, row); - + if (fLatchRect.Contains(position)) { + fMasterView->DrawLatch(this, fLatchRect, B_PRESSED_LATCH, + row); + } else { + fMasterView->DrawLatch(this, fLatchRect, + fTargetRow->fIsExpanded ? B_OPEN_LATCH + : B_CLOSED_LATCH, row); + } } else { Invalidate(fFocusRowRect); fFocusRow = fTargetRow; @@ -2969,8 +3271,10 @@ void OutlineView::MouseDown(BPoint position) else { if (fTargetRow->fNextSelected != 0) { // Unselect row - fTargetRow->fNextSelected->fPrevSelected = fTargetRow->fPrevSelected; - fTargetRow->fPrevSelected->fNextSelected = fTargetRow->fNextSelected; + fTargetRow->fNextSelected->fPrevSelected + = fTargetRow->fPrevSelected; + fTargetRow->fPrevSelected->fNextSelected + = fTargetRow->fNextSelected; fTargetRow->fPrevSelected = 0; fTargetRow->fNextSelected = 0; fFirstSelectedItem = NULL; @@ -2979,14 +3283,17 @@ void OutlineView::MouseDown(BPoint position) if (fSelectionMode == B_SINGLE_SELECTION_LIST) DeselectAll(); - fTargetRow->fNextSelected = fSelectionListDummyHead.fNextSelected; - fTargetRow->fPrevSelected = &fSelectionListDummyHead; + fTargetRow->fNextSelected + = fSelectionListDummyHead.fNextSelected; + fTargetRow->fPrevSelected + = &fSelectionListDummyHead; fTargetRow->fNextSelected->fPrevSelected = fTargetRow; fTargetRow->fPrevSelected->fNextSelected = fTargetRow; fFirstSelectedItem = fTargetRow; } - Invalidate(BRect(fVisibleRect.left, fTargetRowTop, fVisibleRect.right, + Invalidate(BRect(fVisibleRect.left, fTargetRowTop, + fVisibleRect.right, fTargetRowTop + fTargetRow->Height())); } @@ -3017,34 +3324,42 @@ void OutlineView::MouseDown(BPoint position) Window()->CurrentMessage()->FindInt32("clicks", &fClickCount); fClickPoint = position; -} // end of MouseDown() +} -void OutlineView::MouseMoved(BPoint position, uint32 /*transit*/, const BMessage */*message*/) + +void +OutlineView::MouseMoved(BPoint position, uint32 /*transit*/, + const BMessage* /*dragMessage*/) { if (!fMouseDown) { // Update fCurrentField bool handle_field = false; - BField *new_field = 0; - BRow *new_row = 0; - BColumn *new_column = 0; + BField* new_field = 0; + BRow* new_row = 0; + BColumn* new_column = 0; BRect new_rect(0,0,0,0); if (position.y >=0 ) { float top; int32 indent; - BRow *row = FindRow(position.y, &indent, &top); + BRow* row = FindRow(position.y, &indent, &top); if (row && position.x >=0 ) { float x=0; for (int32 c=0;cCountColumns();c++) { new_column = fMasterView->ColumnAt(c); if (!new_column->IsVisible()) continue; - if ((MAX(kLeftMargin, fMasterView->LatchWidth())+x)+new_column->Width() > position.x) { + if ((MAX(kLeftMargin, + fMasterView->LatchWidth()) + x) + new_column->Width() + > position.x) { + if(new_column->WantsEvents()) { new_field = row->GetField(c); new_row = row; FindRect(new_row,&new_rect); - new_rect.left = MAX(kLeftMargin, fMasterView->LatchWidth()) + x; - new_rect.right = new_rect.left + new_column->Width() - 1; + new_rect.left = MAX(kLeftMargin, + fMasterView->LatchWidth()) + x; + new_rect.right = new_rect.left + + new_column->Width() - 1; handle_field = true; } break; @@ -3059,26 +3374,30 @@ void OutlineView::MouseMoved(BPoint position, uint32 /*transit*/, const BMessage if (new_field != fCurrentField) { if (fCurrentField) { fCurrentColumn->MouseMoved(fMasterView, fCurrentRow, - fCurrentField, fFieldRect, position, 0, fCurrentCode = B_EXITED_VIEW); + fCurrentField, fFieldRect, position, 0, + fCurrentCode = B_EXITED_VIEW); } fCurrentColumn = new_column; fCurrentRow = new_row; fCurrentField = new_field; fFieldRect = new_rect; - if(fCurrentField) { + if (fCurrentField) { fCurrentColumn->MouseMoved(fMasterView, fCurrentRow, - fCurrentField, fFieldRect, position, 0, fCurrentCode = B_ENTERED_VIEW); + fCurrentField, fFieldRect, position, 0, + fCurrentCode = B_ENTERED_VIEW); } } else { - if(fCurrentField) { + if (fCurrentField) { fCurrentColumn->MouseMoved(fMasterView, fCurrentRow, - fCurrentField, fFieldRect, position, 0, fCurrentCode = B_INSIDE_VIEW); + fCurrentField, fFieldRect, position, 0, + fCurrentCode = B_INSIDE_VIEW); } } } else { if (fCurrentField) { fCurrentColumn->MouseMoved(fMasterView, fCurrentRow, - fCurrentField, fFieldRect, position, 0, fCurrentCode = B_EXITED_VIEW); + fCurrentField, fFieldRect, position, 0, + fCurrentCode = B_EXITED_VIEW); fCurrentField = 0; fCurrentColumn = 0; fCurrentRow = 0; @@ -3090,19 +3409,23 @@ void OutlineView::MouseMoved(BPoint position, uint32 /*transit*/, const BMessage if (fCurrentCode == B_OUTSIDE_VIEW || fCurrentCode == B_EXITED_VIEW) { fCurrentColumn->MouseMoved(fMasterView, fCurrentRow, - fCurrentField, fFieldRect, position, 1, fCurrentCode = B_ENTERED_VIEW); + fCurrentField, fFieldRect, position, 1, + fCurrentCode = B_ENTERED_VIEW); } else { fCurrentColumn->MouseMoved(fMasterView, fCurrentRow, - fCurrentField, fFieldRect, position, 1, fCurrentCode = B_INSIDE_VIEW); + fCurrentField, fFieldRect, position, 1, + fCurrentCode = B_INSIDE_VIEW); } } else { if (fCurrentCode == B_INSIDE_VIEW || fCurrentCode == B_ENTERED_VIEW) { fCurrentColumn->MouseMoved(fMasterView, fCurrentRow, - fCurrentField, fFieldRect, position, 1, fCurrentCode = B_EXITED_VIEW); + fCurrentField, fFieldRect, position, 1, + fCurrentCode = B_EXITED_VIEW); } else { fCurrentColumn->MouseMoved(fMasterView, fCurrentRow, - fCurrentField, fFieldRect, position, 1, fCurrentCode = B_OUTSIDE_VIEW); + fCurrentField, fFieldRect, position, 1, + fCurrentCode = B_OUTSIDE_VIEW); } } } @@ -3112,30 +3435,29 @@ void OutlineView::MouseMoved(BPoint position, uint32 /*transit*/, const BMessage switch (fCurrentState) { case LATCH_CLICKED: - if (fTargetRow->fNextSelected != 0) { - if(fEditMode) - SetHighColor(fMasterView->Color(B_COLOR_EDIT_BACKGROUND)); - else - SetHighColor(fMasterView->Color(B_COLOR_SELECTION)); - } + if (fTargetRow->fNextSelected != 0) + SetHighColor(fMasterView->Color(B_COLOR_SELECTION)); else SetHighColor(fMasterView->Color(B_COLOR_BACKGROUND)); FillRect(fLatchRect); - if (fLatchRect.Contains(position)) - fMasterView->DrawLatch(this, fLatchRect, B_PRESSED_LATCH, fTargetRow); - else - fMasterView->DrawLatch(this, fLatchRect, fTargetRow->fIsExpanded - ? B_OPEN_LATCH : B_CLOSED_LATCH, fTargetRow); - + if (fLatchRect.Contains(position)) { + fMasterView->DrawLatch(this, fLatchRect, B_PRESSED_LATCH, + fTargetRow); + } else { + fMasterView->DrawLatch(this, fLatchRect, + fTargetRow->fIsExpanded ? B_OPEN_LATCH : B_CLOSED_LATCH, + fTargetRow); + } break; - - + case ROW_CLICKED: if (abs((int)(position.x - fClickPoint.x)) > kRowDragSensitivity - || abs((int)(position.y - fClickPoint.y)) > kRowDragSensitivity) { + || abs((int)(position.y - fClickPoint.y)) + > kRowDragSensitivity) { fCurrentState = DRAGGING_ROWS; - fMasterView->InitiateDrag(fClickPoint, fTargetRow->fNextSelected != 0); + fMasterView->InitiateDrag(fClickPoint, + fTargetRow->fNextSelected != 0); } break; @@ -3147,9 +3469,9 @@ void OutlineView::MouseMoved(BPoint position, uint32 /*transit*/, const BMessage if (fVisibleRect.Contains(position)) { float top; int32 indent; - BRow *target = FindRow(position.y, &indent, &top); - if(target) - SetFocusRow(target,true); + BRow* target = FindRow(position.y, &indent, &top); + if (target) + SetFocusRow(target, true); } } break; @@ -3162,21 +3484,21 @@ void OutlineView::MouseMoved(BPoint position, uint32 /*transit*/, const BMessage if (fVisibleRect.Contains(position)) { float top; int32 indent; - BRow *target = FindRow(position.y, &indent, &top); - if(target==fRollOverRow) + BRow* target = FindRow(position.y, &indent, &top); + if (target == fRollOverRow) break; if (fRollOverRow) { BRect rect; FindRect(fRollOverRow, &rect); Invalidate(rect); } - fRollOverRow=target; + fRollOverRow = target; #if 0 SetFocusRow(fRollOverRow,false); #else PushState(); SetDrawingMode(B_OP_BLEND); - SetHighColor(255,255,255,255); + SetHighColor(255, 255, 255, 255); BRect rect; FindRect(fRollOverRow, &rect); rect.bottom -= 1.0; @@ -3195,58 +3517,73 @@ void OutlineView::MouseMoved(BPoint position, uint32 /*transit*/, const BMessage } } } -} // end of MouseMoved() +} -void OutlineView::MouseUp(BPoint position) + +void +OutlineView::MouseUp(BPoint position) { if (fCurrentField) { - fCurrentColumn->MouseUp(fMasterView,fCurrentRow,fCurrentField); + fCurrentColumn->MouseUp(fMasterView, fCurrentRow, fCurrentField); fMouseDown = false; } - if (!fEditMode) { - switch (fCurrentState) { - case LATCH_CLICKED: - if (fLatchRect.Contains(position)) - fMasterView->ExpandOrCollapse(fTargetRow, !fTargetRow->fIsExpanded); - - Invalidate(fLatchRect); - fCurrentState = INACTIVE; - break; - - case ROW_CLICKED: - if (fClickCount > 1 - && abs((int)fClickPoint.x - (int)position.x) < kDoubleClickMoveSensitivity - && abs((int)fClickPoint.y - (int)position.y) < kDoubleClickMoveSensitivity) { - fMasterView->ItemInvoked(); - } - fCurrentState = INACTIVE; - break; - - case DRAGGING_ROWS: - fCurrentState = INACTIVE; - // Falls through + if (fEditMode) + return; - default: - if (fDropHighlightY != -1) { - InvertRect(BRect(0, fDropHighlightY - kDropHighlightLineHeight / 2, 1000000, - fDropHighlightY + kDropHighlightLineHeight / 2)); // Erase the old target line - fDropHighlightY = -1; - } - } + switch (fCurrentState) { + case LATCH_CLICKED: + if (fLatchRect.Contains(position)) { + fMasterView->ExpandOrCollapse(fTargetRow, + !fTargetRow->fIsExpanded); + } + + Invalidate(fLatchRect); + fCurrentState = INACTIVE; + break; + + case ROW_CLICKED: + if (fClickCount > 1 + && abs((int)fClickPoint.x - (int)position.x) + < kDoubleClickMoveSensitivity + && abs((int)fClickPoint.y - (int)position.y) + < kDoubleClickMoveSensitivity) { + fMasterView->ItemInvoked(); + } + fCurrentState = INACTIVE; + break; + + case DRAGGING_ROWS: + fCurrentState = INACTIVE; + // Falls through + + default: + if (fDropHighlightY != -1) { + InvertRect(BRect(0, + fDropHighlightY - kDropHighlightLineHeight / 2, + 1000000, fDropHighlightY + kDropHighlightLineHeight / 2)); + // Erase the old target line + fDropHighlightY = -1; + } } } -void OutlineView::MessageReceived(BMessage *message) + +void +OutlineView::MessageReceived(BMessage* message) { if (message->WasDropped()) { - fMasterView->MessageDropped(message, ConvertFromScreen(message->DropPoint())); + fMasterView->MessageDropped(message, + ConvertFromScreen(message->DropPoint())); } else { BView::MessageReceived(message); } } -void OutlineView::ChangeFocusRow(bool up, bool updateSelection, bool addToCurrentSelection) + +void +OutlineView::ChangeFocusRow(bool up, bool updateSelection, + bool addToCurrentSelection) { int32 indent; float top; @@ -3265,7 +3602,7 @@ void OutlineView::ChangeFocusRow(bool up, bool updateSelection, bool addToCurren // no row is currently focused, set this to the top of the window // so we will select the first visible item in the list. - BRow *newRow = FindRow(newRowPos, &indent, &top); + BRow* newRow = FindRow(newRowPos, &indent, &top); if (newRow) { if (fFocusRow) { fFocusRowRect.right = 10000; @@ -3279,11 +3616,14 @@ void OutlineView::ChangeFocusRow(bool up, bool updateSelection, bool addToCurren Invalidate(fFocusRowRect); if (updateSelection) { - if (!addToCurrentSelection || fSelectionMode == B_SINGLE_SELECTION_LIST) + if (!addToCurrentSelection + || fSelectionMode == B_SINGLE_SELECTION_LIST) { DeselectAll(); + } if (fFocusRow->fNextSelected == 0) { - fFocusRow->fNextSelected = fSelectionListDummyHead.fNextSelected; + fFocusRow->fNextSelected + = fSelectionListDummyHead.fNextSelected; fFocusRow->fPrevSelected = &fSelectionListDummyHead; fFocusRow->fNextSelected->fPrevSelected = fFocusRow; fFocusRow->fPrevSelected->fNextSelected = fFocusRow; @@ -3295,7 +3635,7 @@ void OutlineView::ChangeFocusRow(bool up, bool updateSelection, bool addToCurren Invalidate(fFocusRowRect); if (verticalScroll != 0) { - BScrollBar *vScrollBar = ScrollBar(B_VERTICAL); + BScrollBar* vScrollBar = ScrollBar(B_VERTICAL); float min, max; vScrollBar->GetRange(&min, &max); if (verticalScroll < min) @@ -3310,15 +3650,19 @@ void OutlineView::ChangeFocusRow(bool up, bool updateSelection, bool addToCurren fMasterView->SelectionChanged(); } -void OutlineView::MoveFocusToVisibleRect() + +void +OutlineView::MoveFocusToVisibleRect() { fFocusRow = 0; ChangeFocusRow(true, true, false); } -BRow* OutlineView::CurrentSelection(BRow *lastSelected) const + +BRow* +OutlineView::CurrentSelection(BRow* lastSelected) const { - BRow *row; + BRow* row; if (lastSelected == 0) row = fSelectionListDummyHead.fNextSelected; else @@ -3331,7 +3675,9 @@ BRow* OutlineView::CurrentSelection(BRow *lastSelected) const return row; } -void OutlineView::ToggleFocusRowSelection(bool selectRange) + +void +OutlineView::ToggleFocusRowSelection(bool selectRange) { if (fFocusRow == 0) return; @@ -3362,131 +3708,142 @@ void OutlineView::ToggleFocusRowSelection(bool selectRange) Invalidate(fFocusRowRect); } -void OutlineView::ToggleFocusRowOpen() + +void +OutlineView::ToggleFocusRowOpen() { if (fFocusRow) fMasterView->ExpandOrCollapse(fFocusRow, !fFocusRow->fIsExpanded); } -// xxx Could use CopyBits here to speed things up. -void OutlineView::ExpandOrCollapse(BRow* ParentRow, bool Expand) +void +OutlineView::ExpandOrCollapse(BRow* parentRow, bool expand) { - if (ParentRow) { - - if (ParentRow->fIsExpanded == Expand) - return; + // TODO: Could use CopyBits here to speed things up. - ParentRow->fIsExpanded = Expand; + if (parentRow == NULL) + return; - BRect parentRect; - if (FindRect(ParentRow, &parentRect)) { - // Determine my new height - float subTreeHeight = 0.0; - if (ParentRow->fIsExpanded) - for (RecursiveOutlineIterator iterator(ParentRow->fChildList); - iterator.CurrentRow(); - iterator.GoToNext() - ) - { - subTreeHeight += iterator.CurrentRow()->Height()+1; - } - else - for (RecursiveOutlineIterator iterator(ParentRow->fChildList); - iterator.CurrentRow(); - iterator.GoToNext() - ) - { - subTreeHeight -= iterator.CurrentRow()->Height()+1; - } - fItemsHeight += subTreeHeight; - - // Adjust focus row if necessary. - if (FindRect(fFocusRow, &fFocusRowRect) == false) { - // focus row is in a subtree that has collapsed, move it up to the parent. - fFocusRow = ParentRow; - FindRect(fFocusRow, &fFocusRowRect); - } - - Invalidate(BRect(0, parentRect.top, fVisibleRect.right, fVisibleRect.bottom)); - FixScrollBar(false); - } - } - -} + if (parentRow->fIsExpanded == expand) + return; -void OutlineView::RemoveRow(BRow *row) -{ - if (row) { - BRow *parentRow; - bool parentIsVisible; - float subTreeHeight = row->Height(); - if (FindParent(row, &parentRow, &parentIsVisible)) { - // adjust height - if (parentIsVisible && (parentRow == 0 || parentRow->fIsExpanded)) { - if (row->fIsExpanded) { - for (RecursiveOutlineIterator iterator(row->fChildList); - iterator.CurrentRow(); iterator.GoToNext()) - subTreeHeight += iterator.CurrentRow()->Height(); - } + parentRow->fIsExpanded = expand; + + BRect parentRect; + if (FindRect(parentRow, &parentRect)) { + // Determine my new height + float subTreeHeight = 0.0; + if (parentRow->fIsExpanded) + for (RecursiveOutlineIterator iterator(parentRow->fChildList); + iterator.CurrentRow(); + iterator.GoToNext() + ) + { + subTreeHeight += iterator.CurrentRow()->Height()+1; } - } - if (parentRow) { - if (parentRow->fIsExpanded) - fItemsHeight -= subTreeHeight + 1; - } else { - fItemsHeight -= subTreeHeight + 1; - } - FixScrollBar(false); - if (parentRow) - parentRow->fChildList->RemoveItem(row); else - fRows.RemoveItem(row); - - if (parentRow != 0 && parentRow->fChildList->CountItems() == 0) { - delete parentRow->fChildList; - parentRow->fChildList = 0; - if (parentIsVisible) - Invalidate(); // xxx crude way of redrawing latch - } - - if (parentIsVisible && (parentRow == 0 || parentRow->fIsExpanded)) - Invalidate(); // xxx make me smarter. - + for (RecursiveOutlineIterator iterator(parentRow->fChildList); + iterator.CurrentRow(); + iterator.GoToNext() + ) + { + subTreeHeight -= iterator.CurrentRow()->Height()+1; + } + fItemsHeight += subTreeHeight; // Adjust focus row if necessary. - if (fFocusRow && FindRect(fFocusRow, &fFocusRowRect) == false) { - // focus row is in a subtree that is gone, move it up to the parent. + if (FindRect(fFocusRow, &fFocusRowRect) == false) { + // focus row is in a subtree that has collapsed, + // move it up to the parent. fFocusRow = parentRow; - if (fFocusRow) - FindRect(fFocusRow, &fFocusRowRect); + FindRect(fFocusRow, &fFocusRowRect); } - // Remove this from the selection if necessary - if (row->fNextSelected != 0) { - row->fNextSelected->fPrevSelected = row->fPrevSelected; - row->fPrevSelected->fNextSelected = row->fNextSelected; - row->fPrevSelected = 0; - row->fNextSelected = 0; - fMasterView->SelectionChanged(); - } - - fCurrentColumn = 0; - fCurrentRow = 0; - fCurrentField = 0; + Invalidate(BRect(0, parentRect.top, fVisibleRect.right, + fVisibleRect.bottom)); + FixScrollBar(false); } } -BRowContainer* OutlineView::RowList() +void +OutlineView::RemoveRow(BRow* row) +{ + if (row == NULL) + return; + + BRow* parentRow; + bool parentIsVisible; + float subTreeHeight = row->Height(); + if (FindParent(row, &parentRow, &parentIsVisible)) { + // adjust height + if (parentIsVisible && (parentRow == 0 || parentRow->fIsExpanded)) { + if (row->fIsExpanded) { + for (RecursiveOutlineIterator iterator(row->fChildList); + iterator.CurrentRow(); iterator.GoToNext()) + subTreeHeight += iterator.CurrentRow()->Height(); + } + } + } + if (parentRow) { + if (parentRow->fIsExpanded) + fItemsHeight -= subTreeHeight + 1; + } else { + fItemsHeight -= subTreeHeight + 1; + } + FixScrollBar(false); + if (parentRow) + parentRow->fChildList->RemoveItem(row); + else + fRows.RemoveItem(row); + + if (parentRow != 0 && parentRow->fChildList->CountItems() == 0) { + delete parentRow->fChildList; + parentRow->fChildList = 0; + if (parentIsVisible) + Invalidate(); // xxx crude way of redrawing latch + } + + if (parentIsVisible && (parentRow == 0 || parentRow->fIsExpanded)) + Invalidate(); // xxx make me smarter. + + + // Adjust focus row if necessary. + if (fFocusRow && FindRect(fFocusRow, &fFocusRowRect) == false) { + // focus row is in a subtree that is gone, move it up to the parent. + fFocusRow = parentRow; + if (fFocusRow) + FindRect(fFocusRow, &fFocusRowRect); + } + + // Remove this from the selection if necessary + if (row->fNextSelected != 0) { + row->fNextSelected->fPrevSelected = row->fPrevSelected; + row->fPrevSelected->fNextSelected = row->fNextSelected; + row->fPrevSelected = 0; + row->fNextSelected = 0; + fMasterView->SelectionChanged(); + } + + fCurrentColumn = 0; + fCurrentRow = 0; + fCurrentField = 0; +} + + +BRowContainer* +OutlineView::RowList() { return &fRows; } -void OutlineView::UpdateRow(BRow *row) + +void +OutlineView::UpdateRow(BRow* row) { if (row) { // Determine if this row has changed its sort order - BRow *parentRow = NULL; + BRow* parentRow = NULL; bool parentIsVisible = false; FindParent(row, &parentRow, &parentIsVisible); @@ -3518,119 +3875,124 @@ void OutlineView::UpdateRow(BRow *row) } } -void OutlineView::AddRow(BRow* Row, int32 Index, BRow* ParentRow) + +void +OutlineView::AddRow(BRow* row, int32 Index, BRow* parentRow) { - if(Row) { - Row->fParent = ParentRow; - - if (fMasterView->SortingEnabled()) { - // Ignore index here. - if (ParentRow) { - if (ParentRow->fChildList == 0) - ParentRow->fChildList = new BRowContainer; - - AddSorted(ParentRow->fChildList, Row); - } else - AddSorted(&fRows, Row); - } else { - // Note, a -1 index implies add to end if sorting is not enabled - if (ParentRow) { - if (ParentRow->fChildList == 0) - ParentRow->fChildList = new BRowContainer; - - if (Index < 0 || Index > ParentRow->fChildList->CountItems()) - ParentRow->fChildList->AddItem(Row); - else - ParentRow->fChildList->AddItem(Row, Index); - } else { - if (Index < 0 || Index >= fRows.CountItems()) - fRows.AddItem(Row); - else - fRows.AddItem(Row, Index); - } - } - - if (ParentRow == 0 || ParentRow->fIsExpanded) - fItemsHeight += Row->Height() + 1; - - FixScrollBar(false); - - BRect newRowRect; - bool newRowIsInOpenBranch = FindRect(Row, &newRowRect); - - if (fFocusRow && fFocusRowRect.top > newRowRect.bottom) { - // The focus row has moved. - Invalidate(fFocusRowRect); - FindRect(fFocusRow, &fFocusRowRect); - Invalidate(fFocusRowRect); - } - - if (newRowIsInOpenBranch) { - if (fCurrentState == INACTIVE) { - if (newRowRect.bottom < fVisibleRect.top) { - // The new row is totally above the current viewport, move - // everything down and redraw the first line. - BRect source(fVisibleRect); - BRect dest(fVisibleRect); - source.bottom -= Row->Height() + 1; - dest.top += Row->Height() + 1; - CopyBits(source, dest); - Invalidate(BRect(fVisibleRect.left, fVisibleRect.top, fVisibleRect.right, - fVisibleRect.top + newRowRect.Height())); - } else if (newRowRect.top < fVisibleRect.bottom) { - // New item is somewhere in the current region. Scroll everything - // beneath it down and invalidate just the new row rect. - BRect source(fVisibleRect.left, newRowRect.top, fVisibleRect.right, - fVisibleRect.bottom - newRowRect.Height()); - BRect dest(source); - dest.OffsetBy(0, newRowRect.Height() + 1); - CopyBits(source, dest); - Invalidate(newRowRect); - } // otherwise, this is below the currently visible region - } else { - // Adding the item may have caused the item that the user is currently - // selected to move. This would cause annoying drawing and interaction - // bugs, as the position of that item is cached. If this happens, resize - // the scroll bar, then scroll back so the selected item is in view. - BRect targetRect; - if (FindRect(fTargetRow, &targetRect)) { - float delta = targetRect.top - fTargetRowTop; - if (delta != 0) { - // This causes a jump because ScrollBy will copy a chunk of the view. - // Since the actual contents of the view have been offset, we don't - // want this, we just want to change the virtual origin of the window. - // Constrain the clipping region so everything is clipped out so no - // copy occurs. - // - // xxx this currently doesn't work if the scroll bars aren't enabled. - // everything will still move anyway. A minor annoyance. - BRegion emptyRegion; - ConstrainClippingRegion(&emptyRegion); - PushState(); - ScrollBy(0, delta); - PopState(); - ConstrainClippingRegion(NULL); + if (!row) + return; + + row->fParent = parentRow; + + if (fMasterView->SortingEnabled()) { + // Ignore index here. + if (parentRow) { + if (parentRow->fChildList == NULL) + parentRow->fChildList = new BRowContainer; - fTargetRowTop += delta; - fClickPoint.y += delta; - fLatchRect.OffsetBy(0, delta); - } - } - } + AddSorted(parentRow->fChildList, row); + } else + AddSorted(&fRows, row); + } else { + // Note, a -1 index implies add to end if sorting is not enabled + if (parentRow) { + if (parentRow->fChildList == 0) + parentRow->fChildList = new BRowContainer; + + if (Index < 0 || Index > parentRow->fChildList->CountItems()) + parentRow->fChildList->AddItem(row); + else + parentRow->fChildList->AddItem(row, Index); + } else { + if (Index < 0 || Index >= fRows.CountItems()) + fRows.AddItem(row); + else + fRows.AddItem(row, Index); } - - // If the parent was previously childless, it will need to have a latch drawn. - BRect parentRect; - if (ParentRow && ParentRow->fChildList->CountItems() == 1 - && FindVisibleRect(ParentRow, &parentRect)) - Invalidate(parentRect); } + + if (parentRow == 0 || parentRow->fIsExpanded) + fItemsHeight += row->Height() + 1; + + FixScrollBar(false); + + BRect newRowRect; + bool newRowIsInOpenBranch = FindRect(row, &newRowRect); + + if (fFocusRow && fFocusRowRect.top > newRowRect.bottom) { + // The focus row has moved. + Invalidate(fFocusRowRect); + FindRect(fFocusRow, &fFocusRowRect); + Invalidate(fFocusRowRect); + } + + if (newRowIsInOpenBranch) { + if (fCurrentState == INACTIVE) { + if (newRowRect.bottom < fVisibleRect.top) { + // The new row is totally above the current viewport, move + // everything down and redraw the first line. + BRect source(fVisibleRect); + BRect dest(fVisibleRect); + source.bottom -= row->Height() + 1; + dest.top += row->Height() + 1; + CopyBits(source, dest); + Invalidate(BRect(fVisibleRect.left, fVisibleRect.top, fVisibleRect.right, + fVisibleRect.top + newRowRect.Height())); + } else if (newRowRect.top < fVisibleRect.bottom) { + // New item is somewhere in the current region. Scroll everything + // beneath it down and invalidate just the new row rect. + BRect source(fVisibleRect.left, newRowRect.top, fVisibleRect.right, + fVisibleRect.bottom - newRowRect.Height()); + BRect dest(source); + dest.OffsetBy(0, newRowRect.Height() + 1); + CopyBits(source, dest); + Invalidate(newRowRect); + } // otherwise, this is below the currently visible region + } else { + // Adding the item may have caused the item that the user is currently + // selected to move. This would cause annoying drawing and interaction + // bugs, as the position of that item is cached. If this happens, resize + // the scroll bar, then scroll back so the selected item is in view. + BRect targetRect; + if (FindRect(fTargetRow, &targetRect)) { + float delta = targetRect.top - fTargetRowTop; + if (delta != 0) { + // This causes a jump because ScrollBy will copy a chunk of the view. + // Since the actual contents of the view have been offset, we don't + // want this, we just want to change the virtual origin of the window. + // Constrain the clipping region so everything is clipped out so no + // copy occurs. + // + // xxx this currently doesn't work if the scroll bars aren't enabled. + // everything will still move anyway. A minor annoyance. + BRegion emptyRegion; + ConstrainClippingRegion(&emptyRegion); + PushState(); + ScrollBy(0, delta); + PopState(); + ConstrainClippingRegion(NULL); + + fTargetRowTop += delta; + fClickPoint.y += delta; + fLatchRect.OffsetBy(0, delta); + } + } + } + } + + // If the parent was previously childless, it will need to have a latch + // drawn. + BRect parentRect; + if (parentRow && parentRow->fChildList->CountItems() == 1 + && FindVisibleRect(parentRow, &parentRect)) + Invalidate(parentRect); } -void OutlineView::FixScrollBar(bool scrollToFit) +void +OutlineView::FixScrollBar(bool scrollToFit) { - BScrollBar *vScrollBar = ScrollBar(B_VERTICAL); + BScrollBar* vScrollBar = ScrollBar(B_VERTICAL); if (vScrollBar) { if (fItemsHeight > fVisibleRect.Height()) { float maxScrollBarValue = fItemsHeight - fVisibleRect.Height(); @@ -3649,7 +4011,9 @@ void OutlineView::FixScrollBar(bool scrollToFit) } } -void OutlineView::AddSorted(BRowContainer *list, BRow *row) + +void +OutlineView::AddSorted(BRowContainer* list, BRow* row) { if (list && row) { // Find general vicinity with binary search. @@ -3678,15 +4042,17 @@ void OutlineView::AddSorted(BRowContainer *list, BRow *row) } } -int32 OutlineView::CompareRows(BRow *row1, BRow *row2) + +int32 +OutlineView::CompareRows(BRow* row1, BRow* row2) { int32 itemCount (fSortColumns->CountItems()); if (row1 && row2) { for (int32 index = 0; index < itemCount; index++) { - BColumn *column = (BColumn*) fSortColumns->ItemAt(index); + BColumn* column = (BColumn*) fSortColumns->ItemAt(index); int comp = 0; - BField *field1 = (BField*) row1->GetField(column->fFieldID); - BField *field2 = (BField*) row2->GetField(column->fFieldID); + BField* field1 = (BField*) row1->GetField(column->fFieldID); + BField* field2 = (BField*) row2->GetField(column->fFieldID); if (field1 && field2) comp = column->CompareFields(field1, field2); @@ -3700,7 +4066,9 @@ int32 OutlineView::CompareRows(BRow *row1, BRow *row2) return 0; } -void OutlineView::FrameResized(float width, float height) + +void +OutlineView::FrameResized(float width, float height) { fVisibleRect.right = fVisibleRect.left + width; fVisibleRect.bottom = fVisibleRect.top + height; @@ -3708,14 +4076,16 @@ void OutlineView::FrameResized(float width, float height) _inherited::FrameResized(width, height); } -void OutlineView::ScrollTo(BPoint position) + +void +OutlineView::ScrollTo(BPoint position) { fVisibleRect.OffsetTo(position.x, position.y); // In FixScrollBar, we might not have been able to change the size of // the scroll bar because the user was scrolled down too far. Take // this opportunity to sneak it in if we can. - BScrollBar *vScrollBar = ScrollBar(B_VERTICAL); + BScrollBar* vScrollBar = ScrollBar(B_VERTICAL); float maxScrollBarValue = fItemsHeight - fVisibleRect.Height(); float min, max; vScrollBar->GetRange(&min, &max); @@ -3725,15 +4095,18 @@ void OutlineView::ScrollTo(BPoint position) _inherited::ScrollTo(position); } -const BRect& OutlineView::VisibleRect() const + +const BRect& +OutlineView::VisibleRect() const { return fVisibleRect; } -bool OutlineView::FindVisibleRect(BRow *row, BRect *out_rect) +bool +OutlineView::FindVisibleRect(BRow* row, BRect* _rect) { - if (row && out_rect) { + if (row && _rect) { float line = 0.0; for (RecursiveOutlineIterator iterator(&fRows); iterator.CurrentRow(); iterator.GoToNext()) { @@ -3741,7 +4114,8 @@ bool OutlineView::FindVisibleRect(BRow *row, BRect *out_rect) break; if (iterator.CurrentRow() == row) { - out_rect->Set(fVisibleRect.left, line, fVisibleRect.right, line + row->Height()); + _rect->Set(fVisibleRect.left, line, fVisibleRect.right, + line + row->Height()); return true; } @@ -3751,13 +4125,16 @@ bool OutlineView::FindVisibleRect(BRow *row, BRect *out_rect) return false; } -bool OutlineView::FindRect(const BRow *row, BRect *out_rect) + +bool +OutlineView::FindRect(const BRow* row, BRect* _rect) { float line = 0.0; for (RecursiveOutlineIterator iterator(&fRows); iterator.CurrentRow(); iterator.GoToNext()) { if (iterator.CurrentRow() == row) { - out_rect->Set(fVisibleRect.left, line, fVisibleRect.right, line + row->Height()); + _rect->Set(fVisibleRect.left, line, fVisibleRect.right, + line + row->Height()); return true; } @@ -3768,15 +4145,17 @@ bool OutlineView::FindRect(const BRow *row, BRect *out_rect) } -void OutlineView::ScrollTo(const BRow* Row) +void +OutlineView::ScrollTo(const BRow* row) { BRect rect; - if (FindRect(Row, &rect)) + if (FindRect(row, &rect)) ScrollTo(BPoint(rect.left, rect.top)); } -void OutlineView::DeselectAll() +void +OutlineView::DeselectAll() { // Invalidate all selected rows float line = 0.0; @@ -3785,7 +4164,7 @@ void OutlineView::DeselectAll() if (line > fVisibleRect.bottom) break; - BRow *row = iterator.CurrentRow(); + BRow* row = iterator.CurrentRow(); if (line + row->Height() > fVisibleRect.top) { if (row->fNextSelected != 0) Invalidate(BRect(fVisibleRect.left, line, fVisibleRect.right, @@ -3797,7 +4176,7 @@ void OutlineView::DeselectAll() // Set items not selected while (fSelectionListDummyHead.fNextSelected != &fSelectionListDummyHead) { - BRow *row = fSelectionListDummyHead.fNextSelected; + BRow* row = fSelectionListDummyHead.fNextSelected; row->fNextSelected->fPrevSelected = row->fPrevSelected; row->fPrevSelected->fNextSelected = row->fNextSelected; row->fNextSelected = 0; @@ -3805,23 +4184,27 @@ void OutlineView::DeselectAll() } } -BRow* OutlineView::FocusRow() const + +BRow* +OutlineView::FocusRow() const { return fFocusRow; } -void OutlineView::SetFocusRow(BRow* Row, bool Select) + +void +OutlineView::SetFocusRow(BRow* row, bool Select) { - if (Row) { + if (row) { if (Select) - AddToSelection(Row); + AddToSelection(row); - if (fFocusRow == Row) + if (fFocusRow == row) return; Invalidate(fFocusRowRect); // invalidate previous - fTargetRow = fFocusRow = Row; + fTargetRow = fFocusRow = row; FindVisibleRect(fFocusRow, &fFocusRowRect); Invalidate(fFocusRowRect); // invalidate current @@ -3831,11 +4214,13 @@ void OutlineView::SetFocusRow(BRow* Row, bool Select) } } -bool OutlineView::SortList(BRowContainer *list, bool isVisible) + +bool +OutlineView::SortList(BRowContainer* list, bool isVisible) { if (list) { // Shellsort - BRow **items = (BRow**) list->AsBList()->Items(); + BRow** items = (BRow**) list->AsBList()->Items(); int32 numItems = list->CountItems(); int h; for (h = 1; h < numItems / 9; h = 3 * h + 1) @@ -3843,7 +4228,7 @@ bool OutlineView::SortList(BRowContainer *list, bool isVisible) for (;h > 0; h /= 3) { for (int step = h; step < numItems; step++) { - BRow *temp = items[step]; + BRow* temp = items[step]; int i; for (i = step - h; i >= 0; i -= h) { if (CompareRows(temp, items[i]) < 0) @@ -3872,17 +4257,21 @@ bool OutlineView::SortList(BRowContainer *list, bool isVisible) return true; } -int32 OutlineView::DeepSortThreadEntry(void *_outlineView) + +int32 +OutlineView::DeepSortThreadEntry(void* _outlineView) { ((OutlineView*) _outlineView)->DeepSort(); return 0; } -void OutlineView::DeepSort() + +void +OutlineView::DeepSort() { struct stack_entry { bool isVisible; - BRowContainer *list; + BRowContainer* list; int32 listIndex; } stack[kMaxDepth]; int32 stackTop = 0; @@ -3898,7 +4287,7 @@ void OutlineView::DeepSort() bool doneSorting = false; while (!doneSorting && !fSortCancelled) { - stack_entry *currentEntry = &stack[stackTop]; + stack_entry* currentEntry = &stack[stackTop]; // xxx Can make the invalidate area smaller by finding the rect for the // parent item and using that as the top of the invalid rect. @@ -3917,8 +4306,8 @@ void OutlineView::DeepSort() while (!foundNextList && !fSortCancelled) { for (int32 index = currentEntry->listIndex; index < currentEntry->list->CountItems(); index++) { - BRow *parentRow = currentEntry->list->ItemAt(index); - BRowContainer *childList = parentRow->fChildList; + BRow* parentRow = currentEntry->list->ItemAt(index); + BRowContainer* childList = parentRow->fChildList; if (childList != 0) { currentEntry->listIndex = index + 1; stackTop++; @@ -3946,7 +4335,9 @@ void OutlineView::DeepSort() Window()->Unlock(); } -void OutlineView::StartSorting() + +void +OutlineView::StartSorting() { // If this view is not yet attached to a window, don't start a sort thread! if (Window() == NULL) @@ -3977,7 +4368,9 @@ void OutlineView::StartSorting() resume_thread(fSortThread); } -void OutlineView::SelectRange(BRow *start, BRow *end) + +void +OutlineView::SelectRange(BRow* start, BRow* end) { if (!start || !end) return; @@ -3989,7 +4382,7 @@ void OutlineView::SelectRange(BRow *start, BRow *end) while (iterator.CurrentRow() != 0) { if (iterator.CurrentRow() == end) { // reverse selection, swap to fix special case - BRow *temp = start; + BRow* temp = start; start = end; end = temp; break; @@ -4000,8 +4393,8 @@ void OutlineView::SelectRange(BRow *start, BRow *end) } while (true) { - BRow *row = iterator.CurrentRow(); - if(row) { + BRow* row = iterator.CurrentRow(); + if (row) { if (row->fNextSelected == 0) { row->fNextSelected = fSelectionListDummyHead.fNextSelected; row->fPrevSelected = &fSelectionListDummyHead; @@ -4020,7 +4413,9 @@ void OutlineView::SelectRange(BRow *start, BRow *end) Invalidate(); // xxx make invalidation smaller } -bool OutlineView::FindParent(BRow *row, BRow **outParent, bool *out_parentIsVisible) + +bool +OutlineView::FindParent(BRow* row, BRow** outParent, bool* out_parentIsVisible) { bool result = false; if (row && outParent) { @@ -4028,21 +4423,24 @@ bool OutlineView::FindParent(BRow *row, BRow **outParent, bool *out_parentIsVisi // Walk up the parent chain to determine if this row is visible bool isVisible = true; - for (BRow *currentRow = row->fParent; currentRow; currentRow = currentRow->fParent) { + for (BRow* currentRow = row->fParent; currentRow; currentRow = currentRow->fParent) { if (!currentRow->fIsExpanded) { isVisible = false; break; } } - if (out_parentIsVisible) *out_parentIsVisible = isVisible; + if (out_parentIsVisible) + *out_parentIsVisible = isVisible; result = (NULL != *outParent); } return result; } -int32 OutlineView::IndexOf(BRow *row) + +int32 +OutlineView::IndexOf(BRow* row) { if (row) { if (row->fParent == 0) @@ -4055,19 +4453,23 @@ int32 OutlineView::IndexOf(BRow *row) return B_ERROR; } -void OutlineView::InvalidateCachedPositions() + +void +OutlineView::InvalidateCachedPositions() { if (fFocusRow) FindRect(fFocusRow, &fFocusRowRect); } -float OutlineView::GetColumnPreferredWidth(BColumn *column) + +float +OutlineView::GetColumnPreferredWidth(BColumn* column) { float preferred = 0.0; for (RecursiveOutlineIterator iterator(&fRows); iterator.CurrentRow(); iterator.GoToNext()) { - BRow *row = iterator.CurrentRow(); - BField *field = row->GetField(column->fFieldID); + BRow* row = iterator.CurrentRow(); + BField* field = row->GetField(column->fFieldID); if (field) { float width = column->GetPreferredWidth(field, this); if (preferred < width) @@ -4077,14 +4479,17 @@ float OutlineView::GetColumnPreferredWidth(BColumn *column) return preferred; } + // #pragma mark - -RecursiveOutlineIterator::RecursiveOutlineIterator(BRowContainer *list, bool openBranchesOnly) - : fStackIndex(0), - fCurrentListIndex(0), - fCurrentListDepth(0), - fOpenBranchesOnly(openBranchesOnly) +RecursiveOutlineIterator::RecursiveOutlineIterator(BRowContainer* list, + bool openBranchesOnly) + : + fStackIndex(0), + fCurrentListIndex(0), + fCurrentListDepth(0), + fOpenBranchesOnly(openBranchesOnly) { if (list == 0 || list->CountItems() == 0) fCurrentList = 0; @@ -4092,7 +4497,9 @@ RecursiveOutlineIterator::RecursiveOutlineIterator(BRowContainer *list, bool ope fCurrentList = list; } -BRow* RecursiveOutlineIterator::CurrentRow() const + +BRow* +RecursiveOutlineIterator::CurrentRow() const { if (fCurrentList == 0) return 0; @@ -4100,7 +4507,9 @@ BRow* RecursiveOutlineIterator::CurrentRow() const return fCurrentList->ItemAt(fCurrentListIndex); } -void RecursiveOutlineIterator::GoToNext() + +void +RecursiveOutlineIterator::GoToNext() { if (fCurrentList == 0) return; @@ -4109,7 +4518,7 @@ void RecursiveOutlineIterator::GoToNext() return; } - BRow *currentRow = fCurrentList->ItemAt(fCurrentListIndex); + BRow* currentRow = fCurrentList->ItemAt(fCurrentListIndex); if(currentRow) { if (currentRow->fChildList && (currentRow->fIsExpanded || !fOpenBranchesOnly) && currentRow->fChildList->CountItems() > 0) { @@ -4136,7 +4545,91 @@ void RecursiveOutlineIterator::GoToNext() } } -int32 RecursiveOutlineIterator::CurrentLevel() const + +int32 +RecursiveOutlineIterator::CurrentLevel() const { return fCurrentListDepth; } + + +void +BColumnListView::_Init(bool showHorizontalScrollbar) +{ + SetViewColor(B_TRANSPARENT_32_BIT); + + BRect bounds(Bounds()); + + for (int i = 0; i < (int)B_COLOR_TOTAL; i++) + fColorList[i] = kColor[i]; + + BRect titleRect(bounds); + titleRect.bottom = titleRect.top + kTitleHeight; +#if !LOWER_SCROLLBAR + titleRect.right -= B_V_SCROLL_BAR_WIDTH + 1; +#endif + + BRect outlineRect(bounds); + outlineRect.top = titleRect.bottom + 1.0; + outlineRect.right -= B_V_SCROLL_BAR_WIDTH + 1; + if (showHorizontalScrollbar) + outlineRect.bottom -= B_H_SCROLL_BAR_HEIGHT + 1; + + BRect vScrollBarRect(bounds); +#if LOWER_SCROLLBAR + vScrollBarRect.top += kTitleHeight; +#endif + + vScrollBarRect.left = vScrollBarRect.right - B_V_SCROLL_BAR_WIDTH; + if (showHorizontalScrollbar) + vScrollBarRect.bottom -= B_H_SCROLL_BAR_HEIGHT; + + BRect hScrollBarRect(bounds); + hScrollBarRect.top = hScrollBarRect.bottom - B_H_SCROLL_BAR_HEIGHT; + hScrollBarRect.right -= B_V_SCROLL_BAR_WIDTH; + + // Adjust stuff so the border will fit. + if (fBorderStyle == B_PLAIN_BORDER) { + titleRect.InsetBy(1, 0); + titleRect.top++; + outlineRect.InsetBy(1, 0); + outlineRect.bottom--; + + vScrollBarRect.OffsetBy(-1, 0); + vScrollBarRect.InsetBy(0, 1); + hScrollBarRect.OffsetBy(0, -1); + hScrollBarRect.InsetBy(1, 0); + } else if (fBorderStyle == B_FANCY_BORDER) { + titleRect.InsetBy(2, 0); + titleRect.top += 2; + outlineRect.InsetBy(2, 0); + outlineRect.bottom -= 2; + + vScrollBarRect.OffsetBy(-2, 0); + vScrollBarRect.InsetBy(0, 2); + hScrollBarRect.OffsetBy(0, -2); + hScrollBarRect.InsetBy(2, 0); + } + + fOutlineView = new OutlineView(outlineRect, &fColumns, &fSortColumns, this); + AddChild(fOutlineView); + + + fTitleView = new TitleView(titleRect, fOutlineView, &fColumns, + &fSortColumns, this, B_FOLLOW_LEFT_RIGHT | B_FOLLOW_TOP); + AddChild(fTitleView); + + fVerticalScrollBar = new BScrollBar(vScrollBarRect, "vertical_scroll_bar", + fOutlineView, 0.0, bounds.Height(), B_VERTICAL); + AddChild(fVerticalScrollBar); + + fHorizontalScrollBar = new BScrollBar(hScrollBarRect, + "horizontal_scroll_bar", fTitleView, 0.0, bounds.Width(), B_HORIZONTAL); + AddChild(fHorizontalScrollBar); + + if (!showHorizontalScrollbar) + fHorizontalScrollBar->Hide(); + + fOutlineView->FixScrollBar(true); +} +