[2798] | 1 | /* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- */ |
---|
[1365] | 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, |
---|
[2877] | 40 | const char *switchName, Tcl_Obj *valueObjPtr, |
---|
| 41 | char *record, int offset, |
---|
| 42 | int flags); |
---|
| 43 | |
---|
[1365] | 44 | typedef void (SwitchFreeProc)(char *record, int offset, int flags); |
---|
| 45 | |
---|
| 46 | typedef struct { |
---|
| 47 | SwitchParseProc *parseProc; /* Procedure to parse a switch |
---|
| 48 | * value and store it in its * |
---|
| 49 | * converted form in the data * |
---|
| 50 | * record. */ |
---|
| 51 | |
---|
| 52 | SwitchFreeProc *freeProc; /* Procedure to free a switch. */ |
---|
| 53 | |
---|
| 54 | ClientData clientData; /* Arbitrary one-word value used by |
---|
| 55 | * switch parser, passed to |
---|
| 56 | * parseProc. */ |
---|
| 57 | } SwitchCustom; |
---|
| 58 | |
---|
| 59 | |
---|
| 60 | /* |
---|
| 61 | * Type values for SwitchSpec structures. See the user |
---|
| 62 | * documentation for details. |
---|
| 63 | */ |
---|
| 64 | typedef enum { |
---|
| 65 | SWITCH_BOOLEAN, |
---|
| 66 | SWITCH_DOUBLE, |
---|
| 67 | SWITCH_BITMASK, |
---|
| 68 | SWITCH_BITMASK_NEG, |
---|
| 69 | SWITCH_FLOAT, |
---|
| 70 | SWITCH_INT, |
---|
| 71 | SWITCH_INT_NNEG, |
---|
| 72 | SWITCH_INT_POS, |
---|
| 73 | SWITCH_LIST, |
---|
| 74 | SWITCH_LONG, |
---|
| 75 | SWITCH_LONG_NNEG, |
---|
| 76 | SWITCH_LONG_POS, |
---|
| 77 | SWITCH_OBJ, |
---|
| 78 | SWITCH_STRING, |
---|
| 79 | SWITCH_VALUE, |
---|
| 80 | SWITCH_CUSTOM, |
---|
| 81 | SWITCH_END |
---|
| 82 | } SwitchTypes; |
---|
| 83 | |
---|
| 84 | |
---|
| 85 | typedef struct { |
---|
| 86 | SwitchTypes type; /* Type of option, such as |
---|
| 87 | * SWITCH_COLOR; see definitions |
---|
| 88 | * below. Last option in table must |
---|
| 89 | * have type SWITCH_END. */ |
---|
| 90 | |
---|
| 91 | const char *switchName; /* Switch used to specify option in |
---|
| 92 | * argv. NULL means this spec is part |
---|
| 93 | * of a group. */ |
---|
| 94 | |
---|
| 95 | const char *help; /* Help string. */ |
---|
| 96 | int offset; /* Where in widget record to store |
---|
| 97 | * value; use Blt_Offset macro to |
---|
| 98 | * generate values for this. */ |
---|
| 99 | |
---|
| 100 | int flags; /* Any combination of the values |
---|
| 101 | * defined below. */ |
---|
| 102 | |
---|
| 103 | unsigned int mask; |
---|
| 104 | |
---|
| 105 | SwitchCustom *customPtr; /* If type is SWITCH_CUSTOM then |
---|
| 106 | * this is a pointer to info about how |
---|
| 107 | * to parse and print the option. |
---|
| 108 | * Otherwise it is irrelevant. */ |
---|
| 109 | } SwitchSpec; |
---|
| 110 | |
---|
| 111 | #define SWITCH_DEFAULTS (0) |
---|
| 112 | #define SWITCH_ARGV_PARTIAL (1<<1) |
---|
| 113 | #define SWITCH_OBJV_PARTIAL (1<<1) |
---|
| 114 | |
---|
| 115 | /* |
---|
| 116 | * Possible flag values for Blt_SwitchSpec structures. Any bits at or |
---|
| 117 | * above BLT_SWITCH_USER_BIT may be used by clients for selecting |
---|
| 118 | * certain entries. |
---|
| 119 | */ |
---|
| 120 | #define SWITCH_NULL_OK (1<<0) |
---|
| 121 | #define SWITCH_DONT_SET_DEFAULT (1<<3) |
---|
| 122 | #define SWITCH_SPECIFIED (1<<4) |
---|
| 123 | #define SWITCH_USER_BIT (1<<8) |
---|
| 124 | |
---|
| 125 | extern int ParseSwitches(Tcl_Interp *interp, SwitchSpec *specPtr, |
---|
[2877] | 126 | int objc, Tcl_Obj *const *objv, |
---|
| 127 | void *rec, int flags); |
---|
[1365] | 128 | |
---|
| 129 | extern void FreeSwitches(SwitchSpec *specs, void *rec, int flags); |
---|
| 130 | |
---|
| 131 | extern int SwitchChanged TCL_VARARGS(SwitchSpec *, specs); |
---|
| 132 | |
---|
| 133 | } |
---|
| 134 | |
---|
| 135 | #endif /* BLT_SWITCH_H */ |
---|