summaryrefslogtreecommitdiff
path: root/svx/source/tbxctrls/linectrl.cxx
blob: df0115f5b91b25df41346a69fac6a2ededa92f28 (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
/* -*- 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 <tools/debug.hxx>
#include <vcl/settings.hxx>
#include <vcl/svapp.hxx>
#include <vcl/toolbox.hxx>
#include <sfx2/objsh.hxx>

#include <svtools/toolbarmenu.hxx>
#include <svtools/popupwindowcontroller.hxx>
#include <svtools/valueset.hxx>

#include <svx/strings.hrc>
#include <svx/svxids.hrc>
#include <helpids.h>

#include <svx/drawitem.hxx>
#include <svx/xlineit0.hxx>
#include <svx/xlndsit.hxx>
#include <svx/xlnstit.hxx>
#include <svx/xlnedit.hxx>
#include <svx/xtable.hxx>
#include <svx/linectrl.hxx>
#include <svx/itemwin.hxx>
#include <svx/dialmgr.hxx>
#include <svx/tbxcolorupdate.hxx>

#include <memory>

#include <comphelper/lok.hxx>

using namespace ::com::sun::star::uno;
using namespace ::com::sun::star::beans;
using namespace ::com::sun::star::util;
using namespace ::com::sun::star::frame;
using namespace ::com::sun::star::lang;
using namespace ::com::sun::star;

// For End Line Controller
#define MAX_LINES 12

SvxLineStyleToolBoxControl::SvxLineStyleToolBoxControl( const css::uno::Reference<css::uno::XComponentContext>& rContext )
    : svt::PopupWindowController( rContext, nullptr, OUString() )
{
    addStatusListener(".uno:LineDash");
}

SvxLineStyleToolBoxControl::~SvxLineStyleToolBoxControl()
{
}

void SAL_CALL SvxLineStyleToolBoxControl::statusChanged( const frame::FeatureStateEvent& rEvent )
{
    ToolBox* pToolBox = nullptr;
    sal_uInt16 nId = 0;
    if (!getToolboxId(nId, &pToolBox) && !m_pToolbar)
        return;

    OString sId(m_aCommandURL.toUtf8());

    if ( rEvent.FeatureURL.Complete == m_aCommandURL )
    {
        if (m_pToolbar)
            m_pToolbar->set_item_sensitive(sId, rEvent.IsEnabled);
        else
            pToolBox->EnableItem( nId, rEvent.IsEnabled );
    }

    m_xBtnUpdater->Update(rEvent);

    SfxObjectShell* pSh = SfxObjectShell::Current();
    if (pSh)
    {
        const SvxDashListItem* pItem = pSh->GetItem( SID_DASH_LIST );
        if (pItem)
        {
            XDashListRef xList = pItem->GetDashList();
            int nIndex = m_xBtnUpdater->GetStyleIndex();
            switch (nIndex)
            {
                case -1:
                case 0:
                {
                    BitmapEx aEmpty(xList->GetBitmapForUISolidLine());
                    aEmpty.Erase(Application::GetSettings().GetStyleSettings().GetFieldColor());
                    if (m_pToolbar)
                    {
                        Graphic aGraf(aEmpty);
                        m_pToolbar->set_item_image(sId, aGraf.GetXGraphic());
                    }
                    else
                        pToolBox->SetItemImage(nId, Image(aEmpty));
                    break;
                }
                case 1:
                    if (m_pToolbar)
                    {
                        Graphic aGraf(xList->GetBitmapForUISolidLine());
                        m_pToolbar->set_item_image(sId, aGraf.GetXGraphic());
                    }
                    else
                        pToolBox->SetItemImage(nId, Image(xList->GetBitmapForUISolidLine()));
                    break;
                default:
                    if (m_pToolbar)
                    {
                        Graphic aGraf(xList->GetUiBitmap(nIndex - 2));
                        m_pToolbar->set_item_image(sId, aGraf.GetXGraphic());
                    }
                    else
                        pToolBox->SetItemImage(nId, Image(xList->GetUiBitmap(nIndex - 2)));
                    break;
            }
        }
    }
}

void SAL_CALL SvxLineStyleToolBoxControl::execute(sal_Int16 /*KeyModifier*/)
{
    if (m_pToolbar)
    {
        // Toggle the popup also when toolbutton is activated
        const OString aId(m_aCommandURL.toUtf8());
        m_pToolbar->set_menu_item_active(aId, !m_pToolbar->get_menu_item_active(aId));
    }
    else
    {
        // Open the popup also when Enter key is pressed.
        createPopupWindow();
    }
}

void SvxLineStyleToolBoxControl::initialize( const css::uno::Sequence<css::uno::Any>& rArguments )
{
    svt::PopupWindowController::initialize( rArguments );

    if (m_pToolbar)
    {
        mxPopoverContainer.reset(new ToolbarPopupContainer(m_pToolbar));
        m_pToolbar->set_item_popover(m_aCommandURL.toUtf8(), mxPopoverContainer->getTopLevel());
    }

    ToolBox* pToolBox = nullptr;
    sal_uInt16 nId = 0;
    if ( getToolboxId( nId, &pToolBox ) )
    {
        pToolBox->SetItemBits( nId, pToolBox->GetItemBits( nId ) | ToolBoxItemBits::DROPDOWNONLY );
    }

    m_xBtnUpdater.reset(new svx::ToolboxButtonLineStyleUpdater);
}

void SvxLineStyleToolBoxControl::setLineStyleSelectFunction(const LineStyleSelectFunction& rLineStyleSelectFunction)
{
    m_aLineStyleSelectFunction = rLineStyleSelectFunction;
}

void SvxLineStyleToolBoxControl::dispatchLineStyleCommand(const OUString& rCommand, const Sequence<PropertyValue>& rArgs)
{
    if (m_aLineStyleSelectFunction && m_aLineStyleSelectFunction(rCommand, rArgs[0].Value))
        return;

    dispatchCommand(rCommand, rArgs);
}

std::unique_ptr<WeldToolbarPopup> SvxLineStyleToolBoxControl::weldPopupWindow()
{
    return std::make_unique<SvxLineBox>(this, m_pToolbar, m_xBtnUpdater->GetStyleIndex());
}

VclPtr<vcl::Window> SvxLineStyleToolBoxControl::createVclPopupWindow( vcl::Window* pParent )
{
    mxInterimPopover = VclPtr<InterimToolbarPopup>::Create(getFrameInterface(), pParent,
        std::make_unique<SvxLineBox>(this, pParent->GetFrameWeld(), m_xBtnUpdater->GetStyleIndex()));

    mxInterimPopover->Show();

    return mxInterimPopover;
}

OUString SvxLineStyleToolBoxControl::getImplementationName()
{
    return "com.sun.star.comp.svx.LineStyleToolBoxControl";
}

css::uno::Sequence<OUString> SvxLineStyleToolBoxControl::getSupportedServiceNames()
{
    return { "com.sun.star.frame.ToolbarController" };
}

extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface *
com_sun_star_comp_svx_LineStyleToolBoxControl_get_implementation(
    css::uno::XComponentContext* rContext,
    css::uno::Sequence<css::uno::Any> const & )
{
    return cppu::acquire( new SvxLineStyleToolBoxControl( rContext ) );
}

namespace {

class SvxLineEndToolBoxControl final : public svt::PopupWindowController
{
public:
    explicit SvxLineEndToolBoxControl( const css::uno::Reference<css::uno::XComponentContext>& rContext );

    // XInitialization
    virtual void SAL_CALL initialize( const css::uno::Sequence<css::uno::Any>& rArguments ) override;

    // XServiceInfo
    virtual OUString SAL_CALL getImplementationName() override;
    virtual css::uno::Sequence<OUString> SAL_CALL getSupportedServiceNames() override;

