1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: bookmark.cxx,v $
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
39 #include <sfx2/request.hxx>
40 #include <svtools/stritem.hxx>
41 #include <vcl/msgbox.hxx>
46 #include "wrtsh.hxx" //
48 #include "bookmark.hxx" // SwInsertBookmarkDlg
50 #include "bookmark.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
64 String sTmp
= pBox
->GetText();
65 USHORT nLen
= sTmp
.Len();
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
)
77 String
sWarning(sRemoveWarning
);
79 InfoBox(this, sWarning
).Execute();
85 aOkBtn
.Enable(!bSelEntries
); // neue Textmarke
86 aDeleteBtn
.Enable(bSelEntries
); // loeschbar?
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
110 /*------------------------------------------------------------------------
111 Beschreibung: Callback fuer OKButton. Fuegt eine neue Textmarke
112 an die akt. Position ein. Geloeschte Textmarken werden auch am Modell
114 -----------------------------------------------------------------------*/
117 void SwInsertBookmarkDlg::Apply()
119 //at first remove deleted bookmarks to prevent multiple bookmarks with the same
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
) );
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
) );
145 if ( !rReq
.IsDone() )
150 /*------------------------------------------------------------------------
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
)),
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();
176 for( IDocumentMarkAccess::const_iterator_t ppBookmark
= pMarkAccess
->getBookmarksBegin();
177 ppBookmark
!= pMarkAccess
->getBookmarksEnd();
180 if(IDocumentMarkAccess::BOOKMARK
== IDocumentMarkAccess::GetType(**ppBookmark
))
181 aBookmarkBox
.InsertEntry( SwBoxEntry( ppBookmark
->get()->GetName(), nId
++ ) );
184 sRemoveWarning
= String(SW_RES(STR_REMOVE_WARNING
));
187 /*------------------------------------------------------------------------
189 -----------------------------------------------------------------------*/
191 SwInsertBookmarkDlg::~SwInsertBookmarkDlg()
195 /*------------------------------------------------------------------------
197 -----------------------------------------------------------------------*/
199 BookmarkCombo::BookmarkCombo( Window
* pWin
, const ResId
& rResId
) :
200 SwComboBox(pWin
, rResId
)
204 /*------------------------------------------------------------------------
206 -----------------------------------------------------------------------*/
208 USHORT
BookmarkCombo::GetFirstSelEntryPos() const
210 return GetSelEntryPos(0);
213 /*------------------------------------------------------------------------
215 -----------------------------------------------------------------------*/
217 USHORT
BookmarkCombo::GetNextSelEntryPos(USHORT nPos
) const
219 return GetSelEntryPos(nPos
+ 1);
222 /*------------------------------------------------------------------------
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
)
241 return COMBOBOX_ENTRY_NOTFOUND
;
244 /*------------------------------------------------------------------------
246 -----------------------------------------------------------------------*/
248 USHORT
BookmarkCombo::GetSelectEntryCount() const
252 USHORT nPos
= GetFirstSelEntryPos();
253 while (nPos
!= COMBOBOX_ENTRY_NOTFOUND
)
255 nPos
= GetNextSelEntryPos(nPos
);
262 /*------------------------------------------------------------------------
263 Beschreibung: Position in der Listbox (der ComboBox)
264 -----------------------------------------------------------------------*/
266 USHORT
BookmarkCombo::GetSelectEntryPos( USHORT nSelIndex
) const
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
);
286 return COMBOBOX_ENTRY_NOTFOUND
;
288 /* -----------------05.02.99 08:39-------------------
290 * --------------------------------------------------*/
291 long BookmarkCombo::PreNotify( NotifyEvent
& rNEvt
)
294 if( EVENT_KEYINPUT
== rNEvt
.GetType() &&
295 rNEvt
.GetKeyEvent()->GetCharCode() )
297 String
sKey( rNEvt
.GetKeyEvent()->GetCharCode() );
298 if(STRING_NOTFOUND
!= aForbiddenChars
.Search(sKey
))
302 nHandled
= SwComboBox::PreNotify( rNEvt
);