📄 jvspeedbarform.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: JvSbEdit.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.
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:
-----------------------------------------------------------------------------}
// $Id: JvSpeedbarForm.pas,v 1.31 2005/01/29 06:36:55 marquardt Exp $
unit JvSpeedbarForm;
{$I jvcl.inc}
interface
uses
SysUtils, Classes,
Windows, Messages, Graphics, Controls, Forms, Dialogs,
StdCtrls, Buttons, Grids, Menus,
{$IFDEF COMPILER6_UP}
DesignIntf, DesignEditors,
DesignWindows,
{$ELSE}
LibIntf, DsgnIntf, DsgnWnds,
{$ENDIF COMPILER6_UP}
{$IFDEF MSWINDOWS}
JvAppRegistryStorage,
{$ENDIF MSWINDOWS}
JvSpeedButton, JvSpeedBar, JvFormPlacement,
JvConsts, JvComponent, JvAppStorage;
type
TSelectData = record
bRowCount: Integer;
bRow: Integer;
sRowCount: Integer;
sRow: Integer;
end;
TJvSpeedbarEditorMain = class(TDesignWindow)
SectionsBox: TGroupBox;
NewSection: TButton;
DelSection: TButton;
ButtonsBox: TGroupBox;
UpBtn: TSpeedButton;
DownBtn: TSpeedButton;
AddButton: TButton;
RemoveButton: TButton;
CloseBtn: TButton;
SectionName: TEdit;
SectionNameLabel: TLabel;
SectionList: TDrawGrid;
ButtonsList: TDrawGrid;
LabelHint: TLabel;
PopupMenu: TPopupMenu;
CopyMenu: TMenuItem;
PasteMenu: TMenuItem;
CutMenu: TMenuItem;
FormPlacement1: TJvFormStorage;
AppStorage: TJvAppRegistryStorage;
procedure DelSectionClick(Sender: TObject);
procedure AddButtonClick(Sender: TObject);
procedure RemoveButtonClick(Sender: TObject);
procedure CloseBtnClick(Sender: TObject);
procedure UpBtnClick(Sender: TObject);
procedure DownBtnClick(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure SectionNameExit(Sender: TObject);
procedure SectionListSelectCell(Sender: TObject; Col, Row: Longint;
var CanSelect: Boolean);
procedure SectionListDrawCell(Sender: TObject; Col, Row: Longint;
Rect: TRect; State: TGridDrawState);
procedure ButtonsListDblClick(Sender: TObject);
procedure ButtonsListKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
procedure ButtonsListMouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
procedure ButtonsListMouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
procedure ButtonsListMouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
procedure ButtonsListSelectCell(Sender: TObject; Col, Row: Longint;
var CanSelect: Boolean);
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
procedure NewSectionClick(Sender: TObject);
procedure SectionNameKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
procedure ButtonsListDrawCell(Sender: TObject; Col, Row: Longint;
Rect: TRect; State: TGridDrawState);
procedure SectionListMouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
procedure SectionListDragDrop(Sender, Source: TObject; X, Y: Integer);
procedure SectionListDragOver(Sender, Source: TObject; X, Y: Integer;
State: TDragState; var Accept: Boolean);
procedure SectionListKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
procedure CopyMenuClick(Sender: TObject);
procedure PasteMenuClick(Sender: TObject);
procedure CutMenuClick(Sender: TObject);
procedure FormShow(Sender: TObject);
private
FButton: TJvBtnControl;
FImage: TJvButtonImage;
FBar: TJvSpeedBar;
FDrag: Boolean;
FDragItem: TJvSpeedItem;
FLocked: Integer;
FSelectData: TSelectData;
procedure Copy;
procedure Cut;
procedure Paste;
procedure OnPasteItem(Item: TObject);
procedure SaveSelection;
procedure RestoreSelection;
procedure SelectButton(Section: Integer; Item: TJvSpeedItem; SelectBar: Boolean);
procedure UpdateEnabled(BtnRow, Section: Integer);
function CheckSpeedBar: Boolean;
function ConfirmDelete: Boolean;
function CurrentSection: Integer;
function GetForm: TCustomForm;
procedure SetSection(Section: Integer);
procedure UpdateData;
procedure UpdateListHeight;
procedure SetJvSpeedBar(Value: TJvSpeedBar);
function ItemByRow(Row: Integer): TJvSpeedItem;
function SectionByRow(Row: Integer): TJvSpeedbarSection;
function ItemBySectionRow(Section, Row: Integer): TJvSpeedItem;
procedure CMSpeedBarChanged(var Msg: TMessage); message CM_SPEEDBARCHANGED;
protected
procedure Activated; override;
function UniqueName(Component: TComponent): string; override;
public
{$IFDEF COMPILER6_UP}
procedure ItemsModified(const Designer: IDesigner); override;
procedure DesignerClosed(const ADesigner: IDesigner; AGoingDormant: Boolean); override;
{$ELSE}
procedure FormModified; override;
procedure FormClosed(Form: TCustomForm); override;
{$ENDIF COMPILER6_UP}
function GetEditState: TEditState; override;
{$IFDEF COMPILER6_UP}
function EditAction(Action: TEditAction): Boolean; override;
{$ELSE}
procedure EditAction(Action: TEditAction); override;
{$ENDIF COMPILER6_UP}
property JvSpeedBar: TJvSpeedBar read FBar write SetJvSpeedBar;
property OwnerForm: TCustomForm read GetForm;
end;
TJvSpeedbarEditor = class(TComponentEditor)
procedure ExecuteVerb(Index: Integer); override;
function GetVerb(Index: Integer): string; override;
function GetVerbCount: Integer; override;
end;
implementation
uses
TypInfo, Math,
JvPropertyStorage, JvDsgnConsts, JvDsgnTypes, JvJVCLUtils;
{$R *.dfm}
//== Utility routines ========================================================
function FindEditor(JvSpeedBar: TJvSpeedBar): TJvSpeedbarEditorMain;
var
I: Integer;
begin
Result := nil;
for I := 0 to Screen.FormCount - 1 do
if Screen.Forms[I] is TJvSpeedbarEditorMain then
if TJvSpeedbarEditorMain(Screen.Forms[I]).JvSpeedBar = JvSpeedBar then
begin
Result := TJvSpeedbarEditorMain(Screen.Forms[I]);
Break;
end;
end;
procedure ShowSpeedbarDesigner(Designer: IJvDesigner; JvSpeedBar: TJvSpeedBar);
var
Editor: TJvSpeedbarEditorMain;
begin
if JvSpeedBar = nil then
Exit;
Editor := FindEditor(JvSpeedBar);
if Editor <> nil then
begin
Editor.Show;
if Editor.WindowState = wsMinimized then
Editor.WindowState := wsNormal;
end
else
begin
Editor := TJvSpeedbarEditorMain.Create(Application);
try
Editor.Designer := IJvFormDesigner(Designer);
Editor.JvSpeedBar := JvSpeedBar;
Editor.Show;
except
Editor.Free;
raise;
end;
end;
end;
//=== { TJvSpeedbarEditor } ==================================================
procedure TJvSpeedbarEditor.ExecuteVerb(Index: Integer);
begin
case Index of
0:
ShowSpeedbarDesigner(Designer, TJvSpeedBar(Component));
end;
end;
function TJvSpeedbarEditor.GetVerb(Index: Integer): string;
begin
case Index of
0:
Result := RsSpeedbarDesigner;
end;
end;
function TJvSpeedbarEditor.GetVerbCount: Integer;
begin
Result := 1;
end;
//=== { TJvSpeedbarEditorMain } ==============================================
const
MaxBtnListHeight = 158;
function TJvSpeedbarEditorMain.UniqueName(Component: TComponent): string;
var
Temp: string;
begin
Result := '';
if Component <> nil then
Temp := Component.ClassName
else
Temp := TJvSpeedItem.ClassName;
if (UpCase(Temp[1]) = 'T') and (Length(Temp) > 1) then
System.Delete(Temp, 1, 1);
Result := Designer.UniqueName(Temp);
end;
function TJvSpeedbarEditorMain.GetEditState: TEditState;
begin
Result := [];
if RemoveButton.Enabled then
Result := [esCanDelete, esCanCut, esCanCopy];
if AddButton.Enabled and ClipboardComponents then
Include(Result, esCanPaste);
end;
{$IFDEF COMPILER6_UP}
function TJvSpeedbarEditorMain.EditAction(Action: TEditAction): Boolean;
begin
Result := True;
{$ELSE}
procedure TJvSpeedbarEditorMain.EditAction(Action: TEditAction);
begin
{$ENDIF COMPILER6_UP}
case Action of
eaCut:
Cut;
eaCopy:
Copy;
eaPaste:
Paste;
eaDelete:
RemoveButtonClick(Self);
end;
end;
{$IFDEF COMPILER6_UP}
type
TDesignerSelectionList = IDesignerSelections;
{$ENDIF COMPILER6_UP}
procedure TJvSpeedbarEditorMain.SelectButton(Section: Integer; Item: TJvSpeedItem;
SelectBar: Boolean);
var
FCompList: TDesignerSelectionList;
Sect: TJvSpeedbarSection;
begin
if CheckSpeedBar and Active then
begin
//Designer.GetSelections(FCompList);
{$IFDEF COMPILER6_UP}
FCompList := TDesignerSelections.Create;
{$ELSE}
FCompList := TDesignerSelectionList.Create;
{$ENDIF COMPILER6_UP}
if not SelectBar then
begin
if (ActiveControl = SectionList) or (ActiveControl = SectionName) then
begin
Sect := SectionByRow(Section);
if Sect <> nil then
FCompList.Add(Sect);
end;
if (FCompList.Count = 0) and (Item <> nil) then
FCompList.Add(Item);
end;
if (FBar <> nil) and (FCompList.Count = 0) then
FCompList.Add(FBar);
SetSelection(FCompList);
end;
end;
{$IFDEF COMPILER6_UP}
procedure TJvSpeedbarEditorMain.DesignerClosed(const ADesigner: IDesigner; AGoingDormant: Boolean);
{$ELSE}
procedure TJvSpeedbarEditorMain.FormClosed(Form: TCustomForm);
{$ENDIF COMPILER6_UP}
begin
{$IFDEF COMPILER6_UP}
if ADesigner.Root = OwnerForm then
{$ELSE}
if Form = OwnerForm then
{$ENDIF COMPILER6_UP}
Free;
end;
{$IFDEF COMPILER6_UP}
procedure TJvSpeedbarEditorMain.ItemsModified(const Designer: IDesigner);
{$ELSE}
procedure TJvSpeedbarEditorMain.FormModified;
{$ENDIF COMPILER6_UP}
begin
if not (csDestroying in ComponentState) then
UpdateData;
end;
procedure TJvSpeedbarEditorMain.Activated;
begin
SelectButton(CurrentSection, ItemByRow(ButtonsList.Row), False);
PasteMenu.Enabled := CheckSpeedBar and (FBar.SectionCount > 0) and
ClipboardComponents;
end;
function TJvSpeedbarEditorMain.ConfirmDelete: Boolean;
begin
Result := MessageDlg(RsConfirmSBDelete, mtWarning, mbYesNoCancel, 0) = mrYes;
end;
procedure TJvSpeedbarEditorMain.SaveSelection;
begin
with FSelectData do
begin
bRowCount := ButtonsList.RowCount;
bRow := ButtonsList.Row;
sRowCount := SectionList.RowCount;
sRow := SectionList.Row;
end;
end;
procedure TJvSpeedbarEditorMain.RestoreSelection;
var
NewSRow, NewBRow: Integer;
begin
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -