[Libreoffice-commits] core.git: Branch 'feature/tiled-editing' - 2 commits - libreofficekit/source sd/source sw/source

Miklos Vajna vmiklos at collabora.co.uk
Tue Mar 31 03:52:14 PDT 2015


 libreofficekit/source/gtk/lokdocview.cxx |  123 ++++++++++++++-----------------
 sd/source/ui/inc/ViewShell.hxx           |    2 
 sd/source/ui/unoidl/unomodel.cxx         |    4 -
 sd/source/ui/view/viewshel.cxx           |    2 
 sw/source/uibase/docvw/edtwin.cxx        |    2 
 sw/source/uibase/inc/edtwin.hxx          |    2 
 sw/source/uibase/uno/unotxdoc.cxx        |    4 -
 7 files changed, 66 insertions(+), 73 deletions(-)

New commits:
commit 0d0d212300f0c864d95becfd621a8229dc0d9ad8
Author: Miklos Vajna <vmiklos at collabora.co.uk>
Date:   Tue Mar 31 12:50:36 2015 +0200

    lokdocview: GList -> std::vector
    
    Primarily because I'm worried about the untyped GList.
    
    Change-Id: I0ae6610019f6e80b0cad12086782fd89ac74943b

diff --git a/libreofficekit/source/gtk/lokdocview.cxx b/libreofficekit/source/gtk/lokdocview.cxx
index 04a7aeb..f5a3257 100644
--- a/libreofficekit/source/gtk/lokdocview.cxx
+++ b/libreofficekit/source/gtk/lokdocview.cxx
@@ -10,6 +10,7 @@
 #include <sal/types.h>
 #include <math.h>
 #include <string.h>
+#include <vector>
 
 #include <gdk/gdkkeysyms.h>
 
@@ -61,7 +62,7 @@ struct LOKDocView_Impl
     /// Time of the last button release.
     guint32 m_nLastButtonReleaseTime;
     /// Rectangles of the current text selection.
-    GList* m_pTextSelectionRectangles;
+    std::vector<GdkRectangle> m_aTextSelectionRectangles;
     /// Position and size of the selection start (as if there would be a cursor caret there).
     GdkRectangle m_aTextSelectionStart;
     /// Position and size of the selection end.
@@ -155,6 +156,10 @@ struct LOKDocView_Impl
      * the tiles that intersect with pPartial.
      */
     void renderDocument(GdkRectangle* pPartial);
+    /// Returns the GdkRectangle of a width,height,x,y string.
+    static GdkRectangle payloadToRectangle(const char* pPayload);
+    /// Returns the GdkRectangles of a w,h,x,y;w2,h2,x2,y2;... string.
+    static std::vector<GdkRectangle> payloadToRectangles(const char* pPayload);
 };
 
 LOKDocView_Impl::LOKDocView_Impl(LOKDocView* pDocView)
@@ -171,7 +176,6 @@ LOKDocView_Impl::LOKDocView_Impl(LOKDocView* pDocView)
     m_bCursorVisible(true),
     m_nLastButtonPressTime(0),
     m_nLastButtonReleaseTime(0),
-    m_pTextSelectionRectangles(0),
     m_aTextSelectionStart({0, 0, 0, 0}),
     m_aTextSelectionEnd({0, 0, 0, 0}),
     m_aGraphicSelection({0, 0, 0, 0}),
@@ -498,7 +502,7 @@ gboolean LOKDocView_Impl::renderOverlayImpl(GtkWidget* pWidget)
         cairo_fill(pCairo);
     }
 
-    if (m_bEdit && m_bCursorVisible && !isEmptyRectangle(m_aVisibleCursor) && !m_pTextSelectionRectangles)
+    if (m_bEdit && m_bCursorVisible && !isEmptyRectangle(m_aVisibleCursor) && m_aTextSelectionRectangles.empty())
     {
         // Have a cursor, but no selection: we need the middle handle.
         if (!m_pHandleMiddle)
@@ -506,18 +510,17 @@ gboolean LOKDocView_Impl::renderOverlayImpl(GtkWidget* pWidget)
         renderHandle(pCairo, m_aVisibleCursor, m_pHandleMiddle, m_aHandleMiddleRect);
     }
 
