summaryrefslogtreecommitdiff
path: root/plugins/Utils.pas/cbex.pas
blob: 9805b7663413280cd6cfb417f45c9e8f9d1cb5ef (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
unit CBEx;
interface

uses windows;

// build combobox with xstatus icons and names

function AddCBEx(wnd:HWND;proto:PAnsiChar):HWND;

implementation

uses messages,commctrl,m_api,common;

function AddCBEx(wnd:HWND;proto:PAnsiChar):HWND;
var
  cbei:TCOMBOBOXEXITEMW;
  total,cnt:integer;
  il:HIMAGELIST;
  icon:HICON;
  buf,buf1:array [0..127] of AnsiChar;
  b:array [0..63] of WideChar;
  ics:TCUSTOM_STATUS;
begin
  result:=0;
  SendMessage(wnd,CB_RESETCONTENT,0,0);
  StrCopy(StrCopyE(buf,proto),PS_GETCUSTOMSTATUSICON);

  if ServiceExists(@buf)=0 then
    exit;

  il:=ImageList_Create(16,16,ILC_COLOR32 or ILC_MASK,0,1);
  if il=0 then exit;

  cnt:=0;
  StrCopy(StrCopyE(buf1,proto),PS_GETCUSTOMSTATUSEX);

  cbei.mask:=CBEIF_IMAGE or CBEIF_SELECTEDIMAGE or CBEIF_TEXT; //!!
  ics.cbSize  :=SizEOf(ics);
  ics.flags   :=CSSF_STATUSES_COUNT;
  ics.szName.w:=@b;
  ics.wParam  :=@total;
  CallService(buf1,0,lParam(@ics));
  ics.flags :=CSSF_DEFAULT_NAME or CSSF_MASK_NAME or CSSF_UNICODE;

  while cnt<=total do
  begin
    if cnt=0 then
    begin
      ImageList_AddIcon(il,CallService(MS_SKIN_LOADICON,SKINICON_OTHER_SMALLDOT,0));
      cbei.pszText:=TranslateW('None');
    end
    else
    begin
      icon:=CallService(@buf,cnt,LR_SHARED);
      if icon=0 then break;
      if ImageList_AddIcon(il,icon)=-1 then break;
      ics.wParam:=@cnt;
      CallService(@buf1,0,lparam(@ics));
      cbei.pszText:=TranslateW(@b);
    end;
    cbei.iItem         :=cnt;
    cbei.iImage        :=cnt;
    cbei.iSelectedImage:=cnt;
    if SendMessageW(wnd,CBEM_INSERTITEMW,0,lparam(@cbei))=-1 then break;
    inc(cnt);
//    DestroyIcon(icon);
  end;

  if cnt=0 then
    ImageList_Destroy(il)
  else
  begin
    ImageList_Destroy(SendMessage(wnd,CBEM_SETIMAGELIST,0,il));
    SendMessage(wnd,CB_SETCURSEL,0,0);
    result:=wnd;
  end;
end;

end.