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

📄 scommondata.pas

📁 Alpha Controls 界面控件包
💻 PAS
📖 第 1 页 / 共 3 页
字号:
  BGChanged := True;
  if Assigned(SkinManager) then SkinIndex := SkinManager.GetSkinIndex(SkinSection) else SkinIndex := -1;

  if SkinIndex > -1 then begin
    BorderIndex := SkinManager.GetMaskIndex(SkinIndex, SkinSection, s_BordersMask);
    Texture := SkinManager.GetTextureIndex(SkinIndex, SkinSection, s_Pattern);
    HotTexture := SkinManager.GetTextureIndex(SkinIndex, SkinSection, s_HotPattern);
{    if (SkinManager.gd[SkinIndex].ImagePercent = 0) and SkinManager.IsValidImgIndex(Texture) and (SkinManager.ma[Texture].DrawMode in [ord(ord(fmDisTiled))])
      then SkinManager.gd[SkinIndex].ImagePercent := -1;
    if (SkinManager.gd[SkinIndex].HotImagePercent = 0) and SkinManager.IsValidImgIndex(HotTexture) and (SkinManager.ma[HotTexture].DrawMode in [ord(ord(fmDisTiled))])
      then SkinManager.gd[SkinIndex].HotImagePercent := -1;}
  end
  else begin
    Texture := -1;
    HotTexture := -1;
  end;
end;

function CommonWndProc(var Message: TMessage; SkinData : TsCommonData) : boolean;
var
  i : integer;
begin
  Result := False;
  if SkinData <> nil then with SkinData do begin
    if Message.Msg = SM_ALPHACMD then begin // Common messages for all components
      Result := CommonMessage(Message, SkinData);
    end
    else case Message.Msg of
{$IFDEF CHECKXP}
      WM_UPDATEUISTATE : if SkinData.Skinned
        then Result := True
        else if UseThemes and (SkinData.FOwnerControl <> nil) and (SkinData.FOwnerControl is TWinControl)
          then SetWindowTheme(TWinControl(SkinData.FOwnerControl).Handle, nil, nil);
{$ENDIF}
      WM_KILLFOCUS : if Assigned(FOwnerControl) and (FOwnerControl is TWinControl) and TWinControl(FOwnerControl).CanFocus and TWinControl(FOwnerControl).TabStop then begin
        BGChanged := True;
        FFocused := False;
      end;
      WM_PARENTNOTIFY : if Assigned(FOwnerControl) and (FOwnerControl is TWinControl) and
                            (Message.WParam and $FFFF = WM_CREATE) or (Message.WParam and $FFFF = WM_DESTROY) then begin
        if Message.WParamLo = WM_CREATE then AddToAdapter(TWinControl(FOwnerControl))
      end;
      WM_SETFOCUS: if Assigned(FOwnerControl) and (FOwnerControl is TWinControl) and TWinControl(FOwnerControl).CanFocus and TWinControl(FOwnerControl).TabStop then begin
        BGChanged := True;
        FFocused := True;
      end;
      CM_ENABLEDCHANGED, WM_FONTCHANGE: begin
        FMouseAbove := False;     // v4.09
        FFocused := False;        // v4.09
      end;
      CM_MOUSEENTER : if not (csDesigning in FOwnerControl.ComponentState) then begin
        if (FOwnerControl <> nil) and (FOwnerControl is TWinControl) and (DefaultManager <> nil) then begin
          for i := 0 to TWinControl(FOwnerControl).ControlCount - 1 do begin
            if (TWinControl(FOwnerControl).Controls[i] is TsSpeedButton) and (TWinControl(FOwnerControl).Controls[i] <> FOwnerControl) and (TWinControl(FOwnerControl).Controls[i] <> Pointer(Message.LParam)) and TsSpeedButton(TWinControl(FOwnerControl).Controls[i]).SkinData.FMouseAbove then begin
              TWinControl(FOwnerControl).Controls[i].Perform(CM_MOUSELEAVE, 0, 0) // !!!!
            end;
          end;
          if not (COC in sForbidMouse) then FMouseAbove := True;
          DefaultManager.ActiveControl := TWinControl(FOwnerControl).Handle;
        end else if not (COC in sForbidMouse) then FMouseAbove := True;
      end;
      CM_MOUSELEAVE : if not (csDesigning in FOwnerControl.ComponentState) then begin
        if not (COC in sForbidMouse) then FMouseAbove := False;
      end;
      WM_SIZE : if Skinned then begin
        BGChanged := True;
        if (FOwnerControl <> nil) and (FOwnerControl is TWinControl) then begin // v4.27
          if Skinned and (Length(SkinData.SkinManager.gd) > SkinIndex) and (SkinData.SkinManager.gd[SkinIndex].GradientPercent > 0) then begin
            for i := 0 to TWinControl(SkinData.FOwnerControl).ControlCount - 1 do
              if (i < TWinControl(SkinData.FOwnerControl).ControlCount) and
                not (csDestroying in TWinControl(SkinData.FOwnerControl).Controls[i].ComponentState) and
                  not ((akRight in TWinControl(SkinData.FOwnerControl).Controls[i].Anchors) or
                    (akBottom in TWinControl(SkinData.FOwnerControl).Controls[i].Anchors)) // v4.31
              then TWinControl(FOwnerControl).Controls[i].Perform(SM_ALPHACMD, MakeWParam(1, AC_SETCHANGEDIFNECESSARY), 0);
          end;
        end;
      end;
      WM_MOVE : if SkinData.RepaintIfMoved then begin
        if (SkinData.FOwnerControl <> nil) then SkinData.FOwnerControl.Perform(SM_ALPHACMD, MakeWParam(1, AC_SETCHANGEDIFNECESSARY), 0) // v4.35
      end;
    end;
  end;
