TweetFollow Us on Twitter

Text Views
Volume Number:7
Issue Number:7
Column Tag:Jörg's Folder

Text Views and Forth News

By Jörg Langowski, MacTutor Editorial Board

“Multiple text views in MacApp”

First, I’d like to give the Forth users among you some good news and some bad news. The bad news first. Mach2 doesn’t work with System 7.0, and I can’t get hold of Palo Alto Shipping. If anyone of you out there knows how to contact them, if they’re still alive, etc., please drop me a note (Netland: langowski@frembl51.bitnet or langowski@embl-heidelberg.de, Applelink: langowski.j).

The good news is about Neon, the OOP Forth implementation by Kriya Systems. You might remember that Bob Loewenstein from the University of Chicago recently managed to persuade Kriya Systems to put Neon into the public domain - under the name of Yerk. Well, since then he has not been asleep and has made some improvements, right now we’re at Yerk version 3.3.2. Instructions on how to obtain the Yerk files are in the letter that arrived recently over E-Mail:

From:

Bob Loewenstein <rfl@ODDJOB.UCHICAGO.EDU>

Subject: yerk 3.3.2 upgrade

An upgraded version of Yerk, the Object Oriented Forth for the Mac, is available for anonymous ftp on oddjob.uchicago.edu, in directory ~ftp/pub/Yerk.

If you already have version 3.3.0, you need only ftp the ‘upgrade.sit.hqx’ file. If you do not have a previous version, ftp the complete package in file ‘yerk3.3.2.sit.hqx’. The manual has not been changed.

The basic changes from 3.3.0 are:

COSMETIC CHANGES

- revised bold fonts in // so 9 pt chicago not loaded

- class window now erases grow box when grown

- now cursor is erased with delete key if +curs is set

- slight cosmetic change to (.mod)

- slight change stop: timer

- ?lines changed in nuc to keep bottom line on screen

and grow: method in window changed to send current

line to bottom if grow shortened window.

BUG FIXES

- modified savesig

- added negate: to class Int

- fixed slight bug in decompile (for floats)

- fixed to: problem in pathList source for sarray (file

pathlist)

- some changes to Install Module..it still does not

create a stand-alone application, but does reset

dictionary and stack sizes

- slot manager traps now correct

I would appreciate a note from anyone who intends to seriously use this development system. Future upgrades will be forthcoming, and any reasonable suggestions will most likely be included in such upgrades.

Bob Loewenstein

Dept. of Astronomy and Astrophysics

University of Chicago

Yerkes Observatory

Williams Bay, Wisconsin 53191

414-245-5555

As usual, I’d be glad to help those who have difficulty downloading the Yerk source over the network. Drop me a line at one of my E-mail addresses.

The second good news comes from Michael Hore (Australia), of Mops fame (Mops = Michael’s object programming system). To remind you: Michael re-implemented Neon on top of a subroutine-threaded Forth kernel, with lots of inline code and other optimizations. A couple of days ago, his letter arrived:

Dear Jörg,

I was really please with the glowing report you gave about Mops in MacTutor of Oct last year. Several people in various parts of the world have since contacted me for copies of Mops. This is to let you know that I am just putting the finishing touches to Mops 2.0, and expect it to be available in a couple of weeks now. Actually I am aiming to have it available by the time Apple releases System 7, but I think I might beat them to it (wouldn’t be too hard, would it?) [well, it seems once in a while Apple gets something out on a deadline - which has been pushed far enough, however. I remember MacHack 1989 when they were taking bets when System 7 was going to be released, Fall 89 or Spring 90, etc - JL].

With Kriya’s release of the source code of Neon, I am now free to offer Mops to anyone, not just Neon users. Although to really make it accessible to non-Neon users I should probably write a manual (ugh!).

Actually I note that the text of Kriya’s letter to Bob Loewenstein says that Neon is released for “scientific and educational purposes All commercial distribution rights are reserved by Kriya Systems, Inc.” This, of course, isn’t exactly public domain. It means that if a non-Neon owner wanted to do something commercial in Mops, and Mops still contained any of Kriya’s source code, I would have to negotiate a separate agreement with Kriya, somehow

Still, to be realistic, I doubt that any non-Neon owner would want to use it for a commercial project at this stage, although there is a Neon owner here in Australia who is going to use it commercially. Eventually there will be none of Kriya’s code left, and then there will be no problem. The nucleus and most of the standard system stuff is original right now - only the language itself is closely derived from Neon, and my understanding of the legalities is that a language, as such, isn’t copyrightable.

Anyway, this release will have quite a number of improvements:

• Mops will be fully System 7 friendly. All the new system calls will be available through the normal Call xxxx syntax. (I’ve discovered, incidentally, that Neon won’t run under System 7 - there’s a problem with the way it resizes itself in memory on startup).

• Up to 24 named parameters/local variables. This used to be 6 in Neon, 5 in Mops.

• The Assembler will support the 68881/2 FPU instructions.

• Mops already has Neon-compatible floating point - in the new version, FP words test a flag for the presence of an FPU, and if it is present, these words bypass SANE. This gives around a 400% speedup. Mops will also optionally compile inline optimized FPU code. If this mode is selected, up to 6 floating point named parameters or locals will be kept in the FPU registers. This results in some rather swift floating-point code (10 to 20 times faster than SANE). This is probably as quick as anything on the Mac, if not quicker.

• No limit on dictionary size.

When this version is available I’ll send you a copy, which you can distribute [Sure will! - JL] or whatever. As always, anyone who sends me two blank disks will get a copy (or if they put something else useful on the disks, I won’t complain).

Yours sincerely,

Michael Hore

(c/o MAF, P.O. Box 821, Nhulunbuy, NT 0880, Australia)

So you see, the OOP Forth scene for the Mac isn’t anything like dead, but quite a few exciting things are still happening! If you are using any of those systems and have an idea for an article, I’d really appreciate your contributions.

Multi-box text editor

Now let’s go back to C++, MacApp, and this month’s main subject. We’ll extend the simple editor from the May column to accommodate several boxes containing some text, of different style. We also want a border drawn around each box, and the window in which the text boxes are displayed should be scrollable (you notice that with these additions we come closer to adding a ‘text box’ capability to our drawing example).

Anything that is to be scrolled in a MacApp window will be contained in a scroller view (class TScroller). This time we shall create the scroller from a view template that we define with ViewEdit; the scroller will contain two subviews of class TTEBox. This class is derived from the standard class TTEView. It implements its own Draw method which draws a box around the view, and a DoMouseCommand method which handles mouse clicks in the view.

The latter method is important for selecting the text box which will receive the keystrokes typed by the user; clicking in one text box should select that box (this is not an automatic feature of TTEView, but has to be programmed).

The Draw method (Listing 2) gets the extent rectangle of the view in QuickDraw format, and calls FrameRect, and the superclass Draw method. DoMouseCommand simply sends the SetTarget(this) message to the window enclosing the view, which means that keystrokes and DoIdle messages will be sent to this text view.

For the scroller enclosing the text boxes, we also derive a new class from TScroller, TEditView. This allows us to save references to the enclosed TTEBox objects (two in our case) in instance variables - you never know what you’ll be able to use them for. The only new method that we define for TEditView is IEditView, which initializes the print handler and the new instance variables, and sets the window’s target to the second text box (just for the fun of it).

The application’s class is TEditor. The constructor method of this class initializes the application and generates a new window containing the views as defined in a resource file that has been created by ViewEdit. The resource is ‘view’, ID=1002. This view contains one instance of TEditView, with identifier ‘scrl’, which in turn contains two instances of TTEBox as subviews, with identifiers ‘tx01’ and ‘tx02’.

Writing code like this where instances of views are generated from templates at run time requires some attention. If the class is never referenced explicitly in the source code, either by generating an instance using new, or by calling one of its methods, the linker will think that class’ code isn’t used and doesn’t need to be included in the application. Running the application will then generate an error message, because the code required to initialize the new object can’t be found anywhere. We therefore have to include dummy references to TEditView and TTEBox, to make sure we can instantiate the objects at run time. This is done in the code starting with if (gDeadStripSuppression) {}. Finally, we initialize the newly generated TEditView.

How do we generate the templates for our view in ViewEdit? First of all, we draw a TScroller of a certain size. We check the box ‘Top view in TWindow’ to indicate that the view is contained in a window, and then click on the button ‘TWindow parameters ’. This will open a dialog where we can set the window size. It should be 15 pixel bigger than the TScroller in either direction, to accommodate the scroll bars. Returning to the ViewEdit window, we double-click on the TScroller box, opening the dialog for the TScroller parameters. Here, we have to set the two size determiners to ‘sizeRelSuperView’, in order to make the scroll bars grow and shrink with the window. Finally, we find a text box where we can enter the class name. By default, this will be the name of the standard view that we generated (TScroller in this case). Entering another name here allows us to generate an object of a class derived from TScroller. Thus, here we enter TEditView, the name of our derived class. The view identifier, by default ‘VW01’, can be changed, too; I chose ‘scrl’.

Finally, we draw two TTEView boxes inside our TEditView (drawing them inside automatically makes them subviews), and change their class names to TTEBox, and the view identifiers to ‘tx01’ and ‘tx02’. We save the resource file and are ready to go. The view resource that I just described is contained on the source code disk as ‘editor.rsrc’.

We’re done; building the application will now create a program that displays one window, scrollable in both directions, in which two text edit boxes are displayed. Clicking on one of them allows you to enter text there. We’ll continue this example and see how we can add disk read/write; till then.

Listing 1: editor.h

class TEditor : public TApplication {
public:
 pascal TEditor(OSType itsMainFileType);
 pascal void HandleFinderRequest();
#ifdef qDebug
 virtual pascal void IdentifySoftware();
#endif
};

class TEditView : public TScroller {
public:
 TTEView*fTEView1;
 TTEView*fTEView2;
 pascal void IEditView(TWindow *itsWindow);
};

class TTEBox : public TTEView {
public:
 pascal void Draw(Rect *area);
 pascal struct TCommand 
 *DoMouseCommand(Point *theMouse,
 EventInfo *info, Point *hysteresis);
};
Listing 2: editor.cp

#include <UMacApp.h>
#include <UPrinting.h>
#include <UTEView.h>
#include <Fonts.h>
#include <ToolUtils.h>

#include “editor.h”

const OSType kSignature   = ‘JLMT’;
const OSType kFileType    = ‘JL01’;
const int kWindowID= 1002;

pascal TEditor::TEditor(OSType itsMainFileType)
{
 TWindow*aWindow;
 TEditView*aEditView;
 TTEBox *aTEBox;
 
 IApplication(itsMainFileType);

 aWindow = NewTemplateWindow(kWindowID,nil);
 FailNIL(aWindow);
 
 if (gDeadStripSuppression)
 {
 aEditView = new TEditView;
 aTEBox = new TTEBox;
 }

 aEditView = 
 (TEditView*) aWindow->FindSubView(‘scrl’);
 FailNIL(aEditView);
 aEditView->IEditView(aWindow);
 
 aWindow->Open();
}

pascal void TEditor::HandleFinderRequest()  {};

#ifdef qDebug
pascal void TEditor::IdentifySoftware()
{
 ProgramReport
 (“\pEditor ©J.Langowski/MacTutor May 1991”,false);
 inherited::IdentifySoftware();
}
#endif

pascal void TEditView::IEditView(TWindow *itsWindow)
{
 TStdPrintHandler*aStdPrintHandler;
 
 aStdPrintHandler = new TStdPrintHandler;
 FailNIL(aStdPrintHandler);
 aStdPrintHandler->IStdPrintHandler
 (nil,this,kSquareDots,kFixedSize,!kFixedSize);
 fPrintHandler = aStdPrintHandler;

 fTEView1 = 
 (TTEView*) itsWindow->FindSubView(‘tx01’);
 FailNIL(fTEView1);
 fTEView2 = 
 (TTEView*) itsWindow->FindSubView(‘tx02’);
 FailNIL(fTEView2);
 
 itsWindow->SetTarget(fTEView2);
}

pascal void TTEBox::Draw(Rect *area)
{
 Rect itsQDExtent;
 
 PenNormal();
 GetQDExtent(&itsQDExtent);
 FrameRect(&itsQDExtent);
 inherited::Draw(area);
}

pascal struct TCommand 
 *TTEBox::DoMouseCommand(Point *theMouse,
 EventInfo *info, Point *hysteresis)
{
 if (Focus())
   {  GetWindow()->SetTarget(this); }

 return inherited::DoMouseCommand
 (theMouse,info,hysteresis);
}

TEditor *gEditor;

int main()
{
 InitToolBox();
 if (ValidateConfiguration(&gConfiguration))
 {
 InitUMacApp(8);
 InitUPrinting();
 InitUTEView();
 gEditor = new TEditor(kFileType);
 FailNIL(gEditor);
 gEditor->Run();
 }
 else StdAlert(phUnsupportedConfiguration);
 return 0;
}
Listing 3: editor.r

/* editor.r 
 Rez file for MacTutor C++/MacApp Editor example
 J. Langowski May 1991
*/

#ifndef __TYPES.R__
#include “Types.r”
#endif

#ifndef __SYSTYPES.R__
#include “SysTypes.r”
#endif

#ifndef __MacAppTypes__
#include “MacAppTypes.r”
#endif

#ifndef __ViewTypes__
#include “ViewTypes.r”
#endif

#if qDebug
include “Debug.rsrc”;
#endif

include “MacApp.rsrc”;
include “Printing.rsrc”;

include “Defaults.rsrc” ‘SIZE’(-1);
include “Defaults.rsrc” ‘ALRT’(phAboutApp);
include “Defaults.rsrc” ‘DITL’(phAboutApp);
include “Defaults.rsrc” ‘cmnu’(mApple);
include “Defaults.rsrc” ‘cmnu’(mEdit);
include “Defaults.rsrc” ‘cmnu’(mBuzzWords);

include “Editor” ‘CODE’;

include “editor.rsrc”;

#define kSignature ‘JLMT’
#define kDocFileType ‘JL01’
#define getInfoString“©1991 J.Langowski/MacTutor. “

/* ------------------------------------------------------------------------*/

resource ‘cmnu’ (2) {
 2,
 textMenuProc,
 allEnabled,
 enabled,
 “File”,
  {
 “Close”, noIcon, noKey, noMark, plain, 31;
 “-”, noIcon, noKey, noMark, plain, nocommand;
 “Page Setup ”, 
 noIcon, noKey, noMark, plain, 176;
 “Print One”, noIcon, “P”, noMark, plain, 177;
 “Print ”, noIcon, noKey, noMark, plain, 178;
 “-”, noIcon, noKey, noMark, plain, nocommand;
 “Quit”, noIcon, “Q”, noMark, plain, 36
 }
};


resource ‘MBAR’ (kMBarDisplayed,purgeable) 
{
 {mApple; 2; mEdit;}
};


/*--------------------------------------------------------------------------
 The overall package version
----------------------------------------------------------------------------*/
RESOURCE ‘vers’ (2,
#if qNames
“Package Version”,
#endif
 purgeable) {
 0x02,
 0x00,
 beta,
 0x06,
 verUs,
 “2.0”,
 “MacApp® 2.0, ©Apple Computer, Inc. 1990”
};


/*--------------------------------------------------------------------------
 The revision of this particular file
--------------------------------------------------------------------------*/
RESOURCE ‘vers’ (1,
#if qNames
“File Version”,
#endif
 purgeable) {
 0x01,
 0x00,
 beta,
 0x05,
 verUs,
 “Editor”,
 “v 0.9, ©JL/MacTutor 1991”
};

/* =========== debug window ============ */
resource ‘dbug’ (kDebugParamsID,
#if qNames
“Debug”,
#endif
 purgeable) {
 {350, 4, 474, 636}, /* Bounding rect for debug window */
 1,   /* Debug window font rsrc ID (normal = monaco) */
 9,/* Debug window font size (normal = 9) */
 100, /* Number of lines */
 100, /* Width of lines in characters */
 true,  /* open initially */
 “Jörg’s Debug Window”  /* Window title */
};

 

Community Search:
MacTech Search:

Software Updates via MacUpdate

Latest Forum Discussions

See All

Tokkun Studio unveils alpha trailer for...
We are back on the MMORPG news train, and this time it comes from the sort of international developers Tokkun Studio. They are based in France and Japan, so it counts. Anyway, semantics aside, they have released an alpha trailer for the upcoming... | Read more »
Win a host of exclusive in-game Honor of...
To celebrate its latest Jujutsu Kaisen crossover event, Honor of Kings is offering a bounty of login and achievement rewards kicking off the holiday season early. [Read more] | Read more »
Miraibo GO comes out swinging hard as it...
Having just launched what feels like yesterday, Dreamcube Studio is wasting no time adding events to their open-world survival Miraibo GO. Abyssal Souls arrives relatively in time for the spooky season and brings with it horrifying new partners to... | Read more »
Ditch the heavy binders and high price t...
As fun as the real-world equivalent and the very old Game Boy version are, the Pokemon Trading Card games have historically been received poorly on mobile. It is a very strange and confusing trend, but one that The Pokemon Company is determined to... | Read more »
Peace amongst mobile gamers is now shatt...
Some of the crazy folk tales from gaming have undoubtedly come from the EVE universe. Stories of spying, betrayal, and epic battles have entered history, and now the franchise expands as CCP Games launches EVE Galaxy Conquest, a free-to-play 4x... | Read more »
Lord of Nazarick, the turn-based RPG bas...
Crunchyroll and A PLUS JAPAN have just confirmed that Lord of Nazarick, their turn-based RPG based on the popular OVERLORD anime, is now available for iOS and Android. Starting today at 2PM CET, fans can download the game from Google Play and the... | Read more »
Digital Extremes' recent Devstream...
If you are anything like me you are impatiently waiting for Warframe: 1999 whilst simultaneously cursing the fact Excalibur Prime is permanently Vault locked. To keep us fed during our wait, Digital Extremes hosted a Double Devstream to dish out a... | Read more »
The Frozen Canvas adds a splash of colou...
It is time to grab your gloves and layer up, as Torchlight: Infinite is diving into the frozen tundra in its sixth season. The Frozen Canvas is a colourful new update that brings a stylish flair to the Netherrealm and puts creativity in the... | Read more »
Back When AOL WAS the Internet – The Tou...
In Episode 606 of The TouchArcade Show we kick things off talking about my plans for this weekend, which has resulted in this week’s show being a bit shorter than normal. We also go over some more updates on our Patreon situation, which has been... | Read more »
Creative Assembly's latest mobile p...
The Total War series has been slowly trickling onto mobile, which is a fantastic thing because most, if not all, of them are incredibly great fun. Creative Assembly's latest to get the Feral Interactive treatment into portable form is Total War:... | Read more »

Price Scanner via MacPrices.net

