TweetFollow Us on Twitter

Sep 89 Letters
Volume Number:5
Issue Number:9
Column Tag:Letters

Letters

By David E. Smith, Editor & Publisher, MacTutor

Another Way To Post Events

Matthew Snyder

Fairfield, CA

In reference to Joel McNamara’s article in the July issue, there’s another way to post command key events, but you wouldn’t know about it unless you’d read a somewhat obscure 1 page chapter in Inside Macintosh Vol. IV. PPostEvent posts an event just like PostEvent, but it “returns a pointer to the created queue entry.”

Here’s an example of its use. Like Joel, I needed to post an event and then fix the modifier field. This is an FKEY I wrote because too many times I found myself in a situation (like a dialog box) where ordinary paste did not work. Because the command and shift keys are down while the FKEY executes, just using PostEvent would result in all the posted events being command-shifted.

/* 1 */

#include<EventMgr.h>
#include <OSUtil.h>

main() {
 long length, offset;
 int index;
 char **tHandle;
 char *tPtr;
 EvQElPtr MyEventPtr;

if (TEGetScrapLen() > 0) {
 ZeroScrap();
 TEToScrap();
 }

tHandle = (char **) NewHandle(0);
length = GetScrap(tHandle, ‘TEXT’, &offset);
if (length > 0) {
 HLock(tHandle);
 tPtr = *tHandle;
 for (index = 0; index < length; index++) {
 PPostEvent((short) keyDown, (int) tPtr[index], &MyEventPtr);
 MyEventPtr_>evtQModifiers = 0;
 }
 }

DisposHandle(tHandle);
}

By the way, I very much liked Joel’s sentiment that as programmers we can rise above the mere end user; we’re not at the mercy of the “software gods.” It is a good feeling.

Take A Bow, Joel

I. Peter Sealy

New York, NY

I have just purchased a copy of MacTutor (June 1989) on the advice of the Lightspeed C user’s manual, and it has proved very valuable. I was especially impressed by Joel West’s “20 Steps to Printing Incompatibility” which explained maybe 50% of the problems we have had with the Mac. In particular, Excel’s infuriating refusal to work with anything but virgin memory (extremely annoying when you have an expensive 4MB sitting there vacant). More software houses should adopt Joel’s sensitivity to the amount of money that users have spent on their systems.

LSC vs. MPW

Andy Baird

Hightstown, NJ

Will Flor (“MPW vs. LSC,” MacTutor June 1989) is of course entitled to his opinions about the relative merits of MPW and Lightspeed C, but I had to laugh when he compared LSC to a tricycle and said “For very simple programs, perhaps LSC works adequately.” In case you’re unaware of it, Mr. Flor, a few of the “very simple” programs created with LSC are FoxBASE Mac, PageMaker and Digital Darkroom. If those are simple, I’d hate to see what you think is complex!

Hex Conversion

Temple M. Sarles

Nashua, NH

I enjoyed inputting and getting to run the “ADB Demo” for LS pascal 2.0 from your volume 5 number 3 in March 1989. Programs like these give dabblers like me some necessary insight into interfacing with the toolbox and really making things work.

It was a bit of a disappointment to find in procedure QuerySystem the line “str1 := concat(‘System Version (must convert to hex) = ‘, str2, chr(13));”. (emphasis added) Well, I did. Enclosed find the listing of a test program with the function ToHex which accepts a long integer and returns a string representing the value in hexadecimal. I think the code with its comments pretty well explains itself. There were two surprises. I idly tried a negative number, only to get unexpected results. I forgot that negative numbers are represented in two’s complement. An easy solution using the toolbox is presented in lines 21 & 22.

Not really solved is the need to make the string of hex digits a variable instead of a constant. If Hex_Char = ‘0123456789ABCDE’ is declared as a constant then line 27 ( , Hex_Char [Work + 1] ) gets a compile error of “Too many indices are being applied to a variable or expression.” The reason for this is not clear, but making it a string variable works well enough.

To apply this to ADB Demo, add function ToHex to MyADBStuff in the IMPLEMENTATION section ahead of procedure QuerySystem. In QuerySystem, replace the lines:

 NumToString(LongInt(theWorld.systemVersion), str2, chr(13));
 str1 := concat(‘System Version (must convert to hex) = ‘, str2, chr(13));

with:

{2}

 str2 := ToHex(LongInt(theWorld.systemVersion));  {convert to hex string}
 str2 := concat(copy(str2, 1, length(str2) - 2),
 ‘.’, copy(str2, length(str2) - 1, 2));{put in period}
 str1 := concat(‘System Version = ‘, str2, chr(13));

