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

📄 sstyleedits.pas

📁 AlphaControls是一个Delphi标准控件的集合
💻 PAS
📖 第 1 页 / 共 4 页
字号:
unit sStyleEdits;
{$I sDefs.inc}

interface

uses
  windows, Graphics, Classes, Controls,
  {$IFNDEF ALITE}
  sEditorsManager,
  {$ENDIF}
  {$IFDEF USEDB}db, {$ENDIF}
  sUtils, SysUtils, StdCtrls, sStyleSimply, sDefaults,
  Dialogs, Forms, Messages, sConst, extctrls, IniFiles, sSkinManager;

type
{$IFDEF USEDB}
  TsAllowing = class;                  
{$ENDIF}
  TsStyle = class;
  TsCustomStyle = class;
  TsEditorStyle = class;
//  TsEditEffects = class;
  // Type for sEdits borders painting
  TsEditorBorder = class(TPersistent)
  protected
    FOwner : TPersistent;
    procedure SetWidth(const Value: integer);
  public
    FWidth: integer;
    FBevel: TsEditorBevel;
    constructor Create(AOwner: TPersistent); dynamic;
  published
    property Width : integer read FWidth write SetWidth default 2;
    property Bevel : TsEditorBevel read FBevel write FBevel default ebAsBottomBorder;
  end;

  // Type for selected sEdits painting
  TsEditorSelection = class(TPersistent)
  protected
    FMode : TModeSelection;
    FOwner : TPersistent;
    procedure SetMode(const Value: TModeSelection);
    procedure SetColor(const Value: TColor);
  public
    FColor: TColor;
    { @EXCLUDE}
    FBorder : TsEditorBorder;
    { @EXCLUDE}
    constructor Create(AOwner: TPersistent); 
    { @EXCLUDE}
    destructor destroy; override;
  published
    // @Link(TsEditorBorder). Border properties for selected sEdits
    property Border : TsEditorBorder read FBorder write FBorder;
    property Color: TColor read FColor write SetColor default clWindow;
    // Mode for control selection - (msBorder, msColor)
    property Mode : TModeSelection read FMode write SetMode default [msBorder, msColor];
  end;

  TsPainting = class(TPersistent)
  private
    FParentColor : boolean;
    FOwner : TsEditorStyle;
    procedure SetColors (Index: Integer; Value: TColor);
    procedure SetParentColor (Value: Boolean);
    procedure SetBevel(const Value: TsEditorBevel);
    procedure SetBevelWidth(const Value: integer);
  public
    FColor : TColor;
    FColorBorderTop : TColor;
    FColorBorderBottom : TColor;
    FBevel : TsEditorBevel;
    FBevelWidth : integer;
    constructor Create(AOwner : TsEditorStyle);
    property BevelWidth : integer read FBevelWidth write SetBevelWidth;
  published
    property Bevel : TsEditorBevel read FBevel write SetBevel default ebAsBottomBorder;
    property ColorBorderTop: TColor index 0 read FColorBorderTop write SetColors default clWhite;
    property ColorBorderBottom: TColor index 1 read FColorBorderBottom write SetColors default DefaultColorBottomBorder;
    property Color: TColor index 3 read FColor write SetColors default DefaultColor;
    property ParentColor: Boolean read FParentColor write SetParentColor default False;
  end;

{$IFDEF USEDB}
  TsData = class(TPersistent)
  private
    FAllowing : TsAllowing;
    FComment : string;
    FField : TField;
    FIsNumber : boolean;
    FOwner : TsStyle;
    procedure SetField(Value : TField);
  public
    constructor Create(AOwner : TsStyle);
    destructor Destroy; override;
  published
    property Allowing: TsAllowing read FAllowing write FAllowing;
    property Comment:string read FComment write FComment;
    property Field: TField read FField write SetField;
    property IsNumber:boolean read FIsNumber write FIsNumber;
  end;
{$ENDIF}


  TsStyleCaption = class(TPersistent)
  private
    FFont : TFont;
    FOwner : TsCustomStyle;
    FText : string;
    FActive : boolean;
    FMaxWidth : integer;
    FLayout : TsCaptionLayout;
    procedure SetText(const Value: string);
    procedure SetActive(const Value: boolean);
    procedure SetFont(const Value: TFont);
    procedure SetMaxWidth(const Value: integer);
    procedure SetLayout(const Value: TsCaptionLayout);
  public
    constructor Create(AOwner : TPersistent);
    destructor Destroy; override;
  published
    property Layout : TsCaptionLayout read FLayout write SetLayout;
    property MaxWidth: integer read FMaxWidth write SetMaxWidth;
    property Font: TFont read FFont write SetFont;
    property Text: string read FText write SetText;
    property Active: boolean read FActive write SetActive;
  end;

{$IFDEF USEDB}
  TsAllowing = class(TPersistent)
  private
    FInsert   : boolean;
    FUpdate   : boolean;
    FAutoInit : boolean;
    FOwner : TsStyle;
    procedure SetInsert(const Value: boolean);
    procedure SetUpdate(const Value: boolean);
  public
    constructor Create(AOwner : TsStyle);
  published
    property Insert: boolean read FInsert write SetInsert default True;
    property Update: boolean read FUpdate write SetUpdate default True;
    property AutoInit: boolean read FAutoInit write FAutoInit default True;
  end;
{$ENDIF}

  TsEditorStyle = class(TsGenStyle)
  private
    FSelection: TsEditorSelection;
//    FEditEffects: TsEditEffects;
  protected
    FPainting : TsPainting;
  public
    FBorderWidth : integer;
    {$IFNDEF ALITE}
    sC : TsEditorsManager;
    {$ENDIF}
    constructor Create(AOwner : TControl); override;
    destructor Destroy; override;
    function GetActiveColor : TColor;

    procedure WndProc(var Message: TMessage); override;
    procedure sStyleMessage(var Message: TMessage); //override;
    procedure PaintBorder(DC : hWnd; aRect : TsRect);
    procedure RedrawBorder;
    procedure PaintShadow(aCanvas: TCanvas; X, Y : integer); override;
    function GetSelBorder: TsEditorBorder;
    function GetSelMode: TModeSelection;
    procedure CreateRgn; override;
  published
    property Painting: TsPainting read FPainting write FPainting;
    property Selection : TsEditorSelection read FSelection write FSelection;
  end;

  TsCustomStyle = class(TsEditorStyle)
  private
    FTheLabel : TCustomControl;
  protected
{$IFDEF USEDB}
    FDefaultString : string;
    FEditable : boolean;
{$ENDIF}
    FKeysNextControl : string;
    FKeysPrevControl : string;

    FCaption : TsStyleCaption;
    LastControl : boolean;
  public
    procedure AlignLabel;
    constructor Create(AOwner : TControl); override;
    destructor Destroy; override;
    procedure WndProc(var Message: TMessage); override;
    procedure sStyleMessage(var Message: TMessage); //override;
    procedure onKeyDown(Sender:TObject; var Key: Word; Shift: TShiftState);
  published
    property Caption: TsStyleCaption read FCaption write FCaption;
    property KeysNextControl:string read FKeysNextControl write FKeysNextControl;
    property KeysPrevControl:string read FKeysPrevControl write FKeysPrevControl;
{$IFDEF USEDB}
    property DefaultString:string read FDefaultString write FDefaultString;
    property Editable:boolean read FEditable write FEditable;
{$ENDIF}
  end;

  TsStyle = class(TsCustomStyle)
  protected
{$IFDEF USEDB}
    FData : TsData;
{$ENDIF}
  public
    constructor Create(AOwner : TControl); override;
    destructor Destroy; override;
    procedure WndProc(var Message: TMessage); override;
    procedure sStyleMessage(var Message: TMessage); //override;
  published
{$IFDEF USEDB}
    property Data: TsData read FData write FData;
{$ENDIF}
  end;

  TsStyleDB=class(TsCustomStyle)
  protected
  public
    procedure WndProc(var Message: TMessage); override;
    procedure sStyleMessage(var Message: TMessage); //override;
  published
  end;

{$IFDEF USEDB}
function StyleIsActive(sStyle : TsCustomStyle) : boolean;
function GetInsertText(Panel : TWinControl; KeyName, KeyValue : string) : string;
function GetUpdateText(Panel : TWinControl) : string;
procedure InitsEdits(Panel : TWinControl);
{$ENDIF}
// Draws stylish rectangle on DC by style @link(TsBorderStyle)
procedure BeveledBorder(DC: HDC; ColorTop, ColorBottom, Color: TColor; aRect: TRect; Width : integer; Bevel: TsEditorBevel; Soft : boolean);

var
  CChanged : boolean = False;

implementation

uses
  {$IFNDEF ALITE}
    sEdit, sComboEdit, sRadioButton, sCustomComboEdit, sToolEdit,
    sMemo, sCurrencyEdit, sCustomComboBox, sStoreUtils, sShowMessages,
    sPageControl, sCustomListBox,
  {$IFDEF USEDBAWARE}
    sDBMemo,
  {$ENDIF}
  {$ENDIF}
  sCheckBox, {sPanel,} sCheckedControl,
  sGraphUtils, sVclUtils, sMessages, sMaskData,
  sCustomLabel, comctrls, sBorders, sSkinProps;


{$IFDEF USEDB}

function StyleIsActive(sStyle : TsCustomStyle) : boolean;
begin
  if sStyle is TsStyle then
     Result := Assigned(sStyle)
      and Assigned(TsStyle(sStyle).Data.Field)
  else if sStyle is TsStyleDB then
     Result := Assigned(sStyle) and True{Assigned(TDBEdit(sStyle.FOwner).DataSource)  and (TDBEdit(sStyle.FOwner).DataField <> '')}
  else Result := False;
end;

procedure InitsEdits(Panel : TWinControl);
var
  List : TList;
  i : integer;
  mStyle : TsStyle;
begin
  List := TList.Create;
  Panel.GetTabOrderList(List);
  if List.Count>0 then begin
    for i:=0 to List.Count-1 do begin
      if (GetStyleInfo(List[i]) = tos_SSTYLE) then begin
        mStyle := TsStyle(GetsStyle(TWinControl(List[i])));

        if (TWinControl(List[i]) is TsCustomComboBox) and (TsCustomComboBox(List[i]).sStyle.Data.Allowing.AutoInit) then begin
          TsCustomComboBox(List[i]).Active := True;
        end;

        if StyleIsActive(mStyle) and mStyle.Data.Allowing.AutoInit then begin

          if Between(GetsStyle(List[i]).COC, COC_TsEdit, COC_TsMemo) then begin
            if TWinControl(List[i]) is TsMemo then
              TsMemo(List[i]).Text := mStyle.Data.Field.AsString
            else
              TsEdit(List[i]).Text := mStyle.Data.Field.AsString;
          end else

          if Between(GetsStyle(List[i]).COC, COC_TsCustomComboEdit, COC_TsComboEdit) then begin
            TsCustomComboEdit(List[i]).Text := mStyle.Data.Field.AsString
          end else

          if Between(GetsStyle(List[i]).COC, COC_TsCustomComboBox, COC_TsBDEComboBox) then begin
            if TsCustomComboBox(List[i]).Items.Count > 0 then begin
              if mStyle.Data.IsNumber then begin
                if TsCustomComboBox(List[i]).CharsInCode > 0 then begin
                  TsCustomComboBox(List[i]).ItemIndex := TsCustomComboBox(List[i]).IndexOfKod(mStyle.Data.Field.AsString);
                end
                else if TsCustomComboBox(List[i]).UseItemIndex then begin
                  TsCustomComboBox(List[i]).ItemIndex := mStyle.Data.Field.asInteger;
                end
                else begin
                  TsCustomComboBox(List[i]).ItemIndex := TsCustomComboBox(List[i]).Items.IndexOf(mStyle.Data.Field.asString);
                end;
              end
              else begin
                  TsCustomComboBox(List[i]).ItemIndex := TsCustomComboBox(List[i]).Items.IndexOf(mStyle.Data.Field.asString);
              end;
            end;
          end else

          if Between(GetsStyle(List[i]).COC, COC_TsDateEdit, COC_TsDateEdit) then begin
            if mStyle.Data.Field.asString='' then begin
              TsDateEdit(List[i]).Date := Date;
              TsDateEdit(List[i]).Text := '  .  .    ';
            end
            else begin
              TsDateEdit(List[i]).Date := mStyle.Data.Field.asDateTime;
            end;
          end else

          if Between(GetsStyle(List[i]).COC, COC_TsCheckedControl, COC_TsRadioButton) then begin
            TsCheckedControl(List[i]).Checked := mStyle.Data.Field.AsInteger = 1;
          end else

          if Between(GetsStyle(List[i]).COC, COC_TsCurrencyEdit, COC_TsCurrencyEdit) then begin
            TsCurrencyEdit(List[i]).Text := mStyle.Data.Field.AsString;
          end;
        end;
      end;
    end;
  end;
  List.Free;
end;

function GetInsertText(Panel : TWinControl; KeyName, KeyValue : string) : string;
var
  List : TList;
  i : integer;
  s1, s2 : string;
  mStyle : TsStyle;
begin
  List := TList.Create;
  Panel.GetTabOrderList(List);
  if List.Count>0 then begin
    s1 := KeyName;
    s2 := KeyValue;
    for i:=0 to List.Count-1 do begin
      if (GetStyleInfo(List[i]) = 5) then begin
        mStyle := TsStyle(GetsStyle(TWinControl(List[i])));
        if StyleIsActive(mStyle) and mStyle.Data.Allowing.Insert and TControl(List[i]).Enabled then begin
          s1 := iff((s1 = ''), mStyle.Data.Field.FieldName, s1 + ', ' + mStyle.Data.Field.FieldName);
          s2 := iff((s2 = ''), '', s2 + ', ');

          if Between(GetsStyle(List[i]).COC, COC_TsEdit, COC_TsMemo) then begin
            if TWinControl(List[i]) is TsMemo then
              s2 := s2 + iff(mStyle.Data.IsNumber, '0' + TsMemo(List[i]).Text, '''' + CorrectString(TsMemo(List[i]).Text) + '''')
            else begin
//              ShowWarning(TsEdit(List[i]).Name + ' - ' + mStyle.Data.Field.FieldName);
              s2 := s2 + iff(mStyle.Data.IsNumber, '0' + TsEdit(List[i]).Text, '''' + CorrectString(TsEdit(List[i]).Text) + '''');
            end;
          end else

          if Between(GetsStyle(List[i]).COC, COC_TsCustomComboBox, COC_TsBDEComboBox) then begin
            if mStyle.Data.IsNumber then begin 
              if TsCustomComboBox(List[i]).CharsInCode > 0 then begin
                s2 := s2 + IntToStr(TsCustomComboBox(List[i]).GetCurrentKod);
              end
              else if TsComboBox(List[i]).UseItemIndex then begin
                s2 := s2 + IntToStr(TsCustomComboBox(List[i]).ItemIndex);
              end
              else begin
                s2 := s2 + '''' + CorrectString(TsCustomComboBox(List[i]).Text) + '''';
              end;
            end
            else begin
              s2 := s2 + '''' + CorrectString(TsCustomComboBox(List[i]).Text) + '''';
            end;
          end else

          if Between(GetsStyle(List[i]).COC, COC_TsDateEdit, COC_TsDateEdit) then begin
            s2 := s2 + iff(TsDateEdit(List[i]).Text='  .  .    ', 'NULL', '''' + TsDateEdit(List[i]).Text + '''');
          end else

          if Between(GetsStyle(List[i]).COC, COC_TsCheckedControl, COC_TsRadioButton) then begin
            s2 := s2 + iff(TsCheckedControl(List[i]).Checked, '1', '0');
          end else

          if Between(GetsStyle(List[i]).COC, COC_TsCurrencyEdit, COC_TsCurrencyEdit) then begin
            s2 := s2 + iff(mStyle.Data.IsNumber, '0' + FloatToStr(TsCurrencyEdit(List[i]).Value), '''' + TsCurrencyEdit(List[i]).Text + '''');
          end else

⌨️ 快捷键说明

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