sw/qa/extras/uiwriter/data/tdf161426.fodt |  197 ++++++++++++++++++++++++++++++
 sw/qa/extras/uiwriter/uiwriter6.cxx       |  155 +++++++++++++++++++++++
 sw/source/core/frmedt/feshview.cxx        |   26 +--
 3 files changed, 363 insertions(+), 15 deletions(-)

New commits:
commit e15a11679a3e0b4e67a0a27cd42f7fc5567e725f
Author:     László Németh <nem...@numbertext.org>
AuthorDate: Wed Jun 5 14:29:29 2024 +0200
Commit:     Michael Stahl <michael.st...@allotropia.de>
CommitDate: Thu Jun 6 10:46:00 2024 +0200

    tdf#161426 sw: fix selection in multicolumn floating table
    
    It was not possible to select text content of a cell, if
    one of the previous cells in the same row contains a cropped
    image hovering this cell, too.
    
    Follow-up to commit f3b899655018397e71300dbb32cdf4f82940a68b
    "tdf#160842 sw: select cell content instead of cropped part of image".
    
    Also clean-up to commit 2f7bb481c57458a38769ebd961f07cc45767f1f7
    "tdf#161332 sw: fix missing selection of floating table".
    
    Change-Id: Ib033f7238d9513c8ed18c472ce4afbd4d6ad1172
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/168475
    Reviewed-by: László Németh <nem...@numbertext.org>
    Tested-by: Jenkins
    (cherry picked from commit 886cbcd7627985692d4d2ad3197b1af08378d430)
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/168437
    Reviewed-by: Michael Stahl <michael.st...@allotropia.de>

diff --git a/sw/qa/extras/uiwriter/data/tdf161426.fodt 
b/sw/qa/extras/uiwriter/data/tdf161426.fodt
new file mode 100644
index 000000000000..473921880e39
--- /dev/null
+++ b/sw/qa/extras/uiwriter/data/tdf161426.fodt
@@ -0,0 +1,197 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<office:document xmlns:css3t="http://www.w3.org/TR/css3-text/"; 
xmlns:grddl="http://www.w3.org/2003/g/data-view#"; 
xmlns:xhtml="http://www.w3.org/1999/xhtml"; 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"; 
xmlns:xsd="http://www.w3.org/2001/XMLSchema"; 
xmlns:xforms="http://www.w3.org/2002/xforms"; 
xmlns:dom="http://www.w3.org/2001/xml-events"; 
xmlns:script="urn:oasis:names:tc:opendocument:xmlns:script:1.0" 
xmlns:form="urn:oasis:names:tc:opendocument:xmlns:form:1.0" 
xmlns:math="http://www.w3.org/1998/Math/MathML"; 
xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0" 
xmlns:ooo="http://openoffice.org/2004/office"; 
xmlns:fo="urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0" 
xmlns:config="urn:oasis:names:tc:opendocument:xmlns:config:1.0" 
xmlns:ooow="http://openoffice.org/2004/writer"; 
xmlns:xlink="http://www.w3.org/1999/xlink"; 
xmlns:drawooo="http://openoffice.org/2010/draw"; 
xmlns:oooc="http://openoffice.org/2004/calc"; 
xmlns:dc="http://purl.org/dc/elements/1.1/"; xmlns:c
 alcext="urn:org:documentfoundation:names:experimental:calc:xmlns:calcext:1.0" 
xmlns:style="urn:oasis:names:tc:opendocument:xmlns:style:1.0" 
xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0" 
xmlns:of="urn:oasis:names:tc:opendocument:xmlns:of:1.2" 
xmlns:tableooo="http://openoffice.org/2009/table"; 
xmlns:draw="urn:oasis:names:tc:opendocument:xmlns:drawing:1.0" 
xmlns:dr3d="urn:oasis:names:tc:opendocument:xmlns:dr3d:1.0" 
xmlns:rpt="http://openoffice.org/2005/report"; 
xmlns:formx="urn:openoffice:names:experimental:ooxml-odf-interop:xmlns:form:1.0"
 xmlns:svg="urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0" 
xmlns:chart="urn:oasis:names:tc:opendocument:xmlns:chart:1.0" 
xmlns:officeooo="http://openoffice.org/2009/office"; 
xmlns:table="urn:oasis:names:tc:opendocument:xmlns:table:1.0" 
xmlns:field="urn:openoffice:names:experimental:ooo-ms-interop:xmlns:field:1.0" 
xmlns:number="urn:oasis:names:tc:opendocument:xmlns:datastyle:1.0" 
xmlns:meta="urn:oasis:names:tc:opendocument:xmlns:
 meta:1.0" 
xmlns:loext="urn:org:documentfoundation:names:experimental:office:xmlns:loext:1.0"
 office:version="1.3" office:mimetype="application/vnd.oasis.opendocument.text">
+ 
<office:meta><dc:date>2024-06-05T12:36:26.032955294</dc:date><meta:editing-duration>PT4M18S</meta:editing-duration><meta:editing-cycles>2</meta:editing-cycles><meta:generator>LibreOfficeDev/24.8.0.0.alpha1$Linux_X86_64
 
LibreOffice_project/57c56b7b826c02868e48120432363fcb8f9e394a</meta:generator><meta:document-statistic
 meta:table-count="1" meta:image-count="1" meta:object-count="0" 
meta:page-count="1" meta:paragraph-count="2" meta:word-count="7" 
meta:character-count="52" 
meta:non-whitespace-character-count="45"/></office:meta>
+ <office:settings>
+  <config:config-item-set config:name="ooo:view-settings">
+   <config:config-item config:name="ViewAreaTop" 
config:type="long">226</config:config-item>
+   <config:config-item config:name="ViewAreaLeft" 
config:type="long">0</config:config-item>
+   <config:config-item config:name="ViewAreaWidth" 
config:type="long">35696</config:config-item>
+   <config:config-item config:name="ViewAreaHeight" 
config:type="long">20736</config:config-item>
+   <config:config-item config:name="ShowRedlineChanges" 
config:type="boolean">true</config:config-item>
+   <config:config-item config:name="InBrowseMode" 
config:type="boolean">false</config:config-item>
+   <config:config-item-map-indexed config:name="Views">
+    <config:config-item-map-entry>
+     <config:config-item config:name="ViewId" 
config:type="string">view2</config:config-item>
+     <config:config-item config:name="ViewLeft" 
config:type="long">18053</config:config-item>
+     <config:config-item config:name="ViewTop" 
config:type="long">2501</config:config-item>
+     <config:config-item config:name="VisibleLeft" 
config:type="long">0</config:config-item>
+     <config:config-item config:name="VisibleTop" 
config:type="long">226</config:config-item>
+     <config:config-item config:name="VisibleRight" 
config:type="long">35694</config:config-item>
+     <config:config-item config:name="VisibleBottom" 
config:type="long">20960</config:config-item>
+     <config:config-item config:name="ZoomType" 
config:type="short">0</config:config-item>
+     <config:config-item config:name="ViewLayoutColumns" 
config:type="short">1</config:config-item>
+     <config:config-item config:name="ViewLayoutBookMode" 
config:type="boolean">false</config:config-item>
+     <config:config-item config:name="ZoomFactor" 
config:type="short">110</config:config-item>
+     <config:config-item config:name="IsSelectedFrame" 
config:type="boolean">false</config:config-item>
+     <config:config-item config:name="KeepRatio" 
config:type="boolean">false</config:config-item>
+     <config:config-item config:name="AnchoredTextOverflowLegacy" 
config:type="boolean">false</config:config-item>
+     <config:config-item config:name="LegacySingleLineFontwork" 
config:type="boolean">false</config:config-item>
+     <config:config-item config:name="ConnectorUseSnapRect" 
config:type="boolean">false</config:config-item>
+     <config:config-item config:name="IgnoreBreakAfterMultilineField" 
config:type="boolean">false</config:config-item>
+    </config:config-item-map-entry>
+   </config:config-item-map-indexed>
+  </config:config-item-set>
+ </office:settings>
+ <office:scripts>
+  <office:script script:language="ooo:Basic">
+   <ooo:libraries xmlns:ooo="http://openoffice.org/2004/office"; 
xmlns:xlink="http://www.w3.org/1999/xlink"/>
+  </office:script>
+ </office:scripts>
+ <office:font-face-decls>
+  <style:font-face style:name="Linux Libertine G" svg:font-family="&apos;Linux 
Libertine G&apos;"/>
+  <style:font-face style:name="Noto Sans CJK SC" svg:font-family="&apos;Noto 
Sans CJK SC&apos;" style:font-family-generic="system" 
style:font-pitch="variable"/>
+  <style:font-face style:name="Noto Serif CJK SC" svg:font-family="&apos;Noto 
Serif CJK SC&apos;" style:font-family-generic="system" 
style:font-pitch="variable"/>
+ </office:font-face-decls>
+ <office:styles>
+  <style:default-style style:family="graphic">
+   <style:graphic-properties svg:stroke-color="#3465a4" 
draw:fill-color="#729fcf" fo:wrap-option="no-wrap" draw:shadow-offset-x="0.3cm" 
draw:shadow-offset-y="0.3cm" draw:start-line-spacing-horizontal="0.283cm" 
draw:start-line-spacing-vertical="0.283cm" 
draw:end-line-spacing-horizontal="0.283cm" 
draw:end-line-spacing-vertical="0.283cm" style:flow-with-text="false"/>
+   <style:paragraph-properties style:text-autospace="ideograph-alpha" 
style:line-break="strict" loext:tab-stop-distance="0cm" 
style:writing-mode="lr-tb" style:font-independent-line-spacing="false">
+    <style:tab-stops/>
+   </style:paragraph-properties>
+   <style:text-properties style:use-window-font-color="true" 
loext:opacity="0%" style:font-name="Linux Libertine G" fo:font-size="12pt" 
fo:language="hu" fo:country="HU" style:letter-kerning="true"/>
+  </style:default-style>
+  <style:default-style style:family="paragraph">
+   <style:paragraph-properties fo:hyphenation-ladder-count="no-limit" 
fo:hyphenation-keep="auto" loext:hyphenation-keep-type="column" 
style:text-autospace="ideograph-alpha" style:punctuation-wrap="hanging" 
style:line-break="strict" style:tab-stop-distance="1.251cm" 
style:writing-mode="page"/>
+   <style:text-properties style:use-window-font-color="true" 
loext:opacity="0%" style:font-name="Linux Libertine G" fo:font-size="12pt" 
fo:language="hu" fo:country="HU" style:letter-kerning="true" 
fo:hyphenate="false" fo:hyphenation-remain-char-count="2" 
fo:hyphenation-push-char-count="2" loext:hyphenation-no-caps="false" 
loext:hyphenation-no-last-word="false" loext:hyphenation-word-char-count="5" 
loext:hyphenation-zone="no-limit"/>
+  </style:default-style>
+  <style:default-style style:family="table">
+   <style:table-properties table:border-model="collapsing"/>
+  </style:default-style>
+  <style:default-style style:family="table-row">
+   <style:table-row-properties fo:keep-together="auto"/>
+  </style:default-style>
+  <style:style style:name="Standard" style:family="paragraph" 
style:class="text"/>
+  <style:style style:name="Heading" style:family="paragraph" 
style:parent-style-name="Standard" style:next-style-name="Text_20_body" 
style:class="text">
+   <style:paragraph-properties fo:margin-top="0.423cm" 
fo:margin-bottom="0.212cm" style:contextual-spacing="false" 
fo:keep-with-next="always"/>
+   <style:text-properties style:font-name="Linux Libertine G" 
fo:font-family="&apos;Linux Libertine G&apos;" fo:font-size="14pt"/>
+  </style:style>
+  <style:style style:name="Text_20_body" style:display-name="Text body" 
style:family="paragraph" style:parent-style-name="Standard" style:class="text">
+   <style:paragraph-properties fo:margin-top="0cm" fo:margin-bottom="0.247cm" 
style:contextual-spacing="false" fo:line-height="115%"/>
+  </style:style>
+  <style:style style:name="List" style:family="paragraph" 
style:parent-style-name="Text_20_body" style:class="list">
+   <style:text-properties style:font-name="Linux Libertine G" 
fo:font-family="&apos;Linux Libertine G&apos;"/>
+  </style:style>
+  <style:style style:name="Caption" style:family="paragraph" 
style:parent-style-name="Standard" style:class="extra">
+   <style:paragraph-properties fo:margin-top="0.212cm" 
fo:margin-bottom="0.212cm" style:contextual-spacing="false" 
text:number-lines="false" text:line-number="0"/>
+   <style:text-properties style:font-name="Linux Libertine G" 
fo:font-family="&apos;Linux Libertine G&apos;" fo:font-size="12pt" 
fo:font-style="italic"/>
+  </style:style>
+  <style:style style:name="Index" style:family="paragraph" 
style:parent-style-name="Standard" style:class="index">
+   <style:paragraph-properties text:number-lines="false" text:line-number="0"/>
+   <style:text-properties style:font-name="Linux Libertine G" 
fo:font-family="&apos;Linux Libertine G&apos;"/>
+  </style:style>
+  <style:style style:name="Frame_20_contents" style:display-name="Frame 
contents" style:family="paragraph" style:parent-style-name="Standard" 
style:class="extra"/>
+  <style:style style:name="Table_20_Contents" style:display-name="Table 
Contents" style:family="paragraph" style:parent-style-name="Standard" 
style:class="extra">
+   <style:paragraph-properties fo:orphans="0" fo:widows="0" 
text:number-lines="false" text:line-number="0"/>
+  </style:style>
+  <style:style style:name="Table_20_Heading" style:display-name="Table 
Heading" style:family="paragraph" style:parent-style-name="Table_20_Contents" 
style:class="extra">
+   <style:paragraph-properties fo:text-align="center" 
style:justify-single-word="false" text:number-lines="false" 
text:line-number="0"/>
+   <style:text-properties fo:font-weight="bold"/>
+  </style:style>
+  <style:style style:name="Graphics" style:family="graphic">
+   <style:graphic-properties text:anchor-type="paragraph" svg:x="0cm" 
svg:y="0cm" style:wrap="dynamic" style:number-wrapped-paragraphs="no-limit" 
style:wrap-contour="false" style:vertical-pos="top" 
style:vertical-rel="paragraph" style:horizontal-pos="center" 
style:horizontal-rel="paragraph" fo:background-color="transparent" 
draw:fill="none" draw:fill-color="#729fcf"/>
+  </style:style>
+  <style:style style:name="Frame" style:family="graphic">
+   <style:graphic-properties text:anchor-type="paragraph" svg:x="0cm" 
svg:y="0cm" fo:margin-left="0.201cm" fo:margin-right="0.201cm" 
fo:margin-top="0.201cm" fo:margin-bottom="0.201cm" style:wrap="parallel" 
style:number-wrapped-paragraphs="no-limit" style:wrap-contour="false" 
style:vertical-pos="top" style:vertical-rel="paragraph-content" 
style:horizontal-pos="center" style:horizontal-rel="paragraph-content" 
fo:background-color="transparent" draw:fill="none" draw:fill-color="#729fcf" 
fo:padding="0.15cm" fo:border="0.06pt solid #000000"/>
+  </style:style>
+ </office:styles>
+ <office:automatic-styles>
+  <style:style style:name="Table1" style:family="table">
+   <style:table-properties style:width="8.707cm" table:align="margins" 
style:writing-mode="lr-tb"/>
+  </style:style>
+  <style:style style:name="Table1.A" style:family="table-column">
+   <style:table-column-properties style:column-width="4.353cm" 
style:rel-column-width="32768*"/>
+  </style:style>
+  <style:style style:name="Table1.B" style:family="table-column">
+   <style:table-column-properties style:column-width="4.353cm" 
style:rel-column-width="32767*"/>
+  </style:style>
+  <style:style style:name="Table1.1" style:family="table-row">
+   <style:table-row-properties style:row-height="6.897cm" 
fo:keep-together="always"/>
+  </style:style>
+  <style:style style:name="Table1.A1" style:family="table-cell">
+   <style:table-cell-properties style:vertical-align="top" fo:padding="0cm" 
fo:border="0.05pt solid #000000" style:writing-mode="lr-tb"/>
+  </style:style>
+  <style:style style:name="Table1.B1" style:family="table-cell">
+   <style:table-cell-properties style:vertical-align="top" fo:padding="0cm" 
fo:border="none" style:writing-mode="lr-tb"/>
+  </style:style>
+  <style:style style:name="Table1.2" style:family="table-row">
+   <style:table-row-properties style:min-row-height="0.109cm" 
fo:keep-together="always"/>
+  </style:style>
+  <style:style style:name="Table1" style:family="table">
+   <style:table-properties style:width="8.707cm" table:align="margins" 
style:writing-mode="lr-tb"/>
+  </style:style>
+  <style:style style:name="Table1.A" style:family="table-column">
+   <style:table-column-properties style:column-width="4.353cm" 
style:rel-column-width="32768*"/>
+  </style:style>
+  <style:style style:name="Table1.B" style:family="table-column">
+   <style:table-column-properties style:column-width="4.353cm" 
style:rel-column-width="32767*"/>
+  </style:style>
+  <style:style style:name="Table1.1" style:family="table-row">
+   <style:table-row-properties style:row-height="6.897cm" 
fo:keep-together="always"/>
+  </style:style>
+  <style:style style:name="Table1.A1" style:family="table-cell">
+   <style:table-cell-properties style:vertical-align="top" fo:padding="0cm" 
fo:border="0.05pt solid #000000" style:writing-mode="lr-tb"/>
+  </style:style>
+  <style:style style:name="Table1.B1" style:family="table-cell">
+   <style:table-cell-properties style:vertical-align="top" fo:padding="0cm" 
fo:border="none" style:writing-mode="lr-tb"/>
+  </style:style>
+  <style:style style:name="Table1.2" style:family="table-row">
+   <style:table-row-properties style:min-row-height="0.109cm" 
fo:keep-together="always"/>
+  </style:style>
+  <style:style style:name="P1" style:family="paragraph" 
style:parent-style-name="Standard">
+   <style:paragraph-properties style:writing-mode="lr-tb"/>
+  </style:style>
+  <style:style style:name="fr1" style:family="graphic" 
style:parent-style-name="Frame">
+   <style:graphic-properties fo:margin-left="0cm" fo:margin-right="0cm" 
fo:margin-top="0cm" fo:margin-bottom="0cm" style:vertical-pos="top" 
style:vertical-rel="paragraph" style:horizontal-pos="left" 
style:horizontal-rel="paragraph" fo:padding="0cm" fo:border="none" 
draw:wrap-influence-on-position="once-concurrent" loext:allow-overlap="true"/>
+  </style:style>
+  <style:style style:name="fr2" style:family="graphic" 
style:parent-style-name="Graphics">
+   <style:graphic-properties fo:margin-left="0cm" fo:margin-right="0cm" 
fo:margin-top="0cm" fo:margin-bottom="0cm" style:vertical-pos="from-top" 
style:horizontal-pos="center" style:horizontal-rel="paragraph" fo:padding="0cm" 
fo:border="none" style:mirror="none" fo:clip="rect(0cm, 0cm, 0cm, 0cm)" 
draw:luminance="0%" draw:contrast="0%" draw:red="0%" draw:green="0%" 
draw:blue="0%" draw:gamma="100%" draw:color-inversion="false" 
draw:image-opacity="100%" draw:color-mode="standard"/>
+  </style:style>
+  <style:page-layout style:name="pm1">
+   <style:page-layout-properties fo:page-width="21.001cm" 
fo:page-height="29.7cm" style:num-format="1" style:print-orientation="portrait" 
fo:margin-top="2cm" fo:margin-bottom="2cm" fo:margin-left="2cm" 
fo:margin-right="2cm" style:writing-mode="lr-tb" 
style:layout-grid-color="#c0c0c0" style:layout-grid-lines="20" 
style:layout-grid-base-height="0.706cm" style:layout-grid-ruby-height="0.353cm" 
style:layout-grid-mode="none" style:layout-grid-ruby-below="false" 
style:layout-grid-print="false" style:layout-grid-display="false" 
style:footnote-max-height="0cm" loext:margin-gutter="0cm">
+    <style:footnote-sep style:width="0.018cm" 
style:distance-before-sep="0.101cm" style:distance-after-sep="0.101cm" 
style:line-style="solid" style:adjustment="left" style:rel-width="25%" 
style:color="#000000"/>
+   </style:page-layout-properties>
+   <style:header-style/>
+   <style:footer-style/>
+  </style:page-layout>
+  <style:style style:name="dp1" style:family="drawing-page">
+   <style:drawing-page-properties draw:background-size="full"/>
+  </style:style>
+ </office:automatic-styles>
+ <office:master-styles>
+  <style:master-page style:name="Standard" style:page-layout-name="pm1" 
draw:style-name="dp1"/>
+ </office:master-styles>
+ <office:body>
+  <office:text>
+   <text:p text:style-name="Standard"><draw:frame draw:style-name="fr1" 
draw:name="Frame1" text:anchor-type="paragraph" svg:width="8.707cm" 
draw:z-index="0">
+     <draw:text-box fo:min-height="6.765cm">
+      <table:table table:name="Table1" table:style-name="Table1">
+       <table:table-column table:style-name="Table1.A"/>
+       <table:table-column table:style-name="Table1.B"/>
+       <table:table-row table:style-name="Table1.1">
+        <table:table-cell table:style-name="Table1.A1" 
office:value-type="string">
+         <text:p text:style-name="P1"><draw:frame draw:style-name="fr2" 
draw:name="Image1" text:anchor-type="as-char" svg:y="-10.984cm" 
svg:width="11.234cm" svg:height="8.398cm" draw:z-index="1"><draw:image 
draw:mime-type="image/png">
+            
<office:binary-data>iVBORw0KGgoAAAANSUhEUgAAAAIAAAACCAIAAAD91JpzAAAAFklEQVQI12P2Ytilf46NeWX3
+             a804HgAg7QTAqXPBTwAAAABJRU5ErkJggg==
+            </office:binary-data>
+           </draw:image>
+          </draw:frame><text:s/></text:p>
+        </table:table-cell>
+        <table:table-cell table:style-name="Table1.B1" 
office:value-type="string">
+         <text:p text:style-name="Standard"/>
+        </table:table-cell>
+       </table:table-row>
+       <table:table-row table:style-name="Table1.2">
+        <table:table-cell table:style-name="Table1.B1" 
office:value-type="string">
+         <text:p text:style-name="Standard">Lorem ipsum dolor sit amet, 
consectetur adipiscing.</text:p>
+        </table:table-cell>
+        <table:table-cell table:style-name="Table1.B1" 
office:value-type="string">
+         <text:p text:style-name="Standard"/>
+        </table:table-cell>
+       </table:table-row>
+      </table:table>
+     </draw:text-box>
+    </draw:frame></text:p>
+  </office:text>
+ </office:body>
+</office:document>
diff --git a/sw/qa/extras/uiwriter/uiwriter6.cxx 
b/sw/qa/extras/uiwriter/uiwriter6.cxx
index ecb8e6dfaaf4..92ccf7d773fd 100644
--- a/sw/qa/extras/uiwriter/uiwriter6.cxx
+++ b/sw/qa/extras/uiwriter/uiwriter6.cxx
@@ -1688,6 +1688,161 @@ CPPUNIT_TEST_FIXTURE(SwUiWriterTest6, testTdf161332)
     CPPUNIT_ASSERT_EQUAL(SelectionType::Frame, eType2);
 }
 
