1*2ee96f1cSAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*2ee96f1cSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*2ee96f1cSAndrew Rist * or more contributor license agreements. See the NOTICE file 5*2ee96f1cSAndrew Rist * distributed with this work for additional information 6*2ee96f1cSAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*2ee96f1cSAndrew Rist * to you under the Apache License, Version 2.0 (the 8*2ee96f1cSAndrew Rist * "License"); you may not use this file except in compliance 9*2ee96f1cSAndrew Rist * with the License. You may obtain a copy of the License at 10cdf0e10cSrcweir * 11*2ee96f1cSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12cdf0e10cSrcweir * 13*2ee96f1cSAndrew Rist * Unless required by applicable law or agreed to in writing, 14*2ee96f1cSAndrew Rist * software distributed under the License is distributed on an 15*2ee96f1cSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*2ee96f1cSAndrew Rist * KIND, either express or implied. See the License for the 17*2ee96f1cSAndrew Rist * specific language governing permissions and limitations 18*2ee96f1cSAndrew Rist * under the License. 19cdf0e10cSrcweir * 20*2ee96f1cSAndrew Rist *************************************************************/ 21*2ee96f1cSAndrew Rist 22*2ee96f1cSAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 25cdf0e10cSrcweir #include "precompiled_cui.hxx" 26cdf0e10cSrcweir #include <unotools/pathoptions.hxx> 27cdf0e10cSrcweir #include <cuires.hrc> 28cdf0e10cSrcweir #include "optchart.hxx" 29cdf0e10cSrcweir #include "optchart.hrc" 30cdf0e10cSrcweir #include <dialmgr.hxx> 31cdf0e10cSrcweir #include <svx/svxids.hrc> // for SID_SCH_EDITOPTIONS 32cdf0e10cSrcweir 33cdf0e10cSrcweir // ==================== 34cdf0e10cSrcweir // class ChartColorLB 35cdf0e10cSrcweir // ==================== 36cdf0e10cSrcweir void ChartColorLB::FillBox( const SvxChartColorTable & rTab ) 37cdf0e10cSrcweir { 38cdf0e10cSrcweir long nCount = rTab.size(); 39cdf0e10cSrcweir SetUpdateMode( sal_False ); 40cdf0e10cSrcweir 41cdf0e10cSrcweir for( long i = 0; i < nCount; i++ ) 42cdf0e10cSrcweir { 43cdf0e10cSrcweir Append( const_cast< XColorEntry * >( & rTab[ i ] )); 44cdf0e10cSrcweir } 45cdf0e10cSrcweir SetUpdateMode( sal_True ); 46cdf0e10cSrcweir } 47cdf0e10cSrcweir 48cdf0e10cSrcweir 49cdf0e10cSrcweir // ==================== 50cdf0e10cSrcweir // class SvxDefaultColorOptPage 51cdf0e10cSrcweir // ==================== 52cdf0e10cSrcweir SvxDefaultColorOptPage::SvxDefaultColorOptPage( Window* pParent, const SfxItemSet& rInAttrs ) : 53cdf0e10cSrcweir 54cdf0e10cSrcweir SfxTabPage( pParent, CUI_RES( RID_OPTPAGE_CHART_DEFCOLORS ), rInAttrs ), 55cdf0e10cSrcweir 56cdf0e10cSrcweir aGbChartColors ( this, CUI_RES( FL_CHART_COLOR_LIST ) ), 57cdf0e10cSrcweir aLbChartColors ( this, CUI_RES( LB_CHART_COLOR_LIST ) ), 58cdf0e10cSrcweir aGbColorBox ( this, CUI_RES( FL_COLOR_BOX ) ), 59cdf0e10cSrcweir aValSetColorBox ( this, CUI_RES( CT_COLOR_BOX ) ), 60cdf0e10cSrcweir aPBDefault ( this, CUI_RES( PB_RESET_TO_DEFAULT ) ) 61cdf0e10cSrcweir { 62cdf0e10cSrcweir FreeResource(); 63cdf0e10cSrcweir 64cdf0e10cSrcweir aPBDefault.SetClickHdl( LINK( this, SvxDefaultColorOptPage, ResetToDefaults ) ); 65cdf0e10cSrcweir aLbChartColors.SetSelectHdl( LINK( this, SvxDefaultColorOptPage, ListClickedHdl ) ); 66cdf0e10cSrcweir aValSetColorBox.SetSelectHdl( LINK( this, SvxDefaultColorOptPage, BoxClickedHdl ) ); 67cdf0e10cSrcweir 68cdf0e10cSrcweir aValSetColorBox.SetStyle( aValSetColorBox.GetStyle() 69cdf0e10cSrcweir | WB_VSCROLL | WB_ITEMBORDER | WB_NAMEFIELD ); 70cdf0e10cSrcweir aValSetColorBox.SetColCount( 8 ); 71cdf0e10cSrcweir aValSetColorBox.SetLineCount( 12 ); 72cdf0e10cSrcweir aValSetColorBox.SetExtraSpacing( 0 ); 73cdf0e10cSrcweir aValSetColorBox.Show(); 74cdf0e10cSrcweir 75cdf0e10cSrcweir pChartOptions = new SvxChartOptions; 76cdf0e10cSrcweir pColorTab = new XColorTable( SvtPathOptions().GetPalettePath() ); 77cdf0e10cSrcweir 78cdf0e10cSrcweir const SfxPoolItem* pItem = NULL; 79cdf0e10cSrcweir if ( rInAttrs.GetItemState( SID_SCH_EDITOPTIONS, sal_False, &pItem ) == SFX_ITEM_SET ) 80cdf0e10cSrcweir { 81cdf0e10cSrcweir pColorConfig = SAL_STATIC_CAST( SvxChartColorTableItem*, pItem->Clone() ); 82cdf0e10cSrcweir } 83cdf0e10cSrcweir else 84cdf0e10cSrcweir { 85cdf0e10cSrcweir SvxChartColorTable aTable; 86cdf0e10cSrcweir aTable.useDefault(); 87cdf0e10cSrcweir pColorConfig = new SvxChartColorTableItem( SID_SCH_EDITOPTIONS, aTable ); 88cdf0e10cSrcweir pColorConfig->SetOptions( pChartOptions ); 89cdf0e10cSrcweir } 90cdf0e10cSrcweir 91cdf0e10cSrcweir Construct(); 92cdf0e10cSrcweir } 93cdf0e10cSrcweir 94cdf0e10cSrcweir SvxDefaultColorOptPage::~SvxDefaultColorOptPage() 95cdf0e10cSrcweir { 96cdf0e10cSrcweir // save changes 97cdf0e10cSrcweir pChartOptions->SetDefaultColors( pColorConfig->GetColorTable() ); 98cdf0e10cSrcweir pChartOptions->Commit(); 99cdf0e10cSrcweir 100cdf0e10cSrcweir delete pColorConfig; 101cdf0e10cSrcweir delete pColorTab; 102cdf0e10cSrcweir delete pChartOptions; 103cdf0e10cSrcweir } 104cdf0e10cSrcweir 105cdf0e10cSrcweir void SvxDefaultColorOptPage::Construct() 106cdf0e10cSrcweir { 107cdf0e10cSrcweir if( pColorConfig ) 108cdf0e10cSrcweir aLbChartColors.FillBox( pColorConfig->GetColorTable() ); 109cdf0e10cSrcweir 110cdf0e10cSrcweir FillColorBox(); 111cdf0e10cSrcweir 112cdf0e10cSrcweir aLbChartColors.SelectEntryPos( 0 ); 113cdf0e10cSrcweir ListClickedHdl( &aLbChartColors ); 114cdf0e10cSrcweir } 115cdf0e10cSrcweir 116cdf0e10cSrcweir 117cdf0e10cSrcweir SfxTabPage* __EXPORT SvxDefaultColorOptPage::Create( Window* pParent, const SfxItemSet& rAttrs ) 118cdf0e10cSrcweir { 119cdf0e10cSrcweir return new SvxDefaultColorOptPage( pParent, rAttrs ); 120cdf0e10cSrcweir } 121cdf0e10cSrcweir 122cdf0e10cSrcweir sal_Bool __EXPORT SvxDefaultColorOptPage::FillItemSet( SfxItemSet& rOutAttrs ) 123cdf0e10cSrcweir { 124cdf0e10cSrcweir if( pColorConfig ) 125cdf0e10cSrcweir rOutAttrs.Put( *SAL_STATIC_CAST( SfxPoolItem*, pColorConfig )); 126cdf0e10cSrcweir 127cdf0e10cSrcweir return sal_True; 128cdf0e10cSrcweir } 129cdf0e10cSrcweir 130cdf0e10cSrcweir void __EXPORT SvxDefaultColorOptPage::Reset( const SfxItemSet& ) 131cdf0e10cSrcweir { 132cdf0e10cSrcweir aLbChartColors.SelectEntryPos( 0 ); 133cdf0e10cSrcweir ListClickedHdl( &aLbChartColors ); 134cdf0e10cSrcweir } 135cdf0e10cSrcweir 136cdf0e10cSrcweir void SvxDefaultColorOptPage::FillColorBox() 137cdf0e10cSrcweir { 138cdf0e10cSrcweir if( !pColorTab ) return; 139cdf0e10cSrcweir 140cdf0e10cSrcweir long nCount = pColorTab->Count(); 141cdf0e10cSrcweir XColorEntry* pColorEntry; 142cdf0e10cSrcweir 143cdf0e10cSrcweir for( long i = 0; i < nCount; i++ ) 144cdf0e10cSrcweir { 145cdf0e10cSrcweir pColorEntry = pColorTab->GetColor( i ); 146cdf0e10cSrcweir aValSetColorBox.InsertItem( (sal_uInt16) i + 1, pColorEntry->GetColor(), pColorEntry->GetName() ); 147cdf0e10cSrcweir } 148cdf0e10cSrcweir } 149cdf0e10cSrcweir 150cdf0e10cSrcweir 151cdf0e10cSrcweir long SvxDefaultColorOptPage::GetColorIndex( const Color& rCol ) 152cdf0e10cSrcweir { 153cdf0e10cSrcweir if( pColorTab ) 154cdf0e10cSrcweir { 155cdf0e10cSrcweir long nCount = pColorTab->Count(); 156cdf0e10cSrcweir XColorEntry* pColorEntry; 157cdf0e10cSrcweir 158cdf0e10cSrcweir for( long i = nCount - 1; i >= 0; i-- ) // default chart colors are at the end of the table 159cdf0e10cSrcweir { 160cdf0e10cSrcweir pColorEntry = pColorTab->GetColor( i ); 161cdf0e10cSrcweir if( pColorEntry && pColorEntry->GetColor() == rCol ) 162cdf0e10cSrcweir return SAL_STATIC_CAST( XPropertyTable*, pColorTab )->Get( pColorEntry->GetName() ); 163cdf0e10cSrcweir } 164cdf0e10cSrcweir } 165cdf0e10cSrcweir return -1L; 166cdf0e10cSrcweir } 167cdf0e10cSrcweir 168cdf0e10cSrcweir 169cdf0e10cSrcweir 170cdf0e10cSrcweir // -------------------- 171cdf0e10cSrcweir // event handlers 172cdf0e10cSrcweir // -------------------- 173cdf0e10cSrcweir 174cdf0e10cSrcweir // ResetToDefaults 175cdf0e10cSrcweir // --------------- 176cdf0e10cSrcweir 177cdf0e10cSrcweir IMPL_LINK( SvxDefaultColorOptPage, ResetToDefaults, void *, EMPTYARG ) 178cdf0e10cSrcweir { 179cdf0e10cSrcweir if( pColorConfig ) 180cdf0e10cSrcweir { 181cdf0e10cSrcweir pColorConfig->GetColorTable().useDefault(); 182cdf0e10cSrcweir 183cdf0e10cSrcweir aLbChartColors.Clear(); 184cdf0e10cSrcweir aLbChartColors.FillBox( pColorConfig->GetColorTable() ); 185cdf0e10cSrcweir 186cdf0e10cSrcweir aLbChartColors.GetFocus(); 187cdf0e10cSrcweir } 188cdf0e10cSrcweir 189cdf0e10cSrcweir return 0L; 190cdf0e10cSrcweir } 191cdf0e10cSrcweir 192cdf0e10cSrcweir // ListClickedHdl 193cdf0e10cSrcweir // -------------- 194cdf0e10cSrcweir 195cdf0e10cSrcweir IMPL_LINK( SvxDefaultColorOptPage, ListClickedHdl, ChartColorLB*, pColorList ) 196cdf0e10cSrcweir { 197cdf0e10cSrcweir Color aCol = pColorList->GetSelectEntryColor(); 198cdf0e10cSrcweir 199cdf0e10cSrcweir long nIndex = GetColorIndex( aCol ); 200cdf0e10cSrcweir 201cdf0e10cSrcweir if( nIndex == -1 ) // not found 202cdf0e10cSrcweir { 203cdf0e10cSrcweir aValSetColorBox.SetNoSelection(); 204cdf0e10cSrcweir } 205cdf0e10cSrcweir else 206cdf0e10cSrcweir { 207cdf0e10cSrcweir aValSetColorBox.SelectItem( (sal_uInt16)nIndex + 1 ); // ValueSet is 1-based 208cdf0e10cSrcweir } 209cdf0e10cSrcweir 210cdf0e10cSrcweir return 0L; 211cdf0e10cSrcweir } 212cdf0e10cSrcweir 213cdf0e10cSrcweir // BoxClickedHdl 214cdf0e10cSrcweir // ------------- 215cdf0e10cSrcweir 216cdf0e10cSrcweir IMPL_LINK( SvxDefaultColorOptPage, BoxClickedHdl, ValueSet*, EMPTYARG ) 217cdf0e10cSrcweir { 218cdf0e10cSrcweir sal_uInt16 nIdx = aLbChartColors.GetSelectEntryPos(); 219cdf0e10cSrcweir if( nIdx != LISTBOX_ENTRY_NOTFOUND ) 220cdf0e10cSrcweir { 221cdf0e10cSrcweir XColorEntry aEntry( aValSetColorBox.GetItemColor( aValSetColorBox.GetSelectItemId() ), 222cdf0e10cSrcweir aLbChartColors.GetSelectEntry() ); 223cdf0e10cSrcweir 224cdf0e10cSrcweir aLbChartColors.Modify( & aEntry, nIdx ); 225cdf0e10cSrcweir pColorConfig->ReplaceColorByIndex( nIdx, aEntry ); 226cdf0e10cSrcweir 227cdf0e10cSrcweir aLbChartColors.SelectEntryPos( nIdx ); // reselect entry 228cdf0e10cSrcweir } 229cdf0e10cSrcweir 230cdf0e10cSrcweir return 0L; 231cdf0e10cSrcweir } 232cdf0e10cSrcweir 233