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

Generated by: LCOV version 1.11