📄 frxctrls.pas
字号:
{***************************************************}
{ }
{ FastReport v4.0 }
{ Tool controls }
{ }
{ Copyright (c) 1998-2008 }
{ by Alexander Tzyganenko, }
{ Fast Reports Inc. }
{ }
{ }
{ Flat ComboBox, FontComboBox v1.2 }
{ For Delphi 2,3,4,5. Freeware. }
{ }
{ Copyright (c) 1999 by: }
{ Dmitry Statilko (dima_misc@hotbox.ru) }
{ - Main idea and realisation of Flat ComboBox }
{ inherited from TCustomComboBox }
{ }
{ Vladislav Necheporenko (vlad_n@ua.fm) }
{ - Help in bug fixes }
{ - Adaptation to work on Delphi 2 }
{ - MRU list in FontComboBox that stored values }
{ in regitry }
{ - Font preview box in FontComboBox }
{ - New look style, like in Office XP }
{ }
{***************************************************}
unit frxCtrls;
interface
{$I frx.inc}
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, CommCtrl, ExtCtrls, Buttons, Registry, ActiveX
{$IFDEF Delphi6}
, Variants
{$ENDIF};
type
TfrxCustomComboBox = class(TCustomComboBox)
private
FUpDropdown: Boolean;
FButtonWidth: Integer;
msMouseInControl: Boolean;
FListHandle: HWND;
FListInstance: Pointer;
FDefListProc: Pointer;
FChildHandle: HWND;
FSolidBorder: Boolean;
FReadOnly: Boolean;
FEditOffset: Integer;
FListWidth: Integer;
procedure ListWndProc(var Message: TMessage);
procedure WMPaint(var Message: TWMPaint); message WM_PAINT;
procedure CNCommand(var Message: TWMCommand); message CN_COMMAND;
procedure CMEnabledChanged(var Msg: TMessage); message CM_ENABLEDCHANGED;
procedure CMMouseEnter(var Message: TMessage); message CM_MOUSEENTER;
procedure CMMouseLeave(var Message: TMessage); message CM_MOUSELEAVE;
procedure CMFontChanged(var Message: TMessage); message CM_FONTCHANGED;
procedure PaintButtonGlyph(DC: HDC; X: Integer; Y: Integer; Color: TColor);
procedure PaintButton(ButtonStyle: Integer);
procedure PaintBorder(DC: HDC; const SolidBorder: Boolean);
procedure PaintDisabled;
function GetSolidBorder: Boolean;
function GetListHeight: Integer;
procedure SetReadOnly(Value: Boolean);
protected
procedure CreateParams(var Params: TCreateParams); override;
procedure ComboWndProc(var Message: TMessage; ComboWnd: HWnd; ComboProc: Pointer); override;
procedure WndProc(var Message: TMessage); override;
procedure CreateWnd; override;
procedure DrawImage(DC: HDC; Index: Integer; R: TRect); dynamic;
property ListWidth: Integer read FListWidth write FListWidth;
property ReadOnly: Boolean read FReadOnly write SetReadOnly default False;
property SolidBorder: Boolean read FSolidBorder;
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
end;
TfrxComboBox = class(TfrxCustomComboBox)
published
property Color;
property DragMode;
property DragCursor;
property DropDownCount;
property Enabled;
property Font;
property ItemHeight;
property Items;
property ListWidth;
property MaxLength;
property ParentColor;
property ParentFont;
property ParentShowHint;
property PopupMenu;
property ShowHint;
property Sorted;
property TabOrder;
property TabStop;
property Text;
property ReadOnly;
property Visible;
property ItemIndex;
property OnChange;
property OnClick;
property OnDblClick;
property OnDragDrop;
property OnDragOver;
property OnDrawItem;
property OnDropDown;
property OnEndDrag;
property OnEnter;
property OnExit;
property OnKeyDown;
property OnKeyPress;
property OnKeyUp;
property OnStartDrag;
{$IFDEF Delphi4}
property Anchors;
property BiDiMode;
property Constraints;
property DragKind;
property ParentBiDiMode;
property OnEndDock;
property OnStartDock;
{$ENDIF}
end;
TfrxFontPreview = class(TWinControl)
private
FPanel: TPanel;
protected
procedure CreateParams(var Params: TCreateParams); override;
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
end;
TfrxFontComboBox = class(TfrxCustomComboBox)
private
frFontViewForm: TfrxFontPreview;
FRegKey: String;
FTrueTypeBMP: TBitmap;
FDeviceBMP: TBitmap;
FOnClick: TNotifyEvent;
FUpdate: Boolean;
FShowMRU: Boolean;
Numused: Integer;
procedure CNCommand(var Message: TWMCommand); message CN_COMMAND;
procedure CMFontChanged(var Message: TMessage); message CM_FONTCHANGED;
procedure CMFontChange(var Message: TMessage); message CM_FONTCHANGE;
procedure SetRegKey(Value: String);
protected
procedure Loaded; override;
procedure Init;
procedure Reset;
procedure Click; override;
procedure DrawItem(Index: Integer; Rect: TRect; State: TOwnerDrawState); override;
procedure DrawImage(DC: HDC; Index: Integer; R: TRect); override;
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
procedure PopulateList; virtual;
published
property ShowMRU: Boolean read FShowMRU write FShowMRU default True;
property MRURegKey: String read FRegKey write SetRegKey;
property Text;
property Color;
property DragMode;
property DragCursor;
property DropDownCount;
property Enabled;
property Font;
{$IFDEF Delphi4}
property Anchors;
property BiDiMode;
property Constraints;
property DragKind;
property ParentBiDiMode;
{$ENDIF}
property ItemHeight;
property ParentColor;
property ParentFont;
property ParentShowHint;
property PopupMenu;
property ShowHint;
property TabOrder;
property TabStop;
property Visible;
property OnChange;
property OnClick: TNotifyEvent read FOnClick write FOnClick;
property OnDblClick;
property OnDragDrop;
property OnDragOver;
property OnDropDown;
property OnEndDrag;
property OnEnter;
property OnExit;
property OnKeyDown;
property OnKeyPress;
property OnKeyUp;
property OnStartDrag;
{$IFDEF Delphi4}
property OnEndDock;
property OnStartDock;
{$ENDIF}
end;
TfrxComboEdit = class(TComboBox)
private
FPanel: TWinControl;
FButton: TSpeedButton;
FButtonEnabled: Boolean;
FOnButtonClick: TNotifyEvent;
function GetGlyph: TBitmap;
procedure SetGlyph(Value: TBitmap);
function GetButtonHint: String;
procedure SetButtonHint(Value: String);
procedure SetButtonEnabled(Value: Boolean);
procedure ButtonClick(Sender: TObject);
procedure WMSize(var Message: TWMSize); message WM_SIZE;
procedure CMEnabledChanged(var Message: TMessage); message CM_ENABLEDCHANGED;
procedure SetPos;
public
constructor Create(AOwner: TComponent); override;
procedure CreateWnd; override;
procedure KeyPress(var Key: Char); override;
published
property Glyph: TBitmap read GetGlyph write SetGlyph;
property ButtonEnabled: Boolean read FButtonEnabled write SetButtonEnabled default True;
property ButtonHint: String read GetButtonHint write SetButtonHint;
property OnButtonClick: TNotifyEvent read FOnButtonClick write FOnButtonClick;
end;
TfrxScrollWin = class(TCustomControl)
private
FBorderStyle: TBorderStyle;
FHorzPage: Integer;
FHorzPosition: Integer;
FHorzRange: Integer;
FLargeChange: Integer;
FSmallChange: Integer;
FVertPage: Integer;
FVertPosition: Integer;
FVertRange: Integer;
function GetLongPosition(DefValue: Integer; Code: Word): Integer;
procedure SetHorzPosition(Value: Integer);
procedure SetHorzRange(Value: Integer);
procedure SetPosition(Value: Integer; Code: Word);
procedure SetVertPosition(Value: Integer);
procedure SetVertRange(Value: Integer);
procedure UpdateScrollBar(Max, Page, Pos: Integer; Code: Word);
procedure WMEraseBackground(var Message: TMessage); message WM_ERASEBKGND;
procedure WMGetDlgCode(var Message: TWMGetDlgCode); message WM_GETDLGCODE;
procedure WMHScroll(var Message: TWMHScroll); message WM_HSCROLL;
procedure WMVScroll(var Message: TWMVScroll); message WM_VSCROLL;
procedure SetHorzPage(const Value: Integer);
procedure SetVertPage(const Value: Integer);
procedure SetBorderStyle(const Value: TBorderStyle);
protected
procedure CreateParams(var Params: TCreateParams); override;
procedure OnHScrollChange(Sender: TObject); virtual;
procedure OnVScrollChange(Sender: TObject); virtual;
public
constructor Create(AOwner: TComponent); override;
procedure Paint; override;
property BevelKind;
property BorderStyle: TBorderStyle read FBorderStyle write SetBorderStyle;
property HorzPage: Integer read FHorzPage write SetHorzPage;
property HorzPosition: Integer read FHorzPosition write SetHorzPosition;
property HorzRange: Integer read FHorzRange write SetHorzRange;
property LargeChange: Integer read FLargeChange write FLargeChange;
property SmallChange: Integer read FSmallChange write FSmallChange;
property VertPage: Integer read FVertPage write SetVertPage;
property VertPosition: Integer read FVertPosition write SetVertPosition;
property VertRange: Integer read FVertRange write SetVertRange;
end;
implementation
{$R *.RES}
{$IFDEF Delphi6}
{$WARN SYMBOL_DEPRECATED OFF}
{$ENDIF}
uses frxPrinter, frxClass;
const
fr01cm = 3.77953;
fr01in = 96 / 10;
type
THackScrollBar = class(TScrollBar);
{ Additional functions }
function Min(val1, val2: Word): Word;
begin
Result := val1;
if val1 > val2 then
Result := val2;
end;
function GetFontMetrics(Font: TFont): TTextMetric;
var
DC: HDC;
SaveFont: HFont;
begin
DC := GetDC(0);
SaveFont := SelectObject(DC, Font.Handle);
GetTextMetrics(DC, Result);
SelectObject(DC, SaveFont);
ReleaseDC(0, DC);
end;
function GetFontHeight(Font: TFont): Integer;
begin
Result := GetFontMetrics(Font).tmHeight;
end;
function Blend(C1, C2: TColor; W1: Integer): TColor;
var
W2, A1, A2, D, F, G: Integer;
begin
if C1 < 0 then C1 := GetSysColor(C1 and $FF);
if C2 < 0 then C2 := GetSysColor(C2 and $FF);
if W1 >= 100 then D := 1000
else D := 100;
W2 := D - W1;
F := D div 2;
A2 := C2 shr 16 * W2;
A1 := C1 shr 16 * W1;
G := (A1 + A2 + F) div D and $FF;
Result := G shl 16;
A2 := (C2 shr 8 and $FF) * W2;
A1 := (C1 shr 8 and $FF) * W1;
G := (A1 + A2 + F) div D and $FF;
Result := Result or G shl 8;
A2 := (C2 and $FF) * W2;
A1 := (C1 and $FF) * W1;
G := (A1 + A2 + F) div D and $FF;
Result := Result or G;
end;
{ TfrxCustomComboBox }
constructor TfrxCustomComboBox.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
FListInstance := MakeObjectInstance(ListWndProc);
FDefListProc := nil;
FButtonWidth := 11;
ItemHeight := GetFontHeight(Font);
Width := 100;
FEditOffset := 0;
end;
destructor TfrxCustomComboBox.Destroy;
begin
inherited Destroy;
FreeObjectInstance(FListInstance);
end;
procedure TfrxCustomComboBox.SetReadOnly(Value: Boolean);
begin
if FReadOnly <> Value then
begin
FReadOnly := Value;
if HandleAllocated then
SendMessage(EditHandle, EM_SETREADONLY, Ord(Value), 0);
end;
end;
procedure TfrxCustomComboBox.CreateParams(var Params: TCreateParams);
begin
inherited CreateParams(Params);
with Params do
Style := (Style and not CBS_DROPDOWNLIST) or CBS_OWNERDRAWFIXED or CBS_DROPDOWN;
end;
procedure TfrxCustomComboBox.CreateWnd;
begin
inherited;
SendMessage(EditHandle, EM_SETREADONLY, Ord(FReadOnly), 0);
// Desiding, which of the handles is DropDown list handle...
if FChildHandle <> EditHandle then
FListHandle := FChildHandle;
//.. and superclassing it
FDefListProc := Pointer(GetWindowLong(FListHandle, GWL_WNDPROC));
SetWindowLong(FListHandle, GWL_WNDPROC, Longint(FListInstance));
end;
procedure TfrxCustomComboBox.ListWndProc(var Message: TMessage);
var
p: TPoint;
procedure CallDefaultProc;
begin
with Message do
Result := CallWindowProc(FDefListProc, FListHandle, Msg, WParam, LParam);
end;
begin
case Message.Msg of
LB_SETTOPINDEX:
begin
if ItemIndex > DropDownCount then
CallDefaultProc;
end;
WM_WINDOWPOSCHANGING:
with TWMWindowPosMsg(Message).WindowPos^ do
begin
// calculating the size of the drop down list
if FListWidth <> 0 then
cx := FListWidth else
cx := Width;
cy := GetListHeight;
p.x := cx;
p.y := cy + GetFontHeight(Font) + 6;
p := ClientToScreen(p);
FUpDropdown := False;
if p.y > Screen.Height then //if DropDownList showing below
begin
FUpDropdown := True;
end;
end;
else
CallDefaultProc;
end;
end;
procedure TfrxCustomComboBox.WndProc(var Message: TMessage);
begin
case Message.Msg of
WM_SETTEXT:
Invalidate;
WM_PARENTNOTIFY:
if LoWord(Message.wParam)=WM_CREATE then begin
if FDefListProc <> nil then
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -