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 #ifndef INCLUDED_EDITENG_ADJUSTITEM_HXX
20 #define INCLUDED_EDITENG_ADJUSTITEM_HXX
21 
22 #include <svl/cenumitm.hxx>
23 #include <svl/poolitem.hxx>
24 #include <editeng/svxenum.hxx>
25 #include <editeng/editengdllapi.h>
26 
27 // class SvxAdjustItem ---------------------------------------------------
28 
29 /*
30 [Description]
31 This item describes the row orientation.
32 */
33 constexpr sal_uInt16 ADJUST_LASTBLOCK_VERSION = 0x0001;
34 
35 class EDITENG_DLLPUBLIC SvxAdjustItem final : public SfxEnumItemInterface
36 {
37     bool    bLeft      : 1;
38     bool    bRight     : 1;
39     bool    bCenter    : 1;
40     bool    bBlock     : 1;
41 
42     // only active when bBlock
43     bool    bOneBlock : 1;
44     bool    bLastCenter : 1;
45     bool    bLastBlock : 1;
46 
47 public:
48     static SfxPoolItem* CreateDefault();
49 
50     SvxAdjustItem( const SvxAdjust eAdjst /*= SvxAdjust::Left*/,
51                    const sal_uInt16 nId );
52 
53     // "pure virtual Methods" from SfxPoolItem
54     virtual bool            operator==( const SfxPoolItem& ) const override;
55 
56     virtual bool            QueryValue( css::uno::Any& rVal, sal_uInt8 nMemberId = 0 ) const override;
57     virtual bool            PutValue( const css::uno::Any& rVal, sal_uInt8 nMemberId ) override;
58 
59     virtual bool GetPresentation( SfxItemPresentation ePres,
60                                   MapUnit eCoreMetric,
61                                   MapUnit ePresMetric,
62                                   OUString &rText, const IntlWrapper& ) const override;
63     virtual sal_uInt16       GetValueCount() const override;
64     static OUString          GetValueTextByPos( sal_uInt16 nPos );
65     virtual sal_uInt16       GetEnumValue() const override;
66     virtual void             SetEnumValue( sal_uInt16 nNewVal ) override;
67     virtual SvxAdjustItem*   Clone( SfxItemPool *pPool = nullptr ) const override;
68 
SetOneWord(const SvxAdjust eType)69     void SetOneWord( const SvxAdjust eType )
70     {
71         bOneBlock  = eType == SvxAdjust::Block;
72     }
73 
SetLastBlock(const SvxAdjust eType)74     void SetLastBlock( const SvxAdjust eType )
75     {
76         bLastBlock = eType == SvxAdjust::Block;
77         bLastCenter = eType == SvxAdjust::Center;
78     }
79 
SetAdjust(const SvxAdjust eType)80     void SetAdjust( const SvxAdjust eType )
81     {
82         bLeft = eType == SvxAdjust::Left;
83         bRight = eType == SvxAdjust::Right;
84         bCenter = eType == SvxAdjust::Center;
85         bBlock = eType == SvxAdjust::Block;
86     }
87 
GetLastBlock() const88     SvxAdjust GetLastBlock() const
89     {
90         SvxAdjust eRet = SvxAdjust::Left;
91 
92         if ( bLastBlock )
93             eRet = SvxAdjust::Block;
94         else if( bLastCenter )
95             eRet = SvxAdjust::Center;
96         return eRet;
97     }
98 
GetOneWord() const99     SvxAdjust GetOneWord() const
100     {
101         SvxAdjust eRet = SvxAdjust::Left;
102 
103         if ( bBlock && bOneBlock )
104             eRet = SvxAdjust::Block;
105         return eRet;
106     }
107 
GetAdjust() const108     SvxAdjust GetAdjust() const
109     {
110         SvxAdjust eRet = SvxAdjust::Left;
111 
112         if ( bRight )
113             eRet = SvxAdjust::Right;
114         else if ( bCenter )
115             eRet = SvxAdjust::Center;
116         else if ( bBlock )
117             eRet = SvxAdjust::Block;
118         return eRet;
119     }
120 
GetAsFlags() const121     sal_Int8 GetAsFlags() const
122     {
123         sal_Int8 nFlags = 0;
124         if ( bOneBlock )
125             nFlags |= 0x0001;
126         if ( bLastCenter )
127             nFlags |= 0x0002;
128         if ( bLastBlock )
129             nFlags |= 0x0004;
130         return nFlags;
131     }
132 
SetAsFlags(sal_Int8 nFlags)133     void SetAsFlags(sal_Int8 nFlags)
134     {
135         bOneBlock = 0 != (nFlags & 0x0001);
136         bLastCenter = 0 != (nFlags & 0x0002);
137         bLastBlock = 0 != (nFlags & 0x0004);
138     }
139 };
140 
141 #endif
142 
143 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
144