1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ 2 /* 3 * This file is part of the LibreOffice project. 4 * 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/. 8 * 9 * This file incorporates work covered by the following license notice: 10 * 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 . 18 */ 19 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> 28 29 namespace basctl 30 { 31 32 using namespace ::com::sun::star; 33 34 35 DlgEdFactory::DlgEdFactory( const css::uno::Reference< css::frame::XModel >& xModel ) : mxModel( xModel ) 36 { 37 SdrObjFactory::InsertMakeObjectHdl( LINK(this, DlgEdFactory, MakeObject) ); 38 } 39 40 41 DlgEdFactory::~DlgEdFactory() COVERITY_NOEXCEPT_FALSE 42 { 43 SdrObjFactory::RemoveMakeObjectHdl( LINK(this, DlgEdFactory, MakeObject) ); 44 } 45 46 47 IMPL_LINK( DlgEdFactory, MakeObject, SdrObjCreatorParams, aParams, SdrObject* ) 48 { 49 static bool bNeedsInit = true; 50 static uno::Reference< lang::XMultiServiceFactory > xDialogSFact; 51 52 if( bNeedsInit ) 53 { 54 uno::Reference< uno::XComponentContext> xContext = ::comphelper::getProcessComponentContext(); 55 uno::Reference< container::XNameContainer > xC( xContext->getServiceManager()->createInstanceWithContext( "com.sun.star.awt.UnoControlDialogModel", xContext ), uno::UNO_QUERY ); 56 if( xC.is() ) 57 { 58 uno::Reference< lang::XMultiServiceFactory > xModFact( xC, uno::UNO_QUERY ); 59 xDialogSFact = xModFact; 60 } 61 bNeedsInit = false; 62 } 63 64 SdrObject* pNewObj = nullptr; 65 if( (aParams.nInventor == SdrInventor::BasicDialog) && 66 (aParams.nObjIdentifier >= OBJ_DLG_PUSHBUTTON) && 67 (aParams.nObjIdentifier <= OBJ_DLG_FORMHSCROLL) ) 68 { 69 switch( aParams.nObjIdentifier ) 70 { 71 case OBJ_DLG_PUSHBUTTON: 72 pNewObj = new DlgEdObj(aParams.rSdrModel, "com.sun.star.awt.UnoControlButtonModel", xDialogSFact ); 73 break; 74 case OBJ_DLG_RADIOBUTTON: 75 pNewObj = new DlgEdObj(aParams.rSdrModel, "com.sun.star.awt.UnoControlRadioButtonModel", xDialogSFact ); 76 break; 77 case OBJ_DLG_FORMRADIO: 78 pNewObj = new DlgEdObj(aParams.rSdrModel, "com.sun.star.form.component.RadioButton", xDialogSFact ); 79 static_cast< DlgEdObj* >( pNewObj )->MakeDataAware( mxModel ); 80 break; 81 case OBJ_DLG_CHECKBOX: 82 pNewObj = new DlgEdObj(aParams.rSdrModel, "com.sun.star.awt.UnoControlCheckBoxModel", xDialogSFact ); 83 break; 84 case OBJ_DLG_FORMCHECK: 85 pNewObj = new DlgEdObj(aParams.rSdrModel, "com.sun.star.form.component.CheckBox", xDialogSFact ); 86 static_cast< DlgEdObj* >( pNewObj )->MakeDataAware( mxModel ); 87 break; 88 case OBJ_DLG_LISTBOX: 89 pNewObj = new DlgEdObj(aParams.rSdrModel, "com.sun.star.awt.UnoControlListBoxModel", xDialogSFact ); 90 break; 91 case OBJ_DLG_FORMLIST: 92 pNewObj = new DlgEdObj(aParams.rSdrModel, "com.sun.star.form.component.ListBox", xDialogSFact ); 93 static_cast< DlgEdObj* >( pNewObj )->MakeDataAware( mxModel ); 94 break; 95 case OBJ_DLG_FORMCOMBO: 96 case OBJ_DLG_COMBOBOX: 97 { 98 DlgEdObj* pNew = nullptr; 99 if ( aParams.nObjIdentifier == OBJ_DLG_COMBOBOX ) 100 pNew = new DlgEdObj(aParams.rSdrModel, "com.sun.star.awt.UnoControlComboBoxModel", xDialogSFact ); 101 else 102 { 103 pNew = new DlgEdObj(aParams.rSdrModel, "com.sun.star.form.component.ComboBox", xDialogSFact ); 104 pNew->MakeDataAware( mxModel ); 105 } 106 pNewObj = pNew; 107 try 108 { 109 uno::Reference< beans::XPropertySet > xPSet(pNew->GetUnoControlModel(), uno::UNO_QUERY); 110 if (xPSet.is()) 111 { 112 xPSet->setPropertyValue( DLGED_PROP_DROPDOWN, uno::Any(true)); 113 } 114 } 115 catch(...) 116 { 117 } 118 } 119 break; 120 case OBJ_DLG_GROUPBOX: 121 pNewObj = new DlgEdObj(aParams.rSdrModel, "com.sun.star.awt.UnoControlGroupBoxModel", xDialogSFact ); 122 break; 123 case OBJ_DLG_EDIT: 124 pNewObj = new DlgEdObj(aParams.rSdrModel, "com.sun.star.awt.UnoControlEditModel", xDialogSFact ); 125 break; 126 case OBJ_DLG_FIXEDTEXT: 127 pNewObj = new DlgEdObj(aParams.rSdrModel, "com.sun.star.awt.UnoControlFixedTextModel", xDialogSFact ); 128 break; 129 case OBJ_DLG_IMAGECONTROL: 130 pNewObj = new DlgEdObj(aParams.rSdrModel, "com.sun.star.awt.UnoControlImageControlModel", xDialogSFact ); 131 break; 132 case OBJ_DLG_PROGRESSBAR: 133 pNewObj = new DlgEdObj(aParams.rSdrModel, "com.sun.star.awt.UnoControlProgressBarModel", xDialogSFact ); 134 break; 135 case OBJ_DLG_HSCROLLBAR: 136 pNewObj = new DlgEdObj(aParams.rSdrModel, "com.sun.star.awt.UnoControlScrollBarModel", xDialogSFact ); 137 break; 138 case OBJ_DLG_FORMHSCROLL: 139 pNewObj = new DlgEdObj(aParams.rSdrModel, "com.sun.star.form.component.ScrollBar", xDialogSFact ); 140 static_cast< DlgEdObj* >( pNewObj )->MakeDataAware( mxModel ); 141 break; 142 case OBJ_DLG_FORMVSCROLL: 143 case OBJ_DLG_VSCROLLBAR: 144 { 145 DlgEdObj* pNew = nullptr; 146 if ( aParams.nObjIdentifier == OBJ_DLG_VSCROLLBAR ) 147 pNew = new DlgEdObj(aParams.rSdrModel, "com.sun.star.awt.UnoControlScrollBarModel", xDialogSFact ); 148 else 149 { 150 pNew = new DlgEdObj(aParams.rSdrModel, "com.sun.star.form.component.ScrollBar", xDialogSFact ); 151 pNew->MakeDataAware( mxModel ); 152 } 153 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 xPSet->setPropertyValue( DLGED_PROP_ORIENTATION, uno::Any(sal_Int32(css::awt::ScrollBarOrientation::VERTICAL)) ); 161 } 162 } 163 catch(...) 164 { 165 } 166 } break; 167 case OBJ_DLG_HFIXEDLINE: 168 pNewObj = new DlgEdObj(aParams.rSdrModel, "com.sun.star.awt.UnoControlFixedLineModel", xDialogSFact ); 169 break; 170 case OBJ_DLG_VFIXEDLINE: 171 { 172 DlgEdObj* pNew = new DlgEdObj(aParams.rSdrModel, "com.sun.star.awt.UnoControlFixedLineModel", xDialogSFact ); 173 pNewObj = pNew; 174 // set vertical orientation 175 try 176 { 177 uno::Reference< beans::XPropertySet > xPSet(pNew->GetUnoControlModel(), uno::UNO_QUERY); 178 if (xPSet.is()) 179 { 180 xPSet->setPropertyValue( DLGED_PROP_ORIENTATION, uno::Any(sal_Int32(1)) ); 181 } 182 } 183 catch(...) 184 { 185 } 186 } break; 187 case OBJ_DLG_DATEFIELD: 188 pNewObj = new DlgEdObj(aParams.rSdrModel, "com.sun.star.awt.UnoControlDateFieldModel", xDialogSFact ); 189 break; 190 case OBJ_DLG_TIMEFIELD: 191 pNewObj = new DlgEdObj(aParams.rSdrModel, "com.sun.star.awt.UnoControlTimeFieldModel", xDialogSFact ); 192 break; 193 case OBJ_DLG_NUMERICFIELD: 194 pNewObj = new DlgEdObj(aParams.rSdrModel, "com.sun.star.awt.UnoControlNumericFieldModel", xDialogSFact ); 195 break; 196 case OBJ_DLG_CURRENCYFIELD: 197 pNewObj = new DlgEdObj(aParams.rSdrModel, "com.sun.star.awt.UnoControlCurrencyFieldModel", xDialogSFact ); 198 break; 199 case OBJ_DLG_FORMATTEDFIELD: 200 pNewObj = new DlgEdObj(aParams.rSdrModel, "com.sun.star.awt.UnoControlFormattedFieldModel", xDialogSFact ); 201 break; 202 case OBJ_DLG_PATTERNFIELD: 203 pNewObj = new DlgEdObj(aParams.rSdrModel, "com.sun.star.awt.UnoControlPatternFieldModel", xDialogSFact ); 204 break; 205 case OBJ_DLG_FILECONTROL: 206 pNewObj = new DlgEdObj(aParams.rSdrModel, "com.sun.star.awt.UnoControlFileControlModel", xDialogSFact ); 207 break; 208 case OBJ_DLG_SPINBUTTON: 209 pNewObj = new DlgEdObj(aParams.rSdrModel, "com.sun.star.awt.UnoControlSpinButtonModel", xDialogSFact ); 210 break; 211 case OBJ_DLG_FORMSPIN: 212 pNewObj = new DlgEdObj(aParams.rSdrModel, "com.sun.star.form.component.SpinButton", xDialogSFact ); 213 static_cast< DlgEdObj* >( pNewObj )->MakeDataAware( mxModel ); 214 break; 215 case OBJ_DLG_TREECONTROL: 216 pNewObj = new DlgEdObj(aParams.rSdrModel, "com.sun.star.awt.tree.TreeControlModel", xDialogSFact ); 217 break; 218 case OBJ_DLG_GRIDCONTROL: 219 pNewObj = new DlgEdObj(aParams.rSdrModel, "com.sun.star.awt.grid.UnoControlGridModel", xDialogSFact ); 220 break; 221 case OBJ_DLG_HYPERLINKCONTROL: 222 pNewObj = new DlgEdObj(aParams.rSdrModel, "com.sun.star.awt.UnoControlFixedHyperlinkModel", xDialogSFact ); 223 break; 224 default: 225 break; 226 227 } 228 } 229 return pNewObj; 230 } 231 232 } // namespace basctl 233 234 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ 235
