aboutsummaryrefslogtreecommitdiff
path: root/Src/Wasabi/api/config/items/attribute.h
blob: c91e8065b32d00063c321465e763f30c843e1b67 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
#ifndef _ATTRIBUTE_H
#define _ATTRIBUTE_H

#include <bfc/depend.h>
#include <bfc/named.h>
#include <bfc/common.h>
#include <bfc/string/StringW.h>

class CfgItemI;

// lowercase types are reserved for official Nullsoft use
// uppercase are 3rd-party defined
namespace AttributeType {
  /**
    Attribute types.
  */
  enum {
    NONE = 0,
    INT = MK3CC('i','n','t'),		// attrint.h
    STRING = MK3CC('s','t','r'),	// attrstr.h
    BOOL = MK4CC('b','o','o','l'),	// attrbool.h
    FLOAT = MK4CC('f','l','o','t'),	// attrfloat.h
    FILENAME = MK2CC('f','n'),		// attrfn.h
  };
};

/**
  Generic configuration attribute. 
  
  Configuration attributes enable you to store 
  uniquely identifiable values that get pushed 
  to a configuration file automatically upon shutdown 
  of any Wasabi application.
  
  You shouldn't normally use this on 
  it's own, look at the CfgItemI class 
  instead.

  @short Generic configuration attribute.
  @ver 1.0
  @author Nullsoft
  @see _float
  @see _int
  @see _bool
  @see _string
  @see CfgItemI
*/
class NOVTABLE Attribute : public DependentI, private NamedW 
{
public:
  static const GUID *depend_getClassGuid() {
    // {5AB601D4-1628-4604-808A-7ED899849BEB}
    static const GUID ret = 
    { 0x5ab601d4, 0x1628, 0x4604, { 0x80, 0x8a, 0x7e, 0xd8, 0x99, 0x84, 0x9b, 0xeb } };
    return &ret;
  }
protected:
  
  /**
    Optionally set the name and default value of 
    your configuration attribute during construction.
    
    @param name Name of the configuration attribute.
    @param default_val Default value.
  */
  Attribute(const wchar_t *name=NULL, const wchar_t *desc=NULL);
  
public:
  virtual ~Attribute();

  /**
    Set the name of the configuration
    attribute.
    
    @param newname Name of the attribute.
  */
  void setName(const wchar_t *newname);
  
  /**
    Get the name of the configuration
    attribute.
    
    @ret Name of the attribute.
  */
  const wchar_t *getAttributeName();

  /**
    Get the attribute's description.
    
    @ret Attribute's description.
  */
  const wchar_t *getAttributeDesc();

  /**
    Get the attribute type. Override
    this for your custom attribute type.
    
    @ret Attribute type.
  */
  virtual int getAttributeType()=0;	// override me
  
  /**
    Get the configuration group to be used to represent
    this attribute in the registry. 
    
    This is only called if the kernel doesn't have a default 
    config group set for your type already.
    
    @ret Config group to be used.
  */
  virtual const wchar_t *getConfigGroup() { return NULL; }	// override me

  /**
    Get the attribute's value as signed integer.
    
    @ret Attribute value, as a signed integer.
  */
  int getValueAsInt();
  
  /**
    Set the attribute's value with a signed integer while
    also being able to replace the default value previously
    set.
    
    @param newval Attribute's new value.
    @param def true, replace the current default value; false, leave the default value unchanged;
  */
  int setValueAsInt(int newval, bool def=false);

  /**
    Get the attribute's value as signed double.
    
    @ret Attribute value, as a signed double.
  */
  double getValueAsDouble();
  
  /**
    Set the attribute's value with a signed double while
    also being able to replace the default value previously
    set.
    
    @param newval Attribute's new value.
    @param def true, replace the current default value; false, leave the default value unchanged;
  */
  double setValueAsDouble(double newval, bool def=false);

  /**
    Get the length of the attribute's value (data)
    in bytes.
    
    @ret Attribute value (data) length, in bytes.
  */
  int getDataLen();

  /**
    Get the attribute's raw data. 
    
    This will return the data the attribute is storing
    in a char buffer you hand to it.
    
    @ret Attribute value, as a signed double.
    @param data Pointer to a char buffer.
    @param data_len The maximum amount of bytes the char buffer can hold.
  */
  int getData(wchar_t *data, int data_len);
  
  /**
    Set the attribute's value with a zero terminated string. Also 
    enables you to replace the default value previously
    set.
    
    @param newval Attribute's new value.
    @param def true, replace the current default value; false, leave the default value unchanged;
  */
  int setData(const wchar_t *data, bool def=false);

  void disconnect();

  enum {
    Event_DATACHANGE=100,
  };
protected:
  friend class CfgItemI;
  
  /**
    Set the attribute's value without causing 
    a callback.

    @ret 1.
    @param data Attribute's new value.
  */
  int setDataNoCB(const wchar_t *data);
  
  /**
    Set the configuration item associated with this
    attribute.
  */
  void setCfgItem(CfgItemI *item);

  StringW mkTag();

private:
  StringW desc;
	StringW default_val, *private_storage;
  CfgItemI *cfgitemi;
};

#define ATTR_PERM_READ	1
#define ATTR_PERM_WRITE	2

#define ATTR_PERM_ALL	(~0)

// render hints for getRenderHint
enum {
  ATTR_RENDER_HINT_INT_CHECKMARK
};

#endif