var
  isAutoHide:boolean;
  
procedure SwitchAutoHide;
begin
  isAutoHide:=not isAutoHide;
  nAutoHide.checked:=isAutoHide;
  SetSettingInt('AutoHide',isAutoHide);
end;

procedure EditCopy;
begin
  ClipBoard.AsText:=edtFind.text;
end;

procedure EditCut;
begin
  edtFind.text:=ClipBoard.AsText;
end;

procedure ShowPreview(value:boolean);
begin
  BeginUpdate;
  if value or not Docking then
    Widget.Height:=255
  else
    Widget.Height:=45;
  lblTitle.visible:=value;
  if value then
  begin
    if trim(edtFind.text)='' then
    begin
      lblTitle.visible:=false;
      showtrayhint('提示','请输入要翻译的单词');
    end
    else
    try
      lblTitle.caption:=edtFind.text;
      lblTitle.hint:='http://dict.cn/search/?q='+lblTitle.caption;
      htmlwin.url:='http://dict.cn/mini.php?q='+lblTitle.caption;
    except
    
    end;
  end;
  imgFlyout.visible:=lblTitle.visible;
  EndUpdate;
  htmlwin.isVisible:=lblTitle.visible;
  if lblTitle.visible then
  begin
    htmlwin.x:=32;
    htmlwin.y:=51;
    //showtrayhint('','set pos');
  end;
end;

//--- Widget移入边栏事件，当Widget被移到边栏上时会触发此事件 ---
procedure OnWidgetDock;
begin
  ShowPreview(false);
end;

//--- Widget移出边栏事件，当Widget被移出边栏时会触发此事件 ---
procedure OnWidgetUnDock;
begin
  ShowPreview(false);
end;

//--- Widget初始化事件，当打开Widget时会触发此事件 ---
procedure OnWidgetInit;
begin
  edtFind.OnEnter:='OnEditFindEnter';
  isAutoHide:=GetSettingInt('AutoHide',1)=1;
  nAutoHide.checked:=isAutoHide;
end;

//--- Widget关闭事件，当关闭Widget时会触发此事件 ---
procedure OnWidgetClose;
begin
end;

//--- 应用程序失去焦点事件，当应用失去当前焦点时触发此事件 ---
procedure OnApplicationDeactivate;
begin
  ShowPreview(false);
end;

procedure OnWidgetMouseLeave(sender);
begin
  if isAutoHide then
    ShowPreview(false);
end;

procedure OnEditFindEnter(sender);
begin
  ShowPreview(true);
end;

procedure BrowseUrl;
begin
  ShellExecute(0,'open',lblTitle.hint,'','',1);
end;

