Coverage Report

Created: 2025-12-08 09:28

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/sw/source/uibase/utlui/initui.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 <libxml/xmlwriter.h>
21
22
#include <unotools/localedatawrapper.hxx>
23
#include <viewsh.hxx>
24
#include <initui.hxx>
25
#include <edtwin.hxx>
26
#include <shellres.hxx>
27
#include <fldbas.hxx>
28
#include <glosdoc.hxx>
29
#include <gloslst.hxx>
30
#include <comcore.hxx>
31
#include <strings.hrc>
32
#include <utlui.hrc>
33
#include <authfld.hxx>
34
#include <unotools/syslocale.hxx>
35
36
// Global Pointer
37
38
static std::unique_ptr<SwGlossaries> pGlossaries;
39
40
// Provides all needed paths. Is initialized by UI.
41
static SwGlossaryList* pGlossaryList = nullptr;
42
43
namespace
44
{
45
OUString CurrGlosGroup;
46
}
47
48
const OUString& GetCurrGlosGroup()
49
0
{
50
0
    return CurrGlosGroup;
51
0
}
52
53
void SetCurrGlosGroup(const OUString& sStr)
54
0
{
55
0
    CurrGlosGroup = sStr;
56
0
}
57
58
namespace
59
{
60
61
std::vector<OUString>* pAuthFieldNameList = nullptr;
62
std::vector<OUString>* pAuthFieldTypeList = nullptr;
63
64
}
65
66
// Finish UI
67
68
void FinitUI()
69
9
{
70
9
    delete SwViewShell::GetShellRes();
71
9
    SwViewShell::SetShellRes( nullptr );
72
73
9
    SwEditWin::FinitStaticData();
74
75
9
    pGlossaries.reset();
76
77
9
    delete SwFieldType::s_pFieldNames;
78
79
9
    delete pGlossaryList;
80
9
    delete pAuthFieldNameList;
81
9
    delete pAuthFieldTypeList;
82
83
9
}
84
85
// Initialise
86
87
void InitUI()
88
9
{
89
    // ShellResource gives the CORE the possibility to work with resources.
90
9
    SwViewShell::SetShellRes( new ShellResource );
91
9
    SwEditWin::InitStaticData();
92
9
}
93
94
const TranslateId FLD_DOCINFO_ARY[] =
95
{
96
    FLD_DOCINFO_TITLE,
97
    FLD_DOCINFO_SUBJECT,
98
    FLD_DOCINFO_KEYS,
99
    FLD_DOCINFO_COMMENT,
100
    FLD_DOCINFO_CREATE,
101
    FLD_DOCINFO_CHANGE,
102
    FLD_DOCINFO_PRINT,
103
    FLD_DOCINFO_DOCNO,
104
    FLD_DOCINFO_EDIT
105
};
106
107
ShellResource::ShellResource()
108
9
    : aPostItAuthor( SwResId( STR_POSTIT_AUTHOR ) ),
109
9
    aPostItPage( SwResId( STR_POSTIT_PAGE ) ),
110
9
    aPostItLine( SwResId( STR_POSTIT_LINE ) ),
111
112
9
    aCalc_Syntax( SwResId( STR_CALC_SYNTAX ) ),
113
9
    aCalc_ZeroDiv( SwResId( STR_CALC_ZERODIV ) ),
114
9
    aCalc_Brack( SwResId( STR_CALC_BRACK ) ),
115
9
    aCalc_Pow( SwResId( STR_CALC_POW ) ),
116
9
    aCalc_Overflow( SwResId( STR_CALC_OVERFLOW ) ),
117
9
    aCalc_Default( SwResId( STR_CALC_DEFAULT ) ),
118
9
    aCalc_Error( SwResId( STR_CALC_ERROR ) ),
119
120
    // #i81002#
121
9
    aGetRefField_RefItemNotFound( SwResId( STR_GETREFFLD_REFITEMNOTFOUND ) ),
122
9
    aStrNone( SwResId( STR_TEMPLATE_NONE )),
123
9
    aFixedStr( SwResId( STR_FIELD_FIXED )),
124
9
    sDurationFormat( SwResId( STR_DURATION_FORMAT )),
125
126
9
    aTOXIndexName(          SwResId(STR_TOI)),
127
9
    aTOXUserName(           SwResId(STR_TOU)),
128
9
    aTOXContentName(        SwResId(STR_TOC)),
129
9
    aTOXIllustrationsName(  SwResId(STR_TOX_ILL)),
130
9
    aTOXObjectsName(        SwResId(STR_TOX_OBJ)),
131
9
    aTOXTablesName(         SwResId(STR_TOX_TBL)),
132
9
    aTOXAuthoritiesName(    SwResId(STR_TOX_AUTH)),
133
9
    aTOXCitationName(    SwResId(STR_TOX_CITATION)),
134
9
    sPageDescFirstName(     SwResId(STR_PAGEDESC_FIRSTNAME)),
135
9
    sPageDescFollowName(    SwResId(STR_PAGEDESC_FOLLOWNAME)),
136
9
    sPageDescName(          SwResId(STR_PAGEDESC_NAME))
137
9
{
138
9
    for (auto const& aID : FLD_DOCINFO_ARY)
139
81
        aDocInfoLst.push_back(SwResId(aID));
140
9
}
141
142
OUString ShellResource::GetPageDescName(sal_uInt16 nNo, PageNameMode eMode)
143
39.3k
{
144
39.3k
    OUString sRet;
145
146
39.3k
    switch (eMode)
147
39.3k
    {
148
39.3k
        case NORMAL_PAGE:
149
39.3k
            sRet = sPageDescName;
150
39.3k
            break;
151
0
        case FIRST_PAGE:
152
0
            sRet = sPageDescFirstName;
153
0
            break;
154
0
        case FOLLOW_PAGE:
155
0
            sRet = sPageDescFollowName;
156
0
            break;
157
39.3k
    }
158
159
39.3k
    return sRet.replaceFirst( "$(ARG1)", OUString::number( nNo ));
160
39.3k
}
161
162
SwGlossaries* GetGlossaries()
163
0
{
164
0
    if (!pGlossaries)
165
0
        pGlossaries.reset( new SwGlossaries );
166
0
    return pGlossaries.get();
167
0
}
168
169
bool HasGlossaryList()
170
0
{
171
0
    return pGlossaryList != nullptr;
172
0
}
173
174
SwGlossaryList* GetGlossaryList()
175
0
{
176
0
    if(!pGlossaryList)
177
0
        pGlossaryList = new SwGlossaryList();
178
179
0
    return pGlossaryList;
180
0
}
181
182
void ShellResource::GetAutoFormatNameLst_() const
183
0
{
184
0
    assert(!mxAutoFormatNameLst);
185
0
    mxAutoFormatNameLst.emplace();
186
0
    mxAutoFormatNameLst->reserve(STR_AUTOFMTREDL_END);
187
188
0
    static_assert(SAL_N_ELEMENTS(RID_SHELLRES_AUTOFMTSTRS) == STR_AUTOFMTREDL_END);
189
0
    for (sal_uInt16 n = 0; n < STR_AUTOFMTREDL_END; ++n)
190
0
    {
191
0
        OUString p(SwResId(RID_SHELLRES_AUTOFMTSTRS[n]));
192
0
        if (STR_AUTOFMTREDL_TYPO == n)
193
0
        {
194
0
            const SvtSysLocale aSysLocale;
195
0
            const LocaleDataWrapper& rLclD = aSysLocale.GetLocaleData();
196
0
            p = p.replaceFirst("%1", rLclD.getDoubleQuotationMarkStart());
197
0
            p = p.replaceFirst("%2", rLclD.getDoubleQuotationMarkEnd());
198
0
        }
199
0
        mxAutoFormatNameLst->push_back(p);
200
0
    }
201
0
}
202
203
namespace
204
{
205
    const TranslateId STR_AUTH_FIELD_ARY[] =
206
    {
207
        STR_AUTH_FIELD_IDENTIFIER,
208
        STR_AUTH_FIELD_AUTHORITY_TYPE,
209
        STR_AUTH_FIELD_ADDRESS,
210
        STR_AUTH_FIELD_ANNOTE,
211
        STR_AUTH_FIELD_AUTHOR,
212
        STR_AUTH_FIELD_BOOKTITLE,
213
        STR_AUTH_FIELD_CHAPTER,
214
        STR_AUTH_FIELD_EDITION,
215
        STR_AUTH_FIELD_EDITOR,
216
        STR_AUTH_FIELD_HOWPUBLISHED,
217
        STR_AUTH_FIELD_INSTITUTION,
218
        STR_AUTH_FIELD_JOURNAL,
219
        STR_AUTH_FIELD_MONTH,
220
        STR_AUTH_FIELD_NOTE,
221
        STR_AUTH_FIELD_NUMBER,
222
        STR_AUTH_FIELD_ORGANIZATIONS,
223
        STR_AUTH_FIELD_PAGES,
224
        STR_AUTH_FIELD_PUBLISHER,
225
        STR_AUTH_FIELD_SCHOOL,
226
        STR_AUTH_FIELD_SERIES,
227
        STR_AUTH_FIELD_TITLE,
228
        STR_AUTH_FIELD_TYPE,
229
        STR_AUTH_FIELD_VOLUME,
230
        STR_AUTH_FIELD_YEAR,
231
        STR_AUTH_FIELD_URL,
232
        STR_AUTH_FIELD_CUSTOM1,
233
        STR_AUTH_FIELD_CUSTOM2,
234
        STR_AUTH_FIELD_CUSTOM3,
235
        STR_AUTH_FIELD_CUSTOM4,
236
        STR_AUTH_FIELD_CUSTOM5,
237
        STR_AUTH_FIELD_ISBN,
238
        STR_AUTH_FIELD_LOCAL_URL,
239
        STR_AUTH_FIELD_TARGET_TYPE,
240
        STR_AUTH_FIELD_TARGET_URL,
241
    };
242
}
243
244
OUString const & SwAuthorityFieldType::GetAuthFieldName(ToxAuthorityField eType)
245
0
{
246
0
    if(!pAuthFieldNameList)
247
0
    {
248
0
        pAuthFieldNameList = new std::vector<OUString>;
249
0
        pAuthFieldNameList->reserve(AUTH_FIELD_END);
250
0
        for (sal_uInt16 i = 0; i < AUTH_FIELD_END; ++i)
251
0
            pAuthFieldNameList->push_back(SwResId(STR_AUTH_FIELD_ARY[i]));
252
0
    }
253
0
    return (*pAuthFieldNameList)[static_cast< sal_uInt16 >(eType)];
254
0
}
255
256
const TranslateId STR_AUTH_TYPE_ARY[] =
257
{
258
    STR_AUTH_TYPE_ARTICLE,
259
    STR_AUTH_TYPE_BOOK,
260
    STR_AUTH_TYPE_BOOKLET,
261
    STR_AUTH_TYPE_CONFERENCE,
262
    STR_AUTH_TYPE_INBOOK,
263
    STR_AUTH_TYPE_INCOLLECTION,
264
    STR_AUTH_TYPE_INPROCEEDINGS,
265
    STR_AUTH_TYPE_JOURNAL,
266
    STR_AUTH_TYPE_MANUAL,
267
    STR_AUTH_TYPE_MASTERSTHESIS,
268
    STR_AUTH_TYPE_MISC,
269
    STR_AUTH_TYPE_PHDTHESIS,
270
    STR_AUTH_TYPE_PROCEEDINGS,
271
    STR_AUTH_TYPE_TECHREPORT,
272
    STR_AUTH_TYPE_UNPUBLISHED,
273
    STR_AUTH_TYPE_EMAIL,
274
    STR_AUTH_TYPE_WWW,
275
    STR_AUTH_TYPE_CUSTOM1,
276
    STR_AUTH_TYPE_CUSTOM2,
277
    STR_AUTH_TYPE_CUSTOM3,
278
    STR_AUTH_TYPE_CUSTOM4,
279
    STR_AUTH_TYPE_CUSTOM5
280
};
281
282
OUString const & SwAuthorityFieldType::GetAuthTypeName(ToxAuthorityType eType)
283
0
{
284
0
    if(!pAuthFieldTypeList)
285
0
    {
286
0
        pAuthFieldTypeList = new std::vector<OUString>;
287
0
        pAuthFieldTypeList->reserve(AUTH_TYPE_END);
288
0
        for (sal_uInt16 i = 0; i < AUTH_TYPE_END; ++i)
289
0
            pAuthFieldTypeList->push_back(SwResId(STR_AUTH_TYPE_ARY[i]));
290
0
    }
291
0
    return (*pAuthFieldTypeList)[static_cast< sal_uInt16 >(eType)];
292
0
}
293
294
void SwAuthorityFieldType::dumpAsXml(xmlTextWriterPtr pWriter) const
295
0
{
296
0
    (void)xmlTextWriterStartElement(pWriter, BAD_CAST("SwAuthorityFieldType"));
297
0
    SwFieldType::dumpAsXml(pWriter);
298
299
0
    (void)xmlTextWriterStartElement(pWriter, BAD_CAST("DataArr"));
300
0
    for (const auto& xAuthEntry : m_DataArr)
301
0
    {
302
0
        (void)xmlTextWriterStartElement(pWriter, BAD_CAST("AuthEntry"));
303
0
        (void)xmlTextWriterWriteFormatAttribute(pWriter, BAD_CAST("ptr"), "%p", xAuthEntry.get());
304
0
        (void)xmlTextWriterEndElement(pWriter);
305
0
    }
306
0
    (void)xmlTextWriterEndElement(pWriter);
307
308
0
    (void)xmlTextWriterEndElement(pWriter);
309
0
}
310
311
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */