1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #ifndef INCLUDED_SVTOOLS_SOURCE_UNO_TREECONTROLPEER_HXX
21 #define INCLUDED_SVTOOLS_SOURCE_UNO_TREECONTROLPEER_HXX
23 #include <com/sun/star/awt/tree/XTreeControl.hpp>
24 #include <com/sun/star/awt/tree/XTreeDataModel.hpp>
25 #include <com/sun/star/graphic/XGraphicProvider.hpp>
27 #include <toolkit/awt/vclxwindow.hxx>
28 #include <toolkit/awt/vclxwindows.hxx>
30 #include <vcl/image.hxx>
32 #include <cppuhelper/implbase2.hxx>
34 #include <tools/contnr.hxx>
38 namespace com
{ namespace sun
{ namespace star
{ namespace awt
{ namespace tree
{
44 class UnoTreeListEntry
;
45 class TreeControlPeer
;
46 class UnoTreeListBoxImpl
;
48 class TreeControlPeer
: public ::cppu::ImplInheritanceHelper2
< VCLXWindow
, ::com::sun::star::awt::tree::XTreeControl
, ::com::sun::star::awt::tree::XTreeDataModelListener
>
50 typedef std::map
<com::sun::star::uno::Reference
<com::sun::star::awt::tree::XTreeNode
>, UnoTreeListEntry
*> TreeNodeMap
;
52 friend class UnoTreeListBoxImpl
;
53 friend class UnoTreeListEntry
;
56 virtual ~TreeControlPeer();
58 vcl::Window
* createVclControl( vcl::Window
* pParent
, sal_Int64 nWinStyle
);
61 virtual void SetWindow( const VclPtr
< vcl::Window
> &pWindow
) SAL_OVERRIDE
;
63 // ::com::sun::star::view::XSelectionSupplier
64 virtual sal_Bool SAL_CALL
select( const ::com::sun::star::uno::Any
& xSelection
) throw (::com::sun::star::lang::IllegalArgumentException
, ::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
65 virtual ::com::sun::star::uno::Any SAL_CALL
getSelection( ) throw (::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
66 virtual void SAL_CALL
addSelectionChangeListener( const ::com::sun::star::uno::Reference
< ::com::sun::star::view::XSelectionChangeListener
>& xListener
) throw (::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
67 virtual void SAL_CALL
removeSelectionChangeListener( const ::com::sun::star::uno::Reference
< ::com::sun::star::view::XSelectionChangeListener
>& xListener
) throw (::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
69 // ::com::sun::star::view::XMultiSelectionSupplier
70 virtual sal_Bool SAL_CALL
addSelection( const ::com::sun::star::uno::Any
& Selection
) throw (::com::sun::star::lang::IllegalArgumentException
, ::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
71 virtual void SAL_CALL
removeSelection( const ::com::sun::star::uno::Any
& Selection
) throw (::com::sun::star::lang::IllegalArgumentException
, ::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
72 virtual void SAL_CALL
clearSelection( ) throw (::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
73 virtual ::sal_Int32 SAL_CALL
getSelectionCount( ) throw (::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
74 virtual ::com::sun::star::uno::Reference
< ::com::sun::star::container::XEnumeration
> SAL_CALL
createSelectionEnumeration( ) throw (::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
75 virtual ::com::sun::star::uno::Reference
< ::com::sun::star::container::XEnumeration
> SAL_CALL
createReverseSelectionEnumeration( ) throw (::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
77 // ::com::sun::star::awt::XTreeControl
78 virtual OUString SAL_CALL
getDefaultExpandedGraphicURL() throw (::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
79 virtual void SAL_CALL
setDefaultExpandedGraphicURL( const OUString
& _defaultexpandedgraphicurl
) throw (::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
80 virtual OUString SAL_CALL
getDefaultCollapsedGraphicURL() throw (::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
81 virtual void SAL_CALL
setDefaultCollapsedGraphicURL( const OUString
& _defaultcollapsedgraphicurl
) throw (::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
82 virtual sal_Bool SAL_CALL
isNodeExpanded( const ::com::sun::star::uno::Reference
< ::com::sun::star::awt::tree::XTreeNode
>& Node
) throw (::com::sun::star::lang::IllegalArgumentException
, ::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
83 virtual sal_Bool SAL_CALL
isNodeCollapsed( const ::com::sun::star::uno::Reference
< ::com::sun::star::awt::tree::XTreeNode
>& Node
) throw (::com::sun::star::lang::IllegalArgumentException
, ::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
84 virtual void SAL_CALL
makeNodeVisible( const ::com::sun::star::uno::Reference
< ::com::sun::star::awt::tree::XTreeNode
>& Node
) throw (::com::sun::star::lang::IllegalArgumentException
, ::com::sun::star::awt::tree::ExpandVetoException
, ::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
85 virtual sal_Bool SAL_CALL
isNodeVisible( const ::com::sun::star::uno::Reference
< ::com::sun::star::awt::tree::XTreeNode
>& Node
) throw (::com::sun::star::lang::IllegalArgumentException
, ::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
86 virtual void SAL_CALL
expandNode( const ::com::sun::star::uno::Reference
< ::com::sun::star::awt::tree::XTreeNode
>& Node
) throw (::com::sun::star::lang::IllegalArgumentException
, ::com::sun::star::awt::tree::ExpandVetoException
, ::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
87 virtual void SAL_CALL
collapseNode( const ::com::sun::star::uno::Reference
< ::com::sun::star::awt::tree::XTreeNode
>& Node
) throw (::com::sun::star::lang::IllegalArgumentException
, ::com::sun::star::awt::tree::ExpandVetoException
, ::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
88 virtual void SAL_CALL
addTreeExpansionListener( const ::com::sun::star::uno::Reference
< ::com::sun::star::awt::tree::XTreeExpansionListener
>& Listener
) throw (::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
89 virtual void SAL_CALL
removeTreeExpansionListener( const ::com::sun::star::uno::Reference
< ::com::sun::star::awt::tree::XTreeExpansionListener
>& Listener
) throw (::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
90 virtual ::com::sun::star::uno::Reference
< ::com::sun::star::awt::tree::XTreeNode
> SAL_CALL
getNodeForLocation( ::sal_Int32 x
, ::sal_Int32 y
) throw (::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
91 virtual ::com::sun::star::uno::Reference
< ::com::sun::star::awt::tree::XTreeNode
> SAL_CALL
getClosestNodeForLocation( ::sal_Int32 x
, ::sal_Int32 y
) throw (::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
92 virtual ::com::sun::star::awt::Rectangle SAL_CALL
getNodeRect( const ::com::sun::star::uno::Reference
< ::com::sun::star::awt::tree::XTreeNode
>& Node
) throw (::com::sun::star::lang::IllegalArgumentException
, ::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
93 virtual sal_Bool SAL_CALL
isEditing( ) throw (::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
94 virtual sal_Bool SAL_CALL
stopEditing( ) throw (::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
95 virtual void SAL_CALL
cancelEditing( ) throw (::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
96 virtual void SAL_CALL
startEditingAtNode( const ::com::sun::star::uno::Reference
< ::com::sun::star::awt::tree::XTreeNode
>& Node
) throw (::com::sun::star::lang::IllegalArgumentException
, ::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
97 virtual void SAL_CALL
addTreeEditListener( const ::com::sun::star::uno::Reference
< ::com::sun::star::awt::tree::XTreeEditListener
>& Listener
) throw (::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
98 virtual void SAL_CALL
removeTreeEditListener( const ::com::sun::star::uno::Reference
< ::com::sun::star::awt::tree::XTreeEditListener
>& Listener
) throw (::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
100 // ::com::sun::star::awt::tree::TreeDataModelListener
101 virtual void SAL_CALL
treeNodesChanged( const ::com::sun::star::awt::tree::TreeDataModelEvent
& aEvent
) throw (::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
102 virtual void SAL_CALL
treeNodesInserted( const ::com::sun::star::awt::tree::TreeDataModelEvent
& aEvent
) throw (::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
103 virtual void SAL_CALL
treeNodesRemoved( const ::com::sun::star::awt::tree::TreeDataModelEvent
& aEvent
) throw (::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
104 virtual void SAL_CALL
treeStructureChanged( const ::com::sun::star::awt::tree::TreeDataModelEvent
& aEvent
) throw (::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
107 void SAL_CALL
disposing( const ::com::sun::star::lang::EventObject
& Source
) throw(::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
109 // ::com::sun::star::awt::XLayoutConstrains
110 ::com::sun::star::awt::Size SAL_CALL
getMinimumSize() throw(::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
111 ::com::sun::star::awt::Size SAL_CALL
getPreferredSize() throw(::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
112 ::com::sun::star::awt::Size SAL_CALL
calcAdjustedSize( const ::com::sun::star::awt::Size
& aNewSize
) throw(::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
114 // ::com::sun::star::awt::XVclWindowPeer
115 void SAL_CALL
setProperty( const OUString
& PropertyName
, const ::com::sun::star::uno::Any
& Value
) throw(::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
116 ::com::sun::star::uno::Any SAL_CALL
getProperty( const OUString
& PropertyName
) throw(::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
119 UnoTreeListEntry
* getEntry( const ::com::sun::star::uno::Reference
< ::com::sun::star::awt::tree::XTreeNode
>& xNode
, bool bThrow
= true ) throw (::com::sun::star::lang::IllegalArgumentException
);
121 void disposeControl();
123 bool onEditingEntry( UnoTreeListEntry
* pEntry
);
124 bool onEditedEntry( UnoTreeListEntry
* pEntry
, const OUString
& rNewText
);
126 void eraseTree( UnoTreeListBoxImpl
& rTree
);
127 void fillTree( UnoTreeListBoxImpl
& rTree
, const ::com::sun::star::uno::Reference
< ::com::sun::star::awt::tree::XTreeDataModel
>& xDataModel
);
128 void addNode( UnoTreeListBoxImpl
& rTree
, const ::com::sun::star::uno::Reference
< ::com::sun::star::awt::tree::XTreeNode
>& xNode
, UnoTreeListEntry
* pParentEntry
);
130 UnoTreeListEntry
* createEntry( const ::com::sun::star::uno::Reference
< ::com::sun::star::awt::tree::XTreeNode
>& xNode
, UnoTreeListEntry
* pParent
, sal_uLong nPos
= TREELIST_APPEND
);
131 bool updateEntry( UnoTreeListEntry
* pEntry
);
133 void updateTree( const ::com::sun::star::awt::tree::TreeDataModelEvent
& rEvent
, bool bRecursive
);
134 void updateNode( UnoTreeListBoxImpl
& rTree
, const ::com::sun::star::uno::Reference
< ::com::sun::star::awt::tree::XTreeNode
>& xNode
, bool bRecursive
);
135 void updateChildNodes( UnoTreeListBoxImpl
& rTree
, const ::com::sun::star::uno::Reference
< ::com::sun::star::awt::tree::XTreeNode
>& xParentNode
, UnoTreeListEntry
* pParentEntry
);
137 static OUString
getEntryString( const ::com::sun::star::uno::Any
& rValue
);
139 UnoTreeListBoxImpl
& getTreeListBoxOrThrow() const throw (::com::sun::star::uno::RuntimeException
);
140 void ChangeNodesSelection( const ::com::sun::star::uno::Any
& rSelection
, bool bSelect
, bool bSetSelection
) throw( ::com::sun::star::uno::RuntimeException
, ::com::sun::star::lang::IllegalArgumentException
);
142 void onChangeDataModel( UnoTreeListBoxImpl
& rTree
, const ::com::sun::star::uno::Reference
< ::com::sun::star::awt::tree::XTreeDataModel
>& xDataModel
);
144 void onSelectionChanged();
145 void onRequestChildNodes( const ::com::sun::star::uno::Reference
< ::com::sun::star::awt::tree::XTreeNode
>& xNode
);
146 bool onExpanding( const ::com::sun::star::uno::Reference
< ::com::sun::star::awt::tree::XTreeNode
>& xNode
, bool bExpanding
);
147 void onExpanded( const ::com::sun::star::uno::Reference
< ::com::sun::star::awt::tree::XTreeNode
>& xNode
, bool bExpanding
);
149 void onChangeRootDisplayed( bool bIsRootDisplayed
);
151 void addEntry( UnoTreeListEntry
* pEntry
);
152 void removeEntry( UnoTreeListEntry
* pEntry
);
154 bool loadImage( const OUString
& rURL
, Image
& rImage
);
157 ::com::sun::star::uno::Reference
< ::com::sun::star::awt::tree::XTreeDataModel
>mxDataModel
;
158 TreeSelectionListenerMultiplexer maSelectionListeners
;
159 TreeExpansionListenerMultiplexer maTreeExpansionListeners
;
160 TreeEditListenerMultiplexer maTreeEditListeners
;
161 bool mbIsRootDisplayed
;
162 VclPtr
<UnoTreeListBoxImpl
> mpTreeImpl
;
163 sal_Int32 mnEditLock
;
164 OUString msDefaultCollapsedGraphicURL
;
165 OUString msDefaultExpandedGraphicURL
;
166 Image maDefaultExpandedImage
;
167 Image maDefaultCollapsedImage
;
168 TreeNodeMap
* mpTreeNodeMap
;
169 ::com::sun::star::uno::Reference
< ::com::sun::star::graphic::XGraphicProvider
> mxGraphicProvider
;
172 #endif // INCLUDED_SVTOOLS_SOURCE_UNO_TREECONTROLPEER_HXX
174 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */