1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 .
21 #include "DrawDocShell.hxx"
25 #include <svx/svxids.hrc>
26 #include <svx/dialogs.hrc>
28 #include <svx/ofaitem.hxx>
29 #include <svx/svxerr.hxx>
30 #include <svx/dialmgr.hxx>
31 #include <svl/srchitem.hxx>
32 #include <svl/languageoptions.hxx>
33 #include <svtools/langtab.hxx>
34 #include <svx/srchdlg.hxx>
35 #include <sfx2/request.hxx>
36 #include <sfx2/sfxdlg.hxx>
37 #include <vcl/abstdlg.hxx>
38 #include <vcl/window.hxx>
39 #include <svl/style.hxx>
40 #include <svx/drawitem.hxx>
41 #include <editeng/unolingu.hxx>
42 #include <editeng/langitem.hxx>
43 #include <editeng/eeitem.hxx>
44 #include <com/sun/star/i18n/TextConversionOption.hpp>
46 #include "strings.hrc"
48 #include "res_bmp.hrc"
51 #include "drawdoc.hxx"
54 #include "fusearch.hxx"
55 #include "ViewShell.hxx"
57 #include "slideshow.hxx"
58 #include "fuhhconv.hxx"
59 #include <boost/scoped_ptr.hpp>
61 using namespace ::com::sun::star
;
62 using namespace ::com::sun::star::beans
;
63 using namespace ::com::sun::star::uno
;
67 static void lcl_setLanguageForObj( SdrObject
*pObj
, LanguageType nLang
, bool bLanguageNone
= false )
69 const sal_uInt16 aLangWhichId_EE
[3] =
77 nLang
= LANGUAGE_NONE
;
79 if( nLang
!= LANGUAGE_DONTKNOW
)
81 if( nLang
== LANGUAGE_NONE
)
83 for(sal_Int32 n
= 0; n
< 3; n
++ )
84 pObj
->SetMergedItem( SvxLanguageItem( nLang
, aLangWhichId_EE
[n
] ) );
88 sal_uInt16 nLangWhichId
= 0;
89 SvtScriptType nScriptType
= SvtLanguageOptions::GetScriptTypeOfLanguage( nLang
);
92 case SvtScriptType::LATIN
: nLangWhichId
= EE_CHAR_LANGUAGE
; break;
93 case SvtScriptType::ASIAN
: nLangWhichId
= EE_CHAR_LANGUAGE_CJK
; break;
94 case SvtScriptType::COMPLEX
: nLangWhichId
= EE_CHAR_LANGUAGE_CTL
; break;
96 OSL_FAIL("unexpected case" );
99 pObj
->SetMergedItem( SvxLanguageItem( nLang
, nLangWhichId
) );
102 else // Reset to default
104 for( sal_Int32 n
= 0; n
< 3; n
++ )
105 pObj
->ClearMergedItem( aLangWhichId_EE
[n
] );
109 static void lcl_setLanguage( const SdDrawDocument
*pDoc
, const OUString
&rLanguage
, bool bLanguageNone
= false )
111 LanguageType nLang
= SvtLanguageTable::GetLanguageType( rLanguage
);
113 // Do it for SdDrawDocument->SetLanguage as well?
115 sal_uInt16 nPageCount
= pDoc
->GetPageCount(); // Pick All Pages
116 for( sal_uInt16 nPage
= 0; nPage
< nPageCount
; nPage
++ )
118 const SdrPage
*pPage
= pDoc
->GetPage( nPage
);
119 const size_t nObjCount
= pPage
->GetObjCount();
120 for( size_t nObj
= 0; nObj
< nObjCount
; ++nObj
)
122 SdrObject
*pObj
= pPage
->GetObj( nObj
);
123 lcl_setLanguageForObj( pObj
, nLang
, bLanguageNone
);
129 * Handles SFX-Requests
131 void DrawDocShell::Execute( SfxRequest
& rReq
)
133 if(mpViewShell
&& SlideShow::IsRunning( mpViewShell
->GetViewShellBase() ))
135 // during a running presentation no slot will be executed
139 switch ( rReq
.GetSlot() )
141 case SID_SEARCH_ITEM
:
143 const SfxItemSet
* pReqArgs
= rReq
.GetArgs();
147 const SvxSearchItem
* pSearchItem
= static_cast<const SvxSearchItem
*>( &pReqArgs
->Get(SID_SEARCH_ITEM
) );
149 // would be nice to have an assign operation at SearchItem
150 SvxSearchItem
* pAppSearchItem
= SD_MOD()->GetSearchItem();
151 delete pAppSearchItem
;
152 pAppSearchItem
= static_cast<SvxSearchItem
*>( pSearchItem
->Clone() );
153 SD_MOD()->SetSearchItem(pAppSearchItem
);
169 if( dynamic_cast< FuSearch
* >(mxDocShellFunction
.get()) )
171 // End Search&Replace in all docshells
172 SfxObjectShell
* pFirstShell
= SfxObjectShell::GetFirst();
173 SfxObjectShell
* pShell
= pFirstShell
;
177 if (pShell
->ISA(DrawDocShell
))
179 static_cast<DrawDocShell
*>(pShell
)->CancelSearching();
182 pShell
= SfxObjectShell::GetNext(*pShell
);
184 if (pShell
== pFirstShell
)
190 SetDocShellFunction(0);
199 const SfxItemSet
* pReqArgs
= rReq
.GetArgs();
203 rtl::Reference
< FuSearch
> xFuSearch( dynamic_cast< FuSearch
* >( GetDocShellFunction().get() ) );
205 if( !xFuSearch
.is() && mpViewShell
)
207 ::sd::View
* pView
= mpViewShell
->GetView();
208 SetDocShellFunction( FuSearch::Create( mpViewShell
, mpViewShell
->GetActiveWindow(), pView
, mpDoc
, rReq
) );
209 xFuSearch
.set( dynamic_cast< FuSearch
* >( GetDocShellFunction().get() ) );
214 const SvxSearchItem
* pSearchItem
=
215 static_cast<const SvxSearchItem
*>( &pReqArgs
->Get(SID_SEARCH_ITEM
) );
217 // would be nice to have an assign operation at SearchItem
218 SvxSearchItem
* pAppSearchItem
= SD_MOD()->GetSearchItem();
219 delete pAppSearchItem
;
220 pAppSearchItem
= static_cast<SvxSearchItem
*>( pSearchItem
->Clone() );
221 SD_MOD()->SetSearchItem(pAppSearchItem
);
222 xFuSearch
->SearchAndReplace(pSearchItem
);
232 ExecuteSlot(rReq
, SfxObjectShell::GetStaticInterface());
236 case SID_GET_COLORLIST
:
238 const SvxColorListItem
* pColItem
= static_cast<const SvxColorListItem
*>( GetItem( SID_COLOR_TABLE
) );
239 XColorListRef pList
= pColItem
->GetColorList();
240 rReq
.SetReturnValue( OfaRefItem
<XColorList
>( SID_GET_COLORLIST
, pList
) );
246 const SdrSwapGraphicsMode nOldSwapMode
= mpDoc
->GetSwapGraphicsMode();
248 mpDoc
->SetSwapGraphicsMode( SdrSwapGraphicsMode::TEMP
);
249 ExecuteSlot( rReq
, SfxObjectShell::GetStaticInterface() );
250 mpDoc
->SetSwapGraphicsMode( nOldSwapMode
);
254 case SID_HANGUL_HANJA_CONVERSION
:
258 rtl::Reference
<FuPoor
> aFunc( FuHangulHanjaConversion::Create( mpViewShell
, mpViewShell
->GetActiveWindow(), mpViewShell
->GetView(), mpDoc
, rReq
) );
259 static_cast< FuHangulHanjaConversion
* >( aFunc
.get() )->StartConversion( LANGUAGE_KOREAN
, LANGUAGE_KOREAN
, NULL
, i18n::TextConversionOption::CHARACTER_BY_CHARACTER
, true );
264 case SID_CHINESE_CONVERSION
:
268 rtl::Reference
<FuPoor
> aFunc( FuHangulHanjaConversion::Create( mpViewShell
, mpViewShell
->GetActiveWindow(), mpViewShell
->GetView(), mpDoc
, rReq
) );
269 static_cast< FuHangulHanjaConversion
* >( aFunc
.get() )->StartChineseConversion();
273 case SID_LANGUAGE_STATUS
:
275 OUString aNewLangTxt
;
276 SFX_REQUEST_ARG( rReq
, pItem
, SfxStringItem
, SID_LANGUAGE_STATUS
, false );
278 aNewLangTxt
= pItem
->GetValue();
279 if (aNewLangTxt
== "*" )
281 // open the dialog "Tools/Options/Language Settings - Language"
282 SfxAbstractDialogFactory
* pFact
= SfxAbstractDialogFactory::Create();
283 if (pFact
&& mpViewShell
)
285 boost::scoped_ptr
<VclAbstractDialog
> pDlg(pFact
->CreateVclDialog( mpViewShell
->GetActiveWindow(), SID_LANGUAGE_OPTIONS
));
293 // setting the new language...
294 if (!aNewLangTxt
.isEmpty())
296 const OUString
aDocumentLangPrefix("Default_");
297 const OUString
aStrNone("LANGUAGE_NONE");
298 const OUString
aStrResetLangs("RESET_LANGUAGES");
300 if (-1 != (nPos
= aNewLangTxt
.indexOf( aDocumentLangPrefix
, 0 )))
302 aNewLangTxt
= aNewLangTxt
.replaceAt( nPos
, aDocumentLangPrefix
.getLength(), "" );
308 if (aNewLangTxt
== aStrNone
)
309 lcl_setLanguage( mpViewShell
->GetDoc(), OUString() );
310 else if (aNewLangTxt
== aStrResetLangs
)
311 lcl_setLanguage( mpViewShell
->GetDoc(), OUString(), true );
313 lcl_setLanguage( mpViewShell
->GetDoc(), aNewLangTxt
);
325 void DrawDocShell::SetDocShellFunction( const rtl::Reference
<FuPoor
>& xFunction
)
327 if( mxDocShellFunction
.is() )
328 mxDocShellFunction
->Dispose();
330 mxDocShellFunction
= xFunction
;
333 } // end of namespace sd
335 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */