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