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 SVX_FRMSELIMPL_HXX
21 : #define SVX_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 : inline void ClearFocusArea() { maFocusArea.Clear(); }
60 : void AddFocusPolygon( const Polygon& rFocus );
61 : void MergeFocusToPolyPolygon( 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 : PolyPolygon maFocusArea; /// Focus drawing areas.
83 : 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 :
151 : /** Initializes the control, enables/disables frame borders according to flags. */
152 : void Initialize( FrameSelFlags nFlags );
153 :
154 : /** Fills all color members from current style settings. */
155 : void InitColors();
156 : /** Creates the image list with selection arrows regarding current style settings. */
157 : void InitArrowImageList();
158 : /** Initializes global coordinates. */
159 : void InitGlobalGeometry();
160 : /** Initializes coordinates of all frame borders. */
161 : void InitBorderGeometry();
162 : /** Initializes click areas of all enabled frame borders. */
163 : void InitClickAreas();
164 : /** Draws the entire control into the internal virtual device. */
165 : void InitVirtualDevice();
166 :
167 : // frame border access ----------------------------------------------------
168 :
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 :
176 : /** Draws the background of the entire control (the gray areas between borders). */
177 : void DrawBackground();
178 :
179 : /** Draws selection arrows for the specified frame border. */
180 : void DrawArrows( const FrameBorder& rBorder );
181 : /** Draws arrows in current selection state for all enabled frame borders. */
182 : void DrawAllArrows();
183 :
184 : /** Returns the color that has to be used to draw a frame border. */
185 : Color GetDrawLineColor( const Color& rColor ) const;
186 : /** Draws all frame borders. */
187 : void DrawAllFrameBorders();
188 :
189 : /** Draws all contents of the control. */
190 : void DrawVirtualDevice();
191 : /** Copies contents of the virtual device to the control. */
192 : void CopyVirDevToControl();
193 :
194 : /** Draws tracking rectangles for all selected frame borders. */
195 : void DrawAllTrackingRects();
196 :
197 : /** Converts a mouse position to the virtual device position. */
198 : Point GetDevPosFromMousePos( const Point& rMousePos ) const;
199 :
200 : /** Invalidates the control.
201 : @param bFullRepaint true = Full repaint; false = update selection only. */
202 : void DoInvalidate( bool bFullRepaint );
203 :
204 : // frame border state and style -------------------------------------------
205 :
206 : /** Sets the state of the specified frame border. */
207 : void SetBorderState( FrameBorder& rBorder, FrameBorderState eState );
208 : /** Sets the core style of the specified frame border, or hides the frame border, if pStyle is 0. */
209 : void SetBorderCoreStyle( FrameBorder& rBorder, const editeng::SvxBorderLine* pStyle );
210 : /** Sets the color of the specified frame border. */
211 : void SetBorderColor( FrameBorder& rBorder, const Color& rColor );
212 :
213 : /** Changes the state of a frame border after a control event (mouse/keyboard). */
214 : void ToggleBorderState( FrameBorder& rBorder );
215 :
216 : // frame border selection -------------------------------------------------
217 :
218 : /** Selects a frame border and schedules redraw. */
219 : void SelectBorder( FrameBorder& rBorder, bool bSelect );
220 : /** Grabs focus without auto-selection of a frame border, if no border selected. */
221 : void SilentGrabFocus();
222 :
223 : /** Returns true, if all selected frame borders are equal (or if nothing is selected). */
224 : bool SelectedBordersEqual() const;
225 : };
226 :
227 : // ============================================================================
228 :
229 : /** Dummy predicate for frame border iterators to use all borders in a container. */
230 : struct FrameBorderDummy_Pred
231 : {
232 0 : inline bool operator()( const FrameBorder* ) const { return true; }
233 : };
234 :
235 : /** Predicate for frame border iterators to use only visible borders in a container. */
236 : struct FrameBorderVisible_Pred
237 : {
238 0 : inline bool operator()( const FrameBorder* pBorder ) const { return pBorder->GetState() == FRAMESTATE_SHOW; }
239 : };
240 :
241 : /** Predicate for frame border iterators to use only selected borders in a container. */
242 : struct FrameBorderSelected_Pred
243 : {
244 0 : inline bool operator()( const FrameBorder* pBorder ) const { return pBorder->IsSelected(); }
245 : };
246 :
247 : /** Template class for all types of frame border iterators. */
248 : template< typename Cont, typename Iter, typename Pred >
249 : class FrameBorderIterBase
250 : {
251 : public:
252 : typedef Cont container_type;
253 : typedef Iter iterator_type;
254 : typedef Pred predicate_type;
255 : typedef typename Cont::value_type value_type;
256 : typedef FrameBorderIterBase< Cont, Iter, Pred > this_type;
257 :
258 : explicit FrameBorderIterBase( container_type& rCont );
259 0 : inline bool Is() const { return maIt != maEnd; }
260 : this_type& operator++();
261 0 : inline value_type operator*() const { return *maIt; }
262 :
263 : private:
264 : iterator_type maIt;
265 : iterator_type maEnd;
266 : predicate_type maPred;
267 : };
268 :
269 : /** Iterator for constant svx::FrameBorder containers, iterates over all borders. */
270 : typedef FrameBorderIterBase< const FrameBorderPtrVec, FrameBorderPtrVec::const_iterator, FrameBorderDummy_Pred >
271 : FrameBorderCIter;
272 :
273 : /** Iterator for mutable svx::FrameBorder containers, iterates over all borders. */
274 : typedef FrameBorderIterBase< FrameBorderPtrVec, FrameBorderPtrVec::iterator, FrameBorderDummy_Pred >
275 : FrameBorderIter;
276 :
277 : /** Iterator for constant svx::FrameBorder containers, iterates over visible borders. */
278 : typedef FrameBorderIterBase< const FrameBorderPtrVec, FrameBorderPtrVec::const_iterator, FrameBorderVisible_Pred >
279 : VisFrameBorderCIter;
280 :
281 : /** Iterator for mutable svx::FrameBorder containers, iterates over visible borders. */
282 : typedef FrameBorderIterBase< FrameBorderPtrVec, FrameBorderPtrVec::iterator, FrameBorderVisible_Pred >
283 : VisFrameBorderIter;
284 :
285 : /** Iterator for constant svx::FrameBorder containers, iterates over selected borders. */
286 : typedef FrameBorderIterBase< const FrameBorderPtrVec, FrameBorderPtrVec::const_iterator, FrameBorderSelected_Pred >
287 : SelFrameBorderCIter;
288 :
289 : /** Iterator for mutable svx::FrameBorder containers, iterates over selected borders. */
290 : typedef FrameBorderIterBase< FrameBorderPtrVec, FrameBorderPtrVec::iterator, FrameBorderSelected_Pred >
291 : SelFrameBorderIter;
292 :
293 : // ============================================================================
294 :
295 : } // namespace svx
296 :
297 : #endif
298 :
299 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|