LCOV - code coverage report
Current view: top level - usr/local/src/libreoffice/svx/source/mnuctrls - fntszctl.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 2 60 3.3 %
Date: 2013-07-09 Functions: 3 11 27.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             : 
      21             : #include <string>
      22             : #include <svl/itempool.hxx>
      23             : #include <svtools/stdmenu.hxx>
      24             : #include <svtools/ctrltool.hxx>
      25             : #include <sfx2/app.hxx>
      26             : #include <sfx2/objsh.hxx>
      27             : #include <sfx2/viewfrm.hxx>
      28             : #include <sfx2/dispatch.hxx>
      29             : 
      30             : #include <svx/fntszctl.hxx>     //
      31             : #include <svx/dialogs.hrc>
      32             : #include <editeng/fhgtitem.hxx>
      33             : #include "editeng/fontitem.hxx"
      34             : #include "editeng/flstitem.hxx"
      35             : 
      36             : #include "svx/dlgutil.hxx"
      37             : #include <svx/dialmgr.hxx>
      38             : 
      39             : #define LOGIC   OutputDevice::LogicToLogic
      40             : 
      41          75 : SFX_IMPL_MENU_CONTROL(SvxFontSizeMenuControl, SvxFontHeightItem);
      42             : 
      43             : //--------------------------------------------------------------------
      44             : 
      45             : /*  [Beschreibung]
      46             : 
      47             :     Select-Handler des Men"us; die aktuelle Fontgr"o\se
      48             :     wird in einem SvxFontHeightItem verschickt.
      49             : */
      50             : 
      51           0 : IMPL_LINK( SvxFontSizeMenuControl, MenuSelect, FontSizeMenu*, pMen )
      52             : {
      53           0 :     SfxViewFrame* pFrm = SfxViewFrame::Current();
      54           0 :     SfxShell* pSh = pFrm ? pFrm->GetDispatcher()->GetShell( 0 ) : NULL;
      55             : 
      56           0 :     if ( !pSh )
      57           0 :         return 0;
      58             : 
      59           0 :     const SfxItemPool& rPool = pSh->GetPool();
      60           0 :     sal_uInt16 nWhich = rPool.GetWhich( SID_ATTR_CHAR_FONTHEIGHT );
      61           0 :     const SfxMapUnit eUnit = rPool.GetMetric( nWhich );
      62           0 :     long nH = LOGIC( pMen->GetCurHeight(), MAP_POINT, (MapUnit)eUnit ) / 10;
      63           0 :     SvxFontHeightItem aItem( nH, 100, GetId() );
      64           0 :     GetBindings().GetDispatcher()->Execute( GetId(), SFX_CALLMODE_RECORD, &aItem, 0L );
      65           0 :     return 1;
      66             : }
      67             : 
      68             : //--------------------------------------------------------------------
      69             : 
      70             : /*  [Beschreibung]
      71             : 
      72             :     Statusbenachrichtigung;
      73             :     Ist die Funktionalit"at disabled, wird der entsprechende
      74             :     Men"ueintrag im Parentmenu disabled, andernfalls wird er enabled.
      75             :     die aktuelle Fontgr"o\se wird mit einer Checkmark versehen.
      76             : */
      77             : 
      78           0 : void SvxFontSizeMenuControl::StateChanged(
      79             : 
      80             :     sal_uInt16, SfxItemState eState, const SfxPoolItem* pState )
      81             : 
      82             : {
      83           0 :     rParent.EnableItem( GetId(), SFX_ITEM_DISABLED != eState );
      84             : 
      85           0 :     if ( SFX_ITEM_AVAILABLE == eState )
      86             :     {
      87           0 :         if ( pState->ISA(SvxFontHeightItem) )
      88             :         {
      89             :             const SvxFontHeightItem* pItem =
      90           0 :                 PTR_CAST( SvxFontHeightItem, pState );
      91           0 :             long nVal = 0;
      92             : 
      93           0 :             if ( pItem )
      94             :             {
      95           0 :                 SfxViewFrame* pFrm = SfxViewFrame::Current();
      96           0 :                 SfxShell* pSh = pFrm ? pFrm->GetDispatcher()->GetShell( 0 )
      97           0 :                                      : NULL;
      98             : 
      99           0 :                 if ( !pSh )
     100           0 :                     return;
     101             : 
     102           0 :                 const SfxItemPool& rPool = pSh->GetPool();
     103           0 :                 sal_uInt16 nWhich = rPool.GetWhich( SID_ATTR_CHAR_FONTHEIGHT );
     104           0 :                 const SfxMapUnit eUnit = rPool.GetMetric( nWhich );
     105           0 :                 long nH = pItem->GetHeight() * 10;
     106           0 :                 nVal = LOGIC( nH, (MapUnit)eUnit, MAP_POINT );
     107             :             }
     108           0 :             pMenu->SetCurHeight( nVal );
     109             :         }
     110           0 :         else if ( pState->ISA(SvxFontItem) )
     111             :         {
     112           0 :             const SvxFontItem* pItem = PTR_CAST( SvxFontItem, pState );
     113             : 
     114           0 :             if ( pItem )
     115             :             {
     116           0 :                 SfxObjectShell *pDoc = SfxObjectShell::Current();
     117             : 
     118           0 :                 if ( pDoc )
     119             :                 {
     120             :                     const SvxFontListItem* pFonts = (const SvxFontListItem*)
     121           0 :                         pDoc->GetItem( SID_ATTR_CHAR_FONTLIST );
     122           0 :                     const FontList* pList = pFonts ? pFonts->GetFontList(): 0;
     123             : 
     124           0 :                     if ( pList )
     125             :                     {
     126           0 :                         FontInfo aFntInf = pList->Get( pItem->GetFamilyName(),
     127           0 :                                                        pItem->GetStyleName() );
     128           0 :                         pMenu->Fill( aFntInf, pList );
     129             :                     }
     130             :                     // else manche Shells haben keine Fontliste (z.B. Image)
     131             :                 }
     132             :             }
     133             :         }
     134             :     }
     135             :     else
     136             :     {
     137             :         // irgendwie muss man ja das Men"u f"ullen
     138           0 :         SfxObjectShell* pSh = SfxObjectShell::Current();
     139             : 
     140           0 :         if ( pSh )
     141             :         {
     142             :             // daf"ur von der Shell eine Fontliste besorgen
     143             :             const SvxFontListItem* pFonts =
     144           0 :                 (const SvxFontListItem*)pSh->GetItem( SID_ATTR_CHAR_FONTLIST );
     145           0 :             const FontList* pList = pFonts ? pFonts->GetFontList(): NULL;
     146           0 :             if ( pList )
     147           0 :                 pMenu->Fill( pList->GetFontName(0), pList );
     148             :         }
     149             :     }
     150             : }
     151             : 
     152             : //--------------------------------------------------------------------
     153             : 
     154             : /*  [Beschreibung]
     155             : 
     156             :     Ctor; setzt den Select-Handler am Men"u und tr"agt Men"u
     157             :     in seinen Parent ein.
     158             : */
     159             : 
     160           0 : SvxFontSizeMenuControl::SvxFontSizeMenuControl
     161             : (
     162             :     sal_uInt16          _nId,
     163             :     Menu&           rMenu,
     164             :     SfxBindings&    rBindings
     165             : ) :
     166             :     SfxMenuControl( _nId, rBindings ),
     167             : 
     168           0 :     pMenu   ( new FontSizeMenu ),
     169             :     rParent ( rMenu ),
     170           0 :     aFontNameForwarder( SID_ATTR_CHAR_FONT, *this )
     171             : 
     172             : {
     173           0 :     rMenu.SetPopupMenu( _nId, pMenu );
     174           0 :     pMenu->SetSelectHdl( LINK( this, SvxFontSizeMenuControl, MenuSelect ) );
     175           0 : }
     176             : 
     177             : //--------------------------------------------------------------------
     178             : 
     179             : /*  [Beschreibung]
     180             : 
     181             :     Dtor; gibt das Men"u frei.
     182             : */
     183             : 
     184           0 : SvxFontSizeMenuControl::~SvxFontSizeMenuControl()
     185             : {
     186           0 :     delete pMenu;
     187           0 : }
     188             : 
     189             : //--------------------------------------------------------------------
     190             : 
     191             : /*  [Beschreibung]
     192             : 
     193             :     Gibt das Men"u zur"uck
     194             : */
     195             : 
     196           0 : PopupMenu* SvxFontSizeMenuControl::GetPopup() const
     197             : {
     198           0 :     return pMenu;
     199         216 : }
     200             : 
     201             : 
     202             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10