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