diff options
author | Daniel Rentz <dr@openoffice.org> | 2002-07-05 14:42:20 +0000 |
---|---|---|
committer | Daniel Rentz <dr@openoffice.org> | 2002-07-05 14:42:20 +0000 |
commit | 5eeeb534645bfbe5002e09ea8f062496cfdc84dc (patch) | |
tree | 0e3f731cf8ca9bd974aa1601cadcb47f9ab59e0f /sc | |
parent | 00c6e59310a1df679d3c45c64392ca0f6ca488b9 (diff) |
#100032# TableBox redesign in CSV import dlg
Diffstat (limited to 'sc')
-rw-r--r-- | sc/source/ui/inc/asciiopt.hxx | 191 | ||||
-rw-r--r-- | sc/source/ui/inc/csvcontrol.hxx | 389 | ||||
-rw-r--r-- | sc/source/ui/inc/csvgrid.hxx | 356 | ||||
-rw-r--r-- | sc/source/ui/inc/csvruler.hxx | 238 | ||||
-rw-r--r-- | sc/source/ui/inc/csvsplits.hxx | 139 | ||||
-rw-r--r-- | sc/source/ui/inc/csvtablebox.hxx | 201 |
6 files changed, 1406 insertions, 108 deletions
diff --git a/sc/source/ui/inc/asciiopt.hxx b/sc/source/ui/inc/asciiopt.hxx index 81b25e7996b6..438188b02138 100644 --- a/sc/source/ui/inc/asciiopt.hxx +++ b/sc/source/ui/inc/asciiopt.hxx @@ -2,9 +2,9 @@ * * $RCSfile: asciiopt.hxx,v $ * - * $Revision: 1.4 $ + * $Revision: 1.5 $ * - * last change: $Author: dr $ $Date: 2001-05-30 13:33:54 $ + * last change: $Author: dr $ $Date: 2002-07-05 15:42:20 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -59,10 +59,11 @@ * ************************************************************************/ +// ============================================================================ + #ifndef SC_ASCIIOPT_HXX #define SC_ASCIIOPT_HXX -#include <tools/solar.h> #ifndef _STRING_HXX //autogen #include <tools/string.hxx> #endif @@ -84,12 +85,6 @@ #ifndef _FIELD_HXX //autogen #include <vcl/field.hxx> #endif -#ifndef _SCRBAR_HXX //autogen -#include <vcl/scrbar.hxx> -#endif -#ifndef _SVTABBX_HXX //autogen -#include <svtools/svtabbx.hxx> -#endif #ifndef _STREAM_HXX //autogen #include <tools/stream.hxx> #endif @@ -97,28 +92,12 @@ #include <svx/txencbox.hxx> #endif -#ifndef _SVSTDARR_ULONGS -#define _SVSTDARR_ULONGS -#include <svtools/svstdarr.hxx> +#ifndef _SC_CSVTABLEBOX_HXX +#include "csvtablebox.hxx" #endif -#include "tabrul.hxx" - -//=================================================================== - -// Spaltenformate (Werte wie bei OpenText in Excel) - -#define SC_COL_STANDARD 1 -#define SC_COL_TEXT 2 -#define SC_COL_MDY 3 -#define SC_COL_DMY 4 -#define SC_COL_YMD 5 -#define SC_COL_SKIP 9 -#define SC_COL_ENGLISH 10 -#define SC_ASCIIOPT_PREVIEW_LINES 6 // Anzahl Preview Lines - -// Import-Optionen +// ============================================================================ class ScAsciiOptions { @@ -131,8 +110,8 @@ private: BOOL bCharSetSystem; long nStartRow; USHORT nInfoCount; - xub_StrLen* pColStart; - BYTE* pColFormat; + xub_StrLen* pColStart; //! TODO replace with vector + BYTE* pColFormat; //! TODO replace with vector public: ScAsciiOptions(); @@ -168,100 +147,96 @@ public: void SetStartRow( long nRow) { nStartRow= nRow; } void SetColInfo( USHORT nCount, const xub_StrLen* pStart, const BYTE* pFormat ); + void SetColumnInfo( const ScCsvExtColPosVec& rColPosVec, const ScCsvExtColTypeVec& rColTypeVec ); }; -// Import-Dialog +// ============================================================================ class ScImportAsciiDlg : public ModalDialog { - SvStream* pDatStream; - ULONG* pRowPosArray; - ULONG* pRowPosArrayUnicode; - USHORT nArrayEndPos; - USHORT nArrayEndPosUnicode; - ULONG nStreamPos; - ULONG nStreamPosUnicode; - - BOOL bVFlag; - - FixedLine aFlFieldOpt; - FixedText aFtCharSet; - SvxTextEncodingBox aLbCharSet; - BOOL bCharSetSystem; - - FixedText aFtRow; - NumericField aNfRow; - - FixedLine aFlSepOpt; - RadioButton aRbFixed; - RadioButton aRbSeparated; - - CheckBox aCkbTab; - CheckBox aCkbSemicolon; - CheckBox aCkbComma; - CheckBox aCkbSpace; - CheckBox aCkbOther; - Edit aEdOther; - CheckBox aCkbAsOnce; - FixedText aFtTextSep; - ComboBox aCbTextSep; - - FixedLine aFlWidth; - FixedText aFtType; - ListBox aLbType; - ScTableWithRuler aTableBox; - ScrollBar aScrollbar; - ScrollBar aVScroll; - - OKButton aBtnOk; - CancelButton aBtnCancel; - HelpButton aBtnHelp; - - String aStringCol; - String aStringTo; - String aCharSetUser; - String aColumnUser; - String aFldSepList; - String aTextSepList; + SvStream* pDatStream; + ULONG* pRowPosArray; + ULONG* pRowPosArrayUnicode; + USHORT nArrayEndPos; + USHORT nArrayEndPosUnicode; + ULONG nStreamPos; + ULONG nStreamPosUnicode; + BOOL bVFlag; + + FixedLine aFlFieldOpt; + FixedText aFtCharSet; + SvxTextEncodingBox aLbCharSet; + + FixedText aFtRow; + NumericField aNfRow; + + FixedLine aFlSepOpt; + RadioButton aRbFixed; + RadioButton aRbSeparated; + + CheckBox aCkbTab; + CheckBox aCkbSemicolon; + CheckBox aCkbComma; + CheckBox aCkbSpace; + CheckBox aCkbOther; + Edit aEdOther; + CheckBox aCkbAsOnce; + FixedText aFtTextSep; + ComboBox aCbTextSep; + + FixedLine aFlWidth; + FixedText aFtType; + ListBox aLbType; + + ScCsvTableBox maTableBox; + + OKButton aBtnOk; + CancelButton aBtnCancel; + HelpButton aBtnHelp; + + String aCharSetUser; + String aColumnUser; + String aFldSepList; + String aTextSepList; // aPreviewLine contains the byte string as read from the file - ByteString aPreviewLine[SC_ASCIIOPT_PREVIEW_LINES]; + ByteString aPreviewLine[ CSV_PREVIEW_LINES ]; // same for Unicode - String aPreviewLineUnicode[SC_ASCIIOPT_PREVIEW_LINES]; - - USHORT nScrollPos; - USHORT nUsedCols; - USHORT* pEndValues; - BYTE* pFlags; - CharSet eCharSet; - - void CheckDisable(); - void CheckValues(BOOL bReadVal = FALSE, USHORT nEditField = USHRT_MAX); - void CheckColTypes(BOOL bReadVal,void *pCtr=NULL); - void CheckScrollRange(); - void CheckScrollPos(); - void UpdateVertical( BOOL bSwitchToFromUnicode = FALSE ); - void DelimitedPreview(); - void GetCharSet(); - - DECL_LINK( VarFixHdl, void* ); - DECL_LINK( ScrollHdl, void* ); - DECL_LINK( SelectHdl, ScTableWithRuler* ); - DECL_LINK( ColTypeHdl, void* ); - DECL_LINK( CharSetHdl, void* ); - DECL_LINK( VarSepHdl, void* ); + String aPreviewLineUnicode[ CSV_PREVIEW_LINES ]; + + CharSet meCharSet; /// Selected char set. + bool mbCharSetSystem; /// Is System char set selected? public: - ScImportAsciiDlg( Window* pParent, String aDatName, + ScImportAsciiDlg( + Window* pParent, String aDatName, SvStream* pInStream, sal_Unicode cSep = '\t' ); - ~ScImportAsciiDlg(); + ~ScImportAsciiDlg(); + + void GetOptions( ScAsciiOptions& rOpt ); - void GetOptions( ScAsciiOptions& rOpt ); +private: + /** Sets the selected char set data to meCharSet and mbCharSetSystem. */ + void SetSelectedCharSet(); + /** Returns all separator characters in a string. */ + String GetSeparators() const; + + /** Enables or disables all separator checkboxes and edit fields. */ + void SetupSeparatorCtrls(); + + void UpdateVertical( bool bSwitchToFromUnicode = false ); + + DECL_LINK( CharSetHdl, SvxTextEncodingBox* ); + DECL_LINK( RbSepFixHdl, RadioButton* ); + DECL_LINK( SeparatorHdl, Control* ); + DECL_LINK( LbColTypeHdl, ListBox* ); + DECL_LINK( UpdateTextHdl, ScCsvTableBox* ); + DECL_LINK( ColSelectHdl, ScCsvTableBox* ); }; +// ============================================================================ #endif - diff --git a/sc/source/ui/inc/csvcontrol.hxx b/sc/source/ui/inc/csvcontrol.hxx new file mode 100644 index 000000000000..1b5c57b0130a --- /dev/null +++ b/sc/source/ui/inc/csvcontrol.hxx @@ -0,0 +1,389 @@ +/************************************************************************* + * + * $RCSfile: csvcontrol.hxx,v $ + * + * $Revision: 1.1 $ + * + * last change: $Author: dr $ $Date: 2002-07-05 15:42:14 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +// ============================================================================ + +#ifndef _SC_CSVCONTROL_HXX +#define _SC_CSVCONTROL_HXX + +#ifndef _SV_CTRL_HXX +#include <vcl/ctrl.hxx> +#endif + +#ifndef _SC_CSVSPLITS_HXX +#include "csvsplits.hxx" +#endif + + +// ============================================================================ + +/** Specifies which element should be used to perform an action. */ +enum ScMoveMode +{ + MOVE_NONE, /// No action. + MOVE_FIRST, /// First element in current context. + MOVE_LAST, /// Last element in current context. + MOVE_PREV, /// Predecessor of current element in current context. + MOVE_NEXT, /// Successor of current element in current context. + MOVE_PREVPAGE, /// Previous page relative to current context. + MOVE_NEXTPAGE /// Next page relative to current context. +}; + + +// ============================================================================ + +/** A structure containing all layout data valid for both ruler and data grid + (i.e. scroll position or column width). */ +struct ScCsvLayoutData +{ + // horizontal settings + sal_Int32 mnPosCount; /// Number of positions. + sal_Int32 mnPosOffset; /// Horizontal scroll offset. + + sal_Int32 mnWinWidth; /// Width of ruler and data grid. + sal_Int32 mnOffsetX; /// X coordinate of first visible position. + sal_Int32 mnCharWidth; /// Pixel width of one character. + + // vertical settings + sal_Int32 mnLineCount; /// Number of data lines. + sal_Int32 mnLineOffset; /// Index of first visible line (0-based). + + sal_Int32 mnWinHeight; /// Height of entire data grid (incl. header). + sal_Int32 mnOffsetY; /// Y coordinate of first visible line. + sal_Int32 mnLineHeight; /// Height of one line. + + // cursor settings + sal_Int32 mnPosCursor; /// Position of ruler cursor. + sal_Int32 mnColCursor; /// Position of grid column cursor. + + mutable sal_Int32 mnNoRepaint; /// >0 = no repaint. + + ScCsvLayoutData(); + + /** Returns true, if horizontal settings in rData are equal. */ + bool IsHorzEqual( const ScCsvLayoutData& rData ) const; + /** Returns true, if vertical settings in rData are equal. */ + bool IsVertEqual( const ScCsvLayoutData& rData ) const; + /** Returns true, if cursor settings in rData are equal. */ + bool IsCursorEqual( const ScCsvLayoutData& rData ) const; +}; + +bool operator==( const ScCsvLayoutData& rData1, const ScCsvLayoutData& rData2 ); +inline bool operator!=( const ScCsvLayoutData& rData1, const ScCsvLayoutData& rData2 ) +{ + return !(rData1 == rData2); +} + + +// ============================================================================ + +/** Enumeration of possible requests of the controls. + @descr Controls have to send requests to be able to change the tablebox global settings. */ +enum ScCsvRequestType +{ + CSVREQ_NONE, /// No request. + + // misc + CSVREQ_REPAINT, /// Repaint all controls. + CSVREQ_NEWCELLTEXTS, /// Recalculate splits and cell texts. + CSVREQ_UPDATECELLTEXTS, /// Update cell texts with current split settings. + CSVREQ_COLUMNTYPE, /// Change data type of selected columns. + + // modify horizontal dimensions + CSVREQ_POSCOUNT, /// Change position/column count. + CSVREQ_POSOFFSET, /// Change position offset (scroll pos). + CSVREQ_OFFSETX, /// Change X coordinate of first visible position. + CSVREQ_CHARWIDTH, /// Change character pixel width. + + // modify vertical dimensions + CSVREQ_LINECOUNT, /// Change number of data lines. + CSVREQ_LINEOFFSET, /// Change first visible line. + CSVREQ_OFFSETY, /// Change Y coordinate of first visible line. + CSVREQ_LINEHEIGHT, /// Change data line pixel height. + + // cursors + CSVREQ_MOVERULERCURSOR, /// Move ruler cursor to new position. + CSVREQ_MOVEGRIDCURSOR /// Move data grid cursor to new column. +}; + + +// ---------------------------------------------------------------------------- + +/** Data for a CSV control request. */ +class ScCsvRequest +{ +private: + ScCsvRequestType meType; /// Type of the request. + sal_Int32 mnData; /// Signed position data. + +public: + inline ScCsvRequest() : meType( CSVREQ_NONE ), mnData( POS_INVALID ) {} + + inline void Set( ScCsvRequestType eType, sal_Int32 nData ); + + inline ScCsvRequestType GetType() const { return meType; } + inline sal_Int32 GetData() const { return mnData; } +}; + +inline void ScCsvRequest::Set( ScCsvRequestType eType, sal_Int32 nData ) +{ + meType = eType; + mnData = nData; +} + + +// ============================================================================ + +/** Enumeration of possible events of the controls. + @descr Controls send events after they have changed their own data. */ +enum ScCsvEventType +{ + CSVEVENT_NONE, /// No action. + + // ruler events + RULEREVENT_INSERT, /// Split inserted. + RULEREVENT_REMOVE, /// Split removed. + RULEREVENT_MOVE, /// Split moved. + RULEREVENT_REMOVEALL, /// All splits removed. + + // grid events + GRIDEVENT_SELECTION, /// Column selection changed. + GRIDEVENT_COLUMNTYPE /// Column type changed. +}; + + +// ---------------------------------------------------------------------------- + +/** Data for a CSV control event. */ +class ScCsvEvent +{ +private: + ScCsvEventType meType; /// Type of the event. + sal_Int32 mnPos; /// Reference position of the event. + sal_Int32 mnOldPos; /// Old position (i.e. for split move). + +public: + inline ScCsvEvent() : meType( CSVEVENT_NONE ), + mnPos( POS_INVALID ), mnOldPos( POS_INVALID ) {} + + inline void Set( ScCsvEventType eType, sal_Int32 nPos, sal_Int32 nOldPos ); + + inline ScCsvEventType GetType() const { return meType; } + inline sal_Int32 GetPos() const { return mnPos; } + inline sal_Int32 GetOldPos() const { return mnOldPos; } +}; + +inline void ScCsvEvent::Set( ScCsvEventType eType, sal_Int32 nPos, sal_Int32 nOldPos ) +{ + meType = eType; + mnPos = nPos; + mnOldPos = nOldPos; +} + + +// ============================================================================ + +const sal_Int32 SCROLL_DIST = 3; /// Minimum distance to border for auto scroll. + + +// ---------------------------------------------------------------------------- + +/** Base class for the CSV ruler and the data grid control. Implements event handling. */ +class ScCsvControl : public Control +{ +private: + Link maRequestHdl; /// External request handler. + Link maEventHdl; /// External event handler. + + ScCsvRequest maRequest; /// Data of last request. + ScCsvEvent maEvent; /// Data of last event. + + const ScCsvLayoutData& mrData; /// Shared layout data. + + bool mbValidGfx; /// Content of virtual devices valid? + + // ------------------------------------------------------------------------ +public: + ScCsvControl( ScCsvControl& rParent ); + ScCsvControl( Window* pParent, const ScCsvLayoutData& rData, WinBits nStyle = 0 ); + ScCsvControl( Window* pParent, const ScCsvLayoutData& rData, const ResId& rResId ); + + // drawing ---------------------------------------------------------------- + + /** Sets the graphic invalid (next Redraw() will not use cached graphic). */ + inline void InvalidateGfx() { mbValidGfx = false; } + /** Sets the graphic valid (next Redraw() will use cached graphic). */ + inline void ValidateGfx() { mbValidGfx = true; } + /** Returns true, if cached graphic is valid. */ + inline bool IsValidGfx() const { return mbValidGfx; } + + /** Commits repaint request. + @param bInvalidate true = invalidates graphics of this control. */ + void Repaint( bool bInvalidate = false ); + /** Increases no-repaint counter (control does not repaint until the last EnableRepaint()). */ + void DisableRepaint(); + /** Decreases no-repaint counter and repaints if counter reaches 0. + @param bInvalidate true = invalidates graphics of this control. */ + void EnableRepaint( bool bInvalidate = false ); + /** Returns true, if control will not repaint. */ + inline bool IsNoRepaint() const { return mrData.mnNoRepaint > 0; } + + /** Inverts a rectangle in the specified output device. */ + void ImplInvertRect( OutputDevice& rOutDev, const Rectangle& rRect ); + + // event handling --------------------------------------------------------- + + /** Sets a new request handler. */ + inline void SetRequestHdl( const Link& rHdl ) { maRequestHdl = rHdl; } + /** Returns the current request handler. */ + inline const Link& GetRequestHdl() const { return maRequestHdl; } + /** Returns data of the last request. */ + inline const ScCsvRequest& GetRequest() const { return maRequest; } + /** Sets a request with position data and calls request handler. */ + void CommitRequest( + ScCsvRequestType eType, + sal_Int32 nData = POS_INVALID ); + + /** Sets a new event handler. */ + inline void SetEventHdl( const Link& rHdl ) { maEventHdl = rHdl; } + /** Returns the current event handler. */ + inline const Link& GetEventHdl() const { return maEventHdl; } + /** Returns data of the last event. */ + inline const ScCsvEvent& GetEvent() const { return maEvent; } + /** Sets the data of the last event and calls event handler. */ + void CommitEvent( + ScCsvEventType eType, + sal_Int32 nPos = POS_INVALID, + sal_Int32 nOldPos = POS_INVALID ); + + // layout helpers --------------------------------------------------------- + + /** Returns a reference to the current layout data. */ + inline const ScCsvLayoutData& GetLayoutData() const { return mrData; } + + /** Returns the number of available positions. */ + inline sal_Int32 GetPosCount() const { return mrData.mnPosCount; } + /** Returns the number of visible positions. */ + sal_Int32 GetVisPosCount() const; + /** Returns the first visible position. */ + inline sal_Int32 GetFirstVisPos() const { return mrData.mnPosOffset; } + /** Returns the last visible position. */ + inline sal_Int32 GetLastVisPos() const { return GetFirstVisPos() + GetVisPosCount(); } + /** Returns highest possible position for first visible character. */ + sal_Int32 GetMaxPosOffset() const; + + /** Returns true, if it is allowed to set a split at nPos. */ + bool IsValidSplitPos( sal_Int32 nPos ) const; + /** Returns true, if nPos is an allowed AND visible split position. */ + bool IsVisibleSplitPos( sal_Int32 nPos ) const; + + /** Returns X coordinate of first visible position. */ + inline sal_Int32 GetOffsetX() const { return mrData.mnOffsetX; } + /** Returns the width of one character column. */ + inline sal_Int32 GetCharWidth() const { return mrData.mnCharWidth; } + /** Returns output X coordinate of the specified position. */ + sal_Int32 GetX( sal_Int32 nPos ) const; + /** Returns position from output coordinate. */ + sal_Int32 GetPosFromX( sal_Int32 nX ) const; + + /** Returns the number of data lines. */ + inline sal_Int32 GetLineCount() const { return mrData.mnLineCount; } + /** Returns the number of visible lines (including partly visible bottom line). */ + sal_Int32 GetVisLineCount() const; + /** Returns index of first visible line. */ + inline sal_Int32 GetFirstVisLine() const { return mrData.mnLineOffset; } + /** Returns index of last visible line. */ + sal_Int32 GetLastVisLine() const; + /** Returns highest possible index for first line. */ + sal_Int32 GetMaxLineOffset() const; + + /** Returns true, if nLine is a valid line index. */ + bool IsValidLine( sal_Int32 nLine ) const; + /** Returns true, if nLine is a valid and visible line index. */ + bool IsVisibleLine( sal_Int32 nLine ) const; + + /** Returns Y coordinate of first visible line. */ + inline sal_Int32 GetOffsetY() const { return mrData.mnOffsetY; } + /** Returns the height of one line. */ + inline sal_Int32 GetLineHeight() const { return mrData.mnLineHeight; } + /** Returns output Y coordinate of the specified line. */ + sal_Int32 GetY( sal_Int32 nLine ) const; + + /** Returns the ruler cursor position. */ + inline sal_Int32 GetRulerCursorPos() const { return mrData.mnPosCursor; } + /** Returns the data grid cursor position (not column index!). */ + inline sal_Int32 GetGridCursorPos() const { return mrData.mnColCursor; } + + // keyboard helpers ------------------------------------------------------- + + /** Returns direction code for the keys LEFT, RIGHT, HOME, END. + @return bHomeEnd true = Evaluate HOME and END key. */ + ScMoveMode GetHorzDirection( sal_uInt16 nCode, bool bHomeEnd ); + /** Returns direction code for the keys UP, DOWN, HOME, END, PAGE UP, PAGE DOWN. + @return bHomeEnd true = Evaluate HOME and END key. */ + ScMoveMode GetVertDirection( sal_uInt16 nCode, bool bHomeEnd ); +}; + + +// ============================================================================ + +#endif + diff --git a/sc/source/ui/inc/csvgrid.hxx b/sc/source/ui/inc/csvgrid.hxx new file mode 100644 index 000000000000..ccbeef3073bc --- /dev/null +++ b/sc/source/ui/inc/csvgrid.hxx @@ -0,0 +1,356 @@ +/************************************************************************* + * + * $RCSfile: csvgrid.hxx,v $ + * + * $Revision: 1.1 $ + * + * last change: $Author: dr $ $Date: 2002-07-05 15:42:15 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +// ============================================================================ + +#ifndef _SC_CSVGRID_HXX +#define _SC_CSVGRID_HXX + +#ifndef _SV_VIRDEV_HXX +#include <vcl/virdev.hxx> +#endif +#ifndef _MENU_HXX +#include <vcl/menu.hxx> +#endif +#ifndef _SFXLSTNER_HXX +#include <svtools/lstner.hxx> +#endif + +#include <vector> +#include <memory> + +#ifndef _SC_CSVCONTROL_HXX +#include "csvcontrol.hxx" +#endif +#ifndef _SC_CSVSPLITS_HXX +#include "csvsplits.hxx" +#endif + + +// ---------------------------------------------------------------------------- + +namespace svx { class ColorConfig; } +class ScEditEngineDefaulter; +class ScAsciiOptions; + +typedef ::std::vector< String > ScCsvStringVec; +typedef ::std::vector< ScCsvStringVec > ScCsvStringVecVec; +typedef ::std::vector< sal_Int32 > ScCsvColTypeVec; +typedef ::std::vector< sal_uInt8 > ScCsvColFlagsVec; + +typedef ::std::vector< xub_StrLen > ScCsvExtColPosVec; +typedef ::std::vector< sal_uInt8 > ScCsvExtColTypeVec; + + +// ---------------------------------------------------------------------------- + +/** Minimum character count for a column in separators mode. */ +const sal_Int32 CSV_MINCOLWIDTH = 5; +//! TODO make string array dynamic +const sal_Int32 CSV_PREVIEW_LINES = 32; // maximum count of preview lines + +/** Default column data type. */ +const sal_Int32 CSV_TYPE_DEFAULT = 0; +/** Multi selection with different types. */ +const sal_Int32 CSV_TYPE_MULTI = -1; +/** No column selected. */ +const sal_Int32 CSV_TYPE_NOSELECTION = -2; + +// External used column types. +const sal_uInt8 SC_COL_STANDARD = 1; +const sal_uInt8 SC_COL_TEXT = 2; +const sal_uInt8 SC_COL_MDY = 3; +const sal_uInt8 SC_COL_DMY = 4; +const sal_uInt8 SC_COL_YMD = 5; +const sal_uInt8 SC_COL_SKIP = 9; +const sal_uInt8 SC_COL_ENGLISH = 10; + + +// ============================================================================ + +/** A data grid control for the CSV import dialog. The design of this control + simulates a Calc spreadsheet with row and column headers. */ +class ScCsvGrid : public ScCsvControl, public SfxListener +{ +private: + typedef ::std::auto_ptr< ScEditEngineDefaulter > ScEditEnginePtr; + +private: + VirtualDevice maBackgrDev; /// Grid background, headers, cell texts. + VirtualDevice maGridDev; /// Data grid with selection and cursor. + PopupMenu maPopup; /// Popup menu for column types. + + ::svx::ColorConfig& mrColorConfig; /// Application color configuration. + Color maBackColor; /// Cell background color. + Color maGridColor; /// Table grid color. + Color maAppBackColor; /// Background color for unused area. + Color maTextColor; /// Text color for headers and data. + Color maHeaderBackColor; /// Background color for headers. + Color maHeaderGridColor; /// Grid color for headers. + Color maSelectColor; /// Header color of selected columns. + + ScEditEnginePtr mpEditEngine; /// For drawing cell texts. + Font maHeaderFont; /// Font for column and row headers. + Font maMonoFont; /// Monospace font for data cells. + Size maWinSize; /// Size of the control. + + ScCsvSplits maSplits; /// Vector with split positions. + ScCsvColTypeVec maColTypes; /// Data type of each column. + ScCsvColFlagsVec maColFlags; /// Flags for each column. + ScCsvStringVec maTypeNames; /// UI names of data types. + ScCsvStringVecVec maTexts; /// 2D-vector for cell texts. + + sal_uInt32 mnRecentSelCol; /// Index of most recently selected column. + + // ------------------------------------------------------------------------ +public: + ScCsvGrid( ScCsvControl& rParent ); + virtual ~ScCsvGrid(); + + // grid handling ---------------------------------------------------------- + + /** Redraws the entire data grid. */ + void ImplRedraw(); + + /** Updates layout data dependent from the control's state. */ + void UpdateLayoutData(); + /** Updates X coordinate of first visible position dependent from line numbers. */ + void UpdateOffsetX(); + /** Apply current layout data to the grid control. */ + void ApplyLayout( const ScCsvLayoutData& rOldData ); + + /** Finds a column position nearest to nPos which does not cause scrolling the visible area. */ + sal_Int32 GetNoScrollCol( sal_Int32 nPos ) const; + + /** Inserts a split. */ + void InsertSplit( sal_Int32 nPos ); + /** Removes a split. */ + void RemoveSplit( sal_Int32 nPos ); + /** Moves a split from nPos to nNewPos. */ + void MoveSplit( sal_Int32 nPos, sal_Int32 nNewPos ); + /** Removes all splits. */ + void RemoveAllSplits(); + /** Removes all splits and inserts the splits from rSplits. */ + void SetSplits( const ScCsvSplits& rSplits ); + + /** Returns the vector with the data types of all columns. */ + inline const ScCsvColTypeVec& GetColumnTypes() const { return maColTypes; } + /** Sets all column data types to the values in the passed vector. */ + void SetColumnTypes( const ScCsvColTypeVec& rColTypes ); + /** Returns the data type of the selected columns (or -1, if different types are selected). */ + sal_Int32 GetSelColumnType() const; + /** Changes the data type of all selected columns. */ + void SetSelColumnType( sal_Int32 nType ); + /** Sets new UI data type names. */ + void SetTypeNames( const ScCsvStringVec& rTypeNames ); + + /** Fills all cells of a line with the passed text (separators mode). */ + void ImplSetTextLineSep( + sal_Int32 nLine, const String& rTextLine, + const String& rSepChars, sal_Unicode cTextSep, bool bMergeSep ); + /** Fills all cells of a line with the passed text (fixed width mode). */ + void ImplSetTextLineFix( sal_Int32 nLine, const String& rTextLine ); + + /** Fills the options object with column data for separators mode. */ + void FillColumnDataSep( ScAsciiOptions& rOptions ) const; + /** Fills the options object with column data for fixed width mode. */ + void FillColumnDataFix( ScAsciiOptions& rOptions ) const; + + // event handling --------------------------------------------------------- +protected: + virtual void Resize(); + virtual void GetFocus(); + virtual void LoseFocus(); + + virtual void MouseButtonDown( const MouseEvent& rMEvt ); + virtual void KeyInput( const KeyEvent& rKEvt ); + virtual void Command( const CommandEvent& rCEvt ); + + virtual void DataChanged( const DataChangedEvent& rDCEvt ); + virtual void Notify( SfxBroadcaster& rBC, const SfxHint& rHint ); + + // initialization --------------------------------------------------------- +private: + /** Reads colors from system settings. */ + void InitColors(); + /** Initializes all font settings. */ + void InitFonts(); + /** Initializes all data dependent from the control's size. */ + void InitSizeData(); + + // grid handling ---------------------------------------------------------- + + /** Inserts a split and adjusts column data. */ + bool ImplInsertSplit( sal_Int32 nPos ); + /** Removes a split and adjusts column data. */ + bool ImplRemoveSplit( sal_Int32 nPos ); + /** Clears the split array and re-inserts boundary splits. */ + void ImplClearSplits(); + + /** Returns the number of columns. */ + inline sal_uInt32 GetColumnCount() const { return maColTypes.size(); } + /** Returns start position of the column with the specified index. */ + inline sal_Int32 GetColumnPos( sal_uInt32 nColIndex ) const { return maSplits[ nColIndex ]; } + /** Returns the character width of the column with the specified index. */ + sal_Int32 GetColumnWidth( sal_uInt32 nColIndex ) const; + /** Returns column index from position. A split counts to its following column. */ + sal_uInt32 GetColumnFromPos( sal_Int32 nPos ) const; + /** Returns the index of the first visible column. */ + sal_uInt32 GetFirstVisColumn() const; + /** Returns the index of the last visible column. */ + sal_uInt32 GetLastVisColumn() const; + + /** Returns true, if nColIndex points to an existing column. */ + bool IsValidColumn( sal_uInt32 nColIndex ) const; + /** Returns true, if column with index nColIndex is (at least partly) visible. */ + bool IsVisibleColumn( sal_uInt32 nColIndex ) const; + + /** Returns X coordinate of the specified column. */ + sal_Int32 GetColumnX( sal_uInt32 nColIndex ) const; + /** Returns column index from output coordinate. */ + sal_uInt32 GetColumnFromX( sal_Int32 nX ) const; + + /** Returns the data type of the specified column. */ + sal_Int32 GetColumnType( sal_uInt32 nColIndex ) const; + /** Returns the data type of the specified column. */ + void SetColumnType( sal_uInt32 nColIndex, sal_Int32 nColType ); + /** Returns the UI type name of the specified column. */ + const String& GetColumnTypeName( sal_uInt32 nColIndex ) const; + + /** Scrolls data grid vertically. */ + void ScrollVertRel( ScMoveMode eDir ); + /** Executes the data type popup menu. */ + void ExecutePopup( const Point& rPos ); + + // selection handling ----------------------------------------------------- + + /** Returns index of the focused column. */ + inline sal_uInt32 GetFocusColumn() const { return GetColumnFromPos( GetGridCursorPos() ); } + /** Moves column cursor to a new position. */ + void MoveCursor( sal_uInt32 nColIndex ); + /** Moves column cursor to the given direction. */ + void MoveCursorRel( ScMoveMode eDir ); + + /** Clears the entire selection without notify. */ + void ImplClearSelection(); + + /** Returns true, if the specified column is selected. */ + bool IsSelected( sal_uInt32 nColIndex ) const; + /** Returns index of the first selected column. */ + sal_uInt32 GetFirstSelected() const; + /** Returns index of the first selected column really after nFromIndex. */ + sal_uInt32 GetNextSelected( sal_uInt32 nFromIndex ) const; + /** Returns true, if at least one column is selected. */ + inline bool HasSelection() const { return GetFirstSelected() != VEC_NOTFOUND; } + + /** Selects or deselects the specified column. */ + void Select( sal_uInt32 nColIndex, bool bSelect = true ); + /** Toggles selection of the specified column. */ + void ToggleSelect( sal_uInt32 nColIndex ); + /** Selects or deselects the specified column range. */ + void SelectRange( sal_uInt32 nColIndex1, sal_uInt32 nColIndex2, bool bSelect = true ); + /** Selects all columns. */ + void SelectAll(); + + // painting --------------------------------------------------------------- +protected: + virtual void Paint( const Rectangle& ); + +private: + /** Returns the width of the control. */ + inline sal_Int32 GetWidth() const { return maWinSize.Width(); } + /** Returns the height of the control. */ + inline sal_Int32 GetHeight() const { return maWinSize.Height(); } + + /** Sets a clip region in the specified output device for the specified column. */ + void ImplSetColumnClipRegion( OutputDevice& rOutDev, sal_uInt32 nColIndex ); + /** Draws the header of the specified column to the specified output device. */ + void ImplDrawColumnHeader( OutputDevice& rOutDev, sal_uInt32 nColIndex, Color aFillColor ); + + /** Draws the column with index nColIndex to maBackgrDev. */ + void ImplDrawColumnBackgr( sal_uInt32 nColIndex ); + /** Draws the row headers column to maBackgrDev. */ + void ImplDrawRowHeaders(); + /** Draws all columns and the row headers column to maBackgrDev. */ + void ImplDrawBackgrDev(); + + /** Draws the column with index nColIndex with its selection state to maGridDev. */ + void ImplDrawColumnSelection( sal_uInt32 nColIndex ); + /** Draws all columns with selection and cursor to maGridDev. */ + void ImplDrawGridDev(); + + /** Redraws the entire column (background and selection). */ + void ImplDrawColumn( sal_uInt32 nColIndex ); + + /** Draws the cursor bar to the specified position to maGridDev. */ + void ImplDrawCursor( sal_Int32 nPos ); + /** Erases the cursor bar from the specified position from maGridDev. */ + inline void ImplEraseCursor( sal_Int32 nPos ) { ImplDrawCursor( nPos ); } + + /** Draws directly tracking rectangle to the column with the specified index. */ + void ImplDrawTrackingRect( sal_uInt32 nColIndex ); +}; + + +// ============================================================================ + +#endif + diff --git a/sc/source/ui/inc/csvruler.hxx b/sc/source/ui/inc/csvruler.hxx new file mode 100644 index 000000000000..83fc02d3b833 --- /dev/null +++ b/sc/source/ui/inc/csvruler.hxx @@ -0,0 +1,238 @@ +/************************************************************************* + * + * $RCSfile: csvruler.hxx,v $ + * + * $Revision: 1.1 $ + * + * last change: $Author: dr $ $Date: 2002-07-05 15:42:16 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +// ============================================================================ + +#ifndef _SC_CSVRULER_HXX +#define _SC_CSVRULER_HXX + +#ifndef _SV_VIRDEV_HXX +#include <vcl/virdev.hxx> +#endif + +#ifndef _SC_CSVCONTROL_HXX +#include "csvcontrol.hxx" +#endif +#ifndef _SC_CSVSPLITS_HXX +#include "csvsplits.hxx" +#endif + + +// ============================================================================ + +/** A ruler control for the CSV import dialog. Supports setting and moving + splits (which divide lines of data into several columns). */ +class ScCsvRuler : public ScCsvControl +{ +private: + VirtualDevice maBackgrDev; /// Ruler background, scaling. + VirtualDevice maRulerDev; /// Ruler with splits and cursor. + + Color maBackColor; /// Background color. + Color maActiveColor; /// Color for active part of ruler. + Color maTextColor; /// Text and scale color. + Color maSplitColor; /// Split area color. + + ScCsvSplits maSplits; /// Vector with split positions. + ScCsvSplits maOldSplits; /// Old state for cancellation. + + sal_Int32 mnPosCursorLast; /// Last valid position of cursor. + sal_Int32 mnPosMTStart; /// Start position of mouse tracking. + sal_Int32 mnPosMTCurr; /// Current position of mouse tracking. + bool mbPosMTMoved; /// Tracking: Anytime moved to another position? + + Size maWinSize; /// Size of the control. + Rectangle maActiveRect; /// The active area of the ruler. + sal_Int32 mnSplitSize; /// Size of a split circle. + + // ------------------------------------------------------------------------ +public: + ScCsvRuler( ScCsvControl& rParent ); + + // ruler handling --------------------------------------------------------- + + /** Redraws the entire ruler. */ + void ImplRedraw(); + + /** Sets position and size of the ruler. The height is calculated internally. */ + virtual void SetPosSizePixel( + sal_Int32 nX, sal_Int32 nY, + sal_Int32 nWidth, sal_Int32 nHeight, + sal_uInt16 nFlags = WINDOW_POSSIZE_ALL ); + + /** Apply current layout data to the ruler. */ + void ApplyLayout( const ScCsvLayoutData& rOldData ); + + /** Returns the split array. */ + inline const ScCsvSplits& GetSplits() const { return maSplits; } + /** Returns the number of splits. */ + inline sal_uInt32 GetSplitCount() const + { return maSplits.Count(); } + /** Returns the position of the specified split. */ + inline sal_Int32 GetSplitPos( sal_uInt32 nIndex ) const + { return maSplits[ nIndex ]; } + /** Finds a position nearest to nPos which does not cause scrolling the visible area. */ + sal_Int32 GetNoScrollPos( sal_Int32 nPos ) const; + + /** Returns true if at position nPos is a split. */ + inline bool HasSplit( sal_Int32 nPos ) const { return maSplits.HasSplit( nPos ); } + /** Inserts a split and commits event. */ + void InsertSplit( sal_Int32 nPos ); + /** Removes a split and commits event. */ + void RemoveSplit( sal_Int32 nPos ); + /** Inserts a new or removes an existing split and commits event. */ + void ToggleSplit( sal_Int32 nPos ); + /** Moves a split from nPos to nNewPos and commits event. */ + void MoveSplit( sal_Int32 nPos, sal_Int32 nNewPos ); + /** Moves the split from nPos to the given direction and commits event. */ + void MoveSplitRel( sal_Int32 nPos, ScMoveMode eDir ); + /** Removes all splits of the ruler and commits event. */ + void RemoveAllSplits(); + + // event handling --------------------------------------------------------- +protected: + virtual void Resize(); + virtual void GetFocus(); + virtual void LoseFocus(); + virtual void DataChanged( const DataChangedEvent& rDCEvt ); + + virtual void MouseButtonDown( const MouseEvent& rMEvt ); + virtual void MouseMove( const MouseEvent& rMEvt ); + virtual void Tracking( const TrackingEvent& rTEvt ); + + virtual void KeyInput( const KeyEvent& rKEvt ); + + // initialization --------------------------------------------------------- +private: + /** Reads colors from system settings. */ + void InitColors(); + /** Initializes all data dependent from the control's size. */ + void InitSizeData(); + + // ruler handling --------------------------------------------------------- + + /** Returns the height the ruler needs to draw itself. */ + sal_Int32 GetRequiredHeight() const; + + /** Finds next position without a split. */ + sal_Int32 FindEmptyPos( sal_Int32 nPos, ScMoveMode eDir ) const; + + /** Moves cursor to a new position. + @param bScroll TRUE = The method may scroll the ruler. */ + void MoveCursor( sal_Int32 nPos, bool bScroll = true ); + /** Moves cursor to the given direction. */ + void MoveCursorRel( ScMoveMode eDir ); + /** Sets cursor to an existing split, according to eDir. */ + void MoveCursorToSplit( ScMoveMode eDir ); + /** Scrolls data grid vertically. */ + void ScrollVertRel( ScMoveMode eDir ); + + /** Moves split and cursor to nNewPos and commits event. */ + void MoveCurrSplit( sal_Int32 nNewPos ); + /** Moves split and cursor to the given direction and commits event. */ + void MoveCurrSplitRel( ScMoveMode eDir ); + + /** Starts tracking at the specified position. */ + void StartMouseTracking( sal_Int32 nPos ); + /** Moves tracking to a new position. */ + void MoveMouseTracking( sal_Int32 nPos ); + /** Applies tracking action for the current tracking position. + @param bApply TRUE = apply action, FALSE = cancel action. */ + void EndMouseTracking( bool bApply ); + + // painting --------------------------------------------------------------- +protected: + virtual void Paint( const Rectangle& ); + +private: + /** Returns the width of the control. */ + inline sal_Int32 GetWidth() const { return maWinSize.Width(); } + /** Returns the height of the control. */ + inline sal_Int32 GetHeight() const { return maWinSize.Height(); } + + /** Draws the background and active area to maBackgrDev (only the given X range). */ + void ImplDrawArea( sal_Int32 nPosX, sal_Int32 nWidth ); + /** Draws the entire ruler background with scaling to maBackgrDev. */ + void ImplDrawBackgrDev(); + + /** Draws a split to maRulerDev. */ + void ImplDrawSplit( sal_Int32 nPos ); + /** Erases a split from maRulerDev. */ + void ImplEraseSplit( sal_Int32 nPos ); + /** Draws the ruler background, all splits and the cursor to maRulerDev. */ + void ImplDrawRulerDev(); + + /** Draws the cursor bar to the specified position to maRulerDev. */ + void ImplDrawCursor( sal_Int32 nPos ); + /** Erases the cursor bar from the specified position from maRulerDev. */ + inline void ImplEraseCursor( sal_Int32 nPos ) { ImplDrawCursor( nPos ); } + /** Draws directly tracking rectangle to the column with the specified index. */ + void ImplDrawTrackingRect(); + + /** Sets arrow or horizontal split pointer. */ + void ImplSetMousePointer( sal_Int32 nPos ); +}; + + +// ============================================================================ + +#endif + diff --git a/sc/source/ui/inc/csvsplits.hxx b/sc/source/ui/inc/csvsplits.hxx new file mode 100644 index 000000000000..4b483dde09eb --- /dev/null +++ b/sc/source/ui/inc/csvsplits.hxx @@ -0,0 +1,139 @@ +/************************************************************************* + * + * $RCSfile: csvsplits.hxx,v $ + * + * $Revision: 1.1 $ + * + * last change: $Author: dr $ $Date: 2002-07-05 15:42:18 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +// ============================================================================ + +#ifndef _SC_CSVSPLITS_HXX +#define _SC_CSVSPLITS_HXX + +#ifndef _SAL_TYPES_H_ +#include <sal/types.h> +#endif + +#include <vector> + + +// ============================================================================ + +/** Constant for an invalid vector index. */ +const sal_uInt32 VEC_NOTFOUND = ~0UL; +/** Constant for an invalid ruler position. */ +const sal_Int32 POS_INVALID = -1; + + +// ---------------------------------------------------------------------------- + +/** A vector of column splits that supports inserting, removing and moving splits. */ +class ScCsvSplits +{ +private: + typedef ::std::vector< sal_Int32 > ScSplitVector; + typedef ScSplitVector::iterator iterator; + typedef ScSplitVector::const_iterator const_iterator; + + ScSplitVector maVec; /// The split containter. + +public: + // *** access by position *** --------------------------------------------- + + /** Inserts a new split at position nPos into the vector. + @return true = split inserted (nPos was valid and empty). */ + bool Insert( sal_Int32 nPos ); + /** Removes a split by position. + @return true = split found and removed. */ + bool Remove( sal_Int32 nPos ); + /** Removes a range of splits in the given position range. */ + void RemoveRange( sal_Int32 nPosStart, sal_Int32 nPosEnd ); + /** Removes all elements from the vector. */ + void Clear(); + + /** Returns true if at position nPos is a split. */ + bool HasSplit( sal_Int32 nPos ) const; + + // *** access by index *** ------------------------------------------------ + + /** Searches for a split at position nPos. + @return the vector index of the split. */ + sal_uInt32 GetIndex( sal_Int32 nPos ) const; + /** Returns index of the first split greater than or equal to nPos. */ + sal_uInt32 LowerBound( sal_Int32 nPos ) const; + /** Returns index of the last split less than or equal to nPos. */ + sal_uInt32 UpperBound( sal_Int32 nPos ) const; + + /** Returns the number of splits. */ + inline sal_uInt32 Count() const + { return maVec.size(); } + /** Returns the position of the specified split. */ + sal_Int32 GetPos( sal_uInt32 nIndex ) const; + /** Returns the position of the specified split. */ + inline sal_Int32 operator[]( sal_uInt32 nIndex ) const + { return GetPos( nIndex ); } + +private: + /** Returns the vector index of an iterator. */ + sal_uInt32 GetIterIndex( const_iterator aIter ) const; +}; + + +// ============================================================================ + +#endif + diff --git a/sc/source/ui/inc/csvtablebox.hxx b/sc/source/ui/inc/csvtablebox.hxx new file mode 100644 index 000000000000..78dbb9a79e06 --- /dev/null +++ b/sc/source/ui/inc/csvtablebox.hxx @@ -0,0 +1,201 @@ +/************************************************************************* + * + * $RCSfile: csvtablebox.hxx,v $ + * + * $Revision: 1.1 $ + * + * last change: $Author: dr $ $Date: 2002-07-05 15:42:19 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +// ============================================================================ + +#ifndef _SC_CSVTABLEBOX_HXX +#define _SC_CSVTABLEBOX_HXX + +#ifndef _SV_CTRL_HXX +#include <vcl/ctrl.hxx> +#endif +#ifndef _SV_SCRBAR_HXX +#include <vcl/scrbar.hxx> +#endif + +#ifndef _SC_CSVCONTROL_HXX +#include "csvcontrol.hxx" +#endif +#ifndef _SC_CSVRULER_HXX +#include "csvruler.hxx" +#endif +#ifndef _SC_CSVGRID_HXX +#include "csvgrid.hxx" +#endif + + +// ---------------------------------------------------------------------------- + +class ListBox; +class ScAsciiOptions; + + +/* ============================================================================ +Position: Positions between the characters (the dots in the ruler). +Character: The characters (the range from one position to the next). +Split: Positions which contain a split to divide characters into groups (columns). +Column: The range between two splits. +============================================================================ */ + +/** The control in the CSV import dialog that contains a ruler and a data grid + to visualize and modify the current import settings. */ +class ScCsvTableBox : public ScCsvControl +{ +private: + ScCsvLayoutData maData; /// Current layout data of the controls. + + ScCsvRuler maRuler; /// The ruler for fixed width mode. + ScCsvGrid maGrid; /// Calc-like data table for fixed width mode. + ScrollBar maHScroll; /// Horizontal scroll bar. + ScrollBar maVScroll; /// Vertical scroll bar. + ScrollBarBox maScrollBox; /// For the bottom right edge. + + Link maUpdateTextHdl; /// Updates all cell texts. + Link maColSelectHdl; /// Handler for changed column selection. + + ScCsvColTypeVec maFixColTypes; /// Column data types in fixed width mode. + ScCsvColTypeVec maSepColTypes; /// Column data types in separators mode. + + sal_Int32 mnSelColType; /// Cached data type of selected columns. + sal_Int32 mnFixedWidth; /// Cached total width for fixed width mode. + + bool mbFixedMode; /// false = Separators, true = Fixed width. + + // ------------------------------------------------------------------------ +public: + ScCsvTableBox( Window* pParent ); + ScCsvTableBox( Window* pParent, const ResId& rResId ); + + // initialization --------------------------------------------------------- + + /** Reads UI strings for data types from the list box. */ + void InitTypes( const ListBox& rListBox ); + + /** Sets a new handler for "update cell texts" requests. */ + inline void SetUpdateTextHdl( const Link& rHdl ) { maUpdateTextHdl = rHdl; } + /** Returns the handler for "update cell texts" requests. */ + inline const Link& GetUpdateTextHdl() const { return maUpdateTextHdl; } + /** Sets a new handler for "column selection changed" events. */ + inline void SetColSelectHdl( const Link& rHdl ) { maColSelectHdl = rHdl; } + /** Returns the handler for "column selection changed" events. */ + inline const Link& GetColSelectHdl() const { return maColSelectHdl; } + + // control handling ------------------------------------------------------- + + /** Sets the control to separators mode. */ + void SetSeparatorsMode(); + /** Sets the control to fixed width mode. */ + void SetFixedWidthMode(); + + /** Returns the data type of the selected columns (or -1, if different types are selected). */ + inline sal_Int32 GetSelColumnType() const { return mnSelColType; } + + /** Fills all cells of all lines with the passed texts (Unicode strings). */ + void SetUniStrings( + const String* pTextLines, const String& rSepChars, + sal_Unicode cTextSep, bool bMergeSep ); + /** Fills all cells of all lines with the passed texts (ByteStrings). */ + void SetByteStrings( + const ByteString* pLineTexts, CharSet eCharSet, + const String& rSepChars, sal_Unicode cTextSep, bool bMergeSep ); + + /** Fills the options object with current column data. */ + void FillColumnData( ScAsciiOptions& rOptions ) const; + + // event handling --------------------------------------------------------- +protected: + virtual void Resize(); + virtual void DataChanged( const DataChangedEvent& rDCEvt ); + + // initialization --------------------------------------------------------- +private: + /** Initialisation on construction. */ + void Init(); + /** Initializes the children controls (pos/size, scroll bars, ...). */ + void InitControls(); + /** Initializes size and position data of horizontal scrollbar. */ + void InitHScrollBar(); + /** Initializes size and position data of vertical scrollbar. */ + void InitVScrollBar(); + + // control handling ------------------------------------------------------- + + /** Calculates and sets valid position offset nearest to nPos. */ + inline void ImplSetPosOffset( sal_Int32 nPos ) + { maData.mnPosOffset = Max( Min( nPos, GetMaxPosOffset() ), 0L ); } + /** Calculates and sets valid line offset nearest to nLine. */ + inline void ImplSetLineOffset( sal_Int32 nLine ) + { maData.mnLineOffset = Max( Min( nLine, GetMaxLineOffset() ), 0L ); } + + // event handling --------------------------------------------------------- + + DECL_LINK( CsvEventHdl, ScCsvControl* ); + DECL_LINK( CsvRequestHdl, ScCsvControl* ); + + DECL_LINK( ScrollHdl, ScrollBar* ); + DECL_LINK( ScrollEndHdl, ScrollBar* ); +}; + + +// ============================================================================ + +#endif + |