1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 28 #ifndef _BOOKMRK_HXX 29 #define _BOOKMRK_HXX 30 31 #include <cppuhelper/weakref.hxx> 32 33 #include <sfx2/Metadatable.hxx> 34 35 #include <boost/scoped_ptr.hpp> 36 #include <boost/noncopyable.hpp> 37 #include <map> 38 39 #include <IMark.hxx> 40 41 42 namespace com { namespace sun { namespace star { 43 namespace text { class XTextContent; } 44 } } } 45 46 struct SwPosition; // fwd Decl. wg. UI 47 class SwDoc; 48 49 namespace sw { namespace mark 50 { 51 class MarkBase 52 : virtual public IMark 53 { 54 public: 55 //getters 56 virtual SwPosition& GetMarkPos() const 57 { return *m_pPos1; } 58 virtual const ::rtl::OUString& GetName() const 59 { return m_aName; } 60 virtual bool IsCoveringPosition(const SwPosition& rPos) const; 61 virtual SwPosition& GetOtherMarkPos() const 62 { 63 OSL_PRECOND(IsExpanded(), "<SwPosition::GetOtherMarkPos(..)> - I have no other Pos set." ); 64 return *m_pPos2; 65 } 66 virtual SwPosition& GetMarkStart() const 67 { 68 if( !IsExpanded() ) return GetMarkPos( ); 69 if ( GetMarkPos( ) < GetOtherMarkPos( ) ) 70 return GetMarkPos(); 71 else 72 return GetOtherMarkPos( ); 73 } 74 virtual SwPosition& GetMarkEnd() const 75 { 76 if( !IsExpanded() ) return GetMarkPos(); 77 if ( GetMarkPos( ) > GetOtherMarkPos( ) ) 78 return GetMarkPos( ); 79 else 80 return GetOtherMarkPos( ); 81 } 82 virtual bool IsExpanded() const 83 { return m_pPos2; } 84 85 //setters 86 virtual void SetName(const ::rtl::OUString& rName) 87 { m_aName = rName; } 88 virtual void SetMarkPos(const SwPosition& rNewPos); 89 virtual void SetOtherMarkPos(const SwPosition& rNewPos); 90 virtual void ClearOtherMarkPos() 91 { m_pPos2.reset(); } 92 93 virtual rtl::OUString ToString( ) const; 94 95 virtual void Swap() 96 { 97 if(m_pPos2) 98 m_pPos1.swap(m_pPos2); 99 } 100 101 virtual void InitDoc(SwDoc* const) 102 {} 103 104 virtual ~MarkBase(); 105 106 const ::com::sun::star::uno::WeakReference< 107 ::com::sun::star::text::XTextContent> & GetXBookmark() const 108 { return m_wXBookmark; } 109 void SetXBookmark(::com::sun::star::uno::Reference< 110 ::com::sun::star::text::XTextContent> const& xBkmk) 111 { m_wXBookmark = xBkmk; } 112 113 protected: 114 // SwClient 115 virtual void Modify( const SfxPoolItem* pOld, const SfxPoolItem *pNew ); 116 117 MarkBase(const SwPaM& rPaM, 118 const ::rtl::OUString& rName); 119 ::boost::scoped_ptr<SwPosition> m_pPos1; 120 ::boost::scoped_ptr<SwPosition> m_pPos2; 121 ::rtl::OUString m_aName; 122 static ::rtl::OUString GenerateNewName(const ::rtl::OUString& rPrefix); 123 124 ::com::sun::star::uno::WeakReference< 125 ::com::sun::star::text::XTextContent> m_wXBookmark; 126 }; 127 128 class NavigatorReminder 129 : public MarkBase 130 { 131 public: 132 NavigatorReminder(const SwPaM& rPaM); 133 private: 134 static const ::rtl::OUString our_sNamePrefix; 135 }; 136 137 class UnoMark 138 : public MarkBase 139 { 140 public: 141 UnoMark(const SwPaM& rPaM); 142 private: 143 static const ::rtl::OUString our_sNamePrefix; 144 }; 145 146 class DdeBookmark 147 : public MarkBase 148 { 149 public: 150 DdeBookmark(const SwPaM& rPaM); 151 152 //getters 153 const SwServerObject* GetRefObject() const 154 { return &m_aRefObj; } 155 SwServerObject* GetRefObject() 156 { return &m_aRefObj; } 157 158 bool IsServer() const 159 { return m_aRefObj.Is(); } 160 161 //setters 162 void SetRefObject( SwServerObject* pObj ); 163 164 void DeregisterFromDoc(SwDoc* const pDoc); 165 virtual ~DdeBookmark(); 166 private: 167 SwServerObjectRef m_aRefObj; 168 static const ::rtl::OUString our_sNamePrefix; 169 }; 170 171 class Bookmark 172 : virtual public IBookmark 173 , public DdeBookmark 174 , public ::sfx2::Metadatable 175 { 176 public: 177 Bookmark(const SwPaM& rPaM, 178 const KeyCode& rCode, 179 const ::rtl::OUString& rName, 180 const ::rtl::OUString& rShortName); 181 virtual void InitDoc(SwDoc* const io_Doc); 182 183 virtual const ::rtl::OUString& GetShortName() const 184 { return m_sShortName; } 185 virtual const KeyCode& GetKeyCode() const 186 { return m_aCode; } 187 virtual void SetShortName(const ::rtl::OUString& rShortName) 188 { m_sShortName = rShortName; } 189 virtual void SetKeyCode(const KeyCode& rCode) 190 { m_aCode = rCode; } 191 192 // ::sfx2::Metadatable 193 virtual ::sfx2::IXmlIdRegistry& GetRegistry(); 194 virtual bool IsInClipboard() const; 195 virtual bool IsInUndo() const; 196 virtual bool IsInContent() const; 197 virtual ::com::sun::star::uno::Reference< 198 ::com::sun::star::rdf::XMetadatable > MakeUnoObject(); 199 200 private: 201 KeyCode m_aCode; 202 ::rtl::OUString m_sShortName; 203 }; 204 205 class Fieldmark 206 : virtual public IFieldmark 207 , public MarkBase 208 { 209 public: 210 Fieldmark(const SwPaM& rPaM); 211 212 // getters 213 virtual ::rtl::OUString GetFieldname() const 214 { return m_aFieldname; } 215 virtual ::rtl::OUString GetFieldHelptext() const 216 { return m_aFieldHelptext; } 217 218 virtual IFieldmark::parameter_map_t* GetParameters() 219 { return &m_vParams; } 220 221 virtual const IFieldmark::parameter_map_t* GetParameters() const 222 { return &m_vParams; } 223 224 // setters 225 virtual void SetFieldname(const ::rtl::OUString& aFieldname) 226 { m_aFieldname = aFieldname; } 227 virtual void SetFieldHelptext(const ::rtl::OUString& aFieldHelptext) 228 { m_aFieldHelptext = aFieldHelptext; } 229 230 virtual void Invalidate(); 231 virtual rtl::OUString ToString() const; 232 private: 233 ::rtl::OUString m_aFieldname; 234 ::rtl::OUString m_aFieldHelptext; 235 IFieldmark::parameter_map_t m_vParams; 236 237 static const ::rtl::OUString our_sNamePrefix; 238 }; 239 240 class TextFieldmark 241 : public Fieldmark 242 { 243 public: 244 TextFieldmark(const SwPaM& rPaM); 245 virtual void InitDoc(SwDoc* const io_pDoc); 246 }; 247 248 class CheckboxFieldmark 249 : virtual public ICheckboxFieldmark 250 , public Fieldmark 251 { 252 public: 253 CheckboxFieldmark(const SwPaM& rPaM); 254 virtual void InitDoc(SwDoc* const io_pDoc); 255 bool IsChecked() const; 256 void SetChecked(bool checked); 257 }; 258 259 }} 260 #endif 261