LCOV - code coverage report
Current view: top level - sc/source/ui/condformat - condformatdlg.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 672 0.0 %
Date: 2012-08-25 Functions: 0 60 0.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 0 -

           Branch data     Line data    Source code
       1                 :            : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2                 :            : /*
       3                 :            :  * Version: MPL 1.1 / GPLv3+ / LGPLv3+
       4                 :            :  *
       5                 :            :  * The contents of this file are subject to the Mozilla Public License Version
       6                 :            :  * 1.1 (the "License"); you may not use this file except in compliance with
       7                 :            :  * the License or as specified alternatively below. You may obtain a copy of
       8                 :            :  * the License at http://www.mozilla.org/MPL/
       9                 :            :  *
      10                 :            :  * Software distributed under the License is distributed on an "AS IS" basis,
      11                 :            :  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
      12                 :            :  * for the specific language governing rights and limitations under the
      13                 :            :  * License.
      14                 :            :  *
      15                 :            :  * Major Contributor(s):
      16                 :            :  * Copyright (C) 2012 Markus Mohrhard <markus.mohrhard@googlemail.com> (initial developer)
      17                 :            :  *
      18                 :            :  * All Rights Reserved.
      19                 :            :  *
      20                 :            :  * For minor contributions see the git repository.
      21                 :            :  *
      22                 :            :  * Alternatively, the contents of this file may be used under the terms of
      23                 :            :  * either the GNU General Public License Version 3 or later (the "GPLv3+"), or
      24                 :            :  * the GNU Lesser General Public License Version 3 or later (the "LGPLv3+"),
      25                 :            :  * in which case the provisions of the GPLv3+ or the LGPLv3+ are applicable
      26                 :            :  * instead of those above.
      27                 :            :  */
      28                 :            : 
      29                 :            : #include "condformatdlg.hxx"
      30                 :            : #include "condformatdlg.hrc"
      31                 :            : 
      32                 :            : #include <vcl/vclevent.hxx>
      33                 :            : #include <svl/style.hxx>
      34                 :            : #include <sfx2/dispatch.hxx>
      35                 :            : #include <svl/stritem.hxx>
      36                 :            : #include <svl/intitem.hxx>
      37                 :            : #include <svx/xtable.hxx>
      38                 :            : #include <svx/drawitem.hxx>
      39                 :            : #include <vcl/msgbox.hxx>
      40                 :            : 
      41                 :            : #include "anyrefdg.hxx"
      42                 :            : #include "document.hxx"
      43                 :            : #include "conditio.hxx"
      44                 :            : #include "stlpool.hxx"
      45                 :            : #include "tabvwsh.hxx"
      46                 :            : #include "conditio.hxx"
      47                 :            : #include "colorscale.hxx"
      48                 :            : #include "colorformat.hxx"
      49                 :            : 
      50                 :            : #include "globstr.hrc"
      51                 :            : 
      52                 :            : #include <cassert>
      53                 :            : #include <iostream>
      54                 :            : 
      55                 :            : namespace {
      56                 :            : 
      57                 :          0 : void SetColorScaleEntryTypes( const ScColorScaleEntry& rEntry, ListBox& rLbType, Edit& rEdit, ColorListBox& rLbCol )
      58                 :            : {
      59                 :          0 :     switch(rEntry.GetType())
      60                 :            :     {
      61                 :            :         case COLORSCALE_MIN:
      62                 :          0 :             rLbType.SelectEntryPos(0);
      63                 :          0 :             break;
      64                 :            :         case COLORSCALE_MAX:
      65                 :          0 :             rLbType.SelectEntryPos(1);
      66                 :          0 :             break;
      67                 :            :         case COLORSCALE_PERCENTILE:
      68                 :          0 :             rEdit.SetText(rtl::OUString::valueOf(rEntry.GetValue()));
      69                 :          0 :             rLbType.SelectEntryPos(2);
      70                 :          0 :             break;
      71                 :            :         case COLORSCALE_PERCENT:
      72                 :          0 :             rEdit.SetText(rtl::OUString::valueOf(rEntry.GetValue()));
      73                 :          0 :             rLbType.SelectEntryPos(4);
      74                 :          0 :             break;
      75                 :            :         case COLORSCALE_FORMULA:
      76                 :          0 :             rEdit.SetText(rEntry.GetFormula(formula::FormulaGrammar::GRAM_DEFAULT));
      77                 :          0 :             rLbType.SelectEntryPos(5);
      78                 :          0 :             break;
      79                 :            :         case COLORSCALE_VALUE:
      80                 :          0 :             rEdit.SetText(rtl::OUString::valueOf(rEntry.GetValue()));
      81                 :          0 :             rLbType.SelectEntryPos(3);
      82                 :          0 :             break;
      83                 :            :         case COLORSCALE_AUTOMIN:
      84                 :          0 :             rLbType.SelectEntryPos(6);
      85                 :          0 :             break;
      86                 :            :         case COLORSCALE_AUTOMAX:
      87                 :          0 :             rLbType.SelectEntryPos(7);
      88                 :          0 :             break;
      89                 :            :     }
      90                 :          0 :     rLbCol.SelectEntry(rEntry.GetColor());
      91                 :          0 : }
      92                 :            : 
      93                 :          0 : void SetDataBarEntryTypes( const ScColorScaleEntry& rEntry, ListBox& rLbType, Edit& rEdit )
      94                 :            : {
      95                 :          0 :     switch(rEntry.GetType())
      96                 :            :     {
      97                 :            :         case COLORSCALE_MIN:
      98                 :          0 :             rLbType.SelectEntryPos(0);
      99                 :          0 :             break;
     100                 :            :         case COLORSCALE_MAX:
     101                 :          0 :             rLbType.SelectEntryPos(1);
     102                 :          0 :             break;
     103                 :            :         case COLORSCALE_PERCENTILE:
     104                 :          0 :             rEdit.SetText(rtl::OUString::valueOf(rEntry.GetValue()));
     105                 :          0 :             rLbType.SelectEntryPos(2);
     106                 :          0 :             break;
     107                 :            :         case COLORSCALE_PERCENT:
     108                 :          0 :             rEdit.SetText(rtl::OUString::valueOf(rEntry.GetValue()));
     109                 :          0 :             rLbType.SelectEntryPos(4);
     110                 :          0 :             break;
     111                 :            :         case COLORSCALE_FORMULA:
     112                 :          0 :             rEdit.SetText(rEntry.GetFormula(formula::FormulaGrammar::GRAM_DEFAULT));
     113                 :          0 :             rLbType.SelectEntryPos(5);
     114                 :          0 :             break;
     115                 :            :         case COLORSCALE_VALUE:
     116                 :          0 :             rEdit.SetText(rtl::OUString::valueOf(rEntry.GetValue()));
     117                 :          0 :             rLbType.SelectEntryPos(3);
     118                 :          0 :             break;
     119                 :            :         case COLORSCALE_AUTOMIN:
     120                 :          0 :             rLbType.SelectEntryPos(6);
     121                 :          0 :             break;
     122                 :            :         case COLORSCALE_AUTOMAX:
     123                 :          0 :             rLbType.SelectEntryPos(7);
     124                 :          0 :             break;
     125                 :            :     }
     126                 :          0 : }
     127                 :            : 
     128                 :            : }
     129                 :            : 
     130                 :          0 : ScCondFrmtEntry::ScCondFrmtEntry(Window* pParent, ScDocument* pDoc, const ScAddress& rPos):
     131                 :            :     Control(pParent, ScResId( RID_COND_ENTRY ) ),
     132                 :            :     mbActive(false),
     133                 :            :     meType(CONDITION),
     134                 :            :     maLbType( this, ScResId( LB_TYPE ) ),
     135                 :            :     maFtCondNr( this, ScResId( FT_COND_NR ) ),
     136                 :            :     maFtCondition( this, ScResId( FT_CONDITION ) ),
     137                 :            :     maLbCondType( this, ScResId( LB_CELLIS_TYPE ) ),
     138                 :            :     maEdVal1( this, ScResId( ED_VAL1 ) ),
     139                 :            :     maEdVal2( this, ScResId( ED_VAL2 ) ),
     140                 :            :     maFtStyle( this, ScResId( FT_STYLE ) ),
     141                 :            :     maLbStyle( this, ScResId( LB_STYLE ) ),
     142                 :            :     maWdPreview( this, ScResId( WD_PREVIEW ) ),
     143                 :            :     maLbColorFormat( this, ScResId( LB_COLOR_FORMAT ) ),
     144                 :            :     maLbColScale2( this, ScResId( LB_COL_SCALE2 ) ),
     145                 :            :     maLbColScale3( this, ScResId( LB_COL_SCALE3 ) ),
     146                 :            :     maLbEntryTypeMin( this, ScResId( LB_TYPE_COL_SCALE ) ),
     147                 :            :     maLbEntryTypeMiddle( this, ScResId( LB_TYPE_COL_SCALE ) ),
     148                 :            :     maLbEntryTypeMax( this, ScResId( LB_TYPE_COL_SCALE ) ),
     149                 :            :     maEdMin( this, ScResId( ED_COL_SCALE ) ),
     150                 :            :     maEdMiddle( this, ScResId( ED_COL_SCALE ) ),
     151                 :            :     maEdMax( this, ScResId( ED_COL_SCALE ) ),
     152                 :            :     maLbColMin( this, ScResId( LB_COL) ),
     153                 :            :     maLbColMiddle( this, ScResId( LB_COL) ),
     154                 :            :     maLbColMax( this, ScResId( LB_COL) ),
     155                 :            :     maLbDataBarMinType( this, ScResId( LB_TYPE_COL_SCALE ) ),
     156                 :            :     maLbDataBarMaxType( this, ScResId( LB_TYPE_COL_SCALE ) ),
     157                 :            :     maEdDataBarMin( this, ScResId( ED_COL_SCALE ) ),
     158                 :            :     maEdDataBarMax( this, ScResId( ED_COL_SCALE ) ),
     159                 :            :     maBtOptions( this, ScResId( BTN_OPTIONS ) ),
     160                 :            :     mpDoc(pDoc),
     161                 :            :     maPos(rPos),
     162                 :            :     mnIndex(0),
     163                 :          0 :     maStrCondition(ScResId( STR_CONDITION ).toString())
     164                 :            : {
     165                 :          0 :     SetControlBackground(GetSettings().GetStyleSettings().GetDialogColor());
     166                 :          0 :     FreeResource();
     167                 :            : 
     168                 :          0 :     maLbType.SelectEntryPos(1);
     169                 :          0 :     maLbCondType.SelectEntryPos(0);
     170                 :          0 :     maEdVal2.Hide();
     171                 :            : 
     172                 :          0 :     maLbStyle.SetSeparatorPos(0);
     173                 :            : 
     174                 :            :     //disable entries for color formats
     175                 :          0 :     maLbColorFormat.SelectEntryPos(0);
     176                 :          0 :     maLbEntryTypeMin.SelectEntryPos(0);
     177                 :          0 :     maLbEntryTypeMiddle.SelectEntryPos(2);
     178                 :          0 :     maLbEntryTypeMax.SelectEntryPos(1);
     179                 :          0 :     maLbDataBarMinType.SelectEntryPos(0);
     180                 :          0 :     maLbDataBarMaxType.SelectEntryPos(1);
     181                 :          0 :     maEdMiddle.SetText(rtl::OUString::valueOf(static_cast<sal_Int32>(50)));
     182                 :          0 :     maEdDataBarMin.Disable();
     183                 :          0 :     maEdDataBarMax.Disable();
     184                 :            : 
     185                 :          0 :     Init();
     186                 :          0 :     maLbStyle.SelectEntryPos(1);
     187                 :          0 :     maClickHdl = LINK( pParent, ScCondFormatList, EntrySelectHdl );
     188                 :          0 :     SwitchToType(COLLAPSED);
     189                 :          0 :     SetHeight();
     190                 :          0 :     SetCondType();
     191                 :            : 
     192                 :          0 :     EntryTypeHdl(&maLbEntryTypeMin);
     193                 :          0 :     EntryTypeHdl(&maLbEntryTypeMiddle);
     194                 :          0 :     EntryTypeHdl(&maLbEntryTypeMax);
     195                 :          0 : }
     196                 :            : 
     197                 :          0 : ScCondFrmtEntry::ScCondFrmtEntry(Window* pParent, ScDocument* pDoc, const ScFormatEntry* pFormatEntry, const ScAddress& rPos):
     198                 :            :     Control(pParent, ScResId( RID_COND_ENTRY ) ),
     199                 :            :     mbActive(false),
     200                 :            :     meType(CONDITION),
     201                 :            :     maLbType( this, ScResId( LB_TYPE ) ),
     202                 :            :     maFtCondNr( this, ScResId( FT_COND_NR ) ),
     203                 :            :     maFtCondition( this, ScResId( FT_CONDITION ) ),
     204                 :            :     maLbCondType( this, ScResId( LB_CELLIS_TYPE ) ),
     205                 :            :     maEdVal1( this, ScResId( ED_VAL1 ) ),
     206                 :            :     maEdVal2( this, ScResId( ED_VAL2 ) ),
     207                 :            :     maFtStyle( this, ScResId( FT_STYLE ) ),
     208                 :            :     maLbStyle( this, ScResId( LB_STYLE ) ),
     209                 :            :     maWdPreview( this, ScResId( WD_PREVIEW ) ),
     210                 :            :     maLbColorFormat( this, ScResId( LB_COLOR_FORMAT ) ),
     211                 :            :     maLbColScale2( this, ScResId( LB_COL_SCALE2 ) ),
     212                 :            :     maLbColScale3( this, ScResId( LB_COL_SCALE3 ) ),
     213                 :            :     maLbEntryTypeMin( this, ScResId( LB_TYPE_COL_SCALE ) ),
     214                 :            :     maLbEntryTypeMiddle( this, ScResId( LB_TYPE_COL_SCALE ) ),
     215                 :            :     maLbEntryTypeMax( this, ScResId( LB_TYPE_COL_SCALE ) ),
     216                 :            :     maEdMin( this, ScResId( ED_COL_SCALE ) ),
     217                 :            :     maEdMiddle( this, ScResId( ED_COL_SCALE ) ),
     218                 :            :     maEdMax( this, ScResId( ED_COL_SCALE ) ),
     219                 :            :     maLbColMin( this, ScResId( LB_COL) ),
     220                 :            :     maLbColMiddle( this, ScResId( LB_COL) ),
     221                 :            :     maLbColMax( this, ScResId( LB_COL) ),
     222                 :            :     maLbDataBarMinType( this, ScResId( LB_TYPE_COL_SCALE ) ),
     223                 :            :     maLbDataBarMaxType( this, ScResId( LB_TYPE_COL_SCALE ) ),
     224                 :            :     maEdDataBarMin( this, ScResId( ED_COL_SCALE ) ),
     225                 :            :     maEdDataBarMax( this, ScResId( ED_COL_SCALE ) ),
     226                 :            :     maBtOptions( this, ScResId( BTN_OPTIONS ) ),
     227                 :            :     mpDoc(pDoc),
     228                 :          0 :     maPos(rPos)
     229                 :            : {
     230                 :          0 :     SetControlBackground(GetSettings().GetStyleSettings().GetDialogColor());
     231                 :          0 :     FreeResource();
     232                 :          0 :     Init();
     233                 :            : 
     234                 :          0 :     if(pFormatEntry && pFormatEntry->GetType() == condformat::CONDITION)
     235                 :            :     {
     236                 :          0 :         const ScCondFormatEntry* pEntry = static_cast<const ScCondFormatEntry*>(pFormatEntry);
     237                 :          0 :         rtl::OUString aStyleName = pEntry->GetStyle();
     238                 :          0 :         maLbStyle.SelectEntry(aStyleName);
     239                 :          0 :         StyleSelectHdl(NULL);
     240                 :          0 :         ScConditionMode eMode = pEntry->GetOperation();
     241                 :          0 :         maLbType.SelectEntryPos(1);
     242                 :          0 :         maEdVal1.SetText(pEntry->GetExpression(maPos, 0));
     243                 :          0 :         SetCondType();
     244                 :          0 :         switch(eMode)
     245                 :            :         {
     246                 :            :             case SC_COND_EQUAL:
     247                 :          0 :                 maLbCondType.SelectEntryPos(0);
     248                 :          0 :                 break;
     249                 :            :             case SC_COND_LESS:
     250                 :          0 :                 maLbCondType.SelectEntryPos(1);
     251                 :          0 :                 break;
     252                 :            :             case SC_COND_GREATER:
     253                 :          0 :                 maLbCondType.SelectEntryPos(2);
     254                 :          0 :                 break;
     255                 :            :             case SC_COND_EQLESS:
     256                 :          0 :                 maLbCondType.SelectEntryPos(3);
     257                 :          0 :                 break;
     258                 :            :             case SC_COND_EQGREATER:
     259                 :          0 :                 maLbCondType.SelectEntryPos(4);
     260                 :          0 :                 break;
     261                 :            :             case SC_COND_NOTEQUAL:
     262                 :          0 :                 maLbCondType.SelectEntryPos(5);
     263                 :          0 :                 break;
     264                 :            :             case SC_COND_BETWEEN:
     265                 :          0 :                 maEdVal2.SetText(pEntry->GetExpression(maPos, 1));
     266                 :          0 :                 maLbCondType.SelectEntryPos(6);
     267                 :          0 :                 break;
     268                 :            :             case SC_COND_NOTBETWEEN:
     269                 :          0 :                 maEdVal2.SetText(pEntry->GetExpression(maPos, 1));
     270                 :          0 :                 maLbCondType.SelectEntryPos(7);
     271                 :          0 :                 break;
     272                 :            :             case SC_COND_DUPLICATE:
     273                 :          0 :                 maLbCondType.SelectEntryPos(8);
     274                 :          0 :                 break;
     275                 :            :             case SC_COND_NOTDUPLICATE:
     276                 :          0 :                 maLbCondType.SelectEntryPos(9);
     277                 :          0 :                 break;
     278                 :            :             case SC_COND_DIRECT:
     279                 :          0 :                 maLbType.SelectEntryPos(2);
     280                 :          0 :                 SwitchToType(FORMULA);
     281                 :          0 :                 break;
     282                 :            :             case SC_COND_NONE:
     283                 :          0 :                 break;
     284                 :          0 :         }
     285                 :            :     }
     286                 :          0 :     else if( pFormatEntry && pFormatEntry->GetType() == condformat::COLORSCALE )
     287                 :            :     {
     288                 :          0 :         const ScColorScaleFormat* pEntry = static_cast<const ScColorScaleFormat*>(pFormatEntry);
     289                 :          0 :         maLbType.SelectEntryPos(0);
     290                 :          0 :         if(pEntry->size() == 2)
     291                 :          0 :             maLbColorFormat.SelectEntryPos(0);
     292                 :            :         else
     293                 :          0 :             maLbColorFormat.SelectEntryPos(1);
     294                 :          0 :         SetColorScaleType();
     295                 :          0 :         ScColorScaleFormat::const_iterator itr = pEntry->begin();
     296                 :          0 :         SetColorScaleEntryTypes(*itr, maLbEntryTypeMin, maEdMin, maLbColMin);
     297                 :          0 :         if(pEntry->size() == 3)
     298                 :            :         {
     299                 :          0 :             ++itr;
     300                 :          0 :             SetColorScaleEntryTypes(*itr, maLbEntryTypeMiddle, maEdMiddle, maLbColMiddle);
     301                 :            :         }
     302                 :          0 :         ++itr;
     303                 :          0 :         SetColorScaleEntryTypes(*itr, maLbEntryTypeMax, maEdMax, maLbColMax);
     304                 :            :     }
     305                 :          0 :     else if( pFormatEntry && pFormatEntry->GetType() == condformat::DATABAR )
     306                 :            :     {
     307                 :          0 :         const ScDataBarFormat* pEntry = static_cast<const ScDataBarFormat*>(pFormatEntry);
     308                 :          0 :         mpDataBarData.reset(new ScDataBarFormatData(*pEntry->GetDataBarData()));
     309                 :          0 :         maLbType.SelectEntryPos(0);
     310                 :          0 :         maLbColorFormat.SelectEntryPos(2);
     311                 :          0 :         SetDataBarEntryTypes(*mpDataBarData->mpLowerLimit, maLbDataBarMinType, maEdDataBarMin);
     312                 :          0 :         SetDataBarEntryTypes(*mpDataBarData->mpUpperLimit, maLbDataBarMaxType, maEdDataBarMax);
     313                 :          0 :         DataBarTypeSelectHdl(NULL);
     314                 :          0 :         SetDataBarType();
     315                 :            :     }
     316                 :            : 
     317                 :          0 :     maClickHdl = LINK( pParent, ScCondFormatList, EntrySelectHdl );
     318                 :          0 :     SwitchToType(COLLAPSED);
     319                 :          0 :     SetHeight();
     320                 :            : 
     321                 :          0 :     EntryTypeHdl(&maLbEntryTypeMin);
     322                 :          0 :     EntryTypeHdl(&maLbEntryTypeMiddle);
     323                 :          0 :     EntryTypeHdl(&maLbEntryTypeMax);
     324                 :          0 : }
     325                 :            : 
     326                 :          0 : ScCondFrmtEntry::~ScCondFrmtEntry()
     327                 :            : {
     328                 :          0 : }
     329                 :            : 
     330                 :          0 : void ScCondFrmtEntry::Init()
     331                 :            : {
     332                 :          0 :     maLbType.SetSelectHdl( LINK( this, ScCondFrmtEntry, TypeListHdl ) );
     333                 :          0 :     maLbColorFormat.SetSelectHdl( LINK( this, ScCondFrmtEntry, ColFormatTypeHdl ) );
     334                 :          0 :     maLbEntryTypeMin.SetSelectHdl( LINK( this, ScCondFrmtEntry, EntryTypeHdl ) );
     335                 :          0 :     maLbEntryTypeMax.SetSelectHdl( LINK( this, ScCondFrmtEntry, EntryTypeHdl ) );
     336                 :          0 :     maLbEntryTypeMiddle.SetSelectHdl( LINK( this, ScCondFrmtEntry, EntryTypeHdl ) );
     337                 :          0 :     maEdVal1.SetStyle( maEdVal1.GetStyle() | WB_FORCECTRLBACKGROUND );
     338                 :          0 :     maEdVal2.SetStyle( maEdVal2.GetStyle() | WB_FORCECTRLBACKGROUND );
     339                 :            : 
     340                 :          0 :     maEdVal1.SetModifyHdl( LINK( this, ScCondFrmtEntry, EdModifyHdl ) );
     341                 :          0 :     maEdVal2.SetModifyHdl( LINK( this, ScCondFrmtEntry, EdModifyHdl ) );
     342                 :            : 
     343                 :          0 :     SfxStyleSheetIterator aStyleIter( mpDoc->GetStyleSheetPool(), SFX_STYLE_FAMILY_PARA );
     344                 :          0 :     for ( SfxStyleSheetBase* pStyle = aStyleIter.First(); pStyle; pStyle = aStyleIter.Next() )
     345                 :            :     {
     346                 :          0 :         rtl::OUString aName = pStyle->GetName();
     347                 :          0 :         maLbStyle.InsertEntry( aName );
     348                 :          0 :     }
     349                 :          0 :     maLbStyle.SetSelectHdl( LINK( this, ScCondFrmtEntry, StyleSelectHdl ) );
     350                 :            : 
     351                 :          0 :     Point aPointLb = maLbEntryTypeMiddle.GetPosPixel();
     352                 :          0 :     Point aPointEd = maEdMiddle.GetPosPixel();
     353                 :          0 :     Point aPointCol = maLbColMiddle.GetPosPixel();
     354                 :          0 :     Point aPointEdDataBar = maEdDataBarMin.GetPosPixel();
     355                 :          0 :     Point aPointLbDataBar = maLbDataBarMaxType.GetPosPixel();
     356                 :          0 :     const long nMovePos = maLbEntryTypeMiddle.GetSizePixel().Width() * 1.2;
     357                 :          0 :     aPointLb.X() += nMovePos;
     358                 :          0 :     aPointEd.X() += nMovePos;
     359                 :          0 :     aPointCol.X() += nMovePos;
     360                 :          0 :     aPointEdDataBar.X() += 2*nMovePos;
     361                 :          0 :     aPointLbDataBar.X() += 2*nMovePos;
     362                 :          0 :     maLbEntryTypeMiddle.SetPosPixel(aPointLb);
     363                 :          0 :     maEdMiddle.SetPosPixel(aPointEd);
     364                 :          0 :     maLbColMiddle.SetPosPixel(aPointCol);
     365                 :          0 :     maEdDataBarMax.SetPosPixel(aPointEdDataBar);
     366                 :          0 :     maLbDataBarMaxType.SetPosPixel(aPointLbDataBar);
     367                 :          0 :     aPointLb.X() += nMovePos;
     368                 :          0 :     aPointEd.X() += nMovePos;
     369                 :          0 :     aPointCol.X() += nMovePos;
     370                 :          0 :     maLbEntryTypeMax.SetPosPixel(aPointLb);
     371                 :          0 :     maEdMax.SetPosPixel(aPointEd);
     372                 :          0 :     maLbColMax.SetPosPixel(aPointCol);
     373                 :            : 
     374                 :          0 :     SfxObjectShell*     pDocSh      = SfxObjectShell::Current();
     375                 :          0 :     const SfxPoolItem*  pItem       = NULL;
     376                 :          0 :     XColorListRef       pColorTable;
     377                 :            : 
     378                 :            :     DBG_ASSERT( pDocSh, "DocShell not found!" );
     379                 :            : 
     380                 :          0 :     if ( pDocSh )
     381                 :            :     {
     382                 :          0 :         pItem = pDocSh->GetItem( SID_COLOR_TABLE );
     383                 :          0 :         if ( pItem != NULL )
     384                 :          0 :             pColorTable = ( (SvxColorListItem*)pItem )->GetColorList();
     385                 :            :     }
     386                 :          0 :     if ( pColorTable.is() )
     387                 :            :     {
     388                 :            :         // filling the line color box
     389                 :          0 :         maLbColMin.SetUpdateMode( false );
     390                 :          0 :         maLbColMiddle.SetUpdateMode( false );
     391                 :          0 :         maLbColMax.SetUpdateMode( false );
     392                 :            : 
     393                 :          0 :         for ( long i = 0; i < pColorTable->Count(); ++i )
     394                 :            :         {
     395                 :          0 :             XColorEntry* pEntry = pColorTable->GetColor(i);
     396                 :          0 :             maLbColMin.InsertEntry( pEntry->GetColor(), pEntry->GetName() );
     397                 :          0 :             maLbColMiddle.InsertEntry( pEntry->GetColor(), pEntry->GetName() );
     398                 :          0 :             maLbColMax.InsertEntry( pEntry->GetColor(), pEntry->GetName() );
     399                 :            : 
     400                 :          0 :             if(pEntry->GetColor() == Color(COL_LIGHTRED))
     401                 :          0 :                 maLbColMin.SelectEntryPos(i);
     402                 :          0 :             if(pEntry->GetColor() == Color(COL_GREEN))
     403                 :          0 :                 maLbColMiddle.SelectEntryPos(i);
     404                 :          0 :             if(pEntry->GetColor() == Color(COL_LIGHTBLUE))
     405                 :          0 :                 maLbColMax.SelectEntryPos(i);
     406                 :            :         }
     407                 :          0 :         maLbColMin.SetUpdateMode( sal_True );
     408                 :          0 :         maLbColMiddle.SetUpdateMode( sal_True );
     409                 :          0 :         maLbColMax.SetUpdateMode( sal_True );
     410                 :            :     }
     411                 :            : 
     412                 :          0 :     maBtOptions.SetClickHdl( LINK( this, ScCondFrmtEntry, OptionBtnHdl ) );
     413                 :          0 :     maLbDataBarMinType.SetSelectHdl( LINK( this, ScCondFrmtEntry, DataBarTypeSelectHdl ) );
     414                 :          0 :     maLbDataBarMaxType.SetSelectHdl( LINK( this, ScCondFrmtEntry, DataBarTypeSelectHdl ) );
     415                 :          0 :     maLbCondType.SetSelectHdl( LINK( this, ScCondFrmtEntry, ConditionTypeSelectHdl ) );
     416                 :            : 
     417                 :          0 :     mpDataBarData.reset(new ScDataBarFormatData());
     418                 :          0 :     mpDataBarData->mpUpperLimit.reset(new ScColorScaleEntry());
     419                 :          0 :     mpDataBarData->mpLowerLimit.reset(new ScColorScaleEntry());
     420                 :          0 :     mpDataBarData->mpLowerLimit->SetType(COLORSCALE_MIN);
     421                 :          0 :     mpDataBarData->mpUpperLimit->SetType(COLORSCALE_MAX);
     422                 :          0 :     mpDataBarData->maPositiveColor = COL_LIGHTBLUE;
     423                 :          0 : }
     424                 :            : 
     425                 :          0 : long ScCondFrmtEntry::Notify( NotifyEvent& rNEvt )
     426                 :            : {
     427                 :          0 :     if( rNEvt.GetType() == EVENT_MOUSEBUTTONDOWN )
     428                 :            :     {
     429                 :          0 :         ImplCallEventListenersAndHandler( VCLEVENT_WINDOW_MOUSEBUTTONDOWN, maClickHdl, this );
     430                 :            :     }
     431                 :          0 :     return Control::Notify(rNEvt);
     432                 :            : }
     433                 :            : 
     434                 :          0 : void ScCondFrmtEntry::SwitchToType( ScCondFormatEntryType eType )
     435                 :            : {
     436                 :          0 :     switch(eType)
     437                 :            :     {
     438                 :            :         case COLLAPSED:
     439                 :            :             {
     440                 :          0 :                 maLbType.Hide();
     441                 :          0 :                 rtl::OUString maCondText = ScCondFormatHelper::GetExpression(meType, maLbCondType.GetSelectEntryPos());
     442                 :          0 :                 maFtCondition.SetText(maCondText);
     443                 :          0 :                 maFtCondition.Show();
     444                 :          0 :                 maLbType.Hide();
     445                 :          0 :                 HideCondElements();
     446                 :          0 :                 HideColorScaleElements();
     447                 :          0 :                 HideDataBarElements();
     448                 :            :             }
     449                 :          0 :             break;
     450                 :            :         default:
     451                 :          0 :             meType = eType;
     452                 :          0 :             maLbType.Show();
     453                 :          0 :             maFtCondition.SetText(rtl::OUString(""));
     454                 :          0 :             maFtCondition.Hide();
     455                 :          0 :             maLbType.Show();
     456                 :          0 :             break;
     457                 :            :     }
     458                 :          0 : }
     459                 :            : 
     460                 :          0 : void ScCondFrmtEntry::SetIndex(sal_Int32 nIndex)
     461                 :            : {
     462                 :          0 :     mnIndex = nIndex;
     463                 :          0 :     rtl::OUStringBuffer aBuffer(maStrCondition);
     464                 :          0 :     aBuffer.append(rtl::OUString::valueOf(nIndex));
     465                 :          0 :     maFtCondNr.SetText(aBuffer.makeStringAndClear());
     466                 :          0 : }
     467                 :            : 
     468                 :          0 : void ScCondFrmtEntry::HideCondElements()
     469                 :            : {
     470                 :          0 :     maEdVal1.Hide();
     471                 :          0 :     maEdVal2.Hide();
     472                 :          0 :     maLbStyle.Hide();
     473                 :          0 :     maFtStyle.Hide();
     474                 :          0 :     maLbCondType.Hide();
     475                 :          0 :     maWdPreview.Hide();
     476                 :          0 : }
     477                 :            : 
     478                 :          0 : void ScCondFrmtEntry::SetCondType()
     479                 :            : {
     480                 :          0 :     maEdVal1.SetSizePixel(maEdVal2.GetSizePixel());
     481                 :          0 :     Point aPoint(maLbCondType.GetPosPixel().X() + maLbCondType.GetSizePixel().Width() + LogicToPixel(Size(5,1), MapMode(MAP_APPFONT)).getWidth(),
     482                 :          0 :             maEdVal1.GetPosPixel().Y());
     483                 :          0 :     maEdVal1.SetPosPixel(aPoint);
     484                 :          0 :     maEdVal1.Show();
     485                 :          0 :     maEdVal2.Show();
     486                 :          0 :     maLbStyle.Show();
     487                 :          0 :     maLbCondType.Show();
     488                 :          0 :     maFtStyle.Show();
     489                 :          0 :     maWdPreview.Show();
     490                 :          0 :     HideColorScaleElements();
     491                 :          0 :     HideDataBarElements();
     492                 :          0 :     SwitchToType(CONDITION);
     493                 :          0 :     ConditionTypeSelectHdl(NULL);
     494                 :          0 : }
     495                 :            : 
     496                 :          0 : void ScCondFrmtEntry::HideColorScaleElements()
     497                 :            : {
     498                 :          0 :     maLbColorFormat.Hide();
     499                 :          0 :     maLbColScale2.Hide();
     500                 :          0 :     maLbColScale3.Hide();
     501                 :          0 :     maLbEntryTypeMin.Hide();
     502                 :          0 :     maLbEntryTypeMiddle.Hide();
     503                 :          0 :     maLbEntryTypeMax.Hide();
     504                 :          0 :     maEdMin.Hide();
     505                 :          0 :     maEdMiddle.Hide();
     506                 :          0 :     maEdMax.Hide();
     507                 :          0 :     maLbColMin.Hide();
     508                 :          0 :     maLbColMiddle.Hide();
     509                 :          0 :     maLbColMax.Hide();
     510                 :          0 : }
     511                 :            : 
     512                 :          0 : void ScCondFrmtEntry::SetHeight()
     513                 :            : {
     514                 :          0 :     if(mbActive)
     515                 :            :     {
     516                 :          0 :         Size aSize = GetSizePixel();
     517                 :          0 :         switch (meType)
     518                 :            :         {
     519                 :            :             case CONDITION:
     520                 :            :             case FORMULA:
     521                 :          0 :                 aSize.Height() = 120;
     522                 :          0 :                 break;
     523                 :            :             case COLORSCALE:
     524                 :          0 :                 aSize.Height() = 200;
     525                 :          0 :                 break;
     526                 :            :             case DATABAR:
     527                 :          0 :                 aSize.Height() = 200;
     528                 :          0 :                 break;
     529                 :            :             default:
     530                 :          0 :                 break;
     531                 :            :         }
     532                 :          0 :         SetSizePixel(aSize);
     533                 :            :     }
     534                 :            :     else
     535                 :            :     {
     536                 :          0 :         Size aSize = GetSizePixel();
     537                 :          0 :         aSize.Height() = 40;
     538                 :          0 :         SetSizePixel(aSize);
     539                 :            :     }
     540                 :          0 : }
     541                 :            : 
     542                 :          0 : void ScCondFrmtEntry::SetColorScaleType()
     543                 :            : {
     544                 :          0 :     HideCondElements();
     545                 :          0 :     HideDataBarElements();
     546                 :          0 :     maLbColorFormat.Show();
     547                 :          0 :     if(maLbColorFormat.GetSelectEntryPos() == 0)
     548                 :            :     {
     549                 :          0 :         maEdMiddle.Hide();
     550                 :          0 :         maLbEntryTypeMiddle.Hide();
     551                 :            :         // TODO: enale for 3.7 again with good presets
     552                 :            :         //maLbColScale2.Show();
     553                 :          0 :         maLbColScale3.Hide();
     554                 :          0 :         maLbColMiddle.Hide();
     555                 :            :     }
     556                 :            :     else
     557                 :            :     {
     558                 :          0 :         maEdMiddle.Show();
     559                 :          0 :         maLbEntryTypeMiddle.Show();
     560                 :          0 :         maLbColScale2.Hide();
     561                 :            :         // TODO: enale for 3.7 again with good presets
     562                 :            :         // maLbColScale3.Show();
     563                 :          0 :         maLbColMiddle.Show();
     564                 :            :     }
     565                 :          0 :     maLbEntryTypeMin.Show();
     566                 :          0 :     maLbEntryTypeMax.Show();
     567                 :          0 :     maEdMin.Show();
     568                 :          0 :     maEdMax.Show();
     569                 :          0 :     maLbColMin.Show();
     570                 :          0 :     maLbColMax.Show();
     571                 :          0 :     SwitchToType(COLORSCALE);
     572                 :          0 : }
     573                 :            : 
     574                 :          0 : void ScCondFrmtEntry::HideDataBarElements()
     575                 :            : {
     576                 :          0 :     maLbColorFormat.Hide();
     577                 :          0 :     maLbDataBarMinType.Hide();
     578                 :          0 :     maLbDataBarMaxType.Hide();
     579                 :          0 :     maEdDataBarMin.Hide();
     580                 :          0 :     maEdDataBarMax.Hide();
     581                 :          0 :     maBtOptions.Hide();
     582                 :          0 : }
     583                 :            : 
     584                 :          0 : void ScCondFrmtEntry::SetDataBarType()
     585                 :            : {
     586                 :          0 :     SwitchToType(DATABAR);
     587                 :          0 :     HideCondElements();
     588                 :          0 :     HideColorScaleElements();
     589                 :          0 :     maLbColorFormat.Show();
     590                 :          0 :     maLbDataBarMinType.Show();
     591                 :          0 :     maLbDataBarMaxType.Show();
     592                 :          0 :     maEdDataBarMin.Show();
     593                 :          0 :     maEdDataBarMax.Show();
     594                 :          0 :     maBtOptions.Show();
     595                 :          0 : }
     596                 :            : 
     597                 :          0 : void ScCondFrmtEntry::SetFormulaType()
     598                 :            : {
     599                 :          0 :     SwitchToType(FORMULA);
     600                 :          0 :     HideColorScaleElements();
     601                 :          0 :     HideDataBarElements();
     602                 :          0 :     maEdVal1.SetPosPixel(maLbCondType.GetPosPixel());
     603                 :          0 :     Size aSize(maEdVal2.GetPosPixel().X() + maEdVal2.GetSizePixel().Width() - maLbCondType.GetPosPixel().X(), maEdVal1.GetSizePixel().Height());
     604                 :          0 :     maEdVal1.SetPosPixel(maLbCondType.GetPosPixel());
     605                 :          0 :     maEdVal1.SetSizePixel(aSize);
     606                 :          0 :     maEdVal1.Show();
     607                 :          0 :     maEdVal2.Hide();
     608                 :          0 :     maLbCondType.Hide();
     609                 :          0 :     maLbStyle.Show();
     610                 :          0 :     maFtCondition.Show();
     611                 :          0 :     maWdPreview.Show();
     612                 :          0 :     maFtStyle.Show();
     613                 :          0 : }
     614                 :            : 
     615                 :          0 : void ScCondFrmtEntry::Select()
     616                 :            : {
     617                 :          0 :     SetControlForeground(Color(COL_RED));
     618                 :          0 :     switch(meType)
     619                 :            :     {
     620                 :            :         case CONDITION:
     621                 :          0 :             SetCondType();
     622                 :          0 :             break;
     623                 :            :         case COLORSCALE:
     624                 :          0 :             SetColorScaleType();
     625                 :          0 :             break;
     626                 :            :         case DATABAR:
     627                 :          0 :             SetDataBarType();
     628                 :          0 :             break;
     629                 :            :         case FORMULA:
     630                 :          0 :             SetFormulaType();
     631                 :          0 :             break;
     632                 :            :         default:
     633                 :            :             //should not happen
     634                 :          0 :             break;
     635                 :            :     }
     636                 :          0 :     SwitchToType(meType);
     637                 :          0 :     mbActive = true;
     638                 :          0 :     SetHeight();
     639                 :          0 : }
     640                 :            : 
     641                 :          0 : void ScCondFrmtEntry::Deselect()
     642                 :            : {
     643                 :          0 :     SetControlBackground(GetSettings().GetStyleSettings().GetDialogColor());
     644                 :          0 :     SwitchToType(COLLAPSED);
     645                 :          0 :     mbActive = false;
     646                 :          0 :     SetHeight();
     647                 :          0 : }
     648                 :            : 
     649                 :          0 : bool ScCondFrmtEntry::IsSelected() const
     650                 :            : {
     651                 :          0 :     return mbActive;
     652                 :            : }
     653                 :            : 
     654                 :          0 : ScFormatEntry* ScCondFrmtEntry::createConditionEntry() const
     655                 :            : {
     656                 :            :     ScConditionMode eMode;
     657                 :          0 :     rtl::OUString aExpr2;
     658                 :          0 :     switch(maLbCondType.GetSelectEntryPos())
     659                 :            :     {
     660                 :            :         case 0:
     661                 :          0 :             eMode = SC_COND_EQUAL;
     662                 :          0 :             break;
     663                 :            :         case 1:
     664                 :          0 :             eMode = SC_COND_LESS;
     665                 :          0 :             break;
     666                 :            :         case 2:
     667                 :          0 :             eMode = SC_COND_GREATER;
     668                 :          0 :             break;
     669                 :            :         case 3:
     670                 :          0 :             eMode = SC_COND_EQLESS;
     671                 :          0 :             break;
     672                 :            :         case 4:
     673                 :          0 :             eMode = SC_COND_EQGREATER;
     674                 :          0 :             break;
     675                 :            :         case 5:
     676                 :          0 :             eMode = SC_COND_NOTEQUAL;
     677                 :          0 :             break;
     678                 :            :         case 6:
     679                 :          0 :             aExpr2 = maEdVal2.GetText();
     680                 :          0 :             eMode = SC_COND_BETWEEN;
     681                 :          0 :             if(aExpr2.isEmpty())
     682                 :          0 :                 return NULL;
     683                 :          0 :             break;
     684                 :            :         case 7:
     685                 :          0 :             eMode = SC_COND_NOTBETWEEN;
     686                 :          0 :             aExpr2 = maEdVal2.GetText();
     687                 :          0 :             if(aExpr2.isEmpty())
     688                 :          0 :                 return NULL;
     689                 :          0 :             break;
     690                 :            :         case 8:
     691                 :          0 :             eMode = SC_COND_DUPLICATE;
     692                 :          0 :             break;
     693                 :            :         case 9:
     694                 :          0 :             eMode = SC_COND_NOTDUPLICATE;
     695                 :          0 :             break;
     696                 :            :         default:
     697                 :            :             assert(false); // this cannot happen
     698                 :          0 :             return NULL;
     699                 :            :     }
     700                 :            : 
     701                 :          0 :     rtl::OUString aExpr1 = maEdVal1.GetText();
     702                 :            : 
     703                 :          0 :     ScFormatEntry* pEntry = new ScCondFormatEntry(eMode, aExpr1, aExpr2, mpDoc, maPos, maLbStyle.GetSelectEntry());
     704                 :            : 
     705                 :          0 :     return pEntry;
     706                 :            : }
     707                 :            : 
     708                 :            : namespace {
     709                 :            : 
     710                 :          0 : void SetColorScaleEntry( ScColorScaleEntry* pEntry, const ListBox& rType, const Edit& rValue, ScDocument* pDoc, const ScAddress& rPos )
     711                 :            : {
     712                 :          0 :     sal_uInt32 nIndex = 0;
     713                 :          0 :     double nVal = 0;
     714                 :          0 :     SvNumberFormatter* pNumberFormatter = pDoc->GetFormatTable();
     715                 :          0 :     pNumberFormatter->IsNumberFormat(rValue.GetText(), nIndex, nVal);
     716                 :          0 :     switch(rType.GetSelectEntryPos())
     717                 :            :     {
     718                 :            :         case 0:
     719                 :          0 :             pEntry->SetType(COLORSCALE_MIN);
     720                 :          0 :             break;
     721                 :            :         case 1:
     722                 :          0 :             pEntry->SetType(COLORSCALE_MAX);
     723                 :          0 :             break;
     724                 :            :         case 2:
     725                 :          0 :             pEntry->SetType(COLORSCALE_PERCENTILE);
     726                 :          0 :             pEntry->SetValue(nVal);
     727                 :          0 :             break;
     728                 :            :         case 3:
     729                 :          0 :             pEntry->SetType(COLORSCALE_VALUE);
     730                 :          0 :             pEntry->SetValue(nVal);
     731                 :          0 :             break;
     732                 :            :         case 4:
     733                 :          0 :             pEntry->SetType(COLORSCALE_PERCENT);
     734                 :          0 :             pEntry->SetValue(nVal);
     735                 :          0 :             break;
     736                 :            :         case 5:
     737                 :          0 :             pEntry->SetType(COLORSCALE_FORMULA);
     738                 :          0 :             pEntry->SetFormula(rValue.GetText(), pDoc, rPos);
     739                 :          0 :             break;
     740                 :            :         case 6:
     741                 :          0 :             pEntry->SetType(COLORSCALE_AUTOMIN);
     742                 :          0 :             break;
     743                 :            :         case 7:
     744                 :          0 :             pEntry->SetType(COLORSCALE_AUTOMAX);
     745                 :          0 :             break;
     746                 :            :         default:
     747                 :          0 :             break;
     748                 :            :     }
     749                 :          0 : }
     750                 :            : 
     751                 :          0 : ScColorScaleEntry* createColorScaleEntry( const ListBox& rType, const ColorListBox& rColor, const Edit& rValue, ScDocument* pDoc, const ScAddress& rPos )
     752                 :            : {
     753                 :          0 :     ScColorScaleEntry* pEntry = new ScColorScaleEntry();
     754                 :            : 
     755                 :          0 :     SetColorScaleEntry( pEntry, rType, rValue, pDoc, rPos );
     756                 :          0 :     Color aColor = rColor.GetSelectEntryColor();
     757                 :          0 :     pEntry->SetColor(aColor);
     758                 :          0 :     return pEntry;
     759                 :            : }
     760                 :            : 
     761                 :            : }
     762                 :            : 
     763                 :          0 : ScFormatEntry* ScCondFrmtEntry::createColorscaleEntry() const
     764                 :            : {
     765                 :          0 :     ScColorScaleFormat* pColorScale = new ScColorScaleFormat(mpDoc);
     766                 :          0 :     pColorScale->AddEntry(createColorScaleEntry(maLbEntryTypeMin, maLbColMin, maEdMin, mpDoc, maPos));
     767                 :          0 :     if(maLbColorFormat.GetSelectEntryPos() == 1)
     768                 :          0 :         pColorScale->AddEntry(createColorScaleEntry(maLbEntryTypeMiddle, maLbColMiddle, maEdMiddle, mpDoc, maPos));
     769                 :          0 :     pColorScale->AddEntry(createColorScaleEntry(maLbEntryTypeMax, maLbColMax, maEdMax, mpDoc, maPos));
     770                 :          0 :     return pColorScale;
     771                 :            : }
     772                 :            : 
     773                 :          0 : ScFormatEntry* ScCondFrmtEntry::createDatabarEntry() const
     774                 :            : {
     775                 :          0 :     SetColorScaleEntry(mpDataBarData->mpLowerLimit.get(), maLbDataBarMinType, maEdDataBarMin, mpDoc, maPos);
     776                 :          0 :     SetColorScaleEntry(mpDataBarData->mpUpperLimit.get(), maLbDataBarMaxType, maEdDataBarMax, mpDoc, maPos);
     777                 :          0 :     ScDataBarFormat* pDataBar = new ScDataBarFormat(mpDoc);
     778                 :          0 :     pDataBar->SetDataBarData(new ScDataBarFormatData(*mpDataBarData.get()));
     779                 :          0 :     return pDataBar;
     780                 :            : }
     781                 :            : 
     782                 :          0 : ScFormatEntry* ScCondFrmtEntry::createFormulaEntry() const
     783                 :            : {
     784                 :          0 :     ScConditionMode eMode = SC_COND_DIRECT;
     785                 :          0 :     rtl::OUString aFormula = maEdVal1.GetText();
     786                 :          0 :     if(aFormula.isEmpty())
     787                 :          0 :         return NULL;
     788                 :            : 
     789                 :          0 :     rtl::OUString aExpr2;
     790                 :          0 :     ScFormatEntry* pEntry = new ScCondFormatEntry(eMode, aFormula, aExpr2, mpDoc, maPos, maLbStyle.GetSelectEntry());
     791                 :          0 :     return pEntry;
     792                 :            : }
     793                 :            : 
     794                 :          0 : ScFormatEntry* ScCondFrmtEntry::GetEntry() const
     795                 :            : {
     796                 :          0 :     switch(meType)
     797                 :            :     {
     798                 :            :         case CONDITION:
     799                 :          0 :             return createConditionEntry();
     800                 :            :             break;
     801                 :            :         case COLORSCALE:
     802                 :          0 :             return createColorscaleEntry();
     803                 :            :             break;
     804                 :            :         case DATABAR:
     805                 :          0 :             return createDatabarEntry();
     806                 :            :             break;
     807                 :            :         case FORMULA:
     808                 :          0 :             return createFormulaEntry();
     809                 :            :             break;
     810                 :            :         default:
     811                 :          0 :             break;
     812                 :            :     }
     813                 :          0 :     return NULL;
     814                 :            : }
     815                 :            : 
     816                 :          0 : IMPL_LINK_NOARG(ScCondFrmtEntry, TypeListHdl)
     817                 :            : {
     818                 :          0 :     sal_Int32 nPos = maLbType.GetSelectEntryPos();
     819                 :          0 :     switch(nPos)
     820                 :            :     {
     821                 :            :         case 1:
     822                 :          0 :             SetCondType();
     823                 :          0 :             break;
     824                 :            :         case 0:
     825                 :          0 :             if(maLbColorFormat.GetSelectEntryPos() < 2)
     826                 :          0 :                 SetColorScaleType();
     827                 :            :             else
     828                 :          0 :                 SetDataBarType();
     829                 :          0 :             break;
     830                 :            :         case 2:
     831                 :          0 :             SetFormulaType();
     832                 :          0 :             break;
     833                 :            :         default:
     834                 :          0 :             break;
     835                 :            :     }
     836                 :          0 :     SetHeight();
     837                 :          0 :     return 0;
     838                 :            : }
     839                 :            : 
     840                 :          0 : IMPL_LINK(ScCondFrmtEntry, EdModifyHdl, Edit*, pEdit)
     841                 :            : {
     842                 :          0 :     rtl::OUString aFormula = pEdit->GetText();
     843                 :          0 :     ScCompiler aComp( mpDoc, maPos );
     844                 :          0 :     aComp.SetGrammar( mpDoc->GetGrammar() );
     845                 :          0 :     boost::scoped_ptr<ScTokenArray> mpCode(aComp.CompileString(aFormula));
     846                 :          0 :     if(mpCode->GetCodeError())
     847                 :            :     {
     848                 :          0 :         pEdit->SetControlBackground(GetSettings().GetStyleSettings().GetHighlightColor());
     849                 :            :     }
     850                 :            :     else
     851                 :            :     {
     852                 :          0 :         pEdit->SetControlBackground(GetSettings().GetStyleSettings().GetWindowColor());
     853                 :            :     }
     854                 :          0 :     return 0;
     855                 :            : }
     856                 :            : 
     857                 :          0 : IMPL_LINK_NOARG(ScCondFrmtEntry, ColFormatTypeHdl)
     858                 :            : {
     859                 :          0 :     if(maLbColorFormat.GetSelectEntryPos() < 2)
     860                 :            :     {
     861                 :          0 :         SetColorScaleType();
     862                 :            :     }
     863                 :            :     else
     864                 :            :     {
     865                 :          0 :         SetDataBarType();
     866                 :            :     }
     867                 :            : 
     868                 :          0 :     SetHeight();
     869                 :            : 
     870                 :          0 :     return 0;
     871                 :            : }
     872                 :            : 
     873                 :          0 : IMPL_LINK( ScCondFrmtEntry, EntryTypeHdl, ListBox*, pBox )
     874                 :            : {
     875                 :          0 :     bool bEnableEdit = true;
     876                 :          0 :     sal_Int32 nPos = pBox->GetSelectEntryPos();
     877                 :          0 :     if(nPos == 0 || nPos == 1)
     878                 :            :     {
     879                 :          0 :         bEnableEdit = false;
     880                 :            :     }
     881                 :            : 
     882                 :          0 :     Edit* pEd = NULL;
     883                 :          0 :     if(pBox == &maLbEntryTypeMin)
     884                 :          0 :         pEd = &maEdMin;
     885                 :          0 :     else if(pBox == &maLbEntryTypeMiddle)
     886                 :          0 :         pEd = &maEdMiddle;
     887                 :          0 :     else if(pBox == &maLbEntryTypeMax)
     888                 :          0 :         pEd = &maEdMax;
     889                 :            : 
     890                 :          0 :     if(bEnableEdit)
     891                 :          0 :         pEd->Enable();
     892                 :            :     else
     893                 :          0 :         pEd->Disable();
     894                 :            : 
     895                 :          0 :     return 0;
     896                 :            : }
     897                 :            : 
     898                 :          0 : IMPL_LINK_NOARG(ScCondFrmtEntry, StyleSelectHdl)
     899                 :            : {
     900                 :          0 :     if(maLbStyle.GetSelectEntryPos() == 0)
     901                 :            :     {
     902                 :            :         // call new style dialog
     903                 :          0 :         SfxUInt16Item aFamilyItem( SID_STYLE_FAMILY, SFX_STYLE_FAMILY_PARA );
     904                 :          0 :         SfxStringItem aRefItem( SID_STYLE_REFERENCE, ScGlobal::GetRscString(STR_STYLENAME_STANDARD) );
     905                 :            : 
     906                 :            :         // unlock the dispatcher so SID_STYLE_NEW can be executed
     907                 :            :         // (SetDispatcherLock would affect all Calc documents)
     908                 :          0 :         ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
     909                 :          0 :         SfxDispatcher* pDisp = pViewShell->GetDispatcher();
     910                 :          0 :         sal_Bool bLocked = pDisp->IsLocked();
     911                 :          0 :         if (bLocked)
     912                 :          0 :             pDisp->Lock(false);
     913                 :            : 
     914                 :            :         // Execute the "new style" slot, complete with undo and all necessary updates.
     915                 :            :         // The return value (SfxUInt16Item) is ignored, look for new styles instead.
     916                 :            :         pDisp->Execute( SID_STYLE_NEW, SFX_CALLMODE_SYNCHRON | SFX_CALLMODE_RECORD | SFX_CALLMODE_MODAL,
     917                 :            :                 &aFamilyItem,
     918                 :            :                 &aRefItem,
     919                 :          0 :                 0L );
     920                 :            : 
     921                 :          0 :         if (bLocked)
     922                 :          0 :             pDisp->Lock(sal_True);
     923                 :            : 
     924                 :            :         // Find the new style and add it into the style list boxes
     925                 :          0 :         rtl::OUString aNewStyle;
     926                 :          0 :         SfxStyleSheetIterator aStyleIter( mpDoc->GetStyleSheetPool(), SFX_STYLE_FAMILY_PARA );
     927                 :          0 :         for ( SfxStyleSheetBase* pStyle = aStyleIter.First(); pStyle; pStyle = aStyleIter.Next() )
     928                 :            :         {
     929                 :          0 :             rtl::OUString aName = pStyle->GetName();
     930                 :          0 :             if ( maLbStyle.GetEntryPos(aName) == LISTBOX_ENTRY_NOTFOUND )    // all lists contain the same entries
     931                 :            :             {
     932                 :          0 :                 maLbStyle.InsertEntry(aName);
     933                 :          0 :                 maLbStyle.SelectEntry(aName);
     934                 :            :             }
     935                 :          0 :         }
     936                 :            :     }
     937                 :            : 
     938                 :          0 :     rtl::OUString aStyleName = maLbStyle.GetSelectEntry();
     939                 :          0 :     SfxStyleSheetBase* pStyleSheet = mpDoc->GetStyleSheetPool()->Find( aStyleName, SFX_STYLE_FAMILY_PARA );
     940                 :          0 :     if(pStyleSheet)
     941                 :            :     {
     942                 :          0 :         const SfxItemSet& rSet = pStyleSheet->GetItemSet();
     943                 :          0 :         maWdPreview.Init( rSet );
     944                 :            :     }
     945                 :            : 
     946                 :          0 :     return 0;
     947                 :            : }
     948                 :            : 
     949                 :          0 : IMPL_LINK_NOARG( ScCondFrmtEntry, DataBarTypeSelectHdl )
     950                 :            : {
     951                 :          0 :     sal_Int32 nSelectPos = maLbDataBarMinType.GetSelectEntryPos();
     952                 :          0 :     if(nSelectPos == 0 || nSelectPos == 1)
     953                 :          0 :         maEdDataBarMin.Disable();
     954                 :            :     else
     955                 :          0 :         maEdDataBarMin.Enable();
     956                 :            : 
     957                 :          0 :     nSelectPos = maLbDataBarMaxType.GetSelectEntryPos();
     958                 :          0 :     if(nSelectPos == 0 || nSelectPos == 1)
     959                 :          0 :         maEdDataBarMax.Disable();
     960                 :            :     else
     961                 :          0 :         maEdDataBarMax.Enable();
     962                 :            : 
     963                 :          0 :     return 0;
     964                 :            : }
     965                 :            : 
     966                 :          0 : IMPL_LINK_NOARG( ScCondFrmtEntry, OptionBtnHdl )
     967                 :            : {
     968                 :          0 :     SetColorScaleEntry(mpDataBarData->mpLowerLimit.get(), maLbDataBarMinType, maEdDataBarMin, mpDoc, maPos);
     969                 :          0 :     SetColorScaleEntry(mpDataBarData->mpUpperLimit.get(), maLbDataBarMaxType, maEdDataBarMax, mpDoc, maPos);
     970                 :          0 :     ScDataBarSettingsDlg* pDlg = new ScDataBarSettingsDlg(this, *mpDataBarData, mpDoc);
     971                 :          0 :     if( pDlg->Execute() == RET_OK)
     972                 :            :     {
     973                 :          0 :         mpDataBarData.reset(pDlg->GetData());
     974                 :          0 :         SetDataBarEntryTypes(*mpDataBarData->mpLowerLimit, maLbDataBarMinType, maEdDataBarMin);
     975                 :          0 :         SetDataBarEntryTypes(*mpDataBarData->mpUpperLimit, maLbDataBarMaxType, maEdDataBarMax);
     976                 :          0 :         DataBarTypeSelectHdl(NULL);
     977                 :            :     }
     978                 :          0 :     return 0;
     979                 :            : }
     980                 :            : 
     981                 :          0 : IMPL_LINK_NOARG( ScCondFrmtEntry, ConditionTypeSelectHdl )
     982                 :            : {
     983                 :          0 :     if(maLbCondType.GetSelectEntryPos() == 6 || maLbCondType.GetSelectEntryPos() == 7)
     984                 :            :     {
     985                 :          0 :         maEdVal2.Show();
     986                 :            :     }
     987                 :            :     else
     988                 :            :     {
     989                 :          0 :         maEdVal2.Hide();
     990                 :            :     }
     991                 :            : 
     992                 :          0 :     return 0;
     993                 :            : }
     994                 :            : 
     995                 :          0 : ScCondFormatList::ScCondFormatList(Window* pParent, const ResId& rResId, ScDocument* pDoc, const ScConditionalFormat* pFormat, const ScRangeList& rRanges, const ScAddress& rPos):
     996                 :            :     Control(pParent, rResId),
     997                 :            :     mbHasScrollBar(false),
     998                 :          0 :     mpScrollBar(new ScrollBar(this, WB_VERT )),
     999                 :            :     mnTopIndex(0),
    1000                 :            :     mpDoc(pDoc),
    1001                 :            :     maPos(rPos),
    1002                 :          0 :     maRanges(rRanges)
    1003                 :            : {
    1004                 :          0 :     mpScrollBar->SetScrollHdl( LINK( this, ScCondFormatList, ScrollHdl ) );
    1005                 :          0 :     mpScrollBar->EnableDrag();
    1006                 :            : 
    1007                 :          0 :     if(pFormat)
    1008                 :            :     {
    1009                 :          0 :         size_t nCount = pFormat->size();
    1010                 :          0 :         for (size_t nIndex = 0; nIndex < nCount; ++nIndex)
    1011                 :            :         {
    1012                 :          0 :             maEntries.push_back(new ScCondFrmtEntry( this, mpDoc, pFormat->GetEntry(nIndex), maPos ));
    1013                 :            :         }
    1014                 :            :     }
    1015                 :            : 
    1016                 :          0 :     RecalcAll();
    1017                 :          0 :     FreeResource();
    1018                 :          0 : }
    1019                 :            : 
    1020                 :          0 : ScConditionalFormat* ScCondFormatList::GetConditionalFormat() const
    1021                 :            : {
    1022                 :          0 :     if(maEntries.empty())
    1023                 :          0 :         return NULL;
    1024                 :            : 
    1025                 :          0 :     ScConditionalFormat* pFormat = new ScConditionalFormat(0, mpDoc);
    1026                 :          0 :     for(EntryContainer::const_iterator itr = maEntries.begin(); itr != maEntries.end(); ++itr)
    1027                 :            :     {
    1028                 :          0 :         ScFormatEntry* pEntry = itr->GetEntry();
    1029                 :          0 :         if(pEntry)
    1030                 :          0 :             pFormat->AddEntry(pEntry);
    1031                 :            :     }
    1032                 :            : 
    1033                 :          0 :     pFormat->AddRange(maRanges);
    1034                 :            : 
    1035                 :          0 :     return pFormat;
    1036                 :            : }
    1037                 :            : 
    1038                 :          0 : void ScCondFormatList::RecalcAll()
    1039                 :            : {
    1040                 :          0 :     sal_Int32 nTotalHeight = 0;
    1041                 :          0 :     sal_Int32 nIndex = 1;
    1042                 :          0 :     for(EntryContainer::iterator itr = maEntries.begin(); itr != maEntries.end(); ++itr)
    1043                 :            :     {
    1044                 :          0 :         nTotalHeight += itr->GetSizePixel().Height();
    1045                 :          0 :         itr->SetIndex( nIndex );
    1046                 :          0 :         ++nIndex;
    1047                 :            :     }
    1048                 :            : 
    1049                 :          0 :     Size aCtrlSize = GetOutputSize();
    1050                 :          0 :     long nSrcBarSize = GetSettings().GetStyleSettings().GetScrollBarSize();
    1051                 :          0 :     if(nTotalHeight > GetSizePixel().Height())
    1052                 :            :     {
    1053                 :          0 :         mbHasScrollBar = true;
    1054                 :          0 :         mpScrollBar->SetPosSizePixel(Point(aCtrlSize.Width() -nSrcBarSize, 0),
    1055                 :          0 :                 Size(nSrcBarSize, aCtrlSize.Height()) );
    1056                 :          0 :         mpScrollBar->SetRangeMax(nTotalHeight);
    1057                 :          0 :         mpScrollBar->SetVisibleSize(aCtrlSize.Height());
    1058                 :          0 :         mpScrollBar->Show();
    1059                 :            :     }
    1060                 :            :     else
    1061                 :            :     {
    1062                 :          0 :         mbHasScrollBar = false;
    1063                 :          0 :         mpScrollBar->Hide();
    1064                 :            :     }
    1065                 :            : 
    1066                 :          0 :     Point aPoint(0,-1*mpScrollBar->GetThumbPos());
    1067                 :          0 :     for(EntryContainer::iterator itr = maEntries.begin(); itr != maEntries.end(); ++itr)
    1068                 :            :     {
    1069                 :          0 :         itr->SetPosPixel(aPoint);
    1070                 :          0 :         Size aSize = itr->GetSizePixel();
    1071                 :          0 :         if(mbHasScrollBar)
    1072                 :          0 :             aSize.Width() = aCtrlSize.Width() - nSrcBarSize;
    1073                 :            :         else
    1074                 :          0 :             aSize.Width() = aCtrlSize.Width();
    1075                 :          0 :         itr->SetSizePixel(aSize);
    1076                 :            : 
    1077                 :          0 :         aPoint.Y() += itr->GetSizePixel().Height();
    1078                 :            :     }
    1079                 :          0 : }
    1080                 :            : 
    1081                 :          0 : void ScCondFormatList::DoScroll(long nDelta)
    1082                 :            : {
    1083                 :          0 :     Point aNewPoint = mpScrollBar->GetPosPixel();
    1084                 :          0 :     Rectangle aRect(Point(), GetOutputSize());
    1085                 :          0 :     aRect.Right() -= mpScrollBar->GetSizePixel().Width();
    1086                 :          0 :     Scroll( 0, -nDelta, aRect );
    1087                 :          0 :     mpScrollBar->SetPosPixel(aNewPoint);
    1088                 :          0 : }
    1089                 :            : 
    1090                 :          0 : ScCondFormatDlg::ScCondFormatDlg(Window* pParent, ScDocument* pDoc, const ScConditionalFormat* pFormat, const ScRangeList& rRange, const ScAddress& rPos):
    1091                 :            :     ModalDialog(pParent, ScResId( RID_SCDLG_CONDFORMAT )),
    1092                 :            :     maBtnAdd( this, ScResId( BTN_ADD ) ),
    1093                 :            :     maBtnRemove( this, ScResId( BTN_REMOVE ) ),
    1094                 :            :     maBtnOk( this, ScResId( BTN_OK ) ),
    1095                 :            :     maBtnCancel( this, ScResId( BTN_CANCEL ) ),
    1096                 :            :     maCondFormList( this, ScResId( CTRL_LIST ), pDoc, pFormat, rRange, rPos ),
    1097                 :            :     mpDoc(pDoc),
    1098                 :            :     mpFormat(pFormat),
    1099                 :          0 :     maPos(rPos)
    1100                 :            : {
    1101                 :            : 
    1102                 :          0 :     rtl::OUStringBuffer aTitle( GetText() );
    1103                 :          0 :     aTitle.append(rtl::OUString(" "));
    1104                 :          0 :     rtl::OUString aRangeString;
    1105                 :          0 :     rRange.Format(aRangeString, SCA_VALID, pDoc, pDoc->GetAddressConvention());
    1106                 :          0 :     aTitle.append(aRangeString);
    1107                 :          0 :     SetText(aTitle.makeStringAndClear());
    1108                 :          0 :     maBtnAdd.SetClickHdl( LINK( &maCondFormList, ScCondFormatList, AddBtnHdl ) );
    1109                 :          0 :     maBtnRemove.SetClickHdl( LINK( &maCondFormList, ScCondFormatList, RemoveBtnHdl ) );
    1110                 :          0 :     FreeResource();
    1111                 :          0 : }
    1112                 :            : 
    1113                 :          0 : ScConditionalFormat* ScCondFormatDlg::GetConditionalFormat() const
    1114                 :            : {
    1115                 :          0 :     return maCondFormList.GetConditionalFormat();
    1116                 :            : }
    1117                 :            : 
    1118                 :          0 : IMPL_LINK_NOARG( ScCondFormatList, AddBtnHdl )
    1119                 :            : {
    1120                 :          0 :     ScCondFrmtEntry* pNewEntry = new ScCondFrmtEntry(this, mpDoc, maPos);
    1121                 :          0 :     maEntries.push_back( pNewEntry );
    1122                 :          0 :     for(EntryContainer::iterator itr = maEntries.begin(); itr != maEntries.end(); ++itr)
    1123                 :            :     {
    1124                 :          0 :         itr->Deselect();
    1125                 :            :     }
    1126                 :          0 :     pNewEntry->Select();
    1127                 :          0 :     RecalcAll();
    1128                 :          0 :     return 0;
    1129                 :            : }
    1130                 :            : 
    1131                 :          0 : IMPL_LINK_NOARG( ScCondFormatList, RemoveBtnHdl )
    1132                 :            : {
    1133                 :          0 :     for(EntryContainer::iterator itr = maEntries.begin(); itr != maEntries.end(); ++itr)
    1134                 :            :     {
    1135                 :          0 :         if(itr->IsSelected())
    1136                 :            :         {
    1137                 :          0 :             maEntries.erase(itr);
    1138                 :          0 :             break;
    1139                 :            :         }
    1140                 :            :     }
    1141                 :          0 :     RecalcAll();
    1142                 :          0 :     return 0;
    1143                 :            : }
    1144                 :            : 
    1145                 :          0 : IMPL_LINK( ScCondFormatList, EntrySelectHdl, ScCondFrmtEntry*, pEntry )
    1146                 :            : {
    1147                 :          0 :     for(EntryContainer::iterator itr = maEntries.begin(); itr != maEntries.end(); ++itr)
    1148                 :            :     {
    1149                 :          0 :         itr->Deselect();
    1150                 :            :     }
    1151                 :          0 :     pEntry->Select();
    1152                 :          0 :     RecalcAll();
    1153                 :          0 :     return 0;
    1154                 :            : }
    1155                 :            : 
    1156                 :          0 : IMPL_LINK_NOARG( ScCondFormatList, ScrollHdl )
    1157                 :            : {
    1158                 :          0 :     DoScroll(mpScrollBar->GetDelta());
    1159                 :          0 :     return 0;
    1160                 :          0 : }
    1161                 :            : 
    1162                 :            : 
    1163                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10