Back to index

lightning-sunbird  0.9+nobinonly
nsXFormsNodeState.h
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
00002 /* ***** BEGIN LICENSE BLOCK *****
00003  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00004  *
00005  * The contents of this file are subject to the Mozilla Public License Version
00006  * 1.1 (the "License"); you may not use this file except in compliance with
00007  * the License. You may obtain a copy of the License at
00008  * http://www.mozilla.org/MPL/
00009  *
00010  * Software distributed under the License is distributed on an "AS IS" basis,
00011  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00012  * for the specific language governing rights and limitations under the
00013  * License.
00014  *
00015  * The Original Code is Mozilla XForms support.
00016  *
00017  * The Initial Developer of the Original Code is
00018  * Novell, Inc.
00019  * Portions created by the Initial Developer are Copyright (C) 2004
00020  * the Initial Developer. All Rights Reserved.
00021  *
00022  * Contributor(s):
00023  *  Allan Beaufour <abeaufour@novell.com>
00024  *  David Landwehr <dlandwehr@novell.com>
00025  *
00026  * Alternatively, the contents of this file may be used under the terms of
00027  * either the GNU General Public License Version 2 or later (the "GPL"), or
00028  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00029  * in which case the provisions of the GPL or the LGPL are applicable instead
00030  * of those above. If you wish to allow use of your version of this file only
00031  * under the terms of either the GPL or the LGPL, and not to allow others to
00032  * use your version of this file under the terms of the MPL, indicate your
00033  * decision by deleting the provisions above and replace them with the notice
00034  * and other provisions required by the GPL or the LGPL. If you do not delete
00035  * the provisions above, a recipient may use your version of this file under
00036  * the terms of any one of the MPL, the GPL or the LGPL.
00037  *
00038  * ***** END LICENSE BLOCK ***** */
00039 
00040 #ifndef __NSXFORMSNODESTATE_H__
00041 #define __NSXFORMSNODESTATE_H__
00042 
00043 #include "nscore.h"
00044 
00045 #ifdef DEBUG
00046 //#define DEBUG_XF_NODESTATE
00047 #endif
00048 
00050 enum eFlag_t {
00051   // The different states
00052   eFlag_READONLY                    = 1 << 1,
00053   eFlag_CONSTRAINT                  = 1 << 2,
00054   eFlag_CONSTRAINT_SCHEMA           = 1 << 3,
00055   eFlag_RELEVANT                    = 1 << 4,
00056   eFlag_REQUIRED                    = 1 << 5,
00057   eFlag_INHERITED_RELEVANT          = 1 << 6,
00058   eFlag_INHERITED_READONLY          = 1 << 7,
00059   // Events to be dispatched
00060   eFlag_DISPATCH_VALUE_CHANGED      = 1 << 8,
00061   eFlag_DISPATCH_READONLY_CHANGED   = 1 << 9,
00062   eFlag_DISPATCH_VALID_CHANGED      = 1 << 10,
00063   eFlag_DISPATCH_RELEVANT_CHANGED   = 1 << 11,
00064   eFlag_DISPATCH_REQUIRED_CHANGED   = 1 << 12,
00065   eFlag_DISPATCH_CONSTRAINT_CHANGED = 1 << 13
00066 };
00067 
00068 // Default flags set for new states
00069 const PRUint16 kFlags_DEFAULT =
00070   (eFlag_CONSTRAINT         | // The node is valid
00071    eFlag_CONSTRAINT_SCHEMA  | // The node is valid (schema)
00072    eFlag_RELEVANT           | // The node is relevant
00073    eFlag_INHERITED_RELEVANT); // Children should inherit relevant
00074 
00075 // The events dispatched for newly created models
00076 const PRUint16 kFlags_INITIAL_DISPATCH =
00077   (eFlag_DISPATCH_READONLY_CHANGED |
00078    eFlag_DISPATCH_VALID_CHANGED    |
00079    eFlag_DISPATCH_RELEVANT_CHANGED |
00080    eFlag_DISPATCH_REQUIRED_CHANGED);
00081 
00082 // All dispatch flags
00083 const PRUint16 kFlags_ALL_DISPATCH =
00084   (eFlag_DISPATCH_READONLY_CHANGED   |
00085    eFlag_DISPATCH_VALID_CHANGED      |
00086    eFlag_DISPATCH_RELEVANT_CHANGED   |
00087    eFlag_DISPATCH_REQUIRED_CHANGED   |
00088    eFlag_DISPATCH_VALUE_CHANGED      |
00089    eFlag_DISPATCH_CONSTRAINT_CHANGED);
00090 
00091 // All but dispatch flags
00092 const PRUint16 kFlags_NOT_DISPATCH = ~kFlags_ALL_DISPATCH;
00093 
00101 class nsXFormsNodeState
00102 {
00103 private:
00105   PRUint16 mState;
00106   
00107 public:
00113   nsXFormsNodeState(PRUint16 aInitialState = kFlags_DEFAULT)
00114     : mState(aInitialState) {};
00115 
00122   void Set(PRUint16 aFlags,
00123            PRBool   aVal);
00124 
00131   nsXFormsNodeState& operator&=(PRUint16 aMask);
00132   
00139   PRBool operator==(nsXFormsNodeState& aCmp) const;
00140 
00147   PRBool TestAndClear(eFlag_t aFlag);
00148 
00155   PRBool Test(eFlag_t aFlag) const; 
00156 
00157   // Check states
00158   PRBool IsValid() const
00159     { return Test(eFlag_CONSTRAINT) &&
00160              Test(eFlag_CONSTRAINT_SCHEMA); };
00161   PRBool IsConstraint() const
00162     { return Test(eFlag_CONSTRAINT); };
00163   PRBool IsConstraintSchema() const
00164     { return Test(eFlag_CONSTRAINT_SCHEMA); };
00165   PRBool IsReadonly() const
00166     { return Test(eFlag_READONLY) |
00167              Test(eFlag_INHERITED_READONLY); };
00168   PRBool IsRelevant() const
00169     { return Test(eFlag_RELEVANT) &&
00170              Test(eFlag_INHERITED_RELEVANT); };
00171   PRBool IsRequired() const
00172     { return Test(eFlag_REQUIRED); };
00173 
00174   // Check events
00175   PRBool ShouldDispatchReadonly() const
00176     { return Test(eFlag_DISPATCH_READONLY_CHANGED); };
00177   PRBool ShouldDispatchRelevant() const
00178     { return Test(eFlag_DISPATCH_RELEVANT_CHANGED); };
00179   PRBool ShouldDispatchValid() const
00180     { return Test(eFlag_DISPATCH_VALID_CHANGED); };
00181   PRBool ShouldDispatchRequired() const
00182     { return Test(eFlag_DISPATCH_REQUIRED_CHANGED); };
00183   PRBool ShouldDispatchValueChanged() const
00184     { return Test(eFlag_DISPATCH_VALUE_CHANGED); };
00185 
00186   PRUint32 GetIntrinsicState() const;
00187 
00188 #ifdef DEBUG_XF_NODESTATE
00189 
00190   void PrintFlags() const;
00191 #endif
00192 };
00193 
00194 #endif