home *** CD-ROM | disk | FTP | other *** search
/ ftp.mactech.com 2010 / ftp.mactech.com.tar / ftp.mactech.com / csmpdigest / csmp-digest-v3-048 < prev    next >
Internet Message Format  |  2010-09-21  |  40KB

  1. From: pottier@clipper.ens.fr (Francois Pottier)
  2. Subject: no subject (file transmission)
  3. To: Scott.M.Silver@Dartmouth.EDU
  4. Date: Wed, 31 Aug 1994 14:49:20 +0200 (MET DST)
  5. X-Mailer: ELM [version 2.4 PL23]
  6. Mime-Version: 1.0
  7. Content-Type: text/plain; charset=ISO-8859-1
  8. Content-Transfer-Encoding: 8bit
  9.  
  10.  
  11. C.S.M.P. Digest             Thu, 28 Jul 94       Volume 3 : Issue 48
  12.  
  13. Today's Topics:
  14.  
  15.         Color in System 7 popups?
  16.         Controlling Apple MultiSync Monitors
  17.         Drag Mgr problem w- flavorTypePromiseHFS
  18.         GWorlds and other questions - Help
  19.         PBControl() "hangs" the Macintosh
  20.         Patching the GetResource() toolbox routine
  21.  
  22.  
  23.  
  24. The Comp.Sys.Mac.Programmer Digest is moderated by Francois Pottier
  25. (pottier@clipper.ens.fr).
  26.  
  27. The digest is a collection of article threads from the internet newsgroup
  28. comp.sys.mac.programmer.  It is designed for people who read c.s.m.p. semi-
  29. regularly and want an archive of the discussions.  If you don't know what a
  30. newsgroup is, you probably don't have access to it.  Ask your systems
  31. administrator(s) for details.  If you don't have access to news, you may
  32. still be able to post messages to the group by using a mail server like
  33. anon.penet.fi (mail help@anon.penet.fi for more information).
  34.  
  35. Each issue of the digest contains one or more sets of articles (called
  36. threads), with each set corresponding to a 'discussion' of a particular
  37. subject.  The articles are not edited; all articles included in this digest
  38. are in their original posted form (as received by our news server at
  39. nef.ens.fr).  Article threads are not added to the digest until the last
  40. article added to the thread is at least two weeks old (this is to ensure that
  41. the thread is dead before adding it to the digest).  Article threads that
  42. consist of only one message are generally not included in the digest.
  43.  
  44. The digest is officially distributed by two means, by email and ftp.
  45.  
  46. If you want to receive the digest by mail, send email to listserv@ens.fr
  47. with no subject and one of the following commands as body:
  48.     help                        Sends you a summary of commands
  49.     subscribe csmp-digest Your Name    Adds you to the mailing list
  50.     signoff csmp-digest            Removes you from the list
  51. Once you have subscribed, you will automatically receive each new
  52. issue as it is created.
  53.  
  54. The official ftp info is //ftp.dartmouth.edu/pub/csmp-digest.
  55. Questions related to the ftp site should be directed to
  56. scott.silver@dartmouth.edu. Currently no previous volumes of the CSMP
  57. digest are available there.
  58.  
  59. Also, the digests are available to WAIS users.  To search back issues
  60. with WAIS, use comp.sys.mac.programmer.src. With Mosaic, use
  61. http://www.wais.com/wais-dbs/comp.sys.mac.programmer.html.
  62.  
  63.  
  64. -------------------------------------------------------
  65.  
  66. From summeral@benji.Colorado.EDU (Summerall  Thomas G)
  67. Subject: Color in System 7 popups?
  68. Date: Tue, 5 Jul 1994 23:13:04 GMT
  69. Organization: University of Colorado, Boulder
  70.  
  71. This is probably a common question, so I apologize in advance.
  72.  
  73. Can the standard system 7 popup cdef use colored menu items?  If so, how?  It
  74. doesn't seem to recognize mctb resources associated with the menu I'm
  75. adding.  What am I missing here?  If it isn't a feature of system 7, is
  76. there a public domain library that can accomplish this?
  77.  
  78. Thanks,
  79.  
  80. Tom Summerall
  81.  
  82.  
  83. +++++++++++++++++++++++++++
  84.  
  85. From ari@world.std.com (Ari I Halberstadt)
  86. Date: Wed, 13 Jul 1994 01:59:45 GMT
  87. Organization: The World Public Access UNIX, Brookline, MA
  88.  
  89. In article <summeral.773449984@benji.Colorado.EDU>,
  90. Summerall  Thomas G <summeral@benji.Colorado.EDU> wrote:
  91. >This is probably a common question, so I apologize in advance.
  92. >
  93. >Can the standard system 7 popup cdef use colored menu items?  If so, how?  It
  94. >doesn't seem to recognize mctb resources associated with the menu I'm
  95. >adding.  What am I missing here?  If it isn't a feature of system 7, is
  96. >there a public domain library that can accomplish this?
  97.  
  98. Soon there will be a free CDEF that supports color. My popup CDEF
  99. already does most of what you might wan, but its current version
  100. (1.0b3) doesn't work in color grafports. I'm adding color support
  101. right now, and it should be ready within a week or two. There are
  102. still some bugs (visual appearance things, not crashing) that may
  103. require another release or two before I finally discover the magical
  104. solution. The system 7 CDEF seemed to crash when I added a mctb
  105. resource and tried to display the menu's title. I'm also thinking of
  106. adding coloration using an auxillary control color resource, with part
  107. codes for the text, outline, down arrow, etc. of the control.
  108.  
  109. While on this topic, the width of my CDEF is perfect when run on a
  110. macplus. That is, when the menu is displayed, its width is enlarged to
  111. cover the down arrow and the margins around the menu. But on a Quadra,
  112. the width isn't enlarged, it just is set to the actual width of the
  113. menu. Just before calling PopupMenuSelect I set the menuWidth field of
  114. the menu handle to the desired width, but on the color machine the
  115. width I specify is just being ignored. Does anyone know of some
  116. magical workaround to this problem?
  117. -- 
  118. Ari Halberstadt                                 ari@world.std.com
  119. One generation passes away, and another generation comes: but the
  120. earth abides for ever. -- Ecclesiastes, 1:4.
  121.  
  122. +++++++++++++++++++++++++++
  123.  
  124. From leonardr@netcom.com (Leonard Rosenthol)
  125. Date: Wed, 13 Jul 1994 21:47:09 GMT
  126. Organization: Aladdin Systems, Inc.
  127.  
  128. In article <Csuw7L.GIn@world.std.com>, ari@world.std.com (Ari I
  129. Halberstadt) wrote:
  130.  
  131. > While on this topic, the width of my CDEF is perfect when run on a
  132. > macplus. That is, when the menu is displayed, its width is enlarged to
  133. > cover the down arrow and the margins around the menu. But on a Quadra,
  134. > the width isn't enlarged, it just is set to the actual width of the
  135. > menu. Just before calling PopupMenuSelect I set the menuWidth field of
  136. > the menu handle to the desired width, but on the color machine the
  137. > width I specify is just being ignored. Does anyone know of some
  138. > magical workaround to this problem?
  139. >
  140.    The problem/situation is that PopupMenuSelect() will call CalcMenuWidth
  141. on the menu before the menu gets drawn and so the MDEF will recalc the
  142. size w/o the arrow :(.   The standard solution to this is to create a
  143. "stub" MDEF which knows to resize the width on a calc message.  If you
  144. need a code sample, let me know.
  145.  
  146.  
  147. Leonard
  148. - ------------------------------------------------------------------------
  149. Leonard Rosenthol                      Internet:       leonardr@netcom.com
  150. Director of Advanced Technology        AppleLink:      MACgician
  151. Aladdin Systems, Inc.                  GEnie:          MACgician
  152.  
  153. ---------------------------
  154.  
  155. From tgaul@halcyon.com (Troy Gaul)
  156. Subject: Controlling Apple MultiSync Monitors
  157. Date: Fri, 08 Jul 1994 22:57:23 -0700
  158. Organization: Infinity Systems
  159.  
  160. Is there an API that can be used to determine when the resolution of a
  161. MultiSync monitor changes?  Obviously, one could walk the GDevices when
  162. returning from being switched into the foreground, or checked during idle
  163. time, but is there any other way to find out immediately?
  164.  
  165. On a related note, is there any way to force a change of resolution via a
  166. call (or a driver Control call)?  I'm considering an extension that would
  167. facilitate changing monitor resolutions, but I haven't been able to find
  168. the developer notes for MultiSync monitors.
  169.  
  170. Thanks,
  171. _troy
  172. //////// //////___Troy Gaul____________________tgaul@halcyon.com___//
  173.   //    //      Infinity Systems                                  //
  174.  //    //  //  Redmond, Washington                               //
  175. //    //////____________________________________________________//
  176.  
  177. +++++++++++++++++++++++++++
  178.  
  179. From Dave Falkenburg <falken@apple.com>
  180. Date: Wed, 13 Jul 1994 18:40:06 GMT
  181. Organization: Apple Computer, Inc.
  182.  
  183. In article <tgaul-0807942257230001@bellevue-ip88.halcyon.com> Troy Gaul,
  184. tgaul@halcyon.com writes:
  185. >Is there an API that can be used to determine when the resolution of a
  186. >MultiSync monitor changes?  Obviously, one could walk the GDevices when
  187. >returning from being switched into the foreground, or checked during idle
  188. >time, but is there any other way to find out immediately?
  189.  
  190. Yes, but somehow nobody wrote any tech notes yet.
  191. The API is defined in <Displays.h>, but is cryptic at best.
  192.  
  193. The Display Manager allows an application to install an AppleEvent
  194. handler to detect when a display has been changed (e.g., a new display
  195. has come online because you've docked a Duo, or you change the resolution
  196. of a multisynch monitor via the monitors control panel).
  197.  
  198. BTW: Extensions can supply a callback function instead of relying on an
  199. AppleEvent.
  200.  
  201. In order to receive this AppleEvent, you must set the displayManagerAware
  202. bit in your size resource, and install an AppleEvent Handler for
  203. kCoreEventClass,kSystemConfigNotice (or something like that).
  204.  
  205. NOTE: If you choose to become "display manager aware", you must also be
  206. prepared to deal with the change in displays and keep your windows
  207. onscreen.
  208.  
  209. This is just screaming for a tech note, some sample code, and a develop
  210. or MacTech magazine article.
  211.  
  212. -Dave Falkenburg
  213. -Apple Computer, Inc.
  214.  
  215. +++++++++++++++++++++++++++
  216.  
  217. From Dave Falkenburg <falken@apple.com>
  218. Date: Wed, 13 Jul 1994 18:43:25 GMT
  219. Organization: Apple Computer, Inc.
  220.  
  221. In article <tgaul-0807942257230001@bellevue-ip88.halcyon.com> Troy Gaul,
  222. tgaul@halcyon.com writes:
  223. >On a related note, is there any way to force a change of resolution via a
  224. >call (or a driver Control call)?  I'm considering an extension that would
  225. >facilitate changing monitor resolutions, but I haven't been able to find
  226. >the developer notes for MultiSync monitors.
  227.  
  228. Oops.  Forgot to mention that all you really need to do this is a special
  229. video adapter cable. I have an NEC 6FG & their "PowerMac" video cable
  230. adpater which converts the Mac's video cable into that industry standard
  231. SVGA type connector.
  232.  
  233. Under System 7.1.2 on a PowerMac, or System 7.5 on most other recent
  234. machines with built in video, all you need to do is go to the Monitors
  235. control panel to swich resolutions.
  236.  
  237. -Dave Falkenburg
  238. -Apple Computer, Inc.
  239.  
  240. ---------------------------
  241.  
  242. From ron@mcs.com (Ron Schneider)
  243. Subject: Drag Mgr problem w- flavorTypePromiseHFS
  244. Date: Tue, 12 Jul 1994 22:36:36 -0600
  245. Organization: Just a guy...
  246.  
  247.  
  248. I'm playing with the drag manager, and have incorporated it into my app. 
  249. Everything works fine, all my handlers are called, I'm dragging text
  250. between apps, sounds, creating clipping flies, etc.  Most cool.
  251.  
  252. But I can't get flavorTypePromiseHFS to work.  As I'm dragging around, the
  253. Finder correctly hilites applications that accept the file type I specified
  254. in the PromiseHFSFlavor struct, and my DragSendDataProc is called back at
  255. the correct time to return the FSSpec of the created file.  But nothing
  256. ever happens!  The TrackDrag routine returns noErr.  I have AppleEvents
  257. turned on, DragPeek returns the expected results, System 7.1 w/ the
  258. DragManager, Clipping Extension, etc all installed and working.  I am
  259. reduced to random changes hoping to stumble onto the solution.  Here are
  260. some questions I have come up with.
  261.  
  262. 1.  Are there any examples in the universe that show the 'phfs' flavor in
  263. use?  Or anywhere in the finder that uses it so I could use DragPeek to
  264. look at what is happening?
  265.  
  266. 2.  The doc says (I love online docs!) 'This structure (PromiseHFSFlavor)
  267. allows you to create the file in your DragSendDataProc, and provide the
  268. FSSpec for the new file at that time.'  What does this really mean?  In the
  269. DragSendDataProc do I specify a completed HFSFlavor, or a completed FSSpec,
  270. or maybe an alias like all the AppleEvent stuff?  I have tried all, same
  271. non-results.
  272.  
  273. 3. I have noticed the Finder trims its FSSpecs in the 'hfs ' flavors to the
  274. minimum length, whereas it is easier for me to pass sizeof( HFSFlavor ) or
  275. sizeof( FSSpec ), since the filename length is in the structure anyway. 
  276. Does it matter?  (I have tried both).
  277.  
  278. Thanks for any help, suggestions, sympathy, or pointers that you can offer!
  279.  
  280. -- 
  281.  
  282. ron schneider
  283. ron@mcs.com, ron@odesta.com
  284. .sig under construction
  285.  
  286. +++++++++++++++++++++++++++
  287.  
  288. From leonardr@netcom.com (Leonard Rosenthol)
  289. Date: Wed, 13 Jul 1994 21:53:32 GMT
  290. Organization: Aladdin Systems, Inc.
  291.  
  292. In article <ron-120794223636@ron.pr.mcs.net>, ron@mcs.com (Ron Schneider) wrote:
  293.  
  294. > 1.  Are there any examples in the universe that show the 'phfs' flavor in
  295. > use?  Or anywhere in the finder that uses it so I could use DragPeek to
  296. > look at what is happening?
  297.    I believe that the HFS sample app in the Mac Drag & Drop folder on the
  298. Mozart beta CD (and therefore the WWDC CD) shows what you need to know
  299. about using promise HFS flavors.
  300.  
  301.  
  302.    Here is some "sample" code that should show what how to deal with
  303. promiseHFS flavors in your sendProc.  This code will definitely not
  304. compile as is (it's missing var & function declarations but shows the
  305. important stuff!
  306.  
  307.  
  308. Leonard
  309. - ----------
  310. pascal OSErr SampleSendDataProc(FlavorType theType, void *refCon,
  311. ItemReference theItem, DragReference theDrag)
  312. {  
  313.    OSErr       result = noErr;
  314.    AEDesc         dropLoc, specDesc;
  315.    FSSpec         myFSSpec;
  316.    long        dataSize;
  317.    short       tempVRef;
  318.    long        tempDirID;
  319.  
  320.    if (theType == flavorTypePromiseSample) {
  321.       if (!GetDropLocation(theDrag, &dropLoc)) {
  322.          
  323.          if(!GetDropLocationDirectory(&dropLoc, &defdir, &defvol)) {
  324.             
  325.             dataSize = sizeof(sampleFlavorRec);
  326.             if (result = GetFlavorData(theDrag, theItem, flavorTypeSample,
  327. &mySFRec, &dataSize, 0L))
  328.                goto out;
  329.             
  330.             result = FindFolder(defvol, kTrashFolderType,
  331. kDontCreateFolder, &tempVRef, &tempDirID);
  332.  
  333.             // Check if the destination is the trash - if so delete
  334.             if ((tempVRef == defvol) && (tempDirID == defdir)) {
  335.                if(firstPromise)
  336.                   DeleteIt();
  337.             } else {
  338.                // you9ve been grabbed - do something with the it!!!
  339.                if(!abort) {
  340.                   myFSSpec.vRefNum = defvol;
  341.                   myFSSpec.parID = defdir;
  342.                   NameCopy(string,myFSSpec.name);
  343.  
  344.                   result =
  345. SetDragItemFlavorData(theDrag,theItem,flavorTypePromiseSample,
  346.                                  &myFSSpec,sizeof(FSSpec),0);
  347.                }
  348.                   
  349.             }
  350.             firstPromise = FALSE;
  351.             
  352.          }
  353.       }
  354.       
  355.    } else {
  356.       return(cantGetFlavorErr);
  357.    }
  358.  
  359. out:
  360.  
  361.    return(result ? cantGetFlavorErr : noErr);
  362. }
  363. - ------------------------------------------------------------------------
  364. Leonard Rosenthol                      Internet:       leonardr@netcom.com
  365. Director of Advanced Technology        AppleLink:      MACgician
  366. Aladdin Systems, Inc.                  GEnie:          MACgician
  367.  
  368. ---------------------------
  369.  
  370. From cconstan@epdiv1.env.gov.bc.ca (Carl B. Constantine)
  371. Subject: GWorlds and other questions - Help
  372. Date: Wed, 13 Jul 1994 07:59:52 -0700
  373. Organization: Ministry of Environment, Lands & Parks
  374.  
  375. It seems, no matter how much material I read on GWorlds & CopyBits, et.
  376. al, it doesn't answer some of my main questions.  So I humbly turn to the
  377. experts on the net for your guided support and help.
  378.  
  379. 1)  IM IV says to set RGBForeColor to White and RGBBackColor to Black
  380. before using CopyBits to avoid colorization.  That's great, but I've seen
  381. many examples where people don't do this.  My question is, do you have to
  382. do it for Color GWorlds?
  383.  
  384. 2) I've seen alot about rowBytes and BaseAddr values for PixMaps/BitMaps. 
  385. How you have to set it to long word aligned for fastest copying.  If you
  386. use NewGWorld to create your offscreen port (as opposed to OpenCPort), do
  387. you still need to set these values or does NewGWorld do it for you?
  388.  
  389. 3) Develop 17 (ftp'd from ftp.apple.com) mentions in Brigham Stevens'
  390. article "Ten Tips for Game Developers" to use CopyBits with a mask region
  391. instead of CopyMask or CopyDeepMask because it's faster. OK, but how do I
  392. convert my mask (sitting in a GWorld called maskWorld) to a region.  I
  393. haven't seen any good examples of the use of BitMapToRgn anywhere (I did
  394. look, but got more confused. IM didn't explain how to use this at all and
  395. neither did THINK Reference)
  396.  
  397. 4) Can GetGWorld and SetGWorld be used instead of GetPort and SetPort when
  398. using offscreen GWorlds?
  399.  
  400. 5) I can't seem to find the TechNote anymore called, Out of This GWorld. 
  401. Can someone tell me where to get it (prefereablly in DocViewer Format).
  402.  
  403. Thanks for all your help.
  404.  
  405. Signed,
  406.  
  407. Dazed and Confused.
  408.  
  409. -- 
  410. ========================================================================
  411. Carl B. Constantine                  B.C. Environment, Lands & Parks
  412. End-User Support Analyst             CCONSTAN@epdiv1.env.gov.bc.ca
  413.  
  414. +++++++++++++++++++++++++++
  415.  
  416. From giles@med.cornell.edu (Aaron Giles)
  417. Date: 13 Jul 1994 17:11:37 GMT
  418. Organization: Cornell University Medical College
  419.  
  420. In article <cconstan-1307940759520001@eusacbc.env.gov.bc.ca>,
  421. cconstan@epdiv1.env.gov.bc.ca (Carl B. Constantine) wrote:
  422.  
  423. > 1)  IM IV says to set RGBForeColor to White and RGBBackColor to Black
  424. > before using CopyBits to avoid colorization.  That's great, but I've seen
  425. > many examples where people don't do this.  My question is, do you have to
  426. > do it for Color GWorlds?
  427.  
  428. Yes, you do need it.  (BTW, it's RGBForeColor to *black* and RGBBackColor
  429. to *white*).  If the foreground and background colors are something else,
  430. CopyBits will do color masking, which is a cool effect, but slows things
  431. down a lot.
  432.  
  433. > 2) I've seen alot about rowBytes and BaseAddr values for PixMaps/BitMaps. 
  434. > How you have to set it to long word aligned for fastest copying.  If you
  435. > use NewGWorld to create your offscreen port (as opposed to OpenCPort), do
  436. > you still need to set these values or does NewGWorld do it for you?
  437.  
  438. NewGWorld always allocates longword-aligned chunks of memory for its
  439. screen buffer.  As long as you are copying from a longword-aligned offset
  440. from the baseAdr, you don't need to worry.
  441.  
  442. > 3) Develop 17 (ftp'd from ftp.apple.com) mentions in Brigham Stevens'
  443. > article "Ten Tips for Game Developers" to use CopyBits with a mask region
  444. > instead of CopyMask or CopyDeepMask because it's faster. OK, but how do I
  445. > convert my mask (sitting in a GWorld called maskWorld) to a region.  I
  446. > haven't seen any good examples of the use of BitMapToRgn anywhere (I did
  447. > look, but got more confused. IM didn't explain how to use this at all and
  448. > neither did THINK Reference)
  449.  
  450. I assume you're using cicn's to store your graphics?  If you are, then
  451. look at the structure of a CIconHandle in THINK Reference; in there is a
  452. pointer to a BitMap containing the mask.  Allocate a new RgnHandle with
  453. NewRgn(), then call BitMapToRegion() to convert the mask BitMap into a
  454. region.  It's pretty straightforward.  Something like this:
  455.  
  456. CIconHandle myIcon = GetCIcon(kMyIconID);
  457. if (myIcon) {
  458.     RgnHandle myMaskRgn = NewRgn();
  459.     if (myMaskRgn) {
  460.        char hState = HGetState((Handle)myIcon);
  461.        OSErr theErr;
  462.        HLock((Handle)myIcon);
  463.        theErr = BitMapToRegion(myMaskRgn, &(*myIcon)->iconMask);
  464.        HSetState((Handle)myIcon, hState);
  465.        if (theErr == noErr) // everything worked!
  466.     }
  467. }
  468.  
  469. However, you need to be careful, because the mask BitMap was originally in
  470. the source coordinates of the image, so you could just pass the same mask
  471. to CopyMask() to copy to any destination.  When you start using a mask
  472. region for CopyBits(), however, the region is relative to the
  473. *destination* port, so you will need to call OffsetRgn() on the mask
  474. region to transform it from source to destination coordinates before you
  475. copy.
  476.  
  477. That is, if you were doing CopyMask() to two different locations, you
  478. would just do this:
  479.  
  480. CopyMask((BitMap *)*mySrcPixMap, &myMaskBitMap, (BitMap *)*myDestPixMap,
  481.     &srcRect, &srcRect, &destRect1);
  482. CopyMask((BitMap *)*mySrcPixMap, &myMaskBitMap, (BitMap *)*myDestPixMap,
  483.     &srcRect, &srcRect, &destRect2);
  484.  
  485. However, if you were doing the same thing with CopyBits(), you would need
  486. to do a little more work:
  487.  
  488. RgnHandle myDestRgn = NewRgn();
  489. if (myDestRgn) {
  490.     CopyRgn(myMaskRgn, myDestRgn);
  491.     OffsetRgn(myDestRgn, destRect1.left, destRect1.top);
  492.     CopyBits((BitMap *)*mySrcPixMap, (BitMap *)*myDestPixMap,
  493.         &srcRect, &destRect1, mode, myDestRgn);
  494.     CopyRgn(myMaskRgn, myDestRgn);
  495.     OffsetRgn(myDestRgn, destRect2.left, destRect2.top);
  496.     CopyBits((BitMap *)*mySrcPixMap, (BitMap *)*myDestPixMap,
  497.         &srcRect, &destRect2, mode, myDestRgn);
  498. }
  499.  
  500. > 4) Can GetGWorld and SetGWorld be used instead of GetPort and SetPort when
  501. > using offscreen GWorlds?
  502.  
  503. Yes; in fact, they *must* be used.  I never use SetPort() anymore;
  504. SetGWorld() always does the job and you never have to worry about pointing
  505. to the wrong or nonexistant GDevice.
  506.  
  507. Hope this helps!
  508. Aaron
  509. -- 
  510. Aaron Giles (giles@med.cornell.edu)
  511. Power Macintosh Developer, Cornell University Medical College
  512. JPEGView home page: http://www.med.cornell.edu/jpegview.html
  513. JPEGView FTP site:   ftp://ftp.med.cornell.edu/pub/aarong/jpegview/
  514.  
  515. +++++++++++++++++++++++++++
  516.  
  517. From gurgle@dnai.com (Pete Gontier)
  518. Date: Wed, 13 Jul 1994 12:22:25 -0800
  519. Organization: Integer Poet Software
  520.  
  521. In article <giles-1307941311120001@wiggin.med.cornell.edu>,
  522. giles@med.cornell.edu (Aaron Giles) wrote:
  523.  
  524. > In article <cconstan-1307940759520001@eusacbc.env.gov.bc.ca>,
  525. > cconstan@epdiv1.env.gov.bc.ca (Carl B. Constantine) wrote:
  526. > > 1)  IM IV says to set RGBForeColor to White and RGBBackColor to Black
  527. > > before using CopyBits to avoid colorization.  That's great, but I've seen
  528. > > many examples where people don't do this.  My question is, do you have to
  529. > > do it for Color GWorlds?
  530. > Yes, you do need it.  (BTW, it's RGBForeColor to *black* and RGBBackColor
  531. > to *white*).  If the foreground and background colors are something else,
  532. > CopyBits will do color masking, which is a cool effect, but slows things
  533. > down a lot.
  534.  
  535. You don't need to do it every time if you think it is slowing your code
  536. down. What you do need to do is assure yourself that the foreground and
  537. background colors are set the way you think they should be set. Most of
  538. the time that's fore/black and back/white. It so happens that these are
  539. the default foreground and background colors, so that accounts for why you
  540. see code which doesn't bother to set them.
  541.  
  542. -- 
  543.  
  544.  Pete Gontier // CTO, Integer Poet Software // gurgle@dnai.com
  545.  
  546.  "I am Wang of Symantec. You will be assimilated. Resistance is futile."
  547.  
  548. ---------------------------
  549.  
  550. From tzagara@tigris.cti.gr
  551. Subject: PBControl() "hangs" the Macintosh
  552. Date: 12 JUL 94 18:21:00 GMT
  553. Organization: Computer Technology Institute (CTI), Patras, Greece
  554.  
  555. Hi there,
  556.  
  557. I am new in Macintosh programming and I want to write two simple programs 
  558. implementing a client and a server. I am using MacTCP and I am trying to 
  559. open a UDP connection between the client and the server.
  560.  
  561. I am using Think C 5.0 on a MacQuadra 700 and MacTCP 1.1.
  562.  
  563. I wrote the following code trying to open the MacTCP driver and a UDP stream,
  564. but when I try to  "run" it,  the  Macintosh "hangs".
  565.  
  566. - -------------------------------------------------------------------
  567.  
  568. /* Open a UDP stream */
  569.  
  570. #include <PrintTraps.h>
  571. #include <stdio.h>
  572. #include <MacTCPCommonTypes.h>
  573. #include <UDPPB.h>
  574.  
  575. main()
  576. {
  577.  
  578.  short             DrefNum=0;
  579.  UDPiob            myUDPblock;
  580.  CntrlParam        myUDPCblock;
  581.  UDPCreatePB       myUDPCreate;
  582.  Ptr               RcvBuffer;
  583.  OsErr             MyErr;
  584.  char              DriverName[9]="\p.ipp";
  585.  
  586.  myUDPblock.ioCompletion = NULL;
  587.  myUDPblock.ioNamePtr = DriverName;
  588.  myUDPblock.ioCRefNum = 0;
  589.  
  590.  MyErr = PBOpen((ParmBlkPtr)&myUDPblock,false);
  591.  
  592.  DrefNum=myUDPblock.ioCRefNum;
  593.  
  594.  if (MyErr != noErr)
  595.     printf("Error %d\n",MyErr);
  596.  else
  597.     printf("No Error\n");
  598.  
  599.  myUDPCblock.csCode=20;
  600.  myUDPCblock.ioCRefNum=DrefNum;
  601.  myUDPCblock.oCompletion=NULL;
  602.  
  603.  RcvBuffer=(char *)malloc(2048*sizeof(char));
  604.  myUDPCreate.rcvBuff=RcvBuffer;
  605.  myUDPCreate.localPort=0;
  606.  myUDPCreate.endingPort=1500;
  607.  
  608. **>> MyErr=PBControl((ParmBlkPtr)&myUDPCblock,false);  /* At this point the Mac
  609.                                                         "hangs" */
  610.  if (MyErr != noErr)                                 
  611.     printf("PBControl returned error %d\n",MyErr);
  612.  else
  613.     printf("No error returned\n");
  614.  
  615.  
  616. }
  617.  
  618. - ----------------------------------------------------------------------------
  619.  
  620.  
  621. The point where the Macintosh "hangs" is market with **>>. When I use the 
  622. debugger, at the specified point a message appears saying  "Bus Error".
  623.  
  624. Can anybody tell me, what I am doing wrong ?
  625.  
  626. Thank you in advance.
  627.  
  628. ****************************************************************
  629. Emmanuel Tzangarakis, tzagara@cti.gr,   tzagara@grpatvx1.bitnet
  630. Computer Technology Institute (CTI)
  631. Patras,
  632. Greece.
  633.  
  634. +++++++++++++++++++++++++++
  635.  
  636. From oster@netcom.com (David Phillip Oster)
  637. Date: Tue, 12 Jul 1994 18:34:26 GMT
  638. Organization: Netcom Online Communications Services (408-241-9760 login: guest)
  639.  
  640. In article <12JUL94.18210014@tigris.cti.gr> tzagara@tigris.cti.gr writes:
  641. >I wrote the following code trying to open the MacTCP driver and a UDP stream,
  642. >but when I try to  "run" it,  the  Macintosh "hangs".
  643. >
  644. > myUDPCblock.csCode=20;
  645. > myUDPCblock.ioCRefNum=DrefNum;
  646. > myUDPCblock.oCompletion=NULL;
  647. >
  648. > RcvBuffer=(char *)malloc(2048*sizeof(char));
  649. > myUDPCreate.rcvBuff=RcvBuffer;
  650. > myUDPCreate.localPort=0;
  651. > myUDPCreate.endingPort=1500;
  652. >
  653. >**>> MyErr=PBControl((ParmBlkPtr)&myUDPCblock,false);  /* At this point the Mac
  654. >                                                        "hangs" */
  655. You don't initialize your parameter block, so your code installs garbage
  656. as an ASR. When the mac calls that garbage ASR, it bus errors.
  657.  
  658. The following does almost what you want:
  659.  
  660. /* This is a complete, correct, example of creatign a TCP stream.
  661.     Written and tested by David Phillip Oster, 7/12/94
  662.  */
  663. #include "AddressXlation.h"
  664. #include "UDPPB.h"
  665. #include "TCPPB.h"
  666. #include <string.h>
  667.  
  668. static short tcpRefNum = 0;
  669.  
  670. /* UDPMTU - return UDPMaxMTUSize
  671.  */
  672. static OSErr UDPMTU(ip_addr hostAddr, unsigned short *dgramSize){
  673.     UDPiopb    pb;
  674.     OSErr    err;
  675.  
  676.     if(0 == tcpRefNum){
  677.         return openFailed;
  678.     }
  679.     memset(&pb, 0, sizeof pb);
  680.     pb.ioCRefNum = tcpRefNum;
  681.     pb.csCode = UDPMaxMTUSize;
  682.     pb.csParam.mtu.remoteHost = hostAddr;
  683.     pb.csParam.mtu.userDataPtr = nil;
  684.     if(noErr == (err = PBControl((ParmBlkPtr) &pb, FALSE))){
  685.         *dgramSize = pb.csParam.mtu.mtuSize;
  686.     }
  687.     return err;
  688. }
  689.  
  690. /* TcpCreate - opens a TCP stream.
  691.  */
  692. static OSErr TcpCreate(
  693.     Ptr rcvBuff, 
  694.     unsigned long rcvBuffLen, 
  695.     StreamPtr *streamp){
  696.  
  697.     TCPiopb    pb;
  698.     OSErr    err;
  699.  
  700.     if(0 == tcpRefNum){
  701.         return openFailed;
  702.     }
  703.     memset(&pb, 0, sizeof pb);
  704.     pb.ioCRefNum = tcpRefNum;
  705.     pb.csCode = TCPCreate;
  706.     pb.csParam.create.rcvBuff = rcvBuff;
  707.     pb.csParam.create.rcvBuffLen = rcvBuffLen;
  708.     if(noErr == (err = PBControl((ParmBlkPtr) &pb, FALSE))){
  709.         *streamp = pb.tcpStream;
  710.     }
  711.     return err;
  712. }
  713.  
  714. /* TcpRelease - closes a Tcp stream
  715.  */
  716. static OSErr TcpRelease(StreamPtr stream, Ptr *rcvBuff, long *rcvBuffLen){
  717.     TCPiopb    pb;
  718.     OSErr    err;
  719.  
  720.     if(0 == tcpRefNum){
  721.         return openFailed;
  722.     }
  723.     memset(&pb, 0, sizeof pb);
  724.     pb.ioCRefNum = tcpRefNum;
  725.     pb.csCode = TCPRelease;
  726.     pb.tcpStream = stream;
  727.     if(noErr == (err = PBControl((ParmBlkPtr) &pb, FALSE))){
  728.         *rcvBuff = pb.csParam.create.rcvBuff;
  729.         *rcvBuffLen = pb.csParam.create.rcvBuffLen;
  730.     }
  731.     return err;
  732. }
  733.  
  734.  
  735.  
  736. /* main -
  737.     although it appears that err is unused here, actually, I
  738.     dump it out in the debugger.
  739.  
  740.     weaver is just some host this machine can reach, so I can
  741.     ask how big a buffer to allocate, to hand to the stream.
  742.  */
  743. main(){
  744.     OSErr            err;
  745.     ip_addr            weaver_addr;
  746.     struct hostInfo    weaverInfo;
  747.     unsigned short     dgramSize;
  748.     Ptr                buf, buf2;
  749.     long            bufLen, bufLen2;
  750.     StreamPtr        stream;
  751.  
  752.     weaver_addr = 0;
  753.  
  754.     err = OpenDriver("\p.ipp", &tcpRefNum);    /* opens the MacTCP implementation */
  755.     err = OpenResolver(nil);
  756.     err = StrToAddr("weaver.", &weaverInfo, nil, nil);
  757.     if(noErr == err){
  758.         weaver_addr = weaverInfo.addr[0];
  759.     }
  760.     err = CloseResolver();
  761.     err = UDPMTU(weaver_addr, &dgramSize);
  762.     /* the minimum memory allocation for TCP is 4L*dgramSize + 1024L */
  763.     bufLen = 2048L + 4L*dgramSize;
  764.     buf = NewPtr(bufLen);
  765.     err = MemError();
  766.     err = TcpCreate(buf, bufLen, &stream);
  767.     err = TcpRelease(stream, &buf2, &bufLen2);
  768.     return 0;
  769. }
  770.  
  771. +++++++++++++++++++++++++++
  772.  
  773. From Mark Hanrek <hanrek@cts.com>
  774. Date: Thu, 14 Jul 1994 07:22:48 GMT
  775. Organization: The Information Workshop
  776.  
  777. In article <12JUL94.18210014@tigris.cti.gr> , tzagara@tigris.cti.gr
  778. writes:
  779.  
  780. > Hi there,
  781. >
  782. > I am new in Macintosh programming and I want to write two simple
  783. programs 
  784. > implementing a client and a server. I am using MacTCP and I am trying
  785. to 
  786. > open a UDP connection between the client and the server.
  787. >
  788. > I am using Think C 5.0 on a MacQuadra 700 and MacTCP 1.1.
  789. >
  790. > I wrote the following code trying to open the MacTCP driver and a UDP
  791. stream,
  792. > but when I try to  "run" it,  the  Macintosh "hangs".
  793. >
  794.  
  795. < source code not included>
  796.  
  797. >
  798. >
  799. > The point where the Macintosh "hangs" is market with **>>. When I use
  800. the 
  801. > debugger, at the specified point a message appears saying  "Bus Error".
  802. >
  803. > Can anybody tell me, what I am doing wrong ?
  804. >
  805. > Thank you in advance.
  806. >
  807. > ****************************************************************
  808. > Emmanuel Tzangarakis, tzagara@cti.gr,   tzagara@grpatvx1.bitnet
  809. > Computer Technology Institute (CTI)
  810. > Patras,
  811. > Greece.
  812.  
  813.  
  814. Emmanuel,
  815.  
  816. Your *real* problem is that you did not first draw from working example
  817. source code.  
  818.  
  819. Fortunately, David Oster supplied you with an excellent, and "known to be
  820. working" example.  When you look at it, and compare it to yours, you will
  821. see that there are significant differences.
  822.  
  823. The only way to be successful in programming these days is to "stand on
  824. the shoulders of work already done" -- because there is still quite a bit
  825. to do after that. :)
  826.  
  827. If you tackle each programming task all over from scratch, it could take
  828. you weeks, or even months to duplicate the effort that went into David's
  829. code alone.  It is okay for you to stand on the shoulders of that work
  830. and utilize it directly.  If it was not okay, David would have politely
  831. let you know.
  832.  
  833. - ---
  834.  
  835. I would wager that the mistake you made is a common one, which is using
  836. "parameter block" type calls without first initializing them to zero.
  837.  
  838. Your parameter block structures are allocated on the stack, but they are
  839. not initialized, so there is random stuff in all of the parameter block's
  840. fields.  You are setting the values of some of them, but what about the
  841. rest?
  842.  
  843. ooops. :)
  844.  
  845. The toolbox call you are making may be looking at some of the other
  846. parameter block field and perhaps if on of them is not nil, then it
  847. figures it must be good a valid address, and so it uses the address in
  848. that field, not knowing that is is actually a random value -- bus error!
  849.  
  850. In David's code, the "memset" call is used to initialize a parameter
  851. block before it is used.  Now you will remember this from now on, I am
  852. sure!
  853.  
  854. I made the same mistake, too, and will always remember it. :)
  855.  
  856. Keep working at it!
  857.  
  858.  
  859. Mark Hanrek
  860.  
  861. ---------------------------
  862.  
  863. From Dmitry Boldyrev <dmtiry@atlas.chem.utah.edu>
  864. Subject: Patching the GetResource() toolbox routine
  865. Date: 8 Jul 1994 01:51:15 GMT
  866. Organization: University of Utah
  867.  
  868. Hi folx!
  869. I am the author of LZSS Res resource compression utility. The way LZSS Res
  870. works now
  871. is, it has a library function called GetCResource(rType, rID) which has
  872. a call inside it to GetResource, then, the resource is decompressed in real
  873. time
  874. and returned. However, it is a not very convinient way of doing that, that is
  875. someone who's using my package would have to change GetPicture to 
  876. (PicHandle)GetCResource() and so on.. you see, it is not a good way. 
  877. Yesterday, I spoke to the current president of TopSoft, inc. Tony Jacobs who
  878. suggested me another idea, to patch the trap GetResource() so that
  879. whenever someone makes a call GetResource() actually my function will be called
  880. and the resource will be grabbed decompressed and passed. 
  881. Now, is there a way to do it?
  882.  
  883. Greatly appreciate any info.
  884.  
  885. +++++++++++++++++++++++++++
  886.  
  887. From radixinc@aol.com (RadixInc)
  888. Date: 8 Jul 1994 02:39:01 -0400
  889. Organization: America Online, Inc. (1-800-827-6364)
  890.  
  891. In article <2vibej$fve@u.cc.utah.edu>, Dmitry Boldyrev
  892. <dmtiry@atlas.chem.utah.edu> writes:
  893.  
  894. "...suggested me another idea, to patch the trap GetResource() so that
  895. whenever someone makes a call GetResource() actually my function will be
  896. called and the resource will be grabbed decompressed and passed.  Now, is
  897. there a way to do it?"
  898.  
  899. First off, you'll have to patch more than just GetResource. There are
  900. quite a few calls that load resources: GetResource, GetNamedResource,
  901. Get1Resource, Get1NamedResource, LoadResource, and some others. I suspect
  902. they all come down to a call into LoadResource, but the ROM won't get
  903. there through a trap, so you'll probably have to patch them all.
  904.  
  905. Second, you'll have to do your thing AFTER the toolbox gets the resource,
  906. so your patch will do the actual GetResource (or whatever), then
  907. decompress the result and return it. The problem is that by this time the
  908. Resource Manager has already allocated a handle for the resource and made
  909. an entry in the resource map. If you then decompress the resource into
  910. another (larger) block and return a handle to that block to the caller,
  911. you have a bit of a mess to clean up. First you'll have to get rid of the
  912. resource manager's copy, with ReleaseResource. Then you'll have to patch
  913. the ReleaseResource, DetachResource, and perhaps some other calls that
  914. will be expecting resource handles, just in case the calling program
  915. decides to do a resource call with the handle you gave it. The main
  916. problem here is that resource handles are NOT the same as other blocks;
  917. the Resource Manager keeps a private list or map of resources in the heap.
  918.  
  919. Obviously you'll have to install your patch(es) in the System Heap at boot
  920. time (with an INIT) so they will be global to all applications. You'll
  921. probably then find out how many other INITs patch the Resource Manager,
  922. with possibly frustrating results. Your code isn't the only thing that
  923. compresses and decompresses resources, so it had better be able to
  924. identify those it has compressed and ignore anything else.
  925.  
  926. In short, this could get messy.
  927.  
  928. Gregory Jorgensen
  929. XCommander
  930. Radix Consulting Inc.
  931.  
  932. +++++++++++++++++++++++++++
  933.  
  934. From benmartz@grex.cyberspace.org (Ben Martz)
  935. Date: 12 Jul 1994 02:08:23 GMT
  936. Organization: PawPrint Enterprises
  937.  
  938. In article <2vibej$fve@u.cc.utah.edu>, dmtiry@atlas.chem.utah.edu (Dmitry
  939. Boldyrev) wrote:
  940.  
  941. > I am the author of LZSS Res resource compression utility. The way LZSS Res
  942. > ...
  943. > ... However, it is a not very convinient way of doing that...
  944. > ..suggested me another idea, to patch the trap GetResource() so that
  945. > whenever someone makes a call GetResource() actually my function will be
  946. > called and the resource will be grabbed decompressed and passed. 
  947. > Now, is there a way to do it?
  948. > Greatly appreciate any info.
  949.  
  950. Ok, Dmitry, first of all, a disclaimer, if you don't have a way to
  951. determine if the resource is compressed, ADD ONE! Source code - from the
  952. way you wrote your article, it looks like you are using C so here's some C
  953. code for an INIT to patch a trap and call the original one:
  954.  
  955. /* GR_Patch.c, GetResource patch -- MAY NEED SOME WORK TO WORK! */
  956. #include <SetUpA4.h>
  957.  
  958. #define CODE_SETUP() asm {\
  959.                 movem.l    a0-a5/D0-D7, -(SP)\
  960.                 move.l        a0, a4\
  961.             }
  962. #define CODE_CLEANUP() asm {\
  963.                 movem.l    (SP)+, a0-a5/D0-D7\
  964.             }
  965.             
  966. #define GrafSize        206
  967. #define ADD_GRAFSIZE    (GrafSize - 130)
  968. typedef struct
  969. {
  970.     char        filler[ADD_GRAFSIZE];
  971.     long        randSeed;
  972.     BitMap        screenBits;
  973.     Cursor        arrow;
  974.     Pattern        dkGray;
  975.     Pattern        ltGray;
  976.     Pattern        gray;
  977.     Pattern        black;
  978.     Pattern        white;
  979.     GrafPtr        thePort;
  980. } QD_GLOBALS;
  981.  
  982. #ifndef NULL
  983. #define NULL ( (void *)0 )
  984. #endif
  985.  
  986. static QD_GLOBALS our_qd;
  987.  
  988. #define GetResource_Address 0xA9A0 /* yes this is the right address! */
  989. /* define our routine*/
  990. pascal Handle our_GetResource(ResType rType, short rID);
  991. static void *old_GetResource;
  992.  
  993. void main(void) {
  994.     Handle    self_handle;
  995.     Ptr selfPtr;
  996.         
  997.     CODE_SETUP();
  998.     asm { move.l a0, selfPtr }
  999.     self_handle = RecoverHandle(selfPtr);
  1000.     HLock(self_handle);
  1001.     DetachResource(self_handle);
  1002.         
  1003.     /* get the old routine's address for future use! */
  1004.     old_GetResource = (void *)NGetTrapAddress(GetResource_Address, ToolTrap);
  1005.     /* substitute our routine! */
  1006.     NSetTrapAddress((UniversalProcPtr)StripAddress(our_GetResource),
  1007.                     GetResource_Address, ToolTrap);
  1008.     
  1009.     CODE_CLEANUP();
  1010. }
  1011.  
  1012. pascal Handle our_GetResource(ResType rType, short rID) {
  1013.     Handle returnValue;
  1014.     
  1015.     CODE_SETUP();
  1016.     SetUpA4();
  1017.     
  1018.     /* call the old GetResource to get the resource */
  1019.     returnValue = CallPascalL(old_GetResource, rType, rID);
  1020.     
  1021.     /* first, check to see if the resource is compressed, if so, */
  1022.  /* decompress resource here! */
  1023.     
  1024.     RestoreA4();
  1025.     CODE_CLEANUP();
  1026.     return(returnValue);
  1027. }
  1028.  
  1029.  
  1030. /* end of file */
  1031.  
  1032. BTW: I don't think that this code is powerpc compatible unless you compile
  1033. it as 68K code
  1034.  
  1035.  
  1036. Hope that this helps!
  1037.  
  1038. - Ben
  1039.  
  1040.  
  1041. -CUT HERE------------------------------------------------------------------
  1042.  
  1043.            +---------------+        --------------------------------------
  1044.           / +-----------+ /        -- Ben Martz                        --
  1045.          / /  ()   ()  / /        -- benmartz@grex.cyberspace.org     --
  1046.         / /     ^     / /        -- currently residing in Ann Arbor, --
  1047.        / /  ______   / /        --       Michigan                   --
  1048.       / /  \-----/  / /        --------------------------------------
  1049.      / +-----------+ /        -- The views and opinions expressed --
  1050.     /        _____  /        --  here are mine and no one elses! --
  1051.    / *....         /        --------------------------------------
  1052.   +---------------+        -- "Football can touch a young man  --
  1053.   / / / / / / / /         -- where nobody else can...legally" --
  1054.  +-------------+         --------------------------------------=
  1055.  
  1056. +++++++++++++++++++++++++++
  1057.  
  1058. From devans@apple.com (Dave Evans)
  1059. Date: Wed, 13 Jul 1994 09:10:21 GMT
  1060. Organization: N/A
  1061.  
  1062. In article <2vibej$fve@u.cc.utah.edu>, Dmitry Boldyrev
  1063. <dmtiry@atlas.chem.utah.edu> wrote:
  1064. > The way LZSS Res works now is, it has a
  1065. > library function called GetCResource(rType, rID) which has a call inside
  1066. > it to GetResource, then, the resource is decompressed in real time
  1067. > and returned. However, it is a not very convinient way of doing that, that is
  1068. > someone who's using my package would have to change GetPicture to 
  1069. > (PicHandle)GetCResource() and so on.. you see, it is not a good way. 
  1070.  
  1071. Please Dmtiry, DON'T PATCH.  Even if more technically challenging, patching
  1072. only makes your software less stable, less compatible, and much more
  1073. difficult to maintain across system software versions.  Also, your patches
  1074. may very well break other applications;  you would need to test many
  1075. applications to verify that your software was successful.  If you stick
  1076. with a linked library, you will avoid all of this.
  1077.  
  1078. Now, to solve your problem, I recommend you provide a library with many
  1079. routines instead of just one routine.  Name them, for example:
  1080.  
  1081. DBGetResource()
  1082. DBGet1Resource()
  1083. DBGetPicture()
  1084.  
  1085. etc.  The DB is for your name's initials, just to designate your
  1086. routines as separate from the Mac Toolbox routines.  Then write very
  1087. small routines for each which call your GetCResource() routine
  1088. as appropriate or Macro's which redefine them to casted GetCResource()
  1089. calls.  You can then also provide a header file which optionally
  1090. defines all the developer's routines to be yours instead.  E.G.:
  1091.  
  1092. #if hasDmtiryLibrary
  1093. #define GetResource(...)  DBGetResource()
  1094. #endif
  1095.  
  1096. So they don't need to change their code and can easily use your
  1097. software...  AND no patching!!!
  1098.  
  1099. Dave
  1100.  
  1101. ---------------------------
  1102.  
  1103. End of C.S.M.P. Digest
  1104. **********************
  1105.  
  1106.