Early Black Friday Deal: Apple’s newly upgrad...
Amazon has Apple 13″ MacBook Airs with M2 CPUs and 16GB of RAM on early Black Friday sale for $200 off MSRP, only $799. Their prices are the lowest currently available for these newly upgraded 13″ M2... Read more
13-inch 8GB M2 MacBook Airs for $749, $250 of...
Best Buy has Apple 13″ MacBook Airs with M2 CPUs and 8GB of RAM in stock and on sale on their online store for $250 off MSRP. Prices start at $749. Their prices are the lowest currently available for... Read more
Amazon is offering an early Black Friday $100...
Amazon is offering early Black Friday discounts on Apple’s new 2024 WiFi iPad minis ranging up to $100 off MSRP, each with free shipping. These are the lowest prices available for new minis anywhere... Read more
Price Drop! Clearance 14-inch M3 MacBook Pros...
Best Buy is offering a $500 discount on clearance 14″ M3 MacBook Pros on their online store this week with prices available starting at only $1099. Prices valid for online orders only, in-store... Read more
Apple AirPods Pro with USB-C on early Black F...
A couple of Apple retailers are offering $70 (28%) discounts on Apple’s AirPods Pro with USB-C (and hearing aid capabilities) this weekend. These are early AirPods Black Friday discounts if you’re... Read more
Price drop! 13-inch M3 MacBook Airs now avail...
With yesterday’s across-the-board MacBook Air upgrade to 16GB of RAM standard, Apple has dropped prices on clearance 13″ 8GB M3 MacBook Airs, Certified Refurbished, to a new low starting at only $829... Read more
Price drop! Apple 15-inch M3 MacBook Airs now...
With yesterday’s release of 15-inch M3 MacBook Airs with 16GB of RAM standard, Apple has dropped prices on clearance Certified Refurbished 15″ 8GB M3 MacBook Airs to a new low starting at only $999.... Read more
Apple has clearance 15-inch M2 MacBook Airs a...
Apple has clearance, Certified Refurbished, 15″ M2 MacBook Airs now available starting at $929 and ranging up to $410 off original MSRP. These are the cheapest 15″ MacBook Airs for sale today at... Read more
Apple drops prices on 13-inch M2 MacBook Airs...
Apple has dropped prices on 13″ M2 MacBook Airs to a new low of only $749 in their Certified Refurbished store. These are the cheapest M2-powered MacBooks for sale at Apple. Apple’s one-year warranty... Read more
Clearance 13-inch M1 MacBook Airs available a...
Apple has clearance 13″ M1 MacBook Airs, Certified Refurbished, now available for $679 for 8-Core CPU/7-Core GPU/256GB models. Apple’s one-year warranty is included, shipping is free, and each... Read more

Jobs Board

Seasonal Cashier - *Apple* Blossom Mall - J...
Seasonal Cashier - Apple Blossom Mall Location:Winchester, VA, United States (https://jobs.jcp.com/jobs/location/191170/winchester-va-united-states) - Apple Read more
Seasonal Fine Jewelry Commission Associate -...
…Fine Jewelry Commission Associate - Apple Blossom Mall Location:Winchester, VA, United States (https://jobs.jcp.com/jobs/location/191170/winchester-va-united-states) Read more
Seasonal Operations Associate - *Apple* Blo...
Seasonal Operations Associate - Apple Blossom Mall Location:Winchester, VA, United States (https://jobs.jcp.com/jobs/location/191170/winchester-va-united-states) - Read more
Hair Stylist - *Apple* Blossom Mall - JCPen...
Hair Stylist - Apple Blossom Mall Location:Winchester, VA, United States (https://jobs.jcp.com/jobs/location/191170/winchester-va-united-states) - Apple Blossom Read more
Cashier - *Apple* Blossom Mall - JCPenney (...
Cashier - Apple Blossom Mall Location:Winchester, VA, United States (https://jobs.jcp.com/jobs/location/191170/winchester-va-united-states) - Apple Blossom Mall Read more
All contents are Copyright 1984-2011 by Xplain Corporation. All rights reserved. Theme designed by Icreon.