    virtual void SAL_CALL execute(sal_Int16 nKeyModifier) override;

private:
    virtual std::unique_ptr<WeldToolbarPopup> weldPopupWindow() override;
    virtual VclPtr<vcl::Window> createVclPopupWindow( vcl::Window* pParent ) override;
};

class SvxLineEndWindow final : public WeldToolbarPopup
{
private:
    XLineEndListRef mpLineEndList;
    rtl::Reference<SvxLineEndToolBoxControl> mxControl;
    std::unique_ptr<ValueSet> mxLineEndSet;
    std::unique_ptr<weld::CustomWeld> mxLineEndSetWin;
    sal_uInt16 mnLines;
    Size maBmpSize;

    DECL_LINK( SelectHdl, ValueSet*, void );
    void FillValueSet();
    void SetSize();

    virtual void GrabFocus() override
    {
        mxLineEndSet->GrabFocus();
    }

public:
    SvxLineEndWindow(SvxLineEndToolBoxControl* pControl, weld::Widget* pParent);
    virtual void statusChanged( const css::frame::FeatureStateEvent& rEvent ) override;
};

}

static constexpr sal_uInt16 gnCols = 2;

SvxLineEndWindow::SvxLineEndWindow(SvxLineEndToolBoxControl* pControl, weld::Widget* pParent)
    : WeldToolbarPopup(pControl->getFrameInterface(), pParent, "svx/ui/floatinglineend.ui", "FloatingLineEnd")
    , mxControl(pControl)
    , mxLineEndSet(new ValueSet(m_xBuilder->weld_scrolled_window("valuesetwin")))
    , mxLineEndSetWin(new weld::CustomWeld(*m_xBuilder, "valueset", *mxLineEndSet))
    , mnLines(12)
{
    mxLineEndSet->SetStyle(mxLineEndSet->GetStyle() | WB_ITEMBORDER | WB_3DLOOK | WB_NO_DIRECTSELECT);
    mxLineEndSet->SetHelpId(HID_POPUP_LINEEND_CTRL);
    m_xTopLevel->set_help_id(HID_POPUP_LINEEND);

    SfxObjectShell* pDocSh = SfxObjectShell::Current();
    if ( pDocSh )
    {
        const SfxPoolItem*  pItem = pDocSh->GetItem( SID_LINEEND_LIST );
        if( pItem )
            mpLineEndList = static_cast<const SvxLineEndListItem*>( pItem )->GetLineEndList();
    }
    DBG_ASSERT( mpLineEndList.is(), "LineEndList not found" );

    mxLineEndSet->SetSelectHdl( LINK( this, SvxLineEndWindow, SelectHdl ) );
    mxLineEndSet->SetColCount( gnCols );

    // ValueSet fill with entries of LineEndList
    FillValueSet();

    AddStatusListener( ".uno:LineEndListState");
}

IMPL_LINK_NOARG(SvxLineEndWindow, SelectHdl, ValueSet*, void)
{
    std::unique_ptr<XLineEndItem> pLineEndItem;
    std::unique_ptr<XLineStartItem> pLineStartItem;
    sal_uInt16 nId = mxLineEndSet->GetSelectedItemId();

    if( nId == 1 )
    {
        pLineStartItem.reset(new XLineStartItem());
    }
    else if( nId == 2 )
    {
        pLineEndItem.reset(new XLineEndItem());
    }
    else if( nId % 2 ) // beginning of line
    {
        const XLineEndEntry* pEntry = mpLineEndList->GetLineEnd( (nId - 1) / 2 - 1 );
        pLineStartItem.reset(new XLineStartItem(pEntry->GetName(), pEntry->GetLineEnd()));
    }
    else // end of line
    {
        const XLineEndEntry* pEntry = mpLineEndList->GetLineEnd( nId / 2 - 2 );
        pLineEndItem.reset(new XLineEndItem(pEntry->GetName(), pEntry->GetLineEnd()));
    }

    Sequence< PropertyValue > aArgs( 1 );
    Any a;

    if ( pLineStartItem )
    {
        aArgs[0].Name = "LineStart";
        pLineStartItem->QueryValue( a );
        aArgs[0].Value = a;
    }
    else
    {
        aArgs[0].Name = "LineEnd";
        pLineEndItem->QueryValue( a );
        aArgs[0].Value = a;
    }

    /*  #i33380# DR 2004-09-03 Moved the following line above the Dispatch() call.
        This instance may be deleted in the meantime (i.e. when a dialog is opened
        while in Dispatch()), accessing members will crash in this case. */
    mxLineEndSet->SetNoSelection();

    mxControl->dispatchCommand(mxControl->getCommandURL(), aArgs);

    mxControl->EndPopupMode();
}

void SvxLineEndWindow::FillValueSet()
{
    if( !mpLineEndList.is() )
        return;

    ScopedVclPtrInstance< VirtualDevice > pVD;

    long nCount = mpLineEndList->Count();

    // First entry: no line end.
    // An entry is temporarily added to get the UI bitmap
    basegfx::B2DPolyPolygon aNothing;
    mpLineEndList->Insert(std::make_unique<XLineEndEntry>(aNothing,
        comphelper::LibreOfficeKit::isActive() ? SvxResId(RID_SVXSTR_INVISIBLE)
            : SvxResId(RID_SVXSTR_NONE)));
    const XLineEndEntry* pEntry = mpLineEndList->GetLineEnd(nCount);
    BitmapEx aBmp = mpLineEndList->GetUiBitmap( nCount );
    OSL_ENSURE( !aBmp.IsEmpty(), "UI bitmap was not created" );

    maBmpSize = aBmp.GetSizePixel();
    pVD->SetOutputSizePixel( maBmpSize, false );
    maBmpSize.setWidth( maBmpSize.Width() / 2 );
    Point aPt0( 0, 0 );
    Point aPt1( maBmpSize.Width(), 0 );

    pVD->DrawBitmapEx( Point(), aBmp );
    mxLineEndSet->InsertItem(1, Image(pVD->GetBitmapEx(aPt0, maBmpSize)), pEntry->GetName());
    mxLineEndSet->InsertItem(2, Image(pVD->GetBitmapEx(aPt1, maBmpSize)), pEntry->GetName());

    mpLineEndList->Remove(nCount);

    for( long i = 0; i < nCount; i++ )
    {
        pEntry = mpLineEndList->GetLineEnd( i );
        DBG_ASSERT( pEntry, "Could not access LineEndEntry" );
        aBmp = mpLineEndList->GetUiBitmap( i );
        OSL_ENSURE( !aBmp.IsEmpty(), "UI bitmap was not created" );

        pVD->DrawBitmapEx( aPt0, aBmp );
        mxLineEndSet->InsertItem(static_cast<sal_uInt16>((i+1)*2L+1),
                Image(pVD->GetBitmapEx(aPt0, maBmpSize)), pEntry->GetName());
        mxLineEndSet->InsertItem(static_cast<sal_uInt16>((i+2)*2L),
                Image(pVD->GetBitmapEx(aPt1, maBmpSize)), pEntry->GetName());
    }
    mnLines = std::min( static_cast<sal_uInt16>(nCount + 1), sal_uInt16(MAX_LINES) );
    mxLineEndSet->SetLineCount( mnLines );

    SetSize();
}

void SvxLineEndWindow::statusChanged( const css::frame::FeatureStateEvent& rEvent )
{
    if ( rEvent.FeatureURL.Complete == ".uno:LineEndListState" )
    {
        // The list of line ends (LineEndList) has changed
        css::uno::Reference< css::uno::XWeak > xWeak;
        if ( rEvent.State >>= xWeak )
        {
            mpLineEndList.set( static_cast< XLineEndList* >( xWeak.get() ) );
            DBG_ASSERT( mpLineEndList.is(), "LineEndList not found" );

            mxLineEndSet->Clear();
            FillValueSet();
        }
    }
}

void SvxLineEndWindow::SetSize()
{
    sal_uInt16 nItemCount = mxLineEndSet->GetItemCount();
    sal_uInt16 nMaxLines  = nItemCount / gnCols;

    WinBits nBits = mxLineEndSet->GetStyle();
    if ( mnLines == nMaxLines )
        nBits &= ~WB_VSCROLL;
    else
        nBits |= WB_VSCROLL;
    mxLineEndSet->SetStyle( nBits );

    Size aSize( maBmpSize );
    aSize.AdjustWidth(6 );
    aSize.AdjustHeight(6 );
    aSize = mxLineEndSet->CalcWindowSizePixel( aSize );
    mxLineEndSet->GetDrawingArea()->set_size_request(aSize.Width(), aSize.Height());
    mxLineEndSet->SetOutputSizePixel(aSize);
}

SvxLineEndToolBoxControl::SvxLineEndToolBoxControl( const css::uno::Reference<css::uno::XComponentContext>& rContext )
    : svt::PopupWindowController( rContext, nullptr, OUString() )
{
}

void SAL_CALL SvxLineEndToolBoxControl::execute(sal_Int16 /*KeyModifier*/)
{
    if (m_pToolbar)
    {
        // Toggle the popup also when toolbutton is activated
        const OString aId(m_aCommandURL.toUtf8());
        m_pToolbar->set_menu_item_active(aId, !m_pToolbar->get_menu_item_active(aId));
    }
    else
    {
        // Open the popup also when Enter key is pressed.
        createPopupWindow();
    }
}

void SvxLineEndToolBoxControl::initialize( const css::uno::Sequence<css::uno::Any>& rArguments )
{
    svt::PopupWindowController::initialize( rArguments );

    if (m_pToolbar)
    {
        mxPopoverContainer.reset(new ToolbarPopupContainer(m_pToolbar));
        m_pToolbar->set_item_popover(m_aCommandURL.toUtf8(), mxPopoverContainer->getTopLevel());
    }

    ToolBox* pToolBox = nullptr;
    sal_uInt16 nId = 0;
    if ( getToolboxId( nId, &pToolBox ) )
        pToolBox->SetItemBits( nId, pToolBox->GetItemBits( nId ) | ToolBoxItemBits::DROPDOWNONLY );
}

std::unique_ptr<WeldToolbarPopup> SvxLineEndToolBoxControl::weldPopupWindow()
{
    return std::make_unique<SvxLineEndWindow>(this, m_pToolbar);
}

VclPtr<vcl::Window> SvxLineEndToolBoxControl::createVclPopupWindow( vcl::Window* pParent )
{
    mxInterimPopover = VclPtr<InterimToolbarPopup>::Create(getFrameInterface(), pParent,
        std::make_unique<SvxLineEndWindow>(this, pParent->GetFrameWeld()));

    mxInterimPopover->Show();

    mxInterimPopover->SetText(SvxResId(RID_SVXSTR_LINEEND));

    return mxInterimPopover;
}

OUString SvxLineEndToolBoxControl::getImplementationName()
{
    return "com.sun.star.comp.svx.LineEndToolBoxControl";
}

css::uno::Sequence<OUString> SvxLineEndToolBoxControl::getSupportedServiceNames()
{
    return { "com.sun.star.frame.ToolbarController" };
}

extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface *
com_sun_star_comp_svx_LineEndToolBoxControl_get_implementation(
    css::uno::XComponentContext* rContext,
    css::uno::Sequence<css::uno::Any> const & )
{
    return cppu::acquire( new SvxLineEndToolBoxControl( rContext ) );
}

SvxLineBox::SvxLineBox(SvxLineStyleToolBoxControl* pControl, weld::Widget* pParent, int nInitialIndex)
    : WeldToolbarPopup(pControl->getFrameInterface(), pParent, "svx/ui/floatinglinestyle.ui", "FloatingLineStyle")
    , mxControl(pControl)
    , mxLineStyleSet(new ValueSet(m_xBuilder->weld_scrolled_window("valuesetwin")))
    , mxLineStyleSetWin(new weld::CustomWeld(*m_xBuilder, "valueset", *mxLineStyleSet))
{
    mxLineStyleSet->SetStyle(WB_FLATVALUESET | WB_ITEMBORDER | WB_3DLOOK | WB_NO_DIRECTSELECT);

    FillControl();

    mxLineStyleSet->SelectItem(nInitialIndex + 1);

    mxLineStyleSet->SetSelectHdl( LINK( this, SvxLineBox, SelectHdl ) );
}

