nux-1.14.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 "ComboBoxSimple.h" 00027 #include "ComboBoxPropertyItem.h" 00028 00029 namespace nux 00030 { 00031 00032 ComboBoxPropertyItem::ComboBoxPropertyItem (const TCHAR *name) 00033 : SectionProperty (name, NODE_TYPE_COMBOSIMPLE) 00034 { 00035 NODE_SIG_CONNECT (sigTriggered, ComboBoxPropertyItem, RecvPropertyChange); 00036 } 00037 00038 ComboBoxPropertyItem::~ComboBoxPropertyItem() 00039 { 00040 00041 } 00042 00043 long ComboBoxPropertyItem::ProcessPropertyEvent (IEvent &ievent, long TraverseInfo, long ProcessEventInfo) 00044 { 00045 long ret = TraverseInfo; 00046 00047 ret = ProcessEvent (ievent, TraverseInfo, ProcessEventInfo); 00048 return ret; 00049 } 00050 00051 void ComboBoxPropertyItem::DrawProperty (GraphicsEngine &GfxContext, TableCtrl *table, bool force_draw, Geometry geo, const BasePainter &Painter, 00052 RowHeader *row, const std::vector<ColumnHeader>& column_vector, Color ItemBackgroundColor) 00053 { 00054 Geometry geo2 = m_FirstColumnUsableGeometry; 00055 00056 if (isDirtyItem() || IsRedrawNeeded() ) 00057 { 00058 t_u32 nBackground = table->PushItemBackground (GfxContext, this); 00059 Painter.PaintTextLineStatic (GfxContext, GetFont (), m_FirstColumnUsableGeometry, row->_table_item->GetName(), GetItemTextColor() ); 00060 00061 if (m_ItemGeometryVector.size() >= 2) 00062 { 00063 Geometry geo2 = m_ItemGeometryVector[1]; 00064 Geometry prop_geo; 00065 prop_geo.SetX (geo.x + geo.GetWidth() ); 00066 prop_geo.SetY (geo.y); 00067 prop_geo.SetWidth (column_vector[1].m_header_area->GetBaseWidth() ); 00068 prop_geo.SetHeight (geo.GetHeight() ); 00069 00070 geo2.Expand (-PROPERTY_BORDER_X, -PROPERTY_BORDER_Y); 00071 GfxContext.PushClippingRectangle (geo2); 00072 GfxContext.PushClippingRectangle (prop_geo); 00073 ProcessDraw (GfxContext, true); 00074 GfxContext.PopClippingRectangle(); 00075 GfxContext.PopClippingRectangle(); 00076 } 00077 00078 table->PopItemBackground (GfxContext, nBackground); 00079 } 00080 } 00081 00082 void ComboBoxPropertyItem::ComputePropertyLayout (int x, int y, RowHeader *row, const std::vector<ColumnHeader>& column_vector) 00083 { 00084 if (m_ItemGeometryVector.size() >= 2) 00085 { 00086 Geometry geo; 00087 geo = m_ItemGeometryVector[1]; 00088 geo = geo.GetExpand (-PROPERTY_BORDER_X, -PROPERTY_BORDER_Y); 00089 SetGeometry (geo); 00090 } 00091 } 00092 00093 int ComboBoxPropertyItem::GetItemBestHeight() 00094 { 00095 Size sz = GetMinimumSize(); 00096 return sz.height + 2 * PROPERTY_BORDER_Y; 00097 } 00098 00099 ComboBoxPropertyItem *ComboBoxPropertyItem::CreateFromXML (const TiXmlElement *elementxml, NodeNetCom *parent, const char *Name, int id) 00100 { 00101 ComboBoxPropertyItem *node = new ComboBoxPropertyItem (Name); 00102 00103 int NumItem = 0; 00104 int SelectionIndex = 0; 00105 QueryNodeXMLIntAttribute (elementxml, "NumItem", &NumItem, id); 00106 QueryNodeXMLIntAttribute (elementxml, "ItemSelected", &SelectionIndex, id); 00107 const TiXmlElement *childxml = elementxml->FirstChildElement(); 00108 int i = 0; 00109 00110 while (childxml && (i < NumItem) ) 00111 { 00112 int UserValue; 00113 TCHAR label[32]; 00114 Snprintf (label, 32, 32 - 1, TEXT ("Label_%d"), i); 00115 tstring ItemLabel; 00116 QueryNodeXMLStringAttribute (childxml, label, ItemLabel, -1); 00117 QueryNodeXMLIntAttribute (childxml, TEXT ("UserValue"), &UserValue, -1); // - 1 means do not care about he ID 00118 00119 node->AddItem (ItemLabel.c_str(), UserValue); 00120 ++i; 00121 childxml = childxml->NextSiblingElement(); 00122 } 00123 00124 if (SelectionIndex < 0) 00125 node->SetSelectionIndex (0); 00126 else 00127 node->SetSelectionIndex (SelectionIndex); 00128 00129 node->SetID (id); 00130 return node; 00131 } 00132 00133 TiXmlElement *ComboBoxPropertyItem::ToXML() const 00134 { 00135 TiXmlElement *elementxml = NodeNetCom::ToXML(); 00136 elementxml->SetAttribute ("NumItem", GetNumItem() ); 00137 int SelectionIndex = GetSelectionIndex(); 00138 00139 if (SelectionIndex < 0) 00140 SelectionIndex = 0; 00141 00142 elementxml->SetAttribute ("ItemSelected", SelectionIndex); 00143 00144 for (int i = 0; i < GetNumItem(); i++) 00145 { 00146 TiXmlElement *childxml = new TiXmlElement ("ComboBoxItem"); 00147 TCHAR label[32]; 00148 Snprintf (label, 32, 32 - 1, TEXT ("Label_%d"), i); 00149 childxml->SetAttribute (label, GetItem (i)->GetLabel() ); 00150 childxml->SetAttribute (TEXT ("UserValue"), GetItem (i)->GetUserValue() ); 00151 elementxml->LinkEndChild (childxml); 00152 } 00153 00154 return elementxml; 00155 } 00156 00157 bool ComboBoxPropertyItem::FromXML (const TiXmlElement *elementxml) 00158 { 00159 int NumItem = 0; 00160 int SelectionIndex = 0; 00161 QueryNodeXMLIntAttribute (elementxml, "NumItem", &NumItem, GetID() ); 00162 QueryNodeXMLIntAttribute (elementxml, "ItemSelected", &SelectionIndex, GetID() ); 00163 const TiXmlElement *childxml = elementxml->FirstChildElement(); 00164 RemoveAllItem(); 00165 int i = 0; 00166 00167 while (childxml && (i < NumItem) ) 00168 { 00169 int UserValue; 00170 TCHAR label[32]; 00171 Snprintf (label, 32, 32 - 1, TEXT ("Label_%d"), i); 00172 tstring ItemLabel; 00173 QueryNodeXMLStringAttribute (childxml, label, ItemLabel, -1); 00174 QueryNodeXMLIntAttribute (childxml, TEXT ("UserValue"), &UserValue, -1); // - 1 means do not care about he ID 00175 00176 AddItem (ItemLabel.c_str(), UserValue); 00177 ++i; 00178 childxml = childxml->NextSiblingElement(); 00179 } 00180 00181 if (SelectionIndex < 0) 00182 SetSelectionIndex (0); 00183 else 00184 SetSelectionIndex (SelectionIndex); 00185 00186 return NodeNetCom::FromXML (elementxml); 00187 } 00188 }