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