summaryrefslogtreecommitdiff
path: root/plugins/Watrack/status/i_opt_11.inc
blob: 2bb15460157e887673f1aa8347c891889501987e (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
{Templates}
const
  DLGED_INIT = $1000; // dialog init, not activate Apply button
  DLGED_PROT = $0800; // proto changed
  DLGED_STAT = $0400; // status changed
  DLGED_PACK = $0200; // needed string packing
  DLGED_CHGD = $0100; // something changed
  DLGED_MSG  = $0001; // message template changed
  DLGED_STTT = $0004; // status template changed
  DLGED_CHNL = $0008; // channel template changed
  DLGED_XTTL = $0010; // xstatus title changed
  DLGED_XTTT = $0020; // xstatus template changed
  DLGED_TUNE = $0040; // tunes template changed
  DLGED_BASE = DLGED_MSG +DLGED_STTT+DLGED_CHNL+
               DLGED_TUNE+DLGED_XTTL+DLGED_XTTT;

const
  maxShowControls = 7;
  aListFields:array [0..maxShowControls-1] of integer= (
     IDC_STATUS_TEXT,
     IDC_XSTATUS_TITLE, IDC_XSTATUS_TEXT,
     IDC_LISTENING_TEXT,
     IDC_STAT_ENABLE,IDC_XSTAT_ENABLE,IDC_TUNES_ENABLE);

  aShowFields: array [0..2,0..maxShowControls-1] of integer = (
{status}  (SW_SHOW, SW_HIDE, SW_HIDE, SW_HIDE, SW_SHOW, SW_HIDE, SW_HIDE),
{xstatus} (SW_HIDE, SW_SHOW, SW_SHOW, SW_HIDE, SW_HIDE, SW_SHOW, SW_HIDE),
{tunes}   (SW_HIDE, SW_HIDE, SW_HIDE, SW_SHOW, SW_HIDE, SW_HIDE, SW_SHOW));

var
  CurProto,
  CurStatus:integer;

procedure RedrawFields(Dialog:HWND;proto:integer=-1);
var
  wnd1,wnd:HWND;
  p:pWideChar;
  i:integer;
begin
  Changed:=Changed or DLGED_INIT;
  if proto<0 then
    proto:=CurProto;

  SetDlgItemTextW(Dialog,IDC_EDIT_MSG,
      GetTemplateStr(tmpl_pm,proto,CurStatus));

  p:=GetTemplateStr(tmpl_stext,proto,CurStatus);

  wnd:=GetDlgItem(Dialog,IDC_STATUS_TEXT);

  SendMessageW(wnd,WM_SETTEXT,0,lparam(p));
  if IsTemplateActive(tmpl_stext,proto,CurStatus) then
  begin
    EnableWindow(wnd,true);
    i:=BST_CHECKED;
  end
  else
  begin
    EnableWindow(wnd,false);
    i:=BST_UNCHECKED;
  end;
  CheckDlgButton(Dialog,IDC_STAT_ENABLE,i);

  if IsXStatusSupported(CurProto) then
  begin
    wnd :=GetDlgItem(Dialog,IDC_XSTATUS_TITLE);
    wnd1:=GetDlgItem(Dialog,IDC_XSTATUS_TEXT);
    p:=GetTemplateStr(tmpl_xtitle,proto,CurStatus);
    SendMessageW(wnd ,WM_SETTEXT,0,lparam(p));
    SendMessageW(wnd1,WM_SETTEXT,0,
        lparam(GetTemplateStr(tmpl_xtext,proto,CurStatus)));

    if IsTemplateActive(tmpl_xtitle,proto,CurStatus) then
    begin
      EnableWindow(wnd ,true);
      EnableWindow(wnd1,true);
      i:=BST_CHECKED;
    end
    else
    begin
      EnableWindow(wnd ,false);
      EnableWindow(wnd1,false);
      i:=BST_UNCHECKED;
    end;
    CheckDlgButton(Dialog,IDC_XSTAT_ENABLE,i);
  end;

  if IsTunesSupported(CurProto) then
  begin
    p:=GetTemplateStr(tmpl_tunes,proto,CurStatus);
    wnd:=GetDlgItem(Dialog,IDC_LISTENING_TEXT);
    SendMessageW(wnd,WM_SETTEXT,0,lparam(p));
    if IsTemplateActive(tmpl_tunes,proto,CurStatus) then
    begin
      EnableWindow(wnd,true);
      i:=BST_CHECKED;
    end
    else
    begin
      EnableWindow(wnd,false);
      i:=BST_UNCHECKED;
    end;
    CheckDlgButton(Dialog,IDC_TUNES_ENABLE,i);
  end;
 
  if IsChatSupported(CurProto) then
    SetDlgItemTextW(Dialog,IDC_EDIT_CHANNEL,
       GetTemplateStr(tmpl_chat,proto,CurStatus));

  Changed:=Changed and not DLGED_INIT;
end;

procedure SetScreenFull(Dialog:HWND);
var
  show:integer;
  buf:array [0..127] of AnsiChar;
  endis:boolean;
  wnd:HWND;
begin
  Changed:=Changed or DLGED_INIT;
  CurStatus:=0;

  CheckDlgButton(Dialog,IDC_IRC_USER   ,BST_CHECKED);
  CheckDlgButton(Dialog,IDC_IRC_CHANNEL,BST_UNCHECKED);
  ShowWindow(GetDlgItem(Dialog,IDC_EDIT_MSG    ),SW_SHOW);
  ShowWindow(GetDlgItem(Dialog,IDC_EDIT_CHANNEL),SW_HIDE);

  if IsChatSupported(CurProto) then
    show:=SW_SHOW
  else
    show:=SW_HIDE;

  ShowWindow(GetDlgItem(Dialog,IDC_IRC_USER   ),show);
  ShowWindow(GetDlgItem(Dialog,IDC_IRC_CHANNEL),show);

//  wnd:=GetDlgItem(Dialog,IDC_PROTOLIST);

//!!!!  SendMessage(wnd,CB_SETCURSEL,0,0); //???

//  SendMessageA(wnd,LVM_GETITEMTEXTA,);  	
//  ListView_GetItemTextA(wnd,CurProto,0,@buf,SizeOf(buf));

  StrCopy(buf,GetProtoName(CurProto));
  StrCat(buf,PS_GETCUSTOMSTATUSICON);
  endis:=ServiceExists(buf)<>0;

  EnableWindow(GetDlgItem(Dialog,IDC_CBEX       ),endis);
  EnableWindow(GetDlgItem(Dialog,IDC_XSTAT_AUDIO),endis);
  EnableWindow(GetDlgItem(Dialog,IDC_XSTAT_VIDEO),endis);
  if endis then
  begin
    CheckDlgButton(Dialog,IDC_XSTAT_AUDIO,BST_CHECKED);
    CheckDlgButton(Dialog,IDC_XSTAT_VIDEO,BST_UNCHECKED);
  end;
  
  wnd:=GetDlgItem(Dialog,IDC_STATUSLIST);
  FillStatusList(CurProto,wnd,true);
  SendMessage(wnd,CB_SETCURSEL,0,0);
  RedrawFields(Dialog);
end;

procedure SetTemplate(Dialog:HWND;idc:integer;Tmpl:tTemplateType);
begin
  SetTemplateStr   (GetDlgText(Dialog,ABS(idc)),Tmpl,CurProto,CurStatus);
  SetTemplateActive(idc>0                      ,Tmpl,CurProto,CurStatus);
end;

procedure SaveChanges(Dialog:HWND);
var
  i,j:integer;
begin
  if (Changed and DLGED_BASE)<>0 then
  begin
    if (Changed and DLGED_MSG )<>0 then SetTemplate(Dialog,IDC_EDIT_MSG    ,tmpl_pm);
    if (Changed and DLGED_CHNL)<>0 then SetTemplate(Dialog,IDC_EDIT_CHANNEL,tmpl_chat);


    if (Changed and DLGED_STTT)<>0 then
    begin
      if IsDlgButtonChecked(Dialog,IDC_STAT_ENABLE)<>BST_UNCHECKED then
        i:=IDC_STATUS_TEXT
      else
        i:=-IDC_STATUS_TEXT;
      SetTemplate(Dialog,i,tmpl_stext);
    end;

    if (Changed and DLGED_TUNE)<>0 then
    begin
      if IsDlgButtonChecked(Dialog,IDC_TUNES_ENABLE)<>BST_UNCHECKED then
        i:=IDC_LISTENING_TEXT
      else
        i:=-IDC_LISTENING_TEXT;
      SetTemplate(Dialog,i,tmpl_tunes);
    end;

    if (Changed and (DLGED_XTTL or DLGED_XTTT))<>0 then
    begin
      if IsDlgButtonChecked(Dialog,IDC_XSTAT_ENABLE)<>BST_UNCHECKED then
      begin
        i:=IDC_XSTATUS_TITLE;
        j:=IDC_XSTATUS_TEXT;
      end
      else
      begin
        i:=-IDC_XSTATUS_TITLE;
        j:=-IDC_XSTATUS_TEXT;
      end;
      if (Changed and DLGED_XTTL)<>0 then SetTemplate(Dialog,i,tmpl_xtitle);
      if (Changed and DLGED_XTTT)<>0 then SetTemplate(Dialog,j,tmpl_xtext);
    end;

    Changed:=Changed and (not DLGED_BASE);
  end;
end;

function SaveCBExValue(Dialog:HWND;direct:boolean):cardinal;
var
  wnd:HWND;
  i,j,shift:cardinal;
begin
  wnd:=GetDlgItem(Dialog,IDC_CBEX);
  i:=GetProtoSetting(CurProto,true);

  if (IsDlgButtonChecked(Dialog,IDC_XSTAT_VIDEO)<>BST_UNCHECKED) xor direct then
    shift:=0
  else
    shift:=8;

  j:=SendMessage(wnd,CB_GETCURSEL,0,0);
  i:=(i and ($FFFF0000 or ($FF shl (8-shift)))) or (j shl shift);

  SetProtoSetting(CurProto,i,true);

  result:=(i shr (8-shift)) and $FF;
end;

procedure FillCBType(Dialog:HWND;proto:pAnsiChar=nil);
var
  wnd:HWND;
  j:integer;
begin
  wnd:=GetDlgItem(Dialog,IDC_CBSTATYPE);
  SendMessage(wnd,CB_RESETCONTENT,0,0);

  CB_AddStrDataW(wnd,TranslateW('Status'),0);
  if IsXStatusSupported(uint_ptr(proto)) then CB_AddStrDataW(wnd,TranslateW('xStatus'),1);
  if IsTunesSupported  (uint_ptr(proto)) then CB_AddStrDataW(wnd,TranslateW('Tunes'  ),2);

  SendMessage(wnd,CB_SETCURSEL,0,0);

  for j:=0 to maxShowControls-1 do
    ShowWindow(GetDlgItem(Dialog,aListFields[j]),aShowFields[0][j]);
end;

function DlgProcOptions11(Dialog:HWND;hMessage:uint;wParam:WPARAM;lParam:LPARAM):LRESULT; stdcall;
var
  Item:LV_ITEMA;
  buf:array [0..127] of AnsiChar;
  i,j:integer;
  wnd:HWND;
  b:boolean;
begin
  result:=0;
  case hMessage of
    WM_DESTROY: begin
      ListView_SetImageList(GetDlgItem(Dialog,IDC_STATUSLIST),0,LVSIL_SMALL);
      ListView_SetImageList(GetDlgItem(Dialog,IDC_PROTOLIST ),0,LVSIL_SMALL);
    end;

    WM_INITDIALOG: begin
      TranslateDialogDefault(Dialog);
      Changed:=DLGED_INIT;
      FillProtoList(GetDlgItem(Dialog,IDC_PROTOLIST),true);
      CurProto  :=0;
      SetScreenFull(Dialog);
      FillCBType(Dialog,nil);
      SendMessage(Dialog,WM_COMMAND,(CBN_SELCHANGE shl 16)+IDC_CBSTATYPE,
          GetDlgItem(Dialog,IDC_CBSTATYPE));
      result:=0;
      Changed:=0;
    end;

    WM_COMMAND: begin
      case wParam shr 16 of
        EN_CHANGE: begin
          if (Changed and DLGED_INIT)=0 then
          begin
            Changed:=Changed or DLGED_CHGD or DLGED_PACK;
            case loword(wParam) of
              IDC_EDIT_MSG      : Changed:=Changed or DLGED_MSG;
              IDC_EDIT_CHANNEL  : Changed:=Changed or DLGED_CHNL;
              IDC_STATUS_TEXT   : Changed:=Changed or DLGED_STTT;
              IDC_XSTATUS_TITLE : Changed:=Changed or DLGED_XTTL;
              IDC_XSTATUS_TEXT  : Changed:=Changed or DLGED_XTTT;
              IDC_LISTENING_TEXT: Changed:=Changed or DLGED_TUNE;
            end;
            SendMessage(GetParent(Dialog),PSM_CHANGED,0,0);
          end;
        end;

        CBN_SELCHANGE: begin
          case loword(wParam) of
            IDC_CBSTATYPE: begin
              i:=CB_GetData(lParam);
              for j:=0 to maxShowControls-1 do
                ShowWindow(GetDlgItem(Dialog,aListFields[j]),aShowFields[i][j]);
            end;

            IDC_CBEX: begin
              SendMessage(GetParent(Dialog),PSM_CHANGED,0,0);
            end;
          end;
        end;

        BN_CLICKED: begin
          case LoWord(wParam) of
            IDC_CMD_DEFAULT: begin
              RedrawFields(Dialog,0);
              Changed:=Changed or DLGED_CHGD or DLGED_BASE;
              SendMessage(GetParent(Dialog),PSM_CHANGED,0,0);
            end;
            IDC_CMD_RESET: begin
              RedrawFields(Dialog);
            end;

            IDC_STAT_ENABLE, IDC_XSTAT_ENABLE, IDC_TUNES_ENABLE: begin
              case LoWord(wParam) of
                IDC_STAT_ENABLE: begin
                  Changed:=Changed or DLGED_STTT;
                  EnableWindow(GetDlgItem(Dialog,IDC_STATUS_TEXT),
                      IsDlgButtonChecked(Dialog,IDC_STAT_ENABLE)<>BST_UNCHECKED);
                end;
                IDC_XSTAT_ENABLE: begin
                  b:=IsDlgButtonChecked(Dialog,IDC_XSTAT_ENABLE)<>BST_UNCHECKED;
                  EnableWindow(GetDlgItem(Dialog,IDC_XSTATUS_TITLE),b);
                  EnableWindow(GetDlgItem(Dialog,IDC_XSTATUS_TEXT ),b);
                  Changed:=Changed or DLGED_XTTL;
                  Changed:=Changed or DLGED_XTTT;
                end;
                IDC_TUNES_ENABLE: begin
                  Changed:=Changed or DLGED_TUNE;
                  EnableWindow(GetDlgItem(Dialog,IDC_LISTENING_TEXT),
                      IsDlgButtonChecked(Dialog,IDC_TUNES_ENABLE)<>BST_UNCHECKED);
                end;
              end;
              SendMessage(GetParent(Dialog),PSM_CHANGED,0,0);
            end;

            IDC_XSTAT_VIDEO, IDC_XSTAT_AUDIO: begin
              SendDlgItemMessage(Dialog,IDC_CBEX,CB_SETCURSEL,SaveCBExValue(Dialog,false),0);
            end;
            IDC_HELP_COLOR: begin
              ShowColorHelpDlg(Dialog);
              exit;
            end;
            IDC_HELP_FORMAT: begin
              MessageBoxW(0,TranslateW(sFormatHelp),TranslateW('Format text Info'),0);
              exit;
            end;
            IDC_HELP_VARIABLES: begin
              CallService(MS_WAT_MACROHELP,Dialog,0);
              exit;
            end;
            IDC_IRC_USER: begin
//              CheckDlgButton(Dialog,IDC_IRC_USER   ,BST_CHECKED);
//              CheckDlgButton(Dialog,IDC_IRC_CHANNEL,BST_UNCHECKED);
              ShowWindow(GetDlgItem(Dialog,IDC_EDIT_MSG    ),SW_SHOW);
              ShowWindow(GetDlgItem(Dialog,IDC_EDIT_CHANNEL),SW_HIDE);
            end;
            IDC_IRC_CHANNEL: begin
//              CheckDlgButton(Dialog,IDC_IRC_USER   ,BST_UNCHECKED);
//              CheckDlgButton(Dialog,IDC_IRC_CHANNEL,BST_CHECKED);
              ShowWindow(GetDlgItem(Dialog,IDC_EDIT_CHANNEL),SW_SHOW);
              ShowWindow(GetDlgItem(Dialog,IDC_EDIT_MSG    ),SW_HIDE);
            end;
          else
            SaveChanges(Dialog); //??
          end;
        end;
      end;

    end;

    WM_HELP: begin
      case PHELPINFO(lParam).iCtrlId of
        IDC_EDIT_MSG,IDC_EDIT_CHANNEL,IDC_XSTATUS_TITLE,
        IDC_STATUS_TEXT,IDC_XSTATUS_TEXT,IDC_LISTENING_TEXT:
          CallService(MS_WAT_MACROHELP,Dialog,0);
      end;
    end;

    WM_NOTIFY: begin
      if (Changed and DLGED_INIT)<>0 then
        exit;
      if integer(PNMLISTVIEW(lParam)^.hdr.code)=LVN_ITEMCHANGED then
      begin
        SendMessage(GetParent(Dialog),PSM_CHANGED,0,0);
        if ((PNMLISTVIEW(lParam)^.uNewState and LVIS_FOCUSED)<>0) then
        begin
          SaveChanges(Dialog);

          if PNMLISTVIEW(lParam)^.hdr.idFrom=IDC_PROTOLIST then
          begin
            CheckStatusList(GetDlgItem(Dialog,IDC_STATUSLIST),CurProto);
            SaveCBExValue(Dialog,true);
            CurProto:=PNMLISTVIEW(lParam)^.iItem;
            SetScreenFull(Dialog);
//            ListView_GetItemTextA(PNMLISTVIEW(lParam)^.hdr.hwndFrom,CurProto,0,@buf,SizeOf(buf));
            StrCopy(buf,GetProtoName(CurProto));
            wnd:=GetDlgItem(Dialog,IDC_CBEX);
            FillCBType(Dialog,buf);
            if AddCBEx(wnd,buf)<>0 then
            begin
              i:=GetProtoSetting(CurProto,true);
              SendMessage(wnd,CB_SETCURSEL,i and $FF,0);
            end;
          end

          else //IDC_STATUSLIST
          begin
            Item.iItem:=PNMLISTVIEW(lParam)^.iItem;
            Item.mask:=LVIF_PARAM;
            SendMessageA(PNMLISTVIEW(lParam)^.hdr.hwndFrom,LVM_GETITEMA,0,tlparam(@Item));
//            ListView_GetItemA(PNMLISTVIEW(lParam)^.hdr.hwndFrom,Item);
            CurStatus:=GetStatusNum(Item.lParam);
            RedrawFields(Dialog);
          end;
        end

        else if PNMLISTVIEW(lParam)^.uNewState<>0 then
        begin
          if PNMLISTVIEW(lParam)^.hdr.idFrom=IDC_PROTOLIST then
            Changed:=Changed or DLGED_PROT or DLGED_CHGD
          else
            Changed:=Changed or DLGED_STAT or DLGED_CHGD;
        end;
      end

      else if integer(PNMHdr(lParam)^.code)=PSN_APPLY then
      begin
        if (Changed and DLGED_PROT)<>0 then
        begin
          CheckProtoList(GetDlgItem(Dialog,IDC_PROTOLIST));
          Changed:=Changed and not DLGED_PROT;
        end;
        if (Changed and DLGED_STAT)<>0 then
        begin
          CheckStatusList(GetDlgItem(Dialog,IDC_STATUSLIST),CurProto);
          Changed:=Changed and not DLGED_STAT;
        end;
        SaveCBExValue(Dialog,true);
        SaveChanges(Dialog);
        SaveTemplates;
      end;
    end;
  else
    {result:=}DefWindowProc(Dialog,hMessage,wParam,lParam);
  end;
end;