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

Generated by: LCOV version 1.10