btrfs: Attempt to fix GCC2 build.
[haiku.git] / src / apps / icon-o-matic / shape / commands / AddPointCommand.cpp
blob1da965fc931c88c7754161093c1d684550164d0a
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 "AddPointCommand.h"
11 #include <stdio.h>
13 #include <Catalog.h>
14 #include <Locale.h>
16 #include "VectorPath.h"
19 #undef B_TRANSLATION_CONTEXT
20 #define B_TRANSLATION_CONTEXT "Icon-O-Matic-AddPointCmd"
23 // constructor
24 AddPointCommand::AddPointCommand(VectorPath* path,
25 int32 index,
26 const int32* selected,
27 int32 count)
28 : PathCommand(path),
29 fIndex(index),
30 fOldSelection(NULL),
31 fOldSelectionCount(count)
33 if (fOldSelectionCount > 0 && selected) {
34 fOldSelection = new int32[fOldSelectionCount];
35 memcpy(fOldSelection, selected, fOldSelectionCount * sizeof(int32));
39 // destructor
40 AddPointCommand::~AddPointCommand()
42 delete[] fOldSelection;
45 // Perform
46 status_t
47 AddPointCommand::Perform()
49 status_t status = InitCheck();
50 if (status < B_OK)
51 return status;
53 // path point is already added,
54 // but we don't know the parameters yet
55 if (!fPath->GetPointsAt(fIndex, fPoint, fPointIn, fPointOut))
56 status = B_NO_INIT;
58 return status;
61 // Undo
62 status_t
63 AddPointCommand::Undo()
65 status_t status = InitCheck();
66 if (status < B_OK)
67 return status;
69 // remove point
70 if (fPath->RemovePoint(fIndex)) {
71 // restore selection before adding point
72 _Select(fOldSelection, fOldSelectionCount);
73 } else {
74 status = B_ERROR;
77 return status;
80 // Redo
81 status_t
82 AddPointCommand::Redo()
84 status_t status = InitCheck();
85 if (status < B_OK)
86 return status;
88 AutoNotificationSuspender _(fPath);
90 // add point again
91 if (fPath->AddPoint(fPoint, fIndex)) {
92 fPath->SetPoint(fIndex, fPoint, fPointIn, fPointOut, true);
93 // select added point
94 _Select(&fIndex, 1);
95 } else {
96 status = B_ERROR;
99 return status;
102 // GetName
103 void
104 AddPointCommand::GetName(BString& name)
106 // name << _GetString(ADD_CONTROL_POINT, "Add Control Point");
107 name << B_TRANSLATE("Add Control Point");