Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members

scim_property.h

Go to the documentation of this file.
00001 /** @file scim_property.h 00002 * @brief Definition of scim::Property and scim::PropertyList 00003 * 00004 * Provide class scim::Property to hold of a property 00005 * of a IMEngineInstance or a Panel GUI client. 00006 */ 00007 00008 /* 00009 * Smart Common Input Method 00010 * 00011 * Copyright (c) 2004 James Su <suzhe@tsinghua.org.cn> 00012 * 00013 * 00014 * This library is free software; you can redistribute it and/or 00015 * modify it under the terms of the GNU Lesser General Public 00016 * License as published by the Free Software Foundation; either 00017 * version 2 of the License, or (at your option) any later version. 00018 * 00019 * This library is distributed in the hope that it will be useful, 00020 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00021 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00022 * GNU Lesser General Public License for more details. 00023 * 00024 * You should have received a copy of the GNU Lesser General Public 00025 * License along with this program; if not, write to the 00026 * Free Software Foundation, Inc., 59 Temple Place, Suite 330, 00027 * Boston, MA 02111-1307 USA 00028 * 00029 * $Id: scim_property.h,v 1.4.2.1 2004/09/28 05:18:32 liuspider Exp $ 00030 */ 00031 00032 #ifndef __SCIM_PROPERTY_H 00033 #define __SCIM_PROPERTY_H 00034 00035 namespace scim { 00036 00037 #define SCIM_PROPERTY_ACTIVE 0x01 00038 #define SCIM_PROPERTY_VISIBLE 0x02 00039 00040 /** 00041 * @addtogroup Helper 00042 * 00043 * @{ 00044 */ 00045 00046 /** 00047 * @brief Class to hold a property of a IMEngineInstance object or a Panel GUI client. 00048 * 00049 * A property has four elements: 00050 * - key 00051 * An unique identify key of the property, for example: 00052 * - /TableInstance 00053 * - /TableInstance/FullWidthLetter 00054 * In this case, the second property will be a leaf (maybe a submenu item) of the first property. 00055 * - label 00056 * A label of the property which should be displayed. 00057 * - icon 00058 * An icon file of the property which should be displayed along with label. 00059 * - tip 00060 * A string to descript what the property means. 00061 * 00062 * With path like keys, the properties can form a cascade structure, which may be displayed 00063 * like a cascading menu. 00064 * 00065 * But only the top most properties can act as trigger commands 00066 * and give feedback to IMEngineInstance. 00067 */ 00068 class Property 00069 { 00070 String m_key; 00071 String m_label; 00072 String m_icon; 00073 String m_tip; 00074 uint16 m_state; 00075 00076 public: 00077 /** 00078 * @brief Default constructor 00079 */ 00080 Property () : m_state (0) { } 00081 00082 /** 00083 * @brief Constructor 00084 */ 00085 Property (const String &key, 00086 const String &label, 00087 const String &icon = String (""), 00088 const String &tip = String ("")) 00089 : m_key (key), m_label (label), m_icon (icon), 00090 m_tip (tip), m_state (SCIM_PROPERTY_VISIBLE | SCIM_PROPERTY_ACTIVE) { } 00091 00092 /** 00093 * @brief Test if this property is valid. 00094 * 00095 * @return true if this property is valid. 00096 */ 00097 bool valid () const { return m_key.length (); } 00098 00099 /** 00100 * @brief If this property is visible. 00101 * 00102 * @return true if this property is visible. 00103 */ 00104 bool visible () const { return m_state & SCIM_PROPERTY_VISIBLE; } 00105 00106 /** 00107 * @brief If this property is active. 00108 * 00109 * A active property can be clicked by users. 00110 * 00111 * @return true if this property is active. 00112 */ 00113 bool active () const { return m_state & SCIM_PROPERTY_ACTIVE; } 00114 00115 /** 00116 * @brief Get the key of this property. 00117 */ 00118 const String & get_key () const { return m_key; } 00119 00120 /** 00121 * @brief Get the label of this property. 00122 */ 00123 const String & get_label () const { return m_label; } 00124 00125 /** 00126 * @brief Get the icon file of this property. 00127 */ 00128 const String & get_icon () const { return m_icon; } 00129 00130 /** 00131 * @brief Get the tip of this property. 00132 */ 00133 const String & get_tip () const { return m_tip; } 00134 00135 /** 00136 * @brief Set a new key for this property. 00137 */ 00138 void set_key (const String & key) { m_key = key; } 00139 00140 /** 00141 * @brief Set a new label for this property. 00142 */ 00143 void set_label (const String & label) { m_label = label; } 00144 00145 /** 00146 * @brief Set a new icon file for this property. 00147 */ 00148 void set_icon (const String & icon) { m_icon = icon; } 00149 00150 /** 00151 * @brief Set a new tip for this property. 00152 */ 00153 void set_tip (const String & tip) { m_tip = tip; } 00154 00155 /** 00156 * @brief Set if this property is active. 00157 * 00158 * @param active If this property is active. 00159 */ 00160 void set_active (bool active) { 00161 if (active) m_state |= SCIM_PROPERTY_ACTIVE; 00162 else m_state &= (~ SCIM_PROPERTY_ACTIVE); 00163 } 00164 00165 void show (bool visible = true) { 00166 if (visible) m_state |= SCIM_PROPERTY_VISIBLE; 00167 else m_state &= ~SCIM_PROPERTY_VISIBLE; 00168 } 00169 00170 void hide (bool hidden = true) { show (!hidden); } 00171 00172 /** 00173 * @brief Test if this property is a leaf of another one. 00174 * 00175 * @return true if this property is a leaf of the node. 00176 */ 00177 bool is_a_leaf_of (const Property &node) const { 00178 if (m_key.length () > node.m_key.length () && 00179 m_key.substr (0, node.m_key.length ()) == node.m_key && 00180 m_key [node.m_key.length ()] == '/') 00181 return true; 00182 return false; 00183 } 00184 }; 00185 00186 inline bool 00187 operator < (const Property &lhs, const Property &rhs) { 00188 return lhs.get_key () < rhs.get_key (); 00189 } 00190 00191 inline bool 00192 operator < (const Property &lhs, const String &rhs) { 00193 return lhs.get_key () < rhs; 00194 } 00195 00196 inline bool 00197 operator < (const String &lhs, const Property &rhs) { 00198 return lhs < rhs.get_key (); 00199 } 00200 00201 inline bool 00202 operator == (const Property &lhs, const Property &rhs) { 00203 return lhs.get_key () == rhs.get_key (); 00204 } 00205 00206 inline bool 00207 operator == (const Property &lhs, const String &rhs) { 00208 return lhs.get_key () == rhs; 00209 } 00210 00211 inline bool 00212 operator == (const String &lhs, const Property &rhs) { 00213 return lhs == rhs.get_key (); 00214 } 00215 00216 inline bool 00217 operator != (const Property &lhs, const Property &rhs) { 00218 return lhs.get_key () != rhs.get_key (); 00219 } 00220 00221 inline bool 00222 operator != (const Property &lhs, const String &rhs) { 00223 return lhs.get_key () != rhs; 00224 } 00225 00226 inline bool 00227 operator != (const String &lhs, const Property &rhs) { 00228 return lhs != rhs.get_key (); 00229 } 00230 00231 /** 00232 * @typedef std::vector<Property> PropertyList; 00233 * @brief The container to store a set of Properties. 00234 * 00235 * You should use the STL container methods to manipulate its objects. 00236 */ 00237 typedef std::vector<Property> PropertyList; 00238 00239 /** @} */ 00240 00241 } // namespace scim 00242 00243 #endif //__SCIM_PROPERTY_H 00244 00245 /* 00246 vi:ts=4:nowrap:ai:expandtab 00247 */

Generated on Thu Dec 30 21:03:19 2004 for scim by doxygen 1.3.8