Re: [Lazarus] Detect that component selected in OI.

2016-05-22 Thread Vojtěch Čihák

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

Od: Ondrej Pokorny <laza...@kluug.net>
Komu: Lazarus mailing list <lazarus@lists.lazarus.freepascal.org>
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


--

--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus 
<http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus>

--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] Detect that component selected in OI.

2016-05-22 Thread Ondrej Pokorny

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
--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] Detect that component selected in OI.

2016-05-22 Thread Vojtěch Čihák

Separating Component Editors is quiet easy but how can I separate the Hook (SelectionHook 
method) when I need "self"?
 
Thanks, V.
 
__

Od: Ondrej Pokorny <laza...@kluug.net>
Komu: Lazarus mailing list <lazarus@lists.lazarus.freepascal.org>
Datum: 22.05.2016 16:10
Předmět: Re: [Lazarus] Detect that component selected in OI.


On 22.05.2016 15:45, Vojtěch Čihák wrote: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


--

--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus 
<http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus>

--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] Detect that component selected in OI.

2016-05-22 Thread Vojtěch Čihák

OK, thanks.
__

Od: Ondrej Pokorny <laza...@kluug.net>
Komu: Lazarus mailing list <lazarus@lists.lazarus.freepascal.org>
Datum: 22.05.2016 16:21
Předmět: Re: [Lazarus] Detect that component selected in OI.


On 22.05.2016 14:13, Vojtěch Čihák wrote: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


--

--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus 
<http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus>

--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] Detect that component selected in OI.

2016-05-22 Thread Ondrej Pokorny

On 22.05.2016 14:13, Vojtěch Čihák wrote:


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

--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] Detect that component selected in OI.

2016-05-22 Thread Ondrej Pokorny

On 22.05.2016 15:45, Vojtěch Čihák wrote:


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
--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] Detect that component selected in OI.

2016-05-22 Thread Vojtěch Čihák

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.
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus 


--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] Detect that component selected in OI.

2016-05-22 Thread Vojtěch Čihák

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;   
 
__

Od: Ondrej Pokorny <laza...@kluug.net>
Komu: Lazarus mailing list <lazarus@lists.lazarus.freepascal.org>
Datum: 22.05.2016 12:56
Předmět: Re: [Lazarus] Detect that component selected in OI.



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

--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus 
<http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus>

--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] Detect that component selected in OI.

2016-05-22 Thread Ondrej Pokorny

On 22.05.2016 11:02, Ondrej Pokorny wrote:

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

--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] Detect that component selected in OI.

2016-05-22 Thread Ondrej Pokorny

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.

Ondrej


--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] Detect that component selected in OI.

2016-05-22 Thread Ondrej Pokorny

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


On 21.05.2016 22:49, Vojtěch Čihák wrote:


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.



--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] Detect that component selected in OI.

2016-05-21 Thread Vojtěch Čihák

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.
__

Od: Howard Page-Clark <h...@talktalk.net>
Komu: lazarus@lists.lazarus.freepascal.org
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.

--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus 
<http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus>

--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] Detect that component selected in OI.

2016-05-21 Thread Howard Page-Clark

On 21/05/16 18:48, 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.

--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


[Lazarus] Detect that component selected in OI.

2016-05-21 Thread 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.

--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus