1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: ascfldlg.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sw.hxx"
33 #ifdef SW_DLLIMPLEMENTATION
34 #undef SW_DLLIMPLEMENTATION
36 #include <hintids.hxx>
37 #include <rtl/textenc.h>
38 #include <i18npool/mslangid.hxx>
39 #include <com/sun/star/i18n/ScriptType.hpp>
40 #include <svtools/lingucfg.hxx>
41 #include <fontcfg.hxx>
42 #include <swmodule.hxx>
43 #include <svx/unolingu.hxx>
44 #include <sfx2/printer.hxx>
45 #include <svx/flstitem.hxx>
46 #include <svx/dlgutil.hxx>
47 #include <svx/fontitem.hxx>
48 #include <svx/langitem.hxx>
49 #include <svx/scripttypeitem.hxx>
50 #include <swtypes.hxx>
51 #include <ascfldlg.hxx>
52 #include <shellio.hxx>
61 #include <ascfldlg.hrc>
65 using namespace ::com::sun::star
;
67 const sal_Unicode cDialogExtraDataClose
= '}';
68 const char __FAR_DATA sDialogImpExtraData
[] = "EncImpDlg:{";
69 const char __FAR_DATA sDialogExpExtraData
[] = "EncExpDlg:{";
70 const USHORT nDialogExtraDataLen
= 11; // 12345678901
72 SwAsciiFilterDlg::SwAsciiFilterDlg( Window
* pParent
, SwDocShell
& rDocSh
,
74 : SfxModalDialog( pParent
, SW_RES( DLG_ASCII_FILTER
)),
75 aFL( this, SW_RES( FL_1
)),
76 aCharSetFT( this, SW_RES( FT_CHARSET
)),
77 aCharSetLB( this, SW_RES( LB_CHARSET
)),
78 aFontFT( this, SW_RES( FT_FONT
)),
79 aFontLB( this, SW_RES( LB_FONT
)),
80 aLanguageFT( this, SW_RES( FT_LANGUAGE
)),
81 aLanguageLB( this, SW_RES( LB_LANGUAGE
)),
82 aCRLF_FT( this, SW_RES( FT_CRLF
)),
83 aCRLF_RB( this, SW_RES( RB_CRLF
)),
84 aCR_RB( this, SW_RES( RB_CR
)),
85 aLF_RB( this, SW_RES( RB_LF
)),
86 aOkPB( this, SW_RES( PB_OK
)),
87 aCancelPB( this, SW_RES( PB_CANCEL
)),
88 aHelpPB( this, SW_RES( PB_HELP
)),
89 sSystemCharSet( SW_RES( STR_SYS_CHARSET
)),
90 bSaveLineStatus( TRUE
)
96 const String
& rFindNm
= String::CreateFromAscii(
97 pStream
? sDialogImpExtraData
98 : sDialogExpExtraData
);
99 USHORT nEnd
, nStt
= GetExtraData().Search( rFindNm
);
100 if( STRING_NOTFOUND
!= nStt
)
102 nStt
+= nDialogExtraDataLen
;
103 nEnd
= GetExtraData().Search( cDialogExtraDataClose
, nStt
);
104 if( STRING_NOTFOUND
!= nEnd
)
106 aOpt
.ReadUserData( GetExtraData().Copy( nStt
, nEnd
- nStt
));
107 nStt
-= nDialogExtraDataLen
;
108 GetExtraData().Erase( nStt
, nEnd
- nStt
+ 1 );
113 // read the first chars and check the charset, (language - with L&H)
116 char aBuffer
[ 4098 ];
117 ULONG nOldPos
= pStream
->Tell();
118 ULONG nBytesRead
= pStream
->Read( aBuffer
, 4096 );
119 pStream
->Seek( nOldPos
);
121 if( nBytesRead
<= 4096 )
123 aBuffer
[ nBytesRead
] = '0';
124 aBuffer
[ nBytesRead
+1 ] = '0';
125 if( 0 != ( nBytesRead
& 0x00000001 ) )
126 aBuffer
[ nBytesRead
+ 2 ] = '0';
129 BOOL bCR
= FALSE
, bLF
= FALSE
, bNoNormalChar
= FALSE
,
131 for( USHORT nCnt
= 0; nCnt
< nBytesRead
; ++nCnt
)
132 switch( aBuffer
[ nCnt
] )
134 case 0x0: bNullChar
= TRUE
; break;
135 case 0xA: bLF
= TRUE
; break;
136 case 0xD: bCR
= TRUE
; break;
141 if( 0x20 > aBuffer
[ nCnt
] )
142 bNoNormalChar
= TRUE
;
151 aOpt
.SetParaFlags( LINEEND_CRLF
);
152 // have to check if of CharSet is type of ANSI
153 // aOpt.SetCharSet( CHARSET_ANSI );
157 aOpt
.SetParaFlags( LINEEND_CR
);
158 // have to check if CharSet is type of MAC
159 // aOpt.SetCharSet( CHARSET_MAC );
164 aOpt
.SetParaFlags( LINEEND_LF
);
165 // have to check if of CharSet is type of ANSI
166 // aOpt.SetCharSet( CHARSET_ANSI );
170 SwDoc
* pDoc
= rDocSh
.GetDoc();
172 USHORT nAppScriptType
= GetI18NScriptTypeOfLanguage( (USHORT
)GetAppLanguage() );
174 BOOL bDelPrinter
= FALSE
;
175 SfxPrinter
* pPrt
= pDoc
? pDoc
->getPrinter(false) : 0;
178 SfxItemSet
* pSet
= new SfxItemSet( rDocSh
.GetPool(),
179 SID_PRINTER_NOTFOUND_WARN
, SID_PRINTER_NOTFOUND_WARN
,
180 SID_PRINTER_CHANGESTODOC
, SID_PRINTER_CHANGESTODOC
,
182 pPrt
= new SfxPrinter( pSet
);
186 const USHORT nCount
= pPrt
->GetFontCount();
187 for (USHORT i
= 0; i
< nCount
; ++i
)
189 const String
&rStr
= pPrt
->GetFont(i
)->GetName();
190 aFontLB
.InsertEntry( rStr
);
193 if( !aOpt
.GetFontName().Len() )
197 USHORT nFontRes
= RES_CHRATR_FONT
;
198 if(SCRIPTTYPE_ASIAN
== nAppScriptType
)
199 nFontRes
= RES_CHRATR_CJK_FONT
;
200 else if(SCRIPTTYPE_COMPLEX
== nAppScriptType
)
201 nFontRes
= RES_CHRATR_CTL_FONT
;
203 aOpt
.SetFontName( ((SvxFontItem
&)pDoc
->GetDefault(
204 nFontRes
)).GetFamilyName() );
208 USHORT nFontType
= FONT_STANDARD
;
209 if(SCRIPTTYPE_ASIAN
== nAppScriptType
)
210 nFontType
= FONT_STANDARD_CJK
;
211 else if(SCRIPTTYPE_COMPLEX
== nAppScriptType
)
212 nFontType
= FONT_STANDARD_CTL
;
213 aOpt
.SetFontName(SW_MOD()->GetStdFontConfig()->GetFontFor(nFontType
));
216 aFontLB
.SelectEntry( aOpt
.GetFontName() );
222 // initialisiere Sprache
224 if( !aOpt
.GetLanguage() )
228 USHORT nWhich
= GetWhichOfScript( RES_CHRATR_LANGUAGE
, nAppScriptType
);
229 aOpt
.SetLanguage( ((SvxLanguageItem
&)pDoc
->
230 GetDefault( nWhich
)).GetLanguage());
234 SvtLinguOptions aLinguOpt
;
235 SvtLinguConfig().GetOptions( aLinguOpt
);
236 switch(nAppScriptType
)
238 case SCRIPTTYPE_ASIAN
:
239 aOpt
.SetLanguage(MsLangId::resolveSystemLanguageByScriptType(aLinguOpt
.nDefaultLanguage_CJK
, SCRIPTTYPE_ASIAN
));
241 case SCRIPTTYPE_COMPLEX
:
242 aOpt
.SetLanguage(MsLangId::resolveSystemLanguageByScriptType(aLinguOpt
.nDefaultLanguage_CTL
, SCRIPTTYPE_COMPLEX
));
246 aOpt
.SetLanguage(MsLangId::resolveSystemLanguageByScriptType(aLinguOpt
.nDefaultLanguage
, SCRIPTTYPE_LATIN
));
251 aLanguageLB
.SetLanguageList( LANG_LIST_ALL
, TRUE
, FALSE
);
252 aLanguageLB
.SelectLanguage( aOpt
.GetLanguage() );
257 // hide the used Control for the Export and move the
258 // other behind the charset controls
264 long nY
= aFontFT
.GetPosPixel().Y() + 1;
265 Point
aPos( aCRLF_FT
.GetPosPixel() ); aPos
.Y() = nY
;
266 aCRLF_FT
.SetPosPixel( aPos
);
268 aPos
= aCRLF_RB
.GetPosPixel(); aPos
.Y() = nY
;
269 aCRLF_RB
.SetPosPixel( aPos
);
271 aPos
= aCR_RB
.GetPosPixel(); aPos
.Y() = nY
;
272 aCR_RB
.SetPosPixel( aPos
);
274 aPos
= aLF_RB
.GetPosPixel(); aPos
.Y() = nY
;
275 aLF_RB
.SetPosPixel( aPos
);
277 Size aSize
= GetSizePixel();
279 aTmpSz
= LogicToPixel(aTmpSz
, MAP_APPFONT
);
280 aSize
.Height() = aHelpPB
.GetPosPixel().Y() +
281 aHelpPB
.GetSizePixel().Height() + aTmpSz
.Height();
282 SetSizePixel( aSize
);
285 // initialisiere Zeichensatz
286 aCharSetLB
.FillFromTextEncodingTable( pStream
!= NULL
);
287 aCharSetLB
.SelectTextEncoding( aOpt
.GetCharSet() );
289 aCharSetLB
.SetSelectHdl( LINK( this, SwAsciiFilterDlg
, CharSetSelHdl
));
290 aCRLF_RB
.SetToggleHdl( LINK( this, SwAsciiFilterDlg
, LineEndHdl
));
291 aLF_RB
.SetToggleHdl( LINK( this, SwAsciiFilterDlg
, LineEndHdl
));
292 aCR_RB
.SetToggleHdl( LINK( this, SwAsciiFilterDlg
, LineEndHdl
));
294 SetCRLF( aOpt
.GetParaFlags() );
296 aCRLF_RB
.SaveValue();
302 SwAsciiFilterDlg::~SwAsciiFilterDlg()
307 void SwAsciiFilterDlg::FillOptions( SwAsciiOptions
& rOptions
)
309 ULONG nCCode
= aCharSetLB
.GetSelectTextEncoding();
312 if( aFontLB
.IsVisible() )
314 sFont
= aFontLB
.GetSelectEntry();
315 nLng
= (ULONG
)aLanguageLB
.GetSelectLanguage();
318 rOptions
.SetFontName( sFont
);
319 rOptions
.SetCharSet( rtl_TextEncoding( nCCode
) );
320 rOptions
.SetLanguage( USHORT( nLng
) );
321 rOptions
.SetParaFlags( GetCRLF() );
323 // JP: Task #71802# save the user settings
325 rOptions
.WriteUserData( sData
);
328 const String
& rFindNm
= String::CreateFromAscii(
329 aFontLB
.IsVisible() ? sDialogImpExtraData
330 : sDialogExpExtraData
);
331 USHORT nEnd
, nStt
= GetExtraData().Search( rFindNm
);
332 if( STRING_NOTFOUND
!= nStt
)
334 // called twice, so remove "old" settings
335 nEnd
= GetExtraData().Search( cDialogExtraDataClose
,
336 nStt
+ nDialogExtraDataLen
);
337 if( STRING_NOTFOUND
!= nEnd
)
338 GetExtraData().Erase( nStt
, nEnd
- nStt
+ 1 );
340 String
sTmp(GetExtraData());
343 sTmp
+= cDialogExtraDataClose
;
344 GetExtraData() = sTmp
;
348 void SwAsciiFilterDlg::SetCRLF( LineEnd eEnd
)
352 case LINEEND_CR
: aCR_RB
.Check(); break;
353 case LINEEND_CRLF
: aCRLF_RB
.Check(); break;
354 case LINEEND_LF
: aLF_RB
.Check(); break;
358 LineEnd
SwAsciiFilterDlg::GetCRLF() const
361 if( aCR_RB
.IsChecked() )
363 else if( aLF_RB
.IsChecked() )
370 IMPL_LINK( SwAsciiFilterDlg
, CharSetSelHdl
, SvxTextEncodingBox
*, pBox
)
372 LineEnd eOldEnd
= GetCRLF(), eEnd
= (LineEnd
)-1;
373 LanguageType nLng
= aFontLB
.IsVisible()
374 ? aLanguageLB
.GetSelectLanguage()
378 rtl_TextEncoding nChrSet
= pBox
->GetSelectTextEncoding();
379 if( nChrSet
== gsl_getSystemTextEncoding() )
380 eEnd
= GetSystemLineEnd();
385 case RTL_TEXTENCODING_MS_1252
:
389 eEnd
= LINEEND_CRLF
; // ANSI
393 case RTL_TEXTENCODING_APPLE_ROMAN
: // MAC
397 case RTL_TEXTENCODING_IBM_850
: // DOS
401 case RTL_TEXTENCODING_APPLE_ARABIC
:
402 case RTL_TEXTENCODING_APPLE_CENTEURO
:
403 case RTL_TEXTENCODING_APPLE_CROATIAN
:
404 case RTL_TEXTENCODING_APPLE_CYRILLIC
:
405 case RTL_TEXTENCODING_APPLE_DEVANAGARI
:
406 case RTL_TEXTENCODING_APPLE_FARSI
:
407 case RTL_TEXTENCODING_APPLE_GREEK
:
408 case RTL_TEXTENCODING_APPLE_GUJARATI
:
409 case RTL_TEXTENCODING_APPLE_GURMUKHI
:
410 case RTL_TEXTENCODING_APPLE_HEBREW
:
411 case RTL_TEXTENCODING_APPLE_ICELAND
:
412 case RTL_TEXTENCODING_APPLE_ROMANIAN
:
413 case RTL_TEXTENCODING_APPLE_THAI
:
414 case RTL_TEXTENCODING_APPLE_TURKISH
:
415 case RTL_TEXTENCODING_APPLE_UKRAINIAN
:
416 case RTL_TEXTENCODING_APPLE_CHINSIMP
:
417 case RTL_TEXTENCODING_APPLE_CHINTRAD
:
418 case RTL_TEXTENCODING_APPLE_JAPANESE
:
419 case RTL_TEXTENCODING_APPLE_KOREAN
:
425 bSaveLineStatus
= FALSE
;
426 if( eEnd
!= (LineEnd
)-1 ) // changed?
428 if( eOldEnd
!= eEnd
)
433 // restore old user choise (not the automatic!)
434 aCRLF_RB
.Check( aCRLF_RB
.GetSavedValue() );
435 aCR_RB
.Check( aCR_RB
.GetSavedValue() );
436 aLF_RB
.Check( aLF_RB
.GetSavedValue() );
438 bSaveLineStatus
= TRUE
;
440 if( nOldLng
!= nLng
&& aFontLB
.IsVisible() )
441 aLanguageLB
.SelectLanguage( nLng
);
446 IMPL_LINK( SwAsciiFilterDlg
, LineEndHdl
, RadioButton
*, pBtn
)
448 if( bSaveLineStatus
)