1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
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>
35
36 using namespace ::com::sun::star;
37
SdrHHCWrapper(SwView * pVw,LanguageType nSourceLanguage,LanguageType nTargetLanguage,const vcl::Font * pTargetFnt,sal_Int32 nConvOptions,bool bInteractive)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 pView( pVw ),
47 pTextObj( nullptr ),
48 nOptions( nConvOptions ),
49 nDocIndex( 0 ),
50 nSourceLang( nSourceLanguage ),
51 nTargetLang( nTargetLanguage ),
52 pTargetFont( pTargetFnt ),
53 bIsInteractive( bInteractive )
54 {
55 SetRefDevice( pView->GetDocShell()->GetDoc()->getIDocumentDeviceAccess().getPrinter( false ) );
56
57 MapMode aMapMode (MapUnit::MapTwip);
58 SetRefMapMode(aMapMode);
59
60 Size aSize( 1, 1 );
61 SetPaperSize( aSize );
62
63 pOutlView.reset( new OutlinerView( this, &(pView->GetEditWin()) ) );
64 pOutlView->GetOutliner()->SetRefDevice(pView->GetWrtShell().getIDocumentDeviceAccess().getPrinter( false ));
65
66 // Hack: all SdrTextObj attributes should be transferred to EditEngine
67 pOutlView->SetBackgroundColor( COL_WHITE );
68
69 InsertView( pOutlView.get() );
70 Point aPoint( 0, 0 );
71 tools::Rectangle aRect( aPoint, aSize );
72 pOutlView->SetOutputArea( aRect );
73 // SetText( NULL );
74 ClearModifyFlag();
75 }
76
~SdrHHCWrapper()77 SdrHHCWrapper::~SdrHHCWrapper()
78 {
79 if (pTextObj)
80 {
81 SdrView *pSdrView = pView->GetWrtShell().GetDrawView();
82 OSL_ENSURE( pSdrView, "SdrHHCWrapper without DrawView?" );
83 pSdrView->SdrEndTextEdit( true );
84 SetUpdateMode(false);
85 pOutlView->SetOutputArea( tools::Rectangle( Point(), Size(1, 1) ) );
86 }
87 RemoveView( pOutlView.get() );
88 pOutlView.reset();
89 }
90
StartTextConversion()91 void SdrHHCWrapper::StartTextConversion()
92 {
93 pOutlView->StartTextConversion(pView->GetFrameWeld(), nSourceLang, nTargetLang, pTargetFont, nOptions, bIsInteractive, true);
94 }
95
ConvertNextDocument()96 bool SdrHHCWrapper::ConvertNextDocument()
97 {
98 bool bNextDoc = false;
99
100 if ( pTextObj )
101 {
102 SdrView *pSdrView = pView->GetWrtShell().GetDrawView();
103 OSL_ENSURE( pSdrView, "SdrHHCWrapper without DrawView?" );
104 pSdrView->SdrEndTextEdit( true );
105 SetUpdateMode(false);
106 pOutlView->SetOutputArea( tools::Rectangle( Point(), Size(1, 1) ) );
107 SetPaperSize( Size(1, 1) );
108 Clear();
109 pTextObj = nullptr;
110 }
111
112 const auto n = nDocIndex;
113
114 std::list<SdrTextObj*> aTextObjs;
115 SwDrawContact::GetTextObjectsFromFormat(aTextObjs, *pView->GetDocShell()->GetDoc());
116 for (auto const& textObj : aTextObjs)
117 {
118 pTextObj = textObj;
119 if (textObj)
120 {
121 OutlinerParaObject* pParaObj = textObj->GetOutlinerParaObject();
122 if ( pParaObj )
123 {
124 SetPaperSize( textObj->GetLogicRect().GetSize() );
125 SetText( *pParaObj );
126
127 ClearModifyFlag();
128
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 SetUpdateMode(true);
135 if (HasConvertibleTextPortion( nSourceLang ))
136 {
137 SdrView *pSdrView = pView->GetWrtShell().GetDrawView();
138 OSL_ENSURE( pSdrView, "SdrHHCWrapper without DrawView?" );
139 SdrPageView* pPV = pSdrView->GetSdrPageView();
140 nDocIndex = n;
141 bNextDoc = true;
142 pOutlView->SetOutputArea( tools::Rectangle( Point(), Size(1,1)));
143 SetPaperSize( pTextObj->GetLogicRect().GetSize() );
144 SetUpdateMode(true);
145 pView->GetWrtShell().MakeVisible(SwRect(pTextObj->GetLogicRect()));
146
147 pSdrView->SdrBeginTextEdit(pTextObj, pPV, &pView->GetEditWin(), false, this, pOutlView.get(), true, true);
148 }
149 else
150 SetUpdateMode(false);
151 }
152
153 if ( !bNextDoc )
154 pTextObj = nullptr;
155 else
156 break;
157 }
158 }
159
160 ClearModifyFlag();
161
162 return bNextDoc;
163 }
164
165 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
166