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

Cédric Bosdonnat cbosdo at kemper.freedesktop.org
Fri Apr 15 02:05:22 PDT 2011


 svtools/inc/svtools/ctrlbox.hxx    |   12 ++++-
 svtools/source/control/ctrlbox.cxx |   76 +++++++++++++++++++++++++++++++++++++
 2 files changed, 86 insertions(+), 2 deletions(-)

New commits:
commit fb5cde5389879620ad237fc22da863948d5b1277
Author: Marco Cecchetti <mrcekets at gmail.com>
Date:   Thu Apr 14 12:36:44 2011 +0200

    Hack: store/restore font name box mru entries
    
    When a LibreOffice window with a FontNameBox control is closed the
    list of mru entries for the control is stored in a file,
    discarding the previous saved entry list; when a document is opened or
    created the last saved mru entry list for the FontNameBox control is
    restored.

diff --git a/svtools/inc/svtools/ctrlbox.hxx b/svtools/inc/svtools/ctrlbox.hxx
index 267a104..90f52b6 100644
--- a/svtools/inc/svtools/ctrlbox.hxx
+++ b/svtools/inc/svtools/ctrlbox.hxx
@@ -31,6 +31,7 @@
 
 #include "svtools/svtdllapi.h"
 
+#include <tools/string.hxx>
 #include <vcl/lstbox.hxx>
 #include <vcl/combobox.hxx>
 #include <vcl/image.hxx>
@@ -56,6 +57,8 @@ typedef ::std::vector< ImplFontNameListData* > ImplFontList;
 #define CHANGE_DIST                ( ( sal_uInt16 ) 4 )
 #define ADAPT_DIST                 ( ( sal_uInt16 ) 8 )
 
+
+
 /*************************************************************************
 
 Beschreibung
@@ -461,8 +464,9 @@ private:
     Image			maImagePrinterFont;
     Image			maImageBitmapFont;
     Image			maImageScalableFont;
-    sal_Bool			mbWYSIWYG;
-    sal_Bool			mbSymbols;
+    sal_Bool		mbWYSIWYG;
+    sal_Bool		mbSymbols;
+    String         maFontMRUEntriesFile;
 
 #ifdef _CTRLBOX_CXX
     SVT_DLLPRIVATE void			ImplCalcUserItemSize();
@@ -472,6 +476,8 @@ private:
     void			InitBitmaps( void );
 protected:
     virtual void	DataChanged( const DataChangedEvent& rDCEvt );
+    void			LoadMRUEntries( const String& aFontMRUEntriesFile, xub_Unicode cSep = ';' );
+    void			SaveMRUEntries( const String& aFontMRUEntriesFile, xub_Unicode cSep = ';' ) const;
 public:
                     FontNameBox( Window* pParent,
                                  WinBits nWinStyle = WB_SORT );
@@ -489,6 +495,8 @@ public:
     sal_Bool			IsSymbolsEnabled() const { return mbSymbols; }
 
 private:
+    void            InitFontMRUEntriesFile();
+
     // declared as private because some compilers would generate the default functions
                     FontNameBox( const FontNameBox& );
     FontNameBox&	operator =( const FontNameBox& );
diff --git a/svtools/source/control/ctrlbox.cxx b/svtools/source/control/ctrlbox.cxx
index 9305e18..1333e7b 100644
--- a/svtools/source/control/ctrlbox.cxx
+++ b/svtools/source/control/ctrlbox.cxx
@@ -31,8 +31,10 @@
 
 #define _CTRLBOX_CXX
 #include <tools/debug.hxx>
+#include <tools/stream.hxx>
 #include <vcl/svapp.hxx>
 #include <vcl/field.hxx>
+#include <vcl/helper.hxx>
 #include <sal/macros.h>
 #include <comphelper/processfactory.hxx>
 #include <unotools/charclass.hxx>
@@ -48,6 +50,10 @@
 #include <basegfx/polygon/b2dpolygon.hxx>
 #include <basegfx/polygon/b2dpolygontools.hxx>
 
+#if OSL_DEBUG_LEVEL > 1
+#include <cstdio>
+#endif
+
 #define IMGINNERTEXTSPACE 2
 #define IMGOUTERTEXTSPACE 5
 #define EXTRAFONTSIZE 5
@@ -56,7 +62,10 @@
 #define TWIPS_TO_PT100(val) (val * 5)
 #define PT100_TO_TWIPS(val) (val / 5)
 
+#define FONTNAMEBOXMRUENTRIESFILE "/user/config/fontnameboxmruentries"
+
 using namespace ::com::sun::star;
+using namespace psp;
 
 // ========================================================================
 // ColorListBox
@@ -986,6 +995,7 @@ FontNameBox::FontNameBox( Window* pParent, WinBits nWinStyle ) :
     mpFontList = NULL;
     mbWYSIWYG = sal_False;
     mbSymbols = sal_False;
+    InitFontMRUEntriesFile();
 }
 
 // -------------------------------------------------------------------
@@ -997,12 +1007,14 @@ FontNameBox::FontNameBox( Window* pParent, const ResId& rResId ) :
     mpFontList = NULL;
     mbWYSIWYG = sal_False;
     mbSymbols = sal_False;
+    InitFontMRUEntriesFile();
 }
 
 // -------------------------------------------------------------------
 
 FontNameBox::~FontNameBox()
 {
+    SaveMRUEntries (maFontMRUEntriesFile);
     ImplDestroyFontList();
 }
 
@@ -1018,6 +1030,63 @@ void FontNameBox::DataChanged( const DataChangedEvent& rDCEvt )
 
 // -------------------------------------------------------------------
 
+void FontNameBox::SaveMRUEntries( const String& aFontMRUEntriesFile, xub_Unicode cSep ) const
+{
+    ByteString aEntries =  ByteString( GetMRUEntries( cSep ), RTL_TEXTENCODING_UTF8 );
+
+    if( ! aEntries.Len() || ! aFontMRUEntriesFile.Len() )
+        return;
+
+    SvFileStream aStream;
+    aStream.Open( aFontMRUEntriesFile, STREAM_WRITE | STREAM_TRUNC );
+    if( ! (aStream.IsOpen() && aStream.IsWritable()) )
+    {
+#if OSL_DEBUG_LEVEL > 1
+        fprintf( stderr, "FontNameBox::SaveMRUEntries: opening mru entries file %s failed\n", ByteString(aFontMRUEntriesFile , RTL_TEXTENCODING_UTF8 ).GetBuffer() );
+#endif
+        return;
+    }
+
+    aStream.SetLineDelimiter( LINEEND_LF );
+    aStream.WriteLine( aEntries );
+    aStream.WriteLine( ByteString() );
+}
+
+// -------------------------------------------------------------------
+
+void FontNameBox::LoadMRUEntries( const String& aFontMRUEntriesFile, xub_Unicode cSep )
+{
+    if( ! aFontMRUEntriesFile.Len() )
+        return;
+
+    SvFileStream aStream( aFontMRUEntriesFile, STREAM_READ );
+    if( ! aStream.IsOpen() )
+    {
+#if OSL_DEBUG_LEVEL > 1
+        fprintf( stderr, "FontNameBox::LoadMRUEntries: opening mru entries file %s failed\n", ByteString( aFontMRUEntriesFile, RTL_TEXTENCODING_UTF8 ).GetBuffer() );
+#endif
+        return;
+    }
+
+    ByteString aLine;
+    aStream.ReadLine( aLine );
+    XubString aEntries = XubString( aLine, RTL_TEXTENCODING_UTF8 );
+    SetMRUEntries( aEntries, cSep );
+}
+
+// ------------------------------------------------------------------
+
+void FontNameBox::InitFontMRUEntriesFile()
+{
+    maFontMRUEntriesFile = getOfficePath( UserPath );
+    if( maFontMRUEntriesFile.Len() )
+    {
+        maFontMRUEntriesFile.AppendAscii( FONTNAMEBOXMRUENTRIESFILE );
+    }
+}
+
+// -------------------------------------------------------------------
+
 void FontNameBox::InitBitmaps( void )
 {
     maImagePrinterFont = Image( SvtResId( RID_IMG_PRINTERFONT ) );
@@ -1045,6 +1114,8 @@ void FontNameBox::Fill( const FontList* pList )
 {
     // store old text and clear box
     XubString aOldText = GetText();
+    XubString rEntries = GetMRUEntries();
+    sal_Bool bLoadFromFile = ! rEntries.Len();
     Clear();
 
     ImplDestroyFontList();
@@ -1070,6 +1141,11 @@ void FontNameBox::Fill( const FontList* pList )
         }
     }
 
+    if ( bLoadFromFile )
+        LoadMRUEntries (maFontMRUEntriesFile);
+    else
+        SetMRUEntries( rEntries );
+
     ImplCalcUserItemSize();
 
     // restore text


More information about the Libreoffice-commits mailing list