Version 5.4.3.2, tag libreoffice-5.4.3.2
[LibreOffice.git] / include / svx / frmsel.hxx
blobc91241b6965360b395884fda25696d99a11e2795
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_FRMSEL_HXX
21 #define INCLUDED_SVX_FRMSEL_HXX
23 #include <memory>
24 #include <tools/color.hxx>
25 #include <vcl/ctrl.hxx>
26 #include <vcl/bitmap.hxx>
27 #include <editeng/borderline.hxx>
28 #include <svx/framebordertype.hxx>
29 #include <svx/svxdllapi.h>
30 #include <o3tl/typed_flags_set.hxx>
32 namespace editeng {
33 class SvxBorderLine;
36 enum class FrameSelFlags
38 NONE = 0x0000,
39 /** If set, the left frame border is enabled. */
40 Left = 0x0001,
41 /** If set, the right frame border is enabled. */
42 Right = 0x0002,
43 /** If set, the top frame border is enabled. */
44 Top = 0x0004,
45 /** If set, the bottom frame border is enabled. */
46 Bottom = 0x0008,
47 /** If set, the inner horizontal frame border is enabled. */
48 InnerHorizontal = 0x0010,
49 /** If set, the inner vertical frame border is enabled. */
50 InnerVertical = 0x0020,
51 /** If set, the top-left to bottom-right diagonal frame border is enabled. */
52 DiagonalTLBR = 0x0040,
53 /** If set, the bottom-left to top-right diagonal frame border is enabled. */
54 DiagonalBLTR = 0x0080,
56 /** If set, all four outer frame borders are enabled. */
57 Outer = Left | Right | Top | Bottom,
59 /** If set, all frame borders will support the don't care state. */
60 DontCare = 0x0100
62 namespace o3tl
64 template<> struct typed_flags<FrameSelFlags> : is_typed_flags<FrameSelFlags, 0x1ff> {};
67 namespace svx {
69 struct FrameSelectorImpl;
72 /** All possible states of a frame border. */
73 enum class FrameBorderState
75 Show, /// Frame border has a visible style.
76 Hide, /// Frame border is hidden (off).
77 DontCare /// Frame border is in don't care state (if enabled).
81 class SAL_WARN_UNUSED SVX_DLLPUBLIC FrameSelector : public Control
83 public:
84 FrameSelector(vcl::Window* pParent);
85 virtual ~FrameSelector() override;
87 /** Initializes the control, enables/disables frame borders according to flags. */
88 void Initialize( FrameSelFlags nFlags );
90 // enabled frame borders --------------------------------------------------
92 /** Returns true, if the specified frame border is enabled. */
93 bool IsBorderEnabled( FrameBorderType eBorder ) const;
94 /** Returns the number of enabled frame borders. */
95 sal_Int32 GetEnabledBorderCount() const;
96 /** Returns the border type from the passed index (counts only enabled frame borders). */
97 FrameBorderType GetEnabledBorderType( sal_Int32 nIndex ) const;
98 /** Returns the index of a frame border (counts only enabled borders) from passed type. */
99 sal_Int32 GetEnabledBorderIndex( FrameBorderType eBorder ) const;
101 // frame border state and style -------------------------------------------
103 /** Returns true, if the control supports the "don't care" frame border state. */
104 bool SupportsDontCareState() const;
106 /** Returns the state (visible/hidden/don't care) of the specified frame border. */
107 FrameBorderState GetFrameBorderState( FrameBorderType eBorder ) const;
108 /** Returns the style of the specified frame border, if it is visible. */
109 const editeng::SvxBorderLine* GetFrameBorderStyle( FrameBorderType eBorder ) const;
111 /** Shows the specified frame border using the passed style, or hides it, if pStyle is 0. */
112 void ShowBorder( FrameBorderType eBorder, const editeng::SvxBorderLine* pStyle );
113 /** Sets the specified frame border to "don't care" state. */
114 void SetBorderDontCare( FrameBorderType eBorder );
116 /** Returns true, if any enabled frame border has a visible style (not "don't care"). */
117 bool IsAnyBorderVisible() const;
118 /** Hides all enabled frame borders. */
119 void HideAllBorders();
121 /** Returns true, if all visible frame borders have equal widths.
122 @descr Ignores hidden and "don't care" frame borders. On success,
123 returns the width in the passed parameter. */
124 bool GetVisibleWidth( long& rnWidth, SvxBorderLineStyle& rnStyle ) const;
125 /** Returns true, if all visible frame borders have equal color.
126 @descr Ignores hidden and "don't care" frame borders. On success,
127 returns the color in the passed parameter. */
128 bool GetVisibleColor( Color& rColor ) const;
130 // frame border selection -------------------------------------------------
132 /** Returns the current selection handler. */
133 const Link<LinkParamNone*,void>& GetSelectHdl() const;
134 /** Sets the passed handler that is called if the selection of the control changes. */
135 void SetSelectHdl( const Link<LinkParamNone*,void>& rHdl );
137 /** Returns true, if the specified frame border is selected. */
138 bool IsBorderSelected( FrameBorderType eBorder ) const;
139 /** Selects or deselects the specified frame border. */
140 void SelectBorder( FrameBorderType eBorder );
141 /** Returns true, if any of the enabled frame borders is selected. */
142 bool IsAnyBorderSelected() const;
143 /** Selects or deselects all frame borders. */
144 void SelectAllBorders( bool bSelect );
145 /** Deselects all frame borders. */
146 void DeselectAllBorders() { SelectAllBorders( false ); }
148 /** Selects or deselects all visible frame borders (ignores hidden and "don't care" borders). */
149 void SelectAllVisibleBorders();
151 /** Sets the passed line widths to all selected frame borders (in twips). */
152 void SetStyleToSelection( long nWidth, SvxBorderLineStyle nStyle );
153 /** Sets the passed color to all selected frame borders. */
154 void SetColorToSelection( const Color& rColor );
156 // accessibility ----------------------------------------------------------
158 virtual css::uno::Reference< css::accessibility::XAccessible >
159 CreateAccessible() override;
161 /** Returns the accessibility child object of the specified frame border (if enabled). */
162 css::uno::Reference< css::accessibility::XAccessible >
163 GetChildAccessible( FrameBorderType eBorder );
164 /** Returns the accessibility child object with specified index (counts enabled frame borders only). */
165 css::uno::Reference< css::accessibility::XAccessible >
166 GetChildAccessible( sal_Int32 nIndex );
167 /** Returns the accessibility child object at the specified position (relative to control). */
168 css::uno::Reference< css::accessibility::XAccessible >
169 GetChildAccessible( const Point& rPos );
171 /** Returns true, if the passed point is inside the click area of any enabled frame border. */
172 bool ContainsClickPoint( const Point& rPos ) const;
173 /** Returns the bounding rectangle of the specified frame border (if enabled). */
174 tools::Rectangle GetClickBoundRect( FrameBorderType eBorder ) const;
177 protected:
178 virtual void Paint( vcl::RenderContext& rRenderContext, const tools::Rectangle& rRect ) override;
179 virtual void MouseButtonDown( const MouseEvent& rMEvt ) override;
180 virtual void KeyInput( const KeyEvent& rKEvt ) override;
181 virtual void GetFocus() override;
182 virtual void LoseFocus() override;
183 virtual void DataChanged( const DataChangedEvent& rDCEvt ) override;
184 virtual void Resize() override;
185 virtual Size GetOptimalSize() const override;
187 private:
188 std::unique_ptr< FrameSelectorImpl > mxImpl;
194 #endif
196 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */