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