summaryrefslogtreecommitdiff
path: root/svx/source/sidebar/text/TextPropertyPanel.cxx
blob: b4794efd7a37de582f35c5707e6be86422b0297e (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
/* -*- 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 "TextPropertyPanel.hrc"
#include "TextPropertyPanel.hxx"

#include <editeng/kernitem.hxx>
#include <editeng/udlnitem.hxx>
#include <rtl/ref.hxx>
#include <sfx2/dispatch.hxx>
#include <svtools/unitconv.hxx>

#include <vcl/toolbox.hxx>
#include "TextCharacterSpacingControl.hxx"
#include "TextUnderlineControl.hxx"
#include "TextUnderlinePopup.hxx"
#include <svx/sidebar/PopupContainer.hxx>


using namespace css;
using namespace css::uno;

const char UNO_UNDERLINE[] = ".uno:Underline";

namespace svx { namespace sidebar {

VclPtr<PopupControl> TextPropertyPanel::CreateUnderlinePopupControl (PopupContainer* pParent)
{
    return VclPtrInstance<TextUnderlineControl>(pParent, *this, mpBindings);
}

VclPtr<vcl::Window> TextPropertyPanel::Create (
    vcl::Window* pParent,
    const css::uno::Reference<css::frame::XFrame>& rxFrame,
    SfxBindings* pBindings,
    const ::sfx2::sidebar::EnumContext& rContext)
{
    if (pParent == nullptr)
        throw lang::IllegalArgumentException("no parent Window given to TextPropertyPanel::Create", nullptr, 0);
    if ( ! rxFrame.is())
        throw lang::IllegalArgumentException("no XFrame given to TextPropertyPanel::Create", nullptr, 1);
    if (pBindings == nullptr)
        throw lang::IllegalArgumentException("no SfxBindings given to TextPropertyPanel::Create", nullptr, 2);

    return VclPtr<TextPropertyPanel>::Create(
                pParent,
                rxFrame,
                pBindings,
                rContext);
}

TextPropertyPanel::TextPropertyPanel ( vcl::Window* pParent, const css::uno::Reference<css::frame::XFrame>& rxFrame, SfxBindings* pBindings, const ::sfx2::sidebar::EnumContext& /*rContext*/ )
    : PanelLayout(pParent, "SidebarTextPanel", "svx/ui/sidebartextpanel.ui", rxFrame),
        maFontSizeControl   (SID_ATTR_CHAR_FONTHEIGHT,  *pBindings, *this, OUString("FontHeight"),   rxFrame),
        maUnderlineControl  (SID_ATTR_CHAR_UNDERLINE,   *pBindings, *this, OUString("Underline"),    rxFrame),

        maUnderlinePopup(this, [this] (PopupContainer *const pContainer) { return this->CreateUnderlinePopupControl(pContainer); }),
        maContext(),
        mpBindings(pBindings)
{
    get(mpToolBoxFont, "fonteffects");
    get(mpToolBoxIncDec, "fontadjust");
    get(mpToolBoxSpacing, "spacingbar");
    get(mpToolBoxFontColorSw, "colorbar_writer");
    get(mpToolBoxFontColor, "colorbar_others");
    get(mpToolBoxBackgroundColor, "colorbar_background");

    //toolbox
    SetupToolboxItems();
    InitToolBoxFont();

    //init state
    mpHeightItem = nullptr;
    meUnderline = LINESTYLE_NONE;
    meUnderlineColor = COL_AUTO;
}

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

void TextPropertyPanel::dispose()
{
    mpToolBoxFont.clear();
    mpToolBoxIncDec.clear();
    mpToolBoxSpacing.clear();
    mpToolBoxFontColorSw.clear();
    mpToolBoxFontColor.clear();

    maFontSizeControl.dispose();
    maUnderlineControl.dispose();

    maUnderlinePopup.dispose();

    PanelLayout::dispose();
}

void TextPropertyPanel::HandleContextChange (
    const ::sfx2::sidebar::EnumContext& rContext)
{
    if (maContext == rContext)
        return;

    maContext = rContext;

    bool bWriterText = false;
    bool bDrawText = false;
    bool bNeedTextSpacing = false;

    switch (maContext.GetCombinedContext_DI())
    {
        case CombinedEnumContext(Application_Calc, Context_Cell):
        case CombinedEnumContext(Application_Calc, Context_Pivot):
            // bNeedTextSpacing = false;
            break;

        case CombinedEnumContext(Application_Calc, Context_EditCell):
        case CombinedEnumContext(Application_Calc, Context_DrawText):

        case CombinedEnumContext(Application_WriterVariants, Context_DrawText):
        case CombinedEnumContext(Application_WriterVariants, Context_Annotation):
        case CombinedEnumContext(Application_DrawImpress, Context_DrawText):
        case CombinedEnumContext(Application_DrawImpress, Context_Text):
        case CombinedEnumContext(Application_DrawImpress, Context_Table):
        case CombinedEnumContext(Application_DrawImpress, Context_OutlineText):
        case CombinedEnumContext(Application_DrawImpress, Context_Draw):
        case CombinedEnumContext(Application_DrawImpress, Context_TextObject):
        case CombinedEnumContext(Application_DrawImpress, Context_Graphic):
            bNeedTextSpacing = true;
            bDrawText = true;
            break;

        case CombinedEnumContext(Application_WriterVariants, Context_Text):
        case CombinedEnumContext(Application_WriterVariants, Context_Table):
            bNeedTextSpacing = true;
            bWriterText = true;
            break;

        default:
            break;
    }

    mpToolBoxSpacing->Enable(bNeedTextSpacing);
    mpToolBoxFontColor->Show(!bWriterText);
    mpToolBoxFontColorSw->Show(bWriterText);
    mpToolBoxBackgroundColor->Show(bDrawText);
}

void TextPropertyPanel::DataChanged (const DataChangedEvent& /*rEvent*/)
{
    SetupToolboxItems();
}

void TextPropertyPanel::EndUnderlinePopupMode()
{
    maUnderlinePopup.Hide();
}

void TextPropertyPanel::InitToolBoxFont()
{
    Link<ToolBox *, void> aLink = LINK(this, TextPropertyPanel, UnderlineClickHdl);
    mpToolBoxFont->SetDropdownClickHdl(aLink);
}

void TextPropertyPanel::SetupToolboxItems()
{
    maUnderlineControl.SetupToolBoxItem(*mpToolBoxFont, mpToolBoxFont->GetItemId(UNO_UNDERLINE));
}

IMPL_LINK_TYPED(TextPropertyPanel, UnderlineClickHdl, ToolBox*, pToolBox, void)
{
    const sal_uInt16 nId = pToolBox->GetCurItemId();
    const OUString aCommand(pToolBox->GetItemCommand(nId));

    if (aCommand == UNO_UNDERLINE)
    {
        pToolBox->SetItemDown( nId, true );
        maUnderlinePopup.Rearrange(meUnderline);
        maUnderlinePopup.Show(*pToolBox);
    }
}

void TextPropertyPanel::NotifyItemUpdate (
    const sal_uInt16 nSID,
    const SfxItemState eState,
    const SfxPoolItem* pState,
    const bool bIsEnabled)
{
    switch(nSID)
    {
    case SID_ATTR_CHAR_FONTHEIGHT:
        {
            if (  eState >= SfxItemState::DEFAULT && dynamic_cast<const SvxFontHeightItem*>( pState) !=  nullptr )
                mpHeightItem = const_cast<SvxFontHeightItem*>(static_cast<const SvxFontHeightItem*>(pState));
            else
                mpHeightItem = nullptr;
        }
        break;
    case SID_ATTR_CHAR_UNDERLINE:
        {
            if( eState >= SfxItemState::DEFAULT && dynamic_cast<const SvxUnderlineItem*>( pState) !=  nullptr )
            {
                const SvxUnderlineItem* pItem = static_cast<const SvxUnderlineItem*>(pState);
                meUnderline = (FontLineStyle)pItem->GetValue();
                meUnderlineColor = pItem->GetColor();
            }
            else
                meUnderline = LINESTYLE_NONE;
        }
        break;
    case SID_ATTR_CHAR_KERNING:
        {
            mpToolBoxSpacing->Enable(bIsEnabled);
        }
        break;
    }
}

} } // end of namespace svx::sidebar

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