1
/****************************************************************************
3
* wxWindows HTML Applet Package
5
* Copyright (C) 1991-2001 SciTech Software, Inc.
8
* ========================================================================
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
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.
20
* ========================================================================
25
* Description: Implementation of wxIfElseVariable Class, Dynamically constructed
26
* objects representing variables in SSI #if, #else, and #endif directives
28
****************************************************************************/
30
// Include private headers
31
#include "wx/applet/ifelsevar.h"
33
// wxWindows forcelink macro
34
#include "wx/html/forcelnk.h"
35
#include "wx/msgdlg.h"
37
/*---------------------------- Global variables ---------------------------*/
39
static wxIfElseVariable *wxIfElseVariable::sm_first = NULL;
40
static wxHashTable *wxIfElseVariable::sm_varTable = NULL;
42
/*----------------------------- Implementation ----------------------------*/
44
/****************************************************************************
46
varName - The String name of the class
47
getValueFn - Pointer to the function that returns the echo variable value
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(
57
wxIfElseVariableGetValueFn getValueFn)
60
m_getValueFn = getValueFn;
65
/****************************************************************************
67
Initializes parent pointers and hash table for fast searching for echo
69
****************************************************************************/
70
void wxIfElseVariable::Initialize()
72
wxIfElseVariable::sm_varTable = new wxHashTable(wxKEY_STRING);
74
// Index all class infos by their class name
75
wxIfElseVariable *info = sm_first;
78
sm_varTable->Put(info->m_varName, info);
83
/****************************************************************************
85
Clean up echo variable hash tables on application exit.
86
****************************************************************************/
87
void wxIfElseVariable::CleanUp()
89
delete wxIfElseVariable::sm_varTable;
90
wxIfElseVariable::sm_varTable = NULL;
93
/****************************************************************************
95
varName - The String name of the class
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)
106
wxIfElseVariable *info = wxIfElseVariable::FindVariable(varName);
108
// Return the forced value if the variable has been forced.
110
return info->forceVal;
111
return info->m_getValueFn();
114
wxMessageBox(wxString("wxHTML #if error: Class is not a valid if else variable (") + varName + wxString(")."),"Error",wxICON_ERROR);
119
/****************************************************************************
121
varName - The String name of the class
124
True if the if/else variable exists, false if not.
125
****************************************************************************/
126
bool wxIfElseVariable::Exists(
127
const wxChar *varName)
129
return wxIfElseVariable::FindVariable(varName) != NULL;
132
/****************************************************************************
134
varName - The String name of the class
135
val - Value to force the if/else variable with
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.
142
NOTE: This is only available when compiled in CHECKED mode.
143
****************************************************************************/
144
void wxIfElseVariable::Force(
145
const wxChar *varName,
148
wxIfElseVariable *info = wxIfElseVariable::FindVariable(varName);
151
info->forceVal = val;
155
wxMessageBox(wxString("wxHTML #if error: Class is not a valid if else variable (") + varName + wxString(")."),"Error",wxICON_ERROR);
160
/*------------------------ Macro Documentation ---------------------------*/
162
// Here we declare some fake functions to get doc-jet to properly document the macros
164
#undef BEGIN_IFELSE_VARIABLE
165
/****************************************************************************
167
name - The name of the variable to create
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.
176
BEGIN_IFELSE_VARIABLE(UserName)
177
// Get username from nucleus
178
bool tmp = GA_HasRegistered();
179
END_IFELSE_VARIABLE(UserName, tmp)
182
wxIfElseVariable, wxIfElsePrep, END_IFELSE_VARIABLE, IFELSE_VARIABLE
183
****************************************************************************/
184
void BEGIN_IFELSE_VARIABLE(
187
#undef END_IFELSE_VARIABLE
188
/****************************************************************************
190
name - The name of the variable to end
191
returnval - The boolean value which is the value of the variable
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.
200
BEGIN_IFELSE_VARIABLE(UserName)
201
// Get username from nucleus
202
bool tmp = GA_HasRegistered();
203
END_IFELSE_VARIABLE(UserName, tmp)
206
wxIfElseVariable, wxIfElsePrep, BEGIN_IFELSE_VARIABLE, IFELSE_VARIABLE
207
****************************************************************************/
208
void END_IFELSE_VARIABLE(
212
#undef IFELSE_VARIABLE
213
/****************************************************************************
215
name - The name of the variable
216
state - value of the variable
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
225
wxIfElseVariable, wxIfElsePrep, BEGIN_IFELSE_VARIABLE, END_IFELSE_VARIABLE
226
****************************************************************************/
227
void IFELSE_VARIABLE(
231
FORCE_LINK_ME(ifelsevar)