xref: /aoo41x/main/starmath/source/dialog.cxx (revision 7ea7a1cc)
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 
GetCount() const80     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 
SmFontStyles()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 
GetStyleName(const Font & rFont) const99 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 
GetStyleName(sal_uInt16 nIdx) const116 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 
GetFontStyles()135 const SmFontStyles & GetFontStyles()
136 {
137     static const SmFontStyles aImpl;
138     return aImpl;
139 }
140 
141 /////////////////////////////////////////////////////////////////
142 
SetFontStyle(const XubString & rStyleName,Font & rFont)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 
IMPL_LINK_INLINE_START(SmPrintOptionsTabPage,SizeButtonClickHdl,Button *,EMPTYARG)168 IMPL_LINK_INLINE_START( SmPrintOptionsTabPage, SizeButtonClickHdl, Button *, EMPTYARG/*pButton*/ )
169 {
170 	aZoom.Enable(aSizeZoomed.IsChecked());
171 	return 0;
172 }
IMPL_LINK_INLINE_END(SmPrintOptionsTabPage,SizeButtonClickHdl,Button *,pButton)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 
FillItemSet(SfxItemSet & rSet)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 
Reset(const SfxItemSet & rSet)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 
Create(Window * pWindow,const SfxItemSet & rSet)243 SfxTabPage* SmPrintOptionsTabPage::Create(Window* pWindow, const SfxItemSet& rSet)
244 {
245 	return (new SmPrintOptionsTabPage(pWindow, rSet));
246 }
247 
248 /**************************************************************************/
249 
250 
Paint(const Rectangle & rRect)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 
SetFont(const Font & rFont)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 
IMPL_LINK_INLINE_START(SmFontDialog,FontSelectHdl,ComboBox *,pComboBox)278 IMPL_LINK_INLINE_START( SmFontDialog, FontSelectHdl, ComboBox *, pComboBox )
279 {
280 	Face.SetName(pComboBox->GetText());
281 	aShowFont.SetFont(Face);
282 	return 0;
283 }
IMPL_LINK_INLINE_END(SmFontDialog,FontSelectHdl,ComboBox *,pComboBox)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 
IMPL_LINK(SmFontDialog,AttrChangeHdl,CheckBox *,EMPTYARG)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 
SetFont(const Font & rFont)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 
SmFontDialog(Window * pParent,OutputDevice * pFntListDevice,sal_Bool bHideCheckboxes,sal_Bool bFreeRes)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 
InitColor_Impl()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 
DataChanged(const DataChangedEvent & rDCEvt)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 
IMPL_LINK(SmFontSizeDialog,DefaultButtonClickHdl,Button *,EMPTYARG)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 
SmFontSizeDialog(Window * pParent,sal_Bool bFreeRes)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 
ReadFrom(const SmFormat & rFormat)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 
WriteTo(SmFormat & rFormat) const480 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 
IMPL_LINK(SmFontTypeDialog,MenuSelectHdl,Menu *,pMenu)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 
IMPL_LINK_INLINE_START(SmFontTypeDialog,DefaultButtonClickHdl,Button *,EMPTYARG)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 }
IMPL_LINK_INLINE_END(SmFontTypeDialog,DefaultButtonClickHdl,Button *,pButton)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 
ReadFrom(const SmFormat & rFormat)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 
WriteTo(SmFormat & rFormat) const602 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 
SmCategoryDesc(const ResId & rResId,sal_uInt16 nCategoryIdx)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 
~SmCategoryDesc()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 
IMPL_LINK(SmDistanceDialog,GetFocusHdl,Control *,pControl)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 
IMPL_LINK(SmDistanceDialog,MenuSelectHdl,Menu *,pMenu)730 IMPL_LINK( SmDistanceDialog, MenuSelectHdl, Menu *, pMenu )
731 {
732 	SetCategory(pMenu->GetCurItemId() - 1);
733 	return 0;
734 }
735 
736 
IMPL_LINK(SmDistanceDialog,DefaultButtonClickHdl,Button *,EMPTYARG)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 
IMPL_LINK(SmDistanceDialog,CheckBoxClickHdl,CheckBox *,pCheckBox)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 
SetHelpId(MetricField & rField,const rtl::OString & sHelpId)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 
SetCategory(sal_uInt16 nCategory)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_PERCENT;
869 			nDigits = 0;
870 		}
871 		else
872 		{
873 			eUnit   = FUNIT_100TH_MM;
874 			nDigits = 2;
875 		}
876         pMF->SetUnit(eUnit);            //! veraendert den Wert
877 		pMF->SetDecimalDigits(nDigits);
878 
879 		if (bActive)
880 		{
881 			pCat = Categories[nCategory];
882 			pFT->SetText(*pCat->GetString(i));
883 
884 			pMF->SetMin(pCat->GetMinimum(i));
885 			pMF->SetMax(pCat->GetMaximum(i));
886 			pMF->SetValue(pCat->GetValue(i));
887 
888 			SetHelpId(*pMF, aCatMf2Hid[nCategory][i]);
889 		}
890 	}
891     // nun noch die CheckBox und das zugehoerige MetricField genau dann aktivieren,
892 	// falls es sich um das Klammer Menu handelt.
893 	bActive = nCategory == 5;
894 	aCheckBox1.Show(bActive);
895 	aCheckBox1.Enable(bActive);
896 	if (bActive)
897 	{
898 		aCheckBox1.Check( bScaleAllBrackets );
899 
900 		sal_Bool bChecked = aCheckBox1.IsChecked();
901 		aFixedText4  .Enable( bChecked );
902 		aMetricField4.Enable( bChecked );
903 	}
904 
905 	aMenuButton.GetPopupMenu()->CheckItem(nCategory + 1, sal_True);
906     aFixedLine.SetText(Categories[nCategory]->GetName());
907 
908 	nActiveCategory = nCategory;
909 
910 	aMetricField1.GrabFocus();
911 	Invalidate();
912 	Update();
913 }
914 
915 
SmDistanceDialog(Window * pParent,sal_Bool bFreeRes)916 SmDistanceDialog::SmDistanceDialog(Window *pParent, sal_Bool bFreeRes)
917 	: ModalDialog(pParent, SmResId(RID_DISTANCEDIALOG)),
918     aFixedText1    (this, SmResId(1)),
919     aMetricField1  (this, SmResId(1)),
920     aFixedText2    (this, SmResId(2)),
921     aMetricField2  (this, SmResId(2)),
922     aFixedText3    (this, SmResId(3)),
923     aMetricField3  (this, SmResId(3)),
924     aCheckBox1     (this, SmResId(1)),
925     aFixedText4    (this, SmResId(4)),
926     aMetricField4  (this, SmResId(4)),
927     aOKButton1     (this, SmResId(1)),
928     aCancelButton1 (this, SmResId(1)),
929     aMenuButton    (this, SmResId(1)),
930     aDefaultButton (this, SmResId(1)),
931     aBitmap        (this, SmResId(1)),
932     aFixedLine     (this, SmResId(1))
933 {
934     for (sal_uInt16 i = 0; i < NOCATEGORIES; i++)
935 		Categories[i] = new SmCategoryDesc(SmResId(i + 1), i);
936 	nActiveCategory   = CATEGORY_NONE;
937 	bScaleAllBrackets = sal_False;
938 
939 	if (bFreeRes)
940 		FreeResource();
941 
942     ApplyImages();
943 
944     // preview like controls should have a 2D look
945     aBitmap.SetBorderStyle( WINDOW_BORDER_MONO );
946 
947 	aMetricField1.SetGetFocusHdl(LINK(this, SmDistanceDialog, GetFocusHdl));
948 	aMetricField2.SetGetFocusHdl(LINK(this, SmDistanceDialog, GetFocusHdl));
949 	aMetricField3.SetGetFocusHdl(LINK(this, SmDistanceDialog, GetFocusHdl));
950 	aMetricField4.SetGetFocusHdl(LINK(this, SmDistanceDialog, GetFocusHdl));
951 	aCheckBox1.SetClickHdl(LINK(this, SmDistanceDialog, CheckBoxClickHdl));
952 
953 	aMenuButton.GetPopupMenu()->SetSelectHdl(LINK(this, SmDistanceDialog, MenuSelectHdl));
954 
955 	aDefaultButton.SetClickHdl(LINK(this, SmDistanceDialog, DefaultButtonClickHdl));
956 }
957 
958 
~SmDistanceDialog()959 SmDistanceDialog::~SmDistanceDialog()
960 {
961 	for (int i = 0; i < NOCATEGORIES; i++)
962 		DELETEZ(Categories[i]);
963 }
964 
ApplyImages()965 void SmDistanceDialog::ApplyImages()
966 {
967     sal_Bool bHighContrast = GetSettings().GetStyleSettings().GetHighContrastMode();
968     for (int i = 0;  i < NOCATEGORIES;  ++i)
969     {
970         SmCategoryDesc *pCat = Categories[i];
971         if (pCat)
972             pCat->SetHighContrast( bHighContrast );
973     }
974 }
975 
DataChanged(const DataChangedEvent & rEvt)976 void SmDistanceDialog::DataChanged( const DataChangedEvent &rEvt )
977 {
978     if ( (rEvt.GetType() == DATACHANGED_SETTINGS) && (rEvt.GetFlags() & SETTINGS_STYLE) )
979             ApplyImages();
980 
981     ModalDialog::DataChanged( rEvt );
982 }
983 
ReadFrom(const SmFormat & rFormat)984 void SmDistanceDialog::ReadFrom(const SmFormat &rFormat)
985 {
986 	Categories[0]->SetValue(0, rFormat.GetDistance(DIS_HORIZONTAL));
987 	Categories[0]->SetValue(1, rFormat.GetDistance(DIS_VERTICAL));
988 	Categories[0]->SetValue(2, rFormat.GetDistance(DIS_ROOT));
989 	Categories[1]->SetValue(0, rFormat.GetDistance(DIS_SUPERSCRIPT));
990 	Categories[1]->SetValue(1, rFormat.GetDistance(DIS_SUBSCRIPT));
991 	Categories[2]->SetValue(0, rFormat.GetDistance(DIS_NUMERATOR));
992 	Categories[2]->SetValue(1, rFormat.GetDistance(DIS_DENOMINATOR));
993 	Categories[3]->SetValue(0, rFormat.GetDistance(DIS_FRACTION));
994 	Categories[3]->SetValue(1, rFormat.GetDistance(DIS_STROKEWIDTH));
995 	Categories[4]->SetValue(0, rFormat.GetDistance(DIS_UPPERLIMIT));
996 	Categories[4]->SetValue(1, rFormat.GetDistance(DIS_LOWERLIMIT));
997 	Categories[5]->SetValue(0, rFormat.GetDistance(DIS_BRACKETSIZE));
998 	Categories[5]->SetValue(1, rFormat.GetDistance(DIS_BRACKETSPACE));
999 	Categories[5]->SetValue(3, rFormat.GetDistance(DIS_NORMALBRACKETSIZE));
1000 	Categories[6]->SetValue(0, rFormat.GetDistance(DIS_MATRIXROW));
1001 	Categories[6]->SetValue(1, rFormat.GetDistance(DIS_MATRIXCOL));
1002 	Categories[7]->SetValue(0, rFormat.GetDistance(DIS_ORNAMENTSIZE));
1003 	Categories[7]->SetValue(1, rFormat.GetDistance(DIS_ORNAMENTSPACE));
1004 	Categories[8]->SetValue(0, rFormat.GetDistance(DIS_OPERATORSIZE));
1005 	Categories[8]->SetValue(1, rFormat.GetDistance(DIS_OPERATORSPACE));
1006 	Categories[9]->SetValue(0, rFormat.GetDistance(DIS_LEFTSPACE));
1007 	Categories[9]->SetValue(1, rFormat.GetDistance(DIS_RIGHTSPACE));
1008 	Categories[9]->SetValue(2, rFormat.GetDistance(DIS_TOPSPACE));
1009 	Categories[9]->SetValue(3, rFormat.GetDistance(DIS_BOTTOMSPACE));
1010 
1011 	bScaleAllBrackets = rFormat.IsScaleNormalBrackets();
1012 
1013 	// force update (even of category 0) by setting nActiveCategory to a
1014 	// non-existent category number
1015 	nActiveCategory = CATEGORY_NONE;
1016 	SetCategory(0);
1017 }
1018 
1019 
WriteTo(SmFormat & rFormat)1020 void SmDistanceDialog::WriteTo(SmFormat &rFormat) /*const*/
1021 {
1022     // hmm... koennen die tatsaechlich unterschiedlich sein?
1023     // wenn nicht kann oben naemlich das const stehen!
1024 	SetCategory(nActiveCategory);
1025 
1026 	rFormat.SetDistance( DIS_HORIZONTAL,    	Categories[0]->GetValue(0) );
1027 	rFormat.SetDistance( DIS_VERTICAL,  		Categories[0]->GetValue(1) );
1028 	rFormat.SetDistance( DIS_ROOT,  			Categories[0]->GetValue(2) );
1029 	rFormat.SetDistance( DIS_SUPERSCRIPT,   	Categories[1]->GetValue(0) );
1030 	rFormat.SetDistance( DIS_SUBSCRIPT,     	Categories[1]->GetValue(1) );
1031 	rFormat.SetDistance( DIS_NUMERATOR,     	Categories[2]->GetValue(0) );
1032 	rFormat.SetDistance( DIS_DENOMINATOR,   	Categories[2]->GetValue(1) );
1033 	rFormat.SetDistance( DIS_FRACTION,  		Categories[3]->GetValue(0) );
1034 	rFormat.SetDistance( DIS_STROKEWIDTH,   	Categories[3]->GetValue(1) );
1035 	rFormat.SetDistance( DIS_UPPERLIMIT,    	Categories[4]->GetValue(0) );
1036 	rFormat.SetDistance( DIS_LOWERLIMIT,    	Categories[4]->GetValue(1) );
1037 	rFormat.SetDistance( DIS_BRACKETSIZE,   	Categories[5]->GetValue(0) );
1038 	rFormat.SetDistance( DIS_BRACKETSPACE,  	Categories[5]->GetValue(1) );
1039 	rFormat.SetDistance( DIS_MATRIXROW,     	Categories[6]->GetValue(0) );
1040 	rFormat.SetDistance( DIS_MATRIXCOL,     	Categories[6]->GetValue(1) );
1041 	rFormat.SetDistance( DIS_ORNAMENTSIZE,  	Categories[7]->GetValue(0) );
1042 	rFormat.SetDistance( DIS_ORNAMENTSPACE, 	Categories[7]->GetValue(1) );
1043 	rFormat.SetDistance( DIS_OPERATORSIZE,  	Categories[8]->GetValue(0) );
1044 	rFormat.SetDistance( DIS_OPERATORSPACE, 	Categories[8]->GetValue(1) );
1045 	rFormat.SetDistance( DIS_LEFTSPACE,     	Categories[9]->GetValue(0) );
1046 	rFormat.SetDistance( DIS_RIGHTSPACE,    	Categories[9]->GetValue(1) );
1047 	rFormat.SetDistance( DIS_TOPSPACE,  		Categories[9]->GetValue(2) );
1048 	rFormat.SetDistance( DIS_BOTTOMSPACE,   	Categories[9]->GetValue(3) );
1049 	rFormat.SetDistance( DIS_NORMALBRACKETSIZE, Categories[5]->GetValue(3) );
1050 
1051 	rFormat.SetScaleNormalBrackets( bScaleAllBrackets );
1052 
1053 	rFormat.RequestApplyChanges();
1054 }
1055 
1056 
1057 /**************************************************************************/
1058 
1059 
IMPL_LINK(SmAlignDialog,DefaultButtonClickHdl,Button *,EMPTYARG)1060 IMPL_LINK( SmAlignDialog, DefaultButtonClickHdl, Button *, EMPTYARG /*pButton*/ )
1061 {
1062    QueryBox *pQueryBox = new QueryBox(this, SmResId(RID_DEFAULTSAVEQUERY));
1063 
1064 	if (pQueryBox->Execute() == RET_YES)
1065 	{
1066         SmModule *pp = SM_MOD();
1067         SmFormat aFmt( pp->GetConfig()->GetStandardFormat() );
1068         WriteTo( aFmt );
1069         pp->GetConfig()->SetStandardFormat( aFmt );
1070 	}
1071 
1072 	delete pQueryBox;
1073 	return 0;
1074 }
1075 
1076 
SmAlignDialog(Window * pParent,sal_Bool bFreeRes)1077 SmAlignDialog::SmAlignDialog(Window * pParent, sal_Bool bFreeRes)
1078 	: ModalDialog(pParent, SmResId(RID_ALIGNDIALOG)),
1079 	aLeft		   (this, SmResId(1)),
1080 	aCenter 	   (this, SmResId(2)),
1081 	aRight		   (this, SmResId(3)),
1082     aFixedLine1    (this, SmResId(1)),
1083 	aOKButton1	   (this, SmResId(1)),
1084 	aCancelButton1 (this, SmResId(1)),
1085 	aDefaultButton (this, SmResId(1))
1086 {
1087 	if (bFreeRes)
1088 		FreeResource();
1089 
1090 	aDefaultButton.SetClickHdl(LINK(this, SmAlignDialog, DefaultButtonClickHdl));
1091 }
1092 
1093 
ReadFrom(const SmFormat & rFormat)1094 void SmAlignDialog::ReadFrom(const SmFormat &rFormat)
1095 {
1096 	switch (rFormat.GetHorAlign())
1097 	{
1098 		case AlignLeft:
1099 			aLeft  .Check(sal_True);
1100 			aCenter.Check(sal_False);
1101 			aRight .Check(sal_False);
1102 			break;
1103 
1104 		case AlignCenter:
1105 			aLeft  .Check(sal_False);
1106 			aCenter.Check(sal_True);
1107 			aRight .Check(sal_False);
1108 			break;
1109 
1110 		case AlignRight:
1111 			aLeft  .Check(sal_False);
1112 			aCenter.Check(sal_False);
1113 			aRight .Check(sal_True);
1114 			break;
1115 	}
1116 }
1117 
1118 
WriteTo(SmFormat & rFormat) const1119 void SmAlignDialog::WriteTo(SmFormat &rFormat) const
1120 {
1121 	if (aLeft.IsChecked())
1122 		rFormat.SetHorAlign(AlignLeft);
1123 	else if (aRight.IsChecked())
1124 		rFormat.SetHorAlign(AlignRight);
1125 	else
1126 		rFormat.SetHorAlign(AlignCenter);
1127 
1128 	rFormat.RequestApplyChanges();
1129 }
1130 
1131 
1132 /**************************************************************************/
1133 
1134 
Paint(const Rectangle &)1135 void SmShowSymbolSet::Paint(const Rectangle&)
1136 {
1137 	Push(PUSH_MAPMODE);
1138 
1139     // MapUnit einstellen fuer die 'nLen' berechnet wurde
1140 	SetMapMode(MapMode(MAP_PIXEL));
1141 
1142     sal_uInt16 v        = sal::static_int_cast< sal_uInt16 >((aVScrollBar.GetThumbPos() * nColumns));
1143     size_t nSymbols = aSymbolSet.size();
1144 
1145     Color aTxtColor( GetTextColor() );
1146     for (sal_uInt16 i = v; i < nSymbols ; i++)
1147 	{
1148         SmSym    aSymbol (*aSymbolSet[i]);
1149 		Font     aFont	 (aSymbol.GetFace());
1150         aFont.SetAlign(ALIGN_TOP);
1151 
1152 		// etwas kleinere FontSize nehmen (als nLen) um etwas Luft zu haben
1153         // (hoffentlich auch genug fuer links und rechts!)
1154 		aFont.SetSize(Size(0, nLen - (nLen / 3)));
1155 		SetFont(aFont);
1156         // keep text color
1157         SetTextColor( aTxtColor );
1158 
1159 		int   nIV 	= i - v;
1160         sal_UCS4 cChar = aSymbol.GetCharacter();
1161         String aText( OUString( &cChar, 1 ) );
1162 		Size  aSize( GetTextWidth( aText ), GetTextHeight());
1163 
1164 		DrawText(Point((nIV % nColumns) * nLen + (nLen - aSize.Width()) / 2,
1165 					   (nIV / nColumns) * nLen + (nLen - aSize.Height()) / 2),
1166 				 aText);
1167 	}
1168 
1169 	if (nSelectSymbol != SYMBOL_NONE)
1170 	{
1171 		Invert(Rectangle(Point(((nSelectSymbol - v) % nColumns) * nLen,
1172 			  				   ((nSelectSymbol - v) / nColumns) * nLen),
1173 			  			 Size(nLen, nLen)));
1174 	}
1175 
1176 	Pop();
1177 }
1178 
1179 
MouseButtonDown(const MouseEvent & rMEvt)1180 void SmShowSymbolSet::MouseButtonDown(const MouseEvent& rMEvt)
1181 {
1182 	GrabFocus();
1183 
1184 	if (rMEvt.IsLeft() && Rectangle(Point(0, 0), aOutputSize).IsInside(rMEvt.GetPosPixel()))
1185 	{
1186         long nPos = (rMEvt.GetPosPixel().Y() / nLen) * nColumns + (rMEvt.GetPosPixel().X() / nLen) +
1187                       aVScrollBar.GetThumbPos() * nColumns;
1188         SelectSymbol( sal::static_int_cast< sal_uInt16 >(nPos) );
1189 
1190 		aSelectHdlLink.Call(this);
1191 
1192 		if (rMEvt.GetClicks() > 1) aDblClickHdlLink.Call(this);
1193 	}
1194 	else Control::MouseButtonDown (rMEvt);
1195 }
1196 
1197 
KeyInput(const KeyEvent & rKEvt)1198 void SmShowSymbolSet::KeyInput(const KeyEvent& rKEvt)
1199 {
1200 	sal_uInt16 n = nSelectSymbol;
1201 
1202 	if (n != SYMBOL_NONE)
1203 	{
1204 		switch (rKEvt.GetKeyCode().GetCode())
1205 		{
1206             case KEY_DOWN:      n = n + nColumns;   break;
1207             case KEY_UP:        n = n - nColumns;   break;
1208 			case KEY_LEFT:		n -= 1;	break;
1209 			case KEY_RIGHT:		n += 1;	break;
1210 			case KEY_HOME:		n  = 0;	break;
1211             case KEY_END:       n  = static_cast< sal_uInt16 >(aSymbolSet.size() - 1);   break;
1212 			case KEY_PAGEUP:	n -= nColumns * nRows;	break;
1213 			case KEY_PAGEDOWN:	n += nColumns * nRows;	break;
1214 
1215 			default:
1216 				Control::KeyInput(rKEvt);
1217 				return;
1218 		}
1219 	}
1220 	else
1221 		n = 0;
1222 
1223     if (n >= aSymbolSet.size())
1224 		n = nSelectSymbol;
1225 
1226 	// adjust scrollbar
1227 	if ((n < (sal_uInt16) (aVScrollBar.GetThumbPos() * nColumns)) ||
1228 		(n >= (sal_uInt16) ((aVScrollBar.GetThumbPos() + nRows) * nColumns)))
1229 	{
1230 		aVScrollBar.SetThumbPos(n / nColumns);
1231 		Invalidate();
1232 		Update();
1233 	}
1234 
1235 	SelectSymbol(n);
1236 	aSelectHdlLink.Call(this);
1237 }
1238 
1239 
SmShowSymbolSet(Window * pParent,const ResId & rResId)1240 SmShowSymbolSet::SmShowSymbolSet(Window *pParent, const ResId& rResId) :
1241 	Control(pParent, rResId),
1242 	aVScrollBar(this, WinBits(WB_VSCROLL))
1243 {
1244 	nSelectSymbol = SYMBOL_NONE;
1245 
1246 	aOutputSize = GetOutputSizePixel();
1247 	long nScrollBarWidth = aVScrollBar.GetSizePixel().Width(),
1248 		 nUseableWidth   = aOutputSize.Width() - nScrollBarWidth;
1249 
1250     // Hoehe von 16pt in Pixeln (passend zu 'aOutputSize')
1251 	nLen = (sal_uInt16) LogicToPixel(Size(0, 16), MapMode(MAP_POINT)).Height();
1252 
1253     nColumns = sal::static_int_cast< sal_uInt16 >(nUseableWidth / nLen);
1254 	if (nColumns > 2  && nColumns % 2 != 0)
1255 		nColumns--;
1256     nRows    = sal::static_int_cast< sal_uInt16 >(aOutputSize.Height() / nLen);
1257 #if OSL_DEBUG_LEVEL > 1
1258 	DBG_ASSERT(nColumns > 0, "Sm : keine Spalten");
1259 	DBG_ASSERT(nRows > 0, "Sm : keine Zeilen");
1260 #endif
1261 
1262 	// genau passend machen
1263 	aOutputSize.Width()	 = nColumns * nLen;
1264 	aOutputSize.Height() = nRows * nLen;
1265 
1266 	aVScrollBar.SetPosSizePixel(Point(aOutputSize.Width() + 1, -1),
1267 								Size(nScrollBarWidth, aOutputSize.Height() + 2));
1268 	aVScrollBar.Enable(sal_False);
1269 	aVScrollBar.Show();
1270 	aVScrollBar.SetScrollHdl(LINK(this, SmShowSymbolSet, ScrollHdl));
1271 
1272 	Size WindowSize (aOutputSize);
1273 	WindowSize.Width() += nScrollBarWidth;
1274 	SetOutputSizePixel(WindowSize);
1275 
1276 }
1277 
1278 
SetSymbolSet(const SymbolPtrVec_t & rSymbolSet)1279 void SmShowSymbolSet::SetSymbolSet(const SymbolPtrVec_t& rSymbolSet)
1280 {
1281 	aSymbolSet = rSymbolSet;
1282 
1283     if (static_cast< sal_uInt16 >(aSymbolSet.size()) > (nColumns * nRows))
1284 	{
1285         aVScrollBar.SetRange(Range(0, ((aSymbolSet.size() + (nColumns - 1)) / nColumns) - nRows));
1286 		aVScrollBar.Enable(sal_True);
1287 	}
1288 	else
1289 	{
1290 		aVScrollBar.SetRange(Range(0,0));
1291 		aVScrollBar.Enable (sal_False);
1292 	}
1293 
1294 	Invalidate();
1295 }
1296 
1297 
SelectSymbol(sal_uInt16 nSymbol)1298 void SmShowSymbolSet::SelectSymbol(sal_uInt16 nSymbol)
1299 {
1300 	int v = (int) (aVScrollBar.GetThumbPos() * nColumns);
1301 
1302 	if (nSelectSymbol != SYMBOL_NONE)
1303 		Invalidate(Rectangle(Point(((nSelectSymbol - v) % nColumns) * nLen,
1304 								   ((nSelectSymbol - v) / nColumns) * nLen),
1305 							 Size(nLen, nLen)));
1306 
1307     if (nSymbol < aSymbolSet.size())
1308 		nSelectSymbol = nSymbol;
1309 
1310     if (aSymbolSet.size() == 0)
1311 		nSelectSymbol = SYMBOL_NONE;
1312 
1313 	if (nSelectSymbol != SYMBOL_NONE)
1314 		Invalidate(Rectangle(Point(((nSelectSymbol - v) % nColumns) * nLen,
1315 								   ((nSelectSymbol - v) / nColumns) * nLen),
1316 							 Size(nLen, nLen)));
1317 
1318 	Update();
1319 }
1320 
1321 
IMPL_LINK(SmShowSymbolSet,ScrollHdl,ScrollBar *,EMPTYARG)1322 IMPL_LINK( SmShowSymbolSet, ScrollHdl, ScrollBar*, EMPTYARG /*pScrollBar*/)
1323 {
1324 	Invalidate();
1325 	return 0;
1326 }
1327 
1328 ////////////////////////////////////////////////////////////////////////////////
1329 
Paint(const Rectangle & rRect)1330 void SmShowSymbol::Paint(const Rectangle &rRect)
1331 {
1332     Control::Paint( rRect );
1333 
1334 	const XubString &rText = GetText();
1335 	Size            aTextSize(GetTextWidth(rText), GetTextHeight());
1336 
1337 	DrawText(Point((GetOutputSize().Width()  - aTextSize.Width())  / 2,
1338 				   (GetOutputSize().Height() * 7/10)), rText);
1339 }
1340 
1341 
MouseButtonDown(const MouseEvent & rMEvt)1342 void SmShowSymbol::MouseButtonDown(const MouseEvent& rMEvt)
1343 {
1344 	if (rMEvt.GetClicks() > 1)
1345 		aDblClickHdlLink.Call(this);
1346 	else
1347 		Control::MouseButtonDown (rMEvt);
1348 }
1349 
1350 
SetSymbol(const SmSym * pSymbol)1351 void SmShowSymbol::SetSymbol(const SmSym *pSymbol)
1352 {
1353 	if (pSymbol)
1354 	{
1355 		Font aFont (pSymbol->GetFace());
1356 		aFont.SetSize(Size(0, GetOutputSize().Height() - GetOutputSize().Height() / 3));
1357         aFont.SetAlign(ALIGN_BASELINE);
1358 		SetFont(aFont);
1359 
1360         sal_UCS4 cChar = pSymbol->GetCharacter();
1361         String aText( OUString( &cChar, 1 ) );
1362 		SetText( aText );
1363 	}
1364 
1365     // 'Invalidate' fuellt den background mit der background-Farbe.
1366     // Falls der NULL pointer uebergeben wurde reicht dies also zum loeschen
1367 	// der Anzeige
1368 	Invalidate();
1369 }
1370 
1371 
1372 ////////////////////////////////////////////////////////////////////////////////
1373 
FillSymbolSets(sal_Bool bDeleteText)1374 void SmSymbolDialog::FillSymbolSets(sal_Bool bDeleteText)
1375     // fuellt die Eintraege der moeglichen 'SymbolsSet's im Dialog mit den
1376 	// aktuellen Werten des SymbolSet Managers, selektiert aber keinen.
1377 {
1378 	aSymbolSets.Clear();
1379 	if (bDeleteText)
1380 		aSymbolSets.SetNoSelection();
1381 
1382     std::set< String >  aSybolSetNames( rSymbolMgr.GetSymbolSetNames() );
1383     std::set< String >::const_iterator aIt( aSybolSetNames.begin() );
1384     for ( ; aIt != aSybolSetNames.end(); ++aIt)
1385         aSymbolSets.InsertEntry( *aIt );
1386 }
1387 
1388 
IMPL_LINK(SmSymbolDialog,SymbolSetChangeHdl,ListBox *,EMPTYARG pListBox)1389 IMPL_LINK( SmSymbolDialog, SymbolSetChangeHdl, ListBox *, EMPTYARG pListBox )
1390 {
1391     (void) pListBox;
1392 #if OSL_DEBUG_LEVEL > 1
1393 	DBG_ASSERT(pListBox == &aSymbolSets, "Sm : falsches Argument");
1394 #endif
1395 
1396 	SelectSymbolSet(aSymbolSets.GetSelectEntry());
1397 	return 0;
1398 }
1399 
1400 
IMPL_LINK(SmSymbolDialog,SymbolChangeHdl,SmShowSymbolSet *,EMPTYARG pShowSymbolSet)1401 IMPL_LINK( SmSymbolDialog, SymbolChangeHdl, SmShowSymbolSet *, EMPTYARG pShowSymbolSet )
1402 {
1403     (void) pShowSymbolSet;
1404 #if OSL_DEBUG_LEVEL > 1
1405 	DBG_ASSERT(pShowSymbolSet == &aSymbolSetDisplay, "Sm : falsches Argument");
1406 #endif
1407 
1408 	SelectSymbol(aSymbolSetDisplay.GetSelectSymbol());
1409 	return 0;
1410 }
1411 
IMPL_LINK(SmSymbolDialog,EditClickHdl,Button *,EMPTYARG pButton)1412 IMPL_LINK( SmSymbolDialog, EditClickHdl, Button *, EMPTYARG pButton )
1413 {
1414     (void) pButton;
1415 #if OSL_DEBUG_LEVEL > 1
1416 	DBG_ASSERT(pButton == &aEditBtn, "Sm : falsches Argument");
1417 #endif
1418 
1419     SmSymDefineDialog *pDialog = new SmSymDefineDialog(this, pFontListDev, rSymbolMgr);
1420 
1421 	// aktuelles Symbol und SymbolSet am neuen Dialog setzen
1422 	const XubString  aSymSetName (aSymbolSets.GetSelectEntry()),
1423 					aSymName    (aSymbolName.GetText());
1424 	pDialog->SelectOldSymbolSet(aSymSetName);
1425 	pDialog->SelectOldSymbol(aSymName);
1426 	pDialog->SelectSymbolSet(aSymSetName);
1427 	pDialog->SelectSymbol(aSymName);
1428 
1429 	// altes SymbolSet merken
1430 	XubString  aOldSymbolSet (aSymbolSets.GetSelectEntry());
1431 
1432     sal_uInt16 nSymPos = GetSelectedSymbol();
1433 
1434     // Dialog an evtl geaenderte Daten des SymbolSet Manager anpassen
1435     if (pDialog->Execute() == RET_OK  &&  rSymbolMgr.IsModified())
1436 	{
1437         rSymbolMgr.Save();
1438 		FillSymbolSets();
1439 	}
1440 
1441 	// wenn das alte SymbolSet nicht mehr existiert zum ersten gehen
1442 	// (soweit eines vorhanden ist)
1443 	if (!SelectSymbolSet(aOldSymbolSet)  &&  aSymbolSets.GetEntryCount() > 0)
1444 		SelectSymbolSet(aSymbolSets.GetEntry(0));
1445     else
1446     {
1447         // just update display of current symbol set
1448         DBG_ASSERT( aSymSetName == aSymSetName, "unexpected change in symbol set name" );
1449        	aSymbolSet      = rSymbolMgr.GetSymbolSet( aSymbolSetName );
1450         aSymbolSetDisplay.SetSymbolSet( aSymbolSet );
1451     }
1452 
1453     if (nSymPos >= aSymbolSet.size())
1454         nSymPos = static_cast< sal_uInt16 >(aSymbolSet.size()) - 1;
1455     SelectSymbol( nSymPos );
1456 
1457 	delete pDialog;
1458 	return 0;
1459 }
1460 
1461 
IMPL_LINK(SmSymbolDialog,SymbolDblClickHdl,SmShowSymbolSet *,EMPTYARG pShowSymbolSet)1462 IMPL_LINK( SmSymbolDialog, SymbolDblClickHdl, SmShowSymbolSet *, EMPTYARG pShowSymbolSet )
1463 {
1464     (void) pShowSymbolSet;
1465 #if OSL_DEBUG_LEVEL > 1
1466 	DBG_ASSERT(pShowSymbolSet == &aSymbolSetDisplay, "Sm : falsches Argument");
1467 #endif
1468 
1469 	GetClickHdl(&aGetBtn);
1470 	EndDialog(RET_OK);
1471 	return 0;
1472 }
1473 
1474 
IMPL_LINK(SmSymbolDialog,GetClickHdl,Button *,EMPTYARG pButton)1475 IMPL_LINK( SmSymbolDialog, GetClickHdl, Button *, EMPTYARG pButton )
1476 {
1477     (void) pButton;
1478 #if OSL_DEBUG_LEVEL > 1
1479 	DBG_ASSERT(pButton == &aGetBtn, "Sm : falscher Button");
1480 #endif
1481 
1482 	const SmSym *pSym = GetSymbol();
1483 	if (pSym)
1484 	{
1485 		String	aText ('%');
1486 		aText += pSym->GetName();
1487 		aText += (sal_Unicode)' ';
1488 
1489         rViewSh.GetViewFrame()->GetDispatcher()->Execute(
1490                 SID_INSERTTEXT, SFX_CALLMODE_STANDARD,
1491                 new SfxStringItem(SID_INSERTTEXT, aText), 0L);
1492 	}
1493 
1494 	return 0;
1495 }
1496 
1497 
IMPL_LINK_INLINE_START(SmSymbolDialog,CloseClickHdl,Button *,EMPTYARG pButton)1498 IMPL_LINK_INLINE_START( SmSymbolDialog, CloseClickHdl, Button *, EMPTYARG pButton )
1499 {
1500     (void) pButton;
1501 #if OSL_DEBUG_LEVEL > 1
1502 	DBG_ASSERT(pButton == &aCloseBtn, "Sm : falscher Button");
1503 #endif
1504 
1505 	EndDialog(sal_True);
1506 	return 0;
1507 }
IMPL_LINK_INLINE_END(SmSymbolDialog,CloseClickHdl,Button *,pButton)1508 IMPL_LINK_INLINE_END( SmSymbolDialog, CloseClickHdl, Button *, pButton )
1509 
1510 
1511 SmSymbolDialog::SmSymbolDialog(Window *pParent, OutputDevice *pFntListDevice,
1512         SmSymbolManager &rMgr, SmViewShell &rViewShell, sal_Bool bFreeRes) :
1513 	ModalDialog			(pParent, SmResId(RID_SYMBOLDIALOG)),
1514     aSymbolSetText      (this, SmResId(1)),
1515     aSymbolSets         (this, SmResId(1)),
1516     aSymbolSetDisplay   (this, SmResId(1)),
1517     aSymbolName         (this, SmResId(2)),
1518     aSymbolDisplay      (this, SmResId(2)),
1519     aGetBtn             (this, SmResId(2)),
1520     aCloseBtn           (this, SmResId(3)),
1521     aEditBtn            (this, SmResId(1)),
1522     rViewSh             (rViewShell),
1523     rSymbolMgr          (rMgr),
1524     pFontListDev        (pFntListDevice)
1525 {
1526 	if (bFreeRes)
1527 		FreeResource();
1528 
1529     aSymbolSetName = String();
1530     aSymbolSet.clear();
1531 	FillSymbolSets();
1532 	if (aSymbolSets.GetEntryCount() > 0)
1533 		SelectSymbolSet(aSymbolSets.GetEntry(0));
1534 
1535     InitColor_Impl();
1536 
1537     // preview like controls should have a 2D look
1538     aSymbolDisplay.SetBorderStyle( WINDOW_BORDER_MONO );
1539 
1540 	aSymbolSets		 .SetSelectHdl	(LINK(this, SmSymbolDialog, SymbolSetChangeHdl));
1541 	aSymbolSetDisplay.SetSelectHdl  (LINK(this, SmSymbolDialog, SymbolChangeHdl));
1542 	aSymbolSetDisplay.SetDblClickHdl(LINK(this, SmSymbolDialog, SymbolDblClickHdl));
1543 	aSymbolDisplay	 .SetDblClickHdl(LINK(this, SmSymbolDialog, SymbolDblClickHdl));
1544 	aCloseBtn		 .SetClickHdl   (LINK(this, SmSymbolDialog, CloseClickHdl));
1545 	aEditBtn		 .SetClickHdl   (LINK(this, SmSymbolDialog, EditClickHdl));
1546 	aGetBtn			 .SetClickHdl   (LINK(this, SmSymbolDialog, GetClickHdl));
1547 }
1548 
1549 
~SmSymbolDialog()1550 SmSymbolDialog::~SmSymbolDialog()
1551 {
1552 }
1553 
1554 
InitColor_Impl()1555 void SmSymbolDialog::InitColor_Impl()
1556 {
1557 #if OSL_DEBUG_LEVEL > 1
1558     Color aBC( GetDisplayBackground().GetColor() );
1559 #endif
1560     ColorData   nBgCol  = COL_WHITE,
1561                 nTxtCol = COL_BLACK;
1562     const StyleSettings &rS = GetSettings().GetStyleSettings();
1563     if (rS.GetHighContrastMode())
1564     {
1565         nBgCol  = rS.GetFieldColor().GetColor();
1566         nTxtCol = rS.GetFieldTextColor().GetColor();
1567     }
1568 
1569     Color aTmpColor( nBgCol );
1570     Wallpaper aWall( aTmpColor );
1571     Color aTxtColor( nTxtCol );
1572     aSymbolDisplay   .SetBackground( aWall );
1573     aSymbolDisplay   .SetTextColor( aTxtColor );
1574     aSymbolSetDisplay.SetBackground( aWall );
1575     aSymbolSetDisplay.SetTextColor( aTxtColor );
1576 }
1577 
1578 
DataChanged(const DataChangedEvent & rDCEvt)1579 void SmSymbolDialog::DataChanged( const DataChangedEvent& rDCEvt )
1580 {
1581     if ( rDCEvt.GetType() == DATACHANGED_SETTINGS  &&
1582          (rDCEvt.GetFlags() & SETTINGS_STYLE) )
1583             InitColor_Impl();
1584 
1585     ModalDialog::DataChanged( rDCEvt );
1586 }
1587 
1588 
SelectSymbolSet(const XubString & rSymbolSetName)1589 sal_Bool SmSymbolDialog::SelectSymbolSet(const XubString &rSymbolSetName)
1590 {
1591 	sal_Bool	bRet = sal_False;
1592 	sal_uInt16 	nPos = aSymbolSets.GetEntryPos(rSymbolSetName);
1593 
1594     aSymbolSetName = String();
1595     aSymbolSet.clear();
1596 	if (nPos != LISTBOX_ENTRY_NOTFOUND)
1597 	{
1598 		aSymbolSets.SelectEntryPos(nPos);
1599 
1600         aSymbolSetName  = rSymbolSetName;
1601         aSymbolSet      = rSymbolMgr.GetSymbolSet( aSymbolSetName );
1602 
1603         // sort symbols by Unicode position (useful for displaying Greek characters alphabetically)
1604         std::sort( aSymbolSet.begin(), aSymbolSet.end(), lt_SmSymPtr() );
1605 
1606         aSymbolSetDisplay.SetSymbolSet( aSymbolSet );
1607         if (aSymbolSet.size() > 0)
1608 			SelectSymbol(0);
1609 
1610 		bRet = sal_True;
1611 	}
1612 	else
1613 		aSymbolSets.SetNoSelection();
1614 
1615 	return bRet;
1616 }
1617 
1618 
SelectSymbol(sal_uInt16 nSymbolNo)1619 void SmSymbolDialog::SelectSymbol(sal_uInt16 nSymbolNo)
1620 {
1621 	const SmSym *pSym = NULL;
1622     if (aSymbolSetName.Len() > 0  &&  nSymbolNo < static_cast< sal_uInt16 >(aSymbolSet.size()))
1623         pSym = aSymbolSet[ nSymbolNo ];
1624 
1625 	aSymbolSetDisplay.SelectSymbol(nSymbolNo);
1626 	aSymbolDisplay.SetSymbol(pSym);
1627 	aSymbolName.SetText(pSym ? pSym->GetName() : XubString());
1628 }
1629 
1630 
GetSymbol() const1631 const SmSym * SmSymbolDialog::GetSymbol() const
1632 {
1633 	sal_uInt16 nSymbolNo = aSymbolSetDisplay.GetSelectSymbol();
1634     bool bValid = aSymbolSetName.Len() > 0  &&  nSymbolNo < static_cast< sal_uInt16 >(aSymbolSet.size());
1635     return bValid ? aSymbolSet[ nSymbolNo ] : NULL;
1636 }
1637 
1638 
1639 ////////////////////////////////////////////////////////////////////////////////
1640 
1641 
Paint(const Rectangle & rRect)1642 void SmShowChar::Paint(const Rectangle &rRect)
1643 {
1644     Control::Paint( rRect );
1645 
1646 	OUString aText( GetText() );
1647     if (aText.getLength() > 0)
1648 	{
1649 #if OSL_DEBUG_LEVEL > 1
1650         sal_Int32 nPos = 0;
1651         sal_UCS4 cChar = aText.iterateCodePoints( &nPos );
1652         (void) cChar;
1653 #endif
1654 		Size aTextSize(GetTextWidth(aText), GetTextHeight());
1655 
1656 		DrawText(Point((GetOutputSize().Width()  - aTextSize.Width())  / 2,
1657 					   (GetOutputSize().Height() * 7/10)), aText);
1658 	}
1659 }
1660 
1661 
SetSymbol(const SmSym * pSym)1662 void SmShowChar::SetSymbol( const SmSym *pSym )
1663 {
1664     if (pSym)
1665         SetSymbol( pSym->GetCharacter(), pSym->GetFace() );
1666 }
1667 
1668 
SetSymbol(sal_UCS4 cChar,const Font & rFont)1669 void SmShowChar::SetSymbol( sal_UCS4 cChar, const Font &rFont )
1670 {
1671     Font aFont( rFont );
1672     aFont.SetSize( Size(0, GetOutputSize().Height() - GetOutputSize().Height() / 3) );
1673     aFont.SetAlign(ALIGN_BASELINE);
1674     SetFont(aFont);
1675 
1676     String aText( OUString( &cChar, 1) );
1677     SetText( aText );
1678 
1679     Invalidate();
1680 }
1681 
1682 
1683 ////////////////////////////////////////////////////////////////////////////////
1684 
FillSymbols(ComboBox & rComboBox,sal_Bool bDeleteText)1685 void SmSymDefineDialog::FillSymbols(ComboBox &rComboBox, sal_Bool bDeleteText)
1686 {
1687 #if OSL_DEBUG_LEVEL > 1
1688 	DBG_ASSERT(&rComboBox == &aOldSymbols  ||  &rComboBox == &aSymbols,
1689 		"Sm : falsche ComboBox");
1690 #endif
1691 
1692 	rComboBox.Clear();
1693 	if (bDeleteText)
1694 		rComboBox.SetText(XubString());
1695 
1696     ComboBox &rBox = &rComboBox == &aOldSymbols ? aOldSymbolSets : aSymbolSets;
1697     SymbolPtrVec_t aSymSet( aSymbolMgrCopy.GetSymbolSet( rBox.GetText() ) );
1698     for (size_t i = 0;  i < aSymSet.size();  ++i)
1699         rComboBox.InsertEntry( aSymSet[i]->GetName() );
1700 }
1701 
1702 
FillSymbolSets(ComboBox & rComboBox,sal_Bool bDeleteText)1703 void SmSymDefineDialog::FillSymbolSets(ComboBox &rComboBox, sal_Bool bDeleteText)
1704 {
1705 #if OSL_DEBUG_LEVEL > 1
1706 	DBG_ASSERT(&rComboBox == &aOldSymbolSets  ||  &rComboBox == &aSymbolSets,
1707 		"Sm : falsche ComboBox");
1708 #endif
1709 
1710 	rComboBox.Clear();
1711 	if (bDeleteText)
1712 		rComboBox.SetText(XubString());
1713 
1714     const std::set< String >  aSymbolSetNames( aSymbolMgrCopy.GetSymbolSetNames() );
1715     std::set< String >::const_iterator aIt( aSymbolSetNames.begin() );
1716     for ( ;  aIt != aSymbolSetNames.end();  ++aIt)
1717         rComboBox.InsertEntry( *aIt );
1718 }
1719 
1720 
FillFonts(sal_Bool bDelete)1721 void SmSymDefineDialog::FillFonts(sal_Bool bDelete)
1722 {
1723 	aFonts.Clear();
1724 	if (bDelete)
1725 		aFonts.SetNoSelection();
1726 
1727 	// alle Fonts der 'FontList' in die Fontliste aufnehmen
1728 	// von denen mit gleichen Namen jedoch nur einen (denn der Style wird
1729     // ueber die 'FontStyleBox' gewaehlt und nicht auch noch hier)
1730     if (pFontList)
1731     {
1732         sal_uInt16  nCount = pFontList->GetFontNameCount();
1733         for (sal_uInt16 i = 0;  i < nCount;  i++)
1734             aFonts.InsertEntry( pFontList->GetFontName(i).GetName() );
1735     }
1736 }
1737 
1738 
FillStyles(sal_Bool bDeleteText)1739 void SmSymDefineDialog::FillStyles(sal_Bool bDeleteText)
1740 {
1741 	aStyles.Clear();
1742 	if (bDeleteText)
1743 		aStyles.SetText(XubString());
1744 
1745 	XubString aText (aFonts.GetSelectEntry());
1746 	if (aText.Len() != 0)
1747 	{
1748 		//aStyles.Fill(aText, &aFontList);
1749 		// eigene StyleName's verwenden
1750         const SmFontStyles &rStyles = GetFontStyles();
1751         for (sal_uInt16 i = 0;  i < rStyles.GetCount();  i++)
1752             aStyles.InsertEntry( rStyles.GetStyleName(i) );
1753 
1754 #if OSL_DEBUG_LEVEL > 1
1755 		DBG_ASSERT(aStyles.GetEntryCount() > 0, "Sm : keine Styles vorhanden");
1756 #endif
1757         aStyles.SetText( aStyles.GetEntry(0) );
1758 	}
1759 }
1760 
1761 
GetSymbol(const ComboBox & rComboBox)1762 SmSym * SmSymDefineDialog::GetSymbol(const ComboBox &rComboBox)
1763 {
1764 #if OSL_DEBUG_LEVEL > 1
1765 	DBG_ASSERT(&rComboBox == &aOldSymbols  ||  &rComboBox == &aSymbols,
1766 		"Sm : falsche ComboBox");
1767 #endif
1768     return aSymbolMgrCopy.GetSymbolByName(rComboBox.GetText());
1769 }
1770 
1771 
IMPL_LINK(SmSymDefineDialog,OldSymbolChangeHdl,ComboBox *,EMPTYARG pComboBox)1772 IMPL_LINK( SmSymDefineDialog, OldSymbolChangeHdl, ComboBox *, EMPTYARG pComboBox )
1773 {
1774     (void) pComboBox;
1775 #if OSL_DEBUG_LEVEL > 1
1776 	DBG_ASSERT(pComboBox == &aOldSymbols, "Sm : falsches Argument");
1777 #endif
1778     SelectSymbol(aOldSymbols, aOldSymbols.GetText(), sal_False);
1779 	return 0;
1780 }
1781 
1782 
IMPL_LINK(SmSymDefineDialog,OldSymbolSetChangeHdl,ComboBox *,EMPTYARG pComboBox)1783 IMPL_LINK( SmSymDefineDialog, OldSymbolSetChangeHdl, ComboBox *, EMPTYARG pComboBox )
1784 {
1785     (void) pComboBox;
1786 #if OSL_DEBUG_LEVEL > 1
1787 	DBG_ASSERT(pComboBox == &aOldSymbolSets, "Sm : falsches Argument");
1788 #endif
1789 	SelectSymbolSet(aOldSymbolSets, aOldSymbolSets.GetText(), sal_False);
1790 	return 0;
1791 }
1792 
1793 
IMPL_LINK(SmSymDefineDialog,ModifyHdl,ComboBox *,pComboBox)1794 IMPL_LINK( SmSymDefineDialog, ModifyHdl, ComboBox *, pComboBox )
1795 {
1796 	// merken der Cursorposition zum wiederherstellen derselben
1797 	Selection  aSelection (pComboBox->GetSelection());
1798 
1799 	if (pComboBox == &aSymbols)
1800 		SelectSymbol(aSymbols, aSymbols.GetText(), sal_False);
1801 	else if (pComboBox == &aSymbolSets)
1802 		SelectSymbolSet(aSymbolSets, aSymbolSets.GetText(), sal_False);
1803 	else if (pComboBox == &aOldSymbols)
1804 		// nur Namen aus der Liste erlauben
1805 		SelectSymbol(aOldSymbols, aOldSymbols.GetText(), sal_True);
1806 	else if (pComboBox == &aOldSymbolSets)
1807 		// nur Namen aus der Liste erlauben
1808 		SelectSymbolSet(aOldSymbolSets, aOldSymbolSets.GetText(), sal_True);
1809 	else if (pComboBox == &aStyles)
1810 		// nur Namen aus der Liste erlauben (ist hier eh immer der Fall)
1811 		SelectStyle(aStyles.GetText(), sal_True);
1812 	else
1813     {
1814 #if OSL_DEBUG_LEVEL > 1
1815 		DBG_ASSERT(0, "Sm : falsche ComboBox Argument");
1816 #endif
1817     }
1818 
1819 	pComboBox->SetSelection(aSelection);
1820 
1821 	UpdateButtons();
1822 
1823 	return 0;
1824 }
1825 
1826 
IMPL_LINK(SmSymDefineDialog,FontChangeHdl,ListBox *,EMPTYARG pListBox)1827 IMPL_LINK( SmSymDefineDialog, FontChangeHdl, ListBox *, EMPTYARG pListBox )
1828 {
1829     (void) pListBox;
1830 #if OSL_DEBUG_LEVEL > 1
1831 	DBG_ASSERT(pListBox == &aFonts, "Sm : falsches Argument");
1832 #endif
1833 
1834 	SelectFont(aFonts.GetSelectEntry());
1835 	return 0;
1836 }
1837 
1838 
IMPL_LINK(SmSymDefineDialog,SubsetChangeHdl,ListBox *,EMPTYARG pListBox)1839 IMPL_LINK( SmSymDefineDialog, SubsetChangeHdl, ListBox *, EMPTYARG pListBox )
1840 {
1841     (void) pListBox;
1842     sal_uInt16 nPos = aFontsSubsetLB.GetSelectEntryPos();
1843     if (LISTBOX_ENTRY_NOTFOUND != nPos)
1844     {
1845         const Subset* pSubset = reinterpret_cast<const Subset*> (aFontsSubsetLB.GetEntryData( nPos ));
1846         if (pSubset)
1847         {
1848             aCharsetDisplay.SelectCharacter( pSubset->GetRangeMin() );
1849         }
1850     }
1851     return 0;
1852 }
1853 
1854 
IMPL_LINK(SmSymDefineDialog,StyleChangeHdl,ComboBox *,EMPTYARG pComboBox)1855 IMPL_LINK( SmSymDefineDialog, StyleChangeHdl, ComboBox *, EMPTYARG pComboBox )
1856 {
1857     (void) pComboBox;
1858 #if OSL_DEBUG_LEVEL > 1
1859 	DBG_ASSERT(pComboBox == &aStyles, "Sm : falsches Argument");
1860 #endif
1861 
1862 	SelectStyle(aStyles.GetText());
1863 	return 0;
1864 }
1865 
1866 
IMPL_LINK(SmSymDefineDialog,CharHighlightHdl,Control *,EMPTYARG)1867 IMPL_LINK( SmSymDefineDialog, CharHighlightHdl, Control *, EMPTYARG )
1868 {
1869    sal_UCS4 cChar = aCharsetDisplay.GetSelectCharacter();
1870 
1871 #if OSL_DEBUG_LEVEL > 1
1872     DBG_ASSERT( pSubsetMap, "SubsetMap missing" );
1873 #endif
1874     if (pSubsetMap)
1875     {
1876         const Subset* pSubset = pSubsetMap->GetSubsetByUnicode( cChar );
1877         if (pSubset)
1878             aFontsSubsetLB.SelectEntry( pSubset->GetName() );
1879         else
1880             aFontsSubsetLB.SetNoSelection();
1881     }
1882 
1883     aSymbolDisplay.SetSymbol( cChar, aCharsetDisplay.GetFont() );
1884 
1885 	UpdateButtons();
1886 
1887     // display Unicode position as symbol name while iterating over characters
1888     const String aHex( String::CreateFromInt64( cChar, 16 ).ToUpperAscii() );
1889     const String aPattern( A2OU( aHex.Len() > 4 ? "Ux000000" : "Ux0000" ) );
1890     String aUnicodePos( aPattern.Copy( 0, aPattern.Len() - aHex.Len() ) );
1891     aUnicodePos += aHex;
1892     aSymbols.SetText( aUnicodePos );
1893     aSymbolName.SetText( aUnicodePos );
1894 
1895 	return 0;
1896 }
1897 
1898 
IMPL_LINK(SmSymDefineDialog,AddClickHdl,Button *,EMPTYARG pButton)1899 IMPL_LINK( SmSymDefineDialog, AddClickHdl, Button *, EMPTYARG pButton )
1900 {
1901     (void) pButton;
1902 #if OSL_DEBUG_LEVEL > 1
1903 	DBG_ASSERT(pButton == &aAddBtn, "Sm : falsches Argument");
1904     DBG_ASSERT(aAddBtn.IsEnabled(), "Sm : Voraussetzungen erfuellt ??");
1905 #endif
1906 
1907     // add symbol
1908     const SmSym aNewSymbol( aSymbols.GetText(), aCharsetDisplay.GetFont(),
1909             aCharsetDisplay.GetSelectCharacter(), aSymbolSets.GetText() );
1910     //DBG_ASSERT( aSymbolMgrCopy.GetSymbolByName(aTmpSymbolName) == NULL, "symbol already exists" );
1911     aSymbolMgrCopy.AddOrReplaceSymbol( aNewSymbol );
1912 
1913     // update display of new symbol
1914     aSymbolDisplay.SetSymbol( &aNewSymbol );
1915     aSymbolName.SetText( aNewSymbol.GetName() );
1916     aSymbolSetName.SetText( aNewSymbol.GetSymbolSetName() );
1917 
1918     // update list box entries
1919     FillSymbolSets(aOldSymbolSets, sal_False);
1920     FillSymbolSets(aSymbolSets,    sal_False);
1921 	FillSymbols(aOldSymbols ,sal_False);
1922 	FillSymbols(aSymbols    ,sal_False);
1923 
1924 	UpdateButtons();
1925 
1926 	return 0;
1927 }
1928 
1929 
IMPL_LINK(SmSymDefineDialog,ChangeClickHdl,Button *,EMPTYARG pButton)1930 IMPL_LINK( SmSymDefineDialog, ChangeClickHdl, Button *, EMPTYARG pButton )
1931 {
1932     (void) pButton;
1933 #if OSL_DEBUG_LEVEL > 1
1934 	DBG_ASSERT(pButton == &aChangeBtn, "Sm : falsches Argument");
1935     DBG_ASSERT(aChangeBtn.IsEnabled(), "Sm : Voraussetzungen erfuellt ??");
1936 #endif
1937 
1938     // get new Sybol to use
1939     //! get font from symbol-disp lay since charset-display does not keep
1940     //! the bold attribut.
1941     const SmSym aNewSymbol( aSymbols.GetText(), aCharsetDisplay.GetFont(),
1942             aCharsetDisplay.GetSelectCharacter(), aSymbolSets.GetText() );
1943 
1944     // remove old symbol if the name was changed then add new one
1945 //    const bool bSetNameChanged    = aOldSymbolSets.GetText() != aSymbolSets.GetText();
1946     const bool bNameChanged       = aOldSymbols.GetText() != aSymbols.GetText();
1947     if (bNameChanged)
1948         aSymbolMgrCopy.RemoveSymbol( aOldSymbols.GetText() );
1949     aSymbolMgrCopy.AddOrReplaceSymbol( aNewSymbol, true );
1950 
1951     // clear display for original symbol if necessary
1952     if (bNameChanged)
1953         SetOrigSymbol(NULL, XubString());
1954 
1955     // update display of new symbol
1956     aSymbolDisplay.SetSymbol( &aNewSymbol );
1957     aSymbolName.SetText( aNewSymbol.GetName() );
1958     aSymbolSetName.SetText( aNewSymbol.GetSymbolSetName() );
1959 
1960     // update list box entries
1961     FillSymbolSets(aOldSymbolSets, sal_False);
1962     FillSymbolSets(aSymbolSets,    sal_False);
1963     FillSymbols(aOldSymbols ,sal_False);
1964     FillSymbols(aSymbols    ,sal_False);
1965 
1966     UpdateButtons();
1967 
1968 	return 0;
1969 }
1970 
1971 
IMPL_LINK(SmSymDefineDialog,DeleteClickHdl,Button *,EMPTYARG pButton)1972 IMPL_LINK( SmSymDefineDialog, DeleteClickHdl, Button *, EMPTYARG pButton )
1973 {
1974     (void) pButton;
1975 #if OSL_DEBUG_LEVEL > 1
1976 	DBG_ASSERT(pButton == &aDeleteBtn, "Sm : falsches Argument");
1977     DBG_ASSERT(aDeleteBtn.IsEnabled(), "Sm : Voraussetzungen erfuellt ??");
1978 #endif
1979 
1980 	if (pOrigSymbol)
1981 	{
1982         aSymbolMgrCopy.RemoveSymbol( pOrigSymbol->GetName() );
1983 
1984         // clear display for original symbol
1985 		SetOrigSymbol(NULL, XubString());
1986 
1987         // update list box entries
1988         FillSymbolSets(aOldSymbolSets, sal_False);
1989         FillSymbolSets(aSymbolSets,    sal_False);
1990         FillSymbols(aOldSymbols ,sal_False);
1991         FillSymbols(aSymbols    ,sal_False);
1992 	}
1993 
1994 	UpdateButtons();
1995 
1996 	return 0;
1997 }
1998 
1999 
UpdateButtons()2000 void SmSymDefineDialog::UpdateButtons()
2001 {
2002 	sal_Bool  bAdd    = sal_False,
2003 		  bChange = sal_False,
2004 		  bDelete = sal_False,
2005 		  bEqual;
2006     XubString aTmpSymbolName    (aSymbols.GetText()),
2007               aTmpSymbolSetName (aSymbolSets.GetText());
2008 
2009     if (aTmpSymbolName.Len() > 0  &&  aTmpSymbolSetName.Len() > 0)
2010 	{
2011 		// alle Einstellungen gleich?
2012 		//! (Font-, Style- und SymbolSet Name werden nicht case sensitiv verglichen)
2013 		bEqual = pOrigSymbol
2014                     && aTmpSymbolSetName.EqualsIgnoreCaseAscii(aOldSymbolSetName.GetText())
2015                     && aTmpSymbolName.Equals(pOrigSymbol->GetName())
2016                     && aFonts.GetSelectEntry().EqualsIgnoreCaseAscii(
2017                             pOrigSymbol->GetFace().GetName())
2018                     && aStyles.GetText().EqualsIgnoreCaseAscii(
2019                             GetFontStyles().GetStyleName(pOrigSymbol->GetFace()))
2020                     && aCharsetDisplay.GetSelectCharacter() == pOrigSymbol->GetCharacter();
2021 
2022         // hinzufuegen nur wenn es noch kein Symbol desgleichen Namens gibt
2023         bAdd    = aSymbolMgrCopy.GetSymbolByName(aTmpSymbolName) == NULL;
2024 
2025         // loeschen nur wenn alle Einstellungen gleich sind
2026 		bDelete = pOrigSymbol != NULL;
2027 
2028         // aendern wenn bei gleichem Namen mindestens eine Einstellung anders ist
2029         // oder wenn es noch kein Symbol des neuen Namens gibt (wuerde implizites
2030         // loeschen des bereits vorhandenen Symbols erfordern)
2031 //        sal_Bool  bEqualName = pOrigSymbol && aTmpSymbolName == pOrigSymbol->GetName();
2032 //		bChange = pOrigSymbol && ( (bEqualName && !bEqual) || (!bEqualName && bAdd) );
2033 
2034         // aendern nur falls altes Symbol vorhanden und am neuen etwas anders ist
2035 		bChange = pOrigSymbol && !bEqual;
2036 }
2037 
2038 	aAddBtn   .Enable(bAdd);
2039 	aChangeBtn.Enable(bChange);
2040 	aDeleteBtn.Enable(bDelete);
2041 }
2042 
2043 
SmSymDefineDialog(Window * pParent,OutputDevice * pFntListDevice,SmSymbolManager & rMgr,sal_Bool bFreeRes)2044 SmSymDefineDialog::SmSymDefineDialog(Window * pParent,
2045         OutputDevice *pFntListDevice, SmSymbolManager &rMgr, sal_Bool bFreeRes) :
2046 	ModalDialog			(pParent, SmResId(RID_SYMDEFINEDIALOG)),
2047     aOldSymbolText      (this, SmResId(1)),
2048     aOldSymbols         (this, SmResId(1)),
2049     aOldSymbolSetText   (this, SmResId(2)),
2050     aOldSymbolSets      (this, SmResId(2)),
2051     aCharsetDisplay     (this, SmResId(1)),
2052     aSymbolText         (this, SmResId(9)),
2053     aSymbols            (this, SmResId(4)),
2054     aSymbolSetText      (this, SmResId(10)),
2055     aSymbolSets         (this, SmResId(5)),
2056     aFontText           (this, SmResId(3)),
2057     aFonts              (this, SmResId(1)),
2058     aFontsSubsetFT      (this, SmResId( FT_FONTS_SUBSET )),
2059     aFontsSubsetLB      (this, SmResId( LB_FONTS_SUBSET )),
2060     aStyleText          (this, SmResId(4)),
2061     aStyles             (this, SmResId(3)),
2062     aOldSymbolName      (this, SmResId(7)),
2063     aOldSymbolDisplay   (this, SmResId(3)),
2064     aOldSymbolSetName   (this, SmResId(8)),
2065     aSymbolName         (this, SmResId(5)),
2066     aSymbolDisplay      (this, SmResId(2)),
2067     aSymbolSetName      (this, SmResId(6)),
2068     aOkBtn              (this, SmResId(1)),
2069     aCancelBtn          (this, SmResId(1)),
2070     aAddBtn             (this, SmResId(1)),
2071     aChangeBtn          (this, SmResId(2)),
2072     aDeleteBtn          (this, SmResId(3)),
2073     aRightArrow         (this, SmResId(1)),
2074     aRigthArrow_Im      (SmResId(1)),
2075     aRigthArrow_Im_HC   (SmResId(2)),   // hi-contrast version
2076     rSymbolMgr          (rMgr),
2077     pSubsetMap          (NULL),
2078     pFontList           (NULL)
2079 {
2080 	if (bFreeRes)
2081 		FreeResource();
2082 
2083     pFontList = new FontList( pFntListDevice );
2084 
2085 	pOrigSymbol = 0;
2086 
2087     // auto completion is troublesome since that symbols character also gets automatically selected in the
2088     // display and if the user previously selected a character to define/redefine that one this is bad
2089     aOldSymbols.EnableAutocomplete( sal_False, sal_True );
2090     aSymbols   .EnableAutocomplete( sal_False, sal_True );
2091 
2092 	FillFonts();
2093 	if (aFonts.GetEntryCount() > 0)
2094 		SelectFont(aFonts.GetEntry(0));
2095 
2096     InitColor_Impl();
2097 
2098     SetSymbolSetManager(rSymbolMgr);
2099 
2100 	aOldSymbols	   .SetSelectHdl(LINK(this, SmSymDefineDialog, OldSymbolChangeHdl));
2101 	aOldSymbolSets .SetSelectHdl(LINK(this, SmSymDefineDialog, OldSymbolSetChangeHdl));
2102 	aSymbolSets    .SetModifyHdl(LINK(this, SmSymDefineDialog, ModifyHdl));
2103 	aOldSymbolSets .SetModifyHdl(LINK(this, SmSymDefineDialog, ModifyHdl));
2104 	aSymbols       .SetModifyHdl(LINK(this, SmSymDefineDialog, ModifyHdl));
2105 	aOldSymbols    .SetModifyHdl(LINK(this, SmSymDefineDialog, ModifyHdl));
2106 	aStyles		   .SetModifyHdl(LINK(this, SmSymDefineDialog, ModifyHdl));
2107 	aFonts         .SetSelectHdl(LINK(this, SmSymDefineDialog, FontChangeHdl));
2108     aFontsSubsetLB .SetSelectHdl(LINK(this, SmSymDefineDialog, SubsetChangeHdl));
2109 	aStyles        .SetSelectHdl(LINK(this, SmSymDefineDialog, StyleChangeHdl));
2110 	aAddBtn        .SetClickHdl (LINK(this, SmSymDefineDialog, AddClickHdl));
2111 	aChangeBtn     .SetClickHdl (LINK(this, SmSymDefineDialog, ChangeClickHdl));
2112 	aDeleteBtn     .SetClickHdl (LINK(this, SmSymDefineDialog, DeleteClickHdl));
2113     aCharsetDisplay.SetHighlightHdl( LINK( this, SmSymDefineDialog, CharHighlightHdl ) );
2114 
2115     // preview like controls should have a 2D look
2116     aOldSymbolDisplay.SetBorderStyle( WINDOW_BORDER_MONO );
2117     aSymbolDisplay   .SetBorderStyle( WINDOW_BORDER_MONO );
2118 }
2119 
2120 
~SmSymDefineDialog()2121 SmSymDefineDialog::~SmSymDefineDialog()
2122 {
2123     delete pSubsetMap;
2124     delete pOrigSymbol;
2125 }
2126 
InitColor_Impl()2127 void SmSymDefineDialog::InitColor_Impl()
2128 {
2129 #if OSL_DEBUG_LEVEL > 1
2130     Color aBC( GetDisplayBackground().GetColor() );
2131 #endif
2132     ColorData   nBgCol  = COL_WHITE,
2133                 nTxtCol = COL_BLACK;
2134     sal_Bool bHighContrast = GetSettings().GetStyleSettings().GetHighContrastMode();
2135     if (bHighContrast)
2136     {
2137         const StyleSettings &rS = GetSettings().GetStyleSettings();
2138         nBgCol  = rS.GetFieldColor().GetColor();
2139         nTxtCol = rS.GetFieldTextColor().GetColor();
2140     }
2141 
2142     Color aTmpColor( nBgCol );
2143     Wallpaper aWall( aTmpColor );
2144     Color aTxtColor( nTxtCol );
2145     aCharsetDisplay  .SetBackground( aWall );
2146     aCharsetDisplay  .SetTextColor( aTxtColor );
2147     aOldSymbolDisplay.SetBackground( aWall );
2148     aOldSymbolDisplay.SetTextColor( aTxtColor );
2149     aSymbolDisplay   .SetBackground( aWall );
2150     aSymbolDisplay   .SetTextColor( aTxtColor );
2151 
2152     const Image &rArrowRight = bHighContrast ? aRigthArrow_Im_HC : aRigthArrow_Im;
2153     aRightArrow.SetImage( rArrowRight );
2154 }
2155 
2156 
DataChanged(const DataChangedEvent & rDCEvt)2157 void SmSymDefineDialog::DataChanged( const DataChangedEvent& rDCEvt )
2158 {
2159     if ( rDCEvt.GetType() == DATACHANGED_SETTINGS  &&
2160          (rDCEvt.GetFlags() & SETTINGS_STYLE) )
2161             InitColor_Impl();
2162 
2163     ModalDialog::DataChanged( rDCEvt );
2164 }
2165 
2166 
Execute()2167 short SmSymDefineDialog::Execute()
2168 {
2169 	short nResult = ModalDialog::Execute();
2170 
2171     // Aenderungen uebernehmen falls Dialog mit OK beendet wurde
2172     if (aSymbolMgrCopy.IsModified()  &&  nResult == RET_OK)
2173         rSymbolMgr = aSymbolMgrCopy;
2174 
2175 	return nResult;
2176 }
2177 
2178 
SetSymbolSetManager(const SmSymbolManager & rMgr)2179 void SmSymDefineDialog::SetSymbolSetManager(const SmSymbolManager &rMgr)
2180 {
2181     aSymbolMgrCopy = rMgr;
2182 #ifdef DEBUG
2183 //        sal_uInt16 nS = aSymbolMgrCopy.GetSymbolSetCount();
2184 #endif
2185 
2186     // Das modified Flag der Kopie auf sal_False setzen, damit man spaeter damit
2187     // testen kann ob sich was geaendert hat.
2188     aSymbolMgrCopy.SetModified(sal_False);
2189 
2190 	FillSymbolSets(aOldSymbolSets);
2191 	if (aOldSymbolSets.GetEntryCount() > 0)
2192 		SelectSymbolSet(aOldSymbolSets.GetEntry(0));
2193 	FillSymbolSets(aSymbolSets);
2194 	if (aSymbolSets.GetEntryCount() > 0)
2195 		SelectSymbolSet(aSymbolSets.GetEntry(0));
2196 	FillSymbols(aOldSymbols);
2197 	if (aOldSymbols.GetEntryCount() > 0)
2198 		SelectSymbol(aOldSymbols.GetEntry(0));
2199 	FillSymbols(aSymbols);
2200 	if (aSymbols.GetEntryCount() > 0)
2201 		SelectSymbol(aSymbols.GetEntry(0));
2202 
2203 	UpdateButtons();
2204 }
2205 
2206 
SelectSymbolSet(ComboBox & rComboBox,const XubString & rSymbolSetName,sal_Bool bDeleteText)2207 sal_Bool SmSymDefineDialog::SelectSymbolSet(ComboBox &rComboBox,
2208 		const XubString &rSymbolSetName, sal_Bool bDeleteText)
2209 {
2210 #if OSL_DEBUG_LEVEL > 1
2211 	DBG_ASSERT(&rComboBox == &aOldSymbolSets  ||  &rComboBox == &aSymbolSets,
2212 		"Sm : falsche ComboBox");
2213 #endif
2214 
2215 	// 'Normalisieren' des SymbolNamens (ohne leading und trailing Leerzeichen)
2216 	XubString  aNormName (rSymbolSetName);
2217 	aNormName.EraseLeadingChars(' ');
2218 	aNormName.EraseTrailingChars(' ');
2219 	// und evtl Abweichungen in der Eingabe beseitigen
2220 	rComboBox.SetText(aNormName);
2221 
2222 	sal_Bool   bRet = sal_False;
2223 	sal_uInt16 nPos = rComboBox.GetEntryPos(aNormName);
2224 
2225 	if (nPos != COMBOBOX_ENTRY_NOTFOUND)
2226 	{
2227 		rComboBox.SetText(rComboBox.GetEntry(nPos));
2228 		bRet = sal_True;
2229 	}
2230 	else if (bDeleteText)
2231 		rComboBox.SetText(XubString());
2232 
2233 	sal_Bool  bIsOld = &rComboBox == &aOldSymbolSets;
2234 
2235     // setzen des SymbolSet Namens an der zugehoerigen Darstellung
2236 	FixedText &rFT = bIsOld ? aOldSymbolSetName : aSymbolSetName;
2237 	rFT.SetText(rComboBox.GetText());
2238 
2239     // setzen der zum SymbolSet gehoerenden Symbol Namen an der zugehoerigen
2240 	// Auswahbox
2241 	ComboBox  &rCB = bIsOld ? aOldSymbols : aSymbols;
2242 	FillSymbols(rCB, sal_False);
2243 
2244     // bei Wechsel des SymbolSets fuer das alte Zeichen ein gueltiges
2245 	// Symbol bzw keins zur Anzeige bringen
2246 	if (bIsOld)
2247 	{
2248         XubString  aTmpOldSymbolName;
2249 		if (aOldSymbols.GetEntryCount() > 0)
2250             aTmpOldSymbolName = aOldSymbols.GetEntry(0);
2251         SelectSymbol(aOldSymbols, aTmpOldSymbolName, sal_True);
2252 	}
2253 
2254 	UpdateButtons();
2255 
2256 	return bRet;
2257 }
2258 
2259 
SetOrigSymbol(const SmSym * pSymbol,const XubString & rSymbolSetName)2260 void SmSymDefineDialog::SetOrigSymbol(const SmSym *pSymbol,
2261 									  const XubString &rSymbolSetName)
2262 {
2263     // clear old symbol
2264     delete pOrigSymbol;
2265     pOrigSymbol = 0;
2266 
2267     XubString   aSymName,
2268                 aSymSetName;
2269 	if (pSymbol)
2270 	{
2271         // set new symbol
2272         pOrigSymbol = new SmSym( *pSymbol );
2273 
2274 		aSymName    = pSymbol->GetName();
2275 		aSymSetName = rSymbolSetName;
2276 		aOldSymbolDisplay.SetSymbol( pSymbol );
2277 	}
2278 	else
2279     {   // loeschen des angezeigten Symbols
2280 		aOldSymbolDisplay.SetText(XubString());
2281 		aOldSymbolDisplay.Invalidate();
2282 	}
2283 	aOldSymbolName   .SetText(aSymName);
2284 	aOldSymbolSetName.SetText(aSymSetName);
2285 }
2286 
2287 
SelectSymbol(ComboBox & rComboBox,const XubString & rSymbolName,sal_Bool bDeleteText)2288 sal_Bool SmSymDefineDialog::SelectSymbol(ComboBox &rComboBox,
2289 		const XubString &rSymbolName, sal_Bool bDeleteText)
2290 {
2291 #if OSL_DEBUG_LEVEL > 1
2292 	DBG_ASSERT(&rComboBox == &aOldSymbols  ||  &rComboBox == &aSymbols,
2293 		"Sm : falsche ComboBox");
2294 #endif
2295 
2296 	// 'Normalisieren' des SymbolNamens (ohne Leerzeichen)
2297 	XubString  aNormName (rSymbolName);
2298 	aNormName.EraseAllChars(' ');
2299 	// und evtl Abweichungen in der Eingabe beseitigen
2300 	rComboBox.SetText(aNormName);
2301 
2302 	sal_Bool   bRet = sal_False;
2303 	sal_uInt16 nPos = rComboBox.GetEntryPos(aNormName);
2304 
2305 	sal_Bool  bIsOld = &rComboBox == &aOldSymbols;
2306 
2307 	if (nPos != COMBOBOX_ENTRY_NOTFOUND)
2308 	{
2309 		rComboBox.SetText(rComboBox.GetEntry(nPos));
2310 
2311 		if (!bIsOld)
2312 		{
2313 			const SmSym *pSymbol = GetSymbol(aSymbols);
2314 			if (pSymbol)
2315 			{
2316                 // Font und Style entsprechend waehlen
2317 				const Font &rFont = pSymbol->GetFace();
2318 				SelectFont(rFont.GetName(), sal_False);
2319                 SelectStyle(GetFontStyles().GetStyleName(rFont), sal_False);
2320 
2321                 // da das setzen des Fonts ueber den Style Namen des SymbolsFonts nicht
2322 				// so gut klappt (er kann zB leer sein obwohl der Font selbst 'bold' und
2323                 // 'italic' ist!). Setzen wir hier den Font wie er zum Symbol gehoert
2324                 // zu Fuss.
2325 				aCharsetDisplay.SetFont(rFont);
2326 				aSymbolDisplay.SetFont(rFont);
2327 
2328                 // das zugehoerige Zeichen auswaehlen
2329 				SelectChar(pSymbol->GetCharacter());
2330 
2331                 // since SelectChar will also set the unicode point as text in the
2332                 // symbols box, we have to set the symbol name again to get that one displayed
2333                 aSymbols.SetText( pSymbol->GetName() );
2334 			}
2335 		}
2336 
2337 		bRet = sal_True;
2338 	}
2339 	else if (bDeleteText)
2340 		rComboBox.SetText(XubString());
2341 
2342 	if (bIsOld)
2343 	{
2344 		// bei Wechsel des alten Symbols nur vorhandene anzeigen sonst keins
2345 		const SmSym *pOldSymbol = NULL;
2346         XubString     aTmpOldSymbolSetName;
2347 		if (nPos != COMBOBOX_ENTRY_NOTFOUND)
2348 		{
2349             pOldSymbol        = aSymbolMgrCopy.GetSymbolByName(aNormName);
2350             aTmpOldSymbolSetName = aOldSymbolSets.GetText();
2351 		}
2352         SetOrigSymbol(pOldSymbol, aTmpOldSymbolSetName);
2353 	}
2354 	else
2355 		aSymbolName.SetText(rComboBox.GetText());
2356 
2357 	UpdateButtons();
2358 
2359 	return bRet;
2360 }
2361 
2362 
SetFont(const XubString & rFontName,const XubString & rStyleName)2363 void SmSymDefineDialog::SetFont(const XubString &rFontName, const XubString &rStyleName)
2364 {
2365 	// Font (FontInfo) passend zu Namen und Style holen
2366     FontInfo aFI;
2367     if (pFontList)
2368         aFI = pFontList->Get(rFontName, WEIGHT_NORMAL, ITALIC_NONE);
2369 	SetFontStyle(rStyleName, aFI);
2370 
2371 	aCharsetDisplay.SetFont(aFI);
2372 	aSymbolDisplay.SetFont(aFI);
2373 
2374     // update subset listbox for new font's unicode subsets
2375     FontCharMap aFontCharMap;
2376     aCharsetDisplay.GetFontCharMap( aFontCharMap );
2377     if (pSubsetMap)
2378         delete pSubsetMap;
2379     pSubsetMap = new SubsetMap( &aFontCharMap );
2380     //
2381     aFontsSubsetLB.Clear();
2382     bool bFirst = true;
2383     const Subset* pSubset;
2384     while( NULL != (pSubset = pSubsetMap->GetNextSubset( bFirst )) )
2385     {
2386         sal_uInt16 nPos = aFontsSubsetLB.InsertEntry( pSubset->GetName());
2387         aFontsSubsetLB.SetEntryData( nPos, (void *) pSubset );
2388         // subset must live at least as long as the selected font !!!
2389         if( bFirst )
2390 	        aFontsSubsetLB.SelectEntryPos( nPos );
2391         bFirst = false;
2392     }
2393     if( bFirst )
2394         aFontsSubsetLB.SetNoSelection();
2395     aFontsSubsetLB.Enable( !bFirst );
2396 }
2397 
2398 
SelectFont(const XubString & rFontName,sal_Bool bApplyFont)2399 sal_Bool SmSymDefineDialog::SelectFont(const XubString &rFontName, sal_Bool bApplyFont)
2400 {
2401 	sal_Bool   bRet = sal_False;
2402 	sal_uInt16 nPos = aFonts.GetEntryPos(rFontName);
2403 
2404 	if (nPos != LISTBOX_ENTRY_NOTFOUND)
2405 	{
2406 		aFonts.SelectEntryPos(nPos);
2407 		if (aStyles.GetEntryCount() > 0)
2408 			SelectStyle(aStyles.GetEntry(0));
2409 		if (bApplyFont)
2410         {
2411 			SetFont(aFonts.GetSelectEntry(), aStyles.GetText());
2412             // update preview to use new font
2413             aSymbolDisplay.SetSymbol( aCharsetDisplay.GetSelectCharacter(), aCharsetDisplay.GetFont() );
2414         }
2415 		bRet = sal_True;
2416 	}
2417 	else
2418 		aFonts.SetNoSelection();
2419 	FillStyles();
2420 
2421 	UpdateButtons();
2422 
2423 	return bRet;
2424 }
2425 
2426 
SelectStyle(const XubString & rStyleName,sal_Bool bApplyFont)2427 sal_Bool SmSymDefineDialog::SelectStyle(const XubString &rStyleName, sal_Bool bApplyFont)
2428 {
2429 	sal_Bool   bRet = sal_False;
2430 	sal_uInt16 nPos = aStyles.GetEntryPos(rStyleName);
2431 
2432     // falls der Style nicht zur Auswahl steht nehmen wir den erst moeglichen
2433 	// (sofern vorhanden)
2434 	if (nPos == COMBOBOX_ENTRY_NOTFOUND  &&  aStyles.GetEntryCount() > 0)
2435 		nPos = 0;
2436 
2437 	if (nPos != COMBOBOX_ENTRY_NOTFOUND)
2438 	{
2439 		aStyles.SetText(aStyles.GetEntry(nPos));
2440 		if (bApplyFont)
2441         {
2442 			SetFont(aFonts.GetSelectEntry(), aStyles.GetText());
2443             // update preview to use new font
2444             aSymbolDisplay.SetSymbol( aCharsetDisplay.GetSelectCharacter(), aCharsetDisplay.GetFont() );
2445         }
2446 		bRet = sal_True;
2447 	}
2448 	else
2449 		aStyles.SetText(XubString());
2450 
2451 	UpdateButtons();
2452 
2453 	return bRet;
2454 }
2455 
2456 
SelectChar(xub_Unicode cChar)2457 void SmSymDefineDialog::SelectChar(xub_Unicode cChar)
2458 {
2459     aCharsetDisplay.SelectCharacter( cChar );
2460     aSymbolDisplay.SetSymbol( cChar, aCharsetDisplay.GetFont() );
2461 
2462 	UpdateButtons();
2463 }
2464 
2465 
2466 /**************************************************************************/
2467 
2468