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