Line data Source code
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 <hintids.hxx>
21 : #include <svx/svditer.hxx>
22 : #include <svx/svdotext.hxx>
23 : #include <editeng/editdata.hxx>
24 : #include <svx/svdpagv.hxx>
25 : #include <svx/svdogrp.hxx>
26 : #include <sfx2/printer.hxx>
27 : #include <svx/svdmodel.hxx>
28 : #include <editeng/langitem.hxx>
29 : #include <com/sun/star/beans/XPropertySet.hpp>
30 : #include <linguistic/lngprops.hxx>
31 : #include <sfx2/sfxuno.hxx>
32 : #include <svx/svdview.hxx>
33 : #include <editeng/unolingu.hxx>
34 : #include <unotools/localedatawrapper.hxx>
35 : #include <sdrhhcwrap.hxx>
36 : #include <frmfmt.hxx>
37 : #include <docsh.hxx>
38 : #include <wrtsh.hxx>
39 : #include <view.hxx>
40 : #include <dcontact.hxx>
41 : #include <doc.hxx>
42 : #include <docary.hxx>
43 : #include <edtwin.hxx>
44 :
45 : using namespace ::com::sun::star;
46 :
47 0 : SdrHHCWrapper::SdrHHCWrapper( SwView* pVw,
48 : LanguageType nSourceLanguage, LanguageType nTargetLanguage,
49 : const Font* pTargetFnt,
50 : sal_Int32 nConvOptions,
51 : bool bInteractive ) :
52 0 : SdrOutliner(pVw->GetDocShell()->GetDoc()->GetDrawModel()->
53 0 : GetDrawOutliner().GetEmptyItemSet().GetPool(),
54 : OUTLINERMODE_TEXTOBJECT ),
55 : pView( pVw ),
56 : pTextObj( NULL ),
57 : pOutlView( NULL ),
58 : nOptions( nConvOptions ),
59 : nDocIndex( 0 ),
60 : nSourceLang( nSourceLanguage ),
61 : nTargetLang( nTargetLanguage ),
62 : pTargetFont( pTargetFnt ),
63 0 : bIsInteractive( bInteractive )
64 : {
65 0 : SetRefDevice( pView->GetDocShell()->GetDoc()->getPrinter( false ) );
66 :
67 0 : MapMode aMapMode (MAP_TWIP);
68 0 : SetRefMapMode(aMapMode);
69 :
70 0 : Size aSize( 1, 1 );
71 0 : SetPaperSize( aSize );
72 :
73 0 : pOutlView = new OutlinerView( this, &(pView->GetEditWin()) );
74 0 : pOutlView->GetOutliner()->SetRefDevice(pView->GetWrtShell().getIDocumentDeviceAccess()->getPrinter( false ));
75 :
76 : // Hack: all SdrTextObj attributes should be transferred to EditEngine
77 0 : pOutlView->SetBackgroundColor( Color( COL_WHITE ) );
78 :
79 0 : InsertView( pOutlView );
80 0 : Point aPoint( 0, 0 );
81 0 : Rectangle aRect( aPoint, aSize );
82 0 : pOutlView->SetOutputArea( aRect );
83 : // SetText( NULL );
84 0 : ClearModifyFlag();
85 0 : }
86 :
87 0 : SdrHHCWrapper::~SdrHHCWrapper()
88 : {
89 0 : if (pTextObj)
90 : {
91 0 : SdrView *pSdrView = pView->GetWrtShell().GetDrawView();
92 : OSL_ENSURE( pSdrView, "SdrHHCWrapper without DrawView?" );
93 0 : pSdrView->SdrEndTextEdit( true );
94 0 : SetUpdateMode(false);
95 0 : pOutlView->SetOutputArea( Rectangle( Point(), Size(1, 1) ) );
96 : }
97 0 : RemoveView( pOutlView );
98 0 : delete pOutlView;
99 0 : }
100 :
101 0 : void SdrHHCWrapper::StartTextConversion()
102 : {
103 0 : pOutlView->StartTextConversion( nSourceLang, nTargetLang, pTargetFont, nOptions, bIsInteractive, true );
104 0 : }
105 :
106 0 : bool SdrHHCWrapper::ConvertNextDocument()
107 : {
108 0 : bool bNextDoc = false;
109 :
110 0 : if ( pTextObj )
111 : {
112 0 : SdrView *pSdrView = pView->GetWrtShell().GetDrawView();
113 : OSL_ENSURE( pSdrView, "SdrHHCWrapper without DrawView?" );
114 0 : pSdrView->SdrEndTextEdit( true );
115 0 : SetUpdateMode(false);
116 0 : pOutlView->SetOutputArea( Rectangle( Point(), Size(1, 1) ) );
117 0 : SetPaperSize( Size(1, 1) );
118 0 : Clear();
119 0 : pTextObj = NULL;
120 : }
121 :
122 0 : sal_uInt16 n = nDocIndex;
123 :
124 0 : std::list<SdrTextObj*> aTextObjs;
125 0 : SwDrawContact::GetTextObjectsFromFmt( aTextObjs, pView->GetDocShell()->GetDoc() );
126 0 : for ( std::list<SdrTextObj*>::iterator aIt = aTextObjs.begin(); aIt != aTextObjs.end(); ++aIt )
127 : {
128 0 : pTextObj = (*aIt);
129 0 : if ( pTextObj )
130 : {
131 0 : OutlinerParaObject* pParaObj = pTextObj->GetOutlinerParaObject();
132 0 : if ( pParaObj )
133 : {
134 0 : SetPaperSize( pTextObj->GetLogicRect().GetSize() );
135 0 : SetText( *pParaObj );
136 :
137 0 : ClearModifyFlag();
138 :
139 : //!! update mode needs to be set to true otherwise
140 : //!! the call to 'HasConvertibleTextPortion' will not always
141 : //!! work correctly because the document may not be properly
142 : //!! formatted when some information is accessed, and thus
143 : //!! incorrect results get returned.
144 0 : SetUpdateMode(true);
145 0 : if (HasConvertibleTextPortion( nSourceLang ))
146 : {
147 0 : SdrView *pSdrView = pView->GetWrtShell().GetDrawView();
148 : OSL_ENSURE( pSdrView, "SdrHHCWrapper without DrawView?" );
149 0 : SdrPageView* pPV = pSdrView->GetSdrPageView();
150 0 : nDocIndex = n;
151 0 : bNextDoc = true;
152 0 : pOutlView->SetOutputArea( Rectangle( Point(), Size(1,1)));
153 0 : SetPaperSize( pTextObj->GetLogicRect().GetSize() );
154 0 : SetUpdateMode(true);
155 0 : pView->GetWrtShell().MakeVisible(pTextObj->GetLogicRect());
156 :
157 0 : pSdrView->SdrBeginTextEdit(pTextObj, pPV, &pView->GetEditWin(), false, this, pOutlView, true, true);
158 : }
159 : else
160 0 : SetUpdateMode(false);
161 : }
162 :
163 0 : if ( !bNextDoc )
164 0 : pTextObj = NULL;
165 : else
166 0 : break;
167 : }
168 : }
169 :
170 0 : ClearModifyFlag();
171 :
172 0 : return bNextDoc;
173 : }
174 :
175 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|