nux-1.16.0
CheckBoxProperty.cpp
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 #include "Nux.h"
00024 #include "PropertyList.h"
00025 
00026 #include "CheckBox.h"
00027 #include "CheckBoxProperty.h"
00028 
00029 namespace nux
00030 {
00031 
00032   CheckBoxPropertyItem::CheckBoxPropertyItem (std::string label, NUX_FILE_LINE_DECL)
00033     :   SectionProperty (label.c_str(), NODE_TYPE_CHECKBOX)
00034     ,   CheckBox (label, NUX_FILE_LINE_PARAM)
00035   {
00036     //FIXME - needs updating to the latest Button codebase
00037     //SetState (on);
00038     SetUsingStyleDrawing (false);
00039     //FIXME needs to be updated to the latest button codebase
00040     //NODE_SIG_CONNECT (sigStateToggled, CheckBoxPropertyItem, RecvPropertyChange);
00041   }
00042 
00043   CheckBoxPropertyItem::~CheckBoxPropertyItem()
00044   {
00045 
00046   }
00047 
00048   long CheckBoxPropertyItem::ProcessPropertyEvent (IEvent &ievent, long TraverseInfo, long ProcessEventInfo)
00049   {
00050     long ret = TraverseInfo;
00051 
00052     ret = ProcessEvent (ievent, TraverseInfo, ProcessEventInfo);
00053     return ret;
00054   }
00055 
00056   void CheckBoxPropertyItem::DrawProperty (GraphicsEngine &GfxContext, TableCtrl *table, bool force_draw, Geometry ItemGeo, const BasePainter &Painter,
00057       RowHeader *row, const std::vector<ColumnHeader>& column_vector, Color ItemBackgroundColor)
00058   {
00059     Geometry geo2 = m_FirstColumnUsableGeometry;
00060 
00061     if (isDirtyItem() || IsRedrawNeeded() )
00062     {
00063       t_u32 nBackground = table->PushItemBackground (GfxContext, this);
00064       Painter.PaintTextLineStatic (GfxContext, GetFont (), m_FirstColumnUsableGeometry, row->_table_item->GetName(), GetItemTextColor() );
00065 
00066       if (m_ItemGeometryVector.size() >= 2)
00067       {
00068         Geometry geo2 = m_ItemGeometryVector[1];
00069         Geometry prop_geo;
00070         prop_geo.SetX (ItemGeo.x + ItemGeo.GetWidth() );
00071         prop_geo.SetY (ItemGeo.y);
00072         prop_geo.SetWidth (column_vector[1].m_header_area->GetBaseWidth() );
00073         prop_geo.SetHeight (ItemGeo.GetHeight() );
00074 
00075         geo2.Expand (-PROPERTY_BORDER_X, -PROPERTY_BORDER_Y);
00076         GfxContext.PushClippingRectangle (geo2);
00077         GfxContext.PushClippingRectangle (prop_geo);
00078         Painter.Paint2DQuadColor (GfxContext, geo2, ItemBackgroundColor);
00079         ProcessDraw (GfxContext, true);
00080         GfxContext.PopClippingRectangle();
00081         GfxContext.PopClippingRectangle();
00082       }
00083 
00084       table->PopItemBackground (GfxContext, nBackground);
00085     }
00086   }
00087 
00088   void CheckBoxPropertyItem::ComputePropertyLayout (int x, int y, RowHeader *row, const std::vector<ColumnHeader>& column_vector)
00089   {
00090     if (m_ItemGeometryVector.size() >= 2)
00091     {
00092       Geometry geo;
00093       geo = m_ItemGeometryVector[1];
00094       geo = geo.GetExpand (-PROPERTY_BORDER_X, -PROPERTY_BORDER_Y);
00095       SetGeometry (geo);
00096     }
00097   }
00098 
00099   int CheckBoxPropertyItem::GetItemBestHeight()
00100   {
00101     Size sz = GetMinimumSize();
00102     return sz.height + 2 * PROPERTY_BORDER_Y;
00103   }
00104 
00105   CheckBoxPropertyItem *CheckBoxPropertyItem::CreateFromXML (const TiXmlElement *elementxml, NodeNetCom *parent, const char *Name, int id)
00106   {
00107     int check = 0;
00108     QueryNodeXMLIntAttribute (elementxml, "Check",       &check,     id);
00109     CheckBoxPropertyItem *node = new CheckBoxPropertyItem (Name);
00110     node->active = check ? true : false;
00111     node->SetID (id);
00112     return node;
00113   }
00114 
00115   TiXmlElement *CheckBoxPropertyItem::ToXML() const
00116   {
00117     TiXmlElement *elementxml = NodeNetCom::ToXML();
00118     //FIXME needs to be updated to the latest button codebase
00119     //elementxml->SetAttribute ("Check", GetState() ? 1 : 0);
00120     return elementxml;
00121   }
00122 
00123   bool CheckBoxPropertyItem::FromXML (const TiXmlElement *elementxml)
00124   {
00125     int check;
00126 
00127     if (QueryNodeXMLIntAttribute (elementxml, "Check", &check, GetID() ) )
00128     {
00129       //FIXME needs to be updated to the latest button codebase
00130       //SetState (check ? true : false);
00131       //nuxDebugMsg(TEXT("Updated Node %s - ID: %d - Type: %s"), GetName().c_str(), GetID(), ConvertTypeToString(GetParameterType()));
00132       return NodeNetCom::FromXML (elementxml);
00133     }
00134 
00135     return false;
00136   }
00137 
00138 }
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends