📄 teependlg.pas
字号:
{**********************************************}
{ TPenDialog }
{ Copyright (c) 1996-2004 by David Berneda }
{**********************************************}
unit TeePenDlg;
{$I TeeDefs.inc}
interface
uses {$IFNDEF LINUX}
Windows, Messages,
{$ENDIF}
SysUtils, Classes,
{$IFDEF CLX}
Qt, QGraphics, QControls, QForms, QDialogs, QStdCtrls, QExtCtrls, QComCtrls,
Types,
{$ELSE}
Graphics, Controls, Forms, Dialogs, StdCtrls, ExtCtrls, ComCtrls,
{$ENDIF}
TeCanvas, TeeProcs;
type
TPenDialog = class(TForm)
CBVisible: TCheckBox;
SEWidth: TEdit;
LWidth: TLabel;
BOk: TButton;
BCancel: TButton;
UDWidth: TUpDown;
Label1: TLabel;
CBStyle: TComboFlat;
BColor: TButtonColor;
CBEndStyle: TComboFlat;
procedure FormShow(Sender: TObject);
procedure SEWidthChange(Sender: TObject);
procedure CBVisibleClick(Sender: TObject);
procedure BCancelClick(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure CBStyleChange(Sender: TObject);
{$IFDEF CLX}
procedure CBStyleDrawItem(Sender: TObject; Index: Integer;
Rect: TRect; State: TOwnerDrawState; var Handled:Boolean);
{$ELSE}
procedure CBStyleDrawItem(Control: TWinControl; Index: Integer;
Rect: TRect; State: TOwnerDrawState);
{$ENDIF}
procedure BColorClick(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure CBEndStyleChange(Sender: TObject);
private
{ Private declarations }
BackupPen : TChartPen;
ModifiedPen : Boolean;
Procedure EnablePenStyle;
public
{ Public declarations }
ThePen : TPen;
end;
Function EditChartPen(AOwner:TComponent; ChartPen:TChartPen; HideColor:Boolean=False):Boolean;
{ Show / Hide controls in array }
Procedure ShowControls(Show:Boolean; Const AControls:Array of TControl);
{ Asks the user a question and returns Yes or No }
Function TeeYesNo(Const Message:String; Owner:TControl=nil):Boolean;
{ Same as above, but using predefined "Sure to Delete?" message }
Function TeeYesNoDelete(Const Message:String; Owner:TControl=nil):Boolean;
type
TButtonPen=class(TTeeButton)
protected
procedure DrawSymbol(ACanvas:TTeeCanvas); override;
public
HideColor : Boolean;
procedure Click; override;
procedure LinkPen(APen:TChartPen);
end;
{$IFDEF CLX}
Procedure TeeFixParentedForm(AForm:TForm);
{$ENDIF}
Procedure AddFormTo(AForm:TForm; AParent:TWinControl); overload;
Procedure AddFormTo(AForm:TForm; AParent:TWinControl; ATag:TPersistent); overload;
Procedure AddFormTo(AForm:TForm; AParent:TWinControl; ATag:Integer); overload;
Procedure AddDefaultValueFormats(AItems:TStrings);
Procedure TeeLoadArrowBitmaps(AUp,ADown:TBitmap);
{ Helper listbox items routines }
procedure MoveList(Source,Dest:TCustomListBox);
procedure MoveListAll(Source,Dest:TStrings);
// Adds all cursors and special "crTeeHand" cursor to ACombo.
// Sets combo ItemIndex to ACursor.
procedure TeeFillCursors(ACombo:TComboFlat; ACursor:TCursor);
Function TeeSetCursor(ACursor:TCursor; const S:String):TCursor;
Const TeeFormBorderStyle={$IFDEF CLX}fbsNone{$ELSE}bsNone{$ENDIF};
Function TeeCreateForm(FormClass:TFormClass; AOwner:TComponent):TForm;
Function TeeCursorToIdent(ACursor:Integer; Var AName:String):Boolean;
Function TeeIdentToCursor(Const AName:String; Var ACursor:Integer):Boolean;
implementation
{$IFNDEF CLX}
{$R *.DFM}
{$ELSE}
{$R *.xfm}
{$ENDIF}
Uses {$IFNDEF CLX}
ExtDlgs,
{$ENDIF}
{$IFDEF CLR}
Variants,
{$ENDIF}
Math, TypInfo, TeeConst;
{$IFDEF CLR}
{$R TeeArrowDown.bmp}
{$R TeeArrowUp.bmp}
{$ENDIF}
Function TeeCreateForm(FormClass:TFormClass; AOwner:TComponent):TForm;
Function TeeGetParentForm(AOwner:TComponent):TComponent;
begin
result:=AOwner;
if Assigned(result) and (result is TControl) then
begin
result:=GetParentForm(TControl(result));
if not Assigned(result) then result:=AOwner;
end;
end;
begin
result:=FormClass.Create(TeeGetParentForm(AOwner));
with result do
begin
Align:=alNone;
{$IFDEF D5}
if Assigned(Owner) then Position:=poOwnerFormCenter
else
{$ENDIF}
Position:=poScreenCenter;
BorderStyle:=TeeBorderStyle;
end;
end;
Function EditChartPen(AOwner:TComponent; ChartPen:TChartPen; HideColor:Boolean=False):Boolean;
Begin
With TeeCreateForm(TPenDialog,AOwner) as TPenDialog do
try
ThePen:=ChartPen;
if HideColor then BColor.Hide;
result:=ShowModal=mrOk;
finally
Free;
end;
end;
procedure TPenDialog.FormShow(Sender: TObject);
begin
BackupPen:=TChartPen.Create(nil);
if Assigned(ThePen) then
begin
BackupPen.Assign(ThePen);
if ThePen is TChartPen then
begin
CBVisible.Checked:=TChartPen(ThePen).Visible;
BackupPen.Visible:=CBVisible.Checked;
if IsWindowsNT then CBStyle.Items.Add(TeeMsg_SmallDotsPen);
if TChartPen(ThePen).SmallDots then
begin
CBStyle.ItemIndex:=CBStyle.Items.Count-1;
UDWidth.Enabled:=False;
SEWidth.Enabled:=False;
end
else
CBStyle.ItemIndex:=Ord(ThePen.Style);
if IsWindowsNT then
begin
CBEndStyle.ItemIndex:=Ord(TChartPen(ThePen).EndStyle);
{$IFDEF CLX}
CBEndStyle.OnSelect:=CBEndStyleChange;
{$ENDIF}
end
else CBEndStyle.Visible:=False;
end
else
begin
CBVisible.Visible:=False;
CBStyle.ItemIndex:=Ord(ThePen.Style);
end;
UDWidth.Position:=ThePen.Width;
EnablePenStyle;
BColor.LinkProperty(ThePen,'Color');
end;
TeeTranslateControl(Self);
ModifiedPen:=False;
end;
Procedure TPenDialog.EnablePenStyle;
begin
{$IFNDEF CLX}
if not IsWindowsNT then CBStyle.Enabled:=ThePen.Width=1;
{$ENDIF}
end;
procedure TPenDialog.SEWidthChange(Sender: TObject);
begin
if Showing then
begin
ThePen.Width:=UDWidth.Position;
EnablePenStyle;
ModifiedPen:=True;
end;
end;
procedure TPenDialog.CBEndStyleChange(Sender: TObject);
begin
TChartPen(ThePen).EndStyle:=TPenEndStyle(CBEndStyle.ItemIndex);
ModifiedPen:=True;
end;
procedure TPenDialog.CBVisibleClick(Sender: TObject);
begin
if Showing then
begin
TChartPen(ThePen).Visible:=CBVisible.Checked;
ModifiedPen:=True;
end;
end;
procedure TPenDialog.BCancelClick(Sender: TObject);
begin
if ModifiedPen then
begin
ThePen.Assign(BackupPen);
if ThePen is TChartPen then
begin
TChartPen(ThePen).Visible:=BackupPen.Visible;
if Assigned(ThePen.OnChange) then ThePen.OnChange(Self);
end;
end;
ModalResult:=mrCancel;
end;
procedure TPenDialog.FormClose(Sender: TObject; var Action: TCloseAction);
begin
BackupPen.Free;
end;
procedure TPenDialog.FormCreate(Sender: TObject);
begin
BorderStyle:=TeeBorderStyle;
end;
procedure TPenDialog.CBStyleChange(Sender: TObject);
var tmp : Boolean;
begin
if (ThePen is TChartPen) and IsWindowsNT and
(CBStyle.ItemIndex=CBStyle.Items.Count-1) then
begin
TChartPen(ThePen).SmallDots:=True;
tmp:=False;
end
else
begin
tmp:=True;
ThePen.Style:=TPenStyle(CBStyle.ItemIndex);
if ThePen is TChartPen then
TChartPen(ThePen).SmallDots:=False;
end;
UDWidth.Enabled:=tmp; { 5.01 }
SEWidth.Enabled:=tmp;
ModifiedPen:=True;
end;
procedure TPenDialog.BColorClick(Sender: TObject);
begin
CBStyle.Repaint;
ModifiedPen:=True;
end;
{$IFDEF CLX}
procedure TPenDialog.CBStyleDrawItem(Sender: TObject; Index: Integer;
Rect: TRect; State: TOwnerDrawState; var Handled:Boolean);
{$ELSE}
procedure TPenDialog.CBStyleDrawItem(Control: TWinControl; Index: Integer;
Rect: TRect; State: TOwnerDrawState);
{$ENDIF}
var tmp : TColor;
begin
With TControlCanvas(CBStyle.Canvas) do
begin
{$IFDEF CLX}
Brush.Style:=bsSolid;
if (odFocused in State) or (odSelected in State) then
Brush.Color:=clHighLight;
{$ENDIF}
FillRect(Rect);
{$IFNDEF CLX}
if Index<>CBStyle.Items.Count-1 then
{$ENDIF}
Pen.Style:=TPenStyle(Index);
Pen.Color:=ThePen.Color;
if odSelected in State then tmp:=clHighLight
else tmp:=CBStyle.Color;
if Pen.Color=ColorToRGB(tmp) then
if Pen.Color=clWhite then Pen.Color:=clBlack
else Pen.Color:=clWhite;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -