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 : VclPtr<PopupControl> TextPropertyPanel::CreateCharacterSpacingControl (PopupContainer* pParent)
47 : {
48 0 : return VclPtrInstance<TextCharacterSpacingControl>(pParent, *this, mpBindings);
49 : }
50 :
51 0 : VclPtr<PopupControl> TextPropertyPanel::CreateUnderlinePopupControl (PopupContainer* pParent)
52 : {
53 0 : return VclPtrInstance<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 515 : VclPtr<vcl::Window> 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 515 : if (pParent == NULL)
72 0 : throw lang::IllegalArgumentException("no parent Window given to TextPropertyPanel::Create", NULL, 0);
73 515 : if ( ! rxFrame.is())
74 0 : throw lang::IllegalArgumentException("no XFrame given to TextPropertyPanel::Create", NULL, 1);
75 515 : if (pBindings == NULL)
76 0 : throw lang::IllegalArgumentException("no SfxBindings given to TextPropertyPanel::Create", NULL, 2);
77 :
78 : return VclPtr<TextPropertyPanel>::Create(
79 : pParent,
80 : rxFrame,
81 : pBindings,
82 515 : rContext);
83 : }
84 :
85 :
86 515 : 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 541 : mpBindings(pBindings)
96 : {
97 489 : get(mpToolBoxFont, "fonteffects");
98 489 : get(mpToolBoxIncDec, "fontadjust");
99 489 : get(mpToolBoxSpacing, "spacingbar");
100 489 : get(mpToolBoxFontColorSw, "colorbar_writer");
101 489 : get(mpToolBoxFontColor, "colorbar_others");
102 489 : get(mpToolBoxBackgroundColor, "colorbar_background");
103 :
104 : //toolbox
105 489 : SetupToolboxItems();
106 489 : InitToolBoxFont();
107 489 : InitToolBoxSpacing();
108 :
109 : //init state
110 489 : mpHeightItem = NULL;
111 489 : meUnderline = UNDERLINE_NONE;
112 489 : meUnderlineColor = COL_AUTO;
113 489 : mbKernAvailable = true;
114 489 : mbKernLBAvailable = true;
115 489 : mlKerning = 0;
116 489 : }
117 :
118 0 : TextPropertyPanel::~TextPropertyPanel()
119 : {
120 0 : disposeOnce();
121 0 : }
122 :
123 489 : void TextPropertyPanel::dispose()
124 : {
125 489 : mpToolBoxFont.clear();
126 489 : mpToolBoxIncDec.clear();
127 489 : mpToolBoxSpacing.clear();
128 489 : mpToolBoxFontColorSw.clear();
129 489 : mpToolBoxFontColor.clear();
130 :
131 489 : maFontSizeControl.dispose();
132 489 : maUnderlineControl.dispose();
133 489 : maSpacingControl.dispose();
134 :
135 489 : PanelLayout::dispose();
136 489 : }
137 :
138 512 : void TextPropertyPanel::HandleContextChange (
139 : const ::sfx2::sidebar::EnumContext& rContext)
140 : {
141 512 : if (maContext == rContext)
142 512 : return;
143 :
144 512 : maContext = rContext;
145 512 : mpToolBoxIncDec->Show(maContext.GetApplication_DI() != sfx2::sidebar::EnumContext::Application_Calc);
146 :
147 512 : bool bWriterText = false;
148 512 : bool bDrawText = false;
149 512 : bool bNeedTextSpacing = false;
150 :
151 512 : switch (maContext.GetCombinedContext_DI())
152 : {
153 : case CombinedEnumContext(Application_Calc, Context_Cell):
154 : case CombinedEnumContext(Application_Calc, Context_Pivot):
155 : // bNeedTextSpacing = false;
156 151 : break;
157 :
158 : case CombinedEnumContext(Application_Calc, Context_EditCell):
159 : case CombinedEnumContext(Application_Calc, Context_DrawText):
160 :
161 : case CombinedEnumContext(Application_WriterVariants, Context_DrawText):
162 : case CombinedEnumContext(Application_WriterVariants, Context_Annotation):
163 : case CombinedEnumContext(Application_DrawImpress, Context_DrawText):
164 : case CombinedEnumContext(Application_DrawImpress, Context_Text):
165 : case CombinedEnumContext(Application_DrawImpress, Context_Table):
166 : case CombinedEnumContext(Application_DrawImpress, Context_OutlineText):
167 : case CombinedEnumContext(Application_DrawImpress, Context_Draw):
168 : case CombinedEnumContext(Application_DrawImpress, Context_TextObject):
169 : case CombinedEnumContext(Application_DrawImpress, Context_Graphic):
170 1 : bNeedTextSpacing = true;
171 1 : bDrawText = true;
172 1 : break;
173 :
174 : case CombinedEnumContext(Application_WriterVariants, Context_Text):
175 : case CombinedEnumContext(Application_WriterVariants, Context_Table):
176 339 : bNeedTextSpacing = true;
177 339 : bWriterText = true;
178 339 : break;
179 :
180 : default:
181 21 : break;
182 : }
183 :
184 512 : mpToolBoxSpacing->Enable(bNeedTextSpacing);
185 512 : mpToolBoxFontColor->Show(!bWriterText);
186 512 : mpToolBoxFontColorSw->Show(bWriterText);
187 512 : mpToolBoxBackgroundColor->Show(bDrawText);
188 : }
189 :
190 0 : void TextPropertyPanel::DataChanged (const DataChangedEvent& /*rEvent*/)
191 : {
192 0 : SetupToolboxItems();
193 0 : }
194 :
195 0 : void TextPropertyPanel::EndSpacingPopupMode()
196 : {
197 0 : maCharSpacePopup.Hide();
198 0 : }
199 :
200 0 : void TextPropertyPanel::EndUnderlinePopupMode()
201 : {
202 0 : maUnderlinePopup.Hide();
203 0 : }
204 :
205 489 : void TextPropertyPanel::InitToolBoxFont()
206 : {
207 489 : Link<ToolBox *, void> aLink = LINK(this, TextPropertyPanel, UnderlineClickHdl);
208 489 : mpToolBoxFont->SetDropdownClickHdl(aLink);
209 489 : }
210 :
211 489 : void TextPropertyPanel::InitToolBoxSpacing()
212 : {
213 489 : const sal_uInt16 nId = mpToolBoxSpacing->GetItemId(UNO_SPACING);
214 489 : mpToolBoxSpacing->SetItemBits(nId, mpToolBoxSpacing->GetItemBits(nId) | ToolBoxItemBits::DROPDOWNONLY);
215 :
216 489 : Link<ToolBox *, void> aLink = LINK(this, TextPropertyPanel, SpacingClickHdl);
217 489 : mpToolBoxSpacing->SetDropdownClickHdl ( aLink );
218 489 : mpToolBoxSpacing->SetSelectHdl( aLink );
219 489 : }
220 :
221 489 : void TextPropertyPanel::SetupToolboxItems()
222 : {
223 489 : maUnderlineControl.SetupToolBoxItem(*mpToolBoxFont, mpToolBoxFont->GetItemId(UNO_UNDERLINE));
224 489 : maSpacingControl.SetupToolBoxItem(*mpToolBoxSpacing, mpToolBoxSpacing->GetItemId(UNO_SPACING));
225 489 : }
226 :
227 0 : IMPL_LINK_TYPED(TextPropertyPanel, UnderlineClickHdl, ToolBox*, pToolBox, void)
228 : {
229 0 : const sal_uInt16 nId = pToolBox->GetCurItemId();
230 0 : const OUString aCommand(pToolBox->GetItemCommand(nId));
231 :
232 0 : if (aCommand == UNO_UNDERLINE)
233 : {
234 0 : pToolBox->SetItemDown( nId, true );
235 0 : maUnderlinePopup.Rearrange(meUnderline);
236 0 : maUnderlinePopup.Show(*pToolBox);
237 0 : }
238 0 : }
239 :
240 0 : IMPL_LINK_TYPED(TextPropertyPanel, SpacingClickHdl, ToolBox*, pToolBox, void)
241 : {
242 0 : const sal_uInt16 nId = pToolBox->GetCurItemId();
243 0 : const OUString aCommand(pToolBox->GetItemCommand(nId));
244 :
245 0 : if (aCommand == UNO_SPACING)
246 : {
247 0 : pToolBox->SetItemDown( nId, true );
248 0 : maCharSpacePopup.Rearrange(mbKernLBAvailable,mbKernAvailable,mlKerning);
249 0 : maCharSpacePopup.Show(*pToolBox);
250 0 : }
251 0 : }
252 :
253 1056 : void TextPropertyPanel::NotifyItemUpdate (
254 : const sal_uInt16 nSID,
255 : const SfxItemState eState,
256 : const SfxPoolItem* pState,
257 : const bool bIsEnabled)
258 : {
259 1056 : switch(nSID)
260 : {
261 : case SID_ATTR_CHAR_FONTHEIGHT:
262 : {
263 354 : if ( eState >= SfxItemState::DEFAULT && pState->ISA(SvxFontHeightItem) )
264 349 : mpHeightItem = const_cast<SvxFontHeightItem*>(static_cast<const SvxFontHeightItem*>(pState));
265 : else
266 5 : mpHeightItem = NULL;
267 : }
268 354 : break;
269 : case SID_ATTR_CHAR_UNDERLINE:
270 : {
271 351 : if( eState >= SfxItemState::DEFAULT && pState->ISA(SvxUnderlineItem) )
272 : {
273 346 : const SvxUnderlineItem* pItem = static_cast<const SvxUnderlineItem*>(pState);
274 346 : meUnderline = (FontUnderline)pItem->GetValue();
275 346 : meUnderlineColor = pItem->GetColor();
276 : }
277 : else
278 5 : meUnderline = UNDERLINE_NONE;
279 : }
280 351 : break;
281 : case SID_ATTR_CHAR_KERNING:
282 : {
283 351 : if ( SfxItemState::DEFAULT == eState )
284 : {
285 261 : mbKernLBAvailable = true;
286 :
287 261 : if(pState->ISA(SvxKerningItem))
288 : {
289 261 : const SvxKerningItem* pKerningItem = static_cast<const SvxKerningItem*>(pState);
290 261 : mlKerning = (long)pKerningItem->GetValue();
291 261 : mbKernAvailable = true;
292 : }
293 : else
294 : {
295 0 : mlKerning = 0;
296 0 : mbKernAvailable =false;
297 : }
298 : }
299 90 : else if (SfxItemState::DISABLED == eState)
300 : {
301 90 : mbKernLBAvailable = false;
302 90 : mbKernAvailable = false;
303 90 : mlKerning = 0;
304 : }
305 : else
306 : {
307 0 : mbKernLBAvailable = true;
308 0 : mbKernAvailable = false;
309 0 : mlKerning = 0;
310 : }
311 351 : mpToolBoxSpacing->Enable(bIsEnabled);
312 : }
313 351 : break;
314 : }
315 1056 : }
316 :
317 :
318 390 : } } // end of namespace svx::sidebar
319 :
320 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|