LCL: add CM_OBJECTINSPECTORSELECT message (to handle OI selection change). Implement it for TPageControl and TNotebook.

git-svn-id: trunk@52338 -
This commit is contained in:
ondrej 2016-05-22 09:01:20 +00:00
parent e2d6d7b8b3
commit e26e156a5c
7 changed files with 57 additions and 9 deletions

View File

@ -25,7 +25,7 @@ interface
uses
Classes, SysUtils, TypInfo, LCLProc, AvgLvlTree, Dialogs, Controls, ComCtrls,
Graphics, ExtCtrls,
Graphics, ExtCtrls, LMessages,
ObjInspStrConsts, PropEdits, PropEditUtils;
type
@ -286,6 +286,7 @@ var
ANode: TTreeNode;
APersistent: TPersistent;
NewSelection: TPersistentSelectionList;
Msg: TLMessage;
begin
NewSelection := TPersistentSelectionList.Create;
try
@ -308,13 +309,26 @@ begin
if NewSelection.IsEqual(FComponentList.Selection) then
Exit;
FComponentList.Selection.Assign(NewSelection);
if (NewSelection.Count=1) and
(NewSelection[0] is TCustomPage) and
(TCustomPage(NewSelection[0]).Parent is TCustomTabControl) then
if (NewSelection.Count=1) then
begin
TCustomTabControl(TCustomPage(NewSelection[0]).Parent).PageIndex :=
TCustomPage(NewSelection[0]).PageIndex;
ANode := GetFirstMultiSelected;
FillChar(Msg{%H-}, SizeOf(Msg), 0);
Msg.msg := CM_OBJECTINSPECTORSELECT;
while Assigned(ANode) do
begin
APersistent := TPersistent(ANode.Data);
if Assigned(APersistent) then
begin
if APersistent is TControl then
TControl(APersistent).Perform(Msg.msg, Msg.wParam, Msg.lParam)
else // support TComponent(s) as well
APersistent.Dispatch(Msg);
end;
Msg.lParam := 1; // see comment at CM_OBJECTINSPECTORSELECT for more info
ANode := ANode.Parent;
end;
end;
inherited DoSelectionChanged;
finally
NewSelection.Free;

View File

@ -244,6 +244,7 @@ type
procedure SetParent(AParent: TWinControl); override;
property Flags: TPageFlags read FFlags write FFlags;
procedure CMHitTest(var Message: TLMNCHITTEST); message CM_HITTEST;
procedure CMObjectInspectorSelect(var Message: TLMessage); message CM_OBJECTINSPECTORSELECT;
procedure CMVisibleChanged(var Message: TLMessage); message CM_VISIBLECHANGED;
function GetPageIndex: integer; virtual;
procedure SetPageIndex(AValue: Integer); virtual;

View File

@ -42,11 +42,15 @@ type
TPage = class(TCustomControl)
private
FOnBeforeShow: TBeforeShowPageEvent;
function GetPageIndex: Integer;
protected
procedure CMObjectInspectorSelect(var Message: TLMessage); message CM_OBJECTINSPECTORSELECT;
procedure SetParent(AParent: TWinControl); override;
public
constructor Create(TheOwner: TComponent); override;
destructor Destroy; override;
public
property PageIndex: Integer read GetPageIndex;
published
// Lazarus-specific TPage events
// OnBeforeShow occurs before a page is displayed, so that
@ -128,8 +132,8 @@ type
{ function TabIndexAtClientPos(ClientPos: TPoint): integer;
function TabRect(AIndex: Integer): TRect;
function GetImageIndex(ThePageIndex: Integer): Integer; virtual;
function IndexOf(APage: TCustomPage): integer;
function CustomPage(Index: integer): TCustomPage;}
function IndexOf(APage: TPage): integer;
public
property ActivePage: String read GetActivePage;// write SetActivePage; // should not be published because the read can raise an exception
property ActivePageComponent: TPage read GetActivePageComponent;// write SetActivePage; // should not be published because the read can raise an exception

View File

@ -102,8 +102,9 @@ const
CM_TABLETOPTIONSCHANGED = CM_BASE + 87 unimplemented;
CM_PARENTTABLETOPTIONSCHANGED = CM_BASE + 88 unimplemented;
// LCL only
CM_APPSHOWBTNGLYPHCHANGED = CM_BASE + CM_LCLOFFSET + 68;
CM_APPSHOWMENUGLYPHCHANGED = CM_BASE + CM_LCLOFFSET + 69;
CM_APPSHOWBTNGLYPHCHANGED = CM_BASE + CM_LCLOFFSET + 68;
CM_APPSHOWMENUGLYPHCHANGED = CM_BASE + CM_LCLOFFSET + 69;
CM_OBJECTINSPECTORSELECT = CM_BASE + CM_LCLOFFSET + 70; // sent when this or a child node is selected in the OI (LParam = 0 for this node, LParam = 1 for a child node)
CN_BASE = $BC00;
CN_CHARTOITEM = CN_BASE + LM_CHARTOITEM;

View File

@ -195,6 +195,12 @@ begin
FOnHide(Self);
end;
procedure TCustomPage.CMObjectInspectorSelect(var Message: TLMessage);
begin
if (Parent is TCustomTabControl) and (csDesigning in ComponentState) then
TCustomTabControl(Parent).PageIndex := PageIndex;
end;
procedure TCustomPage.DoShow;
begin
if Assigned(FOnShow) then

View File

@ -154,6 +154,15 @@ begin
Result := FPageIndex;
end;
function TNotebook.IndexOf(APage: TPage): integer;
begin
for Result := 0 to PageCount-1 do
if Page[Result] = APage then
Exit;
Result := -1;
end;
procedure TNotebook.InsertPage(APage: TPage; Index: Integer);
begin
if FPageList.IndexOf(APage) >= 0 then Exit;

View File

@ -56,6 +56,12 @@ begin
Visible := False;
end;
procedure TPage.CMObjectInspectorSelect(var Message: TLMessage);
begin
if (Parent is TNotebook) and (csDesigning in ComponentState) then
TNotebook(Parent).PageIndex := PageIndex;
end;
destructor TPage.Destroy;
begin
{$ifdef DEBUG_NEW_NOTEBOOK}
@ -73,6 +79,13 @@ begin
inherited Destroy;
end;
function TPage.GetPageIndex: Integer;
begin
if Parent is TNotebook then
Result := TNotebook(Parent).IndexOf(Self)
else
Result := -1;
end;
// included by extctrls.pp