2
* Copyright 2010 Inalogic Inc.
4
* This program is free software: you can redistribute it and/or modify it
5
* under the terms of the GNU Lesser General Public License version 3, as
6
* published by the Free Software Foundation.
8
* This program is distributed in the hope that it will be useful, but
9
* WITHOUT ANY WARRANTY; without even the implied warranties of
10
* MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR
11
* PURPOSE. See the applicable version of the GNU Lesser General Public
12
* License for more details.
14
* You should have received a copy of both the GNU Lesser General Public
15
* License version 3 along with this program. If not, see
16
* <http://www.gnu.org/licenses/>
18
* Authored by: Jay Taoko <jay.taoko_AT_gmail_DOT_com>
26
#include "TableItem.h"
27
#include "ScrollView.h"
32
extern const int ROWHEADERWIDTH;
33
extern const int OPENCLOSE_BTN_WIDTH;
34
extern const int ITEM_DEPTH_MARGIN;
35
extern const int MIN_COLUMN_WIDTH;
36
extern const int TABLE_AREA_BOTTOM_SPACE;
37
extern const int COLUMNHEADERHEIGHT;
44
typedef CoreArea sizehandler2;
46
class TableCtrl: public ScrollView
52
Construct the TableCtrl class. The parameter <B><VAR>floating_column</VAR></B> columns can be resized past the size of the content view area.
53
@param floating_column set the column as floating. Default is set to true
54
@see SetFloatingColumn()
55
@see isFloatingColumn()
57
TableCtrl (bool floating_column = true);
60
virtual long ProcessEvent (IEvent &ievent, long TraverseInfo, long ProcessEventInfo);
62
virtual void Draw (GraphicsEngine &GfxContext, bool force_draw);
63
virtual void DrawContent (GraphicsEngine &GfxContext, bool force_draw);
64
virtual void PostDraw (GraphicsEngine &GfxContext, bool force_draw);
65
void DrawTable (GraphicsEngine &GfxContext);
66
void DrawHeader (GraphicsEngine &GfxContext);
67
void DrawHeaderPreview (GraphicsEngine &GfxContext);
68
void OverlayDrawing (GraphicsEngine &GfxContext);
71
void addHeader (const TCHAR *name, bool fixed_width = false, int column_width = 10);
74
@return The total width of the header;
78
//! Add a column to the table.
80
Add a column to the table.
82
@param title The title of the column.
83
@param fixed_wided True if the column should have a fixed width.
84
@param width The width of the column. This parameter is used if the width is not fixed.
86
virtual void AddColumn (const TCHAR *column_name, bool fixed_width = false, int column_width = 10);
89
//! Add a row item. Used internally.
93
virtual void AddItem (TableItem *item /*const TCHAR* item_name*/);
95
typedef void (TableCtrl::*ItemOperator) (TableItem *);
98
Add an item has a direct child of the Root of the Table. The root of the Table is never displayed.
99
Only its children are displayed.
100
@param item The item to add.
101
@param isOpen If TRUE, the item will .
103
void setTableItems (TableItem *item, bool isOpen = false);
104
//! Add a table item as a child of the root node of the table controller.
105
void AddTableItem (TableItem *item);
107
Repopulate the table starting at the root node. Recreate the m_row_header.
110
void TraverseItem (TableItem *item, bool open_only, ItemOperator);
112
Delete the row size handler. All elements are delete.
114
void DeleteRowSizeHandler();
116
Delete the row header. All elements are delete.
118
void DeleteRowHeader();
123
int m_OpenItemTotalHeight;
125
void OpBuildItemDepth (TableItem *item, int depth);
126
void OpAddItem (TableItem *item);
127
void OpCloseItem (TableItem *item);
128
void OpOpenItem (TableItem *item);
129
void OpHideItem (TableItem *item);
130
void OpShowItem (TableItem *item);
132
//! EnableResizing the height of row headers.
134
Enable the resizing to row headers by dragging the line at the bottom of the row.
136
virtual void EnableRowResizing (bool b)
138
m_bEnableRowResizing = b;
141
//! EnableResizing the width of column headers.
143
Enable the resizing to column headers by dragging the line at the right of the column.
145
virtual void EnableColumnResizing (bool b)
147
m_bEnableColumnResizing = b;
149
//! Show the row headers.
151
Show the row headers. Rows are numbered from 0 to the number of row - 1.
153
virtual void ShowRowHeader (bool b);
154
//! Show the column headers.
156
Show the column headers. Columns are titled according to the name given when addColumn() is called.
158
virtual void ShowColumnHeader (bool b);
160
//! Show the columns vertical separation lines.
162
Show the columns vertical separation lines.
163
@param b If b is true the vertical separation lines are visible.
165
void ShowVerticalSeparationLine (bool b);
167
//! Show the rows horizontal separation lines.
169
Show the rows horizontal separation lines.
170
@param b If b is true the horizontal separation lines are visible.
172
void ShowHorizontalSeparationLine (bool b);
174
void ShowSeparationLine (bool bHor, bool bVert);
176
void ClickSelectRow();
177
void ClickSelectColumn();
178
void ClickSelectCell();
180
//! Paint Decoration.
182
Paint the item hierarchy, open/close decoration in the first column.
183
@param item The item whose decoration must be drawn.
185
virtual void PaintDecoration (GraphicsEngine &GfxContext, TableItem *item);
187
//! Paint Item row header decoration.
189
@param item The item whose row header must be drawn.
191
virtual void PaintRowDecoration (GraphicsEngine &GfxContext, TableItem *item, Color color);
192
//! Paint Item Background.
194
Paint Item Background. Also push the background on the painter background stack.
196
@return The number of background pushed onto the painter stack.
198
UINT PushItemBackground (GraphicsEngine &GfxContext, TableItem *item, bool MouseOver = false);
200
//! Pop the item background pushed on the painter stack.
202
Pop the item background pushed on the painter stack.
204
@param NumBackground The number of background to pop of the painter stack.
206
void PopItemBackground (GraphicsEngine &GfxContext, UINT NumBackground);
208
//! Enable row to have a height fixed by the contained item.
210
Enable row to have a height fixed by the contained item.
212
void EnableApplyItemBestHeight (bool b);
214
//! Set ItemBackgroundColor when the mouse is over the Item.
216
Set ItemBackgroundColor when the mouse is over the Item.
217
This color supersedes other background colors.
219
void SetMouseOverColor (Color color)
221
m_MouseOverColor = color;
223
//! Return the user defined color used as background color when the mouse is over the item.
225
@return the user defined color used as background color when the mouse is over the item.
227
Color GetMouseOverColor()
229
return m_MouseOverColor;
231
//! Enable the use of a user defined color when the mouse is over the item.
233
@param b If b is True the user defined color replaces the background color when the mouse is over the item.
235
void EnableMouseOverColor (bool b)
237
m_IsEnableMouseOverColor = b;
240
void SetRowColorOdd (Color color)
242
m_RowColorOdd = color;
245
Color GetRowColorOdd() const
247
return m_RowColorOdd;
250
void SetRowColorEven (Color color)
252
m_RowColorEven = color;
255
Color GetRowColorEven() const
257
return m_RowColorEven;
260
void SetRowColor (Color evencolor, Color oddcolor)
262
m_RowColorEven = evencolor;
263
m_RowColorOdd = oddcolor;
265
void SetHorizontalSeparationLineColor (Color color)
267
m_HorizontalSeparationLineColor = color;
270
Color GetHorizontalSeparationLineColor() const
272
return m_HorizontalSeparationLineColor;
275
void SetVerticalSeparationLineColor (Color color)
277
m_VerticalSeparationLineColor = color;
280
Color GetVerticalSeparationLineColor() const
282
return m_VerticalSeparationLineColor;
285
void SetSeparationLineColor (const Color &horcolor, const Color &vertcolor)
287
m_HorizontalSeparationLineColor = horcolor;
288
m_VerticalSeparationLineColor = vertcolor;
291
//! Return true if this object can break the layout.
293
Return true if this object can break the layout, meaning, the layout can be done on the composition layout only without
294
recomputing the whole window layout.
297
virtual bool CanBreakLayout()
299
if (IsSizeMatchContent() )
307
void UsedForComboBox (bool b)
309
m_IsPartOfComboBox = b;
311
bool IsPartOfCombobox() const
313
return m_IsPartOfComboBox;
315
bool m_IsPartOfComboBox;
318
When the tableCtrl is used in a combo box, it only shows the content and the TableArea is fully exposed.
319
Sometimes we need force the focus on that TableArea.
321
void ForceStartFocusOnContentTable (int x, int y);
323
Color m_MouseOverColor;
324
bool m_IsEnableMouseOverColor;
327
//! set Floating column.
329
Set if the header have floating columns or not. With floating column, the total width of
330
the headers may be greater that the width of the content view area (the horizontal scrollbar will reflect that).
331
With non floating columns, the sum of all headers width is exactly equal to the width of the content view area.
333
@see isFloatingColumn()
335
void SetFloatingColumn (bool b);
337
//! Return true if the columns are floating.
339
Return true if the columns are floating.
341
@see SetFloatingColumn()
343
bool isFloatingColumn();
345
//! Get information about the item below the pointer.
349
void FindItemUnderPointer (int x, int y, TableItem **ppItem, int &row, int &column);
351
void SetSelectionColor (const Color &color)
353
m_SelectionColor = color;
356
const Color GetSelectionColor()
358
return m_SelectionColor;
361
TableItem *GetSelectedItem()
363
return m_selectedTableItem;
366
t_u32 GetSelectedRow()
368
return m_selectedRow;
371
t_u32 GetSelectedColumn()
373
return m_selectedColumn;
376
//! Get the number of column in the table.
378
Get the number of column in the table.
379
@return the number of column.
381
t_s32 GetNumColumn();
383
//! Get the number of row in the table.
385
Get the number of row in the table.
386
@return the number of row.
390
//! reset Items flags.
392
Reset the dirty flag of items.
398
@return const TableItem*
400
const TableItem *GetRootNode() const
402
return m_TableItemHead;
408
TableItem *GetRootNode()
410
return m_TableItemHead;
414
Get number of child element of the root node.
416
int GetNumRootChild() const
418
return m_TableItemHead->NumChild();
422
Delete all elements of the tabled below the root node.
426
void HighlightItem (int row, int column);
431
// OnMouseDoubleClick and OnMouseDown have a custom implementation in TreeView. We need to make them virtual.
432
virtual void OnMouseDoubleClick (int x, int y, unsigned long button_flags, unsigned long key_flags);
433
virtual void OnMouseDown (int x, int y, unsigned long button_flags, unsigned long key_flags);
434
void OnMouseUp (int x, int y, unsigned long button_flags, unsigned long key_flags);
435
void OnMouseDrag (int x, int y, int dx, int dy, unsigned long button_flags, unsigned long key_flags);
436
void OnKeyboardFocus();
437
void OnLostKeyboardFocus();
438
void OnResizeHeaderMouseDown (int x, int y, unsigned long button_flags, unsigned long key_flags, t_u32 header_pos);
439
void OnResizeHeaderMouseUp (int x, int y, unsigned long button_flags, unsigned long key_flags, t_u32 header_pos);
440
void OnResizeHeaderMouseDrag (int x, int y, int dx, int dy, unsigned long button_flags, unsigned long key_flags, t_u32 header_pos);
442
void OnResizeRowMouseDown (int x, int y, unsigned long button_flags, unsigned long key_flags, t_u32 header_pos);
443
void OnResizeRowMouseDrag (int x, int y, int dx, int dy, unsigned long button_flags, unsigned long key_flags, t_u32 header_pos);
449
sigc::signal<void, int, int> sigItemSelected;
450
sigc::signal<void, const TableItem &> sigItemChange;
451
sigc::signal<void, TableCtrl &, TableItem &, int, int> sigTableItemSelected;
453
sigc::signal<void> sigLostFocus;
457
// for debugging purpose to find out who called NeedReedraw for the TableCtrl.
460
virtual void SetGeometry (const Geometry &geo);
461
friend class ComboBoxComplex;
462
friend class ComboBoxSimple;
465
Distribute the width to headers equally, except for fix-width headers.
466
ComputeNonFloatingColumn is called when a new column is added to the table.
468
void ComputeNonFloatingColumn();
471
This function member computes the size of the headers for a non-floating column table.
472
Given the m_ViewWidth, the width of the view content area. AdjustNonFloatingColumn rescale the width of headers so they
473
fit within the width of the view content area. The new width of each headers respect the its current scales compare to other headers.
474
Fix-width columns remain unchanged.
476
void AdjustNonFloatingColumn();
478
virtual void PreLayoutManagement();
479
virtual long PostLayoutManagement (long LayoutResult);
480
virtual void PositionChildLayout (float offsetX, float offsetY);
485
virtual void ScrollLeft (float stepx, int mousedx);
486
virtual void ScrollRight (float stepx, int mousedx);
487
virtual void ScrollUp (float stepy, int mousedy);
488
virtual void ScrollDown (float stepy, int mousedy);
493
CoreArea *m_TableArea;
497
int m_tableNumColumn;
500
int m_selectedColumn;
501
Geometry m_selectedGeometry;
503
TableItem *m_selectedTableItem;
504
TableItem *m_selectedMouseDownTableItem;
505
TableItem *m_TableItemHead;
507
bool m_bEnableRowResizing;
508
bool m_bEnableColumnResizing;
509
bool m_bShowRowHeader;
510
bool m_bShowColumnHeader;
511
bool m_bShowVerticalSeparationLine;
512
bool m_bShowHorizontalSeparationLine;
513
bool m_bEnableItemBestHeight;
515
std::vector<RowHeader *> m_row_header;
516
//std::vector<Geometry> m_column;
517
std::vector<ColumnHeader> m_column_header;
518
std::vector<ColumnHeader> m_column_header_preview;
519
std::vector<sizehandler2 *> m_column_sizehandler;
520
std::vector<sizehandler2 *> m_row_sizehandler;
521
//std::vector<std::string> m_item;
523
bool m_FloatingColumn;
526
Color m_RowColorEven;
527
Color m_SelectionColor;
528
Color m_TableBottomColor;
529
Color m_HorizontalSeparationLineColor;
530
Color m_VerticalSeparationLineColor;
532
// We need to draw the background on the previous size of the Table if its
533
// size is set to match the content(IsSizeMatchContent) and an item is close.
534
Geometry m_PreviousGeometry;
535
bool m_DrawBackgroundOnPreviousGeometry;
544
CELL_SELECT m_ClickSelect;
545
//TableItem* m_TableItem;
553
#endif // TABLECTRL_H