nux-0.9.48

Nux/TableItem.h

Go to the documentation of this file.
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 TABLEITEM_H
00024 #define TABLEITEM_H
00025 
00026 #include "NodeItem.h"
00027 #include "NodeNetProtocol.h"
00028 
00029 namespace nux
00030 {
00031 
00032   class TableItem;
00033   class TableCtrl;
00034   class TreeView;
00035 
00036   extern const int ITEMDEFAULTWIDTH;
00037   extern const int ITEMDEFAULTHEIGHT;
00038   extern Color GPropertyItemTextColor0;
00039   extern Color GPropertyItemTextColor1;
00040 
00041   class ColumnHeader
00042   {
00043   public:
00044     ColumnHeader();
00045     ColumnHeader(const ColumnHeader& Other);
00046     ~ColumnHeader();
00047 
00048     ColumnHeader& operator = (const ColumnHeader& Other);
00049 
00050     InputArea *m_header_area;
00051     bool _fix_width;
00052     int _fix_width_value;
00053   };
00054 
00055   class RowHeader
00056   {
00057   public:
00058     RowHeader();
00059     RowHeader(const RowHeader& Other);
00060     ~RowHeader();
00061 
00062     RowHeader& operator = (const RowHeader& Other);
00063 
00064     //void SetItem(TableItem* item);
00065     //TableItem* GetItem();
00066 
00067     TableItem *_table_item;
00068   };
00069 
00070   class TableItem: public NodeNetCom
00071   {
00072   public:
00073     TableItem (const TCHAR *name, NodeParameterType type = NODE_TYPE_STATICTEXT);
00074     virtual ~TableItem();
00075 
00076     virtual long ProcessPropertyEvent (IEvent &ievent, long TraverseInfo, long ProcessEventInfo);
00077     virtual void DrawProperty (GraphicsEngine &GfxContext, TableCtrl *table, bool force_draw, Geometry geo, const BasePainter &Painter, RowHeader *row, const std::vector<ColumnHeader>& column_vector, Color ItemBackgroundColor = Color (0x0) );
00078     virtual void ComputePropertyLayout (int x, int y, RowHeader *row, const std::vector<ColumnHeader>& column_vector) {};
00079     virtual int GetItemBestHeight();
00080     virtual void SetPropertyItemWidth();
00081 
00082     void SetItemTextColor (const Color &color)
00083     {
00084       m_PropertyTextColor = color.Clone();
00085     }
00086 
00087     void SetItemTextColor (const Color *color)
00088     {
00089       if (color == 0)
00090       {
00091         NUX_SAFE_DELETE (m_PropertyTextColor);
00092       }
00093       else
00094       {
00095         NUX_SAFE_DELETE (m_PropertyTextColor);
00096         m_PropertyTextColor = color->Clone();
00097       }
00098     }
00099 
00100     const Color &GetItemTextColor()
00101     {
00102       if (m_PropertyTextColor)
00103         return *m_PropertyTextColor;
00104       else
00105         return GPropertyItemTextColor0;
00106     }
00107 
00108     virtual void SetBackgroundColor (Color c)
00109     {
00110       m_ItemBackgroundColor = c;
00111     }
00112     Color GetBackgroundColor() const
00113     {
00114       return m_ItemBackgroundColor;
00115     }
00116 
00120     void SetAlwaysShowOpeningButton (bool b)
00121     {
00122       m_AlwaysShowOpeningButton = b;
00123     }
00127     bool AlwaysShowOpeningButton()
00128     {
00129       return m_AlwaysShowOpeningButton;
00130     }
00135     void Open()
00136     {
00137       m_isOpen = true;
00138     }
00142     void Close()
00143     {
00144       m_isOpen = false;
00145     }
00149     bool isOpen() const
00150     {
00151       return m_isOpen;
00152     }
00156     void Hide()
00157     {
00158       m_bParentOpen = false;
00159     }
00163     void Show()
00164     {
00165       m_bParentOpen = true;
00166     }
00170     bool IsParentOpen() const
00171     {
00172       return m_bParentOpen;
00173     };
00174     void setDirtyItem (bool b)
00175     {
00176       m_bDirty = b;
00177     }
00178     bool isDirtyItem() const
00179     {
00180       return m_bDirty;
00181     }
00182 
00183     void RequestPropertyRedraw()
00184     {
00185       m_PropertyRedraw = true;
00186     }
00187 
00188     virtual void      PushChildFront ( NodeItem *child );
00189     virtual void      PushChildBack ( NodeItem *child );
00190     virtual void      AddNextSibling ( NodeItem *sibling );
00191     virtual void      AddPrevSibling ( NodeItem *sibling );
00192     virtual void      Unlink ( void );
00193 
00194     sigc::signal<void> sigCellFocus;
00195     sigc::signal<void> sigRowFocus;
00196 
00197     TableCtrl *GetTable()
00198     {
00199       return m_Table;
00200     }
00201   protected:
00202     //  Only the Root node of the table has this value defined. Every other item should have it set to NULL;
00203     TableCtrl *m_Table;
00204     bool m_isOpen;
00206     bool m_bParentOpen;
00207 
00208     int m_x;
00209     int m_y;
00210     int m_height;
00211     int m_width;
00212     int m_depth;
00213 
00214     bool m_bDirty;
00215 
00216     bool m_PropertyRedraw;
00217     Color m_ItemBackgroundColor;
00218     Color *m_PropertyTextColor;
00219 
00220     bool  m_AlwaysShowOpeningButton;
00221 
00223     InputArea *_row_header_area;
00225     std::vector<Geometry> m_ItemGeometryVector;
00226     //Geometry m_FirstColumnInRowGeometry;
00227     Geometry m_RowHeaderGeometry;
00228     Geometry m_FirstColumnUsableGeometry;
00229     Geometry m_TotalGeometry;
00230 
00231     bool m_bIsMouseInside;
00232     bool m_bIsFirstVisibleItem;
00233     bool m_bIsLastVisibleItem;
00234 
00235     friend class TableCtrl;
00236     friend class TreeControl;
00237     friend class ListControl;
00238   };
00239 
00240 }
00241 
00242 #endif // TABLEITEM_H
00243