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:
|
||||||
@@ -41,64 +41,68 @@
|
|||||||
|
|
||||||
using std::nothrow;
|
using std::nothrow;
|
||||||
|
|
||||||
class ShapeListItem : public SimpleItem,
|
class ShapeListItem : public SimpleItem, public Observer {
|
||||||
public Observer {
|
public:
|
||||||
public:
|
ShapeListItem(Shape* s, ShapeListView* listView)
|
||||||
ShapeListItem(Shape* s,
|
:
|
||||||
ShapeListView* listView)
|
SimpleItem(""),
|
||||||
: SimpleItem(""),
|
shape(NULL),
|
||||||
shape(NULL),
|
fListView(listView)
|
||||||
fListView(listView)
|
{
|
||||||
{
|
SetShape(s);
|
||||||
SetClip(s);
|
}
|
||||||
}
|
|
||||||
|
|
||||||
virtual ~ShapeListItem()
|
|
||||||
{
|
|
||||||
SetClip(NULL);
|
|
||||||
}
|
|
||||||
|
|
||||||
virtual void ObjectChanged(const Observable* object)
|
virtual ~ShapeListItem()
|
||||||
{
|
{
|
||||||
UpdateText();
|
SetShape(NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SetClip(Shape* s)
|
|
||||||
{
|
|
||||||
if (s == shape)
|
|
||||||
return;
|
|
||||||
|
|
||||||
if (shape) {
|
virtual void ObjectChanged(const Observable* object)
|
||||||
shape->RemoveObserver(this);
|
{
|
||||||
shape->Release();
|
UpdateText();
|
||||||
}
|
}
|
||||||
|
|
||||||
shape = s;
|
void SetShape(Shape* s)
|
||||||
|
{
|
||||||
|
if (s == shape)
|
||||||
|
return;
|
||||||
|
|
||||||
if (shape) {
|
if (shape) {
|
||||||
shape->Acquire();
|
shape->RemoveObserver(this);
|
||||||
shape->AddObserver(this);
|
shape->Release();
|
||||||
UpdateText();
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
void UpdateText()
|
|
||||||
{
|
|
||||||
SetText(shape->Name());
|
|
||||||
// :-/
|
|
||||||
if (fListView->LockLooper()) {
|
|
||||||
fListView->InvalidateItem(
|
|
||||||
fListView->IndexOf(this));
|
|
||||||
fListView->UnlockLooper();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
shape = s;
|
||||||
|
|
||||||
|
if (shape) {
|
||||||
|
shape->Acquire();
|
||||||
|
shape->AddObserver(this);
|
||||||
|
UpdateText();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void UpdateText()
|
||||||
|
{
|
||||||
|
SetText(shape->Name());
|
||||||
|
if (fListView->LockLooper()) {
|
||||||
|
fListView->InvalidateItem(fListView->IndexOf(this));
|
||||||
|
fListView->UnlockLooper();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public:
|
||||||
Shape* shape;
|
Shape* shape;
|
||||||
private:
|
|
||||||
|
private:
|
||||||
ShapeListView* fListView;
|
ShapeListView* fListView;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
// #pragma mark -
|
// #pragma mark -
|
||||||
|
|
||||||
|
|
||||||
enum {
|
enum {
|
||||||
MSG_REMOVE = 'rmsh',
|
MSG_REMOVE = 'rmsh',
|
||||||
MSG_DUPLICATE = 'dpsh',
|
MSG_DUPLICATE = 'dpsh',
|
||||||
@@ -108,31 +112,30 @@ enum {
|
|||||||
MSG_DRAG_SHAPE = 'drgs',
|
MSG_DRAG_SHAPE = 'drgs',
|
||||||
};
|
};
|
||||||
|
|
||||||
// constructor
|
|
||||||
ShapeListView::ShapeListView(BRect frame,
|
ShapeListView::ShapeListView(BRect frame, const char* name, BMessage* message,
|
||||||
const char* name,
|
BHandler* target)
|
||||||
BMessage* message, BHandler* target)
|
:
|
||||||
: SimpleListView(frame, name,
|
SimpleListView(frame, name, NULL, B_MULTIPLE_SELECTION_LIST),
|
||||||
NULL, B_MULTIPLE_SELECTION_LIST),
|
fMessage(message),
|
||||||
fMessage(message),
|
fShapeContainer(NULL),
|
||||||
fShapeContainer(NULL),
|
fCommandStack(NULL)
|
||||||
fCommandStack(NULL)
|
|
||||||
{
|
{
|
||||||
SetDragCommand(MSG_DRAG_SHAPE);
|
SetDragCommand(MSG_DRAG_SHAPE);
|
||||||
SetTarget(target);
|
SetTarget(target);
|
||||||
}
|
}
|
||||||
|
|
||||||
// destructor
|
|
||||||
ShapeListView::~ShapeListView()
|
ShapeListView::~ShapeListView()
|
||||||
{
|
{
|
||||||
_MakeEmpty();
|
_MakeEmpty();
|
||||||
delete fMessage;
|
delete fMessage;
|
||||||
|
|
||||||
if (fShapeContainer)
|
if (fShapeContainer != NULL)
|
||||||
fShapeContainer->RemoveListener(this);
|
fShapeContainer->RemoveListener(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
// SelectionChanged
|
|
||||||
void
|
void
|
||||||
ShapeListView::SelectionChanged()
|
ShapeListView::SelectionChanged()
|
||||||
{
|
{
|
||||||
@@ -151,7 +154,7 @@ ShapeListView::SelectionChanged()
|
|||||||
_UpdateMenu();
|
_UpdateMenu();
|
||||||
}
|
}
|
||||||
|
|
||||||
// MessageReceived
|
|
||||||
void
|
void
|
||||||
ShapeListView::MessageReceived(BMessage* message)
|
ShapeListView::MessageReceived(BMessage* message)
|
||||||
{
|
{
|
||||||
@@ -159,7 +162,9 @@ ShapeListView::MessageReceived(BMessage* message)
|
|||||||
case MSG_REMOVE:
|
case MSG_REMOVE:
|
||||||
RemoveSelected();
|
RemoveSelected();
|
||||||
break;
|
break;
|
||||||
case MSG_DUPLICATE: {
|
|
||||||
|
case MSG_DUPLICATE:
|
||||||
|
{
|
||||||
int32 count = CountSelectedItems();
|
int32 count = CountSelectedItems();
|
||||||
int32 index = 0;
|
int32 index = 0;
|
||||||
BList items;
|
BList items;
|
||||||
@@ -172,7 +177,9 @@ ShapeListView::MessageReceived(BMessage* message)
|
|||||||
CopyItems(items, index + 1);
|
CopyItems(items, index + 1);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case MSG_RESET_TRANSFORMATION: {
|
|
||||||
|
case MSG_RESET_TRANSFORMATION:
|
||||||
|
{
|
||||||
BList shapes;
|
BList shapes;
|
||||||
_GetSelectedShapes(shapes);
|
_GetSelectedShapes(shapes);
|
||||||
int32 count = shapes.CountItems();
|
int32 count = shapes.CountItems();
|
||||||
@@ -191,27 +198,30 @@ ShapeListView::MessageReceived(BMessage* message)
|
|||||||
fCommandStack->Perform(command);
|
fCommandStack->Perform(command);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case MSG_FREEZE_TRANSFORMATION: {
|
|
||||||
|
case MSG_FREEZE_TRANSFORMATION:
|
||||||
|
{
|
||||||
BList shapes;
|
BList shapes;
|
||||||
_GetSelectedShapes(shapes);
|
_GetSelectedShapes(shapes);
|
||||||
int32 count = shapes.CountItems();
|
int32 count = shapes.CountItems();
|
||||||
if (count < 0)
|
if (count < 0)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
FreezeTransformationCommand* command =
|
FreezeTransformationCommand* command
|
||||||
new FreezeTransformationCommand((Shape**)shapes.Items(),
|
= new FreezeTransformationCommand((Shape**)shapes.Items(),
|
||||||
count);
|
count);
|
||||||
|
|
||||||
fCommandStack->Perform(command);
|
fCommandStack->Perform(command);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
default:
|
default:
|
||||||
SimpleListView::MessageReceived(message);
|
SimpleListView::MessageReceived(message);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// MakeDragMessage
|
|
||||||
void
|
void
|
||||||
ShapeListView::MakeDragMessage(BMessage* message) const
|
ShapeListView::MakeDragMessage(BMessage* message) const
|
||||||
{
|
{
|
||||||
@@ -221,51 +231,40 @@ ShapeListView::MakeDragMessage(BMessage* message) const
|
|||||||
for (int32 i = 0; i < count; i++) {
|
for (int32 i = 0; i < count; i++) {
|
||||||
ShapeListItem* item = dynamic_cast<ShapeListItem*>(
|
ShapeListItem* item = dynamic_cast<ShapeListItem*>(
|
||||||
ItemAt(CurrentSelection(i)));
|
ItemAt(CurrentSelection(i)));
|
||||||
if (item)
|
if (item != NULL)
|
||||||
message->AddPointer("shape", (void*)item->shape);
|
message->AddPointer("shape", (void*)item->shape);
|
||||||
else
|
else
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
// message->AddInt32("be:actions", B_COPY_TARGET);
|
|
||||||
// message->AddInt32("be:actions", B_TRASH_TARGET);
|
|
||||||
//
|
|
||||||
// message->AddString("be:types", B_FILE_MIME_TYPE);
|
|
||||||
//// message->AddString("be:filetypes", "");
|
|
||||||
//// message->AddString("be:type_descriptions", "");
|
|
||||||
//
|
|
||||||
// message->AddString("be:clip_name", item->shape->Name());
|
|
||||||
//
|
|
||||||
// message->AddString("be:originator", "Icon-O-Matic");
|
|
||||||
// message->AddPointer("be:originator_data", (void*)item->shape);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// AcceptDragMessage
|
|
||||||
bool
|
bool
|
||||||
ShapeListView::AcceptDragMessage(const BMessage* message) const
|
ShapeListView::AcceptDragMessage(const BMessage* message) const
|
||||||
{
|
{
|
||||||
return SimpleListView::AcceptDragMessage(message);
|
return SimpleListView::AcceptDragMessage(message);
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetDropTargetRect
|
|
||||||
void
|
void
|
||||||
ShapeListView::SetDropTargetRect(const BMessage* message, BPoint where)
|
ShapeListView::SetDropTargetRect(const BMessage* message, BPoint where)
|
||||||
{
|
{
|
||||||
SimpleListView::SetDropTargetRect(message, where);
|
SimpleListView::SetDropTargetRect(message, where);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// #pragma mark -
|
// #pragma mark -
|
||||||
|
|
||||||
// MoveItems
|
|
||||||
void
|
void
|
||||||
ShapeListView::MoveItems(BList& items, int32 toIndex)
|
ShapeListView::MoveItems(BList& items, int32 toIndex)
|
||||||
{
|
{
|
||||||
if (!fCommandStack || !fShapeContainer)
|
if (fCommandStack == NULL || fShapeContainer == NULL)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
int32 count = items.CountItems();
|
int32 count = items.CountItems();
|
||||||
Shape** shapes = new (nothrow) Shape*[count];
|
Shape** shapes = new(nothrow) Shape*[count];
|
||||||
if (!shapes)
|
if (shapes == NULL)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
for (int32 i = 0; i < count; i++) {
|
for (int32 i = 0; i < count; i++) {
|
||||||
@@ -274,10 +273,9 @@ ShapeListView::MoveItems(BList& items, int32 toIndex)
|
|||||||
shapes[i] = item ? item->shape : NULL;
|
shapes[i] = item ? item->shape : NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
MoveShapesCommand* command
|
MoveShapesCommand* command = new (nothrow) MoveShapesCommand(
|
||||||
= new (nothrow) MoveShapesCommand(fShapeContainer,
|
fShapeContainer, shapes, count, toIndex);
|
||||||
shapes, count, toIndex);
|
if (command == NULL) {
|
||||||
if (!command) {
|
|
||||||
delete[] shapes;
|
delete[] shapes;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -289,7 +287,7 @@ ShapeListView::MoveItems(BList& items, int32 toIndex)
|
|||||||
void
|
void
|
||||||
ShapeListView::CopyItems(BList& items, int32 toIndex)
|
ShapeListView::CopyItems(BList& items, int32 toIndex)
|
||||||
{
|
{
|
||||||
if (!fCommandStack || !fShapeContainer)
|
if (fCommandStack == NULL || fShapeContainer == NULL)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
int32 count = items.CountItems();
|
int32 count = items.CountItems();
|
||||||
@@ -298,14 +296,12 @@ ShapeListView::CopyItems(BList& items, int32 toIndex)
|
|||||||
for (int32 i = 0; i < count; i++) {
|
for (int32 i = 0; i < count; i++) {
|
||||||
ShapeListItem* item
|
ShapeListItem* item
|
||||||
= dynamic_cast<ShapeListItem*>((BListItem*)items.ItemAtFast(i));
|
= dynamic_cast<ShapeListItem*>((BListItem*)items.ItemAtFast(i));
|
||||||
shapes[i] = item ? new (nothrow) Shape(*item->shape) : NULL;
|
shapes[i] = item ? new(nothrow) Shape(*item->shape) : NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
AddShapesCommand* command
|
AddShapesCommand* command = new(nothrow) AddShapesCommand(fShapeContainer,
|
||||||
= new (nothrow) AddShapesCommand(fShapeContainer,
|
shapes, count, toIndex, fSelection);
|
||||||
shapes, count, toIndex,
|
if (command == NULL) {
|
||||||
fSelection);
|
|
||||||
if (!command) {
|
|
||||||
for (int32 i = 0; i < count; i++)
|
for (int32 i = 0; i < count; i++)
|
||||||
delete shapes[i];
|
delete shapes[i];
|
||||||
return;
|
return;
|
||||||
@@ -314,11 +310,11 @@ ShapeListView::CopyItems(BList& items, int32 toIndex)
|
|||||||
fCommandStack->Perform(command);
|
fCommandStack->Perform(command);
|
||||||
}
|
}
|
||||||
|
|
||||||
// RemoveItemList
|
|
||||||
void
|
void
|
||||||
ShapeListView::RemoveItemList(BList& items)
|
ShapeListView::RemoveItemList(BList& items)
|
||||||
{
|
{
|
||||||
if (!fCommandStack || !fShapeContainer)
|
if (fCommandStack == NULL || fShapeContainer == NULL)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
int32 count = items.CountItems();
|
int32 count = items.CountItems();
|
||||||
@@ -326,43 +322,44 @@ ShapeListView::RemoveItemList(BList& items)
|
|||||||
for (int32 i = 0; i < count; i++)
|
for (int32 i = 0; i < count; i++)
|
||||||
indices[i] = IndexOf((BListItem*)items.ItemAtFast(i));
|
indices[i] = IndexOf((BListItem*)items.ItemAtFast(i));
|
||||||
|
|
||||||
RemoveShapesCommand* command
|
RemoveShapesCommand* command = new(nothrow) RemoveShapesCommand(
|
||||||
= new (nothrow) RemoveShapesCommand(fShapeContainer,
|
fShapeContainer, indices, count);
|
||||||
indices, count);
|
|
||||||
fCommandStack->Perform(command);
|
fCommandStack->Perform(command);
|
||||||
}
|
}
|
||||||
|
|
||||||
// CloneItem
|
|
||||||
BListItem*
|
BListItem*
|
||||||
ShapeListView::CloneItem(int32 index) const
|
ShapeListView::CloneItem(int32 index) const
|
||||||
{
|
{
|
||||||
if (ShapeListItem* item = dynamic_cast<ShapeListItem*>(ItemAt(index))) {
|
ShapeListItem* item = dynamic_cast<ShapeListItem*>(ItemAt(index));
|
||||||
|
if (item != NULL) {
|
||||||
return new ShapeListItem(item->shape,
|
return new ShapeListItem(item->shape,
|
||||||
const_cast<ShapeListView*>(this));
|
const_cast<ShapeListView*>(this));
|
||||||
}
|
}
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
// IndexOfSelectable
|
|
||||||
int32
|
int32
|
||||||
ShapeListView::IndexOfSelectable(Selectable* selectable) const
|
ShapeListView::IndexOfSelectable(Selectable* selectable) const
|
||||||
{
|
{
|
||||||
Shape* shape = dynamic_cast<Shape*>(selectable);
|
Shape* shape = dynamic_cast<Shape*>(selectable);
|
||||||
if (!shape) {
|
if (shape == NULL) {
|
||||||
Transformer* transformer = dynamic_cast<Transformer*>(selectable);
|
Transformer* transformer = dynamic_cast<Transformer*>(selectable);
|
||||||
if (!transformer)
|
if (transformer == NULL)
|
||||||
return -1;
|
return -1;
|
||||||
for (int32 i = 0;
|
int32 count = CountItems();
|
||||||
ShapeListItem* item = dynamic_cast<ShapeListItem*>(ItemAt(i));
|
for (int32 i = 0; i < count; i++) {
|
||||||
i++) {
|
ShapeListItem* item = dynamic_cast<ShapeListItem*>(ItemAt(i));
|
||||||
if (item->shape->HasTransformer(transformer))
|
if (item != NULL && item->shape->HasTransformer(transformer))
|
||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
for (int32 i = 0;
|
int32 count = CountItems();
|
||||||
ShapeListItem* item = dynamic_cast<ShapeListItem*>(ItemAt(i));
|
for (int32 i = 0; i < count; i++) {
|
||||||
i++) {
|
ShapeListItem* item = dynamic_cast<ShapeListItem*>(ItemAt(i));
|
||||||
if (item->shape == shape)
|
if (item != NULL && item->shape == shape)
|
||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -370,19 +367,20 @@ ShapeListView::IndexOfSelectable(Selectable* selectable) const
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// SelectableFor
|
|
||||||
Selectable*
|
Selectable*
|
||||||
ShapeListView::SelectableFor(BListItem* item) const
|
ShapeListView::SelectableFor(BListItem* item) const
|
||||||
{
|
{
|
||||||
ShapeListItem* shapeItem = dynamic_cast<ShapeListItem*>(item);
|
ShapeListItem* shapeItem = dynamic_cast<ShapeListItem*>(item);
|
||||||
if (shapeItem)
|
if (shapeItem != NULL)
|
||||||
return shapeItem->shape;
|
return shapeItem->shape;
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// #pragma mark -
|
// #pragma mark -
|
||||||
|
|
||||||
// ShapeAdded
|
|
||||||
void
|
void
|
||||||
ShapeListView::ShapeAdded(Shape* shape, int32 index)
|
ShapeListView::ShapeAdded(Shape* shape, int32 index)
|
||||||
{
|
{
|
||||||
@@ -399,7 +397,7 @@ ShapeListView::ShapeAdded(Shape* shape, int32 index)
|
|||||||
UnlockLooper();
|
UnlockLooper();
|
||||||
}
|
}
|
||||||
|
|
||||||
// ShapeRemoved
|
|
||||||
void
|
void
|
||||||
ShapeListView::ShapeRemoved(Shape* shape)
|
ShapeListView::ShapeRemoved(Shape* shape)
|
||||||
{
|
{
|
||||||
@@ -416,9 +414,10 @@ ShapeListView::ShapeRemoved(Shape* shape)
|
|||||||
UnlockLooper();
|
UnlockLooper();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// #pragma mark -
|
// #pragma mark -
|
||||||
|
|
||||||
// SetMenu
|
|
||||||
void
|
void
|
||||||
ShapeListView::SetMenu(BMenu* menu)
|
ShapeListView::SetMenu(BMenu* menu)
|
||||||
{
|
{
|
||||||
@@ -426,6 +425,7 @@ ShapeListView::SetMenu(BMenu* menu)
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
fMenu = menu;
|
fMenu = menu;
|
||||||
|
|
||||||
if (fMenu == NULL)
|
if (fMenu == NULL)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@@ -480,7 +480,7 @@ ShapeListView::SetMenu(BMenu* menu)
|
|||||||
_UpdateMenu();
|
_UpdateMenu();
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetShapeContainer
|
|
||||||
void
|
void
|
||||||
ShapeListView::SetShapeContainer(ShapeContainer* container)
|
ShapeListView::SetShapeContainer(ShapeContainer* container)
|
||||||
{
|
{
|
||||||
@@ -488,14 +488,14 @@ ShapeListView::SetShapeContainer(ShapeContainer* container)
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
// detach from old container
|
// detach from old container
|
||||||
if (fShapeContainer)
|
if (fShapeContainer != NULL)
|
||||||
fShapeContainer->RemoveListener(this);
|
fShapeContainer->RemoveListener(this);
|
||||||
|
|
||||||
_MakeEmpty();
|
_MakeEmpty();
|
||||||
|
|
||||||
fShapeContainer = container;
|
fShapeContainer = container;
|
||||||
|
|
||||||
if (!fShapeContainer)
|
if (fShapeContainer == NULL)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
fShapeContainer->AddListener(this);
|
fShapeContainer->AddListener(this);
|
||||||
@@ -506,54 +506,65 @@ ShapeListView::SetShapeContainer(ShapeContainer* container)
|
|||||||
_AddShape(fShapeContainer->ShapeAtFast(i), i);
|
_AddShape(fShapeContainer->ShapeAtFast(i), i);
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetCommandStack
|
|
||||||
void
|
void
|
||||||
ShapeListView::SetCommandStack(CommandStack* stack)
|
ShapeListView::SetCommandStack(CommandStack* stack)
|
||||||
{
|
{
|
||||||
fCommandStack = stack;
|
fCommandStack = stack;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// #pragma mark -
|
// #pragma mark -
|
||||||
|
|
||||||
// _AddShape
|
|
||||||
bool
|
bool
|
||||||
ShapeListView::_AddShape(Shape* shape, int32 index)
|
ShapeListView::_AddShape(Shape* shape, int32 index)
|
||||||
{
|
{
|
||||||
if (shape)
|
if (shape == NULL)
|
||||||
return AddItem(new ShapeListItem(shape, this), index);
|
return false;
|
||||||
return false;
|
|
||||||
|
ShapeListItem* item = new(std::nothrow) ShapeListItem(shape, this);
|
||||||
|
if (item == NULL)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
if (!AddItem(item, index)) {
|
||||||
|
delete item;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// _RemoveShape
|
|
||||||
bool
|
bool
|
||||||
ShapeListView::_RemoveShape(Shape* shape)
|
ShapeListView::_RemoveShape(Shape* shape)
|
||||||
{
|
{
|
||||||
ShapeListItem* item = _ItemForShape(shape);
|
ShapeListItem* item = _ItemForShape(shape);
|
||||||
if (item && RemoveItem(item)) {
|
if (item != NULL && RemoveItem(item)) {
|
||||||
delete item;
|
delete item;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// _ItemForShape
|
|
||||||
ShapeListItem*
|
ShapeListItem*
|
||||||
ShapeListView::_ItemForShape(Shape* shape) const
|
ShapeListView::_ItemForShape(Shape* shape) const
|
||||||
{
|
{
|
||||||
for (int32 i = 0;
|
int32 count = CountItems();
|
||||||
ShapeListItem* item = dynamic_cast<ShapeListItem*>(ItemAt(i));
|
for (int32 i = 0; i < count; i++) {
|
||||||
i++) {
|
ShapeListItem* item = dynamic_cast<ShapeListItem*>(ItemAt(i));
|
||||||
if (item->shape == shape)
|
if (item != NULL && item->shape == shape)
|
||||||
return item;
|
return item;
|
||||||
}
|
}
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
// _UpdateMenu
|
|
||||||
void
|
void
|
||||||
ShapeListView::_UpdateMenu()
|
ShapeListView::_UpdateMenu()
|
||||||
{
|
{
|
||||||
if (!fMenu)
|
if (fMenu == NULL)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
bool gotSelection = CurrentSelection(0) >= 0;
|
bool gotSelection = CurrentSelection(0) >= 0;
|
||||||
@@ -564,7 +575,7 @@ ShapeListView::_UpdateMenu()
|
|||||||
fRemoveMI->SetEnabled(gotSelection);
|
fRemoveMI->SetEnabled(gotSelection);
|
||||||
}
|
}
|
||||||
|
|
||||||
// _GetSelectedShapes
|
|
||||||
void
|
void
|
||||||
ShapeListView::_GetSelectedShapes(BList& shapes) const
|
ShapeListView::_GetSelectedShapes(BList& shapes) const
|
||||||
{
|
{
|
||||||
@@ -572,7 +583,7 @@ ShapeListView::_GetSelectedShapes(BList& shapes) const
|
|||||||
for (int32 i = 0; i < count; i++) {
|
for (int32 i = 0; i < count; i++) {
|
||||||
ShapeListItem* item = dynamic_cast<ShapeListItem*>(
|
ShapeListItem* item = dynamic_cast<ShapeListItem*>(
|
||||||
ItemAt(CurrentSelection(i)));
|
ItemAt(CurrentSelection(i)));
|
||||||
if (item && item->shape) {
|
if (item != NULL && item->shape != NULL) {
|
||||||
if (!shapes.AddItem((void*)item->shape))
|
if (!shapes.AddItem((void*)item->shape))
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user