summaryrefslogtreecommitdiff
path: root/plugins/!NotAdopted/WinterSpeak/speak/speak.cpp
blob: d15641d532ecf6143f6fdd1cebbee3481d937dfd (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
//==============================================================================
// 	Miranda Speak Plugin, © 2002 Ryan Winter
//==============================================================================

#pragma warning(disable:4786)

#include "speak.h"
#include "m_speak.h"

#include "resource.h"
#include "config/speak_config.h"
#include "announce/speak_announce.h"
#include "announce/dialog_announce.h"
#include "config/dialog_config_active.h"
#include "config/dialog_config_engine.h"

#include <general/debug/debug.h>
#include <general/debug/debug_window.h>
#include <general/debug/debug_file.h>
#include <general/optimise/aggressive_optimise.h>

//-----------------------------------------------------------------------------
PLUGINLINK    *pluginLink = 0;
HINSTANCE      g_hInst;

SpeakConfig   *g_speak_config = 0;
SpeakAnnounce *g_speak_announce = 0;
HANDLE         g_dialog_options_initialise;
HANDLE         g_event_status_change;
HANDLE         g_event_message_added;
HANDLE         g_protocol_ack;

PLUGININFO g_pluginInfo = 
{
	sizeof(PLUGININFO),
	"Speak",
	PLUGIN_MAKE_VERSION(0,9,7,0),
	"Miranda interface to the Microsoft Speech API",
	"Ryan Winter",
	"ryanwinter@hotmail.com",
	"© 2002 Ryan Winter",
	"",
	0,
	0
};

#ifdef _DEBUG
    DebugWindow g_debug_window;
//    DebugFile g_debug_file;
#endif


//-----------------------------------------------------------------------------
// Description : External hook
//-----------------------------------------------------------------------------
int say(WPARAM wParam, LPARAM lParam)
{
	return g_speak_config->say(
        reinterpret_cast<char *>(lParam), 
        reinterpret_cast<HANDLE>(wParam));
}

//-----------------------------------------------------------------------------
// Description : an status change event occured
//-----------------------------------------------------------------------------
int eventStatusChange(WPARAM wParam, LPARAM lParam)
{
	g_speak_announce->statusChange(
		reinterpret_cast<DBCONTACTWRITESETTING *>(lParam),
		reinterpret_cast<HANDLE>(wParam));

	return 0;
}

//-----------------------------------------------------------------------------
// Description : a message event occured
//-----------------------------------------------------------------------------
int eventMessageAdded(WPARAM wParam, LPARAM lParam)
{
	g_speak_announce->incomingEvent(
		reinterpret_cast<HANDLE>(wParam),
		reinterpret_cast<HANDLE>(lParam));

	return 0;
}

//-----------------------------------------------------------------------------
// Description : a messaging protocol changed state
//-----------------------------------------------------------------------------
int protocolAck(WPARAM wParam, LPARAM lParam)
{
    g_speak_announce->protocolAck(reinterpret_cast<ACKDATA *>(lParam));
    
    return 0;
}

//-----------------------------------------------------------------------------
// Description : request for dialog box
//-----------------------------------------------------------------------------
int dialogOptionsInitialise(WPARAM wParam,LPARAM lParam)
{
	OPTIONSDIALOGPAGE odp;

	ZeroMemory(&odp, sizeof(odp));

    odp.cbSize = sizeof(odp);
    odp.position = 100000000;
    odp.hInstance = g_hInst;
    odp.pszGroup = Translate("Speak");

    if (g_speak_config)
    {
	    odp.pszTemplate = MAKEINTRESOURCE(IDD_CONFIG);
	    odp.pszTitle = Translate("Engine/Voice");
	    odp.pfnDlgProc = DialogConfigEngine::process;
	    CallService(MS_OPT_ADDPAGE, wParam, (LPARAM)&odp);

	    odp.pszTemplate = MAKEINTRESOURCE(IDD_ACTIVEMODES);
	    odp.pszTitle = Translate("Active Modes");
	    odp.pfnDlgProc = DialogConfigActive::process;
	    CallService(MS_OPT_ADDPAGE, wParam, (LPARAM)&odp);
    }

    if (g_speak_announce)
    {
	    odp.pszTemplate = MAKEINTRESOURCE(IDD_ANNOUNCE);
	    odp.pszTitle = Translate("Announce");
	    odp.pfnDlgProc = AnnounceDialog::process;
	    CallService(MS_OPT_ADDPAGE, wParam, (LPARAM)&odp);
    }

	return 0;
}

//-----------------------------------------------------------------------------
// Description : Return info about the plugin
//-----------------------------------------------------------------------------
extern "C" __declspec(dllexport) PLUGININFO * 
MirandaPluginInfo(DWORD mirandaVersion)
{
	return &g_pluginInfo;
}

//-----------------------------------------------------------------------------
// Description : Construct the plugin
//-----------------------------------------------------------------------------
extern "C" int __declspec(dllexport) 
Load(PLUGINLINK *link)
{
  	pluginLink = link;

	if (!g_speak_config)
	{
		g_speak_config = new SpeakConfig(g_hInst);

		// expose to allow miranda + plugins to access my speak routines
		CreateServiceFunction("Speak/Say", say);
	}

    if (!g_speak_announce)
    {
        g_speak_announce = new SpeakAnnounce(g_hInst);

		// tap into contact setting change event
		g_event_status_change 
			= HookEvent(ME_DB_CONTACT_SETTINGCHANGED, eventStatusChange);

		// a new message event has occured
		g_event_message_added = HookEvent(ME_DB_EVENT_ADDED, eventMessageAdded);

        // a messaging protocol changed state
    	g_protocol_ack = HookEvent(ME_PROTO_ACK, protocolAck);

    }

	// a option dialog box request has occured
	g_dialog_options_initialise 
		= HookEvent(ME_OPT_INITIALISE, dialogOptionsInitialise);

	return 0; 
}

//-----------------------------------------------------------------------------
// Description : Destruct the plugin
//-----------------------------------------------------------------------------
extern "C" int __declspec(dllexport) 
Unload(void)
{
	UnhookEvent(g_dialog_options_initialise);

	if (g_speak_config)
	{
		delete g_speak_config;
        g_speak_config = 0;
	}

    if (g_speak_announce)
    {
		UnhookEvent(g_event_status_change);
		UnhookEvent(g_event_message_added);
        UnhookEvent(g_protocol_ack);

        delete g_speak_announce;
        g_speak_announce = 0;
    }

	return 0;
}

//-----------------------------------------------------------------------------
// Description : Main line
//-----------------------------------------------------------------------------
BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD dwReason, LPVOID)
{
    CERR("================================================================");

	DisableThreadLibraryCalls(hinstDLL);
	g_hInst = hinstDLL;

    // dispatch application messages    
/*    MSG msg;

    while(::GetMessage(&msg, NULL, 0, 0))
    {
        ::TranslateMessage(&msg);
        ::DispatchMessage(&msg);
    }*/

	return TRUE;
}

//==============================================================================
//
//  Summary     : DLL interface
//
//  Description : Define the interface to the miranda program
//
//==============================================================================