LCOV - code coverage report
Current view: top level - sw/source/ui/misc - bookmark.cxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 112 0.0 %
Date: 2014-04-14 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 <comphelper/string.hxx>
      21             : #include <sfx2/request.hxx>
      22             : #include <svl/stritem.hxx>
      23             : #include <vcl/msgbox.hxx>
      24             : 
      25             : #include "view.hxx"
      26             : #include "basesh.hxx"
      27             : #include "wrtsh.hxx"
      28             : #include "cmdid.h"
      29             : #include "bookmark.hxx"
      30             : #include "IMark.hxx"
      31             : #include "globals.hrc"
      32             : 
      33           0 : const OUString BookmarkCombo::aForbiddenChars("/\\@:*?\";,.#");
      34             : 
      35           0 : IMPL_LINK( SwInsertBookmarkDlg, ModifyHdl, BookmarkCombo *, pBox )
      36             : {
      37           0 :     sal_Bool bSelEntries = pBox->GetSelectEntryCount() != 0;
      38             :     // if a string has been pasted from the clipboard then
      39             :     // there may be illegal characters in the box
      40           0 :     if(!bSelEntries)
      41             :     {
      42           0 :         OUString sTmp = pBox->GetText();
      43           0 :         const sal_Int32 nLen = sTmp.getLength();
      44           0 :         OUString sMsg;
      45           0 :         for(sal_Int32 i = 0; i < BookmarkCombo::aForbiddenChars.getLength(); i++)
      46             :         {
      47           0 :             const sal_Int32 nTmpLen = sTmp.getLength();
      48           0 :             sTmp = comphelper::string::remove(sTmp, BookmarkCombo::aForbiddenChars[i]);
      49           0 :             if(sTmp.getLength() != nTmpLen)
      50           0 :                 sMsg += OUString(BookmarkCombo::aForbiddenChars[i]);
      51             :         }
      52           0 :         if(sTmp.getLength() != nLen)
      53             :         {
      54           0 :             pBox->SetText(sTmp);
      55           0 :             InfoBox(this, sRemoveWarning+sMsg).Execute();
      56           0 :         }
      57             : 
      58             :     }
      59             : 
      60           0 :     m_pOkBtn->Enable(!bSelEntries);    // new text mark
      61           0 :     m_pDeleteBtn->Enable(bSelEntries); // deletable?
      62             : 
      63           0 :     return 0;
      64             : }
      65             : 
      66             : /*------------------------------------------------------------------------
      67             :      Description: callback to delete a text mark
      68             :  -----------------------------------------------------------------------*/
      69           0 : IMPL_LINK_NOARG(SwInsertBookmarkDlg, DeleteHdl)
      70             : {
      71             :     // remove text marks from the ComboBox
      72             : 
      73           0 :     for (sal_Int32 i = m_pBookmarkBox->GetSelectEntryCount(); i; i-- )
      74           0 :         m_pBookmarkBox->RemoveEntryAt(m_pBookmarkBox->GetSelectEntryPos(i - 1));
      75             : 
      76           0 :     m_pBookmarkBox->SetText(OUString());
      77           0 :     m_pDeleteBtn->Enable(false);   // no further entries there
      78             : 
      79           0 :     m_pOkBtn->Enable();            // the OK handler deletes
      80           0 :     return 0;
      81             : }
      82             : 
      83             : /*------------------------------------------------------------------------
      84             :      Description: callback for OKButton. Inserts a new text mark to the
      85             :      current position. Deleted text marks are also deleted in the model.
      86             :  -----------------------------------------------------------------------*/
      87           0 : void SwInsertBookmarkDlg::Apply()
      88             : {
      89             :     //at first remove deleted bookmarks to prevent multiple bookmarks with the same
      90             :     //name
      91           0 :     for (sal_Int32 nCount = m_pBookmarkBox->GetRemovedCount(); nCount > 0; nCount--)
      92             :     {
      93           0 :         OUString sRemoved = m_pBookmarkBox->GetRemovedEntry( nCount -1 ).GetName();
      94           0 :         IDocumentMarkAccess* const pMarkAccess = rSh.getIDocumentMarkAccess();
      95           0 :         pMarkAccess->deleteMark( pMarkAccess->findMark(sRemoved) );
      96           0 :         SfxRequest aReq( rSh.GetView().GetViewFrame(), FN_DELETE_BOOKMARK );
      97           0 :         aReq.AppendItem( SfxStringItem( FN_DELETE_BOOKMARK, sRemoved ) );
      98           0 :         aReq.Done();
      99           0 :     }
     100             : 
     101             :     // insert text mark
     102           0 :     SwBoxEntry  aTmpEntry(m_pBookmarkBox->GetText(), 0 );
     103             : 
     104           0 :     if (!m_pBookmarkBox->GetText().isEmpty() &&
     105           0 :         (m_pBookmarkBox->GetSwEntryPos(aTmpEntry) == COMBOBOX_ENTRY_NOTFOUND))
     106             :     {
     107           0 :         OUString sEntry(comphelper::string::remove(m_pBookmarkBox->GetText(),
     108           0 :             m_pBookmarkBox->GetMultiSelectionSeparator()));
     109             : 
     110           0 :         rSh.SetBookmark( KeyCode(), sEntry, OUString() );
     111           0 :         rReq.AppendItem( SfxStringItem( FN_INSERT_BOOKMARK, sEntry ) );
     112           0 :         rReq.Done();
     113             :     }
     114             : 
     115           0 :     if ( !rReq.IsDone() )
     116           0 :         rReq.Ignore();
     117             : 
     118           0 : }
     119             : 
     120           0 : SwInsertBookmarkDlg::SwInsertBookmarkDlg( Window *pParent, SwWrtShell &rS, SfxRequest& rRequest ) :
     121             :     SvxStandardDialog(pParent, "InsertBookmarkDialog", "modules/swriter/ui/insertbookmark.ui"),
     122             :     rSh( rS ),
     123           0 :     rReq( rRequest )
     124             : {
     125           0 :     get(m_pBookmarkBox, "bookmarks");
     126           0 :     get(m_pOkBtn, "ok");
     127           0 :     get(m_pDeleteBtn, "delete");
     128             : 
     129           0 :     m_pBookmarkBox->SetModifyHdl(LINK(this, SwInsertBookmarkDlg, ModifyHdl));
     130           0 :     m_pBookmarkBox->EnableMultiSelection(true);
     131           0 :     m_pBookmarkBox->EnableAutocomplete( true, true );
     132             : 
     133           0 :     m_pDeleteBtn->SetClickHdl(LINK(this, SwInsertBookmarkDlg, DeleteHdl));
     134             : 
     135             :     // fill Combobox with existing bookmarks
     136           0 :     IDocumentMarkAccess* const pMarkAccess = rSh.getIDocumentMarkAccess();
     137           0 :     sal_Int32 nId = 0;
     138           0 :     for( IDocumentMarkAccess::const_iterator_t ppBookmark = pMarkAccess->getBookmarksBegin();
     139           0 :         ppBookmark != pMarkAccess->getBookmarksEnd();
     140             :         ++ppBookmark)
     141             :     {
     142           0 :         if(IDocumentMarkAccess::BOOKMARK == IDocumentMarkAccess::GetType(**ppBookmark))
     143             :         {
     144             :             m_pBookmarkBox->InsertSwEntry(
     145           0 :                     SwBoxEntry(ppBookmark->get()->GetName(), nId++));
     146             :         }
     147             :     }
     148             : 
     149           0 :     sRemoveWarning = OUString(SW_RES(STR_REMOVE_WARNING));
     150           0 : }
     151             : 
     152           0 : SwInsertBookmarkDlg::~SwInsertBookmarkDlg()
     153             : {
     154           0 : }
     155             : 
     156           0 : BookmarkCombo::BookmarkCombo(Window* pWin, WinBits nStyle)
     157           0 :     : SwComboBox(pWin, nStyle)
     158             : {
     159           0 : }
     160             : 
     161           0 : sal_Int32 BookmarkCombo::GetFirstSelEntryPos() const
     162             : {
     163           0 :     return GetSelEntryPos(0);
     164             : }
     165             : 
     166           0 : sal_Int32 BookmarkCombo::GetNextSelEntryPos(sal_Int32 nPos) const
     167             : {
     168           0 :     return GetSelEntryPos(nPos + 1);
     169             : }
     170             : 
     171           0 : sal_Int32 BookmarkCombo::GetSelEntryPos(sal_Int32 nPos) const
     172             : {
     173           0 :     sal_Unicode cSep = GetMultiSelectionSeparator();
     174             : 
     175           0 :     sal_Int32 nCnt = comphelper::string::getTokenCount(GetText(), cSep);
     176             : 
     177           0 :     for (; nPos < nCnt; nPos++)
     178             :     {
     179           0 :         OUString sEntry(comphelper::string::strip(GetText().getToken(nPos, cSep), ' '));
     180           0 :         if (GetEntryPos(sEntry) != COMBOBOX_ENTRY_NOTFOUND)
     181           0 :             return nPos;
     182           0 :     }
     183             : 
     184           0 :     return COMBOBOX_ENTRY_NOTFOUND;
     185             : }
     186             : 
     187           0 : sal_Int32 BookmarkCombo::GetSelectEntryCount() const
     188             : {
     189           0 :     sal_Int32 nCnt = 0;
     190             : 
     191           0 :     sal_Int32 nPos = GetFirstSelEntryPos();
     192           0 :     while (nPos != COMBOBOX_ENTRY_NOTFOUND)
     193             :     {
     194           0 :         nPos = GetNextSelEntryPos(nPos);
     195           0 :         nCnt++;
     196             :     }
     197             : 
     198           0 :     return nCnt;
     199             : }
     200             : 
     201             : /*------------------------------------------------------------------------
     202             :      Description: position inside of the listbox (the ComboBox)
     203             :  -----------------------------------------------------------------------*/
     204           0 : sal_Int32 BookmarkCombo::GetSelectEntryPos( sal_Int32 nSelIndex ) const
     205             : {
     206           0 :     sal_Int32 nCnt = 0;
     207           0 :     sal_Int32 nPos = GetFirstSelEntryPos();
     208             : 
     209           0 :     while (nPos != COMBOBOX_ENTRY_NOTFOUND)
     210             :     {
     211           0 :         if (nSelIndex == nCnt)
     212             :         {
     213           0 :             sal_Unicode cSep = GetMultiSelectionSeparator();
     214           0 :             OUString sEntry(comphelper::string::strip(GetText().getToken(nPos, cSep), ' '));
     215           0 :             return GetEntryPos(sEntry);
     216             :         }
     217           0 :         nPos = GetNextSelEntryPos(nPos);
     218           0 :         nCnt++;
     219             :     }
     220             : 
     221           0 :     return COMBOBOX_ENTRY_NOTFOUND;
     222             : }
     223             : 
     224           0 : bool BookmarkCombo::PreNotify( NotifyEvent& rNEvt )
     225             : {
     226           0 :     bool nHandled = false;
     227           0 :     if( EVENT_KEYINPUT == rNEvt.GetType() &&
     228           0 :          rNEvt.GetKeyEvent()->GetCharCode() )
     229             :     {
     230           0 :         OUString sKey( rNEvt.GetKeyEvent()->GetCharCode() );
     231           0 :         if(-1 != aForbiddenChars.indexOf(sKey))
     232           0 :             nHandled = true;
     233             :     }
     234           0 :     if(!nHandled)
     235           0 :         nHandled = SwComboBox::PreNotify( rNEvt );
     236           0 :     return nHandled;
     237             : }
     238             : 
     239           0 : extern "C" SAL_DLLPUBLIC_EXPORT Window* SAL_CALL makeBookmarkCombo(Window* pParent, VclBuilder::stringmap &)
     240             : {
     241           0 :     return new BookmarkCombo(pParent, 0);
     242           0 : }
     243             : 
     244             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10