[PATCH 3/3] enable preview for 'special' '*' formats
Noel Power
noel.power at novell.com
Wed Apr 18 08:03:19 PDT 2012
---
cui/source/inc/numfmt.hxx | 3 +-
cui/source/tabpages/numfmt.cxx | 51 +++++++++++++++++++++++++++++++++++----
svl/inc/svl/zforlist.hxx | 3 +-
svl/source/numbers/zforlist.cxx | 11 +++++++-
svx/inc/svx/numfmtsh.hxx | 5 ++-
svx/source/items/numfmtsh.cxx | 12 +++++----
6 files changed, 69 insertions(+), 16 deletions(-)
diff --git a/cui/source/inc/numfmt.hxx b/cui/source/inc/numfmt.hxx
index 3a9e027..c2bde83 100644
--- a/cui/source/inc/numfmt.hxx
+++ b/cui/source/inc/numfmt.hxx
@@ -55,7 +55,8 @@ class SvxNumberPreviewImpl : public Window
private:
String aPrevStr;
Color aPrevCol;
-
+ sal_Int32 mnPos;
+ sal_Unicode mnChar;
void InitSettings( sal_Bool bForeground, sal_Bool bBackground );
protected:
diff --git a/cui/source/tabpages/numfmt.cxx b/cui/source/tabpages/numfmt.cxx
index 798da33..f847ae9 100644
--- a/cui/source/tabpages/numfmt.cxx
+++ b/cui/source/tabpages/numfmt.cxx
@@ -51,6 +51,11 @@
#include <sfx2/basedlgs.hxx>
#include "svx/flagsdef.hxx"
#include <vector>
+#include <com/sun/star/lang/XServiceInfo.hpp>
+
+using ::com::sun::star::uno::Reference;
+using ::com::sun::star::lang::XServiceInfo;
+using ::com::sun::star::uno::UNO_QUERY;
#define NUMKEY_UNDEFINED SAL_MAX_UINT32
@@ -82,8 +87,9 @@ static sal_uInt16 pRanges[] =
SvxNumberPreviewImpl::SvxNumberPreviewImpl( Window* pParent, const ResId& rResId ) :
- Window( pParent, rResId )
-
+ Window( pParent, rResId ),
+ mnPos( STRING_NOTFOUND ),
+ mnChar( 0x0 )
{
Font aFont( GetFont() );
aFont.SetTransparent( sal_True );
@@ -122,7 +128,16 @@ SvxNumberPreviewImpl::~SvxNumberPreviewImpl()
void SvxNumberPreviewImpl::NotifyChange( const String& rPrevStr,
const Color* pColor )
{
+ // detect and strip out '*' related placeholders
aPrevStr = rPrevStr;
+ mnPos = aPrevStr.Search( 0x1B );
+ if ( mnPos != STRING_NOTFOUND )
+ {
+ --mnPos;
+ mnChar = aPrevStr.GetChar( mnPos );
+ // delete placeholder and char to repeat
+ aPrevStr.Erase( mnPos, 2 );
+ }
svtools::ColorConfig aColorConfig;
Color aWindowTextColor( aColorConfig.GetColorValue( svtools::FONTCOLOR ).nColor );
aPrevCol = pColor ? *pColor : aWindowTextColor;
@@ -145,12 +160,26 @@ void SvxNumberPreviewImpl::Paint( const Rectangle& )
{
Font aDrawFont = GetFont();
Size aSzWnd = GetOutputSizePixel();
- Point aPosText = Point( (aSzWnd.Width() - GetTextWidth( aPrevStr )) /2,
- (aSzWnd.Height() - GetTextHeight())/2 );
+ String aTmpStr( aPrevStr );
+ long nLeadSpace = (aSzWnd.Width() - GetTextWidth( aTmpStr )) /2;
aDrawFont.SetColor( aPrevCol );
SetFont( aDrawFont );
- DrawText( aPosText, aPrevStr );
+
+ if ( mnPos != STRING_NOTFOUND )
+ {
+ long nCharWidth = GetTextWidth( rtl::OUString::valueOf( mnChar ) );
+ int nNumCharsToInsert = nLeadSpace / nCharWidth;
+
+ if ( nNumCharsToInsert )
+ {
+ for ( int i = 0; i < nNumCharsToInsert; ++i )
+ aTmpStr.Insert( mnChar, mnPos );
+ }
+ }
+ Point aPosText = Point( ( mnPos != STRING_NOTFOUND ) ? 0 : nLeadSpace,
+ (aSzWnd.Height() - GetTextHeight())/2 );
+ DrawText( aPosText, aTmpStr );
}
// -----------------------------------------------------------------------
@@ -523,6 +552,18 @@ void SvxNumberFormatTabPage::Reset( const SfxItemSet& rSet )
nValDouble,
&aValString );
+
+ bool bUseStarFormat = false;
+ SfxObjectShell* pDocSh = SfxObjectShell::Current();
+ if ( pDocSh )
+ {
+ // is this a calc document
+ Reference< XServiceInfo > xSI( pDocSh->GetModel(), UNO_QUERY );
+ if ( xSI.is() )
+ bUseStarFormat = xSI->supportsService( rtl::OUString( "com.sun.star.sheet.SpreadsheetDocument" ) );
+ }
+ pNumFmtShell->SetUseStarFormat( bUseStarFormat );
+
FillCurrencyBox();
String aPrevString;
diff --git a/svl/inc/svl/zforlist.hxx b/svl/inc/svl/zforlist.hxx
index 7f2a7ff..989df98 100644
--- a/svl/inc/svl/zforlist.hxx
+++ b/svl/inc/svl/zforlist.hxx
@@ -517,7 +517,8 @@ public:
*/
bool GetPreviewString( const String& sFormatString, double fPreviewNumber,
String& sOutString, Color** ppColor,
- LanguageType eLnge = LANGUAGE_DONTKNOW );
+ LanguageType eLnge = LANGUAGE_DONTKNOW,
+ bool bUseStarFormat = false );
/** Same as <method>GetPreviewString</method> but the format code string
may be either language/country eLnge or en_US english US */
diff --git a/svl/source/numbers/zforlist.cxx b/svl/source/numbers/zforlist.cxx
index d897274..c799570 100644
--- a/svl/source/numbers/zforlist.cxx
+++ b/svl/source/numbers/zforlist.cxx
@@ -1637,7 +1637,8 @@ bool SvNumberFormatter::GetPreviewString(const String& sFormatString,
double fPreviewNumber,
String& sOutString,
Color** ppColor,
- LanguageType eLnge)
+ LanguageType eLnge,
+ bool bUseStarFormat )
{
if (sFormatString.Len() == 0) // keinen Leerstring
return false;
@@ -1660,9 +1661,15 @@ bool SvNumberFormatter::GetPreviewString(const String& sFormatString,
// formate anlegen
nKey = ImpIsEntry(p_Entry->GetFormatstring(),CLOffset, eLnge);
if (nKey != NUMBERFORMAT_ENTRY_NOT_FOUND) // schon vorhanden
- GetOutputString(fPreviewNumber,nKey,sOutString,ppColor);
+ GetOutputString(fPreviewNumber,nKey,sOutString,ppColor, bUseStarFormat);
else
+ {
+ if ( bUseStarFormat )
+ p_Entry->SetStarFormatSupport( true );
p_Entry->GetOutputString(fPreviewNumber,sOutString, ppColor);
+ if ( bUseStarFormat )
+ p_Entry->SetStarFormatSupport( false );
+ }
delete p_Entry;
return true;
}
diff --git a/svx/inc/svx/numfmtsh.hxx b/svx/inc/svx/numfmtsh.hxx
index d6005ab..3cd1df5 100644
--- a/svx/inc/svx/numfmtsh.hxx
+++ b/svx/inc/svx/numfmtsh.hxx
@@ -184,7 +184,8 @@ public:
sal_uInt16 FindCurrencyTableEntry( const String& rFmtString, bool &bTestBanking );
bool IsInTable(sal_uInt16 nPos,bool bTmpBanking,const String &rFmtString);
-
+ void SetUseStarFormat( bool bUse ) { bUseStarFormat = bUse; }
+ bool IsUseStarFormat( void ) { return bUseStarFormat; }
private:
static const double DEFAULT_NUMVALUE;
@@ -206,7 +207,7 @@ private:
bool bBankingSymbol;
sal_uInt16 nCurCurrencyEntryPos;
std::vector<String*> aCurrencyFormatList;
-
+ bool bUseStarFormat;
#ifdef _SVX_NUMFMTSH_CXX
SVX_DLLPRIVATE short FillEntryList_Impl( std::vector<String*>& rList );
SVX_DLLPRIVATE void FillEListWithStd_Impl( std::vector<String*>& rList,sal_uInt16 aPrivCat, short &Pos);
diff --git a/svx/source/items/numfmtsh.cxx b/svx/source/items/numfmtsh.cxx
index d696123..7530982 100644
--- a/svx/source/items/numfmtsh.cxx
+++ b/svx/source/items/numfmtsh.cxx
@@ -84,7 +84,8 @@ SvxNumberFormatShell::SvxNumberFormatShell( SvNumberFormatter* pNumFormatter,
nCurFormatKey ( nFormatKey ),
pCurCurrencyEntry(NULL),
bBankingSymbol (false),
- nCurCurrencyEntryPos((sal_uInt16) SELPOS_NONE)
+ nCurCurrencyEntryPos((sal_uInt16) SELPOS_NONE),
+ bUseStarFormat (false)
{
nValNum = DEFAULT_NUMVALUE;
@@ -115,7 +116,8 @@ SvxNumberFormatShell::SvxNumberFormatShell( SvNumberFormatter* pNumFormatter,
nCurFormatKey ( nFormatKey ),
pCurCurrencyEntry(NULL),
bBankingSymbol (false),
- nCurCurrencyEntryPos((sal_uInt16) SELPOS_NONE)
+ nCurCurrencyEntryPos((sal_uInt16) SELPOS_NONE),
+ bUseStarFormat (false)
{
// #50441# When used in Writer, the SvxNumberInfoItem contains the
// original string in addition to the value
@@ -439,7 +441,7 @@ void SvxNumberFormatShell::MakePreviewString( const String& rFormatStr,
// real preview - not implemented in NumberFormatter for text formats
pFormatter->GetPreviewString( rFormatStr, nValNum, rPreviewStr,
- &rpFontColor, eCurLanguage );
+ &rpFontColor, eCurLanguage, bUseStarFormat );
}
else
{
@@ -453,7 +455,7 @@ void SvxNumberFormatShell::MakePreviewString( const String& rFormatStr,
rPreviewStr, &rpFontColor );
else
pFormatter->GetOutputString( nValNum, nExistingFormat,
- rPreviewStr, &rpFontColor );
+ rPreviewStr, &rpFontColor, bUseStarFormat );
}
}
@@ -1153,7 +1155,7 @@ void SvxNumberFormatShell::GetPreviewString_Impl( String& rString, Color*& rpCol
if ( bUseText )
pFormatter->GetOutputString( aValStr, nCurFormatKey, rString, &rpColor );
else
- pFormatter->GetOutputString( nValNum, nCurFormatKey, rString, &rpColor );
+ pFormatter->GetOutputString( nValNum, nCurFormatKey, rString, &rpColor, bUseStarFormat );
}
// -----------------------------------------------------------------------
--
1.7.3.4
--------------030000000700060006090308
Content-Type: text/x-patch;
name="0002-support-new-xml-number-repeated-elem-for-number-styl.patch"
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment;
filename*0="0002-support-new-xml-number-repeated-elem-for-number-styl.pa";
filename*1="tch"
More information about the LibreOffice
mailing list