From 1bde6d664d10eb7dfd00b9e7e66dccfdce1eb2b8 Mon Sep 17 00:00:00 2001
From: Douglas Mencken <dougmencken@gmail.com>
Date: Sun, 3 Apr 2016 15:58:39 -0400
Subject: [PATCH 2/2] sd: convert NavigatorDragType to enum class

Change-Id: Ifb2e13e9ecadd6caaadb3802033b28465438dfc7
---
 sd/inc/pres.hxx               | 19 ++++++++++-----
 sd/source/ui/dlg/navigatr.cxx | 56 ++++++++++++++++++++++---------------------
 sd/source/ui/dlg/sdtreelb.cxx |  6 ++---
 sd/source/ui/view/sdview2.cxx |  6 ++---
 4 files changed, 48 insertions(+), 39 deletions(-)

diff --git a/sd/inc/pres.hxx b/sd/inc/pres.hxx
index ab816d5..1e2eada 100644
--- a/sd/inc/pres.hxx
+++ b/sd/inc/pres.hxx
@@ -121,14 +121,21 @@ enum class DocumentType
     Draw
 };
 
-enum NavigatorDragType
+enum class NavigatorDragType
 {
-    NAVIGATOR_DRAGTYPE_NONE,
-    NAVIGATOR_DRAGTYPE_URL,
-    NAVIGATOR_DRAGTYPE_LINK,
-    NAVIGATOR_DRAGTYPE_EMBEDDED
+    None,
+    URL,
+    Link,
+    Embedded,
+    LAST = Embedded
 };
-#define NAVIGATOR_DRAGTYPE_COUNT 4
+
+/*
+inline NavigatorDragType operator++( NavigatorDragType & t )
+{
+    return x = ( NavigatorDragType )( std::underlying_type< NavigatorDragType >::type( t ) + 1 );
+}
+*/
 
 #endif // INCLUDED_SD_INC_PRES_HXX
 
diff --git a/sd/source/ui/dlg/navigatr.cxx b/sd/source/ui/dlg/navigatr.cxx
index 042f06a..6a7dfe40 100644
--- a/sd/source/ui/dlg/navigatr.cxx
+++ b/sd/source/ui/dlg/navigatr.cxx
@@ -65,7 +65,7 @@ SdNavigatorWin::SdNavigatorWin(vcl::Window* pParent, SfxBindings* pInBindings)
     : PanelLayout(pParent, "NavigatorPanel", "modules/simpress/ui/navigatorpanel.ui", nullptr)
     , mbDocImported ( false )
       // On changes of the DragType: adjust SelectionMode of TLB!
-    , meDragType ( NAVIGATOR_DRAGTYPE_EMBEDDED )
+    , meDragType ( NavigatorDragType::Embedded )
     , mpBindings ( pInBindings )
     , mpNavigatorCtrlItem( nullptr )
     , mpPageNameCtrlItem( nullptr )
@@ -204,8 +204,8 @@ NavigatorDragType SdNavigatorWin::GetNavigatorDragType()
     NavigatorDragType   eDT = meDragType;
     NavDocInfo*         pInfo = GetDocInfo();
 
-    if( ( eDT == NAVIGATOR_DRAGTYPE_LINK ) && ( ( pInfo && !pInfo->HasName() ) || !maTlbObjects->IsLinkableSelected() ) )
-        eDT = NAVIGATOR_DRAGTYPE_NONE;
+    if( ( eDT == NavigatorDragType::Link ) && ( ( pInfo && !pInfo->HasName() ) || !maTlbObjects->IsLinkableSelected() ) )
+        eDT = NavigatorDragType::None;
 
     return eDT;
 }
@@ -214,7 +214,7 @@ NavigatorDragType SdNavigatorWin::GetNavigatorDragType()
 sd::DrawDocShell* SdNavigatorWin::GetDrawDocShell( const SdDrawDocument* pDoc )
 {
     if( !pDoc )
-        return nullptr; // const as const can...
+        return nullptr;
     sd::DrawDocShell* pDocShell = pDoc->GetDocSh();
     return pDocShell;
 }
@@ -236,7 +236,7 @@ IMPL_LINK_NOARG(SdNavigatorWin, SelectToolboxHdl, ToolBox *, void)
 
     if (ePage != PAGE_NONE)
     {
-        SfxUInt16Item aItem( SID_NAVIGATOR_PAGE, (sal_uInt16)ePage );
+        SfxUInt16Item aItem( SID_NAVIGATOR_PAGE, static_cast< sal_uInt16 >( ePage ) );
         mpBindings->GetDispatcher()->ExecuteList(SID_NAVIGATOR_PAGE,
                 SfxCallMode::SLOT | SfxCallMode::RECORD, { &aItem });
     }
@@ -254,33 +254,36 @@ IMPL_LINK( SdNavigatorWin, DropdownClickToolBoxHdl, ToolBox*, pBox, void )
 
         static const char* aHIDs[] =
         {
+             nullptr,
              HID_SD_NAVIGATOR_MENU1,
              HID_SD_NAVIGATOR_MENU2,
              HID_SD_NAVIGATOR_MENU3,
              nullptr
         };
 
-        for (sal_uInt16 nID = NAVIGATOR_DRAGTYPE_URL; nID < NAVIGATOR_DRAGTYPE_COUNT; ++nID)
+        const std::array< NavigatorDragType, 3 > navigatorDragTypes = { NavigatorDragType::URL, NavigatorDragType::Link, NavigatorDragType::Embedded };
+
+        for ( NavigatorDragType nID : navigatorDragTypes )
         {
-            sal_uInt16 nRId = GetDragTypeSdResId( (NavigatorDragType)nID, false );
+            sal_uInt16 nRId = GetDragTypeSdResId( nID, false );
             if( nRId > 0 )
             {
-                DBG_ASSERT(aHIDs[nID-NAVIGATOR_DRAGTYPE_URL],"HelpId not added!");
-                pMenu->InsertItem(nID, SD_RESSTR(nRId), MenuItemBits::RADIOCHECK);
-                pMenu->SetHelpId(nID, aHIDs[nID - NAVIGATOR_DRAGTYPE_URL]);
+                const char* theHID = aHIDs[ std::underlying_type< NavigatorDragType >::type( nID ) ];
+                DBG_ASSERT( theHID , "HelpId not added" );
+                pMenu->InsertItem( std::underlying_type< NavigatorDragType >::type( nID ), SD_RESSTR( nRId ), MenuItemBits::RADIOCHECK );
+                pMenu->SetHelpId( std::underlying_type< NavigatorDragType >::type( nID ), theHID );
             }
-
         }
         NavDocInfo* pInfo = GetDocInfo();
 
         if( ( pInfo && !pInfo->HasName() ) || !maTlbObjects->IsLinkableSelected() )
         {
-            pMenu->EnableItem( NAVIGATOR_DRAGTYPE_LINK, false );
-            pMenu->EnableItem( NAVIGATOR_DRAGTYPE_URL, false );
-            meDragType = NAVIGATOR_DRAGTYPE_EMBEDDED;
+            pMenu->EnableItem( std::underlying_type< NavigatorDragType >::type( NavigatorDragType::Link ), false );
+            pMenu->EnableItem( std::underlying_type< NavigatorDragType >::type( NavigatorDragType::URL ), false );
+            meDragType = NavigatorDragType::Embedded;
         }
 
-        pMenu->CheckItem( (sal_uInt16)meDragType );
+        pMenu->CheckItem( std::underlying_type< NavigatorDragType >::type( meDragType ) );
         pMenu->SetSelectHdl( LINK( this, SdNavigatorWin, MenuSelectHdl ) );
 
         pMenu->Execute( this, maToolbox->GetItemRect( nId ), PopupMenuFlags::ExecuteDown );
@@ -382,9 +385,9 @@ IMPL_LINK_NOARG(SdNavigatorWin, SelectDocumentHdl, ListBox&, void)
     }
 
     // check if link or url is possible
-    if( ( pInfo && !pInfo->HasName() ) || !maTlbObjects->IsLinkableSelected() || ( meDragType != NAVIGATOR_DRAGTYPE_EMBEDDED ) )
+    if( ( pInfo && !pInfo->HasName() ) || !maTlbObjects->IsLinkableSelected() || ( meDragType != NavigatorDragType::Embedded ) )
     {
-        meDragType = NAVIGATOR_DRAGTYPE_EMBEDDED;
+        meDragType = NavigatorDragType::Embedded;
         SetDragImage();
     }
 }
@@ -399,17 +402,17 @@ IMPL_LINK( SdNavigatorWin, MenuSelectHdl, Menu *, pMenu, bool )
     if( pMenu )
         nMenuId = pMenu->GetCurItemId();
     else
-        nMenuId = NAVIGATOR_DRAGTYPE_URL;
+        nMenuId = static_cast< sal_uInt16 >( NavigatorDragType::URL );
 
     if( nMenuId != USHRT_MAX ) // Necessary ?
     {
-        NavigatorDragType eDT = (NavigatorDragType) nMenuId;
+        NavigatorDragType eDT = static_cast< NavigatorDragType >( nMenuId );
         if( meDragType != eDT )
         {
             meDragType = eDT;
             SetDragImage();
 
-            if( meDragType == NAVIGATOR_DRAGTYPE_URL )
+            if( meDragType == NavigatorDragType::URL )
             {
                 // patch, prevents endless loop
                 if( maTlbObjects->GetSelectionCount() > 1 )
@@ -441,8 +444,7 @@ IMPL_LINK( SdNavigatorWin, ShapeFilterCallback, Menu *, pMenu, bool )
                 break;
 
             default:
-                OSL_FAIL(
-                    "SdNavigatorWin::ShapeFilterCallback called for unknown menu entry");
+                SAL_WARN( "sd", "SdNavigatorWin::ShapeFilterCallback met unknown menu entry" );
                 break;
         }
 
@@ -616,15 +618,15 @@ sal_uInt16 SdNavigatorWin::GetDragTypeSdResId( NavigatorDragType eDT, bool bImag
 {
     switch( eDT )
     {
-        case NAVIGATOR_DRAGTYPE_NONE:
+        case NavigatorDragType::None:
                 return( bImage ? 0 : STR_NONE );
-        case NAVIGATOR_DRAGTYPE_URL:
+        case NavigatorDragType::URL:
                 return( bImage ? IMG_HYPERLINK : STR_DRAGTYPE_URL );
-        case NAVIGATOR_DRAGTYPE_EMBEDDED:
+        case NavigatorDragType::Embedded:
                 return( bImage ? IMG_EMBEDDED : STR_DRAGTYPE_EMBEDDED );
-        case NAVIGATOR_DRAGTYPE_LINK:
+        case NavigatorDragType::Link:
                 return( bImage ? IMG_LINK : STR_DRAGTYPE_LINK );
-        default: OSL_FAIL( "No resource for DragType available!" );
+        default: SAL_WARN( "sd", "unexpected NavigatorDragType" ); break;
     }
     return 0;
 }
diff --git a/sd/source/ui/dlg/sdtreelb.cxx b/sd/source/ui/dlg/sdtreelb.cxx
index c0be533..543f6c4 100644
--- a/sd/source/ui/dlg/sdtreelb.cxx
+++ b/sd/source/ui/dlg/sdtreelb.cxx
@@ -1118,7 +1118,7 @@ void SdPageObjsTLB::StartDrag( sal_Int8 nAction, const Point& rPosPixel)
     if (pEntry != nullptr
         && pNavWin !=nullptr
         && pNavWin == mpParent
-        && pNavWin->GetNavigatorDragType() != NAVIGATOR_DRAGTYPE_NONE )
+        && pNavWin->GetNavigatorDragType() != NavigatorDragType::None )
     {
         // Mark only the children of the page under the mouse as drop
         // targets.  This prevents moving shapes from one page to another.
@@ -1173,7 +1173,7 @@ void SdPageObjsTLB::DoDrag()
         INetBookmark    aBookmark( aURL, GetSelectEntry() );
         sal_Int8        nDNDActions = DND_ACTION_COPYMOVE;
 
-        if( eDragType == NAVIGATOR_DRAGTYPE_LINK )
+        if( eDragType == NavigatorDragType::Link )
             nDNDActions = DND_ACTION_LINK;  // Either COPY *or* LINK, never both!
         else if (mpDoc->GetSdPageCount(PageKind::Standard) == 1)
         {
@@ -1195,7 +1195,7 @@ void SdPageObjsTLB::DoDrag()
         sd::View* pView = pViewShell->GetView();
         if (pView == nullptr)
         {
-            OSL_ASSERT(pView!=nullptr);
+            SAL_WARN( "sd", "pView from pViewShell->GetView() is nil" );
             return;
         }
 
diff --git a/sd/source/ui/view/sdview2.cxx b/sd/source/ui/view/sdview2.cxx
index ccdf2ad..2b84a6c 100644
--- a/sd/source/ui/view/sdview2.cxx
+++ b/sd/source/ui/view/sdview2.cxx
@@ -707,8 +707,8 @@ sal_Int8 View::ExecuteDrop( const ExecuteDropEvent& rEvt,
                     SdPageObjsTLB::SdPageObjsTransferable* pPageObjsTransferable = SdPageObjsTLB::SdPageObjsTransferable::getImplementation( aDataHelper.GetXTransferable() );
 
                     if( pPageObjsTransferable &&
-                        ( NAVIGATOR_DRAGTYPE_LINK == pPageObjsTransferable->GetDragType() ||
-                          NAVIGATOR_DRAGTYPE_EMBEDDED == pPageObjsTransferable->GetDragType() ) )
+                        ( NavigatorDragType::Link == pPageObjsTransferable->GetDragType() ||
+                          NavigatorDragType::Embedded == pPageObjsTransferable->GetDragType() ) )
                     {
                         // insert bookmark from own navigator (handled async. due to possible message box )
                         Application::PostUserEvent( LINK( this, View, ExecuteNavigatorDrop ),
@@ -833,7 +833,7 @@ IMPL_LINK( View, ExecuteNavigatorDrop, void*, p, void )
         /* In order t ensure unique page names, we test the ones we want to
            insert. If necessary. we put them into and replacement list (bNameOK
            == sal_False -> User canceled).  */
-        bool    bLink = pPageObjsTransferable->GetDragType() == NAVIGATOR_DRAGTYPE_LINK;
+        bool    bLink = pPageObjsTransferable->GetDragType() == NavigatorDragType::Link;
         bool    bNameOK = GetExchangeList( aExchangeList, aBookmarkList, 2 );
         bool    bReplace = false;
 
-- 
2.8.1