end;

procedure CopyWinControlCache(Control : TWinControl; SkinData : TsCommonData; SrcRect, DstRect : TRect; DstDC : HDC; UpdateCorners : boolean; OffsetX : integer = 0; OffsetY : integer = 0);
var
  SaveIndex : HDC;
  i : integer;
  Child : TControl;
begin
  if UpdateCorners then sAlphaGraph.UpdateCorners(SkinData, 0);
  SaveIndex := SaveDC(DstDC);
  IntersectClipRect(DstDC, DstRect.Left, DstRect.Top, DstRect.Right, DstRect.Bottom);
  try
    for i := 0 to Control.ControlCount - 1 do begin
      Child := Control.Controls[i];
      if not ((Control.Controls[i] is TGraphicControl) and StdTransparency) and
          Child.Visible and
            (Control.Controls[i].Left < DstRect.Right) and
              (Control.Controls[i].Top < DstRect.Bottom) and
                (Control.Controls[i].Left + Control.Controls[i].Width > DstRect.Left) and
                  (Control.Controls[i].top + Control.Controls[i].Height > DstRect.Top) and
                    ((csOpaque in Control.Controls[i].ControlStyle) or
                     (Control.Controls[i] is TGraphicControl) or
                     (csDesigning in Control.ComponentState) {or (Control.Controls[i] is TWinControl)}) then begin

        ExcludeClipRect(DstDC, Control.Controls[i].Left + OffsetX, Control.Controls[i].Top + OffsetY,
                          Control.Controls[i].Left + Control.Controls[i].Width + OffsetX,
                          Control.Controls[i].Top + Control.Controls[i].Height + OffsetY);
      end;
    end;
    BitBlt(DstDC, DstRect.Left, DstRect.Top, WidthOf(DstRect), HeightOf(DstRect), SkinData.FCacheBmp.Canvas.Handle, SrcRect.Left, SrcRect.Top, SRCCOPY); // v4.22
  finally
    RestoreDC(DstDC, SaveIndex);
  end;
end;

procedure CopyHwndCache(hwnd : THandle; SkinData : TsCommonData; SrcRect, DstRect : TRect; DstDC : HDC; UpdateCorners : boolean; OffsetX : integer = 0; OffsetY : integer = 0); overload;
var
  SaveIndex : HDC;
  hctrl : THandle;
  R, hR : TRect;
  Index : integer;
begin
  if UpdateCorners then sAlphaGraph.UpdateCorners(SkinData, 0);
  SaveIndex := SaveDC(DstDC);
  IntersectClipRect(DstDC, DstRect.Left, DstRect.Top, DstRect.Right, DstRect.Bottom);
  try        
    hctrl := GetTopWindow(hwnd);
    GetWindowRect(hwnd, R);

    while (hctrl <> 0) do begin
      if IsWindowVisible(hctrl) then begin
        GetWindowRect(hctrl, hR);
        OffsetRect(hR, -R.Left - OffsetX, -R.Top - OffsetY);
        if GetWindowLong(hctrl, GWL_STYLE) and BS_GROUPBOX = BS_GROUPBOX then begin
          if DefaultManager <> nil then begin
            Index := DefaultManager.GetSkinIndex(s_GroupBox);
            Index := DefaultManager.GetMaskIndex(Index, s_GroupBox, s_BordersMask);
            ExcludeClipRect(DstDC, hR.Left, hR.Top, hR.Right, hR.Top + SendAMessage(hctrl, AC_GETSERVICEINT));
            ExcludeClipRect(DstDC, hR.Left, hR.Top, hR.Left + DefaultManager.MaskWidthLeft(Index), hR.Bottom);
            ExcludeClipRect(DstDC, hR.Right - DefaultManager.MaskWidthRight(Index), hR.Top, hR.Right, hR.Bottom);
            ExcludeClipRect(DstDC, hR.Left, hR.Bottom - DefaultManager.MaskWidthBottom(Index), hR.Right, hR.Bottom);
          end;
        end
        else ExcludeClipRect(DstDC, hR.Left, hR.Top, hR.Right, hR.Bottom);
      end;
      hctrl := GetNextWindow(hctrl, GW_HWNDNEXT);
    end;
    BitBlt(DstDC, DstRect.Left, DstRect.Top, WidthOf(DstRect), HeightOf(DstRect), SkinData.FCacheBmp.Canvas.Handle, SrcRect.Left, SrcRect.Top, SRCCOPY); // v4.22
  finally
    RestoreDC(DstDC, SaveIndex);
  end;
end;

{ TsBoundLabel }

procedure TsBoundLabel.AlignLabel;
begin
  if Assigned(FTheLabel) and FTheLabel.Visible then begin
    FTheLabel.AutoSize := True;
    case Layout of
      sclLeft : begin
        FTheLabel.Left := FTheLabel.FocusControl.Left - FTheLabel.Width - 4 - Indent;
        FTheLabel.Top := FTheLabel.FocusControl.Top +
                         (FTheLabel.FocusControl.Height - FTheLabel.Height) div 2 - 1;// + 6;
      end;
      sclTopLeft : begin
        FTheLabel.Left := FTheLabel.FocusControl.Left;
        FTheLabel.Top := FTheLabel.FocusControl.Top - FTheLabel.Height - Indent;
      end;
      sclTopCenter : begin
        FTheLabel.Left := FTheLabel.FocusControl.Left + (FTheLabel.FocusControl.Width - FTheLabel.Width) div 2;
        FTheLabel.Top := FTheLabel.FocusControl.Top - FTheLabel.Height - Indent;
      end;
      sclTopRight : begin
        FTheLabel.Left := FTheLabel.FocusControl.Left + FTheLabel.FocusControl.Width - FTheLabel.Width;
        FTheLabel.Top := FTheLabel.FocusControl.Top - FTheLabel.Height - Indent;
      end;
    end;
    if FMaxWidth <> 0 then begin
      FTheLabel.AutoSize := False;
      FTheLabel.Width := FMaxWidth;
      FTheLabel.WordWrap := True;
      FTheLabel.Height := Max(FTheLabel.Height, FTheLabel.FocusControl.Height);
    end;
  end;
