LCOV - code coverage report
Current view: top level - libreoffice/sw/source/ui/misc - bookmark.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 114 0.0 %
Date: 2012-12-27 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 = rtl::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 :     sal_uInt16      nLen = m_pBookmarkBox->GetText().Len();
     107           0 :     SwBoxEntry  aTmpEntry(m_pBookmarkBox->GetText(), 0 );
     108             : 
     109           0 :     if ( nLen && (m_pBookmarkBox->GetEntryPos(aTmpEntry) == COMBOBOX_ENTRY_NOTFOUND) )
     110             :     {
     111           0 :         String sEntry(comphelper::string::remove(m_pBookmarkBox->GetText(),
     112           0 :             m_pBookmarkBox->GetMultiSelectionSeparator()));
     113             : 
     114           0 :         rSh.SetBookmark( KeyCode(), sEntry, aEmptyStr );
     115           0 :         rReq.AppendItem( SfxStringItem( FN_INSERT_BOOKMARK, sEntry ) );
     116           0 :         rReq.Done();
     117             :     }
     118             : 
     119           0 :     if ( !rReq.IsDone() )
     120           0 :         rReq.Ignore();
     121             : 
     122           0 : }
     123             : 
     124           0 : SwInsertBookmarkDlg::SwInsertBookmarkDlg( Window *pParent, SwWrtShell &rS, SfxRequest& rRequest ) :
     125             :     SvxStandardDialog(pParent, "InsertBookmarkDialog", "modules/swriter/ui/insertbookmark.ui"),
     126             :     rSh( rS ),
     127           0 :     rReq( rRequest )
     128             : {
     129           0 :     get(m_pBookmarkBox, "bookmarks");
     130           0 :     get(m_pOkBtn, "ok");
     131           0 :     get(m_pDeleteBtn, "delete");
     132             : 
     133           0 :     m_pBookmarkBox->SetModifyHdl(LINK(this, SwInsertBookmarkDlg, ModifyHdl));
     134           0 :     m_pBookmarkBox->EnableMultiSelection(sal_True);
     135           0 :     m_pBookmarkBox->EnableAutocomplete( sal_True, sal_True );
     136             : 
     137           0 :     m_pDeleteBtn->SetClickHdl(LINK(this, SwInsertBookmarkDlg, DeleteHdl));
     138             : 
     139             :     // fill Combobox with existing bookmarks
     140           0 :     IDocumentMarkAccess* const pMarkAccess = rSh.getIDocumentMarkAccess();
     141           0 :     sal_uInt16 nId = 0;
     142           0 :     for( IDocumentMarkAccess::const_iterator_t ppBookmark = pMarkAccess->getBookmarksBegin();
     143           0 :         ppBookmark != pMarkAccess->getBookmarksEnd();
     144             :         ++ppBookmark)
     145             :     {
     146           0 :         if(IDocumentMarkAccess::BOOKMARK == IDocumentMarkAccess::GetType(**ppBookmark))
     147           0 :             m_pBookmarkBox->InsertEntry( SwBoxEntry( ppBookmark->get()->GetName(), nId++ ) );
     148             :     }
     149             : 
     150           0 :     sRemoveWarning = String(SW_RES(STR_REMOVE_WARNING));
     151           0 : }
     152             : 
     153           0 : SwInsertBookmarkDlg::~SwInsertBookmarkDlg()
     154             : {
     155           0 : }
     156             : 
     157           0 : BookmarkCombo::BookmarkCombo(Window* pWin)
     158           0 :     : SwComboBox(pWin)
     159             : {
     160           0 : }
     161             : 
     162           0 : sal_uInt16 BookmarkCombo::GetFirstSelEntryPos() const
     163             : {
     164           0 :     return GetSelEntryPos(0);
     165             : }
     166             : 
     167           0 : sal_uInt16 BookmarkCombo::GetNextSelEntryPos(sal_uInt16 nPos) const
     168             : {
     169           0 :     return GetSelEntryPos(nPos + 1);
     170             : }
     171             : 
     172           0 : sal_uInt16 BookmarkCombo::GetSelEntryPos(sal_uInt16 nPos) const
     173             : {
     174           0 :     sal_Unicode cSep = GetMultiSelectionSeparator();
     175             : 
     176           0 :     sal_uInt16 nCnt = comphelper::string::getTokenCount(GetText(), cSep);
     177             : 
     178           0 :     for (; nPos < nCnt; nPos++)
     179             :     {
     180           0 :         String sEntry(comphelper::string::strip(GetText().GetToken(nPos, cSep), ' '));
     181           0 :         if (GetEntryPos(sEntry) != COMBOBOX_ENTRY_NOTFOUND)
     182           0 :             return nPos;
     183           0 :     }
     184             : 
     185           0 :     return COMBOBOX_ENTRY_NOTFOUND;
     186             : }
     187             : 
     188           0 : sal_uInt16 BookmarkCombo::GetSelectEntryCount() const
     189             : {
     190           0 :     sal_uInt16 nCnt = 0;
     191             : 
     192           0 :     sal_uInt16 nPos = GetFirstSelEntryPos();
     193           0 :     while (nPos != COMBOBOX_ENTRY_NOTFOUND)
     194             :     {
     195           0 :         nPos = GetNextSelEntryPos(nPos);
     196           0 :         nCnt++;
     197             :     }
     198             : 
     199           0 :     return nCnt;
     200             : }
     201             : 
     202             : /*------------------------------------------------------------------------
     203             :      Description: position inside of the listbox (the ComboBox)
     204             :  -----------------------------------------------------------------------*/
     205           0 : sal_uInt16 BookmarkCombo::GetSelectEntryPos( sal_uInt16 nSelIndex ) const
     206             : {
     207           0 :     sal_uInt16 nCnt = 0;
     208           0 :     sal_uInt16 nPos = GetFirstSelEntryPos();
     209             : 
     210           0 :     while (nPos != COMBOBOX_ENTRY_NOTFOUND)
     211             :     {
     212           0 :         if (nSelIndex == nCnt)
     213             :         {
     214           0 :             sal_Unicode cSep = GetMultiSelectionSeparator();
     215           0 :             String sEntry(comphelper::string::strip(GetText().GetToken(nPos, cSep), ' '));
     216           0 :             return GetEntryPos(sEntry);
     217             :         }
     218           0 :         nPos = GetNextSelEntryPos(nPos);
     219           0 :         nCnt++;
     220             :     }
     221             : 
     222           0 :     return COMBOBOX_ENTRY_NOTFOUND;
     223             : }
     224             : 
     225           0 : long BookmarkCombo::PreNotify( NotifyEvent& rNEvt )
     226             : {
     227           0 :     long nHandled = 0;
     228           0 :     if( EVENT_KEYINPUT == rNEvt.GetType() &&
     229           0 :          rNEvt.GetKeyEvent()->GetCharCode() )
     230             :     {
     231           0 :         rtl::OUString sKey( rNEvt.GetKeyEvent()->GetCharCode() );
     232           0 :         if(STRING_NOTFOUND != aForbiddenChars.Search(sKey))
     233           0 :             nHandled = 1;
     234             :     }
     235           0 :     if(!nHandled)
     236           0 :         nHandled = SwComboBox::PreNotify( rNEvt );
     237           0 :     return nHandled;
     238             : }
     239             : 
     240           0 : extern "C" SAL_DLLPUBLIC_EXPORT Window* SAL_CALL makeBookmarkCombo(Window* pParent)
     241             : {
     242           0 :     return new BookmarkCombo(pParent);
     243           0 : }
     244             : 
     245             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10