// Text of project MonacoTest written on 4/23/97 at 2:51 PM // Beginning of text file Constants /* ** Newton Developer Technical Support Sample Code ** ** MonacoTest, a Newton 2.0 monaco font example ** ** by J. Christopher Bell, Newton Developer Technical Support ** ** Copyright © 1994-7 by Apple Computer, Inc. All rights reserved. ** ** You may incorporate this sample code into your applications without ** restriction. This sample code has been provided "AS IS" and the ** responsibility for its operation is 100% yours. You are not ** permitted to modify and redistribute the source as "DTS Sample Code." ** If you are going to re-distribute the source, we require that you ** make it clear in the source that the code was descended from ** Apple-provided sample code, but that you've made changes. */ constant kMyMainDataDefSym := '|myDataDef:monacoTest:DTS| ; constant kMyMainViewDefSym := '|myViewDef:monacoTest:DTS| ; DefConst('kMonaco9Plain, {family: 'Monaco, size: 9, face: 0}); // End of text file Constants // Beginning of file Install Slip // Before Script for "installSlip" x := OpenResFileX(HOME & "Monaco.rsrc"); DefConst('kFontName, GetNamedResource("ustr", "Font Name", 'string)); DefConst('kFontPackage, GetNamedResource("pkg ", "Font Package", 'binary)); DefConst('kFontSymbol, Intern(GetNamedResource("ustr", "Font Symbol", 'string))); CloseResFileX(x); installSlip := {viewBounds: {left: 0, top: 100, right: 200, bottom: 220}, declareSelf: 'base, viewJustify: 16, destination: nil // store , title: "Font Installer", ViewSetupDoneScript: func() destination := GetStores()[0];, ReorientToScreen: func() nil;, debug: "installSlip", _proto: @179 }; _view000 := {_proto: @229}; AddStepForm(installSlip, _view000); _view001 := { text: "This application requires the ^1 font, which is not installed. Choose a destination and tap the Install button to install it now." // The afterScript replaces ^1 with the font name from the resource file. , viewBounds: {top: 3, left: 10, right: -10, bottom: 48}, viewJustify: 8240, _proto: @218 }; AddStepForm(installSlip, _view001); // After Script for "_view001" thisView := _view001; StrMunger(thisView.text, StrPos(thisView.text, "^1", 0), 2, kFontName, 0, nil); destination := {viewBounds: {left: 0, top: 76, right: 180, bottom: 89}, bounds: {left: 0, top: 0, right: 0, bottom: 0}, labelCommands: nil, viewJustify: 8388624, labelActionScript: func(cmd) begin destination := labelStores[cmd]; end, text: "Destination", textSetup: func() // return first one as default begin :MakeStoresLists(); // to get the default if labelCommands then labelCommands[0] else "" end;, MakeStoresLists: func() begin labelCommands := []; labelStores := []; foreach store in GetStores() do if not store:IsReadOnly() then begin AddArraySlot(labelCommands, store:GetName()); AddArraySlot(labelStores, store); end; end;, labelStores: nil, pickerSetup: func() begin :MakeStoresLists(); // do it every time in case a new store is inserted. true // the popup should happen end, debug: "destination", _proto: @190 }; AddStepForm(installSlip, destination); // After Script for "destination" thisView := destination; // this proto uses the bounds instead of the viewbounds slot thisView.bounds := thisView.viewBounds; _view002 := {_proto: @163}; AddStepForm(installSlip, _view002); install := { buttonClickScript: func() begin destination:RestorePackage(kFontPackage); base:Close(); GetRoot().(kAppSymbol):Open(); // re-open the original app end;, text: "Install", viewBounds: {top: -18, left: -56, right: -6, bottom: -5}, viewJustify: 8390790, debug: "install", _proto: @226 }; AddStepForm(installSlip, install); constant |layout_Install Slip| := installSlip; // End of file Install Slip // Beginning of text file Install&RemoveScripts.f /* ** Newton Developer Technical Support Sample Code ** ** MonacoTest, a Newton 2.0 monaco font example ** ** by J. Christopher Bell, Newton Developer Technical Support ** ** Copyright © 1994-7 by Apple Computer, Inc. All rights reserved. ** ** You may incorporate this sample code into your applications without ** restriction. This sample code has been provided "AS IS" and the ** responsibility for its operation is 100% yours. You are not ** permitted to modify and redistribute the source as "DTS Sample Code." ** If you are going to re-distribute the source, we require that you ** make it clear in the source that the code was descended from ** Apple-provided sample code, but that you've made changes. */ InstallScript := func(partFrame) begin local myApp := partFrame.theForm; RegisterViewDef(myApp.MyFormats.viewFormat, kMyMainDataDefSym); end; // run when application and/or card with app removed // cleanup routing stuff RemoveScript := func(partFrame) begin UnregisterViewDef(kMyMainViewDefSym, kMyMainDataDefSym); end; // End of text file Install&RemoveScripts.f // Beginning of file PrintFormat // Before Script for "_view003" // Copyright 1994-7 by Apple Computer, Inc. All rights reserved. _view003 := { PrintNextPageScript: func() begin nil; // only print one page end, title: kAppName && "Default", symbol: kMyMainViewDefSym, _proto: @200 }; _view004 := {viewFlags: 1, viewFormat: 592, viewBounds: {left: 2, top: 2, right: -2, bottom: -2}, ViewDrawScript: func() begin local string := "Demo of text drawn with DrawShape method..."; local theLen := StrFontWidth(string, viewFont); local height := FontHeight(viewFont); local descent := FontDescent(viewFont); local otherFont := {family:'monaco, size:9,face:3}; // draw bold and italic! :DrawShape(MakeRect(100,120 - height + descent,100 + theLen, 120 + descent), {penPattern:vfLtGray}); :DrawShape(MakeText(string, 100,70,500,120), {font:viewFont}); // draw bold! theLen := StrFontWidth(string, otherfont); height := FontHeight(otherFont); descent := FontDescent(otherFont); :DrawShape(MakeRect(100,150 - height + descent,100 + theLen, 150 + descent), {penPattern:vfLtGray}); :DrawShape(MakeText(string, 100,80,500,150), {font:otherFont}); end, viewFont: {family: 'Monaco, size: 9, face: 2}, viewJustify: 240, viewClass: 74 }; AddStepForm(_view003, _view004); _view005 := {viewBounds: {top: 200, left: 10, right: -10, bottom: -50}, viewFlags: 1, viewFont: kMonaco9Plain, viewFormat: 337, viewLineSpacing: 15 , text: "0123456789012345678901234567890123456789012345678901234567890\n0 1 2 3 4 5 6\n\nWith any font that comes from a centralized source (for instance, Apple), you should not embed the font within your application using an NTK multi-part package (including a package as file in the project). This is a bad idea because:\n\n1) compatibility with other apps. Other apps could embed the font in their application. If both applications appear one on Newton device, one of them will break at \"install\" time or \"deinstall\" time. If a font is installed a font more than once, there will be problems.\n\n2) compatibility with the future ROMs. The font family symbol for this font is 'monaco (and '|MonacoCourier:Newton| for font substitution parts). If a future ROM contains these, there will be problems.\n\nIf you want to use the font in your package, use the 'auto-install' feature used in this sample. Alternatively, you can re-build the font part included in the \"Monaco Font\" folder but create *NEW* font symbols for the two font components. (the font itself (the \"font\"), and the MonacoCourier 'font substitution' part (the \"psFont\") used for printing to LaserWriters." , viewJustify: 240, viewClass: 81 }; AddStepForm(_view003, _view005); _view006 := {text: "Static Text", viewBounds: {left: 0, top: -40, right: 0, bottom: -20}, ViewSetupFormScript: func() begin text := "The data from the application: " & target.data ; inherited:?viewSetupFormScript(); end;, viewFont: kMonaco9Plain, viewJustify: 178, _proto: @218 }; AddStepForm(_view003, _view006); constant |layout_PrintFormat| := _view003; // End of file PrintFormat // Beginning of file MonacoTest.t // Before Script for "myBase" /* ** Newton Developer Technical Support Sample Code ** ** Custom Route, a Newton 2.0 routing example ** ** by J. Christopher Bell, Newton Developer Technical Support ** ** Copyright © 1994-5 by Apple Computer, Inc. All rights reserved. ** ** You may incorporate this sample code into your applications without ** restriction. This sample code has been provided "AS IS" and the ** responsibility for its operation is 100% yours. You are not ** permitted to modify and redistribute the source as "DTS Sample Code." ** If you are going to re-distribute the source, we require that you ** make it clear in the source that the code was descended from ** Apple-provided sample code, but that you've made changes. */ myBase := {viewBounds: {left: 0, top: 2, right: 236, bottom: 326}, ViewSetupFormScript: func() begin viewBounds := GetAppParams().appAreaBounds; // should probably define max/min here... // make sure Monaco is available if not fonts.monaco then begin // open our user-friendly dialog to offer font installation to the user. BuildContext(GetLayout("Install Slip")):Open(); // prevent the app from opening by setting its viewbounds very small (we are top-left justified) self.viewBounds := RelBounds(0,0,0,0); // close ourselves in a deferred action and remove the viewbounds slot to save some // space and to let our view template's viewBounds be used next time we open... AddDeferredAction(func(v) begin v:Close(); RemoveSlot(v, 'viewBounds) end, [self]); end; end;, PutAwayScript: func(item) begin /* your app might be asked to put away something you don't know about. Return * nil if you don't know how to deal with it! */ if classof(item.body) <> kMyMainDataDefSym or TargetIsCursor(item.body) then return nil; :Open(); // we might not be open! // This is the place where you could get wild and move the information // into soups, other apps, and otherwise extract the information. if item.body.data then SetValue(theLine, 'text, item.body.data); true; // return true if it was put away successfully end, GetActiveView: func() begin printFormatView; // return the current "active" view (for Intelligent Assistant) end, myFormats: { viewFormat: GetLayout("PrintFormat"), }, ReorientToScreen: ROM_defRotateFunc // Allow landscape mode , appSymbol: kAppSymbol, title: kAppName, debug: "myBase", _proto: @157 }; printFormatView := {viewBounds: {left: 10, top: 37, right: -10, bottom: 156}, viewFlags: 1, viewFormat: 336, GetTargetInfo: func(targetType) begin // the targetType will always be 'routing for routing operations // This function is also called for filing and find local theFrame := { target: { class: kMyMainDataDefSym, // set unique class (and register viewDefs on this symbol!) data: theLine.text }, targetView: theLine, appSymbol: kAppSymbol, // targetInfo.appSymbol is used by some transports // However, note that the Action button *also* looks in its own // view context to find the appSymbol slot. Usually it is found in // the base view because NTK creates it. However, for floaters // with Action buttons, you may need to add an appSymbol slot! }; // Note: if the target is a soup entry, then also include a targetStore slot for use by filing... theFrame; end, viewJustify: 48, debug: "printFormatView", viewClass: 74 }; AddStepForm(myBase, printFormatView); StepDeclare(myBase, printFormatView, 'printFormatView); theLine := {viewBounds: {left: 10, top: 0, right: -10, bottom: -20}, text: "Text", viewJustify: 240, ViewSetupFormScript: // be sure to call inherited:?ViewSetupFormScript() func() begin if not fonts.monaco exists then text := clone("The Monaco font package is not installed"); else if not psfonts.|MonacoCourier:Newton| exists then // you should not normally need to check! text := clone("An old version of the monaco font is installed!"); inherited:?ViewSetupFormScript(); end, debug: "theLine", _proto: @185 }; AddStepForm(printFormatView, theLine); StepDeclare(myBase, theLine, 'theLine); _view007 := { menuRightButtons: [ protoActionButton, ], _proto: @73 }; AddStepForm(printFormatView, _view007); constant |layout_MonacoTest.t| := myBase; // End of file MonacoTest.t