masterfix DEV300: #i10000# build fix
[LibreOffice.git] / cui / source / options / optchart.cxx
blobcfec52f07a591ed5a57ea2337754bd129a147364
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
11 * OpenOffice.org is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License version 3
13 * only, as published by the Free Software Foundation.
15 * OpenOffice.org is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License version 3 for more details
19 * (a copy is included in the LICENSE file that accompanied this code).
21 * You should have received a copy of the GNU Lesser General Public License
22 * version 3 along with OpenOffice.org. If not, see
23 * <http://www.openoffice.org/license.html>
24 * for a copy of the LGPLv3 License.
26 ************************************************************************/
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_cui.hxx"
30 #include <unotools/pathoptions.hxx>
31 #include <cuires.hrc>
32 #include "optchart.hxx"
33 #include "optchart.hrc"
34 #include <dialmgr.hxx>
35 #include <svx/svxids.hrc> // for SID_SCH_EDITOPTIONS
37 // ====================
38 // class ChartColorLB
39 // ====================
40 void ChartColorLB::FillBox( const SvxChartColorTable & rTab )
42 long nCount = rTab.size();
43 SetUpdateMode( sal_False );
45 for( long i = 0; i < nCount; i++ )
47 Append( const_cast< XColorEntry * >( & rTab[ i ] ));
49 SetUpdateMode( sal_True );
53 // ====================
54 // class SvxDefaultColorOptPage
55 // ====================
56 SvxDefaultColorOptPage::SvxDefaultColorOptPage( Window* pParent, const SfxItemSet& rInAttrs ) :
58 SfxTabPage( pParent, CUI_RES( RID_OPTPAGE_CHART_DEFCOLORS ), rInAttrs ),
60 aGbChartColors ( this, CUI_RES( FL_CHART_COLOR_LIST ) ),
61 aLbChartColors ( this, CUI_RES( LB_CHART_COLOR_LIST ) ),
62 aGbColorBox ( this, CUI_RES( FL_COLOR_BOX ) ),
63 aValSetColorBox ( this, CUI_RES( CT_COLOR_BOX ) ),
64 aPBDefault ( this, CUI_RES( PB_RESET_TO_DEFAULT ) )
66 FreeResource();
68 aPBDefault.SetClickHdl( LINK( this, SvxDefaultColorOptPage, ResetToDefaults ) );
69 aLbChartColors.SetSelectHdl( LINK( this, SvxDefaultColorOptPage, ListClickedHdl ) );
70 aValSetColorBox.SetSelectHdl( LINK( this, SvxDefaultColorOptPage, BoxClickedHdl ) );
72 aValSetColorBox.SetStyle( aValSetColorBox.GetStyle()
73 | WB_VSCROLL | WB_ITEMBORDER | WB_NAMEFIELD );
74 aValSetColorBox.SetColCount( 8 );
75 aValSetColorBox.SetLineCount( 12 );
76 aValSetColorBox.SetExtraSpacing( 0 );
77 aValSetColorBox.Show();
79 pChartOptions = new SvxChartOptions;
80 pColorTab = new XColorTable( SvtPathOptions().GetPalettePath() );
82 const SfxPoolItem* pItem = NULL;
83 if ( rInAttrs.GetItemState( SID_SCH_EDITOPTIONS, sal_False, &pItem ) == SFX_ITEM_SET )
85 pColorConfig = SAL_STATIC_CAST( SvxChartColorTableItem*, pItem->Clone() );
87 else
89 SvxChartColorTable aTable;
90 aTable.useDefault();
91 pColorConfig = new SvxChartColorTableItem( SID_SCH_EDITOPTIONS, aTable );
92 pColorConfig->SetOptions( pChartOptions );
95 Construct();
98 SvxDefaultColorOptPage::~SvxDefaultColorOptPage()
100 // save changes
101 pChartOptions->SetDefaultColors( pColorConfig->GetColorTable() );
102 pChartOptions->Commit();
104 delete pColorConfig;
105 delete pColorTab;
106 delete pChartOptions;
109 void SvxDefaultColorOptPage::Construct()
111 if( pColorConfig )
112 aLbChartColors.FillBox( pColorConfig->GetColorTable() );
114 FillColorBox();
116 aLbChartColors.SelectEntryPos( 0 );
117 ListClickedHdl( &aLbChartColors );
121 SfxTabPage* __EXPORT SvxDefaultColorOptPage::Create( Window* pParent, const SfxItemSet& rAttrs )
123 return new SvxDefaultColorOptPage( pParent, rAttrs );
126 sal_Bool __EXPORT SvxDefaultColorOptPage::FillItemSet( SfxItemSet& rOutAttrs )
128 if( pColorConfig )
129 rOutAttrs.Put( *SAL_STATIC_CAST( SfxPoolItem*, pColorConfig ));
131 return sal_True;
134 void __EXPORT SvxDefaultColorOptPage::Reset( const SfxItemSet& )
136 aLbChartColors.SelectEntryPos( 0 );
137 ListClickedHdl( &aLbChartColors );
140 void SvxDefaultColorOptPage::FillColorBox()
142 if( !pColorTab ) return;
144 long nCount = pColorTab->Count();
145 XColorEntry* pColorEntry;
147 for( long i = 0; i < nCount; i++ )
149 pColorEntry = pColorTab->GetColor( i );
150 aValSetColorBox.InsertItem( (sal_uInt16) i + 1, pColorEntry->GetColor(), pColorEntry->GetName() );
155 long SvxDefaultColorOptPage::GetColorIndex( const Color& rCol )
157 if( pColorTab )
159 long nCount = pColorTab->Count();
160 XColorEntry* pColorEntry;
162 for( long i = nCount - 1; i >= 0; i-- ) // default chart colors are at the end of the table
164 pColorEntry = pColorTab->GetColor( i );
165 if( pColorEntry && pColorEntry->GetColor() == rCol )
166 return SAL_STATIC_CAST( XPropertyTable*, pColorTab )->Get( pColorEntry->GetName() );
169 return -1L;
174 // --------------------
175 // event handlers
176 // --------------------
178 // ResetToDefaults
179 // ---------------
181 IMPL_LINK( SvxDefaultColorOptPage, ResetToDefaults, void *, EMPTYARG )
183 if( pColorConfig )
185 pColorConfig->GetColorTable().useDefault();
187 aLbChartColors.Clear();
188 aLbChartColors.FillBox( pColorConfig->GetColorTable() );
190 aLbChartColors.GetFocus();
193 return 0L;
196 // ListClickedHdl
197 // --------------
199 IMPL_LINK( SvxDefaultColorOptPage, ListClickedHdl, ChartColorLB*, pColorList )
201 Color aCol = pColorList->GetSelectEntryColor();
203 long nIndex = GetColorIndex( aCol );
205 if( nIndex == -1 ) // not found
207 aValSetColorBox.SetNoSelection();
209 else
211 aValSetColorBox.SelectItem( (sal_uInt16)nIndex + 1 ); // ValueSet is 1-based
214 return 0L;
217 // BoxClickedHdl
218 // -------------
220 IMPL_LINK( SvxDefaultColorOptPage, BoxClickedHdl, ValueSet*, EMPTYARG )
222 sal_uInt16 nIdx = aLbChartColors.GetSelectEntryPos();
223 if( nIdx != LISTBOX_ENTRY_NOTFOUND )
225 XColorEntry aEntry( aValSetColorBox.GetItemColor( aValSetColorBox.GetSelectItemId() ),
226 aLbChartColors.GetSelectEntry() );
228 aLbChartColors.Modify( & aEntry, nIdx );
229 pColorConfig->ReplaceColorByIndex( nIdx, aEntry );
231 aLbChartColors.SelectEntryPos( nIdx ); // reselect entry
234 return 0L;