1 /* 2 * Copyright 2006, Haiku. 3 * Distributed under the terms of the MIT License. 4 * 5 * Authors: 6 * Stephan Aßmus <superstippi@gmx.de> 7 */ 8 9 #include "IconProperty.h" 10 11 #include <new> 12 #include <stdio.h> 13 14 #include <Message.h> 15 16 using std::nothrow; 17 18 // constructor 19 IconProperty::IconProperty(uint32 identifier, 20 const uchar* icon, 21 uint32 width, uint32 height, 22 color_space format, 23 BMessage* message) 24 : Property(identifier), 25 fMessage(message), 26 fIcon(icon), 27 fWidth(width), 28 fHeight(height), 29 fFormat(format) 30 { 31 } 32 33 // archive constructor 34 IconProperty::IconProperty(const IconProperty& other) 35 : Property(other), 36 fMessage(other.fMessage ? new BMessage(*other.fMessage) : NULL), 37 fIcon(other.fIcon), 38 fWidth(other.fWidth), 39 fHeight(other.fHeight), 40 fFormat(other.fFormat) 41 { 42 } 43 44 // archive constructor 45 IconProperty::IconProperty(BMessage* archive) 46 : Property(archive), 47 fMessage(new BMessage()) 48 { 49 if (archive->FindMessage("message", fMessage) < B_OK) { 50 delete fMessage; 51 fMessage = NULL; 52 } 53 } 54 55 // destrucor 56 IconProperty::~IconProperty() 57 { 58 delete fMessage; 59 } 60 61 // Archive 62 status_t 63 IconProperty::Archive(BMessage* into, bool deep) const 64 { 65 status_t status = Property::Archive(into, deep); 66 67 if (status >= B_OK && fMessage) 68 status = into->AddMessage("message", fMessage); 69 70 // finish off 71 if (status >= B_OK) 72 status = into->AddString("class", "IconProperty"); 73 74 return status; 75 } 76 77 // Instantiate 78 BArchivable* 79 IconProperty::Instantiate(BMessage* archive) 80 { 81 if (validate_instantiation(archive, "IconProperty")) 82 return new IconProperty(archive); 83 return NULL; 84 } 85 86 // #pragma mark - 87 88 // Clone 89 Property* 90 IconProperty::Clone() const 91 { 92 return new (nothrow) IconProperty(*this); 93 } 94 95 // SetValue 96 bool 97 IconProperty::SetValue(const char* str) 98 { 99 return false; 100 } 101 102 // SetValue 103 bool 104 IconProperty::SetValue(const Property* other) 105 { 106 const IconProperty* i = dynamic_cast<const IconProperty*>(other); 107 if (i) { 108 SetMessage(i->Message()); 109 return true; 110 } 111 return false; 112 } 113 114 // GetValue 115 void 116 IconProperty::GetValue(BString& string) 117 { 118 string << "dummy"; 119 } 120 121 // InterpolateTo 122 bool 123 IconProperty::InterpolateTo(const Property* other, float scale) 124 { 125 return false; 126 } 127 128 // #pragma mark - 129 130 // SetMessage 131 void 132 IconProperty::SetMessage(const BMessage* message) 133 { 134 if (message && fMessage) { 135 *fMessage = *message; 136 } 137 } 138 139