xref: /trunk/main/svx/inc/svx/frmsel.hxx (revision 3334a7e6)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 #ifndef SVX_FRMSEL_HXX
25 #define SVX_FRMSEL_HXX
26 
27 #include <memory>
28 #include <tools/color.hxx>
29 #include <vcl/ctrl.hxx>
30 #include <vcl/bitmap.hxx>
31 #include <svx/framebordertype.hxx>
32 #include "svx/svxdllapi.h"
33 
34 class SvxBorderLine;
35 
36 namespace svx {
37 
38 struct FrameSelectorImpl;
39 
40 // ============================================================================
41 
42 typedef int FrameSelFlags;
43 
44 const FrameSelFlags FRAMESEL_NONE       = 0x0000;
45 /** If set, the left frame border is enabled. */
46 const FrameSelFlags FRAMESEL_LEFT       = 0x0001;
47 /** If set, the right frame border is enabled. */
48 const FrameSelFlags FRAMESEL_RIGHT      = 0x0002;
49 /** If set, the top frame border is enabled. */
50 const FrameSelFlags FRAMESEL_TOP        = 0x0004;
51 /** If set, the bottom frame border is enabled. */
52 const FrameSelFlags FRAMESEL_BOTTOM     = 0x0008;
53 /** If set, the inner horizontal frame border is enabled. */
54 const FrameSelFlags FRAMESEL_INNER_HOR  = 0x0010;
55 /** If set, the inner vertical frame border is enabled. */
56 const FrameSelFlags FRAMESEL_INNER_VER  = 0x0020;
57 /** If set, the top-left to bottom-right diagonal frame border is enabled. */
58 const FrameSelFlags FRAMESEL_DIAG_TLBR  = 0x0040;
59 /** If set, the bottom-left to top-right diagonal frame border is enabled. */
60 const FrameSelFlags FRAMESEL_DIAG_BLTR  = 0x0080;
61 
62 /** If set, all four outer frame borders are enabled. */
63 const FrameSelFlags FRAMESEL_OUTER      = FRAMESEL_LEFT|FRAMESEL_RIGHT|FRAMESEL_TOP|FRAMESEL_BOTTOM;
64 /** If set, both inner frame borders are enabled. */
65 const FrameSelFlags FRAMESEL_INNER      = FRAMESEL_INNER_HOR|FRAMESEL_INNER_VER;
66 /** If set, both diagonal frame borders are enabled. */
67 const FrameSelFlags FRAMESEL_DIAGONAL   = FRAMESEL_DIAG_TLBR|FRAMESEL_DIAG_BLTR;
68 
69 /** If set, all frame borders will support the don't care state. */
70 const FrameSelFlags FRAMESEL_DONTCARE   = 0x0100;
71 
72 // ----------------------------------------------------------------------------
73 
74 /** All possible states of a frame border. */
75 enum FrameBorderState
76 {
77     FRAMESTATE_SHOW,        /// Frame border has a visible style.
78     FRAMESTATE_HIDE,        /// Frame border is hidden (off).
79     FRAMESTATE_DONTCARE     /// Frame border is in don't care state (if enabled).
80 };
81 
82 // ============================================================================
83 
84 class SVX_DLLPUBLIC FrameSelector : public Control
85 {
86 public:
87     explicit            FrameSelector( Window* pParent, const ResId& rResId );
88     virtual             ~FrameSelector();
89 
90     /** Initializes the control, enables/disables frame borders according to flags. */
91     void                Initialize( FrameSelFlags nFlags );
92 
93     // enabled frame borders --------------------------------------------------
94 
95     /** Returns true, if the specified frame border is enabled. */
96     bool                IsBorderEnabled( FrameBorderType eBorder ) const;
97     /** Returns the number of enabled frame borders. */
98     sal_Int32           GetEnabledBorderCount() const;
99     /** Returns the border type from the passed index (counts only enabled frame borders). */
100     FrameBorderType     GetEnabledBorderType( sal_Int32 nIndex ) const;
101     /** Returns the index of a frame border (counts only enabled borders) from passed type. */
102     sal_Int32           GetEnabledBorderIndex( FrameBorderType eBorder ) const;
103 
104     // frame border state and style -------------------------------------------
105 
106     /** Returns true, if the control supports the "don't care" frame border state. */
107     bool                SupportsDontCareState() const;
108 
109     /** Returns the state (visible/hidden/don't care) of the specified frame border. */
110     FrameBorderState    GetFrameBorderState( FrameBorderType eBorder ) const;
111     /** Returns the style of the specified frame border, if it is visible. */
112     const SvxBorderLine* GetFrameBorderStyle( FrameBorderType eBorder ) const;
113 
114     /** Shows the specified frame border using the passed style, or hides it, if pStyle is 0. */
115     void                ShowBorder( FrameBorderType eBorder, const SvxBorderLine* pStyle );
116     /** Sets the specified frame border to "don't care" state. */
117     void                SetBorderDontCare( FrameBorderType eBorder );
118 
119     /** Returns true, if any enabled frame border has a visible style (not "don't care"). */
120     bool                IsAnyBorderVisible() const;
121     /** Hides all enabled frame borders. */
122     void                HideAllBorders();
123 
124     /** Returns true, if all visible frame borders have equal widths.
125         @descr  Ignores hidden and "don't care" frame borders. On success,
126         returns the widths in the passed parameters. */
127     bool                GetVisibleWidth( sal_uInt16& rnPrim, sal_uInt16& rnDist, sal_uInt16& rnSec ) const;
128     /** Returns true, if all visible frame borders have equal color.
129         @descr  Ignores hidden and "don't care" frame borders. On success,
130         returns the color in the passed parameter. */
131     bool                GetVisibleColor( Color& rColor ) const;
132 
133     // frame border selection -------------------------------------------------
134 
135     /** Returns the current selection handler. */
136     const Link&         GetSelectHdl() const;
137     /** Sets the passed handler that is called if the selection of the control changes. */
138     void                SetSelectHdl( const Link& rHdl );
139 
140     /** Returns true, if the specified frame border is selected. */
141     bool                IsBorderSelected( FrameBorderType eBorder ) const;
142     /** Selects or deselects the specified frame border. */
143     void                SelectBorder( FrameBorderType eBorder, bool bSelect = true );
144     /** Deselects the specified frame border. */
DeselectBorder(FrameBorderType eBorder)145     inline void         DeselectBorder( FrameBorderType eBorder ) { SelectBorder( eBorder, false ); }
146 
147     /** Returns true, if any of the enabled frame borders is selected. */
148     bool                IsAnyBorderSelected() const;
149     /** Selects or deselects all frame borders. */
150     void                SelectAllBorders( bool bSelect = true );
151     /** Deselects all frame borders. */
DeselectAllBorders()152     inline void         DeselectAllBorders() { SelectAllBorders( false ); }
153 
154     /** Selects or deselects all visible frame borders (ignores hidden and "don't care" borders). */
155     void                SelectAllVisibleBorders( bool bSelect = true );
156 
157     /** Sets the passed line widths to all selected frame borders (in twips). */
158     void                SetStyleToSelection( sal_uInt16 nPrim, sal_uInt16 nDist, sal_uInt16 nSec );
159     /** Sets the passed color to all selected frame borders. */
160     void                SetColorToSelection( const Color& rColor );
161 
162     // accessibility ----------------------------------------------------------
163 
164     virtual ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible >
165                         CreateAccessible();
166 
167     /** Returns the accessibility child object of the specified frame border (if enabled). */
168     ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible >
169                         GetChildAccessible( FrameBorderType eBorder );
170     /** Returns the accessibility child object with specified index (counts enabled frame borders only). */
171     ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible >
172                         GetChildAccessible( sal_Int32 nIndex );
173     /** Returns the accessibility child object at the specified position (relative to control). */
174     ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible >
175                         GetChildAccessible( const Point& rPos );
176 
177     /** Returns true, if the passed point is inside the click area of any enabled frame border. */
178     bool                ContainsClickPoint( const Point& rPos ) const;
179     /** Returns the bounding rectangle of the specified frame border (if enabled). */
180     Rectangle           GetClickBoundRect( FrameBorderType eBorder ) const;
181 
182     // ------------------------------------------------------------------------
183 protected:
184     virtual void        Paint( const Rectangle& rRect );
185     virtual void        MouseButtonDown( const MouseEvent& rMEvt );
186     virtual void        KeyInput( const KeyEvent& rKEvt );
187     virtual void        GetFocus();
188     virtual void        LoseFocus();
189     virtual void        DataChanged( const DataChangedEvent& rDCEvt );
190 
191 private:
192     std::auto_ptr< FrameSelectorImpl > mxImpl;
193 };
194 
195 // ============================================================================
196 
197 } // namespace svx
198 
199 #endif
200 
201