LCOV - code coverage report
Current view: top level - sc/source/ui/sidebar - AlignmentPropertyPanel.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 103 177 58.2 %
Date: 2015-06-13 12:38:46 Functions: 8 20 40.0 %
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 "AlignmentPropertyPanel.hxx"
      21             : #include <editeng/justifyitem.hxx>
      22             : #include "sc.hrc"
      23             : #include "scresid.hxx"
      24             : #include <sfx2/bindings.hxx>
      25             : #include <sfx2/dispatch.hxx>
      26             : #include <svx/algitem.hxx>
      27             : #include <svx/dlgutil.hxx>
      28             : #include <vcl/toolbox.hxx>
      29             : #include <svx/sidebar/SidebarDialControl.hxx>
      30             : 
      31             : using namespace css;
      32             : using namespace css::uno;
      33             : 
      34             : // namespace open
      35             : 
      36             : namespace sc { namespace sidebar {
      37             : 
      38         176 : AlignmentPropertyPanel::AlignmentPropertyPanel(
      39             :     vcl::Window* pParent,
      40             :     const css::uno::Reference<css::frame::XFrame>& rxFrame,
      41             :     SfxBindings* pBindings)
      42             :     : PanelLayout(pParent, "AlignmentPropertyPanel", "modules/scalc/ui/sidebaralignment.ui", rxFrame),
      43             :       maAlignHorControl(SID_H_ALIGNCELL, *pBindings, *this),
      44             :       maLeftIndentControl(SID_ATTR_ALIGN_INDENT, *pBindings, *this),
      45             :       maMergeCellControl(FID_MERGE_TOGGLE, *pBindings, *this),
      46             :       maWrapTextControl(SID_ATTR_ALIGN_LINEBREAK, *pBindings, *this),
      47             :       maAngleControl(SID_ATTR_ALIGN_DEGREES, *pBindings, *this),
      48             :       mbMultiDisable(false),
      49             :       mxFrame(rxFrame),
      50             :       maContext(),
      51         201 :       mpBindings(pBindings)
      52             : {
      53         151 :     get(mpFTLeftIndent, "leftindentlabel");
      54         151 :     get(mpMFLeftIndent, "leftindent");
      55         151 :     get(mpCBXWrapText, "wraptext");
      56         151 :     get(mpCBXMergeCell, "mergecells");
      57         151 :     get(mpFtRotate, "orientationlabel");
      58         151 :     get(mpMtrAngle, "orientationdegrees");
      59             : 
      60         151 :     Initialize();
      61             : 
      62         151 :     mpFTLeftIndent->SetBackground(Wallpaper());
      63         151 :     mpFtRotate->SetBackground(Wallpaper());
      64         151 : }
      65             : 
      66           0 : AlignmentPropertyPanel::~AlignmentPropertyPanel()
      67             : {
      68           0 :     disposeOnce();
      69           0 : }
      70             : 
      71         151 : void AlignmentPropertyPanel::dispose()
      72             : {
      73         151 :     mpFTLeftIndent.clear();
      74         151 :     mpMFLeftIndent.clear();
      75         151 :     mpCBXWrapText.clear();
      76         151 :     mpCBXMergeCell.clear();
      77         151 :     mpFtRotate.clear();
      78         151 :     mpMtrAngle.clear();
      79             : 
      80         151 :     maAlignHorControl.dispose();
      81         151 :     maLeftIndentControl.dispose();
      82         151 :     maMergeCellControl.dispose();
      83         151 :     maWrapTextControl.dispose();
      84         151 :     maAngleControl.dispose();
      85             : 
      86         151 :     PanelLayout::dispose();
      87         151 : }
      88             : 
      89         151 : void AlignmentPropertyPanel::Initialize()
      90             : {
      91         151 :     mpFTLeftIndent->Disable();
      92         151 :     mpMFLeftIndent->Disable();
      93         151 :     mpMFLeftIndent->SetAccessibleName(OUString( "Left Indent"));    //wj acc
      94         151 :     Link<> aLink = LINK(this, AlignmentPropertyPanel, MFLeftIndentMdyHdl);
      95         151 :     mpMFLeftIndent->SetModifyHdl ( aLink );
      96             : 
      97         151 :     aLink = LINK(this, AlignmentPropertyPanel, CBOXMergnCellClkHdl);
      98         151 :     mpCBXMergeCell->SetClickHdl ( aLink );
      99             : 
     100         151 :     aLink = LINK(this, AlignmentPropertyPanel, CBOXWrapTextClkHdl);
     101         151 :     mpCBXWrapText->SetClickHdl ( aLink );
     102             : 
     103             :     //rotation control
     104             : 
     105             :     //rotation
     106         151 :     mpMtrAngle->SetAccessibleName(OUString( "Text Orientation"));   //wj acc
     107         151 :     mpMtrAngle->SetModifyHdl(LINK( this, AlignmentPropertyPanel, AngleModifiedHdl));
     108         151 :     mpMtrAngle->EnableAutocomplete( false );
     109             : 
     110             :     //Vertical stacked
     111             : 
     112         151 :     mpMtrAngle->InsertValue(0, FUNIT_CUSTOM);
     113         151 :     mpMtrAngle->InsertValue(45, FUNIT_CUSTOM);
     114         151 :     mpMtrAngle->InsertValue(90, FUNIT_CUSTOM);
     115         151 :     mpMtrAngle->InsertValue(135, FUNIT_CUSTOM);
     116         151 :     mpMtrAngle->InsertValue(180, FUNIT_CUSTOM);
     117         151 :     mpMtrAngle->InsertValue(225, FUNIT_CUSTOM);
     118         151 :     mpMtrAngle->InsertValue(270, FUNIT_CUSTOM);
     119         151 :     mpMtrAngle->InsertValue(315, FUNIT_CUSTOM);
     120         151 :     mpMtrAngle->SetDropDownLineCount(mpMtrAngle->GetEntryCount());
     121             : 
     122         151 :     mpMFLeftIndent->SetAccessibleRelationLabeledBy(mpFTLeftIndent);
     123         151 :     mpMtrAngle->SetAccessibleRelationLabeledBy(mpFtRotate);
     124         151 : }
     125             : 
     126           0 : IMPL_LINK_NOARG( AlignmentPropertyPanel, AngleModifiedHdl )
     127             : {
     128           0 :     OUString sTmp = mpMtrAngle->GetText();
     129           0 :     if (sTmp.isEmpty())
     130           0 :         return 0;
     131           0 :     sal_Unicode nChar = sTmp[0];
     132           0 :     if( nChar == '-' )
     133             :     {
     134           0 :         if (sTmp.getLength() < 2)
     135           0 :             return 0;
     136           0 :         nChar = sTmp[1];
     137             :     }
     138             : 
     139           0 :     if( (nChar < '0') || (nChar > '9') )
     140           0 :         return 0;
     141             : 
     142           0 :     const LocaleDataWrapper& rLocaleWrapper( Application::GetSettings().GetLocaleDataWrapper() );
     143           0 :     const sal_Unicode cSep = rLocaleWrapper.getNumDecimalSep()[0];
     144             : 
     145             :     // Do not check that the entire string was parsed up to its end, there may
     146             :     // be a degree symbol following the number. Note that this also means that
     147             :     // the number recognized just stops at any non-matching character.
     148             :     /* TODO: we could check for the degree symbol stop if there are no other
     149             :      * cases with different symbol characters in any language? */
     150             :     rtl_math_ConversionStatus eStatus;
     151           0 :     double fTmp = rtl::math::stringToDouble( sTmp, cSep, 0, &eStatus);
     152           0 :     if (eStatus != rtl_math_ConversionStatus_Ok)
     153           0 :         return 0;
     154             : 
     155           0 :     FormatDegrees(fTmp);
     156             : 
     157           0 :     sal_Int64 nTmp = (sal_Int64)fTmp*100;
     158           0 :     SfxInt32Item aAngleItem( SID_ATTR_ALIGN_DEGREES,(sal_uInt32) nTmp);
     159             : 
     160             :     GetBindings()->GetDispatcher()->Execute(
     161           0 :         SID_ATTR_ALIGN_DEGREES, SfxCallMode::RECORD, &aAngleItem, 0L );
     162           0 :     return 0;
     163             : }
     164           0 : IMPL_LINK_NOARG(AlignmentPropertyPanel, MFLeftIndentMdyHdl)
     165             : {
     166           0 :     mpCBXWrapText->EnableTriState(false);
     167           0 :     sal_uInt16 nVal = (sal_uInt16)mpMFLeftIndent->GetValue();
     168           0 :     SfxUInt16Item aItem( SID_ATTR_ALIGN_INDENT,  (sal_uInt16)CalcToUnit( nVal,  SFX_MAPUNIT_TWIP ) );
     169             : 
     170           0 :     GetBindings()->GetDispatcher()->Execute(SID_ATTR_ALIGN_INDENT, SfxCallMode::RECORD, &aItem, 0L);
     171           0 :     return 0L;
     172             : }
     173             : 
     174           0 : IMPL_LINK_NOARG(AlignmentPropertyPanel, CBOXMergnCellClkHdl)
     175             : {
     176           0 :     bool bState = mpCBXMergeCell->IsChecked();
     177             : 
     178             :     //Modified
     179             :     //SfxBoolItem aItem( FID_MERGE_TOGGLE , bState);
     180             :     //GetBindings()->GetDispatcher()->Execute(FID_MERGE_TOGGLE, SfxCallMode::RECORD, &aItem, false, 0L);
     181           0 :     if(bState)
     182           0 :         GetBindings()->GetDispatcher()->Execute(FID_MERGE_ON, SfxCallMode::RECORD);
     183             :     else
     184           0 :         GetBindings()->GetDispatcher()->Execute(FID_MERGE_OFF, SfxCallMode::RECORD);
     185           0 :     GetBindings()->Invalidate(FID_MERGE_TOGGLE,true,false);
     186             :     //modified end
     187             : 
     188           0 :     return 0;
     189             : }
     190             : 
     191           0 : IMPL_LINK_NOARG(AlignmentPropertyPanel, CBOXWrapTextClkHdl)
     192             : {
     193           0 :     bool bState = mpCBXWrapText->IsChecked();
     194           0 :     SfxBoolItem aItem( SID_ATTR_ALIGN_LINEBREAK , bState);
     195           0 :     GetBindings()->GetDispatcher()->Execute(SID_ATTR_ALIGN_LINEBREAK, SfxCallMode::RECORD, &aItem, 0L);
     196           0 :     return 0;
     197             : }
     198             : 
     199         176 : VclPtr<vcl::Window> AlignmentPropertyPanel::Create (
     200             :     vcl::Window* pParent,
     201             :     const css::uno::Reference<css::frame::XFrame>& rxFrame,
     202             :     SfxBindings* pBindings)
     203             : {
     204         176 :     if (pParent == NULL)
     205           0 :         throw lang::IllegalArgumentException("no parent Window given to AlignmentPropertyPanel::Create", NULL, 0);
     206         176 :     if ( ! rxFrame.is())
     207           0 :         throw lang::IllegalArgumentException("no XFrame given to AlignmentPropertyPanel::Create", NULL, 1);
     208         176 :     if (pBindings == NULL)
     209           0 :         throw lang::IllegalArgumentException("no SfxBindings given to AlignmentPropertyPanel::Create", NULL, 2);
     210             : 
     211             :     return  VclPtr<AlignmentPropertyPanel>::Create(
     212         176 :                         pParent, rxFrame, pBindings);
     213             : }
     214             : 
     215           0 : void AlignmentPropertyPanel::DataChanged(
     216             :     const DataChangedEvent& rEvent)
     217             : {
     218             :     (void)rEvent;
     219           0 : }
     220             : 
     221         165 : void AlignmentPropertyPanel::HandleContextChange(
     222             :     const ::sfx2::sidebar::EnumContext& rContext)
     223             : {
     224         165 :     if (maContext == rContext)
     225             :     {
     226             :         // Nothing to do.
     227         165 :         return;
     228             :     }
     229             : 
     230         165 :     maContext = rContext;
     231             : }
     232             : 
     233         342 : void AlignmentPropertyPanel::NotifyItemUpdate(
     234             :     sal_uInt16 nSID,
     235             :     SfxItemState eState,
     236             :     const SfxPoolItem* pState,
     237             :     const bool bIsEnabled)
     238             : {
     239             :     (void)bIsEnabled;
     240             : 
     241         342 :     switch(nSID)
     242             :     {
     243             :     case SID_H_ALIGNCELL:
     244             :         {
     245          36 :             SvxCellHorJustify meHorAlignState = SVX_HOR_JUSTIFY_STANDARD;
     246          36 :             if(eState >= SfxItemState::DEFAULT && pState && pState->ISA(SvxHorJustifyItem) )
     247             :             {
     248          31 :                 const SvxHorJustifyItem* pItem = static_cast<const SvxHorJustifyItem*>(pState);
     249          31 :                 meHorAlignState = (SvxCellHorJustify)pItem->GetValue();
     250             :             }
     251             : 
     252          36 :             if( meHorAlignState == SVX_HOR_JUSTIFY_REPEAT )
     253             :             {
     254           0 :                 mpFtRotate->Disable();
     255           0 :                 mpMtrAngle->Disable();
     256             :             }
     257             :             else
     258             :             {
     259          36 :                 mpFtRotate->Enable(!mbMultiDisable);
     260          36 :                 mpMtrAngle->Enable(!mbMultiDisable);
     261             :             }
     262             : 
     263          36 :             mpFTLeftIndent->Enable( meHorAlignState == SVX_HOR_JUSTIFY_LEFT );
     264          36 :             mpMFLeftIndent->Enable( meHorAlignState == SVX_HOR_JUSTIFY_LEFT );
     265             :         }
     266          36 :         break;
     267             :     case SID_ATTR_ALIGN_INDENT:
     268          90 :         if(eState >= SfxItemState::DEFAULT && pState && pState->ISA(SfxUInt16Item) )
     269             :         {
     270          85 :                 const SfxUInt16Item* pItem = static_cast<const SfxUInt16Item*>(pState);
     271          85 :                 sal_uInt16 nVal = pItem->GetValue();
     272          85 :                 mpMFLeftIndent->SetValue( CalcToPoint(nVal, SFX_MAPUNIT_TWIP, 1) );
     273             :         }
     274             :         else
     275             :         {
     276           5 :             mpMFLeftIndent->SetValue(0);
     277           5 :             mpMFLeftIndent->SetText(OUString());
     278             :         }
     279          90 :         break;
     280             :     case FID_MERGE_TOGGLE:
     281          36 :         if(eState >= SfxItemState::DEFAULT && pState && pState->ISA(SfxBoolItem) )
     282             :         {
     283           0 :             mpCBXMergeCell->Enable();
     284           0 :             const SfxBoolItem* pItem = static_cast<const SfxBoolItem*>(pState);
     285           0 :             mpCBXMergeCell->Check(pItem->GetValue());
     286             :         }
     287             :         else
     288             :         {
     289          36 :             mpCBXMergeCell->Check(false);
     290          36 :             mpCBXMergeCell->Disable();
     291             :         }
     292          36 :         break;
     293             : 
     294             :     case SID_ATTR_ALIGN_LINEBREAK:
     295          90 :         if(eState == SfxItemState::DISABLED)
     296             :         {
     297           5 :             mpCBXWrapText->EnableTriState(false);
     298           5 :             mpCBXWrapText->Check(false);
     299           5 :             mpCBXWrapText->Disable();
     300             :         }
     301             :         else
     302             :         {
     303          85 :             mpCBXWrapText->Enable();
     304          85 :             if(eState >= SfxItemState::DEFAULT && pState && pState->ISA(SfxBoolItem) )
     305             :             {
     306          85 :                 mpCBXWrapText->EnableTriState(false);
     307          85 :                 const SfxBoolItem* pItem = static_cast<const SfxBoolItem*>(pState);
     308          85 :                 mpCBXWrapText->Check(pItem->GetValue());
     309             :             }
     310           0 :             else if(eState == SfxItemState::DONTCARE)
     311             :             {
     312           0 :                 mpCBXWrapText->EnableTriState(true);
     313           0 :                 mpCBXWrapText->SetState(TRISTATE_INDET);
     314             :             }
     315             :         }
     316          90 :         break;
     317             :     case SID_ATTR_ALIGN_DEGREES:
     318          90 :         if (eState >= SfxItemState::DEFAULT)
     319             :         {
     320          85 :             long nTmp = static_cast<const SfxInt32Item*>(pState)->GetValue();
     321          85 :             mpMtrAngle->SetValue( nTmp / 100);  //wj
     322          85 :             switch(nTmp)
     323             :             {
     324             :                 case 0:
     325          85 :                     mpMtrAngle->SelectEntryPos(0);
     326          85 :                 break;
     327             :                 case 4500:
     328           0 :                     mpMtrAngle->SelectEntryPos(1);
     329           0 :                 break;
     330             :                 case 9000:
     331           0 :                     mpMtrAngle->SelectEntryPos(2);
     332           0 :                 break;
     333             :                 case 13500:
     334           0 :                     mpMtrAngle->SelectEntryPos(3);
     335           0 :                 break;
     336             :                 case 18000:
     337           0 :                     mpMtrAngle->SelectEntryPos(4);
     338           0 :                 break;
     339             :                 case 22500:
     340           0 :                     mpMtrAngle->SelectEntryPos(5);
     341           0 :                 break;
     342             :                 case 27000:
     343           0 :                     mpMtrAngle->SelectEntryPos(6);
     344           0 :                 break;
     345             :                 case 31500:
     346           0 :                     mpMtrAngle->SelectEntryPos(7);
     347             :             }
     348             :         }
     349             :         else
     350             :         {
     351           5 :             mpMtrAngle->SetText( OUString() );
     352             :         }
     353          90 :         break;
     354             :     }
     355         342 : }
     356             : 
     357           0 : void AlignmentPropertyPanel::FormatDegrees(double& dTmp)
     358             : {
     359           0 :     while(dTmp<0)
     360           0 :         dTmp += 360;
     361           0 :     while (dTmp > 359)  //modify
     362           0 :         dTmp = 359;
     363           0 : }
     364             : 
     365             : // namespace close
     366             : 
     367         156 : }} // end of namespace ::sc::sidebar
     368             : 
     369             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11