1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ 2 /* 3 * This file is part of the LibreOffice project. 4 * 5 * This Source Code Form is subject to the terms of the Mozilla Public 6 * License, v. 2.0. If a copy of the MPL was not distributed with this 7 * file, You can obtain one at http://mozilla.org/MPL/2.0/. 8 * 9 * This file incorporates work covered by the following license notice: 10 * 11 * Licensed to the Apache Software Foundation (ASF) under one or more 12 * contributor license agreements. See the NOTICE file distributed 13 * with this work for additional information regarding copyright 14 * ownership. The ASF licenses this file to you under the Apache 15 * License, Version 2.0 (the "License"); you may not use this file 16 * except in compliance with the License. You may obtain a copy of 17 * the License at http://www.apache.org/licenses/LICENSE-2.0 . 18 */ 19 20 #ifndef INCLUDED_SVX_SVDMARK_HXX 21 #define INCLUDED_SVX_SVDMARK_HXX 22 23 #include <rtl/ustring.hxx> 24 #include <svx/svxdllapi.h> 25 #include <svx/sdrobjectuser.hxx> 26 27 #include <memory> 28 #include <set> 29 #include <vector> 30 31 namespace tools { class Rectangle; } 32 class SdrPage; 33 class SdrObjList; 34 class SdrObject; 35 class SdrPageView; 36 37 typedef std::set<sal_uInt16> SdrUShortCont; 38 39 40 /** 41 * Everything a View needs to know about a selected object 42 */ 43 class SVX_DLLPUBLIC SdrMark final : public sdr::ObjectUser 44 { 45 sal_Int64 mnTimeStamp; 46 SdrObject* mpSelectedSdrObject; // the selected object 47 SdrPageView* mpPageView; 48 SdrUShortCont maPoints; // Selected Points 49 SdrUShortCont maGluePoints; // Selected Gluepoints (their Id's) 50 bool mbCon1; // for Connectors 51 bool mbCon2; // for Connectors 52 sal_uInt16 mnUser; // E.g. for CopyObjects, also copy Edges 53 54 void setTime(); 55 56 public: 57 explicit SdrMark(SdrObject* pNewObj = nullptr, SdrPageView* pNewPageView = nullptr); 58 SdrMark(const SdrMark& rMark); 59 virtual ~SdrMark(); 60 61 // Derived from ObjectUser 62 virtual void ObjectInDestruction(const SdrObject& rObject) override; 63 64 SdrMark& operator=(const SdrMark& rMark); 65 66 void SetMarkedSdrObj(SdrObject* pNewObj); GetMarkedSdrObj() const67 SdrObject* GetMarkedSdrObj() const { return mpSelectedSdrObject;} 68 GetPageView() const69 SdrPageView* GetPageView() const 70 { 71 return mpPageView; 72 } 73 SetPageView(SdrPageView * pNewPageView)74 void SetPageView(SdrPageView* pNewPageView) 75 { 76 mpPageView = pNewPageView; 77 } 78 SetCon1(bool bOn)79 void SetCon1(bool bOn) 80 { 81 mbCon1 = bOn; 82 } 83 IsCon1() const84 bool IsCon1() const 85 { 86 return mbCon1; 87 } 88 SetCon2(bool bOn)89 void SetCon2(bool bOn) 90 { 91 mbCon2 = bOn; 92 } 93 IsCon2() const94 bool IsCon2() const 95 { 96 return mbCon2; 97 } 98 SetUser(sal_uInt16 nVal)99 void SetUser(sal_uInt16 nVal) 100 { 101 mnUser = nVal; 102 } 103 GetUser() const104 sal_uInt16 GetUser() const 105 { 106 return mnUser; 107 } 108 GetMarkedPoints() const109 const SdrUShortCont& GetMarkedPoints() const 110 { 111 return maPoints; 112 } 113 GetMarkedGluePoints() const114 const SdrUShortCont& GetMarkedGluePoints() const 115 { 116 return maGluePoints; 117 } 118 GetMarkedPoints()119 SdrUShortCont& GetMarkedPoints() 120 { 121 return maPoints; 122 } 123 GetMarkedGluePoints()124 SdrUShortCont& GetMarkedGluePoints() 125 { 126 return maGluePoints; 127 } 128 getTimeStamp() const129 sal_Int64 getTimeStamp() const 130 { 131 return mnTimeStamp; 132 } 133 }; 134 135 class SVX_DLLPUBLIC SdrMarkList final 136 { 137 std::vector<std::unique_ptr<SdrMark>> maList; 138 139 OUString maMarkName; 140 OUString maPointName; 141 OUString maGluePointName; 142 143 bool mbPointNameOk; 144 bool mbGluePointNameOk; 145 bool mbNameOk; 146 bool mbSorted; 147 148 SVX_DLLPRIVATE void ImpForceSort(); 149 SVX_DLLPRIVATE const OUString& GetPointMarkDescription(bool bGlue) const; 150 151 public: SdrMarkList()152 SdrMarkList() 153 : maList(), 154 mbPointNameOk(false), 155 mbGluePointNameOk(false), 156 mbNameOk(false), 157 mbSorted(true) 158 { 159 } 160 SdrMarkList(const SdrMarkList & rLst)161 SdrMarkList(const SdrMarkList& rLst) 162 : maList() 163 { 164 *this = rLst; 165 } 166 ~SdrMarkList()167 ~SdrMarkList() 168 { 169 Clear(); 170 } 171 172 void Clear(); 173 void ForceSort() const; SetUnsorted()174 void SetUnsorted() 175 { 176 mbSorted = false; 177 } 178 GetMarkCount() const179 size_t GetMarkCount() const 180 { 181 return maList.size(); 182 } 183 184 SdrMark* GetMark(size_t nNum) const; 185 // returns SAL_MAX_SIZE if not found 186 size_t FindObject(const SdrObject* pObj) const; 187 void InsertEntry(const SdrMark& rMark, bool bChkSort = true); 188 void DeleteMark(size_t nNum); 189 void ReplaceMark(const SdrMark& rNewMark, size_t nNum); 190 void Merge(const SdrMarkList& rSrcList, bool bReverse = false); 191 bool DeletePageView(const SdrPageView& rPV); 192 bool InsertPageView(const SdrPageView& rPV); 193 SetNameDirty()194 void SetNameDirty() 195 { 196 mbNameOk = false; 197 mbPointNameOk = false; 198 mbGluePointNameOk = false; 199 } 200 201 // A verbal description of selected objects e.g.: 202 // "27 Lines", "12 Objects", "Polygon" or even "Not an object" 203 const OUString& GetMarkDescription() const; GetPointMarkDescription() const204 const OUString& GetPointMarkDescription() const 205 { 206 return GetPointMarkDescription(false); 207 } 208 GetGluePointMarkDescription() const209 const OUString& GetGluePointMarkDescription() const 210 { 211 return GetPointMarkDescription(true); 212 } 213 214 // pPage=0: Selection of everything! Respect Pages 215 bool TakeBoundRect(SdrPageView const * pPageView, tools::Rectangle& rRect) const; 216 bool TakeSnapRect(SdrPageView const * pPageView, tools::Rectangle& rRect) const; 217 218 // All Entries are copied! 219 SdrMarkList& operator=(const SdrMarkList& rLst); 220 }; 221 222 223 // migrate selections 224 225 namespace sdr 226 { 227 class SVX_DLLPUBLIC ViewSelection 228 { 229 SdrMarkList maMarkedObjectList; 230 SdrMarkList maEdgesOfMarkedNodes; 231 SdrMarkList maMarkedEdgesOfMarkedNodes; 232 std::vector<SdrObject*> maAllMarkedObjects; 233 234 bool mbEdgesOfMarkedNodesDirty : 1; 235 236 SVX_DLLPRIVATE void ImpForceEdgesOfMarkedNodes(); 237 SVX_DLLPRIVATE void ImplCollectCompleteSelection(SdrObject* pObj); 238 239 public: 240 ViewSelection(); 241 242 void SetEdgesOfMarkedNodesDirty(); 243 GetMarkedObjectList() const244 const SdrMarkList& GetMarkedObjectList() const 245 { 246 return maMarkedObjectList; 247 } 248 249 const SdrMarkList& GetEdgesOfMarkedNodes() const; 250 const SdrMarkList& GetMarkedEdgesOfMarkedNodes() const; 251 const std::vector<SdrObject*>& GetAllMarkedObjects() const; 252 GetMarkedObjectListWriteAccess()253 SdrMarkList& GetMarkedObjectListWriteAccess() 254 { 255 return maMarkedObjectList; 256 } 257 }; 258 } // end of namespace sdr 259 260 #endif // INCLUDED_SVX_SVDMARK_HXX 261 262 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ 263