LCOV - code coverage report
Current view: top level - chart2/source/controller/dialogs - tp_AxisPositions.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 1 159 0.6 %
Date: 2014-11-03 Functions: 2 15 13.3 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  *
       9             :  * 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 "tp_AxisPositions.hxx"
      21             : 
      22             : #include "ResId.hxx"
      23             : #include "ResourceIds.hrc"
      24             : #include "Strings.hrc"
      25             : #include "chartview/ChartSfxItemIds.hxx"
      26             : #include "AxisHelper.hxx"
      27             : 
      28             : #include <svx/svxids.hrc>
      29             : #include <rtl/math.hxx>
      30             : #include <svx/chrtitem.hxx>
      31             : #include <svl/eitem.hxx>
      32             : #include <svl/intitem.hxx>
      33             : #include <vcl/msgbox.hxx>
      34             : #include <svl/zformat.hxx>
      35             : #include <svtools/controldims.hrc>
      36             : 
      37             : #include <com/sun/star/chart/ChartAxisPosition.hpp>
      38             : #include <com/sun/star/chart2/AxisType.hpp>
      39             : 
      40             : using namespace ::com::sun::star;
      41             : 
      42             : namespace chart
      43             : {
      44             : 
      45           0 : AxisPositionsTabPage::AxisPositionsTabPage(vcl::Window* pWindow,const SfxItemSet& rInAttrs)
      46             :     : SfxTabPage(pWindow
      47             :                 ,"tp_AxisPositions"
      48             :                 ,"modules/schart/ui/tp_AxisPositions.ui"
      49             :                 , &rInAttrs)
      50             :     , m_pNumFormatter(NULL)
      51             :     , m_bCrossingAxisIsCategoryAxis(false)
      52             :     , m_aCategories()
      53           0 :     , m_bSupportAxisPositioning(false)
      54             : {
      55           0 :     get(m_pFL_AxisLine, "FL_AXIS_LINE");
      56           0 :     get(m_pLB_CrossesAt,"LB_CROSSES_OTHER_AXIS_AT");
      57           0 :     get(m_pED_CrossesAt,"EDT_CROSSES_OTHER_AXIS_AT");
      58           0 :     get(m_pED_CrossesAtCategory, "EDT_CROSSES_OTHER_AXIS_AT_CATEGORY");
      59           0 :     get(m_pCB_AxisBetweenCategories, "CB_AXIS_BETWEEN_CATEGORIES");
      60             : 
      61           0 :     get(m_pFL_Labels, "FL_LABELS");
      62           0 :     get(m_pLB_PlaceLabels,"LB_PLACE_LABELS");
      63           0 :     get(m_pED_LabelDistance,"EDT_AXIS_LABEL_DISTANCE");
      64             : 
      65           0 :     get(m_pCB_TicksInner, "CB_TICKS_INNER");
      66           0 :     get(m_pCB_TicksOuter, "CB_TICKS_OUTER");
      67           0 :     get(m_pCB_MinorInner, "CB_MINOR_INNER");
      68           0 :     get(m_pCB_MinorOuter, "CB_MINOR_OUTER");
      69             : 
      70           0 :     get(m_pBxPlaceTicks, "boxPLACE_TICKS");
      71           0 :     get(m_pLB_PlaceTicks, "LB_PLACE_TICKS");
      72             : 
      73             :     // these are not used/implemented
      74             : //     get(m_pCB_MajorGrid, "CB_MAJOR_GRID");
      75             : //     get(m_pPB_MajorGrid, "PB_MAJOR_GRID");
      76             : //     get(m_pCB_MinorGrid, "CB_MINOR_GRID");
      77             : //     get(m_pPB_MinorGrid, "PB_MINOR_GRID");
      78             : 
      79           0 :     m_pLB_CrossesAt->SetSelectHdl( LINK( this, AxisPositionsTabPage, CrossesAtSelectHdl ) );
      80           0 :     m_pLB_CrossesAt->SetDropDownLineCount( m_pLB_CrossesAt->GetEntryCount() );
      81             : 
      82           0 :     m_pLB_PlaceLabels->SetSelectHdl( LINK( this, AxisPositionsTabPage, PlaceLabelsSelectHdl ) );
      83           0 :     m_pLB_PlaceLabels->SetDropDownLineCount( m_pLB_PlaceLabels->GetEntryCount() );
      84           0 :     m_pLB_PlaceTicks->SetDropDownLineCount( m_pLB_PlaceTicks->GetEntryCount() );
      85           0 : }
      86             : 
      87           0 : SfxTabPage* AxisPositionsTabPage::Create(vcl::Window* pWindow,const SfxItemSet* rOutAttrs)
      88             : {
      89           0 :     return new AxisPositionsTabPage(pWindow, *rOutAttrs);
      90             : }
      91             : 
      92           0 : bool AxisPositionsTabPage::FillItemSet(SfxItemSet* rOutAttrs)
      93             : {
      94             :     // axis line
      95           0 :     sal_Int32 nPos = m_pLB_CrossesAt->GetSelectEntryPos();
      96           0 :     rOutAttrs->Put( SfxInt32Item( SCHATTR_AXIS_POSITION, nPos+1 ));
      97           0 :     if( 2==nPos )
      98             :     {
      99           0 :         double fCrossover = m_pED_CrossesAt->GetValue();
     100           0 :         if( m_bCrossingAxisIsCategoryAxis )
     101           0 :             fCrossover = m_pED_CrossesAtCategory->GetSelectEntryPos()+1;
     102           0 :         rOutAttrs->Put(SvxDoubleItem(fCrossover,SCHATTR_AXIS_POSITION_VALUE));
     103             :     }
     104             : 
     105             :     // labels
     106           0 :     sal_Int32 nLabelPos = m_pLB_PlaceLabels->GetSelectEntryPos();
     107           0 :     if( nLabelPos != LISTBOX_ENTRY_NOTFOUND )
     108           0 :         rOutAttrs->Put( SfxInt32Item( SCHATTR_AXIS_LABEL_POSITION, nLabelPos ));
     109             : 
     110             :     // tick marks
     111           0 :     long nTicks=0;
     112           0 :     long nMinorTicks=0;
     113             : 
     114           0 :     if(m_pCB_MinorInner->IsChecked())
     115           0 :         nMinorTicks|=CHAXIS_MARK_INNER;
     116           0 :     if(m_pCB_MinorOuter->IsChecked())
     117           0 :         nMinorTicks|=CHAXIS_MARK_OUTER;
     118           0 :     if(m_pCB_TicksInner->IsChecked())
     119           0 :         nTicks|=CHAXIS_MARK_INNER;
     120           0 :     if(m_pCB_TicksOuter->IsChecked())
     121           0 :         nTicks|=CHAXIS_MARK_OUTER;
     122             : 
     123           0 :     rOutAttrs->Put(SfxInt32Item(SCHATTR_AXIS_TICKS,nTicks));
     124           0 :     rOutAttrs->Put(SfxInt32Item(SCHATTR_AXIS_HELPTICKS,nMinorTicks));
     125             : 
     126           0 :     sal_Int32 nMarkPos = m_pLB_PlaceTicks->GetSelectEntryPos();
     127           0 :     if( nMarkPos != LISTBOX_ENTRY_NOTFOUND )
     128           0 :         rOutAttrs->Put( SfxInt32Item( SCHATTR_AXIS_MARK_POSITION, nMarkPos ));
     129             : 
     130           0 :     return true;
     131             : }
     132             : 
     133           0 : void AxisPositionsTabPage::Reset(const SfxItemSet* rInAttrs)
     134             : {
     135             :     //init and enable controls
     136           0 :     m_pED_CrossesAt->Show( !m_bCrossingAxisIsCategoryAxis );
     137           0 :     m_pED_CrossesAtCategory->Show( m_bCrossingAxisIsCategoryAxis );
     138           0 :     const sal_Int32 nMaxCount = LISTBOX_ENTRY_NOTFOUND;
     139           0 :     if( m_bCrossingAxisIsCategoryAxis )
     140             :     {
     141           0 :         for( sal_Int32 nN=0; nN<m_aCategories.getLength() && nN<nMaxCount; nN++ )
     142           0 :             m_pED_CrossesAtCategory->InsertEntry( m_aCategories[nN] );
     143             : 
     144           0 :         sal_uInt16 nCount = m_pED_CrossesAtCategory->GetEntryCount();
     145           0 :         if( nCount>30 )
     146           0 :             nCount=30;
     147           0 :         m_pED_CrossesAtCategory->SetDropDownLineCount( nCount );
     148             :     }
     149             : 
     150           0 :     if( m_pLB_CrossesAt->GetEntryCount() > 3 )
     151             :     {
     152           0 :         if( m_bCrossingAxisIsCategoryAxis )
     153           0 :             m_pLB_CrossesAt->RemoveEntry(2);
     154             :         else
     155           0 :             m_pLB_CrossesAt->RemoveEntry(3);
     156             :     }
     157             : 
     158             :     //fill controls
     159           0 :     const SfxPoolItem *pPoolItem = NULL;
     160             : 
     161             :     //axis line
     162           0 :     if(rInAttrs->GetItemState(SCHATTR_AXIS_POSITION,true, &pPoolItem)== SfxItemState::SET)
     163             :     {
     164           0 :         bool bZero = false;
     165           0 :         sal_Int32 nPos = static_cast< const SfxInt32Item * >( pPoolItem )->GetValue();
     166           0 :         if(nPos==0)
     167             :         {
     168             :             //switch to value
     169           0 :             bZero = true;
     170           0 :             nPos = 2;
     171             :         }
     172             :         else
     173           0 :             nPos--;
     174             : 
     175           0 :         if( nPos < m_pLB_CrossesAt->GetEntryCount() )
     176           0 :             m_pLB_CrossesAt->SelectEntryPos( nPos );
     177           0 :         CrossesAtSelectHdl( (void*)0 );
     178             : 
     179           0 :         if( rInAttrs->GetItemState(SCHATTR_AXIS_POSITION_VALUE,true, &pPoolItem)== SfxItemState::SET || bZero )
     180             :         {
     181           0 :             double fCrossover = 0.0;
     182           0 :             if( !bZero )
     183           0 :                 fCrossover = static_cast<const SvxDoubleItem*>(pPoolItem)->GetValue();
     184           0 :             if( m_bCrossingAxisIsCategoryAxis )
     185           0 :                 m_pED_CrossesAtCategory->SelectEntryPos( static_cast<sal_uInt16>(::rtl::math::round(fCrossover-1.0)) );
     186             :             else
     187           0 :                 m_pED_CrossesAt->SetValue(fCrossover);
     188             :         }
     189             :         else
     190             :         {
     191           0 :             m_pED_CrossesAtCategory->SetNoSelection();
     192           0 :             m_pED_CrossesAt->SetTextValue("");
     193             :         }
     194             :     }
     195             :     else
     196             :     {
     197           0 :         m_pLB_CrossesAt->SetNoSelection();
     198           0 :         m_pED_CrossesAt->Enable( false );
     199             :     }
     200             : 
     201             :     // Labels
     202           0 :     if( rInAttrs->GetItemState( SCHATTR_AXIS_LABEL_POSITION, false, &pPoolItem ) == SfxItemState::SET )
     203             :     {
     204           0 :         sal_Int32 nPos = static_cast< const SfxInt32Item * >( pPoolItem )->GetValue();
     205           0 :         if( nPos < m_pLB_PlaceLabels->GetEntryCount() )
     206           0 :             m_pLB_PlaceLabels->SelectEntryPos( nPos );
     207             :     }
     208             :     else
     209           0 :         m_pLB_PlaceLabels->SetNoSelection();
     210           0 :     PlaceLabelsSelectHdl( (void*)0 );
     211             : 
     212             :     // Tick marks
     213           0 :     long nTicks = 0, nMinorTicks = 0;
     214           0 :     if(rInAttrs->GetItemState(SCHATTR_AXIS_TICKS,true, &pPoolItem)== SfxItemState::SET)
     215           0 :         nTicks = static_cast<const SfxInt32Item*>(pPoolItem)->GetValue();
     216           0 :     if(rInAttrs->GetItemState(SCHATTR_AXIS_HELPTICKS,true, &pPoolItem)== SfxItemState::SET)
     217           0 :         nMinorTicks = static_cast<const SfxInt32Item*>(pPoolItem)->GetValue();
     218             : 
     219           0 :     m_pCB_TicksInner->Check(bool(nTicks&CHAXIS_MARK_INNER));
     220           0 :     m_pCB_TicksOuter->Check(bool(nTicks&CHAXIS_MARK_OUTER));
     221           0 :     m_pCB_MinorInner->Check(bool(nMinorTicks&CHAXIS_MARK_INNER));
     222           0 :     m_pCB_MinorOuter->Check(bool(nMinorTicks&CHAXIS_MARK_OUTER));
     223             : 
     224             :     // Tick position
     225           0 :     if( rInAttrs->GetItemState( SCHATTR_AXIS_MARK_POSITION, false, &pPoolItem ) == SfxItemState::SET )
     226             :     {
     227           0 :         sal_Int32 nPos = static_cast< const SfxInt32Item * >( pPoolItem )->GetValue();
     228           0 :         if( nPos < m_pLB_PlaceTicks->GetEntryCount() )
     229           0 :             m_pLB_PlaceTicks->SelectEntryPos( nPos );
     230             :     }
     231             :     else
     232           0 :         m_pLB_PlaceTicks->SetNoSelection();
     233             : 
     234           0 :     if( !m_bSupportAxisPositioning )
     235             :     {
     236           0 :         m_pFL_AxisLine->Show(false);
     237             : 
     238           0 :         m_pFL_Labels->Show(false);
     239             : 
     240           0 :         m_pBxPlaceTicks->Show(false);
     241             :     }
     242           0 :     else if( !AxisHelper::isAxisPositioningEnabled() )
     243             :     {
     244             : 
     245           0 :         m_pFL_AxisLine->Enable(false);
     246             : 
     247           0 :         m_pFL_Labels->Enable(false);
     248             : 
     249           0 :         m_pBxPlaceTicks->Enable(false);
     250             : 
     251             :         //todo: maybe set a special help id to all those controls
     252             :     }
     253           0 : }
     254             : 
     255           0 : int AxisPositionsTabPage::DeactivatePage(SfxItemSet* pItemSet)
     256             : {
     257           0 :     if( pItemSet )
     258           0 :         FillItemSet( pItemSet );
     259             : 
     260           0 :     return LEAVE_PAGE;
     261             : }
     262             : 
     263           0 : void AxisPositionsTabPage::SetNumFormatter( SvNumberFormatter* pFormatter )
     264             : {
     265           0 :     m_pNumFormatter = pFormatter;
     266           0 :     m_pED_CrossesAt->SetFormatter( m_pNumFormatter );
     267           0 :     m_pED_CrossesAt->UseInputStringForFormatting();
     268             : 
     269           0 :     const SfxPoolItem *pPoolItem = NULL;
     270           0 :     if( GetItemSet().GetItemState( SCHATTR_AXIS_CROSSING_MAIN_AXIS_NUMBERFORMAT, true, &pPoolItem ) == SfxItemState::SET )
     271             :     {
     272           0 :         sal_uLong nFmt = (sal_uLong)static_cast<const SfxInt32Item*>(pPoolItem)->GetValue();
     273           0 :         m_pED_CrossesAt->SetFormatKey( nFmt );
     274             :     }
     275           0 : }
     276             : 
     277           0 : void AxisPositionsTabPage::SetCrossingAxisIsCategoryAxis( bool bCrossingAxisIsCategoryAxis )
     278             : {
     279           0 :     m_bCrossingAxisIsCategoryAxis = bCrossingAxisIsCategoryAxis;
     280           0 : }
     281             : 
     282           0 : void AxisPositionsTabPage::SetCategories( const ::com::sun::star::uno::Sequence< OUString >& rCategories )
     283             : {
     284           0 :     m_aCategories = rCategories;
     285           0 : }
     286             : 
     287           0 : void AxisPositionsTabPage::SupportAxisPositioning( bool bSupportAxisPositioning )
     288             : {
     289           0 :     m_bSupportAxisPositioning = bSupportAxisPositioning;
     290           0 : }
     291             : 
     292           0 : IMPL_LINK_NOARG(AxisPositionsTabPage, CrossesAtSelectHdl)
     293             : {
     294           0 :     sal_Int32 nPos = m_pLB_CrossesAt->GetSelectEntryPos();
     295           0 :     m_pED_CrossesAt->Show( (2==nPos) && !m_bCrossingAxisIsCategoryAxis );
     296           0 :     m_pED_CrossesAtCategory->Show( (2==nPos) && m_bCrossingAxisIsCategoryAxis );
     297             : 
     298           0 :     if( m_pED_CrossesAt->GetText().isEmpty() )
     299           0 :         m_pED_CrossesAt->SetValue(0.0);
     300           0 :     if( 0 == m_pED_CrossesAtCategory->GetSelectEntryCount() )
     301           0 :         m_pED_CrossesAtCategory->SelectEntryPos(0);
     302             : 
     303           0 :     PlaceLabelsSelectHdl( (void*)0 );
     304           0 :     return 0;
     305             : }
     306             : 
     307           0 : IMPL_LINK_NOARG(AxisPositionsTabPage, PlaceLabelsSelectHdl)
     308             : {
     309           0 :     sal_Int32 nLabelPos = m_pLB_PlaceLabels->GetSelectEntryPos();
     310             : 
     311           0 :     bool bEnableTickmarkPlacement = (nLabelPos>1);
     312           0 :     if( bEnableTickmarkPlacement )
     313             :     {
     314           0 :         sal_Int32 nAxisPos = m_pLB_CrossesAt->GetSelectEntryPos();
     315           0 :         if( nLabelPos-2 == nAxisPos )
     316           0 :             bEnableTickmarkPlacement=false;
     317             :     }
     318           0 :     m_pBxPlaceTicks->Enable(bEnableTickmarkPlacement);
     319             : 
     320           0 :     return 0;
     321             : }
     322             : 
     323         102 : } //namespace chart
     324             : 
     325             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10