summaryrefslogtreecommitdiff
path: root/plugins/ShlExt/inc/m_helpers.inc
blob: ef8edeb088284444307062a08060d38d88efa6fd (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
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
(*

Miranda IM: the free IM client for Microsoft* Windows*

Copyright 2000-2004 Miranda ICQ/IM project,
all portions of this codebase are copyrighted to the people
listed in contributors.txt.

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

This program 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 General Public License for more details.

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

*)

{$ifdef M_API_UNIT}

    function PLUGIN_MAKE_VERSION(a,b,c,d: Cardinal): int;
    function PLUGIN_CMP_VERSION(verA: LongInt; verB: LongInt): int;

{$else}

    function PLUGIN_MAKE_VERSION(a,b,c,d: Cardinal): int;
    {$ifdef FPC}
    inline;
    {$endif}
    begin
        Result := (a shl 24) or (b shl 16) or (c shl 8) or d;
    end;

    function PLUGIN_CMP_VERSION(verA: LongInt; verB: LongInt): int;
    {$ifdef FPC}
    inline;
    {$endif}
    begin
        Result := 0;
        { could be used to compare for severity of age for positive values, if a<b
        results are minus values, 0 for equal, positive if a is newer }
        Inc(Result, (verA and $FF) - (verB and $FF));
        Inc(Result, (verA and $FF00) - (verB and $FF00));
        Inc(Result, (verA and $FF0000) - (verB and $FF0000));
        Inc(Result, (verA and $FF000000) - (verB and $FF000000));
    end;

{$endif}

{$ifdef M_SYSTEM}
    {$ifdef M_API_UNIT}

    function CallService(const szService: PChar; wParam: WPARAM; lParam: LPARAM): int;

    function HookEvent(const szHook: PChar; hook_proc: TMIRANDAHOOK): int;

    function CreateServiceFunction(const szName: PChar; const MirandaService: TMIRANDASERVICE): int;

    {$else}

    function CallService(const szService: PChar; wParam: WPARAM; lParam: lParam): int;
    {$ifdef FPC}
    inline;
    {$endif}
    begin
        Result := PluginLink^.CallService(szService, wParam, lParam);
    end;

    function HookEvent(const szHook: PChar; hook_proc: TMIRANDAHOOK): int;
    {$ifdef FPC}
    inline;
    {$endif}
    begin
        Result := PluginLink^.HookEvent(szHook, @hook_proc);
    end;

    function CreateServiceFunction(const szName: PChar; const MirandaService: TMIRANDASERVICE): int;
    {$ifdef FPC}
    inline;
    {$endif}
    begin
        Result := PluginLink^.CreateServiceFunction(szName, @MirandaService);
    end;

    {$endif}

{$endif}

{$ifdef M_DATABASE}

    {$ifdef M_API_UNIT}

    function DBGetContactSettingByte(hContact: THandle;
        const szModule: PChar; const szSetting: PChar; errorValue: Integer): Integer;

    function DBGetContactSettingWord(hContact: THandle;
        const szModule: PChar; const szSetting: PChar; errorValue: Integer): Integer;

    function DBGetContactSettingDword(hContact: THandle;
        const szModule: PChar; const szSetting: PChar; errorValue: Integer): Integer;

    function DBGetContactSetting(hContact: THandle;
        const szModule: PChar; const szSetting: PChar; dbv: PDBVARIANT): Integer;

    function DBFreeVariant(dbv: PDBVARIANT): Integer;

    function DBDeleteContactSetting(hContact: THandle; const szModule: PChar; const szSetting: PChar): Integer;

    function DBWriteContactSettingByte(hContact: THandle; const szModule: PChar; const szSetting: PChar; val: Byte): Integer;

    function DBWriteContactSettingWord(hContact: THandle; const szModule: PChar; const szSetting: PChar; val: Word): Integer;

    function DBWriteContactSettingDWord(hContact: THandle; const szModule: PChar; const szSetting: PChar; val: LongInt): Integer;

    function DBWriteContactSettingString(hContact: THandle; const szModule: PChar; const szSetting: PChar; const val: PChar): Integer;

    {$else}

    function DBGetContactSettingByte(hContact: THandle;
        const szModule: PChar; const szSetting: PChar; errorValue: Integer): Integer;
    {$ifdef FPC}
    inline;
    {$endif}
    var
        dbv: TDBVARIANT;
        cgs: TDBCONTACTGETSETTING;
    begin

        cgs.szModule := szModule;
        cgs.szSetting := szSetting;
        cgs.pValue := @dbv;

        If PluginLink^.CallService(MS_DB_CONTACT_GETSETTING, hContact, lParam(@cgs)) <> 0 then
            Result := ErrorValue
        else
            Result := dbv.bVal;
    end;

    function DBGetContactSettingWord(hContact: THandle;
        const szModule: PChar; const szSetting: PChar; errorValue: Integer): Integer;
    {$ifdef FPC}
    inline;
    {$endif}
    var
        dbv: TDBVARIANT;
        cgs: TDBCONTACTGETSETTING;
    begin
        cgs.szModule := szModule;
        cgs.szSetting := szSetting;
        cgs.pValue := @dbv;
        If PluginLink^.CallService(MS_DB_CONTACT_GETSETTING, hContact, lParam(@cgs)) <> 0 then
            Result := ErrorValue
        else
            Result := dbv.wVal;
    end;

    function DBGetContactSettingDword(hContact: THandle;
        const szModule: PChar; const szSetting: PChar; errorValue: Integer): Integer;
    {$ifdef FPC}
    inline;
    {$endif}
    var
        dbv: TDBVARIANT;
        cgs: TDBCONTACTGETSETTING;
    begin
        cgs.szModule := szModule;
        cgs.szSetting := szSetting;
        cgs.pValue := @dbv;
        If PluginLink^.CallService(MS_DB_CONTACT_GETSETTING, hContact, lParam(@cgs)) <> 0 then
            Result := ErrorValue
        else
            Result := dbv.dVal;
    end;

    function DBGetContactSetting(hContact: THandle;
        const szModule: PChar; const szSetting: PChar; dbv: PDBVARIANT): Integer;
    {$ifdef FPC}
    inline;
    {$endif}
    var
        cgs: TDBCONTACTGETSETTING;
    begin
        cgs.szModule := szModule;
        cgs.szSetting := szSetting;
        cgs.pValue := dbv;
        Result := PluginLink^.CallService(MS_DB_CONTACT_GETSETTING, hContact, lParam(@cgs));
    end;

    function DBFreeVariant(dbv: PDBVARIANT): Integer;
    {$ifdef FPC}
    inline;
    {$endif}
    begin
        Result := PluginLink^.CallService(MS_DB_CONTACT_FREEVARIANT, 0, lParam(dbv));
    end;

    function DBDeleteContactSetting(hContact: THandle; const szModule: PChar; const szSetting: PChar): Integer;
    {$ifdef FPC}
    inline;
    {$endif}
    var
        cgs: TDBCONTACTGETSETTING;
    begin
        cgs.szModule := szModule;
        cgs.szSetting := szSetting;
        Result := PluginLink^.CallService(MS_DB_CONTACT_DELETESETTING, hContact, lParam(@cgs));
    end;

    function DBWriteContactSettingByte(hContact: THandle; const szModule: PChar; const szSetting: PChar; val: Byte): Integer;
    {$ifdef FPC}
    inline;
    {$endif}
    var
        cws: TDBCONTACTWRITESETTING;
    begin
        cws.szModule := szModule;
        cws.szSetting := szSetting;
        cws.value.type_ := DBVT_BYTE;
        cws.value.bVal := Val;
        Result := PluginLink^.CallService(MS_DB_CONTACT_WRITESETTING, hContact, lParam(@cws));
    end;

    function DBWriteContactSettingWord(hContact: THandle; const szModule: PChar; const szSetting: PChar; val: Word): Integer;
    {$ifdef FPC}
    inline;
    {$endif}
    var
        cws: TDBCONTACTWRITESETTING;
    begin
        cws.szModule := szModule;
        cws.szSetting := szSetting;
        cws.value.type_ := DBVT_WORD;
        cws.value.wVal := Val;
        Result := PluginLink^.CallService(MS_DB_CONTACT_WRITESETTING, hContact, lParam(@cws));
    end;

    function DBWriteContactSettingDWord(hContact: THandle; const szModule: PChar; const szSetting: PChar; val: LongInt): Integer;
    {$ifdef FPC}
    inline;
    {$endif}
    var
        cws: TDBCONTACTWRITESETTING;
    begin
        cws.szModule := szModule;
        cws.szSetting := szSetting;
        cws.value.type_ := DBVT_DWORD;
        cws.value.dVal := Val;
        Result := PluginLink^.CallService(MS_DB_CONTACT_WRITESETTING, hContact, lParam(@cws));
    end;

    function DBWriteContactSettingString(hContact: THandle; const szModule: PChar; const szSetting: PChar; const val: PChar): Integer;
    {$ifdef FPC}
    inline;
    {$endif}
    var
        cws: TDBCONTACTWRITESETTING;
    begin
        cws.szModule := szModule;
        cws.szSetting := szSetting;
        cws.value.type_ := DBVT_ASCIIZ;
        cws.value.pszVal := Val;
        Result := PluginLink^.CallService(MS_DB_CONTACT_WRITESETTING, hContact, lParam(@cws));
    end;

    {$endif}

{$endif}

{$ifdef M_NETLIB}

    {$ifdef M_API_UNIT}

    function Netlib_CloseHandle(Handle: THandle): int;

    function Netlib_GetBase64DecodedBufferSize(const cchEncoded: int): int;

    function Netlib_GetBase64EncodedBufferSize(const cbDecoded: int): int;

    function Netlib_Send(hConn: THandle; const buf: PChar; len: int; flags: int): int;

    function Netlib_Recv(hConn: THandle; const buf: PChar; len: int; flags: int): int;

    procedure Netlib_Log(hNetLib: THandle; const sz: PChar);

    {$else}

    function Netlib_CloseHandle(Handle: THandle): int;
    {$ifdef FPC}
    inline;
    {$endif}
    begin
        Result := PluginLink^.CallService(MS_NETLIB_CLOSEHANDLE, Handle, 0);
    end;

    function Netlib_GetBase64DecodedBufferSize(const cchEncoded: int): int;
    {$ifdef FPC}
    inline;
    {$endif}
    begin
        Result := (cchEncoded shr 2) * 3;
    end;

    function Netlib_GetBase64EncodedBufferSize(const cbDecoded: int): int;
    {$ifdef FPC}
    inline;
    {$endif}
    begin
        Result := (cbDecoded  * 4+11) div 12*4+1;
    end;

    function Netlib_Send(hConn: THandle; const buf: PChar; len: int; flags: int): int;
    {$ifdef FPC}
    inline;
    {$endif}
    var
        nlb: TNETLIBBUFFER;
    begin
        nlb.buf := buf;
        nlb.len := len;
        nlb.flags := flags;
        Result := PluginLink^.CallService(MS_NETLIB_SEND, wParam(hConn), lParam(@nlb));
    end;

    function Netlib_Recv(hConn: THandle; const buf: PChar; len: int; flags: int): int;
    {$ifdef FPC}
    inline;
    {$endif}
    var
        nlb: TNETLIBBUFFER;
    begin
        nlb.buf := buf;
        nlb.len := len;
        nlb.flags := flags;
        Result := PluginLink^.CallService(MS_NETLIB_RECV, wParam(hConn), lParam(@nlb));
    end;

    procedure Netlib_Log(hNetLib: THandle; const sz: PChar);
    {$ifdef FPC}
    inline;
    {$endif}
    begin
        PluginLink^.CallService(MS_NETLIB_LOG, hNetLib, lParam(sz));
    end;

    {$endif}

{$endif}

{$ifdef M_UTILS}

    {$ifdef M_API_UNIT}

	function WindowList_Add(hList: THandle; hWnd: HWND; hContact: THandle): int;

 	function WindowList_Remove(hList: THandle; hWnd: THandle): int;

	function WindowList_Find(hList: THandle; hContact: THandle): int;

    function WindowList_Broadcast(hList: THandle; message: int; wParam: WPARAM; lParam: LPARAM): int;

    function Utils_SaveWindowPosition(hWnd: THandle; hContact: THandle; const szModule, szNamePrefix: PChar): int;

	function Utils_RestoreWindowPosition(hWnd: THandle; hContact: THandle; Flags: int; const szModule, szNamePrefix: PChar): int;

    {$else}

    function WindowList_Add(hList: THandle; hWnd: hWnd; hContact: THandle): int;
    var
        wle: TWINDOWLISTENTRY;
    begin
        wle.hList    := hList;
        wle.hWnd     := hWnd;
        wle.hContact := hContact;
        Result := PluginLink^.CallService(MS_UTILS_ADDTOWINDOWLIST, 0, lParam(@wle));
    end;

    function WindowList_Remove(hList: THandle; hWnd: THandle): int;
    begin
        Result := PluginLink^.CallService(MS_UTILS_REMOVEFROMWINDOWLIST, hList, hWnd);
    end;

    function WindowList_Find(hList: THandle; hContact: THandle): int;
    begin
        Result := PluginLink^.CallService(MS_UTILS_FINDWINDOWINLIST, hList, hContact);
    end;

    function WindowList_Broadcast(hList: THandle; message: int; wParam: WPARAM; lParam: LPARAM): int;
    var
        msg: TMSG;
    begin
        msg.message := message;
        msg.wParam  := wParam;
        msg.lParam  := lParam;
        Result := PluginLink^.CallService(MS_UTILS_BROADCASTTOWINDOWLIST, hList, Integer(@Msg));
    end;

    function Utils_SaveWindowPosition(hWnd: THandle; hContact: THandle; const szModule, szNamePrefix: PChar): int;
    var
        swp: TSAVEWINDOWPOS;
    begin
        swp.hWnd := hWnd;
        swp.hContact := hContact;
        swp.szModule := szModule;
        swp.szNamePrefix := szNamePrefix;
        Result := PluginLink^.CallService(MS_UTILS_SAVEWINDOWPOSITION, 0, lParam(@swp));
    end;

    function Utils_RestoreWindowPosition(hWnd: THandle; hContact: THandle; Flags: int; const szModule, szNamePrefix: PChar): int;
    var
        swp: TSAVEWINDOWPOS;
    begin
        swp.hWnd         := hWnd;
        swp.hContact     := hContact;
        swp.szModule     := szModule;
        swp.szNamePrefix := szNamePrefix;
        Result := PluginLink^.CallService(MS_UTILS_RESTOREWINDOWPOSITION, Flags, lParam(@swp));
    end;

    {$endif}

{$endif}

{$ifdef M_LANGPACK}

    {$ifdef M_API_UNIT}

	function Translate(sz: PChar): PChar;

	function TranslateString(sz: string): string;

	function TranslateDialogDefault(hwndDlg: THandle): int;

    {$else}

    function Translate(sz: PChar): PChar;
    {$ifdef FPC}
    inline;
    {$endif}
    begin
        { the return value maybe NULL(0) -- it's upto the caller to know if the allocated
        string has to be removed from the DLL heap, this has little to do with Miranda,
        but if a dynamic string is passed and a return string is used -- the dynamic
        string is lost -- be careful, lazy? use TranslateString (note it's slower) }
        Result := PChar(PluginLink^.CallService(MS_LANGPACK_TRANSLATESTRING, 0, lParam(sz)));
    end;

    function TranslateString(sz: string): string;
    {$ifdef FPC}
    inline;
    {$endif}
    begin
         Result := string(PChar( PluginLink^.CallService(MS_LANGPACK_TRANSLATESTRING, 0, lParam(sz))));
    end;

    function TranslateDialogDefault(hwndDlg: THandle): int;
    {$ifdef FPC}
    inline;
    {$endif}
    var
        lptd: TLANGPACKTRANSLATEDIALOG;
    begin
        lptd.cbSize := sizeof(lptd);
        lptd.flags := 0;
        lptd.hwndDlg := hwndDlg;
        lptd.ignoreControls := nil;
        Result := PluginLink^.CallService(MS_LANGPACK_TRANSLATEDIALOG, 0, lParam(@lptd));
    end;

    {$endif}

{$endif}

{$ifdef M_PROTOCOLS}
    {$ifdef M_API_UNIT}

        function CallContactService(hContact: THandle; const szProtoService: PChar; wParam: WPARAM; lParam: LPARAM): int;

        function CallProtoService(const szModule, szService: PChar; wParam: WPARAM; lParam: LPARAM): int;

    {$else}

        function CallContactService(hContact: THandle; const szProtoService: PChar; wParam: WPARAM; lParam: LPARAM): int;
        {$ifdef FPC}
        inline;
        {$endif}
        var
            css: TCCSDATA;
        begin
            css.hContact := hContact;
            css.szProtoService := szProtoService;
            css.wParam := wParam;
            css.lParam := lParam;
            Result := PluginLink^.CallService(MS_PROTO_CALLCONTACTSERVICE, 0, Integer(@css));
        end;

        function CallProtoService(const szModule, szService: PChar; wParam: WPARAM; lParam: LPARAM): int;
        {$ifdef FPC}
        inline;
        {$endif}
        var
            szStr: array[0..MAXMODULELABELLENGTH] of Char;
        begin
            strcpy(szStr, szModule);
            strcat(szStr, szService);
            Result := PluginLink^.CallService(szStr, wParam, lParam);
        end;

    {$endif}
{$endif}

{$ifdef M_PROTOMOD}
    {$ifdef M_API_UNIT}

    function ProtoBroadcastAck(const szModule: PChar; hContact: THandle; type_: int; result_: int; hProcess: THandle; lParam: LPARAM): int;

    function CreateProtoServiceFunction(const szModule, szService: PChar; serviceProc: TMIRANDASERVICE): int;

    {$else}

    function ProtoBroadcastAck(const szModule: PChar; hContact: THandle; type_: int; result_: int; hProcess: THandle; lParam: LPARAM): int;
    {$ifdef FPC}
    inline;
    {$endif}
    var
        ack: TACKDATA;
    begin
        ack.cbSize   := sizeof(TACKDATA);
        ack.szModule := szModule;
        ack.hContact := hContact;
        ack.type_    := type_;
        ack.result_  := result_;
        ack.hProcess := hProcess;
        ack.lParam   := lParam;
        Result := PluginLink^.CallService(MS_PROTO_BROADCASTACK, 0, Integer(@ack));
    end;

    function CreateProtoServiceFunction(const szModule, szService: PChar; serviceProc: TMIRANDASERVICE): int;
    {$ifdef FPC}
    inline;
    {$endif}
    var
        szStr: array[0..MAXMODULELABELLENGTH] of Char;
    begin
        strcpy(szStr, szModule);
        strcat(szStr, szService);
        Result := PluginLink^.CreateServiceFunction(szStr, @serviceProc);
    end;

    {$endif}

{$endif}

{$ifdef M_SKIN}

    {$ifdef M_API_UNIT}

    function LoadSkinnedIcon(id: int): THandle;

    function LoadSkinnedProtoIcon(const szProto: PChar; status: int): THandle;

    function SkinAddNewSound(const name, description, defaultFile: PChar): int;

    function SkinPlaySound (const name: PChar): int;

    {$else}

    function LoadSkinnedIcon(id: int): THandle;
    {$ifdef FPC}
    inline;
    {$endif}
    begin
        Result := PluginLink^.CallService(MS_SKIN_LOADICON, id, 0);
    end;

    function LoadSkinnedProtoIcon(const szProto: PChar; status: int): THandle;
    {$ifdef FPC}
    inline;
    {$endif}
    begin
        Result := PluginLink^.CallService(MS_SKIN_LOADPROTOICON, wParam(szProto), status);
    end;

    function SkinAddNewSound(const name, description, defaultFile: PChar): int;
    {$ifdef FPC}
    inline;
    {$endif}
    var
        ssd: TSKINSOUNDDESC;
    begin
        ssd.cbSize := sizeof(ssd);
        ssd.pszName := name;
        ssd.pszDescription := description;
        ssd.pszDefaultFile := defaultFile;
        Result := PluginLink^.CallService(MS_SKIN_ADDNEWSOUND, 0, lParam(@ssd));
    end;

    function SkinPlaySound (const name: PChar): int;
    {$ifdef FPC}
    inline;
    {$endif}
    begin
        Result := PluginLink^.CallService(MS_SKIN_PLAYSOUND, 0, lParam(name));
    end;

    {$endif}

{$endif}