Branch libreoffice-5-0-4
[LibreOffice.git] / include / svx / svdglue.hxx
blob2d0b6c9541f48f61534cbf86d8e9f53a3b1d27e5
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #ifndef INCLUDED_SVX_SVDGLUE_HXX
21 #define INCLUDED_SVX_SVDGLUE_HXX
23 namespace vcl { class Window; }
24 class OutputDevice;
25 class SvStream;
26 class SdrObject;
28 #include <tools/gen.hxx>
29 #include <svx/svxdllapi.h>
30 #include <vector>
31 #include <o3tl/typed_flags_set.hxx>
34 enum class SdrEscapeDirection
36 SMART = 0x0000,
37 LEFT = 0x0001,
38 RIGHT = 0x0002,
39 TOP = 0x0004,
40 BOTTOM = 0x0008,
41 HORZ = LEFT | RIGHT,
42 VERT = TOP | BOTTOM,
43 ALL = 0x00ff,
45 namespace o3tl
47 template<> struct typed_flags<SdrEscapeDirection> : is_typed_flags<SdrEscapeDirection, 0x00ff> {};
50 enum class SdrAlign
52 NONE = 0x0000,
53 HORZ_CENTER = 0x0000,
54 HORZ_LEFT = 0x0001,
55 HORZ_RIGHT = 0x0002,
56 HORZ_DONTCARE = 0x0010,
57 VERT_CENTER = 0x0000,
58 VERT_TOP = 0x0100,
59 VERT_BOTTOM = 0x0200,
60 VERT_DONTCARE = 0x1000,
62 namespace o3tl
64 template<> struct typed_flags<SdrAlign> : is_typed_flags<SdrAlign, 0x1313> {};
67 class SVX_DLLPUBLIC SdrGluePoint {
68 // Reference Point is SdrObject::GetSnapRect().Center()
69 // bNoPercent=false: position is -5000..5000 (1/100)% or 0..10000 (depending on align)
70 // bNoPercent=true : position is in log unit, relativ to the reference point
71 Point aPos;
72 SdrEscapeDirection nEscDir;
73 sal_uInt16 nId;
74 SdrAlign nAlign;
75 bool bNoPercent:1;
76 bool bReallyAbsolute:1; // temp for transformations on the reference object
77 bool bUserDefined:1; // #i38892#
78 public:
79 SdrGluePoint(): nEscDir(SdrEscapeDirection::SMART),nId(0),nAlign(SdrAlign::NONE),bNoPercent(false),bReallyAbsolute(false),bUserDefined(true) {}
80 SdrGluePoint(const Point& rNewPos, bool bNewPercent=true, SdrAlign nNewAlign = SdrAlign::HORZ_CENTER): aPos(rNewPos),nEscDir(SdrEscapeDirection::SMART),nId(0),nAlign(nNewAlign),bNoPercent(!bNewPercent),bReallyAbsolute(false),bUserDefined(true) {}
81 bool operator==(const SdrGluePoint& rCmpGP) const { return aPos==rCmpGP.aPos && nEscDir==rCmpGP.nEscDir && nId==rCmpGP.nId && nAlign==rCmpGP.nAlign && bNoPercent==rCmpGP.bNoPercent && bReallyAbsolute==rCmpGP.bReallyAbsolute && bUserDefined==rCmpGP.bUserDefined; }
82 bool operator!=(const SdrGluePoint& rCmpGP) const { return !operator==(rCmpGP); }
83 const Point& GetPos() const { return aPos; }
84 void SetPos(const Point& rNewPos) { aPos=rNewPos; }
85 SdrEscapeDirection GetEscDir() const { return nEscDir; }
86 void SetEscDir(SdrEscapeDirection nNewEsc) { nEscDir=nNewEsc; }
87 sal_uInt16 GetId() const { return nId; }
88 void SetId(sal_uInt16 nNewId) { nId=nNewId; }
89 bool IsPercent() const { return !bNoPercent; }
90 void SetPercent(bool bOn) { bNoPercent = !bOn; }
91 // temp for transformations on the reference object
92 bool IsReallyAbsolute() const { return bReallyAbsolute; }
93 void SetReallyAbsolute(bool bOn, const SdrObject& rObj);
95 // #i38892#
96 bool IsUserDefined() const { return bUserDefined; }
97 void SetUserDefined(bool bNew) { bUserDefined = bNew; }
99 SdrAlign GetAlign() const { return nAlign; }
100 void SetAlign(SdrAlign nAlg) { nAlign=nAlg; }
101 SdrAlign GetHorzAlign() const { return nAlign & static_cast<SdrAlign>(0x00FF); }
102 void SetHorzAlign(SdrAlign nAlg) { assert((nAlg & static_cast<SdrAlign>(0xff)) == SdrAlign::NONE); nAlign = SdrAlign(nAlign & static_cast<SdrAlign>(0xFF00)) | (nAlg & static_cast<SdrAlign>(0x00FF)); }
103 SdrAlign GetVertAlign() const { return nAlign & static_cast<SdrAlign>(0xFF00); }
104 void SetVertAlign(SdrAlign nAlg) { assert((nAlg & static_cast<SdrAlign>(0xff00)) == SdrAlign::NONE); nAlign = SdrAlign(nAlign & static_cast<SdrAlign>(0x00FF)) | (nAlg & static_cast<SdrAlign>(0xFF00)); }
105 bool IsHit(const Point& rPnt, const OutputDevice& rOut, const SdrObject* pObj) const;
106 void Invalidate(vcl::Window& rWin, const SdrObject* pObj) const;
107 Point GetAbsolutePos(const SdrObject& rObj) const;
108 void SetAbsolutePos(const Point& rNewPos, const SdrObject& rObj);
109 long GetAlignAngle() const;
110 void SetAlignAngle(long nAngle);
111 static long EscDirToAngle(SdrEscapeDirection nEsc);
112 static SdrEscapeDirection EscAngleToDir(long nAngle);
113 void Rotate(const Point& rRef, long nAngle, double sn, double cs, const SdrObject* pObj);
114 void Mirror(const Point& rRef1, const Point& rRef2, long nAngle, const SdrObject* pObj);
115 void Shear (const Point& rRef, long nAngle, double tn, bool bVShear, const SdrObject* pObj);
118 #define SDRGLUEPOINT_NOTFOUND 0xFFFF
120 class SVX_DLLPUBLIC SdrGluePointList {
121 std::vector<SdrGluePoint*> aList;
122 protected:
123 SdrGluePoint* GetObject(sal_uInt16 i) const { return aList[i]; }
124 public:
125 SdrGluePointList(): aList() {}
126 SdrGluePointList(const SdrGluePointList& rSrcList): aList() { *this=rSrcList; }
127 ~SdrGluePointList() { Clear(); }
128 void Clear();
129 void operator=(const SdrGluePointList& rSrcList);
130 sal_uInt16 GetCount() const { return sal_uInt16(aList.size()); }
131 // At insert, the object (GluePoint) automatically gets an ID assigned.
132 // Return value is the index of the new GluePoint in the list.
133 sal_uInt16 Insert(const SdrGluePoint& rGP);
134 void Delete(sal_uInt16 nPos)
136 SdrGluePoint* p = aList[nPos];
137 aList.erase(aList.begin()+nPos);
138 delete p;
140 SdrGluePoint& operator[](sal_uInt16 nPos) { return *GetObject(nPos); }
141 const SdrGluePoint& operator[](sal_uInt16 nPos) const { return *GetObject(nPos); }
142 sal_uInt16 FindGluePoint(sal_uInt16 nId) const;
143 sal_uInt16 HitTest(const Point& rPnt, const OutputDevice& rOut, const SdrObject* pObj, bool bBack = false, bool bNext = false, sal_uInt16 nId0=0) const;
144 void Invalidate(vcl::Window& rWin, const SdrObject* pObj) const;
145 // temp for transformations on the reference object
146 void SetReallyAbsolute(bool bOn, const SdrObject& rObj);
147 void Rotate(const Point& rRef, long nAngle, double sn, double cs, const SdrObject* pObj);
148 void Mirror(const Point& rRef1, const Point& rRef2, const SdrObject* pObj);
149 void Mirror(const Point& rRef1, const Point& rRef2, long nAngle, const SdrObject* pObj);
150 void Shear (const Point& rRef, long nAngle, double tn, bool bVShear, const SdrObject* pObj);
156 #endif // INCLUDED_SVX_SVDGLUE_HXX
158 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */