Problem updating Legacy Declare

Per the LangRef … WindowPtr has been deprecated… and it says to use Window.Handle

Declare Sub SetAutorecalculatesContentBorder Lib "AppKit" Selector "setAutorecalculatesContentBorderThickness:forEdge:" (inWindow As WindowPtr, inRecalculates As Boolean, inEdge As UInt32)
Declare Sub SetContentBorderThickness Lib "AppKit" Selector "setContentBorderThickness:forEdge:" (inWindow As WindowPtr, inBorderThickness As Single, inEdge As UInt32)
Declare Sub ContentBorderThickness Lib "AppKit" Selector "ContentBorderThicknessForEdge:" (inWindow As Window.Handle, inBorderThickness As Single, inEdge As UInt32)

but I get an error on the last line (I just changed one as a test)

[quote]This is no class with this name[/quote] “.handle” is highlighted

You should be able to use Ptr there and then pass window.handle as the parameter when you call the method.

uh… nope

Protected Sub SetRoundWindowTopBottom(w As window, topHeight As Integer, botHeight As Integer)
  #If TargetMacOS Then
    #If TargetCocoa
      Const NSBackingStoreType = 2
      Const NSMaxYEdge = 3
      Const NSMinYEdge = 1
      Const NSTexturedBackgroundWindowMask = 256
      Const NSTitledWindowMask = 1
      Const NSResizabkeWindowMask = 8
      Const NSMiniaturizableWindowMask = 4
      Const NSClosableWindowMask = 2
      Const NSResizableWindowMask=8
      
      w.Frame=9
      
      Declare Sub setBackingType Lib "Cocoa" selector "setBackingType:" ( ObjID As Integer, bufferingType As Integer)
      Declare Sub setStyleMask Lib "Cocoa" selector "setStyleMask:" (obj_id As Integer, mask As Integer)
      Declare Function styleMask Lib "Cocoa.framework" selector "styleMask" (id As Integer) As Integer 
      Declare Sub SetAutorecalculatesContentBorder Lib "AppKit" Selector "setAutorecalculatesContentBorderThickness:forEdge:" (inWindow As Ptr, inRecalculates As Boolean, inEdge As UInt32)
      Declare Sub SetContentBorderThickness Lib "AppKit" Selector "setContentBorderThickness:forEdge:" (inWindow As Ptr, inBorderThickness As Single, inEdge As UInt32)
      Declare Sub ContentBorderThickness Lib "AppKit" Selector "ContentBorderThicknessForEdge:" (inWindow As Ptr, inBorderThickness As Single, inEdge As UInt32)
      
      //Soft Declare Sub setMovableByWindowBackground Lib "Cocoa" selector "setMovableByWindowBackground:" (windowRef As Integer, yesNo As Boolean)
      '
      '
      '
      setBackingType w.Handle, NSBackingStoreType
      setStyleMask w.Handle, styleMask(w.Handle) Or NSTexturedBackgroundWindowMask
     
      SetAutorecalculatesContentBorder(w.handle,False,NSMinYEdge)
      SetAutorecalculatesContentBorder(w.handle,False,NSMaxYEdge)
      
      If topHeight>0 Then SetContentBorderThickness(w.handle,topHeight,NSMaxYEdge) '<----set the height top]
      If botHeight>0 Then SetContentBorderThickness(w.handle,botHeight,NSMinYEdge) '<----set the height bottom
   
      w.Frame=0
      
    #EndIf
  #EndIf
  
End Sub

And I take it that Integer doesn’t work either?

Integer does work… so (rhetorical), why wasn’t it written that way to begin with (I acquired that code).
Also, since Integer is aliased to Int32 and Int64 depending on compiler settings… I really should use Int32 explictily… right?

I would look at the docs for the declared method and see what it wants, but in a 64-bit system, the handle may be able to be that big.

Problem I see with your declares is you are mixing integer and ptr which makes it hard to debug.
I would advise you to restrict to one data type for the handle – either Integer or Ptr. Apple uses Ptr throughout all their frameworks, Xojo uses Integer on Desktop.
In the case you posted: Either make the declare

"Declare Sub SetContentBorderThickness Lib "AppKit" Selector "setContentBorderThickness:forEdge:" (inWindow As *Integer*, inBorderThickness As *CGFloat*, inEdge As *Integer*))

or call it with

If topHeight>0 Then SetContentBorderThickness(*ptr*(w.handle),topHeight,NSMaxYEdge) '<----set the height top]

