Difference between revisions of "Treecontrol"

From Apache OpenOffice Wiki
Jump to: navigation, search
Line 27: Line 27:
  
 
// set the default model at the tree control model
 
// set the default model at the tree control model
xTreeControlModel->setModel( xDefaultTreeModel );
+
xTreeControlModel->setTreeModel( xDefaultTreeModel );
 +
</pre>
 +
 
 +
=== The tree cell renderer ===
 +
 
 +
The DefaultTreeCellRenderer renders the following values:
 +
 
 +
# OUString
 +
# sal_Int32, sal_Int16, double, sal_Bool
 +
# ::com::sun::star::awt::XBitmap
 +
# ::com::sun::star::graphics::XGraphic
 +
# ::com::sun::star::awt::XControlModel
 +
# Sequence< T > where T is one of the supported types
 +
 
 +
==== Using the DefaultTreeCellRenderer ====
 +
 
 +
<pre>
 +
#define O(x) ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( x ) )
 +
 
 +
Reference< ComponentContext > xCC(...);
 +
Reference< XTreeControlModel > xTreeControlModel(...);
 +
 
 +
// create the default tree cell renderer and tell him to use images before nodes
 +
Reference< XDefaultTreeCellRenderer > xDefaultRenderer( DefaultTreeCellRenderer::create( xCC ) );
 +
xDefaultRenderer->setExpandedImageURL( O( "expand.png" ) );
 +
xDefaultRenderer->setCollapsedImageURL( O( "collapsed.png" ) );
 +
xDefaultRenderer->setLeafNodeImageURL( O( "leaf.png" ) );
 +
 
 +
// set the default cell renderer at the tree control model
 +
xTreeControlModel->setCellRenderer( Reference< XTreeCellRenderer >( xDefaultTreeModel, UNO_QUERY ) );
 +
</pre>

Revision as of 15:29, 7 September 2006

API Preview: file://x|/cl/awt/com/sun/star/awt/tree/module-ix.html

The Tree Model

The tree control needs a tree model that stores the model information of the entries in the tree. You can provide your own mode which must at least support the interface com.sun.star.awt.XTreeModel. Or you can use the service DefaultTreeModel which manages a hirarchie of MutableTreeModels.

Using the DefaultTreeModel

#define O(x) ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( x ) )

Reference< ComponentContext > xCC(...);
Reference< XTreeControlModel > xTreeControlModel(...);

// create the root node with the text value "root node text"

Reference< XMutableTreeNode > xRootNode( MutableTreeNode::create2( xCC, Any( O( "root node text" ) ) ) );

// add two child nodes with text
xRootNode.appendChild( MutableTreeNode::create2( xCC, Any( O( "child 1" ) ) ) );
xRootNode.appendChild( MutableTreeNode::create2( xCC, Any( O( "child 2" ) ) ) );

// create the default tree model with the root node
Reference< XTreeModel > xDefaultTreeModel( DefaultTreeModel::create2( xCC, xRootNode ), UNO_QUERY );

// set the default model at the tree control model
xTreeControlModel->setTreeModel( xDefaultTreeModel );

The tree cell renderer

The DefaultTreeCellRenderer renders the following values:

  1. OUString
  2. sal_Int32, sal_Int16, double, sal_Bool
  3.  ::com::sun::star::awt::XBitmap
  4.  ::com::sun::star::graphics::XGraphic
  5.  ::com::sun::star::awt::XControlModel
  6. Sequence< T > where T is one of the supported types

Using the DefaultTreeCellRenderer

#define O(x) ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( x ) )

Reference< ComponentContext > xCC(...);
Reference< XTreeControlModel > xTreeControlModel(...);

// create the default tree cell renderer and tell him to use images before nodes
Reference< XDefaultTreeCellRenderer > xDefaultRenderer( DefaultTreeCellRenderer::create( xCC ) );
xDefaultRenderer->setExpandedImageURL( O( "expand.png" ) );
xDefaultRenderer->setCollapsedImageURL( O( "collapsed.png" ) );
xDefaultRenderer->setLeafNodeImageURL( O( "leaf.png" ) );

// set the default cell renderer at the tree control model
xTreeControlModel->setCellRenderer( Reference< XTreeCellRenderer >( xDefaultTreeModel, UNO_QUERY ) );
Personal tools