Import from 1.9a8 tarball
[mozilla-extra.git] / extensions / xforms / nsXFormsNodeState.h
blob94773e859910ae00b81c3e972929f964a58dd7f4
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* ***** BEGIN LICENSE BLOCK *****
3 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
5 * The contents of this file are subject to the Mozilla Public License Version
6 * 1.1 (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 * http://www.mozilla.org/MPL/
10 * Software distributed under the License is distributed on an "AS IS" basis,
11 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 * for the specific language governing rights and limitations under the
13 * License.
15 * The Original Code is Mozilla XForms support.
17 * The Initial Developer of the Original Code is
18 * Novell, Inc.
19 * Portions created by the Initial Developer are Copyright (C) 2004
20 * the Initial Developer. All Rights Reserved.
22 * Contributor(s):
23 * Allan Beaufour <abeaufour@novell.com>
24 * David Landwehr <dlandwehr@novell.com>
26 * Alternatively, the contents of this file may be used under the terms of
27 * either the GNU General Public License Version 2 or later (the "GPL"), or
28 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
29 * in which case the provisions of the GPL or the LGPL are applicable instead
30 * of those above. If you wish to allow use of your version of this file only
31 * under the terms of either the GPL or the LGPL, and not to allow others to
32 * use your version of this file under the terms of the MPL, indicate your
33 * decision by deleting the provisions above and replace them with the notice
34 * and other provisions required by the GPL or the LGPL. If you do not delete
35 * the provisions above, a recipient may use your version of this file under
36 * the terms of any one of the MPL, the GPL or the LGPL.
38 * ***** END LICENSE BLOCK ***** */
40 #ifndef __NSXFORMSNODESTATE_H__
41 #define __NSXFORMSNODESTATE_H__
43 #include "nscore.h"
45 #ifdef DEBUG
46 //#define DEBUG_XF_NODESTATE
47 #endif
49 /** Flags used in nsXFormsNodeState */
50 enum eFlag_t {
51 // The different states
52 eFlag_READONLY = 1 << 1,
53 eFlag_CONSTRAINT = 1 << 2,
54 eFlag_CONSTRAINT_SCHEMA = 1 << 3,
55 eFlag_RELEVANT = 1 << 4,
56 eFlag_REQUIRED = 1 << 5,
57 eFlag_INHERITED_RELEVANT = 1 << 6,
58 eFlag_INHERITED_READONLY = 1 << 7,
59 // Events to be dispatched
60 eFlag_DISPATCH_VALUE_CHANGED = 1 << 8,
61 eFlag_DISPATCH_READONLY_CHANGED = 1 << 9,
62 eFlag_DISPATCH_VALID_CHANGED = 1 << 10,
63 eFlag_DISPATCH_RELEVANT_CHANGED = 1 << 11,
64 eFlag_DISPATCH_REQUIRED_CHANGED = 1 << 12,
65 eFlag_DISPATCH_CONSTRAINT_CHANGED = 1 << 13
68 // Default flags set for new states
69 const PRUint16 kFlags_DEFAULT =
70 (eFlag_CONSTRAINT | // The node is valid
71 eFlag_CONSTRAINT_SCHEMA | // The node is valid (schema)
72 eFlag_RELEVANT | // The node is relevant
73 eFlag_INHERITED_RELEVANT); // Children should inherit relevant
75 // The events dispatched for newly created models
76 const PRUint16 kFlags_INITIAL_DISPATCH =
77 (eFlag_DISPATCH_READONLY_CHANGED |
78 eFlag_DISPATCH_VALID_CHANGED |
79 eFlag_DISPATCH_RELEVANT_CHANGED |
80 eFlag_DISPATCH_REQUIRED_CHANGED);
82 // All dispatch flags
83 const PRUint16 kFlags_ALL_DISPATCH =
84 (eFlag_DISPATCH_READONLY_CHANGED |
85 eFlag_DISPATCH_VALID_CHANGED |
86 eFlag_DISPATCH_RELEVANT_CHANGED |
87 eFlag_DISPATCH_REQUIRED_CHANGED |
88 eFlag_DISPATCH_VALUE_CHANGED |
89 eFlag_DISPATCH_CONSTRAINT_CHANGED);
91 // All but dispatch flags
92 const PRUint16 kFlags_NOT_DISPATCH = ~kFlags_ALL_DISPATCH;
94 /**
95 * Holds the current state of a MDG node.
97 * That is, whether the node is readonly, relevant, etc., and also information
98 * about which events that should be dispatched to any controls bound to the
99 * node.
101 class nsXFormsNodeState
103 private:
104 /** The node state, bit vector of eFlag_t */
105 PRUint16 mState;
107 public:
109 * Constructor.
111 * @param aInitialState The initial state of this
113 nsXFormsNodeState(PRUint16 aInitialState = kFlags_DEFAULT)
114 : mState(aInitialState) {};
117 * Sets flag(s) on or off
119 * @param aFlags The flag(s) to set
120 * @param aVal The flag value
122 void Set(PRUint16 aFlags,
123 PRBool aVal);
126 * And own state with a bit mask.
128 * @param aMask Bit mask
129 * @return New value
131 nsXFormsNodeState& operator&=(PRUint16 aMask);
134 * Comparator.
136 * @param aCmp Object to compare with
137 * @return Objects equal?
139 PRBool operator==(nsXFormsNodeState& aCmp) const;
142 * Get flag state and clear flag.
144 * @param aFlag The flag
145 * @return The flag state
147 PRBool TestAndClear(eFlag_t aFlag);
150 * Get flag state
152 * @param aFlag The flag
153 * @return The flag state
155 PRBool Test(eFlag_t aFlag) const;
157 // Check states
158 PRBool IsValid() const
159 { return Test(eFlag_CONSTRAINT) &&
160 Test(eFlag_CONSTRAINT_SCHEMA); };
161 PRBool IsConstraint() const
162 { return Test(eFlag_CONSTRAINT); };
163 PRBool IsConstraintSchema() const
164 { return Test(eFlag_CONSTRAINT_SCHEMA); };
165 PRBool IsReadonly() const
166 { return Test(eFlag_READONLY) |
167 Test(eFlag_INHERITED_READONLY); };
168 PRBool IsRelevant() const
169 { return Test(eFlag_RELEVANT) &&
170 Test(eFlag_INHERITED_RELEVANT); };
171 PRBool IsRequired() const
172 { return Test(eFlag_REQUIRED); };
174 // Check events
175 PRBool ShouldDispatchReadonly() const
176 { return Test(eFlag_DISPATCH_READONLY_CHANGED); };
177 PRBool ShouldDispatchRelevant() const
178 { return Test(eFlag_DISPATCH_RELEVANT_CHANGED); };
179 PRBool ShouldDispatchValid() const
180 { return Test(eFlag_DISPATCH_VALID_CHANGED); };
181 PRBool ShouldDispatchRequired() const
182 { return Test(eFlag_DISPATCH_REQUIRED_CHANGED); };
183 PRBool ShouldDispatchValueChanged() const
184 { return Test(eFlag_DISPATCH_VALUE_CHANGED); };
186 PRUint32 GetIntrinsicState() const;
188 #ifdef DEBUG_XF_NODESTATE
189 /** Print the flags currently set to stdout */
190 void PrintFlags() const;
191 #endif
194 #endif