Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
5 : * This Source Code Form is subject to the terms of the Mozilla Public
6 : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
11 : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : * contributor license agreements. See the NOTICE file distributed
13 : * with this work for additional information regarding copyright
14 : * ownership. The ASF licenses this file to you under the Apache
15 : * License, Version 2.0 (the "License"); you may not use this file
16 : * except in compliance with the License. You may obtain a copy of
17 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : */
19 :
20 : #include "TextPropertyPanel.hrc"
21 : #include "TextPropertyPanel.hxx"
22 :
23 : #include <editeng/kernitem.hxx>
24 : #include <editeng/udlnitem.hxx>
25 : #include <rtl/ref.hxx>
26 : #include <sfx2/dispatch.hxx>
27 : #include <svtools/unitconv.hxx>
28 :
29 : #include <vcl/toolbox.hxx>
30 : #include "TextCharacterSpacingControl.hxx"
31 : #include "TextCharacterSpacingPopup.hxx"
32 : #include "TextUnderlineControl.hxx"
33 : #include "TextUnderlinePopup.hxx"
34 : #include <svx/sidebar/PopupContainer.hxx>
35 :
36 : #include <boost/bind.hpp>
37 :
38 : using namespace css;
39 : using namespace css::uno;
40 :
41 : const char UNO_SPACING[] = ".uno:Spacing";
42 : const char UNO_UNDERLINE[] = ".uno:Underline";
43 :
44 : namespace svx { namespace sidebar {
45 :
46 0 : PopupControl* TextPropertyPanel::CreateCharacterSpacingControl (PopupContainer* pParent)
47 : {
48 0 : return new TextCharacterSpacingControl(pParent, *this, mpBindings);
49 : }
50 :
51 0 : PopupControl* TextPropertyPanel::CreateUnderlinePopupControl (PopupContainer* pParent)
52 : {
53 0 : return new TextUnderlineControl(pParent, *this, mpBindings);
54 : }
55 :
56 0 : long TextPropertyPanel::GetSelFontSize()
57 : {
58 0 : long nH = 240;
59 0 : SfxMapUnit eUnit = maSpacingControl.GetCoreMetric();
60 0 : if (mpHeightItem)
61 0 : nH = LogicToLogic( mpHeightItem->GetHeight(), (MapUnit)eUnit, MAP_TWIP );
62 0 : return nH;
63 : }
64 :
65 738 : TextPropertyPanel* TextPropertyPanel::Create (
66 : vcl::Window* pParent,
67 : const css::uno::Reference<css::frame::XFrame>& rxFrame,
68 : SfxBindings* pBindings,
69 : const ::sfx2::sidebar::EnumContext& rContext)
70 : {
71 738 : if (pParent == NULL)
72 0 : throw lang::IllegalArgumentException("no parent Window given to TextPropertyPanel::Create", NULL, 0);
73 738 : if ( ! rxFrame.is())
74 0 : throw lang::IllegalArgumentException("no XFrame given to TextPropertyPanel::Create", NULL, 1);
75 738 : if (pBindings == NULL)
76 0 : throw lang::IllegalArgumentException("no SfxBindings given to TextPropertyPanel::Create", NULL, 2);
77 :
78 : return new TextPropertyPanel(
79 : pParent,
80 : rxFrame,
81 : pBindings,
82 738 : rContext);
83 : }
84 :
85 :
86 738 : TextPropertyPanel::TextPropertyPanel ( vcl::Window* pParent, const css::uno::Reference<css::frame::XFrame>& rxFrame, SfxBindings* pBindings, const ::sfx2::sidebar::EnumContext& /*rContext*/ )
87 : : PanelLayout(pParent, "SidebarTextPanel", "svx/ui/sidebartextpanel.ui", rxFrame),
88 : maFontSizeControl (SID_ATTR_CHAR_FONTHEIGHT, *pBindings, *this, OUString("FontHeight"), rxFrame),
89 : maUnderlineControl (SID_ATTR_CHAR_UNDERLINE, *pBindings, *this, OUString("Underline"), rxFrame),
90 : maSpacingControl (SID_ATTR_CHAR_KERNING, *pBindings, *this, OUString("Spacing"), rxFrame),
91 :
92 : maCharSpacePopup(this, ::boost::bind(&TextPropertyPanel::CreateCharacterSpacingControl, this, _1)),
93 : maUnderlinePopup(this, ::boost::bind(&TextPropertyPanel::CreateUnderlinePopupControl, this, _1)),
94 : maContext(),
95 738 : mpBindings(pBindings)
96 : {
97 738 : get(mpToolBoxFont, "fonteffects");
98 738 : get(mpToolBoxIncDec, "fontadjust");
99 738 : get(mpToolBoxSpacing, "spacingbar");
100 738 : get(mpToolBoxFontColorSw, "colorbar");
101 738 : get(mpToolBoxFontColor, "colorsingle");
102 :
103 : //toolbox
104 738 : SetupToolboxItems();
105 738 : InitToolBoxFont();
106 738 : InitToolBoxSpacing();
107 :
108 : //init state
109 738 : mpHeightItem = NULL;
110 738 : meUnderline = UNDERLINE_NONE;
111 738 : meUnderlineColor = COL_AUTO;
112 738 : mbKernAvailable = true;
113 738 : mbKernLBAvailable = true;
114 738 : mlKerning = 0;
115 738 : }
116 :
117 1476 : TextPropertyPanel::~TextPropertyPanel (void)
118 : {
119 1476 : }
120 :
121 758 : void TextPropertyPanel::HandleContextChange (
122 : const ::sfx2::sidebar::EnumContext aContext)
123 : {
124 758 : if (maContext == aContext)
125 758 : return;
126 :
127 758 : maContext = aContext;
128 758 : mpToolBoxIncDec->Show(maContext.GetApplication_DI() != sfx2::sidebar::EnumContext::Application_Calc);
129 :
130 758 : bool bWriterText = false;
131 758 : switch (maContext.GetCombinedContext_DI())
132 : {
133 : case CombinedEnumContext(Application_Calc, Context_Cell):
134 : case CombinedEnumContext(Application_Calc, Context_Pivot):
135 0 : mpToolBoxSpacing->Disable();
136 0 : break;
137 :
138 : case CombinedEnumContext(Application_Calc, Context_EditCell):
139 : case CombinedEnumContext(Application_Calc, Context_DrawText):
140 : case CombinedEnumContext(Application_WriterVariants, Context_DrawText):
141 : case CombinedEnumContext(Application_WriterVariants, Context_Annotation):
142 : case CombinedEnumContext(Application_DrawImpress, Context_DrawText):
143 : case CombinedEnumContext(Application_DrawImpress, Context_Text):
144 : case CombinedEnumContext(Application_DrawImpress, Context_Table):
145 : case CombinedEnumContext(Application_DrawImpress, Context_OutlineText):
146 : case CombinedEnumContext(Application_DrawImpress, Context_Draw):
147 : case CombinedEnumContext(Application_DrawImpress, Context_TextObject):
148 : case CombinedEnumContext(Application_DrawImpress, Context_Graphic):
149 0 : mpToolBoxSpacing->Enable();
150 0 : break;
151 :
152 : case CombinedEnumContext(Application_WriterVariants, Context_Text):
153 : case CombinedEnumContext(Application_WriterVariants, Context_Table):
154 742 : mpToolBoxSpacing->Enable();
155 742 : bWriterText = true;
156 742 : break;
157 :
158 : default:
159 16 : break;
160 : }
161 :
162 758 : mpToolBoxFontColor->Show(!bWriterText);
163 758 : mpToolBoxFontColorSw->Show(bWriterText);
164 : }
165 :
166 0 : void TextPropertyPanel::DataChanged (const DataChangedEvent& /*rEvent*/)
167 : {
168 0 : SetupToolboxItems();
169 0 : }
170 :
171 0 : void TextPropertyPanel::EndSpacingPopupMode (void)
172 : {
173 0 : maCharSpacePopup.Hide();
174 0 : }
175 :
176 0 : void TextPropertyPanel::EndUnderlinePopupMode (void)
177 : {
178 0 : maUnderlinePopup.Hide();
179 0 : }
180 :
181 738 : void TextPropertyPanel::InitToolBoxFont()
182 : {
183 738 : Link aLink = LINK(this, TextPropertyPanel, UnderlineClickHdl);
184 738 : mpToolBoxFont->SetDropdownClickHdl(aLink);
185 738 : }
186 :
187 738 : void TextPropertyPanel::InitToolBoxSpacing()
188 : {
189 738 : const sal_uInt16 nId = mpToolBoxSpacing->GetItemId(UNO_SPACING);
190 738 : mpToolBoxSpacing->SetItemBits(nId, mpToolBoxSpacing->GetItemBits(nId) | ToolBoxItemBits::DROPDOWNONLY);
191 :
192 738 : Link aLink = LINK(this, TextPropertyPanel, SpacingClickHdl);
193 738 : mpToolBoxSpacing->SetDropdownClickHdl ( aLink );
194 738 : mpToolBoxSpacing->SetSelectHdl( aLink );
195 738 : }
196 :
197 738 : void TextPropertyPanel::SetupToolboxItems (void)
198 : {
199 738 : maUnderlineControl.SetupToolBoxItem(*mpToolBoxFont, mpToolBoxFont->GetItemId(UNO_UNDERLINE));
200 738 : maSpacingControl.SetupToolBoxItem(*mpToolBoxSpacing, mpToolBoxSpacing->GetItemId(UNO_SPACING));
201 738 : }
202 :
203 0 : IMPL_LINK(TextPropertyPanel, UnderlineClickHdl, ToolBox*, pToolBox)
204 : {
205 0 : const sal_uInt16 nId = pToolBox->GetCurItemId();
206 0 : const OUString aCommand(pToolBox->GetItemCommand(nId));
207 :
208 0 : if (aCommand == UNO_UNDERLINE)
209 : {
210 0 : pToolBox->SetItemDown( nId, true );
211 0 : maUnderlinePopup.Rearrange(meUnderline);
212 0 : maUnderlinePopup.Show(*pToolBox);
213 : }
214 :
215 0 : return 0L;
216 : }
217 :
218 0 : IMPL_LINK(TextPropertyPanel, SpacingClickHdl, ToolBox*, pToolBox)
219 : {
220 0 : const sal_uInt16 nId = pToolBox->GetCurItemId();
221 0 : const OUString aCommand(pToolBox->GetItemCommand(nId));
222 :
223 0 : if (aCommand == UNO_SPACING)
224 : {
225 0 : pToolBox->SetItemDown( nId, true );
226 0 : maCharSpacePopup.Rearrange(mbKernLBAvailable,mbKernAvailable,mlKerning);
227 0 : maCharSpacePopup.Show(*pToolBox);
228 : }
229 :
230 0 : return 0L;
231 : }
232 :
233 552 : void TextPropertyPanel::NotifyItemUpdate (
234 : const sal_uInt16 nSID,
235 : const SfxItemState eState,
236 : const SfxPoolItem* pState,
237 : const bool bIsEnabled)
238 : {
239 552 : switch(nSID)
240 : {
241 : case SID_ATTR_CHAR_FONTHEIGHT:
242 : {
243 184 : if ( eState >= SfxItemState::DEFAULT && pState->ISA(SvxFontHeightItem) )
244 184 : mpHeightItem = const_cast<SvxFontHeightItem*>(static_cast<const SvxFontHeightItem*>(pState));
245 : else
246 0 : mpHeightItem = NULL;
247 : }
248 184 : break;
249 : case SID_ATTR_CHAR_UNDERLINE:
250 : {
251 184 : if( eState >= SfxItemState::DEFAULT && pState->ISA(SvxUnderlineItem) )
252 : {
253 184 : const SvxUnderlineItem* pItem = static_cast<const SvxUnderlineItem*>(pState);
254 184 : meUnderline = (FontUnderline)pItem->GetValue();
255 184 : meUnderlineColor = pItem->GetColor();
256 : }
257 : else
258 0 : meUnderline = UNDERLINE_NONE;
259 : }
260 184 : break;
261 : case SID_ATTR_CHAR_KERNING:
262 : {
263 184 : if ( SfxItemState::DEFAULT == eState )
264 : {
265 184 : mbKernLBAvailable = true;
266 :
267 184 : if(pState->ISA(SvxKerningItem))
268 : {
269 184 : const SvxKerningItem* pKerningItem = static_cast<const SvxKerningItem*>(pState);
270 184 : mlKerning = (long)pKerningItem->GetValue();
271 184 : mbKernAvailable = true;
272 : }
273 : else
274 : {
275 0 : mlKerning = 0;
276 0 : mbKernAvailable =false;
277 : }
278 : }
279 0 : else if (SfxItemState::DISABLED == eState)
280 : {
281 0 : mbKernLBAvailable = false;
282 0 : mbKernAvailable = false;
283 0 : mlKerning = 0;
284 : }
285 : else
286 : {
287 0 : mbKernLBAvailable = true;
288 0 : mbKernAvailable = false;
289 0 : mlKerning = 0;
290 : }
291 184 : mpToolBoxSpacing->Enable(bIsEnabled);
292 : }
293 184 : break;
294 : }
295 552 : }
296 :
297 :
298 594 : } } // end of namespace svx::sidebar
299 :
300 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|