LCOV - code coverage report
Current view: top level - usr/local/src/libreoffice/svx/source/sidebar/text - SvxSBFontNameBox.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 1 80 1.2 %
Date: 2013-07-09 Functions: 2 12 16.7 %
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 "SvxSBFontNameBox.hxx"
      20             : 
      21             : #include <unotools/fontoptions.hxx>
      22             : #include <sfx2/objsh.hxx>
      23             : #include <sfx2/dispatch.hxx>
      24             : #include <editeng/flstitem.hxx>
      25             : #include <editeng/editids.hrc>
      26             : #include <editeng/fontitem.hxx>
      27             : #include <vcl/builder.hxx>
      28             : 
      29             : const static sal_uInt16 MAX_MRU_FONTNAME_ENTRIES = 5;
      30             : 
      31             : 
      32             : namespace svx { namespace sidebar {
      33             : 
      34             : namespace {
      35           0 :     bool GetDocFontList_Impl( const FontList** ppFontList, SvxSBFontNameBox* pBox )
      36             :     {
      37           0 :         bool bChanged = false;
      38           0 :         const SfxObjectShell* pDocSh = SfxObjectShell::Current();
      39           0 :         SvxFontListItem* pFontListItem = NULL;
      40             : 
      41           0 :         if ( pDocSh )
      42             :             pFontListItem =
      43           0 :                 (SvxFontListItem*)pDocSh->GetItem( SID_ATTR_CHAR_FONTLIST );
      44             : 
      45           0 :         if ( pFontListItem )
      46             :         {
      47           0 :             const FontList* pNewFontList = pFontListItem->GetFontList();
      48             :             DBG_ASSERT( pNewFontList, "Doc-FontList not available!" );
      49             : 
      50           0 :             if ( !*ppFontList )
      51             :             {
      52           0 :                 *ppFontList = pNewFontList;
      53           0 :                 bChanged = true;
      54             :             }
      55             :             else
      56             :             {
      57           0 :                 bChanged = ( *ppFontList != pNewFontList );
      58           0 :                 if( !bChanged && pBox!=NULL )
      59           0 :                     bChanged = ( pBox->GetListCount() != pNewFontList->GetFontNameCount() );
      60             :                 //HACK(vergleich ist unvollstaendig)
      61           0 :                 if ( bChanged )
      62           0 :                     *ppFontList = pNewFontList;
      63             :             }
      64             : 
      65           0 :             if ( pBox )
      66           0 :                 pBox->Enable();
      67             :         }
      68           0 :         else if ( pBox )
      69           0 :             pBox->Disable();
      70             : 
      71             :         // in die FontBox ggf. auch die neue Liste f"ullen
      72           0 :         if ( pBox && bChanged )
      73             :         {
      74           0 :             if ( *ppFontList )
      75           0 :                 pBox->Fill( *ppFontList );
      76             :             else
      77           0 :                 pBox->Clear();
      78             :         }
      79           0 :         return bChanged;
      80             :     }
      81             : }
      82             : 
      83             : 
      84             : 
      85             : 
      86           0 : SvxSBFontNameBox::SvxSBFontNameBox( Window* pParent,  const ResId& rResId  ) :
      87             :     FontNameBox ( pParent, rResId )
      88             : ,   pFontList   ( NULL )
      89             : ,   nFtCount    ( 0 )
      90           0 : ,   pBindings(NULL)
      91             : {
      92           0 :     EnableControls_Impl();
      93             : //  StartListening( *SFX_APP() );
      94           0 : }
      95             : 
      96           0 : SvxSBFontNameBox::SvxSBFontNameBox( Window* pParent ) :
      97             :     FontNameBox ( pParent, WB_LEFT|WB_VCENTER|WB_3DLOOK|WB_TABSTOP|WB_DROPDOWN )
      98             : ,   pFontList   ( NULL )
      99             : ,   nFtCount    ( 0 )
     100           0 : ,   pBindings(NULL)
     101             : {
     102           0 :     EnableControls_Impl();
     103           0 :     EnableAutoSize(true);
     104             : //  StartListening( *SFX_APP() );
     105           0 : }
     106             : 
     107           0 : extern "C" SAL_DLLPUBLIC_EXPORT Window* SAL_CALL makeSvxSBFontNameBox(Window *pParent, VclBuilder::stringmap &)
     108             : {
     109           0 :     return new SvxSBFontNameBox(pParent);
     110             : }
     111             : 
     112           0 : void SvxSBFontNameBox::EnableControls_Impl()
     113             : {
     114           0 :     SvtFontOptions aFontOpt;
     115           0 :     bool bEnable = aFontOpt.IsFontHistoryEnabled();
     116           0 :     sal_uInt16 nEntries = bEnable ? MAX_MRU_FONTNAME_ENTRIES : 0;
     117           0 :     if ( GetMaxMRUCount() != nEntries )
     118             :     {
     119             :         // refill in the next GetFocus-Handler
     120           0 :         pFontList = NULL;
     121           0 :         Clear();
     122           0 :         SetMaxMRUCount( nEntries );
     123             :     }
     124             : 
     125           0 :     bEnable = aFontOpt.IsFontWYSIWYGEnabled();
     126           0 :     EnableWYSIWYG( bEnable );
     127           0 : }
     128             : 
     129           0 : void SvxSBFontNameBox::FillList()
     130             : {
     131           0 :     Selection aOldSel = GetSelection();
     132           0 :     GetDocFontList_Impl( &pFontList, this );
     133           0 :     aCurText = GetText();
     134           0 :     SetSelection( aOldSel );
     135           0 : }
     136             : 
     137           0 : long SvxSBFontNameBox::PreNotify( NotifyEvent& rNEvt )
     138             : {
     139           0 :     const sal_uInt16 nType (rNEvt.GetType());
     140             : 
     141           0 :     if ( EVENT_MOUSEBUTTONDOWN == nType || EVENT_GETFOCUS == nType )
     142           0 :         FillList();
     143           0 :     return FontNameBox::PreNotify( rNEvt );
     144             : }
     145             : //<<modify
     146           0 : long SvxSBFontNameBox::Notify( NotifyEvent& rNEvt) //SfxBroadcaster& rBC, const SfxHint& rHint
     147             : {
     148             :     //SfxItemSetHint* pHint = PTR_CAST(SfxItemSetHint, &rHint);
     149             :     //if ( pHint )
     150             :     //  EnableControls_Impl();
     151           0 :     bool bHandle = 0;
     152           0 :     if ( rNEvt.GetType() == EVENT_KEYINPUT )
     153             :     {
     154           0 :         const sal_uInt16 nCode (rNEvt.GetKeyEvent()->GetKeyCode().GetCode());
     155             : 
     156           0 :         if( nCode == KEY_RETURN)
     157             :         {
     158           0 :             bHandle = 1;
     159           0 :             Select();
     160             :         }
     161             :     }
     162             : 
     163           0 :     return bHandle ? bHandle : FontNameBox::Notify( rNEvt );
     164             : }
     165           0 : void SvxSBFontNameBox::Select()
     166             : {
     167           0 :     FontNameBox::Select();
     168             : 
     169           0 :     if ( !IsTravelSelect() )
     170             :     {
     171           0 :         FillList();
     172           0 :         FontInfo aInfo( pFontList->Get( GetText(),WEIGHT_NORMAL, ITALIC_NORMAL ) );//meWeight, meItalic
     173             : 
     174           0 :         SvxFontItem aFontItem( aInfo.GetFamily(), aInfo.GetName(), aInfo.GetStyleName(),
     175           0 :             aInfo.GetPitch(), aInfo.GetCharSet(), SID_ATTR_CHAR_FONT );
     176             : 
     177           0 :         pBindings->GetDispatcher()->Execute( SID_ATTR_CHAR_FONT, SFX_CALLMODE_RECORD, &aFontItem, 0L );
     178           0 :         pBindings->Invalidate(SID_ATTR_CHAR_FONT,true,false);
     179             :     }
     180           0 : }
     181           0 : void SvxSBFontNameBox::SetBindings(SfxBindings* pB)
     182             : {
     183           0 :     pBindings = pB;
     184           0 : }
     185             : 
     186         216 : } } // end of namespace svx::sidebar

Generated by: LCOV version 1.10