2 * Copyright 2006, Haiku.
3 * Distributed under the terms of the MIT License.
6 * Stephan Aßmus <superstippi@gmx.de>
9 #include "SetGradientCommand.h"
17 #include "GradientTransformable.h"
21 #undef B_TRANSLATION_CONTEXT
22 #define B_TRANSLATION_CONTEXT "Icon-O-Matic-SetGradientCmd"
28 SetGradientCommand::SetGradientCommand(Style
* style
,
29 const Gradient
* gradient
)
32 fGradient(gradient
? new (nothrow
) Gradient(*gradient
) : NULL
)
37 SetGradientCommand::~SetGradientCommand()
39 if (fGradient
!= NULL
)
40 fGradient
->ReleaseReference();
45 SetGradientCommand::InitCheck()
49 if (fGradient
&& fStyle
->Gradient()) {
50 if (*fGradient
== *fStyle
->Gradient()) {
51 printf("SetGradientCommand::InitCheck() - same gradients\n");
60 SetGradientCommand::Perform()
62 // clone the new gradient for handling over to the style
63 Gradient
* clone
= NULL
;
65 clone
= new (nothrow
) Gradient(*fGradient
);
70 if (fStyle
->Gradient()) {
71 // remember the current gradient of the style
73 *fGradient
= *fStyle
->Gradient();
75 fGradient
= new (nothrow
) Gradient(*fStyle
->Gradient());
81 } else if (fGradient
!= NULL
) {
82 // the style didn't have a gradient set
83 fGradient
->ReleaseReference();
87 // remove the gradient or set the new one
88 fStyle
->SetGradient(clone
);
96 SetGradientCommand::Undo()
103 SetGradientCommand::GetName(BString
& name
)
105 name
<< B_TRANSLATE("Edit Gradient");
110 SetGradientCommand::CombineWithNext(const Command
* command
)
112 const SetGradientCommand
* next
113 = dynamic_cast<const SetGradientCommand
*>(command
);
115 if (next
&& next
->fTimeStamp
- fTimeStamp
< 1000000) {
116 fTimeStamp
= next
->fTimeStamp
;
117 // NOTE: next was already performed, but
118 // when undoing, we want to use our
119 // remembered gradient