1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: optchart.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_svx.hxx"
34 #ifdef SVX_DLLIMPLEMENTATION
35 #undef SVX_DLLIMPLEMENTATION
37 #include <svtools/pathoptions.hxx>
39 #include <svx/dialogs.hrc>
41 #include "optchart.hxx"
42 #include "optchart.hrc"
43 #include <svx/dialmgr.hxx>
45 // ====================
47 // ====================
48 void ChartColorLB::FillBox( const SvxChartColorTable
& rTab
)
50 long nCount
= rTab
.size();
51 SetUpdateMode( FALSE
);
53 for( long i
= 0; i
< nCount
; i
++ )
55 Append( const_cast< XColorEntry
* >( & rTab
[ i
] ));
57 SetUpdateMode( TRUE
);
61 // ====================
62 // class SvxDefaultColorOptPage
63 // ====================
64 SvxDefaultColorOptPage::SvxDefaultColorOptPage( Window
* pParent
, const SfxItemSet
& rInAttrs
) :
66 SfxTabPage( pParent
, SVX_RES( RID_OPTPAGE_CHART_DEFCOLORS
), rInAttrs
),
68 aGbChartColors ( this, SVX_RES( FL_CHART_COLOR_LIST
) ),
69 aLbChartColors ( this, SVX_RES( LB_CHART_COLOR_LIST
) ),
70 aGbColorBox ( this, SVX_RES( FL_COLOR_BOX
) ),
71 aValSetColorBox ( this, SVX_RES( CT_COLOR_BOX
) ),
72 aPBDefault ( this, SVX_RES( PB_RESET_TO_DEFAULT
) )
76 aPBDefault
.SetClickHdl( LINK( this, SvxDefaultColorOptPage
, ResetToDefaults
) );
77 aLbChartColors
.SetSelectHdl( LINK( this, SvxDefaultColorOptPage
, ListClickedHdl
) );
78 aValSetColorBox
.SetSelectHdl( LINK( this, SvxDefaultColorOptPage
, BoxClickedHdl
) );
80 aValSetColorBox
.SetStyle( aValSetColorBox
.GetStyle()
81 | WB_VSCROLL
| WB_ITEMBORDER
| WB_NAMEFIELD
);
82 aValSetColorBox
.SetColCount( 8 );
83 aValSetColorBox
.SetLineCount( 12 );
84 aValSetColorBox
.SetExtraSpacing( 0 );
85 aValSetColorBox
.Show();
87 pChartOptions
= new SvxChartOptions
;
88 pColorTab
= new XColorTable( SvtPathOptions().GetPalettePath() );
90 const SfxPoolItem
* pItem
= NULL
;
91 if ( rInAttrs
.GetItemState( SID_SCH_EDITOPTIONS
, FALSE
, &pItem
) == SFX_ITEM_SET
)
93 pColorConfig
= SAL_STATIC_CAST( SvxChartColorTableItem
*, pItem
->Clone() );
97 SvxChartColorTable aTable
;
99 pColorConfig
= new SvxChartColorTableItem( SID_SCH_EDITOPTIONS
, aTable
);
100 pColorConfig
->SetOptions( pChartOptions
);
106 SvxDefaultColorOptPage::~SvxDefaultColorOptPage()
109 pChartOptions
->SetDefaultColors( pColorConfig
->GetColorTable() );
110 pChartOptions
->Commit();
114 delete pChartOptions
;
117 void SvxDefaultColorOptPage::Construct()
120 aLbChartColors
.FillBox( pColorConfig
->GetColorTable() );
124 aLbChartColors
.SelectEntryPos( 0 );
125 ListClickedHdl( &aLbChartColors
);
129 SfxTabPage
* __EXPORT
SvxDefaultColorOptPage::Create( Window
* pParent
, const SfxItemSet
& rAttrs
)
131 return new SvxDefaultColorOptPage( pParent
, rAttrs
);
134 BOOL __EXPORT
SvxDefaultColorOptPage::FillItemSet( SfxItemSet
& rOutAttrs
)
137 rOutAttrs
.Put( *SAL_STATIC_CAST( SfxPoolItem
*, pColorConfig
));
142 void __EXPORT
SvxDefaultColorOptPage::Reset( const SfxItemSet
& )
144 aLbChartColors
.SelectEntryPos( 0 );
145 ListClickedHdl( &aLbChartColors
);
148 void SvxDefaultColorOptPage::FillColorBox()
150 if( !pColorTab
) return;
152 long nCount
= pColorTab
->Count();
153 XColorEntry
* pColorEntry
;
155 for( long i
= 0; i
< nCount
; i
++ )
157 pColorEntry
= pColorTab
->GetColor( i
);
158 aValSetColorBox
.InsertItem( (USHORT
) i
+ 1, pColorEntry
->GetColor(), pColorEntry
->GetName() );
163 long SvxDefaultColorOptPage::GetColorIndex( const Color
& rCol
)
167 long nCount
= pColorTab
->Count();
168 XColorEntry
* pColorEntry
;
170 for( long i
= nCount
- 1; i
>= 0; i
-- ) // default chart colors are at the end of the table
172 pColorEntry
= pColorTab
->GetColor( i
);
173 if( pColorEntry
&& pColorEntry
->GetColor() == rCol
)
174 return SAL_STATIC_CAST( XPropertyTable
*, pColorTab
)->Get( pColorEntry
->GetName() );
182 // --------------------
184 // --------------------
189 IMPL_LINK( SvxDefaultColorOptPage
, ResetToDefaults
, void *, EMPTYARG
)
193 pColorConfig
->GetColorTable().useDefault();
195 aLbChartColors
.Clear();
196 aLbChartColors
.FillBox( pColorConfig
->GetColorTable() );
198 aLbChartColors
.GetFocus();
207 IMPL_LINK( SvxDefaultColorOptPage
, ListClickedHdl
, ChartColorLB
*, pColorList
)
209 Color aCol
= pColorList
->GetSelectEntryColor();
211 long nIndex
= GetColorIndex( aCol
);
213 if( nIndex
== -1 ) // not found
215 aValSetColorBox
.SetNoSelection();
219 aValSetColorBox
.SelectItem( (USHORT
)nIndex
+ 1 ); // ValueSet is 1-based
228 IMPL_LINK( SvxDefaultColorOptPage
, BoxClickedHdl
, ValueSet
*, EMPTYARG
)
230 USHORT nIdx
= aLbChartColors
.GetSelectEntryPos();
231 if( nIdx
!= LISTBOX_ENTRY_NOTFOUND
)
233 XColorEntry
aEntry( aValSetColorBox
.GetItemColor( aValSetColorBox
.GetSelectItemId() ),
234 aLbChartColors
.GetSelectEntry() );
236 aLbChartColors
.Modify( & aEntry
, nIdx
);
237 pColorConfig
->ReplaceColorByIndex( nIdx
, aEntry
);
239 aLbChartColors
.SelectEntryPos( nIdx
); // reselect entry