SetParent for Linux and Windows

Share your advanced PureBasic knowledge/code with the community.
d.j.peters
User
User
Posts: 10
Joined: Sat Dec 10, 2011 7:53 pm

SetParent for Linux and Windows

Post 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
Last edited by d.j.peters on Thu Mar 29, 2012 1:11 pm, edited 1 time in total.
User avatar
idle
Always Here
Always Here
Posts: 5095
Joined: Fri Sep 21, 2007 5:52 am
Location: New Zealand

Re: SetParent for Linux and Windows

Post by idle »

that's good to know thanks
Windows 11, Manjaro, Raspberry Pi OS
Image
User avatar
Guimauve
Enthusiast
Enthusiast
Posts: 742
Joined: Wed Oct 22, 2003 2:51 am
Location: Canada

Re: SetParent for Linux and Windows

Post 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
Last edited by Guimauve on Wed Mar 28, 2012 5:29 pm, edited 1 time in total.
User avatar
ts-soft
Always Here
Always Here
Posts: 5756
Joined: Thu Jun 24, 2004 2:44 pm
Location: Berlin - Germany

Re: SetParent for Linux and Windows

Post by ts-soft »

and for multiprocessor, it is better to use integer for handles :wink:

nice work!
PureBasic 5.73 | SpiderBasic 2.30 | Windows 10 Pro (x64) | Linux Mint 20.1 (x64)
Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.
Image
d.j.peters
User
User
Posts: 10
Joined: Sat Dec 10, 2011 7:53 pm

Re: SetParent for Linux and Windows

Post 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.
User avatar
HeX0R
Addict
Addict
Posts: 992
Joined: Mon Sep 20, 2004 7:12 am
Location: Hell

Re: SetParent for Linux and Windows

Post 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.
d.j.peters
User
User
Posts: 10
Joined: Sat Dec 10, 2011 7:53 pm

Re: SetParent for Linux and Windows

Post by d.j.peters »

Should be more safe now.
(see at first post)

DJ.
User avatar
ts-soft
Always Here
Always Here
Posts: 5756
Joined: Thu Jun 24, 2004 2:44 pm
Location: Berlin - Germany

Re: SetParent for Linux and Windows

Post 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
PureBasic 5.73 | SpiderBasic 2.30 | Windows 10 Pro (x64) | Linux Mint 20.1 (x64)
Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.
Image
Post Reply