xref: /aoo42x/main/sc/source/ui/inc/fieldwnd.hxx (revision 6b6a7a13)
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 SC_FIELDWND_HXX
25 #define SC_FIELDWND_HXX
26 
27 #include <utility>
28 #include <vector>
29 #include <boost/shared_ptr.hpp>
30 #include <cppuhelper/weakref.hxx>
31 #include <rtl/ref.hxx>
32 #include <vcl/ctrl.hxx>
33 #include <vcl/fixed.hxx>
34 
35 #include "address.hxx"
36 #include "pivot.hxx"
37 
38 // ============================================================================
39 
40 class ScPivotLayoutDlg;
41 class ScAccessibleDataPilotControl;
42 
43 const size_t PIVOTFIELD_INVALID = static_cast< size_t >( -1 );
44 
45 // ============================================================================
46 
47 /** Type of the pivot table field window. */
48 enum ScPivotFieldType
49 {
50     PIVOTFIELDTYPE_PAGE,            /// Window for all page fields.
51     PIVOTFIELDTYPE_COL,             /// Window for all column fields.
52     PIVOTFIELDTYPE_ROW,             /// Window for all row fields.
53     PIVOTFIELDTYPE_DATA,            /// Window for all data fields.
54     PIVOTFIELDTYPE_SELECT           /// Selection window with all fields.
55 };
56 
57 /** Type of an end tracking event. */
58 enum ScPivotFieldEndTracking
59 {
60     ENDTRACKING_SUSPEND,            /// Stop tracking in this window, but tracking still active (in another window).
61     ENDTRACKING_CANCEL,             /// Tracking has been cancelled.
62     ENDTRACKING_DROP                /// Tracking has ended, a field has been dropped.
63 };
64 
65 // ============================================================================
66 
67 typedef ::std::pair< const ScPivotFuncData*, size_t > ScPivotFuncDataEntry;
68 
69 // ============================================================================
70 
71 /** Represents a field area in the pivot table layout dialog. */
72 class ScPivotFieldWindow : public Control
73 {
74 public:
75                         ScPivotFieldWindow(
76                             ScPivotLayoutDlg* pDialog,
77                             const ResId& rResId,
78                             ScrollBar& rScrollBar,
79                             FixedText* pFtCaption,
80                             const ::rtl::OUString& rName,
81                             ScPivotFieldType eFieldType,
82                             const sal_Char* pcHelpId,
83                             PointerStyle eDropPointer,
84                             size_t nColCount,
85                             size_t nRowCount,
86                             long nFieldWidthFactor,
87                             long nSpaceSize );
88 
89     virtual             ~ScPivotFieldWindow();
90 
91     /** Initializes this field window from the passed label data (used for selection window). */
92     void                ReadDataLabels( const ScDPLabelDataVector& rLabels );
93     /** Initializes this field window from the passed field data (used for row/col/page/data window). */
94     void                ReadPivotFields( const ScPivotFieldVector& rPivotFields );
95 
96     /** Fills the passed vector with the plain names of all fields from this field window. */
97     void                WriteFieldNames( ScDPNameVec& rFieldNames ) const;
98     /** Fills the passed pivot field vector with the fields of this field window. */
99     void                WritePivotFields( ScPivotFieldVector& rPivotFields ) const;
100 
101     /** Returns the type of this field window. */
GetType() const102     inline ScPivotFieldType GetType() const { return meFieldType; }
103     /** Returns the mouse pointer style for tracking over this window. */
GetDropPointerStyle() const104     inline PointerStyle GetDropPointerStyle() const { return meDropPointer; }
105     /** Returns the name of the control without shortcut. */
GetName() const106     inline ::rtl::OUString GetName() const { return maName; }
107     /** Returns the description of the control which is used for the accessibility objects. */
108     ::rtl::OUString     GetDescription() const;
109 
110     /** Returns true, if the window is empty. */
IsEmpty() const111     inline bool         IsEmpty() const { return maFields.empty(); }
112     /** Returns the number of existing fields. */
GetFieldCount() const113     inline size_t       GetFieldCount() const { return maFields.size(); }
114     /** Returns the text of an existing field. */
115     ::rtl::OUString     GetFieldText( size_t nFieldIndex ) const;
116 
117     /** Returns the index of a field with the specified column identifier. */
118     ScPivotFuncDataEntry FindFuncDataByCol( SCCOL nCol ) const;
119 
120     /** Returns the pixel size of a field. */
GetFieldSize() const121     inline const Size&  GetFieldSize() const { return maFieldSize; }
122     /** Returns the pixel position of a field (without bound check). */
123     Point               GetFieldPosition( size_t nFieldIndex ) const;
124     /** Calculates the field index at a specific pixel position. */
125     size_t              GetFieldIndex( const Point& rWindowPos ) const;
126     /** Calculates the field insertion index for mouse drop at a specific pixel position. */
127     size_t              GetDropIndex( const Point& rWindowPos ) const;
128 
129     /** Returns the index of the selected field. */
GetSelectedIndex() const130     inline size_t       GetSelectedIndex() const { return mnSelectIndex; }
131     /** Grabs focus and sets the passed selection. */
132     void                GrabFocusAndSelect( size_t nIndex );
133     /** Selects the next field. */
134     void                SelectNextField();
135 
136     /** Inserts a new field in front of the specified field. */
137     void                InsertField( size_t nInsertIndex, const ScPivotFuncData& rFuncData );
138     /** Removes the specified field. */
139     bool                RemoveField( size_t nRemoveIndex );
140     /** Moves the specified field to a new position. */
141     bool                MoveField( size_t nFieldIndex, size_t nInsertIndex );
142 
143     /** Returns the selected field (pointer is valid as long as field vector is not changed). */
144     const ScPivotFuncData* GetSelectedFuncData() const;
145     /** Removes the selected field. */
146     void                ModifySelectedField( const ScPivotFuncData& rFuncData );
147     /** Removes the selected field. */
148     bool                RemoveSelectedField();
149     /** Moves the selected field in front of the specified field. */
150     bool                MoveSelectedField( size_t nInsertIndex );
151 
152     /** Called from dialog when tracking starts in this field window. */
153     void                NotifyStartTracking();
154     /** Called from dialog while tracking in this field window. */
155     void                NotifyTracking( const Point& rWindowPos );
156     /** Called from dialog when tracking ends in this field window. */
157     void                NotifyEndTracking( ScPivotFieldEndTracking eEndType );
158 
159 protected:
160     virtual void        Paint( const Rectangle& rRect );
161     virtual void        StateChanged( StateChangedType nStateChange );
162     virtual void        DataChanged( const DataChangedEvent& rDCEvt );
163     virtual void        KeyInput( const KeyEvent& rKEvt );
164     virtual void        MouseButtonDown( const MouseEvent& rMEvt );
165     virtual void        RequestHelp( const HelpEvent& rHEvt );
166     virtual void        GetFocus();
167     virtual void        LoseFocus();
168     virtual ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible >
169                         CreateAccessible();
170 
171 private:
172     /** A structure containing all data needed for a field in this window. */
173     struct ScPivotWindowField
174     {
175         ScPivotFuncData     maFuncData;         /// Field data from source pivot table.
176         ::rtl::OUString     maFieldName;        /// Name displayed on the field button.
177         bool                mbClipped;          /// True = field text does not fit into button.
178         explicit            ScPivotWindowField( const ScDPLabelData& rLabelData );
179         explicit            ScPivotWindowField( ScPivotLayoutDlg& rDialog, const ScPivotField& rField, bool bDataWindow );
180         explicit            ScPivotWindowField( ScPivotLayoutDlg& rDialog, const ScPivotFuncData& rFuncData, bool bDataWindow );
181         void                InitFieldName( ScPivotLayoutDlg& rDialog, bool bDataWindow );
182     };
183 
184     /** Specifies how the selection cursor can move in the window. */
185     enum MoveType { PREV_FIELD, NEXT_FIELD, PREV_LINE, NEXT_LINE, PREV_PAGE, NEXT_PAGE, FIRST_FIELD, LAST_FIELD };
186 
187     /** Calculates a scroll position to make the passed field visible. Tries to
188         stick to current scroll position if possible. */
189     size_t              RecalcVisibleIndex( size_t nSelectIndex ) const;
190 
191     /** Sets selection to the specified field and changes scrolling position. */
192     void                SetSelectionUnchecked( size_t nSelectIndex, size_t nFirstVisIndex );
193     /** Selects a field and adjusts scrolling position to make the field visible. */
194     void                MoveSelection( size_t nSelectIndex );
195     /** Sets selection to a new position relative to current. */
196     void                MoveSelection( MoveType eMoveType );
197     /** Moves the selected field to a new position relative to current. */
198     void                MoveSelectedField( MoveType eMoveType );
199 
200     /** Inserts the passed field into the vector and notifies accessibility object. */
201     void                InsertFieldUnchecked( size_t nInsertIndex, const ScPivotWindowField& rField );
202     /** Removes the specified field from the vector and notifies accessibility object. */
203     void                RemoveFieldUnchecked( size_t nRemoveIndex );
204 
205     /** Draws the background. */
206     void                DrawBackground( OutputDevice& rDev );
207     /** Draws the specified field. */
208     void                DrawField( OutputDevice& rDev, size_t nFieldIndex );
209     /** Draws the insertion cursor. */
210     void                DrawInsertionCursor( OutputDevice& rDev );
211 
212     /** Returns a reference to the accessibility object, if still alive. */
213     ::rtl::Reference< ScAccessibleDataPilotControl > GetAccessibleControl();
214 
215 	DECL_LINK( ScrollHdl, ScrollBar* );
216 
217 private:
218     typedef ::std::vector< ScPivotWindowField > ScPivotWindowFieldVector;
219 
220     ScPivotLayoutDlg*   mpDialog;           /// Parent pivot table dialog.
221     ::com::sun::star::uno::WeakReference< ::com::sun::star::accessibility::XAccessible >
222                         mxAccessible;       /// Weak reference to the accessible object.
223     ScAccessibleDataPilotControl*
224                         mpAccessible;       /// Pointer to the accessible implementation.
225     ScrollBar&          mrScrollBar;        /// Scrollbar of the select window.
226     FixedText*          mpFtCaption;        /// Associated fixedtext control with caption text and mnemonic.
227     ::rtl::OUString     maName;             /// Name of the control, used for accessibility.
228     ScPivotWindowFieldVector maFields;      /// Vector with all fields contained in this window.
229     Size                maFieldSize;        /// Size of a single field in pixels.
230     Size                maSpaceSize;        /// Size between fields in pixels.
231     ScPivotFieldType    meFieldType;        /// Type of this field window.
232     PointerStyle        meDropPointer;      /// Mouse pointer style for tracking over this window.
233     size_t              mnColCount;         /// Number of field columns.
234     size_t              mnRowCount;         /// Number of field rows.
235     size_t              mnLineSize;         /// Number of fields per line (depending on scrolling orientation).
236     size_t              mnPageSize;         /// Number of visible fields.
237     size_t              mnFirstVisIndex;    /// Index of first visible field (scrolling offset).
238     size_t              mnSelectIndex;      /// Currently selected field.
239     size_t              mnInsCursorIndex;   /// Position of the insertion cursor.
240     size_t              mnOldFirstVisIndex; /// Stores original scroll position during auto scrolling.
241     size_t              mnAutoScrollDelay;  /// Initial counter before auto scrolling starts on tracking.
242     bool                mbVertical;         /// True = sort fields vertically.
243     bool                mbIsTrackingSource; /// True = this field window is the source while tracking.
244 };
245 
246 // ============================================================================
247 
248 #endif
249