#include "ColorValueView.h"
#include <stdio.h>
#include <Message.h>
#include <String.h>
#include <Window.h>
#include "support_ui.h"
#include "PropertyItemView.h"
#include "SwatchValueView.h"
enum {
MSG_VALUE_CHANGED = 'vchd',
};
ColorValueView::ColorValueView(ColorProperty* property)
: PropertyEditorView(),
fProperty(property)
{
fSwatchView = new SwatchValueView("swatch property view",
NULL, this,
fProperty->Value());
fSwatchView->SetDroppedMessage(new BMessage(MSG_VALUE_CHANGED));
AddChild(fSwatchView);
}
ColorValueView::~ColorValueView()
{
}
void
ColorValueView::Draw(BRect updateRect)
{
BRect b(Bounds());
if (fSwatchView->IsFocus()) {
SetHighColor(ui_color(B_KEYBOARD_NAVIGATION_COLOR));
StrokeRect(b);
b.InsetBy(1.0, 1.0);
updateRect = updateRect & b;
}
FillRect(b, B_SOLID_LOW);
}
void
ColorValueView::FrameResized(float width, float height)
{
BRect b(Bounds());
b.InsetBy(2.0, 2.0);
b.left = floorf(b.left + (b.Width() / 2.0) - b.Height() / 2.0);
b.right = b.left + b.Height();
fSwatchView->MoveTo(b.LeftTop());
fSwatchView->ResizeTo(b.Width(), b.Height());
}
void
ColorValueView::MakeFocus(bool focused)
{
fSwatchView->MakeFocus(focused);
}
void
ColorValueView::MessageReceived(BMessage* message)
{
switch (message->what) {
case B_PASTE:
fSwatchView->MessageReceived(message);
break;
case MSG_VALUE_CHANGED: {
rgb_color c;
if (restore_color_from_message(message, c) >= B_OK
&& fProperty->SetValue(c)) {
ValueChanged();
}
break;
}
default:
PropertyEditorView::MessageReceived(message);
}
}
void
ColorValueView::SetEnabled(bool enabled)
{
}
bool
ColorValueView::IsFocused() const
{
return fSwatchView->IsFocus();
}
bool
ColorValueView::AdoptProperty(Property* property)
{
ColorProperty* p = dynamic_cast<ColorProperty*>(property);
if (p) {
rgb_color ownColor = fProperty->Value();
rgb_color color = p->Value();
if (ownColor != color) {
fSwatchView->SetColor(color);
}
fProperty = p;
return true;
}
return false;
}
Property*
ColorValueView::GetProperty() const
{
return fProperty;
}