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 "Window.hxx"
21 : #include "DrawDocShell.hxx"
22 :
23 : #include "app.hrc"
24 :
25 : #include <svx/svxids.hrc>
26 : #include <svx/dialogs.hrc>
27 :
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>
45 :
46 : #include "strings.hrc"
47 : #include "glob.hrc"
48 : #include "res_bmp.hrc"
49 :
50 : #include "sdmod.hxx"
51 : #include "drawdoc.hxx"
52 : #include "sdpage.hxx"
53 : #include "sdattr.hxx"
54 : #include "fusearch.hxx"
55 : #include "ViewShell.hxx"
56 : #include "View.hxx"
57 : #include "slideshow.hxx"
58 : #include "fuhhconv.hxx"
59 : #include <boost/scoped_ptr.hpp>
60 :
61 : using namespace ::com::sun::star;
62 : using namespace ::com::sun::star::beans;
63 : using namespace ::com::sun::star::uno;
64 :
65 : namespace sd {
66 :
67 0 : static void lcl_setLanguageForObj( SdrObject *pObj, LanguageType nLang, bool bLanguageNone = false )
68 : {
69 : const sal_uInt16 aLangWhichId_EE[3] =
70 : {
71 : EE_CHAR_LANGUAGE,
72 : EE_CHAR_LANGUAGE_CJK,
73 : EE_CHAR_LANGUAGE_CTL
74 0 : };
75 :
76 0 : if( bLanguageNone )
77 0 : nLang = LANGUAGE_NONE;
78 :
79 0 : if( nLang != LANGUAGE_DONTKNOW )
80 : {
81 0 : if( nLang == LANGUAGE_NONE )
82 : {
83 0 : for(sal_Int32 n = 0; n < 3; n++ )
84 0 : pObj->SetMergedItem( SvxLanguageItem( nLang, aLangWhichId_EE[n] ) );
85 : }
86 : else
87 : {
88 0 : sal_uInt16 nLangWhichId = 0;
89 0 : sal_uInt16 nScriptType = SvtLanguageOptions::GetScriptTypeOfLanguage( nLang );
90 0 : switch (nScriptType)
91 : {
92 0 : case SCRIPTTYPE_LATIN : nLangWhichId = EE_CHAR_LANGUAGE; break;
93 0 : case SCRIPTTYPE_ASIAN : nLangWhichId = EE_CHAR_LANGUAGE_CJK; break;
94 0 : case SCRIPTTYPE_COMPLEX : nLangWhichId = EE_CHAR_LANGUAGE_CTL; break;
95 : default:
96 : OSL_FAIL("unexpected case" );
97 0 : return;
98 : }
99 0 : pObj->SetMergedItem( SvxLanguageItem( nLang, nLangWhichId ) );
100 : }
101 : }
102 : else // Reset to default
103 : {
104 0 : for( sal_Int32 n = 0; n < 3; n++ )
105 0 : pObj->ClearMergedItem( aLangWhichId_EE[n] );
106 : }
107 : }
108 :
109 0 : static void lcl_setLanguage( const SdDrawDocument *pDoc, const OUString &rLanguage, bool bLanguageNone = false )
110 : {
111 0 : LanguageType nLang = SvtLanguageTable::GetLanguageType( rLanguage );
112 :
113 : // Do it for SdDrawDocument->SetLanguage as well?
114 :
115 0 : sal_uInt16 nPageCount = pDoc->GetPageCount(); // Pick All Pages
116 0 : for( sal_uInt16 nPage = 0; nPage < nPageCount; nPage++ )
117 : {
118 0 : const SdrPage *pPage = pDoc->GetPage( nPage );
119 0 : const size_t nObjCount = pPage->GetObjCount();
120 0 : for( size_t nObj = 0; nObj < nObjCount; ++nObj )
121 : {
122 0 : SdrObject *pObj = pPage->GetObj( nObj );
123 0 : lcl_setLanguageForObj( pObj, nLang, bLanguageNone );
124 : }
125 : }
126 0 : }
127 :
128 : /**
129 : * Handles SFX-Requests
130 : */
131 0 : void DrawDocShell::Execute( SfxRequest& rReq )
132 : {
133 0 : if(mpViewShell && SlideShow::IsRunning( mpViewShell->GetViewShellBase() ))
134 : {
135 : // during a running presentation no slot will be executed
136 0 : return;
137 : }
138 :
139 0 : switch ( rReq.GetSlot() )
140 : {
141 : case SID_SEARCH_ITEM:
142 : {
143 0 : const SfxItemSet* pReqArgs = rReq.GetArgs();
144 :
145 0 : if (pReqArgs)
146 : {
147 : const SvxSearchItem* pSearchItem =
148 0 : (const SvxSearchItem*) &pReqArgs->Get(SID_SEARCH_ITEM);
149 :
150 : // would be nice to have an an assign operation at SearchItem
151 0 : SvxSearchItem* pAppSearchItem = SD_MOD()->GetSearchItem();
152 0 : delete pAppSearchItem;
153 0 : pAppSearchItem = (SvxSearchItem*) pSearchItem->Clone();
154 0 : SD_MOD()->SetSearchItem(pAppSearchItem);
155 : }
156 :
157 0 : rReq.Done();
158 : }
159 0 : break;
160 :
161 : case FID_SEARCH_ON:
162 : {
163 : // no action needed
164 0 : rReq.Done();
165 : }
166 0 : break;
167 :
168 : case FID_SEARCH_OFF:
169 : {
170 0 : if( dynamic_cast< FuSearch* >(mxDocShellFunction.get()) )
171 : {
172 : // End Search&Replace in all docshells
173 0 : SfxObjectShell* pFirstShell = SfxObjectShell::GetFirst();
174 0 : SfxObjectShell* pShell = pFirstShell;
175 :
176 0 : while (pShell)
177 : {
178 0 : if (pShell->ISA(DrawDocShell))
179 : {
180 0 : ( (DrawDocShell*) pShell)->CancelSearching();
181 : }
182 :
183 0 : pShell = SfxObjectShell::GetNext(*pShell);
184 :
185 0 : if (pShell == pFirstShell)
186 : {
187 0 : pShell = NULL;
188 : }
189 : }
190 :
191 0 : SetDocShellFunction(0);
192 0 : Invalidate();
193 0 : rReq.Done();
194 : }
195 : }
196 0 : break;
197 :
198 : case FID_SEARCH_NOW:
199 : {
200 0 : const SfxItemSet* pReqArgs = rReq.GetArgs();
201 :
202 0 : if ( pReqArgs )
203 : {
204 0 : rtl::Reference< FuSearch > xFuSearch( dynamic_cast< FuSearch* >( GetDocShellFunction().get() ) );
205 :
206 0 : if( !xFuSearch.is() && mpViewShell )
207 : {
208 0 : ::sd::View* pView = mpViewShell->GetView();
209 0 : SetDocShellFunction( FuSearch::Create( mpViewShell, mpViewShell->GetActiveWindow(), pView, mpDoc, rReq ) );
210 0 : xFuSearch.set( dynamic_cast< FuSearch* >( GetDocShellFunction().get() ) );
211 : }
212 :
213 0 : if( xFuSearch.is() )
214 : {
215 : const SvxSearchItem* pSearchItem =
216 0 : (const SvxSearchItem*) &pReqArgs->Get(SID_SEARCH_ITEM);
217 :
218 : // would be nice to have an an assign operation at SearchItem
219 0 : SvxSearchItem* pAppSearchItem = SD_MOD()->GetSearchItem();
220 0 : delete pAppSearchItem;
221 0 : pAppSearchItem = (SvxSearchItem*)pSearchItem->Clone();
222 0 : SD_MOD()->SetSearchItem(pAppSearchItem);
223 0 : xFuSearch->SearchAndReplace(pSearchItem);
224 0 : }
225 : }
226 :
227 0 : rReq.Done();
228 : }
229 0 : break;
230 :
231 : case SID_CLOSEDOC:
232 : {
233 0 : ExecuteSlot(rReq, SfxObjectShell::GetStaticInterface());
234 : }
235 0 : break;
236 :
237 : case SID_GET_COLORLIST:
238 : {
239 0 : SvxColorListItem* pColItem = (SvxColorListItem*) GetItem( SID_COLOR_TABLE );
240 0 : XColorListRef pList = pColItem->GetColorList();
241 0 : rReq.SetReturnValue( OfaRefItem<XColorList>( SID_GET_COLORLIST, pList ) );
242 : }
243 0 : break;
244 :
245 : case SID_VERSION:
246 : {
247 0 : const sal_uLong nOldSwapMode = mpDoc->GetSwapGraphicsMode();
248 :
249 0 : mpDoc->SetSwapGraphicsMode( SDR_SWAPGRAPHICSMODE_TEMP );
250 0 : ExecuteSlot( rReq, SfxObjectShell::GetStaticInterface() );
251 0 : mpDoc->SetSwapGraphicsMode( nOldSwapMode );
252 : }
253 0 : break;
254 :
255 : case SID_HANGUL_HANJA_CONVERSION:
256 : {
257 0 : if( mpViewShell )
258 : {
259 0 : rtl::Reference<FuPoor> aFunc( FuHangulHanjaConversion::Create( mpViewShell, mpViewShell->GetActiveWindow(), mpViewShell->GetView(), mpDoc, rReq ) );
260 0 : static_cast< FuHangulHanjaConversion* >( aFunc.get() )->StartConversion( LANGUAGE_KOREAN, LANGUAGE_KOREAN, NULL, i18n::TextConversionOption::CHARACTER_BY_CHARACTER, true );
261 : }
262 : }
263 0 : break;
264 :
265 : case SID_CHINESE_CONVERSION:
266 : {
267 0 : if( mpViewShell )
268 : {
269 0 : rtl::Reference<FuPoor> aFunc( FuHangulHanjaConversion::Create( mpViewShell, mpViewShell->GetActiveWindow(), mpViewShell->GetView(), mpDoc, rReq ) );
270 0 : static_cast< FuHangulHanjaConversion* >( aFunc.get() )->StartChineseConversion();
271 : }
272 : }
273 0 : break;
274 : case SID_LANGUAGE_STATUS:
275 : {
276 0 : OUString aNewLangTxt;
277 0 : SFX_REQUEST_ARG( rReq, pItem, SfxStringItem, SID_LANGUAGE_STATUS , false );
278 0 : if (pItem)
279 0 : aNewLangTxt = pItem->GetValue();
280 0 : if (aNewLangTxt == "*" )
281 : {
282 : // open the dialog "Tools/Options/Language Settings - Language"
283 0 : SfxAbstractDialogFactory* pFact = SfxAbstractDialogFactory::Create();
284 0 : if (pFact && mpViewShell)
285 : {
286 0 : boost::scoped_ptr<VclAbstractDialog> pDlg(pFact->CreateVclDialog( mpViewShell->GetActiveWindow(), SID_LANGUAGE_OPTIONS ));
287 0 : pDlg->Execute();
288 : }
289 : }
290 : else
291 : {
292 0 : if( mpViewShell )
293 : {
294 : // setting the new language...
295 0 : if (!aNewLangTxt.isEmpty())
296 : {
297 0 : const OUString aDocumentLangPrefix("Default_");
298 0 : const OUString aStrNone("LANGUAGE_NONE");
299 0 : const OUString aStrResetLangs("RESET_LANGUAGES");
300 0 : sal_Int32 nPos = -1;
301 0 : if (-1 != (nPos = aNewLangTxt.indexOf( aDocumentLangPrefix , 0 )))
302 : {
303 0 : aNewLangTxt = aNewLangTxt.replaceAt( nPos, aDocumentLangPrefix.getLength(), "" );
304 : }
305 : else
306 : {
307 0 : break;
308 : }
309 0 : if (aNewLangTxt == aStrNone)
310 0 : lcl_setLanguage( mpViewShell->GetDoc(), OUString() );
311 0 : else if (aNewLangTxt == aStrResetLangs)
312 0 : lcl_setLanguage( mpViewShell->GetDoc(), OUString(), true );
313 : else
314 0 : lcl_setLanguage( mpViewShell->GetDoc(), aNewLangTxt );
315 : }
316 : }
317 0 : }
318 : }
319 0 : break;
320 :
321 : default:
322 0 : break;
323 : }
324 : }
325 :
326 650 : void DrawDocShell::SetDocShellFunction( const rtl::Reference<FuPoor>& xFunction )
327 : {
328 650 : if( mxDocShellFunction.is() )
329 0 : mxDocShellFunction->Dispose();
330 :
331 650 : mxDocShellFunction = xFunction;
332 650 : }
333 :
334 114 : } // end of namespace sd
335 :
336 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|