2004-11-05 02:53:01 +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
|
|
|
|
* Novell, Inc.
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 2004
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
|
|
|
* Allan Beaufour <abeaufour@novell.com>
|
2005-06-26 22:30:17 +04:00
|
|
|
* Olli Pettay <Olli.Pettay@helsinki.fi>
|
2004-11-05 02:53:01 +03:00
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
|
|
|
* either 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 ***** */
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
//#define DEBUG_XF_OUTPUT
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "nsIXTFXMLVisualWrapper.h"
|
|
|
|
|
|
|
|
#include "nsAutoPtr.h"
|
|
|
|
#include "nsCOMPtr.h"
|
|
|
|
#include "nsMemory.h"
|
|
|
|
#include "nsString.h"
|
2005-06-26 22:30:17 +04:00
|
|
|
#include "nsDOMString.h"
|
2004-11-05 02:53:01 +03:00
|
|
|
#include "nsIDOM3Node.h"
|
|
|
|
#include "nsIDOMDocument.h"
|
|
|
|
#include "nsIDOMElement.h"
|
|
|
|
#include "nsIDOMEventTarget.h"
|
|
|
|
#include "nsIDOMXPathExpression.h"
|
|
|
|
#include "nsIDOMXPathResult.h"
|
|
|
|
#include "nsISchema.h"
|
|
|
|
|
|
|
|
#include "nsIModelElementPrivate.h"
|
2005-06-26 22:30:17 +04:00
|
|
|
#include "nsXFormsDelegateStub.h"
|
2004-11-05 02:53:01 +03:00
|
|
|
#include "nsXFormsAtoms.h"
|
|
|
|
#include "nsXFormsUtils.h"
|
2005-06-26 22:30:17 +04:00
|
|
|
#include "nsIXFormsUIWidget.h"
|
|
|
|
|
2004-11-05 02:53:01 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Implementation of the XForms \<output\> element.
|
|
|
|
*
|
|
|
|
* @see http://www.w3.org/TR/xforms/slice8.html#ui-output
|
|
|
|
*/
|
2005-06-26 22:30:17 +04:00
|
|
|
class nsXFormsOutputElement : public nsXFormsDelegateStub
|
2004-11-05 02:53:01 +03:00
|
|
|
{
|
|
|
|
public:
|
2004-11-07 11:54:32 +03:00
|
|
|
// nsIXFormsControl
|
2005-01-19 19:05:31 +03:00
|
|
|
NS_IMETHOD Bind();
|
|
|
|
NS_IMETHOD Refresh();
|
2004-11-05 02:53:01 +03:00
|
|
|
|
2005-06-26 22:30:17 +04:00
|
|
|
// nsIXFormsDelegate
|
|
|
|
NS_IMETHOD GetValue(nsAString& aValue);
|
2004-11-05 02:53:01 +03:00
|
|
|
|
2005-06-26 22:30:17 +04:00
|
|
|
nsXFormsOutputElement() :
|
|
|
|
nsXFormsDelegateStub(NS_LITERAL_STRING("output")) {}
|
2004-11-05 02:53:01 +03:00
|
|
|
|
2005-04-11 20:33:31 +04:00
|
|
|
|
2005-06-26 22:30:17 +04:00
|
|
|
private:
|
|
|
|
PRBool mHasBinding;
|
|
|
|
nsString mValue;
|
|
|
|
};
|
2004-11-05 02:53:01 +03:00
|
|
|
|
2004-11-07 11:54:32 +03:00
|
|
|
// nsIXFormsControl
|
2004-11-05 02:53:01 +03:00
|
|
|
|
2005-01-19 19:05:31 +03:00
|
|
|
nsresult
|
|
|
|
nsXFormsOutputElement::Bind()
|
2004-11-05 02:53:01 +03:00
|
|
|
{
|
2005-06-26 22:30:17 +04:00
|
|
|
// Clear existing bound node, etc.
|
|
|
|
mBoundNode = nsnull;
|
|
|
|
mDependencies.Clear();
|
|
|
|
RemoveIndexListeners();
|
2004-11-05 02:53:01 +03:00
|
|
|
|
2005-06-26 22:30:17 +04:00
|
|
|
if (!mHasParent)
|
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
nsresult rv = mElement->HasAttribute(NS_LITERAL_STRING("ref"), &mHasBinding);
|
2004-11-05 02:53:01 +03:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2005-01-19 19:05:31 +03:00
|
|
|
if (!mHasBinding) {
|
|
|
|
rv = mElement->HasAttribute(NS_LITERAL_STRING("bind"), &mHasBinding);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
}
|
2004-11-05 02:53:01 +03:00
|
|
|
|
2005-06-26 22:30:17 +04:00
|
|
|
nsCOMPtr<nsIDOMXPathResult> result;
|
2005-01-19 19:05:31 +03:00
|
|
|
if (mHasBinding) {
|
2005-06-26 22:30:17 +04:00
|
|
|
rv = ProcessNodeBinding(NS_LITERAL_STRING("ref"),
|
|
|
|
nsIDOMXPathResult::FIRST_ORDERED_NODE_TYPE,
|
|
|
|
getter_AddRefs(result));
|
2004-11-05 02:53:01 +03:00
|
|
|
} else {
|
2005-06-26 22:30:17 +04:00
|
|
|
rv = ProcessNodeBinding(NS_LITERAL_STRING("value"),
|
|
|
|
nsIDOMXPathResult::STRING_TYPE,
|
|
|
|
getter_AddRefs(result));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
nsXFormsUtils::ReportError(NS_LITERAL_STRING("controlBindError"), mElement);
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (result) {
|
|
|
|
result->GetSingleNodeValue(getter_AddRefs(mBoundNode));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mBoundNode && mModel) {
|
|
|
|
mModel->SetStates(this, mBoundNode);
|
|
|
|
}
|
2005-01-19 19:05:31 +03:00
|
|
|
|
2005-05-05 11:09:40 +04:00
|
|
|
return rv;
|
2005-01-19 19:05:31 +03:00
|
|
|
}
|
2005-06-26 22:30:17 +04:00
|
|
|
|
2005-01-19 19:05:31 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsXFormsOutputElement::Refresh()
|
|
|
|
{
|
2005-06-26 22:30:17 +04:00
|
|
|
if (mRepeatState == eType_Template)
|
2005-01-19 19:05:31 +03:00
|
|
|
return NS_OK;
|
2004-11-05 02:53:01 +03:00
|
|
|
|
2005-06-26 22:30:17 +04:00
|
|
|
nsresult rv = NS_OK;
|
|
|
|
SetDOMStringToNull(mValue);
|
|
|
|
|
|
|
|
if (mModel) {
|
|
|
|
if (mHasBinding) {
|
|
|
|
if (mBoundNode) {
|
|
|
|
nsXFormsUtils::GetNodeValue(mBoundNode, mValue);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
nsCOMPtr<nsIDOMXPathResult> result;
|
|
|
|
rv = ProcessNodeBinding(NS_LITERAL_STRING("value"),
|
|
|
|
nsIDOMXPathResult::STRING_TYPE,
|
|
|
|
getter_AddRefs(result));
|
2004-11-05 02:53:01 +03:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2005-06-26 22:30:17 +04:00
|
|
|
|
|
|
|
if (result) {
|
|
|
|
rv = result->GetStringValue(mValue);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
}
|
2004-11-05 02:53:01 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-06-26 22:30:17 +04:00
|
|
|
SetMozTypeAttribute();
|
2005-01-19 19:05:31 +03:00
|
|
|
|
2005-06-26 22:30:17 +04:00
|
|
|
nsCOMPtr<nsIXFormsUIWidget> widget = do_QueryInterface(mElement);
|
|
|
|
if (widget)
|
|
|
|
widget->Refresh();
|
2005-01-19 19:05:31 +03:00
|
|
|
|
|
|
|
return rv;
|
2004-11-05 02:53:01 +03:00
|
|
|
}
|
|
|
|
|
2005-06-26 22:30:17 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsXFormsOutputElement::GetValue(nsAString& aValue)
|
2005-04-11 20:33:31 +04:00
|
|
|
{
|
2005-06-26 22:30:17 +04:00
|
|
|
aValue = mValue;
|
|
|
|
return NS_OK;
|
2005-04-11 20:33:31 +04:00
|
|
|
}
|
|
|
|
|
2004-11-05 02:53:01 +03:00
|
|
|
NS_HIDDEN_(nsresult)
|
|
|
|
NS_NewXFormsOutputElement(nsIXTFElement **aResult)
|
|
|
|
{
|
|
|
|
*aResult = new nsXFormsOutputElement();
|
|
|
|
if (!*aResult)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
|
|
|
|
NS_ADDREF(*aResult);
|
|
|
|
return NS_OK;
|
|
|
|
}
|