summaryrefslogtreecommitdiffstats
path: root/sw/source/ui/fldui/fldfunc.cxx
blob: 6447c375e5b4d13290b840bc55d99efa3873c1b6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
 * This file is part of the LibreOffice project.
 *
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 *
 * This file incorporates work covered by the following license notice:
 *
 *   Licensed to the Apache Software Foundation (ASF) under one or more
 *   contributor license agreements. See the NOTICE file distributed
 *   with this work for additional information regarding copyright
 *   ownership. The ASF licenses this file to you under the Apache
 *   License, Version 2.0 (the "License"); you may not use this file
 *   except in compliance with the License. You may obtain a copy of
 *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
 */

#include <swtypes.hxx>
#include <strings.hrc>
#include <fldbas.hxx>
#include <docufld.hxx>
#include <wrtsh.hxx>
#include <swmodule.hxx>
#include "fldfunc.hxx"
#include "flddinf.hxx"
#include <flddropdown.hxx>
#include <o3tl/string_view.hxx>

#define USER_DATA_VERSION_1 "1"
#define USER_DATA_VERSION USER_DATA_VERSION_1

using namespace ::com::sun::star;

SwFieldFuncPage::SwFieldFuncPage(weld::Container* pPage, weld::DialogController* pController, const SfxItemSet *const pCoreSet)
    : SwFieldPage(pPage, pController, "modules/swriter/ui/fldfuncpage.ui", "FieldFuncPage", pCoreSet)
    , m_nOldFormat(0)
    , m_bDropDownLBChanged(false)
    , m_xTypeLB(m_xBuilder->weld_tree_view("type"))
    , m_xSelectionLB(m_xBuilder->weld_tree_view("select"))
    , m_xFormat(m_xBuilder->weld_widget("formatframe"))
    , m_xFormatLB(m_xBuilder->weld_tree_view("format"))
    , m_xNameFT(m_xBuilder->weld_label("nameft"))
    , m_xNameED(new ConditionEdit(m_xBuilder->weld_entry("condFunction")))
    , m_xValueGroup(m_xBuilder->weld_widget("valuegroup"))
    , m_xValueFT(m_xBuilder->weld_label("valueft"))
    , m_xValueED(m_xBuilder->weld_entry("value"))
    , m_xCond1FT(m_xBuilder->weld_label("cond1ft"))
    , m_xCond1ED(new ConditionEdit(m_xBuilder->weld_entry("cond1")))
    , m_xCond2FT(m_xBuilder->weld_label("cond2ft"))
    , m_xCond2ED(new ConditionEdit(m_xBuilder->weld_entry("cond2")))
    , m_xMacroBT(m_xBuilder->weld_button("macro"))
    , m_xListGroup(m_xBuilder->weld_widget("listgroup"))
    , m_xListItemED(m_xBuilder->weld_entry("item"))
    , m_xListAddPB(m_xBuilder->weld_button("add"))
    , m_xListItemsLB(m_xBuilder->weld_tree_view("listitems"))
    , m_xListRemovePB(m_xBuilder->weld_button("remove"))
    , m_xListUpPB(m_xBuilder->weld_button("up"))
    , m_xListDownPB(m_xBuilder->weld_button("down"))
    , m_xListNameED(m_xBuilder->weld_entry("listname"))
{
    FillFieldSelect(*m_xSelectionLB);
    FillFieldSelect(*m_xFormatLB);
    m_xListItemsLB->set_size_request(m_xListItemED->get_preferred_size().Width(),
                                     m_xListItemsLB->get_height_rows(5));

    auto nWidth = m_xTypeLB->get_approximate_digit_width() * FIELD_COLUMN_WIDTH;
    auto nHeight = m_xTypeLB->get_height_rows(10);
    m_xTypeLB->set_size_request(nWidth, nHeight);
    m_xFormatLB->set_size_request(nWidth, nHeight);

    m_xNameED->connect_changed(LINK(this, SwFieldFuncPage, ModifyHdl));

    m_sOldValueFT = m_xValueFT->get_label();
    m_sOldNameFT = m_xNameFT->get_label();

    m_xCond1ED->ShowBrackets(false);
    m_xCond2ED->ShowBrackets(false);

    // uitests
    m_xTypeLB->set_buildable_name(m_xTypeLB->get_buildable_name() + "-func");
    m_xValueED->set_buildable_name(m_xValueED->get_buildable_name() + "-func");
    m_xSelectionLB->set_buildable_name(m_xSelectionLB->get_buildable_name() + "-func");
    m_xFormatLB->set_buildable_name(m_xFormatLB->get_buildable_name() + "-func");
}

SwFieldFuncPage::~SwFieldFuncPage()
{
}

void SwFieldFuncPage::Reset(const SfxItemSet* )
{
    SavePos(*m_xTypeLB);
    Init(); // general initialisation

    m_xTypeLB->freeze();
    m_xTypeLB->clear();

    if (!IsFieldEdit())
    {
        // initialise TypeListBox
        const SwFieldGroupRgn& rRg = SwFieldMgr::GetGroupRange(IsFieldDlgHtmlMode(), GetGroup());

        // fill Typ-Listbox
        for(sal_uInt16 i = rRg.nStart; i < rRg.nEnd; ++i)
        {
            const SwFieldTypesEnum nTypeId = SwFieldMgr::GetTypeId(i);
            m_xTypeLB->append(OUString::number(static_cast<sal_uInt16>(nTypeId)), SwFieldMgr::GetTypeStr(i));
        }
    }
    else
    {
        const SwFieldTypesEnum nTypeId = GetCurField()->GetTypeId();
        m_xTypeLB->append(OUString::number(static_cast<sal_uInt16>(nTypeId)), SwFieldMgr::GetTypeStr(SwFieldMgr::GetPos(nTypeId)));

        if (nTypeId == SwFieldTypesEnum::Macro)
        {
            GetFieldMgr().SetMacroPath(GetCurField()->GetPar1());
        }
    }

    m_xTypeLB->connect_row_activated(LINK(this, SwFieldFuncPage, TreeViewInsertHdl));
    m_xTypeLB->connect_changed(LINK(this, SwFieldFuncPage, TypeHdl));
    m_xSelectionLB->connect_changed(LINK(this, SwFieldFuncPage, SelectHdl));
    m_xSelectionLB->connect_row_activated(LINK(this, SwFieldFuncPage, InsertMacroHdl));
    m_xFormatLB->connect_row_activated(LINK(this, SwFieldFuncPage, TreeViewInsertHdl));
    m_xMacroBT->connect_clicked(LINK(this, SwFieldFuncPage, MacroHdl));
    Link<weld::Button&,void> aListModifyLk( LINK(this, SwFieldFuncPage, ListModifyButtonHdl));
    m_xListAddPB->connect_clicked(aListModifyLk);
    m_xListRemovePB->connect_clicked(aListModifyLk);
    m_xListUpPB->connect_clicked(aListModifyLk);
    m_xListDownPB->connect_clicked(aListModifyLk);
    m_xListItemED->connect_activate(LINK(this, SwFieldFuncPage, ListModifyReturnActionHdl));
    Link<weld::Entry&,void> aListEnableLk = LINK(this, SwFieldFuncPage, ListEnableHdl);
    m_xListItemED->connect_changed(aListEnableLk);
    m_xListItemsLB->connect_changed(LINK(this, SwFieldFuncPage, ListEnableListBoxHdl));

    int nSelect = -1;
    if( !IsRefresh() )
    {
        const OUString sUserData = GetUserData();
        sal_Int32 nIdx{ 0 };
        if(o3tl::equalsIgnoreAsciiCase(o3tl::getToken(sUserData, 0, ';', nIdx), u"" USER_DATA_VERSION_1))
        {
            const sal_uInt16 nVal = static_cast< sal_uInt16 >(o3tl::toInt32(o3tl::getToken(sUserData, 0, ';', nIdx)));
            if(nVal != USHRT_MAX)
            {
                for (sal_Int32 i = 0, nEntryCount = m_xTypeLB->n_children(); i < nEntryCount; ++i)
                {
                    if (nVal == m_xTypeLB->get_id(i).toUInt32())
                    {
                        nSelect = i;
                        break;
                    }
                }
            }
        }
    }

    m_xTypeLB->thaw();
    if (nSelect != -1)
        m_xTypeLB->select(nSelect);
    else
    {
        // select old Pos
        RestorePos(*m_xTypeLB);
    }
    TypeHdl(*m_xTypeLB);

    if (IsFieldEdit())
    {
        m_xNameED->save_value();
        m_xValueED->save_value();
        m_xCond1ED->save_value();
        m_xCond2ED->save_value();
        m_nOldFormat = GetCurField()->GetFormat();
    }
}

const TranslateId FMT_MARK_ARY[] =
{
    FMT_MARK_TEXT,
    FMT_MARK_TABLE,
    FMT_MARK_FRAME,
    FMT_MARK_GRAFIC,
    FMT_MARK_OLE
};

IMPL_LINK_NOARG(SwFieldFuncPage, TypeHdl, weld::TreeView&, void)
{
    // save old ListBoxPos
    const sal_Int32 nOld = GetTypeSel();

    // current ListBoxPos
    SetTypeSel(m_xTypeLB->get_selected_index());

    if(GetTypeSel() == -1)
    {
        SetTypeSel(0);
        m_xTypeLB->select(0);
    }

    if (nOld == GetTypeSel())
        return;

    const SwFieldTypesEnum nTypeId = static_cast<SwFieldTypesEnum>(m_xTypeLB->get_id(GetTypeSel()).toUInt32());

    // fill Selection-Listbox
    UpdateSubType();

    // fill Format-Listbox
    m_xFormatLB->clear();

    const sal_uInt16 nSize = GetFieldMgr().GetFormatCount(nTypeId, IsFieldDlgHtmlMode());

    for (sal_uInt16 i = 0; i < nSize; i++)
    {
        m_xFormatLB->append(OUString::number(GetFieldMgr().GetFormatId(nTypeId, i)),
                              GetFieldMgr().GetFormatStr(nTypeId, i));
    }

    if (nSize)
    {
        if (IsFieldEdit() && nTypeId == SwFieldTypesEnum::JumpEdit)
            m_xFormatLB->select_text(SwResId(FMT_MARK_ARY[GetCurField()->GetFormat()]));

        if (m_xFormatLB->get_selected_index() == -1)
            m_xFormatLB->select(0);
    }

    bool bValue = false, bName = false, bMacro = false, bInsert = true;
    bool bFormat = nSize != 0;

    // two controls for conditional text
    bool bDropDown = SwFieldTypesEnum::Dropdown == nTypeId;
    bool bCondTextField = SwFieldTypesEnum::ConditionalText == nTypeId;

    m_xCond1FT->set_visible(!bDropDown && bCondTextField);
    m_xCond1ED->set_visible(!bDropDown && bCondTextField);
    m_xCond2FT->set_visible(!bDropDown && bCondTextField);
    m_xCond2ED->set_visible(!bDropDown && bCondTextField);
    m_xValueGroup->set_visible(!bDropDown && !bCondTextField);
    m_xMacroBT->set_visible(!bDropDown);
    m_xNameED->set_visible(!bDropDown);
    m_xNameFT->set_visible(!bDropDown);

    m_xListGroup->set_visible(bDropDown);

    m_xNameED->SetDropEnable(false);

    if (IsFieldEdit())
    {
        if(bDropDown)
        {
            const SwDropDownField* pDrop = static_cast<const SwDropDownField*>(GetCurField());
            const uno::Sequence<OUString> aItems = pDrop->GetItemSequence();
            m_xListItemsLB->clear();
            for (const OUString& rItem : aItems)
                m_xListItemsLB->append_text(rItem);
            m_xListItemsLB->select_text(pDrop->GetSelectedItem());
            m_xListNameED->set_text(pDrop->GetPar2());
            m_xListNameED->save_value();
            m_bDropDownLBChanged = false;
        }
        else
        {
            m_xNameED->set_text(GetCurField()->GetPar1());
            m_xValueED->set_text(GetCurField()->GetPar2());
        }
    }
    else
    {
        m_xNameED->set_text(OUString());
        m_xValueED->set_text(OUString());
    }
    if(bDropDown)
        ListEnableHdl(*m_xListItemED);

    if (m_xNameFT->get_label() != m_sOldNameFT)
        m_xNameFT->set_label(m_sOldNameFT);
    if (m_xValueFT->get_label() != m_sOldValueFT)
        m_xValueFT->set_label(m_sOldValueFT);

    switch (nTypeId)
    {
        case SwFieldTypesEnum::Macro:
            bMacro = true;
            if (!GetFieldMgr().GetMacroPath().isEmpty())
                bValue = true;
            else
                bInsert = false;

            m_xNameFT->set_label(SwResId(STR_MACNAME));
            m_xValueFT->set_label(SwResId(STR_PROMPT));
            m_xNameED->set_text(GetFieldMgr().GetMacroName());
            m_xNameED->set_accessible_name(m_xNameFT->get_label());
            m_xValueED->set_accessible_name(m_xValueFT->get_label());
            break;

        case SwFieldTypesEnum::HiddenParagraph:
            m_xNameFT->set_label(SwResId(STR_COND));
            m_xNameED->SetDropEnable(true);
            bName = true;
            m_xNameED->set_accessible_name(m_xNameFT->get_label());
            m_xValueED->set_accessible_name(m_xValueFT->get_label());
            break;

        case SwFieldTypesEnum::HiddenText:
        {
            m_xNameFT->set_label(SwResId(STR_COND));
            m_xNameED->SetDropEnable(true);
            m_xValueFT->set_label(SwResId(STR_INSTEXT));
            SwWrtShell* pSh = GetActiveWrtShell();
            if (!IsFieldEdit() && pSh)
                m_xValueED->set_text(pSh->GetSelText());
            bName = bValue = true;
            m_xNameED->set_accessible_name(m_xNameFT->get_label());
            m_xValueED->set_accessible_name(m_xValueFT->get_label());
        }
        break;

        case SwFieldTypesEnum::ConditionalText:
            m_xNameFT->set_label(SwResId(STR_COND));
            m_xNameED->SetDropEnable(true);
            if (IsFieldEdit())
            {
                sal_Int32 nIdx{ 0 };
                m_xCond1ED->set_text(GetCurField()->GetPar2().getToken(0, '|', nIdx));
                m_xCond2ED->set_text(GetCurField()->GetPar2().getToken(0, '|', nIdx));
            }

            bName = bValue = true;
            m_xNameED->set_accessible_name(m_xNameFT->get_label());
            m_xValueED->set_accessible_name(m_xValueFT->get_label());
            break;

        case SwFieldTypesEnum::JumpEdit:
            m_xNameFT->set_label(SwResId(STR_JUMPEDITFLD));
            m_xValueFT->set_label(SwResId(STR_PROMPT));
            bName = bValue = true;
            m_xNameED->set_accessible_name(m_xNameFT->get_label());
            m_xValueED->set_accessible_name(m_xValueFT->get_label());
            break;

        case SwFieldTypesEnum::Input:
            m_xValueFT->set_label(SwResId(STR_PROMPT));
            bValue = true;
            m_xNameED->set_accessible_name(m_xNameFT->get_label());
            m_xValueED->set_accessible_name(m_xValueFT->get_label());
            break;

        case SwFieldTypesEnum::CombinedChars:
            {
                m_xNameFT->set_label(SwResId(STR_COMBCHRS_FT));
                m_xNameED->SetDropEnable(true);
                bName = true;

                const sal_Int32 nLen = m_xNameED->get_text().getLength();
                if( !nLen || nLen > MAX_COMBINED_CHARACTERS )
                    bInsert = false;
                m_xNameED->set_accessible_name(m_xNameFT->get_label());
                m_xValueED->set_accessible_name(m_xValueFT->get_label());
            }
            break;
        case SwFieldTypesEnum::Dropdown :
        break;
        default:
            break;
    }

    m_xSelectionLB->hide();

    m_xFormat->set_sensitive(bFormat);
    m_xNameFT->set_sensitive(bName);
    m_xNameED->set_sensitive(bName);
    m_xValueGroup->set_sensitive(bValue);
    m_xMacroBT->set_sensitive(bMacro);

    EnableInsert( bInsert );
}

