15900e8ecSAndrew Rist /**************************************************************
2cdf0e10cSrcweir *
35900e8ecSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one
45900e8ecSAndrew Rist * or more contributor license agreements. See the NOTICE file
55900e8ecSAndrew Rist * distributed with this work for additional information
65900e8ecSAndrew Rist * regarding copyright ownership. The ASF licenses this file
75900e8ecSAndrew Rist * to you under the Apache License, Version 2.0 (the
85900e8ecSAndrew Rist * "License"); you may not use this file except in compliance
95900e8ecSAndrew Rist * with the License. You may obtain a copy of the License at
10cdf0e10cSrcweir *
115900e8ecSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir *
135900e8ecSAndrew Rist * Unless required by applicable law or agreed to in writing,
145900e8ecSAndrew Rist * software distributed under the License is distributed on an
155900e8ecSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
165900e8ecSAndrew Rist * KIND, either express or implied. See the License for the
175900e8ecSAndrew Rist * specific language governing permissions and limitations
185900e8ecSAndrew Rist * under the License.
19cdf0e10cSrcweir *
205900e8ecSAndrew Rist *************************************************************/
215900e8ecSAndrew Rist
225900e8ecSAndrew Rist
23cdf0e10cSrcweir
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_svtools.hxx"
26cdf0e10cSrcweir
27cdf0e10cSrcweir #define _SVTREEBX_CXX
28cdf0e10cSrcweir #include <tools/debug.hxx>
29cdf0e10cSrcweir #include <com/sun/star/lang/XServiceInfo.hpp>
30cdf0e10cSrcweir #include <com/sun/star/lang/DisposedException.hpp>
31cdf0e10cSrcweir #include <com/sun/star/view/SelectionType.hpp>
32cdf0e10cSrcweir #include <toolkit/helper/property.hxx>
33cdf0e10cSrcweir #include <toolkit/helper/vclunohelper.hxx>
34cdf0e10cSrcweir
35cdf0e10cSrcweir #include <com/sun/star/awt/tree/XMutableTreeNode.hpp>
36cdf0e10cSrcweir #include <treecontrolpeer.hxx>
37cdf0e10cSrcweir #include <comphelper/processfactory.hxx>
38cdf0e10cSrcweir
39cdf0e10cSrcweir #include <rtl/ref.hxx>
40cdf0e10cSrcweir #include <vcl/graph.hxx>
41cdf0e10cSrcweir #include <svtools/svtreebx.hxx>
42cdf0e10cSrcweir
43cdf0e10cSrcweir #include <map>
44cdf0e10cSrcweir
45cdf0e10cSrcweir using ::rtl::OUString;
46cdf0e10cSrcweir using namespace ::com::sun::star;
47cdf0e10cSrcweir using namespace ::com::sun::star::uno;
48cdf0e10cSrcweir using namespace ::com::sun::star::lang;
49cdf0e10cSrcweir using namespace ::com::sun::star::awt::tree;
50cdf0e10cSrcweir using namespace ::com::sun::star::beans;
51cdf0e10cSrcweir using namespace ::com::sun::star::view;
52cdf0e10cSrcweir using namespace ::com::sun::star::container;
53cdf0e10cSrcweir using namespace ::com::sun::star::util;
54cdf0e10cSrcweir using namespace ::com::sun::star::graphic;
55cdf0e10cSrcweir
56cdf0e10cSrcweir #define O(x) OUString( RTL_CONSTASCII_USTRINGPARAM(x) )
57cdf0e10cSrcweir
58cdf0e10cSrcweir struct LockGuard
59cdf0e10cSrcweir {
60cdf0e10cSrcweir public:
LockGuardLockGuard61cdf0e10cSrcweir LockGuard( sal_Int32& rLock )
62cdf0e10cSrcweir : mrLock( rLock )
63cdf0e10cSrcweir {
64cdf0e10cSrcweir rLock++;
65cdf0e10cSrcweir }
66cdf0e10cSrcweir
~LockGuardLockGuard67cdf0e10cSrcweir ~LockGuard()
68cdf0e10cSrcweir {
69cdf0e10cSrcweir mrLock--;
70cdf0e10cSrcweir }
71cdf0e10cSrcweir
72cdf0e10cSrcweir sal_Int32& mrLock;
73cdf0e10cSrcweir };
74cdf0e10cSrcweir
75cdf0e10cSrcweir // --------------------------------------------------------------------
76cdf0e10cSrcweir
77cdf0e10cSrcweir class ImplGraphicItem : public SvLBoxBmp
78cdf0e10cSrcweir {
79cdf0e10cSrcweir public:
ImplGraphicItem(SvLBoxEntry * pEntry,sal_uInt16 nFlags,Image & aImage)80cdf0e10cSrcweir ImplGraphicItem( SvLBoxEntry* pEntry, sal_uInt16 nFlags, Image& aImage ) : SvLBoxBmp( pEntry, nFlags, aImage ) {}
81cdf0e10cSrcweir
82cdf0e10cSrcweir OUString msGraphicURL;
83cdf0e10cSrcweir };
84cdf0e10cSrcweir
85cdf0e10cSrcweir // --------------------------------------------------------------------
86cdf0e10cSrcweir
87cdf0e10cSrcweir class ImplContextGraphicItem : public SvLBoxContextBmp
88cdf0e10cSrcweir {
89cdf0e10cSrcweir public:
ImplContextGraphicItem(SvLBoxEntry * pEntry,sal_uInt16 nFlags,Image & rI1,Image & rI2,sal_uInt16 nEntryFlagsBmp1)90cdf0e10cSrcweir ImplContextGraphicItem( SvLBoxEntry* pEntry,sal_uInt16 nFlags,Image& rI1,Image& rI2, sal_uInt16 nEntryFlagsBmp1)
91cdf0e10cSrcweir : SvLBoxContextBmp( pEntry, nFlags, rI1, rI2, nEntryFlagsBmp1 ) {}
92cdf0e10cSrcweir
93cdf0e10cSrcweir OUString msExpandedGraphicURL;
94cdf0e10cSrcweir OUString msCollapsedGraphicURL;
95cdf0e10cSrcweir };
96cdf0e10cSrcweir
97cdf0e10cSrcweir // --------------------------------------------------------------------
98cdf0e10cSrcweir
99cdf0e10cSrcweir class UnoTreeListBoxImpl : public SvTreeListBox
100cdf0e10cSrcweir {
101cdf0e10cSrcweir public:
102cdf0e10cSrcweir UnoTreeListBoxImpl( TreeControlPeer* pPeer, Window* pParent, WinBits nWinStyle );
103cdf0e10cSrcweir ~UnoTreeListBoxImpl();
104cdf0e10cSrcweir
105cdf0e10cSrcweir sal_uInt32 insert( SvLBoxEntry* pEntry,SvLBoxEntry* pParent,sal_uLong nPos=LIST_APPEND );
106cdf0e10cSrcweir
107cdf0e10cSrcweir virtual void RequestingChilds( SvLBoxEntry* pParent );
108cdf0e10cSrcweir
109cdf0e10cSrcweir virtual sal_Bool EditingEntry( SvLBoxEntry* pEntry, Selection& );
110cdf0e10cSrcweir virtual sal_Bool EditedEntry( SvLBoxEntry* pEntry, const XubString& rNewText );
111cdf0e10cSrcweir
112cdf0e10cSrcweir DECL_LINK( OnSelectionChangeHdl, UnoTreeListBoxImpl* );
113cdf0e10cSrcweir DECL_LINK( OnExpandingHdl, UnoTreeListBoxImpl* );
114cdf0e10cSrcweir DECL_LINK( OnExpandedHdl, UnoTreeListBoxImpl* );
115cdf0e10cSrcweir
116cdf0e10cSrcweir private:
117cdf0e10cSrcweir rtl::Reference< TreeControlPeer > mxPeer;
118cdf0e10cSrcweir };
119cdf0e10cSrcweir
120cdf0e10cSrcweir // --------------------------------------------------------------------
121cdf0e10cSrcweir
122cdf0e10cSrcweir class SVT_DLLPUBLIC UnoTreeListItem : public SvLBoxItem
123cdf0e10cSrcweir {
124cdf0e10cSrcweir public:
125cdf0e10cSrcweir UnoTreeListItem( SvLBoxEntry* );
126cdf0e10cSrcweir UnoTreeListItem();
127cdf0e10cSrcweir virtual ~UnoTreeListItem();
128cdf0e10cSrcweir virtual sal_uInt16 IsA();
129cdf0e10cSrcweir void InitViewData( SvLBox*,SvLBoxEntry*,SvViewDataItem* );
130cdf0e10cSrcweir OUString GetText() const;
131cdf0e10cSrcweir void SetText( const OUString& rText );
132cdf0e10cSrcweir Image GetImage() const;
133cdf0e10cSrcweir void SetImage( const Image& rImage );
134cdf0e10cSrcweir OUString GetGraphicURL() const;
135cdf0e10cSrcweir void SetGraphicURL( const OUString& rGraphicURL );
136cdf0e10cSrcweir void Paint( const Point&, SvLBox& rDev, sal_uInt16 nFlags,SvLBoxEntry* );
137cdf0e10cSrcweir SvLBoxItem* Create() const;
138cdf0e10cSrcweir void Clone( SvLBoxItem* pSource );
139cdf0e10cSrcweir
140cdf0e10cSrcweir private:
141cdf0e10cSrcweir OUString maText;
142cdf0e10cSrcweir OUString maGraphicURL;
143cdf0e10cSrcweir Image maImage;
144cdf0e10cSrcweir };
145cdf0e10cSrcweir
146cdf0e10cSrcweir // --------------------------------------------------------------------
147cdf0e10cSrcweir
148cdf0e10cSrcweir class UnoTreeListEntry : public SvLBoxEntry
149cdf0e10cSrcweir {
150cdf0e10cSrcweir public:
151cdf0e10cSrcweir UnoTreeListEntry( const Reference< XTreeNode >& xNode, TreeControlPeer* pPeer );
152cdf0e10cSrcweir virtual ~UnoTreeListEntry();
153cdf0e10cSrcweir
154cdf0e10cSrcweir Reference< XTreeNode > mxNode;
155cdf0e10cSrcweir TreeControlPeer* mpPeer;
156cdf0e10cSrcweir };
157cdf0e10cSrcweir
158cdf0e10cSrcweir // --------------------------------------------------------------------
159cdf0e10cSrcweir
160cdf0e10cSrcweir class TreeNodeMap : public std::map< Reference< XTreeNode >, UnoTreeListEntry* >
161cdf0e10cSrcweir {
162cdf0e10cSrcweir };
163cdf0e10cSrcweir
164cdf0e10cSrcweir // --------------------------------------------------------------------
165cdf0e10cSrcweir
TreeControlPeer()166cdf0e10cSrcweir TreeControlPeer::TreeControlPeer()
167cdf0e10cSrcweir : maSelectionListeners( *this )
168cdf0e10cSrcweir , maTreeExpansionListeners( *this )
169cdf0e10cSrcweir , maTreeEditListeners( *this )
170cdf0e10cSrcweir , mpTreeImpl( 0 )
171cdf0e10cSrcweir , mnEditLock( 0 )
172cdf0e10cSrcweir , mpTreeNodeMap( 0 )
173cdf0e10cSrcweir {
174cdf0e10cSrcweir }
175cdf0e10cSrcweir
176cdf0e10cSrcweir // --------------------------------------------------------------------
177cdf0e10cSrcweir
~TreeControlPeer()178cdf0e10cSrcweir TreeControlPeer::~TreeControlPeer()
179cdf0e10cSrcweir {
180cdf0e10cSrcweir if( mpTreeImpl )
181cdf0e10cSrcweir mpTreeImpl->Clear();
182cdf0e10cSrcweir delete mpTreeNodeMap;
183cdf0e10cSrcweir }
184cdf0e10cSrcweir
185cdf0e10cSrcweir // --------------------------------------------------------------------
186cdf0e10cSrcweir
addEntry(UnoTreeListEntry * pEntry)187cdf0e10cSrcweir void TreeControlPeer::addEntry( UnoTreeListEntry* pEntry )
188cdf0e10cSrcweir {
189cdf0e10cSrcweir if( pEntry && pEntry->mxNode.is() )
190cdf0e10cSrcweir {
191cdf0e10cSrcweir if( !mpTreeNodeMap )
192cdf0e10cSrcweir {
193cdf0e10cSrcweir mpTreeNodeMap = new TreeNodeMap();
194cdf0e10cSrcweir }
195cdf0e10cSrcweir
196cdf0e10cSrcweir (*mpTreeNodeMap)[ pEntry->mxNode ] = pEntry;
197cdf0e10cSrcweir }
198cdf0e10cSrcweir }
199cdf0e10cSrcweir
200cdf0e10cSrcweir // --------------------------------------------------------------------
201cdf0e10cSrcweir
removeEntry(UnoTreeListEntry * pEntry)202cdf0e10cSrcweir void TreeControlPeer::removeEntry( UnoTreeListEntry* pEntry )
203cdf0e10cSrcweir {
204cdf0e10cSrcweir if( mpTreeNodeMap && pEntry && pEntry->mxNode.is() )
205cdf0e10cSrcweir {
206cdf0e10cSrcweir TreeNodeMap::iterator aIter( mpTreeNodeMap->find( pEntry->mxNode ) );
207cdf0e10cSrcweir if( aIter != mpTreeNodeMap->end() )
208cdf0e10cSrcweir {
209cdf0e10cSrcweir mpTreeNodeMap->erase( aIter );
210cdf0e10cSrcweir }
211cdf0e10cSrcweir }
212cdf0e10cSrcweir }
213cdf0e10cSrcweir
214cdf0e10cSrcweir // --------------------------------------------------------------------
215cdf0e10cSrcweir
getEntry(const Reference<XTreeNode> & xNode,bool bThrow)216cdf0e10cSrcweir UnoTreeListEntry* TreeControlPeer::getEntry( const Reference< XTreeNode >& xNode, bool bThrow /* = true */ ) throw( IllegalArgumentException )
217cdf0e10cSrcweir {
218cdf0e10cSrcweir if( mpTreeNodeMap )
219cdf0e10cSrcweir {
220cdf0e10cSrcweir TreeNodeMap::iterator aIter( mpTreeNodeMap->find( xNode ) );
221cdf0e10cSrcweir if( aIter != mpTreeNodeMap->end() )
222cdf0e10cSrcweir return (*aIter).second;
223cdf0e10cSrcweir }
224cdf0e10cSrcweir
225cdf0e10cSrcweir if( bThrow )
226cdf0e10cSrcweir throw IllegalArgumentException();
227cdf0e10cSrcweir
228cdf0e10cSrcweir return 0;
229cdf0e10cSrcweir }
230cdf0e10cSrcweir
231cdf0e10cSrcweir // --------------------------------------------------------------------
232cdf0e10cSrcweir
createVclControl(Window * pParent,sal_Int64 nWinStyle)233cdf0e10cSrcweir Window* TreeControlPeer::createVclControl( Window* pParent, sal_Int64 nWinStyle )
234cdf0e10cSrcweir {
235cdf0e10cSrcweir mpTreeImpl = new UnoTreeListBoxImpl( this, pParent, nWinStyle );
236cdf0e10cSrcweir return mpTreeImpl;
237cdf0e10cSrcweir }
238cdf0e10cSrcweir
239cdf0e10cSrcweir // --------------------------------------------------------------------
240cdf0e10cSrcweir
241cdf0e10cSrcweir /** called from the UnoTreeListBoxImpl when it gets deleted */
disposeControl()242cdf0e10cSrcweir void TreeControlPeer::disposeControl()
243cdf0e10cSrcweir {
244cdf0e10cSrcweir delete mpTreeNodeMap;
245cdf0e10cSrcweir mpTreeNodeMap = 0;
246cdf0e10cSrcweir mpTreeImpl = 0;
247cdf0e10cSrcweir }
248cdf0e10cSrcweir
249cdf0e10cSrcweir // --------------------------------------------------------------------
250cdf0e10cSrcweir
SetWindow(Window * pWindow)251cdf0e10cSrcweir void TreeControlPeer::SetWindow( Window* pWindow )
252cdf0e10cSrcweir {
253cdf0e10cSrcweir VCLXWindow::SetWindow( pWindow );
254cdf0e10cSrcweir }
255cdf0e10cSrcweir
256cdf0e10cSrcweir // --------------------------------------------------------------------
257cdf0e10cSrcweir
createEntry(const Reference<XTreeNode> & xNode,UnoTreeListEntry * pParent,sal_uLong nPos)258cdf0e10cSrcweir UnoTreeListEntry* TreeControlPeer::createEntry( const Reference< XTreeNode >& xNode, UnoTreeListEntry* pParent, sal_uLong nPos /* = LIST_APPEND */ )
259cdf0e10cSrcweir {
260cdf0e10cSrcweir UnoTreeListEntry* pEntry = 0;
261cdf0e10cSrcweir if( mpTreeImpl )
262cdf0e10cSrcweir {
263cdf0e10cSrcweir Image aImage;
264cdf0e10cSrcweir pEntry = new UnoTreeListEntry( xNode, this );
265cdf0e10cSrcweir ImplContextGraphicItem* pContextBmp= new ImplContextGraphicItem( pEntry,0, aImage, aImage, SVLISTENTRYFLAG_EXPANDED );
266cdf0e10cSrcweir
267cdf0e10cSrcweir pEntry->AddItem( pContextBmp );
268cdf0e10cSrcweir
269cdf0e10cSrcweir UnoTreeListItem * pUnoItem = new UnoTreeListItem( pEntry );
270cdf0e10cSrcweir
271cdf0e10cSrcweir if( xNode->getNodeGraphicURL().getLength() )
272cdf0e10cSrcweir {
273cdf0e10cSrcweir pUnoItem->SetGraphicURL( xNode->getNodeGraphicURL() );
274cdf0e10cSrcweir Image aNodeImage;
275cdf0e10cSrcweir loadImage( xNode->getNodeGraphicURL(), aNodeImage );
276cdf0e10cSrcweir pUnoItem->SetImage( aNodeImage );
277cdf0e10cSrcweir mpTreeImpl->AdjustEntryHeight( aNodeImage );
278cdf0e10cSrcweir }
279cdf0e10cSrcweir
280cdf0e10cSrcweir pEntry->AddItem( pUnoItem );
281cdf0e10cSrcweir
282cdf0e10cSrcweir mpTreeImpl->insert( pEntry, pParent, nPos );
283cdf0e10cSrcweir
284cdf0e10cSrcweir if( msDefaultExpandedGraphicURL.getLength() )
285cdf0e10cSrcweir mpTreeImpl->SetExpandedEntryBmp( pEntry, maDefaultExpandedImage );
286cdf0e10cSrcweir
287cdf0e10cSrcweir if( msDefaultCollapsedGraphicURL.getLength() )
288cdf0e10cSrcweir mpTreeImpl->SetCollapsedEntryBmp( pEntry, maDefaultCollapsedImage );
289cdf0e10cSrcweir
290cdf0e10cSrcweir updateEntry( pEntry );
291cdf0e10cSrcweir }
292cdf0e10cSrcweir return pEntry;
293cdf0e10cSrcweir }
294cdf0e10cSrcweir
295cdf0e10cSrcweir // --------------------------------------------------------------------
296cdf0e10cSrcweir
updateEntry(UnoTreeListEntry * pEntry)297cdf0e10cSrcweir bool TreeControlPeer::updateEntry( UnoTreeListEntry* pEntry )
298cdf0e10cSrcweir {
299cdf0e10cSrcweir bool bChanged = false;
300cdf0e10cSrcweir if( pEntry && pEntry->mxNode.is() && mpTreeImpl )
301cdf0e10cSrcweir {
302cdf0e10cSrcweir const OUString aValue( getEntryString( pEntry->mxNode->getDisplayValue() ) );
303cdf0e10cSrcweir UnoTreeListItem* pUnoItem = dynamic_cast< UnoTreeListItem* >( pEntry->GetItem( 1 ) );
304cdf0e10cSrcweir if( pUnoItem )
305cdf0e10cSrcweir {
306cdf0e10cSrcweir if( aValue != pUnoItem->GetText() )
307cdf0e10cSrcweir {
308cdf0e10cSrcweir pUnoItem->SetText( aValue );
309cdf0e10cSrcweir bChanged = true;
310cdf0e10cSrcweir }
311cdf0e10cSrcweir
312cdf0e10cSrcweir if( pUnoItem->GetGraphicURL() != pEntry->mxNode->getNodeGraphicURL() )
313cdf0e10cSrcweir {
314cdf0e10cSrcweir Image aImage;
315cdf0e10cSrcweir if( loadImage( pEntry->mxNode->getNodeGraphicURL(), aImage ) )
316cdf0e10cSrcweir {
317cdf0e10cSrcweir pUnoItem->SetGraphicURL( pEntry->mxNode->getNodeGraphicURL() );
318cdf0e10cSrcweir pUnoItem->SetImage( aImage );
319cdf0e10cSrcweir mpTreeImpl->AdjustEntryHeight( aImage );
320cdf0e10cSrcweir bChanged = true;
321cdf0e10cSrcweir }
322cdf0e10cSrcweir }
323cdf0e10cSrcweir }
324cdf0e10cSrcweir
325cdf0e10cSrcweir if( (pEntry->mxNode->hasChildrenOnDemand() == sal_True) != (pEntry->HasChildsOnDemand() == sal_True) )
326cdf0e10cSrcweir {
327cdf0e10cSrcweir pEntry->EnableChildsOnDemand( pEntry->mxNode->hasChildrenOnDemand() ? sal_True : sal_False );
328cdf0e10cSrcweir bChanged = true;
329cdf0e10cSrcweir }
330cdf0e10cSrcweir
331cdf0e10cSrcweir ImplContextGraphicItem* pContextGraphicItem = dynamic_cast< ImplContextGraphicItem* >( pEntry->GetItem( 0 ) );
332cdf0e10cSrcweir if( pContextGraphicItem )
333cdf0e10cSrcweir {
334cdf0e10cSrcweir if( pContextGraphicItem->msExpandedGraphicURL != pEntry->mxNode->getExpandedGraphicURL() )
335cdf0e10cSrcweir {
336cdf0e10cSrcweir Image aImage;
337cdf0e10cSrcweir if( loadImage( pEntry->mxNode->getExpandedGraphicURL(), aImage ) )
338cdf0e10cSrcweir {
339cdf0e10cSrcweir pContextGraphicItem->msExpandedGraphicURL = pEntry->mxNode->getExpandedGraphicURL();
340cdf0e10cSrcweir mpTreeImpl->SetExpandedEntryBmp( pEntry, aImage );
341cdf0e10cSrcweir bChanged = true;
342cdf0e10cSrcweir }
343cdf0e10cSrcweir }
344cdf0e10cSrcweir if( pContextGraphicItem->msCollapsedGraphicURL != pEntry->mxNode->getCollapsedGraphicURL() )
345cdf0e10cSrcweir {
346cdf0e10cSrcweir Image aImage;
347cdf0e10cSrcweir if( loadImage( pEntry->mxNode->getCollapsedGraphicURL(), aImage ) )
348cdf0e10cSrcweir {
349cdf0e10cSrcweir pContextGraphicItem->msCollapsedGraphicURL = pEntry->mxNode->getCollapsedGraphicURL();
350cdf0e10cSrcweir mpTreeImpl->SetCollapsedEntryBmp( pEntry, aImage );
351cdf0e10cSrcweir bChanged = true;
352cdf0e10cSrcweir }
353cdf0e10cSrcweir }
354cdf0e10cSrcweir }
355cdf0e10cSrcweir
356cdf0e10cSrcweir if( bChanged )
357cdf0e10cSrcweir mpTreeImpl->GetModel()->InvalidateEntry( pEntry );
358cdf0e10cSrcweir }
359cdf0e10cSrcweir
360cdf0e10cSrcweir return bChanged;
361cdf0e10cSrcweir }
362cdf0e10cSrcweir
363cdf0e10cSrcweir // --------------------------------------------------------------------
364cdf0e10cSrcweir
onSelectionChanged()365cdf0e10cSrcweir void TreeControlPeer::onSelectionChanged()
366cdf0e10cSrcweir {
367cdf0e10cSrcweir Reference< XInterface > xSource( static_cast< ::cppu::OWeakObject* >( this ) );
368cdf0e10cSrcweir EventObject aEvent( xSource );
369cdf0e10cSrcweir maSelectionListeners.selectionChanged( aEvent );
370cdf0e10cSrcweir }
371cdf0e10cSrcweir
372cdf0e10cSrcweir // --------------------------------------------------------------------
373cdf0e10cSrcweir
onRequestChildNodes(const Reference<XTreeNode> & xNode)374cdf0e10cSrcweir void TreeControlPeer::onRequestChildNodes( const Reference< XTreeNode >& xNode )
375cdf0e10cSrcweir {
376cdf0e10cSrcweir try
377cdf0e10cSrcweir {
378cdf0e10cSrcweir Reference< XInterface > xSource( static_cast< ::cppu::OWeakObject* >( this ) );
379cdf0e10cSrcweir TreeExpansionEvent aEvent( xSource, xNode );
380cdf0e10cSrcweir maTreeExpansionListeners.requestChildNodes( aEvent );
381cdf0e10cSrcweir }
382cdf0e10cSrcweir catch( Exception& )
383cdf0e10cSrcweir {
384cdf0e10cSrcweir }
385cdf0e10cSrcweir }
386cdf0e10cSrcweir
387cdf0e10cSrcweir // --------------------------------------------------------------------
388cdf0e10cSrcweir
onExpanding(const Reference<XTreeNode> & xNode,bool bExpanding)389cdf0e10cSrcweir bool TreeControlPeer::onExpanding( const Reference< XTreeNode >& xNode, bool bExpanding )
390cdf0e10cSrcweir {
391cdf0e10cSrcweir try
392cdf0e10cSrcweir {
393cdf0e10cSrcweir Reference< XInterface > xSource( static_cast< ::cppu::OWeakObject* >( this ) );
394cdf0e10cSrcweir TreeExpansionEvent aEvent( xSource, xNode );
395cdf0e10cSrcweir if( bExpanding )
396cdf0e10cSrcweir {
397cdf0e10cSrcweir maTreeExpansionListeners.treeExpanding( aEvent );
398cdf0e10cSrcweir }
399cdf0e10cSrcweir else
400cdf0e10cSrcweir {
401cdf0e10cSrcweir maTreeExpansionListeners.treeCollapsing( aEvent );
402cdf0e10cSrcweir }
403cdf0e10cSrcweir }
404cdf0e10cSrcweir catch( Exception& )
405cdf0e10cSrcweir {
406cdf0e10cSrcweir return false;
407cdf0e10cSrcweir }
408cdf0e10cSrcweir return true;
409cdf0e10cSrcweir }
410cdf0e10cSrcweir
411cdf0e10cSrcweir // --------------------------------------------------------------------
412cdf0e10cSrcweir
onExpanded(const Reference<XTreeNode> & xNode,bool bExpanding)413cdf0e10cSrcweir void TreeControlPeer::onExpanded( const Reference< XTreeNode >& xNode, bool bExpanding )
414cdf0e10cSrcweir {
415cdf0e10cSrcweir try
416cdf0e10cSrcweir {
417cdf0e10cSrcweir Reference< XInterface > xSource( static_cast< ::cppu::OWeakObject* >( this ) );
418cdf0e10cSrcweir TreeExpansionEvent aEvent( xSource, xNode );
419cdf0e10cSrcweir
420cdf0e10cSrcweir if( bExpanding )
421cdf0e10cSrcweir {
422cdf0e10cSrcweir maTreeExpansionListeners.treeExpanded( aEvent );
423cdf0e10cSrcweir }
424cdf0e10cSrcweir else
425cdf0e10cSrcweir {
426cdf0e10cSrcweir maTreeExpansionListeners.treeCollapsed( aEvent );
427cdf0e10cSrcweir }
428cdf0e10cSrcweir }
429cdf0e10cSrcweir catch( Exception& )
430cdf0e10cSrcweir {
431cdf0e10cSrcweir }
432cdf0e10cSrcweir }
433cdf0e10cSrcweir
434cdf0e10cSrcweir // --------------------------------------------------------------------
435cdf0e10cSrcweir
fillTree(UnoTreeListBoxImpl & rTree,const Reference<XTreeDataModel> & xDataModel)436cdf0e10cSrcweir void TreeControlPeer::fillTree( UnoTreeListBoxImpl& rTree, const Reference< XTreeDataModel >& xDataModel )
437cdf0e10cSrcweir {
438cdf0e10cSrcweir rTree.Clear();
439cdf0e10cSrcweir
440cdf0e10cSrcweir if( xDataModel.is() )
441cdf0e10cSrcweir {
442cdf0e10cSrcweir Reference< XTreeNode > xRootNode( xDataModel->getRoot() );
443cdf0e10cSrcweir if( xRootNode.is() )
444cdf0e10cSrcweir {
445cdf0e10cSrcweir if( mbIsRootDisplayed )
446cdf0e10cSrcweir {
447cdf0e10cSrcweir addNode( rTree, xRootNode, 0 );
448cdf0e10cSrcweir }
449cdf0e10cSrcweir else
450cdf0e10cSrcweir {
451cdf0e10cSrcweir const sal_Int32 nChildCount = xRootNode->getChildCount();
452cdf0e10cSrcweir for( sal_Int32 nChild = 0; nChild < nChildCount; nChild++ )
453cdf0e10cSrcweir addNode( rTree, xRootNode->getChildAt( nChild ), 0 );
454cdf0e10cSrcweir }
455cdf0e10cSrcweir }
456cdf0e10cSrcweir }
457cdf0e10cSrcweir }
458cdf0e10cSrcweir
459cdf0e10cSrcweir // --------------------------------------------------------------------
460cdf0e10cSrcweir
addNode(UnoTreeListBoxImpl & rTree,const Reference<XTreeNode> & xNode,UnoTreeListEntry * pParentEntry)461cdf0e10cSrcweir void TreeControlPeer::addNode( UnoTreeListBoxImpl& rTree, const Reference< XTreeNode >& xNode, UnoTreeListEntry* pParentEntry )
462cdf0e10cSrcweir {
463cdf0e10cSrcweir if( xNode.is() )
464cdf0e10cSrcweir {
465cdf0e10cSrcweir UnoTreeListEntry* pEntry = createEntry( xNode, pParentEntry, LIST_APPEND );
466cdf0e10cSrcweir const sal_Int32 nChildCount = xNode->getChildCount();
467cdf0e10cSrcweir for( sal_Int32 nChild = 0; nChild < nChildCount; nChild++ )
468cdf0e10cSrcweir addNode( rTree, xNode->getChildAt( nChild ), pEntry );
469cdf0e10cSrcweir }
470cdf0e10cSrcweir }
471cdf0e10cSrcweir
472cdf0e10cSrcweir // --------------------------------------------------------------------
473cdf0e10cSrcweir
getTreeListBoxOrThrow() const474cdf0e10cSrcweir UnoTreeListBoxImpl& TreeControlPeer::getTreeListBoxOrThrow() const throw (RuntimeException )
475cdf0e10cSrcweir {
476cdf0e10cSrcweir if( !mpTreeImpl )
477cdf0e10cSrcweir throw DisposedException();
478cdf0e10cSrcweir return *mpTreeImpl;
479cdf0e10cSrcweir }
480cdf0e10cSrcweir
481cdf0e10cSrcweir // --------------------------------------------------------------------
482cdf0e10cSrcweir
ChangeNodesSelection(const Any & rSelection,bool bSelect,bool bSetSelection)483cdf0e10cSrcweir void TreeControlPeer::ChangeNodesSelection( const Any& rSelection, bool bSelect, bool bSetSelection ) throw( RuntimeException, IllegalArgumentException )
484cdf0e10cSrcweir {
485cdf0e10cSrcweir ::vos::OGuard aGuard( GetMutex() );
486cdf0e10cSrcweir
487cdf0e10cSrcweir UnoTreeListBoxImpl& rTree = getTreeListBoxOrThrow();
488cdf0e10cSrcweir
489cdf0e10cSrcweir Reference< XTreeNode > xTempNode;
490cdf0e10cSrcweir Sequence< XTreeNode > aTempSeq;
491cdf0e10cSrcweir
492cdf0e10cSrcweir const Reference< XTreeNode > *pNodes = 0;
493cdf0e10cSrcweir sal_Int32 nCount = 0;
494cdf0e10cSrcweir
495cdf0e10cSrcweir if( rSelection.hasValue() )
496cdf0e10cSrcweir {
497cdf0e10cSrcweir switch( rSelection.getValueTypeClass() )
498cdf0e10cSrcweir {
499cdf0e10cSrcweir case TypeClass_INTERFACE:
500cdf0e10cSrcweir {
501cdf0e10cSrcweir rSelection >>= xTempNode;
502cdf0e10cSrcweir if( xTempNode.is() )
503cdf0e10cSrcweir {
504cdf0e10cSrcweir nCount = 1;
505cdf0e10cSrcweir pNodes = &xTempNode;
506cdf0e10cSrcweir }
507cdf0e10cSrcweir break;
508cdf0e10cSrcweir }
509cdf0e10cSrcweir case TypeClass_SEQUENCE:
510cdf0e10cSrcweir {
511cdf0e10cSrcweir if( rSelection.getValueType() == ::getCppuType( (const Sequence< Reference< XTreeNode > > *) 0 ) )
512cdf0e10cSrcweir {
513cdf0e10cSrcweir const Sequence< Reference< XTreeNode > >& rSeq( *(const Sequence< Reference< XTreeNode > > *)rSelection.getValue() );
514cdf0e10cSrcweir nCount = rSeq.getLength();
515cdf0e10cSrcweir if( nCount )
516cdf0e10cSrcweir pNodes = rSeq.getConstArray();
517cdf0e10cSrcweir }
518cdf0e10cSrcweir break;
519cdf0e10cSrcweir }
520cdf0e10cSrcweir default:
521cdf0e10cSrcweir break;
522cdf0e10cSrcweir }
523cdf0e10cSrcweir
524cdf0e10cSrcweir if( nCount == 0 )
525cdf0e10cSrcweir throw IllegalArgumentException();
526cdf0e10cSrcweir }
527cdf0e10cSrcweir
528cdf0e10cSrcweir if( bSetSelection )
529cdf0e10cSrcweir rTree.SelectAll( sal_False );
530cdf0e10cSrcweir
531cdf0e10cSrcweir if( pNodes && nCount )
532cdf0e10cSrcweir {
533cdf0e10cSrcweir while( nCount-- )
534cdf0e10cSrcweir {
535cdf0e10cSrcweir UnoTreeListEntry* pEntry = getEntry( *pNodes++ );
536cdf0e10cSrcweir rTree.Select( pEntry, bSelect ? sal_True : sal_False );
537cdf0e10cSrcweir }
538cdf0e10cSrcweir }
539cdf0e10cSrcweir }
540cdf0e10cSrcweir
541cdf0e10cSrcweir // -------------------------------------------------------------------
542cdf0e10cSrcweir // ::com::sun::star::view::XSelectionSupplier
543cdf0e10cSrcweir // -------------------------------------------------------------------
544cdf0e10cSrcweir
select(const Any & rSelection)545cdf0e10cSrcweir sal_Bool SAL_CALL TreeControlPeer::select( const Any& rSelection ) throw (IllegalArgumentException, RuntimeException)
546cdf0e10cSrcweir {
547cdf0e10cSrcweir ::vos::OGuard aGuard( GetMutex() );
548cdf0e10cSrcweir ChangeNodesSelection( rSelection, true, true );
549cdf0e10cSrcweir return sal_True;
550cdf0e10cSrcweir }
551cdf0e10cSrcweir
552cdf0e10cSrcweir // -------------------------------------------------------------------
553cdf0e10cSrcweir
getSelection()554cdf0e10cSrcweir Any SAL_CALL TreeControlPeer::getSelection() throw (RuntimeException)
555cdf0e10cSrcweir {
556cdf0e10cSrcweir ::vos::OGuard aGuard( GetMutex() );
557cdf0e10cSrcweir
558cdf0e10cSrcweir UnoTreeListBoxImpl& rTree = getTreeListBoxOrThrow();
559cdf0e10cSrcweir
560cdf0e10cSrcweir Any aRet;
561cdf0e10cSrcweir
562cdf0e10cSrcweir sal_uLong nSelectionCount = rTree.GetSelectionCount();
563cdf0e10cSrcweir if( nSelectionCount == 1 )
564cdf0e10cSrcweir {
565cdf0e10cSrcweir UnoTreeListEntry* pEntry = dynamic_cast< UnoTreeListEntry* >( rTree.FirstSelected() );
566cdf0e10cSrcweir if( pEntry && pEntry->mxNode.is() )
567cdf0e10cSrcweir aRet <<= pEntry->mxNode;
568cdf0e10cSrcweir }
569cdf0e10cSrcweir else if( nSelectionCount > 1 )
570cdf0e10cSrcweir {
571cdf0e10cSrcweir Sequence< Reference< XTreeNode > > aSelection( nSelectionCount );
572cdf0e10cSrcweir Reference< XTreeNode >* pNodes = aSelection.getArray();
573cdf0e10cSrcweir UnoTreeListEntry* pEntry = dynamic_cast< UnoTreeListEntry* >( rTree.FirstSelected() );
574cdf0e10cSrcweir while( pEntry && nSelectionCount )
575cdf0e10cSrcweir {
576cdf0e10cSrcweir *pNodes++ = pEntry->mxNode;
577cdf0e10cSrcweir pEntry = dynamic_cast< UnoTreeListEntry* >( rTree.NextSelected( pEntry ) );
578cdf0e10cSrcweir --nSelectionCount;
579cdf0e10cSrcweir }
580cdf0e10cSrcweir
581cdf0e10cSrcweir OSL_ASSERT( (pEntry == 0) && (nSelectionCount == 0) );
582cdf0e10cSrcweir aRet <<= aSelection;
583cdf0e10cSrcweir }
584cdf0e10cSrcweir
585cdf0e10cSrcweir return aRet;
586cdf0e10cSrcweir }
587cdf0e10cSrcweir
588cdf0e10cSrcweir // -------------------------------------------------------------------
589cdf0e10cSrcweir
addSelectionChangeListener(const Reference<XSelectionChangeListener> & xListener)590cdf0e10cSrcweir void SAL_CALL TreeControlPeer::addSelectionChangeListener( const Reference< XSelectionChangeListener >& xListener ) throw (RuntimeException)
591cdf0e10cSrcweir {
592cdf0e10cSrcweir maSelectionListeners.addInterface( xListener );
593cdf0e10cSrcweir }
594cdf0e10cSrcweir
595cdf0e10cSrcweir // -------------------------------------------------------------------
596cdf0e10cSrcweir
removeSelectionChangeListener(const Reference<XSelectionChangeListener> & xListener)597cdf0e10cSrcweir void SAL_CALL TreeControlPeer::removeSelectionChangeListener( const Reference< XSelectionChangeListener >& xListener ) throw (RuntimeException)
598cdf0e10cSrcweir {
599cdf0e10cSrcweir maSelectionListeners.addInterface( xListener );
600cdf0e10cSrcweir }
601cdf0e10cSrcweir
602cdf0e10cSrcweir // -------------------------------------------------------------------
603cdf0e10cSrcweir // ::com::sun::star::view::XMultiSelectionSupplier
604cdf0e10cSrcweir // -------------------------------------------------------------------
605cdf0e10cSrcweir
addSelection(const Any & rSelection)606cdf0e10cSrcweir sal_Bool SAL_CALL TreeControlPeer::addSelection( const Any& rSelection ) throw (IllegalArgumentException, RuntimeException)
607cdf0e10cSrcweir {
608cdf0e10cSrcweir ChangeNodesSelection( rSelection, true, false );
609cdf0e10cSrcweir return sal_True;
610cdf0e10cSrcweir }
611cdf0e10cSrcweir
612cdf0e10cSrcweir // -------------------------------------------------------------------
613cdf0e10cSrcweir
removeSelection(const Any & rSelection)614cdf0e10cSrcweir void SAL_CALL TreeControlPeer::removeSelection( const Any& rSelection ) throw (IllegalArgumentException, RuntimeException)
615cdf0e10cSrcweir {
616cdf0e10cSrcweir ChangeNodesSelection( rSelection, false, false );
617cdf0e10cSrcweir }
618cdf0e10cSrcweir
619cdf0e10cSrcweir // -------------------------------------------------------------------
620cdf0e10cSrcweir
clearSelection()621cdf0e10cSrcweir void SAL_CALL TreeControlPeer::clearSelection() throw (RuntimeException)
622cdf0e10cSrcweir {
623cdf0e10cSrcweir ::vos::OGuard aGuard( GetMutex() );
624cdf0e10cSrcweir getTreeListBoxOrThrow().SelectAll( sal_False );
625cdf0e10cSrcweir }
626cdf0e10cSrcweir
627cdf0e10cSrcweir // -------------------------------------------------------------------
628cdf0e10cSrcweir
getSelectionCount()629cdf0e10cSrcweir sal_Int32 SAL_CALL TreeControlPeer::getSelectionCount() throw (RuntimeException)
630cdf0e10cSrcweir {
631cdf0e10cSrcweir ::vos::OGuard aGuard( GetMutex() );
632cdf0e10cSrcweir return getTreeListBoxOrThrow().GetSelectionCount();
633cdf0e10cSrcweir }
634cdf0e10cSrcweir
635cdf0e10cSrcweir // -------------------------------------------------------------------
636cdf0e10cSrcweir
637cdf0e10cSrcweir class TreeSelectionEnumeration : public ::cppu::WeakImplHelper1< XEnumeration >
638cdf0e10cSrcweir {
639cdf0e10cSrcweir public:
640cdf0e10cSrcweir TreeSelectionEnumeration( std::list< Any >& rSelection );
641cdf0e10cSrcweir virtual ::sal_Bool SAL_CALL hasMoreElements() throw (RuntimeException);
642cdf0e10cSrcweir virtual Any SAL_CALL nextElement() throw (NoSuchElementException, WrappedTargetException, RuntimeException);
643cdf0e10cSrcweir
644cdf0e10cSrcweir std::list< Any > maSelection;
645cdf0e10cSrcweir std::list< Any >::iterator maIter;
646cdf0e10cSrcweir };
647cdf0e10cSrcweir
648cdf0e10cSrcweir // -------------------------------------------------------------------
649cdf0e10cSrcweir
TreeSelectionEnumeration(std::list<Any> & rSelection)650cdf0e10cSrcweir TreeSelectionEnumeration::TreeSelectionEnumeration( std::list< Any >& rSelection )
651cdf0e10cSrcweir {
652cdf0e10cSrcweir maSelection.swap( rSelection );
653cdf0e10cSrcweir maIter = maSelection.begin();
654cdf0e10cSrcweir }
655cdf0e10cSrcweir
656cdf0e10cSrcweir // -------------------------------------------------------------------
657cdf0e10cSrcweir
hasMoreElements()658cdf0e10cSrcweir ::sal_Bool SAL_CALL TreeSelectionEnumeration::hasMoreElements() throw (RuntimeException)
659cdf0e10cSrcweir {
660cdf0e10cSrcweir return maIter != maSelection.end();
661cdf0e10cSrcweir }
662cdf0e10cSrcweir
663cdf0e10cSrcweir // -------------------------------------------------------------------
664cdf0e10cSrcweir
nextElement()665cdf0e10cSrcweir Any SAL_CALL TreeSelectionEnumeration::nextElement() throw (NoSuchElementException, WrappedTargetException, RuntimeException)
666cdf0e10cSrcweir {
667cdf0e10cSrcweir if( maIter == maSelection.end() )
668cdf0e10cSrcweir throw NoSuchElementException();
669cdf0e10cSrcweir
670cdf0e10cSrcweir return (*maIter++);
671cdf0e10cSrcweir }
672cdf0e10cSrcweir
673cdf0e10cSrcweir // -------------------------------------------------------------------
674cdf0e10cSrcweir
createSelectionEnumeration()675cdf0e10cSrcweir Reference< XEnumeration > SAL_CALL TreeControlPeer::createSelectionEnumeration() throw (RuntimeException)
676cdf0e10cSrcweir {
677cdf0e10cSrcweir ::vos::OGuard aGuard( GetMutex() );
678cdf0e10cSrcweir
679cdf0e10cSrcweir UnoTreeListBoxImpl& rTree = getTreeListBoxOrThrow();
680cdf0e10cSrcweir
681cdf0e10cSrcweir sal_uInt32 nSelectionCount = rTree.GetSelectionCount();
682cdf0e10cSrcweir std::list< Any > aSelection( nSelectionCount );
683cdf0e10cSrcweir
684cdf0e10cSrcweir UnoTreeListEntry* pEntry = dynamic_cast< UnoTreeListEntry* >( rTree.FirstSelected() );
685cdf0e10cSrcweir while( pEntry && nSelectionCount )
686cdf0e10cSrcweir {
687cdf0e10cSrcweir aSelection.push_back( Any( pEntry->mxNode ) );
688cdf0e10cSrcweir pEntry = dynamic_cast< UnoTreeListEntry* >( rTree.NextSelected( pEntry ) );
689cdf0e10cSrcweir --nSelectionCount;
690cdf0e10cSrcweir }
691cdf0e10cSrcweir
692cdf0e10cSrcweir OSL_ASSERT( (pEntry == 0) && (nSelectionCount == 0) );
693cdf0e10cSrcweir
694cdf0e10cSrcweir return Reference< XEnumeration >( new TreeSelectionEnumeration( aSelection ) );
695cdf0e10cSrcweir }
696cdf0e10cSrcweir
697cdf0e10cSrcweir // -------------------------------------------------------------------
698cdf0e10cSrcweir
createReverseSelectionEnumeration()699cdf0e10cSrcweir Reference< XEnumeration > SAL_CALL TreeControlPeer::createReverseSelectionEnumeration() throw (RuntimeException)
700cdf0e10cSrcweir {
701cdf0e10cSrcweir ::vos::OGuard aGuard( GetMutex() );
702cdf0e10cSrcweir
703cdf0e10cSrcweir UnoTreeListBoxImpl& rTree = getTreeListBoxOrThrow();
704cdf0e10cSrcweir
705cdf0e10cSrcweir sal_uInt32 nSelectionCount = rTree.GetSelectionCount();
706cdf0e10cSrcweir std::list< Any > aSelection;
707cdf0e10cSrcweir
708cdf0e10cSrcweir UnoTreeListEntry* pEntry = dynamic_cast< UnoTreeListEntry* >( rTree.FirstSelected() );
709cdf0e10cSrcweir while( pEntry && nSelectionCount )
710cdf0e10cSrcweir {
711cdf0e10cSrcweir aSelection.push_front( Any( pEntry->mxNode ) );
712cdf0e10cSrcweir pEntry = dynamic_cast< UnoTreeListEntry* >( rTree.NextSelected( pEntry ) );
713cdf0e10cSrcweir --nSelectionCount;
714cdf0e10cSrcweir }
715cdf0e10cSrcweir
716cdf0e10cSrcweir OSL_ASSERT( (pEntry == 0) && (nSelectionCount == 0) );
717cdf0e10cSrcweir
718cdf0e10cSrcweir return Reference< XEnumeration >( new TreeSelectionEnumeration( aSelection ) );
719cdf0e10cSrcweir }
720cdf0e10cSrcweir
721cdf0e10cSrcweir // --------------------------------------------------------------------
722cdf0e10cSrcweir // ::com::sun::star::awt::XTreeControl
723cdf0e10cSrcweir // --------------------------------------------------------------------
724cdf0e10cSrcweir
getDefaultExpandedGraphicURL()725cdf0e10cSrcweir OUString SAL_CALL TreeControlPeer::getDefaultExpandedGraphicURL() throw (::com::sun::star::uno::RuntimeException)
726cdf0e10cSrcweir {
727cdf0e10cSrcweir ::vos::OGuard aGuard( GetMutex() );
728cdf0e10cSrcweir return msDefaultExpandedGraphicURL;
729cdf0e10cSrcweir }
730cdf0e10cSrcweir
731cdf0e10cSrcweir // --------------------------------------------------------------------
732cdf0e10cSrcweir
setDefaultExpandedGraphicURL(const::rtl::OUString & sDefaultExpandedGraphicURL)733cdf0e10cSrcweir void SAL_CALL TreeControlPeer::setDefaultExpandedGraphicURL( const ::rtl::OUString& sDefaultExpandedGraphicURL ) throw (::com::sun::star::uno::RuntimeException)
734cdf0e10cSrcweir {
735cdf0e10cSrcweir ::vos::OGuard aGuard( GetMutex() );
736cdf0e10cSrcweir if( msDefaultExpandedGraphicURL != sDefaultExpandedGraphicURL )
737cdf0e10cSrcweir {
738cdf0e10cSrcweir if( sDefaultExpandedGraphicURL.getLength() )
739cdf0e10cSrcweir loadImage( sDefaultExpandedGraphicURL, maDefaultExpandedImage );
740cdf0e10cSrcweir else
741cdf0e10cSrcweir maDefaultExpandedImage = Image();
742cdf0e10cSrcweir
743cdf0e10cSrcweir UnoTreeListBoxImpl& rTree = getTreeListBoxOrThrow();
744cdf0e10cSrcweir
745cdf0e10cSrcweir SvLBoxEntry* pEntry = rTree.First();
746cdf0e10cSrcweir while( pEntry )
747cdf0e10cSrcweir {
748cdf0e10cSrcweir ImplContextGraphicItem* pContextGraphicItem = dynamic_cast< ImplContextGraphicItem* >( pEntry->GetItem( 0 ) );
749cdf0e10cSrcweir if( pContextGraphicItem )
750cdf0e10cSrcweir {
751cdf0e10cSrcweir if( pContextGraphicItem->msExpandedGraphicURL.getLength() == 0 )
752cdf0e10cSrcweir rTree.SetExpandedEntryBmp( pEntry, maDefaultExpandedImage );
753cdf0e10cSrcweir }
754cdf0e10cSrcweir pEntry = rTree.Next( pEntry );
755cdf0e10cSrcweir }
756cdf0e10cSrcweir
757cdf0e10cSrcweir msDefaultExpandedGraphicURL = sDefaultExpandedGraphicURL;
758cdf0e10cSrcweir }
759cdf0e10cSrcweir }
760cdf0e10cSrcweir
761cdf0e10cSrcweir // --------------------------------------------------------------------
762cdf0e10cSrcweir
getDefaultCollapsedGraphicURL()763cdf0e10cSrcweir OUString SAL_CALL TreeControlPeer::getDefaultCollapsedGraphicURL() throw (::com::sun::star::uno::RuntimeException)
764cdf0e10cSrcweir {
765cdf0e10cSrcweir ::vos::OGuard aGuard( GetMutex() );
766cdf0e10cSrcweir return msDefaultCollapsedGraphicURL;
767cdf0e10cSrcweir }
768cdf0e10cSrcweir
769cdf0e10cSrcweir // --------------------------------------------------------------------
770cdf0e10cSrcweir
setDefaultCollapsedGraphicURL(const::rtl::OUString & sDefaultCollapsedGraphicURL)771cdf0e10cSrcweir void SAL_CALL TreeControlPeer::setDefaultCollapsedGraphicURL( const ::rtl::OUString& sDefaultCollapsedGraphicURL ) throw (::com::sun::star::uno::RuntimeException)
772cdf0e10cSrcweir {
773cdf0e10cSrcweir ::vos::OGuard aGuard( GetMutex() );
774cdf0e10cSrcweir if( msDefaultCollapsedGraphicURL != sDefaultCollapsedGraphicURL )
775cdf0e10cSrcweir {
776cdf0e10cSrcweir if( sDefaultCollapsedGraphicURL.getLength() )
777cdf0e10cSrcweir loadImage( sDefaultCollapsedGraphicURL, maDefaultCollapsedImage );
778cdf0e10cSrcweir else
779cdf0e10cSrcweir maDefaultCollapsedImage = Image();
780cdf0e10cSrcweir
781cdf0e10cSrcweir UnoTreeListBoxImpl& rTree = getTreeListBoxOrThrow();
782cdf0e10cSrcweir
783cdf0e10cSrcweir SvLBoxEntry* pEntry = rTree.First();
784cdf0e10cSrcweir while( pEntry )
785cdf0e10cSrcweir {
786cdf0e10cSrcweir ImplContextGraphicItem* pContextGraphicItem = dynamic_cast< ImplContextGraphicItem* >( pEntry->GetItem( 0 ) );
787cdf0e10cSrcweir if( pContextGraphicItem )
788cdf0e10cSrcweir {
789cdf0e10cSrcweir if( pContextGraphicItem->msCollapsedGraphicURL.getLength() == 0 )
790cdf0e10cSrcweir rTree.SetCollapsedEntryBmp( pEntry, maDefaultCollapsedImage );
791cdf0e10cSrcweir }
792cdf0e10cSrcweir pEntry = rTree.Next( pEntry );
793cdf0e10cSrcweir }
794cdf0e10cSrcweir
795cdf0e10cSrcweir msDefaultCollapsedGraphicURL = sDefaultCollapsedGraphicURL;
796cdf0e10cSrcweir }
797cdf0e10cSrcweir }
798cdf0e10cSrcweir
799cdf0e10cSrcweir // --------------------------------------------------------------------
800cdf0e10cSrcweir
isNodeExpanded(const Reference<XTreeNode> & xNode)801cdf0e10cSrcweir sal_Bool SAL_CALL TreeControlPeer::isNodeExpanded( const Reference< XTreeNode >& xNode ) throw (RuntimeException, IllegalArgumentException)
802cdf0e10cSrcweir {
803cdf0e10cSrcweir ::vos::OGuard aGuard( GetMutex() );
804cdf0e10cSrcweir
805cdf0e10cSrcweir UnoTreeListBoxImpl& rTree = getTreeListBoxOrThrow();
806cdf0e10cSrcweir UnoTreeListEntry* pEntry = getEntry( xNode );
807cdf0e10cSrcweir return ( pEntry && rTree.IsExpanded( pEntry ) ) ? sal_True : sal_False;
808cdf0e10cSrcweir }
809cdf0e10cSrcweir
810cdf0e10cSrcweir // -------------------------------------------------------------------
811cdf0e10cSrcweir
isNodeCollapsed(const Reference<XTreeNode> & xNode)812cdf0e10cSrcweir sal_Bool SAL_CALL TreeControlPeer::isNodeCollapsed( const Reference< XTreeNode >& xNode ) throw (RuntimeException, IllegalArgumentException)
813cdf0e10cSrcweir {
814cdf0e10cSrcweir ::vos::OGuard aGuard( GetMutex() );
815cdf0e10cSrcweir return !isNodeExpanded( xNode );
816cdf0e10cSrcweir }
817cdf0e10cSrcweir
818cdf0e10cSrcweir // -------------------------------------------------------------------
819cdf0e10cSrcweir
makeNodeVisible(const Reference<XTreeNode> & xNode)820cdf0e10cSrcweir void SAL_CALL TreeControlPeer::makeNodeVisible( const Reference< XTreeNode >& xNode ) throw (RuntimeException, ExpandVetoException, IllegalArgumentException)
821cdf0e10cSrcweir {
822cdf0e10cSrcweir ::vos::OGuard aGuard( GetMutex() );
823cdf0e10cSrcweir
824cdf0e10cSrcweir UnoTreeListBoxImpl& rTree = getTreeListBoxOrThrow();
825cdf0e10cSrcweir UnoTreeListEntry* pEntry = getEntry( xNode );
826cdf0e10cSrcweir if( pEntry )
827cdf0e10cSrcweir rTree.MakeVisible( pEntry );
828cdf0e10cSrcweir }
829cdf0e10cSrcweir
830cdf0e10cSrcweir // -------------------------------------------------------------------
831cdf0e10cSrcweir
isNodeVisible(const Reference<XTreeNode> & xNode)832cdf0e10cSrcweir sal_Bool SAL_CALL TreeControlPeer::isNodeVisible( const Reference< XTreeNode >& xNode ) throw (RuntimeException, IllegalArgumentException)
833cdf0e10cSrcweir {
834cdf0e10cSrcweir ::vos::OGuard aGuard( GetMutex() );
835cdf0e10cSrcweir
836cdf0e10cSrcweir UnoTreeListBoxImpl& rTree = getTreeListBoxOrThrow();
837cdf0e10cSrcweir UnoTreeListEntry* pEntry = getEntry( xNode );
838cdf0e10cSrcweir return ( pEntry && rTree.IsEntryVisible( pEntry ) ) ? sal_True : sal_False;
839cdf0e10cSrcweir }
840cdf0e10cSrcweir
841cdf0e10cSrcweir // -------------------------------------------------------------------
842cdf0e10cSrcweir
expandNode(const Reference<XTreeNode> & xNode)843cdf0e10cSrcweir void SAL_CALL TreeControlPeer::expandNode( const Reference< XTreeNode >& xNode ) throw (RuntimeException, ExpandVetoException, IllegalArgumentException)
844cdf0e10cSrcweir {
845cdf0e10cSrcweir ::vos::OGuard aGuard( GetMutex() );
846cdf0e10cSrcweir
847cdf0e10cSrcweir UnoTreeListBoxImpl& rTree = getTreeListBoxOrThrow();
848cdf0e10cSrcweir UnoTreeListEntry* pEntry = getEntry( xNode );
849cdf0e10cSrcweir if( pEntry )
850cdf0e10cSrcweir rTree.Expand( pEntry );
851cdf0e10cSrcweir }
852cdf0e10cSrcweir
853cdf0e10cSrcweir // -------------------------------------------------------------------
854cdf0e10cSrcweir
collapseNode(const Reference<XTreeNode> & xNode)855cdf0e10cSrcweir void SAL_CALL TreeControlPeer::collapseNode( const Reference< XTreeNode >& xNode ) throw (RuntimeException, ExpandVetoException, IllegalArgumentException)
856cdf0e10cSrcweir {
857cdf0e10cSrcweir ::vos::OGuard aGuard( GetMutex() );
858cdf0e10cSrcweir
859cdf0e10cSrcweir UnoTreeListBoxImpl& rTree = getTreeListBoxOrThrow();
860cdf0e10cSrcweir UnoTreeListEntry* pEntry = getEntry( xNode );
861cdf0e10cSrcweir if( pEntry )
862cdf0e10cSrcweir rTree.Collapse( pEntry );
863cdf0e10cSrcweir }
864cdf0e10cSrcweir
865cdf0e10cSrcweir // -------------------------------------------------------------------
866cdf0e10cSrcweir
addTreeExpansionListener(const Reference<XTreeExpansionListener> & xListener)867cdf0e10cSrcweir void SAL_CALL TreeControlPeer::addTreeExpansionListener( const Reference< XTreeExpansionListener >& xListener ) throw (RuntimeException)
868cdf0e10cSrcweir {
869cdf0e10cSrcweir maTreeExpansionListeners.addInterface( xListener );
870cdf0e10cSrcweir }
871cdf0e10cSrcweir
872cdf0e10cSrcweir // -------------------------------------------------------------------
873cdf0e10cSrcweir
removeTreeExpansionListener(const Reference<XTreeExpansionListener> & xListener)874cdf0e10cSrcweir void SAL_CALL TreeControlPeer::removeTreeExpansionListener( const Reference< XTreeExpansionListener >& xListener ) throw (RuntimeException)
875cdf0e10cSrcweir {
876cdf0e10cSrcweir maTreeExpansionListeners.removeInterface( xListener );
877cdf0e10cSrcweir }
878cdf0e10cSrcweir
879cdf0e10cSrcweir // -------------------------------------------------------------------
880cdf0e10cSrcweir
getNodeForLocation(sal_Int32 x,sal_Int32 y)881cdf0e10cSrcweir Reference< XTreeNode > SAL_CALL TreeControlPeer::getNodeForLocation( sal_Int32 x, sal_Int32 y ) throw (RuntimeException)
882cdf0e10cSrcweir {
883cdf0e10cSrcweir ::vos::OGuard aGuard( GetMutex() );
884cdf0e10cSrcweir
885cdf0e10cSrcweir UnoTreeListBoxImpl& rTree = getTreeListBoxOrThrow();
886cdf0e10cSrcweir
887cdf0e10cSrcweir Reference< XTreeNode > xNode;
888cdf0e10cSrcweir
889cdf0e10cSrcweir const Point aPos( x, y );
890cdf0e10cSrcweir UnoTreeListEntry* pEntry = dynamic_cast< UnoTreeListEntry* >( rTree.GetEntry( aPos, sal_True ) );
891cdf0e10cSrcweir if( pEntry )
892cdf0e10cSrcweir xNode = pEntry->mxNode;
893cdf0e10cSrcweir
894cdf0e10cSrcweir return xNode;
895cdf0e10cSrcweir }
896cdf0e10cSrcweir
897cdf0e10cSrcweir // -------------------------------------------------------------------
898cdf0e10cSrcweir
getClosestNodeForLocation(sal_Int32 x,sal_Int32 y)899cdf0e10cSrcweir Reference< XTreeNode > SAL_CALL TreeControlPeer::getClosestNodeForLocation( sal_Int32 x, sal_Int32 y ) throw (RuntimeException)
900cdf0e10cSrcweir {
901cdf0e10cSrcweir ::vos::OGuard aGuard( GetMutex() );
902cdf0e10cSrcweir
903cdf0e10cSrcweir UnoTreeListBoxImpl& rTree = getTreeListBoxOrThrow();
904cdf0e10cSrcweir
905cdf0e10cSrcweir Reference< XTreeNode > xNode;
906cdf0e10cSrcweir
907cdf0e10cSrcweir const Point aPos( x, y );
908cdf0e10cSrcweir UnoTreeListEntry* pEntry = dynamic_cast< UnoTreeListEntry* >( rTree.GetEntry( aPos, sal_True ) );
909cdf0e10cSrcweir if( pEntry )
910cdf0e10cSrcweir xNode = pEntry->mxNode;
911cdf0e10cSrcweir
912cdf0e10cSrcweir return xNode;
913cdf0e10cSrcweir }
914cdf0e10cSrcweir
915cdf0e10cSrcweir // -------------------------------------------------------------------
916cdf0e10cSrcweir
getNodeRect(const Reference<XTreeNode> & i_Node)917cdf0e10cSrcweir awt::Rectangle SAL_CALL TreeControlPeer::getNodeRect( const Reference< XTreeNode >& i_Node ) throw (IllegalArgumentException, RuntimeException)
918cdf0e10cSrcweir {
919cdf0e10cSrcweir ::vos::OGuard aGuard( GetMutex() );
920cdf0e10cSrcweir
921cdf0e10cSrcweir UnoTreeListBoxImpl& rTree = getTreeListBoxOrThrow();
922cdf0e10cSrcweir UnoTreeListEntry* pEntry = getEntry( i_Node, true );
923cdf0e10cSrcweir
924cdf0e10cSrcweir ::Rectangle aEntryRect( rTree.GetFocusRect( pEntry, rTree.GetEntryPosition( pEntry ).Y() ) );
925cdf0e10cSrcweir return VCLUnoHelper::ConvertToAWTRect( aEntryRect );
926cdf0e10cSrcweir }
927cdf0e10cSrcweir
928cdf0e10cSrcweir // -------------------------------------------------------------------
929cdf0e10cSrcweir
isEditing()930cdf0e10cSrcweir sal_Bool SAL_CALL TreeControlPeer::isEditing( ) throw (RuntimeException)
931cdf0e10cSrcweir {
932cdf0e10cSrcweir ::vos::OGuard aGuard( GetMutex() );
933cdf0e10cSrcweir
934cdf0e10cSrcweir UnoTreeListBoxImpl& rTree = getTreeListBoxOrThrow();
935cdf0e10cSrcweir return rTree.IsEditingActive() ? sal_True : sal_False;
936cdf0e10cSrcweir }
937cdf0e10cSrcweir
938cdf0e10cSrcweir // -------------------------------------------------------------------
939cdf0e10cSrcweir
stopEditing()940cdf0e10cSrcweir sal_Bool SAL_CALL TreeControlPeer::stopEditing() throw (RuntimeException)
941cdf0e10cSrcweir {
942cdf0e10cSrcweir ::vos::OGuard aGuard( GetMutex() );
943cdf0e10cSrcweir
944cdf0e10cSrcweir UnoTreeListBoxImpl& rTree = getTreeListBoxOrThrow();
945cdf0e10cSrcweir if( rTree.IsEditingActive() )
946cdf0e10cSrcweir {
947cdf0e10cSrcweir rTree.EndEditing(sal_False);
948cdf0e10cSrcweir return sal_True;
949cdf0e10cSrcweir }
950cdf0e10cSrcweir else
951cdf0e10cSrcweir {
952cdf0e10cSrcweir return sal_False;
953cdf0e10cSrcweir }
954cdf0e10cSrcweir }
955cdf0e10cSrcweir
956cdf0e10cSrcweir // -------------------------------------------------------------------
957cdf0e10cSrcweir
cancelEditing()958cdf0e10cSrcweir void SAL_CALL TreeControlPeer::cancelEditing( ) throw (RuntimeException)
959cdf0e10cSrcweir {
960cdf0e10cSrcweir ::vos::OGuard aGuard( GetMutex() );
961cdf0e10cSrcweir
962cdf0e10cSrcweir UnoTreeListBoxImpl& rTree = getTreeListBoxOrThrow();
963cdf0e10cSrcweir rTree.EndEditing(sal_False);
964cdf0e10cSrcweir }
965cdf0e10cSrcweir
966cdf0e10cSrcweir // -------------------------------------------------------------------
967cdf0e10cSrcweir
startEditingAtNode(const Reference<XTreeNode> & xNode)968cdf0e10cSrcweir void SAL_CALL TreeControlPeer::startEditingAtNode( const Reference< XTreeNode >& xNode ) throw (IllegalArgumentException, RuntimeException)
969cdf0e10cSrcweir {
970cdf0e10cSrcweir ::vos::OGuard aGuard( GetMutex() );
971cdf0e10cSrcweir
972cdf0e10cSrcweir UnoTreeListBoxImpl& rTree = getTreeListBoxOrThrow();
973cdf0e10cSrcweir UnoTreeListEntry* pEntry = getEntry( xNode );
974cdf0e10cSrcweir rTree.EditEntry( pEntry );
975cdf0e10cSrcweir }
976cdf0e10cSrcweir
addTreeEditListener(const Reference<XTreeEditListener> & xListener)977cdf0e10cSrcweir void SAL_CALL TreeControlPeer::addTreeEditListener( const Reference< XTreeEditListener >& xListener ) throw (RuntimeException)
978cdf0e10cSrcweir {
979cdf0e10cSrcweir maTreeEditListeners.addInterface( xListener );
980cdf0e10cSrcweir }
981cdf0e10cSrcweir
removeTreeEditListener(const Reference<XTreeEditListener> & xListener)982cdf0e10cSrcweir void SAL_CALL TreeControlPeer::removeTreeEditListener( const Reference< XTreeEditListener >& xListener ) throw (RuntimeException)
983cdf0e10cSrcweir {
984cdf0e10cSrcweir maTreeEditListeners.removeInterface( xListener );
985cdf0e10cSrcweir }
986cdf0e10cSrcweir
onEditingEntry(UnoTreeListEntry * pEntry)987cdf0e10cSrcweir bool TreeControlPeer::onEditingEntry( UnoTreeListEntry* pEntry )
988cdf0e10cSrcweir {
989cdf0e10cSrcweir if( mpTreeImpl && pEntry && pEntry->mxNode.is() && (maTreeEditListeners.getLength() > 0) )
990cdf0e10cSrcweir {
991cdf0e10cSrcweir try
992cdf0e10cSrcweir {
993cdf0e10cSrcweir maTreeEditListeners.nodeEditing( pEntry->mxNode );
994cdf0e10cSrcweir }
995cdf0e10cSrcweir catch( VetoException& )
996cdf0e10cSrcweir {
997cdf0e10cSrcweir return false;
998cdf0e10cSrcweir }
999cdf0e10cSrcweir catch( Exception& )
1000cdf0e10cSrcweir {
1001cdf0e10cSrcweir }
1002cdf0e10cSrcweir }
1003cdf0e10cSrcweir return true;
1004cdf0e10cSrcweir }
1005cdf0e10cSrcweir
onEditedEntry(UnoTreeListEntry * pEntry,const XubString & rNewText)1006cdf0e10cSrcweir bool TreeControlPeer::onEditedEntry( UnoTreeListEntry* pEntry, const XubString& rNewText )
1007cdf0e10cSrcweir {
1008cdf0e10cSrcweir if( mpTreeImpl && pEntry && pEntry->mxNode.is() ) try
1009cdf0e10cSrcweir {
1010cdf0e10cSrcweir LockGuard aLockGuard( mnEditLock );
1011cdf0e10cSrcweir const OUString aNewText( rNewText );
1012cdf0e10cSrcweir if( maTreeEditListeners.getLength() > 0 )
1013cdf0e10cSrcweir {
1014cdf0e10cSrcweir maTreeEditListeners.nodeEdited( pEntry->mxNode, aNewText );
1015cdf0e10cSrcweir return false;
1016cdf0e10cSrcweir }
1017cdf0e10cSrcweir else
1018cdf0e10cSrcweir {
1019cdf0e10cSrcweir Reference< XMutableTreeNode > xMutableNode( pEntry->mxNode, UNO_QUERY );
1020cdf0e10cSrcweir if( xMutableNode.is() )
1021cdf0e10cSrcweir xMutableNode->setDisplayValue( Any( aNewText ) );
1022cdf0e10cSrcweir else
1023cdf0e10cSrcweir return false;
1024cdf0e10cSrcweir }
1025cdf0e10cSrcweir
1026cdf0e10cSrcweir }
1027cdf0e10cSrcweir catch( Exception& )
1028cdf0e10cSrcweir {
1029cdf0e10cSrcweir }
1030cdf0e10cSrcweir
1031cdf0e10cSrcweir return true;
1032cdf0e10cSrcweir }
1033cdf0e10cSrcweir
1034cdf0e10cSrcweir // --------------------------------------------------------------------
1035cdf0e10cSrcweir // ::com::sun::star::awt::tree::TreeDataModelListener
1036cdf0e10cSrcweir // --------------------------------------------------------------------
1037cdf0e10cSrcweir
treeNodesChanged(const::com::sun::star::awt::tree::TreeDataModelEvent & rEvent)1038cdf0e10cSrcweir void SAL_CALL TreeControlPeer::treeNodesChanged( const ::com::sun::star::awt::tree::TreeDataModelEvent& rEvent ) throw (RuntimeException)
1039cdf0e10cSrcweir {
1040cdf0e10cSrcweir ::vos::OGuard aGuard( GetMutex() );
1041cdf0e10cSrcweir
1042cdf0e10cSrcweir if( mnEditLock != 0 )
1043cdf0e10cSrcweir return;
1044cdf0e10cSrcweir
1045cdf0e10cSrcweir updateTree( rEvent, true );
1046cdf0e10cSrcweir }
1047cdf0e10cSrcweir
treeNodesInserted(const::com::sun::star::awt::tree::TreeDataModelEvent & rEvent)1048cdf0e10cSrcweir void SAL_CALL TreeControlPeer::treeNodesInserted( const ::com::sun::star::awt::tree::TreeDataModelEvent& rEvent ) throw (RuntimeException)
1049cdf0e10cSrcweir {
1050cdf0e10cSrcweir ::vos::OGuard aGuard( GetMutex() );
1051cdf0e10cSrcweir
1052cdf0e10cSrcweir if( mnEditLock != 0 )
1053cdf0e10cSrcweir return;
1054cdf0e10cSrcweir
1055cdf0e10cSrcweir updateTree( rEvent, true );
1056cdf0e10cSrcweir }
1057cdf0e10cSrcweir
treeNodesRemoved(const::com::sun::star::awt::tree::TreeDataModelEvent & rEvent)1058cdf0e10cSrcweir void SAL_CALL TreeControlPeer::treeNodesRemoved( const ::com::sun::star::awt::tree::TreeDataModelEvent& rEvent ) throw (RuntimeException)
1059cdf0e10cSrcweir {
1060cdf0e10cSrcweir ::vos::OGuard aGuard( GetMutex() );
1061cdf0e10cSrcweir
1062cdf0e10cSrcweir if( mnEditLock != 0 )
1063cdf0e10cSrcweir return;
1064cdf0e10cSrcweir
1065cdf0e10cSrcweir updateTree( rEvent, true );
1066cdf0e10cSrcweir }
1067cdf0e10cSrcweir
treeStructureChanged(const::com::sun::star::awt::tree::TreeDataModelEvent & rEvent)1068cdf0e10cSrcweir void SAL_CALL TreeControlPeer::treeStructureChanged( const ::com::sun::star::awt::tree::TreeDataModelEvent& rEvent ) throw (RuntimeException)
1069cdf0e10cSrcweir {
1070cdf0e10cSrcweir ::vos::OGuard aGuard( GetMutex() );
1071cdf0e10cSrcweir
1072cdf0e10cSrcweir if( mnEditLock != 0 )
1073cdf0e10cSrcweir return;
1074cdf0e10cSrcweir
1075cdf0e10cSrcweir updateTree( rEvent, true );
1076cdf0e10cSrcweir }
1077cdf0e10cSrcweir
updateTree(const::com::sun::star::awt::tree::TreeDataModelEvent & rEvent,bool bRecursive)1078cdf0e10cSrcweir void TreeControlPeer::updateTree( const ::com::sun::star::awt::tree::TreeDataModelEvent& rEvent, bool bRecursive )
1079cdf0e10cSrcweir {
1080cdf0e10cSrcweir UnoTreeListBoxImpl& rTree = getTreeListBoxOrThrow();
1081cdf0e10cSrcweir
1082cdf0e10cSrcweir Sequence< Reference< XTreeNode > > Nodes;
1083cdf0e10cSrcweir Reference< XTreeNode > xNode( rEvent.ParentNode );
1084cdf0e10cSrcweir if( !xNode.is() && Nodes.getLength() )
1085cdf0e10cSrcweir {
1086cdf0e10cSrcweir xNode = Nodes[0];
1087cdf0e10cSrcweir }
1088cdf0e10cSrcweir
1089cdf0e10cSrcweir if( xNode.is() )
1090cdf0e10cSrcweir updateNode( rTree, xNode, bRecursive );
1091cdf0e10cSrcweir }
1092cdf0e10cSrcweir
updateNode(UnoTreeListBoxImpl & rTree,const Reference<XTreeNode> & xNode,bool bRecursive)1093cdf0e10cSrcweir void TreeControlPeer::updateNode( UnoTreeListBoxImpl& rTree, const Reference< XTreeNode >& xNode, bool bRecursive )
1094cdf0e10cSrcweir {
1095cdf0e10cSrcweir if( xNode.is() )
1096cdf0e10cSrcweir {
1097cdf0e10cSrcweir UnoTreeListEntry* pNodeEntry = getEntry( xNode, false );
1098cdf0e10cSrcweir
1099cdf0e10cSrcweir if( !pNodeEntry )
1100cdf0e10cSrcweir {
1101cdf0e10cSrcweir Reference< XTreeNode > xParentNode( xNode->getParent() );
1102cdf0e10cSrcweir UnoTreeListEntry* pParentEntry = 0;
1103cdf0e10cSrcweir sal_uLong nChild = LIST_APPEND;
1104cdf0e10cSrcweir
1105cdf0e10cSrcweir if( xParentNode.is() )
1106cdf0e10cSrcweir {
1107cdf0e10cSrcweir pParentEntry = getEntry( xParentNode );
1108cdf0e10cSrcweir nChild = xParentNode->getIndex( xNode );
1109cdf0e10cSrcweir }
1110cdf0e10cSrcweir
1111cdf0e10cSrcweir pNodeEntry = createEntry( xNode, pParentEntry, nChild );
1112cdf0e10cSrcweir }
1113cdf0e10cSrcweir
1114cdf0e10cSrcweir if( bRecursive )
1115cdf0e10cSrcweir updateChildNodes( rTree, xNode, pNodeEntry );
1116cdf0e10cSrcweir }
1117cdf0e10cSrcweir }
1118cdf0e10cSrcweir
updateChildNodes(UnoTreeListBoxImpl & rTree,const Reference<XTreeNode> & xParentNode,UnoTreeListEntry * pParentEntry)1119cdf0e10cSrcweir void TreeControlPeer::updateChildNodes( UnoTreeListBoxImpl& rTree, const Reference< XTreeNode >& xParentNode, UnoTreeListEntry* pParentEntry )
1120cdf0e10cSrcweir {
1121cdf0e10cSrcweir if( xParentNode.is() && pParentEntry )
1122cdf0e10cSrcweir {
1123cdf0e10cSrcweir UnoTreeListEntry* pCurrentChild = dynamic_cast< UnoTreeListEntry* >( rTree.FirstChild( pParentEntry ) );
1124cdf0e10cSrcweir
1125cdf0e10cSrcweir const sal_Int32 nChildCount = xParentNode->getChildCount();
1126cdf0e10cSrcweir for( sal_Int32 nChild = 0; nChild < nChildCount; nChild++ )
1127cdf0e10cSrcweir {
1128cdf0e10cSrcweir Reference< XTreeNode > xNode( xParentNode->getChildAt( nChild ) );
1129cdf0e10cSrcweir if( !pCurrentChild || ( pCurrentChild->mxNode != xNode ) )
1130cdf0e10cSrcweir {
1131cdf0e10cSrcweir UnoTreeListEntry* pNodeEntry = getEntry( xNode, false );
1132cdf0e10cSrcweir if( pNodeEntry == 0 )
1133cdf0e10cSrcweir {
1134cdf0e10cSrcweir // child node is not yet part of the tree, add it
1135cdf0e10cSrcweir pCurrentChild = createEntry( xNode, pParentEntry, nChild );
1136cdf0e10cSrcweir }
1137cdf0e10cSrcweir else if( pNodeEntry != pCurrentChild )
1138cdf0e10cSrcweir {
1139cdf0e10cSrcweir // node is already part of the tree, but not on the correct position
1140cdf0e10cSrcweir rTree.GetModel()->Move( pNodeEntry, pParentEntry, nChild );
1141cdf0e10cSrcweir pCurrentChild = pNodeEntry;
1142cdf0e10cSrcweir updateEntry( pCurrentChild );
1143cdf0e10cSrcweir }
1144cdf0e10cSrcweir }
1145cdf0e10cSrcweir else
1146cdf0e10cSrcweir {
1147cdf0e10cSrcweir // child node has entry and entry is equal to current entry,
1148cdf0e10cSrcweir // so no structural changes happened
1149cdf0e10cSrcweir updateEntry( pCurrentChild );
1150cdf0e10cSrcweir }
1151cdf0e10cSrcweir
1152cdf0e10cSrcweir pCurrentChild = dynamic_cast< UnoTreeListEntry* >( rTree.NextSibling( pCurrentChild ) );
1153cdf0e10cSrcweir }
1154cdf0e10cSrcweir
1155cdf0e10cSrcweir // check if we have entries without nodes left, we need to remove them
1156cdf0e10cSrcweir while( pCurrentChild )
1157cdf0e10cSrcweir {
1158cdf0e10cSrcweir UnoTreeListEntry* pNextChild = dynamic_cast< UnoTreeListEntry* >( rTree.NextSibling( pCurrentChild ) );
1159cdf0e10cSrcweir rTree.GetModel()->Remove( pCurrentChild );
1160cdf0e10cSrcweir pCurrentChild = pNextChild;
1161cdf0e10cSrcweir }
1162cdf0e10cSrcweir }
1163cdf0e10cSrcweir }
1164cdf0e10cSrcweir
getEntryString(const Any & rValue)1165cdf0e10cSrcweir OUString TreeControlPeer::getEntryString( const Any& rValue )
1166cdf0e10cSrcweir {
1167cdf0e10cSrcweir OUString sValue;
1168cdf0e10cSrcweir if( rValue.hasValue() )
1169cdf0e10cSrcweir {
1170cdf0e10cSrcweir switch( rValue.getValueTypeClass() )
1171cdf0e10cSrcweir {
1172cdf0e10cSrcweir case TypeClass_SHORT:
1173cdf0e10cSrcweir case TypeClass_LONG:
1174cdf0e10cSrcweir {
1175cdf0e10cSrcweir sal_Int32 nValue = 0;
1176cdf0e10cSrcweir if( rValue >>= nValue )
1177cdf0e10cSrcweir sValue = OUString::valueOf( nValue );
1178cdf0e10cSrcweir break;
1179cdf0e10cSrcweir }
1180cdf0e10cSrcweir case TypeClass_BYTE:
1181cdf0e10cSrcweir case TypeClass_UNSIGNED_SHORT:
1182cdf0e10cSrcweir case TypeClass_UNSIGNED_LONG:
1183cdf0e10cSrcweir {
1184cdf0e10cSrcweir sal_uInt32 nValue = 0;
1185cdf0e10cSrcweir if( rValue >>= nValue )
1186cdf0e10cSrcweir sValue = OUString::valueOf( (sal_Int64)nValue );
1187cdf0e10cSrcweir break;
1188cdf0e10cSrcweir }
1189cdf0e10cSrcweir case TypeClass_HYPER:
1190cdf0e10cSrcweir {
1191cdf0e10cSrcweir sal_Int64 nValue = 0;
1192cdf0e10cSrcweir if( rValue >>= nValue )
1193cdf0e10cSrcweir sValue = OUString::valueOf( nValue );
1194cdf0e10cSrcweir break;
1195cdf0e10cSrcweir }
1196cdf0e10cSrcweir case TypeClass_UNSIGNED_HYPER:
1197cdf0e10cSrcweir {
1198cdf0e10cSrcweir sal_uInt64 nValue = 0;
1199cdf0e10cSrcweir if( rValue >>= nValue )
1200cdf0e10cSrcweir sValue = OUString::valueOf( (sal_Int64)nValue );
1201cdf0e10cSrcweir break;
1202cdf0e10cSrcweir }
1203cdf0e10cSrcweir case TypeClass_FLOAT:
1204cdf0e10cSrcweir case TypeClass_DOUBLE:
1205cdf0e10cSrcweir {
1206cdf0e10cSrcweir double fValue = 0.0;
1207cdf0e10cSrcweir if( rValue >>= fValue )
1208cdf0e10cSrcweir sValue = OUString::valueOf( fValue );
1209cdf0e10cSrcweir break;
1210cdf0e10cSrcweir }
1211cdf0e10cSrcweir case TypeClass_STRING:
1212cdf0e10cSrcweir rValue >>= sValue;
1213cdf0e10cSrcweir break;
1214cdf0e10cSrcweir /*
1215cdf0e10cSrcweir case TypeClass_INTERFACE:
1216cdf0e10cSrcweir // @todo
1217cdf0e10cSrcweir break;
1218cdf0e10cSrcweir case TypeClass_SEQUENCE:
1219cdf0e10cSrcweir {
1220cdf0e10cSrcweir Sequence< Any > aValues;
1221cdf0e10cSrcweir if( aValue >>= aValues )
1222cdf0e10cSrcweir {
1223cdf0e10cSrcweir updateEntry( SvLBoxEntry& rEntry, aValues );
1224cdf0e10cSrcweir return;
1225cdf0e10cSrcweir }
1226cdf0e10cSrcweir }
1227cdf0e10cSrcweir break;
1228cdf0e10cSrcweir */
1229cdf0e10cSrcweir default:
1230cdf0e10cSrcweir break;
1231cdf0e10cSrcweir }
1232cdf0e10cSrcweir }
1233cdf0e10cSrcweir return sValue;
1234cdf0e10cSrcweir }
1235cdf0e10cSrcweir
1236cdf0e10cSrcweir // XEventListener
disposing(const::com::sun::star::lang::EventObject &)1237cdf0e10cSrcweir void SAL_CALL TreeControlPeer::disposing( const ::com::sun::star::lang::EventObject& ) throw(::com::sun::star::uno::RuntimeException)
1238cdf0e10cSrcweir {
1239cdf0e10cSrcweir // model is disposed, so we clear our tree
1240cdf0e10cSrcweir ::vos::OGuard aGuard( GetMutex() );
1241cdf0e10cSrcweir UnoTreeListBoxImpl& rTree = getTreeListBoxOrThrow();
1242cdf0e10cSrcweir rTree.Clear();
1243cdf0e10cSrcweir mxDataModel.clear();
1244cdf0e10cSrcweir }
1245cdf0e10cSrcweir
onChangeDataModel(UnoTreeListBoxImpl & rTree,const Reference<XTreeDataModel> & xDataModel)1246cdf0e10cSrcweir void TreeControlPeer::onChangeDataModel( UnoTreeListBoxImpl& rTree, const Reference< XTreeDataModel >& xDataModel )
1247cdf0e10cSrcweir {
1248cdf0e10cSrcweir if( xDataModel.is() && (mxDataModel == xDataModel) )
1249cdf0e10cSrcweir return; // do nothing
1250cdf0e10cSrcweir
1251cdf0e10cSrcweir Reference< XTreeDataModelListener > xListener( this );
1252cdf0e10cSrcweir
1253cdf0e10cSrcweir if( mxDataModel.is() )
1254cdf0e10cSrcweir mxDataModel->removeTreeDataModelListener( xListener );
1255cdf0e10cSrcweir
1256cdf0e10cSrcweir if( !xDataModel.is() )
1257cdf0e10cSrcweir {
1258cdf0e10cSrcweir static const OUString aSN( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.awt.tree.DefaultTreeDataModel" ) );
1259cdf0e10cSrcweir Reference< XMultiServiceFactory > xORB( ::comphelper::getProcessServiceFactory() );
1260cdf0e10cSrcweir if( xORB.is() )
1261cdf0e10cSrcweir {
1262cdf0e10cSrcweir mxDataModel.query( xORB->createInstance( aSN ) );
1263cdf0e10cSrcweir }
1264cdf0e10cSrcweir }
1265cdf0e10cSrcweir
1266cdf0e10cSrcweir mxDataModel = xDataModel;
1267cdf0e10cSrcweir
1268cdf0e10cSrcweir fillTree( rTree, mxDataModel );
1269cdf0e10cSrcweir
1270cdf0e10cSrcweir if( mxDataModel.is() )
1271cdf0e10cSrcweir mxDataModel->addTreeDataModelListener( xListener );
1272cdf0e10cSrcweir }
1273cdf0e10cSrcweir
1274cdf0e10cSrcweir // --------------------------------------------------------------------
1275cdf0e10cSrcweir // ::com::sun::star::awt::XLayoutConstrains
1276cdf0e10cSrcweir // --------------------------------------------------------------------
1277cdf0e10cSrcweir
getMinimumSize()1278cdf0e10cSrcweir ::com::sun::star::awt::Size TreeControlPeer::getMinimumSize() throw(RuntimeException)
1279cdf0e10cSrcweir {
1280cdf0e10cSrcweir ::vos::OGuard aGuard( GetMutex() );
1281cdf0e10cSrcweir
1282cdf0e10cSrcweir ::com::sun::star::awt::Size aSz;
1283cdf0e10cSrcweir /* todo
1284cdf0e10cSrcweir MultiLineEdit* pEdit = (MultiLineEdit*) GetWindow();
1285cdf0e10cSrcweir if ( pEdit )
1286cdf0e10cSrcweir aSz = AWTSize(pEdit->CalcMinimumSize());
1287cdf0e10cSrcweir */
1288cdf0e10cSrcweir return aSz;
1289cdf0e10cSrcweir }
1290cdf0e10cSrcweir
getPreferredSize()1291cdf0e10cSrcweir ::com::sun::star::awt::Size TreeControlPeer::getPreferredSize() throw(RuntimeException)
1292cdf0e10cSrcweir {
1293cdf0e10cSrcweir return getMinimumSize();
1294cdf0e10cSrcweir }
1295cdf0e10cSrcweir
calcAdjustedSize(const::com::sun::star::awt::Size & rNewSize)1296cdf0e10cSrcweir ::com::sun::star::awt::Size TreeControlPeer::calcAdjustedSize( const ::com::sun::star::awt::Size& rNewSize ) throw(RuntimeException)
1297cdf0e10cSrcweir {
1298cdf0e10cSrcweir ::vos::OGuard aGuard( GetMutex() );
1299cdf0e10cSrcweir
1300cdf0e10cSrcweir ::com::sun::star::awt::Size aSz = rNewSize;
1301cdf0e10cSrcweir /* todo
1302cdf0e10cSrcweir MultiLineEdit* pEdit = (MultiLineEdit*) GetWindow();
1303cdf0e10cSrcweir if ( pEdit )
1304cdf0e10cSrcweir aSz = AWTSize(pEdit->CalcAdjustedSize( VCLSize(rNewSize )));
1305cdf0e10cSrcweir */
1306cdf0e10cSrcweir return aSz;
1307cdf0e10cSrcweir }
1308cdf0e10cSrcweir
1309cdf0e10cSrcweir // --------------------------------------------------------------------
1310cdf0e10cSrcweir // ::com::sun::star::awt::XVclWindowPeer
1311cdf0e10cSrcweir // --------------------------------------------------------------------
1312cdf0e10cSrcweir
setProperty(const::rtl::OUString & PropertyName,const Any & aValue)1313cdf0e10cSrcweir void TreeControlPeer::setProperty( const ::rtl::OUString& PropertyName, const Any& aValue) throw(RuntimeException)
1314cdf0e10cSrcweir {
1315cdf0e10cSrcweir ::vos::OGuard aGuard( GetMutex() );
1316cdf0e10cSrcweir
1317cdf0e10cSrcweir UnoTreeListBoxImpl& rTree = getTreeListBoxOrThrow();
1318cdf0e10cSrcweir
1319cdf0e10cSrcweir switch( GetPropertyId( PropertyName ) )
1320cdf0e10cSrcweir {
1321cdf0e10cSrcweir case BASEPROPERTY_HIDEINACTIVESELECTION:
1322cdf0e10cSrcweir {
1323cdf0e10cSrcweir sal_Bool bEnabled = sal_False;
1324cdf0e10cSrcweir if ( aValue >>= bEnabled )
1325cdf0e10cSrcweir {
1326cdf0e10cSrcweir WinBits nStyle = rTree.GetStyle();
1327cdf0e10cSrcweir if ( bEnabled )
1328cdf0e10cSrcweir nStyle |= WB_HIDESELECTION;
1329cdf0e10cSrcweir else
1330cdf0e10cSrcweir nStyle &= ~WB_HIDESELECTION;
1331cdf0e10cSrcweir rTree.SetStyle( nStyle );
1332cdf0e10cSrcweir }
1333cdf0e10cSrcweir }
1334cdf0e10cSrcweir break;
1335cdf0e10cSrcweir
1336cdf0e10cSrcweir case BASEPROPERTY_TREE_SELECTIONTYPE:
1337cdf0e10cSrcweir {
1338cdf0e10cSrcweir SelectionType eSelectionType;
1339cdf0e10cSrcweir if( aValue >>= eSelectionType )
1340cdf0e10cSrcweir {
1341cdf0e10cSrcweir SelectionMode eSelMode;
1342cdf0e10cSrcweir switch( eSelectionType )
1343cdf0e10cSrcweir {
1344cdf0e10cSrcweir case SelectionType_SINGLE: eSelMode = SINGLE_SELECTION; break;
1345cdf0e10cSrcweir case SelectionType_RANGE: eSelMode = RANGE_SELECTION; break;
1346cdf0e10cSrcweir case SelectionType_MULTI: eSelMode = MULTIPLE_SELECTION; break;
1347cdf0e10cSrcweir // case SelectionType_NONE:
1348cdf0e10cSrcweir default: eSelMode = NO_SELECTION; break;
1349cdf0e10cSrcweir }
1350cdf0e10cSrcweir if( rTree.GetSelectionMode() != eSelMode )
1351cdf0e10cSrcweir rTree.SetSelectionMode( eSelMode );
1352cdf0e10cSrcweir }
1353cdf0e10cSrcweir break;
1354cdf0e10cSrcweir }
1355cdf0e10cSrcweir
1356cdf0e10cSrcweir case BASEPROPERTY_TREE_DATAMODEL:
1357cdf0e10cSrcweir onChangeDataModel( rTree, Reference< XTreeDataModel >( aValue, UNO_QUERY ) );
1358cdf0e10cSrcweir break;
1359cdf0e10cSrcweir case BASEPROPERTY_ROW_HEIGHT:
1360cdf0e10cSrcweir {
1361cdf0e10cSrcweir sal_Int32 nHeight = 0;
1362cdf0e10cSrcweir if( aValue >>= nHeight )
1363cdf0e10cSrcweir rTree.SetEntryHeight( (short)nHeight );
1364cdf0e10cSrcweir break;
1365cdf0e10cSrcweir }
1366cdf0e10cSrcweir case BASEPROPERTY_TREE_EDITABLE:
1367cdf0e10cSrcweir {
1368cdf0e10cSrcweir sal_Bool bEnabled = false;
1369cdf0e10cSrcweir if( aValue >>= bEnabled )
1370cdf0e10cSrcweir rTree.EnableInplaceEditing( bEnabled ? sal_True : sal_False );
1371cdf0e10cSrcweir break;
1372cdf0e10cSrcweir }
1373cdf0e10cSrcweir case BASEPROPERTY_TREE_INVOKESSTOPNODEEDITING:
1374cdf0e10cSrcweir break; // @todo
1375cdf0e10cSrcweir case BASEPROPERTY_TREE_ROOTDISPLAYED:
1376cdf0e10cSrcweir {
1377cdf0e10cSrcweir sal_Bool bDisplayed = false;
1378cdf0e10cSrcweir if( (aValue >>= bDisplayed) && ( bDisplayed != mbIsRootDisplayed) )
1379cdf0e10cSrcweir {
1380cdf0e10cSrcweir onChangeRootDisplayed(bDisplayed);
1381cdf0e10cSrcweir }
1382cdf0e10cSrcweir break;
1383cdf0e10cSrcweir }
1384cdf0e10cSrcweir case BASEPROPERTY_TREE_SHOWSHANDLES:
1385cdf0e10cSrcweir {
1386cdf0e10cSrcweir sal_Bool bEnabled = false;
1387cdf0e10cSrcweir if( aValue >>= bEnabled )
1388cdf0e10cSrcweir {
1389cdf0e10cSrcweir WinBits nBits = rTree.GetStyle() & (~WB_HASLINES);
1390cdf0e10cSrcweir if( bEnabled )
1391cdf0e10cSrcweir nBits |= WB_HASLINES;
1392cdf0e10cSrcweir if( nBits != rTree.GetStyle() )
1393cdf0e10cSrcweir rTree.SetStyle( nBits );
1394cdf0e10cSrcweir }
1395cdf0e10cSrcweir break;
1396cdf0e10cSrcweir }
1397cdf0e10cSrcweir case BASEPROPERTY_TREE_SHOWSROOTHANDLES:
1398cdf0e10cSrcweir {
1399cdf0e10cSrcweir sal_Bool bEnabled = false;
1400cdf0e10cSrcweir if( aValue >>= bEnabled )
1401cdf0e10cSrcweir {
1402cdf0e10cSrcweir WinBits nBits = rTree.GetStyle() & (~WB_HASLINESATROOT);
1403cdf0e10cSrcweir if( bEnabled )
1404cdf0e10cSrcweir nBits |= WB_HASLINESATROOT;
1405cdf0e10cSrcweir if( nBits != rTree.GetStyle() )
1406cdf0e10cSrcweir rTree.SetStyle( nBits );
1407cdf0e10cSrcweir }
1408cdf0e10cSrcweir break;
1409cdf0e10cSrcweir }
1410cdf0e10cSrcweir default:
1411cdf0e10cSrcweir VCLXWindow::setProperty( PropertyName, aValue );
1412cdf0e10cSrcweir break;
1413cdf0e10cSrcweir }
1414cdf0e10cSrcweir }
1415cdf0e10cSrcweir
getProperty(const::rtl::OUString & PropertyName)1416cdf0e10cSrcweir Any TreeControlPeer::getProperty( const ::rtl::OUString& PropertyName ) throw(RuntimeException)
1417cdf0e10cSrcweir {
1418cdf0e10cSrcweir ::vos::OGuard aGuard( GetMutex() );
1419cdf0e10cSrcweir
1420cdf0e10cSrcweir const sal_uInt16 nPropId = GetPropertyId( PropertyName );
1421cdf0e10cSrcweir if( (nPropId >= BASEPROPERTY_TREE_START) && (nPropId <= BASEPROPERTY_TREE_END) )
1422cdf0e10cSrcweir {
1423cdf0e10cSrcweir UnoTreeListBoxImpl& rTree = getTreeListBoxOrThrow();
1424cdf0e10cSrcweir switch(nPropId)
1425cdf0e10cSrcweir {
1426cdf0e10cSrcweir case BASEPROPERTY_HIDEINACTIVESELECTION:
1427cdf0e10cSrcweir return Any( ( rTree.GetStyle() & WB_HIDESELECTION ) != 0 ? sal_True : sal_False );
1428cdf0e10cSrcweir
1429cdf0e10cSrcweir case BASEPROPERTY_TREE_SELECTIONTYPE:
1430cdf0e10cSrcweir {
1431cdf0e10cSrcweir SelectionType eSelectionType;
1432cdf0e10cSrcweir
1433cdf0e10cSrcweir SelectionMode eSelMode = rTree.GetSelectionMode();
1434cdf0e10cSrcweir switch( eSelMode )
1435cdf0e10cSrcweir {
1436cdf0e10cSrcweir case SINGLE_SELECTION: eSelectionType = SelectionType_SINGLE; break;
1437cdf0e10cSrcweir case RANGE_SELECTION: eSelectionType = SelectionType_RANGE; break;
1438cdf0e10cSrcweir case MULTIPLE_SELECTION:eSelectionType = SelectionType_MULTI; break;
1439cdf0e10cSrcweir // case NO_SELECTION:
1440cdf0e10cSrcweir default: eSelectionType = SelectionType_NONE; break;
1441cdf0e10cSrcweir }
1442cdf0e10cSrcweir return Any( eSelectionType );
1443cdf0e10cSrcweir }
1444cdf0e10cSrcweir case BASEPROPERTY_ROW_HEIGHT:
1445cdf0e10cSrcweir return Any( (sal_Int32)rTree.GetEntryHeight() );
1446cdf0e10cSrcweir case BASEPROPERTY_TREE_DATAMODEL:
1447cdf0e10cSrcweir return Any( mxDataModel );
1448cdf0e10cSrcweir case BASEPROPERTY_TREE_EDITABLE:
1449cdf0e10cSrcweir return Any( rTree.IsInplaceEditingEnabled() ? sal_True : sal_False );
1450cdf0e10cSrcweir case BASEPROPERTY_TREE_INVOKESSTOPNODEEDITING:
1451cdf0e10cSrcweir return Any( sal_True ); // @todo
1452cdf0e10cSrcweir case BASEPROPERTY_TREE_ROOTDISPLAYED:
1453cdf0e10cSrcweir return Any( mbIsRootDisplayed );
1454cdf0e10cSrcweir case BASEPROPERTY_TREE_SHOWSHANDLES:
1455cdf0e10cSrcweir return Any( (rTree.GetStyle() & WB_HASLINES) != 0 ? sal_True : sal_False );
1456cdf0e10cSrcweir case BASEPROPERTY_TREE_SHOWSROOTHANDLES:
1457cdf0e10cSrcweir return Any( (rTree.GetStyle() & WB_HASLINESATROOT) != 0 ? sal_True : sal_False );
1458cdf0e10cSrcweir }
1459cdf0e10cSrcweir }
1460cdf0e10cSrcweir return VCLXWindow::getProperty( PropertyName );
1461cdf0e10cSrcweir }
1462cdf0e10cSrcweir
onChangeRootDisplayed(sal_Bool bIsRootDisplayed)1463cdf0e10cSrcweir void TreeControlPeer::onChangeRootDisplayed( sal_Bool bIsRootDisplayed )
1464cdf0e10cSrcweir {
1465cdf0e10cSrcweir if( mbIsRootDisplayed == bIsRootDisplayed )
1466cdf0e10cSrcweir return;
1467cdf0e10cSrcweir
1468cdf0e10cSrcweir mbIsRootDisplayed = bIsRootDisplayed;
1469cdf0e10cSrcweir
1470cdf0e10cSrcweir UnoTreeListBoxImpl& rTree = getTreeListBoxOrThrow();
1471cdf0e10cSrcweir
1472cdf0e10cSrcweir if( rTree.GetEntryCount() == 0 )
1473cdf0e10cSrcweir return;
1474cdf0e10cSrcweir
1475cdf0e10cSrcweir // todo
1476cdf0e10cSrcweir fillTree( rTree, mxDataModel );
1477cdf0e10cSrcweir if( mbIsRootDisplayed )
1478cdf0e10cSrcweir {
1479cdf0e10cSrcweir }
1480cdf0e10cSrcweir else
1481cdf0e10cSrcweir {
1482cdf0e10cSrcweir }
1483cdf0e10cSrcweir }
1484cdf0e10cSrcweir
loadImage(const::rtl::OUString & rURL,Image & rImage)1485cdf0e10cSrcweir bool TreeControlPeer::loadImage( const ::rtl::OUString& rURL, Image& rImage )
1486cdf0e10cSrcweir {
1487cdf0e10cSrcweir if( !mxGraphicProvider.is() )
1488cdf0e10cSrcweir {
1489cdf0e10cSrcweir static const OUString aSN( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.graphic.GraphicProvider" ) );
1490cdf0e10cSrcweir Reference< XMultiServiceFactory > xORB( ::comphelper::getProcessServiceFactory() );
1491cdf0e10cSrcweir if( xORB.is() )
1492cdf0e10cSrcweir {
1493cdf0e10cSrcweir Reference< XInterface > x( xORB->createInstance( aSN ) );
1494cdf0e10cSrcweir mxGraphicProvider.query( x );
1495cdf0e10cSrcweir mxGraphicProvider = Reference< XGraphicProvider >( x, UNO_QUERY );
1496cdf0e10cSrcweir }
1497cdf0e10cSrcweir }
1498cdf0e10cSrcweir
1499cdf0e10cSrcweir if( mxGraphicProvider.is() ) try
1500cdf0e10cSrcweir {
1501cdf0e10cSrcweir ::com::sun::star::beans::PropertyValues aProps( 1 );
1502cdf0e10cSrcweir aProps[0].Name = OUString( RTL_CONSTASCII_USTRINGPARAM( "URL" ) );
1503cdf0e10cSrcweir aProps[0].Value <<= rURL;
1504cdf0e10cSrcweir
1505cdf0e10cSrcweir Reference< XGraphic > xGraphic( mxGraphicProvider->queryGraphic( aProps ) );
1506cdf0e10cSrcweir
1507cdf0e10cSrcweir Graphic aGraphic( xGraphic );
1508cdf0e10cSrcweir rImage = aGraphic.GetBitmapEx();
1509cdf0e10cSrcweir return true;
1510cdf0e10cSrcweir }
1511cdf0e10cSrcweir catch( Exception& )
1512cdf0e10cSrcweir {
1513cdf0e10cSrcweir }
1514cdf0e10cSrcweir
1515cdf0e10cSrcweir return false;
1516cdf0e10cSrcweir }
1517cdf0e10cSrcweir
1518cdf0e10cSrcweir // ====================================================================
1519cdf0e10cSrcweir // class UnoTreeListBoxImpl
1520cdf0e10cSrcweir // ====================================================================
1521cdf0e10cSrcweir
UnoTreeListBoxImpl(TreeControlPeer * pPeer,Window * pParent,WinBits nWinStyle)1522cdf0e10cSrcweir UnoTreeListBoxImpl::UnoTreeListBoxImpl( TreeControlPeer* pPeer, Window* pParent, WinBits nWinStyle )
1523cdf0e10cSrcweir : SvTreeListBox( pParent, nWinStyle )
1524cdf0e10cSrcweir , mxPeer( pPeer )
1525cdf0e10cSrcweir {
1526cdf0e10cSrcweir SetStyle( WB_BORDER | WB_HASLINES |WB_HASBUTTONS | WB_HASLINESATROOT | WB_HASBUTTONSATROOT | WB_HSCROLL );
1527cdf0e10cSrcweir SetNodeDefaultImages();
1528cdf0e10cSrcweir SetSelectHdl( LINK(this, UnoTreeListBoxImpl, OnSelectionChangeHdl) );
1529cdf0e10cSrcweir SetDeselectHdl( LINK(this, UnoTreeListBoxImpl, OnSelectionChangeHdl) );
1530cdf0e10cSrcweir
1531cdf0e10cSrcweir SetExpandingHdl( LINK(this, UnoTreeListBoxImpl, OnExpandingHdl) );
1532cdf0e10cSrcweir SetExpandedHdl( LINK(this, UnoTreeListBoxImpl, OnExpandedHdl) );
1533cdf0e10cSrcweir
1534cdf0e10cSrcweir }
1535cdf0e10cSrcweir
1536cdf0e10cSrcweir // --------------------------------------------------------------------
1537cdf0e10cSrcweir
~UnoTreeListBoxImpl()1538cdf0e10cSrcweir UnoTreeListBoxImpl::~UnoTreeListBoxImpl()
1539cdf0e10cSrcweir {
1540cdf0e10cSrcweir if( mxPeer.is() )
1541cdf0e10cSrcweir mxPeer->disposeControl();
1542cdf0e10cSrcweir }
1543cdf0e10cSrcweir
1544cdf0e10cSrcweir // --------------------------------------------------------------------
1545cdf0e10cSrcweir
IMPL_LINK(UnoTreeListBoxImpl,OnSelectionChangeHdl,UnoTreeListBoxImpl *,EMPTYARG)1546cdf0e10cSrcweir IMPL_LINK( UnoTreeListBoxImpl, OnSelectionChangeHdl, UnoTreeListBoxImpl*, EMPTYARG )
1547cdf0e10cSrcweir {
1548cdf0e10cSrcweir if( mxPeer.is() )
1549cdf0e10cSrcweir mxPeer->onSelectionChanged();
1550cdf0e10cSrcweir return 0;
1551cdf0e10cSrcweir }
1552cdf0e10cSrcweir
1553cdf0e10cSrcweir // --------------------------------------------------------------------
1554cdf0e10cSrcweir
IMPL_LINK(UnoTreeListBoxImpl,OnExpandingHdl,UnoTreeListBoxImpl *,EMPTYARG)1555cdf0e10cSrcweir IMPL_LINK(UnoTreeListBoxImpl, OnExpandingHdl, UnoTreeListBoxImpl*, EMPTYARG )
1556cdf0e10cSrcweir {
1557cdf0e10cSrcweir UnoTreeListEntry* pEntry = dynamic_cast< UnoTreeListEntry* >( GetHdlEntry() );
1558cdf0e10cSrcweir
1559cdf0e10cSrcweir if( pEntry && mxPeer.is() )
1560cdf0e10cSrcweir {
1561cdf0e10cSrcweir return mxPeer->onExpanding( pEntry->mxNode, !IsExpanded( pEntry ) ) ? 1 : 0;
1562cdf0e10cSrcweir }
1563cdf0e10cSrcweir return 0;
1564cdf0e10cSrcweir }
1565cdf0e10cSrcweir
1566cdf0e10cSrcweir // --------------------------------------------------------------------
1567cdf0e10cSrcweir
IMPL_LINK(UnoTreeListBoxImpl,OnExpandedHdl,UnoTreeListBoxImpl *,EMPTYARG)1568cdf0e10cSrcweir IMPL_LINK(UnoTreeListBoxImpl, OnExpandedHdl, UnoTreeListBoxImpl*, EMPTYARG )
1569cdf0e10cSrcweir {
1570cdf0e10cSrcweir UnoTreeListEntry* pEntry = dynamic_cast< UnoTreeListEntry* >( GetHdlEntry() );
1571cdf0e10cSrcweir if( pEntry && mxPeer.is() )
1572cdf0e10cSrcweir {
1573cdf0e10cSrcweir mxPeer->onExpanded( pEntry->mxNode, IsExpanded( pEntry ) );
1574cdf0e10cSrcweir }
1575cdf0e10cSrcweir return 0;
1576cdf0e10cSrcweir }
1577cdf0e10cSrcweir
1578cdf0e10cSrcweir // --------------------------------------------------------------------
1579cdf0e10cSrcweir
insert(SvLBoxEntry * pEntry,SvLBoxEntry * pParent,sal_uLong nPos)1580cdf0e10cSrcweir sal_uInt32 UnoTreeListBoxImpl::insert( SvLBoxEntry* pEntry,SvLBoxEntry* pParent,sal_uLong nPos )
1581cdf0e10cSrcweir {
1582cdf0e10cSrcweir if( pParent )
1583cdf0e10cSrcweir return SvTreeListBox::Insert( pEntry, pParent, nPos );
1584cdf0e10cSrcweir else
1585cdf0e10cSrcweir return SvTreeListBox::Insert( pEntry, nPos );
1586cdf0e10cSrcweir }
1587cdf0e10cSrcweir
1588cdf0e10cSrcweir // --------------------------------------------------------------------
1589cdf0e10cSrcweir
RequestingChilds(SvLBoxEntry * pParent)1590cdf0e10cSrcweir void UnoTreeListBoxImpl::RequestingChilds( SvLBoxEntry* pParent )
1591cdf0e10cSrcweir {
1592cdf0e10cSrcweir UnoTreeListEntry* pEntry = dynamic_cast< UnoTreeListEntry* >( pParent );
1593cdf0e10cSrcweir if( pEntry && pEntry->mxNode.is() && mxPeer.is() )
1594cdf0e10cSrcweir mxPeer->onRequestChildNodes( pEntry->mxNode );
1595cdf0e10cSrcweir }
1596cdf0e10cSrcweir
1597cdf0e10cSrcweir // --------------------------------------------------------------------
1598cdf0e10cSrcweir
EditingEntry(SvLBoxEntry * pEntry,Selection &)1599cdf0e10cSrcweir sal_Bool UnoTreeListBoxImpl::EditingEntry( SvLBoxEntry* pEntry, Selection& )
1600cdf0e10cSrcweir {
1601cdf0e10cSrcweir return mxPeer.is() ? mxPeer->onEditingEntry( dynamic_cast< UnoTreeListEntry* >( pEntry ) ) : false;
1602cdf0e10cSrcweir }
1603cdf0e10cSrcweir
1604cdf0e10cSrcweir // --------------------------------------------------------------------
1605cdf0e10cSrcweir
EditedEntry(SvLBoxEntry * pEntry,const XubString & rNewText)1606cdf0e10cSrcweir sal_Bool UnoTreeListBoxImpl::EditedEntry( SvLBoxEntry* pEntry, const XubString& rNewText )
1607cdf0e10cSrcweir {
1608cdf0e10cSrcweir return mxPeer.is() ? mxPeer->onEditedEntry( dynamic_cast< UnoTreeListEntry* >( pEntry ), rNewText ) : false;
1609cdf0e10cSrcweir }
1610cdf0e10cSrcweir
1611cdf0e10cSrcweir // ====================================================================
1612cdf0e10cSrcweir // class UnoTreeListItem
1613cdf0e10cSrcweir // ====================================================================
1614cdf0e10cSrcweir
UnoTreeListItem(SvLBoxEntry * pEntry)1615cdf0e10cSrcweir UnoTreeListItem::UnoTreeListItem( SvLBoxEntry* pEntry )
1616cdf0e10cSrcweir : SvLBoxItem( pEntry, 0 )
1617cdf0e10cSrcweir {
1618cdf0e10cSrcweir }
1619cdf0e10cSrcweir
1620cdf0e10cSrcweir // --------------------------------------------------------------------
1621cdf0e10cSrcweir
UnoTreeListItem()1622cdf0e10cSrcweir UnoTreeListItem::UnoTreeListItem()
1623cdf0e10cSrcweir : SvLBoxItem()
1624cdf0e10cSrcweir {
1625cdf0e10cSrcweir }
1626cdf0e10cSrcweir
1627cdf0e10cSrcweir // --------------------------------------------------------------------
1628cdf0e10cSrcweir
~UnoTreeListItem()1629cdf0e10cSrcweir UnoTreeListItem::~UnoTreeListItem()
1630cdf0e10cSrcweir {
1631cdf0e10cSrcweir }
1632cdf0e10cSrcweir
1633cdf0e10cSrcweir // --------------------------------------------------------------------
1634cdf0e10cSrcweir
IsA()1635cdf0e10cSrcweir sal_uInt16 UnoTreeListItem::IsA()
1636cdf0e10cSrcweir {
1637*760d640aSAriel Constenla-Haile return SV_ITEM_ID_LBOXSTRING;
1638cdf0e10cSrcweir }
1639cdf0e10cSrcweir
1640cdf0e10cSrcweir // --------------------------------------------------------------------
1641cdf0e10cSrcweir
Paint(const Point & rPos,SvLBox & rDev,sal_uInt16,SvLBoxEntry * _pEntry)1642cdf0e10cSrcweir void UnoTreeListItem::Paint( const Point& rPos, SvLBox& rDev, sal_uInt16 /* nFlags */, SvLBoxEntry* _pEntry)
1643cdf0e10cSrcweir {
1644cdf0e10cSrcweir Point aPos( rPos );
1645cdf0e10cSrcweir if( _pEntry )
1646cdf0e10cSrcweir {
1647cdf0e10cSrcweir Size aSize( GetSize(&rDev,_pEntry) );
1648cdf0e10cSrcweir if( !!maImage )
1649cdf0e10cSrcweir {
1650cdf0e10cSrcweir rDev.DrawImage( aPos, maImage, rDev.IsEnabled() ? 0 : IMAGE_DRAW_DISABLE );
1651cdf0e10cSrcweir int nWidth = maImage.GetSizePixel().Width() + 6;
1652cdf0e10cSrcweir aPos.X() += nWidth;
1653cdf0e10cSrcweir aSize.Width() -= nWidth;
1654cdf0e10cSrcweir }
1655cdf0e10cSrcweir rDev.DrawText( Rectangle(aPos,aSize),maText, rDev.IsEnabled() ? 0 : TEXT_DRAW_DISABLE );
1656cdf0e10cSrcweir }
1657cdf0e10cSrcweir else
1658cdf0e10cSrcweir {
1659cdf0e10cSrcweir if( !!maImage )
1660cdf0e10cSrcweir {
1661cdf0e10cSrcweir rDev.DrawImage( aPos, maImage, rDev.IsEnabled() ? 0 : IMAGE_DRAW_DISABLE);
1662cdf0e10cSrcweir aPos.X() += maImage.GetSizePixel().Width() + 6;
1663cdf0e10cSrcweir }
1664cdf0e10cSrcweir rDev.DrawText( aPos, maText);
1665cdf0e10cSrcweir }
1666cdf0e10cSrcweir }
1667cdf0e10cSrcweir
1668cdf0e10cSrcweir // --------------------------------------------------------------------
1669cdf0e10cSrcweir
Create() const1670cdf0e10cSrcweir SvLBoxItem* UnoTreeListItem::Create() const
1671cdf0e10cSrcweir {
1672cdf0e10cSrcweir return new UnoTreeListItem;
1673cdf0e10cSrcweir }
1674cdf0e10cSrcweir
1675cdf0e10cSrcweir // --------------------------------------------------------------------
1676cdf0e10cSrcweir
Clone(SvLBoxItem * pSource)1677cdf0e10cSrcweir void UnoTreeListItem::Clone( SvLBoxItem* pSource )
1678cdf0e10cSrcweir {
1679cdf0e10cSrcweir UnoTreeListItem* pSourceItem = dynamic_cast< UnoTreeListItem* >( pSource );
1680cdf0e10cSrcweir if( pSourceItem )
1681cdf0e10cSrcweir {
1682cdf0e10cSrcweir maText = pSourceItem->maText;
1683cdf0e10cSrcweir maImage = pSourceItem->maImage;
1684cdf0e10cSrcweir }
1685cdf0e10cSrcweir }
1686cdf0e10cSrcweir
1687cdf0e10cSrcweir // --------------------------------------------------------------------
1688cdf0e10cSrcweir
GetText() const1689cdf0e10cSrcweir OUString UnoTreeListItem::GetText() const
1690cdf0e10cSrcweir {
1691cdf0e10cSrcweir return maText;
1692cdf0e10cSrcweir }
1693cdf0e10cSrcweir
1694cdf0e10cSrcweir // --------------------------------------------------------------------
1695cdf0e10cSrcweir
SetText(const OUString & rText)1696cdf0e10cSrcweir void UnoTreeListItem::SetText( const OUString& rText )
1697cdf0e10cSrcweir {
1698cdf0e10cSrcweir maText = rText;
1699cdf0e10cSrcweir }
1700cdf0e10cSrcweir
1701cdf0e10cSrcweir // --------------------------------------------------------------------
1702cdf0e10cSrcweir
SetImage(const Image & rImage)1703cdf0e10cSrcweir void UnoTreeListItem::SetImage( const Image& rImage )
1704cdf0e10cSrcweir {
1705cdf0e10cSrcweir maImage = rImage;
1706cdf0e10cSrcweir }
1707cdf0e10cSrcweir
1708cdf0e10cSrcweir // --------------------------------------------------------------------
1709cdf0e10cSrcweir
GetGraphicURL() const1710cdf0e10cSrcweir OUString UnoTreeListItem::GetGraphicURL() const
1711cdf0e10cSrcweir {
1712cdf0e10cSrcweir return maGraphicURL;
1713cdf0e10cSrcweir }
1714cdf0e10cSrcweir
1715cdf0e10cSrcweir // --------------------------------------------------------------------
1716cdf0e10cSrcweir
SetGraphicURL(const OUString & rGraphicURL)1717cdf0e10cSrcweir void UnoTreeListItem::SetGraphicURL( const OUString& rGraphicURL )
1718cdf0e10cSrcweir {
1719cdf0e10cSrcweir maGraphicURL = rGraphicURL;
1720cdf0e10cSrcweir }
1721cdf0e10cSrcweir
1722cdf0e10cSrcweir // --------------------------------------------------------------------
1723cdf0e10cSrcweir
InitViewData(SvLBox * pView,SvLBoxEntry * pEntry,SvViewDataItem * pViewData)1724cdf0e10cSrcweir void UnoTreeListItem::InitViewData( SvLBox* pView,SvLBoxEntry* pEntry, SvViewDataItem* pViewData)
1725cdf0e10cSrcweir {
1726cdf0e10cSrcweir if( !pViewData )
1727cdf0e10cSrcweir pViewData = pView->GetViewDataItem( pEntry, this );
1728cdf0e10cSrcweir
1729cdf0e10cSrcweir pViewData->aSize = maImage.GetSizePixel();
1730cdf0e10cSrcweir
1731cdf0e10cSrcweir const Size aTextSize(pView->GetTextWidth( maText ), pView->GetTextHeight());
1732cdf0e10cSrcweir if( pViewData->aSize.Width() )
1733cdf0e10cSrcweir {
1734cdf0e10cSrcweir pViewData->aSize.Width() += 6 + aTextSize.Width();
1735cdf0e10cSrcweir if( pViewData->aSize.Height() < aTextSize.Height() )
1736cdf0e10cSrcweir pViewData->aSize.Height() = aTextSize.Height();
1737cdf0e10cSrcweir }
1738cdf0e10cSrcweir else
1739cdf0e10cSrcweir {
1740cdf0e10cSrcweir pViewData->aSize = aTextSize;
1741cdf0e10cSrcweir }
1742cdf0e10cSrcweir }
1743cdf0e10cSrcweir
1744cdf0e10cSrcweir // --------------------------------------------------------------------
1745cdf0e10cSrcweir
UnoTreeListEntry(const Reference<XTreeNode> & xNode,TreeControlPeer * pPeer)1746cdf0e10cSrcweir UnoTreeListEntry::UnoTreeListEntry( const Reference< XTreeNode >& xNode, TreeControlPeer* pPeer )
1747cdf0e10cSrcweir : SvLBoxEntry()
1748cdf0e10cSrcweir , mxNode( xNode )
1749cdf0e10cSrcweir , mpPeer( pPeer )
1750cdf0e10cSrcweir {
1751cdf0e10cSrcweir if( mpPeer )
1752cdf0e10cSrcweir mpPeer->addEntry( this );
1753cdf0e10cSrcweir }
1754cdf0e10cSrcweir
1755cdf0e10cSrcweir // --------------------------------------------------------------------
1756cdf0e10cSrcweir
~UnoTreeListEntry()1757cdf0e10cSrcweir UnoTreeListEntry::~UnoTreeListEntry()
1758cdf0e10cSrcweir {
1759cdf0e10cSrcweir if( mpPeer )
1760cdf0e10cSrcweir mpPeer->removeEntry( this );
1761cdf0e10cSrcweir }
1762