]> git.saurik.com Git - wxWidgets.git/blob - contrib/src/applet/ifelsevar.cpp
Make wxBase compiled for wxMotif compatible with wxbase compiled
[wxWidgets.git] / contrib / src / applet / ifelsevar.cpp
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: Implementation of wxIfElseVariable Class, Dynamically constructed
26 * objects representing variables in SSI #if, #else, and #endif directives
27 *
28 ****************************************************************************/
29
30 // Include private headers
31 #include "wx/applet/ifelsevar.h"
32
33 // wxWindows forcelink macro
34 #include "wx/html/forcelnk.h"
35 #include "wx/msgdlg.h"
36
37 /*---------------------------- Global variables ---------------------------*/
38
39 static wxIfElseVariable *wxIfElseVariable::sm_first = NULL;
40 static wxHashTable *wxIfElseVariable::sm_varTable = NULL;
41
42 /*----------------------------- Implementation ----------------------------*/
43
44 /****************************************************************************
45 PARAMETERS:
46 varName - The String name of the class
47 getValueFn - Pointer to the function that returns the echo variable value
48
49 REMARKS:
50 Constructor for the wxIfElseVariable class that self registers itself with
51 the list of all echo variables when the static class instance is created
52 at program init time (remember all the constructors get called before
53 the main program function!).
54 ****************************************************************************/
55 wxIfElseVariable::wxIfElseVariable(
56 const char *varName,
57 wxIfElseVariableGetValueFn getValueFn)
58 {
59 m_varName = varName;
60 m_getValueFn = getValueFn;
61 m_next = sm_first;
62 sm_first = this;
63 }
64
65 /****************************************************************************
66 REMARKS:
67 Initializes parent pointers and hash table for fast searching for echo
68 variables.
69 ****************************************************************************/
70 void wxIfElseVariable::Initialize()
71 {
72 wxIfElseVariable::sm_varTable = new wxHashTable(wxKEY_STRING);
73
74 // Index all class infos by their class name
75 wxIfElseVariable *info = sm_first;
76 while (info) {
77 if (info->m_varName)
78 sm_varTable->Put(info->m_varName, info);
79 info = info->m_next;
80 }
81 }
82
83 /****************************************************************************
84 REMARKS:
85 Clean up echo variable hash tables on application exit.
86 ****************************************************************************/
87 void wxIfElseVariable::CleanUp()
88 {
89 delete wxIfElseVariable::sm_varTable;
90 wxIfElseVariable::sm_varTable = NULL;
91 }
92
93 /****************************************************************************
94 PARAMETERS:
95 varName - The String name of the class
96
97 REMARKS:
98 Constructor for the wxIfElseVariable class that self registers itself with
99 the list of all ifelse variables when the static class instance is created
100 at program init time (remember all the constructors get called before
101 the main program function!).
102 ****************************************************************************/
103 bool wxIfElseVariable::GetValue(
104 const wxChar *varName)
105 {
106 wxIfElseVariable *info = wxIfElseVariable::FindVariable(varName);
107 if (info) {
108 // Return the forced value if the variable has been forced.
109 if (info->forced)
110 return info->forceVal;
111 return info->m_getValueFn();
112 }
113 #ifdef CHECKED
114 wxMessageBox(wxString("wxHTML #if error: Class is not a valid if else variable (") + varName + wxString(")."),"Error",wxICON_ERROR);
115 #endif
116 return wxString("");
117 }
118
119 /****************************************************************************
120 PARAMETERS:
121 varName - The String name of the class
122
123 RETURNS:
124 True if the if/else variable exists, false if not.
125 ****************************************************************************/
126 bool wxIfElseVariable::Exists(
127 const wxChar *varName)
128 {
129 return wxIfElseVariable::FindVariable(varName) != NULL;
130 }
131
132 /****************************************************************************
133 PARAMETERS:
134 varName - The String name of the class
135 val - Value to force the if/else variable with
136
137 REMARKS:
138 Function to forcibly override the value of an if/else variable for
139 testing purposes. Once the variable has been forced, it will always return
140 the forced value until the application exists.
141
142 NOTE: This is only available when compiled in CHECKED mode.
143 ****************************************************************************/
144 void wxIfElseVariable::Force(
145 const wxChar *varName,
146 bool val)
147 {
148 wxIfElseVariable *info = wxIfElseVariable::FindVariable(varName);
149 if (info) {
150 info->forced = true;
151 info->forceVal = val;
152 }
153 else {
154 #ifdef CHECKED
155 wxMessageBox(wxString("wxHTML #if error: Class is not a valid if else variable (") + varName + wxString(")."),"Error",wxICON_ERROR);
156 #endif
157 }
158 }
159
160 /*------------------------ Macro Documentation ---------------------------*/
161
162 // Here we declare some fake functions to get doc-jet to properly document the macros
163
164 #undef BEGIN_IFELSE_VARIABLE
165 /****************************************************************************
166 PARAMETERS:
167 name - The name of the variable to create
168
169 REMARKS:
170 This macro is used to create variables for use by the #if, #else and #endif
171 blocks in the HTML preprocessor.
172 To create a new variable include the code necessary to get the value of the
173 variable between a block of BEGIN_IFELSE_VARIABLE and END_IFELSE_VARIABLE macros.
174
175 EXAMPLE:
176 BEGIN_IFELSE_VARIABLE(UserName)
177 // Get username from nucleus
178 bool tmp = GA_HasRegistered();
179 END_IFELSE_VARIABLE(UserName, tmp)
180
181 SEE ALSO:
182 wxIfElseVariable, wxIfElsePrep, END_IFELSE_VARIABLE, IFELSE_VARIABLE
183 ****************************************************************************/
184 void BEGIN_IFELSE_VARIABLE(
185 const char *name);
186
187 #undef END_IFELSE_VARIABLE
188 /****************************************************************************
189 PARAMETERS:
190 name - The name of the variable to end
191 returnval - The boolean value which is the value of the variable
192
193 REMARKS:
194 This macro is used to create variables for use by the #if, #else and #endif
195 blocks in the HTML preprocessor.
196 To create a new variable include the code necessary to get the value of the
197 variable between a block of BEGIN_IFELSE_VARIABLE and END_IFELSE_VARIABLE macros.
198
199 EXAMPLE:
200 BEGIN_IFELSE_VARIABLE(UserName)
201 // Get username from nucleus
202 bool tmp = GA_HasRegistered();
203 END_IFELSE_VARIABLE(UserName, tmp)
204
205 SEE ALSO:
206 wxIfElseVariable, wxIfElsePrep, BEGIN_IFELSE_VARIABLE, IFELSE_VARIABLE
207 ****************************************************************************/
208 void END_IFELSE_VARIABLE(
209 const char *name,
210 bool returnval);
211
212 #undef IFELSE_VARIABLE
213 /****************************************************************************
214 PARAMETERS:
215 name - The name of the variable
216 state - value of the variable
217
218 REMARKS:
219 This macro is used to create constant boolean variables for use by the
220 #if, #else and #endif blocks in the HTML preprocessor.
221 This MACRO creates a variable that simply returns the given state and is
222 not modifiable.
223
224 SEE ALSO:
225 wxIfElseVariable, wxIfElsePrep, BEGIN_IFELSE_VARIABLE, END_IFELSE_VARIABLE
226 ****************************************************************************/
227 void IFELSE_VARIABLE(
228 const char *name,
229 bool state);
230
231 FORCE_LINK_ME(ifelsevar)
232