1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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>
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
;
55 LockGuard( sal_Int32
& rLock
)
70 // --------------------------------------------------------------------
72 class ImplContextGraphicItem
: public SvLBoxContextBmp
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
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 *);
102 rtl::Reference
< TreeControlPeer
> mxPeer
;
105 // --------------------------------------------------------------------
107 class UnoTreeListItem
: public SvLBoxString
110 UnoTreeListItem( SvTreeListEntry
* );
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
);
119 const Point
& rPos
, SvTreeListBox
& rOutDev
, const SvViewDataEntry
* pView
, const SvTreeListEntry
* pEntry
);
120 SvLBoxItem
* Create() const;
121 void Clone( SvLBoxItem
* pSource
);
124 OUString maGraphicURL
;
128 // --------------------------------------------------------------------
130 class UnoTreeListEntry
: public SvTreeListEntry
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 )
150 // --------------------------------------------------------------------
152 TreeControlPeer::~TreeControlPeer()
156 delete mpTreeNodeMap
;
159 // --------------------------------------------------------------------
161 void TreeControlPeer::addEntry( UnoTreeListEntry
* pEntry
)
163 if( pEntry
&& pEntry
->mxNode
.is() )
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
)
194 TreeNodeMap::iterator
aIter( mpTreeNodeMap
->find( xNode
) );
195 if( aIter
!= mpTreeNodeMap
->end() )
196 return (*aIter
).second
;
200 throw IllegalArgumentException();
205 // --------------------------------------------------------------------
207 Window
* TreeControlPeer::createVclControl( Window
* pParent
, sal_Int64 nWinStyle
)
209 mpTreeImpl
= new UnoTreeListBoxImpl( this, pParent
, nWinStyle
);
213 // --------------------------------------------------------------------
215 /** called from the UnoTreeListBoxImpl when it gets deleted */
216 void TreeControlPeer::disposeControl()
218 delete mpTreeNodeMap
;
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;
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() );
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
);
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 ) );
280 if( aValue
!= pUnoItem
->GetText() )
282 pUnoItem
->SetText( aValue
);
286 if( pUnoItem
->GetGraphicURL() != pEntry
->mxNode
->getNodeGraphicURL() )
289 if( loadImage( pEntry
->mxNode
->getNodeGraphicURL(), aImage
) )
291 pUnoItem
->SetGraphicURL( pEntry
->mxNode
->getNodeGraphicURL() );
292 pUnoItem
->SetImage( aImage
);
293 mpTreeImpl
->AdjustEntryHeight( aImage
);
299 if( (pEntry
->mxNode
->hasChildrenOnDemand() == sal_True
) != (pEntry
->HasChildrenOnDemand() == sal_True
) )
301 pEntry
->EnableChildrenOnDemand( pEntry
->mxNode
->hasChildrenOnDemand() ? sal_True
: sal_False
);
305 ImplContextGraphicItem
* pContextGraphicItem
= dynamic_cast< ImplContextGraphicItem
* >( pEntry
->GetItem( 0 ) );
306 if( pContextGraphicItem
)
308 if( pContextGraphicItem
->msExpandedGraphicURL
!= pEntry
->mxNode
->getExpandedGraphicURL() )
311 if( loadImage( pEntry
->mxNode
->getExpandedGraphicURL(), aImage
) )
313 pContextGraphicItem
->msExpandedGraphicURL
= pEntry
->mxNode
->getExpandedGraphicURL();
314 mpTreeImpl
->SetExpandedEntryBmp( pEntry
, aImage
);
318 if( pContextGraphicItem
->msCollapsedGraphicURL
!= pEntry
->mxNode
->getCollapsedGraphicURL() )
321 if( loadImage( pEntry
->mxNode
->getCollapsedGraphicURL(), aImage
) )
323 pContextGraphicItem
->msCollapsedGraphicURL
= pEntry
->mxNode
->getCollapsedGraphicURL();
324 mpTreeImpl
->SetCollapsedEntryBmp( pEntry
, aImage
);
331 mpTreeImpl
->GetModel()->InvalidateEntry( pEntry
);
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
);
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
);
371 maTreeExpansionListeners
.treeExpanding( aEvent
);
375 maTreeExpansionListeners
.treeCollapsing( aEvent
);
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
);
396 maTreeExpansionListeners
.treeExpanded( aEvent
);
400 maTreeExpansionListeners
.treeCollapsed( aEvent
);
408 // --------------------------------------------------------------------
410 void TreeControlPeer::fillTree( UnoTreeListBoxImpl
& rTree
, const Reference
< XTreeDataModel
>& xDataModel
)
414 if( xDataModel
.is() )
416 Reference
< XTreeNode
> xRootNode( xDataModel
->getRoot() );
419 if( mbIsRootDisplayed
)
421 addNode( rTree
, xRootNode
, 0 );
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
)
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
)
451 throw DisposedException();
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
;
465 const Reference
< XTreeNode
> *pNodes
= 0;
466 sal_Int32 nCount
= 0;
468 if( rSelection
.hasValue() )
470 switch( rSelection
.getValueTypeClass() )
472 case TypeClass_INTERFACE
:
474 rSelection
>>= xTempNode
;
482 case TypeClass_SEQUENCE
:
484 if( rSelection
.getValueType() == ::getCppuType( (const Sequence
< Reference
< XTreeNode
> > *) 0 ) )
486 const Sequence
< Reference
< XTreeNode
> >& rSeq( *(const Sequence
< Reference
< XTreeNode
> > *)rSelection
.getValue() );
487 nCount
= rSeq
.getLength();
489 pNodes
= rSeq
.getConstArray();
498 throw IllegalArgumentException();
502 rTree
.SelectAll( sal_False
);
504 if( pNodes
&& nCount
)
508 UnoTreeListEntry
* pEntry
= getEntry( *pNodes
++ );
509 rTree
.Select( pEntry
, bSelect
? sal_True
: sal_False
);
514 // -------------------------------------------------------------------
515 // ::com::sun::star::view::XSelectionSupplier
516 // -------------------------------------------------------------------
518 sal_Bool SAL_CALL
TreeControlPeer::select( const Any
& rSelection
) throw (IllegalArgumentException
, RuntimeException
)
520 SolarMutexGuard aGuard
;
521 ChangeNodesSelection( rSelection
, true, true );
525 // -------------------------------------------------------------------
527 Any SAL_CALL
TreeControlPeer::getSelection() throw (RuntimeException
)
529 SolarMutexGuard aGuard
;
531 UnoTreeListBoxImpl
& rTree
= getTreeListBoxOrThrow();
535 sal_uLong nSelectionCount
= rTree
.GetSelectionCount();
536 if( nSelectionCount
== 1 )
538 UnoTreeListEntry
* pEntry
= dynamic_cast< UnoTreeListEntry
* >( rTree
.FirstSelected() );
539 if( pEntry
&& pEntry
->mxNode
.is() )
540 aRet
<<= pEntry
->mxNode
;
542 else if( nSelectionCount
> 1 )
544 Sequence
< Reference
< XTreeNode
> > aSelection( nSelectionCount
);
545 Reference
< XTreeNode
>* pNodes
= aSelection
.getArray();
546 UnoTreeListEntry
* pEntry
= dynamic_cast< UnoTreeListEntry
* >( rTree
.FirstSelected() );
547 while( pEntry
&& nSelectionCount
)
549 *pNodes
++ = pEntry
->mxNode
;
550 pEntry
= dynamic_cast< UnoTreeListEntry
* >( rTree
.NextSelected( pEntry
) );
554 OSL_ASSERT( (pEntry
== 0) && (nSelectionCount
== 0) );
561 // -------------------------------------------------------------------
563 void SAL_CALL
TreeControlPeer::addSelectionChangeListener( const Reference
< XSelectionChangeListener
>& xListener
) throw (RuntimeException
)
565 maSelectionListeners
.addInterface( xListener
);
568 // -------------------------------------------------------------------
570 void SAL_CALL
TreeControlPeer::removeSelectionChangeListener( const Reference
< XSelectionChangeListener
>& xListener
) throw (RuntimeException
)
572 maSelectionListeners
.addInterface( xListener
);
575 // -------------------------------------------------------------------
576 // ::com::sun::star::view::XMultiSelectionSupplier
577 // -------------------------------------------------------------------
579 sal_Bool SAL_CALL
TreeControlPeer::addSelection( const Any
& rSelection
) throw (IllegalArgumentException
, RuntimeException
)
581 ChangeNodesSelection( rSelection
, true, false );
585 // -------------------------------------------------------------------
587 void SAL_CALL
TreeControlPeer::removeSelection( const Any
& rSelection
) throw (IllegalArgumentException
, RuntimeException
)
589 ChangeNodesSelection( rSelection
, false, false );
592 // -------------------------------------------------------------------
594 void SAL_CALL
TreeControlPeer::clearSelection() throw (RuntimeException
)
596 SolarMutexGuard aGuard
;
597 getTreeListBoxOrThrow().SelectAll( sal_False
);
600 // -------------------------------------------------------------------
602 sal_Int32 SAL_CALL
TreeControlPeer::getSelectionCount() throw (RuntimeException
)
604 SolarMutexGuard aGuard
;
605 return getTreeListBoxOrThrow().GetSelectionCount();
608 // -------------------------------------------------------------------
610 class TreeSelectionEnumeration
: public ::cppu::WeakImplHelper1
< XEnumeration
>
613 TreeSelectionEnumeration( std::list
< Any
>& rSelection
);
614 virtual ::sal_Bool SAL_CALL
hasMoreElements() throw (RuntimeException
);
615 virtual Any SAL_CALL
nextElement() throw (NoSuchElementException
, WrappedTargetException
, RuntimeException
);
617 std::list
< Any
> maSelection
;
618 std::list
< Any
>::iterator maIter
;
621 // -------------------------------------------------------------------
623 TreeSelectionEnumeration::TreeSelectionEnumeration( std::list
< Any
>& rSelection
)
625 maSelection
.swap( rSelection
);
626 maIter
= maSelection
.begin();
629 // -------------------------------------------------------------------
631 ::sal_Bool SAL_CALL
TreeSelectionEnumeration::hasMoreElements() throw (RuntimeException
)
633 return maIter
!= maSelection
.end();
636 // -------------------------------------------------------------------
638 Any SAL_CALL
TreeSelectionEnumeration::nextElement() throw (NoSuchElementException
, WrappedTargetException
, RuntimeException
)
640 if( maIter
== maSelection
.end() )
641 throw NoSuchElementException();
646 // -------------------------------------------------------------------
648 Reference
< XEnumeration
> SAL_CALL
TreeControlPeer::createSelectionEnumeration() throw (RuntimeException
)
650 SolarMutexGuard aGuard
;
652 UnoTreeListBoxImpl
& rTree
= getTreeListBoxOrThrow();
654 sal_uInt32 nSelectionCount
= rTree
.GetSelectionCount();
655 std::list
< Any
> aSelection( nSelectionCount
);
657 UnoTreeListEntry
* pEntry
= dynamic_cast< UnoTreeListEntry
* >( rTree
.FirstSelected() );
658 while( pEntry
&& nSelectionCount
)
660 aSelection
.push_back( Any( pEntry
->mxNode
) );
661 pEntry
= dynamic_cast< UnoTreeListEntry
* >( rTree
.NextSelected( pEntry
) );
665 OSL_ASSERT( (pEntry
== 0) && (nSelectionCount
== 0) );
667 return Reference
< XEnumeration
>( new TreeSelectionEnumeration( aSelection
) );
670 // -------------------------------------------------------------------
672 Reference
< XEnumeration
> SAL_CALL
TreeControlPeer::createReverseSelectionEnumeration() throw (RuntimeException
)
674 SolarMutexGuard aGuard
;
676 UnoTreeListBoxImpl
& rTree
= getTreeListBoxOrThrow();
678 sal_uInt32 nSelectionCount
= rTree
.GetSelectionCount();
679 std::list
< Any
> aSelection
;
681 UnoTreeListEntry
* pEntry
= dynamic_cast< UnoTreeListEntry
* >( rTree
.FirstSelected() );
682 while( pEntry
&& nSelectionCount
)
684 aSelection
.push_front( Any( pEntry
->mxNode
) );
685 pEntry
= dynamic_cast< UnoTreeListEntry
* >( rTree
.NextSelected( pEntry
) );
689 OSL_ASSERT( (pEntry
== 0) && (nSelectionCount
== 0) );
691 return Reference
< XEnumeration
>( new TreeSelectionEnumeration( aSelection
) );
694 // --------------------------------------------------------------------
695 // ::com::sun::star::awt::XTreeControl
696 // --------------------------------------------------------------------
698 OUString SAL_CALL
TreeControlPeer::getDefaultExpandedGraphicURL() throw (::com::sun::star::uno::RuntimeException
)
700 SolarMutexGuard aGuard
;
701 return msDefaultExpandedGraphicURL
;
704 // --------------------------------------------------------------------
706 void SAL_CALL
TreeControlPeer::setDefaultExpandedGraphicURL( const OUString
& sDefaultExpandedGraphicURL
) throw (::com::sun::star::uno::RuntimeException
)
708 SolarMutexGuard aGuard
;
709 if( msDefaultExpandedGraphicURL
!= sDefaultExpandedGraphicURL
)
711 if( !sDefaultExpandedGraphicURL
.isEmpty() )
712 loadImage( sDefaultExpandedGraphicURL
, maDefaultExpandedImage
);
714 maDefaultExpandedImage
= Image();
716 UnoTreeListBoxImpl
& rTree
= getTreeListBoxOrThrow();
718 SvTreeListEntry
* pEntry
= rTree
.First();
721 ImplContextGraphicItem
* pContextGraphicItem
= dynamic_cast< ImplContextGraphicItem
* >( pEntry
->GetItem( 0 ) );
722 if( pContextGraphicItem
)
724 if( pContextGraphicItem
->msExpandedGraphicURL
.isEmpty() )
725 rTree
.SetExpandedEntryBmp( pEntry
, maDefaultExpandedImage
);
727 pEntry
= rTree
.Next( pEntry
);
730 msDefaultExpandedGraphicURL
= sDefaultExpandedGraphicURL
;
734 // --------------------------------------------------------------------
736 OUString SAL_CALL
TreeControlPeer::getDefaultCollapsedGraphicURL() throw (::com::sun::star::uno::RuntimeException
)
738 SolarMutexGuard aGuard
;
739 return msDefaultCollapsedGraphicURL
;
742 // --------------------------------------------------------------------
744 void SAL_CALL
TreeControlPeer::setDefaultCollapsedGraphicURL( const OUString
& sDefaultCollapsedGraphicURL
) throw (::com::sun::star::uno::RuntimeException
)
746 SolarMutexGuard aGuard
;
747 if( msDefaultCollapsedGraphicURL
!= sDefaultCollapsedGraphicURL
)
749 if( !sDefaultCollapsedGraphicURL
.isEmpty() )
750 loadImage( sDefaultCollapsedGraphicURL
, maDefaultCollapsedImage
);
752 maDefaultCollapsedImage
= Image();
754 UnoTreeListBoxImpl
& rTree
= getTreeListBoxOrThrow();
756 SvTreeListEntry
* pEntry
= rTree
.First();
759 ImplContextGraphicItem
* pContextGraphicItem
= dynamic_cast< ImplContextGraphicItem
* >( pEntry
->GetItem( 0 ) );
760 if( pContextGraphicItem
)
762 if( pContextGraphicItem
->msCollapsedGraphicURL
.isEmpty() )
763 rTree
.SetCollapsedEntryBmp( pEntry
, maDefaultCollapsedImage
);
765 pEntry
= rTree
.Next( pEntry
);
768 msDefaultCollapsedGraphicURL
= sDefaultCollapsedGraphicURL
;
772 // --------------------------------------------------------------------
774 sal_Bool SAL_CALL
TreeControlPeer::isNodeExpanded( const Reference
< XTreeNode
>& xNode
) throw (RuntimeException
, IllegalArgumentException
)
776 SolarMutexGuard aGuard
;
778 UnoTreeListBoxImpl
& rTree
= getTreeListBoxOrThrow();
779 UnoTreeListEntry
* pEntry
= getEntry( xNode
);
780 return ( pEntry
&& rTree
.IsExpanded( pEntry
) ) ? sal_True
: sal_False
;
783 // -------------------------------------------------------------------
785 sal_Bool SAL_CALL
TreeControlPeer::isNodeCollapsed( const Reference
< XTreeNode
>& xNode
) throw (RuntimeException
, IllegalArgumentException
)
787 SolarMutexGuard aGuard
;
788 return !isNodeExpanded( xNode
);
791 // -------------------------------------------------------------------
793 void SAL_CALL
TreeControlPeer::makeNodeVisible( const Reference
< XTreeNode
>& xNode
) throw (RuntimeException
, ExpandVetoException
, IllegalArgumentException
)
795 SolarMutexGuard aGuard
;
797 UnoTreeListBoxImpl
& rTree
= getTreeListBoxOrThrow();
798 UnoTreeListEntry
* pEntry
= getEntry( xNode
);
800 rTree
.MakeVisible( pEntry
);
803 // -------------------------------------------------------------------
805 sal_Bool SAL_CALL
TreeControlPeer::isNodeVisible( const Reference
< XTreeNode
>& xNode
) throw (RuntimeException
, IllegalArgumentException
)
807 SolarMutexGuard aGuard
;
809 UnoTreeListBoxImpl
& rTree
= getTreeListBoxOrThrow();
810 UnoTreeListEntry
* pEntry
= getEntry( xNode
);
811 return ( pEntry
&& rTree
.IsEntryVisible( pEntry
) ) ? sal_True
: sal_False
;
814 // -------------------------------------------------------------------
816 void SAL_CALL
TreeControlPeer::expandNode( const Reference
< XTreeNode
>& xNode
) throw (RuntimeException
, ExpandVetoException
, IllegalArgumentException
)
818 SolarMutexGuard aGuard
;
820 UnoTreeListBoxImpl
& rTree
= getTreeListBoxOrThrow();
821 UnoTreeListEntry
* pEntry
= getEntry( xNode
);
823 rTree
.Expand( pEntry
);
826 // -------------------------------------------------------------------
828 void SAL_CALL
TreeControlPeer::collapseNode( const Reference
< XTreeNode
>& xNode
) throw (RuntimeException
, ExpandVetoException
, IllegalArgumentException
)
830 SolarMutexGuard aGuard
;
832 UnoTreeListBoxImpl
& rTree
= getTreeListBoxOrThrow();
833 UnoTreeListEntry
* pEntry
= getEntry( xNode
);
835 rTree
.Collapse( pEntry
);
838 // -------------------------------------------------------------------
840 void SAL_CALL
TreeControlPeer::addTreeExpansionListener( const Reference
< XTreeExpansionListener
>& xListener
) throw (RuntimeException
)
842 maTreeExpansionListeners
.addInterface( xListener
);
845 // -------------------------------------------------------------------
847 void SAL_CALL
TreeControlPeer::removeTreeExpansionListener( const Reference
< XTreeExpansionListener
>& xListener
) throw (RuntimeException
)
849 maTreeExpansionListeners
.removeInterface( xListener
);
852 // -------------------------------------------------------------------
854 Reference
< XTreeNode
> SAL_CALL
TreeControlPeer::getNodeForLocation( sal_Int32 x
, sal_Int32 y
) throw (RuntimeException
)
856 SolarMutexGuard aGuard
;
858 UnoTreeListBoxImpl
& rTree
= getTreeListBoxOrThrow();
860 Reference
< XTreeNode
> xNode
;
862 const Point
aPos( x
, y
);
863 UnoTreeListEntry
* pEntry
= dynamic_cast< UnoTreeListEntry
* >( rTree
.GetEntry( aPos
, sal_True
) );
865 xNode
= pEntry
->mxNode
;
870 // -------------------------------------------------------------------
872 Reference
< XTreeNode
> SAL_CALL
TreeControlPeer::getClosestNodeForLocation( sal_Int32 x
, sal_Int32 y
) throw (RuntimeException
)
874 SolarMutexGuard aGuard
;
876 UnoTreeListBoxImpl
& rTree
= getTreeListBoxOrThrow();
878 Reference
< XTreeNode
> xNode
;
880 const Point
aPos( x
, y
);
881 UnoTreeListEntry
* pEntry
= dynamic_cast< UnoTreeListEntry
* >( rTree
.GetEntry( aPos
, sal_True
) );
883 xNode
= pEntry
->mxNode
;
888 // -------------------------------------------------------------------
890 awt::Rectangle SAL_CALL
TreeControlPeer::getNodeRect( const Reference
< XTreeNode
>& i_Node
) throw (IllegalArgumentException
, RuntimeException
)
892 SolarMutexGuard aGuard
;
894 UnoTreeListBoxImpl
& rTree
= getTreeListBoxOrThrow();
895 UnoTreeListEntry
* pEntry
= getEntry( i_Node
, true );
897 ::Rectangle
aEntryRect( rTree
.GetFocusRect( pEntry
, rTree
.GetEntryPosition( pEntry
).Y() ) );
898 return VCLUnoHelper::ConvertToAWTRect( aEntryRect
);
901 // -------------------------------------------------------------------
903 sal_Bool SAL_CALL
TreeControlPeer::isEditing( ) throw (RuntimeException
)
905 SolarMutexGuard aGuard
;
907 UnoTreeListBoxImpl
& rTree
= getTreeListBoxOrThrow();
908 return rTree
.IsEditingActive() ? sal_True
: sal_False
;
911 // -------------------------------------------------------------------
913 sal_Bool SAL_CALL
TreeControlPeer::stopEditing() throw (RuntimeException
)
915 SolarMutexGuard aGuard
;
917 UnoTreeListBoxImpl
& rTree
= getTreeListBoxOrThrow();
918 if( rTree
.IsEditingActive() )
920 rTree
.EndEditing(sal_False
);
929 // -------------------------------------------------------------------
931 void SAL_CALL
TreeControlPeer::cancelEditing( ) throw (RuntimeException
)
933 SolarMutexGuard aGuard
;
935 UnoTreeListBoxImpl
& rTree
= getTreeListBoxOrThrow();
936 rTree
.EndEditing(sal_False
);
939 // -------------------------------------------------------------------
941 void SAL_CALL
TreeControlPeer::startEditingAtNode( const Reference
< XTreeNode
>& xNode
) throw (IllegalArgumentException
, RuntimeException
)
943 SolarMutexGuard aGuard
;
945 UnoTreeListBoxImpl
& rTree
= getTreeListBoxOrThrow();
946 UnoTreeListEntry
* pEntry
= getEntry( xNode
);
947 rTree
.EditEntry( pEntry
);
950 void SAL_CALL
TreeControlPeer::addTreeEditListener( const Reference
< XTreeEditListener
>& xListener
) throw (RuntimeException
)
952 maTreeEditListeners
.addInterface( xListener
);
955 void SAL_CALL
TreeControlPeer::removeTreeEditListener( const Reference
< XTreeEditListener
>& xListener
) throw (RuntimeException
)
957 maTreeEditListeners
.removeInterface( xListener
);
960 bool TreeControlPeer::onEditingEntry( UnoTreeListEntry
* pEntry
)
962 if( mpTreeImpl
&& pEntry
&& pEntry
->mxNode
.is() && (maTreeEditListeners
.getLength() > 0) )
966 maTreeEditListeners
.nodeEditing( pEntry
->mxNode
);
968 catch( VetoException
& )
979 bool TreeControlPeer::onEditedEntry( UnoTreeListEntry
* pEntry
, const OUString
& rNewText
)
981 if( mpTreeImpl
&& pEntry
&& pEntry
->mxNode
.is() ) try
983 LockGuard
aLockGuard( mnEditLock
);
984 if( maTreeEditListeners
.getLength() > 0 )
986 maTreeEditListeners
.nodeEdited( pEntry
->mxNode
, rNewText
);
991 Reference
< XMutableTreeNode
> xMutableNode( pEntry
->mxNode
, UNO_QUERY
);
992 if( xMutableNode
.is() )
993 xMutableNode
->setDisplayValue( Any( rNewText
) );
1006 // --------------------------------------------------------------------
1007 // ::com::sun::star::awt::tree::TreeDataModelListener
1008 // --------------------------------------------------------------------
1010 void SAL_CALL
TreeControlPeer::treeNodesChanged( const ::com::sun::star::awt::tree::TreeDataModelEvent
& rEvent
) throw (RuntimeException
)
1012 SolarMutexGuard aGuard
;
1014 if( mnEditLock
!= 0 )
1017 updateTree( rEvent
, true );
1020 void SAL_CALL
TreeControlPeer::treeNodesInserted( const ::com::sun::star::awt::tree::TreeDataModelEvent
& rEvent
) throw (RuntimeException
)
1022 SolarMutexGuard aGuard
;
1024 if( mnEditLock
!= 0 )
1027 updateTree( rEvent
, true );
1030 void SAL_CALL
TreeControlPeer::treeNodesRemoved( const ::com::sun::star::awt::tree::TreeDataModelEvent
& rEvent
) throw (RuntimeException
)
1032 SolarMutexGuard aGuard
;
1034 if( mnEditLock
!= 0 )
1037 updateTree( rEvent
, true );
1040 void SAL_CALL
TreeControlPeer::treeStructureChanged( const ::com::sun::star::awt::tree::TreeDataModelEvent
& rEvent
) throw (RuntimeException
)
1042 SolarMutexGuard aGuard
;
1044 if( mnEditLock
!= 0 )
1047 updateTree( rEvent
, true );
1050 void TreeControlPeer::updateTree( const ::com::sun::star::awt::tree::TreeDataModelEvent
& rEvent
, bool bRecursive
)
1052 UnoTreeListBoxImpl
& rTree
= getTreeListBoxOrThrow();
1054 Sequence
< Reference
< XTreeNode
> > Nodes
;
1055 Reference
< XTreeNode
> xNode( rEvent
.ParentNode
);
1056 if( !xNode
.is() && Nodes
.getLength() )
1062 updateNode( rTree
, xNode
, bRecursive
);
1065 void TreeControlPeer::updateNode( UnoTreeListBoxImpl
& rTree
, const Reference
< XTreeNode
>& xNode
, bool bRecursive
)
1069 UnoTreeListEntry
* pNodeEntry
= getEntry( xNode
, false );
1073 Reference
< XTreeNode
> xParentNode( xNode
->getParent() );
1074 UnoTreeListEntry
* pParentEntry
= 0;
1075 sal_uLong nChild
= LIST_APPEND
;
1077 if( xParentNode
.is() )
1079 pParentEntry
= getEntry( xParentNode
);
1080 nChild
= xParentNode
->getIndex( xNode
);
1083 pNodeEntry
= createEntry( xNode
, pParentEntry
, nChild
);
1087 updateChildNodes( rTree
, xNode
, pNodeEntry
);
1091 void TreeControlPeer::updateChildNodes( UnoTreeListBoxImpl
& rTree
, const Reference
< XTreeNode
>& xParentNode
, UnoTreeListEntry
* pParentEntry
)
1093 if( xParentNode
.is() && pParentEntry
)
1095 UnoTreeListEntry
* pCurrentChild
= dynamic_cast< UnoTreeListEntry
* >( rTree
.FirstChild( pParentEntry
) );
1097 const sal_Int32 nChildCount
= xParentNode
->getChildCount();
1098 for( sal_Int32 nChild
= 0; nChild
< nChildCount
; nChild
++ )
1100 Reference
< XTreeNode
> xNode( xParentNode
->getChildAt( nChild
) );
1101 if( !pCurrentChild
|| ( pCurrentChild
->mxNode
!= xNode
) )
1103 UnoTreeListEntry
* pNodeEntry
= getEntry( xNode
, false );
1104 if( pNodeEntry
== 0 )
1106 // child node is not yet part of the tree, add it
1107 pCurrentChild
= createEntry( xNode
, pParentEntry
, nChild
);
1109 else if( pNodeEntry
!= pCurrentChild
)
1111 // node is already part of the tree, but not on the correct position
1112 rTree
.GetModel()->Move( pNodeEntry
, pParentEntry
, nChild
);
1113 pCurrentChild
= pNodeEntry
;
1114 updateEntry( pCurrentChild
);
1119 // child node has entry and entry is equal to current entry,
1120 // so no structural changes happened
1121 updateEntry( pCurrentChild
);
1124 pCurrentChild
= dynamic_cast< UnoTreeListEntry
* >( rTree
.NextSibling( pCurrentChild
) );
1127 // check if we have entries without nodes left, we need to remove them
1128 while( pCurrentChild
)
1130 UnoTreeListEntry
* pNextChild
= dynamic_cast< UnoTreeListEntry
* >( rTree
.NextSibling( pCurrentChild
) );
1131 rTree
.GetModel()->Remove( pCurrentChild
);
1132 pCurrentChild
= pNextChild
;
1137 OUString
TreeControlPeer::getEntryString( const Any
& rValue
)
1140 if( rValue
.hasValue() )
1142 switch( rValue
.getValueTypeClass() )
1144 case TypeClass_SHORT
:
1145 case TypeClass_LONG
:
1147 sal_Int32 nValue
= 0;
1148 if( rValue
>>= nValue
)
1149 sValue
= OUString::number( nValue
);
1152 case TypeClass_BYTE
:
1153 case TypeClass_UNSIGNED_SHORT
:
1154 case TypeClass_UNSIGNED_LONG
:
1156 sal_uInt32 nValue
= 0;
1157 if( rValue
>>= nValue
)
1158 sValue
= OUString::number( nValue
);
1161 case TypeClass_HYPER
:
1163 sal_Int64 nValue
= 0;
1164 if( rValue
>>= nValue
)
1165 sValue
= OUString::number( nValue
);
1168 case TypeClass_UNSIGNED_HYPER
:
1170 sal_uInt64 nValue
= 0;
1171 if( rValue
>>= nValue
)
1172 sValue
= OUString::number( nValue
);
1175 case TypeClass_FLOAT
:
1176 case TypeClass_DOUBLE
:
1178 double fValue
= 0.0;
1179 if( rValue
>>= fValue
)
1180 sValue
= OUString::number( fValue
);
1183 case TypeClass_STRING
:
1187 case TypeClass_INTERFACE:
1190 case TypeClass_SEQUENCE:
1192 Sequence< Any > aValues;
1193 if( aValue >>= aValues )
1195 updateEntry( SvTreeListEntry& rEntry, aValues );
1209 void SAL_CALL
TreeControlPeer::disposing( const ::com::sun::star::lang::EventObject
& ) throw(::com::sun::star::uno::RuntimeException
)
1211 // model is disposed, so we clear our tree
1212 SolarMutexGuard aGuard
;
1213 UnoTreeListBoxImpl
& rTree
= getTreeListBoxOrThrow();
1215 mxDataModel
.clear();
1218 void TreeControlPeer::onChangeDataModel( UnoTreeListBoxImpl
& rTree
, const Reference
< XTreeDataModel
>& xDataModel
)
1220 if( xDataModel
.is() && (mxDataModel
== xDataModel
) )
1221 return; // do nothing
1223 Reference
< XTreeDataModelListener
> xListener( this );
1225 if( mxDataModel
.is() )
1226 mxDataModel
->removeTreeDataModelListener( xListener
);
1228 mxDataModel
= xDataModel
;
1230 fillTree( rTree
, mxDataModel
);
1232 if( mxDataModel
.is() )
1233 mxDataModel
->addTreeDataModelListener( xListener
);
1236 // --------------------------------------------------------------------
1237 // ::com::sun::star::awt::XLayoutConstrains
1238 // --------------------------------------------------------------------
1240 ::com::sun::star::awt::Size
TreeControlPeer::getMinimumSize() throw(RuntimeException
)
1242 SolarMutexGuard aGuard
;
1244 ::com::sun::star::awt::Size aSz
;
1246 MultiLineEdit* pEdit = (MultiLineEdit*) GetWindow();
1248 aSz = AWTSize(pEdit->CalcMinimumSize());
1253 ::com::sun::star::awt::Size
TreeControlPeer::getPreferredSize() throw(RuntimeException
)
1255 return getMinimumSize();
1258 ::com::sun::star::awt::Size
TreeControlPeer::calcAdjustedSize( const ::com::sun::star::awt::Size
& rNewSize
) throw(RuntimeException
)
1260 SolarMutexGuard aGuard
;
1262 ::com::sun::star::awt::Size aSz
= rNewSize
;
1264 MultiLineEdit* pEdit = (MultiLineEdit*) GetWindow();
1266 aSz = AWTSize(pEdit->CalcAdjustedSize( VCLSize(rNewSize )));
1271 // --------------------------------------------------------------------
1272 // ::com::sun::star::awt::XVclWindowPeer
1273 // --------------------------------------------------------------------
1275 void TreeControlPeer::setProperty( const OUString
& PropertyName
, const Any
& aValue
) throw(RuntimeException
)
1277 SolarMutexGuard aGuard
;
1279 UnoTreeListBoxImpl
& rTree
= getTreeListBoxOrThrow();
1281 switch( GetPropertyId( PropertyName
) )
1283 case BASEPROPERTY_HIDEINACTIVESELECTION
:
1285 sal_Bool bEnabled
= sal_False
;
1286 if ( aValue
>>= bEnabled
)
1288 WinBits nStyle
= rTree
.GetStyle();
1290 nStyle
|= WB_HIDESELECTION
;
1292 nStyle
&= ~WB_HIDESELECTION
;
1293 rTree
.SetStyle( nStyle
);
1298 case BASEPROPERTY_TREE_SELECTIONTYPE
:
1300 SelectionType eSelectionType
;
1301 if( aValue
>>= eSelectionType
)
1303 SelectionMode eSelMode
;
1304 switch( eSelectionType
)
1306 case SelectionType_SINGLE
: eSelMode
= SINGLE_SELECTION
; break;
1307 case SelectionType_RANGE
: eSelMode
= RANGE_SELECTION
; break;
1308 case SelectionType_MULTI
: eSelMode
= MULTIPLE_SELECTION
; break;
1309 // case SelectionType_NONE:
1310 default: eSelMode
= NO_SELECTION
; break;
1312 if( rTree
.GetSelectionMode() != eSelMode
)
1313 rTree
.SetSelectionMode( eSelMode
);
1318 case BASEPROPERTY_TREE_DATAMODEL
:
1319 onChangeDataModel( rTree
, Reference
< XTreeDataModel
>( aValue
, UNO_QUERY
) );
1321 case BASEPROPERTY_ROW_HEIGHT
:
1323 sal_Int32 nHeight
= 0;
1324 if( aValue
>>= nHeight
)
1325 rTree
.SetEntryHeight( (short)nHeight
);
1328 case BASEPROPERTY_TREE_EDITABLE
:
1330 sal_Bool bEnabled
= false;
1331 if( aValue
>>= bEnabled
)
1332 rTree
.EnableInplaceEditing( bEnabled
? sal_True
: sal_False
);
1335 case BASEPROPERTY_TREE_INVOKESSTOPNODEEDITING
:
1337 case BASEPROPERTY_TREE_ROOTDISPLAYED
:
1339 sal_Bool bDisplayed
= false;
1340 if( (aValue
>>= bDisplayed
) && ( bDisplayed
!= mbIsRootDisplayed
) )
1342 onChangeRootDisplayed(bDisplayed
);
1346 case BASEPROPERTY_TREE_SHOWSHANDLES
:
1348 sal_Bool bEnabled
= false;
1349 if( aValue
>>= bEnabled
)
1351 WinBits nBits
= rTree
.GetStyle() & (~WB_HASLINES
);
1353 nBits
|= WB_HASLINES
;
1354 if( nBits
!= rTree
.GetStyle() )
1355 rTree
.SetStyle( nBits
);
1359 case BASEPROPERTY_TREE_SHOWSROOTHANDLES
:
1361 sal_Bool bEnabled
= false;
1362 if( aValue
>>= bEnabled
)
1364 WinBits nBits
= rTree
.GetStyle() & (~WB_HASLINESATROOT
);
1366 nBits
|= WB_HASLINESATROOT
;
1367 if( nBits
!= rTree
.GetStyle() )
1368 rTree
.SetStyle( nBits
);
1373 VCLXWindow::setProperty( PropertyName
, aValue
);
1378 Any
TreeControlPeer::getProperty( const OUString
& PropertyName
) throw(RuntimeException
)
1380 SolarMutexGuard aGuard
;
1382 const sal_uInt16 nPropId
= GetPropertyId( PropertyName
);
1383 if( (nPropId
>= BASEPROPERTY_TREE_START
) && (nPropId
<= BASEPROPERTY_TREE_END
) )
1385 UnoTreeListBoxImpl
& rTree
= getTreeListBoxOrThrow();
1388 case BASEPROPERTY_HIDEINACTIVESELECTION
:
1389 return Any( ( rTree
.GetStyle() & WB_HIDESELECTION
) != 0 ? sal_True
: sal_False
);
1391 case BASEPROPERTY_TREE_SELECTIONTYPE
:
1393 SelectionType eSelectionType
;
1395 SelectionMode eSelMode
= rTree
.GetSelectionMode();
1398 case SINGLE_SELECTION
: eSelectionType
= SelectionType_SINGLE
; break;
1399 case RANGE_SELECTION
: eSelectionType
= SelectionType_RANGE
; break;
1400 case MULTIPLE_SELECTION
:eSelectionType
= SelectionType_MULTI
; break;
1401 // case NO_SELECTION:
1402 default: eSelectionType
= SelectionType_NONE
; break;
1404 return Any( eSelectionType
);
1406 case BASEPROPERTY_ROW_HEIGHT
:
1407 return Any( (sal_Int32
)rTree
.GetEntryHeight() );
1408 case BASEPROPERTY_TREE_DATAMODEL
:
1409 return Any( mxDataModel
);
1410 case BASEPROPERTY_TREE_EDITABLE
:
1411 return Any( rTree
.IsInplaceEditingEnabled() ? sal_True
: sal_False
);
1412 case BASEPROPERTY_TREE_INVOKESSTOPNODEEDITING
:
1413 return Any( sal_True
); // @todo
1414 case BASEPROPERTY_TREE_ROOTDISPLAYED
:
1415 return Any( mbIsRootDisplayed
);
1416 case BASEPROPERTY_TREE_SHOWSHANDLES
:
1417 return Any( (rTree
.GetStyle() & WB_HASLINES
) != 0 ? sal_True
: sal_False
);
1418 case BASEPROPERTY_TREE_SHOWSROOTHANDLES
:
1419 return Any( (rTree
.GetStyle() & WB_HASLINESATROOT
) != 0 ? sal_True
: sal_False
);
1422 return VCLXWindow::getProperty( PropertyName
);
1425 void TreeControlPeer::onChangeRootDisplayed( sal_Bool bIsRootDisplayed
)
1427 if( mbIsRootDisplayed
== bIsRootDisplayed
)
1430 mbIsRootDisplayed
= bIsRootDisplayed
;
1432 UnoTreeListBoxImpl
& rTree
= getTreeListBoxOrThrow();
1434 if( rTree
.GetEntryCount() == 0 )
1438 fillTree( rTree
, mxDataModel
);
1439 if( mbIsRootDisplayed
)
1447 bool TreeControlPeer::loadImage( const OUString
& rURL
, Image
& rImage
)
1449 if( !mxGraphicProvider
.is() )
1451 Reference
< XComponentContext
> xContext( ::comphelper::getProcessComponentContext() );
1452 Reference
< XInterface
> x( graphic::GraphicProvider::create(xContext
) );
1453 mxGraphicProvider
.query( x
);
1454 mxGraphicProvider
= Reference
< XGraphicProvider
>( x
, UNO_QUERY
);
1457 if( mxGraphicProvider
.is() ) try
1459 ::com::sun::star::beans::PropertyValues
aProps( 1 );
1460 aProps
[0].Name
= "URL";
1461 aProps
[0].Value
<<= rURL
;
1463 Reference
< XGraphic
> xGraphic( mxGraphicProvider
->queryGraphic( aProps
) );
1465 Graphic
aGraphic( xGraphic
);
1466 rImage
= Image(aGraphic
.GetBitmapEx());
1476 // ====================================================================
1477 // class UnoTreeListBoxImpl
1478 // ====================================================================
1480 UnoTreeListBoxImpl::UnoTreeListBoxImpl( TreeControlPeer
* pPeer
, Window
* pParent
, WinBits nWinStyle
)
1481 : SvTreeListBox( pParent
, nWinStyle
)
1484 SetStyle( WB_BORDER
| WB_HASLINES
|WB_HASBUTTONS
| WB_HASLINESATROOT
| WB_HASBUTTONSATROOT
| WB_HSCROLL
);
1485 SetNodeDefaultImages();
1486 SetSelectHdl( LINK(this, UnoTreeListBoxImpl
, OnSelectionChangeHdl
) );
1487 SetDeselectHdl( LINK(this, UnoTreeListBoxImpl
, OnSelectionChangeHdl
) );
1489 SetExpandingHdl( LINK(this, UnoTreeListBoxImpl
, OnExpandingHdl
) );
1490 SetExpandedHdl( LINK(this, UnoTreeListBoxImpl
, OnExpandedHdl
) );
1494 // --------------------------------------------------------------------
1496 UnoTreeListBoxImpl::~UnoTreeListBoxImpl()
1499 mxPeer
->disposeControl();
1502 // --------------------------------------------------------------------
1504 IMPL_LINK_NOARG(UnoTreeListBoxImpl
, OnSelectionChangeHdl
)
1507 mxPeer
->onSelectionChanged();
1511 // --------------------------------------------------------------------
1513 IMPL_LINK_NOARG(UnoTreeListBoxImpl
, OnExpandingHdl
)
1515 UnoTreeListEntry
* pEntry
= dynamic_cast< UnoTreeListEntry
* >( GetHdlEntry() );
1517 if( pEntry
&& mxPeer
.is() )
1519 return mxPeer
->onExpanding( pEntry
->mxNode
, !IsExpanded( pEntry
) ) ? 1 : 0;
1524 // --------------------------------------------------------------------
1526 IMPL_LINK_NOARG(UnoTreeListBoxImpl
, OnExpandedHdl
)
1528 UnoTreeListEntry
* pEntry
= dynamic_cast< UnoTreeListEntry
* >( GetHdlEntry() );
1529 if( pEntry
&& mxPeer
.is() )
1531 mxPeer
->onExpanded( pEntry
->mxNode
, IsExpanded( pEntry
) );
1536 // --------------------------------------------------------------------
1538 sal_uInt32
UnoTreeListBoxImpl::insert( SvTreeListEntry
* pEntry
,SvTreeListEntry
* pParent
,sal_uLong nPos
)
1541 return SvTreeListBox::Insert( pEntry
, pParent
, nPos
);
1543 return SvTreeListBox::Insert( pEntry
, nPos
);
1546 // --------------------------------------------------------------------
1548 void UnoTreeListBoxImpl::RequestingChildren( SvTreeListEntry
* pParent
)
1550 UnoTreeListEntry
* pEntry
= dynamic_cast< UnoTreeListEntry
* >( pParent
);
1551 if( pEntry
&& pEntry
->mxNode
.is() && mxPeer
.is() )
1552 mxPeer
->onRequestChildNodes( pEntry
->mxNode
);
1555 // --------------------------------------------------------------------
1557 sal_Bool
UnoTreeListBoxImpl::EditingEntry( SvTreeListEntry
* pEntry
, Selection
& )
1559 return mxPeer
.is() ? mxPeer
->onEditingEntry( dynamic_cast< UnoTreeListEntry
* >( pEntry
) ) : false;
1562 // --------------------------------------------------------------------
1564 sal_Bool
UnoTreeListBoxImpl::EditedEntry( SvTreeListEntry
* pEntry
, const OUString
& rNewText
)
1566 return mxPeer
.is() ? mxPeer
->onEditedEntry( dynamic_cast< UnoTreeListEntry
* >( pEntry
), rNewText
) : false;
1569 // ====================================================================
1570 // class UnoTreeListItem
1571 // ====================================================================
1573 UnoTreeListItem::UnoTreeListItem( SvTreeListEntry
* pEntry
)
1574 : SvLBoxString(pEntry
, 0, OUString())
1578 // --------------------------------------------------------------------
1580 UnoTreeListItem::UnoTreeListItem()
1585 // --------------------------------------------------------------------
1587 UnoTreeListItem::~UnoTreeListItem()
1591 // --------------------------------------------------------------------
1593 void UnoTreeListItem::Paint(
1594 const Point
& rPos
, SvTreeListBox
& rDev
, const SvViewDataEntry
* /*pView*/, const SvTreeListEntry
* pEntry
)
1599 Size
aSize( GetSize(&rDev
, pEntry
) );
1602 rDev
.DrawImage( aPos
, maImage
, rDev
.IsEnabled() ? 0 : IMAGE_DRAW_DISABLE
);
1603 int nWidth
= maImage
.GetSizePixel().Width() + 6;
1605 aSize
.Width() -= nWidth
;
1607 rDev
.DrawText( Rectangle(aPos
,aSize
),maText
, rDev
.IsEnabled() ? 0 : TEXT_DRAW_DISABLE
);
1613 rDev
.DrawImage( aPos
, maImage
, rDev
.IsEnabled() ? 0 : IMAGE_DRAW_DISABLE
);
1614 aPos
.X() += maImage
.GetSizePixel().Width() + 6;
1616 rDev
.DrawText( aPos
, maText
);
1620 // --------------------------------------------------------------------
1622 SvLBoxItem
* UnoTreeListItem::Create() const
1624 return new UnoTreeListItem
;
1627 // --------------------------------------------------------------------
1629 void UnoTreeListItem::Clone( SvLBoxItem
* pSource
)
1631 UnoTreeListItem
* pSourceItem
= dynamic_cast< UnoTreeListItem
* >( pSource
);
1634 maText
= pSourceItem
->maText
;
1635 maImage
= pSourceItem
->maImage
;
1639 // --------------------------------------------------------------------
1641 void UnoTreeListItem::SetImage( const Image
& rImage
)
1646 // --------------------------------------------------------------------
1648 OUString
UnoTreeListItem::GetGraphicURL() const
1650 return maGraphicURL
;
1653 // --------------------------------------------------------------------
1655 void UnoTreeListItem::SetGraphicURL( const OUString
& rGraphicURL
)
1657 maGraphicURL
= rGraphicURL
;
1660 // --------------------------------------------------------------------
1662 void UnoTreeListItem::InitViewData( SvTreeListBox
* pView
,SvTreeListEntry
* pEntry
, SvViewDataItem
* pViewData
)
1665 pViewData
= pView
->GetViewDataItem( pEntry
, this );
1667 pViewData
->maSize
= maImage
.GetSizePixel();
1669 const Size
aTextSize(pView
->GetTextWidth( maText
), pView
->GetTextHeight());
1670 if( pViewData
->maSize
.Width() )
1672 pViewData
->maSize
.Width() += 6 + aTextSize
.Width();
1673 if( pViewData
->maSize
.Height() < aTextSize
.Height() )
1674 pViewData
->maSize
.Height() = aTextSize
.Height();
1678 pViewData
->maSize
= aTextSize
;
1682 // --------------------------------------------------------------------
1684 UnoTreeListEntry::UnoTreeListEntry( const Reference
< XTreeNode
>& xNode
, TreeControlPeer
* pPeer
)
1690 mpPeer
->addEntry( this );
1693 // --------------------------------------------------------------------
1695 UnoTreeListEntry::~UnoTreeListEntry()
1698 mpPeer
->removeEntry( this );
1701 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */