1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: dlgedfac.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_basctl.hxx"
35 #include "dlgedfac.hxx"
36 #include "dlgedobj.hxx"
37 #include <dlgeddef.hxx>
38 #include <com/sun/star/container/XNameContainer.hpp>
39 #include <com/sun/star/beans/PropertyValue.hpp>
40 #include <com/sun/star/beans/XPropertySet.hpp>
41 #include <com/sun/star/awt/ScrollBarOrientation.hpp>
43 using namespace ::com::sun::star
;
45 //----------------------------------------------------------------------------
47 DlgEdFactory::DlgEdFactory()
49 SdrObjFactory::InsertMakeObjectHdl( LINK(this, DlgEdFactory
, MakeObject
) );
52 //----------------------------------------------------------------------------
54 DlgEdFactory::~DlgEdFactory()
56 SdrObjFactory::RemoveMakeObjectHdl( LINK(this, DlgEdFactory
, MakeObject
) );
59 //----------------------------------------------------------------------------
61 IMPL_LINK( DlgEdFactory
, MakeObject
, SdrObjFactory
*, pObjFactory
)
63 static sal_Bool bNeedsInit
= sal_True
;
64 static uno::Reference
< lang::XMultiServiceFactory
> xDialogSFact
;
68 uno::Reference
< lang::XMultiServiceFactory
> xMSF
= ::comphelper::getProcessServiceFactory();
69 uno::Reference
< container::XNameContainer
> xC( xMSF
->createInstance( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.awt.UnoControlDialogModel" ) ) ), uno::UNO_QUERY
);
72 uno::Reference
< lang::XMultiServiceFactory
> xModFact( xC
, uno::UNO_QUERY
);
73 xDialogSFact
= xModFact
;
75 bNeedsInit
= sal_False
;
78 if( (pObjFactory
->nInventor
== DlgInventor
) &&
79 (pObjFactory
->nIdentifier
>= OBJ_DLG_PUSHBUTTON
) &&
80 (pObjFactory
->nIdentifier
<= OBJ_DLG_TREECONTROL
) )
82 switch( pObjFactory
->nIdentifier
)
84 case OBJ_DLG_PUSHBUTTON
:
85 pObjFactory
->pNewObj
= new DlgEdObj( ::rtl::OUString::createFromAscii("com.sun.star.awt.UnoControlButtonModel") , xDialogSFact
);
87 case OBJ_DLG_RADIOBUTTON
:
88 pObjFactory
->pNewObj
= new DlgEdObj( ::rtl::OUString::createFromAscii("com.sun.star.awt.UnoControlRadioButtonModel") , xDialogSFact
);
90 case OBJ_DLG_CHECKBOX
:
91 pObjFactory
->pNewObj
= new DlgEdObj( ::rtl::OUString::createFromAscii("com.sun.star.awt.UnoControlCheckBoxModel") , xDialogSFact
);
94 pObjFactory
->pNewObj
= new DlgEdObj( ::rtl::OUString::createFromAscii("com.sun.star.awt.UnoControlListBoxModel") , xDialogSFact
);
96 case OBJ_DLG_COMBOBOX
:
98 DlgEdObj
* pNew
= new DlgEdObj( ::rtl::OUString::createFromAscii("com.sun.star.awt.UnoControlComboBoxModel") , xDialogSFact
);
99 pObjFactory
->pNewObj
= pNew
;
102 uno::Reference
< beans::XPropertySet
> xPSet(pNew
->GetUnoControlModel(), uno::UNO_QUERY
);
105 sal_Bool bB
= sal_True
;
106 xPSet
->setPropertyValue( DLGED_PROP_DROPDOWN
, uno::Any(&bB
,::getBooleanCppuType()));
113 case OBJ_DLG_GROUPBOX
:
114 pObjFactory
->pNewObj
= new DlgEdObj( ::rtl::OUString::createFromAscii("com.sun.star.awt.UnoControlGroupBoxModel") , xDialogSFact
);
117 pObjFactory
->pNewObj
= new DlgEdObj( ::rtl::OUString::createFromAscii("com.sun.star.awt.UnoControlEditModel") , xDialogSFact
);
119 case OBJ_DLG_FIXEDTEXT
:
120 pObjFactory
->pNewObj
= new DlgEdObj( ::rtl::OUString::createFromAscii("com.sun.star.awt.UnoControlFixedTextModel") , xDialogSFact
);
122 case OBJ_DLG_IMAGECONTROL
:
123 pObjFactory
->pNewObj
= new DlgEdObj( ::rtl::OUString::createFromAscii("com.sun.star.awt.UnoControlImageControlModel") , xDialogSFact
);
125 case OBJ_DLG_PROGRESSBAR
:
126 pObjFactory
->pNewObj
= new DlgEdObj( ::rtl::OUString::createFromAscii("com.sun.star.awt.UnoControlProgressBarModel") , xDialogSFact
);
128 case OBJ_DLG_HSCROLLBAR
:
129 pObjFactory
->pNewObj
= new DlgEdObj( ::rtl::OUString::createFromAscii("com.sun.star.awt.UnoControlScrollBarModel") , xDialogSFact
);
131 case OBJ_DLG_VSCROLLBAR
:
133 DlgEdObj
* pNew
= new DlgEdObj( ::rtl::OUString::createFromAscii("com.sun.star.awt.UnoControlScrollBarModel") , xDialogSFact
);
134 pObjFactory
->pNewObj
= pNew
;
135 // set vertical orientation
138 uno::Reference
< beans::XPropertySet
> xPSet(pNew
->GetUnoControlModel(), uno::UNO_QUERY
);
142 aValue
<<= (sal_Int32
) ::com::sun::star::awt::ScrollBarOrientation::VERTICAL
;
143 xPSet
->setPropertyValue( DLGED_PROP_ORIENTATION
, aValue
);
150 case OBJ_DLG_HFIXEDLINE
:
151 pObjFactory
->pNewObj
= new DlgEdObj( ::rtl::OUString::createFromAscii("com.sun.star.awt.UnoControlFixedLineModel") , xDialogSFact
);
153 case OBJ_DLG_VFIXEDLINE
:
155 DlgEdObj
* pNew
= new DlgEdObj( ::rtl::OUString::createFromAscii("com.sun.star.awt.UnoControlFixedLineModel") , xDialogSFact
);
156 pObjFactory
->pNewObj
= pNew
;
157 // set vertical orientation
160 uno::Reference
< beans::XPropertySet
> xPSet(pNew
->GetUnoControlModel(), uno::UNO_QUERY
);
164 aValue
<<= (sal_Int32
) 1;
165 xPSet
->setPropertyValue( DLGED_PROP_ORIENTATION
, aValue
);
172 case OBJ_DLG_DATEFIELD
:
173 pObjFactory
->pNewObj
= new DlgEdObj( ::rtl::OUString::createFromAscii("com.sun.star.awt.UnoControlDateFieldModel") , xDialogSFact
);
175 case OBJ_DLG_TIMEFIELD
:
176 pObjFactory
->pNewObj
= new DlgEdObj( ::rtl::OUString::createFromAscii("com.sun.star.awt.UnoControlTimeFieldModel") , xDialogSFact
);
178 case OBJ_DLG_NUMERICFIELD
:
179 pObjFactory
->pNewObj
= new DlgEdObj( ::rtl::OUString::createFromAscii("com.sun.star.awt.UnoControlNumericFieldModel") , xDialogSFact
);
181 case OBJ_DLG_CURRENCYFIELD
:
182 pObjFactory
->pNewObj
= new DlgEdObj( ::rtl::OUString::createFromAscii("com.sun.star.awt.UnoControlCurrencyFieldModel") , xDialogSFact
);
184 case OBJ_DLG_FORMATTEDFIELD
:
185 pObjFactory
->pNewObj
= new DlgEdObj( ::rtl::OUString::createFromAscii("com.sun.star.awt.UnoControlFormattedFieldModel") , xDialogSFact
);
187 case OBJ_DLG_PATTERNFIELD
:
188 pObjFactory
->pNewObj
= new DlgEdObj( ::rtl::OUString::createFromAscii("com.sun.star.awt.UnoControlPatternFieldModel") , xDialogSFact
);
190 case OBJ_DLG_FILECONTROL
:
191 pObjFactory
->pNewObj
= new DlgEdObj( ::rtl::OUString::createFromAscii("com.sun.star.awt.UnoControlFileControlModel") , xDialogSFact
);
193 case OBJ_DLG_TREECONTROL
:
194 DlgEdObj
* pNew
= new DlgEdObj( ::rtl::OUString::createFromAscii("com.sun.star.awt.tree.TreeControlModel") , xDialogSFact
);
195 pObjFactory
->pNewObj
= pNew
;
199 uno::Reference< beans::XPropertySet > xPSet(pNew->GetUnoControlModel(), uno::UNO_QUERY);
202 // first create a data model for our tree control
203 Reference< XComponentContext > xComponentContext;
205 Reference< XPropertySet > xPropSet( xInterface, UNO_QUERY );
206 xPropSet->getPropertyValue( OUString::createFromAscii("DefaultContext") ) >>= xComponentContext;
208 // gets the service manager from the office
209 Reference< XMultiComponentFactory > xMultiComponentFactoryServer( xComponentContext->getServiceManager() );
212 // gets the TreeDataModel
213 Reference< XMutableTreeDataModel > xTreeDataModel;
215 xTreeDataModel = Reference< XMutableTreeDataModel >(
216 xMultiComponentFactoryServer->createInstanceWithContext(
217 OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.awt.tree.MutableTreeDataModel" ) ), xComponentContext ), UNO_QUERY_THROW );
219 // now fill it with some sample data
220 const OUString sRoot( RTL_CONSTASCII_USTRINGPARAM( "Root" ) );
222 Reference< XMutableTreeNode > xNode( mxTreeDataModel->createNode( sRoot, false ), UNO_QUERY_THROW );
223 xNode->setDataValue( sRoot );
224 xNode->setExpandedGraphicURL( OUString( RTL_CONSTASCII_USTRINGPARAM( "private:graphicrepository/sd/res/triangle_down.png" ) ) );
225 xNode->setCollapsedGraphicURL( OUString( RTL_CONSTASCII_USTRINGPARAM( "private:graphicrepository/sd/res/triangle_right.png" ) ) );
227 const OUString sNode_1( RTL_CONSTASCII_USTRINGPARAM( "Node_1" ) );
229 Reference< XMutableTreeNode > xChildNode_1( mxTreeDataModel->createNode( sNode_1, true ), UNO_QUERY_THROW );
230 xChildNode_1->setDataValue( sNode_1 );
231 xChildNode_1->setExpandedGraphicURL( OUString( RTL_CONSTASCII_USTRINGPARAM( "private:graphicrepository/sd/res/triangle_down.png" ) ) );
232 xChildNode_1->setCollapsedGraphicURL( OUString( RTL_CONSTASCII_USTRINGPARAM( "private:graphicrepository/sd/res/triangle_right.png" ) ) );
234 xNode->appendChild( xChildNode_1 );
236 const OUString sNode_1_1( RTL_CONSTASCII_USTRINGPARAM( "Node_1_1" ) );
238 Reference< XMutableTreeNode > xChildNode_1_1( mxTreeDataModel->createNode( sNode_1_1, false ), UNO_QUERY_THROW );
239 xChildNode_1_1->setDataValue( sNode_1_1 );
240 xChildNode_1_1->setExpandedGraphicURL( OUString( RTL_CONSTASCII_USTRINGPARAM( "private:graphicrepository/sd/res/triangle_down.png" ) ) );
241 xChildNode_1_1->setCollapsedGraphicURL( OUString( RTL_CONSTASCII_USTRINGPARAM( "private:graphicrepository/sd/res/triangle_right.png" ) ) );
243 xChildNode_1->appendChild( xChildNode_1_1 );
245 const OUString sNode_1_1( RTL_CONSTASCII_USTRINGPARAM( "Node_2" ) );
247 Reference< XMutableTreeNode > xChildNode_2( mxTreeDataModel->createNode( sNode_2, false ), UNO_QUERY_THROW );
248 xChildNode_2->setDataValue( sNode_2 );
249 xChildNode_2->setNodeGraphicURL( OUString( RTL_CONSTASCII_USTRINGPARAM("private:graphicrepository/sw/imglst/nc20010.png") ) );
250 xNode->appendChild( xChildNode_2 );
252 xTreeDataModel->setRoot( xNode );
255 const OUString sDataModel( RTL_CONSTASCII_USTRINGPARAM( "DataModel" ) );
257 xPSet->setPropertyValue( sDataModel, xTreeDataModel );
270 //----------------------------------------------------------------------------