bump product version to 5.0.4.1
[LibreOffice.git] / svx / source / inc / frmselimpl.hxx
blob4b516e83139bf230677a2ea575caee031d422dcf
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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_SOURCE_INC_FRMSELIMPL_HXX
21 #define INCLUDED_SVX_SOURCE_INC_FRMSELIMPL_HXX
23 #include <vcl/virdev.hxx>
24 #include <vcl/image.hxx>
25 #include <svx/frmsel.hxx>
26 #include <svx/framelinkarray.hxx>
27 #include <editeng/borderline.hxx>
29 namespace svx {
31 namespace a11y {
32 class AccFrameSelector;
35 class FrameBorder
37 public:
38 explicit FrameBorder(FrameBorderType eType);
40 inline FrameBorderType GetType() const
42 return meType;
45 inline bool IsEnabled() const
47 return mbEnabled;
49 void Enable(FrameSelFlags nFlags);
51 inline FrameBorderState GetState() const
53 return meState;
55 void SetState(FrameBorderState eState);
57 inline bool IsSelected() const { return mbSelected; }
58 inline void Select( bool bSelect ) { mbSelected = bSelect; }
60 const editeng::SvxBorderLine& GetCoreStyle() const { return maCoreStyle; }
61 void SetCoreStyle( const editeng::SvxBorderLine* pStyle );
63 inline void SetUIColorPrim( const Color& rColor ) {maUIStyle.SetColorPrim( rColor ); }
64 inline void SetUIColorSecn( const Color& rColor ) {maUIStyle.SetColorSecn( rColor ); }
65 inline void SetUIColorGap( bool bUseIt, const Color& rColor ) {maUIStyle.SetColorGap(bUseIt, rColor);}
66 inline const frame::Style& GetUIStyle() const { return maUIStyle; }
68 inline void ClearFocusArea() { maFocusArea.Clear(); }
69 void AddFocusPolygon( const Polygon& rFocus );
70 void MergeFocusToPolyPolygon( tools::PolyPolygon& rPPoly ) const;
72 inline void ClearClickArea() { maClickArea.Clear(); }
73 void AddClickRect( const Rectangle& rRect );
74 bool ContainsClickPoint( const Point& rPos ) const;
75 Rectangle GetClickBoundRect() const;
77 void SetKeyboardNeighbors(FrameBorderType eLeft, FrameBorderType eRight,
78 FrameBorderType eTop, FrameBorderType eBottom);
79 FrameBorderType GetKeyboardNeighbor( sal_uInt16 nKeyCode ) const;
81 private:
82 const FrameBorderType meType; /// Frame border type (position in control).
83 FrameBorderState meState; /// Frame border state (on/off/don't care).
84 editeng::SvxBorderLine maCoreStyle; /// Core style from application.
85 frame::Style maUIStyle; /// Internal style to draw lines.
86 FrameBorderType meKeyLeft; /// Left neighbor for keyboard control.
87 FrameBorderType meKeyRight; /// Right neighbor for keyboard control.
88 FrameBorderType meKeyTop; /// Upper neighbor for keyboard control.
89 FrameBorderType meKeyBottom; /// Lower neighbor for keyboard control.
90 tools::PolyPolygon maFocusArea; /// Focus drawing areas.
91 tools::PolyPolygon maClickArea; /// Mouse click areas.
92 bool mbEnabled : 1; /// true = Border enabled in control.
93 bool mbSelected : 1; /// true = Border selected in control.
98 typedef std::vector< FrameBorder* > FrameBorderPtrVec;
100 struct FrameSelectorImpl : public Resource
102 typedef css::uno::Reference<css::accessibility::XAccessible> XAccessibleRef;
103 typedef std::vector<a11y::AccFrameSelector*> AccessibleImplVec;
104 typedef std::vector<XAccessibleRef> XAccessibleRefVec;
106 FrameSelector& mrFrameSel; /// The control itself.
107 ScopedVclPtr<VirtualDevice> mpVirDev; /// 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.
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 editeng::SvxBorderLine maCurrStyle; /// Current style and color for new borders.
125 frame::Array maArray; /// Frame link array to draw an array of frame borders.
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.
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.
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.
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.
153 explicit FrameSelectorImpl( FrameSelector& rFrameSel );
154 ~FrameSelectorImpl();
156 // initialization
157 /** Initializes the control, enables/disables frame borders according to flags. */
158 void Initialize( FrameSelFlags nFlags );
160 /** Fills all color members from current style settings. */
161 void InitColors();
162 /** Creates the image list with selection arrows regarding current style settings. */
163 void InitArrowImageList();
164 /** Initializes global coordinates. */
165 void InitGlobalGeometry();
166 /** Initializes coordinates of all frame borders. */
167 void InitBorderGeometry();
168 /** Initializes click areas of all enabled frame borders. */
169 void InitClickAreas();
170 /** Draws the entire control into the internal virtual device. */
171 void InitVirtualDevice();
172 /** call this to recalculate based on parent size */
173 void sizeChanged();
175 // frame border access
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 );
181 // drawing
182 /** Draws the background of the entire control (the gray areas between borders). */
183 void DrawBackground();
185 /** Draws selection arrows for the specified frame border. */
186 void DrawArrows( const FrameBorder& rBorder );
187 /** Draws arrows in current selection state for all enabled frame borders. */
188 void DrawAllArrows();
190 /** Returns the color that has to be used to draw a frame border. */
191 Color GetDrawLineColor( const Color& rColor ) const;
192 /** Draws all frame borders. */
193 void DrawAllFrameBorders();
195 /** Draws all contents of the control. */
196 void DrawVirtualDevice();
197 /** Copies contents of the virtual device to the control. */
198 void CopyVirDevToControl(vcl::RenderContext& rRenderContext);
200 /** Draws tracking rectangles for all selected frame borders. */
201 void DrawAllTrackingRects();
203 /** Converts a mouse position to the virtual device position. */
204 Point GetDevPosFromMousePos( const Point& rMousePos ) const;
206 /** Invalidates the control.
207 @param bFullRepaint true = Full repaint; false = update selection only. */
208 void DoInvalidate( bool bFullRepaint );
210 // frame border state and style
211 /** Sets the state of the specified frame border. */
212 void SetBorderState( FrameBorder& rBorder, FrameBorderState eState );
213 /** Sets the core style of the specified frame border, or hides the frame border, if pStyle is 0. */
214 void SetBorderCoreStyle( FrameBorder& rBorder, const editeng::SvxBorderLine* pStyle );
216 /** Changes the state of a frame border after a control event (mouse/keyboard). */
217 void ToggleBorderState( FrameBorder& rBorder );
219 // frame border selection
220 /** Selects a frame border and schedules redraw. */
221 void SelectBorder( FrameBorder& rBorder, bool bSelect );
222 /** Grabs focus without auto-selection of a frame border, if no border selected. */
223 void SilentGrabFocus();
225 /** Returns true, if all selected frame borders are equal (or if nothing is selected). */
226 bool SelectedBordersEqual() const;
231 /** Dummy predicate for frame border iterators to use all borders in a container. */
232 struct FrameBorderDummy_Pred
234 inline bool operator()( const FrameBorder* ) const { return true; }
237 /** Predicate for frame border iterators to use only visible borders in a container. */
238 struct FrameBorderVisible_Pred
240 inline bool operator()( const FrameBorder* pBorder ) const { return pBorder->GetState() == FRAMESTATE_SHOW; }
243 /** Predicate for frame border iterators to use only selected borders in a container. */
244 struct FrameBorderSelected_Pred
246 inline bool operator()( const FrameBorder* pBorder ) const { return pBorder->IsSelected(); }
249 /** Template class for all types of frame border iterators. */
250 template< typename Cont, typename Iter, typename Pred >
251 class FrameBorderIterBase
253 public:
254 typedef Cont container_type;
255 typedef Iter iterator_type;
256 typedef Pred predicate_type;
257 typedef typename Cont::value_type value_type;
258 typedef FrameBorderIterBase<Cont, Iter, Pred> this_type;
260 explicit FrameBorderIterBase( container_type& rCont );
261 inline bool Is() const { return maIt != maEnd; }
262 this_type& operator++();
263 inline value_type operator*() const { return *maIt; }
265 private:
266 iterator_type maIt;
267 iterator_type maEnd;
268 predicate_type maPred;
271 /** Iterator for constant svx::FrameBorder containers, iterates over all borders. */
272 typedef FrameBorderIterBase< const FrameBorderPtrVec, FrameBorderPtrVec::const_iterator, FrameBorderDummy_Pred >
273 FrameBorderCIter;
275 /** Iterator for mutable svx::FrameBorder containers, iterates over all borders. */
276 typedef FrameBorderIterBase< FrameBorderPtrVec, FrameBorderPtrVec::iterator, FrameBorderDummy_Pred >
277 FrameBorderIter;
279 /** Iterator for constant svx::FrameBorder containers, iterates over visible borders. */
280 typedef FrameBorderIterBase< const FrameBorderPtrVec, FrameBorderPtrVec::const_iterator, FrameBorderVisible_Pred >
281 VisFrameBorderCIter;
283 /** Iterator for mutable svx::FrameBorder containers, iterates over visible borders. */
284 typedef FrameBorderIterBase< FrameBorderPtrVec, FrameBorderPtrVec::iterator, FrameBorderVisible_Pred >
285 VisFrameBorderIter;
287 /** Iterator for constant svx::FrameBorder containers, iterates over selected borders. */
288 typedef FrameBorderIterBase< const FrameBorderPtrVec, FrameBorderPtrVec::const_iterator, FrameBorderSelected_Pred >
289 SelFrameBorderCIter;
291 /** Iterator for mutable svx::FrameBorder containers, iterates over selected borders. */
292 typedef FrameBorderIterBase< FrameBorderPtrVec, FrameBorderPtrVec::iterator, FrameBorderSelected_Pred >
293 SelFrameBorderIter;
297 #endif
299 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */