* Copyright 2006, Haiku.
* Distributed under the terms of the MIT License.
*
* Authors:
* Stephan Aßmus <superstippi@gmx.de>
*/
#include "SetColorCommand.h"
#include <new>
#include <stdio.h>
#include <Catalog.h>
#include <Locale.h>
#include "GradientTransformable.h"
#include "Style.h"
#undef B_TRANSLATION_CONTEXT
#define B_TRANSLATION_CONTEXT "Icon-O-Matic-SetColorCmd"
using std::nothrow;
SetColorCommand::SetColorCommand(Style* style,
const rgb_color& color)
: Command(),
fStyle(style),
fColor(color)
{
}
SetColorCommand::~SetColorCommand()
{
}
status_t
SetColorCommand::InitCheck()
{
#ifdef __HAIKU__
return fStyle && fStyle->Color() != fColor ? B_OK : B_NO_INIT;
#else
rgb_color color = fStyle->Color();
return fStyle && *(uint32*)&color != *(uint32*)&fColor ?
B_OK : B_NO_INIT;
#endif
}
status_t
SetColorCommand::Perform()
{
rgb_color previous = fStyle->Color();
fStyle->SetColor(fColor);
fColor = previous;
return B_OK;
}
status_t
SetColorCommand::Undo()
{
return Perform();
}
void
SetColorCommand::GetName(BString& name)
{
name << B_TRANSLATE("Change color");
}
bool
SetColorCommand::CombineWithNext(const Command* command)
{
const SetColorCommand* next
= dynamic_cast<const SetColorCommand*>(command);
if (next && next->fTimeStamp - fTimeStamp < 1000000) {
fTimeStamp = next->fTimeStamp;
return true;
}
return false;
}