2004-12-15 05:08:53 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
|
|
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
|
|
|
*
|
|
|
|
* The contents of this file are subject to the Mozilla Public License Version
|
|
|
|
* 1.1 (the "License"); you may not use this file except in compliance with
|
|
|
|
* the License. You may obtain a copy of the License at
|
|
|
|
* http://www.mozilla.org/MPL/
|
|
|
|
*
|
|
|
|
* Software distributed under the License is distributed on an "AS IS" basis,
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
|
|
|
* for the specific language governing rights and limitations under the
|
|
|
|
* License.
|
|
|
|
*
|
|
|
|
* The Original Code is Mozilla XForms support.
|
|
|
|
*
|
|
|
|
* The Initial Developer of the Original Code is
|
|
|
|
* Olli Pettay.
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 2004
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
|
|
|
* Olli Pettay <Olli.Pettay@helsinki.fi> (original author)
|
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
|
|
|
* either of the GNU General Public License Version 2 or later (the "GPL"),
|
|
|
|
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
|
|
|
* in which case the provisions of the GPL or the LGPL are applicable instead
|
|
|
|
* of those above. If you wish to allow use of your version of this file only
|
|
|
|
* under the terms of either the GPL or the LGPL, and not to allow others to
|
|
|
|
* use your version of this file under the terms of the MPL, indicate your
|
|
|
|
* decision by deleting the provisions above and replace them with the notice
|
|
|
|
* and other provisions required by the GPL or the LGPL. If you do not delete
|
|
|
|
* the provisions above, a recipient may use your version of this file under
|
|
|
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
|
|
|
|
|
|
|
#include "nsXFormsStubElement.h"
|
|
|
|
#include "nsXFormsAtoms.h"
|
|
|
|
#include "nsXFormsUtils.h"
|
|
|
|
#include "nsIXFormsCaseElement.h"
|
2005-08-09 23:17:18 +04:00
|
|
|
#include "nsIXFormsCaseUIElement.h"
|
|
|
|
#include "nsIXFormsSwitchElement.h"
|
2004-12-15 05:08:53 +03:00
|
|
|
#include "nsCOMPtr.h"
|
|
|
|
#include "nsIDOMElement.h"
|
|
|
|
#include "nsString.h"
|
2005-08-09 23:17:18 +04:00
|
|
|
#include "nsIXTFBindableElementWrapper.h"
|
2004-12-15 05:08:53 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Implementation of the XForms case element.
|
|
|
|
*/
|
|
|
|
|
2005-08-09 23:17:18 +04:00
|
|
|
class nsXFormsCaseElement : public nsXFormsBindableStub,
|
|
|
|
public nsIXFormsCaseElement
|
2004-12-15 05:08:53 +03:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
NS_DECL_ISUPPORTS_INHERITED
|
2005-08-09 23:17:18 +04:00
|
|
|
NS_DECL_NSIXFORMSCASEELEMENT
|
2004-12-15 05:08:53 +03:00
|
|
|
|
2005-08-09 23:17:18 +04:00
|
|
|
NS_IMETHOD OnCreated(nsIXTFBindableElementWrapper *aWrapper);
|
2004-12-15 05:08:53 +03:00
|
|
|
NS_IMETHOD OnDestroyed();
|
2006-04-04 12:12:38 +04:00
|
|
|
NS_IMETHOD DoneAddingChildren();
|
2004-12-15 05:08:53 +03:00
|
|
|
|
2005-08-09 23:17:18 +04:00
|
|
|
nsXFormsCaseElement()
|
2005-08-11 20:15:17 +04:00
|
|
|
: mElement(nsnull), mSelected(PR_FALSE), mCachedSelectedAttr(PR_FALSE)
|
2005-08-09 23:17:18 +04:00
|
|
|
{
|
|
|
|
}
|
2004-12-15 05:08:53 +03:00
|
|
|
|
2005-08-09 23:17:18 +04:00
|
|
|
protected:
|
2004-12-15 05:08:53 +03:00
|
|
|
nsIDOMElement* mElement;
|
2005-08-09 23:17:18 +04:00
|
|
|
PRPackedBool mSelected;
|
2005-08-11 20:15:17 +04:00
|
|
|
PRPackedBool mCachedSelectedAttr;
|
2004-12-15 05:08:53 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
NS_IMPL_ISUPPORTS_INHERITED1(nsXFormsCaseElement,
|
2005-08-09 23:17:18 +04:00
|
|
|
nsXFormsBindableStub,
|
2004-12-15 05:08:53 +03:00
|
|
|
nsIXFormsCaseElement)
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2005-08-09 23:17:18 +04:00
|
|
|
nsXFormsCaseElement::OnCreated(nsIXTFBindableElementWrapper *aWrapper)
|
2004-12-15 05:08:53 +03:00
|
|
|
{
|
2005-08-10 11:58:29 +04:00
|
|
|
nsresult rv = nsXFormsBindableStub::OnCreated(aWrapper);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2006-04-04 12:12:38 +04:00
|
|
|
aWrapper->SetNotificationMask(nsIXTFElement::NOTIFY_DONE_ADDING_CHILDREN);
|
|
|
|
|
2004-12-15 05:08:53 +03:00
|
|
|
nsCOMPtr<nsIDOMElement> node;
|
|
|
|
aWrapper->GetElementNode(getter_AddRefs(node));
|
|
|
|
|
2005-08-09 23:17:18 +04:00
|
|
|
// It's ok to keep a pointer to mElement. mElement will have an
|
|
|
|
// owning reference to this object, so as long as we null out mElement in
|
|
|
|
// OnDestroyed, it will always be valid.
|
|
|
|
|
|
|
|
mElement = node;
|
2004-12-15 05:08:53 +03:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsXFormsCaseElement::OnDestroyed()
|
|
|
|
{
|
|
|
|
mElement = nsnull;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2006-04-04 12:12:38 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsXFormsCaseElement::DoneAddingChildren()
|
|
|
|
{
|
|
|
|
// cache the value of the "selected" attr
|
|
|
|
nsAutoString value;
|
|
|
|
mElement->GetAttribute(NS_LITERAL_STRING("selected"), value);
|
|
|
|
if (value.EqualsLiteral("true") || value.EqualsLiteral("1")) {
|
|
|
|
mCachedSelectedAttr = PR_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2004-12-15 05:08:53 +03:00
|
|
|
NS_IMETHODIMP
|
2005-08-11 20:15:17 +04:00
|
|
|
nsXFormsCaseElement::GetInitialSelectedState(PRBool *aInitialSelectedState)
|
2004-12-15 05:08:53 +03:00
|
|
|
{
|
2005-08-11 20:15:17 +04:00
|
|
|
*aInitialSelectedState = mCachedSelectedAttr;
|
2004-12-15 05:08:53 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsXFormsCaseElement::SetSelected(PRBool aEnable)
|
|
|
|
{
|
2005-08-09 23:17:18 +04:00
|
|
|
mSelected = aEnable;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIXFormsCaseUIElement> caseUI(do_QueryInterface(mElement));
|
2006-04-04 12:12:38 +04:00
|
|
|
if (!caseUI)
|
|
|
|
return NS_ERROR_FAILURE;
|
2005-08-09 23:17:18 +04:00
|
|
|
|
2006-04-04 12:12:38 +04:00
|
|
|
caseUI->CaseSelected(mSelected);
|
2005-08-09 23:17:18 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsXFormsCaseElement::WidgetAttached()
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIXFormsCaseUIElement> caseUI(do_QueryInterface(mElement));
|
2006-04-04 12:12:38 +04:00
|
|
|
NS_WARN_IF_FALSE(caseUI,
|
|
|
|
"Case element not implementing nsIXFormCaseUIElement?");
|
2005-08-09 23:17:18 +04:00
|
|
|
if (caseUI) {
|
|
|
|
caseUI->CaseSelected(mSelected);
|
|
|
|
}
|
|
|
|
|
2004-12-15 05:08:53 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_HIDDEN_(nsresult)
|
|
|
|
NS_NewXFormsCaseElement(nsIXTFElement **aResult)
|
|
|
|
{
|
|
|
|
*aResult = new nsXFormsCaseElement();
|
|
|
|
if (!*aResult)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
|
|
|
|
NS_ADDREF(*aResult);
|
|
|
|
return NS_OK;
|
|
|
|
}
|