// Copyright © 1993, 1994 Apple Computer, Inc. All rights reserved. /* project data for PreeferMadness */ // application constants constant kAppSymbol := '|Preefer:PIEDTS|; constant kAppString := "Preefer:PIEDTS"; constant kPackageName := kAppString; constant kAppName := "Preefer Madness" ; constant kAppMaxWidth := 240 ; constant kAppMaxHeight := 336 ; // prefs constants DefConst('kPrefsFrame, {tag: kAppString, version: 1, startWithSound: nil, onePrefOnly: true, philospherIndex: 0, }); // philisophical constants DefConst('kPhilPicker, ["None", 'pickSeparator, "Plato", "Aristotle", "Descartes", "Mill", "Tsunemoto", "Nietzsche", "Marx", "Wittgenstien", "Heidegger", "Russell", "Popper", "Dr. Llama"]) ; InstallScript := func(partFrame) begin /* AUTO PART: if you have an auto part that requires preferences you would add them to the system preferences roll. This bit of code shows you how... //install preferences template in preferences global partFrame.prefsTemplate := Clone(partFrame.theForm.PT_PreeferAutoPrefsItem); AddArraySlot(Preferences,partFrame.prefsTemplate); //if Prefs is open - force update to show our entry if GetRoot().preferenceRoll.viewCObject then GetRoot().preferenceRoll:RedoChildren(); */ //install formula template in formulaList global partFrame.formulaTemplate := Clone(partFrame.theForm.PT_PreeferFormulaItem); AddArraySlot(FormulaList,partFrame.formulaTemplate); //if Formulas is open - force update to show our entry if GetRoot().formulaRoll.viewCObject then GetRoot().formulaRoll:RedoChildren(); end; RemoveScript := func(partFrame) begin /* AUTO PART: if you have an auto part that requires preferences you would remove your preference from the system preferences roll, this bit of code shows you how... //remove preferences template from preferences global SetRemove(Preferences,partFrame.prefsTemplate); //if Prefs is open - force update to remove our entry if GetRoot().preferenceRoll.viewCObject then GetRoot().preferenceRoll:RedoChildren(); */ //remove formula template from formulaList global SetRemove(FormulaList,partFrame.formulaTemplate); //if Formulas is open - force update to remove our entry if GetRoot().formulaRoll.viewCObject then GetRoot().formulaRoll:RedoChildren(); end; // ---- End Project Data ---- // ---- File PreeferMadness.t ---- // Before Script for "MyBase" // Copyright © 1993,1994 Apple Computer, Inc. All rights reserved. MyBase := {title: "", viewBounds: {left: 0, top: 0, right: 240, bottom: 336}, viewSetupFormScript: func() begin // resize the app to the screen local l := GetAppParams() ; self.viewBounds := RelBounds(l.appAreaLeft, l.appAreaTop, MIN(kAppMaxWidth, l.appAreaWidth), MIN(kAppMaxHeight, l.appAreaHeight)); //get our preference data from the SystemSoup - create if necessary // NOTE: the preference is created in the internal store, not the // default store local sysSoup := GetStores()[0]:GetSoup(ROM_SystemSoupName); local cursor := Query(sysSoup,{type: 'index, indexPath: 'tag, startKey: kAppString, endTest: func(e) NOT StrEqual(e.tag,kAppString)}); prefsEntry := cursor:Entry(); if NOT prefsEntry then prefsEntry := sysSoup:Add(Clone(kPrefsFrame)); // update earlier prefs versions to latest if (NOT prefsEntry.version) OR (prefsEntry.version < currentPrefsVersion) then begin foreach slot, val in kPrefsFrame do if NOT prefsEntry.(slot) exists then prefsEntry.(slot) := DeepClone(val); EntryChange(prefsEntry); end; if prefsEntry.startWithSound then PlaySound(ROM_poof); end, viewQuitScript: func() begin //nil out slots to allow for GC prefsEntry := nil; end, prefsEntry: // will be the our entry from the system preferences soup // set in protoApp.viewSetupFormScript nil, viewFlags: 4, viewFormat: 328017, declareSelf: 'base, AppInfoItems: ["Prefs"], InfoItemSelected: func(item) begin // this is where you respond to the info button // see the pickActionScript in the protoInfoButton to // to see where this script is called from. // see the infoButton sample for details on protoInfoButton // open up the preferences roll PrefsView:Open(); end, currentPrefsVersion: 1, viewclass: 74, debug: "MyBase" }; _view000 := /* child of MyBase */ {viewBounds: {left: -6, top: 2, right: 74, bottom: 18}, _proto: protoTitle}; _view001 := /* child of MyBase */ {_proto: protoStatus}; // ---- File protoInfoButton ---- // Before Script for "info" // Copyright ©1994 Apple Computer, Inc., All Rights Reserved. info := {viewBounds: {left: 17, top: 0, right: 30, bottom: 12}, viewFormat: 67109457, pickCancelledScript: func() begin :Hilite(nil); end, icon: GetPictAsBits("info icon", nil), viewClickScript: func(unit) begin if :TrackHilite(unit) then begin local l := :LocalBox(); DoPopUp(AppInfoItems, l.right+3, l.top, self); end; end, viewFlags: 513, viewclass: 76, debug: "info" }; // After Script for "info" thisView := info; // set the bounds of the button so that it is to the right // of the clock and the correct height for the status bar // NOTE: this is the first button, so argument to the // ButtonBounds function MUST be negative thisView.viewBounds := ButtonBounds(-(thisView.viewBounds.right - thisView.viewBounds.left)); // ---- Back in File PreeferMadness.t ---- _view002 := /* child of _view001 */ { pickActionScript: func(index) begin // MUST do this :Hilite(nil); :InfoItemSelected(index) ; end, _proto: info }; // ---- File Preferences.t ---- // Before Script for "PrefsView" // Copyright © 1993,4 Apple Computer, Inc. All rights reserved. PrefsView := /* child of MyBase */ {rollItems: nil, viewBounds: {left: 0, top: 0, right: 0, bottom: 0}, viewJustify: 240, viewFlags: 4, viewSetupFormScript: func() begin // add the preference items to the browser if prefsEntry.onePrefOnly then begin rollItems := [PT_PreeferAppPrefs] ; // If there is only one entry, start with the roll expanded rollCollapsed := nil ; end else begin rollItems := [PT_PreeferAppPrefs, PT_PreeferPhilPref] ; // if there are multiple entries, start with it collapsed // NOTE: you could also check if all prefs would fit in one screen // and start with it expanded as well rollCollapsed := true ; end; end, _proto: protoRollBrowser, debug: "PrefsView" }; // View PrefsView is declared to MyBase // After Script for "PrefsView" thisView := PrefsView; // set the title correctly for this application thisView.title := kAppName && "Prefs"; // ---- Back in File PreeferMadness.t ---- _view003 := /* child of MyBase */ { text: "Click on the Info button and choose \"Prefs\" to set the application preferences" , viewBounds: {top: -65, left: 10, right: 154, bottom: -20}, viewJustify: 128, viewFont: ROM_fontsystem10, _proto: protoStaticText }; PhilView := /* child of MyBase */ {text: "", viewBounds: {left: 2, top: 42, right: 242, bottom: 218}, viewJustify: 0, viewFont: {family: 'NewYork, face: kFaceBold, size: 14}, viewSetupFormScript: func() begin if prefsEntry.philosopherIndex then text := philText[prefsEntry.philosopherIndex] ; else begin prefsEntry.philosopherIndex := 0 ; EntryChange(prefsEntry) ; text := ""; end; end, philText: ["","", // Plato "There is an objective ideal Llama form of which all manifistations are just shadows", // Aristotle "Every Llama can be classified into one of a finite number of sub-types of Llamas", // Rene Descartes "I think, therefore there must be Llamas", // John Stuart Mill "It is up to the free will of the individual to believe in Llamas or not", // Tsunemoto "It does not matter if Llamas exist or not, it only matters than an individual live by the way of courage", // Nietzsche "The Llama is dead!", // Marx "To each Llama according to its needs, from each according to its abilities", // Wittgenstien "It is futile to talk about Llamas because we will never agree on what the concept means", // Heidegger "There is no objective ideal Llama, each individual's concept of Llama is made up of their own experiences of and about Llamas", // Russell "With the help of mathematics we have discovered that Llamas are not valid constructs", // Popper "The question of the verification of Llamas depends upon the ability to falsify that Llamas do not exist", // Dr. Llama "I am the Llama", ], RevisePhilosophy: func() begin SetValue(self, 'text, philText[prefsEntry.philosopherIndex]) ; end, _proto: protoStaticText, debug: "PhilView" }; // View PhilView is declared to MyBase // After Script for "MyBase" thisView := MyBase; // set the title of the application: thisView.title := kAppName ; // ---- Beginning of non-used User Protos ---- // ---- File PreeferAppPrefs ---- // ---- File ProtoPrefsRollItem ---- // Before Script for "_userproto001" // Copyright © 1993,4 Apple Computer, Inc. All rights reserved. _userproto001 := {height: 42, overview: "Pref Item Overview Title", viewDrawScript: func() begin // draw the border :DrawShape(borderShape,borderStyle); end, viewFormat: 1, viewSetupDoneScript: func() begin // make the shape used to draw the border constant borderIndent := 4; constant borderDiam := 10; local bounds := :LocalBox(); borderShape := MakeRoundRect(borderIndent,borderIndent+2,bounds.right-borderIndent,bounds.bottom-1,borderDiam); // use overview string for border text unless it's explicitly specified if NOT self.text then self.text := overview; // set height to actual view height // Set the value in the template if possible - that's what the standard rollBrowser // uses (Prefs and Formulas). // This hinges on the template having been cloned into RAM. This is generally true // for other reasons. (see the InstallScript of PreeferMadness for details) // The else clause is planning for the future - possibly a specialized rollBrowser // for app specific prefs (which will hopefully require no template cloning) // NOTE: this code assumes that your viewbounds.top is 0, if not, use // the appropriate offset. if height<> bounds.bottom AND NOT IsReadOnly(self._proto) then self._proto.height := bounds.bottom else self.height := bounds.bottom; end, borderStyle: { penSize: 2, }, borderShape: // used to hold the shape object that will be // the border. // setup in protoRollItem.viewSetupDoneScript nil, _proto: protoRollItem }; _view004 := /* child of _userproto001 */ {viewFlags: 3, viewFont: ROM_fontsystem10bold, viewBounds: {left: 14, top: 1, right: 214, bottom: 16}, viewJustify: 8388608 , viewFormat: 0, viewTransferMode: 0, viewclass: 81 }; // ---- Back in File PreeferAppPrefs ---- // Before Script for "_userproto000" // Copyright © 1993,4 Apple Computer, Inc. All rights reserved. _userproto000 := {viewBounds: {left: 0, top: 0, right: 0, bottom: 96}, overview: "Application", height: 96, text: "Application", _proto: _userproto001 }; soundCheckbox := /* child of _userproto000 */ {text: "Start with sound", viewBounds: {left: 32, top: 24, right: 200, bottom: 48}, buttonValue: true, valueChanged: func() begin prefsEntry.startWithSound := viewValue; EntryChange(prefsEntry); end, viewSetupFormScript: func() begin viewValue := prefsEntry.startWithSound ; end, _proto: protoCheckbox, debug: "soundCheckbox" }; onePrefItemOnlyCheckbox := /* child of _userproto000 */ {text: "Only One Preference", viewBounds: {left: 32, top: 56, right: 200, bottom: 80}, buttonValue: true, valueChanged: func() begin prefsEntry.onePrefOnly := viewValue; EntryChange(prefsEntry); end, viewSetupFormScript: func() begin viewValue := prefsEntry.onePrefOnly ; end, _proto: protoCheckbox, debug: "onePrefItemOnlyCheckbox" }; // ---- File PreeferAutoPrefsItem ---- // Before Script for "PrefsPanelBase" // Copyright © 1993,4 Apple Computer, Inc. All rights reserved. PrefsPanelBase := {viewBounds: {left: 0, top: 0, right: 0, bottom: 128}, overview: "Preefer Prefs", text: "Preefer Prefs", viewSetupDoneScript: func() begin //get our preference data from the SystemSoup - create if necessary local sysSoup := GetStores()[0]:GetSoup(ROM_SystemSoupName); local cursor := Query(sysSoup,{type: 'index, indexPath: 'tag, startKey: kAppString, endTest: func(e) NOT StrEqual(e.tag,kAppString)}); prefsEntry := cursor:Entry(); if NOT prefsEntry then prefsEntry := sysSoup:Add({tag: kAppString, startWithSound: nil}); //init the checkbox using the preferences data if prefsEntry.startWithSound then soundCheckBox:ToggleCheck(); //IMPORTANT to call the inherited ViewSetupDoneScript in our proto inherited:?ViewSetupDoneScript(); end, prefsEntry: nil, viewQuitScript: func() begin //nil out slots to allow for GC prefsEntry := nil; end, height: 128, _proto: _userproto001, debug: "PrefsPanelBase" }; soundCheckbox := /* child of PrefsPanelBase */ {text: "Start with sound", viewBounds: {left: 16, top: 32, right: 184, bottom: 56}, buttonValue: true, valueChanged: func() begin prefsEntry.startWithSound := viewValue; EntryChange(prefsEntry); end, viewValue: nil, _proto: protoCheckbox, debug: "soundCheckbox" }; // View soundCheckbox is declared to PrefsPanelBase // ---- File PreeferFormulaItem ---- // Before Script for "_userproto002" // Copyright © 1993,4 Apple Computer, Inc. All rights reserved. _userproto002 := {viewBounds: {left: 0, top: 0, right: 0, bottom: 128}, text: "Preefer Formula Panel Title", overview: "Preefer Formula Overview Title", _proto: _userproto001 }; _view005 := /* child of _userproto002 */ {viewBounds: {left: 16, top: 32, right: 200, bottom: 56}, viewFlags: 1, text: "42", label: "Enter the answer:", entryFlags: 10753, viewSetupFormScript: func() begin // make the entry line ignore spaces inherited:?viewSetupFormScript(); entryLine.textFlags := vNoSpaces ; end, _proto: protoLabelInputLine }; // ---- File PreeferPhilPref ---- // Before Script for "_userproto003" // Copyright © 1993,4 Apple Computer, Inc. All rights reserved. _userproto003 := {viewBounds: {left: 0, top: 0, right: 0, bottom: 112}, height: 112, overview: "Philisophical Leaning", text: "Philisophical Leaning", _proto: _userproto001 }; _view006 := /* child of _userproto003 */ {viewBounds: {left: 25, top: 49, right: 159, bottom: 71}, labelCommands: , viewSetupFormScript: func() begin labelCommands := Clone(kPhilPicker) ; inherited:?viewSetupFormScript(); end;, text: "Philosopher", textSetup: func() begin labelCommands[prefsEntry.philosopherIndex] ; end, labelActionScript: func(cmd) begin prefsEntry.philosopherIndex := cmd; EntryChange(prefsEntry); philView:RevisePhilosophy(); end, _proto: protoLabelPicker }; // ---- End of non-used User Protos ---- // ---- Beginning of section for non used Layout files ---- // ---- File Preferences.t ---- // Before Script for "_view007" // Copyright © 1993,4 Apple Computer, Inc. All rights reserved. _view007 := {rollItems: nil, viewBounds: {left: 0, top: 0, right: 0, bottom: 0}, viewJustify: 240, viewFlags: 4, viewSetupFormScript: func() begin // add the preference items to the browser if prefsEntry.onePrefOnly then begin rollItems := [PT_PreeferAppPrefs] ; // If there is only one entry, start with the roll expanded rollCollapsed := nil ; end else begin rollItems := [PT_PreeferAppPrefs, PT_PreeferPhilPref] ; // if there are multiple entries, start with it collapsed // NOTE: you could also check if all prefs would fit in one screen // and start with it expanded as well rollCollapsed := true ; end; end, _proto: protoRollBrowser }; // After Script for "_view007" thisView := _view007; // set the title correctly for this application thisView.title := kAppName && "Prefs"; // End of output