summaryrefslogtreecommitdiffstats
path: root/svx/source/tbxctrls/layctrl.cxx
blob: 88b110e8c1f103b725e1a0fb859a2663f8aa70bb (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
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
/* -*- 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 <vcl/customweld.hxx>
#include <vcl/event.hxx>
#include <vcl/settings.hxx>
#include <vcl/svapp.hxx>
#include <vcl/toolbox.hxx>

#include <svx/strings.hrc>
#include <svx/layctrl.hxx>
#include <svx/dialmgr.hxx>
#include <comphelper/processfactory.hxx>
#include <svtools/colorcfg.hxx>
#include <svtools/toolbarmenu.hxx>
#include <com/sun/star/util/URLTransformer.hpp>
#include <com/sun/star/frame/XDispatchProvider.hpp>

// namespaces
using namespace ::com::sun::star::uno;
using namespace ::com::sun::star::beans;
using namespace ::com::sun::star::util;
using namespace ::com::sun::star::frame;

namespace {

class TableWidget final : public weld::CustomWidgetController
{
private:
    rtl::Reference<SvxTableToolBoxControl> mxControl;
    OUString maCommand;

    long                nCol;
    long                nLine;

    static const long TABLE_CELLS_HORIZ;
    static const long TABLE_CELLS_VERT;

    long mnTableCellWidth;
    long mnTableCellHeight;

    long mnTableWidth;
    long mnTableHeight;

    ::Color             aFontColor;
    ::Color             aLineColor;
    ::Color             aFillColor;
    ::Color             aHighlightFillColor;
    ::Color             aBackgroundColor;

    void                Update(long nNewCol, long nNewLine);
    void                InsertTable();

public:
    TableWidget(SvxTableToolBoxControl* pControl, const OUString& rCommand);

    virtual void SetDrawingArea(weld::DrawingArea* pDrawingArea) override;

    virtual bool KeyInput(const KeyEvent&) override;
    virtual bool MouseButtonDown(const MouseEvent&) override;
    virtual bool MouseMove(const MouseEvent&) override;
    virtual bool MouseButtonUp(const MouseEvent&) override;
    virtual void Paint(vcl::RenderContext& rRenderContext, const tools::Rectangle& rRect) override;
};

class TableWindow final : public WeldToolbarPopup
{
private:
    std::unique_ptr<weld::Button> mxTableButton;
    std::unique_ptr<TableWidget> mxTableWidget;
    std::unique_ptr<weld::CustomWeld> mxTableWidgetWin;
    rtl::Reference<SvxTableToolBoxControl> mxControl;

    DECL_LINK(SelectHdl, weld::Button&, void);

public:
    TableWindow( SvxTableToolBoxControl* pControl, weld::Widget* pParent,
                 const OUString& rCmd);
    virtual void GrabFocus() override
    {
        mxTableWidget->GrabFocus();
    }
};

}

const long TableWidget::TABLE_CELLS_HORIZ = 10;
const long TableWidget::TABLE_CELLS_VERT = 15;

IMPL_LINK_NOARG(TableWindow, SelectHdl, weld::Button&, void)
{
    mxControl->CloseAndShowTableDialog();
}

TableWindow::TableWindow(SvxTableToolBoxControl* pControl, weld::Widget* pParent, const OUString& rCmd)
    : WeldToolbarPopup(pControl->getFrameInterface(), pParent, "svx/ui/tablewindow.ui", "TableWindow")
    , mxTableButton(m_xBuilder->weld_button("moreoptions"))
    , mxTableWidget(new TableWidget(pControl, rCmd))
    , mxTableWidgetWin(new weld::CustomWeld(*m_xBuilder, "table", *mxTableWidget))
    , mxControl(pControl)
{
    mxTableButton->set_label( SvxResId( RID_SVXSTR_MORE ) );
    mxTableButton->connect_clicked( LINK( this, TableWindow, SelectHdl ) );
    mxTableButton->show();
}

TableWidget::TableWidget(SvxTableToolBoxControl* pControl, const OUString& rCommand)
    : mxControl(pControl)
    , maCommand(rCommand)
    , nCol(0)
    , nLine(0)
    , mnTableCellWidth(0)
    , mnTableCellHeight(0)
    , mnTableWidth(0)
    , mnTableHeight(0)
{
    const StyleSettings& rStyles = Application::GetSettings().GetStyleSettings();
    svtools::ColorConfig aColorConfig;
    aFontColor = aColorConfig.GetColorValue( svtools::FONTCOLOR ).nColor;
    aLineColor = rStyles.GetShadowColor();
    aFillColor = rStyles.GetWindowColor();
    aHighlightFillColor = rStyles.GetHighlightColor();
    aBackgroundColor = rStyles.GetFaceColor();
}

void TableWidget::SetDrawingArea(weld::DrawingArea* pDrawingArea)
{
    float fScaleFactor = pDrawingArea->get_ref_device().GetDPIScaleFactor();

    mnTableCellWidth  = 15 * fScaleFactor;
    mnTableCellHeight = 15 * fScaleFactor;

    mnTableWidth  = TABLE_CELLS_HORIZ*mnTableCellWidth;
    mnTableHeight = TABLE_CELLS_VERT*mnTableCellHeight;

    // + 1 to leave space to draw the right/bottom borders
    Size aSize(mnTableWidth + 1, mnTableHeight + 1);
    pDrawingArea->set_size_request(aSize.Width(), aSize.Height());
    CustomWidgetController::SetDrawingArea(pDrawingArea);
    SetOutputSizePixel(aSize);
}

bool TableWidget::MouseMove(const MouseEvent& rMEvt)
{
    Point aPos = rMEvt.GetPosPixel();
    Point aMousePos( aPos );

    long nNewCol = ( aMousePos.X() + mnTableCellWidth ) / mnTableCellWidth;
    long nNewLine = ( aMousePos.Y() + mnTableCellHeight ) / mnTableCellHeight;

    Update( nNewCol, nNewLine );

    return true;
}

bool TableWidget::KeyInput(const KeyEvent& rKEvt)
{
    bool bHandled = false;
    sal_uInt16 nModifier = rKEvt.GetKeyCode().GetModifier();
    sal_uInt16 nKey = rKEvt.GetKeyCode().GetCode();
    if ( !nModifier )
    {
        bHandled = true;
        long nNewCol = nCol;
        long nNewLine = nLine;
        switch(nKey)
        {
            case KEY_UP:
                if ( nNewLine > 1 )
                    nNewLine--;
                else
                    mxControl->EndPopupMode();
                break;
            case KEY_DOWN:
                if ( nNewLine < TABLE_CELLS_VERT )
                {
                    nNewLine++;
                    if ( nNewCol == 0 )
                        nNewCol = 1;
                }
                else
                    mxControl->CloseAndShowTableDialog();
                break;
            case KEY_LEFT:
                if ( nNewCol > 1 )
                    nNewCol--;
                else
                    mxControl->EndPopupMode();
                break;
            case KEY_RIGHT:
                if ( nNewCol < TABLE_CELLS_HORIZ )
                {
                    nNewCol++;
                    if ( nNewLine == 0 )
                        nNewLine = 1;
                }
                else
                    mxControl->CloseAndShowTableDialog();
                break;
            case KEY_ESCAPE:
                mxControl->EndPopupMode();
                break;
            case KEY_RETURN:
                InsertTable();
                mxControl->EndPopupMode();
                return true;
            default:
                bHandled = false;
        }
        if ( bHandled )
        {
            Update( nNewCol, nNewLine );
        }
    }
    else if (KEY_MOD1 == nModifier && KEY_RETURN == nKey)
    {
        InsertTable();
        mxControl->EndPopupMode();
        return true;
    }

    return bHandled;
}

bool TableWidget::MouseButtonUp(const MouseEvent&)
{
    InsertTable();
    mxControl->EndPopupMode();
    return true;
}

bool TableWidget::MouseButtonDown(const MouseEvent&)
{
    return true;
}

void TableWidget::Paint(vcl::RenderContext& rRenderContext, const tools::Rectangle&)
{
    rRenderContext.Push(PushFlags::FONT);

    rRenderContext.SetBackground( aBackgroundColor );
    vcl::Font aFont = rRenderContext.GetFont();
    aFont.SetColor( aFontColor );
    aFont.SetFillColor( aBackgroundColor );
    aFont.SetTransparent( false );
    rRenderContext.SetFont( aFont );

    const long nSelectionWidth = nCol * mnTableCellWidth;
    const long nSelectionHeight = nLine * mnTableCellHeight;

    // the non-selected parts of the table
    rRenderContext.SetLineColor(aLineColor);
    rRenderContext.SetFillColor(aFillColor);
    rRenderContext.DrawRect(tools::Rectangle(nSelectionWidth, 0, mnTableWidth, nSelectionHeight));
    rRenderContext.DrawRect(tools::Rectangle(0, nSelectionHeight, nSelectionWidth, mnTableHeight));
    rRenderContext.DrawRect(tools::Rectangle(nSelectionWidth, nSelectionHeight, mnTableWidth, mnTableHeight));

    // the selection
    if (nCol > 0 && nLine > 0)
    {
        rRenderContext.SetFillColor(aHighlightFillColor);
        rRenderContext.DrawRect(tools::Rectangle(0, 0, nSelectionWidth, nSelectionHeight));
    }

    // lines inside of the table
    rRenderContext.SetLineColor(aLineColor);
    for (long i = 1; i < TABLE_CELLS_VERT; ++i)
    {
        rRenderContext.DrawLine(Point(0, i*mnTableCellHeight),
                                Point(mnTableWidth, i*mnTableCellHeight));
    }

    for (long i = 1; i < TABLE_CELLS_HORIZ; ++i)
    {
        rRenderContext.DrawLine(Point( i*mnTableCellWidth, 0),
                                Point( i*mnTableCellWidth, mnTableHeight));
    }

    // the text near the mouse cursor telling the table dimensions
    if (!nCol || !nLine)
    {
        rRenderContext.Pop();
        return;
    }

    OUString aText = OUString::number( nCol ) + " x " + OUString::number( nLine );
    if (maCommand == ".uno:ShowMultiplePages")
    {
        aText += " " + SvxResId(RID_SVXSTR_PAGES);
    }

    Size aTextSize(rRenderContext.GetTextWidth(aText), rRenderContext.GetTextHeight());

    long nTextX = nSelectionWidth + mnTableCellWidth;
    long nTextY = nSelectionHeight + mnTableCellHeight;
    const long nTipBorder = 2;

    if (aTextSize.Width() + mnTableCellWidth + 2 * nTipBorder < nSelectionWidth)
        nTextX = nSelectionWidth - mnTableCellWidth - aTextSize.Width();

    if (aTextSize.Height() + mnTableCellHeight + 2 * nTipBorder < nSelectionHeight)
        nTextY = nSelectionHeight - mnTableCellHeight - aTextSize.Height();

    rRenderContext.SetLineColor(aLineColor);
    rRenderContext.SetFillColor(aBackgroundColor);
    rRenderContext.DrawRect(tools::Rectangle(nTextX - 2 * nTipBorder,
                                      nTextY - 2 * nTipBorder,
                                      nTextX + aTextSize.Width() + nTipBorder,
                                      nTextY + aTextSize.Height() + nTipBorder));

    // #i95350# force RTL output
    if (IsRTLEnabled())
        aText = u"\u202D" + aText;

    rRenderContext.DrawText(Point(nTextX, nTextY), aText);

    rRenderContext.Pop();
}

void TableWidget::InsertTable()
{
    if (nCol && nLine)
    {
        Sequence< PropertyValue > aArgs( 2 );
        aArgs[0].Name = "Columns";
        aArgs[0].Value <<= sal_Int16( nCol );
        aArgs[1].Name = "Rows";
        aArgs[1].Value <<= sal_Int16( nLine );

        mxControl->TableDialog( aArgs );
    }
}

void TableWidget::Update( long nNewCol, long nNewLine )
{
    if ( nNewCol < 0 || nNewCol > TABLE_CELLS_HORIZ )
        nNewCol = 0;

    if ( nNewLine < 0 || nNewLine > TABLE_CELLS_VERT )
        nNewLine = 0;

    if ( nNewCol != nCol || nNewLine != nLine )
    {
        nCol = nNewCol;
        nLine = nNewLine;
        Invalidate(tools::Rectangle(0, 0, mnTableWidth, mnTableHeight));
    }
}

void SvxTableToolBoxControl::TableDialog( const Sequence< PropertyValue >& rArgs )
{
    Reference< XDispatchProvider > xDispatchProvider( m_xFrame, UNO_QUERY );
    if ( xDispatchProvider.is() )
    {
        css::util::URL aTargetURL;
        Reference < XURLTransformer > xTrans( URLTransformer::create(::comphelper::getProcessComponentContext()) );
        aTargetURL.Complete = m_aCommandURL;
        xTrans->parseStrict( aTargetURL );

        Reference< XDispatch > xDispatch = xDispatchProvider->queryDispatch( aTargetURL, OUString(), 0 );
        if ( xDispatch.is() )
            xDispatch->dispatch( aTargetURL, rArgs );
    }
}

void SvxTableToolBoxControl::CloseAndShowTableDialog()
{
    // close the toolbar tool
    EndPopupMode();

    // and open the table dialog instead
    TableDialog( Sequence< PropertyValue >() );
}

namespace {

class ColumnsWidget final : public weld::CustomWidgetController
{
private:
    static constexpr long WIDTH = 5;

    rtl::Reference<SvxColumnsToolBoxControl> mxControl;
    weld::SpinButton& mrSpinButton;

    ::Color             aLineColor;
    ::Color             aHighlightLineColor;
    ::Color             aFillColor;
    ::Color             aHighlightFillColor;
    ::Color             aFaceColor;
    long                nCol;
    long                nMX;
    bool                m_bMod1;

    DECL_LINK(ValueChangedHdl, weld::SpinButton&, void);
    DECL_LINK(ActivateHdl, weld::Entry&, bool);

    void InsertColumns();
    void UpdateSize_Impl( long nNewCol );
public:
    ColumnsWidget(SvxColumnsToolBoxControl* pControl, weld::SpinButton& rSpinButton);

    virtual void SetDrawingArea(weld::DrawingArea* pDrawingArea) override;

    virtual bool KeyInput(const KeyEvent&) override;
    virtual bool MouseButtonDown(const MouseEvent&) override;
    virtual bool MouseMove(const MouseEvent&) override;
    virtual bool MouseButtonUp(const MouseEvent&) override;
    virtual void Paint(vcl::RenderContext& rRenderContext, const tools::Rectangle& rRect) override;
};


class ColumnsWindow final : public WeldToolbarPopup
{
private:
    std::unique_ptr<weld::SpinButton> mxSpinButton;
    std::unique_ptr<ColumnsWidget> mxColumnsWidget;
    std::unique_ptr<weld::CustomWeld> mxColumnsWidgetWin;
    rtl::Reference<SvxColumnsToolBoxControl> mxControl;

public:
    ColumnsWindow(SvxColumnsToolBoxControl* pControl, weld::Widget* pParent);

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

}

ColumnsWindow::ColumnsWindow(SvxColumnsToolBoxControl* pControl, weld::Widget* pParent)
    : WeldToolbarPopup(pControl->getFrameInterface(), pParent, "svx/ui/columnswindow.ui", "ColumnsWindow")
    , mxSpinButton(m_xBuilder->weld_spin_button("spinbutton"))
    , mxColumnsWidget(new ColumnsWidget(pControl, *mxSpinButton))
    , mxColumnsWidgetWin(new weld::CustomWeld(*m_xBuilder, "columns", *mxColumnsWidget))
    , mxControl(pControl)
{
}

ColumnsWidget::ColumnsWidget(SvxColumnsToolBoxControl* pControl, weld::SpinButton& rSpinButton)
    : mxControl(pControl)
    , mrSpinButton(rSpinButton)
    , nCol(1)
    , nMX(0)
    , m_bMod1(false)
{
    mrSpinButton.connect_value_changed(LINK(this, ColumnsWidget, ValueChangedHdl));
    mrSpinButton.connect_activate(LINK(this, ColumnsWidget, ActivateHdl));

    const StyleSettings& rStyles = Application::GetSettings().GetStyleSettings();
    svtools::ColorConfig aColorConfig;
    aLineColor = aColorConfig.GetColorValue( svtools::FONTCOLOR ).nColor;
    aHighlightLineColor = rStyles.GetHighlightTextColor();
    aFillColor = rStyles.GetWindowColor();
    aHighlightFillColor = rStyles.GetHighlightColor();
    aFaceColor = rStyles.GetFaceColor();
}

IMPL_LINK_NOARG(ColumnsWidget, ValueChangedHdl, weld::SpinButton&, void)
{
    UpdateSize_Impl(mrSpinButton.get_value());
}

IMPL_LINK_NOARG(ColumnsWidget, ActivateHdl, weld::Entry&, bool)
{
    InsertColumns();
    mxControl->EndPopupMode();
    return true;
}

void ColumnsWidget::SetDrawingArea(weld::DrawingArea* pDrawingArea)
{
    OutputDevice& rDevice = pDrawingArea->get_ref_device();
    Size aLogicSize = rDevice.LogicToPixel( Size( 95, 155 ), MapMode( MapUnit::Map10thMM ) );
    nMX = aLogicSize.Width();
    Size aSize(nMX*WIDTH-1, aLogicSize.Height());
    pDrawingArea->set_size_request(aSize.Width(), aSize.Height());
    CustomWidgetController::SetDrawingArea(pDrawingArea);
    SetOutputSizePixel(aSize);
}

bool ColumnsWidget::MouseMove(const MouseEvent& rMEvt)
{
    Point aPos = rMEvt.GetPosPixel();

    long nNewCol = 1;
    if ( aPos.X() > 0 )
        nNewCol = aPos.X() / nMX + 1;
    if ( nNewCol > 20 )
        nNewCol = 20;
    UpdateSize_Impl( nNewCol );

    return true;
}

void ColumnsWidget::UpdateSize_Impl( long nNewCol )
{
    if ( nNewCol != nCol )
    {
        Size aWinSize = GetOutputSizePixel();

        Invalidate( tools::Rectangle( 0, aWinSize.Height() - 2,
                               aWinSize.Width(), aWinSize.Height() ) );

        long nMinCol = 0, nMaxCol = 0;

        if ( nNewCol < nCol )
        {
            nMinCol = nNewCol;
            nMaxCol = nCol;
        }
        else
        {
            nMinCol = nCol;
            nMaxCol = nNewCol;
        }

        Invalidate( tools::Rectangle( nMinCol*nMX-1, 0,
                               nMaxCol*nMX+1, aWinSize.Height() - 2 ) );
        nCol = nNewCol;
        mrSpinButton.set_value(nCol);
    }
}

bool ColumnsWidget::MouseButtonDown(const MouseEvent&)
{
    return true;
}

bool ColumnsWidget::KeyInput(const KeyEvent& rKEvt)
{
    bool bHandled = false;
    sal_uInt16 nModifier = rKEvt.GetKeyCode().GetModifier();
    sal_uInt16 nKey = rKEvt.GetKeyCode().GetCode();
    if(!nModifier)
    {
        if( KEY_LEFT == nKey || KEY_RIGHT == nKey ||
            KEY_RETURN == nKey ||KEY_ESCAPE == nKey ||
            KEY_UP == nKey)
        {
            bHandled = true;
            long nNewCol = nCol;
            switch(nKey)
            {
                case KEY_LEFT :
                    if(nNewCol)
                        nNewCol--;
                break;
                case KEY_RIGHT :
                    nNewCol++;
                break;
                case KEY_RETURN :
                    InsertColumns();
                    mxControl->EndPopupMode();
                break;
                case KEY_ESCAPE :
                case KEY_UP :
                    mxControl->EndPopupMode();
                break;
            }
            UpdateSize_Impl( nNewCol );
        }
    }
    else if(KEY_MOD1 == nModifier && KEY_RETURN == nKey)
    {
        m_bMod1 = true;
        InsertColumns();
        mxControl->EndPopupMode();
    }
    return bHandled;
}

bool ColumnsWidget::MouseButtonUp(const MouseEvent&)
{
    InsertColumns();
    mxControl->EndPopupMode();
    return true;
}

void ColumnsWidget::Paint(vcl::RenderContext& rRenderContext, const tools::Rectangle&)
{
    rRenderContext.Push(PushFlags::FONT);

    rRenderContext.SetBackground();
    vcl::Font aFont( rRenderContext.GetFont() );
    aFont.SetColor( aLineColor );
    aFont.SetFillColor( aFaceColor );
    aFont.SetTransparent( false );
    rRenderContext.SetFont( aFont );

    long i;
    long nLineWidth;
    Size aSize(GetOutputSizePixel());

    for (i = 0; i < WIDTH; i++)
    {
        if (i < nCol)
        {
            rRenderContext.SetLineColor(aHighlightLineColor);
            rRenderContext.SetFillColor(aHighlightFillColor);
        }
        else
        {
            rRenderContext.SetLineColor(aLineColor);
            rRenderContext.SetFillColor(aFillColor);
        }

        rRenderContext.DrawRect(tools::Rectangle(i * nMX - 1, -1, i * nMX + nMX, aSize.Height() - 1));

        long j = 4;
        while (j < aSize.Height() - 4)
        {
            if (!(j % 16))
                nLineWidth = 10;
            else
                nLineWidth = 4;
            rRenderContext.DrawLine(Point(i * nMX + 4, j), Point(i * nMX + nMX - nLineWidth - 4, j));
            j += 4;
        }
    }

    rRenderContext.SetLineColor();
    rRenderContext.SetFillColor(aFaceColor);

    rRenderContext.DrawRect(tools::Rectangle(0,
                                      aSize.Height() - 2,
                                      aSize.Width() / 2 - 1,
                                      aSize.Height()));

    rRenderContext.DrawRect(tools::Rectangle(aSize.Width() / 2,
                                      aSize.Height() - 2,
                                      aSize.Width(),
                                      aSize.Height()));

    rRenderContext.SetLineColor(aLineColor);
    rRenderContext.SetFillColor();
    rRenderContext.DrawRect(tools::Rectangle( 0, 0, aSize.Width() - 1, aSize.Height() - 1));

    rRenderContext.Pop();
}

void SvxColumnsToolBoxControl::InsertColumns(const Sequence< PropertyValue >& rArgs)
{
    Reference< XDispatchProvider > xDispatchProvider( m_xFrame, UNO_QUERY );
    if ( xDispatchProvider.is() )
    {
        css::util::URL aTargetURL;
        Reference < XURLTransformer > xTrans( URLTransformer::create(::comphelper::getProcessComponentContext()) );
        aTargetURL.Complete = m_aCommandURL;
        xTrans->parseStrict( aTargetURL );

        Reference< XDispatch > xDispatch = xDispatchProvider->queryDispatch( aTargetURL, OUString(), 0 );
        if ( xDispatch.is() )
            xDispatch->dispatch( aTargetURL, rArgs );
    }
}

void ColumnsWidget::InsertColumns()
{
    if (nCol)
    {
        Sequence< PropertyValue > aArgs( 2 );
        aArgs[0].Name = "Columns";
        aArgs[0].Value <<= sal_Int16( nCol );
        aArgs[1].Name = "Modifier";
        aArgs[1].Value <<= sal_Int16( m_bMod1 ? KEY_MOD1 : 0 );
        mxControl->InsertColumns(aArgs);
    }
}

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

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

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

SvxTableToolBoxControl::~SvxTableToolBoxControl()
{
}

std::unique_ptr<WeldToolbarPopup> SvxTableToolBoxControl::weldPopupWindow()
{
    return std::make_unique<TableWindow>(this, m_pToolbar, m_aCommandURL);
}

VclPtr<vcl::Window> SvxTableToolBoxControl::createVclPopupWindow( vcl::Window* pParent )
{
    ToolBox* pToolBox = nullptr;
    sal_uInt16 nId = 0;
    bool bToolBox = getToolboxId(nId, &pToolBox);

    mxInterimPopover = VclPtr<InterimToolbarPopup>::Create(getFrameInterface(), pParent,
        std::make_unique<TableWindow>(this, pParent->GetFrameWeld(), m_aCommandURL));

    mxInterimPopover->SetText(bToolBox ? pToolBox->GetItemText(nId) : OUString());

    mxInterimPopover->Show();

    return mxInterimPopover;
}

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

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

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

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

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

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

SvxColumnsToolBoxControl::~SvxColumnsToolBoxControl()
{
}

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

VclPtr<vcl::Window> SvxColumnsToolBoxControl::createVclPopupWindow(vcl::Window* pParent)
{
    ToolBox* pToolBox = nullptr;
    sal_uInt16 nId = 0;
    bool bToolBox = getToolboxId(nId, &pToolBox);

    mxInterimPopover = VclPtr<InterimToolbarPopup>::Create(getFrameInterface(), pParent,
        std::make_unique<ColumnsWindow>(this, pParent->GetFrameWeld()));

    mxInterimPopover->SetText(bToolBox ? pToolBox->GetItemText(nId) : OUString());

    mxInterimPopover->Show();

    return mxInterimPopover;
}

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

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

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

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