Appropriate credit should be given to Think Technology for their excellent implementation of Pascal and especially for their outstanding development environment (DEC & Apollo could take lessons).

{3}

program Test;    {Just a place to try things out}
 var
 T1: integer;    {The value as an integer}
 T2: string;{What it looks like as a string}

 function ToHex (Number_In: LongInt): string;      {This does the job}
 var
 Accumulate: string; {I never work into return value}
 Hex_Char: string; {The set of Hexadecimal digits}
 Shift: Integer; {Offset into the LongInt}
 Suppress_Zero: boolean;  
 {A switch to suppress leading zeroes}
 Work: LongInt;  {The clipped byte from the Number_In}

 begin
 Accumulate := ‘’; {Start with a blank string}
 Hex_Char := ‘0123456789ABCDEF’; 
 {Somehow this doesn’t work as a Const}
 Suppress_Zero := True; 
 {To start with suppress leading zeroes}

{First take care of sign bit, dispose of two’s complement }
{ and then deal with short three bit high-order hex number}

 if BitTst(@Number_In, 0) then{The sign bit is set!}
 begin
 Accumulate := ‘-’;
 Number_In := BitNot(Number_In); 
 {Two’s Complement cleared}
 Number_In := Number_In + $1
 {It’s always one shy - back to DP101}
 end;
 Work := BitShift(Number_In, 1);   
 {Bang to left  - IM/I-472}
 Work := BitShift(Work, -29); 
 {Back to right - IM/I-472}
 if Work > 0 then
 Accumulate := concat(Accumulate, Hex_Char[Work + 1]);

 Shift := 4;{Start with bit 5 - the 2nd digitd}
 repeat {Now a loop for the other 7 digitd}
 Work := BitShift(Number_In, shift); 
 {Bang to left  - IM/I-472}
 Work := BitShift(Work, -28); 
 {Back to right - IM/I-472}
 if Suppress_Zero then
 if Work > 0 then {The beginning of what we want}
 begin
 Suppress_Zero := False;  
 {A digit - No more leading zeroes}
 Accumulate := concat(Accumulate, Hex_Char[Work + 1])
 end
 else   {Don’t do anything!!}
 else
 Accumulate := concat(Accumulate, Hex_Char[Work + 1]);
 Shift := Shift + 4; {Move over one byte}
 until Shift = 32; {Bit 33 is out of bounds}

 ToHex := Accumulate {Put the result into return value}
 end;   {of function ToHex}

begin
 T1 := 1538;{A famous number now-a-days}
 T2 := ToHex(LongInt(T1));{Let’s see what it is}

{The next line inserts the period needed to make theWorld.systemVersion 
human readable}

 T2 := concat(copy(T2, 1, length(T2) - 2), ‘.’, copy(T2, length(T2) - 
1, 2));
 writeln(‘T1 = ‘, T1, ‘:  T2 = ‘, T2)
end.    {of program Test}

Fill Rectangle Tool

Kevin Parichan

Reedley, CA

In the article I wrote showing how to do the Spray Can and Paint Bucket tools I mentioned that there was a unit on GEnie that implemented these and other tools. That unit is no longer available, so I thought that I would give away the source for the standard filled rectangle tool. I rewrote the code in C so as to show that I don’t play favorites. With the routine given as is, you can easily modify it for ovals and round rectangles, filled or not. The routine uses the current grafport to get the fill pattern and the widths for the frame. Enjoy.

/* 4 */

#define NULL0L

Ptr NewBitMap(theBitMap,theRect)
   BitMap *theBitMap;
   Rect *theRect;
{
   theBitMap->rowBytes = ((theRect->right - theRect->left + 15) / 16) 
* 2;
   theBitMap->baseAddr = NewPtr(theBitMap->rowBytes * (theRect->bottom 
- theRect->top));
   theBitMap->bounds = *theRect;
   if (MemError() == noErr)
      return(theBitMap->baseAddr);
   return(NULL);
}

RectTool_Filled(where,workRect)
   Pointwhere;
   Rect *workRect;
{
   GrafPtrworkPort;
   BitMap workBits;
   PenState workState;
   BitMap oldBits,tempBits;
   Rect tempRect,theRect,aRect;
   PointnewLoc,pivot;
   long position;
   
   GetPort(&workPort);
   workBits = workPort->portBits;
   
   if (NewBitMap(&oldBits,workRect) == NULL)
      return;
   if (NewBitMap(&tempBits,workRect) == NULL)
   {
      DisposPtr(oldBits.baseAddr);
      return;
   }
   
   CopyBits(&workBits,&oldBits,workRect,workRect,srcCopy,NULL);
   
   tempRect = *workRect;
   tempRect.right = tempRect.right + 1;
   tempRect.bottom = tempRect.bottom + 1;
   
   GetPenState(&workState);
   PenNormal();
   PenSize(workState.pnSize.h,workState.pnSize.v);
   
   pivot = newLoc = where;
   SetRect(&theRect,where.h,where.v,where.h,where.v);
   
   while (Button()) {
      GetMouse(&newLoc);
      position = PinRect(&tempRect,newLoc);
      newLoc.v = HiWord(position);
      newLoc.h = LoWord(position);
      if (!EqualPt(newLoc,where))
      {
         Pt2Rect(newLoc,pivot,&theRect);
         Pt2Rect(where,pivot,&aRect);
         UnionRect(&theRect,&aRect,&aRect);
         CopyBits(&oldBits,&tempBits,workRect,workRect,srcCopy,NULL);
         SetPortBits(&tempBits);
         FillRect(&theRect,workState.pnPat);
         FrameRect(&theRect);
         SetPortBits(&workBits);
         CopyBits(&tempBits,&workBits,&aRect,&aRect,srcCopy,NULL);
         where = newLoc;
      }
   }
   
   DisposPtr(tempBits.baseAddr);
   DisposPtr(oldBits.baseAddr);
   SetPenState(&workState);
}

Stop The Press!

Kirk Chase

Anaheim, CA

Well, the Splitbar CDEF indicator dragging bug is fixed, thanks to Alexander S. Colwell of Redondo Beach, CA andMurat N. Konar of Minneapolis, MN. Each one suggests that the Quickdraw global DragPattern at $A34 should be stuffed with a gray pattern. Murat suggests this be done in the initialization procedure, and Alexander says in the doCalc procedure when the thumb region is requested.

It seems that the varialble is initialized to black instead of gray as the Window Manager implies in Inside Macintosh Vol. I on page 294 and 295. It states that " DragGrayRgn pulls a dotted (gray) outline of the region around " and "If you want the region's outline to be drawn in a pattern other than gray, you can store the pattern in the global varialbe DragPattern and then invoke the macro _DragTheRgn." But it looks as if the standard CDEF initializes the global even though we are told by Apple not to write to low memory globals. Oh, well. Hopefully this bug(?) will be fixed later on.

On a side note, I became a father for the first time on July 10, 1989 at 11:36 AM. My wife gave birth to a 5lb. boy named, "Brandon Lee Chase." I like to thank those, especially the staff at MacTutor, for putting up with me at this time. I would also like to thank my wife, Sylvia Lue, for putting up with me. I married simply the best.

 

Community Search:
MacTech Search:

Software Updates via MacUpdate

Latest Forum Discussions

See All

Whitethorn Games combines two completely...
If you have ever gone fishing then you know that it is a lesson in patience, sitting around waiting for a bite that may never come. Well, that's because you have been doing it wrong, since as Whitehorn Games now demonstrates in new release Skate... | Read more »
Call of Duty Warzone is a Waiting Simula...
It's always fun when a splashy multiplayer game comes to mobile because they are few and far between, so I was excited to see the notification about Call of Duty: Warzone Mobile (finally) launching last week and wanted to try it out. As someone who... | Read more »
Albion Online introduces some massive ne...
Sandbox Interactive has announced an upcoming update to its flagship MMORPG Albion Online, containing massive updates to its existing guild Vs guild systems. Someone clearly rewatched the Helms Deep battle in Lord of the Rings and spent the next... | Read more »
Chucklefish announces launch date of the...
Chucklefish, the indie London-based team we probably all know from developing Terraria or their stint publishing Stardew Valley, has revealed the mobile release date for roguelike deck-builder Wildfrost. Developed by Gaziter and Deadpan Games, the... | Read more »
Netmarble opens pre-registration for act...
It has been close to three years since Netmarble announced they would be adapting the smash series Solo Leveling into a video game, and at last, they have announced the opening of pre-orders for Solo Leveling: Arise. [Read more] | Read more »
PUBG Mobile celebrates sixth anniversary...
For the past six years, PUBG Mobile has been one of the most popular shooters you can play in the palm of your hand, and Krafton is celebrating this milestone and many years of ups by teaming up with hit music man JVKE to create a special song for... | Read more »
ASTRA: Knights of Veda refuse to pump th...
In perhaps the most recent example of being incredibly eager, ASTRA: Knights of Veda has dropped its second collaboration with South Korean boyband Seventeen, named so as it consists of exactly thirteen members and a video collaboration with Lee... | Read more »
Collect all your cats and caterpillars a...
If you are growing tired of trying to build a town with your phone by using it as a tiny, ineffectual shover then fear no longer, as Independent Arts Software has announced the upcoming release of Construction Simulator 4, from the critically... | Read more »
Backbone complete its lineup of 2nd Gene...
With all the ports of big AAA games that have been coming to mobile, it is becoming more convenient than ever to own a good controller, and to help with this Backbone has announced the completion of their 2nd generation product lineup with their... | Read more »
Zenless Zone Zero opens entries for its...
miHoYo, aka HoYoverse, has become such a big name in mobile gaming that it's hard to believe that arguably their flagship title, Genshin Impact, is only three and a half years old. Now, they continue the road to the next title in their world, with... | Read more »

Price Scanner via MacPrices.net

B&H has Apple’s 13-inch M2 MacBook Airs o...
B&H Photo has 13″ MacBook Airs with M2 CPUs and 256GB of storage in stock and on sale for up to $150 off Apple’s new MSRP, starting at only $849. Free 1-2 day delivery is available to most US... Read more
M2 Mac minis on sale for $100-$200 off MSRP,...
B&H Photo has Apple’s M2-powered Mac minis back in stock and on sale today for $100-$200 off MSRP. Free 1-2 day shipping is available for most US addresses: – Mac mini M2/256GB SSD: $499, save $... Read more
Mac Studios with M2 Max and M2 Ultra CPUs on...
B&H Photo has standard-configuration Mac Studios with Apple’s M2 Max & Ultra CPUs in stock today and on Easter sale for $200 off MSRP. Their prices are the lowest available for these models... Read more
Deal Alert! B&H Photo has Apple’s 14-inch...
B&H Photo has new Gray and Black 14″ M3, M3 Pro, and M3 Max MacBook Pros on sale for $200-$300 off MSRP, starting at only $1399. B&H offers free 1-2 day delivery to most US addresses: – 14″ 8... Read more
Department Of Justice Sets Sights On Apple In...
NEWS – The ball has finally dropped on the big Apple. The ball (metaphorically speaking) — an antitrust lawsuit filed in the U.S. on March 21 by the Department of Justice (DOJ) — came down following... Read more
New 13-inch M3 MacBook Air on sale for $999,...
Amazon has Apple’s new 13″ M3 MacBook Air on sale for $100 off MSRP for the first time, now just $999 shipped. Shipping is free: – 13″ MacBook Air (8GB RAM/256GB SSD/Space Gray): $999 $100 off MSRP... Read more
Amazon has Apple’s 9th-generation WiFi iPads...
Amazon has Apple’s 9th generation 10.2″ WiFi iPads on sale for $80-$100 off MSRP, starting only $249. Their prices are the lowest available for new iPads anywhere: – 10″ 64GB WiFi iPad (Space Gray or... Read more
Discounted 14-inch M3 MacBook Pros with 16GB...
Apple retailer Expercom has 14″ MacBook Pros with M3 CPUs and 16GB of standard memory discounted by up to $120 off Apple’s MSRP: – 14″ M3 MacBook Pro (16GB RAM/256GB SSD): $1691.06 $108 off MSRP – 14... Read more
Clearance 15-inch M2 MacBook Airs on sale for...
B&H Photo has Apple’s 15″ MacBook Airs with M2 CPUs (8GB RAM/256GB SSD) in stock today and on clearance sale for $999 in all four colors. Free 1-2 delivery is available to most US addresses.... Read more
Clearance 13-inch M1 MacBook Airs drop to onl...
B&H has Apple’s base 13″ M1 MacBook Air (Space Gray, Silver, & Gold) in stock and on clearance sale today for $300 off MSRP, only $699. Free 1-2 day shipping is available to most addresses in... Read more

Jobs Board

Medical Assistant - Surgical Oncology- *Apple...
Medical Assistant - Surgical Oncology- Apple Hill Location: WellSpan Medical Group, York, PA Schedule: Full Time Sign-On Bonus Eligible Remote/Hybrid Regular Apply Read more
Omnichannel Associate - *Apple* Blossom Mal...
Omnichannel Associate - Apple Blossom Mall Location:Winchester, VA, United States (https://jobs.jcp.com/jobs/location/191170/winchester-va-united-states) - Apple 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
Operations Associate - *Apple* Blossom Mall...
Operations Associate - Apple Blossom Mall Location:Winchester, VA, United States (https://jobs.jcp.com/jobs/location/191170/winchester-va-united-states) - Apple Read more
Business Analyst | *Apple* Pay - Banco Popu...
Business Analyst | Apple PayApply now " Apply now + Apply Now + Start applying with LinkedIn Start + Please wait Date:Mar 19, 2024 Location: San Juan-Cupey, PR Read more
All contents are Copyright 1984-2011 by Xplain Corporation. All rights reserved. Theme designed by Icreon.