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>
32 #include "optchart.hxx"
33 #include "optchart.hrc"
34 #include <dialmgr.hxx>
35 #include <svx/svxids.hrc> // for SID_SCH_EDITOPTIONS
37 // ====================
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
) )
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() );
89 SvxChartColorTable aTable
;
91 pColorConfig
= new SvxChartColorTableItem( SID_SCH_EDITOPTIONS
, aTable
);
92 pColorConfig
->SetOptions( pChartOptions
);
98 SvxDefaultColorOptPage::~SvxDefaultColorOptPage()
101 pChartOptions
->SetDefaultColors( pColorConfig
->GetColorTable() );
102 pChartOptions
->Commit();
106 delete pChartOptions
;
109 void SvxDefaultColorOptPage::Construct()
112 aLbChartColors
.FillBox( pColorConfig
->GetColorTable() );
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
)
129 rOutAttrs
.Put( *SAL_STATIC_CAST( SfxPoolItem
*, pColorConfig
));
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
)
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() );
174 // --------------------
176 // --------------------
181 IMPL_LINK( SvxDefaultColorOptPage
, ResetToDefaults
, void *, EMPTYARG
)
185 pColorConfig
->GetColorTable().useDefault();
187 aLbChartColors
.Clear();
188 aLbChartColors
.FillBox( pColorConfig
->GetColorTable() );
190 aLbChartColors
.GetFocus();
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();
211 aValSetColorBox
.SelectItem( (sal_uInt16
)nIndex
+ 1 ); // ValueSet is 1-based
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