📄 rm_jvjvclutils.pas
字号:
{$IFDEF MSWINDOWS}
{ TargetFileName - if FileName is ShortCut returns filename ShortCut linked to }
function TargetFileName(const FileName: TFileName): TFileName;
{ return filename ShortCut linked to }
function ResolveLink(const HWND: THandle; const LinkFile: TFileName;
var FileName: TFileName): HRESULT;
{$ENDIF MSWINDOWS}
type
TProcObj = procedure of object;
procedure ExecAfterPause(Proc: TProcObj; Pause: Integer);
{$ENDIF !CLR}
{ end JvUtils }
{ begin JvAppUtils}
function GetDefaultSection(Component: TComponent): string;
function GetDefaultIniName: string;
type
TOnGetDefaultIniName = function: string;
TPlacementOption = (fpState, fpSize, fpLocation, fpActiveControl);
TPlacementOptions = set of TPlacementOption;
TPlacementOperation = (poSave, poRestore);
var
OnGetDefaultIniName: TOnGetDefaultIniName = nil;
DefCompanyName: string = '';
RegUseAppTitle: Boolean = False;
function GetDefaultIniRegKey: string;
function FindForm(FormClass: TFormClass): TForm;
function FindShowForm(FormClass: TFormClass; const Caption: string): TForm;
function ShowDialog(FormClass: TFormClass): Boolean;
function InstantiateForm(FormClass: TFormClass; var Reference): TForm;
function StrToIniStr(const Str: string): string;
function IniStrToStr(const Str: string): string;
// Ini Utilitie Functions
// Added by RDB
function FontStylesToString(Styles: TFontStyles): string;
function StringToFontStyles(const Styles: string): TFontStyles;
{$IFDEF VCL}
function FontToString(Font: TFont): string;
function StringToFont(const Str: string): TFont;
{$ENDIF VCL}
function RectToStr(Rect: TRect): string;
function StrToRect(const Str: string; const Def: TRect): TRect;
function PointToStr(P: TPoint): string;
function StrToPoint(const Str: string; const Def: TPoint): TPoint;
{
function IniReadString(IniFile: TObject; const Section, Ident,
Default: string): string;
procedure IniWriteString(IniFile: TObject; const Section, Ident,
Value: string);
function IniReadInteger(IniFile: TObject; const Section, Ident: string;
Default: Longint): Longint;
procedure IniWriteInteger(IniFile: TObject; const Section, Ident: string;
Value: Longint);
function IniReadBool(IniFile: TObject; const Section, Ident: string;
Default: Boolean): Boolean;
procedure IniWriteBool(IniFile: TObject; const Section, Ident: string;
Value: Boolean);
procedure IniReadSections(IniFile: TObject; Strings: TStrings);
procedure IniEraseSection(IniFile: TObject; const Section: string);
procedure IniDeleteKey(IniFile: TObject; const Section, Ident: string);
}
{$IFDEF VCL}
procedure AppBroadcast(Msg, wParam: Longint; lParam: Longint);
procedure AppTaskbarIcons(AppOnly: Boolean);
{$ENDIF VCL}
{ end JvAppUtils }
{ begin JvGraph }
type
TMappingMethod = (mmHistogram, mmQuantize, mmTrunc784, mmTrunc666,
mmTripel, mmGrayscale);
function GetBitmapPixelFormat(Bitmap: TBitmap): TPixelFormat;
{$IFDEF VCL}
function GetPaletteBitmapFormat(Bitmap: TBitmap): TPixelFormat;
{$IFNDEF CLR}
procedure SetBitmapPixelFormat(Bitmap: TBitmap; PixelFormat: TPixelFormat;
Method: TMappingMethod);
function BitmapToMemoryStream(Bitmap: TBitmap; PixelFormat: TPixelFormat;
Method: TMappingMethod): TMemoryStream;
procedure GrayscaleBitmap(Bitmap: TBitmap);
function BitmapToMemory(Bitmap: TBitmap; Colors: Integer): TStream;
procedure SaveBitmapToFile(const FileName: string; Bitmap: TBitmap;
Colors: Integer);
{$ENDIF !CLR}
function ScreenPixelFormat: TPixelFormat;
function ScreenColorCount: Integer;
var
DefaultMappingMethod: TMappingMethod = mmHistogram;
{$ENDIF VCL}
procedure TileImage(Canvas: TCanvas; Rect: TRect; Image: TGraphic);
function ZoomImage(ImageW, ImageH, MaxW, MaxH: Integer; Stretch: Boolean): TPoint;
type
TJvGradientOptions = class(TPersistent)
private
FStartColor: TColor;
FEndColor: TColor;
FDirection: TFillDirection;
FStepCount: Byte;
FVisible: Boolean;
FOnChange: TNotifyEvent;
procedure SetStartColor(Value: TColor);
procedure SetEndColor(Value: TColor);
procedure SetDirection(Value: TFillDirection);
procedure SetStepCount(Value: Byte);
procedure SetVisible(Value: Boolean);
protected
procedure Changed; dynamic;
public
constructor Create;
procedure Assign(Source: TPersistent); override;
procedure Draw(Canvas: TCanvas; Rect: TRect);
published
property Direction: TFillDirection read FDirection write SetDirection default fdTopToBottom;
property EndColor: TColor read FEndColor write SetEndColor default clGray;
property StartColor: TColor read FStartColor write SetStartColor default clSilver;
property StepCount: Byte read FStepCount write SetStepCount default 64;
property Visible: Boolean read FVisible write SetVisible default False;
property OnChange: TNotifyEvent read FOnChange write FOnChange;
end;
{ end JvGraph }
type
// equivalent of TPoint, but that can be a published property for BCB
TJvPoint = class(TPersistent)
private
FY: Longint;
FX: Longint;
FOnChange: TNotifyEvent;
procedure SetX(Value: Longint);
procedure SetY(Value: Longint);
protected
procedure DoChange;
public
procedure Assign(Source: TPersistent); override;
property OnChange: TNotifyEvent read FOnChange write FOnChange;
published
property X: Longint read FX write SetX;
property Y: Longint read FY write SetY;
end;
// equivalent of TRect, but that can be a published property for BCB
TJvRect = class(TPersistent)
private
FTopLeft: TJvPoint;
FBottomRight: TJvPoint;
FOnChange: TNotifyEvent;
function GetBottom: Integer;
function GetLeft: Integer;
function GetRight: Integer;
function GetTop: Integer;
procedure SetBottom(Value: Integer);
procedure SetLeft(Value: Integer);
procedure SetRight(Value: Integer);
procedure SetTop(Value: Integer);
procedure SetBottomRight(Value: TJvPoint);
procedure SetTopLeft(Value: TJvPoint);
procedure PointChange(Sender: TObject);
function GetHeight: Integer;
function GetWidth: Integer;
procedure SetHeight(Value: Integer);
procedure SetWidth(Value: Integer);
protected
procedure DoChange;
public
constructor Create;
destructor Destroy; override;
procedure Assign(Source: TPersistent); override;
property TopLeft: TJvPoint read FTopLeft write SetTopLeft;
property BottomRight: TJvPoint read FBottomRight write SetBottomRight;
property Width: Integer read GetWidth write SetWidth;
property Height: Integer read GetHeight write SetHeight;
property OnChange: TNotifyEvent read FOnChange write FOnChange;
published
property Left: Integer read GetLeft write SetLeft;
property Top: Integer read GetTop write SetTop;
property Right: Integer read GetRight write SetRight;
property Bottom: Integer read GetBottom write SetBottom;
end;
{ begin JvCtrlUtils }
//------------------------------------------------------------------------------
// ToolBarMenu
//------------------------------------------------------------------------------
procedure JvCreateToolBarMenu(AForm: TForm; AToolBar: TToolBar;
AMenu: TMainMenu = nil);
//------------------------------------------------------------------------------
// ListView functions
//------------------------------------------------------------------------------
type
{$IFDEF CLR}
TJvLVItemStateData = record
Caption: string;
Data: TObject;
Focused: Boolean;
Selected: Boolean;
end;
PJvLVItemStateData = TJvLVItemStateData;
{$ELSE}
PJvLVItemStateData = ^TJvLVItemStateData;
TJvLVItemStateData = record
Caption: string;
Data: Pointer;
Focused: Boolean;
Selected: Boolean;
end;
{$ENDIF CLR}
{ listview functions }
function ConvertStates(const State: Integer): TItemStates;
function ChangeHasDeselect(const peOld, peNew: TItemStates): Boolean;
function ChangeHasSelect(const peOld, peNew: TItemStates): Boolean;
function ChangeHasDefocus(const peOld, peNew: TItemStates): Boolean;
function ChangeHasFocus(const peOld, peNew: TItemStates): Boolean;
function GetListItemColumn(const pcItem: TListItem; piIndex: Integer): string;
procedure JvListViewToStrings(ListView: TListView; Strings: TStrings;
SelectedOnly: Boolean = False; Headers: Boolean = True);
function JvListViewSafeSubItemString(Item: TListItem; SubItemIndex: Integer): string;
procedure JvListViewSortClick(Column: TListColumn;
AscendingSortImage: Integer = -1; DescendingSortImage: Integer = -1);
procedure JvListViewCompare(ListView: TListView; Item1, Item2: TListItem;
var Compare: Integer);
procedure JvListViewSelectAll(ListView: TListView; Deselect: Boolean = False);
function JvListViewSaveState(ListView: TListView): TJvLVItemStateData;
function JvListViewRestoreState(ListView: TListView; Data: TJvLVItemStateData;
MakeVisible: Boolean = True; FocusFirst: Boolean = False): Boolean;
{$IFDEF VCL}
function JvListViewGetOrderedColumnIndex(Column: TListColumn): Integer;
procedure JvListViewSetSystemImageList(ListView: TListView);
{$ENDIF VCL}
//------------------------------------------------------------------------------
// MessageBox
//------------------------------------------------------------------------------
function JvMessageBox(const Text, Caption: string; Flags: DWORD): Integer; overload;
function JvMessageBox(const Text: string; Flags: DWORD): Integer; overload;
{ end JvCtrlUtils }
procedure UpdateTrackFont(TrackFont, Font: TFont; TrackOptions: TJvTrackFontOptions);
// Returns the size of the image
// used for checkboxes and radiobuttons.
// Originally from Mike Lischke
function GetDefaultCheckBoxSize: TSize;
function CanvasMaxTextHeight(Canvas: TCanvas): Integer;
{$IFDEF MSWINDOWS}
// AllocateHWndEx works like Classes.AllocateHWnd but does not use any virtual memory pages
function AllocateHWndEx(Method: TWndMethod; const AClassName: string = ''): THandle;
// DeallocateHWndEx works like Classes.DeallocateHWnd but does not use any virtual memory pages
procedure DeallocateHWndEx(Wnd: THandle);
function JvMakeObjectInstance(Method: TWndMethod): {$IFDEF CLR}TFNWndProc{$ELSE}Pointer{$ENDIF};
procedure JvFreeObjectInstance(ObjectInstance: {$IFDEF CLR}TFNWndProc{$ELSE}Pointer{$ENDIF});
{$ENDIF MSWINDOWS}
function GetAppHandle: THandle;
// DrawArrow draws a standard arrow in any of four directions and with the specifed color.
// Rect is the area to draw the arrow in and also defines the size of the arrow
// Note that this procedure might shrink Rect so that it's width and height is always
// the same and the width and height are always even, i.e calling with
// Rect(0,0,12,12) (odd) is the same as calling with Rect(0,0,11,11) (even)
// Direction defines the direction of the arrow. If Direction is akLeft, the arrow point is
// pointing to the left
procedure DrawArrow(Canvas: TCanvas; Rect: TRect; Color: TColor = clBlack; Direction: TAnchorKind = akBottom);
function IsPositiveResult(Value: TModalResult): Boolean;
function IsNegativeResult(Value: TModalResult): Boolean;
function IsAbortResult(const Value: TModalResult): Boolean;
function StripAllFromResult(const Value: TModalResult): TModalResult;
// returns either BrightColor or DarkColor depending on the luminance of AColor
// This function gives the same result (AFAIK) as the function used in Windows to
// calculate the desktop icon text color based on the desktop background color
function SelectColorByLuminance(AColor, DarkColor, BrightColor: TColor): TColor;
// (peter3) implementation moved from JvHTControls.
type
TJvHTMLCalcType = (htmlShow, htmlCalcWidth, htmlCalcHeight);
procedure HTMLDrawTextEx(Canvas: TCanvas; Rect: TRect;
const State: TOwnerDrawState; const Text: string; var Width: Integer;
CalcType: TJvHTMLCalcType; MouseX, MouseY: Integer; var MouseOnLink: Boolean;
var LinkName: string; Scale: Integer = 100);
function HTMLDrawText(Canvas: TCanvas; Rect: TRect;
const State: TOwnerDrawState; const Text: string; Scale: Integer = 100): string;
function HTMLTextWidth(Canvas: TCanvas; Rect: TRect;
const State: TOwnerDrawState; const Text: string; Scale: Integer = 100): Integer;
function HTMLPlainText(const Text: string): string;
function HTMLTextHeight(Canvas: TCanvas; const Text: string; Scale: Integer = 100): Integer;
function HTMLPrepareText(const Text: string): string;
// This type is used to allow an easy migration from a TBitmap property to a
// TPicture property. It is, for instance, used in TJvXPButton so that users
// migrating to the JVCL can still open their applications and benefit
// automatically from the change of format. The whole point is that a TPicture
// can also contain an Icon, which could be a valid source for a button glyph.
type
TJvPicture = class (TPicture)
private
procedure ReadBitmapData(Stream: TStream);
protected
procedure DefineProperties(Filer: TFiler); override;
end;
{$IFDEF UNITVERSIONING}
const
UnitVersioning: TUnitVersionInfo = (
RCSfile: '$RCSfile$';
Revision: '$Revision: 10476 $';
Date: '$Date: 2006-04-13 07:06:45 -0700 (Thu, 13 Apr 2006) $';
LogPath: 'JVCL\run'
);
{$ENDIF UNITVERSIONING}
implementation
uses
SysConst,
{$IFDEF VCL}
Consts,
{$ENDIF VCL}
{$IFDEF MSWINDOWS}
CommCtrl, MMSystem, ShlObj, ActiveX,
{$ENDIF MSWINDOWS}
{$IFDEF VisualCLX}
QConsts,
{$ENDIF VisualCLX}
Math,
{JclSysInfo,}
rm_JvConsts, rm_JvResources;
{$R rm_JvConsts.res}
const
{$IFDEF MSWINDOWS}
RC_ControlRegistry = 'Control Panel\Desktop';
RC_WallPaperStyle = 'WallpaperStyle';
RC_WallpaperRegistry = 'Wallpaper';
RC_TileWallpaper = 'TileWallpaper';
RC_RunCpl = 'rundll32.exe shell32,Control_RunDLL ';
{$ENDIF MSWINDOWS}
function GetAppHandle: THandle;
begin
{$IFDEF VCL}
Result := Application.Handle;
{$ENDIF VCL}
{$IFDEF VisualCLX}
Result := Application.AppWidget;
{$ENDIF VisualCLX}
end;
type
TWaitCursor = class(TInterfacedObject, IInterface)
private
FCursor: TCursor;
public
constructor Create(ACursor: TCursor);
destructor Destroy; override;
end;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -