Kaydet (Commit) 84dedf4f authored tarafından Miklos Vajna's avatar Miklos Vajna

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
üst 18ce0560
......@@ -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);
......
......@@ -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;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment