📄 tntjvtooledit.pas
字号:
{-----------------------------------------------------------------------------
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 Original Code is: JvToolEdit.PAS, released on 2002-07-04.
The Initial Developers of the Original Code are: Fedor Koshevnikov, Igor Pavluk and Serge Korolev
Copyright (c) 1997, 1998 Fedor Koshevnikov, Igor Pavluk and Serge Korolev
Copyright (c) 2001,2002 SGB Software
All Rights Reserved.
Contributers:
Rob den Braasem [rbraasem att xs4all dott nl]
Polaris Software
rblaurindo
Andreas Hausladen
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:
(rb) Move button related functionality from TTntJvCustomComboEdit to TTntJvEditButton
-----------------------------------------------------------------------------}
// $Id: JvToolEdit.pas,v 1.187 2006/01/12 16:35:09 elahn Exp $
{ 03/22/2006: Solved an important bug in ClipFilename used in TTntJvFilenameEdit }
unit TntJvToolEdit;
{$I jvcl.inc}
{$I crossplatform.inc}
{$D+}
interface
uses
{$IFDEF UNITVERSIONING}
JclUnitVersioning,
{$ENDIF UNITVERSIONING}
{$IFDEF CLR}
Types, WinUtils, System.Text, System.IO, System.Reflection,
System.Runtime.InteropServices,
{$ENDIF CLR}
{$IFDEF MSWINDOWS}
Windows, Messages, ShellAPI, ActiveX,
{$ENDIF MSWINDOWS}
{$IFDEF VCL}
ShlObj,
{$ENDIF VCL}
{$IFDEF HAS_UNIT_VARIANTS}
Variants,
{$ENDIF HAS_UNIT_VARIANTS}
SysUtils, Classes, Graphics, TntGraphics, Controls, Forms, Dialogs, StdCtrls, Menus,
Buttons, FileCtrl, TntFileCtrl2, Mask, ImgList, ActnList, ExtDlgs,
{$IFDEF VisualCLX}
Qt, QComboEdits, JvQExComboEdits, QWindows,
{$ENDIF VisualCLX}
{JvExControls,} JvSpeedButton, TntJvSpeedButton, JvTypes, JvExMask, JvExForms, JvButton, JvToolEdit,
TntJvExControls, TntClasses, TntDialogs, TntJvExMask;
(***
const
scAltDown = scAlt + VK_DOWN;
DefEditBtnWidth = 21;
CM_POPUPCLOSEUP = CM_BASE + $0300; // arbitrary value
{$IFDEF CLR}
type
[ComImport, InterfaceTypeAttribute(ComInterfaceType.InterfaceIsIUnknown)]
IUnknown = IInterface;
{$ENDIF CLR}
{$IFNDEF COMPILER7_UP}
// Autocomplete stuff for Delphi 5 and 6. (missing in ShlObj)
type
IAutoComplete = interface(IUnknown)
['{00bb2762-6a77-11d0-a535-00c04fd7d062}']
function Init(hwndEdit: THandle; punkACL: IUnknown;
pwszRegKeyPath: LPCWSTR; pwszQuickComplete: LPCWSTR): HRESULT; stdcall;
function Enable(fEnable: BOOL): HRESULT; stdcall;
end;
const
{ IAutoComplete2 options }
ACO_NONE = 0;
ACO_AUTOSUGGEST = $1;
ACO_AUTOAPPEND = $2;
ACO_SEARCH = $4;
ACO_FILTERPREFIXES = $8;
ACO_USETAB = $10;
ACO_UPDOWNKEYDROPSLIST = $20;
ACO_RTLREADING = $40;
type
IAutoComplete2 = interface(IAutoComplete)
['{EAC04BC0-3791-11d2-BB95-0060977B464C}']
function SetOptions(dwFlag: DWORD): HRESULT; stdcall;
function GetOptions(var dwFlag: DWORD): HRESULT; stdcall;
end;
{$ENDIF !COMPILER7_UP}
// C++ Builder needs this HPPEMIT in order for the generated header to compile.
{$HPPEMIT 'typedef DelphiInterface<IEnumString> _di_IEnumString;'}
**)
type
TFileExtW = type WideString;
(**
TCloseUpEvent = procedure(Sender: TObject; Accept: Boolean) of object;
TPopupAlign = (epaRight, epaLeft);
**)
{$IFDEF VisualCLX}
TTntJvPopupWindowBase = TTntJvExCustomForm; {???}
{$ENDIF VisualCLX}
{$IFDEF VCL}
TTntJvPopupWindowBase = TTntJvExCustomControl;
{$ENDIF VCL}
TTntJvPopupWindow = class(TTntJvPopupWindowBase)
private
FEditor: TWinControl;
FCloseUp: TCloseUpEvent;
{$IFDEF VCL}
procedure WMMouseActivate(var Msg: TMessage); message WM_MOUSEACTIVATE;
procedure WMActivate(var Msg: TWMActivate); message WM_ACTIVATE;
{$ENDIF VCL}
protected
FActiveControl: TWinControl;
FIsFocusable: Boolean;
{$IFDEF VCL}
procedure CreateParams(var Params: TCreateParams); override;
{$ENDIF VCL}
{$IFDEF VisualCLX}
procedure SetParent(const Value: TWidgetControl); override;
function WidgetFlags: Integer; override;
{$ENDIF VisualCLX}
function GetValue: Variant; virtual; abstract;
procedure SetValue(const Value: Variant); virtual; abstract;
procedure InvalidateEditor;
procedure MouseUp(Button: TMouseButton; Shift: TShiftState;
X, Y: Integer); override;
procedure CloseUp(Accept: Boolean); virtual;
{$IFDEF CLR}
procedure KeyDown(var Key: Word; Shift: TShiftState); override;
procedure KeyPress(var Key: Char); override;
{$ENDIF CLR}
public
constructor Create(AOwner: TComponent); override;
function GetPopupText: WideString; virtual;
procedure Hide;
procedure Show(Origin: TPoint); virtual; // Polaris
{ Determines the ctrl that receives the keyboard input if the dropdown
window is showing, but the combo edit still has focus }
property ActiveControl: TWinControl read FActiveControl;
{ Determines whether the popup window may be activated }
property IsFocusable: Boolean read FIsFocusable;
property OnCloseUp: TCloseUpEvent read FCloseUp write FCloseUp;
end;
TTntJvEditButton = class(TTntJvImageSpeedButton)
private
FNoAction: Boolean;
{$IFDEF VCL}
procedure WMContextMenu(var Msg: TWMContextMenu); message WM_CONTEXTMENU;
{$ENDIF VCL}
function GetGlyph: TBitmap;
function GetNumGlyphs: TJvNumGlyphs;
function GetUseGlyph: Boolean;
procedure SetGlyph(const Value: TBitmap);
procedure SetNumGlyphs(Value: TJvNumGlyphs);
protected
{$IFDEF JVCLThemesEnabled}
FDrawThemedDropDownBtn: Boolean;
{$ENDIF JVCLThemesEnabled}
FStandard: Boolean; // Polaris
procedure MouseDown(Button: TMouseButton; Shift: TShiftState;
X, Y: Integer); override;
procedure PaintImage(Canvas: TCanvas; ARect: TRect; const Offset: TPoint;
AState: TJvButtonState; DrawMark: Boolean); override;
procedure Paint; override;
public
constructor Create(AOwner: TComponent); override;
procedure Click; override;
property UseGlyph: Boolean read GetUseGlyph;// write FDrawGlyph;
property Glyph: TBitmap read GetGlyph write SetGlyph;
property NumGlyphs: TJvNumGlyphs read GetNumGlyphs write SetNumGlyphs;
end;
(****
TGlyphKind = (gkCustom, gkDefault, gkDropDown, gkEllipsis);
TJvImageKind = (ikCustom, ikDefault, ikDropDown, ikEllipsis);
***)
TTntJvCustomComboEdit = class;
TTntJvCustomComboEditActionLink = class(TWinControlActionLink)
protected
function IsCaptionLinked: Boolean; override;
function IsHintLinked: Boolean; override;
function IsImageIndexLinked: Boolean; override;
function IsOnExecuteLinked: Boolean; override;
function IsShortCutLinked: Boolean; override;
procedure SetHint(const Value: THintString); override;
procedure SetImageIndex(Value: Integer); override;
procedure SetOnExecute(Value: TNotifyEvent); override;
procedure SetShortCut(Value: TShortCut); override;
end;
TTntJvCustomComboEditActionLinkClass = class of TTntJvCustomComboEditActionLink;
(***
{$IFDEF VCL}
TJvAutoCompleteOption = (acoAutoSuggest, acoAutoAppend, acoSearch,
acoFilterPrefixes, acoUseTab, acoUpDownKeyDropsList, acoRTLReading);
TJvAutoCompleteOptions = set of TJvAutoCompleteOption;
TJvAutoCompleteFileOption = (acfFileSystem, acfFileSysDirs, acfURLHistory, acfURLMRU);
TJvAutoCompleteFileOptions = set of TJvAutoCompleteFileOption;
{$ENDIF VCL}
***)
{$IFDEF VCL}
TTntJvCustomComboEditBase = TTntJvExCustomMaskEdit; {???}
{$ENDIF VCL}
{$IFDEF VisualCLX}
TTntJvCustomComboEditBase = TTntJvExCustomComboMaskEdit;
{$ENDIF VisualCLX}
TTntJvCustomComboEdit = class(TTntJvCustomComboEditBase)
private
FOnButtonClick: TNotifyEvent;
FOnPopupShown: TNotifyEvent;
FOnPopupHidden: TNotifyEvent;
FClickKey: TShortCut;
FReadOnly: Boolean;
FDirectInput: Boolean;
FAlwaysEnableButton: Boolean;
FAlwaysShowPopup: Boolean;
FPopupAlign: TPopupAlign;
FGroupIndex: Integer; // RDB
FDisabledColor: TColor; // RDB
FDisabledTextColor: TColor; // RDB
FOnKeyDown: TKeyEvent; // RDB
FImages: TCustomImageList;
FImageIndex: TImageIndex;
FImageKind: TJvImageKind;
FNumGlyphs: Integer;
FStreamedButtonWidth: Integer;
FStreamedFixedWidth: Boolean;
FOnEnabledChanged: TNotifyEvent;
{ We hide the button by setting its width to 0, thus we have to store the
width the button should have when shown again in FSavedButtonWidth: }
FSavedButtonWidth: Integer;
{$IFDEF VCL}
FAlignment: TAlignment;
FAutoCompleteIntf: IAutoComplete;
FAutoCompleteItems: TTntStrings;
FAutoCompleteOptions: TJvAutoCompleteOptions;
FAutoCompleteSource: IEnumString;
procedure SetAutoCompleteItems(Strings: TTntStrings);
procedure SetAutoCompleteOptions(const Value: TJvAutoCompleteOptions);
procedure SetAlignment(Value: TAlignment);
function GetFlat: Boolean;
procedure ReadCtl3D(Reader: TReader);
procedure SetFlat(const Value: Boolean);
function IsFlatStored: Boolean;
{$ENDIF VCL}
function BtnWidthStored: Boolean;
function GetButtonFlat: Boolean;
function GetButtonHint: WideString;
function GetButtonWidth: Integer;
function GetDirectInput: Boolean;
function GetGlyph: TBitmap;
function GetGlyphKind: TGlyphKind;
function GetMinHeight: Integer;
function GetNumGlyphs: TNumGlyphs;
function GetPopupVisible: Boolean;
function GetShowButton: Boolean;
function GetTextHeight: Integer;
function IsImageIndexStored: Boolean;
function IsCustomGlyph: Boolean;
procedure EditButtonClick(Sender: TObject);
procedure ReadGlyphKind(Reader: TReader);
procedure RecreateGlyph;
procedure SetButtonFlat(const Value: Boolean);
procedure SetButtonHint(const Value: WideString);
procedure SetButtonWidth(Value: Integer);
procedure SetGlyph(Value: TBitmap);
procedure SetGlyphKind(Value: TGlyphKind);
procedure SetImageIndex(const Value: TImageIndex);
procedure SetImageKind(const Value: TJvImageKind);
procedure SetImages(const Value: TCustomImageList);
procedure SetNumGlyphs(const Value: TNumGlyphs);
procedure SetShowButton(const Value: Boolean);
{$IFDEF COMPILER6_UP}
procedure UpdateBtnBounds(var NewLeft, NewTop, NewWidth, NewHeight: Integer);
{$ENDIF COMPILER6_UP}
{ (rb) renamed from UpdateEdit }
procedure UpdateGroup; // RDB
{$IFDEF VCL}
procedure CMWantSpecialKey(var Msg: TCMWantSpecialKey); message CM_WANTSPECIALKEY;
procedure CMBiDiModeChanged(var Msg: TMessage); message CM_BIDIMODECHANGED;
procedure CMCancelMode(var Msg: TCMCancelMode); message CM_CANCELMODE;
procedure CMCtl3DChanged(var Msg: TMessage); message CM_CTL3DCHANGED;
procedure CNCtlColor(var Msg: TMessage); message CN_CTLCOLOREDIT;
procedure WMPaint(var Msg: TWMPaint); message WM_PAINT; // RDB
procedure CMPopupCloseup(var Msg: TMessage); message CM_POPUPCLOSEUP;
{$IFDEF JVCLThemesEnabled}
procedure WMNCPaint(var Msg: TWMNCPaint); message WM_NCPAINT;
procedure WMNCCalcSize(var Msg: TWMNCCalcSize); message WM_NCCALCSIZE;
{$ENDIF JVCLThemesEnabled}
procedure WMNCHitTest(var Msg: TWMNCHitTest); message WM_NCHITTEST;
{$ENDIF VCL}
protected
FButton: TTntJvEditButton; // Polaris
FBtnControl: TWinControl;
FPopupVisible: Boolean; // Polaris
FFocused: Boolean; // Polaris
FPopup: TWinControl;
{$IFDEF COMPILER6_UP}
{$IFDEF VCL}
procedure CustomAlignPosition(Control: TControl; var NewLeft, NewTop, NewWidth,
NewHeight: Integer; var AlignRect: TRect; AlignInfo: TAlignInfo); override;
{$ENDIF VCL}
{$IFDEF VisualCLX}
procedure CustomAlignPosition(Control: TControl; var NewLeft,
NewTop, NewWidth, NewHeight: Integer; var AlignRect: TRect); override;
{$ENDIF VisualCLX}
{$ENDIF COMPILER6_UP}
{$IFDEF VCL}
procedure WndProc(var Msg: TMessage); override;
{$ENDIF VCL}
procedure WMClear(var Msg: TMessage); message WM_CLEAR;
procedure WMCut(var Msg: TMessage); message WM_CUT;
procedure WMPaste(var Msg: TMessage); message WM_PASTE;
procedure AdjustSize; override;
procedure FocusKilled(NextWnd: THandle); override;
procedure FocusSet(PrevWnd: THandle); override;
procedure EnabledChanged; override;
procedure FontChanged; override;
procedure DoEnter; override;
procedure DoCtl3DChanged; virtual;
function DoEraseBackground(Canvas: TCanvas; Param: Integer): Boolean; override;
{ Repositions the child controls; checkbox }
procedure UpdateControls; virtual;
{ Updates the margins of the edit box }
procedure UpdateMargins; dynamic;
{ Returns the margins of the edit box }
procedure GetInternalMargins(var ALeft, ARight: Integer); virtual;
procedure CreatePopup; virtual;
procedure HidePopup; virtual; // (ahuser): WARNING: Do not release or free the component in HidePopup -> else AV in MouseUp
procedure ShowPopup(Origin: TPoint); virtual;
{$IFDEF VisualCLX}
procedure DoFlatChanged; override;
procedure Paint; override;
{$ENDIF VisualCLX}
function AcceptPopup(var Value: Variant): Boolean; virtual;
function EditCanModify: Boolean; override;
function GetActionLinkClass: TControlActionLinkClass; override;
function GetPopupValue: Variant; virtual;
function GetReadOnly: Boolean; virtual;
function GetSettingCursor: Boolean;
procedure AcceptValue(const Value: Variant); virtual;
procedure ActionChange(Sender: TObject; CheckDefaults: Boolean); override;
procedure AdjustHeight;
procedure ButtonClick; dynamic;
procedure Change; override;
procedure CreateWnd; override;
{$IFDEF VCL}
procedure CreateParams(var Params: TCreateParams); override;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -