summaryrefslogtreecommitdiff
path: root/sw/source/ui/fldui/fldfunc.cxx
blob: 8b0396cad75b0eb75c3a09d159ed49d49a5e0027 (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
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
/* -*- 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 <sfx2/app.hxx>
#include <basic/basmgr.hxx>
#include <basic/sbmod.hxx>
#include <docsh.hxx>
#include <swtypes.hxx>
#include <globals.hrc>
#include <strings.hrc>
#include <fldbas.hxx>
#include <docufld.hxx>
#include <view.hxx>
#include <wrtsh.hxx>
#include <swmodule.hxx>
#include <fldfunc.hxx>
#include <flddropdown.hxx>

#define USER_DATA_VERSION_1 "1"
#define USER_DATA_VERSION USER_DATA_VERSION_1

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

SwFieldFuncPage::SwFieldFuncPage(vcl::Window* pParent, const SfxItemSet *const pCoreSet)
    : SwFieldPage(pParent, "FieldFuncPage",
        "modules/swriter/ui/fldfuncpage.ui", pCoreSet)
    , nOldFormat(0)
    , bDropDownLBChanged(false)
{
    get(m_pTypeLB, "type");
    get(m_pFormat, "formatframe");
    get(m_pSelectionLB, "select");
    get(m_pFormatLB, "format");
    get(m_pNameFT, "nameft");
    get(m_pNameED, "name");
    get(m_pValueGroup, "valuegroup");
    get(m_pValueFT, "valueft");
    get(m_pValueED, "value");
    get(m_pCond1FT, "cond1ft");
    get(m_pCond1ED, "cond1");
    get(m_pCond2FT, "cond2ft");
    get(m_pCond2ED, "cond2");
    get(m_pMacroBT, "macro");

    get(m_pListGroup, "listgroup");
    get(m_pListItemFT, "itemft");
    get(m_pListItemED, "item");
    get(m_pListAddPB, "add");
    get(m_pListItemsFT, "listitemft");
    get(m_pListItemsLB, "listitems");
    m_pListItemsLB->SetDropDownLineCount(5);
    m_pListItemsLB->set_width_request(m_pListItemED->GetOptimalSize().Width());
    get(m_pListRemovePB, "remove");
    get(m_pListUpPB, "up");
    get(m_pListDownPB, "down");
    get(m_pListNameFT, "listnameft");
    get(m_pListNameED, "listname");

    long nHeight = m_pTypeLB->GetTextHeight() * 20;
    m_pTypeLB->set_height_request(nHeight);
    m_pFormatLB->set_height_request(nHeight);

    long nWidth = m_pTypeLB->LogicToPixel(Size(FIELD_COLUMN_WIDTH, 0), MapMode(MapUnit::MapAppFont)).Width();
    m_pTypeLB->set_width_request(nWidth);
    m_pFormatLB->set_width_request(nWidth);

    m_pNameED->SetModifyHdl(LINK(this, SwFieldFuncPage, ModifyHdl));

    m_sOldValueFT = m_pValueFT->GetText();
    m_sOldNameFT = m_pNameFT->GetText();

    m_pCond1ED->ShowBrackets(false);
    m_pCond2ED->ShowBrackets(false);
}

SwFieldFuncPage::~SwFieldFuncPage()
{
    disposeOnce();
}

void SwFieldFuncPage::dispose()
{
    m_pTypeLB.clear();
    m_pSelectionLB.clear();
    m_pFormat.clear();
    m_pFormatLB.clear();
    m_pNameFT.clear();
    m_pNameED.clear();
    m_pValueGroup.clear();
    m_pValueFT.clear();
    m_pValueED.clear();
    m_pCond1FT.clear();
    m_pCond1ED.clear();
    m_pCond2FT.clear();
    m_pCond2ED.clear();
    m_pMacroBT.clear();
    m_pListGroup.clear();
    m_pListItemFT.clear();
    m_pListItemED.clear();
    m_pListAddPB.clear();
    m_pListItemsFT.clear();
    m_pListItemsLB.clear();
    m_pListRemovePB.clear();
    m_pListUpPB.clear();
    m_pListDownPB.clear();
    m_pListNameFT.clear();
    m_pListNameED.clear();
    SwFieldPage::dispose();
}

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

    m_pTypeLB->SetUpdateMode(false);
    m_pTypeLB->Clear();

    sal_Int32 nPos;

    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 sal_uInt16 nTypeId = SwFieldMgr::GetTypeId(i);
            nPos = m_pTypeLB->InsertEntry(SwFieldMgr::GetTypeStr(i));
            m_pTypeLB->SetEntryData(nPos, reinterpret_cast<void*>(nTypeId));
        }
    }
    else
    {
        const sal_uInt16 nTypeId = GetCurField()->GetTypeId();
        nPos = m_pTypeLB->InsertEntry(SwFieldMgr::GetTypeStr(SwFieldMgr::GetPos(nTypeId)));
        m_pTypeLB->SetEntryData(nPos, reinterpret_cast<void*>(nTypeId));

        if (nTypeId == TYP_MACROFLD)
        {
            GetFieldMgr().SetMacroPath(GetCurField()->GetPar1());
        }
    }

    // select old Pos
    RestorePos(m_pTypeLB);

    m_pTypeLB->SetDoubleClickHdl       (LINK(this, SwFieldFuncPage, ListBoxInsertHdl));
    m_pTypeLB->SetSelectHdl            (LINK(this, SwFieldFuncPage, TypeHdl));
    m_pSelectionLB->SetSelectHdl       (LINK(this, SwFieldFuncPage, SelectHdl));
    m_pSelectionLB->SetDoubleClickHdl  (LINK(this, SwFieldFuncPage, InsertMacroHdl));
    m_pFormatLB->SetDoubleClickHdl     (LINK(this, SwFieldFuncPage, ListBoxInsertHdl));
    m_pMacroBT->SetClickHdl            (LINK(this, SwFieldFuncPage, MacroHdl));
    Link<Button*,void> aListModifyLk( LINK(this, SwFieldFuncPage, ListModifyButtonHdl));
    m_pListAddPB->SetClickHdl(aListModifyLk);
    m_pListRemovePB->SetClickHdl(aListModifyLk);
    m_pListUpPB->SetClickHdl(aListModifyLk);
    m_pListDownPB->SetClickHdl(aListModifyLk);
    m_pListItemED->SetReturnActionLink(LINK(this, SwFieldFuncPage, ListModifyReturnActionHdl));
    Link<Edit&,void> aListEnableLk = LINK(this, SwFieldFuncPage, ListEnableHdl);
    m_pListItemED->SetModifyHdl(aListEnableLk);
    m_pListItemsLB->SetSelectHdl(LINK(this, SwFieldFuncPage, ListEnableListBoxHdl));

    if( !IsRefresh() )
    {
        OUString sUserData = GetUserData();
        if(sUserData.getToken(0, ';').equalsIgnoreAsciiCase(USER_DATA_VERSION_1))
        {
            OUString sVal = sUserData.getToken(1, ';');
            const sal_uInt16 nVal = static_cast< sal_uInt16 >(sVal.toInt32());
            if(nVal != USHRT_MAX)
            {
                for(sal_Int32 i = 0; i < m_pTypeLB->GetEntryCount(); i++)
                    if(nVal == (sal_uInt16)reinterpret_cast<sal_uLong>(m_pTypeLB->GetEntryData(i)))
                    {
                        m_pTypeLB->SelectEntryPos(i);
                        break;
                    }
            }
        }
    }
    TypeHdl(*m_pTypeLB);

    m_pTypeLB->SetUpdateMode(true);

    if (IsFieldEdit())
    {
        m_pNameED->SaveValue();
        m_pValueED->SaveValue();
        m_pCond1ED->SaveValue();
        m_pCond2ED->SaveValue();
        nOldFormat = GetCurField()->GetFormat();
    }
}

static const char* FMT_MARK_ARY[] =
{
    FMT_MARK_TEXT,
    FMT_MARK_TABLE,
    FMT_MARK_FRAME,
    FMT_MARK_GRAFIC,
    FMT_MARK_OLE
};

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

    // current ListBoxPos
    SetTypeSel(m_pTypeLB->GetSelectedEntryPos());

    if(GetTypeSel() == LISTBOX_ENTRY_NOTFOUND)
    {
        SetTypeSel(0);
        m_pTypeLB->SelectEntryPos(0);
    }

    if (nOld != GetTypeSel())
    {
        const sal_uInt16 nTypeId = (sal_uInt16)reinterpret_cast<sal_uLong>(m_pTypeLB->GetEntryData(GetTypeSel()));

        // fill Selection-Listbox
        UpdateSubType();

        // fill Format-Listbox
        m_pFormatLB->Clear();

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

        for (sal_uInt16 i = 0; i < nSize; i++)
        {
            sal_Int32 nPos = m_pFormatLB->InsertEntry(GetFieldMgr().GetFormatStr(nTypeId, i));
            m_pFormatLB->SetEntryData( nPos, reinterpret_cast<void*>(GetFieldMgr().GetFormatId( nTypeId, i )) );
        }

        if (nSize)
        {
            if (IsFieldEdit() && nTypeId == TYP_JUMPEDITFLD)
                m_pFormatLB->SelectEntry(SwResId(FMT_MARK_ARY[GetCurField()->GetFormat()]));

            if (!m_pFormatLB->GetSelectedEntryCount())
                m_pFormatLB->SelectEntryPos(0);
        }

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

        // two controls for conditional text
        bool bDropDown = TYP_DROPDOWN == nTypeId;
        bool bCondTextField = TYP_CONDTXTFLD == nTypeId;

        m_pCond1FT->Show(!bDropDown && bCondTextField);
        m_pCond1ED->Show(!bDropDown && bCondTextField);
        m_pCond2FT->Show(!bDropDown && bCondTextField);
        m_pCond2ED->Show(!bDropDown && bCondTextField);
        m_pValueGroup->Show(!bDropDown && !bCondTextField);
        m_pMacroBT->Show(!bDropDown);
        m_pNameED->Show(!bDropDown);
        m_pNameFT->Show(!bDropDown);

        m_pListGroup->Show(bDropDown);

        m_pNameED->SetDropEnable(false);

        if (IsFieldEdit())
        {
            if(bDropDown)
            {
                const SwDropDownField* pDrop = static_cast<const SwDropDownField*>(GetCurField());
                uno::Sequence<OUString> aItems = pDrop->GetItemSequence();
                const OUString* pArray = aItems.getConstArray();
                m_pListItemsLB->Clear();
                for(sal_Int32 i = 0; i < aItems.getLength(); i++)
                    m_pListItemsLB->InsertEntry(pArray[i]);
                m_pListItemsLB->SelectEntry(pDrop->GetSelectedItem());
                m_pListNameED->SetText(pDrop->GetPar2());
                m_pListNameED->SaveValue();
                bDropDownLBChanged = false;
            }
            else
            {
                m_pNameED->SetText(GetCurField()->GetPar1());
                m_pValueED->SetText(GetCurField()->GetPar2());
            }
        }
        else
        {
            m_pNameED->SetText(OUString());
            m_pValueED->SetText(OUString());
        }
        if(bDropDown)
            ListEnableHdl(*m_pListItemED);

        if (m_pNameFT->GetText() != m_sOldNameFT)
            m_pNameFT->SetText(m_sOldNameFT);
        if (m_pValueFT->GetText() != m_sOldValueFT)
            m_pValueFT->SetText(m_sOldValueFT);

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

                m_pNameFT->SetText(SwResId(STR_MACNAME));
                m_pValueFT->SetText(SwResId(STR_PROMPT));
                m_pNameED->SetText(GetFieldMgr().GetMacroName());
                m_pNameED->SetAccessibleName(m_pNameFT->GetText());
                m_pValueED->SetAccessibleName(m_pValueFT->GetText());
                break;

            case TYP_HIDDENPARAFLD:
                m_pNameFT->SetText(SwResId(STR_COND));
                m_pNameED->SetDropEnable(true);
                bName = true;
                m_pNameED->SetAccessibleName(m_pNameFT->GetText());
                m_pValueED->SetAccessibleName(m_pValueFT->GetText());
                break;

            case TYP_HIDDENTXTFLD:
            {
                m_pNameFT->SetText(SwResId(STR_COND));
                m_pNameED->SetDropEnable(true);
                m_pValueFT->SetText(SwResId(STR_INSTEXT));
                SwWrtShell* pSh = GetActiveWrtShell();
                if (!IsFieldEdit() && pSh )
                    m_pValueED->SetText(pSh->GetSelText());
                bName = bValue = true;
                m_pNameED->SetAccessibleName(m_pNameFT->GetText());
                m_pValueED->SetAccessibleName(m_pValueFT->GetText());
            }
            break;

            case TYP_CONDTXTFLD:
                m_pNameFT->SetText(SwResId(STR_COND));
                m_pNameED->SetDropEnable(true);
                if (IsFieldEdit())
                {
                    m_pCond1ED->SetText(GetCurField()->GetPar2().getToken(0, '|'));
                    m_pCond2ED->SetText(GetCurField()->GetPar2().getToken(1, '|'));
                }

                bName = bValue = true;
                m_pNameED->SetAccessibleName(m_pNameFT->GetText());
                m_pValueED->SetAccessibleName(m_pValueFT->GetText());
                break;

            case TYP_JUMPEDITFLD:
                m_pNameFT->SetText(SwResId(STR_JUMPEDITFLD));
                m_pValueFT->SetText(SwResId(STR_PROMPT));
                bName = bValue = true;
                m_pNameED->SetAccessibleName(m_pNameFT->GetText());
                m_pValueED->SetAccessibleName(m_pValueFT->GetText());
                break;

            case TYP_INPUTFLD:
                m_pValueFT->SetText(SwResId(STR_PROMPT));
                bValue = true;
                m_pNameED->SetAccessibleName(m_pNameFT->GetText());
                m_pValueED->SetAccessibleName(m_pValueFT->GetText());
                break;

            case TYP_COMBINED_CHARS:
                {
                    m_pNameFT->SetText(SwResId(STR_COMBCHRS_FT));
                    m_pNameED->SetDropEnable(true);
                    bName = true;

                    const sal_Int32 nLen = m_pNameED->GetText().getLength();
                    if( !nLen || nLen > MAX_COMBINED_CHARACTERS )
                        bInsert = false;
                    m_pNameED->SetAccessibleName(m_pNameFT->GetText());
                    m_pValueED->SetAccessibleName(m_pValueFT->GetText());
                }
                break;
            case TYP_DROPDOWN :
            break;
            default:
                break;
        }

        m_pSelectionLB->Hide();

        m_pFormat->Enable(bFormat);
        m_pNameFT->Enable(bName);
        m_pNameED->Enable(bName);
        m_pValueGroup->Enable(bValue);
        m_pMacroBT->Enable(bMacro);

        EnableInsert( bInsert );
    }
}

IMPL_LINK_NOARG(SwFieldFuncPage, SelectHdl, ListBox&, void)
{
    const sal_uInt16 nTypeId = (sal_uInt16)reinterpret_cast<sal_uLong>(m_pTypeLB->GetEntryData(GetTypeSel()));

    if( TYP_MACROFLD == nTypeId )
        m_pNameED->SetText( m_pSelectionLB->GetSelectedEntry() );
}

IMPL_LINK_NOARG(SwFieldFuncPage, InsertMacroHdl, ListBox&, void)
{
    SelectHdl(*m_pSelectionLB);
    InsertHdl(nullptr);
}

IMPL_LINK( SwFieldFuncPage, ListModifyButtonHdl, Button*, pControl, void)
{
    ListModifyHdl(pControl);
}
IMPL_LINK( SwFieldFuncPage, ListModifyReturnActionHdl, ReturnActionEdit&, rControl, void)
{
    ListModifyHdl(&rControl);
}
void SwFieldFuncPage::ListModifyHdl(Control const * pControl)
{
    m_pListItemsLB->SetUpdateMode(false);
    if(pControl == m_pListAddPB ||
            (pControl == m_pListItemED && m_pListAddPB->IsEnabled()))
    {
        const OUString sEntry(m_pListItemED->GetText());
        m_pListItemsLB->InsertEntry(sEntry);
        m_pListItemsLB->SelectEntry(sEntry);
    }
    else if(m_pListItemsLB->GetSelectedEntryCount())
    {
        sal_Int32 nSelPos = m_pListItemsLB->GetSelectedEntryPos();
        if(pControl == m_pListRemovePB)
        {
            m_pListItemsLB->RemoveEntry(nSelPos);
            m_pListItemsLB->SelectEntryPos(nSelPos ? nSelPos - 1 : 0);
        }
        else if(pControl == m_pListUpPB)
        {
            if(nSelPos)
            {
                const OUString sEntry = m_pListItemsLB->GetSelectedEntry();
                m_pListItemsLB->RemoveEntry(nSelPos);
                nSelPos--;
                m_pListItemsLB->InsertEntry(sEntry, nSelPos);
                m_pListItemsLB->SelectEntryPos(nSelPos);
            }
        }
        else if(pControl == m_pListDownPB)
        {
            if(nSelPos < m_pListItemsLB->GetEntryCount() - 1)
            {
                const OUString sEntry = m_pListItemsLB->GetSelectedEntry();
                m_pListItemsLB->RemoveEntry(nSelPos);
                nSelPos++;
                m_pListItemsLB->InsertEntry(sEntry, nSelPos);
                m_pListItemsLB->SelectEntryPos(nSelPos);
            }
        }
    }
    bDropDownLBChanged = true;
    m_pListItemsLB->SetUpdateMode(true);
    ListEnableHdl(*m_pListItemED);
}

IMPL_LINK_NOARG(SwFieldFuncPage, ListEnableListBoxHdl, ListBox&, void)
{
    ListEnableHdl(*m_pListItemED);
}
IMPL_LINK_NOARG(SwFieldFuncPage, ListEnableHdl, Edit&, void)
{
    //enable "Add" button when text is in the Edit that's not already member of the box
    m_pListAddPB->Enable(!m_pListItemED->GetText().isEmpty() &&
                LISTBOX_ENTRY_NOTFOUND == m_pListItemsLB->GetEntryPos(m_pListItemED->GetText()));
    bool bEnableButtons = m_pListItemsLB->GetSelectedEntryCount() > 0;
    m_pListRemovePB->Enable(bEnableButtons);
    m_pListUpPB->Enable(bEnableButtons && (m_pListItemsLB->GetSelectedEntryPos() > 0));
    m_pListDownPB->Enable(bEnableButtons &&
                (m_pListItemsLB->GetSelectedEntryPos() < (m_pListItemsLB->GetEntryCount() - 1)));
}

// renew types in SelectionBox
void SwFieldFuncPage::UpdateSubType()
{
    const sal_uInt16 nTypeId = (sal_uInt16)reinterpret_cast<sal_uLong>(m_pTypeLB->GetEntryData(GetTypeSel()));

    // fill Selection-Listbox
    m_pSelectionLB->SetUpdateMode(false);
    m_pSelectionLB->Clear();

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

    for(size_t i = 0; i < nCount; ++i)
    {
        size_t nPos = m_pSelectionLB->InsertEntry(aLst[i]);
        m_pSelectionLB->SetEntryData(nPos, reinterpret_cast<void*>(i));
    }

    bool bEnable = nCount != 0;

    m_pSelectionLB->Enable( bEnable );

    if (bEnable)
    {
            m_pSelectionLB->SelectEntryPos(0);
    }

    if (nTypeId == TYP_MACROFLD)
    {
        const bool bHasMacro = !GetFieldMgr().GetMacroPath().isEmpty();

        if (bHasMacro)
        {
            m_pNameED->SetText(GetFieldMgr().GetMacroName());
            m_pValueGroup->Enable();
        }
        EnableInsert(bHasMacro);
    }

    m_pSelectionLB->SetUpdateMode(true);
}

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

bool SwFieldFuncPage::FillItemSet(SfxItemSet* )
{
    const sal_uInt16 nTypeId = (sal_uInt16)reinterpret_cast<sal_uLong>(m_pTypeLB->GetEntryData(GetTypeSel()));

    sal_uInt16 nSubType = 0;

    const sal_Int32 nEntryPos = m_pFormatLB->GetSelectedEntryPos();
    const sal_uLong nFormat = (nEntryPos == LISTBOX_ENTRY_NOTFOUND)
        ? 0 : reinterpret_cast<sal_uLong>(m_pFormatLB->GetEntryData(nEntryPos));

    OUString aVal(m_pValueED->GetText());
    OUString aName(m_pNameED->GetText());

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

            break;

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

        case TYP_CONDTXTFLD:
            aVal = m_pCond1ED->GetText() + "|" + m_pCond2ED->GetText();
            break;
        case TYP_DROPDOWN :
        {
            aName = m_pListNameED->GetText();
            for(sal_Int32 i = 0; i < m_pListItemsLB->GetEntryCount(); i++)
            {
                if(i)
                    aVal += OUStringLiteral1(DB_DELIM);
                aVal += m_pListItemsLB->GetEntry(i);
            }
        }
        break;
        default:
            break;
    }

    if (!IsFieldEdit() ||
        m_pNameED->IsValueChangedFromSaved() ||
        m_pValueED->IsValueChangedFromSaved() ||
        m_pCond1ED->IsValueChangedFromSaved() ||
        m_pCond2ED->IsValueChangedFromSaved() ||
        m_pListNameED->IsValueChangedFromSaved() ||
        bDropDownLBChanged ||
        nOldFormat != nFormat)
    {
        InsertField( nTypeId, nSubType, aName, aVal, nFormat );
    }

    ModifyHdl(*m_pNameED);    // enable/disable Insert if applicable

    return false;
}

VclPtr<SfxTabPage> SwFieldFuncPage::Create( vcl::Window* pParent,
                                          const SfxItemSet *const pAttrSet)
{
    return VclPtr<SwFieldFuncPage>::Create( pParent, pAttrSet );
}

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

void    SwFieldFuncPage::FillUserData()
{
    const sal_Int32 nEntryPos = m_pTypeLB->GetSelectedEntryPos();
    const sal_uInt16 nTypeSel = ( LISTBOX_ENTRY_NOTFOUND == nEntryPos )
        ? USHRT_MAX
        : sal::static_int_cast< sal_uInt16 >
            (reinterpret_cast< sal_uIntPtr >(m_pTypeLB->GetEntryData( nEntryPos )));
    SetUserData(USER_DATA_VERSION ";" + OUString::number( nTypeSel ));
}

IMPL_LINK_NOARG(SwFieldFuncPage, ModifyHdl, Edit&, void)
{
    const sal_Int32 nLen = m_pNameED->GetText().getLength();

    bool bEnable = true;
    sal_uInt16 nTypeId = (sal_uInt16)reinterpret_cast<sal_uLong>(m_pTypeLB->GetEntryData(GetTypeSel()));

    if( TYP_COMBINED_CHARS == nTypeId &&
        (!nLen || nLen > MAX_COMBINED_CHARACTERS ))
        bEnable = false;

    EnableInsert( bEnable );
}

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