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

Generated by: LCOV version 1.11