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