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