Set Minimum and Maximum Sizes for an Application

Maximum Size

Create a text file (named "constants") which defines maximum sizes:

constant kMaxWidth := 300;
constant kMaxHeight := 300;
So that we can support screen rotation, add a ReOrientToScreen slot to the protoApp with the value:

ROM_DefRotateFunc
Make the protoApp take up the full screen by setting the viewJustify to parent full horizontally and vertically and all the slots of viewBounds to 0.

Add a viewSetupFormScript to the protoApp:

func()
begin
   inherited:?viewSetupFormScript();

   local size := :LocalBox();
   
   if size.bottom > kMaxHeight or 
      size.right > kMaxWidth then begin

      // figure amount too wide or tall
      local extraWidth := Max(0, 
         size.right - kMaxWidth);
      local extraHeight := Max(0, 
         size.bottom - kMaxHeight);
      
      // adjust viewBounds to make narrower 
      // and/or shorter
      self.viewBounds := Clone(viewBounds);
      viewBounds.left := viewBounds.left +
         extraWidth div 2;
      viewBounds.right := viewBounds.right -
         extraWidth div 2;
      viewBounds.top := viewBounds.top +
         extraHeight div 2;
      viewBounds.bottom := viewBounds.bottom -
         extraHeight div 2;
   end;
end
This correctly modifies the viewBounds. However, when the application quits, the modified viewBounds remains in the view. If the screen rotates, this modified viewBounds is used instead of the original viewBounds in the template. The solution is to remove the viewBounds slot from the view when the application closes. Add a viewQuitScript to the protoApp:

func()
begin
   RemoveSlot(self, 'viewBounds);

   inherited:?viewQuitScript();
end
Note that it is OK to call RemoveSlot with a non-existent slot (as would be the case if we hadn't maxed out). That's important because in some cases the view will contain a viewBounds slot, and in some cases it won't.


An online version of Programming for the Newton using Macintosh, 2nd ed. ©1996, 1994, Julie McKeehan and Neil Rhodes.

Last modified: 1 DEC 1996