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 : : #include "csvruler.hxx"
30 : : #include "AccessibleCsvControl.hxx"
31 : :
32 : :
33 : : #include <optutil.hxx>
34 : : #include <com/sun/star/uno/Any.hxx>
35 : : #include <com/sun/star/uno/Sequence.hxx>
36 : : #include <comphelper/string.hxx>
37 : : #include "miscuno.hxx"
38 : :
39 : : using namespace com::sun::star::uno;
40 : :
41 : : using ::rtl::OUString;
42 : :
43 : :
44 : :
45 : : // ============================================================================
46 : : #define SEP_PATH "Office.Calc/Dialogs/CSVImport"
47 : : #define FIXED_WIDTH_LIST "FixedWidthList"
48 : :
49 : :
50 : : // ============================================================================
51 : :
52 : 0 : static void load_FixedWidthList(ScCsvSplits &aSplits)
53 : : {
54 [ # # ]: 0 : String sSplits;
55 : 0 : OUString sFixedWidthLists;
56 : :
57 [ # # ]: 0 : Sequence<Any>aValues;
58 : : const Any *pProperties;
59 [ # # ]: 0 : Sequence<OUString> aNames(1);
60 [ # # ]: 0 : OUString* pNames = aNames.getArray();
61 [ # # ][ # # ]: 0 : ScLinkConfigItem aItem( OUString(RTL_CONSTASCII_USTRINGPARAM( SEP_PATH )) );
62 : :
63 [ # # ]: 0 : pNames[0] = OUString(RTL_CONSTASCII_USTRINGPARAM( FIXED_WIDTH_LIST ));
64 [ # # ][ # # ]: 0 : aValues = aItem.GetProperties( aNames );
[ # # ]
65 : 0 : pProperties = aValues.getConstArray();
66 : :
67 [ # # ]: 0 : if( pProperties[0].hasValue() )
68 : : {
69 [ # # ]: 0 : aSplits.Clear();
70 : 0 : pProperties[0] >>= sFixedWidthLists;
71 : :
72 [ # # ][ # # ]: 0 : sSplits = String( sFixedWidthLists );
[ # # ]
73 : :
74 : : // String ends with a semi-colon so there is no 'int' after the last one.
75 [ # # ][ # # ]: 0 : xub_StrLen n = comphelper::string::getTokenCount(sSplits, ';') - 1;
76 [ # # ]: 0 : for (xub_StrLen i = 0; i < n; ++i)
77 [ # # ][ # # ]: 0 : aSplits.Insert( sSplits.GetToken(i).ToInt32() );
[ # # ][ # # ]
78 [ # # ][ # # ]: 0 : }
[ # # ][ # # ]
79 : 0 : }
80 : 0 : static void save_FixedWidthList(ScCsvSplits aSplits)
81 : : {
82 [ # # ]: 0 : String sSplits;
83 : : // Create a semi-colon separated string to save the splits
84 : 0 : sal_uInt32 n = aSplits.Count();
85 [ # # ]: 0 : for (sal_uInt32 i = 0; i < n; ++i)
86 : : {
87 [ # # ][ # # ]: 0 : sSplits.Append( String::CreateFromInt32( aSplits[i] ) );
[ # # ][ # # ]
88 [ # # ]: 0 : sSplits.Append((char)';');
89 : : }
90 : :
91 [ # # ]: 0 : OUString sFixedWidthLists = OUString( sSplits );
92 [ # # ]: 0 : Sequence<Any> aValues;
93 : : Any *pProperties;
94 [ # # ]: 0 : Sequence<OUString> aNames(1);
95 [ # # ]: 0 : OUString* pNames = aNames.getArray();
96 [ # # ][ # # ]: 0 : ScLinkConfigItem aItem( OUString(RTL_CONSTASCII_USTRINGPARAM( SEP_PATH )) );
97 : :
98 [ # # ]: 0 : pNames[0] = OUString(RTL_CONSTASCII_USTRINGPARAM( FIXED_WIDTH_LIST ));
99 [ # # ][ # # ]: 0 : aValues = aItem.GetProperties( aNames );
[ # # ]
100 [ # # ]: 0 : pProperties = aValues.getArray();
101 [ # # ]: 0 : pProperties[0] <<= sFixedWidthLists;
102 : :
103 [ # # ][ # # ]: 0 : aItem.PutProperties(aNames, aValues);
[ # # ][ # # ]
[ # # ]
104 : 0 : }
105 : :
106 : 0 : ScCsvRuler::ScCsvRuler( ScCsvControl& rParent ) :
107 : : ScCsvControl( rParent ),
108 [ # # ][ # # ]: 0 : mnPosCursorLast( 1 )
[ # # ][ # # ]
[ # # ]
109 : : {
110 [ # # ]: 0 : EnableRTL( false ); // RTL
111 [ # # ]: 0 : InitColors();
112 [ # # ]: 0 : InitSizeData();
113 [ # # ]: 0 : maBackgrDev.SetFont( GetFont() );
114 [ # # ]: 0 : maRulerDev.SetFont( GetFont() );
115 : :
116 [ # # ]: 0 : load_FixedWidthList( maSplits );
117 : 0 : }
118 : :
119 [ # # ][ # # ]: 0 : ScCsvRuler::~ScCsvRuler()
120 : : {
121 [ # # ][ # # ]: 0 : save_FixedWidthList( maSplits );
122 [ # # ]: 0 : }
123 : :
124 : :
125 : : // common ruler handling ------------------------------------------------------
126 : :
127 : 0 : void ScCsvRuler::SetPosSizePixel(
128 : : long nX, long nY, long nWidth, long nHeight, sal_uInt16 nFlags )
129 : : {
130 [ # # ]: 0 : if( nFlags & WINDOW_POSSIZE_HEIGHT )
131 : 0 : nHeight = GetTextHeight() + mnSplitSize + 2;
132 : 0 : ScCsvControl::SetPosSizePixel( nX, nY, nWidth, nHeight, nFlags );
133 : 0 : }
134 : :
135 : 0 : void ScCsvRuler::ApplyLayout( const ScCsvLayoutData& rOldData )
136 : : {
137 : 0 : ScCsvDiff nDiff = GetLayoutData().GetDiff( rOldData ) & (CSV_DIFF_HORIZONTAL | CSV_DIFF_RULERCURSOR);
138 [ # # ]: 0 : if( nDiff == CSV_DIFF_EQUAL ) return;
139 : :
140 : 0 : DisableRepaint();
141 [ # # ]: 0 : if( nDiff & CSV_DIFF_HORIZONTAL )
142 : : {
143 : 0 : InitSizeData();
144 [ # # ]: 0 : if( GetRulerCursorPos() >= GetPosCount() )
145 : 0 : MoveCursor( GetPosCount() - 1 );
146 : : }
147 [ # # ]: 0 : if( nDiff & CSV_DIFF_RULERCURSOR )
148 : : {
149 : 0 : ImplInvertCursor( rOldData.mnPosCursor );
150 : 0 : ImplInvertCursor( GetRulerCursorPos() );
151 : : }
152 : 0 : EnableRepaint();
153 : :
154 [ # # ]: 0 : if( nDiff & CSV_DIFF_POSOFFSET )
155 : 0 : AccSendVisibleEvent();
156 : : }
157 : :
158 : 0 : void ScCsvRuler::InitColors()
159 : : {
160 : 0 : const StyleSettings& rSett = GetSettings().GetStyleSettings();
161 : 0 : maBackColor = rSett.GetFaceColor();
162 : 0 : maActiveColor = rSett.GetWindowColor();
163 : 0 : maTextColor = rSett.GetLabelTextColor();
164 [ # # ][ # # ]: 0 : maSplitColor = maBackColor.IsDark() ? maTextColor : Color( COL_LIGHTRED );
165 : 0 : InvalidateGfx();
166 : 0 : }
167 : :
168 : 0 : void ScCsvRuler::InitSizeData()
169 : : {
170 : 0 : maWinSize = GetSizePixel();
171 : :
172 : 0 : mnSplitSize = (GetCharWidth() * 3 / 5) | 1; // make an odd number
173 : :
174 : 0 : sal_Int32 nActiveWidth = Min( GetWidth() - GetHdrWidth(), GetPosCount() * GetCharWidth() );
175 : 0 : sal_Int32 nActiveHeight = GetTextHeight();
176 : :
177 : 0 : maActiveRect.SetPos( Point( GetFirstX(), (GetHeight() - nActiveHeight - 1) / 2 ) );
178 [ # # ]: 0 : maActiveRect.SetSize( Size( nActiveWidth, nActiveHeight ) );
179 : :
180 : 0 : maBackgrDev.SetOutputSizePixel( maWinSize );
181 : 0 : maRulerDev.SetOutputSizePixel( maWinSize );
182 : :
183 : 0 : InvalidateGfx();
184 : 0 : }
185 : :
186 : 0 : void ScCsvRuler::MoveCursor( sal_Int32 nPos, bool bScroll )
187 : : {
188 : 0 : DisableRepaint();
189 [ # # ]: 0 : if( bScroll )
190 : 0 : Execute( CSVCMD_MAKEPOSVISIBLE, nPos );
191 [ # # ]: 0 : Execute( CSVCMD_MOVERULERCURSOR, IsVisibleSplitPos( nPos ) ? nPos : CSV_POS_INVALID );
192 : 0 : EnableRepaint();
193 : 0 : AccSendCaretEvent();
194 : 0 : }
195 : :
196 : 0 : void ScCsvRuler::MoveCursorRel( ScMoveMode eDir )
197 : : {
198 [ # # ]: 0 : if( GetRulerCursorPos() != CSV_POS_INVALID )
199 : : {
200 [ # # # # : 0 : switch( eDir )
# ]
201 : : {
202 : : case MOVE_FIRST:
203 : 0 : MoveCursor( 1 );
204 : 0 : break;
205 : : case MOVE_LAST:
206 : 0 : MoveCursor( GetPosCount() - 1 );
207 : 0 : break;
208 : : case MOVE_PREV:
209 [ # # ]: 0 : if( GetRulerCursorPos() > 1 )
210 : 0 : MoveCursor( GetRulerCursorPos() - 1 );
211 : 0 : break;
212 : : case MOVE_NEXT:
213 [ # # ]: 0 : if( GetRulerCursorPos() < GetPosCount() - 1 )
214 : 0 : MoveCursor( GetRulerCursorPos() + 1 );
215 : 0 : break;
216 : : default:
217 : : {
218 : : // added to avoid warnings
219 : : }
220 : : }
221 : : }
222 : 0 : }
223 : :
224 : 0 : void ScCsvRuler::MoveCursorToSplit( ScMoveMode eDir )
225 : : {
226 [ # # ]: 0 : if( GetRulerCursorPos() != CSV_POS_INVALID )
227 : : {
228 : 0 : sal_uInt32 nIndex = CSV_VEC_NOTFOUND;
229 [ # # # # : 0 : switch( eDir )
# ]
230 : : {
231 : 0 : case MOVE_FIRST: nIndex = maSplits.LowerBound( 0 ); break;
232 : 0 : case MOVE_LAST: nIndex = maSplits.UpperBound( GetPosCount() ); break;
233 : 0 : case MOVE_PREV: nIndex = maSplits.UpperBound( GetRulerCursorPos() - 1 ); break;
234 : 0 : case MOVE_NEXT: nIndex = maSplits.LowerBound( GetRulerCursorPos() + 1 ); break;
235 : : default:
236 : : {
237 : : // added to avoid warnings
238 : : }
239 : : }
240 : 0 : sal_Int32 nPos = maSplits[ nIndex ];
241 [ # # ]: 0 : if( nPos != CSV_POS_INVALID )
242 : 0 : MoveCursor( nPos );
243 : : }
244 : 0 : }
245 : :
246 : 0 : void ScCsvRuler::ScrollVertRel( ScMoveMode eDir )
247 : : {
248 : 0 : sal_Int32 nLine = GetFirstVisLine();
249 [ # # # # : 0 : switch( eDir )
# ]
250 : : {
251 : 0 : case MOVE_PREV: --nLine; break;
252 : 0 : case MOVE_NEXT: ++nLine; break;
253 : 0 : case MOVE_PREVPAGE: nLine -= GetVisLineCount() - 1; break;
254 : 0 : case MOVE_NEXTPAGE: nLine += GetVisLineCount() - 1; break;
255 : : default:
256 : : {
257 : : // added to avoid warnings
258 : : }
259 : : }
260 : 0 : Execute( CSVCMD_SETLINEOFFSET, nLine );
261 : 0 : }
262 : :
263 : :
264 : : // split handling -------------------------------------------------------------
265 : :
266 : 0 : sal_Int32 ScCsvRuler::GetNoScrollPos( sal_Int32 nPos ) const
267 : : {
268 : 0 : sal_Int32 nNewPos = nPos;
269 [ # # ]: 0 : if( nNewPos != CSV_POS_INVALID )
270 : : {
271 [ # # ]: 0 : if( nNewPos < GetFirstVisPos() + CSV_SCROLL_DIST )
272 : : {
273 [ # # ]: 0 : sal_Int32 nScroll = (GetFirstVisPos() > 0) ? CSV_SCROLL_DIST : 0;
274 : 0 : nNewPos = Max( nPos, GetFirstVisPos() + nScroll );
275 : : }
276 [ # # ]: 0 : else if( nNewPos > GetLastVisPos() - CSV_SCROLL_DIST - 1L )
277 : : {
278 [ # # ]: 0 : sal_Int32 nScroll = (GetFirstVisPos() < GetMaxPosOffset()) ? CSV_SCROLL_DIST : 0;
279 : 0 : nNewPos = Min( nNewPos, GetLastVisPos() - nScroll - sal_Int32( 1 ) );
280 : : }
281 : : }
282 : 0 : return nNewPos;
283 : : }
284 : :
285 : 0 : void ScCsvRuler::InsertSplit( sal_Int32 nPos )
286 : : {
287 [ # # ]: 0 : if( maSplits.Insert( nPos ) )
288 : : {
289 : 0 : ImplDrawSplit( nPos );
290 : 0 : Repaint();
291 : : }
292 : 0 : }
293 : :
294 : 0 : void ScCsvRuler::RemoveSplit( sal_Int32 nPos )
295 : : {
296 [ # # ]: 0 : if( maSplits.Remove( nPos ) )
297 : : {
298 : 0 : ImplEraseSplit( nPos );
299 : 0 : Repaint();
300 : : }
301 : 0 : }
302 : :
303 : 0 : void ScCsvRuler::MoveSplit( sal_Int32 nPos, sal_Int32 nNewPos )
304 : : {
305 : 0 : bool bRemove = maSplits.Remove( nPos );
306 : 0 : bool bInsert = maSplits.Insert( nNewPos );
307 [ # # ][ # # ]: 0 : if( bRemove || bInsert )
308 : : {
309 : 0 : ImplEraseSplit( nPos );
310 : 0 : ImplDrawSplit( nNewPos );
311 : 0 : Repaint();
312 : : }
313 : 0 : }
314 : :
315 : 0 : void ScCsvRuler::RemoveAllSplits()
316 : : {
317 : 0 : maSplits.Clear();
318 : 0 : Repaint( true );
319 : 0 : }
320 : :
321 : 0 : sal_Int32 ScCsvRuler::FindEmptyPos( sal_Int32 nPos, ScMoveMode eDir ) const
322 : : {
323 : 0 : sal_Int32 nNewPos = nPos;
324 [ # # ]: 0 : if( nNewPos != CSV_POS_INVALID )
325 : : {
326 [ # # # # : 0 : switch( eDir )
# ]
327 : : {
328 : : case MOVE_FIRST:
329 : 0 : nNewPos = Min( nPos, FindEmptyPos( 0, MOVE_NEXT ) );
330 : 0 : break;
331 : : case MOVE_LAST:
332 : 0 : nNewPos = Max( nPos, FindEmptyPos( GetPosCount(), MOVE_PREV ) );
333 : 0 : break;
334 : : case MOVE_PREV:
335 [ # # ]: 0 : while( HasSplit( --nNewPos ) ) ;
336 : 0 : break;
337 : : case MOVE_NEXT:
338 [ # # ]: 0 : while( HasSplit( ++nNewPos ) ) ;
339 : 0 : break;
340 : : default:
341 : : {
342 : : // added to avoid warnings
343 : : }
344 : : }
345 : : }
346 [ # # ]: 0 : return IsValidSplitPos( nNewPos ) ? nNewPos : CSV_POS_INVALID;
347 : : }
348 : :
349 : 0 : void ScCsvRuler::MoveCurrSplit( sal_Int32 nNewPos )
350 : : {
351 : 0 : DisableRepaint();
352 : 0 : Execute( CSVCMD_MOVESPLIT, GetRulerCursorPos(), nNewPos );
353 : 0 : MoveCursor( nNewPos );
354 : 0 : EnableRepaint();
355 : 0 : }
356 : :
357 : 0 : void ScCsvRuler::MoveCurrSplitRel( ScMoveMode eDir )
358 : : {
359 [ # # ]: 0 : if( HasSplit( GetRulerCursorPos() ) )
360 : : {
361 : 0 : sal_Int32 nNewPos = FindEmptyPos( GetRulerCursorPos(), eDir );
362 [ # # ]: 0 : if( nNewPos != CSV_POS_INVALID )
363 : 0 : MoveCurrSplit( nNewPos );
364 : : }
365 : 0 : }
366 : :
367 : :
368 : : // event handling -------------------------------------------------------------
369 : :
370 : 0 : void ScCsvRuler::Resize()
371 : : {
372 : 0 : ScCsvControl::Resize();
373 : 0 : InitSizeData();
374 : 0 : Repaint();
375 : 0 : }
376 : :
377 : 0 : void ScCsvRuler::GetFocus()
378 : : {
379 : 0 : ScCsvControl::GetFocus();
380 : 0 : DisableRepaint();
381 [ # # ]: 0 : if( GetRulerCursorPos() == CSV_POS_INVALID )
382 : 0 : MoveCursor( GetNoScrollPos( mnPosCursorLast ) );
383 : 0 : EnableRepaint();
384 : 0 : }
385 : :
386 : 0 : void ScCsvRuler::LoseFocus()
387 : : {
388 : 0 : ScCsvControl::LoseFocus();
389 : 0 : mnPosCursorLast = GetRulerCursorPos();
390 : 0 : MoveCursor( CSV_POS_INVALID );
391 : 0 : }
392 : :
393 : 0 : void ScCsvRuler::DataChanged( const DataChangedEvent& rDCEvt )
394 : : {
395 [ # # ][ # # ]: 0 : if( (rDCEvt.GetType() == DATACHANGED_SETTINGS) && (rDCEvt.GetFlags() & SETTINGS_STYLE) )
[ # # ]
396 : : {
397 : 0 : InitColors();
398 : 0 : Repaint();
399 : : }
400 : 0 : ScCsvControl::DataChanged( rDCEvt );
401 : 0 : }
402 : :
403 : 0 : void ScCsvRuler::MouseButtonDown( const MouseEvent& rMEvt )
404 : : {
405 : 0 : DisableRepaint();
406 [ # # ]: 0 : if( !HasFocus() )
407 : 0 : GrabFocus();
408 [ # # ]: 0 : if( rMEvt.IsLeft() )
409 : : {
410 : 0 : sal_Int32 nPos = GetPosFromX( rMEvt.GetPosPixel().X() );
411 [ # # ]: 0 : if( IsVisibleSplitPos( nPos ) )
412 : 0 : StartMouseTracking( nPos );
413 : 0 : ImplSetMousePointer( nPos );
414 : : }
415 : 0 : EnableRepaint();
416 : 0 : }
417 : :
418 : 0 : void ScCsvRuler::MouseMove( const MouseEvent& rMEvt )
419 : : {
420 [ # # ]: 0 : if( !rMEvt.IsModifierChanged() )
421 : : {
422 : 0 : sal_Int32 nPos = GetPosFromX( rMEvt.GetPosPixel().X() );
423 [ # # ]: 0 : if( IsTracking() )
424 : : {
425 : : // on mouse tracking: keep position valid
426 : 0 : nPos = Max( Min( nPos, GetPosCount() - sal_Int32( 1 ) ), sal_Int32( 1 ) );
427 : 0 : MoveMouseTracking( nPos );
428 : : }
429 : : else
430 : : {
431 : 0 : Point aPoint;
432 [ # # ]: 0 : Rectangle aRect( aPoint, maWinSize );
433 [ # # ][ # # ]: 0 : if( !IsVisibleSplitPos( nPos ) || !aRect.IsInside( rMEvt.GetPosPixel() ) )
[ # # ][ # # ]
[ # # ]
434 : : // if focused, keep old cursor position for key input
435 [ # # ][ # # ]: 0 : nPos = HasFocus() ? GetRulerCursorPos() : CSV_POS_INVALID;
436 [ # # ]: 0 : MoveCursor( nPos, false );
437 : : }
438 : 0 : ImplSetMousePointer( nPos );
439 : : }
440 : 0 : }
441 : :
442 : 0 : void ScCsvRuler::Tracking( const TrackingEvent& rTEvt )
443 : : {
444 [ # # ][ # # ]: 0 : if( rTEvt.IsTrackingEnded() || rTEvt.IsTrackingRepeat() )
[ # # ]
445 : 0 : MouseMove( rTEvt.GetMouseEvent() );
446 [ # # ]: 0 : if( rTEvt.IsTrackingEnded() )
447 : 0 : EndMouseTracking( !rTEvt.IsTrackingCanceled() );
448 : 0 : }
449 : :
450 : 0 : void ScCsvRuler::KeyInput( const KeyEvent& rKEvt )
451 : : {
452 : 0 : const KeyCode& rKCode = rKEvt.GetKeyCode();
453 : 0 : sal_uInt16 nCode = rKCode.GetCode();
454 : 0 : bool bNoMod = !rKCode.GetModifier();
455 : 0 : bool bShift = (rKCode.GetModifier() == KEY_SHIFT);
456 : 0 : bool bJump = (rKCode.GetModifier() == KEY_MOD1);
457 : 0 : bool bMove = (rKCode.GetModifier() == (KEY_MOD1 | KEY_SHIFT));
458 : :
459 : 0 : ScMoveMode eHDir = GetHorzDirection( nCode, true );
460 : 0 : ScMoveMode eVDir = GetVertDirection( nCode, false );
461 : :
462 [ # # ]: 0 : if( bNoMod )
463 : : {
464 [ # # ]: 0 : if( eHDir != MOVE_NONE )
465 : 0 : MoveCursorRel( eHDir );
466 [ # # ]: 0 : else if( eVDir != MOVE_NONE )
467 : 0 : ScrollVertRel( eVDir );
468 [ # # # # ]: 0 : else switch( nCode )
469 : : {
470 : 0 : case KEY_SPACE: Execute( CSVCMD_TOGGLESPLIT, GetRulerCursorPos() ); break;
471 : 0 : case KEY_INSERT: Execute( CSVCMD_INSERTSPLIT, GetRulerCursorPos() ); break;
472 : 0 : case KEY_DELETE: Execute( CSVCMD_REMOVESPLIT, GetRulerCursorPos() ); break;
473 : : }
474 : : }
475 [ # # ][ # # ]: 0 : else if( bJump && (eHDir != MOVE_NONE) )
476 : 0 : MoveCursorToSplit( eHDir );
477 [ # # ][ # # ]: 0 : else if( bMove && (eHDir != MOVE_NONE) )
478 : 0 : MoveCurrSplitRel( eHDir );
479 [ # # ][ # # ]: 0 : else if( bShift && (nCode == KEY_DELETE) )
480 : 0 : Execute( CSVCMD_REMOVEALLSPLITS );
481 : :
482 [ # # ]: 0 : if( rKCode.GetGroup() != KEYGROUP_CURSOR )
483 : 0 : ScCsvControl::KeyInput( rKEvt );
484 : 0 : }
485 : :
486 : 0 : void ScCsvRuler::StartMouseTracking( sal_Int32 nPos )
487 : : {
488 : 0 : mnPosMTStart = mnPosMTCurr = nPos;
489 : 0 : mbPosMTMoved = false;
490 : 0 : maOldSplits = maSplits;
491 : 0 : Execute( CSVCMD_INSERTSPLIT, nPos );
492 [ # # ]: 0 : if( HasSplit( nPos ) )
493 : 0 : StartTracking( STARTTRACK_BUTTONREPEAT );
494 : 0 : }
495 : :
496 : 0 : void ScCsvRuler::MoveMouseTracking( sal_Int32 nPos )
497 : : {
498 [ # # ]: 0 : if( mnPosMTCurr != nPos )
499 : : {
500 : 0 : DisableRepaint();
501 : 0 : MoveCursor( nPos );
502 [ # # ][ # # ]: 0 : if( (mnPosMTCurr != mnPosMTStart) && maOldSplits.HasSplit( mnPosMTCurr ) )
[ # # ]
503 : 0 : Execute( CSVCMD_INSERTSPLIT, nPos );
504 : : else
505 : 0 : Execute( CSVCMD_MOVESPLIT, mnPosMTCurr, nPos );
506 : 0 : mnPosMTCurr = nPos;
507 : 0 : mbPosMTMoved = true;
508 : 0 : EnableRepaint();
509 : : }
510 : 0 : }
511 : :
512 : 0 : void ScCsvRuler::EndMouseTracking( bool bApply )
513 : : {
514 [ # # ]: 0 : if( bApply ) // tracking finished successfully
515 : : {
516 : : // remove on simple click on an existing split
517 [ # # ][ # # ]: 0 : if( (mnPosMTCurr == mnPosMTStart) && maOldSplits.HasSplit( mnPosMTCurr ) && !mbPosMTMoved )
[ # # ][ # # ]
518 : 0 : Execute( CSVCMD_REMOVESPLIT, mnPosMTCurr );
519 : : }
520 : : else // tracking cancelled
521 : : {
522 : 0 : MoveCursor( mnPosMTStart );
523 : : // move split to origin
524 [ # # ]: 0 : if( maOldSplits.HasSplit( mnPosMTStart ) )
525 : 0 : MoveMouseTracking( mnPosMTStart );
526 : : // remove temporarily inserted split
527 [ # # ]: 0 : else if( !maOldSplits.HasSplit( mnPosMTCurr ) )
528 : 0 : Execute( CSVCMD_REMOVESPLIT, mnPosMTCurr );
529 : : }
530 : 0 : mnPosMTStart = CSV_POS_INVALID;
531 : 0 : }
532 : :
533 : :
534 : : // painting -------------------------------------------------------------------
535 : :
536 : 0 : void ScCsvRuler::Paint( const Rectangle& )
537 : : {
538 : 0 : Repaint();
539 : 0 : }
540 : :
541 : 0 : void ScCsvRuler::ImplRedraw()
542 : : {
543 [ # # ]: 0 : if( IsVisible() )
544 : : {
545 [ # # ]: 0 : if( !IsValidGfx() )
546 : : {
547 : 0 : ValidateGfx();
548 : 0 : ImplDrawBackgrDev();
549 : 0 : ImplDrawRulerDev();
550 : : }
551 [ # # ]: 0 : DrawOutDev( Point(), maWinSize, Point(), maWinSize, maRulerDev );
552 : 0 : ImplDrawTrackingRect();
553 : : }
554 : 0 : }
555 : :
556 : 0 : void ScCsvRuler::ImplDrawArea( sal_Int32 nPosX, sal_Int32 nWidth )
557 : : {
558 [ # # ]: 0 : maBackgrDev.SetLineColor();
559 [ # # ]: 0 : Rectangle aRect( Point( nPosX, 0 ), Size( nWidth, GetHeight() ) );
560 [ # # ]: 0 : maBackgrDev.SetFillColor( maBackColor );
561 [ # # ]: 0 : maBackgrDev.DrawRect( aRect );
562 : :
563 : 0 : aRect = maActiveRect;
564 [ # # ]: 0 : aRect.Left() = Max( GetFirstX(), nPosX );
565 [ # # ][ # # ]: 0 : aRect.Right() = Min( Min( GetX( GetPosCount() ), GetLastX() ), nPosX + nWidth - sal_Int32( 1 ) );
566 [ # # ]: 0 : if( aRect.Left() <= aRect.Right() )
567 : : {
568 [ # # ]: 0 : maBackgrDev.SetFillColor( maActiveColor );
569 [ # # ]: 0 : maBackgrDev.DrawRect( aRect );
570 : : }
571 : :
572 [ # # ]: 0 : maBackgrDev.SetLineColor( maTextColor );
573 : 0 : sal_Int32 nY = GetHeight() - 1;
574 [ # # ]: 0 : maBackgrDev.DrawLine( Point( nPosX, nY ), Point( nPosX + nWidth - 1, nY ) );
575 : 0 : }
576 : :
577 : 0 : void ScCsvRuler::ImplDrawBackgrDev()
578 : : {
579 : 0 : ImplDrawArea( 0, GetWidth() );
580 : :
581 : : // scale
582 : 0 : maBackgrDev.SetLineColor( maTextColor );
583 : 0 : maBackgrDev.SetFillColor();
584 : : sal_Int32 nPos;
585 : :
586 : 0 : sal_Int32 nFirstPos = Max( GetPosFromX( 0 ) - (sal_Int32)(1L), (sal_Int32)(0L) );
587 : 0 : sal_Int32 nLastPos = GetPosFromX( GetWidth() );
588 : 0 : sal_Int32 nY = (maActiveRect.Top() + maActiveRect.Bottom()) / 2;
589 [ # # ]: 0 : for( nPos = nFirstPos; nPos <= nLastPos; ++nPos )
590 : : {
591 : 0 : sal_Int32 nX = GetX( nPos );
592 [ # # ]: 0 : if( nPos % 5 )
593 [ # # ]: 0 : maBackgrDev.DrawPixel( Point( nX, nY ) );
594 : : else
595 [ # # ]: 0 : maBackgrDev.DrawLine( Point( nX, nY - 1 ), Point( nX, nY + 1 ) );
596 : : }
597 : :
598 : : // texts
599 : 0 : maBackgrDev.SetTextColor( maTextColor );
600 : 0 : maBackgrDev.SetTextFillColor();
601 [ # # ]: 0 : for( nPos = ((nFirstPos + 9) / 10) * 10; nPos <= nLastPos; nPos += 10 )
602 : : {
603 [ # # ]: 0 : String aText( String::CreateFromInt32( nPos ) );
604 [ # # ]: 0 : sal_Int32 nTextWidth = maBackgrDev.GetTextWidth( aText );
605 [ # # ]: 0 : sal_Int32 nTextX = GetX( nPos ) - nTextWidth / 2;
606 [ # # ]: 0 : ImplDrawArea( nTextX - 1, nTextWidth + 2 );
607 [ # # ]: 0 : maBackgrDev.DrawText( Point( nTextX, maActiveRect.Top() ), aText );
608 [ # # ]: 0 : }
609 : 0 : }
610 : :
611 : 0 : void ScCsvRuler::ImplDrawSplit( sal_Int32 nPos )
612 : : {
613 [ # # ]: 0 : if( IsVisibleSplitPos( nPos ) )
614 : : {
615 [ # # ]: 0 : Point aPos( GetX( nPos ) - mnSplitSize / 2, GetHeight() - mnSplitSize - 2 );
616 : 0 : Size aSize( mnSplitSize, mnSplitSize );
617 [ # # ]: 0 : maRulerDev.SetLineColor( maTextColor );
618 [ # # ]: 0 : maRulerDev.SetFillColor( maSplitColor );
619 [ # # ][ # # ]: 0 : maRulerDev.DrawEllipse( Rectangle( aPos, aSize ) );
620 [ # # ][ # # ]: 0 : maRulerDev.DrawPixel( Point( GetX( nPos ), GetHeight() - 2 ) );
621 : : }
622 : 0 : }
623 : :
624 : 0 : void ScCsvRuler::ImplEraseSplit( sal_Int32 nPos )
625 : : {
626 [ # # ]: 0 : if( IsVisibleSplitPos( nPos ) )
627 : : {
628 [ # # ]: 0 : ImplInvertCursor( GetRulerCursorPos() );
629 [ # # ]: 0 : Point aPos( GetX( nPos ) - mnSplitSize / 2, 0 );
630 : 0 : Size aSize( mnSplitSize, GetHeight() );
631 [ # # ]: 0 : maRulerDev.DrawOutDev( aPos, aSize, aPos, aSize, maBackgrDev );
632 [ # # ]: 0 : ImplInvertCursor( GetRulerCursorPos() );
633 : : }
634 : 0 : }
635 : :
636 : 0 : void ScCsvRuler::ImplDrawRulerDev()
637 : : {
638 [ # # ]: 0 : maRulerDev.DrawOutDev( Point(), maWinSize, Point(), maWinSize, maBackgrDev );
639 : 0 : ImplInvertCursor( GetRulerCursorPos() );
640 : :
641 : 0 : sal_uInt32 nFirst = maSplits.LowerBound( GetFirstVisPos() );
642 : 0 : sal_uInt32 nLast = maSplits.UpperBound( GetLastVisPos() );
643 [ # # ][ # # ]: 0 : if( (nFirst != CSV_VEC_NOTFOUND) && (nLast != CSV_VEC_NOTFOUND) )
644 [ # # ]: 0 : for( sal_uInt32 nIndex = nFirst; nIndex <= nLast; ++nIndex )
645 : 0 : ImplDrawSplit( GetSplitPos( nIndex ) );
646 : 0 : }
647 : :
648 : 0 : void ScCsvRuler::ImplInvertCursor( sal_Int32 nPos )
649 : : {
650 [ # # ]: 0 : if( IsVisibleSplitPos( nPos ) )
651 : : {
652 [ # # ][ # # ]: 0 : ImplInvertRect( maRulerDev, Rectangle( Point( GetX( nPos ) - 1, 0 ), Size( 3, GetHeight() - 1 ) ) );
[ # # ]
653 [ # # ]: 0 : if( HasSplit( nPos ) )
654 : 0 : ImplDrawSplit( nPos );
655 : : }
656 : 0 : }
657 : :
658 : 0 : void ScCsvRuler::ImplDrawTrackingRect()
659 : : {
660 [ # # ]: 0 : if( HasFocus() )
661 : 0 : InvertTracking( Rectangle( 0, 0, GetWidth() - 1, GetHeight() - 2 ),
662 [ # # ]: 0 : SHOWTRACK_SMALL | SHOWTRACK_WINDOW );
663 : 0 : }
664 : :
665 : 0 : void ScCsvRuler::ImplSetMousePointer( sal_Int32 nPos )
666 : : {
667 [ # # ][ # # ]: 0 : SetPointer( Pointer( HasSplit( nPos ) ? POINTER_HSPLIT : POINTER_ARROW ) );
668 : 0 : }
669 : :
670 : :
671 : : // accessibility ==============================================================
672 : :
673 : 0 : ScAccessibleCsvControl* ScCsvRuler::ImplCreateAccessible()
674 : : {
675 [ # # ]: 0 : return new ScAccessibleCsvRuler( *this );
676 : : }
677 : :
678 : :
679 : : // ============================================================================
680 : :
681 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|