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