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