1*b0724fc6SAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*b0724fc6SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*b0724fc6SAndrew Rist * or more contributor license agreements. See the NOTICE file 5*b0724fc6SAndrew Rist * distributed with this work for additional information 6*b0724fc6SAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*b0724fc6SAndrew Rist * to you under the Apache License, Version 2.0 (the 8*b0724fc6SAndrew Rist * "License"); you may not use this file except in compliance 9*b0724fc6SAndrew Rist * with the License. You may obtain a copy of the License at 10cdf0e10cSrcweir * 11*b0724fc6SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12cdf0e10cSrcweir * 13*b0724fc6SAndrew Rist * Unless required by applicable law or agreed to in writing, 14*b0724fc6SAndrew Rist * software distributed under the License is distributed on an 15*b0724fc6SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*b0724fc6SAndrew Rist * KIND, either express or implied. See the License for the 17*b0724fc6SAndrew Rist * specific language governing permissions and limitations 18*b0724fc6SAndrew Rist * under the License. 19cdf0e10cSrcweir * 20*b0724fc6SAndrew Rist *************************************************************/ 21*b0724fc6SAndrew Rist 22*b0724fc6SAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 25cdf0e10cSrcweir #include "precompiled_toolkit.hxx" 26cdf0e10cSrcweir 27cdf0e10cSrcweir #ifndef _TOOLKIT_TREE_CONTROL_HXX 28cdf0e10cSrcweir #include <treecontrol.hxx> 29cdf0e10cSrcweir #endif 30cdf0e10cSrcweir 31cdf0e10cSrcweir #include <com/sun/star/lang/XMultiServiceFactory.hpp> 32cdf0e10cSrcweir #include <com/sun/star/view/SelectionType.hpp> 33cdf0e10cSrcweir #include <com/sun/star/awt/tree/XTreeDataModel.hpp> 34cdf0e10cSrcweir #include <toolkit/helper/unopropertyarrayhelper.hxx> 35cdf0e10cSrcweir #include <toolkit/helper/property.hxx> 36cdf0e10cSrcweir #include <com/sun/star/awt/XVclWindowPeer.hpp> 37cdf0e10cSrcweir #include <comphelper/processfactory.hxx> 38cdf0e10cSrcweir #include <osl/diagnose.h> 39cdf0e10cSrcweir 40cdf0e10cSrcweir using ::rtl::OUString; 41cdf0e10cSrcweir using namespace ::com::sun::star; 42cdf0e10cSrcweir using namespace ::com::sun::star::uno; 43cdf0e10cSrcweir using namespace ::com::sun::star::awt::tree; 44cdf0e10cSrcweir using namespace ::com::sun::star::lang; 45cdf0e10cSrcweir using namespace ::com::sun::star::beans; 46cdf0e10cSrcweir using namespace ::com::sun::star::container; 47cdf0e10cSrcweir using namespace ::com::sun::star::view; 48cdf0e10cSrcweir 49cdf0e10cSrcweir namespace toolkit 50cdf0e10cSrcweir { 51cdf0e10cSrcweir // ---------------------------------------------------- 52cdf0e10cSrcweir // class UnoTreeModel 53cdf0e10cSrcweir // ---------------------------------------------------- 54cdf0e10cSrcweir UnoTreeModel::UnoTreeModel( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& i_factory ) 55cdf0e10cSrcweir :UnoControlModel( i_factory ) 56cdf0e10cSrcweir { 57cdf0e10cSrcweir ImplRegisterProperty( BASEPROPERTY_BACKGROUNDCOLOR ); 58cdf0e10cSrcweir ImplRegisterProperty( BASEPROPERTY_BORDER ); 59cdf0e10cSrcweir ImplRegisterProperty( BASEPROPERTY_BORDERCOLOR ); 60cdf0e10cSrcweir ImplRegisterProperty( BASEPROPERTY_DEFAULTCONTROL ); 61cdf0e10cSrcweir ImplRegisterProperty( BASEPROPERTY_ENABLED ); 62cdf0e10cSrcweir ImplRegisterProperty( BASEPROPERTY_ENABLEVISIBLE ); 63cdf0e10cSrcweir ImplRegisterProperty( BASEPROPERTY_FILLCOLOR ); 64cdf0e10cSrcweir ImplRegisterProperty( BASEPROPERTY_HELPTEXT ); 65cdf0e10cSrcweir ImplRegisterProperty( BASEPROPERTY_HELPURL ); 66cdf0e10cSrcweir ImplRegisterProperty( BASEPROPERTY_PRINTABLE ); 67cdf0e10cSrcweir ImplRegisterProperty( BASEPROPERTY_TABSTOP ); 68cdf0e10cSrcweir ImplRegisterProperty( BASEPROPERTY_TREE_SELECTIONTYPE ); 69cdf0e10cSrcweir ImplRegisterProperty( BASEPROPERTY_TREE_EDITABLE ); 70cdf0e10cSrcweir ImplRegisterProperty( BASEPROPERTY_TREE_DATAMODEL ); 71cdf0e10cSrcweir ImplRegisterProperty( BASEPROPERTY_TREE_ROOTDISPLAYED ); 72cdf0e10cSrcweir ImplRegisterProperty( BASEPROPERTY_TREE_SHOWSHANDLES ); 73cdf0e10cSrcweir ImplRegisterProperty( BASEPROPERTY_TREE_SHOWSROOTHANDLES ); 74cdf0e10cSrcweir ImplRegisterProperty( BASEPROPERTY_ROW_HEIGHT ); 75cdf0e10cSrcweir ImplRegisterProperty( BASEPROPERTY_TREE_INVOKESSTOPNODEEDITING ); 76cdf0e10cSrcweir ImplRegisterProperty( BASEPROPERTY_HIDEINACTIVESELECTION ); 77cdf0e10cSrcweir } 78cdf0e10cSrcweir 79cdf0e10cSrcweir UnoTreeModel::UnoTreeModel( const UnoTreeModel& rModel ) 80cdf0e10cSrcweir : UnoControlModel( rModel ) 81cdf0e10cSrcweir { 82cdf0e10cSrcweir } 83cdf0e10cSrcweir 84cdf0e10cSrcweir UnoControlModel* UnoTreeModel::Clone() const 85cdf0e10cSrcweir { 86cdf0e10cSrcweir return new UnoTreeModel( *this ); 87cdf0e10cSrcweir } 88cdf0e10cSrcweir 89cdf0e10cSrcweir OUString UnoTreeModel::getServiceName() throw(RuntimeException) 90cdf0e10cSrcweir { 91cdf0e10cSrcweir return OUString::createFromAscii( szServiceName_TreeControlModel ); 92cdf0e10cSrcweir } 93cdf0e10cSrcweir 94cdf0e10cSrcweir Any UnoTreeModel::ImplGetDefaultValue( sal_uInt16 nPropId ) const 95cdf0e10cSrcweir { 96cdf0e10cSrcweir switch( nPropId ) 97cdf0e10cSrcweir { 98cdf0e10cSrcweir case BASEPROPERTY_TREE_SELECTIONTYPE: 99cdf0e10cSrcweir return Any( SelectionType_NONE ); 100cdf0e10cSrcweir case BASEPROPERTY_ROW_HEIGHT: 101cdf0e10cSrcweir return Any( sal_Int32( 0 ) ); 102cdf0e10cSrcweir case BASEPROPERTY_TREE_DATAMODEL: 103cdf0e10cSrcweir return Any( Reference< XTreeDataModel >( 0 ) ); 104cdf0e10cSrcweir case BASEPROPERTY_TREE_EDITABLE: 105cdf0e10cSrcweir case BASEPROPERTY_TREE_INVOKESSTOPNODEEDITING: 106cdf0e10cSrcweir return Any( sal_False ); 107cdf0e10cSrcweir case BASEPROPERTY_TREE_ROOTDISPLAYED: 108cdf0e10cSrcweir case BASEPROPERTY_TREE_SHOWSROOTHANDLES: 109cdf0e10cSrcweir case BASEPROPERTY_TREE_SHOWSHANDLES: 110cdf0e10cSrcweir return Any( sal_True ); 111cdf0e10cSrcweir case BASEPROPERTY_DEFAULTCONTROL: 112cdf0e10cSrcweir return uno::makeAny( ::rtl::OUString::createFromAscii( szServiceName_TreeControl ) ); 113cdf0e10cSrcweir default: 114cdf0e10cSrcweir return UnoControlModel::ImplGetDefaultValue( nPropId ); 115cdf0e10cSrcweir } 116cdf0e10cSrcweir } 117cdf0e10cSrcweir 118cdf0e10cSrcweir ::cppu::IPropertyArrayHelper& UnoTreeModel::getInfoHelper() 119cdf0e10cSrcweir { 120cdf0e10cSrcweir static UnoPropertyArrayHelper* pHelper = NULL; 121cdf0e10cSrcweir if ( !pHelper ) 122cdf0e10cSrcweir { 123cdf0e10cSrcweir Sequence<sal_Int32> aIDs = ImplGetPropertyIds(); 124cdf0e10cSrcweir pHelper = new UnoPropertyArrayHelper( aIDs ); 125cdf0e10cSrcweir } 126cdf0e10cSrcweir return *pHelper; 127cdf0e10cSrcweir } 128cdf0e10cSrcweir 129cdf0e10cSrcweir // XMultiPropertySet 130cdf0e10cSrcweir Reference< XPropertySetInfo > UnoTreeModel::getPropertySetInfo( ) throw(RuntimeException) 131cdf0e10cSrcweir { 132cdf0e10cSrcweir static Reference< XPropertySetInfo > xInfo( createPropertySetInfo( getInfoHelper() ) ); 133cdf0e10cSrcweir return xInfo; 134cdf0e10cSrcweir } 135cdf0e10cSrcweir 136cdf0e10cSrcweir 137cdf0e10cSrcweir // ---------------------------------------------------- 138cdf0e10cSrcweir // class UnoTreeControl 139cdf0e10cSrcweir // ---------------------------------------------------- 140cdf0e10cSrcweir UnoTreeControl::UnoTreeControl( const Reference< XMultiServiceFactory >& i_factory ) 141cdf0e10cSrcweir : UnoTreeControl_Base( i_factory ) 142cdf0e10cSrcweir , maSelectionListeners( *this ) 143cdf0e10cSrcweir , maTreeExpansionListeners( *this ) 144cdf0e10cSrcweir , maTreeEditListeners( *this ) 145cdf0e10cSrcweir { 146cdf0e10cSrcweir } 147cdf0e10cSrcweir 148cdf0e10cSrcweir OUString UnoTreeControl::GetComponentServiceName() 149cdf0e10cSrcweir { 150cdf0e10cSrcweir return OUString::createFromAscii( "Tree" ); 151cdf0e10cSrcweir } 152cdf0e10cSrcweir 153cdf0e10cSrcweir // ------------------------------------------------------------------- 154cdf0e10cSrcweir // ::com::sun::star::view::XSelectionSupplier 155cdf0e10cSrcweir // ------------------------------------------------------------------- 156cdf0e10cSrcweir 157cdf0e10cSrcweir sal_Bool SAL_CALL UnoTreeControl::select( const Any& rSelection ) throw (IllegalArgumentException, RuntimeException) 158cdf0e10cSrcweir { 159cdf0e10cSrcweir return Reference< XTreeControl >( getPeer(), UNO_QUERY_THROW )->select( rSelection ); 160cdf0e10cSrcweir } 161cdf0e10cSrcweir 162cdf0e10cSrcweir // ------------------------------------------------------------------- 163cdf0e10cSrcweir 164cdf0e10cSrcweir Any SAL_CALL UnoTreeControl::getSelection() throw (RuntimeException) 165cdf0e10cSrcweir { 166cdf0e10cSrcweir return Reference< XTreeControl >( getPeer(), UNO_QUERY_THROW )->getSelection(); 167cdf0e10cSrcweir } 168cdf0e10cSrcweir 169cdf0e10cSrcweir // ------------------------------------------------------------------- 170cdf0e10cSrcweir 171cdf0e10cSrcweir void SAL_CALL UnoTreeControl::addSelectionChangeListener( const Reference< XSelectionChangeListener >& xListener ) throw (RuntimeException) 172cdf0e10cSrcweir { 173cdf0e10cSrcweir maSelectionListeners.addInterface( xListener ); 174cdf0e10cSrcweir if( getPeer().is() && (maSelectionListeners.getLength() == 1) ) 175cdf0e10cSrcweir { 176cdf0e10cSrcweir // maSelectionListeners acts as a proxy, 177cdf0e10cSrcweir // add it to the peer if this is the first listener added to that proxy 178cdf0e10cSrcweir Reference< XWindowPeer > xGcc3WorkaroundTemporary( getPeer()); 179cdf0e10cSrcweir Reference< XTreeControl >( xGcc3WorkaroundTemporary, UNO_QUERY_THROW )->addSelectionChangeListener(&maSelectionListeners); 180cdf0e10cSrcweir } 181cdf0e10cSrcweir } 182cdf0e10cSrcweir 183cdf0e10cSrcweir // ------------------------------------------------------------------- 184cdf0e10cSrcweir 185cdf0e10cSrcweir void SAL_CALL UnoTreeControl::removeSelectionChangeListener( const Reference< XSelectionChangeListener >& xListener ) throw (RuntimeException) 186cdf0e10cSrcweir { 187cdf0e10cSrcweir if( getPeer().is() && (maSelectionListeners.getLength() == 1) ) 188cdf0e10cSrcweir { 189cdf0e10cSrcweir // maSelectionListeners acts as a proxy, 190cdf0e10cSrcweir // remove it from the peer if this is the last listener removed from that proxy 191cdf0e10cSrcweir Reference< XWindowPeer > xGcc3WorkaroundTemporary( getPeer()); 192cdf0e10cSrcweir Reference< XTreeControl >( xGcc3WorkaroundTemporary, UNO_QUERY_THROW )->removeSelectionChangeListener(&maSelectionListeners); 193cdf0e10cSrcweir } 194cdf0e10cSrcweir maSelectionListeners.removeInterface( xListener ); 195cdf0e10cSrcweir } 196cdf0e10cSrcweir 197cdf0e10cSrcweir // ------------------------------------------------------------------- 198cdf0e10cSrcweir // ::com::sun::star::view::XMultiSelectionSupplier 199cdf0e10cSrcweir // ------------------------------------------------------------------- 200cdf0e10cSrcweir 201cdf0e10cSrcweir sal_Bool SAL_CALL UnoTreeControl::addSelection( const Any& rSelection ) throw (IllegalArgumentException, RuntimeException) 202cdf0e10cSrcweir { 203cdf0e10cSrcweir return Reference< XTreeControl >( getPeer(), UNO_QUERY_THROW )->addSelection(rSelection); 204cdf0e10cSrcweir } 205cdf0e10cSrcweir 206cdf0e10cSrcweir // ------------------------------------------------------------------- 207cdf0e10cSrcweir 208cdf0e10cSrcweir void SAL_CALL UnoTreeControl::removeSelection( const Any& rSelection ) throw (IllegalArgumentException, RuntimeException) 209cdf0e10cSrcweir { 210cdf0e10cSrcweir Reference< XWindowPeer > xGcc3WorkaroundTemporary( getPeer()); 211cdf0e10cSrcweir Reference< XTreeControl >( xGcc3WorkaroundTemporary, UNO_QUERY_THROW )->removeSelection(rSelection); 212cdf0e10cSrcweir } 213cdf0e10cSrcweir 214cdf0e10cSrcweir // ------------------------------------------------------------------- 215cdf0e10cSrcweir 216cdf0e10cSrcweir void SAL_CALL UnoTreeControl::clearSelection() throw (RuntimeException) 217cdf0e10cSrcweir { 218cdf0e10cSrcweir Reference< XWindowPeer > xGcc3WorkaroundTemporary( getPeer()); 219cdf0e10cSrcweir Reference< XTreeControl >( xGcc3WorkaroundTemporary, UNO_QUERY_THROW )->clearSelection(); 220cdf0e10cSrcweir } 221cdf0e10cSrcweir 222cdf0e10cSrcweir // ------------------------------------------------------------------- 223cdf0e10cSrcweir 224cdf0e10cSrcweir sal_Int32 SAL_CALL UnoTreeControl::getSelectionCount() throw (RuntimeException) 225cdf0e10cSrcweir { 226cdf0e10cSrcweir return Reference< XTreeControl >( getPeer(), UNO_QUERY_THROW )->getSelectionCount(); 227cdf0e10cSrcweir } 228cdf0e10cSrcweir 229cdf0e10cSrcweir // ------------------------------------------------------------------- 230cdf0e10cSrcweir 231cdf0e10cSrcweir Reference< XEnumeration > SAL_CALL UnoTreeControl::createSelectionEnumeration() throw (RuntimeException) 232cdf0e10cSrcweir { 233cdf0e10cSrcweir return Reference< XTreeControl >( getPeer(), UNO_QUERY_THROW )->createSelectionEnumeration(); 234cdf0e10cSrcweir } 235cdf0e10cSrcweir 236cdf0e10cSrcweir // ------------------------------------------------------------------- 237cdf0e10cSrcweir 238cdf0e10cSrcweir Reference< XEnumeration > SAL_CALL UnoTreeControl::createReverseSelectionEnumeration() throw (RuntimeException) 239cdf0e10cSrcweir { 240cdf0e10cSrcweir return Reference< XTreeControl >( getPeer(), UNO_QUERY_THROW )->createReverseSelectionEnumeration(); 241cdf0e10cSrcweir } 242cdf0e10cSrcweir 243cdf0e10cSrcweir // -------------------------------------------------------------------- 244cdf0e10cSrcweir // XTreeControl 245cdf0e10cSrcweir // -------------------------------------------------------------------- 246cdf0e10cSrcweir 247cdf0e10cSrcweir OUString SAL_CALL UnoTreeControl::getDefaultExpandedGraphicURL() throw (RuntimeException) 248cdf0e10cSrcweir { 249cdf0e10cSrcweir return Reference< XTreeControl >( getPeer(), UNO_QUERY_THROW )->getDefaultExpandedGraphicURL(); 250cdf0e10cSrcweir } 251cdf0e10cSrcweir 252cdf0e10cSrcweir // ------------------------------------------------------------------- 253cdf0e10cSrcweir 254cdf0e10cSrcweir void SAL_CALL UnoTreeControl::setDefaultExpandedGraphicURL( const OUString& _defaultexpansiongraphicurl ) throw (RuntimeException) 255cdf0e10cSrcweir { 256cdf0e10cSrcweir Reference< XWindowPeer > xGcc3WorkaroundTemporary( getPeer()); 257cdf0e10cSrcweir Reference< XTreeControl >( xGcc3WorkaroundTemporary, UNO_QUERY_THROW )->setDefaultExpandedGraphicURL(_defaultexpansiongraphicurl); 258cdf0e10cSrcweir } 259cdf0e10cSrcweir 260cdf0e10cSrcweir // ------------------------------------------------------------------- 261cdf0e10cSrcweir 262cdf0e10cSrcweir OUString SAL_CALL UnoTreeControl::getDefaultCollapsedGraphicURL() throw (RuntimeException) 263cdf0e10cSrcweir { 264cdf0e10cSrcweir return Reference< XTreeControl >( getPeer(), UNO_QUERY_THROW )->getDefaultCollapsedGraphicURL(); 265cdf0e10cSrcweir } 266cdf0e10cSrcweir 267cdf0e10cSrcweir // ------------------------------------------------------------------- 268cdf0e10cSrcweir 269cdf0e10cSrcweir void SAL_CALL UnoTreeControl::setDefaultCollapsedGraphicURL( const OUString& _defaultcollapsedgraphicurl ) throw (RuntimeException) 270cdf0e10cSrcweir { 271cdf0e10cSrcweir Reference< XWindowPeer > xGcc3WorkaroundTemporary( getPeer()); 272cdf0e10cSrcweir Reference< XTreeControl >( xGcc3WorkaroundTemporary, UNO_QUERY_THROW )->setDefaultCollapsedGraphicURL(_defaultcollapsedgraphicurl); 273cdf0e10cSrcweir } 274cdf0e10cSrcweir 275cdf0e10cSrcweir // ------------------------------------------------------------------- 276cdf0e10cSrcweir 277cdf0e10cSrcweir sal_Bool SAL_CALL UnoTreeControl::isNodeExpanded( const Reference< XTreeNode >& xNode ) throw (RuntimeException, IllegalArgumentException) 278cdf0e10cSrcweir { 279cdf0e10cSrcweir return Reference< XTreeControl >( getPeer(), UNO_QUERY_THROW )->isNodeExpanded(xNode); 280cdf0e10cSrcweir } 281cdf0e10cSrcweir 282cdf0e10cSrcweir // ------------------------------------------------------------------- 283cdf0e10cSrcweir 284cdf0e10cSrcweir sal_Bool SAL_CALL UnoTreeControl::isNodeCollapsed( const Reference< XTreeNode >& xNode ) throw (RuntimeException, IllegalArgumentException) 285cdf0e10cSrcweir { 286cdf0e10cSrcweir return Reference< XTreeControl >( getPeer(), UNO_QUERY_THROW )->isNodeCollapsed(xNode); 287cdf0e10cSrcweir } 288cdf0e10cSrcweir 289cdf0e10cSrcweir // ------------------------------------------------------------------- 290cdf0e10cSrcweir 291cdf0e10cSrcweir void SAL_CALL UnoTreeControl::makeNodeVisible( const Reference< XTreeNode >& xNode ) throw (RuntimeException, ExpandVetoException, IllegalArgumentException) 292cdf0e10cSrcweir { 293cdf0e10cSrcweir Reference< XWindowPeer > xGcc3WorkaroundTemporary( getPeer()); 294cdf0e10cSrcweir Reference< XTreeControl >( xGcc3WorkaroundTemporary, UNO_QUERY_THROW )->makeNodeVisible(xNode); 295cdf0e10cSrcweir } 296cdf0e10cSrcweir 297cdf0e10cSrcweir // ------------------------------------------------------------------- 298cdf0e10cSrcweir 299cdf0e10cSrcweir sal_Bool SAL_CALL UnoTreeControl::isNodeVisible( const Reference< XTreeNode >& xNode ) throw (RuntimeException, IllegalArgumentException) 300cdf0e10cSrcweir { 301cdf0e10cSrcweir return Reference< XTreeControl >( getPeer(), UNO_QUERY_THROW )->isNodeVisible(xNode); 302cdf0e10cSrcweir } 303cdf0e10cSrcweir 304cdf0e10cSrcweir // ------------------------------------------------------------------- 305cdf0e10cSrcweir 306cdf0e10cSrcweir void SAL_CALL UnoTreeControl::expandNode( const Reference< XTreeNode >& xNode ) throw (RuntimeException, ExpandVetoException, IllegalArgumentException) 307cdf0e10cSrcweir { 308cdf0e10cSrcweir Reference< XWindowPeer > xGcc3WorkaroundTemporary( getPeer()); 309cdf0e10cSrcweir Reference< XTreeControl >( xGcc3WorkaroundTemporary, UNO_QUERY_THROW )->expandNode(xNode); 310cdf0e10cSrcweir } 311cdf0e10cSrcweir 312cdf0e10cSrcweir // ------------------------------------------------------------------- 313cdf0e10cSrcweir 314cdf0e10cSrcweir void SAL_CALL UnoTreeControl::collapseNode( const Reference< XTreeNode >& xNode ) throw (RuntimeException, ExpandVetoException, IllegalArgumentException) 315cdf0e10cSrcweir { 316cdf0e10cSrcweir Reference< XWindowPeer > xGcc3WorkaroundTemporary( getPeer()); 317cdf0e10cSrcweir Reference< XTreeControl >( xGcc3WorkaroundTemporary, UNO_QUERY_THROW )->collapseNode(xNode); 318cdf0e10cSrcweir } 319cdf0e10cSrcweir 320cdf0e10cSrcweir // ------------------------------------------------------------------- 321cdf0e10cSrcweir 322cdf0e10cSrcweir void SAL_CALL UnoTreeControl::addTreeExpansionListener( const Reference< XTreeExpansionListener >& xListener ) throw (RuntimeException) 323cdf0e10cSrcweir { 324cdf0e10cSrcweir maTreeExpansionListeners.addInterface( xListener ); 325cdf0e10cSrcweir if( getPeer().is() && (maTreeExpansionListeners.getLength() == 1) ) 326cdf0e10cSrcweir { 327cdf0e10cSrcweir // maSelectionListeners acts as a proxy, 328cdf0e10cSrcweir // add it to the peer if this is the first listener added to that proxy 329cdf0e10cSrcweir Reference< XWindowPeer > xGcc3WorkaroundTemporary( getPeer()); 330cdf0e10cSrcweir Reference< XTreeControl >( xGcc3WorkaroundTemporary, UNO_QUERY_THROW )->addTreeExpansionListener(&maTreeExpansionListeners); 331cdf0e10cSrcweir } 332cdf0e10cSrcweir } 333cdf0e10cSrcweir 334cdf0e10cSrcweir // ------------------------------------------------------------------- 335cdf0e10cSrcweir 336cdf0e10cSrcweir void SAL_CALL UnoTreeControl::removeTreeExpansionListener( const Reference< XTreeExpansionListener >& xListener ) throw (RuntimeException) 337cdf0e10cSrcweir { 338cdf0e10cSrcweir if( getPeer().is() && (maTreeExpansionListeners.getLength() == 1) ) 339cdf0e10cSrcweir { 340cdf0e10cSrcweir // maSelectionListeners acts as a proxy, 341cdf0e10cSrcweir // remove it from the peer if this is the last listener removed from that proxy 342cdf0e10cSrcweir Reference< XWindowPeer > xGcc3WorkaroundTemporary( getPeer()); 343cdf0e10cSrcweir Reference< XTreeControl >( xGcc3WorkaroundTemporary, UNO_QUERY_THROW )->removeTreeExpansionListener(&maTreeExpansionListeners); 344cdf0e10cSrcweir } 345cdf0e10cSrcweir maTreeExpansionListeners.removeInterface( xListener ); 346cdf0e10cSrcweir } 347cdf0e10cSrcweir 348cdf0e10cSrcweir // ------------------------------------------------------------------- 349cdf0e10cSrcweir 350cdf0e10cSrcweir Reference< XTreeNode > SAL_CALL UnoTreeControl::getNodeForLocation( sal_Int32 x, sal_Int32 y ) throw (RuntimeException) 351cdf0e10cSrcweir { 352cdf0e10cSrcweir return Reference< XTreeControl >( getPeer(), UNO_QUERY_THROW )->getNodeForLocation(x,y); 353cdf0e10cSrcweir } 354cdf0e10cSrcweir 355cdf0e10cSrcweir // ------------------------------------------------------------------- 356cdf0e10cSrcweir 357cdf0e10cSrcweir Reference< XTreeNode > SAL_CALL UnoTreeControl::getClosestNodeForLocation( sal_Int32 x, sal_Int32 y ) throw (RuntimeException) 358cdf0e10cSrcweir { 359cdf0e10cSrcweir return Reference< XTreeControl >( getPeer(), UNO_QUERY_THROW )->getClosestNodeForLocation(x,y); 360cdf0e10cSrcweir } 361cdf0e10cSrcweir 362cdf0e10cSrcweir // ------------------------------------------------------------------- 363cdf0e10cSrcweir 364cdf0e10cSrcweir awt::Rectangle SAL_CALL UnoTreeControl::getNodeRect( const Reference< XTreeNode >& Node ) throw (IllegalArgumentException, RuntimeException) 365cdf0e10cSrcweir { 366cdf0e10cSrcweir return Reference< XTreeControl >( getPeer(), UNO_QUERY_THROW )->getNodeRect( Node ); 367cdf0e10cSrcweir } 368cdf0e10cSrcweir 369cdf0e10cSrcweir // ------------------------------------------------------------------- 370cdf0e10cSrcweir 371cdf0e10cSrcweir sal_Bool SAL_CALL UnoTreeControl::isEditing( ) throw (RuntimeException) 372cdf0e10cSrcweir { 373cdf0e10cSrcweir return Reference< XTreeControl >( getPeer(), UNO_QUERY_THROW )->isEditing(); 374cdf0e10cSrcweir } 375cdf0e10cSrcweir 376cdf0e10cSrcweir // ------------------------------------------------------------------- 377cdf0e10cSrcweir 378cdf0e10cSrcweir sal_Bool SAL_CALL UnoTreeControl::stopEditing() throw (RuntimeException) 379cdf0e10cSrcweir { 380cdf0e10cSrcweir return Reference< XTreeControl >( getPeer(), UNO_QUERY_THROW )->stopEditing(); 381cdf0e10cSrcweir } 382cdf0e10cSrcweir 383cdf0e10cSrcweir // ------------------------------------------------------------------- 384cdf0e10cSrcweir 385cdf0e10cSrcweir void SAL_CALL UnoTreeControl::cancelEditing() throw (RuntimeException) 386cdf0e10cSrcweir { 387cdf0e10cSrcweir Reference< XWindowPeer > xGcc3WorkaroundTemporary( getPeer()); 388cdf0e10cSrcweir Reference< XTreeControl >( xGcc3WorkaroundTemporary, UNO_QUERY_THROW )->cancelEditing(); 389cdf0e10cSrcweir } 390cdf0e10cSrcweir 391cdf0e10cSrcweir // ------------------------------------------------------------------- 392cdf0e10cSrcweir 393cdf0e10cSrcweir void SAL_CALL UnoTreeControl::startEditingAtNode( const Reference< XTreeNode >& xNode ) throw (IllegalArgumentException, RuntimeException) 394cdf0e10cSrcweir { 395cdf0e10cSrcweir Reference< XWindowPeer > xGcc3WorkaroundTemporary( getPeer()); 396cdf0e10cSrcweir Reference< XTreeControl >( xGcc3WorkaroundTemporary, UNO_QUERY_THROW )->startEditingAtNode(xNode); 397cdf0e10cSrcweir } 398cdf0e10cSrcweir 399cdf0e10cSrcweir // ------------------------------------------------------------------- 400cdf0e10cSrcweir 401cdf0e10cSrcweir void SAL_CALL UnoTreeControl::addTreeEditListener( const Reference< XTreeEditListener >& xListener ) throw (RuntimeException) 402cdf0e10cSrcweir { 403cdf0e10cSrcweir maTreeEditListeners.addInterface( xListener ); 404cdf0e10cSrcweir if( getPeer().is() && (maTreeEditListeners.getLength() == 1) ) 405cdf0e10cSrcweir { 406cdf0e10cSrcweir // maSelectionListeners acts as a proxy, 407cdf0e10cSrcweir // add it to the peer if this is the first listener added to that proxy 408cdf0e10cSrcweir Reference< XWindowPeer > xGcc3WorkaroundTemporary( getPeer()); 409cdf0e10cSrcweir Reference< XTreeControl >( xGcc3WorkaroundTemporary, UNO_QUERY_THROW )->addTreeEditListener(&maTreeEditListeners); 410cdf0e10cSrcweir } 411cdf0e10cSrcweir } 412cdf0e10cSrcweir 413cdf0e10cSrcweir // ------------------------------------------------------------------- 414cdf0e10cSrcweir 415cdf0e10cSrcweir void SAL_CALL UnoTreeControl::removeTreeEditListener( const Reference< XTreeEditListener >& xListener ) throw (RuntimeException) 416cdf0e10cSrcweir { 417cdf0e10cSrcweir if( getPeer().is() && (maTreeEditListeners.getLength() == 1) ) 418cdf0e10cSrcweir { 419cdf0e10cSrcweir // maSelectionListeners acts as a proxy, 420cdf0e10cSrcweir // remove it from the peer if this is the last listener removed from that proxy 421cdf0e10cSrcweir Reference< XWindowPeer > xGcc3WorkaroundTemporary( getPeer()); 422cdf0e10cSrcweir Reference< XTreeControl >( xGcc3WorkaroundTemporary, UNO_QUERY_THROW )->removeTreeEditListener(&maTreeEditListeners); 423cdf0e10cSrcweir } 424cdf0e10cSrcweir maTreeEditListeners.removeInterface( xListener ); 425cdf0e10cSrcweir } 426cdf0e10cSrcweir 427cdf0e10cSrcweir // ------------------------------------------------------------------- 428cdf0e10cSrcweir // XComponent 429cdf0e10cSrcweir // ------------------------------------------------------------------- 430cdf0e10cSrcweir 431cdf0e10cSrcweir void SAL_CALL UnoTreeControl::dispose( ) throw(RuntimeException) 432cdf0e10cSrcweir { 433cdf0e10cSrcweir lang::EventObject aEvt; 434cdf0e10cSrcweir aEvt.Source = static_cast< ::cppu::OWeakObject* >(this); 435cdf0e10cSrcweir maSelectionListeners.disposeAndClear( aEvt ); 436cdf0e10cSrcweir maTreeExpansionListeners.disposeAndClear( aEvt ); 437cdf0e10cSrcweir UnoControl::dispose(); 438cdf0e10cSrcweir } 439cdf0e10cSrcweir 440cdf0e10cSrcweir void UnoTreeControl::createPeer( const uno::Reference< awt::XToolkit > & rxToolkit, const uno::Reference< awt::XWindowPeer > & rParentPeer ) throw(uno::RuntimeException) 441cdf0e10cSrcweir { 442cdf0e10cSrcweir UnoControlBase::createPeer( rxToolkit, rParentPeer ); 443cdf0e10cSrcweir 444cdf0e10cSrcweir Reference< XTreeControl > xTree( getPeer(), UNO_QUERY_THROW ); 445cdf0e10cSrcweir if( maSelectionListeners.getLength() ) 446cdf0e10cSrcweir xTree->addSelectionChangeListener( &maSelectionListeners ); 447cdf0e10cSrcweir if( maTreeExpansionListeners.getLength() ) 448cdf0e10cSrcweir xTree->addTreeExpansionListener( &maTreeExpansionListeners ); 449cdf0e10cSrcweir } 450cdf0e10cSrcweir 451cdf0e10cSrcweir } 452cdf0e10cSrcweir 453cdf0e10cSrcweir Reference< XInterface > SAL_CALL TreeControl_CreateInstance( const Reference< XMultiServiceFactory >& i_factory ) 454cdf0e10cSrcweir { 455cdf0e10cSrcweir return Reference < XInterface >( ( ::cppu::OWeakObject* ) new ::toolkit::UnoTreeControl( i_factory ) ); 456cdf0e10cSrcweir } 457cdf0e10cSrcweir 458cdf0e10cSrcweir Reference< XInterface > SAL_CALL TreeControlModel_CreateInstance( const Reference< XMultiServiceFactory >& i_factory ) 459cdf0e10cSrcweir { 460cdf0e10cSrcweir return Reference < XInterface >( ( ::cppu::OWeakObject* ) new ::toolkit::UnoTreeModel( i_factory ) ); 461cdf0e10cSrcweir } 462cdf0e10cSrcweir 463cdf0e10cSrcweir void SAL_CALL TreeEditListenerMultiplexer::nodeEditing( const Reference< XTreeNode >& Node ) throw (RuntimeException, ::com::sun::star::util::VetoException) 464cdf0e10cSrcweir { 465cdf0e10cSrcweir ::cppu::OInterfaceIteratorHelper aIt( *this ); 466cdf0e10cSrcweir while( aIt.hasMoreElements() ) 467cdf0e10cSrcweir { 468cdf0e10cSrcweir Reference< XTreeEditListener > xListener(static_cast< XTreeEditListener* >( aIt.next() ) ); 469cdf0e10cSrcweir try 470cdf0e10cSrcweir { 471cdf0e10cSrcweir xListener->nodeEditing( Node ); 472cdf0e10cSrcweir } 473cdf0e10cSrcweir catch( DisposedException& e ) 474cdf0e10cSrcweir { 475cdf0e10cSrcweir OSL_ENSURE( e.Context.is(), "caught DisposedException with empty Context field" ); 476cdf0e10cSrcweir if ( e.Context == xListener || !e.Context.is() ) 477cdf0e10cSrcweir aIt.remove(); 478cdf0e10cSrcweir } 479cdf0e10cSrcweir catch( RuntimeException& e ) 480cdf0e10cSrcweir { 481cdf0e10cSrcweir (void)e; 482cdf0e10cSrcweir DISPLAY_EXCEPTION( TreeEditListenerMultiplexer, nodeEditing, e ) 483cdf0e10cSrcweir } 484cdf0e10cSrcweir } 485cdf0e10cSrcweir } 486cdf0e10cSrcweir 487cdf0e10cSrcweir void SAL_CALL TreeEditListenerMultiplexer::nodeEdited( const Reference< XTreeNode >& Node, const OUString& NewText ) throw (RuntimeException) 488cdf0e10cSrcweir { 489cdf0e10cSrcweir ::cppu::OInterfaceIteratorHelper aIt( *this ); 490cdf0e10cSrcweir while( aIt.hasMoreElements() ) 491cdf0e10cSrcweir { 492cdf0e10cSrcweir Reference< XTreeEditListener > xListener( static_cast< XTreeEditListener* >( aIt.next() ) ); 493cdf0e10cSrcweir try 494cdf0e10cSrcweir { 495cdf0e10cSrcweir xListener->nodeEdited( Node, NewText ); 496cdf0e10cSrcweir } 497cdf0e10cSrcweir catch( DisposedException& e ) 498cdf0e10cSrcweir { 499cdf0e10cSrcweir OSL_ENSURE( e.Context.is(), "caught DisposedException with empty Context field" ); 500cdf0e10cSrcweir if ( e.Context == xListener || !e.Context.is() ) 501cdf0e10cSrcweir aIt.remove(); 502cdf0e10cSrcweir } 503cdf0e10cSrcweir catch( RuntimeException& e ) 504cdf0e10cSrcweir { 505cdf0e10cSrcweir (void)e; 506cdf0e10cSrcweir DISPLAY_EXCEPTION( TreeEditListenerMultiplexer, nodeEdited, e ) 507cdf0e10cSrcweir } 508cdf0e10cSrcweir } 509cdf0e10cSrcweir } 510