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