xref: /aoo41x/main/svx/source/inc/frmselimpl.hxx (revision cdf0e10c)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 #ifndef SVX_FRMSELIMPL_HXX
29 #define SVX_FRMSELIMPL_HXX
30 
31 #include <vcl/virdev.hxx>
32 #include <vcl/image.hxx>
33 #include <svx/frmsel.hxx>
34 #include <svx/framelinkarray.hxx>
35 #include <editeng/borderline.hxx>
36 
37 namespace svx {
38 
39 namespace a11y { class AccFrameSelector; }
40 
41 // ============================================================================
42 
43 class FrameBorder
44 {
45 public:
46     explicit            FrameBorder( FrameBorderType eType );
47 
48     inline FrameBorderType GetType() const { return meType; }
49 
50     inline bool         IsEnabled() const { return mbEnabled; }
51     void                Enable( FrameSelFlags nFlags );
52 
53     inline FrameBorderState GetState() const { return meState; }
54     void                SetState( FrameBorderState eState );
55 
56     inline bool         IsSelected() const { return mbSelected; }
57     inline void         Select( bool bSelect ) { mbSelected = bSelect; }
58 
59     const SvxBorderLine& GetCoreStyle() const { return maCoreStyle; }
60     void                SetCoreStyle( const SvxBorderLine* pStyle );
61 
62     inline void         SetUIColor( const Color& rColor ) {maUIStyle.SetColor( rColor ); }
63     inline const frame::Style& GetUIStyle() const { return maUIStyle; }
64 
65     inline void         ClearFocusArea() { maFocusArea.Clear(); }
66     void                AddFocusPolygon( const Polygon& rFocus );
67     void                MergeFocusToPolyPolygon( PolyPolygon& rPPoly ) const;
68 
69     inline void         ClearClickArea() { maClickArea.Clear(); }
70     void                AddClickRect( const Rectangle& rRect );
71     bool                ContainsClickPoint( const Point& rPos ) const;
72     void                MergeClickAreaToPolyPolygon( PolyPolygon& rPPoly ) const;
73     Rectangle           GetClickBoundRect() const;
74 
75     void                SetKeyboardNeighbors(
76                             FrameBorderType eLeft, FrameBorderType eRight,
77                             FrameBorderType eTop, FrameBorderType eBottom );
78     FrameBorderType     GetKeyboardNeighbor( sal_uInt16 nKeyCode ) const;
79 
80 private:
81     const FrameBorderType meType;       /// Frame border type (position in control).
82     FrameBorderState    meState;        /// Frame border state (on/off/don't care).
83     SvxBorderLine       maCoreStyle;    /// Core style from application.
84     frame::Style        maUIStyle;      /// Internal style to draw lines.
85     FrameBorderType     meKeyLeft;      /// Left neighbor for keyboard control.
86     FrameBorderType     meKeyRight;     /// Right neighbor for keyboard control.
87     FrameBorderType     meKeyTop;       /// Upper neighbor for keyboard control.
88     FrameBorderType     meKeyBottom;    /// Lower neighbor for keyboard control.
89     PolyPolygon         maFocusArea;    /// Focus drawing areas.
90     PolyPolygon         maClickArea;    /// Mouse click areas.
91     bool                mbEnabled;      /// true = Border enabled in control.
92     bool                mbSelected;     /// true = Border selected in control.
93 };
94 
95 // ============================================================================
96 
97 typedef std::vector< FrameBorder* >     FrameBorderPtrVec;
98 
99 struct FrameSelectorImpl : public Resource
100 {
101     typedef ::com::sun::star::uno::Reference<
102         ::com::sun::star::accessibility::XAccessible >  XAccessibleRef;
103     typedef std::vector< a11y::AccFrameSelector* >      AccessibleImplVec;
104     typedef std::vector< XAccessibleRef >               XAccessibleRefVec;
105 
106     FrameSelector&      mrFrameSel;     /// The control itself.
107     VirtualDevice       maVirDev;       /// For all buffered drawing operations.
108     ImageList           maILArrows;     /// Arrows in current system colors.
109     Color               maBackCol;      /// Background color.
110     Color               maArrowCol;     /// Selection arrow color.
111     Color               maMarkCol;      /// Selection marker color.
112     Color               maHCLineCol;    /// High contrast line color.
113     Point               maVirDevPos;    /// Position of virtual device in the control.
114     Point               maMousePos;     /// Last mouse pointer position.
115 
116     FrameBorder         maLeft;         /// All data of left frame border.
117     FrameBorder         maRight;        /// All data of right frame border.
118     FrameBorder         maTop;          /// All data of top frame border.
119     FrameBorder         maBottom;       /// All data of bottom frame border.
120     FrameBorder         maHor;          /// All data of inner horizontal frame border.
121     FrameBorder         maVer;          /// All data of inner vertical frame border.
122     FrameBorder         maTLBR;         /// All data of top-left to bottom-right frame border.
123     FrameBorder         maBLTR;         /// All data of bottom-left to top-right frame border.
124     SvxBorderLine       maCurrStyle;    /// Current style and color for new borders.
125     frame::Array        maArray;        /// Frame link array to draw an array of frame borders.
126 
127     FrameSelFlags       mnFlags;        /// Flags for enabled frame borders.
128     FrameBorderPtrVec   maAllBorders;   /// Pointers to all frame borders.
129     FrameBorderPtrVec   maEnabBorders;  /// Pointers to enables frame borders.
130     Link                maSelectHdl;    /// Selection handler.
131 
132     long                mnCtrlSize;     /// Size of the control (always square).
133     long                mnArrowSize;    /// Size of an arrow image.
134     long                mnLine1;        /// Middle of left/top frame borders.
135     long                mnLine2;        /// Middle of inner frame borders.
136     long                mnLine3;        /// Middle of right/bottom frame borders.
137     long                mnFocusOffs;    /// Offset from frame border middle to draw focus.
138 
139     bool                mbHor;          /// true = Inner horizontal frame border enabled.
140     bool                mbVer;          /// true = Inner vertical frame border enabled.
141     bool                mbTLBR;         /// true = Top-left to bottom-right frame border enabled.
142     bool                mbBLTR;         /// true = Bottom-left to top-right frame border enabled.
143     bool                mbFullRepaint;  /// Used for repainting (false = only copy virtual device).
144     bool                mbAutoSelect;   /// true = Auto select a frame border, if focus reaches control.
145     bool                mbClicked;      /// true = The control has been clicked at least one time.
146     bool                mbHCMode;       /// true = High contrast mode.
147 
148     a11y::AccFrameSelector* mpAccess;   /// Pointer to accessibility object of the control.
149     XAccessibleRef      mxAccess;       /// Reference to accessibility object of the control.
150     AccessibleImplVec   maChildVec;     /// Pointers to accessibility objects for frame borders.
151     XAccessibleRefVec   mxChildVec;     /// References to accessibility objects for frame borders.
152 
153     explicit            FrameSelectorImpl( FrameSelector& rFrameSel );
154                         ~FrameSelectorImpl();
155 
156     // initialization ---------------------------------------------------------
157 
158     /** Initializes the control, enables/disables frame borders according to flags. */
159     void                Initialize( FrameSelFlags nFlags );
160 
161     /** Fills all color members from current style settings. */
162     void                InitColors();
163     /** Creates the image list with selection arrows regarding current style settings. */
164     void                InitArrowImageList();
165     /** Initializes global coordinates. */
166     void                InitGlobalGeometry();
167     /** Initializes coordinates of all frame borders. */
168     void                InitBorderGeometry();
169     /** Initializes click areas of all enabled frame borders. */
170     void                InitClickAreas();
171     /** Draws the entire control into the internal virtual device. */
172     void                InitVirtualDevice();
173 
174     // frame border access ----------------------------------------------------
175 
176     /** Returns the object representing the specified frame border. */
177     const FrameBorder&  GetBorder( FrameBorderType eBorder ) const;
178     /** Returns the object representing the specified frame border (write access). */
179     FrameBorder&        GetBorderAccess( FrameBorderType eBorder );
180 
181     // drawing ----------------------------------------------------------------
182 
183     /** Draws the background of the entire control (the gray areas between borders). */
184     void                DrawBackground();
185 
186     /** Draws selection arrows for the specified frame border. */
187     void                DrawArrows( const FrameBorder& rBorder );
188     /** Draws arrows in current selection state for all enabled frame borders. */
189     void                DrawAllArrows();
190 
191     /** Returns the color that has to be used to draw a frame border. */
192     Color               GetDrawLineColor( const Color& rColor ) const;
193     /** Draws all frame borders. */
194     void                DrawAllFrameBorders();
195 
196     /** Draws all contents of the control. */
197     void                DrawVirtualDevice();
198     /** Copies contents of the virtual device to the control. */
199     void                CopyVirDevToControl();
200 
201     /** Draws tracking rectangles for all selected frame borders. */
202     void                DrawAllTrackingRects();
203 
204     /** Converts a mouse position to the virtual device position. */
205     Point               GetDevPosFromMousePos( const Point& rMousePos ) const;
206 
207     /** Invalidates the control.
208         @param bFullRepaint  true = Full repaint; false = update selection only. */
209     void                DoInvalidate( bool bFullRepaint );
210 
211     // frame border state and style -------------------------------------------
212 
213     /** Sets the state of the specified frame border. */
214     void                SetBorderState( FrameBorder& rBorder, FrameBorderState eState );
215     /** Sets the core style of the specified frame border, or hides the frame border, if pStyle is 0. */
216     void                SetBorderCoreStyle( FrameBorder& rBorder, const SvxBorderLine* pStyle );
217     /** Sets the color of the specified frame border. */
218     void                SetBorderColor( FrameBorder& rBorder, const Color& rColor );
219 
220     /** Changes the state of a frame border after a control event (mouse/keyboard). */
221     void                ToggleBorderState( FrameBorder& rBorder );
222 
223     // frame border selection -------------------------------------------------
224 
225     /** Selects a frame border and schedules redraw. */
226     void                SelectBorder( FrameBorder& rBorder, bool bSelect );
227     /** Grabs focus without auto-selection of a frame border, if no border selected. */
228     void                SilentGrabFocus();
229 
230     /** Returns true, if all selected frame borders are equal (or if nothing is selected). */
231     bool                SelectedBordersEqual() const;
232 };
233 
234 // ============================================================================
235 
236 /** Dummy predicate for frame border iterators to use all borders in a container. */
237 struct FrameBorderDummy_Pred
238 {
239     inline bool operator()( const FrameBorder* ) const { return true; }
240 };
241 
242 /** Predicate for frame border iterators to use only visible borders in a container. */
243 struct FrameBorderVisible_Pred
244 {
245     inline bool operator()( const FrameBorder* pBorder ) const { return pBorder->GetState() == FRAMESTATE_SHOW; }
246 };
247 
248 /** Predicate for frame border iterators to use only selected borders in a container. */
249 struct FrameBorderSelected_Pred
250 {
251     inline bool operator()( const FrameBorder* pBorder ) const { return pBorder->IsSelected(); }
252 };
253 
254 /** Template class for all types of frame border iterators. */
255 template< typename Cont, typename Iter, typename Pred >
256 class FrameBorderIterBase
257 {
258 public:
259     typedef Cont                                        container_type;
260     typedef Iter                                        iterator_type;
261     typedef Pred                                        predicate_type;
262     typedef typename Cont::value_type                   value_type;
263     typedef FrameBorderIterBase< Cont, Iter, Pred >    this_type;
264 
265     explicit            FrameBorderIterBase( container_type& rCont );
266     inline bool         Is() const { return maIt != maEnd; }
267     this_type&          operator++();
268     inline value_type   operator*() const { return *maIt; }
269 
270 private:
271     iterator_type       maIt;
272     iterator_type       maEnd;
273     predicate_type      maPred;
274 };
275 
276 /** Iterator for constant svx::FrameBorder containers, iterates over all borders. */
277 typedef FrameBorderIterBase< const FrameBorderPtrVec, FrameBorderPtrVec::const_iterator, FrameBorderDummy_Pred >
278     FrameBorderCIter;
279 
280 /** Iterator for mutable svx::FrameBorder containers, iterates over all borders. */
281 typedef FrameBorderIterBase< FrameBorderPtrVec, FrameBorderPtrVec::iterator, FrameBorderDummy_Pred >
282     FrameBorderIter;
283 
284 /** Iterator for constant svx::FrameBorder containers, iterates over visible borders. */
285 typedef FrameBorderIterBase< const FrameBorderPtrVec, FrameBorderPtrVec::const_iterator, FrameBorderVisible_Pred >
286     VisFrameBorderCIter;
287 
288 /** Iterator for mutable svx::FrameBorder containers, iterates over visible borders. */
289 typedef FrameBorderIterBase< FrameBorderPtrVec, FrameBorderPtrVec::iterator, FrameBorderVisible_Pred >
290     VisFrameBorderIter;
291 
292 /** Iterator for constant svx::FrameBorder containers, iterates over selected borders. */
293 typedef FrameBorderIterBase< const FrameBorderPtrVec, FrameBorderPtrVec::const_iterator, FrameBorderSelected_Pred >
294     SelFrameBorderCIter;
295 
296 /** Iterator for mutable svx::FrameBorder containers, iterates over selected borders. */
297 typedef FrameBorderIterBase< FrameBorderPtrVec, FrameBorderPtrVec::iterator, FrameBorderSelected_Pred >
298     SelFrameBorderIter;
299 
300 // ============================================================================
301 
302 } // namespace svx
303 
304 #endif
305 
306