home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Mac Game Programming Gurus / TricksOfTheMacGameProgrammingGurus.iso / Information / CSMP Digest / volume 1 / csmp-v1-165.txt < prev    next >
Encoding:
Text File  |  1994-12-08  |  35.9 KB  |  957 lines  |  [TEXT/R*ch]

  1. C.S.M.P. Digest             Tue, 11 Aug 92       Volume 1 : Issue 165
  2.  
  3. Today's Topics:
  4.  
  5.     SourceBug vs THINK C Debugger?
  6.     Using _ExitToShell (Re: Why can't I Quit?)
  7.     Fraudulent compressed resources
  8.     Easy question (!?)
  9.     creating/using 'styl' & 'TEXT' resources
  10.     Powerbook 100 Roms
  11.     Perl under MPW??
  12.     windowKind usage, the RIGHT way to do it...
  13.     member() bug SOLVED (I hope)
  14.  
  15.  
  16.  
  17. The Comp.Sys.Mac.Programmer Digest is moderated by Michael A. Kelly.
  18.  
  19. The digest is a collection of article threads from the internet newsgroup
  20. comp.sys.mac.programmer.  It is designed for people who read c.s.m.p. semi-
  21. regularly and want an archive of the discussions.  If you don't know what a
  22. newsgroup is, you probably don't have access to it.  Ask your systems
  23. administrator(s) for details.  (This means you can't post questions to the
  24. digest.)
  25.  
  26. Each issue of the digest contains one or more sets of articles (called
  27. threads), with each set corresponding to a 'discussion' of a particular
  28. subject.  The articles are not edited; all articles included in this digest
  29. are in their original posted form (as received by our news server at
  30. cs.uoregon.edu).  Article threads are not added to the digest until the last
  31. article added to the thread is at least one month old (this is to ensure that
  32. the thread is dead before adding it to the digest).  Article threads that
  33. consist of only one message are generally not included in the digest.
  34.  
  35. The entire digest is available for anonymous ftp from ftp.cs.uoregon.edu
  36. [128.223.8.8] in the directory /pub/mac/csmp-digest.  Be sure to read the
  37. file /pub/mac/csmp-digest/README before downloading any files.  The most
  38. recent issues are available from sumex-aim.stanford.edu [36.44.0.6] in the
  39. directory /info-mac/digest/csmp.  If you don't have ftp capability, the sumex
  40. archive has a mail server; send a message with the text '$MACarch help' (no
  41. quotes) to LISTSERV@ricevm1.rice.edu for more information.
  42.  
  43. The digest is also available via email.  Just send a note saying that you
  44. want to be on the digest mailing list to mkelly@cs.uoregon.edu, and you will
  45. automatically receive each new issue as it is created.  Sorry, back issues
  46. are not available through the mailing list.
  47.  
  48. Send administrative mail to mkelly@cs.uoregon.edu.
  49.  
  50.  
  51. -------------------------------------------------------
  52.  
  53. From: quesnel@ems (Rene Quesnel)
  54. Subject: SourceBug vs THINK C Debugger?
  55. Date: 5 Jul 92 17:24:40 GMT
  56. Organization: Faculty of Music, McGill University
  57.  
  58. Could anyone tell me how does the new SourceBug debugger that runs with
  59. MPW C++ compare with THINK C's debugger in terms of ease of accessing
  60. members of structures dereferenced from pointers to those structures or
  61. accessing structure elements in a linked list? It is so simple with
  62. THINK C and so cumbersome with SADE (sigh). I will gladly buy 
  63. SourceBug if it's worth the price.
  64.  
  65. Thank you,
  66. Rene Quesnel
  67. quesnel@music.mcgill.ca
  68.  
  69. +++++++++++++++++++++++++++
  70.  
  71. From: ksand@apple.com (Kent Sandvik)
  72. Date: 9 Jul 92 00:14:26 GMT
  73. Organization: Apple Inc, Debugging Department
  74.  
  75. In article <1992Jul5.172440.7277@thunder.mcrcim.mcgill.edu>, quesnel@ems
  76. (Rene Quesnel) wrote:
  77. > Could anyone tell me how does the new SourceBug debugger that runs with
  78. > MPW C++ compare with THINK C's debugger in terms of ease of accessing
  79. > members of structures dereferenced from pointers to those structures or
  80. > accessing structure elements in a linked list? It is so simple with
  81. > THINK C and so cumbersome with SADE (sigh). I will gladly buy 
  82. > SourceBug if it's worth the price.
  83.  
  84. SourceBug relies on PascalObject meta-information, so unless
  85. you are programming with MacApp I'm afraid that you will not be as
  86. pleased with the information concerning class fields. They don't show
  87. up in the third column. However the examination function shows all the
  88. fields,
  89. values and pointers in a C++ object -- in a really nice way.
  90.  
  91. I don't want to state that SourceBug is a lousy editor, I do know of C
  92. programmers that use it because it's easy to learn, and is fine for
  93. breakpoint settings, stack traces, C++ field value examination and many
  94. other typical
  95. common debugging cases. You have the choice of SourceBug, which is a very
  96. good
  97. high level debugger, SADE which has the neat features of extension
  98. programming
  99. and watch points, Steve Jasik's which is a combination of high-low level
  100. debugger, and then MacsBug/TMON which you need now and then.
  101.  
  102. Cheers,
  103. Kent/DTS
  104.  
  105. ---------------------------
  106.  
  107. From: leonardr@ccs.itd.umich.edu
  108. Subject: Using _ExitToShell (Re: Why can't I Quit?)
  109. Organization: Campus Computing Sites, University of Michigan-Ann Arbor
  110. Date: Tue, 7 Jul 92 04:14:21 GMT
  111.  
  112. In article <+65lf8l.howard@netcom.com> howard@netcom.com (Howard Berkey) writes:
  113. >
  114. >A better way to quit is to use ExitToShell() in this case as your app
  115. >is guaranteed to be in the foreground when the user selects Quit or hits
  116. >command-Q in your application.  Something like this in your file menu handler:
  117. >
  118.     You should NOT use ExitToShell() to exit applications anymore. With
  119. Apple event Handlers the way they are constructed, it is recommended (or
  120. required) that you leave the application through the "bottom" rather than
  121. exiting abuptly so that the AEManager can clean up it's handler tables.
  122.  
  123.  
  124. - -- 
  125. - -----------------------------------------------------------------------
  126. Leonard Rosenthol          Internet: leonardr@ccs.itd.umich.edu
  127. Director of Advanced Technology   AppleLink: MACgician
  128. Aladdin Systems, inc.          GEnie:     MACgician
  129.  
  130. +++++++++++++++++++++++++++
  131.  
  132. From: Martin.Friedrich@arbi.informatik.uni-oldenburg.de (Martin Friedrich)
  133. Date: 7 Jul 92 08:48:38 GMT
  134. Organization: University of Oldenburg, Germany
  135.  
  136. leonardr@ccs.itd.umich.edu writes:
  137.  
  138. >In article <+65lf8l.howard@netcom.com> howard@netcom.com (Howard Berkey) writes:
  139. >>
  140. >>A better way to quit is to use ExitToShell() in this case as your app
  141. >>is guaranteed to be in the foreground when the user selects Quit or hits
  142. >>command-Q in your application.  Something like this in your file menu handler:
  143. >>
  144. >    You should NOT use ExitToShell() to exit applications anymore. With
  145. >Apple event Handlers the way they are constructed, it is recommended (or
  146. >required) that you leave the application through the "bottom" rather than
  147. >exiting abuptly so that the AEManager can clean up it's handler tables.
  148.  
  149. What do You mean by "through the "bottom""? The AEhandlers in the application
  150. heap are removed automaticly (at least, I don't care about them, and never
  151. get crashed on application exit...), and if a handler resides in the system
  152. heap you must remove it explicitly. Supposing this handler is AEQuit handler
  153. you can't do that while executing the handler, do you?
  154. - -- 
  155. LLaP
  156.        Martin Friedrich
  157.  
  158. - -----------------------------------------------------------------------------
  159.                          |"I never will understand
  160. REAL      Martin Friedrich   (CS-Student)    | humans ..."
  161. NICK      jupp                               | -- Spock, Patterns of Force
  162. UUCP      friedrich@uniol                    --------------------------------
  163. DOMAIN    Martin.Friedrich@arbi.informatik.uni-oldenburg.de
  164. HOME      Straekweg 1 , 2986 Leezdorf
  165.  
  166.      Superior abilities breed superior ambitions
  167. - -----------------------------------------------------------------------------
  168.  
  169. +++++++++++++++++++++++++++
  170.  
  171. From: zben@ni.umd.edu (Charles B. Cranston)
  172. Date: 7 Jul 92 22:41:48 GMT
  173. Organization: UM Home for the Terminally Analytical
  174.  
  175. In article <+65lf8l.howard@netcom.com> howard@netcom.com (Howard Berkey) writes:
  176.  
  177. > A better way to quit is to use ExitToShell() in this case ...
  178.  
  179. If you're using MacTCP you had better terminate all your streams first,
  180. or else next time you run the same application you'll hang bigtime...
  181.  
  182. I deal with this problem by writing a "terminate" function that closes
  183. everything down, then calls ExitToShell...
  184.  
  185. +++++++++++++++++++++++++++
  186.  
  187. From: grobbins@Apple.COM (Grobbins)
  188. Date: 8 Jul 92 04:41:44 GMT
  189. Organization: C.K.'s Office Decorating Club
  190.  
  191. In article <1992Jul7.085807.29819@arbi.Informatik.Uni-Oldenburg.DE> Martin.Friedrich@arbi.informatik.uni-oldenburg.de (Martin Friedrich) writes:
  192. >leonardr@ccs.itd.umich.edu writes:
  193. >>    You should NOT use ExitToShell() to exit applications anymore.
  194. >What do You mean by "through the "bottom""? 
  195. >... Supposing this handler is AEQuit handler
  196. >you can't do that while executing the handler, do you?
  197.  
  198. It's just that it may not always be a good idea to call ExitToShell.
  199. This is not particularly new; for example, you wouldn't ever call
  200. ExitToShell from a completion routine or a def proc, I hope.
  201.  
  202. Nowadays it is more common with the kind of dispatching that the Apple
  203. Event Manager does to be in a state where ExitToShell is a bad idea.
  204. The classic case is the Quit event handler, which should just set a
  205. flag telling your main program that it's time to go.
  206.  
  207. The System will clean up whatever it can whenever the application
  208. quits, whether the app quits via an explicit ExitToShell or by dropping
  209. out the bottom.  But it can't deal with exiting from within an event
  210. handler or from code which may have been reached in any other bizarre
  211. manner.  Just set a global done flag and let the main program bail when
  212. the coast is clear.
  213.  
  214.  
  215. Grobbins                 grobbins@apple.com
  216.  
  217. Usual disclaimers apply.
  218.  
  219.  
  220. +++++++++++++++++++++++++++
  221.  
  222. From: pbrande1@cc.swarthmore.edu (Philip Brandenberger)
  223. Organization: Swarthmore College
  224. Date: Thu, 9 Jul 1992 16:26:03 GMT
  225.  
  226. zben@ni.umd.edu (Charles B. Cranston) writes:
  227. > In article <+65lf8l.howard@netcom.com> howard@netcom.com (Howard Berkey) writes:
  228. > > A better way to quit is to use ExitToShell() in this case ...
  229. > If you're using MacTCP you had better terminate all your streams first,
  230. > or else next time you run the same application you'll hang bigtime...
  231.  
  232. Nawwww, just get ZapTCP!  It saves you the trouble of closing your
  233. own streams!  :-)
  234.  
  235. - -Phil
  236.  
  237. - -- 
  238. Philip J. Brandenberger
  239. Swarthmore College, but I don't speak for it, in fact usually against it.
  240. pbrande1@cc.swarthmore.edu
  241.  
  242. ---------------------------
  243.  
  244. Subject: Fraudulent compressed resources
  245. From: michael@otago.ac.nz
  246. Date: 8 Jul 92 09:32:48 +1300
  247. Organization: University of Otago, Dunedin, New Zealand
  248.  
  249. I would like to be able to tell (so I can warn users) when the file I am
  250. processing contains compressed resources. So, you, say, just check that
  251. "compressed" bit in the resource attributes and away you go...
  252.  
  253. Not so. Certain perfectly ordinary applications have the compressed bit set on
  254. some perfectly normal resources. This causes my warning to come up when it
  255. shouldn't. But then, how do the applications work? Why don't the resources get
  256. decompressed and mangled? Somehow, the system knows something else about what a
  257. compressed resource looks like. So does ResEdit, for that matter, because if
  258. you look at these resources with it it will tell you that they aren't
  259. compressed. DeRez tells the true story: the compressed bit in the attributes 
  260. is set.
  261.  
  262. So, has anyone encountered this before? What do I need to do to find out if
  263. resources are *really* compressed?
  264.  
  265.  
  266. Michael(tm) Hamel, Computing Services Centre, University of Otago, New Zealand
  267.  
  268. RADLETT (n.)                       
  269. The single hemisphere of dried pea which is invariably found in an otherwise
  270. spotlessly clean saucepan.
  271.  
  272.  
  273. +++++++++++++++++++++++++++
  274.  
  275. From: leonardr@ccs.itd.umich.edu
  276. Date: 8 Jul 92 03:08:32 GMT
  277. Organization: Campus Computing Sites, University of Michigan-Ann Arbor
  278.  
  279. In article <1992Jul8.093248.3089@otago.ac.nz> michael@otago.ac.nz writes:
  280. >I would like to be able to tell (so I can warn users) when the file I am
  281. >processing contains compressed resources. So, you, say, just check that
  282. >"compressed" bit in the resource attributes and away you go...
  283. >
  284. > [more problems when just checking the bit]
  285. >
  286.     There are two problems that you have to deal with...
  287.  
  288. 1) As you noted, the System's resource compression scheme is smart enough to 
  289. check more than just the compressed bit.  It knows about the format of a 
  290. compressed resource & will look at the header and validate it as REALLY being
  291. compressed.  Since the format for compressed resources is a) undocumented and
  292. b) guarenteed to change, you're SOL unless you want to reverse engineer it
  293. now and int he future.
  294.  
  295. 2) A number of companies are now offering developers (and in some cases users)
  296. resource compression tools in order to reduce the size of their applications.
  297. One of them (Alysis) uses Apple's scheme (and will break in the future), while 
  298. the other two (MindVision & Aladdin) have their own schemes and do NOT
  299. even set the compressed bit (since that is reserved for Apple).  So you would
  300. not be able to tell that those resources are compressed - unless you know 
  301. their headers too...
  302.  
  303.  
  304. - -- 
  305. - -----------------------------------------------------------------------
  306. Leonard Rosenthol          Internet: leonardr@ccs.itd.umich.edu
  307. Director of Advanced Technology   AppleLink: MACgician
  308. Aladdin Systems, inc.          GEnie:     MACgician
  309.  
  310. +++++++++++++++++++++++++++
  311.  
  312. From: darweesh@acsu.buffalo.edu (michael j darweesh)
  313. Date: 8 Jul 92 15:39:05 GMT
  314. Organization: UB
  315.  
  316. The resources ARE compressed, but the system calls used to access these
  317. resources transparently uncompress them for you. If the compressed bit is
  318. set, then the version of the resource actually in the file IS compressed
  319. and if you ask for a handle to it (perhaps via GetResource()), then
  320. the system will return a handle to an uncompresses version of that
  321. resource.
  322.  
  323. - -Mike
  324.  
  325. +++++++++++++++++++++++++++
  326.  
  327. From: Michael_Hecht@mac.sas.com (Michael Hecht)
  328. Date: 9 Jul 92 13:30:25 GMT
  329. Organization: SAS Institute Inc.
  330.  
  331. In article <Br2u56.L44@acsu.buffalo.edu>, darweesh@acsu.buffalo.edu
  332. (michael j darweesh) wrote:
  333. > The resources ARE compressed, but the system calls used to access these
  334. > resources transparently uncompress them for you.
  335.  
  336. I wish this were the case, but alas, it isn't.
  337.  
  338. I discovered the hard way that for compressed resources, SizeResource
  339. returns the uncompressed size, but GetResource returns the compressed
  340. resource data. It's left totally up to the calling application to compress
  341. and decompress the data. All the Resource Manager does for you is keep
  342. track of two different sizes.
  343.  
  344. My ResCompare program always said that compressed resources were different,
  345. because it was using the size returned by SizeResource to determine how
  346. much data to compare. I changed it to use the size returned by
  347. GetHandleSize after loading the resource, and now it works much better.
  348.  
  349. - --Michael
  350.  
  351. =======================================================================
  352. Michael P. Hecht                 | Internet:  Michael_Hecht@mac.sas.com
  353. SAS Institute Inc.; Cary, NC USA | AppleLink: SAS.HECHT
  354.  
  355. ---------------------------
  356.  
  357. From: sichase@csa2.lbl.gov (SCOTT I CHASE)
  358. Subject: Easy question (!?)
  359. Date: 8 Jul 92 03:18:07 GMT
  360. Organization: Lawrence Berkeley Laboratory - Berkeley, CA, USA
  361.  
  362. Hello all (especially bc, who I haven't seen since my days at The Tech),
  363.  
  364. Well, I just tried my first little toy program in Think C on my new IIci.
  365. Armed with my Think C manual (just about useless), six volumes of Inside
  366. Macintosh (incredible useful, but painfully expensive),  and my cat (worse 
  367. than useless, but doesn't cost much) I tried to write a simple program to catch
  368. events and show me what I caught.  I plan to use it as a shell for a background
  369. process to do some CPU-intensive stuff, i.e., do a little bit after catching
  370. each null event. 
  371.  
  372. My problem is that I am surprised to see that I am catching not only null
  373. events (event.what == 0) but also events with event.what == 15.  The 
  374. manual says that this is an application-defined code.  So I assume that
  375. I should never get one unless I am passing events around myself.  What's
  376. going on?  Thanks in advance for any pointers.  -Scott
  377.  
  378. So that there is no ambiguity, here is the offending code:
  379.  
  380. #include <stdlib.h>
  381. #include <stdio.h>
  382. #include <math.h>
  383. #include <console.h>
  384. main()
  385. {
  386. int        Col1 = 1, Row1 = 1;
  387. char        GotEvent;
  388. EventRecord myEvent;
  389. RgnHandle   cursorRgn;
  390. int        Sleep = 1;
  391. int        menu_ID;
  392. int        menu,item;
  393. int        QUIT = (2<<16) + 1;
  394.  
  395.     FlushEvents(everyEvent,0);
  396.     printf("Starting...\n");    /* initialize Toolbox Managers */
  397.         
  398.     while (1) {
  399.          GotEvent = WaitNextEvent(everyEvent, &myEvent, Sleep, cursorRgn);
  400.              switch(myEvent.what) {
  401.              case mouseDown:
  402.                  menu_ID = MenuSelect(myEvent.where);
  403.                 if (menu_ID == QUIT) ExitToShell();
  404.                 item    = menu_ID &  0xFFFF;
  405.                 menu    = menu_ID >>     16;
  406.                  printf("Menu Item Selected: Menu = %ld, Item = %ld\n",
  407.                          menu,item);
  408.                  break;
  409.             case 0:
  410.                 printf("GOT NULL EVENT\n");
  411.                 break;
  412.             default:
  413.                 printf("Unexpected Event Recorded: Type = %ld\n",myEvent.what);
  414.                 break;
  415.              }        
  416.           }                    
  417. }
  418.  
  419. - --------------------
  420. Scott I. Chase            "The question seems to be of such a character
  421. SICHASE@CSA2.LBL.GOV        that if I should come to life after my death
  422.                 and some mathematician were to tell me that it
  423.                 had been definitely settled, I think I would
  424.                 immediately drop dead again."      - Vandiver
  425.  
  426. +++++++++++++++++++++++++++
  427.  
  428. From: eric_gorr@coglab_psych.uoregon.edu (Eric Gorr)
  429. Organization: University of Oregon Network Services
  430. Date: Wed, 8 Jul 92 16:14:55 GMT
  431.  
  432.  
  433. I am not certain as to the answer, but what I found extremely useful
  434. when starting to program on the MAC was the Macintosh C Programming
  435. Primer, vol I & II.  (There is a second edition for Vol I which covers
  436. system 7.)  
  437.  
  438. I highly recommend the book.
  439.  
  440.  
  441.  
  442. In article <24450@dog.ee.lbl.gov>, sichase@csa2.lbl.gov (SCOTT I CHASE)
  443. writes:
  444. > Hello all (especially bc, who I haven't seen since my days at The Tech),
  445. > Well, I just tried my first little toy program in Think C on my new IIci.
  446. > Armed with my Think C manual (just about useless), six volumes of Inside
  447. > Macintosh (incredible useful, but painfully expensive),  and my cat (worse 
  448. > than useless, but doesn't cost much) I tried to write a simple program to catch
  449. > events and show me what I caught.  I plan to use it as a shell for a background
  450. > process to do some CPU-intensive stuff, i.e., do a little bit after catching
  451. > each null event. 
  452. > My problem is that I am surprised to see that I am catching not only null
  453. > events (event.what == 0) but also events with event.what == 15.  The 
  454. > manual says that this is an application-defined code.  So I assume that
  455. > I should never get one unless I am passing events around myself.  What's
  456. > going on?  Thanks in advance for any pointers.  -Scott
  457.  
  458.  
  459. +++++++++++++++++++++++++++
  460.  
  461. From: sichase@csa2.lbl.gov (SCOTT I CHASE)
  462. Date: 8 Jul 92 18:55:08 GMT
  463. Organization: Lawrence Berkeley Laboratory - Berkeley, CA, USA
  464.  
  465. Thanks to the many people who wrote to tell me that event 15 is no longer
  466. reserved for applications, but rather used my System 7 to generate 
  467. suspend/resume and mouseMoved events.  I have learned two lessons:
  468. (1) Always start with IM6 and work backwards.  The early volumes are full
  469. of outdated information, even though they cost me an arm and a leg.
  470. (2) The ThinkC debugger is probably handling my application in a way that
  471. generates the flurry of event 15's.  When run from the Finder, I am told
  472. that my program does not repeatedly generate the events in question.  I will
  473. have to check this when I get home tonight.
  474.  
  475. Thanks again to all who took the time to answer (and at least one person
  476. who actually compiled and ran my program!) 
  477.  
  478. - -Scott
  479.  
  480. - --------------------
  481. Scott I. Chase            "The question seems to be of such a character
  482. SICHASE@CSA2.LBL.GOV        that if I should come to life after my death
  483.                 and some mathematician were to tell me that it
  484.                 had been definitely settled, I think I would
  485.                 immediately drop dead again."      - Vandiver
  486.  
  487. +++++++++++++++++++++++++++
  488.  
  489. From: djpegg@utkvx4.utk.edu (PEGG, DAVID J)
  490. Organization: University of Tennessee Computing Center
  491. Date: Wed, 8 Jul 1992 21:57:00 GMT
  492.  
  493. In article <24450@dog.ee.lbl.gov>, sichase@csa2.lbl.gov writes...
  494. >My problem is that I am surprised to see that I am catching not only null
  495. >events (event.what == 0) but also events with event.what == 15.  The 
  496. >manual says that this is an application-defined code.  So I assume that
  497. >I should never get one unless I am passing events around myself.  What's
  498. >going on?
  499.  
  500. >From the Macintosh C Programming Primer, pg. 133:
  501. "osEvt (formerly known as app4Evt): The system will post an osEvt just before
  502. it moves your event into the background (suspends it) and just after it brings
  503. your application back to the foreground (resumes it).  You can also set your
  504. application up to receive mouseMoved events.mouseMoved events are posted when
  505. the user moves the cursor outside a predefined region (such as a text-editing
  506. window) or back in again.  When your application receives a mouseMoved event,
  507. it can change the cursor to one appropriate for that region."
  508.  
  509. The book refers me to IM V:249, but I don't have access to that volume. 
  510. However, I believe that _is_ event.what == 15.
  511.  
  512. Good luck,
  513.  -Michael Lewis
  514.  
  515. ---------------------------
  516.  
  517. From: engber@ils.nwu.edu (Mike Engber)
  518. Subject: creating/using 'styl' & 'TEXT' resources
  519. Organization: The Institute for the Learning Sciences
  520. Date: Wed, 8 Jul 1992 16:03:04 GMT
  521.  
  522. Here's a followup to the question someone asked about how
  523. to create the 'styl' resources to accompany your 'TEXT' resources.
  524. I assumed that this was well known - but he told me he got a lot
  525. of me too requests - so here's the method I've been successfully
  526. using (since yesterday).
  527.  
  528. There's an untested C function at the end if you want to skip
  529. the discussion (the code pretty much says it all).
  530.  
  531. I checked the Tech Notes and Q&A stack and didn't see this info
  532. anywhere - so this is all empirically determined. If anyone knows
  533. different please speak up.
  534.  
  535. At first I blindly saved the handle returned by GetStylHandle as the
  536. 'styl' resource. After crashing the machine and then thinking about it
  537. for a few seconds (like taking a look at the data structure I was
  538. saving) it became obvious that this was a ridiculous thing to try.
  539.  
  540. The secret seems to be use the calls GetStylScrap & SetStylScrap.
  541. GetStylScrap is documented in IM V and SetStylScrap in IM VI (I assume
  542. is was accidentally left out of V?) They're both discussed in Mac
  543. Revealed volume IV.
  544.  
  545. MacRevealed's discussion on p. 322 of how StyledTE puts items of
  546. type 'styl' on the clipboard is what tipped me off as to what to
  547. do. Chernicoff doesn't come right out and say it - my guess is
  548. because 'styl' resources weren't in widespread use at the time the
  549. book was written.
  550.  
  551. GetStylScrap returns you a handle that you can just pass to AddResource.
  552. GetStylScrap returns a new handle on every call - so you don't have to
  553. worry about making a copy lest you trash something your TERecord is
  554. still holding onto. The format of this handle is described in IM V
  555. p. 265-266 - but basically its a list of styles that get mapped onto
  556. your text.
  557.  
  558. Once you have a 'styl' resource you use SetStylScrap to apply it
  559. to your text (which is already installed in your TERec).
  560.  
  561. I assume it's obvious how to deal with the 'TEXT' resources. If not
  562. I can elaborate. One possible gottcha is to forget that TextEdit
  563. still has a hold of the hText handle and will DisposeHandle on it
  564. when you TEDispose. So you don't want to blindly pass the the hText
  565. handle to AddResource (make a copy - or remove it from the
  566. TERec - replacing it with a dummy handle)
  567.  
  568. The ResEdit 'styl' editor expects a 'TEXT' resource and its asscociated
  569. 'styl' resource to have the same rsrc id. Sounds like a good convention
  570. to me. But there is nothing to keep you from violating it - except you
  571. won't be able to edit your resource with ResEdit.
  572.  
  573. In summary - the ToolBox call I wanted, but which doesn't exist would
  574. be something like: (if the ToolBox followed C conventions)
  575.  
  576. - - warning - completely untested code to follow -
  577.  
  578. TEHandle GetTEStylNew(short id,Rect* destRect,Rect* viewRect){
  579.  Handle   textHandle = GetResource('TEXT',id);
  580.  Handle   stylHandle = GetResource('styl',id);
  581.  TEHandle hTE        = NULL;
  582.  
  583.  if(textHandle){
  584.    hTE = TEStylNew(destRect,viewRect);
  585.    HLock(textHandle);
  586.    TESetText(*hTE,GetHandleSize(hTE),hTE);
  587.    HUnlock(textHandle);
  588.    ReleaseResource(textHandle);
  589.    if(stylHandle){
  590.      SetStylScrap(0,(*hTE)->teLength,stylHandle,false,hTE);
  591.      ReleaseResource(stylHandle);
  592.    }
  593.  }
  594.  return hTE;
  595. }
  596.  
  597. Using this approach, copies of the 'TEXT' and 'styl' data are installed
  598. in the new TEHandle. This means that saving will require you to first
  599. remove any existiong 'styl' and 'TEXT' resources and then use
  600. AddResource with the 2 new handles.
  601.  
  602. Yes, it would be possible to install the original 'TEXT' resource
  603. handle into the TERec (rather than copying the the text in with
  604. TESetText) - This would mean your TERec would be directly editing
  605. the 'TEXT' resource (& you wouldn't have to go through the remove and
  606. add process to save changes to it). But there is no way to accomplish
  607. an analogous thing for the 'styl' resoruce - so I thought it best to
  608. treat them both consistently.
  609.  
  610. - -ME
  611.  
  612. +++++++++++++++++++++++++++
  613.  
  614. From: Michael_Hecht@mac.sas.com (Michael Hecht)
  615. Date: Thu, 9 Jul 1992 14:07:58 GMT
  616. Organization: SAS Institute Inc.
  617.  
  618. In article <1992Jul8.160304.19393@ils.nwu.edu>, engber@ils.nwu.edu (Mike
  619. Engber) wrote:
  620. > I checked the Tech Notes and Q&A stack and didn't see this info
  621. > anywhere - so this is all empirically determined. If anyone knows
  622. > different please speak up.
  623.  
  624. There's documentation in Q&A Stack 4.1: Toolbox & IAC: TextEdit: 12/19/90:
  625. Saving and restoring styled TextEdit records. (I found this using the
  626. Developer Info Assistant's "Search" card, looking for "TextEdit" and
  627. "style". Just thought you'd want to know!)
  628.  
  629. > The secret seems to be use the calls GetStylScrap & SetStylScrap.
  630. > GetStylScrap is documented in IM V and SetStylScrap in IM VI (I assume
  631. > is was accidentally left out of V?)
  632.  
  633. IM V predates SetStylScrap. It was first documented in TN #207, Styled
  634. TextEdit changes in System 6.0, which is where most of the IM VI
  635. information comes from. Reading this is a must if you plan to implement
  636. your own styled text editor using TextEdit. It greatly simplifies applying
  637. stylistic changes to the text.
  638.  
  639. You might also want to look at TEStylInsert, which *is* documented in IM V
  640. (right under the documentation for GetStylScrap, actually :-). It is, I
  641. think, easier to use than SetStylScrap in this situation, since it will
  642. insert both the text *and* the styles in one easy step.
  643.  
  644. In other words, this:
  645.  
  646. >    HLock(textHandle);
  647. >    TESetText(*textHandle /*sic*/,GetHandleSize(textHandle /*sic*/),hTE);
  648. >    HUnlock(textHandle);
  649. >    ReleaseResource(textHandle);
  650. >    if(stylHandle){
  651. >      SetStylScrap(0,(*hTE)->teLength,stylHandle,false,hTE);
  652. >      ReleaseResource(stylHandle);
  653. >    }
  654.  
  655. becomes this:
  656.  
  657.      HLock( textHandle );
  658.      TEStylInsert( *textHandle, GetHandleSize( textHandle ), stylHandle,
  659. hTE );
  660.      HUnlock( textHandle );
  661.  
  662.      ReleaseResource( textHandle );
  663.      ReleaseResource( stylHandle );
  664.  
  665. Note: According to IM V, "when [stylHandle] is NIL and/or hTE has not been
  666. created using TEStylNew, there is no difference between [TEStylInsert] and
  667. TEInsert."
  668.  
  669. If anyone wants some simple code for displaying styled text in a scrolling
  670. field of a dialog, let me know. It's great for help and info messages that
  671. you can edit with ResEdit!
  672.  
  673. > The ResEdit 'styl' editor expects a 'TEXT' resource and its asscociated
  674. > 'styl' resource to have the same rsrc id. Sounds like a good convention
  675. > to me. But there is nothing to keep you from violating it - except you
  676. > won't be able to edit your resource with ResEdit.
  677.  
  678. This is a good convention. The answer in the Q&A stack also suggests saving
  679. the 'TEXT' part of the record as the data fork of a normal TEXT file, and
  680. saving the 'styl' part as a 'styl' resource in the same file ('styl' 128?).
  681. That way, other text editing apps can read it, whether they support styled
  682. text or not.
  683.  
  684. - --Michael
  685.  
  686. =======================================================================
  687. Michael P. Hecht                 | Internet:  Michael_Hecht@mac.sas.com
  688. SAS Institute Inc.; Cary, NC USA | AppleLink: SAS.HECHT
  689.  
  690. ---------------------------
  691.  
  692. From: mike@optimla.aimla.com (Mike Diehr)
  693. Subject: Powerbook 100 Roms
  694. Organization: Philips Interactive Media
  695. Date: Wed, 8 Jul 92 17:42:32 GMT
  696.  
  697.  
  698. What sort of roms does the PB 100 have?  Specifically, I'm wondering
  699. if I can do any Quicktime programming in think C.  Obviously, I 
  700. won't have color.  But will Quicktime run at all in B/W?
  701.  
  702. Also, are the roms 32 bit clean?
  703.  
  704.  
  705. +++++++++++++++++++++++++++
  706.  
  707. From: Quinn <quinn@cs.uwa.edu.au>
  708. Organization: The University of Western Australia
  709. Date: Thu, 9 Jul 1992 06:26:11 GMT
  710.  
  711. In article <1992Jul8.174232.8140@aimla.com> Mike Diehr,
  712. mike@optimla.aimla.com writes:
  713. >What sort of roms does the PB 100 have?
  714.  
  715. The same as the Macintosh Portable.
  716.  
  717. >Specifically, I'm wondering if I can do any Quicktime programming in
  718. think
  719. >C.  Obviously, I won't have color.  But will Quicktime run at all in B/W?
  720.  
  721. QuickTime (at the moment) requires an 68020 or better.  The PB100
  722. has a 68000.  Bad luck!  Rumours of a later version that runs on
  723. 68000s abound but it is not yet released.
  724.  
  725. >Also, are the roms 32 bit clean?
  726.  
  727. Mu.  The question of 32 bit cleaness is invalid on the 68000 which
  728. only has 24 address lines (which is where the 24 bit problem
  729. originates).
  730.  
  731. Quinn "The Eskimo!"   <quinn@cs.uwa.edu.au>  "Real Coke, Diet .sig"
  732. Department of Computer Science, The University of Western Australia
  733.   -- World's proudest PB100 owner (-:
  734.  
  735. ---------------------------
  736.  
  737. From: stickler@utrio.helsinki.fi (Patrick Stickler)
  738. Subject: Perl under MPW??
  739. Date: 8 Jul 92 12:41:50 GMT
  740. Organization: University of Helsinki, Finland
  741.  
  742. Does anyone know if Perl has been ported to the Mac under MPW. Would
  743. this even be feasable? Any info would be much appreciated.
  744.  
  745. Please reply via email. Thanks.
  746.  
  747.  
  748. //////////////////////////////////////////////////////////////////////////
  749.        Patrick Stickler             WSOY, Information Systems Division
  750.     stickler@cc.helsinki.fi           Bulevardi 12, Helsinki FINLAND
  751.       (+358 0) 4020 366                      (+ 358 0) 61681
  752. ==========================================================================
  753.         The comments contained herein cannot reflect the official
  754.            views of my employer.  (proof left for the reader)
  755. //////////////////////////////////////////////////////////////////////////
  756.  
  757. - -- 
  758.  
  759. +++++++++++++++++++++++++++
  760.  
  761. From: major@bbn.com (John Major)
  762. Date: 9 Jul 92 16:09:06 GMT
  763. Organization: Bolt Beranek and Newman Inc., Cambridge MA
  764.  
  765.  
  766. There is an excellent port of Perl done by Matthias Neeracher
  767. on WUARCHIVE.WUSTL.EDU, in mirrors2/rascal.../programming (the
  768. original was on rascal... but was moved to WUARCHIVE because
  769. of disk space limitations).
  770.  
  771. Good luck -
  772.  
  773. John Major
  774. major@bbn.com
  775. ALINK:D6590
  776. 617/873-8165
  777.  
  778. ---------------------------
  779.  
  780. From: pbrande1@cc.swarthmore.edu (Philip Brandenberger)
  781. Subject: windowKind usage, the RIGHT way to do it...
  782. Organization: Swarthmore College
  783. Date: Thu, 9 Jul 1992 16:15:30 GMT
  784.  
  785. leonardr@ccs.itd.umich.edu writes:
  786. > In article <Br3u8z.BCH@news.cso.uiuc.edu> s-dorner@uiuc.edu (Steve Dorner) writes:
  787. > >
  788. > >A certain screensaver which I do not care to name (it's part of a
  789. > >commercial security package) does its thing by creating a window in
  790. > >the frontmost application's heap
  791.  
  792. > [Stuff deleted....]
  793.  
  794. > >Does this strike anyone else as incredibly hostile behavior?
  795. > >
  796. >     Putting a window into someone else's layer is an evil thing in its
  797. > own right,
  798.  
  799. > [Stuff Deleted....]
  800.  
  801. >     Actually if they are going to continue to put things into application's
  802. > layers, then at least use negative IDs which are reserved for things like
  803. > DA's and system windows.
  804.  
  805. Alright, how does one avoid adding a window to the (front of the) 
  806. foreground app's windowlist?  My impression is that nearly all screensavers
  807. do, partly because the other approach, that is recalcing the visRgn's
  808. of windows doesn't really work for the Finder's desktop, which will either
  809. "bleed through" (if you don't call empty the GrayRgn) or cause icon
  810. positions will sometimes be recalculated because the size of the 
  811. GrayRgn has changed.
  812.  
  813. Comments?
  814.  
  815. - -Phil
  816.  
  817. - -- 
  818. Philip J. Brandenberger
  819. Swarthmore College, but I don't speak for it, in fact usually against it.
  820. pbrande1@cc.swarthmore.edu
  821.  
  822. +++++++++++++++++++++++++++
  823.  
  824. From: leonardr@ccs.itd.umich.edu
  825. Date: 9 Jul 92 17:47:53 GMT
  826. Organization: Campus Computing Sites, University of Michigan-Ann Arbor
  827.  
  828. In article <WMJMBS0Z@cc.swarthmore.edu> pbrande1@cc.swarthmore.edu (Philip Brandenberger) writes:
  829. >leonardr@ccs.itd.umich.edu writes:
  830. >> In article <Br3u8z.BCH@news.cso.uiuc.edu> s-dorner@uiuc.edu (Steve Dorner) writes:
  831. >> >
  832. >> >A certain screensaver which I do not care to name (it's part of a
  833. >> >commercial security package) does its thing by creating a window in
  834. >> >the frontmost application's heap
  835. >
  836. >> [Stuff deleted....]
  837. >
  838. >> >Does this strike anyone else as incredibly hostile behavior?
  839. >> >
  840. >>     Putting a window into someone else's layer is an evil thing in its
  841. >> own right,
  842. >
  843. >> [Stuff Deleted....]
  844. >
  845. >>     Actually if they are going to continue to put things into application's
  846. >> layers, then at least use negative IDs which are reserved for things like
  847. >> DA's and system windows.
  848. >
  849. >Alright, how does one avoid adding a window to the (front of the) 
  850. >foreground app's windowlist?  My impression is that nearly all screensavers
  851. >do, partly because the other approach, that is recalcing the visRgn's
  852. >of windows doesn't really work for the Finder's desktop, which will either
  853. >"bleed through" (if you don't call empty the GrayRgn) or cause icon
  854. >positions will sometimes be recalculated because the size of the 
  855. >GrayRgn has changed.
  856. >
  857.     There are three common approaches to writing a screensaver - the 
  858. System 7 way, the After Dark way and the easy way.
  859.  
  860.     The easy way (and the most incompatible) is to do what is described
  861. above and simply put a whole new window up in whatever layer happens to be 
  862. current at the time that the screen saver needs to kick in.  This will work
  863. under both 6 & 7, but since the Sys6 Process Manager is undocumented, you
  864. have to do this - under Sys7, you do what Darkside does (or I assume it does,
  865. Tom??) and switch yourself to the frontProcess and THEN bring up a window in
  866. your own process.
  867.  
  868.     What After Dark does is to patch out the world, in this case the global
  869. QDBottlenecks, and when the screen saver is active, make all drawing that 
  870. intersects with the screen the equivalent of a NOP (it does allow drawing
  871. into offscreens ;).  I believe the QT/Sunset uses a similar approach.
  872.  
  873.     
  874. - -- 
  875. - -----------------------------------------------------------------------
  876. Leonard Rosenthol          Internet: leonardr@ccs.itd.umich.edu
  877. Director of Advanced Technology   AppleLink: MACgician
  878. Aladdin Systems, inc.          GEnie:     MACgician
  879.  
  880. ---------------------------
  881.  
  882. From: d88-jwa@dront.nada.kth.se (Jon W{tte)
  883. Subject: member() bug SOLVED (I hope)
  884. Date: 9 Jul 92 18:30:34 GMT
  885. Organization: Royal Institute of Technology, Stockholm, Sweden
  886.  
  887.  
  888. I recently got mail from Symantec tech support. It turns
  889. out that if you use 4 byte ints, but don't turn on far code
  890. or data, the declaration for member() in oops.h is faulty.
  891. Turning off 4byte ints, or changing oops.h fixes the bug
  892. (this bug is in 1.1.2 so it has to be recently discovered)
  893.  
  894. change:
  895.  
  896. char __member(...);
  897.  
  898. should be:
  899.  
  900. #if __option(far_code) || __option(far_data)
  901. char __member(void *, void*);
  902. #else
  903. char __member(void *, short);
  904. #endif
  905.  
  906.  
  907. Yahoo ! (Of course, haven't tried it yet, but it looks like
  908. this is the problem)
  909.  
  910. - -- 
  911.          Jon W{tte, Svartmangatan 18, S-111 29 Stockholm, Sweden
  912.  
  913. ### You have the Easy Access virus. This virus may cause strange sounds
  914. ### and weird keyboard behaviour when you press the shift key repeatedly.
  915.  
  916. +++++++++++++++++++++++++++
  917.  
  918. From: d88-jwa@cyklop.nada.kth.se (Jon W{tte)
  919. Organization: Royal Institute of Technology, Stockholm, Sweden
  920. Date: Thu, 9 Jul 1992 23:19:19 GMT
  921.  
  922. > d88-jwa@dront.nada.kth.se (Jon W{tte) writes:
  923.  
  924.    I recently got mail from Symantec tech support. It turns
  925.    out that if you use 4 byte ints, but don't turn on far code
  926.    or data, the declaration for member() in oops.h is faulty.
  927.  
  928. This is correct.
  929.  
  930.    Turning off 4byte ints, or changing oops.h fixes the bug
  931.    (this bug is in 1.1.2 so it has to be recently discovered)
  932.  
  933. This is not - IT DIDN'T FIX MY BUG !
  934.  
  935. I've tried to help a lot of people here, so I hope I'll
  936. get some help back. I'm at a dead end. AUGH ! (I'm writing my
  937. own class library just to get around this - I DON'T WANT TO)
  938.  
  939. - -- 
  940.          Jon W{tte, Svartmangatan 18, S-111 29 Stockholm, Sweden
  941.  
  942. ### You have the Easy Access virus. This virus may cause strange sounds
  943. ### and weird keyboard behaviour when you press the shift key repeatedly.
  944.  
  945. ---------------------------
  946.  
  947. End of C.S.M.P. Digest
  948. **********************
  949.