summaryrefslogtreecommitdiff
path: root/plugins/Watrack/kolframe/kolframe.pas
blob: 49a541a206cbaf2c84e8057d15ebfcfa3e7758ae (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
{CList frame}
unit KOLFrame;

interface

implementation

uses windows,kol,commdlg,messages,common,commctrl, KOLCCtrls,
     wat_api,wrapper,global,m_api,dbsettings,waticons,mirutils,
     icobuttons,textblock,kolsizer;

{$R frm.res}

{$include frm_data.inc}
{$include frm_vars.inc}

procedure MouseDown(DummySelf, Sender:PControl;var Mouse:TMouseEventData);
var
  wnd:HWND;
begin
  wnd:=GetParent(Sender.GetWindowHandle);
  SendMessage(wnd,WM_SYSCOMMAND,
     SC_MOVE or HTCAPTION,MAKELPARAM(Mouse.x,Mouse.y));
end;

// ---------------- frame functions ----------------

procedure SetFrameTitle(title:pointer;icon:HICON;addflag:integer=FO_UNICODETEXT);
var
  D:PWATFrameData;
begin
  D:=FrameCtrl.CustomData;
  CallService(MS_CLIST_FRAMES_SETFRAMEOPTIONS,
      (D.FrameId shl 16)+FO_TBNAME+addflag,tlparam(title));
  CallService(MS_CLIST_FRAMES_SETFRAMEOPTIONS,(D.FrameId shl 16)+FO_ICON,icon);
  CallService(MS_CLIST_FRAMES_UPDATEFRAME,D.FrameId,FU_TBREDRAW);
end;

// -----------------------

function IsFrameMinimized(FrameId:integer):bool;
begin
  result:=(CallService(MS_CLIST_FRAMES_GETFRAMEOPTIONS,
          (FrameId shl 16)+FO_FLAGS,0) and F_UNCOLLAPSED)=0;
end;

function IsFrameFloated(FrameId:integer):bool;
begin
  result:=CallService(MS_CLIST_FRAMES_GETFRAMEOPTIONS,
          (FrameId shl 16)+FO_FLOATING,0)>0;
end;

function IsFrameHidden(FrameId:integer):bool;
begin
  result:=(CallService(MS_CLIST_FRAMES_GETFRAMEOPTIONS,
          (FrameId shl 16)+FO_FLAGS,0) and F_VISIBLE)=0;
end;

procedure HideFrame(FrameId:integer);
begin
  if not IsFrameHidden(FrameId) then
  begin
    CallService(MS_CLIST_FRAMES_SHFRAME,FrameId,0);
    HiddenByMe:=true;
  end;
end;

function ShowFrame(FrameId:integer):integer;
begin
  result:=0;
  if IsFrameHidden(FrameId) then
    if HiddenByMe then
    begin
      CallService(MS_CLIST_FRAMES_SHFRAME,FrameId,0);
      HiddenByMe:=false;
    end
    else
      result:=1;
end;

{$include frm_rc.inc}
{$include frm_icogroup.inc}
{$include frm_trackbar.inc}
{$include frm_text.inc}
{$include frm_frame.inc}
{$include frm_designer.inc}

{$include frm_dlg1.inc}
{$include frm_dlg2.inc}

// ---------------- basic frame functions ----------------

function NewPlStatus(wParam:WPARAM;lParam:LPARAM):int;cdecl;
const
  needToChange:boolean=true;
var
  bufw:array [0..511] of WideChar;
//  FrameWnd:HWND;
  Cover:pAnsiChar;
  D:PWATFrameData;
begin
  result:=0;
//  FrameWnd:=FrameCtrl.Form.GetWindowHandle;
  D:=FrameCtrl.CustomData;

  case wParam of
    WAT_EVENT_PLAYERSTATUS: begin
      case integer(loword(lParam)) of
        WAT_PLS_STOPPED : begin
          if D.HideNoMusic then
            HideFrame(D.FrameId)
          else
            ShowFrame(D.FrameId); // if was hidden with "no player"
        end;
        WAT_PLS_NOTFOUND: begin
          if D.HideNoPlayer then
            HideFrame(D.FrameId);

          SetFrameTitle(PluginShort,0,0); // frame update code there
        end;
      else
        exit;
      end;
      FrameCtrl.ResetFrame;
    end;

    WAT_EVENT_NEWTRACK: begin
      // cover
      if D.UseCover then
        if (pSongInfo(lParam)^.Cover<>nil) and (pSongInfo(lParam)^.Cover^<>#0) then
        begin
          GetShortPathNameW(pSongInfo(lParam)^.Cover,bufw,SizeOf(bufw));
          WideToAnsi(bufw,Cover);
          FrameCtrl.RefreshPicture(Cover);
          mFreeMem(Cover);
        end;

      // trackbar
      TrackbarSetRange(D.Trackbar,D.UpdInterval,pSongInfo(lParam)^.total);

      if (D.UpdTimer=0) and (D.UpdInterval>0) then
        D.UpdTimer:=SetTimer(0,0,D.UpdInterval,@FrameTimerProc);

      // text
      UpdateTextBlock(D,true);

      ShowFrame(D.FrameId);
    end;

    WAT_EVENT_NEWPLAYER: begin
      SetFrameTitle(pSongInfo(lParam)^.player,pSongInfo(lParam)^.icon);
      // new player must call "no music" at least, so we have chance to show frame
    end;

    WAT_EVENT_PLUGINSTATUS: begin
      case lParam of
        dsEnabled: begin
          ShowFrame(D.FrameId);
          // plus - start frame and text timers
          if D.UpdInterval>0 then
            D.UpdTimer:=SetTimer(0,0,D.UpdInterval,@FrameTimerProc);
        end;

        dsPermanent: begin
          HideFrame(D.FrameId);

          // plus - stop frame and text timers
          if D.UpdTimer<>0 then
          begin
            KillTimer(0,D.UpdTimer);
            D.UpdTimer:=0;
          end;
        end;
      end;
    end;
  end;
end;

function IconChanged(wParam:WPARAM;lParam:LPARAM):int;cdecl;
begin
  result:=0;
  if PWATFrameData(FrameCtrl.CustomData).FrameId<>0 then
  begin
    FrameCtrl.RefreshAllFrameIcons;
    ShowWindow(FrameCtrl.GetWindowHandle,SW_HIDE);
    ShowWindow(FrameCtrl.GetWindowHandle,SW_SHOW);
  end;
end;

//??const opt_FrmHeight :PAnsiChar = 'frame/frmheight';

function CreateFrame(parent:HWND):boolean;
var
  CLFrame:TCLISTFrame;
  rc:TRECT;
  FrameWnd:HWND;
begin
  result:=false;
  if ServiceExists(MS_CLIST_FRAMES_ADDFRAME)=0 then
    exit;

  if parent=0 then
    parent:=CallService(MS_CLUI_GETHWND,0,0);

  FrameWnd:=CreateFrameWindow(parent);

  if FrameWnd<>0 then
  begin
    FillChar(CLFrame,SizeOf(CLFrame),0);
    with CLFrame do
    begin
      cbSize  :=SizeOf(CLFrame);
      hWnd    :=FrameWnd;
      hIcon   :=0;
      align   :=alTop;
      GetClientRect(FrameWnd,rc);
//??      height  :=DBReadWord(0,PluginShort,opt_FrmHeight,rc.bottom-rc.top);
      Flags   :=0;//{F_VISIBLE or} F_SHOWTB;
      name.a  :=PluginShort;
      TBName.a:=PluginShort;
    end;
    FrameHeight:=CLFrame.height;

    PWATFrameData(FrameCtrl.CustomData).FrameId:=CallService(MS_CLIST_FRAMES_ADDFRAME,twparam(@CLFrame),0);
    if PWATFrameData(FrameCtrl.CustomData).FrameId>=0 then
    begin
      plStatusHook:=HookEvent(ME_WAT_NEWSTATUS,@NewPlStatus);
    end;
  end;
  result:=FrameWnd<>0;
end;

procedure DestroyFrame;
var
  id:integer;
begin
  if (FrameCtrl<>nil) and (PWATFrameData(FrameCtrl.CustomData).FrameId>=0) then
  begin
    UnhookEvent(plStatusHook);

    id:=PWATFrameData(FrameCtrl.CustomData).FrameId;
    FrameCtrl.Free;
    FrameCtrl:=nil;
    CallService(MS_CLIST_FRAMES_REMOVEFRAME,Id,0);
  end;
end;

const
  opt_ModStatus:PAnsiChar = 'module/frame';

function GetModStatus:integer;
begin
  result:=DBReadByte(0,PluginShort,opt_ModStatus,1);
end;

procedure SetModStatus(stat:integer);
begin
  DBWriteByte(0,PluginShort,opt_modStatus,stat);
end;

// ---------------- base interface procedures ----------------

function InitProc(aGetStatus:boolean=false):integer;
begin
  FrameCtrl:=nil;
  result:=0;
  if aGetStatus then
  begin
    if GetModStatus=0 then
      exit;
  end
  else
    SetModStatus(1);

  result:=ord(CreateFrame(0));
  if result<>0 then
    sic:=HookEvent(ME_SKIN2_ICONSCHANGED,@IconChanged);
end;

procedure DeInitProc(aSetDisable:boolean);
begin
  if aSetDisable then
    SetModStatus(0);

  if sic<>0 then
  begin
    UnhookEvent(sic);
    sic:=0;
  end;
  DestroyFrame;
end;

function AddOptionsPage(var tmpl:pAnsiChar;var proc:pointer;var name:PAnsiChar):integer;
const
  count:integer=2;
begin
  if count=0 then
    count:=2;
  if count=2 then
  begin
    tmpl:='FRAME';
    proc:=@FrameViewDlg;
    name:='Frame (main)';
  end
  else
  begin
    tmpl:='FRAME2';
    proc:=@FrameTextDlg;
    name:='Frame (text)';
  end;

  dec(count);
  result:=count;
end;

var
  Frame:twModule;

procedure Init;
begin
  Frame.Next      :=ModuleLink;
  Frame.Init      :=@InitProc;
  Frame.DeInit    :=@DeInitProc;
  Frame.AddOption :=@AddOptionsPage;
  Frame.Check     :=nil;
  Frame.ModuleName:='Frame';
  ModuleLink      :=@Frame;
end;

begin
  Init;
end.