Style cleanup, no functional change intended
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2006-2009, Haiku, Inc. All rights reserved.
|
* Copyright 2006-2012, Haiku, Inc. All rights reserved.
|
||||||
* Distributed under the terms of the MIT License.
|
* Distributed under the terms of the MIT License.
|
||||||
*
|
*
|
||||||
* Authors:
|
* Authors:
|
||||||
@@ -47,28 +47,29 @@ static const float kMarkWidth = 14.0;
|
|||||||
static const float kBorderOffset = 3.0;
|
static const float kBorderOffset = 3.0;
|
||||||
static const float kTextOffset = 4.0;
|
static const float kTextOffset = 4.0;
|
||||||
|
|
||||||
class PathListItem : public SimpleItem,
|
|
||||||
public Observer {
|
|
||||||
public:
|
|
||||||
PathListItem(VectorPath* p,
|
|
||||||
PathListView* listView,
|
|
||||||
bool markEnabled)
|
|
||||||
: SimpleItem(""),
|
|
||||||
path(NULL),
|
|
||||||
fListView(listView),
|
|
||||||
fMarkEnabled(markEnabled),
|
|
||||||
fMarked(false)
|
|
||||||
{
|
|
||||||
SetPath(p);
|
|
||||||
}
|
|
||||||
|
|
||||||
virtual ~PathListItem()
|
class PathListItem : public SimpleItem, public Observer {
|
||||||
{
|
public:
|
||||||
SetPath(NULL);
|
PathListItem(VectorPath* p, PathListView* listView, bool markEnabled)
|
||||||
}
|
:
|
||||||
|
SimpleItem(""),
|
||||||
|
path(NULL),
|
||||||
|
fListView(listView),
|
||||||
|
fMarkEnabled(markEnabled),
|
||||||
|
fMarked(false)
|
||||||
|
{
|
||||||
|
SetPath(p);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
virtual ~PathListItem()
|
||||||
|
{
|
||||||
|
SetPath(NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// SimpleItem interface
|
// SimpleItem interface
|
||||||
virtual void Draw(BView* owner, BRect itemFrame, uint32 flags)
|
virtual void Draw(BView* owner, BRect itemFrame, uint32 flags)
|
||||||
{
|
{
|
||||||
SimpleItem::DrawBackground(owner, itemFrame, flags);
|
SimpleItem::DrawBackground(owner, itemFrame, flags);
|
||||||
|
|
||||||
@@ -78,18 +79,13 @@ class PathListItem : public SimpleItem,
|
|||||||
owner->GetFontHeight(&fh);
|
owner->GetFontHeight(&fh);
|
||||||
BString truncatedString(Text());
|
BString truncatedString(Text());
|
||||||
owner->TruncateString(&truncatedString, B_TRUNCATE_MIDDLE,
|
owner->TruncateString(&truncatedString, B_TRUNCATE_MIDDLE,
|
||||||
itemFrame.Width()
|
itemFrame.Width() - kBorderOffset - kMarkWidth - kTextOffset
|
||||||
- kBorderOffset
|
- kBorderOffset);
|
||||||
- kMarkWidth
|
|
||||||
- kTextOffset
|
|
||||||
- kBorderOffset);
|
|
||||||
float height = itemFrame.Height();
|
float height = itemFrame.Height();
|
||||||
float textHeight = fh.ascent + fh.descent;
|
float textHeight = fh.ascent + fh.descent;
|
||||||
BPoint pos;
|
BPoint pos;
|
||||||
pos.x = itemFrame.left
|
pos.x = itemFrame.left + kBorderOffset + kMarkWidth + kTextOffset;
|
||||||
+ kBorderOffset + kMarkWidth + kTextOffset;
|
pos.y = itemFrame.top + ceilf((height - textHeight) / 2.0 + fh.ascent);
|
||||||
pos.y = itemFrame.top
|
|
||||||
+ ceilf((height - textHeight) / 2.0 + fh.ascent);
|
|
||||||
owner->DrawString(truncatedString.String(), pos);
|
owner->DrawString(truncatedString.String(), pos);
|
||||||
|
|
||||||
if (!fMarkEnabled)
|
if (!fMarkEnabled)
|
||||||
@@ -109,7 +105,7 @@ class PathListItem : public SimpleItem,
|
|||||||
if (fMarked) {
|
if (fMarked) {
|
||||||
markRect.InsetBy(2, 2);
|
markRect.InsetBy(2, 2);
|
||||||
owner->SetHighColor(tint_color(owner->LowColor(),
|
owner->SetHighColor(tint_color(owner->LowColor(),
|
||||||
B_DARKEN_4_TINT));
|
B_DARKEN_4_TINT));
|
||||||
owner->SetPenSize(2);
|
owner->SetPenSize(2);
|
||||||
owner->StrokeLine(markRect.LeftTop(), markRect.RightBottom());
|
owner->StrokeLine(markRect.LeftTop(), markRect.RightBottom());
|
||||||
owner->StrokeLine(markRect.LeftBottom(), markRect.RightTop());
|
owner->StrokeLine(markRect.LeftBottom(), markRect.RightTop());
|
||||||
@@ -117,64 +113,73 @@ class PathListItem : public SimpleItem,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Observer interface
|
// Observer interface
|
||||||
virtual void ObjectChanged(const Observable* object)
|
virtual void ObjectChanged(const Observable* object)
|
||||||
{
|
{
|
||||||
UpdateText();
|
UpdateText();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// PathListItem
|
// PathListItem
|
||||||
void SetPath(VectorPath* p)
|
void SetPath(VectorPath* p)
|
||||||
{
|
{
|
||||||
if (p == path)
|
if (p == path)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (path) {
|
if (path) {
|
||||||
path->RemoveObserver(this);
|
path->RemoveObserver(this);
|
||||||
path->Release();
|
path->Release();
|
||||||
}
|
}
|
||||||
|
|
||||||
path = p;
|
path = p;
|
||||||
|
|
||||||
if (path) {
|
if (path) {
|
||||||
path->Acquire();
|
path->Acquire();
|
||||||
path->AddObserver(this);
|
path->AddObserver(this);
|
||||||
UpdateText();
|
UpdateText();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
void UpdateText()
|
|
||||||
{
|
|
||||||
SetText(path->Name());
|
|
||||||
Invalidate();
|
|
||||||
}
|
|
||||||
|
|
||||||
void SetMarkEnabled(bool enabled)
|
|
||||||
{
|
|
||||||
if (fMarkEnabled == enabled)
|
|
||||||
return;
|
|
||||||
fMarkEnabled = enabled;
|
|
||||||
Invalidate();
|
|
||||||
}
|
|
||||||
void SetMarked(bool marked)
|
|
||||||
{
|
|
||||||
if (fMarked == marked)
|
|
||||||
return;
|
|
||||||
fMarked = marked;
|
|
||||||
Invalidate();
|
|
||||||
}
|
|
||||||
|
|
||||||
void Invalidate()
|
void UpdateText()
|
||||||
{
|
{
|
||||||
// :-/
|
SetText(path->Name());
|
||||||
if (fListView->LockLooper()) {
|
Invalidate();
|
||||||
fListView->InvalidateItem(
|
}
|
||||||
fListView->IndexOf(this));
|
|
||||||
fListView->UnlockLooper();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
void SetMarkEnabled(bool enabled)
|
||||||
|
{
|
||||||
|
if (fMarkEnabled == enabled)
|
||||||
|
return;
|
||||||
|
fMarkEnabled = enabled;
|
||||||
|
Invalidate();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void SetMarked(bool marked)
|
||||||
|
{
|
||||||
|
if (fMarked == marked)
|
||||||
|
return;
|
||||||
|
fMarked = marked;
|
||||||
|
Invalidate();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void Invalidate()
|
||||||
|
{
|
||||||
|
if (fListView->LockLooper()) {
|
||||||
|
fListView->InvalidateItem(
|
||||||
|
fListView->IndexOf(this));
|
||||||
|
fListView->UnlockLooper();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public:
|
||||||
VectorPath* path;
|
VectorPath* path;
|
||||||
private:
|
|
||||||
|
private:
|
||||||
PathListView* fListView;
|
PathListView* fListView;
|
||||||
bool fMarkEnabled;
|
bool fMarkEnabled;
|
||||||
bool fMarked;
|
bool fMarked;
|
||||||
@@ -182,35 +187,47 @@ class PathListItem : public SimpleItem,
|
|||||||
|
|
||||||
|
|
||||||
class ShapePathListener : public PathContainerListener,
|
class ShapePathListener : public PathContainerListener,
|
||||||
public ShapeContainerListener {
|
public ShapeContainerListener {
|
||||||
public:
|
public:
|
||||||
ShapePathListener(PathListView* listView)
|
ShapePathListener(PathListView* listView)
|
||||||
: fListView(listView),
|
:
|
||||||
fShape(NULL)
|
fListView(listView),
|
||||||
|
fShape(NULL)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
virtual ~ShapePathListener()
|
virtual ~ShapePathListener()
|
||||||
{
|
{
|
||||||
SetShape(NULL);
|
SetShape(NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// PathContainerListener interface
|
// PathContainerListener interface
|
||||||
virtual void PathAdded(VectorPath* path, int32 index)
|
virtual void PathAdded(VectorPath* path, int32 index)
|
||||||
{
|
{
|
||||||
fListView->_SetPathMarked(path, true);
|
fListView->_SetPathMarked(path, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
virtual void PathRemoved(VectorPath* path)
|
virtual void PathRemoved(VectorPath* path)
|
||||||
{
|
{
|
||||||
fListView->_SetPathMarked(path, false);
|
fListView->_SetPathMarked(path, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// ShapeContainerListener interface
|
// ShapeContainerListener interface
|
||||||
virtual void ShapeAdded(Shape* shape, int32 index) {}
|
virtual void ShapeAdded(Shape* shape, int32 index)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
virtual void ShapeRemoved(Shape* shape)
|
virtual void ShapeRemoved(Shape* shape)
|
||||||
{
|
{
|
||||||
fListView->SetCurrentShape(NULL);
|
fListView->SetCurrentShape(NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// ShapePathListener
|
// ShapePathListener
|
||||||
void SetShape(Shape* shape)
|
void SetShape(Shape* shape)
|
||||||
{
|
{
|
||||||
@@ -226,18 +243,21 @@ class ShapePathListener : public PathContainerListener,
|
|||||||
fShape->Paths()->AddListener(this);
|
fShape->Paths()->AddListener(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Shape* CurrentShape() const
|
Shape* CurrentShape() const
|
||||||
{
|
{
|
||||||
return fShape;
|
return fShape;
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
PathListView* fListView;
|
PathListView* fListView;
|
||||||
Shape* fShape;
|
Shape* fShape;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
// #pragma mark -
|
// #pragma mark -
|
||||||
|
|
||||||
|
|
||||||
enum {
|
enum {
|
||||||
MSG_ADD = 'addp',
|
MSG_ADD = 'addp',
|
||||||
|
|
||||||
@@ -255,41 +275,40 @@ enum {
|
|||||||
MSG_REMOVE = 'remp',
|
MSG_REMOVE = 'remp',
|
||||||
};
|
};
|
||||||
|
|
||||||
// constructor
|
|
||||||
PathListView::PathListView(BRect frame,
|
|
||||||
const char* name,
|
|
||||||
BMessage* message, BHandler* target)
|
|
||||||
: SimpleListView(frame, name,
|
|
||||||
NULL, B_SINGLE_SELECTION_LIST),
|
|
||||||
fMessage(message),
|
|
||||||
fMenu(NULL),
|
|
||||||
|
|
||||||
fPathContainer(NULL),
|
PathListView::PathListView(BRect frame, const char* name, BMessage* message,
|
||||||
fShapeContainer(NULL),
|
BHandler* target)
|
||||||
fCommandStack(NULL),
|
:
|
||||||
|
SimpleListView(frame, name, NULL, B_SINGLE_SELECTION_LIST),
|
||||||
|
fMessage(message),
|
||||||
|
fMenu(NULL),
|
||||||
|
|
||||||
fCurrentShape(NULL),
|
fPathContainer(NULL),
|
||||||
fShapePathListener(new ShapePathListener(this))
|
fShapeContainer(NULL),
|
||||||
|
fCommandStack(NULL),
|
||||||
|
|
||||||
|
fCurrentShape(NULL),
|
||||||
|
fShapePathListener(new ShapePathListener(this))
|
||||||
{
|
{
|
||||||
SetTarget(target);
|
SetTarget(target);
|
||||||
}
|
}
|
||||||
|
|
||||||
// destructor
|
|
||||||
PathListView::~PathListView()
|
PathListView::~PathListView()
|
||||||
{
|
{
|
||||||
_MakeEmpty();
|
_MakeEmpty();
|
||||||
delete fMessage;
|
delete fMessage;
|
||||||
|
|
||||||
if (fPathContainer)
|
if (fPathContainer != NULL)
|
||||||
fPathContainer->RemoveListener(this);
|
fPathContainer->RemoveListener(this);
|
||||||
|
|
||||||
if (fShapeContainer)
|
if (fShapeContainer != NULL)
|
||||||
fShapeContainer->RemoveListener(fShapePathListener);
|
fShapeContainer->RemoveListener(fShapePathListener);
|
||||||
|
|
||||||
delete fShapePathListener;
|
delete fShapePathListener;
|
||||||
}
|
}
|
||||||
|
|
||||||
// SelectionChanged
|
|
||||||
void
|
void
|
||||||
PathListView::SelectionChanged()
|
PathListView::SelectionChanged()
|
||||||
{
|
{
|
||||||
@@ -299,7 +318,7 @@ PathListView::SelectionChanged()
|
|||||||
// NOTE: single selection list
|
// NOTE: single selection list
|
||||||
PathListItem* item
|
PathListItem* item
|
||||||
= dynamic_cast<PathListItem*>(ItemAt(CurrentSelection(0)));
|
= dynamic_cast<PathListItem*>(ItemAt(CurrentSelection(0)));
|
||||||
if (fMessage) {
|
if (fMessage != NULL) {
|
||||||
BMessage message(*fMessage);
|
BMessage message(*fMessage);
|
||||||
message.AddPointer("path", item ? (void*)item->path : NULL);
|
message.AddPointer("path", item ? (void*)item->path : NULL);
|
||||||
Invoke(&message);
|
Invoke(&message);
|
||||||
@@ -309,11 +328,11 @@ PathListView::SelectionChanged()
|
|||||||
_UpdateMenu();
|
_UpdateMenu();
|
||||||
}
|
}
|
||||||
|
|
||||||
// MouseDown
|
|
||||||
void
|
void
|
||||||
PathListView::MouseDown(BPoint where)
|
PathListView::MouseDown(BPoint where)
|
||||||
{
|
{
|
||||||
if (!fCurrentShape) {
|
if (fCurrentShape == NULL) {
|
||||||
SimpleListView::MouseDown(where);
|
SimpleListView::MouseDown(where);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -321,25 +340,22 @@ PathListView::MouseDown(BPoint where)
|
|||||||
bool handled = false;
|
bool handled = false;
|
||||||
int32 index = IndexOf(where);
|
int32 index = IndexOf(where);
|
||||||
PathListItem* item = dynamic_cast<PathListItem*>(ItemAt(index));
|
PathListItem* item = dynamic_cast<PathListItem*>(ItemAt(index));
|
||||||
if (item) {
|
if (item != NULL) {
|
||||||
BRect itemFrame(ItemFrame(index));
|
BRect itemFrame(ItemFrame(index));
|
||||||
itemFrame.right = itemFrame.left
|
itemFrame.right = itemFrame.left + kBorderOffset + kMarkWidth
|
||||||
+ kBorderOffset + kMarkWidth
|
+ kTextOffset / 2.0;
|
||||||
+ kTextOffset / 2.0;
|
|
||||||
VectorPath* path = item->path;
|
VectorPath* path = item->path;
|
||||||
if (itemFrame.Contains(where) && fCommandStack) {
|
if (itemFrame.Contains(where) && fCommandStack) {
|
||||||
// add or remove the path to the shape
|
// add or remove the path to the shape
|
||||||
::Command* command;
|
::Command* command;
|
||||||
if (fCurrentShape->Paths()->HasPath(path)) {
|
if (fCurrentShape->Paths()->HasPath(path)) {
|
||||||
command = new UnassignPathCommand(
|
command = new UnassignPathCommand(fCurrentShape, path);
|
||||||
fCurrentShape, path);
|
|
||||||
} else {
|
} else {
|
||||||
VectorPath* paths[1];
|
VectorPath* paths[1];
|
||||||
paths[0] = path;
|
paths[0] = path;
|
||||||
command = new AddPathsCommand(
|
command = new AddPathsCommand(fCurrentShape->Paths(),
|
||||||
fCurrentShape->Paths(),
|
paths, 1, false, fCurrentShape->Paths()->CountPaths());
|
||||||
paths, 1, false,
|
|
||||||
fCurrentShape->Paths()->CountPaths());
|
|
||||||
}
|
}
|
||||||
fCommandStack->Perform(command);
|
fCommandStack->Perform(command);
|
||||||
handled = true;
|
handled = true;
|
||||||
@@ -350,7 +366,7 @@ PathListView::MouseDown(BPoint where)
|
|||||||
SimpleListView::MouseDown(where);
|
SimpleListView::MouseDown(where);
|
||||||
}
|
}
|
||||||
|
|
||||||
// MessageReceived
|
|
||||||
void
|
void
|
||||||
PathListView::MessageReceived(BMessage* message)
|
PathListView::MessageReceived(BMessage* message)
|
||||||
{
|
{
|
||||||
@@ -482,7 +498,7 @@ PathListView::MessageReceived(BMessage* message)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// MakeDragMessage
|
|
||||||
void
|
void
|
||||||
PathListView::MakeDragMessage(BMessage* message) const
|
PathListView::MakeDragMessage(BMessage* message) const
|
||||||
{
|
{
|
||||||
@@ -492,37 +508,37 @@ PathListView::MakeDragMessage(BMessage* message) const
|
|||||||
for (int32 i = 0; i < count; i++) {
|
for (int32 i = 0; i < count; i++) {
|
||||||
PathListItem* item = dynamic_cast<PathListItem*>(
|
PathListItem* item = dynamic_cast<PathListItem*>(
|
||||||
ItemAt(CurrentSelection(i)));
|
ItemAt(CurrentSelection(i)));
|
||||||
if (item)
|
if (item != NULL)
|
||||||
message->AddPointer("path", (void*)item->path);
|
message->AddPointer("path", (void*)item->path);
|
||||||
else
|
else
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// AcceptDragMessage
|
|
||||||
bool
|
bool
|
||||||
PathListView::AcceptDragMessage(const BMessage* message) const
|
PathListView::AcceptDragMessage(const BMessage* message) const
|
||||||
{
|
{
|
||||||
return SimpleListView::AcceptDragMessage(message);
|
return SimpleListView::AcceptDragMessage(message);
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetDropTargetRect
|
|
||||||
void
|
void
|
||||||
PathListView::SetDropTargetRect(const BMessage* message, BPoint where)
|
PathListView::SetDropTargetRect(const BMessage* message, BPoint where)
|
||||||
{
|
{
|
||||||
SimpleListView::SetDropTargetRect(message, where);
|
SimpleListView::SetDropTargetRect(message, where);
|
||||||
}
|
}
|
||||||
|
|
||||||
// MoveItems
|
|
||||||
void
|
void
|
||||||
PathListView::MoveItems(BList& items, int32 toIndex)
|
PathListView::MoveItems(BList& items, int32 toIndex)
|
||||||
{
|
{
|
||||||
if (!fCommandStack || !fPathContainer)
|
if (fCommandStack == NULL || fPathContainer == NULL)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
int32 count = items.CountItems();
|
int32 count = items.CountItems();
|
||||||
VectorPath** paths = new (nothrow) VectorPath*[count];
|
VectorPath** paths = new (nothrow) VectorPath*[count];
|
||||||
if (!paths)
|
if (paths == NULL)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
for (int32 i = 0; i < count; i++) {
|
for (int32 i = 0; i < count; i++) {
|
||||||
@@ -531,10 +547,9 @@ PathListView::MoveItems(BList& items, int32 toIndex)
|
|||||||
paths[i] = item ? item->path : NULL;
|
paths[i] = item ? item->path : NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
MovePathsCommand* command
|
MovePathsCommand* command = new (nothrow) MovePathsCommand(fPathContainer,
|
||||||
= new (nothrow) MovePathsCommand(fPathContainer,
|
paths, count, toIndex);
|
||||||
paths, count, toIndex);
|
if (command == NULL) {
|
||||||
if (!command) {
|
|
||||||
delete[] paths;
|
delete[] paths;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -542,11 +557,11 @@ PathListView::MoveItems(BList& items, int32 toIndex)
|
|||||||
fCommandStack->Perform(command);
|
fCommandStack->Perform(command);
|
||||||
}
|
}
|
||||||
|
|
||||||
// CopyItems
|
|
||||||
void
|
void
|
||||||
PathListView::CopyItems(BList& items, int32 toIndex)
|
PathListView::CopyItems(BList& items, int32 toIndex)
|
||||||
{
|
{
|
||||||
if (!fCommandStack || !fPathContainer)
|
if (fCommandStack == NULL || fPathContainer == NULL)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
int32 count = items.CountItems();
|
int32 count = items.CountItems();
|
||||||
@@ -558,10 +573,9 @@ PathListView::CopyItems(BList& items, int32 toIndex)
|
|||||||
paths[i] = item ? new (nothrow) VectorPath(*item->path) : NULL;
|
paths[i] = item ? new (nothrow) VectorPath(*item->path) : NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
AddPathsCommand* command
|
AddPathsCommand* command = new(nothrow) AddPathsCommand(fPathContainer,
|
||||||
= new (nothrow) AddPathsCommand(fPathContainer,
|
paths, count, true, toIndex);
|
||||||
paths, count, true, toIndex);
|
if (command == NULL) {
|
||||||
if (!command) {
|
|
||||||
for (int32 i = 0; i < count; i++)
|
for (int32 i = 0; i < count; i++)
|
||||||
delete paths[i];
|
delete paths[i];
|
||||||
return;
|
return;
|
||||||
@@ -570,11 +584,11 @@ PathListView::CopyItems(BList& items, int32 toIndex)
|
|||||||
fCommandStack->Perform(command);
|
fCommandStack->Perform(command);
|
||||||
}
|
}
|
||||||
|
|
||||||
// RemoveItemList
|
|
||||||
void
|
void
|
||||||
PathListView::RemoveItemList(BList& items)
|
PathListView::RemoveItemList(BList& items)
|
||||||
{
|
{
|
||||||
if (!fCommandStack || !fPathContainer)
|
if (fCommandStack == NULL || fPathContainer == NULL)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
int32 count = items.CountItems();
|
int32 count = items.CountItems();
|
||||||
@@ -582,61 +596,60 @@ PathListView::RemoveItemList(BList& items)
|
|||||||
for (int32 i = 0; i < count; i++) {
|
for (int32 i = 0; i < count; i++) {
|
||||||
PathListItem* item = dynamic_cast<PathListItem*>(
|
PathListItem* item = dynamic_cast<PathListItem*>(
|
||||||
(BListItem*)items.ItemAtFast(i));
|
(BListItem*)items.ItemAtFast(i));
|
||||||
if (item)
|
if (item != NULL)
|
||||||
paths[i] = item->path;
|
paths[i] = item->path;
|
||||||
else
|
else
|
||||||
paths[i] = NULL;
|
paths[i] = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
RemovePathsCommand* command
|
RemovePathsCommand* command = new (nothrow) RemovePathsCommand(
|
||||||
= new (nothrow) RemovePathsCommand(fPathContainer,
|
fPathContainer, paths, count);
|
||||||
paths, count);
|
|
||||||
fCommandStack->Perform(command);
|
fCommandStack->Perform(command);
|
||||||
}
|
}
|
||||||
|
|
||||||
// CloneItem
|
|
||||||
BListItem*
|
BListItem*
|
||||||
PathListView::CloneItem(int32 index) const
|
PathListView::CloneItem(int32 index) const
|
||||||
{
|
{
|
||||||
if (PathListItem* item = dynamic_cast<PathListItem*>(ItemAt(index))) {
|
if (PathListItem* item = dynamic_cast<PathListItem*>(ItemAt(index))) {
|
||||||
return new PathListItem(item->path,
|
return new(nothrow) PathListItem(item->path,
|
||||||
const_cast<PathListView*>(this),
|
const_cast<PathListView*>(this), fCurrentShape != NULL);
|
||||||
fCurrentShape != NULL);
|
|
||||||
}
|
}
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
// IndexOfSelectable
|
|
||||||
int32
|
int32
|
||||||
PathListView::IndexOfSelectable(Selectable* selectable) const
|
PathListView::IndexOfSelectable(Selectable* selectable) const
|
||||||
{
|
{
|
||||||
VectorPath* path = dynamic_cast<VectorPath*>(selectable);
|
VectorPath* path = dynamic_cast<VectorPath*>(selectable);
|
||||||
if (!path)
|
if (path == NULL)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
for (int32 i = 0;
|
int32 count = CountItems();
|
||||||
PathListItem* item = dynamic_cast<PathListItem*>(ItemAt(i));
|
for (int32 i = 0; i < count; i++) {
|
||||||
i++) {
|
if (SelectableFor(ItemAt(i)) == path)
|
||||||
if (item->path == path)
|
|
||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// SelectableFor
|
|
||||||
Selectable*
|
Selectable*
|
||||||
PathListView::SelectableFor(BListItem* item) const
|
PathListView::SelectableFor(BListItem* item) const
|
||||||
{
|
{
|
||||||
PathListItem* pathItem = dynamic_cast<PathListItem*>(item);
|
PathListItem* pathItem = dynamic_cast<PathListItem*>(item);
|
||||||
if (pathItem)
|
if (pathItem != NULL)
|
||||||
return pathItem->path;
|
return pathItem->path;
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// #pragma mark -
|
// #pragma mark -
|
||||||
|
|
||||||
// PathAdded
|
|
||||||
void
|
void
|
||||||
PathListView::PathAdded(VectorPath* path, int32 index)
|
PathListView::PathAdded(VectorPath* path, int32 index)
|
||||||
{
|
{
|
||||||
@@ -653,7 +666,7 @@ PathListView::PathAdded(VectorPath* path, int32 index)
|
|||||||
UnlockLooper();
|
UnlockLooper();
|
||||||
}
|
}
|
||||||
|
|
||||||
// PathRemoved
|
|
||||||
void
|
void
|
||||||
PathListView::PathRemoved(VectorPath* path)
|
PathListView::PathRemoved(VectorPath* path)
|
||||||
{
|
{
|
||||||
@@ -670,9 +683,10 @@ PathListView::PathRemoved(VectorPath* path)
|
|||||||
UnlockLooper();
|
UnlockLooper();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// #pragma mark -
|
// #pragma mark -
|
||||||
|
|
||||||
// SetPathContainer
|
|
||||||
void
|
void
|
||||||
PathListView::SetPathContainer(PathContainer* container)
|
PathListView::SetPathContainer(PathContainer* container)
|
||||||
{
|
{
|
||||||
@@ -680,14 +694,14 @@ PathListView::SetPathContainer(PathContainer* container)
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
// detach from old container
|
// detach from old container
|
||||||
if (fPathContainer)
|
if (fPathContainer != NULL)
|
||||||
fPathContainer->RemoveListener(this);
|
fPathContainer->RemoveListener(this);
|
||||||
|
|
||||||
_MakeEmpty();
|
_MakeEmpty();
|
||||||
|
|
||||||
fPathContainer = container;
|
fPathContainer = container;
|
||||||
|
|
||||||
if (!fPathContainer)
|
if (fPathContainer == NULL)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
fPathContainer->AddListener(this);
|
fPathContainer->AddListener(this);
|
||||||
@@ -703,7 +717,7 @@ PathListView::SetPathContainer(PathContainer* container)
|
|||||||
// fPathContainer->ReadUnlock();
|
// fPathContainer->ReadUnlock();
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetShapeContainer
|
|
||||||
void
|
void
|
||||||
PathListView::SetShapeContainer(ShapeContainer* container)
|
PathListView::SetShapeContainer(ShapeContainer* container)
|
||||||
{
|
{
|
||||||
@@ -711,23 +725,23 @@ PathListView::SetShapeContainer(ShapeContainer* container)
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
// detach from old container
|
// detach from old container
|
||||||
if (fShapeContainer)
|
if (fShapeContainer != NULL)
|
||||||
fShapeContainer->RemoveListener(fShapePathListener);
|
fShapeContainer->RemoveListener(fShapePathListener);
|
||||||
|
|
||||||
fShapeContainer = container;
|
fShapeContainer = container;
|
||||||
|
|
||||||
if (fShapeContainer)
|
if (fShapeContainer != NULL)
|
||||||
fShapeContainer->AddListener(fShapePathListener);
|
fShapeContainer->AddListener(fShapePathListener);
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetCommandStack
|
|
||||||
void
|
void
|
||||||
PathListView::SetCommandStack(CommandStack* stack)
|
PathListView::SetCommandStack(CommandStack* stack)
|
||||||
{
|
{
|
||||||
fCommandStack = stack;
|
fCommandStack = stack;
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetMenu
|
|
||||||
void
|
void
|
||||||
PathListView::SetMenu(BMenu* menu)
|
PathListView::SetMenu(BMenu* menu)
|
||||||
{
|
{
|
||||||
@@ -781,7 +795,7 @@ PathListView::SetMenu(BMenu* menu)
|
|||||||
_UpdateMenu();
|
_UpdateMenu();
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetCurrentShape
|
|
||||||
void
|
void
|
||||||
PathListView::SetCurrentShape(Shape* shape)
|
PathListView::SetCurrentShape(Shape* shape)
|
||||||
{
|
{
|
||||||
@@ -794,57 +808,70 @@ PathListView::SetCurrentShape(Shape* shape)
|
|||||||
_UpdateMarks();
|
_UpdateMarks();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// #pragma mark -
|
// #pragma mark -
|
||||||
|
|
||||||
// _AddPath
|
|
||||||
bool
|
bool
|
||||||
PathListView::_AddPath(VectorPath* path, int32 index)
|
PathListView::_AddPath(VectorPath* path, int32 index)
|
||||||
{
|
{
|
||||||
if (path) {
|
if (path == NULL)
|
||||||
return AddItem(
|
return false;
|
||||||
new PathListItem(path, this, fCurrentShape != NULL), index);
|
|
||||||
|
PathListItem* item = new(nothrow) PathListItem(path, this,
|
||||||
|
fCurrentShape != NULL);
|
||||||
|
if (item == NULL)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
if (!AddItem(item, index)) {
|
||||||
|
delete item;
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
return false;
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// _RemovePath
|
|
||||||
bool
|
bool
|
||||||
PathListView::_RemovePath(VectorPath* path)
|
PathListView::_RemovePath(VectorPath* path)
|
||||||
{
|
{
|
||||||
PathListItem* item = _ItemForPath(path);
|
PathListItem* item = _ItemForPath(path);
|
||||||
if (item && RemoveItem(item)) {
|
if (item != NULL && RemoveItem(item)) {
|
||||||
delete item;
|
delete item;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// _ItemForPath
|
|
||||||
PathListItem*
|
PathListItem*
|
||||||
PathListView::_ItemForPath(VectorPath* path) const
|
PathListView::_ItemForPath(VectorPath* path) const
|
||||||
{
|
{
|
||||||
for (int32 i = 0;
|
int32 count = CountItems();
|
||||||
|
for (int32 i = 0; i < count; i++) {
|
||||||
PathListItem* item = dynamic_cast<PathListItem*>(ItemAt(i));
|
PathListItem* item = dynamic_cast<PathListItem*>(ItemAt(i));
|
||||||
i++) {
|
if (item == NULL)
|
||||||
|
continue;
|
||||||
if (item->path == path)
|
if (item->path == path)
|
||||||
return item;
|
return item;
|
||||||
}
|
}
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// #pragma mark -
|
// #pragma mark -
|
||||||
|
|
||||||
// _UpdateMarks
|
|
||||||
void
|
void
|
||||||
PathListView::_UpdateMarks()
|
PathListView::_UpdateMarks()
|
||||||
{
|
{
|
||||||
int32 count = CountItems();
|
int32 count = CountItems();
|
||||||
if (fCurrentShape) {
|
if (fCurrentShape != NULL) {
|
||||||
// enable display of marks and mark items whoes
|
// enable display of marks and mark items whoes
|
||||||
// path is contained in fCurrentShape
|
// path is contained in fCurrentShape
|
||||||
for (int32 i = 0; i < count; i++) {
|
for (int32 i = 0; i < count; i++) {
|
||||||
PathListItem* item = dynamic_cast<PathListItem*>(ItemAt(i));
|
PathListItem* item = dynamic_cast<PathListItem*>(ItemAt(i));
|
||||||
if (!item)
|
if (item == NULL)
|
||||||
continue;
|
continue;
|
||||||
item->SetMarkEnabled(true);
|
item->SetMarkEnabled(true);
|
||||||
item->SetMarked(fCurrentShape->Paths()->HasPath(item->path));
|
item->SetMarked(fCurrentShape->Paths()->HasPath(item->path));
|
||||||
@@ -853,7 +880,7 @@ PathListView::_UpdateMarks()
|
|||||||
// disable display of marks
|
// disable display of marks
|
||||||
for (int32 i = 0; i < count; i++) {
|
for (int32 i = 0; i < count; i++) {
|
||||||
PathListItem* item = dynamic_cast<PathListItem*>(ItemAt(i));
|
PathListItem* item = dynamic_cast<PathListItem*>(ItemAt(i));
|
||||||
if (!item)
|
if (item == NULL)
|
||||||
continue;
|
continue;
|
||||||
item->SetMarkEnabled(false);
|
item->SetMarkEnabled(false);
|
||||||
}
|
}
|
||||||
@@ -862,20 +889,20 @@ PathListView::_UpdateMarks()
|
|||||||
Invalidate();
|
Invalidate();
|
||||||
}
|
}
|
||||||
|
|
||||||
// _SetPathMarked
|
|
||||||
void
|
void
|
||||||
PathListView::_SetPathMarked(VectorPath* path, bool marked)
|
PathListView::_SetPathMarked(VectorPath* path, bool marked)
|
||||||
{
|
{
|
||||||
if (PathListItem* item = _ItemForPath(path)) {
|
PathListItem* item = _ItemForPath(path);
|
||||||
|
if (item != NULL)
|
||||||
item->SetMarked(marked);
|
item->SetMarked(marked);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// _UpdateMenu
|
|
||||||
void
|
void
|
||||||
PathListView::_UpdateMenu()
|
PathListView::_UpdateMenu()
|
||||||
{
|
{
|
||||||
if (!fMenu)
|
if (fMenu == NULL)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
bool gotSelection = CurrentSelection(0) >= 0;
|
bool gotSelection = CurrentSelection(0) >= 0;
|
||||||
|
|||||||
@@ -50,7 +50,7 @@ class PathListView : public SimpleListView,
|
|||||||
|
|
||||||
virtual bool AcceptDragMessage(const BMessage* message) const;
|
virtual bool AcceptDragMessage(const BMessage* message) const;
|
||||||
virtual void SetDropTargetRect(const BMessage* message,
|
virtual void SetDropTargetRect(const BMessage* message,
|
||||||
BPoint where);
|
BPoint where);
|
||||||
|
|
||||||
virtual void MoveItems(BList& items, int32 toIndex);
|
virtual void MoveItems(BList& items, int32 toIndex);
|
||||||
virtual void CopyItems(BList& items, int32 toIndex);
|
virtual void CopyItems(BList& items, int32 toIndex);
|
||||||
|
|||||||
Reference in New Issue
Block a user