IMPL_LINK_NOARG(SwFieldFuncPage, SelectHdl, weld::TreeView&, void)
{
    const SwFieldTypesEnum nTypeId = static_cast<SwFieldTypesEnum>(m_xTypeLB->get_id(GetTypeSel()).toUInt32());

    if( SwFieldTypesEnum::Macro == nTypeId )
        m_xNameED->set_text( m_xSelectionLB->get_selected_text() );
}

IMPL_LINK_NOARG(SwFieldFuncPage, InsertMacroHdl, weld::TreeView&, bool)
{
    SelectHdl(*m_xSelectionLB);
    InsertHdl(nullptr);
    return true;
}

IMPL_LINK(SwFieldFuncPage, ListModifyButtonHdl, weld::Button&, rControl, void)
{
    ListModifyHdl(&rControl);
}

IMPL_LINK(SwFieldFuncPage, ListModifyReturnActionHdl, weld::Entry&, rControl, bool)
{
    ListModifyHdl(&rControl);
    return true;
}

void SwFieldFuncPage::ListModifyHdl(const weld::Widget* pControl)
{
    if (pControl == m_xListAddPB.get() ||
            (pControl == m_xListItemED.get() && m_xListAddPB->get_sensitive()))
    {
        const OUString sEntry(m_xListItemED->get_text());
        m_xListItemsLB->append_text(sEntry);
        m_xListItemsLB->select_text(sEntry);
    }
    else if (m_xListItemsLB->get_selected_index() != -1)
    {
        sal_Int32 nSelPos = m_xListItemsLB->get_selected_index();
        if (pControl == m_xListRemovePB.get())
        {
            m_xListItemsLB->remove(nSelPos);
            m_xListItemsLB->select(nSelPos ? nSelPos - 1 : 0);
        }
        else if (pControl == m_xListUpPB.get())
        {
            if(nSelPos)
            {
                const OUString sEntry = m_xListItemsLB->get_selected_text();
                m_xListItemsLB->remove(nSelPos);
                nSelPos--;
                m_xListItemsLB->insert_text(nSelPos, sEntry);
                m_xListItemsLB->select(nSelPos);
            }
        }
        else if (pControl == m_xListDownPB.get())
        {
            if( nSelPos < m_xListItemsLB->n_children() - 1)
            {
                const OUString sEntry = m_xListItemsLB->get_selected_text();
                m_xListItemsLB->remove(nSelPos);
                nSelPos++;
                m_xListItemsLB->insert_text(nSelPos, sEntry);
                m_xListItemsLB->select(nSelPos);
            }
        }
    }
    m_bDropDownLBChanged = true;
    ListEnableHdl(*m_xListItemED);
}

IMPL_LINK_NOARG(SwFieldFuncPage, ListEnableListBoxHdl, weld::TreeView&, void)
{
    ListEnableHdl(*m_xListItemED);
}

IMPL_LINK_NOARG(SwFieldFuncPage, ListEnableHdl, weld::Entry&, void)
{
    //enable "Add" button when text is in the Edit that's not already member of the box
    m_xListAddPB->set_sensitive(!m_xListItemED->get_text().isEmpty() &&
                -1 == m_xListItemsLB->find_text(m_xListItemED->get_text()));
    bool bEnableButtons = m_xListItemsLB->get_selected_index() != -1;
    m_xListRemovePB->set_sensitive(bEnableButtons);
    m_xListUpPB->set_sensitive(bEnableButtons && (m_xListItemsLB->get_selected_index() > 0));
    m_xListDownPB->set_sensitive(bEnableButtons &&
                (m_xListItemsLB->get_selected_index() < (m_xListItemsLB->n_children() - 1)));
}

// renew types in SelectionBox
void SwFieldFuncPage::UpdateSubType()
{
    const SwFieldTypesEnum nTypeId = static_cast<SwFieldTypesEnum>(m_xTypeLB->get_id(GetTypeSel()).toUInt32());

    // fill Selection-Listbox
    m_xSelectionLB->freeze();
    m_xSelectionLB->clear();

    std::vector<OUString> aLst;
    GetFieldMgr().GetSubTypes(nTypeId, aLst);
    const size_t nCount = aLst.size();

    for (size_t i = 0; i < nCount; ++i)
        m_xSelectionLB->append(OUString::number(i), aLst[i]);
    m_xSelectionLB->thaw();

    bool bEnable = nCount != 0;

    m_xSelectionLB->set_sensitive( bEnable );

    if (bEnable)
        m_xSelectionLB->select(0);

    if (nTypeId == SwFieldTypesEnum::Macro)
    {
        const bool bHasMacro = !GetFieldMgr().GetMacroPath().isEmpty();

        if (bHasMacro)
        {
            m_xNameED->set_text(GetFieldMgr().GetMacroName());
            m_xValueGroup->set_sensitive(true);
        }
        EnableInsert(bHasMacro);
    }
}

// call MacroBrowser, fill Listbox with Macros
IMPL_LINK_NOARG( SwFieldFuncPage, MacroHdl, weld::Button&, void)
{
    if (GetFieldMgr().ChooseMacro(GetFrameWeld()))
        UpdateSubType();
}

bool SwFieldFuncPage::FillItemSet(SfxItemSet* )
{
    const SwFieldTypesEnum nTypeId = static_cast<SwFieldTypesEnum>(m_xTypeLB->get_id(GetTypeSel()).toUInt32());

    sal_uInt16 nSubType = 0;

    const sal_Int32 nEntryPos = m_xFormatLB->get_selected_index();
    const sal_uInt32 nFormat = (nEntryPos == -1)
        ? 0 : m_xFormatLB->get_id(nEntryPos).toUInt32();

    OUString aVal(m_xValueED->get_text());
    OUString aName(m_xNameED->get_text());

    switch(nTypeId)
    {
        case SwFieldTypesEnum::Input:
            nSubType = INP_TXT;
            // to prevent removal of CR/LF restore old content
            if (!m_xNameED->get_value_changed_from_saved() && IsFieldEdit())
                aName = GetCurField()->GetPar1();

            break;

        case SwFieldTypesEnum::Macro:
            // use the full script URL, not the name in the Edit control
            aName = GetFieldMgr().GetMacroPath();
            break;

        case SwFieldTypesEnum::ConditionalText:
            aVal = m_xCond1ED->get_text() + "|" + m_xCond2ED->get_text();
            break;
        case SwFieldTypesEnum::Dropdown :
        {
            aName = m_xListNameED->get_text();
            for (sal_Int32 i = 0, nEntryCount = m_xListItemsLB->n_children(); i < nEntryCount; ++i)
            {
                if(i)
                    aVal += OUStringChar(DB_DELIM);
                aVal += m_xListItemsLB->get_text(i);
            }
        }
        break;
        default:
            break;
    }

    if (!IsFieldEdit() ||
        m_xNameED->get_value_changed_from_saved() ||
        m_xValueED->get_value_changed_from_saved() ||
        m_xCond1ED->get_value_changed_from_saved() ||
        m_xCond2ED->get_value_changed_from_saved() ||
        m_xListNameED->get_value_changed_from_saved() ||
        m_bDropDownLBChanged ||
        m_nOldFormat != nFormat)
    {
        InsertField( nTypeId, nSubType, aName, aVal, nFormat );
    }

    ModifyHdl(m_xNameED->get_widget());    // enable/disable Insert if applicable

    return false;
}

std::unique_ptr<SfxTabPage> SwFieldFuncPage::Create( weld::Container* pPage, weld::DialogController* pController,
                                          const SfxItemSet *const pAttrSet)
{
    return std::make_unique<SwFieldFuncPage>(pPage, pController, pAttrSet);
}

sal_uInt16 SwFieldFuncPage::GetGroup()
{
    return GRP_FKT;
}

void    SwFieldFuncPage::FillUserData()
{
    const sal_Int32 nEntryPos = m_xTypeLB->get_selected_index();
    const sal_uInt16 nTypeSel = ( -1 == nEntryPos )
        ? USHRT_MAX
        : m_xTypeLB->get_id(nEntryPos).toUInt32();
    SetUserData(USER_DATA_VERSION ";" + OUString::number( nTypeSel ));
}

IMPL_LINK_NOARG(SwFieldFuncPage, ModifyHdl, weld::Entry&, void)
{
    const sal_Int32 nLen = m_xNameED->get_text().getLength();

    bool bEnable = true;
    SwFieldTypesEnum nTypeId = static_cast<SwFieldTypesEnum>(m_xTypeLB->get_id(GetTypeSel()).toUInt32());

    if( SwFieldTypesEnum::CombinedChars == nTypeId &&
        (!nLen || nLen > MAX_COMBINED_CHARACTERS ))
        bEnable = false;

    EnableInsert( bEnable );
}

/* vim:set shiftwidth=4 softtabstop=4 expandtab: */