Update ooo320-m1
[ooovba.git] / basctl / source / dlged / dlgedfac.cxx
blob6dc1237c5239ed0d3adbd5c19e76316929ae9b97
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: dlgedfac.cxx,v $
10 * $Revision: 1.21 $
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;
66 if( bNeedsInit )
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 );
70 if( xC.is() )
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 );
86 break;
87 case OBJ_DLG_RADIOBUTTON:
88 pObjFactory->pNewObj = new DlgEdObj( ::rtl::OUString::createFromAscii("com.sun.star.awt.UnoControlRadioButtonModel") , xDialogSFact );
89 break;
90 case OBJ_DLG_CHECKBOX:
91 pObjFactory->pNewObj = new DlgEdObj( ::rtl::OUString::createFromAscii("com.sun.star.awt.UnoControlCheckBoxModel") , xDialogSFact );
92 break;
93 case OBJ_DLG_LISTBOX:
94 pObjFactory->pNewObj = new DlgEdObj( ::rtl::OUString::createFromAscii("com.sun.star.awt.UnoControlListBoxModel") , xDialogSFact );
95 break;
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);
103 if (xPSet.is())
105 sal_Bool bB = sal_True;
106 xPSet->setPropertyValue( DLGED_PROP_DROPDOWN, uno::Any(&bB,::getBooleanCppuType()));
109 catch(...)
112 } break;
113 case OBJ_DLG_GROUPBOX:
114 pObjFactory->pNewObj = new DlgEdObj( ::rtl::OUString::createFromAscii("com.sun.star.awt.UnoControlGroupBoxModel") , xDialogSFact );
115 break;
116 case OBJ_DLG_EDIT:
117 pObjFactory->pNewObj = new DlgEdObj( ::rtl::OUString::createFromAscii("com.sun.star.awt.UnoControlEditModel") , xDialogSFact );
118 break;
119 case OBJ_DLG_FIXEDTEXT:
120 pObjFactory->pNewObj = new DlgEdObj( ::rtl::OUString::createFromAscii("com.sun.star.awt.UnoControlFixedTextModel") , xDialogSFact );
121 break;
122 case OBJ_DLG_IMAGECONTROL:
123 pObjFactory->pNewObj = new DlgEdObj( ::rtl::OUString::createFromAscii("com.sun.star.awt.UnoControlImageControlModel") , xDialogSFact );
124 break;
125 case OBJ_DLG_PROGRESSBAR:
126 pObjFactory->pNewObj = new DlgEdObj( ::rtl::OUString::createFromAscii("com.sun.star.awt.UnoControlProgressBarModel") , xDialogSFact );
127 break;
128 case OBJ_DLG_HSCROLLBAR:
129 pObjFactory->pNewObj = new DlgEdObj( ::rtl::OUString::createFromAscii("com.sun.star.awt.UnoControlScrollBarModel") , xDialogSFact );
130 break;
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);
139 if (xPSet.is())
141 uno::Any aValue;
142 aValue <<= (sal_Int32) ::com::sun::star::awt::ScrollBarOrientation::VERTICAL;
143 xPSet->setPropertyValue( DLGED_PROP_ORIENTATION, aValue );
146 catch(...)
149 } break;
150 case OBJ_DLG_HFIXEDLINE:
151 pObjFactory->pNewObj = new DlgEdObj( ::rtl::OUString::createFromAscii("com.sun.star.awt.UnoControlFixedLineModel") , xDialogSFact );
152 break;
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);
161 if (xPSet.is())
163 uno::Any aValue;
164 aValue <<= (sal_Int32) 1;
165 xPSet->setPropertyValue( DLGED_PROP_ORIENTATION, aValue );
168 catch(...)
171 } break;
172 case OBJ_DLG_DATEFIELD:
173 pObjFactory->pNewObj = new DlgEdObj( ::rtl::OUString::createFromAscii("com.sun.star.awt.UnoControlDateFieldModel") , xDialogSFact );
174 break;
175 case OBJ_DLG_TIMEFIELD:
176 pObjFactory->pNewObj = new DlgEdObj( ::rtl::OUString::createFromAscii("com.sun.star.awt.UnoControlTimeFieldModel") , xDialogSFact );
177 break;
178 case OBJ_DLG_NUMERICFIELD:
179 pObjFactory->pNewObj = new DlgEdObj( ::rtl::OUString::createFromAscii("com.sun.star.awt.UnoControlNumericFieldModel") , xDialogSFact );
180 break;
181 case OBJ_DLG_CURRENCYFIELD:
182 pObjFactory->pNewObj = new DlgEdObj( ::rtl::OUString::createFromAscii("com.sun.star.awt.UnoControlCurrencyFieldModel") , xDialogSFact );
183 break;
184 case OBJ_DLG_FORMATTEDFIELD:
185 pObjFactory->pNewObj = new DlgEdObj( ::rtl::OUString::createFromAscii("com.sun.star.awt.UnoControlFormattedFieldModel") , xDialogSFact );
186 break;
187 case OBJ_DLG_PATTERNFIELD:
188 pObjFactory->pNewObj = new DlgEdObj( ::rtl::OUString::createFromAscii("com.sun.star.awt.UnoControlPatternFieldModel") , xDialogSFact );
189 break;
190 case OBJ_DLG_FILECONTROL:
191 pObjFactory->pNewObj = new DlgEdObj( ::rtl::OUString::createFromAscii("com.sun.star.awt.UnoControlFileControlModel") , xDialogSFact );
192 break;
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);
200 if (xPSet.is())
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 );
260 catch(...)
263 break;
267 return 0;
270 //----------------------------------------------------------------------------