and the like.

Just back from a christmas dinner with a good friend of ours and more than late to get to bed. In that sense: Peaceful days to all of you.
EDIT: checked NSRectEdge and it seems to be a normal integer, not Int32.

I did not write these declares, I have no idea what they “require”…

WindowPtr was there originially, and worked fine, but is deprecated now.
PTR does not work

Ulrich… .what is a “normal integer”? Today if you specify INTEGER, you get 32bit or 64bit integer depending on platform and compile settings. The same as the new (to Xojo) CGFloat is 32bit or 64bit

Like Greg wrote: Check Apple‘s docs: https://developer.apple.com/reference/appkit/nswindow/1419541-setcontentborderthickness?language=objc
It says

[quote]- (void)setContentBorderThickness:(CGFloat)thickness
forEdge:(NSRectEdge)edge;[/quote] (in ObjC language)
The minus at the start meaning it’s an instance methode, that’s why you need to pass the window handle.

In Xojo Window.Handle is an Integer (4 Bytes on a 32 Bit system, 8 Bytes on a 64 Bit sytem) which maps exactly to what a “normal” Integer does. So no need to use (U)Int32 or (U)Int64.
While window.handle is an Integer, Apple uses Ptrs for the handle. Which behave exactly like Integer and can be interchanged with them - they take 4 Bytes on a 32 Bit system and 8 Bytes on a 64 Bit system too.

To make the declare compatible, you either have to declare the instance as an Integer (and can then pass Window.handle), or you can take Apple’s scheme (which makes it easier to use your declares on iOS too in the cases where they are the same), but then you have to convert Window.handle to a Ptr which can be done with typecasting: Ptr(Window.handle).

In every case where it is not noted differently, enumerations in Apple’s system use Integer too. That’s why NSRectEdge should be a “normal” Integer too (not Int32 or Int64).

Try this (all Integers):

[code]Protected Sub SetRoundWindowTopBottom(w As window, topHeight As Integer, botHeight As Integer)
#If TargetMacOS Then
#If TargetCocoa // Do you really want to check for Carbon? I think it’s unnecessary today.
Const NSBackingStoreType = 2
Const NSMaxYEdge = 3
Const NSMinYEdge = 1
Const NSTexturedBackgroundWindowMask = 256
Const NSTitledWindowMask = 1
Const NSResizabkeWindowMask = 8
Const NSMiniaturizableWindowMask = 4
Const NSClosableWindowMask = 2
Const NSResizableWindowMask=8

  w.Frame=9
  
  Declare Sub setBackingType Lib "Cocoa" selector "setBackingType:" ( ObjID As Integer, bufferingType As Integer)
  Declare Sub setStyleMask Lib "Cocoa" seleactor "setStyleMask:" (obj_id As Integer, mask As Integer)
  Declare Function styleMask Lib "Cocoa.framework" selector "styleMask" (id As Integer) As Integer 
  Declare Sub SetAutorecalculatesContentBorder Lib "AppKit" Selector "setAutorecalculatesContentBorderThickness:forEdge:" (inWindow As Integer, inRecalculates As Boolean, inEdge As Integer)
  Declare Sub SetContentBorderThickness Lib "AppKit" Selector "setContentBorderThickness:forEdge:" (inWindow As Integer, inBorderThickness As CGFloat, inEdge As Integer)
  Declare Sub ContentBorderThickness Lib "AppKit" Selector "ContentBorderThicknessForEdge:" (inWindow As Integer, inBorderThickness As CGFloat, inEdge As Integer)
  
  //Soft Declare Sub setMovableByWindowBackground Lib "Cocoa" selector "setMovableByWindowBackground:" (windowRef As Integer, yesNo As Boolean)
  '
  '
  '
  setBackingType w.Handle, NSBackingStoreType
  setStyleMask w.Handle, styleMask(w.Handle) Or NSTexturedBackgroundWindowMask
 
  SetAutorecalculatesContentBorder(w.handle,False,NSMinYEdge)
  SetAutorecalculatesContentBorder(w.handle,False,NSMaxYEdge)
  
  If topHeight>0 Then SetContentBorderThickness(w.handle,topHeight,NSMaxYEdge) '<----set the height top]
  If botHeight>0 Then SetContentBorderThickness(w.handle,botHeight,NSMinYEdge) '<----set the height bottom

  w.Frame=0
  
#EndIf

#EndIf

End Sub[/code]