📄 jvqspeedbarform.pas
字号:
{******************************************************************************}
{* WARNING: JEDI VCL To CLX Converter generated unit. *}
{* Manual modifications will be lost on next release. *}
{******************************************************************************}
{-----------------------------------------------------------------------------
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: JvQSpeedbarForm.pas,v 1.9 2004/12/25 13:20:43 marquardt Exp $
{$I jvcl.inc}
unit JvQSpeedbarForm;
interface
uses
SysUtils, Classes,
QWindows, Types, QGraphics, QControls, QForms, QDialogs,
QStdCtrls, QButtons, QGrids, QMenus, QMessages,
DesignIntf, DesignEditors,
QDesignWindows,
{$IFDEF MSWINDOWS}
// JvAppRegistryStorage,
{$ENDIF MSWINDOWS}
JvQSpeedButton, JvQSpeedBar, JvQFormPlacement,
JvQConsts, JvQComponent, JvQAppStorage, QTypes;
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;
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
procedure ItemsModified(const Designer: IDesigner); override;
procedure DesignerClosed(const ADesigner: IDesigner; AGoingDormant: Boolean); override;
function GetEditState: TEditState; override;
function EditAction(Action: TEditAction): Boolean; override;
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,
JvQPropertyStorage, JvQDsgnConsts, JvQDsgnTypes, JvQJVCLUtils;
{$R *.xfm}
//== 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;
function TJvSpeedbarEditorMain.EditAction(Action: TEditAction): Boolean;
begin
Result := True;
case Action of
eaCut:
Cut;
eaCopy:
Copy;
eaPaste:
Paste;
eaDelete:
RemoveButtonClick(Self);
end;
end;
type
TDesignerSelectionList = IDesignerSelections;
procedure TJvSpeedbarEditorMain.SelectButton(Section: Integer; Item: TJvSpeedItem;
SelectBar: Boolean);
var
FCompList: TDesignerSelectionList;
Sect: TJvSpeedbarSection;
begin
if CheckSpeedBar and Active then
begin
//Designer.GetSelections(FCompList);
FCompList := TDesignerSelections.Create;
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;
procedure TJvSpeedbarEditorMain.DesignerClosed(const ADesigner: IDesigner; AGoingDormant: Boolean);
begin
if ADesigner.Root = OwnerForm then
Free;
end;
procedure TJvSpeedbarEditorMain.ItemsModified(const Designer: IDesigner);
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
NewSRow := FSelectData.sRow;
if (SectionList.RowCount > FSelectData.sRowCount) or
(NewSRow > SectionList.RowCount - 1) then
NewSRow := SectionList.RowCount - 1;
if NewSRow < 0 then
NewSRow := 0;
SectionList.Row := NewSRow;
SetSection(SectionList.Row); { set ButtonsList to current section }
NewBRow := FSelectData.bRow;
if (ButtonsList.RowCount > FSelectData.bRowCount) or
(NewBRow > ButtonsList.RowCount - 1) then
NewBRow := ButtonsList.RowCount - 1;
if NewBRow < 0 then
NewBRow := 0;
ButtonsList.Row := NewBRow;
end;
procedure TJvSpeedbarEditorMain.UpdateEnabled(BtnRow, Section: Integer);
var
EnableSect, EnableBtn: Boolean;
begin
EnableSect := CheckSpeedBar and (FBar.SectionCount > 0);
EnableBtn := EnableSect and (BtnRow >= 0) and (ItemBySectionRow(Section,
BtnRow) <> nil);
DelSection.Enabled := EnableSect;
SectionName.Enabled := EnableSect;
AddButton.Enabled := EnableSect;
RemoveButton.Enabled := EnableBtn;
CopyMenu.Enabled := EnableBtn;
CutMenu.Enabled := EnableBtn;
PasteMenu.Enabled := EnableSect and ClipboardComponents;
UpBtn.Enabled := EnableBtn and (BtnRow > 0);
DownBtn.Enabled := EnableBtn and (BtnRow < ButtonsList.RowCount - 1);
end;
function TJvSpeedbarEditorMain.CheckSpeedBar: Boolean;
begin
Result := (FBar <> nil) and (FBar.Owner <> nil) and (FBar.Parent <> nil) and
(Designer.Root <> nil);
end;
function TJvSpeedbarEditorMain.CurrentSection: Integer;
begin
if CheckSpeedBar and (FBar.SectionCount > 0) then
Result := SectionList.Row
else
Result := -1;
end;
procedure TJvSpeedbarEditorMain.SetSection(Section: Integer);
var
I: Integer;
begin
if CheckSpeedBar then
begin
I := Section;
if (I >= 0) and (I < FBar.SectionCount) then
begin
SectionName.Text := TJvSpeedbarSection(FBar.Sections[I]).Caption;
ButtonsList.RowCount := FBar.ItemsCount(I);
end
else
begin
SectionName.Text := '';
ButtonsList.RowCount := 0;
end;
SectionList.DefaultColWidth := SectionList.ClientWidth;
ButtonsList.DefaultColWidth := ButtonsList.ClientWidth;
end;
end;
procedure TJvSpeedbarEditorMain.UpdateData;
begin
Inc(FLocked);
try
SaveSelection;
if CheckSpeedBar then
SectionList.RowCount := FBar.SectionCount
else
SectionList.RowCount := 0;
RestoreSelection; { set section }
finally
Dec(FLocked);
end;
UpdateEnabled(ButtonsList.Row, SectionList.Row);
SelectButton(CurrentSection, ItemByRow(ButtonsList.Row), False);
end;
function TJvSpeedbarEditorMain.GetForm: TCustomForm;
begin
Result := TCustomForm(Designer.Root); { GetParentForm(FBar) }
end;
procedure TJvSpeedbarEditorMain.UpdateListHeight;
var
Cnt: Integer;
MaxHeight: Integer;
begin
Canvas.Font := Font;
MaxHeight := MulDiv(MaxBtnListHeight, Screen.PixelsPerInch, 96);
ButtonsList.DefaultRowHeight := FBar.BtnHeight + 2;
Cnt := Max(1, Max(ButtonsList.ClientHeight, MaxHeight) div
(FBar.BtnHeight + 2));
ButtonsList.ClientHeight := Min(ButtonsList.DefaultRowHeight * Cnt,
MaxHeight);
SectionList.DefaultRowHeight := CanvasMaxTextHeight(Canvas) + 2;
end;
procedure TJvSpeedbarEditorMain.SetJvSpeedBar(Value: TJvSpeedBar);
var
I: Integer;
begin
if FBar <> Value then
begin
if FBar <> nil then
FBar.SetEditing(nil);
FBar := Value;
if FBar <> nil then
FBar.SetEditing(Handle);
Inc(FLocked);
try
if FBar <> nil then
UpdateListHeight;
if FBar.SectionCount = 0 then
NewSectionClick(Self)
else
for I := 0 to FBar.SectionCount - 1 do
if FBar.Sections[I].Name = '' then
begin
FBar.Sections[I].Name := UniqueName(FBar.Sections[I]);
Designer.Modified;
end;
if ButtonsList.RowCount > 0 then
ActiveControl := ButtonsList
else
ActiveControl := SectionList;
UpdateData;
ButtonsList.Row := 0;
finally
Dec(FLocked);
end;
SectionList.Row := 0;
end;
end;
procedure TJvSpeedbarEditorMain.CMSpeedBarChanged(var Msg: TMessage);
begin
if Pointer(Msg.LParam) = FBar then
case Msg.WParam of
SBR_CHANGED:
Designer.Modified;
SBR_DESTROYED:
Close;
SBR_BTNSIZECHANGED:
if FBar <> nil then
UpdateListHeight;
end
else
if (Msg.WParam = SBR_BTNSELECT) and CheckSpeedBar then
begin
SelectButton(-1, nil, True);
Designer.Modified;
end;
end;
function TJvSpeedbarEditorMain.ItemBySectionRow(Section, Row: Integer): TJvSpeedItem;
begin
if CheckSpeedBar then
Result := FBar.Items(Section, Row)
else
Result := nil;
end;
function TJvSpeedbarEditorMain.SectionByRow(Row: Integer): TJvSpeedbarSection;
begin
if CheckSpeedBar and (Row >= 0) and (Row < FBar.SectionCount) then
Result := FBar.Sections[Row]
else
Result := nil;
end;
function TJvSpeedbarEditorMain.ItemByRow(Row: Integer): TJvSpeedItem;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -