lib

KoTextBookmark.h
1/* This file is part of the KDE project
2 Copyright (C) 2002-2003 Laurent Montel <montel@kde.org>
3 Copyright (C) 2006 David Faure <faure@kde.org>
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details.
14
15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 Boston, MA 02110-1301, USA.
19*/
20
21#ifndef KOTEXTBOOKMARK_H
22#define KOTEXTBOOKMARK_H
23
24#include <koffice_export.h>
25#include <tqstring.h>
26#include <tqvaluelist.h>
27#include <tqmap.h>
28class KoTextParag;
29class KoTextDocument;
30
31/*
32 * A bookmark is a name associated with a single position or a run of text (start and end) in a text document.
33 */
34class KOTEXT_EXPORT KoTextBookmark {
35public:
36 KoTextBookmark( const TQString& name = TQString() );
37 KoTextBookmark( const TQString& name,
38 KoTextParag* startParag, KoTextParag* endParag,
39 int start, int end );
40
41 TQString bookmarkName() const { return m_name; }
42 void setBookmarkName( const TQString &name ) { m_name = name; }
43
44 // Note: the text document always m_startParag->document(), which is also m_endParag->document().
45 KoTextDocument* textDocument() const;
46
47 KoTextParag* startParag() const { return m_startParag; }
48 void setStartParag( KoTextParag* parag ) { m_startParag = parag; }
49
50 KoTextParag* endParag() const { return m_endParag; }
51 void setEndParag( KoTextParag* parag ) { m_endParag = parag; }
52
53 void setBookmarkStartIndex( int pos ) { m_startIndex = pos; }
54 int bookmarkStartIndex() const { return m_startIndex; }
55
56 void setBookmarkEndIndex( int end ) { m_endIndex = end; }
57 int bookmarkEndIndex() const { return m_endIndex; }
58
59 bool isSimple() const { return m_startParag == m_endParag && m_startIndex == m_endIndex; }
60
61private:
62 TQString m_name;
63 KoTextParag* m_startParag;
64 KoTextParag* m_endParag;
65 int m_startIndex;
66 int m_endIndex;
67};
68
69class KOTEXT_EXPORT KoTextBookmarkList : public TQValueList<KoTextBookmark>
70{
71public:
72 const_iterator findByName( const TQString& name ) const {
73 for ( const_iterator it = begin(), itend = end(); it != itend; ++it )
74 if ( (*it).bookmarkName() == name )
75 return it;
76 return end();
77 }
78 iterator findByName( const TQString& name ) {
79 for ( iterator it = begin(), itend = end(); it != itend; ++it )
80 if ( (*it).bookmarkName() == name )
81 return it;
82 return end();
83 }
84 bool removeByName( const TQString& name ) {
85 for ( iterator it = begin(), itend = end(); it != itend; ++it )
86 if ( (*it).bookmarkName() == name ) {
87 remove( it );
88 return true;
89 }
90 return false;
91 }
94 TQMap<const KoTextParag*, KoTextBookmarkList> bookmarksPerParagraph() const {
95 TQMap<const KoTextParag*, KoTextBookmarkList> ret;
96 for ( const_iterator it = begin(), itend = end(); it != itend; ++it ) {
97 ret[ (*it).startParag() ].append( *it );
98 if ( (*it).startParag() != (*it).endParag() )
99 ret[ (*it).endParag() ].append( *it );
100 }
101 return ret;
102 }
103};
104
105#endif /* KOTEXTBOOKMARK_H */
106
const char * name(StdAction id)