LCOV - code coverage report
Current view: top level - libreoffice/sc/source/ui/condformat - condformatdlgentry.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 1 800 0.1 %
Date: 2012-12-17 Functions: 2 87 2.3 %
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 "condformatdlg.hxx"
      11             : #include "condformatdlgentry.hxx"
      12             : #include "condformatdlg.hrc"
      13             : #include "conditio.hxx"
      14             : 
      15             : #include "document.hxx"
      16             : 
      17             : #include <vcl/vclevent.hxx>
      18             : #include <svl/style.hxx>
      19             : #include <sfx2/dispatch.hxx>
      20             : #include <svl/stritem.hxx>
      21             : #include <svl/intitem.hxx>
      22             : #include <svx/xtable.hxx>
      23             : #include <svx/drawitem.hxx>
      24             : #include <vcl/msgbox.hxx>
      25             : #include "stlpool.hxx"
      26             : #include "tabvwsh.hxx"
      27             : 
      28             : #include "colorformat.hxx"
      29             : 
      30             : #include "globstr.hrc"
      31             : 
      32             : #include <set>
      33             : 
      34           0 : ScCondFrmtEntry::ScCondFrmtEntry(Window* pParent, ScDocument* pDoc, const ScAddress& rPos):
      35             :     Control(pParent, ScResId( RID_COND_ENTRY ) ),
      36             :     mbActive(false),
      37             :     maFtCondNr( this, ScResId( FT_COND_NR ) ),
      38             :     maFtCondition( this, ScResId( FT_CONDITION ) ),
      39             :     mnIndex(0),
      40             :     maStrCondition(ScResId( STR_CONDITION ).toString()),
      41             :     maLbType( this, ScResId( LB_TYPE ) ),
      42             :     mpDoc(pDoc),
      43           0 :     maPos(rPos)
      44             : {
      45           0 :     SetControlBackground(GetSettings().GetStyleSettings().GetDialogColor());
      46             : 
      47           0 :     maLbType.SetSelectHdl( LINK( pParent, ScCondFormatList, TypeListHdl ) );
      48           0 :     maClickHdl = LINK( pParent, ScCondFormatList, EntrySelectHdl );
      49           0 : }
      50             : 
      51           0 : ScCondFrmtEntry::~ScCondFrmtEntry()
      52             : {
      53           0 : }
      54             : 
      55           0 : long ScCondFrmtEntry::Notify( NotifyEvent& rNEvt )
      56             : {
      57           0 :     if( rNEvt.GetType() == EVENT_MOUSEBUTTONDOWN )
      58             :     {
      59           0 :         ImplCallEventListenersAndHandler( VCLEVENT_WINDOW_MOUSEBUTTONDOWN, maClickHdl, this );
      60             :     }
      61           0 :     return Control::Notify(rNEvt);
      62             : }
      63             : 
      64           0 : void ScCondFrmtEntry::SetIndex(sal_Int32 nIndex)
      65             : {
      66           0 :     mnIndex = nIndex;
      67           0 :     rtl::OUStringBuffer aBuffer(maStrCondition);
      68           0 :     aBuffer.append(rtl::OUString::valueOf(nIndex));
      69           0 :     maFtCondNr.SetText(aBuffer.makeStringAndClear());
      70           0 : }
      71             : 
      72           0 : void ScCondFrmtEntry::SetHeight()
      73             : {
      74           0 :     long nPad = LogicToPixel(Size(42,2), MapMode(MAP_APPFONT)).getHeight();
      75             : 
      76             :     // Calculate maximum height we need from visible widgets
      77           0 :     sal_uInt16 nChildren = GetChildCount();
      78             : 
      79           0 :     long nMaxHeight = 0;
      80           0 :     for(sal_uInt16 i = 0; i < nChildren; i++)
      81             :     {
      82           0 :         Window *pChild  = GetChild(i);
      83           0 :         if(!pChild || !pChild->IsVisible())
      84           0 :             continue;
      85           0 :         Point aPos = pChild->GetPosPixel();
      86           0 :         Size aSize = pChild->GetSizePixel();
      87           0 :         nMaxHeight = std::max(aPos.Y() + aSize.Height(), nMaxHeight);
      88             :     }
      89           0 :     Size aSize = GetSizePixel();
      90           0 :     if(nMaxHeight > 0)
      91             :     {
      92           0 :         aSize.Height() = nMaxHeight + nPad;
      93           0 :         SetSizePixel(aSize);
      94             :     }
      95           0 : }
      96             : 
      97           0 : void ScCondFrmtEntry::Select()
      98             : {
      99           0 :     maFtCondition.SetText(rtl::OUString());
     100           0 :     maFtCondition.Hide();
     101           0 :     maLbType.Show();
     102           0 :     mbActive = true;
     103           0 :     SetHeight();
     104           0 : }
     105             : 
     106           0 : void ScCondFrmtEntry::Deselect()
     107             : {
     108           0 :     rtl::OUString maCondText = GetExpressionString();
     109           0 :     maFtCondition.SetText(maCondText);
     110           0 :     maFtCondition.Show();
     111           0 :     maLbType.Hide();
     112           0 :     mbActive = false;
     113           0 :     SetHeight();
     114           0 : }
     115             : 
     116           0 : bool ScCondFrmtEntry::IsSelected() const
     117             : {
     118           0 :     return mbActive;
     119             : }
     120             : 
     121           0 : IMPL_LINK(ScCondFrmtEntry, EdModifyHdl, Edit*, pEdit)
     122             : {
     123           0 :     rtl::OUString aFormula = pEdit->GetText();
     124           0 :     ScCompiler aComp( mpDoc, maPos );
     125           0 :     aComp.SetGrammar( mpDoc->GetGrammar() );
     126           0 :     boost::scoped_ptr<ScTokenArray> mpCode(aComp.CompileString(aFormula));
     127           0 :     if(mpCode->GetCodeError())
     128             :     {
     129           0 :         pEdit->SetControlBackground(COL_LIGHTRED);
     130             :     }
     131             :     else
     132             :     {
     133           0 :         pEdit->SetControlBackground(GetSettings().GetStyleSettings().GetWindowColor());
     134             :     }
     135           0 :     return 0;
     136             : }
     137             : 
     138             : //
     139             : //condition
     140             : //
     141             : namespace {
     142             : 
     143           0 : void FillStyleListBox( ScDocument* pDoc, ListBox& rLbStyle )
     144             : {
     145           0 :     rLbStyle.SetSeparatorPos(0);
     146           0 :     std::set<rtl::OUString> aStyleNames;
     147           0 :     SfxStyleSheetIterator aStyleIter( pDoc->GetStyleSheetPool(), SFX_STYLE_FAMILY_PARA );
     148           0 :     for ( SfxStyleSheetBase* pStyle = aStyleIter.First(); pStyle; pStyle = aStyleIter.Next() )
     149             :     {
     150           0 :         rtl::OUString aName = pStyle->GetName();
     151           0 :         aStyleNames.insert(aName);
     152           0 :     }
     153           0 :     for(std::set<rtl::OUString>::const_iterator itr = aStyleNames.begin(), itrEnd = aStyleNames.end();
     154             :                         itr != itrEnd; ++itr)
     155             :     {
     156           0 :         rLbStyle.InsertEntry( *itr );
     157           0 :     }
     158           0 : }
     159             : 
     160             : }
     161             : 
     162           0 : ScConditionFrmtEntry::ScConditionFrmtEntry( Window* pParent, ScDocument* pDoc, const ScAddress& rPos, const ScCondFormatEntry* pFormatEntry ):
     163             :     ScCondFrmtEntry( pParent, pDoc, rPos ),
     164             :     maLbCondType( this, ScResId( LB_CELLIS_TYPE ) ),
     165             :     maEdVal1( this, NULL, ScResId( ED_VAL1 ) ),
     166             :     maEdVal2( this, NULL, ScResId( ED_VAL2 ) ),
     167             :     maFtStyle( this, ScResId( FT_STYLE ) ),
     168             :     maLbStyle( this, ScResId( LB_STYLE ) ),
     169           0 :     maWdPreview( this, ScResId( WD_PREVIEW ) )
     170             : {
     171             : 
     172           0 :     FreeResource();
     173           0 :     maLbType.SelectEntryPos(1);
     174             : 
     175           0 :     Init();
     176             : 
     177           0 :     if(pFormatEntry)
     178             :     {
     179           0 :         rtl::OUString aStyleName = pFormatEntry->GetStyle();
     180           0 :         maLbStyle.SelectEntry(aStyleName);
     181           0 :         StyleSelectHdl(NULL);
     182           0 :         ScConditionMode eMode = pFormatEntry->GetOperation();
     183           0 :         maEdVal1.SetText(pFormatEntry->GetExpression(maPos, 0));
     184           0 :         maEdVal2.Hide();
     185           0 :         switch(eMode)
     186             :         {
     187             :             case SC_COND_EQUAL:
     188           0 :                 maLbCondType.SelectEntryPos(0);
     189           0 :                 break;
     190             :             case SC_COND_LESS:
     191           0 :                 maLbCondType.SelectEntryPos(1);
     192           0 :                 break;
     193             :             case SC_COND_GREATER:
     194           0 :                 maLbCondType.SelectEntryPos(2);
     195           0 :                 break;
     196             :             case SC_COND_EQLESS:
     197           0 :                 maLbCondType.SelectEntryPos(3);
     198           0 :                 break;
     199             :             case SC_COND_EQGREATER:
     200           0 :                 maLbCondType.SelectEntryPos(4);
     201           0 :                 break;
     202             :             case SC_COND_NOTEQUAL:
     203           0 :                 maLbCondType.SelectEntryPos(5);
     204           0 :                 break;
     205             :             case SC_COND_BETWEEN:
     206           0 :                 maEdVal2.Show();
     207           0 :                 maEdVal2.SetText(pFormatEntry->GetExpression(maPos, 1));
     208           0 :                 maLbCondType.SelectEntryPos(6);
     209           0 :                 break;
     210             :             case SC_COND_NOTBETWEEN:
     211           0 :                 maEdVal2.Show();
     212           0 :                 maEdVal2.SetText(pFormatEntry->GetExpression(maPos, 1));
     213           0 :                 maLbCondType.SelectEntryPos(7);
     214           0 :                 break;
     215             :             case SC_COND_DUPLICATE:
     216           0 :                 maLbCondType.SelectEntryPos(8);
     217           0 :                 break;
     218             :             case SC_COND_NOTDUPLICATE:
     219           0 :                 maLbCondType.SelectEntryPos(9);
     220           0 :                 break;
     221             :             case SC_COND_DIRECT:
     222             :                 assert(false);
     223             :                 //maLbType.SelectEntryPos(2);
     224           0 :                 break;
     225             :             case SC_COND_TOP10:
     226           0 :                 maLbCondType.SelectEntryPos(10);
     227           0 :                 break;
     228             :             case SC_COND_BOTTOM10:
     229           0 :                 maLbCondType.SelectEntryPos(11);
     230           0 :                 break;
     231             :             case SC_COND_TOP_PERCENT:
     232           0 :                 maLbCondType.SelectEntryPos(12);
     233           0 :                 break;
     234             :             case SC_COND_BOTTOM_PERCENT:
     235           0 :                 maLbCondType.SelectEntryPos(13);
     236           0 :                 break;
     237             :             case SC_COND_ABOVE_AVERAGE:
     238           0 :                 maEdVal1.Hide();
     239           0 :                 maLbCondType.SelectEntryPos(14);
     240           0 :                 break;
     241             :             case SC_COND_BELOW_AVERAGE:
     242           0 :                 maEdVal1.Hide();
     243           0 :                 maLbCondType.SelectEntryPos(15);
     244           0 :                 break;
     245             :             case SC_COND_ERROR:
     246           0 :                 maEdVal1.Hide();
     247           0 :                 maLbCondType.SelectEntryPos(16);
     248           0 :                 break;
     249             :             case SC_COND_NOERROR:
     250           0 :                 maEdVal1.Hide();
     251           0 :                 maLbCondType.SelectEntryPos(17);
     252           0 :                 break;
     253             :             case SC_COND_BEGINS_WITH:
     254           0 :                 maLbCondType.SelectEntryPos(18);
     255           0 :                 break;
     256             :             case SC_COND_ENDS_WITH:
     257           0 :                 maLbCondType.SelectEntryPos(19);
     258           0 :                 break;
     259             :             case SC_COND_CONTAINS_TEXT:
     260           0 :                 maLbCondType.SelectEntryPos(20);
     261           0 :                 break;
     262             :             case SC_COND_NOT_CONTAINS_TEXT:
     263           0 :                 maLbCondType.SelectEntryPos(21);
     264           0 :                 break;
     265             :             case SC_COND_NONE:
     266           0 :                 break;
     267           0 :         }
     268             :     }
     269             :     else
     270             :     {
     271           0 :         maLbCondType.SelectEntryPos(0);
     272           0 :         maEdVal2.Hide();
     273           0 :         maLbStyle.SelectEntryPos(1);
     274             :     }
     275           0 :     maLbType.SelectEntryPos(1);
     276           0 : }
     277             : 
     278           0 : void ScConditionFrmtEntry::Init()
     279             : {
     280           0 :     maEdVal1.SetGetFocusHdl( LINK( GetParent()->GetParent(), ScCondFormatDlg, RangeGetFocusHdl ) );
     281           0 :     maEdVal2.SetGetFocusHdl( LINK( GetParent()->GetParent(), ScCondFormatDlg, RangeGetFocusHdl ) );
     282           0 :     maEdVal1.SetLoseFocusHdl( LINK( GetParent()->GetParent(), ScCondFormatDlg, RangeLoseFocusHdl ) );
     283           0 :     maEdVal2.SetLoseFocusHdl( LINK( GetParent()->GetParent(), ScCondFormatDlg, RangeLoseFocusHdl ) );
     284             : 
     285           0 :     maEdVal1.SetStyle( maEdVal1.GetStyle() | WB_FORCECTRLBACKGROUND );
     286           0 :     maEdVal2.SetStyle( maEdVal2.GetStyle() | WB_FORCECTRLBACKGROUND );
     287             : 
     288           0 :     maEdVal1.SetModifyHdl( LINK( this, ScCondFrmtEntry, EdModifyHdl ) );
     289           0 :     maEdVal2.SetModifyHdl( LINK( this, ScCondFrmtEntry, EdModifyHdl ) );
     290             : 
     291           0 :     FillStyleListBox( mpDoc, maLbStyle );
     292           0 :     maLbStyle.SetSelectHdl( LINK( this, ScConditionFrmtEntry, StyleSelectHdl ) );
     293             : 
     294           0 :     maLbCondType.SetSelectHdl( LINK( this, ScConditionFrmtEntry, ConditionTypeSelectHdl ) );
     295           0 : }
     296             : 
     297           0 : ScFormatEntry* ScConditionFrmtEntry::createConditionEntry() const
     298             : {
     299             :     ScConditionMode eMode;
     300           0 :     rtl::OUString aExpr2;
     301           0 :     switch(maLbCondType.GetSelectEntryPos())
     302             :     {
     303             :         case 0:
     304           0 :             eMode = SC_COND_EQUAL;
     305           0 :             break;
     306             :         case 1:
     307           0 :             eMode = SC_COND_LESS;
     308           0 :             break;
     309             :         case 2:
     310           0 :             eMode = SC_COND_GREATER;
     311           0 :             break;
     312             :         case 3:
     313           0 :             eMode = SC_COND_EQLESS;
     314           0 :             break;
     315             :         case 4:
     316           0 :             eMode = SC_COND_EQGREATER;
     317           0 :             break;
     318             :         case 5:
     319           0 :             eMode = SC_COND_NOTEQUAL;
     320           0 :             break;
     321             :         case 6:
     322           0 :             aExpr2 = maEdVal2.GetText();
     323           0 :             eMode = SC_COND_BETWEEN;
     324           0 :             if(aExpr2.isEmpty())
     325           0 :                 return NULL;
     326           0 :             break;
     327             :         case 7:
     328           0 :             eMode = SC_COND_NOTBETWEEN;
     329           0 :             aExpr2 = maEdVal2.GetText();
     330           0 :             if(aExpr2.isEmpty())
     331           0 :                 return NULL;
     332           0 :             break;
     333             :         case 8:
     334           0 :             eMode = SC_COND_DUPLICATE;
     335           0 :             break;
     336             :         case 9:
     337           0 :             eMode = SC_COND_NOTDUPLICATE;
     338           0 :             break;
     339             :         case 10:
     340           0 :             eMode = SC_COND_TOP10;
     341           0 :             break;
     342             :         case 11:
     343           0 :             eMode = SC_COND_BOTTOM10;
     344           0 :             break;
     345             :         case 12:
     346           0 :             eMode = SC_COND_TOP_PERCENT;
     347           0 :             break;
     348             :         case 13:
     349           0 :             eMode = SC_COND_BOTTOM_PERCENT;
     350           0 :             break;
     351             :         case 14:
     352           0 :             eMode = SC_COND_ABOVE_AVERAGE;
     353           0 :             break;
     354             :         case 15:
     355           0 :             eMode = SC_COND_BELOW_AVERAGE;
     356           0 :             break;
     357             :         case 16:
     358           0 :             eMode = SC_COND_ERROR;
     359           0 :             break;
     360             :         case 17:
     361           0 :             eMode = SC_COND_NOERROR;
     362           0 :             break;
     363             :         case 18:
     364           0 :             eMode = SC_COND_BEGINS_WITH;
     365           0 :             break;
     366             :         case 19:
     367           0 :             eMode = SC_COND_ENDS_WITH;
     368           0 :             break;
     369             :         case 20:
     370           0 :             eMode = SC_COND_CONTAINS_TEXT;
     371           0 :             break;
     372             :         case 21:
     373           0 :             eMode = SC_COND_NOT_CONTAINS_TEXT;
     374           0 :             break;
     375             :         default:
     376             :             assert(false); // this cannot happen
     377           0 :             return NULL;
     378             :     }
     379             : 
     380           0 :     rtl::OUString aExpr1 = maEdVal1.GetText();
     381             : 
     382           0 :     ScFormatEntry* pEntry = new ScCondFormatEntry(eMode, aExpr1, aExpr2, mpDoc, maPos, maLbStyle.GetSelectEntry());
     383             : 
     384           0 :     return pEntry;
     385             : }
     386             : 
     387           0 : rtl::OUString ScConditionFrmtEntry::GetExpressionString()
     388             : {
     389           0 :     return ScCondFormatHelper::GetExpression(CONDITION, maLbCondType.GetSelectEntryPos(), maEdVal1.GetText(), maEdVal2.GetText());
     390             : }
     391             : 
     392           0 : ScFormatEntry* ScConditionFrmtEntry::GetEntry() const
     393             : {
     394           0 :     return createConditionEntry();
     395             : }
     396             : 
     397           0 : void ScConditionFrmtEntry::SetActive()
     398             : {
     399           0 :     maLbCondType.Show();
     400           0 :     maEdVal1.Show();
     401           0 :     if(maLbCondType.GetSelectEntryPos() == 6 || maLbCondType.GetSelectEntryPos() == 7)
     402           0 :         maEdVal2.Show();
     403           0 :     maFtStyle.Show();
     404           0 :     maLbStyle.Show();
     405           0 :     maWdPreview.Show();
     406             : 
     407           0 :     Select();
     408           0 : }
     409             : 
     410           0 : void ScConditionFrmtEntry::SetInactive()
     411             : {
     412           0 :     maLbCondType.Hide();
     413           0 :     maEdVal1.Hide();
     414           0 :     maEdVal2.Hide();
     415           0 :     maFtStyle.Hide();
     416           0 :     maLbStyle.Hide();
     417           0 :     maWdPreview.Hide();
     418             : 
     419           0 :     Deselect();
     420           0 : }
     421             : 
     422             : namespace {
     423             : 
     424           0 : void StyleSelect( ListBox& rLbStyle, ScDocument* pDoc, SvxFontPrevWindow& rWdPreview )
     425             : {
     426           0 :     if(rLbStyle.GetSelectEntryPos() == 0)
     427             :     {
     428             :         // call new style dialog
     429           0 :         SfxUInt16Item aFamilyItem( SID_STYLE_FAMILY, SFX_STYLE_FAMILY_PARA );
     430           0 :         SfxStringItem aRefItem( SID_STYLE_REFERENCE, ScGlobal::GetRscString(STR_STYLENAME_STANDARD) );
     431             : 
     432             :         // unlock the dispatcher so SID_STYLE_NEW can be executed
     433             :         // (SetDispatcherLock would affect all Calc documents)
     434           0 :         ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
     435           0 :         SfxDispatcher* pDisp = pViewShell->GetDispatcher();
     436           0 :         sal_Bool bLocked = pDisp->IsLocked();
     437           0 :         if (bLocked)
     438           0 :             pDisp->Lock(false);
     439             : 
     440             :         // Execute the "new style" slot, complete with undo and all necessary updates.
     441             :         // The return value (SfxUInt16Item) is ignored, look for new styles instead.
     442             :         pDisp->Execute( SID_STYLE_NEW, SFX_CALLMODE_SYNCHRON | SFX_CALLMODE_RECORD | SFX_CALLMODE_MODAL,
     443             :                 &aFamilyItem,
     444             :                 &aRefItem,
     445           0 :                 0L );
     446             : 
     447           0 :         if (bLocked)
     448           0 :             pDisp->Lock(sal_True);
     449             : 
     450             :         // Find the new style and add it into the style list boxes
     451           0 :         rtl::OUString aNewStyle;
     452           0 :         SfxStyleSheetIterator aStyleIter( pDoc->GetStyleSheetPool(), SFX_STYLE_FAMILY_PARA );
     453           0 :         bool bFound = false;
     454           0 :         for ( SfxStyleSheetBase* pStyle = aStyleIter.First(); pStyle && !bFound; pStyle = aStyleIter.Next() )
     455             :         {
     456           0 :             rtl::OUString aName = pStyle->GetName();
     457           0 :             if ( rLbStyle.GetEntryPos(aName) == LISTBOX_ENTRY_NOTFOUND )    // all lists contain the same entries
     458             :             {
     459           0 :                 for( sal_uInt16 i = 1, n = rLbStyle.GetEntryCount(); i <= n && !bFound; ++i)
     460             :                 {
     461           0 :                     rtl::OUString aStyleName = ScGlobal::pCharClass->uppercase(rtl::OUString(rLbStyle.GetEntry(i)));
     462           0 :                     if( i == n )
     463             :                     {
     464           0 :                         rLbStyle.InsertEntry(aName);
     465           0 :                         rLbStyle.SelectEntry(aName);
     466           0 :                         bFound = true;
     467             :                     }
     468           0 :                     else if( aStyleName > ScGlobal::pCharClass->uppercase(aName) )
     469             :                     {
     470           0 :                         rLbStyle.InsertEntry(aName, i);
     471           0 :                         rLbStyle.SelectEntry(aName);
     472           0 :                         bFound = true;
     473             :                     }
     474           0 :                 }
     475             :             }
     476           0 :         }
     477             :     }
     478             : 
     479           0 :     rtl::OUString aStyleName = rLbStyle.GetSelectEntry();
     480           0 :     SfxStyleSheetBase* pStyleSheet = pDoc->GetStyleSheetPool()->Find( aStyleName, SFX_STYLE_FAMILY_PARA );
     481           0 :     if(pStyleSheet)
     482             :     {
     483           0 :         const SfxItemSet& rSet = pStyleSheet->GetItemSet();
     484           0 :         rWdPreview.Init( rSet );
     485           0 :     }
     486           0 : }
     487             : 
     488             : }
     489             : 
     490           0 : IMPL_LINK_NOARG(ScConditionFrmtEntry, StyleSelectHdl)
     491             : {
     492           0 :     StyleSelect( maLbStyle, mpDoc, maWdPreview );
     493           0 :     return 0;
     494             : }
     495             : 
     496             : // formula
     497             : 
     498           0 : ScFormulaFrmtEntry::ScFormulaFrmtEntry( Window* pParent, ScDocument* pDoc, const ScAddress& rPos, const ScCondFormatEntry* pFormat ):
     499             :     ScCondFrmtEntry( pParent, pDoc, rPos ),
     500             :     maFtStyle( this, ScResId( FT_STYLE ) ),
     501             :     maLbStyle( this, ScResId( LB_STYLE ) ),
     502             :     maWdPreview( this, ScResId( WD_PREVIEW ) ),
     503           0 :     maEdFormula( this, NULL, ScResId( ED_FORMULA ) )
     504             : {
     505           0 :     Init();
     506             : 
     507           0 :     FreeResource();
     508           0 :     maLbType.SelectEntryPos(2);
     509             : 
     510           0 :     if(pFormat)
     511             :     {
     512           0 :         maEdFormula.SetText(pFormat->GetExpression(rPos, 0, 0, pDoc->GetGrammar()));
     513           0 :         maLbStyle.SelectEntry(pFormat->GetStyle());
     514             :     }
     515             :     else
     516             :     {
     517           0 :         maLbStyle.SelectEntryPos(1);
     518             :     }
     519           0 : }
     520             : 
     521           0 : void ScFormulaFrmtEntry::Init()
     522             : {
     523           0 :     maEdFormula.SetGetFocusHdl( LINK( GetParent()->GetParent(), ScCondFormatDlg, RangeGetFocusHdl ) );
     524           0 :     maEdFormula.SetLoseFocusHdl( LINK( GetParent()->GetParent(), ScCondFormatDlg, RangeLoseFocusHdl ) );
     525             : 
     526           0 :     FillStyleListBox( mpDoc, maLbStyle );
     527           0 :     maLbStyle.SetSelectHdl( LINK( this, ScFormulaFrmtEntry, StyleSelectHdl ) );
     528           0 : }
     529             : 
     530           0 : IMPL_LINK_NOARG(ScFormulaFrmtEntry, StyleSelectHdl)
     531             : {
     532           0 :     StyleSelect( maLbStyle, mpDoc, maWdPreview );
     533             : 
     534           0 :     return 0;
     535             : }
     536             : 
     537           0 : ScFormatEntry* ScFormulaFrmtEntry::createFormulaEntry() const
     538             : {
     539           0 :     ScConditionMode eMode = SC_COND_DIRECT;
     540           0 :     rtl::OUString aFormula = maEdFormula.GetText();
     541           0 :     if(aFormula.isEmpty())
     542           0 :         return NULL;
     543             : 
     544           0 :     rtl::OUString aExpr2;
     545           0 :     ScFormatEntry* pEntry = new ScCondFormatEntry(eMode, aFormula, aExpr2, mpDoc, maPos, maLbStyle.GetSelectEntry());
     546           0 :     return pEntry;
     547             : }
     548             : 
     549           0 : ScFormatEntry* ScFormulaFrmtEntry::GetEntry() const
     550             : {
     551           0 :     return createFormulaEntry();
     552             : }
     553             : 
     554           0 : rtl::OUString ScFormulaFrmtEntry::GetExpressionString()
     555             : {
     556           0 :     return ScCondFormatHelper::GetExpression(FORMULA, 0, maEdFormula.GetText());
     557             : }
     558             : 
     559           0 : void ScFormulaFrmtEntry::SetActive()
     560             : {
     561           0 :     maWdPreview.Show();
     562           0 :     maFtStyle.Show();
     563           0 :     maLbStyle.Show();
     564           0 :     maEdFormula.Show();
     565             : 
     566           0 :     Select();
     567           0 : }
     568             : 
     569           0 : void ScFormulaFrmtEntry::SetInactive()
     570             : {
     571           0 :     maWdPreview.Hide();
     572           0 :     maFtStyle.Hide();
     573           0 :     maLbStyle.Hide();
     574           0 :     maEdFormula.Hide();
     575             : 
     576           0 :     Deselect();
     577           0 : }
     578             : 
     579             : //color scale
     580             : 
     581             : namespace {
     582             : 
     583           0 : void SetColorScaleEntryTypes( const ScColorScaleEntry& rEntry, ListBox& rLbType, Edit& rEdit, ColorListBox& rLbCol )
     584             : {
     585             :     // entry Automatic is not available for color scales
     586           0 :     sal_Int32 nIndex = static_cast<sal_Int32>(rEntry.GetType());
     587             :     assert(nIndex > 0);
     588           0 :     rLbType.SelectEntryPos(nIndex - 1);
     589           0 :     switch(rEntry.GetType())
     590             :     {
     591             :         case COLORSCALE_MIN:
     592             :         case COLORSCALE_MAX:
     593           0 :             break;
     594             :         case COLORSCALE_PERCENTILE:
     595             :         case COLORSCALE_VALUE:
     596             :         case COLORSCALE_PERCENT:
     597           0 :             rEdit.SetText(rtl::OUString::valueOf(rEntry.GetValue()));
     598           0 :             break;
     599             :         case COLORSCALE_FORMULA:
     600           0 :             rEdit.SetText(rEntry.GetFormula(formula::FormulaGrammar::GRAM_DEFAULT));
     601           0 :             break;
     602             :         case COLORSCALE_AUTO:
     603           0 :             abort();
     604             :             break;
     605             :     }
     606           0 :     rLbCol.SelectEntry(rEntry.GetColor());
     607           0 : }
     608             : 
     609           0 : void SetColorScaleEntry( ScColorScaleEntry* pEntry, const ListBox& rType, const Edit& rValue, ScDocument* pDoc, const ScAddress& rPos, bool bDataBar )
     610             : {
     611           0 :     sal_uInt32 nIndex = 0;
     612           0 :     double nVal = 0;
     613           0 :     SvNumberFormatter* pNumberFormatter = pDoc->GetFormatTable();
     614           0 :     pNumberFormatter->IsNumberFormat(rValue.GetText(), nIndex, nVal);
     615             : 
     616             :     // color scale does not have the automatic entry
     617           0 :     sal_Int32 nPos = rType.GetSelectEntryPos();
     618           0 :     if(!bDataBar)
     619           0 :         ++nPos;
     620             : 
     621           0 :     pEntry->SetType(static_cast<ScColorScaleEntryType>(nPos));
     622           0 :     switch(nPos)
     623             :     {
     624             :         case COLORSCALE_AUTO:
     625             :         case COLORSCALE_MIN:
     626             :         case COLORSCALE_MAX:
     627           0 :             break;
     628             :         case COLORSCALE_PERCENTILE:
     629             :         case COLORSCALE_VALUE:
     630             :         case COLORSCALE_PERCENT:
     631           0 :             pEntry->SetValue(nVal);
     632           0 :             break;
     633             :         case COLORSCALE_FORMULA:
     634           0 :             pEntry->SetFormula(rValue.GetText(), pDoc, rPos);
     635           0 :             break;
     636             :         default:
     637           0 :             break;
     638             :     }
     639           0 : }
     640             : 
     641           0 : ScColorScaleEntry* createColorScaleEntry( const ListBox& rType, const ColorListBox& rColor, const Edit& rValue, ScDocument* pDoc, const ScAddress& rPos )
     642             : {
     643           0 :     ScColorScaleEntry* pEntry = new ScColorScaleEntry();
     644             : 
     645           0 :     SetColorScaleEntry( pEntry, rType, rValue, pDoc, rPos, false );
     646           0 :     Color aColor = rColor.GetSelectEntryColor();
     647           0 :     pEntry->SetColor(aColor);
     648           0 :     return pEntry;
     649             : }
     650             : 
     651             : }
     652             : 
     653           0 : ScColorScale2FrmtEntry::ScColorScale2FrmtEntry( Window* pParent, ScDocument* pDoc, const ScAddress& rPos, const ScColorScaleFormat* pFormat ):
     654             :     ScCondFrmtEntry( pParent, pDoc, rPos ),
     655             :     maLbColorFormat( this, ScResId( LB_COLOR_FORMAT ) ),
     656             :     maLbEntryTypeMin( this, ScResId( LB_TYPE_COL_SCALE_MIN ) ),
     657             :     maLbEntryTypeMax( this, ScResId( LB_TYPE_COL_SCALE_MAX ) ),
     658             :     maEdMin( this, ScResId( ED_COL_SCALE_MIN ) ),
     659             :     maEdMax( this, ScResId( ED_COL_SCALE_MAX ) ),
     660             :     maLbColMin( this, ScResId( LB_COL_MIN ) ),
     661           0 :     maLbColMax( this, ScResId( LB_COL_MAX ) )
     662             : {
     663             :     // remove the automatic entry from color scales
     664           0 :     maLbEntryTypeMin.RemoveEntry(0);
     665           0 :     maLbEntryTypeMax.RemoveEntry(0);
     666             : 
     667           0 :     maLbType.SelectEntryPos(0);
     668           0 :     maLbColorFormat.SelectEntryPos(0);
     669           0 :     if(pFormat)
     670             :     {
     671           0 :         ScColorScaleFormat::const_iterator itr = pFormat->begin();
     672           0 :         SetColorScaleEntryTypes(*itr, maLbEntryTypeMin, maEdMin, maLbColMin);
     673           0 :         ++itr;
     674           0 :         SetColorScaleEntryTypes(*itr, maLbEntryTypeMax, maEdMax, maLbColMax);
     675             :     }
     676             :     else
     677             :     {
     678           0 :         maLbEntryTypeMin.SelectEntryPos(0);
     679           0 :         maLbEntryTypeMax.SelectEntryPos(1);
     680             :     }
     681           0 :     FreeResource();
     682             : 
     683           0 :     maLbColorFormat.SetSelectHdl( LINK( pParent, ScCondFormatList, ColFormatTypeHdl ) );
     684             : 
     685           0 :     Init();
     686           0 : }
     687             : 
     688           0 : void ScColorScale2FrmtEntry::Init()
     689             : {
     690           0 :     maLbEntryTypeMin.SetSelectHdl( LINK( this, ScColorScale2FrmtEntry, EntryTypeHdl ) );
     691           0 :     maLbEntryTypeMax.SetSelectHdl( LINK( this, ScColorScale2FrmtEntry, EntryTypeHdl ) );
     692             : 
     693           0 :     SfxObjectShell*     pDocSh      = SfxObjectShell::Current();
     694           0 :     const SfxPoolItem*  pItem       = NULL;
     695           0 :     XColorListRef       pColorTable;
     696             : 
     697             :     DBG_ASSERT( pDocSh, "DocShell not found!" );
     698             : 
     699           0 :     if ( pDocSh )
     700             :     {
     701           0 :         pItem = pDocSh->GetItem( SID_COLOR_TABLE );
     702           0 :         if ( pItem != NULL )
     703           0 :             pColorTable = ( (SvxColorListItem*)pItem )->GetColorList();
     704             :     }
     705           0 :     if ( pColorTable.is() )
     706             :     {
     707             :         // filling the line color box
     708           0 :         maLbColMin.SetUpdateMode( false );
     709           0 :         maLbColMax.SetUpdateMode( false );
     710             : 
     711           0 :         for ( long i = 0; i < pColorTable->Count(); ++i )
     712             :         {
     713           0 :             XColorEntry* pEntry = pColorTable->GetColor(i);
     714           0 :             maLbColMin.InsertEntry( pEntry->GetColor(), pEntry->GetName() );
     715           0 :             maLbColMax.InsertEntry( pEntry->GetColor(), pEntry->GetName() );
     716             : 
     717           0 :             if(pEntry->GetColor() == Color(COL_LIGHTRED))
     718           0 :                 maLbColMin.SelectEntryPos(i);
     719           0 :             if(pEntry->GetColor() == Color(COL_LIGHTBLUE))
     720           0 :                 maLbColMax.SelectEntryPos(i);
     721             :         }
     722           0 :         maLbColMin.SetUpdateMode( sal_True );
     723           0 :         maLbColMax.SetUpdateMode( sal_True );
     724             :     }
     725             : 
     726           0 :     EntryTypeHdl(&maLbEntryTypeMin);
     727           0 :     EntryTypeHdl(&maLbEntryTypeMax);
     728           0 : }
     729             : 
     730           0 : ScFormatEntry* ScColorScale2FrmtEntry::createColorscaleEntry() const
     731             : {
     732           0 :     ScColorScaleFormat* pColorScale = new ScColorScaleFormat(mpDoc);
     733           0 :     pColorScale->AddEntry(createColorScaleEntry(maLbEntryTypeMin, maLbColMin, maEdMin, mpDoc, maPos));
     734           0 :     pColorScale->AddEntry(createColorScaleEntry(maLbEntryTypeMax, maLbColMax, maEdMax, mpDoc, maPos));
     735           0 :     return pColorScale;
     736             : }
     737             : 
     738           0 : rtl::OUString ScColorScale2FrmtEntry::GetExpressionString()
     739             : {
     740           0 :     return ScCondFormatHelper::GetExpression( COLORSCALE, 0 );
     741             : }
     742             : 
     743           0 : ScFormatEntry* ScColorScale2FrmtEntry::GetEntry() const
     744             : {
     745           0 :     return createColorscaleEntry();
     746             : }
     747             : 
     748           0 : void ScColorScale2FrmtEntry::SetActive()
     749             : {
     750           0 :     maLbColorFormat.Show();
     751             : 
     752           0 :     maLbEntryTypeMin.Show();
     753           0 :     maLbEntryTypeMax.Show();
     754             : 
     755           0 :     maEdMin.Show();
     756           0 :     maEdMax.Show();
     757             : 
     758           0 :     maLbColMin.Show();
     759           0 :     maLbColMax.Show();
     760             : 
     761           0 :     Select();
     762           0 : }
     763             : 
     764           0 : void ScColorScale2FrmtEntry::SetInactive()
     765             : {
     766           0 :     maLbColorFormat.Hide();
     767             : 
     768           0 :     maLbEntryTypeMin.Hide();
     769           0 :     maLbEntryTypeMax.Hide();
     770             : 
     771           0 :     maEdMin.Hide();
     772           0 :     maEdMax.Hide();
     773             : 
     774           0 :     maLbColMin.Hide();
     775           0 :     maLbColMax.Hide();
     776             : 
     777           0 :     Deselect();
     778           0 : }
     779             : 
     780           0 : IMPL_LINK( ScColorScale2FrmtEntry, EntryTypeHdl, ListBox*, pBox )
     781             : {
     782           0 :     bool bEnableEdit = true;
     783           0 :     sal_Int32 nPos = pBox->GetSelectEntryPos();
     784           0 :     if(nPos < 2)
     785             :     {
     786           0 :         bEnableEdit = false;
     787             :     }
     788             : 
     789           0 :     Edit* pEd = NULL;
     790           0 :     if(pBox == &maLbEntryTypeMin)
     791           0 :         pEd = &maEdMin;
     792           0 :     else if(pBox == &maLbEntryTypeMax)
     793           0 :         pEd = &maEdMax;
     794             : 
     795           0 :     if(bEnableEdit)
     796           0 :         pEd->Enable();
     797             :     else
     798           0 :         pEd->Disable();
     799             : 
     800           0 :     return 0;
     801             : }
     802             : 
     803           0 : ScColorScale3FrmtEntry::ScColorScale3FrmtEntry( Window* pParent, ScDocument* pDoc, const ScAddress& rPos, const ScColorScaleFormat* pFormat ):
     804             :     ScCondFrmtEntry( pParent, pDoc, rPos ),
     805             :     maLbColorFormat( this, ScResId( LB_COLOR_FORMAT ) ),
     806             :     maLbEntryTypeMin( this, ScResId( LB_TYPE_COL_SCALE_MIN ) ),
     807             :     maLbEntryTypeMiddle( this, ScResId( LB_TYPE_COL_SCALE_MIDDLE ) ),
     808             :     maLbEntryTypeMax( this, ScResId( LB_TYPE_COL_SCALE_MAX ) ),
     809             :     maEdMin( this, ScResId( ED_COL_SCALE_MIN ) ),
     810             :     maEdMiddle( this, ScResId( ED_COL_SCALE_MIDDLE ) ),
     811             :     maEdMax( this, ScResId( ED_COL_SCALE_MAX ) ),
     812             :     maLbColMin( this, ScResId( LB_COL_MIN ) ),
     813             :     maLbColMiddle( this, ScResId( LB_COL_MIDDLE ) ),
     814           0 :     maLbColMax( this, ScResId( LB_COL_MAX ) )
     815             : {
     816             :     // remove the automatic entry from color scales
     817           0 :     maLbEntryTypeMin.RemoveEntry(0);
     818           0 :     maLbEntryTypeMiddle.RemoveEntry(0);
     819           0 :     maLbEntryTypeMax.RemoveEntry(0);
     820             : 
     821           0 :     maLbType.SelectEntryPos(0);
     822           0 :     if(pFormat)
     823             :     {
     824           0 :         ScColorScaleFormat::const_iterator itr = pFormat->begin();
     825           0 :         SetColorScaleEntryTypes(*itr, maLbEntryTypeMin, maEdMin, maLbColMin);
     826             :         assert(pFormat->size() == 3);
     827           0 :         ++itr;
     828           0 :         SetColorScaleEntryTypes(*itr, maLbEntryTypeMiddle, maEdMiddle, maLbColMiddle);
     829           0 :         ++itr;
     830           0 :         SetColorScaleEntryTypes(*itr, maLbEntryTypeMax, maEdMax, maLbColMax);
     831             :     }
     832             :     else
     833             :     {
     834           0 :         maLbColorFormat.SelectEntryPos(1);
     835           0 :         maLbEntryTypeMin.SelectEntryPos(0);
     836           0 :         maLbEntryTypeMiddle.SelectEntryPos(2);
     837           0 :         maLbEntryTypeMax.SelectEntryPos(1);
     838           0 :         maEdMiddle.SetText(rtl::OUString::valueOf(static_cast<sal_Int32>(50)));
     839             :     }
     840           0 :     FreeResource();
     841             : 
     842           0 :     maLbColorFormat.SetSelectHdl( LINK( pParent, ScCondFormatList, ColFormatTypeHdl ) );
     843             : 
     844           0 :     Init();
     845           0 : }
     846             : 
     847           0 : void ScColorScale3FrmtEntry::Init()
     848             : {
     849           0 :     maLbEntryTypeMin.SetSelectHdl( LINK( this, ScColorScale3FrmtEntry, EntryTypeHdl ) );
     850           0 :     maLbEntryTypeMax.SetSelectHdl( LINK( this, ScColorScale3FrmtEntry, EntryTypeHdl ) );
     851           0 :     maLbEntryTypeMiddle.SetSelectHdl( LINK( this, ScColorScale3FrmtEntry, EntryTypeHdl ) );
     852             : 
     853           0 :     SfxObjectShell*     pDocSh      = SfxObjectShell::Current();
     854           0 :     const SfxPoolItem*  pItem       = NULL;
     855           0 :     XColorListRef       pColorTable;
     856             : 
     857             :     DBG_ASSERT( pDocSh, "DocShell not found!" );
     858             : 
     859           0 :     if ( pDocSh )
     860             :     {
     861           0 :         pItem = pDocSh->GetItem( SID_COLOR_TABLE );
     862           0 :         if ( pItem != NULL )
     863           0 :             pColorTable = ( (SvxColorListItem*)pItem )->GetColorList();
     864             :     }
     865           0 :     if ( pColorTable.is() )
     866             :     {
     867             :         // filling the line color box
     868           0 :         maLbColMin.SetUpdateMode( false );
     869           0 :         maLbColMiddle.SetUpdateMode( false );
     870           0 :         maLbColMax.SetUpdateMode( false );
     871             : 
     872           0 :         for ( long i = 0; i < pColorTable->Count(); ++i )
     873             :         {
     874           0 :             XColorEntry* pEntry = pColorTable->GetColor(i);
     875           0 :             maLbColMin.InsertEntry( pEntry->GetColor(), pEntry->GetName() );
     876           0 :             maLbColMiddle.InsertEntry( pEntry->GetColor(), pEntry->GetName() );
     877           0 :             maLbColMax.InsertEntry( pEntry->GetColor(), pEntry->GetName() );
     878             : 
     879           0 :             if(pEntry->GetColor() == Color(COL_LIGHTRED))
     880           0 :                 maLbColMin.SelectEntryPos(i);
     881           0 :             if(pEntry->GetColor() == Color(COL_GREEN))
     882           0 :                 maLbColMiddle.SelectEntryPos(i);
     883           0 :             if(pEntry->GetColor() == Color(COL_LIGHTBLUE))
     884           0 :                 maLbColMax.SelectEntryPos(i);
     885             :         }
     886           0 :         maLbColMin.SetUpdateMode( sal_True );
     887           0 :         maLbColMiddle.SetUpdateMode( sal_True );
     888           0 :         maLbColMax.SetUpdateMode( sal_True );
     889             :     }
     890             : 
     891           0 :     EntryTypeHdl(&maLbEntryTypeMin);
     892           0 :     EntryTypeHdl(&maLbEntryTypeMiddle);
     893           0 :     EntryTypeHdl(&maLbEntryTypeMax);
     894           0 : }
     895             : 
     896           0 : ScFormatEntry* ScColorScale3FrmtEntry::createColorscaleEntry() const
     897             : {
     898           0 :     ScColorScaleFormat* pColorScale = new ScColorScaleFormat(mpDoc);
     899           0 :     pColorScale->AddEntry(createColorScaleEntry(maLbEntryTypeMin, maLbColMin, maEdMin, mpDoc, maPos));
     900           0 :     if(maLbColorFormat.GetSelectEntryPos() == 1)
     901           0 :         pColorScale->AddEntry(createColorScaleEntry(maLbEntryTypeMiddle, maLbColMiddle, maEdMiddle, mpDoc, maPos));
     902           0 :     pColorScale->AddEntry(createColorScaleEntry(maLbEntryTypeMax, maLbColMax, maEdMax, mpDoc, maPos));
     903           0 :     return pColorScale;
     904             : }
     905             : 
     906           0 : rtl::OUString ScColorScale3FrmtEntry::GetExpressionString()
     907             : {
     908           0 :     return ScCondFormatHelper::GetExpression( COLORSCALE, 0 );
     909             : }
     910             : 
     911           0 : ScFormatEntry* ScColorScale3FrmtEntry::GetEntry() const
     912             : {
     913           0 :     return createColorscaleEntry();
     914             : }
     915             : 
     916           0 : void ScColorScale3FrmtEntry::SetActive()
     917             : {
     918           0 :     maLbColorFormat.Show();
     919           0 :     maLbEntryTypeMin.Show();
     920           0 :     maLbEntryTypeMiddle.Show();
     921           0 :     maLbEntryTypeMax.Show();
     922             : 
     923           0 :     maEdMin.Show();
     924           0 :     maEdMiddle.Show();
     925           0 :     maEdMax.Show();
     926             : 
     927           0 :     maLbColMin.Show();
     928           0 :     maLbColMiddle.Show();
     929           0 :     maLbColMax.Show();
     930             : 
     931           0 :     Select();
     932           0 : }
     933             : 
     934           0 : void ScColorScale3FrmtEntry::SetInactive()
     935             : {
     936           0 :     maLbColorFormat.Hide();
     937             : 
     938           0 :     maLbEntryTypeMin.Hide();
     939           0 :     maLbEntryTypeMiddle.Hide();
     940           0 :     maLbEntryTypeMax.Hide();
     941             : 
     942           0 :     maEdMin.Hide();
     943           0 :     maEdMiddle.Hide();
     944           0 :     maEdMax.Hide();
     945             : 
     946           0 :     maLbColMin.Hide();
     947           0 :     maLbColMiddle.Hide();
     948           0 :     maLbColMax.Hide();
     949             : 
     950           0 :     Deselect();
     951           0 : }
     952             : 
     953           0 : IMPL_LINK( ScColorScale3FrmtEntry, EntryTypeHdl, ListBox*, pBox )
     954             : {
     955           0 :     bool bEnableEdit = true;
     956           0 :     sal_Int32 nPos = pBox->GetSelectEntryPos();
     957           0 :     if(nPos < 2)
     958             :     {
     959           0 :         bEnableEdit = false;
     960             :     }
     961             : 
     962           0 :     Edit* pEd = NULL;
     963           0 :     if(pBox == &maLbEntryTypeMin)
     964           0 :         pEd = &maEdMin;
     965           0 :     else if(pBox == &maLbEntryTypeMiddle)
     966           0 :         pEd = &maEdMiddle;
     967           0 :     else if(pBox == &maLbEntryTypeMax)
     968           0 :         pEd = &maEdMax;
     969             : 
     970           0 :     if(bEnableEdit)
     971           0 :         pEd->Enable();
     972             :     else
     973           0 :         pEd->Disable();
     974             : 
     975           0 :     return 0;
     976             : }
     977             : 
     978           0 : IMPL_LINK_NOARG( ScConditionFrmtEntry, ConditionTypeSelectHdl )
     979             : {
     980           0 :     sal_Int32 nSelectPos = maLbCondType.GetSelectEntryPos();
     981           0 :     if(nSelectPos == 6 || nSelectPos == 7)
     982             :     {
     983           0 :         maEdVal1.Show();
     984           0 :         maEdVal2.Show();
     985             :     }
     986           0 :     else if(nSelectPos == 8 || nSelectPos == 9)
     987             :     {
     988           0 :         maEdVal2.Hide();
     989           0 :         maEdVal1.Hide();
     990             :     }
     991           0 :     else if(nSelectPos <= 5 || (nSelectPos >= 10 && nSelectPos <= 13)
     992             :             || nSelectPos >= 18)
     993             :     {
     994           0 :         maEdVal1.Show();
     995           0 :         maEdVal2.Hide();
     996             :     }
     997             :     else
     998             :     {
     999           0 :         maEdVal1.Hide();
    1000           0 :         maEdVal2.Hide();
    1001             :     }
    1002             : 
    1003           0 :     return 0;
    1004             : }
    1005             : 
    1006             : //databar
    1007             : 
    1008             : namespace {
    1009             : 
    1010           0 : void SetDataBarEntryTypes( const ScColorScaleEntry& rEntry, ListBox& rLbType, Edit& rEdit )
    1011             : {
    1012           0 :     rLbType.SelectEntryPos(rEntry.GetType());
    1013           0 :     switch(rEntry.GetType())
    1014             :     {
    1015             :         case COLORSCALE_AUTO:
    1016             :         case COLORSCALE_MIN:
    1017             :         case COLORSCALE_MAX:
    1018           0 :             break;
    1019             :         case COLORSCALE_PERCENTILE:
    1020           0 :             rEdit.SetText(rtl::OUString::valueOf(rEntry.GetValue()));
    1021           0 :             break;
    1022             :         case COLORSCALE_PERCENT:
    1023           0 :             rEdit.SetText(rtl::OUString::valueOf(rEntry.GetValue()));
    1024           0 :             break;
    1025             :         case COLORSCALE_FORMULA:
    1026           0 :             rEdit.SetText(rEntry.GetFormula(formula::FormulaGrammar::GRAM_DEFAULT));
    1027           0 :             break;
    1028             :         case COLORSCALE_VALUE:
    1029           0 :             rEdit.SetText(rtl::OUString::valueOf(rEntry.GetValue()));
    1030           0 :             break;
    1031             :     }
    1032           0 : }
    1033             : 
    1034             : }
    1035             : 
    1036           0 : ScDataBarFrmtEntry::ScDataBarFrmtEntry( Window* pParent, ScDocument* pDoc, const ScAddress& rPos, const ScDataBarFormat* pFormat ):
    1037             :     ScCondFrmtEntry( pParent, pDoc, rPos ),
    1038             :     maLbColorFormat( this, ScResId( LB_COLOR_FORMAT ) ),
    1039             :     maLbDataBarMinType( this, ScResId( LB_TYPE_COL_SCALE_MIN ) ),
    1040             :     maLbDataBarMaxType( this, ScResId( LB_TYPE_COL_SCALE_MAX ) ),
    1041             :     maEdDataBarMin( this, ScResId( ED_COL_SCALE_MIN ) ),
    1042             :     maEdDataBarMax( this, ScResId( ED_COL_SCALE_MAX ) ),
    1043           0 :     maBtOptions( this, ScResId( BTN_OPTIONS ) )
    1044             : {
    1045           0 :     maLbColorFormat.SelectEntryPos(2);
    1046           0 :     maLbType.SelectEntryPos(0);
    1047           0 :     if(pFormat)
    1048             :     {
    1049           0 :         mpDataBarData.reset(new ScDataBarFormatData(*pFormat->GetDataBarData()));
    1050           0 :         SetDataBarEntryTypes(*mpDataBarData->mpLowerLimit, maLbDataBarMinType, maEdDataBarMin);
    1051           0 :         SetDataBarEntryTypes(*mpDataBarData->mpUpperLimit, maLbDataBarMaxType, maEdDataBarMax);
    1052           0 :         DataBarTypeSelectHdl(NULL);
    1053             :     }
    1054             :     else
    1055             :     {
    1056           0 :         maLbDataBarMinType.SelectEntryPos(0);
    1057           0 :         maLbDataBarMaxType.SelectEntryPos(0);
    1058           0 :         DataBarTypeSelectHdl(NULL);
    1059             :     }
    1060           0 :     Init();
    1061             : 
    1062           0 :     maLbColorFormat.SetSelectHdl( LINK( pParent, ScCondFormatList, ColFormatTypeHdl ) );
    1063             : 
    1064           0 :     FreeResource();
    1065           0 : }
    1066             : 
    1067           0 : ScFormatEntry* ScDataBarFrmtEntry::GetEntry() const
    1068             : {
    1069           0 :     return createDatabarEntry();
    1070             : }
    1071             : 
    1072           0 : void ScDataBarFrmtEntry::Init()
    1073             : {
    1074           0 :     maLbDataBarMinType.SetSelectHdl( LINK( this, ScDataBarFrmtEntry, DataBarTypeSelectHdl ) );
    1075           0 :     maLbDataBarMaxType.SetSelectHdl( LINK( this, ScDataBarFrmtEntry, DataBarTypeSelectHdl ) );
    1076             : 
    1077           0 :     maBtOptions.SetClickHdl( LINK( this, ScDataBarFrmtEntry, OptionBtnHdl ) );
    1078             : 
    1079           0 :     mpDataBarData.reset(new ScDataBarFormatData());
    1080           0 :     mpDataBarData->mpUpperLimit.reset(new ScColorScaleEntry());
    1081           0 :     mpDataBarData->mpLowerLimit.reset(new ScColorScaleEntry());
    1082           0 :     mpDataBarData->mpLowerLimit->SetType(COLORSCALE_AUTO);
    1083           0 :     mpDataBarData->mpUpperLimit->SetType(COLORSCALE_AUTO);
    1084           0 :     mpDataBarData->maPositiveColor = COL_LIGHTBLUE;
    1085           0 : }
    1086             : 
    1087           0 : ScFormatEntry* ScDataBarFrmtEntry::createDatabarEntry() const
    1088             : {
    1089           0 :     SetColorScaleEntry(mpDataBarData->mpLowerLimit.get(), maLbDataBarMinType, maEdDataBarMin, mpDoc, maPos, true);
    1090           0 :     SetColorScaleEntry(mpDataBarData->mpUpperLimit.get(), maLbDataBarMaxType, maEdDataBarMax, mpDoc, maPos, true);
    1091           0 :     ScDataBarFormat* pDataBar = new ScDataBarFormat(mpDoc);
    1092           0 :     pDataBar->SetDataBarData(new ScDataBarFormatData(*mpDataBarData.get()));
    1093           0 :     return pDataBar;
    1094             : }
    1095             : 
    1096           0 : rtl::OUString ScDataBarFrmtEntry::GetExpressionString()
    1097             : {
    1098           0 :     return ScCondFormatHelper::GetExpression( DATABAR, 0 );
    1099             : }
    1100             : 
    1101           0 : void ScDataBarFrmtEntry::SetActive()
    1102             : {
    1103           0 :     maLbColorFormat.Show();
    1104             : 
    1105           0 :     maLbDataBarMinType.Show();
    1106           0 :     maLbDataBarMaxType.Show();
    1107           0 :     maEdDataBarMin.Show();
    1108           0 :     maEdDataBarMax.Show();
    1109           0 :     maBtOptions.Show();
    1110             : 
    1111           0 :     Select();
    1112           0 : }
    1113             : 
    1114           0 : void ScDataBarFrmtEntry::SetInactive()
    1115             : {
    1116           0 :     maLbColorFormat.Hide();
    1117             : 
    1118           0 :     maLbDataBarMinType.Hide();
    1119           0 :     maLbDataBarMaxType.Hide();
    1120           0 :     maEdDataBarMin.Hide();
    1121           0 :     maEdDataBarMax.Hide();
    1122           0 :     maBtOptions.Hide();
    1123             : 
    1124           0 :     Deselect();
    1125           0 : }
    1126             : 
    1127           0 : IMPL_LINK_NOARG( ScDataBarFrmtEntry, DataBarTypeSelectHdl )
    1128             : {
    1129           0 :     sal_Int32 nSelectPos = maLbDataBarMinType.GetSelectEntryPos();
    1130           0 :     if(nSelectPos <= COLORSCALE_MAX)
    1131           0 :         maEdDataBarMin.Disable();
    1132             :     else
    1133           0 :         maEdDataBarMin.Enable();
    1134             : 
    1135           0 :     nSelectPos = maLbDataBarMaxType.GetSelectEntryPos();
    1136           0 :     if(nSelectPos <= COLORSCALE_MAX)
    1137           0 :         maEdDataBarMax.Disable();
    1138             :     else
    1139           0 :         maEdDataBarMax.Enable();
    1140             : 
    1141           0 :     return 0;
    1142             : }
    1143             : 
    1144           0 : IMPL_LINK_NOARG( ScDataBarFrmtEntry, OptionBtnHdl )
    1145             : {
    1146           0 :     SetColorScaleEntry(mpDataBarData->mpLowerLimit.get(), maLbDataBarMinType, maEdDataBarMin, mpDoc, maPos, true);
    1147           0 :     SetColorScaleEntry(mpDataBarData->mpUpperLimit.get(), maLbDataBarMaxType, maEdDataBarMax, mpDoc, maPos, true);
    1148           0 :     ScDataBarSettingsDlg* pDlg = new ScDataBarSettingsDlg(this, *mpDataBarData, mpDoc, maPos);
    1149           0 :     if( pDlg->Execute() == RET_OK)
    1150             :     {
    1151           0 :         mpDataBarData.reset(pDlg->GetData());
    1152           0 :         SetDataBarEntryTypes(*mpDataBarData->mpLowerLimit, maLbDataBarMinType, maEdDataBarMin);
    1153           0 :         SetDataBarEntryTypes(*mpDataBarData->mpUpperLimit, maLbDataBarMaxType, maEdDataBarMax);
    1154           0 :         DataBarTypeSelectHdl(NULL);
    1155             :     }
    1156           0 :     return 0;
    1157             : }
    1158             : 
    1159           0 : ScDateFrmtEntry::ScDateFrmtEntry( Window* pParent, ScDocument* pDoc, const ScCondDateFormatEntry* pFormat ):
    1160             :     ScCondFrmtEntry( pParent, pDoc, ScAddress() ),
    1161             :     maLbDateEntry( this, ScResId( LB_DATE_TYPE ) ),
    1162             :     maFtStyle( this, ScResId( FT_STYLE ) ),
    1163             :     maLbStyle( this, ScResId( LB_STYLE ) ),
    1164           0 :     maWdPreview( this, ScResId( WD_PREVIEW ) )
    1165             : {
    1166           0 :     Init();
    1167           0 :     FreeResource();
    1168             : 
    1169           0 :     if(pFormat)
    1170             :     {
    1171           0 :         sal_Int32 nPos = static_cast<sal_Int32>(pFormat->GetDateType());
    1172           0 :         maLbDateEntry.SelectEntryPos(nPos);
    1173             :     }
    1174           0 : }
    1175             : 
    1176           0 : void ScDateFrmtEntry::Init()
    1177             : {
    1178           0 :     maLbDateEntry.SelectEntryPos(0);
    1179           0 :     maLbType.SelectEntryPos(3);
    1180             : 
    1181           0 :     FillStyleListBox( mpDoc, maLbStyle );
    1182           0 :     maLbStyle.SetSelectHdl( LINK( this, ScDateFrmtEntry, StyleSelectHdl ) );
    1183           0 : }
    1184             : 
    1185           0 : void ScDateFrmtEntry::SetActive()
    1186             : {
    1187           0 :     maLbDateEntry.Show();
    1188           0 :     maFtStyle.Show();
    1189           0 :     maWdPreview.Show();
    1190             : 
    1191           0 :     Select();
    1192           0 : }
    1193             : 
    1194           0 : void ScDateFrmtEntry::SetInactive()
    1195             : {
    1196           0 :     maLbDateEntry.Show();
    1197           0 :     maFtStyle.Show();
    1198           0 :     maWdPreview.Show();
    1199             : 
    1200           0 :     Deselect();
    1201           0 : }
    1202             : 
    1203           0 : ScFormatEntry* ScDateFrmtEntry::GetEntry() const
    1204             : {
    1205           0 :     ScCondDateFormatEntry* pNewEntry = new ScCondDateFormatEntry(mpDoc);
    1206           0 :     condformat::ScCondFormatDateType eType = static_cast<condformat::ScCondFormatDateType>(maLbDateEntry.GetSelectEntryPos());
    1207           0 :     pNewEntry->SetDateType(eType);
    1208           0 :     pNewEntry->SetStyleName(maLbStyle.GetSelectEntry());
    1209           0 :     return pNewEntry;
    1210             : }
    1211             : 
    1212           0 : rtl::OUString ScDateFrmtEntry::GetExpressionString()
    1213             : {
    1214           0 :     return ScCondFormatHelper::GetExpression(DATE, 0);
    1215             : }
    1216             : 
    1217           0 : IMPL_LINK_NOARG( ScDateFrmtEntry, StyleSelectHdl )
    1218             : {
    1219           0 :     StyleSelect( maLbStyle, mpDoc, maWdPreview );
    1220             : 
    1221           0 :     return 0;
    1222             : }
    1223             : 
    1224           0 : ScIconSetFrmtEntry::ScIconSetFrmtDataEntry::ScIconSetFrmtDataEntry( Window* pParent, ScIconSetType eType, sal_Int32 i, const ScColorScaleEntry* pEntry ):
    1225             :     Control( pParent, ScResId( RID_ICON_SET_ENTRY ) ),
    1226             :     maImgIcon( this, ScResId( IMG_ICON ) ),
    1227             :     maFtEntry( this, ScResId( FT_ICON_SET_ENTRY_TEXT ) ),
    1228             :     maEdEntry( this, ScResId( ED_ICON_SET_ENTRY_VALUE ) ),
    1229           0 :     maLbEntryType( this, ScResId( LB_ICON_SET_ENTRY_TYPE ) )
    1230             : {
    1231           0 :     maImgIcon.SetImage(ScIconSetFormat::getBitmap( eType, i ));
    1232           0 :     if(pEntry)
    1233             :     {
    1234           0 :         switch(pEntry->GetType())
    1235             :         {
    1236             :             case COLORSCALE_VALUE:
    1237           0 :                 maLbEntryType.SelectEntryPos(0);
    1238           0 :                 maEdEntry.SetText(OUString::valueOf(pEntry->GetValue()));
    1239           0 :                 break;
    1240             :             case COLORSCALE_PERCENTILE:
    1241           0 :                 maLbEntryType.SelectEntryPos(2);
    1242           0 :                 maEdEntry.SetText(OUString::valueOf(pEntry->GetValue()));
    1243           0 :                 break;
    1244             :             case COLORSCALE_PERCENT:
    1245           0 :                 maLbEntryType.SelectEntryPos(1);
    1246           0 :                 maEdEntry.SetText(OUString::valueOf(pEntry->GetValue()));
    1247           0 :                 break;
    1248             :             case COLORSCALE_FORMULA:
    1249           0 :                 maLbEntryType.SelectEntryPos(3);
    1250           0 :                 maEdEntry.SetText(pEntry->GetFormula(formula::FormulaGrammar::GRAM_DEFAULT));
    1251           0 :                 break;
    1252             :             default:
    1253             :                 assert(false);
    1254             :         }
    1255             :     }
    1256             :     else
    1257             :     {
    1258           0 :         maLbEntryType.SelectEntryPos(1);
    1259             :     }
    1260           0 :     FreeResource();
    1261           0 : }
    1262             : 
    1263           0 : ScColorScaleEntry* ScIconSetFrmtEntry::ScIconSetFrmtDataEntry::CreateEntry(ScDocument* pDoc, const ScAddress& rPos) const
    1264             : {
    1265           0 :     sal_Int32 nPos = maLbEntryType.GetSelectEntryPos();
    1266           0 :     rtl::OUString aText = maEdEntry.GetText();
    1267           0 :     ScColorScaleEntry* pEntry = new ScColorScaleEntry();
    1268             : 
    1269           0 :     sal_uInt32 nIndex = 0;
    1270           0 :     double nVal = 0;
    1271           0 :     SvNumberFormatter* pNumberFormatter = pDoc->GetFormatTable();
    1272           0 :     pNumberFormatter->IsNumberFormat(aText, nIndex, nVal);
    1273           0 :     pEntry->SetValue(nVal);
    1274             : 
    1275           0 :     switch(nPos)
    1276             :     {
    1277             :         case 0:
    1278           0 :             pEntry->SetType(COLORSCALE_VALUE);
    1279           0 :             break;
    1280             :         case 1:
    1281           0 :             pEntry->SetType(COLORSCALE_PERCENT);
    1282           0 :             break;
    1283             :         case 2:
    1284           0 :             pEntry->SetType(COLORSCALE_PERCENTILE);
    1285           0 :             break;
    1286             :         case 3:
    1287           0 :             pEntry->SetType(COLORSCALE_FORMULA);
    1288           0 :             pEntry->SetFormula(aText, pDoc, rPos, pDoc->GetGrammar());
    1289           0 :             break;
    1290             :         default:
    1291             :             assert(false);
    1292             :     }
    1293             : 
    1294           0 :     return pEntry;
    1295             : }
    1296             : 
    1297           0 : void ScIconSetFrmtEntry::ScIconSetFrmtDataEntry::SetLastEntry()
    1298             : {
    1299           0 :     maEdEntry.Hide();
    1300           0 :     maLbEntryType.Hide();
    1301           0 :     maFtEntry.Hide();
    1302           0 : }
    1303             : 
    1304           0 : ScIconSetFrmtEntry::ScIconSetFrmtEntry( Window* pParent, ScDocument* pDoc, const ScAddress& rPos, const ScIconSetFormat* pFormat ):
    1305             :         ScCondFrmtEntry( pParent, pDoc, rPos ),
    1306             :         maLbColorFormat( this, ScResId( LB_COLOR_FORMAT ) ),
    1307           0 :         maLbIconSetType( this, ScResId( LB_ICONSET_TYPE ) )
    1308             : {
    1309           0 :     Init();
    1310           0 :     FreeResource();
    1311           0 :     maLbColorFormat.SetSelectHdl( LINK( pParent, ScCondFormatList, ColFormatTypeHdl ) );
    1312             : 
    1313           0 :     if(pFormat)
    1314             :     {
    1315           0 :         const ScIconSetFormatData* pIconSetFormatData = pFormat->GetIconSetData();
    1316           0 :         ScIconSetType eType = pIconSetFormatData->eIconSetType;
    1317           0 :         sal_Int32 nType = static_cast<sal_Int32>(eType);
    1318           0 :         maLbIconSetType.SelectEntryPos(nType);
    1319             : 
    1320           0 :         for(size_t i = 0, n = pIconSetFormatData->maEntries.size();
    1321             :                 i < n; ++i)
    1322             :         {
    1323           0 :             maEntries.push_back( new ScIconSetFrmtDataEntry( this, eType, i, &pIconSetFormatData->maEntries[i] ) );
    1324           0 :             Point aPos = maEntries[0].GetPosPixel();
    1325           0 :             aPos.Y() += maEntries[0].GetSizePixel().Height() * i * 1.2;
    1326           0 :             maEntries[i].SetPosPixel( aPos );
    1327             :         }
    1328           0 :         maEntries.back().SetLastEntry();
    1329             :     }
    1330             :     else
    1331           0 :         IconSetTypeHdl(NULL);
    1332           0 : }
    1333             : 
    1334           0 : void ScIconSetFrmtEntry::Init()
    1335             : {
    1336           0 :     maLbColorFormat.SelectEntryPos(3);
    1337           0 :     maLbType.SelectEntryPos(0);
    1338           0 :     maLbIconSetType.SelectEntryPos(0);
    1339             : 
    1340           0 :     maLbIconSetType.SetSelectHdl( LINK( this, ScIconSetFrmtEntry, IconSetTypeHdl ) );
    1341           0 : }
    1342             : 
    1343           0 : IMPL_LINK_NOARG( ScIconSetFrmtEntry, IconSetTypeHdl )
    1344             : {
    1345           0 :     ScIconSetMap* pMap = ScIconSetFormat::getIconSetMap();
    1346             : 
    1347           0 :     sal_Int32 nPos = maLbIconSetType.GetSelectEntryPos();
    1348           0 :     sal_uInt32 nElements = pMap[nPos].nElements;
    1349           0 :     maEntries.clear();
    1350             : 
    1351           0 :     for(size_t i = 0; i < nElements; ++i)
    1352             :     {
    1353           0 :         maEntries.push_back( new ScIconSetFrmtDataEntry( this, static_cast<ScIconSetType>(nPos), i ) );
    1354           0 :         Point aPos = maEntries[0].GetPosPixel();
    1355           0 :         aPos.Y() += maEntries[0].GetSizePixel().Height() * i * 1.2;
    1356           0 :         maEntries[i].SetPosPixel( aPos );
    1357             :     }
    1358           0 :     maEntries.back().SetLastEntry();
    1359             : 
    1360           0 :     return 0;
    1361             : }
    1362             : 
    1363           0 : OUString ScIconSetFrmtEntry::GetExpressionString()
    1364             : {
    1365           0 :     return ScCondFormatHelper::GetExpression(ICONSET, 0);
    1366             : }
    1367             : 
    1368           0 : void ScIconSetFrmtEntry::SetActive()
    1369             : {
    1370           0 :     maLbColorFormat.Show();
    1371           0 :     maLbIconSetType.Show();
    1372           0 :     for(ScIconSetFrmtDateEntriesType::iterator itr = maEntries.begin(),
    1373           0 :             itrEnd = maEntries.end(); itr != itrEnd; ++itr)
    1374             :     {
    1375           0 :         itr->Show();
    1376             :     }
    1377             : 
    1378           0 :     Select();
    1379           0 : }
    1380             : 
    1381           0 : void ScIconSetFrmtEntry::SetInactive()
    1382             : {
    1383           0 :     maLbColorFormat.Hide();
    1384           0 :     maLbIconSetType.Hide();
    1385           0 :     for(ScIconSetFrmtDateEntriesType::iterator itr = maEntries.begin(),
    1386           0 :             itrEnd = maEntries.end(); itr != itrEnd; ++itr)
    1387             :     {
    1388           0 :         itr->Hide();
    1389             :     }
    1390             : 
    1391           0 :     Deselect();
    1392           0 : }
    1393             : 
    1394           0 : ScFormatEntry* ScIconSetFrmtEntry::GetEntry() const
    1395             : {
    1396           0 :     ScIconSetFormat* pFormat = new ScIconSetFormat(mpDoc);
    1397             : 
    1398           0 :     ScIconSetFormatData* pData = new ScIconSetFormatData;
    1399           0 :     pData->eIconSetType = static_cast<ScIconSetType>(maLbIconSetType.GetSelectEntryPos());
    1400           0 :     for(ScIconSetFrmtDateEntriesType::const_iterator itr = maEntries.begin(),
    1401           0 :             itrEnd = maEntries.end(); itr != itrEnd; ++itr)
    1402             :     {
    1403           0 :         pData->maEntries.push_back(itr->CreateEntry(mpDoc, maPos));
    1404             :     }
    1405           0 :     pFormat->SetIconSetData(pData);
    1406             : 
    1407           0 :     return pFormat;
    1408         102 : }
    1409             : 
    1410             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10