xref: /trunk/main/basctl/source/dlged/dlgedfac.cxx (revision 1ecadb572e7010ff3b3382ad9bf179dbc6efadbb)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_basctl.hxx"
30 
31 
32 #include "dlgedfac.hxx"
33 #include "dlgedobj.hxx"
34 #include <dlgeddef.hxx>
35 #include <com/sun/star/container/XNameContainer.hpp>
36 #include <com/sun/star/beans/PropertyValue.hpp>
37 #include <com/sun/star/beans/XPropertySet.hpp>
38 #include <com/sun/star/awt/ScrollBarOrientation.hpp>
39 
40 using namespace ::com::sun::star;
41 
42 //----------------------------------------------------------------------------
43 
44 DlgEdFactory::DlgEdFactory()
45 {
46     SdrObjFactory::InsertMakeObjectHdl( LINK(this, DlgEdFactory, MakeObject) );
47 }
48 
49 //----------------------------------------------------------------------------
50 
51 DlgEdFactory::~DlgEdFactory()
52 {
53     SdrObjFactory::RemoveMakeObjectHdl( LINK(this, DlgEdFactory, MakeObject) );
54 }
55 
56 //----------------------------------------------------------------------------
57 
58 IMPL_LINK( DlgEdFactory, MakeObject, SdrObjFactory *, pObjFactory )
59 {
60     static sal_Bool bNeedsInit = sal_True;
61     static uno::Reference< lang::XMultiServiceFactory > xDialogSFact;
62 
63     if( bNeedsInit )
64     {
65         uno::Reference< lang::XMultiServiceFactory > xMSF = ::comphelper::getProcessServiceFactory();
66         uno::Reference< container::XNameContainer > xC( xMSF->createInstance( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.awt.UnoControlDialogModel" ) ) ), uno::UNO_QUERY );
67         if( xC.is() )
68         {
69             uno::Reference< lang::XMultiServiceFactory > xModFact( xC, uno::UNO_QUERY );
70             xDialogSFact = xModFact;
71         }
72         bNeedsInit = sal_False;
73     }
74 
75     if( (pObjFactory->nInventor == DlgInventor) &&
76         (pObjFactory->nIdentifier >= OBJ_DLG_PUSHBUTTON) &&
77         (pObjFactory->nIdentifier <= OBJ_DLG_TREECONTROL)    )
78     {
79         switch( pObjFactory->nIdentifier )
80         {
81             case OBJ_DLG_PUSHBUTTON:
82                  pObjFactory->pNewObj = new DlgEdObj( ::rtl::OUString::createFromAscii("com.sun.star.awt.UnoControlButtonModel") , xDialogSFact );
83                  break;
84             case OBJ_DLG_RADIOBUTTON:
85                  pObjFactory->pNewObj = new DlgEdObj( ::rtl::OUString::createFromAscii("com.sun.star.awt.UnoControlRadioButtonModel") , xDialogSFact );
86                  break;
87             case OBJ_DLG_CHECKBOX:
88                  pObjFactory->pNewObj = new DlgEdObj( ::rtl::OUString::createFromAscii("com.sun.star.awt.UnoControlCheckBoxModel") , xDialogSFact );
89                  break;
90             case OBJ_DLG_LISTBOX:
91                  pObjFactory->pNewObj = new DlgEdObj( ::rtl::OUString::createFromAscii("com.sun.star.awt.UnoControlListBoxModel") , xDialogSFact );
92                  break;
93             case OBJ_DLG_COMBOBOX:
94             {
95                  DlgEdObj* pNew = new DlgEdObj( ::rtl::OUString::createFromAscii("com.sun.star.awt.UnoControlComboBoxModel") , xDialogSFact );
96                  pObjFactory->pNewObj = pNew;
97                  try
98                  {
99                     uno::Reference< beans::XPropertySet >  xPSet(pNew->GetUnoControlModel(), uno::UNO_QUERY);
100                     if (xPSet.is())
101                     {
102                         sal_Bool bB = sal_True;
103                         xPSet->setPropertyValue( DLGED_PROP_DROPDOWN, uno::Any(&bB,::getBooleanCppuType()));
104                     }
105                  }
106                  catch(...)
107                  {
108                  }
109             }    break;
110             case OBJ_DLG_GROUPBOX:
111                  pObjFactory->pNewObj = new DlgEdObj( ::rtl::OUString::createFromAscii("com.sun.star.awt.UnoControlGroupBoxModel") , xDialogSFact );
112                  break;
113             case OBJ_DLG_EDIT:
114                  pObjFactory->pNewObj = new DlgEdObj( ::rtl::OUString::createFromAscii("com.sun.star.awt.UnoControlEditModel") , xDialogSFact );
115                  break;
116             case OBJ_DLG_FIXEDTEXT:
117                  pObjFactory->pNewObj = new DlgEdObj( ::rtl::OUString::createFromAscii("com.sun.star.awt.UnoControlFixedTextModel") , xDialogSFact );
118                  break;
119             case OBJ_DLG_IMAGECONTROL:
120                  pObjFactory->pNewObj = new DlgEdObj( ::rtl::OUString::createFromAscii("com.sun.star.awt.UnoControlImageControlModel") , xDialogSFact );
121                  break;
122             case OBJ_DLG_PROGRESSBAR:
123                  pObjFactory->pNewObj = new DlgEdObj( ::rtl::OUString::createFromAscii("com.sun.star.awt.UnoControlProgressBarModel") , xDialogSFact );
124                  break;
125             case OBJ_DLG_HSCROLLBAR:
126                  pObjFactory->pNewObj = new DlgEdObj( ::rtl::OUString::createFromAscii("com.sun.star.awt.UnoControlScrollBarModel") , xDialogSFact );
127                  break;
128             case OBJ_DLG_VSCROLLBAR:
129             {
130                  DlgEdObj* pNew = new DlgEdObj( ::rtl::OUString::createFromAscii("com.sun.star.awt.UnoControlScrollBarModel") , xDialogSFact );
131                  pObjFactory->pNewObj = pNew;
132                  // set vertical orientation
133                  try
134                  {
135                     uno::Reference< beans::XPropertySet >  xPSet(pNew->GetUnoControlModel(), uno::UNO_QUERY);
136                     if (xPSet.is())
137                     {
138                         uno::Any aValue;
139                         aValue <<= (sal_Int32) ::com::sun::star::awt::ScrollBarOrientation::VERTICAL;
140                         xPSet->setPropertyValue( DLGED_PROP_ORIENTATION, aValue );
141                     }
142                  }
143                  catch(...)
144                  {
145                  }
146             }    break;
147             case OBJ_DLG_HFIXEDLINE:
148                  pObjFactory->pNewObj = new DlgEdObj( ::rtl::OUString::createFromAscii("com.sun.star.awt.UnoControlFixedLineModel") , xDialogSFact );
149                  break;
150             case OBJ_DLG_VFIXEDLINE:
151             {
152                  DlgEdObj* pNew = new DlgEdObj( ::rtl::OUString::createFromAscii("com.sun.star.awt.UnoControlFixedLineModel") , xDialogSFact );
153                  pObjFactory->pNewObj = pNew;
154                  // set vertical orientation
155                  try
156                  {
157                     uno::Reference< beans::XPropertySet >  xPSet(pNew->GetUnoControlModel(), uno::UNO_QUERY);
158                     if (xPSet.is())
159                     {
160                         uno::Any aValue;
161                         aValue <<= (sal_Int32) 1;
162                         xPSet->setPropertyValue( DLGED_PROP_ORIENTATION, aValue );
163                     }
164                  }
165                  catch(...)
166                  {
167                  }
168             }    break;
169             case OBJ_DLG_DATEFIELD:
170                  pObjFactory->pNewObj = new DlgEdObj( ::rtl::OUString::createFromAscii("com.sun.star.awt.UnoControlDateFieldModel") , xDialogSFact );
171                  break;
172             case OBJ_DLG_TIMEFIELD:
173                  pObjFactory->pNewObj = new DlgEdObj( ::rtl::OUString::createFromAscii("com.sun.star.awt.UnoControlTimeFieldModel") , xDialogSFact );
174                  break;
175             case OBJ_DLG_NUMERICFIELD:
176                  pObjFactory->pNewObj = new DlgEdObj( ::rtl::OUString::createFromAscii("com.sun.star.awt.UnoControlNumericFieldModel") , xDialogSFact );
177                  break;
178             case OBJ_DLG_CURRENCYFIELD:
179                  pObjFactory->pNewObj = new DlgEdObj( ::rtl::OUString::createFromAscii("com.sun.star.awt.UnoControlCurrencyFieldModel") , xDialogSFact );
180                  break;
181             case OBJ_DLG_FORMATTEDFIELD:
182                  pObjFactory->pNewObj = new DlgEdObj( ::rtl::OUString::createFromAscii("com.sun.star.awt.UnoControlFormattedFieldModel") , xDialogSFact );
183                  break;
184             case OBJ_DLG_PATTERNFIELD:
185                  pObjFactory->pNewObj = new DlgEdObj( ::rtl::OUString::createFromAscii("com.sun.star.awt.UnoControlPatternFieldModel") , xDialogSFact );
186                  break;
187             case OBJ_DLG_FILECONTROL:
188                  pObjFactory->pNewObj = new DlgEdObj( ::rtl::OUString::createFromAscii("com.sun.star.awt.UnoControlFileControlModel") , xDialogSFact );
189                  break;
190             case OBJ_DLG_TREECONTROL:
191                  DlgEdObj* pNew = new DlgEdObj( ::rtl::OUString::createFromAscii("com.sun.star.awt.tree.TreeControlModel") , xDialogSFact );
192                  pObjFactory->pNewObj = pNew;
193                  /*
194                  try
195                  {
196                     uno::Reference< beans::XPropertySet >  xPSet(pNew->GetUnoControlModel(), uno::UNO_QUERY);
197                     if (xPSet.is())
198                     {
199                         // first create a data model for our tree control
200                         Reference< XComponentContext > xComponentContext;
201 
202                         Reference< XPropertySet > xPropSet( xInterface, UNO_QUERY );
203                         xPropSet->getPropertyValue( OUString::createFromAscii("DefaultContext") ) >>= xComponentContext;
204 
205                         // gets the service manager from the office
206                         Reference< XMultiComponentFactory > xMultiComponentFactoryServer( xComponentContext->getServiceManager() );
207 
208 
209                         // gets the TreeDataModel
210                         Reference< XMutableTreeDataModel > xTreeDataModel;
211 
212                         xTreeDataModel = Reference< XMutableTreeDataModel >(
213                         xMultiComponentFactoryServer->createInstanceWithContext(
214                         OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.awt.tree.MutableTreeDataModel" ) ), xComponentContext ), UNO_QUERY_THROW );
215 
216                         // now fill it with some sample data
217                         const OUString sRoot( RTL_CONSTASCII_USTRINGPARAM( "Root" ) );
218 
219                         Reference< XMutableTreeNode > xNode( mxTreeDataModel->createNode( sRoot, false ), UNO_QUERY_THROW );
220                         xNode->setDataValue( sRoot );
221                         xNode->setExpandedGraphicURL( OUString( RTL_CONSTASCII_USTRINGPARAM( "private:graphicrepository/sd/res/triangle_down.png" ) ) );
222                         xNode->setCollapsedGraphicURL( OUString( RTL_CONSTASCII_USTRINGPARAM( "private:graphicrepository/sd/res/triangle_right.png" ) ) );
223 
224                         const OUString sNode_1( RTL_CONSTASCII_USTRINGPARAM( "Node_1" ) );
225 
226                         Reference< XMutableTreeNode > xChildNode_1( mxTreeDataModel->createNode( sNode_1, true ), UNO_QUERY_THROW );
227                         xChildNode_1->setDataValue( sNode_1 );
228                         xChildNode_1->setExpandedGraphicURL( OUString( RTL_CONSTASCII_USTRINGPARAM( "private:graphicrepository/sd/res/triangle_down.png" ) ) );
229                         xChildNode_1->setCollapsedGraphicURL( OUString( RTL_CONSTASCII_USTRINGPARAM( "private:graphicrepository/sd/res/triangle_right.png" ) ) );
230 
231                         xNode->appendChild( xChildNode_1 );
232 
233                         const OUString sNode_1_1( RTL_CONSTASCII_USTRINGPARAM( "Node_1_1" ) );
234 
235                         Reference< XMutableTreeNode > xChildNode_1_1( mxTreeDataModel->createNode( sNode_1_1, false ), UNO_QUERY_THROW );
236                         xChildNode_1_1->setDataValue( sNode_1_1 );
237                         xChildNode_1_1->setExpandedGraphicURL( OUString( RTL_CONSTASCII_USTRINGPARAM( "private:graphicrepository/sd/res/triangle_down.png" ) ) );
238                         xChildNode_1_1->setCollapsedGraphicURL( OUString( RTL_CONSTASCII_USTRINGPARAM( "private:graphicrepository/sd/res/triangle_right.png" ) ) );
239 
240                         xChildNode_1->appendChild( xChildNode_1_1 );
241 
242                         const OUString sNode_1_1( RTL_CONSTASCII_USTRINGPARAM( "Node_2" ) );
243 
244                         Reference< XMutableTreeNode > xChildNode_2( mxTreeDataModel->createNode( sNode_2, false ), UNO_QUERY_THROW );
245                         xChildNode_2->setDataValue( sNode_2 );
246                         xChildNode_2->setNodeGraphicURL( OUString( RTL_CONSTASCII_USTRINGPARAM("private:graphicrepository/sw/imglst/nc20010.png") ) );
247                         xNode->appendChild( xChildNode_2 );
248 
249                         xTreeDataModel->setRoot( xNode );
250 
251 
252                         const OUString sDataModel( RTL_CONSTASCII_USTRINGPARAM( "DataModel" ) );
253 
254                         xPSet->setPropertyValue( sDataModel, xTreeDataModel );
255                     }
256                  }
257                  catch(...)
258                  {
259                  }*/
260                  break;
261         }
262     }
263 
264     return 0;
265 }
266 
267 //----------------------------------------------------------------------------
268 
269