From 8c2813c1871f922248d187c377ccd4a3176b6432 Mon Sep 17 00:00:00 2001 From: John Scipione Date: Wed, 25 Feb 2015 16:33:50 -0500 Subject: [PATCH] Tracker: Style fixes --- src/kits/tracker/Pose.cpp | 54 +++++++++++++++++---------------- src/kits/tracker/PoseView.cpp | 12 +++++--- src/kits/tracker/PoseView.h | 9 +++--- src/kits/tracker/TextWidget.cpp | 10 +++--- 4 files changed, 47 insertions(+), 38 deletions(-) diff --git a/src/kits/tracker/Pose.cpp b/src/kits/tracker/Pose.cpp index 149b685bb5..83e9a8e599 100644 --- a/src/kits/tracker/Pose.cpp +++ b/src/kits/tracker/Pose.cpp @@ -133,6 +133,7 @@ BPose::CreateWidgets(BPoseView* poseView) BColumn* column = poseView->ColumnAt(index); if (column == NULL) break; + fWidgetList.AddItem(new BTextWidget(fModel, column, poseView)); } } @@ -147,6 +148,7 @@ BPose::AddWidget(BPoseView* poseView, BColumn* column) BTextWidget* widget = new BTextWidget(fModel, column, poseView); fWidgetList.AddItem(widget); + return widget; } @@ -171,7 +173,7 @@ BPose::RemoveWidget(BPoseView*, BColumn* column) { int32 index; BTextWidget* widget = WidgetFor(column->AttrHash(), &index); - if (widget) + if (widget != NULL) delete fWidgetList.RemoveItemAt(index); } @@ -183,7 +185,7 @@ BPose::Commit(bool saveChanges, BPoint loc, BPoseView* poseView, int32 count = fWidgetList.CountItems(); for (int32 index = 0; index < count; index++) { BTextWidget* widget = fWidgetList.ItemAt(index); - if (widget->IsActive()) { + if (widget != NULL && widget->IsActive()) { widget->StopEdit(saveChanges, loc, poseView, this, poseIndex); break; } @@ -199,7 +201,7 @@ OneMouseUp(BTextWidget* widget, BPose* pose, BPoseView* poseView, if (poseView->ViewMode() == kListMode) rect = widget->CalcClickRect(poseLoc, column, poseView); else - rect = widget->CalcClickRect(pose->Location(poseView), 0, poseView); + rect = widget->CalcClickRect(pose->Location(poseView), NULL, poseView); if (rect.Contains(where)) { widget->MouseUp(rect, poseView, pose, where); @@ -254,9 +256,9 @@ BPose::UpdateWidgetAndModel(Model* resolvedModel, const char* attrName, // may overlap and we get aliasing uint32 attrHash = AttrHashString(attrName, attrType); BTextWidget* widget = WidgetFor(attrHash); - if (widget) { + if (widget != NULL) { BColumn* column = poseView->ColumnFor(attrHash); - if (column) + if (column != NULL) widget->CheckAndUpdate(poseLoc, column, poseView, visible); } else if (attrType == 0) { // attribute got likely removed, so let's search the @@ -265,9 +267,9 @@ BPose::UpdateWidgetAndModel(Model* resolvedModel, const char* attrName, for (int32 i = 0; i < count; i++) { BTextWidget* widget = fWidgetList.ItemAt(i); BColumn* column = poseView->ColumnFor(widget->AttrHash()); - if (column != NULL && !strcmp(column->AttrName(), attrName)) { - widget->CheckAndUpdate(poseLoc, column, poseView, - visible); + if (column != NULL + && strcmp(column->AttrName(), attrName) == 0) { + widget->CheckAndUpdate(poseLoc, column, poseView, visible); break; } } @@ -292,10 +294,8 @@ BPose::UpdateWidgetAndModel(Model* resolvedModel, const char* attrName, if (column->StatField()) { BTextWidget* widget = WidgetFor(column->AttrHash()); - if (widget) { - widget->CheckAndUpdate(poseLoc, column, poseView, - visible); - } + if (widget != NULL) + widget->CheckAndUpdate(poseLoc, column, poseView, visible); } } } @@ -364,9 +364,8 @@ void BPose::UpdateBrokenSymLink(BPoint poseLoc, BPoseView* poseView) { ASSERT(TargetModel()->IsSymLink()); - ASSERT(!TargetModel()->LinkTo()); - - if (!TargetModel()->IsSymLink() || TargetModel()->LinkTo()) + ASSERT(TargetModel()->LinkTo() == NULL); + if (!TargetModel()->IsSymLink() || TargetModel()->LinkTo() != NULL) return; UpdateIcon(poseLoc, poseView); @@ -379,7 +378,7 @@ BPose::UpdateWasBrokenSymlink(BPoint poseLoc, BPoseView* poseView) if (!fModel->IsSymLink()) return; - if (fModel->LinkTo()) { + if (fModel->LinkTo() != NULL) { BEntry entry(fModel->EntryRef(), true); if (entry.InitCheck() != B_OK) { watch_node(fModel->LinkTo()->NodeRef(), B_STOP_WATCHING, poseView); @@ -391,7 +390,7 @@ BPose::UpdateWasBrokenSymlink(BPoint poseLoc, BPoseView* poseView) poseView->CreateSymlinkPoseTarget(fModel); UpdateIcon(poseLoc, poseView); - if (fModel->LinkTo()) + if (fModel->LinkTo() != NULL) fModel->LinkTo()->CloseNode(); } @@ -401,10 +400,10 @@ BPose::EditFirstWidget(BPoint poseLoc, BPoseView* poseView) { // find first editable widget BColumn* column; - for (int32 i = 0;(column = poseView->ColumnAt(i)) != NULL;i++) { + for (int32 i = 0; (column = poseView->ColumnAt(i)) != NULL; i++) { BTextWidget* widget = WidgetFor(column->AttrHash()); - if (widget && widget->IsEditable()) { + if (widget != NULL && widget->IsEditable()) { BRect bounds; // ToDo: // fold the three StartEdit code sequences into a cover call @@ -412,6 +411,7 @@ BPose::EditFirstWidget(BPoint poseLoc, BPoseView* poseView) bounds = widget->CalcRect(poseLoc, column, poseView); else bounds = widget->CalcRect(Location(poseView), NULL, poseView); + widget->StartEdit(bounds, poseView, this); break; } @@ -451,7 +451,7 @@ BPose::EditPreviousNextWidgetCommon(BPoseView* poseView, bool next) BPoint poseLoc(0, poseIndex* poseView->ListElemHeight()); bounds = widget->CalcRect(poseLoc, column, poseView); } else - bounds = widget->CalcRect(Location(poseView), 0, poseView); + bounds = widget->CalcRect(Location(poseView), NULL, poseView); widget->StartEdit(bounds, poseView, this); break; @@ -537,11 +537,13 @@ BPose::PointInPose(BPoint loc, const BPoseView* poseView, BPoint where, BColumn* column = poseView->ColumnAt(index); if (column == NULL) break; + BTextWidget* widget = WidgetFor(column->AttrHash()); - if (widget + if (widget != NULL && widget->CalcClickRect(loc, column, poseView).Contains(where)) { - if (hitWidget) + if (hitWidget != NULL) *hitWidget = widget; + return true; } } @@ -595,7 +597,7 @@ BPose::Draw(BRect rect, const BRect& updateRect, BPoseView* poseView, // if widget doesn't exist, create it BTextWidget* widget = WidgetFor(column, poseView, modelOpener); - if (widget && widget->IsVisible()) { + if (widget != NULL && widget->IsVisible()) { BRect widgetRect(widget->ColumnRect(rect.LeftTop(), column, poseView)); @@ -658,7 +660,7 @@ BPose::Draw(BRect rect, const BRect& updateRect, BPoseView* poseView, if (widget == NULL || !widget->IsVisible()) return; - rect = widget->CalcRect(location, 0, poseView); + rect = widget->CalcRect(location, NULL, poseView); bool selectDuringDraw = directDraw && selected && (poseView->IsDesktopWindow() || windowActive); @@ -713,7 +715,7 @@ BPose::DeselectWithoutErasingBackground(BRect, BPoseView* poseView) return; // just invalidate the background, don't draw anything - poseView->Invalidate(widget->CalcRect(location, 0, poseView)); + poseView->Invalidate(widget->CalcRect(location, NULL, poseView)); } @@ -787,7 +789,7 @@ BPose::WidgetFor(uint32 attr, int32* index) const } } - return 0; + return NULL; } diff --git a/src/kits/tracker/PoseView.cpp b/src/kits/tracker/PoseView.cpp index 83e0c653ef..d91c1a1d1e 100644 --- a/src/kits/tracker/PoseView.cpp +++ b/src/kits/tracker/PoseView.cpp @@ -322,6 +322,7 @@ BPoseView::InitCommon() fTitleView = new BTitleView(this); if (fHScrollBar != NULL) fHScrollBar->SetTitleView(fTitleView); + fCountView = new BCountView(this); BPoint origin; @@ -2660,6 +2661,7 @@ BPoseView::RemoveColumn(BColumn* columnToRemove, bool runAlert) int32 count = fPoseList->CountItems(); for (int32 index = 0; index < count; index++) fPoseList->ItemAt(index)->RemoveWidget(this, columnToRemove); + fColumnList->RemoveItem(columnToRemove, false); fTitleView->RemoveTitle(columnToRemove); @@ -2683,7 +2685,7 @@ BPoseView::RemoveColumn(BColumn* columnToRemove, bool runAlert) int32 columnCount = CountColumns(); bool anyDateAttributesLeft = false; - for (int32 i = 0; iAttrType() == B_TIME_TYPE) anyDateAttributesLeft = true; @@ -2739,11 +2741,11 @@ BPoseView::AddColumn(BColumn* newColumn, const BColumn* after) PoseList* poseList = CurrentPoseList(); int32 count = poseList->CountItems(); int32 startIndex = (int32)(rect.top / fListElemHeight); - BPoint loc(0, startIndex* fListElemHeight); + BPoint loc(0, startIndex * fListElemHeight); for (int32 index = startIndex; index < count; index++) { BPose* pose = poseList->ItemAt(index); - if (!pose->WidgetFor(newColumn->AttrHash())) + if (pose->WidgetFor(newColumn->AttrHash()) == NULL) pose->AddWidget(this, newColumn); loc.y += fListElemHeight; @@ -6370,6 +6372,7 @@ BPoseView::InvertSelection() } else { if (index == startIndex) fSelectionPivotPose = pose; + fSelectionList->AddItem(pose); pose->Select(true); } @@ -8998,13 +9001,14 @@ BPoseView::SynchronousUpdate(BRect updateRect, bool clip) void -BPoseView::DrawViewCommon(const BRect &updateRect) +BPoseView::DrawViewCommon(const BRect& updateRect) { if (ViewMode() == kListMode) { PoseList* poseList = CurrentPoseList(); int32 count = poseList->CountItems(); int32 startIndex = (int32)((updateRect.top - fListElemHeight) / fListElemHeight); + if (startIndex < 0) startIndex = 0; diff --git a/src/kits/tracker/PoseView.h b/src/kits/tracker/PoseView.h index 131f872958..7b177efcf5 100644 --- a/src/kits/tracker/PoseView.h +++ b/src/kits/tracker/PoseView.h @@ -1245,7 +1245,7 @@ EachTextWidget(BPose* pose, BPoseView* poseView, break; BTextWidget* widget = pose->WidgetFor(column->AttrHash()); - if (widget) + if (widget != NULL) (func)(widget, pose, poseView, column, p1); } } @@ -1263,7 +1263,7 @@ EachTextWidget(BPose* pose, BPoseView* poseView, break; BTextWidget* widget = pose->WidgetFor(column->AttrHash()); - if (widget) + if (widget != NULL) (func)(widget, pose, poseView, column, p1, p2); } } @@ -1281,12 +1281,13 @@ WhileEachTextWidget(BPose* pose, BPoseView* poseView, break; BTextWidget* widget = pose->WidgetFor(column->AttrHash()); - if (widget) { + if (widget != NULL) { Result result = (func)(widget, pose, poseView, column, p1, p2); - if (result) + if (result != 0) return result; } } + return 0; } diff --git a/src/kits/tracker/TextWidget.cpp b/src/kits/tracker/TextWidget.cpp index 9174fe9a55..81b4be015b 100644 --- a/src/kits/tracker/TextWidget.cpp +++ b/src/kits/tracker/TextWidget.cpp @@ -159,6 +159,7 @@ BTextWidget::CalcRectCommon(BPoint poseLoc, const BColumn* column, - (textWidth / 2); if (result.left < 0) result.left = 0; + result.right = result.left + textWidth + 1; break; @@ -168,6 +169,7 @@ BTextWidget::CalcRectCommon(BPoint poseLoc, const BColumn* column, if (result.left < 0) result.left = 0; break; + default: TRESPASS(); break; @@ -217,7 +219,7 @@ BTextWidget::CalcClickRect(BPoint poseLoc, const BColumn* column, if (result.Width() < kWidthMargin) { // if resulting rect too narrow, make it a bit wider // for comfortable clicking - if (column && column->Width() < kWidthMargin) + if (column != NULL && column->Width() < kWidthMargin) result.right = result.left + column->Width(); else result.right = result.left + kWidthMargin; @@ -436,7 +438,7 @@ BTextWidget::StartEdit(BRect bounds, BPoseView* view, BPose* pose) // make this text widget invisible while we edit it SetVisible(false); - ASSERT(view->Window()); + ASSERT(view->Window() != NULL); // how can I not have a Window here??? if (view->Window()) { @@ -452,7 +454,7 @@ BTextWidget::StopEdit(bool saveChanges, BPoint poseLoc, BPoseView* view, { // find the text editing view BView* scrollView = view->FindView("BorderView"); - ASSERT(scrollView); + ASSERT(scrollView != NULL); if (scrollView == NULL) return; @@ -480,7 +482,7 @@ BTextWidget::StopEdit(bool saveChanges, BPoint poseLoc, BPoseView* view, scrollView->RemoveSelf(); delete scrollView; - ASSERT(view->Window()); + ASSERT(view->Window() != NULL); view->Window()->UpdateIfNeeded(); view->MakeFocus();