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

📄 jvqdyncontrolengine.pas

📁 East make Tray Icon in delphi
💻 PAS
📖 第 1 页 / 共 3 页
字号:
{******************************************************************************}
{* WARNING:  JEDI VCL To CLX Converter generated unit.                        *}
{*           Manual modifications will be lost on next release.               *}
{******************************************************************************}

{-----------------------------------------------------------------------------
The contents of this file are subject to the Mozilla Public License
Version 1.1 (the "License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.mozilla.org/MPL/MPL-1.1.html

Software distributed under the License is distributed on an "AS IS" basis,
WITHOUT WARRANTY OF ANY KIND, either expressed or implied. See the License for
the specific language governing rights and limitations under the License.

The Initial Developer of the Original Code is Jens Fudickar [jens dott fudickar att oratool dott de]
All Rights Reserved.

Contributor(s):
Jens Fudickar [jens dott fudickar att oratool dott de]

You may retrieve the latest version of this file at the Project JEDI's JVCL home page,
located at http://jvcl.sourceforge.net

Known Issues:
-----------------------------------------------------------------------------}
// $Id: JvQDynControlEngine.pas,v 1.18 2005/02/06 14:06:05 asnepvangers Exp $

unit JvQDynControlEngine;

{$I jvcl.inc}

interface

uses
  Classes, QControls, QForms, QStdCtrls, QGraphics, QButtons,
  JvQDynControlEngineIntf;

type
  TJvDynControlType = string;

const
  jctLabel = TJvDynControlType('Label');
  jctStaticText = TJvDynControlType('StaticText');
  jctPanel = TJvDynControlType('Panel');
  jctScrollBox = TJvDynControlType('ScrollBox');
  jctEdit = TJvDynControlType('Edit');
  jctCheckBox = TJvDynControlType('CheckBox');
  jctComboBox = TJvDynControlType('ComboBox');
  jctGroupBox = TJvDynControlType('GroupBox');
  jctImage = TJvDynControlType('Image');
  jctRadioGroup = TJvDynControlType('RadioGroup');
  jctRadioButton = TJvDynControlType('RadioButton');
  jctMemo = TJvDynControlType('Memo');
  jctRichEdit = TJvDynControlType('RichEdit');
  jctListBox = TJvDynControlType('ListBox');
  jctCheckListBox = TJvDynControlType('CheckListBox');
  jctDateTimeEdit = TJvDynControlType('DateTimeEdit');
  jctDateEdit = TJvDynControlType('DateEdit');
  jctTimeEdit = TJvDynControlType('TimeEdit');
  jctCalculateEdit = TJvDynControlType('CalculateEdit');
  jctSpinEdit = TJvDynControlType('SpinEdit');
  jctDirectoryEdit = TJvDynControlType('DirectoryEdit');
  jctFileNameEdit = TJvDynControlType('FileNameEdit');
  jctButton = TJvDynControlType('Button');
  jctButtonEdit = TJvDynControlType('ButtonEdit');
  jctForm = TJvDynControlType('Form');

type
  TControlClass = class of TControl;

  TJvControlClassObject = class(TObject)
  private
    FControlClass: TControlClass;
  public
    property ControlClass: TControlClass read FControlClass write FControlClass;
  end;

  TJvAfterCreateControl = procedure(AControl: TControl) of object;

  TJvCustomDynControlEngine = class(TPersistent)
  private
    //FRegisteredControlTypes: array [TJvDynControlType] of TControlClass;
    FRegisteredControlTypes: TStringList;
    FRegisterControlsExecuted: Boolean;
    FAfterCreateControl: TJvAfterCreateControl;
    function GetPropName(Instance: TPersistent; Index: Integer): string;
    function GetPropCount(Instance: TPersistent): Integer;
  protected
    procedure SetPropertyValue(const APersistent: TPersistent; const APropertyName: string; const AValue: Variant);
    function GetPropertyValue(const APersistent: TPersistent; const APropertyName: string): Variant;
    procedure AfterCreateControl(AControl: TControl); virtual;
    procedure NeedRegisterControls;
    procedure RegisterControls; virtual;
  public
    constructor Create; virtual;
    destructor Destroy; override;

    function GetRegisteredControlClass(AControlType: TJvDynControlType): TControlClass;

    function CreateControl(AControlType: TJvDynControlType; AOwner: TComponent;
      AParentControl: TWinControl; AControlName: string): TControl; virtual;
    function CreateControlClass(AControlClass: TControlClass; AOwner: TComponent;
      AParentControl: TWinControl; AControlName: string): TControl; virtual;

    function IsControlTypeRegistered(const ADynControlType: TJvDynControlType): Boolean;

    function IsControlTypeValid(const ADynControlType: TJvDynControlType;
      AControlClass: TControlClass): Boolean; virtual;
    procedure RegisterControlType(const ADynControlType: TJvDynControlType;
      AControlClass: TControlClass); virtual;

    procedure SetControlCaption(AControl: IJvDynControl; const Value: string);
    procedure SetControlTabOrder(AControl: IJvDynControl; Value: Integer);

    procedure SetControlOnEnter(AControl: IJvDynControl; Value: TNotifyEvent);
    procedure SetControlOnExit(AControl: IJvDynControl; Value: TNotifyEvent);
    procedure SetControlOnClick(AControl: IJvDynControl; Value: TNotifyEvent);
  published
    property OnAfterCreateControl: TJvAfterCreateControl read FAfterCreateControl write FAfterCreateControl;
  end;

  TJvDynControlEngine = class(TJvCustomDynControlEngine)
  private
    FDistanceBetweenLabelAndControlHorz: Integer;
    FDistanceBetweenLabelAndControlVert: Integer;
  public
    constructor Create; override;
    function CreateLabelControl(AOwner: TComponent; AParentControl: TWinControl;
      const AControlName, ACaption: string; AFocusControl: TWinControl): TControl; virtual;
    function CreateStaticTextControl(AOwner: TComponent; AParentControl: TWinControl;
      const AControlName, ACaption: string): TWinControl; virtual;
    function CreatePanelControl(AOwner: TComponent; AParentControl: TWinControl;
      const AControlName, ACaption: string; AAlign: TAlign): TWinControl; virtual;
    function CreateScrollBoxControl(AOwner: TComponent; AParentControl: TWinControl;
      const AControlName: string): TWinControl; virtual;
    function CreateEditControl(AOwner: TComponent; AParentControl: TWinControl;
      const AControlName: string): TWinControl; virtual;
    function CreateCheckboxControl(AOwner: TComponent; AParentControl: TWinControl;
      const AControlName, ACaption: string): TWinControl; virtual;
    function CreateComboBoxControl(AOwner: TComponent; AParentControl: TWinControl;
      const AControlName: string; AItems: TStrings): TWinControl; virtual;
    function CreateGroupBoxControl(AOwner: TComponent; AParentControl: TWinControl;
      const AControlName, ACaption: string): TWinControl; virtual;
    function CreateImageControl(AOwner: TComponent; AParentControl: TWinControl;
      const AControlName: string): TWinControl; virtual;
    function CreateRadioGroupControl(AOwner: TComponent; AParentControl: TWinControl;
      const AControlName, ACaption: string; AItems: TStrings;
      AItemIndex: Integer = 0): TWinControl; virtual;
    function CreateMemoControl(AOwner: TComponent; AParentControl: TWinControl;
      const AControlName: string): TWinControl; virtual;
    function CreateRichEditControl(AOwner: TComponent; AParentControl: TWinControl;
      const AControlName: string): TWinControl; virtual;
    function CreateListBoxControl(AOwner: TComponent; AParentControl: TWinControl;
      const AControlName: string; AItems: TStrings): TWinControl; virtual;
    function CreateCheckListBoxControl(AOwner: TComponent;
      AParentControl: TWinControl; const AControlName: string; AItems: TStrings): TWinControl;
    function CreateDateTimeControl(AOwner: TComponent; AParentControl: TWinControl;
      const AControlName: string): TWinControl; virtual;
    function CreateDateControl(AOwner: TComponent; AParentControl: TWinControl;
      const AControlName: string): TWinControl; virtual;
    function CreateTimeControl(AOwner: TComponent; AParentControl: TWinControl;
      const AControlName: string): TWinControl; virtual;
    function CreateCalculateControl(AOwner: TComponent; AParentControl: TWinControl;
      const AControlName: string): TWinControl; virtual;
    function CreateSpinControl(AOwner: TComponent; AParentControl: TWinControl;
      const AControlName: string): TWinControl; virtual;
    function CreateDirectoryControl(AOwner: TComponent; AParentControl: TWinControl;
      const AControlName: string): TWinControl; virtual;
    function CreateFileNameControl(AOwner: TComponent; AParentControl: TWinControl;
      const AControlName: string): TWinControl; virtual;
    function CreateButton(AOwner: TComponent; AParentControl: TWinControl;
      const AButtonName, ACaption, AHint: string;
      AOnClick: TNotifyEvent; ADefault: Boolean = False;
      ACancel: Boolean = False): TButton; virtual;
    function CreateRadioButton(AOwner: TComponent; AParentControl: TWinControl;
      const ARadioButtonName, ACaption: string): TWinControl; virtual;
    function CreateButtonEditControl(AOwner: TComponent; AParentControl: TWinControl;
      const AControlName: string; AOnButtonClick: TNotifyEvent): TWinControl; virtual;
    function CreateForm(const ACaption, AHint: string): TCustomForm; virtual;

    function CreateLabelControlPanel(AOwner: TComponent; AParentControl: TWinControl;
      const AControlName, ACaption: string; AFocusControl: TWinControl;
      ALabelOnTop: Boolean = True; ALabelDefaultWidth: Integer = 0): TWinControl; virtual;
  published
    property DistanceBetweenLabelAndControlHorz: Integer read FDistanceBetweenLabelAndControlHorz write FDistanceBetweenLabelAndControlHorz default 4;
    property DistanceBetweenLabelAndControlVert: Integer read FDistanceBetweenLabelAndControlVert write FDistanceBetweenLabelAndControlVert default 1;
  end;



function IntfCast(Instance: TObject; const Intf: TGUID): IUnknown;

procedure SetDefaultDynControlEngine(AEngine: TJvDynControlEngine);
function DefaultDynControlEngine: TJvDynControlEngine;

implementation

uses
  {$IFDEF UNITVERSIONING}
  JclUnitVersioning,
  {$ENDIF UNITVERSIONING}
  {$IFDEF HAS_UNIT_VARIANTS}
  Variants,
  {$ENDIF HAS_UNIT_VARIANTS}
  SysUtils, TypInfo,
  JvQResources, JvQTypes, JvQDynControlEngineVCL;

var
  GlobalDefaultDynControlEngine: TJvDynControlEngine = nil;



function IntfCast(Instance: TObject; const Intf: TGUID): IUnknown;
begin
  if not Supports(Instance, Intf, Result) then
    raise EIntfCastError.CreateRes(@RsEIntfCastError);
end;

//=== { TJvCustomDynControlEngine } ==========================================

constructor TJvCustomDynControlEngine.Create;
begin
  inherited Create;
  FRegisteredControlTypes := TStringList.Create;
end;

destructor TJvCustomDynControlEngine.Destroy;
var
  Ind: Integer;
begin
  for Ind := 0 to FRegisteredControlTypes.Count - 1 do
    if Assigned(FRegisteredControlTypes.Objects[Ind]) then
      FRegisteredControlTypes.Objects[Ind].Free;
  FRegisteredControlTypes.Free;
  inherited Destroy;
end;

function TJvCustomDynControlEngine.IsControlTypeRegistered(const ADynControlType: TJvDynControlType): Boolean;
var
  Ind: Integer;
begin
  NeedRegisterControls;
  Ind := FRegisteredControlTypes.IndexOf(ADynControlType);
  if Ind >= 0 then
    Result := Assigned(FRegisteredControlTypes.Objects[Ind])
  else
    Result := False;
end;

function TJvCustomDynControlEngine.IsControlTypeValid(const ADynControlType: TJvDynControlType;
  AControlClass: TControlClass): Boolean;
var
  Valid: Boolean;
begin
  Valid := Supports(AControlClass, IJvDynControl);
  if ADynControlType = jctButton then
    Valid := Valid and Supports(AControlClass, IJvDynControlButton)
  else
  if ADynControlType = jctButtonEdit then
    Valid := Valid and Supports(AControlClass, IJvDynControlButton) and
      Supports(AControlClass, IJvDynControlData)
  else
  if ADynControlType = jctPanel then
    Valid := Valid and Supports(AControlClass, IJvDynControlPanel)
  else
  if ADynControlType = jctLabel then
    Valid := Valid and Supports(AControlClass, IJvDynControlLabel)
  else
  if ADynControlType = jctMemo then
    Valid := Valid and
      Supports(AControlClass, IJvDynControlItems) and
      Supports(AControlClass, IJvDynControlData) and
      Supports(AControlClass, IJvDynControlMemo)
  else
  if (ADynControlType = jctRadioGroup) or
    (ADynControlType = jctComboBox) then
    Valid := Valid and
      Supports(AControlClass, IJvDynControlItems) and

⌨️ 快捷键说明

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