Use COMReference to handle COM pointers in CreateShortcut
[LibreOffice.git] / svx / source / form / fmobjfac.cxx
blob459350663aee889d7b9b4f879d37d429b72c62a5
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <config_features.h>
21 #include <config_fuzzers.h>
23 #include <comphelper/diagnose_ex.hxx>
24 #include <svx/svdobj.hxx>
25 #include <svx/fmtools.hxx>
26 #include <fmservs.hxx>
28 #include <svx/fmobjfac.hxx>
30 #include <svx/svdobjkind.hxx>
32 #include <fmobj.hxx>
34 #include <svx/fmshell.hxx>
36 #include <svx/svxids.hrc>
37 #include <tbxform.hxx>
39 #include <tabwin.hxx>
40 #include <fmexpl.hxx>
41 #include <filtnav.hxx>
43 #include <fmprop.hxx>
44 #include <fmPropBrw.hxx>
45 #include <datanavi.hxx>
47 using namespace ::com::sun::star::uno;
48 using namespace ::com::sun::star::beans;
49 using namespace ::svxform;
51 static bool bInit = false;
53 FmFormObjFactory::FmFormObjFactory()
55 if ( bInit )
56 return;
58 SdrObjFactory::InsertMakeObjectHdl(LINK(this, FmFormObjFactory, MakeObject));
61 // register the configuration css::frame::Controller and the NavigationBar
62 SvxFmTbxCtlAbsRec::RegisterControl( SID_FM_RECORD_ABSOLUTE );
63 SvxFmTbxCtlRecText::RegisterControl( SID_FM_RECORD_TEXT );
64 SvxFmTbxCtlRecFromText::RegisterControl( SID_FM_RECORD_FROM_TEXT );
65 SvxFmTbxCtlRecTotal::RegisterControl( SID_FM_RECORD_TOTAL );
66 SvxFmTbxPrevRec::RegisterControl( SID_FM_RECORD_PREV );
67 SvxFmTbxNextRec::RegisterControl( SID_FM_RECORD_NEXT );
69 // registering global windows
70 FmFieldWinMgr::RegisterChildWindow();
71 FmPropBrwMgr::RegisterChildWindow();
72 NavigatorFrameManager::RegisterChildWindow();
73 DataNavigatorManager::RegisterChildWindow();
74 #if HAVE_FEATURE_DBCONNECTIVITY && !ENABLE_FUZZERS
75 FmFilterNavigatorWinMgr::RegisterChildWindow();
76 #endif
78 // register the interface for the Formshell
79 FmFormShell::RegisterInterface();
81 ImplSmartRegisterUnoServices();
82 bInit = true;
85 // create css::form::Form objects
86 namespace
88 void lcl_initProperty( FmFormObj const * _pObject, const OUString& _rPropName, const Any& _rValue )
90 try
92 Reference< XPropertySet > xModelSet( _pObject->GetUnoControlModel(), UNO_QUERY );
93 if ( xModelSet.is() )
94 xModelSet->setPropertyValue( _rPropName, _rValue );
96 catch( const Exception& )
98 TOOLS_WARN_EXCEPTION( "svx", "lcl_initProperty" );
103 IMPL_STATIC_LINK(FmFormObjFactory, MakeObject, SdrObjCreatorParams, aParams, rtl::Reference<SdrObject>)
105 rtl::Reference<SdrObject> pNewObj;
107 if (aParams.nInventor == SdrInventor::FmForm)
109 OUString sServiceSpecifier;
111 typedef ::std::vector< ::std::pair< OUString, Any > > PropertyValueArray;
112 PropertyValueArray aInitialProperties;
114 switch ( aParams.nObjIdentifier )
116 case SdrObjKind::FormEdit:
117 sServiceSpecifier = FM_COMPONENT_EDIT;
118 break;
120 case SdrObjKind::FormButton:
121 sServiceSpecifier = FM_COMPONENT_COMMANDBUTTON;
122 break;
124 case SdrObjKind::FormFixedText:
125 sServiceSpecifier = FM_COMPONENT_FIXEDTEXT;
126 break;
128 case SdrObjKind::FormListbox:
129 sServiceSpecifier = FM_COMPONENT_LISTBOX;
130 break;
132 case SdrObjKind::FormCheckbox:
133 sServiceSpecifier = FM_COMPONENT_CHECKBOX;
134 break;
136 case SdrObjKind::FormRadioButton:
137 sServiceSpecifier = FM_COMPONENT_RADIOBUTTON;
138 break;
140 case SdrObjKind::FormGroupBox:
141 sServiceSpecifier = FM_COMPONENT_GROUPBOX;
142 break;
144 case SdrObjKind::FormCombobox:
145 sServiceSpecifier = FM_COMPONENT_COMBOBOX;
146 break;
148 case SdrObjKind::FormGrid:
149 sServiceSpecifier = FM_COMPONENT_GRID;
150 break;
152 case SdrObjKind::FormImageButton:
153 sServiceSpecifier = FM_COMPONENT_IMAGEBUTTON;
154 break;
156 case SdrObjKind::FormFileControl:
157 sServiceSpecifier = FM_COMPONENT_FILECONTROL;
158 break;
160 case SdrObjKind::FormDateField:
161 sServiceSpecifier = FM_COMPONENT_DATEFIELD;
162 break;
164 case SdrObjKind::FormTimeField:
165 sServiceSpecifier = FM_COMPONENT_TIMEFIELD;
166 aInitialProperties.emplace_back( FM_PROP_TIMEMAX, Any( tools::Time( 23, 59, 59, 999999999 ).GetUNOTime() ) );
167 break;
169 case SdrObjKind::FormNumericField:
170 sServiceSpecifier = FM_COMPONENT_NUMERICFIELD;
171 break;
173 case SdrObjKind::FormCurrencyField:
174 sServiceSpecifier = FM_COMPONENT_CURRENCYFIELD;
175 break;
177 case SdrObjKind::FormPatternField:
178 sServiceSpecifier = FM_COMPONENT_PATTERNFIELD;
179 break;
181 case SdrObjKind::FormHidden:
182 sServiceSpecifier = FM_COMPONENT_HIDDEN;
183 break;
185 case SdrObjKind::FormImageControl:
186 sServiceSpecifier = FM_COMPONENT_IMAGECONTROL;
187 break;
189 case SdrObjKind::FormFormattedField:
190 sServiceSpecifier = FM_COMPONENT_FORMATTEDFIELD;
191 break;
193 case SdrObjKind::FormNavigationBar:
194 sServiceSpecifier = FM_SUN_COMPONENT_NAVIGATIONBAR;
195 break;
197 case SdrObjKind::FormScrollbar:
198 sServiceSpecifier = FM_SUN_COMPONENT_SCROLLBAR;
199 aInitialProperties.emplace_back( FM_PROP_BORDER, Any( sal_Int16(0) ) );
200 break;
202 case SdrObjKind::FormSpinButton:
203 sServiceSpecifier = FM_SUN_COMPONENT_SPINBUTTON;
204 aInitialProperties.emplace_back( FM_PROP_BORDER, Any( sal_Int16(0) ) );
205 break;
207 default:
208 break;
211 // create the actual object
212 if ( !sServiceSpecifier.isEmpty() )
213 pNewObj = new FmFormObj(aParams.rSdrModel, sServiceSpecifier);
214 else
215 pNewObj = new FmFormObj(aParams.rSdrModel);
217 // initialize some properties which we want to differ from the defaults
218 for (const auto& rInitProp : aInitialProperties)
220 lcl_initProperty(
221 static_cast< FmFormObj* >( pNewObj.get() ),
222 rInitProp.first,
223 rInitProp.second
227 return pNewObj;
231 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */