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 #include "Nux.h" 00024 #include "PropertyList.h" 00025 00026 #include "RangeValueIntegerPropertyItem.h" 00027 00028 namespace nux 00029 { 00030 00031 RangeValueIntegerPropertyItem::RangeValueIntegerPropertyItem (const TCHAR *name, int Value, int MinValue, int MaxValue) 00032 : SectionProperty (name, NODE_TYPE_RANGE) 00033 { 00034 SetRange (MinValue, MaxValue); 00035 SetValue (Value); 00036 m_ValueString->SetMinimumSize (DEFAULT_WIDGET_WIDTH, DEFAULT_WIDGET_HEIGHT); 00037 //m_ValueString->SetMaximumHeight(14 /*PRACTICAL_WIDGET_HEIGHT*/); 00038 //m_ValueString->SetGeometry(Geometry(0, 0, 3*DEFAULT_WIDGET_WIDTH, 16 /*PRACTICAL_WIDGET_HEIGHT*/)); 00039 00040 m_Percentage->SetMinimumSize (2 * DEFAULT_WIDGET_WIDTH, DEFAULT_WIDGET_HEIGHT); 00041 //m_Percentage->SetMaximumHeight(14 /*PRACTICAL_WIDGET_HEIGHT*/); 00042 //m_Percentage->SetGeometry(Geometry(0, 0, DEFAULT_WIDGET_WIDTH, 16 /*PRACTICAL_WIDGET_HEIGHT*/)); 00043 SetMaximumHeight (14); 00044 00045 NODE_SIG_CONNECT (sigValueChanged, RangeValueIntegerPropertyItem, RecvPropertyChange); 00046 } 00047 00048 RangeValueIntegerPropertyItem::~RangeValueIntegerPropertyItem() 00049 { 00050 00051 } 00052 00053 long RangeValueIntegerPropertyItem::ProcessPropertyEvent (IEvent &ievent, long TraverseInfo, long ProcessEventInfo) 00054 { 00055 long ret = TraverseInfo; 00056 00057 Geometry geo = m_ItemGeometryVector[1]; 00058 00059 if ( (ievent.e_event == NUX_MOUSE_PRESSED) && geo.IsPointInside (ievent.e_x, ievent.e_y) == false) 00060 { 00061 // This will filter out mouse down event that happened in the item in the same row on the right. 00062 // This is necessary because the widget we are testing maybe larger that the table element where it resides. 00063 // 00064 // ____________________________________________________________ 00065 // | NAME | WIDGET | : | 00066 // |___________|________________|_____:_____________|___________ 00067 // ^ 00068 // | 00069 // end of widget 00070 // 00071 ret = ProcessEvent (ievent, TraverseInfo, eDoNotProcess | ProcessEventInfo); 00072 } 00073 else 00074 { 00075 ret = ProcessEvent (ievent, TraverseInfo, ProcessEventInfo); 00076 } 00077 00078 return ret; 00079 } 00080 00081 void RangeValueIntegerPropertyItem::DrawProperty (GraphicsEngine &GfxContext, TableCtrl *table, bool force_draw, Geometry geo, const BasePainter &Painter, 00082 RowHeader *row, const std::vector<ColumnHeader>& column_vector, Color ItemBackgroundColor) 00083 { 00084 if (isDirtyItem() || IsRedrawNeeded() ) 00085 { 00086 t_u32 nBackground = table->PushItemBackground (GfxContext, this); 00087 Painter.PaintTextLineStatic (GfxContext, GetFont (), m_FirstColumnUsableGeometry, row->_table_item->GetName(), GetItemTextColor() ); 00088 00089 if (m_ItemGeometryVector.size() >= 2) 00090 { 00091 Geometry geo2 = m_ItemGeometryVector[1]; 00092 Geometry prop_geo; 00093 prop_geo.SetX (geo.x + geo.GetWidth() ); 00094 prop_geo.SetY (geo.y); 00095 prop_geo.SetWidth (column_vector[1].m_header_area->GetBaseWidth() ); 00096 prop_geo.SetHeight (geo.GetHeight() ); 00097 00098 geo2.Expand (-PROPERTY_BORDER_X, -PROPERTY_BORDER_Y); 00099 GfxContext.PushClippingRectangle (geo2); 00100 GfxContext.PushClippingRectangle (prop_geo); 00101 ProcessDraw (GfxContext, true); 00102 GfxContext.PopClippingRectangle(); 00103 GfxContext.PopClippingRectangle(); 00104 } 00105 00106 table->PopItemBackground (GfxContext, nBackground); 00107 } 00108 } 00109 00110 void RangeValueIntegerPropertyItem::ComputePropertyLayout (int x, int y, RowHeader *row, const std::vector<ColumnHeader>& column_vector) 00111 { 00112 if (m_ItemGeometryVector.size() >= 2) 00113 { 00114 Geometry geo; 00115 geo = m_ItemGeometryVector[1]; 00116 geo = geo.GetExpand (-PROPERTY_BORDER_X, -PROPERTY_BORDER_Y); 00117 SetGeometry (geo); 00118 } 00119 } 00120 00121 int RangeValueIntegerPropertyItem::GetItemBestHeight() 00122 { 00123 Size sz = GetMinimumSize(); 00124 return sz.height + 2 * PROPERTY_BORDER_Y; 00125 } 00126 00127 RangeValueIntegerPropertyItem *RangeValueIntegerPropertyItem::CreateFromXML (const TiXmlElement *elementxml, NodeNetCom *parent, const char *Name, int id) 00128 { 00129 int value = 0; 00130 int minvalue = 0; 00131 int maxvalue = 100; 00132 //double step = 1; 00133 QueryNodeXMLIntAttribute (elementxml, TEXT ("Value"), &value, id); 00134 QueryNodeXMLIntAttribute (elementxml, TEXT ("MinValue"), &minvalue, id); 00135 QueryNodeXMLIntAttribute (elementxml, TEXT ("MaxValue"), &maxvalue, id); 00136 //QueryNodeXMLIntAttribute(elementxml, "Step", &step, id); 00137 00138 RangeValueIntegerPropertyItem *node = new RangeValueIntegerPropertyItem (Name, value, minvalue, maxvalue); 00139 node->SetID (id); 00140 return node; 00141 } 00142 00143 TiXmlElement *RangeValueIntegerPropertyItem::ToXML() const 00144 { 00145 TiXmlElement *elementxml = NodeNetCom::ToXML(); 00146 elementxml->SetAttribute (TEXT ("Value"), GetValue() ); 00147 //elementxml->SetAttribute("Step", GetStep()); 00148 elementxml->SetAttribute (TEXT ("MinValue"), GetMinValue() ); 00149 elementxml->SetAttribute (TEXT ("MaxValue"), GetMaxValue() ); 00150 return elementxml; 00151 } 00152 00153 bool RangeValueIntegerPropertyItem::FromXML (const TiXmlElement *elementxml) 00154 { 00155 int value = 0; 00156 int minvalue = 0; 00157 int maxvalue = 100; 00158 //double step = 1; 00159 QueryNodeXMLIntAttribute (elementxml, TEXT ("Value"), &value, GetID() ); 00160 QueryNodeXMLIntAttribute (elementxml, TEXT ("MinValue"), &minvalue, GetID() ); 00161 QueryNodeXMLIntAttribute (elementxml, TEXT ("MaxValue"), &maxvalue, GetID() ); 00162 //QueryNodeXMLIntAttribute(elementxml, "Step", &step, GetID()); 00163 SetRange (minvalue, maxvalue); 00164 SetValue (value); 00165 return NodeNetCom::FromXML (elementxml); 00166 } 00167 }