-    if (m_pTextSelectionRectangles)
+    if (!m_aTextSelectionRectangles.empty())
     {
-        for (GList* i = m_pTextSelectionRectangles; i != NULL; i = i->next)
+        for (GdkRectangle& rRectangle : m_aTextSelectionRectangles)
         {
-            GdkRectangle* pRectangle = static_cast<GdkRectangle*>(i->data);
             // Blue with 75% transparency.
             cairo_set_source_rgba(pCairo, ((double)0x43)/255, ((double)0xac)/255, ((double)0xe8)/255, 0.25);
             cairo_rectangle(pCairo,
-                            twipToPixel(pRectangle->x),
-                            twipToPixel(pRectangle->y),
-                            twipToPixel(pRectangle->width),
-                            twipToPixel(pRectangle->height));
+                            twipToPixel(rRectangle.x),
+                            twipToPixel(rRectangle.y),
+                            twipToPixel(rRectangle.width),
+                            twipToPixel(rRectangle.height));
             cairo_fill(pCairo);
         }
 
@@ -766,6 +769,44 @@ void LOKDocView_Impl::renderDocument(GdkRectangle* pPartial)
     }
 }
 
+GdkRectangle LOKDocView_Impl::payloadToRectangle(const char* pPayload)
+{
+    GdkRectangle aRet;
+
+    aRet.width = aRet.height = aRet.x = aRet.y = 0;
+    gchar** ppCoordinates = g_strsplit(pPayload, ", ", 4);
+    gchar** ppCoordinate = ppCoordinates;
+    if (!*ppCoordinate)
+        return aRet;
+    aRet.x = atoi(*ppCoordinate);
+    ++ppCoordinate;
+    if (!*ppCoordinate)
+        return aRet;
+    aRet.y = atoi(*ppCoordinate);
+    ++ppCoordinate;
+    if (!*ppCoordinate)
+        return aRet;
+    aRet.width = atoi(*ppCoordinate);
+    ++ppCoordinate;
+    if (!*ppCoordinate)
+        return aRet;
+    aRet.height = atoi(*ppCoordinate);
+    g_strfreev(ppCoordinates);
+    return aRet;
+}
+
+std::vector<GdkRectangle> LOKDocView_Impl::payloadToRectangles(const char* pPayload)
+{
+    std::vector<GdkRectangle> aRet;
+
+    gchar** ppRectangles = g_strsplit(pPayload, "; ", 0);
+    for (gchar** ppRectangle = ppRectangles; *ppRectangle; ++ppRectangle)
+        aRet.push_back(payloadToRectangle(*ppRectangle));
+    g_strfreev(ppRectangles);
+
+    return aRet;
+}
+
 enum
 {
     EDIT_CHANGED,
@@ -854,51 +895,6 @@ typedef struct
 }
 LOKDocViewCallbackData;
 
-/// Returns the GdkRectangle of a width,height,x,y string.
-static GdkRectangle lcl_payloadToRectangle(const char* pPayload)
-{
-    GdkRectangle aRet;
-
-    aRet.width = aRet.height = aRet.x = aRet.y = 0;
-    gchar** ppCoordinates = g_strsplit(pPayload, ", ", 4);
-    gchar** ppCoordinate = ppCoordinates;
-    if (!*ppCoordinate)
-        return aRet;
-    aRet.x = atoi(*ppCoordinate);
-    ++ppCoordinate;
-    if (!*ppCoordinate)
-        return aRet;
-    aRet.y = atoi(*ppCoordinate);
-    ++ppCoordinate;
-    if (!*ppCoordinate)
-        return aRet;
-    aRet.width = atoi(*ppCoordinate);
-    ++ppCoordinate;
-    if (!*ppCoordinate)
-        return aRet;
-    aRet.height = atoi(*ppCoordinate);
-    g_strfreev(ppCoordinates);
-    return aRet;
-}
-
-/// Returns the GdkRectangle list of a w,h,x,y;w2,h2,x2,y2;... string.
-static GList* lcl_payloadToRectangles(const char* pPayload)
-{
-    GList* pRet = NULL;
-
-    gchar** ppRectangles = g_strsplit(pPayload, "; ", 0);
-    for (gchar** ppRectangle = ppRectangles; *ppRectangle; ++ppRectangle)
-    {
-        GdkRectangle aRect = lcl_payloadToRectangle(*ppRectangle);
-        GdkRectangle* pRect = g_new0(GdkRectangle, 1);
-        *pRect = aRect;
-        pRet = g_list_prepend(pRet, pRect);
-    }
-    g_strfreev(ppRectangles);
-
-    return pRet;
-}
-
 static const gchar* lcl_LibreOfficeKitCallbackTypeToString(int nType)
 {
     switch (nType)
@@ -935,7 +931,7 @@ static gboolean lok_docview_callback(gpointer pData)
     {
         if (strcmp(pCallback->m_pPayload, "EMPTY") != 0)
         {
-            GdkRectangle aRectangle = lcl_payloadToRectangle(pCallback->m_pPayload);
+            GdkRectangle aRectangle = LOKDocView_Impl::payloadToRectangle(pCallback->m_pPayload);
             pCallback->m_pDocView->m_pImpl->renderDocument(&aRectangle);
         }
         else
@@ -944,7 +940,7 @@ static gboolean lok_docview_callback(gpointer pData)
     break;
     case LOK_CALLBACK_INVALIDATE_VISIBLE_CURSOR:
     {
-        pCallback->m_pDocView->m_pImpl->m_aVisibleCursor = lcl_payloadToRectangle(pCallback->m_pPayload);
+        pCallback->m_pDocView->m_pImpl->m_aVisibleCursor = LOKDocView_Impl::payloadToRectangle(pCallback->m_pPayload);
         pCallback->m_pDocView->m_pImpl->m_bCursorOverlayVisible = true;
         gtk_widget_queue_draw(GTK_WIDGET(pCallback->m_pDocView->m_pImpl->m_pEventBox));
     }
@@ -952,13 +948,10 @@ static gboolean lok_docview_callback(gpointer pData)
     case LOK_CALLBACK_TEXT_SELECTION:
     {
         LOKDocView* pDocView = pCallback->m_pDocView;
-        GList* pRectangles = lcl_payloadToRectangles(pCallback->m_pPayload);
-        if (pDocView->m_pImpl->m_pTextSelectionRectangles)
-            g_list_free_full(pDocView->m_pImpl->m_pTextSelectionRectangles, g_free);
-        pDocView->m_pImpl->m_pTextSelectionRectangles = pRectangles;
+        pDocView->m_pImpl->m_aTextSelectionRectangles = LOKDocView_Impl::payloadToRectangles(pCallback->m_pPayload);
 
         // In case the selection is empty, then we get no LOK_CALLBACK_TEXT_SELECTION_START/END events.
-        if (pRectangles == NULL)
+        if (pDocView->m_pImpl->m_aTextSelectionRectangles.empty())
         {
             memset(&pDocView->m_pImpl->m_aTextSelectionStart, 0, sizeof(pDocView->m_pImpl->m_aTextSelectionStart));
             memset(&pDocView->m_pImpl->m_aHandleStartRect, 0, sizeof(pDocView->m_pImpl->m_aHandleStartRect));
@@ -972,12 +965,12 @@ static gboolean lok_docview_callback(gpointer pData)
     break;
     case LOK_CALLBACK_TEXT_SELECTION_START:
     {
-        pCallback->m_pDocView->m_pImpl->m_aTextSelectionStart = lcl_payloadToRectangle(pCallback->m_pPayload);
+        pCallback->m_pDocView->m_pImpl->m_aTextSelectionStart = LOKDocView_Impl::payloadToRectangle(pCallback->m_pPayload);
     }
     break;
     case LOK_CALLBACK_TEXT_SELECTION_END:
     {
-        pCallback->m_pDocView->m_pImpl->m_aTextSelectionEnd = lcl_payloadToRectangle(pCallback->m_pPayload);
+        pCallback->m_pDocView->m_pImpl->m_aTextSelectionEnd = LOKDocView_Impl::payloadToRectangle(pCallback->m_pPayload);
     }
     break;
     case LOK_CALLBACK_CURSOR_VISIBLE:
@@ -988,7 +981,7 @@ static gboolean lok_docview_callback(gpointer pData)
     case LOK_CALLBACK_GRAPHIC_SELECTION:
     {
         if (strcmp(pCallback->m_pPayload, "EMPTY") != 0)
-            pCallback->m_pDocView->m_pImpl->m_aGraphicSelection = lcl_payloadToRectangle(pCallback->m_pPayload);
+            pCallback->m_pDocView->m_pImpl->m_aGraphicSelection = LOKDocView_Impl::payloadToRectangle(pCallback->m_pPayload);
         else
             memset(&pCallback->m_pDocView->m_pImpl->m_aGraphicSelection, 0, sizeof(pCallback->m_pDocView->m_pImpl->m_aGraphicSelection));
         gtk_widget_queue_draw(GTK_WIDGET(pCallback->m_pDocView->m_pImpl->m_pEventBox));
commit 7471a98bf02635289a4de9a3155f8b2d46b508dd
Author: Miklos Vajna <vmiklos at collabora.co.uk>
Date:   Tue Mar 31 11:58:23 2015 +0200

    Change the Logic in SetGraphicLogicPosition()
    
    Seeing that SetGraphicLogicPosition works in twips in sw but in mm100 in
    sd, change the Logic in then name to the actual unit.
    
    Change-Id: I825f735eac8c626efcb11d85532ea30e85416acd

diff --git a/sd/source/ui/inc/ViewShell.hxx b/sd/source/ui/inc/ViewShell.hxx
index 89bd8e6..93bb0f9 100644
--- a/sd/source/ui/inc/ViewShell.hxx
+++ b/sd/source/ui/inc/ViewShell.hxx
@@ -450,7 +450,7 @@ public:
     /// Allows adjusting the point or mark of the selection to a document coordinate.
     void SetCursorLogicPosition(const Point& rPosition, bool bPoint, bool bClearMark);
     /// Allows starting or ending a graphic move or resize action.
-    void SetGraphicLogicPosition(bool bStart, const Point& rPosition);
+    void SetGraphicMm100Position(bool bStart, const Point& rPosition);
 
     class Implementation;
 
diff --git a/sd/source/ui/unoidl/unomodel.cxx b/sd/source/ui/unoidl/unomodel.cxx
index 0a1a955..9c9678b 100644
--- a/sd/source/ui/unoidl/unomodel.cxx
+++ b/sd/source/ui/unoidl/unomodel.cxx
@@ -2440,10 +2440,10 @@ void SdXImpressDocument::setGraphicSelection(int nType, int nX, int nY)
     switch (nType)
     {
     case LOK_SETGRAPHICSELECTION_START:
-        pViewShell->SetGraphicLogicPosition(/*bStart=*/true, aPoint);
+        pViewShell->SetGraphicMm100Position(/*bStart=*/true, aPoint);
         break;
     case LOK_SETGRAPHICSELECTION_END:
-        pViewShell->SetGraphicLogicPosition(/*bStart=*/false, aPoint);
+        pViewShell->SetGraphicMm100Position(/*bStart=*/false, aPoint);
         break;
     default:
         assert(false);
diff --git a/sd/source/ui/view/viewshel.cxx b/sd/source/ui/view/viewshel.cxx
index 39aff2f..7f46731 100644
--- a/sd/source/ui/view/viewshel.cxx
+++ b/sd/source/ui/view/viewshel.cxx
@@ -548,7 +548,7 @@ void ViewShell::SetCursorLogicPosition(const Point& rPosition, bool bPoint, bool
     }
 }
 
-void ViewShell::SetGraphicLogicPosition(bool bStart, const Point& rPosition)
+void ViewShell::SetGraphicMm100Position(bool bStart, const Point& rPosition)
 {
     if (bStart)
     {
diff --git a/sw/source/uibase/docvw/edtwin.cxx b/sw/source/uibase/docvw/edtwin.cxx
index f0831ac..9b0eecb 100644
--- a/sw/source/uibase/docvw/edtwin.cxx
+++ b/sw/source/uibase/docvw/edtwin.cxx
@@ -6229,7 +6229,7 @@ void SwEditWin::SetCursorLogicPosition(const Point& rPosition, bool bPoint, bool
         rShell.getShellCrsr(/*bBlock=*/false)->Exchange();
 }
 
-void SwEditWin::SetGraphicLogicPosition(bool bStart, const Point& rPosition)
+void SwEditWin::SetGraphicTwipPosition(bool bStart, const Point& rPosition)
 {
     if (bStart)
     {
diff --git a/sw/source/uibase/inc/edtwin.hxx b/sw/source/uibase/inc/edtwin.hxx
index b9d00f9..5a4cf7a 100644
--- a/sw/source/uibase/inc/edtwin.hxx
+++ b/sw/source/uibase/inc/edtwin.hxx
@@ -305,7 +305,7 @@ public:
     /// Allows adjusting the point or mark of the selection to a document coordinate.
     void SetCursorLogicPosition(const Point& rPosition, bool bPoint, bool bClearMark);
     /// Allows starting or ending a graphic move or resize action.
-    void SetGraphicLogicPosition(bool bStart, const Point& rPosition);
+    void SetGraphicTwipPosition(bool bStart, const Point& rPosition);
 };
 
 #endif
diff --git a/sw/source/uibase/uno/unotxdoc.cxx b/sw/source/uibase/uno/unotxdoc.cxx
index 02c603c..cdf2577 100644
--- a/sw/source/uibase/uno/unotxdoc.cxx
+++ b/sw/source/uibase/uno/unotxdoc.cxx
@@ -3237,10 +3237,10 @@ void SwXTextDocument::setGraphicSelection(int nType, int nX, int nY)
     switch (nType)
     {
     case LOK_SETGRAPHICSELECTION_START:
-        rEditWin.SetGraphicLogicPosition(/*bStart=*/true, Point(nX, nY));
+        rEditWin.SetGraphicTwipPosition(/*bStart=*/true, Point(nX, nY));
         break;
     case LOK_SETGRAPHICSELECTION_END:
-        rEditWin.SetGraphicLogicPosition(/*bStart=*/false, Point(nX, nY));
+        rEditWin.SetGraphicTwipPosition(/*bStart=*/false, Point(nX, nY));
         break;
     default:
         assert(false);


More information about the Libreoffice-commits mailing list