]> git.saurik.com Git - wxWidgets.git/blob - contrib/include/wx/applet/ifelsevar.h
made XPM data const
[wxWidgets.git] / contrib / include / wx / applet / ifelsevar.h
1 /****************************************************************************
2 *
3 * wxWindows HTML Applet Package
4 *
5 * Copyright (C) 1991-2001 SciTech Software, Inc.
6 * All rights reserved.
7 *
8 * ========================================================================
9 *
10 * The contents of this file are subject to the wxWindows License
11 * Version 3.0 (the "License"); you may not use this file except in
12 * compliance with the License. You may obtain a copy of the License at
13 * http://www.wxwindows.org/licence3.txt
14 *
15 * Software distributed under the License is distributed on an
16 * "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
17 * implied. See the License for the specific language governing
18 * rights and limitations under the License.
19 *
20 * ========================================================================
21 *
22 * Language: ANSI C++
23 * Environment: Any
24 *
25 * Description: Header file for wxIfElseVariable Class, Dynamically constructed
26 * objects representing variables in SSI #if, #else and #endif directives
27 *
28 ****************************************************************************/
29
30 #ifndef __WX_IFELSEVAR_H
31 #define __WX_IFELSEVAR_H
32
33 #include "wx/object.h"
34 #include "wx/hash.h"
35
36 /*--------------------------- Class Definitions ---------------------------*/
37
38 /****************************************************************************
39 RETURNS:
40 The boolean value of the variable
41
42 REMARKS:
43 To create new variables for the #if, #else and #endif HTML preprocessing
44 blocks you need to derive classes from wxIfElseVariable and override the
45 pure virtual GetValue function. However this should not be done directly
46 but by using the BEGIN_IFELSE_VARIABLE and END_IFELSE_VARIABLE macros
47
48 SEE ALSO:
49 wxIfElsePrep, BEGIN_IFELSE_VARIABLE, END_IFELSE_VARIABLE
50 ****************************************************************************/
51 typedef bool (*wxIfElseVariableGetValueFn)();
52
53 /****************************************************************************
54 REMARKS:
55 wxIfElseVariable class Definition
56 ****************************************************************************/
57 class wxIfElseVariable : public wxObject {
58 protected:
59 const wxChar *m_varName;
60 wxIfElseVariableGetValueFn m_getValueFn;
61 static wxIfElseVariable *sm_first;
62 wxIfElseVariable *m_next;
63 static wxHashTable *sm_varTable;
64 bool forced;
65 bool forceVal;
66
67 static inline wxIfElseVariable *wxIfElseVariable::FindVariable(const wxChar *varName);
68
69 public:
70 // Constructor to create the echo variable and register the class
71 wxIfElseVariable(
72 const char *varName,
73 wxIfElseVariableGetValueFn getValueFn);
74
75 // Member variable access functions
76 const wxChar *GetClassName() const { return m_varName; }
77 wxIfElseVariableGetValueFn GetValueFn() const { return m_getValueFn; }
78 static const wxIfElseVariable* GetFirst() { return sm_first; }
79 const wxIfElseVariable* GetNext() const { return m_next; }
80
81 // Static functions to retrieve any variable avaliable
82 static bool GetValue(const wxChar *varName);
83 static bool Exists(const wxChar *varName);
84 static void Force(const wxChar *varName, bool val);
85
86 // Initializes parent pointers and hash table for fast searching.
87 static void Initialize();
88
89 // Cleans up hash table used for fast searching.
90 static void CleanUp();
91 };
92
93 /****************************************************************************
94 PARAMETERS:
95 class - Name of class for echo variable to find
96
97 RETURNS:
98 Pointer to the echo variable class
99
100 REMARKS:
101 Inline helper function to find the echo variable from it's class name.
102 ****************************************************************************/
103 inline wxIfElseVariable *wxIfElseVariable::FindVariable(
104 const wxChar *varName)
105 {
106 if (sm_varTable)
107 return (wxIfElseVariable*)sm_varTable->Get(varName);
108 else {
109 wxIfElseVariable *info = sm_first;
110 while (info) {
111 if (info->m_varName && wxStrcmp(info->m_varName, varName) == 0)
112 return info;
113 info = info->m_next;
114 }
115 return NULL;
116 }
117 }
118
119 /*--------------------------------- MACROS --------------------------------*/
120
121 #define BEGIN_IFELSE_VARIABLE(name) \
122 bool wxIfElseVariableFn##name(); \
123 wxIfElseVariable wxIfElseVariable##name(#name,wxIfElseVariableFn##name); \
124 bool wxIfElseVariableFn##name() { \
125
126 #define END_IFELSE_VARIABLE(returnval) \
127 return returnval; \
128 }
129
130 #define IFELSE_VARIABLE(name, state) \
131 BEGIN_IFELSE_VARIABLE(##name##); \
132 END_IFELSE_VARIABLE(bool (state))
133
134 #endif // __WX_IFELSEVAR_H
135