Wednesday, April 24, 2013

Fullscreen on Snow Leopard

On previous OSX versions it was of course already possible and quite easy to make a fullscreen application with RealBasic. Toggle the fullscreen property of the Window, this will make the window cover the whole screen.

Two small niggles still remained: the grow-icon and a menubar hiding glitch.

If the application window is re-sizable when not in fullscreen, the 'grow icon' is still visible when the window is fullscreen. Grabbing this also allows the window to be resized when 'officially' in fullscreen mode. One way to solve this is to maintain two Window objects, one for windowed and one non-sizable for the fullscreen view. Another, easier solution is to use the SetWindowGrowTab function from the excellent collection of CarbonDeclares. (Yes, with Cocoa these will be obsolete ultimately, but now still useful.)

When toggling the fullscreen mode, call:
   SetWindowGrowTab( MyWindow,  Not MyWindow.FullScreen)

The function itself from CarbonDeclares:
Sub SetWindowGrowTab(w as window, b as boolean)
  // Added 11/13/2001 by Jarvis Badgley
  // Renamed 11/16/2001 by Jarvis Badgley from DisableWindowMinimizeWidget
  
  const attrib = 16

  dim err as integer
  #if TargetCarbon then
    Declare Function ChangeWindowAttributes Lib "Carbon" (window as WindowPtr, setTheseAttributes as Integer, clearTheseAttributes as Integer) as Integer
    
    if b then
      err = ChangeWindowAttributes(w, attrib, 0)
    else
      err = ChangeWindowAttributes(w, 0, attrib)
    end
    
  #endif // TargetCarbon
End Sub



The second niggle is that after the user selects a menu item by pressing the shortcut key (e.g. Cmd-O) , the menubar comes out of hiding and does not go back. The simple hack to work around this is to toggle the MenuBarVisible state. Call this hack at the end of every menu handler.


  If MyWindow.FullScreen Then
    MyWindow.MenuBarVisible = True //brings state in sync with OS again, otherwise the hide won't trigger
    MyWindow.MenuBarVisible = Not MyWindow.FullScreen
  End if
 

There are likely other or better ways to avoid these small niggles, but these worked. These allow the application to have a 'clean' fullscreen option for it's window also on older versions of OSX.


No comments:

Post a Comment