1 /* 2 * Copyright 2006, Haiku. All rights reserved. 3 * Distributed under the terms of the MIT License. 4 * 5 * Authors: 6 * Stephan Aßmus <superstippi@gmx.de> 7 */ 8 9 #include "AssignStyleCommand.h" 10 11 #include "Shape.h" 12 #include "Style.h" 13 14 // constructor 15 AssignStyleCommand::AssignStyleCommand(Shape* shape, 16 Style* style) 17 : Command(), 18 fShape(shape), 19 fOldStyle(shape ? shape->Style() : NULL), 20 fNewStyle(style) 21 { 22 if (fOldStyle) 23 fOldStyle->Acquire(); 24 if (fNewStyle) 25 fNewStyle->Acquire(); 26 } 27 28 // destructor 29 AssignStyleCommand::~AssignStyleCommand() 30 { 31 if (fOldStyle) 32 fOldStyle->Release(); 33 if (fNewStyle) 34 fNewStyle->Release(); 35 } 36 37 // InitCheck 38 status_t 39 AssignStyleCommand::InitCheck() 40 { 41 return fShape && fNewStyle ? B_OK : B_NO_INIT; 42 } 43 44 // Perform 45 status_t 46 AssignStyleCommand::Perform() 47 { 48 fShape->SetStyle(fNewStyle); 49 50 return B_OK; 51 } 52 53 // Undo 54 status_t 55 AssignStyleCommand::Undo() 56 { 57 fShape->SetStyle(fOldStyle); 58 59 return B_OK; 60 } 61 62 // GetName 63 void 64 AssignStyleCommand::GetName(BString& name) 65 { 66 name << "Assign Style"; 67 if (fNewStyle) 68 name << " \"" << fNewStyle->Name() << "\""; 69 } 70 71