xref: /haiku/src/apps/icon-o-matic/generic/property/specific_properties/IconProperty.cpp (revision 0e1ba39f0440e200e30b6a648e70c3e8683dc5f7)
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
IconProperty(uint32 identifier,const uchar * icon,uint32 width,uint32 height,color_space format,BMessage * message)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
IconProperty(const IconProperty & other)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
IconProperty(BMessage * archive)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
~IconProperty()56 IconProperty::~IconProperty()
57 {
58 	delete fMessage;
59 }
60 
61 // Archive
62 status_t
Archive(BMessage * into,bool deep) const63 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*
Instantiate(BMessage * archive)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*
Clone() const90 IconProperty::Clone() const
91 {
92 	return new (nothrow) IconProperty(*this);
93 }
94 
95 // SetValue
96 bool
SetValue(const char * str)97 IconProperty::SetValue(const char* str)
98 {
99 	return false;
100 }
101 
102 // SetValue
103 bool
SetValue(const Property * other)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
GetValue(BString & string)116 IconProperty::GetValue(BString& string)
117 {
118 	string << "dummy";
119 }
120 
121 // InterpolateTo
122 bool
InterpolateTo(const Property * other,float scale)123 IconProperty::InterpolateTo(const Property* other, float scale)
124 {
125 	return false;
126 }
127 
128 // #pragma mark -
129 
130 // SetMessage
131 void
SetMessage(const BMessage * message)132 IconProperty::SetMessage(const BMessage* message)
133 {
134 	if (message && fMessage) {
135 		*fMessage = *message;
136 	}
137 }
138 
139