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

Generated by: LCOV version 1.10