summaryrefslogtreecommitdiff
path: root/svx/source/inc/frmselimpl.hxx
blob: 09cc6188250445c3c041387cf32a36e21cd9c819 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
 * This file is part of the LibreOffice project.
 *
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 *
 * This file incorporates work covered by the following license notice:
 *
 *   Licensed to the Apache Software Foundation (ASF) under one or more
 *   contributor license agreements. See the NOTICE file distributed
 *   with this work for additional information regarding copyright
 *   ownership. The ASF licenses this file to you under the Apache
 *   License, Version 2.0 (the "License"); you may not use this file
 *   except in compliance with the License. You may obtain a copy of
 *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
 */

#ifndef INCLUDED_SVX_SOURCE_INC_FRMSELIMPL_HXX
#define INCLUDED_SVX_SOURCE_INC_FRMSELIMPL_HXX

#include <vcl/virdev.hxx>
#include <vcl/image.hxx>
#include <svx/frmsel.hxx>
#include <svx/framelink.hxx>
#include <svx/framelinkarray.hxx>
#include <editeng/borderline.hxx>

namespace svx {

namespace a11y {
    class AccFrameSelector;
    class AccFrameSelectorChild;
}

class FrameBorder
{
public:
    explicit FrameBorder(FrameBorderType eType);
    static double GetDefaultPatternScale() { return 0.05; }

    FrameBorderType GetType() const
    {
        return meType;
    }

    bool IsEnabled() const
    {
        return mbEnabled;
    }
    void Enable(FrameSelFlags nFlags);

    FrameBorderState GetState() const
    {
        return meState;
    }
    void SetState(FrameBorderState eState);

    bool IsSelected() const { return mbSelected; }
    void Select( bool bSelect ) { mbSelected = bSelect; }

    const editeng::SvxBorderLine& GetCoreStyle() const { return maCoreStyle; }
    void SetCoreStyle( const editeng::SvxBorderLine* pStyle );

    void SetUIColorPrim( const Color& rColor ) {maUIStyle.SetColorPrim( rColor ); }
    void SetUIColorSecn( const Color& rColor ) {maUIStyle.SetColorSecn( rColor ); }
    const frame::Style& GetUIStyle() const { return maUIStyle; }

    void ClearFocusArea() { maFocusArea.Clear(); }
    void AddFocusPolygon( const tools::Polygon& rFocus );
    void MergeFocusToPolyPolygon( tools::PolyPolygon& rPPoly ) const;

    void ClearClickArea() { maClickArea.Clear(); }
    void AddClickRect( const tools::Rectangle& rRect );
    bool ContainsClickPoint( const Point& rPos ) const;
    tools::Rectangle GetClickBoundRect() const;

    void SetKeyboardNeighbors(FrameBorderType eLeft, FrameBorderType eRight,
                              FrameBorderType eTop, FrameBorderType eBottom);
    FrameBorderType GetKeyboardNeighbor( sal_uInt16 nKeyCode ) const;

private:
    const FrameBorderType meType; /// Frame border type (position in control).
    FrameBorderState meState; /// Frame border state (on/off/don't care).
    editeng::SvxBorderLine maCoreStyle; /// Core style from application.
    frame::Style maUIStyle; /// Internal style to draw lines.
    FrameBorderType meKeyLeft; /// Left neighbor for keyboard control.
    FrameBorderType meKeyRight; /// Right neighbor for keyboard control.
    FrameBorderType meKeyTop; /// Upper neighbor for keyboard control.
    FrameBorderType meKeyBottom;    /// Lower neighbor for keyboard control.
    tools::PolyPolygon maFocusArea;    /// Focus drawing areas.
    tools::PolyPolygon maClickArea;    /// Mouse click areas.
    bool mbEnabled : 1; /// true = Border enabled in control.
    bool mbSelected : 1; /// true = Border selected in control.
};


typedef std::vector< FrameBorder* > FrameBorderPtrVec;

struct FrameSelectorImpl
{
    FrameSelector&      mrFrameSel;     /// The control itself.
    ScopedVclPtr<VirtualDevice> mpVirDev; /// For all buffered drawing operations.
    std::vector<Image>  maArrows;       /// Arrows in current system colors.
    Color               maBackCol;      /// Background color.
    Color               maArrowCol;     /// Selection arrow color.
    Color               maMarkCol;      /// Selection marker color.
    Color               maHCLineCol;    /// High contrast line color.
    Point               maVirDevPos;    /// Position of virtual device in the control.

    FrameBorder         maLeft;         /// All data of left frame border.
    FrameBorder         maRight;        /// All data of right frame border.
    FrameBorder         maTop;          /// All data of top frame border.
    FrameBorder         maBottom;       /// All data of bottom frame border.
    FrameBorder         maHor;          /// All data of inner horizontal frame border.
    FrameBorder         maVer;          /// All data of inner vertical frame border.
    FrameBorder         maTLBR;         /// All data of top-left to bottom-right frame border.
    FrameBorder         maBLTR;         /// All data of bottom-left to top-right frame border.
    editeng::SvxBorderLine maCurrStyle;    /// Current style and color for new borders.
    frame::Array        maArray;        /// Frame link array to draw an array of frame borders.

    FrameSelFlags       mnFlags;        /// Flags for enabled frame borders.
    FrameBorderPtrVec   maAllBorders;   /// Pointers to all frame borders.
    FrameBorderPtrVec   maEnabBorders;  /// Pointers to enables frame borders.
    Link<LinkParamNone*,void> maSelectHdl;    /// Selection handler.

    long                mnCtrlSize;     /// Size of the control (always square).
    long                mnArrowSize;    /// Size of an arrow image.
    long                mnLine1;        /// Middle of left/top frame borders.
    long                mnLine2;        /// Middle of inner frame borders.
    long                mnLine3;        /// Middle of right/bottom frame borders.
    long                mnFocusOffs;    /// Offset from frame border middle to draw focus.

    bool                mbHor;          /// true = Inner horizontal frame border enabled.
    bool                mbVer;          /// true = Inner vertical frame border enabled.
    bool                mbTLBR;         /// true = Top-left to bottom-right frame border enabled.
    bool                mbBLTR;         /// true = Bottom-left to top-right frame border enabled.
    bool                mbFullRepaint;  /// Used for repainting (false = only copy virtual device).
    bool                mbAutoSelect;   /// true = Auto select a frame border, if focus reaches control.
    bool                mbHCMode;       /// true = High contrast mode.

    std::vector<rtl::Reference<a11y::AccFrameSelectorChild>>
                        maChildVec;     /// Pointers to accessibility objects for frame borders.
    explicit            FrameSelectorImpl( FrameSelector& rFrameSel );
                        ~FrameSelectorImpl();

    // initialization
    /** Initializes the control, enables/disables frame borders according to flags. */
    void                Initialize( FrameSelFlags nFlags );

    /** Fills all color members from current style settings. */
    void                InitColors();
    /** Creates the image list with selection arrows regarding current style settings. */
    void                InitArrowImageList();
    /** Initializes global coordinates. */
    void                InitGlobalGeometry();
    /** Initializes coordinates of all frame borders. */
    void                InitBorderGeometry();
    /** Draws the entire control into the internal virtual device. */
    void                InitVirtualDevice();
    /** call this to recalculate based on parent size */
    void                sizeChanged();

    // frame border access
    /** Returns the object representing the specified frame border. */
    const FrameBorder&  GetBorder( FrameBorderType eBorder ) const;
    /** Returns the object representing the specified frame border (write access). */
    FrameBorder&        GetBorderAccess( FrameBorderType eBorder );

    // drawing
    /** Draws the background of the entire control (the gray areas between borders). */
    void                DrawBackground();

    /** Draws selection arrows for the specified frame border. */
    void                DrawArrows( const FrameBorder& rBorder );

    /** Returns the color that has to be used to draw a frame border. */
    Color               GetDrawLineColor( const Color& rColor ) const;
    /** Draws all frame borders. */
    void                DrawAllFrameBorders();

    /** Draws all contents of the control. */
    void                DrawVirtualDevice();
    /** Copies contents of the virtual device to the control. */
    void                CopyVirDevToControl(vcl::RenderContext& rRenderContext);

    /** Draws tracking rectangles for all selected frame borders. */
    void                DrawAllTrackingRects(vcl::RenderContext& rRenderContext);

    /** Converts a mouse position to the virtual device position. */
    Point               GetDevPosFromMousePos( const Point& rMousePos ) const;

    /** Invalidates the control.
        @param bFullRepaint  true = Full repaint; false = update selection only. */
    void                DoInvalidate( bool bFullRepaint );

    // frame border state and style
    /** Sets the state of the specified frame border. */
    void                SetBorderState( FrameBorder& rBorder, FrameBorderState eState );
    /** Sets the core style of the specified frame border, or hides the frame border, if pStyle is 0. */
    void                SetBorderCoreStyle( FrameBorder& rBorder, const editeng::SvxBorderLine* pStyle );

    /** Changes the state of a frame border after a control event (mouse/keyboard). */
    void                ToggleBorderState( FrameBorder& rBorder );

    // frame border selection
    /** Selects a frame border and schedules redraw. */
    void                SelectBorder( FrameBorder& rBorder, bool bSelect );
    /** Grabs focus without auto-selection of a frame border, if no border selected. */
    void                SilentGrabFocus();

    /** Returns true, if all selected frame borders are equal (or if nothing is selected). */
    bool                SelectedBordersEqual() const;
};


/** Dummy predicate for frame border iterators to use all borders in a container. */
struct FrameBorderDummy_Pred
{
    bool operator()( const FrameBorder* ) const { return true; }
};

/** Predicate for frame border iterators to use only visible borders in a container. */
struct FrameBorderVisible_Pred
{
    bool operator()( const FrameBorder* pBorder ) const { return pBorder->GetState() == FrameBorderState::Show; }
};

/** Predicate for frame border iterators to use only selected borders in a container. */
struct FrameBorderSelected_Pred
{
    bool operator()( const FrameBorder* pBorder ) const { return pBorder->IsSelected(); }
};

/** Template class for all types of frame border iterators. */
template< typename Cont, typename Iter, typename Pred >
class FrameBorderIterBase
{
public:
    typedef Cont container_type;
    typedef Iter iterator_type;
    typedef typename Cont::value_type value_type;
    typedef FrameBorderIterBase<Cont, Iter, Pred> this_type;

    explicit            FrameBorderIterBase( container_type& rCont );
    bool         Is() const { return maIt != maEnd; }
    this_type&          operator++();
    value_type   operator*() const { return *maIt; }

private:
    iterator_type       maIt;
    iterator_type       maEnd;
    Pred                maPred;
};

/** Iterator for constant svx::FrameBorder containers, iterates over all borders. */
typedef FrameBorderIterBase< const FrameBorderPtrVec, FrameBorderPtrVec::const_iterator, FrameBorderDummy_Pred >
    FrameBorderCIter;

/** Iterator for mutable svx::FrameBorder containers, iterates over all borders. */
typedef FrameBorderIterBase< FrameBorderPtrVec, FrameBorderPtrVec::iterator, FrameBorderDummy_Pred >
    FrameBorderIter;

/** Iterator for constant svx::FrameBorder containers, iterates over visible borders. */
typedef FrameBorderIterBase< const FrameBorderPtrVec, FrameBorderPtrVec::const_iterator, FrameBorderVisible_Pred >
    VisFrameBorderCIter;

/** Iterator for mutable svx::FrameBorder containers, iterates over visible borders. */
typedef FrameBorderIterBase< FrameBorderPtrVec, FrameBorderPtrVec::iterator, FrameBorderVisible_Pred >
    VisFrameBorderIter;

/** Iterator for constant svx::FrameBorder containers, iterates over selected borders. */
typedef FrameBorderIterBase< const FrameBorderPtrVec, FrameBorderPtrVec::const_iterator, FrameBorderSelected_Pred >
    SelFrameBorderCIter;

/** Iterator for mutable svx::FrameBorder containers, iterates over selected borders. */
typedef FrameBorderIterBase< FrameBorderPtrVec, FrameBorderPtrVec::iterator, FrameBorderSelected_Pred >
    SelFrameBorderIter;

}

#endif

/* vim:set shiftwidth=4 softtabstop=4 expandtab: */