LCOV - code coverage report
Current view: top level - libreoffice/sw/source/ui/misc - insfnote.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 150 0.0 %
Date: 2012-12-17 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().Len() || 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( 0 != m_pNumberCharEdit->GetText().Len() );
      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(0 != m_pNumberCharEdit->GetText().Len());
     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_pNumberCharEdit->SetAccessibleName(String(SW_RES(STR_FOOTNOTE_DIALOG_CHAR)));
     188           0 :     m_pNumberExtChar->SetAccessibleRelationMemberOf(m_pNumberFrame->get_label_widget());
     189           0 :     m_pNumberCharEdit->SetAccessibleRelationLabeledBy(m_pNumberCharBtn);
     190             : 
     191           0 :     m_pNumberAutoBtn->SetClickHdl(LINK(this,SwInsFootNoteDlg,NumberAutoBtnHdl));
     192           0 :     m_pNumberExtChar->SetClickHdl(LINK(this,SwInsFootNoteDlg,NumberExtCharHdl));
     193           0 :     m_pNumberCharBtn->SetClickHdl(LINK(this,SwInsFootNoteDlg,NumberCharHdl));
     194           0 :     m_pNumberCharEdit->SetModifyHdl(LINK(this,SwInsFootNoteDlg,NumberEditHdl));
     195           0 :     m_pNumberCharEdit->SetMaxTextLen(10);
     196           0 :     m_pNumberCharEdit->Enable();
     197             : 
     198           0 :     m_pPrevBT->SetClickHdl(LINK(this, SwInsFootNoteDlg, NextPrevHdl));
     199           0 :     m_pNextBT->SetClickHdl(LINK(this, SwInsFootNoteDlg, NextPrevHdl));
     200             : 
     201           0 :     rSh.SetCareWin(this);
     202             : 
     203           0 :     if (bEdit)
     204             :     {
     205           0 :         Init();
     206             : 
     207           0 :         m_pPrevBT->Show();
     208           0 :         m_pNextBT->Show();
     209             :     }
     210           0 : }
     211             : 
     212           0 : SwInsFootNoteDlg::~SwInsFootNoteDlg()
     213             : {
     214           0 :     rSh.SetCareWin(0);
     215             : 
     216           0 :     if (bEdit)
     217           0 :         rSh.ResetSelect(0, sal_False);
     218           0 : }
     219             : 
     220           0 : void SwInsFootNoteDlg::Init()
     221             : {
     222           0 :     SwFmtFtn aFtnNote;
     223           0 :     String sNumStr;
     224           0 :     Font aFont;
     225           0 :     bExtCharAvailable = sal_False;
     226             : 
     227           0 :     rSh.StartAction();
     228             : 
     229           0 :     if( rSh.GetCurFtn( &aFtnNote ))
     230             :     {
     231           0 :         if(aFtnNote.GetNumStr().Len())
     232             :         {
     233           0 :             sNumStr = aFtnNote.GetNumStr();
     234             : 
     235           0 :             rSh.Right(CRSR_SKIP_CHARS, sal_True, 1, sal_False );
     236           0 :             SfxItemSet aSet( rSh.GetAttrPool(), RES_CHRATR_FONT, RES_CHRATR_FONT );
     237           0 :             rSh.GetCurAttr( aSet );
     238           0 :             const SvxFontItem &rFont = (SvxFontItem &) aSet.Get( RES_CHRATR_FONT );
     239             : 
     240           0 :             aFont = m_pNumberCharEdit->GetFont();
     241           0 :             aFontName = rFont.GetFamilyName();
     242           0 :             eCharSet = rFont.GetCharSet();
     243           0 :             aFont.SetName(aFontName);
     244           0 :             aFont.SetCharSet(eCharSet);
     245           0 :             bExtCharAvailable = sal_True;
     246           0 :             rSh.Left( CRSR_SKIP_CHARS, sal_False, 1, sal_False );
     247             :         }
     248           0 :         bFootnote = !aFtnNote.IsEndNote();
     249             :     }
     250           0 :     m_pNumberCharEdit->SetFont(aFont);
     251             : 
     252           0 :     sal_Bool bNumChar = sNumStr.Len() != 0;
     253             : 
     254           0 :     m_pNumberCharEdit->SetText(sNumStr);
     255           0 :     m_pNumberCharBtn->Check(bNumChar);
     256           0 :     m_pNumberAutoBtn->Check(!bNumChar);
     257           0 :     if (bNumChar)
     258           0 :         m_pNumberCharEdit->GrabFocus();
     259             : 
     260           0 :     if (bFootnote)
     261           0 :         m_pFtnBtn->Check();
     262             :     else
     263           0 :         m_pEndNoteBtn->Check();
     264             : 
     265           0 :     sal_Bool bNext = rSh.GotoNextFtnAnchor();
     266             : 
     267           0 :     if (bNext)
     268           0 :         rSh.GotoPrevFtnAnchor();
     269             : 
     270           0 :     sal_Bool bPrev = rSh.GotoPrevFtnAnchor();
     271             : 
     272           0 :     if (bPrev)
     273           0 :         rSh.GotoNextFtnAnchor();
     274             : 
     275           0 :     m_pPrevBT->Enable(bPrev);
     276           0 :     m_pNextBT->Enable(bNext);
     277             : 
     278           0 :     rSh.Right(CRSR_SKIP_CHARS, sal_True, 1, sal_False );
     279             : 
     280           0 :     rSh.EndAction();
     281           0 : }
     282             : 
     283             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10