1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 SVX_FRMSELIMPL_HXX
21 #define SVX_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>
31 namespace a11y
{ class AccFrameSelector
; }
33 // ============================================================================
38 explicit FrameBorder( FrameBorderType eType
);
40 inline FrameBorderType
GetType() const { return meType
; }
42 inline bool IsEnabled() const { return mbEnabled
; }
43 void Enable( FrameSelFlags nFlags
);
45 inline FrameBorderState
GetState() const { return meState
; }
46 void SetState( FrameBorderState eState
);
48 inline bool IsSelected() const { return mbSelected
; }
49 inline void Select( bool bSelect
) { mbSelected
= bSelect
; }
51 const editeng::SvxBorderLine
& GetCoreStyle() const { return maCoreStyle
; }
52 void SetCoreStyle( const editeng::SvxBorderLine
* pStyle
);
54 inline void SetUIColorPrim( const Color
& rColor
) {maUIStyle
.SetColorPrim( rColor
); }
55 inline void SetUIColorSecn( const Color
& rColor
) {maUIStyle
.SetColorSecn( rColor
); }
56 inline void SetUIColorGap( bool bUseIt
, const Color
& rColor
) {maUIStyle
.SetColorGap(bUseIt
, rColor
);}
57 inline const frame::Style
& GetUIStyle() const { return maUIStyle
; }
59 inline void ClearFocusArea() { maFocusArea
.Clear(); }
60 void AddFocusPolygon( const Polygon
& rFocus
);
61 void MergeFocusToPolyPolygon( PolyPolygon
& rPPoly
) const;
63 inline void ClearClickArea() { maClickArea
.Clear(); }
64 void AddClickRect( const Rectangle
& rRect
);
65 bool ContainsClickPoint( const Point
& rPos
) const;
66 Rectangle
GetClickBoundRect() const;
68 void SetKeyboardNeighbors(
69 FrameBorderType eLeft
, FrameBorderType eRight
,
70 FrameBorderType eTop
, FrameBorderType eBottom
);
71 FrameBorderType
GetKeyboardNeighbor( sal_uInt16 nKeyCode
) const;
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.
88 // ============================================================================
90 typedef std::vector
< FrameBorder
* > FrameBorderPtrVec
;
92 struct FrameSelectorImpl
: public Resource
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
;
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.
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.
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.
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.
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.
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.
146 explicit FrameSelectorImpl( FrameSelector
& rFrameSel
);
147 ~FrameSelectorImpl();
149 // initialization ---------------------------------------------------------
151 /** Initializes the control, enables/disables frame borders according to flags. */
152 void Initialize( FrameSelFlags nFlags
);
154 /** Fills all color members from current style settings. */
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 /** call this to recalculate based on parent size */
170 // frame border access ----------------------------------------------------
172 /** Returns the object representing the specified frame border. */
173 const FrameBorder
& GetBorder( FrameBorderType eBorder
) const;
174 /** Returns the object representing the specified frame border (write access). */
175 FrameBorder
& GetBorderAccess( FrameBorderType eBorder
);
177 // drawing ----------------------------------------------------------------
179 /** Draws the background of the entire control (the gray areas between borders). */
180 void DrawBackground();
182 /** Draws selection arrows for the specified frame border. */
183 void DrawArrows( const FrameBorder
& rBorder
);
184 /** Draws arrows in current selection state for all enabled frame borders. */
185 void DrawAllArrows();
187 /** Returns the color that has to be used to draw a frame border. */
188 Color
GetDrawLineColor( const Color
& rColor
) const;
189 /** Draws all frame borders. */
190 void DrawAllFrameBorders();
192 /** Draws all contents of the control. */
193 void DrawVirtualDevice();
194 /** Copies contents of the virtual device to the control. */
195 void CopyVirDevToControl();
197 /** Draws tracking rectangles for all selected frame borders. */
198 void DrawAllTrackingRects();
200 /** Converts a mouse position to the virtual device position. */
201 Point
GetDevPosFromMousePos( const Point
& rMousePos
) const;
203 /** Invalidates the control.
204 @param bFullRepaint true = Full repaint; false = update selection only. */
205 void DoInvalidate( bool bFullRepaint
);
207 // frame border state and style -------------------------------------------
209 /** Sets the state of the specified frame border. */
210 void SetBorderState( FrameBorder
& rBorder
, FrameBorderState eState
);
211 /** Sets the core style of the specified frame border, or hides the frame border, if pStyle is 0. */
212 void SetBorderCoreStyle( FrameBorder
& rBorder
, const editeng::SvxBorderLine
* pStyle
);
213 /** Sets the color of the specified frame border. */
214 void SetBorderColor( FrameBorder
& rBorder
, const Color
& rColor
);
216 /** Changes the state of a frame border after a control event (mouse/keyboard). */
217 void ToggleBorderState( FrameBorder
& rBorder
);
219 // frame border selection -------------------------------------------------
221 /** Selects a frame border and schedules redraw. */
222 void SelectBorder( FrameBorder
& rBorder
, bool bSelect
);
223 /** Grabs focus without auto-selection of a frame border, if no border selected. */
224 void SilentGrabFocus();
226 /** Returns true, if all selected frame borders are equal (or if nothing is selected). */
227 bool SelectedBordersEqual() const;
230 // ============================================================================
232 /** Dummy predicate for frame border iterators to use all borders in a container. */
233 struct FrameBorderDummy_Pred
235 inline bool operator()( const FrameBorder
* ) const { return true; }
238 /** Predicate for frame border iterators to use only visible borders in a container. */
239 struct FrameBorderVisible_Pred
241 inline bool operator()( const FrameBorder
* pBorder
) const { return pBorder
->GetState() == FRAMESTATE_SHOW
; }
244 /** Predicate for frame border iterators to use only selected borders in a container. */
245 struct FrameBorderSelected_Pred
247 inline bool operator()( const FrameBorder
* pBorder
) const { return pBorder
->IsSelected(); }
250 /** Template class for all types of frame border iterators. */
251 template< typename Cont
, typename Iter
, typename Pred
>
252 class FrameBorderIterBase
255 typedef Cont container_type
;
256 typedef Iter iterator_type
;
257 typedef Pred predicate_type
;
258 typedef typename
Cont::value_type value_type
;
259 typedef FrameBorderIterBase
< Cont
, Iter
, Pred
> this_type
;
261 explicit FrameBorderIterBase( container_type
& rCont
);
262 inline bool Is() const { return maIt
!= maEnd
; }
263 this_type
& operator++();
264 inline value_type
operator*() const { return *maIt
; }
269 predicate_type maPred
;
272 /** Iterator for constant svx::FrameBorder containers, iterates over all borders. */
273 typedef FrameBorderIterBase
< const FrameBorderPtrVec
, FrameBorderPtrVec::const_iterator
, FrameBorderDummy_Pred
>
276 /** Iterator for mutable svx::FrameBorder containers, iterates over all borders. */
277 typedef FrameBorderIterBase
< FrameBorderPtrVec
, FrameBorderPtrVec::iterator
, FrameBorderDummy_Pred
>
280 /** Iterator for constant svx::FrameBorder containers, iterates over visible borders. */
281 typedef FrameBorderIterBase
< const FrameBorderPtrVec
, FrameBorderPtrVec::const_iterator
, FrameBorderVisible_Pred
>
284 /** Iterator for mutable svx::FrameBorder containers, iterates over visible borders. */
285 typedef FrameBorderIterBase
< FrameBorderPtrVec
, FrameBorderPtrVec::iterator
, FrameBorderVisible_Pred
>
288 /** Iterator for constant svx::FrameBorder containers, iterates over selected borders. */
289 typedef FrameBorderIterBase
< const FrameBorderPtrVec
, FrameBorderPtrVec::const_iterator
, FrameBorderSelected_Pred
>
292 /** Iterator for mutable svx::FrameBorder containers, iterates over selected borders. */
293 typedef FrameBorderIterBase
< FrameBorderPtrVec
, FrameBorderPtrVec::iterator
, FrameBorderSelected_Pred
>
296 // ============================================================================
302 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */