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_SOURCE_INC_FRMSELIMPL_HXX
21 #define INCLUDED_SVX_SOURCE_INC_FRMSELIMPL_HXX
22 
23 #include <vcl/virdev.hxx>
24 #include <vcl/image.hxx>
25 #include <svx/frmsel.hxx>
26 #include <svx/framelink.hxx>
27 #include <svx/framelinkarray.hxx>
28 #include <editeng/borderline.hxx>
29 
30 namespace svx {
31 
32 namespace a11y {
33     class AccFrameSelector;
34     class AccFrameSelectorChild;
35 }
36 
37 class FrameBorder
38 {
39 public:
40     explicit FrameBorder(FrameBorderType eType);
GetDefaultPatternScale()41     static double GetDefaultPatternScale() { return 0.05; }
42 
GetType() const43     FrameBorderType GetType() const
44     {
45         return meType;
46     }
47 
IsEnabled() const48     bool IsEnabled() const
49     {
50         return mbEnabled;
51     }
52     void Enable(FrameSelFlags nFlags);
53 
GetState() const54     FrameBorderState GetState() const
55     {
56         return meState;
57     }
58     void SetState(FrameBorderState eState);
59 
IsSelected() const60     bool IsSelected() const { return mbSelected; }
Select(bool bSelect)61     void Select( bool bSelect ) { mbSelected = bSelect; }
62 
GetCoreStyle() const63     const editeng::SvxBorderLine& GetCoreStyle() const { return maCoreStyle; }
64     void SetCoreStyle( const editeng::SvxBorderLine* pStyle );
65 
SetUIColorPrim(const Color & rColor)66     void SetUIColorPrim( const Color& rColor ) {maUIStyle.SetColorPrim( rColor ); }
SetUIColorSecn(const Color & rColor)67     void SetUIColorSecn( const Color& rColor ) {maUIStyle.SetColorSecn( rColor ); }
GetUIStyle() const68     const frame::Style& GetUIStyle() const { return maUIStyle; }
69 
ClearFocusArea()70     void ClearFocusArea() { maFocusArea.Clear(); }
71     void AddFocusPolygon( const tools::Polygon& rFocus );
72     void MergeFocusToPolyPolygon( tools::PolyPolygon& rPPoly ) const;
73 
ClearClickArea()74     void ClearClickArea() { maClickArea.Clear(); }
75     void AddClickRect( const tools::Rectangle& rRect );
76     bool ContainsClickPoint( const Point& rPos ) const;
77     tools::Rectangle GetClickBoundRect() const;
78 
79     void SetKeyboardNeighbors(FrameBorderType eLeft, FrameBorderType eRight,
80                               FrameBorderType eTop, FrameBorderType eBottom);
81     FrameBorderType GetKeyboardNeighbor( sal_uInt16 nKeyCode ) const;
82 
83 private:
84     const FrameBorderType meType; /// Frame border type (position in control).
85     FrameBorderState meState; /// Frame border state (on/off/don't care).
86     editeng::SvxBorderLine maCoreStyle; /// Core style from application.
87     frame::Style maUIStyle; /// Internal style to draw lines.
88     FrameBorderType meKeyLeft; /// Left neighbor for keyboard control.
89     FrameBorderType meKeyRight; /// Right neighbor for keyboard control.
90     FrameBorderType meKeyTop; /// Upper neighbor for keyboard control.
91     FrameBorderType meKeyBottom;    /// Lower neighbor for keyboard control.
92     tools::PolyPolygon maFocusArea;    /// Focus drawing areas.
93     tools::PolyPolygon maClickArea;    /// Mouse click areas.
94     bool mbEnabled : 1; /// true = Border enabled in control.
95     bool mbSelected : 1; /// true = Border selected in control.
96 };
97 
98 
99 typedef std::vector< FrameBorder* > FrameBorderPtrVec;
100 
101 struct FrameSelectorImpl
102 {
103     FrameSelector&      mrFrameSel;     /// The control itself.
104     ScopedVclPtr<VirtualDevice> mpVirDev; /// For all buffered drawing operations.
105     std::vector<Image>  maArrows;       /// Arrows in current system colors.
106     Color               maBackCol;      /// Background color.
107     Color               maArrowCol;     /// Selection arrow color.
108     Color               maMarkCol;      /// Selection marker color.
109     Color               maHCLineCol;    /// High contrast line color.
110     Point               maVirDevPos;    /// Position of virtual device in the control.
111 
112     FrameBorder         maLeft;         /// All data of left frame border.
113     FrameBorder         maRight;        /// All data of right frame border.
114     FrameBorder         maTop;          /// All data of top frame border.
115     FrameBorder         maBottom;       /// All data of bottom frame border.
116     FrameBorder         maHor;          /// All data of inner horizontal frame border.
117     FrameBorder         maVer;          /// All data of inner vertical frame border.
118     FrameBorder         maTLBR;         /// All data of top-left to bottom-right frame border.
119     FrameBorder         maBLTR;         /// All data of bottom-left to top-right frame border.
120     editeng::SvxBorderLine maCurrStyle;    /// Current style and color for new borders.
121     frame::Array        maArray;        /// Frame link array to draw an array of frame borders.
122 
123     FrameSelFlags       mnFlags;        /// Flags for enabled frame borders.
124     FrameBorderPtrVec   maAllBorders;   /// Pointers to all frame borders.
125     FrameBorderPtrVec   maEnabBorders;  /// Pointers to enables frame borders.
126     Link<LinkParamNone*,void> maSelectHdl;    /// Selection handler.
127 
128     long                mnCtrlSize;     /// Size of the control (always square).
129     long                mnArrowSize;    /// Size of an arrow image.
130     long                mnLine1;        /// Middle of left/top frame borders.
131     long                mnLine2;        /// Middle of inner frame borders.
132     long                mnLine3;        /// Middle of right/bottom frame borders.
133     long                mnFocusOffs;    /// Offset from frame border middle to draw focus.
134 
135     bool                mbHor;          /// true = Inner horizontal frame border enabled.
136     bool                mbVer;          /// true = Inner vertical frame border enabled.
137     bool                mbTLBR;         /// true = Top-left to bottom-right frame border enabled.
138     bool                mbBLTR;         /// true = Bottom-left to top-right frame border enabled.
139     bool                mbFullRepaint;  /// Used for repainting (false = only copy virtual device).
140     bool                mbAutoSelect;   /// true = Auto select a frame border, if focus reaches control.
141     bool                mbHCMode;       /// true = High contrast mode.
142 
143     std::vector<rtl::Reference<a11y::AccFrameSelectorChild>>
144                         maChildVec;     /// Pointers to accessibility objects for frame borders.
145     explicit            FrameSelectorImpl( FrameSelector& rFrameSel );
146                         ~FrameSelectorImpl();
147 
148     // initialization
149     /** Initializes the control, enables/disables frame borders according to flags. */
150     void                Initialize( FrameSelFlags nFlags );
151 
152     /** Fills all color members from current style settings. */
153     void                InitColors();
154     /** Creates the image list with selection arrows regarding current style settings. */
155     void                InitArrowImageList();
156     /** Initializes global coordinates. */
157     void                InitGlobalGeometry();
158     /** Initializes coordinates of all frame borders. */
159     void                InitBorderGeometry();
160     /** Draws the entire control into the internal virtual device. */
161     void                InitVirtualDevice();
162     /** call this to recalculate based on parent size */
163     void                sizeChanged();
164 
165     // frame border access
166     /** Returns the object representing the specified frame border. */
167     const FrameBorder&  GetBorder( FrameBorderType eBorder ) const;
168     /** Returns the object representing the specified frame border (write access). */
169     FrameBorder&        GetBorderAccess( FrameBorderType eBorder );
170 
171     // drawing
172     /** Draws the background of the entire control (the gray areas between borders). */
173     void                DrawBackground();
174 
175     /** Draws selection arrows for the specified frame border. */
176     void                DrawArrows( const FrameBorder& rBorder );
177 
178     /** Returns the color that has to be used to draw a frame border. */
179     Color               GetDrawLineColor( const Color& rColor ) const;
180     /** Draws all frame borders. */
181     void                DrawAllFrameBorders();
182 
183     /** Draws all contents of the control. */
184     void                DrawVirtualDevice();
185     /** Copies contents of the virtual device to the control. */
186     void                CopyVirDevToControl(vcl::RenderContext& rRenderContext);
187 
188     /** Draws tracking rectangles for all selected frame borders. */
189     void                DrawAllTrackingRects(vcl::RenderContext& rRenderContext);
190 
191     /** Converts a mouse position to the virtual device position. */
192     Point               GetDevPosFromMousePos( const Point& rMousePos ) const;
193 
194     /** Invalidates the control.
195         @param bFullRepaint  true = Full repaint; false = update selection only. */
196     void                DoInvalidate( bool bFullRepaint );
197 
198     // frame border state and style
199     /** Sets the state of the specified frame border. */
200     void                SetBorderState( FrameBorder& rBorder, FrameBorderState eState );
201     /** Sets the core style of the specified frame border, or hides the frame border, if pStyle is 0. */
202     void                SetBorderCoreStyle( FrameBorder& rBorder, const editeng::SvxBorderLine* pStyle );
203 
204     /** Changes the state of a frame border after a control event (mouse/keyboard). */
205     void                ToggleBorderState( FrameBorder& rBorder );
206 
207     // frame border selection
208     /** Selects a frame border and schedules redraw. */
209     void                SelectBorder( FrameBorder& rBorder, bool bSelect );
210     /** Grabs focus without auto-selection of a frame border, if no border selected. */
211     void                SilentGrabFocus();
212 
213     /** Returns true, if all selected frame borders are equal (or if nothing is selected). */
214     bool                SelectedBordersEqual() const;
215 };
216 
217 
218 /** Dummy predicate for frame border iterators to use all borders in a container. */
219 struct FrameBorderDummy_Pred
220 {
operator ()svx::FrameBorderDummy_Pred221     bool operator()( const FrameBorder* ) const { return true; }
222 };
223 
224 /** Predicate for frame border iterators to use only visible borders in a container. */
225 struct FrameBorderVisible_Pred
226 {
operator ()svx::FrameBorderVisible_Pred227     bool operator()( const FrameBorder* pBorder ) const { return pBorder->GetState() == FrameBorderState::Show; }
228 };
229 
230 /** Predicate for frame border iterators to use only selected borders in a container. */
231 struct FrameBorderSelected_Pred
232 {
operator ()svx::FrameBorderSelected_Pred233     bool operator()( const FrameBorder* pBorder ) const { return pBorder->IsSelected(); }
234 };
235 
236 /** Template class for all types of frame border iterators. */
237 template< typename Cont, typename Iter, typename Pred >
238 class FrameBorderIterBase
239 {
240 public:
241     typedef Cont container_type;
242     typedef Iter iterator_type;
243     typedef typename Cont::value_type value_type;
244     typedef FrameBorderIterBase<Cont, Iter, Pred> this_type;
245 
246     explicit            FrameBorderIterBase( container_type& rCont );
Is() const247     bool         Is() const { return maIt != maEnd; }
248     this_type&          operator++();
operator *() const249     value_type   operator*() const { return *maIt; }
250 
251 private:
252     iterator_type       maIt;
253     iterator_type       maEnd;
254     Pred                maPred;
255 };
256 
257 /** Iterator for constant svx::FrameBorder containers, iterates over all borders. */
258 typedef FrameBorderIterBase< const FrameBorderPtrVec, FrameBorderPtrVec::const_iterator, FrameBorderDummy_Pred >
259     FrameBorderCIter;
260 
261 /** Iterator for mutable svx::FrameBorder containers, iterates over all borders. */
262 typedef FrameBorderIterBase< FrameBorderPtrVec, FrameBorderPtrVec::iterator, FrameBorderDummy_Pred >
263     FrameBorderIter;
264 
265 /** Iterator for constant svx::FrameBorder containers, iterates over visible borders. */
266 typedef FrameBorderIterBase< const FrameBorderPtrVec, FrameBorderPtrVec::const_iterator, FrameBorderVisible_Pred >
267     VisFrameBorderCIter;
268 
269 /** Iterator for mutable svx::FrameBorder containers, iterates over visible borders. */
270 typedef FrameBorderIterBase< FrameBorderPtrVec, FrameBorderPtrVec::iterator, FrameBorderVisible_Pred >
271     VisFrameBorderIter;
272 
273 /** Iterator for constant svx::FrameBorder containers, iterates over selected borders. */
274 typedef FrameBorderIterBase< const FrameBorderPtrVec, FrameBorderPtrVec::const_iterator, FrameBorderSelected_Pred >
275     SelFrameBorderCIter;
276 
277 /** Iterator for mutable svx::FrameBorder containers, iterates over selected borders. */
278 typedef FrameBorderIterBase< FrameBorderPtrVec, FrameBorderPtrVec::iterator, FrameBorderSelected_Pred >
279     SelFrameBorderIter;
280 
281 }
282 
283 #endif
284 
285 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
286