| 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 <vcl/transfer.hxx> |
| 13 |
#include <editeng/wghtitem.hxx> |
| 14 |
#include <editeng/postitem.hxx> |
| 15 |
#include <editeng/udlnitem.hxx> |
| 16 |
|
| 17 |
#include <docsh.hxx> |
| 18 |
#include <swdtflvr.hxx> |
| 19 |
#include <wrtsh.hxx> |
| 20 |
#include <view.hxx> |
| 21 |
#include <fmtanchr.hxx> |
| 22 |
|
| 23 |
/// Covers sw/source/uibase/dochdl/ fixes. |
| 24 |
class SwUibaseDochdlTest : public SwModelTestBase |
| 25 |
{ |
| 26 |
}; |
| 27 |
|
| 28 |
CPPUNIT_TEST_FIXTURE(SwUibaseDochdlTest, testSelectPasteFormat) |
| 29 |
{ |
| 30 |
// Create a new document and cut a character. |
| 31 |
createSwDoc(); |
| 32 |
SwDocShell* pDocShell = getSwDocShell(); |
| 33 |
SwWrtShell* pWrtShell = pDocShell->GetWrtShell(); |
| 34 |
pWrtShell->Insert2(u"x"_ustr); |
| 35 |
pWrtShell->Left(SwCursorSkipMode::Chars, /*bSelect=*/true, 1, /*bBasicCall=*/false); |
| 36 |
rtl::Reference<SwTransferable> pTransfer = new SwTransferable(*pWrtShell); |
| 37 |
pTransfer->Cut(); |
| 38 |
|
| 39 |
// Decide what format to use when doing a Writer->Writer paste and both RTF and ODF is an |
| 40 |
// available format. |
| 41 |
TransferableDataHelper aHelper(pTransfer); |
| 42 |
sal_uInt8 nAction = EXCHG_OUT_ACTION_INSERT_STRING; |
| 43 |
SotClipboardFormatId nFormat = SotClipboardFormatId::RICHTEXT; |
| 44 |
SwTransferable::SelectPasteFormat(aHelper, nAction, nFormat); |
| 45 |
|
| 46 |
CPPUNIT_ASSERT_EQUAL(EXCHG_OUT_ACTION_INSERT_OLE, nAction); |
| 47 |
// Without the accompanying fix in place, this test would have failed with: |
| 48 |
// - Expected: 85 (EMBED_SOURCE) |
| 49 |
// - Actual : 145 (RICHTEXT) |
| 50 |
// i.e. RTF was selected for Writer->Writer out of process copying, which is worse than ODF. |
| 51 |
CPPUNIT_ASSERT_EQUAL(SotClipboardFormatId::EMBED_SOURCE, nFormat); |
| 52 |
} |
| 53 |
|
| 54 |
CPPUNIT_TEST_FIXTURE(SwUibaseDochdlTest, testComplexSelection) |
| 55 |
{ |
| 56 |
// Given a document where a text node has hints, but no as-char images. |
| 57 |
createSwDoc(); |
| 58 |
SwDocShell* pDocShell = getSwDocShell(); |
| 59 |
SwWrtShell* pWrtShell = pDocShell->GetWrtShell(); |
| 60 |
pWrtShell->Insert2(u"abc"_ustr); |
| 61 |
pWrtShell->Left(SwCursorSkipMode::Chars, /*bSelect=*/false, 1, /*bBasicCall=*/false); |
| 62 |
pWrtShell->Left(SwCursorSkipMode::Chars, /*bSelect=*/true, 1, /*bBasicCall=*/false); |
| 63 |
SfxItemSet aSet(pWrtShell->GetView().GetPool(), |
| 64 |
svl::Items<RES_CHRATR_BEGIN, RES_CHRATR_END - 1>); |
| 65 |
// Bold, italic, underline. |
| 66 |
aSet.Put(SvxWeightItem(WEIGHT_BOLD, RES_CHRATR_WEIGHT)); |
| 67 |
aSet.Put(SvxPostureItem(ITALIC_NORMAL, RES_CHRATR_POSTURE)); |
| 68 |
aSet.Put(SvxUnderlineItem(LINESTYLE_SINGLE, RES_CHRATR_UNDERLINE)); |
| 69 |
pWrtShell->SetAttrSet(aSet); |
| 70 |
uno::Reference<datatransfer::XTransferable2> xTransfer = new SwTransferable(*pWrtShell); |
| 71 |
|
| 72 |
// When checking if the selection is complex, then there should be no crash. |
| 73 |
// Without the accompanying fix in place, this test would have crashed, because we read past the |
| 74 |
// end of the hints array. |
| 75 |
CPPUNIT_ASSERT(!xTransfer->isComplex()); |
| 76 |
} |
| 77 |
|
| 78 |
CPPUNIT_TEST_FIXTURE(SwUibaseDochdlTest, testComplexSelectionAtChar) |
| 79 |
{ |
| 80 |
// Given a document with an at-char anchored image: |
| 81 |
createSwDoc(); |
| 82 |
SwDoc* pDoc = getSwDoc(); |
| 83 |
SwDocShell* pDocShell = getSwDocShell(); |
| 84 |
SwWrtShell* pWrtShell = pDocShell->GetWrtShell(); |
| 85 |
SfxItemSet aFrameSet(pDoc->GetAttrPool(), svl::Items<RES_FRMATR_BEGIN, RES_FRMATR_END - 1>); |
| 86 |
SwFormatAnchor aAnchor(RndStdIds::FLY_AT_CHAR); |
| 87 |
aFrameSet.Put(aAnchor); |
| 88 |
Graphic aGrf; |
| 89 |
pWrtShell->SwFEShell::Insert(OUString(), OUString(), &aGrf, &aFrameSet); |
| 90 |
pWrtShell->UnSelectFrame(); |
| 91 |
|
| 92 |
// When checking if the selection is simple or complex: |
| 93 |
pWrtShell->SelAll(); |
| 94 |
uno::Reference<datatransfer::XTransferable2> xTransfer = new SwTransferable(*pWrtShell); |
| 95 |
bool bComplex = xTransfer->isComplex(); |
| 96 |
|
| 97 |
// Then make sure it's complex: |
| 98 |
// Without the accompanying fix in place, this test would have failed, a selection containing an |
| 99 |
// image was considered simple. |
| 100 |
CPPUNIT_ASSERT(bComplex); |
| 101 |
} |
| 102 |
|
| 103 |
CPPUNIT_PLUGIN_IMPLEMENT(); |
| 104 |
|
| 105 |
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |