LanguageTool: don't crash if REST protocol isn't set
[LibreOffice.git] / basctl / source / dlged / dlgedfac.cxx
blob98c0f260b0f9ed0940efe8d227b7242d0bf4441e
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 <dlgedfac.hxx>
21 #include <dlgedobj.hxx>
22 #include <dlgeddef.hxx>
23 #include <com/sun/star/container/XNameContainer.hpp>
24 #include <com/sun/star/beans/XPropertySet.hpp>
25 #include <com/sun/star/awt/ScrollBarOrientation.hpp>
26 #include <com/sun/star/uno/XComponentContext.hpp>
27 #include <comphelper/processfactory.hxx>
29 namespace basctl
32 using namespace ::com::sun::star;
35 DlgEdFactory::DlgEdFactory( const css::uno::Reference< css::frame::XModel >& xModel ) : mxModel( xModel )
37 SdrObjFactory::InsertMakeObjectHdl( LINK(this, DlgEdFactory, MakeObject) );
41 DlgEdFactory::~DlgEdFactory() COVERITY_NOEXCEPT_FALSE
43 SdrObjFactory::RemoveMakeObjectHdl( LINK(this, DlgEdFactory, MakeObject) );
47 IMPL_LINK( DlgEdFactory, MakeObject, SdrObjCreatorParams, aParams, SdrObject* )
49 static const uno::Reference<lang::XMultiServiceFactory> xDialogSFact = [] {
50 uno::Reference<lang::XMultiServiceFactory> xFact;
51 uno::Reference< uno::XComponentContext> xContext = ::comphelper::getProcessComponentContext();
52 uno::Reference< container::XNameContainer > xC( xContext->getServiceManager()->createInstanceWithContext( "com.sun.star.awt.UnoControlDialogModel", xContext ), uno::UNO_QUERY );
53 if( xC.is() )
55 uno::Reference< lang::XMultiServiceFactory > xModFact( xC, uno::UNO_QUERY );
56 xFact = xModFact;
58 return xFact;
59 }();
61 SdrObject* pNewObj = nullptr;
62 if( (aParams.nInventor == SdrInventor::BasicDialog) &&
63 (aParams.nObjIdentifier >= OBJ_DLG_PUSHBUTTON) &&
64 (aParams.nObjIdentifier <= OBJ_DLG_FORMHSCROLL) )
66 switch( aParams.nObjIdentifier )
68 case OBJ_DLG_PUSHBUTTON:
69 pNewObj = new DlgEdObj(aParams.rSdrModel, "com.sun.star.awt.UnoControlButtonModel", xDialogSFact );
70 break;
71 case OBJ_DLG_RADIOBUTTON:
72 pNewObj = new DlgEdObj(aParams.rSdrModel, "com.sun.star.awt.UnoControlRadioButtonModel", xDialogSFact );
73 break;
74 case OBJ_DLG_FORMRADIO:
75 pNewObj = new DlgEdObj(aParams.rSdrModel, "com.sun.star.form.component.RadioButton", xDialogSFact );
76 static_cast< DlgEdObj* >( pNewObj )->MakeDataAware( mxModel );
77 break;
78 case OBJ_DLG_CHECKBOX:
79 pNewObj = new DlgEdObj(aParams.rSdrModel, "com.sun.star.awt.UnoControlCheckBoxModel", xDialogSFact );
80 break;
81 case OBJ_DLG_FORMCHECK:
82 pNewObj = new DlgEdObj(aParams.rSdrModel, "com.sun.star.form.component.CheckBox", xDialogSFact );
83 static_cast< DlgEdObj* >( pNewObj )->MakeDataAware( mxModel );
84 break;
85 case OBJ_DLG_LISTBOX:
86 pNewObj = new DlgEdObj(aParams.rSdrModel, "com.sun.star.awt.UnoControlListBoxModel", xDialogSFact );
87 break;
88 case OBJ_DLG_FORMLIST:
89 pNewObj = new DlgEdObj(aParams.rSdrModel, "com.sun.star.form.component.ListBox", xDialogSFact );
90 static_cast< DlgEdObj* >( pNewObj )->MakeDataAware( mxModel );
91 break;
92 case OBJ_DLG_FORMCOMBO:
93 case OBJ_DLG_COMBOBOX:
95 DlgEdObj* pNew = nullptr;
96 if ( aParams.nObjIdentifier == OBJ_DLG_COMBOBOX )
97 pNew = new DlgEdObj(aParams.rSdrModel, "com.sun.star.awt.UnoControlComboBoxModel", xDialogSFact );
98 else
100 pNew = new DlgEdObj(aParams.rSdrModel, "com.sun.star.form.component.ComboBox", xDialogSFact );
101 pNew->MakeDataAware( mxModel );
103 pNewObj = pNew;
106 uno::Reference< beans::XPropertySet > xPSet(pNew->GetUnoControlModel(), uno::UNO_QUERY);
107 if (xPSet.is())
109 xPSet->setPropertyValue( DLGED_PROP_DROPDOWN, uno::Any(true));
112 catch(...)
116 break;
117 case OBJ_DLG_GROUPBOX:
118 pNewObj = new DlgEdObj(aParams.rSdrModel, "com.sun.star.awt.UnoControlGroupBoxModel", xDialogSFact );
119 break;
120 case OBJ_DLG_EDIT:
121 pNewObj = new DlgEdObj(aParams.rSdrModel, "com.sun.star.awt.UnoControlEditModel", xDialogSFact );
122 break;
123 case OBJ_DLG_FIXEDTEXT:
124 pNewObj = new DlgEdObj(aParams.rSdrModel, "com.sun.star.awt.UnoControlFixedTextModel", xDialogSFact );
125 break;
126 case OBJ_DLG_IMAGECONTROL:
127 pNewObj = new DlgEdObj(aParams.rSdrModel, "com.sun.star.awt.UnoControlImageControlModel", xDialogSFact );
128 break;
129 case OBJ_DLG_PROGRESSBAR:
130 pNewObj = new DlgEdObj(aParams.rSdrModel, "com.sun.star.awt.UnoControlProgressBarModel", xDialogSFact );
131 break;
132 case OBJ_DLG_HSCROLLBAR:
133 pNewObj = new DlgEdObj(aParams.rSdrModel, "com.sun.star.awt.UnoControlScrollBarModel", xDialogSFact );
134 break;
135 case OBJ_DLG_FORMHSCROLL:
136 pNewObj = new DlgEdObj(aParams.rSdrModel, "com.sun.star.form.component.ScrollBar", xDialogSFact );
137 static_cast< DlgEdObj* >( pNewObj )->MakeDataAware( mxModel );
138 break;
139 case OBJ_DLG_FORMVSCROLL:
140 case OBJ_DLG_VSCROLLBAR:
142 DlgEdObj* pNew = nullptr;
143 if ( aParams.nObjIdentifier == OBJ_DLG_VSCROLLBAR )
144 pNew = new DlgEdObj(aParams.rSdrModel, "com.sun.star.awt.UnoControlScrollBarModel", xDialogSFact );
145 else
147 pNew = new DlgEdObj(aParams.rSdrModel, "com.sun.star.form.component.ScrollBar", xDialogSFact );
148 pNew->MakeDataAware( mxModel );
150 pNewObj = pNew;
151 // set vertical orientation
154 uno::Reference< beans::XPropertySet > xPSet(pNew->GetUnoControlModel(), uno::UNO_QUERY);
155 if (xPSet.is())
157 xPSet->setPropertyValue( DLGED_PROP_ORIENTATION, uno::Any(sal_Int32(css::awt::ScrollBarOrientation::VERTICAL)) );
160 catch(...)
163 } break;
164 case OBJ_DLG_HFIXEDLINE:
165 pNewObj = new DlgEdObj(aParams.rSdrModel, "com.sun.star.awt.UnoControlFixedLineModel", xDialogSFact );
166 break;
167 case OBJ_DLG_VFIXEDLINE:
169 DlgEdObj* pNew = new DlgEdObj(aParams.rSdrModel, "com.sun.star.awt.UnoControlFixedLineModel", xDialogSFact );
170 pNewObj = pNew;
171 // set vertical orientation
174 uno::Reference< beans::XPropertySet > xPSet(pNew->GetUnoControlModel(), uno::UNO_QUERY);
175 if (xPSet.is())
177 xPSet->setPropertyValue( DLGED_PROP_ORIENTATION, uno::Any(sal_Int32(1)) );
180 catch(...)
183 } break;
184 case OBJ_DLG_DATEFIELD:
185 pNewObj = new DlgEdObj(aParams.rSdrModel, "com.sun.star.awt.UnoControlDateFieldModel", xDialogSFact );
186 break;
187 case OBJ_DLG_TIMEFIELD:
188 pNewObj = new DlgEdObj(aParams.rSdrModel, "com.sun.star.awt.UnoControlTimeFieldModel", xDialogSFact );
189 break;
190 case OBJ_DLG_NUMERICFIELD:
191 pNewObj = new DlgEdObj(aParams.rSdrModel, "com.sun.star.awt.UnoControlNumericFieldModel", xDialogSFact );
192 break;
193 case OBJ_DLG_CURRENCYFIELD:
194 pNewObj = new DlgEdObj(aParams.rSdrModel, "com.sun.star.awt.UnoControlCurrencyFieldModel", xDialogSFact );
195 break;
196 case OBJ_DLG_FORMATTEDFIELD:
197 pNewObj = new DlgEdObj(aParams.rSdrModel, "com.sun.star.awt.UnoControlFormattedFieldModel", xDialogSFact );
198 break;
199 case OBJ_DLG_PATTERNFIELD:
200 pNewObj = new DlgEdObj(aParams.rSdrModel, "com.sun.star.awt.UnoControlPatternFieldModel", xDialogSFact );
201 break;
202 case OBJ_DLG_FILECONTROL:
203 pNewObj = new DlgEdObj(aParams.rSdrModel, "com.sun.star.awt.UnoControlFileControlModel", xDialogSFact );
204 break;
205 case OBJ_DLG_SPINBUTTON:
206 pNewObj = new DlgEdObj(aParams.rSdrModel, "com.sun.star.awt.UnoControlSpinButtonModel", xDialogSFact );
207 break;
208 case OBJ_DLG_FORMSPIN:
209 pNewObj = new DlgEdObj(aParams.rSdrModel, "com.sun.star.form.component.SpinButton", xDialogSFact );
210 static_cast< DlgEdObj* >( pNewObj )->MakeDataAware( mxModel );
211 break;
212 case OBJ_DLG_TREECONTROL:
213 pNewObj = new DlgEdObj(aParams.rSdrModel, "com.sun.star.awt.tree.TreeControlModel", xDialogSFact );
214 break;
215 case OBJ_DLG_GRIDCONTROL:
216 pNewObj = new DlgEdObj(aParams.rSdrModel, "com.sun.star.awt.grid.UnoControlGridModel", xDialogSFact );
217 break;
218 case OBJ_DLG_HYPERLINKCONTROL:
219 pNewObj = new DlgEdObj(aParams.rSdrModel, "com.sun.star.awt.UnoControlFixedHyperlinkModel", xDialogSFact );
220 break;
221 default:
222 break;
226 return pNewObj;
229 } // namespace basctl
231 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */