Version 7.6.3.2-android, tag libreoffice-7.6.3.2-android
[LibreOffice.git] / sw / source / uibase / lingu / sdrhhcwrap.cxx
blob6df5911fd2808f0ed8c8567d34318592f033bbd0
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <svx/svdotext.hxx>
21 #include <svx/svdpagv.hxx>
22 #include <sfx2/printer.hxx>
23 #include <svx/svdview.hxx>
24 #include <osl/diagnose.h>
25 #include <drawdoc.hxx>
26 #include "sdrhhcwrap.hxx"
27 #include <docsh.hxx>
28 #include <wrtsh.hxx>
29 #include <view.hxx>
30 #include <dcontact.hxx>
31 #include <doc.hxx>
32 #include <IDocumentDeviceAccess.hxx>
33 #include <IDocumentDrawModelAccess.hxx>
34 #include <edtwin.hxx>
36 using namespace ::com::sun::star;
38 SdrHHCWrapper::SdrHHCWrapper( SwView* pVw,
39 LanguageType nSourceLanguage, LanguageType nTargetLanguage,
40 const vcl::Font* pTargetFnt,
41 sal_Int32 nConvOptions,
42 bool bInteractive ) :
43 SdrOutliner(pVw->GetDocShell()->GetDoc()->getIDocumentDrawModelAccess().GetDrawModel()->
44 GetDrawOutliner().GetEmptyItemSet().GetPool(),
45 OutlinerMode::TextObject ),
46 m_pView( pVw ),
47 m_pTextObj( nullptr ),
48 m_nOptions( nConvOptions ),
49 m_nDocIndex( 0 ),
50 m_nSourceLang( nSourceLanguage ),
51 m_nTargetLang( nTargetLanguage ),
52 m_pTargetFont( pTargetFnt ),
53 m_bIsInteractive( bInteractive )
55 SetRefDevice( m_pView->GetDocShell()->GetDoc()->getIDocumentDeviceAccess().getPrinter( false ) );
57 MapMode aMapMode (MapUnit::MapTwip);
58 SetRefMapMode(aMapMode);
60 Size aSize( 1, 1 );
61 SetPaperSize( aSize );
63 m_pOutlView.reset( new OutlinerView( this, &(m_pView->GetEditWin()) ) );
64 m_pOutlView->GetOutliner()->SetRefDevice(m_pView->GetWrtShell().getIDocumentDeviceAccess().getPrinter( false ));
66 // Hack: all SdrTextObj attributes should be transferred to EditEngine
67 m_pOutlView->SetBackgroundColor( COL_WHITE );
69 InsertView( m_pOutlView.get() );
70 Point aPoint( 0, 0 );
71 tools::Rectangle aRect( aPoint, aSize );
72 m_pOutlView->SetOutputArea( aRect );
73 // SetText( NULL );
74 ClearModifyFlag();
77 SdrHHCWrapper::~SdrHHCWrapper()
79 if (m_pTextObj)
81 SdrView *pSdrView = m_pView->GetWrtShell().GetDrawView();
82 OSL_ENSURE( pSdrView, "SdrHHCWrapper without DrawView?" );
83 pSdrView->SdrEndTextEdit( true );
84 SetUpdateLayout(false);
85 m_pOutlView->SetOutputArea( tools::Rectangle( Point(), Size(1, 1) ) );
87 RemoveView( m_pOutlView.get() );
88 m_pOutlView.reset();
91 void SdrHHCWrapper::StartTextConversion()
93 m_pOutlView->StartTextConversion(m_pView->GetFrameWeld(), m_nSourceLang, m_nTargetLang, m_pTargetFont, m_nOptions, m_bIsInteractive, true);
96 bool SdrHHCWrapper::ConvertNextDocument()
98 bool bNextDoc = false;
100 if ( m_pTextObj )
102 SdrView *pSdrView = m_pView->GetWrtShell().GetDrawView();
103 OSL_ENSURE( pSdrView, "SdrHHCWrapper without DrawView?" );
104 pSdrView->SdrEndTextEdit( true );
105 SetUpdateLayout(false);
106 m_pOutlView->SetOutputArea( tools::Rectangle( Point(), Size(1, 1) ) );
107 SetPaperSize( Size(1, 1) );
108 Clear();
109 m_pTextObj = nullptr;
112 const auto n = m_nDocIndex;
114 std::list<SdrTextObj*> aTextObjs;
115 SwDrawContact::GetTextObjectsFromFormat(aTextObjs, *m_pView->GetDocShell()->GetDoc());
116 for (auto const& textObj : aTextObjs)
118 m_pTextObj = textObj;
119 if (textObj)
121 OutlinerParaObject* pParaObj = textObj->GetOutlinerParaObject();
122 if ( pParaObj )
124 SetPaperSize( textObj->GetLogicRect().GetSize() );
125 SetText( *pParaObj );
127 ClearModifyFlag();
129 //!! update mode needs to be set to true otherwise
130 //!! the call to 'HasConvertibleTextPortion' will not always
131 //!! work correctly because the document may not be properly
132 //!! formatted when some information is accessed, and thus
133 //!! incorrect results get returned.
134 SetUpdateLayout(true);
135 if (HasConvertibleTextPortion( m_nSourceLang ))
137 SdrView *pSdrView = m_pView->GetWrtShell().GetDrawView();
138 OSL_ENSURE( pSdrView, "SdrHHCWrapper without DrawView?" );
139 SdrPageView* pPV = pSdrView->GetSdrPageView();
140 m_nDocIndex = n;
141 bNextDoc = true;
142 m_pOutlView->SetOutputArea( tools::Rectangle( Point(), Size(1,1)));
143 SetPaperSize( m_pTextObj->GetLogicRect().GetSize() );
144 SetUpdateLayout(true);
145 m_pView->GetWrtShell().MakeVisible(SwRect(m_pTextObj->GetLogicRect()));
147 pSdrView->SdrBeginTextEdit(m_pTextObj, pPV, &m_pView->GetEditWin(), false, this, m_pOutlView.get(), true, true);
149 else
150 SetUpdateLayout(false);
153 if ( !bNextDoc )
154 m_pTextObj = nullptr;
155 else
156 break;
160 ClearModifyFlag();
162 return bNextDoc;
165 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */