/src/libreoffice/sw/source/uibase/shells/textsh.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 <config_features.h> |
21 | | |
22 | | #include <hintids.hxx> |
23 | | #include <comphelper/lok.hxx> |
24 | | #include <comphelper/string.hxx> |
25 | | #include <svl/globalnameitem.hxx> |
26 | | #include <sfx2/bindings.hxx> |
27 | | #include <sfx2/frmdescr.hxx> |
28 | | #include <sfx2/objface.hxx> |
29 | | #include <sfx2/toolbarids.hxx> |
30 | | #include <sfx2/sidebar/Sidebar.hxx> |
31 | | #include <sfx2/viewfrm.hxx> |
32 | | |
33 | | #include <i18nutil/transliteration.hxx> |
34 | | #include <svl/eitem.hxx> |
35 | | #include <svl/ptitem.hxx> |
36 | | #include <svl/stritem.hxx> |
37 | | #include <unotools/moduleoptions.hxx> |
38 | | #include <svx/hlnkitem.hxx> |
39 | | #include <svl/whiter.hxx> |
40 | | #include <sfx2/request.hxx> |
41 | | #include <editeng/fontitem.hxx> |
42 | | #include <editeng/boxitem.hxx> |
43 | | #include <editeng/sizeitem.hxx> |
44 | | #include <editeng/svxacorr.hxx> |
45 | | #include <editeng/scriptsetitem.hxx> |
46 | | #include <sfx2/htmlmode.hxx> |
47 | | #include <svtools/htmlcfg.hxx> |
48 | | #include <com/sun/star/embed/Aspects.hpp> |
49 | | #include <com/sun/star/embed/XEmbeddedObject.hpp> |
50 | | #include <osl/diagnose.h> |
51 | | |
52 | | #include <comphelper/classids.hxx> |
53 | | #include <editeng/acorrcfg.hxx> |
54 | | #include <wdocsh.hxx> |
55 | | #include <fmtinfmt.hxx> |
56 | | #include <fmtclds.hxx> |
57 | | #include <fmtfsize.hxx> |
58 | | #include <swmodule.hxx> |
59 | | #include <wrtsh.hxx> |
60 | | #include <view.hxx> |
61 | | #include <docsh.hxx> |
62 | | #include <doc.hxx> |
63 | | #include <IDocumentChartDataProviderAccess.hxx> |
64 | | #include <uitool.hxx> |
65 | | #include <cmdid.h> |
66 | | #include <globals.hrc> |
67 | | #include <frmmgr.hxx> |
68 | | #include <textsh.hxx> |
69 | | #include <frmfmt.hxx> |
70 | | #include <tablemgr.hxx> |
71 | | #include <swundo.hxx> |
72 | | #include <breakit.hxx> |
73 | | #include <edtwin.hxx> |
74 | | #include <strings.hrc> |
75 | | #include <unochart.hxx> |
76 | | #include <chartins.hxx> |
77 | | #include <viewopt.hxx> |
78 | | |
79 | | #define ShellClass_SwTextShell |
80 | | #include <sfx2/msg.hxx> |
81 | | #include <vcl/EnumContext.hxx> |
82 | | #include <swslots.hxx> |
83 | | #include <SwRewriter.hxx> |
84 | | #include <SwCapObjType.hxx> |
85 | | |
86 | | #include <svx/svxdlg.hxx> |
87 | | #include <swabstdlg.hxx> |
88 | | #include <IDocumentDrawModelAccess.hxx> |
89 | | #include <drawdoc.hxx> |
90 | | #include <svtools/embedhlp.hxx> |
91 | | #include <sfx2/event.hxx> |
92 | | #include <com/sun/star/ui/dialogs/DialogClosedEvent.hpp> |
93 | | #include <com/sun/star/ui/dialogs/ExecutableDialogResults.hpp> |
94 | | #include <IDocumentUndoRedo.hxx> |
95 | | #include <formatcontentcontrol.hxx> |
96 | | #include <com/sun/star/i18n/WordType.hpp> |
97 | | |
98 | | |
99 | | using namespace ::com::sun::star; |
100 | | |
101 | | SFX_IMPL_INTERFACE(SwTextShell, SwBaseShell) |
102 | | |
103 | | IMPL_STATIC_LINK( SwTextShell, DialogClosedHdl, css::ui::dialogs::DialogClosedEvent*, pEvent, void ) |
104 | 0 | { |
105 | 0 | if (SwView* pView = GetActiveView()) |
106 | 0 | { |
107 | 0 | SwWrtShell& rWrtShell = pView->GetWrtShell(); |
108 | |
|
109 | 0 | sal_Int16 nDialogRet = pEvent->DialogResult; |
110 | 0 | if( nDialogRet == ui::dialogs::ExecutableDialogResults::CANCEL ) |
111 | 0 | { |
112 | 0 | rWrtShell.Undo(); |
113 | 0 | rWrtShell.GetIDocumentUndoRedo().ClearRedo(); |
114 | 0 | } |
115 | 0 | else |
116 | 0 | { |
117 | 0 | OSL_ENSURE( nDialogRet == ui::dialogs::ExecutableDialogResults::OK, |
118 | 0 | "dialog execution failed" ); |
119 | 0 | } |
120 | 0 | } |
121 | 0 | } |
122 | | |
123 | | void SwTextShell::InitInterface_Impl() |
124 | 9 | { |
125 | 9 | GetStaticInterface()->RegisterPopupMenu(u"text"_ustr); |
126 | | |
127 | 9 | GetStaticInterface()->RegisterObjectBar(SFX_OBJECTBAR_OBJECT, SfxVisibilityFlags::Invisible, ToolbarId::Text_Toolbox_Sw); |
128 | | |
129 | 9 | GetStaticInterface()->RegisterChildWindow(FN_EDIT_FORMULA); |
130 | 9 | GetStaticInterface()->RegisterChildWindow(FN_INSERT_FIELD); |
131 | 9 | GetStaticInterface()->RegisterChildWindow(FN_INSERT_IDX_ENTRY_DLG); |
132 | 9 | GetStaticInterface()->RegisterChildWindow(FN_INSERT_AUTH_ENTRY_DLG); |
133 | 9 | GetStaticInterface()->RegisterChildWindow(SID_RUBY_DIALOG); |
134 | 9 | GetStaticInterface()->RegisterChildWindow(FN_WORDCOUNT_DIALOG); |
135 | 9 | } |
136 | | |
137 | | |
138 | | void SwTextShell::ExecInsert(SfxRequest &rReq) |
139 | 0 | { |
140 | 0 | SwWrtShell &rSh = GetShell(); |
141 | |
|
142 | 0 | OSL_ENSURE( !rSh.GetSelectedObjCount() && !rSh.IsFrameSelected(), |
143 | 0 | "wrong shell on dispatcher" ); |
144 | |
|
145 | 0 | const SfxItemSet *pArgs = rReq.GetArgs(); |
146 | 0 | const SfxPoolItem* pItem = nullptr; |
147 | 0 | const sal_uInt16 nSlot = rReq.GetSlot(); |
148 | 0 | if(pArgs) |
149 | 0 | pArgs->GetItemState(nSlot, false, &pItem ); |
150 | |
|
151 | 0 | switch( nSlot ) |
152 | 0 | { |
153 | 0 | case FN_INSERT_STRING: |
154 | 0 | if( pItem ) |
155 | 0 | rSh.InsertByWord(static_cast<const SfxStringItem *>(pItem)->GetValue()); |
156 | 0 | break; |
157 | | |
158 | 0 | case FN_INSERT_SOFT_HYPHEN: |
159 | 0 | if( CHAR_SOFTHYPHEN != rSh.SwCursorShell::GetChar() && |
160 | 0 | CHAR_SOFTHYPHEN != rSh.SwCursorShell::GetChar( true, -1 )) |
161 | 0 | rSh.Insert( OUString( CHAR_SOFTHYPHEN ) ); |
162 | 0 | break; |
163 | | |
164 | 0 | case FN_INSERT_HARDHYPHEN: |
165 | 0 | case FN_INSERT_HARD_SPACE: |
166 | 0 | { |
167 | 0 | const sal_Unicode cIns = FN_INSERT_HARD_SPACE == nSlot ? CHAR_HARDBLANK : CHAR_HARDHYPHEN; |
168 | |
|
169 | 0 | SvxAutoCorrCfg& rACfg = SvxAutoCorrCfg::Get(); |
170 | 0 | SvxAutoCorrect* pACorr = rACfg.GetAutoCorrect(); |
171 | 0 | if( pACorr && rACfg.IsAutoFormatByInput() |
172 | 0 | && pACorr->IsAutoCorrFlag( |
173 | 0 | ACFlags::CapitalStartSentence | ACFlags::CapitalStartWord | |
174 | 0 | ACFlags::AddNonBrkSpace | ACFlags::ChgOrdinalNumber | ACFlags::TransliterateRTL | |
175 | 0 | ACFlags::ChgToEnEmDash | ACFlags::SetINetAttr | ACFlags::Autocorrect | |
176 | 0 | ACFlags::SetDOIAttr | ACFlags::EsperantoHats ) ) |
177 | 0 | { |
178 | 0 | rSh.AutoCorrect( *pACorr, cIns ); |
179 | 0 | } |
180 | 0 | else |
181 | 0 | { |
182 | 0 | rSh.Insert( OUString( cIns ) ); |
183 | 0 | } |
184 | 0 | } |
185 | 0 | break; |
186 | | |
187 | 0 | case FN_INSERT_NNBSP: // shift+mod2/alt+space inserts some other character w/o going through SwEditWin::KeyInput(), at least on macOS |
188 | 0 | case SID_INSERT_RLM : |
189 | 0 | case SID_INSERT_LRM : |
190 | 0 | case SID_INSERT_WJ : |
191 | 0 | case SID_INSERT_ZWSP: |
192 | 0 | { |
193 | 0 | sal_Unicode cIns = 0; |
194 | 0 | switch(nSlot) |
195 | 0 | { |
196 | 0 | case SID_INSERT_RLM : cIns = CHAR_RLM ; break; |
197 | 0 | case SID_INSERT_LRM : cIns = CHAR_LRM ; break; |
198 | 0 | case SID_INSERT_ZWSP : cIns = CHAR_ZWSP ; break; |
199 | 0 | case SID_INSERT_WJ: cIns = CHAR_WJ; break; |
200 | 0 | case FN_INSERT_NNBSP: cIns = CHAR_NNBSP; break; |
201 | 0 | } |
202 | 0 | rSh.Insert( OUString( cIns ) ); |
203 | 0 | } |
204 | 0 | break; |
205 | | |
206 | 0 | case FN_INSERT_BREAK: |
207 | 0 | { |
208 | 0 | if (!rSh.CursorInsideInputField() && !rSh.CursorInsideContentControl()) |
209 | 0 | { |
210 | 0 | rSh.SplitNode(); |
211 | 0 | } |
212 | 0 | else |
213 | 0 | { |
214 | 0 | rSh.InsertLineBreak(); |
215 | 0 | } |
216 | 0 | } |
217 | 0 | rReq.Done(); |
218 | 0 | break; |
219 | | |
220 | 0 | case FN_INSERT_PAGEBREAK: |
221 | 0 | if (const SfxStringItem* pStyleItem = rReq.GetArg<SfxStringItem>(FN_PARAM_1)) |
222 | 0 | { |
223 | 0 | UIName aStyleName(pStyleItem->GetValue()); |
224 | 0 | if (!aStyleName.isEmpty()) |
225 | 0 | rSh.InsertPageBreak(&aStyleName); |
226 | 0 | else |
227 | 0 | rSh.InsertPageBreak(); |
228 | 0 | } |
229 | 0 | else |
230 | 0 | { |
231 | 0 | rSh.InsertPageBreak(); |
232 | 0 | } |
233 | 0 | rReq.Done(); |
234 | 0 | break; |
235 | | |
236 | 0 | case FN_INSERT_LINEBREAK: |
237 | 0 | rSh.InsertLineBreak(); |
238 | 0 | rReq.Done(); |
239 | 0 | break; |
240 | | |
241 | 0 | case FN_INSERT_CONTENT_CONTROL: |
242 | 0 | rSh.InsertContentControl(SwContentControlType::RICH_TEXT); |
243 | 0 | rReq.Done(); |
244 | 0 | break; |
245 | | |
246 | 0 | case FN_INSERT_CHECKBOX_CONTENT_CONTROL: |
247 | 0 | rSh.InsertContentControl(SwContentControlType::CHECKBOX); |
248 | 0 | rReq.Done(); |
249 | 0 | break; |
250 | | |
251 | 0 | case FN_INSERT_DROPDOWN_CONTENT_CONTROL: |
252 | 0 | rSh.InsertContentControl(SwContentControlType::DROP_DOWN_LIST); |
253 | 0 | rReq.Done(); |
254 | 0 | break; |
255 | | |
256 | 0 | case FN_INSERT_PICTURE_CONTENT_CONTROL: |
257 | 0 | rSh.InsertContentControl(SwContentControlType::PICTURE); |
258 | 0 | rReq.Done(); |
259 | 0 | break; |
260 | | |
261 | 0 | case FN_INSERT_DATE_CONTENT_CONTROL: |
262 | 0 | rSh.InsertContentControl(SwContentControlType::DATE); |
263 | 0 | rReq.Done(); |
264 | 0 | break; |
265 | | |
266 | 0 | case FN_INSERT_PLAIN_TEXT_CONTENT_CONTROL: |
267 | 0 | rSh.InsertContentControl(SwContentControlType::PLAIN_TEXT); |
268 | 0 | rReq.Done(); |
269 | 0 | break; |
270 | | |
271 | 0 | case FN_INSERT_COMBO_BOX_CONTENT_CONTROL: |
272 | 0 | rSh.InsertContentControl(SwContentControlType::COMBO_BOX); |
273 | 0 | rReq.Done(); |
274 | 0 | break; |
275 | | |
276 | 0 | case FN_CONTENT_CONTROL_PROPERTIES: |
277 | 0 | { |
278 | 0 | SwWrtShell& rWrtSh = GetShell(); |
279 | 0 | SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create(); |
280 | 0 | ScopedVclPtr<VclAbstractDialog> pDlg(pFact->CreateSwContentControlDlg(GetView().GetFrameWeld(), rWrtSh)); |
281 | 0 | VclAbstractDialog::AsyncContext aContext; |
282 | 0 | aContext.maEndDialogFn = [](sal_Int32){}; |
283 | 0 | pDlg->StartExecuteAsync(aContext); |
284 | 0 | rReq.Done(); |
285 | 0 | break; |
286 | 0 | } |
287 | | |
288 | 0 | case FN_INSERT_COLUMN_BREAK: |
289 | 0 | rSh.InsertColumnBreak(); |
290 | 0 | rReq.Done(); |
291 | 0 | break; |
292 | | |
293 | 0 | case SID_HYPERLINK_SETLINK: |
294 | 0 | if (pItem) |
295 | 0 | InsertHyperlink(*static_cast<const SvxHyperlinkItem *>(pItem)); |
296 | 0 | rReq.Done(); |
297 | 0 | break; |
298 | | |
299 | 0 | #if HAVE_FEATURE_AVMEDIA |
300 | 0 | case SID_INSERT_AVMEDIA: |
301 | 0 | rReq.SetReturnValue(SfxBoolItem(nSlot, InsertMediaDlg( rReq ))); |
302 | 0 | break; |
303 | 0 | #endif |
304 | | |
305 | 0 | case SID_INSERT_OBJECT: |
306 | 0 | { |
307 | 0 | const SfxGlobalNameItem* pNameItem = rReq.GetArg(SID_INSERT_OBJECT); |
308 | 0 | SvGlobalName *pName = nullptr; |
309 | 0 | SvGlobalName aName; |
310 | 0 | if ( pNameItem ) |
311 | 0 | { |
312 | 0 | aName = pNameItem->GetValue(); |
313 | 0 | pName = &aName; |
314 | 0 | } |
315 | |
|
316 | 0 | svt::EmbeddedObjectRef xObj; |
317 | 0 | rSh.InsertObject( xObj, pName, nSlot); |
318 | 0 | rReq.Done(); |
319 | 0 | break; |
320 | 0 | } |
321 | 0 | case SID_INSERT_FLOATINGFRAME: |
322 | 0 | { |
323 | 0 | svt::EmbeddedObjectRef xObj; |
324 | 0 | const SfxStringItem* pNameItem = rReq.GetArg<SfxStringItem>(FN_PARAM_1); |
325 | 0 | const SfxStringItem* pURLItem = rReq.GetArg<SfxStringItem>(FN_PARAM_2); |
326 | 0 | const SvxSizeItem* pMarginItem = rReq.GetArg<SvxSizeItem>(FN_PARAM_3); |
327 | 0 | const SfxByteItem* pScrollingItem = rReq.GetArg<SfxByteItem>(FN_PARAM_4); |
328 | 0 | const SfxBoolItem* pBorderItem = rReq.GetArg<SfxBoolItem>(FN_PARAM_5); |
329 | |
|
330 | 0 | if(pURLItem) // URL is a _must_ |
331 | 0 | { |
332 | 0 | comphelper::EmbeddedObjectContainer aCnt; |
333 | 0 | OUString aName; |
334 | 0 | xObj.Assign( aCnt.CreateEmbeddedObject( SvGlobalName( SO3_IFRAME_CLASSID ).GetByteSequence(), aName ), |
335 | 0 | embed::Aspects::MSOLE_CONTENT ); |
336 | 0 | (void)svt::EmbeddedObjectRef::TryRunningState( xObj.GetObject() ); |
337 | 0 | uno::Reference < beans::XPropertySet > xSet( xObj->getComponent(), uno::UNO_QUERY ); |
338 | 0 | if ( xSet.is() ) |
339 | 0 | { |
340 | 0 | try |
341 | 0 | { |
342 | 0 | ScrollingMode eScroll = ScrollingMode::Auto; |
343 | 0 | if( pScrollingItem && pScrollingItem->GetValue() <= int(ScrollingMode::Auto) ) |
344 | 0 | eScroll = static_cast<ScrollingMode>(pScrollingItem->GetValue()); |
345 | |
|
346 | 0 | Size aMargin; |
347 | 0 | if ( pMarginItem ) |
348 | 0 | aMargin = pMarginItem->GetSize(); |
349 | |
|
350 | 0 | xSet->setPropertyValue(u"FrameURL"_ustr, uno::Any( pURLItem->GetValue() ) ); |
351 | 0 | if ( pNameItem ) |
352 | 0 | xSet->setPropertyValue(u"FrameName"_ustr, uno::Any( pNameItem->GetValue() ) ); |
353 | |
|
354 | 0 | if ( eScroll == ScrollingMode::Auto ) |
355 | 0 | xSet->setPropertyValue(u"FrameIsAutoScroll"_ustr, |
356 | 0 | uno::Any( true ) ); |
357 | 0 | else |
358 | 0 | xSet->setPropertyValue(u"FrameIsScrollingMode"_ustr, |
359 | 0 | uno::Any( eScroll == ScrollingMode::Yes ) ); |
360 | |
|
361 | 0 | if ( pBorderItem ) |
362 | 0 | xSet->setPropertyValue(u"FrameIsBorder"_ustr, |
363 | 0 | uno::Any( pBorderItem->GetValue() ) ); |
364 | |
|
365 | 0 | if ( pMarginItem ) |
366 | 0 | { |
367 | 0 | xSet->setPropertyValue(u"FrameMarginWidth"_ustr, |
368 | 0 | uno::Any( sal_Int32( aMargin.Width() ) ) ); |
369 | |
|
370 | 0 | xSet->setPropertyValue(u"FrameMarginHeight"_ustr, |
371 | 0 | uno::Any( sal_Int32( aMargin.Height() ) ) ); |
372 | 0 | } |
373 | 0 | } |
374 | 0 | catch (const uno::Exception&) |
375 | 0 | { |
376 | 0 | } |
377 | 0 | } |
378 | |
|
379 | 0 | rSh.InsertOleObject( xObj ); |
380 | 0 | } |
381 | 0 | else |
382 | 0 | { |
383 | 0 | rSh.InsertObject( xObj, nullptr, nSlot); |
384 | 0 | rReq.Done(); |
385 | 0 | } |
386 | 0 | } |
387 | 0 | break; |
388 | 0 | case SID_INSERT_DIAGRAM: |
389 | 0 | { |
390 | 0 | if (!SvtModuleOptions().IsChartInstalled()) |
391 | 0 | break; |
392 | 0 | if(!rReq.IsAPI()) |
393 | 0 | { |
394 | 0 | SwInsertChart( LINK( this, SwTextShell, DialogClosedHdl ) ); |
395 | 0 | } |
396 | 0 | else |
397 | 0 | { |
398 | 0 | uno::Reference< chart2::data::XDataProvider > xDataProvider; |
399 | 0 | bool bFillWithData = true; |
400 | 0 | OUString aRangeString; |
401 | 0 | if (!GetShell().IsTableComplexForChart()) |
402 | 0 | { |
403 | 0 | SwFrameFormat* pTableFormat = GetShell().GetTableFormat(); |
404 | 0 | aRangeString = pTableFormat->GetName().toString() + "." |
405 | 0 | + GetShell().GetBoxNms(); |
406 | | |
407 | | // get table data provider |
408 | 0 | xDataProvider.set( GetView().GetDocShell()->getIDocumentChartDataProviderAccess().GetChartDataProvider() ); |
409 | 0 | } |
410 | 0 | else |
411 | 0 | bFillWithData = false; // will create chart with only it's default image |
412 | |
|
413 | 0 | SwTableFUNC( &rSh ).InsertChart( xDataProvider, bFillWithData, aRangeString ); |
414 | 0 | rSh.LaunchOLEObj(); |
415 | |
|
416 | 0 | svt::EmbeddedObjectRef& xObj = rSh.GetOLEObject(); |
417 | 0 | if(pItem && xObj.is()) |
418 | 0 | { |
419 | 0 | Size aSize(static_cast<const SvxSizeItem*>(pItem)->GetSize()); |
420 | 0 | aSize = o3tl::convert(aSize, o3tl::Length::twip, o3tl::Length::mm100); |
421 | |
|
422 | 0 | if(aSize.Width() > MINLAY&& aSize.Height()> MINLAY) |
423 | 0 | { |
424 | 0 | awt::Size aSz; |
425 | 0 | aSz.Width = aSize.Width(); |
426 | 0 | aSz.Height = aSize.Height(); |
427 | 0 | xObj->setVisualAreaSize( xObj.GetViewAspect(), aSz ); |
428 | 0 | } |
429 | 0 | } |
430 | 0 | } |
431 | 0 | } |
432 | 0 | break; |
433 | | |
434 | 0 | case FN_INSERT_SMA: |
435 | 0 | { |
436 | | // if sidebar is closed - open to show elements deck |
437 | 0 | if (comphelper::LibreOfficeKit::isActive()) |
438 | 0 | sfx2::sidebar::Sidebar::Setup(u""); |
439 | | |
440 | | // #i34343# Inserting a math object into an autocompletion crashes |
441 | | // the suggestion has to be removed before |
442 | 0 | GetView().GetEditWin().StopQuickHelp(); |
443 | 0 | SvGlobalName aGlobalName( SO3_SM_CLASSID ); |
444 | 0 | rSh.InsertObject( svt::EmbeddedObjectRef(), &aGlobalName ); |
445 | 0 | } |
446 | 0 | break; |
447 | | |
448 | 0 | case FN_INSERT_TABLE: |
449 | 0 | InsertTable( rReq ); |
450 | 0 | break; |
451 | | |
452 | 0 | case FN_INSERT_FRAME_INTERACT_NOCOL: |
453 | 0 | case FN_INSERT_FRAME_INTERACT: |
454 | 0 | { |
455 | 0 | sal_uInt16 nCols = 1; |
456 | 0 | bool bModifier1 = rReq.GetModifier() == KEY_MOD1; |
457 | 0 | if(pArgs) |
458 | 0 | { |
459 | 0 | const SfxUInt16Item* pColsItem = nullptr; |
460 | 0 | if(FN_INSERT_FRAME_INTERACT_NOCOL != nSlot && |
461 | 0 | (pColsItem = pArgs->GetItemIfSet(SID_ATTR_COLUMNS, false))) |
462 | 0 | nCols = pColsItem->GetValue(); |
463 | 0 | if(const SfxUInt16Item* pModifierItem = pArgs->GetItemIfSet(SID_MODIFIER, false)) |
464 | 0 | bModifier1 |= KEY_MOD1 == pModifierItem->GetValue(); |
465 | 0 | } |
466 | 0 | if(bModifier1 ) |
467 | 0 | { |
468 | 0 | SwEditWin& rEdtWin = GetView().GetEditWin(); |
469 | 0 | Size aWinSize = rEdtWin.GetSizePixel(); |
470 | 0 | Point aStartPos(aWinSize.Width()/2, aWinSize.Height() / 2); |
471 | 0 | aStartPos = rEdtWin.PixelToLogic(aStartPos); |
472 | 0 | constexpr tools::Long constTwips_2cm = o3tl::toTwips(2, o3tl::Length::cm); |
473 | 0 | constexpr tools::Long constTwips_4cm = o3tl::toTwips(4, o3tl::Length::cm); |
474 | 0 | aStartPos.AdjustX(-constTwips_4cm); |
475 | 0 | aStartPos.AdjustY(-constTwips_2cm); |
476 | 0 | Size aSize(2 * constTwips_4cm, 2 * constTwips_2cm); |
477 | 0 | GetShell().LockPaint(LockPaintReason::InsertFrame); |
478 | 0 | GetShell().StartAllAction(); |
479 | 0 | SwFlyFrameAttrMgr aMgr( true, GetShellPtr(), Frmmgr_Type::TEXT, nullptr ); |
480 | 0 | if(nCols > 1) |
481 | 0 | { |
482 | 0 | SwFormatCol aCol; |
483 | 0 | aCol.Init( nCols, aCol.GetGutterWidth(), aCol.GetWishWidth() ); |
484 | 0 | aMgr.SetCol( aCol ); |
485 | 0 | } |
486 | 0 | aMgr.InsertFlyFrame(RndStdIds::FLY_AT_PARA, aStartPos, aSize); |
487 | 0 | GetShell().EndAllAction(); |
488 | 0 | GetShell().UnlockPaint(); |
489 | 0 | } |
490 | 0 | else |
491 | 0 | { |
492 | 0 | GetView().InsFrameMode(nCols); |
493 | 0 | } |
494 | 0 | rReq.Ignore(); |
495 | 0 | } |
496 | 0 | break; |
497 | 0 | case FN_INSERT_FRAME: |
498 | 0 | { |
499 | 0 | bool bSingleCol = false; |
500 | 0 | if( nullptr!= dynamic_cast< SwWebDocShell*>( GetView().GetDocShell()) ) |
501 | 0 | { |
502 | 0 | if( HTML_CFG_MSIE == SvxHtmlOptions::GetExportMode() ) |
503 | 0 | { |
504 | 0 | bSingleCol = true; |
505 | 0 | } |
506 | |
|
507 | 0 | } |
508 | | // Create new border |
509 | 0 | SwFlyFrameAttrMgr aMgr( true, GetShellPtr(), Frmmgr_Type::TEXT, nullptr ); |
510 | 0 | if(pArgs) |
511 | 0 | { |
512 | 0 | Size aSize(aMgr.GetSize()); |
513 | 0 | aSize.setWidth( GetShell().GetAnyCurRect(CurRectType::PagePrt).Width() ); |
514 | 0 | Point aPos = aMgr.GetPos(); |
515 | 0 | RndStdIds eAnchor = RndStdIds::FLY_AT_PARA; |
516 | 0 | if(pArgs->GetItemState(nSlot, false, &pItem) == SfxItemState::SET) |
517 | 0 | eAnchor = static_cast<RndStdIds>(static_cast<const SfxUInt16Item *>(pItem)->GetValue()); |
518 | 0 | if(pArgs->GetItemState(FN_PARAM_1, false, &pItem) == SfxItemState::SET) |
519 | 0 | aPos = static_cast<const SfxPointItem *>(pItem)->GetValue(); |
520 | 0 | if(pArgs->GetItemState(FN_PARAM_2, false, &pItem) == SfxItemState::SET) |
521 | 0 | aSize = static_cast<const SvxSizeItem *>(pItem)->GetSize(); |
522 | 0 | if(const SfxUInt16Item* pColsItem = pArgs->GetItemIfSet(SID_ATTR_COLUMNS, false)) |
523 | 0 | { |
524 | 0 | const sal_uInt16 nCols = pColsItem->GetValue(); |
525 | 0 | if( !bSingleCol && 1 < nCols ) |
526 | 0 | { |
527 | 0 | SwFormatCol aFormatCol; |
528 | 0 | aFormatCol.Init( nCols , (rReq.IsAPI() ? 0 |
529 | 0 | : DEF_GUTTER_WIDTH), USHRT_MAX ); |
530 | 0 | aMgr.SetCol(aFormatCol); |
531 | 0 | } |
532 | 0 | } |
533 | |
|
534 | 0 | GetShell().LockPaint(LockPaintReason::InsertFrame); |
535 | 0 | GetShell().StartAllAction(); |
536 | |
|
537 | 0 | aMgr.InsertFlyFrame(eAnchor, aPos, aSize); |
538 | |
|
539 | 0 | GetShell().EndAllAction(); |
540 | 0 | GetShell().UnlockPaint(); |
541 | 0 | } |
542 | 0 | else |
543 | 0 | { |
544 | 0 | auto xSet = CreateInsertFrameItemSet(aMgr); |
545 | |
|
546 | 0 | FieldUnit eMetric = ::GetDfltMetric(dynamic_cast<SwWebDocShell*>( GetView().GetDocShell()) != nullptr ); |
547 | 0 | SwModule::get()->PutItem(SfxUInt16Item(SID_ATTR_METRIC, static_cast< sal_uInt16 >(eMetric))); |
548 | 0 | SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create(); |
549 | 0 | VclPtr<SfxAbstractTabDialog> pDlg(pFact->CreateFrameTabDialog(u"FrameDialog"_ustr, |
550 | 0 | GetView().GetViewFrame(), |
551 | 0 | GetView().GetFrameWeld(), |
552 | 0 | *xSet)); |
553 | 0 | pDlg->StartExecuteAsync([xSet=std::move(xSet), pDlg, nSlot, this](sal_Int32 nResult) { |
554 | 0 | if (nResult == RET_OK && pDlg->GetOutputItemSet()) |
555 | 0 | { |
556 | 0 | SwFlyFrameAttrMgr aAttrMgr( true, GetShellPtr(), Frmmgr_Type::TEXT, nullptr ); |
557 | | //local variable necessary at least after call of .AutoCaption() because this could be deleted at this point |
558 | 0 | SwWrtShell& rShell = GetShell(); |
559 | 0 | rShell.LockPaint(LockPaintReason::InsertFrame); |
560 | 0 | rShell.StartAllAction(); |
561 | 0 | rShell.StartUndo(SwUndoId::INSERT); |
562 | |
|
563 | 0 | SfxItemSet aOutSet(*pDlg->GetOutputItemSet()); |
564 | 0 | const SvxBoxItem* pBox = xSet->GetItem(RES_BOX); |
565 | 0 | if (pBox && !aOutSet.HasItem(RES_BOX)) |
566 | 0 | { |
567 | | // The input set had border info but the output set not, then copy it over |
568 | | // to not lose the custom border info. This can happen when a whole table |
569 | | // is selected and that case has its own defaults, not matching the frame |
570 | | // style. |
571 | 0 | aOutSet.Put(*pBox); |
572 | 0 | } |
573 | 0 | aAttrMgr.SetAttrSet(aOutSet); |
574 | | |
575 | | // At first delete the selection at the ClickToEditField. |
576 | 0 | if( rShell.IsInClickToEdit() ) |
577 | 0 | rShell.DelRight(); |
578 | |
|
579 | 0 | aAttrMgr.InsertFlyFrame(); |
580 | |
|
581 | 0 | uno::Reference< frame::XDispatchRecorder > xRecorder = |
582 | 0 | GetView().GetViewFrame().GetBindings().GetRecorder(); |
583 | 0 | if ( xRecorder.is() ) |
584 | 0 | { |
585 | | //FN_INSERT_FRAME |
586 | 0 | sal_uInt16 nAnchor = static_cast<sal_uInt16>(aAttrMgr.GetAnchor()); |
587 | 0 | SfxRequest aReq(GetView().GetViewFrame(), FN_INSERT_FRAME); |
588 | 0 | aReq.AppendItem(SfxUInt16Item(nSlot, nAnchor)); |
589 | 0 | aReq.AppendItem(SfxPointItem(FN_PARAM_1, rShell.GetObjAbsPos())); |
590 | 0 | aReq.AppendItem(SvxSizeItem(FN_PARAM_2, rShell.GetObjSize())); |
591 | 0 | aReq.Done(); |
592 | 0 | } |
593 | |
|
594 | 0 | GetView().AutoCaption(FRAME_CAP); |
595 | |
|
596 | 0 | { |
597 | 0 | SwRewriter aRewriter; |
598 | |
|
599 | 0 | aRewriter.AddRule(UndoArg1, SwResId(STR_FRAME)); |
600 | |
|
601 | 0 | rShell.EndUndo(SwUndoId::INSERT, &aRewriter); |
602 | 0 | } |
603 | 0 | rShell.EndAllAction(); |
604 | 0 | rShell.UnlockPaint(); |
605 | 0 | } |
606 | 0 | pDlg->disposeOnce(); |
607 | 0 | }); |
608 | 0 | } |
609 | 0 | break; |
610 | 0 | } |
611 | 0 | case FN_FORMAT_COLUMN : |
612 | 0 | { |
613 | 0 | SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create(); |
614 | 0 | VclPtr<VclAbstractDialog> pColDlg(pFact->CreateSwColumnDialog(GetView().GetFrameWeld(), rSh)); |
615 | 0 | pColDlg->StartExecuteAsync([=](sal_Int32 /*nResult*/){ |
616 | 0 | pColDlg->disposeOnce(); |
617 | 0 | }); |
618 | 0 | } |
619 | 0 | break; |
620 | | |
621 | 0 | default: |
622 | 0 | OSL_ENSURE(false, "wrong dispatcher"); |
623 | 0 | return; |
624 | 0 | } |
625 | 0 | } |
626 | | |
627 | | static bool lcl_IsMarkInSameSection( SwWrtShell& rWrtSh, const SwSection* pSect ) |
628 | 0 | { |
629 | 0 | rWrtSh.SwapPam(); |
630 | 0 | bool bRet = pSect == rWrtSh.GetCurrSection(); |
631 | 0 | rWrtSh.SwapPam(); |
632 | 0 | return bRet; |
633 | 0 | } |
634 | | |
635 | | void SwTextShell::StateInsert( SfxItemSet &rSet ) |
636 | 0 | { |
637 | 0 | const bool bHtmlModeOn = ::GetHtmlMode(GetView().GetDocShell()) & HTMLMODE_ON; |
638 | 0 | SfxWhichIter aIter( rSet ); |
639 | 0 | SwWrtShell &rSh = GetShell(); |
640 | 0 | sal_uInt16 nWhich = aIter.FirstWhich(); |
641 | 0 | SfxObjectCreateMode eCreateMode = |
642 | 0 | GetView().GetDocShell()->GetCreateMode(); |
643 | 0 | const bool bCursorInHidden = rSh.IsInHiddenRange(/*bSelect=*/false); |
644 | |
|
645 | 0 | while ( nWhich ) |
646 | 0 | { |
647 | 0 | switch ( nWhich ) |
648 | 0 | { |
649 | 0 | case SID_INSERT_AVMEDIA: |
650 | 0 | if ( GetShell().IsSelFrameMode() |
651 | 0 | || GetShell().CursorInsideInputField() |
652 | 0 | || SfxObjectCreateMode::EMBEDDED == eCreateMode |
653 | 0 | || bCursorInHidden ) |
654 | 0 | { |
655 | 0 | rSet.DisableItem( nWhich ); |
656 | 0 | } |
657 | 0 | break; |
658 | | |
659 | 0 | case SID_INSERT_DIAGRAM: |
660 | 0 | if (!SvtModuleOptions().IsChartInstalled() |
661 | 0 | || GetShell().CursorInsideInputField() |
662 | 0 | || eCreateMode == SfxObjectCreateMode::EMBEDDED |
663 | 0 | || bCursorInHidden ) |
664 | 0 | { |
665 | 0 | rSet.DisableItem( nWhich ); |
666 | 0 | } |
667 | 0 | break; |
668 | | |
669 | 0 | case FN_INSERT_SMA: |
670 | 0 | if (!SvtModuleOptions().IsMathInstalled() |
671 | 0 | || eCreateMode == SfxObjectCreateMode::EMBEDDED |
672 | 0 | || bCursorInHidden |
673 | 0 | || rSh.CursorInsideInputField() ) |
674 | 0 | { |
675 | 0 | rSet.DisableItem( nWhich ); |
676 | 0 | } |
677 | 0 | break; |
678 | | |
679 | 0 | case SID_INSERT_FLOATINGFRAME: |
680 | 0 | case SID_INSERT_OBJECT: |
681 | 0 | { |
682 | 0 | if( eCreateMode == SfxObjectCreateMode::EMBEDDED || bCursorInHidden ) |
683 | 0 | { |
684 | 0 | rSet.DisableItem( nWhich ); |
685 | 0 | } |
686 | 0 | else if( GetShell().IsSelFrameMode() |
687 | 0 | || GetShell().CursorInsideInputField() ) |
688 | 0 | { |
689 | 0 | rSet.DisableItem( nWhich ); |
690 | 0 | } |
691 | 0 | else if(SID_INSERT_FLOATINGFRAME == nWhich && bHtmlModeOn) |
692 | 0 | { |
693 | 0 | const sal_uInt16 nExport = SvxHtmlOptions::GetExportMode(); |
694 | 0 | if(HTML_CFG_MSIE != nExport && HTML_CFG_WRITER != nExport ) |
695 | 0 | rSet.DisableItem(nWhich); |
696 | 0 | } |
697 | 0 | } |
698 | 0 | break; |
699 | | |
700 | 0 | case FN_INSERT_FRAME_INTERACT_NOCOL : |
701 | 0 | case FN_INSERT_FRAME_INTERACT: |
702 | 0 | { |
703 | 0 | if( GetShell().IsSelFrameMode() |
704 | 0 | || rSh.IsTableMode() |
705 | 0 | || GetShell().CursorInsideInputField() |
706 | 0 | || bCursorInHidden ) |
707 | 0 | rSet.DisableItem(nWhich); |
708 | 0 | } |
709 | 0 | break; |
710 | | |
711 | 0 | case SID_HYPERLINK_GETLINK: |
712 | 0 | { |
713 | 0 | SfxItemSet aSet(SfxItemSet::makeFixedSfxItemSet<RES_TXTATR_INETFMT, RES_TXTATR_INETFMT>(GetPool())); |
714 | 0 | rSh.GetCurAttr( aSet ); |
715 | |
|
716 | 0 | SvxHyperlinkItem aHLinkItem; |
717 | 0 | aHLinkItem.SetShowName(true); |
718 | 0 | aHLinkItem.SetShowText(true); |
719 | 0 | if(const SwFormatINetFormat* pINetFormat = aSet.GetItemIfSet(RES_TXTATR_INETFMT, false)) |
720 | 0 | { |
721 | 0 | aHLinkItem.SetURL(pINetFormat->GetValue()); |
722 | 0 | aHLinkItem.SetTargetFrame(pINetFormat->GetTargetFrame()); |
723 | 0 | aHLinkItem.SetIntName(pINetFormat->GetName()); |
724 | 0 | const SvxMacro *pMacro = pINetFormat->GetMacro( SvMacroItemId::OnMouseOver ); |
725 | 0 | if( pMacro ) |
726 | 0 | aHLinkItem.SetMacro(HyperDialogEvent::MouseOverObject, *pMacro); |
727 | |
|
728 | 0 | pMacro = pINetFormat->GetMacro( SvMacroItemId::OnClick ); |
729 | 0 | if( pMacro ) |
730 | 0 | aHLinkItem.SetMacro(HyperDialogEvent::MouseClickObject, *pMacro); |
731 | |
|
732 | 0 | pMacro = pINetFormat->GetMacro( SvMacroItemId::OnMouseOut ); |
733 | 0 | if( pMacro ) |
734 | 0 | aHLinkItem.SetMacro(HyperDialogEvent::MouseOutObject, *pMacro); |
735 | | |
736 | | // Get the text of the Link. |
737 | 0 | rSh.StartAction(); |
738 | 0 | const bool bAtEnd(rSh.IsCursorPtAtEnd()); |
739 | 0 | if(!bAtEnd) // tdf#91832: ensure forward selection |
740 | 0 | rSh.SwapPam(); |
741 | 0 | rSh.CreateCursor(); |
742 | 0 | if(!bAtEnd) |
743 | 0 | rSh.SwapPam(); |
744 | 0 | rSh.SwCursorShell::SelectTextAttr(RES_TXTATR_INETFMT,true); |
745 | 0 | OUString sLinkName = rSh.GetSelText(); |
746 | 0 | aHLinkItem.SetName(sLinkName); |
747 | 0 | aHLinkItem.SetInsertMode(HLINK_FIELD); |
748 | 0 | rSh.DestroyCursor(); |
749 | 0 | rSh.EndAction(); |
750 | 0 | } |
751 | 0 | else |
752 | 0 | { |
753 | 0 | OUString sReturn = rSh.GetSelText(); |
754 | 0 | sReturn = sReturn.copy(0, std::min<sal_Int32>(255, sReturn.getLength())); |
755 | 0 | aHLinkItem.SetName(comphelper::string::stripEnd(sReturn, ' ')); |
756 | 0 | } |
757 | |
|
758 | 0 | aHLinkItem.SetInsertMode(static_cast<SvxLinkInsertMode>(aHLinkItem.GetInsertMode() | |
759 | 0 | (bHtmlModeOn ? HLINK_HTMLMODE : 0))); |
760 | 0 | aHLinkItem.SetMacroEvents ( HyperDialogEvent::MouseOverObject| |
761 | 0 | HyperDialogEvent::MouseClickObject | HyperDialogEvent::MouseOutObject ); |
762 | |
|
763 | 0 | rSet.Put(aHLinkItem); |
764 | 0 | } |
765 | 0 | break; |
766 | | |
767 | 0 | case FN_INSERT_FRAME: |
768 | 0 | if (rSh.IsSelFrameMode() ) |
769 | 0 | { |
770 | 0 | const SelectionType nSel = rSh.GetSelectionType(); |
771 | 0 | if( ((SelectionType::Graphic | SelectionType::Ole ) & nSel ) || bCursorInHidden ) |
772 | 0 | rSet.DisableItem(nWhich); |
773 | 0 | } |
774 | 0 | else if ( rSh.CursorInsideInputField() ) |
775 | 0 | { |
776 | 0 | rSet.DisableItem(nWhich); |
777 | 0 | } |
778 | 0 | break; |
779 | | |
780 | 0 | case FN_FORMAT_COLUMN : |
781 | 0 | { |
782 | | //#i80458# column dialog cannot work if the selection contains different page styles and different sections |
783 | 0 | bool bDisable = true; |
784 | 0 | if( rSh.GetFlyFrameFormat() || rSh.GetSelectedPageDescs() ) |
785 | 0 | bDisable = false; |
786 | 0 | if( bDisable ) |
787 | 0 | { |
788 | 0 | const SwSection* pCurrSection = rSh.GetCurrSection(); |
789 | 0 | const sal_uInt16 nFullSectCnt = rSh.GetFullSelectedSectionCount(); |
790 | 0 | if( pCurrSection && ( !rSh.HasSelection() || 0 != nFullSectCnt )) |
791 | 0 | bDisable = false; |
792 | 0 | else if( |
793 | 0 | rSh.HasSelection() && rSh.IsInsRegionAvailable() && |
794 | 0 | ( !pCurrSection || ( 1 != nFullSectCnt && |
795 | 0 | lcl_IsMarkInSameSection( rSh, pCurrSection ) ))) |
796 | 0 | bDisable = false; |
797 | 0 | } |
798 | 0 | if(bDisable) |
799 | 0 | rSet.DisableItem(nWhich); |
800 | 0 | } |
801 | 0 | break; |
802 | 0 | } |
803 | 0 | nWhich = aIter.NextWhich(); |
804 | 0 | } |
805 | 0 | } |
806 | | |
807 | | void SwTextShell::ExecDelete(SfxRequest &rReq) |
808 | 0 | { |
809 | 0 | SwWrtShell &rSh = GetShell(); |
810 | 0 | switch( rReq.GetSlot() ) |
811 | 0 | { |
812 | 0 | case FN_DELETE_SENT: |
813 | 0 | if( rSh.IsTableMode() ) |
814 | 0 | { |
815 | 0 | rSh.DeleteRow(); |
816 | 0 | rSh.EnterStdMode(); |
817 | 0 | } |
818 | 0 | else |
819 | 0 | rSh.DelToEndOfSentence(); |
820 | 0 | break; |
821 | 0 | case FN_DELETE_BACK_SENT: |
822 | 0 | rSh.DelToStartOfSentence(); |
823 | 0 | break; |
824 | 0 | case FN_DELETE_WORD: |
825 | 0 | rSh.DelNxtWord(); |
826 | 0 | break; |
827 | 0 | case FN_DELETE_BACK_WORD: |
828 | 0 | rSh.DelPrvWord(); |
829 | 0 | break; |
830 | 0 | case FN_DELETE_LINE: |
831 | 0 | rSh.DelToEndOfLine(); |
832 | 0 | break; |
833 | 0 | case FN_DELETE_BACK_LINE: |
834 | 0 | rSh.DelToStartOfLine(); |
835 | 0 | break; |
836 | 0 | case FN_DELETE_PARA: |
837 | 0 | rSh.DelToEndOfPara(); |
838 | 0 | break; |
839 | 0 | case FN_DELETE_BACK_PARA: |
840 | 0 | rSh.DelToStartOfPara(); |
841 | 0 | break; |
842 | 0 | case FN_DELETE_WHOLE_LINE: |
843 | 0 | rSh.DelLine(); |
844 | 0 | break; |
845 | 0 | default: |
846 | 0 | OSL_ENSURE(false, "wrong dispatcher"); |
847 | 0 | return; |
848 | 0 | } |
849 | 0 | rReq.Done(); |
850 | 0 | } |
851 | | |
852 | | void SwTextShell::ExecTransliteration( SfxRequest& rReq ) |
853 | 0 | { |
854 | 0 | using namespace ::com::sun::star::i18n; |
855 | 0 | TransliterationFlags nMode = TransliterationFlags::NONE; |
856 | |
|
857 | 0 | switch( rReq.GetSlot() ) |
858 | 0 | { |
859 | 0 | case SID_TRANSLITERATE_SENTENCE_CASE: |
860 | 0 | nMode = TransliterationFlags::SENTENCE_CASE; |
861 | 0 | break; |
862 | 0 | case SID_TRANSLITERATE_TITLE_CASE: |
863 | 0 | nMode = TransliterationFlags::TITLE_CASE; |
864 | 0 | break; |
865 | 0 | case SID_TRANSLITERATE_TOGGLE_CASE: |
866 | 0 | nMode = TransliterationFlags::TOGGLE_CASE; |
867 | 0 | break; |
868 | 0 | case SID_TRANSLITERATE_UPPER: |
869 | 0 | nMode = TransliterationFlags::LOWERCASE_UPPERCASE; |
870 | 0 | break; |
871 | 0 | case SID_TRANSLITERATE_LOWER: |
872 | 0 | nMode = TransliterationFlags::UPPERCASE_LOWERCASE; |
873 | 0 | break; |
874 | | |
875 | 0 | case SID_TRANSLITERATE_HALFWIDTH: |
876 | 0 | nMode = TransliterationFlags::FULLWIDTH_HALFWIDTH; |
877 | 0 | break; |
878 | 0 | case SID_TRANSLITERATE_FULLWIDTH: |
879 | 0 | nMode = TransliterationFlags::HALFWIDTH_FULLWIDTH; |
880 | 0 | break; |
881 | | |
882 | 0 | case SID_TRANSLITERATE_HIRAGANA: |
883 | 0 | nMode = TransliterationFlags::KATAKANA_HIRAGANA; |
884 | 0 | break; |
885 | 0 | case SID_TRANSLITERATE_KATAKANA: |
886 | 0 | nMode = TransliterationFlags::HIRAGANA_KATAKANA; |
887 | 0 | break; |
888 | | |
889 | 0 | default: |
890 | 0 | OSL_ENSURE(false, "wrong dispatcher"); |
891 | 0 | } |
892 | | |
893 | 0 | if( nMode != TransliterationFlags::NONE ) |
894 | 0 | { |
895 | 0 | GetShell().TransliterateText( nMode ); |
896 | 0 | rReq.Done(); |
897 | 0 | } |
898 | 0 | } |
899 | | |
900 | | void SwTextShell::ExecRotateTransliteration( SfxRequest& rReq ) |
901 | 0 | { |
902 | 0 | if( rReq.GetSlot() == SID_TRANSLITERATE_ROTATE_CASE ) |
903 | 0 | { |
904 | 0 | TransliterationFlags transFlags = m_aRotateCase.getNextMode(); |
905 | 0 | bool bSentenceCase = TransliterationFlags::SENTENCE_CASE == transFlags; |
906 | 0 | SwWrtShell& rSh = GetShell(); |
907 | 0 | if (rSh.HasSelection()) |
908 | 0 | { |
909 | 0 | if (bSentenceCase) |
910 | 0 | { |
911 | 0 | OUString aSelection; |
912 | 0 | rSh.GetSelectedText(aSelection); |
913 | 0 | aSelection = aSelection.trim(); |
914 | 0 | if (aSelection.getLength() <= 2 || (aSelection.indexOf(' ') < 0 && aSelection.indexOf('\t') < 0)) |
915 | 0 | transFlags = m_aRotateCase.getNextMode(); |
916 | 0 | } |
917 | 0 | rSh.TransliterateText(transFlags); |
918 | 0 | rReq.Done(); |
919 | 0 | } |
920 | 0 | else |
921 | 0 | { |
922 | 0 | if (bSentenceCase) |
923 | 0 | transFlags = m_aRotateCase.getNextMode(); |
924 | 0 | if ((rSh.IsEndWrd() || rSh.IsStartWord() || rSh.IsInWord()) && rSh.SelWrd(nullptr, i18n::WordType::WORD_COUNT)) |
925 | 0 | { |
926 | 0 | rSh.TransliterateText(transFlags); |
927 | 0 | rReq.Done(); |
928 | 0 | } |
929 | 0 | } |
930 | 0 | } |
931 | 0 | } |
932 | | |
933 | | SwTextShell::SwTextShell(SwView &_rView) : |
934 | 4.01k | SwBaseShell(_rView) |
935 | 4.01k | { |
936 | 4.01k | SetName(u"Text"_ustr); |
937 | 4.01k | SfxShell::SetContextName(vcl::EnumContext::GetContextName(vcl::EnumContext::Context::Text)); |
938 | 4.01k | } |
939 | | |
940 | | SwTextShell::~SwTextShell() |
941 | 4.01k | { |
942 | 4.01k | } |
943 | | |
944 | | std::shared_ptr<SfxItemSet> SwTextShell::CreateInsertFrameItemSet(SwFlyFrameAttrMgr& rMgr) |
945 | 0 | { |
946 | 0 | auto xSet = std::make_shared<SfxItemSet>(GetPool(), svl::Items< |
947 | 0 | RES_FRMATR_BEGIN, RES_FRMATR_END-1, |
948 | 0 | XATTR_FILL_FIRST, XATTR_FILL_LAST, // tdf#95003 |
949 | 0 | SID_ATTR_BORDER_INNER, SID_ATTR_BORDER_INNER, |
950 | 0 | SID_ATTR_PAGE_SIZE, SID_ATTR_PAGE_SIZE, |
951 | 0 | SID_COLOR_TABLE, SID_PATTERN_LIST, |
952 | 0 | SID_HTML_MODE, SID_HTML_MODE, |
953 | 0 | FN_GET_PRINT_AREA, FN_GET_PRINT_AREA, |
954 | 0 | FN_SET_FRM_NAME, FN_SET_FRM_NAME>); |
955 | 0 | xSet->Put(SfxUInt16Item(SID_HTML_MODE, ::GetHtmlMode(GetView().GetDocShell()))); |
956 | | |
957 | | // For the Area tab page. |
958 | 0 | GetShell().GetDoc()->getIDocumentDrawModelAccess().GetDrawModel()->PutAreaListItems(*xSet); |
959 | |
|
960 | 0 | const SwRect &rPg = GetShell().GetAnyCurRect(CurRectType::Page); |
961 | 0 | SwFormatFrameSize aFrameSize(SwFrameSize::Variable, rPg.Width(), rPg.Height()); |
962 | 0 | aFrameSize.SetWhich(GetPool().GetWhichIDFromSlotID(SID_ATTR_PAGE_SIZE)); |
963 | 0 | xSet->Put(aFrameSize); |
964 | |
|
965 | 0 | const SwRect &rPr = GetShell().GetAnyCurRect(CurRectType::PagePrt); |
966 | 0 | SwFormatFrameSize aPrtSize(SwFrameSize::Variable, rPr.Width(), rPr.Height()); |
967 | 0 | aPrtSize.SetWhich(GetPool().GetWhichIDFromSlotID(FN_GET_PRINT_AREA)); |
968 | 0 | xSet->Put(aPrtSize); |
969 | |
|
970 | 0 | xSet->Put(rMgr.GetAttrSet()); |
971 | 0 | xSet->SetParent( rMgr.GetAttrSet().GetParent() ); |
972 | | |
973 | | // Delete minimum size in columns. |
974 | 0 | SvxBoxInfoItem aBoxInfo(xSet->Get(SID_ATTR_BORDER_INNER)); |
975 | 0 | const SvxBoxItem& rBox = xSet->Get(RES_BOX); |
976 | 0 | aBoxInfo.SetMinDist(false); |
977 | 0 | aBoxInfo.SetDefDist(rBox.GetDistance(SvxBoxItemLine::LEFT)); |
978 | 0 | xSet->Put(aBoxInfo); |
979 | |
|
980 | 0 | if (!SwFlyFrameAttrMgr::SingleTableSelected(GetShell())) |
981 | 0 | { |
982 | 0 | SwFormatAnchor aAnchor(RndStdIds::FLY_AT_CHAR); |
983 | 0 | xSet->Put(aAnchor); |
984 | 0 | } |
985 | |
|
986 | 0 | return xSet; |
987 | 0 | } |
988 | | |
989 | | void SwTextShell::InsertSymbol( SfxRequest& rReq ) |
990 | 0 | { |
991 | 0 | const SfxItemSet *pArgs = rReq.GetArgs(); |
992 | 0 | const SfxStringItem* pItem = nullptr; |
993 | 0 | if( pArgs ) |
994 | 0 | pItem = pArgs->GetItemIfSet(SID_CHARMAP, false); |
995 | |
|
996 | 0 | OUString aChars, aFontName; |
997 | 0 | if ( pItem ) |
998 | 0 | { |
999 | 0 | aChars = pItem->GetValue(); |
1000 | 0 | const SfxStringItem* pFontItem = pArgs->GetItemIfSet( SID_ATTR_SPECIALCHAR, false ); |
1001 | 0 | if ( pFontItem ) |
1002 | 0 | aFontName = pFontItem->GetValue(); |
1003 | 0 | } |
1004 | |
|
1005 | 0 | SwWrtShell &rSh = GetShell(); |
1006 | 0 | SfxItemSet aSet(SfxItemSet::makeFixedSfxItemSet< |
1007 | 0 | RES_CHRATR_FONT, RES_CHRATR_FONT, |
1008 | 0 | RES_CHRATR_CJK_FONT, RES_CHRATR_CJK_FONT, |
1009 | 0 | RES_CHRATR_CTL_FONT, RES_CHRATR_CTL_FONT>(GetPool())); |
1010 | 0 | rSh.GetCurAttr( aSet ); |
1011 | 0 | SvtScriptType nScript = rSh.GetScriptType(); |
1012 | |
|
1013 | 0 | std::shared_ptr<SvxFontItem> aFont(std::make_shared<SvxFontItem>(RES_CHRATR_FONT)); |
1014 | 0 | { |
1015 | 0 | SvxScriptSetItem aSetItem( SID_ATTR_CHAR_FONT, *aSet.GetPool() ); |
1016 | 0 | aSetItem.GetItemSet().Put( aSet, false ); |
1017 | 0 | const SfxPoolItem* pI = aSetItem.GetItemOfScript( nScript ); |
1018 | 0 | if( pI ) |
1019 | 0 | { |
1020 | 0 | aFont.reset(static_cast<SvxFontItem*>(pI->Clone())); |
1021 | 0 | } |
1022 | 0 | else |
1023 | 0 | { |
1024 | 0 | TypedWhichId<SvxFontItem> nFontWhich = |
1025 | 0 | GetWhichOfScript( |
1026 | 0 | RES_CHRATR_FONT, |
1027 | 0 | SvtLanguageOptions::GetI18NScriptTypeOfLanguage( GetAppLanguage() ) ); |
1028 | 0 | aFont.reset(aSet.Get(nFontWhich).Clone()); |
1029 | 0 | } |
1030 | |
|
1031 | 0 | if (aFontName.isEmpty()) |
1032 | 0 | aFontName = aFont->GetFamilyName(); |
1033 | 0 | } |
1034 | |
|
1035 | 0 | vcl::Font aNewFont(aFontName, Size(1,1)); // Size only because CTOR. |
1036 | 0 | if( aChars.isEmpty() ) |
1037 | 0 | { |
1038 | | // Set selected font as default. |
1039 | 0 | SfxAllItemSet aAllSet( rSh.GetAttrPool() ); |
1040 | 0 | aAllSet.Put( SfxBoolItem( FN_PARAM_1, false ) ); |
1041 | |
|
1042 | 0 | SwViewOption aOpt(*GetShell().GetViewOptions()); |
1043 | 0 | const OUString& sSymbolFont = aOpt.GetSymbolFont(); |
1044 | 0 | if( aFontName.isEmpty() && !sSymbolFont.isEmpty() ) |
1045 | 0 | aAllSet.Put( SfxStringItem( SID_FONT_NAME, sSymbolFont ) ); |
1046 | 0 | else |
1047 | 0 | aAllSet.Put( SfxStringItem( SID_FONT_NAME, aFont->GetFamilyName() ) ); |
1048 | |
|
1049 | 0 | SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create(); |
1050 | 0 | auto xFrame = GetView().GetViewFrame().GetFrame().GetFrameInterface(); |
1051 | 0 | VclPtr<SfxAbstractDialog> pDlg(pFact->CreateCharMapDialog(GetView().GetFrameWeld(), aAllSet, xFrame)); |
1052 | 0 | pDlg->StartExecuteAsync( |
1053 | 0 | [pDlg] (sal_Int32 /*nResult*/)->void |
1054 | 0 | { |
1055 | 0 | pDlg->disposeOnce(); |
1056 | 0 | } |
1057 | 0 | ); |
1058 | 0 | return; |
1059 | 0 | } |
1060 | | |
1061 | 0 | if( aChars.isEmpty() ) |
1062 | 0 | return; |
1063 | | |
1064 | 0 | rSh.StartAllAction(); |
1065 | | |
1066 | | // Delete selected content. |
1067 | 0 | SwRewriter aRewriter; |
1068 | 0 | aRewriter.AddRule(UndoArg1, SwResId(STR_SPECIALCHAR)); |
1069 | |
|
1070 | 0 | rSh.StartUndo( SwUndoId::INSERT, &aRewriter ); |
1071 | 0 | if ( rSh.HasSelection() ) |
1072 | 0 | { |
1073 | 0 | rSh.DelRight(); |
1074 | 0 | aSet.ClearItem(); |
1075 | 0 | rSh.GetCurAttr( aSet ); |
1076 | |
|
1077 | 0 | SvxScriptSetItem aSetItem( SID_ATTR_CHAR_FONT, *aSet.GetPool() ); |
1078 | 0 | aSetItem.GetItemSet().Put( aSet, false ); |
1079 | 0 | const SfxPoolItem* pI = aSetItem.GetItemOfScript( nScript ); |
1080 | 0 | if( pI ) |
1081 | 0 | { |
1082 | 0 | aFont.reset(static_cast<SvxFontItem*>(pI->Clone())); |
1083 | 0 | } |
1084 | 0 | else |
1085 | 0 | { |
1086 | 0 | TypedWhichId<SvxFontItem> nFontWhich = |
1087 | 0 | GetWhichOfScript( |
1088 | 0 | RES_CHRATR_FONT, |
1089 | 0 | SvtLanguageOptions::GetI18NScriptTypeOfLanguage( GetAppLanguage() ) ); |
1090 | 0 | aFont.reset(aSet.Get( nFontWhich ).Clone()); |
1091 | 0 | } |
1092 | 0 | } |
1093 | | |
1094 | | // Insert character. |
1095 | 0 | rSh.Insert( aChars ); |
1096 | | |
1097 | | // #108876# a font attribute has to be set always due to a guessed script type |
1098 | 0 | if( !aNewFont.GetFamilyName().isEmpty() ) |
1099 | 0 | { |
1100 | 0 | std::unique_ptr<SvxFontItem> aNewFontItem(aFont->Clone()); |
1101 | 0 | aNewFontItem->SetFamilyName( aNewFont.GetFamilyName() ); |
1102 | 0 | aNewFontItem->SetFamily( aNewFont.GetFamilyTypeMaybeAskConfig()); |
1103 | 0 | aNewFontItem->SetPitch( aNewFont.GetPitchMaybeAskConfig()); |
1104 | 0 | aNewFontItem->SetCharSet( aNewFont.GetCharSet() ); |
1105 | |
|
1106 | 0 | SfxItemSet aRestoreSet(SfxItemSet::makeFixedSfxItemSet< |
1107 | 0 | RES_CHRATR_FONT, RES_CHRATR_FONT, |
1108 | 0 | RES_CHRATR_CJK_FONT, RES_CHRATR_CJK_FONT, |
1109 | 0 | RES_CHRATR_CTL_FONT, RES_CHRATR_CTL_FONT>(GetPool())); |
1110 | |
|
1111 | 0 | nScript = g_pBreakIt->GetAllScriptsOfText( aChars ); |
1112 | 0 | if( SvtScriptType::LATIN & nScript ) |
1113 | 0 | { |
1114 | 0 | aRestoreSet.Put( aSet.Get( RES_CHRATR_FONT ) ); |
1115 | 0 | aNewFontItem->SetWhich(RES_CHRATR_FONT); |
1116 | 0 | aSet.Put( *aNewFontItem ); |
1117 | 0 | } |
1118 | 0 | if( SvtScriptType::ASIAN & nScript ) |
1119 | 0 | { |
1120 | 0 | aRestoreSet.Put( aSet.Get( RES_CHRATR_CJK_FONT ) ); |
1121 | 0 | aNewFontItem->SetWhich(RES_CHRATR_CJK_FONT); |
1122 | 0 | aSet.Put( *aNewFontItem ); |
1123 | 0 | } |
1124 | 0 | if( SvtScriptType::COMPLEX & nScript ) |
1125 | 0 | { |
1126 | 0 | aRestoreSet.Put( aSet.Get( RES_CHRATR_CTL_FONT ) ); |
1127 | 0 | aNewFontItem->SetWhich(RES_CHRATR_CTL_FONT); |
1128 | 0 | aSet.Put( *aNewFontItem ); |
1129 | 0 | } |
1130 | |
|
1131 | 0 | rSh.SetMark(); |
1132 | 0 | rSh.ExtendSelection( false, aChars.getLength() ); |
1133 | 0 | rSh.SetAttrSet( aSet, SetAttrMode::DONTEXPAND | SetAttrMode::NOFORMATATTR ); |
1134 | 0 | if( !rSh.IsCursorPtAtEnd() ) |
1135 | 0 | rSh.SwapPam(); |
1136 | |
|
1137 | 0 | rSh.ClearMark(); |
1138 | | |
1139 | | // #i75891# |
1140 | | // SETATTR_DONTEXPAND does not work if there are already hard attributes. |
1141 | | // Therefore we have to restore the font attributes. |
1142 | 0 | rSh.SetMark(); |
1143 | 0 | rSh.SetAttrSet( aRestoreSet ); |
1144 | 0 | rSh.ClearMark(); |
1145 | |
|
1146 | 0 | rSh.UpdateAttr(); |
1147 | | |
1148 | | // Why was this done? aFont is not used anymore below, we are not |
1149 | | // in a loop and it's a local variable...? |
1150 | | // aFont = aNewFontItem; |
1151 | 0 | } |
1152 | |
|
1153 | 0 | rSh.EndAllAction(); |
1154 | 0 | rSh.EndUndo(); |
1155 | |
|
1156 | 0 | if ( !aChars.isEmpty() ) |
1157 | 0 | { |
1158 | 0 | rReq.AppendItem( SfxStringItem( SID_CHARMAP, aChars ) ); |
1159 | 0 | rReq.AppendItem( SfxStringItem( SID_ATTR_SPECIALCHAR, aNewFont.GetFamilyName() ) ); |
1160 | 0 | rReq.Done(); |
1161 | 0 | } |
1162 | 0 | } |
1163 | | |
1164 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |