LCOV - code coverage report
Current view: top level - cui/source/options - optchart.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 132 0.0 %
Date: 2012-08-25 Functions: 0 20 0.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 234 0.0 %

           Branch data     Line data    Source code
       1                 :            : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2                 :            : /*************************************************************************
       3                 :            :  *
       4                 :            :  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       5                 :            :  *
       6                 :            :  * Copyright 2000, 2010 Oracle and/or its affiliates.
       7                 :            :  *
       8                 :            :  * OpenOffice.org - a multi-platform office productivity suite
       9                 :            :  *
      10                 :            :  * This file is part of OpenOffice.org.
      11                 :            :  *
      12                 :            :  * OpenOffice.org is free software: you can redistribute it and/or modify
      13                 :            :  * it under the terms of the GNU Lesser General Public License version 3
      14                 :            :  * only, as published by the Free Software Foundation.
      15                 :            :  *
      16                 :            :  * OpenOffice.org is distributed in the hope that it will be useful,
      17                 :            :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      18                 :            :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      19                 :            :  * GNU Lesser General Public License version 3 for more details
      20                 :            :  * (a copy is included in the LICENSE file that accompanied this code).
      21                 :            :  *
      22                 :            :  * You should have received a copy of the GNU Lesser General Public License
      23                 :            :  * version 3 along with OpenOffice.org.  If not, see
      24                 :            :  * <http://www.openoffice.org/license.html>
      25                 :            :  * for a copy of the LGPLv3 License.
      26                 :            :  *
      27                 :            :  ************************************************************************/
      28                 :            : 
      29                 :            : #include <unotools/pathoptions.hxx>
      30                 :            : #include <cuires.hrc>
      31                 :            : #include "optchart.hxx"
      32                 :            : #include "optchart.hrc"
      33                 :            : #include <dialmgr.hxx>
      34                 :            : #include <vcl/msgbox.hxx>
      35                 :            : #include <svx/svxids.hrc> // for SID_SCH_EDITOPTIONS
      36                 :            : 
      37                 :            : // ====================
      38                 :            : // class ChartColorLB
      39                 :            : // ====================
      40                 :          0 : void ChartColorLB::FillBox( const SvxChartColorTable & rTab )
      41                 :            : {
      42                 :          0 :     long nCount = rTab.size();
      43                 :          0 :     SetUpdateMode( sal_False );
      44                 :            : 
      45         [ #  # ]:          0 :     for( long i = 0; i < nCount; i++ )
      46                 :            :     {
      47                 :          0 :         Append( const_cast< XColorEntry * >( & rTab[ i ] ));
      48                 :            :     }
      49                 :          0 :     SetUpdateMode( sal_True );
      50                 :          0 : }
      51                 :            : 
      52                 :            : 
      53                 :            : // ====================
      54                 :            : // class SvxDefaultColorOptPage
      55                 :            : // ====================
      56                 :          0 : SvxDefaultColorOptPage::SvxDefaultColorOptPage( Window* pParent, const SfxItemSet& rInAttrs ) :
      57                 :            : 
      58                 :          0 :     SfxTabPage( pParent, CUI_RES( RID_OPTPAGE_CHART_DEFCOLORS ), rInAttrs ),
      59                 :            : 
      60         [ #  # ]:          0 :     aGbChartColors  ( this, CUI_RES( FL_CHART_COLOR_LIST ) ),
      61         [ #  # ]:          0 :     aLbChartColors  ( this, CUI_RES( LB_CHART_COLOR_LIST ) ),
      62         [ #  # ]:          0 :     aGbColorBox     ( this, CUI_RES( FL_COLOR_BOX ) ),
      63         [ #  # ]:          0 :     aValSetColorBox ( this, CUI_RES( CT_COLOR_BOX ) ),
      64         [ #  # ]:          0 :     aPBDefault      ( this, CUI_RES( PB_RESET_TO_DEFAULT ) ),
      65         [ #  # ]:          0 :     aPBAdd              ( this, CUI_RES( PB_ADD_CHART_COLOR ) ),
      66 [ #  # ][ #  # ]:          0 :     aPBRemove           ( this, CUI_RES( PB_REMOVE_CHART_COLOR ) )
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
      67                 :            : {
      68         [ #  # ]:          0 :     FreeResource();
      69                 :            : 
      70         [ #  # ]:          0 :     aPBDefault.SetClickHdl( LINK( this, SvxDefaultColorOptPage, ResetToDefaults ) );
      71         [ #  # ]:          0 :     aPBAdd.SetClickHdl( LINK( this, SvxDefaultColorOptPage, AddChartColor ) );
      72         [ #  # ]:          0 :     aPBRemove.SetClickHdl( LINK( this, SvxDefaultColorOptPage, RemoveChartColor ) );
      73         [ #  # ]:          0 :     aLbChartColors.SetSelectHdl( LINK( this, SvxDefaultColorOptPage, ListClickedHdl ) );
      74         [ #  # ]:          0 :     aValSetColorBox.SetSelectHdl( LINK( this, SvxDefaultColorOptPage, BoxClickedHdl ) );
      75                 :            : 
      76         [ #  # ]:          0 :     aValSetColorBox.SetStyle( aValSetColorBox.GetStyle()
      77         [ #  # ]:          0 :                                     | WB_ITEMBORDER | WB_NAMEFIELD );
      78         [ #  # ]:          0 :     aValSetColorBox.SetColCount( 8 );
      79         [ #  # ]:          0 :     aValSetColorBox.SetLineCount( 13 );
      80         [ #  # ]:          0 :     aValSetColorBox.SetExtraSpacing( 0 );
      81         [ #  # ]:          0 :     aValSetColorBox.Show();
      82                 :            : 
      83 [ #  # ][ #  # ]:          0 :     pChartOptions = new SvxChartOptions;
      84 [ #  # ][ #  # ]:          0 :     pColorList = XColorList::CreateStdColorList();
      85                 :            : 
      86                 :          0 :     const SfxPoolItem* pItem = NULL;
      87 [ #  # ][ #  # ]:          0 :     if ( rInAttrs.GetItemState( SID_SCH_EDITOPTIONS, sal_False, &pItem ) == SFX_ITEM_SET )
      88                 :            :     {
      89         [ #  # ]:          0 :         pColorConfig = (static_cast< SvxChartColorTableItem* >(pItem->Clone()) );
      90                 :            :     }
      91                 :            :     else
      92                 :            :     {
      93         [ #  # ]:          0 :         SvxChartColorTable aTable;
      94         [ #  # ]:          0 :         aTable.useDefault();
      95 [ #  # ][ #  # ]:          0 :         pColorConfig = new SvxChartColorTableItem( SID_SCH_EDITOPTIONS, aTable );
      96 [ #  # ][ #  # ]:          0 :         pColorConfig->SetOptions( pChartOptions );
      97                 :            :     }
      98                 :            : 
      99         [ #  # ]:          0 :     Construct();
     100                 :          0 : }
     101                 :            : 
     102 [ #  # ][ #  # ]:          0 : SvxDefaultColorOptPage::~SvxDefaultColorOptPage()
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     103                 :            : {
     104                 :            :     // save changes
     105 [ #  # ][ #  # ]:          0 :     pChartOptions->SetDefaultColors( pColorConfig->GetColorList() );
     106         [ #  # ]:          0 :     pChartOptions->Commit();
     107                 :            : 
     108 [ #  # ][ #  # ]:          0 :     delete pColorConfig;
     109 [ #  # ][ #  # ]:          0 :     delete pChartOptions;
     110         [ #  # ]:          0 : }
     111                 :            : 
     112                 :          0 : void SvxDefaultColorOptPage::Construct()
     113                 :            : {
     114         [ #  # ]:          0 :     if( pColorConfig )
     115                 :          0 :         aLbChartColors.FillBox( pColorConfig->GetColorList() );
     116                 :            : 
     117                 :          0 :     FillColorBox();
     118                 :            : 
     119                 :          0 :     aLbChartColors.SelectEntryPos( 0 );
     120                 :          0 :     ListClickedHdl( &aLbChartColors );
     121                 :          0 : }
     122                 :            : 
     123                 :            : 
     124                 :          0 : SfxTabPage* SvxDefaultColorOptPage::Create( Window* pParent, const SfxItemSet& rAttrs )
     125                 :            : {
     126         [ #  # ]:          0 :     return new SvxDefaultColorOptPage( pParent, rAttrs );
     127                 :            : }
     128                 :            : 
     129                 :          0 : sal_Bool SvxDefaultColorOptPage::FillItemSet( SfxItemSet& rOutAttrs )
     130                 :            : {
     131         [ #  # ]:          0 :     if( pColorConfig )
     132                 :          0 :         rOutAttrs.Put( *(static_cast< SfxPoolItem* >(pColorConfig)));
     133                 :            : 
     134                 :          0 :     return sal_True;
     135                 :            : }
     136                 :            : 
     137                 :          0 : void SvxDefaultColorOptPage::Reset( const SfxItemSet& )
     138                 :            : {
     139                 :          0 :     aLbChartColors.SelectEntryPos( 0 );
     140                 :          0 :     ListClickedHdl( &aLbChartColors );
     141                 :          0 : }
     142                 :            : 
     143                 :          0 : void SvxDefaultColorOptPage::FillColorBox()
     144                 :            : {
     145         [ #  # ]:          0 :     if( !pColorList.is() ) return;
     146                 :            : 
     147                 :          0 :     long nCount = pColorList->Count();
     148                 :            :     XColorEntry* pColorEntry;
     149                 :            : 
     150         [ #  # ]:          0 :     if( nCount > 104 )
     151                 :          0 :         aValSetColorBox.SetStyle( aValSetColorBox.GetStyle() | WB_VSCROLL );
     152                 :            : 
     153         [ #  # ]:          0 :     for( long i = 0; i < nCount; i++ )
     154                 :            :     {
     155                 :          0 :         pColorEntry = pColorList->GetColor( i );
     156                 :          0 :         aValSetColorBox.InsertItem( (sal_uInt16) i + 1, pColorEntry->GetColor(), pColorEntry->GetName() );
     157                 :            :     }
     158                 :            : }
     159                 :            : 
     160                 :            : 
     161                 :          0 : long SvxDefaultColorOptPage::GetColorIndex( const Color& rCol )
     162                 :            : {
     163         [ #  # ]:          0 :     if( pColorList.is() )
     164                 :            :     {
     165                 :          0 :         long nCount = pColorList->Count();
     166                 :            :         XColorEntry* pColorEntry;
     167                 :            : 
     168         [ #  # ]:          0 :         for( long i = nCount - 1; i >= 0; i-- )         // default chart colors are at the end of the table
     169                 :            :         {
     170                 :          0 :             pColorEntry = pColorList->GetColor( i );
     171 [ #  # ][ #  # ]:          0 :             if( pColorEntry && pColorEntry->GetColor() == rCol )
                 [ #  # ]
     172                 :          0 :                 return pColorList->Get( pColorEntry->GetName() );
     173                 :            :         }
     174                 :            :     }
     175                 :          0 :     return -1L;
     176                 :            : }
     177                 :            : 
     178                 :            : 
     179                 :            : 
     180                 :            : // --------------------
     181                 :            : // event handlers
     182                 :            : // --------------------
     183                 :            : 
     184                 :            : // ResetToDefaults
     185                 :            : // ---------------
     186                 :            : 
     187                 :          0 : IMPL_LINK_NOARG(SvxDefaultColorOptPage, ResetToDefaults)
     188                 :            : {
     189         [ #  # ]:          0 :     if( pColorConfig )
     190                 :            :     {
     191                 :          0 :         pColorConfig->GetColorList().useDefault();
     192                 :            : 
     193                 :          0 :         aLbChartColors.Clear();
     194                 :          0 :         aLbChartColors.FillBox( pColorConfig->GetColorList() );
     195                 :            : 
     196                 :          0 :         aLbChartColors.GetFocus();
     197                 :          0 :         aLbChartColors.SelectEntryPos( 0 );
     198                 :          0 :         aPBRemove.Enable( sal_True );
     199                 :            :     }
     200                 :            : 
     201                 :          0 :     return 0L;
     202                 :            : }
     203                 :            : 
     204                 :            : // AddChartColor
     205                 :            : // ------------
     206                 :            : 
     207                 :          0 : IMPL_LINK_NOARG(SvxDefaultColorOptPage, AddChartColor)
     208                 :            : {
     209         [ #  # ]:          0 :     if( pColorConfig )
     210                 :            :     {
     211                 :          0 :         ColorData black = RGB_COLORDATA( 0x00, 0x00, 0x00 );
     212                 :            : 
     213 [ #  # ][ #  # ]:          0 :         pColorConfig->GetColorList().append (XColorEntry ( black, pColorConfig->GetColorList().getDefaultName(pColorConfig->GetColorList().size())));
         [ #  # ][ #  # ]
     214                 :            : 
     215                 :          0 :         aLbChartColors.Clear();
     216                 :          0 :         aLbChartColors.FillBox( pColorConfig->GetColorList() );
     217                 :            : 
     218                 :          0 :         aLbChartColors.GetFocus();
     219                 :          0 :         aLbChartColors.SelectEntryPos( pColorConfig->GetColorList().size() - 1 );
     220                 :          0 :         aPBRemove.Enable( sal_True );
     221                 :            :     }
     222                 :            : 
     223                 :          0 :     return 0L;
     224                 :            : }
     225                 :            : 
     226                 :            : // RemoveChartColor
     227                 :            : // ----------------
     228                 :            : 
     229                 :          0 : IMPL_LINK( SvxDefaultColorOptPage, RemoveChartColor, PushButton*, pButton )
     230                 :            : {
     231                 :          0 :     size_t nIndex = aLbChartColors.GetSelectEntryPos();
     232                 :            : 
     233         [ #  # ]:          0 :     if (aLbChartColors.GetSelectEntryCount() == 0)
     234                 :          0 :         return 0L;
     235                 :            : 
     236         [ #  # ]:          0 :     if( pColorConfig )
     237                 :            :     {
     238                 :            :         OSL_ENSURE(pColorConfig->GetColorList().size() > 1, "don't delete the last chart color");
     239 [ #  # ][ #  # ]:          0 :         QueryBox aQuery(pButton, CUI_RES(RID_OPTQB_COLOR_CHART_DELETE));
     240 [ #  # ][ #  # ]:          0 :         aQuery.SetText(String(CUI_RES(RID_OPTSTR_COLOR_CHART_DELETE)));
         [ #  # ][ #  # ]
     241 [ #  # ][ #  # ]:          0 :         if(RET_YES == aQuery.Execute())
     242                 :            :         {
     243                 :            : 
     244 [ #  # ][ #  # ]:          0 :             pColorConfig->GetColorList().remove( nIndex  );
     245                 :            : 
     246         [ #  # ]:          0 :             aLbChartColors.Clear();
     247 [ #  # ][ #  # ]:          0 :             aLbChartColors.FillBox( pColorConfig->GetColorList() );
     248                 :            : 
     249         [ #  # ]:          0 :             aLbChartColors.GetFocus();
     250                 :            : 
     251 [ #  # ][ #  # ]:          0 :             if (nIndex == aLbChartColors.GetEntryCount() && aLbChartColors.GetEntryCount() > 0)
         [ #  # ][ #  # ]
                 [ #  # ]
     252 [ #  # ][ #  # ]:          0 :                 aLbChartColors.SelectEntryPos( pColorConfig->GetColorList().size() - 1 );
                 [ #  # ]
     253 [ #  # ][ #  # ]:          0 :             else if (aLbChartColors.GetEntryCount() > 0)
     254         [ #  # ]:          0 :                 aLbChartColors.SelectEntryPos( nIndex );
     255                 :            :             else
     256         [ #  # ]:          0 :                 aPBRemove.Enable( sal_False );
     257         [ #  # ]:          0 :         }
     258                 :            :     }
     259                 :            : 
     260                 :          0 :     return 0L;
     261                 :            : }
     262                 :            : 
     263                 :          0 : IMPL_LINK( SvxDefaultColorOptPage, ListClickedHdl, ChartColorLB*, _pColorList )
     264                 :            : {
     265         [ #  # ]:          0 :     Color aCol = _pColorList->GetSelectEntryColor();
     266                 :            : 
     267         [ #  # ]:          0 :     long nIndex = GetColorIndex( aCol );
     268                 :            : 
     269         [ #  # ]:          0 :     if( nIndex == -1 )      // not found
     270         [ #  # ]:          0 :         aValSetColorBox.SetNoSelection();
     271                 :            :     else
     272         [ #  # ]:          0 :         aValSetColorBox.SelectItem( (sal_uInt16)nIndex + 1 );       // ValueSet is 1-based
     273                 :            : 
     274                 :          0 :     return 0L;
     275                 :            : }
     276                 :            : 
     277                 :          0 : IMPL_LINK_NOARG(SvxDefaultColorOptPage, BoxClickedHdl)
     278                 :            : {
     279                 :          0 :     sal_uInt16 nIdx = aLbChartColors.GetSelectEntryPos();
     280         [ #  # ]:          0 :     if( nIdx != LISTBOX_ENTRY_NOTFOUND )
     281                 :            :     {
     282                 :          0 :         XColorEntry aEntry( aValSetColorBox.GetItemColor( aValSetColorBox.GetSelectItemId() ),
     283   [ #  #  #  # ]:          0 :                             aLbChartColors.GetSelectEntry() );
         [ #  # ][ #  # ]
     284                 :            : 
     285         [ #  # ]:          0 :         aLbChartColors.Modify( & aEntry, nIdx );
     286         [ #  # ]:          0 :         pColorConfig->ReplaceColorByIndex( nIdx, aEntry );
     287                 :            : 
     288 [ #  # ][ #  # ]:          0 :         aLbChartColors.SelectEntryPos( nIdx );  // reselect entry
     289                 :            :     }
     290                 :            : 
     291                 :          0 :     return 0L;
     292                 :            : }
     293                 :            : 
     294                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10