LCOV - code coverage report
Current view: top level - sw/source/ui/misc - bookmark.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 0 112 0.0 %
Date: 2014-11-03 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 :     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             : // callback to delete a text mark
      67           0 : IMPL_LINK_NOARG(SwInsertBookmarkDlg, DeleteHdl)
      68             : {
      69             :     // remove text marks from the ComboBox
      70             : 
      71           0 :     for (sal_Int32 i = m_pBookmarkBox->GetSelectEntryCount(); i; i-- )
      72           0 :         m_pBookmarkBox->RemoveEntryAt(m_pBookmarkBox->GetSelectEntryPos(i - 1));
      73             : 
      74           0 :     m_pBookmarkBox->SetText(OUString());
      75           0 :     m_pDeleteBtn->Enable(false);   // no further entries there
      76             : 
      77           0 :     m_pOkBtn->Enable();            // the OK handler deletes
      78           0 :     return 0;
      79             : }
      80             : 
      81             : // callback for OKButton. Inserts a new text mark to the current position.
      82             : // Deleted text marks are also deleted in the model.
      83           0 : void SwInsertBookmarkDlg::Apply()
      84             : {
      85             :     //at first remove deleted bookmarks to prevent multiple bookmarks with the same
      86             :     //name
      87           0 :     for (sal_Int32 nCount = m_pBookmarkBox->GetRemovedCount(); nCount > 0; nCount--)
      88             :     {
      89           0 :         OUString sRemoved = m_pBookmarkBox->GetRemovedEntry( nCount -1 ).GetName();
      90           0 :         IDocumentMarkAccess* const pMarkAccess = rSh.getIDocumentMarkAccess();
      91           0 :         pMarkAccess->deleteMark( pMarkAccess->findMark(sRemoved) );
      92           0 :         SfxRequest aReq( rSh.GetView().GetViewFrame(), FN_DELETE_BOOKMARK );
      93           0 :         aReq.AppendItem( SfxStringItem( FN_DELETE_BOOKMARK, sRemoved ) );
      94           0 :         aReq.Done();
      95           0 :     }
      96             : 
      97             :     // insert text mark
      98           0 :     SwBoxEntry  aTmpEntry(m_pBookmarkBox->GetText(), 0 );
      99             : 
     100           0 :     if (!m_pBookmarkBox->GetText().isEmpty() &&
     101           0 :         (m_pBookmarkBox->GetSwEntryPos(aTmpEntry) == COMBOBOX_ENTRY_NOTFOUND))
     102             :     {
     103           0 :         OUString sEntry(comphelper::string::remove(m_pBookmarkBox->GetText(),
     104           0 :             m_pBookmarkBox->GetMultiSelectionSeparator()));
     105             : 
     106           0 :         rSh.SetBookmark( vcl::KeyCode(), sEntry, OUString() );
     107           0 :         rReq.AppendItem( SfxStringItem( FN_INSERT_BOOKMARK, sEntry ) );
     108           0 :         rReq.Done();
     109             :     }
     110             : 
     111           0 :     if ( !rReq.IsDone() )
     112           0 :         rReq.Ignore();
     113             : 
     114           0 : }
     115             : 
     116           0 : SwInsertBookmarkDlg::SwInsertBookmarkDlg( vcl::Window *pParent, SwWrtShell &rS, SfxRequest& rRequest ) :
     117             :     SvxStandardDialog(pParent, "InsertBookmarkDialog", "modules/swriter/ui/insertbookmark.ui"),
     118             :     rSh( rS ),
     119           0 :     rReq( rRequest )
     120             : {
     121           0 :     get(m_pBookmarkBox, "bookmarks");
     122           0 :     get(m_pOkBtn, "ok");
     123           0 :     get(m_pDeleteBtn, "delete");
     124             : 
     125           0 :     m_pBookmarkBox->SetModifyHdl(LINK(this, SwInsertBookmarkDlg, ModifyHdl));
     126           0 :     m_pBookmarkBox->EnableMultiSelection(true);
     127           0 :     m_pBookmarkBox->EnableAutocomplete( true, true );
     128             : 
     129           0 :     m_pDeleteBtn->SetClickHdl(LINK(this, SwInsertBookmarkDlg, DeleteHdl));
     130             : 
     131             :     // fill Combobox with existing bookmarks
     132           0 :     IDocumentMarkAccess* const pMarkAccess = rSh.getIDocumentMarkAccess();
     133           0 :     sal_Int32 nId = 0;
     134           0 :     for( IDocumentMarkAccess::const_iterator_t ppBookmark = pMarkAccess->getBookmarksBegin();
     135           0 :         ppBookmark != pMarkAccess->getBookmarksEnd();
     136             :         ++ppBookmark)
     137             :     {
     138           0 :         if(IDocumentMarkAccess::BOOKMARK == IDocumentMarkAccess::GetType(**ppBookmark))
     139             :         {
     140             :             m_pBookmarkBox->InsertSwEntry(
     141           0 :                     SwBoxEntry(ppBookmark->get()->GetName(), nId++));
     142             :         }
     143             :     }
     144             : 
     145           0 :     sRemoveWarning = OUString(SW_RES(STR_REMOVE_WARNING));
     146           0 : }
     147             : 
     148           0 : SwInsertBookmarkDlg::~SwInsertBookmarkDlg()
     149             : {
     150           0 : }
     151             : 
     152           0 : BookmarkCombo::BookmarkCombo(vcl::Window* pWin, WinBits nStyle)
     153           0 :     : SwComboBox(pWin, nStyle)
     154             : {
     155           0 : }
     156             : 
     157           0 : sal_Int32 BookmarkCombo::GetFirstSelEntryPos() const
     158             : {
     159           0 :     return GetSelEntryPos(0);
     160             : }
     161             : 
     162           0 : sal_Int32 BookmarkCombo::GetNextSelEntryPos(sal_Int32 nPos) const
     163             : {
     164           0 :     return GetSelEntryPos(nPos + 1);
     165             : }
     166             : 
     167           0 : sal_Int32 BookmarkCombo::GetSelEntryPos(sal_Int32 nPos) const
     168             : {
     169           0 :     sal_Unicode cSep = GetMultiSelectionSeparator();
     170             : 
     171           0 :     sal_Int32 nCnt = comphelper::string::getTokenCount(GetText(), cSep);
     172             : 
     173           0 :     for (; nPos < nCnt; nPos++)
     174             :     {
     175           0 :         OUString sEntry(comphelper::string::strip(GetText().getToken(nPos, cSep), ' '));
     176           0 :         if (GetEntryPos(sEntry) != COMBOBOX_ENTRY_NOTFOUND)
     177           0 :             return nPos;
     178           0 :     }
     179             : 
     180           0 :     return COMBOBOX_ENTRY_NOTFOUND;
     181             : }
     182             : 
     183           0 : sal_Int32 BookmarkCombo::GetSelectEntryCount() const
     184             : {
     185           0 :     sal_Int32 nCnt = 0;
     186             : 
     187           0 :     sal_Int32 nPos = GetFirstSelEntryPos();
     188           0 :     while (nPos != COMBOBOX_ENTRY_NOTFOUND)
     189             :     {
     190           0 :         nPos = GetNextSelEntryPos(nPos);
     191           0 :         nCnt++;
     192             :     }
     193             : 
     194           0 :     return nCnt;
     195             : }
     196             : 
     197             : // position inside of the listbox (the ComboBox)
     198           0 : sal_Int32 BookmarkCombo::GetSelectEntryPos( sal_Int32 nSelIndex ) const
     199             : {
     200           0 :     sal_Int32 nCnt = 0;
     201           0 :     sal_Int32 nPos = GetFirstSelEntryPos();
     202           0 :     while (nPos != COMBOBOX_ENTRY_NOTFOUND)
     203             :     {
     204           0 :         if (nSelIndex == nCnt)
     205             :         {
     206           0 :             sal_Unicode cSep = GetMultiSelectionSeparator();
     207           0 :             OUString sEntry(comphelper::string::strip(GetText().getToken(nPos, cSep), ' '));
     208           0 :             return GetEntryPos(sEntry);
     209             :         }
     210           0 :         nPos = GetNextSelEntryPos(nPos);
     211           0 :         nCnt++;
     212             :     }
     213             : 
     214           0 :     return COMBOBOX_ENTRY_NOTFOUND;
     215             : }
     216             : 
     217           0 : bool BookmarkCombo::PreNotify( NotifyEvent& rNEvt )
     218             : {
     219           0 :     bool nHandled = false;
     220           0 :     if( EVENT_KEYINPUT == rNEvt.GetType() &&
     221           0 :          rNEvt.GetKeyEvent()->GetCharCode() )
     222             :     {
     223           0 :         OUString sKey( rNEvt.GetKeyEvent()->GetCharCode() );
     224           0 :         if(-1 != aForbiddenChars.indexOf(sKey))
     225           0 :             nHandled = true;
     226             :     }
     227           0 :     if(!nHandled)
     228           0 :         nHandled = SwComboBox::PreNotify( rNEvt );
     229           0 :     return nHandled;
     230             : }
     231             : 
     232           0 : extern "C" SAL_DLLPUBLIC_EXPORT vcl::Window* SAL_CALL makeBookmarkCombo(vcl::Window* pParent, VclBuilder::stringmap &)
     233             : {
     234           0 :     return new BookmarkCombo(pParent, 0);
     235           0 : }
     236             : 
     237             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10