1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: fieldwnd.hxx,v $
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 SC_FIELDWND_HXX
32 #define SC_FIELDWND_HXX
35 #include "address.hxx"
36 #include <vcl/ctrl.hxx>
37 #include <vcl/fixed.hxx>
38 #include <cppuhelper/weakref.hxx>
40 #define MAX_LABELS 256
41 #define PAGE_SIZE 16 // count of visible fields for scrollbar
42 #define LINE_SIZE 8 // count of fields per column for scrollbar
43 #define MAX_FIELDS 8 // maximum count of fields for row/col/data area
44 #define MAX_PAGEFIELDS 10 // maximum count of fields for page area
46 #define OWIDTH PivotGlobal::nObjWidth
47 #define OHEIGHT PivotGlobal::nObjHeight
48 #define SSPACE PivotGlobal::nSelSpace
51 class ScAccessibleDataPilotControl
;
53 //===================================================================
55 /** Type of content area. */
58 TYPE_PAGE
, /// Area for all page fields.
59 TYPE_ROW
, /// Area for all row fields.
60 TYPE_COL
, /// Area for all column fields.
61 TYPE_DATA
, /// Area for all data fields.
62 TYPE_SELECT
/// Selection area with all fields.
65 //-------------------------------------------------------------------
67 /** Represents a field area in the DataPilot layout dialog. */
68 class ScDPFieldWindow
: public Control
71 typedef ::std::pair
< String
, bool > FieldString
; // true = text fits into button
73 String aName
; /// name of the control, used in Accessibility
74 ScDPLayoutDlg
* pDlg
; /// Parent dialog.
75 Rectangle aWndRect
; /// Area rectangle in pixels.
76 FixedText
* pFtCaption
; /// FixedText containing the name of the control.
77 Point aTextPos
; /// Position of the caption text.
78 std::vector
< FieldString
> aFieldArr
; /// String array of the field names and flags, if text fits into button.
79 ScDPFieldType eType
; /// Type of this area.
80 Color aFaceColor
; /// Color for dialog background.
81 Color aWinColor
; /// Color for window background.
82 Color aTextColor
; /// Color for text in buttons.
83 Color aWinTextColor
; /// Color for text in field windows.
84 size_t nFieldSize
; /// Maximum count of fields.
85 size_t nFieldSelected
; /// Currently selected field.
87 com::sun::star::uno::WeakReference
< ::com::sun::star::accessibility::XAccessible
> xAccessible
;
88 ScAccessibleDataPilotControl
* pAccessible
;
90 /** Initilize the object. */
93 /** Reads all needed style settings. */
94 void GetStyleSettings();
96 /** Draws the background. */
97 void DrawBackground( OutputDevice
& rDev
);
98 /** Draws a field into the specified rectangle. */
101 const Rectangle
& rRect
,
105 /** @return TRUE, if the field index is inside of the control area. */
106 bool IsValidIndex( size_t nIndex
) const;
107 /** @return TRUE, if the field with the given index exists. */
108 bool IsExistingIndex( size_t nIndex
) const;
109 /** @return TRUE, if the field with the given index exists and the text is
110 too long for the button control. */
111 bool IsShortenedText( size_t nIndex
) const;
112 /** @return The new selection index after moving to the given direction. */
113 size_t CalcNewFieldIndex( SCsCOL nDX
, SCsROW nDY
) const;
115 /** Sets selection to the field with index nIndex. */
116 void SetSelection( size_t nIndex
);
117 /** Sets selection to first field. */
118 void SetSelectionHome();
119 /** Sets selection to last field. */
120 void SetSelectionEnd();
121 /** Sets selection to new position relative to current. */
122 void MoveSelection( USHORT nKeyCode
, SCsCOL nDX
, SCsROW nDY
);
124 /** Moves the selected field to nDestIndex. */
125 void MoveField( size_t nDestIndex
);
126 /** Moves the selected field to the given direction. */
127 void MoveFieldRel( SCsCOL nDX
, SCsROW nDY
);
129 /** Updates the tab stop style bits. */
133 virtual void Paint( const Rectangle
& rRect
);
134 virtual void DataChanged( const DataChangedEvent
& rDCEvt
);
135 virtual void MouseButtonDown( const MouseEvent
& rMEvt
);
136 virtual void MouseButtonUp( const MouseEvent
& rMEvt
);
137 virtual void MouseMove( const MouseEvent
& rMEvt
);
138 virtual void KeyInput( const KeyEvent
& rKEvt
);
139 virtual void GetFocus();
140 virtual void LoseFocus();
141 virtual ::com::sun::star::uno::Reference
< ::com::sun::star::accessibility::XAccessible
> CreateAccessible();
145 ScDPLayoutDlg
* pDialog
,
147 ScDPFieldType eFieldType
,
148 FixedText
* pFtFieldCaption
);
150 ScDPLayoutDlg
* pDialog
,
152 ScDPFieldType eFieldType
,
153 const String
& aName
);
154 virtual ~ScDPFieldWindow();
156 /** Reads the FixedText's text with mnemonic and hides the FixedText. */
159 /** Draws the complete control. */
162 /** @return The pixel position of a field (without bound check). */
163 Point
GetFieldPosition( size_t nIndex
) const;
164 /** @return The pixel size of a field. */
165 Size
GetFieldSize() const;
167 /** @return The index of the selected field. */
168 inline bool IsEmpty() const { return aFieldArr
.empty(); }
169 /** @return The index of the selected field. */
170 inline size_t GetSelectedField() const { return nFieldSelected
; }
171 /** @return The pixel position of the last possible field. */
172 Point
GetLastPosition() const;
174 /** @return The count of existing fields. */
175 inline size_t GetFieldCount() const { return aFieldArr
.size(); }
176 /** Inserts a field to the specified index. */
177 void AddField( const String
& rText
, size_t nNewIndex
);
178 /** Removes a field from the specified index. */
179 void DelField( size_t nDelIndex
);
180 /** Removes all fields. */
182 /** Changes the text on an existing field. */
183 void SetFieldText( const String
& rText
, size_t nIndex
);
184 /** Returns the text of an existing field. */
185 const String
& GetFieldText( size_t nIndex
) const;
187 /** Inserts a field using the specified pixel position.
188 @param rPos The coordinates to insert the field.
189 @param rnIndex The new index of the field is returned here.
190 @return TRUE, if the field has been created. */
191 bool AddField( const String
& rText
, const Point
& rPos
, size_t& rnIndex
);
192 /** Calculates the field index at a specific pixel position.
193 @param rnIndex The index of the field is returned here.
194 @return TRUE, if the index value is valid. */
195 bool GetFieldIndex( const Point
& rPos
, size_t& rnIndex
) const;
196 /** Calculates a field index at a specific pixel position. Returns in every
197 case the index of an existing field.
198 @param rnIndex The index of the field is returned here.
199 @return TRUE, if the index value is valid. */
200 void GetExistingIndex( const Point
& rPos
, size_t& rnIndex
);
202 /** Notifies this control that the offset of the first field has been changed.
203 The control has to adjust the selection to keep the same field selected
204 on scrolling with scrollbar. */
205 void ModifySelectionOffset( long nOffsetDiff
);
206 /** Selects the next field. Called i.e. after moving a field from SELECT area. */
209 /** @return The name of the control without shortcut. */
210 inline String
GetName() const { return aName
; }
212 /** @return The description of the control which is used for the accessibility objects. */
213 String
GetDescription() const;
215 /** Grabs focus and sets new selection. */
216 void GrabFocusWithSel( size_t nIndex
);
218 /** @return The type of the FieldWindow. */
219 inline ScDPFieldType
GetType() const { return eType
; }
222 //===================================================================
224 #endif // SC_FIELDWND_HXX