ksskinforms.pas

来自「小区水费管理系统源代码水费收费管理系统 水费收费管理系统」· PAS 代码 · 共 822 行 · 第 1/2 页

PAS
822
字号
  if UseSkin then
  begin
    if (FSkinClient <> nil) then
    begin
      FSkinClient.Active := FormActive;
      MoveWindowOrg(Canvas.Handle, -FSkinClient.Left, -FSkinClient.Top);
      FSkinClient.Draw(Canvas);
      MoveWindowOrg(Canvas.Handle, FSkinClient.Left, FSkinClient.Top);
    end
    else
      if FSkinForm <> nil then
      begin
        FSkinForm.Active := FormActive;
        FSkinForm.Draw(Canvas);
      end
  end
  else
    inherited ;
end;

procedure TSeSkinForm.PaintNonClientArea(Canvas: TCanvas);
var
  SkinObject: TSeSkinObject;
  Buffer: TSeBitmap;
  BufferCanvas: TCanvas;
begin
  if UseSkin and (FSkinForm <> nil) then
  begin
    if (Form <> nil) and (THackForm(Form).FormStyle = fsMDIChild) and (WindowState = kwsMaximized) then
    begin
      inherited ;
      Exit;
    end;
    if BorderStyle = kbsNone then
    begin
      inherited ;
      Exit;
    end;

    FSkinForm.Active := FormActive;
    { Set skinobjects state }
    case WindowState of
      kwsNormal: FSkinForm.State := ssNormal;
      kwsMaximized: FSkinForm.State := ssMaximized;
      kwsMinimized: FSkinForm.State := ssMinimized;
      kwsRollup: FSkinForm.State := ssRollup;
      kwsTray: FSkinForm.State := ssMinimized;
    end;
    { Set title text }
    if FSkinTitle <> nil then
      FSkinTitle.Text := Form.Caption;
    { Draw }
    if FSkinClient <> nil then
      FSkinClient.Visible := false;

    { Draw }
    if Performance = ksfpNoBuffer then
    begin
      if FSkinClient <> nil then
      begin
        { Buffering caption drawing }
        Buffer := TSeBitmap.Create;
        Buffer.SetSize(Width, FSkinClient.Top);
        Buffer.Clear(ckTransparent);

        BufferCanvas := TCanvas.Create;
        BufferCanvas.Handle := Buffer.DC;
        FSkinForm.Draw(BufferCanvas);
        BufferCanvas.Handle := 0;
        BufferCanvas.Free;

        Buffer.Draw(Canvas, 0, 0, true);
        Buffer.Free;

        { Draw border }
        ExcludeClipRect(Canvas.Handle, 0, 0, Width, FSkinClient.Top);
        FSkinForm.Draw(Canvas);
      end
      else
        FSkinForm.Draw(Canvas);
    end
    else
      FSkinForm.Draw(Canvas);

    if FSkinClient <> nil then
      FSkinClient.Visible := true;
  end
  else
    inherited ;
end;

function TSeSkinForm.GetCaptionButtonRect(Button: TSeBorderIcon): TRect;
begin
  if UseSkin then
  begin
    Result := Rect(0, 0, 0, 0);
  end
  else
    Result := inherited GetCaptionButtonRect(Button);
end;

function TSeSkinForm.GetClientBounds: TRect;
begin
  if ((Form <> nil) and (THackForm(Form).FormStyle = fsMDIChild) and (WindowState = kwsMaximized)) or not UseSkin then
  begin
    Result := inherited GetClientBounds;
    Exit;
  end;

  if BorderStyle = kbsNone then
    Result := inherited GetClientBounds
  else
    if FSkinClient <> nil then
    begin
      if FSkinClient.Left * FSkinClient.Top = 0 then
        Result := inherited GetClientBounds
      else
        Result := FSkinClient.BoundsRect
    end
    else
      Result := Rect(0, 0, Width, Height);
end;

function TSeSkinForm.GetHitTest(X, Y: integer): TSeHitTest;
var
  SkinObject: TSeSkinObject;
  StatusBar: TSeCustomStatusBar;
  R: TRect;
begin
  Result := khtClient;

  if UseSkin then
  begin
    if FSkinForm <> nil then
    begin
      SkinObject := FSkinForm.FindObjectByPoint(Point(X, Y));
      if SkinObject <> nil then
      begin
        case SkinObject.Kind of
          skClient: Result := khtClient;
          skCaption, skTitle: Result := khtCaption;
          skTop: Result := khtTop;
          skTopLeft: Result := khtTopLeft;
          skTopRight: Result := khtTopRight;
          skLeft: Result := khtLeft;
          skRight: Result := khtRight;
          skBottom: Result := khtBottom;
          skBottomLeft: Result := khtBottomLeft;
          skBottomRight: Result := khtBottomRight;
          skSysButton: Result := khtNonClient;
        end;
      end;
    end
    else
      Result := khtClient;

    { StatusBar Grip }
    StatusBar := GetStatusBar(Self);
    if StatusBar <> nil then
    begin
      R := TSeCustomStatusBarHack(StatusBar).GetGripperRect;
      R.TopLeft := NormalizePoint(StatusBar.ClientToScreen(R.TopLeft));
      R.BottomRight := NormalizePoint(StatusBar.ClientToScreen(R.BottomRight));

      if PtInRect(R, Point(X, Y)) then
        Result := khtBottomRight;
    end;
  end
  else
    Result := inherited GetHitTest(X, Y);
end;

function TSeSkinForm.GetMaximizedRect: TRect;
var
  R: TRect;
begin
  if UseSkin then
  begin
    if StayOnTop then
      R := Rect(0, 0, 10000, 10000) 
    else
      SystemParametersInfo(SPI_GETWORKAREA, 0, @R, 0);

    { for DualMonotors }
    if (Form <> nil) and (Form.Monitor <> nil) then
      with Form.Monitor do
        IntersectRect(R, R, Rect(Left, Top, Left + Width, Top + Height));

    Result := R;

    if (Form <> nil) and (THackForm(Form).FormStyle = fsMDIChild) then
      Result := inherited GetMaximizedRect;
  end
  else
    Result := inherited GetMaximizedRect;
end;

function TSeSkinForm.GetMaxTrackSize: TPoint;
var
  R: TRect;
begin
  if UseSkin then
  begin
    if StayOnTop then
      R := Rect(0, 0, Screen.Width, Screen.Height) 
    else
      SystemParametersInfo(SPI_GETWORKAREA, 0, @R, 0);
    Result := Point(RectWidth(R), RectHeight(R));

    if (Form <> nil) and (THackForm(Form).FormStyle = fsMDIChild) then
      Result := inherited GetMaxTrackSize;

    if (Constraints.MaxWidth <> 0) then
      Result.X := Constraints.MaxWidth;
    if (Constraints.MaxHeight <> 0) then
      Result.Y := Constraints.MaxHeight;
  end
  else
    Result := inherited GetMaxTrackSize;
end;

function TSeSkinForm.GetMinimizedRect: TRect;
begin
  Result := inherited GetMinimizedRect;
end;

function TSeSkinForm.GetMinTrackSize: TPoint;
begin
  Result := inherited GetMinTrackSize;
end;

procedure TSeSkinForm.ChangeSize;
begin
  inherited ChangeSize;
end;

function TSeSkinForm.GetRegion: HRgn;
begin
  if UseSkin and (FSkinForm <> nil) then
  begin
    if ((Form <> nil) and (THackForm(Form).FormStyle = fsMDIChild) and
       (WindowState = kwsMaximized)) or (BorderStyle = kbsNone) then
    begin
      if FSkinClient <> nil then
        FSkinClient.BoundsRect := Rect(0, 0, Width, Height);

      Result := inherited GetRegion;

      Exit
    end;

    if FSkinClient <> nil then
      FSkinForm.BoundsRect := Rect(0, 0, Width, Height);
    { Update linked object }
    UpdateLinkedObject;
    { Result }
    Result := FSkinForm.GetRegion;
  end
  else
    Result := inherited GetRegion;
end;

function TSeSkinForm.GetRollupRect: TRect;
begin
  Result := inherited GetRollupRect;
end;

procedure TSeSkinForm.NCMouseDown(Button: TMouseButton; Shift: TShiftState;
  X, Y: integer);
var
  SkinObject: TSeSkinObject;
begin
  inherited;

  if UseSkin and (FSkinForm <> nil) then
  begin
    SkinObject := FSkinForm.FindObjectByPoint(Point(X, Y));
    if SkinObject <> nil then
    begin
      if (ssDouble in Shift) then
        SkinObject.MouseDouble(Button, X - SkinObject.Left, Y - SkinObject.Top)
      else
        SkinObject.MouseDown(Button, X - SkinObject.Left, Y - SkinObject.Top);
    end;

    FDownObject := SkinObject;
  end;
end;

procedure TSeSkinForm.NCMouseMove(Shift: TShiftState; X, Y: integer);
var
  SkinObject: TSeSkinObject;
begin
  inherited;
  if UseSkin and (FSkinForm <> nil) then
  begin
    SkinObject := FSkinForm.FindObjectByPoint(Point(X, Y));
    if SkinObject <> nil then
      if ((ssLeft in Shift) or (ssRight in Shift)) then
      begin
        if FDownObject = SkinObject then
          SkinObject.MouseMove(Shift, X - SkinObject.Left, Y - SkinObject.Top);
      end
      else
        SkinObject.MouseMove(Shift, X - SkinObject.Left, Y - SkinObject.Top);
  end;
end;

procedure TSeSkinForm.NCMouseUp(Button: TMouseButton; Shift: TShiftState;
  X, Y: integer);
var
  SkinObject: TSeSkinObject;
begin
  inherited;
  if UseSkin and (FSkinForm <> nil) then
  begin
    SkinObject := FSkinForm.FindObjectByPoint(Point(X, Y));
    if SkinObject <> nil then
      if FDownObject = SkinObject then
        SkinObject.MouseUp(Button, X - SkinObject.Left, Y - SkinObject.Top);

    FDownObject := nil;
  end;
end;

{ VCL overrides ===============================================================}

procedure TSeSkinForm.Notification(AComponent: TComponent;
  Operation: TOperation);
begin
  inherited;
  if (Operation = opRemove) and (AComponent = FSkinEngine) then
    FSkinEngine := nil;
end;

{ Properties ==================================================================}

function TSeSkinForm.GetVersion: TSeSkinVersion;
begin
  Result := sSeSkinVersion;
end;

procedure TSeSkinForm.SetSkinEngine(const Value: TSeSkinEngine);
var
  R: TRect;
begin
  FSkinEngine := Value;

  if (FSkinEngine <> nil) and (FSkinEngine.SkinSource <> nil) and
     (not FSkinEngine.SkinSource.IsChanging) and
     (FSkinEngine.SkinSource.Count > 0) then
  begin
    if FSkinForm <> nil then FSkinForm.Free;
    FSkinForm := nil;
    FSkinClient := nil;
    FSkinTitle := nil;

    if (FSkinObject = 'Form') and (FSkinEngine.SkinSource.Form <> nil) then
      FSkinForm := FSkinEngine.SkinSource.Form.CreateCopy(nil)
    else
      if FSkinEngine.SkinSource.GetObjectByName(FSkinObject) <> nil then
        FSkinForm := FSkinEngine.SkinSource.GetObjectByName(FSkinObject).CreateCopy(nil)
      else
        FSkinForm := FSkinEngine.SkinSource.Form.CreateCopy(nil);

    if FSkinForm <> nil then
    begin
      FSkinForm.ParentControl := TWinControl(Owner);
      FSkinTitle := FSkinForm.FindObjectByKind(skTitle);
      FSkinClient := FSkinForm.FindObjectByKind(skClient);
      { Set form properties }
      if Form <> nil then
      begin
        Form.Font := FSkinForm.Font;
        Form.Color := FSkinForm.Color;
      end;
    end;
  end
  else
  begin
    if FSkinForm <> nil then FSkinForm.Free;
    FSkinClient := nil;
    FSkinTitle := nil;
    if Form <> nil then
      Form.Color := clBtnFace;
  end;

  { No resizeable form }
  if UseSkin and (FSkinForm.FindObjectByKind(skClient) = nil) then
    Form.SetBounds(Form.Left, Form.Top, FSkinForm.Width, FSkinForm.Height);

  { Update }
  if not (csLoading in ComponentState) then
    Update;
end;

procedure TSeSkinForm.SetVersion(const Value: TSeSkinVersion);
begin
end;

procedure TSeSkinForm.SetSkinObject(const Value: string);
begin
  FSkinObject := Value;
end;

initialization
{$IFDEF SkinTrial}
  ShowVersion2;
{$ENDIF}
end.

⌨️ 快捷键说明

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