summaryrefslogtreecommitdiff
path: root/include/delphi/reserve/m_speak.inc
blob: d8a9a4bfbe56cf966286e3c924af3396b534e706 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
{
Copyright (C) 2007 Ricardo Pescuma Domenecci

This is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.

This is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Library General Public License for more details.

You should have received a copy of the GNU Library General Public
License along with this file; see the file license.txt.  If
not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA.
}

{$IFNDEF M_SPEAK}
{$DEFINE M_SPEAK}

(*
There is 2 ways of using the speak plugin:

1. Older and simple way: just call
	Speak_Say(hContact, _T("text to speak"))
and the text will be spoken using contact settings. If hContact is NULL, it will use
system settings.
Previous versions only had an ascii version, so if you want to support then you need
to call
	Speak_SayA(hContact, "text to speak")


2. Integrating with meSpeak GUI: for that you have first to register a speak type and
then call the speak functions. In both case you have 2 options:

2.1 Sending the full text: meSpeak GUI will only allow to enable/disable the type.
To register call (in modules loaded):
	Speak_Register("PluginName (DB key)", "name", "Prety name for GUI", "icon_xyz")
And to speak call:
	Speak_SayEx("name", hContact, _T("text to speak"))

2.2 Using templates: you will not pass the text, but some variables. meSpeak handles
the GUI to allow the user to create the text for those variables. These functions
end with WT (with templates).
To register call (in modules loaded):
	AnsiChar *templates[] = { "Name\nDefault\n%var1%\tDescription 1\n%var2%\tDescription2\n%var3%\tDescription 3" };
	Speak_RegisterWT("PluginName (DB key)", "name", "Prety name for GUI", "icon_xyz",
					 templates, 1);
And to speak call:
	TCHAR *variables[] = { _T("var1"), _T("Value 1"), _T("var2"), _T("Value 2"), _T("var3"), _T("Value 3") };
	Speak_SayExWT("name", hContact, 0, variables, 3);
*)

const
  MIID_SPEAK = '{1EF72725-6A83-483B-AA50-8953E359EEAD}';

  {*
  Speak a text

  wParam: (HANDLE) hContact
  lParam: (AnsiChar *) text
  return: 0 on success
  *}
  MS_SPEAK_SAY_A = 'Speak/Say';

  {*
  Speak a unicode text

  wParam: (HANDLE) hContact
  lParam: (WCHAR *) text
  return: 0 on success
  *}
  MS_SPEAK_SAY_W = 'Speak/SayW';

type
  PSPEAK_TYPE = ^TSPEAK_TYPE;
  TSPEAK_TYPE = record
    cbSize: integer;
	  module: PAnsiChar;
	  name: PAnsiChar;					// Internal type name
	  description: PAnsiChar;		// Will be translated
	  icon: PAnsiChar;					// Name off icolib icon
  	// Aditional data if wants to use add to history services
	  templates: ^PAnsiChar;    // Each entry is: "Name\nDefault\n%var%\tDescription\n%var%\tDescription\n%var%\tDescription"
	  numTemplates: integer;
  end;

const
  {*
  Register and speak type

  wParam: (SPEAK_TYPE *) type
  lParam: 0
  return: 0 on success
  *}
  MS_SPEAK_REGISTER = 'Speak/Register';

const
  SPEAK_CHAR  = 1;
  SPEAK_WCHAR = 2;

type
  PSPEAK_ITEM = ^TSPEAK_ITEM;
  TSPEAK_ITEM = record
    cbSize: integer;
    _type: PAnsiChar;		      // Internal type name
  	hContact: THandle;
	  flags: integer;       // SPEAK_*
	  templateNum: integer;	// -1 to use text
    case boolean of
      true:  (text: PAnsiChar);
      false: (
        variables: Pointer;
        numVariables: integer;
      );
  end;

const
  {*
  Speak a text

  wParam: (SPEAK_ITEM *) Item
  lParam: 0
  return: 0 on success
  *}
  MS_SPEAK_SAYEX = 'Speak/SayEx';


{$IFDEF I_AM_A_CONSTANT_THAT_IS_NEVER_DEFINED_BUT_ALLOWS_THE_CODE_BELOW_NOT_TO_BE_COMMENTED}
// Helper functions

static int Speak_SayA(HANDLE hContact, const AnsiChar *text)
{
	return CallService(MS_SPEAK_SAY_A, (WPARAM) hContact, (LPARAM) text);
}

static int Speak_SayW(HANDLE hContact, const WCHAR *text)
{
	return CallService(MS_SPEAK_SAY_W, (WPARAM) hContact, (LPARAM) text);
}

static int Speak_Register(AnsiChar *module, AnsiChar *name, AnsiChar *description, AnsiChar *icon)
{
	SPEAK_TYPE type;

	if (!ServiceExists(MS_SPEAK_REGISTER))
		return -1;

	type.cbSize = sizeof(type);
	type.module = module;
	type.name = name;
	type.description = description;
	type.icon = icon;
	type.templates = NULL;
	type.numTemplates = 0;

	return CallService(MS_SPEAK_REGISTER, (WPARAM) &type, 0);
}

static int Speak_RegisterWT(const AnsiChar *module, const AnsiChar *name, const AnsiChar *description,
							const AnsiChar *icon, AnsiChar **templates, int numTemplates)
{
	SPEAK_TYPE type;

	if (!ServiceExists(MS_SPEAK_REGISTER))
		return -1;

	type.cbSize = sizeof(type);
	type.module = module;
	type.name = name;
	type.description = description;
	type.icon = icon;
	type.templates = templates;
	type.numTemplates = numTemplates;

	return CallService(MS_SPEAK_REGISTER, (WPARAM) &type, 0);
}

static int Speak_SayExA(AnsiChar *type, HANDLE hContact, const AnsiChar *text)
{
	SPEAK_ITEM item;

	if (!ServiceExists(MS_SPEAK_SAYEX))
		// Try old service
		return Speak_SayA(hContact, text);

	item.cbSize = sizeof(item);
	item.flags = SPEAK_CHAR;
	item.type = type;
	item.hContact = hContact;
	item.templateNum = -1;
	item.text = text;

	return CallService(MS_SPEAK_SAYEX, (WPARAM) &item, 0);
}

static int Speak_SayExW(AnsiChar *type, HANDLE hContact, const WCHAR *text)
{
	SPEAK_ITEM item;

	if (!ServiceExists(MS_SPEAK_SAYEX))
		// Try old service
		return Speak_SayW(hContact, text);

	item.cbSize = sizeof(item);
	item.flags = SPEAK_WCHAR;
	item.type = type;
	item.hContact = hContact;
	item.templateNum = -1;
	item.text = text;

	return CallService(MS_SPEAK_SAYEX, (WPARAM) &item, 0);
}

static int Speak_SayExWTA(AnsiChar *type, HANDLE hContact, int templateNum, AnsiChar **variables, int numVariables)
{
	SPEAK_ITEM item;

	if (!ServiceExists(MS_SPEAK_SAYEX))
		return -1;

	item.cbSize = sizeof(item);
	item.flags = SPEAK_CHAR;
	item.type = type;
	item.hContact = hContact;
	item.templateNum = templateNum;
	item.variables = variables;
	item.numVariables = numVariables;

	return CallService(MS_SPEAK_SAYEX, (WPARAM) &item, 0);
}

static int Speak_SayExWTW(AnsiChar *type, HANDLE hContact, int templateNum, WCHAR **variables, int numVariables)
{
	SPEAK_ITEM item;

	if (!ServiceExists(MS_SPEAK_SAYEX))
		return -1;

	item.cbSize = sizeof(item);
	item.flags = SPEAK_WCHAR;
	item.type = type;
	item.hContact = hContact;
	item.templateNum = templateNum;
	item.variables = variables;
	item.numVariables = numVariables;

	return CallService(MS_SPEAK_SAYEX, (WPARAM) &item, 0);
}


#ifdef UNICODE
#  define MS_SPEAK_SAY MS_SPEAK_SAY_W
#  define Speak_Say Speak_SayW
#  define Speak_SayEx Speak_SayExW
#  define Speak_SayExWT Speak_SayExWTW
#else
#  define MS_SPEAK_SAY MS_SPEAK_SAY_A
#  define Speak_Say Speak_SayA
#  define Speak_SayEx Speak_SayExA
#  define Speak_SayExWT Speak_SayExWTA
#endif

{$ENDIF}
{$ENDIF}