xref: /trunk/main/sw/source/ui/uno/swdet2.cxx (revision efeef26f)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_sw.hxx"
26 
27 #define _SWLIB_CXX
28 #include <sfx2/docfac.hxx>
29 #include <sfx2/docfilt.hxx>
30 #include <sfx2/fcontnr.hxx>
31 #include <sfx2/docfile.hxx>
32 #include <sfx2/app.hxx>
33 #include <svtools/sfxecode.hxx>
34 #include <vcl/msgbox.hxx>
35 #include <svtools/parhtml.hxx>
36 #include <sot/clsids.hxx>
37 #include <iodetect.hxx>
38 
39 #include <swdetect.hxx>
40 
41 #include <app.hrc>
42 #include <web.hrc>
43 #include <globdoc.hrc>
44 
45 #include <unotools/moduleoptions.hxx>
46 
47 #include <unomid.h>
48 
IsDocShellRegistered()49 bool IsDocShellRegistered()
50 {
51     return SvtModuleOptions().IsWriter();
52 }
53 
54 //-------------------------------------------------------------------------
55 
DetectFilter(SfxMedium & rMedium,const SfxFilter ** ppFilter)56 sal_uLong SwFilterDetect::DetectFilter( SfxMedium& rMedium, const SfxFilter** ppFilter )
57 {
58 	sal_uLong nRet = ERRCODE_NONE;
59     if( *ppFilter )
60     {
61         // verify the given filter
62         String aPrefFlt = (*ppFilter)->GetUserData();
63 
64         // detection for TextFilter needs an additional checking
65         sal_Bool bDetected = SwIoSystem::IsFileFilter( rMedium, aPrefFlt );
66         return bDetected ? nRet : ERRCODE_ABORT;
67     }
68 
69     // mba: without preselection there is no PrefFlt
70     String aPrefFlt;
71     const SfxFilter* pTmp = SwIoSystem::GetFileFilter( rMedium.GetPhysicalName(), aPrefFlt, &rMedium );
72     if( !pTmp )
73         return ERRCODE_ABORT;
74     /*
75     else if( *ppFilter && (*ppFilter)->GetUserData().EqualsAscii( "W4W", 0, 3 )
76                 && pTmp->GetUserData().EqualsAscii( FILTER_TEXT, 0, 4 ) )
77     {
78         // Bug 95262 - if the user (or short  detect) select a
79         //              Word 4 Word filter, but the autodect of mastersoft
80         //              can't detect it, we normally return the ascii filter
81         //              But the user may have a change to use the W4W filter,
82         //              so the SFX must show now a dialog with the 2 filters
83         nRet = ERRCODE_SFX_CONSULTUSER;
84         *ppFilter = pTmp;
85     } */
86 
87     // sollte der voreingestellte Filter ASCII sein und wir haben
88     // ASCII erkannt, dann ist das ein gultiger Filter, ansonsten ist das
89     // ein Fehler und wir wollen die Filterbox sehen
90     /*
91     else if( pTmp->GetUserData().EqualsAscii( FILTER_TEXT ) )
92     {
93         // Bug 28974: "Text" erkannt, aber "Text Dos" "Text ..." eingestellt
94         //  -> keine FilterBox, sondern den eingestellten Filter benutzen
95         if( *ppFilter && (*ppFilter)->GetUserData().EqualsAscii( FILTER_TEXT, 0, 4 ) )
96             ;
97         else
98 //          if( !*ppFilter || COMPARE_EQUAL != pTmp->GetUserData().Compare((*ppFilter)->GetUserData(), 4 ))
99         {
100 //              nRet = ERRCODE_ABORT;
101             *ppFilter = pTmp;
102         }
103     } */
104     else
105     {
106         //Bug 41417: JP 09.07.97: HTML documents should be loaded by WebWriter
107         SfxFilterContainer aFilterContainer( String::CreateFromAscii("swriter/web") );
108         if( pTmp->GetUserData() != C2S(sHTML) ||
109             String::CreateFromAscii( "com.sun.star.text.WebDocument" ) ==
110             String( pTmp->GetServiceName() ) ||
111             0 == ( (*ppFilter) = SwIoSystem::GetFilterOfFormat( C2S(sHTML),
112                     &aFilterContainer ) ) )
113             *ppFilter = pTmp;
114     }
115 
116 	return nRet;
117 }
118 
119