| 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 <comphelper/propertyvalue.hxx> |
| 13 |
|
| 14 |
#include <com/sun/star/text/TextContentAnchorType.hpp> |
| 15 |
|
| 16 |
#include <docsh.hxx> |
| 17 |
#include <wrtsh.hxx> |
| 18 |
#include <frmmgr.hxx> |
| 19 |
#include <itabenum.hxx> |
| 20 |
|
| 21 |
/// Covers sw/source/uibase/frmdlg/ fixes. |
| 22 |
class SwUibaseFrmdlgTest : public SwModelTestBase |
| 23 |
{ |
| 24 |
public: |
| 25 |
SwUibaseFrmdlgTest() |
| 26 |
: SwModelTestBase(u"/sw/qa/uibase/frmdlg/data/"_ustr) |
| 27 |
{ |
| 28 |
} |
| 29 |
}; |
| 30 |
|
| 31 |
CPPUNIT_TEST_FIXTURE(SwUibaseFrmdlgTest, testWrappedMathObject) |
| 32 |
{ |
| 33 |
// The document includes a Math object with explicit wrapping. |
| 34 |
createSwDoc("wrapped-math-object.docx"); |
| 35 |
uno::Reference<drawing::XShape> xMath = getShape(1); |
| 36 |
|
| 37 |
// Without the accompanying fix in place, this test would have failed with: |
| 38 |
// - Expected: 4 (AT_CHARACTER) |
| 39 |
// - Actual : 1 (AS_CHARACTER) |
| 40 |
// i.e. the object lost its wrapping, leading to an incorrect position. |
| 41 |
CPPUNIT_ASSERT_EQUAL(text::TextContentAnchorType_AT_CHARACTER, |
| 42 |
getProperty<text::TextContentAnchorType>(getShape(1), u"AnchorType"_ustr)); |
| 43 |
} |
| 44 |
|
| 45 |
CPPUNIT_TEST_FIXTURE(SwUibaseFrmdlgTest, testAnchorTypeFromStyle) |
| 46 |
{ |
| 47 |
// Given a document with aGraphics style with anchor type set to as-character: |
| 48 |
createSwDoc(); |
| 49 |
uno::Reference<beans::XPropertySet> xGraphics( |
| 50 |
getStyles(u"FrameStyles"_ustr)->getByName(u"Graphics"_ustr), uno::UNO_QUERY); |
| 51 |
xGraphics->setPropertyValue(u"AnchorType"_ustr, |
| 52 |
uno::Any(text::TextContentAnchorType_AS_CHARACTER)); |
| 53 |
|
| 54 |
// When inserting an image: |
| 55 |
uno::Sequence<beans::PropertyValue> aArgs = { |
| 56 |
comphelper::makePropertyValue(u"FileName"_ustr, createFileURL(u"image.png")), |
| 57 |
}; |
| 58 |
dispatchCommand(mxComponent, u".uno:InsertGraphic"_ustr, aArgs); |
| 59 |
|
| 60 |
// Then make sure the image's anchor type is as-char: |
| 61 |
auto eActual = getProperty<text::TextContentAnchorType>(getShape(1), u"AnchorType"_ustr); |
| 62 |
// Without the accompanying fix in place, this test would have failed with: |
| 63 |
// - Expected: 1 (AS_CHARACTER) |
| 64 |
// - Actual : 4 (AT_CHARACTER) |
| 65 |
// i.e. the anchor type from the style was ignored. |
| 66 |
CPPUNIT_ASSERT_EQUAL(text::TextContentAnchorType_AS_CHARACTER, eActual); |
| 67 |
} |
| 68 |
|
| 69 |
CPPUNIT_TEST_FIXTURE(SwUibaseFrmdlgTest, testInsertFrameWidth) |
| 70 |
{ |
| 71 |
// Given a document with an inline table, its width is set to 6000 twips: |
| 72 |
createSwDoc(); |
| 73 |
// Insert a table: |
| 74 |
SwWrtShell* pWrtShell = getSwDocShell()->GetWrtShell(); |
| 75 |
SwInsertTableOptions aTableOptions(SwInsertTableFlags::DefaultBorder, 0); |
| 76 |
pWrtShell->InsertTable(aTableOptions, /*nRows=*/1, /*nCols=*/1); |
| 77 |
pWrtShell->MoveTable(GotoPrevTable, fnTableStart); |
| 78 |
SwTwips nExpectedWidth = 6000; |
| 79 |
{ |
| 80 |
SfxItemSetFixed<RES_FRMATR_BEGIN, RES_FRMATR_END - 1> aSet(pWrtShell->GetAttrPool()); |
| 81 |
SwFormatFrameSize aSize(SwFrameSize::Variable, nExpectedWidth); |
| 82 |
aSet.Put(aSize); |
| 83 |
pWrtShell->SetTableAttr(aSet); |
| 84 |
} |
| 85 |
pWrtShell->GoPrevCell(); |
| 86 |
pWrtShell->Insert(u"A1"_ustr); |
| 87 |
SwFormatFrameSize aRowSize(SwFrameSize::Minimum); |
| 88 |
pWrtShell->SetRowHeight(aRowSize); |
| 89 |
pWrtShell->GoNextCell(); |
| 90 |
pWrtShell->Insert(u"A2"_ustr); |
| 91 |
pWrtShell->SetRowHeight(aRowSize); |
| 92 |
// Select cell: |
| 93 |
pWrtShell->SelAll(); |
| 94 |
// Select table: |
| 95 |
pWrtShell->SelAll(); |
| 96 |
|
| 97 |
// When converting that table to a floating table: |
| 98 |
SwFlyFrameAttrMgr aMgr(/*bNew=*/true, pWrtShell, Frmmgr_Type::TEXT, nullptr); |
| 99 |
|
| 100 |
// Then make sure that the fly width will be based on the table width: |
| 101 |
const SwFormatFrameSize* pFrameSize = aMgr.GetAttrSet().GetItem(RES_FRM_SIZE); |
| 102 |
// Without the accompanying fix in place, this test would have failed with: |
| 103 |
// - Expected: 6000 (nExpectedWidth) |
| 104 |
// - Actual : 1134 (2cm) |
| 105 |
// i.e. the fly width was the default, not inherited from the selected table. |
| 106 |
CPPUNIT_ASSERT_EQUAL(nExpectedWidth, pFrameSize->GetWidth()); |
| 107 |
} |
| 108 |
|
| 109 |
CPPUNIT_PLUGIN_IMPLEMENT(); |
| 110 |
|
| 111 |
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |