中本です。
今まで、用紙のサイズなどは定数で全部決まっていたのですが、これだと用紙を追加
するのにいちいちパッチなどを書かなければいけないなどの問題があったので、動的
に用紙が追加できるようなパッチを書きました。
動的に用紙が追加できる、というのはまだコードレベルの話であって、この後設定
ファイル(*.xcu)を作って、それを読み込んで任意の用紙サイズを追加できるように
しなければユーザー的には何にも変わりません。
今まで用紙を定数(SvxPaper)で表していたのを、BDPaperというクラスで表すように
しました。ただし、このパッチで修正するところ以外にも、SvxPaperが使われている
のるので、次はそれらをBDPaperを使うように書き換えるようにします。
ほんで、その次は設定ファイルを作って、そこから用紙サイズを読み込むようにした
いと思います。そうすれば、言語ごとにリストの順番を入れ換えたりできるようにな
ります。
# 実験的に書いてるコードなのであんまり期待しないでください。
# けどうまくいったら取り込んでもらうつもり。
--
中本崇志 (Takashi Nakamoto)
E-Mail : [EMAIL PROTECTED], [EMAIL PROTECTED]
Homepage: http://bd.tank.jp/
blog : http://bd.tank.jp/blog
Index: inc/paperinf.hxx
===================================================================
RCS file: /cvs/graphics/svx/inc/paperinf.hxx,v
retrieving revision 1.4
diff -c -r1.4 paperinf.hxx
*** inc/paperinf.hxx 8 Sep 2005 18:16:28 -0000 1.4
--- inc/paperinf.hxx 28 Nov 2005 09:00:38 -0000
***************
*** 57,62 ****
--- 57,135 ----
class Size;
class String;
+ // class BDPaper
+ typedef int BDPaperID;
+ #define BD_PAPER_ID_OPTIONAL 0
+
+ #define PAPER_CATEGORY_STD 1
+ #define PAPER_CATEGORY_DRAW (1 << 1)
+
+ enum BDPaperType
+ {
+ BD_PAPER_TYPE_STANDARD,
+ BD_PAPER_TYPE_PRESENTATION
+ };
+
+ // class BDPaper -----------------------------------------------------
+ class BDPaper
+ {
+ private:
+ static int nIdCount;
+ String sName;
+ Size aSize;
+ BDPaperID nId;
+ int nCategory;
+ BDPaperType nType;
+
+ BDPaper(const String &rName,
+ const Size &rSize,
+ const int rCategory = PAPER_CATEGORY_STD | PAPER_CATEGORY_DRAW,
+ const BDPaperType rType = BD_PAPER_TYPE_STANDARD);
+ BDPaper(const Size &rSize);
+ public:
+ BDPaper(const BDPaper &src);
+ ~BDPaper();
+ String GetName() const;
+ Size GetSize() const ;
+ BDPaperID GetID() const;
+ int GetCategory() const;
+ BDPaperType GetType() const;
+
+ friend class BDPaperInfo;
+ };
+
+ // class BDPaperInfo -----------------------------------------------------
+ typedef std::vector< BDPaper > PaperVec;
+
+ class SVX_DLLPUBLIC BDPaperInfo
+ {
+ private:
+ static BDPaperInfo* instance;
+ protected:
+ PaperVec maPapers;
+ public:
+ // singleton pattern
+ static BDPaperInfo& Instance (void);
+ BDPaperInfo (const BDPaperInfo& aHandler);
+ BDPaperInfo& operator= (const BDPaperInfo& aHandler);
+
+ /** This destructor is never called at the moment. But because this
+ class is a singleton this is not a problem.
+ */
+ virtual ~BDPaperInfo (void);
+
+ BDPaperInfo (void);
+
+ PaperVec GetPapers();
+
+ USHORT GetPapersCount();
+ BDPaper GetPaper(USHORT index);
+
+ Size GetDefaultSize();
+ BDPaper GetPaperFromSize( const Size &rSize, MapUnit eUnit, BOOL bSloppy );
+ BDPaper GetPaperFromID( const BDPaperID aId );
+ };
+
// class SvxPaperInfo -----------------------------------------------------
class SVX_DLLPUBLIC SvxPaperInfo
Index: source/dialog/page.cxx
===================================================================
RCS file: /cvs/graphics/svx/source/dialog/page.cxx,v
retrieving revision 1.28
diff -c -r1.28 page.cxx
*** source/dialog/page.cxx 8 Sep 2005 21:49:35 -0000 1.28
--- source/dialog/page.cxx 28 Nov 2005 09:00:39 -0000
***************
*** 573,579 ****
aPaperTrayBox.SelectEntry( aBinName );
// Size rausholen
! Size aPaperSize = SvxPaperInfo::GetPaperSize( pImpl->mpDefPrinter );
pItem = GetItem( rSet, SID_ATTR_PAGE_SIZE );
if ( pItem )
--- 573,580 ----
aPaperTrayBox.SelectEntry( aBinName );
// Size rausholen
! // Size aPaperSize = SvxPaperInfo::GetPaperSize( pImpl->mpDefPrinter );
! Size aPaperSize = BDPaperInfo::Instance().GetDefaultSize();
pItem = GetItem( rSet, SID_ATTR_PAGE_SIZE );
if ( pItem )
***************
*** 608,632 ****
if ( bLandscape )
Swap( aTmpSize );
// aktuelles Format
! SvxPaper ePaper = SvxPaperInfo::GetPaper( aTmpSize, (MapUnit)eUnit, TRUE );
USHORT nActPos = LISTBOX_ENTRY_NOTFOUND;
! USHORT nAryId = RID_SVXSTRARY_PAPERSIZE_STD;
! if ( ePaperStart != SVX_PAPER_A3 )
! nAryId = RID_SVXSTRARY_PAPERSIZE_DRAW;
! ResStringArray aPaperAry( SVX_RES( nAryId ) );
! USHORT nCnt = aPaperAry.Count();
!
! for ( USHORT i = 0; i < nCnt; ++i )
! {
! String aStr = aPaperAry.GetString(i);
! SvxPaper eSize = (SvxPaper)aPaperAry.GetValue(i);
! USHORT nPos = aPaperSizeBox.InsertEntry( aStr );
! aPaperSizeBox.SetEntryData( nPos, (void*)(ULONG)eSize );
- if ( eSize == ePaper )
- nActPos = nPos;
- }
// aktuelles Papierformat selektieren
aPaperSizeBox.SelectEntryPos( nActPos );
--- 609,633 ----
if ( bLandscape )
Swap( aTmpSize );
// aktuelles Format
!
! BDPaper ePaper = BDPaperInfo::Instance().GetPaperFromSize( aTmpSize, (MapUnit)eUnit, TRUE );
USHORT nActPos = LISTBOX_ENTRY_NOTFOUND;
! USHORT nCnt = BDPaperInfo::Instance().GetPapersCount();
! for ( USHORT i = 0; i < nCnt; ++i )
! {
! BDPaper aPaper = BDPaperInfo::Instance().GetPaper(i);
! if( (ePaperStart == SVX_PAPER_A3 &&
! aPaper.GetCategory() & PAPER_CATEGORY_STD) ||
! (ePaperStart != SVX_PAPER_A3 &&
! aPaper.GetCategory() & PAPER_CATEGORY_DRAW)){
! USHORT nPos = aPaperSizeBox.InsertEntry( aPaper.GetName() );
! aPaperSizeBox.SetEntryData( nPos, (void*)(BDPaperID)aPaper.GetID());
! if( ePaper.GetID() == aPaper.GetID() )
! nActPos = nPos;
! }
! }
// aktuelles Papierformat selektieren
aPaperSizeBox.SelectEntryPos( nActPos );
***************
*** 826,836 ****
}
nPos = aPaperSizeBox.GetSelectEntryPos();
! SvxPaper ePaper = (SvxPaper)(ULONG)aPaperSizeBox.GetEntryData( nPos );
const USHORT nOld = aPaperSizeBox.GetSavedValue();
BOOL bChecked = aLandscapeBtn.IsChecked();
! if ( SVX_PAPER_USER == ePaper )
{
if ( nOld != nPos ||
aPaperWidthEdit.IsValueModified() ||
--- 827,838 ----
}
nPos = aPaperSizeBox.GetSelectEntryPos();
! BDPaperID eId = (BDPaperID)aPaperSizeBox.GetEntryData( nPos );
! BDPaper ePaper = BDPaperInfo::Instance().GetPaperFromID( eId );
const USHORT nOld = aPaperSizeBox.GetSavedValue();
BOOL bChecked = aLandscapeBtn.IsChecked();
! if ( eId == BD_PAPER_ID_OPTIONAL )
{
if ( nOld != nPos ||
aPaperWidthEdit.IsValueModified() ||
***************
*** 852,858 ****
{
if ( nOld != nPos || bChecked != aLandscapeBtn.GetSavedValue() )
{
! Size aSize( SvxPaperInfo::GetPaperSize( ePaper, (MapUnit)eUnit ) );
if ( bChecked )
Swap( aSize );
--- 854,860 ----
{
if ( nOld != nPos || bChecked != aLandscapeBtn.GetSavedValue() )
{
! Size aSize( ePaper.GetSize() );
if ( bChecked )
Swap( aSize );
***************
*** 1040,1050 ****
IMPL_LINK( SvxPageDescPage, PaperSizeSelect_Impl, ListBox *, pBox )
{
const USHORT nPos = pBox->GetSelectEntryPos();
! SvxPaper ePaper = (SvxPaper)(ULONG)aPaperSizeBox.GetEntryData( nPos );
! if ( ePaper != SVX_PAPER_USER )
{
! Size aSize( SvxPaperInfo::GetPaperSize( ePaper ) );
if ( aLandscapeBtn.IsChecked() )
Swap( aSize );
--- 1042,1053 ----
IMPL_LINK( SvxPageDescPage, PaperSizeSelect_Impl, ListBox *, pBox )
{
const USHORT nPos = pBox->GetSelectEntryPos();
! BDPaperID eId = (BDPaperID)aPaperSizeBox.GetEntryData( nPos );
! BDPaper ePaper = BDPaperInfo::Instance().GetPaperFromID( eId );
! if( eId != BD_PAPER_ID_OPTIONAL )
{
! Size aSize( ePaper.GetSize() );
if ( aLandscapeBtn.IsChecked() )
Swap( aSize );
***************
*** 1068,1074 ****
{
// Draw: bei Papierformat soll der Rand 1cm betragen
long nTmp = 0;
! BOOL bScreen = ( SVX_PAPER_SCREEN == ePaper );
if ( !bScreen )
// bei Bildschirm keinen Rand
--- 1071,1077 ----
{
// Draw: bei Papierformat soll der Rand 1cm betragen
long nTmp = 0;
! BOOL bScreen = ( ePaper.GetType() == BD_PAPER_TYPE_PRESENTATION );
if ( !bScreen )
// bei Bildschirm keinen Rand
***************
*** 1117,1130 ****
SfxMapUnit eUnit = GetItemSet().GetPool()->GetMetric( nWhich );
Size aSize( GetCoreValue( aPaperWidthEdit, eUnit ),
GetCoreValue( aPaperHeightEdit, eUnit ) );
! SvxPaper ePaper = SvxPaperInfo::GetPaper( aSize, (MapUnit)eUnit, TRUE );
USHORT nEntryCount = aPaperSizeBox.GetEntryCount();
for ( USHORT i = 0; i < nEntryCount; ++i )
{
! SvxPaper eTmp = (SvxPaper)(ULONG)aPaperSizeBox.GetEntryData(i);
! if ( eTmp == ePaper )
{
aPaperSizeBox.SelectEntryPos(i);
break;
--- 1120,1133 ----
SfxMapUnit eUnit = GetItemSet().GetPool()->GetMetric( nWhich );
Size aSize( GetCoreValue( aPaperWidthEdit, eUnit ),
GetCoreValue( aPaperHeightEdit, eUnit ) );
! BDPaper ePaper = BDPaperInfo::Instance().GetPaperFromSize( aSize, (MapUnit)eUnit, TRUE );
USHORT nEntryCount = aPaperSizeBox.GetEntryCount();
for ( USHORT i = 0; i < nEntryCount; ++i )
{
! BDPaperID eId = (BDPaperID)aPaperSizeBox.GetEntryData(i);
! if ( eId == ePaper.GetID() )
{
aPaperSizeBox.SelectEntryPos(i);
break;
***************
*** 1475,1483 ****
// Wenn nicht, dann den Anwender fragen, ob sie "ubernommen werden sollen.
// Wenn nicht, dann auf der TabPage bleiben.
USHORT nPos = aPaperSizeBox.GetSelectEntryPos();
! SvxPaper ePaper = (SvxPaper)(ULONG)aPaperSizeBox.GetEntryData( nPos );
! if ( ePaper != SVX_PAPER_SCREEN && IsMarginOutOfRange() )
{
if ( QueryBox( this, WB_YES_NO | WB_DEF_NO, aPrintRangeQueryText ).Execute() == RET_NO )
{
--- 1478,1489 ----
// Wenn nicht, dann den Anwender fragen, ob sie "ubernommen werden sollen.
// Wenn nicht, dann auf der TabPage bleiben.
USHORT nPos = aPaperSizeBox.GetSelectEntryPos();
! // SvxPaper ePaper = (SvxPaper)(ULONG)aPaperSizeBox.GetEntryData( nPos );
! BDPaperID eId = (BDPaperID)aPaperSizeBox.GetEntryData( nPos );
! BDPaper ePaper = BDPaperInfo::Instance().GetPaperFromID( eId );
! // if ( ePaper != SVX_PAPER_SCREEN && IsMarginOutOfRange() )
! if( ePaper.GetType() != BD_PAPER_TYPE_PRESENTATION && IsMarginOutOfRange() )
{
if ( QueryBox( this, WB_YES_NO | WB_DEF_NO, aPrintRangeQueryText ).Execute() == RET_NO )
{
***************
*** 1767,1772 ****
--- 1773,1779 ----
{
SFX_ITEMSET_ARG (&aSet,pModeItem,SfxAllEnumItem,SID_ENUM_PAGE_MODE,sal_False);
SFX_ITEMSET_ARG (&aSet,pPaperStartItem,SfxAllEnumItem,SID_PAPER_START,sal_False);
+ // const SfxAllEnumItem *pPaperStartItem = (const SfxAllEnumItem*) SfxRequest::GetItem( &aSet, SID_PAPER_START, sal_False, TYPE(ItemType));
SFX_ITEMSET_ARG (&aSet,pPaperEndItem,SfxAllEnumItem,SID_PAPER_END,sal_False);
SFX_ITEMSET_ARG (&aSet,pCollectListItem,SfxStringListItem,SID_COLLECT_LIST,sal_False);
if (pModeItem)
Index: source/items/paperinf.cxx
===================================================================
RCS file: /cvs/graphics/svx/source/items/paperinf.cxx,v
retrieving revision 1.5
diff -c -r1.5 paperinf.cxx
*** source/items/paperinf.cxx 8 Sep 2005 23:38:32 -0000 1.5
--- source/items/paperinf.cxx 28 Nov 2005 09:00:40 -0000
***************
*** 345,347 ****
--- 345,586 ----
}
+ int BDPaper::nIdCount = BD_PAPER_ID_OPTIONAL + 1;
+
+ BDPaper::BDPaper(const String &rName,
+ const Size &rSize,
+ const int rCategory,
+ const BDPaperType rType) :
+ sName(rName),
+ aSize(rSize),
+ nCategory(rCategory),
+ nType(rType)
+ {
+ nId = (BDPaperID)BDPaper::nIdCount++;
+ }
+
+
+ // for optional paper size
+ // not registered paper size will be "OPTIONAL" paper.
+ BDPaper::BDPaper(const Size &rSize) :
+ aSize(rSize)
+ {
+ sName = SVX_RES( RID_SVXSTR_PAPER_USER );
+ nCategory = PAPER_CATEGORY_STD | PAPER_CATEGORY_DRAW;
+ nType = BD_PAPER_TYPE_STANDARD;
+ nId = BD_PAPER_ID_OPTIONAL;
+ }
+
+ BDPaper::BDPaper(const BDPaper &src)
+ {
+ sName = src.sName;
+ aSize = src.aSize;
+ nCategory = src.nCategory;
+ nType = src.nType;
+ nId = src.nId;
+ }
+
+ BDPaper::~BDPaper()
+ {
+ }
+
+ String BDPaper::GetName() const
+ {
+ return sName;
+ }
+
+ Size BDPaper::GetSize() const
+ {
+ return aSize;
+ }
+
+ BDPaperID BDPaper::GetID() const
+ {
+ return nId;
+ }
+
+ int BDPaper::GetCategory() const
+ {
+ return nCategory;
+ }
+
+ BDPaperType BDPaper::GetType() const
+ {
+ return nType;
+ }
+
+ BDPaperInfo* BDPaperInfo::instance = NULL;
+
+ BDPaperInfo& BDPaperInfo::Instance(void)
+ {
+ if (instance == NULL)
+ {
+ // Create the single instance of the shape type handler.
+ instance = new BDPaperInfo;
+ }
+
+ return *instance;
+ }
+
+ BDPaperInfo::BDPaperInfo(const BDPaperInfo& aHandler)
+ {
+ // Don't call this constructor. This class is a singleton.
+ OSL_ENSURE (sal_False, "Wrong (copy-) constructor of singleton BDPaperInfo called."
+ " Don't do that again.");
+
+ }
+
+ BDPaperInfo::~BDPaperInfo(void)
+ {
+ // Because this class is a singleton and the only instance, whose
+ // destructor has just been called, is pointed to from instance,
+ // we reset the static variable instance, so that further calls to
+ // getInstance do not return an undefined object but create a new
+ // singleton.
+ instance = NULL;
+ }
+
+ BDPaperInfo& BDPaperInfo::operator= (const BDPaperInfo& aHandler)
+ {
+ // Don't call this operator. This class is a singleton.
+ OSL_ENSURE (sal_False, "Assignment operator of singleton BDPaperInfo called."
+ " Don't do that again.");
+ return *this;
+ }
+
+ BDPaperInfo::BDPaperInfo(void)
+ {
+ // register standard paper sizes
+ maPapers.push_back( BDPaper( String( SVX_RES( RID_SVXSTR_PAPER_A0 ) ),
+ Size( lA0Width, lA0Height ),
+ PAPER_CATEGORY_DRAW));
+
+ maPapers.push_back( BDPaper( String( SVX_RES( RID_SVXSTR_PAPER_A1 ) ),
+ Size( lA1Width, lA1Height ),
+ PAPER_CATEGORY_DRAW));
+
+ maPapers.push_back( BDPaper( String( SVX_RES( RID_SVXSTR_PAPER_A2 ) ),
+ Size( lA2Width, lA2Height ),
+ PAPER_CATEGORY_DRAW));
+
+ maPapers.push_back( BDPaper( String( SVX_RES( RID_SVXSTR_PAPER_A3 ) ),
+ Size( lA3Width, lA3Height ),
+ PAPER_CATEGORY_DRAW));
+
+ maPapers.push_back( BDPaper( String( SVX_RES( RID_SVXSTR_PAPER_A4 ) ),
+ Size( lA4Width, lA4Height ),
+ PAPER_CATEGORY_STD | PAPER_CATEGORY_DRAW));
+
+ maPapers.push_back( BDPaper( String( SVX_RES( RID_SVXSTR_PAPER_A5 ) ),
+ Size( lA5Width, lA5Height ),
+ PAPER_CATEGORY_STD | PAPER_CATEGORY_DRAW));
+
+ maPapers.push_back( BDPaper( String( SVX_RES( RID_SVXSTR_PAPER_B4 ) ),
+ Size( lB4Width, lB4Height ),
+ PAPER_CATEGORY_STD | PAPER_CATEGORY_DRAW));
+
+ maPapers.push_back( BDPaper( String( SVX_RES( RID_SVXSTR_PAPER_B5 ) ),
+ Size( lB5Width, lB5Height ),
+ PAPER_CATEGORY_STD | PAPER_CATEGORY_DRAW));
+
+ maPapers.push_back( BDPaper( String( SVX_RES( RID_SVXSTR_PAPER_B6 ) ),
+ Size( lB6Width, lB6Height ),
+ PAPER_CATEGORY_STD | PAPER_CATEGORY_DRAW));
+
+ maPapers.push_back( BDPaper( String( SVX_RES( RID_SVXSTR_PAPER_B4_JIS ) ),
+ Size( lJISB4Width, lJISB4Height ),
+ PAPER_CATEGORY_STD | PAPER_CATEGORY_DRAW));
+
+ maPapers.push_back( BDPaper( String( SVX_RES( RID_SVXSTR_PAPER_B5_JIS ) ),
+ Size( lJISB5Width, lJISB5Height ),
+ PAPER_CATEGORY_STD | PAPER_CATEGORY_DRAW));
+
+ maPapers.push_back( BDPaper( String( SVX_RES( RID_SVXSTR_PAPER_B6_JIS ) ),
+ Size( lJISB6Width, lJISB6Height ),
+ PAPER_CATEGORY_STD | PAPER_CATEGORY_DRAW));
+
+ maPapers.push_back( BDPaper( String( SVX_RES( RID_SVXSTR_PAPER_LETTER ) ),
+ Size( lLetterWidth, lLetterHeight ),
+ PAPER_CATEGORY_STD | PAPER_CATEGORY_DRAW));
+
+ maPapers.push_back( BDPaper( String( SVX_RES( RID_SVXSTR_PAPER_LEGAL ) ),
+ Size( lLegalWidth, lLegalHeight ),
+ PAPER_CATEGORY_STD | PAPER_CATEGORY_DRAW));
+
+ maPapers.push_back( BDPaper( String( SVX_RES( RID_SVXSTR_PAPER_TABLOID ) ),
+ Size( lTabloidWidth, lTabloidHeight ),
+ PAPER_CATEGORY_STD | PAPER_CATEGORY_DRAW));
+
+ // for screen
+ maPapers.push_back( BDPaper( String( SVX_RES( RID_SVXSTR_PAPER_SCREEN) ),
+ Size( lScreenWidth, lScreenHeight ),
+ PAPER_CATEGORY_DRAW,
+ BD_PAPER_TYPE_PRESENTATION));
+
+ // for optional paper
+ maPapers.push_back( BDPaper( Size( 0, 0 ) ) );
+ }
+
+ PaperVec BDPaperInfo::GetPapers()
+ {
+
+ }
+
+ USHORT BDPaperInfo::GetPapersCount()
+ {
+ return (USHORT)maPapers.size();
+ }
+
+ BDPaper BDPaperInfo::GetPaper(USHORT index)
+ {
+ return maPapers[index];
+ }
+
+
+ Size BDPaperInfo::GetDefaultSize()
+ {
+ return maPapers[4].GetSize();
+ }
+
+ BDPaper BDPaperInfo::GetPaperFromSize( const Size &rSize, MapUnit eUnit, BOOL bSloppy )
+ {
+ DBG_ASSERT( eUnit == MAP_TWIP || eUnit == MAP_100TH_MM,
+ "map unit not supported" );
+ Size aSize = rSize;
+
+ if ( eUnit == MAP_100TH_MM )
+ ConvertToTwips( aSize );
+
+ USHORT nVecSize = maPapers.size();
+
+ for ( USHORT i = 0; i < nVecSize; i++ )
+ {
+ if ( maPapers[i].GetSize() == aSize )
+ return maPapers[i];
+ else if ( bSloppy )
+ {
+ long lDiffW = Abs(maPapers[i].GetSize().Width () - aSize.Width ()),
+ lDiffH = Abs(maPapers[i].GetSize().Height() - aSize.Height());
+
+ if ( lDiffW < 6 && lDiffH < 6 )
+ return maPapers[i];
+ }
+ }
+
+ // return optional paper
+ return BDPaper(aSize);
+ }
+
+ BDPaper BDPaperInfo::GetPaperFromID( const BDPaperID aId )
+ {
+ USHORT nVecSize = maPapers.size();
+
+ for ( USHORT i = 0; i < nVecSize; i++ )
+ {
+ if ( maPapers[i].GetID() == aId )
+ return maPapers[i];
+ }
+
+ DBG_ASSERT( false, "Do not match any paper." );
+ return maPapers[maPapers.size()-1]; // "OPTIONAL" paper
+ }
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]