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

Generated by: LCOV version 1.11