xref: /AOO41X/main/cui/source/options/optchart.cxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
29*cdf0e10cSrcweir #include "precompiled_cui.hxx"
30*cdf0e10cSrcweir #include <unotools/pathoptions.hxx>
31*cdf0e10cSrcweir #include <cuires.hrc>
32*cdf0e10cSrcweir #include "optchart.hxx"
33*cdf0e10cSrcweir #include "optchart.hrc"
34*cdf0e10cSrcweir #include <dialmgr.hxx>
35*cdf0e10cSrcweir #include <svx/svxids.hrc> // for SID_SCH_EDITOPTIONS
36*cdf0e10cSrcweir 
37*cdf0e10cSrcweir // ====================
38*cdf0e10cSrcweir // class ChartColorLB
39*cdf0e10cSrcweir // ====================
40*cdf0e10cSrcweir void ChartColorLB::FillBox( const SvxChartColorTable & rTab )
41*cdf0e10cSrcweir {
42*cdf0e10cSrcweir     long nCount = rTab.size();
43*cdf0e10cSrcweir 	SetUpdateMode( sal_False );
44*cdf0e10cSrcweir 
45*cdf0e10cSrcweir 	for( long i = 0; i < nCount; i++ )
46*cdf0e10cSrcweir 	{
47*cdf0e10cSrcweir         Append( const_cast< XColorEntry * >( & rTab[ i ] ));
48*cdf0e10cSrcweir 	}
49*cdf0e10cSrcweir 	SetUpdateMode( sal_True );
50*cdf0e10cSrcweir }
51*cdf0e10cSrcweir 
52*cdf0e10cSrcweir 
53*cdf0e10cSrcweir // ====================
54*cdf0e10cSrcweir // class SvxDefaultColorOptPage
55*cdf0e10cSrcweir // ====================
56*cdf0e10cSrcweir SvxDefaultColorOptPage::SvxDefaultColorOptPage( Window* pParent, const SfxItemSet& rInAttrs ) :
57*cdf0e10cSrcweir 
58*cdf0e10cSrcweir 	SfxTabPage( pParent, CUI_RES( RID_OPTPAGE_CHART_DEFCOLORS ), rInAttrs ),
59*cdf0e10cSrcweir 
60*cdf0e10cSrcweir 	aGbChartColors	( this, CUI_RES( FL_CHART_COLOR_LIST ) ),
61*cdf0e10cSrcweir 	aLbChartColors	( this, CUI_RES( LB_CHART_COLOR_LIST ) ),
62*cdf0e10cSrcweir 	aGbColorBox		( this, CUI_RES( FL_COLOR_BOX ) ),
63*cdf0e10cSrcweir 	aValSetColorBox	( this, CUI_RES( CT_COLOR_BOX ) ),
64*cdf0e10cSrcweir 	aPBDefault		( this, CUI_RES( PB_RESET_TO_DEFAULT ) )
65*cdf0e10cSrcweir {
66*cdf0e10cSrcweir 	FreeResource();
67*cdf0e10cSrcweir 
68*cdf0e10cSrcweir 	aPBDefault.SetClickHdl( LINK( this, SvxDefaultColorOptPage, ResetToDefaults ) );
69*cdf0e10cSrcweir 	aLbChartColors.SetSelectHdl( LINK( this, SvxDefaultColorOptPage, ListClickedHdl ) );
70*cdf0e10cSrcweir 	aValSetColorBox.SetSelectHdl( LINK( this, SvxDefaultColorOptPage, BoxClickedHdl ) );
71*cdf0e10cSrcweir 
72*cdf0e10cSrcweir 	aValSetColorBox.SetStyle( aValSetColorBox.GetStyle()
73*cdf0e10cSrcweir 									| WB_VSCROLL | WB_ITEMBORDER | WB_NAMEFIELD );
74*cdf0e10cSrcweir 	aValSetColorBox.SetColCount( 8 );
75*cdf0e10cSrcweir 	aValSetColorBox.SetLineCount( 12 );
76*cdf0e10cSrcweir 	aValSetColorBox.SetExtraSpacing( 0 );
77*cdf0e10cSrcweir 	aValSetColorBox.Show();
78*cdf0e10cSrcweir 
79*cdf0e10cSrcweir 	pChartOptions = new SvxChartOptions;
80*cdf0e10cSrcweir 	pColorTab = new XColorTable( SvtPathOptions().GetPalettePath() );
81*cdf0e10cSrcweir 
82*cdf0e10cSrcweir 	const SfxPoolItem* pItem = NULL;
83*cdf0e10cSrcweir 	if ( rInAttrs.GetItemState( SID_SCH_EDITOPTIONS, sal_False, &pItem ) == SFX_ITEM_SET )
84*cdf0e10cSrcweir 	{
85*cdf0e10cSrcweir 		pColorConfig = SAL_STATIC_CAST( SvxChartColorTableItem*, pItem->Clone() );
86*cdf0e10cSrcweir 	}
87*cdf0e10cSrcweir 	else
88*cdf0e10cSrcweir 	{
89*cdf0e10cSrcweir 		SvxChartColorTable aTable;
90*cdf0e10cSrcweir 		aTable.useDefault();
91*cdf0e10cSrcweir 		pColorConfig = new SvxChartColorTableItem( SID_SCH_EDITOPTIONS, aTable );
92*cdf0e10cSrcweir 		pColorConfig->SetOptions( pChartOptions );
93*cdf0e10cSrcweir 	}
94*cdf0e10cSrcweir 
95*cdf0e10cSrcweir 	Construct();
96*cdf0e10cSrcweir }
97*cdf0e10cSrcweir 
98*cdf0e10cSrcweir SvxDefaultColorOptPage::~SvxDefaultColorOptPage()
99*cdf0e10cSrcweir {
100*cdf0e10cSrcweir 	// save changes
101*cdf0e10cSrcweir 	pChartOptions->SetDefaultColors( pColorConfig->GetColorTable() );
102*cdf0e10cSrcweir 	pChartOptions->Commit();
103*cdf0e10cSrcweir 
104*cdf0e10cSrcweir 	delete pColorConfig;
105*cdf0e10cSrcweir 	delete pColorTab;
106*cdf0e10cSrcweir 	delete pChartOptions;
107*cdf0e10cSrcweir }
108*cdf0e10cSrcweir 
109*cdf0e10cSrcweir void SvxDefaultColorOptPage::Construct()
110*cdf0e10cSrcweir {
111*cdf0e10cSrcweir 	if( pColorConfig )
112*cdf0e10cSrcweir 		aLbChartColors.FillBox( pColorConfig->GetColorTable() );
113*cdf0e10cSrcweir 
114*cdf0e10cSrcweir 	FillColorBox();
115*cdf0e10cSrcweir 
116*cdf0e10cSrcweir 	aLbChartColors.SelectEntryPos( 0 );
117*cdf0e10cSrcweir 	ListClickedHdl( &aLbChartColors );
118*cdf0e10cSrcweir }
119*cdf0e10cSrcweir 
120*cdf0e10cSrcweir 
121*cdf0e10cSrcweir SfxTabPage* __EXPORT SvxDefaultColorOptPage::Create( Window* pParent, const SfxItemSet& rAttrs )
122*cdf0e10cSrcweir {
123*cdf0e10cSrcweir 	return new SvxDefaultColorOptPage( pParent, rAttrs );
124*cdf0e10cSrcweir }
125*cdf0e10cSrcweir 
126*cdf0e10cSrcweir sal_Bool __EXPORT SvxDefaultColorOptPage::FillItemSet( SfxItemSet& rOutAttrs )
127*cdf0e10cSrcweir {
128*cdf0e10cSrcweir 	if( pColorConfig )
129*cdf0e10cSrcweir 		rOutAttrs.Put( *SAL_STATIC_CAST( SfxPoolItem*, pColorConfig ));
130*cdf0e10cSrcweir 
131*cdf0e10cSrcweir 	return sal_True;
132*cdf0e10cSrcweir }
133*cdf0e10cSrcweir 
134*cdf0e10cSrcweir void __EXPORT SvxDefaultColorOptPage::Reset( const SfxItemSet& )
135*cdf0e10cSrcweir {
136*cdf0e10cSrcweir 	aLbChartColors.SelectEntryPos( 0 );
137*cdf0e10cSrcweir 	ListClickedHdl( &aLbChartColors );
138*cdf0e10cSrcweir }
139*cdf0e10cSrcweir 
140*cdf0e10cSrcweir void SvxDefaultColorOptPage::FillColorBox()
141*cdf0e10cSrcweir {
142*cdf0e10cSrcweir 	if( !pColorTab ) return;
143*cdf0e10cSrcweir 
144*cdf0e10cSrcweir 	long nCount = pColorTab->Count();
145*cdf0e10cSrcweir 	XColorEntry* pColorEntry;
146*cdf0e10cSrcweir 
147*cdf0e10cSrcweir 	for( long i = 0; i < nCount; i++ )
148*cdf0e10cSrcweir 	{
149*cdf0e10cSrcweir 		pColorEntry = pColorTab->GetColor( i );
150*cdf0e10cSrcweir 		aValSetColorBox.InsertItem( (sal_uInt16) i + 1, pColorEntry->GetColor(), pColorEntry->GetName() );
151*cdf0e10cSrcweir 	}
152*cdf0e10cSrcweir }
153*cdf0e10cSrcweir 
154*cdf0e10cSrcweir 
155*cdf0e10cSrcweir long SvxDefaultColorOptPage::GetColorIndex( const Color& rCol )
156*cdf0e10cSrcweir {
157*cdf0e10cSrcweir 	if( pColorTab )
158*cdf0e10cSrcweir 	{
159*cdf0e10cSrcweir 		long nCount = pColorTab->Count();
160*cdf0e10cSrcweir 		XColorEntry* pColorEntry;
161*cdf0e10cSrcweir 
162*cdf0e10cSrcweir 		for( long i = nCount - 1; i >= 0; i-- )			// default chart colors are at the end of the table
163*cdf0e10cSrcweir 		{
164*cdf0e10cSrcweir 			pColorEntry = pColorTab->GetColor( i );
165*cdf0e10cSrcweir 			if( pColorEntry && pColorEntry->GetColor() == rCol )
166*cdf0e10cSrcweir 				return SAL_STATIC_CAST( XPropertyTable*, pColorTab )->Get( pColorEntry->GetName() );
167*cdf0e10cSrcweir 		}
168*cdf0e10cSrcweir 	}
169*cdf0e10cSrcweir 	return -1L;
170*cdf0e10cSrcweir }
171*cdf0e10cSrcweir 
172*cdf0e10cSrcweir 
173*cdf0e10cSrcweir 
174*cdf0e10cSrcweir // --------------------
175*cdf0e10cSrcweir // event handlers
176*cdf0e10cSrcweir // --------------------
177*cdf0e10cSrcweir 
178*cdf0e10cSrcweir // ResetToDefaults
179*cdf0e10cSrcweir // ---------------
180*cdf0e10cSrcweir 
181*cdf0e10cSrcweir IMPL_LINK( SvxDefaultColorOptPage, ResetToDefaults, void *, EMPTYARG )
182*cdf0e10cSrcweir {
183*cdf0e10cSrcweir     if( pColorConfig )
184*cdf0e10cSrcweir     {
185*cdf0e10cSrcweir         pColorConfig->GetColorTable().useDefault();
186*cdf0e10cSrcweir 
187*cdf0e10cSrcweir         aLbChartColors.Clear();
188*cdf0e10cSrcweir         aLbChartColors.FillBox( pColorConfig->GetColorTable() );
189*cdf0e10cSrcweir 
190*cdf0e10cSrcweir         aLbChartColors.GetFocus();
191*cdf0e10cSrcweir     }
192*cdf0e10cSrcweir 
193*cdf0e10cSrcweir 	return 0L;
194*cdf0e10cSrcweir }
195*cdf0e10cSrcweir 
196*cdf0e10cSrcweir // ListClickedHdl
197*cdf0e10cSrcweir // --------------
198*cdf0e10cSrcweir 
199*cdf0e10cSrcweir IMPL_LINK( SvxDefaultColorOptPage, ListClickedHdl, ChartColorLB*,  pColorList )
200*cdf0e10cSrcweir {
201*cdf0e10cSrcweir 	Color aCol = pColorList->GetSelectEntryColor();
202*cdf0e10cSrcweir 
203*cdf0e10cSrcweir 	long nIndex = GetColorIndex( aCol );
204*cdf0e10cSrcweir 
205*cdf0e10cSrcweir 	if( nIndex == -1 )		// not found
206*cdf0e10cSrcweir 	{
207*cdf0e10cSrcweir 		aValSetColorBox.SetNoSelection();
208*cdf0e10cSrcweir 	}
209*cdf0e10cSrcweir 	else
210*cdf0e10cSrcweir 	{
211*cdf0e10cSrcweir 		aValSetColorBox.SelectItem( (sal_uInt16)nIndex + 1 );		// ValueSet is 1-based
212*cdf0e10cSrcweir 	}
213*cdf0e10cSrcweir 
214*cdf0e10cSrcweir 	return 0L;
215*cdf0e10cSrcweir }
216*cdf0e10cSrcweir 
217*cdf0e10cSrcweir // BoxClickedHdl
218*cdf0e10cSrcweir // -------------
219*cdf0e10cSrcweir 
220*cdf0e10cSrcweir IMPL_LINK( SvxDefaultColorOptPage, BoxClickedHdl, ValueSet*, EMPTYARG )
221*cdf0e10cSrcweir {
222*cdf0e10cSrcweir 	sal_uInt16 nIdx = aLbChartColors.GetSelectEntryPos();
223*cdf0e10cSrcweir 	if( nIdx != LISTBOX_ENTRY_NOTFOUND )
224*cdf0e10cSrcweir 	{
225*cdf0e10cSrcweir 		XColorEntry aEntry( aValSetColorBox.GetItemColor( aValSetColorBox.GetSelectItemId() ),
226*cdf0e10cSrcweir                             aLbChartColors.GetSelectEntry() );
227*cdf0e10cSrcweir 
228*cdf0e10cSrcweir 		aLbChartColors.Modify( & aEntry, nIdx );
229*cdf0e10cSrcweir 		pColorConfig->ReplaceColorByIndex( nIdx, aEntry );
230*cdf0e10cSrcweir 
231*cdf0e10cSrcweir         aLbChartColors.SelectEntryPos( nIdx );	// reselect entry
232*cdf0e10cSrcweir 	}
233*cdf0e10cSrcweir 
234*cdf0e10cSrcweir     return 0L;
235*cdf0e10cSrcweir }
236*cdf0e10cSrcweir 
237