LibreOffice Module svx (master)  1
svdglue.hxx
Go to the documentation of this file.
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_SVDGLUE_HXX
21 #define INCLUDED_SVX_SVDGLUE_HXX
22 
23 #include <tools/gen.hxx>
24 #include <svx/svxdllapi.h>
25 #include <memory>
26 #include <vector>
27 #include <o3tl/typed_flags_set.hxx>
28 
29 namespace vcl { class Window; }
30 class OutputDevice;
31 class SvStream;
32 class SdrObject;
33 
34 
36 {
37  SMART = 0x0000,
38  LEFT = 0x0001,
39  RIGHT = 0x0002,
40  TOP = 0x0004,
41  BOTTOM = 0x0008,
42  HORZ = LEFT | RIGHT,
43  VERT = TOP | BOTTOM,
44  ALL = 0x00ff,
45 };
46 namespace o3tl
47 {
48  template<> struct typed_flags<SdrEscapeDirection> : is_typed_flags<SdrEscapeDirection, 0x00ff> {};
49 }
50 
51 enum class SdrAlign
52 {
53  NONE = 0x0000,
54  HORZ_CENTER = 0x0000,
55  HORZ_LEFT = 0x0001,
56  HORZ_RIGHT = 0x0002,
57  HORZ_DONTCARE = 0x0010,
58  VERT_CENTER = 0x0000,
59  VERT_TOP = 0x0100,
60  VERT_BOTTOM = 0x0200,
61  VERT_DONTCARE = 0x1000,
62 };
63 namespace o3tl
64 {
65  template<> struct typed_flags<SdrAlign> : is_typed_flags<SdrAlign, 0x1313> {};
66 }
67 
69  // Reference Point is SdrObject::GetSnapRect().Center()
70  // bNoPercent=false: position is -5000..5000 (1/100)% or 0..10000 (depending on align)
71  // bNoPercent=true : position is in log unit, relative to the reference point
74  sal_uInt16 nId;
76  bool bNoPercent:1;
77  bool bReallyAbsolute:1; // temp for transformations on the reference object
78  bool bUserDefined:1; // #i38892#
79 public:
80  SdrGluePoint(): nEscDir(SdrEscapeDirection::SMART),nId(0),nAlign(SdrAlign::NONE),bNoPercent(false),bReallyAbsolute(false),bUserDefined(true) {}
81  SdrGluePoint(const Point& rNewPos): aPos(rNewPos),nEscDir(SdrEscapeDirection::SMART),nId(0),nAlign(SdrAlign::NONE),bNoPercent(false),bReallyAbsolute(false),bUserDefined(true) {}
82  const Point& GetPos() const { return aPos; }
83  void SetPos(const Point& rNewPos) { aPos=rNewPos; }
84  SdrEscapeDirection GetEscDir() const { return nEscDir; }
85  void SetEscDir(SdrEscapeDirection nNewEsc) { nEscDir=nNewEsc; }
86  sal_uInt16 GetId() const { return nId; }
87  void SetId(sal_uInt16 nNewId) { nId=nNewId; }
88  bool IsPercent() const { return !bNoPercent; }
89  void SetPercent(bool bOn) { bNoPercent = !bOn; }
90  // temp for transformations on the reference object
91  void SetReallyAbsolute(bool bOn, const SdrObject& rObj);
92 
93  // #i38892#
94  bool IsUserDefined() const { return bUserDefined; }
95  void SetUserDefined(bool bNew) { bUserDefined = bNew; }
96 
97  SdrAlign GetAlign() const { return nAlign; }
98  void SetAlign(SdrAlign nAlg) { nAlign=nAlg; }
99  SdrAlign GetHorzAlign() const { return nAlign & static_cast<SdrAlign>(0x00FF); }
100  void SetHorzAlign(SdrAlign nAlg) { assert((nAlg & static_cast<SdrAlign>(0xFF00)) == SdrAlign::NONE); nAlign = SdrAlign(nAlign & static_cast<SdrAlign>(0xFF00)) | (nAlg & static_cast<SdrAlign>(0x00FF)); }
101  SdrAlign GetVertAlign() const { return nAlign & static_cast<SdrAlign>(0xFF00); }
102  void SetVertAlign(SdrAlign nAlg) { assert((nAlg & static_cast<SdrAlign>(0x00FF)) == SdrAlign::NONE); nAlign = SdrAlign(nAlign & static_cast<SdrAlign>(0x00FF)) | (nAlg & static_cast<SdrAlign>(0xFF00)); }
103  bool IsHit(const Point& rPnt, const OutputDevice& rOut, const SdrObject* pObj) const;
104  void Invalidate(vcl::Window& rWin, const SdrObject* pObj) const;
105  Point GetAbsolutePos(const SdrObject& rObj) const;
106  void SetAbsolutePos(const Point& rNewPos, const SdrObject& rObj);
107  long GetAlignAngle() const;
108  void SetAlignAngle(long nAngle);
109  static long EscDirToAngle(SdrEscapeDirection nEsc);
110  static SdrEscapeDirection EscAngleToDir(long nAngle);
111  void Rotate(const Point& rRef, long nAngle, double sn, double cs, const SdrObject* pObj);
112  void Mirror(const Point& rRef1, const Point& rRef2, long nAngle, const SdrObject* pObj);
113  void Shear (const Point& rRef, double tn, bool bVShear, const SdrObject* pObj);
114 };
115 
116 #define SDRGLUEPOINT_NOTFOUND 0xFFFF
117 
119  std::vector<std::unique_ptr<SdrGluePoint>> aList;
120 public:
122  SdrGluePointList(const SdrGluePointList& rSrcList) { *this=rSrcList; }
123 
124  void Clear();
125  SdrGluePointList& operator=(const SdrGluePointList& rSrcList);
126  sal_uInt16 GetCount() const { return sal_uInt16(aList.size()); }
127  // At insert, the object (GluePoint) automatically gets an ID assigned.
128  // Return value is the index of the new GluePoint in the list.
129  sal_uInt16 Insert(const SdrGluePoint& rGP);
130  void Delete(sal_uInt16 nPos)
131  {
132  aList.erase(aList.begin()+nPos);
133  }
134  SdrGluePoint& operator[](sal_uInt16 nPos) { return *aList[nPos]; }
135  const SdrGluePoint& operator[](sal_uInt16 nPos) const { return *aList[nPos]; }
136  sal_uInt16 FindGluePoint(sal_uInt16 nId) const;
137  sal_uInt16 HitTest(const Point& rPnt, const OutputDevice& rOut, const SdrObject* pObj) const;
138  void Invalidate(vcl::Window& rWin, const SdrObject* pObj) const;
139  // temp for transformations on the reference object
140  void SetReallyAbsolute(bool bOn, const SdrObject& rObj);
141  void Rotate(const Point& rRef, long nAngle, double sn, double cs, const SdrObject* pObj);
142  void Mirror(const Point& rRef1, const Point& rRef2, const SdrObject* pObj);
143  void Mirror(const Point& rRef1, const Point& rRef2, long nAngle, const SdrObject* pObj);
144  void Shear (const Point& rRef, double tn, bool bVShear, const SdrObject* pObj);
145 };
146 
147 
148 #endif // INCLUDED_SVX_SVDGLUE_HXX
149 
150 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
void SetId(sal_uInt16 nNewId)
Definition: svdglue.hxx:87
SdrAlign GetAlign() const
Definition: svdglue.hxx:97
const SdrGluePoint & operator[](sal_uInt16 nPos) const
Definition: svdglue.hxx:135
SdrAlign GetVertAlign() const
Definition: svdglue.hxx:101
SdrEscapeDirection
Definition: svdglue.hxx:35
void SetHorzAlign(SdrAlign nAlg)
Definition: svdglue.hxx:100
sal_uInt16 GetCount() const
Definition: svdglue.hxx:126
#define SVX_DLLPUBLIC
Definition: svxdllapi.h:28
NONE
sal_uInt16 GetId() const
Definition: svdglue.hxx:86
SdrAlign GetHorzAlign() const
Definition: svdglue.hxx:99
SdrEscapeDirection GetEscDir() const
Definition: svdglue.hxx:84
SdrAlign nAlign
Definition: svdglue.hxx:75
std::vector< std::unique_ptr< SdrGluePoint > > aList
Definition: svdglue.hxx:119
bool IsPercent() const
Definition: svdglue.hxx:88
Point aPos
Definition: svdglue.hxx:72
void SetVertAlign(SdrAlign nAlg)
Definition: svdglue.hxx:102
void SetUserDefined(bool bNew)
Definition: svdglue.hxx:95
void SetPercent(bool bOn)
Definition: svdglue.hxx:89
SdrGluePoint(const Point &rNewPos)
Definition: svdglue.hxx:81
Abstract DrawObject.
Definition: svdobj.hxx:312
void Delete(sal_uInt16 nPos)
Definition: svdglue.hxx:130
sal_uInt16 nId
Definition: svdglue.hxx:74
SdrGluePointList(const SdrGluePointList &rSrcList)
Definition: svdglue.hxx:122
SdrEscapeDirection nEscDir
Definition: svdglue.hxx:73
SdrGluePoint & operator[](sal_uInt16 nPos)
Definition: svdglue.hxx:134
const Point & GetPos() const
Definition: svdglue.hxx:82
void SetAlign(SdrAlign nAlg)
Definition: svdglue.hxx:98
bool IsUserDefined() const
Definition: svdglue.hxx:94
SdrAlign
Definition: svdglue.hxx:51
void SetEscDir(SdrEscapeDirection nNewEsc)
Definition: svdglue.hxx:85
void SetPos(const Point &rNewPos)
Definition: svdglue.hxx:83
Point Rotate(const Point &rPoint, short nOrientation, const Point &rOrigin)