nux-1.16.0
|
00001 /* 00002 * Copyright 2010 Inalogic® Inc. 00003 * 00004 * This program is free software: you can redistribute it and/or modify it 00005 * under the terms of the GNU Lesser General Public License, as 00006 * published by the Free Software Foundation; either version 2.1 or 3.0 00007 * of the License. 00008 * 00009 * This program is distributed in the hope that it will be useful, but 00010 * WITHOUT ANY WARRANTY; without even the implied warranties of 00011 * MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR 00012 * PURPOSE. See the applicable version of the GNU Lesser General Public 00013 * License for more details. 00014 * 00015 * You should have received a copy of both the GNU Lesser General Public 00016 * License along with this program. If not, see <http://www.gnu.org/licenses/> 00017 * 00018 * Authored by: Jay Taoko <jaytaoko@inalogic.com> 00019 * 00020 */ 00021 00022 00023 #ifndef TABLECTRL_H 00024 #define TABLECTRL_H 00025 00026 #include "TableItem.h" 00027 #include "ScrollView.h" 00028 00029 namespace nux 00030 { 00031 00032 extern const int ROWHEADERWIDTH; 00033 extern const int OPENCLOSE_BTN_WIDTH; 00034 extern const int ITEM_DEPTH_MARGIN; 00035 extern const int MIN_COLUMN_WIDTH; 00036 extern const int TABLE_AREA_BOTTOM_SPACE; 00037 extern const int COLUMNHEADERHEIGHT; 00038 00039 class VLayout; 00040 class HLayout; 00041 class TableCtrl; 00042 class TableItem; 00043 00044 typedef InputArea sizehandler2; 00045 00046 class TableCtrl: public ScrollView 00047 { 00048 public: 00049 00051 00057 TableCtrl (bool floating_column = true); 00058 virtual ~TableCtrl(); 00059 00060 virtual long ProcessEvent (IEvent &ievent, long TraverseInfo, long ProcessEventInfo); 00061 00062 virtual void Draw (GraphicsEngine &GfxContext, bool force_draw); 00063 virtual void DrawContent (GraphicsEngine &GfxContext, bool force_draw); 00064 virtual void PostDraw (GraphicsEngine &GfxContext, bool force_draw); 00065 void DrawTable (GraphicsEngine &GfxContext); 00066 void DrawHeader (GraphicsEngine &GfxContext); 00067 void DrawHeaderPreview (GraphicsEngine &GfxContext); 00068 void OverlayDrawing (GraphicsEngine &GfxContext); 00069 00070 // API 00071 void addHeader (const TCHAR *name, bool fixed_width = false, int column_width = 10); 00072 void FormatTable(); 00076 int FormatHeader(); 00077 00079 00086 virtual void AddColumn (const TCHAR *column_name, bool fixed_width = false, int column_width = 10); 00087 00088 private: 00090 00093 virtual void AddItem (TableItem *item /*const TCHAR* item_name*/); 00094 public: 00095 typedef void (TableCtrl::*ItemOperator) (TableItem *); 00096 00103 void setTableItems (TableItem *item, bool isOpen = false); 00105 void AddTableItem (TableItem *item); 00109 void ResetTable(); 00110 void TraverseItem (TableItem *item, bool open_only, ItemOperator); 00114 void DeleteRowSizeHandler(); 00118 void DeleteRowHeader(); 00119 00120 //Item Operator 00121 int m_ItemX; 00122 int m_ItemY; 00123 int m_OpenItemTotalHeight; 00124 00125 void OpBuildItemDepth (TableItem *item, int depth); 00126 void OpAddItem (TableItem *item); 00127 void OpCloseItem (TableItem *item); 00128 void OpOpenItem (TableItem *item); 00129 void OpHideItem (TableItem *item); 00130 void OpShowItem (TableItem *item); 00131 00133 00136 virtual void EnableRowResizing (bool b) 00137 { 00138 m_bEnableRowResizing = b; 00139 } 00140 00142 00145 virtual void EnableColumnResizing (bool b) 00146 { 00147 m_bEnableColumnResizing = b; 00148 } 00150 00153 virtual void ShowRowHeader (bool b); 00155 00158 virtual void ShowColumnHeader (bool b); 00159 00161 00165 void ShowVerticalSeparationLine (bool b); 00166 00168 00172 void ShowHorizontalSeparationLine (bool b); 00173 00174 void ShowSeparationLine (bool bHor, bool bVert); 00175 00176 void ClickSelectRow(); 00177 void ClickSelectColumn(); 00178 void ClickSelectCell(); 00179 00181 00185 virtual void PaintDecoration (GraphicsEngine &GfxContext, TableItem *item); 00186 00188 00191 virtual void PaintRowDecoration (GraphicsEngine &GfxContext, TableItem *item, Color color); 00193 00198 t_u32 PushItemBackground (GraphicsEngine &GfxContext, TableItem *item, bool MouseOver = false); 00199 00201 00206 void PopItemBackground (GraphicsEngine &GfxContext, t_u32 NumBackground); 00207 00209 00212 void EnableApplyItemBestHeight (bool b); 00213 00215 00219 void SetMouseOverColor (Color color) 00220 { 00221 m_MouseOverColor = color; 00222 } 00224 00227 Color GetMouseOverColor() 00228 { 00229 return m_MouseOverColor; 00230 } 00232 00235 void EnableMouseOverColor (bool b) 00236 { 00237 m_IsEnableMouseOverColor = b; 00238 } 00239 00240 void SetRowColorOdd (Color color) 00241 { 00242 m_RowColorOdd = color; 00243 } 00244 00245 Color GetRowColorOdd() const 00246 { 00247 return m_RowColorOdd; 00248 } 00249 00250 void SetRowColorEven (Color color) 00251 { 00252 m_RowColorEven = color; 00253 } 00254 00255 Color GetRowColorEven() const 00256 { 00257 return m_RowColorEven; 00258 } 00259 00260 void SetRowColor (Color evencolor, Color oddcolor) 00261 { 00262 m_RowColorEven = evencolor; 00263 m_RowColorOdd = oddcolor; 00264 } 00265 void SetHorizontalSeparationLineColor (Color color) 00266 { 00267 m_HorizontalSeparationLineColor = color; 00268 } 00269 00270 Color GetHorizontalSeparationLineColor() const 00271 { 00272 return m_HorizontalSeparationLineColor; 00273 } 00274 00275 void SetVerticalSeparationLineColor (Color color) 00276 { 00277 m_VerticalSeparationLineColor = color; 00278 } 00279 00280 Color GetVerticalSeparationLineColor() const 00281 { 00282 return m_VerticalSeparationLineColor; 00283 } 00284 00285 void SetSeparationLineColor (const Color &horcolor, const Color &vertcolor) 00286 { 00287 m_HorizontalSeparationLineColor = horcolor; 00288 m_VerticalSeparationLineColor = vertcolor; 00289 } 00290 00292 /* 00293 Return true if this object can break the layout, meaning, the layout can be done on the composition layout only without 00294 recomputing the whole window layout. 00295 Inherited from View 00296 */ 00297 virtual bool CanBreakLayout() 00298 { 00299 if (IsSizeMatchContent() ) 00300 return false; 00301 00302 return true; 00303 } 00304 00305 private: 00306 00307 void UsedForComboBox (bool b) 00308 { 00309 m_IsPartOfComboBox = b; 00310 } 00311 bool IsPartOfCombobox() const 00312 { 00313 return m_IsPartOfComboBox; 00314 } 00315 bool m_IsPartOfComboBox; 00316 00321 void ForceStartFocusOnContentTable (int x, int y); 00322 00323 Color m_MouseOverColor; 00324 bool m_IsEnableMouseOverColor; 00325 00326 public: 00328 00335 void SetFloatingColumn (bool b); 00336 public: 00338 00343 bool isFloatingColumn(); 00344 00346 00349 void FindItemUnderPointer (int x, int y, TableItem **ppItem, int &row, int &column); 00350 00351 void SetSelectionColor (const Color &color) 00352 { 00353 m_SelectionColor = color; 00354 } 00355 00356 const Color GetSelectionColor() 00357 { 00358 return m_SelectionColor; 00359 } 00360 00361 TableItem *GetSelectedItem() 00362 { 00363 return m_selectedTableItem; 00364 } 00365 00366 t_u32 GetSelectedRow() 00367 { 00368 return m_selectedRow; 00369 } 00370 00371 t_u32 GetSelectedColumn() 00372 { 00373 return m_selectedColumn; 00374 } 00375 00377 00381 t_s32 GetNumColumn(); 00382 00384 00388 t_s32 GetNumRow(); 00389 00391 00394 void ResetItems(); 00395 00400 const TableItem *GetRootNode() const 00401 { 00402 return m_TableItemHead; 00403 } 00408 TableItem *GetRootNode() 00409 { 00410 return m_TableItemHead; 00411 } 00412 00416 int GetNumRootChild() const 00417 { 00418 return m_TableItemHead->NumChild(); 00419 } 00420 00424 void EmptyTable(); 00425 00426 void HighlightItem (int row, int column); 00427 00429 // EMITERS // 00431 // mouse_double_click and OnMouseDown have a custom implementation in TreeView. We need to make them virtual. 00432 virtual void mouse_double_click (int x, int y, unsigned long button_flags, unsigned long key_flags); 00433 virtual void OnMouseDown (int x, int y, unsigned long button_flags, unsigned long key_flags); 00434 void OnMouseUp (int x, int y, unsigned long button_flags, unsigned long key_flags); 00435 void mouse_drag (int x, int y, int dx, int dy, unsigned long button_flags, unsigned long key_flags); 00436 void OnKeyboardFocus(); 00437 void OnLostKeyboardFocus(); 00438 void OnResizeHeaderMouseDown (int x, int y, unsigned long button_flags, unsigned long key_flags, t_u32 header_pos); 00439 void OnResizeHeaderMouseUp (int x, int y, unsigned long button_flags, unsigned long key_flags, t_u32 header_pos); 00440 void OnResizeHeaderMouseDrag (int x, int y, int dx, int dy, unsigned long button_flags, unsigned long key_flags, t_u32 header_pos); 00441 00442 void OnResizeRowMouseDown (int x, int y, unsigned long button_flags, unsigned long key_flags, t_u32 header_pos); 00443 void OnResizeRowMouseDrag (int x, int y, int dx, int dy, unsigned long button_flags, unsigned long key_flags, t_u32 header_pos); 00444 00445 00447 // SIGNALS // 00449 sigc::signal<void, int, int> sigItemSelected; 00450 sigc::signal<void, const TableItem &> sigItemChange; 00451 sigc::signal<void, TableCtrl &, TableItem &, int, int> sigTableItemSelected; 00452 00453 sigc::signal<void> sigLostFocus; 00454 00455 protected: 00456 00457 // for debugging purpose to find out who called NeedReedraw for the TableCtrl. 00458 void QueueDraw(); 00459 00460 virtual void SetGeometry (const Geometry &geo); 00461 friend class ComboBoxComplex; 00462 friend class ComboBoxSimple; 00463 00468 void ComputeNonFloatingColumn(); 00469 00476 void AdjustNonFloatingColumn(); 00477 00478 virtual void PreLayoutManagement(); 00479 virtual long PostLayoutManagement (long LayoutResult); 00480 virtual void PositionChildLayout (float offsetX, float offsetY); 00481 00483 // RECEIVERS // 00485 virtual void ScrollLeft (float stepx, int mousedx); 00486 virtual void ScrollRight (float stepx, int mousedx); 00487 virtual void ScrollUp (float stepy, int mousedy); 00488 virtual void ScrollDown (float stepy, int mousedy); 00489 00490 00491 00492 protected: 00493 InputArea *m_TableArea; 00494 VLayout *m_VLayout; 00495 00496 int m_tableNumRow; 00497 int m_tableNumColumn; 00498 00499 int m_selectedRow; 00500 int m_selectedColumn; 00501 Geometry m_selectedGeometry; 00502 00503 TableItem *m_selectedTableItem; 00504 TableItem *m_selectedMouseDownTableItem; 00505 TableItem *m_TableItemHead; 00506 00507 bool m_bEnableRowResizing; 00508 bool m_bEnableColumnResizing; 00509 bool m_bShowRowHeader; 00510 bool m_bShowColumnHeader; 00511 bool m_bShowVerticalSeparationLine; 00512 bool m_bShowHorizontalSeparationLine; 00513 bool m_bEnableItemBestHeight; 00514 00515 std::vector<RowHeader *> m_row_header; 00516 //std::vector<Geometry> m_column; 00517 std::vector<ColumnHeader> m_column_header; 00518 std::vector<ColumnHeader> m_column_header_preview; 00519 std::vector<sizehandler2 *> m_column_sizehandler; 00520 std::vector<sizehandler2 *> m_row_sizehandler; 00521 //std::vector<std::string> m_item; 00522 00523 bool m_FloatingColumn; 00524 00525 Color m_RowColorOdd; 00526 Color m_RowColorEven; 00527 Color m_SelectionColor; 00528 Color m_TableBottomColor; 00529 Color m_HorizontalSeparationLineColor; 00530 Color m_VerticalSeparationLineColor; 00531 00532 // We need to draw the background on the previous size of the Table if its 00533 // size is set to match the content(IsSizeMatchContent) and an item is close. 00534 Geometry m_PreviousGeometry; 00535 bool m_DrawBackgroundOnPreviousGeometry; 00536 00537 enum CELL_SELECT 00538 { 00539 CLICK_SELECT_CELL, 00540 CLICK_SELECT_COLUMN, 00541 CLICK_SELECT_ROW, 00542 }; 00543 00544 CELL_SELECT m_ClickSelect; 00545 //TableItem* m_TableItem; 00546 Point m_point0; 00547 Point m_point1; 00548 }; 00549 00550 00551 } 00552 00553 #endif // TABLECTRL_H