1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: csvtablebox.cxx,v $
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 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sc.hxx"
35 // ============================================================================
36 #include "csvtablebox.hxx"
37 #include <tools/debug.hxx>
38 #include <vcl/lstbox.hxx>
41 #include "editutil.hxx"
43 // ============================================================================
45 //UNUSED2009-05 ScCsvTableBox::ScCsvTableBox( Window* pParent ) :
46 //UNUSED2009-05 ScCsvControl( pParent, maData, WB_BORDER | WB_TABSTOP | WB_DIALOGCONTROL ),
47 //UNUSED2009-05 maRuler( *this ),
48 //UNUSED2009-05 maGrid( *this ),
49 //UNUSED2009-05 maHScroll( this, WB_HORZ | WB_DRAG ),
50 //UNUSED2009-05 maVScroll( this, WB_VERT | WB_DRAG ),
51 //UNUSED2009-05 maScrollBox( this )
53 //UNUSED2009-05 Init();
56 ScCsvTableBox::ScCsvTableBox( Window
* pParent
, const ResId
& rResId
) :
57 ScCsvControl( pParent
, maData
, rResId
),
60 maHScroll( this, WB_HORZ
| WB_DRAG
),
61 maVScroll( this, WB_VERT
| WB_DRAG
),
68 // common table box handling --------------------------------------------------
70 void ScCsvTableBox::SetSeparatorsMode()
74 // rescue data for fixed width mode
75 mnFixedWidth
= GetPosCount();
76 maFixColStates
= maGrid
.GetColumnStates();
77 // switch to separators mode
79 // reset and reinitialize controls
81 Execute( CSVCMD_SETLINEOFFSET
, 0 );
82 Execute( CSVCMD_SETPOSCOUNT
, 1 );
83 Execute( CSVCMD_NEWCELLTEXTS
);
84 maGrid
.SetColumnStates( maSepColStates
);
90 void ScCsvTableBox::SetFixedWidthMode()
94 // rescue data for separators mode
95 maSepColStates
= maGrid
.GetColumnStates();
96 // switch to fixed width mode
98 // reset and reinitialize controls
100 Execute( CSVCMD_SETLINEOFFSET
, 0 );
101 Execute( CSVCMD_SETPOSCOUNT
, mnFixedWidth
);
102 maGrid
.SetSplits( maRuler
.GetSplits() );
103 maGrid
.SetColumnStates( maFixColStates
);
109 void ScCsvTableBox::Init()
114 maHScroll
.EnableRTL( false ); // #107812# RTL
115 maHScroll
.SetLineSize( 1 );
116 maVScroll
.SetLineSize( 1 );
118 Link aLink
= LINK( this, ScCsvTableBox
, CsvCmdHdl
);
120 maRuler
.SetCmdHdl( aLink
);
121 maGrid
.SetCmdHdl( aLink
);
123 aLink
= LINK( this, ScCsvTableBox
, ScrollHdl
);
124 maHScroll
.SetScrollHdl( aLink
);
125 maVScroll
.SetScrollHdl( aLink
);
127 aLink
= LINK( this, ScCsvTableBox
, ScrollEndHdl
);
128 maHScroll
.SetEndScrollHdl( aLink
);
129 maVScroll
.SetEndScrollHdl( aLink
);
134 void ScCsvTableBox::InitControls()
136 maGrid
.UpdateLayoutData();
138 long nScrollBarSize
= GetSettings().GetStyleSettings().GetScrollBarSize();
139 Size aWinSize
= CalcOutputSize( GetSizePixel() );
140 long nDataWidth
= aWinSize
.Width() - nScrollBarSize
;
141 long nDataHeight
= aWinSize
.Height() - nScrollBarSize
;
143 maData
.mnWinWidth
= nDataWidth
;
144 maData
.mnWinHeight
= nDataHeight
;
148 // ruler sets height internally
149 maRuler
.SetPosSizePixel( 0, 0, nDataWidth
, 0 );
150 sal_Int32 nY
= maRuler
.GetSizePixel().Height();
151 maData
.mnWinHeight
-= nY
;
152 maGrid
.SetPosSizePixel( 0, nY
, nDataWidth
, maData
.mnWinHeight
);
155 maGrid
.SetPosSizePixel( 0, 0, nDataWidth
, nDataHeight
);
157 maRuler
.Show( mbFixedMode
);
159 // scrollbars always visible
160 maHScroll
.SetPosSizePixel( 0, nDataHeight
, nDataWidth
, nScrollBarSize
);
164 // scrollbars always visible
165 maVScroll
.SetPosSizePixel( nDataWidth
, 0, nScrollBarSize
, nDataHeight
);
169 bool bScrBox
= maHScroll
.IsVisible() && maVScroll
.IsVisible();
171 maScrollBox
.SetPosSizePixel( nDataWidth
, nDataHeight
, nScrollBarSize
, nScrollBarSize
);
172 maScrollBox
.Show( bScrBox
);
174 // let the controls self-adjust to visible area
175 Execute( CSVCMD_SETPOSOFFSET
, GetFirstVisPos() );
176 Execute( CSVCMD_SETLINEOFFSET
, GetFirstVisLine() );
179 void ScCsvTableBox::InitHScrollBar()
181 maHScroll
.SetRange( Range( 0, GetPosCount() + 2 ) );
182 maHScroll
.SetVisibleSize( GetVisPosCount() );
183 maHScroll
.SetPageSize( GetVisPosCount() * 3 / 4 );
184 maHScroll
.SetThumbPos( GetFirstVisPos() );
187 void ScCsvTableBox::InitVScrollBar()
189 maVScroll
.SetRange( Range( 0, GetLineCount() + 1 ) );
190 maVScroll
.SetVisibleSize( GetVisLineCount() );
191 maVScroll
.SetPageSize( GetVisLineCount() - 2 );
192 maVScroll
.SetThumbPos( GetFirstVisLine() );
195 void ScCsvTableBox::MakePosVisible( sal_Int32 nPos
)
197 if( (0 <= nPos
) && (nPos
< GetPosCount()) )
199 if( nPos
- CSV_SCROLL_DIST
+ 1 <= GetFirstVisPos() )
200 Execute( CSVCMD_SETPOSOFFSET
, nPos
- CSV_SCROLL_DIST
);
201 else if( nPos
+ CSV_SCROLL_DIST
>= GetLastVisPos() )
202 Execute( CSVCMD_SETPOSOFFSET
, nPos
- GetVisPosCount() + CSV_SCROLL_DIST
);
207 // cell contents --------------------------------------------------------------
209 void ScCsvTableBox::SetUniStrings(
210 const String
* pTextLines
, const String
& rSepChars
,
211 sal_Unicode cTextSep
, bool bMergeSep
)
213 // assuming that pTextLines is a string array with size CSV_PREVIEW_LINES
214 // -> will be dynamic sometime
216 sal_Int32 nEndLine
= GetFirstVisLine() + CSV_PREVIEW_LINES
;
217 const String
* pString
= pTextLines
;
218 for( sal_Int32 nLine
= GetFirstVisLine(); nLine
< nEndLine
; ++nLine
, ++pString
)
221 maGrid
.ImplSetTextLineFix( nLine
, *pString
);
223 maGrid
.ImplSetTextLineSep( nLine
, *pString
, rSepChars
, cTextSep
, bMergeSep
);
228 //UNUSED2009-05 void ScCsvTableBox::SetByteStrings(
229 //UNUSED2009-05 const ByteString* pTextLines, CharSet eCharSet,
230 //UNUSED2009-05 const String& rSepChars, sal_Unicode cTextSep, bool bMergeSep )
232 //UNUSED2009-05 // assuming that pTextLines is a string array with size CSV_PREVIEW_LINES
233 //UNUSED2009-05 // -> will be dynamic sometime
234 //UNUSED2009-05 DisableRepaint();
235 //UNUSED2009-05 sal_Int32 nEndLine = GetFirstVisLine() + CSV_PREVIEW_LINES;
236 //UNUSED2009-05 const ByteString* pString = pTextLines;
237 //UNUSED2009-05 for( sal_Int32 nLine = GetFirstVisLine(); nLine < nEndLine; ++nLine, ++pString )
239 //UNUSED2009-05 if( mbFixedMode )
240 //UNUSED2009-05 maGrid.ImplSetTextLineFix( nLine, String( *pString, eCharSet ) );
242 //UNUSED2009-05 maGrid.ImplSetTextLineSep( nLine, String( *pString, eCharSet ), rSepChars, cTextSep, bMergeSep );
244 //UNUSED2009-05 EnableRepaint();
248 // column settings ------------------------------------------------------------
250 void ScCsvTableBox::InitTypes( const ListBox
& rListBox
)
252 sal_uInt16 nTypeCount
= rListBox
.GetEntryCount();
253 StringVec
aTypeNames( nTypeCount
);
254 for( sal_uInt16 nIndex
= 0; nIndex
< nTypeCount
; ++nIndex
)
255 aTypeNames
[ nIndex
] = rListBox
.GetEntry( nIndex
);
256 maGrid
.SetTypeNames( aTypeNames
);
259 void ScCsvTableBox::FillColumnData( ScAsciiOptions
& rOptions
) const
262 maGrid
.FillColumnDataFix( rOptions
);
264 maGrid
.FillColumnDataSep( rOptions
);
268 // event handling -------------------------------------------------------------
270 void ScCsvTableBox::Resize()
272 ScCsvControl::Resize();
276 void ScCsvTableBox::DataChanged( const DataChangedEvent
& rDCEvt
)
278 if( (rDCEvt
.GetType() == DATACHANGED_SETTINGS
) && (rDCEvt
.GetFlags() & SETTINGS_STYLE
) )
280 ScCsvControl::DataChanged( rDCEvt
);
283 IMPL_LINK( ScCsvTableBox
, CsvCmdHdl
, ScCsvControl
*, pCtrl
)
285 DBG_ASSERT( pCtrl
, "ScCsvTableBox::CsvCmdHdl - missing sender" );
287 const ScCsvCmd
& rCmd
= pCtrl
->GetCmd();
288 ScCsvCmdType eType
= rCmd
.GetType();
289 sal_Int32 nParam1
= rCmd
.GetParam1();
290 sal_Int32 nParam2
= rCmd
.GetParam2();
299 maRuler
.ImplRedraw();
304 case CSVCMD_MAKEPOSVISIBLE
:
305 MakePosVisible( nParam1
);
308 case CSVCMD_NEWCELLTEXTS
:
310 Execute( CSVCMD_UPDATECELLTEXTS
);
314 ScCsvColStateVec
aStates( maGrid
.GetColumnStates() );
315 sal_Int32 nPos
= GetFirstVisPos();
316 Execute( CSVCMD_SETPOSCOUNT
, 1 );
317 Execute( CSVCMD_UPDATECELLTEXTS
);
318 Execute( CSVCMD_SETPOSOFFSET
, nPos
);
319 maGrid
.SetColumnStates( aStates
);
323 case CSVCMD_UPDATECELLTEXTS
:
324 maUpdateTextHdl
.Call( this );
326 case CSVCMD_SETCOLUMNTYPE
:
327 maGrid
.SetSelColumnType( nParam1
);
329 case CSVCMD_EXPORTCOLUMNTYPE
:
330 maColTypeHdl
.Call( this );
332 case CSVCMD_SETFIRSTIMPORTLINE
:
333 maGrid
.SetFirstImportedLine( nParam1
);
336 case CSVCMD_INSERTSPLIT
:
337 DBG_ASSERT( mbFixedMode
, "ScCsvTableBox::CsvCmdHdl::InsertSplit - invalid call" );
338 if( maRuler
.GetSplitCount() + 1 < sal::static_int_cast
<sal_uInt32
>(CSV_MAXCOLCOUNT
) )
340 maRuler
.InsertSplit( nParam1
);
341 maGrid
.InsertSplit( nParam1
);
344 case CSVCMD_REMOVESPLIT
:
345 DBG_ASSERT( mbFixedMode
, "ScCsvTableBox::CsvCmdHdl::RemoveSplit - invalid call" );
346 maRuler
.RemoveSplit( nParam1
);
347 maGrid
.RemoveSplit( nParam1
);
349 case CSVCMD_TOGGLESPLIT
:
350 Execute( maRuler
.HasSplit( nParam1
) ? CSVCMD_REMOVESPLIT
: CSVCMD_INSERTSPLIT
, nParam1
);
352 case CSVCMD_MOVESPLIT
:
353 DBG_ASSERT( mbFixedMode
, "ScCsvTableBox::CsvCmdHdl::MoveSplit - invalid call" );
354 maRuler
.MoveSplit( nParam1
, nParam2
);
355 maGrid
.MoveSplit( nParam1
, nParam2
);
357 case CSVCMD_REMOVEALLSPLITS
:
358 DBG_ASSERT( mbFixedMode
, "ScCsvTableBox::CsvCmdHdl::RemoveAllSplits - invalid call" );
359 maRuler
.RemoveAllSplits();
360 maGrid
.RemoveAllSplits();
368 const ScCsvLayoutData
aOldData( maData
);
371 case CSVCMD_SETPOSCOUNT
:
372 maData
.mnPosCount
= Max( nParam1
, sal_Int32( 1 ) );
373 ImplSetPosOffset( GetFirstVisPos() );
375 case CSVCMD_SETPOSOFFSET
:
376 ImplSetPosOffset( nParam1
);
378 case CSVCMD_SETHDRWIDTH
:
379 maData
.mnHdrWidth
= Max( nParam1
, sal_Int32( 0 ) );
380 ImplSetPosOffset( GetFirstVisPos() );
382 case CSVCMD_SETCHARWIDTH
:
383 maData
.mnCharWidth
= Max( nParam1
, sal_Int32( 1 ) );
384 ImplSetPosOffset( GetFirstVisPos() );
386 case CSVCMD_SETLINECOUNT
:
387 maData
.mnLineCount
= Max( nParam1
, sal_Int32( 1 ) );
388 ImplSetLineOffset( GetFirstVisLine() );
390 case CSVCMD_SETLINEOFFSET
:
391 ImplSetLineOffset( nParam1
);
393 case CSVCMD_SETHDRHEIGHT
:
394 maData
.mnHdrHeight
= Max( nParam1
, sal_Int32( 0 ) );
395 ImplSetLineOffset( GetFirstVisLine() );
397 case CSVCMD_SETLINEHEIGHT
:
398 maData
.mnLineHeight
= Max( nParam1
, sal_Int32( 1 ) );
399 ImplSetLineOffset( GetFirstVisLine() );
401 case CSVCMD_MOVERULERCURSOR
:
402 maData
.mnPosCursor
= IsVisibleSplitPos( nParam1
) ? nParam1
: CSV_POS_INVALID
;
404 case CSVCMD_MOVEGRIDCURSOR
:
405 maData
.mnColCursor
= ((0 <= nParam1
) && (nParam1
< GetPosCount())) ? nParam1
: CSV_POS_INVALID
;
409 // added to avoid warnings
413 if( maData
!= aOldData
)
416 maRuler
.ApplyLayout( aOldData
);
417 maGrid
.ApplyLayout( aOldData
);
424 IMPL_LINK( ScCsvTableBox
, ScrollHdl
, ScrollBar
*, pScrollBar
)
426 DBG_ASSERT( pScrollBar
, "ScCsvTableBox::ScrollHdl - missing sender" );
428 if( pScrollBar
== &maHScroll
)
429 Execute( CSVCMD_SETPOSOFFSET
, pScrollBar
->GetThumbPos() );
430 else if( pScrollBar
== &maVScroll
)
431 Execute( CSVCMD_SETLINEOFFSET
, pScrollBar
->GetThumbPos() );
436 IMPL_LINK( ScCsvTableBox
, ScrollEndHdl
, ScrollBar
*, pScrollBar
)
438 DBG_ASSERT( pScrollBar
, "ScCsvTableBox::ScrollEndHdl - missing sender" );
440 if( pScrollBar
== &maHScroll
)
442 if( GetRulerCursorPos() != CSV_POS_INVALID
)
443 Execute( CSVCMD_MOVERULERCURSOR
, maRuler
.GetNoScrollPos( GetRulerCursorPos() ) );
444 if( GetGridCursorPos() != CSV_POS_INVALID
)
445 Execute( CSVCMD_MOVEGRIDCURSOR
, maGrid
.GetNoScrollCol( GetGridCursorPos() ) );
452 // accessibility --------------------------------------------------------------
454 ScCsvTableBox::XAccessibleRef
ScCsvTableBox::CreateAccessible()
456 // do not use the ScCsvControl mechanism, return default accessible object
457 return Control::CreateAccessible();
460 ScAccessibleCsvControl
* ScCsvTableBox::ImplCreateAccessible()
462 return NULL
; // not used, see CreateAccessible()
466 // ============================================================================