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