Version 7.6.3.2-android, tag libreoffice-7.6.3.2-android
[LibreOffice.git] / toolkit / inc / controls / treecontrolpeer.hxx
blobd584516ae35bbbf89b8c960b5c172d7dc39df5ed
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 #pragma once
22 #include <com/sun/star/awt/tree/XTreeControl.hpp>
23 #include <com/sun/star/awt/tree/XTreeDataModel.hpp>
24 #include <com/sun/star/graphic/XGraphicProvider.hpp>
26 #include <toolkit/awt/vclxwindow.hxx>
27 #include <toolkit/helper/listenermultiplexer.hxx>
29 #include <vcl/image.hxx>
31 #include <cppuhelper/implbase.hxx>
33 #include <map>
35 namespace com::sun::star::awt::tree { class XTreeNode; }
37 class UnoTreeListEntry;
38 class TreeControlPeer;
39 class UnoTreeListBoxImpl;
41 class TreeControlPeer final : public ::cppu::ImplInheritanceHelper< VCLXWindow, css::awt::tree::XTreeControl, css::awt::tree::XTreeDataModelListener >
43 typedef std::map<css::uno::Reference<css::awt::tree::XTreeNode>, UnoTreeListEntry*> TreeNodeMap;
45 friend class UnoTreeListBoxImpl;
46 friend class UnoTreeListEntry;
47 public:
48 TreeControlPeer();
49 virtual ~TreeControlPeer() override;
51 vcl::Window* createVclControl( vcl::Window* pParent, sal_Int64 nWinStyle );
53 // css::view::XSelectionSupplier
54 virtual sal_Bool SAL_CALL select( const css::uno::Any& xSelection ) override;
55 virtual css::uno::Any SAL_CALL getSelection( ) override;
56 virtual void SAL_CALL addSelectionChangeListener( const css::uno::Reference< css::view::XSelectionChangeListener >& xListener ) override;
57 virtual void SAL_CALL removeSelectionChangeListener( const css::uno::Reference< css::view::XSelectionChangeListener >& xListener ) override;
59 // css::view::XMultiSelectionSupplier
60 virtual sal_Bool SAL_CALL addSelection( const css::uno::Any& Selection ) override;
61 virtual void SAL_CALL removeSelection( const css::uno::Any& Selection ) override;
62 virtual void SAL_CALL clearSelection( ) override;
63 virtual ::sal_Int32 SAL_CALL getSelectionCount( ) override;
64 virtual css::uno::Reference< css::container::XEnumeration > SAL_CALL createSelectionEnumeration( ) override;
65 virtual css::uno::Reference< css::container::XEnumeration > SAL_CALL createReverseSelectionEnumeration( ) override;
67 // css::awt::XTreeControl
68 virtual OUString SAL_CALL getDefaultExpandedGraphicURL() override;
69 virtual void SAL_CALL setDefaultExpandedGraphicURL( const OUString& _defaultexpandedgraphicurl ) override;
70 virtual OUString SAL_CALL getDefaultCollapsedGraphicURL() override;
71 virtual void SAL_CALL setDefaultCollapsedGraphicURL( const OUString& _defaultcollapsedgraphicurl ) override;
72 virtual sal_Bool SAL_CALL isNodeExpanded( const css::uno::Reference< css::awt::tree::XTreeNode >& Node ) override;
73 virtual sal_Bool SAL_CALL isNodeCollapsed( const css::uno::Reference< css::awt::tree::XTreeNode >& Node ) override;
74 virtual void SAL_CALL makeNodeVisible( const css::uno::Reference< css::awt::tree::XTreeNode >& Node ) override;
75 virtual sal_Bool SAL_CALL isNodeVisible( const css::uno::Reference< css::awt::tree::XTreeNode >& Node ) override;
76 virtual void SAL_CALL expandNode( const css::uno::Reference< css::awt::tree::XTreeNode >& Node ) override;
77 virtual void SAL_CALL collapseNode( const css::uno::Reference< css::awt::tree::XTreeNode >& Node ) override;
78 virtual void SAL_CALL addTreeExpansionListener( const css::uno::Reference< css::awt::tree::XTreeExpansionListener >& Listener ) override;
79 virtual void SAL_CALL removeTreeExpansionListener( const css::uno::Reference< css::awt::tree::XTreeExpansionListener >& Listener ) override;
80 virtual css::uno::Reference< css::awt::tree::XTreeNode > SAL_CALL getNodeForLocation( ::sal_Int32 x, ::sal_Int32 y ) override;
81 virtual css::uno::Reference< css::awt::tree::XTreeNode > SAL_CALL getClosestNodeForLocation( ::sal_Int32 x, ::sal_Int32 y ) override;
82 virtual css::awt::Rectangle SAL_CALL getNodeRect( const css::uno::Reference< css::awt::tree::XTreeNode >& Node ) override;
83 virtual sal_Bool SAL_CALL isEditing( ) override;
84 virtual sal_Bool SAL_CALL stopEditing( ) override;
85 virtual void SAL_CALL cancelEditing( ) override;
86 virtual void SAL_CALL startEditingAtNode( const css::uno::Reference< css::awt::tree::XTreeNode >& Node ) override;
87 virtual void SAL_CALL addTreeEditListener( const css::uno::Reference< css::awt::tree::XTreeEditListener >& Listener ) override;
88 virtual void SAL_CALL removeTreeEditListener( const css::uno::Reference< css::awt::tree::XTreeEditListener >& Listener ) override;
90 // css::awt::tree::TreeDataModelListener
91 virtual void SAL_CALL treeNodesChanged( const css::awt::tree::TreeDataModelEvent& aEvent ) override;
92 virtual void SAL_CALL treeNodesInserted( const css::awt::tree::TreeDataModelEvent& aEvent ) override;
93 virtual void SAL_CALL treeNodesRemoved( const css::awt::tree::TreeDataModelEvent& aEvent ) override;
94 virtual void SAL_CALL treeStructureChanged( const css::awt::tree::TreeDataModelEvent& aEvent ) override;
96 // XEventListener
97 void SAL_CALL disposing( const css::lang::EventObject& Source ) override;
99 // css::awt::XLayoutConstrains
100 css::awt::Size SAL_CALL getMinimumSize() override;
101 css::awt::Size SAL_CALL getPreferredSize() override;
102 css::awt::Size SAL_CALL calcAdjustedSize( const css::awt::Size& aNewSize ) override;
104 // css::awt::XVclWindowPeer
105 void SAL_CALL setProperty( const OUString& PropertyName, const css::uno::Any& Value ) override;
106 css::uno::Any SAL_CALL getProperty( const OUString& PropertyName ) override;
108 private:
109 /// @throws css::lang::IllegalArgumentException
110 UnoTreeListEntry* getEntry( const css::uno::Reference< css::awt::tree::XTreeNode >& xNode, bool bThrow = true );
112 void disposeControl();
114 bool onEditingEntry( UnoTreeListEntry const * pEntry );
115 bool onEditedEntry( UnoTreeListEntry const * pEntry, const OUString& rNewText );
117 void fillTree( UnoTreeListBoxImpl& rTree, const css::uno::Reference< css::awt::tree::XTreeDataModel >& xDataModel );
118 void addNode( UnoTreeListBoxImpl& rTree, const css::uno::Reference< css::awt::tree::XTreeNode >& xNode, UnoTreeListEntry* pParentEntry );
120 UnoTreeListEntry* createEntry( const css::uno::Reference< css::awt::tree::XTreeNode >& xNode, UnoTreeListEntry* pParent, sal_uLong nPos );
121 void updateEntry( UnoTreeListEntry* pEntry );
123 void updateTree( const css::awt::tree::TreeDataModelEvent& rEvent );
124 void updateNode( UnoTreeListBoxImpl const & rTree, const css::uno::Reference< css::awt::tree::XTreeNode >& xNode );
125 void updateChildNodes( UnoTreeListBoxImpl const & rTree, const css::uno::Reference< css::awt::tree::XTreeNode >& xParentNode, UnoTreeListEntry* pParentEntry );
127 static OUString getEntryString( const css::uno::Any& rValue );
129 /// @throws css::uno::RuntimeException
130 UnoTreeListBoxImpl& getTreeListBoxOrThrow() const;
131 /// @throws css::uno::RuntimeException
132 /// @throws css::lang::IllegalArgumentException
133 void ChangeNodesSelection( const css::uno::Any& rSelection, bool bSelect, bool bSetSelection );
135 void onChangeDataModel( UnoTreeListBoxImpl& rTree, const css::uno::Reference< css::awt::tree::XTreeDataModel >& xDataModel );
137 void onSelectionChanged();
138 void onRequestChildNodes( const css::uno::Reference< css::awt::tree::XTreeNode >& xNode );
139 bool onExpanding( const css::uno::Reference< css::awt::tree::XTreeNode >& xNode, bool bExpanding );
140 void onExpanded( const css::uno::Reference< css::awt::tree::XTreeNode >& xNode, bool bExpanding );
142 void onChangeRootDisplayed( bool bIsRootDisplayed );
144 void addEntry( UnoTreeListEntry* pEntry );
145 void removeEntry( UnoTreeListEntry const * pEntry );
147 bool loadImage( const OUString& rURL, Image& rImage );
149 private:
150 css::uno::Reference< css::awt::tree::XTreeDataModel >mxDataModel;
151 TreeSelectionListenerMultiplexer maSelectionListeners;
152 TreeExpansionListenerMultiplexer maTreeExpansionListeners;
153 TreeEditListenerMultiplexer maTreeEditListeners;
154 bool mbIsRootDisplayed;
155 VclPtr<UnoTreeListBoxImpl> mpTreeImpl;
156 sal_Int32 mnEditLock;
157 OUString msDefaultCollapsedGraphicURL;
158 OUString msDefaultExpandedGraphicURL;
159 Image maDefaultExpandedImage;
160 Image maDefaultCollapsedImage;
161 std::unique_ptr<TreeNodeMap> mpTreeNodeMap;
162 css::uno::Reference< css::graphic::XGraphicProvider > mxGraphicProvider;
166 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */