00001 /***************************************************************************** 00002 * 00003 * \file mgui/xmldata.h 00004 * \brief 00005 * 00006 * \if NODOC 00007 * $Log: xmldata.h_v $ 00008 * Revision 1.6 2003/11/14 18:33:11 dwilliss 00009 * Added a private enum which is passed to a private method. 00010 * 00011 * Revision 1.5 2003/10/03 19:58:19 linux32build!build 00012 * Doxygen 00013 * 00014 * Revision 1.4 2003/09/30 16:53:09 dwilliss 00015 * Doxygen 00016 * 00017 * Revision 1.3 2003/09/15 13:49:32 fileserver!dwilliss 00018 * Doxygen 00019 * 00020 * Revision 1.2 2003/07/08 22:22:23 dwilliss 00021 * Needed to include colorh 00022 * 00023 * Revision 1.1 2003/07/08 17:56:58 dwilliss 00024 * Initial revision 00025 * 00026 * Revision 1.2 2002/10/09 22:41:00 dwilliss 00027 * Moved to mgui subdirectory 00028 * 00029 * Revision 1.1 2002/10/09 22:38:13 dwilliss 00030 * Initial revision 00031 * 00032 * Revision 1.2 2002/09/19 22:34:09 dwilliss 00033 * Major update. Almost complete 00034 * 00035 * Revision 1.1 2002/09/03 22:38:57 dwilliss 00036 * Initial revision 00037 * 00038 * 00039 * \endif 00040 ****************************************************************************/ 00041 00042 #ifndef INC_MGUI_XMLDATA_H 00043 #define INC_MGUI_XMLDATA_H 00044 00045 00046 #ifndef INC_MI32_COLOR_H 00047 #include <mi32/color.h> 00048 #endif 00049 00050 #ifndef INC_MI32_XML_H 00051 #include <mi32/xml.h> 00052 #endif 00053 00054 namespace MGUI { 00055 00056 00057 //! Class used to pass data back and forth between programs and MGUI::DLG_XML 00058 //! and MGUI::LAYOUT_PANE_XML. The actual form data is stored in an XML 00059 //! document which looks something like this... 00060 //! 00061 //! @code 00062 //! <?xml version="1.0" encoding="utf-8"?> 00063 //! <struct> 00064 //! <member id="FirstName">John</member> 00065 //! <member id="LastName">Doe</member> 00066 //! <member id="Age" value="45"/> 00067 //! </struct> 00068 //! @endcode 00069 //! 00070 //! Although I may settle on placing the value always in a "value" attribute 00071 //! instead of as the content of the <member> tag, or always in the contents 00072 //! of the member tag as a CDATA section 00073 //! 00074 //! <b>Data storage:<b> 00075 //! 00076 //! - Combo Boxes and single-select lists: 00077 //! The data in the returned <member> tag will be the "value" 00078 //! attribute of the selected <item>. If the selected <item> 00079 //! does not have a value attribute, it will be the index into 00080 //! the list of items (with the first item being zero) 00081 //! 00082 //! - Multi-Select lists: 00083 //! The data in the returned <member> tag will be a comma-seperated 00084 //! list of the "value" attriubtes of the selected <item>s. 00085 //! 00086 //! - Numeric fields: 00087 //! The returned <member> tag will have a "value" attribute holding 00088 //! the number, but no content (see example above) 00089 //! 00090 //! Toggle Buttons: 00091 //! Toggle buttons are treated as numeric fields with 1 or 0 as 00092 //! the only possible values. You can use the XMLNODE Get/Set 00093 //! property methods which take and return bool to retrieve this. 00094 //! 00095 //! - Radio Groups: 00096 //! If a toggle button is in a RadioGroup, the returned record 00097 //! will have one <member> for the whole group. The "id" of this 00098 //! <member> will be the id of the first button in the group. 00099 //! The "value" attribute of this <member> will be the "value" 00100 //! attribute of the selected button in the group. 00101 //! 00102 //! - Color: (not implemented yet, just planning ahead) 00103 //! Will have attributes, "red", "green", "blue" and "transp" 00104 //! RGB values are from 0 to 65535. transp values are from 00105 //! 0 to 100 (or is it 255?), but will be omitted if the 00106 //! control does not have "AllowTransparency" set. 00107 //! 00108 class XMLFORM_DATA : public XMLDOC { 00109 public: 00110 00111 enum PROPERTY { 00112 PROPERTY_Value = 0, //!< The "value" attribute 00113 PROPERTY_Min, 00114 PROPERTY_Max, 00115 }; 00116 00117 //! Default constructor 00118 XMLFORM_DATA ( 00119 ); 00120 00121 //! Constructor. 00122 //! Copies initial values from the given node 00123 XMLFORM_DATA ( 00124 const XMLNODE* InitialValues 00125 ); 00126 00127 //! Copy constructor 00128 XMLFORM_DATA ( 00129 const XMLFORM_DATA& 00130 ); 00131 00132 //======================= Get Methods ============================ 00133 00134 //! Retrieve the value of a single control (MISTRING) 00135 //! Always stores strings as the <member> tag's contents 00136 //! @return false if the id wasn't found, true if it was 00137 bool GetValue ( 00138 const char* id, //!< ID of the control to get value of 00139 MISTRING& value //!< Value returned 00140 ) const; 00141 00142 //! Retrieve the value of a single control (double) 00143 //! Some controls have more than one value. For example, 00144 //! a range control would have a PROPERTY_Min and a PROPERTY_Max. 00145 //! Currently, only numeric controls can have more than one property 00146 //! @return false if the id wasn't found, true if it was 00147 bool GetValue ( 00148 const char* id, //!< ID of the control to get value of 00149 double& value, //!< Value returned 00150 XMLFORM_DATA::PROPERTY property = PROPERTY_Value 00151 ) const; 00152 00153 //! Retrieve the value of a single control (INT32) 00154 //! Some controls have more than one value. For example, 00155 //! a range control would have a PROPERTY_Min and a PROPERTY_Max. 00156 //! Currently, only numeric controls can have more than one property 00157 //! @return false if the id wasn't found, true if it was 00158 bool GetValue ( 00159 const char* id, //!< ID of the control to get value of 00160 INT32& value, //!< Value returned 00161 XMLFORM_DATA::PROPERTY property = PROPERTY_Value 00162 ) const; 00163 00164 //! Retrieve the value of a single control (INT32) 00165 //! @return false if the id wasn't found, true if it was 00166 bool GetValue ( 00167 const char* id, //!< ID of the control to get value of 00168 bool& value //!< Value returned 00169 ) const; 00170 00171 00172 //! Retrieve the value of a single control (INT32) 00173 //! @return false if the id wasn't found, true if it was 00174 bool GetValue ( 00175 const char* id, //!< ID of the control to get value of 00176 COLOR& value //!< Value returned 00177 ) const; 00178 00179 00180 //! Returns the main record node. 00181 XMLNODE* GetRecordNode ( 00182 ) const { 00183 return m_root; 00184 } 00185 00186 //======================= Set Methods ============================ 00187 00188 //! Set the value of a single control (MISTRING) 00189 void SetValue ( 00190 const char* id, //!< ID of the control to get value of 00191 const MISTRING& value //!< Value to set 00192 ); 00193 00194 //! Set the value of a single control (double) 00195 void SetValue ( 00196 const char* id, //!< ID of the control to get value of 00197 double value, //!< Value to set 00198 XMLFORM_DATA::PROPERTY property = PROPERTY_Value 00199 ); 00200 00201 //! Set the value of a single control (bool) 00202 void SetValue ( 00203 const char* id, //!< ID of the control to get value of 00204 bool value //!< Value to set 00205 ); 00206 00207 //! Set the value of a single control (COLOR) 00208 void SetValue ( 00209 const char* id, //!< ID of the control to get value of 00210 const COLOR& value //!< value to set 00211 ); 00212 00213 private: 00214 #ifndef GENERATING_DOXYGEN_OUTPUT 00215 00216 enum TYPE { 00217 TYPE_Int, 00218 TYPE_Double, 00219 TYPE_String, 00220 TYPE_Bool, 00221 TYPE_Color 00222 }; 00223 00224 XMLNODE* m_root; //!< The root node of the record 00225 00226 XMLNODE* FindNode ( 00227 const char* id, 00228 bool create = false 00229 ) const; 00230 00231 void OnDocReplaced(); 00232 00233 //! Set the value of a single control (MISTRING) 00234 void InternalSetValue ( 00235 const char* id, //!< ID of the control to get value of 00236 const MISTRING& value, //!< Value to set 00237 PROPERTY property, 00238 TYPE type 00239 ); 00240 #endif // GENERATING_DOXYGEN_OUTPUT 00241 00242 }; 00243 00244 } // End of MGUI namespace 00245 00246 #endif
1.3.4-20031026