summaryrefslogtreecommitdiff
path: root/svtools
diff options
context:
space:
mode:
authorMarco Cecchetti <mrcekets@gmail.com>2011-04-14 12:36:44 +0200
committerCédric Bosdonnat <cedricbosdo@openoffice.org>2011-04-15 11:04:05 +0200
commitf82a46dabeb431fc199aa4b43766115184844efe (patch)
treef9b1ded1bcc35fc11d4c93cf9e171f223e4c1d1f /svtools
parent4fc170d3e8d0bb05197deb57f60d85f9fd9f0f72 (diff)
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.
Diffstat (limited to 'svtools')
-rw-r--r--svtools/inc/svtools/ctrlbox.hxx12
-rw-r--r--svtools/source/control/ctrlbox.cxx76
2 files changed, 86 insertions, 2 deletions
diff --git a/svtools/inc/svtools/ctrlbox.hxx b/svtools/inc/svtools/ctrlbox.hxx
index 8678b770dc6e..56c69e0d078b 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 889a3a89c3e0..eddc8d3eb35a 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