LCOV - code coverage report
Current view: top level - sc/source/ui/inc - csvcontrol.hxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 34 0.0 %
Date: 2014-04-14 Functions: 0 28 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_CSVCONTROL_HXX
      21             : #define _SC_CSVCONTROL_HXX
      22             : 
      23             : #include <vcl/ctrl.hxx>
      24             : #include "scdllapi.h"
      25             : #include "global.hxx"
      26             : #include "address.hxx"
      27             : #include "csvsplits.hxx"
      28             : #include <com/sun/star/uno/Reference.hxx>
      29             : 
      30             : 
      31             : class ScAccessibleCsvControl;
      32             : namespace com { namespace sun { namespace star { namespace accessibility {
      33             :     class XAccessible;
      34             : } } } }
      35             : 
      36             : 
      37             : /** Minimum character count for a column in separators mode. */
      38             : const sal_Int32 CSV_MINCOLWIDTH         = 8;
      39             : /** Maximum length of a cell string. */
      40             : const sal_Int32 CSV_MAXSTRLEN          = 0x7FFF;
      41             : /** Transparency for header color of selected columns. */
      42             : const sal_uInt16 CSV_HDR_TRANSPARENCY   = 85;
      43             : /** Minimum distance to border for auto scroll. */
      44             : const sal_Int32 CSV_SCROLL_DIST         = 3;
      45             : 
      46             : //! TODO make string array dynamic
      47             : const sal_Int32 CSV_PREVIEW_LINES       = 32; // maximum count of preview lines
      48             : /** Maximum count of columns. */
      49             : const sal_Int32 CSV_MAXCOLCOUNT         = MAXCOLCOUNT;
      50             : 
      51             : /** Default column data type. */
      52             : const sal_Int32 CSV_TYPE_DEFAULT        = 0;
      53             : /** Multi selection with different types. */
      54             : const sal_Int32 CSV_TYPE_MULTI          = -1;
      55             : /** No column selected. */
      56             : const sal_Int32 CSV_TYPE_NOSELECTION    = -2;
      57             : 
      58             : // External used column types.
      59             : const sal_uInt8 SC_COL_STANDARD         = 1;
      60             : const sal_uInt8 SC_COL_TEXT             = 2;
      61             : const sal_uInt8 SC_COL_MDY              = 3;
      62             : const sal_uInt8 SC_COL_DMY              = 4;
      63             : const sal_uInt8 SC_COL_YMD              = 5;
      64             : const sal_uInt8 SC_COL_SKIP             = 9;
      65             : const sal_uInt8 SC_COL_ENGLISH          = 10;
      66             : 
      67             : 
      68             : /** Exported data of a column (data used in the dialog). */
      69             : struct ScCsvExpData
      70             : {
      71             :     sal_Int32                   mnIndex;        /// Index of a column.
      72             :     sal_uInt8                   mnType;         /// External type of the column.
      73             : 
      74           0 :     inline                      ScCsvExpData() : mnIndex( 0 ), mnType( SC_COL_STANDARD ) {}
      75           0 :     inline                      ScCsvExpData( sal_Int32 nIndex, sal_uInt8 nType ) :
      76           0 :                                     mnIndex( nIndex ), mnType( nType ) {}
      77             : };
      78             : 
      79             : typedef ::std::vector< ScCsvExpData > ScCsvExpDataVec;
      80             : 
      81             : 
      82             : /** Specifies which element should be used to perform an action. */
      83             : enum ScMoveMode
      84             : {
      85             :     MOVE_NONE,                  /// No action.
      86             :     MOVE_FIRST,                 /// First element in current context.
      87             :     MOVE_LAST,                  /// Last element in current context.
      88             :     MOVE_PREV,                  /// Predecessor of current element in current context.
      89             :     MOVE_NEXT,                  /// Successor of current element in current context.
      90             :     MOVE_PREVPAGE,              /// Previous page relative to current context.
      91             :     MOVE_NEXTPAGE               /// Next page relative to current context.
      92             : };
      93             : 
      94             : 
      95             : /** Flags for comparison of old and new control layout data. */
      96             : typedef sal_uInt32 ScCsvDiff;
      97             : 
      98             : const ScCsvDiff CSV_DIFF_EQUAL          = 0x00000000;
      99             : const ScCsvDiff CSV_DIFF_POSCOUNT       = 0x00000001;
     100             : const ScCsvDiff CSV_DIFF_POSOFFSET      = 0x00000002;
     101             : const ScCsvDiff CSV_DIFF_HDRWIDTH       = 0x00000004;
     102             : const ScCsvDiff CSV_DIFF_CHARWIDTH      = 0x00000008;
     103             : const ScCsvDiff CSV_DIFF_LINECOUNT      = 0x00000010;
     104             : const ScCsvDiff CSV_DIFF_LINEOFFSET     = 0x00000020;
     105             : const ScCsvDiff CSV_DIFF_HDRHEIGHT      = 0x00000040;
     106             : const ScCsvDiff CSV_DIFF_LINEHEIGHT     = 0x00000080;
     107             : const ScCsvDiff CSV_DIFF_RULERCURSOR    = 0x00000100;
     108             : const ScCsvDiff CSV_DIFF_GRIDCURSOR     = 0x00000200;
     109             : 
     110             : const ScCsvDiff CSV_DIFF_HORIZONTAL     = CSV_DIFF_POSCOUNT | CSV_DIFF_POSOFFSET | CSV_DIFF_HDRWIDTH | CSV_DIFF_CHARWIDTH;
     111             : const ScCsvDiff CSV_DIFF_VERTICAL       = CSV_DIFF_LINECOUNT | CSV_DIFF_LINEOFFSET | CSV_DIFF_HDRHEIGHT | CSV_DIFF_LINEHEIGHT;
     112             : const ScCsvDiff CSV_DIFF_CURSOR         = CSV_DIFF_RULERCURSOR | CSV_DIFF_GRIDCURSOR;
     113             : 
     114             : 
     115             : /** A structure containing all layout data valid for both ruler and data grid
     116             :     (i.e. scroll position or column width). */
     117             : struct ScCsvLayoutData
     118             : {
     119             :     // horizontal settings
     120             :     sal_Int32                   mnPosCount;         /// Number of positions.
     121             :     sal_Int32                   mnPosOffset;        /// Horizontal scroll offset.
     122             : 
     123             :     sal_Int32                   mnWinWidth;         /// Width of ruler and data grid.
     124             :     sal_Int32                   mnHdrWidth;         /// Width of the header column.
     125             :     sal_Int32                   mnCharWidth;        /// Pixel width of one character.
     126             : 
     127             :     // vertical settings
     128             :     sal_Int32                   mnLineCount;        /// Number of data lines.
     129             :     sal_Int32                   mnLineOffset;       /// Index of first visible line (0-based).
     130             : 
     131             :     sal_Int32                   mnWinHeight;        /// Height of entire data grid (incl. header).
     132             :     sal_Int32                   mnHdrHeight;        /// Height of the header line.
     133             :     sal_Int32                   mnLineHeight;       /// Height of a data line.
     134             : 
     135             :     // cursor settings
     136             :     sal_Int32                   mnPosCursor;        /// Position of ruler cursor.
     137             :     sal_Int32                   mnColCursor;        /// Position of grid column cursor.
     138             : 
     139             :     mutable sal_Int32           mnNoRepaint;        /// >0 = no repaint.
     140             :     bool                        mbAppRTL;           /// true = application in RTL mode.
     141             : 
     142             :     explicit                    ScCsvLayoutData();
     143             : 
     144             :     /** Returns differences to rData.
     145             :         @descr  For each difference the appropriate bit is set in the returned value. */
     146             :     ScCsvDiff                   GetDiff( const ScCsvLayoutData& rData ) const;
     147             : };
     148             : 
     149           0 : inline bool operator==( const ScCsvLayoutData& rData1, const ScCsvLayoutData& rData2 )
     150             : {
     151           0 :     return rData1.GetDiff( rData2 ) == CSV_DIFF_EQUAL;
     152             : }
     153             : 
     154           0 : inline bool operator!=( const ScCsvLayoutData& rData1, const ScCsvLayoutData& rData2 )
     155             : {
     156           0 :     return !(rData1 == rData2);
     157             : }
     158             : 
     159             : 
     160             : /** Enumeration of possible commands to change any settings of the CSV controls.
     161             :     @descr  Controls have to send commands instead of changing their settings directly.
     162             :     This helps to keep the different controls consistent to each other.
     163             :     A command can contain 0 to 2 sal_Int32 parameters. In the description of each
     164             :     command the required parameters are swown in brackets. [-] means no parameter. */
     165             : enum ScCsvCmdType
     166             : {
     167             :     // misc
     168             :     CSVCMD_NONE,                /// No command. [-]
     169             :     CSVCMD_REPAINT,             /// Repaint all controls. [-]
     170             : 
     171             :     // modify horizontal dimensions
     172             :     CSVCMD_SETPOSCOUNT,         /// Change position/column count. [character count]
     173             :     CSVCMD_SETPOSOFFSET,        /// Change position offset (scroll pos). [position]
     174             :     CSVCMD_SETHDRWIDTH,         /// Change width of the header column. [width in pixel]
     175             :     CSVCMD_SETCHARWIDTH,        /// Change character pixel width. [width in pixel]
     176             : 
     177             :     // modify vertical dimensions
     178             :     CSVCMD_SETLINECOUNT,        /// Change number of data lines. [line count]
     179             :     CSVCMD_SETLINEOFFSET,       /// Change first visible line. [line index]
     180             :     CSVCMD_SETHDRHEIGHT,        /// Change height of top header line. [height in pixel]
     181             :     CSVCMD_SETLINEHEIGHT,       /// Change data line pixel height. [height in pixel}
     182             : 
     183             :     // cursors/positions
     184             :     CSVCMD_MOVERULERCURSOR,     /// Move ruler cursor to new position. [position]
     185             :     CSVCMD_MOVEGRIDCURSOR,      /// Move data grid cursor to new column. [position]
     186             :     CSVCMD_MAKEPOSVISIBLE,      /// Move to make passed position visible (for mouse tracking). [position]
     187             : 
     188             :     // table contents
     189             :     CSVCMD_NEWCELLTEXTS,        /// Recalculate splits and cell texts. [-]
     190             :     CSVCMD_UPDATECELLTEXTS,     /// Update cell texts with current split settings. [-]
     191             :     CSVCMD_SETCOLUMNTYPE,       /// Change data type of selected columns. [column type]
     192             :     CSVCMD_EXPORTCOLUMNTYPE,    /// Send selected column type to external controls. [-]
     193             :     CSVCMD_SETFIRSTIMPORTLINE,  /// Set number of first imported line. [line index]
     194             : 
     195             :     // splits
     196             :     CSVCMD_INSERTSPLIT,         /// Insert a split. [position]
     197             :     CSVCMD_REMOVESPLIT,         /// Remove a split. [position]
     198             :     CSVCMD_TOGGLESPLIT,         /// Inserts or removes a split. [position]
     199             :     CSVCMD_MOVESPLIT,           /// Move a split. [old position, new position]
     200             :     CSVCMD_REMOVEALLSPLITS      /// Remove all splits. [-]
     201             : };
     202             : 
     203             : 
     204             : /** Data for a CSV control command. The stored position data is aways character based,
     205             :     it's never a column index (required for internal consistency). */
     206             : class ScCsvCmd
     207             : {
     208             : private:
     209             :     ScCsvCmdType                meType;         /// The command.
     210             :     sal_Int32                   mnParam1;       /// First parameter.
     211             :     sal_Int32                   mnParam2;       /// Second parameter.
     212             : 
     213             : public:
     214           0 :     inline explicit             ScCsvCmd() : meType( CSVCMD_NONE ),
     215           0 :                                     mnParam1( CSV_POS_INVALID ), mnParam2( CSV_POS_INVALID ) {}
     216             : 
     217             :     inline void                 Set( ScCsvCmdType eType, sal_Int32 nParam1, sal_Int32 nParam2 );
     218             : 
     219           0 :     inline ScCsvCmdType         GetType() const     { return meType; }
     220           0 :     inline sal_Int32            GetParam1() const   { return mnParam1; }
     221           0 :     inline sal_Int32            GetParam2() const   { return mnParam2; }
     222             : };
     223             : 
     224           0 : inline void ScCsvCmd::Set( ScCsvCmdType eType, sal_Int32 nParam1, sal_Int32 nParam2 )
     225             : {
     226           0 :     meType = eType; mnParam1 = nParam1; mnParam2 = nParam2;
     227           0 : }
     228             : 
     229             : 
     230             : /** Base class for the CSV ruler and the data grid control. Implements command handling. */
     231             : class SC_DLLPUBLIC ScCsvControl : public Control
     232             : {
     233             : protected:
     234             :     typedef ::std::vector< OUString >   StringVec;
     235             :     typedef ::std::vector< StringVec >  StringVecVec;
     236             : 
     237             :     typedef ::com::sun::star::uno::Reference<
     238             :         ::com::sun::star::accessibility::XAccessible > XAccessibleRef;
     239             : 
     240             : private:
     241             :     Link                        maCmdHdl;           /// External command handler.
     242             :     ScCsvCmd                    maCmd;              /// Data of last command.
     243             :     const ScCsvLayoutData&      mrData;             /// Shared layout data.
     244             : 
     245             :     XAccessibleRef              mxAccessible;       /// The accessible object of the control.
     246             :     ScAccessibleCsvControl*     mpAccessible;       /// Pointer to the accessible implementation object.
     247             :     bool                        mbValidGfx;         /// Content of virtual devices valid?
     248             : 
     249             : 
     250             : public:
     251             :     explicit                    ScCsvControl( ScCsvControl& rParent );
     252             :     explicit                    ScCsvControl( Window* pParent, const ScCsvLayoutData& rData, WinBits nBits );
     253             :     virtual                     ~ScCsvControl();
     254             : 
     255             :     // event handling ---------------------------------------------------------
     256             : 
     257             :     virtual void                GetFocus() SAL_OVERRIDE;
     258             :     virtual void                LoseFocus() SAL_OVERRIDE;
     259             : 
     260             :     /** Sends a GetFocus or LoseFocus event to the accessibility object. */
     261             :     void                        AccSendFocusEvent( bool bFocused );
     262             :     /** Sends a caret changed event to the accessibility object. */
     263             :     void                        AccSendCaretEvent();
     264             :     /** Sends a visible area changed event to the accessibility object. */
     265             :     void                        AccSendVisibleEvent();
     266             :     /** Sends a selection changed event to the accessibility object. */
     267             :     void                        AccSendSelectionEvent();
     268             :     /** Sends a table model changed event for changed cell contents to the accessibility object. */
     269             :     void                        AccSendTableUpdateEvent( sal_uInt32 nFirstColumn, sal_uInt32 nLastColumn, bool bAllRows = true );
     270             :     /** Sends a table model changed event for an inserted column to the accessibility object. */
     271             :     void                        AccSendInsertColumnEvent( sal_uInt32 nFirstColumn, sal_uInt32 nLastColumn );
     272             :     /** Sends a table model changed event for a removed column to the accessibility object. */
     273             :     void                        AccSendRemoveColumnEvent( sal_uInt32 nFirstColumn, sal_uInt32 nLastColumn );
     274             : 
     275             :     // repaint helpers --------------------------------------------------------
     276             : 
     277             :     /** Sets the graphic invalid (next Redraw() will not use cached graphic). */
     278           0 :     inline void                 InvalidateGfx() { mbValidGfx = false; }
     279             :     /** Sets the graphic valid (next Redraw() will use cached graphic). */
     280           0 :     inline void                 ValidateGfx() { mbValidGfx = true; }
     281             :     /** Returns true, if cached graphic is valid. */
     282           0 :     inline bool                 IsValidGfx() const { return mbValidGfx; }
     283             : 
     284             :     /** Repaints all controls.
     285             :         @param bInvalidate  true = invalidates graphics of this control (not all). */
     286             :     void                        Repaint( bool bInvalidate = false );
     287             :     /** Increases no-repaint counter (controls do not repaint until the last EnableRepaint()). */
     288             :     void                        DisableRepaint();
     289             :     /** Decreases no-repaint counter and repaints if counter reaches 0.
     290             :         @param bInvalidate  true = invalidates graphics of this control (not all). */
     291             :     void                        EnableRepaint( bool bInvalidate = false );
     292             :     /** Returns true, if controls will not repaint. */
     293           0 :     inline bool                 IsNoRepaint() const { return mrData.mnNoRepaint > 0; }
     294             : 
     295             :     // command handling -------------------------------------------------------
     296             : 
     297             :     /** Sets a new command handler. */
     298           0 :     inline void                 SetCmdHdl( const Link& rHdl ) { maCmdHdl = rHdl; }
     299             :     /** Returns the current command handler. */
     300             :     inline const Link&          GetCmdHdl() const { return maCmdHdl; }
     301             :     /** Returns data of the last command. */
     302           0 :     inline const ScCsvCmd&      GetCmd() const { return maCmd; }
     303             : 
     304             :     /** Executes a command by calling command handler. */
     305             :     void                        Execute(
     306             :                                     ScCsvCmdType eType,
     307             :                                     sal_Int32 nParam1 = CSV_POS_INVALID,
     308             :                                     sal_Int32 nParam2 = CSV_POS_INVALID );
     309             : 
     310             :     // layout helpers ---------------------------------------------------------
     311             : 
     312             :     /** Returns a reference to the current layout data. */
     313           0 :     inline const ScCsvLayoutData& GetLayoutData() const { return mrData; }
     314             :     /** Returns true, if the Right-to-Left layout mode is active. */
     315           0 :     inline bool                 IsRTL() const { return mrData.mbAppRTL; }
     316             : 
     317             :     /** Returns the number of available positions. */
     318           0 :     inline sal_Int32            GetPosCount() const { return mrData.mnPosCount; }
     319             :     /** Returns the number of visible positions. */
     320             :     sal_Int32                   GetVisPosCount() const;
     321             :     /** Returns the first visible position. */
     322           0 :     inline sal_Int32            GetFirstVisPos() const { return mrData.mnPosOffset; }
     323             :     /** Returns the last visible position. */
     324           0 :     inline sal_Int32            GetLastVisPos() const { return GetFirstVisPos() + GetVisPosCount(); }
     325             :     /** Returns highest possible position for first visible character. */
     326             :     sal_Int32                   GetMaxPosOffset() const;
     327             : 
     328             :     /** Returns true, if it is allowed to set a split at nPos. */
     329             :     bool                        IsValidSplitPos( sal_Int32 nPos ) const;
     330             :     /** Returns true, if nPos is an allowed AND visible split position. */
     331             :     bool                        IsVisibleSplitPos( sal_Int32 nPos ) const;
     332             : 
     333             :     /** Returns the width of the header column. */
     334           0 :     inline sal_Int32            GetHdrWidth() const { return mrData.mnHdrWidth; }
     335             :     /** Returns the width of one character column. */
     336           0 :     inline sal_Int32            GetCharWidth() const { return mrData.mnCharWidth; }
     337             :     /** Returns the start position of the header column. */
     338             :     sal_Int32                   GetHdrX() const;
     339             :     /** Returns the X position of the first pixel of the data area. */
     340             :     sal_Int32                   GetFirstX() const;
     341             :     /** Returns the X position of the last pixel of the data area. */
     342             :     sal_Int32                   GetLastX() const;
     343             :     /** Returns output X coordinate of the specified position. */
     344             :     sal_Int32                   GetX( sal_Int32 nPos ) const;
     345             :     /** Returns position from output coordinate. */
     346             :     sal_Int32                   GetPosFromX( sal_Int32 nX ) const;
     347             : 
     348             :     /** Returns the number of data lines. */
     349           0 :     inline sal_Int32            GetLineCount() const { return mrData.mnLineCount; }
     350             :     /** Returns the number of visible lines (including partly visible bottom line). */
     351             :     sal_Int32                   GetVisLineCount() const;
     352             :     /** Returns index of first visible line. */
     353           0 :     inline sal_Int32            GetFirstVisLine() const { return mrData.mnLineOffset; }
     354             :     /** Returns index of last visible line. */
     355             :     sal_Int32                   GetLastVisLine() const;
     356             :     /** Returns highest possible index for first line. */
     357             :     sal_Int32                   GetMaxLineOffset() const;
     358             : 
     359             :     /** Returns true, if nLine is a valid line index. */
     360             :     bool                        IsValidLine( sal_Int32 nLine ) const;
     361             :     /** Returns true, if nLine is a valid and visible line index. */
     362             :     bool                        IsVisibleLine( sal_Int32 nLine ) const;
     363             : 
     364             :     /** Returns the height of the header line. */
     365           0 :     inline sal_Int32            GetHdrHeight() const { return mrData.mnHdrHeight; }
     366             :     /** Returns the height of one line. */
     367           0 :     inline sal_Int32            GetLineHeight() const { return mrData.mnLineHeight; }
     368             :     /** Returns output Y coordinate of the specified line. */
     369             :     sal_Int32                   GetY( sal_Int32 nLine ) const;
     370             :     /** Returns line index from output coordinate. */
     371             :     sal_Int32                   GetLineFromY( sal_Int32 nY ) const;
     372             : 
     373             :     /** Returns the ruler cursor position. */
     374           0 :     inline sal_Int32            GetRulerCursorPos() const { return mrData.mnPosCursor; }
     375             :     /** Returns the data grid cursor position (not column index!). */
     376           0 :     inline sal_Int32            GetGridCursorPos() const { return mrData.mnColCursor; }
     377             : 
     378             :     // static helpers ---------------------------------------------------------
     379             : 
     380             :     /** Inverts a rectangle in the specified output device. */
     381             :     static void                 ImplInvertRect( OutputDevice& rOutDev, const Rectangle& rRect );
     382             : 
     383             :     /** Returns direction code for the keys LEFT, RIGHT, HOME, END.
     384             :         @param bHomeEnd  false = ignore HOME and END key. */
     385             :     static ScMoveMode           GetHorzDirection( sal_uInt16 nCode, bool bHomeEnd );
     386             :     /** Returns direction code for the keys UP, DOWN, HOME, END, PAGE UP, PAGE DOWN.
     387             :         @param bHomeEnd  false = ignore HOME and END key. */
     388             :     static ScMoveMode           GetVertDirection( sal_uInt16 nCode, bool bHomeEnd );
     389             : 
     390             :     // accessibility ----------------------------------------------------------
     391             : public:
     392             :     /** Creates and returns the accessible object of this control. Do not overwrite in
     393             :         derived classes, use ImplCreateAccessible() instead. */
     394             :     virtual XAccessibleRef     CreateAccessible() SAL_OVERRIDE;
     395             : 
     396             : protected:
     397             :     /** Derived classes create a new accessible object here. */
     398             :     virtual ScAccessibleCsvControl* ImplCreateAccessible() = 0;
     399             : };
     400             : 
     401             : 
     402             : #endif
     403             : 
     404             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10