LCOV - code coverage report
Current view: top level - usr/local/src/libreoffice/sw/source/ui/misc - bookmark.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 113 0.0 %
Date: 2013-07-09 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             : 
      26             : #include "view.hxx"
      27             : #include "basesh.hxx"
      28             : #include "wrtsh.hxx"        //
      29             : #include "cmdid.h"
      30             : #include "bookmark.hxx"     // SwInsertBookmarkDlg
      31             : #include "IMark.hxx"
      32             : #include "globals.hrc"
      33             : 
      34           0 : const String BookmarkCombo::aForbiddenChars = OUString("/\\@:*?\";,.#");
      35             : 
      36           0 : IMPL_LINK( SwInsertBookmarkDlg, ModifyHdl, BookmarkCombo *, pBox )
      37             : {
      38           0 :     sal_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 :         String sTmp = pBox->GetText();
      44           0 :         sal_uInt16 nLen = sTmp.Len();
      45           0 :         String sMsg;
      46           0 :         for(sal_uInt16 i = 0; i < BookmarkCombo::aForbiddenChars.Len(); i++)
      47             :         {
      48           0 :             sal_uInt16 nTmpLen = sTmp.Len();
      49           0 :             sTmp = comphelper::string::remove(sTmp, BookmarkCombo::aForbiddenChars.GetChar(i));
      50           0 :             if(sTmp.Len() != nTmpLen)
      51           0 :                 sMsg += BookmarkCombo::aForbiddenChars.GetChar(i);
      52             :         }
      53           0 :         if(sTmp.Len() != nLen)
      54             :         {
      55           0 :             pBox->SetText(sTmp);
      56           0 :             String sWarning(sRemoveWarning);
      57           0 :             sWarning += sMsg;
      58           0 :             InfoBox(this, sWarning).Execute();
      59           0 :         }
      60             : 
      61             : 
      62             :     }
      63             : 
      64           0 :     m_pOkBtn->Enable(!bSelEntries);    // new text mark
      65           0 :     m_pDeleteBtn->Enable(bSelEntries); // deletable?
      66             : 
      67           0 :     return 0;
      68             : }
      69             : 
      70             : /*------------------------------------------------------------------------
      71             :      Description: callback to delete a text mark
      72             :  -----------------------------------------------------------------------*/
      73           0 : IMPL_LINK_NOARG(SwInsertBookmarkDlg, DeleteHdl)
      74             : {
      75             :     // remove text marks from the ComboBox
      76             : 
      77           0 :     for (sal_uInt16 i = m_pBookmarkBox->GetSelectEntryCount(); i; i-- )
      78           0 :         m_pBookmarkBox->RemoveEntry(m_pBookmarkBox->GetSelectEntryPos(i - 1));
      79             : 
      80           0 :     m_pBookmarkBox->SetText(aEmptyStr);
      81           0 :     m_pDeleteBtn->Enable(sal_False);   // no further entries there
      82             : 
      83           0 :     m_pOkBtn->Enable();            // the OK handler deletes
      84           0 :     return 0;
      85             : }
      86             : 
      87             : /*------------------------------------------------------------------------
      88             :      Description: callback for OKButton. Inserts a new text mark to the
      89             :      current position. Deleted text marks are also deleted in the model.
      90             :  -----------------------------------------------------------------------*/
      91           0 : void SwInsertBookmarkDlg::Apply()
      92             : {
      93             :     //at first remove deleted bookmarks to prevent multiple bookmarks with the same
      94             :     //name
      95           0 :     for (sal_uInt16 nCount = m_pBookmarkBox->GetRemovedCount(); nCount > 0; nCount--)
      96             :     {
      97           0 :         String sRemoved = m_pBookmarkBox->GetRemovedEntry( nCount -1 ).GetName();
      98           0 :         IDocumentMarkAccess* const pMarkAccess = rSh.getIDocumentMarkAccess();
      99           0 :         pMarkAccess->deleteMark( pMarkAccess->findMark(sRemoved) );
     100           0 :         SfxRequest aReq( rSh.GetView().GetViewFrame(), FN_DELETE_BOOKMARK );
     101           0 :         aReq.AppendItem( SfxStringItem( FN_DELETE_BOOKMARK, sRemoved ) );
     102           0 :         aReq.Done();
     103           0 :     }
     104             : 
     105             :     // insert text mark
     106           0 :     SwBoxEntry  aTmpEntry(m_pBookmarkBox->GetText(), 0 );
     107             : 
     108           0 :     if ( !m_pBookmarkBox->GetText().isEmpty() && (m_pBookmarkBox->GetEntryPos(aTmpEntry) == COMBOBOX_ENTRY_NOTFOUND) )
     109             :     {
     110           0 :         String sEntry(comphelper::string::remove(m_pBookmarkBox->GetText(),
     111           0 :             m_pBookmarkBox->GetMultiSelectionSeparator()));
     112             : 
     113           0 :         rSh.SetBookmark( KeyCode(), sEntry, aEmptyStr );
     114           0 :         rReq.AppendItem( SfxStringItem( FN_INSERT_BOOKMARK, sEntry ) );
     115           0 :         rReq.Done();
     116             :     }
     117             : 
     118           0 :     if ( !rReq.IsDone() )
     119           0 :         rReq.Ignore();
     120             : 
     121           0 : }
     122             : 
     123           0 : SwInsertBookmarkDlg::SwInsertBookmarkDlg( Window *pParent, SwWrtShell &rS, SfxRequest& rRequest ) :
     124             :     SvxStandardDialog(pParent, "InsertBookmarkDialog", "modules/swriter/ui/insertbookmark.ui"),
     125             :     rSh( rS ),
     126           0 :     rReq( rRequest )
     127             : {
     128           0 :     get(m_pBookmarkBox, "bookmarks");
     129           0 :     get(m_pOkBtn, "ok");
     130           0 :     get(m_pDeleteBtn, "delete");
     131             : 
     132           0 :     m_pBookmarkBox->SetModifyHdl(LINK(this, SwInsertBookmarkDlg, ModifyHdl));
     133           0 :     m_pBookmarkBox->EnableMultiSelection(sal_True);
     134           0 :     m_pBookmarkBox->EnableAutocomplete( sal_True, sal_True );
     135             : 
     136           0 :     m_pDeleteBtn->SetClickHdl(LINK(this, SwInsertBookmarkDlg, DeleteHdl));
     137             : 
     138             :     // fill Combobox with existing bookmarks
     139           0 :     IDocumentMarkAccess* const pMarkAccess = rSh.getIDocumentMarkAccess();
     140           0 :     sal_uInt16 nId = 0;
     141           0 :     for( IDocumentMarkAccess::const_iterator_t ppBookmark = pMarkAccess->getBookmarksBegin();
     142           0 :         ppBookmark != pMarkAccess->getBookmarksEnd();
     143             :         ++ppBookmark)
     144             :     {
     145           0 :         if(IDocumentMarkAccess::BOOKMARK == IDocumentMarkAccess::GetType(**ppBookmark))
     146           0 :             m_pBookmarkBox->InsertEntry( SwBoxEntry( ppBookmark->get()->GetName(), nId++ ) );
     147             :     }
     148             : 
     149           0 :     sRemoveWarning = String(SW_RES(STR_REMOVE_WARNING));
     150           0 : }
     151             : 
     152           0 : SwInsertBookmarkDlg::~SwInsertBookmarkDlg()
     153             : {
     154           0 : }
     155             : 
     156           0 : BookmarkCombo::BookmarkCombo(Window* pWin)
     157           0 :     : SwComboBox(pWin)
     158             : {
     159           0 : }
     160             : 
     161           0 : sal_uInt16 BookmarkCombo::GetFirstSelEntryPos() const
     162             : {
     163           0 :     return GetSelEntryPos(0);
     164             : }
     165             : 
     166           0 : sal_uInt16 BookmarkCombo::GetNextSelEntryPos(sal_uInt16 nPos) const
     167             : {
     168           0 :     return GetSelEntryPos(nPos + 1);
     169             : }
     170             : 
     171           0 : sal_uInt16 BookmarkCombo::GetSelEntryPos(sal_uInt16 nPos) const
     172             : {
     173           0 :     sal_Unicode cSep = GetMultiSelectionSeparator();
     174             : 
     175           0 :     sal_uInt16 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_uInt16 BookmarkCombo::GetSelectEntryCount() const
     188             : {
     189           0 :     sal_uInt16 nCnt = 0;
     190             : 
     191           0 :     sal_uInt16 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_uInt16 BookmarkCombo::GetSelectEntryPos( sal_uInt16 nSelIndex ) const
     205             : {
     206           0 :     sal_uInt16 nCnt = 0;
     207           0 :     sal_uInt16 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 : long BookmarkCombo::PreNotify( NotifyEvent& rNEvt )
     225             : {
     226           0 :     long nHandled = 0;
     227           0 :     if( EVENT_KEYINPUT == rNEvt.GetType() &&
     228           0 :          rNEvt.GetKeyEvent()->GetCharCode() )
     229             :     {
     230           0 :         OUString sKey( rNEvt.GetKeyEvent()->GetCharCode() );
     231           0 :         if(STRING_NOTFOUND != aForbiddenChars.Search(sKey))
     232           0 :             nHandled = 1;
     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);
     242           0 : }
     243             : 
     244             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10