Commits

Anonymous committed ed0fec8

vcl116: #i88218# cleanup, make field unit strings more robust

  • Participants
  • Parent commits d73a3d3

Comments (0)

Files changed (3)

File vcl/inc/vcl/svdata.hxx

 #ifndef _SV_SVDATA_HXX
 #define _SV_SVDATA_HXX
 
-#ifndef _VOS_THREAD_HXX
-#include <vos/thread.hxx>
-#endif
-#include <tools/string.hxx>
-#include <tools/gen.hxx>
-#include <tools/shl.hxx>
-#include <tools/link.hxx>
-#include <vcl/vclevent.hxx>
-#include <vcl/sv.h>
-#include <tools/color.hxx>
-#include <tools/debug.hxx>
-#include <vcl/dllapi.h>
-#include <com/sun/star/uno/Reference.hxx>
-#include <unotools/options.hxx>
+#include "vos/thread.hxx"
+#include "tools/string.hxx"
+#include "tools/gen.hxx"
+#include "tools/shl.hxx"
+#include "tools/link.hxx"
+#include "tools/fldunit.hxx"
+#include "vcl/vclevent.hxx"
+#include "vcl/sv.h"
+#include "tools/color.hxx"
+#include "tools/debug.hxx"
+#include "vcl/dllapi.h"
+#include "com/sun/star/uno/Reference.hxx"
+#include "unotools/options.hxx"
 
 namespace com {
 namespace sun {
 // - ImplSVCtrlData -
 // ------------------
 
+typedef std::vector< std::pair< String, FieldUnit > > FieldUnitStringList;
+
 struct ImplSVCtrlData
 {
     ImageList*              mpCheckImgList;     // ImageList for CheckBoxes
     ULONG                   mnLastRadioFColor;  // Letzte FaceColor fuer RadioImage
     ULONG                   mnLastRadioWColor;  // Letzte WindowColor fuer RadioImage
     ULONG                   mnLastRadioLColor;  // Letzte LightColor fuer RadioImage
+    FieldUnitStringList*    mpFieldUnitStrings; // list with field units
+    FieldUnitStringList*    mpCleanUnitStrings; // same list but with some "fluff" like spaces removed
 };
 
 
 
 bool ImplInitAccessBridge( BOOL bAllowCancel, BOOL &rCancelled );
 
+FieldUnitStringList* ImplGetFieldUnits();
+FieldUnitStringList* ImplGetCleanedFieldUnits();
+
+
 // -----------------------------------------------------------------------
 
 // -----------------

File vcl/source/app/svdata.cxx

 
 // MARKER(update_precomp.py): autogen include statement, do not remove
 #include "precompiled_vcl.hxx"
+
 #include <string.h>
 
-#ifndef _SV_SVSYS_HXX
-#include <svsys.h>
-#endif
-#include <vcl/salinst.hxx>
-#include <vcl/salframe.hxx>
+#include "rtl/instance.hxx"
+#include "osl/process.h"
+#include "osl/file.hxx"
 
-#ifndef _VOS_MUTEX_HXX
-#include <vos/mutex.hxx>
-#endif
+#include "svsys.h"
 
-#include <osl/process.h>
-#include <osl/file.hxx>
-#include <uno/current_context.hxx>
-#include <cppuhelper/implbase1.hxx>
-#include <tools/debug.hxx>
-#include <unotools/fontcfg.hxx>
-#include <vcl/configsettings.hxx>
-#include <vcl/svdata.hxx>
-#include <vcl/window.h>
-#include <vcl/svapp.hxx>
-#include <vcl/wrkwin.hxx>
-#include <vcl/msgbox.hxx>
-#include <vcl/unohelp.hxx>
-#include <vcl/button.hxx> // for Button::GetStandardText
-#include <vcl/dockwin.hxx>  // for DockingManager
-#include <vcl/salimestatus.hxx>
-#include <com/sun/star/lang/XMultiServiceFactory.hpp>
-#include <com/sun/star/awt/XExtendedToolkit.hpp>
-#include <com/sun/star/java/JavaNotConfiguredException.hpp>
-#include <com/sun/star/java/JavaVMCreationFailureException.hpp>
-#include <com/sun/star/java/MissingJavaRuntimeException.hpp>
-#include <com/sun/star/java/JavaDisabledException.hpp>
+#include "tools/debug.hxx"
+#include "tools/resary.hxx"
 
-#include <com/sun/star/lang/XComponent.hpp>
+#include "vcl/salinst.hxx"
+#include "vcl/salframe.hxx"
+#include "vcl/configsettings.hxx"
+#include "vcl/svdata.hxx"
+#include "vcl/window.h"
+#include "vcl/svapp.hxx"
+#include "vcl/wrkwin.hxx"
+#include "vcl/msgbox.hxx"
+#include "vcl/unohelp.hxx"
+#include "vcl/button.hxx" // for Button::GetStandardText
+#include "vcl/dockwin.hxx"  // for DockingManager
+#include "vcl/salimestatus.hxx"
+#include "vcl/salsys.hxx"
+#include "vcl/svids.hrc"
+
+#include "unotools/fontcfg.hxx"
+
+#include "vos/mutex.hxx"
+
+#include "cppuhelper/implbase1.hxx"
+#include "uno/current_context.hxx"
+
+#include "com/sun/star/lang/XMultiServiceFactory.hpp"
+#include "com/sun/star/lang/XComponent.hpp"
+#include "com/sun/star/awt/XExtendedToolkit.hpp"
+#include "com/sun/star/java/JavaNotConfiguredException.hpp"
+#include "com/sun/star/java/JavaVMCreationFailureException.hpp"
+#include "com/sun/star/java/MissingJavaRuntimeException.hpp"
+#include "com/sun/star/java/JavaDisabledException.hpp"
 
 #include <stdio.h>
-#include <vcl/salsys.hxx>
-#include <vcl/svids.hrc>
-#include <rtl/instance.hxx>
 
 using namespace com::sun::star::uno;
 using namespace com::sun::star::lang;
         delete pSVData->maAppData.mpMSFTempFileName;
         pSVData->maAppData.mpMSFTempFileName = NULL;
     }
+    
+    if( pSVData->maCtrlData.mpFieldUnitStrings )
+        delete pSVData->maCtrlData.mpFieldUnitStrings, pSVData->maCtrlData.mpFieldUnitStrings = NULL;
+    if( pSVData->maCtrlData.mpCleanUnitStrings )
+        delete pSVData->maCtrlData.mpCleanUnitStrings, pSVData->maCtrlData.mpCleanUnitStrings = NULL;
 }
 
 // -----------------------------------------------------------------------
     return ResId( nId, *pMgr );
 }
 
