[Libreoffice-commits] core.git: sfx2/source

Rodolfo Ribeiro Gomes rodolforg at gmail.com
Mon Nov 11 23:26:54 PST 2013


 sfx2/source/control/thumbnailview.cxx |  169 +++++++++++++++++-----------------
 1 file changed, 86 insertions(+), 83 deletions(-)

New commits:
commit b29464a8fa58d776279c6da0247946eefad9be00
Author: Rodolfo Ribeiro Gomes <rodolforg at gmail.com>
Date:   Mon Nov 11 22:24:20 2013 -0200

    less if-nesting in ThumnailView
    
    Easier to read.
    
    Change-Id: I1ceb551d8badffb211b1f444b61375a03cac1348
    Signed-off-by: Rodolfo Ribeiro Gomes <rodolforg at gmail.com>
    Reviewed-on: https://gerrit.libreoffice.org/6643
    Reviewed-by: Noel Grandin <noelgrandin at gmail.com>
    Tested-by: Noel Grandin <noelgrandin at gmail.com>

diff --git a/sfx2/source/control/thumbnailview.cxx b/sfx2/source/control/thumbnailview.cxx
index 6279174..592c8b6 100644
--- a/sfx2/source/control/thumbnailview.cxx
+++ b/sfx2/source/control/thumbnailview.cxx
@@ -732,113 +732,116 @@ void ThumbnailView::MakeItemVisible( sal_uInt16 nItemId )
 
 void ThumbnailView::MouseButtonDown( const MouseEvent& rMEvt )
 {
-    if ( rMEvt.IsLeft() )
+    if ( !rMEvt.IsLeft() )
     {
-        size_t nPos = ImplGetItem(rMEvt.GetPosPixel());
-        ThumbnailViewItem* pItem = ImplGetItem(nPos);
+        Control::MouseButtonDown( rMEvt );
+        return;
+    }
 
-        if (pItem)
-        {
-            if ( rMEvt.GetClicks() == 1 )
-            {
-                if (rMEvt.IsMod1())
-                {
-                    //Keep selected item group state and just invert current desired one state
-                    pItem->setSelection(!pItem->isSelected());
+    size_t nPos = ImplGetItem(rMEvt.GetPosPixel());
+    ThumbnailViewItem* pItem = ImplGetItem(nPos);
 
-                    //This one becomes the selection range start position if it changes its state to selected otherwise resets it
-                    mpStartSelRange = pItem->isSelected() ? mFilteredItemList.begin() + nPos : mFilteredItemList.end();
-                }
-                else if (rMEvt.IsShift() && mpStartSelRange != mFilteredItemList.end())
-                {
-                    std::pair<size_t,size_t> aNewRange;
-                    aNewRange.first = mpStartSelRange - mFilteredItemList.begin();
-                    aNewRange.second = nPos;
+    if ( !pItem )
+    {
+        deselectItems();
+        Control::MouseButtonDown( rMEvt );
+        return;
+    }
 
-                    if (aNewRange.first > aNewRange.second)
-                        std::swap(aNewRange.first,aNewRange.second);
+    if ( rMEvt.GetClicks() == 2 )
+    {
+        OnItemDblClicked(pItem);
+        return;
+    }
 
-                    //Deselect the ones outside of it
-                    for (size_t i = 0, n = mFilteredItemList.size(); i < n; ++i)
-                    {
-                        ThumbnailViewItem *pCurItem  = mFilteredItemList[i];
+    if ( rMEvt.GetClicks() == 1 )
+    {
+        if (rMEvt.IsMod1())
+        {
+            //Keep selected item group state and just invert current desired one state
+            pItem->setSelection(!pItem->isSelected());
 
-                        if (pCurItem->isSelected() && (i < aNewRange.first || i > aNewRange.second))
-                        {
-                            pCurItem->setSelection(false);
+            //This one becomes the selection range start position if it changes its state to selected otherwise resets it
+            mpStartSelRange = pItem->isSelected() ? mFilteredItemList.begin() + nPos : mFilteredItemList.end();
+        }
+        else if (rMEvt.IsShift() && mpStartSelRange != mFilteredItemList.end())
+        {
+            std::pair<size_t,size_t> aNewRange;
+            aNewRange.first = mpStartSelRange - mFilteredItemList.begin();
+            aNewRange.second = nPos;
 
-                            if (pCurItem->isVisible())
-                                DrawItem(pCurItem);
+            if (aNewRange.first > aNewRange.second)
+                std::swap(aNewRange.first,aNewRange.second);
 
-                            maItemStateHdl.Call(pCurItem);
-                        }
-                    }
+            //Deselect the ones outside of it
+            for (size_t i = 0, n = mFilteredItemList.size(); i < n; ++i)
+            {
+                ThumbnailViewItem *pCurItem  = mFilteredItemList[i];
 
-                    size_t nSelPos = mpStartSelRange - mFilteredItemList.begin();
+                if (pCurItem->isSelected() && (i < aNewRange.first || i > aNewRange.second))
+                {
+                    pCurItem->setSelection(false);
 
-                    //Select the items between start range and the selected item
-                    if (nSelPos != nPos)
-                    {
-                        int dir = nSelPos < nPos ? 1 : -1;
-                        size_t nCurPos = nSelPos + dir;
+                    if (pCurItem->isVisible())
+                        DrawItem(pCurItem);
+
+                    maItemStateHdl.Call(pCurItem);
+                }
+            }
+
+            size_t nSelPos = mpStartSelRange - mFilteredItemList.begin();
 
-                        while (nCurPos != nPos)
-                        {
-                            ThumbnailViewItem *pCurItem  = mFilteredItemList[nCurPos];
+            //Select the items between start range and the selected item
+            if (nSelPos != nPos)
+            {
+                int dir = nSelPos < nPos ? 1 : -1;
+                size_t nCurPos = nSelPos + dir;
 
-                            if (!pCurItem->isSelected())
-                            {
-                                pCurItem->setSelection(true);
+                while (nCurPos != nPos)
+                {
+                    ThumbnailViewItem *pCurItem  = mFilteredItemList[nCurPos];
 
-                                if (pCurItem->isVisible())
-                                    DrawItem(pCurItem);
+                    if (!pCurItem->isSelected())
+                    {
+                        pCurItem->setSelection(true);
 
-                                maItemStateHdl.Call(pCurItem);
-                            }
+                        if (pCurItem->isVisible())
+                            DrawItem(pCurItem);
 
-                            nCurPos += dir;
-                        }
+                        maItemStateHdl.Call(pCurItem);
                     }
 
-                    pItem->setSelection(true);
-                }
-                else
-                {
-                    //If we got a group of selected items deselect the rest and only keep the desired one
-                    //mark items as not selected to not fire unnecessary change state events.
-                    pItem->setSelection(false);
-                    deselectItems();
-                    pItem->setSelection(true);
-
-                    //Mark as initial selection range position and reset end one
-                    mpStartSelRange = mFilteredItemList.begin() + nPos;
+                    nCurPos += dir;
                 }
+            }
 
-                if (pItem->isSelected())
-                {
-                    bool bClickOnTitle = pItem->getTextArea().IsInside(rMEvt.GetPosPixel());
-                    pItem->setEditTitle(bClickOnTitle);
-                }
+            pItem->setSelection(true);
+        }
+        else
+        {
+            //If we got a group of selected items deselect the rest and only keep the desired one
+            //mark items as not selected to not fire unnecessary change state events.
+            pItem->setSelection(false);
+            deselectItems();
+            pItem->setSelection(true);
 
-                if (!pItem->isHighlighted())
-                    DrawItem(pItem);
+            //Mark as initial selection range position and reset end one
+            mpStartSelRange = mFilteredItemList.begin() + nPos;
+        }
 
-                maItemStateHdl.Call(pItem);
+        if (pItem->isSelected())
+        {
+            bool bClickOnTitle = pItem->getTextArea().IsInside(rMEvt.GetPosPixel());
+            pItem->setEditTitle(bClickOnTitle);
+        }
 
-                //fire accessible event??
-            }
-            else if ( rMEvt.GetClicks() == 2 )
-            {
-                OnItemDblClicked(pItem);
-            }
+        if (!pItem->isHighlighted())
+            DrawItem(pItem);
 
-            return;
-        }
-        else if (!pItem)
-            deselectItems( );
-    }
+        maItemStateHdl.Call(pItem);
 
-    Control::MouseButtonDown( rMEvt );
+        //fire accessible event??
+    }
 }
 
 void ThumbnailView::MouseButtonUp( const MouseEvent& rMEvt )


More information about the Libreoffice-commits mailing list