+CPPUNIT_TEST_FIXTURE(SwUiWriterTest6, testTdf161426)
+{
+    createSwDoc("tdf161426.fodt");
+    SwDoc* pDoc = getSwDoc();
+    CPPUNIT_ASSERT(pDoc);
+    SwWrtShell* pWrtShell = pDoc->GetDocShell()->GetWrtShell();
+    CPPUNIT_ASSERT(pWrtShell);
+    // the cursor is not in the table
+    CPPUNIT_ASSERT(!pWrtShell->IsCursorInTable());
+
+    SwRootFrame* pLayout = pDoc->getIDocumentLayoutAccess().GetCurrentLayout();
+    auto pPage = dynamic_cast<SwPageFrame*>(pLayout->Lower());
+    CPPUNIT_ASSERT(pPage);
+    const SwSortedObjs& rPageObjs = *pPage->GetSortedObjs();
+    CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(1), rPageObjs.size());
+    auto pPageFly = dynamic_cast<SwFlyAtContentFrame*>(rPageObjs[0]);
+    CPPUNIT_ASSERT(pPageFly);
+    auto pTable = dynamic_cast<SwTabFrame*>(pPageFly->GetLower());
+    CPPUNIT_ASSERT(pTable);
+    auto pRow1 = pTable->GetLower();
+    CPPUNIT_ASSERT(pRow1->IsRowFrame());
+    auto pCellA1 = pRow1->GetLower();
+    CPPUNIT_ASSERT(pCellA1);
+    auto pCellB1 = pCellA1->GetNext();
+    const SwRect& rCellB1Rect = pCellB1->getFrameArea();
+    auto nRowHeight = rCellB1Rect.Height();
+
+    // select text frame by clicking on it at the right side of the upper 
right cell
+    Point ptFrom(rCellB1Rect.Left() + rCellB1Rect.Width(), rCellB1Rect.Top() + 
nRowHeight / 2);
+    vcl::Window& rEditWin = pDoc->GetDocShell()->GetView()->GetEditWin();
+    Point aFrom = rEditWin.LogicToPixel(ptFrom);
+    MouseEvent aClickEvent(aFrom, 1, MouseEventModifiers::SIMPLECLICK, 
MOUSE_LEFT);
+    rEditWin.MouseButtonDown(aClickEvent);
+    rEditWin.MouseButtonUp(aClickEvent);
+
+    // Then make sure that the text frame is selected:
+    SelectionType eType = pWrtShell->GetSelectionType();
+    CPPUNIT_ASSERT_EQUAL(SelectionType::Frame, eType);
+
+    // remove selection
+    dispatchCommand(mxComponent, ".uno:Escape", {});
+
+    // select text frame by clicking on it at the right side of the bottom 
right cell
+    auto pRow2 = pRow1->GetNext();
+    CPPUNIT_ASSERT(pRow2->IsRowFrame());
+    auto pCellA2 = pRow2->GetLower();
+    CPPUNIT_ASSERT(pCellA2);
+    auto pCellB2 = pCellA2->GetNext();
+    CPPUNIT_ASSERT(pCellB2);
+    const SwRect& rCellB2Rect = pCellB2->getFrameArea();
+    auto nRow2Height = rCellB2Rect.Height();
+    Point ptFrom2(rCellB2Rect.Left() + rCellB2Rect.Width(), rCellB2Rect.Top() 
+ nRow2Height / 2);
+    Point aFrom2 = rEditWin.LogicToPixel(ptFrom2);
+    MouseEvent aClickEvent2(aFrom2, 1, MouseEventModifiers::SIMPLECLICK, 
MOUSE_LEFT);
+    rEditWin.MouseButtonDown(aClickEvent2);
+    rEditWin.MouseButtonUp(aClickEvent2);
+
+    // Then make sure that the text frame is selected:
+    SelectionType eType2 = pWrtShell->GetSelectionType();
+    CPPUNIT_ASSERT_EQUAL(SelectionType::Frame, eType2);
+}
+
+CPPUNIT_TEST_FIXTURE(SwUiWriterTest6, testTdf161426_content)
+{
+    createSwDoc("tdf161426.fodt");
+    SwDoc* pDoc = getSwDoc();
+    CPPUNIT_ASSERT(pDoc);
+    SwWrtShell* pWrtShell = pDoc->GetDocShell()->GetWrtShell();
+    CPPUNIT_ASSERT(pWrtShell);
+    // the cursor is not in the table
+    CPPUNIT_ASSERT(!pWrtShell->IsCursorInTable());
+
+    SwRootFrame* pLayout = pDoc->getIDocumentLayoutAccess().GetCurrentLayout();
+    auto pPage = dynamic_cast<SwPageFrame*>(pLayout->Lower());
+    CPPUNIT_ASSERT(pPage);
+    const SwSortedObjs& rPageObjs = *pPage->GetSortedObjs();
+    CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(1), rPageObjs.size());
+    auto pPageFly = dynamic_cast<SwFlyAtContentFrame*>(rPageObjs[0]);
+    CPPUNIT_ASSERT(pPageFly);
+    auto pTable = dynamic_cast<SwTabFrame*>(pPageFly->GetLower());
+    CPPUNIT_ASSERT(pTable);
+    auto pRow1 = pTable->GetLower();
+    CPPUNIT_ASSERT(pRow1->IsRowFrame());
+    auto pCellA1 = pRow1->GetLower();
+    CPPUNIT_ASSERT(pCellA1);
+    auto pCellB1 = pCellA1->GetNext();
+    const SwRect& rCellB1Rect = pCellB1->getFrameArea();
+    auto nRowHeight = rCellB1Rect.Height();
+
+    // select content of the B1 by clicking on the center of it
+    Point ptFrom(rCellB1Rect.Left() + rCellB1Rect.Width() / 2, 
rCellB1Rect.Top() + nRowHeight / 2);
+    vcl::Window& rEditWin = pDoc->GetDocShell()->GetView()->GetEditWin();
+    Point aFrom = rEditWin.LogicToPixel(ptFrom);
+    MouseEvent aClickEvent(aFrom, 1, MouseEventModifiers::SIMPLECLICK, 
MOUSE_LEFT);
+    rEditWin.MouseButtonDown(aClickEvent);
+    rEditWin.MouseButtonUp(aClickEvent);
+
+    // Then make sure that the cursor in the table:
+    SelectionType eType2 = pWrtShell->GetSelectionType();
+    // This was false
+    bool bCursorInTable = eType2 == (SelectionType::Text | 
SelectionType::Table);
+    CPPUNIT_ASSERT(bCursorInTable);
+
+    // select content of the B2 by clicking on the center of it
+    auto pRow2 = pRow1->GetNext();
+    CPPUNIT_ASSERT(pRow2->IsRowFrame());
+    auto pCellA2 = pRow2->GetLower();
+    CPPUNIT_ASSERT(pCellA2);
+    auto pCellB2 = pCellA2->GetNext();
+    CPPUNIT_ASSERT(pCellB2);
+    const SwRect& rCellB2Rect = pCellB2->getFrameArea();
+    auto nRow2Height = rCellB2Rect.Height();
+    Point ptFrom2(rCellB2Rect.Left() + rCellB2Rect.Width() / 2,
+                  rCellB2Rect.Top() + nRow2Height / 2);
+    Point aFrom2 = rEditWin.LogicToPixel(ptFrom2);
+    MouseEvent aClickEvent2(aFrom2, 1, MouseEventModifiers::SIMPLECLICK, 
MOUSE_LEFT);
+    rEditWin.MouseButtonDown(aClickEvent2);
+    rEditWin.MouseButtonUp(aClickEvent2);
+
+    // Then make sure that the cursor in the table:
+    SelectionType eType3 = pWrtShell->GetSelectionType();
+    // This was false
+    bCursorInTable = eType3 == (SelectionType::Text | SelectionType::Table);
+    CPPUNIT_ASSERT(bCursorInTable);
+
+    // select content of the A2 by clicking on the center of it
+    const SwRect& rCellA2Rect = pCellA2->getFrameArea();
+    Point ptFrom3(rCellA2Rect.Left() + rCellA2Rect.Width() / 2,
+                  rCellA2Rect.Top() + nRow2Height / 2);
+    Point aFrom3 = rEditWin.LogicToPixel(ptFrom3);
+    MouseEvent aClickEvent3(aFrom3, 1, MouseEventModifiers::SIMPLECLICK, 
MOUSE_LEFT);
+    rEditWin.MouseButtonDown(aClickEvent3);
+    rEditWin.MouseButtonUp(aClickEvent3);
+
+    // Then make sure that the cursor in the table:
+    SelectionType eType4 = pWrtShell->GetSelectionType();
+    // This was false
+    bCursorInTable = eType4 == (SelectionType::Text | SelectionType::Table);
+    CPPUNIT_ASSERT(bCursorInTable);
+
+    // select content of the A1 by clicking on the center of it
+    const SwRect& rCellA1Rect = pCellA1->getFrameArea();
+    auto nRow1Height = rCellA1Rect.Height();
+    Point ptFrom4(rCellA1Rect.Left() + rCellA1Rect.Width() / 2,
+                  rCellA1Rect.Top() + nRow1Height / 2);
+    Point aFrom4 = rEditWin.LogicToPixel(ptFrom4);
+    MouseEvent aClickEvent4(aFrom4, 1, MouseEventModifiers::SIMPLECLICK, 
MOUSE_LEFT);
+    rEditWin.MouseButtonDown(aClickEvent4);
+    rEditWin.MouseButtonUp(aClickEvent4);
+
+    // Then make sure that the text frame is selected:
+    SelectionType eType5 = pWrtShell->GetSelectionType();
+    CPPUNIT_ASSERT_EQUAL(SelectionType::Graphic, eType5);
+}
+
 CPPUNIT_TEST_FIXTURE(SwUiWriterTest6, testTdf161360)
 {
     createSwDoc("tdf160842.fodt");
diff --git a/sw/source/core/frmedt/feshview.cxx 
b/sw/source/core/frmedt/feshview.cxx
index 66ad74f7c25e..c601ae89b114 100644
--- a/sw/source/core/frmedt/feshview.cxx
+++ b/sw/source/core/frmedt/feshview.cxx
@@ -68,7 +68,7 @@
 #include <rootfrm.hxx>
 #include <pagefrm.hxx>
 #include <sectfrm.hxx>
-#include <rowfrm.hxx>
+#include <cellfrm.hxx>
 #include <doc.hxx>
 #include <IDocumentUndoRedo.hxx>
 #include <dview.hxx>
@@ -1446,17 +1446,17 @@ bool SwFEShell::ShouldObjectBeSelected(const Point& 
rPt, bool *pSelectFrameInste
             }
 
             // within table row, where image cropped by the fixed table row 
height,
-            // click position must be in the cell, where the image anchored as 
character
+            // click position must be in the cell frame, where the image 
anchored as character
             if ( bRet && pContact && pContact->ObjAnchoredAsChar() )
             {
                 if ( const SwTableBox *pBox = 
pContact->GetAnchorNode().GetTableBox() )
                 {
-                    SwIterator<SwRowFrame, SwFormat> aIter( 
*pBox->GetUpper()->GetFrameFormat() );
+                    SwIterator<SwCellFrame, SwFormat> aIter( 
*pBox->GetFrameFormat() );
                     bool bContainsClickPosition = false;
-                    for (SwRowFrame* pFrame = aIter.First(); pFrame; pFrame = 
aIter.Next())
+                    for (SwCellFrame* pFrame = aIter.First(); pFrame; pFrame = 
aIter.Next())
                     {
                         const SwRect& rRect = pFrame->getFrameArea();
-                        // click inside the cell which contains the cropped 
image
+                        // click inside the cell frame which contains the 
cropped image
                         if ( rRect.Contains( rPt ) )
                         {
                             // click next to the right cell border
@@ -1468,17 +1468,13 @@ bool SwFEShell::ShouldObjectBeSelected(const Point& 
rPt, bool *pSelectFrameInste
                             bContainsClickPosition = true;
                             break;
                         }
-                        else if ( pSelectFrameInsteadOfCroppedImage && (
-                            // Click outside of the right border
-                            rRect.Contains( Point(rPt.X() - 2 * nHitTol, 
rPt.Y()) ) ||
-                            // or handle the right border of bottom cells 
covered by the cropped
-                            // image instead putting the cursor inside the 
cell (see tdf#160842).
-                            // Click inside the same table, or outside its 
right border
-                            ( pFrame->GetUpper() && 
pFrame->GetUpper()->getFrameArea().Contains(
+                        // or click on the right table border of the same 
table frame
+                        else if ( pSelectFrameInsteadOfCroppedImage &&
+                            ( pFrame->GetUpper() && 
pFrame->GetUpper()->GetUpper() &&
+                              
pFrame->GetUpper()->GetUpper()->getFrameArea().Contains(
                                   Point(rPt.X() - 2 * nHitTol, rPt.Y()) ) &&
-                              // and the click inside is next to the right 
table border
-                              !rRect.Contains( Point(rPt.X() + 2 * nHitTol, 
rRect.Bottom()) )
-                            ) ) )
+                              
!pFrame->GetUpper()->GetUpper()->getFrameArea().Contains(
+                                  Point(rPt.X() + 2 * nHitTol, rPt.Y()) ) ) )
                         {
                             *pSelectFrameInsteadOfCroppedImage = true;
                             bContainsClickPosition = true;

Reply via email to