xref: /aoo42x/main/sw/source/core/inc/bookmrk.hxx (revision 1d2dbeb0)
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; }
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         private:
163 	        SwServerObjectRef m_aRefObj;
164             static const ::rtl::OUString our_sNamePrefix;
165     };
166 
167     class Bookmark
168         : virtual public IBookmark
169         , public DdeBookmark
170         , public ::sfx2::Metadatable
171     {
172         public:
173             Bookmark(const SwPaM& rPaM,
174                 const KeyCode& rCode,
175                 const ::rtl::OUString& rName,
176                 const ::rtl::OUString& rShortName);
177             virtual void InitDoc(SwDoc* const io_Doc);
178 
179             virtual const ::rtl::OUString& GetShortName() const
180                 { return m_sShortName; }
181             virtual const KeyCode& GetKeyCode() const
182                 { return m_aCode; }
183             virtual void SetShortName(const ::rtl::OUString& rShortName)
184                 { m_sShortName = rShortName; }
185             virtual void SetKeyCode(const KeyCode& rCode)
186                 { m_aCode = rCode; }
187 
188             // ::sfx2::Metadatable
189             virtual ::sfx2::IXmlIdRegistry& GetRegistry();
190             virtual bool IsInClipboard() const;
191             virtual bool IsInUndo() const;
192             virtual bool IsInContent() const;
193             virtual ::com::sun::star::uno::Reference<
194                 ::com::sun::star::rdf::XMetadatable > MakeUnoObject();
195 
196         private:
197             KeyCode m_aCode;
198             ::rtl::OUString m_sShortName;
199     };
200 
201     class Fieldmark
202         : virtual public IFieldmark
203         , public MarkBase
204     {
205         public:
206             Fieldmark(const SwPaM& rPaM);
207 
208             // getters
209             virtual ::rtl::OUString GetFieldname() const
210                 { return m_aFieldname; }
211             virtual ::rtl::OUString GetFieldHelptext() const
212                 { return m_aFieldHelptext; }
213 
214             virtual IFieldmark::parameter_map_t* GetParameters()
215                 { return &m_vParams; }
216 
217             virtual const IFieldmark::parameter_map_t* GetParameters() const
218                 { return &m_vParams; }
219 
220             // setters
221             virtual void SetFieldname(const ::rtl::OUString& aFieldname)
222                 { m_aFieldname = aFieldname; }
223             virtual void SetFieldHelptext(const ::rtl::OUString& aFieldHelptext)
224                 { m_aFieldHelptext = aFieldHelptext; }
225 
226             virtual void Invalidate();
227             virtual rtl::OUString ToString() const;
228         private:
229             ::rtl::OUString m_aFieldname;
230             ::rtl::OUString m_aFieldHelptext;
231             IFieldmark::parameter_map_t m_vParams;
232 
233             static const ::rtl::OUString our_sNamePrefix;
234     };
235 
236     class TextFieldmark
237         : public Fieldmark
238     {
239         public:
240             TextFieldmark(const SwPaM& rPaM);
241             virtual void InitDoc(SwDoc* const io_pDoc);
242     };
243 
244     class CheckboxFieldmark
245         : virtual public ICheckboxFieldmark
246         , public Fieldmark
247     {
248         public:
249             CheckboxFieldmark(const SwPaM& rPaM);
250             virtual void InitDoc(SwDoc* const io_pDoc);
251             bool IsChecked() const;
252             void SetChecked(bool checked);
253     };
254 
255 }}
256 #endif
257