⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sskinprovider.pas

📁 Alpha Controls.v5.46b Source
💻 PAS
📖 第 1 页 / 共 5 页
字号:
    end;
  end;
end;

function TsSkinProvider.HTProcess(Message : TWMNCHitTest): integer;
const
  BtnSpacing = 1;
var
  p : TPoint;
  cy1, cy2 : integer;
  i, SysBtnCount, BtnIndex : integer;
  GripVisible : boolean;
  R, hrect, vrect : TRect;
  function GetBtnIndex(x : integer) : integer;
  var
    i, c : integer;
  begin
    Result := 0;
    c := 0;
    if (biSystemMenu in Form.BorderIcons) and Assigned(SystemMenu) then begin
      inc(c);
      if Between(x, ButtonClose.Rect.Left, ButtonClose.Rect.Right) then begin// CaptionWidth - SysBorderWidth - l, CaptionWidth - SysBorderWidth - l + w) then begin
        Result := c;
        Exit;
      end;
      if SystemMenu.VisibleMax then begin
        inc(c);
        if Between(x, ButtonMax.Rect.Left, ButtonMax.Rect.Right) then begin
          Result := c;
          Exit;
        end;
      end;
      if SystemMenu.VisibleMin then begin
        inc(c);
        if Between(x, ButtonMin.Rect.Left, ButtonMin.Rect.Right) then begin
          Result := c;
          Exit;
        end;
      end;
      if (biHelp in Form.BorderIcons) then begin
        inc(c);
        if Between(x, ButtonHelp.Rect.Left, ButtonHelp.Rect.Right) then begin
          Result := c;
          Exit;
        end;
      end;
    end;       
    for i := 0 to TitleButtons.Count - 1 do begin
      inc(c);
      if Between(x, TitleButtons[i].BtnData.Rect.Left, TitleButtons[i].BtnData.Rect.Right) then begin
        Result := c;
        Exit;
      end;
    end;
  end;
begin
  p := CursorToPoint(Message.XPos, Message.YPos);
  cy1 := (CaptionHeight - ButtonHeight + SysBorderHeight) div 2;
  cy2 := cy1 + ButtonHeight;

  if Between(p.y, cy1, cy2) then begin // If in buttons
    if Between(p.x, SysBorderWidth, SysBorderWidth + WidthOf(IconRect)) // If system menu icon
      then begin SetHotHT(HTSYSMENU); Result := HTSYSMENU; Exit; end;
    // Title button?
    SysBtnCount := 0;
    if SystemMenu.VisibleClose then begin
      inc(SysBtnCount);
      if SystemMenu.VisibleMax then inc(SysBtnCount);
      if SystemMenu.VisibleMin or IsIconic(Form.Handle) then inc(SysBtnCount);
      if biHelp in Form.BorderIcons then inc(SysBtnCount);
    end;
    BtnIndex := GetBtnIndex(p.x);

    if (BtnIndex > 0) and (BtnIndex <= SysBtnCount) then begin // If system button
      case BtnIndex of
        1 : if SystemMenu.VisibleClose then begin
          SetHotHT(HTCLOSE); Result := HTCLOSE; Exit;
        end;
        2 : begin
          if SystemMenu.VisibleMax then begin
            if (SystemMenu.EnabledMax or (SystemMenu.EnabledRestore and not IsIconic(Form.Handle))) then begin
              SetHotHT(HTMAXBUTTON); Result := HTMAXBUTTON; Exit;
            end
            else begin
              SetHotHT(HTCAPTION); Result := HTCAPTION; Exit;
            end;
          end
          else if (SystemMenu.VisibleMin) or IsIconic(Form.Handle) then begin
            if SystemMenu.EnabledMin then begin
              SetHotHT(HTMINBUTTON); Result := HTMINBUTTON; Exit;
            end
            else begin
              SetHotHT(HTCAPTION); Result := HTCAPTION; Exit;
            end;
          end
          else if (biHelp in Form.BorderIcons) then begin
            SetHotHT(HTHELP); Result := HTHELP; EXIT;
          end;
        end;
        3 : begin
          if (SystemMenu.VisibleMin) or IsIconic(Form.Handle) then begin
            if not IsIconic(Form.Handle) then begin
              if SystemMenu.EnabledMin then begin
                SetHotHT(HTMINBUTTON); Result := HTMINBUTTON; Exit;
              end
              else begin
                SetHotHT(HTCAPTION); Result := HTCAPTION; Exit;
              end;
            end
            else begin
              SetHotHT(HTMINBUTTON); Result := HTMINBUTTON; Exit;
            end;
          end
          else if (biHelp in Form.BorderIcons) {and SystemMenu.VisibleMax} then begin
            SetHotHT(HTHELP); Result := HTHELP; EXIT;
          end;
        end;
        4 : if (biHelp in Form.BorderIcons) and SystemMenu.VisibleMax then begin
          SetHotHT(HTHELP); Result := HTHELP; EXIT;
        end;
      end;
    end
    else if (BtnIndex > SysBtnCount) and (BtnIndex <= TitleButtons.Count + SysBtnCount) then begin // UDF button
      BtnIndex := BtnIndex - SysBtnCount - 1;
      if TitleButtons.Items[BtnIndex].Enabled then begin
        Result := HTUDBTN + BtnIndex;
        SetHotHT(Result);
      end
      else begin
        Result := HTCAPTION;
      end;
      Exit;
    end
    else begin
      Result := HTCAPTION;
      Exit;
    end;
  end
  else begin
    if (GripMode = gmRightBottom) then begin
      GripVisible := True;
    end
    else if Assigned(ListSW) and Assigned(ListSW.sbarVert) and ListSW.sbarVert.fScrollVisible and ListSW.sbarHorz.fScrollVisible then begin
      Ac_GetHScrollRect(ListSW, Form.Handle, hrect);
      Ac_GetVScrollRect(ListSW, Form.Handle, vrect);
      GetWindowRect(Form.Handle, R);
      GripVisible := PtInRect(Rect(hrect.Right - R.Left, hrect.Top - R.Top, vrect.Right - R.Left, hrect.Bottom - R.Top), p)
    end
    else GripVisible := False;
    if GripVisible then begin
      i := FCommonData.SkinManager.GetMaskIndex(FCommonData.SkinManager.ConstData.IndexGLobalInfo, s_GlobalInfo, s_GripImage);
      if FCommonData.SkinManager.IsValidImgIndex(i) then begin
        if (p.y > RBGripPoint(i).y) and (p.x > RBGripPoint(i).x) then begin
          Result := HTBOTTOMRIGHT; Exit;
        end;
      end;
    end;
    // MDI child buttons
    if MDIButtonsNeeded then begin
      if PtInRect(MDICLose.Rect, p) then begin
        SetHotHT(HTCHILDCLOSE); Result := HTCHILDCLOSE; Exit;
      end else
      if PtInRect(MDIMax.Rect, p) then begin
        SetHotHT(HTCHILDMAX); Result := HTCHILDMAX; Exit;
      end else
      if PtInRect(MDIMin.Rect, p) then begin
        SetHotHT(HTCHILDMIN); Result := HTCHILDMIN; Exit;
      end;
    end else SetHotHT(0);
  end;
  if (Form.WindowState = wsMaximized) and AboveBorder(Message) then Result := HTTRANSPARENT else Result := Message.Result;
end;

procedure TsSkinProvider.NewWndProc(var Message: TMessage);
var
  DC, SavedDC : hdc;
  mi :  TMenuItem;
  X, Y, i : integer;
  p : TPoint;
  UpdateClient : boolean;
  cR : TRect;
  procedure HandleEdge(var Edge: Integer; SnapToEdge: Integer; SnapDistance: Integer = 0);
  begin
    if (Abs(Edge + SnapDistance - SnapToEdge) < FSnapBuffer) then Edge := SnapToEdge - SnapDistance;
  end;
  procedure UpdateMainForm;
  begin
    if Assigned(MDISkinProvider) then begin
      TsSkinProvider(MDISkinProvider).FCommonData.BeginUpdate;
      Application.ProcessMessages;
      TsSkinProvider(MDISkinProvider).FCommonData.BGChanged := True;
      TsSkinProvider(MDISkinProvider).FLinesCount := -1;
      if Assigned(TsSkinProvider(MDISkinProvider).MDIForm) then TsMDIForm(TsSkinProvider(MDISkinProvider).MDIForm).UpdateMDIIconItem;
      TsSkinProvider(MDISkinProvider).FCommonData.EndUpdate;
      RedrawWindow(TsSkinProvider(MDISkinProvider).Form.Handle, nil, 0,
        RDW_ERASE or RDW_FRAME or RDW_INTERNALPAINT or RDW_INVALIDATE or RDW_UPDATENOW);
    end
  end;
begin
{$IFDEF LOGGED}
  if Assigned(Form) and (Form.FormStyle <> fsMdiChild) then begin
    AddToLog(Message);
  end;
{$ENDIF}
{$IFDEF LOGGED}
//  if Form.Tag = 1 then begin
//    if Form.Parent <> nil then AddToLog(Message, 'Docked  - ') else AddToLog(Message, 'Undocked  - ');
//  end;
//  AddToLog(Message);
{$ENDIF}
  if Message.Msg = SM_ALPHACMD then case Message.WParamHi of
    AC_REMOVESKIN : begin
      if (LongWord(Message.LParam) = LongWord(SkinData.SkinManager)) then begin
        if ListSW <> nil then FreeAndNil(ListSW);
        AdapterRemove;
        CommonMessage(Message, FCommonData);
        FLinesCount := -1;
        AlphaBroadCast(Form, Message);
        if Assigned(SkinData.SkinManager) then begin
          DeleteUnusedBmps(True);
        end;
        if (Form <> nil) and not (csDestroying in Form.ComponentState) then begin
          if Assigned(SkinData.SkinManager) then begin
            InitMenuItems(False);
            if (TForm(Form).BorderIcons <> []) then SetWindowLong(Form.Handle, GWL_STYLE, GetWindowLong(Form.Handle, GWL_STYLE) or WS_SYSMENU);
            if (Form.FormStyle = fsMDIForm) and (MDIForm <> nil) then HookMDI(False);
            if HaveBorder(Self) and not InMenu then SetWindowRgn(Form.Handle, 0, True); // Return standard kind
          end;
          if UseGlobalColor and not SkinData.CustomColor then Form.Color := clBtnFace else if Form <> nil then Form.Repaint;
          FCommonData.FCacheBmp.Width := 0;
          FCommonData.FCacheBmp.Height := 0;
        end;
      end
      else AlphaBroadCast(Form, Message);
      Exit
    end;
    AC_SETNEWSKIN : if not (csDestroying in Form.ComponentState) and Assigned(SkinData) then begin
      if (LongWord(Message.LParam) = LongWord(SkinData.SkinManager)) and not Assigned(SystemMenu) then PrepareForm
    end;
    AC_GETAPPLICATION : begin Message.Result := longint(Application); Exit end;
    AC_PARENTCLOFFSET : begin Message.Result := MakeLong(OffsetX, OffsetY); Exit end;
    AC_CTRLHANDLED : begin Message.LParam := 1; Message.Result := 1; Exit end;
  end;

  if (csDestroying in Form.ComponentState) or not FCommonData.Skinned(True) then begin
    if Message.Msg = SM_ALPHACMD then case Message.WParamHi of
      AC_GETPROVIDER : begin Message.Result := longint(Self); Exit end; // Used for menuline init
      AC_SETNEWSKIN : if not (csDestroying in Form.ComponentState) and Assigned(SkinData) then begin
        if (LongWord(Message.LParam) = LongWord(SkinData.SkinManager)) then begin
          DeleteUnusedBmps(True);
          FCommonData.UpdateIndexes;

          if (SkinData.SkinManager <> nil) then begin
            UpdateIconsIndexes;
            if TForm(Form).BorderIcons <> [] then SetWindowLong(Form.Handle, GWL_STYLE, GetWindowLong(Form.Handle, GWL_STYLE) and not WS_SYSMENU);
            if (Form.FormStyle = fsMDIForm) and (Screen.ActiveForm = Form.ActiveMDIChild) then FormActive := True;
            // Menus skinning
            if not (csLoading in SkinData.SkinManager.ComponentState) then
              InitMenuItems(True); // Update after skinning in run-time
            // Menu Line refresh
            FCommonData.BGChanged := True;
            FLinesCount := -1;
            if (TForm(Form).FormStyle = fsMDIForm) then begin
              if not Assigned(MDIForm) then HookMDI;
            end;
            if UseGlobalColor and not SkinData.CustomColor then Form.Color := SkinData.SkinManager.GetGlobalColor;
          end;
          if Adapter = nil then AdapterCreate else Adapter.AddAllItems;
        end;
        AlphaBroadCast(Form, Message);
        Exit;
      end
    end;
    OldWndProc(Message);
    if (Message.Msg = WM_NCDESTROY) and (Form.FormStyle = fsMDIChild) then begin
      if Assigned(MDISkinProvider) and Assigned(TsSkinProvider(MDISkinProvider).MDIForm) and not (csDestroying in TsSkinProvider(MDISkinProvider).ComponentState) and
          not (csDestroying in TsSkinProvider(MDISkinProvider).Form.ComponentState) and TsSkinProvider(MDISkinProvider).SkinData.Skinned(True) then begin
        TsSkinProvider(MDISkinProvider).RepaintMenu;
        if TsSkinProvider(MDISkinProvider).Form.ActiveMDIChild = nil
          then RedrawWindow(TsSkinProvider(MDISkinProvider).Form.ClientHandle, nil, 0, RDW_ERASE or RDW_FRAME or RDW_INTERNALPAINT or RDW_INVALIDATE or RDW_UPDATENOW);
      end;
    end;
  end
  else begin
    if Message.Msg = SM_ALPHACMD then case Message.WParamHi of
      AC_CONTROLLOADED : if (Form <> nil) and not (csLoading in Form.ComponentState) and (Message.LParam <> 0) then begin
        if Adapter <> nil then Adapter.AddAllItems(TWinControl(Message.LParam));
      end;
      AC_SETGRAPHCONTROL : FCommonData.GraphControl := pointer(Message.LParam);
      AC_PREPARING : if (FCommonData <> nil) then Message.LParam := integer({FCommonData.BGChanged or} FCommonData.Updating);
      AC_UPDATING : begin
        FCommonData.Updating := Message.WParamLo = 1;
        if FCommonData.Updating then FCommonData.BGChanged := True;
      end;
      AC_GETCACHE : begin
        if (csLoading in ComponentState) then Exit;
        GlobalCacheInfo := MakeCacheInfo(FCommonData.FCacheBmp, OffsetX, OffsetY);
      end;
      AC_REFRESH : if (LongWord(Message.LParam) = LongWord(SkinData.SkinManager)) then begin
        if Adapter = nil then AdapterCreate else Adapter.AddAllItems;
        RefreshFormScrolls(Self, ListSW, False);

        FCommonData.BGChanged := True;
        FLinesCount := -1;
        if Assigned(TitleBG) then FreeAndNil(TitleBG);
        if not (csLoading in SkinData.SkinManager.ComponentState) then
          InitMenuItems(SkinData.Skinned);
        if HaveBorder(Self) then RgnChanged := True;
        if not Form.Visible then Exit;
        SendMessage(Form.Handle, WM_NCPAINT, 0, 0);

        if (Form.FormStyle = fsMDIForm) and Assigned(Form.ActiveMDIChild) and (Form.ActiveMDIChild.WindowState = wsMaximized) then begin
          SendMessage(Form.ActiveMDIChild.Handle, WM_PAINT, 0, 0);
        end
        else begin
          SendMessage(Form.Handle, WM_PAINT, 0, 0);
          if Form.FormStyle = fsMDIForm then begin

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -