update dev300-m58
[ooovba.git] / sc / source / ui / inc / csvcontrol.hxx
blob85aa7770e7d5a7c20adf675f7131cedad542be35
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: csvcontrol.hxx,v $
10 * $Revision: 1.15 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // ============================================================================
33 #ifndef _SC_CSVCONTROL_HXX
34 #define _SC_CSVCONTROL_HXX
36 #include <vcl/ctrl.hxx>
37 #include "scdllapi.h"
38 #include "global.hxx"
39 #include "address.hxx"
40 #include "csvsplits.hxx"
41 #include <com/sun/star/uno/Reference.hxx>
44 class ScAccessibleCsvControl;
45 namespace com { namespace sun { namespace star { namespace accessibility {
46 class XAccessible;
47 } } } }
50 // ============================================================================
52 /** Minimum character count for a column in separators mode. */
53 const sal_Int32 CSV_MINCOLWIDTH = 8;
54 /** Maximum length of a cell string. */
55 const xub_StrLen CSV_MAXSTRLEN = 0x7FFF;
56 /** Transparency for header color of selected columns. */
57 const sal_uInt16 CSV_HDR_TRANSPARENCY = 85;
58 /** Minimum distance to border for auto scroll. */
59 const sal_Int32 CSV_SCROLL_DIST = 3;
61 //! TODO make string array dynamic
62 const sal_Int32 CSV_PREVIEW_LINES = 32; // maximum count of preview lines
63 /** Maximum count of columns. */
64 const sal_Int32 CSV_MAXCOLCOUNT = MAXCOLCOUNT;
66 /** Default column data type. */
67 const sal_Int32 CSV_TYPE_DEFAULT = 0;
68 /** Multi selection with different types. */
69 const sal_Int32 CSV_TYPE_MULTI = -1;
70 /** No column selected. */
71 const sal_Int32 CSV_TYPE_NOSELECTION = -2;
73 // External used column types.
74 const sal_uInt8 SC_COL_STANDARD = 1;
75 const sal_uInt8 SC_COL_TEXT = 2;
76 const sal_uInt8 SC_COL_MDY = 3;
77 const sal_uInt8 SC_COL_DMY = 4;
78 const sal_uInt8 SC_COL_YMD = 5;
79 const sal_uInt8 SC_COL_SKIP = 9;
80 const sal_uInt8 SC_COL_ENGLISH = 10;
83 // ============================================================================
85 /** Exported data of a column (data used in the dialog). */
86 struct ScCsvExpData
88 xub_StrLen mnIndex; /// Index of a column.
89 sal_uInt8 mnType; /// External type of the column.
91 inline ScCsvExpData() : mnIndex( 0 ), mnType( SC_COL_STANDARD ) {}
92 inline ScCsvExpData( xub_StrLen nIndex, sal_uInt8 nType ) :
93 mnIndex( nIndex ), mnType( nType ) {}
96 typedef ::std::vector< ScCsvExpData > ScCsvExpDataVec;
99 // ============================================================================
101 /** Specifies which element should be used to perform an action. */
102 enum ScMoveMode
104 MOVE_NONE, /// No action.
105 MOVE_FIRST, /// First element in current context.
106 MOVE_LAST, /// Last element in current context.
107 MOVE_PREV, /// Predecessor of current element in current context.
108 MOVE_NEXT, /// Successor of current element in current context.
109 MOVE_PREVPAGE, /// Previous page relative to current context.
110 MOVE_NEXTPAGE /// Next page relative to current context.
114 // ============================================================================
116 /** Flags for comparison of old and new control layout data. */
117 typedef sal_uInt32 ScCsvDiff;
119 const ScCsvDiff CSV_DIFF_EQUAL = 0x00000000;
120 const ScCsvDiff CSV_DIFF_POSCOUNT = 0x00000001;
121 const ScCsvDiff CSV_DIFF_POSOFFSET = 0x00000002;
122 const ScCsvDiff CSV_DIFF_HDRWIDTH = 0x00000004;
123 const ScCsvDiff CSV_DIFF_CHARWIDTH = 0x00000008;
124 const ScCsvDiff CSV_DIFF_LINECOUNT = 0x00000010;
125 const ScCsvDiff CSV_DIFF_LINEOFFSET = 0x00000020;
126 const ScCsvDiff CSV_DIFF_HDRHEIGHT = 0x00000040;
127 const ScCsvDiff CSV_DIFF_LINEHEIGHT = 0x00000080;
128 const ScCsvDiff CSV_DIFF_RULERCURSOR = 0x00000100;
129 const ScCsvDiff CSV_DIFF_GRIDCURSOR = 0x00000200;
131 const ScCsvDiff CSV_DIFF_HORIZONTAL = CSV_DIFF_POSCOUNT | CSV_DIFF_POSOFFSET | CSV_DIFF_HDRWIDTH | CSV_DIFF_CHARWIDTH;
132 const ScCsvDiff CSV_DIFF_VERTICAL = CSV_DIFF_LINECOUNT | CSV_DIFF_LINEOFFSET | CSV_DIFF_HDRHEIGHT | CSV_DIFF_LINEHEIGHT;
133 const ScCsvDiff CSV_DIFF_CURSOR = CSV_DIFF_RULERCURSOR | CSV_DIFF_GRIDCURSOR;
136 // ----------------------------------------------------------------------------
138 /** A structure containing all layout data valid for both ruler and data grid
139 (i.e. scroll position or column width). */
140 struct ScCsvLayoutData
142 // horizontal settings
143 sal_Int32 mnPosCount; /// Number of positions.
144 sal_Int32 mnPosOffset; /// Horizontal scroll offset.
146 sal_Int32 mnWinWidth; /// Width of ruler and data grid.
147 sal_Int32 mnHdrWidth; /// Width of the header column.
148 sal_Int32 mnCharWidth; /// Pixel width of one character.
150 // vertical settings
151 sal_Int32 mnLineCount; /// Number of data lines.
152 sal_Int32 mnLineOffset; /// Index of first visible line (0-based).
154 sal_Int32 mnWinHeight; /// Height of entire data grid (incl. header).
155 sal_Int32 mnHdrHeight; /// Height of the header line.
156 sal_Int32 mnLineHeight; /// Height of a data line.
158 // cursor settings
159 sal_Int32 mnPosCursor; /// Position of ruler cursor.
160 sal_Int32 mnColCursor; /// Position of grid column cursor.
162 mutable sal_Int32 mnNoRepaint; /// >0 = no repaint.
163 bool mbAppRTL; /// true = application in RTL mode.
165 explicit ScCsvLayoutData();
167 /** Returns differences to rData.
168 @descr For each difference the appropriate bit is set in the returned value. */
169 ScCsvDiff GetDiff( const ScCsvLayoutData& rData ) const;
172 inline bool operator==( const ScCsvLayoutData& rData1, const ScCsvLayoutData& rData2 )
174 return rData1.GetDiff( rData2 ) == CSV_DIFF_EQUAL;
177 inline bool operator!=( const ScCsvLayoutData& rData1, const ScCsvLayoutData& rData2 )
179 return !(rData1 == rData2);
183 // ============================================================================
185 /** Enumeration of possible commands to change any settings of the CSV controls.
186 @descr Controls have to send commands instead of changing their settings directly.
187 This helps to keep the different controls consistent to each other.
188 A command can contain 0 to 2 sal_Int32 parameters. In the description of each
189 command the required parameters are swown in brackets. [-] means no parameter. */
190 enum ScCsvCmdType
192 // misc
193 CSVCMD_NONE, /// No command. [-]
194 CSVCMD_REPAINT, /// Repaint all controls. [-]
196 // modify horizontal dimensions
197 CSVCMD_SETPOSCOUNT, /// Change position/column count. [character count]
198 CSVCMD_SETPOSOFFSET, /// Change position offset (scroll pos). [position]
199 CSVCMD_SETHDRWIDTH, /// Change width of the header column. [width in pixel]
200 CSVCMD_SETCHARWIDTH, /// Change character pixel width. [width in pixel]
202 // modify vertical dimensions
203 CSVCMD_SETLINECOUNT, /// Change number of data lines. [line count]
204 CSVCMD_SETLINEOFFSET, /// Change first visible line. [line index]
205 CSVCMD_SETHDRHEIGHT, /// Change height of top header line. [height in pixel]
206 CSVCMD_SETLINEHEIGHT, /// Change data line pixel height. [height in pixel}
208 // cursors/positions
209 CSVCMD_MOVERULERCURSOR, /// Move ruler cursor to new position. [position]
210 CSVCMD_MOVEGRIDCURSOR, /// Move data grid cursor to new column. [position]
211 CSVCMD_MAKEPOSVISIBLE, /// Move to make passed position visible (for mouse tracking). [position]
213 // table contents
214 CSVCMD_NEWCELLTEXTS, /// Recalculate splits and cell texts. [-]
215 CSVCMD_UPDATECELLTEXTS, /// Update cell texts with current split settings. [-]
216 CSVCMD_SETCOLUMNTYPE, /// Change data type of selected columns. [column type]
217 CSVCMD_EXPORTCOLUMNTYPE, /// Send selected column type to external controls. [-]
218 CSVCMD_SETFIRSTIMPORTLINE, /// Set number of first imported line. [line index]
220 // splits
221 CSVCMD_INSERTSPLIT, /// Insert a split. [position]
222 CSVCMD_REMOVESPLIT, /// Remove a split. [position]
223 CSVCMD_TOGGLESPLIT, /// Inserts or removes a split. [position]
224 CSVCMD_MOVESPLIT, /// Move a split. [old position, new position]
225 CSVCMD_REMOVEALLSPLITS /// Remove all splits. [-]
229 // ----------------------------------------------------------------------------
231 /** Data for a CSV control command. The stored position data is aways character based,
232 it's never a column index (required for internal consistency). */
233 class ScCsvCmd
235 private:
236 ScCsvCmdType meType; /// The command.
237 sal_Int32 mnParam1; /// First parameter.
238 sal_Int32 mnParam2; /// Second parameter.
240 public:
241 inline explicit ScCsvCmd() : meType( CSVCMD_NONE ),
242 mnParam1( CSV_POS_INVALID ), mnParam2( CSV_POS_INVALID ) {}
244 inline void Set( ScCsvCmdType eType, sal_Int32 nParam1, sal_Int32 nParam2 );
246 inline ScCsvCmdType GetType() const { return meType; }
247 inline sal_Int32 GetParam1() const { return mnParam1; }
248 inline sal_Int32 GetParam2() const { return mnParam2; }
251 inline void ScCsvCmd::Set( ScCsvCmdType eType, sal_Int32 nParam1, sal_Int32 nParam2 )
253 meType = eType; mnParam1 = nParam1; mnParam2 = nParam2;
257 // ============================================================================
259 /** Base class for the CSV ruler and the data grid control. Implements command handling. */
260 class SC_DLLPUBLIC ScCsvControl : public Control
262 protected:
263 typedef ::std::vector< String > StringVec;
264 typedef ::std::vector< StringVec > StringVecVec;
266 typedef ::com::sun::star::uno::Reference<
267 ::com::sun::star::accessibility::XAccessible > XAccessibleRef;
269 private:
270 Link maCmdHdl; /// External command handler.
271 ScCsvCmd maCmd; /// Data of last command.
272 const ScCsvLayoutData& mrData; /// Shared layout data.
274 XAccessibleRef mxAccessible; /// The accessible object of the control.
275 ScAccessibleCsvControl* mpAccessible; /// Pointer to the accessible implementation object.
276 bool mbValidGfx; /// Content of virtual devices valid?
278 // ------------------------------------------------------------------------
279 public:
280 explicit ScCsvControl( ScCsvControl& rParent );
281 explicit ScCsvControl( Window* pParent, const ScCsvLayoutData& rData, WinBits nStyle = 0 );
282 explicit ScCsvControl( Window* pParent, const ScCsvLayoutData& rData, const ResId& rResId );
283 virtual ~ScCsvControl();
285 // event handling ---------------------------------------------------------
287 virtual void GetFocus();
288 virtual void LoseFocus();
290 /** Sends a GetFocus or LoseFocus event to the accessibility object. */
291 void AccSendFocusEvent( bool bFocused );
292 /** Sends a caret changed event to the accessibility object. */
293 void AccSendCaretEvent();
294 /** Sends a visible area changed event to the accessibility object. */
295 void AccSendVisibleEvent();
296 /** Sends a selection changed event to the accessibility object. */
297 void AccSendSelectionEvent();
298 /** Sends a table model changed event for changed cell contents to the accessibility object. */
299 void AccSendTableUpdateEvent( sal_uInt32 nFirstColumn, sal_uInt32 nLastColumn, bool bAllRows = true );
300 /** Sends a table model changed event for an inserted column to the accessibility object. */
301 void AccSendInsertColumnEvent( sal_uInt32 nFirstColumn, sal_uInt32 nLastColumn );
302 /** Sends a table model changed event for a removed column to the accessibility object. */
303 void AccSendRemoveColumnEvent( sal_uInt32 nFirstColumn, sal_uInt32 nLastColumn );
305 // repaint helpers --------------------------------------------------------
307 /** Sets the graphic invalid (next Redraw() will not use cached graphic). */
308 inline void InvalidateGfx() { mbValidGfx = false; }
309 /** Sets the graphic valid (next Redraw() will use cached graphic). */
310 inline void ValidateGfx() { mbValidGfx = true; }
311 /** Returns true, if cached graphic is valid. */
312 inline bool IsValidGfx() const { return mbValidGfx; }
314 /** Repaints all controls.
315 @param bInvalidate true = invalidates graphics of this control (not all). */
316 void Repaint( bool bInvalidate = false );
317 /** Increases no-repaint counter (controls do not repaint until the last EnableRepaint()). */
318 void DisableRepaint();
319 /** Decreases no-repaint counter and repaints if counter reaches 0.
320 @param bInvalidate true = invalidates graphics of this control (not all). */
321 void EnableRepaint( bool bInvalidate = false );
322 /** Returns true, if controls will not repaint. */
323 inline bool IsNoRepaint() const { return mrData.mnNoRepaint > 0; }
325 // command handling -------------------------------------------------------
327 /** Sets a new command handler. */
328 inline void SetCmdHdl( const Link& rHdl ) { maCmdHdl = rHdl; }
329 /** Returns the current command handler. */
330 inline const Link& GetCmdHdl() const { return maCmdHdl; }
331 /** Returns data of the last command. */
332 inline const ScCsvCmd& GetCmd() const { return maCmd; }
334 /** Executes a command by calling command handler. */
335 void Execute(
336 ScCsvCmdType eType,
337 sal_Int32 nParam1 = CSV_POS_INVALID,
338 sal_Int32 nParam2 = CSV_POS_INVALID );
340 // layout helpers ---------------------------------------------------------
342 /** Returns a reference to the current layout data. */
343 inline const ScCsvLayoutData& GetLayoutData() const { return mrData; }
344 /** Returns true, if the Right-to-Left layout mode is active. */
345 inline bool IsRTL() const { return mrData.mbAppRTL; }
347 /** Returns the number of available positions. */
348 inline sal_Int32 GetPosCount() const { return mrData.mnPosCount; }
349 /** Returns the number of visible positions. */
350 sal_Int32 GetVisPosCount() const;
351 /** Returns the first visible position. */
352 inline sal_Int32 GetFirstVisPos() const { return mrData.mnPosOffset; }
353 /** Returns the last visible position. */
354 inline sal_Int32 GetLastVisPos() const { return GetFirstVisPos() + GetVisPosCount(); }
355 /** Returns highest possible position for first visible character. */
356 sal_Int32 GetMaxPosOffset() const;
358 /** Returns true, if it is allowed to set a split at nPos. */
359 bool IsValidSplitPos( sal_Int32 nPos ) const;
360 /** Returns true, if nPos is an allowed AND visible split position. */
361 bool IsVisibleSplitPos( sal_Int32 nPos ) const;
363 /** Returns the width of the header column. */
364 inline sal_Int32 GetHdrWidth() const { return mrData.mnHdrWidth; }
365 /** Returns the width of one character column. */
366 inline sal_Int32 GetCharWidth() const { return mrData.mnCharWidth; }
367 /** Returns the start position of the header column. */
368 sal_Int32 GetHdrX() const;
369 /** Returns the X position of the first pixel of the data area. */
370 sal_Int32 GetFirstX() const;
371 /** Returns the X position of the last pixel of the data area. */
372 sal_Int32 GetLastX() const;
373 /** Returns output X coordinate of the specified position. */
374 sal_Int32 GetX( sal_Int32 nPos ) const;
375 /** Returns position from output coordinate. */
376 sal_Int32 GetPosFromX( sal_Int32 nX ) const;
378 /** Returns the number of data lines. */
379 inline sal_Int32 GetLineCount() const { return mrData.mnLineCount; }
380 /** Returns the number of visible lines (including partly visible bottom line). */
381 sal_Int32 GetVisLineCount() const;
382 /** Returns index of first visible line. */
383 inline sal_Int32 GetFirstVisLine() const { return mrData.mnLineOffset; }
384 /** Returns index of last visible line. */
385 sal_Int32 GetLastVisLine() const;
386 /** Returns highest possible index for first line. */
387 sal_Int32 GetMaxLineOffset() const;
389 /** Returns true, if nLine is a valid line index. */
390 bool IsValidLine( sal_Int32 nLine ) const;
391 /** Returns true, if nLine is a valid and visible line index. */
392 bool IsVisibleLine( sal_Int32 nLine ) const;
394 /** Returns the height of the header line. */
395 inline sal_Int32 GetHdrHeight() const { return mrData.mnHdrHeight; }
396 /** Returns the height of one line. */
397 inline sal_Int32 GetLineHeight() const { return mrData.mnLineHeight; }
398 /** Returns output Y coordinate of the specified line. */
399 sal_Int32 GetY( sal_Int32 nLine ) const;
400 /** Returns line index from output coordinate. */
401 sal_Int32 GetLineFromY( sal_Int32 nY ) const;
403 /** Returns the ruler cursor position. */
404 inline sal_Int32 GetRulerCursorPos() const { return mrData.mnPosCursor; }
405 /** Returns the data grid cursor position (not column index!). */
406 inline sal_Int32 GetGridCursorPos() const { return mrData.mnColCursor; }
408 // static helpers ---------------------------------------------------------
410 /** Inverts a rectangle in the specified output device. */
411 static void ImplInvertRect( OutputDevice& rOutDev, const Rectangle& rRect );
413 /** Returns direction code for the keys LEFT, RIGHT, HOME, END.
414 @param bHomeEnd false = ignore HOME and END key. */
415 static ScMoveMode GetHorzDirection( sal_uInt16 nCode, bool bHomeEnd );
416 /** Returns direction code for the keys UP, DOWN, HOME, END, PAGE UP, PAGE DOWN.
417 @param bHomeEnd false = ignore HOME and END key. */
418 static ScMoveMode GetVertDirection( sal_uInt16 nCode, bool bHomeEnd );
420 // accessibility ----------------------------------------------------------
421 public:
422 /** Creates and returns the accessible object of this control. Do not overwrite in
423 derived classes, use ImplCreateAccessible() instead. */
424 virtual XAccessibleRef CreateAccessible();
426 protected:
427 /** Derived classes create a new accessible object here. */
428 virtual ScAccessibleCsvControl* ImplCreateAccessible() = 0;
432 // ============================================================================
434 #endif