Back to index

lightning-sunbird  0.9+nobinonly
nsXFormsAccessors.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) 2005
00020  * the Initial Developer. All Rights Reserved.
00021  *
00022  * Contributor(s):
00023  *  Allan Beaufour <abeaufour@novell.com>
00024  *  Olli Pettay <Olli.Pettay@helsinki.fi>
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 "nsString.h"
00041 #include "nsIDOMElement.h"
00042 #include "nsXFormsUtils.h"
00043 #include "nsXFormsAccessors.h"
00044 #include "nsDOMString.h"
00045 #include "nsIEventStateManager.h"
00046 #include "nsIContent.h"
00047 #include "nsIXFormsControl.h"
00048 #include "nsIProgrammingLanguage.h"
00049 
00050 NS_IMPL_ISUPPORTS2(nsXFormsAccessors, nsIXFormsAccessors, nsIClassInfo)
00051 
00052 void
00053 nsXFormsAccessors::Destroy()
00054 {
00055   mElement = nsnull;
00056   mDelegate = nsnull;
00057 }
00058 
00059 nsresult
00060 nsXFormsAccessors::GetState(PRInt32 aState, PRBool *aStateVal)
00061 {
00062   NS_ENSURE_ARG_POINTER(aStateVal);
00063   nsCOMPtr<nsIContent> content(do_QueryInterface(mElement));
00064   *aStateVal = (content && (content->IntrinsicState() & aState));
00065 
00066   return NS_OK;
00067 }
00068 
00069 NS_IMETHODIMP
00070 nsXFormsAccessors::GetValue(nsAString &aValue)
00071 {
00072   if (mDelegate) {
00073     mDelegate->GetValue(aValue);
00074   } else {
00075     SetDOMStringToNull(aValue);
00076   }
00077   return NS_OK;
00078 }
00079 
00080 NS_IMETHODIMP
00081 nsXFormsAccessors::SetValue(const nsAString & aValue)
00082 {
00083   return mDelegate ? mDelegate->SetValue(aValue) : NS_OK;
00084 }
00085 
00086 NS_IMETHODIMP
00087 nsXFormsAccessors::HasBoundNode(PRBool *aHasBoundNode)
00088 {
00089   NS_ENSURE_ARG_POINTER(aHasBoundNode);
00090   *aHasBoundNode = PR_FALSE;
00091   return mDelegate ? mDelegate->GetHasBoundNode(aHasBoundNode) : NS_OK;
00092 }
00093 
00094 NS_IMETHODIMP
00095 nsXFormsAccessors::IsReadonly(PRBool *aStateVal)
00096 {
00097   return GetState(NS_EVENT_STATE_MOZ_READONLY, aStateVal);
00098 }
00099 
00100 NS_IMETHODIMP
00101 nsXFormsAccessors::IsRelevant(PRBool *aStateVal)
00102 {
00103   return GetState(NS_EVENT_STATE_ENABLED, aStateVal);
00104 }
00105 
00106 NS_IMETHODIMP
00107 nsXFormsAccessors::IsRequired(PRBool *aStateVal)
00108 {
00109   return GetState(NS_EVENT_STATE_REQUIRED, aStateVal);
00110 }
00111 
00112 NS_IMETHODIMP
00113 nsXFormsAccessors::IsValid(PRBool *aStateVal)
00114 {
00115   return GetState(NS_EVENT_STATE_VALID, aStateVal);
00116 }
00117 
00118 NS_IMETHODIMP
00119 nsXFormsAccessors::SetContent(nsIDOMNode *aNode, PRBool aForceUpdate)
00120 {
00121   NS_ENSURE_STATE(mElement);
00122   NS_ENSURE_ARG(aNode);
00123 
00124   nsCOMPtr<nsIDOMNode> boundNode;
00125   nsresult rv = GetBoundNode(getter_AddRefs(boundNode));
00126   NS_ENSURE_SUCCESS(rv, rv);
00127   NS_ENSURE_STATE(boundNode);
00128 
00129   nsCOMPtr<nsIModelElementPrivate> modelPriv = nsXFormsUtils::GetModel(mElement);
00130   NS_ENSURE_STATE(modelPriv);
00131 
00132   return modelPriv->SetNodeContent(boundNode, aNode, aForceUpdate);
00133 }
00134 
00135 NS_IMETHODIMP
00136 nsXFormsAccessors::GetBoundNode(nsIDOMNode **aBoundNode)
00137 {
00138   NS_ENSURE_ARG_POINTER(aBoundNode);
00139   if (mDelegate) {
00140     nsCOMPtr<nsIXFormsControl> control = do_QueryInterface(mDelegate);
00141     return control->GetBoundNode(aBoundNode);
00142   }
00143   return NS_OK;
00144 }
00145 
00146 // nsIClassInfo implementation
00147 
00148 static const nsIID sScriptingIIDs[] = {
00149   NS_IXFORMSACCESSORS_IID
00150 };
00151 
00152 NS_IMETHODIMP
00153 nsXFormsAccessors::GetInterfaces(PRUint32 *aCount, nsIID * **aArray)
00154 {
00155   return nsXFormsUtils::CloneScriptingInterfaces(sScriptingIIDs,
00156                                                  NS_ARRAY_LENGTH(sScriptingIIDs),
00157                                                  aCount, aArray);
00158 }
00159 
00160 NS_IMETHODIMP
00161 nsXFormsAccessors::GetHelperForLanguage(PRUint32 language,
00162                                         nsISupports **_retval)
00163 {
00164   *_retval = nsnull;
00165   return NS_OK;
00166 }
00167 
00168 NS_IMETHODIMP
00169 nsXFormsAccessors::GetContractID(char * *aContractID)
00170 {
00171   *aContractID = nsnull;
00172   return NS_OK;
00173 }
00174 
00175 NS_IMETHODIMP
00176 nsXFormsAccessors::GetClassDescription(char * *aClassDescription)
00177 {
00178   *aClassDescription = nsnull;
00179   return NS_OK;
00180 }
00181 
00182 NS_IMETHODIMP
00183 nsXFormsAccessors::GetClassID(nsCID * *aClassID)
00184 {
00185   *aClassID = nsnull;
00186   return NS_OK;
00187 }
00188 
00189 NS_IMETHODIMP
00190 nsXFormsAccessors::GetImplementationLanguage(PRUint32 *aImplementationLanguage)
00191 {
00192   *aImplementationLanguage = nsIProgrammingLanguage::CPLUSPLUS;
00193   return NS_OK;
00194 }
00195 
00196 NS_IMETHODIMP
00197 nsXFormsAccessors::GetFlags(PRUint32 *aFlags)
00198 {
00199   *aFlags = nsIClassInfo::DOM_OBJECT;
00200   return NS_OK;
00201 }
00202 
00203 NS_IMETHODIMP
00204 nsXFormsAccessors::GetClassIDNoAlloc(nsCID *aClassIDNoAlloc)
00205 {
00206   return NS_ERROR_NOT_AVAILABLE;
00207 }