Page 1 of 1

SetParent for Linux and Windows

Posted: Tue Mar 27, 2012 11:32 pm
by d.j.peters
The most of you (hardcore coders) knows that a PB child window is a bit misspelled.
A real child window exist only inside the client region of it's parent.
How ever I searched the forum and found more than 50 times SetParent_ the WINDOWS API command
but nothing about Linux. (or I'm blind)

here are how you can do it with Linux too

DJ.

Code: Select all

; put child window in client region of a parent window
EnableExplicit
Procedure SetParent(Child.i, Parent.i)
  If IsWindow(Child)=0
    Child=WindowID(Child)
    If Child=#Null
      MessageRequester("error:","SetParent() wrong child param !"):End
    EndIf
  EndIf
  If IsWindow(Parent)=0
    Parent=WindowID(Parent)
    If Parent=#Null
      MessageRequester("error:","SetParent() wrong parent param !"):End
    EndIf 
  EndIf
   
 
  CompilerSelect #PB_Compiler_OS
     
    CompilerCase #PB_OS_Windows
      SetParent_(Child,Parent)
     
    CompilerCase #PB_OS_Linux
      Protected *childWidget.GtkWidget  = Child
      Protected *parentWidget.GtkWidget = Parent
      gdk_window_reparent_(*childWidget\Window, *parentWidget\Window, 0, 0)
     
    CompilerCase #PB_OS_MacOS
      Debug "No solution for MacOS yet !"
     
  CompilerEndSelect
 
EndProcedure
Now i can mix PB gadgets with an OpenGL borderless child window.
Linux:
Image
Windows:
Image

Re: SetParent for Linux and Windows

Posted: Wed Mar 28, 2012 6:46 am
by idle
that's good to know thanks

Re: SetParent for Linux and Windows

Posted: Wed Mar 28, 2012 1:05 pm
by Guimauve
@d.j.peters

For multi-platform code it's more safe to write the code like this :

Code: Select all

Procedure SetParent(Child.i, Parent.i)
  
  CompilerSelect #PB_Compiler_OS
      
    CompilerCase #PB_OS_Windows 
      SetParent_(WindowID(child), WindowID(parent))
      
    CompilerCase #PB_OS_Linux
      Protected *childWidget.GtkWidget = WindowID(child)
      Protected *parentWidget.GtkWidget = WindowID(parent)
      gdk_window_reparent_(*childWidget\Window, *parentWidget\Window, 0, 0)
      
    CompilerCase #PB_OS_MacOS
      Debug "No solution for MacOS yet !"
      
  CompilerEndSelect
  
EndProcedure
But this just my opinion. Otherwise, nice job !

Best regards.
Guimauve

Re: SetParent for Linux and Windows

Posted: Wed Mar 28, 2012 2:35 pm
by ts-soft
and for multiprocessor, it is better to use integer for handles :wink:

nice work!

Re: SetParent for Linux and Windows

Posted: Thu Mar 29, 2012 12:55 am
by d.j.peters
ts-soft wrote:and for multiprocessor, it is better to use integer for handles
The result of XXXId() are handles and can be pointers * or integers
but in my "pseudo code" the params #child and #parent are only numbers
and the range of 32 bit numbers are more than you will ever use in any PB application.

Or do you mean enum's are 32 bit on x86 and 64 bit on a 64 bit OS ?

DJ.

Re: SetParent for Linux and Windows

Posted: Thu Mar 29, 2012 8:33 am
by HeX0R
d.j.peters wrote:The result of XXXId() are handles and can be pointers * or integers
but in my "pseudo code" the params #child and #parent are only numbers
and the range of 32 bit numbers are more than you will ever use in any PB application.
Remember:
If you use #PB_Any to create Windows/whatever, the result will be an address.

Re: SetParent for Linux and Windows

Posted: Thu Mar 29, 2012 1:17 pm
by d.j.peters
Should be more safe now.
(see at first post)

DJ.

Re: SetParent for Linux and Windows

Posted: Thu Mar 29, 2012 5:55 pm
by ts-soft
Thanks, for changing to .i, but the check is not required,
only the programmer sets the parameter!
The MessageRequester is not good, what should the user of your program
do, after this request :mrgreen: .
If you check anything, only add a Debug-Output!

Greetings - Thomas