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 wxEchoVariable Class, Dynamically constructed
26 * objects representing variables in SSI #echo directive
28 ****************************************************************************/
30 // For compilers that support precompilation
32 #include "wx/applet/echovar.h"
33 #include "wx/msgdlg.h"
34 #include "wx/html/forcelnk.h"
36 // Include private headers
38 /*---------------------------- Global variables ---------------------------*/
40 static wxEchoVariable
*wxEchoVariable::sm_first
= NULL
;
41 static wxHashTable
*wxEchoVariable::sm_varTable
= NULL
;
43 /*----------------------------- Implementation ----------------------------*/
45 /****************************************************************************
47 varName - The String name of the class
48 getValueFn - Pointer to the function that returns the echo variable value
51 Constructor for the wxEchoVariable class that self registers itself with
52 the list of all echo variables when the static class instance is created
53 at program init time (remember all the constructors get called before
54 the main program function!).
55 ****************************************************************************/
56 wxEchoVariable::wxEchoVariable(
58 wxEchoVariableGetValueFn getValueFn
)
61 m_getValueFn
= getValueFn
;
66 /****************************************************************************
68 Initializes parent pointers and hash table for fast searching for echo
70 ****************************************************************************/
71 void wxEchoVariable::Initialize()
73 wxEchoVariable::sm_varTable
= new wxHashTable(wxKEY_STRING
);
75 // Index all class infos by their class name
76 wxEchoVariable
*info
= sm_first
;
79 sm_varTable
->Put(info
->m_varName
, info
);
84 /****************************************************************************
86 Clean up echo variable hash tables on application exit.
87 ****************************************************************************/
88 void wxEchoVariable::CleanUp()
90 delete wxEchoVariable::sm_varTable
;
91 wxEchoVariable::sm_varTable
= NULL
;
94 /****************************************************************************
96 varName - The String name of the class
97 parms - Parameter string for the echo variable
100 Constructor for the wxEchoVariable class that self registers itself with
101 the list of all echo variables when the static class instance is created
102 at program init time (remember all the constructors get called before
103 the main program function!).
104 ****************************************************************************/
105 wxString
wxEchoVariable::GetValue(
106 const wxChar
*varName
,
109 wxEchoVariable
*info
= wxEchoVariable::FindVariable(varName
);
111 return info
->m_getValueFn(parms
);
113 wxMessageBox(wxString("wxHTML #echo error: Class is not a valid echo variable (") + varName
+ wxString(")."),"Error",wxICON_ERROR
);
118 /****************************************************************************
120 varName - The String name of the class
123 True if the echo variable exists, false if not.
124 ****************************************************************************/
125 bool wxEchoVariable::Exists(
126 const wxChar
*varName
)
128 return wxEchoVariable::FindVariable(varName
) != NULL
;
131 /*------------------------ Macro Documentation ---------------------------*/
133 // Here we declare some fake functions to get doc-jet to properly document the macros
136 /****************************************************************************
138 The value of the parameter string from the HTML parm= field
141 This is a macro to retrieve the parameter string passed in the parm= field.
142 Use this macro to get the correct variable within a BEGIN_ECHO_VARIABLE and
143 END_ECHO_VARIABLE block.
146 wxEchoVariable, wxEchoPrep, BEGIN_ECHO_VARIABLE, END_ECHO_VARIABLE
147 ****************************************************************************/
148 wxString
ECHO_PARM();
151 #undef BEGIN_ECHO_VARIABLE
152 /****************************************************************************
154 name - The name of the variable to create
157 This macro is used to create variables for use by the #echo directive
158 the HTML preprocessor.
159 To create a new variable include the code necessary to get the value of the
160 variable between a block of BEGIN_ECHO_VARIABLE and END_ECHO_VARIABLE macros.
161 Use the ECHO_PARM macro to grab the optional parameter string passed from the
162 'parm=' field in the html file.
165 BEGIN_ECHO_VARIABLE(UserName)
166 // Get username from nucleus
167 wxString tmp = GA_GetUserName();
168 END_ECHO_VARIABLE(UserName, tmp)
171 wxEchoVariable, wxEchoPrep, END_ECHO_VARIABLE, ECHO_PARM, STRING_ECHO_VARIABLE
172 ****************************************************************************/
173 void BEGIN_ECHO_VARIABLE(
176 #undef END_ECHO_VARIABLE
177 /****************************************************************************
179 name - The name of the variable to end
180 returnval - The value which should be sent back as the value of the variable
183 This macro is used to create variables for use by the #echo directive
184 the HTML preprocessor.
185 To create a new variable include the code necessary to get the value of the
186 variable between a block of BEGIN_ECHO_VARIABLE and END_ECHO_VARIABLE macros.
189 BEGIN_ECHO_VARIABLE(UserName)
190 // Get username from nucleus
191 wxString tmp = GA_GetUserName();
192 END_ECHO_VARIABLE(UserName, tmp)
195 wxEchoVariable, wxEchoPrep, BEGIN_ECHO_VARIABLE, ECHO_PARM, STRING_ECHO_VARIABLE
196 ****************************************************************************/
197 void END_ECHO_VARIABLE(
201 #undef STRING_ECHO_VARIABLE
202 /****************************************************************************
204 name - The name of the variable
205 returnval - String to return as the value of the variable
208 This macro is used to create constant string variables for use by the #echo
209 directive in the HTML preprocessor.
210 This MACRO creates a variable that simply returns the given string and is
214 wxEchoVariable, wxEchoPrep, BEGIN_ECHO_VARIABLE, END_ECHO_VARIABLE
215 ****************************************************************************/
216 void STRING_ECHO_VARIABLE(
220 // hack to make this file link
221 FORCE_LINK_ME(echovar
)