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