Code style cleanup
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2006-2009, 2011, Stephan Aßmus <[email protected]>.
|
* Copyright 2006-2012, Stephan Aßmus <[email protected]>.
|
||||||
* All rights reserved. Distributed under the terms of the MIT License.
|
* All rights reserved. Distributed under the terms of the MIT License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@@ -54,26 +54,25 @@ enum {
|
|||||||
|
|
||||||
class StyleListItem : public SimpleItem,
|
class StyleListItem : public SimpleItem,
|
||||||
public Observer {
|
public Observer {
|
||||||
public:
|
public:
|
||||||
StyleListItem(Style* s,
|
StyleListItem(Style* s, StyleListView* listView, bool markEnabled)
|
||||||
StyleListView* listView,
|
:
|
||||||
bool markEnabled)
|
SimpleItem(""),
|
||||||
: SimpleItem(""),
|
style(NULL),
|
||||||
style(NULL),
|
fListView(listView),
|
||||||
fListView(listView),
|
fMarkEnabled(markEnabled),
|
||||||
fMarkEnabled(markEnabled),
|
fMarked(false)
|
||||||
fMarked(false)
|
{
|
||||||
{
|
SetStyle(s);
|
||||||
SetStyle(s);
|
}
|
||||||
}
|
|
||||||
|
|
||||||
virtual ~StyleListItem()
|
virtual ~StyleListItem()
|
||||||
{
|
{
|
||||||
SetStyle(NULL);
|
SetStyle(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);
|
||||||
|
|
||||||
@@ -83,18 +82,13 @@ class StyleListItem : 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)
|
||||||
@@ -114,7 +108,7 @@ class StyleListItem : 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());
|
||||||
@@ -124,62 +118,64 @@ class StyleListItem : public SimpleItem,
|
|||||||
|
|
||||||
// Observer interface
|
// Observer interface
|
||||||
virtual void ObjectChanged(const Observable* object)
|
virtual void ObjectChanged(const Observable* object)
|
||||||
{
|
{
|
||||||
UpdateText();
|
UpdateText();
|
||||||
}
|
}
|
||||||
|
|
||||||
// StyleListItem
|
// StyleListItem
|
||||||
void SetStyle(Style* s)
|
void SetStyle(Style* s)
|
||||||
{
|
{
|
||||||
if (s == style)
|
if (s == style)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (style) {
|
if (style) {
|
||||||
style->RemoveObserver(this);
|
style->RemoveObserver(this);
|
||||||
style->Release();
|
style->Release();
|
||||||
}
|
}
|
||||||
|
|
||||||
style = s;
|
style = s;
|
||||||
|
|
||||||
if (style) {
|
if (style) {
|
||||||
style->Acquire();
|
style->Acquire();
|
||||||
style->AddObserver(this);
|
style->AddObserver(this);
|
||||||
UpdateText();
|
UpdateText();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
void UpdateText()
|
|
||||||
{
|
|
||||||
SetText(style->Name());
|
|
||||||
Invalidate();
|
|
||||||
}
|
|
||||||
|
|
||||||
void SetMarkEnabled(bool enabled)
|
void UpdateText()
|
||||||
{
|
{
|
||||||
if (fMarkEnabled == enabled)
|
SetText(style->Name());
|
||||||
return;
|
Invalidate();
|
||||||
fMarkEnabled = enabled;
|
}
|
||||||
Invalidate();
|
|
||||||
}
|
|
||||||
void SetMarked(bool marked)
|
|
||||||
{
|
|
||||||
if (fMarked == marked)
|
|
||||||
return;
|
|
||||||
fMarked = marked;
|
|
||||||
Invalidate();
|
|
||||||
}
|
|
||||||
|
|
||||||
void Invalidate()
|
void SetMarkEnabled(bool enabled)
|
||||||
{
|
{
|
||||||
// :-/
|
if (fMarkEnabled == enabled)
|
||||||
if (fListView->LockLooper()) {
|
return;
|
||||||
fListView->InvalidateItem(
|
fMarkEnabled = enabled;
|
||||||
fListView->IndexOf(this));
|
Invalidate();
|
||||||
fListView->UnlockLooper();
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Style* style;
|
void SetMarked(bool marked)
|
||||||
private:
|
{
|
||||||
|
if (fMarked == marked)
|
||||||
|
return;
|
||||||
|
fMarked = marked;
|
||||||
|
Invalidate();
|
||||||
|
}
|
||||||
|
|
||||||
|
void Invalidate()
|
||||||
|
{
|
||||||
|
if (fListView->LockLooper()) {
|
||||||
|
fListView->InvalidateItem(fListView->IndexOf(this));
|
||||||
|
fListView->UnlockLooper();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public:
|
||||||
|
Style* style;
|
||||||
|
|
||||||
|
private:
|
||||||
StyleListView* fListView;
|
StyleListView* fListView;
|
||||||
bool fMarkEnabled;
|
bool fMarkEnabled;
|
||||||
bool fMarked;
|
bool fMarked;
|
||||||
@@ -187,21 +183,28 @@ class StyleListItem : public SimpleItem,
|
|||||||
|
|
||||||
|
|
||||||
class ShapeStyleListener : public ShapeListener,
|
class ShapeStyleListener : public ShapeListener,
|
||||||
public ShapeContainerListener {
|
public ShapeContainerListener {
|
||||||
public:
|
public:
|
||||||
ShapeStyleListener(StyleListView* listView)
|
ShapeStyleListener(StyleListView* listView)
|
||||||
: fListView(listView),
|
:
|
||||||
fShape(NULL)
|
fListView(listView),
|
||||||
|
fShape(NULL)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual ~ShapeStyleListener()
|
virtual ~ShapeStyleListener()
|
||||||
{
|
{
|
||||||
SetShape(NULL);
|
SetShape(NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
// ShapeListener interface
|
// ShapeListener interface
|
||||||
virtual void TransformerAdded(Transformer* t, int32 index) {}
|
virtual void TransformerAdded(Transformer* t, int32 index)
|
||||||
virtual void TransformerRemoved(Transformer* t) {}
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual void TransformerRemoved(Transformer* t)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
virtual void StyleChanged(Style* oldStyle, Style* newStyle)
|
virtual void StyleChanged(Style* oldStyle, Style* newStyle)
|
||||||
{
|
{
|
||||||
@@ -210,7 +213,10 @@ class ShapeStyleListener : public ShapeListener,
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 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);
|
||||||
@@ -236,56 +242,58 @@ class ShapeStyleListener : public ShapeListener,
|
|||||||
return fShape;
|
return fShape;
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
StyleListView* fListView;
|
StyleListView* fListView;
|
||||||
Shape* fShape;
|
Shape* fShape;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
// #pragma mark -
|
// #pragma mark -
|
||||||
|
|
||||||
// constructor
|
|
||||||
StyleListView::StyleListView(BRect frame,
|
|
||||||
const char* name,
|
|
||||||
BMessage* message, BHandler* target)
|
|
||||||
: SimpleListView(frame, name,
|
|
||||||
NULL, B_SINGLE_SELECTION_LIST),
|
|
||||||
fMessage(message),
|
|
||||||
fStyleContainer(NULL),
|
|
||||||
fShapeContainer(NULL),
|
|
||||||
fCommandStack(NULL),
|
|
||||||
fCurrentColor(NULL),
|
|
||||||
|
|
||||||
fCurrentShape(NULL),
|
StyleListView::StyleListView(BRect frame, const char* name, BMessage* message,
|
||||||
fShapeListener(new ShapeStyleListener(this)),
|
BHandler* target)
|
||||||
|
:
|
||||||
|
SimpleListView(frame, name, NULL, B_SINGLE_SELECTION_LIST),
|
||||||
|
fMessage(message),
|
||||||
|
fStyleContainer(NULL),
|
||||||
|
fShapeContainer(NULL),
|
||||||
|
fCommandStack(NULL),
|
||||||
|
fCurrentColor(NULL),
|
||||||
|
|
||||||
fMenu(NULL)
|
fCurrentShape(NULL),
|
||||||
|
fShapeListener(new ShapeStyleListener(this)),
|
||||||
|
|
||||||
|
fMenu(NULL)
|
||||||
{
|
{
|
||||||
SetTarget(target);
|
SetTarget(target);
|
||||||
}
|
}
|
||||||
|
|
||||||
// destructor
|
|
||||||
StyleListView::~StyleListView()
|
StyleListView::~StyleListView()
|
||||||
{
|
{
|
||||||
_MakeEmpty();
|
_MakeEmpty();
|
||||||
delete fMessage;
|
delete fMessage;
|
||||||
|
|
||||||
if (fStyleContainer)
|
if (fStyleContainer != NULL)
|
||||||
fStyleContainer->RemoveListener(this);
|
fStyleContainer->RemoveListener(this);
|
||||||
|
|
||||||
if (fShapeContainer)
|
if (fShapeContainer != NULL)
|
||||||
fShapeContainer->RemoveListener(fShapeListener);
|
fShapeContainer->RemoveListener(fShapeListener);
|
||||||
|
|
||||||
delete fShapeListener;
|
delete fShapeListener;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// #pragma mark -
|
// #pragma mark -
|
||||||
|
|
||||||
// MessageReceived
|
|
||||||
void
|
void
|
||||||
StyleListView::MessageReceived(BMessage* message)
|
StyleListView::MessageReceived(BMessage* message)
|
||||||
{
|
{
|
||||||
switch (message->what) {
|
switch (message->what) {
|
||||||
case MSG_ADD: {
|
case MSG_ADD:
|
||||||
|
{
|
||||||
Style* style;
|
Style* style;
|
||||||
AddStylesCommand* command;
|
AddStylesCommand* command;
|
||||||
rgb_color color;
|
rgb_color color;
|
||||||
@@ -301,10 +309,13 @@ StyleListView::MessageReceived(BMessage* message)
|
|||||||
fCommandStack->Perform(command);
|
fCommandStack->Perform(command);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
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;
|
||||||
@@ -317,19 +328,21 @@ StyleListView::MessageReceived(BMessage* message)
|
|||||||
CopyItems(items, index + 1);
|
CopyItems(items, index + 1);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case MSG_RESET_TRANSFORMATION: {
|
|
||||||
|
case MSG_RESET_TRANSFORMATION:
|
||||||
|
{
|
||||||
int32 count = CountSelectedItems();
|
int32 count = CountSelectedItems();
|
||||||
BList gradients;
|
BList gradients;
|
||||||
for (int32 i = 0; i < count; i++) {
|
for (int32 i = 0; i < count; i++) {
|
||||||
StyleListItem* item = dynamic_cast<StyleListItem*>(
|
StyleListItem* item = dynamic_cast<StyleListItem*>(
|
||||||
ItemAt(CurrentSelection(i)));
|
ItemAt(CurrentSelection(i)));
|
||||||
if (item && item->style && item->style->Gradient())
|
if (item && item->style && item->style->Gradient()) {
|
||||||
if (!gradients.AddItem(
|
if (!gradients.AddItem((void*)item->style->Gradient()))
|
||||||
(void*)item->style->Gradient()))
|
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
count = gradients.CountItems();
|
count = gradients.CountItems();
|
||||||
if (count < 0)
|
if (count <= 0)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
Transformable* transformables[count];
|
Transformable* transformables[count];
|
||||||
@@ -338,19 +351,20 @@ StyleListView::MessageReceived(BMessage* message)
|
|||||||
transformables[i] = gradient;
|
transformables[i] = gradient;
|
||||||
}
|
}
|
||||||
|
|
||||||
ResetTransformationCommand* command =
|
ResetTransformationCommand* command
|
||||||
new ResetTransformationCommand(transformables, count);
|
= new ResetTransformationCommand(transformables, count);
|
||||||
|
|
||||||
fCommandStack->Perform(command);
|
fCommandStack->Perform(command);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
default:
|
default:
|
||||||
SimpleListView::MessageReceived(message);
|
SimpleListView::MessageReceived(message);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// SelectionChanged
|
|
||||||
void
|
void
|
||||||
StyleListView::SelectionChanged()
|
StyleListView::SelectionChanged()
|
||||||
{
|
{
|
||||||
@@ -370,11 +384,11 @@ StyleListView::SelectionChanged()
|
|||||||
_UpdateMenu();
|
_UpdateMenu();
|
||||||
}
|
}
|
||||||
|
|
||||||
// MouseDown
|
|
||||||
void
|
void
|
||||||
StyleListView::MouseDown(BPoint where)
|
StyleListView::MouseDown(BPoint where)
|
||||||
{
|
{
|
||||||
if (!fCurrentShape) {
|
if (fCurrentShape == NULL) {
|
||||||
SimpleListView::MouseDown(where);
|
SimpleListView::MouseDown(where);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -382,11 +396,10 @@ StyleListView::MouseDown(BPoint where)
|
|||||||
bool handled = false;
|
bool handled = false;
|
||||||
int32 index = IndexOf(where);
|
int32 index = IndexOf(where);
|
||||||
StyleListItem* item = dynamic_cast<StyleListItem*>(ItemAt(index));
|
StyleListItem* item = dynamic_cast<StyleListItem*>(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;
|
|
||||||
Style* style = item->style;
|
Style* style = item->style;
|
||||||
if (itemFrame.Contains(where)) {
|
if (itemFrame.Contains(where)) {
|
||||||
// set the style on the shape
|
// set the style on the shape
|
||||||
@@ -405,7 +418,7 @@ StyleListView::MouseDown(BPoint where)
|
|||||||
SimpleListView::MouseDown(where);
|
SimpleListView::MouseDown(where);
|
||||||
}
|
}
|
||||||
|
|
||||||
// MakeDragMessage
|
|
||||||
void
|
void
|
||||||
StyleListView::MakeDragMessage(BMessage* message) const
|
StyleListView::MakeDragMessage(BMessage* message) const
|
||||||
{
|
{
|
||||||
@@ -415,37 +428,37 @@ StyleListView::MakeDragMessage(BMessage* message) const
|
|||||||
for (int32 i = 0; i < count; i++) {
|
for (int32 i = 0; i < count; i++) {
|
||||||
StyleListItem* item = dynamic_cast<StyleListItem*>(
|
StyleListItem* item = dynamic_cast<StyleListItem*>(
|
||||||
ItemAt(CurrentSelection(i)));
|
ItemAt(CurrentSelection(i)));
|
||||||
if (item)
|
if (item != NULL)
|
||||||
message->AddPointer("style", (void*)item->style);
|
message->AddPointer("style", (void*)item->style);
|
||||||
else
|
else
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// AcceptDragMessage
|
|
||||||
bool
|
bool
|
||||||
StyleListView::AcceptDragMessage(const BMessage* message) const
|
StyleListView::AcceptDragMessage(const BMessage* message) const
|
||||||
{
|
{
|
||||||
return SimpleListView::AcceptDragMessage(message);
|
return SimpleListView::AcceptDragMessage(message);
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetDropTargetRect
|
|
||||||
void
|
void
|
||||||
StyleListView::SetDropTargetRect(const BMessage* message, BPoint where)
|
StyleListView::SetDropTargetRect(const BMessage* message, BPoint where)
|
||||||
{
|
{
|
||||||
SimpleListView::SetDropTargetRect(message, where);
|
SimpleListView::SetDropTargetRect(message, where);
|
||||||
}
|
}
|
||||||
|
|
||||||
// MoveItems
|
|
||||||
void
|
void
|
||||||
StyleListView::MoveItems(BList& items, int32 toIndex)
|
StyleListView::MoveItems(BList& items, int32 toIndex)
|
||||||
{
|
{
|
||||||
if (!fCommandStack || !fStyleContainer)
|
if (fCommandStack == NULL || fStyleContainer == NULL)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
int32 count = items.CountItems();
|
int32 count = items.CountItems();
|
||||||
Style** styles = new (nothrow) Style*[count];
|
Style** styles = new (nothrow) Style*[count];
|
||||||
if (!styles)
|
if (styles == NULL)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
for (int32 i = 0; i < count; i++) {
|
for (int32 i = 0; i < count; i++) {
|
||||||
@@ -454,10 +467,9 @@ StyleListView::MoveItems(BList& items, int32 toIndex)
|
|||||||
styles[i] = item ? item->style : NULL;
|
styles[i] = item ? item->style : NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
MoveStylesCommand* command
|
MoveStylesCommand* command = new (nothrow) MoveStylesCommand(
|
||||||
= new (nothrow) MoveStylesCommand(fStyleContainer,
|
fStyleContainer, styles, count, toIndex);
|
||||||
styles, count, toIndex);
|
if (command == NULL) {
|
||||||
if (!command) {
|
|
||||||
delete[] styles;
|
delete[] styles;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -465,11 +477,11 @@ StyleListView::MoveItems(BList& items, int32 toIndex)
|
|||||||
fCommandStack->Perform(command);
|
fCommandStack->Perform(command);
|
||||||
}
|
}
|
||||||
|
|
||||||
// CopyItems
|
|
||||||
void
|
void
|
||||||
StyleListView::CopyItems(BList& items, int32 toIndex)
|
StyleListView::CopyItems(BList& items, int32 toIndex)
|
||||||
{
|
{
|
||||||
if (!fCommandStack || !fStyleContainer)
|
if (fCommandStack == NULL || fStyleContainer == NULL)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
int32 count = items.CountItems();
|
int32 count = items.CountItems();
|
||||||
@@ -493,7 +505,7 @@ StyleListView::CopyItems(BList& items, int32 toIndex)
|
|||||||
fCommandStack->Perform(command);
|
fCommandStack->Perform(command);
|
||||||
}
|
}
|
||||||
|
|
||||||
// RemoveItemList
|
|
||||||
void
|
void
|
||||||
StyleListView::RemoveItemList(BList& items)
|
StyleListView::RemoveItemList(BList& items)
|
||||||
{
|
{
|
||||||
@@ -517,49 +529,49 @@ StyleListView::RemoveItemList(BList& items)
|
|||||||
fCommandStack->Perform(command);
|
fCommandStack->Perform(command);
|
||||||
}
|
}
|
||||||
|
|
||||||
// CloneItem
|
|
||||||
BListItem*
|
BListItem*
|
||||||
StyleListView::CloneItem(int32 index) const
|
StyleListView::CloneItem(int32 index) const
|
||||||
{
|
{
|
||||||
if (StyleListItem* item = dynamic_cast<StyleListItem*>(ItemAt(index))) {
|
if (StyleListItem* item = dynamic_cast<StyleListItem*>(ItemAt(index))) {
|
||||||
return new StyleListItem(item->style,
|
return new StyleListItem(item->style,
|
||||||
const_cast<StyleListView*>(this),
|
const_cast<StyleListView*>(this),
|
||||||
fCurrentShape != NULL);
|
fCurrentShape != NULL);
|
||||||
}
|
}
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
// IndexOfSelectable
|
|
||||||
int32
|
int32
|
||||||
StyleListView::IndexOfSelectable(Selectable* selectable) const
|
StyleListView::IndexOfSelectable(Selectable* selectable) const
|
||||||
{
|
{
|
||||||
Style* style = dynamic_cast<Style*>(selectable);
|
Style* style = dynamic_cast<Style*>(selectable);
|
||||||
if (!style)
|
if (style == NULL)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
for (int32 i = 0;
|
int count = CountItems();
|
||||||
StyleListItem* item = dynamic_cast<StyleListItem*>(ItemAt(i));
|
for (int32 i = 0; i < count; i++) {
|
||||||
i++) {
|
if (SelectableFor(ItemAt(i)) == style)
|
||||||
if (item->style == style)
|
|
||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// SelectableFor
|
|
||||||
Selectable*
|
Selectable*
|
||||||
StyleListView::SelectableFor(BListItem* item) const
|
StyleListView::SelectableFor(BListItem* item) const
|
||||||
{
|
{
|
||||||
StyleListItem* styleItem = dynamic_cast<StyleListItem*>(item);
|
StyleListItem* styleItem = dynamic_cast<StyleListItem*>(item);
|
||||||
if (styleItem)
|
if (styleItem != NULL)
|
||||||
return styleItem->style;
|
return styleItem->style;
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// #pragma mark -
|
// #pragma mark -
|
||||||
|
|
||||||
// StyleAdded
|
|
||||||
void
|
void
|
||||||
StyleListView::StyleAdded(Style* style, int32 index)
|
StyleListView::StyleAdded(Style* style, int32 index)
|
||||||
{
|
{
|
||||||
@@ -576,7 +588,7 @@ StyleListView::StyleAdded(Style* style, int32 index)
|
|||||||
UnlockLooper();
|
UnlockLooper();
|
||||||
}
|
}
|
||||||
|
|
||||||
// StyleRemoved
|
|
||||||
void
|
void
|
||||||
StyleListView::StyleRemoved(Style* style)
|
StyleListView::StyleRemoved(Style* style)
|
||||||
{
|
{
|
||||||
@@ -593,9 +605,10 @@ StyleListView::StyleRemoved(Style* style)
|
|||||||
UnlockLooper();
|
UnlockLooper();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// #pragma mark -
|
// #pragma mark -
|
||||||
|
|
||||||
// SetMenu
|
|
||||||
void
|
void
|
||||||
StyleListView::SetMenu(BMenu* menu)
|
StyleListView::SetMenu(BMenu* menu)
|
||||||
{
|
{
|
||||||
@@ -629,7 +642,7 @@ StyleListView::SetMenu(BMenu* menu)
|
|||||||
_UpdateMenu();
|
_UpdateMenu();
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetStyleContainer
|
|
||||||
void
|
void
|
||||||
StyleListView::SetStyleContainer(StyleContainer* container)
|
StyleListView::SetStyleContainer(StyleContainer* container)
|
||||||
{
|
{
|
||||||
@@ -637,14 +650,14 @@ StyleListView::SetStyleContainer(StyleContainer* container)
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
// detach from old container
|
// detach from old container
|
||||||
if (fStyleContainer)
|
if (fStyleContainer != NULL)
|
||||||
fStyleContainer->RemoveListener(this);
|
fStyleContainer->RemoveListener(this);
|
||||||
|
|
||||||
_MakeEmpty();
|
_MakeEmpty();
|
||||||
|
|
||||||
fStyleContainer = container;
|
fStyleContainer = container;
|
||||||
|
|
||||||
if (!fStyleContainer)
|
if (fStyleContainer == NULL)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
fStyleContainer->AddListener(this);
|
fStyleContainer->AddListener(this);
|
||||||
@@ -655,7 +668,7 @@ StyleListView::SetStyleContainer(StyleContainer* container)
|
|||||||
_AddStyle(fStyleContainer->StyleAtFast(i), i);
|
_AddStyle(fStyleContainer->StyleAtFast(i), i);
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetShapeContainer
|
|
||||||
void
|
void
|
||||||
StyleListView::SetShapeContainer(ShapeContainer* container)
|
StyleListView::SetShapeContainer(ShapeContainer* container)
|
||||||
{
|
{
|
||||||
@@ -672,21 +685,21 @@ StyleListView::SetShapeContainer(ShapeContainer* container)
|
|||||||
fShapeContainer->AddListener(fShapeListener);
|
fShapeContainer->AddListener(fShapeListener);
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetCommandStack
|
|
||||||
void
|
void
|
||||||
StyleListView::SetCommandStack(CommandStack* stack)
|
StyleListView::SetCommandStack(CommandStack* stack)
|
||||||
{
|
{
|
||||||
fCommandStack = stack;
|
fCommandStack = stack;
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetCurrentColor
|
|
||||||
void
|
void
|
||||||
StyleListView::SetCurrentColor(CurrentColor* color)
|
StyleListView::SetCurrentColor(CurrentColor* color)
|
||||||
{
|
{
|
||||||
fCurrentColor = color;
|
fCurrentColor = color;
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetCurrentShape
|
|
||||||
void
|
void
|
||||||
StyleListView::SetCurrentShape(Shape* shape)
|
StyleListView::SetCurrentShape(Shape* shape)
|
||||||
{
|
{
|
||||||
@@ -699,47 +712,51 @@ StyleListView::SetCurrentShape(Shape* shape)
|
|||||||
_UpdateMarks();
|
_UpdateMarks();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// #pragma mark -
|
// #pragma mark -
|
||||||
|
|
||||||
// _AddStyle
|
|
||||||
bool
|
bool
|
||||||
StyleListView::_AddStyle(Style* style, int32 index)
|
StyleListView::_AddStyle(Style* style, int32 index)
|
||||||
{
|
{
|
||||||
if (style) {
|
if (style != NULL) {
|
||||||
return AddItem(new StyleListItem(
|
return AddItem(new StyleListItem(
|
||||||
style, this, fCurrentShape != NULL), index);
|
style, this, fCurrentShape != NULL), index);
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// _RemoveStyle
|
|
||||||
bool
|
bool
|
||||||
StyleListView::_RemoveStyle(Style* style)
|
StyleListView::_RemoveStyle(Style* style)
|
||||||
{
|
{
|
||||||
StyleListItem* item = _ItemForStyle(style);
|
StyleListItem* item = _ItemForStyle(style);
|
||||||
if (item && RemoveItem(item)) {
|
if (item != NULL && RemoveItem(item)) {
|
||||||
delete item;
|
delete item;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// _ItemForStyle
|
|
||||||
StyleListItem*
|
StyleListItem*
|
||||||
StyleListView::_ItemForStyle(Style* style) const
|
StyleListView::_ItemForStyle(Style* style) const
|
||||||
{
|
{
|
||||||
for (int32 i = 0;
|
int count = CountItems();
|
||||||
StyleListItem* item = dynamic_cast<StyleListItem*>(ItemAt(i));
|
for (int32 i = 0; i < count; i++) {
|
||||||
i++) {
|
StyleListItem* item = dynamic_cast<StyleListItem*>(ItemAt(i));
|
||||||
|
if (item == NULL)
|
||||||
|
continue;
|
||||||
if (item->style == style)
|
if (item->style == style)
|
||||||
return item;
|
return item;
|
||||||
}
|
}
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// #pragma mark -
|
// #pragma mark -
|
||||||
|
|
||||||
// _UpdateMarks
|
|
||||||
void
|
void
|
||||||
StyleListView::_UpdateMarks()
|
StyleListView::_UpdateMarks()
|
||||||
{
|
{
|
||||||
@@ -749,7 +766,7 @@ StyleListView::_UpdateMarks()
|
|||||||
// style is contained in fCurrentShape
|
// style is contained in fCurrentShape
|
||||||
for (int32 i = 0; i < count; i++) {
|
for (int32 i = 0; i < count; i++) {
|
||||||
StyleListItem* item = dynamic_cast<StyleListItem*>(ItemAt(i));
|
StyleListItem* item = dynamic_cast<StyleListItem*>(ItemAt(i));
|
||||||
if (!item)
|
if (item == NULL)
|
||||||
continue;
|
continue;
|
||||||
item->SetMarkEnabled(true);
|
item->SetMarkEnabled(true);
|
||||||
item->SetMarked(fCurrentShape->Style() == item->style);
|
item->SetMarked(fCurrentShape->Style() == item->style);
|
||||||
@@ -758,7 +775,7 @@ StyleListView::_UpdateMarks()
|
|||||||
// disable display of marks
|
// disable display of marks
|
||||||
for (int32 i = 0; i < count; i++) {
|
for (int32 i = 0; i < count; i++) {
|
||||||
StyleListItem* item = dynamic_cast<StyleListItem*>(ItemAt(i));
|
StyleListItem* item = dynamic_cast<StyleListItem*>(ItemAt(i));
|
||||||
if (!item)
|
if (item == NULL)
|
||||||
continue;
|
continue;
|
||||||
item->SetMarkEnabled(false);
|
item->SetMarkEnabled(false);
|
||||||
}
|
}
|
||||||
@@ -767,20 +784,20 @@ StyleListView::_UpdateMarks()
|
|||||||
Invalidate();
|
Invalidate();
|
||||||
}
|
}
|
||||||
|
|
||||||
// _SetStyleMarked
|
|
||||||
void
|
void
|
||||||
StyleListView::_SetStyleMarked(Style* style, bool marked)
|
StyleListView::_SetStyleMarked(Style* style, bool marked)
|
||||||
{
|
{
|
||||||
if (StyleListItem* item = _ItemForStyle(style)) {
|
StyleListItem* item = _ItemForStyle(style);
|
||||||
|
if (item != NULL)
|
||||||
item->SetMarked(marked);
|
item->SetMarked(marked);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// _UpdateMenu
|
|
||||||
void
|
void
|
||||||
StyleListView::_UpdateMenu()
|
StyleListView::_UpdateMenu()
|
||||||
{
|
{
|
||||||
if (!fMenu)
|
if (fMenu == NULL)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
bool gotSelection = CurrentSelection(0) >= 0;
|
bool gotSelection = CurrentSelection(0) >= 0;
|
||||||
|
|||||||
Reference in New Issue
Block a user