end;

constructor TsBoundLabel.Create(AOwner: TObject; CommonData : TsCommonData);
begin
  FCommonData := CommonData;
  FFont := TFont.Create;
  FActive := False;
end;

destructor TsBoundLabel.Destroy;
begin
  FreeAndNil(FFont);
  if Assigned(FTheLabel) then FreeAndNil(FTheLabel);
  inherited Destroy;
end;

function TsBoundLabel.GetFont: TFont;
begin
  if Assigned(FTheLabel) and Assigned(FTheLabel.Font) then Result := FTheLabel.Font else Result := FFont;
end;

function TsBoundLabel.GetUseSkin: boolean;
begin
  if Assigned(FTheLabel) then Result := FTheLabel.UseSkinColor else Result := True;
end;

procedure TsBoundLabel.SetActive(const Value: boolean);
begin
  if FActive = Value then Exit;
  if Value then begin
    FActive := True;
    FTheLabel := TsEditLabel.InternalCreate(FCommonData.FOwnerControl{.Parent}, Self);
    FTheLabel.Visible := False;
    FTheLabel.Parent := FCommonData.FOwnerControl.Parent;
    FTheLabel.FocusControl := TWinControl(FCommonData.FOwnerControl);

    UpdateAlignment;
    FTheLabel.Name := FCommonData.FOwnerControl.Name + 'Label';
    if FText = '' then FText := FCommonData.FOwnerControl.Name;
    FTheLabel.Caption := FText; // Serge
    FTheLabel.Visible := FCommonData.FOwnerControl.Visible or (csDesigning in FTheLabel.ComponentState);
    FTheLabel.Enabled := FCommonData.FOwnerControl.Enabled;
    AlignLabel;
  end
  else begin
    if Assigned(FTheLabel) then FreeAndNil(FTheLabel);
    FActive := False;
  end;
end;

procedure TsBoundLabel.SetFont(const Value: TFont);
begin
  FTheLabel.Font.Assign(Value);
  FTheLabel.ParentFont := False;
  AlignLabel;
end;

procedure TsBoundLabel.SetIndent(const Value: integer);
begin
  if FIndent <> Value then begin
    FIndent := Value;
    if Active then AlignLabel;
  end;
end;

procedure TsBoundLabel.SetLayout(const Value: TsCaptionLayout);
begin
  if FLayout <> Value then begin
    FLayout := Value;
    UpdateAlignment;
    if Active then AlignLabel;
  end;
end;

procedure TsBoundLabel.SetMaxWidth(const Value: integer);
begin
  if FMaxWidth <> Value then begin
    FMaxWidth := Value;
    if Active then AlignLabel;
  end;
end;

procedure TsBoundLabel.SetText(const Value: string);
begin
  if FText <> Value then begin
    FText := Value;
    if Active then begin
      FTheLabel.Caption := Value;
      AlignLabel;
    end;
  end;
end;

procedure TsBoundLabel.SetUseSkin(const Value: boolean);
begin
  if Assigned(FTheLabel) then FTheLabel.UseSkinColor := Value;
end;

procedure TsBoundLabel.UpdateAlignment;
begin
  if FTheLabel <> nil then case FLayout of
    sclTopLeft : TsLabel(FTheLabel).Alignment := taLeftJustify;
    sclTopCenter : TsLabel(FTheLabel).Alignment := taCenter;
    sclTopRight, sclLeft : TsLabel(FTheLabel).Alignment := taRightJustify;
  end;
end;

end.

⌨️ 快捷键说明

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