Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / lazarus / 2016-05

Detect that component selected in OI.

14 messages · 3 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Vojtěch Čihák

Hi,
?
is there some event (message or method) triggered when component is selected in OI? It's just like PageControl and its TabSheets. When you select TabSheet in OI, component is repainted in form designer. I oberved the code but I didn't find solution. ?
Thanks, V.

Reply by email

Howard Page-Clark
to Vojtěch Čihák
Vojt?ch ?ih?k wrote
is there some event (message or method) triggered when component is selected in OI? It's just like PageControl and its TabSheets. When you select TabSheet in OI, component is repainted in form designer. I oberved the code but I didn't find solution.

TObjectInspectorDlg has several public properties that may help:

Selection: TPersistentSelectionList
OnSelectionChange: TNotifyEvent
OnSelectPersistentsInOI: TNotifyEvent

also a boolean property EnableHookGetSelection which gives you access to protected get/set selection handlers.

There are possibly other relevant methods too, it is a complex class.

Reply by email

Vojtěch Čihák
to Vojtěch Čihák: ? is there some event (message or method) triggered when component is selected in OI?…

That's something else. I need something that will be part of component. Something like overriden SetFocus; or so. So far I tried CMDesignHitTest and DoEnter but it didn't work. It's like when you design Form with PageControl and two TabSheets. You select the second TabSheet in OI and PageControl "knows" it and it changes the tabs on the form. I'd like to know how this works (what component's code allows this). ?
Thanks, V.
______________________________________________________________

Show quoted text 5 lines
Od: Howard Page-Clark Komu: Datum: 21.05.2016 20:18 P?edm?t: Re: [Lazarus] Detect that component selected in OI.

TObjectInspectorDlg has several public properties that may help:

Selection: TPersistentSelectionList
OnSelectionChange: TNotifyEvent
OnSelectPersistentsInOI: TNotifyEvent

also a boolean property EnableHookGetSelection which gives you access to protected get/set selection handlers.

There are possibly other relevant methods too, it is a complex class.

Reply by email

Ondrej Pokorny
to Vojtěch Čihák

I didn't know it either. But it was quite easy to find out:

1.) Debug Lazarus IDE within another instance.
2.) In the IDE-to-debug create a project with TPageControl and 2 tabs. 3.) Set breakpoint to "TCustomTabControl.ShowCurrentPage" in the debugger IDE.
4.) Change pages with the OI in the IDE-to-debug.

Now you get your Call Stack filled with useful information. See #4 for relevant line:

#0 SHOWCURRENTPAGE(0x15087170) at include\customnotebook.inc:1049 #1 DOSENDPAGEINDEX(0x15087170) at include\customnotebook.inc:1072 #2 INTERNALSETPAGEINDEX(0x15087170, 0) at include\customnotebook.inc:985 #3 SETPAGEINDEX(0x15087170, 0) at include\customnotebook.inc:587 *#4 DOSELECTIONCHANGED(0x150683a0) at componenttreeview.pas:315* #5 INTERNALSELECTIONCHANGED(0x150683a0) at include\treeview.inc:5715 #6 UNLOCKSELECTIONCHANGEEVENT(0x150683a0) at include\treeview.inc:5909 #7 SELECTONLYTHIS(0x169b89f0, 0x19c80ed8) at include\treeview.inc:2097 #8 MOUSEDOWN(0x150683a0, MBLEFT, [SSLEFT], 104, 64) at include\treeview.inc:5349
//...

So you can see that the changing code is hard-coded into IdeIntf. (The callback is in "TComponentTreeView.DoSelectionChanged;".)

IMO you can suggest a custom designing message that will handle it without hard-coding it into the IDE. Because e.g. the TNotebook page change doesn't work.

Ondrej

