Re: [lazarus] ParentWindow

2007-11-11 Thread Mattias Gaertner
On Sun, 11 Nov 2007 09:16:04 +0100
Marc Santhoff [EMAIL PROTECTED] wrote:

[...]
 Only out of curiosity:
 
 Wouldn't a X Windows window ID do? I think that's the equivalent to
 WinAPIs handles.
 
   GDK_WINDOW_XWINDOW (GTK_WIDGET (my_window)-window);
 
 is the function/macro to use then.
[...]
  Maybe my statement was not clear: The Parent/Child connection is the
  main problem. It would be easier to handle the child/parent
  relationship by the LCL and keep the 1:1 mapping between controls
  and handles.
 
 But GTK does have the functions
 
   gtk_widget_get_toplevel()
   gtk_widget_get_ancestor()
   gtk_widget_get_parent()
 
 So the GTK-binding could use them?

Again in other words:
Of course reparenting is possible under all platforms. The LCL use it
everywhere. The problem is that it works different under all
platforms, so you need a wrapper: The LCL is a TWinControl
wrapper to make reparenting possible platform independently.
Reparenting by Handle is the opposite way.
It's easy to do on one platform (e.g. Delphi on win32), but it's very
complex to do it on all platforms. Especially the whole LCL code must
be checked. So it will be a lot of work. And who will maintain it? It
seems only very few people will use this feature, so it will hardly be
tested and probably it will break by the next patch.

Conclusion:
It is technically doable, but it will need a lot of work and will
hardly be maintained.

That's why I propose a TForeignHandleControl. That will be easier. It
can be implemented as package and can start first on the windows
platform. And when it works on all platforms it can be added to
the LCL. See for example the trayicon, openglcontrol and
printers4lazarus packages.


Mattias

_
 To unsubscribe: mail [EMAIL PROTECTED] with
unsubscribe as the Subject
   archives at http://www.lazarus.freepascal.org/mailarchives


Re: [lazarus] ParentWindow

2007-11-11 Thread Marc Santhoff
Am Sonntag, den 11.11.2007, 12:21 +0100 schrieb Mattias Gaertner:
 On Sun, 11 Nov 2007 09:16:04 +0100
 Marc Santhoff [EMAIL PROTECTED] wrote:
 
 [...]
  Only out of curiosity:
  
  Wouldn't a X Windows window ID do? I think that's the equivalent to
  WinAPIs handles.
  
GDK_WINDOW_XWINDOW (GTK_WIDGET (my_window)-window);
  
  is the function/macro to use then.
 [...]
   Maybe my statement was not clear: The Parent/Child connection is the
   main problem. It would be easier to handle the child/parent
   relationship by the LCL and keep the 1:1 mapping between controls
   and handles.
  
  But GTK does have the functions
  
gtk_widget_get_toplevel()
gtk_widget_get_ancestor()
gtk_widget_get_parent()
  
  So the GTK-binding could use them?
 
 Again in other words:
 Of course reparenting is possible under all platforms. The LCL use it
 everywhere. The problem is that it works different under all
 platforms, so you need a wrapper: The LCL is a TWinControl
 wrapper to make reparenting possible platform independently.
 Reparenting by Handle is the opposite way.
 It's easy to do on one platform (e.g. Delphi on win32), but it's very
 complex to do it on all platforms. Especially the whole LCL code must
 be checked. So it will be a lot of work. And who will maintain it? It
 seems only very few people will use this feature, so it will hardly be
 tested and probably it will break by the next patch.
 
 Conclusion:
 It is technically doable, but it will need a lot of work and will
 hardly be maintained.
 
 That's why I propose a TForeignHandleControl. That will be easier. It
 can be implemented as package and can start first on the windows
 platform. And when it works on all platforms it can be added to
 the LCL. See for example the trayicon, openglcontrol and
 printers4lazarus packages.

I think I begin to understand now. I misundestood the matter to be a
lack of capability in GTK. 

Marc


_
 To unsubscribe: mail [EMAIL PROTECTED] with
unsubscribe as the Subject
   archives at http://www.lazarus.freepascal.org/mailarchives


Re: [lazarus] ParentWindow

2007-11-10 Thread Felipe Monteiro de Carvalho
I would try using the Parent property. What's the difference between
Parent and ParentWindow?


-- 
Felipe Monteiro de Carvalho

_
 To unsubscribe: mail [EMAIL PROTECTED] with
unsubscribe as the Subject
   archives at http://www.lazarus.freepascal.org/mailarchives


Re: [lazarus] ParentWindow

2007-11-10 Thread Christian Budde

Hello Felipe,

I would try using the Parent property. What's the difference between
Parent and ParentWindow?
Thanks for the tip, but I tried that already. Parent needs a 
TWinControl, which I don't have. I only have the window handle. I tried 
FindControl(Handle : THandle) : TWinControl (or similar, don't remember 
exactly from memory), but it only returned nil. Having a look at the 
FindControl() code, it seems as if it was just querying a list of self 
instancieted TWinControl descendants.
Having another look at the code I found another constructor 
TWinControl.CreateParented(Handle : THandle) useful. It exactly allows 
me to specify and set the private fParentedWindow property of a 
TWinControl element. However a) I can't just recreate that form, since 
it already exists and b) even in one test, where I recreated the form it 
fails (the behavior is that the form is located always on pixel (0, 0) 
of my screen).


The second thing is: I don't know how to do it platform independent. I 
know since the SDK I'm using also exists on the mac and on linux, that 
it must work similar, but rewriting the SDK in pascal from scratch I do 
not have a clue how to do this. The rest (of my translated SDK) works 
perfectly fine, but this tiny problem stops me from using it.


Kind regards,

   Christian

_
To unsubscribe: mail [EMAIL PROTECTED] with
   unsubscribe as the Subject
  archives at http://www.lazarus.freepascal.org/mailarchives


Re: [lazarus] ParentWindow

2007-11-10 Thread Christian Budde

Felipe Monteiro de Carvalho schrieb:

Is the interface of your SDK fixed? I mean, can't you ask users of the
SDK to pass a TForm or something instead of a system handle?
  
Yes, it is fixed (it's the VST Plugin SDK). I also have written some 
host code for these plugins, but since the specification is fixed, I 
have to live with that limitation.

To me it seams like this would require being implemented on LCL level.
If you wish to follow this road we can guide you. I would say it would
require adding a new widgetset function which needs to be implemented
for all widgetsets. This function would reparent a form given just a
system handle.
Yes I'd wish to do so. I have windows and OSX here (I guess I can test 
the GTK part in OSX). What I don't have is much time, so I'd really like 
to only implement that function. Do you have a link where I can find 
instructions about how to do so?
I already tried it once, but I had to recompile the LCL quite often and 
I probably lost patience.


Thanks for the helping hand,

   Christian

_
To unsubscribe: mail [EMAIL PROTECTED] with
   unsubscribe as the Subject
  archives at http://www.lazarus.freepascal.org/mailarchives


Re: [lazarus] ParentWindow

2007-11-10 Thread Felipe Monteiro de Carvalho
 Yes I'd wish to do so. I have windows and OSX here (I guess I can test
 the GTK part in OSX). What I don't have is much time, so I'd really like
 to only implement that function. Do you have a link where I can find
 instructions about how to do so?

I don't think there are instructions. I just made a commit where I
added a new function to TWSCustomTrayIcon, called ShowBalloonHint:

http://www.freepascal.org/cgi-bin/viewcvs.cgi?root=lazarusrev=12809view=rev

You can study it and see which places were altered. Would would need
to do something similar.

Where is ParentWindow declared? TCustomForm?

 I already tried it once, but I had to recompile the LCL quite often and
 I probably lost patience

You will have to rebuild lcl sometimes to do this, and also to test
and fix if it's wrong.

-- 
Felipe Monteiro de Carvalho

_
 To unsubscribe: mail [EMAIL PROTECTED] with
unsubscribe as the Subject
   archives at http://www.lazarus.freepascal.org/mailarchives


Re: [lazarus] ParentWindow

2007-11-10 Thread Mattias Gaertner
On Sat, 10 Nov 2007 13:01:55 +0100
Felipe Monteiro de Carvalho [EMAIL PROTECTED] wrote:

  Yes I'd wish to do so. I have windows and OSX here (I guess I can
  test the GTK part in OSX). What I don't have is much time, so I'd
  really like to only implement that function. Do you have a link
  where I can find instructions about how to do so?
 
 I don't think there are instructions. I just made a commit where I
 added a new function to TWSCustomTrayIcon, called ShowBalloonHint:
 
 http://www.freepascal.org/cgi-bin/viewcvs.cgi?root=lazarusrev=12809view=rev
 
 You can study it and see which places were altered. Would would need
 to do something similar.
 
 Where is ParentWindow declared? TCustomForm?
 
  I already tried it once, but I had to recompile the LCL quite often
  and I probably lost patience
 
 You will have to rebuild lcl sometimes to do this, and also to test
 and fix if it's wrong.

I think ParentWindow is very widgetset specific (see below). Probably
it will work cross platform very limited. See at end for an
alternative solution.

- AFAIK under winapi you can stack handles even of different processes.
gtk does not allow this. I don't know about qt, carbon, fpgui, but
probably they all have some limitations of child/parent relationships.

- the LCL handles messages and delegates them downwards and upwards to
parents/childs TControls. But if the Handle has no associated
TWinControl then messages can not be passed this way. Only the
widgetset knows how to handle this. You must check every place where a
handle is used if it is a normal LCL handle or a foreign handle. This
will be a lot of work.

Solution:
It is probably easier to create a wrapper TWinControl / TCustomForm
with the ability to use the foreign Handle.


Mattias
 

_
 To unsubscribe: mail [EMAIL PROTECTED] with
unsubscribe as the Subject
   archives at http://www.lazarus.freepascal.org/mailarchives


Re: [lazarus] ParentWindow

2007-11-10 Thread Al Boldi
Mattias Gaertner wrote:
 I think ParentWindow is very widgetset specific (see below). Probably
 it will work cross platform very limited. See at end for an
 alternative solution.

 - AFAIK under winapi you can stack handles even of different processes.
 gtk does not allow this. I don't know about qt, carbon, fpgui, but
 probably they all have some limitations of child/parent relationships.

Actually the gtk does support this, but in a really hacky way, using 
GTKSocket/GTKPlug.

 - the LCL handles messages and delegates them downwards and upwards to
 parents/childs TControls. But if the Handle has no associated
 TWinControl then messages can not be passed this way. Only the
 widgetset knows how to handle this. You must check every place where a
 handle is used if it is a normal LCL handle or a foreign handle. This
 will be a lot of work.

 Solution:
 It is probably easier to create a wrapper TWinControl / TCustomForm
 with the ability to use the foreign Handle.

Correct; all that is needed is a SetParent(hWnd) method.


Thanks!

--
Al

_
 To unsubscribe: mail [EMAIL PROTECTED] with
unsubscribe as the Subject
   archives at http://www.lazarus.freepascal.org/mailarchives


Re: [lazarus] ParentWindow

2007-11-10 Thread Christian Budde
Ok, just for the records: I tried to do it with 
TWinForm.CreateParented(ParentWindow: hwnd), but I get an access 
violation. So that does not work.

I think ParentWindow is very widgetset specific (see below). Probably
it will work cross platform very limited.
  
Ok, thanks for the information. I'm willing to find a cross platform 
solution, so I don't necessary need to go that ParentWindow road.

Solution:
It is probably easier to create a wrapper TWinControl / TCustomForm
with the ability to use the foreign Handle.
  

I just had a look at the wincontrol.inc and I already found this:

{--
 TWinControl CreateParentedControl
--}
class function TWinControl.CreateParentedControl(ParentWindow: hwnd): 
TWinControl;

begin
 // ToDo
 Result:=nil;
end;

Is this what you thought of? I mean it's still pretty ToDo, but I 
guess the structure is already there. Now all I need to do is fill it 
with live. Any ideas?


   Christian

_
To unsubscribe: mail [EMAIL PROTECTED] with
   unsubscribe as the Subject
  archives at http://www.lazarus.freepascal.org/mailarchives


Re: [lazarus] ParentWindow

2007-11-10 Thread Mattias Gaertner
On Sat, 10 Nov 2007 15:55:38 +0300
Al Boldi [EMAIL PROTECTED] wrote:

 Mattias Gaertner wrote:
  I think ParentWindow is very widgetset specific (see below).
  Probably it will work cross platform very limited. See at end for an
  alternative solution.
 
  - AFAIK under winapi you can stack handles even of different
  processes. gtk does not allow this. I don't know about qt, carbon,
  fpgui, but probably they all have some limitations of child/parent
  relationships.
 
 Actually the gtk does support this, but in a really hacky way, using 
 GTKSocket/GTKPlug.

I see. So, you need special handles under gtk, while winapi allows
nearly any window handle. Then I guess, ParentWindow will be far too
complicated to implement cross platform in a generic way.


 
  - the LCL handles messages and delegates them downwards and upwards
  to parents/childs TControls. But if the Handle has no associated
  TWinControl then messages can not be passed this way. Only the
  widgetset knows how to handle this. You must check every place
  where a handle is used if it is a normal LCL handle or a foreign
  handle. This will be a lot of work.
 
  Solution:
  It is probably easier to create a wrapper TWinControl / TCustomForm
  with the ability to use the foreign Handle.
 
 Correct; all that is needed is a SetParent(hWnd) method.

Huh?
Maybe my statement was not clear: The Parent/Child connection is the
main problem. It would be easier to handle the child/parent
relationship by the LCL and keep the 1:1 mapping between controls and
handles.
So, all that is needed is a TForeignHandleControl with a SetHandle
method.


Mattias

_
 To unsubscribe: mail [EMAIL PROTECTED] with
unsubscribe as the Subject
   archives at http://www.lazarus.freepascal.org/mailarchives


Re: [lazarus] ParentWindow

2007-11-10 Thread Christian Budde
Right now I have made it very simple and as expected it doesn't work. I 
implemented it as:


{--
 TWinControl CreateParentedControl
--}
class function TWinControl.CreateParentedControl(ParentWindow: hwnd): 
TWinControl;

begin
 Result := TWinControl.CreateParented(ParentWindow);
end;

I guess I have to dig a bit deeper into the OS-APIs to see how the 
handle stuff works. For Windows I can probably use the 
Windows.SetParent(...), but I'm not sure.


Any hints? Do I really need to implement a new TForeignHandleControl class?

Kind regards,

   Christian

_
To unsubscribe: mail [EMAIL PROTECTED] with
   unsubscribe as the Subject
  archives at http://www.lazarus.freepascal.org/mailarchives


Re: [lazarus] ParentWindow

2007-11-10 Thread Mattias Gaertner
On Sat, 10 Nov 2007 14:41:18 +0100
Christian Budde [EMAIL PROTECTED] wrote:

 Right now I have made it very simple and as expected it doesn't work.
 I implemented it as:
 
 {--
   TWinControl CreateParentedControl
 --}
 class function TWinControl.CreateParentedControl(ParentWindow: hwnd): 
 TWinControl;
 begin
   Result := TWinControl.CreateParented(ParentWindow);
 end;
 
 I guess I have to dig a bit deeper into the OS-APIs to see how the 
 handle stuff works. For Windows I can probably use the 
 Windows.SetParent(...), but I'm not sure.
 
 Any hints? Do I really need to implement a new TForeignHandleControl
 class?

If you only need a reparented control, that will not get focus,
get incorrect mouse and keyboard events and will likely crash, then it
is easier to implement only CreateParented. ;)
That's because the biggest part of the LCL and the LCL interfaces
expects LCL controls.


Mattias

_
 To unsubscribe: mail [EMAIL PROTECTED] with
unsubscribe as the Subject
   archives at http://www.lazarus.freepascal.org/mailarchives


Re: [lazarus] ParentWindow

2007-11-10 Thread Christian Budde

Hello Mattias,

If you only need a reparented control, that will not get focus,
get incorrect mouse and keyboard events and will likely crash, then it
is easier to implement only CreateParented. ;)
  
I not sure if I understand correctly what you meant with this. For sure 
I don't want it to crash and I want something that gets the focus, but 
I'm nearly a complete newbie here and thus I need some constructive help.


So what is the best way to accomplish my goal?

As far as I understood everything you wrote before, I do need to write a 
descendant of TWinControl, that behalves like a normal LCL control (gets 
the focus and other events) but also has the ability to reparent another 
control only given by a handle.


In the original SDK the handle reads something like this:

void * systemWindow 
   platform-dependent parent window (HWND or WindowRef)


so it seems as if this isn't very platform-independent in the original 
spec. I wonder how they do it on OSX and Linux (which are both supported 
platforms)...


Thanks for the help so far,

   Christian

_
To unsubscribe: mail [EMAIL PROTECTED] with
   unsubscribe as the Subject
  archives at http://www.lazarus.freepascal.org/mailarchives


Re: [lazarus] ParentWindow

2007-11-10 Thread Al Boldi
Mattias Gaertner wrote:
 Maybe my statement was not clear: The Parent/Child connection is the
 main problem. It would be easier to handle the child/parent
 relationship by the LCL and keep the 1:1 mapping between controls and
 handles.
 So, all that is needed is a TForeignHandleControl with a SetHandle
 method.

Still not clear what you mean.  Maybe like this:
TForeignHandleControl(x).SetHandle:=hWnd;
then: form1.parent:=TForeignHandleControl(x).SetHandle;
or  : TForeignHandleControl(x).Setparent:=form1.hWnd;


Thanks!

--
Al

_
 To unsubscribe: mail [EMAIL PROTECTED] with
unsubscribe as the Subject
   archives at http://www.lazarus.freepascal.org/mailarchives


Re: [lazarus] ParentWindow

2007-11-10 Thread Marc Weustink

Christian Budde wrote:
Ok, just for the records: I tried to do it with 
TWinForm.CreateParented(ParentWindow: hwnd), but I get an access 
violation. So that does not work.

I think ParentWindow is very widgetset specific (see below). Probably
it will work cross platform very limited.
  
Ok, thanks for the information. I'm willing to find a cross platform 
solution, so I don't necessary need to go that ParentWindow road.

Solution:
It is probably easier to create a wrapper TWinControl / TCustomForm
with the ability to use the foreign Handle.
  

I just had a look at the wincontrol.inc and I already found this:

{-- 


 TWinControl CreateParentedControl
--} 

class function TWinControl.CreateParentedControl(ParentWindow: hwnd): 
TWinControl;

begin
 // ToDo
 Result:=nil;
end;

Is this what you thought of? I mean it's still pretty ToDo, but I 
guess the structure is already there. Now all I need to do is fill it 
with live. Any ideas?


The main reason it exists is delphi compatebility. Using this function 
instead of using windows.SetParent has the advantage that the VCL/LCL 
knows that the parent is not a VCL/LCL control so it can do special things.


I think on win32 for sure and on X or OSX it is doable. However I think 
it will take loads of time to debug the LCL prevent it to assume that a 
parent always is a LCL control. And the result will always have less 
functionality that when it has a real LCL parent. Even in delphi this is 
the case.
So it is a lot of effort for something with limited functionality and 
limited use. I rather spend my time on other things.


Marc





   Christian

_
To unsubscribe: mail [EMAIL PROTECTED] with
   unsubscribe as the Subject
  archives at http://www.lazarus.freepascal.org/mailarchives



_
To unsubscribe: mail [EMAIL PROTECTED] with
   unsubscribe as the Subject
  archives at http://www.lazarus.freepascal.org/mailarchives


Re: [lazarus] ParentWindow

2007-11-09 Thread Christian Budde

Hello,

I once asked here, if someone knows any replacement for the Delphi function:

   MyForm.ParentWindow := HWnd(AnotherForm.Handle);

I need this to make a form stored in a DLL is move into another form 
(called MyForm here). I tried


   Parent := FindControl(AnotherForm.Handle)

but I guess since both forms are not in the same project it won't find 
that handle and thus return nil.


There is a FParentWindow located in TWinControl, but there is nothing 
like ParentWindow. Is there any reason for it or was it simply never 
necessary and thus never implemented? Any hints welcome!


Thanks in advance,

   Christian



Christian Budde wrote:

Hi again,

I'm now missing a procedure to 'host' a form in a different window 
given only by a handle. In Delphi it's as simple as


MyForm.ParentWindow := HWnd(Handle);

It directly uses Windows.SetParent(FHandle, Value); from the WinAPI. 
At the moment I'm still on Windows, but I'd like to find a 
multi-platform solution.


There is a FParentWindow located in TWinControl, but there is nothing 
like ParentWindow. Is there any reason for it or was it simply never 
necessary and thus never implemented? Any hints welcome!


Thanks in advance,

Christian




[lazarus] ParentWindow

2007-08-03 Thread Christian Budde

Hi again,

I'm now missing a procedure to 'host' a form in a different window given 
only by a handle. In Delphi it's as simple as


MyForm.ParentWindow := HWnd(Handle);

It directly uses Windows.SetParent(FHandle, Value); from the WinAPI. At 
the moment I'm still on Windows, but I'd like to find a multi-platform 
solution.


There is a FParentWindow located in TWinControl, but there is nothing 
like ParentWindow. Is there any reason for it or was it simply never 
necessary and thus never implemented? Any hints welcome!


Thanks in advance,

   Christian