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 <sfx2/sfxsids.hrc>
21 : #include "fontdialog.hxx"
22 : #include "formresid.hrc"
23 : #include "modulepcr.hxx"
24 : #include "formlocalid.hrc"
25 : #include <vcl/svapp.hxx>
26 : #include <toolkit/helper/vclunohelper.hxx>
27 : #include <comphelper/types.hxx>
28 : #include <comphelper/extract.hxx>
29 : #include <com/sun/star/awt/FontDescriptor.hpp>
30 : #include <com/sun/star/awt/FontWeight.hpp>
31 : #include <com/sun/star/awt/FontSlant.hpp>
32 : #include <com/sun/star/awt/FontUnderline.hpp>
33 : #include <com/sun/star/awt/FontStrikeout.hpp>
34 : #include "formstrings.hxx"
35 : #include "fontitemids.hxx"
36 : #include <editeng/charreliefitem.hxx>
37 : #include <editeng/emphasismarkitem.hxx>
38 : #include <editeng/fontitem.hxx>
39 : #include <editeng/fhgtitem.hxx>
40 : #include <editeng/postitem.hxx>
41 : #include <editeng/wghtitem.hxx>
42 : #include <editeng/udlnitem.hxx>
43 : #include <editeng/crossedoutitem.hxx>
44 : #include <editeng/colritem.hxx>
45 : #include <editeng/langitem.hxx>
46 : #include <editeng/wrlmitem.hxx>
47 : #include <editeng/cmapitem.hxx>
48 : #include <editeng/contouritem.hxx>
49 : #include <editeng/shdditem.hxx>
50 : #include <editeng/flstitem.hxx>
51 : #include <svtools/ctrltool.hxx>
52 : #include <tools/diagnose_ex.h>
53 : #include <com/sun/star/beans/XPropertyState.hpp>
54 : #include <svx/svxids.hrc>
55 : #include <svx/svxdlg.hxx>
56 : #include <svx/dialogs.hrc>
57 : #include <svx/flagsdef.hxx>
58 : #include <vcl/settings.hxx>
59 :
60 :
61 : namespace pcr
62 : {
63 :
64 :
65 : using namespace ::com::sun::star::uno;
66 : using namespace ::com::sun::star::beans;
67 :
68 :
69 : //= OFontPropertyExtractor
70 :
71 0 : class OFontPropertyExtractor
72 : {
73 : protected:
74 : ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >
75 : m_xPropValueAccess;
76 : ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertyState >
77 : m_xPropStateAccess;
78 :
79 : public:
80 : OFontPropertyExtractor( const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >&
81 : _rxProps );
82 :
83 : public:
84 : bool getCheckFontProperty(const OUString& _rPropName, ::com::sun::star::uno::Any& _rValue);
85 : OUString getStringFontProperty(const OUString& _rPropName, const OUString& _rDefault);
86 : sal_Int16 getInt16FontProperty(const OUString& _rPropName, const sal_Int16 _nDefault);
87 : sal_Int32 getInt32FontProperty(const OUString& _rPropName, const sal_Int32 _nDefault);
88 : float getFloatFontProperty(const OUString& _rPropName, const float _nDefault);
89 :
90 : void invalidateItem(
91 : const OUString& _rPropName,
92 : sal_uInt16 _nItemId,
93 : SfxItemSet& _rSet,
94 : bool _bForceInvalidation = false);
95 : };
96 :
97 :
98 0 : OFontPropertyExtractor::OFontPropertyExtractor(const Reference< XPropertySet >& _rxProps)
99 : :m_xPropValueAccess(_rxProps)
100 0 : ,m_xPropStateAccess(_rxProps, UNO_QUERY)
101 : {
102 : OSL_ENSURE(m_xPropValueAccess.is(), "OFontPropertyExtractor::OFontPropertyExtractor: invalid property set!");
103 0 : }
104 :
105 :
106 0 : bool OFontPropertyExtractor::getCheckFontProperty(const OUString& _rPropName, Any& _rValue)
107 : {
108 0 : _rValue = m_xPropValueAccess->getPropertyValue(_rPropName);
109 0 : if (m_xPropStateAccess.is())
110 0 : return PropertyState_DEFAULT_VALUE == m_xPropStateAccess->getPropertyState(_rPropName);
111 :
112 0 : return false;
113 : }
114 :
115 :
116 0 : OUString OFontPropertyExtractor::getStringFontProperty(const OUString& _rPropName, const OUString& _rDefault)
117 : {
118 0 : Any aValue;
119 0 : if (getCheckFontProperty(_rPropName, aValue))
120 0 : return _rDefault;
121 :
122 0 : return ::comphelper::getString(aValue);
123 : }
124 :
125 :
126 0 : sal_Int16 OFontPropertyExtractor::getInt16FontProperty(const OUString& _rPropName, const sal_Int16 _nDefault)
127 : {
128 0 : Any aValue;
129 0 : if (getCheckFontProperty(_rPropName, aValue))
130 0 : return _nDefault;
131 :
132 0 : sal_Int32 nValue(_nDefault);
133 0 : ::cppu::enum2int(nValue, aValue);
134 0 : return (sal_Int16)nValue;
135 : }
136 :
137 :
138 0 : sal_Int32 OFontPropertyExtractor::getInt32FontProperty(const OUString& _rPropName, const sal_Int32 _nDefault)
139 : {
140 0 : Any aValue;
141 0 : if (getCheckFontProperty(_rPropName, aValue))
142 0 : return _nDefault;
143 :
144 0 : sal_Int32 nValue(_nDefault);
145 0 : ::cppu::enum2int(nValue, aValue);
146 0 : return nValue;
147 : }
148 :
149 :
150 0 : float OFontPropertyExtractor::getFloatFontProperty(const OUString& _rPropName, const float _nDefault)
151 : {
152 0 : Any aValue;
153 0 : if (getCheckFontProperty(_rPropName, aValue))
154 0 : return _nDefault;
155 :
156 0 : return ::comphelper::getFloat(aValue);
157 : }
158 :
159 :
160 0 : void OFontPropertyExtractor::invalidateItem(const OUString& _rPropName, sal_uInt16 _nItemId, SfxItemSet& _rSet, bool _bForceInvalidation)
161 : {
162 0 : if ( _bForceInvalidation
163 0 : || ( m_xPropStateAccess.is()
164 0 : && (PropertyState_AMBIGUOUS_VALUE == m_xPropStateAccess->getPropertyState(_rPropName))
165 : )
166 : )
167 0 : _rSet.InvalidateItem(_nItemId);
168 0 : }
169 :
170 :
171 : //= ControlCharacterDialog
172 :
173 :
174 0 : ControlCharacterDialog::ControlCharacterDialog(vcl::Window* _pParent, const SfxItemSet& _rCoreSet)
175 : : SfxTabDialog(_pParent, "ControlFontDialog",
176 : "modules/spropctrlr/ui/controlfontdialog.ui", &_rCoreSet)
177 0 : , m_nCharsId(0)
178 : {
179 0 : SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
180 : assert(pFact); //CreateFactory fail!
181 0 : m_nCharsId = AddTabPage("font", pFact->GetTabPageCreatorFunc(RID_SVXPAGE_CHAR_NAME), 0 );
182 0 : AddTabPage("fonteffects", pFact->GetTabPageCreatorFunc(RID_SVXPAGE_CHAR_EFFECTS), 0 );
183 0 : }
184 :
185 :
186 0 : ControlCharacterDialog::~ControlCharacterDialog()
187 : {
188 0 : }
189 :
190 :
191 0 : void ControlCharacterDialog::translatePropertiesToItems(const Reference< XPropertySet >& _rxModel, SfxItemSet* _pSet)
192 : {
193 : OSL_ENSURE(_pSet && _rxModel.is(), "ControlCharacterDialog::translatePropertiesToItems: invalid arguments!");
194 0 : if (!_pSet || !_rxModel.is())
195 0 : return;
196 :
197 : try
198 : {
199 0 : OFontPropertyExtractor aPropExtractor(_rxModel);
200 :
201 : // some items, which may be in default state, have to be filled with non-void information
202 0 : vcl::Font aDefaultVCLFont = Application::GetDefaultDevice()->GetSettings().GetStyleSettings().GetAppFont();
203 0 : ::com::sun::star::awt::FontDescriptor aDefaultFont = VCLUnoHelper::CreateFontDescriptor(aDefaultVCLFont);
204 :
205 : // get the current properties
206 0 : OUString aFontName = aPropExtractor.getStringFontProperty(PROPERTY_FONT_NAME, aDefaultFont.Name);
207 0 : OUString aFontStyleName = aPropExtractor.getStringFontProperty(PROPERTY_FONT_STYLENAME, aDefaultFont.StyleName);
208 0 : sal_Int16 nFontFamily = aPropExtractor.getInt16FontProperty(PROPERTY_FONT_FAMILY, aDefaultFont.Family);
209 0 : sal_Int16 nFontCharset = aPropExtractor.getInt16FontProperty(PROPERTY_FONT_CHARSET, aDefaultFont.CharSet);
210 0 : float nFontHeight = aPropExtractor.getFloatFontProperty(PROPERTY_FONT_HEIGHT, (float)aDefaultFont.Height);
211 0 : float nFontWeight = aPropExtractor.getFloatFontProperty(PROPERTY_FONT_WEIGHT, aDefaultFont.Weight);
212 0 : css::awt::FontSlant nFontSlant = static_cast<css::awt::FontSlant>(aPropExtractor.getInt16FontProperty(PROPERTY_FONT_SLANT, (sal_Int16)aDefaultFont.Slant));
213 0 : sal_Int16 nFontUnderline = aPropExtractor.getInt16FontProperty(PROPERTY_FONT_UNDERLINE, aDefaultFont.Underline);
214 0 : sal_Int16 nFontStrikeout = aPropExtractor.getInt16FontProperty(PROPERTY_FONT_STRIKEOUT, aDefaultFont.Strikeout);
215 :
216 0 : sal_Int32 nTextLineColor = aPropExtractor.getInt32FontProperty(PROPERTY_TEXTLINECOLOR, COL_AUTO);
217 0 : sal_Int16 nFontRelief = aPropExtractor.getInt16FontProperty(PROPERTY_FONT_RELIEF, (sal_Int16)aDefaultVCLFont.GetRelief());
218 0 : sal_Int16 nFontEmphasisMark = aPropExtractor.getInt16FontProperty(PROPERTY_FONT_EMPHASIS_MARK, aDefaultVCLFont.GetEmphasisMark());
219 :
220 0 : Any aValue;
221 0 : bool bWordLineMode = aPropExtractor.getCheckFontProperty(PROPERTY_WORDLINEMODE, aValue) ? aDefaultFont.WordLineMode : ::cppu::any2bool(aValue);
222 0 : sal_Int32 nColor32 = aPropExtractor.getInt32FontProperty(PROPERTY_TEXTCOLOR, 0);
223 :
224 : // build SfxItems with the values
225 0 : SvxFontItem aFontItem((FontFamily)nFontFamily, aFontName, aFontStyleName, PITCH_DONTKNOW, nFontCharset, CFID_FONT);
226 :
227 0 : nFontHeight = (float)OutputDevice::LogicToLogic(Size(0, (sal_Int32)nFontHeight), MAP_POINT, MAP_TWIP).Height();
228 0 : SvxFontHeightItem aSvxFontHeightItem((sal_uInt32)nFontHeight,100,CFID_HEIGHT);
229 :
230 0 : FontWeight eWeight=VCLUnoHelper::ConvertFontWeight(nFontWeight);
231 0 : FontItalic eItalic=VCLUnoHelper::ConvertFontSlant(nFontSlant);
232 0 : FontUnderline eUnderline=(FontUnderline)nFontUnderline;
233 0 : FontStrikeout eStrikeout=(FontStrikeout)nFontStrikeout;
234 :
235 0 : SvxWeightItem aWeightItem(eWeight,CFID_WEIGHT);
236 0 : SvxPostureItem aPostureItem(eItalic,CFID_POSTURE);
237 :
238 0 : SvxCrossedOutItem aCrossedOutItem(eStrikeout,CFID_STRIKEOUT);
239 0 : SvxWordLineModeItem aWordLineModeItem(bWordLineMode, CFID_WORDLINEMODE);
240 :
241 0 : SvxUnderlineItem aUnderlineItem(eUnderline,CFID_UNDERLINE);
242 0 : aUnderlineItem.SetColor(Color(nTextLineColor));
243 :
244 0 : SvxColorItem aSvxColorItem(nColor32,CFID_CHARCOLOR);
245 0 : SvxLanguageItem aLanguageItem(Application::GetSettings().GetUILanguageTag().getLanguageType(), CFID_LANGUAGE);
246 :
247 : // the 2 CJK props
248 0 : SvxCharReliefItem aFontReliefItem((FontRelief)nFontRelief, CFID_RELIEF);
249 0 : SvxEmphasisMarkItem aEmphasisMarkitem((FontEmphasisMark)nFontEmphasisMark, CFID_EMPHASIS);
250 :
251 0 : _pSet->Put(aFontItem, CFID_FONT);
252 0 : _pSet->Put(aSvxFontHeightItem,CFID_HEIGHT);
253 0 : _pSet->Put(aWeightItem, CFID_WEIGHT);
254 0 : _pSet->Put(aPostureItem, CFID_POSTURE);
255 0 : _pSet->Put(aLanguageItem, CFID_LANGUAGE);
256 0 : _pSet->Put(aUnderlineItem,CFID_UNDERLINE);
257 0 : _pSet->Put(aCrossedOutItem,CFID_STRIKEOUT);
258 0 : _pSet->Put(aWordLineModeItem, CFID_WORDLINEMODE);
259 0 : _pSet->Put(aSvxColorItem, CFID_CHARCOLOR);
260 0 : _pSet->Put(aFontReliefItem, CFID_RELIEF);
261 0 : _pSet->Put(aEmphasisMarkitem, CFID_EMPHASIS);
262 :
263 0 : aPropExtractor.invalidateItem(PROPERTY_FONT_NAME, CFID_FONT, *_pSet);
264 0 : aPropExtractor.invalidateItem(PROPERTY_FONT_HEIGHT, CFID_HEIGHT, *_pSet);
265 0 : aPropExtractor.invalidateItem(PROPERTY_FONT_WEIGHT, CFID_WEIGHT, *_pSet, ::com::sun::star::awt::FontWeight::DONTKNOW == nFontWeight);
266 0 : aPropExtractor.invalidateItem(PROPERTY_FONT_SLANT, CFID_POSTURE, *_pSet, ::com::sun::star::awt::FontSlant_DONTKNOW == nFontSlant);
267 0 : aPropExtractor.invalidateItem(PROPERTY_FONT_UNDERLINE, CFID_UNDERLINE, *_pSet, ::com::sun::star::awt::FontUnderline::DONTKNOW == nFontUnderline);
268 0 : aPropExtractor.invalidateItem(PROPERTY_FONT_STRIKEOUT, CFID_STRIKEOUT, *_pSet, ::com::sun::star::awt::FontStrikeout::DONTKNOW == nFontStrikeout);
269 0 : aPropExtractor.invalidateItem(PROPERTY_WORDLINEMODE, CFID_WORDLINEMODE, *_pSet);
270 0 : aPropExtractor.invalidateItem(PROPERTY_TEXTCOLOR, CFID_CHARCOLOR, *_pSet);
271 0 : aPropExtractor.invalidateItem(PROPERTY_FONT_RELIEF, CFID_RELIEF, *_pSet);
272 0 : aPropExtractor.invalidateItem(PROPERTY_FONT_EMPHASIS_MARK, CFID_EMPHASIS, *_pSet);
273 : }
274 0 : catch (const Exception&)
275 : {
276 : OSL_FAIL("ControlCharacterDialog::translatePropertiesToItems: caught an exception!");
277 : }
278 :
279 0 : _pSet->DisableItem(SID_ATTR_CHAR_CJK_FONT);
280 0 : _pSet->DisableItem(SID_ATTR_CHAR_CJK_FONTHEIGHT);
281 0 : _pSet->DisableItem(SID_ATTR_CHAR_CJK_LANGUAGE);
282 0 : _pSet->DisableItem(SID_ATTR_CHAR_CJK_POSTURE);
283 0 : _pSet->DisableItem(SID_ATTR_CHAR_CJK_WEIGHT);
284 :
285 0 : _pSet->DisableItem(SID_ATTR_CHAR_CASEMAP);
286 0 : _pSet->DisableItem(SID_ATTR_CHAR_CONTOUR);
287 0 : _pSet->DisableItem(SID_ATTR_CHAR_SHADOWED);
288 :
289 : }
290 :
291 :
292 : namespace
293 : {
294 0 : void lcl_pushBackPropertyValue( Sequence< NamedValue >& _out_properties, const OUString& _name, const Any& _value )
295 : {
296 0 : _out_properties.realloc( _out_properties.getLength() + 1 );
297 0 : _out_properties[ _out_properties.getLength() - 1 ] = NamedValue( _name, _value );
298 0 : }
299 : }
300 :
301 :
302 0 : void ControlCharacterDialog::translateItemsToProperties( const SfxItemSet& _rSet, Sequence< NamedValue >& _out_properties )
303 : {
304 0 : _out_properties.realloc( 0 );
305 :
306 : try
307 : {
308 :
309 : // font name
310 0 : SfxItemState eState = _rSet.GetItemState(CFID_FONT);
311 :
312 0 : if ( eState == SfxItemState::SET )
313 : {
314 : const SvxFontItem& rFontItem =
315 0 : static_cast<const SvxFontItem&>(_rSet.Get(CFID_FONT));
316 :
317 0 : lcl_pushBackPropertyValue( _out_properties, PROPERTY_FONT_NAME , makeAny(OUString(rFontItem.GetFamilyName())));
318 0 : lcl_pushBackPropertyValue( _out_properties, PROPERTY_FONT_STYLENAME, makeAny(OUString(rFontItem.GetStyleName())));
319 0 : lcl_pushBackPropertyValue( _out_properties, PROPERTY_FONT_FAMILY , makeAny((sal_Int16)rFontItem.GetFamily()));
320 0 : lcl_pushBackPropertyValue( _out_properties, PROPERTY_FONT_CHARSET , makeAny((sal_Int16)rFontItem.GetCharSet()));
321 : }
322 :
323 :
324 : // font height
325 0 : eState = _rSet.GetItemState(CFID_HEIGHT);
326 :
327 0 : if ( eState == SfxItemState::SET )
328 : {
329 : const SvxFontHeightItem& rSvxFontHeightItem =
330 0 : static_cast<const SvxFontHeightItem&>(_rSet.Get(CFID_HEIGHT));
331 :
332 0 : float nHeight = (float)OutputDevice::LogicToLogic(Size(0, rSvxFontHeightItem.GetHeight()), MAP_TWIP, MAP_POINT).Height();
333 0 : lcl_pushBackPropertyValue( _out_properties, PROPERTY_FONT_HEIGHT,makeAny(nHeight));
334 :
335 : }
336 :
337 :
338 : // font weight
339 0 : eState = _rSet.GetItemState(CFID_WEIGHT);
340 :
341 0 : if ( eState == SfxItemState::SET )
342 : {
343 : const SvxWeightItem& rWeightItem =
344 0 : static_cast<const SvxWeightItem&>(_rSet.Get(CFID_WEIGHT));
345 :
346 0 : float nWeight = VCLUnoHelper::ConvertFontWeight(rWeightItem.GetWeight());
347 0 : lcl_pushBackPropertyValue( _out_properties, PROPERTY_FONT_WEIGHT,makeAny(nWeight));
348 : }
349 :
350 :
351 : // font slant
352 0 : eState = _rSet.GetItemState(CFID_POSTURE);
353 :
354 0 : if ( eState == SfxItemState::SET )
355 : {
356 : const SvxPostureItem& rPostureItem =
357 0 : static_cast<const SvxPostureItem&>(_rSet.Get(CFID_POSTURE));
358 :
359 0 : ::com::sun::star::awt::FontSlant eSlant = VCLUnoHelper::ConvertFontSlant(rPostureItem.GetPosture());
360 0 : lcl_pushBackPropertyValue( _out_properties, PROPERTY_FONT_SLANT, makeAny((sal_Int16)eSlant));
361 : }
362 :
363 :
364 : // font underline
365 0 : eState = _rSet.GetItemState(CFID_UNDERLINE);
366 :
367 0 : if ( eState == SfxItemState::SET )
368 : {
369 : const SvxUnderlineItem& rUnderlineItem =
370 0 : static_cast<const SvxUnderlineItem&>(_rSet.Get(CFID_UNDERLINE));
371 :
372 0 : sal_Int16 nUnderline = (sal_Int16)rUnderlineItem.GetLineStyle();
373 0 : lcl_pushBackPropertyValue( _out_properties, PROPERTY_FONT_UNDERLINE,makeAny(nUnderline));
374 :
375 : // the text line color is transported in this item, too
376 0 : sal_Int32 nColor = rUnderlineItem.GetColor().GetColor();
377 :
378 0 : Any aUnoColor;
379 0 : if (COL_AUTO != (sal_uInt32)nColor)
380 0 : aUnoColor <<= nColor;
381 :
382 0 : lcl_pushBackPropertyValue( _out_properties, PROPERTY_TEXTLINECOLOR, aUnoColor );
383 : }
384 :
385 :
386 : // font strikeout
387 0 : eState = _rSet.GetItemState(CFID_STRIKEOUT);
388 :
389 0 : if ( eState == SfxItemState::SET )
390 : {
391 : const SvxCrossedOutItem& rCrossedOutItem =
392 0 : static_cast<const SvxCrossedOutItem&>(_rSet.Get(CFID_STRIKEOUT));
393 :
394 0 : sal_Int16 nStrikeout = (sal_Int16)rCrossedOutItem.GetStrikeout();
395 0 : lcl_pushBackPropertyValue( _out_properties, PROPERTY_FONT_STRIKEOUT,makeAny(nStrikeout));
396 : }
397 :
398 :
399 :
400 : // font wordline mode
401 0 : eState = _rSet.GetItemState(CFID_WORDLINEMODE);
402 :
403 0 : if ( eState == SfxItemState::SET )
404 : {
405 : const SvxWordLineModeItem& rWordLineModeItem =
406 0 : static_cast<const SvxWordLineModeItem&>(_rSet.Get(CFID_WORDLINEMODE));
407 :
408 0 : lcl_pushBackPropertyValue( _out_properties, PROPERTY_WORDLINEMODE, css::uno::makeAny(rWordLineModeItem.GetValue()));
409 : }
410 :
411 :
412 :
413 : // text color
414 0 : eState = _rSet.GetItemState(CFID_CHARCOLOR);
415 :
416 0 : if ( eState == SfxItemState::SET )
417 : {
418 : const SvxColorItem& rColorItem =
419 0 : static_cast<const SvxColorItem&>(_rSet.Get(CFID_CHARCOLOR));
420 :
421 0 : sal_Int32 nColor = rColorItem.GetValue().GetColor();
422 :
423 0 : Any aUnoColor;
424 0 : if (COL_AUTO != (sal_uInt32)nColor)
425 0 : aUnoColor <<= nColor;
426 :
427 0 : lcl_pushBackPropertyValue( _out_properties, PROPERTY_TEXTCOLOR, aUnoColor );
428 : }
429 :
430 :
431 : // font relief
432 0 : eState = _rSet.GetItemState(CFID_RELIEF);
433 :
434 0 : if ( eState == SfxItemState::SET )
435 : {
436 : const SvxCharReliefItem& rReliefItem =
437 0 : static_cast<const SvxCharReliefItem&>(_rSet.Get(CFID_RELIEF));
438 :
439 0 : lcl_pushBackPropertyValue( _out_properties, PROPERTY_FONT_RELIEF, makeAny((sal_Int16)rReliefItem.GetValue()) );
440 : }
441 :
442 :
443 : // font emphasis mark
444 0 : eState = _rSet.GetItemState(CFID_EMPHASIS);
445 :
446 0 : if ( eState == SfxItemState::SET )
447 : {
448 : const SvxEmphasisMarkItem& rEmphMarkItem =
449 0 : static_cast<const SvxEmphasisMarkItem&>(_rSet.Get(CFID_EMPHASIS));
450 :
451 0 : lcl_pushBackPropertyValue( _out_properties, PROPERTY_FONT_EMPHASIS_MARK, makeAny((sal_Int16)rEmphMarkItem.GetEmphasisMark()) );
452 : }
453 : }
454 0 : catch (const Exception& )
455 : {
456 : DBG_UNHANDLED_EXCEPTION();
457 : }
458 0 : }
459 :
460 :
461 0 : void ControlCharacterDialog::translateItemsToProperties( const SfxItemSet& _rSet, const Reference< XPropertySet >& _rxModel)
462 : {
463 : OSL_ENSURE( _rxModel.is(), "ControlCharacterDialog::translateItemsToProperties: invalid arguments!" );
464 0 : if ( !_rxModel.is())
465 0 : return;
466 :
467 0 : Sequence< NamedValue > aPropertyValues;
468 0 : translateItemsToProperties( _rSet, aPropertyValues );
469 : try
470 : {
471 0 : const NamedValue* propertyValue = aPropertyValues.getConstArray();
472 0 : const NamedValue* propertyValueEnd = propertyValue + aPropertyValues.getLength();
473 0 : for ( ; propertyValue != propertyValueEnd; ++propertyValue )
474 0 : _rxModel->setPropertyValue( propertyValue->Name, propertyValue->Value );
475 : }
476 0 : catch( const Exception& )
477 : {
478 : DBG_UNHANDLED_EXCEPTION();
479 0 : }
480 : }
481 :
482 :
483 0 : SfxItemSet* ControlCharacterDialog::createItemSet(SfxItemSet*& _rpSet, SfxItemPool*& _rpPool, SfxPoolItem**& _rppDefaults)
484 : {
485 : // just to be sure ....
486 0 : _rpSet = NULL;
487 0 : _rpPool = NULL;
488 0 : _rppDefaults = NULL;
489 :
490 : // create and initialize the defaults
491 0 : _rppDefaults = new SfxPoolItem*[CFID_LAST_ITEM_ID - CFID_FIRST_ITEM_ID + 1];
492 :
493 0 : vcl::Font aDefaultVCLFont = Application::GetDefaultDevice()->GetSettings().GetStyleSettings().GetAppFont();
494 :
495 0 : SfxPoolItem** pCounter = _rppDefaults; // want to modify this without affecting the out param _rppDefaults
496 0 : *pCounter++ = new SvxFontItem(aDefaultVCLFont.GetFamily(), aDefaultVCLFont.GetName(), aDefaultVCLFont.GetStyleName(), aDefaultVCLFont.GetPitch(), aDefaultVCLFont.GetCharSet(), CFID_FONT);
497 0 : *pCounter++ = new SvxFontHeightItem(aDefaultVCLFont.GetHeight(), 100, CFID_HEIGHT);
498 0 : *pCounter++ = new SvxWeightItem(aDefaultVCLFont.GetWeight(), CFID_WEIGHT);
499 0 : *pCounter++ = new SvxPostureItem(aDefaultVCLFont.GetItalic(), CFID_POSTURE);
500 0 : *pCounter++ = new SvxLanguageItem(Application::GetSettings().GetUILanguageTag().getLanguageType(), CFID_LANGUAGE);
501 0 : *pCounter++ = new SvxUnderlineItem(aDefaultVCLFont.GetUnderline(), CFID_UNDERLINE);
502 0 : *pCounter++ = new SvxCrossedOutItem(aDefaultVCLFont.GetStrikeout(), CFID_STRIKEOUT);
503 0 : *pCounter++ = new SvxWordLineModeItem(aDefaultVCLFont.IsWordLineMode(), CFID_WORDLINEMODE);
504 0 : *pCounter++ = new SvxColorItem(aDefaultVCLFont.GetColor(), CFID_CHARCOLOR);
505 0 : *pCounter++ = new SvxCharReliefItem(aDefaultVCLFont.GetRelief(), CFID_RELIEF);
506 0 : *pCounter++ = new SvxEmphasisMarkItem(aDefaultVCLFont.GetEmphasisMark(), CFID_EMPHASIS);
507 :
508 0 : *pCounter++ = new SvxFontItem(aDefaultVCLFont.GetFamily(), aDefaultVCLFont.GetName(), aDefaultVCLFont.GetStyleName(), aDefaultVCLFont.GetPitch(), aDefaultVCLFont.GetCharSet(), CFID_CJK_FONT);
509 0 : *pCounter++ = new SvxFontHeightItem(aDefaultVCLFont.GetHeight(), 100, CFID_CJK_HEIGHT);
510 0 : *pCounter++ = new SvxWeightItem(aDefaultVCLFont.GetWeight(), CFID_CJK_WEIGHT);
511 0 : *pCounter++ = new SvxPostureItem(aDefaultVCLFont.GetItalic(), CFID_CJK_POSTURE);
512 0 : *pCounter++ = new SvxLanguageItem(Application::GetSettings().GetUILanguageTag().getLanguageType(), CFID_CJK_LANGUAGE);
513 :
514 0 : *pCounter++ = new SvxCaseMapItem(SVX_CASEMAP_NOT_MAPPED, CFID_CASEMAP);
515 0 : *pCounter++ = new SvxContourItem(false, CFID_CONTOUR);
516 0 : *pCounter++ = new SvxShadowedItem(false, CFID_SHADOWED);
517 :
518 0 : *pCounter++ = new SvxFontListItem (new FontList(Application::GetDefaultDevice()), CFID_FONTLIST);
519 :
520 : // create the pool
521 : static SfxItemInfo const aItemInfos[CFID_LAST_ITEM_ID - CFID_FIRST_ITEM_ID + 1] =
522 : {
523 : { SID_ATTR_CHAR_FONT, 0 },
524 : { SID_ATTR_CHAR_FONTHEIGHT, 0 },
525 : { SID_ATTR_CHAR_WEIGHT, 0 },
526 : { SID_ATTR_CHAR_POSTURE, 0 },
527 : { SID_ATTR_CHAR_LANGUAGE, 0 },
528 : { SID_ATTR_CHAR_UNDERLINE, 0 },
529 : { SID_ATTR_CHAR_STRIKEOUT, 0 },
530 : { SID_ATTR_CHAR_WORDLINEMODE, 0 },
531 : { SID_ATTR_CHAR_COLOR, 0 },
532 : { SID_ATTR_CHAR_RELIEF, 0 },
533 : { SID_ATTR_CHAR_EMPHASISMARK, 0 },
534 : { 0, 0 },
535 : { 0, 0 },
536 : { 0, 0 },
537 : { 0, 0 },
538 : { 0, 0 },
539 : { 0, 0 },
540 : { 0, 0 },
541 : { 0, 0 },
542 : { SID_ATTR_CHAR_FONTLIST, 0 }
543 : };
544 :
545 : _rpPool = new SfxItemPool(OUString("PCRControlFontItemPool"), CFID_FIRST_ITEM_ID, CFID_LAST_ITEM_ID,
546 0 : aItemInfos, _rppDefaults);
547 0 : _rpPool->FreezeIdRanges();
548 :
549 : // and, finally, the set
550 0 : _rpSet = new SfxItemSet(*_rpPool, true);
551 :
552 0 : return _rpSet;
553 : }
554 :
555 :
556 0 : void ControlCharacterDialog::destroyItemSet(SfxItemSet*& _rpSet, SfxItemPool*& _rpPool, SfxPoolItem**& _rppDefaults)
557 : {
558 : // from the pool, get and remember the font list (needs to be deleted)
559 0 : const SvxFontListItem& rFontListItem = static_cast<const SvxFontListItem&>(_rpPool->GetDefaultItem(CFID_FONTLIST));
560 0 : const FontList* pFontList = rFontListItem.GetFontList();
561 :
562 : // _first_ delete the set (referring the pool)
563 0 : if (_rpSet)
564 : {
565 0 : delete _rpSet;
566 0 : _rpSet = NULL;
567 : }
568 :
569 : // delete the pool
570 0 : _rpPool->ReleaseDefaults(true);
571 : // the "true" means delete the items, too
572 0 : SfxItemPool::Free(_rpPool);
573 0 : _rpPool = NULL;
574 :
575 : // reset the defaults ptr
576 0 : _rppDefaults = NULL;
577 : // no need to explicitly delete the defaults, this has been done by the ReleaseDefaults
578 :
579 0 : delete pFontList;
580 0 : }
581 :
582 :
583 0 : void ControlCharacterDialog::PageCreated( sal_uInt16 _nId, SfxTabPage& _rPage )
584 : {
585 0 : SfxAllItemSet aSet(*(GetInputSetImpl()->GetPool()));
586 0 : if ( _nId == m_nCharsId ) {
587 0 : aSet.Put (SvxFontListItem(static_cast<const SvxFontListItem&>(GetInputSetImpl()->Get(CFID_FONTLIST))));
588 0 : aSet.Put (SfxUInt16Item(SID_DISABLE_CTL,DISABLE_HIDE_LANGUAGE));
589 0 : _rPage.PageCreated(aSet);
590 0 : }
591 0 : }
592 :
593 :
594 12 : } // namespace pcr
595 :
596 :
597 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|