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