libroot/posix/stdio: Remove unused portions.
[haiku.git] / src / apps / icon-o-matic / style / SetGradientCommand.cpp
blobe966368bd816642e3917babbe8ae15f2dfa3ec40
1 /*
2 * Copyright 2006, Haiku.
3 * Distributed under the terms of the MIT License.
5 * Authors:
6 * Stephan Aßmus <superstippi@gmx.de>
7 */
9 #include "SetGradientCommand.h"
11 #include <new>
12 #include <stdio.h>
14 #include <Catalog.h>
15 #include <Locale.h>
17 #include "GradientTransformable.h"
18 #include "Style.h"
21 #undef B_TRANSLATION_CONTEXT
22 #define B_TRANSLATION_CONTEXT "Icon-O-Matic-SetGradientCmd"
25 using std::nothrow;
27 // constructor
28 SetGradientCommand::SetGradientCommand(Style* style,
29 const Gradient* gradient)
30 : Command(),
31 fStyle(style),
32 fGradient(gradient ? new (nothrow) Gradient(*gradient) : NULL)
36 // destructor
37 SetGradientCommand::~SetGradientCommand()
39 if (fGradient != NULL)
40 fGradient->ReleaseReference();
43 // InitCheck
44 status_t
45 SetGradientCommand::InitCheck()
47 if (!fStyle)
48 return B_NO_INIT;
49 if (fGradient && fStyle->Gradient()) {
50 if (*fGradient == *fStyle->Gradient()) {
51 printf("SetGradientCommand::InitCheck() - same gradients\n");
52 return B_ERROR;
55 return B_OK;
58 // Perform
59 status_t
60 SetGradientCommand::Perform()
62 // clone the new gradient for handling over to the style
63 Gradient* clone = NULL;
64 if (fGradient) {
65 clone = new (nothrow) Gradient(*fGradient);
66 if (!clone)
67 return B_NO_MEMORY;
70 if (fStyle->Gradient()) {
71 // remember the current gradient of the style
72 if (fGradient)
73 *fGradient = *fStyle->Gradient();
74 else {
75 fGradient = new (nothrow) Gradient(*fStyle->Gradient());
76 if (!fGradient) {
77 delete clone;
78 return B_NO_MEMORY;
81 } else if (fGradient != NULL) {
82 // the style didn't have a gradient set
83 fGradient->ReleaseReference();
84 fGradient = NULL;
87 // remove the gradient or set the new one
88 fStyle->SetGradient(clone);
89 delete clone;
91 return B_OK;
94 // Undo
95 status_t
96 SetGradientCommand::Undo()
98 return Perform();
101 // GetName
102 void
103 SetGradientCommand::GetName(BString& name)
105 name << B_TRANSLATE("Edit Gradient");
108 // CombineWithNext
109 bool
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
120 return true;
122 return false;