update dev300-m58
[ooovba.git] / starmath / source / dialog.cxx
blob6b9a0ced723081d746f0824af58c3b5caad4c257
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: dialog.cxx,v $
10 * $Revision: 1.44 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_starmath.hxx"
35 #define SMDLL 1
36 #include "tools/rcid.h"
37 #include <svtools/eitem.hxx>
38 #include <svtools/intitem.hxx>
39 #include <svtools/stritem.hxx>
40 #include <sfx2/app.hxx>
41 #include <vcl/msgbox.hxx>
42 #include <svtools/ctrltool.hxx>
43 #include <sfx2/printer.hxx>
44 #include <vcl/sound.hxx>
45 #include <vcl/sndstyle.hxx>
46 #include <vcl/waitobj.hxx>
47 #include <vcl/settings.hxx>
48 #include <vcl/wall.hxx>
49 #include <sfx2/dispatch.hxx>
50 #include <sfx2/sfx.hrc>
51 #include <tools/string.hxx>
52 #include <tools/debug.hxx>
53 #include <svx/ucsubset.hxx>
56 #include "config.hxx"
57 #include "dialog.hxx"
58 #ifndef _STARMATH_HRC
59 #include "starmath.hrc"
60 #endif
62 #include "dialog.hrc"
63 #include "smmod.hxx"
64 #include "symbol.hxx"
65 #include "view.hxx"
66 #include "document.hxx"
68 ////////////////////////////////////////
70 // Da der FontStyle besser ueber die Attribute gesetzt/abgefragt wird als ueber
71 // den StyleName bauen wir uns hier unsere eigene Uebersetzung
72 // Attribute <-> StyleName
75 class SmFontStyles
77 String aNormal;
78 String aBold;
79 String aItalic;
80 String aBoldItalic;
81 String aEmpty;
83 public:
84 SmFontStyles();
86 USHORT GetCount() const { return 4; }
87 const String & GetStyleName( const Font &rFont ) const;
88 const String & GetStyleName( USHORT nIdx ) const;
92 SmFontStyles::SmFontStyles() :
93 aNormal ( ResId( RID_FONTREGULAR, *SM_MOD()->GetResMgr() ) ),
94 aBold ( ResId( RID_FONTBOLD, *SM_MOD()->GetResMgr() ) ),
95 aItalic ( ResId( RID_FONTITALIC, *SM_MOD()->GetResMgr() ) )
97 // SM_MOD()->GetResMgr().FreeResource();
99 aBoldItalic = aBold;
100 aBoldItalic.AppendAscii( ", " );
101 aBoldItalic += aItalic;
105 const String & SmFontStyles::GetStyleName( const Font &rFont ) const
107 //! compare also SmSpecialNode::Prepare
108 BOOL bBold = IsBold( rFont ),
109 bItalic = IsItalic( rFont );
111 if (bBold && bItalic)
112 return aBoldItalic;
113 else if (bItalic)
114 return aItalic;
115 else if (bBold)
116 return aBold;
117 else
118 return aNormal;
122 const String & SmFontStyles::GetStyleName( USHORT nIdx ) const
124 // 0 = "normal", 1 = "italic",
125 // 2 = "bold", 3 = "bold italic"
127 #if OSL_DEBUG_LEVEL > 1
128 DBG_ASSERT( nIdx < GetCount(), "index out of range" );
129 #endif
130 switch (nIdx)
132 case 0 : return aNormal;
133 case 1 : return aItalic;
134 case 2 : return aBold;
135 case 3 : return aBoldItalic;
137 return aEmpty;
141 const SmFontStyles & GetFontStyles()
143 static const SmFontStyles aImpl;
144 return aImpl;
147 /////////////////////////////////////////////////////////////////
149 void SetFontStyle(const XubString &rStyleName, Font &rFont)
151 // finden des Index passend zum StyleName fuer den leeren StyleName wird
152 // 0 (nicht bold nicht italic) angenommen.
153 USHORT nIndex = 0;
154 if (rStyleName.Len())
156 USHORT i;
157 const SmFontStyles &rStyles = GetFontStyles();
158 for (i = 0; i < rStyles.GetCount(); i++)
159 if (rStyleName.CompareTo( rStyles.GetStyleName(i) ) == COMPARE_EQUAL)
160 break;
161 #if OSL_DEBUG_LEVEL > 1
162 DBG_ASSERT(i < rStyles.GetCount(), "style-name unknown");
163 #endif
164 nIndex = i;
167 rFont.SetItalic((nIndex & 0x1) ? ITALIC_NORMAL : ITALIC_NONE);
168 rFont.SetWeight((nIndex & 0x2) ? WEIGHT_BOLD : WEIGHT_NORMAL);
172 /**************************************************************************/
174 IMPL_LINK_INLINE_START( SmPrintOptionsTabPage, SizeButtonClickHdl, Button *, EMPTYARG/*pButton*/ )
176 aZoom.Enable(aSizeZoomed.IsChecked());
177 return 0;
179 IMPL_LINK_INLINE_END( SmPrintOptionsTabPage, SizeButtonClickHdl, Button *, pButton )
182 SmPrintOptionsTabPage::SmPrintOptionsTabPage(Window *pParent, const SfxItemSet &rOptions)
183 : SfxTabPage(pParent, SmResId(RID_PRINTOPTIONPAGE), rOptions),
184 aFixedLine1 (this, SmResId( FL_PRINTOPTIONS )),
185 aTitle (this, SmResId( CB_TITLEROW )),
186 aText (this, SmResId( CB_EQUATION_TEXT )),
187 aFrame (this, SmResId( CB_FRAME )),
188 aFixedLine2 (this, SmResId( FL_PRINT_FORMAT )),
189 aSizeNormal (this, SmResId( RB_ORIGINAL_SIZE )),
190 aSizeScaled (this, SmResId( RB_FIT_TO_PAGE )),
191 aSizeZoomed (this, SmResId( RB_ZOOM )),
192 aZoom (this, SmResId( MF_ZOOM )),
193 aFixedLine3 (this, SmResId( FL_MISC_OPTIONS )),
194 aNoRightSpaces (this, SmResId( CB_IGNORE_SPACING ))
196 FreeResource();
198 aSizeNormal.SetClickHdl(LINK(this, SmPrintOptionsTabPage, SizeButtonClickHdl));
199 aSizeScaled.SetClickHdl(LINK(this, SmPrintOptionsTabPage, SizeButtonClickHdl));
200 aSizeZoomed.SetClickHdl(LINK(this, SmPrintOptionsTabPage, SizeButtonClickHdl));
202 Reset(rOptions);
206 BOOL SmPrintOptionsTabPage::FillItemSet(SfxItemSet& rSet)
208 UINT16 nPrintSize;
209 if (aSizeNormal.IsChecked())
210 nPrintSize = PRINT_SIZE_NORMAL;
211 else if (aSizeScaled.IsChecked())
212 nPrintSize = PRINT_SIZE_SCALED;
213 else
214 nPrintSize = PRINT_SIZE_ZOOMED;
216 rSet.Put(SfxUInt16Item(GetWhich(SID_PRINTSIZE), (UINT16) nPrintSize));
217 rSet.Put(SfxUInt16Item(GetWhich(SID_PRINTZOOM), (UINT16) aZoom.GetValue()));
218 rSet.Put(SfxBoolItem(GetWhich(SID_PRINTTITLE), aTitle.IsChecked()));
219 rSet.Put(SfxBoolItem(GetWhich(SID_PRINTTEXT), aText.IsChecked()));
220 rSet.Put(SfxBoolItem(GetWhich(SID_PRINTFRAME), aFrame.IsChecked()));
221 rSet.Put(SfxBoolItem(GetWhich(SID_NO_RIGHT_SPACES), aNoRightSpaces.IsChecked()));
223 return TRUE;
227 void SmPrintOptionsTabPage::Reset(const SfxItemSet& rSet)
229 SmPrintSize ePrintSize = (SmPrintSize)((const SfxUInt16Item &)rSet.Get(GetWhich(SID_PRINTSIZE))).GetValue();
231 aSizeNormal.Check(ePrintSize == PRINT_SIZE_NORMAL);
232 aSizeScaled.Check(ePrintSize == PRINT_SIZE_SCALED);
233 aSizeZoomed.Check(ePrintSize == PRINT_SIZE_ZOOMED);
235 aZoom.Enable(aSizeZoomed.IsChecked());
237 aZoom.SetValue(((const SfxUInt16Item &)rSet.Get(GetWhich(SID_PRINTZOOM))).GetValue());
239 aTitle.Check(((const SfxBoolItem &)rSet.Get(GetWhich(SID_PRINTTITLE))).GetValue());
240 aText.Check(((const SfxBoolItem &)rSet.Get(GetWhich(SID_PRINTTEXT))).GetValue());
241 aFrame.Check(((const SfxBoolItem &)rSet.Get(GetWhich(SID_PRINTFRAME))).GetValue());
242 aNoRightSpaces.Check(((const SfxBoolItem &)rSet.Get(GetWhich(SID_NO_RIGHT_SPACES))).GetValue());
246 SfxTabPage* SmPrintOptionsTabPage::Create(Window* pWindow, const SfxItemSet& rSet)
248 return (new SmPrintOptionsTabPage(pWindow, rSet));
251 /**************************************************************************/
254 void SmShowFont::Paint(const Rectangle& rRect )
256 Control::Paint( rRect );
258 XubString Text (GetFont().GetName());
259 Size TextSize(GetTextWidth(Text), GetTextHeight());
261 DrawText(Point((GetOutputSize().Width() - TextSize.Width()) / 2,
262 (GetOutputSize().Height() - TextSize.Height()) / 2), Text);
266 void SmShowFont::SetFont(const Font& rFont)
268 Color aTxtColor( GetTextColor() );
269 Font aFont (rFont);
271 Invalidate();
272 aFont.SetSize(Size(0, 24));
273 aFont.SetAlign(ALIGN_TOP);
274 Control::SetFont(aFont);
276 // keep old text color (new font may have different color)
277 SetTextColor( aTxtColor );
281 IMPL_LINK_INLINE_START( SmFontDialog, FontSelectHdl, ComboBox *, pComboBox )
283 Face.SetName(pComboBox->GetText());
284 aShowFont.SetFont(Face);
285 return 0;
287 IMPL_LINK_INLINE_END( SmFontDialog, FontSelectHdl, ComboBox *, pComboBox )
290 IMPL_LINK( SmFontDialog, FontModifyHdl, ComboBox *, pComboBox )
292 // if font is available in list then use it
293 USHORT nPos = pComboBox->GetEntryPos( pComboBox->GetText() );
294 if (COMBOBOX_ENTRY_NOTFOUND != nPos)
296 FontSelectHdl( pComboBox );
298 return 0;
302 IMPL_LINK( SmFontDialog, AttrChangeHdl, CheckBox *, EMPTYARG /*pCheckBox*/ )
304 if (aBoldCheckBox.IsChecked())
305 Face.SetWeight(FontWeight(WEIGHT_BOLD));
306 else
307 Face.SetWeight(FontWeight(WEIGHT_NORMAL));
309 if (aItalicCheckBox.IsChecked())
310 Face.SetItalic(ITALIC_NORMAL);
311 else
312 Face.SetItalic(ITALIC_NONE);
314 aShowFont.SetFont(Face);
315 return 0;
319 void SmFontDialog::SetFont(const Font &rFont)
321 Face = rFont;
323 aFontBox.SetText( Face.GetName() );
324 aBoldCheckBox.Check( IsBold( Face ) );
325 aItalicCheckBox.Check( IsItalic( Face ) );
327 aShowFont.SetFont(Face);
331 SmFontDialog::SmFontDialog(Window * pParent,
332 OutputDevice *pFntListDevice, BOOL bHideCheckboxes, BOOL bFreeRes)
333 : ModalDialog(pParent,SmResId(RID_FONTDIALOG)),
334 aFixedText1 (this, SmResId(1)),
335 aFontBox (this, SmResId(1)),
336 aBoldCheckBox (this, SmResId(1)),
337 aItalicCheckBox (this, SmResId(2)),
338 aOKButton1 (this, SmResId(1)),
339 aCancelButton1 (this, SmResId(1)),
340 aShowFont (this, SmResId(1)),
341 aFixedText2 (this, SmResId(2))
343 if (bFreeRes)
344 FreeResource();
347 WaitObject( this );
349 FontList aFontList( pFntListDevice );
351 USHORT nCount = aFontList.GetFontNameCount();
352 for (USHORT i = 0; i < nCount; i++)
353 aFontBox.InsertEntry( aFontList.GetFontName(i).GetName() );
355 Face.SetSize(Size(0, 24));
356 Face.SetWeight(WEIGHT_NORMAL);
357 Face.SetItalic(ITALIC_NONE);
358 Face.SetFamily(FAMILY_DONTKNOW);
359 Face.SetPitch(PITCH_DONTKNOW);
360 Face.SetCharSet(RTL_TEXTENCODING_DONTKNOW);
361 Face.SetTransparent(TRUE);
363 InitColor_Impl();
365 // preview like controls should have a 2D look
366 aShowFont.SetBorderStyle( WINDOW_BORDER_MONO );
369 aFontBox.SetSelectHdl(LINK(this, SmFontDialog, FontSelectHdl));
370 aFontBox.SetModifyHdl(LINK(this, SmFontDialog, FontModifyHdl));
371 aBoldCheckBox.SetClickHdl(LINK(this, SmFontDialog, AttrChangeHdl));
372 aItalicCheckBox.SetClickHdl(LINK(this, SmFontDialog, AttrChangeHdl));
374 if (bHideCheckboxes)
376 aBoldCheckBox.Check( FALSE );
377 aBoldCheckBox.Enable( FALSE );
378 aBoldCheckBox.Show( FALSE );
379 aItalicCheckBox.Check( FALSE );
380 aItalicCheckBox.Enable( FALSE );
381 aItalicCheckBox.Show( FALSE );
382 aFixedText2.Show( FALSE );
384 Size aSize( aFontBox.GetSizePixel() );
385 long nComboBoxBottom = aFontBox.GetPosPixel().Y() + aFontBox.GetSizePixel().Height();
386 long nCheckBoxBottom = aItalicCheckBox.GetPosPixel().Y() + aItalicCheckBox.GetSizePixel().Height();
387 aSize.Height() += nCheckBoxBottom - nComboBoxBottom;
388 aFontBox.SetSizePixel( aSize );
392 void SmFontDialog::InitColor_Impl()
394 #if OSL_DEBUG_LEVEL > 1
395 Color aBC( GetDisplayBackground().GetColor() );
396 #endif
397 ColorData nBgCol = COL_WHITE,
398 nTxtCol = COL_BLACK;
399 if (GetDisplayBackground().GetColor().IsDark())
401 const StyleSettings &rS = GetSettings().GetStyleSettings();
402 nBgCol = rS.GetFieldColor().GetColor();
403 nTxtCol = rS.GetFieldTextColor().GetColor();
406 Color aTmpColor( nBgCol );
407 Wallpaper aWall( aTmpColor );
408 Color aTxtColor( nTxtCol );
409 aShowFont.SetBackground( aWall );
410 aShowFont.SetTextColor( aTxtColor );
414 void SmFontDialog::DataChanged( const DataChangedEvent& rDCEvt )
416 if ( rDCEvt.GetType() == DATACHANGED_SETTINGS &&
417 (rDCEvt.GetFlags() & SETTINGS_STYLE) )
418 InitColor_Impl();
420 ModalDialog::DataChanged( rDCEvt );
423 /**************************************************************************/
426 IMPL_LINK( SmFontSizeDialog, DefaultButtonClickHdl, Button *, EMPTYARG /*pButton*/ )
428 QueryBox *pQueryBox = new QueryBox(this, SmResId(RID_DEFAULTSAVEQUERY));
430 if (pQueryBox->Execute() == RET_YES)
432 SmModule *pp = SM_MOD1();
433 SmFormat aFmt( pp->GetConfig()->GetStandardFormat() );
434 WriteTo( aFmt );
435 pp->GetConfig()->SetStandardFormat( aFmt );
438 delete pQueryBox;
439 return 0;
443 SmFontSizeDialog::SmFontSizeDialog(Window * pParent, BOOL bFreeRes)
444 : ModalDialog(pParent, SmResId(RID_FONTSIZEDIALOG)),
445 aFixedText1(this, SmResId(1)),
446 aBaseSize(this, SmResId(1)),
447 aFixedText4(this, SmResId(4)),
448 aTextSize(this, SmResId(4)),
449 aFixedText5(this, SmResId(5)),
450 aIndexSize(this, SmResId(5)),
451 aFixedText6(this, SmResId(6)),
452 aFunctionSize(this, SmResId(6)),
453 aFixedText7(this, SmResId(7)),
454 aOperatorSize(this, SmResId(7)),
455 aFixedText8(this, SmResId(8)),
456 aBorderSize(this, SmResId(8)),
457 aFixedLine1(this, SmResId(1)),
458 aOKButton1(this, SmResId(1)),
459 aCancelButton1(this, SmResId(1)),
460 aDefaultButton(this, SmResId(1))
462 if (bFreeRes)
463 FreeResource();
465 aDefaultButton.SetClickHdl(LINK(this, SmFontSizeDialog, DefaultButtonClickHdl));
469 void SmFontSizeDialog::ReadFrom(const SmFormat &rFormat)
471 //! aufpassen: richtig runden!
472 aBaseSize.SetValue( SmRoundFraction(
473 Sm100th_mmToPts( rFormat.GetBaseSize().Height() ) ) );
475 aTextSize .SetValue( rFormat.GetRelSize(SIZ_TEXT) );
476 aIndexSize .SetValue( rFormat.GetRelSize(SIZ_INDEX) );
477 aFunctionSize.SetValue( rFormat.GetRelSize(SIZ_FUNCTION) );
478 aOperatorSize.SetValue( rFormat.GetRelSize(SIZ_OPERATOR) );
479 aBorderSize .SetValue( rFormat.GetRelSize(SIZ_LIMITS) );
483 void SmFontSizeDialog::WriteTo(SmFormat &rFormat) const
485 rFormat.SetBaseSize( Size(0, SmPtsTo100th_mm( static_cast< long >(aBaseSize.GetValue()))) );
487 rFormat.SetRelSize(SIZ_TEXT, (USHORT) aTextSize .GetValue());
488 rFormat.SetRelSize(SIZ_INDEX, (USHORT) aIndexSize .GetValue());
489 rFormat.SetRelSize(SIZ_FUNCTION, (USHORT) aFunctionSize.GetValue());
490 rFormat.SetRelSize(SIZ_OPERATOR, (USHORT) aOperatorSize.GetValue());
491 rFormat.SetRelSize(SIZ_LIMITS, (USHORT) aBorderSize .GetValue());
493 const Size aTmp (rFormat.GetBaseSize());
494 for (USHORT i = FNT_BEGIN; i <= FNT_END; i++)
495 rFormat.SetFontSize(i, aTmp);
497 rFormat.RequestApplyChanges();
501 /**************************************************************************/
504 IMPL_LINK( SmFontTypeDialog, MenuSelectHdl, Menu *, pMenu )
506 SmFontPickListBox *pActiveListBox;
508 BOOL bHideCheckboxes = FALSE;
509 switch (pMenu->GetCurItemId())
511 case 1: pActiveListBox = &aVariableFont; break;
512 case 2: pActiveListBox = &aFunctionFont; break;
513 case 3: pActiveListBox = &aNumberFont; break;
514 case 4: pActiveListBox = &aTextFont; break;
515 case 5: pActiveListBox = &aSerifFont; bHideCheckboxes = TRUE; break;
516 case 6: pActiveListBox = &aSansFont; bHideCheckboxes = TRUE; break;
517 case 7: pActiveListBox = &aFixedFont; bHideCheckboxes = TRUE; break;
518 default:pActiveListBox = NULL;
521 if (pActiveListBox)
523 SmFontDialog *pFontDialog = new SmFontDialog(this, pFontListDev, bHideCheckboxes);
525 pActiveListBox->WriteTo(*pFontDialog);
526 if (pFontDialog->Execute() == RET_OK)
527 pActiveListBox->ReadFrom(*pFontDialog);
528 delete pFontDialog;
530 return 0;
534 IMPL_LINK_INLINE_START( SmFontTypeDialog, DefaultButtonClickHdl, Button *, EMPTYARG /*pButton*/ )
536 QueryBox *pQueryBox = new QueryBox(this, SmResId(RID_DEFAULTSAVEQUERY));
537 if (pQueryBox->Execute() == RET_YES)
539 SmModule *pp = SM_MOD1();
540 SmFormat aFmt( pp->GetConfig()->GetStandardFormat() );
541 WriteTo( aFmt );
542 pp->GetConfig()->SetStandardFormat( aFmt, TRUE );
545 delete pQueryBox;
546 return 0;
548 IMPL_LINK_INLINE_END( SmFontTypeDialog, DefaultButtonClickHdl, Button *, pButton )
551 SmFontTypeDialog::SmFontTypeDialog(Window * pParent, OutputDevice *pFntListDevice, BOOL bFreeRes)
552 : ModalDialog(pParent, SmResId(RID_FONTTYPEDIALOG)),
553 aFixedText1 (this, SmResId(1)),
554 aVariableFont (this, SmResId(1)),
555 aFixedText2 (this, SmResId(2)),
556 aFunctionFont (this, SmResId(2)),
557 aFixedText3 (this, SmResId(3)),
558 aNumberFont (this, SmResId(3)),
559 aFixedText4 (this, SmResId(4)),
560 aTextFont (this, SmResId(4)),
561 aFixedText5 (this, SmResId(5)),
562 aSerifFont (this, SmResId(5)),
563 aFixedText6 (this, SmResId(6)),
564 aSansFont (this, SmResId(6)),
565 aFixedText7 (this, SmResId(7)),
566 aFixedFont (this, SmResId(7)),
567 aFixedLine1 (this, SmResId(1)),
568 aFixedLine2 (this, SmResId(2)),
569 aOKButton1 (this, SmResId(1)),
570 aCancelButton1 (this, SmResId(1)),
571 aMenuButton (this, SmResId(1)),
572 aDefaultButton (this, SmResId(2)),
573 pFontListDev (pFntListDevice)
575 if (bFreeRes)
576 FreeResource();
578 aDefaultButton.SetClickHdl(LINK(this, SmFontTypeDialog, DefaultButtonClickHdl));
580 aMenuButton.GetPopupMenu()->SetSelectHdl(LINK(this, SmFontTypeDialog, MenuSelectHdl));
583 void SmFontTypeDialog::ReadFrom(const SmFormat &rFormat)
585 SmModule *pp = SM_MOD1();
587 aVariableFont = pp->GetConfig()->GetFontPickList(FNT_VARIABLE);
588 aFunctionFont = pp->GetConfig()->GetFontPickList(FNT_FUNCTION);
589 aNumberFont = pp->GetConfig()->GetFontPickList(FNT_NUMBER);
590 aTextFont = pp->GetConfig()->GetFontPickList(FNT_TEXT);
591 aSerifFont = pp->GetConfig()->GetFontPickList(FNT_SERIF);
592 aSansFont = pp->GetConfig()->GetFontPickList(FNT_SANS);
593 aFixedFont = pp->GetConfig()->GetFontPickList(FNT_FIXED);
595 aVariableFont.Insert( rFormat.GetFont(FNT_VARIABLE) );
596 aFunctionFont.Insert( rFormat.GetFont(FNT_FUNCTION) );
597 aNumberFont .Insert( rFormat.GetFont(FNT_NUMBER) );
598 aTextFont .Insert( rFormat.GetFont(FNT_TEXT) );
599 aSerifFont .Insert( rFormat.GetFont(FNT_SERIF) );
600 aSansFont .Insert( rFormat.GetFont(FNT_SANS) );
601 aFixedFont .Insert( rFormat.GetFont(FNT_FIXED) );
605 void SmFontTypeDialog::WriteTo(SmFormat &rFormat) const
607 SmModule *pp = SM_MOD1();
609 pp->GetConfig()->GetFontPickList(FNT_VARIABLE) = aVariableFont;
610 pp->GetConfig()->GetFontPickList(FNT_FUNCTION) = aFunctionFont;
611 pp->GetConfig()->GetFontPickList(FNT_NUMBER) = aNumberFont;
612 pp->GetConfig()->GetFontPickList(FNT_TEXT) = aTextFont;
613 pp->GetConfig()->GetFontPickList(FNT_SERIF) = aSerifFont;
614 pp->GetConfig()->GetFontPickList(FNT_SANS) = aSansFont;
615 pp->GetConfig()->GetFontPickList(FNT_FIXED) = aFixedFont;
617 rFormat.SetFont( FNT_VARIABLE, aVariableFont.Get(0) );
618 rFormat.SetFont( FNT_FUNCTION, aFunctionFont.Get(0) );
619 rFormat.SetFont( FNT_NUMBER, aNumberFont .Get(0) );
620 rFormat.SetFont( FNT_TEXT, aTextFont .Get(0) );
621 rFormat.SetFont( FNT_SERIF, aSerifFont .Get(0) );
622 rFormat.SetFont( FNT_SANS, aSansFont .Get(0) );
623 rFormat.SetFont( FNT_FIXED, aFixedFont .Get(0) );
625 rFormat.RequestApplyChanges();
628 /**************************************************************************/
630 struct FieldMinMax
632 USHORT nMin, nMax;
635 // Data for min and max values of the 4 metric fields
636 // for each of the 10 categories
637 static const FieldMinMax pMinMaxData[10][4] =
639 // 0
640 {{ 0, 200 }, { 0, 200 }, { 0, 100 }, { 0, 0 }},
641 // 1
642 {{ 0, 100 }, { 0, 100 }, { 0, 0 }, { 0, 0 }},
643 // 2
644 {{ 0, 100 }, { 0, 100 }, { 0, 0 }, { 0, 0 }},
645 // 3
646 {{ 0, 100 }, { 1, 100 }, { 0, 0 }, { 0, 0 }},
647 // 4
648 {{ 0, 100 }, { 0, 100 }, { 0, 0 }, { 0, 0 }},
649 // 5
650 {{ 0, 100 }, { 0, 100 }, { 0, 0 }, { 0, 100 }},
651 // 6
652 {{ 0, 300 }, { 0, 300 }, { 0, 0 }, { 0, 0 }},
653 // 7
654 {{ 0, 100 }, { 0, 100 }, { 0, 0 }, { 0, 0 }},
655 // 8
656 {{ 0, 100 }, { 0, 100 }, { 0, 0 }, { 0, 0 }},
657 // 9
658 {{ 0, 10000 }, { 0, 10000 }, { 0, 10000 }, { 0, 10000 }}
661 SmCategoryDesc::SmCategoryDesc(const ResId& rResId, USHORT nCategoryIdx) :
662 Resource(rResId),
663 bIsHighContrast(FALSE)
665 if (IsAvailableRes(ResId(1,*rResId.GetResMgr()).SetRT(RSC_STRING)))
667 Name = XubString(ResId(1,*rResId.GetResMgr()));
669 int i;
670 for (i = 0; i < 4; i++)
672 int nI2 = i + 2;
674 if (IsAvailableRes(ResId(nI2,*rResId.GetResMgr()).SetRT(RSC_STRING)))
676 Strings [i] = new XubString(ResId(nI2,*rResId.GetResMgr()));
677 Graphics [i] = new Bitmap(ResId(10*nI2,*rResId.GetResMgr()));
678 GraphicsH[i] = new Bitmap(ResId(10*nI2+1,*rResId.GetResMgr()));
680 else
682 Strings [i] = 0;
683 Graphics [i] = 0;
684 GraphicsH[i] = 0;
688 for (i = 0; i < 4; i++)
690 const FieldMinMax &rMinMax = pMinMaxData[ nCategoryIdx ][i];
691 Value[i] = Minimum[i] = rMinMax.nMin;
692 Maximum[i] = rMinMax.nMax;
696 FreeResource();
700 SmCategoryDesc::~SmCategoryDesc()
702 for (int i = 0; i < 4; i++)
704 delete Strings [i];
705 delete Graphics [i];
706 delete GraphicsH[i];
710 /**************************************************************************/
712 IMPL_LINK( SmDistanceDialog, GetFocusHdl, Control *, pControl )
714 if (Categories[nActiveCategory])
716 USHORT i;
718 if (pControl == &aMetricField1)
719 i = 0;
720 else if (pControl == &aMetricField2)
721 i = 1;
722 else if (pControl == &aMetricField3)
723 i = 2;
724 else if (pControl == &aMetricField4)
725 i = 3;
726 else
727 return 0;
728 aBitmap.SetBitmap(*(Categories[nActiveCategory]->GetGraphic(i)));
730 return 0;
733 IMPL_LINK( SmDistanceDialog, MenuSelectHdl, Menu *, pMenu )
735 SetCategory(pMenu->GetCurItemId() - 1);
736 return 0;
740 IMPL_LINK( SmDistanceDialog, DefaultButtonClickHdl, Button *, EMPTYARG /*pButton*/ )
742 QueryBox *pQueryBox = new QueryBox(this, SmResId(RID_DEFAULTSAVEQUERY));
744 if (pQueryBox->Execute() == RET_YES)
746 SmModule *pp = SM_MOD1();
747 SmFormat aFmt( pp->GetConfig()->GetStandardFormat() );
748 WriteTo( aFmt );
749 pp->GetConfig()->SetStandardFormat( aFmt );
751 delete pQueryBox;
752 return 0;
756 IMPL_LINK( SmDistanceDialog, CheckBoxClickHdl, CheckBox *, pCheckBox )
758 if (pCheckBox == &aCheckBox1)
760 aCheckBox1.Toggle();
762 BOOL bChecked = aCheckBox1.IsChecked();
763 aFixedText4 .Enable( bChecked );
764 aMetricField4.Enable( bChecked );
766 return 0;
770 void SmDistanceDialog::SetHelpId(MetricField &rField, ULONG nHelpId)
772 //! HelpID's die auf diese Weise explizit gesetzt werden, muessen im
773 //! util Verzeichnis im File "hidother.src" mit Hilfe von "hidspecial"
774 //! definiert werden!
776 const XubString aEmptyText;
777 #if OSL_DEBUG_LEVEL > 1
778 DBG_ASSERT(aEmptyText.Len() == 0, "Sm: Ooops...");
779 #endif
781 rField.SetHelpId(nHelpId);
782 rField.SetHelpText(aEmptyText);
784 // since MetricField inherits from SpinField which has a sub Edit field
785 // (which is actually the one we modify) we have to set the help-id
786 // for it too.
787 Edit *pSubEdit = rField.GetSubEdit();
788 if (pSubEdit)
789 { pSubEdit->SetHelpId(nHelpId);
790 pSubEdit->SetHelpText(aEmptyText);
795 void SmDistanceDialog::SetCategory(USHORT nCategory)
797 #if OSL_DEBUG_LEVEL > 1
798 DBG_ASSERT(/*0 <= nCategory &&*/ nCategory < NOCATEGORIES,
799 "Sm: falsche Kategorienummer in SmDistanceDialog");
800 #endif
802 // array to convert category- and metricfield-number in help ids.
803 // 0 is used in case of unused combinations.
804 #if OSL_DEBUG_LEVEL > 1
805 DBG_ASSERT(NOCATEGORIES == 10, "Sm : Array passt nicht zu Anzahl der Kategorien");
806 #endif
807 ULONG __READONLY_DATA aCatMf2Hid[10][4] =
809 { HID_SMA_DEFAULT_DIST, HID_SMA_LINE_DIST, HID_SMA_ROOT_DIST, 0 },
810 { HID_SMA_SUP_DIST, HID_SMA_SUB_DIST , 0, 0 },
811 { HID_SMA_NUMERATOR_DIST, HID_SMA_DENOMINATOR_DIST, 0, 0 },
812 { HID_SMA_FRACLINE_EXCWIDTH, HID_SMA_FRACLINE_LINEWIDTH, 0, 0 },
813 { HID_SMA_UPPERLIMIT_DIST, HID_SMA_LOWERLIMIT_DIST, 0, 0 },
814 { HID_SMA_BRACKET_EXCHEIGHT, HID_SMA_BRACKET_DIST, 0, HID_SMA_BRACKET_EXCHEIGHT2 },
815 { HID_SMA_MATRIXROW_DIST, HID_SMA_MATRIXCOL_DIST, 0, 0 },
816 { HID_SMA_ATTRIBUT_DIST, HID_SMA_INTERATTRIBUT_DIST, 0, 0 },
817 { HID_SMA_OPERATOR_EXCHEIGHT, HID_SMA_OPERATOR_DIST, 0, 0 },
818 { HID_SMA_LEFTBORDER_DIST, HID_SMA_RIGHTBORDER_DIST, HID_SMA_UPPERBORDER_DIST, HID_SMA_LOWERBORDER_DIST }
821 // array to help iterate over the controls
822 Window * __READONLY_DATA aWin[4][2] =
824 { &aFixedText1, &aMetricField1 },
825 { &aFixedText2, &aMetricField2 },
826 { &aFixedText3, &aMetricField3 },
827 { &aFixedText4, &aMetricField4 }
830 SmCategoryDesc *pCat;
832 // merken der (evtl neuen) Einstellungen der aktiven SmCategoryDesc
833 // bevor zu der neuen gewechselt wird.
834 if (nActiveCategory != CATEGORY_NONE)
836 pCat = Categories[nActiveCategory];
837 pCat->SetValue(0, (USHORT) aMetricField1.GetValue());
838 pCat->SetValue(1, (USHORT) aMetricField2.GetValue());
839 pCat->SetValue(2, (USHORT) aMetricField3.GetValue());
840 pCat->SetValue(3, (USHORT) aMetricField4.GetValue());
842 if (nActiveCategory == 5)
843 bScaleAllBrackets = aCheckBox1.IsChecked();
845 aMenuButton.GetPopupMenu()->CheckItem(nActiveCategory + 1, FALSE);
848 // aktivieren/deaktivieren der zugehoerigen Controls in Abhaengigkeit von der
849 // gewaehlten Kategorie.
850 BOOL bActive;
851 for (USHORT i = 0; i < 4; i++)
853 FixedText *pFT = (FixedText * const) aWin[i][0];
854 MetricField *pMF = (MetricField * const) aWin[i][1];
856 // Um feststellen welche Controls aktiv sein sollen wird das
857 // vorhandensein einer zugehoerigen HelpID ueberprueft.
858 bActive = aCatMf2Hid[nCategory][i] != 0;
860 pFT->Show(bActive);
861 pFT->Enable(bActive);
862 pMF->Show(bActive);
863 pMF->Enable(bActive);
865 // setzen von Masseinheit und Anzahl der Nachkommastellen
866 FieldUnit eUnit;
867 USHORT nDigits;
868 if (nCategory < 9)
870 eUnit = FUNIT_CUSTOM;
871 nDigits = 0;
872 pMF->SetCustomUnitText( '%' );
874 else
876 eUnit = FUNIT_100TH_MM;
877 nDigits = 2;
879 pMF->SetUnit(eUnit); //! veraendert den Wert
880 pMF->SetDecimalDigits(nDigits);
882 if (bActive)
884 pCat = Categories[nCategory];
885 pFT->SetText(*pCat->GetString(i));
887 pMF->SetMin(pCat->GetMinimum(i));
888 pMF->SetMax(pCat->GetMaximum(i));
889 pMF->SetValue(pCat->GetValue(i));
891 SetHelpId(*pMF, aCatMf2Hid[nCategory][i]);
894 // nun noch die CheckBox und das zugehoerige MetricField genau dann aktivieren,
895 // falls es sich um das Klammer Menu handelt.
896 bActive = nCategory == 5;
897 aCheckBox1.Show(bActive);
898 aCheckBox1.Enable(bActive);
899 if (bActive)
901 aCheckBox1.Check( bScaleAllBrackets );
903 BOOL bChecked = aCheckBox1.IsChecked();
904 aFixedText4 .Enable( bChecked );
905 aMetricField4.Enable( bChecked );
908 aMenuButton.GetPopupMenu()->CheckItem(nCategory + 1, TRUE);
909 aFixedLine.SetText(Categories[nCategory]->GetName());
911 nActiveCategory = nCategory;
913 aMetricField1.GrabFocus();
914 Invalidate();
915 Update();
919 SmDistanceDialog::SmDistanceDialog(Window *pParent, BOOL bFreeRes)
920 : ModalDialog(pParent, SmResId(RID_DISTANCEDIALOG)),
921 aFixedText1 (this, SmResId(1)),
922 aMetricField1 (this, SmResId(1)),
923 aFixedText2 (this, SmResId(2)),
924 aMetricField2 (this, SmResId(2)),
925 aFixedText3 (this, SmResId(3)),
926 aMetricField3 (this, SmResId(3)),
927 aCheckBox1 (this, SmResId(1)),
928 aFixedText4 (this, SmResId(4)),
929 aMetricField4 (this, SmResId(4)),
930 aOKButton1 (this, SmResId(1)),
931 aCancelButton1 (this, SmResId(1)),
932 aMenuButton (this, SmResId(1)),
933 aDefaultButton (this, SmResId(1)),
934 aBitmap (this, SmResId(1)),
935 aFixedLine (this, SmResId(1))
937 for (USHORT i = 0; i < NOCATEGORIES; i++)
938 Categories[i] = new SmCategoryDesc(SmResId(i + 1), i);
939 nActiveCategory = CATEGORY_NONE;
940 bScaleAllBrackets = FALSE;
942 if (bFreeRes)
943 FreeResource();
945 ApplyImages();
947 // preview like controls should have a 2D look
948 aBitmap.SetBorderStyle( WINDOW_BORDER_MONO );
950 aMetricField1.SetGetFocusHdl(LINK(this, SmDistanceDialog, GetFocusHdl));
951 aMetricField2.SetGetFocusHdl(LINK(this, SmDistanceDialog, GetFocusHdl));
952 aMetricField3.SetGetFocusHdl(LINK(this, SmDistanceDialog, GetFocusHdl));
953 aMetricField4.SetGetFocusHdl(LINK(this, SmDistanceDialog, GetFocusHdl));
954 aCheckBox1.SetClickHdl(LINK(this, SmDistanceDialog, CheckBoxClickHdl));
956 aMenuButton.GetPopupMenu()->SetSelectHdl(LINK(this, SmDistanceDialog, MenuSelectHdl));
958 aDefaultButton.SetClickHdl(LINK(this, SmDistanceDialog, DefaultButtonClickHdl));
962 SmDistanceDialog::~SmDistanceDialog()
964 for (int i = 0; i < NOCATEGORIES; i++)
965 DELETEZ(Categories[i]);
968 void SmDistanceDialog::ApplyImages()
970 BOOL bHighContrast = GetDisplayBackground().GetColor().IsDark() != 0;
971 for (int i = 0; i < NOCATEGORIES; ++i)
973 SmCategoryDesc *pCat = Categories[i];
974 if (pCat)
975 pCat->SetHighContrast( bHighContrast );
979 void SmDistanceDialog::DataChanged( const DataChangedEvent &rEvt )
981 if ( (rEvt.GetType() == DATACHANGED_SETTINGS) && (rEvt.GetFlags() & SETTINGS_STYLE) )
982 ApplyImages();
984 ModalDialog::DataChanged( rEvt );
987 void SmDistanceDialog::ReadFrom(const SmFormat &rFormat)
989 Categories[0]->SetValue(0, rFormat.GetDistance(DIS_HORIZONTAL));
990 Categories[0]->SetValue(1, rFormat.GetDistance(DIS_VERTICAL));
991 Categories[0]->SetValue(2, rFormat.GetDistance(DIS_ROOT));
992 Categories[1]->SetValue(0, rFormat.GetDistance(DIS_SUPERSCRIPT));
993 Categories[1]->SetValue(1, rFormat.GetDistance(DIS_SUBSCRIPT));
994 Categories[2]->SetValue(0, rFormat.GetDistance(DIS_NUMERATOR));
995 Categories[2]->SetValue(1, rFormat.GetDistance(DIS_DENOMINATOR));
996 Categories[3]->SetValue(0, rFormat.GetDistance(DIS_FRACTION));
997 Categories[3]->SetValue(1, rFormat.GetDistance(DIS_STROKEWIDTH));
998 Categories[4]->SetValue(0, rFormat.GetDistance(DIS_UPPERLIMIT));
999 Categories[4]->SetValue(1, rFormat.GetDistance(DIS_LOWERLIMIT));
1000 Categories[5]->SetValue(0, rFormat.GetDistance(DIS_BRACKETSIZE));
1001 Categories[5]->SetValue(1, rFormat.GetDistance(DIS_BRACKETSPACE));
1002 Categories[5]->SetValue(3, rFormat.GetDistance(DIS_NORMALBRACKETSIZE));
1003 Categories[6]->SetValue(0, rFormat.GetDistance(DIS_MATRIXROW));
1004 Categories[6]->SetValue(1, rFormat.GetDistance(DIS_MATRIXCOL));
1005 Categories[7]->SetValue(0, rFormat.GetDistance(DIS_ORNAMENTSIZE));
1006 Categories[7]->SetValue(1, rFormat.GetDistance(DIS_ORNAMENTSPACE));
1007 Categories[8]->SetValue(0, rFormat.GetDistance(DIS_OPERATORSIZE));
1008 Categories[8]->SetValue(1, rFormat.GetDistance(DIS_OPERATORSPACE));
1009 Categories[9]->SetValue(0, rFormat.GetDistance(DIS_LEFTSPACE));
1010 Categories[9]->SetValue(1, rFormat.GetDistance(DIS_RIGHTSPACE));
1011 Categories[9]->SetValue(2, rFormat.GetDistance(DIS_TOPSPACE));
1012 Categories[9]->SetValue(3, rFormat.GetDistance(DIS_BOTTOMSPACE));
1014 bScaleAllBrackets = rFormat.IsScaleNormalBrackets();
1016 // force update (even of category 0) by setting nActiveCategory to a
1017 // non-existent category number
1018 nActiveCategory = CATEGORY_NONE;
1019 SetCategory(0);
1023 void SmDistanceDialog::WriteTo(SmFormat &rFormat) /*const*/
1025 // hmm... koennen die tatsaechlich unterschiedlich sein?
1026 // wenn nicht kann oben naemlich das const stehen!
1027 SetCategory(nActiveCategory);
1029 rFormat.SetDistance( DIS_HORIZONTAL, Categories[0]->GetValue(0) );
1030 rFormat.SetDistance( DIS_VERTICAL, Categories[0]->GetValue(1) );
1031 rFormat.SetDistance( DIS_ROOT, Categories[0]->GetValue(2) );
1032 rFormat.SetDistance( DIS_SUPERSCRIPT, Categories[1]->GetValue(0) );
1033 rFormat.SetDistance( DIS_SUBSCRIPT, Categories[1]->GetValue(1) );
1034 rFormat.SetDistance( DIS_NUMERATOR, Categories[2]->GetValue(0) );
1035 rFormat.SetDistance( DIS_DENOMINATOR, Categories[2]->GetValue(1) );
1036 rFormat.SetDistance( DIS_FRACTION, Categories[3]->GetValue(0) );
1037 rFormat.SetDistance( DIS_STROKEWIDTH, Categories[3]->GetValue(1) );
1038 rFormat.SetDistance( DIS_UPPERLIMIT, Categories[4]->GetValue(0) );
1039 rFormat.SetDistance( DIS_LOWERLIMIT, Categories[4]->GetValue(1) );
1040 rFormat.SetDistance( DIS_BRACKETSIZE, Categories[5]->GetValue(0) );
1041 rFormat.SetDistance( DIS_BRACKETSPACE, Categories[5]->GetValue(1) );
1042 rFormat.SetDistance( DIS_MATRIXROW, Categories[6]->GetValue(0) );
1043 rFormat.SetDistance( DIS_MATRIXCOL, Categories[6]->GetValue(1) );
1044 rFormat.SetDistance( DIS_ORNAMENTSIZE, Categories[7]->GetValue(0) );
1045 rFormat.SetDistance( DIS_ORNAMENTSPACE, Categories[7]->GetValue(1) );
1046 rFormat.SetDistance( DIS_OPERATORSIZE, Categories[8]->GetValue(0) );
1047 rFormat.SetDistance( DIS_OPERATORSPACE, Categories[8]->GetValue(1) );
1048 rFormat.SetDistance( DIS_LEFTSPACE, Categories[9]->GetValue(0) );
1049 rFormat.SetDistance( DIS_RIGHTSPACE, Categories[9]->GetValue(1) );
1050 rFormat.SetDistance( DIS_TOPSPACE, Categories[9]->GetValue(2) );
1051 rFormat.SetDistance( DIS_BOTTOMSPACE, Categories[9]->GetValue(3) );
1052 rFormat.SetDistance( DIS_NORMALBRACKETSIZE, Categories[5]->GetValue(3) );
1054 rFormat.SetScaleNormalBrackets( bScaleAllBrackets );
1056 rFormat.RequestApplyChanges();
1060 /**************************************************************************/
1063 IMPL_LINK( SmAlignDialog, DefaultButtonClickHdl, Button *, EMPTYARG /*pButton*/ )
1065 QueryBox *pQueryBox = new QueryBox(this, SmResId(RID_DEFAULTSAVEQUERY));
1067 if (pQueryBox->Execute() == RET_YES)
1069 SmModule *pp = SM_MOD1();
1070 SmFormat aFmt( pp->GetConfig()->GetStandardFormat() );
1071 WriteTo( aFmt );
1072 pp->GetConfig()->SetStandardFormat( aFmt );
1075 delete pQueryBox;
1076 return 0;
1080 SmAlignDialog::SmAlignDialog(Window * pParent, BOOL bFreeRes)
1081 : ModalDialog(pParent, SmResId(RID_ALIGNDIALOG)),
1082 aLeft (this, SmResId(1)),
1083 aCenter (this, SmResId(2)),
1084 aRight (this, SmResId(3)),
1085 aFixedLine1 (this, SmResId(1)),
1086 aOKButton1 (this, SmResId(1)),
1087 aCancelButton1 (this, SmResId(1)),
1088 aDefaultButton (this, SmResId(1))
1090 if (bFreeRes)
1091 FreeResource();
1093 aDefaultButton.SetClickHdl(LINK(this, SmAlignDialog, DefaultButtonClickHdl));
1097 void SmAlignDialog::ReadFrom(const SmFormat &rFormat)
1099 switch (rFormat.GetHorAlign())
1101 case AlignLeft:
1102 aLeft .Check(TRUE);
1103 aCenter.Check(FALSE);
1104 aRight .Check(FALSE);
1105 break;
1107 case AlignCenter:
1108 aLeft .Check(FALSE);
1109 aCenter.Check(TRUE);
1110 aRight .Check(FALSE);
1111 break;
1113 case AlignRight:
1114 aLeft .Check(FALSE);
1115 aCenter.Check(FALSE);
1116 aRight .Check(TRUE);
1117 break;
1122 void SmAlignDialog::WriteTo(SmFormat &rFormat) const
1124 if (aLeft.IsChecked())
1125 rFormat.SetHorAlign(AlignLeft);
1126 else if (aRight.IsChecked())
1127 rFormat.SetHorAlign(AlignRight);
1128 else
1129 rFormat.SetHorAlign(AlignCenter);
1131 rFormat.RequestApplyChanges();
1135 /**************************************************************************/
1138 void SmShowSymbolSet::Paint(const Rectangle&)
1140 Push(PUSH_MAPMODE);
1142 // MapUnit einstellen fuer die 'nLen' berechnet wurde
1143 SetMapMode(MapMode(MAP_PIXEL));
1145 USHORT v = sal::static_int_cast< USHORT >((aVScrollBar.GetThumbPos() * nColumns));
1146 USHORT nSymbols = aSymbolSet.GetCount();
1148 Color aTxtColor( GetTextColor() );
1149 for (USHORT i = v; i < nSymbols ; i++)
1151 SmSym aSymbol (aSymbolSet.GetSymbol(i));
1152 Font aFont (aSymbol.GetFace());
1153 aFont.SetAlign(ALIGN_TOP);
1155 // etwas kleinere FontSize nehmen (als nLen) um etwas Luft zu haben
1156 // (hoffentlich auch genug fuer links und rechts!)
1157 aFont.SetSize(Size(0, nLen - (nLen / 3)));
1158 SetFont(aFont);
1159 // keep text color
1160 SetTextColor( aTxtColor );
1162 int nIV = i - v;
1163 Size aSize(GetTextWidth(aSymbol.GetCharacter()), GetTextHeight());
1165 DrawText(Point((nIV % nColumns) * nLen + (nLen - aSize.Width()) / 2,
1166 (nIV / nColumns) * nLen + (nLen - aSize.Height()) / 2),
1167 aSymbol.GetCharacter());
1170 if (nSelectSymbol != SYMBOL_NONE)
1172 Invert(Rectangle(Point(((nSelectSymbol - v) % nColumns) * nLen,
1173 ((nSelectSymbol - v) / nColumns) * nLen),
1174 Size(nLen, nLen)));
1177 Pop();
1181 void SmShowSymbolSet::MouseButtonDown(const MouseEvent& rMEvt)
1183 GrabFocus();
1185 if (rMEvt.IsLeft() && Rectangle(Point(0, 0), aOutputSize).IsInside(rMEvt.GetPosPixel()))
1187 long nPos = (rMEvt.GetPosPixel().Y() / nLen) * nColumns + (rMEvt.GetPosPixel().X() / nLen) +
1188 aVScrollBar.GetThumbPos() * nColumns;
1189 SelectSymbol( sal::static_int_cast< USHORT >(nPos) );
1191 aSelectHdlLink.Call(this);
1193 if (rMEvt.GetClicks() > 1) aDblClickHdlLink.Call(this);
1195 else Control::MouseButtonDown (rMEvt);
1199 void SmShowSymbolSet::KeyInput(const KeyEvent& rKEvt)
1201 USHORT n = nSelectSymbol;
1203 if (n != SYMBOL_NONE)
1205 switch (rKEvt.GetKeyCode().GetCode())
1207 case KEY_DOWN: n = n + nColumns; break;
1208 case KEY_UP: n = n - nColumns; break;
1209 case KEY_LEFT: n -= 1; break;
1210 case KEY_RIGHT: n += 1; break;
1211 case KEY_HOME: n = 0; break;
1212 case KEY_END: n = aSymbolSet.GetCount() - 1; break;
1213 case KEY_PAGEUP: n -= nColumns * nRows; break;
1214 case KEY_PAGEDOWN: n += nColumns * nRows; break;
1216 default:
1217 Control::KeyInput(rKEvt);
1218 return;
1221 else
1222 n = 0;
1224 if (n >= aSymbolSet.GetCount())
1225 n = nSelectSymbol;
1227 // adjust scrollbar
1228 if ((n < (USHORT) (aVScrollBar.GetThumbPos() * nColumns)) ||
1229 (n >= (USHORT) ((aVScrollBar.GetThumbPos() + nRows) * nColumns)))
1231 aVScrollBar.SetThumbPos(n / nColumns);
1232 Invalidate();
1233 Update();
1236 SelectSymbol(n);
1237 aSelectHdlLink.Call(this);
1241 SmShowSymbolSet::SmShowSymbolSet(Window *pParent, const ResId& rResId) :
1242 Control(pParent, rResId),
1243 aVScrollBar(this, WinBits(WB_VSCROLL))
1245 nSelectSymbol = SYMBOL_NONE;
1247 aOutputSize = GetOutputSizePixel();
1248 long nScrollBarWidth = aVScrollBar.GetSizePixel().Width(),
1249 nUseableWidth = aOutputSize.Width() - nScrollBarWidth;
1251 // Hoehe von 16pt in Pixeln (passend zu 'aOutputSize')
1252 nLen = (USHORT) LogicToPixel(Size(0, 16), MapMode(MAP_POINT)).Height();
1254 nColumns = sal::static_int_cast< USHORT >(nUseableWidth / nLen);
1255 if (nColumns > 2 && nColumns % 2 != 0)
1256 nColumns--;
1257 nRows = sal::static_int_cast< USHORT >(aOutputSize.Height() / nLen);
1258 #if OSL_DEBUG_LEVEL > 1
1259 DBG_ASSERT(nColumns > 0, "Sm : keine Spalten");
1260 DBG_ASSERT(nRows > 0, "Sm : keine Zeilen");
1261 #endif
1263 // genau passend machen
1264 aOutputSize.Width() = nColumns * nLen;
1265 aOutputSize.Height() = nRows * nLen;
1267 aVScrollBar.SetPosSizePixel(Point(aOutputSize.Width() + 1, -1),
1268 Size(nScrollBarWidth, aOutputSize.Height() + 2));
1269 aVScrollBar.Enable(FALSE);
1270 aVScrollBar.Show();
1271 aVScrollBar.SetScrollHdl(LINK(this, SmShowSymbolSet, ScrollHdl));
1273 Size WindowSize (aOutputSize);
1274 WindowSize.Width() += nScrollBarWidth;
1275 SetOutputSizePixel(WindowSize);
1280 void SmShowSymbolSet::SetSymbolSet(const SmSymSet& rSymbolSet)
1282 aSymbolSet = rSymbolSet;
1284 if (aSymbolSet.GetCount() > (nColumns * nRows))
1286 aVScrollBar.SetRange(Range(0, ((aSymbolSet.GetCount() + (nColumns - 1)) / nColumns) - nRows));
1287 aVScrollBar.Enable(TRUE);
1289 else
1291 aVScrollBar.SetRange(Range(0,0));
1292 aVScrollBar.Enable (FALSE);
1295 Invalidate();
1299 void SmShowSymbolSet::SelectSymbol(USHORT nSymbol)
1301 int v = (int) (aVScrollBar.GetThumbPos() * nColumns);
1303 if (nSelectSymbol != SYMBOL_NONE)
1304 Invalidate(Rectangle(Point(((nSelectSymbol - v) % nColumns) * nLen,
1305 ((nSelectSymbol - v) / nColumns) * nLen),
1306 Size(nLen, nLen)));
1308 if (nSymbol < aSymbolSet.GetCount())
1309 nSelectSymbol = nSymbol;
1311 if (aSymbolSet.GetCount() == 0)
1312 nSelectSymbol = SYMBOL_NONE;
1314 if (nSelectSymbol != SYMBOL_NONE)
1315 Invalidate(Rectangle(Point(((nSelectSymbol - v) % nColumns) * nLen,
1316 ((nSelectSymbol - v) / nColumns) * nLen),
1317 Size(nLen, nLen)));
1319 Update();
1323 IMPL_LINK( SmShowSymbolSet, ScrollHdl, ScrollBar*, EMPTYARG /*pScrollBar*/)
1325 Invalidate();
1326 return 0;
1329 ////////////////////////////////////////////////////////////////////////////////
1331 void SmShowSymbol::Paint(const Rectangle &rRect)
1333 Control::Paint( rRect );
1335 const XubString &rText = GetText();
1336 Size aTextSize(GetTextWidth(rText), GetTextHeight());
1338 DrawText(Point((GetOutputSize().Width() - aTextSize.Width()) / 2,
1339 (GetOutputSize().Height() - aTextSize.Height()) / 2), rText);
1343 void SmShowSymbol::MouseButtonDown(const MouseEvent& rMEvt)
1345 if (rMEvt.GetClicks() > 1)
1346 aDblClickHdlLink.Call(this);
1347 else
1348 Control::MouseButtonDown (rMEvt);
1352 void SmShowSymbol::SetSymbol(const SmSym *pSymbol)
1354 if (pSymbol)
1356 Color aTxtColor( GetTextColor() );
1358 Font aFont (pSymbol->GetFace());
1359 aFont.SetSize(Size(0, GetOutputSize().Height() - GetOutputSize().Height() / 3));
1360 aFont.SetAlign(ALIGN_TOP);
1361 SetFont(aFont);
1363 // keep old text color (font may have different color set)
1364 SetTextColor(aTxtColor);
1366 SetText(XubString(pSymbol->GetCharacter()));
1369 // 'Invalidate' fuellt den background mit der background-Farbe.
1370 // Falls der NULL pointer uebergeben wurde reicht dies also zum loeschen
1371 // der Anzeige
1372 Invalidate();
1376 ////////////////////////////////////////////////////////////////////////////////
1378 void SmSymbolDialog::FillSymbolSets(BOOL bDeleteText)
1379 // fuellt die Eintraege der moeglichen 'SymbolsSet's im Dialog mit den
1380 // aktuellen Werten des SymbolSet Managers, selektiert aber keinen.
1382 aSymbolSets.Clear();
1383 if (bDeleteText)
1384 aSymbolSets.SetNoSelection();
1386 USHORT nNumSymSets = rSymSetMgr.GetSymbolSetCount();
1387 for (USHORT i = 0; i < nNumSymSets; i++)
1388 aSymbolSets.InsertEntry(rSymSetMgr.GetSymbolSet(i)->GetName());
1392 IMPL_LINK( SmSymbolDialog, SymbolSetChangeHdl, ListBox *, EMPTYARG pListBox )
1394 (void) pListBox;
1395 #if OSL_DEBUG_LEVEL > 1
1396 DBG_ASSERT(pListBox == &aSymbolSets, "Sm : falsches Argument");
1397 #endif
1399 SelectSymbolSet(aSymbolSets.GetSelectEntry());
1400 return 0;
1404 IMPL_LINK( SmSymbolDialog, SymbolChangeHdl, SmShowSymbolSet *, EMPTYARG pShowSymbolSet )
1406 (void) pShowSymbolSet;
1407 #if OSL_DEBUG_LEVEL > 1
1408 DBG_ASSERT(pShowSymbolSet == &aSymbolSetDisplay, "Sm : falsches Argument");
1409 #endif
1411 SelectSymbol(aSymbolSetDisplay.GetSelectSymbol());
1412 return 0;
1415 IMPL_LINK( SmSymbolDialog, EditClickHdl, Button *, EMPTYARG pButton )
1417 (void) pButton;
1418 #if OSL_DEBUG_LEVEL > 1
1419 DBG_ASSERT(pButton == &aEditBtn, "Sm : falsches Argument");
1420 #endif
1422 SmSymDefineDialog *pDialog = new SmSymDefineDialog(this, pFontListDev, rSymSetMgr);
1424 // aktuelles Symbol und SymbolSet am neuen Dialog setzen
1425 const XubString aSymSetName (aSymbolSets.GetSelectEntry()),
1426 aSymName (aSymbolName.GetText());
1427 pDialog->SelectOldSymbolSet(aSymSetName);
1428 pDialog->SelectOldSymbol(aSymName);
1429 pDialog->SelectSymbolSet(aSymSetName);
1430 pDialog->SelectSymbol(aSymName);
1432 // altes SymbolSet merken
1433 XubString aOldSymbolSet (aSymbolSets.GetSelectEntry());
1435 USHORT nSymPos = GetSelectedSymbol();
1437 // Dialog an evtl geaenderte Daten des SymbolSet Manager anpassen
1438 if (pDialog->Execute() == RET_OK && rSymSetMgr.IsModified())
1440 rSymSetMgr.Save();
1441 FillSymbolSets();
1444 // wenn das alte SymbolSet nicht mehr existiert zum ersten gehen
1445 // (soweit eines vorhanden ist)
1446 if (!SelectSymbolSet(aOldSymbolSet) && aSymbolSets.GetEntryCount() > 0)
1447 SelectSymbolSet(aSymbolSets.GetEntry(0));
1449 SelectSymbol( nSymPos );
1451 delete pDialog;
1452 return 0;
1456 IMPL_LINK( SmSymbolDialog, SymbolDblClickHdl, SmShowSymbolSet *, EMPTYARG pShowSymbolSet )
1458 (void) pShowSymbolSet;
1459 #if OSL_DEBUG_LEVEL > 1
1460 DBG_ASSERT(pShowSymbolSet == &aSymbolSetDisplay, "Sm : falsches Argument");
1461 #endif
1463 GetClickHdl(&aGetBtn);
1464 EndDialog(RET_OK);
1465 return 0;
1469 IMPL_LINK( SmSymbolDialog, GetClickHdl, Button *, EMPTYARG pButton )
1471 (void) pButton;
1472 #if OSL_DEBUG_LEVEL > 1
1473 DBG_ASSERT(pButton == &aGetBtn, "Sm : falscher Button");
1474 #endif
1476 const SmSym *pSym = GetSymbol();
1477 if (pSym)
1479 XubString aText ('%');
1480 aText += pSym->GetName();
1482 rViewSh.GetViewFrame()->GetDispatcher()->Execute(
1483 SID_INSERTTEXT, SFX_CALLMODE_STANDARD,
1484 new SfxStringItem(SID_INSERTTEXT, aText), 0L);
1487 return 0;
1491 IMPL_LINK_INLINE_START( SmSymbolDialog, CloseClickHdl, Button *, EMPTYARG pButton )
1493 (void) pButton;
1494 #if OSL_DEBUG_LEVEL > 1
1495 DBG_ASSERT(pButton == &aCloseBtn, "Sm : falscher Button");
1496 #endif
1498 EndDialog(TRUE);
1499 return 0;
1501 IMPL_LINK_INLINE_END( SmSymbolDialog, CloseClickHdl, Button *, pButton )
1504 SmSymbolDialog::SmSymbolDialog(Window *pParent, OutputDevice *pFntListDevice,
1505 SmSymSetManager &rMgr, SmViewShell &rViewShell, BOOL bFreeRes) :
1506 ModalDialog (pParent, SmResId(RID_SYMBOLDIALOG)),
1507 aSymbolSetText (this, SmResId(1)),
1508 aSymbolSets (this, SmResId(1)),
1509 aSymbolSetDisplay (this, SmResId(1)),
1510 aSymbolName (this, SmResId(2)),
1511 aSymbolDisplay (this, SmResId(2)),
1512 aGetBtn (this, SmResId(2)),
1513 aCloseBtn (this, SmResId(3)),
1514 aEditBtn (this, SmResId(1)),
1515 rViewSh (rViewShell),
1516 rSymSetMgr (rMgr),
1517 pFontListDev (pFntListDevice)
1519 if (bFreeRes)
1520 FreeResource();
1522 pSymSet = NULL;
1523 FillSymbolSets();
1524 if (aSymbolSets.GetEntryCount() > 0)
1525 SelectSymbolSet(aSymbolSets.GetEntry(0));
1527 InitColor_Impl();
1529 // preview like controls should have a 2D look
1530 aSymbolDisplay.SetBorderStyle( WINDOW_BORDER_MONO );
1532 aSymbolSets .SetSelectHdl (LINK(this, SmSymbolDialog, SymbolSetChangeHdl));
1533 aSymbolSetDisplay.SetSelectHdl (LINK(this, SmSymbolDialog, SymbolChangeHdl));
1534 aSymbolSetDisplay.SetDblClickHdl(LINK(this, SmSymbolDialog, SymbolDblClickHdl));
1535 aSymbolDisplay .SetDblClickHdl(LINK(this, SmSymbolDialog, SymbolDblClickHdl));
1536 aCloseBtn .SetClickHdl (LINK(this, SmSymbolDialog, CloseClickHdl));
1537 aEditBtn .SetClickHdl (LINK(this, SmSymbolDialog, EditClickHdl));
1538 aGetBtn .SetClickHdl (LINK(this, SmSymbolDialog, GetClickHdl));
1542 SmSymbolDialog::~SmSymbolDialog()
1547 void SmSymbolDialog::InitColor_Impl()
1549 #if OSL_DEBUG_LEVEL > 1
1550 Color aBC( GetDisplayBackground().GetColor() );
1551 #endif
1552 ColorData nBgCol = COL_WHITE,
1553 nTxtCol = COL_BLACK;
1554 if (GetDisplayBackground().GetColor().IsDark())
1556 const StyleSettings &rS = GetSettings().GetStyleSettings();
1557 nBgCol = rS.GetFieldColor().GetColor();
1558 nTxtCol = rS.GetFieldTextColor().GetColor();
1561 Color aTmpColor( nBgCol );
1562 Wallpaper aWall( aTmpColor );
1563 Color aTxtColor( nTxtCol );
1564 aSymbolDisplay .SetBackground( aWall );
1565 aSymbolDisplay .SetTextColor( aTxtColor );
1566 aSymbolSetDisplay.SetBackground( aWall );
1567 aSymbolSetDisplay.SetTextColor( aTxtColor );
1571 void SmSymbolDialog::DataChanged( const DataChangedEvent& rDCEvt )
1573 if ( rDCEvt.GetType() == DATACHANGED_SETTINGS &&
1574 (rDCEvt.GetFlags() & SETTINGS_STYLE) )
1575 InitColor_Impl();
1577 ModalDialog::DataChanged( rDCEvt );
1581 BOOL SmSymbolDialog::SelectSymbolSet(const XubString &rSymbolSetName)
1583 BOOL bRet = FALSE;
1584 USHORT nPos = aSymbolSets.GetEntryPos(rSymbolSetName);
1586 pSymSet = NULL;
1587 if (nPos != LISTBOX_ENTRY_NOTFOUND)
1589 aSymbolSets.SelectEntryPos(nPos);
1590 USHORT nSymbolSetNo = rSymSetMgr.GetSymbolSetPos(aSymbolSets.GetSelectEntry());
1591 pSymSet = rSymSetMgr.GetSymbolSet(nSymbolSetNo);
1592 #if OSL_DEBUG_LEVEL > 1
1593 DBG_ASSERT(pSymSet, "Sm : NULL pointer");
1594 #endif
1596 aSymbolSetDisplay.SetSymbolSet(*pSymSet);
1597 if (pSymSet->GetCount() > 0)
1598 SelectSymbol(0);
1600 bRet = TRUE;
1602 else
1603 aSymbolSets.SetNoSelection();
1605 return bRet;
1609 void SmSymbolDialog::SelectSymbol(USHORT nSymbolNo)
1611 const SmSym *pSym = NULL;
1612 if (pSymSet && nSymbolNo < pSymSet->GetCount())
1613 pSym = &pSymSet->GetSymbol(nSymbolNo);
1615 aSymbolSetDisplay.SelectSymbol(nSymbolNo);
1616 aSymbolDisplay.SetSymbol(pSym);
1617 aSymbolName.SetText(pSym ? pSym->GetName() : XubString());
1621 const SmSym * SmSymbolDialog::GetSymbol() const
1623 USHORT nSymbolNo = aSymbolSetDisplay.GetSelectSymbol();
1624 return pSymSet == NULL ? NULL : &pSymSet->GetSymbol(nSymbolNo);
1628 ////////////////////////////////////////////////////////////////////////////////
1631 void SmShowChar::Paint(const Rectangle &rRect)
1633 Control::Paint( rRect );
1635 XubString Text (GetText ());
1636 if (Text.Len() > 0)
1638 Size aTextSize(GetTextWidth(Text), GetTextHeight());
1640 DrawText(Point((GetOutputSize().Width() - aTextSize.Width()) / 2,
1641 (GetOutputSize().Height() - aTextSize.Height()) / 2), Text);
1646 void SmShowChar::SetChar(xub_Unicode aChar)
1648 SetText(XubString(aChar));
1649 Invalidate();
1653 void SmShowChar::SetFont(const Font &rFont)
1655 Color aTxtColor( GetTextColor() );
1657 Font aFont (rFont);
1658 Size aSize (Size(0, GetOutputSize().Height() - GetOutputSize().Height() / 3));
1660 aFont.SetSize(aSize);
1661 aFont.SetAlign(ALIGN_TOP);
1662 aFont.SetTransparent(TRUE);
1663 Control::SetFont(aFont);
1665 // keep text color (new font may have different one)
1666 SetTextColor( aTxtColor );
1668 Invalidate();
1671 ////////////////////////////////////////////////////////////////////////////////
1673 void SmSymDefineDialog::FillSymbols(ComboBox &rComboBox, BOOL bDeleteText)
1675 #if OSL_DEBUG_LEVEL > 1
1676 DBG_ASSERT(&rComboBox == &aOldSymbols || &rComboBox == &aSymbols,
1677 "Sm : falsche ComboBox");
1678 #endif
1680 rComboBox.Clear();
1681 if (bDeleteText)
1682 rComboBox.SetText(XubString());
1684 ComboBox &rSymbolSets = &rComboBox == &aOldSymbols ?
1685 aOldSymbolSets : aSymbolSets;
1686 const SmSymSet *pSymSet = GetSymbolSet(rSymbolSets);
1687 if (pSymSet)
1688 { USHORT nNumSymbols = pSymSet->GetCount();
1689 for (USHORT i = 0; i < nNumSymbols; i++)
1690 rComboBox.InsertEntry(pSymSet->GetSymbol(i).GetName());
1696 void SmSymDefineDialog::FillSymbolSets(ComboBox &rComboBox, BOOL bDeleteText)
1698 #if OSL_DEBUG_LEVEL > 1
1699 DBG_ASSERT(&rComboBox == &aOldSymbolSets || &rComboBox == &aSymbolSets,
1700 "Sm : falsche ComboBox");
1701 #endif
1703 rComboBox.Clear();
1704 if (bDeleteText)
1705 rComboBox.SetText(XubString());
1707 USHORT nNumSymSets = aSymSetMgrCopy.GetSymbolSetCount();
1708 for (USHORT i = 0; i < nNumSymSets; i++)
1709 rComboBox.InsertEntry(aSymSetMgrCopy.GetSymbolSet(i)->GetName());
1713 void SmSymDefineDialog::FillFonts(BOOL bDelete)
1715 aFonts.Clear();
1716 if (bDelete)
1717 aFonts.SetNoSelection();
1719 // alle Fonts der 'FontList' in die Fontliste aufnehmen
1720 // von denen mit gleichen Namen jedoch nur einen (denn der Style wird
1721 // ueber die 'FontStyleBox' gewaehlt und nicht auch noch hier)
1722 if (pFontList)
1724 USHORT nCount = pFontList->GetFontNameCount();
1725 for (USHORT i = 0; i < nCount; i++)
1726 aFonts.InsertEntry( pFontList->GetFontName(i).GetName() );
1731 void SmSymDefineDialog::FillStyles(BOOL bDeleteText)
1733 aStyles.Clear();
1734 if (bDeleteText)
1735 aStyles.SetText(XubString());
1737 XubString aText (aFonts.GetSelectEntry());
1738 if (aText.Len() != 0)
1740 //aStyles.Fill(aText, &aFontList);
1741 // eigene StyleName's verwenden
1742 const SmFontStyles &rStyles = GetFontStyles();
1743 for (USHORT i = 0; i < rStyles.GetCount(); i++)
1744 aStyles.InsertEntry( rStyles.GetStyleName(i) );
1746 #if OSL_DEBUG_LEVEL > 1
1747 DBG_ASSERT(aStyles.GetEntryCount() > 0, "Sm : keine Styles vorhanden");
1748 #endif
1749 aStyles.SetText( aStyles.GetEntry(0) );
1754 SmSymSet * SmSymDefineDialog::GetSymbolSet(const ComboBox &rComboBox)
1756 #if OSL_DEBUG_LEVEL > 1
1757 DBG_ASSERT(&rComboBox == &aOldSymbolSets || &rComboBox == &aSymbolSets,
1758 "Sm : falsche ComboBox");
1759 #endif
1760 USHORT nSymbolSetNo = aSymSetMgrCopy.GetSymbolSetPos(rComboBox.GetText());
1762 return nSymbolSetNo == SYMBOLSET_NONE ?
1763 NULL : aSymSetMgrCopy.GetSymbolSet(nSymbolSetNo);
1767 SmSym * SmSymDefineDialog::GetSymbol(const ComboBox &rComboBox)
1769 #if OSL_DEBUG_LEVEL > 1
1770 DBG_ASSERT(&rComboBox == &aOldSymbols || &rComboBox == &aSymbols,
1771 "Sm : falsche ComboBox");
1772 #endif
1773 return aSymSetMgrCopy.GetSymbolByName(rComboBox.GetText());
1777 IMPL_LINK( SmSymDefineDialog, OldSymbolChangeHdl, ComboBox *, EMPTYARG pComboBox )
1779 (void) pComboBox;
1780 #if OSL_DEBUG_LEVEL > 1
1781 DBG_ASSERT(pComboBox == &aOldSymbols, "Sm : falsches Argument");
1782 #endif
1783 SelectSymbol(aOldSymbols, aOldSymbols.GetText(), FALSE);
1784 return 0;
1788 IMPL_LINK( SmSymDefineDialog, OldSymbolSetChangeHdl, ComboBox *, EMPTYARG pComboBox )
1790 (void) pComboBox;
1791 #if OSL_DEBUG_LEVEL > 1
1792 DBG_ASSERT(pComboBox == &aOldSymbolSets, "Sm : falsches Argument");
1793 #endif
1794 SelectSymbolSet(aOldSymbolSets, aOldSymbolSets.GetText(), FALSE);
1795 return 0;
1799 IMPL_LINK( SmSymDefineDialog, ModifyHdl, ComboBox *, pComboBox )
1801 // merken der Cursorposition zum wiederherstellen derselben
1802 Selection aSelection (pComboBox->GetSelection());
1804 if (pComboBox == &aSymbols)
1805 SelectSymbol(aSymbols, aSymbols.GetText(), FALSE);
1806 else if (pComboBox == &aSymbolSets)
1807 SelectSymbolSet(aSymbolSets, aSymbolSets.GetText(), FALSE);
1808 else if (pComboBox == &aOldSymbols)
1809 // nur Namen aus der Liste erlauben
1810 SelectSymbol(aOldSymbols, aOldSymbols.GetText(), TRUE);
1811 else if (pComboBox == &aOldSymbolSets)
1812 // nur Namen aus der Liste erlauben
1813 SelectSymbolSet(aOldSymbolSets, aOldSymbolSets.GetText(), TRUE);
1814 else if (pComboBox == &aStyles)
1815 // nur Namen aus der Liste erlauben (ist hier eh immer der Fall)
1816 SelectStyle(aStyles.GetText(), TRUE);
1817 else
1819 #if OSL_DEBUG_LEVEL > 1
1820 DBG_ASSERT(0, "Sm : falsche ComboBox Argument");
1821 #endif
1824 pComboBox->SetSelection(aSelection);
1826 UpdateButtons();
1828 return 0;
1832 IMPL_LINK( SmSymDefineDialog, FontChangeHdl, ListBox *, EMPTYARG pListBox )
1834 (void) pListBox;
1835 #if OSL_DEBUG_LEVEL > 1
1836 DBG_ASSERT(pListBox == &aFonts, "Sm : falsches Argument");
1837 #endif
1839 SelectFont(aFonts.GetSelectEntry());
1840 return 0;
1844 IMPL_LINK( SmSymDefineDialog, SubsetChangeHdl, ListBox *, EMPTYARG pListBox )
1846 (void) pListBox;
1847 USHORT nPos = aFontsSubsetLB.GetSelectEntryPos();
1848 if (LISTBOX_ENTRY_NOTFOUND != nPos)
1850 const Subset* pSubset = reinterpret_cast<const Subset*> (aFontsSubsetLB.GetEntryData( nPos ));
1851 if (pSubset)
1853 aCharsetDisplay.SelectCharacter( pSubset->GetRangeMin() );
1856 return 0;
1860 IMPL_LINK( SmSymDefineDialog, StyleChangeHdl, ComboBox *, EMPTYARG pComboBox )
1862 (void) pComboBox;
1863 #if OSL_DEBUG_LEVEL > 1
1864 DBG_ASSERT(pComboBox == &aStyles, "Sm : falsches Argument");
1865 #endif
1867 SelectStyle(aStyles.GetText());
1868 return 0;
1872 IMPL_LINK( SmSymDefineDialog, CharHighlightHdl, Control *, EMPTYARG )
1874 sal_UCS4 cChar = aCharsetDisplay.GetSelectCharacter();
1876 #if OSL_DEBUG_LEVEL > 1
1877 DBG_ASSERT( pSubsetMap, "SubsetMap missing" );
1878 #endif
1879 if (pSubsetMap)
1881 const Subset* pSubset = pSubsetMap->GetSubsetByUnicode( cChar );
1882 if (pSubset)
1883 aFontsSubsetLB.SelectEntry( pSubset->GetName() );
1884 else
1885 aFontsSubsetLB.SetNoSelection();
1888 // TO_DO_UCS4 (#i74049): get rid of cast without loosing UCS4 functionality
1889 aSymbolDisplay.SetChar( sal::static_int_cast< sal_Unicode >(cChar) );
1890 UpdateButtons();
1891 return 0;
1895 IMPL_LINK( SmSymDefineDialog, AddClickHdl, Button *, EMPTYARG pButton )
1897 (void) pButton;
1898 #if OSL_DEBUG_LEVEL > 1
1899 DBG_ASSERT(pButton == &aAddBtn, "Sm : falsches Argument");
1900 DBG_ASSERT(aAddBtn.IsEnabled(), "Sm : Voraussetzungen erfuellt ??");
1901 #endif
1903 SmSymSet *pSymSet = GetSymbolSet(aSymbolSets);
1905 // SymbolSet einfuegen falls es noch nicht existiert
1906 if (!pSymSet)
1908 pSymSet = new SmSymSet(aSymbolSets.GetText());
1909 aSymSetMgrCopy.AddSymbolSet(pSymSet);
1910 FillSymbolSets(aOldSymbolSets, FALSE);
1911 FillSymbolSets(aSymbolSets, FALSE);
1913 #if OSL_DEBUG_LEVEL > 1
1914 DBG_ASSERT(pSymSet, "Sm : NULL pointer");
1915 #endif
1917 // Symbol ins SymbolSet einfuegen
1918 // TO_DO_UCS4 (#i74049): get rid of cast without loosing UCS4 functionality
1919 SmSym *pSym = new SmSym(aSymbols.GetText(), aCharsetDisplay.GetFont(),
1920 sal::static_int_cast< sal_Unicode >(aCharsetDisplay.GetSelectCharacter()),
1921 aSymbolSets.GetText());
1922 pSymSet->AddSymbol(pSym);
1924 // update der Hash Tabelle erzwingen (damit aAddBtn disabled wird).
1925 // (wird spaeter nach Ueberarbeitung von symbol.cxx ueberfluessig werden).
1926 aSymSetMgrCopy.ChangeSymbolSet((SmSymSet *)1);
1928 // Symbolliste aktualiseren
1929 FillSymbols(aOldSymbols ,FALSE);
1930 FillSymbols(aSymbols ,FALSE);
1932 UpdateButtons();
1934 return 0;
1938 IMPL_LINK( SmSymDefineDialog, ChangeClickHdl, Button *, EMPTYARG pButton )
1940 (void) pButton;
1941 #if OSL_DEBUG_LEVEL > 1
1942 DBG_ASSERT(pButton == &aChangeBtn, "Sm : falsches Argument");
1943 DBG_ASSERT(aChangeBtn.IsEnabled(), "Sm : Voraussetzungen erfuellt ??");
1944 #endif
1946 // finden des SymbolSets zum alten Symbol
1947 SmSymSet *pOldSymSet = GetSymbolSet(aOldSymbolSets);
1948 #if OSL_DEBUG_LEVEL > 1
1949 DBG_ASSERT(pOldSymSet, "Sm : NULL pointer");
1950 #endif
1952 // suchen des neuen SymbolSets
1953 SmSymSet *pNewSymSet = GetSymbolSet(aSymbolSets);
1954 // SymbolSet einfuegen falls es noch nicht existiert
1955 if (!pNewSymSet)
1957 pNewSymSet = new SmSymSet(aSymbolSets.GetText());
1958 aSymSetMgrCopy.AddSymbolSet(pNewSymSet);
1959 FillSymbolSets(aOldSymbolSets, FALSE);
1960 FillSymbolSets(aSymbolSets, FALSE);
1963 // das (alte) Symbol besorgen
1964 USHORT nSymbol = pOldSymSet->GetSymbolPos(aOldSymbols.GetText());
1965 SmSym *pSym = (SmSym *) &pOldSymSet->GetSymbol(nSymbol);
1966 #if OSL_DEBUG_LEVEL > 1
1967 DBG_ASSERT( SYMBOL_NONE != nSymbol, "symbol not found" );
1968 DBG_ASSERT(pSym, "Sm : NULL pointer");
1969 #endif
1971 // apply changes
1972 pSym->SetName( aSymbols.GetText() );
1973 //! get font from symbol-display since charset-display does not keep
1974 //! the bold attribut.
1975 pSym->SetFace( aSymbolDisplay.GetFont() );
1976 // TO_DO_UCS4 (#i74049): get rid of cast without loosing UCS4 functionality
1977 pSym->SetCharacter( sal::static_int_cast< sal_Unicode >(aCharsetDisplay.GetSelectCharacter()) );
1979 // das SymbolSet wechseln wenn noetig
1980 if (pOldSymSet != pNewSymSet)
1982 pNewSymSet->AddSymbol( new SmSym( *pSym ) );
1983 pOldSymSet->DeleteSymbol(nSymbol);
1986 // update controls
1988 // actualize symbol-lists in the dialog
1989 String aTmpOldSymbolName( pOrigSymbol->GetName() );
1990 aOldSymbols.SetText( String() );
1991 aOldSymbols.RemoveEntry( aTmpOldSymbolName );
1992 if (aSymbolSets.GetText() == aOldSymbolSets.GetText())
1993 aSymbols.RemoveEntry( aTmpOldSymbolName );
1994 // clear display for original symbol
1995 SetOrigSymbol(NULL, XubString());
1998 //!! den SymbolSet Manger dazu zwingen seinen HashTable zu aktualisieren,
1999 //!! um mit moeglich neuen bzw fehlenden alten Symbol Namen konform zu sein.
2000 aSymSetMgrCopy.ChangeSymbolSet((SmSymSet *)1);
2002 UpdateButtons();
2004 return 0;
2008 IMPL_LINK( SmSymDefineDialog, DeleteClickHdl, Button *, EMPTYARG pButton )
2010 (void) pButton;
2011 #if OSL_DEBUG_LEVEL > 1
2012 DBG_ASSERT(pButton == &aDeleteBtn, "Sm : falsches Argument");
2013 DBG_ASSERT(aDeleteBtn.IsEnabled(), "Sm : Voraussetzungen erfuellt ??");
2014 #endif
2016 if (pOrigSymbol)
2018 // loeschen des Symbols:
2020 // zugehoeriges SymbolSet finden
2021 SmSymSet *pSymSet = GetSymbolSet(aOldSymbolSets);
2022 // finden des Index
2023 XubString aTmpOldSymbolName (pOrigSymbol->GetName());
2024 USHORT nSymbolNo = pSymSet->GetSymbolPos(aTmpOldSymbolName);
2025 // Bezuege auf das Symbols loeschen
2026 SetOrigSymbol(NULL, XubString());
2027 // und weg mit dem Symbol
2028 pSymSet->DeleteSymbol(nSymbolNo);
2029 #if OSL_DEBUG_LEVEL > 1
2030 DBG_ASSERT(pSymSet, "Sm : NULL pointer");
2031 DBG_ASSERT(nSymbolNo != SYMBOL_NONE, "Sm : kein Symbol");
2032 #endif
2034 //!! den SymbolSet Manger dazu zwingen seinen HashTable zu aktualisieren,
2035 //!! was er naemlich nicht tut, wenn in einem seiner SymbolSets geaendert/
2036 //!! geloescht wird, was wiederum zu einem Absturz fuehren kann (wenn er
2037 //!! ueber ein nicht mehr existentes aber nicht entferntes Symbol iteriert).
2038 aSymSetMgrCopy.ChangeSymbolSet((SmSymSet *)1);
2040 // aktualisieren der Symboleintraege des Dialogs
2041 aOldSymbols.SetText(XubString());
2042 aOldSymbols.RemoveEntry(aTmpOldSymbolName);
2043 if (aSymbolSets.GetText() == aOldSymbolSets.GetText())
2044 aSymbols.RemoveEntry(aTmpOldSymbolName);
2047 UpdateButtons();
2049 return 0;
2053 void SmSymDefineDialog::UpdateButtons()
2055 BOOL bAdd = FALSE,
2056 bChange = FALSE,
2057 bDelete = FALSE,
2058 bEqual;
2059 XubString aTmpSymbolName (aSymbols.GetText()),
2060 aTmpSymbolSetName (aSymbolSets.GetText());
2062 if (aTmpSymbolName.Len() > 0 && aTmpSymbolSetName.Len() > 0)
2064 // alle Einstellungen gleich?
2065 //! (Font-, Style- und SymbolSet Name werden nicht case sensitiv verglichen)
2066 bEqual = pOrigSymbol
2067 && aTmpSymbolSetName.EqualsIgnoreCaseAscii(aOldSymbolSetName.GetText())
2068 && aTmpSymbolName.Equals(pOrigSymbol->GetName())
2069 && aFonts.GetSelectEntry().EqualsIgnoreCaseAscii(
2070 pOrigSymbol->GetFace().GetName())
2071 && aStyles.GetText().EqualsIgnoreCaseAscii(
2072 GetFontStyles().GetStyleName(pOrigSymbol->GetFace()))
2073 && aCharsetDisplay.GetSelectCharacter() == pOrigSymbol->GetCharacter();
2075 // hinzufuegen nur wenn es noch kein Symbol desgleichen Namens gibt
2076 bAdd = aSymSetMgrCopy.GetSymbolByName(aTmpSymbolName) == NULL;
2078 // loeschen nur wenn alle Einstellungen gleich sind
2079 bDelete = pOrigSymbol != NULL;
2081 // aendern wenn bei gleichem Namen mindestens eine Einstellung anders ist
2082 // oder wenn es noch kein Symbol des neuen Namens gibt (wuerde implizites
2083 // loeschen des bereits vorhandenen Symbols erfordern)
2084 BOOL bEqualName = pOrigSymbol && aTmpSymbolName == pOrigSymbol->GetName();
2085 bChange = pOrigSymbol && ( (bEqualName && !bEqual) || (!bEqualName && bAdd) );
2088 aAddBtn .Enable(bAdd);
2089 aChangeBtn.Enable(bChange);
2090 aDeleteBtn.Enable(bDelete);
2094 SmSymDefineDialog::SmSymDefineDialog(Window * pParent,
2095 OutputDevice *pFntListDevice, SmSymSetManager &rMgr, BOOL bFreeRes) :
2096 ModalDialog (pParent, SmResId(RID_SYMDEFINEDIALOG)),
2097 aOldSymbolText (this, SmResId(1)),
2098 aOldSymbols (this, SmResId(1)),
2099 aOldSymbolSetText (this, SmResId(2)),
2100 aOldSymbolSets (this, SmResId(2)),
2101 aCharsetDisplay (this, SmResId(1)),
2102 aSymbolText (this, SmResId(9)),
2103 aSymbols (this, SmResId(4)),
2104 aSymbolSetText (this, SmResId(10)),
2105 aSymbolSets (this, SmResId(5)),
2106 aFontText (this, SmResId(3)),
2107 aFonts (this, SmResId(1)),
2108 aFontsSubsetFT (this, SmResId( FT_FONTS_SUBSET )),
2109 aFontsSubsetLB (this, SmResId( LB_FONTS_SUBSET )),
2110 aStyleText (this, SmResId(4)),
2111 aStyles (this, SmResId(3)),
2112 aOldSymbolName (this, SmResId(7)),
2113 aOldSymbolDisplay (this, SmResId(3)),
2114 aOldSymbolSetName (this, SmResId(8)),
2115 aSymbolName (this, SmResId(5)),
2116 aSymbolDisplay (this, SmResId(2)),
2117 aSymbolSetName (this, SmResId(6)),
2118 aOkBtn (this, SmResId(1)),
2119 aCancelBtn (this, SmResId(1)),
2120 aAddBtn (this, SmResId(1)),
2121 aChangeBtn (this, SmResId(2)),
2122 aDeleteBtn (this, SmResId(3)),
2123 aRightArrow (this, SmResId(1)),
2124 aRigthArrow_Im (SmResId(1)),
2125 aRigthArrow_Im_HC (SmResId(2)), // hi-contrast version
2126 rSymSetMgr (rMgr),
2127 pSubsetMap (NULL),
2128 pFontList (NULL)
2130 if (bFreeRes)
2131 FreeResource();
2133 pFontList = new FontList( pFntListDevice );
2135 pOrigSymbol = 0;
2137 // make autocompletion for symbols case-sensitive
2138 aOldSymbols.EnableAutocomplete(TRUE, TRUE);
2139 aSymbols .EnableAutocomplete(TRUE, TRUE);
2141 FillFonts();
2142 if (aFonts.GetEntryCount() > 0)
2143 SelectFont(aFonts.GetEntry(0));
2145 InitColor_Impl();
2147 SetSymbolSetManager(rSymSetMgr);
2149 aOldSymbols .SetSelectHdl(LINK(this, SmSymDefineDialog, OldSymbolChangeHdl));
2150 aOldSymbolSets .SetSelectHdl(LINK(this, SmSymDefineDialog, OldSymbolSetChangeHdl));
2151 aSymbolSets .SetModifyHdl(LINK(this, SmSymDefineDialog, ModifyHdl));
2152 aOldSymbolSets .SetModifyHdl(LINK(this, SmSymDefineDialog, ModifyHdl));
2153 aSymbols .SetModifyHdl(LINK(this, SmSymDefineDialog, ModifyHdl));
2154 aOldSymbols .SetModifyHdl(LINK(this, SmSymDefineDialog, ModifyHdl));
2155 aStyles .SetModifyHdl(LINK(this, SmSymDefineDialog, ModifyHdl));
2156 aFonts .SetSelectHdl(LINK(this, SmSymDefineDialog, FontChangeHdl));
2157 aFontsSubsetLB .SetSelectHdl(LINK(this, SmSymDefineDialog, SubsetChangeHdl));
2158 aStyles .SetSelectHdl(LINK(this, SmSymDefineDialog, StyleChangeHdl));
2159 aAddBtn .SetClickHdl (LINK(this, SmSymDefineDialog, AddClickHdl));
2160 aChangeBtn .SetClickHdl (LINK(this, SmSymDefineDialog, ChangeClickHdl));
2161 aDeleteBtn .SetClickHdl (LINK(this, SmSymDefineDialog, DeleteClickHdl));
2162 aCharsetDisplay.SetHighlightHdl( LINK( this, SmSymDefineDialog, CharHighlightHdl ) );
2164 // preview like controls should have a 2D look
2165 aOldSymbolDisplay.SetBorderStyle( WINDOW_BORDER_MONO );
2166 aSymbolDisplay .SetBorderStyle( WINDOW_BORDER_MONO );
2170 SmSymDefineDialog::~SmSymDefineDialog()
2172 delete pSubsetMap;
2173 delete pOrigSymbol;
2176 void SmSymDefineDialog::InitColor_Impl()
2178 #if OSL_DEBUG_LEVEL > 1
2179 Color aBC( GetDisplayBackground().GetColor() );
2180 #endif
2181 ColorData nBgCol = COL_WHITE,
2182 nTxtCol = COL_BLACK;
2183 BOOL bHighContrast = GetDisplayBackground().GetColor().IsDark() != 0;
2184 if (bHighContrast)
2186 const StyleSettings &rS = GetSettings().GetStyleSettings();
2187 nBgCol = rS.GetFieldColor().GetColor();
2188 nTxtCol = rS.GetFieldTextColor().GetColor();
2191 Color aTmpColor( nBgCol );
2192 Wallpaper aWall( aTmpColor );
2193 Color aTxtColor( nTxtCol );
2194 aCharsetDisplay .SetBackground( aWall );
2195 aCharsetDisplay .SetTextColor( aTxtColor );
2196 aOldSymbolDisplay.SetBackground( aWall );
2197 aOldSymbolDisplay.SetTextColor( aTxtColor );
2198 aSymbolDisplay .SetBackground( aWall );
2199 aSymbolDisplay .SetTextColor( aTxtColor );
2201 const Image &rArrowRight = bHighContrast ? aRigthArrow_Im_HC : aRigthArrow_Im;
2202 aRightArrow.SetImage( rArrowRight );
2206 void SmSymDefineDialog::DataChanged( const DataChangedEvent& rDCEvt )
2208 if ( rDCEvt.GetType() == DATACHANGED_SETTINGS &&
2209 (rDCEvt.GetFlags() & SETTINGS_STYLE) )
2210 InitColor_Impl();
2212 ModalDialog::DataChanged( rDCEvt );
2216 short SmSymDefineDialog::Execute()
2218 short nResult = ModalDialog::Execute();
2220 // Aenderungen uebernehmen falls Dialog mit OK beendet wurde
2221 if (aSymSetMgrCopy.IsModified() && nResult == RET_OK)
2223 // leere SymbolSets aus dem Ergebnis entfernen.
2224 // Dabei von hinten durch das array iterieren, da beim loeschen die
2225 // Elemente aufruecken.
2226 USHORT nSymbolSets = aSymSetMgrCopy.GetSymbolSetCount();
2227 for (USHORT i = 0; i < nSymbolSets; i++)
2229 USHORT nIdx = nSymbolSets - 1 - i;
2230 if (aSymSetMgrCopy.GetSymbolSet(nIdx)->GetCount() == 0)
2231 aSymSetMgrCopy.DeleteSymbolSet(nIdx);
2236 rSymSetMgr = aSymSetMgrCopy;
2237 #ifdef DEBUG
2238 // USHORT nS = rSymSetMgr.GetSymbolSetCount();
2239 #endif
2242 return nResult;
2246 void SmSymDefineDialog::SetSymbolSetManager(const SmSymSetManager &rMgr)
2248 aSymSetMgrCopy = rMgr;
2249 #ifdef DEBUG
2250 // USHORT nS = aSymSetMgrCopy.GetSymbolSetCount();
2251 #endif
2253 // Das modified Flag der Kopie auf FALSE setzen, damit man spaeter damit
2254 // testen kann ob sich was geaendert hat.
2255 aSymSetMgrCopy.SetModified(FALSE);
2257 FillSymbolSets(aOldSymbolSets);
2258 if (aOldSymbolSets.GetEntryCount() > 0)
2259 SelectSymbolSet(aOldSymbolSets.GetEntry(0));
2260 FillSymbolSets(aSymbolSets);
2261 if (aSymbolSets.GetEntryCount() > 0)
2262 SelectSymbolSet(aSymbolSets.GetEntry(0));
2263 FillSymbols(aOldSymbols);
2264 if (aOldSymbols.GetEntryCount() > 0)
2265 SelectSymbol(aOldSymbols.GetEntry(0));
2266 FillSymbols(aSymbols);
2267 if (aSymbols.GetEntryCount() > 0)
2268 SelectSymbol(aSymbols.GetEntry(0));
2270 UpdateButtons();
2274 BOOL SmSymDefineDialog::SelectSymbolSet(ComboBox &rComboBox,
2275 const XubString &rSymbolSetName, BOOL bDeleteText)
2277 #if OSL_DEBUG_LEVEL > 1
2278 DBG_ASSERT(&rComboBox == &aOldSymbolSets || &rComboBox == &aSymbolSets,
2279 "Sm : falsche ComboBox");
2280 #endif
2282 // 'Normalisieren' des SymbolNamens (ohne leading und trailing Leerzeichen)
2283 XubString aNormName (rSymbolSetName);
2284 aNormName.EraseLeadingChars(' ');
2285 aNormName.EraseTrailingChars(' ');
2286 // und evtl Abweichungen in der Eingabe beseitigen
2287 rComboBox.SetText(aNormName);
2289 BOOL bRet = FALSE;
2290 USHORT nPos = rComboBox.GetEntryPos(aNormName);
2292 if (nPos != COMBOBOX_ENTRY_NOTFOUND)
2294 rComboBox.SetText(rComboBox.GetEntry(nPos));
2295 bRet = TRUE;
2297 else if (bDeleteText)
2298 rComboBox.SetText(XubString());
2300 BOOL bIsOld = &rComboBox == &aOldSymbolSets;
2302 // setzen des SymbolSet Namens an der zugehoerigen Darstellung
2303 FixedText &rFT = bIsOld ? aOldSymbolSetName : aSymbolSetName;
2304 rFT.SetText(rComboBox.GetText());
2306 // setzen der zum SymbolSet gehoerenden Symbol Namen an der zugehoerigen
2307 // Auswahbox
2308 ComboBox &rCB = bIsOld ? aOldSymbols : aSymbols;
2309 FillSymbols(rCB, FALSE);
2311 // bei Wechsel des SymbolSets fuer das alte Zeichen ein gueltiges
2312 // Symbol bzw keins zur Anzeige bringen
2313 if (bIsOld)
2315 XubString aTmpOldSymbolName;
2316 if (aOldSymbols.GetEntryCount() > 0)
2317 aTmpOldSymbolName = aOldSymbols.GetEntry(0);
2318 SelectSymbol(aOldSymbols, aTmpOldSymbolName, TRUE);
2321 UpdateButtons();
2323 return bRet;
2327 void SmSymDefineDialog::SetOrigSymbol(const SmSym *pSymbol,
2328 const XubString &rSymbolSetName)
2330 // clear old symbol
2331 delete pOrigSymbol;
2332 pOrigSymbol = 0;
2334 XubString aSymName,
2335 aSymSetName;
2336 if (pSymbol)
2338 // set new symbol
2339 pOrigSymbol = new SmSym( *pSymbol );
2341 aSymName = pSymbol->GetName();
2342 aSymSetName = rSymbolSetName;
2343 aOldSymbolDisplay.SetFont(pSymbol->GetFace());
2344 aOldSymbolDisplay.SetChar(pSymbol->GetCharacter());
2346 else
2347 { // loeschen des angezeigten Symbols
2348 aOldSymbolDisplay.SetText(XubString());
2349 aOldSymbolDisplay.Invalidate();
2351 aOldSymbolName .SetText(aSymName);
2352 aOldSymbolSetName.SetText(aSymSetName);
2356 BOOL SmSymDefineDialog::SelectSymbol(ComboBox &rComboBox,
2357 const XubString &rSymbolName, BOOL bDeleteText)
2359 #if OSL_DEBUG_LEVEL > 1
2360 DBG_ASSERT(&rComboBox == &aOldSymbols || &rComboBox == &aSymbols,
2361 "Sm : falsche ComboBox");
2362 #endif
2364 // 'Normalisieren' des SymbolNamens (ohne Leerzeichen)
2365 XubString aNormName (rSymbolName);
2366 aNormName.EraseAllChars(' ');
2367 // und evtl Abweichungen in der Eingabe beseitigen
2368 rComboBox.SetText(aNormName);
2370 BOOL bRet = FALSE;
2371 USHORT nPos = rComboBox.GetEntryPos(aNormName);
2373 BOOL bIsOld = &rComboBox == &aOldSymbols;
2375 if (nPos != COMBOBOX_ENTRY_NOTFOUND)
2377 rComboBox.SetText(rComboBox.GetEntry(nPos));
2379 if (!bIsOld)
2381 const SmSym *pSymbol = GetSymbol(aSymbols);
2382 if (pSymbol)
2384 // Font und Style entsprechend waehlen
2385 const Font &rFont = pSymbol->GetFace();
2386 SelectFont(rFont.GetName(), FALSE);
2387 SelectStyle(GetFontStyles().GetStyleName(rFont), FALSE);
2389 // da das setzen des Fonts ueber den Style Namen des SymbolsFonts nicht
2390 // so gut klappt (er kann zB leer sein obwohl der Font selbst 'bold' und
2391 // 'italic' ist!). Setzen wir hier den Font wie er zum Symbol gehoert
2392 // zu Fuss.
2393 aCharsetDisplay.SetFont(rFont);
2394 aSymbolDisplay.SetFont(rFont);
2396 // das zugehoerige Zeichen auswaehlen
2397 SelectChar(pSymbol->GetCharacter());
2401 bRet = TRUE;
2403 else if (bDeleteText)
2404 rComboBox.SetText(XubString());
2406 if (bIsOld)
2408 // bei Wechsel des alten Symbols nur vorhandene anzeigen sonst keins
2409 const SmSym *pOldSymbol = NULL;
2410 XubString aTMpOldSymbolSetName;
2411 if (nPos != COMBOBOX_ENTRY_NOTFOUND)
2413 pOldSymbol = aSymSetMgrCopy.GetSymbolByName(aNormName);
2414 aTMpOldSymbolSetName = aOldSymbolSets.GetText();
2416 SetOrigSymbol(pOldSymbol, aTMpOldSymbolSetName);
2418 else
2419 aSymbolName.SetText(rComboBox.GetText());
2421 UpdateButtons();
2423 return bRet;
2427 void SmSymDefineDialog::SetFont(const XubString &rFontName, const XubString &rStyleName)
2429 // Font (FontInfo) passend zu Namen und Style holen
2430 FontInfo aFI;
2431 if (pFontList)
2432 aFI = pFontList->Get(rFontName, WEIGHT_NORMAL, ITALIC_NONE);
2433 SetFontStyle(rStyleName, aFI);
2435 aCharsetDisplay.SetFont(aFI);
2436 aSymbolDisplay.SetFont(aFI);
2438 // update subset listbox for new font's unicode subsets
2439 FontCharMap aFontCharMap;
2440 aCharsetDisplay.GetFontCharMap( aFontCharMap );
2441 if (pSubsetMap)
2442 delete pSubsetMap;
2443 pSubsetMap = new SubsetMap( &aFontCharMap );
2445 aFontsSubsetLB.Clear();
2446 bool bFirst = true;
2447 const Subset* pSubset;
2448 while( NULL != (pSubset = pSubsetMap->GetNextSubset( bFirst )) )
2450 USHORT nPos = aFontsSubsetLB.InsertEntry( pSubset->GetName());
2451 aFontsSubsetLB.SetEntryData( nPos, (void *) pSubset );
2452 // subset must live at least as long as the selected font !!!
2453 if( bFirst )
2454 aFontsSubsetLB.SelectEntryPos( nPos );
2455 bFirst = false;
2457 if( bFirst )
2458 aFontsSubsetLB.SetNoSelection();
2459 aFontsSubsetLB.Enable( !bFirst );
2463 BOOL SmSymDefineDialog::SelectFont(const XubString &rFontName, BOOL bApplyFont)
2465 BOOL bRet = FALSE;
2466 USHORT nPos = aFonts.GetEntryPos(rFontName);
2468 if (nPos != LISTBOX_ENTRY_NOTFOUND)
2470 aFonts.SelectEntryPos(nPos);
2471 if (aStyles.GetEntryCount() > 0)
2472 SelectStyle(aStyles.GetEntry(0));
2473 if (bApplyFont)
2474 SetFont(aFonts.GetSelectEntry(), aStyles.GetText());
2475 bRet = TRUE;
2477 else
2478 aFonts.SetNoSelection();
2479 FillStyles();
2481 UpdateButtons();
2483 return bRet;
2487 BOOL SmSymDefineDialog::SelectStyle(const XubString &rStyleName, BOOL bApplyFont)
2489 BOOL bRet = FALSE;
2490 USHORT nPos = aStyles.GetEntryPos(rStyleName);
2492 // falls der Style nicht zur Auswahl steht nehmen wir den erst moeglichen
2493 // (sofern vorhanden)
2494 if (nPos == COMBOBOX_ENTRY_NOTFOUND && aStyles.GetEntryCount() > 0)
2495 nPos = 0;
2497 if (nPos != COMBOBOX_ENTRY_NOTFOUND)
2499 aStyles.SetText(aStyles.GetEntry(nPos));
2500 if (bApplyFont)
2501 SetFont(aFonts.GetSelectEntry(), aStyles.GetText());
2502 bRet = TRUE;
2504 else
2505 aStyles.SetText(XubString());
2507 UpdateButtons();
2509 return bRet;
2513 void SmSymDefineDialog::SelectChar(xub_Unicode cChar)
2515 aCharsetDisplay.SelectCharacter( cChar );
2516 aSymbolDisplay.SetChar( cChar );
2518 UpdateButtons();
2522 /**************************************************************************/