// RotateBook // a patch to Copperfield (the internal NewtonBook viewer) to automatically // rotate the screen knownGlobalFunctions.GetOrientation := 0; knownGlobalFunctions.SetScreenOrientation := 1; InstallScript := func(partFrame, removeFrame) begin //try GetRoot().copperfield._proto := { _proto: GetRoot().copperfield._proto, BuildDisplayParams: func() begin local pgsize; // check the current screen dimensions vs. the size of the book // I guess for sanity's sake we should also check if there is no way // the book will fit in the screen - check for 120/130 vs. 2000 vs. eMate pgsize := :PageSize(nil); if pgsize.width > displayparams.appAreaWidth or pgsize.height > displayparams.appAreaHeight then begin // we need to change the screen orientation // note that we always set to a sane orientation for all // platforms. This should really all be replaced with // checks for machine types etc. // yes, I know that SetScreenOrientation() only works for 2.1. local int theorientation, neworientation; local sysinfo; sysinfo := Gestalt(kGestalt_SystemInfo); GetRoot():LockScreen(true); theorientation := GetOrientation(); // the Gestalt docs say that this is improper, but somehow I don't think Apple // is going to change the values anytime soon... if BeginsWith(sysinfo.ROMVersionString, "2.0") then begin // only do valid orientations for 2.0 machines if theorientation = 0 or theorientation = 2 then neworientation := 3; else if theorientation = 1 or theorientation = 3 then neworientation := 0; end; if BeginsWith(sysinfo.ROMVersionString, "2.1") then begin if theorientation = 0 or theorientation = 2 then neworientation := 1; if theorientation = 1 or theorientation = 3 then neworientation := 2; end; SetScreenOrientation(neworientation); GetRoot():LockScreen(nil); end; // the rest of this code is the ROM/patched version of the function - sets up the book form etc. local thedisplayparams, thepagesize, isbnentry, modheight; thedisplayparams := displayParams; thepagesize := :PageSize(nil); thepagesize.width := min(thepagesize.width, thedisplayparams.appAreaWidth); thepagesize.height := min(thepagesize.height, thedisplayparams.appAreaHeight); isbnentry := :GetLibraryEntry(isbn); modheight := thepagesize.height + 18; self.dpCu := {}; if pagesShowing <> 1 then (pagesShowing := 1); if thedisplayparams.appAreaWidth >= thepagesize.width * 2 + 15 and thedisplayparams.appAreaHeight >= thepagesize.height then (if band(isbnentry.flags, 2) = 0 then (pagesShowing := 2)); dpCu.fullBar := true; if thedisplayparams.appAreaHeight < modheight then begin dpCu.fullBar := nil; modheight := thedisplayparams.appAreaHeight; end; if thedisplayparams.appAreaWidth >= thepagesize.width and thedisplayparams.appAreaHeight >= modheight then begin dpCu.left := (thedisplayparams.appAreaWidth - thepagesize.width - 6) div 2; if dpCu.fullBar = nil then (dpCu.top := 0); else begin dpCu.top := thedisplayparams.appAreaHeight - thepagesize.height - 18 - 6 - 4; dpCu.top := max(0, dpCu.top); dpCu.top := dpCu.top div 2; end; if pagesShowing = 2 then begin dpCu.left := self.dpCu.left - thepagesize.width - 15 - 6; dpCu.width := thepagesize.width * 2 + 15; end; else (dpCu.width := thepagesize.width); dpCu.height := modheight; if thedisplayparams.appAreaHeight = modheight and thedisplayparams.appAreaWidth = thepagesize.width then (self.floating := nil); else (if thedisplayparams.appAreaHeight = modheight or thedisplayparams.appAreaWidth = thepagesize.width then (self.floating := 'Partial); else (self.floating := true)); end; else begin dpCu.left := 0; if thedisplayparams.fullBar = nil then (dpCu.top := 0); else (dpCu.top := thedisplayparams.appAreaHeight - thepagesize.height - 18); self.floating := nil; dpCu.width := thepagesize.width; dpCu.height := modheight; end; if dpCu.left < 0 then (dpCu.left := (displayParams.appAreaWidth - dpCu.width) div 2); end } //onexception |evt.ex| do nil; end; // restore the systempatched BuildDisplayParams function RemoveScript := func(removeFrame) begin GetRoot().copperfield._proto := { _proto: GetRoot().copperfield._proto, BuildDisplayParams: func() begin inherited:BuildDisplayParams(); local Local1; if dpCu.left < 0 then (dpCu.left := (displayParams.appAreaWidth - dpCu.width) div 2); Local1 := :PageSize(nil); if Local1.width > displayParams.appAreaWidth or Local1.height > displayParams.appAreaHeight then begin GetRoot():Notify(3, "Book", "Book layout is larger than the screen."); AddDeferredSend(self, 'Close, nil); dpCu := {left: 0, top: 0, width: 0, height: 0} end end } end;