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 SC_FIELDWND_HXX
21 #define SC_FIELDWND_HXX
25 #include <vcl/ctrl.hxx>
26 #include <vcl/fixed.hxx>
27 #include <vcl/scrbar.hxx>
29 #include "address.hxx"
33 class ScPivotLayoutDlg
;
34 class ScAccessibleDataPilotControl
;
36 extern const size_t PIVOTFIELD_INVALID
;
38 /** Type of the pivot table field window. */
41 PIVOTFIELDTYPE_PAGE
= 0, /// Window for all page fields.
42 PIVOTFIELDTYPE_COL
, /// Window for all column fields.
43 PIVOTFIELDTYPE_ROW
, /// Window for all row fields.
44 PIVOTFIELDTYPE_DATA
, /// Window for all data fields.
45 PIVOTFIELDTYPE_SELECT
, /// Selection window with all fields.
46 PIVOTFIELDTYPE_UNKNOWN
50 * Represents a field area in the DataPilot layout dialog. This base class
51 * handles storage of field names and the accessibility object.
53 class ScDPFieldControlBase
: public Control
61 FieldName(const OUString
& rText
, bool bFits
, sal_uInt8 nDupCount
= 0);
62 FieldName(const FieldName
& r
);
64 OUString
getDisplayedText() const;
66 typedef ::std::vector
<FieldName
> FieldNames
;
69 typedef boost::ptr_vector
<ScPivotFuncData
> FuncDataType
;
74 sal_uInt16 mnFuncMask
;
78 * Custom scroll bar to pass the command event to its parent window.
79 * We need this to pass the mouse wheel events to its parent field
80 * control to have mouse wheel events appaer to be properly handled by the
83 class ScrollBar
: public ::ScrollBar
86 ScrollBar(Window
* pParent
, WinBits nStyle
);
87 virtual void Command( const CommandEvent
& rCEvt
);
93 ScPivotLayoutDlg
* pParent
, const ResId
& rResId
, FixedText
* pCaption
, const char* pcHelpId
);
94 virtual ~ScDPFieldControlBase();
96 virtual void CalcSize() = 0;
98 virtual bool IsValidIndex( size_t nIndex
) const = 0;
99 /** @return The pixel position of a field (without bound check). */
100 virtual Point
GetFieldPosition( size_t nIndex
) = 0;
101 /** Calculates the field index at a specific pixel position. */
102 virtual size_t GetFieldIndex( const Point
& rPos
) = 0;
103 /** @return The pixel size of a field. */
104 virtual Size
GetFieldSize() const = 0;
106 /** @return The description of the control which is used for the accessibility objects. */
107 virtual OUString
GetDescription() const = 0;
108 /** @return The type of the FieldWindow. */
109 virtual ScPivotFieldType
GetFieldType() const = 0;
110 virtual void ScrollToShowSelection() = 0;
111 virtual void ScrollToEnd() = 0;
112 virtual void ResetScrollBar() = 0;
113 virtual void HandleWheelScroll(long nNotch
) = 0;
115 /** @return The name of the control without shortcut. */
116 OUString
GetName() const;
117 void SetName(const OUString
& rName
);
119 /** @return TRUE, if the field with the given index exists. */
120 bool IsExistingIndex( size_t nIndex
) const;
122 void AppendField( const OUString
& rText
, const ScPivotFuncData
& rFunc
);
125 * Inserts a field using the specified pixel position.
127 * @param rPos The coordinates to insert the field.
129 size_t AddField(const OUString
& rText
, const Point
& rPos
, const ScPivotFuncData
& rFunc
);
131 bool MoveField(size_t nCurPos
, const Point
& rPos
, size_t& rnIndex
);
133 /** Remove a field by specified index. */
134 void DeleteFieldByIndex( size_t nIndex
);
136 /** Returns the number of existing fields. */
137 size_t GetFieldCount() const;
139 bool IsEmpty() const;
141 /** Removes all fields. */
143 /** Changes the text on an existing field. */
144 void SetFieldText(const OUString
& rText
, size_t nIndex
, sal_uInt8 nDupCount
);
145 /** Returns the text of an existing field. */
146 OUString
GetFieldText( size_t nIndex
) const;
148 /** Calculates a field index at a specific pixel position. Returns in every
149 case the index of an existing field.
150 @param rnIndex The index of the field is returned here.
151 @return TRUE, if the index value is valid. */
152 void GetExistingIndex( const Point
& rPos
, size_t& rnIndex
);
154 size_t GetSelectedField() const;
156 /** Selects the next field. Called i.e. after moving a field from SELECT area. */
158 /** Grabs focus and sets new selection. */
159 void GrabFocusAndSelect( size_t nIndex
);
161 const ScPivotFuncData
& GetFuncData(size_t nIndex
) const;
162 ScPivotFuncData
& GetFuncData(size_t nIndex
);
164 void GetAllFuncItems(std::vector
<FuncItem
>& rItems
) const;
166 sal_uInt8
GetNextDupCount(const ScPivotFuncData
& rData
, size_t nSelfIndex
) const;
168 void ConvertToPivotArray(std::vector
<ScPivotField
>& rFields
) const;
170 size_t GetFieldIndexByData( const ScPivotFuncData
& rData
) const;
172 virtual void Paint( const Rectangle
& rRect
);
175 virtual void StateChanged( StateChangedType nStateChange
);
176 virtual void DataChanged( const DataChangedEvent
& rDCEvt
);
177 virtual void KeyInput( const KeyEvent
& rKEvt
);
178 virtual void Command( const CommandEvent
& rCEvt
);
179 virtual void MouseButtonDown( const MouseEvent
& rMEvt
);
180 virtual void MouseButtonUp( const MouseEvent
& rMEvt
);
181 virtual void MouseMove( const MouseEvent
& rMEvt
);
182 virtual void GetFocus();
183 virtual void LoseFocus();
186 FieldNames
& GetFieldNames();
187 const FieldNames
& GetFieldNames() const;
189 virtual ::com::sun::star::uno::Reference
<
190 ::com::sun::star::accessibility::XAccessible
> CreateAccessible();
192 void FieldFocusChanged(size_t nOldSelected
, size_t nFieldSelected
);
194 /** Updates the tab stop style bits. */
197 /** Draw background color for the whole control area. */
198 void DrawBackground( OutputDevice
& rDev
);
200 /** Draw a single field button. */
201 void DrawField( OutputDevice
& rDev
, const Rectangle
& rRect
,
202 FieldName
& rText
, bool bFocus
);
204 void AppendPaintable(Window
* p
);
205 void DrawPaintables();
206 void DrawInvertSelection();
207 Size
GetStdFieldBtnSize() const;
209 /** @return The new selection index after moving to the given direction. */
210 virtual size_t CalcNewFieldIndex( SCsCOL nDX
, SCsROW nDY
) const = 0;
213 * @param nIndex logical index of a field name, independent of scroll
215 * @return Display position of the button. The first displayed button is
216 * always 0 no matter what the current scroll offset is. In case
217 * the field specified by the index is outside the visible range,
218 * <code>INVALID_INDEX</code> is returned.
220 virtual size_t GetDisplayPosition(size_t nIndex
) const = 0;
222 /** Draws the complete control. */
223 virtual void Redraw() = 0;
226 /** Moves the selected field to nDestIndex. */
227 void MoveField( size_t nDestIndex
);
228 /** Moves the selected field to the given direction. */
229 void MoveFieldRel( SCsCOL nDX
, SCsROW nDY
);
231 /** Selects a field and adjusts scrolling position to make the field visible. */
232 void MoveSelection( size_t nSelectedIndex
);
233 /** Selects a field at a new position relative to the current. */
234 void MoveSelection( SCsCOL nDX
, SCsROW nDY
);
236 sal_uInt8
GetNextDupCount(const OUString
& rFieldText
) const;
239 typedef ::std::vector
<Window
*> Paintables
;
240 Paintables maPaintables
;
242 FuncDataType maFuncData
;
243 FieldNames maFieldNames
; /// String array of the field names and flags, if text fits into button.
244 ScPivotLayoutDlg
* mpDlg
;
245 FixedText
* mpCaption
; /// FixedText containing the name of the control.
248 size_t mnFieldSelected
; /// Currently selected field.
250 // Hold a helpful reference while we work with our weakref.
253 com::sun::star::uno::Reference
< ::com::sun::star::accessibility::XAccessible
> mxRef
;
255 AccessRef( const com::sun::star::uno::WeakReference
< ::com::sun::star::accessibility::XAccessible
> & rAccessible
);
256 ScAccessibleDataPilotControl
*operator -> () const;
257 bool is() { return mxRef
.is(); }
260 com::sun::star::uno::WeakReference
< ::com::sun::star::accessibility::XAccessible
> mxAccessible
;
263 // ============================================================================
266 * Base class for field control with a horizontal scroll bar at the bottom.
267 * Page, column, data and select fields are derived from this class.
269 class ScDPHorFieldControl
: public ScDPFieldControlBase
272 virtual size_t CalcNewFieldIndex(SCsCOL nDX
, SCsROW nDY
) const;
273 virtual size_t GetDisplayPosition(size_t nIndex
) const;
274 virtual void Redraw();
278 ScPivotLayoutDlg
* pDialog
, const ResId
& rResId
, FixedText
* pCaption
, const char* pcHelpId
);
280 virtual ~ScDPHorFieldControl();
282 virtual void CalcSize();
283 virtual bool IsValidIndex( size_t nIndex
) const;
284 virtual Point
GetFieldPosition(size_t nIndex
);
285 virtual Size
GetFieldSize() const;
286 virtual size_t GetFieldIndex( const Point
& rPos
);
287 virtual OUString
GetDescription() const;
289 virtual void ScrollToEnd();
290 virtual void ScrollToShowSelection();
291 virtual void ResetScrollBar();
292 virtual void HandleWheelScroll(long nNotch
);
295 bool GetFieldBtnPosSize(size_t nPos
, Point
& rPos
, Size
& rSize
);
298 DECL_LINK(ScrollHdl
, void*);
299 DECL_LINK(EndScrollHdl
, void*);
305 size_t mnFieldBtnRowCount
;
306 size_t mnFieldBtnColCount
;
309 // ============================================================================
311 class ScDPPageFieldControl
: public ScDPHorFieldControl
314 ScDPPageFieldControl(
315 ScPivotLayoutDlg
* pDialog
, const ResId
& rResId
, FixedText
* pCaption
, const char* pcHelpId
);
316 virtual ~ScDPPageFieldControl();
318 virtual ScPivotFieldType
GetFieldType() const;
319 virtual OUString
GetDescription() const;
322 // ============================================================================
324 class ScDPColFieldControl
: public ScDPHorFieldControl
328 ScPivotLayoutDlg
* pDialog
, const ResId
& rResId
, FixedText
* pCaption
, const char* pcHelpId
);
329 virtual ~ScDPColFieldControl();
331 virtual ScPivotFieldType
GetFieldType() const;
332 virtual OUString
GetDescription() const;
335 // ============================================================================
338 * Row field control with a vertical scroll bar.
340 class ScDPRowFieldControl
: public ScDPFieldControlBase
344 ScPivotLayoutDlg
* pDialog
, const ResId
& rResId
, FixedText
* pCaption
, const char* pcHelpId
);
346 virtual ~ScDPRowFieldControl();
348 virtual void CalcSize();
349 virtual bool IsValidIndex( size_t nIndex
) const;
350 virtual Point
GetFieldPosition( size_t nIndex
);
351 virtual Size
GetFieldSize() const;
352 virtual size_t GetFieldIndex( const Point
& rPos
);
353 virtual OUString
GetDescription() const;
354 virtual ScPivotFieldType
GetFieldType() const;
356 virtual void ScrollToEnd();
357 virtual void ScrollToShowSelection();
358 virtual void ResetScrollBar();
359 virtual void HandleWheelScroll(long nNotch
);
362 virtual size_t CalcNewFieldIndex( SCsCOL nDX
, SCsROW nDY
) const;
363 virtual size_t GetDisplayPosition(size_t nIndex
) const;
364 virtual void Redraw();
367 bool GetFieldBtnPosSize(size_t nPos
, Point
& rPos
, Size
& rSize
);
370 DECL_LINK(ScrollHdl
, void*);
371 DECL_LINK(EndScrollHdl
, void*);
375 ScDPFieldControlBase::ScrollBar maScroll
;
376 size_t mnColumnBtnCount
;
379 // ============================================================================
381 class ScDPSelectFieldControl
: public ScDPHorFieldControl
384 ScDPSelectFieldControl(
385 ScPivotLayoutDlg
* pDialog
, const ResId
& rResId
, FixedText
* pCaption
, const char* pcHelpId
);
386 virtual ~ScDPSelectFieldControl();
388 virtual ScPivotFieldType
GetFieldType() const;
389 virtual OUString
GetDescription() const;
392 // ============================================================================
394 class ScDPDataFieldControl
: public ScDPHorFieldControl
397 ScDPDataFieldControl(
398 ScPivotLayoutDlg
* pParent
, const ResId
& rResId
, FixedText
* pCaption
, const char* pcHelpId
);
399 virtual ~ScDPDataFieldControl();
401 virtual ScPivotFieldType
GetFieldType() const;
402 virtual Size
GetFieldSize() const;
403 virtual OUString
GetDescription() const;
408 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */