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 // MARKER(update_precomp.py): autogen include statement, do not remove 23 #include "precompiled_starmath.hxx" 24 25 #define SMDLL 1 26 #include "tools/rcid.h" 27 #include <svl/eitem.hxx> 28 #include <svl/intitem.hxx> 29 #include <svl/stritem.hxx> 30 #include <sfx2/app.hxx> 31 #include <vcl/msgbox.hxx> 32 #include <svtools/ctrltool.hxx> 33 #include <sfx2/printer.hxx> 34 #include <vcl/sound.hxx> 35 #include <vcl/sndstyle.hxx> 36 #include <vcl/waitobj.hxx> 37 #include <vcl/settings.hxx> 38 #include <vcl/wall.hxx> 39 #include <sfx2/dispatch.hxx> 40 #include <sfx2/sfx.hrc> 41 #include <tools/string.hxx> 42 #include <tools/debug.hxx> 43 #include <svx/ucsubset.hxx> 44 45 #include "dialog.hxx" 46 #include "starmath.hrc" 47 #include "config.hxx" 48 #include "dialog.hrc" 49 #include "smmod.hxx" 50 #include "symbol.hxx" 51 #include "view.hxx" 52 #include "document.hxx" 53 #include "unomodel.hxx" 54 55 using ::rtl::OUString; 56 57 // Da der FontStyle besser über die Attribute gesetzt/abgefragt wird als über 58 // den StyleName bauen wir uns hier unsere eigene Übersetzung 59 // Attribute <-> StyleName 60 61 class SmFontStyles 62 { 63 String aNormal; 64 String aBold; 65 String aItalic; 66 String aBoldItalic; 67 String aEmpty; 68 69 public: 70 SmFontStyles(); 71 72 sal_uInt16 GetCount() const { return 4; } 73 const String & GetStyleName( const Font &rFont ) const; 74 const String & GetStyleName( sal_uInt16 nIdx ) const; 75 }; 76 77 78 SmFontStyles::SmFontStyles() : 79 aNormal ( ResId( RID_FONTREGULAR, *SM_MOD()->GetResMgr() ) ), 80 aBold ( ResId( RID_FONTBOLD, *SM_MOD()->GetResMgr() ) ), 81 aItalic ( ResId( RID_FONTITALIC, *SM_MOD()->GetResMgr() ) ) 82 { 83 // SM_MOD()->GetResMgr().FreeResource(); 84 85 aBoldItalic = aBold; 86 aBoldItalic.AppendAscii( ", " ); 87 aBoldItalic += aItalic; 88 } 89 90 91 const String & SmFontStyles::GetStyleName( const Font &rFont ) const 92 { 93 //! compare also SmSpecialNode::Prepare 94 sal_Bool bBold = IsBold( rFont ), 95 bItalic = IsItalic( rFont ); 96 97 if (bBold && bItalic) 98 return aBoldItalic; 99 else if (bItalic) 100 return aItalic; 101 else if (bBold) 102 return aBold; 103 else 104 return aNormal; 105 } 106 107 108 const String & SmFontStyles::GetStyleName( sal_uInt16 nIdx ) const 109 { 110 // 0 = "normal", 1 = "italic", 111 // 2 = "bold", 3 = "bold italic" 112 113 #if OSL_DEBUG_LEVEL > 1 114 DBG_ASSERT( nIdx < GetCount(), "index out of range" ); 115 #endif 116 switch (nIdx) 117 { 118 case 0 : return aNormal; 119 case 1 : return aItalic; 120 case 2 : return aBold; 121 case 3 : return aBoldItalic; 122 } 123 return aEmpty; 124 } 125 126 127 const SmFontStyles & GetFontStyles() 128 { 129 static const SmFontStyles aImpl; 130 return aImpl; 131 } 132 133 134 void SetFontStyle(const XubString &rStyleName, Font &rFont) 135 { 136 // finden des Index passend zum StyleName für den leeren StyleName wird 137 // 0 (nicht bold nicht italic) angenommen. 138 sal_uInt16 nIndex = 0; 139 if (rStyleName.Len()) 140 { 141 sal_uInt16 i; 142 const SmFontStyles &rStyles = GetFontStyles(); 143 for (i = 0; i < rStyles.GetCount(); i++) 144 if (rStyleName.CompareTo( rStyles.GetStyleName(i) ) == COMPARE_EQUAL) 145 break; 146 #if OSL_DEBUG_LEVEL > 1 147 DBG_ASSERT(i < rStyles.GetCount(), "style-name unknown"); 148 #endif 149 nIndex = i; 150 } 151 152 rFont.SetItalic((nIndex & 0x1) ? ITALIC_NORMAL : ITALIC_NONE); 153 rFont.SetWeight((nIndex & 0x2) ? WEIGHT_BOLD : WEIGHT_NORMAL); 154 } 155 156 157 /**************************************************************************/ 158 159 IMPL_LINK_INLINE_START( SmPrintOptionsTabPage, SizeButtonClickHdl, Button *, EMPTYARG/*pButton*/ ) 160 { 161 aZoom.Enable(aSizeZoomed.IsChecked()); 162 return 0; 163 } 164 IMPL_LINK_INLINE_END( SmPrintOptionsTabPage, SizeButtonClickHdl, Button *, pButton ) 165 166 167 SmPrintOptionsTabPage::SmPrintOptionsTabPage(Window *pParent, const SfxItemSet &rOptions) 168 : SfxTabPage(pParent, SmResId(RID_PRINTOPTIONPAGE), rOptions), 169 aFixedLine1 (this, SmResId( FL_PRINTOPTIONS )), 170 aTitle (this, SmResId( CB_TITLEROW )), 171 aText (this, SmResId( CB_EQUATION_TEXT )), 172 aFrame (this, SmResId( CB_FRAME )), 173 aFixedLine2 (this, SmResId( FL_PRINT_FORMAT )), 174 aSizeNormal (this, SmResId( RB_ORIGINAL_SIZE )), 175 aSizeScaled (this, SmResId( RB_FIT_TO_PAGE )), 176 aSizeZoomed (this, SmResId( RB_ZOOM )), 177 aZoom (this, SmResId( MF_ZOOM )), 178 aFixedLine3 (this, SmResId( FL_MISC_OPTIONS )), 179 aNoRightSpaces (this, SmResId( CB_IGNORE_SPACING )), 180 aSaveOnlyUsedSymbols (this, SmResId( CB_SAVE_ONLY_USED_SYMBOLS )) 181 { 182 FreeResource(); 183 184 aSizeNormal.SetClickHdl(LINK(this, SmPrintOptionsTabPage, SizeButtonClickHdl)); 185 aSizeScaled.SetClickHdl(LINK(this, SmPrintOptionsTabPage, SizeButtonClickHdl)); 186 aSizeZoomed.SetClickHdl(LINK(this, SmPrintOptionsTabPage, SizeButtonClickHdl)); 187 188 Reset(rOptions); 189 } 190 191 192 sal_Bool SmPrintOptionsTabPage::FillItemSet(SfxItemSet& rSet) 193 { 194 sal_uInt16 nPrintSize; 195 if (aSizeNormal.IsChecked()) 196 nPrintSize = PRINT_SIZE_NORMAL; 197 else if (aSizeScaled.IsChecked()) 198 nPrintSize = PRINT_SIZE_SCALED; 199 else 200 nPrintSize = PRINT_SIZE_ZOOMED; 201 202 rSet.Put(SfxUInt16Item(GetWhich(SID_PRINTSIZE), (sal_uInt16) nPrintSize)); 203 rSet.Put(SfxUInt16Item(GetWhich(SID_PRINTZOOM), (sal_uInt16) aZoom.GetValue())); 204 rSet.Put(SfxBoolItem(GetWhich(SID_PRINTTITLE), aTitle.IsChecked())); 205 rSet.Put(SfxBoolItem(GetWhich(SID_PRINTTEXT), aText.IsChecked())); 206 rSet.Put(SfxBoolItem(GetWhich(SID_PRINTFRAME), aFrame.IsChecked())); 207 rSet.Put(SfxBoolItem(GetWhich(SID_NO_RIGHT_SPACES), aNoRightSpaces.IsChecked())); 208 rSet.Put(SfxBoolItem(GetWhich(SID_SAVE_ONLY_USED_SYMBOLS), aSaveOnlyUsedSymbols.IsChecked())); 209 210 return sal_True; 211 } 212 213 214 void SmPrintOptionsTabPage::Reset(const SfxItemSet& rSet) 215 { 216 SmPrintSize ePrintSize = (SmPrintSize)((const SfxUInt16Item &)rSet.Get(GetWhich(SID_PRINTSIZE))).GetValue(); 217 218 aSizeNormal.Check(ePrintSize == PRINT_SIZE_NORMAL); 219 aSizeScaled.Check(ePrintSize == PRINT_SIZE_SCALED); 220 aSizeZoomed.Check(ePrintSize == PRINT_SIZE_ZOOMED); 221 222 aZoom.Enable(aSizeZoomed.IsChecked()); 223 224 aZoom.SetValue(((const SfxUInt16Item &)rSet.Get(GetWhich(SID_PRINTZOOM))).GetValue()); 225 226 aTitle.Check(((const SfxBoolItem &)rSet.Get(GetWhich(SID_PRINTTITLE))).GetValue()); 227 aText.Check(((const SfxBoolItem &)rSet.Get(GetWhich(SID_PRINTTEXT))).GetValue()); 228 aFrame.Check(((const SfxBoolItem &)rSet.Get(GetWhich(SID_PRINTFRAME))).GetValue()); 229 aNoRightSpaces.Check(((const SfxBoolItem &)rSet.Get(GetWhich(SID_NO_RIGHT_SPACES))).GetValue()); 230 aSaveOnlyUsedSymbols.Check(((const SfxBoolItem &)rSet.Get(GetWhich(SID_SAVE_ONLY_USED_SYMBOLS))).GetValue()); 231 } 232 233 234 SfxTabPage* SmPrintOptionsTabPage::Create(Window* pWindow, const SfxItemSet& rSet) 235 { 236 return (new SmPrintOptionsTabPage(pWindow, rSet)); 237 } 238 239 /**************************************************************************/ 240 241 242 void SmShowFont::Paint(const Rectangle& rRect ) 243 { 244 Control::Paint( rRect ); 245 246 XubString Text (GetFont().GetName()); 247 Size TextSize(GetTextWidth(Text), GetTextHeight()); 248 249 DrawText(Point((GetOutputSize().Width() - TextSize.Width()) / 2, 250 (GetOutputSize().Height() - TextSize.Height()) / 2), Text); 251 } 252 253 254 void SmShowFont::SetFont(const Font& rFont) 255 { 256 Color aTxtColor( GetTextColor() ); 257 Font aFont (rFont); 258 259 Invalidate(); 260 aFont.SetSize(Size(0, 24)); 261 aFont.SetAlign(ALIGN_TOP); 262 Control::SetFont(aFont); 263 264 // keep old text color (new font may have different color) 265 SetTextColor( aTxtColor ); 266 } 267 268 269 IMPL_LINK_INLINE_START( SmFontDialog, FontSelectHdl, ComboBox *, pComboBox ) 270 { 271 Face.SetName(pComboBox->GetText()); 272 aShowFont.SetFont(Face); 273 return 0; 274 } 275 IMPL_LINK_INLINE_END( SmFontDialog, FontSelectHdl, ComboBox *, pComboBox ) 276 277 278 IMPL_LINK( SmFontDialog, FontModifyHdl, ComboBox *, pComboBox ) 279 { 280 // if font is available in list then use it 281 sal_uInt16 nPos = pComboBox->GetEntryPos( pComboBox->GetText() ); 282 if (COMBOBOX_ENTRY_NOTFOUND != nPos) 283 { 284 FontSelectHdl( pComboBox ); 285 } 286 return 0; 287 } 288 289 290 IMPL_LINK( SmFontDialog, AttrChangeHdl, CheckBox *, EMPTYARG /*pCheckBox*/ ) 291 { 292 if (aBoldCheckBox.IsChecked()) 293 Face.SetWeight(FontWeight(WEIGHT_BOLD)); 294 else 295 Face.SetWeight(FontWeight(WEIGHT_NORMAL)); 296 297 if (aItalicCheckBox.IsChecked()) 298 Face.SetItalic(ITALIC_NORMAL); 299 else 300 Face.SetItalic(ITALIC_NONE); 301 302 aShowFont.SetFont(Face); 303 return 0; 304 } 305 306 307 void SmFontDialog::SetFont(const Font &rFont) 308 { 309 Face = rFont; 310 311 aFontBox.SetText( Face.GetName() ); 312 aBoldCheckBox.Check( IsBold( Face ) ); 313 aItalicCheckBox.Check( IsItalic( Face ) ); 314 315 aShowFont.SetFont(Face); 316 } 317 318 319 SmFontDialog::SmFontDialog(Window * pParent, 320 OutputDevice *pFntListDevice, sal_Bool bHideCheckboxes, sal_Bool bFreeRes) 321 : ModalDialog(pParent,SmResId(RID_FONTDIALOG)), 322 aFixedText1 (this, SmResId(1)), 323 aFontBox (this, SmResId(1)), 324 aBoldCheckBox (this, SmResId(1)), 325 aItalicCheckBox (this, SmResId(2)), 326 aOKButton1 (this, SmResId(1)), 327 aCancelButton1 (this, SmResId(1)), 328 aShowFont (this, SmResId(1)), 329 aFixedText2 (this, SmResId(2)) 330 { 331 if (bFreeRes) 332 FreeResource(); 333 334 { 335 WaitObject( this ); 336 337 FontList aFontList( pFntListDevice ); 338 339 sal_uInt16 nCount = aFontList.GetFontNameCount(); 340 for (sal_uInt16 i = 0; i < nCount; i++) 341 aFontBox.InsertEntry( aFontList.GetFontName(i).GetName() ); 342 343 Face.SetSize(Size(0, 24)); 344 Face.SetWeight(WEIGHT_NORMAL); 345 Face.SetItalic(ITALIC_NONE); 346 Face.SetFamily(FAMILY_DONTKNOW); 347 Face.SetPitch(PITCH_DONTKNOW); 348 Face.SetCharSet(RTL_TEXTENCODING_DONTKNOW); 349 Face.SetTransparent(sal_True); 350 351 InitColor_Impl(); 352 353 // preview like controls should have a 2D look 354 aShowFont.SetBorderStyle( WINDOW_BORDER_MONO ); 355 } 356 357 aFontBox.SetSelectHdl(LINK(this, SmFontDialog, FontSelectHdl)); 358 aFontBox.SetModifyHdl(LINK(this, SmFontDialog, FontModifyHdl)); 359 aBoldCheckBox.SetClickHdl(LINK(this, SmFontDialog, AttrChangeHdl)); 360 aItalicCheckBox.SetClickHdl(LINK(this, SmFontDialog, AttrChangeHdl)); 361 362 if (bHideCheckboxes) 363 { 364 aBoldCheckBox.Check( sal_False ); 365 aBoldCheckBox.Enable( sal_False ); 366 aBoldCheckBox.Show( sal_False ); 367 aItalicCheckBox.Check( sal_False ); 368 aItalicCheckBox.Enable( sal_False ); 369 aItalicCheckBox.Show( sal_False ); 370 aFixedText2.Show( sal_False ); 371 372 Size aSize( aFontBox.GetSizePixel() ); 373 long nComboBoxBottom = aFontBox.GetPosPixel().Y() + aFontBox.GetSizePixel().Height(); 374 long nCheckBoxBottom = aItalicCheckBox.GetPosPixel().Y() + aItalicCheckBox.GetSizePixel().Height(); 375 aSize.Height() += nCheckBoxBottom - nComboBoxBottom; 376 aFontBox.SetSizePixel( aSize ); 377 } 378 } 379 380 void SmFontDialog::InitColor_Impl() 381 { 382 #if OSL_DEBUG_LEVEL > 1 383 Color aBC( GetDisplayBackground().GetColor() ); 384 #endif 385 ColorData nBgCol = COL_WHITE, 386 nTxtCol = COL_BLACK; 387 const StyleSettings &rS = GetSettings().GetStyleSettings(); 388 if (rS.GetHighContrastMode()) 389 { 390 nBgCol = rS.GetFieldColor().GetColor(); 391 nTxtCol = rS.GetFieldTextColor().GetColor(); 392 } 393 394 Color aTmpColor( nBgCol ); 395 Wallpaper aWall( aTmpColor ); 396 Color aTxtColor( nTxtCol ); 397 aShowFont.SetBackground( aWall ); 398 aShowFont.SetTextColor( aTxtColor ); 399 } 400 401 402 void SmFontDialog::DataChanged( const DataChangedEvent& rDCEvt ) 403 { 404 if ( rDCEvt.GetType() == DATACHANGED_SETTINGS && 405 (rDCEvt.GetFlags() & SETTINGS_STYLE) ) 406 InitColor_Impl(); 407 408 ModalDialog::DataChanged( rDCEvt ); 409 } 410 411 /**************************************************************************/ 412 413 414 IMPL_LINK( SmFontSizeDialog, DefaultButtonClickHdl, Button *, EMPTYARG /*pButton*/ ) 415 { 416 QueryBox *pQueryBox = new QueryBox(this, SmResId(RID_DEFAULTSAVEQUERY)); 417 418 if (pQueryBox->Execute() == RET_YES) 419 { 420 SmModule *pp = SM_MOD(); 421 SmFormat aFmt( pp->GetConfig()->GetStandardFormat() ); 422 WriteTo( aFmt ); 423 pp->GetConfig()->SetStandardFormat( aFmt ); 424 } 425 426 delete pQueryBox; 427 return 0; 428 } 429 430 431 SmFontSizeDialog::SmFontSizeDialog(Window * pParent, sal_Bool bFreeRes) 432 : ModalDialog(pParent, SmResId(RID_FONTSIZEDIALOG)), 433 aFixedText1(this, SmResId(1)), 434 aBaseSize(this, SmResId(1)), 435 aFixedText4(this, SmResId(4)), 436 aTextSize(this, SmResId(4)), 437 aFixedText5(this, SmResId(5)), 438 aIndexSize(this, SmResId(5)), 439 aFixedText6(this, SmResId(6)), 440 aFunctionSize(this, SmResId(6)), 441 aFixedText7(this, SmResId(7)), 442 aOperatorSize(this, SmResId(7)), 443 aFixedText8(this, SmResId(8)), 444 aBorderSize(this, SmResId(8)), 445 aFixedLine1(this, SmResId(1)), 446 aOKButton1(this, SmResId(1)), 447 aCancelButton1(this, SmResId(1)), 448 aDefaultButton(this, SmResId(1)) 449 { 450 if (bFreeRes) 451 FreeResource(); 452 453 aDefaultButton.SetClickHdl(LINK(this, SmFontSizeDialog, DefaultButtonClickHdl)); 454 } 455 456 457 void SmFontSizeDialog::ReadFrom(const SmFormat &rFormat) 458 { 459 //! aufpassen: richtig runden! 460 aBaseSize.SetValue( SmRoundFraction( 461 Sm100th_mmToPts( rFormat.GetBaseSize().Height() ) ) ); 462 463 aTextSize .SetValue( rFormat.GetRelSize(SIZ_TEXT) ); 464 aIndexSize .SetValue( rFormat.GetRelSize(SIZ_INDEX) ); 465 aFunctionSize.SetValue( rFormat.GetRelSize(SIZ_FUNCTION) ); 466 aOperatorSize.SetValue( rFormat.GetRelSize(SIZ_OPERATOR) ); 467 aBorderSize .SetValue( rFormat.GetRelSize(SIZ_LIMITS) ); 468 } 469 470 471 void SmFontSizeDialog::WriteTo(SmFormat &rFormat) const 472 { 473 rFormat.SetBaseSize( Size(0, SmPtsTo100th_mm( static_cast< long >(aBaseSize.GetValue()))) ); 474 475 rFormat.SetRelSize(SIZ_TEXT, (sal_uInt16) aTextSize .GetValue()); 476 rFormat.SetRelSize(SIZ_INDEX, (sal_uInt16) aIndexSize .GetValue()); 477 rFormat.SetRelSize(SIZ_FUNCTION, (sal_uInt16) aFunctionSize.GetValue()); 478 rFormat.SetRelSize(SIZ_OPERATOR, (sal_uInt16) aOperatorSize.GetValue()); 479 rFormat.SetRelSize(SIZ_LIMITS, (sal_uInt16) aBorderSize .GetValue()); 480 481 const Size aTmp (rFormat.GetBaseSize()); 482 for (sal_uInt16 i = FNT_BEGIN; i <= FNT_END; i++) 483 rFormat.SetFontSize(i, aTmp); 484 485 rFormat.RequestApplyChanges(); 486 } 487 488 489 /**************************************************************************/ 490 491 492 IMPL_LINK( SmFontTypeDialog, MenuSelectHdl, Menu *, pMenu ) 493 { 494 SmFontPickListBox *pActiveListBox; 495 496 sal_Bool bHideCheckboxes = sal_False; 497 switch (pMenu->GetCurItemId()) 498 { 499 case 1: pActiveListBox = &aVariableFont; break; 500 case 2: pActiveListBox = &aFunctionFont; break; 501 case 3: pActiveListBox = &aNumberFont; break; 502 case 4: pActiveListBox = &aTextFont; break; 503 case 5: pActiveListBox = &aSerifFont; bHideCheckboxes = sal_True; break; 504 case 6: pActiveListBox = &aSansFont; bHideCheckboxes = sal_True; break; 505 case 7: pActiveListBox = &aFixedFont; bHideCheckboxes = sal_True; break; 506 default:pActiveListBox = NULL; 507 } 508 509 if (pActiveListBox) 510 { 511 SmFontDialog *pFontDialog = new SmFontDialog(this, pFontListDev, bHideCheckboxes); 512 513 pActiveListBox->WriteTo(*pFontDialog); 514 if (pFontDialog->Execute() == RET_OK) 515 pActiveListBox->ReadFrom(*pFontDialog); 516 delete pFontDialog; 517 } 518 return 0; 519 } 520 521 522 IMPL_LINK_INLINE_START( SmFontTypeDialog, DefaultButtonClickHdl, Button *, EMPTYARG /*pButton*/ ) 523 { 524 QueryBox *pQueryBox = new QueryBox(this, SmResId(RID_DEFAULTSAVEQUERY)); 525 if (pQueryBox->Execute() == RET_YES) 526 { 527 SmModule *pp = SM_MOD(); 528 SmFormat aFmt( pp->GetConfig()->GetStandardFormat() ); 529 WriteTo( aFmt ); 530 pp->GetConfig()->SetStandardFormat( aFmt, sal_True ); 531 } 532 533 delete pQueryBox; 534 return 0; 535 } 536 IMPL_LINK_INLINE_END( SmFontTypeDialog, DefaultButtonClickHdl, Button *, pButton ) 537 538 539 SmFontTypeDialog::SmFontTypeDialog(Window * pParent, OutputDevice *pFntListDevice, sal_Bool bFreeRes) 540 : ModalDialog(pParent, SmResId(RID_FONTTYPEDIALOG)), 541 aFixedText1 (this, SmResId(1)), 542 aVariableFont (this, SmResId(1)), 543 aFixedText2 (this, SmResId(2)), 544 aFunctionFont (this, SmResId(2)), 545 aFixedText3 (this, SmResId(3)), 546 aNumberFont (this, SmResId(3)), 547 aFixedText4 (this, SmResId(4)), 548 aTextFont (this, SmResId(4)), 549 aFixedText5 (this, SmResId(5)), 550 aSerifFont (this, SmResId(5)), 551 aFixedText6 (this, SmResId(6)), 552 aSansFont (this, SmResId(6)), 553 aFixedText7 (this, SmResId(7)), 554 aFixedFont (this, SmResId(7)), 555 aFixedLine1 (this, SmResId(1)), 556 aFixedLine2 (this, SmResId(2)), 557 aOKButton1 (this, SmResId(1)), 558 aCancelButton1 (this, SmResId(1)), 559 aMenuButton (this, SmResId(1)), 560 aDefaultButton (this, SmResId(2)), 561 pFontListDev (pFntListDevice) 562 { 563 if (bFreeRes) 564 FreeResource(); 565 566 aDefaultButton.SetClickHdl(LINK(this, SmFontTypeDialog, DefaultButtonClickHdl)); 567 568 aMenuButton.GetPopupMenu()->SetSelectHdl(LINK(this, SmFontTypeDialog, MenuSelectHdl)); 569 } 570 571 void SmFontTypeDialog::ReadFrom(const SmFormat &rFormat) 572 { 573 SmModule *pp = SM_MOD(); 574 575 aVariableFont = pp->GetConfig()->GetFontPickList(FNT_VARIABLE); 576 aFunctionFont = pp->GetConfig()->GetFontPickList(FNT_FUNCTION); 577 aNumberFont = pp->GetConfig()->GetFontPickList(FNT_NUMBER); 578 aTextFont = pp->GetConfig()->GetFontPickList(FNT_TEXT); 579 aSerifFont = pp->GetConfig()->GetFontPickList(FNT_SERIF); 580 aSansFont = pp->GetConfig()->GetFontPickList(FNT_SANS); 581 aFixedFont = pp->GetConfig()->GetFontPickList(FNT_FIXED); 582 583 aVariableFont.Insert( rFormat.GetFont(FNT_VARIABLE) ); 584 aFunctionFont.Insert( rFormat.GetFont(FNT_FUNCTION) ); 585 aNumberFont .Insert( rFormat.GetFont(FNT_NUMBER) ); 586 aTextFont .Insert( rFormat.GetFont(FNT_TEXT) ); 587 aSerifFont .Insert( rFormat.GetFont(FNT_SERIF) ); 588 aSansFont .Insert( rFormat.GetFont(FNT_SANS) ); 589 aFixedFont .Insert( rFormat.GetFont(FNT_FIXED) ); 590 } 591 592 593 void SmFontTypeDialog::WriteTo(SmFormat &rFormat) const 594 { 595 SmModule *pp = SM_MOD(); 596 597 pp->GetConfig()->GetFontPickList(FNT_VARIABLE) = aVariableFont; 598 pp->GetConfig()->GetFontPickList(FNT_FUNCTION) = aFunctionFont; 599 pp->GetConfig()->GetFontPickList(FNT_NUMBER) = aNumberFont; 600 pp->GetConfig()->GetFontPickList(FNT_TEXT) = aTextFont; 601 pp->GetConfig()->GetFontPickList(FNT_SERIF) = aSerifFont; 602 pp->GetConfig()->GetFontPickList(FNT_SANS) = aSansFont; 603 pp->GetConfig()->GetFontPickList(FNT_FIXED) = aFixedFont; 604 605 rFormat.SetFont( FNT_VARIABLE, aVariableFont.Get(0) ); 606 rFormat.SetFont( FNT_FUNCTION, aFunctionFont.Get(0) ); 607 rFormat.SetFont( FNT_NUMBER, aNumberFont .Get(0) ); 608 rFormat.SetFont( FNT_TEXT, aTextFont .Get(0) ); 609 rFormat.SetFont( FNT_SERIF, aSerifFont .Get(0) ); 610 rFormat.SetFont( FNT_SANS, aSansFont .Get(0) ); 611 rFormat.SetFont( FNT_FIXED, aFixedFont .Get(0) ); 612 613 rFormat.RequestApplyChanges(); 614 } 615 616 /**************************************************************************/ 617 618 struct FieldMinMax 619 { 620 sal_uInt16 nMin, nMax; 621 }; 622 623 // Data for min and max values of the 4 metric fields 624 // for each of the 10 categories 625 static const FieldMinMax pMinMaxData[10][4] = 626 { 627 // 0 628 {{ 0, 200 }, { 0, 200 }, { 0, 100 }, { 0, 0 }}, 629 // 1 630 {{ 0, 100 }, { 0, 100 }, { 0, 0 }, { 0, 0 }}, 631 // 2 632 {{ 0, 100 }, { 0, 100 }, { 0, 0 }, { 0, 0 }}, 633 // 3 634 {{ 0, 100 }, { 1, 100 }, { 0, 0 }, { 0, 0 }}, 635 // 4 636 {{ 0, 100 }, { 0, 100 }, { 0, 0 }, { 0, 0 }}, 637 // 5 638 {{ 0, 100 }, { 0, 100 }, { 0, 0 }, { 0, 100 }}, 639 // 6 640 {{ 0, 300 }, { 0, 300 }, { 0, 0 }, { 0, 0 }}, 641 // 7 642 {{ 0, 100 }, { 0, 100 }, { 0, 0 }, { 0, 0 }}, 643 // 8 644 {{ 0, 100 }, { 0, 100 }, { 0, 0 }, { 0, 0 }}, 645 // 9 646 {{ 0, 10000 }, { 0, 10000 }, { 0, 10000 }, { 0, 10000 }} 647 }; 648 649 SmCategoryDesc::SmCategoryDesc(const ResId& rResId, sal_uInt16 nCategoryIdx) : 650 Resource(rResId), 651 bIsHighContrast(sal_False) 652 { 653 if (IsAvailableRes(ResId(1,*rResId.GetResMgr()).SetRT(RSC_STRING))) 654 { 655 Name = XubString(ResId(1,*rResId.GetResMgr())); 656 657 int i; 658 for (i = 0; i < 4; i++) 659 { 660 int nI2 = i + 2; 661 662 if (IsAvailableRes(ResId(nI2,*rResId.GetResMgr()).SetRT(RSC_STRING))) 663 { 664 Strings [i] = new XubString(ResId(nI2,*rResId.GetResMgr())); 665 Graphics [i] = new Bitmap(ResId(10*nI2,*rResId.GetResMgr())); 666 GraphicsH[i] = new Bitmap(ResId(10*nI2+1,*rResId.GetResMgr())); 667 } 668 else 669 { 670 Strings [i] = 0; 671 Graphics [i] = 0; 672 GraphicsH[i] = 0; 673 } 674 } 675 676 for (i = 0; i < 4; i++) 677 { 678 const FieldMinMax &rMinMax = pMinMaxData[ nCategoryIdx ][i]; 679 Value[i] = Minimum[i] = rMinMax.nMin; 680 Maximum[i] = rMinMax.nMax; 681 } 682 } 683 684 FreeResource(); 685 } 686 687 688 SmCategoryDesc::~SmCategoryDesc() 689 { 690 for (int i = 0; i < 4; i++) 691 { 692 delete Strings [i]; 693 delete Graphics [i]; 694 delete GraphicsH[i]; 695 } 696 } 697 698 /**************************************************************************/ 699 700 IMPL_LINK( SmDistanceDialog, GetFocusHdl, Control *, pControl ) 701 { 702 if (Categories[nActiveCategory]) 703 { 704 sal_uInt16 i; 705 706 if (pControl == &aMetricField1) 707 i = 0; 708 else if (pControl == &aMetricField2) 709 i = 1; 710 else if (pControl == &aMetricField3) 711 i = 2; 712 else if (pControl == &aMetricField4) 713 i = 3; 714 else 715 return 0; 716 aBitmap.SetBitmap(*(Categories[nActiveCategory]->GetGraphic(i))); 717 } 718 return 0; 719 } 720 721 IMPL_LINK( SmDistanceDialog, MenuSelectHdl, Menu *, pMenu ) 722 { 723 SetCategory(pMenu->GetCurItemId() - 1); 724 return 0; 725 } 726 727 728 IMPL_LINK( SmDistanceDialog, DefaultButtonClickHdl, Button *, EMPTYARG /*pButton*/ ) 729 { 730 QueryBox *pQueryBox = new QueryBox(this, SmResId(RID_DEFAULTSAVEQUERY)); 731 732 if (pQueryBox->Execute() == RET_YES) 733 { 734 SmModule *pp = SM_MOD(); 735 SmFormat aFmt( pp->GetConfig()->GetStandardFormat() ); 736 WriteTo( aFmt ); 737 pp->GetConfig()->SetStandardFormat( aFmt ); 738 } 739 delete pQueryBox; 740 return 0; 741 } 742 743 744 IMPL_LINK( SmDistanceDialog, CheckBoxClickHdl, CheckBox *, pCheckBox ) 745 { 746 if (pCheckBox == &aCheckBox1) 747 { 748 aCheckBox1.Toggle(); 749 750 sal_Bool bChecked = aCheckBox1.IsChecked(); 751 aFixedText4 .Enable( bChecked ); 752 aMetricField4.Enable( bChecked ); 753 } 754 return 0; 755 } 756 757 758 void SmDistanceDialog::SetHelpId(MetricField &rField, const rtl::OString& sHelpId) 759 { 760 //! HelpID's die auf diese Weise explizit gesetzt werden, müssen im 761 //! util Verzeichnis im File "hidother.src" mit Hilfe von "hidspecial" 762 //! definiert werden! 763 764 const XubString aEmptyText; 765 #if OSL_DEBUG_LEVEL > 1 766 DBG_ASSERT(aEmptyText.Len() == 0, "Sm: Ooops..."); 767 #endif 768 769 rField.SetHelpId(sHelpId); 770 rField.SetHelpText(aEmptyText); 771 772 // since MetricField inherits from SpinField which has a sub Edit field 773 // (which is actually the one we modify) we have to set the help-id 774 // for it too. 775 Edit *pSubEdit = rField.GetSubEdit(); 776 if (pSubEdit) 777 { 778 pSubEdit->SetHelpId(sHelpId); 779 pSubEdit->SetHelpText(aEmptyText); 780 } 781 } 782 783 784 void SmDistanceDialog::SetCategory(sal_uInt16 nCategory) 785 { 786 #if OSL_DEBUG_LEVEL > 1 787 DBG_ASSERT(/*0 <= nCategory &&*/ nCategory < NOCATEGORIES, 788 "Sm: falsche Kategorienummer in SmDistanceDialog"); 789 #endif 790 791 // array to convert category- and metricfield-number in help ids. 792 // 0 is used in case of unused combinations. 793 #if OSL_DEBUG_LEVEL > 1 794 DBG_ASSERT(NOCATEGORIES == 10, "Sm : Array passt nicht zu Anzahl der Kategorien"); 795 #endif 796 const char* __READONLY_DATA aCatMf2Hid[10][4] = 797 { 798 { HID_SMA_DEFAULT_DIST, HID_SMA_LINE_DIST, HID_SMA_ROOT_DIST, 0 }, 799 { HID_SMA_SUP_DIST, HID_SMA_SUB_DIST , 0, 0 }, 800 { HID_SMA_NUMERATOR_DIST, HID_SMA_DENOMINATOR_DIST, 0, 0 }, 801 { HID_SMA_FRACLINE_EXCWIDTH, HID_SMA_FRACLINE_LINEWIDTH, 0, 0 }, 802 { HID_SMA_UPPERLIMIT_DIST, HID_SMA_LOWERLIMIT_DIST, 0, 0 }, 803 { HID_SMA_BRACKET_EXCHEIGHT, HID_SMA_BRACKET_DIST, 0, HID_SMA_BRACKET_EXCHEIGHT2 }, 804 { HID_SMA_MATRIXROW_DIST, HID_SMA_MATRIXCOL_DIST, 0, 0 }, 805 { HID_SMA_ATTRIBUT_DIST, HID_SMA_INTERATTRIBUT_DIST, 0, 0 }, 806 { HID_SMA_OPERATOR_EXCHEIGHT, HID_SMA_OPERATOR_DIST, 0, 0 }, 807 { HID_SMA_LEFTBORDER_DIST, HID_SMA_RIGHTBORDER_DIST, HID_SMA_UPPERBORDER_DIST, HID_SMA_LOWERBORDER_DIST } 808 }; 809 810 // array to help iterate over the controls 811 Window * __READONLY_DATA aWin[4][2] = 812 { 813 { &aFixedText1, &aMetricField1 }, 814 { &aFixedText2, &aMetricField2 }, 815 { &aFixedText3, &aMetricField3 }, 816 { &aFixedText4, &aMetricField4 } 817 }; 818 819 SmCategoryDesc *pCat; 820 821 // merken der (evtl neuen) Einstellungen der aktiven SmCategoryDesc 822 // bevor zu der neuen gewechselt wird. 823 if (nActiveCategory != CATEGORY_NONE) 824 { 825 pCat = Categories[nActiveCategory]; 826 pCat->SetValue(0, (sal_uInt16) aMetricField1.GetValue()); 827 pCat->SetValue(1, (sal_uInt16) aMetricField2.GetValue()); 828 pCat->SetValue(2, (sal_uInt16) aMetricField3.GetValue()); 829 pCat->SetValue(3, (sal_uInt16) aMetricField4.GetValue()); 830 831 if (nActiveCategory == 5) 832 bScaleAllBrackets = aCheckBox1.IsChecked(); 833 834 aMenuButton.GetPopupMenu()->CheckItem(nActiveCategory + 1, sal_False); 835 } 836 837 // aktivieren/deaktivieren der zugehörigen Controls in Abhängigkeit von der 838 // gewählten Kategorie. 839 sal_Bool bActive; 840 for (sal_uInt16 i = 0; i < 4; i++) 841 { 842 FixedText *pFT = (FixedText * const) aWin[i][0]; 843 MetricField *pMF = (MetricField * const) aWin[i][1]; 844 845 // Um feststellen welche Controls aktiv sein sollen wird das 846 // vorhandensein einer zugehörigen HelpID überprüft. 847 bActive = aCatMf2Hid[nCategory][i] != 0; 848 849 pFT->Show(bActive); 850 pFT->Enable(bActive); 851 pMF->Show(bActive); 852 pMF->Enable(bActive); 853 854 // setzen von Masseinheit und Anzahl der Nachkommastellen 855 FieldUnit eUnit; 856 sal_uInt16 nDigits; 857 if (nCategory < 9) 858 { 859 eUnit = FUNIT_PERCENT; 860 nDigits = 0; 861 } 862 else 863 { 864 eUnit = FUNIT_100TH_MM; 865 nDigits = 2; 866 } 867 pMF->SetUnit(eUnit); //! verändert den Wert 868 pMF->SetDecimalDigits(nDigits); 869 870 if (bActive) 871 { 872 pCat = Categories[nCategory]; 873 pFT->SetText(*pCat->GetString(i)); 874 875 pMF->SetMin(pCat->GetMinimum(i)); 876 pMF->SetMax(pCat->GetMaximum(i)); 877 pMF->SetValue(pCat->GetValue(i)); 878 879 SetHelpId(*pMF, aCatMf2Hid[nCategory][i]); 880 } 881 } 882 // nun noch die CheckBox und das zugehörige MetricField genau dann aktivieren, 883 // falls es sich um das Klammer Menu handelt. 884 bActive = nCategory == 5; 885 aCheckBox1.Show(bActive); 886 aCheckBox1.Enable(bActive); 887 if (bActive) 888 { 889 aCheckBox1.Check( bScaleAllBrackets ); 890 891 sal_Bool bChecked = aCheckBox1.IsChecked(); 892 aFixedText4 .Enable( bChecked ); 893 aMetricField4.Enable( bChecked ); 894 } 895 896 aMenuButton.GetPopupMenu()->CheckItem(nCategory + 1, sal_True); 897 aFixedLine.SetText(Categories[nCategory]->GetName()); 898 899 nActiveCategory = nCategory; 900 901 aMetricField1.GrabFocus(); 902 Invalidate(); 903 Update(); 904 } 905 906 907 SmDistanceDialog::SmDistanceDialog(Window *pParent, sal_Bool bFreeRes) 908 : ModalDialog(pParent, SmResId(RID_DISTANCEDIALOG)), 909 aFixedText1 (this, SmResId(1)), 910 aMetricField1 (this, SmResId(1)), 911 aFixedText2 (this, SmResId(2)), 912 aMetricField2 (this, SmResId(2)), 913 aFixedText3 (this, SmResId(3)), 914 aMetricField3 (this, SmResId(3)), 915 aCheckBox1 (this, SmResId(1)), 916 aFixedText4 (this, SmResId(4)), 917 aMetricField4 (this, SmResId(4)), 918 aOKButton1 (this, SmResId(1)), 919 aCancelButton1 (this, SmResId(1)), 920 aMenuButton (this, SmResId(1)), 921 aDefaultButton (this, SmResId(1)), 922 aBitmap (this, SmResId(1)), 923 aFixedLine (this, SmResId(1)) 924 { 925 for (sal_uInt16 i = 0; i < NOCATEGORIES; i++) 926 Categories[i] = new SmCategoryDesc(SmResId(i + 1), i); 927 nActiveCategory = CATEGORY_NONE; 928 bScaleAllBrackets = sal_False; 929 930 if (bFreeRes) 931 FreeResource(); 932 933 ApplyImages(); 934 935 // preview like controls should have a 2D look 936 aBitmap.SetBorderStyle( WINDOW_BORDER_MONO ); 937 938 aMetricField1.SetGetFocusHdl(LINK(this, SmDistanceDialog, GetFocusHdl)); 939 aMetricField2.SetGetFocusHdl(LINK(this, SmDistanceDialog, GetFocusHdl)); 940 aMetricField3.SetGetFocusHdl(LINK(this, SmDistanceDialog, GetFocusHdl)); 941 aMetricField4.SetGetFocusHdl(LINK(this, SmDistanceDialog, GetFocusHdl)); 942 aCheckBox1.SetClickHdl(LINK(this, SmDistanceDialog, CheckBoxClickHdl)); 943 944 aMenuButton.GetPopupMenu()->SetSelectHdl(LINK(this, SmDistanceDialog, MenuSelectHdl)); 945 946 aDefaultButton.SetClickHdl(LINK(this, SmDistanceDialog, DefaultButtonClickHdl)); 947 } 948 949 950 SmDistanceDialog::~SmDistanceDialog() 951 { 952 for (int i = 0; i < NOCATEGORIES; i++) 953 DELETEZ(Categories[i]); 954 } 955 956 void SmDistanceDialog::ApplyImages() 957 { 958 sal_Bool bHighContrast = GetSettings().GetStyleSettings().GetHighContrastMode(); 959 for (int i = 0; i < NOCATEGORIES; ++i) 960 { 961 SmCategoryDesc *pCat = Categories[i]; 962 if (pCat) 963 pCat->SetHighContrast( bHighContrast ); 964 } 965 } 966 967 void SmDistanceDialog::DataChanged( const DataChangedEvent &rEvt ) 968 { 969 if ( (rEvt.GetType() == DATACHANGED_SETTINGS) && (rEvt.GetFlags() & SETTINGS_STYLE) ) 970 ApplyImages(); 971 972 ModalDialog::DataChanged( rEvt ); 973 } 974 975 void SmDistanceDialog::ReadFrom(const SmFormat &rFormat) 976 { 977 Categories[0]->SetValue(0, rFormat.GetDistance(DIS_HORIZONTAL)); 978 Categories[0]->SetValue(1, rFormat.GetDistance(DIS_VERTICAL)); 979 Categories[0]->SetValue(2, rFormat.GetDistance(DIS_ROOT)); 980 Categories[1]->SetValue(0, rFormat.GetDistance(DIS_SUPERSCRIPT)); 981 Categories[1]->SetValue(1, rFormat.GetDistance(DIS_SUBSCRIPT)); 982 Categories[2]->SetValue(0, rFormat.GetDistance(DIS_NUMERATOR)); 983 Categories[2]->SetValue(1, rFormat.GetDistance(DIS_DENOMINATOR)); 984 Categories[3]->SetValue(0, rFormat.GetDistance(DIS_FRACTION)); 985 Categories[3]->SetValue(1, rFormat.GetDistance(DIS_STROKEWIDTH)); 986 Categories[4]->SetValue(0, rFormat.GetDistance(DIS_UPPERLIMIT)); 987 Categories[4]->SetValue(1, rFormat.GetDistance(DIS_LOWERLIMIT)); 988 Categories[5]->SetValue(0, rFormat.GetDistance(DIS_BRACKETSIZE)); 989 Categories[5]->SetValue(1, rFormat.GetDistance(DIS_BRACKETSPACE)); 990 Categories[5]->SetValue(3, rFormat.GetDistance(DIS_NORMALBRACKETSIZE)); 991 Categories[6]->SetValue(0, rFormat.GetDistance(DIS_MATRIXROW)); 992 Categories[6]->SetValue(1, rFormat.GetDistance(DIS_MATRIXCOL)); 993 Categories[7]->SetValue(0, rFormat.GetDistance(DIS_ORNAMENTSIZE)); 994 Categories[7]->SetValue(1, rFormat.GetDistance(DIS_ORNAMENTSPACE)); 995 Categories[8]->SetValue(0, rFormat.GetDistance(DIS_OPERATORSIZE)); 996 Categories[8]->SetValue(1, rFormat.GetDistance(DIS_OPERATORSPACE)); 997 Categories[9]->SetValue(0, rFormat.GetDistance(DIS_LEFTSPACE)); 998 Categories[9]->SetValue(1, rFormat.GetDistance(DIS_RIGHTSPACE)); 999 Categories[9]->SetValue(2, rFormat.GetDistance(DIS_TOPSPACE)); 1000 Categories[9]->SetValue(3, rFormat.GetDistance(DIS_BOTTOMSPACE)); 1001 1002 bScaleAllBrackets = rFormat.IsScaleNormalBrackets(); 1003 1004 // force update (even of category 0) by setting nActiveCategory to a 1005 // non-existent category number 1006 nActiveCategory = CATEGORY_NONE; 1007 SetCategory(0); 1008 } 1009 1010 1011 void SmDistanceDialog::WriteTo(SmFormat &rFormat) /*const*/ 1012 { 1013 // hmm... können die tatsächlich unterschiedlich sein? 1014 // wenn nicht kann oben nämlich das const stehen! 1015 SetCategory(nActiveCategory); 1016 1017 rFormat.SetDistance( DIS_HORIZONTAL, Categories[0]->GetValue(0) ); 1018 rFormat.SetDistance( DIS_VERTICAL, Categories[0]->GetValue(1) ); 1019 rFormat.SetDistance( DIS_ROOT, Categories[0]->GetValue(2) ); 1020 rFormat.SetDistance( DIS_SUPERSCRIPT, Categories[1]->GetValue(0) ); 1021 rFormat.SetDistance( DIS_SUBSCRIPT, Categories[1]->GetValue(1) ); 1022 rFormat.SetDistance( DIS_NUMERATOR, Categories[2]->GetValue(0) ); 1023 rFormat.SetDistance( DIS_DENOMINATOR, Categories[2]->GetValue(1) ); 1024 rFormat.SetDistance( DIS_FRACTION, Categories[3]->GetValue(0) ); 1025 rFormat.SetDistance( DIS_STROKEWIDTH, Categories[3]->GetValue(1) ); 1026 rFormat.SetDistance( DIS_UPPERLIMIT, Categories[4]->GetValue(0) ); 1027 rFormat.SetDistance( DIS_LOWERLIMIT, Categories[4]->GetValue(1) ); 1028 rFormat.SetDistance( DIS_BRACKETSIZE, Categories[5]->GetValue(0) ); 1029 rFormat.SetDistance( DIS_BRACKETSPACE, Categories[5]->GetValue(1) ); 1030 rFormat.SetDistance( DIS_MATRIXROW, Categories[6]->GetValue(0) ); 1031 rFormat.SetDistance( DIS_MATRIXCOL, Categories[6]->GetValue(1) ); 1032 rFormat.SetDistance( DIS_ORNAMENTSIZE, Categories[7]->GetValue(0) ); 1033 rFormat.SetDistance( DIS_ORNAMENTSPACE, Categories[7]->GetValue(1) ); 1034 rFormat.SetDistance( DIS_OPERATORSIZE, Categories[8]->GetValue(0) ); 1035 rFormat.SetDistance( DIS_OPERATORSPACE, Categories[8]->GetValue(1) ); 1036 rFormat.SetDistance( DIS_LEFTSPACE, Categories[9]->GetValue(0) ); 1037 rFormat.SetDistance( DIS_RIGHTSPACE, Categories[9]->GetValue(1) ); 1038 rFormat.SetDistance( DIS_TOPSPACE, Categories[9]->GetValue(2) ); 1039 rFormat.SetDistance( DIS_BOTTOMSPACE, Categories[9]->GetValue(3) ); 1040 rFormat.SetDistance( DIS_NORMALBRACKETSIZE, Categories[5]->GetValue(3) ); 1041 1042 rFormat.SetScaleNormalBrackets( bScaleAllBrackets ); 1043 1044 rFormat.RequestApplyChanges(); 1045 } 1046 1047 1048 /**************************************************************************/ 1049 1050 1051 IMPL_LINK( SmAlignDialog, DefaultButtonClickHdl, Button *, EMPTYARG /*pButton*/ ) 1052 { 1053 QueryBox *pQueryBox = new QueryBox(this, SmResId(RID_DEFAULTSAVEQUERY)); 1054 1055 if (pQueryBox->Execute() == RET_YES) 1056 { 1057 SmModule *pp = SM_MOD(); 1058 SmFormat aFmt( pp->GetConfig()->GetStandardFormat() ); 1059 WriteTo( aFmt ); 1060 pp->GetConfig()->SetStandardFormat( aFmt ); 1061 } 1062 1063 delete pQueryBox; 1064 return 0; 1065 } 1066 1067 1068 SmAlignDialog::SmAlignDialog(Window * pParent, sal_Bool bFreeRes) 1069 : ModalDialog(pParent, SmResId(RID_ALIGNDIALOG)), 1070 aLeft (this, SmResId(1)), 1071 aCenter (this, SmResId(2)), 1072 aRight (this, SmResId(3)), 1073 aFixedLine1 (this, SmResId(1)), 1074 aOKButton1 (this, SmResId(1)), 1075 aCancelButton1 (this, SmResId(1)), 1076 aDefaultButton (this, SmResId(1)) 1077 { 1078 if (bFreeRes) 1079 FreeResource(); 1080 1081 aDefaultButton.SetClickHdl(LINK(this, SmAlignDialog, DefaultButtonClickHdl)); 1082 } 1083 1084 1085 void SmAlignDialog::ReadFrom(const SmFormat &rFormat) 1086 { 1087 switch (rFormat.GetHorAlign()) 1088 { 1089 case AlignLeft: 1090 aLeft .Check(sal_True); 1091 aCenter.Check(sal_False); 1092 aRight .Check(sal_False); 1093 break; 1094 1095 case AlignCenter: 1096 aLeft .Check(sal_False); 1097 aCenter.Check(sal_True); 1098 aRight .Check(sal_False); 1099 break; 1100 1101 case AlignRight: 1102 aLeft .Check(sal_False); 1103 aCenter.Check(sal_False); 1104 aRight .Check(sal_True); 1105 break; 1106 } 1107 } 1108 1109 1110 void SmAlignDialog::WriteTo(SmFormat &rFormat) const 1111 { 1112 if (aLeft.IsChecked()) 1113 rFormat.SetHorAlign(AlignLeft); 1114 else if (aRight.IsChecked()) 1115 rFormat.SetHorAlign(AlignRight); 1116 else 1117 rFormat.SetHorAlign(AlignCenter); 1118 1119 rFormat.RequestApplyChanges(); 1120 } 1121 1122 1123 /**************************************************************************/ 1124 1125 1126 void SmShowSymbolSet::Paint(const Rectangle&) 1127 { 1128 Push(PUSH_MAPMODE); 1129 1130 // MapUnit einstellen für die 'nLen' berechnet wurde 1131 SetMapMode(MapMode(MAP_PIXEL)); 1132 1133 sal_uInt16 v = sal::static_int_cast< sal_uInt16 >((aVScrollBar.GetThumbPos() * nColumns)); 1134 size_t nSymbols = aSymbolSet.size(); 1135 1136 Color aTxtColor( GetTextColor() ); 1137 for (sal_uInt16 i = v; i < nSymbols ; i++) 1138 { 1139 SmSym aSymbol (*aSymbolSet[i]); 1140 Font aFont (aSymbol.GetFace()); 1141 aFont.SetAlign(ALIGN_TOP); 1142 1143 // etwas kleinere FontSize nehmen (als nLen) um etwas Luft zu haben 1144 // (hoffentlich auch genug für links und rechts!) 1145 aFont.SetSize(Size(0, nLen - (nLen / 3))); 1146 SetFont(aFont); 1147 // keep text color 1148 SetTextColor( aTxtColor ); 1149 1150 int nIV = i - v; 1151 sal_UCS4 cChar = aSymbol.GetCharacter(); 1152 String aText( OUString( &cChar, 1 ) ); 1153 Size aSize( GetTextWidth( aText ), GetTextHeight()); 1154 1155 DrawText(Point((nIV % nColumns) * nLen + (nLen - aSize.Width()) / 2, 1156 (nIV / nColumns) * nLen + (nLen - aSize.Height()) / 2), 1157 aText); 1158 } 1159 1160 if (nSelectSymbol != SYMBOL_NONE) 1161 { 1162 Invert(Rectangle(Point(((nSelectSymbol - v) % nColumns) * nLen, 1163 ((nSelectSymbol - v) / nColumns) * nLen), 1164 Size(nLen, nLen))); 1165 } 1166 1167 Pop(); 1168 } 1169 1170 1171 void SmShowSymbolSet::MouseButtonDown(const MouseEvent& rMEvt) 1172 { 1173 GrabFocus(); 1174 1175 if (rMEvt.IsLeft() && Rectangle(Point(0, 0), aOutputSize).IsInside(rMEvt.GetPosPixel())) 1176 { 1177 long nPos = (rMEvt.GetPosPixel().Y() / nLen) * nColumns + (rMEvt.GetPosPixel().X() / nLen) + 1178 aVScrollBar.GetThumbPos() * nColumns; 1179 SelectSymbol( sal::static_int_cast< sal_uInt16 >(nPos) ); 1180 1181 aSelectHdlLink.Call(this); 1182 1183 if (rMEvt.GetClicks() > 1) aDblClickHdlLink.Call(this); 1184 } 1185 else Control::MouseButtonDown (rMEvt); 1186 } 1187 1188 1189 void SmShowSymbolSet::KeyInput(const KeyEvent& rKEvt) 1190 { 1191 sal_uInt16 n = nSelectSymbol; 1192 1193 if (n != SYMBOL_NONE) 1194 { 1195 switch (rKEvt.GetKeyCode().GetCode()) 1196 { 1197 case KEY_DOWN: n = n + nColumns; break; 1198 case KEY_UP: n = n - nColumns; break; 1199 case KEY_LEFT: n -= 1; break; 1200 case KEY_RIGHT: n += 1; break; 1201 case KEY_HOME: n = 0; break; 1202 case KEY_END: n = static_cast< sal_uInt16 >(aSymbolSet.size() - 1); break; 1203 case KEY_PAGEUP: n -= nColumns * nRows; break; 1204 case KEY_PAGEDOWN: n += nColumns * nRows; break; 1205 1206 default: 1207 Control::KeyInput(rKEvt); 1208 return; 1209 } 1210 } 1211 else 1212 n = 0; 1213 1214 if (n >= aSymbolSet.size()) 1215 n = nSelectSymbol; 1216 1217 // adjust scrollbar 1218 if ((n < (sal_uInt16) (aVScrollBar.GetThumbPos() * nColumns)) || 1219 (n >= (sal_uInt16) ((aVScrollBar.GetThumbPos() + nRows) * nColumns))) 1220 { 1221 aVScrollBar.SetThumbPos(n / nColumns); 1222 Invalidate(); 1223 Update(); 1224 } 1225 1226 SelectSymbol(n); 1227 aSelectHdlLink.Call(this); 1228 } 1229 1230 1231 SmShowSymbolSet::SmShowSymbolSet(Window *pParent, const ResId& rResId) : 1232 Control(pParent, rResId), 1233 aVScrollBar(this, WinBits(WB_VSCROLL)) 1234 { 1235 nSelectSymbol = SYMBOL_NONE; 1236 1237 aOutputSize = GetOutputSizePixel(); 1238 long nScrollBarWidth = aVScrollBar.GetSizePixel().Width(), 1239 nUseableWidth = aOutputSize.Width() - nScrollBarWidth; 1240 1241 // Hoehe von 16pt in Pixeln (passend zu 'aOutputSize') 1242 nLen = (sal_uInt16) LogicToPixel(Size(0, 16), MapMode(MAP_POINT)).Height(); 1243 1244 nColumns = sal::static_int_cast< sal_uInt16 >(nUseableWidth / nLen); 1245 if (nColumns > 2 && nColumns % 2 != 0) 1246 nColumns--; 1247 nRows = sal::static_int_cast< sal_uInt16 >(aOutputSize.Height() / nLen); 1248 #if OSL_DEBUG_LEVEL > 1 1249 DBG_ASSERT(nColumns > 0, "Sm : keine Spalten"); 1250 DBG_ASSERT(nRows > 0, "Sm : keine Zeilen"); 1251 #endif 1252 1253 // genau passend machen 1254 aOutputSize.Width() = nColumns * nLen; 1255 aOutputSize.Height() = nRows * nLen; 1256 1257 aVScrollBar.SetPosSizePixel(Point(aOutputSize.Width() + 1, -1), 1258 Size(nScrollBarWidth, aOutputSize.Height() + 2)); 1259 aVScrollBar.Enable(sal_False); 1260 aVScrollBar.Show(); 1261 aVScrollBar.SetScrollHdl(LINK(this, SmShowSymbolSet, ScrollHdl)); 1262 1263 Size WindowSize (aOutputSize); 1264 WindowSize.Width() += nScrollBarWidth; 1265 SetOutputSizePixel(WindowSize); 1266 1267 } 1268 1269 1270 void SmShowSymbolSet::SetSymbolSet(const SymbolPtrVec_t& rSymbolSet) 1271 { 1272 aSymbolSet = rSymbolSet; 1273 1274 if (static_cast< sal_uInt16 >(aSymbolSet.size()) > (nColumns * nRows)) 1275 { 1276 aVScrollBar.SetRange(Range(0, ((aSymbolSet.size() + (nColumns - 1)) / nColumns) - nRows)); 1277 aVScrollBar.Enable(sal_True); 1278 } 1279 else 1280 { 1281 aVScrollBar.SetRange(Range(0,0)); 1282 aVScrollBar.Enable (sal_False); 1283 } 1284 1285 Invalidate(); 1286 } 1287 1288 1289 void SmShowSymbolSet::SelectSymbol(sal_uInt16 nSymbol) 1290 { 1291 int v = (int) (aVScrollBar.GetThumbPos() * nColumns); 1292 1293 if (nSelectSymbol != SYMBOL_NONE) 1294 Invalidate(Rectangle(Point(((nSelectSymbol - v) % nColumns) * nLen, 1295 ((nSelectSymbol - v) / nColumns) * nLen), 1296 Size(nLen, nLen))); 1297 1298 if (nSymbol < aSymbolSet.size()) 1299 nSelectSymbol = nSymbol; 1300 1301 if (aSymbolSet.size() == 0) 1302 nSelectSymbol = SYMBOL_NONE; 1303 1304 if (nSelectSymbol != SYMBOL_NONE) 1305 Invalidate(Rectangle(Point(((nSelectSymbol - v) % nColumns) * nLen, 1306 ((nSelectSymbol - v) / nColumns) * nLen), 1307 Size(nLen, nLen))); 1308 1309 Update(); 1310 } 1311 1312 1313 IMPL_LINK( SmShowSymbolSet, ScrollHdl, ScrollBar*, EMPTYARG /*pScrollBar*/) 1314 { 1315 Invalidate(); 1316 return 0; 1317 } 1318 1319 1320 void SmShowSymbol::Paint(const Rectangle &rRect) 1321 { 1322 Control::Paint( rRect ); 1323 1324 const XubString &rText = GetText(); 1325 Size aTextSize(GetTextWidth(rText), GetTextHeight()); 1326 1327 DrawText(Point((GetOutputSize().Width() - aTextSize.Width()) / 2, 1328 (GetOutputSize().Height() * 7/10)), rText); 1329 } 1330 1331 1332 void SmShowSymbol::MouseButtonDown(const MouseEvent& rMEvt) 1333 { 1334 if (rMEvt.GetClicks() > 1) 1335 aDblClickHdlLink.Call(this); 1336 else 1337 Control::MouseButtonDown (rMEvt); 1338 } 1339 1340 1341 void SmShowSymbol::SetSymbol(const SmSym *pSymbol) 1342 { 1343 if (pSymbol) 1344 { 1345 Font aFont (pSymbol->GetFace()); 1346 aFont.SetSize(Size(0, GetOutputSize().Height() - GetOutputSize().Height() / 3)); 1347 aFont.SetAlign(ALIGN_BASELINE); 1348 SetFont(aFont); 1349 1350 sal_UCS4 cChar = pSymbol->GetCharacter(); 1351 String aText( OUString( &cChar, 1 ) ); 1352 SetText( aText ); 1353 } 1354 1355 // 'Invalidate' fuellt den background mit der background-Farbe. 1356 // Falls der NULL pointer uebergeben wurde reicht dies also zum loeschen 1357 // der Anzeige 1358 Invalidate(); 1359 } 1360 1361 1362 1363 void SmSymbolDialog::FillSymbolSets(sal_Bool bDeleteText) 1364 // füllt die Einträge der möglichen 'SymbolsSet's im Dialog mit den 1365 // aktuellen Werten des SymbolSet Managers, selektiert aber keinen. 1366 { 1367 aSymbolSets.Clear(); 1368 if (bDeleteText) 1369 aSymbolSets.SetNoSelection(); 1370 1371 std::set< String > aSymbolSetNames( rSymbolMgr.GetSymbolSetNames() ); 1372 std::set< String >::const_iterator aIt( aSymbolSetNames.begin() ); 1373 for ( ; aIt != aSymbolSetNames.end(); ++aIt) 1374 aSymbolSets.InsertEntry( *aIt ); 1375 } 1376 1377 1378 IMPL_LINK( SmSymbolDialog, SymbolSetChangeHdl, ListBox *, EMPTYARG pListBox ) 1379 { 1380 (void) pListBox; 1381 #if OSL_DEBUG_LEVEL > 1 1382 DBG_ASSERT(pListBox == &aSymbolSets, "Sm : Wrong argument"); 1383 #endif 1384 1385 SelectSymbolSet(aSymbolSets.GetSelectEntry()); 1386 return 0; 1387 } 1388 1389 1390 IMPL_LINK( SmSymbolDialog, SymbolChangeHdl, SmShowSymbolSet *, EMPTYARG pShowSymbolSet ) 1391 { 1392 (void) pShowSymbolSet; 1393 #if OSL_DEBUG_LEVEL > 1 1394 DBG_ASSERT(pShowSymbolSet == &aSymbolSetDisplay, "Sm : Wrong argument"); 1395 #endif 1396 1397 SelectSymbol(aSymbolSetDisplay.GetSelectSymbol()); 1398 return 0; 1399 } 1400 1401 IMPL_LINK( SmSymbolDialog, EditClickHdl, Button *, EMPTYARG pButton ) 1402 { 1403 (void) pButton; 1404 #if OSL_DEBUG_LEVEL > 1 1405 DBG_ASSERT(pButton == &aEditBtn, "Sm : Wrong argument"); 1406 #endif 1407 1408 SmSymDefineDialog *pDialog = new SmSymDefineDialog(this, pFontListDev, rSymbolMgr); 1409 1410 // aktuelles Symbol und SymbolSet am neuen Dialog setzen 1411 const XubString aSymSetName (aSymbolSets.GetSelectEntry()), 1412 aSymName (aSymbolName.GetText()); 1413 pDialog->SelectOldSymbolSet(aSymSetName); 1414 pDialog->SelectOldSymbol(aSymName); 1415 pDialog->SelectSymbolSet(aSymSetName); 1416 pDialog->SelectSymbol(aSymName); 1417 1418 // altes SymbolSet merken 1419 XubString aOldSymbolSet (aSymbolSets.GetSelectEntry()); 1420 1421 sal_uInt16 nSymPos = GetSelectedSymbol(); 1422 1423 // Dialog an evtl geänderte Daten des SymbolSet Manager anpassen 1424 if (pDialog->Execute() == RET_OK && rSymbolMgr.IsModified()) 1425 { 1426 rSymbolMgr.Save(); 1427 FillSymbolSets(); 1428 } 1429 1430 // wenn das alte SymbolSet nicht mehr existiert zum ersten gehen 1431 // (soweit eines vorhanden ist) 1432 if (!SelectSymbolSet(aOldSymbolSet) && aSymbolSets.GetEntryCount() > 0) 1433 SelectSymbolSet(aSymbolSets.GetEntry(0)); 1434 else 1435 { 1436 // just update display of current symbol set 1437 DBG_ASSERT( aSymSetName == aSymSetName, "unexpected change in symbol set name" ); 1438 aSymbolSet = rSymbolMgr.GetSymbolSet( aSymbolSetName ); 1439 aSymbolSetDisplay.SetSymbolSet( aSymbolSet ); 1440 } 1441 1442 if (nSymPos >= aSymbolSet.size()) 1443 nSymPos = static_cast< sal_uInt16 >(aSymbolSet.size()) - 1; 1444 SelectSymbol( nSymPos ); 1445 1446 delete pDialog; 1447 return 0; 1448 } 1449 1450 1451 IMPL_LINK( SmSymbolDialog, SymbolDblClickHdl, SmShowSymbolSet *, EMPTYARG pShowSymbolSet ) 1452 { 1453 (void) pShowSymbolSet; 1454 #if OSL_DEBUG_LEVEL > 1 1455 DBG_ASSERT(pShowSymbolSet == &aSymbolSetDisplay, "Sm : Wrong argument"); 1456 #endif 1457 1458 GetClickHdl(&aGetBtn); 1459 EndDialog(RET_OK); 1460 return 0; 1461 } 1462 1463 1464 IMPL_LINK( SmSymbolDialog, GetClickHdl, Button *, EMPTYARG pButton ) 1465 { 1466 (void) pButton; 1467 #if OSL_DEBUG_LEVEL > 1 1468 DBG_ASSERT(pButton == &aGetBtn, "Sm : Wrong button"); 1469 #endif 1470 1471 const SmSym *pSym = GetSymbol(); 1472 if (pSym) 1473 { 1474 String aText ('%'); 1475 aText += pSym->GetName(); 1476 aText += (sal_Unicode)' '; 1477 1478 rViewSh.GetViewFrame()->GetDispatcher()->Execute( 1479 SID_INSERTTEXT, SFX_CALLMODE_STANDARD, 1480 new SfxStringItem(SID_INSERTTEXT, aText), 0L); 1481 } 1482 1483 return 0; 1484 } 1485 1486 1487 IMPL_LINK_INLINE_START( SmSymbolDialog, CloseClickHdl, Button *, EMPTYARG pButton ) 1488 { 1489 (void) pButton; 1490 #if OSL_DEBUG_LEVEL > 1 1491 DBG_ASSERT(pButton == &aCloseBtn, "Sm : Wrong button"); 1492 #endif 1493 1494 EndDialog(sal_True); 1495 return 0; 1496 } 1497 IMPL_LINK_INLINE_END( SmSymbolDialog, CloseClickHdl, Button *, pButton ) 1498 1499 1500 SmSymbolDialog::SmSymbolDialog(Window *pParent, OutputDevice *pFntListDevice, 1501 SmSymbolManager &rMgr, SmViewShell &rViewShell, sal_Bool bFreeRes) : 1502 ModalDialog (pParent, SmResId(RID_SYMBOLDIALOG)), 1503 aSymbolSetText (this, SmResId(1)), 1504 aSymbolSets (this, SmResId(1)), 1505 aSymbolSetDisplay (this, SmResId(1)), 1506 aSymbolName (this, SmResId(2)), 1507 aSymbolDisplay (this, SmResId(2)), 1508 aGetBtn (this, SmResId(2)), 1509 aCloseBtn (this, SmResId(3)), 1510 aEditBtn (this, SmResId(1)), 1511 rViewSh (rViewShell), 1512 rSymbolMgr (rMgr), 1513 pFontListDev (pFntListDevice) 1514 { 1515 if (bFreeRes) 1516 FreeResource(); 1517 1518 aSymbolSetName = String(); 1519 aSymbolSet.clear(); 1520 FillSymbolSets(); 1521 if (aSymbolSets.GetEntryCount() > 0) 1522 SelectSymbolSet(aSymbolSets.GetEntry(0)); 1523 1524 InitColor_Impl(); 1525 1526 // preview like controls should have a 2D look 1527 aSymbolDisplay.SetBorderStyle( WINDOW_BORDER_MONO ); 1528 1529 aSymbolSets .SetSelectHdl (LINK(this, SmSymbolDialog, SymbolSetChangeHdl)); 1530 aSymbolSetDisplay.SetSelectHdl (LINK(this, SmSymbolDialog, SymbolChangeHdl)); 1531 aSymbolSetDisplay.SetDblClickHdl(LINK(this, SmSymbolDialog, SymbolDblClickHdl)); 1532 aSymbolDisplay .SetDblClickHdl(LINK(this, SmSymbolDialog, SymbolDblClickHdl)); 1533 aCloseBtn .SetClickHdl (LINK(this, SmSymbolDialog, CloseClickHdl)); 1534 aEditBtn .SetClickHdl (LINK(this, SmSymbolDialog, EditClickHdl)); 1535 aGetBtn .SetClickHdl (LINK(this, SmSymbolDialog, GetClickHdl)); 1536 } 1537 1538 1539 SmSymbolDialog::~SmSymbolDialog() 1540 { 1541 } 1542 1543 1544 void SmSymbolDialog::InitColor_Impl() 1545 { 1546 #if OSL_DEBUG_LEVEL > 1 1547 Color aBC( GetDisplayBackground().GetColor() ); 1548 #endif 1549 ColorData nBgCol = COL_WHITE, 1550 nTxtCol = COL_BLACK; 1551 const StyleSettings &rS = GetSettings().GetStyleSettings(); 1552 if (rS.GetHighContrastMode()) 1553 { 1554 nBgCol = rS.GetFieldColor().GetColor(); 1555 nTxtCol = rS.GetFieldTextColor().GetColor(); 1556 } 1557 1558 Color aTmpColor( nBgCol ); 1559 Wallpaper aWall( aTmpColor ); 1560 Color aTxtColor( nTxtCol ); 1561 aSymbolDisplay .SetBackground( aWall ); 1562 aSymbolDisplay .SetTextColor( aTxtColor ); 1563 aSymbolSetDisplay.SetBackground( aWall ); 1564 aSymbolSetDisplay.SetTextColor( aTxtColor ); 1565 } 1566 1567 1568 void SmSymbolDialog::DataChanged( const DataChangedEvent& rDCEvt ) 1569 { 1570 if ( rDCEvt.GetType() == DATACHANGED_SETTINGS && 1571 (rDCEvt.GetFlags() & SETTINGS_STYLE) ) 1572 InitColor_Impl(); 1573 1574 ModalDialog::DataChanged( rDCEvt ); 1575 } 1576 1577 1578 sal_Bool SmSymbolDialog::SelectSymbolSet(const XubString &rSymbolSetName) 1579 { 1580 sal_Bool bRet = sal_False; 1581 sal_uInt16 nPos = aSymbolSets.GetEntryPos(rSymbolSetName); 1582 1583 aSymbolSetName = String(); 1584 aSymbolSet.clear(); 1585 if (nPos != LISTBOX_ENTRY_NOTFOUND) 1586 { 1587 aSymbolSets.SelectEntryPos(nPos); 1588 1589 aSymbolSetName = rSymbolSetName; 1590 aSymbolSet = rSymbolMgr.GetSymbolSet( aSymbolSetName ); 1591 1592 // sort symbols by Unicode position (useful for displaying Greek characters alphabetically) 1593 std::sort( aSymbolSet.begin(), aSymbolSet.end(), lt_SmSymPtr() ); 1594 1595 aSymbolSetDisplay.SetSymbolSet( aSymbolSet ); 1596 if (aSymbolSet.size() > 0) 1597 SelectSymbol(0); 1598 1599 bRet = sal_True; 1600 } 1601 else 1602 aSymbolSets.SetNoSelection(); 1603 1604 return bRet; 1605 } 1606 1607 1608 void SmSymbolDialog::SelectSymbol(sal_uInt16 nSymbolNo) 1609 { 1610 const SmSym *pSym = NULL; 1611 if (aSymbolSetName.Len() > 0 && nSymbolNo < static_cast< sal_uInt16 >(aSymbolSet.size())) 1612 pSym = aSymbolSet[ nSymbolNo ]; 1613 1614 aSymbolSetDisplay.SelectSymbol(nSymbolNo); 1615 aSymbolDisplay.SetSymbol(pSym); 1616 aSymbolName.SetText(pSym ? pSym->GetName() : XubString()); 1617 } 1618 1619 1620 const SmSym * SmSymbolDialog::GetSymbol() const 1621 { 1622 sal_uInt16 nSymbolNo = aSymbolSetDisplay.GetSelectSymbol(); 1623 bool bValid = aSymbolSetName.Len() > 0 && nSymbolNo < static_cast< sal_uInt16 >(aSymbolSet.size()); 1624 return bValid ? aSymbolSet[ nSymbolNo ] : NULL; 1625 } 1626 1627 1628 1629 1630 void SmShowChar::Paint(const Rectangle &rRect) 1631 { 1632 Control::Paint( rRect ); 1633 1634 OUString aText( GetText() ); 1635 if (aText.getLength() > 0) 1636 { 1637 #if OSL_DEBUG_LEVEL > 1 1638 sal_Int32 nPos = 0; 1639 sal_UCS4 cChar = aText.iterateCodePoints( &nPos ); 1640 (void) cChar; 1641 #endif 1642 Size aTextSize(GetTextWidth(aText), GetTextHeight()); 1643 1644 DrawText(Point((GetOutputSize().Width() - aTextSize.Width()) / 2, 1645 (GetOutputSize().Height() * 7/10)), aText); 1646 } 1647 } 1648 1649 1650 void SmShowChar::SetSymbol( const SmSym *pSym ) 1651 { 1652 if (pSym) 1653 SetSymbol( pSym->GetCharacter(), pSym->GetFace() ); 1654 } 1655 1656 1657 void SmShowChar::SetSymbol( sal_UCS4 cChar, const Font &rFont ) 1658 { 1659 Font aFont( rFont ); 1660 aFont.SetSize( Size(0, GetOutputSize().Height() - GetOutputSize().Height() / 3) ); 1661 aFont.SetAlign(ALIGN_BASELINE); 1662 SetFont(aFont); 1663 1664 String aText( OUString( &cChar, 1) ); 1665 SetText( aText ); 1666 1667 Invalidate(); 1668 } 1669 1670 1671 1672 void SmSymDefineDialog::FillSymbols(ComboBox &rComboBox, sal_Bool bDeleteText) 1673 { 1674 #if OSL_DEBUG_LEVEL > 1 1675 DBG_ASSERT(&rComboBox == &aOldSymbols || &rComboBox == &aSymbols, 1676 "Sm : Wrong comboBox"); 1677 #endif 1678 1679 rComboBox.Clear(); 1680 if (bDeleteText) 1681 rComboBox.SetText(XubString()); 1682 1683 ComboBox &rBox = &rComboBox == &aOldSymbols ? aOldSymbolSets : aSymbolSets; 1684 SymbolPtrVec_t aSymSet( aSymbolMgrCopy.GetSymbolSet( rBox.GetText() ) ); 1685 for (size_t i = 0; i < aSymSet.size(); ++i) 1686 rComboBox.InsertEntry( aSymSet[i]->GetName() ); 1687 } 1688 1689 1690 void SmSymDefineDialog::FillSymbolSets(ComboBox &rComboBox, sal_Bool bDeleteText) 1691 { 1692 #if OSL_DEBUG_LEVEL > 1 1693 DBG_ASSERT(&rComboBox == &aOldSymbolSets || &rComboBox == &aSymbolSets, 1694 "Sm : Wrong comboBox"); 1695 #endif 1696 1697 rComboBox.Clear(); 1698 if (bDeleteText) 1699 rComboBox.SetText(XubString()); 1700 1701 const std::set< String > aSymbolSetNames( aSymbolMgrCopy.GetSymbolSetNames() ); 1702 std::set< String >::const_iterator aIt( aSymbolSetNames.begin() ); 1703 for ( ; aIt != aSymbolSetNames.end(); ++aIt) 1704 rComboBox.InsertEntry( *aIt ); 1705 } 1706 1707 1708 void SmSymDefineDialog::FillFonts(sal_Bool bDelete) 1709 { 1710 aFonts.Clear(); 1711 if (bDelete) 1712 aFonts.SetNoSelection(); 1713 1714 // alle Fonts der 'FontList' in die Fontliste aufnehmen 1715 // von denen mit gleichen Namen jedoch nur einen (denn der Style wird 1716 // ueber die 'FontStyleBox' gewaehlt und nicht auch noch hier) 1717 if (pFontList) 1718 { 1719 sal_uInt16 nCount = pFontList->GetFontNameCount(); 1720 for (sal_uInt16 i = 0; i < nCount; i++) 1721 aFonts.InsertEntry( pFontList->GetFontName(i).GetName() ); 1722 } 1723 } 1724 1725 1726 void SmSymDefineDialog::FillStyles(sal_Bool bDeleteText) 1727 { 1728 aStyles.Clear(); 1729 if (bDeleteText) 1730 aStyles.SetText(XubString()); 1731 1732 XubString aText (aFonts.GetSelectEntry()); 1733 if (aText.Len() != 0) 1734 { 1735 //aStyles.Fill(aText, &aFontList); 1736 // eigene StyleName's verwenden 1737 const SmFontStyles &rStyles = GetFontStyles(); 1738 for (sal_uInt16 i = 0; i < rStyles.GetCount(); i++) 1739 aStyles.InsertEntry( rStyles.GetStyleName(i) ); 1740 1741 #if OSL_DEBUG_LEVEL > 1 1742 DBG_ASSERT(aStyles.GetEntryCount() > 0, "Sm : keine Styles vorhanden"); 1743 #endif 1744 aStyles.SetText( aStyles.GetEntry(0) ); 1745 } 1746 } 1747 1748 1749 SmSym * SmSymDefineDialog::GetSymbol(const ComboBox &rComboBox) 1750 { 1751 #if OSL_DEBUG_LEVEL > 1 1752 DBG_ASSERT(&rComboBox == &aOldSymbols || &rComboBox == &aSymbols, 1753 "Sm : Wrong comboBox"); 1754 #endif 1755 return aSymbolMgrCopy.GetSymbolByName(rComboBox.GetText()); 1756 } 1757 1758 1759 IMPL_LINK( SmSymDefineDialog, OldSymbolChangeHdl, ComboBox *, EMPTYARG pComboBox ) 1760 { 1761 (void) pComboBox; 1762 #if OSL_DEBUG_LEVEL > 1 1763 DBG_ASSERT(pComboBox == &aOldSymbols, "Sm : Wrong argument"); 1764 #endif 1765 SelectSymbol(aOldSymbols, aOldSymbols.GetText(), sal_False); 1766 return 0; 1767 } 1768 1769 1770 IMPL_LINK( SmSymDefineDialog, OldSymbolSetChangeHdl, ComboBox *, EMPTYARG pComboBox ) 1771 { 1772 (void) pComboBox; 1773 #if OSL_DEBUG_LEVEL > 1 1774 DBG_ASSERT(pComboBox == &aOldSymbolSets, "Sm : Wrong argument"); 1775 #endif 1776 SelectSymbolSet(aOldSymbolSets, aOldSymbolSets.GetText(), sal_False); 1777 return 0; 1778 } 1779 1780 1781 IMPL_LINK( SmSymDefineDialog, ModifyHdl, ComboBox *, pComboBox ) 1782 { 1783 // merken der Cursorposition zum wiederherstellen derselben 1784 Selection aSelection (pComboBox->GetSelection()); 1785 1786 if (pComboBox == &aSymbols) 1787 SelectSymbol(aSymbols, aSymbols.GetText(), sal_False); 1788 else if (pComboBox == &aSymbolSets) 1789 SelectSymbolSet(aSymbolSets, aSymbolSets.GetText(), sal_False); 1790 else if (pComboBox == &aOldSymbols) 1791 // nur Namen aus der Liste erlauben 1792 SelectSymbol(aOldSymbols, aOldSymbols.GetText(), sal_True); 1793 else if (pComboBox == &aOldSymbolSets) 1794 // nur Namen aus der Liste erlauben 1795 SelectSymbolSet(aOldSymbolSets, aOldSymbolSets.GetText(), sal_True); 1796 else if (pComboBox == &aStyles) 1797 // nur Namen aus der Liste erlauben (ist hier eh immer der Fall) 1798 SelectStyle(aStyles.GetText(), sal_True); 1799 else 1800 { 1801 #if OSL_DEBUG_LEVEL > 1 1802 DBG_ASSERT(0, "Sm : Wrong comboBox argument"); 1803 #endif 1804 } 1805 1806 pComboBox->SetSelection(aSelection); 1807 1808 UpdateButtons(); 1809 1810 return 0; 1811 } 1812 1813 1814 IMPL_LINK( SmSymDefineDialog, FontChangeHdl, ListBox *, EMPTYARG pListBox ) 1815 { 1816 (void) pListBox; 1817 #if OSL_DEBUG_LEVEL > 1 1818 DBG_ASSERT(pListBox == &aFonts, "Sm : Wrong argument"); 1819 #endif 1820 1821 SelectFont(aFonts.GetSelectEntry()); 1822 return 0; 1823 } 1824 1825 1826 IMPL_LINK( SmSymDefineDialog, SubsetChangeHdl, ListBox *, EMPTYARG pListBox ) 1827 { 1828 (void) pListBox; 1829 sal_uInt16 nPos = aFontsSubsetLB.GetSelectEntryPos(); 1830 if (LISTBOX_ENTRY_NOTFOUND != nPos) 1831 { 1832 const Subset* pSubset = reinterpret_cast<const Subset*> (aFontsSubsetLB.GetEntryData( nPos )); 1833 if (pSubset) 1834 { 1835 aCharsetDisplay.SelectCharacter( pSubset->GetRangeMin() ); 1836 } 1837 } 1838 return 0; 1839 } 1840 1841 1842 IMPL_LINK( SmSymDefineDialog, StyleChangeHdl, ComboBox *, EMPTYARG pComboBox ) 1843 { 1844 (void) pComboBox; 1845 #if OSL_DEBUG_LEVEL > 1 1846 DBG_ASSERT(pComboBox == &aStyles, "Sm : Wrong argument"); 1847 #endif 1848 1849 SelectStyle(aStyles.GetText()); 1850 return 0; 1851 } 1852 1853 1854 IMPL_LINK( SmSymDefineDialog, CharHighlightHdl, Control *, EMPTYARG ) 1855 { 1856 sal_UCS4 cChar = aCharsetDisplay.GetSelectCharacter(); 1857 1858 #if OSL_DEBUG_LEVEL > 1 1859 DBG_ASSERT( pSubsetMap, "SubsetMap missing" ); 1860 #endif 1861 if (pSubsetMap) 1862 { 1863 const Subset* pSubset = pSubsetMap->GetSubsetByUnicode( cChar ); 1864 if (pSubset) 1865 aFontsSubsetLB.SelectEntry( pSubset->GetName() ); 1866 else 1867 aFontsSubsetLB.SetNoSelection(); 1868 } 1869 1870 aSymbolDisplay.SetSymbol( cChar, aCharsetDisplay.GetFont() ); 1871 1872 UpdateButtons(); 1873 1874 // display Unicode position as symbol name while iterating over characters 1875 const String aHex( String::CreateFromInt64( cChar, 16 ).ToUpperAscii() ); 1876 const String aPattern( A2OU( aHex.Len() > 4 ? "Ux000000" : "Ux0000" ) ); 1877 String aUnicodePos( aPattern.Copy( 0, aPattern.Len() - aHex.Len() ) ); 1878 aUnicodePos += aHex; 1879 aSymbols.SetText( aUnicodePos ); 1880 aSymbolName.SetText( aUnicodePos ); 1881 1882 return 0; 1883 } 1884 1885 1886 IMPL_LINK( SmSymDefineDialog, AddClickHdl, Button *, EMPTYARG pButton ) 1887 { 1888 (void) pButton; 1889 #if OSL_DEBUG_LEVEL > 1 1890 DBG_ASSERT(pButton == &aAddBtn, "Sm : Wrong argument"); 1891 DBG_ASSERT(aAddBtn.IsEnabled(), "Sm : Voraussetzungen erfüllt?"); 1892 #endif 1893 1894 // add symbol 1895 const SmSym aNewSymbol( aSymbols.GetText(), aCharsetDisplay.GetFont(), 1896 aCharsetDisplay.GetSelectCharacter(), aSymbolSets.GetText() ); 1897 //DBG_ASSERT( aSymbolMgrCopy.GetSymbolByName(aTmpSymbolName) == NULL, "symbol already exists" ); 1898 aSymbolMgrCopy.AddOrReplaceSymbol( aNewSymbol ); 1899 1900 // update display of new symbol 1901 aSymbolDisplay.SetSymbol( &aNewSymbol ); 1902 aSymbolName.SetText( aNewSymbol.GetName() ); 1903 aSymbolSetName.SetText( aNewSymbol.GetSymbolSetName() ); 1904 1905 // update list box entries 1906 FillSymbolSets(aOldSymbolSets, sal_False); 1907 FillSymbolSets(aSymbolSets, sal_False); 1908 FillSymbols(aOldSymbols ,sal_False); 1909 FillSymbols(aSymbols ,sal_False); 1910 1911 UpdateButtons(); 1912 1913 return 0; 1914 } 1915 1916 1917 IMPL_LINK( SmSymDefineDialog, ChangeClickHdl, Button *, EMPTYARG pButton ) 1918 { 1919 (void) pButton; 1920 #if OSL_DEBUG_LEVEL > 1 1921 DBG_ASSERT(pButton == &aChangeBtn, "Sm : Wrong argument"); 1922 DBG_ASSERT(aChangeBtn.IsEnabled(), "Sm : Voraussetzungen erfüllt?"); 1923 #endif 1924 1925 // get new Symbol to use 1926 //! get font from symbol-disp lay since charset-display does not keep 1927 //! the bold attribute. 1928 const SmSym aNewSymbol( aSymbols.GetText(), aCharsetDisplay.GetFont(), 1929 aCharsetDisplay.GetSelectCharacter(), aSymbolSets.GetText() ); 1930 1931 // remove old symbol if the name was changed then add new one 1932 // const bool bSetNameChanged = aOldSymbolSets.GetText() != aSymbolSets.GetText(); 1933 const bool bNameChanged = aOldSymbols.GetText() != aSymbols.GetText(); 1934 if (bNameChanged) 1935 aSymbolMgrCopy.RemoveSymbol( aOldSymbols.GetText() ); 1936 aSymbolMgrCopy.AddOrReplaceSymbol( aNewSymbol, true ); 1937 1938 // clear display for original symbol if necessary 1939 if (bNameChanged) 1940 SetOrigSymbol(NULL, XubString()); 1941 1942 // update display of new symbol 1943 aSymbolDisplay.SetSymbol( &aNewSymbol ); 1944 aSymbolName.SetText( aNewSymbol.GetName() ); 1945 aSymbolSetName.SetText( aNewSymbol.GetSymbolSetName() ); 1946 1947 // update list box entries 1948 FillSymbolSets(aOldSymbolSets, sal_False); 1949 FillSymbolSets(aSymbolSets, sal_False); 1950 FillSymbols(aOldSymbols ,sal_False); 1951 FillSymbols(aSymbols ,sal_False); 1952 1953 UpdateButtons(); 1954 1955 return 0; 1956 } 1957 1958 1959 IMPL_LINK( SmSymDefineDialog, DeleteClickHdl, Button *, EMPTYARG pButton ) 1960 { 1961 (void) pButton; 1962 #if OSL_DEBUG_LEVEL > 1 1963 DBG_ASSERT(pButton == &aDeleteBtn, "Sm : Wrong argument"); 1964 DBG_ASSERT(aDeleteBtn.IsEnabled(), "Sm : Voraussetzungen erfüllt?"); 1965 #endif 1966 1967 if (pOrigSymbol) 1968 { 1969 aSymbolMgrCopy.RemoveSymbol( pOrigSymbol->GetName() ); 1970 1971 // clear display for original symbol 1972 SetOrigSymbol(NULL, XubString()); 1973 1974 // update list box entries 1975 FillSymbolSets(aOldSymbolSets, sal_False); 1976 FillSymbolSets(aSymbolSets, sal_False); 1977 FillSymbols(aOldSymbols ,sal_False); 1978 FillSymbols(aSymbols ,sal_False); 1979 } 1980 1981 UpdateButtons(); 1982 1983 return 0; 1984 } 1985 1986 1987 void SmSymDefineDialog::UpdateButtons() 1988 { 1989 sal_Bool bAdd = sal_False, 1990 bChange = sal_False, 1991 bDelete = sal_False, 1992 bEqual; 1993 XubString aTmpSymbolName (aSymbols.GetText()), 1994 aTmpSymbolSetName (aSymbolSets.GetText()); 1995 1996 if (aTmpSymbolName.Len() > 0 && aTmpSymbolSetName.Len() > 0) 1997 { 1998 // alle Einstellungen gleich? 1999 //! (Font-, Style- und SymbolSet Name werden nicht case sensitiv verglichen) 2000 bEqual = pOrigSymbol 2001 && aTmpSymbolSetName.EqualsIgnoreCaseAscii(aOldSymbolSetName.GetText()) 2002 && aTmpSymbolName.Equals(pOrigSymbol->GetName()) 2003 && aFonts.GetSelectEntry().EqualsIgnoreCaseAscii( 2004 pOrigSymbol->GetFace().GetName()) 2005 && aStyles.GetText().EqualsIgnoreCaseAscii( 2006 GetFontStyles().GetStyleName(pOrigSymbol->GetFace())) 2007 && aCharsetDisplay.GetSelectCharacter() == pOrigSymbol->GetCharacter(); 2008 2009 // hinzufuegen nur wenn es noch kein Symbol desgleichen Namens gibt 2010 bAdd = aSymbolMgrCopy.GetSymbolByName(aTmpSymbolName) == NULL; 2011 2012 // loeschen nur wenn alle Einstellungen gleich sind 2013 bDelete = pOrigSymbol != NULL; 2014 2015 // aendern wenn bei gleichem Namen mindestens eine Einstellung anders ist 2016 // oder wenn es noch kein Symbol des neuen Namens gibt (wuerde implizites 2017 // loeschen des bereits vorhandenen Symbols erfordern) 2018 // sal_Bool bEqualName = pOrigSymbol && aTmpSymbolName == pOrigSymbol->GetName(); 2019 // bChange = pOrigSymbol && ( (bEqualName && !bEqual) || (!bEqualName && bAdd) ); 2020 2021 // aendern nur falls altes Symbol vorhanden und am neuen etwas anders ist 2022 bChange = pOrigSymbol && !bEqual; 2023 } 2024 2025 aAddBtn .Enable(bAdd); 2026 aChangeBtn.Enable(bChange); 2027 aDeleteBtn.Enable(bDelete); 2028 } 2029 2030 2031 SmSymDefineDialog::SmSymDefineDialog(Window * pParent, 2032 OutputDevice *pFntListDevice, SmSymbolManager &rMgr, sal_Bool bFreeRes) : 2033 ModalDialog (pParent, SmResId(RID_SYMDEFINEDIALOG)), 2034 aOldSymbolText (this, SmResId(1)), 2035 aOldSymbols (this, SmResId(1)), 2036 aOldSymbolSetText (this, SmResId(2)), 2037 aOldSymbolSets (this, SmResId(2)), 2038 aCharsetDisplay (this, SmResId(1)), 2039 aSymbolText (this, SmResId(9)), 2040 aSymbols (this, SmResId(4)), 2041 aSymbolSetText (this, SmResId(10)), 2042 aSymbolSets (this, SmResId(5)), 2043 aFontText (this, SmResId(3)), 2044 aFonts (this, SmResId(1)), 2045 aFontsSubsetFT (this, SmResId( FT_FONTS_SUBSET )), 2046 aFontsSubsetLB (this, SmResId( LB_FONTS_SUBSET )), 2047 aStyleText (this, SmResId(4)), 2048 aStyles (this, SmResId(3)), 2049 aOldSymbolName (this, SmResId(7)), 2050 aOldSymbolDisplay (this, SmResId(3)), 2051 aOldSymbolSetName (this, SmResId(8)), 2052 aSymbolName (this, SmResId(5)), 2053 aSymbolDisplay (this, SmResId(2)), 2054 aSymbolSetName (this, SmResId(6)), 2055 aOkBtn (this, SmResId(1)), 2056 aCancelBtn (this, SmResId(1)), 2057 aAddBtn (this, SmResId(1)), 2058 aChangeBtn (this, SmResId(2)), 2059 aDeleteBtn (this, SmResId(3)), 2060 aRightArrow (this, SmResId(1)), 2061 aRigthArrow_Im (SmResId(1)), 2062 aRigthArrow_Im_HC (SmResId(2)), // hi-contrast version 2063 rSymbolMgr (rMgr), 2064 pSubsetMap (NULL), 2065 pFontList (NULL) 2066 { 2067 if (bFreeRes) 2068 FreeResource(); 2069 2070 pFontList = new FontList( pFntListDevice ); 2071 2072 pOrigSymbol = 0; 2073 2074 // auto completion is troublesome since that symbols character also gets automatically selected in the 2075 // display and if the user previously selected a character to define/redefine that one this is bad 2076 aOldSymbols.EnableAutocomplete( sal_False, sal_True ); 2077 aSymbols .EnableAutocomplete( sal_False, sal_True ); 2078 2079 FillFonts(); 2080 if (aFonts.GetEntryCount() > 0) 2081 SelectFont(aFonts.GetEntry(0)); 2082 2083 InitColor_Impl(); 2084 2085 SetSymbolSetManager(rSymbolMgr); 2086 2087 aOldSymbols .SetSelectHdl(LINK(this, SmSymDefineDialog, OldSymbolChangeHdl)); 2088 aOldSymbolSets .SetSelectHdl(LINK(this, SmSymDefineDialog, OldSymbolSetChangeHdl)); 2089 aSymbolSets .SetModifyHdl(LINK(this, SmSymDefineDialog, ModifyHdl)); 2090 aOldSymbolSets .SetModifyHdl(LINK(this, SmSymDefineDialog, ModifyHdl)); 2091 aSymbols .SetModifyHdl(LINK(this, SmSymDefineDialog, ModifyHdl)); 2092 aOldSymbols .SetModifyHdl(LINK(this, SmSymDefineDialog, ModifyHdl)); 2093 aStyles .SetModifyHdl(LINK(this, SmSymDefineDialog, ModifyHdl)); 2094 aFonts .SetSelectHdl(LINK(this, SmSymDefineDialog, FontChangeHdl)); 2095 aFontsSubsetLB .SetSelectHdl(LINK(this, SmSymDefineDialog, SubsetChangeHdl)); 2096 aStyles .SetSelectHdl(LINK(this, SmSymDefineDialog, StyleChangeHdl)); 2097 aAddBtn .SetClickHdl (LINK(this, SmSymDefineDialog, AddClickHdl)); 2098 aChangeBtn .SetClickHdl (LINK(this, SmSymDefineDialog, ChangeClickHdl)); 2099 aDeleteBtn .SetClickHdl (LINK(this, SmSymDefineDialog, DeleteClickHdl)); 2100 aCharsetDisplay.SetHighlightHdl( LINK( this, SmSymDefineDialog, CharHighlightHdl ) ); 2101 2102 // preview like controls should have a 2D look 2103 aOldSymbolDisplay.SetBorderStyle( WINDOW_BORDER_MONO ); 2104 aSymbolDisplay .SetBorderStyle( WINDOW_BORDER_MONO ); 2105 } 2106 2107 2108 SmSymDefineDialog::~SmSymDefineDialog() 2109 { 2110 delete pSubsetMap; 2111 delete pOrigSymbol; 2112 } 2113 2114 void SmSymDefineDialog::InitColor_Impl() 2115 { 2116 #if OSL_DEBUG_LEVEL > 1 2117 Color aBC( GetDisplayBackground().GetColor() ); 2118 #endif 2119 ColorData nBgCol = COL_WHITE, 2120 nTxtCol = COL_BLACK; 2121 sal_Bool bHighContrast = GetSettings().GetStyleSettings().GetHighContrastMode(); 2122 if (bHighContrast) 2123 { 2124 const StyleSettings &rS = GetSettings().GetStyleSettings(); 2125 nBgCol = rS.GetFieldColor().GetColor(); 2126 nTxtCol = rS.GetFieldTextColor().GetColor(); 2127 } 2128 2129 Color aTmpColor( nBgCol ); 2130 Wallpaper aWall( aTmpColor ); 2131 Color aTxtColor( nTxtCol ); 2132 aCharsetDisplay .SetBackground( aWall ); 2133 aCharsetDisplay .SetTextColor( aTxtColor ); 2134 aOldSymbolDisplay.SetBackground( aWall ); 2135 aOldSymbolDisplay.SetTextColor( aTxtColor ); 2136 aSymbolDisplay .SetBackground( aWall ); 2137 aSymbolDisplay .SetTextColor( aTxtColor ); 2138 2139 const Image &rArrowRight = bHighContrast ? aRigthArrow_Im_HC : aRigthArrow_Im; 2140 aRightArrow.SetImage( rArrowRight ); 2141 } 2142 2143 2144 void SmSymDefineDialog::DataChanged( const DataChangedEvent& rDCEvt ) 2145 { 2146 if ( rDCEvt.GetType() == DATACHANGED_SETTINGS && 2147 (rDCEvt.GetFlags() & SETTINGS_STYLE) ) 2148 InitColor_Impl(); 2149 2150 ModalDialog::DataChanged( rDCEvt ); 2151 } 2152 2153 2154 short SmSymDefineDialog::Execute() 2155 { 2156 short nResult = ModalDialog::Execute(); 2157 2158 // Aenderungen uebernehmen falls Dialog mit OK beendet wurde 2159 if (aSymbolMgrCopy.IsModified() && nResult == RET_OK) 2160 rSymbolMgr = aSymbolMgrCopy; 2161 2162 return nResult; 2163 } 2164 2165 2166 void SmSymDefineDialog::SetSymbolSetManager(const SmSymbolManager &rMgr) 2167 { 2168 aSymbolMgrCopy = rMgr; 2169 #ifdef DEBUG 2170 // sal_uInt16 nS = aSymbolMgrCopy.GetSymbolSetCount(); 2171 #endif 2172 2173 // Das modified Flag der Kopie auf sal_False setzen, damit man spaeter damit 2174 // testen kann ob sich was geaendert hat. 2175 aSymbolMgrCopy.SetModified(sal_False); 2176 2177 FillSymbolSets(aOldSymbolSets); 2178 if (aOldSymbolSets.GetEntryCount() > 0) 2179 SelectSymbolSet(aOldSymbolSets.GetEntry(0)); 2180 FillSymbolSets(aSymbolSets); 2181 if (aSymbolSets.GetEntryCount() > 0) 2182 SelectSymbolSet(aSymbolSets.GetEntry(0)); 2183 FillSymbols(aOldSymbols); 2184 if (aOldSymbols.GetEntryCount() > 0) 2185 SelectSymbol(aOldSymbols.GetEntry(0)); 2186 FillSymbols(aSymbols); 2187 if (aSymbols.GetEntryCount() > 0) 2188 SelectSymbol(aSymbols.GetEntry(0)); 2189 2190 UpdateButtons(); 2191 } 2192 2193 2194 sal_Bool SmSymDefineDialog::SelectSymbolSet(ComboBox &rComboBox, 2195 const XubString &rSymbolSetName, sal_Bool bDeleteText) 2196 { 2197 #if OSL_DEBUG_LEVEL > 1 2198 DBG_ASSERT(&rComboBox == &aOldSymbolSets || &rComboBox == &aSymbolSets, 2199 "Sm : Wrong comboBox"); 2200 #endif 2201 2202 // 'Normalisieren' des SymbolNamens (ohne leading und trailing Leerzeichen) 2203 XubString aNormName (rSymbolSetName); 2204 aNormName.EraseLeadingChars(' '); 2205 aNormName.EraseTrailingChars(' '); 2206 // und evtl Abweichungen in der Eingabe beseitigen 2207 rComboBox.SetText(aNormName); 2208 2209 sal_Bool bRet = sal_False; 2210 sal_uInt16 nPos = rComboBox.GetEntryPos(aNormName); 2211 2212 if (nPos != COMBOBOX_ENTRY_NOTFOUND) 2213 { 2214 rComboBox.SetText(rComboBox.GetEntry(nPos)); 2215 bRet = sal_True; 2216 } 2217 else if (bDeleteText) 2218 rComboBox.SetText(XubString()); 2219 2220 sal_Bool bIsOld = &rComboBox == &aOldSymbolSets; 2221 2222 // setzen des SymbolSet Namens an der zugehörigen Darstellung 2223 FixedText &rFT = bIsOld ? aOldSymbolSetName : aSymbolSetName; 2224 rFT.SetText(rComboBox.GetText()); 2225 2226 // setzen der zum SymbolSet gehörenden Symbol Namen an der zugehörigen 2227 // Auswahlbox 2228 ComboBox &rCB = bIsOld ? aOldSymbols : aSymbols; 2229 FillSymbols(rCB, sal_False); 2230 2231 // bei Wechsel des SymbolSets für das alte Zeichen ein gültiges 2232 // Symbol bzw keins zur Anzeige bringen 2233 if (bIsOld) 2234 { 2235 XubString aTmpOldSymbolName; 2236 if (aOldSymbols.GetEntryCount() > 0) 2237 aTmpOldSymbolName = aOldSymbols.GetEntry(0); 2238 SelectSymbol(aOldSymbols, aTmpOldSymbolName, sal_True); 2239 } 2240 2241 UpdateButtons(); 2242 2243 return bRet; 2244 } 2245 2246 2247 void SmSymDefineDialog::SetOrigSymbol(const SmSym *pSymbol, 2248 const XubString &rSymbolSetName) 2249 { 2250 // clear old symbol 2251 delete pOrigSymbol; 2252 pOrigSymbol = 0; 2253 2254 XubString aSymName, 2255 aSymSetName; 2256 if (pSymbol) 2257 { 2258 // set new symbol 2259 pOrigSymbol = new SmSym( *pSymbol ); 2260 2261 aSymName = pSymbol->GetName(); 2262 aSymSetName = rSymbolSetName; 2263 aOldSymbolDisplay.SetSymbol( pSymbol ); 2264 } 2265 else 2266 { // loeschen des angezeigten Symbols 2267 aOldSymbolDisplay.SetText(XubString()); 2268 aOldSymbolDisplay.Invalidate(); 2269 } 2270 aOldSymbolName .SetText(aSymName); 2271 aOldSymbolSetName.SetText(aSymSetName); 2272 } 2273 2274 2275 sal_Bool SmSymDefineDialog::SelectSymbol(ComboBox &rComboBox, 2276 const XubString &rSymbolName, sal_Bool bDeleteText) 2277 { 2278 #if OSL_DEBUG_LEVEL > 1 2279 DBG_ASSERT(&rComboBox == &aOldSymbols || &rComboBox == &aSymbols, 2280 "Sm : Wrong comboBox"); 2281 #endif 2282 2283 // 'Normalisieren' des SymbolNamens (ohne Leerzeichen) 2284 XubString aNormName (rSymbolName); 2285 aNormName.EraseAllChars(' '); 2286 // und evtl Abweichungen in der Eingabe beseitigen 2287 rComboBox.SetText(aNormName); 2288 2289 sal_Bool bRet = sal_False; 2290 sal_uInt16 nPos = rComboBox.GetEntryPos(aNormName); 2291 2292 sal_Bool bIsOld = &rComboBox == &aOldSymbols; 2293 2294 if (nPos != COMBOBOX_ENTRY_NOTFOUND) 2295 { 2296 rComboBox.SetText(rComboBox.GetEntry(nPos)); 2297 2298 if (!bIsOld) 2299 { 2300 const SmSym *pSymbol = GetSymbol(aSymbols); 2301 if (pSymbol) 2302 { 2303 // Font und Style entsprechend waehlen 2304 const Font &rFont = pSymbol->GetFace(); 2305 SelectFont(rFont.GetName(), sal_False); 2306 SelectStyle(GetFontStyles().GetStyleName(rFont), sal_False); 2307 2308 // da das setzen des Fonts ueber den Style Namen des SymbolsFonts nicht 2309 // so gut klappt (er kann zB leer sein obwohl der Font selbst 'bold' und 2310 // 'italic' ist!). Setzen wir hier den Font wie er zum Symbol gehoert 2311 // zu Fuss. 2312 aCharsetDisplay.SetFont(rFont); 2313 aSymbolDisplay.SetFont(rFont); 2314 2315 // das zugehoerige Zeichen auswaehlen 2316 SelectChar(pSymbol->GetCharacter()); 2317 2318 // since SelectChar will also set the unicode point as text in the 2319 // symbols box, we have to set the symbol name again to get that one displayed 2320 aSymbols.SetText( pSymbol->GetName() ); 2321 } 2322 } 2323 2324 bRet = sal_True; 2325 } 2326 else if (bDeleteText) 2327 rComboBox.SetText(XubString()); 2328 2329 if (bIsOld) 2330 { 2331 // bei Wechsel des alten Symbols nur vorhandene anzeigen sonst keins 2332 const SmSym *pOldSymbol = NULL; 2333 XubString aTmpOldSymbolSetName; 2334 if (nPos != COMBOBOX_ENTRY_NOTFOUND) 2335 { 2336 pOldSymbol = aSymbolMgrCopy.GetSymbolByName(aNormName); 2337 aTmpOldSymbolSetName = aOldSymbolSets.GetText(); 2338 } 2339 SetOrigSymbol(pOldSymbol, aTmpOldSymbolSetName); 2340 } 2341 else 2342 aSymbolName.SetText(rComboBox.GetText()); 2343 2344 UpdateButtons(); 2345 2346 return bRet; 2347 } 2348 2349 2350 void SmSymDefineDialog::SetFont(const XubString &rFontName, const XubString &rStyleName) 2351 { 2352 // Font (FontInfo) passend zu Namen und Style holen 2353 FontInfo aFI; 2354 if (pFontList) 2355 aFI = pFontList->Get(rFontName, WEIGHT_NORMAL, ITALIC_NONE); 2356 SetFontStyle(rStyleName, aFI); 2357 2358 aCharsetDisplay.SetFont(aFI); 2359 aSymbolDisplay.SetFont(aFI); 2360 2361 // update subset listbox for new font's unicode subsets 2362 FontCharMap aFontCharMap; 2363 aCharsetDisplay.GetFontCharMap( aFontCharMap ); 2364 if (pSubsetMap) 2365 delete pSubsetMap; 2366 pSubsetMap = new SubsetMap( &aFontCharMap ); 2367 // 2368 aFontsSubsetLB.Clear(); 2369 bool bFirst = true; 2370 const Subset* pSubset; 2371 while( NULL != (pSubset = pSubsetMap->GetNextSubset( bFirst )) ) 2372 { 2373 sal_uInt16 nPos = aFontsSubsetLB.InsertEntry( pSubset->GetName()); 2374 aFontsSubsetLB.SetEntryData( nPos, (void *) pSubset ); 2375 // subset must live at least as long as the selected font !!! 2376 if( bFirst ) 2377 aFontsSubsetLB.SelectEntryPos( nPos ); 2378 bFirst = false; 2379 } 2380 if( bFirst ) 2381 aFontsSubsetLB.SetNoSelection(); 2382 aFontsSubsetLB.Enable( !bFirst ); 2383 } 2384 2385 2386 sal_Bool SmSymDefineDialog::SelectFont(const XubString &rFontName, sal_Bool bApplyFont) 2387 { 2388 sal_Bool bRet = sal_False; 2389 sal_uInt16 nPos = aFonts.GetEntryPos(rFontName); 2390 2391 if (nPos != LISTBOX_ENTRY_NOTFOUND) 2392 { 2393 aFonts.SelectEntryPos(nPos); 2394 if (aStyles.GetEntryCount() > 0) 2395 SelectStyle(aStyles.GetEntry(0)); 2396 if (bApplyFont) 2397 { 2398 SetFont(aFonts.GetSelectEntry(), aStyles.GetText()); 2399 // update preview to use new font 2400 aSymbolDisplay.SetSymbol( aCharsetDisplay.GetSelectCharacter(), aCharsetDisplay.GetFont() ); 2401 } 2402 bRet = sal_True; 2403 } 2404 else 2405 aFonts.SetNoSelection(); 2406 FillStyles(); 2407 2408 UpdateButtons(); 2409 2410 return bRet; 2411 } 2412 2413 2414 sal_Bool SmSymDefineDialog::SelectStyle(const XubString &rStyleName, sal_Bool bApplyFont) 2415 { 2416 sal_Bool bRet = sal_False; 2417 sal_uInt16 nPos = aStyles.GetEntryPos(rStyleName); 2418 2419 // falls der Style nicht zur Auswahl steht nehmen wir den erst moeglichen 2420 // (sofern vorhanden) 2421 if (nPos == COMBOBOX_ENTRY_NOTFOUND && aStyles.GetEntryCount() > 0) 2422 nPos = 0; 2423 2424 if (nPos != COMBOBOX_ENTRY_NOTFOUND) 2425 { 2426 aStyles.SetText(aStyles.GetEntry(nPos)); 2427 if (bApplyFont) 2428 { 2429 SetFont(aFonts.GetSelectEntry(), aStyles.GetText()); 2430 // update preview to use new font 2431 aSymbolDisplay.SetSymbol( aCharsetDisplay.GetSelectCharacter(), aCharsetDisplay.GetFont() ); 2432 } 2433 bRet = sal_True; 2434 } 2435 else 2436 aStyles.SetText(XubString()); 2437 2438 UpdateButtons(); 2439 2440 return bRet; 2441 } 2442 2443 2444 void SmSymDefineDialog::SelectChar(xub_Unicode cChar) 2445 { 2446 aCharsetDisplay.SelectCharacter( cChar ); 2447 aSymbolDisplay.SetSymbol( cChar, aCharsetDisplay.GetFont() ); 2448 2449 UpdateButtons(); 2450 } 2451 2452 /* vim: set noet sw=4 ts=4: */ 2453