~om26er/ubuntu/oneiric/nux/sru-819721

« back to all changes in this revision

Viewing changes to Nux/TableCtrl.h

  • Committer: Bazaar Package Importer
  • Author(s): Didier Roche
  • Date: 2010-11-18 19:17:32 UTC
  • Revision ID: james.westby@ubuntu.com-20101118191732-rn35790vekj6o4my
Tags: upstream-0.9.4
ImportĀ upstreamĀ versionĀ 0.9.4

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright 2010 Inalogic Inc.
 
3
 *
 
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.
 
7
 *
 
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.
 
13
 *
 
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/>
 
17
 *
 
18
 * Authored by: Jay Taoko <jay.taoko_AT_gmail_DOT_com>
 
19
 *
 
20
 */
 
21
 
 
22
 
 
23
#ifndef TABLECTRL_H
 
24
#define TABLECTRL_H
 
25
 
 
26
#include "TableItem.h"
 
27
#include "ScrollView.h"
 
28
 
 
29
namespace nux
 
30
{
 
31
 
 
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;
 
38
 
 
39
  class VLayout;
 
40
  class HLayout;
 
41
  class TableCtrl;
 
42
  class TableItem;
 
43
 
 
44
  typedef CoreArea sizehandler2;
 
45
 
 
46
  class TableCtrl: public ScrollView
 
47
  {
 
48
  public:
 
49
 
 
50
    //! Constructor
 
51
    /*!
 
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()
 
56
    */
 
57
    TableCtrl (bool floating_column = true);
 
58
    virtual ~TableCtrl();
 
59
 
 
60
    virtual long ProcessEvent (IEvent &ievent, long TraverseInfo, long ProcessEventInfo);
 
61
 
 
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);
 
69
 
 
70
    // API
 
71
    void addHeader (const TCHAR *name, bool fixed_width = false, int column_width = 10);
 
72
    void FormatTable();
 
73
    /*!
 
74
        @return The total width of the header;
 
75
    */
 
76
    int FormatHeader();
 
77
 
 
78
    //! Add a column to the table.
 
79
    /*!
 
80
        Add a column to the table.
 
81
 
 
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.
 
85
    */
 
86
    virtual void AddColumn (const TCHAR *column_name, bool fixed_width = false, int column_width = 10);
 
87
 
 
88
  private:
 
89
    //! Add a row item. Used internally.
 
90
    /*!
 
91
        Add a row item.
 
92
    */
 
93
    virtual void AddItem (TableItem *item /*const TCHAR* item_name*/);
 
94
  public:
 
95
    typedef void (TableCtrl::*ItemOperator) (TableItem *);
 
96
 
 
97
    /*!
 
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 .
 
102
    */
 
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);
 
106
    /*!
 
107
        Repopulate the table starting at the root node. Recreate the m_row_header.
 
108
    */
 
109
    void ResetTable();
 
110
    void TraverseItem (TableItem *item,  bool open_only, ItemOperator);
 
111
    /*!
 
112
        Delete the row size handler. All elements are delete.
 
113
    */
 
114
    void DeleteRowSizeHandler();
 
115
    /*!
 
116
        Delete the row header. All elements are delete.
 
117
    */
 
118
    void DeleteRowHeader();
 
119
 
 
120
    //Item Operator
 
121
    int m_ItemX;
 
122
    int m_ItemY;
 
123
    int m_OpenItemTotalHeight;
 
124
 
 
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);
 
131
 
 
132
    //! EnableResizing the height of row headers.
 
133
    /*!
 
134
        Enable the resizing to row headers by dragging the line at the bottom of the row.
 
135
    */
 
136
    virtual void EnableRowResizing (bool b)
 
137
    {
 
138
      m_bEnableRowResizing = b;
 
139
    }
 
140
 
 
141
    //! EnableResizing the width of column headers.
 
142
    /*!
 
143
        Enable the resizing to column headers by dragging the line at the right of the column.
 
144
    */
 
145
    virtual void EnableColumnResizing (bool b)
 
146
    {
 
147
      m_bEnableColumnResizing = b;
 
148
    }
 
149
    //! Show the row headers.
 
