LCOV - code coverage report
Current view: top level - svx/source/sidebar/line - LineWidthControl.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 1 183 0.5 %
Date: 2014-11-03 Functions: 2 13 15.4 %
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             : #include "LineWidthControl.hxx"
      20             : #include "LinePropertyPanel.hrc"
      21             : #include "LinePropertyPanel.hxx"
      22             : 
      23             : #include <svx/dialogs.hrc>
      24             : #include <svx/dialmgr.hxx>
      25             : #include <sfx2/sidebar/ResourceDefinitions.hrc>
      26             : #include <comphelper/processfactory.hxx>
      27             : #include <vcl/svapp.hxx>
      28             : #include <vcl/settings.hxx>
      29             : #include <unotools/viewoptions.hxx>
      30             : #include <svx/xlnwtit.hxx>
      31             : #include <sfx2/bindings.hxx>
      32             : #include <sfx2/dispatch.hxx>
      33             : #include "svx/sidebar/PopupContainer.hxx"
      34             : 
      35             : 
      36             : namespace svx { namespace sidebar {
      37             : 
      38           0 : LineWidthControl::LineWidthControl (
      39             :     vcl::Window* pParent,
      40             :     LinePropertyPanel& rPanel)
      41           0 :     : svx::sidebar::PopupControl(pParent,SVX_RES(RID_POPUPPANEL_LINEPAGE_WIDTH)),
      42             :       mrLinePropertyPanel(rPanel),
      43             :       mpBindings(NULL),
      44           0 :       maVSWidth( this, SVX_RES(VS_WIDTH)),
      45           0 :       maFTCus( this, SVX_RES(FT_CUSTOME)),
      46           0 :       maFTWidth( this, SVX_RES(FT_LINE_WIDTH)),
      47           0 :       maMFWidth( this, SVX_RES(MF_WIDTH)),
      48             :       meMapUnit(SFX_MAPUNIT_TWIP),
      49             :       rStr(NULL),
      50           0 :       mstrPT(SVX_RESSTR(STR_PT)),
      51             :       mnCustomWidth(0),
      52             :       mbCustom(false),
      53             :       mbCloseByEdit(false),
      54             :       mnTmpCustomWidth(0),
      55             :       mbVSFocus(true),
      56           0 :       maIMGCus(SVX_RES(IMG_WIDTH_CUSTOM)),
      57           0 :       maIMGCusGray(SVX_RES(IMG_WIDTH_CUSTOM_GRAY))
      58             : {
      59           0 :     Initialize();
      60           0 :     FreeResource();
      61           0 :     mpBindings = mrLinePropertyPanel.GetBindings();
      62           0 : }
      63             : 
      64             : 
      65             : 
      66             : 
      67           0 : LineWidthControl::~LineWidthControl (void)
      68             : {
      69           0 :     delete[] rStr;
      70           0 : }
      71             : 
      72             : 
      73             : 
      74             : 
      75           0 : void LineWidthControl::Paint(const Rectangle& rect)
      76             : {
      77           0 :     svx::sidebar::PopupControl::Paint(rect);
      78             : 
      79           0 :     Color aOldLineColor = GetLineColor();
      80           0 :     Color aOldFillColor = GetFillColor();
      81             : 
      82           0 :     Point aPos( LogicToPixel( Point( CUSTOM_X, CUSTOM_Y), MAP_APPFONT ));
      83           0 :     Size aSize( LogicToPixel( Size(  CUSTOM_W, CUSTOM_H ), MAP_APPFONT ));
      84           0 :     Rectangle aRect( aPos, aSize );
      85           0 :     aRect.Left() -= 1;
      86           0 :     aRect.Top() -= 1;
      87           0 :     aRect.Right() += 1;
      88           0 :     aRect.Bottom() += 1;
      89             : 
      90           0 :     Color aLineColor(189,201,219);
      91           0 :     if(!GetSettings().GetStyleSettings().GetHighContrastMode())
      92           0 :         SetLineColor(aLineColor);
      93             :     else
      94           0 :         SetLineColor(GetSettings().GetStyleSettings().GetShadowColor());
      95           0 :     SetFillColor(COL_TRANSPARENT);
      96           0 :     DrawRect(aRect);
      97             : 
      98           0 :     SetLineColor(aOldLineColor);
      99           0 :     SetFillColor(aOldFillColor);
     100           0 : }
     101             : 
     102             : 
     103             : 
     104             : 
     105           0 : void LineWidthControl::Initialize()
     106             : {
     107           0 :     maVSWidth.SetStyle( maVSWidth.GetStyle()| WB_3DLOOK |  WB_NO_DIRECTSELECT  );// WB_NAMEFIELD | WB_ITEMBORDER |WB_DOUBLEBORDER | WB_NONEFIELD |
     108             :     //for high contrast wj
     109           0 :     if(GetSettings().GetStyleSettings().GetHighContrastMode())
     110             :     {
     111           0 :         maVSWidth.SetColor(GetSettings().GetStyleSettings().GetMenuColor());
     112             :     //  maBorder.SetBackground(GetSettings().GetStyleSettings().GetMenuColor());
     113           0 :         maFTWidth.SetBackground(GetSettings().GetStyleSettings().GetMenuColor());
     114             :     }
     115             :     else
     116             :     {
     117           0 :         maVSWidth.SetColor(COL_WHITE);
     118             :     //  maBorder.SetBackground(Wallpaper(COL_WHITE));
     119           0 :         maFTWidth.SetBackground(Wallpaper(COL_WHITE));
     120             :     }
     121             : 
     122           0 :     sal_Int64 nFirst= maMFWidth.Denormalize( maMFWidth.GetFirst( FUNIT_TWIP ) );
     123           0 :     sal_Int64 nLast = maMFWidth.Denormalize( maMFWidth.GetLast( FUNIT_TWIP ) );
     124           0 :     sal_Int64 nMin = maMFWidth.Denormalize( maMFWidth.GetMin( FUNIT_TWIP ) );
     125           0 :     sal_Int64 nMax = maMFWidth.Denormalize( maMFWidth.GetMax( FUNIT_TWIP ) );
     126           0 :     maMFWidth.SetSpinSize( 10 );
     127           0 :     maMFWidth.SetUnit( FUNIT_POINT );
     128           0 :     if( maMFWidth.GetDecimalDigits() > 1 )
     129           0 :          maMFWidth.SetDecimalDigits( 1 );
     130           0 :     maMFWidth.SetFirst( maMFWidth.Normalize( nFirst ), FUNIT_TWIP );
     131           0 :     maMFWidth.SetLast( maMFWidth.Normalize( nLast ), FUNIT_TWIP );
     132           0 :     maMFWidth.SetMin( maMFWidth.Normalize( nMin ), FUNIT_TWIP );
     133           0 :     maMFWidth.SetMax( maMFWidth.Normalize( nMax ), FUNIT_TWIP );
     134             : 
     135           0 :     rStr = new OUString[9];
     136             :     //modify,
     137           0 :     rStr[0] = "0.5";
     138           0 :     rStr[1] = "0.8";
     139           0 :     rStr[2] = "1.0";
     140           0 :     rStr[3] = "1.5";
     141           0 :     rStr[4] = "2.3";
     142           0 :     rStr[5] = "3.0";
     143           0 :     rStr[6] = "4.5";
     144           0 :     rStr[7] = "6.0";
     145           0 :     rStr[8] = SVX_RESSTR(STR_WIDTH_LAST_CUSTOM);
     146             : 
     147           0 :     const LocaleDataWrapper& rLocaleWrapper( Application::GetSettings().GetLocaleDataWrapper() );
     148           0 :     const sal_Unicode cSep = rLocaleWrapper.getNumDecimalSep()[0];
     149             : 
     150           0 :     for(int i = 0; i <= 7 ; i++)
     151             :     {
     152           0 :         rStr[i] = rStr[i].replace('.', cSep);//Modify
     153           0 :         rStr[i] += mstrPT;
     154             :     }
     155             :     //end
     156             : 
     157           0 :     for(sal_uInt16 i = 1 ; i <= 9 ; i++)
     158             :     {
     159           0 :         maVSWidth.InsertItem(i);
     160           0 :         maVSWidth.SetItemText(i, rStr[i-1]);
     161             :     }
     162           0 :     maVSWidth.SetUnit(rStr);
     163           0 :     maVSWidth.SetItemData(1, reinterpret_cast<void*>(5));
     164           0 :     maVSWidth.SetItemData(2, reinterpret_cast<void*>(8));
     165           0 :     maVSWidth.SetItemData(3, reinterpret_cast<void*>(10));
     166           0 :     maVSWidth.SetItemData(4, reinterpret_cast<void*>(15));
     167           0 :     maVSWidth.SetItemData(5, reinterpret_cast<void*>(23));
     168           0 :     maVSWidth.SetItemData(6, reinterpret_cast<void*>(30));
     169           0 :     maVSWidth.SetItemData(7, reinterpret_cast<void*>(45));
     170           0 :     maVSWidth.SetItemData(8, reinterpret_cast<void*>(60));
     171           0 :     maVSWidth.SetImage(maIMGCusGray);
     172             : 
     173           0 :     maVSWidth.SetSelItem(0);
     174           0 :     Link aLink =  LINK( this, LineWidthControl, VSSelectHdl ) ;
     175           0 :     maVSWidth.SetSelectHdl(aLink);
     176           0 :     aLink = LINK(this, LineWidthControl, MFModifyHdl);
     177           0 :     maMFWidth.SetModifyHdl(aLink);
     178             : 
     179           0 :     maVSWidth.StartSelection();
     180           0 :     maVSWidth.Show();
     181           0 : }
     182             : 
     183             : 
     184             : 
     185             : 
     186           0 : void LineWidthControl::GetFocus()
     187             : {
     188           0 :     if(!mbVSFocus)
     189           0 :         maMFWidth.GrabFocus();
     190             :     else
     191           0 :         maVSWidth.GrabFocus();
     192           0 : }
     193             : 
     194             : 
     195             : 
     196             : 
     197           0 : void LineWidthControl::SetWidthSelect( long lValue, bool bValuable, SfxMapUnit eMapUnit)
     198             : {
     199           0 :     mbVSFocus = true;
     200           0 :     maVSWidth.SetSelItem(0);
     201           0 :     mbCloseByEdit = false;
     202           0 :     meMapUnit = eMapUnit;
     203           0 :     SvtViewOptions aWinOpt( E_WINDOW, SIDEBAR_LINE_WIDTH_GLOBAL_VALUE );
     204           0 :     if ( aWinOpt.Exists() )
     205             :     {
     206           0 :         ::com::sun::star::uno::Sequence < ::com::sun::star::beans::NamedValue > aSeq = aWinOpt.GetUserData();
     207           0 :         ::rtl::OUString aTmp;
     208           0 :         if ( aSeq.getLength())
     209           0 :             aSeq[0].Value >>= aTmp;
     210             : 
     211           0 :         OUString aWinData( aTmp );
     212           0 :         mnCustomWidth = aWinData.toInt32();
     213           0 :         mbCustom = true;
     214           0 :         maVSWidth.SetImage(maIMGCus);
     215           0 :         maVSWidth.SetCusEnable(true);
     216             : 
     217           0 :         OUString aStrTip( OUString::number( (double)mnCustomWidth / 10));
     218           0 :         aStrTip += mstrPT;
     219           0 :         maVSWidth.SetItemText(9, aStrTip);
     220             :     }
     221             :     else
     222             :     {
     223           0 :         mbCustom = false;
     224           0 :         maVSWidth.SetImage(maIMGCusGray);
     225           0 :         maVSWidth.SetCusEnable(false);
     226             :         //modify
     227             :         //String aStrTip(String(SVX_RES(STR_WIDTH_LAST_CUSTOM)));
     228             :         //maVSWidth.SetItemText(9, aStrTip);
     229           0 :         maVSWidth.SetItemText(9, rStr[8]);
     230             :     }
     231             : 
     232           0 :     if(bValuable)
     233             :     {
     234           0 :         sal_Int64 nVal = OutputDevice::LogicToLogic( lValue, (MapUnit)eMapUnit, MAP_100TH_MM );
     235           0 :         nVal = maMFWidth.Normalize( nVal );
     236           0 :         maMFWidth.SetValue( nVal, FUNIT_100TH_MM );
     237             :     }
     238             :     else
     239             :     {
     240           0 :         maMFWidth.SetText( "" );
     241             :     }
     242             : 
     243           0 :     MapUnit eOrgUnit = (MapUnit)eMapUnit;
     244           0 :     MapUnit ePntUnit( MAP_TWIP );
     245           0 :     lValue = LogicToLogic( lValue , eOrgUnit, ePntUnit );
     246             : 
     247           0 :     OUString strCurrValue = maMFWidth.GetText();
     248           0 :     sal_uInt16 i = 0;
     249           0 :     for(; i < 8; i++)
     250           0 :         if(strCurrValue == rStr[i])
     251             :         {
     252           0 :             maVSWidth.SetSelItem(i+1);
     253           0 :             break;
     254             :         }
     255           0 :     if (i>=8)
     256             :     {
     257           0 :         mbVSFocus = false;
     258           0 :         maVSWidth.SetSelItem(0);
     259             :     }
     260           0 :     maVSWidth.Format();
     261           0 :     maVSWidth.StartSelection();
     262           0 : }
     263             : 
     264             : 
     265             : 
     266             : 
     267           0 : IMPL_LINK(LineWidthControl, VSSelectHdl, void *, pControl)
     268             : {
     269           0 :     if(pControl == &maVSWidth)
     270             :     {
     271           0 :         sal_uInt16 iPos = maVSWidth.GetSelectItemId();
     272           0 :         if(iPos >= 1 && iPos <= 8)
     273             :         {
     274           0 :             sal_IntPtr nVal = LogicToLogic(reinterpret_cast<sal_IntPtr>(maVSWidth.GetItemData( iPos )), MAP_POINT, (MapUnit)meMapUnit);
     275           0 :             nVal = maMFWidth.Denormalize(nVal);
     276           0 :             XLineWidthItem aWidthItem( nVal );
     277           0 :             mpBindings->GetDispatcher()->Execute(SID_ATTR_LINE_WIDTH, SfxCallMode::RECORD, &aWidthItem, 0L);
     278           0 :             mrLinePropertyPanel.SetWidthIcon(iPos);
     279           0 :             mrLinePropertyPanel.SetWidth(nVal);
     280           0 :             mbCloseByEdit = false;
     281           0 :             mnTmpCustomWidth = 0;
     282             :         }
     283           0 :         else if(iPos == 9)
     284             :         {//last custom
     285             :             //modified
     286           0 :             if(mbCustom)
     287             :             {
     288           0 :                 long nVal = LogicToLogic(mnCustomWidth , MAP_POINT, (MapUnit)meMapUnit);
     289           0 :                 nVal = maMFWidth.Denormalize(nVal);
     290           0 :                 XLineWidthItem aWidthItem( nVal );
     291           0 :                 mpBindings->GetDispatcher()->Execute(SID_ATTR_LINE_WIDTH, SfxCallMode::RECORD, &aWidthItem, 0L);
     292           0 :                 mrLinePropertyPanel.SetWidth(nVal);
     293           0 :                 mbCloseByEdit = false;
     294           0 :                 mnTmpCustomWidth = 0;
     295             :             }
     296             :             else
     297             :             {
     298           0 :                 maVSWidth.SetNoSelection();     //add , set no selection and keep the last select item
     299           0 :                 maVSWidth.Format();
     300           0 :                 Invalidate();
     301           0 :                 maVSWidth.StartSelection();
     302             :             }
     303             :             //modify end
     304             :         }
     305           0 :         if((iPos >= 1 && iPos <= 8) || (iPos == 9 && mbCustom)) //add
     306           0 :             mrLinePropertyPanel.EndLineWidthPopupMode();
     307             :     }
     308           0 :     return( 0L );
     309             : }
     310             : 
     311             : 
     312             : 
     313             : 
     314           0 : IMPL_LINK(LineWidthControl, MFModifyHdl, void *, pControl)
     315             : {
     316           0 :     if(pControl == &maMFWidth)
     317             :     {
     318           0 :         if(maVSWidth.GetSelItem())
     319             :         {
     320           0 :             maVSWidth.SetSelItem(0);
     321           0 :             maVSWidth.Format();
     322           0 :             Invalidate();
     323           0 :             maVSWidth.StartSelection();
     324             :         }
     325           0 :         long nTmp = static_cast<long>(maMFWidth.GetValue());
     326           0 :         long nVal = LogicToLogic( nTmp, MAP_POINT, (MapUnit)meMapUnit );
     327           0 :         sal_Int32 nNewWidth = (short)maMFWidth.Denormalize( nVal );
     328           0 :         XLineWidthItem aWidthItem(nNewWidth);
     329           0 :         mpBindings->GetDispatcher()->Execute(SID_ATTR_LINE_WIDTH, SfxCallMode::RECORD, &aWidthItem, 0L);
     330             : 
     331           0 :         mbCloseByEdit = true;
     332           0 :         mnTmpCustomWidth = nTmp;
     333             :     }
     334           0 :     return( 0L );
     335             : }
     336             : 
     337         594 : } } // end of namespace svx::sidebar
     338             : 
     339             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10