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 <dialmgr.hxx>
24 #include <vcl/msgbox.hxx>
25 #include <svx/svxids.hrc>
29 void FillBoxChartColorLB(ColorLB
*pLB
, const SvxChartColorTable
& rTab
)
31 pLB
->SetUpdateMode(false);
33 long nCount
= rTab
.size();
34 for(long i
= 0; i
< nCount
; ++i
)
38 pLB
->SetUpdateMode(true);
42 SvxDefaultColorOptPage::SvxDefaultColorOptPage(vcl::Window
* pParent
, const SfxItemSet
& rInAttrs
)
43 : SfxTabPage(pParent
, "OptChartColorsPage","cui/ui/optchartcolorspage.ui", &rInAttrs
)
45 get(m_pPBRemove
, "delete");
47 get(m_pPBDefault
, "default");
48 get(m_pValSetColorBox
, "table");
49 get(m_pLbChartColors
, "colors");
50 m_pLbChartColors
->set_height_request(m_pLbChartColors
->GetTextHeight()*16);
52 m_pPBDefault
->SetClickHdl( LINK( this, SvxDefaultColorOptPage
, ResetToDefaults
) );
53 m_pPBAdd
->SetClickHdl( LINK( this, SvxDefaultColorOptPage
, AddChartColor
) );
54 m_pPBRemove
->SetClickHdl( LINK( this, SvxDefaultColorOptPage
, RemoveChartColor
) );
55 m_pLbChartColors
->SetSelectHdl( LINK( this, SvxDefaultColorOptPage
, ListClickedHdl
) );
56 m_pValSetColorBox
->SetSelectHdl( LINK( this, SvxDefaultColorOptPage
, BoxClickedHdl
) );
58 m_pValSetColorBox
->SetStyle( m_pValSetColorBox
->GetStyle()
59 | WB_ITEMBORDER
| WB_NAMEFIELD
);
60 m_pValSetColorBox
->SetColCount( 8 );
61 m_pValSetColorBox
->SetLineCount( 14 );
62 m_pValSetColorBox
->SetExtraSpacing( 0 );
63 m_pValSetColorBox
->Show();
65 pChartOptions
= new SvxChartOptions
;
66 pColorList
= XColorList::CreateStdColorList();
68 const SfxPoolItem
* pItem
= NULL
;
69 if ( rInAttrs
.GetItemState( SID_SCH_EDITOPTIONS
, false, &pItem
) == SfxItemState::SET
)
71 pColorConfig
= (static_cast< SvxChartColorTableItem
* >(pItem
->Clone()) );
75 SvxChartColorTable aTable
;
77 pColorConfig
= new SvxChartColorTableItem( SID_SCH_EDITOPTIONS
, aTable
);
78 pColorConfig
->SetOptions( pChartOptions
);
84 SvxDefaultColorOptPage::~SvxDefaultColorOptPage()
89 void SvxDefaultColorOptPage::dispose()
94 pChartOptions
->SetDefaultColors( pColorConfig
->GetColorList() );
95 pChartOptions
->Commit();
100 pChartOptions
= NULL
;
102 m_pLbChartColors
.clear();
103 m_pValSetColorBox
.clear();
104 m_pPBDefault
.clear();
107 SfxTabPage::dispose();
110 void SvxDefaultColorOptPage::Construct()
113 FillBoxChartColorLB(m_pLbChartColors
, pColorConfig
->GetColorList());
117 m_pLbChartColors
->SelectEntryPos( 0 );
118 ListClickedHdl(m_pLbChartColors
);
122 VclPtr
<SfxTabPage
> SvxDefaultColorOptPage::Create( vcl::Window
* pParent
, const SfxItemSet
* rAttrs
)
124 return VclPtr
<SvxDefaultColorOptPage
>::Create( pParent
, *rAttrs
);
127 bool SvxDefaultColorOptPage::FillItemSet( SfxItemSet
* rOutAttrs
)
130 rOutAttrs
->Put( *(static_cast< SfxPoolItem
* >(pColorConfig
)));
135 void SvxDefaultColorOptPage::Reset( const SfxItemSet
* )
137 m_pLbChartColors
->SelectEntryPos( 0 );
138 ListClickedHdl(m_pLbChartColors
);
141 void SvxDefaultColorOptPage::FillColorBox()
143 if( !pColorList
.is() ) return;
145 long nCount
= pColorList
->Count();
148 m_pValSetColorBox
->SetStyle( m_pValSetColorBox
->GetStyle() | WB_VSCROLL
);
150 for( long i
= 0; i
< nCount
; i
++ )
152 XColorEntry
* pColorEntry
= pColorList
->GetColor( i
);
153 m_pValSetColorBox
->InsertItem( i
+ 1, pColorEntry
->GetColor(), pColorEntry
->GetName() );
158 long SvxDefaultColorOptPage::GetColorIndex( const Color
& rCol
)
160 if( pColorList
.is() )
162 long nCount
= pColorList
->Count();
164 for( long i
= nCount
- 1; i
>= 0; i
-- ) // default chart colors are at the end of the table
166 XColorEntry
* pColorEntry
= pColorList
->GetColor( i
);
167 if( pColorEntry
&& pColorEntry
->GetColor() == rCol
)
168 return pColorList
->GetIndex( pColorEntry
->GetName() );
183 IMPL_LINK_NOARG(SvxDefaultColorOptPage
, ResetToDefaults
)
187 pColorConfig
->GetColorList().useDefault();
189 FillBoxChartColorLB(m_pLbChartColors
, pColorConfig
->GetColorList());
191 m_pLbChartColors
->GetFocus();
192 m_pLbChartColors
->SelectEntryPos( 0 );
193 m_pPBRemove
->Enable( true );
202 IMPL_LINK_NOARG(SvxDefaultColorOptPage
, AddChartColor
)
206 ColorData black
= RGB_COLORDATA( 0x00, 0x00, 0x00 );
208 pColorConfig
->GetColorList().append (XColorEntry ( black
, pColorConfig
->GetColorList().getDefaultName(pColorConfig
->GetColorList().size())));
210 FillBoxChartColorLB(m_pLbChartColors
, pColorConfig
->GetColorList());
212 m_pLbChartColors
->GetFocus();
213 m_pLbChartColors
->SelectEntryPos( pColorConfig
->GetColorList().size() - 1 );
214 m_pPBRemove
->Enable( true );
223 IMPL_LINK( SvxDefaultColorOptPage
, RemoveChartColor
, PushButton
*, pButton
)
225 sal_Int32 nIndex
= m_pLbChartColors
->GetSelectEntryPos();
227 if (m_pLbChartColors
->GetSelectEntryCount() == 0)
232 OSL_ENSURE(pColorConfig
->GetColorList().size() > 1, "don't delete the last chart color");
234 ScopedVclPtrInstance
<MessageDialog
> aQuery(pButton
, "QueryDeleteChartColorDialog",
235 "cui/ui/querydeletechartcolordialog.ui");
236 if (RET_YES
== aQuery
->Execute())
238 pColorConfig
->GetColorList().remove( nIndex
);
240 FillBoxChartColorLB(m_pLbChartColors
, pColorConfig
->GetColorList());
242 m_pLbChartColors
->GetFocus();
244 if (nIndex
== m_pLbChartColors
->GetEntryCount() && m_pLbChartColors
->GetEntryCount() > 0)
245 m_pLbChartColors
->SelectEntryPos( pColorConfig
->GetColorList().size() - 1 );
246 else if (m_pLbChartColors
->GetEntryCount() > 0)
247 m_pLbChartColors
->SelectEntryPos( nIndex
);
249 m_pPBRemove
->Enable(true);
256 IMPL_LINK( SvxDefaultColorOptPage
, ListClickedHdl
, ColorLB
*, _pColorList
)
258 Color aCol
= _pColorList
->GetSelectEntryColor();
260 long nIndex
= GetColorIndex( aCol
);
262 if( nIndex
== -1 ) // not found
263 m_pValSetColorBox
->SetNoSelection();
265 m_pValSetColorBox
->SelectItem( nIndex
+ 1 ); // ValueSet is 1-based
270 IMPL_LINK_NOARG(SvxDefaultColorOptPage
, BoxClickedHdl
)
272 sal_Int32 nIdx
= m_pLbChartColors
->GetSelectEntryPos();
273 if( nIdx
!= LISTBOX_ENTRY_NOTFOUND
)
275 const XColorEntry
aEntry( m_pValSetColorBox
->GetItemColor( m_pValSetColorBox
->GetSelectItemId() ), m_pLbChartColors
->GetSelectEntry() );
277 m_pLbChartColors
->Modify( aEntry
, nIdx
);
278 pColorConfig
->ReplaceColorByIndex( nIdx
, aEntry
);
280 m_pLbChartColors
->SelectEntryPos( nIdx
); // reselect entry
286 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */