[Libreoffice-commits] .: sc/inc sc/source

Libreoffice Gerrit user logerrit at kemper.freedesktop.org
Tue Jan 8 03:01:40 PST 2013


 sc/inc/cell.hxx                          |    4 +
 sc/inc/docpool.hxx                       |    1 
 sc/inc/scitems.hxx                       |   91 +++++++++++++++----------------
 sc/source/core/data/cell.cxx             |   17 +++--
 sc/source/core/data/docpool.cxx          |   23 +++++++
 sc/source/filter/excel/xicontent.cxx     |   16 +++++
 sc/source/filter/oox/worksheethelper.cxx |   29 +++++----
 sc/source/ui/view/gridwin.cxx            |   40 +++++++++----
 8 files changed, 140 insertions(+), 81 deletions(-)

New commits:
commit 92afb61d8bb1b264a945371065115981ecaed0f1
Author: Noel Power <noel.power at suse.com>
Date:   Tue Jan 8 10:56:44 2013 +0000

    support new hyperlink cell attribute
    
    Allows a hyperlink attribute to be set for a cell, allows for import of say a
    hyperlink associated with a formula cell. Since this patch does not add
    any file format support it is not possible to save such an imported hyperlink
    to ods. Note: such a hyperlink would not have been imported in the past so this
    should not be an issue
    
    Change-Id: Ieb234bb6e98e4a2630b596a90972a75be12a92d4

diff --git a/sc/inc/cell.hxx b/sc/inc/cell.hxx
index 521a28f..30ee12b 100644
--- a/sc/inc/cell.hxx
+++ b/sc/inc/cell.hxx
@@ -136,6 +136,8 @@ public:
     bool            HasValueData() const;
     bool            HasStringData() const;
     rtl::OUString   GetStringData() const;          // only real strings
+    // default implementation, creates url object from passed url
+    static EditTextObject* CreateURLObjectFromURL( ScDocument& rDoc, const OUString& rURL, const OUString& rText );
 
     static bool     CellEqual( const ScBaseCell* pCell1, const ScBaseCell* pCell2 );
 
@@ -501,7 +503,7 @@ public:
 
     void            SetErrCode( sal_uInt16 n );
     inline bool     IsHyperLinkCell() const { return pCode && pCode->IsHyperLink(); }
-    EditTextObject* CreateURLObject() ;
+    EditTextObject* CreateURLObject();
     void            GetURLResult( rtl::OUString& rURL, rtl::OUString& rCellText );
 
     /** Determines whether or not the result string contains more than one paragraph */
diff --git a/sc/inc/docpool.hxx b/sc/inc/docpool.hxx
index 6fc0335..f187a48 100644
--- a/sc/inc/docpool.hxx
+++ b/sc/inc/docpool.hxx
@@ -40,6 +40,7 @@ class SC_DLLPUBLIC ScDocumentPool: public SfxItemPool
     static sal_uInt16*  pVersionMap9;
     static sal_uInt16*  pVersionMap10;
     static sal_uInt16*  pVersionMap11;
+    static sal_uInt16*  pVersionMap12;
 
 public:
             ScDocumentPool( SfxItemPool* pSecPool = NULL, sal_Bool bLoadRefCounts = false );
diff --git a/sc/inc/scitems.hxx b/sc/inc/scitems.hxx
index 41181d1..e4e5238 100644
--- a/sc/inc/scitems.hxx
+++ b/sc/inc/scitems.hxx
@@ -108,54 +108,55 @@
 #define ATTR_SHADOW             152
 #define ATTR_VALIDDATA          153
 #define ATTR_CONDITIONAL        154
+#define ATTR_HYPERLINK          155
 
-#define ATTR_PATTERN_END        154     // end cell-attribute-pattern
+#define ATTR_PATTERN_END        155     // end cell-attribute-pattern
 
-#define ATTR_PATTERN            155
+#define ATTR_PATTERN            156
                                         // page attributes
-#define ATTR_LRSPACE            156     // editor: PageDesc-TabPage
-#define ATTR_ULSPACE            157
-#define ATTR_PAGE               158
-#define ATTR_PAGE_PAPERTRAY     159
-#define ATTR_PAGE_PAPERBIN      160
-#define ATTR_PAGE_SIZE          161
-#define ATTR_PAGE_MAXSIZE       162
-#define ATTR_PAGE_HORCENTER     163
-#define ATTR_PAGE_VERCENTER     164
-
-#define ATTR_PAGE_ON            165     // editor: header/footer-page
-#define ATTR_PAGE_DYNAMIC       166
-#define ATTR_PAGE_SHARED        167
-
-#define ATTR_PAGE_NOTES         168     // editor: table
-#define ATTR_PAGE_GRID          169
-#define ATTR_PAGE_HEADERS       170
-#define ATTR_PAGE_CHARTS        171
-#define ATTR_PAGE_OBJECTS       172
-#define ATTR_PAGE_DRAWINGS      173
-#define ATTR_PAGE_TOPDOWN       174
-#define ATTR_PAGE_SCALE         175
-#define ATTR_PAGE_SCALETOPAGES  176
-#define ATTR_PAGE_FIRSTPAGENO   177
-
-#define ATTR_PAGE_PRINTAREA     178     // editor: print areas
-#define ATTR_PAGE_REPEATROW     179
-#define ATTR_PAGE_REPEATCOL     180
-#define ATTR_PAGE_PRINTTABLES   181
-
-#define ATTR_PAGE_HEADERLEFT    182     // contents of header/
-#define ATTR_PAGE_FOOTERLEFT    183     // footer (left)
-#define ATTR_PAGE_HEADERRIGHT   184     // contents of header/
-#define ATTR_PAGE_FOOTERRIGHT   185     // footer (right)
-#define ATTR_PAGE_HEADERSET     186     // the corresponding sets
-#define ATTR_PAGE_FOOTERSET     187
-
-#define ATTR_PAGE_FORMULAS      188
-#define ATTR_PAGE_NULLVALS      189
-
-#define ATTR_PAGE_SCALETO       190     // #i8868# scale printout to width/height
-
-#define ATTR_HIDDEN             191
+#define ATTR_LRSPACE            157     // editor: PageDesc-TabPage
+#define ATTR_ULSPACE            158
+#define ATTR_PAGE               159
+#define ATTR_PAGE_PAPERTRAY     160
+#define ATTR_PAGE_PAPERBIN      161
+#define ATTR_PAGE_SIZE          162
+#define ATTR_PAGE_MAXSIZE       163
+#define ATTR_PAGE_HORCENTER     164
+#define ATTR_PAGE_VERCENTER     165
+
+#define ATTR_PAGE_ON            166     // editor: header/footer-page
+#define ATTR_PAGE_DYNAMIC       167
+#define ATTR_PAGE_SHARED        168
+
+#define ATTR_PAGE_NOTES         169     // editor: table
+#define ATTR_PAGE_GRID          170
+#define ATTR_PAGE_HEADERS       171
+#define ATTR_PAGE_CHARTS        172
+#define ATTR_PAGE_OBJECTS       173
+#define ATTR_PAGE_DRAWINGS      174
+#define ATTR_PAGE_TOPDOWN       175
+#define ATTR_PAGE_SCALE         176
+#define ATTR_PAGE_SCALETOPAGES  177
+#define ATTR_PAGE_FIRSTPAGENO   178
+
+#define ATTR_PAGE_PRINTAREA     179     // editor: print areas
+#define ATTR_PAGE_REPEATROW     180
+#define ATTR_PAGE_REPEATCOL     181
+#define ATTR_PAGE_PRINTTABLES   182
+
+#define ATTR_PAGE_HEADERLEFT    183     // contents of header/
+#define ATTR_PAGE_FOOTERLEFT    184     // footer (left)
+#define ATTR_PAGE_HEADERRIGHT   185     // contents of header/
+#define ATTR_PAGE_FOOTERRIGHT   186     // footer (right)
+#define ATTR_PAGE_HEADERSET     187     // the corresponding sets
+#define ATTR_PAGE_FOOTERSET     188
+
+#define ATTR_PAGE_FORMULAS      189
+#define ATTR_PAGE_NULLVALS      190
+
+#define ATTR_PAGE_SCALETO       191     // #i8868# scale printout to width/height
+
+#define ATTR_HIDDEN             192
 
 #define ATTR_ENDINDEX           ATTR_HIDDEN        // end of pool-range
 
diff --git a/sc/source/core/data/cell.cxx b/sc/source/core/data/cell.cxx
index 3718976..ce073e2 100644
--- a/sc/source/core/data/cell.cxx
+++ b/sc/source/core/data/cell.cxx
@@ -610,6 +610,16 @@ bool ScBaseCell::CellEqual( const ScBaseCell* pCell1, const ScBaseCell* pCell2 )
     return false;
 }
 
+EditTextObject* ScBaseCell::CreateURLObjectFromURL( ScDocument& rDoc, const OUString& rURL, const OUString& rText )
+{
+    SvxURLField aUrlField( rURL, rText, SVXURLFORMAT_APPDEFAULT);
+    EditEngine& rEE = rDoc.GetEditEngine();
+    rEE.SetText( EMPTY_STRING );
+    rEE.QuickInsertField( SvxFieldItem( aUrlField, EE_FEATURE_FIELD ), ESelection( 0xFFFF, 0xFFFF ) );
+
+    return rEE.CreateTextObject();
+}
+
 // ============================================================================
 
 ScNoteCell::ScNoteCell( SvtBroadcaster* pBC ) :
@@ -1979,12 +1989,7 @@ EditTextObject* ScFormulaCell::CreateURLObject()
     rtl::OUString aURL;
     GetURLResult( aURL, aCellText );
 
-    SvxURLField aUrlField( aURL, aCellText, SVXURLFORMAT_APPDEFAULT);
-    EditEngine& rEE = pDocument->GetEditEngine();
-    rEE.SetText( EMPTY_STRING );
-    rEE.QuickInsertField( SvxFieldItem( aUrlField, EE_FEATURE_FIELD ), ESelection( 0xFFFF, 0xFFFF ) );
-
-    return rEE.CreateTextObject();
+    return CreateURLObjectFromURL( *pDocument, aURL, aCellText );
 }
 
 // ============================================================================
diff --git a/sc/source/core/data/docpool.cxx b/sc/source/core/data/docpool.cxx
index 20044fe..7e422db 100644
--- a/sc/source/core/data/docpool.cxx
+++ b/sc/source/core/data/docpool.cxx
@@ -24,6 +24,7 @@
 #include <vcl/outdev.hxx>
 #include <svl/aeitem.hxx>
 #include <svl/itemiter.hxx>
+#include <svl/stritem.hxx>
 #include <svx/algitem.hxx>
 #include <editeng/boxitem.hxx>
 #include <editeng/bolnitem.hxx>
@@ -81,6 +82,7 @@ sal_uInt16* ScDocumentPool::pVersionMap8 = 0;
 sal_uInt16* ScDocumentPool::pVersionMap9 = 0;
 sal_uInt16* ScDocumentPool::pVersionMap10 = 0;
 sal_uInt16* ScDocumentPool::pVersionMap11 = 0;
+sal_uInt16* ScDocumentPool::pVersionMap12 = 0;
 
 // ATTR_FONT_TWOLINES (not used) was changed to ATTR_USERDEF (not saved in binary format) in 641c
 
@@ -141,6 +143,7 @@ static SfxItemInfo const  aItemInfos[] =
     { SID_ATTR_BORDER_SHADOW,       SFX_ITEM_POOLABLE },    // ATTR_SHADOW
     { 0,                            SFX_ITEM_POOLABLE },    // ATTR_VALIDDATA
     { 0,                            SFX_ITEM_POOLABLE },    // ATTR_CONDITIONAL
+    { 0,                            SFX_ITEM_POOLABLE },    // ATTR_HYPERLINK
     { 0,                            SFX_ITEM_POOLABLE },    // ATTR_PATTERN
     { SID_ATTR_LRSPACE,             SFX_ITEM_POOLABLE },    // ATTR_LRSPACE
     { SID_ATTR_ULSPACE,             SFX_ITEM_POOLABLE },    // ATTR_ULSPACE
