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