1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: fontsubs.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_svx.hxx"
34 #ifdef SVX_DLLIMPLEMENTATION
35 #undef SVX_DLLIMPLEMENTATION
41 #include <tools/shl.hxx>
42 #include <svtools/ctrltool.hxx>
43 #include <vcl/svapp.hxx>
44 #include <vcl/wrkwin.hxx>
45 #ifndef _OFA_FONTSUBSTCONFIG_HXX
46 #include <svtools/fontsubstconfig.hxx>
48 #include <svtools/sourceviewconfig.hxx>
50 #include "fontsubs.hrc"
51 #include "fontsubs.hxx"
52 #include <svx/dialmgr.hxx>
54 #include <svx/dialogs.hrc>
56 /*********************************************************************/
58 /* TabPage Fontersetzung */
60 /*********************************************************************/
63 #define CBCOL_SECOND 1
66 SvxFontSubstTabPage::SvxFontSubstTabPage( Window
* pParent
,
67 const SfxItemSet
& rSet
) :
68 SfxTabPage(pParent
, SVX_RES(RID_SVX_FONT_SUBSTITUTION
), rSet
),
69 aUseTableCB (this, SVX_RES(CB_USETABLE
)),
70 aFont1FT (this, SVX_RES(FT_FONT1
)),
71 aFont1CB (this, SVX_RES(CB_FONT1
)),
72 aFont2FT (this, SVX_RES(FT_FONT2
)),
73 aFont2CB (this, SVX_RES(CB_FONT2
)),
74 aNewDelTBX (this, SVX_RES(TBX_SUBSTNEWDEL
)),
75 aCheckLB (this, SVX_RES(CLB_SUBSTITUTES
)),
77 aSourceViewFontsFL (this, SVX_RES(FL_SOURCEVIEW
)),
78 aFontNameFT (this, SVX_RES(FT_FONTNAME
)),
79 aFontNameLB (this, SVX_RES(LB_FONTNAME
)),
80 aNonPropFontsOnlyCB(this, SVX_RES(CB_NONPROP
)),
81 aFontHeightFT (this, SVX_RES(FT_FONTHEIGHT
)),
82 aFontHeightLB (this, SVX_RES(LB_FONTHEIGHT
)),
84 aImageList (SVX_RES(IL_ICON
)),
86 sAutomatic (SVX_RES( STR_AUTOMATIC
)),
87 pConfig(new SvtFontSubstConfig
),
88 pSourceViewConfig(new svt::SourceViewConfig
),
90 sHeader1 (SVX_RES( STR_HEADER1
)),
91 sHeader2 (SVX_RES( STR_HEADER2
)),
92 sHeader3 (SVX_RES( STR_HEADER3
)),
93 sHeader4 (SVX_RES( STR_HEADER4
)),
95 sFontGroup ("FontSubstitution"),
100 aTextColor
= aCheckLB
.GetTextColor();
102 for(USHORT k
= 0; k
< aNewDelTBX
.GetItemCount(); k
++)
103 aNewDelTBX
.SetItemImage(aNewDelTBX
.GetItemId(k
),
104 aImageList
.GetImage(aNewDelTBX
.GetItemId(k
)));
106 aNewDelTBX
.SetSizePixel( aNewDelTBX
.CalcWindowSizePixel() );
108 long nDelta
= ( aFont1CB
.GetSizePixel().Height() -
109 aNewDelTBX
.GetSizePixel().Height() ) / 2;
110 Point aNewPnt
= aNewDelTBX
.GetPosPixel();
111 aNewPnt
.Y() += nDelta
;
112 aNewDelTBX
.SetPosPixel( aNewPnt
);
114 aCheckLB
.SetHelpId(HID_OFA_FONT_SUBST_CLB
);
115 aCheckLB
.SetWindowBits(aCheckLB
.GetStyle()|WB_HSCROLL
|WB_VSCROLL
);
116 aCheckLB
.SetSelectionMode(MULTIPLE_SELECTION
);
117 aCheckLB
.SortByCol(2);
119 Link
aLink(LINK(this, SvxFontSubstTabPage
, SelectHdl
));
121 aCheckLB
.SetSelectHdl(aLink
);
122 aUseTableCB
.SetClickHdl(aLink
);
123 aFont1CB
.SetSelectHdl(aLink
);
124 aFont1CB
.SetModifyHdl(aLink
);
125 aFont2CB
.SetSelectHdl(aLink
);
126 aFont2CB
.SetModifyHdl(aLink
);
127 aNewDelTBX
.SetClickHdl(aLink
);
129 aNonPropFontsOnlyCB
.SetClickHdl(LINK(this, SvxFontSubstTabPage
, NonPropFontsHdl
));
131 static long aStaticTabs
[] = { 4, 0, 0, 0, 0 };
132 long nW1
= GetTextWidth( sHeader1
);
133 long nW2
= GetTextWidth( sHeader2
);
134 long nMax
= Max( nW1
, nW2
) + 6; // width of the longest header + a little offset
135 long nMin
= aFontNameFT
.LogicToPixel( Size( 30, 0 ), MAP_APPFONT
).Width();
136 nMax
= Max( nMax
, nMin
);
137 const long nDoubleMax
= 2*nMax
;
138 const long nRest
= aCheckLB
.GetSizePixel().Width() - nDoubleMax
;
139 aStaticTabs
[2] = nMax
;
140 aStaticTabs
[3] = nDoubleMax
;
141 aStaticTabs
[4] = nDoubleMax
+ nRest
/2;
142 aCheckLB
.SvxSimpleTable::SetTabs( aStaticTabs
, MAP_PIXEL
);
144 String
sHeader(sHeader1
);
145 String
sTab(String::CreateFromAscii("\t"));
146 String
sTabSpace(String::CreateFromAscii("\t "));
149 sHeader
+= sTabSpace
;
151 sHeader
+= sTabSpace
;
153 // sHeader += sTabSpace;
154 aCheckLB
.InsertHeaderEntry(sHeader
);
156 HeaderBar
* pBar
= aCheckLB
.GetTheHeaderBar();
158 HeaderBarItemBits nBits
= pBar
->GetItemBits(1) | HIB_FIXEDPOS
| HIB_FIXED
;
159 nBits
&= ~HIB_CLICKABLE
;
160 pBar
->SetItemBits(1, nBits
);
161 pBar
->SetItemBits(2, nBits
);
164 for(nHeight
= 6; nHeight
<= 16; nHeight
++)
165 aFontHeightLB
.InsertEntry(String::CreateFromInt32(nHeight
));
166 for(nHeight
= 18; nHeight
<= 28; nHeight
+= 2)
167 aFontHeightLB
.InsertEntry(String::CreateFromInt32(nHeight
));
168 for(nHeight
= 32; nHeight
<= 48; nHeight
+= 4)
169 aFontHeightLB
.InsertEntry(String::CreateFromInt32(nHeight
));
170 for(nHeight
= 54; nHeight
<= 72; nHeight
+= 6)
171 aFontHeightLB
.InsertEntry(String::CreateFromInt32(nHeight
));
172 for(nHeight
= 80; nHeight
<= 96; nHeight
+= 8)
173 aFontHeightLB
.InsertEntry(String::CreateFromInt32(nHeight
));
176 /*********************************************************************/
178 /*********************************************************************/
180 SvLBoxEntry
* SvxFontSubstTabPage::CreateEntry(String
& rFont1
, String
& rFont2
)
182 SvLBoxEntry
* pEntry
= new SvLBoxEntry
;
184 if( !pCheckButtonData
)
185 pCheckButtonData
= new SvLBoxButtonData( &aCheckLB
);
187 pEntry
->AddItem( new SvLBoxContextBmp( pEntry
, 0, Image(), Image(), 0)); // Sonst Puff!
189 pEntry
->AddItem( new SvLBoxButton( pEntry
,
190 SvLBoxButtonKind_enabledCheckbox
, 0,
191 pCheckButtonData
) );
192 pEntry
->AddItem( new SvLBoxButton( pEntry
,
193 SvLBoxButtonKind_enabledCheckbox
, 0,
194 pCheckButtonData
) );
196 pEntry
->AddItem( new SvLBoxString( pEntry
, 0, rFont1
) );
197 pEntry
->AddItem( new SvLBoxString( pEntry
, 0, rFont2
) );
202 /*********************************************************************/
204 /*********************************************************************/
207 SvxFontSubstTabPage::~SvxFontSubstTabPage()
209 delete pCheckButtonData
;
211 delete pSourceViewConfig
;
214 /*********************************************************************/
216 /*********************************************************************/
218 SfxTabPage
* SvxFontSubstTabPage::Create( Window
* pParent
,
219 const SfxItemSet
& rAttrSet
)
221 return new SvxFontSubstTabPage(pParent
, rAttrSet
);
224 /*********************************************************************/
226 /*********************************************************************/
228 BOOL
SvxFontSubstTabPage::FillItemSet( SfxItemSet
& )
230 pConfig
->ClearSubstitutions();// remove all entries
232 pConfig
->Enable(aUseTableCB
.IsChecked());
234 SvLBoxEntry
* pEntry
= aCheckLB
.First();
238 SubstitutionStruct aAdd
;
239 aAdd
.sFont
= aCheckLB
.GetEntryText(pEntry
, 0);
240 aAdd
.sReplaceBy
= aCheckLB
.GetEntryText(pEntry
, 1);
241 aAdd
.bReplaceAlways
= aCheckLB
.IsChecked(pEntry
, 0);
242 aAdd
.bReplaceOnScreenOnly
= aCheckLB
.IsChecked(pEntry
, 1);
243 pConfig
->AddSubstitution(aAdd
);
244 pEntry
= aCheckLB
.Next(pEntry
);
246 if(pConfig
->IsModified())
249 if(aFontHeightLB
.GetSavedValue() != aFontHeightLB
.GetSelectEntryPos())
250 pSourceViewConfig
->SetFontHeight((sal_Int16
)aFontHeightLB
.GetSelectEntry().ToInt32());
251 if(aNonPropFontsOnlyCB
.GetSavedValue() != aNonPropFontsOnlyCB
.IsChecked())
252 pSourceViewConfig
->SetShowProportionalFontsOnly(aNonPropFontsOnlyCB
.IsChecked());
253 //font name changes cannot be detected by saved values
255 if(aFontNameLB
.GetSelectEntryPos())
256 sFontName
= aFontNameLB
.GetSelectEntry();
257 pSourceViewConfig
->SetFontName(sFontName
);
262 /*********************************************************************/
264 /*********************************************************************/
267 void SvxFontSubstTabPage::Reset( const SfxItemSet
& )
269 aCheckLB
.SetUpdateMode(FALSE
);
272 FontList
aFntLst( Application::GetDefaultDevice() );
273 aFont1CB
.Fill( &aFntLst
);
274 aFont2CB
.Fill( &aFntLst
);
276 sal_Int32 nCount
= pConfig
->SubstitutionCount();
278 aUseTableCB
.Check(pConfig
->IsEnabled());
280 for (sal_Int32 i
= 0; i
< nCount
; i
++)
282 const SubstitutionStruct
* pSubs
= pConfig
->GetSubstitution(i
);
283 String
aTmpStr1(pSubs
->sFont
);
284 String
aTmpStr2(pSubs
->sReplaceBy
);
285 SvLBoxEntry
* pEntry
= CreateEntry(aTmpStr1
, aTmpStr2
);
286 aCheckLB
.Insert(pEntry
);
287 aCheckLB
.CheckEntry(pEntry
, 0, pSubs
->bReplaceAlways
);
288 aCheckLB
.CheckEntry(pEntry
, 1, pSubs
->bReplaceOnScreenOnly
);
292 aCheckLB
.SetUpdateMode(TRUE
);
294 //fill font name box first
295 aNonPropFontsOnlyCB
.Check(pSourceViewConfig
->IsShowProportionalFontsOnly());
296 NonPropFontsHdl(&aNonPropFontsOnlyCB
);
297 String
sFontName(pSourceViewConfig
->GetFontName());
299 aFontNameLB
.SelectEntry(sFontName
);
301 aFontNameLB
.SelectEntryPos(0);
302 short nFontHeight
= pSourceViewConfig
->GetFontHeight();
303 aFontHeightLB
.SelectEntry(String::CreateFromInt32(nFontHeight
));
304 aNonPropFontsOnlyCB
.SaveValue();
305 aFontHeightLB
.SaveValue();
308 /*********************************************************************/
310 /*********************************************************************/
312 IMPL_LINK(SvxFontSubstTabPage
, SelectHdl
, Window
*, pWin
)
314 if (pWin
== &aNewDelTBX
)
317 // nCol ist behaemmerterweise die nCol'te Textspalte, werden nicht gezaehlt!
318 // Daher als Spalte "0".
319 ULONG nPos
= aCheckLB
.GetEntryPos(aFont1CB
.GetText(), 0);
321 switch (aNewDelTBX
.GetCurItemId())
325 if (nPos
!= 0xffffffff)
328 aCheckLB
.SetEntryText(aFont2CB
.GetText(), nPos
, 1);
329 pEntry
= aCheckLB
.GetEntry(nPos
);
334 String sFont1
= aFont1CB
.GetText();
335 String sFont2
= aFont2CB
.GetText();
337 pEntry
= CreateEntry(sFont1
, sFont2
);
338 aCheckLB
.Insert(pEntry
);
340 aCheckLB
.SelectAll(FALSE
);
341 aCheckLB
.Select(pEntry
);
347 if (nPos
!= 0xffffffff)
349 pEntry
= aCheckLB
.FirstSelected();
352 SvLBoxEntry
* pDelEntry
= pEntry
;
353 pEntry
= aCheckLB
.NextSelected(pEntry
);
354 aCheckLB
.RemoveEntry(pDelEntry
);
362 if (pWin
== &aCheckLB
)
364 SvLBoxEntry
* pEntry
= aCheckLB
.FirstSelected();
366 if (aCheckLB
.NextSelected(pEntry
) == 0)
368 aFont1CB
.SetText(aCheckLB
.GetEntryText(pEntry
, 0));
369 aFont2CB
.SetText(aCheckLB
.GetEntryText(pEntry
, 1));
373 if (pWin
== &aFont1CB
)
375 ULONG nPos
= aCheckLB
.GetEntryPos(aFont1CB
.GetText(), 0);
377 if (nPos
!= 0xffffffff)
379 SvLBoxEntry
* pEntry
= aCheckLB
.GetEntry(nPos
);
381 if (pEntry
!= aCheckLB
.FirstSelected())
383 aCheckLB
.SelectAll(FALSE
);
384 aCheckLB
.Select(pEntry
);
393 /* -----------------------------29.08.2002 11:47------------------------------
395 ---------------------------------------------------------------------------*/
396 IMPL_LINK(SvxFontSubstTabPage
, NonPropFontsHdl
, CheckBox
*, pBox
)
398 String sFontName
= aFontNameLB
.GetSelectEntry();
399 BOOL bNonPropOnly
= pBox
->IsChecked();
401 FontList
aFntLst( Application::GetDefaultDevice() );
402 aFontNameLB
.InsertEntry(sAutomatic
);
403 USHORT nFontCount
= aFntLst
.GetFontNameCount();
404 for(USHORT nFont
= 0; nFont
< nFontCount
; nFont
++)
406 const FontInfo
& rInfo
= aFntLst
.GetFontName( nFont
);
407 if(!bNonPropOnly
|| rInfo
.GetPitch() == PITCH_FIXED
)
408 aFontNameLB
.InsertEntry(rInfo
.GetName());
410 aFontNameLB
.SelectEntry(sFontName
);
413 /*********************************************************************/
415 /*********************************************************************/
417 void SvxFontSubstTabPage::CheckEnable()
419 BOOL bEnableAll
= aUseTableCB
.IsChecked();
423 BOOL bApply
, bDelete
;
425 SvLBoxEntry
* pEntry
= aCheckLB
.FirstSelected();
427 String sEntry
= aFont1CB
.GetText();
429 sEntry
+= aFont2CB
.GetText();
431 /* if (!aFont1CB.GetText().Len() || !aFont2CB.GetText().Len() ||
432 aFont1CB.GetText() == aFont2CB.GetText() ||
433 aCheckLB.GetEntryPos(sEntry) != 0xffffffff ||
434 (pEntry != 0 && aCheckLB.NextSelected(pEntry) != 0))
439 // Wegen OS/2-Optimierungsfehler (Bug #56267) etwas umstaendlicher:
440 if (!aFont1CB
.GetText().Len() || !aFont2CB
.GetText().Len())
442 else if(aFont1CB
.GetText() == aFont2CB
.GetText())
444 else if(aCheckLB
.GetEntryPos(sEntry
) != 0xffffffff)
446 else if(pEntry
!= 0 && aCheckLB
.NextSelected(pEntry
) != 0)
451 bDelete
= pEntry
!= 0;
453 aNewDelTBX
.EnableItem(BT_SUBSTAPPLY
, bApply
);
454 aNewDelTBX
.EnableItem(BT_SUBSTDELETE
, bDelete
);
459 if (!aCheckLB
.IsEnabled())
461 aCheckLB
.EnableTable();
462 aCheckLB
.SetTextColor(aTextColor
);
463 aCheckLB
.Invalidate();
464 SelectHdl(&aFont1CB
);
469 if (aCheckLB
.IsEnabled())
471 aCheckLB
.DisableTable();
472 aCheckLB
.SetTextColor(Color(COL_GRAY
));
473 aCheckLB
.Invalidate();
474 aCheckLB
.SelectAll(FALSE
);
477 aNewDelTBX
.Enable(bEnableAll
);
478 aFont1FT
.Enable(bEnableAll
);
479 aFont1CB
.Enable(bEnableAll
);
480 aFont2FT
.Enable(bEnableAll
);
481 aFont2CB
.Enable(bEnableAll
);
484 /*********************************************************************/
486 /*********************************************************************/
488 void SvxFontSubstCheckListBox::SetTabs()
490 SvxSimpleTable::SetTabs();
491 USHORT nAdjust
= SV_LBOXTAB_ADJUST_RIGHT
|SV_LBOXTAB_ADJUST_LEFT
|SV_LBOXTAB_ADJUST_CENTER
|SV_LBOXTAB_ADJUST_NUMERIC
|SV_LBOXTAB_FORCE
;
493 SvLBoxTab
* pTab
= (SvLBoxTab
*)aTabs
.GetObject(1);
494 pTab
->nFlags
&= ~nAdjust
;
495 pTab
->nFlags
|= SV_LBOXTAB_PUSHABLE
|SV_LBOXTAB_ADJUST_CENTER
|SV_LBOXTAB_FORCE
;
497 pTab
= (SvLBoxTab
*)aTabs
.GetObject(2);
498 pTab
->nFlags
&= ~nAdjust
;
499 pTab
->nFlags
|= SV_LBOXTAB_PUSHABLE
|SV_LBOXTAB_ADJUST_CENTER
|SV_LBOXTAB_FORCE
;
501 /* -----------------------------22.05.2002 11:06------------------------------
503 ---------------------------------------------------------------------------*/
504 void SvxFontSubstCheckListBox::KeyInput( const KeyEvent
& rKEvt
)
506 if(!rKEvt
.GetKeyCode().GetModifier() &&
507 KEY_SPACE
== rKEvt
.GetKeyCode().GetCode())
509 ULONG nSelPos
= GetModel()->GetAbsPos(GetCurEntry());
510 USHORT nCol
= GetCurrentTabPos() - 1;
513 CheckEntryPos( nSelPos
, nCol
, !IsChecked( nSelPos
, nCol
) );
514 CallImplEventListeners( VCLEVENT_CHECKBOX_TOGGLE
, (void*)GetEntry( nSelPos
) );
518 USHORT nCheck
= IsChecked(nSelPos
, 1) ? 1 : 0;
519 if(IsChecked(nSelPos
, 0))
523 CheckEntryPos(nSelPos
, 1, 0 != (nCheck
& 1));
524 CheckEntryPos(nSelPos
, 0, 0 != (nCheck
& 2));
528 SvxSimpleTable::KeyInput(rKEvt
);
531 /*********************************************************************/
533 /*********************************************************************/
535 void SvxFontSubstCheckListBox::CheckEntryPos(ULONG nPos
, USHORT nCol
, BOOL bChecked
)
537 if ( nPos
< GetEntryCount() )
541 bChecked
? SvButtonState( SV_BUTTON_CHECKED
) :
542 SvButtonState( SV_BUTTON_UNCHECKED
) );
545 /*********************************************************************/
547 /*********************************************************************/
549 void SvxFontSubstCheckListBox::CheckEntry(SvLBoxEntry
* pEntry
, USHORT nCol
, BOOL bChecked
)
555 bChecked
? SvButtonState( SV_BUTTON_CHECKED
) :
556 SvButtonState( SV_BUTTON_UNCHECKED
) );
559 /*********************************************************************/
561 /*********************************************************************/
563 BOOL
SvxFontSubstCheckListBox::IsChecked(ULONG nPos
, USHORT nCol
)
565 return GetCheckButtonState( GetEntry(nPos
), nCol
) == SV_BUTTON_CHECKED
;
568 /*********************************************************************/
570 /*********************************************************************/
572 BOOL
SvxFontSubstCheckListBox::IsChecked(SvLBoxEntry
* pEntry
, USHORT nCol
)
574 return GetCheckButtonState( pEntry
, nCol
) == SV_BUTTON_CHECKED
;
577 /*********************************************************************/
579 /*********************************************************************/
581 void SvxFontSubstCheckListBox::SetCheckButtonState( SvLBoxEntry
* pEntry
, USHORT nCol
, SvButtonState eState
)
583 SvLBoxButton
* pItem
= (SvLBoxButton
*)(pEntry
->GetItem(nCol
+ 1));
585 DBG_ASSERT(pItem
,"SetCheckButton:Item not found");
586 if (((SvLBoxItem
*)pItem
)->IsA() == SV_ITEM_ID_LBOXBUTTON
)
590 case SV_BUTTON_CHECKED
:
591 pItem
->SetStateChecked();
594 case SV_BUTTON_UNCHECKED
:
595 pItem
->SetStateUnchecked();
598 case SV_BUTTON_TRISTATE
:
599 pItem
->SetStateTristate();
602 InvalidateEntry( pEntry
);
606 /*********************************************************************/
608 /*********************************************************************/
610 SvButtonState
SvxFontSubstCheckListBox::GetCheckButtonState( SvLBoxEntry
* pEntry
, USHORT nCol
) const
612 SvButtonState eState
= SV_BUTTON_UNCHECKED
;
613 SvLBoxButton
* pItem
= (SvLBoxButton
*)(pEntry
->GetItem(nCol
+ 1));
614 DBG_ASSERT(pItem
,"GetChButnState:Item not found");
616 if (((SvLBoxItem
*)pItem
)->IsA() == SV_ITEM_ID_LBOXBUTTON
)
618 USHORT nButtonFlags
= pItem
->GetButtonFlags();
619 eState
= pCheckButtonData
->ConvertToButtonState( nButtonFlags
);