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