Debian Codegraph @

sw/qa/uibase/uiview/uiview.cxx

raw
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
10 #include <swmodeltestbase.hxx>
11
12 #include <LibreOfficeKit/LibreOfficeKitEnums.h>
13 #include <comphelper/processfactory.hxx>
14 #include <osl/file.hxx>
15 #include <comphelper/propertyvalue.hxx>
16 #include <comphelper/scopeguard.hxx>
17 #include <vcl/scheduler.hxx>
18 #include <sfx2/viewfrm.hxx>
19 #include <sfx2/dispatch.hxx>
20 #include <sfx2/lokhelper.hxx>
21 #include <test/lokcallback.hxx>
22 #include <comphelper/string.hxx>
23
24 #include <com/sun/star/frame/XLayoutManager.hpp>
25 #include <com/sun/star/frame/XDispatchHelper.hpp>
26 #include <com/sun/star/frame/XDispatchProvider.hpp>
27 #include <com/sun/star/frame/XComponentLoader.hpp>
28 #include <com/sun/star/frame/XStorable2.hpp>
29 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
30 #include <com/sun/star/packages/zip/ZipFileAccess.hpp>
31 #include <com/sun/star/view/XSelectionSupplier.hpp>
32 #include <com/sun/star/text/XParagraphCursor.hpp>
33
34 #include <cmdid.h>
35 #include <unotxdoc.hxx>
36 #include <docsh.hxx>
37 #include <wrtsh.hxx>
38 #include <swmodule.hxx>
39 #include <view.hxx>
40 #include <IDocumentRedlineAccess.hxx>
41
42 /// Covers sw/source/uibase/uiview/ fixes.
43 class SwUibaseUiviewTest : public SwModelTestBase
44 {
45 public:
46 SwUibaseUiviewTest()
47 : SwModelTestBase(u"/sw/qa/uibase/uiview/data/"_ustr)
48 {
49 }
50 };
51
52 CPPUNIT_TEST_FIXTURE(SwUibaseUiviewTest, testUpdateAllObjectReplacements)
53 {
54 // Make a temporary copy of the test document
55 createTempCopy(u"updateall-objectreplacements.odt");
56
57 /* BASIC code that exhibits the problem:
58
59 desktop = CreateUnoService("com.sun.star.frame.Desktop")
60 Dim props(0) as new com.sun.star.beans.PropertyValue
61 props(0).Name = "Hidden"
62 props(0).Value = true
63 component = desktop.loadComponentFromURL("file://.../test.odt", "_default", 0, props)
64 Wait 1000 ' workaround
65 dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")
66 frame = component.CurrentController.Frame
67 dispatcher.executeDispatch(frame, ".uno:UpdateAll", "", 0, Array())
68 component.storeSelf(Array())
69 component.dispose()
70 */
71
72 uno::Reference<lang::XMultiServiceFactory> xFactory(comphelper::getProcessServiceFactory());
73
74 // Load the copy
75 uno::Reference<uno::XInterface> xInterface
76 = xFactory->createInstance(u"com.sun.star.frame.Desktop"_ustr);
77 uno::Reference<frame::XComponentLoader> xComponentLoader(xInterface, uno::UNO_QUERY);
78 uno::Sequence<beans::PropertyValue> aLoadArgs{ comphelper::makePropertyValue(u"Hidden"_ustr,
79 true) };
80 mxComponent = xComponentLoader->loadComponentFromURL(maTempFile.GetURL(), u"_default"_ustr, 0,
81 aLoadArgs);
82
83 // Perform the .uno:UpdateAll call and save
84 xInterface = xFactory->createInstance(u"com.sun.star.frame.DispatchHelper"_ustr);
85 uno::Reference<frame::XDispatchHelper> xDispatchHelper(xInterface, uno::UNO_QUERY);
86 uno::Reference<frame::XModel> xModel(mxComponent, uno::UNO_QUERY);
87 uno::Reference<frame::XDispatchProvider> xDispatchProvider(
88 xModel->getCurrentController()->getFrame(), uno::UNO_QUERY);
89 uno::Sequence<beans::PropertyValue> aNoArgs;
90 xDispatchHelper->executeDispatch(xDispatchProvider, u".uno:UpdateAll"_ustr, OUString(), 0,
91 aNoArgs);
92 uno::Reference<frame::XStorable2> xStorable(mxComponent, uno::UNO_QUERY);
93 xStorable->storeSelf(aNoArgs);
94
95 // Check the contents of the updated copy and verify that ObjectReplacements are there
96 uno::Reference<packages::zip::XZipFileAccess2> xNameAccess
97 = packages::zip::ZipFileAccess::createWithURL(comphelper::getComponentContext(xFactory),
98 maTempFile.GetURL());
99
100 CPPUNIT_ASSERT(xNameAccess->hasByName(u"ObjectReplacements/Components"_ustr));
101 CPPUNIT_ASSERT(xNameAccess->hasByName(u"ObjectReplacements/Components_1"_ustr));
102 }
103
104 CPPUNIT_TEST_FIXTURE(SwUibaseUiviewTest, testUpdateReplacementNosetting)
105 {
106 // Load a copy of the document in hidden mode.
107 OUString aSourceURL = createFileURL(u"update-replacement-nosetting.odt");
108 CPPUNIT_ASSERT_EQUAL(osl::FileBase::E_None, osl::File::copy(aSourceURL, maTempFile.GetURL()));
109 loadWithParams(maTempFile.GetURL(), { comphelper::makePropertyValue(u"Hidden"_ustr, true) });
110
111 // Update "everything" (including object replacements) and save it.
112 dispatchCommand(mxComponent, u".uno:UpdateAll"_ustr, {});
113 uno::Reference<frame::XStorable2> xStorable(mxComponent, uno::UNO_QUERY);
114 xStorable->storeSelf({});
115
116 // Check the contents of the updated copy.
117 uno::Reference<uno::XComponentContext> xContext = comphelper::getProcessComponentContext();
118 uno::Reference<packages::zip::XZipFileAccess2> xNameAccess
119 = packages::zip::ZipFileAccess::createWithURL(xContext, maTempFile.GetURL());
120
121 // Without the accompanying fix in place, this test would have failed, because the embedded
122 // object replacement image was not generated.
123 CPPUNIT_ASSERT(xNameAccess->hasByName(u"ObjectReplacements/Components"_ustr));
124 }
125
126 CPPUNIT_TEST_FIXTURE(SwUibaseUiviewTest, testKeepRatio)
127 {
128 // Given a document with a custom KeepRatio:
129 createSwDoc("keep-ratio.fodt");
130
131 // Then make sure we read the custom value:
132 SwWrtShell* pWrtShell = getSwDocShell()->GetWrtShell();
133 const SwViewOption* pViewOption = pWrtShell->GetViewOptions();
134 comphelper::ScopeGuard g([pWrtShell, pViewOption] {
135 SwViewOption aViewOption(*pViewOption);
136 aViewOption.SetKeepRatio(false);
137 SwModule::get()->ApplyUsrPref(aViewOption, &pWrtShell->GetView());
138 });
139 // Without the accompanying fix in place, this test would have failed, because KeepRatio was not
140 // mapped to settings.xml
141 CPPUNIT_ASSERT(pViewOption->IsKeepRatio());
142
143 // Then export as well:
144 save(TestFilter::ODT);
145 xmlDocUniquePtr pXmlDoc = parseExport(u"settings.xml"_ustr);
146 assertXPathContent(pXmlDoc, "//config:config-item[@config:name='KeepRatio']", u"true");
147 }
148
149 namespace
150 {
151 /// Interception implementation that disables .uno:Zoom on Image1, but not on Image2.
152 struct ImageInterceptor : public cppu::WeakImplHelper<frame::XDispatchProviderInterceptor>
153 {
154 uno::Reference<view::XSelectionSupplier> m_xSelectionSupplier;
155 uno::Reference<frame::XDispatchProvider> m_xMaster;
156 uno::Reference<frame::XDispatchProvider> m_xSlave;
157 int m_nEnabled = 0;
158 int m_nDisabled = 0;
159
160 public:
161 ImageInterceptor(const uno::Reference<lang::XComponent>& xComponent);
162
163 // XDispatchProviderInterceptor
164 uno::Reference<frame::XDispatchProvider> SAL_CALL getMasterDispatchProvider() override;
165 uno::Reference<frame::XDispatchProvider> SAL_CALL getSlaveDispatchProvider() override;
166 void SAL_CALL setMasterDispatchProvider(
167 const uno::Reference<frame::XDispatchProvider>& xNewSupplier) override;
168 void SAL_CALL
169 setSlaveDispatchProvider(const uno::Reference<frame::XDispatchProvider>& xNewSupplier) override;
170
171 // XDispatchProvider
172 uno::Reference<frame::XDispatch> SAL_CALL queryDispatch(const util::URL& rURL,
173 const OUString& rTargetFrameName,
174 sal_Int32 SearchFlags) override;
175 uno::Sequence<uno::Reference<frame::XDispatch>> SAL_CALL
176 queryDispatches(const uno::Sequence<frame::DispatchDescriptor>& rRequests) override;
177 };
178 }
179
180 ImageInterceptor::ImageInterceptor(const uno::Reference<lang::XComponent>& xComponent)
181 {
182 uno::Reference<frame::XModel2> xModel(xComponent, uno::UNO_QUERY);
183 CPPUNIT_ASSERT(xModel.is());
184 m_xSelectionSupplier.set(xModel->getCurrentController(), uno::UNO_QUERY);
185 CPPUNIT_ASSERT(m_xSelectionSupplier.is());
186 }
187
188 uno::Reference<frame::XDispatchProvider> ImageInterceptor::getMasterDispatchProvider()
189 {
190 return m_xMaster;
191 }
192
193 uno::Reference<frame::XDispatchProvider> ImageInterceptor::getSlaveDispatchProvider()
194 {
195 return m_xSlave;
196 }
197
198 void ImageInterceptor::setMasterDispatchProvider(
199 const uno::Reference<frame::XDispatchProvider>& xNewSupplier)
200 {
201 m_xMaster = xNewSupplier;
202 }
203
204 void ImageInterceptor::setSlaveDispatchProvider(
205 const uno::Reference<frame::XDispatchProvider>& xNewSupplier)
206 {
207 m_xSlave = xNewSupplier;
208 }
209
210 uno::Reference<frame::XDispatch> ImageInterceptor::queryDispatch(const util::URL& rURL,
211 const OUString& rTargetFrameName,
212 sal_Int32 nSearchFlags)
213 {
214 // Disable the UNO command based on the currently selected image, i.e. this can't be cached when
215 // a different image is selected. Originally this was .uno:SetBorderStyle, but let's pick a
216 // command which is active when running cppunit tests:
217 if (rURL.Complete == ".uno:Zoom")
218 {
219 uno::Reference<container::XNamed> xImage;
220 m_xSelectionSupplier->getSelection() >>= xImage;
221 if (xImage.is() && xImage->getName() == "Image1")
222 {
223 ++m_nDisabled;
224 return {};
225 }
226
227 ++m_nEnabled;
228 }
229
230 return m_xSlave->queryDispatch(rURL, rTargetFrameName, nSearchFlags);
231 }
232
233 uno::Sequence<uno::Reference<frame::XDispatch>>
234 ImageInterceptor::queryDispatches(const uno::Sequence<frame::DispatchDescriptor>& /*rRequests*/)
235 {
236 return {};
237 }
238
239 CPPUNIT_TEST_FIXTURE(SwUibaseUiviewTest, testSwitchBetweenImages)
240 {
241 // Given a document with 2 images, and an interceptor catching an UNO command that specific to
242 // the current selection:
243 createSwDoc();
244 SwWrtShell* pWrtShell = getSwDocShell()->GetWrtShell();
245 uno::Reference<lang::XMultiServiceFactory> xMSF(mxComponent, uno::UNO_QUERY);
246 uno::Reference<text::XTextDocument> xTextDocument(mxComponent, uno::UNO_QUERY);
247 uno::Reference<text::XText> xText = xTextDocument->getText();
248 uno::Reference<text::XTextCursor> xCursor = xText->createTextCursor();
249 for (int i = 0; i < 2; ++i)
250 {
251 uno::Reference<beans::XPropertySet> xTextGraphic(
252 xMSF->createInstance(u"com.sun.star.text.TextGraphicObject"_ustr), uno::UNO_QUERY);
253 xTextGraphic->setPropertyValue(u"AnchorType"_ustr,
254 uno::Any(text::TextContentAnchorType_AS_CHARACTER));
255 xTextGraphic->setPropertyValue(u"Size"_ustr, uno::Any(awt::Size(5000, 5000)));
256 uno::Reference<text::XTextContent> xTextContent(xTextGraphic, uno::UNO_QUERY);
257 xText->insertTextContent(xCursor, xTextContent, false);
258 }
259 pWrtShell->SttEndDoc(/*bStt=*/false);
260 uno::Reference<frame::XModel> xModel(mxComponent, uno::UNO_QUERY);
261 uno::Reference<frame::XDispatchProviderInterception> xRegistration(
262 xModel->getCurrentController()->getFrame(), uno::UNO_QUERY);
263 rtl::Reference pInterceptor(new ImageInterceptor(mxComponent));
264
265 xRegistration->registerDispatchProviderInterceptor(pInterceptor);
266 pInterceptor->m_nEnabled = 0;
267 pInterceptor->m_nDisabled = 0;
268
269 // When selecting the first image:
270 selectShape(1);
271
272 // Then make sure the UNO command is disabled:
273 CPPUNIT_ASSERT_EQUAL(0, pInterceptor->m_nEnabled);
274 CPPUNIT_ASSERT_GREATEREQUAL(1, pInterceptor->m_nDisabled);
275
276 // Given a clean state:
277 pInterceptor->m_nEnabled = 0;
278 pInterceptor->m_nDisabled = 0;
279
280 // When selecting the second image:
281 selectShape(2);
282
283 // Then make sure the UNO command is enabled:
284 CPPUNIT_ASSERT_GREATEREQUAL(1, pInterceptor->m_nEnabled);
285 CPPUNIT_ASSERT_EQUAL(0, pInterceptor->m_nDisabled);
286
287 // Given a clean state:
288 pInterceptor->m_nEnabled = 0;
289 pInterceptor->m_nDisabled = 0;
290
291 // When selecting the first image, again (this time not changing the selection type):
292 selectShape(1);
293
294 // Then make sure the UNO command is disabled:
295 CPPUNIT_ASSERT_EQUAL(0, pInterceptor->m_nEnabled);
296 // Without the accompanying fix in place, this test would have failed with:
297 // - Expected greater or equal than: 1
298 // - Actual : 0
299 // i.e. selecting the first image didn't result in a disabled UNO command.
300 CPPUNIT_ASSERT_GREATEREQUAL(1, pInterceptor->m_nDisabled);
301 }
302
303 CPPUNIT_TEST_FIXTURE(SwUibaseUiviewTest, testPrintPreview)
304 {
305 // Given a normal Writer view, in half-destroyed state, similar to what
306 // SfxViewFrame::SwitchToViewShell_Impl() does in practice:
307 createSwDoc();
308 SwDocShell* pDocShell = getSwDocShell();
309 SwView* pView = pDocShell->GetView();
310 FmFormShell* pFormShell = pView->GetFormShell();
311 pView->SetFormShell(reinterpret_cast<FmFormShell*>(-1));
312 pView->SetDying();
313
314 // When selecting a shell, similar to what happens the doc size changes:
315 // Then make sure we don't crash:
316 pView->SelectShell();
317
318 // Restore the state and shut down.
319 pView->SetFormShell(pFormShell);
320 }
321
322 CPPUNIT_TEST_FIXTURE(SwUibaseUiviewTest, TestTdf152839_Formtext)
323 {
324 createSwDoc("tdf152839_formtext.rtf");
325
326 xmlDocUniquePtr pXmlDoc = parseLayoutDump();
327 sal_Int32 nHeight
328 = getXPath(pXmlDoc, "/root/page[1]/body/tab[1]/row[2]/cell[1]/txt/infos/bounds", "height")
329 .toInt32();
330 CPPUNIT_ASSERT_EQUAL(sal_Int32(723), nHeight);
331 }
332
333 CPPUNIT_TEST_FIXTURE(SwUibaseUiviewTest, testEditInReadonly)
334 {
335 createSwDoc("editinsection.odt");
336
337 SwDocShell* pDocShell = getSwDocShell();
338 SwView* pView = pDocShell->GetView();
339
340 pView->GetViewFrame().GetDispatcher()->Execute(SID_EDITDOC, SfxCallMode::SYNCHRON);
341
342 uno::Reference<frame::XModel> xModel(mxComponent, uno::UNO_QUERY);
343 uno::Reference<text::XTextDocument> xTextDocument(mxComponent, uno::UNO_QUERY);
344 uno::Reference<text::XParagraphCursor> xParaCursor(xTextDocument->getText()->createTextCursor(),
345 uno::UNO_QUERY);
346
347 uno::Reference<view::XSelectionSupplier> xSelSupplier(xModel->getCurrentController(),
348 uno::UNO_QUERY_THROW);
349
350 xSelSupplier->select(css::uno::Any(xParaCursor));
351 std::unique_ptr<SfxPoolItem> pItem;
352 SfxItemState eState = pView->GetViewFrame().GetBindings().QueryState(FN_INSERT_TABLE, pItem);
353 //status disabled in read only content
354 CPPUNIT_ASSERT_EQUAL(SfxItemState::DISABLED, eState);
355
356 //move cursor to section
357 xParaCursor->gotoNextParagraph(false);
358 xSelSupplier->select(css::uno::Any(xParaCursor));
359 eState = pView->GetViewFrame().GetBindings().QueryState(FN_INSERT_TABLE, pItem);
360 //status default in editable section
361 CPPUNIT_ASSERT_EQUAL(SfxItemState::DEFAULT, eState);
362 }
363
364 CPPUNIT_TEST_FIXTURE(SwUibaseUiviewTest, testShowTextobjectbarInReadonly)
365 {
366 createSwDoc("tdf146549.odt");
367
368 SwDocShell* pDocShell = getSwDocShell();
369 SwView* pView = pDocShell->GetView();
370
371 pView->GetViewFrame().GetDispatcher()->Execute(SID_EDITDOC, SfxCallMode::SYNCHRON);
372
373 uno::Reference<frame::XModel> xModel(mxComponent, uno::UNO_QUERY);
374 uno::Reference<text::XTextDocument> xTextDocument(mxComponent, uno::UNO_QUERY);
375 uno::Reference<text::XParagraphCursor> xParaCursor(xTextDocument->getText()->createTextCursor(),
376 uno::UNO_QUERY);
377
378 uno::Reference<view::XSelectionSupplier> xSelSupplier(xModel->getCurrentController(),
379 uno::UNO_QUERY_THROW);
380
381 SwWrtShell* pWrtShell = getSwDocShell()->GetWrtShell();
382 CPPUNIT_ASSERT(pWrtShell);
383
384 SfxViewFrame& rViewFrame = pWrtShell->GetView().GetViewFrame();
385 uno::Reference<com::sun::star::frame::XLayoutManager> xLayoutManager;
386 uno::Reference<beans::XPropertySet> xPropSet(rViewFrame.GetFrame().GetFrameInterface(),
387 uno::UNO_QUERY);
388 xLayoutManager.set(xPropSet->getPropertyValue(u"LayoutManager"_ustr), uno::UNO_QUERY);
389
390 // move the cursor to the non-editable section
391 xSelSupplier->select(css::uno::Any(xParaCursor));
392
393 bool bShow;
394 bShow = xLayoutManager->isElementVisible(u"private:resource/toolbar/drawtextobjectbar"_ustr);
395 CPPUNIT_ASSERT_EQUAL(false, bShow); // the formatting toolbar should be hidden
396
397 // move the cursor to the editable section
398 xParaCursor->gotoNextParagraph(false);
399 xSelSupplier->select(css::uno::Any(xParaCursor));
400
401 bShow = xLayoutManager->isElementVisible(u"private:resource/toolbar/drawtextobjectbar"_ustr);
402 CPPUNIT_ASSERT_EQUAL(true, bShow); // the formatting toolbar should be shown
403
404 // move the cursor to the non-editable section
405 xParaCursor->gotoPreviousParagraph(false);
406 xSelSupplier->select(css::uno::Any(xParaCursor));
407
408 bShow = xLayoutManager->isElementVisible(u"private:resource/toolbar/drawtextobjectbar"_ustr);
409 CPPUNIT_ASSERT_EQUAL(false, bShow); // the formatting toolbar should be hidden
410 }
411
412 CPPUNIT_TEST_FIXTURE(SwUibaseUiviewTest, testReinstateTrackedChangeState)
413 {
414 // Given a document with a deletion:
415 createSwDoc();
416 SwWrtShell* pWrtShell = getSwDocShell()->GetWrtShell();
417 pWrtShell->Insert("abcd");
418 RedlineFlags nMode = pWrtShell->GetRedlineFlags();
419 pWrtShell->SetRedlineFlags(nMode | RedlineFlags::On);
420 pWrtShell->Left(SwCursorSkipMode::Chars, /*bSelect=*/false, 1, /*bBasicCall=*/false);
421 pWrtShell->Left(SwCursorSkipMode::Chars, /*bSelect=*/true, 2, /*bBasicCall=*/false);
422 pWrtShell->DelRight();
423
424 // When the cursor is inside a redline:
425 pWrtShell->SttPara(/*bSelect=*/false);
426 pWrtShell->Right(SwCursorSkipMode::Chars, /*bSelect=*/false, 2, /*bBasicCall=*/false);
427
428 // Then make sure that reinstate is enabled:
429 SwView* pView = getSwDocShell()->GetView();
430 std::unique_ptr<SfxPoolItem> pItem;
431 SfxItemState eState
432 = pView->GetViewFrame().GetBindings().QueryState(FN_REDLINE_REINSTATE_DIRECT, pItem);
433 CPPUNIT_ASSERT_EQUAL(SfxItemState::DEFAULT, eState);
434
435 // When the cursor is outside a redline:
436 pWrtShell->SttPara(/*bSelect=*/false);
437
438 // Then make sure that reinstate is disabled:
439 eState = pView->GetViewFrame().GetBindings().QueryState(FN_REDLINE_REINSTATE_DIRECT, pItem);
440 // Without the accompanying fix in place, this test would have failed with:
441 // - Expected: 1 (DISABLED)
442 // - Actual : 32 (DEFAULT)
443 // i.e. reinstate was always enabled.
444 CPPUNIT_ASSERT_EQUAL(SfxItemState::DISABLED, eState);
445 }
446
447 CPPUNIT_TEST_FIXTURE(SwUibaseUiviewTest, testRedlineRenderModeCommand)
448 {
449 // Given a document with default view options:
450 createSwDoc();
451 SwWrtShell* pWrtShell = getSwDocShell()->GetWrtShell();
452 SwRedlineRenderMode eActual = pWrtShell->GetViewOptions()->GetRedlineRenderMode();
453 CPPUNIT_ASSERT_EQUAL(SwRedlineRenderMode::Standard, eActual);
454
455 // When toggling redline render mode to omit deletes:
456 dispatchCommand(mxComponent, u".uno:RedlineRenderMode"_ustr, {});
457
458 // Then make sure the view option is updated:
459 eActual = pWrtShell->GetViewOptions()->GetRedlineRenderMode();
460 // Without the accompanying fix in place, this test would have failed with:
461 // - Expected: 2 (OmitDeletes)
462 // - Actual : 0 (Standard)
463 // i.e. the view option wasn't set.
464 CPPUNIT_ASSERT_EQUAL(SwRedlineRenderMode::OmitDeletes, eActual);
465
466 // And when toggling off:
467 dispatchCommand(mxComponent, u".uno:RedlineRenderMode"_ustr, {});
468
469 // Then make sure the view option is back to its default:
470 eActual = pWrtShell->GetViewOptions()->GetRedlineRenderMode();
471 CPPUNIT_ASSERT_EQUAL(SwRedlineRenderMode::Standard, eActual);
472 }
473
474 namespace
475 {
476 /// LOK view callback for test purposes.
477 struct ViewCallback
478 {
479 std::set<SwRedlineRenderMode> m_aInvalidationModes;
480
481 static void callback(int nType, const char* pPayload, void* pData);
482 void callbackImpl(int nType, const char* pPayload);
483 };
484
485 void ViewCallback::callback(int nType, const char* pPayload, void* pData)
486 {
487 static_cast<ViewCallback*>(pData)->callbackImpl(nType, pPayload);
488 }
489
490 void ViewCallback::callbackImpl(int nType, const char* pPayload)
491 {
492 switch (nType)
493 {
494 case LOK_CALLBACK_INVALIDATE_TILES:
495 {
496 OUString aPayload = OUString::fromUtf8(pPayload);
497 if (aPayload.startsWith("EMPTY"))
498 {
499 break;
500 }
501 uno::Sequence<OUString> aSeq = comphelper::string::convertCommaSeparated(aPayload);
502 // x y w h part mode
503 CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(6), aSeq.getLength());
504 m_aInvalidationModes.insert(static_cast<SwRedlineRenderMode>(aSeq[5].toInt32()));
505 }
506 break;
507 }
508 }
509 }
510
511 CPPUNIT_TEST_FIXTURE(SwUibaseUiviewTest, testRedlineRenderModeInvalidate)
512 {
513 // Set up LOK:
514 comphelper::LibreOfficeKit::setActive(true);
515 comphelper::LibreOfficeKit::setPartInInvalidation(true);
516
517 // Given a document where redline render mode is set to "omit deletes":
518 createSwDoc();
519 getSwTextDoc()->initializeForTiledRendering({});
520 SwDocShell* pDocShell = getSwDocShell();
521 SwWrtShell* pWrtShell = pDocShell->GetWrtShell();
522 ViewCallback aCallback;
523 TestLokCallbackWrapper aCallbackWrapper(&ViewCallback::callback, &aCallback);
524 pWrtShell->GetSfxViewShell()->setLibreOfficeKitViewCallback(&aCallbackWrapper);
525 aCallbackWrapper.setLOKViewId(SfxLokHelper::getView(*pWrtShell->GetSfxViewShell()));
526 SwViewOption aOpt(*pWrtShell->GetViewOptions());
527 aOpt.SetRedlineRenderMode(SwRedlineRenderMode::OmitDeletes);
528 pWrtShell->ApplyViewOptions(aOpt);
529 Scheduler::ProcessEventsToIdle();
530 aCallback.m_aInvalidationModes.clear();
531
532 // When typing a key:
533 pWrtShell->Insert(u"x"_ustr);
534 pWrtShell->GetSfxViewShell()->flushPendingLOKInvalidateTiles();
535
536 // Then make sure that both the "omit inserts" and the "omit deletes" modes are invalidated:
537 // Without the accompanying fix in place, this test would have failed, only the "omit deletes"
538 // mode was invalidated.
539 CPPUNIT_ASSERT(aCallback.m_aInvalidationModes.contains(SwRedlineRenderMode::OmitInserts));
540 CPPUNIT_ASSERT(aCallback.m_aInvalidationModes.contains(SwRedlineRenderMode::OmitDeletes));
541
542 // Tear down LOK:
543 pWrtShell->GetSfxViewShell()->setLibreOfficeKitViewCallback(nullptr);
544 mxComponent->dispose();
545 mxComponent.clear();
546 comphelper::LibreOfficeKit::setPartInInvalidation(false);
547 comphelper::LibreOfficeKit::setActive(false);
548 }
549
550 CPPUNIT_PLUGIN_IMPLEMENT();
551
552 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */