1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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
24 #include <vcl/customweld.hxx>
25 #include <editeng/borderline.hxx>
26 #include <svx/framebordertype.hxx>
27 #include <svx/svxdllapi.h>
28 #include <o3tl/typed_flags_set.hxx>
32 enum class FrameSelFlags
35 /** If set, the left frame border is enabled. */
37 /** If set, the right frame border is enabled. */
39 /** If set, the top frame border is enabled. */
41 /** If set, the bottom frame border is enabled. */
43 /** If set, the inner horizontal frame border is enabled. */
44 InnerHorizontal
= 0x0010,
45 /** If set, the inner vertical frame border is enabled. */
46 InnerVertical
= 0x0020,
47 /** If set, the top-left to bottom-right diagonal frame border is enabled. */
48 DiagonalTLBR
= 0x0040,
49 /** If set, the bottom-left to top-right diagonal frame border is enabled. */
50 DiagonalBLTR
= 0x0080,
52 /** If set, all four outer frame borders are enabled. */
53 Outer
= Left
| Right
| Top
| Bottom
,
55 /** If set, all frame borders will support the don't care state. */
60 template<> struct typed_flags
<FrameSelFlags
> : is_typed_flags
<FrameSelFlags
, 0x1ff> {};
65 struct FrameSelectorImpl
;
66 namespace a11y
{ class AccFrameSelectorChild
; }
68 /** All possible states of a frame border. */
69 enum class FrameBorderState
71 Show
, /// Frame border has a visible style.
72 Hide
, /// Frame border is hidden (off).
73 DontCare
/// Frame border is in don't care state (if enabled).
79 class AccFrameSelector
;
82 class SAL_WARN_UNUSED SVX_DLLPUBLIC FrameSelector final
: public weld::CustomWidgetController
86 virtual void SetDrawingArea(weld::DrawingArea
* pDrawingArea
) override
;
87 virtual ~FrameSelector() override
;
89 /** Initializes the control, enables/disables frame borders according to flags. */
90 void Initialize( FrameSelFlags nFlags
);
92 // enabled frame borders
94 /** Returns true, if the specified frame border is enabled. */
95 bool IsBorderEnabled( FrameBorderType eBorder
) const;
96 /** Returns the number of enabled frame borders. */
97 sal_Int32
GetEnabledBorderCount() const;
98 /** Returns the border type from the passed index (counts only enabled frame borders). */
99 FrameBorderType
GetEnabledBorderType( sal_Int32 nIndex
) 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
);
158 css::uno::Reference
<css::accessibility::XAccessible
> getAccessibleParent() const { return GetDrawingArea()->get_accessible_parent(); }
159 virtual css::uno::Reference
<css::accessibility::XAccessible
> CreateAccessible() override
;
160 a11yrelationset
get_accessible_relation_set() const { return GetDrawingArea()->get_accessible_relation_set(); }
162 /** Returns the accessibility child object of the specified frame border (if enabled). */
163 rtl::Reference
< a11y::AccFrameSelectorChild
>
164 GetChildAccessible( FrameBorderType eBorder
);
165 /** Returns the accessibility child object with specified index (counts enabled frame borders only). */
166 css::uno::Reference
< css::accessibility::XAccessible
>
167 GetChildAccessible( sal_Int32 nIndex
);
168 /** Returns the accessibility child object at the specified position (relative to control). */
169 css::uno::Reference
< css::accessibility::XAccessible
>
170 GetChildAccessible( const Point
& rPos
);
172 /** Returns the bounding rectangle of the specified frame border (if enabled). */
173 tools::Rectangle
GetClickBoundRect( FrameBorderType eBorder
) const;
176 virtual void Paint( vcl::RenderContext
& rRenderContext
, const tools::Rectangle
& rRect
) override
;
177 virtual bool MouseButtonDown( const MouseEvent
& rMEvt
) override
;
178 virtual bool KeyInput( const KeyEvent
& rKEvt
) override
;
179 virtual void GetFocus() override
;
180 virtual void LoseFocus() override
;
181 virtual void StyleUpdated() override
;
182 virtual void Resize() override
;
184 rtl::Reference
<a11y::AccFrameSelector
> mxAccess
; /// Pointer to accessibility object of the control.
185 std::unique_ptr
< FrameSelectorImpl
> mxImpl
;
192 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */