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: simptabl.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_svx.hxx"
34 // INCLUDE -------------------------------------------------------------------
36 #include <svx/simptabl.hxx>
37 #include <vcl/svapp.hxx>
39 #ifndef _UNOTOOLS_PROCESSFACTORY_HXX
40 #include <comphelper/processfactory.hxx>
42 #include <unotools/intlwrapper.hxx>
44 // SvxSimpTblContainer ------------------------------------------------------
46 SvxSimpTblContainer::SvxSimpTblContainer( Window
* pParent
, WinBits nWinStyle
):
47 Control(pParent
,nWinStyle
)
52 SvxSimpTblContainer::SvxSimpTblContainer( Window
* pParent
, const ResId
& rResId
):
53 Control(pParent
,rResId
)
58 long SvxSimpTblContainer::PreNotify( NotifyEvent
& rNEvt
)
61 if ( rNEvt
.GetType() == EVENT_KEYINPUT
)
63 const KeyCode
& aKeyCode
= rNEvt
.GetKeyEvent()->GetKeyCode();
64 USHORT nKey
= aKeyCode
.GetCode();
65 if ( nKey
== KEY_TAB
)
66 GetParent()->Notify( rNEvt
);
67 else if ( m_pTable
->IsFocusOnCellEnabled() && ( nKey
== KEY_LEFT
|| nKey
== KEY_RIGHT
) )
70 nResult
= Control::PreNotify( rNEvt
);
73 nResult
= Control::PreNotify( rNEvt
);
79 // SvxSimpleTable ------------------------------------------------------------
81 SvxSimpleTable::SvxSimpleTable( Window
* pParent
,WinBits nBits
):
82 SvHeaderTabListBox(pParent
,WB_CLIPCHILDREN
| WB_HSCROLL
| WB_TABSTOP
),
83 aPrivContainer(pParent
,nBits
|WB_DIALOGCONTROL
),
84 aHeaderBar(pParent
,WB_BUTTONSTYLE
| WB_BORDER
| WB_TABSTOP
),
93 SetParent(&aPrivContainer
);
94 aHeaderBar
.SetParent(&aPrivContainer
);
95 aPrivContainer
.SetTable( this );
97 aHeaderBar
.SetStartDragHdl(LINK( this, SvxSimpleTable
, StartDragHdl
));
98 aHeaderBar
.SetDragHdl(LINK( this, SvxSimpleTable
, DragHdl
));
99 aHeaderBar
.SetEndDragHdl(LINK( this, SvxSimpleTable
, EndDragHdl
));
100 aHeaderBar
.SetSelectHdl(LINK( this, SvxSimpleTable
, HeaderBarClick
));
101 aHeaderBar
.SetDoubleClickHdl(LINK( this, SvxSimpleTable
, HeaderBarDblClick
));
104 DisableTransientChildren();
105 InitHeaderBar( &aHeaderBar
);
108 SvHeaderTabListBox::Show();
112 SvxSimpleTable::SvxSimpleTable( Window
* pParent
,const ResId
& rResId
):
113 SvHeaderTabListBox(pParent
,WB_CLIPCHILDREN
| WB_HSCROLL
| WB_TABSTOP
),
114 aPrivContainer(pParent
,rResId
),
115 aHeaderBar(pParent
,WB_BUTTONSTYLE
| WB_BORDER
| WB_TABSTOP
),
125 pMyParentWin
=pParent
;
126 SetParent(&aPrivContainer
);
127 aHeaderBar
.SetParent(&aPrivContainer
);
128 aPrivContainer
.SetTable( this );
130 WinBits nBits
=aPrivContainer
.GetStyle()|WB_DIALOGCONTROL
;
131 aPrivContainer
.SetStyle(nBits
);
133 aHeaderBar
.SetStartDragHdl(LINK( this, SvxSimpleTable
, StartDragHdl
));
134 aHeaderBar
.SetDragHdl(LINK( this, SvxSimpleTable
, DragHdl
));
135 aHeaderBar
.SetEndDragHdl(LINK( this, SvxSimpleTable
, EndDragHdl
));
136 aHeaderBar
.SetSelectHdl(LINK( this, SvxSimpleTable
, HeaderBarClick
));
137 aHeaderBar
.SetDoubleClickHdl(LINK( this, SvxSimpleTable
, HeaderBarDblClick
));
139 Size theWinSize
=aPrivContainer
.GetOutputSizePixel();
140 Size HbSize
=aHeaderBar
.GetSizePixel();
142 HbSize
.Width()=theWinSize
.Width();
143 theWinSize
.Height()-=HbSize
.Height();
146 aHeaderBar
.SetPosPixel(thePos
);
147 aHeaderBar
.SetSizePixel(HbSize
);
149 thePos
.Y()+=HbSize
.Height();
150 SvHeaderTabListBox::SetPosPixel(thePos
);
151 SvHeaderTabListBox::SetSizePixel(theWinSize
);
154 DisableTransientChildren();
155 InitHeaderBar( &aHeaderBar
);
158 SetWindowBits(WB_CLIPCHILDREN
| WB_HSCROLL
);
159 SvHeaderTabListBox::Show();
162 SvxSimpleTable::~SvxSimpleTable()
164 SetParent(pMyParentWin
);
165 aPrivContainer
.SetParent(this);
166 aHeaderBar
.SetParent(this);
170 void SvxSimpleTable::UpdateViewSize()
172 Size theWinSize
=aPrivContainer
.GetOutputSizePixel();
173 Size HbSize
=aHeaderBar
.GetSizePixel();
175 HbSize
.Width()=theWinSize
.Width();
176 theWinSize
.Height()-=HbSize
.Height();
179 aHeaderBar
.SetPosPixel(thePos
);
180 aHeaderBar
.SetSizePixel(HbSize
);
182 thePos
.Y()+=HbSize
.Height();
183 SvHeaderTabListBox::SetPosPixel(thePos
);
184 SvHeaderTabListBox::SetSizePixel(theWinSize
);
188 void SvxSimpleTable::NotifyScrolled()
190 long nOffset
=-GetXOffset();
193 aHeaderBar
.SetOffset(nOffset
);
194 aHeaderBar
.Invalidate();
198 SvHeaderTabListBox::NotifyScrolled();
201 void SvxSimpleTable::SetTabs()
203 SvHeaderTabListBox::SetTabs();
205 USHORT nPrivTabCount
= TabCount();
208 if ( nPrivTabCount
> aHeaderBar
.GetItemCount() )
209 nPrivTabCount
= aHeaderBar
.GetItemCount();
211 USHORT i
, nNewSize
= static_cast< USHORT
>( GetTab(0) ), nPos
= 0;
212 for ( i
= 1; i
< nPrivTabCount
; ++i
)
214 nNewSize
= static_cast< USHORT
>( GetTab(i
) ) - nPos
;
215 aHeaderBar
.SetItemSize( i
, nNewSize
);
216 nPos
= (USHORT
)GetTab(i
);
219 aHeaderBar
.SetItemSize( i
, HEADERBAR_FULLSIZE
); // because no tab for last entry
223 void SvxSimpleTable::SetTabs( long* pTabs
, MapUnit eMapUnit
)
225 SvHeaderTabListBox::SetTabs(pTabs
,eMapUnit
);
228 void SvxSimpleTable::Paint( const Rectangle
& rRect
)
230 SvHeaderTabListBox::Paint(rRect
);
232 USHORT nPrivTabCount
= TabCount();
234 USHORT nNewSize
= ( nPrivTabCount
> 0 ) ? (USHORT
)GetTab(0) : 0;
236 long nOffset
=-GetXOffset();
239 aHeaderBar
.SetOffset(nOffset
);
240 aHeaderBar
.Invalidate();
242 if(nPrivTabCount
&& bPaintFlag
)
244 if(nPrivTabCount
>aHeaderBar
.GetItemCount())
245 nPrivTabCount
=aHeaderBar
.GetItemCount();
247 for(USHORT i
=1;i
<nPrivTabCount
;i
++)
249 nNewSize
= static_cast< USHORT
>( GetTab(i
) ) - nPos
;
250 aHeaderBar
.SetItemSize( i
, nNewSize
);
251 nPos
= static_cast< USHORT
>( GetTab(i
) );
256 void SvxSimpleTable::InsertHeaderEntry(const XubString
& rText
,USHORT nCol
,
257 HeaderBarItemBits nBits
)
259 xub_StrLen nEnd
= rText
.Search( sal_Unicode( '\t' ) );
260 if( nEnd
== STRING_NOTFOUND
)
262 aHeaderBar
.InsertItem(nHeaderItemId
++, rText
, 0, nBits
, nCol
);
266 xub_StrLen nCount
= rText
.GetTokenCount( sal_Unicode( '\t' ) );
268 for( xub_StrLen i
=0; i
<nCount
; i
++ )
270 String aString
=rText
.GetToken(i
, sal_Unicode( '\t' ) );
271 aHeaderBar
.InsertItem(nHeaderItemId
++, aString
, 0, nBits
, nCol
);
277 void SvxSimpleTable::ClearAll()
282 void SvxSimpleTable::ClearHeader()
287 void SvxSimpleTable::ShowTable()
289 aPrivContainer
.Show();
292 void SvxSimpleTable::HideTable()
294 aPrivContainer
.Show();
297 BOOL
SvxSimpleTable::IsVisible() const
299 return aPrivContainer
.IsVisible();
302 void SvxSimpleTable::EnableTable()
304 aPrivContainer
.Enable();
307 void SvxSimpleTable::DisableTable()
309 aPrivContainer
.Disable();
312 BOOL
SvxSimpleTable::IsEnabled() const
314 return aPrivContainer
.IsEnabled();
317 void SvxSimpleTable::TableToTop()
319 aPrivContainer
.ToTop();
322 void SvxSimpleTable::SetPosPixel( const Point
& rNewPos
)
324 aPrivContainer
.SetPosPixel(rNewPos
);
327 Point
SvxSimpleTable::GetPosPixel() const
329 return aPrivContainer
.GetPosPixel();
332 void SvxSimpleTable::SetPosSizePixel( const Point
& rNewPos
, Size
& rNewSize
)
334 aPrivContainer
.SetPosPixel(rNewPos
);
335 aPrivContainer
.SetSizePixel(rNewSize
);
338 void SvxSimpleTable::SetPosSize( const Point
& rNewPos
, const Size
& rNewSize
)
340 aPrivContainer
.SetPosPixel(rNewPos
);
341 SvHeaderTabListBox::SetPosSizePixel(rNewPos
,rNewSize
);
344 Size
SvxSimpleTable::GetSizePixel() const
346 return aPrivContainer
.GetSizePixel();
349 Size
SvxSimpleTable::GetOutputSizePixel() const
351 return aPrivContainer
.GetOutputSizePixel();
354 void SvxSimpleTable::SetSizePixel(const Size
& rNewSize
)
356 aPrivContainer
.SetSizePixel(rNewSize
);
360 void SvxSimpleTable::SetOutputSizePixel(const Size
& rNewSize
)
362 aPrivContainer
.SetOutputSizePixel(rNewSize
);
366 USHORT
SvxSimpleTable::GetSelectedCol()
368 return (aHeaderBar
.GetCurItemId()-1);
371 void SvxSimpleTable::SortByCol(USHORT nCol
,BOOL bDir
)
375 aHeaderBar
.SetItemBits(nSortCol
+1,HIB_STDSTYLE
);
381 aHeaderBar
.SetItemBits( nCol
+1, HIB_STDSTYLE
| HIB_DOWNARROW
);
382 GetModel()->SetSortMode(SortAscending
);
386 aHeaderBar
.SetItemBits( nCol
+1, HIB_STDSTYLE
| HIB_UPARROW
);
387 GetModel()->SetSortMode(SortDescending
);
390 GetModel()->SetCompareHdl( LINK( this, SvxSimpleTable
, CompareHdl
));
391 GetModel()->Resort();
394 GetModel()->SetSortMode(SortNone
);
398 void SvxSimpleTable::HBarClick()
400 USHORT nId
=aHeaderBar
.GetCurItemId();
402 if (aHeaderBar
.GetItemBits(nId
) & HIB_CLICKABLE
)
406 SortByCol(nId
-1,!bSortDirection
);
410 SortByCol(nId
-1,bSortDirection
);
413 aHeaderBarClickLink
.Call(this);
417 void SvxSimpleTable::HBarDblClick()
419 aHeaderBarDblClickLink
.Call(this);
422 void SvxSimpleTable::HBarStartDrag()
424 if(!aHeaderBar
.IsItemMode())
426 Rectangle
aSizeRect(Point(0,0),
427 SvHeaderTabListBox::GetOutputSizePixel());
428 aSizeRect
.Left()=-GetXOffset()+aHeaderBar
.GetDragPos();
429 aSizeRect
.Right()=-GetXOffset()+aHeaderBar
.GetDragPos();
430 ShowTracking( aSizeRect
, SHOWTRACK_SPLIT
);
433 void SvxSimpleTable::HBarDrag()
436 if(!aHeaderBar
.IsItemMode())
438 Rectangle
aSizeRect(Point(0,0),
439 SvHeaderTabListBox::GetOutputSizePixel());
440 aSizeRect
.Left()=-GetXOffset()+aHeaderBar
.GetDragPos();
441 aSizeRect
.Right()=-GetXOffset()+aHeaderBar
.GetDragPos();
442 ShowTracking( aSizeRect
, SHOWTRACK_SPLIT
);
445 void SvxSimpleTable::HBarEndDrag()
448 USHORT nPrivTabCount
=TabCount();
454 if(nPrivTabCount
>aHeaderBar
.GetItemCount())
455 nPrivTabCount
=aHeaderBar
.GetItemCount();
457 //for(USHORT i=1;i<=nPrivTabCount;i++)
458 for(USHORT i
=1;i
<nPrivTabCount
;i
++)
460 nNewSize
= static_cast< USHORT
>( aHeaderBar
.GetItemSize(i
) ) + nPos
;
461 SetTab( i
, nNewSize
, MAP_PIXEL
);
470 CommandEvent
SvxSimpleTable::GetCommandEvent() const
475 void SvxSimpleTable::Command( const CommandEvent
& rCEvt
)
478 aCommandLink
.Call(this);
479 SvHeaderTabListBox::Command(rCEvt
);
482 IMPL_LINK( SvxSimpleTable
, StartDragHdl
, HeaderBar
*, pCtr
)
484 if(pCtr
==&aHeaderBar
)
491 IMPL_LINK( SvxSimpleTable
, DragHdl
, HeaderBar
*, pCtr
)
493 if(pCtr
==&aHeaderBar
)
500 IMPL_LINK( SvxSimpleTable
, EndDragHdl
, HeaderBar
*, pCtr
)
502 if(pCtr
==&aHeaderBar
)
509 IMPL_LINK( SvxSimpleTable
, HeaderBarClick
, HeaderBar
*, pCtr
)
511 if(pCtr
==&aHeaderBar
)
518 IMPL_LINK( SvxSimpleTable
, HeaderBarDblClick
, HeaderBar
*, pCtr
)
520 if(pCtr
==&aHeaderBar
)
527 SvLBoxItem
* SvxSimpleTable::GetEntryAtPos( SvLBoxEntry
* pEntry
, USHORT nPos
) const
529 DBG_ASSERT(pEntry
,"GetEntryText:Invalid Entry");
530 SvLBoxItem
* pItem
= NULL
;
534 USHORT nCount
= pEntry
->ItemCount();
538 if( nTreeFlags
& TREEFLAG_CHKBTN
) nPos
++;
542 pItem
= pEntry
->GetItem( nPos
);
548 StringCompare
SvxSimpleTable::ColCompare(SvLBoxEntry
* pLeft
,SvLBoxEntry
* pRight
)
550 StringCompare eCompare
=COMPARE_EQUAL
;
552 SvLBoxItem
* pLeftItem
= GetEntryAtPos( pLeft
, nSortCol
);
553 SvLBoxItem
* pRightItem
= GetEntryAtPos( pRight
, nSortCol
);
556 if(pLeftItem
!= NULL
&& pRightItem
!= NULL
)
558 USHORT nLeftKind
=pLeftItem
->IsA();
559 USHORT nRightKind
=pRightItem
->IsA();
561 if(nRightKind
== SV_ITEM_ID_LBOXSTRING
&&
562 nLeftKind
== SV_ITEM_ID_LBOXSTRING
)
564 IntlWrapper
aIntlWrapper( ::comphelper::getProcessServiceFactory(), Application::GetSettings().GetLocale() );
565 const CollatorWrapper
* pCollator
= aIntlWrapper
.getCaseCollator();
567 eCompare
=(StringCompare
)pCollator
->compareString( ((SvLBoxString
*)pLeftItem
)->GetText(),
568 ((SvLBoxString
*)pRightItem
)->GetText());
570 if(eCompare
==COMPARE_EQUAL
) eCompare
=COMPARE_LESS
;
576 IMPL_LINK( SvxSimpleTable
, CompareHdl
, SvSortData
*, pData
)
578 SvLBoxEntry
* pLeft
= (SvLBoxEntry
*)(pData
->pLeft
);
579 SvLBoxEntry
* pRight
= (SvLBoxEntry
*)(pData
->pRight
);
580 return (long) ColCompare(pLeft
,pRight
);