📄 rxtooledit.pas
字号:
FAcceptFiles := Value;
end;
end;
procedure TFileDirEdit.DisableSysErrors;
begin
FErrMode := SetErrorMode(SEM_NOOPENFILEERRORBOX or SEM_FAILCRITICALERRORS);
end;
procedure TFileDirEdit.EnableSysErrors;
begin
SetErrorMode(FErrMode);
FErrMode := 0;
end;
procedure TFileDirEdit.WMDropFiles(var Msg: TWMDropFiles);
var
AFileName: array[0..255] of Char;
I, Num: Cardinal;
begin
Msg.Result := 0;
try
{$IFDEF WIN32}
Num := DragQueryFile(Msg.Drop, $FFFFFFFF, nil, 0);
{$ELSE}
Num := DragQueryFile(Msg.Drop, $FFFF, nil, 0);
{$ENDIF}
if Num > 0 then begin
ClearFileList;
for I := 0 to Num - 1 do begin
DragQueryFile(Msg.Drop, I, PChar(@AFileName), Pred(SizeOf(AFileName)));
ReceptFileDir(StrPas(AFileName));
if not FMultipleDirs then Break;
end;
if Assigned(FOnDropFiles) then FOnDropFiles(Self);
end;
finally
DragFinish(Msg.Drop);
end;
end;
procedure TFileDirEdit.ClearFileList;
begin
end;
{ TFilenameEdit }
function ClipFilename(const FileName: string): string;
var
Params: string;
begin
if FileExists(FileName) then Result := FileName
else SplitCommandLine(FileName, Result, Params);
end;
function ExtFilename(const FileName: string): string;
begin
if (Pos(' ', FileName) > 0) and (FileName[1] <> '"') then
Result := Format('"%s"', [FileName])
else Result := FileName;
end;
constructor TFilenameEdit.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
CreateEditDialog;
end;
procedure TFilenameEdit.CreateEditDialog;
var
NewDialog: TOpenDialog;
begin
case FDialogKind of
dkOpen: NewDialog := TOpenDialog.Create(Self);
{$IFDEF RX_D3}
dkOpenPicture: NewDialog := TOpenPictureDialog.Create(Self);
dkSavePicture: NewDialog := TSavePictureDialog.Create(Self);
{$ENDIF}
else {dkSave} NewDialog := TSaveDialog.Create(Self);
end;
try
if FDialog <> nil then begin
with NewDialog do begin
DefaultExt := FDialog.DefaultExt;
FileEditStyle := FDialog.FileEditStyle;
FileName := FDialog.FileName;
Filter := FDialog.Filter;
FilterIndex := FDialog.FilterIndex;
InitialDir := FDialog.InitialDir;
HistoryList := FDialog.HistoryList;
Files.Assign(FDialog.Files);
Options := FDialog.Options;
Title := FDialog.Title;
end;
FDialog.Free;
end
else begin
NewDialog.Title := LoadStr(SBrowse);
NewDialog.Filter := LoadStr(SDefaultFilter);
NewDialog.Options := [ofHideReadOnly];
end;
finally
FDialog := NewDialog;
end;
end;
function TFilenameEdit.IsCustomTitle: Boolean;
begin
Result := CompareStr(LoadStr(SBrowse), FDialog.Title) <> 0;
end;
function TFilenameEdit.IsCustomFilter: Boolean;
begin
Result := CompareStr(LoadStr(SDefaultFilter), FDialog.Filter) <> 0;
end;
procedure TFilenameEdit.ButtonClick;
var
Temp: string;
Action: Boolean;
begin
inherited ButtonClick;
Temp := inherited Text;
Action := True;
Temp := ClipFilename(Temp);
DoBeforeDialog(Temp, Action);
if not Action then Exit;
if ValidFileName(Temp) then
try
if DirExists(ExtractFilePath(Temp)) then
SetInitialDir(ExtractFilePath(Temp));
if (ExtractFileName(Temp) = '') or
not ValidFileName(ExtractFileName(Temp)) then Temp := '';
FDialog.FileName := Temp;
except
{ ignore any exceptions }
end;
FDialog.HelpContext := Self.HelpContext;
DisableSysErrors;
try
Action := FDialog.Execute;
finally
EnableSysErrors;
end;
if Action then Temp := FDialog.FileName;
if CanFocus then SetFocus;
DoAfterDialog(Temp, Action);
if Action then begin
inherited Text := ExtFilename(Temp);
SetInitialDir(ExtractFilePath(FDialog.FileName));
end;
end;
function TFilenameEdit.GetFileName: string;
begin
Result := ClipFilename(inherited Text);
end;
procedure TFilenameEdit.SetFileName(const Value: string);
begin
if (Value = '') or ValidFileName(ClipFilename(Value)) then begin
inherited Text := ExtFilename(Value);
ClearFileList;
end
else raise EComboEditError.CreateFmt(ResStr(SInvalidFilename), [Value]);
end;
{$IFDEF WIN32}
function TFilenameEdit.GetLongName: string;
begin
Result := ShortToLongFileName(FileName);
end;
function TFilenameEdit.GetShortName: string;
begin
Result := LongToShortFileName(FileName);
end;
{$ENDIF WIN32}
procedure TFilenameEdit.ClearFileList;
begin
FDialog.Files.Clear;
end;
procedure TFilenameEdit.ReceptFileDir(const AFileName: string);
begin
if FMultipleDirs then begin
if FDialog.Files.Count = 0 then SetFileName(AFileName);
FDialog.Files.Add(AFileName);
end
else SetFileName(AFileName);
end;
function TFilenameEdit.GetDialogFiles: TStrings;
begin
Result := FDialog.Files;
end;
function TFilenameEdit.GetDefaultExt: TFileExt;
begin
Result := FDialog.DefaultExt;
end;
function TFilenameEdit.GetFileEditStyle: TFileEditStyle;
begin
Result := FDialog.FileEditStyle;
end;
function TFilenameEdit.GetFilter: string;
begin
Result := FDialog.Filter;
end;
function TFilenameEdit.GetFilterIndex: Integer;
begin
Result := FDialog.FilterIndex;
end;
function TFilenameEdit.GetInitialDir: string;
begin
Result := FDialog.InitialDir;
end;
function TFilenameEdit.GetHistoryList: TStrings;
begin
Result := FDialog.HistoryList;
end;
function TFilenameEdit.GetOptions: TOpenOptions;
begin
Result := FDialog.Options;
end;
function TFilenameEdit.GetDialogTitle: string;
begin
Result := FDialog.Title;
end;
procedure TFilenameEdit.SetDialogKind(Value: TFileDialogKind);
begin
if FDialogKind <> Value then begin
FDialogKind := Value;
CreateEditDialog;
end;
end;
procedure TFilenameEdit.SetDefaultExt(Value: TFileExt);
begin
FDialog.DefaultExt := Value;
end;
procedure TFilenameEdit.SetFileEditStyle(Value: TFileEditStyle);
begin
FDialog.FileEditStyle := Value;
end;
procedure TFilenameEdit.SetFilter(const Value: string);
begin
FDialog.Filter := Value;
end;
procedure TFilenameEdit.SetFilterIndex(Value: Integer);
begin
FDialog.FilterIndex := Value;
end;
procedure TFilenameEdit.SetInitialDir(const Value: string);
begin
FDialog.InitialDir := Value;
end;
procedure TFilenameEdit.SetHistoryList(Value: TStrings);
begin
FDialog.HistoryList := Value;
end;
procedure TFilenameEdit.SetOptions(Value: TOpenOptions);
begin
if Value <> FDialog.Options then begin
FDialog.Options := Value;
FMultipleDirs := ofAllowMultiSelect in FDialog.Options;
if not FMultipleDirs then ClearFileList;
end;
end;
procedure TFilenameEdit.SetDialogTitle(const Value: string);
begin
FDialog.Title := Value;
end;
{ TDirectoryEdit }
constructor TDirectoryEdit.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
FOptions := [];
end;
procedure TDirectoryEdit.ButtonClick;
var
Temp: string;
Action: Boolean;
begin
inherited ButtonClick;
Temp := Text;
Action := True;
DoBeforeDialog(Temp, Action);
if not Action then Exit;
if (Temp = '') then begin
if (InitialDir <> '') then Temp := InitialDir
else Temp := '\';
end;
if not DirExists(Temp) then Temp := '\';
DisableSysErrors;
try
{$IFDEF WIN32}
if NewStyleControls and (DialogKind = dkWin32) then
Action := BrowseDirectory(Temp, FDialogText, Self.HelpContext)
else Action := SelectDirectory(Temp, FOptions, Self.HelpContext);
{$ELSE}
Action := SelectDirectory(Temp, FOptions, Self.HelpContext);
{$ENDIF}
finally
EnableSysErrors;
end;
if CanFocus then SetFocus;
DoAfterDialog(Temp, Action);
if Action then begin
SelText := '';
if (Text = '') or not MultipleDirs then Text := Temp
else Text := Text + ';' + Temp;
if (Temp <> '') and DirExists(Temp) then InitialDir := Temp;
end;
end;
procedure TDirectoryEdit.ReceptFileDir(const AFileName: string);
var
Temp: string;
begin
if FileExists(AFileName) then Temp := ExtractFilePath(AFileName)
else Temp := AFileName;
if (Text = '') or not MultipleDirs then Text := Temp
else Text := Text + ';' + Temp;
end;
{$IFDEF WIN32}
function TDirectoryEdit.GetLongName: string;
var
Temp: string;
Pos: Integer;
begin
if not MultipleDirs then Result := ShortToLongPath(Text)
else begin
Result := '';
Pos := 1;
while Pos <= Length(Text) do begin
Temp := ShortToLongPath(ExtractSubstr(Text, Pos, [';']));
if (Result <> '') and (Temp <> '') then Result := Result + ';';
Result := Result + Temp;
end;
end;
end;
function TDirectoryEdit.GetShortName: string;
var
Temp: string;
Pos: Integer;
begin
if not MultipleDirs then Result := LongToShortPath(Text)
else begin
Result := '';
Pos := 1;
while Pos <= Length(Text) do begin
Temp := LongToShortPath(ExtractSubstr(Text, Pos, [';']));
if (Result <> '') and (Temp <> '') then Result := Result + ';';
Result := Result + Temp;
end;
end;
end;
{$ENDIF WIN32}
{ TCustomDateEdit }
function NvlDate(DateValue, DefaultValue: TDateTime): TDateTime;
begin
if DateValue = NullDate then Result := DefaultValue
else Result := DateValue;
end;
constructor TCustomDateEdit.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
// Polaris
FDateAutoBetween := True;
FMinDate := NullDate;
FMaxDate := NullDate;
FBlanksChar := ' ';
{$IFDEF RX_D4} // Polaris
FTitle := LoadStr(SDateDlgTitle);
{$ELSE}
FTitle := NewStr(LoadStr(SDateDlgTitle));
{$ENDIF}
FPopupColor := clBtnFace;
FDefNumGlyphs := 2;
FStartOfWeek := Mon;
FWeekends := [Sun];
FWeekendColor := clRed;
FYearDigits := dyDefault;
FCalendarHints := TStringList.Create;
TStringList(FCalendarHints).OnChange := CalendarHintsChanged;
ControlState := ControlState + [csCreating];
try
UpdateFormat;
{$IFDEF DEFAULT_POPUP_CALENDAR}
FPopup := TPopupWindow(CreatePopupCalendar(Self,
{$IFDEF RX_D4} BiDiMode, {$ENDIF}
// Polaris
FMinDate, FMaxDate
));
TPopupWindow(FPopup).OnCloseUp := PopupCloseUp;
TPopupWindow(FPopup).Color := FPopupColor;
{$ENDIF DEFAULT_POPUP_CALENDAR}
GlyphKind := gkDefault; { force update }
finally
ControlState := ControlState - [csCreating];
end;
end;
destructor TCustomDateEdit.Destroy;
begin
if FHooked then begin
Application.UnhookMainWindow(FormatSettingsChange);
FHooked := False;
end;
if FPopup <> nil then TPopupWindow(FPopup).OnCloseUp := nil;
FPopup.Free;
FPopup := nil;
TStringList(FCalendarHints).OnChange := nil;
FCalendarHints.Free;
FCalendarHints := nil;
{$IFNDEF RX_D4} // Polaris
DisposeStr(FTitle);
{$ENDIF}
inherited Destroy;
end;
procedure TCustomDateEdit.CreateWindowHandle(const Params: TCreateParams);
begin
inherited CreateWindowHandle(Params);
if Handle <> 0 then begin
UpdateMask;
if not (csDesigning in ComponentState) and not (IsLibrary or FHooked) then
begin
Application.HookMainWindow(FormatSettingsChange);
FHooked := True;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -