Coverage Report

Created: 2025-12-31 10:39

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/svx/source/form/fmobjfac.cxx
Line
Count
Source
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 <config_features.h>
21
#include <config_fuzzers.h>
22
23
#include <comphelper/diagnose_ex.hxx>
24
#include <svx/svdobj.hxx>
25
#include <svx/fmtools.hxx>
26
#include <fmservs.hxx>
27
28
#include <svx/fmobjfac.hxx>
29
30
#include <svx/svdobjkind.hxx>
31
32
#include <fmobj.hxx>
33
34
#include <svx/fmshell.hxx>
35
36
#include <svx/svxids.hrc>
37
#include <tbxform.hxx>
38
39
#include <tabwin.hxx>
40
#include <fmexpl.hxx>
41
#include <filtnav.hxx>
42
43
#include <fmprop.hxx>
44
#include <fmPropBrw.hxx>
45
#include <datanavi.hxx>
46
47
using namespace ::com::sun::star::uno;
48
using namespace ::com::sun::star::beans;
49
using namespace ::svxform;
50
51
static bool bInit = false;
52
53
FmFormObjFactory::FmFormObjFactory()
54
26
{
55
26
    if ( bInit )
56
0
        return;
57
58
26
    SdrObjFactory::InsertMakeObjectHdl(LINK(this, FmFormObjFactory, MakeObject));
59
60
61
    // register the configuration css::frame::Controller and the NavigationBar
62
26
    SvxFmTbxCtlAbsRec::RegisterControl( SID_FM_RECORD_ABSOLUTE );
63
26
    SvxFmTbxCtlRecText::RegisterControl( SID_FM_RECORD_TEXT );
64
26
    SvxFmTbxCtlRecFromText::RegisterControl( SID_FM_RECORD_FROM_TEXT );
65
26
    SvxFmTbxCtlRecTotal::RegisterControl( SID_FM_RECORD_TOTAL );
66
26
    SvxFmTbxPrevRec::RegisterControl( SID_FM_RECORD_PREV );
67
26
    SvxFmTbxNextRec::RegisterControl( SID_FM_RECORD_NEXT );
68
69
    // registering global windows
70
26
    FmFieldWinMgr::RegisterChildWindow();
71
26
    FmPropBrwMgr::RegisterChildWindow();
72
26
    NavigatorFrameManager::RegisterChildWindow();
73
26
    DataNavigatorManager::RegisterChildWindow();
74
#if HAVE_FEATURE_DBCONNECTIVITY && !ENABLE_FUZZERS
75
    FmFilterNavigatorWinMgr::RegisterChildWindow();
76
#endif
77
78
    // register the interface for the Formshell
79
26
    FmFormShell::RegisterInterface();
80
81
26
    ImplSmartRegisterUnoServices();
82
26
    bInit = true;
83
26
}
84
85
// create css::form::Form objects
86
namespace
87
{
88
    void    lcl_initProperty( FmFormObj const * _pObject, const OUString& _rPropName, const Any& _rValue )
89
0
    {
90
0
        try
91
0
        {
92
0
            Reference< XPropertySet >  xModelSet( _pObject->GetUnoControlModel(), UNO_QUERY );
93
0
            if ( xModelSet.is() )
94
0
                xModelSet->setPropertyValue( _rPropName, _rValue );
95
0
        }
96
0
        catch( const Exception& )
97
0
        {
98
0
            TOOLS_WARN_EXCEPTION( "svx", "lcl_initProperty" );
99
0
        }
100
0
    }
101
}
102
103
IMPL_STATIC_LINK(FmFormObjFactory, MakeObject, SdrObjCreatorParams, aParams, rtl::Reference<SdrObject>)
104
0
{
105
0
    rtl::Reference<SdrObject> pNewObj;
106
107
0
    if (aParams.nInventor == SdrInventor::FmForm)
108
0
    {
109
0
        OUString sServiceSpecifier;
110
111
0
        typedef ::std::vector< ::std::pair< OUString, Any > > PropertyValueArray;
112
0
        PropertyValueArray aInitialProperties;
113
114
0
        switch ( aParams.nObjIdentifier )
115
0
        {
116
0
            case SdrObjKind::FormEdit:
117
0
                sServiceSpecifier = FM_COMPONENT_EDIT;
118
0
                break;
119
120
0
            case SdrObjKind::FormButton:
121
0
                sServiceSpecifier = FM_COMPONENT_COMMANDBUTTON;
122
0
                break;
123
124
0
            case SdrObjKind::FormFixedText:
125
0
                sServiceSpecifier = FM_COMPONENT_FIXEDTEXT;
126
0
                break;
127
128
0
            case SdrObjKind::FormListbox:
129
0
                sServiceSpecifier = FM_COMPONENT_LISTBOX;
130
0
                break;
131
132
0
            case SdrObjKind::FormCheckbox:
133
0
                sServiceSpecifier = FM_COMPONENT_CHECKBOX;
134
0
                break;
135
136
0
            case SdrObjKind::FormRadioButton:
137
0
                sServiceSpecifier = FM_COMPONENT_RADIOBUTTON;
138
0
                break;
139
140
0
            case SdrObjKind::FormGroupBox:
141
0
                sServiceSpecifier = FM_COMPONENT_GROUPBOX;
142
0
                break;
143
144
0
            case SdrObjKind::FormCombobox:
145
0
                sServiceSpecifier = FM_COMPONENT_COMBOBOX;
146
0
                break;
147
148
0
            case SdrObjKind::FormGrid:
149
0
                sServiceSpecifier = FM_COMPONENT_GRID;
150
0
                break;
151
152
0
            case SdrObjKind::FormImageButton:
153
0
                sServiceSpecifier = FM_COMPONENT_IMAGEBUTTON;
154
0
                break;
155
156
0
            case SdrObjKind::FormFileControl:
157
0
                sServiceSpecifier = FM_COMPONENT_FILECONTROL;
158
0
                break;
159
160
0
            case SdrObjKind::FormDateField:
161
0
                sServiceSpecifier = FM_COMPONENT_DATEFIELD;
162
0
                break;
163
164
0
            case SdrObjKind::FormTimeField:
165
0
                sServiceSpecifier = FM_COMPONENT_TIMEFIELD;
166
0
                aInitialProperties.emplace_back( FM_PROP_TIMEMAX, Any( tools::Time( 23, 59, 59, 999999999 ).GetUNOTime() ) );
167
0
                break;
168
169
0
            case SdrObjKind::FormNumericField:
170
0
                sServiceSpecifier = FM_COMPONENT_NUMERICFIELD;
171
0
                break;
172
173
0
            case SdrObjKind::FormCurrencyField:
174
0
                sServiceSpecifier = FM_COMPONENT_CURRENCYFIELD;
175
0
                break;
176
177
0
            case SdrObjKind::FormPatternField:
178
0
                sServiceSpecifier = FM_COMPONENT_PATTERNFIELD;
179
0
                break;
180
181
0
            case SdrObjKind::FormHidden:
182
0
                sServiceSpecifier = FM_COMPONENT_HIDDEN;
183
0
                break;
184
185
0
            case SdrObjKind::FormImageControl:
186
0
                sServiceSpecifier = FM_COMPONENT_IMAGECONTROL;
187
0
                break;
188
189
0
            case SdrObjKind::FormFormattedField:
190
0
                sServiceSpecifier = FM_COMPONENT_FORMATTEDFIELD;
191
0
                break;
192
193
0
            case SdrObjKind::FormNavigationBar:
194
0
                sServiceSpecifier = FM_SUN_COMPONENT_NAVIGATIONBAR;
195
0
                break;
196
197
0
            case SdrObjKind::FormScrollbar:
198
0
                sServiceSpecifier = FM_SUN_COMPONENT_SCROLLBAR;
199
0
                aInitialProperties.emplace_back( FM_PROP_BORDER, Any( sal_Int16(0) ) );
200
0
                break;
201
202
0
            case SdrObjKind::FormSpinButton:
203
0
                sServiceSpecifier = FM_SUN_COMPONENT_SPINBUTTON;
204
0
                aInitialProperties.emplace_back( FM_PROP_BORDER, Any( sal_Int16(0) ) );
205
0
                break;
206
207
0
            default:
208
0
                break;
209
0
        }
210
211
        // create the actual object
212
0
        if ( !sServiceSpecifier.isEmpty() )
213
0
            pNewObj = new FmFormObj(aParams.rSdrModel, sServiceSpecifier);
214
0
        else
215
0
            pNewObj = new FmFormObj(aParams.rSdrModel);
216
217
        // initialize some properties which we want to differ from the defaults
218
0
        for (const auto& rInitProp : aInitialProperties)
219
0
        {
220
0
            lcl_initProperty(
221
0
                static_cast< FmFormObj* >( pNewObj.get() ),
222
0
                rInitProp.first,
223
0
                rInitProp.second
224
0
            );
225
0
        }
226
0
    }
227
0
    return pNewObj;
228
0
}
229
230
231
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */