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