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 <svtools/lingucfg.hxx>
39 #include <fontcfg.hxx>
40 #include <swmodule.hxx>
41 #include <svx/unolingu.hxx>
42 #include <sfx2/printer.hxx>
43 #include <svx/flstitem.hxx>
44 #include <svx/dlgutil.hxx>
45 #include <svx/fontitem.hxx>
46 #include <svx/langitem.hxx>
47 #include <svx/scripttypeitem.hxx>
48 #include <swtypes.hxx>
49 #include <ascfldlg.hxx>
50 #include <shellio.hxx>
59 #include <ascfldlg.hrc>
63 using namespace ::com::sun::star
;
65 const sal_Unicode cDialogExtraDataClose
= '}';
66 const char __FAR_DATA sDialogImpExtraData
[] = "EncImpDlg:{";
67 const char __FAR_DATA sDialogExpExtraData
[] = "EncExpDlg:{";
68 const USHORT nDialogExtraDataLen
= 11; // 12345678901
70 SwAsciiFilterDlg::SwAsciiFilterDlg( Window
* pParent
, SwDocShell
& rDocSh
,
72 : SfxModalDialog( pParent
, SW_RES( DLG_ASCII_FILTER
)),
73 aFL( this, SW_RES( FL_1
)),
74 aCharSetFT( this, SW_RES( FT_CHARSET
)),
75 aCharSetLB( this, SW_RES( LB_CHARSET
)),
76 aFontFT( this, SW_RES( FT_FONT
)),
77 aFontLB( this, SW_RES( LB_FONT
)),
78 aLanguageFT( this, SW_RES( FT_LANGUAGE
)),
79 aLanguageLB( this, SW_RES( LB_LANGUAGE
)),
80 aCRLF_FT( this, SW_RES( FT_CRLF
)),
81 aCRLF_RB( this, SW_RES( RB_CRLF
)),
82 aCR_RB( this, SW_RES( RB_CR
)),
83 aLF_RB( this, SW_RES( RB_LF
)),
84 aOkPB( this, SW_RES( PB_OK
)),
85 aCancelPB( this, SW_RES( PB_CANCEL
)),
86 aHelpPB( this, SW_RES( PB_HELP
)),
87 sSystemCharSet( SW_RES( STR_SYS_CHARSET
)),
88 bSaveLineStatus( TRUE
)
94 const String
& rFindNm
= String::CreateFromAscii(
95 pStream
? sDialogImpExtraData
96 : sDialogExpExtraData
);
97 USHORT nEnd
, nStt
= GetExtraData().Search( rFindNm
);
98 if( STRING_NOTFOUND
!= nStt
)
100 nStt
+= nDialogExtraDataLen
;
101 nEnd
= GetExtraData().Search( cDialogExtraDataClose
, nStt
);
102 if( STRING_NOTFOUND
!= nEnd
)
104 aOpt
.ReadUserData( GetExtraData().Copy( nStt
, nEnd
- nStt
));
105 nStt
-= nDialogExtraDataLen
;
106 GetExtraData().Erase( nStt
, nEnd
- nStt
+ 1 );
111 // read the first chars and check the charset, (language - with L&H)
114 char aBuffer
[ 4098 ];
115 ULONG nOldPos
= pStream
->Tell();
116 ULONG nBytesRead
= pStream
->Read( aBuffer
, 4096 );
117 pStream
->Seek( nOldPos
);
119 if( nBytesRead
<= 4096 )
121 aBuffer
[ nBytesRead
] = '0';
122 aBuffer
[ nBytesRead
+1 ] = '0';
123 if( 0 != ( nBytesRead
& 0x00000001 ) )
124 aBuffer
[ nBytesRead
+ 2 ] = '0';
127 BOOL bCR
= FALSE
, bLF
= FALSE
, bNoNormalChar
= FALSE
,
129 for( USHORT nCnt
= 0; nCnt
< nBytesRead
; ++nCnt
)
130 switch( aBuffer
[ nCnt
] )
132 case 0x0: bNullChar
= TRUE
; break;
133 case 0xA: bLF
= TRUE
; break;
134 case 0xD: bCR
= TRUE
; break;
139 if( 0x20 > aBuffer
[ nCnt
] )
140 bNoNormalChar
= TRUE
;
149 aOpt
.SetParaFlags( LINEEND_CRLF
);
150 // have to check if of CharSet is type of ANSI
151 // aOpt.SetCharSet( CHARSET_ANSI );
155 aOpt
.SetParaFlags( LINEEND_CR
);
156 // have to check if CharSet is type of MAC
157 // aOpt.SetCharSet( CHARSET_MAC );
162 aOpt
.SetParaFlags( LINEEND_LF
);
163 // have to check if of CharSet is type of ANSI
164 // aOpt.SetCharSet( CHARSET_ANSI );
168 SwDoc
* pDoc
= rDocSh
.GetDoc();
170 USHORT nAppScriptType
= GetI18NScriptTypeOfLanguage( (USHORT
)GetAppLanguage() );
172 BOOL bDelPrinter
= FALSE
;
173 SfxPrinter
* pPrt
= pDoc
? pDoc
->getPrinter(false) : 0;
176 SfxItemSet
* pSet
= new SfxItemSet( rDocSh
.GetPool(),
177 SID_PRINTER_NOTFOUND_WARN
, SID_PRINTER_NOTFOUND_WARN
,
178 SID_PRINTER_CHANGESTODOC
, SID_PRINTER_CHANGESTODOC
,
180 pPrt
= new SfxPrinter( pSet
);
184 const USHORT nCount
= pPrt
->GetFontCount();
185 for (USHORT i
= 0; i
< nCount
; ++i
)
187 const String
&rStr
= pPrt
->GetFont(i
)->GetName();
188 aFontLB
.InsertEntry( rStr
);
191 if( !aOpt
.GetFontName().Len() )
195 USHORT nFontRes
= RES_CHRATR_FONT
;
196 if(SCRIPTTYPE_ASIAN
== nAppScriptType
)
197 nFontRes
= RES_CHRATR_CJK_FONT
;
198 else if(SCRIPTTYPE_COMPLEX
== nAppScriptType
)
199 nFontRes
= RES_CHRATR_CTL_FONT
;
201 aOpt
.SetFontName( ((SvxFontItem
&)pDoc
->GetDefault(
202 nFontRes
)).GetFamilyName() );
206 USHORT nFontType
= FONT_STANDARD
;
207 if(SCRIPTTYPE_ASIAN
== nAppScriptType
)
208 nFontType
= FONT_STANDARD_CJK
;
209 else if(SCRIPTTYPE_COMPLEX
== nAppScriptType
)
210 nFontType
= FONT_STANDARD_CTL
;
211 aOpt
.SetFontName(SW_MOD()->GetStdFontConfig()->GetFontFor(nFontType
));
214 aFontLB
.SelectEntry( aOpt
.GetFontName() );
220 // initialisiere Sprache
222 if( !aOpt
.GetLanguage() )
226 USHORT nWhich
= GetWhichOfScript( RES_CHRATR_LANGUAGE
, nAppScriptType
);
227 aOpt
.SetLanguage( ((SvxLanguageItem
&)pDoc
->
228 GetDefault( nWhich
)).GetLanguage());
232 SvtLinguOptions aLinguOpt
;
233 SvtLinguConfig().GetOptions( aLinguOpt
);
234 switch(nAppScriptType
)
236 case SCRIPTTYPE_ASIAN
:
237 aOpt
.SetLanguage(aLinguOpt
.nDefaultLanguage_CJK
);
239 case SCRIPTTYPE_COMPLEX
:
240 aOpt
.SetLanguage(aLinguOpt
.nDefaultLanguage_CTL
);
244 aOpt
.SetLanguage(aLinguOpt
.nDefaultLanguage
);
249 aLanguageLB
.SetLanguageList( LANG_LIST_ALL
, TRUE
, FALSE
);
250 aLanguageLB
.SelectLanguage( aOpt
.GetLanguage() );
255 // hide the used Control for the Export and move the
256 // other behind the charset controls
262 long nY
= aFontFT
.GetPosPixel().Y() + 1;
263 Point
aPos( aCRLF_FT
.GetPosPixel() ); aPos
.Y() = nY
;
264 aCRLF_FT
.SetPosPixel( aPos
);
266 aPos
= aCRLF_RB
.GetPosPixel(); aPos
.Y() = nY
;
267 aCRLF_RB
.SetPosPixel( aPos
);
269 aPos
= aCR_RB
.GetPosPixel(); aPos
.Y() = nY
;
270 aCR_RB
.SetPosPixel( aPos
);
272 aPos
= aLF_RB
.GetPosPixel(); aPos
.Y() = nY
;
273 aLF_RB
.SetPosPixel( aPos
);
275 Size aSize
= GetSizePixel();
277 aTmpSz
= LogicToPixel(aTmpSz
, MAP_APPFONT
);
278 aSize
.Height() = aHelpPB
.GetPosPixel().Y() +
279 aHelpPB
.GetSizePixel().Height() + aTmpSz
.Height();
280 SetSizePixel( aSize
);
283 // initialisiere Zeichensatz
284 aCharSetLB
.FillFromTextEncodingTable( pStream
!= NULL
);
285 aCharSetLB
.SelectTextEncoding( aOpt
.GetCharSet() );
287 aCharSetLB
.SetSelectHdl( LINK( this, SwAsciiFilterDlg
, CharSetSelHdl
));
288 aCRLF_RB
.SetToggleHdl( LINK( this, SwAsciiFilterDlg
, LineEndHdl
));
289 aLF_RB
.SetToggleHdl( LINK( this, SwAsciiFilterDlg
, LineEndHdl
));
290 aCR_RB
.SetToggleHdl( LINK( this, SwAsciiFilterDlg
, LineEndHdl
));
292 SetCRLF( aOpt
.GetParaFlags() );
294 aCRLF_RB
.SaveValue();
300 SwAsciiFilterDlg::~SwAsciiFilterDlg()
305 void SwAsciiFilterDlg::FillOptions( SwAsciiOptions
& rOptions
)
307 ULONG nCCode
= aCharSetLB
.GetSelectTextEncoding();
310 if( aFontLB
.IsVisible() )
312 sFont
= aFontLB
.GetSelectEntry();
313 nLng
= (ULONG
)aLanguageLB
.GetSelectLanguage();
316 rOptions
.SetFontName( sFont
);
317 rOptions
.SetCharSet( rtl_TextEncoding( nCCode
) );
318 rOptions
.SetLanguage( USHORT( nLng
) );
319 rOptions
.SetParaFlags( GetCRLF() );
321 // JP: Task #71802# save the user settings
323 rOptions
.WriteUserData( sData
);
326 const String
& rFindNm
= String::CreateFromAscii(
327 aFontLB
.IsVisible() ? sDialogImpExtraData
328 : sDialogExpExtraData
);
329 USHORT nEnd
, nStt
= GetExtraData().Search( rFindNm
);
330 if( STRING_NOTFOUND
!= nStt
)
332 // called twice, so remove "old" settings
333 nEnd
= GetExtraData().Search( cDialogExtraDataClose
,
334 nStt
+ nDialogExtraDataLen
);
335 if( STRING_NOTFOUND
!= nEnd
)
336 GetExtraData().Erase( nStt
, nEnd
- nStt
+ 1 );
338 String
sTmp(GetExtraData());
341 sTmp
+= cDialogExtraDataClose
;
342 GetExtraData() = sTmp
;
346 void SwAsciiFilterDlg::SetCRLF( LineEnd eEnd
)
350 case LINEEND_CR
: aCR_RB
.Check(); break;
351 case LINEEND_CRLF
: aCRLF_RB
.Check(); break;
352 case LINEEND_LF
: aLF_RB
.Check(); break;
356 LineEnd
SwAsciiFilterDlg::GetCRLF() const
359 if( aCR_RB
.IsChecked() )
361 else if( aLF_RB
.IsChecked() )
368 IMPL_LINK( SwAsciiFilterDlg
, CharSetSelHdl
, SvxTextEncodingBox
*, pBox
)
370 LineEnd eOldEnd
= GetCRLF(), eEnd
= (LineEnd
)-1;
371 LanguageType nLng
= aFontLB
.IsVisible()
372 ? aLanguageLB
.GetSelectLanguage()
376 rtl_TextEncoding nChrSet
= pBox
->GetSelectTextEncoding();
377 if( nChrSet
== gsl_getSystemTextEncoding() )
378 eEnd
= GetSystemLineEnd();
383 case RTL_TEXTENCODING_MS_1252
:
387 eEnd
= LINEEND_CRLF
; // ANSI
391 case RTL_TEXTENCODING_APPLE_ROMAN
: // MAC
395 case RTL_TEXTENCODING_IBM_850
: // DOS
399 case RTL_TEXTENCODING_APPLE_ARABIC
:
400 case RTL_TEXTENCODING_APPLE_CENTEURO
:
401 case RTL_TEXTENCODING_APPLE_CROATIAN
:
402 case RTL_TEXTENCODING_APPLE_CYRILLIC
:
403 case RTL_TEXTENCODING_APPLE_DEVANAGARI
:
404 case RTL_TEXTENCODING_APPLE_FARSI
:
405 case RTL_TEXTENCODING_APPLE_GREEK
:
406 case RTL_TEXTENCODING_APPLE_GUJARATI
:
407 case RTL_TEXTENCODING_APPLE_GURMUKHI
:
408 case RTL_TEXTENCODING_APPLE_HEBREW
:
409 case RTL_TEXTENCODING_APPLE_ICELAND
:
410 case RTL_TEXTENCODING_APPLE_ROMANIAN
:
411 case RTL_TEXTENCODING_APPLE_THAI
:
412 case RTL_TEXTENCODING_APPLE_TURKISH
:
413 case RTL_TEXTENCODING_APPLE_UKRAINIAN
:
414 case RTL_TEXTENCODING_APPLE_CHINSIMP
:
415 case RTL_TEXTENCODING_APPLE_CHINTRAD
:
416 case RTL_TEXTENCODING_APPLE_JAPANESE
:
417 case RTL_TEXTENCODING_APPLE_KOREAN
:
423 bSaveLineStatus
= FALSE
;
424 if( eEnd
!= (LineEnd
)-1 ) // changed?
426 if( eOldEnd
!= eEnd
)
431 // restore old user choise (not the automatic!)
432 aCRLF_RB
.Check( aCRLF_RB
.GetSavedValue() );
433 aCR_RB
.Check( aCR_RB
.GetSavedValue() );
434 aLF_RB
.Check( aLF_RB
.GetSavedValue() );
436 bSaveLineStatus
= TRUE
;
438 if( nOldLng
!= nLng
&& aFontLB
.IsVisible() )
439 aLanguageLB
.SelectLanguage( nLng
);
444 IMPL_LINK( SwAsciiFilterDlg
, LineEndHdl
, RadioButton
*, pBtn
)
446 if( bSaveLineStatus
)