update dev300-m58
[ooovba.git] / sw / source / ui / misc / bookmark.cxx
blobb38c934b7c5ca4b8a7c60c0f330d0b30cc76b61e
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: bookmark.cxx,v $
10 * $Revision: 1.13 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sw.hxx"
34 #ifdef SW_DLLIMPLEMENTATION
35 #undef SW_DLLIMPLEMENTATION
36 #endif
39 #include <sfx2/request.hxx>
40 #include <svtools/stritem.hxx>
41 #include <vcl/msgbox.hxx>
44 #include "view.hxx"
45 #include "basesh.hxx"
46 #include "wrtsh.hxx" //
47 #include "cmdid.h"
48 #include "bookmark.hxx" // SwInsertBookmarkDlg
49 #include "IMark.hxx"
50 #include "bookmark.hrc"
51 #include "misc.hrc"
54 const String BookmarkCombo::aForbiddenChars = String::CreateFromAscii("/\\@:*?\";,.#");
57 IMPL_LINK( SwInsertBookmarkDlg, ModifyHdl, BookmarkCombo *, pBox )
59 BOOL bSelEntries = pBox->GetSelectEntryCount() != 0;
60 // if a string has been pasted from the clipboard then
61 // there may be illegal characters in the box
62 if(!bSelEntries)
64 String sTmp = pBox->GetText();
65 USHORT nLen = sTmp.Len();
66 String sMsg;
67 for(USHORT i = 0; i < BookmarkCombo::aForbiddenChars.Len(); i++)
69 USHORT nTmpLen = sTmp.Len();
70 sTmp.EraseAllChars(BookmarkCombo::aForbiddenChars.GetChar(i));
71 if(sTmp.Len() != nTmpLen)
72 sMsg += BookmarkCombo::aForbiddenChars.GetChar(i);
74 if(sTmp.Len() != nLen)
76 pBox->SetText(sTmp);
77 String sWarning(sRemoveWarning);
78 sWarning += sMsg;
79 InfoBox(this, sWarning).Execute();
85 aOkBtn.Enable(!bSelEntries); // neue Textmarke
86 aDeleteBtn.Enable(bSelEntries); // loeschbar?
88 return 0;
91 /*------------------------------------------------------------------------
92 Beschreibung: Callback zum Loeschen einer Textmarke
93 -----------------------------------------------------------------------*/
95 IMPL_LINK( SwInsertBookmarkDlg, DeleteHdl, Button *, EMPTYARG )
97 // Textmarken aus der ComboBox entfernen
99 for (USHORT i = aBookmarkBox.GetSelectEntryCount(); i; i-- )
100 aBookmarkBox.RemoveEntry(aBookmarkBox.GetSelectEntryPos(i - 1));
102 aBookmarkBox.SetText(aEmptyStr);
103 aDeleteBtn.Enable(FALSE); // keine weiteren Eintraege vorhanden
104 // aBookmarkBox.SetText(aEmptyStr);
106 aOkBtn.Enable(); // Im OK Handler wird geloescht
107 return 0;
110 /*------------------------------------------------------------------------
111 Beschreibung: Callback fuer OKButton. Fuegt eine neue Textmarke
112 an die akt. Position ein. Geloeschte Textmarken werden auch am Modell
113 entfernt.
114 -----------------------------------------------------------------------*/
117 void SwInsertBookmarkDlg::Apply()
119 //at first remove deleted bookmarks to prevent multiple bookmarks with the same
120 //name
121 for (USHORT nCount = aBookmarkBox.GetRemovedCount(); nCount > 0; nCount--)
123 String sRemoved = aBookmarkBox.GetRemovedEntry( nCount -1 ).GetName();
124 IDocumentMarkAccess* const pMarkAccess = rSh.getIDocumentMarkAccess();
125 pMarkAccess->deleteMark( pMarkAccess->findMark(sRemoved) );
126 SfxRequest aReq( rSh.GetView().GetViewFrame(), FN_DELETE_BOOKMARK );
127 aReq.AppendItem( SfxStringItem( FN_DELETE_BOOKMARK, sRemoved ) );
128 aReq.Done();
131 // Textmarke einfuegen
132 USHORT nLen = aBookmarkBox.GetText().Len();
133 SwBoxEntry aTmpEntry(aBookmarkBox.GetText(), 0 );
135 if ( nLen && (aBookmarkBox.GetEntryPos(aTmpEntry) == COMBOBOX_ENTRY_NOTFOUND) )
137 String sEntry(aBookmarkBox.GetText());
138 sEntry.EraseAllChars(aBookmarkBox.GetMultiSelectionSeparator());
140 rSh.SetBookmark( KeyCode(), sEntry, aEmptyStr );
141 rReq.AppendItem( SfxStringItem( FN_INSERT_BOOKMARK, sEntry ) );
142 rReq.Done();
145 if ( !rReq.IsDone() )
146 rReq.Ignore();
150 /*------------------------------------------------------------------------
151 Beschreibung: CTOR
152 -----------------------------------------------------------------------*/
155 SwInsertBookmarkDlg::SwInsertBookmarkDlg( Window *pParent, SwWrtShell &rS, SfxRequest& rRequest ) :
157 SvxStandardDialog(pParent,SW_RES(DLG_INSERT_BOOKMARK)),
159 aBookmarkBox(this,SW_RES(CB_BOOKMARK)),
160 aBookmarkFl(this,SW_RES(FL_BOOKMARK)),
161 aOkBtn(this,SW_RES(BT_OK)),
162 aCancelBtn(this,SW_RES(BT_CANCEL)),
163 aDeleteBtn(this,SW_RES(BT_DELETE)),
164 rSh( rS ),
165 rReq( rRequest )
167 aBookmarkBox.SetModifyHdl(LINK(this, SwInsertBookmarkDlg, ModifyHdl));
168 aBookmarkBox.EnableMultiSelection(TRUE);
169 aBookmarkBox.EnableAutocomplete( TRUE, TRUE );
171 aDeleteBtn.SetClickHdl(LINK(this, SwInsertBookmarkDlg, DeleteHdl));
173 // Combobox mit vorhandenen Bookmarks fuellen
174 IDocumentMarkAccess* const pMarkAccess = rSh.getIDocumentMarkAccess();
175 USHORT nId = 0;
176 for( IDocumentMarkAccess::const_iterator_t ppBookmark = pMarkAccess->getBookmarksBegin();
177 ppBookmark != pMarkAccess->getBookmarksEnd();
178 ppBookmark++)
180 if(IDocumentMarkAccess::BOOKMARK == IDocumentMarkAccess::GetType(**ppBookmark))
181 aBookmarkBox.InsertEntry( SwBoxEntry( ppBookmark->get()->GetName(), nId++ ) );
183 FreeResource();
184 sRemoveWarning = String(SW_RES(STR_REMOVE_WARNING));
187 /*------------------------------------------------------------------------
188 Beschreibung:
189 -----------------------------------------------------------------------*/
191 SwInsertBookmarkDlg::~SwInsertBookmarkDlg()
195 /*------------------------------------------------------------------------
196 Beschreibung:
197 -----------------------------------------------------------------------*/
199 BookmarkCombo::BookmarkCombo( Window* pWin, const ResId& rResId ) :
200 SwComboBox(pWin, rResId)
204 /*------------------------------------------------------------------------
205 Beschreibung:
206 -----------------------------------------------------------------------*/
208 USHORT BookmarkCombo::GetFirstSelEntryPos() const
210 return GetSelEntryPos(0);
213 /*------------------------------------------------------------------------
214 Beschreibung:
215 -----------------------------------------------------------------------*/
217 USHORT BookmarkCombo::GetNextSelEntryPos(USHORT nPos) const
219 return GetSelEntryPos(nPos + 1);
222 /*------------------------------------------------------------------------
223 Beschreibung:
224 -----------------------------------------------------------------------*/
226 USHORT BookmarkCombo::GetSelEntryPos(USHORT nPos) const
228 sal_Unicode cSep = GetMultiSelectionSeparator();
230 USHORT nCnt = GetText().GetTokenCount(cSep);
232 for (; nPos < nCnt; nPos++)
234 String sEntry(GetText().GetToken(nPos, cSep));
235 sEntry.EraseLeadingChars();
236 sEntry.EraseTrailingChars();
237 if (GetEntryPos(sEntry) != COMBOBOX_ENTRY_NOTFOUND)
238 return nPos;
241 return COMBOBOX_ENTRY_NOTFOUND;
244 /*------------------------------------------------------------------------
245 Beschreibung:
246 -----------------------------------------------------------------------*/
248 USHORT BookmarkCombo::GetSelectEntryCount() const
250 USHORT nCnt = 0;
252 USHORT nPos = GetFirstSelEntryPos();
253 while (nPos != COMBOBOX_ENTRY_NOTFOUND)
255 nPos = GetNextSelEntryPos(nPos);
256 nCnt++;
259 return nCnt;
262 /*------------------------------------------------------------------------
263 Beschreibung: Position in der Listbox (der ComboBox)
264 -----------------------------------------------------------------------*/
266 USHORT BookmarkCombo::GetSelectEntryPos( USHORT nSelIndex ) const
268 USHORT nCnt = 0;
269 USHORT nPos = GetFirstSelEntryPos();
271 while (nPos != COMBOBOX_ENTRY_NOTFOUND)
273 if (nSelIndex == nCnt)
275 sal_Unicode cSep = GetMultiSelectionSeparator();
276 String sEntry(GetText().GetToken(nPos, cSep));
277 sEntry.EraseLeadingChars();
278 sEntry.EraseTrailingChars();
280 return GetEntryPos(sEntry);
282 nPos = GetNextSelEntryPos(nPos);
283 nCnt++;
286 return COMBOBOX_ENTRY_NOTFOUND;
288 /* -----------------05.02.99 08:39-------------------
290 * --------------------------------------------------*/
291 long BookmarkCombo::PreNotify( NotifyEvent& rNEvt )
293 long nHandled = 0;
294 if( EVENT_KEYINPUT == rNEvt.GetType() &&
295 rNEvt.GetKeyEvent()->GetCharCode() )
297 String sKey( rNEvt.GetKeyEvent()->GetCharCode() );
298 if(STRING_NOTFOUND != aForbiddenChars.Search(sKey))
299 nHandled = 1;
301 if(!nHandled)
302 nHandled = SwComboBox::PreNotify( rNEvt );
303 return nHandled;