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