1*cdf0e10cSrcweir /************************************************************************* 2*cdf0e10cSrcweir * 3*cdf0e10cSrcweir * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4*cdf0e10cSrcweir * 5*cdf0e10cSrcweir * Copyright 2000, 2010 Oracle and/or its affiliates. 6*cdf0e10cSrcweir * 7*cdf0e10cSrcweir * OpenOffice.org - a multi-platform office productivity suite 8*cdf0e10cSrcweir * 9*cdf0e10cSrcweir * This file is part of OpenOffice.org. 10*cdf0e10cSrcweir * 11*cdf0e10cSrcweir * OpenOffice.org is free software: you can redistribute it and/or modify 12*cdf0e10cSrcweir * it under the terms of the GNU Lesser General Public License version 3 13*cdf0e10cSrcweir * only, as published by the Free Software Foundation. 14*cdf0e10cSrcweir * 15*cdf0e10cSrcweir * OpenOffice.org is distributed in the hope that it will be useful, 16*cdf0e10cSrcweir * but WITHOUT ANY WARRANTY; without even the implied warranty of 17*cdf0e10cSrcweir * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18*cdf0e10cSrcweir * GNU Lesser General Public License version 3 for more details 19*cdf0e10cSrcweir * (a copy is included in the LICENSE file that accompanied this code). 20*cdf0e10cSrcweir * 21*cdf0e10cSrcweir * You should have received a copy of the GNU Lesser General Public License 22*cdf0e10cSrcweir * version 3 along with OpenOffice.org. If not, see 23*cdf0e10cSrcweir * <http://www.openoffice.org/license.html> 24*cdf0e10cSrcweir * for a copy of the LGPLv3 License. 25*cdf0e10cSrcweir * 26*cdf0e10cSrcweir ************************************************************************/ 27*cdf0e10cSrcweir 28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 29*cdf0e10cSrcweir #include "precompiled_sw.hxx" 30*cdf0e10cSrcweir 31*cdf0e10cSrcweir #ifdef SW_DLLIMPLEMENTATION 32*cdf0e10cSrcweir #undef SW_DLLIMPLEMENTATION 33*cdf0e10cSrcweir #endif 34*cdf0e10cSrcweir 35*cdf0e10cSrcweir 36*cdf0e10cSrcweir #include <sfx2/request.hxx> 37*cdf0e10cSrcweir #include <svl/stritem.hxx> 38*cdf0e10cSrcweir #include <vcl/msgbox.hxx> 39*cdf0e10cSrcweir 40*cdf0e10cSrcweir 41*cdf0e10cSrcweir #include "view.hxx" 42*cdf0e10cSrcweir #include "basesh.hxx" 43*cdf0e10cSrcweir #include "wrtsh.hxx" // 44*cdf0e10cSrcweir #include "cmdid.h" 45*cdf0e10cSrcweir #include "bookmark.hxx" // SwInsertBookmarkDlg 46*cdf0e10cSrcweir #include "IMark.hxx" 47*cdf0e10cSrcweir #include "bookmark.hrc" 48*cdf0e10cSrcweir #include "misc.hrc" 49*cdf0e10cSrcweir 50*cdf0e10cSrcweir 51*cdf0e10cSrcweir const String BookmarkCombo::aForbiddenChars = String::CreateFromAscii("/\\@:*?\";,.#"); 52*cdf0e10cSrcweir 53*cdf0e10cSrcweir 54*cdf0e10cSrcweir IMPL_LINK( SwInsertBookmarkDlg, ModifyHdl, BookmarkCombo *, pBox ) 55*cdf0e10cSrcweir { 56*cdf0e10cSrcweir sal_Bool bSelEntries = pBox->GetSelectEntryCount() != 0; 57*cdf0e10cSrcweir // if a string has been pasted from the clipboard then 58*cdf0e10cSrcweir // there may be illegal characters in the box 59*cdf0e10cSrcweir if(!bSelEntries) 60*cdf0e10cSrcweir { 61*cdf0e10cSrcweir String sTmp = pBox->GetText(); 62*cdf0e10cSrcweir sal_uInt16 nLen = sTmp.Len(); 63*cdf0e10cSrcweir String sMsg; 64*cdf0e10cSrcweir for(sal_uInt16 i = 0; i < BookmarkCombo::aForbiddenChars.Len(); i++) 65*cdf0e10cSrcweir { 66*cdf0e10cSrcweir sal_uInt16 nTmpLen = sTmp.Len(); 67*cdf0e10cSrcweir sTmp.EraseAllChars(BookmarkCombo::aForbiddenChars.GetChar(i)); 68*cdf0e10cSrcweir if(sTmp.Len() != nTmpLen) 69*cdf0e10cSrcweir sMsg += BookmarkCombo::aForbiddenChars.GetChar(i); 70*cdf0e10cSrcweir } 71*cdf0e10cSrcweir if(sTmp.Len() != nLen) 72*cdf0e10cSrcweir { 73*cdf0e10cSrcweir pBox->SetText(sTmp); 74*cdf0e10cSrcweir String sWarning(sRemoveWarning); 75*cdf0e10cSrcweir sWarning += sMsg; 76*cdf0e10cSrcweir InfoBox(this, sWarning).Execute(); 77*cdf0e10cSrcweir } 78*cdf0e10cSrcweir 79*cdf0e10cSrcweir 80*cdf0e10cSrcweir } 81*cdf0e10cSrcweir 82*cdf0e10cSrcweir aOkBtn.Enable(!bSelEntries); // neue Textmarke 83*cdf0e10cSrcweir aDeleteBtn.Enable(bSelEntries); // loeschbar? 84*cdf0e10cSrcweir 85*cdf0e10cSrcweir return 0; 86*cdf0e10cSrcweir } 87*cdf0e10cSrcweir 88*cdf0e10cSrcweir /*------------------------------------------------------------------------ 89*cdf0e10cSrcweir Beschreibung: Callback zum Loeschen einer Textmarke 90*cdf0e10cSrcweir -----------------------------------------------------------------------*/ 91*cdf0e10cSrcweir 92*cdf0e10cSrcweir IMPL_LINK( SwInsertBookmarkDlg, DeleteHdl, Button *, EMPTYARG ) 93*cdf0e10cSrcweir { 94*cdf0e10cSrcweir // Textmarken aus der ComboBox entfernen 95*cdf0e10cSrcweir 96*cdf0e10cSrcweir for (sal_uInt16 i = aBookmarkBox.GetSelectEntryCount(); i; i-- ) 97*cdf0e10cSrcweir aBookmarkBox.RemoveEntry(aBookmarkBox.GetSelectEntryPos(i - 1)); 98*cdf0e10cSrcweir 99*cdf0e10cSrcweir aBookmarkBox.SetText(aEmptyStr); 100*cdf0e10cSrcweir aDeleteBtn.Enable(sal_False); // keine weiteren Eintraege vorhanden 101*cdf0e10cSrcweir // aBookmarkBox.SetText(aEmptyStr); 102*cdf0e10cSrcweir 103*cdf0e10cSrcweir aOkBtn.Enable(); // Im OK Handler wird geloescht 104*cdf0e10cSrcweir return 0; 105*cdf0e10cSrcweir } 106*cdf0e10cSrcweir 107*cdf0e10cSrcweir /*------------------------------------------------------------------------ 108*cdf0e10cSrcweir Beschreibung: Callback fuer OKButton. Fuegt eine neue Textmarke 109*cdf0e10cSrcweir an die akt. Position ein. Geloeschte Textmarken werden auch am Modell 110*cdf0e10cSrcweir entfernt. 111*cdf0e10cSrcweir -----------------------------------------------------------------------*/ 112*cdf0e10cSrcweir 113*cdf0e10cSrcweir 114*cdf0e10cSrcweir void SwInsertBookmarkDlg::Apply() 115*cdf0e10cSrcweir { 116*cdf0e10cSrcweir //at first remove deleted bookmarks to prevent multiple bookmarks with the same 117*cdf0e10cSrcweir //name 118*cdf0e10cSrcweir for (sal_uInt16 nCount = aBookmarkBox.GetRemovedCount(); nCount > 0; nCount--) 119*cdf0e10cSrcweir { 120*cdf0e10cSrcweir String sRemoved = aBookmarkBox.GetRemovedEntry( nCount -1 ).GetName(); 121*cdf0e10cSrcweir IDocumentMarkAccess* const pMarkAccess = rSh.getIDocumentMarkAccess(); 122*cdf0e10cSrcweir pMarkAccess->deleteMark( pMarkAccess->findMark(sRemoved) ); 123*cdf0e10cSrcweir SfxRequest aReq( rSh.GetView().GetViewFrame(), FN_DELETE_BOOKMARK ); 124*cdf0e10cSrcweir aReq.AppendItem( SfxStringItem( FN_DELETE_BOOKMARK, sRemoved ) ); 125*cdf0e10cSrcweir aReq.Done(); 126*cdf0e10cSrcweir } 127*cdf0e10cSrcweir 128*cdf0e10cSrcweir // Textmarke einfuegen 129*cdf0e10cSrcweir sal_uInt16 nLen = aBookmarkBox.GetText().Len(); 130*cdf0e10cSrcweir SwBoxEntry aTmpEntry(aBookmarkBox.GetText(), 0 ); 131*cdf0e10cSrcweir 132*cdf0e10cSrcweir if ( nLen && (aBookmarkBox.GetEntryPos(aTmpEntry) == COMBOBOX_ENTRY_NOTFOUND) ) 133*cdf0e10cSrcweir { 134*cdf0e10cSrcweir String sEntry(aBookmarkBox.GetText()); 135*cdf0e10cSrcweir sEntry.EraseAllChars(aBookmarkBox.GetMultiSelectionSeparator()); 136*cdf0e10cSrcweir 137*cdf0e10cSrcweir rSh.SetBookmark( KeyCode(), sEntry, aEmptyStr ); 138*cdf0e10cSrcweir rReq.AppendItem( SfxStringItem( FN_INSERT_BOOKMARK, sEntry ) ); 139*cdf0e10cSrcweir rReq.Done(); 140*cdf0e10cSrcweir } 141*cdf0e10cSrcweir 142*cdf0e10cSrcweir if ( !rReq.IsDone() ) 143*cdf0e10cSrcweir rReq.Ignore(); 144*cdf0e10cSrcweir 145*cdf0e10cSrcweir } 146*cdf0e10cSrcweir 147*cdf0e10cSrcweir /*------------------------------------------------------------------------ 148*cdf0e10cSrcweir Beschreibung: CTOR 149*cdf0e10cSrcweir -----------------------------------------------------------------------*/ 150*cdf0e10cSrcweir 151*cdf0e10cSrcweir 152*cdf0e10cSrcweir SwInsertBookmarkDlg::SwInsertBookmarkDlg( Window *pParent, SwWrtShell &rS, SfxRequest& rRequest ) : 153*cdf0e10cSrcweir 154*cdf0e10cSrcweir SvxStandardDialog(pParent,SW_RES(DLG_INSERT_BOOKMARK)), 155*cdf0e10cSrcweir aBookmarkFl(this,SW_RES(FL_BOOKMARK)), 156*cdf0e10cSrcweir aBookmarkBox(this,SW_RES(CB_BOOKMARK)), 157*cdf0e10cSrcweir aOkBtn(this,SW_RES(BT_OK)), 158*cdf0e10cSrcweir aCancelBtn(this,SW_RES(BT_CANCEL)), 159*cdf0e10cSrcweir aDeleteBtn(this,SW_RES(BT_DELETE)), 160*cdf0e10cSrcweir rSh( rS ), 161*cdf0e10cSrcweir rReq( rRequest ) 162*cdf0e10cSrcweir { 163*cdf0e10cSrcweir aBookmarkBox.SetModifyHdl(LINK(this, SwInsertBookmarkDlg, ModifyHdl)); 164*cdf0e10cSrcweir aBookmarkBox.EnableMultiSelection(sal_True); 165*cdf0e10cSrcweir aBookmarkBox.EnableAutocomplete( sal_True, sal_True ); 166*cdf0e10cSrcweir 167*cdf0e10cSrcweir aDeleteBtn.SetClickHdl(LINK(this, SwInsertBookmarkDlg, DeleteHdl)); 168*cdf0e10cSrcweir 169*cdf0e10cSrcweir // Combobox mit vorhandenen Bookmarks fuellen 170*cdf0e10cSrcweir IDocumentMarkAccess* const pMarkAccess = rSh.getIDocumentMarkAccess(); 171*cdf0e10cSrcweir sal_uInt16 nId = 0; 172*cdf0e10cSrcweir for( IDocumentMarkAccess::const_iterator_t ppBookmark = pMarkAccess->getBookmarksBegin(); 173*cdf0e10cSrcweir ppBookmark != pMarkAccess->getBookmarksEnd(); 174*cdf0e10cSrcweir ppBookmark++) 175*cdf0e10cSrcweir { 176*cdf0e10cSrcweir if(IDocumentMarkAccess::BOOKMARK == IDocumentMarkAccess::GetType(**ppBookmark)) 177*cdf0e10cSrcweir aBookmarkBox.InsertEntry( SwBoxEntry( ppBookmark->get()->GetName(), nId++ ) ); 178*cdf0e10cSrcweir } 179*cdf0e10cSrcweir FreeResource(); 180*cdf0e10cSrcweir sRemoveWarning = String(SW_RES(STR_REMOVE_WARNING)); 181*cdf0e10cSrcweir } 182*cdf0e10cSrcweir 183*cdf0e10cSrcweir /*------------------------------------------------------------------------ 184*cdf0e10cSrcweir Beschreibung: 185*cdf0e10cSrcweir -----------------------------------------------------------------------*/ 186*cdf0e10cSrcweir 187*cdf0e10cSrcweir SwInsertBookmarkDlg::~SwInsertBookmarkDlg() 188*cdf0e10cSrcweir { 189*cdf0e10cSrcweir } 190*cdf0e10cSrcweir 191*cdf0e10cSrcweir /*------------------------------------------------------------------------ 192*cdf0e10cSrcweir Beschreibung: 193*cdf0e10cSrcweir -----------------------------------------------------------------------*/ 194*cdf0e10cSrcweir 195*cdf0e10cSrcweir BookmarkCombo::BookmarkCombo( Window* pWin, const ResId& rResId ) : 196*cdf0e10cSrcweir SwComboBox(pWin, rResId) 197*cdf0e10cSrcweir { 198*cdf0e10cSrcweir } 199*cdf0e10cSrcweir 200*cdf0e10cSrcweir /*------------------------------------------------------------------------ 201*cdf0e10cSrcweir Beschreibung: 202*cdf0e10cSrcweir -----------------------------------------------------------------------*/ 203*cdf0e10cSrcweir 204*cdf0e10cSrcweir sal_uInt16 BookmarkCombo::GetFirstSelEntryPos() const 205*cdf0e10cSrcweir { 206*cdf0e10cSrcweir return GetSelEntryPos(0); 207*cdf0e10cSrcweir } 208*cdf0e10cSrcweir 209*cdf0e10cSrcweir /*------------------------------------------------------------------------ 210*cdf0e10cSrcweir Beschreibung: 211*cdf0e10cSrcweir -----------------------------------------------------------------------*/ 212*cdf0e10cSrcweir 213*cdf0e10cSrcweir sal_uInt16 BookmarkCombo::GetNextSelEntryPos(sal_uInt16 nPos) const 214*cdf0e10cSrcweir { 215*cdf0e10cSrcweir return GetSelEntryPos(nPos + 1); 216*cdf0e10cSrcweir } 217*cdf0e10cSrcweir 218*cdf0e10cSrcweir /*------------------------------------------------------------------------ 219*cdf0e10cSrcweir Beschreibung: 220*cdf0e10cSrcweir -----------------------------------------------------------------------*/ 221*cdf0e10cSrcweir 222*cdf0e10cSrcweir sal_uInt16 BookmarkCombo::GetSelEntryPos(sal_uInt16 nPos) const 223*cdf0e10cSrcweir { 224*cdf0e10cSrcweir sal_Unicode cSep = GetMultiSelectionSeparator(); 225*cdf0e10cSrcweir 226*cdf0e10cSrcweir sal_uInt16 nCnt = GetText().GetTokenCount(cSep); 227*cdf0e10cSrcweir 228*cdf0e10cSrcweir for (; nPos < nCnt; nPos++) 229*cdf0e10cSrcweir { 230*cdf0e10cSrcweir String sEntry(GetText().GetToken(nPos, cSep)); 231*cdf0e10cSrcweir sEntry.EraseLeadingChars(); 232*cdf0e10cSrcweir sEntry.EraseTrailingChars(); 233*cdf0e10cSrcweir if (GetEntryPos(sEntry) != COMBOBOX_ENTRY_NOTFOUND) 234*cdf0e10cSrcweir return nPos; 235*cdf0e10cSrcweir } 236*cdf0e10cSrcweir 237*cdf0e10cSrcweir return COMBOBOX_ENTRY_NOTFOUND; 238*cdf0e10cSrcweir } 239*cdf0e10cSrcweir 240*cdf0e10cSrcweir /*------------------------------------------------------------------------ 241*cdf0e10cSrcweir Beschreibung: 242*cdf0e10cSrcweir -----------------------------------------------------------------------*/ 243*cdf0e10cSrcweir 244*cdf0e10cSrcweir sal_uInt16 BookmarkCombo::GetSelectEntryCount() const 245*cdf0e10cSrcweir { 246*cdf0e10cSrcweir sal_uInt16 nCnt = 0; 247*cdf0e10cSrcweir 248*cdf0e10cSrcweir sal_uInt16 nPos = GetFirstSelEntryPos(); 249*cdf0e10cSrcweir while (nPos != COMBOBOX_ENTRY_NOTFOUND) 250*cdf0e10cSrcweir { 251*cdf0e10cSrcweir nPos = GetNextSelEntryPos(nPos); 252*cdf0e10cSrcweir nCnt++; 253*cdf0e10cSrcweir } 254*cdf0e10cSrcweir 255*cdf0e10cSrcweir return nCnt; 256*cdf0e10cSrcweir } 257*cdf0e10cSrcweir 258*cdf0e10cSrcweir /*------------------------------------------------------------------------ 259*cdf0e10cSrcweir Beschreibung: Position in der Listbox (der ComboBox) 260*cdf0e10cSrcweir -----------------------------------------------------------------------*/ 261*cdf0e10cSrcweir 262*cdf0e10cSrcweir sal_uInt16 BookmarkCombo::GetSelectEntryPos( sal_uInt16 nSelIndex ) const 263*cdf0e10cSrcweir { 264*cdf0e10cSrcweir sal_uInt16 nCnt = 0; 265*cdf0e10cSrcweir sal_uInt16 nPos = GetFirstSelEntryPos(); 266*cdf0e10cSrcweir 267*cdf0e10cSrcweir while (nPos != COMBOBOX_ENTRY_NOTFOUND) 268*cdf0e10cSrcweir { 269*cdf0e10cSrcweir if (nSelIndex == nCnt) 270*cdf0e10cSrcweir { 271*cdf0e10cSrcweir sal_Unicode cSep = GetMultiSelectionSeparator(); 272*cdf0e10cSrcweir String sEntry(GetText().GetToken(nPos, cSep)); 273*cdf0e10cSrcweir sEntry.EraseLeadingChars(); 274*cdf0e10cSrcweir sEntry.EraseTrailingChars(); 275*cdf0e10cSrcweir 276*cdf0e10cSrcweir return GetEntryPos(sEntry); 277*cdf0e10cSrcweir } 278*cdf0e10cSrcweir nPos = GetNextSelEntryPos(nPos); 279*cdf0e10cSrcweir nCnt++; 280*cdf0e10cSrcweir } 281*cdf0e10cSrcweir 282*cdf0e10cSrcweir return COMBOBOX_ENTRY_NOTFOUND; 283*cdf0e10cSrcweir } 284*cdf0e10cSrcweir /* -----------------05.02.99 08:39------------------- 285*cdf0e10cSrcweir * 286*cdf0e10cSrcweir * --------------------------------------------------*/ 287*cdf0e10cSrcweir long BookmarkCombo::PreNotify( NotifyEvent& rNEvt ) 288*cdf0e10cSrcweir { 289*cdf0e10cSrcweir long nHandled = 0; 290*cdf0e10cSrcweir if( EVENT_KEYINPUT == rNEvt.GetType() && 291*cdf0e10cSrcweir rNEvt.GetKeyEvent()->GetCharCode() ) 292*cdf0e10cSrcweir { 293*cdf0e10cSrcweir String sKey( rNEvt.GetKeyEvent()->GetCharCode() ); 294*cdf0e10cSrcweir if(STRING_NOTFOUND != aForbiddenChars.Search(sKey)) 295*cdf0e10cSrcweir nHandled = 1; 296*cdf0e10cSrcweir } 297*cdf0e10cSrcweir if(!nHandled) 298*cdf0e10cSrcweir nHandled = SwComboBox::PreNotify( rNEvt ); 299*cdf0e10cSrcweir return nHandled; 300*cdf0e10cSrcweir } 301*cdf0e10cSrcweir 302*cdf0e10cSrcweir 303*cdf0e10cSrcweir 304