Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*
3 : : * Version: MPL 1.1 / GPLv3+ / LGPLv3+
4 : : *
5 : : * The contents of this file are subject to the Mozilla Public License Version
6 : : * 1.1 (the "License"); you may not use this file except in compliance with
7 : : * the License or as specified alternatively below. You may obtain a copy of
8 : : * the License at http://www.mozilla.org/MPL/
9 : : *
10 : : * Software distributed under the License is distributed on an "AS IS" basis,
11 : : * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 : : * for the specific language governing rights and limitations under the
13 : : * License.
14 : : *
15 : : * Major Contributor(s):
16 : : * Copyright (C) 2012 Markus Mohrhard <markus.mohrhard@googlemail.com> (initial developer)
17 : : *
18 : : * All Rights Reserved.
19 : : *
20 : : * For minor contributions see the git repository.
21 : : *
22 : : * Alternatively, the contents of this file may be used under the terms of
23 : : * either the GNU General Public License Version 3 or later (the "GPLv3+"), or
24 : : * the GNU Lesser General Public License Version 3 or later (the "LGPLv3+"),
25 : : * in which case the provisions of the GPLv3+ or the LGPLv3+ are applicable
26 : : * instead of those above.
27 : : */
28 : :
29 : : #include "colorformat.hxx"
30 : : #include "colorscale.hxx"
31 : :
32 : : #include "colorformat.hrc"
33 : : #include "document.hxx"
34 : :
35 : : #include <svx/xtable.hxx>
36 : : #include <svx/drawitem.hxx>
37 : : #include <vcl/msgbox.hxx>
38 : :
39 : 0 : ScDataBarSettingsDlg::ScDataBarSettingsDlg(Window* pWindow, ScDocument* pDoc):
40 : : ModalDialog( pWindow, ScResId( RID_SCDLG_DATABAR ) ),
41 : : maBtnOk( this, ScResId( BTN_OK ) ),
42 : : maBtnCancel( this, ScResId( BTN_CANCEL ) ),
43 : : maFlBarColors( this, ScResId( FL_BAR_COLORS ) ),
44 : : maFlAxes( this, ScResId( FL_AXIS ) ),
45 : : maFlValues( this, ScResId( FL_VALUES ) ),
46 : : maFtMin( this, ScResId( FT_MINIMUM ) ),
47 : : maFtMax( this, ScResId( FT_MAXIMUM ) ),
48 : : maFtPositive( this, ScResId( FT_POSITIVE ) ),
49 : : maFtNegative( this, ScResId( FT_NEGATIVE ) ),
50 : : maFtPosition( this, ScResId( FT_POSITION ) ),
51 : : maFtAxisColor( this, ScResId( FT_COLOR_AXIS ) ),
52 : : maLbPos( this, ScResId( LB_POS ) ),
53 : : maLbNeg( this, ScResId( LB_NEG ) ),
54 : : maLbAxisCol( this, ScResId( LB_COL_AXIS ) ),
55 : : maLbTypeMin( this, ScResId( LB_TYPE ) ),
56 : : maLbTypeMax( this, ScResId( LB_TYPE ) ),
57 : : maLbAxisPos( this, ScResId( LB_AXIS_POSITION ) ),
58 : : maEdMin( this, ScResId( ED_MIN ) ),
59 : : maEdMax( this, ScResId( ED_MAX ) ),
60 : 0 : mpNumberFormatter( pDoc->GetFormatTable() )
61 : : {
62 : 0 : Init();
63 : 0 : FreeResource();
64 : :
65 : 0 : maLbTypeMin.SelectEntryPos(0);
66 : 0 : maLbTypeMax.SelectEntryPos(1);
67 : 0 : maLbAxisPos.SelectEntryPos(0);
68 : 0 : }
69 : :
70 : : namespace {
71 : :
72 : 0 : void SetType(const ScColorScaleEntry* pEntry, ListBox& aLstBox)
73 : : {
74 : 0 : switch(pEntry->GetType())
75 : : {
76 : : case COLORSCALE_MIN:
77 : 0 : aLstBox.SelectEntryPos(0);
78 : 0 : break;
79 : : case COLORSCALE_MAX:
80 : 0 : aLstBox.SelectEntryPos(1);
81 : 0 : break;
82 : : case COLORSCALE_PERCENTILE:
83 : 0 : aLstBox.SelectEntryPos(2);
84 : 0 : break;
85 : : case COLORSCALE_PERCENT:
86 : 0 : aLstBox.SelectEntryPos(3);
87 : 0 : break;
88 : : case COLORSCALE_FORMULA:
89 : 0 : aLstBox.SelectEntryPos(5);
90 : 0 : break;
91 : : case COLORSCALE_VALUE:
92 : 0 : aLstBox.SelectEntryPos(4);
93 : 0 : break;
94 : : case COLORSCALE_AUTOMIN:
95 : 0 : aLstBox.SelectEntryPos(6);
96 : 0 : break;
97 : : case COLORSCALE_AUTOMAX:
98 : 0 : aLstBox.SelectEntryPos(7);
99 : 0 : break;
100 : : }
101 : 0 : }
102 : :
103 : 0 : void GetType(const ListBox& rLstBox, const Edit& rEd, ScColorScaleEntry* pEntry, SvNumberFormatter* pNumberFormatter )
104 : : {
105 : 0 : double nVal = 0;
106 : 0 : sal_uInt32 nIndex = 0;
107 : 0 : switch(rLstBox.GetSelectEntryPos())
108 : : {
109 : : case 0:
110 : 0 : pEntry->SetType(COLORSCALE_MIN);
111 : 0 : break;
112 : : case 1:
113 : 0 : pEntry->SetType(COLORSCALE_MAX);
114 : 0 : break;
115 : : case 2:
116 : 0 : pEntry->SetType(COLORSCALE_PERCENTILE);
117 : 0 : pNumberFormatter->IsNumberFormat( rEd.GetText(), nIndex, nVal );
118 : 0 : pEntry->SetValue(nVal);
119 : 0 : break;
120 : : case 3:
121 : 0 : pEntry->SetType(COLORSCALE_PERCENT);
122 : 0 : pNumberFormatter->IsNumberFormat( rEd.GetText(), nIndex, nVal );
123 : 0 : pEntry->SetValue(nVal);
124 : 0 : break;
125 : : case 4:
126 : 0 : pNumberFormatter->IsNumberFormat( rEd.GetText(), nIndex, nVal );
127 : 0 : pEntry->SetType(COLORSCALE_VALUE);
128 : 0 : pEntry->SetValue(nVal);
129 : 0 : break;
130 : : case 5:
131 : : //TODO: moggi
132 : 0 : break;
133 : : case 6:
134 : 0 : pEntry->SetType(COLORSCALE_AUTOMIN);
135 : 0 : break;
136 : : case 7:
137 : 0 : pEntry->SetType(COLORSCALE_AUTOMAX);
138 : 0 : break;
139 : : }
140 : 0 : }
141 : :
142 : 0 : void SetValue( ScColorScaleEntry* pEntry, Edit& aEdit)
143 : : {
144 : 0 : if(pEntry->GetType() == COLORSCALE_FORMULA)
145 : 0 : aEdit.SetText(pEntry->GetFormula(formula::FormulaGrammar::GRAM_DEFAULT));
146 : 0 : else if(pEntry->GetType() != COLORSCALE_MIN && pEntry->GetType() != COLORSCALE_MAX)
147 : 0 : aEdit.SetText(rtl::OUString::valueOf(pEntry->GetValue()));
148 : : else
149 : 0 : aEdit.Disable();
150 : 0 : }
151 : :
152 : : }
153 : :
154 : 0 : ScDataBarSettingsDlg::ScDataBarSettingsDlg(Window* pWindow, const ScDataBarFormatData& rData, ScDocument* pDoc):
155 : : ModalDialog( pWindow, ScResId( RID_SCDLG_DATABAR ) ),
156 : : maBtnOk( this, ScResId( BTN_OK ) ),
157 : : maBtnCancel( this, ScResId( BTN_CANCEL ) ),
158 : : maFlBarColors( this, ScResId( FL_BAR_COLORS ) ),
159 : : maFlAxes( this, ScResId( FL_AXIS ) ),
160 : : maFlValues( this, ScResId( FL_VALUES ) ),
161 : : maFtMin( this, ScResId( FT_MINIMUM ) ),
162 : : maFtMax( this, ScResId( FT_MAXIMUM ) ),
163 : : maFtPositive( this, ScResId( FT_POSITIVE ) ),
164 : : maFtNegative( this, ScResId( FT_NEGATIVE ) ),
165 : : maFtPosition( this, ScResId( FT_POSITION ) ),
166 : : maFtAxisColor( this, ScResId( FT_COLOR_AXIS ) ),
167 : : maLbPos( this, ScResId( LB_POS ) ),
168 : : maLbNeg( this, ScResId( LB_NEG ) ),
169 : : maLbAxisCol( this, ScResId( LB_COL_AXIS ) ),
170 : : maLbTypeMin( this, ScResId( LB_TYPE ) ),
171 : : maLbTypeMax( this, ScResId( LB_TYPE ) ),
172 : : maLbAxisPos( this, ScResId( LB_AXIS_POSITION ) ),
173 : : maEdMin( this, ScResId( ED_MIN ) ),
174 : : maEdMax( this, ScResId( ED_MAX ) ),
175 : : maStrWarnSameValue( SC_RESSTR( STR_WARN_SAME_VALUE ) ),
176 : 0 : mpNumberFormatter( pDoc->GetFormatTable() )
177 : : {
178 : 0 : Init();
179 : 0 : FreeResource();
180 : :
181 : 0 : maLbPos.SelectEntry( rData.maPositiveColor );
182 : 0 : if(rData.mpNegativeColor)
183 : 0 : maLbNeg.SelectEntry( *rData.mpNegativeColor );
184 : :
185 : 0 : switch (rData.meAxisPosition)
186 : : {
187 : : case databar::NONE:
188 : 0 : maLbAxisPos.SelectEntryPos(2);
189 : 0 : break;
190 : : case databar::AUTOMATIC:
191 : 0 : maLbAxisPos.SelectEntryPos(0);
192 : 0 : break;
193 : : case databar::MIDDLE:
194 : 0 : maLbAxisPos.SelectEntryPos(1);
195 : 0 : break;
196 : : }
197 : 0 : ::SetType(rData.mpLowerLimit.get(), maLbTypeMin);
198 : 0 : ::SetType(rData.mpUpperLimit.get(), maLbTypeMax);
199 : 0 : SetValue(rData.mpLowerLimit.get(), maEdMin);
200 : 0 : SetValue(rData.mpUpperLimit.get(), maEdMax);
201 : 0 : maLbAxisCol.SelectEntry(rData.maAxisColor);
202 : :
203 : 0 : TypeSelectHdl(NULL);
204 : 0 : }
205 : :
206 : 0 : void ScDataBarSettingsDlg::Init()
207 : : {
208 : 0 : SfxObjectShell* pDocSh = SfxObjectShell::Current();
209 : 0 : const SfxPoolItem* pItem = NULL;
210 : 0 : XColorListRef pColorTable;
211 : :
212 : : DBG_ASSERT( pDocSh, "DocShell not found!" );
213 : :
214 : 0 : if ( pDocSh )
215 : : {
216 : 0 : pItem = pDocSh->GetItem( SID_COLOR_TABLE );
217 : 0 : if ( pItem != NULL )
218 : 0 : pColorTable = ( (SvxColorListItem*)pItem )->GetColorList();
219 : : }
220 : 0 : if ( pColorTable.is() )
221 : : {
222 : : // filling the line color box
223 : 0 : maLbPos.SetUpdateMode( false );
224 : 0 : maLbNeg.SetUpdateMode( false );
225 : 0 : maLbAxisCol.SetUpdateMode( false );
226 : :
227 : 0 : for ( long i = 0; i < pColorTable->Count(); ++i )
228 : : {
229 : 0 : XColorEntry* pEntry = pColorTable->GetColor(i);
230 : 0 : maLbPos.InsertEntry( pEntry->GetColor(), pEntry->GetName() );
231 : 0 : maLbNeg.InsertEntry( pEntry->GetColor(), pEntry->GetName() );
232 : 0 : maLbAxisCol.InsertEntry( pEntry->GetColor(), pEntry->GetName() );
233 : :
234 : 0 : if(pEntry->GetColor() == Color(COL_LIGHTRED))
235 : 0 : maLbNeg.SelectEntryPos(i);
236 : 0 : if(pEntry->GetColor() == Color(COL_BLACK))
237 : 0 : maLbAxisCol.SelectEntryPos(i);
238 : 0 : if(pEntry->GetColor() == Color(COL_LIGHTBLUE))
239 : 0 : maLbPos.SelectEntryPos(i);
240 : : }
241 : 0 : maLbPos.SetUpdateMode( sal_True );
242 : 0 : maLbNeg.SetUpdateMode( sal_True );
243 : 0 : maLbAxisCol.SetUpdateMode( sal_True );
244 : : }
245 : 0 : maBtnOk.SetClickHdl( LINK( this, ScDataBarSettingsDlg, OkBtnHdl ) );
246 : :
247 : 0 : Point aPoint(maLbTypeMax.GetPosPixel().X(), maFtMax.GetPosPixel().Y());
248 : 0 : maLbTypeMax.SetPosPixel(aPoint);
249 : :
250 : 0 : maLbTypeMin.SetSelectHdl( LINK( this, ScDataBarSettingsDlg, TypeSelectHdl ) );
251 : 0 : maLbTypeMax.SetSelectHdl( LINK( this, ScDataBarSettingsDlg, TypeSelectHdl ) );
252 : :
253 : 0 : }
254 : :
255 : : namespace {
256 : :
257 : 0 : void GetAxesPosition(ScDataBarFormatData* pData, const ListBox& rLbox)
258 : : {
259 : 0 : switch(rLbox.GetSelectEntryPos())
260 : : {
261 : : case 0:
262 : 0 : pData->meAxisPosition = databar::AUTOMATIC;
263 : 0 : break;
264 : : case 1:
265 : 0 : pData->meAxisPosition = databar::MIDDLE;
266 : 0 : break;
267 : : case 2:
268 : 0 : pData->meAxisPosition = databar::NONE;
269 : 0 : break;
270 : : }
271 : 0 : }
272 : :
273 : : }
274 : :
275 : 0 : ScDataBarFormatData* ScDataBarSettingsDlg::GetData()
276 : : {
277 : 0 : ScDataBarFormatData* pData = new ScDataBarFormatData();
278 : 0 : pData->maPositiveColor = maLbPos.GetSelectEntryColor();
279 : 0 : pData->mpNegativeColor.reset(new Color(maLbNeg.GetSelectEntryColor()));
280 : 0 : pData->mbGradient = true; //FIXME
281 : 0 : pData->mpUpperLimit.reset(new ScColorScaleEntry());
282 : 0 : pData->mpLowerLimit.reset(new ScColorScaleEntry());
283 : 0 : pData->maAxisColor = maLbAxisCol.GetSelectEntryColor();
284 : :
285 : 0 : ::GetType(maLbTypeMin, maEdMin, pData->mpLowerLimit.get(), mpNumberFormatter);
286 : 0 : ::GetType(maLbTypeMax, maEdMax, pData->mpUpperLimit.get(), mpNumberFormatter);
287 : 0 : GetAxesPosition(pData, maLbAxisPos);
288 : :
289 : 0 : return pData;
290 : : }
291 : :
292 : 0 : IMPL_LINK_NOARG( ScDataBarSettingsDlg, OkBtnHdl )
293 : : {
294 : : //check that min < max
295 : 0 : bool bWarn = false;
296 : 0 : sal_Int32 nSelectMin = maLbTypeMin.GetSelectEntryPos();
297 : 0 : if( nSelectMin == 1 || nSelectMin == 7)
298 : 0 : bWarn = true;
299 : 0 : sal_Int32 nSelectMax = maLbTypeMax.GetSelectEntryPos();
300 : 0 : if( nSelectMax == 0 || nSelectMax == 6 )
301 : 0 : bWarn = true;
302 : :
303 : 0 : if(!bWarn && maLbTypeMin.GetSelectEntryPos() == maLbTypeMax.GetSelectEntryPos())
304 : : {
305 : 0 : if(maLbTypeMax.GetSelectEntryPos() != 5)
306 : : {
307 : 0 : rtl::OUString aMinString = maEdMin.GetText();
308 : 0 : rtl::OUString aMaxString = maEdMax.GetText();
309 : 0 : double nMinValue = 0;
310 : 0 : sal_uInt32 nIndex = 0;
311 : 0 : mpNumberFormatter->IsNumberFormat(aMinString, nIndex, nMinValue);
312 : 0 : nIndex = 0;
313 : 0 : double nMaxValue = 0;
314 : 0 : mpNumberFormatter->IsNumberFormat(aMaxString, nIndex, nMaxValue);
315 : 0 : if(rtl::math::approxEqual(nMinValue, nMaxValue) || nMinValue > nMaxValue)
316 : 0 : bWarn = true;
317 : : }
318 : : }
319 : :
320 : 0 : if(bWarn)
321 : : {
322 : : //show warning message and don't close
323 : 0 : WarningBox aWarn(this, WB_OK, maStrWarnSameValue );
324 : 0 : aWarn.Execute();
325 : : }
326 : : else
327 : : {
328 : 0 : EndDialog(RET_OK);
329 : : }
330 : 0 : return 0;
331 : : }
332 : :
333 : 0 : IMPL_LINK_NOARG( ScDataBarSettingsDlg, TypeSelectHdl )
334 : : {
335 : 0 : sal_Int32 nSelectMin = maLbTypeMin.GetSelectEntryPos();
336 : 0 : if( nSelectMin == 0 || nSelectMin == 1 || nSelectMin == 6 || nSelectMin == 7)
337 : 0 : maEdMin.Disable();
338 : : else
339 : : {
340 : 0 : maEdMin.Enable();
341 : 0 : if(!maEdMin.GetText().Len())
342 : : {
343 : 0 : if(nSelectMin == 2 || nSelectMin == 3)
344 : 0 : maEdMin.SetText(rtl::OUString::valueOf(static_cast<sal_Int32>(50)));
345 : : else
346 : 0 : maEdMin.SetText(rtl::OUString::valueOf(static_cast<sal_Int32>(0)));
347 : : }
348 : : }
349 : :
350 : 0 : sal_Int32 nSelectMax = maLbTypeMax.GetSelectEntryPos();
351 : 0 : if(nSelectMax == 0 || nSelectMax == 1 || nSelectMax == 6 || nSelectMax == 7)
352 : 0 : maEdMax.Disable();
353 : : else
354 : : {
355 : 0 : maEdMax.Enable();
356 : 0 : if(!maEdMax.GetText().Len())
357 : : {
358 : 0 : if(nSelectMax == 2 || nSelectMax == 3)
359 : 0 : maEdMax.SetText(rtl::OUString::valueOf(static_cast<sal_Int32>(50)));
360 : : else
361 : 0 : maEdMax.SetText(rtl::OUString::valueOf(static_cast<sal_Int32>(0)));
362 : : }
363 : : }
364 : 0 : return 0;
365 : : }
366 : :
367 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|