1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: treecontrolpeer.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_svtools.hxx"
35 #include <tools/debug.hxx>
36 #include <com/sun/star/lang/XServiceInfo.hpp>
37 #include <com/sun/star/lang/DisposedException.hpp>
38 #include <com/sun/star/view/SelectionType.hpp>
39 #include <toolkit/helper/property.hxx>
41 #include <com/sun/star/awt/tree/XMutableTreeNode.hpp>
42 #include <treecontrolpeer.hxx>
43 #include <comphelper/processfactory.hxx>
45 #include <rtl/ref.hxx>
46 #include <vcl/graph.hxx>
47 #include <svtools/svtreebx.hxx>
51 using ::rtl::OUString
;
52 using namespace ::com::sun::star
;
53 using namespace ::com::sun::star::uno
;
54 using namespace ::com::sun::star::lang
;
55 using namespace ::com::sun::star::awt::tree
;
56 using namespace ::com::sun::star::beans
;
57 using namespace ::com::sun::star::view
;
58 using namespace ::com::sun::star::container
;
59 using namespace ::com::sun::star::util
;
60 using namespace ::com::sun::star::graphic
;
62 #define O(x) OUString( RTL_CONSTASCII_USTRINGPARAM(x) )
67 LockGuard( sal_Int32
& rLock
)
81 // --------------------------------------------------------------------
83 class ImplGraphicItem
: public SvLBoxBmp
86 ImplGraphicItem( SvLBoxEntry
* pEntry
, USHORT nFlags
, Image
& aImage
) : SvLBoxBmp( pEntry
, nFlags
, aImage
) {}
88 OUString msGraphicURL
;
91 // --------------------------------------------------------------------
93 class ImplContextGraphicItem
: public SvLBoxContextBmp
96 ImplContextGraphicItem( SvLBoxEntry
* pEntry
,USHORT nFlags
,Image
& rI1
,Image
& rI2
, USHORT nEntryFlagsBmp1
)
97 : SvLBoxContextBmp( pEntry
, nFlags
, rI1
, rI2
, nEntryFlagsBmp1
) {}
99 OUString msExpandedGraphicURL
;
100 OUString msCollapsedGraphicURL
;
103 // --------------------------------------------------------------------
105 class UnoTreeListBoxImpl
: public SvTreeListBox
108 UnoTreeListBoxImpl( TreeControlPeer
* pPeer
, Window
* pParent
, WinBits nWinStyle
);
109 ~UnoTreeListBoxImpl();
111 sal_uInt32
insert( SvLBoxEntry
* pEntry
,SvLBoxEntry
* pParent
,ULONG nPos
=LIST_APPEND
);
113 virtual void RequestingChilds( SvLBoxEntry
* pParent
);
115 virtual BOOL
EditingEntry( SvLBoxEntry
* pEntry
, Selection
& );
116 virtual BOOL
EditedEntry( SvLBoxEntry
* pEntry
, const XubString
& rNewText
);
118 DECL_LINK( OnSelectionChangeHdl
, UnoTreeListBoxImpl
* );
119 DECL_LINK( OnExpandingHdl
, UnoTreeListBoxImpl
* );
120 DECL_LINK( OnExpandedHdl
, UnoTreeListBoxImpl
* );
123 rtl::Reference
< TreeControlPeer
> mxPeer
;
126 // --------------------------------------------------------------------
128 class SVT_DLLPUBLIC UnoTreeListItem
: public SvLBoxItem
131 UnoTreeListItem( SvLBoxEntry
* );
133 virtual ~UnoTreeListItem();
134 virtual USHORT
IsA();
135 void InitViewData( SvLBox
*,SvLBoxEntry
*,SvViewDataItem
* );
136 OUString
GetText() const;
137 void SetText( const OUString
& rText
);
138 Image
GetImage() const;
139 void SetImage( const Image
& rImage
);
140 OUString
GetGraphicURL() const;
141 void SetGraphicURL( const OUString
& rGraphicURL
);
142 void Paint( const Point
&, SvLBox
& rDev
, USHORT nFlags
,SvLBoxEntry
* );
143 SvLBoxItem
* Create() const;
144 void Clone( SvLBoxItem
* pSource
);
148 OUString maGraphicURL
;
152 // --------------------------------------------------------------------
154 class UnoTreeListEntry
: public SvLBoxEntry
157 UnoTreeListEntry( const Reference
< XTreeNode
>& xNode
, TreeControlPeer
* pPeer
);
158 virtual ~UnoTreeListEntry();
160 Reference
< XTreeNode
> mxNode
;
161 TreeControlPeer
* mpPeer
;
164 // --------------------------------------------------------------------
166 class TreeNodeMap
: public std::map
< Reference
< XTreeNode
>, UnoTreeListEntry
* >
170 // --------------------------------------------------------------------
172 TreeControlPeer::TreeControlPeer()
173 : maSelectionListeners( *this )
174 , maTreeExpansionListeners( *this )
175 , maTreeEditListeners( *this )
182 // --------------------------------------------------------------------
184 TreeControlPeer::~TreeControlPeer()
188 delete mpTreeNodeMap
;
191 // --------------------------------------------------------------------
193 void TreeControlPeer::addEntry( UnoTreeListEntry
* pEntry
)
195 if( pEntry
&& pEntry
->mxNode
.is() )
199 mpTreeNodeMap
= new TreeNodeMap();
202 (*mpTreeNodeMap
)[ pEntry
->mxNode
] = pEntry
;
206 // --------------------------------------------------------------------
208 void TreeControlPeer::removeEntry( UnoTreeListEntry
* pEntry
)
210 if( mpTreeNodeMap
&& pEntry
&& pEntry
->mxNode
.is() )
212 TreeNodeMap::iterator
aIter( mpTreeNodeMap
->find( pEntry
->mxNode
) );
213 if( aIter
!= mpTreeNodeMap
->end() )
214 mpTreeNodeMap
->erase( aIter
);
218 // --------------------------------------------------------------------
220 UnoTreeListEntry
* TreeControlPeer::getEntry( const Reference
< XTreeNode
>& xNode
, bool bThrow
/* = true */ ) throw( IllegalArgumentException
)
224 TreeNodeMap::iterator
aIter( mpTreeNodeMap
->find( xNode
) );
225 if( aIter
!= mpTreeNodeMap
->end() )
226 return (*aIter
).second
;
230 throw IllegalArgumentException();
235 // --------------------------------------------------------------------
237 Window
* TreeControlPeer::createVclControl( Window
* pParent
, sal_Int64 nWinStyle
)
239 mpTreeImpl
= new UnoTreeListBoxImpl( this, pParent
, nWinStyle
);
243 // --------------------------------------------------------------------
245 /** called from the UnoTreeListBoxImpl when it gets deleted */
246 void TreeControlPeer::disposeControl()
248 delete mpTreeNodeMap
;
253 // --------------------------------------------------------------------
255 void TreeControlPeer::SetWindow( Window
* pWindow
)
257 VCLXWindow::SetWindow( pWindow
);
260 // --------------------------------------------------------------------
262 UnoTreeListEntry
* TreeControlPeer::createEntry( const Reference
< XTreeNode
>& xNode
, UnoTreeListEntry
* pParent
, ULONG nPos
/* = LIST_APPEND */ )
264 UnoTreeListEntry
* pEntry
= 0;
268 pEntry
= new UnoTreeListEntry( xNode
, this );
269 ImplContextGraphicItem
* pContextBmp
= new ImplContextGraphicItem( pEntry
,0, aImage
, aImage
, SVLISTENTRYFLAG_EXPANDED
);
271 pEntry
->AddItem( pContextBmp
);
273 UnoTreeListItem
* pUnoItem
= new UnoTreeListItem( pEntry
);
275 if( xNode
->getNodeGraphicURL().getLength() )
277 pUnoItem
->SetGraphicURL( xNode
->getNodeGraphicURL() );
279 loadImage( xNode
->getNodeGraphicURL(), aNodeImage
);
280 pUnoItem
->SetImage( aNodeImage
);
281 mpTreeImpl
->AdjustEntryHeight( aNodeImage
);
284 pEntry
->AddItem( pUnoItem
);
286 if( msDefaultExpandedGraphicURL
.getLength() )
287 mpTreeImpl
->SetExpandedEntryBmp( pEntry
, maDefaultExpandedImage
);
289 if( msDefaultCollapsedGraphicURL
.getLength() )
290 mpTreeImpl
->SetCollapsedEntryBmp( pEntry
, maDefaultCollapsedImage
);
292 mpTreeImpl
->insert( pEntry
, pParent
, nPos
);
294 updateEntry( pEntry
);
299 // --------------------------------------------------------------------
301 bool TreeControlPeer::updateEntry( UnoTreeListEntry
* pEntry
)
303 bool bChanged
= false;
304 if( pEntry
&& pEntry
->mxNode
.is() && mpTreeImpl
)
306 const OUString
aValue( getEntryString( pEntry
->mxNode
->getDisplayValue() ) );
307 UnoTreeListItem
* pUnoItem
= dynamic_cast< UnoTreeListItem
* >( pEntry
->GetItem( 1 ) );
310 if( aValue
!= pUnoItem
->GetText() )
312 pUnoItem
->SetText( aValue
);
316 if( pUnoItem
->GetGraphicURL() != pEntry
->mxNode
->getNodeGraphicURL() )
319 if( loadImage( pEntry
->mxNode
->getNodeGraphicURL(), aImage
) )
321 pUnoItem
->SetGraphicURL( pEntry
->mxNode
->getNodeGraphicURL() );
322 pUnoItem
->SetImage( aImage
);
323 mpTreeImpl
->AdjustEntryHeight( aImage
);
329 if( (pEntry
->mxNode
->hasChildrenOnDemand() == sal_True
) != (pEntry
->HasChildsOnDemand() == TRUE
) )
331 pEntry
->EnableChildsOnDemand( pEntry
->mxNode
->hasChildrenOnDemand() ? TRUE
: FALSE
);
335 ImplContextGraphicItem
* pContextGraphicItem
= dynamic_cast< ImplContextGraphicItem
* >( pEntry
->GetItem( 0 ) );
336 if( pContextGraphicItem
)
338 if( pContextGraphicItem
->msExpandedGraphicURL
!= pEntry
->mxNode
->getExpandedGraphicURL() )
341 if( loadImage( pEntry
->mxNode
->getExpandedGraphicURL(), aImage
) )
343 pContextGraphicItem
->msExpandedGraphicURL
= pEntry
->mxNode
->getExpandedGraphicURL();
344 mpTreeImpl
->SetExpandedEntryBmp( pEntry
, aImage
);
348 if( pContextGraphicItem
->msCollapsedGraphicURL
!= pEntry
->mxNode
->getCollapsedGraphicURL() )
351 if( loadImage( pEntry
->mxNode
->getCollapsedGraphicURL(), aImage
) )
353 pContextGraphicItem
->msCollapsedGraphicURL
= pEntry
->mxNode
->getCollapsedGraphicURL();
354 mpTreeImpl
->SetCollapsedEntryBmp( pEntry
, aImage
);
361 mpTreeImpl
->GetModel()->InvalidateEntry( pEntry
);
367 // --------------------------------------------------------------------
369 void TreeControlPeer::onSelectionChanged()
371 Reference
< XInterface
> xSource( static_cast< ::cppu::OWeakObject
* >( this ) );
372 EventObject
aEvent( xSource
);
373 maSelectionListeners
.selectionChanged( aEvent
);
376 // --------------------------------------------------------------------
378 void TreeControlPeer::onRequestChildNodes( const Reference
< XTreeNode
>& xNode
)
382 Reference
< XInterface
> xSource( static_cast< ::cppu::OWeakObject
* >( this ) );
383 TreeExpansionEvent
aEvent( xSource
, xNode
);
384 maTreeExpansionListeners
.requestChildNodes( aEvent
);
391 // --------------------------------------------------------------------
393 bool TreeControlPeer::onExpanding( const Reference
< XTreeNode
>& xNode
, bool bExpanding
)
397 Reference
< XInterface
> xSource( static_cast< ::cppu::OWeakObject
* >( this ) );
398 TreeExpansionEvent
aEvent( xSource
, xNode
);
401 maTreeExpansionListeners
.treeExpanding( aEvent
);
405 maTreeExpansionListeners
.treeCollapsing( aEvent
);
415 // --------------------------------------------------------------------
417 void TreeControlPeer::onExpanded( const Reference
< XTreeNode
>& xNode
, bool bExpanding
)
421 Reference
< XInterface
> xSource( static_cast< ::cppu::OWeakObject
* >( this ) );
422 TreeExpansionEvent
aEvent( xSource
, xNode
);
426 maTreeExpansionListeners
.treeExpanded( aEvent
);
430 maTreeExpansionListeners
.treeCollapsed( aEvent
);
438 // --------------------------------------------------------------------
440 void TreeControlPeer::fillTree( UnoTreeListBoxImpl
& rTree
, const Reference
< XTreeDataModel
>& xDataModel
)
444 if( xDataModel
.is() )
446 Reference
< XTreeNode
> xRootNode( xDataModel
->getRoot() );
449 if( mbIsRootDisplayed
)
451 addNode( rTree
, xRootNode
, 0 );
455 const sal_Int32 nChildCount
= xRootNode
->getChildCount();
456 for( sal_Int32 nChild
= 0; nChild
< nChildCount
; nChild
++ )
457 addNode( rTree
, xRootNode
->getChildAt( nChild
), 0 );
463 // --------------------------------------------------------------------
465 void TreeControlPeer::addNode( UnoTreeListBoxImpl
& rTree
, const Reference
< XTreeNode
>& xNode
, UnoTreeListEntry
* pParentEntry
)
469 UnoTreeListEntry
* pEntry
= createEntry( xNode
, pParentEntry
, LIST_APPEND
);
470 const sal_Int32 nChildCount
= xNode
->getChildCount();
471 for( sal_Int32 nChild
= 0; nChild
< nChildCount
; nChild
++ )
472 addNode( rTree
, xNode
->getChildAt( nChild
), pEntry
);
476 // --------------------------------------------------------------------
478 UnoTreeListBoxImpl
& TreeControlPeer::getTreeListBoxOrThrow() const throw (RuntimeException
)
481 throw DisposedException();
485 // --------------------------------------------------------------------
487 void TreeControlPeer::ChangeNodesSelection( const Any
& rSelection
, bool bSelect
, bool bSetSelection
) throw( RuntimeException
, IllegalArgumentException
)
489 ::vos::OGuard
aGuard( GetMutex() );
491 UnoTreeListBoxImpl
& rTree
= getTreeListBoxOrThrow();
493 Reference
< XTreeNode
> xTempNode
;
494 Sequence
< XTreeNode
> aTempSeq
;
496 const Reference
< XTreeNode
> *pNodes
= 0;
497 sal_Int32 nCount
= 0;
499 if( rSelection
.hasValue() )
501 switch( rSelection
.getValueTypeClass() )
503 case TypeClass_INTERFACE
:
505 rSelection
>>= xTempNode
;
513 case TypeClass_SEQUENCE
:
515 if( rSelection
.getValueType() == ::getCppuType( (const Sequence
< Reference
< XTreeNode
> > *) 0 ) )
517 const Sequence
< Reference
< XTreeNode
> >& rSeq( *(const Sequence
< Reference
< XTreeNode
> > *)rSelection
.getValue() );
518 nCount
= rSeq
.getLength();
520 pNodes
= rSeq
.getConstArray();
529 throw IllegalArgumentException();
533 rTree
.SelectAll( FALSE
);
535 if( pNodes
&& nCount
)
539 UnoTreeListEntry
* pEntry
= getEntry( *pNodes
++ );
540 rTree
.Select( pEntry
, bSelect
? TRUE
: FALSE
);
545 // -------------------------------------------------------------------
546 // ::com::sun::star::view::XSelectionSupplier
547 // -------------------------------------------------------------------
549 sal_Bool SAL_CALL
TreeControlPeer::select( const Any
& rSelection
) throw (IllegalArgumentException
, RuntimeException
)
551 ::vos::OGuard
aGuard( GetMutex() );
552 ChangeNodesSelection( rSelection
, true, true );
556 // -------------------------------------------------------------------
558 Any SAL_CALL
TreeControlPeer::getSelection() throw (RuntimeException
)
560 ::vos::OGuard
aGuard( GetMutex() );
562 UnoTreeListBoxImpl
& rTree
= getTreeListBoxOrThrow();
566 ULONG nSelectionCount
= rTree
.GetSelectionCount();
567 if( nSelectionCount
== 1 )
569 UnoTreeListEntry
* pEntry
= dynamic_cast< UnoTreeListEntry
* >( rTree
.FirstSelected() );
570 if( pEntry
&& pEntry
->mxNode
.is() )
571 aRet
<<= pEntry
->mxNode
;
573 else if( nSelectionCount
> 1 )
575 Sequence
< Reference
< XTreeNode
> > aSelection( nSelectionCount
);
576 Reference
< XTreeNode
>* pNodes
= aSelection
.getArray();
577 UnoTreeListEntry
* pEntry
= dynamic_cast< UnoTreeListEntry
* >( rTree
.FirstSelected() );
578 while( pEntry
&& nSelectionCount
)
580 *pNodes
++ = pEntry
->mxNode
;
581 pEntry
= dynamic_cast< UnoTreeListEntry
* >( rTree
.NextSelected( pEntry
) );
585 OSL_ASSERT( (pEntry
== 0) && (nSelectionCount
== 0) );
592 // -------------------------------------------------------------------
594 void SAL_CALL
TreeControlPeer::addSelectionChangeListener( const Reference
< XSelectionChangeListener
>& xListener
) throw (RuntimeException
)
596 maSelectionListeners
.addInterface( xListener
);
599 // -------------------------------------------------------------------
601 void SAL_CALL
TreeControlPeer::removeSelectionChangeListener( const Reference
< XSelectionChangeListener
>& xListener
) throw (RuntimeException
)
603 maSelectionListeners
.addInterface( xListener
);
606 // -------------------------------------------------------------------
607 // ::com::sun::star::view::XMultiSelectionSupplier
608 // -------------------------------------------------------------------
610 sal_Bool SAL_CALL
TreeControlPeer::addSelection( const Any
& rSelection
) throw (IllegalArgumentException
, RuntimeException
)
612 ChangeNodesSelection( rSelection
, true, false );
616 // -------------------------------------------------------------------
618 void SAL_CALL
TreeControlPeer::removeSelection( const Any
& rSelection
) throw (IllegalArgumentException
, RuntimeException
)
620 ChangeNodesSelection( rSelection
, false, false );
623 // -------------------------------------------------------------------
625 void SAL_CALL
TreeControlPeer::clearSelection() throw (RuntimeException
)
627 ::vos::OGuard
aGuard( GetMutex() );
628 getTreeListBoxOrThrow().SelectAll( FALSE
);
631 // -------------------------------------------------------------------
633 sal_Int32 SAL_CALL
TreeControlPeer::getSelectionCount() throw (RuntimeException
)
635 ::vos::OGuard
aGuard( GetMutex() );
636 return getTreeListBoxOrThrow().GetSelectionCount();
639 // -------------------------------------------------------------------
641 class TreeSelectionEnumeration
: public ::cppu::WeakImplHelper1
< XEnumeration
>
644 TreeSelectionEnumeration( std::list
< Any
>& rSelection
);
645 virtual ::sal_Bool SAL_CALL
hasMoreElements() throw (RuntimeException
);
646 virtual Any SAL_CALL
nextElement() throw (NoSuchElementException
, WrappedTargetException
, RuntimeException
);
648 std::list
< Any
> maSelection
;
649 std::list
< Any
>::iterator maIter
;
652 // -------------------------------------------------------------------
654 TreeSelectionEnumeration::TreeSelectionEnumeration( std::list
< Any
>& rSelection
)
656 maSelection
.swap( rSelection
);
657 maIter
= maSelection
.begin();
660 // -------------------------------------------------------------------
662 ::sal_Bool SAL_CALL
TreeSelectionEnumeration::hasMoreElements() throw (RuntimeException
)
664 return maIter
!= maSelection
.end();
667 // -------------------------------------------------------------------
669 Any SAL_CALL
TreeSelectionEnumeration::nextElement() throw (NoSuchElementException
, WrappedTargetException
, RuntimeException
)
671 if( maIter
== maSelection
.end() )
672 throw NoSuchElementException();
677 // -------------------------------------------------------------------
679 Reference
< XEnumeration
> SAL_CALL
TreeControlPeer::createSelectionEnumeration() throw (RuntimeException
)
681 ::vos::OGuard
aGuard( GetMutex() );
683 UnoTreeListBoxImpl
& rTree
= getTreeListBoxOrThrow();
685 sal_uInt32 nSelectionCount
= rTree
.GetSelectionCount();
686 std::list
< Any
> aSelection( nSelectionCount
);
688 UnoTreeListEntry
* pEntry
= dynamic_cast< UnoTreeListEntry
* >( rTree
.FirstSelected() );
689 while( pEntry
&& nSelectionCount
)
691 aSelection
.push_back( Any( pEntry
->mxNode
) );
692 pEntry
= dynamic_cast< UnoTreeListEntry
* >( rTree
.NextSelected( pEntry
) );
696 OSL_ASSERT( (pEntry
== 0) && (nSelectionCount
== 0) );
698 return Reference
< XEnumeration
>( new TreeSelectionEnumeration( aSelection
) );
701 // -------------------------------------------------------------------
703 Reference
< XEnumeration
> SAL_CALL
TreeControlPeer::createReverseSelectionEnumeration() throw (RuntimeException
)
705 ::vos::OGuard
aGuard( GetMutex() );
707 UnoTreeListBoxImpl
& rTree
= getTreeListBoxOrThrow();
709 sal_uInt32 nSelectionCount
= rTree
.GetSelectionCount();
710 std::list
< Any
> aSelection
;
712 UnoTreeListEntry
* pEntry
= dynamic_cast< UnoTreeListEntry
* >( rTree
.FirstSelected() );
713 while( pEntry
&& nSelectionCount
)
715 aSelection
.push_front( Any( pEntry
->mxNode
) );
716 pEntry
= dynamic_cast< UnoTreeListEntry
* >( rTree
.NextSelected( pEntry
) );
720 OSL_ASSERT( (pEntry
== 0) && (nSelectionCount
== 0) );
722 return Reference
< XEnumeration
>( new TreeSelectionEnumeration( aSelection
) );
725 // --------------------------------------------------------------------
726 // ::com::sun::star::awt::XTreeControl
727 // --------------------------------------------------------------------
729 OUString SAL_CALL
TreeControlPeer::getDefaultExpandedGraphicURL() throw (::com::sun::star::uno::RuntimeException
)
731 ::vos::OGuard
aGuard( GetMutex() );
732 return msDefaultExpandedGraphicURL
;
735 // --------------------------------------------------------------------
737 void SAL_CALL
TreeControlPeer::setDefaultExpandedGraphicURL( const ::rtl::OUString
& sDefaultExpandedGraphicURL
) throw (::com::sun::star::uno::RuntimeException
)
739 ::vos::OGuard
aGuard( GetMutex() );
740 if( msDefaultExpandedGraphicURL
!= sDefaultExpandedGraphicURL
)
742 if( sDefaultExpandedGraphicURL
.getLength() )
743 loadImage( sDefaultExpandedGraphicURL
, maDefaultExpandedImage
);
745 maDefaultExpandedImage
= Image();
747 UnoTreeListBoxImpl
& rTree
= getTreeListBoxOrThrow();
749 SvLBoxEntry
* pEntry
= rTree
.First();
752 ImplContextGraphicItem
* pContextGraphicItem
= dynamic_cast< ImplContextGraphicItem
* >( pEntry
->GetItem( 0 ) );
753 if( pContextGraphicItem
)
755 if( pContextGraphicItem
->msExpandedGraphicURL
.getLength() == 0 )
756 rTree
.SetExpandedEntryBmp( pEntry
, maDefaultExpandedImage
);
758 pEntry
= rTree
.Next( pEntry
);
761 msDefaultExpandedGraphicURL
= sDefaultExpandedGraphicURL
;
765 // --------------------------------------------------------------------
767 OUString SAL_CALL
TreeControlPeer::getDefaultCollapsedGraphicURL() throw (::com::sun::star::uno::RuntimeException
)
769 ::vos::OGuard
aGuard( GetMutex() );
770 return msDefaultCollapsedGraphicURL
;
773 // --------------------------------------------------------------------
775 void SAL_CALL
TreeControlPeer::setDefaultCollapsedGraphicURL( const ::rtl::OUString
& sDefaultCollapsedGraphicURL
) throw (::com::sun::star::uno::RuntimeException
)
777 ::vos::OGuard
aGuard( GetMutex() );
778 if( msDefaultCollapsedGraphicURL
!= sDefaultCollapsedGraphicURL
)
780 if( sDefaultCollapsedGraphicURL
.getLength() )
781 loadImage( sDefaultCollapsedGraphicURL
, maDefaultCollapsedImage
);
783 maDefaultCollapsedImage
= Image();
785 UnoTreeListBoxImpl
& rTree
= getTreeListBoxOrThrow();
787 SvLBoxEntry
* pEntry
= rTree
.First();
790 ImplContextGraphicItem
* pContextGraphicItem
= dynamic_cast< ImplContextGraphicItem
* >( pEntry
->GetItem( 0 ) );
791 if( pContextGraphicItem
)
793 if( pContextGraphicItem
->msCollapsedGraphicURL
.getLength() == 0 )
794 rTree
.SetCollapsedEntryBmp( pEntry
, maDefaultCollapsedImage
);
796 pEntry
= rTree
.Next( pEntry
);
799 msDefaultCollapsedGraphicURL
= sDefaultCollapsedGraphicURL
;
803 // --------------------------------------------------------------------
805 sal_Bool SAL_CALL
TreeControlPeer::isNodeExpanded( const Reference
< XTreeNode
>& xNode
) throw (RuntimeException
, IllegalArgumentException
)
807 ::vos::OGuard
aGuard( GetMutex() );
809 UnoTreeListBoxImpl
& rTree
= getTreeListBoxOrThrow();
810 UnoTreeListEntry
* pEntry
= getEntry( xNode
);
811 return ( pEntry
&& rTree
.IsExpanded( pEntry
) ) ? sal_True
: sal_False
;
814 // -------------------------------------------------------------------
816 sal_Bool SAL_CALL
TreeControlPeer::isNodeCollapsed( const Reference
< XTreeNode
>& xNode
) throw (RuntimeException
, IllegalArgumentException
)
818 ::vos::OGuard
aGuard( GetMutex() );
819 return !isNodeExpanded( xNode
);
822 // -------------------------------------------------------------------
824 void SAL_CALL
TreeControlPeer::makeNodeVisible( const Reference
< XTreeNode
>& xNode
) throw (RuntimeException
, ExpandVetoException
, IllegalArgumentException
)
826 ::vos::OGuard
aGuard( GetMutex() );
828 UnoTreeListBoxImpl
& rTree
= getTreeListBoxOrThrow();
829 UnoTreeListEntry
* pEntry
= getEntry( xNode
);
831 rTree
.MakeVisible( pEntry
);
834 // -------------------------------------------------------------------
836 sal_Bool SAL_CALL
TreeControlPeer::isNodeVisible( const Reference
< XTreeNode
>& xNode
) throw (RuntimeException
, IllegalArgumentException
)
838 ::vos::OGuard
aGuard( GetMutex() );
840 UnoTreeListBoxImpl
& rTree
= getTreeListBoxOrThrow();
841 UnoTreeListEntry
* pEntry
= getEntry( xNode
);
842 return ( pEntry
&& rTree
.IsEntryVisible( pEntry
) ) ? sal_True
: sal_False
;
845 // -------------------------------------------------------------------
847 void SAL_CALL
TreeControlPeer::expandNode( const Reference
< XTreeNode
>& xNode
) throw (RuntimeException
, ExpandVetoException
, IllegalArgumentException
)
849 ::vos::OGuard
aGuard( GetMutex() );
851 UnoTreeListBoxImpl
& rTree
= getTreeListBoxOrThrow();
852 UnoTreeListEntry
* pEntry
= getEntry( xNode
);
854 rTree
.Expand( pEntry
);
857 // -------------------------------------------------------------------
859 void SAL_CALL
TreeControlPeer::collapseNode( const Reference
< XTreeNode
>& xNode
) throw (RuntimeException
, ExpandVetoException
, IllegalArgumentException
)
861 ::vos::OGuard
aGuard( GetMutex() );
863 UnoTreeListBoxImpl
& rTree
= getTreeListBoxOrThrow();
864 UnoTreeListEntry
* pEntry
= getEntry( xNode
);
866 rTree
.Collapse( pEntry
);
869 // -------------------------------------------------------------------
871 void SAL_CALL
TreeControlPeer::addTreeExpansionListener( const Reference
< XTreeExpansionListener
>& xListener
) throw (RuntimeException
)
873 maTreeExpansionListeners
.addInterface( xListener
);
876 // -------------------------------------------------------------------
878 void SAL_CALL
TreeControlPeer::removeTreeExpansionListener( const Reference
< XTreeExpansionListener
>& xListener
) throw (RuntimeException
)
880 maTreeExpansionListeners
.removeInterface( xListener
);
883 // -------------------------------------------------------------------
885 Reference
< XTreeNode
> SAL_CALL
TreeControlPeer::getNodeForLocation( sal_Int32 x
, sal_Int32 y
) throw (RuntimeException
)
887 ::vos::OGuard
aGuard( GetMutex() );
889 UnoTreeListBoxImpl
& rTree
= getTreeListBoxOrThrow();
891 Reference
< XTreeNode
> xNode
;
893 const Point
aPos( x
, y
);
894 UnoTreeListEntry
* pEntry
= dynamic_cast< UnoTreeListEntry
* >( rTree
.GetEntry( aPos
, TRUE
) );
896 xNode
= pEntry
->mxNode
;
901 // -------------------------------------------------------------------
903 Reference
< XTreeNode
> SAL_CALL
TreeControlPeer::getClosestNodeForLocation( sal_Int32 x
, sal_Int32 y
) throw (RuntimeException
)
905 ::vos::OGuard
aGuard( GetMutex() );
907 UnoTreeListBoxImpl
& rTree
= getTreeListBoxOrThrow();
909 Reference
< XTreeNode
> xNode
;
911 const Point
aPos( x
, y
);
912 UnoTreeListEntry
* pEntry
= dynamic_cast< UnoTreeListEntry
* >( rTree
.GetEntry( aPos
, TRUE
) );
914 xNode
= pEntry
->mxNode
;
919 // -------------------------------------------------------------------
921 sal_Bool SAL_CALL
TreeControlPeer::isEditing( ) throw (RuntimeException
)
923 ::vos::OGuard
aGuard( GetMutex() );
925 UnoTreeListBoxImpl
& rTree
= getTreeListBoxOrThrow();
926 return rTree
.IsEditingActive() ? sal_True
: sal_False
;
929 // -------------------------------------------------------------------
931 sal_Bool SAL_CALL
TreeControlPeer::stopEditing() throw (RuntimeException
)
933 ::vos::OGuard
aGuard( GetMutex() );
935 UnoTreeListBoxImpl
& rTree
= getTreeListBoxOrThrow();
936 if( rTree
.IsEditingActive() )
938 rTree
.EndEditing(FALSE
);
947 // -------------------------------------------------------------------
949 void SAL_CALL
TreeControlPeer::cancelEditing( ) throw (RuntimeException
)
951 ::vos::OGuard
aGuard( GetMutex() );
953 UnoTreeListBoxImpl
& rTree
= getTreeListBoxOrThrow();
954 rTree
.EndEditing(FALSE
);
957 // -------------------------------------------------------------------
959 void SAL_CALL
TreeControlPeer::startEditingAtNode( const Reference
< XTreeNode
>& xNode
) throw (IllegalArgumentException
, RuntimeException
)
961 ::vos::OGuard
aGuard( GetMutex() );
963 UnoTreeListBoxImpl
& rTree
= getTreeListBoxOrThrow();
964 UnoTreeListEntry
* pEntry
= getEntry( xNode
);
965 rTree
.EditEntry( pEntry
);
968 void SAL_CALL
TreeControlPeer::addTreeEditListener( const Reference
< XTreeEditListener
>& xListener
) throw (RuntimeException
)
970 maTreeEditListeners
.addInterface( xListener
);
973 void SAL_CALL
TreeControlPeer::removeTreeEditListener( const Reference
< XTreeEditListener
>& xListener
) throw (RuntimeException
)
975 maTreeEditListeners
.removeInterface( xListener
);
978 bool TreeControlPeer::onEditingEntry( UnoTreeListEntry
* pEntry
)
980 if( mpTreeImpl
&& pEntry
&& pEntry
->mxNode
.is() && (maTreeEditListeners
.getLength() > 0) )
984 maTreeEditListeners
.nodeEditing( pEntry
->mxNode
);
986 catch( VetoException
& )
997 bool TreeControlPeer::onEditedEntry( UnoTreeListEntry
* pEntry
, const XubString
& rNewText
)
999 if( mpTreeImpl
&& pEntry
&& pEntry
->mxNode
.is() ) try
1001 LockGuard
aLockGuard( mnEditLock
);
1002 const OUString
aNewText( rNewText
);
1003 if( maTreeEditListeners
.getLength() > 0 )
1005 maTreeEditListeners
.nodeEdited( pEntry
->mxNode
, aNewText
);
1010 Reference
< XMutableTreeNode
> xMutableNode( pEntry
->mxNode
, UNO_QUERY
);
1011 if( xMutableNode
.is() )
1012 xMutableNode
->setDisplayValue( Any( aNewText
) );
1025 // --------------------------------------------------------------------
1026 // ::com::sun::star::awt::tree::TreeDataModelListener
1027 // --------------------------------------------------------------------
1029 void SAL_CALL
TreeControlPeer::treeNodesChanged( const ::com::sun::star::awt::tree::TreeDataModelEvent
& rEvent
) throw (RuntimeException
)
1031 ::vos::OGuard
aGuard( GetMutex() );
1033 if( mnEditLock
!= 0 )
1036 updateTree( rEvent
, true );
1039 void SAL_CALL
TreeControlPeer::treeNodesInserted( const ::com::sun::star::awt::tree::TreeDataModelEvent
& rEvent
) throw (RuntimeException
)
1041 ::vos::OGuard
aGuard( GetMutex() );
1043 if( mnEditLock
!= 0 )
1046 updateTree( rEvent
, true );
1049 void SAL_CALL
TreeControlPeer::treeNodesRemoved( const ::com::sun::star::awt::tree::TreeDataModelEvent
& rEvent
) throw (RuntimeException
)
1051 ::vos::OGuard
aGuard( GetMutex() );
1053 if( mnEditLock
!= 0 )
1056 updateTree( rEvent
, true );
1059 void SAL_CALL
TreeControlPeer::treeStructureChanged( const ::com::sun::star::awt::tree::TreeDataModelEvent
& rEvent
) throw (RuntimeException
)
1061 ::vos::OGuard
aGuard( GetMutex() );
1063 if( mnEditLock
!= 0 )
1066 updateTree( rEvent
, true );
1069 void TreeControlPeer::updateTree( const ::com::sun::star::awt::tree::TreeDataModelEvent
& rEvent
, bool bRecursive
)
1071 UnoTreeListBoxImpl
& rTree
= getTreeListBoxOrThrow();
1073 Sequence
< Reference
< XTreeNode
> > Nodes
;
1074 Reference
< XTreeNode
> xNode( rEvent
.ParentNode
);
1075 if( !xNode
.is() && Nodes
.getLength() )
1081 updateNode( rTree
, xNode
, bRecursive
);
1084 void TreeControlPeer::updateNode( UnoTreeListBoxImpl
& rTree
, const Reference
< XTreeNode
>& xNode
, bool bRecursive
)
1088 UnoTreeListEntry
* pNodeEntry
= getEntry( xNode
, false );
1092 Reference
< XTreeNode
> xParentNode( xNode
->getParent() );
1093 UnoTreeListEntry
* pParentEntry
= 0;
1094 ULONG nChild
= LIST_APPEND
;
1096 if( xParentNode
.is() )
1098 pParentEntry
= getEntry( xParentNode
);
1099 nChild
= xParentNode
->getIndex( xNode
);
1102 pNodeEntry
= createEntry( xNode
, pParentEntry
, nChild
);
1106 updateChildNodes( rTree
, xNode
, pNodeEntry
);
1110 void TreeControlPeer::updateChildNodes( UnoTreeListBoxImpl
& rTree
, const Reference
< XTreeNode
>& xParentNode
, UnoTreeListEntry
* pParentEntry
)
1112 if( xParentNode
.is() && pParentEntry
)
1114 UnoTreeListEntry
* pCurrentChild
= dynamic_cast< UnoTreeListEntry
* >( rTree
.FirstChild( pParentEntry
) );
1116 const sal_Int32 nChildCount
= xParentNode
->getChildCount();
1117 for( sal_Int32 nChild
= 0; nChild
< nChildCount
; nChild
++ )
1119 Reference
< XTreeNode
> xNode( xParentNode
->getChildAt( nChild
) );
1120 if( !pCurrentChild
|| ( pCurrentChild
->mxNode
!= xNode
) )
1122 UnoTreeListEntry
* pNodeEntry
= getEntry( xNode
, false );
1123 if( pNodeEntry
== 0 )
1125 // child node is not yet part of the tree, add it
1126 pCurrentChild
= createEntry( xNode
, pParentEntry
, nChild
);
1128 else if( pNodeEntry
!= pCurrentChild
)
1130 // node is already part of the tree, but not on the correct position
1131 rTree
.GetModel()->Move( pNodeEntry
, pParentEntry
, nChild
);
1132 pCurrentChild
= pNodeEntry
;
1133 updateEntry( pCurrentChild
);
1138 // child node has entry and entry is equal to current entry,
1139 // so no structural changes happened
1140 updateEntry( pCurrentChild
);
1143 pCurrentChild
= dynamic_cast< UnoTreeListEntry
* >( rTree
.NextSibling( pCurrentChild
) );
1146 // check if we have entries without nodes left, we need to remove them
1147 while( pCurrentChild
)
1149 UnoTreeListEntry
* pNextChild
= dynamic_cast< UnoTreeListEntry
* >( rTree
.NextSibling( pCurrentChild
) );
1150 rTree
.GetModel()->Remove( pCurrentChild
);
1151 pCurrentChild
= pNextChild
;
1156 OUString
TreeControlPeer::getEntryString( const Any
& rValue
)
1159 if( rValue
.hasValue() )
1161 switch( rValue
.getValueTypeClass() )
1163 case TypeClass_SHORT
:
1164 case TypeClass_LONG
:
1166 sal_Int32 nValue
= 0;
1167 if( rValue
>>= nValue
)
1168 sValue
= OUString::valueOf( nValue
);
1171 case TypeClass_BYTE
:
1172 case TypeClass_UNSIGNED_SHORT
:
1173 case TypeClass_UNSIGNED_LONG
:
1175 sal_uInt32 nValue
= 0;
1176 if( rValue
>>= nValue
)
1177 sValue
= OUString::valueOf( (sal_Int64
)nValue
);
1180 case TypeClass_HYPER
:
1182 sal_Int64 nValue
= 0;
1183 if( rValue
>>= nValue
)
1184 sValue
= OUString::valueOf( nValue
);
1187 case TypeClass_UNSIGNED_HYPER
:
1189 sal_uInt64 nValue
= 0;
1190 if( rValue
>>= nValue
)
1191 sValue
= OUString::valueOf( (sal_Int64
)nValue
);
1194 case TypeClass_FLOAT
:
1195 case TypeClass_DOUBLE
:
1197 double fValue
= 0.0;
1198 if( rValue
>>= fValue
)
1199 sValue
= OUString::valueOf( fValue
);
1202 case TypeClass_STRING
:
1206 case TypeClass_INTERFACE:
1209 case TypeClass_SEQUENCE:
1211 Sequence< Any > aValues;
1212 if( aValue >>= aValues )
1214 updateEntry( SvLBoxEntry& rEntry, aValues );
1228 void SAL_CALL
TreeControlPeer::disposing( const ::com::sun::star::lang::EventObject
& ) throw(::com::sun::star::uno::RuntimeException
)
1230 // model is disposed, so we clear our tree
1231 ::vos::OGuard
aGuard( GetMutex() );
1232 UnoTreeListBoxImpl
& rTree
= getTreeListBoxOrThrow();
1234 mxDataModel
.clear();
1237 void TreeControlPeer::onChangeDataModel( UnoTreeListBoxImpl
& rTree
, const Reference
< XTreeDataModel
>& xDataModel
)
1239 if( xDataModel
.is() && (mxDataModel
== xDataModel
) )
1240 return; // do nothing
1242 Reference
< XTreeDataModelListener
> xListener( this );
1244 if( mxDataModel
.is() )
1245 mxDataModel
->removeTreeDataModelListener( xListener
);
1247 if( !xDataModel
.is() )
1249 static const OUString
aSN( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.awt.tree.DefaultTreeDataModel" ) );
1250 Reference
< XMultiServiceFactory
> xORB( ::comphelper::getProcessServiceFactory() );
1253 mxDataModel
.query( xORB
->createInstance( aSN
) );
1257 mxDataModel
= xDataModel
;
1259 fillTree( rTree
, mxDataModel
);
1261 if( mxDataModel
.is() )
1262 mxDataModel
->addTreeDataModelListener( xListener
);
1265 // --------------------------------------------------------------------
1266 // ::com::sun::star::awt::XLayoutConstrains
1267 // --------------------------------------------------------------------
1269 ::com::sun::star::awt::Size
TreeControlPeer::getMinimumSize() throw(RuntimeException
)
1271 ::vos::OGuard
aGuard( GetMutex() );
1273 ::com::sun::star::awt::Size aSz
;
1275 MultiLineEdit* pEdit = (MultiLineEdit*) GetWindow();
1277 aSz = AWTSize(pEdit->CalcMinimumSize());
1282 ::com::sun::star::awt::Size
TreeControlPeer::getPreferredSize() throw(RuntimeException
)
1284 return getMinimumSize();
1287 ::com::sun::star::awt::Size
TreeControlPeer::calcAdjustedSize( const ::com::sun::star::awt::Size
& rNewSize
) throw(RuntimeException
)
1289 ::vos::OGuard
aGuard( GetMutex() );
1291 ::com::sun::star::awt::Size aSz
= rNewSize
;
1293 MultiLineEdit* pEdit = (MultiLineEdit*) GetWindow();
1295 aSz = AWTSize(pEdit->CalcAdjustedSize( VCLSize(rNewSize )));
1300 // --------------------------------------------------------------------
1301 // ::com::sun::star::awt::XVclWindowPeer
1302 // --------------------------------------------------------------------
1304 void TreeControlPeer::setProperty( const ::rtl::OUString
& PropertyName
, const Any
& aValue
) throw(RuntimeException
)
1306 ::vos::OGuard
aGuard( GetMutex() );
1308 UnoTreeListBoxImpl
& rTree
= getTreeListBoxOrThrow();
1310 switch( GetPropertyId( PropertyName
) )
1312 case BASEPROPERTY_TREE_SELECTIONTYPE
:
1314 SelectionType eSelectionType
;
1315 if( aValue
>>= eSelectionType
)
1317 SelectionMode eSelMode
;
1318 switch( eSelectionType
)
1320 case SelectionType_SINGLE
: eSelMode
= SINGLE_SELECTION
; break;
1321 case SelectionType_RANGE
: eSelMode
= RANGE_SELECTION
; break;
1322 case SelectionType_MULTI
: eSelMode
= MULTIPLE_SELECTION
; break;
1323 // case SelectionType_NONE:
1324 default: eSelMode
= NO_SELECTION
; break;
1326 if( rTree
.GetSelectionMode() != eSelMode
)
1327 rTree
.SetSelectionMode( eSelMode
);
1332 case BASEPROPERTY_TREE_DATAMODEL
:
1333 onChangeDataModel( rTree
, Reference
< XTreeDataModel
>( aValue
, UNO_QUERY
) );
1335 case BASEPROPERTY_TREE_ROWHEIGHT
:
1337 sal_Int32 nHeight
= 0;
1338 if( aValue
>>= nHeight
)
1339 rTree
.SetEntryHeight( (short)nHeight
);
1342 case BASEPROPERTY_TREE_EDITABLE
:
1344 sal_Bool bEnabled
= false;
1345 if( aValue
>>= bEnabled
)
1346 rTree
.EnableInplaceEditing( bEnabled
? TRUE
: FALSE
);
1349 case BASEPROPERTY_TREE_INVOKESSTOPNODEEDITING
:
1351 case BASEPROPERTY_TREE_ROOTDISPLAYED
:
1353 sal_Bool bDisplayed
= false;
1354 if( (aValue
>>= bDisplayed
) && ( bDisplayed
!= mbIsRootDisplayed
) )
1356 onChangeRootDisplayed(bDisplayed
);
1360 case BASEPROPERTY_TREE_SHOWSHANDLES
:
1362 sal_Bool bEnabled
= false;
1363 if( aValue
>>= bEnabled
)
1365 WinBits nBits
= rTree
.GetWindowBits() & (~WB_HASLINES
);
1367 nBits
|= WB_HASLINES
;
1368 if( nBits
!= rTree
.GetWindowBits() )
1369 rTree
.SetWindowBits( nBits
);
1373 case BASEPROPERTY_TREE_SHOWSROOTHANDLES
:
1375 sal_Bool bEnabled
= false;
1376 if( aValue
>>= bEnabled
)
1378 WinBits nBits
= rTree
.GetWindowBits() & (~WB_HASLINESATROOT
);
1380 nBits
|= WB_HASLINESATROOT
;
1381 if( nBits
!= rTree
.GetWindowBits() )
1382 rTree
.SetWindowBits( nBits
);
1387 VCLXWindow::setProperty( PropertyName
, aValue
);
1392 Any
TreeControlPeer::getProperty( const ::rtl::OUString
& PropertyName
) throw(RuntimeException
)
1394 ::vos::OGuard
aGuard( GetMutex() );
1396 const sal_uInt16 nPropId
= GetPropertyId( PropertyName
);
1397 if( (nPropId
>= BASEPROPERTY_TREE_START
) && (nPropId
<= BASEPROPERTY_TREE_END
) )
1399 UnoTreeListBoxImpl
& rTree
= getTreeListBoxOrThrow();
1402 case BASEPROPERTY_TREE_SELECTIONTYPE
:
1404 SelectionType eSelectionType
;
1406 SelectionMode eSelMode
= rTree
.GetSelectionMode();
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_TREE_ROWHEIGHT
:
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
.GetWindowBits() & WB_HASLINES
) != 0 ? sal_True
: sal_False
);
1429 case BASEPROPERTY_TREE_SHOWSROOTHANDLES
:
1430 return Any( (rTree
.GetWindowBits() & WB_HASLINESATROOT
) != 0 ? sal_True
: sal_False
);
1433 return VCLXWindow::getProperty( PropertyName
);
1436 void TreeControlPeer::onChangeRootDisplayed( sal_Bool bIsRootDisplayed
)
1438 if( mbIsRootDisplayed
== bIsRootDisplayed
)
1441 mbIsRootDisplayed
= bIsRootDisplayed
;
1443 UnoTreeListBoxImpl
& rTree
= getTreeListBoxOrThrow();
1445 if( rTree
.GetEntryCount() == 0 )
1449 fillTree( rTree
, mxDataModel
);
1450 if( mbIsRootDisplayed
)
1458 bool TreeControlPeer::loadImage( const ::rtl::OUString
& rURL
, Image
& rImage
)
1460 if( !mxGraphicProvider
.is() )
1462 static const OUString
aSN( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.graphic.GraphicProvider" ) );
1463 Reference
< XMultiServiceFactory
> xORB( ::comphelper::getProcessServiceFactory() );
1466 Reference
< XInterface
> x( xORB
->createInstance( aSN
) );
1467 mxGraphicProvider
.query( x
);
1468 mxGraphicProvider
= Reference
< XGraphicProvider
>( x
, UNO_QUERY
);
1472 if( mxGraphicProvider
.is() ) try
1474 ::com::sun::star::beans::PropertyValues
aProps( 1 );
1475 aProps
[0].Name
= OUString( RTL_CONSTASCII_USTRINGPARAM( "URL" ) );
1476 aProps
[0].Value
<<= rURL
;
1478 Reference
< XGraphic
> xGraphic( mxGraphicProvider
->queryGraphic( aProps
) );
1480 Graphic
aGraphic( xGraphic
);
1481 rImage
= aGraphic
.GetBitmapEx();
1491 // ====================================================================
1492 // class UnoTreeListBoxImpl
1493 // ====================================================================
1495 UnoTreeListBoxImpl::UnoTreeListBoxImpl( TreeControlPeer
* pPeer
, Window
* pParent
, WinBits nWinStyle
)
1496 : SvTreeListBox( pParent
, nWinStyle
)
1499 SetWindowBits( WB_BORDER
| WB_HASLINES
|WB_HASBUTTONS
| WB_HASLINESATROOT
| WB_HASBUTTONSATROOT
| WB_HSCROLL
);
1500 SetNodeDefaultImages();
1501 SetSelectHdl( LINK(this, UnoTreeListBoxImpl
, OnSelectionChangeHdl
) );
1502 SetDeselectHdl( LINK(this, UnoTreeListBoxImpl
, OnSelectionChangeHdl
) );
1504 SetExpandingHdl( LINK(this, UnoTreeListBoxImpl
, OnExpandingHdl
) );
1505 SetExpandedHdl( LINK(this, UnoTreeListBoxImpl
, OnExpandedHdl
) );
1509 // --------------------------------------------------------------------
1511 UnoTreeListBoxImpl::~UnoTreeListBoxImpl()
1514 mxPeer
->disposeControl();
1517 // --------------------------------------------------------------------
1519 IMPL_LINK( UnoTreeListBoxImpl
, OnSelectionChangeHdl
, UnoTreeListBoxImpl
*, EMPTYARG
)
1522 mxPeer
->onSelectionChanged();
1526 // --------------------------------------------------------------------
1528 IMPL_LINK(UnoTreeListBoxImpl
, OnExpandingHdl
, UnoTreeListBoxImpl
*, EMPTYARG
)
1530 UnoTreeListEntry
* pEntry
= dynamic_cast< UnoTreeListEntry
* >( GetHdlEntry() );
1532 if( pEntry
&& mxPeer
.is() )
1534 return mxPeer
->onExpanding( pEntry
->mxNode
, !IsExpanded( pEntry
) ) ? 1 : 0;
1539 // --------------------------------------------------------------------
1541 IMPL_LINK(UnoTreeListBoxImpl
, OnExpandedHdl
, UnoTreeListBoxImpl
*, EMPTYARG
)
1543 UnoTreeListEntry
* pEntry
= dynamic_cast< UnoTreeListEntry
* >( GetHdlEntry() );
1544 if( pEntry
&& mxPeer
.is() )
1546 mxPeer
->onExpanded( pEntry
->mxNode
, IsExpanded( pEntry
) );
1551 // --------------------------------------------------------------------
1553 sal_uInt32
UnoTreeListBoxImpl::insert( SvLBoxEntry
* pEntry
,SvLBoxEntry
* pParent
,ULONG nPos
)
1556 return SvTreeListBox::Insert( pEntry
, pParent
, nPos
);
1558 return SvTreeListBox::Insert( pEntry
, nPos
);
1561 // --------------------------------------------------------------------
1563 void UnoTreeListBoxImpl::RequestingChilds( SvLBoxEntry
* pParent
)
1565 UnoTreeListEntry
* pEntry
= dynamic_cast< UnoTreeListEntry
* >( pParent
);
1566 if( pEntry
&& pEntry
->mxNode
.is() && mxPeer
.is() )
1567 mxPeer
->onRequestChildNodes( pEntry
->mxNode
);
1570 // --------------------------------------------------------------------
1572 BOOL
UnoTreeListBoxImpl::EditingEntry( SvLBoxEntry
* pEntry
, Selection
& )
1574 return mxPeer
.is() ? mxPeer
->onEditingEntry( dynamic_cast< UnoTreeListEntry
* >( pEntry
) ) : false;
1577 // --------------------------------------------------------------------
1579 BOOL
UnoTreeListBoxImpl::EditedEntry( SvLBoxEntry
* pEntry
, const XubString
& rNewText
)
1581 return mxPeer
.is() ? mxPeer
->onEditedEntry( dynamic_cast< UnoTreeListEntry
* >( pEntry
), rNewText
) : false;
1584 // ====================================================================
1585 // class UnoTreeListItem
1586 // ====================================================================
1588 UnoTreeListItem::UnoTreeListItem( SvLBoxEntry
* pEntry
)
1589 : SvLBoxItem( pEntry
, 0 )
1593 // --------------------------------------------------------------------
1595 UnoTreeListItem::UnoTreeListItem()
1600 // --------------------------------------------------------------------
1602 UnoTreeListItem::~UnoTreeListItem()
1606 // --------------------------------------------------------------------
1608 USHORT
UnoTreeListItem::IsA()
1613 // --------------------------------------------------------------------
1615 void UnoTreeListItem::Paint( const Point
& rPos
, SvLBox
& rDev
, USHORT
/* nFlags */, SvLBoxEntry
* _pEntry
)
1620 Size
aSize( GetSize(&rDev
,_pEntry
) );
1623 rDev
.DrawImage( aPos
, maImage
, rDev
.IsEnabled() ? 0 : IMAGE_DRAW_DISABLE
);
1624 int nWidth
= maImage
.GetSizePixel().Width() + 6;
1626 aSize
.Width() -= nWidth
;
1628 rDev
.DrawText( Rectangle(aPos
,aSize
),maText
, rDev
.IsEnabled() ? 0 : TEXT_DRAW_DISABLE
);
1634 rDev
.DrawImage( aPos
, maImage
, rDev
.IsEnabled() ? 0 : IMAGE_DRAW_DISABLE
);
1635 aPos
.X() += maImage
.GetSizePixel().Width() + 6;
1637 rDev
.DrawText( aPos
, maText
);
1641 // --------------------------------------------------------------------
1643 SvLBoxItem
* UnoTreeListItem::Create() const
1645 return new UnoTreeListItem
;
1648 // --------------------------------------------------------------------
1650 void UnoTreeListItem::Clone( SvLBoxItem
* pSource
)
1652 UnoTreeListItem
* pSourceItem
= dynamic_cast< UnoTreeListItem
* >( pSource
);
1655 maText
= pSourceItem
->maText
;
1656 maImage
= pSourceItem
->maImage
;
1660 // --------------------------------------------------------------------
1662 OUString
UnoTreeListItem::GetText() const
1667 // --------------------------------------------------------------------
1669 void UnoTreeListItem::SetText( const OUString
& rText
)
1674 // --------------------------------------------------------------------
1676 void UnoTreeListItem::SetImage( const Image
& rImage
)
1681 // --------------------------------------------------------------------
1683 OUString
UnoTreeListItem::GetGraphicURL() const
1685 return maGraphicURL
;
1688 // --------------------------------------------------------------------
1690 void UnoTreeListItem::SetGraphicURL( const OUString
& rGraphicURL
)
1692 maGraphicURL
= rGraphicURL
;
1695 // --------------------------------------------------------------------
1697 void UnoTreeListItem::InitViewData( SvLBox
* pView
,SvLBoxEntry
* pEntry
, SvViewDataItem
* pViewData
)
1700 pViewData
= pView
->GetViewDataItem( pEntry
, this );
1702 pViewData
->aSize
= maImage
.GetSizePixel();
1704 const Size
aTextSize(pView
->GetTextWidth( maText
), pView
->GetTextHeight());
1705 if( pViewData
->aSize
.Width() )
1707 pViewData
->aSize
.Width() += 6 + aTextSize
.Width();
1708 if( pViewData
->aSize
.Height() < aTextSize
.Height() )
1709 pViewData
->aSize
.Height() = aTextSize
.Height();
1713 pViewData
->aSize
= aTextSize
;
1717 // --------------------------------------------------------------------
1719 UnoTreeListEntry::UnoTreeListEntry( const Reference
< XTreeNode
>& xNode
, TreeControlPeer
* pPeer
)
1725 mpPeer
->addEntry( this );
1728 // --------------------------------------------------------------------
1730 UnoTreeListEntry::~UnoTreeListEntry()
1733 mpPeer
->removeEntry( this );