12ee96f1cSAndrew Rist /**************************************************************
2cdf0e10cSrcweir *
32ee96f1cSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one
42ee96f1cSAndrew Rist * or more contributor license agreements. See the NOTICE file
52ee96f1cSAndrew Rist * distributed with this work for additional information
62ee96f1cSAndrew Rist * regarding copyright ownership. The ASF licenses this file
72ee96f1cSAndrew Rist * to you under the Apache License, Version 2.0 (the
82ee96f1cSAndrew Rist * "License"); you may not use this file except in compliance
92ee96f1cSAndrew Rist * with the License. You may obtain a copy of the License at
102ee96f1cSAndrew Rist *
112ee96f1cSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0
122ee96f1cSAndrew Rist *
132ee96f1cSAndrew Rist * Unless required by applicable law or agreed to in writing,
142ee96f1cSAndrew Rist * software distributed under the License is distributed on an
152ee96f1cSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
162ee96f1cSAndrew Rist * KIND, either express or implied. See the License for the
172ee96f1cSAndrew Rist * specific language governing permissions and limitations
182ee96f1cSAndrew Rist * under the License.
192ee96f1cSAndrew Rist *
202ee96f1cSAndrew Rist *************************************************************/
212ee96f1cSAndrew Rist
222ee96f1cSAndrew 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 // ====================
FillBox(const SvxChartColorTable & rTab)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 {
43*3e407bd8SArmin Le Grand Append( rTab[ i ] );
44cdf0e10cSrcweir }
45cdf0e10cSrcweir SetUpdateMode( sal_True );
46cdf0e10cSrcweir }
47cdf0e10cSrcweir
48cdf0e10cSrcweir
49cdf0e10cSrcweir // ====================
50cdf0e10cSrcweir // class SvxDefaultColorOptPage
51cdf0e10cSrcweir // ====================
SvxDefaultColorOptPage(Window * pParent,const SfxItemSet & rInAttrs)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;
76c7be74b1SArmin Le Grand maColorTab = XPropertyListFactory::CreateSharedXColorList(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
~SvxDefaultColorOptPage()94cdf0e10cSrcweir SvxDefaultColorOptPage::~SvxDefaultColorOptPage()
95cdf0e10cSrcweir {
96cdf0e10cSrcweir // save changes
97cdf0e10cSrcweir pChartOptions->SetDefaultColors( pColorConfig->GetColorTable() );
98cdf0e10cSrcweir pChartOptions->Commit();
99cdf0e10cSrcweir
100cdf0e10cSrcweir delete pColorConfig;
101cdf0e10cSrcweir delete pChartOptions;
102cdf0e10cSrcweir }
103cdf0e10cSrcweir
Construct()104cdf0e10cSrcweir void SvxDefaultColorOptPage::Construct()
105cdf0e10cSrcweir {
106cdf0e10cSrcweir if( pColorConfig )
107cdf0e10cSrcweir aLbChartColors.FillBox( pColorConfig->GetColorTable() );
108cdf0e10cSrcweir
109cdf0e10cSrcweir FillColorBox();
110cdf0e10cSrcweir
111cdf0e10cSrcweir aLbChartColors.SelectEntryPos( 0 );
112cdf0e10cSrcweir ListClickedHdl( &aLbChartColors );
113cdf0e10cSrcweir }
114cdf0e10cSrcweir
115cdf0e10cSrcweir
Create(Window * pParent,const SfxItemSet & rAttrs)116cdf0e10cSrcweir SfxTabPage* __EXPORT SvxDefaultColorOptPage::Create( Window* pParent, const SfxItemSet& rAttrs )
117cdf0e10cSrcweir {
118cdf0e10cSrcweir return new SvxDefaultColorOptPage( pParent, rAttrs );
119cdf0e10cSrcweir }
120cdf0e10cSrcweir
FillItemSet(SfxItemSet & rOutAttrs)121cdf0e10cSrcweir sal_Bool __EXPORT SvxDefaultColorOptPage::FillItemSet( SfxItemSet& rOutAttrs )
122cdf0e10cSrcweir {
123cdf0e10cSrcweir if( pColorConfig )
124cdf0e10cSrcweir rOutAttrs.Put( *SAL_STATIC_CAST( SfxPoolItem*, pColorConfig ));
125cdf0e10cSrcweir
126cdf0e10cSrcweir return sal_True;
127cdf0e10cSrcweir }
128cdf0e10cSrcweir
Reset(const SfxItemSet &)129cdf0e10cSrcweir void __EXPORT SvxDefaultColorOptPage::Reset( const SfxItemSet& )
130cdf0e10cSrcweir {
131cdf0e10cSrcweir aLbChartColors.SelectEntryPos( 0 );
132cdf0e10cSrcweir ListClickedHdl( &aLbChartColors );
133cdf0e10cSrcweir }
134cdf0e10cSrcweir
FillColorBox()135cdf0e10cSrcweir void SvxDefaultColorOptPage::FillColorBox()
136cdf0e10cSrcweir {
137c7be74b1SArmin Le Grand if( !maColorTab.get() ) return;
138cdf0e10cSrcweir
139c7be74b1SArmin Le Grand long nCount = maColorTab->Count();
140cdf0e10cSrcweir XColorEntry* pColorEntry;
141cdf0e10cSrcweir
142cdf0e10cSrcweir for( long i = 0; i < nCount; i++ )
143cdf0e10cSrcweir {
144c7be74b1SArmin Le Grand pColorEntry = maColorTab->GetColor( i );
145cdf0e10cSrcweir aValSetColorBox.InsertItem( (sal_uInt16) i + 1, pColorEntry->GetColor(), pColorEntry->GetName() );
146cdf0e10cSrcweir }
147cdf0e10cSrcweir }
148cdf0e10cSrcweir
149cdf0e10cSrcweir
GetColorIndex(const Color & rCol)150cdf0e10cSrcweir long SvxDefaultColorOptPage::GetColorIndex( const Color& rCol )
151cdf0e10cSrcweir {
152c7be74b1SArmin Le Grand if( maColorTab.get() )
153cdf0e10cSrcweir {
154c7be74b1SArmin Le Grand long nCount = maColorTab->Count();
155cdf0e10cSrcweir XColorEntry* pColorEntry;
156cdf0e10cSrcweir
157cdf0e10cSrcweir for( long i = nCount - 1; i >= 0; i-- ) // default chart colors are at the end of the table
158cdf0e10cSrcweir {
159c7be74b1SArmin Le Grand pColorEntry = maColorTab->GetColor( i );
160cdf0e10cSrcweir if( pColorEntry && pColorEntry->GetColor() == rCol )
161c7be74b1SArmin Le Grand return maColorTab->GetIndex( pColorEntry->GetName() );
162cdf0e10cSrcweir }
163cdf0e10cSrcweir }
164cdf0e10cSrcweir return -1L;
165cdf0e10cSrcweir }
166cdf0e10cSrcweir
167cdf0e10cSrcweir
168cdf0e10cSrcweir
169cdf0e10cSrcweir // --------------------
170cdf0e10cSrcweir // event handlers
171cdf0e10cSrcweir // --------------------
172cdf0e10cSrcweir
173cdf0e10cSrcweir // ResetToDefaults
174cdf0e10cSrcweir // ---------------
175cdf0e10cSrcweir
IMPL_LINK(SvxDefaultColorOptPage,ResetToDefaults,void *,EMPTYARG)176cdf0e10cSrcweir IMPL_LINK( SvxDefaultColorOptPage, ResetToDefaults, void *, EMPTYARG )
177cdf0e10cSrcweir {
178cdf0e10cSrcweir if( pColorConfig )
179cdf0e10cSrcweir {
180cdf0e10cSrcweir pColorConfig->GetColorTable().useDefault();
181cdf0e10cSrcweir
182cdf0e10cSrcweir aLbChartColors.Clear();
183cdf0e10cSrcweir aLbChartColors.FillBox( pColorConfig->GetColorTable() );
184cdf0e10cSrcweir
185cdf0e10cSrcweir aLbChartColors.GetFocus();
186cdf0e10cSrcweir }
187cdf0e10cSrcweir
188cdf0e10cSrcweir return 0L;
189cdf0e10cSrcweir }
190cdf0e10cSrcweir
191cdf0e10cSrcweir // ListClickedHdl
192cdf0e10cSrcweir // --------------
193cdf0e10cSrcweir
IMPL_LINK(SvxDefaultColorOptPage,ListClickedHdl,ChartColorLB *,pColorList)194cdf0e10cSrcweir IMPL_LINK( SvxDefaultColorOptPage, ListClickedHdl, ChartColorLB*, pColorList )
195cdf0e10cSrcweir {
196cdf0e10cSrcweir Color aCol = pColorList->GetSelectEntryColor();
197cdf0e10cSrcweir
198cdf0e10cSrcweir long nIndex = GetColorIndex( aCol );
199cdf0e10cSrcweir
200cdf0e10cSrcweir if( nIndex == -1 ) // not found
201cdf0e10cSrcweir {
202cdf0e10cSrcweir aValSetColorBox.SetNoSelection();
203cdf0e10cSrcweir }
204cdf0e10cSrcweir else
205cdf0e10cSrcweir {
206cdf0e10cSrcweir aValSetColorBox.SelectItem( (sal_uInt16)nIndex + 1 ); // ValueSet is 1-based
207cdf0e10cSrcweir }
208cdf0e10cSrcweir
209cdf0e10cSrcweir return 0L;
210cdf0e10cSrcweir }
211cdf0e10cSrcweir
212cdf0e10cSrcweir // BoxClickedHdl
213cdf0e10cSrcweir // -------------
214cdf0e10cSrcweir
IMPL_LINK(SvxDefaultColorOptPage,BoxClickedHdl,ValueSet *,EMPTYARG)215cdf0e10cSrcweir IMPL_LINK( SvxDefaultColorOptPage, BoxClickedHdl, ValueSet*, EMPTYARG )
216cdf0e10cSrcweir {
217cdf0e10cSrcweir sal_uInt16 nIdx = aLbChartColors.GetSelectEntryPos();
218cdf0e10cSrcweir if( nIdx != LISTBOX_ENTRY_NOTFOUND )
219cdf0e10cSrcweir {
220*3e407bd8SArmin Le Grand const XColorEntry aEntry( aValSetColorBox.GetItemColor( aValSetColorBox.GetSelectItemId() ), aLbChartColors.GetSelectEntry() );
221cdf0e10cSrcweir
222*3e407bd8SArmin Le Grand aLbChartColors.Modify( aEntry, nIdx );
223cdf0e10cSrcweir pColorConfig->ReplaceColorByIndex( nIdx, aEntry );
224cdf0e10cSrcweir
225cdf0e10cSrcweir aLbChartColors.SelectEntryPos( nIdx ); // reselect entry
226cdf0e10cSrcweir }
227cdf0e10cSrcweir
228cdf0e10cSrcweir return 0L;
229cdf0e10cSrcweir }
230cdf0e10cSrcweir
231