LCOV - code coverage report
Current view: top level - svx/source/sidebar/text - TextPropertyPanel.cxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 131 0.0 %
Date: 2014-04-14 Functions: 0 23 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /*
       2             :  * This file is part of the LibreOffice project.
       3             :  *
       4             :  * This Source Code Form is subject to the terms of the Mozilla Public
       5             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       6             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       7             :  *
       8             :  * This file incorporates work covered by the following license notice:
       9             :  *
      10             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      11             :  *   contributor license agreements. See the NOTICE file distributed
      12             :  *   with this work for additional information regarding copyright
      13             :  *   ownership. The ASF licenses this file to you under the Apache
      14             :  *   License, Version 2.0 (the "License"); you may not use this file
      15             :  *   except in compliance with the License. You may obtain a copy of
      16             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      17             :  */
      18             : 
      19             : #include "TextPropertyPanel.hrc"
      20             : #include "TextPropertyPanel.hxx"
      21             : 
      22             : #include <editeng/kernitem.hxx>
      23             : #include <editeng/udlnitem.hxx>
      24             : #include <rtl/ref.hxx>
      25             : #include <sfx2/dispatch.hxx>
      26             : #include <svtools/unitconv.hxx>
      27             : 
      28             : #include <vcl/toolbox.hxx>
      29             : #include "TextCharacterSpacingControl.hxx"
      30             : #include "TextCharacterSpacingPopup.hxx"
      31             : #include "TextUnderlineControl.hxx"
      32             : #include "TextUnderlinePopup.hxx"
      33             : #include <svx/sidebar/PopupContainer.hxx>
      34             : 
      35             : #include <boost/bind.hpp>
      36             : 
      37             : using namespace css;
      38             : using namespace cssu;
      39             : 
      40             : const char UNO_SPACING[] = ".uno:Spacing";
      41             : const char UNO_UNDERLINE[] = ".uno:Underline";
      42             : 
      43             : namespace svx { namespace sidebar {
      44             : 
      45           0 : PopupControl* TextPropertyPanel::CreateCharacterSpacingControl (PopupContainer* pParent)
      46             : {
      47           0 :     return new TextCharacterSpacingControl(pParent, *this, mpBindings);
      48             : }
      49             : 
      50           0 : PopupControl* TextPropertyPanel::CreateUnderlinePopupControl (PopupContainer* pParent)
      51             : {
      52           0 :     return new TextUnderlineControl(pParent, *this, mpBindings);
      53             : }
      54             : 
      55           0 : long TextPropertyPanel::GetSelFontSize()
      56             : {
      57           0 :     long nH = 240;
      58           0 :     SfxMapUnit eUnit = maSpacingControl.GetCoreMetric();
      59           0 :     if (mpHeightItem)
      60           0 :         nH = LogicToLogic(  mpHeightItem->GetHeight(), (MapUnit)eUnit, MAP_TWIP );
      61           0 :     return nH;
      62             : }
      63             : 
      64           0 : TextPropertyPanel* TextPropertyPanel::Create (
      65             :     Window* pParent,
      66             :     const cssu::Reference<css::frame::XFrame>& rxFrame,
      67             :     SfxBindings* pBindings,
      68             :     const ::sfx2::sidebar::EnumContext& rContext)
      69             : {
      70           0 :     if (pParent == NULL)
      71           0 :         throw lang::IllegalArgumentException("no parent Window given to TextPropertyPanel::Create", NULL, 0);
      72           0 :     if ( ! rxFrame.is())
      73           0 :         throw lang::IllegalArgumentException("no XFrame given to TextPropertyPanel::Create", NULL, 1);
      74           0 :     if (pBindings == NULL)
      75           0 :         throw lang::IllegalArgumentException("no SfxBindings given to TextPropertyPanel::Create", NULL, 2);
      76             : 
      77             :     return new TextPropertyPanel(
      78             :         pParent,
      79             :         rxFrame,
      80             :         pBindings,
      81           0 :         rContext);
      82             : }
      83             : 
      84           0 : ::sfx2::sidebar::ControllerItem& TextPropertyPanel::GetSpaceController()
      85             : {
      86           0 :     return maSpacingControl;
      87             : }
      88             : 
      89           0 : TextPropertyPanel::TextPropertyPanel ( Window* pParent, const cssu::Reference<css::frame::XFrame>& rxFrame, SfxBindings* pBindings, const ::sfx2::sidebar::EnumContext& /*rContext*/ )
      90             :     : PanelLayout(pParent, "SidebarTextPanel", "svx/ui/sidebartextpanel.ui", rxFrame),
      91             :         maFontSizeControl   (SID_ATTR_CHAR_FONTHEIGHT,  *pBindings, *this, OUString("FontHeight"),   rxFrame),
      92             :         maUnderlineControl  (SID_ATTR_CHAR_UNDERLINE,   *pBindings, *this, OUString("Underline"),    rxFrame),
      93             :         maSpacingControl    (SID_ATTR_CHAR_KERNING,     *pBindings, *this, OUString("Spacing"),      rxFrame),
      94             : 
      95             :         maCharSpacePopup(this, ::boost::bind(&TextPropertyPanel::CreateCharacterSpacingControl, this, _1)),
      96             :         maUnderlinePopup(this, ::boost::bind(&TextPropertyPanel::CreateUnderlinePopupControl, this, _1)),
      97             :         maContext(),
      98           0 :         mpBindings(pBindings)
      99             : {
     100           0 :     get(mpToolBoxFont, "fonteffects");
     101           0 :     get(mpToolBoxIncDec, "fontadjust");
     102           0 :     get(mpToolBoxSpacing, "spacingbar");
     103           0 :     get(mpToolBoxFontColorSw, "colorbar");
     104           0 :     get(mpToolBoxFontColor, "colorsingle");
     105             : 
     106             :     //toolbox
     107           0 :     SetupToolboxItems();
     108           0 :     InitToolBoxFont();
     109           0 :     InitToolBoxSpacing();
     110             : 
     111             :     //init state
     112           0 :     mpHeightItem = NULL;
     113           0 :     meUnderline = UNDERLINE_NONE;
     114           0 :     meUnderlineColor = COL_AUTO;
     115           0 :     mbKernAvailable = true;
     116           0 :     mbKernLBAvailable = true;
     117           0 :     mlKerning = 0;
     118           0 : }
     119             : 
     120           0 : TextPropertyPanel::~TextPropertyPanel (void)
     121             : {
     122           0 : }
     123             : 
     124           0 : void TextPropertyPanel::HandleContextChange (
     125             :     const ::sfx2::sidebar::EnumContext aContext)
     126             : {
     127           0 :     if (maContext == aContext)
     128           0 :         return;
     129             : 
     130           0 :     maContext = aContext;
     131             : 
     132           0 :     if (maContext.GetApplication_DI() == sfx2::sidebar::EnumContext::Application_Calc)
     133           0 :         mpToolBoxIncDec->Hide();
     134             :     else
     135           0 :         mpToolBoxIncDec->Show();
     136             : 
     137           0 :     bool bWriterText = false;
     138           0 :     switch (maContext.GetCombinedContext_DI())
     139             :     {
     140             :         case CombinedEnumContext(Application_Calc, Context_Cell):
     141             :         case CombinedEnumContext(Application_Calc, Context_Pivot):
     142           0 :             mpToolBoxSpacing->Disable();
     143           0 :             break;
     144             : 
     145             :         case CombinedEnumContext(Application_Calc, Context_EditCell):
     146             :         case CombinedEnumContext(Application_Calc, Context_DrawText):
     147             :         case CombinedEnumContext(Application_WriterVariants, Context_DrawText):
     148             :         case CombinedEnumContext(Application_WriterVariants, Context_Annotation):
     149             :         case CombinedEnumContext(Application_DrawImpress, Context_DrawText):
     150             :         case CombinedEnumContext(Application_DrawImpress, Context_Text):
     151             :         case CombinedEnumContext(Application_DrawImpress, Context_Table):
     152             :         case CombinedEnumContext(Application_DrawImpress, Context_OutlineText):
     153             :         case CombinedEnumContext(Application_DrawImpress, Context_Draw):
     154             :         case CombinedEnumContext(Application_DrawImpress, Context_TextObject):
     155             :         case CombinedEnumContext(Application_DrawImpress, Context_Graphic):
     156           0 :             mpToolBoxSpacing->Enable();
     157           0 :             break;
     158             : 
     159             :         case CombinedEnumContext(Application_WriterVariants, Context_Text):
     160             :         case CombinedEnumContext(Application_WriterVariants, Context_Table):
     161           0 :             mpToolBoxSpacing->Enable();
     162           0 :             bWriterText = true;
     163           0 :             break;
     164             : 
     165             :         default:
     166           0 :             break;
     167             :     }
     168             : 
     169           0 :     mpToolBoxFontColor->Show(!bWriterText);
     170           0 :     mpToolBoxFontColorSw->Show(bWriterText);
     171             : }
     172             : 
     173           0 : void TextPropertyPanel::DataChanged (const DataChangedEvent& /*rEvent*/)
     174             : {
     175           0 :     SetupToolboxItems();
     176           0 : }
     177             : 
     178           0 : void TextPropertyPanel::EndSpacingPopupMode (void)
     179             : {
     180           0 :     maCharSpacePopup.Hide();
     181           0 : }
     182             : 
     183           0 : void TextPropertyPanel::EndUnderlinePopupMode (void)
     184             : {
     185           0 :     maUnderlinePopup.Hide();
     186           0 : }
     187             : 
     188           0 : void TextPropertyPanel::InitToolBoxFont()
     189             : {
     190           0 :     Link aLink = LINK(this, TextPropertyPanel, UnderlineClickHdl);
     191           0 :     mpToolBoxFont->SetDropdownClickHdl(aLink);
     192           0 : }
     193             : 
     194           0 : void TextPropertyPanel::InitToolBoxSpacing()
     195             : {
     196           0 :     const sal_uInt16 nId = mpToolBoxSpacing->GetItemId(UNO_SPACING);
     197           0 :     mpToolBoxSpacing->SetItemBits(nId, mpToolBoxSpacing->GetItemBits(nId) | TIB_DROPDOWNONLY);
     198             : 
     199           0 :     Link aLink = LINK(this, TextPropertyPanel, SpacingClickHdl);
     200           0 :     mpToolBoxSpacing->SetDropdownClickHdl ( aLink );
     201           0 :     mpToolBoxSpacing->SetSelectHdl( aLink );
     202           0 : }
     203             : 
     204           0 : void TextPropertyPanel::SetupToolboxItems (void)
     205             : {
     206           0 :     maUnderlineControl.SetupToolBoxItem(*mpToolBoxFont, mpToolBoxFont->GetItemId(UNO_UNDERLINE));
     207           0 :     maSpacingControl.SetupToolBoxItem(*mpToolBoxSpacing, mpToolBoxSpacing->GetItemId(UNO_SPACING));
     208           0 : }
     209             : 
     210           0 : IMPL_LINK(TextPropertyPanel, UnderlineClickHdl, ToolBox*, pToolBox)
     211             : {
     212           0 :     const sal_uInt16 nId = pToolBox->GetCurItemId();
     213           0 :     const OUString aCommand(pToolBox->GetItemCommand(nId));
     214             : 
     215           0 :     if (aCommand == UNO_UNDERLINE)
     216             :     {
     217           0 :         pToolBox->SetItemDown( nId, true );
     218           0 :         maUnderlinePopup.Rearrange(meUnderline);
     219           0 :         maUnderlinePopup.Show(*pToolBox);
     220             :     }
     221             : 
     222           0 :     return 0L;
     223             : }
     224             : 
     225           0 : IMPL_LINK(TextPropertyPanel, SpacingClickHdl, ToolBox*, pToolBox)
     226             : {
     227           0 :     const sal_uInt16 nId = pToolBox->GetCurItemId();
     228           0 :     const OUString aCommand(pToolBox->GetItemCommand(nId));
     229             : 
     230           0 :     if (aCommand == UNO_SPACING)
     231             :     {
     232           0 :         pToolBox->SetItemDown( nId, true );
     233           0 :         maCharSpacePopup.Rearrange(mbKernLBAvailable,mbKernAvailable,mlKerning);
     234           0 :         maCharSpacePopup.Show(*pToolBox);
     235             :     }
     236             : 
     237           0 :     return 0L;
     238             : }
     239             : 
     240           0 : void TextPropertyPanel::NotifyItemUpdate (
     241             :     const sal_uInt16 nSID,
     242             :     const SfxItemState eState,
     243             :     const SfxPoolItem* pState,
     244             :     const bool bIsEnabled)
     245             : {
     246           0 :     switch(nSID)
     247             :     {
     248             :     case SID_ATTR_CHAR_FONTHEIGHT:
     249             :         {
     250           0 :             if (  eState >= SFX_ITEM_DEFAULT && pState->ISA(SvxFontHeightItem) )
     251           0 :                 mpHeightItem = (SvxFontHeightItem*)pState;
     252             :             else
     253           0 :                 mpHeightItem = NULL;
     254             :         }
     255           0 :         break;
     256             :     case SID_ATTR_CHAR_UNDERLINE:
     257             :         {
     258           0 :             if( eState >= SFX_ITEM_DEFAULT && pState->ISA(SvxUnderlineItem) )
     259             :             {
     260           0 :                 const SvxUnderlineItem* pItem = (const SvxUnderlineItem*)pState;
     261           0 :                 meUnderline = (FontUnderline)pItem->GetValue();
     262           0 :                 meUnderlineColor = pItem->GetColor();
     263             :             }
     264             :             else
     265           0 :                 meUnderline = UNDERLINE_NONE;
     266             :         }
     267           0 :         break;
     268             :     case SID_ATTR_CHAR_KERNING:
     269             :         {
     270           0 :             if ( SFX_ITEM_AVAILABLE == eState )
     271             :             {
     272           0 :                 mbKernLBAvailable = true;
     273             : 
     274           0 :                 if(pState->ISA(SvxKerningItem))
     275             :                 {
     276           0 :                     const SvxKerningItem* pKerningItem  = (const SvxKerningItem*)pState;
     277           0 :                     mlKerning = (long)pKerningItem->GetValue();
     278           0 :                     mbKernAvailable = true;
     279             :                 }
     280             :                 else
     281             :                 {
     282           0 :                     mlKerning = 0;
     283           0 :                     mbKernAvailable =false;
     284             :                 }
     285             :             }
     286           0 :             else if (SFX_ITEM_DISABLED == eState)
     287             :             {
     288           0 :                 mbKernLBAvailable = false;
     289           0 :                 mbKernAvailable = false;
     290           0 :                 mlKerning = 0;
     291             :             }
     292             :             else
     293             :             {
     294           0 :                 mbKernLBAvailable = true;
     295           0 :                 mbKernAvailable = false;
     296           0 :                 mlKerning = 0;
     297             :             }
     298           0 :             mpToolBoxSpacing->Enable(bIsEnabled);
     299             :         }
     300           0 :         break;
     301             :     }
     302           0 : }
     303             : 
     304           0 : Color& TextPropertyPanel::GetUnderlineColor()
     305             : {
     306           0 :     return meUnderlineColor;
     307             : }
     308             : 
     309           0 : } } // end of namespace svx::sidebar

Generated by: LCOV version 1.10