LibreOffice Module sd (master) 1
fuhhconv.cxx
Go to the documentation of this file.
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 <com/sun/star/i18n/TextConversionOption.hpp>
21
22#include <com/sun/star/ui/dialogs/XExecutableDialog.hpp>
23#include <com/sun/star/lang/XMultiComponentFactory.hpp>
24#include <com/sun/star/lang/XInitialization.hpp>
25#include <com/sun/star/awt/XWindow.hpp>
26#include <com/sun/star/beans/XPropertySet.hpp>
29#include <svl/style.hxx>
30#include <editeng/eeitem.hxx>
31#include <editeng/langitem.hxx>
32#include <editeng/fontitem.hxx>
33
34#include <fuhhconv.hxx>
35#include <drawdoc.hxx>
36#include <Outliner.hxx>
37#include <DrawViewShell.hxx>
38#include <OutlineViewShell.hxx>
39#include <Window.hxx>
40#include <ViewShellBase.hxx>
41
42#include <sdresid.hxx>
43#include <strings.hrc>
44
45class SfxRequest;
46
47using namespace ::com::sun::star;
48using namespace ::com::sun::star::beans;
49using namespace ::com::sun::star::uno;
50
51namespace sd {
52
53
55 ViewShell* pViewSh,
56 ::sd::Window* pWin,
57 ::sd::View* pView,
58 SdDrawDocument* pDocument,
59 SfxRequest& rReq )
60 : FuPoor(pViewSh, pWin, pView, pDocument, rReq),
61 pSdOutliner(nullptr),
62 bOwnOutliner(false)
63{
64 if ( dynamic_cast< const DrawViewShell *>( mpViewShell ) != nullptr )
65 {
66 bOwnOutliner = true;
67 pSdOutliner = new SdOutliner( mpDoc, OutlinerMode::TextObject );
68 }
69 else if ( dynamic_cast< const OutlineViewShell *>( mpViewShell ) != nullptr )
70 {
71 bOwnOutliner = false;
73 }
74
75 if (pSdOutliner)
77}
78
80{
81 if (pSdOutliner)
83
84 if (bOwnOutliner)
85 delete pSdOutliner;
86}
87
89{
90 rtl::Reference<FuPoor> xFunc( new FuHangulHanjaConversion( pViewSh, pWin, pView, pDoc, rReq ) );
91 return xFunc;
92}
93
98 const vcl::Font *pTargetFont, sal_Int32 nOptions, bool bIsInteractive )
99{
100
101 mpView->BegUndo(SdResId(STR_UNDO_HANGULHANJACONVERSION));
102
103 ViewShellBase* pBase = dynamic_cast<ViewShellBase*>( SfxViewShell::Current() );
104 if (pBase != nullptr)
105 mpViewShell = pBase->GetMainViewShell().get();
106
107 if( mpViewShell )
108 {
109 if ( pSdOutliner && dynamic_cast< const DrawViewShell *>( mpViewShell ) != nullptr && !bOwnOutliner )
110 {
112
113 bOwnOutliner = true;
114 pSdOutliner = new SdOutliner( mpDoc, OutlinerMode::TextObject );
116 }
117 else if ( pSdOutliner && dynamic_cast< const OutlineViewShell *>( mpViewShell ) != nullptr && bOwnOutliner )
118 {
120 delete pSdOutliner;
121
122 bOwnOutliner = false;
125 }
126
127 if (pSdOutliner)
128 pSdOutliner->StartConversion(nSourceLanguage, nTargetLanguage, pTargetFont, nOptions, bIsInteractive );
129 }
130
131 // Due to changing between edit mode, notes mode, and handout mode the
132 // view has most likely changed. Get the new one.
133 mpViewShell = pBase ? pBase->GetMainViewShell().get() : nullptr;
134 if (mpViewShell != nullptr)
135 {
138 }
139 else
140 {
141 mpView = nullptr;
142 mpWindow = nullptr;
143 }
144
145 if (mpView != nullptr)
146 mpView->EndUndo();
147}
148
149void FuHangulHanjaConversion::ConvertStyles( LanguageType nTargetLanguage, const vcl::Font *pTargetFont )
150{
151 if( !mpDoc )
152 return;
153
154 SfxStyleSheetBasePool* pStyleSheetPool = mpDoc->GetStyleSheetPool();
155 if( !pStyleSheetPool )
156 return;
157
158 SfxStyleSheetBase* pStyle = pStyleSheetPool->First(SfxStyleFamily::All);
159 while( pStyle )
160 {
161 SfxItemSet& rSet = pStyle->GetItemSet();
162
163 const bool bHasParent = !pStyle->GetParent().isEmpty();
164
165 if( !bHasParent || rSet.GetItemState( EE_CHAR_LANGUAGE_CJK, false ) == SfxItemState::SET )
166 rSet.Put( SvxLanguageItem( nTargetLanguage, EE_CHAR_LANGUAGE_CJK ) );
167
168 if( pTargetFont &&
169 ( !bHasParent || rSet.GetItemState( EE_CHAR_FONTINFO_CJK, false ) == SfxItemState::SET ) )
170 {
171 // set new font attribute
173 aFontItem.SetFamilyName( pTargetFont->GetFamilyName());
174 aFontItem.SetFamily( pTargetFont->GetFamilyType());
175 aFontItem.SetStyleName( pTargetFont->GetStyleName());
176 aFontItem.SetPitch( pTargetFont->GetPitch());
177 aFontItem.SetCharSet( pTargetFont->GetCharSet());
178 rSet.Put( aFontItem );
179 }
180
181 pStyle = pStyleSheetPool->Next();
182 }
183
184 mpDoc->SetLanguage( nTargetLanguage, EE_CHAR_LANGUAGE_CJK );
185}
186
188{
189 //open ChineseTranslationDialog
190 Reference< XComponentContext > xContext(
191 ::cppu::defaultBootstrap_InitialComponentContext() ); //@todo get context from calc if that has one
192 if(!xContext.is())
193 return;
194
195 Reference< lang::XMultiComponentFactory > xMCF( xContext->getServiceManager() );
196 if(!xMCF.is())
197 return;
198
199 Reference< ui::dialogs::XExecutableDialog > xDialog(
200 xMCF->createInstanceWithContext("com.sun.star.linguistic2.ChineseTranslationDialog"
201 , xContext), UNO_QUERY);
202 Reference< lang::XInitialization > xInit( xDialog, UNO_QUERY );
203 if( xInit.is() )
204 {
205 // initialize dialog
206 Reference< awt::XWindow > xDialogParentWindow;
208 {
209 {"ParentWindow", uno::Any(xDialogParentWindow)}
210 }));
211 xInit->initialize( aSeq );
212
213 //execute dialog
214 sal_Int16 nDialogRet = xDialog->execute();
215 if( RET_OK == nDialogRet )
216 {
217 //get some parameters from the dialog
218 bool bToSimplified = true;
219 bool bUseVariants = true;
220 bool bCommonTerms = true;
221 Reference< beans::XPropertySet > xProp( xDialog, UNO_QUERY );
222 if( xProp.is() )
223 {
224 try
225 {
226 xProp->getPropertyValue( "IsDirectionToSimplified" ) >>= bToSimplified;
227 xProp->getPropertyValue( "IsUseCharacterVariants" ) >>= bUseVariants;
228 xProp->getPropertyValue( "IsTranslateCommonTerms" ) >>= bCommonTerms;
229 }
230 catch( Exception& )
231 {
232 }
233 }
234
235 //execute translation
238 sal_Int32 nOptions = bUseVariants ? i18n::TextConversionOption::USE_CHARACTER_VARIANTS : 0;
239 if( !bCommonTerms )
240 nOptions = nOptions | i18n::TextConversionOption::CHARACTER_BY_CHARACTER;
241
243 DefaultFontType::CJK_PRESENTATION,
244 nTargetLang, GetDefaultFontFlags::OnlyOne );
245
246 StartConversion( nSourceLang, nTargetLang, &aTargetFont, nOptions, false );
247 ConvertStyles( nTargetLang, &aTargetFont );
248 }
249 }
250 Reference< lang::XComponent > xComponent( xDialog, UNO_QUERY );
251 if( xComponent.is() )
252 xComponent->dispose();
253}
254} // end of namespace
255
256/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
static vcl::Font GetDefaultFont(DefaultFontType nType, LanguageType eLang, GetDefaultFontFlags nFlags, const OutputDevice *pOutDev=nullptr)
SAL_DLLPRIVATE SdOutliner * GetOutliner(bool bCreateOutliner=true)
Definition: drawdoc.cxx:912
SAL_DLLPRIVATE void SetLanguage(const LanguageType eLang, const sal_uInt16 nId)
Definition: drawdoc2.cxx:845
The main purpose of this class is searching and replacing as well as spelling of impress documents.
Definition: Outliner.hxx:123
void PrepareSpelling()
Despite the name this method is called prior to spell checking and searching and replacing.
Definition: Outliner.cxx:241
void BeginConversion()
This is called internally when text conversion is started.
Definition: Outliner.cxx:1845
void StartConversion(LanguageType nSourceLanguage, LanguageType nTargetLanguage, const vcl::Font *pTargetFont, sal_Int32 nOptions, bool bIsInteractive)
Starts the text conversion (hangul/hanja or Chinese simplified/traditional) for the current viewshell...
Definition: Outliner.cxx:1792
void EndConversion()
Release all resources that have been created during the conversion.
Definition: Outliner.cxx:1874
void BegUndo()
void EndUndo()
SfxStyleSheetBasePool * GetStyleSheetPool() const
SfxItemState GetItemState(sal_uInt16 nWhich, bool bSrchInParent=true, const SfxPoolItem **ppItem=nullptr) const
const SfxPoolItem * Put(const SfxPoolItem &rItem, sal_uInt16 nWhich)
const SfxPoolItem & Get(sal_uInt16 nWhich, bool bSrchInParent=true) const
SfxStyleSheetBase * First(SfxStyleFamily eFamily, SfxStyleSearchBits eMask=SfxStyleSearchBits::All)
SfxStyleSheetBase * Next()
virtual const OUString & GetParent() const
virtual SfxItemSet & GetItemSet()
static SAL_WARN_UNUSED_RESULT SfxViewShell * Current()
void SetStyleName(const OUString &rStyleName)
void SetFamily(FontFamily _eFamily)
void SetPitch(FontPitch _ePitch)
void SetFamilyName(const OUString &rFamilyName)
void SetCharSet(rtl_TextEncoding _eEncoding)
Base class of the stacked shells that provide graphical views to Draw and Impress documents and editi...
void ConvertStyles(LanguageType nTargetLanguage, const vcl::Font *pTargetFont)
Definition: fuhhconv.cxx:149
FuHangulHanjaConversion(ViewShell *pViewSh, ::sd::Window *pWin, ::sd::View *pView, SdDrawDocument *pDoc, SfxRequest &rReq)
Definition: fuhhconv.cxx:54
void StartConversion(LanguageType nSourceLanguage, LanguageType nTargetLanguage, const vcl::Font *pTargetFont, sal_Int32 nOptions, bool bIsInteractive)
Search and replace.
Definition: fuhhconv.cxx:97
static rtl::Reference< FuPoor > Create(ViewShell *pViewSh, ::sd::Window *pWin, ::sd::View *pView, SdDrawDocument *pDoc, SfxRequest &rReq)
Definition: fuhhconv.cxx:88
virtual ~FuHangulHanjaConversion() override
Definition: fuhhconv.cxx:79
Base class for all functions.
Definition: fupoor.hxx:48
SdDrawDocument * mpDoc
Definition: fupoor.hxx:148
VclPtr< ::sd::Window > mpWindow
Definition: fupoor.hxx:146
ViewShell * mpViewShell
Definition: fupoor.hxx:145
::sd::View * mpView
Definition: fupoor.hxx:144
Show a textual overview of the text contents of all slides.
SfxViewShell descendant that the stacked Draw/Impress shells are based on.
std::shared_ptr< ViewShell > GetMainViewShell() const
Return the main view shell stacked on the called ViewShellBase object.
Base class of the stacked shell hierarchy.
Definition: ViewShell.hxx:92
::sd::Window * GetActiveWindow() const
The active window is usually the mpContentWindow.
Definition: ViewShell.hxx:155
::sd::View * GetView() const
Definition: ViewShell.hxx:144
An SdWindow contains the actual working area of ViewShell.
Definition: Window.hxx:45
FontFamily GetFamilyType()
const OUString & GetStyleName() const
const OUString & GetFamilyName() const
FontPitch GetPitch()
rtl_TextEncoding GetCharSet() const
constexpr TypedWhichId< SvxFontItem > EE_CHAR_FONTINFO_CJK(EE_CHAR_START+17)
constexpr TypedWhichId< SvxLanguageItem > EE_CHAR_LANGUAGE_CJK(EE_CHAR_START+15)
#define LANGUAGE_CHINESE_TRADITIONAL
#define LANGUAGE_CHINESE_SIMPLIFIED
Sequence< sal_Int8 > aSeq
@ Exception
css::uno::Sequence< css::uno::Any > InitAnyPropertySequence(::std::initializer_list< ::std::pair< OUString, css::uno::Any > > vInit)
OUString SdResId(TranslateId aId)
Definition: sdmod.cxx:83
static SfxItemSet & rSet
RET_OK