xref: /aoo42x/main/padmin/source/fontentry.cxx (revision 466d5a0b)
1*466d5a0bSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*466d5a0bSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*466d5a0bSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*466d5a0bSAndrew Rist  * distributed with this work for additional information
6*466d5a0bSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*466d5a0bSAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*466d5a0bSAndrew Rist  * "License"); you may not use this file except in compliance
9*466d5a0bSAndrew Rist  * with the License.  You may obtain a copy of the License at
10*466d5a0bSAndrew Rist  *
11*466d5a0bSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*466d5a0bSAndrew Rist  *
13*466d5a0bSAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*466d5a0bSAndrew Rist  * software distributed under the License is distributed on an
15*466d5a0bSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*466d5a0bSAndrew Rist  * KIND, either express or implied.  See the License for the
17*466d5a0bSAndrew Rist  * specific language governing permissions and limitations
18*466d5a0bSAndrew Rist  * under the License.
19*466d5a0bSAndrew Rist  *
20*466d5a0bSAndrew Rist  *************************************************************/
21*466d5a0bSAndrew Rist 
22*466d5a0bSAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir #include "fontentry.hxx"
25cdf0e10cSrcweir #include "helper.hxx"
26cdf0e10cSrcweir #include "padialog.hrc"
27cdf0e10cSrcweir #include "vcl/strhelper.hxx"
28cdf0e10cSrcweir 
29cdf0e10cSrcweir #include "vcl/msgbox.hxx"
30cdf0e10cSrcweir #include "vcl/fontmanager.hxx"
31cdf0e10cSrcweir 
32cdf0e10cSrcweir #include "osl/thread.h"
33cdf0e10cSrcweir 
34cdf0e10cSrcweir #include "tools/config.hxx"
35cdf0e10cSrcweir 
36cdf0e10cSrcweir using namespace padmin;
37cdf0e10cSrcweir using namespace osl;
38cdf0e10cSrcweir using namespace rtl;
39cdf0e10cSrcweir using namespace psp;
40cdf0e10cSrcweir 
41cdf0e10cSrcweir #if 0
42cdf0e10cSrcweir static void CreateAfmFile( const INetURLObject& rFontFile )
43cdf0e10cSrcweir {
44cdf0e10cSrcweir 	rtl_TextEncoding aEncoding = gsl_getSystemTextEncoding();
45cdf0e10cSrcweir 
46cdf0e10cSrcweir 	INetURLObject aFontMap( rFontFile.GetPath(), INET_PROT_FILE, INetURLObject::ENCODE_ALL );
47cdf0e10cSrcweir 	aFontMap.Append( String( RTL_CONSTASCII_USTRINGPARAM( "Fontmap" ) ) );
48cdf0e10cSrcweir 	INetURLObject aAfmFile( rFontFile );
49cdf0e10cSrcweir 	aAfmFile.setExtension( String::CreateFromAscii( "afm", 3 ) );
50cdf0e10cSrcweir 
51cdf0e10cSrcweir 
52cdf0e10cSrcweir 	SvFileStream aMap( aFontMap.PathToFileName(), STREAM_WRITE | STREAM_TRUNC );
53cdf0e10cSrcweir 	if( aMap.IsOpen() )
54cdf0e10cSrcweir 	{
55cdf0e10cSrcweir 		SvFileStream aRead( rFontFile.GetFull(), STREAM_READ );
56cdf0e10cSrcweir 		ByteString aLine;
57cdf0e10cSrcweir 		ByteString aFullName;
58cdf0e10cSrcweir 		int nPos;
59cdf0e10cSrcweir 		while( ! aRead.IsEof() &&
60cdf0e10cSrcweir 			   ( nPos = aLine.Search( "/FullName" ) ) == STRING_NOTFOUND )
61cdf0e10cSrcweir 			aRead.ReadLine( aLine );
62cdf0e10cSrcweir 		aRead.Close();
63cdf0e10cSrcweir 		if( nPos != STRING_NOTFOUND )
64cdf0e10cSrcweir 		{
65cdf0e10cSrcweir 			aLine.Erase( 0, nPos );
66cdf0e10cSrcweir 			aFullName = aLine.GetToken( 1, '(' ).GetToken( 0, ')' );
67cdf0e10cSrcweir 
68cdf0e10cSrcweir 			aLine = '/';
69cdf0e10cSrcweir 			aLine += aFullName;
70cdf0e10cSrcweir 			aLine += ' ';
71cdf0e10cSrcweir 			aLine += '(';
72cdf0e10cSrcweir 			aLine += ByteString( rFontFile.GetName(), aEncoding );
73cdf0e10cSrcweir 			aLine += ')';
74cdf0e10cSrcweir 			aLine += ';';
75cdf0e10cSrcweir 
76cdf0e10cSrcweir 			aMap.WriteLine( aLine );
77cdf0e10cSrcweir 		}
78cdf0e10cSrcweir 		aMap.Close();
79cdf0e10cSrcweir 		pid_t nPID = fork();
80cdf0e10cSrcweir 		if( ! nPID )
81cdf0e10cSrcweir 		{
82cdf0e10cSrcweir 			INetURLObject aTmp( rFontFile );
83cdf0e10cSrcweir 			aTmp.CutName();
84cdf0e10cSrcweir 			ByteString aEnv( "GS_LIB=" );
85cdf0e10cSrcweir 			aEnv += ByteString( aTmp.PathToFileName(), aEncoding );
86cdf0e10cSrcweir 			putenv( const_cast<char*>(aEnv.GetBuffer()) );
87cdf0e10cSrcweir 
88cdf0e10cSrcweir 			int nDescr = open( ByteString( aAfmFile.PathToFileName(), aEncoding ).GetBuffer(),
89cdf0e10cSrcweir 							   O_CREAT | O_TRUNC| O_WRONLY,
90cdf0e10cSrcweir 							   00755 );
91cdf0e10cSrcweir #if OSL_DEBUG_LEVEL > 1
92cdf0e10cSrcweir 			if( nDescr < 0 )
93cdf0e10cSrcweir 				fprintf( stderr, "open( %s ) failed because of %d\n", ByteString( aAfmFile.GetFull(), aEncoding ).GetBuffer(), errno );
94cdf0e10cSrcweir #endif
95cdf0e10cSrcweir 			if( dup2( nDescr, STDOUT_FILENO ) > 0 )
96cdf0e10cSrcweir 			{
97cdf0e10cSrcweir 				execlp( "gs",
98cdf0e10cSrcweir 						"-q",
99cdf0e10cSrcweir 						"-dNODISPLAY",
100cdf0e10cSrcweir 						"--", "printafm.ps",
101cdf0e10cSrcweir 						aFullName.GetBuffer(),
102cdf0e10cSrcweir 						NULL );
103cdf0e10cSrcweir 			}
104cdf0e10cSrcweir #if OSL_DEBUG_LEVEL > 1
105cdf0e10cSrcweir 			else
106cdf0e10cSrcweir 				fprintf( stderr, "dup2( %d, %d ) failed because of %d\n", nDescr, STDOUT_FILENO, errno );
107cdf0e10cSrcweir #endif
108cdf0e10cSrcweir 			_exit( 0 );
109cdf0e10cSrcweir 		}
110cdf0e10cSrcweir 		if( nPID > 0 )
111cdf0e10cSrcweir 			waitpid( nPID, NULL, 0 );
112cdf0e10cSrcweir 		MetricConverter::ConvertAFM( aAfmFile );
113cdf0e10cSrcweir 	}
114cdf0e10cSrcweir 
115cdf0e10cSrcweir 	struct stat aStat;
116cdf0e10cSrcweir 	ByteString aSysFile( aAfmFile.PathToFileName(), aEncoding );
117cdf0e10cSrcweir 	if( stat( aSysFile.GetBuffer(), &aStat ) || ! aStat.st_size )
118cdf0e10cSrcweir 		unlink( aSysFile.GetBuffer() );
119cdf0e10cSrcweir #if OSL_DEBUG_LEVEL > 1
120cdf0e10cSrcweir 	fprintf( stderr, " %s\n", ! access( aSysFile.GetBuffer(), F_OK ) ? "success" : "failed" );
121cdf0e10cSrcweir #endif
122cdf0e10cSrcweir 	unlink( ByteString( aFontMap.PathToFileName(), aEncoding ).GetBuffer() );
123cdf0e10cSrcweir }
124cdf0e10cSrcweir 
125cdf0e10cSrcweir #endif
126cdf0e10cSrcweir 
FontNameDlg(Window * pParent)127cdf0e10cSrcweir FontNameDlg::FontNameDlg( Window *pParent ) :
128cdf0e10cSrcweir 		ModalDialog( pParent, PaResId( RID_FONTNAMEDIALOG ) ),
129cdf0e10cSrcweir 		m_aOKButton( this, PaResId( RID_FNTNM_BTN_OK ) ),
130cdf0e10cSrcweir         m_aRenameButton( this, PaResId( RID_FNTNM_BTN_RENAME ) ),
131cdf0e10cSrcweir 		m_aRemoveButton( this, PaResId( RID_FNTNM_BTN_REMOVE ) ),
132cdf0e10cSrcweir         m_aImportButton( this, PaResId( RID_FNTNM_BTN_IMPORT ) ),
133cdf0e10cSrcweir 		m_aFontBox( this, PaResId( RID_FNTNM_LB_FONTS ) ),
134cdf0e10cSrcweir 		m_aFixedText( this, PaResId( RID_FNTNM_FIXED ) ),
135cdf0e10cSrcweir         m_aRenameString( PaResId( RID_FNTNM_STR_RENAME ) ),
136cdf0e10cSrcweir         m_aRenameTTCString( PaResId( RID_FNTNM_STR_TTCRENAME ) ),
137cdf0e10cSrcweir         m_aNoRenameString( PaResId( RID_FNTNM_STR_NOTRENAMABLE ) ),
138cdf0e10cSrcweir 		m_rFontManager( PrintFontManager::get() )
139cdf0e10cSrcweir {
140cdf0e10cSrcweir 	FreeResource();
141cdf0e10cSrcweir 
142cdf0e10cSrcweir 	m_aFontBox.EnableMultiSelection( sal_True );
143cdf0e10cSrcweir 
144cdf0e10cSrcweir 	m_aOKButton.SetClickHdl( LINK( this, FontNameDlg, ClickBtnHdl ) );
145cdf0e10cSrcweir     m_aRenameButton.SetClickHdl( LINK( this, FontNameDlg, ClickBtnHdl ) );
146cdf0e10cSrcweir 	m_aRemoveButton.SetClickHdl( LINK( this, FontNameDlg, ClickBtnHdl ) );
147cdf0e10cSrcweir     m_aImportButton.SetClickHdl( LINK( this, FontNameDlg, ClickBtnHdl ) );
148cdf0e10cSrcweir 	m_aFontBox.setDelPressedLink( LINK( this, FontNameDlg, DelPressedHdl ) );
149cdf0e10cSrcweir     m_aFontBox.SetSelectHdl( LINK( this, FontNameDlg, SelectHdl ) );
150cdf0e10cSrcweir 
151cdf0e10cSrcweir     init();
152cdf0e10cSrcweir }
153cdf0e10cSrcweir 
~FontNameDlg()154cdf0e10cSrcweir FontNameDlg::~FontNameDlg()
155cdf0e10cSrcweir {
156cdf0e10cSrcweir }
157cdf0e10cSrcweir 
fillFontEntry(FastPrintFontInfo & rInfo,const String & rFile,bool bAddRegular)158cdf0e10cSrcweir String FontNameDlg::fillFontEntry( FastPrintFontInfo& rInfo, const String& rFile, bool bAddRegular )
159cdf0e10cSrcweir {
160cdf0e10cSrcweir     static String aThinTxt( PaResId( RID_TXT_FONT_THIN ) );
161cdf0e10cSrcweir     static String aUltraLightTxt( PaResId( RID_TXT_FONT_ULTRALIGHT ) );
162cdf0e10cSrcweir     static String aLightTxt( PaResId( RID_TXT_FONT_LIGHT ) );
163cdf0e10cSrcweir     static String aSemiLightTxt( PaResId( RID_TXT_FONT_SEMILIGHT ) );
164cdf0e10cSrcweir     static String aSemiBoldTxt( PaResId( RID_TXT_FONT_SEMIBOLD ) );
165cdf0e10cSrcweir     static String aBoldTxt( PaResId( RID_TXT_FONT_BOLD ) );
166cdf0e10cSrcweir     static String aUltraBoldTxt( PaResId( RID_TXT_FONT_ULTRABOLD ) );
167cdf0e10cSrcweir 
168cdf0e10cSrcweir     static String aItalicTxt( PaResId( RID_TXT_FONT_ITALIC ) );
169cdf0e10cSrcweir     static String aObliqueTxt( PaResId( RID_TXT_FONT_OBLIQUE ) );
170cdf0e10cSrcweir 
171cdf0e10cSrcweir     static String aUltraCondensedTxt( PaResId( RID_TXT_FONT_ULTRACONDENSED ) );
172cdf0e10cSrcweir     static String aExtraCondensedTxt( PaResId( RID_TXT_FONT_EXTRACONDENSED ) );
173cdf0e10cSrcweir     static String aCondensedTxt( PaResId( RID_TXT_FONT_CONDENSED ) );
174cdf0e10cSrcweir     static String aSemiCondensedTxt( PaResId( RID_TXT_FONT_SEMICONDENSED ) );
175cdf0e10cSrcweir     static String aSemiExpandedTxt( PaResId( RID_TXT_FONT_SEMIEXPANDED ) );
176cdf0e10cSrcweir     static String aExpandedTxt( PaResId( RID_TXT_FONT_EXPANDED ) );
177cdf0e10cSrcweir     static String aExtraExpandedTxt( PaResId( RID_TXT_FONT_EXTRAEXPANDED ) );
178cdf0e10cSrcweir     static String aUltraExpandedTxt( PaResId( RID_TXT_FONT_ULTRAEXPANDED ) );
179cdf0e10cSrcweir 
180cdf0e10cSrcweir     static String aRegularTxt( PaResId( RID_TXT_FONT_REGULAR ) );
181cdf0e10cSrcweir 
182cdf0e10cSrcweir     String aEntry( rInfo.m_aFamilyName );
183cdf0e10cSrcweir     bool bWeight = true, bItalic = true, bWidth = true;
184cdf0e10cSrcweir     switch( rInfo.m_eWeight )
185cdf0e10cSrcweir     {
186cdf0e10cSrcweir         case weight::Thin:			aEntry.AppendAscii( ", " ); aEntry.Append( aThinTxt ); break;
187cdf0e10cSrcweir         case weight::UltraLight:	aEntry.AppendAscii( ", " ); aEntry.Append( aUltraLightTxt ); break;
188cdf0e10cSrcweir         case weight::Light:			aEntry.AppendAscii( ", " ); aEntry.Append( aLightTxt ); break;
189cdf0e10cSrcweir         case weight::SemiLight:		aEntry.AppendAscii( ", " ); aEntry.Append( aSemiLightTxt ); break;
190cdf0e10cSrcweir         case weight::SemiBold:		aEntry.AppendAscii( ", " ); aEntry.Append( aSemiBoldTxt ); break;
191cdf0e10cSrcweir         case weight::Bold:			aEntry.AppendAscii( ", " ); aEntry.Append( aBoldTxt ); break;
192cdf0e10cSrcweir         case weight::UltraBold:		aEntry.AppendAscii( ", " ); aEntry.Append( aUltraBoldTxt ); break;
193cdf0e10cSrcweir         default:
194cdf0e10cSrcweir             bWeight = false;
195cdf0e10cSrcweir             break;
196cdf0e10cSrcweir     }
197cdf0e10cSrcweir     switch( rInfo.m_eItalic )
198cdf0e10cSrcweir     {
199cdf0e10cSrcweir         case italic::Oblique:		aEntry.AppendAscii( ", " ); aEntry.Append( aObliqueTxt ); break;
200cdf0e10cSrcweir         case italic::Italic:		aEntry.AppendAscii( ", " ); aEntry.Append( aItalicTxt ); break;
201cdf0e10cSrcweir         default:
202cdf0e10cSrcweir             bItalic = false;
203cdf0e10cSrcweir             break;
204cdf0e10cSrcweir     }
205cdf0e10cSrcweir     switch( rInfo.m_eWidth )
206cdf0e10cSrcweir     {
207cdf0e10cSrcweir         case width::UltraCondensed:	aEntry.AppendAscii( ", " ); aEntry.Append( aUltraCondensedTxt ); break;
208cdf0e10cSrcweir         case width::ExtraCondensed:	aEntry.AppendAscii( ", " ); aEntry.Append( aExtraCondensedTxt ); break;
209cdf0e10cSrcweir         case width::Condensed:		aEntry.AppendAscii( ", " ); aEntry.Append( aCondensedTxt ); break;
210cdf0e10cSrcweir         case width::SemiCondensed:	aEntry.AppendAscii( ", " ); aEntry.Append( aSemiCondensedTxt ); break;
211cdf0e10cSrcweir         case width::SemiExpanded:	aEntry.AppendAscii( ", " ); aEntry.Append( aSemiExpandedTxt ); break;
212cdf0e10cSrcweir         case width::Expanded:		aEntry.AppendAscii( ", " ); aEntry.Append( aExpandedTxt ); break;
213cdf0e10cSrcweir         case width::ExtraExpanded:	aEntry.AppendAscii( ", " ); aEntry.Append( aExtraExpandedTxt ); break;
214cdf0e10cSrcweir         case width::UltraExpanded:	aEntry.AppendAscii( ", " ); aEntry.Append( aUltraExpandedTxt ); break;
215cdf0e10cSrcweir         default:
216cdf0e10cSrcweir             bWidth = false;
217cdf0e10cSrcweir             break;
218cdf0e10cSrcweir     }
219cdf0e10cSrcweir 
220cdf0e10cSrcweir     if( bAddRegular && ! bItalic && ! bWidth && ! bWeight )
221cdf0e10cSrcweir     {
222cdf0e10cSrcweir         aEntry.AppendAscii( ", " );
223cdf0e10cSrcweir         aEntry.Append( aRegularTxt );
224cdf0e10cSrcweir     }
225cdf0e10cSrcweir 
226cdf0e10cSrcweir     aEntry.AppendAscii( " (" );
227cdf0e10cSrcweir     aEntry.Append( rFile );
228cdf0e10cSrcweir     aEntry.AppendAscii( ")" );
229cdf0e10cSrcweir     return aEntry;
230cdf0e10cSrcweir }
231cdf0e10cSrcweir 
fillFontEntry(const::std::list<FastPrintFontInfo> & rInfos,const String & rFile)232cdf0e10cSrcweir String FontNameDlg::fillFontEntry( const ::std::list< FastPrintFontInfo >& rInfos, const String& rFile )
233cdf0e10cSrcweir {
234cdf0e10cSrcweir     String aEntry;
235cdf0e10cSrcweir     bool bFirst = true;
236cdf0e10cSrcweir     for( ::std::list< FastPrintFontInfo >::const_iterator it = rInfos.begin(); it != rInfos.end(); ++it )
237cdf0e10cSrcweir     {
238cdf0e10cSrcweir         if( ! bFirst )
239cdf0e10cSrcweir             aEntry.AppendAscii( " & " );
240cdf0e10cSrcweir         aEntry.Append( String( it->m_aFamilyName ) );
241cdf0e10cSrcweir         bFirst = false;
242cdf0e10cSrcweir     }
243cdf0e10cSrcweir 
244cdf0e10cSrcweir     aEntry.AppendAscii( " (" );
245cdf0e10cSrcweir     aEntry.Append( rFile );
246cdf0e10cSrcweir     aEntry.AppendAscii( ")" );
247cdf0e10cSrcweir     return aEntry;
248cdf0e10cSrcweir }
249cdf0e10cSrcweir 
init()250cdf0e10cSrcweir void FontNameDlg::init()
251cdf0e10cSrcweir {
252cdf0e10cSrcweir 	::std::list< fontID > aFonts;
253cdf0e10cSrcweir 	m_rFontManager.getFontList( aFonts );
254cdf0e10cSrcweir     m_aFontBox.Clear();
255cdf0e10cSrcweir     m_aRemoveButton.Enable( sal_False );
256cdf0e10cSrcweir     m_aRenameButton.Enable( sal_False );
257cdf0e10cSrcweir 
258cdf0e10cSrcweir     ::std::hash_map< OUString, int, OUStringHash > aFamilies;
259cdf0e10cSrcweir     ::std::list< fontID >::iterator font_it;
260cdf0e10cSrcweir 	for( font_it = aFonts.begin(); font_it != aFonts.end(); ++font_it )
261cdf0e10cSrcweir 	{
262cdf0e10cSrcweir 		if( m_rFontManager.isPrivateFontFile( *font_it ) )
263cdf0e10cSrcweir 		{
264cdf0e10cSrcweir             const OUString& rFamily( m_rFontManager.getFontFamily( *font_it ) );
265cdf0e10cSrcweir             if( aFamilies.find( rFamily ) == aFamilies.end() )
266cdf0e10cSrcweir                 aFamilies[rFamily] = 0;
267cdf0e10cSrcweir             aFamilies[rFamily]++;
268cdf0e10cSrcweir         }
269cdf0e10cSrcweir     }
270cdf0e10cSrcweir 
271cdf0e10cSrcweir 	for( font_it = aFonts.begin(); font_it != aFonts.end(); ++font_it )
272cdf0e10cSrcweir 	{
273cdf0e10cSrcweir 		if( m_rFontManager.isPrivateFontFile( *font_it ) )
274cdf0e10cSrcweir 		{
275cdf0e10cSrcweir             OString aFile( m_rFontManager.getFontFileSysPath( *font_it ) );
276cdf0e10cSrcweir             int nLast = aFile.lastIndexOf( '/' );
277cdf0e10cSrcweir             if( nLast != -1 )
278cdf0e10cSrcweir                 aFile = aFile.copy( nLast+1 );
279cdf0e10cSrcweir 
280cdf0e10cSrcweir             FastPrintFontInfo aInfo;
281cdf0e10cSrcweir             m_rFontManager.getFontFastInfo( *font_it, aInfo );
282cdf0e10cSrcweir             std::list< fontID > aDups;
283cdf0e10cSrcweir             String aEntry;
284cdf0e10cSrcweir             if( m_rFontManager.getFileDuplicates( *font_it, aDups ) )
285cdf0e10cSrcweir             {
286cdf0e10cSrcweir                 FastPrintFontInfo aDupInfo;
287cdf0e10cSrcweir                 std::list< FastPrintFontInfo > aInfos;
288cdf0e10cSrcweir                 aInfos.push_back( aInfo );
289cdf0e10cSrcweir                 for( std::list< fontID >::iterator dup = aDups.begin(); dup != aDups.end(); ++dup )
290cdf0e10cSrcweir                 {
291cdf0e10cSrcweir                     m_rFontManager.getFontFastInfo( *dup, aDupInfo );
292cdf0e10cSrcweir                     aInfos.push_back( aDupInfo );
293cdf0e10cSrcweir                     aFonts.remove( *dup );
294cdf0e10cSrcweir                 }
295cdf0e10cSrcweir                 aEntry = fillFontEntry( aInfos, String( ByteString( aFile ), osl_getThreadTextEncoding() ) );
296cdf0e10cSrcweir             }
297cdf0e10cSrcweir             else
298cdf0e10cSrcweir                 aEntry = fillFontEntry( aInfo, String( ByteString( aFile ), osl_getThreadTextEncoding() ), aFamilies[ aInfo.m_aFamilyName ] > 1  );
299cdf0e10cSrcweir 			sal_uInt16 nEntry = m_aFontBox.InsertEntry( aEntry );
300cdf0e10cSrcweir 			m_aFontBox.SetEntryData( nEntry, (void*)(*font_it) );
301cdf0e10cSrcweir 		}
302cdf0e10cSrcweir 	}
303cdf0e10cSrcweir }
304cdf0e10cSrcweir 
IMPL_LINK(FontNameDlg,SelectHdl,ListBox *,pBox)305cdf0e10cSrcweir IMPL_LINK( FontNameDlg, SelectHdl, ListBox*, pBox )
306cdf0e10cSrcweir {
307cdf0e10cSrcweir     if( pBox == &m_aFontBox )
308cdf0e10cSrcweir     {
309cdf0e10cSrcweir         sal_Bool bEnable = m_aFontBox.GetSelectEntryCount() ? sal_True : sal_False;
310cdf0e10cSrcweir         m_aRemoveButton.Enable( bEnable );
311cdf0e10cSrcweir         m_aRenameButton.Enable( bEnable );
312cdf0e10cSrcweir     }
313cdf0e10cSrcweir     return 0;
314cdf0e10cSrcweir }
315cdf0e10cSrcweir 
IMPL_LINK(FontNameDlg,DelPressedHdl,ListBox *,pBox)316cdf0e10cSrcweir IMPL_LINK( FontNameDlg, DelPressedHdl, ListBox*, pBox )
317cdf0e10cSrcweir {
318cdf0e10cSrcweir 	if( pBox == &m_aFontBox && m_aRemoveButton.IsEnabled() )
319cdf0e10cSrcweir 	{
320cdf0e10cSrcweir 		ClickBtnHdl( &m_aRemoveButton );
321cdf0e10cSrcweir 	}
322cdf0e10cSrcweir 	return 0;
323cdf0e10cSrcweir }
324cdf0e10cSrcweir 
IMPL_LINK(FontNameDlg,ClickBtnHdl,Button *,pButton)325cdf0e10cSrcweir IMPL_LINK( FontNameDlg, ClickBtnHdl, Button*, pButton )
326cdf0e10cSrcweir {
327cdf0e10cSrcweir 
328cdf0e10cSrcweir 	int i;
329cdf0e10cSrcweir 
330cdf0e10cSrcweir 	if( pButton == &m_aOKButton )
331cdf0e10cSrcweir 	{
332cdf0e10cSrcweir 		EndDialog();
333cdf0e10cSrcweir 	}
334cdf0e10cSrcweir 	else if( pButton == &m_aRemoveButton && AreYouSure( this, RID_QUERY_REMOVEFONTFROMLIST ) && m_aFontBox.GetSelectEntryCount() )
335cdf0e10cSrcweir 	{
336cdf0e10cSrcweir         ::std::list< fontID > aRemoveIDs;
337cdf0e10cSrcweir 		for( i = 0; i < m_aFontBox.GetSelectEntryCount(); i++ )
338cdf0e10cSrcweir 		{
339cdf0e10cSrcweir             int nSelect = m_aFontBox.GetSelectEntryPos( i );
340cdf0e10cSrcweir             aRemoveIDs.push_back( (fontID)(sal_IntPtr)m_aFontBox.GetEntryData( nSelect ) );
341cdf0e10cSrcweir 		}
342cdf0e10cSrcweir         m_rFontManager.removeFonts( aRemoveIDs );
343cdf0e10cSrcweir         init();
344cdf0e10cSrcweir 	}
345cdf0e10cSrcweir     else if( pButton == &m_aImportButton )
346cdf0e10cSrcweir     {
347cdf0e10cSrcweir 		FontImportDialog aDialog( this );
348cdf0e10cSrcweir 		aDialog.Execute();
349cdf0e10cSrcweir         init();
350cdf0e10cSrcweir     }
351cdf0e10cSrcweir     else if( pButton == &m_aRenameButton && m_aFontBox.GetSelectEntryCount() )
352cdf0e10cSrcweir     {
353cdf0e10cSrcweir 		for( i = 0; i < m_aFontBox.GetSelectEntryCount(); i++ )
354cdf0e10cSrcweir 		{
355cdf0e10cSrcweir             fontID aFont = (fontID)(sal_IntPtr)m_aFontBox.GetEntryData( m_aFontBox.GetSelectEntryPos( i ) );
356cdf0e10cSrcweir             if( ! m_rFontManager.checkChangeFontPropertiesPossible( aFont ) )
357cdf0e10cSrcweir             {
358cdf0e10cSrcweir                 String aErrorText( m_aNoRenameString );
359cdf0e10cSrcweir                 aErrorText.SearchAndReplace( String( RTL_CONSTASCII_USTRINGPARAM( "%s" ) ), m_aFontBox.GetSelectEntry( i ) );
360cdf0e10cSrcweir                 ErrorBox aBox( this, WB_OK | WB_DEF_OK, aErrorText );
361cdf0e10cSrcweir                 aBox.Execute();
362cdf0e10cSrcweir                 continue;
363cdf0e10cSrcweir             }
364cdf0e10cSrcweir             ::std::list< fontID > aDuplicates;
365cdf0e10cSrcweir             m_rFontManager.getFileDuplicates( aFont, aDuplicates );
366cdf0e10cSrcweir             aDuplicates.push_front( aFont );
367cdf0e10cSrcweir             int nFonts = aDuplicates.size();
368cdf0e10cSrcweir             for( int n = 0; n < nFonts; n++ )
369cdf0e10cSrcweir             {
370cdf0e10cSrcweir                 aFont = aDuplicates.front();
371cdf0e10cSrcweir                 aDuplicates.pop_front();
372cdf0e10cSrcweir                 String aFamily( m_rFontManager.getFontFamily( aFont ) );
373cdf0e10cSrcweir                 ::std::list< OUString > aAlternatives;
374cdf0e10cSrcweir                 m_rFontManager.getAlternativeFamilyNames( aFont, aAlternatives );
375cdf0e10cSrcweir                 ::std::list< String > aChoices;
376cdf0e10cSrcweir                 while( aAlternatives.size() )
377cdf0e10cSrcweir                 {
378cdf0e10cSrcweir                     aChoices.push_back( aAlternatives.front() );
379cdf0e10cSrcweir                     aAlternatives.pop_front();
380cdf0e10cSrcweir                 }
381cdf0e10cSrcweir                 String aQueryTxt( m_aRenameString );
382cdf0e10cSrcweir                 if( nFonts > 1 )
383cdf0e10cSrcweir                 {
384cdf0e10cSrcweir                     aQueryTxt = m_aRenameTTCString;
385cdf0e10cSrcweir                     aQueryTxt.SearchAndReplace( String( RTL_CONSTASCII_USTRINGPARAM( "%d1" ) ), String::CreateFromInt32( n+1 ) );
386cdf0e10cSrcweir                     aQueryTxt.SearchAndReplace( String( RTL_CONSTASCII_USTRINGPARAM( "%d2" ) ), String::CreateFromInt32( nFonts ) );
387cdf0e10cSrcweir                 }
388cdf0e10cSrcweir                 aQueryTxt.SearchAndReplace( String( RTL_CONSTASCII_USTRINGPARAM( "%s" ) ), aFamily );
389cdf0e10cSrcweir                 QueryString aQuery( this, aQueryTxt, aFamily, aChoices );
390cdf0e10cSrcweir                 if( aQuery.Execute() )
391cdf0e10cSrcweir                 {
392cdf0e10cSrcweir                     aFamily.SearchAndReplaceAll( '-', ' ' );
393cdf0e10cSrcweir                     aFamily.SearchAndReplaceAll( '?', ' ' );
394cdf0e10cSrcweir                     aFamily.SearchAndReplaceAll( '*', ' ' );
395cdf0e10cSrcweir                     aFamily = WhitespaceToSpace( aFamily );
396cdf0e10cSrcweir                     if( aFamily.Len() )
397cdf0e10cSrcweir                     {
398cdf0e10cSrcweir                         String aXLFD = m_rFontManager.getFontXLFD( aFont );
399cdf0e10cSrcweir                         aXLFD.SetToken( 2, '-', aFamily );
400cdf0e10cSrcweir                         m_rFontManager.changeFontProperties( aFont, aXLFD );
401cdf0e10cSrcweir                     }
402cdf0e10cSrcweir                 }
403cdf0e10cSrcweir             }
404cdf0e10cSrcweir         }
405cdf0e10cSrcweir         init();
406cdf0e10cSrcweir     }
407cdf0e10cSrcweir 	return 0;
408cdf0e10cSrcweir }
409cdf0e10cSrcweir 
410cdf0e10cSrcweir //--------------------------------------------------
411cdf0e10cSrcweir 
FontImportDialog(Window * pParent)412cdf0e10cSrcweir FontImportDialog::FontImportDialog( Window* pParent ) :
413cdf0e10cSrcweir 		ModalDialog( pParent, PaResId( RID_FONTIMPORT_DIALOG ) ),
414cdf0e10cSrcweir 		m_aOKBtn( this, PaResId( RID_FIMP_BTN_OK ) ),
415cdf0e10cSrcweir 		m_aCancelBtn( this, PaResId( RID_FIMP_BTN_CANCEL ) ),
416cdf0e10cSrcweir         m_aSelectAllBtn( this, PaResId( RID_FIMP_BTN_SELECTALL ) ),
417cdf0e10cSrcweir         m_aNewFontsBox( this, PaResId( RID_FIMP_BOX_NEWFONTS ) ),
418cdf0e10cSrcweir 		m_aFromFL( this, PaResId( RID_FIMP_FL_FROM ) ),
419cdf0e10cSrcweir 		m_aFromDirEdt( this, PaResId( RID_FIMP_EDT_FROM ) ),
420cdf0e10cSrcweir 		m_aFromBtn( this, PaResId( RID_FIMP_BTN_FROM ) ),
421cdf0e10cSrcweir         m_aSubDirsBox( this, PaResId( RID_FIMP_BOX_SUBDIRS ) ),
422cdf0e10cSrcweir         m_aTargetOptFL( this, PaResId( RID_FIMP_FL_TARGETOPTS ) ),
423cdf0e10cSrcweir         m_aLinkOnlyBox( this, PaResId( RID_FIMP_BOX_LINKONLY ) ),
424cdf0e10cSrcweir         m_aFixedText( this, PaResId( RID_FIMP_TXT_HELP ) ),
425cdf0e10cSrcweir 		m_bOverwriteAll( false ),
426cdf0e10cSrcweir 		m_bOverwriteNone( false ),
427cdf0e10cSrcweir 		m_pProgress( NULL ),
428cdf0e10cSrcweir 		m_aImportOperation( PaResId( RID_FIMP_STR_IMPORTOP ) ),
429cdf0e10cSrcweir 		m_aOverwriteQueryText( PaResId( RID_FIMP_STR_QUERYOVERWRITE ) ),
430cdf0e10cSrcweir 		m_aOverwriteAllText( PaResId( RID_FIMP_STR_OVERWRITEALL ) ),
431cdf0e10cSrcweir 		m_aOverwriteNoneText( PaResId( RID_FIMP_STR_OVERWRITENONE ) ),
432cdf0e10cSrcweir 		m_aNoAfmText( PaResId( RID_FIMP_STR_NOAFM ) ),
433cdf0e10cSrcweir 		m_aAfmCopyFailedText( PaResId( RID_FIMP_STR_AFMCOPYFAILED ) ),
434cdf0e10cSrcweir 		m_aFontCopyFailedText( PaResId( RID_FIMP_STR_FONTCOPYFAILED ) ),
435cdf0e10cSrcweir 		m_aNoWritableFontsDirText( PaResId( RID_FIMP_STR_NOWRITEABLEFONTSDIR ) ),
436cdf0e10cSrcweir 		m_aFontsImportedText( PaResId( RID_FIMP_STR_NUMBEROFFONTSIMPORTED ) ),
437cdf0e10cSrcweir 		m_rFontManager( ::psp::PrintFontManager::get() )
438cdf0e10cSrcweir {
439cdf0e10cSrcweir 	FreeResource();
440cdf0e10cSrcweir 
441cdf0e10cSrcweir 	m_aNewFontsBox.EnableMultiSelection( sal_True );
442cdf0e10cSrcweir 
443cdf0e10cSrcweir 	m_aOKBtn.SetClickHdl( LINK( this, FontImportDialog, ClickBtnHdl ) );
444cdf0e10cSrcweir     m_aSelectAllBtn.SetClickHdl( LINK( this, FontImportDialog, ClickBtnHdl ) );
445cdf0e10cSrcweir 	m_aFromBtn.SetClickHdl( LINK( this, FontImportDialog, ClickBtnHdl ) );
446cdf0e10cSrcweir     m_aFromDirEdt.SetModifyHdl( LINK( this, FontImportDialog, ModifyHdl ) );
447cdf0e10cSrcweir     m_aRefreshTimer.SetTimeoutHdl( LINK( this, FontImportDialog, RefreshTimeoutHdl ) );
448cdf0e10cSrcweir     m_aRefreshTimer.SetTimeout( 2000 );
449cdf0e10cSrcweir     m_aLinkOnlyBox.Check( sal_False );
450cdf0e10cSrcweir     m_aSubDirsBox.Check( sal_True );
451cdf0e10cSrcweir     m_aSubDirsBox.SetToggleHdl( LINK( this, FontImportDialog, ToggleHdl ) );
452cdf0e10cSrcweir 
453cdf0e10cSrcweir     Config& rPadminRC( getPadminRC() );
454cdf0e10cSrcweir     rPadminRC.SetGroup( "FontImport" );
455cdf0e10cSrcweir     m_aFromDirEdt.SetText( String( rPadminRC.ReadKey( "FromPath" ), RTL_TEXTENCODING_UTF8 ) );
456cdf0e10cSrcweir     RefreshTimeoutHdl( NULL );
457cdf0e10cSrcweir }
458cdf0e10cSrcweir 
~FontImportDialog()459cdf0e10cSrcweir FontImportDialog::~FontImportDialog()
460cdf0e10cSrcweir {
461cdf0e10cSrcweir     Config& rPadminRC( getPadminRC() );
462cdf0e10cSrcweir     rPadminRC.SetGroup( "FontImport" );
463cdf0e10cSrcweir     rPadminRC.WriteKey( "FromPath", ByteString( m_aFromDirEdt.GetText(), RTL_TEXTENCODING_UTF8 ) );
464cdf0e10cSrcweir }
465cdf0e10cSrcweir 
importFontsFailed(::psp::PrintFontManager::ImportFontCallback::FailCondition eReason)466cdf0e10cSrcweir void FontImportDialog::importFontsFailed( ::psp::PrintFontManager::ImportFontCallback::FailCondition eReason )
467cdf0e10cSrcweir {
468cdf0e10cSrcweir 	String aText;
469cdf0e10cSrcweir 	switch( eReason )
470cdf0e10cSrcweir 	{
471cdf0e10cSrcweir 		case psp::PrintFontManager::ImportFontCallback::NoWritableDirectory:
472cdf0e10cSrcweir 			aText = m_aNoWritableFontsDirText;
473cdf0e10cSrcweir             break;
474cdf0e10cSrcweir         default:
475cdf0e10cSrcweir             break;
476cdf0e10cSrcweir 	}
477cdf0e10cSrcweir 	ErrorBox aBox( m_pProgress ? (Window*)m_pProgress : (Window*)this, WB_OK | WB_DEF_OK, aText );
478cdf0e10cSrcweir 	aBox.Execute();
479cdf0e10cSrcweir }
480cdf0e10cSrcweir 
progress(const::rtl::OUString & rFile)481cdf0e10cSrcweir void FontImportDialog::progress( const ::rtl::OUString& rFile )
482cdf0e10cSrcweir {
483cdf0e10cSrcweir 	m_pProgress->setValue( ++m_nFont );
484cdf0e10cSrcweir 	m_pProgress->setFilename( rFile );
485cdf0e10cSrcweir }
486cdf0e10cSrcweir 
queryOverwriteFile(const::rtl::OUString & rFile)487cdf0e10cSrcweir bool FontImportDialog::queryOverwriteFile( const ::rtl::OUString& rFile )
488cdf0e10cSrcweir {
489cdf0e10cSrcweir 	bool bRet = false;
490cdf0e10cSrcweir 
491cdf0e10cSrcweir 	if( m_bOverwriteNone )
492cdf0e10cSrcweir 		return false;
493cdf0e10cSrcweir 	if( m_bOverwriteAll )
494cdf0e10cSrcweir 		return true;
495cdf0e10cSrcweir 
496cdf0e10cSrcweir 	String aText( m_aOverwriteQueryText );
497cdf0e10cSrcweir 	aText.SearchAndReplace( String( RTL_CONSTASCII_USTRINGPARAM( "%s" ) ), rFile );
498cdf0e10cSrcweir 
499cdf0e10cSrcweir 	QueryBox aQueryBox( m_pProgress ? (Window*)m_pProgress : (Window*)this, WB_YES_NO | WB_DEF_NO, aText );
500cdf0e10cSrcweir 	aQueryBox.AddButton( m_aOverwriteAllText, 20, 0 );
501cdf0e10cSrcweir 	aQueryBox.AddButton( m_aOverwriteNoneText, 21, 0 );
502cdf0e10cSrcweir 
503cdf0e10cSrcweir 	int nResult = aQueryBox.Execute();
504cdf0e10cSrcweir 	switch( nResult )
505cdf0e10cSrcweir 	{
506cdf0e10cSrcweir 		case BUTTONID_YES:		bRet = true; break;
507cdf0e10cSrcweir 		case BUTTONID_NO:		bRet = false; break;
508cdf0e10cSrcweir 		case 20:				bRet = m_bOverwriteAll = true; break;
509cdf0e10cSrcweir 		case 21:				bRet = false; m_bOverwriteNone = true; break;
510cdf0e10cSrcweir 	}
511cdf0e10cSrcweir 
512cdf0e10cSrcweir 	return bRet;
513cdf0e10cSrcweir }
514cdf0e10cSrcweir 
importFontFailed(const::rtl::OUString & rFile,::psp::PrintFontManager::ImportFontCallback::FailCondition eReason)515cdf0e10cSrcweir void FontImportDialog::importFontFailed( const ::rtl::OUString& rFile, ::psp::PrintFontManager::ImportFontCallback::FailCondition eReason )
516cdf0e10cSrcweir {
517cdf0e10cSrcweir 	String aText;
518cdf0e10cSrcweir 	switch( eReason )
519cdf0e10cSrcweir 	{
520cdf0e10cSrcweir 		case psp::PrintFontManager::ImportFontCallback::NoAfmMetric:
521cdf0e10cSrcweir 			aText = m_aNoAfmText;
522cdf0e10cSrcweir 			break;
523cdf0e10cSrcweir 		case psp::PrintFontManager::ImportFontCallback::AfmCopyFailed:
524cdf0e10cSrcweir 			aText = m_aAfmCopyFailedText;
525cdf0e10cSrcweir 			break;
526cdf0e10cSrcweir 		case psp::PrintFontManager::ImportFontCallback::FontCopyFailed:
527cdf0e10cSrcweir 			aText = m_aFontCopyFailedText;
528cdf0e10cSrcweir 			break;
529cdf0e10cSrcweir         default:
530cdf0e10cSrcweir             break;
531cdf0e10cSrcweir 	}
532cdf0e10cSrcweir 	aText.SearchAndReplace( String( RTL_CONSTASCII_USTRINGPARAM( "%s" ) ), rFile );
533cdf0e10cSrcweir 	ErrorBox aBox( m_pProgress ? (Window*)m_pProgress : (Window*)this, WB_OK | WB_DEF_OK, aText );
534cdf0e10cSrcweir 	aBox.Execute();
535cdf0e10cSrcweir }
536cdf0e10cSrcweir 
isCanceled()537cdf0e10cSrcweir bool FontImportDialog::isCanceled()
538cdf0e10cSrcweir {
539cdf0e10cSrcweir 	return m_pProgress->isCanceled();
540cdf0e10cSrcweir }
541cdf0e10cSrcweir 
IMPL_LINK(FontImportDialog,ModifyHdl,Edit *,EMPTYARG)542cdf0e10cSrcweir IMPL_LINK( FontImportDialog, ModifyHdl, Edit*, EMPTYARG )
543cdf0e10cSrcweir {
544cdf0e10cSrcweir     m_aRefreshTimer.Start();
545cdf0e10cSrcweir     return 0;
546cdf0e10cSrcweir }
547cdf0e10cSrcweir 
IMPL_LINK(FontImportDialog,RefreshTimeoutHdl,void *,EMPTYARG)548cdf0e10cSrcweir IMPL_LINK( FontImportDialog, RefreshTimeoutHdl, void*, EMPTYARG )
549cdf0e10cSrcweir {
550cdf0e10cSrcweir     rtl_TextEncoding aEncoding = osl_getThreadTextEncoding();
551cdf0e10cSrcweir 	std::list< String > aFiles;
552cdf0e10cSrcweir     m_aNewFonts.clear();
553cdf0e10cSrcweir 	OUString aDirectory( m_aFromDirEdt.GetText() );
554cdf0e10cSrcweir 	FindFiles( aDirectory, aFiles, String( RTL_CONSTASCII_USTRINGPARAM( "PFA;PFB;TTF;TTC;OTF" ) ), m_aSubDirsBox.IsChecked() );
555cdf0e10cSrcweir     OString aDir( OUStringToOString( aDirectory, aEncoding ) );
556cdf0e10cSrcweir     aDir += "/";
557cdf0e10cSrcweir 	while( aFiles.begin() != aFiles.end() )
558cdf0e10cSrcweir 	{
559cdf0e10cSrcweir 		OString aFont( aDir );
560cdf0e10cSrcweir 		aFont += OUStringToOString( aFiles.front(), aEncoding );
561cdf0e10cSrcweir 		aFiles.pop_front();
562cdf0e10cSrcweir         ::std::list< FastPrintFontInfo > aInfos;
563cdf0e10cSrcweir         if( m_rFontManager.getImportableFontProperties( aFont, aInfos ) )
564cdf0e10cSrcweir             m_aNewFonts[ aFont ] = aInfos;
565cdf0e10cSrcweir 	}
566cdf0e10cSrcweir     fillFontBox();
567cdf0e10cSrcweir     return 0;
568cdf0e10cSrcweir }
569cdf0e10cSrcweir 
fillFontBox()570cdf0e10cSrcweir void FontImportDialog::fillFontBox()
571cdf0e10cSrcweir {
572cdf0e10cSrcweir     rtl_TextEncoding aEncoding = osl_getThreadTextEncoding();
573cdf0e10cSrcweir     m_aNewFontsBox.Clear();
574cdf0e10cSrcweir 
575cdf0e10cSrcweir     ::std::hash_map< OUString, int, OUStringHash > aFamilies;
576cdf0e10cSrcweir     ::std::hash_map< OString, ::std::list< FastPrintFontInfo >, OStringHash >::iterator it;
577cdf0e10cSrcweir 	for( it = m_aNewFonts.begin(); it != m_aNewFonts.end(); ++it )
578cdf0e10cSrcweir 	{
579cdf0e10cSrcweir         const OUString& rFamily( it->second.front().m_aFamilyName );
580cdf0e10cSrcweir         if( aFamilies.find( rFamily ) == aFamilies.end() )
581cdf0e10cSrcweir                 aFamilies[rFamily] = 0;
582cdf0e10cSrcweir             aFamilies[rFamily]++;
583cdf0e10cSrcweir     }
584cdf0e10cSrcweir 
585cdf0e10cSrcweir     for( it = m_aNewFonts.begin(); it != m_aNewFonts.end(); ++it )
586cdf0e10cSrcweir     {
587cdf0e10cSrcweir         OString aFileName( it->first.copy( it->first.lastIndexOf( '/' )+1 ) );
588cdf0e10cSrcweir         OUString aFile( OStringToOUString( aFileName, aEncoding ) );
589cdf0e10cSrcweir         String aEntry;
590cdf0e10cSrcweir         if( it->second.size() == 1 )
591cdf0e10cSrcweir             aEntry = FontNameDlg::fillFontEntry( it->second.front(), aFile, aFamilies[ it->second.front().m_aFamilyName ] > 1 );
592cdf0e10cSrcweir         else
593cdf0e10cSrcweir             aEntry = FontNameDlg::fillFontEntry( it->second, aFile );
594cdf0e10cSrcweir         sal_uInt16 nPos = m_aNewFontsBox.InsertEntry( aEntry );
595cdf0e10cSrcweir         m_aNewFontsBox.SetEntryData( nPos, (void*)&(it->first) );
596cdf0e10cSrcweir     }
597cdf0e10cSrcweir }
598cdf0e10cSrcweir 
copyFonts()599cdf0e10cSrcweir void FontImportDialog::copyFonts()
600cdf0e10cSrcweir {
601cdf0e10cSrcweir 	::std::list< OString > aFiles;
602cdf0e10cSrcweir     for( int i = 0; i < m_aNewFontsBox.GetSelectEntryCount(); i++ )
603cdf0e10cSrcweir     {
604cdf0e10cSrcweir         OString* pFile = (OString*)m_aNewFontsBox.GetEntryData( m_aNewFontsBox.GetSelectEntryPos( i ) );
605cdf0e10cSrcweir         aFiles.push_back( *pFile );
606cdf0e10cSrcweir     }
607cdf0e10cSrcweir 
608cdf0e10cSrcweir 	int nSuccess = 0;
609cdf0e10cSrcweir 	if( aFiles.size() )
610cdf0e10cSrcweir 	{
611cdf0e10cSrcweir 		m_nFont = 0;
612cdf0e10cSrcweir 		m_pProgress = new ProgressDialog( this );
613cdf0e10cSrcweir 		m_pProgress->setRange( 0, aFiles.size() );
614cdf0e10cSrcweir 		m_pProgress->startOperation( m_aImportOperation );
615cdf0e10cSrcweir 		m_pProgress->Show( sal_True );
616cdf0e10cSrcweir 		m_pProgress->setValue( 0 );
617cdf0e10cSrcweir 		m_pProgress->Invalidate();
618cdf0e10cSrcweir 		m_pProgress->Sync();
619cdf0e10cSrcweir 		nSuccess = m_rFontManager.importFonts( aFiles, m_aLinkOnlyBox.IsChecked() ? true : false, this );
620cdf0e10cSrcweir 		m_pProgress->Show( sal_False );
621cdf0e10cSrcweir 		delete m_pProgress;
622cdf0e10cSrcweir 		m_pProgress = NULL;
623cdf0e10cSrcweir 	}
624cdf0e10cSrcweir 	String aText( m_aFontsImportedText );
625cdf0e10cSrcweir 	aText.SearchAndReplace( String( RTL_CONSTASCII_USTRINGPARAM( "%d" ) ), String::CreateFromInt32( nSuccess ) );
626cdf0e10cSrcweir 	InfoBox aBox( this, aText );
627cdf0e10cSrcweir 	aBox.Execute();
628cdf0e10cSrcweir }
629cdf0e10cSrcweir 
IMPL_LINK(FontImportDialog,ClickBtnHdl,Button *,pButton)630cdf0e10cSrcweir IMPL_LINK( FontImportDialog, ClickBtnHdl, Button*, pButton )
631cdf0e10cSrcweir {
632cdf0e10cSrcweir 	if( pButton == &m_aFromBtn )
633cdf0e10cSrcweir 	{
634cdf0e10cSrcweir         String aPath( m_aFromDirEdt.GetText() );
635cdf0e10cSrcweir         if( chooseDirectory( aPath ) )
636cdf0e10cSrcweir         {
637cdf0e10cSrcweir 			m_aFromDirEdt.SetText( aPath );
638cdf0e10cSrcweir             RefreshTimeoutHdl( NULL );
639cdf0e10cSrcweir         }
640cdf0e10cSrcweir 	}
641cdf0e10cSrcweir 	else if( pButton == &m_aOKBtn )
642cdf0e10cSrcweir 	{
643cdf0e10cSrcweir 		copyFonts();
644cdf0e10cSrcweir 		EndDialog( 0 );
645cdf0e10cSrcweir 	}
646cdf0e10cSrcweir     else if( pButton == &m_aSelectAllBtn )
647cdf0e10cSrcweir     {
648cdf0e10cSrcweir         m_aNewFontsBox.SetUpdateMode( sal_False );
649cdf0e10cSrcweir         for( int i = 0; i < m_aNewFontsBox.GetEntryCount(); i++ )
650cdf0e10cSrcweir             m_aNewFontsBox.SelectEntryPos( i, sal_True );
651cdf0e10cSrcweir         m_aNewFontsBox.SetUpdateMode( sal_True );
652cdf0e10cSrcweir     }
653cdf0e10cSrcweir 	return 0;
654cdf0e10cSrcweir }
655cdf0e10cSrcweir 
IMPL_LINK(FontImportDialog,ToggleHdl,CheckBox *,pBox)656cdf0e10cSrcweir IMPL_LINK( FontImportDialog, ToggleHdl, CheckBox*, pBox )
657cdf0e10cSrcweir {
658cdf0e10cSrcweir     if( pBox == &m_aSubDirsBox )
659cdf0e10cSrcweir     {
660cdf0e10cSrcweir         RefreshTimeoutHdl( NULL );
661cdf0e10cSrcweir     }
662cdf0e10cSrcweir 
663cdf0e10cSrcweir     return 0;
664cdf0e10cSrcweir }
665