merge the formfield patch from ooo-build
[ooovba.git] / configmgr / source / inc / attributes.hxx
blobca5b18be4822c31321a4735c1fabd4df57dd4baf
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: attributes.hxx,v $
10 * $Revision: 1.13 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 #ifndef CONFIGMGR_CONFIGURATION_ATTRIBUTES_HXX_
32 #define CONFIGMGR_CONFIGURATION_ATTRIBUTES_HXX_
33 namespace configmgr
35 namespace node
37 enum State
39 isDefault, isToDefault = isDefault,
40 isMerged, isModification = isMerged,
41 isReplaced, isReplacement = isReplaced,
42 isAdded, isAddition = isAdded
44 enum Access
46 accessNull = 0,
47 accessWritable = 0,
48 accessFinal = 1,
49 accessReadonly = 2,
50 accessReadonlyAndFinal = 3
52 inline Access makeAccess(bool readonly, bool final)
53 { return Access( (readonly ? accessReadonly : accessNull) | (final ? accessFinal : accessNull) ); }
54 inline bool isAccessReadonly(Access access)
55 { return (access & accessReadonly) != 0; }
56 inline bool isAccessFinal(Access access)
57 { return (access & accessFinal) != 0; }
59 inline bool existsInDefault(State eState) { return eState <= isReplaced;}
60 inline bool isReplacedForUser(State eState) { return eState >= isReplaced;}
62 /// holds attributes a node in the schema
63 struct Attributes
65 Attributes()
66 : state_(node::isMerged)
67 , bReadonly(false)
68 , bFinalized(false)
69 , bNullable(true)
70 , bLocalized(false)
71 , bMandatory(false)
72 , bRemovable(false)
75 State state() const { return State(0x03 & state_); }
76 void setState(State _state) { this->state_ = _state; }
78 bool isWritable() const { return!bReadonly; }
79 bool isReadonly() const { return bReadonly; }
80 bool isFinalized() const { return bFinalized; }
82 void markReadonly() { bReadonly = true; }
84 Access getAccess() const
85 { return makeAccess(bReadonly,bFinalized); }
87 void setAccess(bool _bReadonly, bool _bFinalized)
88 { bReadonly = _bReadonly; bFinalized = _bFinalized; }
90 void setAccess(Access _aAccessLevel)
91 { setAccess( isAccessReadonly(_aAccessLevel), isAccessFinal(_aAccessLevel) ); }
93 bool isNullable() const { return bNullable; }
94 void setNullable (bool _bNullable) {bNullable = _bNullable; }
96 bool isLocalized() const { return bLocalized; }
97 void setLocalized (bool _bLocalized) {bLocalized = _bLocalized; }
99 bool isMandatory() const { return bMandatory; }
100 bool isRemovable() const { return bRemovable; }
102 void markMandatory() { bMandatory = true; }
103 void markRemovable() { bRemovable = true; }
105 void setRemovability(bool _bRemovable, bool _bMandatory)
106 { bRemovable = _bRemovable; bMandatory = _bMandatory; }
108 bool isDefault() const { return this->state() == node::isDefault;}
109 bool existsInDefault() const { return node::existsInDefault(this->state());}
110 bool isReplacedForUser() const { return node::isReplacedForUser(this->state());}
112 void markAsDefault(bool _bDefault = true)
114 if (_bDefault)
115 this->state_ = node::isDefault;
116 else if (this->isDefault())
117 this->state_ = node::isMerged;
120 private:
121 State state_ : 2; // merged/replaced/default state
123 bool bReadonly : 1; // write-protected, if true
124 bool bFinalized : 1; // can not be overridden - write protected when merged upwards
126 bool bNullable : 1; // values only: can be NULL
127 bool bLocalized : 1; // values only: value may depend on locale
129 bool bMandatory : 1; // cannot be removed/replaced in subsequent layers
130 bool bRemovable : 1; // can be removed
136 #endif