void SvxLineBox::GrabFocus()
{
    mxLineStyleSet->GrabFocus();
}

SvxLineBox::~SvxLineBox()
{
}

// Fills the listbox (provisional) with strings

void SvxLineBox::Fill( const XDashListRef &pList )
{
    mxLineStyleSet->Clear();

    if( !pList.is() )
        return;

    // entry for 'none'
    mxLineStyleSet->InsertItem(1, Image(), pList->GetStringForUiNoLine());

    // entry for solid line
    auto aBmp = pList->GetBitmapForUISolidLine();
    Size aBmpSize = aBmp.GetSizePixel();
    mxLineStyleSet->InsertItem(2, Image(aBmp), pList->GetStringForUiSolidLine());

    // entries for dashed lines
    long nCount = pList->Count();
    for( long i = 0; i < nCount; i++ )
    {
        const XDashEntry* pEntry = pList->GetDash(i);
        const BitmapEx aBitmap = pList->GetUiBitmap(i);

        mxLineStyleSet->InsertItem(i + 3, Image(aBitmap), pEntry->GetName());
    }

    sal_uInt16 nLines = std::min( static_cast<sal_uInt16>(nCount + 2), sal_uInt16(MAX_LINES) );
    mxLineStyleSet->SetLineCount(nLines);

    WinBits nBits = mxLineStyleSet->GetStyle();
    if ( nLines == mxLineStyleSet->GetItemCount() )
        nBits &= ~WB_VSCROLL;
    else
        nBits |= WB_VSCROLL;
    mxLineStyleSet->SetStyle( nBits );

    Size aSize(aBmpSize);
    aSize.AdjustWidth(6);
    aSize.AdjustHeight(6);
    aSize = mxLineStyleSet->CalcWindowSizePixel(aSize);
    mxLineStyleSet->GetDrawingArea()->set_size_request(aSize.Width(), aSize.Height());
    mxLineStyleSet->SetOutputSizePixel(aSize);
}

IMPL_LINK_NOARG(SvxLineBox, SelectHdl, ValueSet*, void)
{
    drawing::LineStyle eXLS;
    sal_Int32 nPos = mxLineStyleSet->GetSelectedItemId();
    --nPos; // ids start at 1, get the pos of the id

    switch ( nPos )
    {
        case 0:
            eXLS = drawing::LineStyle_NONE;
            break;

        case 1:
            eXLS = drawing::LineStyle_SOLID;
            break;

        default:
        {
            eXLS = drawing::LineStyle_DASH;

            if ( nPos != -1 &&
                 SfxObjectShell::Current()  &&
                 SfxObjectShell::Current()->GetItem( SID_DASH_LIST ) )
            {
                // LineDashItem will only be sent if it also has a dash.
                // Notify cares!
                SvxDashListItem const * pItem = SfxObjectShell::Current()->GetItem( SID_DASH_LIST );
                const XDashEntry* pEntry = pItem->GetDashList()->GetDash(nPos - 2);
                XLineDashItem aLineDashItem(pEntry->GetName(), pEntry->GetDash());

                Any a;
                Sequence< PropertyValue > aArgs( 1 );
                aArgs[0].Name = "LineDash";
                aLineDashItem.QueryValue ( a );
                aArgs[0].Value = a;
                mxControl->dispatchLineStyleCommand(".uno:LineDash", aArgs);
            }
        }
        break;
    }

    XLineStyleItem aLineStyleItem( eXLS );
    Any a;
    Sequence< PropertyValue > aArgs( 1 );
    aArgs[0].Name = "XLineStyle";
    aLineStyleItem.QueryValue ( a );
    aArgs[0].Value = a;
    mxControl->dispatchLineStyleCommand(".uno:XLineStyle", aArgs);

    mxControl->EndPopupMode();
}

void SvxLineBox::FillControl()
{
    SfxObjectShell* pSh = SfxObjectShell::Current();
    if (pSh)
    {
        const SvxDashListItem* pItem = pSh->GetItem( SID_DASH_LIST );
        if (pItem)
            Fill(pItem->GetDashList());
    }
}

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