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