📄 fcstatusbar.pas
字号:
unit fcStatusBar;
{
//
// Components : TfcStatusBar
//
// Copyright (c) 1999 by Woll2Woll Software
}
// 10/12/98 - Handle disabling of images for the glyphs style
// 10/12/98 - Occasional flicker as time changes.
// 4/17/99 - Renamed imagelist to images
// 4/26/99 - PYW - Only shrink width if last panel and sizegrip is true.
// 4/26/99 - PYW - Show sizegrip only if sizeable window.
// 4/27/99 - PYW - Update Timer for time styles to 1000.
// 5/06/99 - PYW - Added StatusBarText property.
// 5/27/99 - RSW - Don't use StatusBar Canvas, but use StatusPanel Canvas
// 7/11/99 - Clear StatusBars static variable so that if referenced for
// some reason later in in destructor it would not cause an exception
// 8/14/2000 - PYW - Don't change the parents for richedit controls.
// 5/22/2000 - PYW - Added code to make statusbar respect active container.
interface
{$i fcIfDef.pas}
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
CommCtrl, Menus, Richedit, StdCtrls, fcCollection,
fcCommon, fcText, ComCtrls{$ifdef fcDelphi4Up}, ImgList{$endif};
const
TIMER_ID = 200;
HINT_TIMER_ID = 300;
RICHEDIT_TIMER_ID = 400;
type
TfcCustomStatusBar = class;
// 5/06/99 - PYW - Added StatusBarText property.
TfcStatusBarText = class(TPersistent)
private
FOwner : TfcCustomStatusBar;
FCapsLock: string;
FOverwrite: string;
FNumLock: string;
FScrollLock: string;
procedure SetCapsLock(Value:String);
procedure SetOverwrite(Value:String);
procedure SetNumLock(Value:String);
procedure SetScrollLock(Value:String);
public
constructor Create(AOwner: TfcCustomStatusBar);
published
property CapsLock: string read FCapsLock write SetCapsLock;
property Overwrite: string read FOverwrite write SetOverwrite;
property NumLock: string read FNumLock write SetNumLock;
property ScrollLock: string read FScrollLock write SetScrollLock;
end;
TfcStatusPanels = class;
TfcStatusPanel = class;
TfcCustomStatusBarClass = class of TfcCustomStatusBar;
TfcStatusPanelsClass = class of TfcStatusPanels;
TfcStatusPanelClass = class of TfcStatusPanel;
TfcStatusPanelStyle = (psTextOnly, psControl, psOverWrite, psCapsLock,
psNumLock, psDateTime, psDate, psTime, psGlyph,
psRichEditStatus, psHint, psUserName, psComputerName, psScrollLock, psHintContainerOnly);
TfcStatusPanelBevel = (pbNone, pbLowered, pbRaised);
TfcPanelTextChangedEvent = procedure(Sender: TObject; const Text: string) of object;
TfcDrawTextEvent = procedure(Panel: TfcStatusPanel; var Text: string; var Enabled:Boolean) of object;
{
// TfcStatusPanel
// Properties:
// (Public)
// - Col: Returns the current Col in the TCustomMemo. (Only
// applicable if Control is a TCustomMemo) For use
// when customizing the line and Col text.
//
// - Row: Returns the current Row in the TCustomMemo. See
// the Col property for details.
//
// (Published)
// - Alignment: Determines the alignment of the text in the Panel.
//
// - Bevel: Determines the type of Bevel the panel has.
//
// - Color: Determines the color of the panel.
//
// - Control: When the style property is set to psControl then this
// is the control that gets displayed. Setting this
// property to a non-nil value will set the style property
// to psControl.
//
// - Enabled: When False, text appears disabled (grayed-out). Setting
// this will also set the Control's enabled property if the
// Control property is assigned.
//
// - Font: The font that the text uses to display itself.
//
// - Hint: The hint that gets displayed when the mouse cursor
// remains over the panel for a short period of time.
//
// - ImageIndex: The index within the StatusBar's Imagelist to display.
// Setting this property to a value other than -1 will
// set the style property to psGlyph.
//
// - Indent: When the Style property is set to psTextOnly, this property
// specifies how much from the border the text is spaced
// away. When the Alignment property is taLeftJustify,
// the Indent property pertains to the left border.
//
// - Margin: This property specifies how far the edges of text and
// controls are from the edge of the panel.
//
// - Name: Used with the PanelByName method of the TfcStatusPanels.
//
// - PopupMenu: The associated popupmenu of the panel.
//
// - Style: Determines what kind of information the panel displays.
//
// - Text: Determines what text the panel displays.
//
// - Width: Determines how wide the panel is. This value is a string but
// but can be only one of two types of values.
// - It can be an integer (i.e. 5, 25, 30, etc.)
// - It can be a percentage (i.e. 5%, 50%, 66%, etc.)
//
// Methods:
// - GetRect: Returns the rectangle of the panel.
//
// Events:
// - OnClick, OnDblClick, OnMouseDown, OnMouseUp, OnMouseMove:
// Standard mouse events equivalent to that of TControl.
//
// - OnDrawText: Event occurs immediately prior to drawing text onto the
// panel. The supplied Text variable can change to change
// the text that gets drawn.
//
// - OnTextChanged: Occurs immediately after the text for the panel
// changes.
//
}
TfcStatusPanel = class(TfcCollectionItem)
private
// Property Storage Variables
FCanvas: TCanvas; // Protected
FCol: Integer; // Public
FRow: Integer;
FBevel: TfcStatusPanelBevel;
FColor: TColor;
FComponent: TComponent;
FEnabled: Boolean;
FDrawTextEnabled: Boolean;
FInDrawText:Boolean;
FFont: TFont;
FHint: String;
FImageIndex: Integer;
FIndent: Integer;
FMargin: Integer;
FName: string;
FPaintWidth: Integer;
FPopupMenu: TPopupMenu;
FStyle: TfcStatusPanelStyle;
FText: string;
FCurDateTime: TDateTime;
FTextOptions: TfcCaptionText;
FWidth: string;
FOnClick: TNotifyEvent; // Events
FOnDblClick: TNotifyEvent;
FOnDrawText: TfcDrawTextEvent;
FOnMouseDown: TMouseEvent;
FOnMouseMove: TMouseMoveEvent;
FOnMouseUp: TMouseEvent;
FOnSetName: TNotifyEvent;
FOnTextChanged: TfcPanelTextChangedEvent;
FRect: TRect;
// Property Access Methods
function GetControl: TControl;
procedure SetBevel(Value: TfcStatusPanelBevel);
procedure SetColor(Value: TColor);
procedure SetComponent(Value: TComponent);
procedure SetEnabled(Value: Boolean);
procedure SetFont(Value:TFont);
procedure SetHint(Value:String);
procedure SetImageIndex(Value: Integer);
procedure SetIndent(Value:Integer);
procedure SetMargin(Value: Integer);
procedure SetName(const Value: string);
procedure SetStyle(Value: TfcStatusPanelStyle);
procedure SetText(const Value: string);
procedure SetWidth(Value: string);
protected
function GenerateName: string; virtual;
function GetDisplayName: string; override;
function GetStatusBar: TfcCustomStatusBar; virtual;
function StoreWidth: Boolean; virtual;
procedure FontChanged(Sender: TObject); virtual;
procedure Notification(AComponent: TComponent; Operation: TOperation); virtual;
// procedure ParentWndProc(var Message: TMessage); virtual;
// IfcTextControl
function GetTextEnabled: Boolean; virtual;
procedure AdjustBounds; virtual;
// Draw methods
function DoDrawDateTime: Boolean; virtual;
procedure Draw(ACanvas: TCanvas; ARect: TRect); virtual;
procedure DrawControl; virtual;
procedure DrawGlyph; virtual;
procedure DrawKeyboardState; virtual;
procedure DrawHint; virtual;
procedure DrawUserName; virtual;
procedure DrawComputerName; virtual;
procedure DrawRichEditStatus; virtual;
procedure DrawText(AText: string; ARect: TRect; AEnabled:Boolean); virtual;
// Overriden methods
procedure AssignTo(Dest: TPersistent); override;
// Event wrappers
procedure Click; dynamic;
procedure DblClick; dynamic;
procedure MouseDown(Button: TMouseButton; Shift: TShiftState;
X, Y: Integer); dynamic;
procedure MouseMove(Shift: TShiftState; X, Y: Integer); dynamic;
procedure MouseUp(Button: TMouseButton; Shift: TShiftState;
X, Y: Integer); dynamic;
procedure PanelTextChanged(Const Text:String); dynamic;
// Protected Properties
property Canvas: TCanvas read FCanvas;
property DrawTextEnabled: Boolean read FDrawTextEnabled write FDrawTextEnabled;
public
Patch: Variant;
constructor Create(Collection: TCollection); override;
destructor Destroy; override;
function ClientToScreen(p: TPoint): TPoint; virtual;
function GetRect: TRect; virtual;
procedure Invalidate; virtual;
// Public Properties
property Col: Integer read FCol;
property Control: TControl read GetControl;
property PaintWidth: Integer read FPaintWidth write FPaintWidth;
property Row: Integer read FRow;
property StatusBar: TfcCustomStatusBar read GetStatusBar;
property OnSetName: TNotifyEvent read FOnSetName write FOnSetName;
published
// Published Properties
property Bevel: TfcStatusPanelBevel read FBevel write SetBevel default pbLowered;
property Color: TColor read FColor write SetColor default clBtnFace;
property Component: TComponent read FComponent write SetComponent;
property Enabled: Boolean read FEnabled write SetEnabled default True;
property Font: TFont read FFont write SetFont;
property Hint : string read FHint write SetHint;
property ImageIndex: Integer read FImageIndex write SetImageIndex default 0;
property Indent : Integer read FIndent write SetIndent default 0;
property Margin: Integer read FMargin write SetMargin default 0;
property Name: string read FName write SetName;
property PopupMenu: TPopupMenu read FPopupMenu write FPopupMenu;
property Style: TfcStatusPanelStyle read FStyle write SetStyle default psTextOnly;
property Tag;
property Text : string read FText write SetText;
property TextOptions: TfcCaptionText read FTextOptions write FTextOptions;
property Width: string read FWidth write SetWidth stored StoreWidth;
property OnClick: TNotifyEvent read FOnClick write FOnClick;
property OnDblClick: TNotifyEvent read FOnDblClick write FOnDblClick;
property OnDrawText: TfcDrawTextEvent read FOnDrawText write FOnDrawText;
property OnMouseDown: TMouseEvent read FOnMouseDown write FOnMouseDown;
property OnMouseMove: TMouseMoveEvent read FOnMouseMove write FOnMouseMove;
property OnMouseUp: TMouseEvent read FOnMouseUp write FOnMouseUp;
property OnTextChanged: TfcPanelTextChangedEvent read FOnTextChanged write FOnTextChanged;
end;
{
// TfcStatusPanels
// Properties:
// - Items: Array property to retrieve a TfcStatusPanel.
//
// Methods:
// - Add: Method to add a new panel. Returns the newly created
// panel.
//
// - PanelByName: Returns the panel with the name that matches in the
// name that was passed in. Returns nil if no panels
// with that name are found.
//
}
TfcStatusPanels = class(TfcCollection)
private
FStatusBar: TfcCustomStatusBar;
// Property Access Methods
function GetItem(Index: Integer): TfcStatusPanel;
procedure SetItem(Index: Integer; Value: TfcStatusPanel);
protected
procedure RedrawIfNeeded(StyleToCheck: TfcStatusPanelStyle); virtual;
// Overriden Methods
function GetOwner: TPersistent; override;
procedure Update(Item: TCollectionItem); override;
// Protected Properties
property StatusBar: TfcCustomStatusBar read FStatusBar;
public
constructor Create(StatusBar: TfcCustomStatusBar; AStatusPanelClass: TfcStatusPanelClass);
function Add: TfcStatusPanel;
function PanelByName(AName: string): TfcStatusPanel;
// Public Properties
property Items[Index: Integer]: TfcStatusPanel read GetItem write SetItem; default;
end;
TDrawPanelEvent = procedure(StatusBar: TfcCustomStatusBar; Panel: TfcStatusPanel;
const Rect: TRect) of object;
TDrawKeyboardStateEvent = procedure(StatusBar: TfcCustomStatusBar; StatusPanel: TfcStatusPanel;
KeyIsOn: Boolean; Rect: TRect; var AText: string) of object;
{
// TfcCustomStatusBar
// Properties:
// - ImageList: The ImageList that panels whose style is set to psGlyph
// uses to render the image.
//
// - Panels: The instance of TfcStatusPanels that contains the panels
// of the status bar.
//
// - SimplePanel: Same as TStatusBar.SimplePanel
//
// - SimpleText: Same as TStatusBar.SimpleText
//
// - SizeGrip: Same as TStatusBar.SizeGrip
//
// Methods:
// - GetPanelFromPt: Returns the TfcStatusPanel located at the specified
// x and y coordinates.
//
// Events:
// - OnDrawKeyboardState: Event occurs before drawing the text for a
// panel whose style property is set to psOverwrite,
// psCapsLock, psScrollLock, or psNumLock. Used to customize
// the text that is displayed.
//
// - OnDrawPanel: Same as TStatusBar.OnDrawPanel
//
}
TfcCustomStatusBar = class(TWinControl)
private
// Property Storage Variables
FCanvas: TCanvas; // Protected
FLastSize: TSize;
FImageList: TCustomImageList; // Published
FPanels: TfcStatusPanels;
FSimplePanel: Boolean;
FSimpleText: string;
FSizeGrip: Boolean;
FSizing: Boolean;
{$ifdef fcDelphi3}
FOnResize: TNotifyEvent;
{$endif}
FOnDrawKeyboardState: TDrawKeyboardStateEvent; // Events
FOnDrawPanel: TDrawPanelEvent;
FStatusBarText: TfcStatusBarText; // 5/06/99 - PYW - Added StatusBarText property.
FDisableThemes: boolean;
// Property Access Methods
procedure SetPanels(Value: TfcStatusPanels);
procedure SetSimplePanel(Value: Boolean);
procedure SetSimpleText(const Value: string);
procedure SetSizeGrip(Value: Boolean);
function GetSizeGrip: boolean;
// Message Handlers
procedure CMShowingChanged(var Message: TMessage); message CM_SHOWINGCHANGED;
procedure CNDrawItem(var Message: TWMDrawItem); message CN_DRAWITEM;
procedure WMEraseBkgnd(var Message: TWMEraseBkgnd); message WM_ERASEBKGND;
procedure WMSize(var Message: TWMSize); message WM_SIZE;
procedure WMTimer(var Message: TWMTimer); message WM_TIMER;
protected
function GetCollectionClass: TfcStatusPanelsClass; virtual;
procedure DrawPanel(Panel: TfcStatusPanel; Rect: TRect); dynamic;
procedure Resize; {$ifdef fcDelphi3}virtual;{$else}override;{$endif}
procedure UpdatePanel(Index: Integer; DoInvalidate: Boolean);
procedure UpdatePanels; virtual;
// Overriden methods
procedure Click; override;
procedure CreateParams(var Params: TCreateParams); override;
procedure CreateWnd; override;
procedure DblClick; override;
procedure DestroyWnd; override;
procedure Loaded; override;
procedure MouseDown(Button: TMouseButton; Shift: TShiftState;
X, Y: Integer); override;
procedure MouseMove(Shift: TShiftState; X, Y: Integer); override;
procedure MouseUp(Button: TMouseButton; Shift: TShiftState;
X, Y: Integer); override;
procedure Notification(AComponent: TComponent; Operation: TOperation); override;
procedure WndProc(var Message: TMessage); override;
property Canvas: TCanvas read FCanvas;
public
Patch: Variant;
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
// function GetPriorityPanel(APriority: Integer): TfcStatusPanel;
// function GetOpenPriority: Integer;
procedure Invalidate; override;
function GetPanelFromPt(x, y: Integer): TfcStatusPanel; virtual;
procedure ComponentExclusive(Value: TComponent; Panel: TfcStatusPanel; ThisStatusBarOnly: Boolean);
// Public Properties
property Images: TCustomImageList read FImageList write FImageList;
property Panels: TfcStatusPanels read FPanels write SetPanels;
property SimplePanel: Boolean read FSimplePanel write SetSimplePanel;
property SimpleText: string read FSimpleText write SetSimpleText;
property SizeGrip: Boolean read GetSizeGrip write SetSizeGrip default True;
property OnDrawKeyboardState: TDrawKeyboardStateEvent read FOnDrawKeyboardState write FOnDrawKeyboardState;
property OnDrawPanel: TDrawPanelEvent read FOnDrawPanel write FOnDrawPanel;
{$ifdef fcDelphi3}
property OnResize: TNotifyEvent read FOnResize write FOnResize;
{$endif}
property StatusBarText: TfcStatusBarText read FStatusBarText write FStatusBarText;
property DisableThemes : boolean read FDisableThemes write FDisableThemes default False;
end;
TfcStatusBar = class(TfcCustomStatusBar)
published
property DisableThemes;
{$ifdef fcDelphi4Up}
property Anchors;
property Constraints;
{$endif}
property Align default alBottom;
property DragCursor;
property DragMode;
property Enabled;
property Font;
property Images;
property Panels;
property ParentFont;
property ParentShowHint;
property PopupMenu;
property ShowHint;
property SimplePanel;
property SimpleText;
property SizeGrip;
property StatusBarText;
property Visible;
property OnClick;
property OnDblClick;
property OnDragDrop;
property OnDragOver;
property OnEndDrag;
property OnMouseDown;
property OnMouseMove;
property OnMouseUp;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -