LCOV - code coverage report
Current view: top level - sc/source/ui/condformat - colorformat.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 1 148 0.7 %
Date: 2014-04-11 Functions: 2 13 15.4 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       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/.
       8             :  */
       9             : 
      10             : #include "colorformat.hxx"
      11             : #include "colorscale.hxx"
      12             : 
      13             : #include "document.hxx"
      14             : #include "sc.hrc"
      15             : 
      16             : #include <svx/xtable.hxx>
      17             : #include <svx/drawitem.hxx>
      18             : #include <vcl/msgbox.hxx>
      19             : 
      20             : namespace {
      21             : 
      22           0 : void SetType(const ScColorScaleEntry* pEntry, ListBox& rLstBox)
      23             : {
      24           0 :     rLstBox.SelectEntryPos(pEntry->GetType());
      25           0 : }
      26             : 
      27           0 : void GetType(const ListBox& rLstBox, const Edit& rEd, ScColorScaleEntry* pEntry, SvNumberFormatter* pNumberFormatter,
      28             :         ScDocument* pDoc, const ScAddress& rPos )
      29             : {
      30           0 :     double nVal = 0;
      31           0 :     sal_uInt32 nIndex = 0;
      32           0 :     pEntry->SetType(static_cast<ScColorScaleEntryType>(rLstBox.GetSelectEntryPos()));
      33           0 :     switch(rLstBox.GetSelectEntryPos())
      34             :     {
      35             :         case COLORSCALE_AUTO:
      36             :         case COLORSCALE_MIN:
      37             :         case COLORSCALE_MAX:
      38           0 :             break;
      39             :         case COLORSCALE_PERCENTILE:
      40             :         case COLORSCALE_VALUE:
      41             :         case COLORSCALE_PERCENT:
      42           0 :             pNumberFormatter->IsNumberFormat( rEd.GetText(), nIndex, nVal );
      43           0 :             pEntry->SetValue(nVal);
      44           0 :             break;
      45             :         case COLORSCALE_FORMULA:
      46           0 :             pEntry->SetFormula(rEd.GetText(), pDoc, rPos);
      47           0 :             break;
      48             :     }
      49           0 : }
      50             : 
      51           0 : void SetValue( ScColorScaleEntry* pEntry, Edit& aEdit)
      52             : {
      53           0 :     if(pEntry->GetType() == COLORSCALE_FORMULA)
      54           0 :         aEdit.SetText(pEntry->GetFormula(formula::FormulaGrammar::GRAM_DEFAULT));
      55           0 :     else if(pEntry->GetType() != COLORSCALE_MIN && pEntry->GetType() != COLORSCALE_MAX)
      56           0 :         aEdit.SetText(OUString::number(pEntry->GetValue()));
      57             :     else
      58           0 :         aEdit.Disable();
      59           0 : }
      60             : 
      61             : }
      62             : 
      63           0 : ScDataBarSettingsDlg::ScDataBarSettingsDlg(Window* pWindow, const ScDataBarFormatData& rData, ScDocument* pDoc, const ScAddress& rPos):
      64             :     ModalDialog( pWindow, "DataBarOptions", "modules/scalc/ui/databaroptions.ui" ),
      65           0 :     mpNumberFormatter( pDoc->GetFormatTable() ),
      66             :     mpDoc(pDoc),
      67           0 :     maPos(rPos)
      68             : {
      69           0 :     get( mpBtnOk, "ok");
      70           0 :     get( mpBtnCancel, "cancel" );
      71           0 :     get( mpLbPos, "positive_colour" );
      72           0 :     get( mpLbNeg, "negative_colour" );
      73           0 :     get( mpLbTypeMin, "min" );
      74           0 :     get( mpLbTypeMax, "max" );
      75           0 :     get( mpLbAxisPos, "axis_pos" );
      76           0 :     get( mpLbAxisCol, "axis_colour" );
      77           0 :     get( mpEdMin, "min_value" );
      78           0 :     get( mpEdMax, "max_value" );
      79             : 
      80           0 :     maStrWarnSameValue = get<FixedText>("str_same_value")->GetText();
      81             : 
      82           0 :     Init();
      83             : 
      84           0 :     mpLbPos->SelectEntry( rData.maPositiveColor );
      85           0 :     if(rData.mpNegativeColor)
      86           0 :         mpLbNeg->SelectEntry( *rData.mpNegativeColor );
      87             : 
      88           0 :     switch (rData.meAxisPosition)
      89             :     {
      90             :         case databar::NONE:
      91           0 :             mpLbAxisPos->SelectEntryPos(2);
      92           0 :             break;
      93             :         case databar::AUTOMATIC:
      94           0 :             mpLbAxisPos->SelectEntryPos(0);
      95           0 :             break;
      96             :         case databar::MIDDLE:
      97           0 :             mpLbAxisPos->SelectEntryPos(1);
      98           0 :             break;
      99             :     }
     100           0 :     ::SetType(rData.mpLowerLimit.get(), *mpLbTypeMin);
     101           0 :     ::SetType(rData.mpUpperLimit.get(), *mpLbTypeMax);
     102           0 :     SetValue(rData.mpLowerLimit.get(), *mpEdMin);
     103           0 :     SetValue(rData.mpUpperLimit.get(), *mpEdMax);
     104           0 :     mpLbAxisCol->SelectEntry(rData.maAxisColor);
     105             : 
     106           0 :     TypeSelectHdl(NULL);
     107           0 : }
     108             : 
     109           0 : void ScDataBarSettingsDlg::Init()
     110             : {
     111           0 :     SfxObjectShell*     pDocSh      = SfxObjectShell::Current();
     112           0 :     XColorListRef       pColorTable;
     113             : 
     114             :     DBG_ASSERT( pDocSh, "DocShell not found!" );
     115             : 
     116           0 :     if ( pDocSh )
     117             :     {
     118           0 :         const SfxPoolItem*  pItem = pDocSh->GetItem( SID_COLOR_TABLE );
     119           0 :         if ( pItem != NULL )
     120           0 :             pColorTable = ( (SvxColorListItem*)pItem )->GetColorList();
     121             :     }
     122           0 :     if ( pColorTable.is() )
     123             :     {
     124             :         // filling the line color box
     125           0 :         mpLbPos->SetUpdateMode( false );
     126           0 :         mpLbNeg->SetUpdateMode( false );
     127           0 :         mpLbAxisCol->SetUpdateMode( false );
     128             : 
     129           0 :         for ( long i = 0; i < pColorTable->Count(); ++i )
     130             :         {
     131           0 :             XColorEntry* pEntry = pColorTable->GetColor(i);
     132           0 :             mpLbPos->InsertEntry( pEntry->GetColor(), pEntry->GetName() );
     133           0 :             mpLbNeg->InsertEntry( pEntry->GetColor(), pEntry->GetName() );
     134           0 :             mpLbAxisCol->InsertEntry( pEntry->GetColor(), pEntry->GetName() );
     135             : 
     136           0 :             if(pEntry->GetColor() == Color(COL_LIGHTRED))
     137           0 :                 mpLbNeg->SelectEntryPos(i);
     138           0 :             if(pEntry->GetColor() == Color(COL_BLACK))
     139           0 :                 mpLbAxisCol->SelectEntryPos(i);
     140           0 :             if(pEntry->GetColor() == Color(COL_LIGHTBLUE))
     141           0 :                 mpLbPos->SelectEntryPos(i);
     142             :         }
     143           0 :         mpLbPos->SetUpdateMode( true );
     144           0 :         mpLbNeg->SetUpdateMode( true );
     145           0 :         mpLbAxisCol->SetUpdateMode( true );
     146             :     }
     147           0 :     mpBtnOk->SetClickHdl( LINK( this, ScDataBarSettingsDlg, OkBtnHdl ) );
     148             : 
     149           0 :     mpLbTypeMin->SetSelectHdl( LINK( this, ScDataBarSettingsDlg, TypeSelectHdl ) );
     150           0 :     mpLbTypeMax->SetSelectHdl( LINK( this, ScDataBarSettingsDlg, TypeSelectHdl ) );
     151             : 
     152           0 : }
     153             : 
     154             : namespace {
     155             : 
     156           0 : void GetAxesPosition(ScDataBarFormatData* pData, const ListBox* rLbox)
     157             : {
     158           0 :     switch(rLbox->GetSelectEntryPos())
     159             :     {
     160             :         case 0:
     161           0 :             pData->meAxisPosition = databar::AUTOMATIC;
     162           0 :             break;
     163             :         case 1:
     164           0 :             pData->meAxisPosition = databar::MIDDLE;
     165           0 :             break;
     166             :         case 2:
     167           0 :             pData->meAxisPosition = databar::NONE;
     168           0 :             break;
     169             :     }
     170           0 : }
     171             : 
     172             : }
     173             : 
     174           0 : ScDataBarFormatData* ScDataBarSettingsDlg::GetData()
     175             : {
     176           0 :     ScDataBarFormatData* pData = new ScDataBarFormatData();
     177           0 :     pData->maPositiveColor = mpLbPos->GetSelectEntryColor();
     178           0 :     pData->mpNegativeColor.reset(new Color(mpLbNeg->GetSelectEntryColor()));
     179           0 :     pData->mbGradient = true; //FIXME
     180           0 :     pData->mpUpperLimit.reset(new ScColorScaleEntry());
     181           0 :     pData->mpLowerLimit.reset(new ScColorScaleEntry());
     182           0 :     pData->maAxisColor = mpLbAxisCol->GetSelectEntryColor();
     183             : 
     184           0 :     ::GetType(*mpLbTypeMin, *mpEdMin, pData->mpLowerLimit.get(), mpNumberFormatter, mpDoc, maPos);
     185           0 :     ::GetType(*mpLbTypeMax, *mpEdMax, pData->mpUpperLimit.get(), mpNumberFormatter, mpDoc, maPos);
     186           0 :     GetAxesPosition(pData, mpLbAxisPos);
     187             : 
     188           0 :     return pData;
     189             : }
     190             : 
     191           0 : IMPL_LINK_NOARG( ScDataBarSettingsDlg, OkBtnHdl )
     192             : {
     193             :     //check that min < max
     194           0 :     bool bWarn = false;
     195           0 :     sal_Int32 nSelectMin = mpLbTypeMin->GetSelectEntryPos();
     196           0 :     if( nSelectMin == COLORSCALE_MAX )
     197           0 :         bWarn = true;
     198           0 :     sal_Int32 nSelectMax = mpLbTypeMax->GetSelectEntryPos();
     199           0 :     if( nSelectMax == COLORSCALE_MIN )
     200           0 :         bWarn = true;
     201             : 
     202           0 :     if(!bWarn && mpLbTypeMin->GetSelectEntryPos() == mpLbTypeMax->GetSelectEntryPos())
     203             :     {
     204             : 
     205           0 :         if(nSelectMax != COLORSCALE_FORMULA && nSelectMax != COLORSCALE_AUTO)
     206             :         {
     207           0 :             OUString aMinString = mpEdMin->GetText();
     208           0 :             OUString aMaxString = mpEdMax->GetText();
     209           0 :             double nMinValue = 0;
     210           0 :             sal_uInt32 nIndex = 0;
     211           0 :             mpNumberFormatter->IsNumberFormat(aMinString, nIndex, nMinValue);
     212           0 :             nIndex = 0;
     213           0 :             double nMaxValue = 0;
     214           0 :             mpNumberFormatter->IsNumberFormat(aMaxString, nIndex, nMaxValue);
     215           0 :             if(rtl::math::approxEqual(nMinValue, nMaxValue) || nMinValue > nMaxValue)
     216           0 :                 bWarn = true;
     217             :         }
     218             :     }
     219             : 
     220           0 :     if(bWarn)
     221             :     {
     222             :         //show warning message and don't close
     223           0 :         WarningBox aWarn(this, WB_OK, maStrWarnSameValue );
     224           0 :         aWarn.Execute();
     225             :     }
     226             :     else
     227             :     {
     228           0 :         EndDialog(RET_OK);
     229             :     }
     230           0 :     return 0;
     231             : }
     232             : 
     233           0 : IMPL_LINK_NOARG( ScDataBarSettingsDlg, TypeSelectHdl )
     234             : {
     235           0 :     sal_Int32 nSelectMin = mpLbTypeMin->GetSelectEntryPos();
     236           0 :     if( nSelectMin <= COLORSCALE_MAX)
     237           0 :         mpEdMin->Disable();
     238             :     else
     239             :     {
     240           0 :         mpEdMin->Enable();
     241           0 :         if(mpEdMin->GetText().isEmpty())
     242             :         {
     243           0 :             if(nSelectMin == COLORSCALE_PERCENTILE || nSelectMin == COLORSCALE_PERCENT)
     244           0 :                 mpEdMin->SetText(OUString::number(50));
     245             :             else
     246           0 :                 mpEdMin->SetText(OUString::number(0));
     247             :         }
     248             :     }
     249             : 
     250           0 :     sal_Int32 nSelectMax = mpLbTypeMax->GetSelectEntryPos();
     251           0 :     if(nSelectMax <= COLORSCALE_MAX)
     252           0 :         mpEdMax->Disable();
     253             :     else
     254             :     {
     255           0 :         mpEdMax->Enable();
     256           0 :         if(mpEdMax->GetText().isEmpty())
     257             :         {
     258           0 :             if(nSelectMax == COLORSCALE_PERCENTILE || nSelectMax == COLORSCALE_PERCENT)
     259           0 :                 mpEdMax->SetText(OUString::number(50));
     260             :             else
     261           0 :                 mpEdMax->SetText(OUString::number(0));
     262             :         }
     263             :     }
     264           0 :     return 0;
     265         102 : }
     266             : 
     267             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10