xref: /AOO41X/main/cui/source/options/fontsubs.cxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
29*cdf0e10cSrcweir #include "precompiled_cui.hxx"
30*cdf0e10cSrcweir #include <tools/shl.hxx>
31*cdf0e10cSrcweir #include <svtools/ctrltool.hxx>
32*cdf0e10cSrcweir #include <vcl/svapp.hxx>
33*cdf0e10cSrcweir #include <vcl/wrkwin.hxx>
34*cdf0e10cSrcweir #include <svtools/fontsubstconfig.hxx>
35*cdf0e10cSrcweir #include <unotools/sourceviewconfig.hxx>
36*cdf0e10cSrcweir #include "fontsubs.hrc"
37*cdf0e10cSrcweir #include "fontsubs.hxx"
38*cdf0e10cSrcweir #include <dialmgr.hxx>
39*cdf0e10cSrcweir #include "helpid.hrc"
40*cdf0e10cSrcweir #include <cuires.hrc>
41*cdf0e10cSrcweir 
42*cdf0e10cSrcweir /*********************************************************************/
43*cdf0e10cSrcweir /*                                                                   */
44*cdf0e10cSrcweir /* 	TabPage Fontersetzung                                            */
45*cdf0e10cSrcweir /*                                                                   */
46*cdf0e10cSrcweir /*********************************************************************/
47*cdf0e10cSrcweir 
48*cdf0e10cSrcweir #define CBCOL_FIRST		0
49*cdf0e10cSrcweir #define CBCOL_SECOND	1
50*cdf0e10cSrcweir #define CBCOL_BOTH		2
51*cdf0e10cSrcweir 
52*cdf0e10cSrcweir SvxFontSubstTabPage::SvxFontSubstTabPage( Window* pParent,
53*cdf0e10cSrcweir 								const SfxItemSet& rSet ) :
54*cdf0e10cSrcweir 	SfxTabPage(pParent, CUI_RES(RID_SVX_FONT_SUBSTITUTION), rSet),
55*cdf0e10cSrcweir 	aUseTableCB 		(this,	CUI_RES(CB_USETABLE)),
56*cdf0e10cSrcweir     aFont1FT            (this,  CUI_RES(FT_FONT1)),
57*cdf0e10cSrcweir 	aFont1CB			(this,	CUI_RES(CB_FONT1)),
58*cdf0e10cSrcweir 	aFont2FT			(this,	CUI_RES(FT_FONT2)),
59*cdf0e10cSrcweir 	aFont2CB			(this,	CUI_RES(CB_FONT2)),
60*cdf0e10cSrcweir 	aNewDelTBX			(this,	CUI_RES(TBX_SUBSTNEWDEL)),
61*cdf0e10cSrcweir     aCheckLB            (this,  CUI_RES(CLB_SUBSTITUTES)),
62*cdf0e10cSrcweir 
63*cdf0e10cSrcweir     aSourceViewFontsFL (this,  CUI_RES(FL_SOURCEVIEW  )),
64*cdf0e10cSrcweir     aFontNameFT        (this,  CUI_RES(FT_FONTNAME    )),
65*cdf0e10cSrcweir     aFontNameLB        (this,  CUI_RES(LB_FONTNAME    )),
66*cdf0e10cSrcweir     aNonPropFontsOnlyCB(this,  CUI_RES(CB_NONPROP     )),
67*cdf0e10cSrcweir     aFontHeightFT      (this,  CUI_RES(FT_FONTHEIGHT  )),
68*cdf0e10cSrcweir     aFontHeightLB      (this,  CUI_RES(LB_FONTHEIGHT  )),
69*cdf0e10cSrcweir 
70*cdf0e10cSrcweir 	aImageList			(CUI_RES(IL_ICON)),
71*cdf0e10cSrcweir 
72*cdf0e10cSrcweir     sAutomatic          (CUI_RES( STR_AUTOMATIC  )),
73*cdf0e10cSrcweir     pConfig(new SvtFontSubstConfig),
74*cdf0e10cSrcweir     pSourceViewConfig(new utl::SourceViewConfig),
75*cdf0e10cSrcweir 
76*cdf0e10cSrcweir 	sHeader1			(CUI_RES( STR_HEADER1		)),
77*cdf0e10cSrcweir 	sHeader2			(CUI_RES( STR_HEADER2		)),
78*cdf0e10cSrcweir 	sHeader3			(CUI_RES( STR_HEADER3		)),
79*cdf0e10cSrcweir 	sHeader4			(CUI_RES( STR_HEADER4		)),
80*cdf0e10cSrcweir 
81*cdf0e10cSrcweir     sFontGroup          ("FontSubstitution"),
82*cdf0e10cSrcweir     pCheckButtonData(0)
83*cdf0e10cSrcweir {
84*cdf0e10cSrcweir 	FreeResource();
85*cdf0e10cSrcweir 
86*cdf0e10cSrcweir 	aTextColor = aCheckLB.GetTextColor();
87*cdf0e10cSrcweir 
88*cdf0e10cSrcweir 	for(sal_uInt16 k = 0; k < aNewDelTBX.GetItemCount(); k++)
89*cdf0e10cSrcweir 		aNewDelTBX.SetItemImage(aNewDelTBX.GetItemId(k),
90*cdf0e10cSrcweir 			aImageList.GetImage(aNewDelTBX.GetItemId(k)));
91*cdf0e10cSrcweir 
92*cdf0e10cSrcweir 	aNewDelTBX.SetSizePixel( aNewDelTBX.CalcWindowSizePixel() );
93*cdf0e10cSrcweir 
94*cdf0e10cSrcweir 	long nDelta = ( aFont1CB.GetSizePixel().Height() -
95*cdf0e10cSrcweir 					aNewDelTBX.GetSizePixel().Height() ) / 2;
96*cdf0e10cSrcweir 	Point aNewPnt = aNewDelTBX.GetPosPixel();
97*cdf0e10cSrcweir 	aNewPnt.Y() += nDelta;
98*cdf0e10cSrcweir 	aNewDelTBX.SetPosPixel( aNewPnt );
99*cdf0e10cSrcweir 
100*cdf0e10cSrcweir 	aCheckLB.SetHelpId(HID_OFA_FONT_SUBST_CLB);
101*cdf0e10cSrcweir 	aCheckLB.SetStyle(aCheckLB.GetStyle()|WB_HSCROLL|WB_VSCROLL);
102*cdf0e10cSrcweir 	aCheckLB.SetSelectionMode(MULTIPLE_SELECTION);
103*cdf0e10cSrcweir 	aCheckLB.SortByCol(2);
104*cdf0e10cSrcweir 
105*cdf0e10cSrcweir 	Link aLink(LINK(this, SvxFontSubstTabPage, SelectHdl));
106*cdf0e10cSrcweir 
107*cdf0e10cSrcweir 	aCheckLB.SetSelectHdl(aLink);
108*cdf0e10cSrcweir 	aUseTableCB.SetClickHdl(aLink);
109*cdf0e10cSrcweir 	aFont1CB.SetSelectHdl(aLink);
110*cdf0e10cSrcweir 	aFont1CB.SetModifyHdl(aLink);
111*cdf0e10cSrcweir 	aFont2CB.SetSelectHdl(aLink);
112*cdf0e10cSrcweir 	aFont2CB.SetModifyHdl(aLink);
113*cdf0e10cSrcweir 	aNewDelTBX.SetClickHdl(aLink);
114*cdf0e10cSrcweir 
115*cdf0e10cSrcweir     aNonPropFontsOnlyCB.SetClickHdl(LINK(this, SvxFontSubstTabPage, NonPropFontsHdl));
116*cdf0e10cSrcweir 
117*cdf0e10cSrcweir     static long aStaticTabs[] = { 4, 0, 0, 0, 0 };
118*cdf0e10cSrcweir     long nW1 = GetTextWidth( sHeader1 );
119*cdf0e10cSrcweir     long nW2 = GetTextWidth( sHeader2 );
120*cdf0e10cSrcweir     long nMax = Max( nW1, nW2 ) + 6; // width of the longest header + a little offset
121*cdf0e10cSrcweir     long nMin = aFontNameFT.LogicToPixel( Size( 30, 0 ), MAP_APPFONT ).Width();
122*cdf0e10cSrcweir     nMax = Max( nMax, nMin );
123*cdf0e10cSrcweir     const long nDoubleMax = 2*nMax;
124*cdf0e10cSrcweir     const long nRest = aCheckLB.GetSizePixel().Width() - nDoubleMax;
125*cdf0e10cSrcweir     aStaticTabs[2] = nMax;
126*cdf0e10cSrcweir     aStaticTabs[3] = nDoubleMax;
127*cdf0e10cSrcweir     aStaticTabs[4] = nDoubleMax + nRest/2;
128*cdf0e10cSrcweir     aCheckLB.SvxSimpleTable::SetTabs( aStaticTabs, MAP_PIXEL );
129*cdf0e10cSrcweir 
130*cdf0e10cSrcweir     String sHeader(sHeader1);
131*cdf0e10cSrcweir 	String sTab(String::CreateFromAscii("\t"));
132*cdf0e10cSrcweir 	String sTabSpace(String::CreateFromAscii("\t "));
133*cdf0e10cSrcweir 	sHeader += sTab;
134*cdf0e10cSrcweir 	sHeader += sHeader2;
135*cdf0e10cSrcweir 	sHeader += sTabSpace;
136*cdf0e10cSrcweir 	sHeader += sHeader3;
137*cdf0e10cSrcweir 	sHeader += sTabSpace;
138*cdf0e10cSrcweir 	sHeader += sHeader4;
139*cdf0e10cSrcweir //   sHeader += sTabSpace;
140*cdf0e10cSrcweir 	aCheckLB.InsertHeaderEntry(sHeader);
141*cdf0e10cSrcweir 
142*cdf0e10cSrcweir 	HeaderBar* pBar = aCheckLB.GetTheHeaderBar();
143*cdf0e10cSrcweir 
144*cdf0e10cSrcweir 	HeaderBarItemBits nBits = pBar->GetItemBits(1) | HIB_FIXEDPOS | HIB_FIXED;
145*cdf0e10cSrcweir 	nBits &= ~HIB_CLICKABLE;
146*cdf0e10cSrcweir 	pBar->SetItemBits(1, nBits);
147*cdf0e10cSrcweir 	pBar->SetItemBits(2, nBits);
148*cdf0e10cSrcweir 
149*cdf0e10cSrcweir     sal_uInt16 nHeight;
150*cdf0e10cSrcweir     for(nHeight = 6; nHeight <= 16; nHeight++)
151*cdf0e10cSrcweir         aFontHeightLB.InsertEntry(String::CreateFromInt32(nHeight));
152*cdf0e10cSrcweir     for(nHeight = 18; nHeight <= 28; nHeight+= 2)
153*cdf0e10cSrcweir         aFontHeightLB.InsertEntry(String::CreateFromInt32(nHeight));
154*cdf0e10cSrcweir     for(nHeight = 32; nHeight <= 48; nHeight+= 4)
155*cdf0e10cSrcweir         aFontHeightLB.InsertEntry(String::CreateFromInt32(nHeight));
156*cdf0e10cSrcweir     for(nHeight = 54; nHeight <= 72; nHeight+= 6)
157*cdf0e10cSrcweir         aFontHeightLB.InsertEntry(String::CreateFromInt32(nHeight));
158*cdf0e10cSrcweir     for(nHeight = 80; nHeight <= 96; nHeight+= 8)
159*cdf0e10cSrcweir         aFontHeightLB.InsertEntry(String::CreateFromInt32(nHeight));
160*cdf0e10cSrcweir }
161*cdf0e10cSrcweir 
162*cdf0e10cSrcweir /*********************************************************************/
163*cdf0e10cSrcweir /*                                                                   */
164*cdf0e10cSrcweir /*********************************************************************/
165*cdf0e10cSrcweir 
166*cdf0e10cSrcweir SvLBoxEntry* SvxFontSubstTabPage::CreateEntry(String& rFont1, String& rFont2)
167*cdf0e10cSrcweir {
168*cdf0e10cSrcweir 	SvLBoxEntry* pEntry = new SvLBoxEntry;
169*cdf0e10cSrcweir 
170*cdf0e10cSrcweir 	if( !pCheckButtonData )
171*cdf0e10cSrcweir 		pCheckButtonData = new SvLBoxButtonData( &aCheckLB );
172*cdf0e10cSrcweir 
173*cdf0e10cSrcweir 	pEntry->AddItem( new SvLBoxContextBmp( pEntry, 0, Image(), Image(), 0));	// Sonst Puff!
174*cdf0e10cSrcweir 
175*cdf0e10cSrcweir 	pEntry->AddItem( new SvLBoxButton( pEntry,
176*cdf0e10cSrcweir                                            SvLBoxButtonKind_enabledCheckbox, 0,
177*cdf0e10cSrcweir                                            pCheckButtonData ) );
178*cdf0e10cSrcweir 	pEntry->AddItem( new SvLBoxButton( pEntry,
179*cdf0e10cSrcweir                                            SvLBoxButtonKind_enabledCheckbox, 0,
180*cdf0e10cSrcweir                                            pCheckButtonData ) );
181*cdf0e10cSrcweir 
182*cdf0e10cSrcweir 	pEntry->AddItem( new SvLBoxString( pEntry, 0, rFont1 ) );
183*cdf0e10cSrcweir 	pEntry->AddItem( new SvLBoxString( pEntry, 0, rFont2 ) );
184*cdf0e10cSrcweir 
185*cdf0e10cSrcweir 	return pEntry;
186*cdf0e10cSrcweir }
187*cdf0e10cSrcweir 
188*cdf0e10cSrcweir /*********************************************************************/
189*cdf0e10cSrcweir /*                                                                   */
190*cdf0e10cSrcweir /*********************************************************************/
191*cdf0e10cSrcweir 
192*cdf0e10cSrcweir 
193*cdf0e10cSrcweir  SvxFontSubstTabPage::~SvxFontSubstTabPage()
194*cdf0e10cSrcweir {
195*cdf0e10cSrcweir 	delete pCheckButtonData;
196*cdf0e10cSrcweir 	delete pConfig;
197*cdf0e10cSrcweir     delete pSourceViewConfig;
198*cdf0e10cSrcweir }
199*cdf0e10cSrcweir 
200*cdf0e10cSrcweir /*********************************************************************/
201*cdf0e10cSrcweir /*                                                                   */
202*cdf0e10cSrcweir /*********************************************************************/
203*cdf0e10cSrcweir 
204*cdf0e10cSrcweir SfxTabPage*  SvxFontSubstTabPage::Create( Window* pParent,
205*cdf0e10cSrcweir 								const SfxItemSet& rAttrSet)
206*cdf0e10cSrcweir {
207*cdf0e10cSrcweir 	return new SvxFontSubstTabPage(pParent, rAttrSet);
208*cdf0e10cSrcweir }
209*cdf0e10cSrcweir 
210*cdf0e10cSrcweir /*********************************************************************/
211*cdf0e10cSrcweir /*                                                                   */
212*cdf0e10cSrcweir /*********************************************************************/
213*cdf0e10cSrcweir 
214*cdf0e10cSrcweir sal_Bool  SvxFontSubstTabPage::FillItemSet( SfxItemSet& )
215*cdf0e10cSrcweir {
216*cdf0e10cSrcweir 	pConfig->ClearSubstitutions();// remove all entries
217*cdf0e10cSrcweir 
218*cdf0e10cSrcweir 	pConfig->Enable(aUseTableCB.IsChecked());
219*cdf0e10cSrcweir 
220*cdf0e10cSrcweir 	SvLBoxEntry* pEntry = aCheckLB.First();
221*cdf0e10cSrcweir 
222*cdf0e10cSrcweir 	while (pEntry)
223*cdf0e10cSrcweir 	{
224*cdf0e10cSrcweir 		SubstitutionStruct aAdd;
225*cdf0e10cSrcweir         aAdd.sFont = aCheckLB.GetEntryText(pEntry, 0);
226*cdf0e10cSrcweir         aAdd.sReplaceBy = aCheckLB.GetEntryText(pEntry, 1);
227*cdf0e10cSrcweir 		aAdd.bReplaceAlways = aCheckLB.IsChecked(pEntry, 0);
228*cdf0e10cSrcweir 		aAdd.bReplaceOnScreenOnly = aCheckLB.IsChecked(pEntry, 1);
229*cdf0e10cSrcweir 		pConfig->AddSubstitution(aAdd);
230*cdf0e10cSrcweir 		pEntry = aCheckLB.Next(pEntry);
231*cdf0e10cSrcweir 	}
232*cdf0e10cSrcweir 	if(pConfig->IsModified())
233*cdf0e10cSrcweir 		pConfig->Commit();
234*cdf0e10cSrcweir 	pConfig->Apply();
235*cdf0e10cSrcweir     if(aFontHeightLB.GetSavedValue() != aFontHeightLB.GetSelectEntryPos())
236*cdf0e10cSrcweir         pSourceViewConfig->SetFontHeight((sal_Int16)aFontHeightLB.GetSelectEntry().ToInt32());
237*cdf0e10cSrcweir     if(aNonPropFontsOnlyCB.GetSavedValue() != aNonPropFontsOnlyCB.IsChecked())
238*cdf0e10cSrcweir         pSourceViewConfig->SetShowProportionalFontsOnly(aNonPropFontsOnlyCB.IsChecked());
239*cdf0e10cSrcweir     //font name changes cannot be detected by saved values
240*cdf0e10cSrcweir     String sFontName;
241*cdf0e10cSrcweir     if(aFontNameLB.GetSelectEntryPos())
242*cdf0e10cSrcweir         sFontName = aFontNameLB.GetSelectEntry();
243*cdf0e10cSrcweir     pSourceViewConfig->SetFontName(sFontName);
244*cdf0e10cSrcweir 
245*cdf0e10cSrcweir 	return sal_False;
246*cdf0e10cSrcweir }
247*cdf0e10cSrcweir 
248*cdf0e10cSrcweir /*********************************************************************/
249*cdf0e10cSrcweir /*                                                                   */
250*cdf0e10cSrcweir /*********************************************************************/
251*cdf0e10cSrcweir 
252*cdf0e10cSrcweir 
253*cdf0e10cSrcweir void  SvxFontSubstTabPage::Reset( const SfxItemSet& )
254*cdf0e10cSrcweir {
255*cdf0e10cSrcweir 	aCheckLB.SetUpdateMode(sal_False);
256*cdf0e10cSrcweir 	aCheckLB.Clear();
257*cdf0e10cSrcweir 
258*cdf0e10cSrcweir 	FontList aFntLst( Application::GetDefaultDevice() );
259*cdf0e10cSrcweir 	aFont1CB.Fill( &aFntLst );
260*cdf0e10cSrcweir 	aFont2CB.Fill( &aFntLst );
261*cdf0e10cSrcweir 
262*cdf0e10cSrcweir 	sal_Int32 nCount = pConfig->SubstitutionCount();
263*cdf0e10cSrcweir 	if (nCount)
264*cdf0e10cSrcweir 		aUseTableCB.Check(pConfig->IsEnabled());
265*cdf0e10cSrcweir 
266*cdf0e10cSrcweir 	for (sal_Int32  i = 0; i < nCount; i++)
267*cdf0e10cSrcweir 	{
268*cdf0e10cSrcweir 		const SubstitutionStruct* pSubs = pConfig->GetSubstitution(i);
269*cdf0e10cSrcweir 		String aTmpStr1(pSubs->sFont);
270*cdf0e10cSrcweir         String aTmpStr2(pSubs->sReplaceBy);
271*cdf0e10cSrcweir         SvLBoxEntry* pEntry = CreateEntry(aTmpStr1, aTmpStr2);
272*cdf0e10cSrcweir         aCheckLB.Insert(pEntry);
273*cdf0e10cSrcweir 		aCheckLB.CheckEntry(pEntry, 0, pSubs->bReplaceAlways);
274*cdf0e10cSrcweir 		aCheckLB.CheckEntry(pEntry, 1, pSubs->bReplaceOnScreenOnly);
275*cdf0e10cSrcweir 	}
276*cdf0e10cSrcweir 
277*cdf0e10cSrcweir 	CheckEnable();
278*cdf0e10cSrcweir 	aCheckLB.SetUpdateMode(sal_True);
279*cdf0e10cSrcweir 
280*cdf0e10cSrcweir     //fill font name box first
281*cdf0e10cSrcweir     aNonPropFontsOnlyCB.Check(pSourceViewConfig->IsShowProportionalFontsOnly());
282*cdf0e10cSrcweir     NonPropFontsHdl(&aNonPropFontsOnlyCB);
283*cdf0e10cSrcweir     String sFontName(pSourceViewConfig->GetFontName());
284*cdf0e10cSrcweir     if(sFontName.Len())
285*cdf0e10cSrcweir         aFontNameLB.SelectEntry(sFontName);
286*cdf0e10cSrcweir     else
287*cdf0e10cSrcweir         aFontNameLB.SelectEntryPos(0);
288*cdf0e10cSrcweir     short nFontHeight = pSourceViewConfig->GetFontHeight();
289*cdf0e10cSrcweir     aFontHeightLB.SelectEntry(String::CreateFromInt32(nFontHeight));
290*cdf0e10cSrcweir     aNonPropFontsOnlyCB.SaveValue();
291*cdf0e10cSrcweir     aFontHeightLB.SaveValue();
292*cdf0e10cSrcweir }
293*cdf0e10cSrcweir 
294*cdf0e10cSrcweir /*********************************************************************/
295*cdf0e10cSrcweir /*                                                                   */
296*cdf0e10cSrcweir /*********************************************************************/
297*cdf0e10cSrcweir 
298*cdf0e10cSrcweir IMPL_LINK(SvxFontSubstTabPage, SelectHdl, Window*, pWin)
299*cdf0e10cSrcweir {
300*cdf0e10cSrcweir 	if (pWin == &aNewDelTBX)
301*cdf0e10cSrcweir 	{
302*cdf0e10cSrcweir 		SvLBoxEntry* pEntry;
303*cdf0e10cSrcweir 		// nCol ist behaemmerterweise die nCol'te Textspalte, werden nicht gezaehlt!
304*cdf0e10cSrcweir 		// Daher als Spalte "0".
305*cdf0e10cSrcweir 		sal_uLong nPos = aCheckLB.GetEntryPos(aFont1CB.GetText(), 0);
306*cdf0e10cSrcweir 
307*cdf0e10cSrcweir 		switch (aNewDelTBX.GetCurItemId())
308*cdf0e10cSrcweir 		{
309*cdf0e10cSrcweir 			case BT_SUBSTAPPLY:
310*cdf0e10cSrcweir 			{
311*cdf0e10cSrcweir 				if (nPos != 0xffffffff)
312*cdf0e10cSrcweir 				{
313*cdf0e10cSrcweir 					// Eintrag aendern
314*cdf0e10cSrcweir 					aCheckLB.SetEntryText(aFont2CB.GetText(), nPos, 1);
315*cdf0e10cSrcweir 					pEntry = aCheckLB.GetEntry(nPos);
316*cdf0e10cSrcweir 				}
317*cdf0e10cSrcweir 				else
318*cdf0e10cSrcweir 				{
319*cdf0e10cSrcweir 					// Neuer Eintrag
320*cdf0e10cSrcweir 					String sFont1 = aFont1CB.GetText();
321*cdf0e10cSrcweir 					String sFont2 = aFont2CB.GetText();
322*cdf0e10cSrcweir 
323*cdf0e10cSrcweir 					pEntry = CreateEntry(sFont1, sFont2);
324*cdf0e10cSrcweir                     aCheckLB.Insert(pEntry);
325*cdf0e10cSrcweir 				}
326*cdf0e10cSrcweir 				aCheckLB.SelectAll(sal_False);
327*cdf0e10cSrcweir 				aCheckLB.Select(pEntry);
328*cdf0e10cSrcweir 			}
329*cdf0e10cSrcweir 			break;
330*cdf0e10cSrcweir 
331*cdf0e10cSrcweir 			case BT_SUBSTDELETE:
332*cdf0e10cSrcweir 			{
333*cdf0e10cSrcweir 				if (nPos != 0xffffffff)
334*cdf0e10cSrcweir 				{
335*cdf0e10cSrcweir 					pEntry = aCheckLB.FirstSelected();
336*cdf0e10cSrcweir 					while (pEntry)
337*cdf0e10cSrcweir 					{
338*cdf0e10cSrcweir 						SvLBoxEntry* pDelEntry = pEntry;
339*cdf0e10cSrcweir 						pEntry = aCheckLB.NextSelected(pEntry);
340*cdf0e10cSrcweir                         aCheckLB.RemoveEntry(pDelEntry);
341*cdf0e10cSrcweir 					}
342*cdf0e10cSrcweir 				}
343*cdf0e10cSrcweir 			}
344*cdf0e10cSrcweir 			break;
345*cdf0e10cSrcweir 		}
346*cdf0e10cSrcweir 	}
347*cdf0e10cSrcweir 
348*cdf0e10cSrcweir 	if (pWin == &aCheckLB)
349*cdf0e10cSrcweir 	{
350*cdf0e10cSrcweir 		SvLBoxEntry* pEntry = aCheckLB.FirstSelected();
351*cdf0e10cSrcweir 
352*cdf0e10cSrcweir 		if (aCheckLB.NextSelected(pEntry) == 0)
353*cdf0e10cSrcweir 		{
354*cdf0e10cSrcweir             aFont1CB.SetText(aCheckLB.GetEntryText(pEntry, 0));
355*cdf0e10cSrcweir             aFont2CB.SetText(aCheckLB.GetEntryText(pEntry, 1));
356*cdf0e10cSrcweir 		}
357*cdf0e10cSrcweir 	}
358*cdf0e10cSrcweir 
359*cdf0e10cSrcweir 	if (pWin == &aFont1CB)
360*cdf0e10cSrcweir 	{
361*cdf0e10cSrcweir 		sal_uLong nPos = aCheckLB.GetEntryPos(aFont1CB.GetText(), 0);
362*cdf0e10cSrcweir 
363*cdf0e10cSrcweir 		if (nPos != 0xffffffff)
364*cdf0e10cSrcweir 		{
365*cdf0e10cSrcweir 			SvLBoxEntry* pEntry = aCheckLB.GetEntry(nPos);
366*cdf0e10cSrcweir 
367*cdf0e10cSrcweir 			if (pEntry != aCheckLB.FirstSelected())
368*cdf0e10cSrcweir 			{
369*cdf0e10cSrcweir 				aCheckLB.SelectAll(sal_False);
370*cdf0e10cSrcweir 				aCheckLB.Select(pEntry);
371*cdf0e10cSrcweir 			}
372*cdf0e10cSrcweir 		}
373*cdf0e10cSrcweir 	}
374*cdf0e10cSrcweir 
375*cdf0e10cSrcweir 	CheckEnable();
376*cdf0e10cSrcweir 
377*cdf0e10cSrcweir 	return 0;
378*cdf0e10cSrcweir }
379*cdf0e10cSrcweir /* -----------------------------29.08.2002 11:47------------------------------
380*cdf0e10cSrcweir 
381*cdf0e10cSrcweir  ---------------------------------------------------------------------------*/
382*cdf0e10cSrcweir IMPL_LINK(SvxFontSubstTabPage, NonPropFontsHdl, CheckBox*, pBox)
383*cdf0e10cSrcweir {
384*cdf0e10cSrcweir     String sFontName = aFontNameLB.GetSelectEntry();
385*cdf0e10cSrcweir     sal_Bool bNonPropOnly = pBox->IsChecked();
386*cdf0e10cSrcweir     aFontNameLB.Clear();
387*cdf0e10cSrcweir     FontList aFntLst( Application::GetDefaultDevice() );
388*cdf0e10cSrcweir     aFontNameLB.InsertEntry(sAutomatic);
389*cdf0e10cSrcweir     sal_uInt16 nFontCount = aFntLst.GetFontNameCount();
390*cdf0e10cSrcweir     for(sal_uInt16 nFont = 0; nFont < nFontCount; nFont++)
391*cdf0e10cSrcweir     {
392*cdf0e10cSrcweir         const FontInfo& rInfo = aFntLst.GetFontName( nFont );
393*cdf0e10cSrcweir         if(!bNonPropOnly || rInfo.GetPitch() == PITCH_FIXED)
394*cdf0e10cSrcweir             aFontNameLB.InsertEntry(rInfo.GetName());
395*cdf0e10cSrcweir     }
396*cdf0e10cSrcweir     aFontNameLB.SelectEntry(sFontName);
397*cdf0e10cSrcweir     return 0;
398*cdf0e10cSrcweir }
399*cdf0e10cSrcweir /*********************************************************************/
400*cdf0e10cSrcweir /*                                                                   */
401*cdf0e10cSrcweir /*********************************************************************/
402*cdf0e10cSrcweir 
403*cdf0e10cSrcweir void SvxFontSubstTabPage::CheckEnable()
404*cdf0e10cSrcweir {
405*cdf0e10cSrcweir 	sal_Bool bEnableAll = aUseTableCB.IsChecked();
406*cdf0e10cSrcweir 
407*cdf0e10cSrcweir 	if (bEnableAll)
408*cdf0e10cSrcweir 	{
409*cdf0e10cSrcweir 		sal_Bool bApply, bDelete;
410*cdf0e10cSrcweir 
411*cdf0e10cSrcweir 		SvLBoxEntry* pEntry = aCheckLB.FirstSelected();
412*cdf0e10cSrcweir 
413*cdf0e10cSrcweir 		String sEntry = aFont1CB.GetText();
414*cdf0e10cSrcweir 		sEntry += '\t';
415*cdf0e10cSrcweir 		sEntry += aFont2CB.GetText();
416*cdf0e10cSrcweir 
417*cdf0e10cSrcweir /*		if (!aFont1CB.GetText().Len() || !aFont2CB.GetText().Len() ||
418*cdf0e10cSrcweir 			aFont1CB.GetText() == aFont2CB.GetText() ||
419*cdf0e10cSrcweir 			aCheckLB.GetEntryPos(sEntry) != 0xffffffff ||
420*cdf0e10cSrcweir 			(pEntry != 0 && aCheckLB.NextSelected(pEntry) != 0))
421*cdf0e10cSrcweir 			bApply = sal_False;
422*cdf0e10cSrcweir 		else
423*cdf0e10cSrcweir 			bApply = sal_True;*/
424*cdf0e10cSrcweir 
425*cdf0e10cSrcweir 		// Wegen OS/2-Optimierungsfehler (Bug #56267) etwas umstaendlicher:
426*cdf0e10cSrcweir 		if (!aFont1CB.GetText().Len() || !aFont2CB.GetText().Len())
427*cdf0e10cSrcweir 			bApply = sal_False;
428*cdf0e10cSrcweir 		else if(aFont1CB.GetText() == aFont2CB.GetText())
429*cdf0e10cSrcweir 			bApply = sal_False;
430*cdf0e10cSrcweir 		else if(aCheckLB.GetEntryPos(sEntry) != 0xffffffff)
431*cdf0e10cSrcweir 			bApply = sal_False;
432*cdf0e10cSrcweir 		else if(pEntry != 0 && aCheckLB.NextSelected(pEntry) != 0)
433*cdf0e10cSrcweir 			bApply = sal_False;
434*cdf0e10cSrcweir 		else
435*cdf0e10cSrcweir 			bApply = sal_True;
436*cdf0e10cSrcweir 
437*cdf0e10cSrcweir 		bDelete = pEntry != 0;
438*cdf0e10cSrcweir 
439*cdf0e10cSrcweir 		aNewDelTBX.EnableItem(BT_SUBSTAPPLY, bApply);
440*cdf0e10cSrcweir 		aNewDelTBX.EnableItem(BT_SUBSTDELETE, bDelete);
441*cdf0e10cSrcweir 	}
442*cdf0e10cSrcweir 
443*cdf0e10cSrcweir 	if (bEnableAll)
444*cdf0e10cSrcweir 	{
445*cdf0e10cSrcweir 		if (!aCheckLB.IsEnabled())
446*cdf0e10cSrcweir 		{
447*cdf0e10cSrcweir             aCheckLB.EnableTable();
448*cdf0e10cSrcweir 			aCheckLB.SetTextColor(aTextColor);
449*cdf0e10cSrcweir 			aCheckLB.Invalidate();
450*cdf0e10cSrcweir 			SelectHdl(&aFont1CB);
451*cdf0e10cSrcweir 		}
452*cdf0e10cSrcweir 	}
453*cdf0e10cSrcweir 	else
454*cdf0e10cSrcweir 	{
455*cdf0e10cSrcweir         if (aCheckLB.IsEnabled())
456*cdf0e10cSrcweir 		{
457*cdf0e10cSrcweir             aCheckLB.DisableTable();
458*cdf0e10cSrcweir 			aCheckLB.SetTextColor(Color(COL_GRAY));
459*cdf0e10cSrcweir 			aCheckLB.Invalidate();
460*cdf0e10cSrcweir 			aCheckLB.SelectAll(sal_False);
461*cdf0e10cSrcweir 		}
462*cdf0e10cSrcweir 	}
463*cdf0e10cSrcweir 	aNewDelTBX.Enable(bEnableAll);
464*cdf0e10cSrcweir 	aFont1FT.Enable(bEnableAll);
465*cdf0e10cSrcweir 	aFont1CB.Enable(bEnableAll);
466*cdf0e10cSrcweir 	aFont2FT.Enable(bEnableAll);
467*cdf0e10cSrcweir 	aFont2CB.Enable(bEnableAll);
468*cdf0e10cSrcweir }
469*cdf0e10cSrcweir 
470*cdf0e10cSrcweir /*********************************************************************/
471*cdf0e10cSrcweir /*                                                                   */
472*cdf0e10cSrcweir /*********************************************************************/
473*cdf0e10cSrcweir 
474*cdf0e10cSrcweir void SvxFontSubstCheckListBox::SetTabs()
475*cdf0e10cSrcweir {
476*cdf0e10cSrcweir 	SvxSimpleTable::SetTabs();
477*cdf0e10cSrcweir 	sal_uInt16 nAdjust = SV_LBOXTAB_ADJUST_RIGHT|SV_LBOXTAB_ADJUST_LEFT|SV_LBOXTAB_ADJUST_CENTER|SV_LBOXTAB_ADJUST_NUMERIC|SV_LBOXTAB_FORCE;
478*cdf0e10cSrcweir 
479*cdf0e10cSrcweir 	SvLBoxTab* pTab = (SvLBoxTab*)aTabs.GetObject(1);
480*cdf0e10cSrcweir 	pTab->nFlags &= ~nAdjust;
481*cdf0e10cSrcweir 	pTab->nFlags |= SV_LBOXTAB_PUSHABLE|SV_LBOXTAB_ADJUST_CENTER|SV_LBOXTAB_FORCE;
482*cdf0e10cSrcweir 
483*cdf0e10cSrcweir 	pTab = (SvLBoxTab*)aTabs.GetObject(2);
484*cdf0e10cSrcweir 	pTab->nFlags &= ~nAdjust;
485*cdf0e10cSrcweir 	pTab->nFlags |= SV_LBOXTAB_PUSHABLE|SV_LBOXTAB_ADJUST_CENTER|SV_LBOXTAB_FORCE;
486*cdf0e10cSrcweir }
487*cdf0e10cSrcweir /* -----------------------------22.05.2002 11:06------------------------------
488*cdf0e10cSrcweir 
489*cdf0e10cSrcweir  ---------------------------------------------------------------------------*/
490*cdf0e10cSrcweir void    SvxFontSubstCheckListBox::KeyInput( const KeyEvent& rKEvt )
491*cdf0e10cSrcweir {
492*cdf0e10cSrcweir     if(!rKEvt.GetKeyCode().GetModifier() &&
493*cdf0e10cSrcweir         KEY_SPACE == rKEvt.GetKeyCode().GetCode())
494*cdf0e10cSrcweir     {
495*cdf0e10cSrcweir         sal_uLong nSelPos = GetModel()->GetAbsPos(GetCurEntry());
496*cdf0e10cSrcweir         sal_uInt16 nCol = GetCurrentTabPos() - 1;
497*cdf0e10cSrcweir         if ( nCol < 2 )
498*cdf0e10cSrcweir         {
499*cdf0e10cSrcweir             CheckEntryPos( nSelPos, nCol, !IsChecked( nSelPos, nCol ) );
500*cdf0e10cSrcweir             CallImplEventListeners( VCLEVENT_CHECKBOX_TOGGLE, (void*)GetEntry( nSelPos ) );
501*cdf0e10cSrcweir         }
502*cdf0e10cSrcweir         else
503*cdf0e10cSrcweir         {
504*cdf0e10cSrcweir             sal_uInt16 nCheck = IsChecked(nSelPos, 1) ? 1 : 0;
505*cdf0e10cSrcweir             if(IsChecked(nSelPos, 0))
506*cdf0e10cSrcweir                 nCheck += 2;
507*cdf0e10cSrcweir             nCheck--;
508*cdf0e10cSrcweir             nCheck &= 3;
509*cdf0e10cSrcweir             CheckEntryPos(nSelPos, 1, 0 != (nCheck & 1));
510*cdf0e10cSrcweir             CheckEntryPos(nSelPos, 0, 0 != (nCheck & 2));
511*cdf0e10cSrcweir         }
512*cdf0e10cSrcweir     }
513*cdf0e10cSrcweir     else
514*cdf0e10cSrcweir         SvxSimpleTable::KeyInput(rKEvt);
515*cdf0e10cSrcweir }
516*cdf0e10cSrcweir 
517*cdf0e10cSrcweir /*********************************************************************/
518*cdf0e10cSrcweir /*                                                                   */
519*cdf0e10cSrcweir /*********************************************************************/
520*cdf0e10cSrcweir 
521*cdf0e10cSrcweir void SvxFontSubstCheckListBox::CheckEntryPos(sal_uLong nPos, sal_uInt16 nCol, sal_Bool bChecked)
522*cdf0e10cSrcweir {
523*cdf0e10cSrcweir 	if ( nPos < GetEntryCount() )
524*cdf0e10cSrcweir 		SetCheckButtonState(
525*cdf0e10cSrcweir 			GetEntry(nPos),
526*cdf0e10cSrcweir 			nCol,
527*cdf0e10cSrcweir 			bChecked ? SvButtonState( SV_BUTTON_CHECKED ) :
528*cdf0e10cSrcweir 									   SvButtonState( SV_BUTTON_UNCHECKED ) );
529*cdf0e10cSrcweir }
530*cdf0e10cSrcweir 
531*cdf0e10cSrcweir /*********************************************************************/
532*cdf0e10cSrcweir /*                                                                   */
533*cdf0e10cSrcweir /*********************************************************************/
534*cdf0e10cSrcweir 
535*cdf0e10cSrcweir void SvxFontSubstCheckListBox::CheckEntry(SvLBoxEntry* pEntry, sal_uInt16 nCol, sal_Bool bChecked)
536*cdf0e10cSrcweir {
537*cdf0e10cSrcweir 	if ( pEntry )
538*cdf0e10cSrcweir 		SetCheckButtonState(
539*cdf0e10cSrcweir 			pEntry,
540*cdf0e10cSrcweir 			nCol,
541*cdf0e10cSrcweir 			bChecked ? SvButtonState( SV_BUTTON_CHECKED ) :
542*cdf0e10cSrcweir 									   SvButtonState( SV_BUTTON_UNCHECKED ) );
543*cdf0e10cSrcweir }
544*cdf0e10cSrcweir 
545*cdf0e10cSrcweir /*********************************************************************/
546*cdf0e10cSrcweir /*                                                                   */
547*cdf0e10cSrcweir /*********************************************************************/
548*cdf0e10cSrcweir 
549*cdf0e10cSrcweir sal_Bool SvxFontSubstCheckListBox::IsChecked(sal_uLong nPos, sal_uInt16 nCol)
550*cdf0e10cSrcweir {
551*cdf0e10cSrcweir 	return GetCheckButtonState( GetEntry(nPos), nCol ) == SV_BUTTON_CHECKED;
552*cdf0e10cSrcweir }
553*cdf0e10cSrcweir 
554*cdf0e10cSrcweir /*********************************************************************/
555*cdf0e10cSrcweir /*                                                                   */
556*cdf0e10cSrcweir /*********************************************************************/
557*cdf0e10cSrcweir 
558*cdf0e10cSrcweir sal_Bool SvxFontSubstCheckListBox::IsChecked(SvLBoxEntry* pEntry, sal_uInt16 nCol)
559*cdf0e10cSrcweir {
560*cdf0e10cSrcweir 	return GetCheckButtonState( pEntry, nCol ) == SV_BUTTON_CHECKED;
561*cdf0e10cSrcweir }
562*cdf0e10cSrcweir 
563*cdf0e10cSrcweir /*********************************************************************/
564*cdf0e10cSrcweir /*                                                                   */
565*cdf0e10cSrcweir /*********************************************************************/
566*cdf0e10cSrcweir 
567*cdf0e10cSrcweir void SvxFontSubstCheckListBox::SetCheckButtonState( SvLBoxEntry* pEntry, sal_uInt16 nCol, SvButtonState eState)
568*cdf0e10cSrcweir {
569*cdf0e10cSrcweir 	SvLBoxButton* pItem = (SvLBoxButton*)(pEntry->GetItem(nCol + 1));
570*cdf0e10cSrcweir 
571*cdf0e10cSrcweir 	DBG_ASSERT(pItem,"SetCheckButton:Item not found");
572*cdf0e10cSrcweir 	if (((SvLBoxItem*)pItem)->IsA() == SV_ITEM_ID_LBOXBUTTON)
573*cdf0e10cSrcweir 	{
574*cdf0e10cSrcweir 		switch( eState )
575*cdf0e10cSrcweir 		{
576*cdf0e10cSrcweir 			case SV_BUTTON_CHECKED:
577*cdf0e10cSrcweir 				pItem->SetStateChecked();
578*cdf0e10cSrcweir 				break;
579*cdf0e10cSrcweir 
580*cdf0e10cSrcweir 			case SV_BUTTON_UNCHECKED:
581*cdf0e10cSrcweir 				pItem->SetStateUnchecked();
582*cdf0e10cSrcweir 				break;
583*cdf0e10cSrcweir 
584*cdf0e10cSrcweir 			case SV_BUTTON_TRISTATE:
585*cdf0e10cSrcweir 				pItem->SetStateTristate();
586*cdf0e10cSrcweir 				break;
587*cdf0e10cSrcweir 		}
588*cdf0e10cSrcweir 		InvalidateEntry( pEntry );
589*cdf0e10cSrcweir 	}
590*cdf0e10cSrcweir }
591*cdf0e10cSrcweir 
592*cdf0e10cSrcweir /*********************************************************************/
593*cdf0e10cSrcweir /*                                                                   */
594*cdf0e10cSrcweir /*********************************************************************/
595*cdf0e10cSrcweir 
596*cdf0e10cSrcweir SvButtonState SvxFontSubstCheckListBox::GetCheckButtonState( SvLBoxEntry* pEntry, sal_uInt16 nCol ) const
597*cdf0e10cSrcweir {
598*cdf0e10cSrcweir 	SvButtonState eState = SV_BUTTON_UNCHECKED;
599*cdf0e10cSrcweir 	SvLBoxButton* pItem = (SvLBoxButton*)(pEntry->GetItem(nCol + 1));
600*cdf0e10cSrcweir 	DBG_ASSERT(pItem,"GetChButnState:Item not found");
601*cdf0e10cSrcweir 
602*cdf0e10cSrcweir 	if (((SvLBoxItem*)pItem)->IsA() == SV_ITEM_ID_LBOXBUTTON)
603*cdf0e10cSrcweir 	{
604*cdf0e10cSrcweir 		sal_uInt16 nButtonFlags = pItem->GetButtonFlags();
605*cdf0e10cSrcweir 		eState = pCheckButtonData->ConvertToButtonState( nButtonFlags );
606*cdf0e10cSrcweir 	}
607*cdf0e10cSrcweir 
608*cdf0e10cSrcweir 	return eState;
609*cdf0e10cSrcweir }
610*cdf0e10cSrcweir 
611*cdf0e10cSrcweir 
612