summaryrefslogtreecommitdiffstats
path: root/svx/source/sidebar/text/TextUnderlineControl.cxx
blob: aaf5f82d3deef67d6f5eed775469d04b93743072 (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
/* -*- 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 "TextUnderlineControl.hxx"
#include <svx/strings.hrc>
#include <svx/dialmgr.hxx>
#include <svx/svxids.hrc>
#include <sfx2/dispatch.hxx>
#include <sfx2/sidebar/Theme.hxx>
#include <editeng/editids.hrc>
#include <editeng/udlnitem.hxx>
#include <vcl/settings.hxx>
#include "helpids.h"

namespace svx {

TextUnderlineControl::TextUnderlineControl(sal_uInt16 nId)
:   SfxPopupWindow(nId, "TextUnderlineControl", "svx/ui/textunderlinecontrol.ui")
{
    get(maNone, "none");
    get(maSingle, "single");
    get(maDouble, "double");
    get(maBold, "bold");
    get(maDot, "dot");
    get(maDotBold, "dotbold");
    get(maDash, "dash");
    get(maDashLong, "dashlong");
    get(maDashDot, "dashdot");
    get(maDashDotDot, "dashdotdot");
    get(maWave, "wave");
    get(maMoreOptions, "moreoptions");

    maMoreOptions->SetHelpId(HID_UNDERLINE_BTN);

    Link<Button*,void> aLink = LINK(this, TextUnderlineControl, PBClickHdl);
    maNone->SetClickHdl(aLink);
    maSingle->SetClickHdl(aLink);
    maDouble->SetClickHdl(aLink);
    maBold->SetClickHdl(aLink);
    maDot->SetClickHdl(aLink);
    maDotBold->SetClickHdl(aLink);
    maDash->SetClickHdl(aLink);
    maDashLong->SetClickHdl(aLink);
    maDashDot->SetClickHdl(aLink);
    maDashDotDot->SetClickHdl(aLink);
    maWave->SetClickHdl(aLink);
    maMoreOptions->SetClickHdl(aLink);
}

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

void TextUnderlineControl::dispose()
{
    maNone.clear();
    maSingle.clear();
    maDouble.clear();
    maBold.clear();
    maDot.clear();
    maDotBold.clear();
    maDash.clear();
    maDashLong.clear();
    maDashDot.clear();
    maDashDotDot.clear();
    maWave.clear();
    maMoreOptions.clear();

    SfxPopupWindow::dispose();
}

FontLineStyle TextUnderlineControl::getLineStyle(Button const * pButton)
{
    if(pButton == maSingle)
        return LINESTYLE_SINGLE;
    else if(pButton == maDouble)
        return LINESTYLE_DOUBLE;
    else if(pButton == maBold)
        return LINESTYLE_BOLD;
    else if(pButton == maDot)
        return LINESTYLE_DOTTED;
    else if(pButton == maDotBold)
        return LINESTYLE_BOLDDOTTED;
    else if(pButton == maDash)
        return LINESTYLE_DASH;
    else if(pButton == maDashLong)
        return LINESTYLE_LONGDASH;
    else if(pButton == maDashDot)
        return LINESTYLE_DASHDOT;
    else if(pButton == maDashDotDot)
        return LINESTYLE_DASHDOTDOT;
    else if(pButton == maWave)
        return LINESTYLE_WAVE;

    return LINESTYLE_NONE;
}

namespace {

Color GetUnderlineColor()
{
    const SfxPoolItem* pItem;
    SfxViewFrame::Current()->GetBindings().GetDispatcher()->QueryState(SID_ATTR_CHAR_UNDERLINE, pItem);

    const SvxUnderlineItem* pUnderlineItem = static_cast<const SvxUnderlineItem*>(pItem);

    if(pUnderlineItem)
        return pUnderlineItem->GetColor();

    return COL_AUTO;
}

}

IMPL_LINK(TextUnderlineControl, PBClickHdl, Button*, pButton, void)
{
    if(pButton == maMoreOptions)
    {
        SfxDispatcher* pDisp = SfxViewFrame::Current()->GetBindings().GetDispatcher();
        pDisp->Execute(SID_CHAR_DLG_EFFECT, SfxCallMode::ASYNCHRON);

        EndPopupMode();
    }
    else
    {
        const FontLineStyle eUnderline = getLineStyle(pButton);

        SvxUnderlineItem aLineItem(eUnderline, SID_ATTR_CHAR_UNDERLINE);
        aLineItem.SetColor(GetUnderlineColor());

        SfxViewFrame::Current()->GetBindings().GetDispatcher()->ExecuteList(SID_ATTR_CHAR_UNDERLINE,
               SfxCallMode::RECORD, { &aLineItem });

        EndPopupMode();
    }
}

}

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