xref: /trunk/main/sw/source/core/inc/bookmrk.hxx (revision edfeb9b7)
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
GetMarkPos() const52             virtual const SwPosition& GetMarkPos() const
53                 { return *m_pPos1; }
GetName() const54             virtual const ::rtl::OUString& GetName() const
55                 { return m_aName; }
56             virtual bool IsCoveringPosition(const SwPosition& rPos) const;
GetOtherMarkPos() const57             virtual const SwPosition& GetOtherMarkPos() const
58             {
59                 OSL_PRECOND(IsExpanded(), "<SwPosition::GetOtherMarkPos(..)> - I have no other Pos set." );
60                 return *m_pPos2;
61             }
GetMarkStart() const62             virtual const SwPosition& GetMarkStart() const
63             {
64                 if( !IsExpanded() ) return GetMarkPos( );
65                 if ( GetMarkPos( ) < GetOtherMarkPos( ) )
66                     return GetMarkPos();
67                 else
68                     return GetOtherMarkPos( );
69             }
GetMarkEnd() const70             virtual const SwPosition& GetMarkEnd() const
71             {
72                 if( !IsExpanded() ) return GetMarkPos();
73                 if ( GetMarkPos( ) > GetOtherMarkPos( ) )
74                     return GetMarkPos( );
75                 else
76                     return GetOtherMarkPos( );
77             }
IsExpanded() const78             virtual bool IsExpanded() const
79                 { return (m_pPos2.get() != NULL); }
80 
81             //setters
SetName(const::rtl::OUString & rName)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);
ClearOtherMarkPos()86             virtual void ClearOtherMarkPos()
87                 { m_pPos2.reset(); }
88 
89             virtual rtl::OUString ToString( ) const;
90 
Swap()91             virtual void Swap()
92             {
93                 if(m_pPos2)
94                     m_pPos1.swap(m_pPos2);
95             }
96 
InitDoc(SwDoc * const)97             virtual void InitDoc(SwDoc* const)
98             {}
99 
100             virtual ~MarkBase();
101 
102             const ::com::sun::star::uno::WeakReference<
GetXBookmark() const103                 ::com::sun::star::text::XTextContent> & GetXBookmark() const
104                     { return m_wXBookmark; }
SetXBookmark(::com::sun::star::uno::Reference<::com::sun::star::text::XTextContent> const & xBkmk)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
GetRefObject() const149             const SwServerObject* GetRefObject() const
150                 { return &m_aRefObj; }
GetRefObject()151             SwServerObject* GetRefObject()
152                 { return &m_aRefObj; }
153 
IsServer() const154             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();
IsInDestruction() const162             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 
GetShortName() const184             virtual const ::rtl::OUString& GetShortName() const
185                 { return m_sShortName; }
GetKeyCode() const186             virtual const KeyCode& GetKeyCode() const
187                 { return m_aCode; }
SetShortName(const::rtl::OUString & rShortName)188             virtual void SetShortName(const ::rtl::OUString& rShortName)
189                 { m_sShortName = rShortName; }
SetKeyCode(const KeyCode & rCode)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
GetFieldname() const214             virtual ::rtl::OUString GetFieldname() const
215                 { return m_aFieldname; }
GetFieldHelptext() const216             virtual ::rtl::OUString GetFieldHelptext() const
217                 { return m_aFieldHelptext; }
218 
GetParameters()219             virtual IFieldmark::parameter_map_t* GetParameters()
220                 { return &m_vParams; }
221 
GetParameters() const222             virtual const IFieldmark::parameter_map_t* GetParameters() const
223                 { return &m_vParams; }
224 
225             // setters
SetFieldname(const::rtl::OUString & aFieldname)226             virtual void SetFieldname(const ::rtl::OUString& aFieldname)
227                 { m_aFieldname = aFieldname; }
SetFieldHelptext(const::rtl::OUString & aFieldHelptext)228             virtual void SetFieldHelptext(const ::rtl::OUString& aFieldHelptext)
229                 { m_aFieldHelptext = aFieldHelptext; }
230 
231             void SetMarkStartPos( const SwPosition& rNewStartPos );
232             void SetMarkEndPos( const SwPosition& rNewEndPos );
233 
234             virtual void Invalidate();
235             virtual rtl::OUString ToString() const;
236         private:
237             ::rtl::OUString m_aFieldname;
238             ::rtl::OUString m_aFieldHelptext;
239             IFieldmark::parameter_map_t m_vParams;
240 
241             static const ::rtl::OUString our_sNamePrefix;
242     };
243 
244     class TextFieldmark
245         : public Fieldmark
246     {
247         public:
248             TextFieldmark(const SwPaM& rPaM);
249             virtual void InitDoc(SwDoc* const io_pDoc);
250             void ReleaseDoc(SwDoc* const pDoc);
251     };
252 
253     class CheckboxFieldmark
254         : virtual public ICheckboxFieldmark
255         , public Fieldmark
256     {
257         public:
258             CheckboxFieldmark(const SwPaM& rPaM);
259             virtual void InitDoc(SwDoc* const io_pDoc);
260             bool IsChecked() const;
261             void SetChecked(bool checked);
262     };
263 
264 }}
265 #endif
266