/src/libreoffice/sw/source/uibase/lingu/sdrhhcwrap.cxx
Line | Count | Source |
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 <vcl/weld/Window.hxx> |
25 | | #include <osl/diagnose.h> |
26 | | #include <drawdoc.hxx> |
27 | | #include "sdrhhcwrap.hxx" |
28 | | #include <docsh.hxx> |
29 | | #include <wrtsh.hxx> |
30 | | #include <view.hxx> |
31 | | #include <dcontact.hxx> |
32 | | #include <doc.hxx> |
33 | | #include <IDocumentDeviceAccess.hxx> |
34 | | #include <IDocumentDrawModelAccess.hxx> |
35 | | #include <edtwin.hxx> |
36 | | |
37 | | using namespace ::com::sun::star; |
38 | | |
39 | | SdrHHCWrapper::SdrHHCWrapper( SwView& rView, |
40 | | LanguageType nSourceLanguage, LanguageType nTargetLanguage, |
41 | | const vcl::Font* pTargetFnt, |
42 | | sal_Int32 nConvOptions, |
43 | | bool bInteractive ) : |
44 | 0 | SdrOutliner(rView.GetDocShell()->GetDoc()->getIDocumentDrawModelAccess().GetDrawModel()-> |
45 | 0 | GetDrawOutliner().GetEmptyItemSet().GetPool(), |
46 | 0 | OutlinerMode::TextObject ), |
47 | 0 | m_rView( rView ), |
48 | 0 | m_pTextObj( nullptr ), |
49 | 0 | m_nOptions( nConvOptions ), |
50 | 0 | m_nDocIndex( 0 ), |
51 | 0 | m_nSourceLang( nSourceLanguage ), |
52 | 0 | m_nTargetLang( nTargetLanguage ), |
53 | 0 | m_pTargetFont( pTargetFnt ), |
54 | 0 | m_bIsInteractive( bInteractive ) |
55 | 0 | { |
56 | 0 | SetRefDevice( m_rView.GetDocShell()->GetDoc()->getIDocumentDeviceAccess().getPrinter( false ) ); |
57 | |
|
58 | 0 | MapMode aMapMode (MapUnit::MapTwip); |
59 | 0 | SetRefMapMode(aMapMode); |
60 | |
|
61 | 0 | Size aSize( 1, 1 ); |
62 | 0 | SetPaperSize( aSize ); |
63 | |
|
64 | 0 | m_pOutlView.reset(new OutlinerView(*this, &(m_rView.GetEditWin()))); |
65 | 0 | m_pOutlView->GetOutliner().SetRefDevice(m_rView.GetWrtShell().getIDocumentDeviceAccess().getPrinter( false )); |
66 | | |
67 | | // Hack: all SdrTextObj attributes should be transferred to EditEngine |
68 | 0 | m_pOutlView->SetBackgroundColor( COL_WHITE ); |
69 | |
|
70 | 0 | InsertView( m_pOutlView.get() ); |
71 | 0 | Point aPoint( 0, 0 ); |
72 | 0 | tools::Rectangle aRect( aPoint, aSize ); |
73 | 0 | m_pOutlView->SetOutputArea( aRect ); |
74 | | // SetText( NULL ); |
75 | 0 | ClearModifyFlag(); |
76 | 0 | } |
77 | | |
78 | | SdrHHCWrapper::~SdrHHCWrapper() |
79 | 0 | { |
80 | 0 | if (m_pTextObj) |
81 | 0 | { |
82 | 0 | SdrView *pSdrView = m_rView.GetWrtShell().GetDrawView(); |
83 | 0 | OSL_ENSURE( pSdrView, "SdrHHCWrapper without DrawView?" ); |
84 | 0 | pSdrView->SdrEndTextEdit( true ); |
85 | 0 | SetUpdateLayout(false); |
86 | 0 | m_pOutlView->SetOutputArea( tools::Rectangle( Point(), Size(1, 1) ) ); |
87 | 0 | } |
88 | 0 | RemoveView( m_pOutlView.get() ); |
89 | 0 | m_pOutlView.reset(); |
90 | 0 | } |
91 | | |
92 | | void SdrHHCWrapper::StartTextConversion() |
93 | 0 | { |
94 | 0 | m_pOutlView->StartTextConversion(m_rView.GetFrameWeld(), m_nSourceLang, m_nTargetLang, m_pTargetFont, m_nOptions, m_bIsInteractive, true); |
95 | 0 | } |
96 | | |
97 | | bool SdrHHCWrapper::ConvertNextDocument() |
98 | 0 | { |
99 | 0 | bool bNextDoc = false; |
100 | |
|
101 | 0 | if ( m_pTextObj ) |
102 | 0 | { |
103 | 0 | SdrView *pSdrView = m_rView.GetWrtShell().GetDrawView(); |
104 | 0 | OSL_ENSURE( pSdrView, "SdrHHCWrapper without DrawView?" ); |
105 | 0 | pSdrView->SdrEndTextEdit( true ); |
106 | 0 | SetUpdateLayout(false); |
107 | 0 | m_pOutlView->SetOutputArea( tools::Rectangle( Point(), Size(1, 1) ) ); |
108 | 0 | SetPaperSize( Size(1, 1) ); |
109 | 0 | Clear(); |
110 | 0 | m_pTextObj = nullptr; |
111 | 0 | } |
112 | |
|
113 | 0 | const auto n = m_nDocIndex; |
114 | |
|
115 | 0 | std::list<SdrTextObj*> aTextObjs; |
116 | 0 | SwDrawContact::GetTextObjectsFromFormat(aTextObjs, *m_rView.GetDocShell()->GetDoc()); |
117 | 0 | for (auto const& textObj : aTextObjs) |
118 | 0 | { |
119 | 0 | m_pTextObj = textObj; |
120 | 0 | if (textObj) |
121 | 0 | { |
122 | 0 | OutlinerParaObject* pParaObj = textObj->GetOutlinerParaObject(); |
123 | 0 | if ( pParaObj ) |
124 | 0 | { |
125 | 0 | SetPaperSize( textObj->GetLogicRect().GetSize() ); |
126 | 0 | SetText( *pParaObj ); |
127 | |
|
128 | 0 | ClearModifyFlag(); |
129 | | |
130 | | //!! update mode needs to be set to true otherwise |
131 | | //!! the call to 'HasConvertibleTextPortion' will not always |
132 | | //!! work correctly because the document may not be properly |
133 | | //!! formatted when some information is accessed, and thus |
134 | | //!! incorrect results get returned. |
135 | 0 | SetUpdateLayout(true); |
136 | 0 | if (HasConvertibleTextPortion( m_nSourceLang )) |
137 | 0 | { |
138 | 0 | SdrView *pSdrView = m_rView.GetWrtShell().GetDrawView(); |
139 | 0 | assert(pSdrView && "SdrHHCWrapper without DrawView?"); |
140 | 0 | SdrPageView* pPV = pSdrView->GetSdrPageView(); |
141 | 0 | m_nDocIndex = n; |
142 | 0 | bNextDoc = true; |
143 | 0 | m_pOutlView->SetOutputArea( tools::Rectangle( Point(), Size(1,1))); |
144 | 0 | SetPaperSize( m_pTextObj->GetLogicRect().GetSize() ); |
145 | 0 | SetUpdateLayout(true); |
146 | 0 | m_rView.GetWrtShell().MakeVisible(SwRect(m_pTextObj->GetLogicRect())); |
147 | |
|
148 | 0 | pSdrView->SdrBeginTextEdit(m_pTextObj, pPV, &m_rView.GetEditWin(), false, this, m_pOutlView.get(), true, true); |
149 | 0 | } |
150 | 0 | else |
151 | 0 | SetUpdateLayout(false); |
152 | 0 | } |
153 | |
|
154 | 0 | if ( !bNextDoc ) |
155 | 0 | m_pTextObj = nullptr; |
156 | 0 | else |
157 | 0 | break; |
158 | 0 | } |
159 | 0 | } |
160 | |
|
161 | 0 | ClearModifyFlag(); |
162 | |
|
163 | 0 | return bNextDoc; |
164 | 0 | } |
165 | | |
166 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |