Updated core
[LibreOffice.git] / svtools / source / uno / treecontrolpeer.cxx
blobe4976a62b7561539457ae2521ce974e0074ee829
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 .
21 #include <com/sun/star/graphic/GraphicProvider.hpp>
22 #include <com/sun/star/lang/XServiceInfo.hpp>
23 #include <com/sun/star/lang/DisposedException.hpp>
24 #include <com/sun/star/view/SelectionType.hpp>
25 #include <toolkit/helper/property.hxx>
26 #include <toolkit/helper/vclunohelper.hxx>
28 #include <com/sun/star/awt/tree/XMutableTreeNode.hpp>
29 #include <treecontrolpeer.hxx>
30 #include <comphelper/processfactory.hxx>
32 #include <rtl/ref.hxx>
33 #include <vcl/graph.hxx>
34 #include <vcl/svapp.hxx>
35 #include <svtools/treelistbox.hxx>
36 #include "svtools/treelistentry.hxx"
37 #include "svtools/viewdataentry.hxx"
38 #include <svtools/svlbitm.hxx>
40 #include <map>
42 using namespace ::com::sun::star;
43 using namespace ::com::sun::star::uno;
44 using namespace ::com::sun::star::lang;
45 using namespace ::com::sun::star::awt::tree;
46 using namespace ::com::sun::star::beans;
47 using namespace ::com::sun::star::view;
48 using namespace ::com::sun::star::container;
49 using namespace ::com::sun::star::util;
50 using namespace ::com::sun::star::graphic;
52 struct LockGuard
54 public:
55 LockGuard( sal_Int32& rLock )
56 : mrLock( rLock )
58 rLock++;
61 ~LockGuard()
63 mrLock--;
66 sal_Int32& mrLock;
70 // --------------------------------------------------------------------
72 class ImplContextGraphicItem : public SvLBoxContextBmp
74 public:
75 ImplContextGraphicItem( SvTreeListEntry* pEntry,sal_uInt16 nFlags,Image& rI1,Image& rI2, bool bExpanded)
76 : SvLBoxContextBmp(pEntry, nFlags, rI1, rI2, bExpanded) {}
78 OUString msExpandedGraphicURL;
79 OUString msCollapsedGraphicURL;
82 // --------------------------------------------------------------------
84 class UnoTreeListBoxImpl : public SvTreeListBox
86 public:
87 UnoTreeListBoxImpl( TreeControlPeer* pPeer, Window* pParent, WinBits nWinStyle );
88 ~UnoTreeListBoxImpl();
90 sal_uInt32 insert( SvTreeListEntry* pEntry,SvTreeListEntry* pParent,sal_uLong nPos=LIST_APPEND );
92 virtual void RequestingChildren( SvTreeListEntry* pParent );
94 virtual sal_Bool EditingEntry( SvTreeListEntry* pEntry, Selection& );
95 virtual sal_Bool EditedEntry( SvTreeListEntry* pEntry, const OUString& rNewText );
97 DECL_LINK(OnSelectionChangeHdl, void *);
98 DECL_LINK(OnExpandingHdl, void *);
99 DECL_LINK(OnExpandedHdl, void *);
101 private:
102 rtl::Reference< TreeControlPeer > mxPeer;
105 // --------------------------------------------------------------------
107 class UnoTreeListItem : public SvLBoxString
109 public:
110 UnoTreeListItem( SvTreeListEntry* );
111 UnoTreeListItem();
112 virtual ~UnoTreeListItem();
113 void InitViewData( SvTreeListBox*,SvTreeListEntry*,SvViewDataItem* );
114 Image GetImage() const;
115 void SetImage( const Image& rImage );
116 OUString GetGraphicURL() const;
117 void SetGraphicURL( const OUString& rGraphicURL );
118 virtual void Paint(
119 const Point& rPos, SvTreeListBox& rOutDev, const SvViewDataEntry* pView, const SvTreeListEntry* pEntry);
120 SvLBoxItem* Create() const;
121 void Clone( SvLBoxItem* pSource );
123 private:
124 OUString maGraphicURL;
125 Image maImage;
128 // --------------------------------------------------------------------
130 class UnoTreeListEntry : public SvTreeListEntry
132 public:
133 UnoTreeListEntry( const Reference< XTreeNode >& xNode, TreeControlPeer* pPeer );
134 virtual ~UnoTreeListEntry();
136 Reference< XTreeNode > mxNode;
137 TreeControlPeer* mpPeer;
140 TreeControlPeer::TreeControlPeer()
141 : maSelectionListeners( *this )
142 , maTreeExpansionListeners( *this )
143 , maTreeEditListeners( *this )
144 , mpTreeImpl( 0 )
145 , mnEditLock( 0 )
146 , mpTreeNodeMap( 0 )
150 // --------------------------------------------------------------------
152 TreeControlPeer::~TreeControlPeer()
154 if( mpTreeImpl )
155 mpTreeImpl->Clear();
156 delete mpTreeNodeMap;
159 // --------------------------------------------------------------------
161 void TreeControlPeer::addEntry( UnoTreeListEntry* pEntry )
163 if( pEntry && pEntry->mxNode.is() )
165 if( !mpTreeNodeMap )
167 mpTreeNodeMap = new TreeNodeMap();
170 (*mpTreeNodeMap)[ pEntry->mxNode ] = pEntry;
174 // --------------------------------------------------------------------
176 void TreeControlPeer::removeEntry( UnoTreeListEntry* pEntry )
178 if( mpTreeNodeMap && pEntry && pEntry->mxNode.is() )
180 TreeNodeMap::iterator aIter( mpTreeNodeMap->find( pEntry->mxNode ) );
181 if( aIter != mpTreeNodeMap->end() )
183 mpTreeNodeMap->erase( aIter );
188 // --------------------------------------------------------------------
190 UnoTreeListEntry* TreeControlPeer::getEntry( const Reference< XTreeNode >& xNode, bool bThrow /* = true */ ) throw( IllegalArgumentException )
192 if( mpTreeNodeMap )
194 TreeNodeMap::iterator aIter( mpTreeNodeMap->find( xNode ) );
195 if( aIter != mpTreeNodeMap->end() )
196 return (*aIter).second;
199 if( bThrow )
200 throw IllegalArgumentException();
202 return 0;
205 // --------------------------------------------------------------------
207 Window* TreeControlPeer::createVclControl( Window* pParent, sal_Int64 nWinStyle )
209 mpTreeImpl = new UnoTreeListBoxImpl( this, pParent, nWinStyle );
210 return mpTreeImpl;
213 // --------------------------------------------------------------------
215 /** called from the UnoTreeListBoxImpl when it gets deleted */
216 void TreeControlPeer::disposeControl()
218 delete mpTreeNodeMap;
219 mpTreeNodeMap = 0;
220 mpTreeImpl = 0;
223 // --------------------------------------------------------------------
225 void TreeControlPeer::SetWindow( Window* pWindow )
227 VCLXWindow::SetWindow( pWindow );
230 // --------------------------------------------------------------------
232 UnoTreeListEntry* TreeControlPeer::createEntry( const Reference< XTreeNode >& xNode, UnoTreeListEntry* pParent, sal_uLong nPos /* = LIST_APPEND */ )
234 UnoTreeListEntry* pEntry = 0;
235 if( mpTreeImpl )
237 Image aImage;
238 pEntry = new UnoTreeListEntry( xNode, this );
239 ImplContextGraphicItem* pContextBmp= new ImplContextGraphicItem(pEntry, 0, aImage, aImage, true);
241 pEntry->AddItem( pContextBmp );
243 UnoTreeListItem * pUnoItem = new UnoTreeListItem( pEntry );
245 if( !xNode->getNodeGraphicURL().isEmpty() )
247 pUnoItem->SetGraphicURL( xNode->getNodeGraphicURL() );
248 Image aNodeImage;
249 loadImage( xNode->getNodeGraphicURL(), aNodeImage );
250 pUnoItem->SetImage( aNodeImage );
251 mpTreeImpl->AdjustEntryHeight( aNodeImage );
254 pEntry->AddItem( pUnoItem );
256 mpTreeImpl->insert( pEntry, pParent, nPos );
258 if( !msDefaultExpandedGraphicURL.isEmpty() )
259 mpTreeImpl->SetExpandedEntryBmp( pEntry, maDefaultExpandedImage );
261 if( !msDefaultCollapsedGraphicURL.isEmpty() )
262 mpTreeImpl->SetCollapsedEntryBmp( pEntry, maDefaultCollapsedImage );
264 updateEntry( pEntry );
266 return pEntry;
269 // --------------------------------------------------------------------
271 bool TreeControlPeer::updateEntry( UnoTreeListEntry* pEntry )
273 bool bChanged = false;
274 if( pEntry && pEntry->mxNode.is() && mpTreeImpl )
276 const OUString aValue( getEntryString( pEntry->mxNode->getDisplayValue() ) );
277 UnoTreeListItem* pUnoItem = dynamic_cast< UnoTreeListItem* >( pEntry->GetItem( 1 ) );
278 if( pUnoItem )
280 if( aValue != pUnoItem->GetText() )
282 pUnoItem->SetText( aValue );
283 bChanged = true;
286 if( pUnoItem->GetGraphicURL() != pEntry->mxNode->getNodeGraphicURL() )
288 Image aImage;
289 if( loadImage( pEntry->mxNode->getNodeGraphicURL(), aImage ) )
291 pUnoItem->SetGraphicURL( pEntry->mxNode->getNodeGraphicURL() );
292 pUnoItem->SetImage( aImage );
293 mpTreeImpl->AdjustEntryHeight( aImage );
294 bChanged = true;
299 if( (pEntry->mxNode->hasChildrenOnDemand() == sal_True) != (pEntry->HasChildrenOnDemand() == sal_True) )
301 pEntry->EnableChildrenOnDemand( pEntry->mxNode->hasChildrenOnDemand() ? sal_True : sal_False );
302 bChanged = true;
305 ImplContextGraphicItem* pContextGraphicItem = dynamic_cast< ImplContextGraphicItem* >( pEntry->GetItem( 0 ) );
306 if( pContextGraphicItem )
308 if( pContextGraphicItem->msExpandedGraphicURL != pEntry->mxNode->getExpandedGraphicURL() )
310 Image aImage;
311 if( loadImage( pEntry->mxNode->getExpandedGraphicURL(), aImage ) )
313 pContextGraphicItem->msExpandedGraphicURL = pEntry->mxNode->getExpandedGraphicURL();
314 mpTreeImpl->SetExpandedEntryBmp( pEntry, aImage );
315 bChanged = true;
318 if( pContextGraphicItem->msCollapsedGraphicURL != pEntry->mxNode->getCollapsedGraphicURL() )
320 Image aImage;
321 if( loadImage( pEntry->mxNode->getCollapsedGraphicURL(), aImage ) )
323 pContextGraphicItem->msCollapsedGraphicURL = pEntry->mxNode->getCollapsedGraphicURL();
324 mpTreeImpl->SetCollapsedEntryBmp( pEntry, aImage );
325 bChanged = true;
330 if( bChanged )
331 mpTreeImpl->GetModel()->InvalidateEntry( pEntry );
334 return bChanged;
337 // --------------------------------------------------------------------
339 void TreeControlPeer::onSelectionChanged()
341 Reference< XInterface > xSource( static_cast< ::cppu::OWeakObject* >( this ) );
342 EventObject aEvent( xSource );
343 maSelectionListeners.selectionChanged( aEvent );
346 // --------------------------------------------------------------------
348 void TreeControlPeer::onRequestChildNodes( const Reference< XTreeNode >& xNode )
352 Reference< XInterface > xSource( static_cast< ::cppu::OWeakObject* >( this ) );
353 TreeExpansionEvent aEvent( xSource, xNode );
354 maTreeExpansionListeners.requestChildNodes( aEvent );
356 catch( Exception& )
361 // --------------------------------------------------------------------
363 bool TreeControlPeer::onExpanding( const Reference< XTreeNode >& xNode, bool bExpanding )
367 Reference< XInterface > xSource( static_cast< ::cppu::OWeakObject* >( this ) );
368 TreeExpansionEvent aEvent( xSource, xNode );
369 if( bExpanding )
371 maTreeExpansionListeners.treeExpanding( aEvent );
373 else
375 maTreeExpansionListeners.treeCollapsing( aEvent );
378 catch( Exception& )
380 return false;
382 return true;
385 // --------------------------------------------------------------------
387 void TreeControlPeer::onExpanded( const Reference< XTreeNode >& xNode, bool bExpanding )
391 Reference< XInterface > xSource( static_cast< ::cppu::OWeakObject* >( this ) );
392 TreeExpansionEvent aEvent( xSource, xNode );
394 if( bExpanding )
396 maTreeExpansionListeners.treeExpanded( aEvent );
398 else
400 maTreeExpansionListeners.treeCollapsed( aEvent );
403 catch( Exception& )
408 // --------------------------------------------------------------------
410 void TreeControlPeer::fillTree( UnoTreeListBoxImpl& rTree, const Reference< XTreeDataModel >& xDataModel )
412 rTree.Clear();
414 if( xDataModel.is() )
416 Reference< XTreeNode > xRootNode( xDataModel->getRoot() );
417 if( xRootNode.is() )
419 if( mbIsRootDisplayed )
421 addNode( rTree, xRootNode, 0 );
423 else
425 const sal_Int32 nChildCount = xRootNode->getChildCount();
426 for( sal_Int32 nChild = 0; nChild < nChildCount; nChild++ )
427 addNode( rTree, xRootNode->getChildAt( nChild ), 0 );
433 // --------------------------------------------------------------------
435 void TreeControlPeer::addNode( UnoTreeListBoxImpl& rTree, const Reference< XTreeNode >& xNode, UnoTreeListEntry* pParentEntry )
437 if( xNode.is() )
439 UnoTreeListEntry* pEntry = createEntry( xNode, pParentEntry, LIST_APPEND );
440 const sal_Int32 nChildCount = xNode->getChildCount();
441 for( sal_Int32 nChild = 0; nChild < nChildCount; nChild++ )
442 addNode( rTree, xNode->getChildAt( nChild ), pEntry );
446 // --------------------------------------------------------------------
448 UnoTreeListBoxImpl& TreeControlPeer::getTreeListBoxOrThrow() const throw (RuntimeException )
450 if( !mpTreeImpl )
451 throw DisposedException();
452 return *mpTreeImpl;
455 // --------------------------------------------------------------------
457 void TreeControlPeer::ChangeNodesSelection( const Any& rSelection, bool bSelect, bool bSetSelection ) throw( RuntimeException, IllegalArgumentException )
459 SolarMutexGuard aGuard;
461 UnoTreeListBoxImpl& rTree = getTreeListBoxOrThrow();
463 Reference< XTreeNode > xTempNode;
464 Sequence< XTreeNode > aTempSeq;
466 const Reference< XTreeNode > *pNodes = 0;
467 sal_Int32 nCount = 0;
469 if( rSelection.hasValue() )
471 switch( rSelection.getValueTypeClass() )
473 case TypeClass_INTERFACE:
475 rSelection >>= xTempNode;
476 if( xTempNode.is() )
478 nCount = 1;
479 pNodes = &xTempNode;
481 break;
483 case TypeClass_SEQUENCE:
485 if( rSelection.getValueType() == ::getCppuType( (const Sequence< Reference< XTreeNode > > *) 0 ) )
487 const Sequence< Reference< XTreeNode > >& rSeq( *(const Sequence< Reference< XTreeNode > > *)rSelection.getValue() );
488 nCount = rSeq.getLength();
489 if( nCount )
490 pNodes = rSeq.getConstArray();
492 break;
494 default:
495 break;
498 if( nCount == 0 )
499 throw IllegalArgumentException();
502 if( bSetSelection )
503 rTree.SelectAll( sal_False );
505 if( pNodes && nCount )
507 while( nCount-- )
509 UnoTreeListEntry* pEntry = getEntry( *pNodes++ );
510 rTree.Select( pEntry, bSelect ? sal_True : sal_False );
515 // -------------------------------------------------------------------
516 // ::com::sun::star::view::XSelectionSupplier
517 // -------------------------------------------------------------------
519 sal_Bool SAL_CALL TreeControlPeer::select( const Any& rSelection ) throw (IllegalArgumentException, RuntimeException)
521 SolarMutexGuard aGuard;
522 ChangeNodesSelection( rSelection, true, true );
523 return sal_True;
526 // -------------------------------------------------------------------
528 Any SAL_CALL TreeControlPeer::getSelection() throw (RuntimeException)
530 SolarMutexGuard aGuard;
532 UnoTreeListBoxImpl& rTree = getTreeListBoxOrThrow();
534 Any aRet;
536 sal_uLong nSelectionCount = rTree.GetSelectionCount();
537 if( nSelectionCount == 1 )
539 UnoTreeListEntry* pEntry = dynamic_cast< UnoTreeListEntry* >( rTree.FirstSelected() );
540 if( pEntry && pEntry->mxNode.is() )
541 aRet <<= pEntry->mxNode;
543 else if( nSelectionCount > 1 )
545 Sequence< Reference< XTreeNode > > aSelection( nSelectionCount );
546 Reference< XTreeNode >* pNodes = aSelection.getArray();
547 UnoTreeListEntry* pEntry = dynamic_cast< UnoTreeListEntry* >( rTree.FirstSelected() );
548 while( pEntry && nSelectionCount )
550 *pNodes++ = pEntry->mxNode;
551 pEntry = dynamic_cast< UnoTreeListEntry* >( rTree.NextSelected( pEntry ) );
552 --nSelectionCount;
555 OSL_ASSERT( (pEntry == 0) && (nSelectionCount == 0) );
556 aRet <<= aSelection;
559 return aRet;
562 // -------------------------------------------------------------------
564 void SAL_CALL TreeControlPeer::addSelectionChangeListener( const Reference< XSelectionChangeListener >& xListener ) throw (RuntimeException)
566 maSelectionListeners.addInterface( xListener );
569 // -------------------------------------------------------------------
571 void SAL_CALL TreeControlPeer::removeSelectionChangeListener( const Reference< XSelectionChangeListener >& xListener ) throw (RuntimeException)
573 maSelectionListeners.addInterface( xListener );
576 // -------------------------------------------------------------------
577 // ::com::sun::star::view::XMultiSelectionSupplier
578 // -------------------------------------------------------------------
580 sal_Bool SAL_CALL TreeControlPeer::addSelection( const Any& rSelection ) throw (IllegalArgumentException, RuntimeException)
582 ChangeNodesSelection( rSelection, true, false );
583 return sal_True;
586 // -------------------------------------------------------------------
588 void SAL_CALL TreeControlPeer::removeSelection( const Any& rSelection ) throw (IllegalArgumentException, RuntimeException)
590 ChangeNodesSelection( rSelection, false, false );
593 // -------------------------------------------------------------------
595 void SAL_CALL TreeControlPeer::clearSelection() throw (RuntimeException)
597 SolarMutexGuard aGuard;
598 getTreeListBoxOrThrow().SelectAll( sal_False );
601 // -------------------------------------------------------------------
603 sal_Int32 SAL_CALL TreeControlPeer::getSelectionCount() throw (RuntimeException)
605 SolarMutexGuard aGuard;
606 return getTreeListBoxOrThrow().GetSelectionCount();
609 // -------------------------------------------------------------------
611 class TreeSelectionEnumeration : public ::cppu::WeakImplHelper1< XEnumeration >
613 public:
614 TreeSelectionEnumeration( std::list< Any >& rSelection );
615 virtual ::sal_Bool SAL_CALL hasMoreElements() throw (RuntimeException);
616 virtual Any SAL_CALL nextElement() throw (NoSuchElementException, WrappedTargetException, RuntimeException);
618 std::list< Any > maSelection;
619 std::list< Any >::iterator maIter;
622 // -------------------------------------------------------------------
624 TreeSelectionEnumeration::TreeSelectionEnumeration( std::list< Any >& rSelection )
626 maSelection.swap( rSelection );
627 maIter = maSelection.begin();
630 // -------------------------------------------------------------------
632 ::sal_Bool SAL_CALL TreeSelectionEnumeration::hasMoreElements() throw (RuntimeException)
634 return maIter != maSelection.end();
637 // -------------------------------------------------------------------
639 Any SAL_CALL TreeSelectionEnumeration::nextElement() throw (NoSuchElementException, WrappedTargetException, RuntimeException)
641 if( maIter == maSelection.end() )
642 throw NoSuchElementException();
644 return (*maIter++);
647 // -------------------------------------------------------------------
649 Reference< XEnumeration > SAL_CALL TreeControlPeer::createSelectionEnumeration() throw (RuntimeException)
651 SolarMutexGuard aGuard;
653 UnoTreeListBoxImpl& rTree = getTreeListBoxOrThrow();
655 sal_uInt32 nSelectionCount = rTree.GetSelectionCount();
656 std::list< Any > aSelection( nSelectionCount );
658 UnoTreeListEntry* pEntry = dynamic_cast< UnoTreeListEntry* >( rTree.FirstSelected() );
659 while( pEntry && nSelectionCount )
661 aSelection.push_back( Any( pEntry->mxNode ) );
662 pEntry = dynamic_cast< UnoTreeListEntry* >( rTree.NextSelected( pEntry ) );
663 --nSelectionCount;
666 OSL_ASSERT( (pEntry == 0) && (nSelectionCount == 0) );
668 return Reference< XEnumeration >( new TreeSelectionEnumeration( aSelection ) );
671 // -------------------------------------------------------------------
673 Reference< XEnumeration > SAL_CALL TreeControlPeer::createReverseSelectionEnumeration() throw (RuntimeException)
675 SolarMutexGuard aGuard;
677 UnoTreeListBoxImpl& rTree = getTreeListBoxOrThrow();
679 sal_uInt32 nSelectionCount = rTree.GetSelectionCount();
680 std::list< Any > aSelection;
682 UnoTreeListEntry* pEntry = dynamic_cast< UnoTreeListEntry* >( rTree.FirstSelected() );
683 while( pEntry && nSelectionCount )
685 aSelection.push_front( Any( pEntry->mxNode ) );
686 pEntry = dynamic_cast< UnoTreeListEntry* >( rTree.NextSelected( pEntry ) );
687 --nSelectionCount;
690 OSL_ASSERT( (pEntry == 0) && (nSelectionCount == 0) );
692 return Reference< XEnumeration >( new TreeSelectionEnumeration( aSelection ) );
695 // --------------------------------------------------------------------
696 // ::com::sun::star::awt::XTreeControl
697 // --------------------------------------------------------------------
699 OUString SAL_CALL TreeControlPeer::getDefaultExpandedGraphicURL() throw (::com::sun::star::uno::RuntimeException)
701 SolarMutexGuard aGuard;
702 return msDefaultExpandedGraphicURL;
705 // --------------------------------------------------------------------
707 void SAL_CALL TreeControlPeer::setDefaultExpandedGraphicURL( const OUString& sDefaultExpandedGraphicURL ) throw (::com::sun::star::uno::RuntimeException)
709 SolarMutexGuard aGuard;
710 if( msDefaultExpandedGraphicURL != sDefaultExpandedGraphicURL )
712 if( !sDefaultExpandedGraphicURL.isEmpty() )
713 loadImage( sDefaultExpandedGraphicURL, maDefaultExpandedImage );
714 else
715 maDefaultExpandedImage = Image();
717 UnoTreeListBoxImpl& rTree = getTreeListBoxOrThrow();
719 SvTreeListEntry* pEntry = rTree.First();
720 while( pEntry )
722 ImplContextGraphicItem* pContextGraphicItem = dynamic_cast< ImplContextGraphicItem* >( pEntry->GetItem( 0 ) );
723 if( pContextGraphicItem )
725 if( pContextGraphicItem->msExpandedGraphicURL.isEmpty() )
726 rTree.SetExpandedEntryBmp( pEntry, maDefaultExpandedImage );
728 pEntry = rTree.Next( pEntry );
731 msDefaultExpandedGraphicURL = sDefaultExpandedGraphicURL;
735 // --------------------------------------------------------------------
737 OUString SAL_CALL TreeControlPeer::getDefaultCollapsedGraphicURL() throw (::com::sun::star::uno::RuntimeException)
739 SolarMutexGuard aGuard;
740 return msDefaultCollapsedGraphicURL;
743 // --------------------------------------------------------------------
745 void SAL_CALL TreeControlPeer::setDefaultCollapsedGraphicURL( const OUString& sDefaultCollapsedGraphicURL ) throw (::com::sun::star::uno::RuntimeException)
747 SolarMutexGuard aGuard;
748 if( msDefaultCollapsedGraphicURL != sDefaultCollapsedGraphicURL )
750 if( !sDefaultCollapsedGraphicURL.isEmpty() )
751 loadImage( sDefaultCollapsedGraphicURL, maDefaultCollapsedImage );
752 else
753 maDefaultCollapsedImage = Image();
755 UnoTreeListBoxImpl& rTree = getTreeListBoxOrThrow();
757 SvTreeListEntry* pEntry = rTree.First();
758 while( pEntry )
760 ImplContextGraphicItem* pContextGraphicItem = dynamic_cast< ImplContextGraphicItem* >( pEntry->GetItem( 0 ) );
761 if( pContextGraphicItem )
763 if( pContextGraphicItem->msCollapsedGraphicURL.isEmpty() )
764 rTree.SetCollapsedEntryBmp( pEntry, maDefaultCollapsedImage );
766 pEntry = rTree.Next( pEntry );
769 msDefaultCollapsedGraphicURL = sDefaultCollapsedGraphicURL;
773 // --------------------------------------------------------------------
775 sal_Bool SAL_CALL TreeControlPeer::isNodeExpanded( const Reference< XTreeNode >& xNode ) throw (RuntimeException, IllegalArgumentException)
777 SolarMutexGuard aGuard;
779 UnoTreeListBoxImpl& rTree = getTreeListBoxOrThrow();
780 UnoTreeListEntry* pEntry = getEntry( xNode );
781 return ( pEntry && rTree.IsExpanded( pEntry ) ) ? sal_True : sal_False;
784 // -------------------------------------------------------------------
786 sal_Bool SAL_CALL TreeControlPeer::isNodeCollapsed( const Reference< XTreeNode >& xNode ) throw (RuntimeException, IllegalArgumentException)
788 SolarMutexGuard aGuard;
789 return !isNodeExpanded( xNode );
792 // -------------------------------------------------------------------
794 void SAL_CALL TreeControlPeer::makeNodeVisible( const Reference< XTreeNode >& xNode ) throw (RuntimeException, ExpandVetoException, IllegalArgumentException)
796 SolarMutexGuard aGuard;
798 UnoTreeListBoxImpl& rTree = getTreeListBoxOrThrow();
799 UnoTreeListEntry* pEntry = getEntry( xNode );
800 if( pEntry )
801 rTree.MakeVisible( pEntry );
804 // -------------------------------------------------------------------
806 sal_Bool SAL_CALL TreeControlPeer::isNodeVisible( const Reference< XTreeNode >& xNode ) throw (RuntimeException, IllegalArgumentException)
808 SolarMutexGuard aGuard;
810 UnoTreeListBoxImpl& rTree = getTreeListBoxOrThrow();
811 UnoTreeListEntry* pEntry = getEntry( xNode );
812 return ( pEntry && rTree.IsEntryVisible( pEntry ) ) ? sal_True : sal_False;
815 // -------------------------------------------------------------------
817 void SAL_CALL TreeControlPeer::expandNode( const Reference< XTreeNode >& xNode ) throw (RuntimeException, ExpandVetoException, IllegalArgumentException)
819 SolarMutexGuard aGuard;
821 UnoTreeListBoxImpl& rTree = getTreeListBoxOrThrow();
822 UnoTreeListEntry* pEntry = getEntry( xNode );
823 if( pEntry )
824 rTree.Expand( pEntry );
827 // -------------------------------------------------------------------
829 void SAL_CALL TreeControlPeer::collapseNode( const Reference< XTreeNode >& xNode ) throw (RuntimeException, ExpandVetoException, IllegalArgumentException)
831 SolarMutexGuard aGuard;
833 UnoTreeListBoxImpl& rTree = getTreeListBoxOrThrow();
834 UnoTreeListEntry* pEntry = getEntry( xNode );
835 if( pEntry )
836 rTree.Collapse( pEntry );
839 // -------------------------------------------------------------------
841 void SAL_CALL TreeControlPeer::addTreeExpansionListener( const Reference< XTreeExpansionListener >& xListener ) throw (RuntimeException)
843 maTreeExpansionListeners.addInterface( xListener );
846 // -------------------------------------------------------------------
848 void SAL_CALL TreeControlPeer::removeTreeExpansionListener( const Reference< XTreeExpansionListener >& xListener ) throw (RuntimeException)
850 maTreeExpansionListeners.removeInterface( xListener );
853 // -------------------------------------------------------------------
855 Reference< XTreeNode > SAL_CALL TreeControlPeer::getNodeForLocation( sal_Int32 x, sal_Int32 y ) throw (RuntimeException)
857 SolarMutexGuard aGuard;
859 UnoTreeListBoxImpl& rTree = getTreeListBoxOrThrow();
861 Reference< XTreeNode > xNode;
863 const Point aPos( x, y );
864 UnoTreeListEntry* pEntry = dynamic_cast< UnoTreeListEntry* >( rTree.GetEntry( aPos, sal_True ) );
865 if( pEntry )
866 xNode = pEntry->mxNode;
868 return xNode;
871 // -------------------------------------------------------------------
873 Reference< XTreeNode > SAL_CALL TreeControlPeer::getClosestNodeForLocation( sal_Int32 x, sal_Int32 y ) throw (RuntimeException)
875 SolarMutexGuard aGuard;
877 UnoTreeListBoxImpl& rTree = getTreeListBoxOrThrow();
879 Reference< XTreeNode > xNode;
881 const Point aPos( x, y );
882 UnoTreeListEntry* pEntry = dynamic_cast< UnoTreeListEntry* >( rTree.GetEntry( aPos, sal_True ) );
883 if( pEntry )
884 xNode = pEntry->mxNode;
886 return xNode;
889 // -------------------------------------------------------------------
891 awt::Rectangle SAL_CALL TreeControlPeer::getNodeRect( const Reference< XTreeNode >& i_Node ) throw (IllegalArgumentException, RuntimeException)
893 SolarMutexGuard aGuard;
895 UnoTreeListBoxImpl& rTree = getTreeListBoxOrThrow();
896 UnoTreeListEntry* pEntry = getEntry( i_Node, true );
898 ::Rectangle aEntryRect( rTree.GetFocusRect( pEntry, rTree.GetEntryPosition( pEntry ).Y() ) );
899 return VCLUnoHelper::ConvertToAWTRect( aEntryRect );
902 // -------------------------------------------------------------------
904 sal_Bool SAL_CALL TreeControlPeer::isEditing( ) throw (RuntimeException)
906 SolarMutexGuard aGuard;
908 UnoTreeListBoxImpl& rTree = getTreeListBoxOrThrow();
909 return rTree.IsEditingActive() ? sal_True : sal_False;
912 // -------------------------------------------------------------------
914 sal_Bool SAL_CALL TreeControlPeer::stopEditing() throw (RuntimeException)
916 SolarMutexGuard aGuard;
918 UnoTreeListBoxImpl& rTree = getTreeListBoxOrThrow();
919 if( rTree.IsEditingActive() )
921 rTree.EndEditing(sal_False);
922 return sal_True;
924 else
926 return sal_False;
930 // -------------------------------------------------------------------
932 void SAL_CALL TreeControlPeer::cancelEditing( ) throw (RuntimeException)
934 SolarMutexGuard aGuard;
936 UnoTreeListBoxImpl& rTree = getTreeListBoxOrThrow();
937 rTree.EndEditing(sal_False);
940 // -------------------------------------------------------------------
942 void SAL_CALL TreeControlPeer::startEditingAtNode( const Reference< XTreeNode >& xNode ) throw (IllegalArgumentException, RuntimeException)
944 SolarMutexGuard aGuard;
946 UnoTreeListBoxImpl& rTree = getTreeListBoxOrThrow();
947 UnoTreeListEntry* pEntry = getEntry( xNode );
948 rTree.EditEntry( pEntry );
951 void SAL_CALL TreeControlPeer::addTreeEditListener( const Reference< XTreeEditListener >& xListener ) throw (RuntimeException)
953 maTreeEditListeners.addInterface( xListener );
956 void SAL_CALL TreeControlPeer::removeTreeEditListener( const Reference< XTreeEditListener >& xListener ) throw (RuntimeException)
958 maTreeEditListeners.removeInterface( xListener );
961 bool TreeControlPeer::onEditingEntry( UnoTreeListEntry* pEntry )
963 if( mpTreeImpl && pEntry && pEntry->mxNode.is() && (maTreeEditListeners.getLength() > 0) )
967 maTreeEditListeners.nodeEditing( pEntry->mxNode );
969 catch( VetoException& )
971 return false;
973 catch( Exception& )
977 return true;
980 bool TreeControlPeer::onEditedEntry( UnoTreeListEntry* pEntry, const OUString& rNewText )
982 if( mpTreeImpl && pEntry && pEntry->mxNode.is() ) try
984 LockGuard aLockGuard( mnEditLock );
985 if( maTreeEditListeners.getLength() > 0 )
987 maTreeEditListeners.nodeEdited( pEntry->mxNode, rNewText );
988 return false;
990 else
992 Reference< XMutableTreeNode > xMutableNode( pEntry->mxNode, UNO_QUERY );
993 if( xMutableNode.is() )
994 xMutableNode->setDisplayValue( Any( rNewText ) );
995 else
996 return false;
1000 catch( Exception& )
1004 return true;
1007 // --------------------------------------------------------------------
1008 // ::com::sun::star::awt::tree::TreeDataModelListener
1009 // --------------------------------------------------------------------
1011 void SAL_CALL TreeControlPeer::treeNodesChanged( const ::com::sun::star::awt::tree::TreeDataModelEvent& rEvent ) throw (RuntimeException)
1013 SolarMutexGuard aGuard;
1015 if( mnEditLock != 0 )
1016 return;
1018 updateTree( rEvent, true );
1021 void SAL_CALL TreeControlPeer::treeNodesInserted( const ::com::sun::star::awt::tree::TreeDataModelEvent& rEvent ) throw (RuntimeException)
1023 SolarMutexGuard aGuard;
1025 if( mnEditLock != 0 )
1026 return;
1028 updateTree( rEvent, true );
1031 void SAL_CALL TreeControlPeer::treeNodesRemoved( const ::com::sun::star::awt::tree::TreeDataModelEvent& rEvent ) throw (RuntimeException)
1033 SolarMutexGuard aGuard;
1035 if( mnEditLock != 0 )
1036 return;
1038 updateTree( rEvent, true );
1041 void SAL_CALL TreeControlPeer::treeStructureChanged( const ::com::sun::star::awt::tree::TreeDataModelEvent& rEvent ) throw (RuntimeException)
1043 SolarMutexGuard aGuard;
1045 if( mnEditLock != 0 )
1046 return;
1048 updateTree( rEvent, true );
1051 void TreeControlPeer::updateTree( const ::com::sun::star::awt::tree::TreeDataModelEvent& rEvent, bool bRecursive )
1053 UnoTreeListBoxImpl& rTree = getTreeListBoxOrThrow();
1055 Sequence< Reference< XTreeNode > > Nodes;
1056 Reference< XTreeNode > xNode( rEvent.ParentNode );
1057 if( !xNode.is() && Nodes.getLength() )
1059 xNode = Nodes[0];
1062 if( xNode.is() )
1063 updateNode( rTree, xNode, bRecursive );
1066 void TreeControlPeer::updateNode( UnoTreeListBoxImpl& rTree, const Reference< XTreeNode >& xNode, bool bRecursive )
1068 if( xNode.is() )
1070 UnoTreeListEntry* pNodeEntry = getEntry( xNode, false );
1072 if( !pNodeEntry )
1074 Reference< XTreeNode > xParentNode( xNode->getParent() );
1075 UnoTreeListEntry* pParentEntry = 0;
1076 sal_uLong nChild = LIST_APPEND;
1078 if( xParentNode.is() )
1080 pParentEntry = getEntry( xParentNode );
1081 nChild = xParentNode->getIndex( xNode );
1084 pNodeEntry = createEntry( xNode, pParentEntry, nChild );
1087 if( bRecursive )
1088 updateChildNodes( rTree, xNode, pNodeEntry );
1092 void TreeControlPeer::updateChildNodes( UnoTreeListBoxImpl& rTree, const Reference< XTreeNode >& xParentNode, UnoTreeListEntry* pParentEntry )
1094 if( xParentNode.is() && pParentEntry )
1096 UnoTreeListEntry* pCurrentChild = dynamic_cast< UnoTreeListEntry* >( rTree.FirstChild( pParentEntry ) );
1098 const sal_Int32 nChildCount = xParentNode->getChildCount();
1099 for( sal_Int32 nChild = 0; nChild < nChildCount; nChild++ )
1101 Reference< XTreeNode > xNode( xParentNode->getChildAt( nChild ) );
1102 if( !pCurrentChild || ( pCurrentChild->mxNode != xNode ) )
1104 UnoTreeListEntry* pNodeEntry = getEntry( xNode, false );
1105 if( pNodeEntry == 0 )
1107 // child node is not yet part of the tree, add it
1108 pCurrentChild = createEntry( xNode, pParentEntry, nChild );
1110 else if( pNodeEntry != pCurrentChild )
1112 // node is already part of the tree, but not on the correct position
1113 rTree.GetModel()->Move( pNodeEntry, pParentEntry, nChild );
1114 pCurrentChild = pNodeEntry;
1115 updateEntry( pCurrentChild );
1118 else
1120 // child node has entry and entry is equal to current entry,
1121 // so no structural changes happened
1122 updateEntry( pCurrentChild );
1125 pCurrentChild = dynamic_cast< UnoTreeListEntry* >( rTree.NextSibling( pCurrentChild ) );
1128 // check if we have entries without nodes left, we need to remove them
1129 while( pCurrentChild )
1131 UnoTreeListEntry* pNextChild = dynamic_cast< UnoTreeListEntry* >( rTree.NextSibling( pCurrentChild ) );
1132 rTree.GetModel()->Remove( pCurrentChild );
1133 pCurrentChild = pNextChild;
1138 OUString TreeControlPeer::getEntryString( const Any& rValue )
1140 OUString sValue;
1141 if( rValue.hasValue() )
1143 switch( rValue.getValueTypeClass() )
1145 case TypeClass_SHORT:
1146 case TypeClass_LONG:
1148 sal_Int32 nValue = 0;
1149 if( rValue >>= nValue )
1150 sValue = OUString::valueOf( nValue );
1151 break;
1153 case TypeClass_BYTE:
1154 case TypeClass_UNSIGNED_SHORT:
1155 case TypeClass_UNSIGNED_LONG:
1157 sal_uInt32 nValue = 0;
1158 if( rValue >>= nValue )
1159 sValue = OUString::valueOf( (sal_Int64)nValue );
1160 break;
1162 case TypeClass_HYPER:
1164 sal_Int64 nValue = 0;
1165 if( rValue >>= nValue )
1166 sValue = OUString::valueOf( nValue );
1167 break;
1169 case TypeClass_UNSIGNED_HYPER:
1171 sal_uInt64 nValue = 0;
1172 if( rValue >>= nValue )
1173 sValue = OUString::valueOf( (sal_Int64)nValue );
1174 break;
1176 case TypeClass_FLOAT:
1177 case TypeClass_DOUBLE:
1179 double fValue = 0.0;
1180 if( rValue >>= fValue )
1181 sValue = OUString::valueOf( fValue );
1182 break;
1184 case TypeClass_STRING:
1185 rValue >>= sValue;
1186 break;
1188 case TypeClass_INTERFACE:
1189 // @todo
1190 break;
1191 case TypeClass_SEQUENCE:
1193 Sequence< Any > aValues;
1194 if( aValue >>= aValues )
1196 updateEntry( SvTreeListEntry& rEntry, aValues );
1197 return;
1200 break;
1202 default:
1203 break;
1206 return sValue;
1209 // XEventListener
1210 void SAL_CALL TreeControlPeer::disposing( const ::com::sun::star::lang::EventObject& ) throw(::com::sun::star::uno::RuntimeException)
1212 // model is disposed, so we clear our tree
1213 SolarMutexGuard aGuard;
1214 UnoTreeListBoxImpl& rTree = getTreeListBoxOrThrow();
1215 rTree.Clear();
1216 mxDataModel.clear();
1219 void TreeControlPeer::onChangeDataModel( UnoTreeListBoxImpl& rTree, const Reference< XTreeDataModel >& xDataModel )
1221 if( xDataModel.is() && (mxDataModel == xDataModel) )
1222 return; // do nothing
1224 Reference< XTreeDataModelListener > xListener( this );
1226 if( mxDataModel.is() )
1227 mxDataModel->removeTreeDataModelListener( xListener );
1229 if( !xDataModel.is() )
1231 static const OUString aSN( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.awt.tree.DefaultTreeDataModel" ) );
1232 Reference< XMultiServiceFactory > xORB( ::comphelper::getProcessServiceFactory() );
1233 if( xORB.is() )
1235 mxDataModel.query( xORB->createInstance( aSN ) );
1239 mxDataModel = xDataModel;
1241 fillTree( rTree, mxDataModel );
1243 if( mxDataModel.is() )
1244 mxDataModel->addTreeDataModelListener( xListener );
1247 // --------------------------------------------------------------------
1248 // ::com::sun::star::awt::XLayoutConstrains
1249 // --------------------------------------------------------------------
1251 ::com::sun::star::awt::Size TreeControlPeer::getMinimumSize() throw(RuntimeException)
1253 SolarMutexGuard aGuard;
1255 ::com::sun::star::awt::Size aSz;
1256 /* todo
1257 MultiLineEdit* pEdit = (MultiLineEdit*) GetWindow();
1258 if ( pEdit )
1259 aSz = AWTSize(pEdit->CalcMinimumSize());
1261 return aSz;
1264 ::com::sun::star::awt::Size TreeControlPeer::getPreferredSize() throw(RuntimeException)
1266 return getMinimumSize();
1269 ::com::sun::star::awt::Size TreeControlPeer::calcAdjustedSize( const ::com::sun::star::awt::Size& rNewSize ) throw(RuntimeException)
1271 SolarMutexGuard aGuard;
1273 ::com::sun::star::awt::Size aSz = rNewSize;
1274 /* todo
1275 MultiLineEdit* pEdit = (MultiLineEdit*) GetWindow();
1276 if ( pEdit )
1277 aSz = AWTSize(pEdit->CalcAdjustedSize( VCLSize(rNewSize )));
1279 return aSz;
1282 // --------------------------------------------------------------------
1283 // ::com::sun::star::awt::XVclWindowPeer
1284 // --------------------------------------------------------------------
1286 void TreeControlPeer::setProperty( const OUString& PropertyName, const Any& aValue) throw(RuntimeException)
1288 SolarMutexGuard aGuard;
1290 UnoTreeListBoxImpl& rTree = getTreeListBoxOrThrow();
1292 switch( GetPropertyId( PropertyName ) )
1294 case BASEPROPERTY_HIDEINACTIVESELECTION:
1296 sal_Bool bEnabled = sal_False;
1297 if ( aValue >>= bEnabled )
1299 WinBits nStyle = rTree.GetStyle();
1300 if ( bEnabled )
1301 nStyle |= WB_HIDESELECTION;
1302 else
1303 nStyle &= ~WB_HIDESELECTION;
1304 rTree.SetStyle( nStyle );
1307 break;
1309 case BASEPROPERTY_TREE_SELECTIONTYPE:
1311 SelectionType eSelectionType;
1312 if( aValue >>= eSelectionType )
1314 SelectionMode eSelMode;
1315 switch( eSelectionType )
1317 case SelectionType_SINGLE: eSelMode = SINGLE_SELECTION; break;
1318 case SelectionType_RANGE: eSelMode = RANGE_SELECTION; break;
1319 case SelectionType_MULTI: eSelMode = MULTIPLE_SELECTION; break;
1320 // case SelectionType_NONE:
1321 default: eSelMode = NO_SELECTION; break;
1323 if( rTree.GetSelectionMode() != eSelMode )
1324 rTree.SetSelectionMode( eSelMode );
1326 break;
1329 case BASEPROPERTY_TREE_DATAMODEL:
1330 onChangeDataModel( rTree, Reference< XTreeDataModel >( aValue, UNO_QUERY ) );
1331 break;
1332 case BASEPROPERTY_ROW_HEIGHT:
1334 sal_Int32 nHeight = 0;
1335 if( aValue >>= nHeight )
1336 rTree.SetEntryHeight( (short)nHeight );
1337 break;
1339 case BASEPROPERTY_TREE_EDITABLE:
1341 sal_Bool bEnabled = false;
1342 if( aValue >>= bEnabled )
1343 rTree.EnableInplaceEditing( bEnabled ? sal_True : sal_False );
1344 break;
1346 case BASEPROPERTY_TREE_INVOKESSTOPNODEEDITING:
1347 break; // @todo
1348 case BASEPROPERTY_TREE_ROOTDISPLAYED:
1350 sal_Bool bDisplayed = false;
1351 if( (aValue >>= bDisplayed) && ( bDisplayed != mbIsRootDisplayed) )
1353 onChangeRootDisplayed(bDisplayed);
1355 break;
1357 case BASEPROPERTY_TREE_SHOWSHANDLES:
1359 sal_Bool bEnabled = false;
1360 if( aValue >>= bEnabled )
1362 WinBits nBits = rTree.GetStyle() & (~WB_HASLINES);
1363 if( bEnabled )
1364 nBits |= WB_HASLINES;
1365 if( nBits != rTree.GetStyle() )
1366 rTree.SetStyle( nBits );
1368 break;
1370 case BASEPROPERTY_TREE_SHOWSROOTHANDLES:
1372 sal_Bool bEnabled = false;
1373 if( aValue >>= bEnabled )
1375 WinBits nBits = rTree.GetStyle() & (~WB_HASLINESATROOT);
1376 if( bEnabled )
1377 nBits |= WB_HASLINESATROOT;
1378 if( nBits != rTree.GetStyle() )
1379 rTree.SetStyle( nBits );
1381 break;
1383 default:
1384 VCLXWindow::setProperty( PropertyName, aValue );
1385 break;
1389 Any TreeControlPeer::getProperty( const OUString& PropertyName ) throw(RuntimeException)
1391 SolarMutexGuard aGuard;
1393 const sal_uInt16 nPropId = GetPropertyId( PropertyName );
1394 if( (nPropId >= BASEPROPERTY_TREE_START) && (nPropId <= BASEPROPERTY_TREE_END) )
1396 UnoTreeListBoxImpl& rTree = getTreeListBoxOrThrow();
1397 switch(nPropId)
1399 case BASEPROPERTY_HIDEINACTIVESELECTION:
1400 return Any( ( rTree.GetStyle() & WB_HIDESELECTION ) != 0 ? sal_True : sal_False );
1402 case BASEPROPERTY_TREE_SELECTIONTYPE:
1404 SelectionType eSelectionType;
1406 SelectionMode eSelMode = rTree.GetSelectionMode();
1407 switch( eSelMode )
1409 case SINGLE_SELECTION: eSelectionType = SelectionType_SINGLE; break;
1410 case RANGE_SELECTION: eSelectionType = SelectionType_RANGE; break;
1411 case MULTIPLE_SELECTION:eSelectionType = SelectionType_MULTI; break;
1412 // case NO_SELECTION:
1413 default: eSelectionType = SelectionType_NONE; break;
1415 return Any( eSelectionType );
1417 case BASEPROPERTY_ROW_HEIGHT:
1418 return Any( (sal_Int32)rTree.GetEntryHeight() );
1419 case BASEPROPERTY_TREE_DATAMODEL:
1420 return Any( mxDataModel );
1421 case BASEPROPERTY_TREE_EDITABLE:
1422 return Any( rTree.IsInplaceEditingEnabled() ? sal_True : sal_False );
1423 case BASEPROPERTY_TREE_INVOKESSTOPNODEEDITING:
1424 return Any( sal_True ); // @todo
1425 case BASEPROPERTY_TREE_ROOTDISPLAYED:
1426 return Any( mbIsRootDisplayed );
1427 case BASEPROPERTY_TREE_SHOWSHANDLES:
1428 return Any( (rTree.GetStyle() & WB_HASLINES) != 0 ? sal_True : sal_False );
1429 case BASEPROPERTY_TREE_SHOWSROOTHANDLES:
1430 return Any( (rTree.GetStyle() & WB_HASLINESATROOT) != 0 ? sal_True : sal_False );
1433 return VCLXWindow::getProperty( PropertyName );
1436 void TreeControlPeer::onChangeRootDisplayed( sal_Bool bIsRootDisplayed )
1438 if( mbIsRootDisplayed == bIsRootDisplayed )
1439 return;
1441 mbIsRootDisplayed = bIsRootDisplayed;
1443 UnoTreeListBoxImpl& rTree = getTreeListBoxOrThrow();
1445 if( rTree.GetEntryCount() == 0 )
1446 return;
1448 // todo
1449 fillTree( rTree, mxDataModel );
1450 if( mbIsRootDisplayed )
1453 else
1458 bool TreeControlPeer::loadImage( const OUString& rURL, Image& rImage )
1460 if( !mxGraphicProvider.is() )
1462 Reference< XComponentContext > xContext( ::comphelper::getProcessComponentContext() );
1463 Reference< XInterface > x( graphic::GraphicProvider::create(xContext) );
1464 mxGraphicProvider.query( x );
1465 mxGraphicProvider = Reference< XGraphicProvider >( x, UNO_QUERY );
1468 if( mxGraphicProvider.is() ) try
1470 ::com::sun::star::beans::PropertyValues aProps( 1 );
1471 aProps[0].Name = OUString( "URL" );
1472 aProps[0].Value <<= rURL;
1474 Reference< XGraphic > xGraphic( mxGraphicProvider->queryGraphic( aProps ) );
1476 Graphic aGraphic( xGraphic );
1477 rImage = aGraphic.GetBitmapEx();
1478 return true;
1480 catch( Exception& )
1484 return false;
1487 // ====================================================================
1488 // class UnoTreeListBoxImpl
1489 // ====================================================================
1491 UnoTreeListBoxImpl::UnoTreeListBoxImpl( TreeControlPeer* pPeer, Window* pParent, WinBits nWinStyle )
1492 : SvTreeListBox( pParent, nWinStyle )
1493 , mxPeer( pPeer )
1495 SetStyle( WB_BORDER | WB_HASLINES |WB_HASBUTTONS | WB_HASLINESATROOT | WB_HASBUTTONSATROOT | WB_HSCROLL );
1496 SetNodeDefaultImages();
1497 SetSelectHdl( LINK(this, UnoTreeListBoxImpl, OnSelectionChangeHdl) );
1498 SetDeselectHdl( LINK(this, UnoTreeListBoxImpl, OnSelectionChangeHdl) );
1500 SetExpandingHdl( LINK(this, UnoTreeListBoxImpl, OnExpandingHdl) );
1501 SetExpandedHdl( LINK(this, UnoTreeListBoxImpl, OnExpandedHdl) );
1505 // --------------------------------------------------------------------
1507 UnoTreeListBoxImpl::~UnoTreeListBoxImpl()
1509 if( mxPeer.is() )
1510 mxPeer->disposeControl();
1513 // --------------------------------------------------------------------
1515 IMPL_LINK_NOARG(UnoTreeListBoxImpl, OnSelectionChangeHdl)
1517 if( mxPeer.is() )
1518 mxPeer->onSelectionChanged();
1519 return 0;
1522 // --------------------------------------------------------------------
1524 IMPL_LINK_NOARG(UnoTreeListBoxImpl, OnExpandingHdl)
1526 UnoTreeListEntry* pEntry = dynamic_cast< UnoTreeListEntry* >( GetHdlEntry() );
1528 if( pEntry && mxPeer.is() )
1530 return mxPeer->onExpanding( pEntry->mxNode, !IsExpanded( pEntry ) ) ? 1 : 0;
1532 return 0;
1535 // --------------------------------------------------------------------
1537 IMPL_LINK_NOARG(UnoTreeListBoxImpl, OnExpandedHdl)
1539 UnoTreeListEntry* pEntry = dynamic_cast< UnoTreeListEntry* >( GetHdlEntry() );
1540 if( pEntry && mxPeer.is() )
1542 mxPeer->onExpanded( pEntry->mxNode, IsExpanded( pEntry ) );
1544 return 0;
1547 // --------------------------------------------------------------------
1549 sal_uInt32 UnoTreeListBoxImpl::insert( SvTreeListEntry* pEntry,SvTreeListEntry* pParent,sal_uLong nPos )
1551 if( pParent )
1552 return SvTreeListBox::Insert( pEntry, pParent, nPos );
1553 else
1554 return SvTreeListBox::Insert( pEntry, nPos );
1557 // --------------------------------------------------------------------
1559 void UnoTreeListBoxImpl::RequestingChildren( SvTreeListEntry* pParent )
1561 UnoTreeListEntry* pEntry = dynamic_cast< UnoTreeListEntry* >( pParent );
1562 if( pEntry && pEntry->mxNode.is() && mxPeer.is() )
1563 mxPeer->onRequestChildNodes( pEntry->mxNode );
1566 // --------------------------------------------------------------------
1568 sal_Bool UnoTreeListBoxImpl::EditingEntry( SvTreeListEntry* pEntry, Selection& )
1570 return mxPeer.is() ? mxPeer->onEditingEntry( dynamic_cast< UnoTreeListEntry* >( pEntry ) ) : false;
1573 // --------------------------------------------------------------------
1575 sal_Bool UnoTreeListBoxImpl::EditedEntry( SvTreeListEntry* pEntry, const OUString& rNewText )
1577 return mxPeer.is() ? mxPeer->onEditedEntry( dynamic_cast< UnoTreeListEntry* >( pEntry ), rNewText ) : false;
1580 // ====================================================================
1581 // class UnoTreeListItem
1582 // ====================================================================
1584 UnoTreeListItem::UnoTreeListItem( SvTreeListEntry* pEntry )
1585 : SvLBoxString(pEntry, 0, OUString())
1589 // --------------------------------------------------------------------
1591 UnoTreeListItem::UnoTreeListItem()
1592 : SvLBoxString()
1596 // --------------------------------------------------------------------
1598 UnoTreeListItem::~UnoTreeListItem()
1602 // --------------------------------------------------------------------
1604 void UnoTreeListItem::Paint(
1605 const Point& rPos, SvTreeListBox& rDev, const SvViewDataEntry* /*pView*/, const SvTreeListEntry* pEntry)
1607 Point aPos( rPos );
1608 if (pEntry)
1610 Size aSize( GetSize(&rDev, pEntry) );
1611 if( !!maImage )
1613 rDev.DrawImage( aPos, maImage, rDev.IsEnabled() ? 0 : IMAGE_DRAW_DISABLE );
1614 int nWidth = maImage.GetSizePixel().Width() + 6;
1615 aPos.X() += nWidth;
1616 aSize.Width() -= nWidth;
1618 rDev.DrawText( Rectangle(aPos,aSize),maText, rDev.IsEnabled() ? 0 : TEXT_DRAW_DISABLE );
1620 else
1622 if( !!maImage )
1624 rDev.DrawImage( aPos, maImage, rDev.IsEnabled() ? 0 : IMAGE_DRAW_DISABLE);
1625 aPos.X() += maImage.GetSizePixel().Width() + 6;
1627 rDev.DrawText( aPos, maText);
1631 // --------------------------------------------------------------------
1633 SvLBoxItem* UnoTreeListItem::Create() const
1635 return new UnoTreeListItem;
1638 // --------------------------------------------------------------------
1640 void UnoTreeListItem::Clone( SvLBoxItem* pSource )
1642 UnoTreeListItem* pSourceItem = dynamic_cast< UnoTreeListItem* >( pSource );
1643 if( pSourceItem )
1645 maText = pSourceItem->maText;
1646 maImage = pSourceItem->maImage;
1650 // --------------------------------------------------------------------
1652 void UnoTreeListItem::SetImage( const Image& rImage )
1654 maImage = rImage;
1657 // --------------------------------------------------------------------
1659 OUString UnoTreeListItem::GetGraphicURL() const
1661 return maGraphicURL;
1664 // --------------------------------------------------------------------
1666 void UnoTreeListItem::SetGraphicURL( const OUString& rGraphicURL )
1668 maGraphicURL = rGraphicURL;
1671 // --------------------------------------------------------------------
1673 void UnoTreeListItem::InitViewData( SvTreeListBox* pView,SvTreeListEntry* pEntry, SvViewDataItem* pViewData)
1675 if( !pViewData )
1676 pViewData = pView->GetViewDataItem( pEntry, this );
1678 pViewData->maSize = maImage.GetSizePixel();
1680 const Size aTextSize(pView->GetTextWidth( maText ), pView->GetTextHeight());
1681 if( pViewData->maSize.Width() )
1683 pViewData->maSize.Width() += 6 + aTextSize.Width();
1684 if( pViewData->maSize.Height() < aTextSize.Height() )
1685 pViewData->maSize.Height() = aTextSize.Height();
1687 else
1689 pViewData->maSize = aTextSize;
1693 // --------------------------------------------------------------------
1695 UnoTreeListEntry::UnoTreeListEntry( const Reference< XTreeNode >& xNode, TreeControlPeer* pPeer )
1696 : SvTreeListEntry()
1697 , mxNode( xNode )
1698 , mpPeer( pPeer )
1700 if( mpPeer )
1701 mpPeer->addEntry( this );
1704 // --------------------------------------------------------------------
1706 UnoTreeListEntry::~UnoTreeListEntry()
1708 if( mpPeer )
1709 mpPeer->removeEntry( this );
1712 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */