LCOV - code coverage report
Current view: top level - libreoffice/sc/source/ui/condformat - colorformat.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 1 141 0.7 %
Date: 2012-12-17 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             :  * 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             : namespace {
      40             : 
      41           0 : void SetType(const ScColorScaleEntry* pEntry, ListBox& rLstBox)
      42             : {
      43           0 :     rLstBox.SelectEntryPos(pEntry->GetType());
      44           0 : }
      45             : 
      46           0 : void GetType(const ListBox& rLstBox, const Edit& rEd, ScColorScaleEntry* pEntry, SvNumberFormatter* pNumberFormatter,
      47             :         ScDocument* pDoc, const ScAddress& rPos )
      48             : {
      49           0 :     double nVal = 0;
      50           0 :     sal_uInt32 nIndex = 0;
      51           0 :     pEntry->SetType(static_cast<ScColorScaleEntryType>(rLstBox.GetSelectEntryPos()));
      52           0 :     switch(rLstBox.GetSelectEntryPos())
      53             :     {
      54             :         case COLORSCALE_AUTO:
      55             :         case COLORSCALE_MIN:
      56             :         case COLORSCALE_MAX:
      57           0 :             break;
      58             :         case COLORSCALE_PERCENTILE:
      59             :         case COLORSCALE_VALUE:
      60             :         case COLORSCALE_PERCENT:
      61           0 :             pNumberFormatter->IsNumberFormat( rEd.GetText(), nIndex, nVal );
      62           0 :             pEntry->SetValue(nVal);
      63           0 :             break;
      64             :         case COLORSCALE_FORMULA:
      65           0 :             pEntry->SetFormula(rEd.GetText(), pDoc, rPos);
      66           0 :             break;
      67             :     }
      68           0 : }
      69             : 
      70           0 : void SetValue( ScColorScaleEntry* pEntry, Edit& aEdit)
      71             : {
      72           0 :     if(pEntry->GetType() == COLORSCALE_FORMULA)
      73           0 :         aEdit.SetText(pEntry->GetFormula(formula::FormulaGrammar::GRAM_DEFAULT));
      74           0 :     else if(pEntry->GetType() != COLORSCALE_MIN && pEntry->GetType() != COLORSCALE_MAX)
      75           0 :         aEdit.SetText(rtl::OUString::valueOf(pEntry->GetValue()));
      76             :     else
      77           0 :         aEdit.Disable();
      78           0 : }
      79             : 
      80             : }
      81             : 
      82           0 : ScDataBarSettingsDlg::ScDataBarSettingsDlg(Window* pWindow, const ScDataBarFormatData& rData, ScDocument* pDoc, const ScAddress& rPos):
      83             :     ModalDialog( pWindow, ScResId( RID_SCDLG_DATABAR ) ),
      84             :     maBtnOk( this, ScResId( BTN_OK ) ),
      85             :     maBtnCancel( this, ScResId( BTN_CANCEL ) ),
      86             :     maFlBarColors( this, ScResId( FL_BAR_COLORS ) ),
      87             :     maFlAxes( this, ScResId( FL_AXIS ) ),
      88             :     maFlValues( this, ScResId( FL_VALUES ) ),
      89             :     maFtMin( this, ScResId( FT_MINIMUM ) ),
      90             :     maFtMax( this, ScResId( FT_MAXIMUM ) ),
      91             :     maFtPositive( this, ScResId( FT_POSITIVE ) ),
      92             :     maFtNegative( this, ScResId( FT_NEGATIVE ) ),
      93             :     maFtPosition( this, ScResId( FT_POSITION ) ),
      94             :     maFtAxisColor( this, ScResId( FT_COLOR_AXIS ) ),
      95             :     maLbPos( this, ScResId( LB_POS ) ),
      96             :     maLbNeg( this, ScResId( LB_NEG ) ),
      97             :     maLbAxisCol( this, ScResId( LB_COL_AXIS ) ),
      98             :     maLbTypeMin( this, ScResId( LB_TYPE ) ),
      99             :     maLbTypeMax( this, ScResId( LB_TYPE ) ),
     100             :     maLbAxisPos( this, ScResId( LB_AXIS_POSITION ) ),
     101             :     maEdMin( this, ScResId( ED_MIN ) ),
     102             :     maEdMax( this, ScResId( ED_MAX ) ),
     103             :     maStrWarnSameValue( SC_RESSTR( STR_WARN_SAME_VALUE ) ),
     104           0 :     mpNumberFormatter( pDoc->GetFormatTable() ),
     105             :     mpDoc(pDoc),
     106           0 :     maPos(rPos)
     107             : {
     108           0 :     Init();
     109           0 :     FreeResource();
     110             : 
     111           0 :     maLbPos.SelectEntry( rData.maPositiveColor );
     112           0 :     if(rData.mpNegativeColor)
     113           0 :         maLbNeg.SelectEntry( *rData.mpNegativeColor );
     114             : 
     115           0 :     switch (rData.meAxisPosition)
     116             :     {
     117             :         case databar::NONE:
     118           0 :             maLbAxisPos.SelectEntryPos(2);
     119           0 :             break;
     120             :         case databar::AUTOMATIC:
     121           0 :             maLbAxisPos.SelectEntryPos(0);
     122           0 :             break;
     123             :         case databar::MIDDLE:
     124           0 :             maLbAxisPos.SelectEntryPos(1);
     125           0 :             break;
     126             :     }
     127           0 :     ::SetType(rData.mpLowerLimit.get(), maLbTypeMin);
     128           0 :     ::SetType(rData.mpUpperLimit.get(), maLbTypeMax);
     129           0 :     SetValue(rData.mpLowerLimit.get(), maEdMin);
     130           0 :     SetValue(rData.mpUpperLimit.get(), maEdMax);
     131           0 :     maLbAxisCol.SelectEntry(rData.maAxisColor);
     132             : 
     133           0 :     TypeSelectHdl(NULL);
     134           0 : }
     135             : 
     136           0 : void ScDataBarSettingsDlg::Init()
     137             : {
     138           0 :     SfxObjectShell*     pDocSh      = SfxObjectShell::Current();
     139           0 :     const SfxPoolItem*  pItem       = NULL;
     140           0 :     XColorListRef       pColorTable;
     141             : 
     142             :     DBG_ASSERT( pDocSh, "DocShell not found!" );
     143             : 
     144           0 :     if ( pDocSh )
     145             :     {
     146           0 :         pItem = pDocSh->GetItem( SID_COLOR_TABLE );
     147           0 :         if ( pItem != NULL )
     148           0 :             pColorTable = ( (SvxColorListItem*)pItem )->GetColorList();
     149             :     }
     150           0 :     if ( pColorTable.is() )
     151             :     {
     152             :         // filling the line color box
     153           0 :         maLbPos.SetUpdateMode( false );
     154           0 :         maLbNeg.SetUpdateMode( false );
     155           0 :         maLbAxisCol.SetUpdateMode( false );
     156             : 
     157           0 :         for ( long i = 0; i < pColorTable->Count(); ++i )
     158             :         {
     159           0 :             XColorEntry* pEntry = pColorTable->GetColor(i);
     160           0 :             maLbPos.InsertEntry( pEntry->GetColor(), pEntry->GetName() );
     161           0 :             maLbNeg.InsertEntry( pEntry->GetColor(), pEntry->GetName() );
     162           0 :             maLbAxisCol.InsertEntry( pEntry->GetColor(), pEntry->GetName() );
     163             : 
     164           0 :             if(pEntry->GetColor() == Color(COL_LIGHTRED))
     165           0 :                 maLbNeg.SelectEntryPos(i);
     166           0 :             if(pEntry->GetColor() == Color(COL_BLACK))
     167           0 :                 maLbAxisCol.SelectEntryPos(i);
     168           0 :             if(pEntry->GetColor() == Color(COL_LIGHTBLUE))
     169           0 :                 maLbPos.SelectEntryPos(i);
     170             :         }
     171           0 :         maLbPos.SetUpdateMode( sal_True );
     172           0 :         maLbNeg.SetUpdateMode( sal_True );
     173           0 :         maLbAxisCol.SetUpdateMode( sal_True );
     174             :     }
     175           0 :     maBtnOk.SetClickHdl( LINK( this, ScDataBarSettingsDlg, OkBtnHdl ) );
     176             : 
     177           0 :     Point aPoint(maLbTypeMax.GetPosPixel().X(), maFtMax.GetPosPixel().Y());
     178           0 :     maLbTypeMax.SetPosPixel(aPoint);
     179             : 
     180           0 :     maLbTypeMin.SetSelectHdl( LINK( this, ScDataBarSettingsDlg, TypeSelectHdl ) );
     181           0 :     maLbTypeMax.SetSelectHdl( LINK( this, ScDataBarSettingsDlg, TypeSelectHdl ) );
     182             : 
     183           0 : }
     184             : 
     185             : namespace {
     186             : 
     187           0 : void GetAxesPosition(ScDataBarFormatData* pData, const ListBox& rLbox)
     188             : {
     189           0 :     switch(rLbox.GetSelectEntryPos())
     190             :     {
     191             :         case 0:
     192           0 :             pData->meAxisPosition = databar::AUTOMATIC;
     193           0 :             break;
     194             :         case 1:
     195           0 :             pData->meAxisPosition = databar::MIDDLE;
     196           0 :             break;
     197             :         case 2:
     198           0 :             pData->meAxisPosition = databar::NONE;
     199           0 :             break;
     200             :     }
     201           0 : }
     202             : 
     203             : }
     204             : 
     205           0 : ScDataBarFormatData* ScDataBarSettingsDlg::GetData()
     206             : {
     207           0 :     ScDataBarFormatData* pData = new ScDataBarFormatData();
     208           0 :     pData->maPositiveColor = maLbPos.GetSelectEntryColor();
     209           0 :     pData->mpNegativeColor.reset(new Color(maLbNeg.GetSelectEntryColor()));
     210           0 :     pData->mbGradient = true; //FIXME
     211           0 :     pData->mpUpperLimit.reset(new ScColorScaleEntry());
     212           0 :     pData->mpLowerLimit.reset(new ScColorScaleEntry());
     213           0 :     pData->maAxisColor = maLbAxisCol.GetSelectEntryColor();
     214             : 
     215           0 :     ::GetType(maLbTypeMin, maEdMin, pData->mpLowerLimit.get(), mpNumberFormatter, mpDoc, maPos);
     216           0 :     ::GetType(maLbTypeMax, maEdMax, pData->mpUpperLimit.get(), mpNumberFormatter, mpDoc, maPos);
     217           0 :     GetAxesPosition(pData, maLbAxisPos);
     218             : 
     219           0 :     return pData;
     220             : }
     221             : 
     222           0 : IMPL_LINK_NOARG( ScDataBarSettingsDlg, OkBtnHdl )
     223             : {
     224             :     //check that min < max
     225           0 :     bool bWarn = false;
     226           0 :     sal_Int32 nSelectMin = maLbTypeMin.GetSelectEntryPos();
     227           0 :     if( nSelectMin == COLORSCALE_MAX )
     228           0 :         bWarn = true;
     229           0 :     sal_Int32 nSelectMax = maLbTypeMax.GetSelectEntryPos();
     230           0 :     if( nSelectMax == COLORSCALE_MIN )
     231           0 :         bWarn = true;
     232             : 
     233           0 :     if(!bWarn && maLbTypeMin.GetSelectEntryPos() == maLbTypeMax.GetSelectEntryPos())
     234             :     {
     235           0 :         if(maLbTypeMax.GetSelectEntryPos() != COLORSCALE_FORMULA)
     236             :         {
     237           0 :             rtl::OUString aMinString = maEdMin.GetText();
     238           0 :             rtl::OUString aMaxString = maEdMax.GetText();
     239           0 :             double nMinValue = 0;
     240           0 :             sal_uInt32 nIndex = 0;
     241           0 :             mpNumberFormatter->IsNumberFormat(aMinString, nIndex, nMinValue);
     242           0 :             nIndex = 0;
     243           0 :             double nMaxValue = 0;
     244           0 :             mpNumberFormatter->IsNumberFormat(aMaxString, nIndex, nMaxValue);
     245           0 :             if(rtl::math::approxEqual(nMinValue, nMaxValue) || nMinValue > nMaxValue)
     246           0 :                 bWarn = true;
     247             :         }
     248             :     }
     249             : 
     250           0 :     if(bWarn)
     251             :     {
     252             :         //show warning message and don't close
     253           0 :         WarningBox aWarn(this, WB_OK, maStrWarnSameValue );
     254           0 :         aWarn.Execute();
     255             :     }
     256             :     else
     257             :     {
     258           0 :         EndDialog(RET_OK);
     259             :     }
     260           0 :     return 0;
     261             : }
     262             : 
     263           0 : IMPL_LINK_NOARG( ScDataBarSettingsDlg, TypeSelectHdl )
     264             : {
     265           0 :     sal_Int32 nSelectMin = maLbTypeMin.GetSelectEntryPos();
     266           0 :     if( nSelectMin <= COLORSCALE_MAX)
     267           0 :         maEdMin.Disable();
     268             :     else
     269             :     {
     270           0 :         maEdMin.Enable();
     271           0 :         if(!maEdMin.GetText().Len())
     272             :         {
     273           0 :             if(nSelectMin == COLORSCALE_PERCENTILE || nSelectMin == COLORSCALE_PERCENT)
     274           0 :                 maEdMin.SetText(rtl::OUString::valueOf(static_cast<sal_Int32>(50)));
     275             :             else
     276           0 :                 maEdMin.SetText(rtl::OUString::valueOf(static_cast<sal_Int32>(0)));
     277             :         }
     278             :     }
     279             : 
     280           0 :     sal_Int32 nSelectMax = maLbTypeMax.GetSelectEntryPos();
     281           0 :     if(nSelectMax <= COLORSCALE_MAX)
     282           0 :         maEdMax.Disable();
     283             :     else
     284             :     {
     285           0 :         maEdMax.Enable();
     286           0 :         if(!maEdMax.GetText().Len())
     287             :         {
     288           0 :             if(nSelectMax == COLORSCALE_PERCENTILE || nSelectMax == COLORSCALE_PERCENT)
     289           0 :                 maEdMax.SetText(rtl::OUString::valueOf(static_cast<sal_Int32>(50)));
     290             :             else
     291           0 :                 maEdMax.SetText(rtl::OUString::valueOf(static_cast<sal_Int32>(0)));
     292             :         }
     293             :     }
     294           0 :     return 0;
     295         102 : }
     296             : 
     297             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10