Line data Source code
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_FRMSEL_HXX
21 : #define INCLUDED_SVX_FRMSEL_HXX
22 :
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 :
31 : namespace editeng {
32 : class SvxBorderLine;
33 : }
34 :
35 : namespace svx {
36 :
37 : struct FrameSelectorImpl;
38 :
39 :
40 :
41 : typedef int FrameSelFlags;
42 :
43 : const FrameSelFlags FRAMESEL_NONE = 0x0000;
44 : /** If set, the left frame border is enabled. */
45 : const FrameSelFlags FRAMESEL_LEFT = 0x0001;
46 : /** If set, the right frame border is enabled. */
47 : const FrameSelFlags FRAMESEL_RIGHT = 0x0002;
48 : /** If set, the top frame border is enabled. */
49 : const FrameSelFlags FRAMESEL_TOP = 0x0004;
50 : /** If set, the bottom frame border is enabled. */
51 : const FrameSelFlags FRAMESEL_BOTTOM = 0x0008;
52 : /** If set, the inner horizontal frame border is enabled. */
53 : const FrameSelFlags FRAMESEL_INNER_HOR = 0x0010;
54 : /** If set, the inner vertical frame border is enabled. */
55 : const FrameSelFlags FRAMESEL_INNER_VER = 0x0020;
56 : /** If set, the top-left to bottom-right diagonal frame border is enabled. */
57 : const FrameSelFlags FRAMESEL_DIAG_TLBR = 0x0040;
58 : /** If set, the bottom-left to top-right diagonal frame border is enabled. */
59 : const FrameSelFlags FRAMESEL_DIAG_BLTR = 0x0080;
60 :
61 : /** If set, all four outer frame borders are enabled. */
62 : const FrameSelFlags FRAMESEL_OUTER = FRAMESEL_LEFT|FRAMESEL_RIGHT|FRAMESEL_TOP|FRAMESEL_BOTTOM;
63 : /** If set, both inner frame borders are enabled. */
64 : const FrameSelFlags FRAMESEL_INNER = FRAMESEL_INNER_HOR|FRAMESEL_INNER_VER;
65 : /** If set, both diagonal frame borders are enabled. */
66 : const FrameSelFlags FRAMESEL_DIAGONAL = FRAMESEL_DIAG_TLBR|FRAMESEL_DIAG_BLTR;
67 :
68 : /** If set, all frame borders will support the don't care state. */
69 : const FrameSelFlags FRAMESEL_DONTCARE = 0x0100;
70 :
71 :
72 :
73 : /** All possible states of a frame border. */
74 : enum FrameBorderState
75 : {
76 : FRAMESTATE_SHOW, /// Frame border has a visible style.
77 : FRAMESTATE_HIDE, /// Frame border is hidden (off).
78 : FRAMESTATE_DONTCARE /// Frame border is in don't care state (if enabled).
79 : };
80 :
81 :
82 :
83 : class SVX_DLLPUBLIC SAL_WARN_UNUSED FrameSelector : public Control
84 : {
85 : public:
86 : FrameSelector(vcl::Window* pParent);
87 : virtual ~FrameSelector();
88 :
89 : /** Initializes the control, enables/disables frame borders according to flags. */
90 : void Initialize( FrameSelFlags nFlags );
91 :
92 : // enabled frame borders --------------------------------------------------
93 :
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;
100 : /** Returns the index of a frame border (counts only enabled borders) from passed type. */
101 : sal_Int32 GetEnabledBorderIndex( FrameBorderType eBorder ) const;
102 :
103 : // frame border state and style -------------------------------------------
104 :
105 : /** Returns true, if the control supports the "don't care" frame border state. */
106 : bool SupportsDontCareState() const;
107 :
108 : /** Returns the state (visible/hidden/don't care) of the specified frame border. */
109 : FrameBorderState GetFrameBorderState( FrameBorderType eBorder ) const;
110 : /** Returns the style of the specified frame border, if it is visible. */
111 : const editeng::SvxBorderLine* GetFrameBorderStyle( FrameBorderType eBorder ) const;
112 :
113 : /** Shows the specified frame border using the passed style, or hides it, if pStyle is 0. */
114 : void ShowBorder( FrameBorderType eBorder, const editeng::SvxBorderLine* pStyle );
115 : /** Sets the specified frame border to "don't care" state. */
116 : void SetBorderDontCare( FrameBorderType eBorder );
117 :
118 : /** Returns true, if any enabled frame border has a visible style (not "don't care"). */
119 : bool IsAnyBorderVisible() const;
120 : /** Hides all enabled frame borders. */
121 : void HideAllBorders();
122 :
123 : /** Returns true, if all visible frame borders have equal widths.
124 : @descr Ignores hidden and "don't care" frame borders. On success,
125 : returns the width in the passed parameter. */
126 : bool GetVisibleWidth( long& rnWidth, editeng::SvxBorderStyle& rnStyle ) const;
127 : /** Returns true, if all visible frame borders have equal color.
128 : @descr Ignores hidden and "don't care" frame borders. On success,
129 : returns the color in the passed parameter. */
130 : bool GetVisibleColor( Color& rColor ) const;
131 :
132 : // frame border selection -------------------------------------------------
133 :
134 : /** Returns the current selection handler. */
135 : const Link<>& GetSelectHdl() const;
136 : /** Sets the passed handler that is called if the selection of the control changes. */
137 : void SetSelectHdl( const Link<>& rHdl );
138 :
139 : /** Returns true, if the specified frame border is selected. */
140 : bool IsBorderSelected( FrameBorderType eBorder ) const;
141 : /** Selects or deselects the specified frame border. */
142 : void SelectBorder( FrameBorderType eBorder, bool bSelect = true );
143 : /** Deselects the specified frame border. */
144 : inline void DeselectBorder( FrameBorderType eBorder ) { SelectBorder( eBorder, false ); }
145 :
146 : /** Returns true, if any of the enabled frame borders is selected. */
147 : bool IsAnyBorderSelected() const;
148 : /** Selects or deselects all frame borders. */
149 : void SelectAllBorders( bool bSelect = true );
150 : /** Deselects all frame borders. */
151 0 : inline void DeselectAllBorders() { SelectAllBorders( false ); }
152 :
153 : /** Selects or deselects all visible frame borders (ignores hidden and "don't care" borders). */
154 : void SelectAllVisibleBorders( bool bSelect = true );
155 :
156 : /** Sets the passed line widths to all selected frame borders (in twips). */
157 : void SetStyleToSelection( long nWidth, editeng::SvxBorderStyle nStyle );
158 : /** Sets the passed color to all selected frame borders. */
159 : void SetColorToSelection( const Color& rColor );
160 :
161 : // accessibility ----------------------------------------------------------
162 :
163 : virtual ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible >
164 : CreateAccessible() SAL_OVERRIDE;
165 :
166 : /** Returns the accessibility child object of the specified frame border (if enabled). */
167 : ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible >
168 : GetChildAccessible( FrameBorderType eBorder );
169 : /** Returns the accessibility child object with specified index (counts enabled frame borders only). */
170 : ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible >
171 : GetChildAccessible( sal_Int32 nIndex );
172 : /** Returns the accessibility child object at the specified position (relative to control). */
173 : ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible >
174 : GetChildAccessible( const Point& rPos );
175 :
176 : /** Returns true, if the passed point is inside the click area of any enabled frame border. */
177 : bool ContainsClickPoint( const Point& rPos ) const;
178 : /** Returns the bounding rectangle of the specified frame border (if enabled). */
179 : Rectangle GetClickBoundRect( FrameBorderType eBorder ) const;
180 :
181 :
182 : protected:
183 : virtual void Paint( vcl::RenderContext& rRenderContext, const Rectangle& rRect ) SAL_OVERRIDE;
184 : virtual void MouseButtonDown( const MouseEvent& rMEvt ) SAL_OVERRIDE;
185 : virtual void KeyInput( const KeyEvent& rKEvt ) SAL_OVERRIDE;
186 : virtual void GetFocus() SAL_OVERRIDE;
187 : virtual void LoseFocus() SAL_OVERRIDE;
188 : virtual void DataChanged( const DataChangedEvent& rDCEvt ) SAL_OVERRIDE;
189 : virtual void Resize() SAL_OVERRIDE;
190 : virtual Size GetOptimalSize() const SAL_OVERRIDE;
191 :
192 : private:
193 : std::unique_ptr< FrameSelectorImpl > mxImpl;
194 : };
195 :
196 :
197 :
198 : }
199 :
200 : #endif
201 :
202 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|