diff options
Diffstat (limited to 'sc/source/ui/inc/fieldwnd.hxx')
-rw-r--r-- | sc/source/ui/inc/fieldwnd.hxx | 368 |
1 files changed, 200 insertions, 168 deletions
diff --git a/sc/source/ui/inc/fieldwnd.hxx b/sc/source/ui/inc/fieldwnd.hxx index 5c74777edf47..65dd07d19e8a 100644 --- a/sc/source/ui/inc/fieldwnd.hxx +++ b/sc/source/ui/inc/fieldwnd.hxx @@ -28,193 +28,225 @@ #ifndef SC_FIELDWND_HXX #define SC_FIELDWND_HXX +#include <utility> #include <vector> -#include "address.hxx" +#include <boost/shared_ptr.hpp> +#include <cppuhelper/weakref.hxx> +#include <rtl/ref.hxx> #include <vcl/ctrl.hxx> #include <vcl/fixed.hxx> -#include <cppuhelper/weakref.hxx> -#define PAGE_SIZE 16 // count of visible fields for scrollbar -#define LINE_SIZE 8 // count of fields per column for scrollbar -#define MAX_FIELDS 8 // maximum count of fields for row/col/data area -#define MAX_PAGEFIELDS 10 // maximum count of fields for page area +#include "address.hxx" +#include "pivot.hxx" -#define OWIDTH PivotGlobal::nObjWidth -#define OHEIGHT PivotGlobal::nObjHeight -#define SSPACE PivotGlobal::nSelSpace +// ============================================================================ -class ScDPLayoutDlg; +class ScPivotLayoutDlg; class ScAccessibleDataPilotControl; -//=================================================================== +const size_t PIVOTFIELD_INVALID = static_cast< size_t >( -1 ); + +// ============================================================================ -/** Type of content area. */ -enum ScDPFieldType +/** Type of the pivot table field window. */ +enum ScPivotFieldType { - TYPE_PAGE, /// Area for all page fields. - TYPE_ROW, /// Area for all row fields. - TYPE_COL, /// Area for all column fields. - TYPE_DATA, /// Area for all data fields. - TYPE_SELECT /// Selection area with all fields. + PIVOTFIELDTYPE_PAGE, /// Window for all page fields. + PIVOTFIELDTYPE_COL, /// Window for all column fields. + PIVOTFIELDTYPE_ROW, /// Window for all row fields. + PIVOTFIELDTYPE_DATA, /// Window for all data fields. + PIVOTFIELDTYPE_SELECT /// Selection window with all fields. }; -//------------------------------------------------------------------- +/** Type of an end tracking event. */ +enum ScPivotFieldEndTracking +{ + ENDTRACKING_SUSPEND, /// Stop tracking in this window, but tracking still active (in another window). + ENDTRACKING_CANCEL, /// Tracking has been cancelled. + ENDTRACKING_DROP /// Tracking has ended, a field has been dropped. +}; + +// ============================================================================ + +typedef ::std::pair< const ScPivotFuncData*, size_t > ScPivotFuncDataEntry; + +// ============================================================================ -/** Represents a field area in the DataPilot layout dialog. */ -class ScDPFieldWindow : public Control +/** Represents a field area in the pivot table layout dialog. */ +class ScPivotFieldWindow : public Control { +public: + ScPivotFieldWindow( + ScPivotLayoutDlg* pDialog, + const ResId& rResId, + ScrollBar& rScrollBar, + FixedText* pFtCaption, + const ::rtl::OUString& rName, + ScPivotFieldType eFieldType, + const sal_Char* pcHelpId, + PointerStyle eDropPointer, + size_t nColCount, + size_t nRowCount, + long nFieldWidthFactor, + long nSpaceSize ); + + virtual ~ScPivotFieldWindow(); + + /** Initializes this field window from the passed label data (used for selection window). */ + void ReadDataLabels( const ScDPLabelDataVector& rLabels ); + /** Initializes this field window from the passed field data (used for row/col/page/data window). */ + void ReadPivotFields( const ScPivotFieldVector& rPivotFields ); + + /** Fills the passed vector with the plain names of all fields from this field window. */ + void WriteFieldNames( ScDPNameVec& rFieldNames ) const; + /** Fills the passed pivot field vector with the fields of this field window. */ + void WritePivotFields( ScPivotFieldVector& rPivotFields ) const; + + /** Returns the type of this field window. */ + inline ScPivotFieldType GetType() const { return meFieldType; } + /** Returns the mouse pointer style for tracking over this window. */ + inline PointerStyle GetDropPointerStyle() const { return meDropPointer; } + /** Returns the name of the control without shortcut. */ + inline ::rtl::OUString GetName() const { return maName; } + /** Returns the description of the control which is used for the accessibility objects. */ + ::rtl::OUString GetDescription() const; + + /** Returns true, if the window is empty. */ + inline bool IsEmpty() const { return maFields.empty(); } + /** Returns the number of existing fields. */ + inline size_t GetFieldCount() const { return maFields.size(); } + /** Returns the text of an existing field. */ + ::rtl::OUString GetFieldText( size_t nFieldIndex ) const; + + /** Returns the index of a field with the specified column identifier. */ + ScPivotFuncDataEntry FindFuncDataByCol( SCCOL nCol ) const; + + /** Returns the pixel size of a field. */ + inline const Size& GetFieldSize() const { return maFieldSize; } + /** Returns the pixel position of a field (without bound check). */ + Point GetFieldPosition( size_t nFieldIndex ) const; + /** Calculates the field index at a specific pixel position. */ + size_t GetFieldIndex( const Point& rWindowPos ) const; + /** Calculates the field insertion index for mouse drop at a specific pixel position. */ + size_t GetDropIndex( const Point& rWindowPos ) const; + + /** Returns the index of the selected field. */ + inline size_t GetSelectedIndex() const { return mnSelectIndex; } + /** Grabs focus and sets the passed selection. */ + void GrabFocusAndSelect( size_t nIndex ); + /** Selects the next field. */ + void SelectNextField(); + + /** Inserts a new field in front of the specified field. */ + void InsertField( size_t nInsertIndex, const ScPivotFuncData& rFuncData ); + /** Removes the specified field. */ + bool RemoveField( size_t nRemoveIndex ); + /** Moves the specified field to a new position. */ + bool MoveField( size_t nFieldIndex, size_t nInsertIndex ); + + /** Returns the selected field (pointer is valid as long as field vector is not changed). */ + const ScPivotFuncData* GetSelectedFuncData() const; + /** Removes the selected field. */ + void ModifySelectedField( const ScPivotFuncData& rFuncData ); + /** Removes the selected field. */ + bool RemoveSelectedField(); + /** Moves the selected field in front of the specified field. */ + bool MoveSelectedField( size_t nInsertIndex ); + + /** Called from dialog when tracking starts in this field window. */ + void NotifyStartTracking(); + /** Called from dialog while tracking in this field window. */ + void NotifyTracking( const Point& rWindowPos ); + /** Called from dialog when tracking ends in this field window. */ + void NotifyEndTracking( ScPivotFieldEndTracking eEndType ); + +protected: + virtual void Paint( const Rectangle& rRect ); + virtual void StateChanged( StateChangedType nStateChange ); + virtual void DataChanged( const DataChangedEvent& rDCEvt ); + virtual void KeyInput( const KeyEvent& rKEvt ); + virtual void MouseButtonDown( const MouseEvent& rMEvt ); + virtual void RequestHelp( const HelpEvent& rHEvt ); + virtual void GetFocus(); + virtual void LoseFocus(); + virtual ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible > + CreateAccessible(); + private: - typedef ::std::pair< String, bool > FieldString; // true = text fits into button - - String aName; /// name of the control, used in Accessibility - ScDPLayoutDlg* pDlg; /// Parent dialog. - Rectangle aWndRect; /// Area rectangle in pixels. - FixedText* pFtCaption; /// FixedText containing the name of the control. - Point aTextPos; /// Position of the caption text. - std::vector< FieldString > aFieldArr; /// String array of the field names and flags, if text fits into button. - ScDPFieldType eType; /// Type of this area. - Color aFaceColor; /// Color for dialog background. - Color aWinColor; /// Color for window background. - Color aTextColor; /// Color for text in buttons. - Color aWinTextColor; /// Color for text in field windows. - size_t nFieldSize; /// Maximum count of fields. - size_t nFieldSelected; /// Currently selected field. - - com::sun::star::uno::WeakReference< ::com::sun::star::accessibility::XAccessible > xAccessible; - ScAccessibleDataPilotControl* pAccessible; - - /** Initilize the object. */ - void Init(); - - /** Reads all needed style settings. */ - void GetStyleSettings(); + /** A structure containing all data needed for a field in this window. */ + struct ScPivotWindowField + { + ScPivotFuncData maFuncData; /// Field data from source pivot table. + ::rtl::OUString maFieldName; /// Name displayed on the field button. + bool mbClipped; /// True = field text does not fit into button. + explicit ScPivotWindowField( const ScDPLabelData& rLabelData ); + explicit ScPivotWindowField( ScPivotLayoutDlg& rDialog, const ScPivotField& rField, bool bDataWindow ); + explicit ScPivotWindowField( ScPivotLayoutDlg& rDialog, const ScPivotFuncData& rFuncData, bool bDataWindow ); + void InitFieldName( ScPivotLayoutDlg& rDialog, bool bDataWindow ); + }; + + /** Specifies how the selection cursor can move in the window. */ + enum MoveType { PREV_FIELD, NEXT_FIELD, PREV_LINE, NEXT_LINE, PREV_PAGE, NEXT_PAGE, FIRST_FIELD, LAST_FIELD }; + + /** Calculates a scroll position to make the passed field visible. Tries to + stick to current scroll position if possible. */ + size_t RecalcVisibleIndex( size_t nSelectIndex ) const; + + /** Sets selection to the specified field and changes scrolling position. */ + void SetSelectionUnchecked( size_t nSelectIndex, size_t nFirstVisIndex ); + /** Selects a field and adjusts scrolling position to make the field visible. */ + void MoveSelection( size_t nSelectIndex ); + /** Sets selection to a new position relative to current. */ + void MoveSelection( MoveType eMoveType ); + /** Moves the selected field to a new position relative to current. */ + void MoveSelectedField( MoveType eMoveType ); + + /** Inserts the passed field into the vector and notifies accessibility object. */ + void InsertFieldUnchecked( size_t nInsertIndex, const ScPivotWindowField& rField ); + /** Removes the specified field from the vector and notifies accessibility object. */ + void RemoveFieldUnchecked( size_t nRemoveIndex ); /** Draws the background. */ - void DrawBackground( OutputDevice& rDev ); - /** Draws a field into the specified rectangle. */ - void DrawField( - OutputDevice& rDev, - const Rectangle& rRect, - FieldString& rText, - bool bFocus ); - - /** @return sal_True, if the field index is inside of the control area. */ - bool IsValidIndex( size_t nIndex ) const; - /** @return sal_True, if the field with the given index exists. */ - bool IsExistingIndex( size_t nIndex ) const; - /** @return sal_True, if the field with the given index exists and the text is - too long for the button control. */ - bool IsShortenedText( size_t nIndex ) const; - /** @return The new selection index after moving to the given direction. */ - size_t CalcNewFieldIndex( SCsCOL nDX, SCsROW nDY ) const; - - /** Sets selection to the field with index nIndex. */ - void SetSelection( size_t nIndex ); - /** Sets selection to first field. */ - void SetSelectionHome(); - /** Sets selection to last field. */ - void SetSelectionEnd(); - /** Sets selection to new position relative to current. */ - void MoveSelection( sal_uInt16 nKeyCode, SCsCOL nDX, SCsROW nDY ); - - /** Moves the selected field to nDestIndex. */ - void MoveField( size_t nDestIndex ); - /** Moves the selected field to the given direction. */ - void MoveFieldRel( SCsCOL nDX, SCsROW nDY ); - - /** Updates the tab stop style bits. */ - void UpdateStyle(); + void DrawBackground( OutputDevice& rDev ); + /** Draws the specified field. */ + void DrawField( OutputDevice& rDev, size_t nFieldIndex ); + /** Draws the insertion cursor. */ + void DrawInsertionCursor( OutputDevice& rDev ); -protected: - virtual void Paint( const Rectangle& rRect ); - virtual void DataChanged( const DataChangedEvent& rDCEvt ); - virtual void MouseButtonDown( const MouseEvent& rMEvt ); - virtual void MouseButtonUp( const MouseEvent& rMEvt ); - virtual void MouseMove( const MouseEvent& rMEvt ); - virtual void KeyInput( const KeyEvent& rKEvt ); - virtual void GetFocus(); - virtual void LoseFocus(); - virtual ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible > CreateAccessible(); + /** Returns a reference to the accessiblity object, if still alive. */ + ::rtl::Reference< ScAccessibleDataPilotControl > GetAccessibleControl(); -public: - ScDPFieldWindow( - ScDPLayoutDlg* pDialog, - const ResId& rResId, - ScDPFieldType eFieldType, - FixedText* pFtFieldCaption ); - ScDPFieldWindow( - ScDPLayoutDlg* pDialog, - const ResId& rResId, - ScDPFieldType eFieldType, - const String& aName ); - virtual ~ScDPFieldWindow(); - - /** Reads the FixedText's text with mnemonic and hides the FixedText. */ - void UseMnemonic(); - - /** Draws the complete control. */ - void Redraw(); - - /** @return The pixel position of a field (without bound check). */ - Point GetFieldPosition( size_t nIndex ) const; - /** @return The pixel size of a field. */ - Size GetFieldSize() const; - - /** @return The index of the selected field. */ - inline bool IsEmpty() const { return aFieldArr.empty(); } - /** @return The index of the selected field. */ - inline size_t GetSelectedField() const { return nFieldSelected; } - /** @return The pixel position of the last possible field. */ - Point GetLastPosition() const; - - /** @return The count of existing fields. */ - inline size_t GetFieldCount() const { return aFieldArr.size(); } - /** Inserts a field to the specified index. */ - void AddField( const String& rText, size_t nNewIndex ); - /** Removes a field from the specified index. */ - void DelField( size_t nDelIndex ); - /** Removes all fields. */ - void ClearFields(); - /** Changes the text on an existing field. */ - void SetFieldText( const String& rText, size_t nIndex ); - /** Returns the text of an existing field. */ - const String& GetFieldText( size_t nIndex ) const; - - /** Inserts a field using the specified pixel position. - @param rPos The coordinates to insert the field. - @param rnIndex The new index of the field is returned here. - @return sal_True, if the field has been created. */ - bool AddField( const String& rText, const Point& rPos, size_t& rnIndex ); - /** Calculates the field index at a specific pixel position. - @param rnIndex The index of the field is returned here. - @return sal_True, if the index value is valid. */ - bool GetFieldIndex( const Point& rPos, size_t& rnIndex ) const; - /** Calculates a field index at a specific pixel position. Returns in every - case the index of an existing field. - @param rnIndex The index of the field is returned here. - @return sal_True, if the index value is valid. */ - void GetExistingIndex( const Point& rPos, size_t& rnIndex ); - - /** Notifies this control that the offset of the first field has been changed. - The control has to adjust the selection to keep the same field selected - on scrolling with scrollbar. */ - void ModifySelectionOffset( long nOffsetDiff ); - /** Selects the next field. Called i.e. after moving a field from SELECT area. */ - void SelectNext(); - - /** @return The name of the control without shortcut. */ - inline String GetName() const { return aName; } - - /** @return The description of the control which is used for the accessibility objects. */ - String GetDescription() const; - - /** Grabs focus and sets new selection. */ - void GrabFocusWithSel( size_t nIndex ); - - /** @return The type of the FieldWindow. */ - inline ScDPFieldType GetType() const { return eType; } + DECL_LINK( ScrollHdl, ScrollBar* ); + +private: + typedef ::std::vector< ScPivotWindowField > ScPivotWindowFieldVector; + + ScPivotLayoutDlg* mpDialog; /// Parent pivot table dialog. + ::com::sun::star::uno::WeakReference< ::com::sun::star::accessibility::XAccessible > + mxAccessible; /// Weak reference to the accessible object. + ScAccessibleDataPilotControl* + mpAccessible; /// Pointer to the accessible implementation. + ScrollBar& mrScrollBar; /// Scrollbar of the select window. + FixedText* mpFtCaption; /// Associated fixedtext control with caption text and mnemonic. + ::rtl::OUString maName; /// Name of the control, used for accessibility. + ScPivotWindowFieldVector maFields; /// Vector with all fields contained in this window. + Size maFieldSize; /// Size of a single field in pixels. + Size maSpaceSize; /// Size between fields in pixels. + ScPivotFieldType meFieldType; /// Type of this field window. + PointerStyle meDropPointer; /// Mouse pointer style for tracking over this window. + size_t mnColCount; /// Number of field columns. + size_t mnRowCount; /// Number of field rows. + size_t mnLineSize; /// Number of fields per line (depending on scrolling orientation). + size_t mnPageSize; /// Number of visible fields. + size_t mnFirstVisIndex; /// Index of first visible field (scrolling offset). + size_t mnSelectIndex; /// Currently selected field. + size_t mnInsCursorIndex; /// Position of the insertion cursor. + size_t mnOldFirstVisIndex; /// Stores original scroll position during auto scrolling. + size_t mnAutoScrollDelay; /// Initial counter before auto scrolling starts on tracking. + bool mbVertical; /// True = sort fields vertically. + bool mbIsTrackingSource; /// True = this field window is the source while tracking. }; -//=================================================================== +// ============================================================================ -#endif // SC_FIELDWND_HXX +#endif |