1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include "tools/rcid.h"
21 #include <comphelper/string.hxx>
22 #include <svl/eitem.hxx>
23 #include <svl/intitem.hxx>
24 #include <svl/stritem.hxx>
25 #include <sfx2/app.hxx>
26 #include <vcl/msgbox.hxx>
27 #include <svtools/ctrltool.hxx>
28 #include <sfx2/printer.hxx>
29 #include <vcl/help.hxx>
30 #include <vcl/waitobj.hxx>
31 #include <vcl/settings.hxx>
32 #include <vcl/wall.hxx>
33 #include <sfx2/dispatch.hxx>
34 #include <sfx2/sfx.hrc>
35 #include <osl/diagnose.h>
36 #include <svx/ucsubset.hxx>
40 #include "starmath.hrc"
46 #include "document.hxx"
47 #include "unomodel.hxx"
50 // Since it's better to set/query the FontStyle via its attributes rather
51 // than via the StyleName we create a way to translate
52 // Attribute <-> StyleName
65 sal_uInt16
GetCount() const { return 4; }
66 const OUString
& GetStyleName( const Font
&rFont
) const;
67 const OUString
& GetStyleName( sal_uInt16 nIdx
) const;
71 SmFontStyles::SmFontStyles() :
72 aNormal ( ResId( RID_FONTREGULAR
, *SM_MOD()->GetResMgr() ) ),
73 aBold ( ResId( RID_FONTBOLD
, *SM_MOD()->GetResMgr() ) ),
74 aItalic ( ResId( RID_FONTITALIC
, *SM_MOD()->GetResMgr() ) )
79 aBoldItalic
+= aItalic
;
83 const OUString
& SmFontStyles::GetStyleName( const Font
&rFont
) const
85 //! compare also SmSpecialNode::Prepare
86 bool bBold
= IsBold( rFont
),
87 bItalic
= IsItalic( rFont
);
99 const OUString
& SmFontStyles::GetStyleName( sal_uInt16 nIdx
) const
101 // 0 = "normal", 1 = "italic",
102 // 2 = "bold", 3 = "bold italic"
104 #if OSL_DEBUG_LEVEL > 1
105 OSL_ENSURE( nIdx
< GetCount(), "index out of range" );
109 case 0 : return aNormal
;
110 case 1 : return aItalic
;
111 case 2 : return aBold
;
112 case 3 : return aBoldItalic
;
118 const SmFontStyles
& GetFontStyles()
120 static const SmFontStyles aImpl
;
124 /////////////////////////////////////////////////////////////////
126 void SetFontStyle(const OUString
&rStyleName
, Font
&rFont
)
128 // Find index related to StyleName. For an empty StyleName it's assumed to be
129 // 0 (neither bold nor italic).
130 sal_uInt16 nIndex
= 0;
131 if (!rStyleName
.isEmpty())
134 const SmFontStyles
&rStyles
= GetFontStyles();
135 for (i
= 0; i
< rStyles
.GetCount(); ++i
)
136 if (rStyleName
== rStyles
.GetStyleName(i
))
138 #if OSL_DEBUG_LEVEL > 1
139 OSL_ENSURE(i
< rStyles
.GetCount(), "style-name unknown");
144 rFont
.SetItalic((nIndex
& 0x1) ? ITALIC_NORMAL
: ITALIC_NONE
);
145 rFont
.SetWeight((nIndex
& 0x2) ? WEIGHT_BOLD
: WEIGHT_NORMAL
);
149 /**************************************************************************/
151 IMPL_LINK_INLINE_START( SmPrintOptionsTabPage
, SizeButtonClickHdl
, Button
*, EMPTYARG
/*pButton*/ )
153 aZoom
.Enable(aSizeZoomed
.IsChecked());
156 IMPL_LINK_INLINE_END( SmPrintOptionsTabPage
, SizeButtonClickHdl
, Button
*, pButton
)
159 SmPrintOptionsTabPage::SmPrintOptionsTabPage(Window
*pParent
, const SfxItemSet
&rOptions
)
160 : SfxTabPage(pParent
, SmResId(RID_PRINTOPTIONPAGE
), rOptions
),
161 aFixedLine1 (this, SmResId( FL_PRINTOPTIONS
)),
162 aTitle (this, SmResId( CB_TITLEROW
)),
163 aText (this, SmResId( CB_EQUATION_TEXT
)),
164 aFrame (this, SmResId( CB_FRAME
)),
165 aFixedLine2 (this, SmResId( FL_PRINT_FORMAT
)),
166 aSizeNormal (this, SmResId( RB_ORIGINAL_SIZE
)),
167 aSizeScaled (this, SmResId( RB_FIT_TO_PAGE
)),
168 aSizeZoomed (this, SmResId( RB_ZOOM
)),
169 aZoom (this, SmResId( MF_ZOOM
)),
170 aFixedLine3 (this, SmResId( FL_MISC_OPTIONS
)),
171 aNoRightSpaces (this, SmResId( CB_IGNORE_SPACING
)),
172 aSaveOnlyUsedSymbols (this, SmResId( CB_SAVE_ONLY_USED_SYMBOLS
))
176 aSizeNormal
.SetClickHdl(LINK(this, SmPrintOptionsTabPage
, SizeButtonClickHdl
));
177 aSizeScaled
.SetClickHdl(LINK(this, SmPrintOptionsTabPage
, SizeButtonClickHdl
));
178 aSizeZoomed
.SetClickHdl(LINK(this, SmPrintOptionsTabPage
, SizeButtonClickHdl
));
184 sal_Bool
SmPrintOptionsTabPage::FillItemSet(SfxItemSet
& rSet
)
186 sal_uInt16 nPrintSize
;
187 if (aSizeNormal
.IsChecked())
188 nPrintSize
= PRINT_SIZE_NORMAL
;
189 else if (aSizeScaled
.IsChecked())
190 nPrintSize
= PRINT_SIZE_SCALED
;
192 nPrintSize
= PRINT_SIZE_ZOOMED
;
194 rSet
.Put(SfxUInt16Item(GetWhich(SID_PRINTSIZE
), (sal_uInt16
) nPrintSize
));
195 rSet
.Put(SfxUInt16Item(GetWhich(SID_PRINTZOOM
), (sal_uInt16
) aZoom
.GetValue()));
196 rSet
.Put(SfxBoolItem(GetWhich(SID_PRINTTITLE
), aTitle
.IsChecked()));
197 rSet
.Put(SfxBoolItem(GetWhich(SID_PRINTTEXT
), aText
.IsChecked()));
198 rSet
.Put(SfxBoolItem(GetWhich(SID_PRINTFRAME
), aFrame
.IsChecked()));
199 rSet
.Put(SfxBoolItem(GetWhich(SID_NO_RIGHT_SPACES
), aNoRightSpaces
.IsChecked()));
200 rSet
.Put(SfxBoolItem(GetWhich(SID_SAVE_ONLY_USED_SYMBOLS
), aSaveOnlyUsedSymbols
.IsChecked()));
206 void SmPrintOptionsTabPage::Reset(const SfxItemSet
& rSet
)
208 SmPrintSize ePrintSize
= (SmPrintSize
)((const SfxUInt16Item
&)rSet
.Get(GetWhich(SID_PRINTSIZE
))).GetValue();
210 aSizeNormal
.Check(ePrintSize
== PRINT_SIZE_NORMAL
);
211 aSizeScaled
.Check(ePrintSize
== PRINT_SIZE_SCALED
);
212 aSizeZoomed
.Check(ePrintSize
== PRINT_SIZE_ZOOMED
);
214 aZoom
.Enable(aSizeZoomed
.IsChecked());
216 aZoom
.SetValue(((const SfxUInt16Item
&)rSet
.Get(GetWhich(SID_PRINTZOOM
))).GetValue());
218 aTitle
.Check(((const SfxBoolItem
&)rSet
.Get(GetWhich(SID_PRINTTITLE
))).GetValue());
219 aText
.Check(((const SfxBoolItem
&)rSet
.Get(GetWhich(SID_PRINTTEXT
))).GetValue());
220 aFrame
.Check(((const SfxBoolItem
&)rSet
.Get(GetWhich(SID_PRINTFRAME
))).GetValue());
221 aNoRightSpaces
.Check(((const SfxBoolItem
&)rSet
.Get(GetWhich(SID_NO_RIGHT_SPACES
))).GetValue());
222 aSaveOnlyUsedSymbols
.Check(((const SfxBoolItem
&)rSet
.Get(GetWhich(SID_SAVE_ONLY_USED_SYMBOLS
))).GetValue());
226 SfxTabPage
* SmPrintOptionsTabPage::Create(Window
* pWindow
, const SfxItemSet
& rSet
)
228 return (new SmPrintOptionsTabPage(pWindow
, rSet
));
231 /**************************************************************************/
234 void SmShowFont::Paint(const Rectangle
& rRect
)
236 Control::Paint( rRect
);
238 OUString
Text (GetFont().GetName());
239 Size
TextSize(GetTextWidth(Text
), GetTextHeight());
241 DrawText(Point((GetOutputSize().Width() - TextSize
.Width()) / 2,
242 (GetOutputSize().Height() - TextSize
.Height()) / 2), Text
);
246 void SmShowFont::SetFont(const Font
& rFont
)
248 Color
aTxtColor( GetTextColor() );
252 aFont
.SetSize(Size(0, 24));
253 aFont
.SetAlign(ALIGN_TOP
);
254 Control::SetFont(aFont
);
256 // keep old text color (new font may have different color)
257 SetTextColor( aTxtColor
);
261 IMPL_LINK_INLINE_START( SmFontDialog
, FontSelectHdl
, ComboBox
*, pComboBox
)
263 Face
.SetName(pComboBox
->GetText());
264 aShowFont
.SetFont(Face
);
267 IMPL_LINK_INLINE_END( SmFontDialog
, FontSelectHdl
, ComboBox
*, pComboBox
)
270 IMPL_LINK( SmFontDialog
, FontModifyHdl
, ComboBox
*, pComboBox
)
272 // if font is available in list then use it
273 sal_uInt16 nPos
= pComboBox
->GetEntryPos( pComboBox
->GetText() );
274 if (COMBOBOX_ENTRY_NOTFOUND
!= nPos
)
276 FontSelectHdl( pComboBox
);
282 IMPL_LINK( SmFontDialog
, AttrChangeHdl
, CheckBox
*, EMPTYARG
/*pCheckBox*/ )
284 if (aBoldCheckBox
.IsChecked())
285 Face
.SetWeight(FontWeight(WEIGHT_BOLD
));
287 Face
.SetWeight(FontWeight(WEIGHT_NORMAL
));
289 if (aItalicCheckBox
.IsChecked())
290 Face
.SetItalic(ITALIC_NORMAL
);
292 Face
.SetItalic(ITALIC_NONE
);
294 aShowFont
.SetFont(Face
);
299 void SmFontDialog::SetFont(const Font
&rFont
)
303 aFontBox
.SetText( Face
.GetName() );
304 aBoldCheckBox
.Check( IsBold( Face
) );
305 aItalicCheckBox
.Check( IsItalic( Face
) );
307 aShowFont
.SetFont(Face
);
310 IMPL_LINK( SmFontDialog
, HelpButtonClickHdl
, Button
*, EMPTYARG
/*pButton*/ )
313 Help
* pHelp
= Application::GetHelp();
316 pHelp
->Start( OUString( "HID_SMA_FONTDIALOG" ), &aHelpButton1
);
321 SmFontDialog::SmFontDialog(Window
* pParent
,
322 OutputDevice
*pFntListDevice
, bool bHideCheckboxes
, bool bFreeRes
)
323 : ModalDialog(pParent
,SmResId(RID_FONTDIALOG
)),
324 aFixedText1 (this, SmResId(1)),
325 aFontBox (this, SmResId(1)),
326 aBoldCheckBox (this, SmResId(1)),
327 aItalicCheckBox (this, SmResId(2)),
328 aOKButton1 (this, SmResId(1)),
329 aHelpButton1 (this, SmResId(1)),
330 aCancelButton1 (this, SmResId(1)),
331 aShowFont (this, SmResId(1)),
332 aFixedText2 (this, SmResId(2))
336 aHelpButton1
.SetClickHdl(LINK(this, SmFontDialog
, HelpButtonClickHdl
));
339 WaitObject
aWait( this );
341 FontList
aFontList( pFntListDevice
);
343 sal_uInt16 nCount
= aFontList
.GetFontNameCount();
344 for (sal_uInt16 i
= 0; i
< nCount
; i
++)
345 aFontBox
.InsertEntry( aFontList
.GetFontName(i
).GetName() );
347 Face
.SetSize(Size(0, 24));
348 Face
.SetWeight(WEIGHT_NORMAL
);
349 Face
.SetItalic(ITALIC_NONE
);
350 Face
.SetFamily(FAMILY_DONTKNOW
);
351 Face
.SetPitch(PITCH_DONTKNOW
);
352 Face
.SetCharSet(RTL_TEXTENCODING_DONTKNOW
);
353 Face
.SetTransparent(true);
357 // preview like controls should have a 2D look
358 aShowFont
.SetBorderStyle( WINDOW_BORDER_MONO
);
361 aFontBox
.SetSelectHdl(LINK(this, SmFontDialog
, FontSelectHdl
));
362 aFontBox
.SetModifyHdl(LINK(this, SmFontDialog
, FontModifyHdl
));
363 aBoldCheckBox
.SetClickHdl(LINK(this, SmFontDialog
, AttrChangeHdl
));
364 aItalicCheckBox
.SetClickHdl(LINK(this, SmFontDialog
, AttrChangeHdl
));
368 aBoldCheckBox
.Check( false );
369 aBoldCheckBox
.Enable( false );
370 aBoldCheckBox
.Show( false );
371 aItalicCheckBox
.Check( false );
372 aItalicCheckBox
.Enable( false );
373 aItalicCheckBox
.Show( false );
374 aFixedText2
.Show( false );
376 Size
aSize( aFontBox
.GetSizePixel() );
377 long nComboBoxBottom
= aFontBox
.GetPosPixel().Y() + aFontBox
.GetSizePixel().Height();
378 long nCheckBoxBottom
= aItalicCheckBox
.GetPosPixel().Y() + aItalicCheckBox
.GetSizePixel().Height();
379 aSize
.Height() += nCheckBoxBottom
- nComboBoxBottom
;
380 aFontBox
.SetSizePixel( aSize
);
384 void SmFontDialog::InitColor_Impl()
386 #if OSL_DEBUG_LEVEL > 1
387 Color
aBC( GetDisplayBackground().GetColor() );
389 ColorData nBgCol
= COL_WHITE
,
391 const StyleSettings
&rS
= GetSettings().GetStyleSettings();
392 if (rS
.GetHighContrastMode())
394 nBgCol
= rS
.GetFieldColor().GetColor();
395 nTxtCol
= rS
.GetFieldTextColor().GetColor();
398 Color
aTmpColor( nBgCol
);
399 Wallpaper
aWall( aTmpColor
);
400 Color
aTxtColor( nTxtCol
);
401 aShowFont
.SetBackground( aWall
);
402 aShowFont
.SetTextColor( aTxtColor
);
405 void SmFontDialog::DataChanged( const DataChangedEvent
& rDCEvt
)
407 if ( rDCEvt
.GetType() == DATACHANGED_SETTINGS
&&
408 (rDCEvt
.GetFlags() & SETTINGS_STYLE
) )
411 ModalDialog::DataChanged( rDCEvt
);
414 /**************************************************************************/
417 IMPL_LINK( SmFontSizeDialog
, DefaultButtonClickHdl
, Button
*, EMPTYARG
/*pButton*/ )
419 QueryBox
*pQueryBox
= new QueryBox(this, SmResId(RID_DEFAULTSAVEQUERY
));
421 if (pQueryBox
->Execute() == RET_YES
)
423 SmModule
*pp
= SM_MOD();
424 SmFormat
aFmt( pp
->GetConfig()->GetStandardFormat() );
426 pp
->GetConfig()->SetStandardFormat( aFmt
);
433 IMPL_LINK( SmFontSizeDialog
, HelpButtonClickHdl
, Button
*, EMPTYARG
/*pButton*/ )
436 Help
* pHelp
= Application::GetHelp();
439 pHelp
->Start( OUString( "HID_SMA_FONTSIZEDIALOG" ), &aHelpButton1
);
444 SmFontSizeDialog::SmFontSizeDialog(Window
* pParent
, bool bFreeRes
)
445 : ModalDialog(pParent
, SmResId(RID_FONTSIZEDIALOG
)),
446 aFixedText1(this, SmResId(1)),
447 aBaseSize(this, SmResId(1)),
448 aFixedText4(this, SmResId(4)),
449 aTextSize(this, SmResId(4)),
450 aFixedText5(this, SmResId(5)),
451 aIndexSize(this, SmResId(5)),
452 aFixedText6(this, SmResId(6)),
453 aFunctionSize(this, SmResId(6)),
454 aFixedText7(this, SmResId(7)),
455 aOperatorSize(this, SmResId(7)),
456 aFixedText8(this, SmResId(8)),
457 aBorderSize(this, SmResId(8)),
458 aFixedLine1(this, SmResId(1)),
459 aOKButton1(this, SmResId(1)),
460 aHelpButton1(this, SmResId(1)),
461 aCancelButton1(this, SmResId(1)),
462 aDefaultButton(this, SmResId(1))
467 aDefaultButton
.SetClickHdl(LINK(this, SmFontSizeDialog
, DefaultButtonClickHdl
));
468 aHelpButton1
.SetClickHdl(LINK(this, SmFontSizeDialog
, HelpButtonClickHdl
));
472 void SmFontSizeDialog::ReadFrom(const SmFormat
&rFormat
)
474 //! aufpassen: richtig runden!
475 aBaseSize
.SetValue( SmRoundFraction(
476 Sm100th_mmToPts( rFormat
.GetBaseSize().Height() ) ) );
478 aTextSize
.SetValue( rFormat
.GetRelSize(SIZ_TEXT
) );
479 aIndexSize
.SetValue( rFormat
.GetRelSize(SIZ_INDEX
) );
480 aFunctionSize
.SetValue( rFormat
.GetRelSize(SIZ_FUNCTION
) );
481 aOperatorSize
.SetValue( rFormat
.GetRelSize(SIZ_OPERATOR
) );
482 aBorderSize
.SetValue( rFormat
.GetRelSize(SIZ_LIMITS
) );
486 void SmFontSizeDialog::WriteTo(SmFormat
&rFormat
) const
488 rFormat
.SetBaseSize( Size(0, SmPtsTo100th_mm( static_cast< long >(aBaseSize
.GetValue()))) );
490 rFormat
.SetRelSize(SIZ_TEXT
, (sal_uInt16
) aTextSize
.GetValue());
491 rFormat
.SetRelSize(SIZ_INDEX
, (sal_uInt16
) aIndexSize
.GetValue());
492 rFormat
.SetRelSize(SIZ_FUNCTION
, (sal_uInt16
) aFunctionSize
.GetValue());
493 rFormat
.SetRelSize(SIZ_OPERATOR
, (sal_uInt16
) aOperatorSize
.GetValue());
494 rFormat
.SetRelSize(SIZ_LIMITS
, (sal_uInt16
) aBorderSize
.GetValue());
496 const Size
aTmp (rFormat
.GetBaseSize());
497 for (sal_uInt16 i
= FNT_BEGIN
; i
<= FNT_END
; i
++)
498 rFormat
.SetFontSize(i
, aTmp
);
500 rFormat
.RequestApplyChanges();
504 /**************************************************************************/
507 IMPL_LINK( SmFontTypeDialog
, MenuSelectHdl
, Menu
*, pMenu
)
509 SmFontPickListBox
*pActiveListBox
;
511 bool bHideCheckboxes
= false;
512 switch (pMenu
->GetCurItemId())
514 case 1: pActiveListBox
= &aVariableFont
; break;
515 case 2: pActiveListBox
= &aFunctionFont
; break;
516 case 3: pActiveListBox
= &aNumberFont
; break;
517 case 4: pActiveListBox
= &aTextFont
; break;
518 case 5: pActiveListBox
= &aSerifFont
; bHideCheckboxes
= true; break;
519 case 6: pActiveListBox
= &aSansFont
; bHideCheckboxes
= true; break;
520 case 7: pActiveListBox
= &aFixedFont
; bHideCheckboxes
= true; break;
521 default:pActiveListBox
= NULL
;
526 SmFontDialog
*pFontDialog
= new SmFontDialog(this, pFontListDev
, bHideCheckboxes
);
528 pActiveListBox
->WriteTo(*pFontDialog
);
529 if (pFontDialog
->Execute() == RET_OK
)
530 pActiveListBox
->ReadFrom(*pFontDialog
);
537 IMPL_LINK_INLINE_START( SmFontTypeDialog
, DefaultButtonClickHdl
, Button
*, EMPTYARG
/*pButton*/ )
539 QueryBox
*pQueryBox
= new QueryBox(this, SmResId(RID_DEFAULTSAVEQUERY
));
540 if (pQueryBox
->Execute() == RET_YES
)
542 SmModule
*pp
= SM_MOD();
543 SmFormat
aFmt( pp
->GetConfig()->GetStandardFormat() );
545 pp
->GetConfig()->SetStandardFormat( aFmt
, true );
551 IMPL_LINK_INLINE_END( SmFontTypeDialog
, DefaultButtonClickHdl
, Button
*, pButton
)
553 IMPL_LINK( SmFontTypeDialog
, HelpButtonClickHdl
, Button
*, EMPTYARG
/*pButton*/ )
556 Help
* pHelp
= Application::GetHelp();
559 pHelp
->Start( OUString( "HID_SMA_FONTTYPEDIALOG" ), &aHelpButton1
);
564 SmFontTypeDialog::SmFontTypeDialog(Window
* pParent
, OutputDevice
*pFntListDevice
, bool bFreeRes
)
565 : ModalDialog(pParent
, SmResId(RID_FONTTYPEDIALOG
)),
566 aFixedText1 (this, SmResId(1)),
567 aVariableFont (this, SmResId(1)),
568 aFixedText2 (this, SmResId(2)),
569 aFunctionFont (this, SmResId(2)),
570 aFixedText3 (this, SmResId(3)),
571 aNumberFont (this, SmResId(3)),
572 aFixedText4 (this, SmResId(4)),
573 aTextFont (this, SmResId(4)),
574 aFixedText5 (this, SmResId(5)),
575 aSerifFont (this, SmResId(5)),
576 aFixedText6 (this, SmResId(6)),
577 aSansFont (this, SmResId(6)),
578 aFixedText7 (this, SmResId(7)),
579 aFixedFont (this, SmResId(7)),
580 aFixedLine1 (this, SmResId(1)),
581 aFixedLine2 (this, SmResId(2)),
582 aOKButton1 (this, SmResId(1)),
583 aHelpButton1 (this, SmResId(1)),
584 aCancelButton1 (this, SmResId(1)),
585 aMenuButton (this, SmResId(1)),
586 aDefaultButton (this, SmResId(2)),
587 pFontListDev (pFntListDevice
)
592 aDefaultButton
.SetClickHdl(LINK(this, SmFontTypeDialog
, DefaultButtonClickHdl
));
593 aHelpButton1
.SetClickHdl(LINK(this, SmFontTypeDialog
, HelpButtonClickHdl
));
595 aMenuButton
.GetPopupMenu()->SetSelectHdl(LINK(this, SmFontTypeDialog
, MenuSelectHdl
));
598 void SmFontTypeDialog::ReadFrom(const SmFormat
&rFormat
)
600 SmModule
*pp
= SM_MOD();
602 aVariableFont
= pp
->GetConfig()->GetFontPickList(FNT_VARIABLE
);
603 aFunctionFont
= pp
->GetConfig()->GetFontPickList(FNT_FUNCTION
);
604 aNumberFont
= pp
->GetConfig()->GetFontPickList(FNT_NUMBER
);
605 aTextFont
= pp
->GetConfig()->GetFontPickList(FNT_TEXT
);
606 aSerifFont
= pp
->GetConfig()->GetFontPickList(FNT_SERIF
);
607 aSansFont
= pp
->GetConfig()->GetFontPickList(FNT_SANS
);
608 aFixedFont
= pp
->GetConfig()->GetFontPickList(FNT_FIXED
);
610 aVariableFont
.Insert( rFormat
.GetFont(FNT_VARIABLE
) );
611 aFunctionFont
.Insert( rFormat
.GetFont(FNT_FUNCTION
) );
612 aNumberFont
.Insert( rFormat
.GetFont(FNT_NUMBER
) );
613 aTextFont
.Insert( rFormat
.GetFont(FNT_TEXT
) );
614 aSerifFont
.Insert( rFormat
.GetFont(FNT_SERIF
) );
615 aSansFont
.Insert( rFormat
.GetFont(FNT_SANS
) );
616 aFixedFont
.Insert( rFormat
.GetFont(FNT_FIXED
) );
620 void SmFontTypeDialog::WriteTo(SmFormat
&rFormat
) const
622 SmModule
*pp
= SM_MOD();
624 pp
->GetConfig()->GetFontPickList(FNT_VARIABLE
) = aVariableFont
;
625 pp
->GetConfig()->GetFontPickList(FNT_FUNCTION
) = aFunctionFont
;
626 pp
->GetConfig()->GetFontPickList(FNT_NUMBER
) = aNumberFont
;
627 pp
->GetConfig()->GetFontPickList(FNT_TEXT
) = aTextFont
;
628 pp
->GetConfig()->GetFontPickList(FNT_SERIF
) = aSerifFont
;
629 pp
->GetConfig()->GetFontPickList(FNT_SANS
) = aSansFont
;
630 pp
->GetConfig()->GetFontPickList(FNT_FIXED
) = aFixedFont
;
632 rFormat
.SetFont( FNT_VARIABLE
, aVariableFont
.Get(0) );
633 rFormat
.SetFont( FNT_FUNCTION
, aFunctionFont
.Get(0) );
634 rFormat
.SetFont( FNT_NUMBER
, aNumberFont
.Get(0) );
635 rFormat
.SetFont( FNT_TEXT
, aTextFont
.Get(0) );
636 rFormat
.SetFont( FNT_SERIF
, aSerifFont
.Get(0) );
637 rFormat
.SetFont( FNT_SANS
, aSansFont
.Get(0) );
638 rFormat
.SetFont( FNT_FIXED
, aFixedFont
.Get(0) );
640 rFormat
.RequestApplyChanges();
643 /**************************************************************************/
647 sal_uInt16 nMin
, nMax
;
650 // Data for min and max values of the 4 metric fields
651 // for each of the 10 categories
652 static const FieldMinMax pMinMaxData
[10][4] =
655 {{ 0, 200 }, { 0, 200 }, { 0, 100 }, { 0, 0 }},
657 {{ 0, 100 }, { 0, 100 }, { 0, 0 }, { 0, 0 }},
659 {{ 0, 100 }, { 0, 100 }, { 0, 0 }, { 0, 0 }},
661 {{ 0, 100 }, { 1, 100 }, { 0, 0 }, { 0, 0 }},
663 {{ 0, 100 }, { 0, 100 }, { 0, 0 }, { 0, 0 }},
665 {{ 0, 100 }, { 0, 100 }, { 0, 0 }, { 0, 100 }},
667 {{ 0, 300 }, { 0, 300 }, { 0, 0 }, { 0, 0 }},
669 {{ 0, 100 }, { 0, 100 }, { 0, 0 }, { 0, 0 }},
671 {{ 0, 100 }, { 0, 100 }, { 0, 0 }, { 0, 0 }},
673 {{ 0, 10000 }, { 0, 10000 }, { 0, 10000 }, { 0, 10000 }}
676 SmCategoryDesc::SmCategoryDesc(const ResId
& rResId
, sal_uInt16 nCategoryIdx
) :
679 if (IsAvailableRes(ResId(1,*rResId
.GetResMgr()).SetRT(RSC_STRING
)))
681 Name
= ResId(1,*rResId
.GetResMgr()).toString();
684 for (i
= 0; i
< 4; i
++)
688 if (IsAvailableRes(ResId(nI2
,*rResId
.GetResMgr()).SetRT(RSC_STRING
)))
690 Strings
[i
] = new OUString(ResId(nI2
,*rResId
.GetResMgr()).toString());
691 Graphics
[i
] = new Bitmap(ResId(10*nI2
,*rResId
.GetResMgr()));
700 for (i
= 0; i
< 4; i
++)
702 const FieldMinMax
&rMinMax
= pMinMaxData
[ nCategoryIdx
][i
];
703 Value
[i
] = Minimum
[i
] = rMinMax
.nMin
;
704 Maximum
[i
] = rMinMax
.nMax
;
712 SmCategoryDesc::~SmCategoryDesc()
714 for (int i
= 0; i
< 4; i
++)
721 /**************************************************************************/
723 IMPL_LINK( SmDistanceDialog
, GetFocusHdl
, Control
*, pControl
)
725 if (Categories
[nActiveCategory
])
729 if (pControl
== &aMetricField1
)
731 else if (pControl
== &aMetricField2
)
733 else if (pControl
== &aMetricField3
)
735 else if (pControl
== &aMetricField4
)
739 aBitmap
.SetBitmap(*(Categories
[nActiveCategory
]->GetGraphic(i
)));
744 IMPL_LINK( SmDistanceDialog
, MenuSelectHdl
, Menu
*, pMenu
)
746 SetCategory(pMenu
->GetCurItemId() - 1);
751 IMPL_LINK( SmDistanceDialog
, DefaultButtonClickHdl
, Button
*, EMPTYARG
/*pButton*/ )
753 QueryBox
*pQueryBox
= new QueryBox(this, SmResId(RID_DEFAULTSAVEQUERY
));
755 if (pQueryBox
->Execute() == RET_YES
)
757 SmModule
*pp
= SM_MOD();
758 SmFormat
aFmt( pp
->GetConfig()->GetStandardFormat() );
760 pp
->GetConfig()->SetStandardFormat( aFmt
);
766 IMPL_LINK( SmDistanceDialog
, HelpButtonClickHdl
, Button
*, EMPTYARG
/*pButton*/ )
769 Help
* pHelp
= Application::GetHelp();
772 pHelp
->Start( OUString( "HID_SMA_DISTANCEDIALOG" ), &aHelpButton1
);
778 IMPL_LINK( SmDistanceDialog
, CheckBoxClickHdl
, CheckBox
*, pCheckBox
)
780 if (pCheckBox
== &aCheckBox1
)
784 bool bChecked
= aCheckBox1
.IsChecked();
785 aFixedText4
.Enable( bChecked
);
786 aMetricField4
.Enable( bChecked
);
792 void SmDistanceDialog::SetHelpId(MetricField
&rField
, const OString
& sHelpId
)
794 const OUString aEmptyText
;
796 rField
.SetHelpId(sHelpId
);
797 rField
.SetHelpText(aEmptyText
);
799 // since MetricField inherits from SpinField which has a sub Edit field
800 // (which is actually the one we modify) we have to set the help-id
802 Edit
*pSubEdit
= rField
.GetSubEdit();
805 pSubEdit
->SetHelpId(sHelpId
);
806 pSubEdit
->SetHelpText(aEmptyText
);
811 void SmDistanceDialog::SetCategory(sal_uInt16 nCategory
)
813 #if OSL_DEBUG_LEVEL > 1
814 OSL_ENSURE(/*0 <= nCategory &&*/ nCategory
< NOCATEGORIES
,
815 "Sm: wrong category number in SmDistanceDialog");
818 // array to convert category- and metricfield-number in help ids.
819 // 0 is used in case of unused combinations.
820 #if OSL_DEBUG_LEVEL > 1
821 OSL_ENSURE(NOCATEGORIES
== 10, "Sm : array doesn't fit into the number of categories");
823 static const char * aCatMf2Hid
[10][4] =
825 { HID_SMA_DEFAULT_DIST
, HID_SMA_LINE_DIST
, HID_SMA_ROOT_DIST
, 0 },
826 { HID_SMA_SUP_DIST
, HID_SMA_SUB_DIST
, 0, 0 },
827 { HID_SMA_NUMERATOR_DIST
, HID_SMA_DENOMINATOR_DIST
, 0, 0 },
828 { HID_SMA_FRACLINE_EXCWIDTH
, HID_SMA_FRACLINE_LINEWIDTH
, 0, 0 },
829 { HID_SMA_UPPERLIMIT_DIST
, HID_SMA_LOWERLIMIT_DIST
, 0, 0 },
830 { HID_SMA_BRACKET_EXCHEIGHT
, HID_SMA_BRACKET_DIST
, 0, HID_SMA_BRACKET_EXCHEIGHT2
},
831 { HID_SMA_MATRIXROW_DIST
, HID_SMA_MATRIXCOL_DIST
, 0, 0 },
832 { HID_SMA_ATTRIBUT_DIST
, HID_SMA_INTERATTRIBUT_DIST
, 0, 0 },
833 { HID_SMA_OPERATOR_EXCHEIGHT
, HID_SMA_OPERATOR_DIST
, 0, 0 },
834 { HID_SMA_LEFTBORDER_DIST
, HID_SMA_RIGHTBORDER_DIST
, HID_SMA_UPPERBORDER_DIST
, HID_SMA_LOWERBORDER_DIST
}
837 // array to help iterate over the controls
838 Window
* const aWin
[4][2] =
840 { &aFixedText1
, &aMetricField1
},
841 { &aFixedText2
, &aMetricField2
},
842 { &aFixedText3
, &aMetricField3
},
843 { &aFixedText4
, &aMetricField4
}
846 SmCategoryDesc
*pCat
;
848 // remember the (maybe new) settings of the active SmCategoryDesc
849 // before switching to the new one
850 if (nActiveCategory
!= CATEGORY_NONE
)
852 pCat
= Categories
[nActiveCategory
];
853 pCat
->SetValue(0, (sal_uInt16
) aMetricField1
.GetValue());
854 pCat
->SetValue(1, (sal_uInt16
) aMetricField2
.GetValue());
855 pCat
->SetValue(2, (sal_uInt16
) aMetricField3
.GetValue());
856 pCat
->SetValue(3, (sal_uInt16
) aMetricField4
.GetValue());
858 if (nActiveCategory
== 5)
859 bScaleAllBrackets
= aCheckBox1
.IsChecked();
861 aMenuButton
.GetPopupMenu()->CheckItem(nActiveCategory
+ 1, false);
864 // activation/deactivation of the associated controls depending on the chosen category
866 for (sal_uInt16 i
= 0; i
< 4; i
++)
868 FixedText
*pFT
= (FixedText
* const) aWin
[i
][0];
869 MetricField
*pMF
= (MetricField
* const) aWin
[i
][1];
871 // To determine which Controls should be active, the existence
872 // of an associated HelpID is checked
873 bActive
= aCatMf2Hid
[nCategory
][i
] != 0;
876 pFT
->Enable(bActive
);
878 pMF
->Enable(bActive
);
880 // set measurement unit and number of decimal places
885 eUnit
= FUNIT_CUSTOM
;
887 pMF
->SetCustomUnitText(OUString('%'));
891 eUnit
= FUNIT_100TH_MM
;
894 pMF
->SetUnit(eUnit
); // changes the value
895 pMF
->SetDecimalDigits(nDigits
);
899 pCat
= Categories
[nCategory
];
900 pFT
->SetText(*pCat
->GetString(i
));
902 pMF
->SetMin(pCat
->GetMinimum(i
));
903 pMF
->SetMax(pCat
->GetMaximum(i
));
904 pMF
->SetValue(pCat
->GetValue(i
));
906 SetHelpId(*pMF
, aCatMf2Hid
[nCategory
][i
]);
909 // activate the CheckBox and the associated MetricField if we're dealing with the brackets menu
910 bActive
= nCategory
== 5;
911 aCheckBox1
.Show(bActive
);
912 aCheckBox1
.Enable(bActive
);
915 aCheckBox1
.Check( bScaleAllBrackets
);
917 bool bChecked
= aCheckBox1
.IsChecked();
918 aFixedText4
.Enable( bChecked
);
919 aMetricField4
.Enable( bChecked
);
922 aMenuButton
.GetPopupMenu()->CheckItem(nCategory
+ 1, true);
923 aFixedLine
.SetText(Categories
[nCategory
]->GetName());
925 nActiveCategory
= nCategory
;
927 aMetricField1
.GrabFocus();
933 SmDistanceDialog::SmDistanceDialog(Window
*pParent
, bool bFreeRes
)
934 : ModalDialog(pParent
, SmResId(RID_DISTANCEDIALOG
)),
935 aFixedText1 (this, SmResId(1)),
936 aMetricField1 (this, SmResId(1)),
937 aFixedText2 (this, SmResId(2)),
938 aMetricField2 (this, SmResId(2)),
939 aFixedText3 (this, SmResId(3)),
940 aMetricField3 (this, SmResId(3)),
941 aCheckBox1 (this, SmResId(1)),
942 aFixedText4 (this, SmResId(4)),
943 aMetricField4 (this, SmResId(4)),
944 aOKButton1 (this, SmResId(1)),
945 aHelpButton1 (this, SmResId(1)),
946 aCancelButton1 (this, SmResId(1)),
947 aMenuButton (this, SmResId(1)),
948 aDefaultButton (this, SmResId(1)),
949 aBitmap (this, SmResId(1)),
950 aFixedLine (this, SmResId(1))
952 for (sal_uInt16 i
= 0; i
< NOCATEGORIES
; i
++)
953 Categories
[i
] = new SmCategoryDesc(SmResId(i
+ 1), i
);
954 nActiveCategory
= CATEGORY_NONE
;
955 bScaleAllBrackets
= false;
960 // preview like controls should have a 2D look
961 aBitmap
.SetBorderStyle( WINDOW_BORDER_MONO
);
963 aMetricField1
.SetGetFocusHdl(LINK(this, SmDistanceDialog
, GetFocusHdl
));
964 aMetricField2
.SetGetFocusHdl(LINK(this, SmDistanceDialog
, GetFocusHdl
));
965 aMetricField3
.SetGetFocusHdl(LINK(this, SmDistanceDialog
, GetFocusHdl
));
966 aMetricField4
.SetGetFocusHdl(LINK(this, SmDistanceDialog
, GetFocusHdl
));
967 aCheckBox1
.SetClickHdl(LINK(this, SmDistanceDialog
, CheckBoxClickHdl
));
969 aMenuButton
.GetPopupMenu()->SetSelectHdl(LINK(this, SmDistanceDialog
, MenuSelectHdl
));
971 aDefaultButton
.SetClickHdl(LINK(this, SmDistanceDialog
, DefaultButtonClickHdl
));
972 aHelpButton1
.SetClickHdl(LINK(this, SmDistanceDialog
, HelpButtonClickHdl
));
976 SmDistanceDialog::~SmDistanceDialog()
978 for (int i
= 0; i
< NOCATEGORIES
; i
++)
979 DELETEZ(Categories
[i
]);
982 void SmDistanceDialog::DataChanged( const DataChangedEvent
&rEvt
)
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
;
1023 void SmDistanceDialog::WriteTo(SmFormat
&rFormat
) /*const*/
1025 // TODO can they actually be different?
1026 // if that's not the case 'const' could be used above!
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_MOD();
1070 SmFormat
aFmt( pp
->GetConfig()->GetStandardFormat() );
1072 pp
->GetConfig()->SetStandardFormat( aFmt
);
1080 IMPL_LINK( SmAlignDialog
, HelpButtonClickHdl
, Button
*, EMPTYARG
/*pButton*/ )
1082 // start help system
1083 Help
* pHelp
= Application::GetHelp();
1086 pHelp
->Start( OUString( "HID_SMA_ALIGNDIALOG" ), &aHelpButton1
);
1091 SmAlignDialog::SmAlignDialog(Window
* pParent
, bool bFreeRes
)
1092 : ModalDialog(pParent
, SmResId(RID_ALIGNDIALOG
)),
1093 aLeft (this, SmResId(1)),
1094 aCenter (this, SmResId(2)),
1095 aRight (this, SmResId(3)),
1096 aFixedLine1 (this, SmResId(1)),
1097 aOKButton1 (this, SmResId(1)),
1098 aHelpButton1 (this, SmResId(1)),
1099 aCancelButton1 (this, SmResId(1)),
1100 aDefaultButton (this, SmResId(1))
1105 aDefaultButton
.SetClickHdl(LINK(this, SmAlignDialog
, DefaultButtonClickHdl
));
1106 aHelpButton1
.SetClickHdl(LINK(this, SmAlignDialog
, HelpButtonClickHdl
));
1110 void SmAlignDialog::ReadFrom(const SmFormat
&rFormat
)
1112 switch (rFormat
.GetHorAlign())
1116 aCenter
.Check(false);
1117 aRight
.Check(false);
1121 aLeft
.Check(false);
1122 aCenter
.Check(true);
1123 aRight
.Check(false);
1127 aLeft
.Check(false);
1128 aCenter
.Check(false);
1129 aRight
.Check(true);
1135 void SmAlignDialog::WriteTo(SmFormat
&rFormat
) const
1137 if (aLeft
.IsChecked())
1138 rFormat
.SetHorAlign(AlignLeft
);
1139 else if (aRight
.IsChecked())
1140 rFormat
.SetHorAlign(AlignRight
);
1142 rFormat
.SetHorAlign(AlignCenter
);
1144 rFormat
.RequestApplyChanges();
1148 /**************************************************************************/
1151 void SmShowSymbolSet::Paint(const Rectangle
&)
1155 // set MapUnit for which 'nLen' has been calculated
1156 SetMapMode(MapMode(MAP_PIXEL
));
1158 sal_uInt16 v
= sal::static_int_cast
< sal_uInt16
>((aVScrollBar
.GetThumbPos() * nColumns
));
1159 size_t nSymbols
= aSymbolSet
.size();
1161 Color
aTxtColor( GetTextColor() );
1162 for (sal_uInt16 i
= v
; i
< nSymbols
; i
++)
1164 SmSym
aSymbol (*aSymbolSet
[i
]);
1165 Font
aFont (aSymbol
.GetFace());
1166 aFont
.SetAlign(ALIGN_TOP
);
1168 // taking a FontSize which is a bit smaller (compared to nLen) in order to have a buffer
1169 // (hopefully enough for left and right, too)
1170 aFont
.SetSize(Size(0, nLen
- (nLen
/ 3)));
1173 SetTextColor( aTxtColor
);
1176 sal_UCS4 cChar
= aSymbol
.GetCharacter();
1177 OUString
aText(&cChar
, 1);
1178 Size
aSize( GetTextWidth( aText
), GetTextHeight());
1180 DrawText(Point((nIV
% nColumns
) * nLen
+ (nLen
- aSize
.Width()) / 2,
1181 (nIV
/ nColumns
) * nLen
+ (nLen
- aSize
.Height()) / 2),
1185 if (nSelectSymbol
!= SYMBOL_NONE
)
1187 Invert(Rectangle(Point(((nSelectSymbol
- v
) % nColumns
) * nLen
,
1188 ((nSelectSymbol
- v
) / nColumns
) * nLen
),
1196 void SmShowSymbolSet::MouseButtonDown(const MouseEvent
& rMEvt
)
1200 if (rMEvt
.IsLeft() && Rectangle(Point(0, 0), aOutputSize
).IsInside(rMEvt
.GetPosPixel()))
1202 long nPos
= (rMEvt
.GetPosPixel().Y() / nLen
) * nColumns
+ (rMEvt
.GetPosPixel().X() / nLen
) +
1203 aVScrollBar
.GetThumbPos() * nColumns
;
1204 SelectSymbol( sal::static_int_cast
< sal_uInt16
>(nPos
) );
1206 aSelectHdlLink
.Call(this);
1208 if (rMEvt
.GetClicks() > 1) aDblClickHdlLink
.Call(this);
1210 else Control::MouseButtonDown (rMEvt
);
1214 void SmShowSymbolSet::KeyInput(const KeyEvent
& rKEvt
)
1216 sal_uInt16 n
= nSelectSymbol
;
1218 if (n
!= SYMBOL_NONE
)
1220 switch (rKEvt
.GetKeyCode().GetCode())
1222 case KEY_DOWN
: n
= n
+ nColumns
; break;
1223 case KEY_UP
: n
= n
- nColumns
; break;
1224 case KEY_LEFT
: n
-= 1; break;
1225 case KEY_RIGHT
: n
+= 1; break;
1226 case KEY_HOME
: n
= 0; break;
1227 case KEY_END
: n
= static_cast< sal_uInt16
>(aSymbolSet
.size() - 1); break;
1228 case KEY_PAGEUP
: n
-= nColumns
* nRows
; break;
1229 case KEY_PAGEDOWN
: n
+= nColumns
* nRows
; break;
1232 Control::KeyInput(rKEvt
);
1239 if (n
>= aSymbolSet
.size())
1243 if ((n
< (sal_uInt16
) (aVScrollBar
.GetThumbPos() * nColumns
)) ||
1244 (n
>= (sal_uInt16
) ((aVScrollBar
.GetThumbPos() + nRows
) * nColumns
)))
1246 aVScrollBar
.SetThumbPos(n
/ nColumns
);
1252 aSelectHdlLink
.Call(this);
1256 SmShowSymbolSet::SmShowSymbolSet(Window
*pParent
, const ResId
& rResId
) :
1257 Control(pParent
, rResId
),
1258 aVScrollBar(this, WinBits(WB_VSCROLL
))
1260 nSelectSymbol
= SYMBOL_NONE
;
1262 aOutputSize
= GetOutputSizePixel();
1263 long nScrollBarWidth
= aVScrollBar
.GetSizePixel().Width(),
1264 nUseableWidth
= aOutputSize
.Width() - nScrollBarWidth
;
1266 // Height of 16pt in pixels (matching 'aOutputSize')
1267 nLen
= (sal_uInt16
) LogicToPixel(Size(0, 16), MapMode(MAP_POINT
)).Height();
1269 nColumns
= sal::static_int_cast
< sal_uInt16
>(nUseableWidth
/ nLen
);
1270 if (nColumns
> 2 && nColumns
% 2 != 0)
1272 nRows
= sal::static_int_cast
< sal_uInt16
>(aOutputSize
.Height() / nLen
);
1273 #if OSL_DEBUG_LEVEL > 1
1274 OSL_ENSURE(nColumns
> 0, "Sm : no columns");
1275 OSL_ENSURE(nRows
> 0, "Sm : no rows");
1278 // make it fit exactly
1279 aOutputSize
.Width() = nColumns
* nLen
;
1280 aOutputSize
.Height() = nRows
* nLen
;
1282 aVScrollBar
.SetPosSizePixel(Point(aOutputSize
.Width() + 1, -1),
1283 Size(nScrollBarWidth
, aOutputSize
.Height() + 2));
1284 aVScrollBar
.Enable(false);
1286 aVScrollBar
.SetScrollHdl(LINK(this, SmShowSymbolSet
, ScrollHdl
));
1288 Size
WindowSize (aOutputSize
);
1289 WindowSize
.Width() += nScrollBarWidth
;
1290 SetOutputSizePixel(WindowSize
);
1295 void SmShowSymbolSet::SetSymbolSet(const SymbolPtrVec_t
& rSymbolSet
)
1297 aSymbolSet
= rSymbolSet
;
1299 if (static_cast< sal_uInt16
>(aSymbolSet
.size()) > (nColumns
* nRows
))
1301 aVScrollBar
.SetRange(Range(0, ((aSymbolSet
.size() + (nColumns
- 1)) / nColumns
) - nRows
));
1302 aVScrollBar
.Enable(true);
1306 aVScrollBar
.SetRange(Range(0,0));
1307 aVScrollBar
.Enable (false);
1314 void SmShowSymbolSet::SelectSymbol(sal_uInt16 nSymbol
)
1316 int v
= (int) (aVScrollBar
.GetThumbPos() * nColumns
);
1318 if (nSelectSymbol
!= SYMBOL_NONE
)
1319 Invalidate(Rectangle(Point(((nSelectSymbol
- v
) % nColumns
) * nLen
,
1320 ((nSelectSymbol
- v
) / nColumns
) * nLen
),
1323 if (nSymbol
< aSymbolSet
.size())
1324 nSelectSymbol
= nSymbol
;
1326 if (aSymbolSet
.empty())
1327 nSelectSymbol
= SYMBOL_NONE
;
1329 if (nSelectSymbol
!= SYMBOL_NONE
)
1330 Invalidate(Rectangle(Point(((nSelectSymbol
- v
) % nColumns
) * nLen
,
1331 ((nSelectSymbol
- v
) / nColumns
) * nLen
),
1338 IMPL_LINK( SmShowSymbolSet
, ScrollHdl
, ScrollBar
*, EMPTYARG
/*pScrollBar*/)
1344 ////////////////////////////////////////////////////////////////////////////////
1346 void SmShowSymbol::Paint(const Rectangle
&rRect
)
1348 Control::Paint( rRect
);
1350 const OUString
&rText
= GetText();
1351 Size
aTextSize(GetTextWidth(rText
), GetTextHeight());
1353 DrawText(Point((GetOutputSize().Width() - aTextSize
.Width()) / 2,
1354 (GetOutputSize().Height() * 7/10)), rText
);
1358 void SmShowSymbol::MouseButtonDown(const MouseEvent
& rMEvt
)
1360 if (rMEvt
.GetClicks() > 1)
1361 aDblClickHdlLink
.Call(this);
1363 Control::MouseButtonDown (rMEvt
);
1367 void SmShowSymbol::SetSymbol(const SmSym
*pSymbol
)
1371 Font
aFont (pSymbol
->GetFace());
1372 aFont
.SetSize(Size(0, GetOutputSize().Height() - GetOutputSize().Height() / 3));
1373 aFont
.SetAlign(ALIGN_BASELINE
);
1376 sal_UCS4 cChar
= pSymbol
->GetCharacter();
1377 OUString
aText(&cChar
, 1);
1381 // 'Invalidate' fills the background with the background color.
1382 // If a NULL pointer has been passed that's already enough to clear the display
1387 ////////////////////////////////////////////////////////////////////////////////
1389 void SmSymbolDialog::FillSymbolSets(bool bDeleteText
)
1390 // populate the entries of possible SymbolsSets in the dialog with
1391 // current values of the SymbolSet manager but selects none of those
1393 aSymbolSets
.Clear();
1395 aSymbolSets
.SetNoSelection();
1397 std::set
< OUString
> aSybolSetNames( rSymbolMgr
.GetSymbolSetNames() );
1398 std::set
< OUString
>::const_iterator
aIt( aSybolSetNames
.begin() );
1399 for ( ; aIt
!= aSybolSetNames
.end(); ++aIt
)
1400 aSymbolSets
.InsertEntry( *aIt
);
1404 IMPL_LINK( SmSymbolDialog
, SymbolSetChangeHdl
, ListBox
*, EMPTYARG pListBox
)
1407 #if OSL_DEBUG_LEVEL > 1
1408 OSL_ENSURE(pListBox
== &aSymbolSets
, "Sm : wrong argument");
1411 SelectSymbolSet(aSymbolSets
.GetSelectEntry());
1416 IMPL_LINK( SmSymbolDialog
, SymbolChangeHdl
, SmShowSymbolSet
*, EMPTYARG pShowSymbolSet
)
1418 (void) pShowSymbolSet
;
1419 #if OSL_DEBUG_LEVEL > 1
1420 OSL_ENSURE(pShowSymbolSet
== &aSymbolSetDisplay
, "Sm : wrong argument");
1423 SelectSymbol(aSymbolSetDisplay
.GetSelectSymbol());
1427 IMPL_LINK( SmSymbolDialog
, EditClickHdl
, Button
*, EMPTYARG pButton
)
1430 #if OSL_DEBUG_LEVEL > 1
1431 OSL_ENSURE(pButton
== &aEditBtn
, "Sm : wrong argument");
1434 SmSymDefineDialog
*pDialog
= new SmSymDefineDialog(this, pFontListDev
, rSymbolMgr
);
1436 // set current symbol and SymbolSet for the new dialog
1437 const OUString
aSymSetName (aSymbolSets
.GetSelectEntry()),
1438 aSymName (aSymbolName
.GetText());
1439 pDialog
->SelectOldSymbolSet(aSymSetName
);
1440 pDialog
->SelectOldSymbol(aSymName
);
1441 pDialog
->SelectSymbolSet(aSymSetName
);
1442 pDialog
->SelectSymbol(aSymName
);
1444 // remember old SymbolSet
1445 OUString
aOldSymbolSet (aSymbolSets
.GetSelectEntry());
1447 sal_uInt16 nSymPos
= GetSelectedSymbol();
1449 // adapt dialog to data of the SymbolSet manager, which might have changed
1450 if (pDialog
->Execute() == RET_OK
&& rSymbolMgr
.IsModified())
1456 // if the old SymbolSet doesn't exist anymore, go to the first one SymbolSet (if one exists)
1457 if (!SelectSymbolSet(aOldSymbolSet
) && aSymbolSets
.GetEntryCount() > 0)
1458 SelectSymbolSet(aSymbolSets
.GetEntry(0));
1461 // just update display of current symbol set
1462 OSL_ENSURE( aSymSetName
== aSymSetName
, "unexpected change in symbol set name" );
1463 aSymbolSet
= rSymbolMgr
.GetSymbolSet( aSymbolSetName
);
1464 aSymbolSetDisplay
.SetSymbolSet( aSymbolSet
);
1467 if (nSymPos
>= aSymbolSet
.size())
1468 nSymPos
= static_cast< sal_uInt16
>(aSymbolSet
.size()) - 1;
1469 SelectSymbol( nSymPos
);
1476 IMPL_LINK( SmSymbolDialog
, SymbolDblClickHdl
, SmShowSymbolSet
*, EMPTYARG pShowSymbolSet
)
1478 (void) pShowSymbolSet
;
1479 #if OSL_DEBUG_LEVEL > 1
1480 OSL_ENSURE(pShowSymbolSet
== &aSymbolSetDisplay
, "Sm : wrong argument");
1483 GetClickHdl(&aGetBtn
);
1489 IMPL_LINK( SmSymbolDialog
, GetClickHdl
, Button
*, EMPTYARG pButton
)
1492 #if OSL_DEBUG_LEVEL > 1
1493 OSL_ENSURE(pButton
== &aGetBtn
, "Sm : wrong button");
1496 const SmSym
*pSym
= GetSymbol();
1499 OUStringBuffer aText
;
1500 aText
.append('%').append(pSym
->GetName()).append(' ');
1502 rViewSh
.GetViewFrame()->GetDispatcher()->Execute(
1503 SID_INSERTSYMBOL
, SFX_CALLMODE_STANDARD
,
1504 new SfxStringItem(SID_INSERTSYMBOL
, aText
.makeStringAndClear()), 0L);
1511 IMPL_LINK_INLINE_START( SmSymbolDialog
, CloseClickHdl
, Button
*, EMPTYARG pButton
)
1514 #if OSL_DEBUG_LEVEL > 1
1515 OSL_ENSURE(pButton
== &aCloseBtn
, "Sm : wrong button");
1521 IMPL_LINK_INLINE_END( SmSymbolDialog
, CloseClickHdl
, Button
*, pButton
)
1523 IMPL_LINK( SmSymbolDialog
, HelpButtonClickHdl
, Button
*, EMPTYARG
/*pButton*/ )
1525 // start help system
1526 Help
* pHelp
= Application::GetHelp();
1529 pHelp
->Start( OUString( "HID_SMA_SYMBOLDIALOG" ), &aHelpBtn
);
1534 SmSymbolDialog::SmSymbolDialog(Window
*pParent
, OutputDevice
*pFntListDevice
,
1535 SmSymbolManager
&rMgr
, SmViewShell
&rViewShell
, bool bFreeRes
) :
1536 ModalDialog (pParent
, SmResId(RID_SYMBOLDIALOG
)),
1537 aSymbolSetText (this, SmResId(1)),
1538 aSymbolSets (this, SmResId(1)),
1539 aSymbolSetDisplay (this, SmResId(1)),
1540 aSymbolName (this, SmResId(2)),
1541 aSymbolDisplay (this, SmResId(2)),
1542 aHelpBtn (this, SmResId(1)),
1543 aGetBtn (this, SmResId(2)),
1544 aCloseBtn (this, SmResId(3)),
1545 aEditBtn (this, SmResId(1)),
1546 rViewSh (rViewShell
),
1548 pFontListDev (pFntListDevice
)
1553 aHelpBtn
.SetClickHdl(LINK(this, SmSymbolDialog
, HelpButtonClickHdl
));
1554 aSymbolSetName
= OUString();
1557 if (aSymbolSets
.GetEntryCount() > 0)
1558 SelectSymbolSet(aSymbolSets
.GetEntry(0));
1562 // preview like controls should have a 2D look
1563 aSymbolDisplay
.SetBorderStyle( WINDOW_BORDER_MONO
);
1565 aSymbolSets
.SetSelectHdl (LINK(this, SmSymbolDialog
, SymbolSetChangeHdl
));
1566 aSymbolSetDisplay
.SetSelectHdl (LINK(this, SmSymbolDialog
, SymbolChangeHdl
));
1567 aSymbolSetDisplay
.SetDblClickHdl(LINK(this, SmSymbolDialog
, SymbolDblClickHdl
));
1568 aSymbolDisplay
.SetDblClickHdl(LINK(this, SmSymbolDialog
, SymbolDblClickHdl
));
1569 aCloseBtn
.SetClickHdl (LINK(this, SmSymbolDialog
, CloseClickHdl
));
1570 aEditBtn
.SetClickHdl (LINK(this, SmSymbolDialog
, EditClickHdl
));
1571 aGetBtn
.SetClickHdl (LINK(this, SmSymbolDialog
, GetClickHdl
));
1575 SmSymbolDialog::~SmSymbolDialog()
1580 void SmSymbolDialog::InitColor_Impl()
1582 #if OSL_DEBUG_LEVEL > 1
1583 Color
aBC( GetDisplayBackground().GetColor() );
1585 ColorData nBgCol
= COL_WHITE
,
1586 nTxtCol
= COL_BLACK
;
1587 const StyleSettings
&rS
= GetSettings().GetStyleSettings();
1588 if (rS
.GetHighContrastMode())
1590 nBgCol
= rS
.GetFieldColor().GetColor();
1591 nTxtCol
= rS
.GetFieldTextColor().GetColor();
1594 Color
aTmpColor( nBgCol
);
1595 Wallpaper
aWall( aTmpColor
);
1596 Color
aTxtColor( nTxtCol
);
1597 aSymbolDisplay
.SetBackground( aWall
);
1598 aSymbolDisplay
.SetTextColor( aTxtColor
);
1599 aSymbolSetDisplay
.SetBackground( aWall
);
1600 aSymbolSetDisplay
.SetTextColor( aTxtColor
);
1604 void SmSymbolDialog::DataChanged( const DataChangedEvent
& rDCEvt
)
1606 if ( rDCEvt
.GetType() == DATACHANGED_SETTINGS
&&
1607 (rDCEvt
.GetFlags() & SETTINGS_STYLE
) )
1610 ModalDialog::DataChanged( rDCEvt
);
1614 bool SmSymbolDialog::SelectSymbolSet(const OUString
&rSymbolSetName
)
1617 sal_uInt16 nPos
= aSymbolSets
.GetEntryPos(rSymbolSetName
);
1619 aSymbolSetName
= OUString();
1621 if (nPos
!= LISTBOX_ENTRY_NOTFOUND
)
1623 aSymbolSets
.SelectEntryPos(nPos
);
1625 aSymbolSetName
= rSymbolSetName
;
1626 aSymbolSet
= rSymbolMgr
.GetSymbolSet( aSymbolSetName
);
1628 // sort symbols by Unicode position (useful for displaying Greek characters alphabetically)
1629 std::sort( aSymbolSet
.begin(), aSymbolSet
.end(), lt_SmSymPtr() );
1631 aSymbolSetDisplay
.SetSymbolSet( aSymbolSet
);
1632 if (aSymbolSet
.size() > 0)
1638 aSymbolSets
.SetNoSelection();
1644 void SmSymbolDialog::SelectSymbol(sal_uInt16 nSymbolNo
)
1646 const SmSym
*pSym
= NULL
;
1647 if (!aSymbolSetName
.isEmpty() && nSymbolNo
< static_cast< sal_uInt16
>(aSymbolSet
.size()))
1648 pSym
= aSymbolSet
[ nSymbolNo
];
1650 aSymbolSetDisplay
.SelectSymbol(nSymbolNo
);
1651 aSymbolDisplay
.SetSymbol(pSym
);
1652 aSymbolName
.SetText(pSym
? pSym
->GetName() : OUString());
1656 const SmSym
* SmSymbolDialog::GetSymbol() const
1658 sal_uInt16 nSymbolNo
= aSymbolSetDisplay
.GetSelectSymbol();
1659 bool bValid
= !aSymbolSetName
.isEmpty() && nSymbolNo
< static_cast< sal_uInt16
>(aSymbolSet
.size());
1660 return bValid
? aSymbolSet
[ nSymbolNo
] : NULL
;
1664 ////////////////////////////////////////////////////////////////////////////////
1667 void SmShowChar::Paint(const Rectangle
&rRect
)
1669 Control::Paint( rRect
);
1671 OUString
aText( GetText() );
1672 if (!aText
.isEmpty())
1674 #if OSL_DEBUG_LEVEL > 1
1676 sal_UCS4 cChar
= aText
.iterateCodePoints( &nPos
);
1679 Size
aTextSize(GetTextWidth(aText
), GetTextHeight());
1681 DrawText(Point((GetOutputSize().Width() - aTextSize
.Width()) / 2,
1682 (GetOutputSize().Height() * 7/10)), aText
);
1687 void SmShowChar::SetSymbol( const SmSym
*pSym
)
1690 SetSymbol( pSym
->GetCharacter(), pSym
->GetFace() );
1694 void SmShowChar::SetSymbol( sal_UCS4 cChar
, const Font
&rFont
)
1696 Font
aFont( rFont
);
1697 aFont
.SetSize( Size(0, GetOutputSize().Height() - GetOutputSize().Height() / 3) );
1698 aFont
.SetAlign(ALIGN_BASELINE
);
1700 aFont
.SetTransparent(true);
1702 OUString
aText(&cChar
, 1);
1709 ////////////////////////////////////////////////////////////////////////////////
1711 void SmSymDefineDialog::FillSymbols(ComboBox
&rComboBox
, bool bDeleteText
)
1713 #if OSL_DEBUG_LEVEL > 1
1714 OSL_ENSURE(&rComboBox
== &aOldSymbols
|| &rComboBox
== &aSymbols
,
1715 "Sm : wrong ComboBox");
1720 rComboBox
.SetText(OUString());
1722 ComboBox
&rBox
= &rComboBox
== &aOldSymbols
? aOldSymbolSets
: aSymbolSets
;
1723 SymbolPtrVec_t
aSymSet( aSymbolMgrCopy
.GetSymbolSet( rBox
.GetText() ) );
1724 for (size_t i
= 0; i
< aSymSet
.size(); ++i
)
1725 rComboBox
.InsertEntry( aSymSet
[i
]->GetName() );
1729 void SmSymDefineDialog::FillSymbolSets(ComboBox
&rComboBox
, bool bDeleteText
)
1731 #if OSL_DEBUG_LEVEL > 1
1732 OSL_ENSURE(&rComboBox
== &aOldSymbolSets
|| &rComboBox
== &aSymbolSets
,
1733 "Sm : falsche ComboBox");
1738 rComboBox
.SetText(OUString());
1740 const std::set
< OUString
> aSymbolSetNames( aSymbolMgrCopy
.GetSymbolSetNames() );
1741 std::set
< OUString
>::const_iterator
aIt( aSymbolSetNames
.begin() );
1742 for ( ; aIt
!= aSymbolSetNames
.end(); ++aIt
)
1743 rComboBox
.InsertEntry( *aIt
);
1747 void SmSymDefineDialog::FillFonts(bool bDelete
)
1751 aFonts
.SetNoSelection();
1753 // Include all fonts of FontList into the font list.
1754 // If there are duplicates, only include one entry of each font since the style will be
1755 // already selected using the FontStyleBox.
1758 sal_uInt16 nCount
= pFontList
->GetFontNameCount();
1759 for (sal_uInt16 i
= 0; i
< nCount
; i
++)
1760 aFonts
.InsertEntry( pFontList
->GetFontName(i
).GetName() );
1765 void SmSymDefineDialog::FillStyles(bool bDeleteText
)
1769 aStyles
.SetText(OUString());
1771 OUString
aText (aFonts
.GetSelectEntry());
1772 if (!aText
.isEmpty())
1774 // use own StyleNames
1775 const SmFontStyles
&rStyles
= GetFontStyles();
1776 for (sal_uInt16 i
= 0; i
< rStyles
.GetCount(); i
++)
1777 aStyles
.InsertEntry( rStyles
.GetStyleName(i
) );
1779 #if OSL_DEBUG_LEVEL > 1
1780 OSL_ENSURE(aStyles
.GetEntryCount() > 0, "Sm : no styles available");
1782 aStyles
.SetText( aStyles
.GetEntry(0) );
1787 SmSym
* SmSymDefineDialog::GetSymbol(const ComboBox
&rComboBox
)
1789 #if OSL_DEBUG_LEVEL > 1
1790 OSL_ENSURE(&rComboBox
== &aOldSymbols
|| &rComboBox
== &aSymbols
,
1791 "Sm : wrong combobox");
1793 return aSymbolMgrCopy
.GetSymbolByName(rComboBox
.GetText());
1797 IMPL_LINK( SmSymDefineDialog
, OldSymbolChangeHdl
, ComboBox
*, EMPTYARG pComboBox
)
1800 #if OSL_DEBUG_LEVEL > 1
1801 OSL_ENSURE(pComboBox
== &aOldSymbols
, "Sm : wrong argument");
1803 SelectSymbol(aOldSymbols
, aOldSymbols
.GetText(), false);
1808 IMPL_LINK( SmSymDefineDialog
, OldSymbolSetChangeHdl
, ComboBox
*, EMPTYARG pComboBox
)
1811 #if OSL_DEBUG_LEVEL > 1
1812 OSL_ENSURE(pComboBox
== &aOldSymbolSets
, "Sm : wrong argument");
1814 SelectSymbolSet(aOldSymbolSets
, aOldSymbolSets
.GetText(), false);
1819 IMPL_LINK( SmSymDefineDialog
, ModifyHdl
, ComboBox
*, pComboBox
)
1821 // remember cursor position for later restoring of it
1822 Selection
aSelection (pComboBox
->GetSelection());
1824 if (pComboBox
== &aSymbols
)
1825 SelectSymbol(aSymbols
, aSymbols
.GetText(), false);
1826 else if (pComboBox
== &aSymbolSets
)
1827 SelectSymbolSet(aSymbolSets
, aSymbolSets
.GetText(), false);
1828 else if (pComboBox
== &aOldSymbols
)
1829 // allow only names from the list
1830 SelectSymbol(aOldSymbols
, aOldSymbols
.GetText(), true);
1831 else if (pComboBox
== &aOldSymbolSets
)
1832 // allow only names from the list
1833 SelectSymbolSet(aOldSymbolSets
, aOldSymbolSets
.GetText(), true);
1834 else if (pComboBox
== &aStyles
)
1835 // allow only names from the list (that's the case here anyway)
1836 SelectStyle(aStyles
.GetText(), true);
1839 #if OSL_DEBUG_LEVEL > 1
1840 OSL_FAIL("Sm : wrong combobox argument");
1844 pComboBox
->SetSelection(aSelection
);
1852 IMPL_LINK( SmSymDefineDialog
, FontChangeHdl
, ListBox
*, EMPTYARG pListBox
)
1855 #if OSL_DEBUG_LEVEL > 1
1856 OSL_ENSURE(pListBox
== &aFonts
, "Sm : wrong argument");
1859 SelectFont(aFonts
.GetSelectEntry());
1864 IMPL_LINK( SmSymDefineDialog
, SubsetChangeHdl
, ListBox
*, EMPTYARG pListBox
)
1867 sal_uInt16 nPos
= aFontsSubsetLB
.GetSelectEntryPos();
1868 if (LISTBOX_ENTRY_NOTFOUND
!= nPos
)
1870 const Subset
* pSubset
= reinterpret_cast<const Subset
*> (aFontsSubsetLB
.GetEntryData( nPos
));
1873 aCharsetDisplay
.SelectCharacter( pSubset
->GetRangeMin() );
1880 IMPL_LINK( SmSymDefineDialog
, StyleChangeHdl
, ComboBox
*, EMPTYARG pComboBox
)
1883 #if OSL_DEBUG_LEVEL > 1
1884 OSL_ENSURE(pComboBox
== &aStyles
, "Sm : falsches Argument");
1887 SelectStyle(aStyles
.GetText());
1892 IMPL_LINK_NOARG(SmSymDefineDialog
, CharHighlightHdl
)
1894 sal_UCS4 cChar
= aCharsetDisplay
.GetSelectCharacter();
1896 #if OSL_DEBUG_LEVEL > 1
1897 OSL_ENSURE( pSubsetMap
, "SubsetMap missing" );
1901 const Subset
* pSubset
= pSubsetMap
->GetSubsetByUnicode( cChar
);
1903 aFontsSubsetLB
.SelectEntry( pSubset
->GetName() );
1905 aFontsSubsetLB
.SetNoSelection();
1908 aSymbolDisplay
.SetSymbol( cChar
, aCharsetDisplay
.GetFont() );
1912 // display Unicode position as symbol name while iterating over characters
1913 const OUString
aHex(OUString::valueOf(static_cast<sal_Int64
>(cChar
), 16 ).toAsciiUpperCase());
1914 const OUString
aPattern( (aHex
.getLength() > 4) ? OUString("Ux000000") : OUString("Ux0000") );
1915 OUString
aUnicodePos( aPattern
.copy( 0, aPattern
.getLength() - aHex
.getLength() ) );
1916 aUnicodePos
+= aHex
;
1917 aSymbols
.SetText( aUnicodePos
);
1918 aSymbolName
.SetText( aUnicodePos
);
1924 IMPL_LINK( SmSymDefineDialog
, AddClickHdl
, Button
*, EMPTYARG pButton
)
1927 #if OSL_DEBUG_LEVEL > 1
1928 OSL_ENSURE(pButton
== &aAddBtn
, "Sm : wrong argument");
1929 OSL_ENSURE(aAddBtn
.IsEnabled(), "Sm : requirements met ??");
1933 const SmSym
aNewSymbol( aSymbols
.GetText(), aCharsetDisplay
.GetFont(),
1934 aCharsetDisplay
.GetSelectCharacter(), aSymbolSets
.GetText() );
1935 //OSL_ENSURE( aSymbolMgrCopy.GetSymbolByName(aTmpSymbolName) == NULL, "symbol already exists" );
1936 aSymbolMgrCopy
.AddOrReplaceSymbol( aNewSymbol
);
1938 // update display of new symbol
1939 aSymbolDisplay
.SetSymbol( &aNewSymbol
);
1940 aSymbolName
.SetText( aNewSymbol
.GetName() );
1941 aSymbolSetName
.SetText( aNewSymbol
.GetSymbolSetName() );
1943 // update list box entries
1944 FillSymbolSets(aOldSymbolSets
, false);
1945 FillSymbolSets(aSymbolSets
, false);
1946 FillSymbols(aOldSymbols
,false);
1947 FillSymbols(aSymbols
,false);
1955 IMPL_LINK( SmSymDefineDialog
, ChangeClickHdl
, Button
*, EMPTYARG pButton
)
1958 #if OSL_DEBUG_LEVEL > 1
1959 OSL_ENSURE(pButton
== &aChangeBtn
, "Sm : wrong argument");
1960 OSL_ENSURE(aChangeBtn
.IsEnabled(), "Sm : requirements met ??");
1963 // get new Sybol to use
1964 //! get font from symbol-disp lay since charset-display does not keep
1965 //! the bold attribut.
1966 const SmSym
aNewSymbol( aSymbols
.GetText(), aCharsetDisplay
.GetFont(),
1967 aCharsetDisplay
.GetSelectCharacter(), aSymbolSets
.GetText() );
1969 // remove old symbol if the name was changed then add new one
1970 const bool bNameChanged
= aOldSymbols
.GetText() != aSymbols
.GetText();
1972 aSymbolMgrCopy
.RemoveSymbol( aOldSymbols
.GetText() );
1973 aSymbolMgrCopy
.AddOrReplaceSymbol( aNewSymbol
, true );
1975 // clear display for original symbol if necessary
1977 SetOrigSymbol(NULL
, OUString());
1979 // update display of new symbol
1980 aSymbolDisplay
.SetSymbol( &aNewSymbol
);
1981 aSymbolName
.SetText( aNewSymbol
.GetName() );
1982 aSymbolSetName
.SetText( aNewSymbol
.GetSymbolSetName() );
1984 // update list box entries
1985 FillSymbolSets(aOldSymbolSets
, false);
1986 FillSymbolSets(aSymbolSets
, false);
1987 FillSymbols(aOldSymbols
,false);
1988 FillSymbols(aSymbols
,false);
1996 IMPL_LINK( SmSymDefineDialog
, DeleteClickHdl
, Button
*, EMPTYARG pButton
)
1999 #if OSL_DEBUG_LEVEL > 1
2000 OSL_ENSURE(pButton
== &aDeleteBtn
, "Sm : wrong argument");
2001 OSL_ENSURE(aDeleteBtn
.IsEnabled(), "Sm : requirements met ??");
2006 aSymbolMgrCopy
.RemoveSymbol( pOrigSymbol
->GetName() );
2008 // clear display for original symbol
2009 SetOrigSymbol(NULL
, OUString());
2011 // update list box entries
2012 FillSymbolSets(aOldSymbolSets
, false);
2013 FillSymbolSets(aSymbolSets
, false);
2014 FillSymbols(aOldSymbols
,false);
2015 FillSymbols(aSymbols
,false);
2024 void SmSymDefineDialog::UpdateButtons()
2029 OUString
aTmpSymbolName (aSymbols
.GetText()),
2030 aTmpSymbolSetName (aSymbolSets
.GetText());
2032 if (aTmpSymbolName
.getLength() > 0 && aTmpSymbolSetName
.getLength() > 0)
2034 // are all settings equal?
2035 //! (Font-, Style- und SymbolSet name comparison is not case sensitive)
2036 bool bEqual
= pOrigSymbol
2037 && aTmpSymbolSetName
.equalsIgnoreAsciiCase(aOldSymbolSetName
.GetText())
2038 && aTmpSymbolName
.equals(pOrigSymbol
->GetName())
2039 && aFonts
.GetSelectEntry().EqualsIgnoreCaseAscii(
2040 pOrigSymbol
->GetFace().GetName())
2041 && aStyles
.GetText().equalsIgnoreAsciiCase(
2042 GetFontStyles().GetStyleName(pOrigSymbol
->GetFace()))
2043 && aCharsetDisplay
.GetSelectCharacter() == pOrigSymbol
->GetCharacter();
2045 // only add it if there isn't already a symbol with the same name
2046 bAdd
= aSymbolMgrCopy
.GetSymbolByName(aTmpSymbolName
) == NULL
;
2048 // only delete it if all settings are equal
2049 bDelete
= pOrigSymbol
!= NULL
;
2051 // only change it if the old symbol exists and the new one is different
2052 bChange
= pOrigSymbol
&& !bEqual
;
2055 aAddBtn
.Enable(bAdd
);
2056 aChangeBtn
.Enable(bChange
);
2057 aDeleteBtn
.Enable(bDelete
);
2060 IMPL_LINK( SmSymDefineDialog
, HelpButtonClickHdl
, Button
*, EMPTYARG
/*pButton*/ )
2062 // start help system
2063 Help
* pHelp
= Application::GetHelp();
2066 pHelp
->Start( OUString( "HID_SMA_SYMDEFINEDIALOG" ), &aHelpBtn
);
2071 SmSymDefineDialog::SmSymDefineDialog(Window
* pParent
,
2072 OutputDevice
*pFntListDevice
, SmSymbolManager
&rMgr
, bool bFreeRes
) :
2073 ModalDialog (pParent
, SmResId(RID_SYMDEFINEDIALOG
)),
2074 aOldSymbolText (this, SmResId(1)),
2075 aOldSymbols (this, SmResId(1)),
2076 aOldSymbolSetText (this, SmResId(2)),
2077 aOldSymbolSets (this, SmResId(2)),
2078 aCharsetDisplay (this, SmResId(1)),
2079 aSymbolText (this, SmResId(9)),
2080 aSymbols (this, SmResId(4)),
2081 aSymbolSetText (this, SmResId(10)),
2082 aSymbolSets (this, SmResId(5)),
2083 aFontText (this, SmResId(3)),
2084 aFonts (this, SmResId(1)),
2085 aFontsSubsetFT (this, SmResId( FT_FONTS_SUBSET
)),
2086 aFontsSubsetLB (this, SmResId( LB_FONTS_SUBSET
)),
2087 aStyleText (this, SmResId(4)),
2088 aStyles (this, SmResId(3)),
2089 aOldSymbolName (this, SmResId(7)),
2090 aOldSymbolDisplay (this, SmResId(3)),
2091 aOldSymbolSetName (this, SmResId(8)),
2092 aSymbolName (this, SmResId(5)),
2093 aSymbolDisplay (this, SmResId(2)),
2094 aSymbolSetName (this, SmResId(6)),
2095 aOkBtn (this, SmResId(1)),
2096 aHelpBtn (this, SmResId(1)),
2097 aCancelBtn (this, SmResId(1)),
2098 aAddBtn (this, SmResId(1)),
2099 aChangeBtn (this, SmResId(2)),
2100 aDeleteBtn (this, SmResId(3)),
2101 aRightArrow (this, SmResId(1)),
2102 aRigthArrow_Im (SmResId(1)),
2110 aHelpBtn
.SetClickHdl(LINK(this, SmSymDefineDialog
, HelpButtonClickHdl
));
2112 pFontList
= new FontList( pFntListDevice
);
2116 // auto completion is troublesome since that symbols character also gets automatically selected in the
2117 // display and if the user previously selected a character to define/redefine that one this is bad
2118 aOldSymbols
.EnableAutocomplete( false, true );
2119 aSymbols
.EnableAutocomplete( false, true );
2122 if (aFonts
.GetEntryCount() > 0)
2123 SelectFont(aFonts
.GetEntry(0));
2127 SetSymbolSetManager(rSymbolMgr
);
2129 aOldSymbols
.SetSelectHdl(LINK(this, SmSymDefineDialog
, OldSymbolChangeHdl
));
2130 aOldSymbolSets
.SetSelectHdl(LINK(this, SmSymDefineDialog
, OldSymbolSetChangeHdl
));
2131 aSymbolSets
.SetModifyHdl(LINK(this, SmSymDefineDialog
, ModifyHdl
));
2132 aOldSymbolSets
.SetModifyHdl(LINK(this, SmSymDefineDialog
, ModifyHdl
));
2133 aSymbols
.SetModifyHdl(LINK(this, SmSymDefineDialog
, ModifyHdl
));
2134 aOldSymbols
.SetModifyHdl(LINK(this, SmSymDefineDialog
, ModifyHdl
));
2135 aStyles
.SetModifyHdl(LINK(this, SmSymDefineDialog
, ModifyHdl
));
2136 aFonts
.SetSelectHdl(LINK(this, SmSymDefineDialog
, FontChangeHdl
));
2137 aFontsSubsetLB
.SetSelectHdl(LINK(this, SmSymDefineDialog
, SubsetChangeHdl
));
2138 aStyles
.SetSelectHdl(LINK(this, SmSymDefineDialog
, StyleChangeHdl
));
2139 aAddBtn
.SetClickHdl (LINK(this, SmSymDefineDialog
, AddClickHdl
));
2140 aChangeBtn
.SetClickHdl (LINK(this, SmSymDefineDialog
, ChangeClickHdl
));
2141 aDeleteBtn
.SetClickHdl (LINK(this, SmSymDefineDialog
, DeleteClickHdl
));
2142 aCharsetDisplay
.SetHighlightHdl( LINK( this, SmSymDefineDialog
, CharHighlightHdl
) );
2144 // preview like controls should have a 2D look
2145 aOldSymbolDisplay
.SetBorderStyle( WINDOW_BORDER_MONO
);
2146 aSymbolDisplay
.SetBorderStyle( WINDOW_BORDER_MONO
);
2150 SmSymDefineDialog::~SmSymDefineDialog()
2156 void SmSymDefineDialog::InitColor_Impl()
2158 #if OSL_DEBUG_LEVEL > 1
2159 Color
aBC( GetDisplayBackground().GetColor() );
2161 ColorData nBgCol
= COL_WHITE
,
2162 nTxtCol
= COL_BLACK
;
2163 bool bHighContrast
= GetSettings().GetStyleSettings().GetHighContrastMode();
2166 const StyleSettings
&rS
= GetSettings().GetStyleSettings();
2167 nBgCol
= rS
.GetFieldColor().GetColor();
2168 nTxtCol
= rS
.GetFieldTextColor().GetColor();
2171 Color
aTmpColor( nBgCol
);
2172 Wallpaper
aWall( aTmpColor
);
2173 Color
aTxtColor( nTxtCol
);
2174 aCharsetDisplay
.SetBackground( aWall
);
2175 aCharsetDisplay
.SetTextColor( aTxtColor
);
2176 aOldSymbolDisplay
.SetBackground( aWall
);
2177 aOldSymbolDisplay
.SetTextColor( aTxtColor
);
2178 aSymbolDisplay
.SetBackground( aWall
);
2179 aSymbolDisplay
.SetTextColor( aTxtColor
);
2181 const Image
&rArrowRight
= aRigthArrow_Im
;
2182 aRightArrow
.SetImage( rArrowRight
);
2186 void SmSymDefineDialog::DataChanged( const DataChangedEvent
& rDCEvt
)
2188 if ( rDCEvt
.GetType() == DATACHANGED_SETTINGS
&&
2189 (rDCEvt
.GetFlags() & SETTINGS_STYLE
) )
2192 ModalDialog::DataChanged( rDCEvt
);
2196 short SmSymDefineDialog::Execute()
2198 short nResult
= ModalDialog::Execute();
2200 // apply changes if dialog was closed by clicking OK
2201 if (aSymbolMgrCopy
.IsModified() && nResult
== RET_OK
)
2202 rSymbolMgr
= aSymbolMgrCopy
;
2208 void SmSymDefineDialog::SetSymbolSetManager(const SmSymbolManager
&rMgr
)
2210 aSymbolMgrCopy
= rMgr
;
2212 // Set the modified flag of the copy to false so that
2213 // we can check later on if anything has been changed
2214 aSymbolMgrCopy
.SetModified(false);
2216 FillSymbolSets(aOldSymbolSets
);
2217 if (aOldSymbolSets
.GetEntryCount() > 0)
2218 SelectSymbolSet(aOldSymbolSets
.GetEntry(0));
2219 FillSymbolSets(aSymbolSets
);
2220 if (aSymbolSets
.GetEntryCount() > 0)
2221 SelectSymbolSet(aSymbolSets
.GetEntry(0));
2222 FillSymbols(aOldSymbols
);
2223 if (aOldSymbols
.GetEntryCount() > 0)
2224 SelectSymbol(aOldSymbols
.GetEntry(0));
2225 FillSymbols(aSymbols
);
2226 if (aSymbols
.GetEntryCount() > 0)
2227 SelectSymbol(aSymbols
.GetEntry(0));
2233 bool SmSymDefineDialog::SelectSymbolSet(ComboBox
&rComboBox
,
2234 const OUString
&rSymbolSetName
, bool bDeleteText
)
2236 #if OSL_DEBUG_LEVEL > 1
2237 OSL_ENSURE(&rComboBox
== &aOldSymbolSets
|| &rComboBox
== &aSymbolSets
,
2238 "Sm : wrong ComboBox");
2241 // trim SymbolName (no leading and trailing blanks)
2242 OUString
aNormName (rSymbolSetName
);
2243 aNormName
= comphelper::string::stripStart(aNormName
, ' ');
2244 aNormName
= comphelper::string::stripEnd(aNormName
, ' ');
2245 // and remove possible deviations within the input
2246 rComboBox
.SetText(aNormName
);
2249 sal_uInt16 nPos
= rComboBox
.GetEntryPos(aNormName
);
2251 if (nPos
!= COMBOBOX_ENTRY_NOTFOUND
)
2253 rComboBox
.SetText(rComboBox
.GetEntry(nPos
));
2256 else if (bDeleteText
)
2257 rComboBox
.SetText(OUString());
2259 bool bIsOld
= &rComboBox
== &aOldSymbolSets
;
2261 // setting the SymbolSet name at the associated display
2262 FixedText
&rFT
= bIsOld
? aOldSymbolSetName
: aSymbolSetName
;
2263 rFT
.SetText(rComboBox
.GetText());
2265 // set the symbol name which belongs to the SymbolSet at the associated combobox
2266 ComboBox
&rCB
= bIsOld
? aOldSymbols
: aSymbols
;
2267 FillSymbols(rCB
, false);
2269 // display a valid respectively no symbol when changing the SymbolSets
2272 OUString aTmpOldSymbolName
;
2273 if (aOldSymbols
.GetEntryCount() > 0)
2274 aTmpOldSymbolName
= aOldSymbols
.GetEntry(0);
2275 SelectSymbol(aOldSymbols
, aTmpOldSymbolName
, true);
2284 void SmSymDefineDialog::SetOrigSymbol(const SmSym
*pSymbol
,
2285 const OUString
&rSymbolSetName
)
2296 pOrigSymbol
= new SmSym( *pSymbol
);
2298 aSymName
= pSymbol
->GetName();
2299 aSymSetName
= rSymbolSetName
;
2300 aOldSymbolDisplay
.SetSymbol( pSymbol
);
2303 { // delete displayed symbols
2304 aOldSymbolDisplay
.SetText(OUString());
2305 aOldSymbolDisplay
.Invalidate();
2307 aOldSymbolName
.SetText(aSymName
);
2308 aOldSymbolSetName
.SetText(aSymSetName
);
2312 bool SmSymDefineDialog::SelectSymbol(ComboBox
&rComboBox
,
2313 const OUString
&rSymbolName
, bool bDeleteText
)
2315 #if OSL_DEBUG_LEVEL > 1
2316 OSL_ENSURE(&rComboBox
== &aOldSymbols
|| &rComboBox
== &aSymbols
,
2317 "Sm : wrong ComboBox");
2320 // trim SymbolName (no blanks)
2321 OUString
aNormName(comphelper::string::remove(rSymbolName
, ' '));
2322 // and remove possible deviations within the input
2323 rComboBox
.SetText(aNormName
);
2326 sal_uInt16 nPos
= rComboBox
.GetEntryPos(aNormName
);
2328 bool bIsOld
= &rComboBox
== &aOldSymbols
;
2330 if (nPos
!= COMBOBOX_ENTRY_NOTFOUND
)
2332 rComboBox
.SetText(rComboBox
.GetEntry(nPos
));
2336 const SmSym
*pSymbol
= GetSymbol(aSymbols
);
2339 // choose font and style accordingly
2340 const Font
&rFont
= pSymbol
->GetFace();
2341 SelectFont(rFont
.GetName(), false);
2342 SelectStyle(GetFontStyles().GetStyleName(rFont
), false);
2344 // Since setting the Font via the Style name of the SymbolFonts doesn't
2345 // work really well (e.g. it can be empty even though the font itself is
2346 // bold or italic) we're manually setting the Font with respect to the Symbol
2347 aCharsetDisplay
.SetFont(rFont
);
2348 aSymbolDisplay
.SetFont(rFont
);
2350 // select associated character
2351 SelectChar(pSymbol
->GetCharacter());
2353 // since SelectChar will also set the unicode point as text in the
2354 // symbols box, we have to set the symbol name again to get that one displayed
2355 aSymbols
.SetText( pSymbol
->GetName() );
2361 else if (bDeleteText
)
2362 rComboBox
.SetText(OUString());
2366 // if there's a change of the old symbol, show only the available ones, otherwise show none
2367 const SmSym
*pOldSymbol
= NULL
;
2368 OUString aTmpOldSymbolSetName
;
2369 if (nPos
!= COMBOBOX_ENTRY_NOTFOUND
)
2371 pOldSymbol
= aSymbolMgrCopy
.GetSymbolByName(aNormName
);
2372 aTmpOldSymbolSetName
= aOldSymbolSets
.GetText();
2374 SetOrigSymbol(pOldSymbol
, aTmpOldSymbolSetName
);
2377 aSymbolName
.SetText(rComboBox
.GetText());
2385 void SmSymDefineDialog::SetFont(const OUString
&rFontName
, const OUString
&rStyleName
)
2387 // get Font (FontInfo) matching name and style
2390 aFI
= pFontList
->Get(rFontName
, WEIGHT_NORMAL
, ITALIC_NONE
);
2391 SetFontStyle(rStyleName
, aFI
);
2393 aCharsetDisplay
.SetFont(aFI
);
2394 aSymbolDisplay
.SetFont(aFI
);
2396 // update subset listbox for new font's unicode subsets
2397 FontCharMap aFontCharMap
;
2398 aCharsetDisplay
.GetFontCharMap( aFontCharMap
);
2401 pSubsetMap
= new SubsetMap( &aFontCharMap
);
2403 aFontsSubsetLB
.Clear();
2405 const Subset
* pSubset
;
2406 while( NULL
!= (pSubset
= pSubsetMap
->GetNextSubset( bFirst
)) )
2408 sal_uInt16 nPos
= aFontsSubsetLB
.InsertEntry( pSubset
->GetName());
2409 aFontsSubsetLB
.SetEntryData( nPos
, (void *) pSubset
);
2410 // subset must live at least as long as the selected font !!!
2412 aFontsSubsetLB
.SelectEntryPos( nPos
);
2416 aFontsSubsetLB
.SetNoSelection();
2417 aFontsSubsetLB
.Enable( !bFirst
);
2421 bool SmSymDefineDialog::SelectFont(const OUString
&rFontName
, bool bApplyFont
)
2424 sal_uInt16 nPos
= aFonts
.GetEntryPos(rFontName
);
2426 if (nPos
!= LISTBOX_ENTRY_NOTFOUND
)
2428 aFonts
.SelectEntryPos(nPos
);
2429 if (aStyles
.GetEntryCount() > 0)
2430 SelectStyle(aStyles
.GetEntry(0));
2433 SetFont(aFonts
.GetSelectEntry(), aStyles
.GetText());
2435 aSymbolDisplay
.SetSymbol( aCharsetDisplay
.GetSelectCharacter(), aCharsetDisplay
.GetFont() );
2440 aFonts
.SetNoSelection();
2449 bool SmSymDefineDialog::SelectStyle(const OUString
&rStyleName
, bool bApplyFont
)
2452 sal_uInt16 nPos
= aStyles
.GetEntryPos(rStyleName
);
2454 // if the style is not available take the first available one (if existent)
2455 if (nPos
== COMBOBOX_ENTRY_NOTFOUND
&& aStyles
.GetEntryCount() > 0)
2458 if (nPos
!= COMBOBOX_ENTRY_NOTFOUND
)
2460 aStyles
.SetText(aStyles
.GetEntry(nPos
));
2463 SetFont(aFonts
.GetSelectEntry(), aStyles
.GetText());
2465 aSymbolDisplay
.SetSymbol( aCharsetDisplay
.GetSelectCharacter(), aCharsetDisplay
.GetFont() );
2470 aStyles
.SetText(OUString());
2478 void SmSymDefineDialog::SelectChar(sal_Unicode cChar
)
2480 aCharsetDisplay
.SelectCharacter( cChar
);
2481 aSymbolDisplay
.SetSymbol( cChar
, aCharsetDisplay
.GetFont() );
2487 /**************************************************************************/
2489 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */