From 68e707bbc6fe23881b822e6efab8a2933343dc1a Mon Sep 17 00:00:00 2001 From: Armin Le Grand Date: Tue, 16 Apr 2013 08:41:07 +0000 Subject: i122041 Unified and centralized control for Color ValueSets --- svx/source/sidebar/tools/ColorControl.cxx | 46 ++++++------- svx/source/tbxctrls/colorwindow.hxx | 7 +- svx/source/tbxctrls/colrctrl.cxx | 103 +++++++++++------------------- svx/source/tbxctrls/tbcontrl.cxx | 76 +++++----------------- 4 files changed, 79 insertions(+), 153 deletions(-) (limited to 'svx/source') diff --git a/svx/source/sidebar/tools/ColorControl.cxx b/svx/source/sidebar/tools/ColorControl.cxx index 6fece95f6651..66f4e6baf5aa 100644 --- a/svx/source/sidebar/tools/ColorControl.cxx +++ b/svx/source/sidebar/tools/ColorControl.cxx @@ -109,6 +109,7 @@ ColorControl::ColorControl ( maColorSetter(rColorSetter) { FreeResource(); + FillColors(); } @@ -126,40 +127,37 @@ void ColorControl::FillColors (void) if (pColorTable) { - const long nColorCount (pColorTable->Count()); + const long nColorCount(pColorTable->Count()); if (nColorCount <= 0) return; - const sal_Int32 nColumnCount (ceil(sqrt(double(nColorCount)))); - const sal_Int32 nRowCount (ceil(double(nColorCount)/nColumnCount)); - maVSColor.SetColCount(nColumnCount); - maVSColor.SetLineCount(nRowCount); - const sal_Int32 nItemSize (15*12 / ::std::max(nColumnCount, nRowCount)); - maVSColor.CalcWindowSizePixel(Size(nItemSize,nItemSize)); - Link aLink = LINK(this, ColorControl, VSSelectHdl); - maVSColor.SetSelectHdl(aLink); - maVSColor.SetStyle( - (maVSColor.GetStyle() - | WB_TABSTOP | WB_ITEMBORDER | WB_NAMEFIELD// | WB_FLATVALUESET - | WB_NO_DIRECTSELECT | WB_MENUSTYLEVALUESET | WB_NO_DIRECTSELECT) - & ~WB_VSCROLL); - if (msNoColorString.Len() > 0) + const WinBits aWinBits(maVSColor.GetStyle() | WB_TABSTOP | WB_ITEMBORDER | WB_NAMEFIELD | + WB_NO_DIRECTSELECT | WB_MENUSTYLEVALUESET | WB_NO_DIRECTSELECT); + + maVSColor.SetStyle(aWinBits); + + // neds to be done *before* layouting + if(msNoColorString.Len() > 0) { maVSColor.SetStyle(maVSColor.GetStyle() | WB_NONEFIELD); maVSColor.SetText(msNoColorString); } + const Size aNewSize(maVSColor.layoutAllVisible(nColorCount)); + maVSColor.SetOutputSizePixel(aNewSize); + static sal_Int32 nAdd = 4; + + SetOutputSizePixel(Size(aNewSize.Width() + nAdd, aNewSize.Height() + nAdd)); + Link aLink = LINK(this, ColorControl, VSSelectHdl); + maVSColor.SetSelectHdl(aLink); + // Now, after all calls to SetStyle, we can change the // background color. maVSColor.SetBackground(Theme::GetWallpaper(Theme::Paint_DropDownBackground)); + // add entrties maVSColor.Clear(); - XColorEntry* pEntry = NULL; - for (sal_Int32 nIndex=0; nIndexGetColor(nIndex); - maVSColor.InsertItem(nIndex+1, pEntry->GetColor(), pEntry->GetName() ); - } + maVSColor.addEntriesForXColorList(*pColorTable); } maVSColor.Show(); @@ -178,7 +176,7 @@ void ColorControl::GetFocus (void) void ColorControl::SetCurColorSelect (Color aCol, bool bAvailable) { - FillColors(); +// FillColors(); short nCol = GetItemId_Imp( maVSColor, aCol ); if(! bAvailable) { @@ -193,7 +191,9 @@ void ColorControl::SetCurColorSelect (Color aCol, bool bAvailable) } else { - maVSColor.SelectItem( nCol ); + // remove selection first to force evtl. scroll when scroll is needed + maVSColor.SetNoSelection(); + maVSColor.SelectItem(nCol); } } diff --git a/svx/source/tbxctrls/colorwindow.hxx b/svx/source/tbxctrls/colorwindow.hxx index 3de31b8c612a..78558fa086c3 100644 --- a/svx/source/tbxctrls/colorwindow.hxx +++ b/svx/source/tbxctrls/colorwindow.hxx @@ -29,6 +29,7 @@ #include #include #include +#include //======================================================================== // class SvxColorWindow_Impl -------------------------------------------------- @@ -39,9 +40,9 @@ class SvxColorWindow_Impl : public SfxPopupWindow using FloatingWindow::StateChanged; private: - const sal_uInt16 theSlotId; - ValueSet aColorSet; - rtl::OUString maCommand; + const sal_uInt16 theSlotId; + SvxColorValueSet aColorSet; + rtl::OUString maCommand; #if _SOLAR__PRIVATE DECL_LINK( SelectHdl, void * ); diff --git a/svx/source/tbxctrls/colrctrl.cxx b/svx/source/tbxctrls/colrctrl.cxx index 24b5e3de21eb..23ac6277ca3b 100644 --- a/svx/source/tbxctrls/colrctrl.cxx +++ b/svx/source/tbxctrls/colrctrl.cxx @@ -44,8 +44,6 @@ #include "svx/xexch.hxx" #include -SFX_IMPL_DOCKINGWINDOW( SvxColorChildWindow, SID_COLOR_CONTROL ) - // ------------------------ // - SvxColorValueSetData - // ------------------------ @@ -100,55 +98,55 @@ sal_Bool SvxColorValueSetData::WriteObject( SotStorageStreamRef& rxOStm, void*, /************************************************************************* |* -|* SvxColorValueSet: Ctor +|* SvxColorValueSet_docking: Ctor |* \************************************************************************/ -SvxColorValueSet::SvxColorValueSet( Window* _pParent, WinBits nWinStyle ) : - ValueSet( _pParent, nWinStyle ), +SvxColorValueSet_docking::SvxColorValueSet_docking( Window* _pParent, WinBits nWinStyle ) : + SvxColorValueSet( _pParent, nWinStyle ), DragSourceHelper( this ), - bLeft (sal_True) + mbLeftButton(true) { SetAccessibleName(String( SVX_RES( STR_COLORTABLE ) ) ); } /************************************************************************* |* -|* SvxColorValueSet: Ctor +|* SvxColorValueSet_docking: Ctor |* \************************************************************************/ -SvxColorValueSet::SvxColorValueSet( Window* _pParent, const ResId& rResId ) : - ValueSet( _pParent, rResId ), +SvxColorValueSet_docking::SvxColorValueSet_docking( Window* _pParent, const ResId& rResId ) : + SvxColorValueSet( _pParent, rResId ), DragSourceHelper( this ), - bLeft (sal_True) + mbLeftButton(true) { SetAccessibleName(String( SVX_RES( STR_COLORTABLE ) )); } /************************************************************************* |* -|* SvxColorValueSet: MouseButtonDown +|* SvxColorValueSet_docking: MouseButtonDown |* \************************************************************************/ -void SvxColorValueSet::MouseButtonDown( const MouseEvent& rMEvt ) +void SvxColorValueSet_docking::MouseButtonDown( const MouseEvent& rMEvt ) { // Fuer Mac noch anders handlen ! if( rMEvt.IsLeft() ) { - bLeft = sal_True; - ValueSet::MouseButtonDown( rMEvt ); + mbLeftButton = true; + SvxColorValueSet::MouseButtonDown( rMEvt ); } else { - bLeft = sal_False; + mbLeftButton = false; MouseEvent aMEvt( rMEvt.GetPosPixel(), rMEvt.GetClicks(), rMEvt.GetMode(), MOUSE_LEFT, rMEvt.GetModifier() ); - ValueSet::MouseButtonDown( aMEvt ); + SvxColorValueSet::MouseButtonDown( aMEvt ); } aDragPosPixel = GetPointerPosPixel(); @@ -156,27 +154,27 @@ void SvxColorValueSet::MouseButtonDown( const MouseEvent& rMEvt ) /************************************************************************* |* -|* SvxColorValueSet: MouseButtonUp +|* SvxColorValueSet_docking: MouseButtonUp |* \************************************************************************/ -void SvxColorValueSet::MouseButtonUp( const MouseEvent& rMEvt ) +void SvxColorValueSet_docking::MouseButtonUp( const MouseEvent& rMEvt ) { // Fuer Mac noch anders handlen ! if( rMEvt.IsLeft() ) { - bLeft = sal_True; - ValueSet::MouseButtonUp( rMEvt ); + mbLeftButton = true; + SvxColorValueSet::MouseButtonUp( rMEvt ); } else { - bLeft = sal_False; + mbLeftButton = false; MouseEvent aMEvt( rMEvt.GetPosPixel(), rMEvt.GetClicks(), rMEvt.GetMode(), MOUSE_LEFT, rMEvt.GetModifier() ); - ValueSet::MouseButtonUp( aMEvt ); + SvxColorValueSet::MouseButtonUp( aMEvt ); } SetNoSelection(); } @@ -187,10 +185,10 @@ void SvxColorValueSet::MouseButtonUp( const MouseEvent& rMEvt ) |* \************************************************************************/ -void SvxColorValueSet::Command(const CommandEvent& rCEvt) +void SvxColorValueSet_docking::Command(const CommandEvent& rCEvt) { // Basisklasse - ValueSet::Command(rCEvt); + SvxColorValueSet::Command(rCEvt); } /************************************************************************* @@ -199,9 +197,9 @@ void SvxColorValueSet::Command(const CommandEvent& rCEvt) |* \************************************************************************/ -void SvxColorValueSet::StartDrag( sal_Int8 , const Point& ) +void SvxColorValueSet_docking::StartDrag( sal_Int8 , const Point& ) { - Application::PostUserEvent(STATIC_LINK(this, SvxColorValueSet, ExecDragHdl)); + Application::PostUserEvent(STATIC_LINK(this, SvxColorValueSet_docking, ExecDragHdl)); } /************************************************************************* @@ -210,7 +208,7 @@ void SvxColorValueSet::StartDrag( sal_Int8 , const Point& ) |* \************************************************************************/ -void SvxColorValueSet::DoDrag() +void SvxColorValueSet_docking::DoDrag() { SfxObjectShell* pDocSh = SfxObjectShell::Current(); sal_uInt16 nItemId = GetItemId( aDragPosPixel ); @@ -235,7 +233,7 @@ void SvxColorValueSet::DoDrag() |* \************************************************************************/ -IMPL_STATIC_LINK(SvxColorValueSet, ExecDragHdl, void*, EMPTYARG) +IMPL_STATIC_LINK(SvxColorValueSet_docking, ExecDragHdl, void*, EMPTYARG) { // Als Link, damit asynchron ohne ImpMouseMoveMsg auf dem Stack auch die // Farbleiste geloescht werden darf @@ -243,29 +241,6 @@ IMPL_STATIC_LINK(SvxColorValueSet, ExecDragHdl, void*, EMPTYARG) return(0); } -/************************************************************************* -|* -|* Ableitung vom SfxChildWindow als "Behaelter" fuer Animator -|* -\************************************************************************/ - -SvxColorChildWindow::SvxColorChildWindow( Window* _pParent, - sal_uInt16 nId, - SfxBindings* pBindings, - SfxChildWinInfo* pInfo ) : - SfxChildWindow( _pParent, nId ) -{ - SvxColorDockingWindow* pWin = new SvxColorDockingWindow( pBindings, this, - _pParent, SVX_RES( RID_SVXCTRL_COLOR ) ); - pWindow = pWin; - - eChildAlignment = SFX_ALIGN_BOTTOM; - - pWin->Initialize( pInfo ); -} - - - /************************************************************************* |* |* Ctor: SvxColorDockingWindow @@ -287,8 +262,7 @@ SvxColorDockingWindow::SvxColorDockingWindow nLeftSlot ( SID_ATTR_FILL_COLOR ), nRightSlot ( SID_ATTR_LINE_COLOR ), nCols ( 20 ), - nLines ( 1 ), - aColorSize ( 14, 14 ) + nLines ( 1 ) { FreeResource(); @@ -323,10 +297,11 @@ SvxColorDockingWindow::SvxColorDockingWindow FillValueSet(); } } - aItemSize = aColorSet.CalcItemSizePixel( aColorSize ); - aItemSize.Width() = aItemSize.Width() + aColorSize.Width(); + + aItemSize = aColorSet.CalcItemSizePixel(Size(aColorSet.getEntryEdgeLength(), aColorSet.getEntryEdgeLength())); + aItemSize.Width() = aItemSize.Width() + aColorSet.getEntryEdgeLength(); aItemSize.Width() /= 2; - aItemSize.Height() = aItemSize.Height() + aColorSize.Height(); + aItemSize.Height() = aItemSize.Height() + aColorSet.getEntryEdgeLength(); aItemSize.Height() /= 2; SetSize(); @@ -374,12 +349,15 @@ void SvxColorDockingWindow::FillValueSet() { if( pColorTable ) { + nCount = pColorTable->Count(); aColorSet.Clear(); - // Erster Eintrag: unsichtbar + // create the first entry for 'invisible/none' + const Size aColorSize(aColorSet.getEntryEdgeLength(), aColorSet.getEntryEdgeLength()); long nPtX = aColorSize.Width() - 1; long nPtY = aColorSize.Height() - 1; VirtualDevice aVD; + aVD.SetOutputSizePixel( aColorSize ); aVD.SetLineColor( Color( COL_BLACK ) ); aVD.SetBackground( Wallpaper( Color( COL_WHITE ) ) ); @@ -389,16 +367,7 @@ void SvxColorDockingWindow::FillValueSet() Bitmap aBmp( aVD.GetBitmap( Point(), aColorSize ) ); aColorSet.InsertItem( (sal_uInt16)1, Image(aBmp), SVX_RESSTR( RID_SVXSTR_INVISIBLE ) ); - - XColorEntry* pEntry; - nCount = pColorTable->Count(); - - for( long i = 0; i < nCount; i++ ) - { - pEntry = pColorTable->GetColor( i ); - aColorSet.InsertItem( (sal_uInt16)i+2, - pEntry->GetColor(), pEntry->GetName() ); - } + aColorSet.addEntriesForXColorList(*pColorTable, 2); } } diff --git a/svx/source/tbxctrls/tbcontrl.cxx b/svx/source/tbxctrls/tbcontrl.cxx index 93f726ff5ef3..0e107532b830 100644 --- a/svx/source/tbxctrls/tbcontrl.cxx +++ b/svx/source/tbxctrls/tbcontrl.cxx @@ -815,10 +815,6 @@ void SvxFontNameBox_Impl::Select() #define WB_NO_DIRECTSELECT ((WinBits)0x04000000) #endif -#define PALETTE_X 10 -#define PALETTE_Y 11 -#define PALETTE_SIZE (PALETTE_X * PALETTE_Y) - SvxColorWindow_Impl::SvxColorWindow_Impl( const OUString& rCommand, sal_uInt16 nSlotId, const Reference< XFrame >& rFrame, @@ -836,7 +832,6 @@ SvxColorWindow_Impl::SvxColorWindow_Impl( const OUString& rCommand, const SfxPoolItem* pItem = NULL; XColorList* pColorTable = NULL; sal_Bool bKillTable = sal_False; - const Size aSize12( 13, 13 ); if ( pDocSh ) if ( 0 != ( pItem = pDocSh->GetItem( SID_COLOR_TABLE ) ) ) @@ -877,43 +872,23 @@ SvxColorWindow_Impl::SvxColorWindow_Impl( const OUString& rCommand, if ( pColorTable ) { - short i = 0; - long nCount = pColorTable->Count(); - XColorEntry* pEntry = NULL; - ::Color aColWhite( COL_WHITE ); - String aStrWhite( EditResId(RID_SVXITEMS_COLOR_WHITE) ); - - if ( nCount > PALETTE_SIZE ) - // Show scrollbar if more than PALLETTE_SIZE colors are available - aColorSet.SetStyle( aColorSet.GetStyle() | WB_VSCROLL ); - - for ( i = 0; i < nCount; i++ ) - { - pEntry = pColorTable->GetColor(i); - aColorSet.InsertItem( i+1, pEntry->GetColor(), pEntry->GetName() ); - } + const long nColorCount(pColorTable->Count()); + const Size aNewSize(aColorSet.layoutAllVisible(nColorCount)); + aColorSet.SetOutputSizePixel(aNewSize); + static sal_Int32 nAdd = 4; - while ( i < PALETTE_SIZE ) - { - // fill empty elements if less then PALLETTE_SIZE colors are available - aColorSet.InsertItem( i+1, aColWhite, aStrWhite ); - i++; - } + SetOutputSizePixel(Size(aNewSize.Width() + nAdd, aNewSize.Height() + nAdd)); + aColorSet.Clear(); + aColorSet.addEntriesForXColorList(*pColorTable); } aColorSet.SetSelectHdl( LINK( this, SvxColorWindow_Impl, SelectHdl ) ); - aColorSet.SetColCount( PALETTE_X ); - aColorSet.SetLineCount( PALETTE_Y ); - - lcl_CalcSizeValueSet( *this, aColorSet, aSize12 ); - SetHelpId( HID_POPUP_COLOR ); aColorSet.SetHelpId( HID_POPUP_COLOR_CTRL ); - SetText( rWndTitle ); aColorSet.Show(); - AddStatusListener( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ".uno:ColorTableState" ))); + if ( bKillTable ) delete pColorTable; } @@ -1019,33 +994,14 @@ void SvxColorWindow_Impl::StateChanged( sal_uInt16 nSID, SfxItemState eState, co if ( pColorTable ) { // Die Liste der Farben (ColorTable) hat sich ge"andert: - short i = 0; - long nCount = pColorTable->Count(); - XColorEntry* pEntry = NULL; - ::Color aColWhite( COL_WHITE ); - String aStrWhite( SVX_RES( RID_SVXITEMS_COLOR_WHITE ) ); - - // ScrollBar an oder aus - WinBits nBits = aColorSet.GetStyle(); - if ( nCount > PALETTE_SIZE ) - nBits &= ~WB_VSCROLL; - else - nBits |= WB_VSCROLL; - aColorSet.SetStyle( nBits ); - - for ( i = 0; i < nCount; ++i ) - { - pEntry = pColorTable->GetColor(i); - aColorSet.SetItemColor( i + 1, pEntry->GetColor() ); - aColorSet.SetItemText ( i + 1, pEntry->GetName() ); - } - - while ( i < PALETTE_SIZE ) - { - aColorSet.SetItemColor( i + 1, aColWhite ); - aColorSet.SetItemText ( i + 1, aStrWhite ); - i++; - } + const long nColorCount(pColorTable->Count()); + const Size aNewSize(aColorSet.layoutAllVisible(nColorCount)); + aColorSet.SetOutputSizePixel(aNewSize); + static sal_Int32 nAdd = 4; + + SetOutputSizePixel(Size(aNewSize.Width() + nAdd, aNewSize.Height() + nAdd)); + aColorSet.Clear(); + aColorSet.addEntriesForXColorList(*pColorTable); } } } -- cgit v1.2.3