summaryrefslogtreecommitdiff
path: root/plugins/Watrack/status/i_hotkey.inc
blob: 3ad23ae6566a2955087f649c93e8e8c57ba0a723 (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
{main hotkey code}
function InsertProc(wParam:WPARAM;lParam:LPARAM):int_ptr; cdecl;
var
  CurWin:HWND;
  s:pWideChar;
  p:PAnsiChar;
  isUnicode:boolean;
  i:integer;
  j:integer;
  tt:tTemplateType;
begin
  result:=0;
  if DisablePlugin=dsPermanent then
    exit;
  if Loword(LastStatus)<>WAT_PLS_NORMAL then
    exit;
//  i:=CallService(MS_WAT_GETMUSICINFO,0,0);
  if UseMessages=BST_CHECKED then
  begin
    CurWin:=GetFocus;
    if CurWin<>0 then
    begin
//      j:=WndToContact(WaitFocusedWndChild(GetForegroundwindow){GetFocus});
      j:=WndToContact(CurWin);
      p:=GetContactProtoAcc(j);
//      p:=PAnsiChar(CallService(MS_PROTO_GETCONTACTBASEPROTO,j,0));
      if DBReadByte(j,p,'ChatRoom',0)=1 then
      begin
        isUnicode:=false;
        tt:=tmpl_chat;
      end
      else
      begin
        isUnicode:=true;
        tt:=tmpl_pm;
      end;
      if SimpleMode<>BST_UNCHECKED then
        i:=0
      else
        i:=FindProto(p);
      s:=GetMacros(tt,i);
      // not empty and not disabled
      if (s<>nil) and (uint_ptr(s)<>uint_ptr(-1)) then
      begin
        if StrScanW(s,'{')<>nil then
          SendRTF(CurWin,s,isUnicode,UserCP)
        else
        begin
          if isUnicode then
            SendMessageW(CurWin,EM_REPLACESEL,0,tlparam(s))
          else
          begin
            SendMessageA(CurWin,EM_REPLACESEL,0,tlparam(WideToAnsi(s,p,UserCP)));
            mFreeMem(p);
          end;
        end;
        mFreeMem(s);
      end;
      result:=1;
    end;
  end;
end;