1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <unotools/pathoptions.hxx>
22 #include "optchart.hxx"
23 #include "optchart.hrc"
24 #include <dialmgr.hxx>
25 #include <vcl/msgbox.hxx>
26 #include <svx/svxids.hrc> // for SID_SCH_EDITOPTIONS
28 // ====================
30 // ====================
31 void ChartColorLB::FillBox( const SvxChartColorTable
& rTab
)
33 long nCount
= rTab
.size();
34 SetUpdateMode( sal_False
);
36 for( long i
= 0; i
< nCount
; i
++ )
38 Append( const_cast< XColorEntry
* >( & rTab
[ i
] ));
40 SetUpdateMode( sal_True
);
44 // ====================
45 // class SvxDefaultColorOptPage
46 // ====================
47 SvxDefaultColorOptPage::SvxDefaultColorOptPage( Window
* pParent
, const SfxItemSet
& rInAttrs
) :
49 SfxTabPage( pParent
, CUI_RES( RID_OPTPAGE_CHART_DEFCOLORS
), rInAttrs
),
51 aGbChartColors ( this, CUI_RES( FL_CHART_COLOR_LIST
) ),
52 aLbChartColors ( this, CUI_RES( LB_CHART_COLOR_LIST
) ),
53 aGbColorBox ( this, CUI_RES( FL_COLOR_BOX
) ),
54 aValSetColorBox ( this, CUI_RES( CT_COLOR_BOX
) ),
55 aPBDefault ( this, CUI_RES( PB_RESET_TO_DEFAULT
) ),
56 aPBAdd ( this, CUI_RES( PB_ADD_CHART_COLOR
) ),
57 aPBRemove ( this, CUI_RES( PB_REMOVE_CHART_COLOR
) )
61 aPBDefault
.SetClickHdl( LINK( this, SvxDefaultColorOptPage
, ResetToDefaults
) );
62 aPBAdd
.SetClickHdl( LINK( this, SvxDefaultColorOptPage
, AddChartColor
) );
63 aPBRemove
.SetClickHdl( LINK( this, SvxDefaultColorOptPage
, RemoveChartColor
) );
64 aLbChartColors
.SetSelectHdl( LINK( this, SvxDefaultColorOptPage
, ListClickedHdl
) );
65 aValSetColorBox
.SetSelectHdl( LINK( this, SvxDefaultColorOptPage
, BoxClickedHdl
) );
67 aValSetColorBox
.SetStyle( aValSetColorBox
.GetStyle()
68 | WB_ITEMBORDER
| WB_NAMEFIELD
);
69 aValSetColorBox
.SetColCount( 8 );
70 aValSetColorBox
.SetLineCount( 13 );
71 aValSetColorBox
.SetExtraSpacing( 0 );
72 aValSetColorBox
.Show();
74 pChartOptions
= new SvxChartOptions
;
75 pColorList
= XColorList::CreateStdColorList();
77 const SfxPoolItem
* pItem
= NULL
;
78 if ( rInAttrs
.GetItemState( SID_SCH_EDITOPTIONS
, sal_False
, &pItem
) == SFX_ITEM_SET
)
80 pColorConfig
= (static_cast< SvxChartColorTableItem
* >(pItem
->Clone()) );
84 SvxChartColorTable aTable
;
86 pColorConfig
= new SvxChartColorTableItem( SID_SCH_EDITOPTIONS
, aTable
);
87 pColorConfig
->SetOptions( pChartOptions
);
93 SvxDefaultColorOptPage::~SvxDefaultColorOptPage()
96 pChartOptions
->SetDefaultColors( pColorConfig
->GetColorList() );
97 pChartOptions
->Commit();
100 delete pChartOptions
;
103 void SvxDefaultColorOptPage::Construct()
106 aLbChartColors
.FillBox( pColorConfig
->GetColorList() );
110 aLbChartColors
.SelectEntryPos( 0 );
111 ListClickedHdl( &aLbChartColors
);
115 SfxTabPage
* SvxDefaultColorOptPage::Create( Window
* pParent
, const SfxItemSet
& rAttrs
)
117 return new SvxDefaultColorOptPage( pParent
, rAttrs
);
120 sal_Bool
SvxDefaultColorOptPage::FillItemSet( SfxItemSet
& rOutAttrs
)
123 rOutAttrs
.Put( *(static_cast< SfxPoolItem
* >(pColorConfig
)));
128 void SvxDefaultColorOptPage::Reset( const SfxItemSet
& )
130 aLbChartColors
.SelectEntryPos( 0 );
131 ListClickedHdl( &aLbChartColors
);
134 void SvxDefaultColorOptPage::FillColorBox()
136 if( !pColorList
.is() ) return;
138 long nCount
= pColorList
->Count();
139 XColorEntry
* pColorEntry
;
142 aValSetColorBox
.SetStyle( aValSetColorBox
.GetStyle() | WB_VSCROLL
);
144 for( long i
= 0; i
< nCount
; i
++ )
146 pColorEntry
= pColorList
->GetColor( i
);
147 aValSetColorBox
.InsertItem( (sal_uInt16
) i
+ 1, pColorEntry
->GetColor(), pColorEntry
->GetName() );
152 long SvxDefaultColorOptPage::GetColorIndex( const Color
& rCol
)
154 if( pColorList
.is() )
156 long nCount
= pColorList
->Count();
157 XColorEntry
* pColorEntry
;
159 for( long i
= nCount
- 1; i
>= 0; i
-- ) // default chart colors are at the end of the table
161 pColorEntry
= pColorList
->GetColor( i
);
162 if( pColorEntry
&& pColorEntry
->GetColor() == rCol
)
163 return pColorList
->Get( pColorEntry
->GetName() );
171 // --------------------
173 // --------------------
178 IMPL_LINK_NOARG(SvxDefaultColorOptPage
, ResetToDefaults
)
182 pColorConfig
->GetColorList().useDefault();
184 aLbChartColors
.Clear();
185 aLbChartColors
.FillBox( pColorConfig
->GetColorList() );
187 aLbChartColors
.GetFocus();
188 aLbChartColors
.SelectEntryPos( 0 );
189 aPBRemove
.Enable( sal_True
);
198 IMPL_LINK_NOARG(SvxDefaultColorOptPage
, AddChartColor
)
202 ColorData black
= RGB_COLORDATA( 0x00, 0x00, 0x00 );
204 pColorConfig
->GetColorList().append (XColorEntry ( black
, pColorConfig
->GetColorList().getDefaultName(pColorConfig
->GetColorList().size())));
206 aLbChartColors
.Clear();
207 aLbChartColors
.FillBox( pColorConfig
->GetColorList() );
209 aLbChartColors
.GetFocus();
210 aLbChartColors
.SelectEntryPos( pColorConfig
->GetColorList().size() - 1 );
211 aPBRemove
.Enable( sal_True
);
220 IMPL_LINK( SvxDefaultColorOptPage
, RemoveChartColor
, PushButton
*, pButton
)
222 size_t nIndex
= aLbChartColors
.GetSelectEntryPos();
224 if (aLbChartColors
.GetSelectEntryCount() == 0)
229 OSL_ENSURE(pColorConfig
->GetColorList().size() > 1, "don't delete the last chart color");
230 QueryBox
aQuery(pButton
, CUI_RES(RID_OPTQB_COLOR_CHART_DELETE
));
231 aQuery
.SetText(String(CUI_RES(RID_OPTSTR_COLOR_CHART_DELETE
)));
232 if(RET_YES
== aQuery
.Execute())
235 pColorConfig
->GetColorList().remove( nIndex
);
237 aLbChartColors
.Clear();
238 aLbChartColors
.FillBox( pColorConfig
->GetColorList() );
240 aLbChartColors
.GetFocus();
242 if (nIndex
== aLbChartColors
.GetEntryCount() && aLbChartColors
.GetEntryCount() > 0)
243 aLbChartColors
.SelectEntryPos( pColorConfig
->GetColorList().size() - 1 );
244 else if (aLbChartColors
.GetEntryCount() > 0)
245 aLbChartColors
.SelectEntryPos( nIndex
);
247 aPBRemove
.Enable( sal_False
);
254 IMPL_LINK( SvxDefaultColorOptPage
, ListClickedHdl
, ChartColorLB
*, _pColorList
)
256 Color aCol
= _pColorList
->GetSelectEntryColor();
258 long nIndex
= GetColorIndex( aCol
);
260 if( nIndex
== -1 ) // not found
261 aValSetColorBox
.SetNoSelection();
263 aValSetColorBox
.SelectItem( (sal_uInt16
)nIndex
+ 1 ); // ValueSet is 1-based
268 IMPL_LINK_NOARG(SvxDefaultColorOptPage
, BoxClickedHdl
)
270 sal_uInt16 nIdx
= aLbChartColors
.GetSelectEntryPos();
271 if( nIdx
!= LISTBOX_ENTRY_NOTFOUND
)
273 XColorEntry
aEntry( aValSetColorBox
.GetItemColor( aValSetColorBox
.GetSelectItemId() ),
274 aLbChartColors
.GetSelectEntry() );
276 aLbChartColors
.Modify( & aEntry
, nIdx
);
277 pColorConfig
->ReplaceColorByIndex( nIdx
, aEntry
);
279 aLbChartColors
.SelectEntryPos( nIdx
); // reselect entry
285 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */