LCOV - code coverage report
Current view: top level - libreoffice/sc/source/ui/inc - fieldwnd.hxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 4 0.0 %
Date: 2012-12-27 Functions: 0 6 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       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/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      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 .
      18             :  */
      19             : 
      20             : #ifndef SC_FIELDWND_HXX
      21             : #define SC_FIELDWND_HXX
      22             : 
      23             : #include <vector>
      24             : 
      25             : #include <vcl/ctrl.hxx>
      26             : #include <vcl/fixed.hxx>
      27             : #include <vcl/scrbar.hxx>
      28             : 
      29             : #include "address.hxx"
      30             : #include "pivot.hxx"
      31             : 
      32             : struct ScPivotField;
      33             : class ScPivotLayoutDlg;
      34             : class ScAccessibleDataPilotControl;
      35             : 
      36             : extern const size_t PIVOTFIELD_INVALID;
      37             : 
      38             : /** Type of the pivot table field window. */
      39             : enum ScPivotFieldType
      40             : {
      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
      47             : };
      48             : 
      49             : /**
      50             :  * Represents a field area in the DataPilot layout dialog.  This base class
      51             :  * handles storage of field names and the accessibility object.
      52             :  */
      53             : class ScDPFieldControlBase : public Control
      54             : {
      55             : protected:
      56           0 :     struct FieldName
      57             :     {
      58             :         rtl::OUString maText;
      59             :         bool mbFits;
      60             :         sal_uInt8 mnDupCount;
      61             :         FieldName(const rtl::OUString& rText, bool bFits, sal_uInt8 nDupCount = 0);
      62             :         FieldName(const FieldName& r);
      63             : 
      64             :         rtl::OUString getDisplayedText() const;
      65             :     };
      66             :     typedef ::std::vector<FieldName> FieldNames;
      67             : 
      68             : public:
      69             :     typedef boost::ptr_vector<ScPivotFuncData> FuncDataType;
      70             : 
      71             :     struct FuncItem
      72             :     {
      73             :         SCCOL mnCol;
      74             :         sal_uInt16 mnFuncMask;
      75             :     };
      76             : 
      77             :     /**
      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
      81             :      * scroll bar.
      82             :      */
      83           0 :     class ScrollBar : public ::ScrollBar
      84             :     {
      85             :     public:
      86             :         ScrollBar(Window* pParent, WinBits nStyle);
      87             :         virtual void Command( const CommandEvent& rCEvt );
      88             :     private:
      89             :         Window* mpParent;
      90             :     };
      91             : 
      92             :     ScDPFieldControlBase(
      93             :         ScPivotLayoutDlg* pParent, const ResId& rResId, FixedText* pCaption, const char* pcHelpId);
      94             :     virtual ~ScDPFieldControlBase();
      95             : 
      96             :     virtual void CalcSize() = 0;
      97             : 
      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;
     105             : 
     106             :     /** @return The description of the control which is used for the accessibility objects. */
     107             :     virtual String 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;
     114             : 
     115             :     /** @return The name of the control without shortcut. */
     116             :     ::rtl::OUString GetName() const;
     117             :     void SetName(const ::rtl::OUString& rName);
     118             : 
     119             :     /** @return  TRUE, if the field with the given index exists. */
     120             :     bool            IsExistingIndex( size_t nIndex ) const;
     121             : 
     122             :     void AppendField( const rtl::OUString& rText, const ScPivotFuncData& rFunc );
     123             : 
     124             :     /**
     125             :      * Inserts a field using the specified pixel position.
     126             :      *
     127             :      * @param rPos  The coordinates to insert the field.
     128             :      */
     129             :     size_t AddField(const rtl::OUString& rText, const Point& rPos, const ScPivotFuncData& rFunc);
     130             : 
     131             :     bool MoveField(size_t nCurPos, const Point& rPos, size_t& rnIndex);
     132             : 
     133             :     /** Remove a field by specified index. */
     134             :     void DeleteFieldByIndex( size_t nIndex );
     135             : 
     136             :     /** Returns the number of existing fields. */
     137             :     size_t          GetFieldCount() const;
     138             : 
     139             :     bool            IsEmpty() const;
     140             : 
     141             :     /** Removes all fields. */
     142             :     void            ClearFields();
     143             :     /** Changes the text on an existing field. */
     144             :     void SetFieldText(const rtl::OUString& rText, size_t nIndex, sal_uInt8 nDupCount);
     145             :     /** Returns the text of an existing field. */
     146             :     rtl::OUString GetFieldText( size_t nIndex ) const;
     147             : 
     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 );
     153             : 
     154             :     size_t GetSelectedField() const;
     155             : 
     156             :     /** Selects the next field. Called i.e. after moving a field from SELECT area. */
     157             :     void            SelectNext();
     158             :     /** Grabs focus and sets new selection. */
     159             :     void            GrabFocusAndSelect( size_t nIndex );
     160             : 
     161             :     const ScPivotFuncData& GetFuncData(size_t nIndex) const;
     162             :     ScPivotFuncData& GetFuncData(size_t nIndex);
     163             : 
     164             :     void GetAllFuncItems(std::vector<FuncItem>& rItems) const;
     165             : 
     166             :     sal_uInt8 GetNextDupCount(const ScPivotFuncData& rData, size_t nSelfIndex) const;
     167             : 
     168             :     void ConvertToPivotArray(std::vector<ScPivotField>& rFields) const;
     169             : 
     170             :     size_t GetFieldIndexByData( const ScPivotFuncData& rData ) const;
     171             : 
     172             :     virtual void            Paint( const Rectangle& rRect );
     173             : 
     174             : protected:
     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();
     184             : 
     185             : protected:
     186             :     FieldNames& GetFieldNames();
     187             :     const FieldNames& GetFieldNames() const;
     188             : 
     189             :     virtual ::com::sun::star::uno::Reference<
     190             :         ::com::sun::star::accessibility::XAccessible > CreateAccessible();
     191             : 
     192             :     void FieldFocusChanged(size_t nOldSelected, size_t nFieldSelected);
     193             : 
     194             :     /** Updates the tab stop style bits. */
     195             :     void UpdateStyle();
     196             : 
     197             :     /** Draw background color for the whole control area. */
     198             :     void DrawBackground( OutputDevice& rDev );
     199             : 
     200             :     /** Draw a single field button. */
     201             :     void DrawField( OutputDevice& rDev, const Rectangle& rRect,
     202             :                     FieldName& rText, bool bFocus );
     203             : 
     204             :     void AppendPaintable(Window* p);
     205             :     void DrawPaintables();
     206             :     void DrawInvertSelection();
     207             :     Size GetStdFieldBtnSize() const;
     208             : 
     209             :     /** @return  The new selection index after moving to the given direction. */
     210             :     virtual size_t CalcNewFieldIndex( SCsCOL nDX, SCsROW nDY ) const = 0;
     211             : 
     212             :     /**
     213             :      * @param nIndex logical index of a field name, independent of scroll
     214             :      *               offsets.
     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.
     219             :      */
     220             :     virtual size_t GetDisplayPosition(size_t nIndex) const = 0;
     221             : 
     222             :     /** Draws the complete control. */
     223             :     virtual void Redraw() = 0;
     224             : 
     225             : private:
     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 );
     230             : 
     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 );
     235             : 
     236             :     sal_uInt8 GetNextDupCount(const rtl::OUString& rFieldText) const;
     237             : 
     238             : private:
     239             :     typedef ::std::vector<Window*> Paintables;
     240             :     Paintables maPaintables;
     241             : 
     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.
     246             :     ::rtl::OUString maName;
     247             : 
     248             :     size_t mnFieldSelected; /// Currently selected field.
     249             : 
     250             :     // Hold a helpful reference while we work with our weakref.
     251           0 :     class AccessRef
     252             :     {
     253             :         com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible > mxRef;
     254             :     public:
     255             :         AccessRef( const com::sun::star::uno::WeakReference< ::com::sun::star::accessibility::XAccessible > & rAccessible );
     256             :         ScAccessibleDataPilotControl *operator -> () const;
     257           0 :         bool is() { return mxRef.is(); }
     258             :     };
     259             : 
     260             :     com::sun::star::uno::WeakReference< ::com::sun::star::accessibility::XAccessible > mxAccessible;
     261             : };
     262             : 
     263             : // ============================================================================
     264             : 
     265             : /**
     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.
     268             :  */
     269             : class ScDPHorFieldControl : public ScDPFieldControlBase
     270             : {
     271             : protected:
     272             :     virtual size_t          CalcNewFieldIndex(SCsCOL nDX, SCsROW nDY) const;
     273             :     virtual size_t          GetDisplayPosition(size_t nIndex) const;
     274             :     virtual void            Redraw();
     275             : 
     276             : public:
     277             :     ScDPHorFieldControl(
     278             :         ScPivotLayoutDlg* pDialog, const ResId& rResId, FixedText* pCaption, const char* pcHelpId);
     279             : 
     280             :     virtual                 ~ScDPHorFieldControl();
     281             : 
     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 String          GetDescription() const;
     288             : 
     289             :     virtual void ScrollToEnd();
     290             :     virtual void ScrollToShowSelection();
     291             :     virtual void ResetScrollBar();
     292             :     virtual void HandleWheelScroll(long nNotch);
     293             : 
     294             : private:
     295             :     bool GetFieldBtnPosSize(size_t nPos, Point& rPos, Size& rSize);
     296             :     void HandleScroll();
     297             : 
     298             :     DECL_LINK(ScrollHdl, void*);
     299             :     DECL_LINK(EndScrollHdl, void*);
     300             : 
     301             : private:
     302             : 
     303             :     ScrollBar               maScroll;
     304             : 
     305             :     size_t                  mnFieldBtnRowCount;
     306             :     size_t                  mnFieldBtnColCount;
     307             : };
     308             : 
     309             : // ============================================================================
     310             : 
     311             : class ScDPPageFieldControl : public ScDPHorFieldControl
     312             : {
     313             : public:
     314             :     ScDPPageFieldControl(
     315             :         ScPivotLayoutDlg* pDialog, const ResId& rResId, FixedText* pCaption, const char* pcHelpId);
     316             :     virtual ~ScDPPageFieldControl();
     317             : 
     318             :     virtual ScPivotFieldType GetFieldType() const;
     319             :     virtual String GetDescription() const;
     320             : };
     321             : 
     322             : // ============================================================================
     323             : 
     324             : class ScDPColFieldControl : public ScDPHorFieldControl
     325             : {
     326             : public:
     327             :     ScDPColFieldControl(
     328             :         ScPivotLayoutDlg* pDialog, const ResId& rResId, FixedText* pCaption, const char* pcHelpId);
     329             :     virtual ~ScDPColFieldControl();
     330             : 
     331             :     virtual ScPivotFieldType GetFieldType() const;
     332             :     virtual String GetDescription() const;
     333             : };
     334             : 
     335             : // ============================================================================
     336             : 
     337             : /**
     338             :  * Row field control with a vertical scroll bar.
     339             :  */
     340             : class ScDPRowFieldControl : public ScDPFieldControlBase
     341             : {
     342             : public:
     343             :     ScDPRowFieldControl(
     344             :         ScPivotLayoutDlg* pDialog, const ResId& rResId, FixedText* pCaption, const char* pcHelpId);
     345             : 
     346             :     virtual                 ~ScDPRowFieldControl();
     347             : 
     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 String          GetDescription() const;
     354             :     virtual ScPivotFieldType   GetFieldType() const;
     355             : 
     356             :     virtual void ScrollToEnd();
     357             :     virtual void ScrollToShowSelection();
     358             :     virtual void ResetScrollBar();
     359             :     virtual void HandleWheelScroll(long nNotch);
     360             : 
     361             : protected:
     362             :     virtual size_t          CalcNewFieldIndex( SCsCOL nDX, SCsROW nDY ) const;
     363             :     virtual size_t          GetDisplayPosition(size_t nIndex) const;
     364             :     virtual void            Redraw();
     365             : 
     366             : private:
     367             :     bool GetFieldBtnPosSize(size_t nPos, Point& rPos, Size& rSize);
     368             :     void HandleScroll();
     369             : 
     370             :     DECL_LINK(ScrollHdl, void*);
     371             :     DECL_LINK(EndScrollHdl, void*);
     372             : 
     373             : private:
     374             : 
     375             :     ScDPFieldControlBase::ScrollBar maScroll;
     376             :     size_t                  mnColumnBtnCount;
     377             : };
     378             : 
     379             : // ============================================================================
     380             : 
     381             : class ScDPSelectFieldControl : public ScDPHorFieldControl
     382             : {
     383             : public:
     384             :     ScDPSelectFieldControl(
     385             :         ScPivotLayoutDlg* pDialog, const ResId& rResId, FixedText* pCaption, const char* pcHelpId);
     386             :     virtual ~ScDPSelectFieldControl();
     387             : 
     388             :     virtual ScPivotFieldType GetFieldType() const;
     389             :     virtual String GetDescription() const;
     390             : };
     391             : 
     392             : // ============================================================================
     393             : 
     394             : class ScDPDataFieldControl : public ScDPHorFieldControl
     395             : {
     396             : public:
     397             :     ScDPDataFieldControl(
     398             :         ScPivotLayoutDlg* pParent, const ResId& rResId, FixedText* pCaption, const char* pcHelpId);
     399             :     virtual ~ScDPDataFieldControl();
     400             : 
     401             :     virtual ScPivotFieldType GetFieldType() const;
     402             :     virtual Size GetFieldSize() const;
     403             :     virtual String GetDescription() const;
     404             : };
     405             : 
     406             : #endif
     407             : 
     408             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10