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

Generated by: LCOV version 1.10