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.
Mailing lists / lazarus / 2016-05
Detect that component selected in OI.
14 messages · 3 people · –
- VVojtěch Čihák 7
- OOndrej Pokorny 6
- HHoward Page-Clark 1
Reply by email Subscribe to this list Your subscription
Read-only archive. Use j and k to move between messages.
Vojt?ch ?ih?k wroteis 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.
? 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
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.
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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20160522/d8525df7/attachment-0001.html>
Ondrej Pokorny wroteIMO 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
Ondrej Pokorny wrote 6 lines
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
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; ??
?
No need. I added CM_OBJECTINSPECTORSELECT in r52338. Ondrej
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; ?
?
V.
Vojt?ch ?ih?k wrote 15 lines
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>
Thank you, Ondrej, it works and it is pretty easy. ? Summary: ? Let's say you have class…
Vojt?ch ?ih?k wrote 12 lines
+ 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>
Thank you, Ondrej, it works and it is pretty easy. ? Summary: ? Let's say you have class…
OK, thanks.
With a small correction: it must be hooked only in design time. ?…
Separating Component Editors is quiet easy but how can I separate the Hook (SelectionHook method) when I need "self"? ?
Thanks, V.
?
Vojt?ch ?ih?k wrote 6 lines
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 hereOndrej
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20160522/5a2ee76c/attachment-0001.html>
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
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 hereOndrej
----------
