summaryrefslogtreecommitdiff
path: root/plugins/mRadio/rframeapi.pas
blob: c0cc1702bcc1782e2450ccb3d6d834b52e1ca83b (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
{mRadio frame}
unit rframeapi;

interface

uses
  windows;

const
  hVolFrmCtrl:HWND=0;
  hVolFrmMute:HWND=0;

procedure CreateFrame(parent:HWND);
procedure DestroyFrame;

implementation

uses
  messages,commctrl,
  m_api,common,
  rglobal;

{$include mr_rc.inc}

const
  frm_back:pAnsiChar = 'Frame background';
const
  FrameWnd:HWND = 0;
  FrameId:integer = -1;
var
  colorhook:THANDLE;
  hbr:HBRUSH;
  frm_bkg:TCOLORREF;
  OldSliderWndProc:pointer;

function QSDlgResizer(Dialog:HWND;lParam:LPARAM;urc:PUTILRESIZECONTROL):int; cdecl;
begin
  case urc^.wId of
    IDC_RADIO_OPEN: result:=RD_ANCHORX_LEFT  or RD_ANCHORY_CENTRE;
    IDC_RADIO_MUTE: result:=RD_ANCHORX_RIGHT or RD_ANCHORY_CENTRE;
    IDC_RADIO_VOL : result:=RD_ANCHORX_WIDTH or RD_ANCHORY_CENTRE;
  else
    result:=0;
  end;
end;

function SliderWndProc(Dialog:HWND;hMessage:uint;wParam:WPARAM;lParam:LPARAM):LRESULT; stdcall;
begin
  if hMessage=WM_ERASEBKGND then
    result:=1
  else
    result:=CallWindowProc(OldSliderWndProc, Dialog, hMessage, wParam, lParam);
end;

procedure MakeTooltip(Dialog:HWND);
var
  hwndTooltip:HWND;
  ti:TTOOLINFOW;
begin
  hwndTooltip:=CreateWindowW(TOOLTIPS_CLASS,nil,TTS_ALWAYSTIP,
      integer(CW_USEDEFAULT),integer(CW_USEDEFAULT),
      integer(CW_USEDEFAULT),integer(CW_USEDEFAULT),
      Dialog,0,hInstance,nil);

  FillChar(ti,SizeOf(ti),0);
  ti.cbSize  :=sizeof(TOOLINFO);
  ti.uFlags  :=TTF_IDISHWND or TTF_SUBCLASS;
  ti.hwnd    :=Dialog;
  ti.hinst   :=hInstance;
  ti.uId     :=GetDlgItem(Dialog,IDC_RADIO_MUTE);
  ti.lpszText:=pWideChar(TranslateW('Mute'));
  SendMessageW(hwndTooltip,TTM_ADDTOOLW,0,tlparam(@ti));
end;

function RadioFrameProc(Dialog:HWND;hMessage:uint;wParam:WPARAM;lParam:LPARAM):LRESULT; stdcall;
var
  rc:TRECT;
  tmp:pAnsiChar;
begin
  result:=0;
  case hMessage of
    WM_DESTROY: begin
      hVolFrmCtrl:=0;
      hVolFrmMute:=0;
      DeleteObject(hbr);
      hbr:=0;
    end;

    WM_INITDIALOG: begin
      SendDlgItemMessage(Dialog,IDC_RADIO_MUTE, BUTTONSETASFLATBTN,0,0);
//      SetButtonIcon(hMuteFrmCtrl,IcoBtnOn);

      MakeTooltip(Dialog);

      hVolFrmCtrl:=GetDlgItem(Dialog,IDC_RADIO_VOL);
      hVolFrmMute:=GetDlgItem(Dialog,IDC_RADIO_MUTE);
      SendMessage(hVolFrmCtrl,TBM_SETRANGE,0,MAKELONG(0,100));
      SendMessage(hVolFrmCtrl,TBM_SETPAGESIZE,0,20);
      SendMessage(hVolFrmCtrl,TBM_SETPOS,1,gVolume);

      OldSliderWndProc:=pointer(SetWindowLongPtrW(hVolFrmCtrl,GWL_WNDPROC,LONG_PTR(@SliderWndProc)));
    end;

    WM_SIZE: begin
      Utils_ResizeDialog(Dialog, hInstance, MAKEINTRESOURCEA(IDD_FRAME), @QSDlgResizer);
    end;

    WM_ERASEBKGND: begin
      GetClientRect(Dialog,rc);
      FillRect(wParam,rc,hbr);
      result:=1;
    end;

    WM_DRAWITEM: begin
      case wParam of
        IDC_RADIO_OPEN: begin
          result:=1;
          DrawIconEx(PDRAWITEMSTRUCT(lParam)^.hDC,0,0,
              IcoLib_GetIcon(IcoBtnOpen,0),
              16,16,0,hbr,DI_NORMAL);
        end;

        IDC_RADIO_MUTE: begin
          result:=1;
          if gVolume<0 then
            tmp:=IcoBtnOff
          else
            tmp:=IcoBtnOn;
          DrawIconEx(PDRAWITEMSTRUCT(lParam)^.hDC,0,0,
              IcoLib_GetIcon(tmp,0),
              16,16,0,hbr,DI_NORMAL);
        end;
      end;
    end;

    WM_CTLCOLORBTN: begin
      if (THANDLE(lParam)=GetDlgItem(Dialog,IDC_RADIO_MUTE)) or
         (THANDLE(lParam)=GetDlgItem(Dialog,IDC_RADIO_OPEN)) then
      begin
        SetBkColor(wParam, frm_bkg);
        result:=hbr;
      end;
    end;

    WM_CTLCOLORSTATIC: begin
      if THANDLE(lParam)=hVolFrmCtrl then
      begin
        SetBkColor(wParam, frm_bkg);
        result:=hbr;
      end;
    end;

    WM_CONTEXTMENU: begin
      CallService(cPluginName + '/Settings',0,0);
    end;

    WM_COMMAND: begin
      case wParam shr 16 of

        BN_CLICKED: begin
          case loword(wParam) of
            IDC_RADIO_OPEN: begin
              CallService(MS_RADIO_QUICKOPEN,0,0);
            end;
            IDC_RADIO_MUTE: begin
              CallService(MS_RADIO_MUTE,0,1);
            end;
          end;
        end;
      end;
    end;

    WM_HSCROLL: begin
      CallService(MS_RADIO_SETVOL,SendMessage(lParam,TBM_GETPOS,0,0){gVolume},2)
    end;

  else
    result:=DefWindowProc(Dialog,hMessage,wParam,lParam);
  end;
end;

function ColorReload(wParam:WPARAM;lParam:LPARAM):int;cdecl;
var
  wnd:HWND;
begin
  result:=0;
  frm_bkg:=Colour_Get(cPluginName,frm_back);
  if hbr<>0 then DeleteObject(hbr);
  hbr:=CreateSolidBrush(frm_bkg);

  wnd:=GetFocus();
	InvalidateRect(hVolFrmCtrl,nil,true);
	SetFocus(hVolFrmCtrl);
  RedrawWindow(FrameWnd,nil,0,RDW_INVALIDATE or RDW_ALLCHILDREN or RDW_ERASE);
  SetFocus(wnd);
end;

procedure CreateFrame(parent:HWND);
var
  Frame:TCLISTFrame;
  wnd:HWND;
  tmp:cardinal;
  tr:TRECT;
  cid:TColourID;
begin
  if not ServiceExists(MS_CLIST_FRAMES_ADDFRAME) then
    exit;
  if parent=0 then
    parent:=cli^.hwndContactList;

  if FrameWnd=0 then
    FrameWnd:=CreateDialog(hInstance,MAKEINTRESOURCE(IDD_FRAME),parent,@RadioFrameProc);

  if FrameWnd<>0 then
  begin
    GetWindowRect(FrameWnd,tr);
    FillChar(Frame,SizeOf(Frame),0);
    with Frame do
    begin
      cbSize  :=SizeOf(Frame);
      hWnd    :=FrameWnd;
      hIcon   :=IcoLib_GetIcon(IcoBtnSettings,0);
      align   :=alTop;
      height  :=tr.bottom-tr.top+2;
      Flags   :=F_VISIBLE or F_NOBORDER or F_UNICODE;
      name.w  :=cPluginName;
      TBName.w:=TranslateW(cPluginName + ' volume control');
    end;

    FrameId:=CallService(MS_CLIST_FRAMES_ADDFRAME,wparam(@Frame),0);
    if FrameId>=0 then
    begin
      CallService(MS_CLIST_FRAMES_UPDATEFRAME,FrameId, FU_FMPOS);

      wnd:=cli^.hwndContactList;
      tmp:=SendMessage(wnd,CLM_GETEXSTYLE,0,0);
      SendMessage(wnd,CLM_SETEXSTYLE,tmp or CLS_EX_SHOWSELALWAYS,0);

      cid.cbSize:=SizeOf(cid);
      cid.flags :=0;
      StrCopy(cid.group,cPluginName);
      StrCopy(cid.dbSettingsGroup,cPluginName);

      StrCopy(cid.name   ,frm_back);
      StrCopy(cid.setting,'frame_back');
      cid.defcolour:=GetSysColor(COLOR_3DFACE);
      cid.order    :=0;
      ColourRegister(@cid);

      hbr:=0;
      colorhook:=HookEvent(ME_COLOUR_RELOAD,@ColorReload);
      ColorReload(0,0);
      CallService(MS_RADIO_SETVOL,gVolume,0);
    end;
  end;
end;

procedure DestroyFrame;
begin
  if FrameId>=0 then
  begin
    UnhookEvent(colorhook);
    CallService(MS_CLIST_FRAMES_REMOVEFRAME,FrameId,0);
    FrameId:=-1;
  end;
  DestroyWindow(FrameWnd);
  FrameWnd:=0;
end;

end.