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 <svx/simptabl.hxx>
30 : : #include <vcl/svapp.hxx>
31 : :
32 : : #include <comphelper/processfactory.hxx>
33 : : #include <unotools/intlwrapper.hxx>
34 : :
35 : : // SvxSimpleTableContainer ------------------------------------------------------
36 : :
37 : 0 : SvxSimpleTableContainer::SvxSimpleTableContainer( Window* pParent, const ResId& rResId)
38 : : : Control(pParent, rResId)
39 : 0 : , m_pTable(NULL)
40 : : {
41 [ # # ]: 0 : SetBorderStyle(WINDOW_BORDER_NOBORDER);
42 : 0 : }
43 : :
44 : 0 : void SvxSimpleTableContainer::SetTable(SvxSimpleTable* pTable)
45 : : {
46 : 0 : m_pTable = pTable;
47 : 0 : }
48 : :
49 : 0 : long SvxSimpleTableContainer::PreNotify( NotifyEvent& rNEvt )
50 : : {
51 : 0 : long nResult = sal_True;
52 [ # # ]: 0 : if ( rNEvt.GetType() == EVENT_KEYINPUT )
53 : : {
54 : 0 : const KeyCode& aKeyCode = rNEvt.GetKeyEvent()->GetKeyCode();
55 : 0 : sal_uInt16 nKey = aKeyCode.GetCode();
56 [ # # ]: 0 : if (nKey == KEY_TAB)
57 : 0 : GetParent()->Notify( rNEvt );
58 [ # # ][ # # ]: 0 : else if (m_pTable && m_pTable->IsFocusOnCellEnabled() && ( nKey == KEY_LEFT || nKey == KEY_RIGHT))
[ # # ][ # # ]
[ # # ]
59 : 0 : return 0;
60 : : else
61 : 0 : nResult = Control::PreNotify( rNEvt );
62 : : }
63 : : else
64 : 0 : nResult = Control::PreNotify( rNEvt );
65 : :
66 : 0 : return nResult;
67 : : }
68 : :
69 : 0 : void SvxSimpleTableContainer::SetSizePixel(const Size& rNewSize )
70 : : {
71 : 0 : Control::SetSizePixel(rNewSize);
72 [ # # ]: 0 : if (m_pTable)
73 : 0 : m_pTable->UpdateViewSize();
74 : 0 : }
75 : :
76 : 0 : void SvxSimpleTableContainer::GetFocus()
77 : : {
78 : 0 : Control::GetFocus();
79 [ # # ]: 0 : if (m_pTable)
80 : 0 : m_pTable->GrabFocus();
81 : 0 : }
82 : :
83 : : // SvxSimpleTable ------------------------------------------------------------
84 : :
85 : 0 : SvxSimpleTable::SvxSimpleTable(SvxSimpleTableContainer& rParent, WinBits nBits):
86 : : SvHeaderTabListBox(&rParent, nBits | WB_CLIPCHILDREN | WB_HSCROLL | WB_TABSTOP),
87 : : m_rParentTableContainer(rParent),
88 : : aHeaderBar(&rParent,WB_BUTTONSTYLE | WB_BORDER | WB_TABSTOP),
89 : : nHeaderItemId(1),
90 : : bResizeFlag(sal_False),
91 [ # # ][ # # ]: 0 : bPaintFlag(sal_True)
[ # # ][ # # ]
[ # # ]
92 : : {
93 [ # # ]: 0 : m_rParentTableContainer.SetTable(this);
94 : :
95 : 0 : bSortDirection=sal_True;
96 : 0 : nSortCol=0xFFFF;
97 : 0 : nOldPos=0;
98 : :
99 [ # # ]: 0 : aHeaderBar.SetStartDragHdl(LINK( this, SvxSimpleTable, StartDragHdl));
100 [ # # ]: 0 : aHeaderBar.SetDragHdl(LINK( this, SvxSimpleTable, DragHdl));
101 [ # # ]: 0 : aHeaderBar.SetEndDragHdl(LINK( this, SvxSimpleTable, EndDragHdl));
102 [ # # ]: 0 : aHeaderBar.SetSelectHdl(LINK( this, SvxSimpleTable, HeaderBarClick));
103 [ # # ]: 0 : aHeaderBar.SetDoubleClickHdl(LINK( this, SvxSimpleTable, HeaderBarDblClick));
104 : :
105 [ # # ]: 0 : EnableCellFocus();
106 [ # # ]: 0 : DisableTransientChildren();
107 [ # # ]: 0 : InitHeaderBar( &aHeaderBar );
108 : :
109 [ # # ]: 0 : UpdateViewSize();
110 : :
111 [ # # ]: 0 : aHeaderBar.Show();
112 [ # # ]: 0 : SvHeaderTabListBox::Show();
113 : 0 : }
114 : :
115 [ # # ]: 0 : SvxSimpleTable::~SvxSimpleTable()
116 : : {
117 [ # # ]: 0 : m_rParentTableContainer.SetTable(NULL);
118 [ # # ]: 0 : }
119 : :
120 : 0 : void SvxSimpleTable::UpdateViewSize()
121 : : {
122 [ # # ]: 0 : Size theWinSize=m_rParentTableContainer.GetSizePixel();
123 [ # # ]: 0 : Size HbSize=aHeaderBar.GetSizePixel();
124 : :
125 : 0 : HbSize.Width()=theWinSize.Width();
126 : 0 : theWinSize.Height()-=HbSize.Height();
127 : 0 : Point thePos(0,0);
128 : :
129 [ # # ]: 0 : aHeaderBar.SetPosPixel(thePos);
130 [ # # ]: 0 : aHeaderBar.SetSizePixel(HbSize);
131 : :
132 : 0 : thePos.Y()+=HbSize.Height();
133 [ # # ]: 0 : SvHeaderTabListBox::SetPosPixel(thePos);
134 [ # # ]: 0 : SvHeaderTabListBox::SetSizePixel(theWinSize);
135 [ # # ]: 0 : Invalidate();
136 : 0 : }
137 : :
138 : 0 : void SvxSimpleTable::NotifyScrolled()
139 : : {
140 : 0 : long nOffset=-GetXOffset();
141 [ # # ]: 0 : if(nOldPos!=nOffset)
142 : : {
143 : 0 : aHeaderBar.SetOffset(nOffset);
144 : 0 : aHeaderBar.Invalidate();
145 : 0 : aHeaderBar.Update();
146 : 0 : nOldPos=nOffset;
147 : : }
148 : 0 : SvHeaderTabListBox::NotifyScrolled();
149 : 0 : }
150 : :
151 : 0 : void SvxSimpleTable::SetTabs()
152 : : {
153 : 0 : SvHeaderTabListBox::SetTabs();
154 : :
155 : 0 : sal_uInt16 nPrivTabCount = TabCount();
156 [ # # ]: 0 : if ( nPrivTabCount )
157 : : {
158 [ # # ]: 0 : if ( nPrivTabCount > aHeaderBar.GetItemCount() )
159 : 0 : nPrivTabCount = aHeaderBar.GetItemCount();
160 : :
161 : 0 : sal_uInt16 i, nNewSize = static_cast< sal_uInt16 >( GetTab(0) ), nPos = 0;
162 [ # # ]: 0 : for ( i = 1; i < nPrivTabCount; ++i )
163 : : {
164 : 0 : nNewSize = static_cast< sal_uInt16 >( GetTab(i) ) - nPos;
165 : 0 : aHeaderBar.SetItemSize( i, nNewSize );
166 : 0 : nPos = (sal_uInt16)GetTab(i);
167 : : }
168 : :
169 : 0 : aHeaderBar.SetItemSize( i, HEADERBAR_FULLSIZE ); // because no tab for last entry
170 : : }
171 : 0 : }
172 : :
173 : 0 : void SvxSimpleTable::SetTabs( long* pTabs, MapUnit eMapUnit)
174 : : {
175 : 0 : SvHeaderTabListBox::SetTabs(pTabs,eMapUnit);
176 : 0 : }
177 : :
178 : 0 : void SvxSimpleTable::Paint( const Rectangle& rRect )
179 : : {
180 : 0 : SvHeaderTabListBox::Paint(rRect );
181 : :
182 : 0 : sal_uInt16 nPrivTabCount = TabCount();
183 [ # # ]: 0 : sal_uInt16 nNewSize = ( nPrivTabCount > 0 ) ? (sal_uInt16)GetTab(0) : 0;
184 : :
185 : 0 : long nOffset=-GetXOffset();
186 : 0 : nOldPos=nOffset;
187 : :
188 : 0 : aHeaderBar.SetOffset(nOffset);
189 : 0 : aHeaderBar.Invalidate();
190 : :
191 [ # # ][ # # ]: 0 : if(nPrivTabCount && bPaintFlag)
192 : : {
193 [ # # ]: 0 : if(nPrivTabCount>aHeaderBar.GetItemCount())
194 : 0 : nPrivTabCount=aHeaderBar.GetItemCount();
195 : :
196 : 0 : sal_uInt16 nPos = 0;
197 [ # # ]: 0 : for(sal_uInt16 i=1;i<nPrivTabCount;i++)
198 : : {
199 : 0 : nNewSize = static_cast< sal_uInt16 >( GetTab(i) ) - nPos;
200 : 0 : aHeaderBar.SetItemSize( i, nNewSize );
201 : 0 : nPos= static_cast< sal_uInt16 >( GetTab(i) );
202 : : }
203 : : }
204 : 0 : bPaintFlag=sal_True;
205 : 0 : }
206 : 0 : void SvxSimpleTable::InsertHeaderEntry(const rtl::OUString& rText,
207 : : sal_uInt16 nCol, HeaderBarItemBits nBits)
208 : : {
209 : 0 : sal_Int32 nEnd = rText.indexOf( sal_Unicode( '\t' ) );
210 [ # # ]: 0 : if( nEnd == -1 )
211 : : {
212 [ # # ]: 0 : aHeaderBar.InsertItem(nHeaderItemId++, rText, 0, nBits, nCol);
213 : : }
214 : : else
215 : : {
216 : 0 : sal_Int32 nIndex = 0;
217 [ # # ]: 0 : do
218 : : {
219 : 0 : rtl::OUString aString = rText.getToken(0, '\t', nIndex);
220 [ # # ][ # # ]: 0 : aHeaderBar.InsertItem(nHeaderItemId++, aString, 0, nBits, nCol);
[ # # ]
221 : : }
222 : : while ( nIndex >= 0 );
223 : : }
224 : 0 : SetTabs();
225 : 0 : }
226 : :
227 : 0 : void SvxSimpleTable::ClearHeader()
228 : : {
229 : 0 : aHeaderBar.Clear();
230 : 0 : }
231 : :
232 : 0 : void SvxSimpleTable::ShowTable()
233 : : {
234 : 0 : m_rParentTableContainer.Show();
235 : 0 : }
236 : :
237 : 0 : void SvxSimpleTable::HideTable()
238 : : {
239 : 0 : m_rParentTableContainer.Hide();
240 : 0 : }
241 : :
242 : 0 : sal_Bool SvxSimpleTable::IsVisible() const
243 : : {
244 : 0 : return m_rParentTableContainer.IsVisible();
245 : : }
246 : :
247 : 0 : void SvxSimpleTable::EnableTable()
248 : : {
249 : 0 : m_rParentTableContainer.Enable();
250 : 0 : }
251 : :
252 : 0 : void SvxSimpleTable::DisableTable()
253 : : {
254 : 0 : m_rParentTableContainer.Disable();
255 : 0 : }
256 : :
257 : 0 : sal_Bool SvxSimpleTable::IsEnabled() const
258 : : {
259 : 0 : return m_rParentTableContainer.IsEnabled();
260 : : }
261 : :
262 : 0 : sal_uInt16 SvxSimpleTable::GetSelectedCol()
263 : : {
264 : 0 : return (aHeaderBar.GetCurItemId()-1);
265 : : }
266 : :
267 : 0 : void SvxSimpleTable::SortByCol(sal_uInt16 nCol,sal_Bool bDir)
268 : : {
269 : 0 : bSortDirection=bDir;
270 [ # # ]: 0 : if(nSortCol!=0xFFFF)
271 : 0 : aHeaderBar.SetItemBits(nSortCol+1,HIB_STDSTYLE);
272 : :
273 [ # # ]: 0 : if (nCol != 0xFFFF)
274 : : {
275 [ # # ]: 0 : if(bDir)
276 : : {
277 : 0 : aHeaderBar.SetItemBits( nCol+1, HIB_STDSTYLE | HIB_DOWNARROW);
278 : 0 : GetModel()->SetSortMode(SortAscending);
279 : : }
280 : : else
281 : : {
282 : 0 : aHeaderBar.SetItemBits( nCol+1, HIB_STDSTYLE | HIB_UPARROW);
283 : 0 : GetModel()->SetSortMode(SortDescending);
284 : : }
285 : 0 : nSortCol=nCol;
286 : 0 : GetModel()->SetCompareHdl( LINK( this, SvxSimpleTable, CompareHdl));
287 : 0 : GetModel()->Resort();
288 : : }
289 : : else
290 : 0 : GetModel()->SetSortMode(SortNone);
291 : 0 : nSortCol=nCol;
292 : 0 : }
293 : :
294 : 0 : void SvxSimpleTable::HBarClick()
295 : : {
296 : 0 : sal_uInt16 nId=aHeaderBar.GetCurItemId();
297 : :
298 [ # # ]: 0 : if (aHeaderBar.GetItemBits(nId) & HIB_CLICKABLE)
299 : : {
300 [ # # ]: 0 : if(nId==nSortCol+1)
301 : : {
302 : 0 : SortByCol(nId-1,!bSortDirection);
303 : : }
304 : : else
305 : : {
306 : 0 : SortByCol(nId-1,bSortDirection);
307 : : }
308 : :
309 : 0 : aHeaderBarClickLink.Call(this);
310 : : }
311 : 0 : }
312 : :
313 : 0 : void SvxSimpleTable::HBarDblClick()
314 : : {
315 : 0 : aHeaderBarDblClickLink.Call(this);
316 : 0 : }
317 : :
318 : 0 : void SvxSimpleTable::HBarStartDrag()
319 : : {
320 [ # # ]: 0 : if(!aHeaderBar.IsItemMode())
321 : : {
322 : : Rectangle aSizeRect(Point(0,0),
323 [ # # ][ # # ]: 0 : SvHeaderTabListBox::GetOutputSizePixel());
324 : 0 : aSizeRect.Left()=-GetXOffset()+aHeaderBar.GetDragPos();
325 : 0 : aSizeRect.Right()=-GetXOffset()+aHeaderBar.GetDragPos();
326 [ # # ]: 0 : ShowTracking( aSizeRect, SHOWTRACK_SPLIT );
327 : : }
328 : 0 : }
329 : 0 : void SvxSimpleTable::HBarDrag()
330 : : {
331 : 0 : HideTracking();
332 [ # # ]: 0 : if(!aHeaderBar.IsItemMode())
333 : : {
334 : : Rectangle aSizeRect(Point(0,0),
335 [ # # ][ # # ]: 0 : SvHeaderTabListBox::GetOutputSizePixel());
336 : 0 : aSizeRect.Left()=-GetXOffset()+aHeaderBar.GetDragPos();
337 : 0 : aSizeRect.Right()=-GetXOffset()+aHeaderBar.GetDragPos();
338 [ # # ]: 0 : ShowTracking( aSizeRect, SHOWTRACK_SPLIT );
339 : : }
340 : 0 : }
341 : 0 : void SvxSimpleTable::HBarEndDrag()
342 : : {
343 : 0 : HideTracking();
344 : 0 : sal_uInt16 nPrivTabCount=TabCount();
345 : :
346 [ # # ]: 0 : if(nPrivTabCount)
347 : : {
348 [ # # ]: 0 : if(nPrivTabCount>aHeaderBar.GetItemCount())
349 : 0 : nPrivTabCount=aHeaderBar.GetItemCount();
350 : :
351 : 0 : sal_uInt16 nPos=0;
352 : 0 : sal_uInt16 nNewSize=0;
353 [ # # ]: 0 : for(sal_uInt16 i=1;i<nPrivTabCount;i++)
354 : : {
355 : 0 : nNewSize = static_cast< sal_uInt16 >( aHeaderBar.GetItemSize(i) ) + nPos;
356 : 0 : SetTab( i, nNewSize, MAP_PIXEL );
357 : 0 : nPos = nNewSize;
358 : : }
359 : : }
360 : 0 : bPaintFlag=sal_False;
361 : 0 : Invalidate();
362 : 0 : Update();
363 : 0 : }
364 : :
365 : 0 : CommandEvent SvxSimpleTable::GetCommandEvent() const
366 : : {
367 : 0 : return aCEvt;
368 : : }
369 : :
370 : 0 : void SvxSimpleTable::Command( const CommandEvent& rCEvt )
371 : : {
372 : 0 : aCEvt=rCEvt;
373 : 0 : aCommandLink.Call(this);
374 : 0 : SvHeaderTabListBox::Command(rCEvt);
375 : 0 : }
376 : :
377 : 0 : IMPL_LINK( SvxSimpleTable, StartDragHdl, HeaderBar*, pCtr)
378 : : {
379 [ # # ]: 0 : if(pCtr==&aHeaderBar)
380 : : {
381 : 0 : HBarStartDrag();
382 : : }
383 : 0 : return 0;
384 : : }
385 : :
386 : 0 : IMPL_LINK( SvxSimpleTable, DragHdl, HeaderBar*, pCtr)
387 : : {
388 [ # # ]: 0 : if(pCtr==&aHeaderBar)
389 : : {
390 : 0 : HBarDrag();
391 : : }
392 : 0 : return 0;
393 : : }
394 : :
395 : 0 : IMPL_LINK( SvxSimpleTable, EndDragHdl, HeaderBar*, pCtr)
396 : : {
397 [ # # ]: 0 : if(pCtr==&aHeaderBar)
398 : : {
399 : 0 : HBarEndDrag();
400 : : }
401 : 0 : return 0;
402 : : }
403 : :
404 : 0 : IMPL_LINK( SvxSimpleTable, HeaderBarClick, HeaderBar*, pCtr)
405 : : {
406 [ # # ]: 0 : if(pCtr==&aHeaderBar)
407 : : {
408 : 0 : HBarClick();
409 : : }
410 : 0 : return 0;
411 : : }
412 : :
413 : 0 : IMPL_LINK( SvxSimpleTable, HeaderBarDblClick, HeaderBar*, pCtr)
414 : : {
415 [ # # ]: 0 : if(pCtr==&aHeaderBar)
416 : : {
417 : 0 : HBarDblClick();
418 : : }
419 : 0 : return 0;
420 : : }
421 : :
422 : 0 : SvLBoxItem* SvxSimpleTable::GetEntryAtPos( SvLBoxEntry* pEntry, sal_uInt16 nPos ) const
423 : : {
424 : : DBG_ASSERT(pEntry,"GetEntryText:Invalid Entry");
425 : 0 : SvLBoxItem* pItem = NULL;
426 : :
427 [ # # ]: 0 : if( pEntry )
428 : : {
429 : 0 : sal_uInt16 nCount = pEntry->ItemCount();
430 : :
431 : 0 : nPos++;
432 : :
433 [ # # ]: 0 : if( nTreeFlags & TREEFLAG_CHKBTN ) nPos++;
434 : :
435 [ # # ]: 0 : if( nPos < nCount )
436 : : {
437 : 0 : pItem = pEntry->GetItem( nPos);
438 : : }
439 : : }
440 : 0 : return pItem;
441 : : }
442 : :
443 : 0 : StringCompare SvxSimpleTable::ColCompare(SvLBoxEntry* pLeft,SvLBoxEntry* pRight)
444 : : {
445 : 0 : StringCompare eCompare=COMPARE_EQUAL;
446 : :
447 : 0 : SvLBoxItem* pLeftItem = GetEntryAtPos( pLeft, nSortCol);
448 : 0 : SvLBoxItem* pRightItem = GetEntryAtPos( pRight, nSortCol);
449 : :
450 : :
451 [ # # ][ # # ]: 0 : if(pLeftItem != NULL && pRightItem != NULL)
452 : : {
453 : 0 : sal_uInt16 nLeftKind=pLeftItem->IsA();
454 : 0 : sal_uInt16 nRightKind=pRightItem->IsA();
455 : :
456 [ # # ][ # # ]: 0 : if(nRightKind == SV_ITEM_ID_LBOXSTRING &&
457 : : nLeftKind == SV_ITEM_ID_LBOXSTRING )
458 : : {
459 [ # # ][ # # ]: 0 : IntlWrapper aIntlWrapper( ::comphelper::getProcessServiceFactory(), Application::GetSettings().GetLocale() );
[ # # ][ # # ]
460 [ # # ]: 0 : const CollatorWrapper* pCollator = aIntlWrapper.getCaseCollator();
461 : :
462 : : eCompare=(StringCompare)pCollator->compareString( ((SvLBoxString*)pLeftItem)->GetText(),
463 [ # # ]: 0 : ((SvLBoxString*)pRightItem)->GetText());
464 : :
465 [ # # ][ # # ]: 0 : if(eCompare==COMPARE_EQUAL) eCompare=COMPARE_LESS;
466 : : }
467 : : }
468 : 0 : return eCompare;
469 : : }
470 : :
471 : 0 : IMPL_LINK( SvxSimpleTable, CompareHdl, SvSortData*, pData)
472 : : {
473 : 0 : SvLBoxEntry* pLeft = (SvLBoxEntry*)(pData->pLeft );
474 : 0 : SvLBoxEntry* pRight = (SvLBoxEntry*)(pData->pRight );
475 : 0 : return (long) ColCompare(pLeft,pRight);
476 : : }
477 : :
478 : :
479 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|