desktop/qa/desktop_lib/test_desktop_lib.cxx | 54 ++++++++++++++++++-- libreofficekit/qa/gtktiledviewer/gtktiledviewer.cxx | 36 ++++--------- sc/source/ui/view/tabview.cxx | 26 ++------- 3 files changed, 68 insertions(+), 48 deletions(-)
New commits: commit 2bed1867531fc91d1bd20da226d3fa012356125d Author: Miklos Vajna <[email protected]> Date: Wed Nov 4 10:59:08 2015 +0100 CppunitTest_desktop_lib: test absolute positions for row/column headers Change-Id: If2526647221fef2c6b18b21b589192239d8a89ad diff --git a/desktop/qa/desktop_lib/test_desktop_lib.cxx b/desktop/qa/desktop_lib/test_desktop_lib.cxx index 8a1947e..0e66678 100644 --- a/desktop/qa/desktop_lib/test_desktop_lib.cxx +++ b/desktop/qa/desktop_lib/test_desktop_lib.cxx @@ -363,6 +363,35 @@ void DesktopLOKTest::testPasteWriter() void DesktopLOKTest::testRowColumnHeaders() { + /* + * Payload example: + * + * { + * "rows": [ + * { + * "size": "254.987250637468", + * "text": "1" + * }, + * { + * "size": "509.974501274936", + * "text": "2" + * } + * ], + * "columns": [ + * { + * "size": "1274.93625318734", + * "text": "A" + * }, + * { + * "size": "2549.87250637468", + * "text": "B" + * } + * ] + * } + * + * "size" defines the bottom/right boundary of a row/column in twips (size between 0 and boundary) + * "text" has the header label in UTF-8 + */ LibLODocument_Impl* pDocument = loadDoc("search.ods"); boost::property_tree::ptree aTree; char* pJSON = pDocument->m_pDocumentClass->getCommandValues(pDocument, ".uno:ViewRowColumnHeaders"); @@ -371,23 +400,38 @@ void DesktopLOKTest::testRowColumnHeaders() CPPUNIT_ASSERT(!aStream.str().empty()); boost::property_tree::read_json(aStream, aTree); + sal_Int32 nPrevious = 0; for (boost::property_tree::ptree::value_type& rValue : aTree.get_child("rows")) { sal_Int32 nSize = OString(rValue.second.get<std::string>("size").c_str()).toInt32(); CPPUNIT_ASSERT(nSize > 0); OString aText(rValue.second.get<std::string>("text").c_str()); - // This failed, as the first item did not contain the text of the first row. - CPPUNIT_ASSERT_EQUAL(OString("1"), aText); - break; + if (!nPrevious) + // This failed, as the first item did not contain the text of the first row. + CPPUNIT_ASSERT_EQUAL(OString("1"), aText); + else + { + // Make sure that size is absolute: the first two items have the same relative size. + CPPUNIT_ASSERT(nPrevious < nSize); + break; + } + nPrevious = nSize; } + nPrevious = 0; for (boost::property_tree::ptree::value_type& rValue : aTree.get_child("columns")) { sal_Int32 nSize = OString(rValue.second.get<std::string>("size").c_str()).toInt32(); CPPUNIT_ASSERT(nSize > 0); OString aText(rValue.second.get<std::string>("text").c_str()); - CPPUNIT_ASSERT_EQUAL(OString("A"), aText); - break; + if (!nPrevious) + CPPUNIT_ASSERT_EQUAL(OString("A"), aText); + else + { + CPPUNIT_ASSERT(nPrevious < nSize); + break; + } + nPrevious = nSize; } } commit 84dedf4ff8e7267efa95674e6545c80c9b995cb2 Author: Miklos Vajna <[email protected]> Date: Wed Nov 4 10:32:23 2015 +0100 sc lok: return absolute positions for row/column headers This simplifies both LOK API implementation and client code, and also clients are no longer required to floor() the twip -> pixel conversion result. Change-Id: I63dbc05f53e8f7582b964c43d5da3aad51ede10d diff --git a/libreofficekit/qa/gtktiledviewer/gtktiledviewer.cxx b/libreofficekit/qa/gtktiledviewer/gtktiledviewer.cxx index 2ba6866..a0bf1f8 100644 --- a/libreofficekit/qa/gtktiledviewer/gtktiledviewer.cxx +++ b/libreofficekit/qa/gtktiledviewer/gtktiledviewer.cxx @@ -192,16 +192,16 @@ gboolean TiledRowColumnBar::drawImpl(GtkWidget* /*pWidget*/, cairo_t* pCairo) { cairo_set_source_rgb(pCairo, 0, 0, 0); - int nTotal = 0; + int nPrevious = 0; for (const Header& rHeader : m_aHeaders) { GdkRectangle aRectangle; if (m_eType == ROW) { aRectangle.x = 0; - aRectangle.y = nTotal - 1; + aRectangle.y = nPrevious - 1; aRectangle.width = ROW_HEADER_WIDTH - 1; - aRectangle.height = rHeader.m_nSize; + aRectangle.height = rHeader.m_nSize - nPrevious; // Left line. cairo_rectangle(pCairo, aRectangle.x, aRectangle.y, 1, aRectangle.height); cairo_fill(pCairo); @@ -214,9 +214,9 @@ gboolean TiledRowColumnBar::drawImpl(GtkWidget* /*pWidget*/, cairo_t* pCairo) } else { - aRectangle.x = nTotal - 1; + aRectangle.x = nPrevious - 1; aRectangle.y = 0; - aRectangle.width = rHeader.m_nSize; + aRectangle.width = rHeader.m_nSize - nPrevious; aRectangle.height = COLUMN_HEADER_HEIGHT - 1; // Top line. cairo_rectangle(pCairo, aRectangle.x, aRectangle.y, aRectangle.width, 1); @@ -229,8 +229,8 @@ gboolean TiledRowColumnBar::drawImpl(GtkWidget* /*pWidget*/, cairo_t* pCairo) cairo_fill(pCairo); } drawText(pCairo, aRectangle, rHeader.m_aText); - nTotal += rHeader.m_nSize; - if (nTotal > m_nSizePixel) + nPrevious = rHeader.m_nSize; + if (rHeader.m_nSize > m_nSizePixel) break; } @@ -275,39 +275,29 @@ gboolean TiledRowColumnBar::docConfigureEvent(GtkWidget* pDocView, GdkEventConfi gtk_widget_show(rWindow.m_pCornerButton->m_pDrawingArea); rWindow.m_pRowBar->m_aHeaders.clear(); - int nTotal = 0; for (boost::property_tree::ptree::value_type& rValue : aTree.get_child("rows")) { - int nSize = lok_doc_view_twip_to_pixel(LOK_DOC_VIEW(pDocView), std::atof(rValue.second.get<std::string>("size").c_str())); - int nScrolledSize = nSize; - if (nTotal + nSize >= rWindow.m_pRowBar->m_nPositionPixel) + int nSize = std::round(lok_doc_view_twip_to_pixel(LOK_DOC_VIEW(pDocView), std::atof(rValue.second.get<std::string>("size").c_str()))); + if (nSize >= rWindow.m_pRowBar->m_nPositionPixel) { - if (nTotal < rWindow.m_pRowBar->m_nPositionPixel) - // First visible row: reduce height because the row is only partially visible. - nScrolledSize = nTotal + nSize - rWindow.m_pRowBar->m_nPositionPixel; + int nScrolledSize = nSize - rWindow.m_pRowBar->m_nPositionPixel; Header aHeader(nScrolledSize, rValue.second.get<std::string>("text")); rWindow.m_pRowBar->m_aHeaders.push_back(aHeader); } - nTotal += nSize; } gtk_widget_show(rWindow.m_pRowBar->m_pDrawingArea); gtk_widget_queue_draw(rWindow.m_pRowBar->m_pDrawingArea); rWindow.m_pColumnBar->m_aHeaders.clear(); - nTotal = 0; for (boost::property_tree::ptree::value_type& rValue : aTree.get_child("columns")) { - int nSize = lok_doc_view_twip_to_pixel(LOK_DOC_VIEW(pDocView), std::atof(rValue.second.get<std::string>("size").c_str())); - int nScrolledSize = nSize; - if (nTotal + nSize >= rWindow.m_pColumnBar->m_nPositionPixel) + int nSize = std::round(lok_doc_view_twip_to_pixel(LOK_DOC_VIEW(pDocView), std::atof(rValue.second.get<std::string>("size").c_str()))); + if (nSize >= rWindow.m_pColumnBar->m_nPositionPixel) { - if (nTotal < rWindow.m_pColumnBar->m_nPositionPixel) - // First visible column: reduce width because the column is only partially visible. - nScrolledSize = nTotal + nSize - rWindow.m_pColumnBar->m_nPositionPixel; + int nScrolledSize = nSize - rWindow.m_pColumnBar->m_nPositionPixel; Header aHeader(nScrolledSize, rValue.second.get<std::string>("text")); rWindow.m_pColumnBar->m_aHeaders.push_back(aHeader); } - nTotal += nSize; } gtk_widget_show(rWindow.m_pColumnBar->m_pDrawingArea); gtk_widget_queue_draw(rWindow.m_pColumnBar->m_pDrawingArea); diff --git a/sc/source/ui/view/tabview.cxx b/sc/source/ui/view/tabview.cxx index d197750..b4703d9 100644 --- a/sc/source/ui/view/tabview.cxx +++ b/sc/source/ui/view/tabview.cxx @@ -2295,6 +2295,7 @@ OUString ScTabView::getRowColumnHeaders(const Rectangle& rRectangle) for (SCROW nRow = 0; nRow <= nEndRow; ++nRow) { sal_uInt16 nSize = pDoc->GetOriginalHeight(nRow, aViewData.GetTabNo()); + long nSizePixels = ScViewData::ToPixel(nSize, aViewData.GetPPTY()); OUString aText = pRowBar[SC_SPLIT_BOTTOM]->GetEntryText(nRow); bool bSkip = false; @@ -2308,22 +2309,13 @@ OUString ScTabView::getRowColumnHeaders(const Rectangle& rRectangle) } if (!bSkip) { - if (aRows.empty() && nTotal > 0) - { - // The sizes are relative sizes, so include the total skipped size before the real items. - boost::property_tree::ptree aRow; - // Client is required to floor(), rather than round() the sizes in general, so add 0.5 here to have rounding. - aRow.put("size", OString::number(long((nTotalPixels + 0.5) / aViewData.GetPPTY())).getStr()); - aRow.put("text", ""); - aRows.push_back(std::make_pair("", aRow)); - } boost::property_tree::ptree aRow; - aRow.put("size", OString::number(nSize).getStr()); + aRow.put("size", OString::number((nTotalPixels + nSizePixels) / aViewData.GetPPTY()).getStr()); aRow.put("text", aText.toUtf8().getStr()); aRows.push_back(std::make_pair("", aRow)); } nTotal += nSize; - nTotalPixels += long(nSize * aViewData.GetPPTY()); + nTotalPixels += nSizePixels; } boost::property_tree::ptree aCols; @@ -2332,6 +2324,7 @@ OUString ScTabView::getRowColumnHeaders(const Rectangle& rRectangle) for (SCCOL nCol = 0; nCol <= nEndCol; ++nCol) { sal_uInt16 nSize = pDoc->GetColWidth(nCol, aViewData.GetTabNo()); + long nSizePixels = ScViewData::ToPixel(nSize, aViewData.GetPPTX()); OUString aText = pColBar[SC_SPLIT_LEFT]->GetEntryText(nCol); bool bSkip = false; @@ -2345,20 +2338,13 @@ OUString ScTabView::getRowColumnHeaders(const Rectangle& rRectangle) } if (!bSkip) { - if (aCols.empty() && nTotal > 0) - { - boost::property_tree::ptree aCol; - aCol.put("size", OString::number(long((nTotalPixels + 0.5) / aViewData.GetPPTX())).getStr()); - aCol.put("text", ""); - aCols.push_back(std::make_pair("", aCol)); - } boost::property_tree::ptree aCol; - aCol.put("size", OString::number(nSize).getStr()); + aCol.put("size", OString::number((nTotalPixels + nSizePixels) / aViewData.GetPPTX()).getStr()); aCol.put("text", aText.toUtf8().getStr()); aCols.push_back(std::make_pair("", aCol)); } nTotal += nSize; - nTotalPixels += long(nSize * aViewData.GetPPTX()); + nTotalPixels += nSizePixels; } boost::property_tree::ptree aTree; _______________________________________________ Libreoffice-commits mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits
