2000-11-03 02:01:46 -06:00
|
|
|
/*************************************************************************
|
|
|
|
*
|
2008-04-11 07:06:31 -05:00
|
|
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
2000-11-03 02:01:46 -06:00
|
|
|
*
|
2008-04-11 07:06:31 -05:00
|
|
|
* Copyright 2008 by Sun Microsystems, Inc.
|
2000-11-03 02:01:46 -06:00
|
|
|
*
|
2008-04-11 07:06:31 -05:00
|
|
|
* OpenOffice.org - a multi-platform office productivity suite
|
2000-11-03 02:01:46 -06:00
|
|
|
*
|
2008-04-11 07:06:31 -05:00
|
|
|
* $RCSfile: valuenode.hxx,v $
|
|
|
|
* $Revision: 1.31 $
|
2000-11-03 02:01:46 -06:00
|
|
|
*
|
2008-04-11 07:06:31 -05:00
|
|
|
* This file is part of OpenOffice.org.
|
2000-11-03 02:01:46 -06:00
|
|
|
*
|
2008-04-11 07:06:31 -05:00
|
|
|
* OpenOffice.org is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Lesser General Public License version 3
|
|
|
|
* only, as published by the Free Software Foundation.
|
2000-11-03 02:01:46 -06:00
|
|
|
*
|
2008-04-11 07:06:31 -05:00
|
|
|
* OpenOffice.org is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU Lesser General Public License version 3 for more details
|
|
|
|
* (a copy is included in the LICENSE file that accompanied this code).
|
2000-11-03 02:01:46 -06:00
|
|
|
*
|
2008-04-11 07:06:31 -05:00
|
|
|
* You should have received a copy of the GNU Lesser General Public License
|
|
|
|
* version 3 along with OpenOffice.org. If not, see
|
|
|
|
* <http://www.openoffice.org/license.html>
|
|
|
|
* for a copy of the LGPLv3 License.
|
2000-11-03 02:01:46 -06:00
|
|
|
*
|
|
|
|
************************************************************************/
|
|
|
|
|
|
|
|
#ifndef _CONFIGMGR_TREE_VALUENODE_HXX
|
|
|
|
#define _CONFIGMGR_TREE_VALUENODE_HXX
|
|
|
|
|
2003-03-19 09:20:19 -06:00
|
|
|
#include "attributes.hxx"
|
2001-09-28 06:44:40 -05:00
|
|
|
#include "anypair.hxx"
|
2000-11-15 00:14:58 -06:00
|
|
|
#include <com/sun/star/uno/Any.h>
|
2001-09-28 06:44:40 -05:00
|
|
|
#include <rtl/ustring.hxx>
|
2003-03-19 09:20:19 -06:00
|
|
|
#include "rttimacros.hxx"
|
|
|
|
|
2002-02-21 07:11:15 -06:00
|
|
|
#include <string.h>
|
2001-09-28 06:44:40 -05:00
|
|
|
#ifndef INCLUDED_MEMORY
|
|
|
|
#include <memory>
|
|
|
|
#define INCLUDED_MEMORY
|
2001-06-20 14:17:35 -05:00
|
|
|
#endif
|
|
|
|
|
2000-11-15 00:14:58 -06:00
|
|
|
namespace configmgr
|
|
|
|
{
|
|
|
|
|
|
|
|
namespace css = com::sun::star;
|
|
|
|
namespace uno = css::uno;
|
|
|
|
|
|
|
|
class INode;
|
|
|
|
class ISubtree;
|
|
|
|
class ValueNode;
|
|
|
|
|
2001-09-28 06:44:40 -05:00
|
|
|
using rtl::OUString;
|
|
|
|
|
2001-04-05 08:43:14 -05:00
|
|
|
// helper (tag) class
|
2003-03-19 09:20:19 -06:00
|
|
|
namespace treeop { struct NoChildCopy {}; struct DeepChildCopy {}; enum { ALL_LEVELS = -1 }; }
|
2000-11-15 00:14:58 -06:00
|
|
|
//==========================================================================
|
|
|
|
//= Visitors
|
|
|
|
//==========================================================================
|
|
|
|
struct NodeAction
|
|
|
|
{
|
|
|
|
virtual void handle(ValueNode const&) = 0;
|
|
|
|
virtual void handle(ISubtree const&) = 0;
|
|
|
|
|
|
|
|
void applyToNode(INode const&);
|
|
|
|
void applyToChildren(ISubtree const&);
|
2004-03-23 03:26:24 -06:00
|
|
|
protected:
|
|
|
|
virtual ~NodeAction() {}
|
2000-11-15 00:14:58 -06:00
|
|
|
};
|
|
|
|
|
|
|
|
struct NodeModification
|
|
|
|
{
|
|
|
|
virtual void handle(ValueNode&) = 0;
|
|
|
|
virtual void handle(ISubtree&) = 0;
|
|
|
|
|
|
|
|
void applyToNode(INode&);
|
|
|
|
void applyToChildren(ISubtree&);
|
2004-03-23 03:26:24 -06:00
|
|
|
protected:
|
|
|
|
virtual ~NodeModification() {}
|
2000-11-15 00:14:58 -06:00
|
|
|
};
|
|
|
|
|
|
|
|
class INode
|
|
|
|
{
|
2007-11-23 07:27:38 -06:00
|
|
|
OUString m_aName;
|
|
|
|
node::Attributes m_aAttributes;
|
2000-11-30 02:01:47 -06:00
|
|
|
|
|
|
|
protected:
|
|
|
|
INode(){}
|
2000-11-15 00:14:58 -06:00
|
|
|
|
2001-11-05 09:50:20 -06:00
|
|
|
void markAsDefault(bool _bDefault = true)
|
|
|
|
{
|
|
|
|
m_aAttributes.markAsDefault(_bDefault);
|
|
|
|
}
|
2000-11-15 00:14:58 -06:00
|
|
|
public:
|
2001-09-28 06:44:40 -05:00
|
|
|
explicit
|
|
|
|
INode(node::Attributes);
|
|
|
|
INode(OUString const& aName, node::Attributes);
|
|
|
|
|
2000-11-15 00:14:58 -06:00
|
|
|
virtual ~INode();
|
2001-09-28 06:44:40 -05:00
|
|
|
|
2002-02-11 06:47:56 -06:00
|
|
|
virtual std::auto_ptr<INode> clone() const = 0;
|
2001-09-28 06:44:40 -05:00
|
|
|
public:
|
2000-11-15 00:14:58 -06:00
|
|
|
|
2001-09-28 06:44:40 -05:00
|
|
|
const OUString& getName() const { return m_aName; }
|
|
|
|
node::Attributes getAttributes() const { return m_aAttributes; }
|
2000-11-15 00:14:58 -06:00
|
|
|
|
2001-11-05 09:50:20 -06:00
|
|
|
bool isDefault() const { return m_aAttributes.isDefault(); }
|
2003-04-01 06:35:11 -06:00
|
|
|
bool isLocalized() const { return m_aAttributes.isLocalized(); }
|
2001-09-25 10:05:21 -05:00
|
|
|
|
2001-11-14 10:00:14 -06:00
|
|
|
void modifyState(node::State _eNewState);
|
2003-04-01 06:35:11 -06:00
|
|
|
void modifyAccess(node::Access _aAccessLevel);
|
|
|
|
void markMandatory();
|
|
|
|
void markRemovable();
|
|
|
|
void promoteAccessToDefault();
|
|
|
|
void forceReadonlyToFinalized();
|
2001-09-25 10:05:21 -05:00
|
|
|
|
2000-11-15 00:14:58 -06:00
|
|
|
// to be used with caution. If the node is referenced from somewhere else under it's old name,
|
|
|
|
// you may have problems with this inconsistence
|
2001-09-28 06:44:40 -05:00
|
|
|
void setName(const OUString& _rNewName) { m_aName = _rNewName; }
|
2000-11-15 00:14:58 -06:00
|
|
|
|
|
|
|
virtual ValueNode* asValueNode();
|
|
|
|
virtual ValueNode const* asValueNode() const;
|
|
|
|
virtual ISubtree* asISubtree();
|
|
|
|
virtual ISubtree const* asISubtree() const;
|
|
|
|
|
|
|
|
// double dispatch support
|
|
|
|
virtual void dispatch(NodeAction&) const = 0;
|
|
|
|
virtual void dispatch(NodeModification&) = 0;
|
|
|
|
|
|
|
|
// "rtti"
|
|
|
|
RTTI_BASE(INode);
|
|
|
|
};
|
|
|
|
|
2001-06-20 14:17:35 -05:00
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
|
2000-11-15 00:14:58 -06:00
|
|
|
//==========================================================================
|
|
|
|
//= ISubtree
|
|
|
|
//==========================================================================
|
|
|
|
class ISubtree : public INode
|
|
|
|
{
|
2001-09-28 06:44:40 -05:00
|
|
|
sal_Int16 m_nLevel; /// determines if everything is read
|
|
|
|
sal_Int16 m_nDefaultLevels; /// determines if defaults are read
|
|
|
|
OUString m_sId;
|
|
|
|
OUString m_sTemplateName; /// path of the template for child instantiation
|
|
|
|
OUString m_sTemplateModule; /// module of the template for child instantiation
|
2000-11-30 02:01:47 -06:00
|
|
|
|
2001-09-28 06:44:40 -05:00
|
|
|
virtual INode* doGetChild(OUString const& name) const = 0;
|
2000-11-15 00:14:58 -06:00
|
|
|
|
2000-11-30 02:01:47 -06:00
|
|
|
protected:
|
|
|
|
ISubtree():m_nLevel(0){}
|
2000-11-15 00:14:58 -06:00
|
|
|
|
2000-12-20 05:14:21 -06:00
|
|
|
ISubtree(ISubtree const& other)
|
|
|
|
:INode(other)
|
|
|
|
,m_nLevel(other.m_nLevel)
|
2001-09-28 06:44:40 -05:00
|
|
|
,m_nDefaultLevels(other.m_nDefaultLevels)
|
2006-06-19 17:24:42 -05:00
|
|
|
,m_sId() // do not copy ID while cloning !
|
2000-12-20 05:14:21 -06:00
|
|
|
,m_sTemplateName(other.m_sTemplateName)
|
2001-03-12 07:58:00 -06:00
|
|
|
,m_sTemplateModule(other.m_sTemplateModule)
|
2000-12-20 05:14:21 -06:00
|
|
|
{}
|
|
|
|
|
2000-11-15 00:14:58 -06:00
|
|
|
public:
|
2001-03-12 07:58:00 -06:00
|
|
|
// Ctor for group trees
|
2001-09-28 06:44:40 -05:00
|
|
|
ISubtree(const rtl::OUString& aName, const node::Attributes& _rAttrs)
|
2001-03-12 07:58:00 -06:00
|
|
|
:INode(aName, _rAttrs)
|
|
|
|
,m_nLevel(0)
|
2001-09-28 06:44:40 -05:00
|
|
|
,m_nDefaultLevels(0)
|
2001-03-12 07:58:00 -06:00
|
|
|
{}
|
|
|
|
|
|
|
|
// Ctor for set trees
|
|
|
|
ISubtree(const rtl::OUString& aName,
|
|
|
|
const rtl::OUString& _rTemplateName,
|
|
|
|
const rtl::OUString& _rTemplateModule,
|
2001-09-28 06:44:40 -05:00
|
|
|
const node::Attributes& _rAttrs)
|
2000-11-30 02:01:47 -06:00
|
|
|
:INode(aName, _rAttrs)
|
|
|
|
,m_nLevel(0)
|
2001-09-28 06:44:40 -05:00
|
|
|
,m_nDefaultLevels(0)
|
2001-03-12 07:58:00 -06:00
|
|
|
,m_sTemplateName(_rTemplateName)
|
|
|
|
,m_sTemplateModule(_rTemplateModule){}
|
2000-11-15 00:14:58 -06:00
|
|
|
|
2001-09-28 06:44:40 -05:00
|
|
|
INode* getChild(OUString const& name) { return doGetChild(name); }
|
|
|
|
INode const* getChild(OUString const& name) const { return doGetChild(name); }
|
2000-11-15 00:14:58 -06:00
|
|
|
|
|
|
|
ISubtree* asISubtree();
|
|
|
|
ISubtree const* asISubtree() const;
|
|
|
|
|
2001-09-28 06:44:40 -05:00
|
|
|
using INode::markAsDefault;
|
2000-11-15 00:14:58 -06:00
|
|
|
|
2001-09-28 06:44:40 -05:00
|
|
|
sal_Int16 getLevel() const { return m_nLevel; }
|
|
|
|
|
|
|
|
void setLevels(sal_Int16 _nLevel,sal_Int16 _nDefaultsLevel);
|
|
|
|
|
|
|
|
bool isSetNode() const { return m_sTemplateName.getLength() != 0; }
|
|
|
|
|
2002-02-11 06:47:56 -06:00
|
|
|
void makeSetNode(OUString const& _sTemplateName, OUString const& _sTemplateModule)
|
|
|
|
{ m_sTemplateName = _sTemplateName; m_sTemplateModule = _sTemplateModule; }
|
|
|
|
|
2001-09-28 06:44:40 -05:00
|
|
|
OUString const& getElementTemplateName() const { return m_sTemplateName; }
|
|
|
|
OUString const& getElementTemplateModule() const { return m_sTemplateModule; }
|
2000-11-30 02:01:47 -06:00
|
|
|
|
|
|
|
virtual INode* addChild(std::auto_ptr<INode> node) =0; // takes ownership
|
|
|
|
virtual ::std::auto_ptr<INode> removeChild(rtl::OUString const& name) =0; // releases ownership
|
|
|
|
|
|
|
|
// Iteration support, stop if (action returns true)
|
|
|
|
virtual void forEachChild(NodeAction& anAction) const = 0;
|
|
|
|
virtual void forEachChild(NodeModification& anAction) = 0;
|
2000-11-15 00:14:58 -06:00
|
|
|
|
|
|
|
// double dispatch support
|
|
|
|
virtual void dispatch(NodeAction& anAction) const { anAction.handle(*this); }
|
|
|
|
virtual void dispatch(NodeModification& anAction) { anAction.handle(*this); }
|
|
|
|
|
|
|
|
// "rtti"
|
|
|
|
RTTI(ISubtree, INode);
|
|
|
|
};
|
|
|
|
|
|
|
|
//==========================================================================
|
|
|
|
//= ValueNode
|
|
|
|
//==========================================================================
|
|
|
|
class ValueNode : public INode
|
|
|
|
{
|
2001-06-20 14:17:35 -05:00
|
|
|
AnyPair m_aValuePair;
|
|
|
|
// uno::Type m_aType;
|
|
|
|
// uno::Any m_aValue;
|
|
|
|
// uno::Any m_aDefaultValue;
|
2000-11-30 02:01:47 -06:00
|
|
|
|
2000-11-15 00:14:58 -06:00
|
|
|
public:
|
2001-09-28 06:44:40 -05:00
|
|
|
//ValueNode(){}
|
2000-11-15 00:14:58 -06:00
|
|
|
|
2001-09-28 06:44:40 -05:00
|
|
|
//explicit ValueNode(node::Attributes _aAttrs):INode(_aAttrs){}
|
2000-11-30 02:01:47 -06:00
|
|
|
|
2001-09-28 06:44:40 -05:00
|
|
|
/*
|
|
|
|
ValueNode(OUString const& aName, node::Attributes _aAttrs)
|
|
|
|
: INode(aName, _aAttrs)
|
|
|
|
, m_aValuePair()
|
2000-11-15 00:14:58 -06:00
|
|
|
{}
|
2001-09-28 06:44:40 -05:00
|
|
|
*/
|
|
|
|
ValueNode(OUString const& aName,uno::Type const& aType, node::Attributes _aAttrs)
|
|
|
|
: INode(aName, _aAttrs)
|
|
|
|
, m_aValuePair(aType)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
ValueNode(OUString const& aName,uno::Any const& anAny, node::Attributes _aAttrs)
|
|
|
|
: INode(aName, _aAttrs)
|
2001-11-05 09:50:20 -06:00
|
|
|
, m_aValuePair(anAny, selectMember(_aAttrs.isDefault()))
|
2001-06-20 14:17:35 -05:00
|
|
|
{
|
|
|
|
}
|
2001-09-28 06:44:40 -05:00
|
|
|
ValueNode(OUString const& aName,uno::Any const& anAny,uno::Any const& aDefault, node::Attributes _aAttrs)
|
|
|
|
: INode(aName, _aAttrs)
|
|
|
|
, m_aValuePair(anAny, aDefault)
|
2001-06-20 14:17:35 -05:00
|
|
|
{
|
|
|
|
}
|
2000-11-15 00:14:58 -06:00
|
|
|
|
2002-02-11 06:47:56 -06:00
|
|
|
bool isEmpty() const {return m_aValuePair.isEmpty();}
|
2001-09-28 06:44:40 -05:00
|
|
|
bool isValid() const {return !m_aValuePair.isEmpty();}
|
2000-11-15 00:14:58 -06:00
|
|
|
|
2001-09-28 06:44:40 -05:00
|
|
|
bool isNull() const {return m_aValuePair.isNull();}
|
2003-04-01 06:35:11 -06:00
|
|
|
bool hasUsableDefault() const {return getAttributes().isNullable() || m_aValuePair.hasSecond();}
|
2000-12-01 06:40:40 -06:00
|
|
|
|
2001-09-28 06:44:40 -05:00
|
|
|
uno::Type getValueType() const {return m_aValuePair.getValueType();}
|
|
|
|
uno::Any getValue() const {return m_aValuePair.getValue( selectMember(this->isDefault()) );}
|
2002-02-11 06:47:56 -06:00
|
|
|
uno::Any getUserValue() const {return m_aValuePair.getFirst();}
|
2001-09-28 06:44:40 -05:00
|
|
|
uno::Any getDefault() const {return m_aValuePair.getSecond();}
|
2000-11-15 00:14:58 -06:00
|
|
|
|
2002-07-14 10:49:53 -05:00
|
|
|
bool setValueType(uno::Type const& _aType);
|
2002-05-16 04:57:32 -05:00
|
|
|
bool setValue(uno::Any const& _aValue);
|
2000-11-15 00:14:58 -06:00
|
|
|
void setDefault();
|
|
|
|
|
2002-05-16 04:57:32 -05:00
|
|
|
bool changeDefault(uno::Any const& _aValue);
|
2002-07-03 08:36:47 -05:00
|
|
|
void promoteToDefault();
|
2001-09-28 06:44:40 -05:00
|
|
|
|
2002-02-11 06:47:56 -06:00
|
|
|
virtual std::auto_ptr<INode> clone() const;
|
2000-11-15 00:14:58 -06:00
|
|
|
|
|
|
|
ValueNode* asValueNode();
|
|
|
|
ValueNode const* asValueNode() const;
|
|
|
|
// double dispatch support
|
|
|
|
virtual void dispatch(NodeAction& anAction) const { anAction.handle(*this); }
|
|
|
|
virtual void dispatch(NodeModification& anAction) { anAction.handle(*this); }
|
|
|
|
|
|
|
|
// "rtti"
|
|
|
|
RTTI(ValueNode, INode);
|
|
|
|
private:
|
2001-09-28 06:44:40 -05:00
|
|
|
static AnyPair::SelectMember selectValue() { return AnyPair::SELECT_FIRST; }
|
|
|
|
static AnyPair::SelectMember selectDeflt() { return AnyPair::SELECT_SECOND; }
|
|
|
|
static AnyPair::SelectMember selectMember(bool bDeflt)
|
|
|
|
{ return bDeflt ? AnyPair::SELECT_SECOND : AnyPair::SELECT_FIRST; }
|
2000-11-15 00:14:58 -06:00
|
|
|
};
|
2001-04-05 08:43:14 -05:00
|
|
|
//==========================================================================
|
|
|
|
|
|
|
|
extern bool isLocalizedValueSet(ISubtree const& _aSubtree);
|
|
|
|
|
2000-11-19 18:38:19 -06:00
|
|
|
//==========================================================================
|
|
|
|
//= inlines
|
|
|
|
//==========================================================================
|
|
|
|
inline void NodeAction::applyToNode(INode const& aNode)
|
|
|
|
{ aNode.dispatch(*this); }
|
|
|
|
inline void NodeAction::applyToChildren(ISubtree const& aSubtree)
|
|
|
|
{ aSubtree.forEachChild(*this); }
|
|
|
|
|
|
|
|
inline void NodeModification::applyToNode(INode& aNode)
|
|
|
|
{ aNode.dispatch(*this); }
|
|
|
|
inline void NodeModification::applyToChildren(ISubtree& aSubtree)
|
|
|
|
{ aSubtree.forEachChild(*this); }
|
|
|
|
|
2000-11-15 00:14:58 -06:00
|
|
|
|
|
|
|
} // namespace configmgr
|
2000-11-03 02:01:46 -06:00
|
|
|
|
|
|
|
#endif
|