Back to index

lightning-sunbird  0.9+nobinonly
nsXFormsNodeState.cpp
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 #include "nsXFormsNodeState.h"
00041 #include "nsIEventStateManager.h"
00042 
00043 void
00044 nsXFormsNodeState::Set(PRUint16 aFlags, PRBool aVal)
00045 {
00046   if (aVal) {
00047     mState |= aFlags;
00048   } else {
00049     mState &= ~aFlags;
00050   }
00051 }
00052 
00053 nsXFormsNodeState&
00054 nsXFormsNodeState::operator&=(PRUint16 aMask)
00055 {
00056   mState &= aMask;
00057   return *this;
00058 }
00059 
00060 PRBool
00061 nsXFormsNodeState::operator==(nsXFormsNodeState& aCmp) const
00062 {
00063   return (mState == aCmp.mState) ? PR_TRUE : PR_FALSE;
00064 }
00065 
00066 PRBool
00067 nsXFormsNodeState::TestAndClear(eFlag_t aFlag)
00068 {
00069   PRUint16 test = mState & aFlag;
00070   mState &= ~aFlag;
00071   return test ? PR_TRUE : PR_FALSE;
00072 }
00073 
00074 PRBool
00075 nsXFormsNodeState::Test(eFlag_t aFlag) const
00076 {
00077   return (mState & aFlag) ? PR_TRUE : PR_FALSE;
00078 }
00079 
00080 PRUint32
00081 nsXFormsNodeState::GetIntrinsicState() const
00082 {
00083   PRUint32 state =
00084     (IsValid() ? NS_EVENT_STATE_VALID : NS_EVENT_STATE_INVALID) |
00085     (IsReadonly() ? NS_EVENT_STATE_MOZ_READONLY
00086                   : NS_EVENT_STATE_MOZ_READWRITE) |
00087     (IsRequired() ? NS_EVENT_STATE_REQUIRED : NS_EVENT_STATE_OPTIONAL) |
00088     (IsRelevant() ? NS_EVENT_STATE_ENABLED : NS_EVENT_STATE_DISABLED);
00089 
00090   return state;
00091 }
00092 
00093 #ifdef DEBUG_XF_NODESTATE
00094 const char* flagnames[] = {0,
00095                            "eFlag_READONLY",
00096                            "eFlag_CONSTRAINT",
00097                            "eFlag_RELEVANT",
00098                            "eFlag_REQUIRED",
00099                            "eFlag_VALID",
00100                            "eFlag_INHERITED_RELEVANT",
00101                            "eFlag_INHERITED_READONLY",
00102                            "eFlag_DISPATCH_VALUE_CHANGED",
00103                            "eFlag_DISPATCH_READONLY_CHANGED",
00104                            "eFlag_DISPATCH_VALID_CHANGED",
00105                            "eFlag_DISPATCH_RELEVANT_CHANGED",
00106                            "eFlag_DISPATCH_REQUIRED_CHANGED",
00107                            "eFlag_DISPATCH_CONSTRAINT_CHANGED",
00108                            0};
00109 
00110 
00111 
00112 #include <stdio.h>
00113 
00114 void
00115 nsXFormsNodeState::PrintFlags() const
00116 {
00117   int pos = 1;
00118   while (flagnames[pos]) {
00119     if (mState & (1 << pos)) {
00120       printf("\t%s\n", flagnames[pos]);
00121     }
00122     ++pos;
00123   }
00124 }
00125 #endif