Vojt?ch ?ih?k wrote 13 lines
That's something else. I need something that will be part of component. Something like overriden SetFocus; or so. So far I tried CMDesignHitTest and DoEnter but it didn't work. It's like when you design Form with PageControl and two TabSheets. You select the second TabSheet in OI and PageControl "knows" it and it changes the tabs on the form. I'd like to know how this works (what component's code allows this). Thanks, V.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20160522/d8525df7/attachment-0001.html>

Reply by email

Ondrej Pokorny
to Ondrej Pokorny
Ondrej Pokorny wrote
IMO you can suggest a custom designing message that will handle it without hard-coding it into the IDE. Because e.g. the TNotebook page change doesn't work.

No need. I added CM_OBJECTINSPECTORSELECT in r52338.

Ondrej

Reply by email

Ondrej Pokorny
to Ondrej Pokorny
Ondrej Pokorny wrote 6 lines
On 22.05.2016 8:50, Ondrej Pokorny wrote: > IMO you can suggest a custom designing message that will handle it > without hard-coding it into the IDE. Because e.g. the TNotebook page > change doesn't work. No need. I added CM_OBJECTINSPECTORSELECT in r52338.

No, I reverted it. I though a little bit more about it and we shouldn't pollute the LCL with designer code if not necessary.

Instead, do what Howard suggested (although not directly): In your component's design-time package, register a SetSelection hook ("GlobalDesignHook.AddHandlerSetSelection(@OnComponentSelection);"). Then in OnComponentSelection you check if your own component is in the new selection and do whatever you want.

Ondrej

Reply by email

Vojtěch Čihák
to Ondrej Pokorny: No need. I added CM_OBJECTINSPECTORSELECT in r52338. Ondrej

Thank you, Ondrej, it works and it is pretty easy. ?
Summary:
?
Let's say you have class TMyPageControl which consists of TMyTabSheet classes (TWinControls). ?
uses ... PropEdits, ...;
?
TMyTabSheet?= class(TWinControl)
? ...
? protected
? ? procedure HookSelection(const ASelection: TPersistentSelectionList); ? ...
? end; ? ??
?
constructor?TMyTabSheet.Create(TheOwner: TComponent); begin
? ...
? GlobalDesignHook.AddHandlerSetSelection(@HookSelection); end; ?
?
procedure?TMyTabSheet.HookSelection(const ASelection: TPersistentSelectionList); begin
? if assigned(FMyPageControl) and (ASelection.IndexOf(self)>=0) then ? ??FMyPageControl.TabIndex:=?FMyPageControl.Pages.IndexOf(self); end; ??
?

Reply by email

Ondrej Pokorny
to Vojtěch Čihák
Vojt?ch ?ih?k wrote 15 lines
With a small correction: it must be hooked only in design time. constructor TMyTabSheet.Create(TheOwner: TComponent); begin ... if csDesigning in ComponentState then GlobalDesignHook.AddHandlerSetSelection(@HookSelection); end;

You should separate the hook completely from your run-time code. Use the hook (and include IDEIntf) only in your design-time package and unit.

Ondrej
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20160522/589a37fc/attachment.html>

Reply by email

Ondrej Pokorny
to Vojtěch Čihák: Thank you, Ondrej, it works and it is pretty easy. ? Summary: ? Let's say you have class…
Vojt?ch ?ih?k wrote 12 lines
procedure TMyTabSheet.HookSelection(const ASelection: TPersistentSelectionList); begin if assigned(FMyPageControl) and (ASelection.IndexOf(self)>=0) then FMyPageControl.TabIndex:= FMyPageControl.Pages.IndexOf(self); end;

+ You also should check for selecting child controls (e.g. the user selects a button in the page). See
TObjectInspectorDlg.DefSelectionVisibleInDesigner from r52344.

Ondrej

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20160522/518f0d07/attachment.html>

Reply by email

Ondrej Pokorny
to Vojtěch Čihák
Vojt?ch ?ih?k wrote 6 lines
Separating Component Editors is quiet easy but how can I separate the Hook (SelectionHook method) when I need "self"? Thanks, V.
For what do you need self? You have the list, so do
for I := 0 to ASelection.Count-1 do
   if ASelection[I] is TMyTabSheet then
     // do your job here

Ondrej
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20160522/5a2ee76c/attachment-0001.html>

Reply by email

Vojtěch Čihák
to Vojtěch Čihák: Separating Component Editors is quiet easy but how can I separate the Hook (SelectionHook…

Thanks again, you're right. Now it all works, even with recursive searching in parents. ..______________________________________________________________

Show quoted text 5 lines
Od: Ondrej Pokorny Komu: Lazarus mailing list Datum: 22.05.2016 17:47 P?edm?t: Re: [Lazarus] Detect that component selected in OI.

On 22.05.2016 17:37, Vojt?ch ?ih?k wrote:Separating Component Editors is quiet easy but how can I separate the Hook (SelectionHook method) when I need "self"? ?
Thanks, V.

 For what do you need self? You have the list, so do
 for I := 0 to ASelection.Count-1 do
 ? if ASelection[I] is TMyTabSheet then
 ??? // do your job here

Ondrej

----------

Reply by email