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