xref: /trunk/main/sw/source/ui/lingu/sdrhhcwrap.cxx (revision 1ecadb572e7010ff3b3382ad9bf179dbc6efadbb)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_sw.hxx"
30 #include <hintids.hxx>
31 #include <svx/svditer.hxx>
32 #include <svx/svdotext.hxx>
33 #include <editeng/editdata.hxx>
34 #include <svx/svdpagv.hxx>
35 #include <svx/svdogrp.hxx>
36 #include <sfx2/printer.hxx>
37 #include <svx/svdmodel.hxx>
38 #include <editeng/langitem.hxx>
39 #include <com/sun/star/beans/XPropertySet.hpp>
40 #include <linguistic/lngprops.hxx>
41 #include <sfx2/sfxuno.hxx>
42 #include <svx/svdview.hxx>
43 #include <editeng/unolingu.hxx>
44 #include <unotools/localedatawrapper.hxx>
45 #include <sdrhhcwrap.hxx>
46 #include <frmfmt.hxx>
47 #ifndef _DOCSH_HXX
48 #include <docsh.hxx>        //     "     "     "
49 #endif
50 #include <wrtsh.hxx>        //  MakeVisible
51 #ifndef _VIEW_HXX
52 #include <view.hxx>
53 #endif
54 #include <dcontact.hxx>     // Spelling von DrawObj
55 #include <doc.hxx>        //     "     "     "
56 #include <docary.hxx>
57 #include <edtwin.hxx>
58 
59 using namespace ::com::sun::star;
60 using ::rtl::OUString;
61 
62 //////////////////////////////////////////////////////////////////////
63 
64 SdrHHCWrapper::SdrHHCWrapper( SwView* pVw,
65        LanguageType nSourceLanguage, LanguageType nTargetLanguage,
66        const Font* pTargetFnt,
67        sal_Int32 nConvOptions,
68        sal_Bool bInteractive ) :
69     SdrOutliner(pVw->GetDocShell()->GetDoc()->GetDrawModel()->
70                              GetDrawOutliner().GetEmptyItemSet().GetPool(),
71                 OUTLINERMODE_TEXTOBJECT ),
72     pView( pVw ),
73     pTextObj( NULL ),
74     pOutlView( NULL ),
75     nOptions( nConvOptions ),
76     nDocIndex( 0 ),
77     nSourceLang( nSourceLanguage ),
78     nTargetLang( nTargetLanguage ),
79     pTargetFont( pTargetFnt ),
80     bIsInteractive( bInteractive )
81 {
82     SetRefDevice( pView->GetDocShell()->GetDoc()->getPrinter( false ) );
83 
84     MapMode aMapMode (MAP_TWIP);
85     SetRefMapMode(aMapMode);
86 
87     Size aSize( 1, 1 );
88     SetPaperSize( aSize );
89 
90     pOutlView = new OutlinerView( this, &(pView->GetEditWin()) );
91     pOutlView->GetOutliner()->SetRefDevice(pView->GetWrtShell().getIDocumentDeviceAccess()->getPrinter( false ));
92 
93     // Hack: Es sollten alle SdrTextObj-Attribute an die EditEngine
94     //       uebertragen werden.
95     pOutlView->SetBackgroundColor( Color( COL_WHITE ) );
96 
97 
98     InsertView( pOutlView );
99     Point aPoint( 0, 0 );
100     Rectangle aRect( aPoint, aSize );
101     pOutlView->SetOutputArea( aRect );
102 //  SetText( NULL );
103     ClearModifyFlag();
104 }
105 
106 SdrHHCWrapper::~SdrHHCWrapper()
107 {
108     if (pTextObj)
109     {
110         SdrView *pSdrView = pView->GetWrtShell().GetDrawView();
111         ASSERT( pSdrView, "SdrHHCWrapper without DrawView?" );
112         pSdrView->SdrEndTextEdit( sal_True );
113         SetUpdateMode(sal_False);
114         pOutlView->SetOutputArea( Rectangle( Point(), Size(1, 1) ) );
115 //      SetPaperSize( Size(1, 1) );
116 //      SetText(NULL);
117 //      pTextObj = NULL;
118     }
119     RemoveView( pOutlView );
120     delete pOutlView;
121 }
122 
123 
124 void SdrHHCWrapper::StartTextConversion()
125 {
126     pOutlView->StartTextConversion( nSourceLang, nTargetLang, pTargetFont, nOptions, bIsInteractive, sal_True );
127 }
128 
129 
130 sal_Bool SdrHHCWrapper::ConvertNextDocument()
131 {
132     sal_Bool bNextDoc = sal_False;
133 
134     if ( pTextObj )
135     {
136         SdrView *pSdrView = pView->GetWrtShell().GetDrawView();
137         ASSERT( pSdrView, "SdrHHCWrapper without DrawView?" );
138         pSdrView->SdrEndTextEdit( sal_True );
139         SetUpdateMode(sal_False);
140         pOutlView->SetOutputArea( Rectangle( Point(), Size(1, 1) ) );
141         SetPaperSize( Size(1, 1) );
142         Clear();
143         pTextObj = NULL;
144     }
145 
146     sal_uInt16 n = nDocIndex;
147 
148     std::list<SdrTextObj*> aTextObjs;
149     SwDrawContact::GetTextObjectsFromFmt( aTextObjs, pView->GetDocShell()->GetDoc() );
150     for ( std::list<SdrTextObj*>::iterator aIt = aTextObjs.begin(); aIt != aTextObjs.end(); aIt++ )
151     {
152         pTextObj = (*aIt);
153         if ( pTextObj )
154         {
155             OutlinerParaObject* pParaObj = pTextObj->GetOutlinerParaObject();
156             if ( pParaObj )
157             {
158                 SetPaperSize( pTextObj->GetLogicRect().GetSize() );
159                 SetText( *pParaObj );
160 
161                 ClearModifyFlag();
162 
163                 //!! update mode needs to be set to true otherwise
164                 //!! the call to 'HasConvertibleTextPortion' will not always
165                 //!! work correctly because the document may not be properly
166                 //!! formatted when some information is accessed, and thus
167                 //!! incorrect results get returned.
168                 SetUpdateMode(sal_True);
169                 if (HasConvertibleTextPortion( nSourceLang ))
170                 {
171                     SdrView *pSdrView = pView->GetWrtShell().GetDrawView();
172                     ASSERT( pSdrView, "SdrHHCWrapper without DrawView?" );
173                     SdrPageView* pPV = pSdrView->GetSdrPageView();
174                     nDocIndex = n;
175                     bNextDoc = sal_True;
176                     pOutlView->SetOutputArea( Rectangle( Point(), Size(1,1)));
177                     SetPaperSize( pTextObj->GetLogicRect().GetSize() );
178                     SetUpdateMode(sal_True);
179                     pView->GetWrtShell().MakeVisible(pTextObj->GetLogicRect());
180 
181                     pSdrView->SdrBeginTextEdit(pTextObj, pPV, &pView->GetEditWin(), sal_False, this, pOutlView, sal_True, sal_True);
182                 }
183                 else
184                     SetUpdateMode(sal_False);
185             }
186 
187             if ( !bNextDoc )
188                 pTextObj = NULL;
189             else
190                 break;
191         }
192     }
193 
194     ClearModifyFlag();
195 
196     return bNextDoc;
197 }
198 
199 //////////////////////////////////////////////////////////////////////
200 
201