1 | |
---|
2 | /* |
---|
3 | * Switch.h -- |
---|
4 | * |
---|
5 | * Copyright 1993-2004 George A Howlett. |
---|
6 | * |
---|
7 | * Permission is hereby granted, free of charge, to any person |
---|
8 | * obtaining a copy of this software and associated documentation |
---|
9 | * files (the "Software"), to deal in the Software without |
---|
10 | * restriction, including without limitation the rights to use, |
---|
11 | * copy, modify, merge, publish, distribute, sublicense, and/or |
---|
12 | * sell copies of the Software, and to permit persons to whom the |
---|
13 | * Software is furnished to do so, subject to the following |
---|
14 | * conditions: |
---|
15 | * |
---|
16 | * The above copyright notice and this permission notice shall be |
---|
17 | * included in all copies or substantial portions of the |
---|
18 | * Software. |
---|
19 | * |
---|
20 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY |
---|
21 | * KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE |
---|
22 | * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR |
---|
23 | * PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS |
---|
24 | * OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR |
---|
25 | * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR |
---|
26 | * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE |
---|
27 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
---|
28 | */ |
---|
29 | |
---|
30 | #ifndef SWITCH_H |
---|
31 | #define SWITCH_H |
---|
32 | |
---|
33 | #ifdef HAVE_STDDEF_H |
---|
34 | # include <stddef.h> |
---|
35 | #endif /* HAVE_STDDEF_H */ |
---|
36 | |
---|
37 | namespace Rappture { |
---|
38 | |
---|
39 | typedef int (SwitchParseProc)(ClientData clientData, Tcl_Interp *interp, |
---|
40 | const char *switchName, Tcl_Obj *valueObjPtr, char *record, int offset, |
---|
41 | int flags); |
---|
42 | typedef void (SwitchFreeProc)(char *record, int offset, int flags); |
---|
43 | |
---|
44 | typedef struct { |
---|
45 | SwitchParseProc *parseProc; /* Procedure to parse a switch |
---|
46 | * value and store it in its * |
---|
47 | * converted form in the data * |
---|
48 | * record. */ |
---|
49 | |
---|
50 | SwitchFreeProc *freeProc; /* Procedure to free a switch. */ |
---|
51 | |
---|
52 | ClientData clientData; /* Arbitrary one-word value used by |
---|
53 | * switch parser, passed to |
---|
54 | * parseProc. */ |
---|
55 | } SwitchCustom; |
---|
56 | |
---|
57 | |
---|
58 | /* |
---|
59 | * Type values for SwitchSpec structures. See the user |
---|
60 | * documentation for details. |
---|
61 | */ |
---|
62 | typedef enum { |
---|
63 | SWITCH_BOOLEAN, |
---|
64 | SWITCH_DOUBLE, |
---|
65 | SWITCH_BITMASK, |
---|
66 | SWITCH_BITMASK_NEG, |
---|
67 | SWITCH_FLOAT, |
---|
68 | SWITCH_INT, |
---|
69 | SWITCH_INT_NNEG, |
---|
70 | SWITCH_INT_POS, |
---|
71 | SWITCH_LIST, |
---|
72 | SWITCH_LONG, |
---|
73 | SWITCH_LONG_NNEG, |
---|
74 | SWITCH_LONG_POS, |
---|
75 | SWITCH_OBJ, |
---|
76 | SWITCH_STRING, |
---|
77 | SWITCH_VALUE, |
---|
78 | SWITCH_CUSTOM, |
---|
79 | SWITCH_END |
---|
80 | } SwitchTypes; |
---|
81 | |
---|
82 | |
---|
83 | typedef struct { |
---|
84 | SwitchTypes type; /* Type of option, such as |
---|
85 | * SWITCH_COLOR; see definitions |
---|
86 | * below. Last option in table must |
---|
87 | * have type SWITCH_END. */ |
---|
88 | |
---|
89 | const char *switchName; /* Switch used to specify option in |
---|
90 | * argv. NULL means this spec is part |
---|
91 | * of a group. */ |
---|
92 | |
---|
93 | const char *help; /* Help string. */ |
---|
94 | int offset; /* Where in widget record to store |
---|
95 | * value; use Blt_Offset macro to |
---|
96 | * generate values for this. */ |
---|
97 | |
---|
98 | int flags; /* Any combination of the values |
---|
99 | * defined below. */ |
---|
100 | |
---|
101 | unsigned int mask; |
---|
102 | |
---|
103 | SwitchCustom *customPtr; /* If type is SWITCH_CUSTOM then |
---|
104 | * this is a pointer to info about how |
---|
105 | * to parse and print the option. |
---|
106 | * Otherwise it is irrelevant. */ |
---|
107 | } SwitchSpec; |
---|
108 | |
---|
109 | #define SWITCH_DEFAULTS (0) |
---|
110 | #define SWITCH_ARGV_PARTIAL (1<<1) |
---|
111 | #define SWITCH_OBJV_PARTIAL (1<<1) |
---|
112 | |
---|
113 | /* |
---|
114 | * Possible flag values for Blt_SwitchSpec structures. Any bits at or |
---|
115 | * above BLT_SWITCH_USER_BIT may be used by clients for selecting |
---|
116 | * certain entries. |
---|
117 | */ |
---|
118 | #define SWITCH_NULL_OK (1<<0) |
---|
119 | #define SWITCH_DONT_SET_DEFAULT (1<<3) |
---|
120 | #define SWITCH_SPECIFIED (1<<4) |
---|
121 | #define SWITCH_USER_BIT (1<<8) |
---|
122 | |
---|
123 | extern int ParseSwitches(Tcl_Interp *interp, SwitchSpec *specPtr, |
---|
124 | int objc, Tcl_Obj *const *objv, void *rec, int flags); |
---|
125 | |
---|
126 | extern void FreeSwitches(SwitchSpec *specs, void *rec, int flags); |
---|
127 | |
---|
128 | extern int SwitchChanged TCL_VARARGS(SwitchSpec *, specs); |
---|
129 | |
---|
130 | } |
---|
131 | |
---|
132 | #endif /* BLT_SWITCH_H */ |
---|