attribute.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  1. #ifndef _ATTRIBUTE_H
  2. #define _ATTRIBUTE_H
  3. #include <bfc/depend.h>
  4. #include <bfc/named.h>
  5. #include <bfc/common.h>
  6. #include <bfc/string/StringW.h>
  7. class CfgItemI;
  8. // lowercase types are reserved for official Nullsoft use
  9. // uppercase are 3rd-party defined
  10. namespace AttributeType {
  11. /**
  12. Attribute types.
  13. */
  14. enum {
  15. NONE = 0,
  16. INT = MK3CC('i','n','t'), // attrint.h
  17. STRING = MK3CC('s','t','r'), // attrstr.h
  18. BOOL = MK4CC('b','o','o','l'), // attrbool.h
  19. FLOAT = MK4CC('f','l','o','t'), // attrfloat.h
  20. FILENAME = MK2CC('f','n'), // attrfn.h
  21. };
  22. };
  23. /**
  24. Generic configuration attribute.
  25. Configuration attributes enable you to store
  26. uniquely identifiable values that get pushed
  27. to a configuration file automatically upon shutdown
  28. of any Wasabi application.
  29. You shouldn't normally use this on
  30. it's own, look at the CfgItemI class
  31. instead.
  32. @short Generic configuration attribute.
  33. @ver 1.0
  34. @author Nullsoft
  35. @see _float
  36. @see _int
  37. @see _bool
  38. @see _string
  39. @see CfgItemI
  40. */
  41. class NOVTABLE Attribute : public DependentI, private NamedW
  42. {
  43. public:
  44. static const GUID *depend_getClassGuid() {
  45. // {5AB601D4-1628-4604-808A-7ED899849BEB}
  46. static const GUID ret =
  47. { 0x5ab601d4, 0x1628, 0x4604, { 0x80, 0x8a, 0x7e, 0xd8, 0x99, 0x84, 0x9b, 0xeb } };
  48. return &ret;
  49. }
  50. protected:
  51. /**
  52. Optionally set the name and default value of
  53. your configuration attribute during construction.
  54. @param name Name of the configuration attribute.
  55. @param default_val Default value.
  56. */
  57. Attribute(const wchar_t *name=NULL, const wchar_t *desc=NULL);
  58. public:
  59. virtual ~Attribute();
  60. /**
  61. Set the name of the configuration
  62. attribute.
  63. @param newname Name of the attribute.
  64. */
  65. void setName(const wchar_t *newname);
  66. /**
  67. Get the name of the configuration
  68. attribute.
  69. @ret Name of the attribute.
  70. */
  71. const wchar_t *getAttributeName();
  72. /**
  73. Get the attribute's description.
  74. @ret Attribute's description.
  75. */
  76. const wchar_t *getAttributeDesc();
  77. /**
  78. Get the attribute type. Override
  79. this for your custom attribute type.
  80. @ret Attribute type.
  81. */
  82. virtual int getAttributeType()=0; // override me
  83. /**
  84. Get the configuration group to be used to represent
  85. this attribute in the registry.
  86. This is only called if the kernel doesn't have a default
  87. config group set for your type already.
  88. @ret Config group to be used.
  89. */
  90. virtual const wchar_t *getConfigGroup() { return NULL; } // override me
  91. /**
  92. Get the attribute's value as signed integer.
  93. @ret Attribute value, as a signed integer.
  94. */
  95. int getValueAsInt();
  96. /**
  97. Set the attribute's value with a signed integer while
  98. also being able to replace the default value previously
  99. set.
  100. @param newval Attribute's new value.
  101. @param def true, replace the current default value; false, leave the default value unchanged;
  102. */
  103. int setValueAsInt(int newval, bool def=false);
  104. /**
  105. Get the attribute's value as signed double.
  106. @ret Attribute value, as a signed double.
  107. */
  108. double getValueAsDouble();
  109. /**
  110. Set the attribute's value with a signed double while
  111. also being able to replace the default value previously
  112. set.
  113. @param newval Attribute's new value.
  114. @param def true, replace the current default value; false, leave the default value unchanged;
  115. */
  116. double setValueAsDouble(double newval, bool def=false);
  117. /**
  118. Get the length of the attribute's value (data)
  119. in bytes.
  120. @ret Attribute value (data) length, in bytes.
  121. */
  122. int getDataLen();
  123. /**
  124. Get the attribute's raw data.
  125. This will return the data the attribute is storing
  126. in a char buffer you hand to it.
  127. @ret Attribute value, as a signed double.
  128. @param data Pointer to a char buffer.
  129. @param data_len The maximum amount of bytes the char buffer can hold.
  130. */
  131. int getData(wchar_t *data, int data_len);
  132. /**
  133. Set the attribute's value with a zero terminated string. Also
  134. enables you to replace the default value previously
  135. set.
  136. @param newval Attribute's new value.
  137. @param def true, replace the current default value; false, leave the default value unchanged;
  138. */
  139. int setData(const wchar_t *data, bool def=false);
  140. void disconnect();
  141. enum {
  142. Event_DATACHANGE=100,
  143. };
  144. protected:
  145. friend class CfgItemI;
  146. /**
  147. Set the attribute's value without causing
  148. a callback.
  149. @ret 1.
  150. @param data Attribute's new value.
  151. */
  152. int setDataNoCB(const wchar_t *data);
  153. /**
  154. Set the configuration item associated with this
  155. attribute.
  156. */
  157. void setCfgItem(CfgItemI *item);
  158. StringW mkTag();
  159. private:
  160. StringW desc;
  161. StringW default_val, *private_storage;
  162. CfgItemI *cfgitemi;
  163. };
  164. #define ATTR_PERM_READ 1
  165. #define ATTR_PERM_WRITE 2
  166. #define ATTR_PERM_ALL (~0)
  167. // render hints for getRenderHint
  168. enum {
  169. ATTR_RENDER_HINT_INT_CHECKMARK
  170. };
  171. #endif