LCOV - code coverage report
Current view: top level - chart2/source/controller/dialogs - tp_AxisPositions.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 1 179 0.6 %
Date: 2015-06-13 12:38:46 Functions: 2 18 11.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 "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 : AxisPositionsTabPage::~AxisPositionsTabPage()
      88             : {
      89           0 :     disposeOnce();
      90           0 : }
      91             : 
      92           0 : void AxisPositionsTabPage::dispose()
      93             : {
      94           0 :     m_pFL_AxisLine.clear();
      95           0 :     m_pLB_CrossesAt.clear();
      96           0 :     m_pED_CrossesAt.clear();
      97           0 :     m_pED_CrossesAtCategory.clear();
      98           0 :     m_pCB_AxisBetweenCategories.clear();
      99           0 :     m_pFL_Labels.clear();
     100           0 :     m_pLB_PlaceLabels.clear();
     101           0 :     m_pED_LabelDistance.clear();
     102           0 :     m_pCB_TicksInner.clear();
     103           0 :     m_pCB_TicksOuter.clear();
     104           0 :     m_pCB_MinorInner.clear();
     105           0 :     m_pCB_MinorOuter.clear();
     106           0 :     m_pBxPlaceTicks.clear();
     107           0 :     m_pLB_PlaceTicks.clear();
     108           0 :     SfxTabPage::dispose();
     109           0 : }
     110             : 
     111           0 : VclPtr<SfxTabPage> AxisPositionsTabPage::Create(vcl::Window* pWindow,const SfxItemSet* rOutAttrs)
     112             : {
     113           0 :     return VclPtr<AxisPositionsTabPage>::Create(pWindow, *rOutAttrs);
     114             : }
     115             : 
     116           0 : bool AxisPositionsTabPage::FillItemSet(SfxItemSet* rOutAttrs)
     117             : {
     118             :     // axis line
     119           0 :     sal_Int32 nPos = m_pLB_CrossesAt->GetSelectEntryPos();
     120           0 :     rOutAttrs->Put( SfxInt32Item( SCHATTR_AXIS_POSITION, nPos+1 ));
     121           0 :     if( 2==nPos )
     122             :     {
     123           0 :         double fCrossover = m_pED_CrossesAt->GetValue();
     124           0 :         if( m_bCrossingAxisIsCategoryAxis )
     125           0 :             fCrossover = m_pED_CrossesAtCategory->GetSelectEntryPos()+1;
     126           0 :         rOutAttrs->Put(SvxDoubleItem(fCrossover,SCHATTR_AXIS_POSITION_VALUE));
     127             :     }
     128             : 
     129             :     // labels
     130           0 :     sal_Int32 nLabelPos = m_pLB_PlaceLabels->GetSelectEntryPos();
     131           0 :     if( nLabelPos != LISTBOX_ENTRY_NOTFOUND )
     132           0 :         rOutAttrs->Put( SfxInt32Item( SCHATTR_AXIS_LABEL_POSITION, nLabelPos ));
     133             : 
     134             :     // tick marks
     135           0 :     long nTicks=0;
     136           0 :     long nMinorTicks=0;
     137             : 
     138           0 :     if(m_pCB_MinorInner->IsChecked())
     139           0 :         nMinorTicks|=CHAXIS_MARK_INNER;
     140           0 :     if(m_pCB_MinorOuter->IsChecked())
     141           0 :         nMinorTicks|=CHAXIS_MARK_OUTER;
     142           0 :     if(m_pCB_TicksInner->IsChecked())
     143           0 :         nTicks|=CHAXIS_MARK_INNER;
     144           0 :     if(m_pCB_TicksOuter->IsChecked())
     145           0 :         nTicks|=CHAXIS_MARK_OUTER;
     146             : 
     147           0 :     rOutAttrs->Put(SfxInt32Item(SCHATTR_AXIS_TICKS,nTicks));
     148           0 :     rOutAttrs->Put(SfxInt32Item(SCHATTR_AXIS_HELPTICKS,nMinorTicks));
     149             : 
     150           0 :     sal_Int32 nMarkPos = m_pLB_PlaceTicks->GetSelectEntryPos();
     151           0 :     if( nMarkPos != LISTBOX_ENTRY_NOTFOUND )
     152           0 :         rOutAttrs->Put( SfxInt32Item( SCHATTR_AXIS_MARK_POSITION, nMarkPos ));
     153             : 
     154           0 :     return true;
     155             : }
     156             : 
     157           0 : void AxisPositionsTabPage::Reset(const SfxItemSet* rInAttrs)
     158             : {
     159             :     //init and enable controls
     160           0 :     m_pED_CrossesAt->Show( !m_bCrossingAxisIsCategoryAxis );
     161           0 :     m_pED_CrossesAtCategory->Show( m_bCrossingAxisIsCategoryAxis );
     162           0 :     const sal_Int32 nMaxCount = LISTBOX_ENTRY_NOTFOUND;
     163           0 :     if( m_bCrossingAxisIsCategoryAxis )
     164             :     {
     165           0 :         for( sal_Int32 nN=0; nN<m_aCategories.getLength() && nN<nMaxCount; nN++ )
     166           0 :             m_pED_CrossesAtCategory->InsertEntry( m_aCategories[nN] );
     167             : 
     168           0 :         sal_uInt16 nCount = m_pED_CrossesAtCategory->GetEntryCount();
     169           0 :         if( nCount>30 )
     170           0 :             nCount=30;
     171           0 :         m_pED_CrossesAtCategory->SetDropDownLineCount( nCount );
     172             :     }
     173             : 
     174           0 :     if( m_pLB_CrossesAt->GetEntryCount() > 3 )
     175             :     {
     176           0 :         if( m_bCrossingAxisIsCategoryAxis )
     177           0 :             m_pLB_CrossesAt->RemoveEntry(2);
     178             :         else
     179           0 :             m_pLB_CrossesAt->RemoveEntry(3);
     180             :     }
     181             : 
     182             :     //fill controls
     183           0 :     const SfxPoolItem *pPoolItem = NULL;
     184             : 
     185             :     //axis line
     186           0 :     if(rInAttrs->GetItemState(SCHATTR_AXIS_POSITION,true, &pPoolItem)== SfxItemState::SET)
     187             :     {
     188           0 :         bool bZero = false;
     189           0 :         sal_Int32 nPos = static_cast< const SfxInt32Item * >( pPoolItem )->GetValue();
     190           0 :         if(nPos==0)
     191             :         {
     192             :             //switch to value
     193           0 :             bZero = true;
     194           0 :             nPos = 2;
     195             :         }
     196             :         else
     197           0 :             nPos--;
     198             : 
     199           0 :         if( nPos < m_pLB_CrossesAt->GetEntryCount() )
     200           0 :             m_pLB_CrossesAt->SelectEntryPos( nPos );
     201           0 :         CrossesAtSelectHdl( nullptr );
     202             : 
     203           0 :         if( rInAttrs->GetItemState(SCHATTR_AXIS_POSITION_VALUE,true, &pPoolItem)== SfxItemState::SET || bZero )
     204             :         {
     205           0 :             double fCrossover = 0.0;
     206           0 :             if( !bZero )
     207           0 :                 fCrossover = static_cast<const SvxDoubleItem*>(pPoolItem)->GetValue();
     208           0 :             if( m_bCrossingAxisIsCategoryAxis )
     209           0 :                 m_pED_CrossesAtCategory->SelectEntryPos( static_cast<sal_uInt16>(::rtl::math::round(fCrossover-1.0)) );
     210             :             else
     211           0 :                 m_pED_CrossesAt->SetValue(fCrossover);
     212             :         }
     213             :         else
     214             :         {
     215           0 :             m_pED_CrossesAtCategory->SetNoSelection();
     216           0 :             m_pED_CrossesAt->SetTextValue("");
     217             :         }
     218             :     }
     219             :     else
     220             :     {
     221           0 :         m_pLB_CrossesAt->SetNoSelection();
     222           0 :         m_pED_CrossesAt->Enable( false );
     223             :     }
     224             : 
     225             :     // Labels
     226           0 :     if( rInAttrs->GetItemState( SCHATTR_AXIS_LABEL_POSITION, false, &pPoolItem ) == SfxItemState::SET )
     227             :     {
     228           0 :         sal_Int32 nPos = static_cast< const SfxInt32Item * >( pPoolItem )->GetValue();
     229           0 :         if( nPos < m_pLB_PlaceLabels->GetEntryCount() )
     230           0 :             m_pLB_PlaceLabels->SelectEntryPos( nPos );
     231             :     }
     232             :     else
     233           0 :         m_pLB_PlaceLabels->SetNoSelection();
     234           0 :     PlaceLabelsSelectHdl( nullptr );
     235             : 
     236             :     // Tick marks
     237           0 :     long nTicks = 0, nMinorTicks = 0;
     238           0 :     if(rInAttrs->GetItemState(SCHATTR_AXIS_TICKS,true, &pPoolItem)== SfxItemState::SET)
     239           0 :         nTicks = static_cast<const SfxInt32Item*>(pPoolItem)->GetValue();
     240           0 :     if(rInAttrs->GetItemState(SCHATTR_AXIS_HELPTICKS,true, &pPoolItem)== SfxItemState::SET)
     241           0 :         nMinorTicks = static_cast<const SfxInt32Item*>(pPoolItem)->GetValue();
     242             : 
     243           0 :     m_pCB_TicksInner->Check(bool(nTicks&CHAXIS_MARK_INNER));
     244           0 :     m_pCB_TicksOuter->Check(bool(nTicks&CHAXIS_MARK_OUTER));
     245           0 :     m_pCB_MinorInner->Check(bool(nMinorTicks&CHAXIS_MARK_INNER));
     246           0 :     m_pCB_MinorOuter->Check(bool(nMinorTicks&CHAXIS_MARK_OUTER));
     247             : 
     248             :     // Tick position
     249           0 :     if( rInAttrs->GetItemState( SCHATTR_AXIS_MARK_POSITION, false, &pPoolItem ) == SfxItemState::SET )
     250             :     {
     251           0 :         sal_Int32 nPos = static_cast< const SfxInt32Item * >( pPoolItem )->GetValue();
     252           0 :         if( nPos < m_pLB_PlaceTicks->GetEntryCount() )
     253           0 :             m_pLB_PlaceTicks->SelectEntryPos( nPos );
     254             :     }
     255             :     else
     256           0 :         m_pLB_PlaceTicks->SetNoSelection();
     257             : 
     258           0 :     if( !m_bSupportAxisPositioning )
     259             :     {
     260           0 :         m_pFL_AxisLine->Show(false);
     261             : 
     262           0 :         m_pFL_Labels->Show(false);
     263             : 
     264           0 :         m_pBxPlaceTicks->Show(false);
     265             :     }
     266           0 :     else if( !AxisHelper::isAxisPositioningEnabled() )
     267             :     {
     268             : 
     269           0 :         m_pFL_AxisLine->Enable(false);
     270             : 
     271           0 :         m_pFL_Labels->Enable(false);
     272             : 
     273           0 :         m_pBxPlaceTicks->Enable(false);
     274             : 
     275             :         //todo: maybe set a special help id to all those controls
     276             :     }
     277           0 : }
     278             : 
     279           0 : SfxTabPage::sfxpg AxisPositionsTabPage::DeactivatePage(SfxItemSet* pItemSet)
     280             : {
     281           0 :     if( pItemSet )
     282           0 :         FillItemSet( pItemSet );
     283             : 
     284           0 :     return LEAVE_PAGE;
     285             : }
     286             : 
     287           0 : void AxisPositionsTabPage::SetNumFormatter( SvNumberFormatter* pFormatter )
     288             : {
     289           0 :     m_pNumFormatter = pFormatter;
     290           0 :     m_pED_CrossesAt->SetFormatter( m_pNumFormatter );
     291           0 :     m_pED_CrossesAt->UseInputStringForFormatting();
     292             : 
     293           0 :     const SfxPoolItem *pPoolItem = NULL;
     294           0 :     if( GetItemSet().GetItemState( SCHATTR_AXIS_CROSSING_MAIN_AXIS_NUMBERFORMAT, true, &pPoolItem ) == SfxItemState::SET )
     295             :     {
     296           0 :         sal_uLong nFmt = (sal_uLong)static_cast<const SfxInt32Item*>(pPoolItem)->GetValue();
     297           0 :         m_pED_CrossesAt->SetFormatKey( nFmt );
     298             :     }
     299           0 : }
     300             : 
     301           0 : void AxisPositionsTabPage::SetCrossingAxisIsCategoryAxis( bool bCrossingAxisIsCategoryAxis )
     302             : {
     303           0 :     m_bCrossingAxisIsCategoryAxis = bCrossingAxisIsCategoryAxis;
     304           0 : }
     305             : 
     306           0 : void AxisPositionsTabPage::SetCategories( const ::com::sun::star::uno::Sequence< OUString >& rCategories )
     307             : {
     308           0 :     m_aCategories = rCategories;
     309           0 : }
     310             : 
     311           0 : void AxisPositionsTabPage::SupportAxisPositioning( bool bSupportAxisPositioning )
     312             : {
     313           0 :     m_bSupportAxisPositioning = bSupportAxisPositioning;
     314           0 : }
     315             : 
     316           0 : IMPL_LINK_NOARG(AxisPositionsTabPage, CrossesAtSelectHdl)
     317             : {
     318           0 :     sal_Int32 nPos = m_pLB_CrossesAt->GetSelectEntryPos();
     319           0 :     m_pED_CrossesAt->Show( (2==nPos) && !m_bCrossingAxisIsCategoryAxis );
     320           0 :     m_pED_CrossesAtCategory->Show( (2==nPos) && m_bCrossingAxisIsCategoryAxis );
     321             : 
     322           0 :     if( m_pED_CrossesAt->GetText().isEmpty() )
     323           0 :         m_pED_CrossesAt->SetValue(0.0);
     324           0 :     if( 0 == m_pED_CrossesAtCategory->GetSelectEntryCount() )
     325           0 :         m_pED_CrossesAtCategory->SelectEntryPos(0);
     326             : 
     327           0 :     PlaceLabelsSelectHdl( nullptr );
     328           0 :     return 0;
     329             : }
     330             : 
     331           0 : IMPL_LINK_NOARG(AxisPositionsTabPage, PlaceLabelsSelectHdl)
     332             : {
     333           0 :     sal_Int32 nLabelPos = m_pLB_PlaceLabels->GetSelectEntryPos();
     334             : 
     335           0 :     bool bEnableTickmarkPlacement = (nLabelPos>1);
     336           0 :     if( bEnableTickmarkPlacement )
     337             :     {
     338           0 :         sal_Int32 nAxisPos = m_pLB_CrossesAt->GetSelectEntryPos();
     339           0 :         if( nLabelPos-2 == nAxisPos )
     340           0 :             bEnableTickmarkPlacement=false;
     341             :     }
     342           0 :     m_pBxPlaceTicks->Enable(bEnableTickmarkPlacement);
     343             : 
     344           0 :     return 0;
     345             : }
     346             : 
     347          57 : } //namespace chart
     348             : 
     349             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11