xref: /aoo42x/main/svx/source/inc/frmselimpl.hxx (revision 3334a7e6)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 #ifndef SVX_FRMSELIMPL_HXX
25 #define SVX_FRMSELIMPL_HXX
26 
27 #include <vcl/virdev.hxx>
28 #include <vcl/image.hxx>
29 #include <svx/frmsel.hxx>
30 #include <svx/framelinkarray.hxx>
31 #include <editeng/borderline.hxx>
32 
33 namespace svx {
34 
35 namespace a11y { class AccFrameSelector; }
36 
37 // ============================================================================
38 
39 class FrameBorder
40 {
41 public:
42     explicit            FrameBorder( FrameBorderType eType );
43 
GetType() const44     inline FrameBorderType GetType() const { return meType; }
45 
IsEnabled() const46     inline bool         IsEnabled() const { return mbEnabled; }
47     void                Enable( FrameSelFlags nFlags );
48 
GetState() const49     inline FrameBorderState GetState() const { return meState; }
50     void                SetState( FrameBorderState eState );
51 
IsSelected() const52     inline bool         IsSelected() const { return mbSelected; }
Select(bool bSelect)53     inline void         Select( bool bSelect ) { mbSelected = bSelect; }
54 
GetCoreStyle() const55     const SvxBorderLine& GetCoreStyle() const { return maCoreStyle; }
56     void                SetCoreStyle( const SvxBorderLine* pStyle );
57 
SetUIColor(const Color & rColor)58     inline void         SetUIColor( const Color& rColor ) {maUIStyle.SetColor( rColor ); }
GetUIStyle() const59     inline const frame::Style& GetUIStyle() const { return maUIStyle; }
60 
ClearFocusArea()61     inline void         ClearFocusArea() { maFocusArea.Clear(); }
62     void                AddFocusPolygon( const Polygon& rFocus );
63     void                MergeFocusToPolyPolygon( PolyPolygon& rPPoly ) const;
64 
ClearClickArea()65     inline void         ClearClickArea() { maClickArea.Clear(); }
66     void                AddClickRect( const Rectangle& rRect );
67     bool                ContainsClickPoint( const Point& rPos ) const;
68     void                MergeClickAreaToPolyPolygon( PolyPolygon& rPPoly ) const;
69     Rectangle           GetClickBoundRect() const;
70 
71     void                SetKeyboardNeighbors(
72                             FrameBorderType eLeft, FrameBorderType eRight,
73                             FrameBorderType eTop, FrameBorderType eBottom );
74     FrameBorderType     GetKeyboardNeighbor( sal_uInt16 nKeyCode ) const;
75 
76 private:
77     const FrameBorderType meType;       /// Frame border type (position in control).
78     FrameBorderState    meState;        /// Frame border state (on/off/don't care).
79     SvxBorderLine       maCoreStyle;    /// Core style from application.
80     frame::Style        maUIStyle;      /// Internal style to draw lines.
81     FrameBorderType     meKeyLeft;      /// Left neighbor for keyboard control.
82     FrameBorderType     meKeyRight;     /// Right neighbor for keyboard control.
83     FrameBorderType     meKeyTop;       /// Upper neighbor for keyboard control.
84     FrameBorderType     meKeyBottom;    /// Lower neighbor for keyboard control.
85     PolyPolygon         maFocusArea;    /// Focus drawing areas.
86     PolyPolygon         maClickArea;    /// Mouse click areas.
87     bool                mbEnabled;      /// true = Border enabled in control.
88     bool                mbSelected;     /// true = Border selected in control.
89 };
90 
91 // ============================================================================
92 
93 typedef std::vector< FrameBorder* >     FrameBorderPtrVec;
94 
95 struct FrameSelectorImpl : public Resource
96 {
97     typedef ::com::sun::star::uno::Reference<
98         ::com::sun::star::accessibility::XAccessible >  XAccessibleRef;
99     typedef std::vector< a11y::AccFrameSelector* >      AccessibleImplVec;
100     typedef std::vector< XAccessibleRef >               XAccessibleRefVec;
101 
102     FrameSelector&      mrFrameSel;     /// The control itself.
103     VirtualDevice       maVirDev;       /// For all buffered drawing operations.
104     ImageList           maILArrows;     /// Arrows in current system colors.
105     Color               maBackCol;      /// Background color.
106     Color               maArrowCol;     /// Selection arrow color.
107     Color               maMarkCol;      /// Selection marker color.
108     Color               maHCLineCol;    /// High contrast line color.
109     Point               maVirDevPos;    /// Position of virtual device in the control.
110     Point               maMousePos;     /// Last mouse pointer position.
111 
112     FrameBorder         maLeft;         /// All data of left frame border.
113     FrameBorder         maRight;        /// All data of right frame border.
114     FrameBorder         maTop;          /// All data of top frame border.
115     FrameBorder         maBottom;       /// All data of bottom frame border.
116     FrameBorder         maHor;          /// All data of inner horizontal frame border.
117     FrameBorder         maVer;          /// All data of inner vertical frame border.
118     FrameBorder         maTLBR;         /// All data of top-left to bottom-right frame border.
119     FrameBorder         maBLTR;         /// All data of bottom-left to top-right frame border.
120     SvxBorderLine       maCurrStyle;    /// Current style and color for new borders.
121     frame::Array        maArray;        /// Frame link array to draw an array of frame borders.
122 
123     FrameSelFlags       mnFlags;        /// Flags for enabled frame borders.
124     FrameBorderPtrVec   maAllBorders;   /// Pointers to all frame borders.
125     FrameBorderPtrVec   maEnabBorders;  /// Pointers to enables frame borders.
126     Link                maSelectHdl;    /// Selection handler.
127 
128     long                mnCtrlSize;     /// Size of the control (always square).
129     long                mnArrowSize;    /// Size of an arrow image.
130     long                mnLine1;        /// Middle of left/top frame borders.
131     long                mnLine2;        /// Middle of inner frame borders.
132     long                mnLine3;        /// Middle of right/bottom frame borders.
133     long                mnFocusOffs;    /// Offset from frame border middle to draw focus.
134 
135     bool                mbHor;          /// true = Inner horizontal frame border enabled.
136     bool                mbVer;          /// true = Inner vertical frame border enabled.
137     bool                mbTLBR;         /// true = Top-left to bottom-right frame border enabled.
138     bool                mbBLTR;         /// true = Bottom-left to top-right frame border enabled.
139     bool                mbFullRepaint;  /// Used for repainting (false = only copy virtual device).
140     bool                mbAutoSelect;   /// true = Auto select a frame border, if focus reaches control.
141     bool                mbClicked;      /// true = The control has been clicked at least one time.
142     bool                mbHCMode;       /// true = High contrast mode.
143 
144     a11y::AccFrameSelector* mpAccess;   /// Pointer to accessibility object of the control.
145     XAccessibleRef      mxAccess;       /// Reference to accessibility object of the control.
146     AccessibleImplVec   maChildVec;     /// Pointers to accessibility objects for frame borders.
147     XAccessibleRefVec   mxChildVec;     /// References to accessibility objects for frame borders.
148 
149     explicit            FrameSelectorImpl( FrameSelector& rFrameSel );
150                         ~FrameSelectorImpl();
151 
152     // initialization ---------------------------------------------------------
153 
154     /** Initializes the control, enables/disables frame borders according to flags. */
155     void                Initialize( FrameSelFlags nFlags );
156 
157     /** Fills all color members from current style settings. */
158     void                InitColors();
159     /** Creates the image list with selection arrows regarding current style settings. */
160     void                InitArrowImageList();
161     /** Initializes global coordinates. */
162     void                InitGlobalGeometry();
163     /** Initializes coordinates of all frame borders. */
164     void                InitBorderGeometry();
165     /** Initializes click areas of all enabled frame borders. */
166     void                InitClickAreas();
167     /** Draws the entire control into the internal virtual device. */
168     void                InitVirtualDevice();
169 
170     // frame border access ----------------------------------------------------
171 
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 );
176 
177     // drawing ----------------------------------------------------------------
178 
179     /** Draws the background of the entire control (the gray areas between borders). */
180     void                DrawBackground();
181 
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();
186 
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();
191 
192     /** Draws all contents of the control. */
193     void                DrawVirtualDevice();
194     /** Copies contents of the virtual device to the control. */
195     void                CopyVirDevToControl();
196 
197     /** Draws tracking rectangles for all selected frame borders. */
198     void                DrawAllTrackingRects();
199 
200     /** Converts a mouse position to the virtual device position. */
201     Point               GetDevPosFromMousePos( const Point& rMousePos ) const;
202 
203     /** Invalidates the control.
204         @param bFullRepaint  true = Full repaint; false = update selection only. */
205     void                DoInvalidate( bool bFullRepaint );
206 
207     // frame border state and style -------------------------------------------
208 
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 SvxBorderLine* pStyle );
213     /** Sets the color of the specified frame border. */
214     void                SetBorderColor( FrameBorder& rBorder, const Color& rColor );
215 
216     /** Changes the state of a frame border after a control event (mouse/keyboard). */
217     void                ToggleBorderState( FrameBorder& rBorder );
218 
219     // frame border selection -------------------------------------------------
220 
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();
225 
226     /** Returns true, if all selected frame borders are equal (or if nothing is selected). */
227     bool                SelectedBordersEqual() const;
228 };
229 
230 // ============================================================================
231 
232 /** Dummy predicate for frame border iterators to use all borders in a container. */
233 struct FrameBorderDummy_Pred
234 {
operator ()svx::FrameBorderDummy_Pred235     inline bool operator()( const FrameBorder* ) const { return true; }
236 };
237 
238 /** Predicate for frame border iterators to use only visible borders in a container. */
239 struct FrameBorderVisible_Pred
240 {
operator ()svx::FrameBorderVisible_Pred241     inline bool operator()( const FrameBorder* pBorder ) const { return pBorder->GetState() == FRAMESTATE_SHOW; }
242 };
243 
244 /** Predicate for frame border iterators to use only selected borders in a container. */
245 struct FrameBorderSelected_Pred
246 {
operator ()svx::FrameBorderSelected_Pred247     inline bool operator()( const FrameBorder* pBorder ) const { return pBorder->IsSelected(); }
248 };
249 
250 /** Template class for all types of frame border iterators. */
251 template< typename Cont, typename Iter, typename Pred >
252 class FrameBorderIterBase
253 {
254 public:
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;
260 
261     explicit            FrameBorderIterBase( container_type& rCont );
Is() const262     inline bool         Is() const { return maIt != maEnd; }
263     this_type&          operator++();
operator *() const264     inline value_type   operator*() const { return *maIt; }
265 
266 private:
267     iterator_type       maIt;
268     iterator_type       maEnd;
269     predicate_type      maPred;
270 };
271 
272 /** Iterator for constant svx::FrameBorder containers, iterates over all borders. */
273 typedef FrameBorderIterBase< const FrameBorderPtrVec, FrameBorderPtrVec::const_iterator, FrameBorderDummy_Pred >
274     FrameBorderCIter;
275 
276 /** Iterator for mutable svx::FrameBorder containers, iterates over all borders. */
277 typedef FrameBorderIterBase< FrameBorderPtrVec, FrameBorderPtrVec::iterator, FrameBorderDummy_Pred >
278     FrameBorderIter;
279 
280 /** Iterator for constant svx::FrameBorder containers, iterates over visible borders. */
281 typedef FrameBorderIterBase< const FrameBorderPtrVec, FrameBorderPtrVec::const_iterator, FrameBorderVisible_Pred >
282     VisFrameBorderCIter;
283 
284 /** Iterator for mutable svx::FrameBorder containers, iterates over visible borders. */
285 typedef FrameBorderIterBase< FrameBorderPtrVec, FrameBorderPtrVec::iterator, FrameBorderVisible_Pred >
286     VisFrameBorderIter;
287 
288 /** Iterator for constant svx::FrameBorder containers, iterates over selected borders. */
289 typedef FrameBorderIterBase< const FrameBorderPtrVec, FrameBorderPtrVec::const_iterator, FrameBorderSelected_Pred >
290     SelFrameBorderCIter;
291 
292 /** Iterator for mutable svx::FrameBorder containers, iterates over selected borders. */
293 typedef FrameBorderIterBase< FrameBorderPtrVec, FrameBorderPtrVec::iterator, FrameBorderSelected_Pred >
294     SelFrameBorderIter;
295 
296 // ============================================================================
297 
298 } // namespace svx
299 
300 #endif
301 
302