]> git.saurik.com Git - wxWidgets.git/blame - contrib/src/applet/echovar.cpp
bug fixes for using wxTransientPopupWindow and wxDP_ALLOWNONE support from Andreas...
[wxWidgets.git] / contrib / src / applet / echovar.cpp
CommitLineData
716cd410
KB
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 wxEchoVariable Class, Dynamically constructed
26* objects representing variables in SSI #echo directive
27*
28****************************************************************************/
29
30// For compilers that support precompilation
574c939e
KB
31
32#include "wx/applet/echovar.h"
33#include "wx/msgdlg.h"
716cd410
KB
34#include "wx/html/forcelnk.h"
35
36// Include private headers
716cd410
KB
37
38/*---------------------------- Global variables ---------------------------*/
39
574c939e
KB
40static wxEchoVariable *wxEchoVariable::sm_first = NULL;
41static wxHashTable *wxEchoVariable::sm_varTable = NULL;
716cd410
KB
42
43/*----------------------------- Implementation ----------------------------*/
44
45/****************************************************************************
46PARAMETERS:
574c939e
KB
47varName - The String name of the class
48getValueFn - Pointer to the function that returns the echo variable value
716cd410 49
574c939e
KB
50REMARKS:
51Constructor for the wxEchoVariable class that self registers itself with
52the list of all echo variables when the static class instance is created
53at program init time (remember all the constructors get called before
54the main program function!).
55****************************************************************************/
56wxEchoVariable::wxEchoVariable(
57 const char *varName,
58 wxEchoVariableGetValueFn getValueFn)
59{
60 m_varName = varName;
61 m_getValueFn = getValueFn;
62 m_next = sm_first;
63 sm_first = this;
64}
716cd410 65
574c939e 66/****************************************************************************
716cd410 67REMARKS:
574c939e
KB
68Initializes parent pointers and hash table for fast searching for echo
69variables.
70****************************************************************************/
71void wxEchoVariable::Initialize()
72{
73 wxEchoVariable::sm_varTable = new wxHashTable(wxKEY_STRING);
74
75 // Index all class infos by their class name
76 wxEchoVariable *info = sm_first;
77 while (info) {
78 if (info->m_varName)
79 sm_varTable->Put(info->m_varName, info);
80 info = info->m_next;
81 }
82}
716cd410 83
574c939e
KB
84/****************************************************************************
85REMARKS:
86Clean up echo variable hash tables on application exit.
716cd410 87****************************************************************************/
574c939e 88void wxEchoVariable::CleanUp()
716cd410 89{
574c939e
KB
90 delete wxEchoVariable::sm_varTable;
91 wxEchoVariable::sm_varTable = NULL;
92}
716cd410 93
574c939e
KB
94/****************************************************************************
95PARAMETERS:
96varName - The String name of the class
97parms - Parameter string for the echo variable
716cd410 98
574c939e
KB
99REMARKS:
100Constructor for the wxEchoVariable class that self registers itself with
101the list of all echo variables when the static class instance is created
102at program init time (remember all the constructors get called before
103the main program function!).
104****************************************************************************/
105wxString wxEchoVariable::GetValue(
106 const wxChar *varName,
107 const wxChar *parms)
108{
109 wxEchoVariable *info = wxEchoVariable::FindVariable(varName);
110 if (info)
111 return info->m_getValueFn(parms);
716cd410 112#ifdef CHECKED
574c939e 113 wxMessageBox(wxString("wxHTML #echo error: Class is not a valid echo variable (") + varName + wxString(")."),"Error",wxICON_ERROR);
716cd410 114#endif
574c939e 115 return wxString("");
716cd410
KB
116}
117
574c939e
KB
118/****************************************************************************
119PARAMETERS:
120varName - The String name of the class
121
122RETURNS:
123True if the echo variable exists, false if not.
124****************************************************************************/
125bool wxEchoVariable::Exists(
126 const wxChar *varName)
127{
128 return wxEchoVariable::FindVariable(varName) != NULL;
129}
716cd410
KB
130
131/*------------------------ Macro Documentation ---------------------------*/
132
133// Here we declare some fake functions to get doc-jet to properly document the macros
134
135#undef ECHO_PARM
136/****************************************************************************
137RETURNS:
138The value of the parameter string from the HTML parm= field
139
140REMARKS:
141This is a macro to retrieve the parameter string passed in the parm= field.
142Use this macro to get the correct variable within a BEGIN_ECHO_VARIABLE and
143END_ECHO_VARIABLE block.
144
145SEE ALSO:
146wxEchoVariable, wxEchoPrep, BEGIN_ECHO_VARIABLE, END_ECHO_VARIABLE
147****************************************************************************/
148wxString ECHO_PARM();
149
150
151#undef BEGIN_ECHO_VARIABLE
152/****************************************************************************
153PARAMETERS:
154name - The name of the variable to create
155
156REMARKS:
157This macro is used to create variables for use by the #echo directive
158the HTML preprocessor.
159To create a new variable include the code necessary to get the value of the
160variable between a block of BEGIN_ECHO_VARIABLE and END_ECHO_VARIABLE macros.
161Use the ECHO_PARM macro to grab the optional parameter string passed from the
162'parm=' field in the html file.
163
164EXAMPLE:
165BEGIN_ECHO_VARIABLE(UserName)
166 // Get username from nucleus
167 wxString tmp = GA_GetUserName();
168END_ECHO_VARIABLE(UserName, tmp)
169
170SEE ALSO:
171wxEchoVariable, wxEchoPrep, END_ECHO_VARIABLE, ECHO_PARM, STRING_ECHO_VARIABLE
172****************************************************************************/
173void BEGIN_ECHO_VARIABLE(
174 const char *name);
175
176#undef END_ECHO_VARIABLE
177/****************************************************************************
178PARAMETERS:
179name - The name of the variable to end
180returnval - The value which should be sent back as the value of the variable
181
182REMARKS:
183This macro is used to create variables for use by the #echo directive
184the HTML preprocessor.
185To create a new variable include the code necessary to get the value of the
186variable between a block of BEGIN_ECHO_VARIABLE and END_ECHO_VARIABLE macros.
187
188EXAMPLE:
189BEGIN_ECHO_VARIABLE(UserName)
190 // Get username from nucleus
191 wxString tmp = GA_GetUserName();
192END_ECHO_VARIABLE(UserName, tmp)
193
194SEE ALSO:
195wxEchoVariable, wxEchoPrep, BEGIN_ECHO_VARIABLE, ECHO_PARM, STRING_ECHO_VARIABLE
196****************************************************************************/
197void END_ECHO_VARIABLE(
198 const char *name,
199 wxString returnval);
200
201#undef STRING_ECHO_VARIABLE
202/****************************************************************************
203PARAMETERS:
204name - The name of the variable
205returnval - String to return as the value of the variable
206
207REMARKS:
208This macro is used to create constant string variables for use by the #echo
209directive in the HTML preprocessor.
210This MACRO creates a variable that simply returns the given string and is
211not modifiable.
212
213SEE ALSO:
214wxEchoVariable, wxEchoPrep, BEGIN_ECHO_VARIABLE, END_ECHO_VARIABLE
215****************************************************************************/
216void STRING_ECHO_VARIABLE(
217 const char *name,
218 wxString string);
219
220// hack to make this file link
574c939e
KB
221FORCE_LINK_ME(echovar)
222