xref: /aoo4110/main/sw/source/ui/lingu/sdrhhcwrap.cxx (revision b1cdbd2c)
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 #include <hintids.hxx>
27 #include <svx/svditer.hxx>
28 #include <svx/svdotext.hxx>
29 #include <editeng/editdata.hxx>
30 #include <svx/svdpagv.hxx>
31 #include <svx/svdogrp.hxx>
32 #include <sfx2/printer.hxx>
33 #include <svx/svdmodel.hxx>
34 #include <editeng/langitem.hxx>
35 #include <com/sun/star/beans/XPropertySet.hpp>
36 #include <linguistic/lngprops.hxx>
37 #include <sfx2/sfxuno.hxx>
38 #include <svx/svdview.hxx>
39 #include <editeng/unolingu.hxx>
40 #include <unotools/localedatawrapper.hxx>
41 #include <sdrhhcwrap.hxx>
42 #include <frmfmt.hxx>
43 #ifndef _DOCSH_HXX
44 #include <docsh.hxx>        //     "     "     "
45 #endif
46 #include <wrtsh.hxx>        //  MakeVisible
47 #ifndef _VIEW_HXX
48 #include <view.hxx>
49 #endif
50 #include <dcontact.hxx>		// Spelling von DrawObj
51 #include <doc.hxx>        //     "     "     "
52 #include <docary.hxx>
53 #include <edtwin.hxx>
54 
55 using namespace ::com::sun::star;
56 using ::rtl::OUString;
57 
58 //////////////////////////////////////////////////////////////////////
59 
SdrHHCWrapper(SwView * pVw,LanguageType nSourceLanguage,LanguageType nTargetLanguage,const Font * pTargetFnt,sal_Int32 nConvOptions,sal_Bool bInteractive)60 SdrHHCWrapper::SdrHHCWrapper( SwView* pVw,
61        LanguageType nSourceLanguage, LanguageType nTargetLanguage,
62        const Font* pTargetFnt,
63        sal_Int32 nConvOptions,
64        sal_Bool bInteractive ) :
65 	SdrOutliner(pVw->GetDocShell()->GetDoc()->GetDrawModel()->
66 							 GetDrawOutliner().GetEmptyItemSet().GetPool(),
67                 OUTLINERMODE_TEXTOBJECT ),
68 	pView( pVw ),
69 	pTextObj( NULL ),
70 	pOutlView( NULL ),
71     nOptions( nConvOptions ),
72     nDocIndex( 0 ),
73     nSourceLang( nSourceLanguage ),
74     nTargetLang( nTargetLanguage ),
75     pTargetFont( pTargetFnt ),
76     bIsInteractive( bInteractive )
77 {
78     SetRefDevice( pView->GetDocShell()->GetDoc()->getPrinter( false ) );
79 
80 	MapMode aMapMode (MAP_TWIP);
81 	SetRefMapMode(aMapMode);
82 
83  	Size aSize( 1, 1 );
84 	SetPaperSize( aSize );
85 
86 	pOutlView = new OutlinerView( this, &(pView->GetEditWin()) );
87     pOutlView->GetOutliner()->SetRefDevice(pView->GetWrtShell().getIDocumentDeviceAccess()->getPrinter( false ));
88 
89 	// Hack: Es sollten alle SdrTextObj-Attribute an die EditEngine
90 	//		 uebertragen werden.
91 	pOutlView->SetBackgroundColor( Color( COL_WHITE ) );
92 
93 
94 	InsertView( pOutlView );
95 	Point aPoint( 0, 0 );
96  	Rectangle aRect( aPoint, aSize );
97 	pOutlView->SetOutputArea( aRect );
98 //	SetText( NULL );
99 	ClearModifyFlag();
100 }
101 
~SdrHHCWrapper()102 SdrHHCWrapper::~SdrHHCWrapper()
103 {
104 	if (pTextObj)
105 	{
106 		SdrView *pSdrView = pView->GetWrtShell().GetDrawView();
107         ASSERT( pSdrView, "SdrHHCWrapper without DrawView?" );
108 		pSdrView->SdrEndTextEdit( sal_True );
109 		SetUpdateMode(sal_False);
110 		pOutlView->SetOutputArea( Rectangle( Point(), Size(1, 1) ) );
111 //		SetPaperSize( Size(1, 1) );
112 //		SetText(NULL);
113 //		pTextObj = NULL;
114 	}
115 	RemoveView( pOutlView );
116 	delete pOutlView;
117 }
118 
119 
StartTextConversion()120 void SdrHHCWrapper::StartTextConversion()
121 {
122     pOutlView->StartTextConversion( nSourceLang, nTargetLang, pTargetFont, nOptions, bIsInteractive, sal_True );
123 }
124 
125 
ConvertNextDocument()126 sal_Bool SdrHHCWrapper::ConvertNextDocument()
127 {
128 	sal_Bool bNextDoc = sal_False;
129 
130 	if ( pTextObj )
131 	{
132         SdrView *pSdrView = pView->GetWrtShell().GetDrawView();
133         ASSERT( pSdrView, "SdrHHCWrapper without DrawView?" );
134 		pSdrView->SdrEndTextEdit( sal_True );
135 		SetUpdateMode(sal_False);
136 		pOutlView->SetOutputArea( Rectangle( Point(), Size(1, 1) ) );
137 		SetPaperSize( Size(1, 1) );
138 		Clear();
139 		pTextObj = NULL;
140 	}
141 
142 	sal_uInt16 n = nDocIndex;
143 
144     std::list<SdrTextObj*> aTextObjs;
145     SwDrawContact::GetTextObjectsFromFmt( aTextObjs, pView->GetDocShell()->GetDoc() );
146     for ( std::list<SdrTextObj*>::iterator aIt = aTextObjs.begin(); aIt != aTextObjs.end(); aIt++ )
147 	{
148         pTextObj = (*aIt);
149 		if ( pTextObj )
150 		{
151 			OutlinerParaObject* pParaObj = pTextObj->GetOutlinerParaObject();
152 			if ( pParaObj )
153 			{
154 				SetPaperSize( pTextObj->GetLogicRect().GetSize() );
155 				SetText( *pParaObj );
156 
157 				ClearModifyFlag();
158 
159                 //!! update mode needs to be set to true otherwise
160                 //!! the call to 'HasConvertibleTextPortion' will not always
161                 //!! work correctly because the document may not be properly
162                 //!! formatted when some information is accessed, and thus
163                 //!! incorrect results get returned.
164                 SetUpdateMode(sal_True);
165                 if (HasConvertibleTextPortion( nSourceLang ))
166 				{
167                     SdrView *pSdrView = pView->GetWrtShell().GetDrawView();
168                     ASSERT( pSdrView, "SdrHHCWrapper without DrawView?" );
169 					SdrPageView* pPV = pSdrView->GetSdrPageView();
170 					nDocIndex = n;
171 					bNextDoc = sal_True;
172 					pOutlView->SetOutputArea( Rectangle( Point(), Size(1,1)));
173 					SetPaperSize( pTextObj->GetLogicRect().GetSize() );
174 					SetUpdateMode(sal_True);
175 					pView->GetWrtShell().MakeVisible(pTextObj->GetLogicRect());
176 
177 					pSdrView->SdrBeginTextEdit(pTextObj, pPV, &pView->GetEditWin(), sal_False, this, pOutlView, sal_True, sal_True);
178 				}
179                 else
180                     SetUpdateMode(sal_False);
181 			}
182 
183 			if ( !bNextDoc )
184 				pTextObj = NULL;
185             else
186                 break;
187 		}
188 	}
189 
190 	ClearModifyFlag();
191 
192 	return bNextDoc;
193 }
194 
195 //////////////////////////////////////////////////////////////////////
196 
197