xref: /aoo42x/main/sw/source/core/inc/bookmrk.hxx (revision 0ca1f900)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 #ifndef _BOOKMRK_HXX
25 #define _BOOKMRK_HXX
26 
27 #include <cppuhelper/weakref.hxx>
28 
29 #include <sfx2/Metadatable.hxx>
30 
31 #include <boost/scoped_ptr.hpp>
32 #include <boost/noncopyable.hpp>
33 #include <map>
34 
35 #include <IMark.hxx>
36 
37 
38 namespace com { namespace sun { namespace star {
39     namespace text { class XTextContent; }
40 } } }
41 
42 struct SwPosition;	// fwd Decl. wg. UI
43 class SwDoc;
44 
45 namespace sw { namespace mark
46 {
47     class MarkBase
48         : virtual public IMark
49     {
50         public:
51             //getters
52             virtual SwPosition& GetMarkPos() const
53                 { return *m_pPos1; }
54             virtual const ::rtl::OUString& GetName() const
55                 { return m_aName; }
56             virtual bool IsCoveringPosition(const SwPosition& rPos) const;
57             virtual SwPosition& GetOtherMarkPos() const
58             {
59                 OSL_PRECOND(IsExpanded(), "<SwPosition::GetOtherMarkPos(..)> - I have no other Pos set." );
60                 return *m_pPos2;
61             }
62             virtual SwPosition& GetMarkStart() const
63             {
64                 if( !IsExpanded() ) return GetMarkPos( );
65                 if ( GetMarkPos( ) < GetOtherMarkPos( ) )
66                     return GetMarkPos();
67                 else
68                     return GetOtherMarkPos( );
69             }
70             virtual SwPosition& GetMarkEnd() const
71             {
72                 if( !IsExpanded() ) return GetMarkPos();
73                 if ( GetMarkPos( ) > GetOtherMarkPos( ) )
74                     return GetMarkPos( );
75                 else
76                     return GetOtherMarkPos( );
77             }
78             virtual bool IsExpanded() const
79                 { return (m_pPos2.get() != NULL); }
80 
81             //setters
82             virtual void SetName(const ::rtl::OUString& rName)
83                 { m_aName = rName; }
84             virtual void SetMarkPos(const SwPosition& rNewPos);
85             virtual void SetOtherMarkPos(const SwPosition& rNewPos);
86             virtual void ClearOtherMarkPos()
87                 { m_pPos2.reset(); }
88 
89             virtual rtl::OUString ToString( ) const;
90 
91             virtual void Swap()
92             {
93                 if(m_pPos2)
94                     m_pPos1.swap(m_pPos2);
95             }
96 
97             virtual void InitDoc(SwDoc* const)
98             {}
99 
100             virtual ~MarkBase();
101 
102             const ::com::sun::star::uno::WeakReference<
103                 ::com::sun::star::text::XTextContent> & GetXBookmark() const
104                     { return m_wXBookmark; }
105             void SetXBookmark(::com::sun::star::uno::Reference<
106                         ::com::sun::star::text::XTextContent> const& xBkmk)
107                     { m_wXBookmark = xBkmk; }
108 
109         protected:
110             // SwClient
111             virtual void Modify( const SfxPoolItem* pOld, const SfxPoolItem *pNew );
112 
113             MarkBase(const SwPaM& rPaM,
114                 const ::rtl::OUString& rName);
115             ::boost::scoped_ptr<SwPosition> m_pPos1;
116             ::boost::scoped_ptr<SwPosition> m_pPos2;
117             ::rtl::OUString m_aName;
118             static ::rtl::OUString GenerateNewName(const ::rtl::OUString& rPrefix);
119 
120             ::com::sun::star::uno::WeakReference<
121                 ::com::sun::star::text::XTextContent> m_wXBookmark;
122     };
123 
124     class NavigatorReminder
125         : public MarkBase
126     {
127         public:
128             NavigatorReminder(const SwPaM& rPaM);
129         private:
130             static const ::rtl::OUString our_sNamePrefix;
131     };
132 
133     class UnoMark
134         : public MarkBase
135     {
136         public:
137             UnoMark(const SwPaM& rPaM);
138         private:
139             static const ::rtl::OUString our_sNamePrefix;
140     };
141 
142     class DdeBookmark
143         : public MarkBase
144     {
145         public:
146             DdeBookmark(const SwPaM& rPaM);
147 
148             //getters
149             const SwServerObject* GetRefObject() const
150                 { return &m_aRefObj; }
151             SwServerObject* GetRefObject()
152                 { return &m_aRefObj; }
153 
154             bool IsServer() const
155                 { return m_aRefObj.Is(); }
156 
157             //setters
158             void SetRefObject( SwServerObject* pObj );
159 
160             void DeregisterFromDoc(SwDoc* const pDoc);
161             virtual ~DdeBookmark();
162             inline bool IsInDestruction() const
163             {
164                 return mbInDestruction;
165             }
166         private:
167             SwServerObjectRef m_aRefObj;
168             bool mbInDestruction;
169             static const ::rtl::OUString our_sNamePrefix;
170     };
171 
172     class Bookmark
173         : virtual public IBookmark
174         , public DdeBookmark
175         , public ::sfx2::Metadatable
176     {
177         public:
178             Bookmark(const SwPaM& rPaM,
179                 const KeyCode& rCode,
180                 const ::rtl::OUString& rName,
181                 const ::rtl::OUString& rShortName);
182             virtual void InitDoc(SwDoc* const io_Doc);
183 
184             virtual const ::rtl::OUString& GetShortName() const
185                 { return m_sShortName; }
186             virtual const KeyCode& GetKeyCode() const
187                 { return m_aCode; }
188             virtual void SetShortName(const ::rtl::OUString& rShortName)
189                 { m_sShortName = rShortName; }
190             virtual void SetKeyCode(const KeyCode& rCode)
191                 { m_aCode = rCode; }
192 
193             // ::sfx2::Metadatable
194             virtual ::sfx2::IXmlIdRegistry& GetRegistry();
195             virtual bool IsInClipboard() const;
196             virtual bool IsInUndo() const;
197             virtual bool IsInContent() const;
198             virtual ::com::sun::star::uno::Reference<
199                 ::com::sun::star::rdf::XMetadatable > MakeUnoObject();
200 
201         private:
202             KeyCode m_aCode;
203             ::rtl::OUString m_sShortName;
204     };
205 
206     class Fieldmark
207         : virtual public IFieldmark
208         , public MarkBase
209     {
210         public:
211             Fieldmark(const SwPaM& rPaM);
212 
213             // getters
214             virtual ::rtl::OUString GetFieldname() const
215                 { return m_aFieldname; }
216             virtual ::rtl::OUString GetFieldHelptext() const
217                 { return m_aFieldHelptext; }
218 
219             virtual IFieldmark::parameter_map_t* GetParameters()
220                 { return &m_vParams; }
221 
222             virtual const IFieldmark::parameter_map_t* GetParameters() const
223                 { return &m_vParams; }
224 
225             // setters
226             virtual void SetFieldname(const ::rtl::OUString& aFieldname)
227                 { m_aFieldname = aFieldname; }
228             virtual void SetFieldHelptext(const ::rtl::OUString& aFieldHelptext)
229                 { m_aFieldHelptext = aFieldHelptext; }
230 
231             virtual void Invalidate();
232             virtual rtl::OUString ToString() const;
233         private:
234             ::rtl::OUString m_aFieldname;
235             ::rtl::OUString m_aFieldHelptext;
236             IFieldmark::parameter_map_t m_vParams;
237 
238             static const ::rtl::OUString our_sNamePrefix;
239     };
240 
241     class TextFieldmark
242         : public Fieldmark
243     {
244         public:
245             TextFieldmark(const SwPaM& rPaM);
246             virtual void InitDoc(SwDoc* const io_pDoc);
247             void ReleaseDoc(SwDoc* const pDoc);
248     };
249 
250     class CheckboxFieldmark
251         : virtual public ICheckboxFieldmark
252         , public Fieldmark
253     {
254         public:
255             CheckboxFieldmark(const SwPaM& rPaM);
256             virtual void InitDoc(SwDoc* const io_pDoc);
257             bool IsChecked() const;
258             void SetChecked(bool checked);
259     };
260 
261 }}
262 #endif
263