@@ -279,6 +282,7 @@ ScDocumentPool::ScDocumentPool( SfxItemPool* pSecPool, sal_Bool bLoadRefCounts )
     ppPoolDefaults[ ATTR_SHADOW          - ATTR_STARTINDEX ] = new SvxShadowItem( ATTR_SHADOW );
     ppPoolDefaults[ ATTR_VALIDDATA       - ATTR_STARTINDEX ] = new SfxUInt32Item( ATTR_VALIDDATA, 0 );
     ppPoolDefaults[ ATTR_CONDITIONAL     - ATTR_STARTINDEX ] = new ScCondFormatItem;
+    ppPoolDefaults[ ATTR_HYPERLINK       - ATTR_STARTINDEX ] = new SfxStringItem( ATTR_HYPERLINK, rtl::OUString() ) ;
 
     //  GetRscString funktioniert erst nach ScGlobal::Init, zu erkennen am EmptyBrushItem
     //! zusaetzliche Methode ScGlobal::IsInit() oder so...
@@ -366,6 +370,8 @@ ScDocumentPool::ScDocumentPool( SfxItemPool* pSecPool, sal_Bool bLoadRefCounts )
 
     // ATTR_FONT_OVERLINE added in DEV300/overline2
     SetVersionMap( 11, 100, 187, pVersionMap11 );
+    // ATTR_HYERLINK added
+    SetVersionMap( 12, 100, 192, pVersionMap12 );
 }
 
 ScDocumentPool::~ScDocumentPool()
@@ -389,7 +395,7 @@ void ScDocumentPool::InitVersionMaps()
                 !pVersionMap5 && !pVersionMap6 &&
                 !pVersionMap7 && !pVersionMap8 &&
                 !pVersionMap9 && !pVersionMap10 &&
-                !pVersionMap11, "InitVersionMaps call multiple times" );
+                !pVersionMap11 && !pVersionMap12 , "InitVersionMaps call multiple times" );
 
     // alte WhichId's mappen
     // nicht mit ATTR_* zaehlen, falls die sich nochmal aendern
@@ -539,6 +545,17 @@ void ScDocumentPool::InitVersionMaps()
     // 1 entry inserted
     for ( i=nMap11New, j=nMap11Start+nMap11New+1; i < nMap11Count; i++, j++ )
         pVersionMap11[i] = j;
+
+    const sal_uInt16 nMap12Start = 100;  // ATTR_STARTINDEX
+    const sal_uInt16 nMap12End   = 192;  // ATTR_ENDINDEX
+    const sal_uInt16 nMap12Count = nMap12End - nMap12Start + 1;
+    const sal_uInt16 nMap12New   = 55;    // ATTR_HYPERLINK - ATTR_STARTINDEX
+    pVersionMap12 = new sal_uInt16 [ nMap12Count ];
+    for ( i=0, j=nMap12Start; i < nMap12New; i++, j++ )
+        pVersionMap12[i] = j;
+    // 1 entry inserted
+    for ( i=nMap12New, j=nMap12Start+nMap12New+1; i < nMap12Count; i++, j++ )
+        pVersionMap12[i] = j;
 }
 
 void ScDocumentPool::DeleteVersionMaps()
@@ -548,8 +565,10 @@ void ScDocumentPool::DeleteVersionMaps()
                 pVersionMap5 && pVersionMap6 &&
                 pVersionMap7 && pVersionMap8 &&
                 pVersionMap9 && pVersionMap10 &&
-                pVersionMap11, "DeleteVersionMaps without maps" );
+                pVersionMap11 && pVersionMap12 , "DeleteVersionMaps without maps" );
 
+    delete[] pVersionMap12;
+    pVersionMap12 = 0;
     delete[] pVersionMap11;
     pVersionMap11 = 0;
     delete[] pVersionMap10;
diff --git a/sc/source/filter/excel/xicontent.cxx b/sc/source/filter/excel/xicontent.cxx
index 7e09fb4..2a7b5ff 100644
--- a/sc/source/filter/excel/xicontent.cxx
+++ b/sc/source/filter/excel/xicontent.cxx
@@ -205,7 +205,21 @@ void lclInsertUrl( const XclImpRoot& rRoot, const String& rUrl, SCCOL nScCol, SC
         }
         break;
 
-        default:;
+        default:
+        // Handle other cell types e.g. formulas ( and ? ) that have associated
+        // hyperlinks.
+        // Ideally all hyperlinks should be treated  as below. For the moment,
+        // given the current absence of ods support lets just handle what we
+        // previously didn't handle the new way.
+        // Unfortunately we won't be able to preserve such hyperlinks when
+        // saving to ods. Note: when we are able to save such hyperlinks to ods
+        // we should handle *all* imported hyperlinks as below ( e.g. as cell
+        // attribute ) for better interoperability.
+        {
+            SfxStringItem aItem( ATTR_HYPERLINK, rUrl );
+            rDoc.ApplyAttr( nScCol, nScRow, nScTab, aItem );
+            break;
+        }
     }
 }
 
diff --git a/sc/source/filter/oox/worksheethelper.cxx b/sc/source/filter/oox/worksheethelper.cxx
index fbb4dd2..449306a 100644
--- a/sc/source/filter/oox/worksheethelper.cxx
+++ b/sc/source/filter/oox/worksheethelper.cxx
@@ -66,6 +66,8 @@
 #include "worksheetbuffer.hxx"
 #include "worksheetsettings.hxx"
 #include "formulabuffer.hxx"
+#include "scitems.hxx"
+#include <svl/stritem.hxx>
 
 namespace oox {
 namespace xls {
@@ -1039,22 +1041,21 @@ void WorksheetGlobals::insertHyperlink( const CellAddress& rAddress, const OUStr
             }
         }
         break;
-
-        // fix for #i31050# disabled, HYPERLINK is not able to return numeric value (#i91351#)
-#if 0
-        // #i31050# replace number with HYPERLINK function
-        case CellContentType_VALUE:
+        // Handle other cell types e.g. formulas ( and ? ) that have associated
+        // hyperlinks.
+        // Ideally all hyperlinks should be treated  as below. For the moment,
+        // given the current absence of ods support lets just handle what we
+        // previously didn't handle the new way.
+        // Unfortunately we won't be able to preserve such hyperlinks when
+        // saving to ods. Note: when we are able to save such hyperlinks to ods
+        // we should handle *all* imported hyperlinks as below ( e.g. as cell
+        // attribute ) for better interoperability.
+        default:
         {
-            Reference< XFormulaTokens > xTokens( xCell, UNO_QUERY );
-            ApiTokenSequence aTokens = getFormulaParser().convertNumberToHyperlink( rUrl, xCell->getValue() );
-            OSL_ENSURE( xTokens.is(), "WorksheetHelper::insertHyperlink - missing formula token interface" );
-            if( xTokens.is() && aTokens.hasElements() )
-                xTokens->setTokens( aTokens );
+            SfxStringItem aItem( ATTR_HYPERLINK, rUrl );
+            getScDocument().ApplyAttr( static_cast< SCCOL >( rAddress.Column ), static_cast< SCROW >( rAddress.Row ), static_cast< SCTAB >( rAddress.Sheet ), aItem );
+            break;
         }
-        break;
-#endif
-
-        default:;
     }
 }
 
diff --git a/sc/source/ui/view/gridwin.cxx b/sc/source/ui/view/gridwin.cxx
index 620d625..96edbcb 100644
--- a/sc/source/ui/view/gridwin.cxx
+++ b/sc/source/ui/view/gridwin.cxx
@@ -378,7 +378,7 @@ static void lcl_UnLockComment( ScDrawView* pView, SdrPageView* pPV, SdrModel* pD
     }
 }
 
-static sal_Bool lcl_GetHyperlinkCell(ScDocument* pDoc, SCCOL& rPosX, SCROW& rPosY, SCTAB nTab, ScBaseCell*& rpCell )
+static sal_Bool lcl_GetHyperlinkCell(ScDocument* pDoc, SCCOL& rPosX, SCROW& rPosY, SCTAB nTab, ScBaseCell*& rpCell, OUString& rURL )
 {
     sal_Bool bFound = false;
     do
@@ -391,13 +391,22 @@ static sal_Bool lcl_GetHyperlinkCell(ScDocument* pDoc, SCCOL& rPosX, SCROW& rPos
             else
                 --rPosX;                                // weitersuchen
         }
-                else if ( rpCell->GetCellType() == CELLTYPE_EDIT)
-                    bFound = sal_True;
-                else if (rpCell->GetCellType() == CELLTYPE_FORMULA &&
-                  static_cast<ScFormulaCell*>(rpCell)->IsHyperLinkCell())
-                    bFound = sal_True;
         else
-            return false;                               // andere Zelle
+        {
+            const ScPatternAttr* pPattern = pDoc->GetPattern( rPosX, rPosY, nTab );
+            if ( ((SfxStringItem&)pPattern->GetItem(ATTR_HYPERLINK)).GetValue().Len() > 0 )
+            {
+                rURL =  ((SfxStringItem&)pPattern->GetItem(ATTR_HYPERLINK)).GetValue();
+                bFound = true;
+            }
+            else if ( rpCell->GetCellType() == CELLTYPE_EDIT)
+                bFound = sal_True;
+            else if (rpCell->GetCellType() == CELLTYPE_FORMULA &&
+                static_cast<ScFormulaCell*>(rpCell)->IsHyperLinkCell())
+                bFound = sal_True;
+            else
+                return false;                               // andere Zelle
+        }
     }
     while ( !bFound );
 
@@ -2305,7 +2314,8 @@ void ScGridWindow::MouseButtonUp( const MouseEvent& rMEvt )
                 SCTAB nTab = pViewData->GetTabNo();
                 pViewData->GetPosFromPixel( aPos.X(), aPos.Y(), eWhich, nPosX, nPosY );
                 ScBaseCell* pCell = NULL;
-                if( lcl_GetHyperlinkCell( pDoc, nPosX, nPosY, nTab, pCell ) )
+                OUString sURL;
+                if( lcl_GetHyperlinkCell( pDoc, nPosX, nPosY, nTab, pCell, sURL ) )
                 {
                     ScAddress aCellPos( nPosX, nPosY, nTab );
                     uno::Reference< table::XCell > xCell( new ScCellObj( pViewData->GetDocShell(), aCellPos ) );
@@ -5016,8 +5026,8 @@ bool ScGridWindow::GetEditUrlOrError( bool bSpellErr, const Point& rPos,
     ScDocShell* pDocSh = pViewData->GetDocShell();
     ScDocument* pDoc = pDocSh->GetDocument();
     ScBaseCell* pCell = NULL;
-
-    sal_Bool bFound = lcl_GetHyperlinkCell( pDoc, nPosX, nPosY, nTab, pCell );
+    OUString sURL;
+    sal_Bool bFound = lcl_GetHyperlinkCell( pDoc, nPosX, nPosY, nTab, pCell, sURL );
     if( !bFound )
         return false;
 
@@ -5094,9 +5104,15 @@ bool ScGridWindow::GetEditUrlOrError( bool bSpellErr, const Point& rPos,
         if (pData)
             aEngine.SetText(*pData);
     }
-    else  // HyperLink Formula cell
+    else  // Not an Edit cell and is a formula cell with 'Hyperlink'
+          // function if we have no URL, otherwise it could be a formula
+          // cell ( or other type ? ) with a hyperlink associated with it.
     {
-        pTextObj.reset((static_cast<ScFormulaCell*>(pCell))->CreateURLObject());
+        if (  sURL.isEmpty() )
+            pTextObj.reset((static_cast<ScFormulaCell*>(pCell))->CreateURLObject());
+        else
+            pTextObj.reset( ScBaseCell::CreateURLObjectFromURL( *pDoc, sURL, sURL ) );
+
         if (pTextObj.get())
             aEngine.SetText(*pTextObj);
     }


More information about the Libreoffice-commits mailing list