2009-11-13 Jeffrey Stedfast <fejj@novell.com>
[moon.git] / src / style.cpp
blobb05c7a6c0a67c2450c9755d6efd32145500840bc
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
2 /*
3 * style.cpp:
5 * Contact:
6 * Moonlight List (moonlight-list@lists.ximian.com)
8 * Copyright 2008 Novell, Inc. (http://www.novell.com)
10 * See the LICENSE file included with the distribution for details.
15 #include <config.h>
16 #include "style.h"
17 #include "error.h"
18 #include "deployment.h"
21 // Style
24 Style::Style ()
26 SetObjectType (Type::STYLE);
29 Style::~Style ()
33 void
34 Style::Seal ()
36 SetIsSealed (true);
37 GetSetters ()->Seal ();
42 // SetterBaseCollection
45 SetterBaseCollection::SetterBaseCollection ()
47 SetObjectType (Type::SETTERBASE_COLLECTION);
50 void
51 SetterBaseCollection::Seal ()
53 SetIsSealed (true);
54 CollectionIterator *iter = GetIterator ();
56 int error = 0;
57 Value *current;
58 Types *types = Deployment::GetCurrent ()->GetTypes ();
60 while (iter->Next () && (current = iter->GetCurrent (&error))) {
61 SetterBase *setter = current->AsSetterBase (types);
62 setter->Seal ();
65 delete iter;
68 bool
69 SetterBaseCollection::AddedToCollection (Value *value, MoonError *error)
71 if (!value || !ValidateSetter (value, error))
72 return false;
74 SetterBase *setter = value->AsSetterBase ();
75 setter->SetAttached (true);
76 setter->Seal ();
78 return DependencyObjectCollection::AddedToCollection (value, error);
81 void
82 SetterBaseCollection::RemovedFromCollection (Value *value)
84 value->AsSetterBase ()->SetAttached (false);
85 DependencyObjectCollection::RemovedFromCollection (value);
88 bool
89 SetterBaseCollection::ValidateSetter (Value *value, MoonError *error)
91 Types *types = Deployment::GetCurrent ()->GetTypes ();
93 if (types->IsSubclassOf (value->GetKind (), Type::SETTER)) {
94 Setter *s = value->AsSetter (types);
95 if (!s->GetValue (Setter::PropertyProperty)) {
96 MoonError::FillIn (error, MoonError::EXCEPTION, "Cannot have a null target property");
97 return false;
101 if (types->IsSubclassOf (value->GetKind (), Type::SETTERBASE)) {
102 SetterBase *s = value->AsSetterBase (types);
103 if (s->GetAttached ()) {
104 MoonError::FillIn (error, MoonError::INVALID_OPERATION, "Setter is currently attached to another style");
105 return false;
109 if (GetIsSealed ()) {
110 MoonError::FillIn (error, MoonError::EXCEPTION, "Cannot add a setter to a sealed style");
111 return false;
114 return true;
119 // SetterBase
122 SetterBase::SetterBase ()
124 SetObjectType (Type::SETTERBASE);
125 attached = false;
128 void
129 SetterBase::Seal ()
131 if (GetIsSealed ())
132 return;
133 SetIsSealed (true);
136 bool
137 SetterBase::GetAttached ()
139 return attached;
142 void
143 SetterBase::SetAttached (bool value)
145 attached = value;
150 // Setter
153 Setter::Setter ()
155 SetObjectType (Type::SETTER);
158 Setter::~Setter ()