xref: /AOO41X/main/cui/source/options/optchart.cxx (revision 3ce09a58b0d6873449cda31e55c66dba2dbc8f7f)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_cui.hxx"
26 #include <unotools/pathoptions.hxx>
27 #include <cuires.hrc>
28 #include "optchart.hxx"
29 #include "optchart.hrc"
30 #include <dialmgr.hxx>
31 #include <svx/svxids.hrc> // for SID_SCH_EDITOPTIONS
32 
33 // ====================
34 // class ChartColorLB
35 // ====================
FillBox(const SvxChartColorTable & rTab)36 void ChartColorLB::FillBox( const SvxChartColorTable & rTab )
37 {
38     long nCount = rTab.size();
39     SetUpdateMode( sal_False );
40 
41     for( long i = 0; i < nCount; i++ )
42     {
43         Append( rTab[ i ] );
44     }
45     SetUpdateMode( sal_True );
46 }
47 
48 
49 // ====================
50 // class SvxDefaultColorOptPage
51 // ====================
SvxDefaultColorOptPage(Window * pParent,const SfxItemSet & rInAttrs)52 SvxDefaultColorOptPage::SvxDefaultColorOptPage( Window* pParent, const SfxItemSet& rInAttrs ) :
53 
54     SfxTabPage( pParent, CUI_RES( RID_OPTPAGE_CHART_DEFCOLORS ), rInAttrs ),
55 
56     aGbChartColors  ( this, CUI_RES( FL_CHART_COLOR_LIST ) ),
57     aLbChartColors  ( this, CUI_RES( LB_CHART_COLOR_LIST ) ),
58     aGbColorBox     ( this, CUI_RES( FL_COLOR_BOX ) ),
59     aValSetColorBox ( this, CUI_RES( CT_COLOR_BOX ) ),
60     aPBDefault      ( this, CUI_RES( PB_RESET_TO_DEFAULT ) )
61 {
62     FreeResource();
63 
64     aPBDefault.SetClickHdl( LINK( this, SvxDefaultColorOptPage, ResetToDefaults ) );
65     aLbChartColors.SetSelectHdl( LINK( this, SvxDefaultColorOptPage, ListClickedHdl ) );
66     aValSetColorBox.SetSelectHdl( LINK( this, SvxDefaultColorOptPage, BoxClickedHdl ) );
67 
68     aValSetColorBox.SetStyle( aValSetColorBox.GetStyle()
69                                     | WB_VSCROLL | WB_ITEMBORDER | WB_NAMEFIELD );
70     aValSetColorBox.SetColCount( 8 );
71     aValSetColorBox.SetLineCount( 12 );
72     aValSetColorBox.SetExtraSpacing( 0 );
73     aValSetColorBox.Show();
74 
75     pChartOptions = new SvxChartOptions;
76     maColorTab = XPropertyListFactory::CreateSharedXColorList(SvtPathOptions().GetPalettePath());
77 
78     const SfxPoolItem* pItem = NULL;
79     if ( rInAttrs.GetItemState( SID_SCH_EDITOPTIONS, sal_False, &pItem ) == SFX_ITEM_SET )
80     {
81         pColorConfig = SAL_STATIC_CAST( SvxChartColorTableItem*, pItem->Clone() );
82     }
83     else
84     {
85         SvxChartColorTable aTable;
86         aTable.useDefault();
87         pColorConfig = new SvxChartColorTableItem( SID_SCH_EDITOPTIONS, aTable );
88         pColorConfig->SetOptions( pChartOptions );
89     }
90 
91     Construct();
92 }
93 
~SvxDefaultColorOptPage()94 SvxDefaultColorOptPage::~SvxDefaultColorOptPage()
95 {
96     // save changes
97     pChartOptions->SetDefaultColors( pColorConfig->GetColorTable() );
98     pChartOptions->Commit();
99 
100     delete pColorConfig;
101     delete pChartOptions;
102 }
103 
Construct()104 void SvxDefaultColorOptPage::Construct()
105 {
106     if( pColorConfig )
107         aLbChartColors.FillBox( pColorConfig->GetColorTable() );
108 
109     FillColorBox();
110 
111     aLbChartColors.SelectEntryPos( 0 );
112     ListClickedHdl( &aLbChartColors );
113 }
114 
115 
Create(Window * pParent,const SfxItemSet & rAttrs)116 SfxTabPage* __EXPORT SvxDefaultColorOptPage::Create( Window* pParent, const SfxItemSet& rAttrs )
117 {
118     return new SvxDefaultColorOptPage( pParent, rAttrs );
119 }
120 
FillItemSet(SfxItemSet & rOutAttrs)121 sal_Bool __EXPORT SvxDefaultColorOptPage::FillItemSet( SfxItemSet& rOutAttrs )
122 {
123     if( pColorConfig )
124         rOutAttrs.Put( *SAL_STATIC_CAST( SfxPoolItem*, pColorConfig ));
125 
126     return sal_True;
127 }
128 
Reset(const SfxItemSet &)129 void __EXPORT SvxDefaultColorOptPage::Reset( const SfxItemSet& )
130 {
131     aLbChartColors.SelectEntryPos( 0 );
132     ListClickedHdl( &aLbChartColors );
133 }
134 
FillColorBox()135 void SvxDefaultColorOptPage::FillColorBox()
136 {
137     if( !maColorTab.get() ) return;
138 
139     long nCount = maColorTab->Count();
140     XColorEntry* pColorEntry;
141 
142     for( long i = 0; i < nCount; i++ )
143     {
144         pColorEntry = maColorTab->GetColor( i );
145         aValSetColorBox.InsertItem( (sal_uInt16) i + 1, pColorEntry->GetColor(), pColorEntry->GetName() );
146     }
147 }
148 
149 
GetColorIndex(const Color & rCol)150 long SvxDefaultColorOptPage::GetColorIndex( const Color& rCol )
151 {
152     if( maColorTab.get() )
153     {
154         long nCount = maColorTab->Count();
155         XColorEntry* pColorEntry;
156 
157         for( long i = nCount - 1; i >= 0; i-- )         // default chart colors are at the end of the table
158         {
159             pColorEntry = maColorTab->GetColor( i );
160             if( pColorEntry && pColorEntry->GetColor() == rCol )
161                 return maColorTab->GetIndex( pColorEntry->GetName() );
162         }
163     }
164     return -1L;
165 }
166 
167 
168 
169 // --------------------
170 // event handlers
171 // --------------------
172 
173 // ResetToDefaults
174 // ---------------
175 
IMPL_LINK(SvxDefaultColorOptPage,ResetToDefaults,void *,EMPTYARG)176 IMPL_LINK( SvxDefaultColorOptPage, ResetToDefaults, void *, EMPTYARG )
177 {
178     if( pColorConfig )
179     {
180         pColorConfig->GetColorTable().useDefault();
181 
182         aLbChartColors.Clear();
183         aLbChartColors.FillBox( pColorConfig->GetColorTable() );
184 
185         aLbChartColors.GetFocus();
186     }
187 
188     return 0L;
189 }
190 
191 // ListClickedHdl
192 // --------------
193 
IMPL_LINK(SvxDefaultColorOptPage,ListClickedHdl,ChartColorLB *,pColorList)194 IMPL_LINK( SvxDefaultColorOptPage, ListClickedHdl, ChartColorLB*,  pColorList )
195 {
196     Color aCol = pColorList->GetSelectEntryColor();
197 
198     long nIndex = GetColorIndex( aCol );
199 
200     if( nIndex == -1 )      // not found
201     {
202         aValSetColorBox.SetNoSelection();
203     }
204     else
205     {
206         aValSetColorBox.SelectItem( (sal_uInt16)nIndex + 1 );       // ValueSet is 1-based
207     }
208 
209     return 0L;
210 }
211 
212 // BoxClickedHdl
213 // -------------
214 
IMPL_LINK(SvxDefaultColorOptPage,BoxClickedHdl,ValueSet *,EMPTYARG)215 IMPL_LINK( SvxDefaultColorOptPage, BoxClickedHdl, ValueSet*, EMPTYARG )
216 {
217     sal_uInt16 nIdx = aLbChartColors.GetSelectEntryPos();
218     if( nIdx != LISTBOX_ENTRY_NOTFOUND )
219     {
220         const XColorEntry aEntry( aValSetColorBox.GetItemColor( aValSetColorBox.GetSelectItemId() ), aLbChartColors.GetSelectEntry() );
221 
222         aLbChartColors.Modify( aEntry, nIdx );
223         pColorConfig->ReplaceColorByIndex( nIdx, aEntry );
224 
225         aLbChartColors.SelectEntryPos( nIdx );  // reselect entry
226     }
227 
228     return 0L;
229 }
230 
231