+FieldUnitStringList* ImplGetFieldUnits()
+{
+    ImplSVData* pSVData = ImplGetSVData();
+    if( ! pSVData->maCtrlData.mpFieldUnitStrings )
+    {
+        ResMgr* pResMgr = ImplGetResMgr();
+        if( pResMgr )
+        {
+            ResStringArray aUnits( ResId (SV_FUNIT_STRINGS, *pResMgr) );
+            sal_uInt32 nUnits = aUnits.Count();
+            pSVData->maCtrlData.mpFieldUnitStrings = new FieldUnitStringList();
+            pSVData->maCtrlData.mpFieldUnitStrings->reserve( nUnits );
+            for( sal_uInt32 i = 0; i < nUnits; i++ )
+            {
+                std::pair< String, FieldUnit > aElement( aUnits.GetString(i), static_cast<FieldUnit>(aUnits.GetValue(i)) );
+                pSVData->maCtrlData.mpFieldUnitStrings->push_back( aElement );
+            }
+        }
+    }
+    return pSVData->maCtrlData.mpFieldUnitStrings;
+}
+
+FieldUnitStringList* ImplGetCleanedFieldUnits()
+{
+    ImplSVData* pSVData = ImplGetSVData();
+    if( ! pSVData->maCtrlData.mpCleanUnitStrings )
+    {
+        FieldUnitStringList* pUnits = ImplGetFieldUnits();
+        if( pUnits )
+        {
+            size_t nUnits = pUnits->size();
+            pSVData->maCtrlData.mpCleanUnitStrings = new FieldUnitStringList();
+            pSVData->maCtrlData.mpCleanUnitStrings->reserve( nUnits );
+            for( size_t i = 0; i < nUnits; i++ )
+            {
+                String aUnit( (*pUnits)[i].first );
+                aUnit.EraseAllChars( sal_Unicode( ' ' ) );
+                aUnit.ToLowerAscii();
+                std::pair< String, FieldUnit > aElement( aUnit, (*pUnits)[i].second );
+                pSVData->maCtrlData.mpCleanUnitStrings->push_back( aElement );
+            }
+        }
+    }
+    return pSVData->maCtrlData.mpCleanUnitStrings;
+}
+
 DockingManager* ImplGetDockingManager()
 {
     ImplSVData* pSVData = ImplGetSVData();

File vcl/source/control/field.cxx

 
 using namespace ::com::sun::star;
 
-static ResStringArray *strAllUnits = NULL;
-
 // -----------------------------------------------------------------------
 
 #define FORMAT_NUMERIC       1
 
 // #104355# support localized mesaurements
 
-static String ImplMetricToString( FieldUnit rUnit )
+static const String& ImplMetricToString( FieldUnit rUnit )
 {
-    if( !strAllUnits )
+    FieldUnitStringList* pList = ImplGetFieldUnits();
+    if( pList )
     {
-        ResMgr* pResMgr = ImplGetResMgr();
-        strAllUnits = new ResStringArray( ResId (SV_FUNIT_STRINGS, *pResMgr) );
+        // return unit's default string (ie, the first one )
+        for( FieldUnitStringList::const_iterator it = pList->begin(); it != pList->end(); ++it )
+        {
+            if ( it->second == rUnit )
+                return it->first;
+        }
     }
-    // return unit's default string (ie, the first one )
-    for( USHORT i=0; i < strAllUnits->Count(); i++ )
-        if( (FieldUnit) strAllUnits->GetValue( i ) == rUnit )
-            return strAllUnits->GetString( i );
-
-    return String();
+
+    return String::EmptyString();
 }
 
 static FieldUnit ImplStringToMetric( const String &rMetricString )
 {
-    if( !strAllUnits )
+    FieldUnitStringList* pList = ImplGetCleanedFieldUnits();
+    if( pList )
     {
-        ResMgr* pResMgr = ImplGetResMgr();
-        strAllUnits = new ResStringArray( ResId (SV_FUNIT_STRINGS, *pResMgr) );
+        // return FieldUnit
+        String aStr( rMetricString );
+        aStr.ToLowerAscii();
+        aStr.EraseAllChars( sal_Unicode( ' ' ) );
+        for( FieldUnitStringList::const_iterator it = pList->begin(); it != pList->end(); ++it )
+        {
+            if ( it->first.Equals( aStr ) )
+                return it->second;
+        }
     }
-    // return FieldUnit
-    String aStr( rMetricString );
-    aStr.ToLowerAscii();
-    for( USHORT i=0; i < strAllUnits->Count(); i++ )
-        if ( strAllUnits->GetString( i ).Equals( aStr ) )
-            return (FieldUnit) strAllUnits->GetValue( i );
 
     return FUNIT_NONE;
 }