150
    /*!
 
151
        Show the row headers. Rows are numbered from 0 to the number of row - 1.
 
152
    */
 
153
    virtual void ShowRowHeader (bool b);
 
154
    //! Show the column headers.
 
155
    /*!
 
156
        Show the column headers. Columns are titled according to the name given when addColumn() is called.
 
157
    */
 
158
    virtual void ShowColumnHeader (bool b);
 
159
 
 
160
    //! Show the columns vertical separation lines.
 
161
    /*!
 
162
        Show the columns vertical separation lines.
 
163
        @param b If b is true the vertical separation lines are visible.
 
164
    */
 
165
    void ShowVerticalSeparationLine (bool b);
 
166
 
 
167
    //! Show the rows horizontal separation lines.
 
168
    /*!
 
169
        Show the rows horizontal separation lines.
 
170
        @param  b   If b is true the horizontal separation lines are visible.
 
171
    */
 
172
    void ShowHorizontalSeparationLine (bool b);
 
173
 
 
174
    void ShowSeparationLine (bool bHor, bool bVert);
 
175
 
 
176
    void ClickSelectRow();
 
177
    void ClickSelectColumn();
 
178
    void ClickSelectCell();
 
179
 
 
180
    //! Paint Decoration.
 
181
    /*!
 
182
        Paint the item hierarchy, open/close decoration in the first column.
 
183
        @param  item    The item whose decoration must be drawn.
 
184
    */
 
185
    virtual void PaintDecoration (GraphicsEngine &GfxContext, TableItem *item);
 
186
 
 
187
    //! Paint Item row header decoration.
 
188
    /*!
 
189
        @param  item    The item whose row header must be drawn.
 
190
    */
 
191
    virtual void PaintRowDecoration (GraphicsEngine &GfxContext, TableItem *item, Color color);
 
192
    //! Paint Item Background.
 
193
    /*!
 
194
        Paint Item Background. Also push the background on the painter background stack.
 
195
 
 
196
        @return The number of background pushed onto the painter stack.
 
197
    */
 
198
    UINT PushItemBackground (GraphicsEngine &GfxContext, TableItem *item, bool MouseOver = false);
 
199
 
 
200
    //! Pop the item background pushed on the painter stack.
 
201
    /*!
 
202
        Pop the item background pushed on the painter stack.
 
203
 
 
204
        @param NumBackground The number of background to pop of the painter stack.
 
205
    */
 
206
    void PopItemBackground (GraphicsEngine &GfxContext, UINT NumBackground);
 
207
 
 
208
    //! Enable  row to have a height fixed by the contained item.
 
209
    /*!
 
210
        Enable  row to have a height fixed by the contained item.
 
211
    */
 
212
    void EnableApplyItemBestHeight (bool b);
 
213
 
 
214
    //! Set ItemBackgroundColor when the mouse is over the Item.
 
215
    /*!
 
216
        Set ItemBackgroundColor when the mouse is over the Item.
 
217
        This color supersedes other background colors.
 
218
    */
 
219
    void SetMouseOverColor (Color color)
 
220
    {
 
221
      m_MouseOverColor = color;
 
222
    }
 
223
    //! Return the user defined color used as background color when the mouse is over the item.
 
224
    /*!
 
225
        @return the user defined color used as background color when the mouse is over the item.
 
226
    */
 
227
    Color GetMouseOverColor()
 
228
    {
 
229
      return m_MouseOverColor;
 
230
    }
 
231
    //! Enable the use of a user defined color when the mouse is over the item.
 
232
    /*!
 
233
        @param b If b is True the user defined color replaces the background color when the mouse is over the item.
 
234
    */
 
235
    void EnableMouseOverColor (bool b)
 
236
    {
 
237
      m_IsEnableMouseOverColor = b;
 
238
    }
 
239
 
 
240
    void SetRowColorOdd (Color color)
 
241
    {
 
242
      m_RowColorOdd = color;
 
243
    }
 
244
 
 
245
    Color GetRowColorOdd() const
 
246
    {
 
247
      return m_RowColorOdd;
 
248
    }
 
249
 
 
250
    void SetRowColorEven (Color color)
 
251
    {
 
252
      m_RowColorEven = color;
 
253
    }
 
