LCOV - code coverage report
Current view: top level - sc/source/ui/condformat - colorformat.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 1 217 0.5 %
Date: 2015-06-13 12:38:46 Functions: 2 20 10.0 %
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 :             (void)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 : OUString convertNumberToString(double nVal, ScDocument* pDoc)
      52             : {
      53           0 :     SvNumberFormatter* pNumberFormatter = pDoc->GetFormatTable();
      54           0 :     OUString aText;
      55           0 :     pNumberFormatter->GetInputLineString(nVal, 0, aText);
      56           0 :     return aText;
      57             : }
      58             : 
      59           0 : void SetValue( ScDocument* pDoc, ScColorScaleEntry* pEntry, Edit& aEdit)
      60             : {
      61           0 :     if(pEntry->GetType() == COLORSCALE_FORMULA)
      62           0 :         aEdit.SetText(pEntry->GetFormula(formula::FormulaGrammar::GRAM_DEFAULT));
      63           0 :     else if(pEntry->GetType() != COLORSCALE_MIN && pEntry->GetType() != COLORSCALE_MAX)
      64           0 :         aEdit.SetText(convertNumberToString(pEntry->GetValue(), pDoc));
      65             :     else
      66           0 :         aEdit.Disable();
      67           0 : }
      68             : 
      69             : }
      70             : 
      71           0 : ScDataBarSettingsDlg::ScDataBarSettingsDlg(vcl::Window* pWindow, const ScDataBarFormatData& rData, ScDocument* pDoc, const ScAddress& rPos):
      72             :     ModalDialog( pWindow, "DataBarOptions", "modules/scalc/ui/databaroptions.ui" ),
      73           0 :     mpNumberFormatter( pDoc->GetFormatTable() ),
      74             :     mpDoc(pDoc),
      75           0 :     maPos(rPos)
      76             : {
      77           0 :     get( mpBtnOk, "ok");
      78           0 :     get( mpBtnCancel, "cancel" );
      79           0 :     get( mpLbPos, "positive_colour" );
      80           0 :     get( mpLbNeg, "negative_colour" );
      81           0 :     get( mpLbFillType, "fill_type" );
      82           0 :     get( mpLbTypeMin, "min" );
      83           0 :     get( mpLbTypeMax, "max" );
      84           0 :     get( mpLbAxisPos, "axis_pos" );
      85           0 :     get( mpLbAxisCol, "axis_colour" );
      86           0 :     get( mpEdMin, "min_value" );
      87           0 :     get( mpEdMax, "max_value" );
      88           0 :     get( mpLenMin, "min_length" );
      89           0 :     get( mpLenMax, "max_length" );
      90           0 :     get( mpCbOnlyBar, "only_bar");
      91             : 
      92           0 :     maStrWarnSameValue = get<FixedText>("str_same_value")->GetText();
      93             : 
      94           0 :     Init();
      95             : 
      96           0 :     mpLbPos->SelectEntry( rData.maPositiveColor );
      97           0 :     mpLbFillType->SelectEntryPos( rData.mbGradient ? 1 : 0 );
      98           0 :     if(rData.mpNegativeColor)
      99           0 :         mpLbNeg->SelectEntry( *rData.mpNegativeColor );
     100             : 
     101           0 :     switch (rData.meAxisPosition)
     102             :     {
     103             :         case databar::NONE:
     104           0 :             mpLbAxisPos->SelectEntryPos(2);
     105           0 :             break;
     106             :         case databar::AUTOMATIC:
     107           0 :             mpLbAxisPos->SelectEntryPos(0);
     108           0 :             break;
     109             :         case databar::MIDDLE:
     110           0 :             mpLbAxisPos->SelectEntryPos(1);
     111           0 :             break;
     112             :     }
     113           0 :     ::SetType(rData.mpLowerLimit.get(), *mpLbTypeMin);
     114           0 :     ::SetType(rData.mpUpperLimit.get(), *mpLbTypeMax);
     115           0 :     SetValue(mpDoc, rData.mpLowerLimit.get(), *mpEdMin);
     116           0 :     SetValue(mpDoc, rData.mpUpperLimit.get(), *mpEdMax);
     117           0 :     mpLenMin->SetText(convertNumberToString(rData.mnMinLength, mpDoc));
     118           0 :     mpLenMax->SetText(convertNumberToString(rData.mnMaxLength, mpDoc));
     119           0 :     mpLbAxisCol->SelectEntry(rData.maAxisColor);
     120           0 :     mpCbOnlyBar->Check(rData.mbOnlyBar);
     121             : 
     122           0 :     TypeSelectHdl(NULL);
     123           0 :     PosSelectHdl(NULL);
     124           0 : }
     125             : 
     126           0 : ScDataBarSettingsDlg::~ScDataBarSettingsDlg()
     127             : {
     128           0 :     disposeOnce();
     129           0 : }
     130             : 
     131           0 : void ScDataBarSettingsDlg::dispose()
     132             : {
     133           0 :     mpBtnOk.clear();
     134           0 :     mpBtnCancel.clear();
     135           0 :     mpLbPos.clear();
     136           0 :     mpLbNeg.clear();
     137           0 :     mpLbAxisCol.clear();
     138           0 :     mpLbTypeMin.clear();
     139           0 :     mpLbTypeMax.clear();
     140           0 :     mpLbFillType.clear();
     141           0 :     mpLbAxisPos.clear();
     142           0 :     mpEdMin.clear();
     143           0 :     mpEdMax.clear();
     144           0 :     mpLenMin.clear();
     145           0 :     mpLenMax.clear();
     146           0 :     mpCbOnlyBar.clear();
     147           0 :     ModalDialog::dispose();
     148           0 : }
     149             : 
     150           0 : void ScDataBarSettingsDlg::Init()
     151             : {
     152           0 :     SfxObjectShell*     pDocSh      = SfxObjectShell::Current();
     153           0 :     XColorListRef       pColorTable;
     154             : 
     155             :     DBG_ASSERT( pDocSh, "DocShell not found!" );
     156             : 
     157           0 :     if ( pDocSh )
     158             :     {
     159           0 :         const SfxPoolItem*  pItem = pDocSh->GetItem( SID_COLOR_TABLE );
     160           0 :         if ( pItem != NULL )
     161           0 :             pColorTable = static_cast<const SvxColorListItem*>(pItem)->GetColorList();
     162             :     }
     163           0 :     if ( pColorTable.is() )
     164             :     {
     165             :         // filling the line color box
     166           0 :         mpLbPos->SetUpdateMode( false );
     167           0 :         mpLbNeg->SetUpdateMode( false );
     168           0 :         mpLbAxisCol->SetUpdateMode( false );
     169             : 
     170           0 :         for ( long i = 0; i < pColorTable->Count(); ++i )
     171             :         {
     172           0 :             XColorEntry* pEntry = pColorTable->GetColor(i);
     173           0 :             mpLbPos->InsertEntry( pEntry->GetColor(), pEntry->GetName() );
     174           0 :             mpLbNeg->InsertEntry( pEntry->GetColor(), pEntry->GetName() );
     175           0 :             mpLbAxisCol->InsertEntry( pEntry->GetColor(), pEntry->GetName() );
     176             : 
     177           0 :             if(pEntry->GetColor() == Color(COL_LIGHTRED))
     178           0 :                 mpLbNeg->SelectEntryPos(i);
     179           0 :             if(pEntry->GetColor() == Color(COL_BLACK))
     180           0 :                 mpLbAxisCol->SelectEntryPos(i);
     181           0 :             if(pEntry->GetColor() == Color(COL_LIGHTBLUE))
     182           0 :                 mpLbPos->SelectEntryPos(i);
     183             :         }
     184           0 :         mpLbPos->SetUpdateMode( true );
     185           0 :         mpLbNeg->SetUpdateMode( true );
     186           0 :         mpLbAxisCol->SetUpdateMode( true );
     187             :     }
     188           0 :     mpBtnOk->SetClickHdl( LINK( this, ScDataBarSettingsDlg, OkBtnHdl ) );
     189             : 
     190           0 :     mpLbTypeMin->SetSelectHdl( LINK( this, ScDataBarSettingsDlg, TypeSelectHdl ) );
     191           0 :     mpLbTypeMax->SetSelectHdl( LINK( this, ScDataBarSettingsDlg, TypeSelectHdl ) );
     192           0 :     mpLbAxisPos->SetSelectHdl( LINK( this, ScDataBarSettingsDlg, PosSelectHdl ) );
     193             : 
     194           0 : }
     195             : 
     196             : namespace {
     197             : 
     198           0 : void GetAxesPosition(ScDataBarFormatData* pData, const ListBox* rLbox)
     199             : {
     200           0 :     switch(rLbox->GetSelectEntryPos())
     201             :     {
     202             :         case 0:
     203           0 :             pData->meAxisPosition = databar::AUTOMATIC;
     204           0 :             break;
     205             :         case 1:
     206           0 :             pData->meAxisPosition = databar::MIDDLE;
     207           0 :             break;
     208             :         case 2:
     209           0 :             pData->meAxisPosition = databar::NONE;
     210           0 :             break;
     211             :     }
     212           0 : }
     213             : 
     214           0 : void SetBarLength(ScDataBarFormatData* pData, const OUString& minStr, const OUString& maxStr, SvNumberFormatter* mpNumberFormatter)
     215             : {
     216           0 :     double nMinValue = 0;
     217           0 :     sal_uInt32 nIndex = 0;
     218           0 :     (void)mpNumberFormatter->IsNumberFormat(minStr, nIndex, nMinValue);
     219           0 :     nIndex = 0;
     220           0 :     double nMaxValue = 0;
     221           0 :     (void)mpNumberFormatter->IsNumberFormat(maxStr, nIndex, nMaxValue);
     222           0 :     pData->mnMinLength = nMinValue;
     223           0 :     pData->mnMaxLength = nMaxValue;
     224           0 : }
     225             : 
     226             : }
     227             : 
     228           0 : ScDataBarFormatData* ScDataBarSettingsDlg::GetData()
     229             : {
     230           0 :     ScDataBarFormatData* pData = new ScDataBarFormatData();
     231           0 :     pData->maPositiveColor = mpLbPos->GetSelectEntryColor();
     232           0 :     pData->mpNegativeColor.reset(new Color(mpLbNeg->GetSelectEntryColor()));
     233           0 :     pData->mbGradient = ( mpLbFillType->GetSelectEntryPos() == 1 );
     234           0 :     pData->mpUpperLimit.reset(new ScColorScaleEntry());
     235           0 :     pData->mpLowerLimit.reset(new ScColorScaleEntry());
     236           0 :     pData->maAxisColor = mpLbAxisCol->GetSelectEntryColor();
     237           0 :     pData->mbOnlyBar = mpCbOnlyBar->IsChecked();
     238             : 
     239           0 :     ::GetType(*mpLbTypeMin, *mpEdMin, pData->mpLowerLimit.get(), mpNumberFormatter, mpDoc, maPos);
     240           0 :     ::GetType(*mpLbTypeMax, *mpEdMax, pData->mpUpperLimit.get(), mpNumberFormatter, mpDoc, maPos);
     241           0 :     GetAxesPosition(pData, mpLbAxisPos);
     242           0 :     SetBarLength(pData, mpLenMin->GetText(), mpLenMax->GetText(), mpNumberFormatter);
     243             : 
     244           0 :     return pData;
     245             : }
     246             : 
     247           0 : IMPL_LINK_NOARG( ScDataBarSettingsDlg, OkBtnHdl )
     248             : {
     249             :     //check that min < max
     250           0 :     bool bWarn = false;
     251           0 :     sal_Int32 nSelectMin = mpLbTypeMin->GetSelectEntryPos();
     252           0 :     if( nSelectMin == COLORSCALE_MAX )
     253           0 :         bWarn = true;
     254           0 :     sal_Int32 nSelectMax = mpLbTypeMax->GetSelectEntryPos();
     255           0 :     if( nSelectMax == COLORSCALE_MIN )
     256           0 :         bWarn = true;
     257           0 :     if(!bWarn) // databar length checks
     258             :     {
     259           0 :         OUString aMinString = mpLenMin->GetText();
     260           0 :         OUString aMaxString = mpLenMax->GetText();
     261           0 :         double nMinValue = 0;
     262           0 :         sal_uInt32 nIndex = 0;
     263           0 :         (void)mpNumberFormatter->IsNumberFormat(aMinString, nIndex, nMinValue);
     264           0 :         nIndex = 0;
     265           0 :         double nMaxValue = 0;
     266           0 :         (void)mpNumberFormatter->IsNumberFormat(aMaxString, nIndex, nMaxValue);
     267           0 :         if(rtl::math::approxEqual(nMinValue, nMaxValue) || nMinValue > nMaxValue || nMaxValue > 100 || nMinValue < 0)
     268           0 :             bWarn = true;
     269             :     }
     270           0 :     if(!bWarn && mpLbTypeMin->GetSelectEntryPos() == mpLbTypeMax->GetSelectEntryPos())
     271             :     {
     272             : 
     273           0 :         if(nSelectMax != COLORSCALE_FORMULA && nSelectMax != COLORSCALE_AUTO)
     274             :         {
     275           0 :             OUString aMinString = mpEdMin->GetText();
     276           0 :             OUString aMaxString = mpEdMax->GetText();
     277           0 :             double nMinValue = 0;
     278           0 :             sal_uInt32 nIndex = 0;
     279           0 :             (void)mpNumberFormatter->IsNumberFormat(aMinString, nIndex, nMinValue);
     280           0 :             nIndex = 0;
     281           0 :             double nMaxValue = 0;
     282           0 :             (void)mpNumberFormatter->IsNumberFormat(aMaxString, nIndex, nMaxValue);
     283           0 :             if(rtl::math::approxEqual(nMinValue, nMaxValue) || nMinValue > nMaxValue)
     284           0 :                 bWarn = true;
     285             :         }
     286             :     }
     287             : 
     288           0 :     if(bWarn)
     289             :     {
     290             :         //show warning message and don't close
     291           0 :         ScopedVclPtrInstance< WarningBox > aWarn(this, WB_OK, maStrWarnSameValue );
     292           0 :         aWarn->Execute();
     293             :     }
     294             :     else
     295             :     {
     296           0 :         EndDialog(RET_OK);
     297             :     }
     298           0 :     return 0;
     299             : }
     300             : 
     301           0 : IMPL_LINK_NOARG( ScDataBarSettingsDlg, TypeSelectHdl )
     302             : {
     303           0 :     sal_Int32 nSelectMin = mpLbTypeMin->GetSelectEntryPos();
     304           0 :     if( nSelectMin <= COLORSCALE_MAX)
     305           0 :         mpEdMin->Disable();
     306             :     else
     307             :     {
     308           0 :         mpEdMin->Enable();
     309           0 :         if(mpEdMin->GetText().isEmpty())
     310             :         {
     311           0 :             if(nSelectMin == COLORSCALE_PERCENTILE || nSelectMin == COLORSCALE_PERCENT)
     312           0 :                 mpEdMin->SetText(OUString::number(50));
     313             :             else
     314           0 :                 mpEdMin->SetText(OUString::number(0));
     315             :         }
     316             :     }
     317             : 
     318           0 :     sal_Int32 nSelectMax = mpLbTypeMax->GetSelectEntryPos();
     319           0 :     if(nSelectMax <= COLORSCALE_MAX)
     320           0 :         mpEdMax->Disable();
     321             :     else
     322             :     {
     323           0 :         mpEdMax->Enable();
     324           0 :         if(mpEdMax->GetText().isEmpty())
     325             :         {
     326           0 :             if(nSelectMax == COLORSCALE_PERCENTILE || nSelectMax == COLORSCALE_PERCENT)
     327           0 :                 mpEdMax->SetText(OUString::number(50));
     328             :             else
     329           0 :                 mpEdMax->SetText(OUString::number(0));
     330             :         }
     331             :     }
     332           0 :     return 0;
     333             : }
     334             : 
     335           0 : IMPL_LINK_NOARG( ScDataBarSettingsDlg, PosSelectHdl )
     336             : {
     337           0 :     sal_Int32 axisPos = mpLbAxisPos->GetSelectEntryPos();
     338           0 :     if(axisPos != 2 && axisPos != 1) // disable if axis vertical position is automatic
     339             :     {
     340           0 :         mpLenMin->Disable();
     341           0 :         mpLenMax->Disable();
     342             :     }
     343             :     else
     344             :     {
     345           0 :         mpLenMin->Enable();
     346           0 :         mpLenMax->Enable();
     347           0 :         if(mpLenMin->GetText().isEmpty())
     348             :         {
     349           0 :             mpLenMin->SetText(OUString::number(0));
     350           0 :             mpLenMax->SetText(OUString::number(100));
     351             :         }
     352             :     }
     353           0 :     return 0;
     354         156 : }
     355             : 
     356             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
     357             : 

Generated by: LCOV version 1.11