LCOV - code coverage report
Current view: top level - usr/local/src/libreoffice/sw/source/ui/misc - insfnote.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 147 0.0 %
Date: 2013-07-09 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             : static sal_Bool bFootnote = sal_True;
      42             : 
      43             : /*------------------------------------------------------------------------
      44             :  Description:   inserting a footnote with OK
      45             : ------------------------------------------------------------------------*/
      46             : 
      47           0 : void SwInsFootNoteDlg::Apply()
      48             : {
      49           0 :     String aStr;
      50             : 
      51           0 :     if ( m_pNumberCharBtn->IsChecked() )
      52           0 :         aStr = m_pNumberCharEdit->GetText();
      53             : 
      54           0 :     if ( bEdit )
      55             :     {
      56           0 :         rSh.StartAction();
      57           0 :         rSh.Left(CRSR_SKIP_CHARS, sal_False, 1, sal_False );
      58           0 :         rSh.StartUndo( UNDO_START );
      59           0 :         SwFmtFtn aNote( m_pEndNoteBtn->IsChecked() );
      60           0 :         aNote.SetNumStr( aStr );
      61             : 
      62           0 :         if( rSh.SetCurFtn( aNote ) && bExtCharAvailable )
      63             :         {
      64           0 :             rSh.Right(CRSR_SKIP_CHARS, sal_True, 1, sal_False );
      65           0 :             SfxItemSet aSet( rSh.GetAttrPool(), RES_CHRATR_FONT, RES_CHRATR_FONT );
      66           0 :             rSh.GetCurAttr( aSet );
      67           0 :             SvxFontItem &rFont = (SvxFontItem &) aSet.Get( RES_CHRATR_FONT );
      68             :             SvxFontItem aFont( rFont.GetFamily(), aFontName,
      69           0 :                                rFont.GetStyleName(), rFont.GetPitch(),
      70           0 :                                eCharSet, RES_CHRATR_FONT );
      71           0 :             aSet.Put( aFont );
      72           0 :             rSh.SetAttr( aSet, nsSetAttrMode::SETATTR_DONTEXPAND );
      73           0 :             rSh.ResetSelect(0, sal_False);
      74           0 :             rSh.Left(CRSR_SKIP_CHARS, sal_False, 1, sal_False );
      75             :         }
      76           0 :         rSh.EndUndo( UNDO_END );
      77           0 :         rSh.EndAction();
      78             :     }
      79             :     else
      80             :     {
      81             : 
      82             :     }
      83             : 
      84           0 :     bFootnote = m_pFtnBtn->IsChecked();
      85           0 : }
      86             : 
      87           0 : IMPL_LINK_NOARG_INLINE_START(SwInsFootNoteDlg, NumberCharHdl)
      88             : {
      89           0 :     m_pNumberCharEdit->GrabFocus();
      90           0 :     m_pOkBtn->Enable( !m_pNumberCharEdit->GetText().isEmpty() || bExtCharAvailable );
      91           0 :     return 0;
      92             : }
      93           0 : IMPL_LINK_NOARG_INLINE_END(SwInsFootNoteDlg, NumberCharHdl)
      94             : 
      95           0 : IMPL_LINK_NOARG_INLINE_START(SwInsFootNoteDlg, NumberEditHdl)
      96             : {
      97           0 :     m_pNumberCharBtn->Check( sal_True );
      98           0 :     m_pOkBtn->Enable( !m_pNumberCharEdit->GetText().isEmpty() );
      99             : 
     100           0 :     return 0;
     101             : }
     102           0 : IMPL_LINK_NOARG_INLINE_END(SwInsFootNoteDlg, NumberEditHdl)
     103             : 
     104           0 : IMPL_LINK_NOARG_INLINE_START(SwInsFootNoteDlg, NumberAutoBtnHdl)
     105             : {
     106           0 :     m_pOkBtn->Enable( sal_True );
     107           0 :     return 0;
     108             : }
     109           0 : IMPL_LINK_NOARG_INLINE_END(SwInsFootNoteDlg, NumberAutoBtnHdl)
     110             : 
     111           0 : IMPL_LINK_NOARG(SwInsFootNoteDlg, NumberExtCharHdl)
     112             : {
     113           0 :     m_pNumberCharBtn->Check( sal_True );
     114             : 
     115           0 :     SfxItemSet aSet( rSh.GetAttrPool(), RES_CHRATR_FONT, RES_CHRATR_FONT );
     116           0 :     rSh.GetCurAttr( aSet );
     117           0 :     const SvxFontItem &rFont = (SvxFontItem &) aSet.Get( RES_CHRATR_FONT );
     118             : 
     119           0 :     SfxAllItemSet aAllSet( rSh.GetAttrPool() );
     120           0 :     aAllSet.Put( SfxBoolItem( FN_PARAM_1, sal_False ) );
     121           0 :     aAllSet.Put( rFont );
     122             : 
     123           0 :     SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
     124             :     SfxAbstractDialog* pDlg = pFact->CreateSfxDialog( this, aAllSet,
     125           0 :         rSh.GetView().GetViewFrame()->GetFrame().GetFrameInterface(), RID_SVXDLG_CHARMAP );
     126           0 :     if (RET_OK == pDlg->Execute())
     127             :     {
     128           0 :         SFX_ITEMSET_ARG( pDlg->GetOutputItemSet(), pItem, SfxStringItem, SID_CHARMAP, sal_False );
     129           0 :         SFX_ITEMSET_ARG( pDlg->GetOutputItemSet(), pFontItem, SvxFontItem, SID_ATTR_CHAR_FONT, sal_False );
     130           0 :         if ( pItem )
     131             :         {
     132           0 :             String sExtChars(pItem->GetValue());
     133           0 :             m_pNumberCharEdit->SetText( sExtChars );
     134             : 
     135           0 :             if ( pFontItem )
     136             :             {
     137           0 :                 aFontName = pFontItem->GetFamilyName();
     138           0 :                 eCharSet  = pFontItem->GetCharSet();
     139           0 :                 Font aFont( aFontName, pFontItem->GetStyleName(), m_pNumberCharEdit->GetFont().GetSize() );
     140           0 :                 aFont.SetCharSet( pFontItem->GetCharSet() );
     141           0 :                 aFont.SetPitch( pFontItem->GetPitch() );
     142           0 :                 m_pNumberCharEdit->SetFont( aFont  );
     143             :             }
     144             : 
     145           0 :             bExtCharAvailable = sal_True;
     146           0 :             m_pOkBtn->Enable(!m_pNumberCharEdit->GetText().isEmpty());
     147             :         }
     148             :     }
     149           0 :     delete pDlg;
     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 :     String 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().Len())
     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 :             aFontName = rFont.GetFamilyName();
     238           0 :             eCharSet = rFont.GetCharSet();
     239           0 :             aFont.SetName(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 :     bool bNumChar = sNumStr.Len() != 0;
     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