1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 24 // MARKER(update_precomp.py): autogen include statement, do not remove 25 #include "precompiled_forms.hxx" 26 #include "formcontrolfont.hxx" 27 #ifndef _FRM_PROPERTY_HRC_ 28 #include "property.hrc" 29 #endif 30 #include "property.hxx" 31 #include <tools/debug.hxx> 32 #include <comphelper/property.hxx> 33 #include <comphelper/types.hxx> 34 #include <tools/color.hxx> 35 #include <toolkit/helper/emptyfontdescriptor.hxx> 36 #include <com/sun/star/awt/FontRelief.hpp> 37 #include <com/sun/star/awt/FontEmphasisMark.hpp> 38 39 //......................................................................... 40 namespace frm 41 { 42 //......................................................................... 43 44 using namespace ::comphelper; 45 using namespace ::com::sun::star::uno; 46 using namespace ::com::sun::star::awt; 47 using namespace ::com::sun::star::lang; 48 using namespace ::com::sun::star::beans; 49 50 //------------------------------------------------------------------------------ 51 namespace 52 { lcl_extractFontDescriptorAggregate(sal_Int32 _nHandle,const FontDescriptor & _rFont)53 Any lcl_extractFontDescriptorAggregate( sal_Int32 _nHandle, const FontDescriptor& _rFont ) 54 { 55 Any aValue; 56 switch ( _nHandle ) 57 { 58 case PROPERTY_ID_FONT_NAME: 59 aValue <<= _rFont.Name; 60 break; 61 62 case PROPERTY_ID_FONT_STYLENAME: 63 aValue <<= _rFont.StyleName; 64 break; 65 66 case PROPERTY_ID_FONT_FAMILY: 67 aValue <<= (sal_Int16)_rFont.Family; 68 break; 69 70 case PROPERTY_ID_FONT_CHARSET: 71 aValue <<= (sal_Int16)_rFont.CharSet; 72 break; 73 74 case PROPERTY_ID_FONT_CHARWIDTH: 75 aValue <<= _rFont.CharacterWidth; 76 break; 77 78 case PROPERTY_ID_FONT_KERNING: 79 aValue <<= _rFont.Kerning; 80 break; 81 82 case PROPERTY_ID_FONT_ORIENTATION: 83 aValue <<= _rFont.Orientation; 84 break; 85 86 case PROPERTY_ID_FONT_PITCH: 87 aValue <<= _rFont.Pitch; 88 break; 89 90 case PROPERTY_ID_FONT_TYPE: 91 aValue <<= _rFont.Type; 92 break; 93 94 case PROPERTY_ID_FONT_WIDTH: 95 aValue <<= _rFont.Width; 96 break; 97 98 case PROPERTY_ID_FONT_HEIGHT: 99 aValue <<= (float)( _rFont.Height ); 100 break; 101 102 case PROPERTY_ID_FONT_WEIGHT: 103 aValue <<= (float)_rFont.Weight; 104 break; 105 106 case PROPERTY_ID_FONT_SLANT: 107 aValue = makeAny(_rFont.Slant); 108 break; 109 110 case PROPERTY_ID_FONT_UNDERLINE: 111 aValue <<= (sal_Int16)_rFont.Underline; 112 break; 113 114 case PROPERTY_ID_FONT_STRIKEOUT: 115 aValue <<= (sal_Int16)_rFont.Strikeout; 116 break; 117 118 case PROPERTY_ID_FONT_WORDLINEMODE: 119 aValue = makeAny( (sal_Bool)_rFont.WordLineMode ); 120 break; 121 122 default: 123 OSL_ENSURE( sal_False, "lcl_extractFontDescriptorAggregate: invalid handle!" ); 124 break; 125 } 126 return aValue; 127 } 128 } 129 130 //===================================================================== 131 //= FontControlModel 132 //===================================================================== 133 //--------------------------------------------------------------------- FontControlModel(bool _bToolkitCompatibleDefaults)134 FontControlModel::FontControlModel( bool _bToolkitCompatibleDefaults ) 135 :m_nFontRelief( FontRelief::NONE ) 136 ,m_nFontEmphasis( FontEmphasisMark::NONE ) 137 ,m_bToolkitCompatibleDefaults( _bToolkitCompatibleDefaults ) 138 { 139 } 140 141 //--------------------------------------------------------------------- FontControlModel(const FontControlModel * _pOriginal)142 FontControlModel::FontControlModel( const FontControlModel* _pOriginal ) 143 { 144 m_aFont = _pOriginal->m_aFont; 145 m_nFontRelief = _pOriginal->m_nFontRelief; 146 m_nFontEmphasis = _pOriginal->m_nFontEmphasis; 147 m_aTextLineColor = _pOriginal->m_aTextLineColor; 148 m_aTextColor = _pOriginal->m_aTextColor; 149 m_bToolkitCompatibleDefaults = _pOriginal->m_bToolkitCompatibleDefaults; 150 } 151 152 //--------------------------------------------------------------------- isFontRelatedProperty(sal_Int32 _nPropertyHandle) const153 bool FontControlModel::isFontRelatedProperty( sal_Int32 _nPropertyHandle ) const 154 { 155 return isFontAggregateProperty( _nPropertyHandle ) 156 || ( _nPropertyHandle == PROPERTY_ID_FONT ) 157 || ( _nPropertyHandle == PROPERTY_ID_FONTEMPHASISMARK ) 158 || ( _nPropertyHandle == PROPERTY_ID_FONTRELIEF ) 159 || ( _nPropertyHandle == PROPERTY_ID_TEXTLINECOLOR ) 160 || ( _nPropertyHandle == PROPERTY_ID_TEXTCOLOR ); 161 } 162 163 //--------------------------------------------------------------------- isFontAggregateProperty(sal_Int32 _nPropertyHandle) const164 bool FontControlModel::isFontAggregateProperty( sal_Int32 _nPropertyHandle ) const 165 { 166 return ( _nPropertyHandle == PROPERTY_ID_FONT_CHARWIDTH ) 167 || ( _nPropertyHandle == PROPERTY_ID_FONT_ORIENTATION ) 168 || ( _nPropertyHandle == PROPERTY_ID_FONT_WIDTH ) 169 || ( _nPropertyHandle == PROPERTY_ID_FONT_NAME ) 170 || ( _nPropertyHandle == PROPERTY_ID_FONT_STYLENAME ) 171 || ( _nPropertyHandle == PROPERTY_ID_FONT_FAMILY ) 172 || ( _nPropertyHandle == PROPERTY_ID_FONT_CHARSET ) 173 || ( _nPropertyHandle == PROPERTY_ID_FONT_HEIGHT ) 174 || ( _nPropertyHandle == PROPERTY_ID_FONT_WEIGHT ) 175 || ( _nPropertyHandle == PROPERTY_ID_FONT_SLANT ) 176 || ( _nPropertyHandle == PROPERTY_ID_FONT_UNDERLINE ) 177 || ( _nPropertyHandle == PROPERTY_ID_FONT_STRIKEOUT ) 178 || ( _nPropertyHandle == PROPERTY_ID_FONT_WORDLINEMODE ) 179 || ( _nPropertyHandle == PROPERTY_ID_FONT_PITCH ) 180 || ( _nPropertyHandle == PROPERTY_ID_FONT_KERNING ) 181 || ( _nPropertyHandle == PROPERTY_ID_FONT_TYPE ); 182 } 183 184 //--------------------------------------------------------------------- getTextColor() const185 sal_Int32 FontControlModel::getTextColor( ) const 186 { 187 sal_Int32 nColor = COL_TRANSPARENT; 188 m_aTextColor >>= nColor; 189 return nColor; 190 } 191 192 //--------------------------------------------------------------------- getTextLineColor() const193 sal_Int32 FontControlModel::getTextLineColor( ) const 194 { 195 sal_Int32 nColor = COL_TRANSPARENT; 196 m_aTextLineColor >>= nColor; 197 return nColor; 198 } 199 200 //------------------------------------------------------------------------------ describeFontRelatedProperties(Sequence<Property> & _rProps) const201 void FontControlModel::describeFontRelatedProperties( Sequence< Property >& /* [out] */ _rProps ) const 202 { 203 sal_Int32 nPos = _rProps.getLength(); 204 _rProps.realloc( nPos + 21 ); 205 Property* pProperties = _rProps.getArray(); 206 207 DECL_PROP2 ( FONT, FontDescriptor, BOUND, MAYBEDEFAULT ); 208 DECL_PROP2 ( FONTEMPHASISMARK, sal_Int16, BOUND, MAYBEDEFAULT ); 209 DECL_PROP2 ( FONTRELIEF, sal_Int16, BOUND, MAYBEDEFAULT ); 210 DECL_PROP3 ( TEXTCOLOR, sal_Int32, BOUND, MAYBEDEFAULT, MAYBEVOID ); 211 DECL_PROP3 ( TEXTLINECOLOR, sal_Int32, BOUND, MAYBEDEFAULT, MAYBEVOID ); 212 213 DECL_PROP1 ( FONT_CHARWIDTH, float, MAYBEDEFAULT ); 214 DECL_BOOL_PROP1 ( FONT_KERNING, MAYBEDEFAULT ); 215 DECL_PROP1 ( FONT_ORIENTATION, float, MAYBEDEFAULT ); 216 DECL_PROP1 ( FONT_PITCH, sal_Int16, MAYBEDEFAULT ); 217 DECL_PROP1 ( FONT_TYPE, sal_Int16, MAYBEDEFAULT ); 218 DECL_PROP1 ( FONT_WIDTH, sal_Int16, MAYBEDEFAULT ); 219 DECL_PROP1 ( FONT_NAME, ::rtl::OUString, MAYBEDEFAULT ); 220 DECL_PROP1 ( FONT_STYLENAME, ::rtl::OUString, MAYBEDEFAULT ); 221 DECL_PROP1 ( FONT_FAMILY, sal_Int16, MAYBEDEFAULT ); 222 DECL_PROP1 ( FONT_CHARSET, sal_Int16, MAYBEDEFAULT ); 223 DECL_PROP1 ( FONT_HEIGHT, float, MAYBEDEFAULT ); 224 DECL_PROP1 ( FONT_WEIGHT, float, MAYBEDEFAULT ); 225 DECL_PROP1 ( FONT_SLANT, sal_Int16, MAYBEDEFAULT ); 226 DECL_PROP1 ( FONT_UNDERLINE, sal_Int16, MAYBEDEFAULT ); 227 DECL_PROP1 ( FONT_STRIKEOUT, sal_Int16, MAYBEDEFAULT ); 228 DECL_BOOL_PROP1 ( FONT_WORDLINEMODE, MAYBEDEFAULT ); 229 } 230 231 //--------------------------------------------------------------------- getFastPropertyValue(Any & _rValue,sal_Int32 _nHandle) const232 void FontControlModel::getFastPropertyValue( Any& _rValue, sal_Int32 _nHandle ) const 233 { 234 switch( _nHandle ) 235 { 236 case PROPERTY_ID_TEXTCOLOR: 237 _rValue = m_aTextColor; 238 break; 239 240 case PROPERTY_ID_FONTEMPHASISMARK: 241 _rValue <<= m_nFontEmphasis; 242 break; 243 244 case PROPERTY_ID_FONTRELIEF: 245 _rValue <<= m_nFontRelief; 246 break; 247 248 case PROPERTY_ID_TEXTLINECOLOR: 249 _rValue = m_aTextLineColor; 250 break; 251 252 case PROPERTY_ID_FONT: 253 _rValue = makeAny( m_aFont ); 254 break; 255 256 default: 257 _rValue = lcl_extractFontDescriptorAggregate( _nHandle, m_aFont ); 258 break; 259 } 260 } 261 262 //--------------------------------------------------------------------- convertFastPropertyValue(Any & _rConvertedValue,Any & _rOldValue,sal_Int32 _nHandle,const Any & _rValue)263 sal_Bool FontControlModel::convertFastPropertyValue( Any& _rConvertedValue, Any& _rOldValue, 264 sal_Int32 _nHandle, const Any& _rValue ) throw( IllegalArgumentException ) 265 { 266 sal_Bool bModified = sal_False; 267 switch( _nHandle ) 268 { 269 case PROPERTY_ID_TEXTCOLOR: 270 bModified = tryPropertyValue( _rConvertedValue, _rOldValue, _rValue, m_aTextColor, ::getCppuType( static_cast< const sal_Int32* >( NULL ) ) ); 271 break; 272 273 case PROPERTY_ID_TEXTLINECOLOR: 274 bModified = tryPropertyValue( _rConvertedValue, _rOldValue, _rValue, m_aTextLineColor, ::getCppuType( static_cast< sal_Int32* >( NULL ) ) ); 275 break; 276 277 case PROPERTY_ID_FONTEMPHASISMARK: 278 bModified = tryPropertyValue( _rConvertedValue, _rOldValue, _rValue, m_nFontEmphasis ); 279 break; 280 281 case PROPERTY_ID_FONTRELIEF: 282 bModified = tryPropertyValue( _rConvertedValue, _rOldValue, _rValue, m_nFontRelief ); 283 break; 284 285 case PROPERTY_ID_FONT: 286 { 287 Any aWorkAroundGccLimitation = makeAny( m_aFont ); 288 bModified = tryPropertyValue( _rConvertedValue, _rOldValue, _rValue, aWorkAroundGccLimitation, ::getCppuType( &m_aFont ) ); 289 } 290 break; 291 292 case PROPERTY_ID_FONT_NAME: 293 bModified = tryPropertyValue( _rConvertedValue, _rOldValue, _rValue, m_aFont.Name ); 294 break; 295 296 case PROPERTY_ID_FONT_STYLENAME: 297 bModified = tryPropertyValue( _rConvertedValue, _rOldValue, _rValue, m_aFont.StyleName ); 298 break; 299 300 case PROPERTY_ID_FONT_FAMILY: 301 bModified = tryPropertyValue( _rConvertedValue, _rOldValue, _rValue, (sal_Int16)m_aFont.Family ); 302 break; 303 304 case PROPERTY_ID_FONT_CHARSET: 305 bModified = tryPropertyValue( _rConvertedValue, _rOldValue, _rValue, (sal_Int16)m_aFont.CharSet ); 306 break; 307 308 case PROPERTY_ID_FONT_CHARWIDTH: 309 bModified = tryPropertyValue( _rConvertedValue, _rOldValue, _rValue, float( m_aFont.CharacterWidth ) ); 310 break; 311 312 case PROPERTY_ID_FONT_KERNING: 313 bModified = tryPropertyValue( _rConvertedValue, _rOldValue, _rValue, (sal_Int16)m_aFont.Kerning ); 314 break; 315 316 case PROPERTY_ID_FONT_ORIENTATION: 317 bModified = tryPropertyValue( _rConvertedValue, _rOldValue, _rValue, float( m_aFont.Orientation ) ); 318 break; 319 320 case PROPERTY_ID_FONT_PITCH: 321 bModified = tryPropertyValue( _rConvertedValue, _rOldValue, _rValue, (sal_Int16)m_aFont.Pitch ); 322 break; 323 324 case PROPERTY_ID_FONT_TYPE: 325 bModified = tryPropertyValue( _rConvertedValue, _rOldValue, _rValue, (sal_Int16)m_aFont.Type ); 326 break; 327 328 case PROPERTY_ID_FONT_WIDTH: 329 bModified = tryPropertyValue( _rConvertedValue, _rOldValue, _rValue, (sal_Int16)m_aFont.Width ); 330 break; 331 332 case PROPERTY_ID_FONT_HEIGHT: 333 bModified = tryPropertyValue( _rConvertedValue, _rOldValue, _rValue, float( m_aFont.Height ) ); 334 break; 335 336 case PROPERTY_ID_FONT_WEIGHT: 337 bModified = tryPropertyValue( _rConvertedValue, _rOldValue, _rValue, m_aFont.Weight ); 338 break; 339 340 case PROPERTY_ID_FONT_SLANT: 341 bModified = tryPropertyValueEnum( _rConvertedValue, _rOldValue, _rValue, m_aFont.Slant ); 342 break; 343 344 case PROPERTY_ID_FONT_UNDERLINE: 345 bModified = tryPropertyValue( _rConvertedValue, _rOldValue, _rValue, (sal_Int16)m_aFont.Underline ); 346 break; 347 348 case PROPERTY_ID_FONT_STRIKEOUT: 349 bModified = tryPropertyValue( _rConvertedValue, _rOldValue, _rValue, (sal_Int16)m_aFont.Strikeout ); 350 break; 351 352 case PROPERTY_ID_FONT_WORDLINEMODE: 353 bModified = tryPropertyValue( _rConvertedValue, _rOldValue, _rValue, (sal_Bool)m_aFont.WordLineMode ); 354 break; 355 356 default: 357 DBG_ERROR( "FontControlModel::convertFastPropertyValue: no font aggregate!" ); 358 } 359 return bModified; 360 } 361 362 //------------------------------------------------------------------------------ setFastPropertyValue_NoBroadcast(sal_Int32 _nHandle,const Any & _rValue)363 void FontControlModel::setFastPropertyValue_NoBroadcast( sal_Int32 _nHandle, const Any& _rValue ) throw ( Exception ) 364 { 365 switch( _nHandle ) 366 { 367 case PROPERTY_ID_TEXTCOLOR: 368 m_aTextColor = _rValue; 369 break; 370 371 case PROPERTY_ID_TEXTLINECOLOR: 372 m_aTextLineColor = _rValue; 373 break; 374 375 case PROPERTY_ID_FONTEMPHASISMARK: 376 _rValue >>= m_nFontEmphasis; 377 break; 378 379 case PROPERTY_ID_FONTRELIEF: 380 _rValue >>= m_nFontRelief; 381 break; 382 383 case PROPERTY_ID_FONT: 384 _rValue >>= m_aFont; 385 break; 386 387 case PROPERTY_ID_FONT_NAME: 388 _rValue >>= m_aFont.Name; 389 break; 390 391 case PROPERTY_ID_FONT_STYLENAME: 392 _rValue >>= m_aFont.StyleName; 393 break; 394 395 case PROPERTY_ID_FONT_FAMILY: 396 _rValue >>= m_aFont.Family; 397 break; 398 399 case PROPERTY_ID_FONT_CHARSET: 400 _rValue >>= m_aFont.CharSet; 401 break; 402 403 case PROPERTY_ID_FONT_CHARWIDTH: 404 _rValue >>= m_aFont.CharacterWidth; 405 break; 406 407 case PROPERTY_ID_FONT_KERNING: 408 _rValue >>= m_aFont.Kerning; 409 break; 410 411 case PROPERTY_ID_FONT_ORIENTATION: 412 _rValue >>= m_aFont.Orientation; 413 break; 414 415 case PROPERTY_ID_FONT_PITCH: 416 _rValue >>= m_aFont.Pitch; 417 break; 418 419 case PROPERTY_ID_FONT_TYPE: 420 _rValue >>= m_aFont.Type; 421 break; 422 423 case PROPERTY_ID_FONT_WIDTH: 424 _rValue >>= m_aFont.Width; 425 break; 426 427 case PROPERTY_ID_FONT_HEIGHT: 428 { 429 float nHeight = 0; 430 _rValue >>= nHeight; 431 m_aFont.Height = (sal_Int16)nHeight; 432 } 433 break; 434 435 case PROPERTY_ID_FONT_WEIGHT: 436 _rValue >>= m_aFont.Weight; 437 break; 438 439 case PROPERTY_ID_FONT_SLANT: 440 _rValue >>= m_aFont.Slant; 441 break; 442 443 case PROPERTY_ID_FONT_UNDERLINE: 444 _rValue >>= m_aFont.Underline; 445 break; 446 447 case PROPERTY_ID_FONT_STRIKEOUT: 448 _rValue >>= m_aFont.Strikeout; 449 break; 450 451 case PROPERTY_ID_FONT_WORDLINEMODE: 452 { 453 sal_Bool bWordLineMode = sal_False; 454 _rValue >>= bWordLineMode; 455 m_aFont.WordLineMode = bWordLineMode; 456 } 457 break; 458 459 default: 460 DBG_ERROR( "FontControlModel::setFastPropertyValue_NoBroadcast: invalid property!" ); 461 } 462 } 463 464 //------------------------------------------------------------------------------ getPropertyDefaultByHandle(sal_Int32 _nHandle) const465 Any FontControlModel::getPropertyDefaultByHandle( sal_Int32 _nHandle ) const 466 { 467 Any aReturn; 468 // some defaults which are the same, not matter if we have toolkit-compatible 469 // defaults or not 470 bool bHandled = false; 471 switch( _nHandle ) 472 { 473 case PROPERTY_ID_TEXTCOLOR: 474 case PROPERTY_ID_TEXTLINECOLOR: 475 // void 476 bHandled = true; 477 break; 478 479 case PROPERTY_ID_FONTEMPHASISMARK: 480 aReturn <<= FontEmphasisMark::NONE; 481 bHandled = true; 482 break; 483 484 case PROPERTY_ID_FONTRELIEF: 485 aReturn <<= FontRelief::NONE; 486 bHandled = true; 487 break; 488 } 489 if ( bHandled ) 490 return aReturn; 491 492 if ( m_bToolkitCompatibleDefaults ) 493 { 494 EmptyFontDescriptor aEmpty; 495 if ( PROPERTY_ID_FONT == _nHandle ) 496 return makeAny( (FontDescriptor)aEmpty ); 497 return lcl_extractFontDescriptorAggregate( _nHandle, aEmpty ); 498 } 499 500 switch( _nHandle ) 501 { 502 case PROPERTY_ID_FONT: 503 aReturn <<= ::comphelper::getDefaultFont(); 504 break; 505 506 case PROPERTY_ID_FONT_WORDLINEMODE: 507 aReturn = makeBoolAny(sal_False); 508 509 case PROPERTY_ID_FONT_NAME: 510 case PROPERTY_ID_FONT_STYLENAME: 511 aReturn <<= ::rtl::OUString(); 512 513 case PROPERTY_ID_FONT_FAMILY: 514 case PROPERTY_ID_FONT_CHARSET: 515 case PROPERTY_ID_FONT_SLANT: 516 case PROPERTY_ID_FONT_UNDERLINE: 517 case PROPERTY_ID_FONT_STRIKEOUT: 518 aReturn <<= (sal_Int16)1; 519 break; 520 521 case PROPERTY_ID_FONT_KERNING: 522 aReturn = makeBoolAny(sal_False); 523 break; 524 525 case PROPERTY_ID_FONT_PITCH: 526 case PROPERTY_ID_FONT_TYPE: 527 case PROPERTY_ID_FONT_WIDTH: 528 aReturn <<= (sal_Int16)0; 529 break; 530 531 case PROPERTY_ID_FONT_HEIGHT: 532 case PROPERTY_ID_FONT_WEIGHT: 533 case PROPERTY_ID_FONT_CHARWIDTH: 534 case PROPERTY_ID_FONT_ORIENTATION: 535 aReturn <<= (float)0; 536 break; 537 538 default: 539 DBG_ERROR( "FontControlModel::getPropertyDefaultByHandle: invalid property!" ); 540 } 541 542 return aReturn; 543 } 544 545 //......................................................................... 546 } // namespace frm 547 //......................................................................... 548