jvcllaz: Add TJvPageList, contribution by Michal Gawrycki. Add JvTabBarDemp_PageList example.

git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@7413 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
wp_xxyyzz
2020-04-28 20:39:01 +00:00
parent 977021871d
commit e8f5f157ab
13 changed files with 2787 additions and 363 deletions

View File

@ -16,7 +16,7 @@ implementation
uses
ImgList,
PropEdits, ComponentEditors,
JvDsgnConsts,
JvDsgnConsts, JvPageList,
JvNavigationPane, JvNavPaneEditors,
JvTabBar, JvTabBarXPPainter,
JvNotebookPageList,
@ -26,6 +26,7 @@ uses
procedure Register;
const
cImageIndex = 'ImageIndex';
cActivePage = 'ActivePage';
begin
// JvNavigationPanel
RegisterComponents(RsPaletteJvclVisual, [ // was: RsPaletteNavPane
@ -47,20 +48,18 @@ begin
// JvPageList
RegisterComponents(RsPaletteJvclVisual, [ // was: RsPaletteListComboTree
//TJvPageList,
TJvPageList,
TJvNotebookPageList]);
{
RegisterClasses([TJvPageList, TJvStandardPage]);
RegisterComponentEditor(TJvCustomPageList, TJvCustomPageListEditor); // was: TJvCustomPageEditor
RegisterNoIcon([TJvStandardPage]);
RegisterComponentEditor(TJvCustomPageList, TJvCustomPageEditor); // was: TJvCustomPageEditor
RegisterComponentEditor(TJvCustomPage, TJvCustomPageEditor);
RegisterPropertyEditor(TypeInfo(TJvShowDesignCaption), nil, '',
TJvShowDesignCaptionProperty);#
}
TJvShowDesignCaptionProperty);
{
RegisterPropertyEditor(TypeInfo(TJvCustomPage),
TJvCustomPageList, cActivePage, TJvActivePageProperty);
}
// JvPageTree
RegisterComponents(RsPaletteJvclVisual, [ // was: TsPaletteListComboTree

View File

@ -0,0 +1,160 @@
object frmJvTreeViewLinksEditor: TfrmJvTreeViewLinksEditor
Left = 294
Top = 184
ClientWidth = 464
ClientHeight = 231
ActiveControl = tvItems
BorderIcons = [biSystemMenu]
Caption = 'JvTreeViewLinks Editor'
OldCreateOrder = False
PopupMenu = popTree
OnResize = FormResize
PixelsPerInch = 96
TextHeight = 13
object Bevel1: TBevel
Left = 0
Top = 191
Width = 464
Height = 42
Align = alBottom
Shape = bsTopLine
end
object Splitter1: TSplitter
Left = 163
Top = 0
Width = 3
Height = 191
Cursor = crHSplit
AutoSnap = False
end
object Splitter2: TSplitter
Left = 268
Top = 0
Width = 3
Height = 191
Cursor = crHSplit
AutoSnap = False
end
object pnlLeft: TPanel
Left = 0
Top = 0
Width = 163
Height = 191
Align = alLeft
BevelOuter = bvNone
BorderWidth = 4
TabOrder = 0
object Label1: TLabel
Left = 4
Top = 4
Width = 155
Height = 16
Align = alTop
AutoSize = False
Caption = '&Nodes:'
FocusControl = tvItems
Layout = tlCenter
end
object tvItems: TTreeView
Left = 4
Top = 20
Width = 155
Height = 167
Align = alClient
ChangeDelay = 60
HideSelection = False
Indent = 19
PopupMenu = popTree
ReadOnly = True
ShowButtons = False
ShowLines = False
TabOrder = 0
ToolTips = False
OnChange = tvItemsChange
end
end
object btnOK: TButton
Left = 285
Top = 199
Width = 75
Height = 25
Anchors = [akRight, akBottom]
Caption = '&OK'
ModalResult = 1
TabOrder = 3
end
object btnCancel: TButton
Left = 373
Top = 199
Width = 75
Height = 25
Anchors = [akRight, akBottom]
Caption = '&Cancel'
ModalResult = 2
TabOrder = 4
end
object pnlMid: TPanel
Left = 166
Top = 0
Width = 102
Height = 191
Align = alLeft
BevelOuter = bvNone
TabOrder = 1
object btnLink: TButton
Left = 5
Top = 24
Width = 91
Height = 25
Action = acLink
Anchors = [akTop]
TabOrder = 0
TabStop = False
end
end
object pnlRight: TPanel
Left = 271
Top = 0
Width = 193
Height = 191
Align = alClient
BevelOuter = bvNone
BorderWidth = 4
Caption = 'pnlRight'
TabOrder = 2
object Label2: TLabel
Left = 4
Top = 4
Width = 185
Height = 17
Align = alTop
AutoSize = False
Caption = '&Pages:'
FocusControl = lbPages
Layout = tlCenter
end
object lbPages: TListBox
Left = 4
Top = 21
Width = 185
Height = 166
Align = alClient
ItemHeight = 13
TabOrder = 0
end
end
object acMain: TActionList
OnUpdate = acMainUpdate
Left = 168
Top = 64
object acLink: TAction
Caption = '<- Create &Link ->'
ShortCut = 16397
OnExecute = acLinkExecute
end
end
object popTree: TPopupMenu
Left = 58
Top = 72
end
end

View File

@ -0,0 +1,287 @@
{-----------------------------------------------------------------------------
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: JvPageLinkEditorForm.PAS, released on 2003-01-01.
The Initial Developer of the Original Code is Peter Th�rnqvist [peter3 at sourceforge dot net] .
Portions created by Peter Th�rnqvist are Copyright (C) 2003 Peter Th�rnqvist.
All Rights Reserved.
Contributor(s):
You may retrieve the latest version of this file at the Project JEDI's JVCL home page,
located at http://jvcl.delphi-jedi.org
Known Issues:
Changes:
2002-10-22:
changed the way a parent/child PageIndex is assigned so that it matches the
actual component using this editor
$Id$
-----------------------------------------------------------------------------}
// $Id$
unit JvPageLinkEditorForm;
{$I jvcl.inc}
interface
uses
Classes, SysUtils, Windows, Forms, Controls, StdCtrls, ExtCtrls, ComCtrls,
ActnList, Menus,
Variants,
DesignEditors, DesignIntf,
JvPageList, JvPageListTreeView, JvComponent;
type
{ a property editor for the PageLinks property of TJvCustomPageListTreeView}
TJvPageLinksProperty = class(TClassProperty)
public
function GetAttributes: TPropertyAttributes; override;
procedure Edit; override;
end;
TfrmJvTreeViewLinksEditor = class(TJvForm)
tvItems: TTreeView;
btnLink: TButton;
lbPages: TListBox;
acMain: TActionList;
acLink: TAction;
Label1: TLabel;
Label2: TLabel;
btnOK: TButton;
btnCancel: TButton;
Bevel1: TBevel;
pnlLeft: TPanel;
pnlMid: TPanel;
pnlRight: TPanel;
popTree: TPopupMenu;
Splitter1: TSplitter;
Splitter2: TSplitter;
procedure tvItemsChange(Sender: TObject; Node: TTreeNode);
procedure acLinkExecute(Sender: TObject);
procedure acMainUpdate(Action: TBasicAction;
var Handled: Boolean);
procedure FormResize(Sender: TObject);
private
FTreeView:TCustomTreeView;
function CreatePopUpItem(Index: Integer): TMenuItem;
procedure DoPopClick(Sender: TObject);
procedure AssignComponents(TreeView: TCustomTreeView; const PageList: IPageList);
procedure AssignToComponents(TreeView: TCustomTreeView; const PageList: IPageList);
public
class function Edit(TreeView: TCustomTreeView; const PageList: IPageList): Boolean;
end;
function ShowPageLinkEditor(TreeView: TJvCustomPageListTreeView): Boolean;
implementation
uses
JvDsgnConsts;
{$R *.dfm}
type
THackTreeView = class(TJvCustomPageListTreeView);
function ShowPageLinkEditor(TreeView: TJvCustomPageListTreeView): Boolean;
begin
Result := TfrmJvTreeViewLinksEditor.Edit(TreeView, TreeView.PageList);
if Result and (THackTreeView(TreeView).Items.Count > 0) then
THackTreeView(TreeView).Items.GetFirstNode.Expand(False);
end;
//=== { TJvPageLinksProperty } ===============================================
procedure TJvPageLinksProperty.Edit;
begin
if ShowPageLinkEditor(GetComponent(0) as TJvCustomPageListTreeView) then
Modified;
end;
function TJvPageLinksProperty.GetAttributes: TPropertyAttributes;
begin
Result := [paDialog, paReadOnly];
end;
//=== { TfrmJvTreeViewLinksEditor } ==========================================
function GetStrippedText(const AText: string): string;
var
I: Integer;
begin
Result := AText;
for I := Length(AText) downto 1 do
if AText[I] = '(' then
begin
Result := Copy(AText, 1, I - 2);
Break;
end;
end;
function GetNewTreeText(const AText: string; Index: Integer): string;
begin
Result := Format('%s (%d)', [GetStrippedText(AText), Index])
end;
procedure TfrmJvTreeViewLinksEditor.DoPopClick(Sender: TObject);
begin
with Sender as TMenuItem do
begin
lbPages.ItemIndex := Tag;
if acLink.Enabled then
acLink.Execute;
end;
end;
function TfrmJvTreeViewLinksEditor.CreatePopUpItem(Index: Integer): TMenuItem;
begin
Result := TMenuItem.Create(popTree);
Result.Caption := Format(RsCreateLinkToPaged, [Index]);
Result.Tag := Index;
if Index < 10 then
Result.ShortCut := ShortCut(Ord('0') + Index, [ssCtrl])
else
if (Index >= 10) and (Index < 36) then
Result.ShortCut := ShortCut(Ord('A') + Index - 10, [ssCtrl]);
Result.OnClick := DoPopClick;
end;
procedure TfrmJvTreeViewLinksEditor.AssignComponents(TreeView: TCustomTreeView;
const PageList: IPageList);
var
N1: TJvPageIndexNode;
N2: TTreeNode;
I: Integer;
begin
tvItems.Items.Clear;
FTreeView := TreeView;
if TreeView <> nil then
begin
tvItems.Items.Assign(THackTreeView(TreeView).Items);
tvItems.ShowButtons := True; // THackTreeView(TreeView).ShowButtons;
end;
if TreeView is TJvCustomPageListTreeView then
begin
N1 := THackTreeView(TreeView).Items.GetFirstNode as TJvPageIndexNode;
N2 := tvItems.Items.GetFirstNode;
while Assigned(N1) and Assigned(N2) do
begin
N2.Data := Pointer(N1.PageIndex);
N2.Text := Format('%s (%d)', [N1.Text, N1.PageIndex]);
N1 := TJvPageIndexNode(N1.GetNext);
N2 := N2.GetNext;
end;
end;
lbPages.Items.Clear;
popTree.Items.Clear;
if PageList <> nil then
for I := 0 to PageList.GetPageCount - 1 do
begin
lbPages.Items.Add(Format('%s (%d)', [PageList.GetPageCaption(I), I]));
popTree.Items.Add(CreatePopUpItem(I));
end;
if tvItems.Items.Count > 0 then
begin
tvItems.Items[0].Selected := True;
tvItems.Items[0].Expand(False);
end;
end;
procedure TfrmJvTreeViewLinksEditor.AssignToComponents(TreeView: TCustomTreeView;
const PageList: IPageList);
var
N1: TJvPageIndexNode;
N2: TTreeNode;
begin
if TreeView <> nil then
THackTreeView(TreeView).Items.Assign(tvItems.Items);
if TreeView is TJvCustomPageListTreeView then
begin
N1 := THackTreeView(TreeView).Items.GetFirstNode as TJvPageIndexNode;
N2 := tvItems.Items.GetFirstNode;
while Assigned(N1) and Assigned(N2) do
begin
N1.PageIndex := Integer(N2.Data);
N1.Text := GetStrippedText(N2.Text);
N1 := TJvPageIndexNode(N1.GetNext);
N2 := N2.GetNext;
end;
end;
end;
procedure TfrmJvTreeViewLinksEditor.tvItemsChange(Sender: TObject;
Node: TTreeNode);
begin
if Node <> nil then
if Node is TJvPageIndexNode then
lbPages.ItemIndex := TJvPageIndexNode(Node).PageIndex
else
lbPages.ItemIndex := Integer(Node.Data);
end;
procedure TfrmJvTreeViewLinksEditor.acLinkExecute(Sender: TObject);
var
N: TTreeNode;
begin
N := tvItems.Selected;
N.Data := Pointer(lbPages.ItemIndex);
if FTreeView is TJvCustomSettingsTreeView then
begin
// make the editor behave like the component
if (N.Parent <> nil) and (N.Parent.GetFirstChild = N) then
begin
N.Parent.Data := Pointer(lbPages.ItemIndex);
N.Parent.Text := GetNewTreeText(N.Parent.Text, lbPages.ItemIndex);
end
else
if N.HasChildren then
begin
N.GetFirstChild.Data := Pointer(lbPages.ItemIndex);
N.GetFirstChild.Text := GetNewTreeText(N.GetFirstChild.Text, lbPages.ItemIndex);
end;
end;
if N is TJvPageIndexNode then
TJvPageIndexNode(N).PageIndex := lbPages.ItemIndex;
N.Text := GetNewTreeText(N.Text, lbPages.ItemIndex);
end;
procedure TfrmJvTreeViewLinksEditor.acMainUpdate(Action: TBasicAction;
var Handled: Boolean);
begin
acLink.Enabled := (tvItems.Selected <> nil) and (lbPages.ItemIndex > -1);
end;
procedure TfrmJvTreeViewLinksEditor.FormResize(Sender: TObject);
begin
pnlLeft.Width := (ClientWidth - pnlMid.Width) div 2;
end;
class function TfrmJvTreeViewLinksEditor.Edit(TreeView: TCustomTreeView;
const PageList: IPageList): Boolean;
begin
// keep in mind that Self is a class here not an object
with Self.Create(Application) do
try
AssignComponents(TreeView, PageList);
Result := ShowModal = mrOk;
if Result then
AssignToComponents(TreeView, PageList);
finally
Free;
end;
end;
end.

View File

@ -0,0 +1,148 @@
object frmPageListEditor: TfrmPageListEditor
Left = 446
Height = 342
Top = 114
Width = 233
Caption = 'PageList Editor'
ClientHeight = 342
ClientWidth = 233
OnClose = FormClose
OnCreate = FormCreate
OnDestroy = FormDestroy
LCLVersion = '2.1.0.0'
object ToolBar1: TToolBar
Left = 0
Height = 23
Top = 0
Width = 233
AutoSize = True
ButtonHeight = 23
ButtonWidth = 23
Caption = 'ToolBar1'
EdgeInner = esNone
EdgeOuter = esNone
Images = ilButtons
ParentShowHint = False
ShowHint = True
TabOrder = 0
object btnAdd: TToolButton
Left = 1
Hint = 'Add page'
Top = 0
Action = acAdd
end
object btnDelete: TToolButton
Left = 24
Hint = 'Delete page'
Top = 0
Action = acDelete
end
object ToolButton1: TToolButton
Left = 47
Height = 23
Top = 0
Caption = 'ToolButton1'
ImageIndex = 3
Style = tbsSeparator
end
object tbMoveUp: TToolButton
Left = 55
Top = 0
Action = acMoveUp
end
object tbMoveDown: TToolButton
Left = 78
Top = 0
Action = acMoveDown
end
end
object lbPages: TListBox
Left = 0
Height = 296
Top = 23
Width = 233
Align = alClient
ItemHeight = 0
OnClick = lbPagesClick
OnKeyPress = lbPagesKeyPress
PopupMenu = popEditor
TabOrder = 1
end
object StatusBar1: TStatusBar
Left = 0
Height = 23
Top = 319
Width = 233
Panels = <>
end
object alEditor: TActionList
Images = ilButtons
OnUpdate = alEditorUpdate
Left = 86
Top = 34
object acAdd: TAction
Caption = 'Add'
Hint = 'Add Welcome page'
ImageIndex = 0
OnExecute = acAddExecute
ShortCut = 45
end
object acDelete: TAction
Caption = 'Delete'
Hint = 'Delete selected page(s)'
ImageIndex = 1
OnExecute = acDeleteExecute
OnUpdate = acDeleteUpdate
ShortCut = 46
end
object acMoveUp: TAction
Caption = 'Move Up'
Hint = 'Move Up'
ImageIndex = 2
OnExecute = acMoveUpExecute
ShortCut = 16422
end
object acMoveDown: TAction
Caption = 'Move Down'
Hint = 'Move Down'
ImageIndex = 3
OnExecute = acMoveDownExecute
ShortCut = 16424
end
end
object ilButtons: TImageList
Left = 20
Top = 30
Bitmap = {
4C7A040000001000000010000000FE0000000000000078DAED558B0E833008E4
E3FB6DFE56679DD42BC5963E96749B24448DDC1D6041A2CB9C733E18B518C407
7CF65C31C4A0BEE4B270C8AB31FD04E3CF7BF41076E384718C65CEE275C7737F
102B73A11B0EC6C75A85367294F4F9DE2BBA167D6EA3A55EE988AFF58C35B66D
53F1167DC67A257F933EC465FA1D8EF321CF9CD569590BB9F5E6D88295B16DBA
EFB8D42B339FCCBFC6D133FF3207CB79546B3EDE1938707F0036EE0172C55D76
E99F2E62E2BBEAFC3B3F32FFF15B3DF3FF8B3652DFDE9F744E5BB1EC8D1C09B6
9143C51A39C4D9CA70D9DEFA50FD4BE03B6A7E6CADB91FF97EDF787E67CCEFC8
FE98B1BF66F56F747FCFF87FFC85BD007F143BD9
}
end
object popEditor: TPopupMenu
Images = ilButtons
Left = 54
Top = 120
object Add1: TMenuItem
Action = acAdd
end
object Delete1: TMenuItem
Action = acDelete
end
object N1: TMenuItem
Caption = '-'
end
object MoveUp1: TMenuItem
Action = acMoveUp
end
object MoveDown1: TMenuItem
Action = acMoveDown
end
end
end

View File

@ -0,0 +1,374 @@
{-----------------------------------------------------------------------------
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: JvPageListEditorForm.PAS, released on 2004-03-28.
The Initial Developer of the Original Code is Peter Thornqvist <peter3 at sourceforge dot net>
Portions created by Peter Thornqvist are Copyright (C) 2004 Peter Thornqvist.
All Rights Reserved.
Contributor(s):
You may retrieve the latest version of this file at the Project JEDI's JVCL home page,
located at http://jvcl.delphi-jedi.org
Known Issues:
-----------------------------------------------------------------------------}
// $Id$
unit JvPageListEditorForm;
{$mode objfpc}{$H+}
interface
uses
SysUtils, Classes, Graphics, Controls, Forms,
Dialogs, ActnList, ImgList, ComCtrls, StdCtrls, ToolWin, Menus,
PropEdits, PropEditUtils, ComponentEditors,
JvPageList, JvPageListEditors, IDEWindowIntf;
type
{ TfrmPageListEditor }
TfrmPageListEditor = class(TForm)
ToolBar1: TToolBar;
btnAdd: TToolButton;
btnDelete: TToolButton;
ToolButton1: TToolButton;
tbMoveUp: TToolButton;
tbMoveDown: TToolButton;
lbPages: TListBox;
alEditor: TActionList;
acAdd: TAction;
acDelete: TAction;
acMoveUp: TAction;
acMoveDown: TAction;
ilButtons: TImageList;
StatusBar1: TStatusBar;
popEditor: TPopupMenu;
Add1: TMenuItem;
Delete1: TMenuItem;
N1: TMenuItem;
MoveUp1: TMenuItem;
MoveDown1: TMenuItem;
procedure FormCreate(Sender: TObject);
procedure acAddExecute(Sender: TObject);
procedure acDeleteExecute(Sender: TObject);
procedure acMoveUpExecute(Sender: TObject);
procedure acMoveDownExecute(Sender: TObject);
procedure FormClose(Sender: TObject; var AAction: TCloseAction);
procedure acDeleteUpdate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
procedure lbPagesClick(Sender: TObject);
procedure alEditorUpdate(AAction: TBasicAction; var Handled: Boolean);
procedure lbPagesKeyPress(Sender: TObject; var Key: Char);
private
FPageList: TJvCustomPageList;
FIgnoreEvents: Boolean;
FEditor: TJvCustomPageEditor;
procedure SetPageList(const Value: TJvCustomPageList);
procedure UpdateList(ItemIndex: Integer);
procedure SelectPage(const Index: Integer);
//procedure Add(Page: TJvCustomPage);
function FindPage(APage: TJvCustomPage; out AIndex: Integer): Boolean;
procedure OnComponentRenamed(AComponent: TComponent);
procedure OnPersistentDeleting(APersistent: TPersistent);
procedure OnPersistentAdded(APersistent: TPersistent; Select: boolean);
public
property PageList:TJvCustomPageList read FPageList write SetPageList;
end;
procedure ShowPageListEditor(Editor: TJvCustomPageEditor; APageList: TJvCustomPageList);
implementation
uses
JvDsgnConsts;
{$R *.lfm}
procedure ShowPageListEditor(Editor: TJvCustomPageEditor; APageList: TJvCustomPageList);
var
frmPageListEditor: TfrmPageListEditor = nil;
begin
// Show the editor
frmPageListEditor := FindEditorForm(Editor.GetComponent) as TfrmPageListEditor;
if not Assigned(frmPageListEditor) then
frmPageListEditor := TfrmPageListEditor.Create(Application);
try
frmPageListEditor.FEditor := Editor;
frmPageListEditor.PageList := APageList;
frmPageListEditor.Caption := Format(RsFmtCaption,[APageList.Name]);
RegisterEditorForm(frmPageListEditor, Editor.GetComponent);
except
frmPageListEditor.Free;
raise;
end;
frmPageListEditor.EnsureVisible;
end;
type
TJvCustomPageAccess = class(TJvCustomPage);
procedure TfrmPageListEditor.acAddExecute(Sender: TObject);
//var
//APage: TJvCustomPage;
//Hook: TPropertyEditorHook;
begin
//if not FEditor.GetHook(Hook) then
// Exit;
//APage := PageList.GetPageClass.Create(PageList.Owner);
//try
// APage.Name := FEditor.GetDesigner.CreateUniqueComponentName(APage.ClassName);
// Add(APage);
// Hook.PersistentAdded(APage, True);
// FEditor.Modified;
//except
// APage.Free;
// raise;
//end;
if FEditor.GetPageControl <> nil then
FEditor.InsertPage;
end;
procedure TfrmPageListEditor.acDeleteExecute(Sender: TObject);
//var
// I: Integer;
// Hook: TPropertyEditorHook;
begin
//if Assigned(PageList.ActivePage) and FEditor.GetHook(Hook) then
//begin
// I := lbPages.ItemIndex;
// if lbPages.ItemIndex >= 0 then
// lbPages.Items.Delete(TJvCustomPageAccess(PageList.ActivePage).PageIndex);
// if GlobalDesignHook <> nil then
// GlobalDesignHook.SelectOnlyThis(PageList);
// PageList.ActivePage.Free;
// Hook.PersistentDeleted;
// if I >= lbPages.Items.Count then
// Dec(I);
// if (I >= 0) and (I < lbPages.Items.Count) then
// begin
// lbPages.ItemIndex := I;
// SelectPage(I);
// end
// else
// FEditor.Modified;
//end;
if (FEditor.GetPageControl <> nil) then
FEditor.RemovePage;
end;
procedure TfrmPageListEditor.acMoveUpExecute(Sender: TObject);
var
I: Integer;
begin
I := lbPages.ItemIndex;
lbPages.Items.Move(I, I-1);
if Assigned(PageList) then
begin
TJvCustomPageAccess(PageList.Pages[I]).PageIndex := I - 1;
lbPages.ItemIndex := I - 1;
end;
end;
procedure TfrmPageListEditor.acMoveDownExecute(Sender: TObject);
var
I: Integer;
begin
I := lbPages.ItemIndex;
lbPages.Items.Move(I, I+1);
if Assigned(PageList) then
begin
TJvCustomPageAccess(PageList.Pages[I]).PageIndex := I + 1;
lbPages.ItemIndex := I + 1;
end;
end;
procedure TfrmPageListEditor.SetPageList(const Value: TJvCustomPageList);
begin
if FPageList <> Value then
begin
FPageList := Value;
UpdateList(0);
end;
end;
//procedure TfrmPageListEditor.Add(Page: TJvCustomPage);
//var
// Hook: TPropertyEditorHook;
//begin
// if not FEditor.GetHook(Hook) then
// Exit;
// Page.Parent := PageList;
// Page.PageList := PageList;
// PageList.ActivePage := Page;
// Hook.PersistentAdded(Page, True);
// GlobalDesignHook.SelectOnlyThis(Page);
// FEditor.Modified;
// lbPages.ItemIndex := lbPages.Items.Add(Page.Name);
//end;
function TfrmPageListEditor.FindPage(APage: TJvCustomPage; out AIndex: Integer
): Boolean;
var
I: Integer;
begin
if Assigned(PageList) and (PageList.PageCount > 0) then
for I := 0 to PageList.PageCount - 1 do
if PageList.Pages[I] = APage then
begin
AIndex := I;
Exit(True);
end;
AIndex := -1;
Result := False;
end;
procedure TfrmPageListEditor.OnComponentRenamed(AComponent: TComponent);
var
I: Integer;
begin
if FIgnoreEvents then Exit;
if (AComponent is TJvCustomPage) and FindPage(TJvCustomPage(AComponent), I) then
UpdateList(I);
end;
procedure TfrmPageListEditor.OnPersistentDeleting(APersistent: TPersistent);
var
I: Integer;
begin
if FIgnoreEvents then Exit;
if (APersistent is TJvCustomPage) then
UpdateList(-1)
else if (APersistent is TJvCustomPageList) and (FEditor.GetPageControl = APersistent) then
Close;
end;
procedure TfrmPageListEditor.OnPersistentAdded(APersistent: TPersistent;
Select: boolean);
var
I: Integer;
begin
if FIgnoreEvents then Exit;
if (APersistent is TJvCustomPage) and FindPage(TJvCustomPage(APersistent), I) then
begin
UpdateList(I);
lbPages.Selected[I] := Select;
end;
end;
procedure TfrmPageListEditor.SelectPage(const Index: Integer);
var
Page: TJvCustomPageAccess;
begin
if Assigned(FPageList) and Active then
begin
FIgnoreEvents := True;
try
Page := nil;
if (Index >= 0) and (Index < FPageList.PageCount) then
Page := TJvCustomPageAccess(FPageList.Pages[Index]);
PageList.ActivePage := Page;
if GlobalDesignHook <> nil then
begin
GlobalDesignHook.SelectOnlyThis(Page);
GlobalDesignHook.Modified(PageList);
end;
finally
FIgnoreEvents := False;
end;
end;
end;
procedure TfrmPageListEditor.UpdateList(ItemIndex: Integer);
var
I: Integer;
begin
if Assigned(FPageList) then
begin
FIgnoreEvents := True;
lbPages.Items.BeginUpdate;
try
lbPages.Items.Clear;
for I := 0 to FPageList.PageCount - 1 do
lbPages.Items.Add(TJvCustomPageAccess(FPageList.Pages[I]).Name);
if (ItemIndex >= 0) and (ItemIndex < lbPages.Items.Count) then
lbPages.ItemIndex := ItemIndex
else
lbPages.ItemIndex := -1;
finally
lbPages.Items.EndUpdate;
FIgnoreEvents := False;
end;
end
else
lbPages.Items.Clear;
end;
procedure TfrmPageListEditor.FormClose(Sender: TObject;
var AAction: TCloseAction);
begin
IDEDialogLayoutList.SaveLayout(Self);
AAction := caFree;
end;
procedure TfrmPageListEditor.acDeleteUpdate(Sender: TObject);
begin
(Sender as TAction).Enabled :=
(lbPages.Items.Count > 0) and (lbPages.ItemIndex >= 0);
end;
procedure TfrmPageListEditor.FormDestroy(Sender: TObject);
begin
if Assigned(GlobalDesignHook) then
GlobalDesignHook.RemoveAllHandlersForObject(Self);
UnregisterEditorForm(Self);
end;
procedure TfrmPageListEditor.lbPagesClick(Sender: TObject);
begin
SelectPage(lbPages.ItemIndex);
end;
procedure TfrmPageListEditor.alEditorUpdate(AAction: TBasicAction;
var Handled: Boolean);
begin
acMoveUp.Enabled := lbPages.ItemIndex > 0;
acMoveDown.Enabled :=
(lbPages.ItemIndex <> -1) and
(lbPages.ItemIndex < lbPages.Items.Count - 1);
end;
procedure TfrmPageListEditor.lbPagesKeyPress(Sender: TObject;
var Key: Char);
begin
if lbPages.ItemIndex <> -1 then
begin
SelectPage(lbPages.ItemIndex);
//ActivateInspector(Key);
Key := #0;
end;
end;
procedure TfrmPageListEditor.FormCreate(Sender: TObject);
begin
IDEDialogLayoutList.ApplyLayout(Self);
if Assigned(GlobalDesignHook) then
begin
GlobalDesignHook.AddHandlerComponentRenamed(@OnComponentRenamed);
GlobalDesignHook.AddHandlerPersistentDeleting(@OnPersistentDeleting);
GlobalDesignHook.AddHandlerPersistentAdded(@OnPersistentAdded);
end;
end;
end.

View File

@ -30,65 +30,38 @@ unit JvPageListEditors;
interface
uses
SysUtils, Classes, ImgList, Menus,
PropEdits, GraphPropEdits, ComponentEditors;
SysUtils, ImgList, Graphics, Classes,
PropEdits, ComponentEditors, GraphPropEdits, PropEditUtils,
JvPageList, JvDsgnEditors;
type
(*
{ a property editor for the ActivePage property of TJvPageList }
TJvActivePageProperty = class(TComponentProperty)
public
function GetAttributes: TPropertyAttributes; override;
procedure GetValues(Proc: TGetStrProc); override;
end;
*)
TJvShowDesignCaptionProperty = class(TEnumProperty)
function GetAttributes: TPropertyAttributes; override;
end;
{ a component editor for the TJvPageList }
(********************************** NOT WORKING ***************
// adapted from TUntabbedNotebookComponentEditor)
TJvCustomPageListEditor = class(TDefaultComponentEditor)
protected
procedure AddNewPageToDesigner(Index: integer); virtual;
procedure DoAddPage; virtual;
procedure DoDeletePage; virtual;
procedure AddMenuItemsForPages(ParentMenuItem: TMenuItem); virtual;
procedure ShowPageMenuItemClick(Sender: TObject);
public
procedure ExecuteVerb(Index: Integer); override;
function GetVerb(Index: Integer): string; override;
function GetVerbCount: Integer; override;
procedure PrepareItem(Index: Integer; const AnItem: TMenuItem); override;
function PageList: TJvCustomPageList; virtual;
end;
TJvCustomPageEditor = class(TJvCustomPageListEditor)
public
function PageList: TJvCustomPageList; override;
function Page: TJvCustomPage; virtual;
end;
{
TJvCustomPageEditor = class(TComponentEditor)
private
procedure InsertPage;
procedure PrevPage;
procedure NextPage;
procedure RemovePage;
function GetPageControl: TJvCustomPageList;
public
function GetVerb(Index: Integer): string; override;
function GetVerbCount: Integer; override;
procedure ExecuteVerb(Index: Integer); override;
procedure Edit; override;
end; }
***********************************************)
TJvSettingsTreeImagesProperty = class(TImageIndexPropertyEditor)
function GetPageControl: TJvCustomPageList;
procedure InsertPage;
procedure PrevPage;
procedure NextPage;
procedure RemovePage;
end;
TJvSettingsTreeImagesProperty = class(TImageIndexPropertyEditor{TJvDefaultImageIndexProperty})
protected
function GetImageList: TCustomImageList; override;
end;
@ -97,13 +70,11 @@ implementation
uses
TypInfo,
JvPageListTreeView;
JvDsgnConsts, JvPageListTreeView, JvPageListEditorForm;
type
// THackPageList = class(TJvPageList);
THackTreeView = class(TJvCustomPageListTreeView);
{
const
cShowEditor = 0;
cDash = 1;
@ -114,157 +85,6 @@ const
cElementCount = 6;
const
unbvAddPage = 0;
unbvDeletePage = 1;
unbvShowPage = 2;
}
{ TJvCustomPageListEditor }
(****************************************** NOT WORKING
{ adapted from TUntabbedNotebookComponentEditor for LCL's Notebook
originally named "TJvCustomPageEditor" }
function TJvCustomPageListEditor.PageList: TJvCustomPageList;
begin
Result := TJvCustomPageList(GetComponent);
end;
procedure TJvCustomPageListEditor.AddNewPageToDesigner(Index: integer);
var
Hook: TPropertyEditorHook;
newPage: TJvCustomPage;
newName: string;
begin
Hook := nil;
if not GetHook(Hook) then exit;
DebugLn('GetHook ' + Hook.ClassName);
newPage := PageList.Pages[Index];
newName := GetDesigner.CreateUniqueComponentName(newPage.ClassName);
newPage.Caption := newName;
newPage.Name := newName;
PageList.ActivePageIndex := Index;
Hook.PersistentAdded(newPage, true);
Modified;
end;
procedure TJvCustomPageListEditor.DoAddPage;
begin
DebugLn('DoAddPage: ENTER');
if not HasHook then exit;
DebugLn('DoAddPage');
THackPageList(PageList).AddPage('');
DebugLn('DoAddPage: PageCount=' + IntToStr(PageList.pageCount));
AddNewPageToDesigner(PageList.PageCount-1);
DebugLn('DoAddPage: EXIT');
end;
procedure TJvCustomPageListEditor.DoDeletePage;
var
Hook: TPropertyEditorHook;
OldIndex: integer;
PageComponent: TPersistent;
begin
OldIndex := PageList.ActivePageIndex;
if (OldIndex >= 0) and (OldIndex < PageList.PageCount) then
begin
if not GetHook(Hook) then exit;
PageComponent := TPersistent(PageList.Pages[OldIndex]);
Hook.DeletePersistent(PageComponent);
end;
end;
procedure TJvCustomPageListEditor.AddMenuItemsForPages(ParentMenuItem: TMenuItem);
var
n: Integer;
i: integer;
NewMenuItem: TMenuItem;
begin
n := PageList.PageCount;
ParentMenuItem.Enabled := n > 0;
for i := 0 to n - 1 do
begin
NewMenuItem := TMenuItem.Create(ParentMenuItem);
NewMenuItem.Name := 'ShowPage' + IntToStr(i);
NewMenuItem.Caption := PageList.Pages[i].Name + ' "' + PageList.Pages[i].Caption + '"';
NewMenuItem.OnClick := @ShowPageMenuItemClick;
ParentMenuItem.Add(NewMenuItem);
end;
end;
procedure TJvCustomPageListEditor.ShowPageMenuItemClick(Sender: TObject);
var
AMenuItem: TMenuItem;
NewPageIndex: integer;
begin
AMenuItem := TMenuItem(Sender);
if (AMenuItem = nil) or (not (AMenuItem is TMenuItem)) then exit;
NewPageIndex := AMenuItem.MenuIndex;
if (NewPageIndex < 0) or (NewPageIndex >= PageList.PageCount) then exit;
PageList.ActivePageIndex := NewPageIndex;
GetDesigner.SelectOnlyThisComponent(PageList.Pages[NewPageIndex]);
end;
procedure TJvCustomPageListEditor.ExecuteVerb(Index: Integer);
begin
case Index of
unbvAddPage : DoAddPage;
unbvDeletePage : DoDeletePage; // beware: this can free the editor itself
end;
end;
function TJvCustomPageListEditor.GetVerb(Index: Integer): string;
begin
case Index of
unbvAddPage : Result := RsNewPage;
unbvDeletePage : Result := RsDelPage;
unbvShowPage : Result := RsShowPage;
else
Result := '';
end;
end;
function TJvCustomPageListEditor.GetVerbCount: Integer;
begin
Result := 3;
end;
procedure TJvCustomPageListEditor.PrepareItem(Index: Integer;
const AnItem: TMenuItem);
begin
inherited PrepareItem(Index, AnItem);
case Index of
unbvAddPage : ;
unbvDeletePage : AnItem.Enabled := PageList.ActivePageIndex >= 0;
unbvShowPage : AddMenuItemsForPages(AnItem);
end;
end;
{ TJvCustomPageEditor }
{ adapted from TUNBPageComponentEditor for LCL's Notebook pages }
function TJvCustomPageEditor.PageList: TJvCustomPageList;
var
lPage: TJvCustomPage;
begin
lPage := Page;
if (lPage.Parent <> nil) and (lPage.Parent is TJvCustomPageList) then
Result := TJvCustomPageList(lPage.Parent)
else
Result := nil;
end;
function TJvCustomPageEditor.Page: TJvCustomPage;
begin
Result := TJvCustomPage(GetComponent);
end;
{
procedure TJvCustomPageEditor.Edit;
begin
ExecuteVerb(cShowEditor);
@ -274,8 +94,7 @@ procedure TJvCustomPageEditor.ExecuteVerb(Index: Integer);
begin
case Index of
cShowEditor:
ShowMessage('NOT IMPLEMENTED');
// ShowPageListEditor(Designer, GetPageControl);
ShowPageListEditor(Self, GetPageControl);
cNextPage:
NextPage;
cPrevPage:
@ -289,7 +108,7 @@ end;
function TJvCustomPageEditor.GetPageControl: TJvCustomPageList;
begin
if Component is TJvCustomPageList then
if GetComponent is TJvCustomPageList then
Result := TJvCustomPageList(Component)
else
Result := TJvCustomPageList(TJvCustomPage(Component).PageList);
@ -322,14 +141,20 @@ procedure TJvCustomPageEditor.InsertPage;
var
P: TJvCustomPage;
C: TJvCustomPageList;
Hook: TPropertyEditorHook = nil;
begin
if not GetHook(Hook) then
Exit;
C := GetPageControl;
P := C.GetPageClass.Create(Designer.LookupRoot);
P := C.GetPageClass.Create(C.Owner);
try
P.Parent := C;
P.Name := Designer.UniqueName(C.GetPageClass.ClassName);
P.Name := GetDesigner.CreateUniqueComponentName(C.GetPageClass.ClassName);
P.PageList := C;
C.ActivePage := P;
Hook.PersistentAdded(P, True);
GlobalDesignHook.SelectOnlyThis(P);
Modified;
except
P.Free;
raise;
@ -350,24 +175,24 @@ procedure TJvCustomPageEditor.RemovePage;
var
AList: TJvCustomPageList;
APage: TJvCustomPage;
APers: TPersistent;
Hook: TPropertyEditorHook;
begin
AList := GetPageControl;
if (AList <> nil) and (AList.ActivePage <> nil) then
begin
APage := AList.ActivePage;
// Designer.SelectComponent(APage);
Designer.SelectOnlyThisComponent(APage);
APage.PageList := nil;
APage.Free;
Designer.Modified;
//APage.Free;
//Designer.Modified;
APers := TPersistent(APage);
if GetHook(Hook) then
Hook.DeletePersistent(APers);
end;
end;
}
*********************************************************)
//=== { TJvActivePageProperty } ==============================================
(*
function TJvActivePageProperty.GetAttributes: TPropertyAttributes;
begin
Result := [paValueList];
@ -378,16 +203,16 @@ var
I: Integer;
Component: TComponent;
begin
for I := 0 to Designer.GetRoot.ComponentCount - 1 do
begin
Component := Designer.GetRoot.Components[I];
if (Component.Name <> '') and (Component is TJvCustomPage) and
(TJvCustomPage(Component).PageList = GetComponent(0)) then
Proc(Component.Name);
end;
if (GlobalDesignHook <> nil) and (GlobalDesignHook.LookupRoot <> nil) and
(GlobalDesignHook.LookupRoot is TComponent) then
for I := 0 to TComponent(GlobalDesignHook.LookupRoot).ComponentCount - 1 do
begin
Component := TComponent(GlobalDesignHook.LookupRoot).Components[I];
if (Component.Name <> '') and (Component is TJvCustomPage) and
(TJvCustomPage(Component).PageList = GetComponent(0)) then
Proc(Component.Name);
end;
end;
*)
//=== { TJvSettingsTreeImagesProperty } ======================================
@ -405,7 +230,6 @@ begin
Result := nil;
end;
//=== { TJvShowDesignCaptionProperty } =======================================
function TJvShowDesignCaptionProperty.GetAttributes: TPropertyAttributes;

View File

@ -0,0 +1,90 @@
object JvProxyEditor: TJvProxyEditor
Left = 269
Top = 114
ClientWidth = 508
ClientHeight = 295
BorderIcons = [biSystemMenu]
Caption = 'Page Proxy Editor'
Icon.Data = {
0000010001002020100000000000E80200001600000028000000200000004000
0000010004000000000000020000000000000000000000000000000000000000
0000000080000080000000808000800000008000800080800000C0C0C0008080
80000000FF0000FF000000FFFF00FF000000FF00FF00FFFF0000FFFFFF000000
0000000000000000000000000000000000000000000000000000000000000000
000000000000000000F000000000000000000000000000000FF00F0000000000
0000000000000000FFF07F0000000BBBBBBBBBBBBBBBBB0FFFF07F0BBBB00B80
00000000000000FFF8F07F0000B00B8FFEFFFFFFFFF708FF88F07F0770B00B8F
FEFFFFFFFFF0B0F8D8F07F0770B00B8EEEEEEEEEEEE708FD8DF07F0A70B00B8F
FEFFFFFFFFF708F8D8F07F0A70B00B8FFEFFFFFFFFF0B0FD8DF07F0A70B00B8E
EEEEEEEEEEE708F8DFF07F0A70B00B8FFEFFFFFFFFF708FDFFF07F0A70B00B8F
FEFFFFFFFFF0B0FFAFF0CF0A70B00B8EEEEEEEEEEEE708FAAFF0CF0770B00B8F
FEFFFFFFFFF708FAAFF0CF0770B00B8FFEFFFFFFFFF0B0FAAFF0CF0770B00B8E
EEEEEEEEEEE708FAAFF07F0970B00B8FFEFFFFFFFFF708FAFFF07F0970B00B8F
FEFFFFFFFFF0B0FFFFF07F0770B00B8EEEEEEEEEEEE708FFFF087F0770B00B8F
FEFFFFFFFFF708FFF087F00770B00B8FFEFFFFFFFFF0B0FF08700877F0B00B8F
FE777777777708F0800877FFF0B00B8F00000000008708000777FFFFF0B00B88
0FF77778800000000000000000B00BBBB0FF77880BBB0BBBBBBBBBBBBBB00000
000FF780000BBB00000000000000000000FF7778000000000000000000000000
000000000000000000000000000000000000000000000000000000000000FFFF
FEFFFFFFFCFFFFFFF89FFFFFF01F800000010000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
000000000000000000000000000080000001F8063FFFFC0FFFFFFFFFFFFF0100}
OldCreateOrder = True
OnClose = FormClose
OnCreate = FormCreate
OnResize = FormResize
OnShow = FormShow
PixelsPerInch = 96
TextHeight = 13
object BtnPanel: TPanel
Left = 409
Top = 0
Width = 97
Height = 304
Align = alRight
BevelOuter = bvNone
TabOrder = 0
object CloseBtn: TButton
Left = 11
Top = 12
Width = 77
Height = 25
Anchors = [akTop, akRight]
Caption = 'Close'
TabOrder = 0
OnClick = CloseBtnClick
end
object DeleteBtn: TButton
Left = 11
Top = 44
Width = 77
Height = 25
Anchors = [akTop, akRight]
Caption = 'Delete'
TabOrder = 1
OnClick = DeleteBtnClick
end
end
object ProxyGrid: TDrawGrid
Left = 0
Top = 0
Width = 409
Height = 304
Align = alClient
ColCount = 2
Ctl3D = True
DefaultRowHeight = 17
FixedCols = 0
RowCount = 2
Options = [goFixedVertLine, goFixedHorzLine, goVertLine, goHorzLine, goRowSelect]
ParentCtl3D = False
TabOrder = 1
OnDrawCell = ProxyGridDrawCell
OnKeyDown = ProxyGridKeyDown
OnSelectCell = ProxyGridSelectCell
ColWidths = (
162
175)
end
end

View File

@ -0,0 +1,452 @@
{-----------------------------------------------------------------------------
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: JvPgMngrEd.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.delphi-jedi.org
Known Issues:
-----------------------------------------------------------------------------}
// $Id$
unit JvPageManagerForm;
{$I jvcl.inc}
interface
uses
SysUtils, Classes, Windows, Graphics, Controls, Forms, Grids, StdCtrls, ExtCtrls,
RTLConsts, DesignIntf, DesignEditors, VCLEditors, DesignWindows,
JvPageManager, JvJVCLUtils, JvComponent;
type
TJvProxyEditor = class(TDesignWindow)
BtnPanel: TPanel;
CloseBtn: TButton;
DeleteBtn: TButton;
ProxyGrid: TDrawGrid;
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure FormShow(Sender: TObject);
procedure ProxyGridDrawCell(Sender: TObject; Col, Row: Longint; Rect: TRect; State: TGridDrawState);
procedure ProxyGridSelectCell(Sender: TObject; Col, Row: Longint; var CanSelect: Boolean);
procedure CloseBtnClick(Sender: TObject);
procedure DeleteBtnClick(Sender: TObject);
procedure ProxyGridKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
procedure FormResize(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
FPageManager: TJvPageManager;
FDeleting: Boolean;
procedure SetPageManager(Value: TJvPageManager);
function GetForm: TCustomForm;
procedure UpdateData;
function CheckPageManager: Boolean;
procedure SelectProxy(Proxy: TJvPageProxy);
function ProxyByRow(Row: Integer): TJvPageProxy;
protected
function UniqueName(Component: TComponent): string; override;
procedure Activated; override;
public
procedure NameProxy(Sender: TObject);
procedure ItemsModified(const Designer: IDesigner); override;
procedure DesignerClosed(const ADesigner: IDesigner; AGoingDormant: Boolean); override;
function GetEditState: TEditState; override;
procedure ItemDeleted(const ADesigner: IDesigner; Item: TPersistent); override;
property PageManager: TJvPageManager read FPageManager write SetPageManager;
property OwnerForm: TCustomForm read GetForm;
end;
TJvProxyListProperty = class(TPropertyEditor)
function GetAttributes: TPropertyAttributes; override;
function GetValue: string; override;
procedure Edit; override;
end;
TJvPageManagerEditor = class(TComponentEditor)
procedure ExecuteVerb(Index: Integer); override;
function GetVerb(Index: Integer): string; override;
function GetVerbCount: Integer; override;
end;
TJvPageNameProperty = class(TStringProperty)
function GetAttributes: TPropertyAttributes; override;
procedure GetValues(Proc: TGetStrProc); override;
end;
TJvPageBtnProperty = class(TComponentProperty)
procedure GetValues(Proc: TGetStrProc); override;
end;
implementation
uses
Consts, Buttons,
JvDsgnConsts, JvDsgnTypes;
{$R *.dfm}
function FindEditor(Manager: TJvPageManager): TJvProxyEditor;
var
I: Integer;
begin
Result := nil;
for I := 0 to Screen.FormCount - 1 do
if Screen.Forms[I] is TJvProxyEditor then
if TJvProxyEditor(Screen.Forms[I]).PageManager = Manager then
begin
Result := TJvProxyEditor(Screen.Forms[I]);
Break;
end;
end;
procedure ShowProxyEditor(Designer: IJvDesigner; Manager: TJvPageManager);
var
Editor: TJvProxyEditor;
begin
if Manager = nil then
Exit;
Editor := FindEditor(Manager);
if Editor <> nil then
begin
Editor.Show;
if Editor.WindowState = wsMinimized then
Editor.WindowState := wsNormal;
end
else
begin
Editor := TJvProxyEditor.Create(Application);
try
Editor.Designer := IJvFormDesigner(Designer);
Editor.PageManager := Manager;
Editor.Show;
except
Editor.Free;
raise;
end;
end;
end;
//=== { TJvProxyListProperty } ===============================================
function TJvProxyListProperty.GetAttributes: TPropertyAttributes;
begin
Result := [paDialog, paReadOnly];
end;
function TJvProxyListProperty.GetValue: string;
var
List: TList;
begin
List := TList(Pointer(GetOrdValue));
if (List = nil) or (List.Count = 0) then
Result := srNone
else
Result := Format('(%s)', [GetPropType^.Name]);
end;
procedure TJvProxyListProperty.Edit;
begin
ShowProxyEditor(Designer, TJvPageManager(GetComponent(0)));
end;
//=== { TJvPageBtnProperty } =================================================
procedure TJvPageBtnProperty.GetValues(Proc: TGetStrProc);
var
I: Integer;
Component: TComponent;
begin
for I := 0 to Designer.Root.ComponentCount - 1 do
begin
Component := Designer.Root.Components[I];
if (Component.Name <> '') and (Component.InheritsFrom(TButtonControl) or
Component.InheritsFrom(TSpeedButton) or
AnsiSameText(Component.ClassName, 'TJvSpeedButton')) then
Proc(Component.Name);
end;
end;
//=== { TJvPageNameProperty } ================================================
function TJvPageNameProperty.GetAttributes: TPropertyAttributes;
begin
Result := [paValueList];
end;
procedure TJvPageNameProperty.GetValues(Proc: TGetStrProc);
var
PageProxy: TJvPageProxy;
I: Integer;
begin
PageProxy := GetComponent(0) as TJvPageProxy;
if (PageProxy <> nil) and (PageProxy.PageManager <> nil) and
(PageProxy.PageManager.PageOwner <> nil) then
for I := 0 to PageProxy.PageManager.PageCount - 1 do
Proc(PageProxy.PageManager.PageNames[I]);
end;
//=== { TJvPageManagerEditor } ===============================================
procedure TJvPageManagerEditor.ExecuteVerb(Index: Integer);
begin
case Index of
0:
ShowProxyEditor(Designer, TJvPageManager(Component));
end;
end;
function TJvPageManagerEditor.GetVerb(Index: Integer): string;
begin
case Index of
0:
Result := RsProxyEditor;
end;
end;
function TJvPageManagerEditor.GetVerbCount: Integer;
begin
Result := 1;
end;
//=== { TJvProxyEditor } =====================================================
procedure TJvProxyEditor.SetPageManager(Value: TJvPageManager);
begin
if FPageManager <> Value then
begin
if FPageManager <> nil then
FPageManager.OnCheckProxy := nil;
FPageManager := Value;
if FPageManager <> nil then
FPageManager.OnCheckProxy := NameProxy;
UpdateData;
end;
end;
function TJvProxyEditor.UniqueName(Component: TComponent): string;
var
Temp: string;
begin
Result := '';
if (Component <> nil) then
Temp := Component.ClassName
else
Temp := TJvPageProxy.ClassName;
if (UpCase(Temp[1]) = 'T') and (Length(Temp) > 1) then
System.Delete(Temp, 1, 1);
Result := Designer.UniqueName(Temp);
end;
function TJvProxyEditor.GetEditState: TEditState;
begin
Result := [];
end;
procedure TJvProxyEditor.NameProxy(Sender: TObject);
begin
if (Sender is TJvPageProxy) and (TJvPageProxy(Sender).Name = '') then
TJvPageProxy(Sender).Name := UniqueName(TJvPageProxy(Sender));
end;
procedure TJvProxyEditor.DesignerClosed(const ADesigner: IDesigner; AGoingDormant: Boolean);
begin
if ADesigner.Root = OwnerForm then
Free;
end;
procedure TJvProxyEditor.ItemsModified(const Designer: IDesigner);
begin
if not (csDestroying in ComponentState) then
UpdateData;
end;
procedure TJvProxyEditor.Activated;
begin
SelectProxy(ProxyByRow(ProxyGrid.Row - 1));
end;
procedure TJvProxyEditor.ItemDeleted(const ADesigner: IDesigner; Item: TPersistent);
begin
if Item = FPageManager then
begin
FPageManager := nil;
Close;
end;
end;
procedure TJvProxyEditor.UpdateData;
var
ProxyCount: Integer;
begin
if CheckPageManager then
begin
if not FDeleting then
FPageManager.Resync;
ProxyCount := FPageManager.PageProxies.Count;
if ProxyCount = 0 then
begin
ProxyGrid.RowCount := 2;
SelectProxy(nil);
end
else
ProxyGrid.RowCount := 1 + ProxyCount;
DeleteBtn.Enabled := ProxyCount > 0;
ProxyGrid.Invalidate;
end;
end;
function TJvProxyEditor.GetForm: TCustomForm;
begin
Result := TCustomForm(Designer.Root); { GetParentForm(FBar) }
end;
procedure TJvProxyEditor.FormClose(Sender: TObject; var Action: TCloseAction);
begin
Action := caFree;
if FPageManager <> nil then
FPageManager.OnCheckProxy := nil;
end;
procedure TJvProxyEditor.FormShow(Sender: TObject);
begin
if FPageManager.PageOwner <> nil then
Caption := Format(RsPageProxies, [FPageManager.PageOwner.Name]);
end;
function TJvProxyEditor.CheckPageManager: Boolean;
begin
Result := (FPageManager <> nil) and (FPageManager.Owner <> nil) and
(Designer.Root <> nil);
end;
type
TDesignerSelectionList = IDesignerSelections;
procedure TJvProxyEditor.SelectProxy(Proxy: TJvPageProxy);
var
FComponents: TDesignerSelectionList;
begin
if CheckPageManager and Active then
begin
FComponents := TDesignerSelections.Create;
if Proxy <> nil then
FComponents.Add(Proxy)
else
FComponents.Add(FPageManager);
SetSelection(FComponents);
end;
end;
function TJvProxyEditor.ProxyByRow(Row: Integer): TJvPageProxy;
begin
Result := nil;
if CheckPageManager and (Row >= 0) and
(Row < FPageManager.PageProxies.Count) then
Result := FPageManager.PageProxies.Items[Row];
end;
procedure TJvProxyEditor.ProxyGridDrawCell(Sender: TObject;
Col, Row: Longint; Rect: TRect; State: TGridDrawState);
var
CellText: string;
Proxy: TJvPageProxy;
begin
CellText := '';
if gdFixed in State then
case Col of
0:
CellText := RsProxyName;
1:
CellText := RsPageName;
end
else
begin
Proxy := ProxyByRow(Row - 1);
if Proxy <> nil then
begin
case Col of
0:
CellText := Proxy.Name;
1:
CellText := Proxy.PageName;
end;
end;
end;
DrawCellText(ProxyGrid, Col, Row, CellText, Rect, taLeftJustify, vaCenterJustify);
end;
procedure TJvProxyEditor.ProxyGridSelectCell(Sender: TObject;
Col, Row: Longint; var CanSelect: Boolean);
begin
SelectProxy(ProxyByRow(Row - 1));
end;
procedure TJvProxyEditor.CloseBtnClick(Sender: TObject);
begin
Close;
end;
procedure TJvProxyEditor.DeleteBtnClick(Sender: TObject);
var
Proxy: TJvPageProxy;
begin
Proxy := ProxyByRow(ProxyGrid.Row - 1);
if Proxy <> nil then
begin
TCustomForm(Designer.Root).Designer.ValidateRename(Proxy, Proxy.Name, '');
FDeleting := True;
try
Proxy.Free;
Designer.Modified;
finally
FDeleting := False;
end;
end;
end;
procedure TJvProxyEditor.ProxyGridKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
if Shift = [] then
begin
case Key of
VK_RETURN:
if ProxyByRow(ProxyGrid.Row - 1) <> nil then
ActivateInspector(#0);
VK_DELETE:
DeleteBtnClick(nil);
end;
end;
end;
procedure TJvProxyEditor.FormResize(Sender: TObject);
begin
with ProxyGrid do
begin
DefaultColWidth := (ClientWidth - 1) div 2;
ColWidths[1] := ClientWidth - ColWidths[0] - 1;
end;
end;
procedure TJvProxyEditor.FormCreate(Sender: TObject);
begin
if NewStyleControls then
Font.Style := [];
end;
end.