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