LCOV - code coverage report
Current view: top level - libreoffice/cui/source/options - optchart.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 1 133 0.8 %
Date: 2012-12-27 Functions: 2 22 9.1 %
Legend: Lines: hit not hit

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

Generated by: LCOV version 1.10