include/epubutils/epub_property.h

Go to the documentation of this file.
00001 
00002 // Name:        epub_property.h
00003 // Purpose:     EpProperty objects represent name/value pairs.
00004 // Author:      Julian Smart
00005 // Modified by:
00006 // Created:     2002-12-11
00007 // RCS-ID:      $Id: EpProperty.h,v 1.2 2008/01/18 13:11:24 anthemion Exp $
00008 // Copyright:   (c) Julian Smart
00009 // Licence:     New BSD License
00011 
00012 #ifndef _EPUB_PROPERTY_H_
00013 #define _EPUB_PROPERTY_H_
00014 
00015 #include "wx/variant.h"
00016 
00022 class EpProperty: public wxObject
00023 {
00024     DECLARE_CLASS(EpProperty)
00025 public:
00026     EpProperty()
00027     {
00028         m_styleValue = 0;
00029         m_show = TRUE;
00030     }
00031 
00032     EpProperty(const EpProperty& property) { Copy(property); }
00033     EpProperty(const wxString& descr, const wxVariant& variant,
00034         const wxString& editorType = wxEmptyString,
00035         const wxString& groupName = wxEmptyString,
00036         const wxString& exclusivityGroupName = wxEmptyString,
00037         long styleValue = 0)
00038     {
00039         m_description = descr;
00040         m_variant = variant;
00041         m_editorType = editorType;
00042         m_groupName = groupName;
00043         m_exclusivityGroupName = exclusivityGroupName;
00044         m_styleValue = styleValue;
00045         m_show = TRUE;
00046     }
00047 
00048     EpProperty(const wxString& name, const wxString& value = wxEmptyString)
00049     {
00050         m_variant.SetName(name);
00051         m_variant = value;
00052         m_show = TRUE;
00053     }
00054 
00055     void operator= (const EpProperty& property) { Copy(property); }
00056     void Copy(const EpProperty& property)
00057     {
00058         m_variant = property.m_variant;
00059         m_groupName = property.m_groupName;
00060         m_exclusivityGroupName = property.m_exclusivityGroupName;
00061         m_styleValue = property.m_styleValue;
00062         m_editorType = property.m_editorType;
00063         m_description = property.m_description;
00064         m_choices = property.m_choices;
00065         m_show = property.m_show;
00066         m_parentName = property.m_parentName;
00067         m_translatedName = property.m_translatedName;
00068     }
00069 
00070     bool operator== (const EpProperty& property) const
00071     {
00072         return ((m_variant == property.m_variant) &&
00073             (m_groupName == property.m_groupName) &&
00074             (m_parentName == property.m_parentName) &&
00075             (m_exclusivityGroupName == property.m_exclusivityGroupName) &&
00076             (m_styleValue == property.m_styleValue) &&
00077             (m_editorType == property.m_editorType) &&
00078             (m_description == property.m_description) &&
00079             (m_show == property.m_show) &&
00080             (m_translatedName == property.m_translatedName) &&
00081             (m_choices == property.m_choices));
00082     }
00083 
00084     bool operator!= (const EpProperty& property) const
00085     {
00086         return !((*this) == property);
00087     }
00088 
00089     inline const wxString& GetName() const { return m_variant.GetName(); }
00090     inline const wxString& GetParentName() const { return m_parentName; }
00091     inline wxString GetValue() const { return m_variant.GetString(); }
00092     inline wxVariant& GetVariant() { return m_variant; }
00093     inline const wxVariant& GetVariant() const { return m_variant; }
00094     inline const wxString& GetEditorType() const { return m_editorType; }
00095     inline const wxString& GetGroupName() const { return m_groupName; }
00096     inline const wxString GetCategory() const { return m_category; }
00097     inline const wxString& GetExclusivityGroupName() const { return m_exclusivityGroupName; }
00098     inline long GetStyleValue() const { return m_styleValue; }
00099     inline const wxArrayString& GetChoices() const { return m_choices; }
00100     inline const wxString& GetDescription() const { return m_description; }
00101     inline const wxString& GetMinVersion() const { return m_minVersion; }
00102     inline const wxString& GetMaxVersion() const { return m_maxVersion; }
00103     
00104     inline void SetName(const wxString& name) { m_variant.SetName(name); }
00105     inline void SetParentName(const wxString& name) { m_parentName = name; }
00106     inline void SetValue(const wxString& value) { m_variant = value; }
00107     inline void SetValue(const wxVariant& value) { m_variant = value; }
00108     inline void SetEditorType(const wxString& type) { m_editorType = type; }
00109     inline void SetGroupName(const wxString& groupName) { m_groupName = groupName; }
00110     inline void SetCategory(const wxString& category) { m_category = category; }
00111     inline void SetExclusivityGroupName(const wxString& name) { m_exclusivityGroupName = name; }
00112     inline void SetStyleValue(long style) { m_styleValue = style; }
00113     inline void SetChoices(const wxArrayString& choices) { m_choices = choices; }
00114     inline void SetDescription(const wxString& descr) { m_description = descr; }
00115     inline void SetMinMaxVersion(const wxString& minVersion, const wxString& maxVersion)
00116         { m_minVersion = minVersion; m_maxVersion = maxVersion; }
00117     inline void Show(bool show) { m_show = show; }
00118     inline bool IsShown() const { return m_show; }
00119 
00120     // Get/set the visible translation, if any
00121     const wxString& GetTranslatedName() const { return m_translatedName; }
00122     void SetTranslatedName(const wxString& name) { m_translatedName = name; }
00123 
00124     // Get display name - translation if available, or actual
00125     wxString GetDisplayName() const { return m_translatedName.IsEmpty() ? GetName() : GetTranslatedName(); }
00126 
00127     // Is this property applicable to the given wxWidgets version?
00128     bool IsApplicableToVersion(const wxString& useVersion) const;
00129 
00130     // The name and value
00131     wxVariant   m_variant;
00132 
00133     // The visible translation, if any
00134     wxString    m_translatedName;
00135 
00136     // The editor type name (e.g. "file")
00137     // used to choose an editor.
00138     wxString    m_editorType;
00139 
00140     // The group name, e.g. window-style
00141     wxString    m_groupName;
00142 
00143     // The parent property name. Can be dot-separated if more than one.
00144     wxString    m_parentName;
00145 
00146     // Exclusivity group name, e.g. vertical-alignment
00147     wxString    m_exclusivityGroupName;
00148 
00149     // Style value, if any.
00150     long        m_styleValue;
00151 
00152     // Array of choices
00153     wxArrayString   m_choices;
00154 
00155     // Description
00156     wxString        m_description;
00157 
00158     // Min wxWidgets version appropriate for this property/style
00159     wxString        m_minVersion;
00160 
00161     // Max wxWidgets version appropriate for this property/style
00162     wxString        m_maxVersion;
00163 
00164     // Category for this property
00165     wxString        m_category;
00166 
00167     // Whether to show or hide (e.g. not properly initialized)
00168     bool            m_show;
00169 };
00170 
00171 // A class to manage properties
00172 class EpProperties: public wxObject
00173 {
00174     DECLARE_CLASS(EpProperties)
00175 public:
00176     EpProperties() {}
00177     EpProperties(const EpProperties& properties) { Copy(properties); }
00178     ~EpProperties() { Clear(); }
00179 
00180     void operator = (const EpProperties& properties) { Clear(); Copy(properties); }
00181     bool operator == (const EpProperties& properties) ;
00182     void Copy(const EpProperties& properties);
00183 
00184     inline const wxList& GetList() const { return m_list; }
00185 
00186     inline size_t GetCount() const { return m_list.GetCount(); }
00187 
00188     EpProperty* AddProperty(EpProperty* property, const wxString& insertAfter = wxEmptyString);
00189     void SetProperty(const wxString& name, const wxString& value);
00190     void SetProperty(const wxString& name, long value);
00191     void SetProperty(const wxString& name, int value) { SetProperty(name, (long) value); }
00192     void SetProperty(const wxString& name, double value);
00193     void SetProperty(const wxString& name, bool value);
00194     void SetProperty(const wxString& name, const wxVariant& value);
00195     void RemoveProperty(EpProperty* property);
00196     void DeleteProperty(EpProperty* property);
00197     void DeleteProperty(const wxString& name);
00198     void DeleteProperty(size_t i);
00199     EpProperty* FindProperty(const wxString& name) const;
00200     EpProperty* FindPropertyByDisplayName(const wxString& name);
00201     EpProperty* FindOrCreateProperty(const wxString& name);
00202     wxString FindPropertyValueString(const wxString& name) const;
00203     bool FindPropertyValueBool(const wxString& name) const;
00204     long FindPropertyValueLong(const wxString& name) const;
00205     double FindPropertyValueDouble(const wxString& name) const;
00206     wxVariant FindPropertyValue(const wxString& name) const;
00207     EpProperty* GetNth(int i) const;
00208     EpProperty* GetProperty(int i) const { return GetNth(i); }
00209     
00210     // Remove any spurious properties that need garbage
00211     // collecting.
00212     void RemoveHiddenProperties();
00213 
00214 // Dealing with styles
00215 
00220     long CombineStyles(const wxString& groupName, const wxString& useVersion = wxEmptyString);
00221 
00226     wxString CombineStylesString(const wxString& groupName, const wxString& useVersion = wxEmptyString);
00227 
00228     void Clear();
00229 
00230 private:
00231     wxList      m_list;
00232 };
00233 
00234 #endif
00235     // _EPUB_PROPERTY_H_
00236 

Generated on Wed May 6 19:20:18 2009 for AxTk by  doxygen 1.5.1