LCOV - code coverage report
Current view: top level - sw/source/core/uibase/docvw - AnnotationWin.cxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 156 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 <AnnotationWin.hxx>
      21             : 
      22             : #include <AnnotationMenuButton.hxx>
      23             : #include <PostItMgr.hxx>
      24             : 
      25             : #include <annotation.hrc>
      26             : #include <popup.hrc>
      27             : #include <cmdid.h>
      28             : 
      29             : #include <vcl/menu.hxx>
      30             : 
      31             : #include <svl/undo.hxx>
      32             : #include <unotools/syslocale.hxx>
      33             : #include <svl/languageoptions.hxx>
      34             : 
      35             : #include <editeng/postitem.hxx>
      36             : #include <editeng/fhgtitem.hxx>
      37             : #include <editeng/langitem.hxx>
      38             : 
      39             : #include <editeng/editview.hxx>
      40             : #include <editeng/outliner.hxx>
      41             : #include <editeng/editeng.hxx>
      42             : #include <editeng/editobj.hxx>
      43             : 
      44             : #include <docufld.hxx>
      45             : #include <txtfld.hxx>
      46             : #include <ndtxt.hxx>
      47             : #include <view.hxx>
      48             : #include <wrtsh.hxx>
      49             : #include <docsh.hxx>
      50             : #include <doc.hxx>
      51             : #include <IDocumentUndoRedo.hxx>
      52             : #include <SwUndoField.hxx>
      53             : 
      54             : #include <boost/scoped_ptr.hpp>
      55             : 
      56             : namespace sw { namespace annotation {
      57             : 
      58           0 : SwAnnotationWin::SwAnnotationWin( SwEditWin& rEditWin,
      59             :                                   WinBits nBits,
      60             :                                   SwPostItMgr& aMgr,
      61             :                                   SwPostItBits aBits,
      62             :                                   SwSidebarItem& rSidebarItem,
      63             :                                   SwFmtFld* aField )
      64             :     : SwSidebarWin( rEditWin, nBits, aMgr, aBits, rSidebarItem )
      65             :     , mpFmtFld(aField)
      66           0 :     , mpFld( static_cast<SwPostItField*>(aField->GetField()))
      67           0 :     , mpButtonPopup(0)
      68             : {
      69           0 : }
      70             : 
      71           0 : SwAnnotationWin::~SwAnnotationWin()
      72             : {
      73           0 :     delete mpButtonPopup;
      74           0 : }
      75             : 
      76           0 : void SwAnnotationWin::SetPostItText()
      77             : {
      78             :     //If the cursor was visible, then make it visible again after
      79             :     //changing text, e.g. fdo#33599
      80           0 :     Cursor *pCursor = GetOutlinerView()->GetEditView().GetCursor();
      81           0 :     bool bCursorVisible = pCursor ? pCursor->IsVisible() : false;
      82             : 
      83             :     //If the new text is the same as the old text, keep the same insertion
      84             :     //point .e.g. fdo#33599
      85           0 :     mpFld = static_cast<SwPostItField*>(mpFmtFld->GetField());
      86           0 :     OUString sNewText = mpFld->GetPar2();
      87           0 :     bool bTextUnchanged = sNewText.equals(Engine()->GetEditEngine().GetText());
      88           0 :     ESelection aOrigSelection(GetOutlinerView()->GetEditView().GetSelection());
      89             : 
      90             :     // get text from SwPostItField and insert into our textview
      91           0 :     Engine()->SetModifyHdl( Link() );
      92           0 :     Engine()->EnableUndo( false );
      93           0 :     if( mpFld->GetTextObject() )
      94           0 :         Engine()->SetText( *mpFld->GetTextObject() );
      95             :     else
      96             :     {
      97           0 :         Engine()->Clear();
      98           0 :         GetOutlinerView()->SetAttribs(DefaultItem());
      99           0 :         GetOutlinerView()->InsertText(sNewText,false);
     100             :     }
     101             : 
     102           0 :     Engine()->ClearModifyFlag();
     103           0 :     Engine()->GetUndoManager().Clear();
     104           0 :     Engine()->EnableUndo( true );
     105           0 :     Engine()->SetModifyHdl( LINK( this, SwAnnotationWin, ModifyHdl ) );
     106           0 :     if (bTextUnchanged)
     107           0 :         GetOutlinerView()->GetEditView().SetSelection(aOrigSelection);
     108           0 :     if (bCursorVisible)
     109           0 :         GetOutlinerView()->ShowCursor();
     110           0 :     Invalidate();
     111           0 : }
     112             : 
     113           0 : void SwAnnotationWin::UpdateData()
     114             : {
     115           0 :     if ( Engine()->IsModified() )
     116             :     {
     117             :         IDocumentUndoRedo & rUndoRedo(
     118           0 :             DocView().GetDocShell()->GetDoc()->GetIDocumentUndoRedo());
     119           0 :         boost::scoped_ptr<SwField> pOldField;
     120           0 :         if (rUndoRedo.DoesUndo())
     121             :         {
     122           0 :             pOldField.reset(mpFld->Copy());
     123             :         }
     124           0 :         mpFld->SetPar2(Engine()->GetEditEngine().GetText());
     125           0 :         mpFld->SetTextObject(Engine()->CreateParaObject());
     126           0 :         if (rUndoRedo.DoesUndo())
     127             :         {
     128           0 :             SwTxtFld *const pTxtFld = mpFmtFld->GetTxtFld();
     129           0 :             SwPosition aPosition( pTxtFld->GetTxtNode() );
     130           0 :             aPosition.nContent = *pTxtFld->GetStart();
     131             :             rUndoRedo.AppendUndo(
     132           0 :                 new SwUndoFieldFromDoc(aPosition, *pOldField, *mpFld, 0, true));
     133             :         }
     134             :         // so we get a new layout of notes (anchor position is still the same and we would otherwise not get one)
     135           0 :         Mgr().SetLayout();
     136             :         // #i98686# if we have several views, all notes should update their text
     137           0 :         mpFmtFld->Broadcast(SwFmtFldHint( 0, SWFMTFLD_CHANGED));
     138           0 :         DocView().GetDocShell()->SetModified();
     139             :     }
     140           0 :     Engine()->ClearModifyFlag();
     141           0 :     Engine()->GetUndoManager().Clear();
     142           0 : }
     143             : 
     144           0 : void SwAnnotationWin::Delete()
     145             : {
     146           0 :     SwSidebarWin::Delete();
     147             :     // we delete the field directly, the Mgr cleans up the PostIt by listening
     148           0 :     DocView().GetWrtShellPtr()->GotoField(*mpFmtFld);
     149           0 :     GrabFocusToDocument();
     150           0 :     DocView().GetWrtShellPtr()->DelRight();
     151           0 : }
     152             : 
     153           0 : void SwAnnotationWin::GotoPos()
     154             : {
     155           0 :     DocView().GetDocShell()->GetWrtShell()->GotoField(*mpFmtFld);
     156           0 : }
     157             : 
     158           0 : sal_uInt32 SwAnnotationWin::MoveCaret()
     159             : {
     160             :     // if this is an answer, do not skip over all following ones, but insert directly behind the current one
     161             :     // but when just leaving a note, skip all following ones as well to continue typing
     162           0 :     return Mgr().IsAnswer()
     163             :            ? 1
     164           0 :            : 1 + CountFollowing();
     165             : }
     166             : 
     167             : //returns true, if there is another note right before this note
     168           0 : bool SwAnnotationWin::CalcFollow()
     169             : {
     170           0 :     SwTxtFld* pTxtFld = mpFmtFld->GetTxtFld();
     171           0 :     SwPosition aPosition( pTxtFld->GetTxtNode() );
     172           0 :     aPosition.nContent = *pTxtFld->GetStart();
     173             :     SwTxtAttr * const pTxtAttr =
     174           0 :         pTxtFld->GetTxtNode().GetTxtAttrForCharAt(
     175           0 :             aPosition.nContent.GetIndex() - 1,
     176           0 :             RES_TXTATR_ANNOTATION );
     177           0 :     const SwField* pFld = pTxtAttr ? pTxtAttr->GetFmtFld().GetField() : 0;
     178           0 :     return pFld && (pFld->Which()== RES_POSTITFLD);
     179             : }
     180             : 
     181             : // counts how many SwPostItField we have right after the current one
     182           0 : sal_uInt32 SwAnnotationWin::CountFollowing()
     183             : {
     184           0 :     sal_uInt32 aCount = 1;  // we start with 1, so we have to subtract one at the end again
     185           0 :     SwTxtFld* pTxtFld = mpFmtFld->GetTxtFld();
     186           0 :     SwPosition aPosition( pTxtFld->GetTxtNode() );
     187           0 :     aPosition.nContent = *pTxtFld->GetStart();
     188             : 
     189           0 :     SwTxtAttr * pTxtAttr = pTxtFld->GetTxtNode().GetTxtAttrForCharAt(
     190           0 :                                         aPosition.nContent.GetIndex() + 1,
     191           0 :                                         RES_TXTATR_ANNOTATION );
     192             :     SwField* pFld = pTxtAttr
     193           0 :                     ? const_cast<SwField*>(pTxtAttr->GetFmtFld().GetField())
     194           0 :                     : 0;
     195           0 :     while ( pFld && ( pFld->Which()== RES_POSTITFLD ) )
     196             :     {
     197           0 :         aCount++;
     198           0 :         pTxtAttr = pTxtFld->GetTxtNode().GetTxtAttrForCharAt(
     199           0 :                                         aPosition.nContent.GetIndex() + aCount,
     200           0 :                                         RES_TXTATR_ANNOTATION );
     201             :         pFld = pTxtAttr
     202           0 :                ? const_cast<SwField*>(pTxtAttr->GetFmtFld().GetField())
     203           0 :                : 0;
     204             :     }
     205           0 :     return aCount - 1;
     206             : }
     207             : 
     208           0 : MenuButton* SwAnnotationWin::CreateMenuButton()
     209             : {
     210           0 :     mpButtonPopup = new PopupMenu(SW_RES(MN_ANNOTATION_BUTTON));
     211           0 :     OUString aText = mpButtonPopup->GetItemText( FN_DELETE_NOTE_AUTHOR );
     212           0 :     SwRewriter aRewriter;
     213           0 :     aRewriter.AddRule(UndoArg1,GetAuthor());
     214           0 :     aText = aRewriter.Apply(aText);
     215           0 :     mpButtonPopup->SetItemText(FN_DELETE_NOTE_AUTHOR,aText);
     216           0 :     MenuButton* pMenuButton = new AnnotationMenuButton( *this );
     217           0 :     pMenuButton->SetPopupMenu( mpButtonPopup );
     218           0 :     pMenuButton->Show();
     219           0 :     return pMenuButton;
     220             : }
     221             : 
     222           0 : void SwAnnotationWin::InitAnswer(OutlinerParaObject* pText)
     223             : {
     224             :     //collect our old meta data
     225           0 :     SwSidebarWin* pWin = Mgr().GetNextPostIt(KEY_PAGEUP, this);
     226           0 :     const SvtSysLocale aSysLocale;
     227           0 :     const LocaleDataWrapper& rLocalData = aSysLocale.GetLocaleData();
     228           0 :     SwRewriter aRewriter;
     229           0 :     aRewriter.AddRule(UndoArg1, pWin->GetAuthor());
     230             :     const OUString aText = aRewriter.Apply(SW_RESSTR(STR_REPLY))
     231           0 :             + " (" + rLocalData.getDate( pWin->GetDate())
     232           0 :             + ", " + rLocalData.getTime( pWin->GetTime(), false)
     233           0 :             + "): \"";
     234           0 :     GetOutlinerView()->InsertText(aText,false);
     235             : 
     236             :     // insert old, selected text or "..."
     237             :     // TODO: iterate over all paragraphs, not only first one to find out if it is empty
     238           0 :     if (!pText->GetTextObject().GetText(0).isEmpty())
     239           0 :         GetOutlinerView()->GetEditView().InsertText(pText->GetTextObject());
     240             :     else
     241           0 :         GetOutlinerView()->InsertText(OUString("..."),false);
     242           0 :     GetOutlinerView()->InsertText(OUString("\"\n"),false);
     243             : 
     244           0 :     GetOutlinerView()->SetSelection(ESelection(0,0,EE_PARA_ALL,EE_TEXTPOS_ALL));
     245           0 :     SfxItemSet aAnswerSet( DocView().GetDocShell()->GetPool() );
     246           0 :     aAnswerSet.Put(SvxFontHeightItem(200,80,EE_CHAR_FONTHEIGHT));
     247           0 :     aAnswerSet.Put(SvxPostureItem(ITALIC_NORMAL,EE_CHAR_ITALIC));
     248           0 :     GetOutlinerView()->SetAttribs(aAnswerSet);
     249           0 :     GetOutlinerView()->SetSelection(ESelection(EE_PARA_MAX_COUNT,EE_TEXTPOS_MAX_COUNT,EE_PARA_MAX_COUNT,EE_TEXTPOS_MAX_COUNT));
     250             : 
     251             :     //remove all attributes and reset our standard ones
     252           0 :     GetOutlinerView()->GetEditView().RemoveAttribsKeepLanguages(true);
     253           0 :     GetOutlinerView()->SetAttribs(DefaultItem());
     254             :     // lets insert an undo step so the initial text can be easily deleted
     255             :     // but do not use UpdateData() directly, would set modified state again and reentrance into Mgr
     256           0 :     Engine()->SetModifyHdl( Link() );
     257             :     IDocumentUndoRedo & rUndoRedo(
     258           0 :         DocView().GetDocShell()->GetDoc()->GetIDocumentUndoRedo());
     259           0 :     boost::scoped_ptr<SwField> pOldField;
     260           0 :     if (rUndoRedo.DoesUndo())
     261             :     {
     262           0 :         pOldField.reset(mpFld->Copy());
     263             :     }
     264           0 :     mpFld->SetPar2(Engine()->GetEditEngine().GetText());
     265           0 :     mpFld->SetTextObject(Engine()->CreateParaObject());
     266           0 :     if (rUndoRedo.DoesUndo())
     267             :     {
     268           0 :         SwTxtFld *const pTxtFld = mpFmtFld->GetTxtFld();
     269           0 :         SwPosition aPosition( pTxtFld->GetTxtNode() );
     270           0 :         aPosition.nContent = *pTxtFld->GetStart();
     271             :         rUndoRedo.AppendUndo(
     272           0 :             new SwUndoFieldFromDoc(aPosition, *pOldField, *mpFld, 0, true));
     273             :     }
     274           0 :     Engine()->SetModifyHdl( LINK( this, SwAnnotationWin, ModifyHdl ) );
     275           0 :     Engine()->ClearModifyFlag();
     276           0 :     Engine()->GetUndoManager().Clear();
     277           0 : }
     278             : 
     279           0 : SvxLanguageItem SwAnnotationWin::GetLanguage(void)
     280             : {
     281             :     // set initial language for outliner
     282           0 :     sal_uInt16 nScriptType = SvtLanguageOptions::GetScriptTypeOfLanguage( mpFld->GetLanguage() );
     283           0 :     sal_uInt16 nLangWhichId = 0;
     284           0 :     switch (nScriptType)
     285             :     {
     286           0 :         case SCRIPTTYPE_LATIN :    nLangWhichId = EE_CHAR_LANGUAGE ; break;
     287           0 :         case SCRIPTTYPE_ASIAN :    nLangWhichId = EE_CHAR_LANGUAGE_CJK; break;
     288           0 :         case SCRIPTTYPE_COMPLEX :  nLangWhichId = EE_CHAR_LANGUAGE_CTL; break;
     289             :         default: OSL_FAIL("GetLanguage: wrong script type");
     290             :     }
     291           0 :     return SvxLanguageItem(mpFld->GetLanguage(),nLangWhichId);
     292             : }
     293             : 
     294           0 : bool SwAnnotationWin::IsProtected()
     295             : {
     296           0 :     return SwSidebarWin::IsProtected() ||
     297           0 :            GetLayoutStatus() == SwPostItHelper::DELETED ||
     298           0 :            ( mpFmtFld ? mpFmtFld->IsProtect() : false );
     299             : }
     300             : 
     301           0 : OUString SwAnnotationWin::GetAuthor()
     302             : {
     303           0 :     return mpFld->GetPar1();
     304             : }
     305             : 
     306           0 : Date SwAnnotationWin::GetDate()
     307             : {
     308           0 :     return mpFld->GetDate();
     309             : }
     310             : 
     311           0 : Time SwAnnotationWin::GetTime()
     312             : {
     313           0 :     return mpFld->GetTime();
     314             : }
     315             : 
     316             : } } // end of namespace sw::annotation
     317             : 
     318             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10