254
 
 
255
    Color GetRowColorEven() const
 
256
    {
 
257
      return m_RowColorEven;
 
258
    }
 
259
 
 
260
    void SetRowColor (Color evencolor, Color oddcolor)
 
261
    {
 
262
      m_RowColorEven = evencolor;
 
263
      m_RowColorOdd = oddcolor;
 
264
    }
 
265
    void SetHorizontalSeparationLineColor (Color color)
 
266
    {
 
267
      m_HorizontalSeparationLineColor = color;
 
268
    }
 
269
 
 
270
    Color GetHorizontalSeparationLineColor() const
 
271
    {
 
272
      return m_HorizontalSeparationLineColor;
 
273
    }
 
274
 
 
275
    void SetVerticalSeparationLineColor (Color color)
 
276
    {
 
277
      m_VerticalSeparationLineColor = color;
 
278
    }
 
279
 
 
280
    Color GetVerticalSeparationLineColor() const
 
281
    {
 
282
      return m_VerticalSeparationLineColor;
 
283
    }
 
284
 
 
285
    void SetSeparationLineColor (const Color &horcolor, const Color &vertcolor)
 
286
    {
 
287
      m_HorizontalSeparationLineColor = horcolor;
 
288
      m_VerticalSeparationLineColor = vertcolor;
 
289
    }
 
290
 
 
291
    //! Return true if this object can break the layout.
 
292
    /*
 
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.
 
295
        Inherited from View
 
296
    */
 
297
    virtual bool CanBreakLayout()
 
298
    {
 
299
      if (IsSizeMatchContent() )
 
300
        return false;
 
301
 
 
302
      return true;
 
303
    }
 
304
 
 
305
  private:
 
306
 
 
307
    void UsedForComboBox (bool b)
 
308
    {
 
309
      m_IsPartOfComboBox = b;
 
310
    }
 
311
    bool IsPartOfCombobox() const
 
312
    {
 
313
      return m_IsPartOfComboBox;
 
314
    }
 
315
    bool m_IsPartOfComboBox;
 
316
 
 
317
    /*!
 
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.
 
320
    */
 
321
    void ForceStartFocusOnContentTable (int x, int y);
 
322
 
 
323
    Color m_MouseOverColor;
 
324
    bool m_IsEnableMouseOverColor;
 
325
 
 
326
  public:
 
327
    //! set Floating column.
 
328
    /*!
 
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.
 
332
 
 
333
        @see isFloatingColumn()
 
334
    */
 
335
    void SetFloatingColumn (bool b);
 
336
  public:
 
337
    //! Return true if the columns are floating.
 
338
    /*!
 
339
        Return true if the columns are floating.
 
340
 
 
341
        @see SetFloatingColumn()
 
342
    */
 
343
    bool isFloatingColumn();
 
344
 
 
345
    //! Get information about the item below the pointer.
 
346
    /*!
 
347
 
 
348
    */
 
349
    void FindItemUnderPointer (int x, int y, TableItem **ppItem, int &row, int &column);
 
350
 
 
351
    void SetSelectionColor (const Color &color)
 
352
    {
 
353
      m_SelectionColor = color;
 
354
    }
 
355
 
 
356
    const Color GetSelectionColor()
 
357
    {
 
358
      return m_SelectionColor;
 
359
    }
 
360
 
 
361
    TableItem *GetSelectedItem()
 
362
    {
 
363
      return m_selectedTableItem;
 
364
    }
 
365
 
 
366
    t_u32 GetSelectedRow()
 
367
    {
 
368
      return m_selectedRow;
 
369
    }
 
370
 
 
371
    t_u32 GetSelectedColumn()
 
372
    {
 
373
      return m_selectedColumn;
 
374
    }
 
375
 
 
376
    //! Get the number of column in the table.
 
377
    /*!
 
378
        Get the number of column in the table.
 
379
        @return the number of column.
 
380
    */
 
381
    t_s32 GetNumColumn();
 
382
 
 
383
    //! Get the number of row in the table.
 
384
    /*!
 
385
        Get the number of row in the table.
 
386
        @return the number of row.
 
387
    */
 
388
    t_s32 GetNumRow();
 
389
 
 
390
    //! reset Items flags.
 
391
    /*!
 
392
        Reset the dirty flag of items.
 
393
    */
 
394
    void ResetItems();
 
395
 
 
396
    /*!
 
397
        Get Root Node.
 
398
        @return const TableItem*
 
399
    */
 
400
    const TableItem *GetRootNode() const
 
401
    {
 
402
      return m_TableItemHead;
 
403
    }
 
404
    /*!
 
405
        Get Root Node.
 
406
        @return TableItem*
 
407
    */
 
408
    TableItem *GetRootNode()
 
409
    {
 
410
      return m_TableItemHead;
 
411
    }
 
412
 
 
413
    /*!
 
414
        Get number of child element of the root node.
 
415
    */
 
416
    int GetNumRootChild() const
 
417
    {
 
418
      return m_TableItemHead->NumChild();
 
419
    }
 
420
 
 
421
    /*!
 
422
        Delete all elements of the tabled below the root node.
 
423
    */
 
424
    void EmptyTable();
 
425
 
 
426
    void HighlightItem (int row, int column);
 
427
 
 
428
    /////////////////
 
429
    //  EMITERS    //
 
430
    /////////////////
 
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);
 
441
 
 
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);
 
444
 
 
445
 
 
446
    /////////////////
 
447
    //  SIGNALS    //
 
448
    /////////////////
 
449
    sigc::signal<void, int, int> sigItemSelected;
 
450
    sigc::signal<void, const TableItem &> sigItemChange;
 
451
    sigc::signal<void, TableCtrl &, TableItem &, int, int> sigTableItemSelected;
 
452
 
 
453
    sigc::signal<void> sigLostFocus;
 
454
 
 
455
  protected:
 
456
 
 
457
    // for debugging purpose to find out who called NeedReedraw for the TableCtrl.
 
458
    void NeedRedraw();
 
459
 
 
460
    virtual void SetGeometry (const Geometry &geo);
 
461
    friend class ComboBoxComplex;
 
462
    friend class ComboBoxSimple;
 
463
 
 
464
    /*!
 
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.
 
467
    */
 
468
    void ComputeNonFloatingColumn();
 
469
 
 
470
    /*!
 
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.
 
475
    */
 
476
    void AdjustNonFloatingColumn();
 
477
 
 
478
    virtual void PreLayoutManagement();
 
479
    virtual long PostLayoutManagement (long LayoutResult);
 
480
    virtual void PositionChildLayout (float offsetX, float offsetY);
 
481
 
 
482
    /////////////////
 
483
    //  RECEIVERS  //
 
484
    /////////////////
 
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);
 
489
 
 
490
 
 
491
 
 
492
  protected:
 
493
    CoreArea   *m_TableArea;
 
494
    VLayout    *m_VLayout;
 
495
 
 
496
    int m_tableNumRow;
 
497
    int m_tableNumColumn;
 
498
 
 
499
    int m_selectedRow;
 
500
    int m_selectedColumn;
 
501
    Geometry m_selectedGeometry;
 
502
 
 
503
    TableItem *m_selectedTableItem;
 
504
    TableItem *m_selectedMouseDownTableItem;
 
505
    TableItem *m_TableItemHead;
 
506
 
 
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;
 
514
 
 
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;
 
522
 
 
523
    bool m_FloatingColumn;
 
524
 
 
525
    Color m_RowColorOdd;
 
526
    Color m_RowColorEven;
 
527
    Color m_SelectionColor;
 
528
    Color m_TableBottomColor;
 
529
    Color m_HorizontalSeparationLineColor;
 
530
    Color m_VerticalSeparationLineColor;
 
531
 
 
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;
 
536
 
 
537
    enum CELL_SELECT
 
538
    {
 
539
      CLICK_SELECT_CELL,
 
540
      CLICK_SELECT_COLUMN,
 
541
      CLICK_SELECT_ROW,
 
542
    };
 
543
 
 
544
    CELL_SELECT m_ClickSelect;
 
545
    //TableItem* m_TableItem;
 
546
    Point m_point0;
 
547
    Point m_point1;
 
548
  };
 
549
 
 
550
 
 
551
}
 
552
 
 
553
#endif // TABLECTRL_H