1*01aa44aaSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*01aa44aaSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*01aa44aaSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*01aa44aaSAndrew Rist  * distributed with this work for additional information
6*01aa44aaSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*01aa44aaSAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*01aa44aaSAndrew Rist  * "License"); you may not use this file except in compliance
9*01aa44aaSAndrew Rist  * with the License.  You may obtain a copy of the License at
10*01aa44aaSAndrew Rist  *
11*01aa44aaSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*01aa44aaSAndrew Rist  *
13*01aa44aaSAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*01aa44aaSAndrew Rist  * software distributed under the License is distributed on an
15*01aa44aaSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*01aa44aaSAndrew Rist  * KIND, either express or implied.  See the License for the
17*01aa44aaSAndrew Rist  * specific language governing permissions and limitations
18*01aa44aaSAndrew Rist  * under the License.
19*01aa44aaSAndrew Rist  *
20*01aa44aaSAndrew Rist  *************************************************************/
21*01aa44aaSAndrew Rist 
22*01aa44aaSAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir #ifndef _TREE_CONTROL_PEER_HXX_
25cdf0e10cSrcweir #define _TREE_CONTROL_PEER_HXX_
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #include <com/sun/star/awt/tree/XTreeControl.hpp>
28cdf0e10cSrcweir #include <com/sun/star/awt/tree/XTreeDataModel.hpp>
29cdf0e10cSrcweir #include <com/sun/star/graphic/XGraphicProvider.hpp>
30cdf0e10cSrcweir 
31cdf0e10cSrcweir #include <toolkit/awt/vclxwindow.hxx>
32cdf0e10cSrcweir #include <toolkit/awt/vclxwindows.hxx>
33cdf0e10cSrcweir 
34cdf0e10cSrcweir #include <vcl/image.hxx>
35cdf0e10cSrcweir 
36cdf0e10cSrcweir //#include <comphelper/uno3.hxx>
37cdf0e10cSrcweir #include <cppuhelper/implbase2.hxx>
38cdf0e10cSrcweir 
39cdf0e10cSrcweir 
40cdf0e10cSrcweir class UnoTreeListEntry;
41cdf0e10cSrcweir class TreeControlPeer;
42cdf0e10cSrcweir class UnoTreeListBoxImpl;
43cdf0e10cSrcweir class TreeNodeMap;
44cdf0e10cSrcweir 
45cdf0e10cSrcweir //	----------------------------------------------------
46cdf0e10cSrcweir //	class TreeControlPeer
47cdf0e10cSrcweir //	----------------------------------------------------
48cdf0e10cSrcweir class TreeControlPeer :	public ::cppu::ImplInheritanceHelper2< VCLXWindow, ::com::sun::star::awt::tree::XTreeControl, ::com::sun::star::awt::tree::XTreeDataModelListener >
49cdf0e10cSrcweir {
50cdf0e10cSrcweir 	friend class UnoTreeListBoxImpl;
51cdf0e10cSrcweir 	friend class UnoTreeListEntry;
52cdf0e10cSrcweir public:
53cdf0e10cSrcweir 	TreeControlPeer();
54cdf0e10cSrcweir 	virtual ~TreeControlPeer();
55cdf0e10cSrcweir 
56cdf0e10cSrcweir 	Window* createVclControl( Window* pParent, sal_Int64 nWinStyle );
57cdf0e10cSrcweir 
58cdf0e10cSrcweir 	// VCLXWindow
59cdf0e10cSrcweir 	virtual void SetWindow( Window* pWindow );
60cdf0e10cSrcweir 
61cdf0e10cSrcweir 	// ::com::sun::star::view::XSelectionSupplier
62cdf0e10cSrcweir     virtual ::sal_Bool SAL_CALL select( const ::com::sun::star::uno::Any& xSelection ) throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException);
63cdf0e10cSrcweir     virtual ::com::sun::star::uno::Any SAL_CALL getSelection(  ) throw (::com::sun::star::uno::RuntimeException);
64cdf0e10cSrcweir     virtual void SAL_CALL addSelectionChangeListener( const ::com::sun::star::uno::Reference< ::com::sun::star::view::XSelectionChangeListener >& xListener ) throw (::com::sun::star::uno::RuntimeException);
65cdf0e10cSrcweir     virtual void SAL_CALL removeSelectionChangeListener( const ::com::sun::star::uno::Reference< ::com::sun::star::view::XSelectionChangeListener >& xListener ) throw (::com::sun::star::uno::RuntimeException);
66cdf0e10cSrcweir 
67cdf0e10cSrcweir 	// ::com::sun::star::view::XMultiSelectionSupplier
68cdf0e10cSrcweir     virtual ::sal_Bool SAL_CALL addSelection( const ::com::sun::star::uno::Any& Selection ) throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException);
69cdf0e10cSrcweir     virtual void SAL_CALL removeSelection( const ::com::sun::star::uno::Any& Selection ) throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException);
70cdf0e10cSrcweir     virtual void SAL_CALL clearSelection(  ) throw (::com::sun::star::uno::RuntimeException);
71cdf0e10cSrcweir     virtual ::sal_Int32 SAL_CALL getSelectionCount(  ) throw (::com::sun::star::uno::RuntimeException);
72cdf0e10cSrcweir     virtual ::com::sun::star::uno::Reference< ::com::sun::star::container::XEnumeration > SAL_CALL createSelectionEnumeration(  ) throw (::com::sun::star::uno::RuntimeException);
73cdf0e10cSrcweir     virtual ::com::sun::star::uno::Reference< ::com::sun::star::container::XEnumeration > SAL_CALL createReverseSelectionEnumeration(  ) throw (::com::sun::star::uno::RuntimeException);
74cdf0e10cSrcweir 
75cdf0e10cSrcweir     // ::com::sun::star::awt::XTreeControl
76cdf0e10cSrcweir     virtual ::rtl::OUString SAL_CALL getDefaultExpandedGraphicURL() throw (::com::sun::star::uno::RuntimeException);
77cdf0e10cSrcweir     virtual void SAL_CALL setDefaultExpandedGraphicURL( const ::rtl::OUString& _defaultexpandedgraphicurl ) throw (::com::sun::star::uno::RuntimeException);
78cdf0e10cSrcweir     virtual ::rtl::OUString SAL_CALL getDefaultCollapsedGraphicURL() throw (::com::sun::star::uno::RuntimeException);
79cdf0e10cSrcweir     virtual void SAL_CALL setDefaultCollapsedGraphicURL( const ::rtl::OUString& _defaultcollapsedgraphicurl ) throw (::com::sun::star::uno::RuntimeException);
80cdf0e10cSrcweir     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);
81cdf0e10cSrcweir     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);
82cdf0e10cSrcweir     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);
83cdf0e10cSrcweir     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);
84cdf0e10cSrcweir     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);
85cdf0e10cSrcweir     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);
86cdf0e10cSrcweir     virtual void SAL_CALL addTreeExpansionListener( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::tree::XTreeExpansionListener >& Listener ) throw (::com::sun::star::uno::RuntimeException);
87cdf0e10cSrcweir     virtual void SAL_CALL removeTreeExpansionListener( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::tree::XTreeExpansionListener >& Listener ) throw (::com::sun::star::uno::RuntimeException);
88cdf0e10cSrcweir     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);
89cdf0e10cSrcweir     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);
90cdf0e10cSrcweir     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);
91cdf0e10cSrcweir     virtual ::sal_Bool SAL_CALL isEditing(  ) throw (::com::sun::star::uno::RuntimeException);
92cdf0e10cSrcweir     virtual ::sal_Bool SAL_CALL stopEditing(  ) throw (::com::sun::star::uno::RuntimeException);
93cdf0e10cSrcweir     virtual void SAL_CALL cancelEditing(  ) throw (::com::sun::star::uno::RuntimeException);
94cdf0e10cSrcweir     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);
95cdf0e10cSrcweir     virtual void SAL_CALL addTreeEditListener( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::tree::XTreeEditListener >& Listener ) throw (::com::sun::star::uno::RuntimeException);
96cdf0e10cSrcweir     virtual void SAL_CALL removeTreeEditListener( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::tree::XTreeEditListener >& Listener ) throw (::com::sun::star::uno::RuntimeException);
97cdf0e10cSrcweir 
98cdf0e10cSrcweir     // ::com::sun::star::awt::tree::TreeDataModelListener
99cdf0e10cSrcweir     virtual void SAL_CALL treeNodesChanged( const ::com::sun::star::awt::tree::TreeDataModelEvent& aEvent ) throw (::com::sun::star::uno::RuntimeException);
100cdf0e10cSrcweir     virtual void SAL_CALL treeNodesInserted( const ::com::sun::star::awt::tree::TreeDataModelEvent& aEvent ) throw (::com::sun::star::uno::RuntimeException);
101cdf0e10cSrcweir     virtual void SAL_CALL treeNodesRemoved( const ::com::sun::star::awt::tree::TreeDataModelEvent& aEvent ) throw (::com::sun::star::uno::RuntimeException);
102cdf0e10cSrcweir     virtual void SAL_CALL treeStructureChanged( const ::com::sun::star::awt::tree::TreeDataModelEvent& aEvent ) throw (::com::sun::star::uno::RuntimeException);
103cdf0e10cSrcweir 
104cdf0e10cSrcweir     // XEventListener
105cdf0e10cSrcweir     void SAL_CALL disposing( const ::com::sun::star::lang::EventObject& Source ) throw(::com::sun::star::uno::RuntimeException);
106cdf0e10cSrcweir 
107cdf0e10cSrcweir 	// ::com::sun::star::awt::XLayoutConstrains
108cdf0e10cSrcweir     ::com::sun::star::awt::Size SAL_CALL getMinimumSize() throw(::com::sun::star::uno::RuntimeException);
109cdf0e10cSrcweir     ::com::sun::star::awt::Size SAL_CALL getPreferredSize() throw(::com::sun::star::uno::RuntimeException);
110cdf0e10cSrcweir     ::com::sun::star::awt::Size SAL_CALL calcAdjustedSize( const ::com::sun::star::awt::Size& aNewSize ) throw(::com::sun::star::uno::RuntimeException);
111cdf0e10cSrcweir 
112cdf0e10cSrcweir 	// ::com::sun::star::awt::XVclWindowPeer
113cdf0e10cSrcweir     void SAL_CALL setProperty( const ::rtl::OUString& PropertyName, const ::com::sun::star::uno::Any& Value ) throw(::com::sun::star::uno::RuntimeException);
114cdf0e10cSrcweir     ::com::sun::star::uno::Any SAL_CALL getProperty( const ::rtl::OUString& PropertyName ) throw(::com::sun::star::uno::RuntimeException);
115cdf0e10cSrcweir 
116cdf0e10cSrcweir private:
117cdf0e10cSrcweir 	UnoTreeListEntry* getEntry( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::tree::XTreeNode >& xNode, bool bThrow = true ) throw (::com::sun::star::lang::IllegalArgumentException );
118cdf0e10cSrcweir 
119cdf0e10cSrcweir 	void disposeControl();
120cdf0e10cSrcweir 
121cdf0e10cSrcweir 	bool onEditingEntry( UnoTreeListEntry* pEntry );
122cdf0e10cSrcweir 	bool onEditedEntry( UnoTreeListEntry* pEntry, const XubString& rNewText );
123cdf0e10cSrcweir 
124cdf0e10cSrcweir 	void eraseTree( UnoTreeListBoxImpl& rTree );
125cdf0e10cSrcweir 	void fillTree( UnoTreeListBoxImpl& rTree, const ::com::sun::star::uno::Reference< ::com::sun::star::awt::tree::XTreeDataModel >& xDataModel );
126cdf0e10cSrcweir 	void addNode( UnoTreeListBoxImpl& rTree, const ::com::sun::star::uno::Reference< ::com::sun::star::awt::tree::XTreeNode >& xNode, UnoTreeListEntry* pParentEntry );
127cdf0e10cSrcweir 
128cdf0e10cSrcweir 	UnoTreeListEntry* createEntry( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::tree::XTreeNode >& xNode, UnoTreeListEntry* pParent, sal_uLong nPos = LIST_APPEND );
129cdf0e10cSrcweir 	bool updateEntry( UnoTreeListEntry* pEntry );
130cdf0e10cSrcweir 
131cdf0e10cSrcweir 	void updateTree( const ::com::sun::star::awt::tree::TreeDataModelEvent& rEvent, bool bRecursive );
132cdf0e10cSrcweir 	void updateNode( UnoTreeListBoxImpl& rTree, const ::com::sun::star::uno::Reference< ::com::sun::star::awt::tree::XTreeNode >& xNode, bool bRecursive );
133cdf0e10cSrcweir 	void updateChildNodes( UnoTreeListBoxImpl& rTree, const ::com::sun::star::uno::Reference< ::com::sun::star::awt::tree::XTreeNode >& xParentNode, UnoTreeListEntry* pParentEntry );
134cdf0e10cSrcweir 
135cdf0e10cSrcweir 	::rtl::OUString getEntryString( const ::com::sun::star::uno::Any& rValue );
136cdf0e10cSrcweir 
137cdf0e10cSrcweir 	UnoTreeListBoxImpl& getTreeListBoxOrThrow() const throw (::com::sun::star::uno::RuntimeException );
138cdf0e10cSrcweir 	void ChangeNodesSelection( const ::com::sun::star::uno::Any& rSelection, bool bSelect, bool bSetSelection ) throw( ::com::sun::star::uno::RuntimeException, ::com::sun::star::lang::IllegalArgumentException );
139cdf0e10cSrcweir 
140cdf0e10cSrcweir 	void onChangeDataModel( UnoTreeListBoxImpl& rTree, const ::com::sun::star::uno::Reference< ::com::sun::star::awt::tree::XTreeDataModel >& xDataModel );
141cdf0e10cSrcweir 
142cdf0e10cSrcweir 	void onSelectionChanged();
143cdf0e10cSrcweir 	void onRequestChildNodes( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::tree::XTreeNode >& xNode );
144cdf0e10cSrcweir 	bool onExpanding( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::tree::XTreeNode >& xNode, bool bExpanding );
145cdf0e10cSrcweir 	void onExpanded( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::tree::XTreeNode >& xNode, bool bExpanding );
146cdf0e10cSrcweir 
147cdf0e10cSrcweir 	void onChangeRootDisplayed( sal_Bool bIsRootDisplayed );
148cdf0e10cSrcweir 
149cdf0e10cSrcweir 	void addEntry( UnoTreeListEntry* pEntry );
150cdf0e10cSrcweir 	void removeEntry( UnoTreeListEntry* pEntry );
151cdf0e10cSrcweir 
152cdf0e10cSrcweir 	bool loadImage( const ::rtl::OUString& rURL, Image& rImage );
153cdf0e10cSrcweir 
154cdf0e10cSrcweir private:
155cdf0e10cSrcweir 	::com::sun::star::uno::Reference< ::com::sun::star::awt::tree::XTreeDataModel >mxDataModel;
156cdf0e10cSrcweir 	TreeSelectionListenerMultiplexer maSelectionListeners;
157cdf0e10cSrcweir 	TreeExpansionListenerMultiplexer maTreeExpansionListeners;
158cdf0e10cSrcweir 	TreeEditListenerMultiplexer maTreeEditListeners;
159cdf0e10cSrcweir 	sal_Bool mbIsRootDisplayed;
160cdf0e10cSrcweir 	UnoTreeListBoxImpl* mpTreeImpl;
161cdf0e10cSrcweir 	sal_Int32 mnEditLock;
162cdf0e10cSrcweir 	::rtl::OUString msDefaultCollapsedGraphicURL;
163cdf0e10cSrcweir 	::rtl::OUString msDefaultExpandedGraphicURL;
164cdf0e10cSrcweir 	Image maDefaultExpandedImage;
165cdf0e10cSrcweir 	Image maDefaultCollapsedImage;
166cdf0e10cSrcweir 	TreeNodeMap* mpTreeNodeMap;
167cdf0e10cSrcweir 	::com::sun::star::uno::Reference< ::com::sun::star::graphic::XGraphicProvider > mxGraphicProvider;
168cdf0e10cSrcweir };
169cdf0e10cSrcweir 
170cdf0e10cSrcweir #endif // _TREE_CONTROL_PEER_HXX_
171