| 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 |
| 31 | |
| 32 | #include "wx/applet/echovar.h" |
| 33 | #include "wx/msgdlg.h" |
| 34 | #include "wx/html/forcelnk.h" |
| 35 | |
| 36 | // Include private headers |
| 37 | |
| 38 | /*---------------------------- Global variables ---------------------------*/ |
| 39 | |
| 40 | static wxEchoVariable *wxEchoVariable::sm_first = NULL; |
| 41 | static wxHashTable *wxEchoVariable::sm_varTable = NULL; |
| 42 | |
| 43 | /*----------------------------- Implementation ----------------------------*/ |
| 44 | |
| 45 | /**************************************************************************** |
| 46 | PARAMETERS: |
| 47 | varName - The String name of the class |
| 48 | getValueFn - Pointer to the function that returns the echo variable value |
| 49 | |
| 50 | REMARKS: |
| 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( |
| 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 | } |
| 65 | |
| 66 | /**************************************************************************** |
| 67 | REMARKS: |
| 68 | Initializes parent pointers and hash table for fast searching for echo |
| 69 | variables. |
| 70 | ****************************************************************************/ |
| 71 | void 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 | } |
| 83 | |
| 84 | /**************************************************************************** |
| 85 | REMARKS: |
| 86 | Clean up echo variable hash tables on application exit. |
| 87 | ****************************************************************************/ |
| 88 | void wxEchoVariable::CleanUp() |
| 89 | { |
| 90 | delete wxEchoVariable::sm_varTable; |
| 91 | wxEchoVariable::sm_varTable = NULL; |
| 92 | } |
| 93 | |
| 94 | /**************************************************************************** |
| 95 | PARAMETERS: |
| 96 | varName - The String name of the class |
| 97 | parms - Parameter string for the echo variable |
| 98 | |
| 99 | REMARKS: |
| 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, |
| 107 | const wxChar *parms) |
| 108 | { |
| 109 | wxEchoVariable *info = wxEchoVariable::FindVariable(varName); |
| 110 | if (info) |
| 111 | return info->m_getValueFn(parms); |
| 112 | #ifdef CHECKED |
| 113 | wxMessageBox(wxString("wxHTML #echo error: Class is not a valid echo variable (") + varName + wxString(")."),"Error",wxICON_ERROR); |
| 114 | #endif |
| 115 | return wxString(""); |
| 116 | } |
| 117 | |
| 118 | /**************************************************************************** |
| 119 | PARAMETERS: |
| 120 | varName - The String name of the class |
| 121 | |
| 122 | RETURNS: |
| 123 | True if the echo variable exists, false if not. |
| 124 | ****************************************************************************/ |
| 125 | bool wxEchoVariable::Exists( |
| 126 | const wxChar *varName) |
| 127 | { |
| 128 | return wxEchoVariable::FindVariable(varName) != NULL; |
| 129 | } |
| 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 | /**************************************************************************** |
| 137 | RETURNS: |
| 138 | The value of the parameter string from the HTML parm= field |
| 139 | |
| 140 | REMARKS: |
| 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. |
| 144 | |
| 145 | SEE ALSO: |
| 146 | wxEchoVariable, wxEchoPrep, BEGIN_ECHO_VARIABLE, END_ECHO_VARIABLE |
| 147 | ****************************************************************************/ |
| 148 | wxString ECHO_PARM(); |
| 149 | |
| 150 | |
| 151 | #undef BEGIN_ECHO_VARIABLE |
| 152 | /**************************************************************************** |
| 153 | PARAMETERS: |
| 154 | name - The name of the variable to create |
| 155 | |
| 156 | REMARKS: |
| 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. |
| 163 | |
| 164 | EXAMPLE: |
| 165 | BEGIN_ECHO_VARIABLE(UserName) |
| 166 | // Get username from nucleus |
| 167 | wxString tmp = GA_GetUserName(); |
| 168 | END_ECHO_VARIABLE(UserName, tmp) |
| 169 | |
| 170 | SEE ALSO: |
| 171 | wxEchoVariable, wxEchoPrep, END_ECHO_VARIABLE, ECHO_PARM, STRING_ECHO_VARIABLE |
| 172 | ****************************************************************************/ |
| 173 | void BEGIN_ECHO_VARIABLE( |
| 174 | const char *name); |
| 175 | |
| 176 | #undef END_ECHO_VARIABLE |
| 177 | /**************************************************************************** |
| 178 | PARAMETERS: |
| 179 | name - The name of the variable to end |
| 180 | returnval - The value which should be sent back as the value of the variable |
| 181 | |
| 182 | REMARKS: |
| 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. |
| 187 | |
| 188 | EXAMPLE: |
| 189 | BEGIN_ECHO_VARIABLE(UserName) |
| 190 | // Get username from nucleus |
| 191 | wxString tmp = GA_GetUserName(); |
| 192 | END_ECHO_VARIABLE(UserName, tmp) |
| 193 | |
| 194 | SEE ALSO: |
| 195 | wxEchoVariable, wxEchoPrep, BEGIN_ECHO_VARIABLE, ECHO_PARM, STRING_ECHO_VARIABLE |
| 196 | ****************************************************************************/ |
| 197 | void END_ECHO_VARIABLE( |
| 198 | const char *name, |
| 199 | wxString returnval); |
| 200 | |
| 201 | #undef STRING_ECHO_VARIABLE |
| 202 | /**************************************************************************** |
| 203 | PARAMETERS: |
| 204 | name - The name of the variable |
| 205 | returnval - String to return as the value of the variable |
| 206 | |
| 207 | REMARKS: |
| 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 |
| 211 | not modifiable. |
| 212 | |
| 213 | SEE ALSO: |
| 214 | wxEchoVariable, wxEchoPrep, BEGIN_ECHO_VARIABLE, END_ECHO_VARIABLE |
| 215 | ****************************************************************************/ |
| 216 | void STRING_ECHO_VARIABLE( |
| 217 | const char *name, |
| 218 | wxString string); |
| 219 | |
| 220 | // hack to make this file link |
| 221 | FORCE_LINK_ME(echovar) |
| 222 | |