When Does a Window Have an Attached Sheet?

· Jul 27, 07:46 AM

A blog post by Norman Palardy describes a workaround for a REALbasic bug in which Mac OS windows with attached sheets are closed when they should not be. The crux of the workaround is to decide when a window has an open sheet attached. Here is a function that allows you to answer that question without subclassing.

Function HasSheet(extends w as Window) As Boolean
  #if targetMacOS
    dim theAnswer as Boolean = false
     
    for i as Integer = 0 to WindowCount -1
      dim s as Window = Window(i)
      if s is nil then
        continue
      end if
       
      if not (s.Frame = Window.FrameTypeSheet) then
        continue
      end if
       
      soft declare function GetSheetWindowParent lib "Carbon.framework" (inSheet as WindowPtr, ByRef outParentWindow as Integer) as Integer
       
      dim parentHandle as Integer
      dim OSError as Integer = GetSheetWindowParent(s, parentHandle)
      if parentHandle = w.Handle then
        theAnswer = true
        exit
      end if
    next
    return theAnswer
     
  #else
    return false
  #endif
End Function
---

Comment

  1. This is also handy if you are using sheet windows in a multi-window environment and you want to update the contents of the sheet throughout a number of background processes without closing and reopening the sheet.

    You can check to see if the sheet is already assigned to the proper parent window and then only update the contents.

    Tim · Apr 26, 04:20 PM · #

Commenting is closed for this article.