xref: /aoo42x/main/svx/source/form/fmobjfac.cxx (revision cdf0e10c)
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_svx.hxx"
30 #include <comphelper/stl_types.hxx>
31 #include <svx/svdobj.hxx>
32 #include "svx/fmtools.hxx"
33 #include "fmservs.hxx"
34 
35 #ifndef _FM_FMOBJFAC_HXX
36 #include "svx/fmobjfac.hxx"
37 #endif
38 
39 #ifndef _FM_FMGLOB_HXX
40 #include <svx/fmglob.hxx>
41 #endif
42 
43 #ifndef _FM_FMOBJ_HXX
44 #include "fmobj.hxx"
45 #endif
46 #include "fmshimp.hxx"
47 
48 #ifndef _FM_FMSHELL_HXX
49 #include <svx/fmshell.hxx>
50 #endif
51 
52 #ifndef _SVX_SVXIDS_HRC
53 #include <svx/svxids.hrc>
54 #endif
55 #include "tbxform.hxx"
56 #include <tools/resid.hxx>
57 
58 #ifndef _SVX_FMRESIDS_HRC
59 #include "svx/fmresids.hrc"
60 #endif
61 #include <tools/shl.hxx>
62 #include <svx/dialmgr.hxx>
63 #include "fmservs.hxx"
64 #include "tabwin.hxx"
65 #include "fmexpl.hxx"
66 #include "filtnav.hxx"
67 
68 #ifndef _SVX_FMPROP_HRC
69 #include "fmprop.hrc"
70 #endif
71 #include "fmPropBrw.hxx"
72 #include "datanavi.hxx"
73 
74 using namespace ::com::sun::star::uno;
75 using namespace ::com::sun::star::beans;
76 using namespace ::svxform;
77 
78 static sal_Bool bInit = sal_False;
79 
80 /*************************************************************************
81 |*
82 |* Ctor
83 |*
84 \************************************************************************/
85 FmFormObjFactory::FmFormObjFactory()
86 {
87 	if ( !bInit )
88 	{
89 		SdrObjFactory::InsertMakeObjectHdl(LINK(this, FmFormObjFactory, MakeObject));
90 
91 		//////////////////////////////////////////////////////////////////////
92 		// Konfigurations-::com::sun::star::frame::Controller und NavigationBar registrieren
93 		SvxFmTbxCtlConfig::RegisterControl( SID_FM_CONFIG );
94 		SvxFmTbxCtlAbsRec::RegisterControl( SID_FM_RECORD_ABSOLUTE );
95 		SvxFmTbxCtlRecText::RegisterControl( SID_FM_RECORD_TEXT );
96 		SvxFmTbxCtlRecFromText::RegisterControl( SID_FM_RECORD_FROM_TEXT );
97 		SvxFmTbxCtlRecTotal::RegisterControl( SID_FM_RECORD_TOTAL );
98 		SvxFmTbxPrevRec::RegisterControl( SID_FM_RECORD_PREV );
99 		SvxFmTbxNextRec::RegisterControl( SID_FM_RECORD_NEXT );
100 		ControlConversionMenuController::RegisterControl(SID_FM_CHANGECONTROLTYPE);
101 
102 		// Registrieung von globalen fenstern
103 		FmFieldWinMgr::RegisterChildWindow();
104 		FmPropBrwMgr::RegisterChildWindow();
105 		NavigatorFrameManager::RegisterChildWindow();
106 		DataNavigatorManager::RegisterChildWindow();
107 		FmFilterNavigatorWinMgr::RegisterChildWindow();
108 
109 		//////////////////////////////////////////////////////////////////////
110 		// Interface fuer die Formshell registrieren
111 		FmFormShell::RegisterInterface(0);
112 
113 		ImplSmartRegisterUnoServices();
114 		bInit = sal_True;
115 	}
116 }
117 
118 
119 /*************************************************************************
120 |*
121 |* Dtor
122 |*
123 \************************************************************************/
124 FmFormObjFactory::~FmFormObjFactory()
125 {
126 }
127 
128 
129 /*************************************************************************
130 |*
131 |* ::com::sun::star::form::Form-Objekte erzeugen
132 |*
133 \************************************************************************/
134 namespace
135 {
136 	void	lcl_initProperty( FmFormObj* _pObject, const ::rtl::OUString& _rPropName, const Any& _rValue )
137 	{
138 		try
139 		{
140 			Reference< XPropertySet >  xModelSet( _pObject->GetUnoControlModel(), UNO_QUERY );
141 			if ( xModelSet.is() )
142 				xModelSet->setPropertyValue( _rPropName, _rValue );
143 		}
144 		catch( const Exception& )
145 		{
146 			DBG_ERROR( "lcl_initProperty: caught an exception!" );
147 		}
148 	}
149 }
150 
151 IMPL_LINK(FmFormObjFactory, MakeObject, SdrObjFactory*, pObjFactory)
152 {
153 	if (pObjFactory->nInventor == FmFormInventor)
154 	{
155         ::rtl::OUString sServiceSpecifier;
156 
157         typedef ::std::vector< ::std::pair< ::rtl::OUString, Any > > PropertyValueArray;
158         PropertyValueArray aInitialProperties;
159 
160         switch ( pObjFactory->nIdentifier )
161         {
162 			case OBJ_FM_EDIT:
163                 sServiceSpecifier = FM_COMPONENT_EDIT;
164                 break;
165 
166 			case OBJ_FM_BUTTON:
167                 sServiceSpecifier = FM_COMPONENT_COMMANDBUTTON;
168                 break;
169 
170 			case OBJ_FM_FIXEDTEXT:
171                 sServiceSpecifier = FM_COMPONENT_FIXEDTEXT;
172                 break;
173 
174 			case OBJ_FM_LISTBOX:
175 				sServiceSpecifier = FM_COMPONENT_LISTBOX;
176 			    break;
177 
178 			case OBJ_FM_CHECKBOX:
179 				sServiceSpecifier = FM_COMPONENT_CHECKBOX;
180 			    break;
181 
182 			case OBJ_FM_RADIOBUTTON:
183 				sServiceSpecifier = FM_COMPONENT_RADIOBUTTON;
184 			    break;
185 
186 			case OBJ_FM_GROUPBOX:
187 				sServiceSpecifier = FM_COMPONENT_GROUPBOX;
188 			    break;
189 
190 			case OBJ_FM_COMBOBOX:
191 				sServiceSpecifier = FM_COMPONENT_COMBOBOX;
192 			    break;
193 
194             case OBJ_FM_GRID:
195 				sServiceSpecifier = FM_COMPONENT_GRID;
196 			    break;
197 
198 			case OBJ_FM_IMAGEBUTTON:
199 				sServiceSpecifier = FM_COMPONENT_IMAGEBUTTON;
200 			    break;
201 
202 			case OBJ_FM_FILECONTROL:
203 				sServiceSpecifier = FM_COMPONENT_FILECONTROL;
204 			    break;
205 
206 			case OBJ_FM_DATEFIELD:
207 				sServiceSpecifier = FM_COMPONENT_DATEFIELD;
208 			    break;
209 
210 			case OBJ_FM_TIMEFIELD:
211 				sServiceSpecifier = FM_COMPONENT_TIMEFIELD;
212                 aInitialProperties.push_back( PropertyValueArray::value_type( FM_PROP_TIMEMAX, makeAny( (sal_Int32)( Time( 23, 59, 59, 99 ).GetTime() ) ) ) );
213 			    break;
214 
215 			case OBJ_FM_NUMERICFIELD:
216 				sServiceSpecifier = FM_COMPONENT_NUMERICFIELD;
217 			    break;
218 
219 			case OBJ_FM_CURRENCYFIELD:
220 				sServiceSpecifier = FM_COMPONENT_CURRENCYFIELD;
221 			    break;
222 
223 			case OBJ_FM_PATTERNFIELD:
224 				sServiceSpecifier = FM_COMPONENT_PATTERNFIELD;
225 			    break;
226 
227 			case OBJ_FM_HIDDEN:
228 				sServiceSpecifier = FM_COMPONENT_HIDDEN;
229 			    break;
230 
231 			case OBJ_FM_IMAGECONTROL:
232 				sServiceSpecifier = FM_COMPONENT_IMAGECONTROL;
233 			    break;
234 
235 			case OBJ_FM_FORMATTEDFIELD:
236 				sServiceSpecifier = FM_COMPONENT_FORMATTEDFIELD;
237 			    break;
238 
239             case OBJ_FM_NAVIGATIONBAR:
240                 sServiceSpecifier = FM_SUN_COMPONENT_NAVIGATIONBAR;
241                 break;
242 
243             case OBJ_FM_SCROLLBAR:
244                 sServiceSpecifier = FM_SUN_COMPONENT_SCROLLBAR;
245                 aInitialProperties.push_back( PropertyValueArray::value_type( FM_PROP_BORDER, makeAny( (sal_Int16)0 ) ) );
246                 break;
247 
248             case OBJ_FM_SPINBUTTON:
249                 sServiceSpecifier = FM_SUN_COMPONENT_SPINBUTTON;
250                 aInitialProperties.push_back( PropertyValueArray::value_type( FM_PROP_BORDER, makeAny( (sal_Int16)0 ) ) );
251                 break;
252 		}
253 
254         // create the actual object
255         if ( sServiceSpecifier.getLength() )
256 			pObjFactory->pNewObj = new FmFormObj( sServiceSpecifier, pObjFactory->nIdentifier );
257         else
258 			pObjFactory->pNewObj = new FmFormObj( pObjFactory->nIdentifier );
259 
260         // initialize some properties which we want to differ from the defaults
261         for (   PropertyValueArray::const_iterator aInitProp = aInitialProperties.begin();
262                 aInitProp != aInitialProperties.end();
263                 ++aInitProp
264             )
265         {
266             lcl_initProperty(
267                 static_cast< FmFormObj* >( pObjFactory->pNewObj ),
268                 aInitProp->first,
269                 aInitProp->second
270             );
271 		}
272 	}
273 
274 	return 0;
275 }
276 
277 
278 
279