LCOV - code coverage report
Current view: top level - sw/source/ui/misc - insfnote.cxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 145 0.0 %
Date: 2014-04-14 Functions: 0 17 0.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 <hintids.hxx>
      21             : #include <svl/eitem.hxx>
      22             : #include <svl/stritem.hxx>
      23             : #include <sfx2/request.hxx>
      24             : #include <editeng/fontitem.hxx>
      25             : #include <vcl/msgbox.hxx>
      26             : #include <fmtftn.hxx>
      27             : #include <swundo.hxx>
      28             : #include <cmdid.h>
      29             : #include <wrtsh.hxx>
      30             : #include <view.hxx>
      31             : #include <basesh.hxx>
      32             : #include <insfnote.hxx>
      33             : #include <crsskip.hxx>
      34             : #include <misc.hrc>
      35             : #include <globals.hrc>
      36             : #include <svx/svxdlg.hxx>
      37             : #include <svx/dialogs.hrc>
      38             : #include <sfx2/viewfrm.hxx>
      39             : #include <vcl/layout.hxx>
      40             : 
      41             : #include <boost/scoped_ptr.hpp>
      42             : 
      43             : static sal_Bool bFootnote = sal_True;
      44             : 
      45             : /*------------------------------------------------------------------------
      46             :  Description:   inserting a footnote with OK
      47             : ------------------------------------------------------------------------*/
      48             : 
      49           0 : void SwInsFootNoteDlg::Apply()
      50             : {
      51           0 :     OUString aStr;
      52             : 
      53           0 :     if ( m_pNumberCharBtn->IsChecked() )
      54           0 :         aStr = m_pNumberCharEdit->GetText();
      55             : 
      56           0 :     if ( bEdit )
      57             :     {
      58           0 :         rSh.StartAction();
      59           0 :         rSh.Left(CRSR_SKIP_CHARS, sal_False, 1, sal_False );
      60           0 :         rSh.StartUndo( UNDO_START );
      61           0 :         SwFmtFtn aNote( m_pEndNoteBtn->IsChecked() );
      62           0 :         aNote.SetNumStr( aStr );
      63             : 
      64           0 :         if( rSh.SetCurFtn( aNote ) && bExtCharAvailable )
      65             :         {
      66           0 :             rSh.Right(CRSR_SKIP_CHARS, sal_True, 1, sal_False );
      67           0 :             SfxItemSet aSet( rSh.GetAttrPool(), RES_CHRATR_FONT, RES_CHRATR_FONT );
      68           0 :             rSh.GetCurAttr( aSet );
      69           0 :             SvxFontItem &rFont = (SvxFontItem &) aSet.Get( RES_CHRATR_FONT );
      70             :             SvxFontItem aFont( rFont.GetFamily(), m_aFontName,
      71           0 :                                rFont.GetStyleName(), rFont.GetPitch(),
      72           0 :                                eCharSet, RES_CHRATR_FONT );
      73           0 :             aSet.Put( aFont );
      74           0 :             rSh.SetAttrSet( aSet, nsSetAttrMode::SETATTR_DONTEXPAND );
      75           0 :             rSh.ResetSelect(0, sal_False);
      76           0 :             rSh.Left(CRSR_SKIP_CHARS, sal_False, 1, sal_False );
      77             :         }
      78           0 :         rSh.EndUndo( UNDO_END );
      79           0 :         rSh.EndAction();
      80             :     }
      81             :     else
      82             :     {
      83             : 
      84             :     }
      85             : 
      86           0 :     bFootnote = m_pFtnBtn->IsChecked();
      87           0 : }
      88             : 
      89           0 : IMPL_LINK_NOARG_INLINE_START(SwInsFootNoteDlg, NumberCharHdl)
      90             : {
      91           0 :     m_pNumberCharEdit->GrabFocus();
      92           0 :     m_pOkBtn->Enable( !m_pNumberCharEdit->GetText().isEmpty() || bExtCharAvailable );
      93           0 :     return 0;
      94             : }
      95           0 : IMPL_LINK_NOARG_INLINE_END(SwInsFootNoteDlg, NumberCharHdl)
      96             : 
      97           0 : IMPL_LINK_NOARG_INLINE_START(SwInsFootNoteDlg, NumberEditHdl)
      98             : {
      99           0 :     m_pNumberCharBtn->Check( true );
     100           0 :     m_pOkBtn->Enable( !m_pNumberCharEdit->GetText().isEmpty() );
     101             : 
     102           0 :     return 0;
     103             : }
     104           0 : IMPL_LINK_NOARG_INLINE_END(SwInsFootNoteDlg, NumberEditHdl)
     105             : 
     106           0 : IMPL_LINK_NOARG_INLINE_START(SwInsFootNoteDlg, NumberAutoBtnHdl)
     107             : {
     108           0 :     m_pOkBtn->Enable( true );
     109           0 :     return 0;
     110             : }
     111           0 : IMPL_LINK_NOARG_INLINE_END(SwInsFootNoteDlg, NumberAutoBtnHdl)
     112             : 
     113           0 : IMPL_LINK_NOARG(SwInsFootNoteDlg, NumberExtCharHdl)
     114             : {
     115           0 :     m_pNumberCharBtn->Check( true );
     116             : 
     117           0 :     SfxItemSet aSet( rSh.GetAttrPool(), RES_CHRATR_FONT, RES_CHRATR_FONT );
     118           0 :     rSh.GetCurAttr( aSet );
     119           0 :     const SvxFontItem &rFont = (SvxFontItem &) aSet.Get( RES_CHRATR_FONT );
     120             : 
     121           0 :     SfxAllItemSet aAllSet( rSh.GetAttrPool() );
     122           0 :     aAllSet.Put( SfxBoolItem( FN_PARAM_1, false ) );
     123           0 :     aAllSet.Put( rFont );
     124             : 
     125           0 :     SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
     126             :     boost::scoped_ptr<SfxAbstractDialog> pDlg(pFact->CreateSfxDialog( this, aAllSet,
     127           0 :         rSh.GetView().GetViewFrame()->GetFrame().GetFrameInterface(), RID_SVXDLG_CHARMAP ));
     128           0 :     if (RET_OK == pDlg->Execute())
     129             :     {
     130           0 :         SFX_ITEMSET_ARG( pDlg->GetOutputItemSet(), pItem, SfxStringItem, SID_CHARMAP, false );
     131           0 :         SFX_ITEMSET_ARG( pDlg->GetOutputItemSet(), pFontItem, SvxFontItem, SID_ATTR_CHAR_FONT, false );
     132           0 :         if ( pItem )
     133             :         {
     134           0 :             m_pNumberCharEdit->SetText( pItem->GetValue() );
     135             : 
     136           0 :             if ( pFontItem )
     137             :             {
     138           0 :                 m_aFontName = pFontItem->GetFamilyName();
     139           0 :                 eCharSet  = pFontItem->GetCharSet();
     140           0 :                 Font aFont( m_aFontName, pFontItem->GetStyleName(), m_pNumberCharEdit->GetFont().GetSize() );
     141           0 :                 aFont.SetCharSet( pFontItem->GetCharSet() );
     142           0 :                 aFont.SetPitch( pFontItem->GetPitch() );
     143           0 :                 m_pNumberCharEdit->SetFont( aFont  );
     144             :             }
     145             : 
     146           0 :             bExtCharAvailable = sal_True;
     147           0 :             m_pOkBtn->Enable(!m_pNumberCharEdit->GetText().isEmpty());
     148             :         }
     149             :     }
     150             : 
     151           0 :     return 0;
     152             : }
     153             : 
     154           0 : IMPL_LINK( SwInsFootNoteDlg, NextPrevHdl, Button *, pBtn )
     155             : {
     156           0 :     Apply();
     157             : 
     158             :     // go to the next foot/endnote here
     159           0 :     rSh.ResetSelect(0, sal_False);
     160           0 :     if (pBtn == m_pNextBT)
     161           0 :         rSh.GotoNextFtnAnchor();
     162             :     else
     163           0 :         rSh.GotoPrevFtnAnchor();
     164             : 
     165           0 :     Init();
     166             : 
     167           0 :     return 0;
     168             : }
     169             : 
     170           0 : SwInsFootNoteDlg::SwInsFootNoteDlg(Window *pParent, SwWrtShell &rShell, sal_Bool bEd) :
     171             :     SvxStandardDialog(pParent, "InsertFootnoteDialog", "modules/swriter/ui/insertfootnote.ui"),
     172             :     rSh(rShell),
     173             :     bExtCharAvailable(sal_False),
     174           0 :     bEdit(bEd)
     175             : {
     176           0 :     get(m_pNumberFrame, "numberingframe");
     177           0 :     get(m_pNumberAutoBtn, "automatic");
     178           0 :     get(m_pNumberCharBtn, "character");
     179           0 :     get(m_pNumberCharEdit, "characterentry");
     180           0 :     get(m_pNumberExtChar, "choosecharacter");
     181           0 :     get(m_pFtnBtn, "footnote");
     182           0 :     get(m_pEndNoteBtn, "endnote");
     183           0 :     get(m_pOkBtn, "ok");
     184           0 :     get(m_pPrevBT, "prev");
     185           0 :     get(m_pNextBT, "next");
     186             : 
     187           0 :     m_pNumberAutoBtn->SetClickHdl(LINK(this,SwInsFootNoteDlg,NumberAutoBtnHdl));
     188           0 :     m_pNumberExtChar->SetClickHdl(LINK(this,SwInsFootNoteDlg,NumberExtCharHdl));
     189           0 :     m_pNumberCharBtn->SetClickHdl(LINK(this,SwInsFootNoteDlg,NumberCharHdl));
     190           0 :     m_pNumberCharEdit->SetModifyHdl(LINK(this,SwInsFootNoteDlg,NumberEditHdl));
     191           0 :     m_pNumberCharEdit->SetMaxTextLen(10);
     192           0 :     m_pNumberCharEdit->Enable();
     193             : 
     194           0 :     m_pPrevBT->SetClickHdl(LINK(this, SwInsFootNoteDlg, NextPrevHdl));
     195           0 :     m_pNextBT->SetClickHdl(LINK(this, SwInsFootNoteDlg, NextPrevHdl));
     196             : 
     197           0 :     rSh.SetCareWin(this);
     198             : 
     199           0 :     if (bEdit)
     200             :     {
     201           0 :         Init();
     202             : 
     203           0 :         m_pPrevBT->Show();
     204           0 :         m_pNextBT->Show();
     205             :     }
     206           0 : }
     207             : 
     208           0 : SwInsFootNoteDlg::~SwInsFootNoteDlg()
     209             : {
     210           0 :     rSh.SetCareWin(0);
     211             : 
     212           0 :     if (bEdit)
     213           0 :         rSh.ResetSelect(0, sal_False);
     214           0 : }
     215             : 
     216           0 : void SwInsFootNoteDlg::Init()
     217             : {
     218           0 :     SwFmtFtn aFtnNote;
     219           0 :     OUString sNumStr;
     220           0 :     Font aFont;
     221           0 :     bExtCharAvailable = sal_False;
     222             : 
     223           0 :     rSh.StartAction();
     224             : 
     225           0 :     if( rSh.GetCurFtn( &aFtnNote ))
     226             :     {
     227           0 :         if (!aFtnNote.GetNumStr().isEmpty())
     228             :         {
     229           0 :             sNumStr = aFtnNote.GetNumStr();
     230             : 
     231           0 :             rSh.Right(CRSR_SKIP_CHARS, sal_True, 1, sal_False );
     232           0 :             SfxItemSet aSet( rSh.GetAttrPool(), RES_CHRATR_FONT, RES_CHRATR_FONT );
     233           0 :             rSh.GetCurAttr( aSet );
     234           0 :             const SvxFontItem &rFont = (SvxFontItem &) aSet.Get( RES_CHRATR_FONT );
     235             : 
     236           0 :             aFont = m_pNumberCharEdit->GetFont();
     237           0 :             m_aFontName = rFont.GetFamilyName();
     238           0 :             eCharSet = rFont.GetCharSet();
     239           0 :             aFont.SetName(m_aFontName);
     240           0 :             aFont.SetCharSet(eCharSet);
     241           0 :             bExtCharAvailable = sal_True;
     242           0 :             rSh.Left( CRSR_SKIP_CHARS, sal_False, 1, sal_False );
     243             :         }
     244           0 :         bFootnote = !aFtnNote.IsEndNote();
     245             :     }
     246           0 :     m_pNumberCharEdit->SetFont(aFont);
     247             : 
     248           0 :     const bool bNumChar = !sNumStr.isEmpty();
     249             : 
     250           0 :     m_pNumberCharEdit->SetText(sNumStr);
     251           0 :     m_pNumberCharBtn->Check(bNumChar);
     252           0 :     m_pNumberAutoBtn->Check(!bNumChar);
     253           0 :     if (bNumChar)
     254           0 :         m_pNumberCharEdit->GrabFocus();
     255             : 
     256           0 :     if (bFootnote)
     257           0 :         m_pFtnBtn->Check();
     258             :     else
     259           0 :         m_pEndNoteBtn->Check();
     260             : 
     261           0 :     sal_Bool bNext = rSh.GotoNextFtnAnchor();
     262             : 
     263           0 :     if (bNext)
     264           0 :         rSh.GotoPrevFtnAnchor();
     265             : 
     266           0 :     sal_Bool bPrev = rSh.GotoPrevFtnAnchor();
     267             : 
     268           0 :     if (bPrev)
     269           0 :         rSh.GotoNextFtnAnchor();
     270             : 
     271           0 :     m_pPrevBT->Enable(bPrev);
     272           0 :     m_pNextBT->Enable(bNext);
     273             : 
     274           0 :     rSh.Right(CRSR_SKIP_CHARS, sal_True, 1, sal_False );
     275             : 
     276           0 :     rSh.EndAction();
     277           0 : }
     278             : 
     279             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10