home *** CD-ROM | disk | FTP | other *** search
/ ftp.mactech.com 2010 / ftp.mactech.com.tar / ftp.mactech.com / csmpdigest / csmp-digest-v3-051 < prev    next >
Text File  |  2010-09-21  |  70KB  |  1,914 lines

  1. Received-Date: Fri, 12 Aug 1994 16:04:18 +0200
  2. From: pottier@clipper.ens.fr (Francois Pottier)
  3. Subject: csmp-digest-v3-051
  4. To: csmp-digest@ens.fr
  5. Date: Fri, 12 Aug 1994 16:04:14 +0200 (MET DST)
  6. X-Mailer: ELM [version 2.4 PL23]
  7. Mime-Version: 1.0
  8. Content-Type: text/plain; charset=ISO-8859-1
  9. Content-Transfer-Encoding: 8bit
  10. Errors-To: listman@ens.fr
  11. Reply-To: pottier@clipper.ens.fr
  12. X-Sequence: 56
  13.  
  14. C.S.M.P. Digest             Fri, 12 Aug 94       Volume 3 : Issue 51
  15.  
  16. Today's Topics:
  17.  
  18.         Controls, Fonts, Dialogs & ResEdit (long)
  19.         Deleting ptr to base not calling dtors of derived
  20.         Icon positions on desktop
  21.         Looking for source code
  22.         Need C source code for recording sound
  23.         OpenPicture with temporary memory?
  24.         QuickTime 2.0 and MIDI
  25.         Tab Patch for TextEdit
  26.         [Q] Increasing stack size?
  27.  
  28.  
  29.  
  30. The Comp.Sys.Mac.Programmer Digest is moderated by Francois Pottier
  31. (pottier@clipper.ens.fr).
  32.  
  33. The digest is a collection of article threads from the internet newsgroup
  34. comp.sys.mac.programmer.  It is designed for people who read c.s.m.p. semi-
  35. regularly and want an archive of the discussions.  If you don't know what a
  36. newsgroup is, you probably don't have access to it.  Ask your systems
  37. administrator(s) for details.  If you don't have access to news, you may
  38. still be able to post messages to the group by using a mail server like
  39. anon.penet.fi (mail help@anon.penet.fi for more information).
  40.  
  41. Each issue of the digest contains one or more sets of articles (called
  42. threads), with each set corresponding to a 'discussion' of a particular
  43. subject.  The articles are not edited; all articles included in this digest
  44. are in their original posted form (as received by our news server at
  45. nef.ens.fr).  Article threads are not added to the digest until the last
  46. article added to the thread is at least two weeks old (this is to ensure that
  47. the thread is dead before adding it to the digest).  Article threads that
  48. consist of only one message are generally not included in the digest.
  49.  
  50. The digest is officially distributed by two means, by email and ftp.
  51.  
  52. If you want to receive the digest by mail, send email to listserv@ens.fr
  53. with no subject and one of the following commands as body:
  54.     help                        Sends you a summary of commands
  55.     subscribe csmp-digest Your Name    Adds you to the mailing list
  56.     signoff csmp-digest            Removes you from the list
  57. Once you have subscribed, you will automatically receive each new
  58. issue as it is created.
  59.  
  60. The official ftp info is //ftp.dartmouth.edu/pub/csmp-digest.
  61. Questions related to the ftp site should be directed to
  62. scott.silver@dartmouth.edu. Currently no previous volumes of the CSMP
  63. digest are available there.
  64.  
  65. Also, the digests are available to WAIS users.  To search back issues
  66. with WAIS, use comp.sys.mac.programmer.src. With Mosaic, use
  67. http://www.wais.com/wais-dbs/comp.sys.mac.programmer.html.
  68.  
  69.  
  70. -------------------------------------------------------
  71.  
  72. >From jcr@mbunix.mitre.org (Rogers)
  73. Subject: Controls, Fonts, Dialogs & ResEdit (long)
  74. Date: 28 Jul 1994 19:31:23 GMT
  75. Organization: The MITRE Corporation, Bedford, MA
  76.  
  77. There's been a bit of traffic lately all having to do with fonts
  78. of dialog items, and I just happen to have been concerned with that
  79. myself lately, and also with controls, so I decided to try to put
  80. together a concise guide to these overlapping topics. It follows.
  81. Everyone feel free to add to it. Or send comments to me and I'll
  82. incorporate.
  83.  
  84. =====================================================================
  85. Creating Controls with ResEdit 2.1.1                     28 July 1994
  86. =====================================================================
  87.  
  88. Here is a guide to creating controls using ResEdit 2.1.1.
  89.  
  90. Please distribute freely, and add to any appropriate FAQs.
  91.  
  92. Please send any comments regarding errors, omissions, etc., to:
  93.  
  94.      Jeff Rogers
  95.      jrogers@mitre.org
  96. _____________________________________________________________________
  97.  
  98. When editing a control in ResEdit, you see a template much like
  99. the ASCII depiction below.
  100.  
  101.  
  102. +-------------------------------------------------------------------+
  103. |=|_|============== CNTL ID = 128 from App_pi.rsrc =================|
  104. |-----------------------------------------------------------------+-|
  105. |                                                                 |^|
  106. |               +-----+ +-----+ +-----+ +-----+    ,-----.        | |
  107. |  BoundsRect   | 391 | | 502 | | 411 | | 652 |   (  Set  )       | |
  108. |               +-----+ +-----+ +-----+ +-----+    '-----'        | |
  109. |               +-----------+                                     | |
  110. |  Value        | 0         |                                     | |
  111. |               +-----------+                                     | |
  112. |                ,-.            ,-.                               | |
  113. |  Visible      ( 0 ) True     (   ) False                        | |
  114. |                '-'            '-'                               | |
  115. |               +-----------+                                     | |
  116. |  Max          | 1         |                                     | |
  117. |               +-----------+                                     | |
  118. |               +-----------+                                     | |
  119. |  Min          | 0         |                                     | |
  120. |               +-----------+                                     | |
  121. |               +-----------+                                     | |
  122. |  ProcID       | 8         |                                     | |
  123. |               +-----------+                                     | |
  124. |               +----------------+                                | |
  125. |  RefCon       | 0              |                                | |
  126. |               +----------------+                                | |
  127. |               +------------------------------------+            | |
  128. |  Title        | Generate Schedule...               |            | |
  129. |               +------------------------------------+            | |
  130. |                                                                 |v|
  131. |_________________________________________________________________|_|
  132.  
  133.  
  134. The proper values for the various fields are not always obvious.
  135. Below is a guide to assigning the correct values.
  136.  
  137. BoundsRect
  138. - --------
  139. This is the control's rectangle in local coordinates. The bounds
  140. are shown in the following order: top, left, bottom, right.
  141.  
  142. Value
  143. - ---
  144. This is the initial value of the control. It should be given one of
  145. the following values, based on the type of control you wish to create:
  146.  
  147.    PushButton  : 0
  148.  
  149.    CheckBox    : 0 = not checked
  150.                  1 = checked
  151.  
  152.    RadioButton : 0 = not selected
  153.                  1 = selected
  154.  
  155.    ScrollBar   : anything between Max and Min, inclusive
  156.  
  157.    PopUpMenu   : The Value parameter of a pop-up menu is used when
  158.                  creating the menu to indicate how the pop-up's
  159.                  title is to be drawn. It should be any ORed
  160.                  combination (sum) of the following:
  161.  
  162.                       0 - left-justified
  163.                       1 - center-justified
  164.                     255 - right-justified
  165.                     256 - bold             4096 - shadow
  166.                     512 - italic           8192 - condensed
  167.                    1024 - underlined      16384 - extended
  168.                    2048 - outlined        32768 - plain
  169.  
  170.                  After the pop-up menu is created, this field
  171.                  will contain the value 1.
  172.  
  173. Visible
  174. - -----
  175. This indicates whether the control is initially visible.
  176.  
  177. Max
  178. - -
  179. This is the maximum value the control may assume. It should
  180. be given one of the following values:
  181.  
  182.    PushButton  : 1
  183.    CheckButton : 1
  184.    RadioButton : 1
  185.    ScrollBar   : any value appropriate to the application
  186.    PopUpMenu   : width in pixels of pop-up menu's title
  187.                  (After the pop-up menu is created, this field
  188.                   will contain the # of items in the pop-up menu.)
  189.  
  190. Min
  191. - -
  192. This is the minimum value the control may assume. It should
  193. be given one of the following values:
  194.  
  195.    PushButton  : 0
  196.    CheckButton : 0
  197.    RadioButton : 0
  198.    ScrollBar   : any value appropriate to the application
  199.    PopUpMenu   : resource ID of menu to pop up
  200.                  (After the pop-up menu is created,
  201.                   this field will contain the value 1.)
  202.  
  203. ProcID
  204. - ----
  205. This indicates which type of control to create, and also which
  206. font to use when drawing the control's title and other text. It
  207. should be given one of the following values:
  208.  
  209.    PushButton,  in system font :    0
  210.                 in window font :    8
  211.  
  212.    CheckButton, in system font :    1
  213.                 in window font :    9
  214.  
  215.    RadioButton, in system font :    2
  216.                 in window font :   10
  217.  
  218.    PopUpMenu ................. : 1008 *
  219.  
  220.    * PopUpMenu behavior can be affected by ORing (summing) the
  221.      ProcID with any of the following:
  222.         1 - don't dynamically adjust pop-up's width to accommodate
  223.             long menu items
  224.         8 - use the grafPort's font to draw the control's text
  225.         4 - ignore "min" field; instead, build a menu listing all
  226.             available resources of the type contained in "refCon"
  227.             field
  228.      Thus the following are valid ProcID values for a popUpMenu:
  229.         1008 - dynamic menu width - system font - menu from "Min"
  230.         1009 - fixed menu width   - system font - menu from "Min"
  231.         1012 - dynamic menu width - system font - list a resType
  232.         1013 - fixed menu width   - system font - list a resType
  233.         1016 - dynamic menu width - window font - menu from "Min"
  234.         1017 - fixed menu width   - window font - menu from "Min"
  235.         1020 - dynamic menu width - window font - list a resType
  236.         1021 - fixed menu width   - window font - list a resType
  237.  
  238. RefCon
  239. - ----
  240. This 32-bit value can be used by your app in any way you wish.
  241.  
  242. For popUpMenus, this field may (depending on the value of "ProcID"
  243. above) be used during creation of the popUpMenu and contain a
  244. 4-character resource type.
  245.  
  246. Title
  247. - ---
  248. This is the control's title. This text shows up inside a pushButton,
  249. or beside a checkBox, radioButton or popUpMenu. For scrollBars it
  250. remains invisible, but still can be used, e.g., to search a window's
  251. controls by title.
  252.  
  253.  
  254. ============================
  255. Dialogs, Controls, and Fonts
  256. ============================
  257.  
  258. A question that often arises is how to get pushButtons, checkBoxes,
  259. radioButtons, and/or popUpMenus in a dialog to be drawn with a font
  260. other than the system font. There are several ways to do this, one
  261. of which is the following:
  262.  
  263. In the DITL editor, rather than creating each control as the type of
  264. control you ultimately want it to be, instead create it as a generic
  265. control. Then, in the CNTL editor, you can specify the ProcID that
  266. will cause the control to be drawn in the dialog's font instead of
  267. the system font. (Thanks to Jens Alfke [jens_alfke@powertalk.apple.com]
  268. for this one.) Otherwise, the dialog manager creates the controls
  269. for you, and it will use ProcID values specifying use of the system
  270. font when drawing the controls. Once these controls are created, there
  271. seems to be no way to change this aspect of them; Apple has provided
  272. a "GetCVariant" call but no "SetCVariant" call.
  273.  
  274. To change the font of statText and editText items, you must take
  275. a different approach. Once the dialog has been created, call a
  276. routine like the following:
  277.  
  278. /**********************************************************************
  279. *
  280. *  FUNCTION:    SetDialogFontAndSize( DialogPtr theDialog,
  281. *                                     short     fontNum,
  282. *                                     short     fontSize    )
  283. *
  284. *  DESCRIPTION: This function sets the font and size to be used
  285. *               subsequently by static-text and edit-text items
  286. *               of a dialog.
  287. *
  288. *  WRITTEN BY:  jarezina@magnus.acs.ohio-state.edu
  289. *               (Jasna M. Arezina-Wilson)
  290. *
  291. *  MODIFIED BY: Jeffrey C. Rogers
  292. *               (jrogers@mitre.org)
  293. *
  294. ****************/
  295.  
  296. void SetDialogFontAndSize( DialogPtr theDialog,
  297.                            short     fontNum,
  298.                            short     fontSize   )
  299. {
  300.   FontInfo   f ;
  301.   GrafPtr    savedPort ;
  302.   
  303.   // Store the current grafPort, then change to the dialog.
  304.   
  305.   GetPort( &savedPort );
  306.   SetPort( theDialog );
  307.   
  308.   // Set up the dialog's grafPort font info.
  309.   
  310.   TextFont( fontNum );
  311.   TextSize( fontSize );
  312.   
  313.   // Deal with the static & edit text items.
  314.   
  315.   GetFontInfo( &f );
  316.   (*((DialogPeek)theDialog)->textH)->txFont = fontNum ;
  317.   (*((DialogPeek)theDialog)->textH)->txSize = fontSize ;
  318.   (*((DialogPeek)theDialog)->textH)->lineHeight = f.ascent + f.descent +
  319.                                                              f.leading ;
  320.   (*((DialogPeek)theDialog)->textH)->fontAscent = f.ascent ;
  321.   
  322.   // Restore previous grafPort.
  323.   
  324.   SetPort( savedPort );
  325. }
  326. /*********************************************************************/
  327.  
  328.  
  329. ---------------------------
  330.  
  331. >From ant@kunikpok.icus.com (handle)
  332. Subject: Deleting ptr to base not calling dtors of derived
  333. Date: Wed, 27 Jul 94 04:41:07 CDT
  334. Organization: Kunikpok Kennels and Komputers (Pet Project)
  335.  
  336. I'm having a problem with destructors. It popped up in a fairly large
  337. hierarchy, and I've boiled it down to the simplest possible below. If
  338. I call a function which accepts a pointer to Base, but the pointer is
  339. of class Derived, when the function deletes the object, it doesn't
  340. call Derived's destructor. If I add a destructor to Base, then it
  341. calls Derived's destructor, then Base's destructor (as I would expect).
  342. This seems like inconsistent behaviour. Is this correct C++? I need to
  343. get it to correctly call Derived's destructor. I don't want to have to
  344. add a destructor to Base (it doesnt need one). If your response is
  345. "just add one anyway", I must point this out: If this is a bug, then
  346. let's find out all the ramifications, instead of just ignoring it.
  347.  
  348. I am using (how on earth did you guess??) Symantec C++ 7.0.3  :)
  349.  
  350. Thanx!
  351.  
  352. - --- test.cp -----
  353.  
  354. class Base { };                 // Empty base class
  355.  
  356. class Derived : public Base     // Derived class, has a constructor
  357. {                               // and destructor
  358. public:
  359.     Derived( void );
  360.     virtual ~Derived( void );
  361.     char* theP;
  362. };
  363.  
  364. Derived::Derived( void )
  365. {
  366.     theP = new char [20000];    // Allocate some space
  367. }
  368.  
  369. Derived::~Derived( void )
  370. {
  371.     if ( theP != 0 )
  372.         delete[] theP;          // Free if allocated
  373. }
  374.  
  375. void    DeleteDerived( Derived* obj )
  376. {
  377.     delete obj;                 // Delete obj
  378. }
  379.  
  380. void    DeleteBase( Base* obj )
  381. {
  382.     delete obj;                 // Delete obj
  383. }
  384.  
  385. main()
  386. {
  387.     Derived*    b1 = new Derived;
  388.     Derived*    b2 = new Derived;
  389.     
  390.     DeleteDerived( b1 );        // Correctly calls ~Derived().
  391.     DeleteBase( b2 );           // Calls *no* destructors
  392.     
  393.     return 0;
  394. }
  395.  
  396. - --- end of test.cp -----
  397.  
  398. - ------------------------------------------------------------------
  399. Chelly Green 'Ant'          <cgreen%podbox.uucp@cs.utexas.edu>
  400.  
  401. +++++++++++++++++++++++++++
  402.  
  403. >From neeri@iis.ee.ethz.ch (Matthias Neeracher)
  404. Date: 28 Jul 1994 15:53:09 GMT
  405. Organization: Integrated Systems Laboratory, ETH, Zurich
  406.  
  407. In article <9q94Pc2w165w@kunikpok.icus.com> ant@kunikpok.icus.com (handle) writes:
  408. > I'm having a problem with destructors. It popped up in a fairly large
  409. > hierarchy, and I've boiled it down to the simplest possible below. If
  410. > I call a function which accepts a pointer to Base, but the pointer is
  411. > of class Derived, when the function deletes the object, it doesn't
  412. > call Derived's destructor. If I add a destructor to Base, then it
  413. > calls Derived's destructor, then Base's destructor (as I would expect).
  414. > This seems like inconsistent behaviour. Is this correct C++?
  415.  
  416. Yes.
  417.  
  418. > I need to get it to correctly call Derived's destructor. I don't want to have
  419. > to add a destructor to Base (it doesnt need one).
  420.  
  421. Well, I'll start with the argument by authority:
  422.  
  423. To quote Bjarne Stroustrup, _The C++ Programming Language_, 2nd edition:
  424. # In general, it is wise to supply a virtual destructor in all classes that
  425. # act as a base class in the sense that objects of derived classes are
  426. # manipulated (and possibly deleted) through a pointer to the base. This is
  427. # almost always the case for classes with even a single virtual function.
  428.  
  429. If that doesn't convince you, think about it in technical terms: How is
  430. the compiler to know to call a destructor of the derived class on a
  431.  
  432. delete base;
  433.  
  434. statement, unless the base class provides a hint in the form of a virtual
  435. destructor.
  436.  
  437. >If your response is "just
  438. > add one anyway", I must point this out: If this is a bug, then let's find out
  439. > all the ramifications, instead of just ignoring it.
  440.  
  441. Your attitude is correct, but it's not a bug.
  442.  
  443. > I am using (how on earth did you guess??) Symantec C++ 7.0.3  :)
  444.  
  445. Awww, leave those poor Symantec compiler guys alone for a change and let them
  446. fix the bugs that *are* there (As the "*=" thread has shown, it is hard enough
  447. to convince them of those already. The Metrowerks guys, on the other hand,
  448. didn't explicitely admit that it was a bug, but promised to fix it :-).
  449.  
  450. Matthias
  451.  
  452. - ---
  453. Matthias Neeracher <neeri@iis.ee.ethz.ch> http://err.ethz.ch/members/neeri.html
  454.   "Paranotions, which designate constructs, may now contain metanotions and
  455.    ``hypernotions'' have been introduced in order to designate protonotions"
  456.                 -- A. van Wijngaarden et al., _ALGOL 68 Revised Report_
  457.  
  458. +++++++++++++++++++++++++++
  459.  
  460. >From nagle@netcom.com (John Nagle)
  461. Date: Fri, 29 Jul 1994 04:08:28 GMT
  462. Organization: NETCOM On-line Communication Services (408 261-4700 guest)
  463.  
  464. neeri@iis.ee.ethz.ch (Matthias Neeracher) writes:
  465. >In article <9q94Pc2w165w@kunikpok.icus.com> ant@kunikpok.icus.com (handle) writes:
  466. >> I'm having a problem with destructors. It popped up in a fairly large
  467. >> hierarchy, and I've boiled it down to the simplest possible below. If
  468. >> I call a function which accepts a pointer to Base, but the pointer is
  469. >> of class Derived, when the function deletes the object, it doesn't
  470. >> call Derived's destructor. If I add a destructor to Base, then it
  471. >> calls Derived's destructor, then Base's destructor (as I would expect).
  472. >> This seems like inconsistent behaviour. Is this correct C++?
  473.  
  474. >Yes.
  475.  
  476.      That's right, but the rationale for it working this way is wierd.
  477.  
  478.      The trouble comes from the C++ design decision that classes and
  479. structs are the same, plus the design decision that classes that don't
  480. use "C++ features" have compatible storage layout with C structs.
  481.  Logically, all destructors should be virtual, but that would force
  482. all classes to have the machinery for virtual functions, in case somebody
  483. later derived a class from that class.  This would break C data structure
  484. compatibility.
  485.  
  486.      It really should be an error to derive a class with a destructor
  487. from a class which does not have a virtual destructor.  If you want
  488. normal destructor semantics, you have to have virtual destructors all the way
  489. down to the base class.  This is easily checkable and should be
  490. checked, rather than being viewed as a rite of passage for C++ programmers.
  491.  
  492.                     John Nagle
  493.  
  494. +++++++++++++++++++++++++++
  495.  
  496. >From sokoloff@mv.mv.com (Jim Sokoloff)
  497. Date: Thu, 28 Jul 1994 20:04:24 GMT
  498. Organization: MV Communications, Inc.
  499.  
  500. In article <9q94Pc2w165w@kunikpok.icus.com>,
  501. handle <ant@kunikpok.icus.com> wrote:
  502. >I'm having a problem with destructors. It popped up in a fairly large
  503. >hierarchy, and I've boiled it down to the simplest possible below. If
  504. >I call a function which accepts a pointer to Base, but the pointer is
  505. >of class Derived, when the function deletes the object, it doesn't
  506. >call Derived's destructor. If I add a destructor to Base, then it
  507. >calls Derived's destructor, then Base's destructor (as I would expect).
  508. >This seems like inconsistent behaviour. Is this correct C++? I need to
  509. >get it to correctly call Derived's destructor. I don't want to have to
  510. >add a destructor to Base (it doesnt need one). If your response is
  511. >"just add one anyway", I must point this out: If this is a bug, then
  512. >let's find out all the ramifications, instead of just ignoring it.
  513. [Sample deleted]
  514. AS far as I know, this is correct C++. Base has no dtor, therefore, when 
  515. you delete a Base *, there is no dtor to call. Therefore, your compiler is
  516. doing the right thing. Add a virtual dtor to Base anyway. This will cause the
  517. correct thing to happen. (From your perspective, meaning Derived dtor is 
  518. called. From the C++ perspective, the correct thing is already happening, and
  519. you have a bug in your code...)
  520.  
  521. - -Jim
  522.  
  523.  
  524.  
  525. +++++++++++++++++++++++++++
  526.  
  527. >From s2361905@techst02.technion.ac.il (Ben Hekster)
  528. Date: Thu, 28 Jul 1994 19:37:44 GMT
  529. Organization: Technion, Israel Institute of Technology
  530.  
  531. Hi--
  532.  
  533. >If
  534. >I call a function which accepts a pointer to Base, but the pointer is
  535. >of class Derived, when the function deletes the object, it doesn't
  536. >call Derived's destructor. If I add a destructor to Base, then it
  537. >calls Derived's destructor, then Base's destructor (as I would expect).
  538. >[...] Is this correct C++?
  539.  
  540. Yes, this is correct C++.  If you expect to be able to call member
  541. functions that you override in derived classes, you must declare
  542. the member function `virtual' in the base type.  Note that this
  543. is true for any member function, not just destructors.  I.e., if you
  544. have
  545.  
  546.     class Base { void f(); };
  547.  
  548.     class Derived : public Base { virtual void f(); };
  549.  
  550. then any application of f() to a Base binds to Base::f().  If you
  551. want the binding to be dynamic, you must supply the `virtual'.
  552. By omitting it you are implying that either you do not expect this
  553. function to be overridden, or that you don't want/need overridden
  554. versions to be called.
  555.  
  556.     The questionable thing here is why the compiler doesn't
  557. warn about the redeclaration of f().  Possibly because of C
  558. compatibility reasons.  MPW cfront doesn't either, even with maximum
  559. warnings.
  560.  
  561.     In general, if your class has virtual members, it should
  562. have a virtual destructor, even if the destructor action itself is
  563. trivial.  The ARM warns about this, to avoid exactly the problem
  564. you are having now.
  565.  
  566. Ben
  567.  
  568.  
  569. +++++++++++++++++++++++++++
  570.  
  571. >From afcjlloyd@aol.com (AFC JLloyd)
  572. Date: 29 Jul 1994 02:11:07 -0400
  573. Organization: America Online, Inc. (1-800-827-6364)
  574.  
  575. In article <nagleCtoou4.Bxw@netcom.com>, nagle@netcom.com (John Nagle)
  576. writes:
  577.  
  578. >neeri@iis.ee.ethz.ch (Matthias Neeracher) writes:
  579. >>In article <9q94Pc2w165w@kunikpok.icus.com> ant@kunikpok.icus.com
  580. (handle) writes:
  581. >>> I'm having a problem with destructors. It popped up in a fairly large
  582. >>> hierarchy, and I've boiled it down to the simplest possible below. If
  583. >>> I call a function which accepts a pointer to Base, but the pointer is
  584. >>> of class Derived, when the function deletes the object, it doesn't
  585. >>> call Derived's destructor. If I add a destructor to Base, then it
  586. >>> calls Derived's destructor, then Base's destructor (as I would
  587. expect).
  588. >>> This seems like inconsistent behaviour. Is this correct C++?
  589. >
  590. >>Yes.
  591. >
  592. >     That's right, but the rationale for it working this way is wierd.
  593. >
  594. >     The trouble comes from the C++ design decision that classes and
  595. >structs are the same, plus the design decision that classes that don't
  596. >use "C++ features" have compatible storage layout with C structs.
  597. > Logically, all destructors should be virtual, but that would force
  598. >all classes to have the machinery for virtual functions, in case somebody
  599. >later derived a class from that class.  This would break C data structure
  600. >compatibility.
  601. >
  602. >     It really should be an error to derive a class with a destructor
  603. >from a class which does not have a virtual destructor.  If you want
  604. >normal destructor semantics, you have to have virtual destructors all the
  605. way
  606. >down to the base class.  This is easily checkable and should be
  607. >checked, rather than being viewed as a rite of passage for C++
  608. programmers.
  609.  
  610. I think it's a little more complicated than this.  I can think of lots of
  611. uses for classes that don't need any virtual functions, but need
  612. destructors (e.g. resource acquisition classes).  There is no point in
  613. making the destructor be virtual in such a case, and doing so generates a
  614. whole vtbl when none is needed, so the overhead cost is actually quite
  615. high (much more so than adding one entry to an already existing vtbl).
  616.  
  617. However, I agree with the idea that it should be an error to derive from
  618. classes that don't have virtual destructors.  Since the compiler doesn't
  619. enforce it (what a great optional warning!), the only thing you can do is
  620. add it to your list of coding guidelines.  Scott Meyer's is now writing a
  621. column for the C++ Report which continues the set of guidelines he
  622. established in his (truly excellent) book "Effective C++: 50 Specific Ways
  623. to Improve Your Programs and Designs".  His most recent column presents
  624. the guideline: "Avoid having concrete classes inherit from concrete
  625. classes".  Couple this with the guideline "Make destructors virtual in
  626. abstract base classes", and you're well covered.
  627.  
  628. By the way, if the guideline against deriving from concrete classes seems
  629. wrong to you, I highly recommend you read the article (July-August 94
  630. issue of C++ Report, should still be on the newstands).
  631.  
  632. Jim Lloyd
  633. afcjlloyd@aol.com
  634.  
  635.  
  636. ---------------------------
  637.  
  638. >From eajohnsn@blue.weeg.uiowa.edu (Eric Johnson)
  639. Subject: Icon positions on desktop
  640. Date: 25 Jul 1994 18:12:33 -0500
  641. Organization: University of Iowa, Iowa City, IA, USA
  642.  
  643. Hope this isn't too obvious, but I lack most reference sources.  I am 
  644. curious how programs like UnderWare know where on the screen the 
  645. different icons and folders are kept.  If I wanted to write a program 
  646. that would move the desktop icons around (or copy the screen and pretend 
  647. to move them), where do I find their positions?  Any tips or pointers to 
  648. the correct IM volume would be great.
  649.  
  650. Eric Johnson                eajohnsn@blue.weeg.uiowa.edu
  651. Program in Genetics
  652. University of Iowa
  653.  
  654.  
  655.  
  656. +++++++++++++++++++++++++++
  657.  
  658. >From zobkiw@datawatch.com (joe zobkiw)
  659. Date: Tue, 26 Jul 1994 15:19:14 GMT
  660. Organization: Datawatch Corporation
  661.  
  662. In article <311gt1$2g57@blue.weeg.uiowa.edu>, eajohnsn@blue.weeg.uiowa.edu
  663. (Eric Johnson) wrote:
  664.  
  665. > Hope this isn't too obvious, but I lack most reference sources.  I am 
  666. > curious how programs like UnderWare know where on the screen the 
  667. > different icons and folders are kept.  If I wanted to write a program 
  668. > that would move the desktop icons around (or copy the screen and pretend 
  669. > to move them), where do I find their positions?  Any tips or pointers to 
  670. > the correct IM volume would be great.
  671.  
  672. For each volume, recurse through the "Desktop folder" and perform an
  673. FSpGetFInfo on each file. The fdLocation gives you the location of the
  674. topLeft corner of the icon. For directories (if you use FSpGetDInfo) it is
  675. the frLocation field.
  676.  
  677. ___________________________________________________________
  678. _/_/_/_/   Joe Zobkiw                                   ,,,
  679.     _/     Senior Software Engineer                     - -
  680.   _/       Datawatch Corporation                         L
  681. _/_/_/_/   zobkiw@datawatch.com                          -
  682.  
  683. +++++++++++++++++++++++++++
  684.  
  685. >From dkj@apple.com (Dave Johnson)
  686. Date: Tue, 26 Jul 1994 17:54:41 GMT
  687. Organization: Apple Computer
  688.  
  689. In article <zobkiw-2607941019140001@zobkiw.datawatch.com>,
  690. zobkiw@datawatch.com (joe zobkiw) wrote:
  691.  
  692. > For each volume, recurse through the "Desktop folder" and perform an
  693. > FSpGetFInfo on each file. The fdLocation gives you the location of the
  694. > topLeft corner of the icon. For directories (if you use FSpGetDInfo) it is
  695. > the frLocation field.
  696.  
  697. Note also that with the scriptable Finder (7.5+, I think) you can get/set
  698. the locations of items via AppleScript or Apple Events real easy . . .
  699.  
  700. +++++++++++++++++++++++++++
  701.  
  702. >From macneils@aol.com (MacneilS)
  703. Date: 28 Jul 1994 20:44:03 -0400
  704. Organization: America Online, Inc. (1-800-827-6364)
  705.  
  706. In article <mouse-280794174850@ppp-83-19.bu.edu>, mouse@bu.edu (Matt Mick)
  707. writes:
  708.  
  709. >>>>>>
  710. Look at the NIM:Files.  It tells you how to get the h and v pos of the
  711. file.  I think, if I remember correctly, that is for the Icon!
  712. <<<<<<
  713.  
  714. You want to use HGetFInfo(). This will give you all of the information
  715. that the Finder itself uses for the posistion of icons.
  716.  
  717. Take Care,
  718. MacneilS@aol.com
  719.  
  720. +++++++++++++++++++++++++++
  721.  
  722. >From grobbins@apple.com (Grobbins)
  723. Date: 28 Jul 1994 21:06:31 -0700
  724. Organization: Skunkworks
  725.  
  726. In article <mouse-280794174850@ppp-83-19.bu.edu>,
  727. Matt Mick <mouse@bu.edu> wrote:
  728. >In article <311gt1$2g57@blue.weeg.uiowa.edu>, eajohnsn@blue.weeg.uiowa.edu
  729. >(Eric Johnson) wrote:
  730. >> Hope this isn't too obvious, but I lack most reference sources.  I am 
  731. >> curious how programs like UnderWare know where on the screen the 
  732. >> different icons and folders are kept.
  733. >
  734. >Look at the NIM:Files.  It tells you how to get the h and v pos of the
  735. >file.  I think, if I remember correctly, that is for the Icon!
  736.  
  737. The fdLocation field of a file's FInfo (returned by PBGetCatInfo and
  738. FSpGetFInfo, among other calls) may have the icon location.  But because
  739. the Finder ruthlessly caches its file information, the numbers on
  740. disk may not be accurate and cannot reliably be used to determine or
  741. set the icon position.
  742.  
  743. With the Scriptable Finder, you can use AppleScript to have the Finder
  744. get and set the positions of icons.  But any commercial products now
  745. that "know" where the icons reside are probably doing hacky skanky things
  746. to get that information reliably, 'cause the non-scriptable versions of
  747. the Finder are really unfriendly about sharing the knowledge.
  748.  
  749. Grobbins                grobbins@apple.com
  750.  
  751. Usual disclaimers apply.
  752.  
  753.  
  754. +++++++++++++++++++++++++++
  755.  
  756. >From mouse@bu.edu (Matt Mick)
  757. Date: Thu, 28 Jul 1994 17:48:49 -0500
  758. Organization: Boston University
  759.  
  760. In article <311gt1$2g57@blue.weeg.uiowa.edu>, eajohnsn@blue.weeg.uiowa.edu
  761. (Eric Johnson) wrote:
  762.  
  763. > Hope this isn't too obvious, but I lack most reference sources.  I am 
  764. > curious how programs like UnderWare know where on the screen the 
  765. > different icons and folders are kept.  If I wanted to write a program 
  766. > that would move the desktop icons around (or copy the screen and pretend 
  767. > to move them), where do I find their positions?  Any tips or pointers to 
  768. > the correct IM volume would be great.
  769. > Eric Johnson                eajohnsn@blue.weeg.uiowa.edu
  770. > Program in Genetics
  771. > University of Iowa
  772.  
  773. Look at the NIM:Files.  It tells you how to get the h and v pos of the
  774. file.  I think, if I remember correctly, that is for the Icon!
  775.  
  776. --matt
  777.  
  778. ---------------------------
  779.  
  780. >From rweber@helium.Gas.UUG.Arizona.EDU (Roygena R Weber)
  781. Subject: Looking for source code
  782. Date: 26 Jul 1994 22:52:09 GMT
  783. Organization: University of Arizona UNIX Users Group
  784.  
  785.  
  786. Could somebody point me to any ftp sites (besides umich and sumex) that 
  787. contain Macintosh source code? Pascal is preferred, but C is okay, too.
  788.  
  789. Also, is there a FAQ for this group? Where can it be found?
  790.  
  791. Thanks,
  792.  
  793. JACOB WEBER------------------------------------------*
  794.  \   Tucson, Arizona                    Where's       \
  795.   \   rweber@gas.uug.arizona.edu         My            \
  796.    \   CompuServe: 72303,3540             Thing?        \
  797.     *----------------------------------------------------*
  798.  
  799.  
  800. +++++++++++++++++++++++++++
  801.  
  802. >From tg3@u.washington.edu (Thurman Gillespy III)
  803. Date: Wed, 27 Jul 1994 09:21:22 -0800
  804. Organization: Dept of Radiology, Univ of Washington
  805.  
  806. In article <31442p$enm@news.CCIT.Arizona.EDU>,
  807. rweber@helium.Gas.UUG.Arizona.EDU (Roygena R Weber) wrote:
  808.  
  809. > Could somebody point me to any ftp sites (besides umich and sumex) that 
  810. > contain Macintosh source code? Pascal is preferred, but C is okay, too.
  811. > Also, is there a FAQ for this group? Where can it be found?
  812. > Thanks,
  813. > JACOB WEBER------------------------------------------*
  814. >  \   Tucson, Arizona                    Where's       \
  815. >   \   rweber@gas.uug.arizona.edu         My            \
  816. >    \   CompuServe: 72303,3540             Thing?        \
  817. >     *----------------------------------------------------*
  818.  
  819. You should get the Apprentice CD-ROM from Celestin Company. This CD-ROM
  820. is PACKED with source code, demos, and various utilites. Its a bargain
  821. at $35.
  822.  
  823.   Celestin Company
  824.   celestin@pt.olympus.net
  825.   (800) 835-5514 oders
  826.   file://speedway.net/pub/celestin/www/Celestin.html
  827.  
  828. -- 
  829. Thurman Gillespy III, MD         |  tg3@u.washington.edu
  830. Department of Radiology, SB-05   |  (206)543-3320 voice
  831. University of Washington         |  (206)543-6317 fax
  832. Seattle, WA 98195
  833.  
  834. +++++++++++++++++++++++++++
  835.  
  836. >From kenlong@netcom.com (Ken Long)
  837. Date: Wed, 27 Jul 1994 16:02:13 GMT
  838. Organization: NETCOM On-line Communication Services (408 261-4700 guest)
  839.  
  840. ftp devtools.symantec.com - has C source.
  841. ftp gatekeeper.dec.com - pub/DEC/Modula-2/m2.tar.Z
  842. ftp ftp.cwi.nl - Pascal
  843. ftp.eb.ele.tue.nl - pub/src/pascal/pasos2*
  844. ftp ftp.uu.net - usenet comp sources
  845. ftp zippy.nimh.nih.gov - image (Pascal - several versions)
  846. ftp nic.switch.ch /software/mac
  847. ftp uniwa.uwa.edu.au - POV
  848. ftp ftp.dartmouth.edu /pub/mac
  849. ftp midway.uchicago.edu /pub/OzTex   
  850. ftp ftpbio.bgsu.edu in pub/mac/alt.sources.mac
  851. ftp ftp.cc.umanitoba.ca /mac/develop
  852. ftp oddjob.uchicago.edu. 
  853. ftp magoo.uwsuper.edu - MacWT .04
  854. ftp csvax.cs.caltech.edu - pub/p2c-1.20.tar.Z.
  855. ftp bigbird.csd.scarolina.edu -  pub/mac - JWWalker
  856. ftp mrcnext.cso.uiuc.edu - pub/mac (old P, B, C, M2, F, A and HC)
  857. ftp prep.ai.mit.edu  pub/gnu/etc/GNU
  858.  
  859. That oughta get you started.
  860.  
  861. Get any ftp site lists that are available and connect and see what they 
  862. have.  The MacFTP List is pretty well known, but there are others.
  863.  
  864. I found one site by reading comp.sources.wanted, and a referral by 
  865. someone there.  That group is mostly non-Mac, but I get site tips from 
  866. messages.  Whenever I read, "So-and-so file is available at ftp.xxx.xxx" 
  867. and it's a site I haven't look on yet, I save that address in NotePad++ 
  868. (which I run in addition to my telecom program) and connect after I get 
  869. out of tin.
  870.  
  871. Always get the site indexes - description files too, if they have them.  
  872. Or start a screen capture as soon as you connect.  I save all the site 
  873. directory lists in a folder on my desktop called "Indexes."
  874.  
  875. Get on some services, too.  AOL has sources you won't find anywhere else, 
  876. and other services may be the same.  You don't have to remain a meber 
  877. for life - just long enough to get all their unique source code, if any.
  878.  
  879. -Ken-
  880.  
  881.  
  882. +++++++++++++++++++++++++++
  883.  
  884. >From Bill Melotti <bill.melotti@rl.ac.uk>
  885. Date: 27 Jul 1994 17:27:59 GMT
  886. Organization: Rutherford Appleton Labs (EPSRC)
  887.  
  888. Looking for source code
  889.  
  890. Try ftp.switch.ch
  891.  
  892. Bill
  893. - -----------------------------------------
  894. Bill Melotti                   Rm2.09, R68,
  895. Electronics Engineer           D-RAL,
  896. System Design Group            Chilton,
  897. Electronics Division           Nr. Didcot,
  898. Rutherford Appleton Lab        OX11 0QX
  899.  
  900. V (0235) 446815, F (0235) 445753
  901. - ----------------------
  902. All these opinions are mine and no one elses
  903.  
  904. +++++++++++++++++++++++++++
  905.  
  906. >From kenlong@netcom.com (Ken Long)
  907. Date: Wed, 27 Jul 1994 19:48:34 GMT
  908. Organization: NETCOM On-line Communication Services (408 261-4700 guest)
  909.  
  910. : You should get the Apprentice CD-ROM from Celestin Company. This CD-ROM
  911. : is PACKED with source code, demos, and various utilites. Its a bargain
  912. : at $35.
  913.  
  914. If you're going the CD route, EduCarp (no typo) has source on CD's and 
  915. disks, and MacTech has there source CD available for a couple C notes - 
  916. that's U.S. currency, not music tones.  Yeah, you can have it for a 
  917. song!  Two C notes!
  918.  
  919. Meanwhile, back at reality, there's also the AMUG CD, but theirs and 
  920. EduCarp's contain stuff that's posted.  MacTechs is from their mag.
  921.  
  922. -Ken-
  923.  
  924. +++++++++++++++++++++++++++
  925.  
  926. >From quesnel@sound.music.mcgill.ca (Rene Quesnel)
  927. Date: Wed, 27 Jul 1994 18:21:03 GMT
  928. Organization: Faculty of Music, McGill University
  929.  
  930. Roygena R Weber (rweber@helium.Gas.UUG.Arizona.EDU) wrote:
  931.  
  932. > Could somebody point me to any ftp sites (besides umich and sumex) that 
  933. > contain Macintosh source code? Pascal is preferred, but C is okay, too.
  934.  
  935. Try ftp.apple.com in directory dts/mac/sc. It contains code snippets and
  936. more elaborate examples, some in pascal, a  lot in C and C++. They also
  937. have the source code for the book Macintosh Programming Secrets by Knaster
  938. and Rollin.
  939.  
  940. You can get the csmp FAQ at nada.kth.se in directory
  941. pub/hacks/mac-faq/
  942.  
  943. Rene Quesnel
  944.  
  945. Music Technology and Sound Recording Areas
  946. Faculty of Music, McGill University
  947. Montreal, QC, Canada
  948. e-mail: quesnel@music.mcgill.ca
  949.  
  950.  
  951. +++++++++++++++++++++++++++
  952.  
  953. >From celestin@pt.olympus.net (Paul Celestin)
  954. Date: Thu, 28 Jul 1994 12:54:41 -0700
  955. Organization: Celestin Company
  956.  
  957. In article <31442p$enm@news.CCIT.Arizona.EDU>,
  958. rweber@helium.Gas.UUG.Arizona.EDU (Roygena R Weber) wrote:
  959.  
  960. > Could somebody point me to any ftp sites (besides umich and
  961. > sumex) that  contain Macintosh source code? Pascal is
  962. > preferred, but C is okay, too.
  963.  
  964. Here is a list of a few places I know of:
  965.  
  966. ftp://ftpbio.bgsu.edu/
  967. ftp://daemon.ncsa.uiuc.edu/TCL/
  968. ftp://ftp.luth.se/pub/mac/developer/
  969. ftp://f.ms.uky.edu/pub/mac/sources/
  970. ftp://ftp.ncsa.uiuc.edu/Mac/
  971. ftp://ics.uci.edu/mac/think-c/
  972. ftp://nic.switch.ch/software/mac/src/
  973. ftp://zippy.nimh.nih.gov/pub/nih-image/
  974. ftp://oak.oakland.edu/pub/macintosh/code/
  975. ftp://plains.nodak.edu/pub/mac/pub/programming/src/
  976. ftp://ssyx.ucsc.edu/pub/mac/
  977. ftp://ftp.cc.umanitoba.ca/Mac-Develop/
  978. ftp://ftp.netcom.com/pub/xplain/
  979.  
  980. -- 
  981. celestin@pt.olympus.net              (Paul Celestin, Celestin Company)
  982. Home of Apprentice - the Mac Programmer Source Code & Utilities CD-ROM
  983. finger me for more information about Celestin Company and its products
  984.  
  985. ---------------------------
  986.  
  987. >From smithjim@aol.com (Smith Jim)
  988. Subject: Need C source code for recording sound
  989. Date: 28 Jul 1994 18:12:06 -0400
  990. Organization: America Online, Inc. (1-800-827-6364)
  991.  
  992. I am looking for source code in C that demonstrates how to record sound
  993. with the
  994. microphone input port.  Any ideas?  Thanks.
  995.  
  996. Jim 
  997.  
  998. +++++++++++++++++++++++++++
  999.  
  1000. >From mars@netcom.com (Darren Giles)
  1001. Date: Fri, 29 Jul 1994 21:40:31 GMT
  1002. Organization: NETCOM On-line Communication Services (408 261-4700 guest)
  1003.  
  1004. In article <319afm$sh@search01.news.aol.com>,
  1005. Smith Jim <smithjim@aol.com> wrote:
  1006. >I am looking for source code in C that demonstrates how to record sound
  1007. >with the
  1008. >microphone input port.  Any ideas?  Thanks.
  1009. >
  1010. >Jim 
  1011.  
  1012. Here's a section of code which does what I believe you're looking for,
  1013. asynchronously, and writes the sampled sound to a resource.  Enjoy!
  1014.  
  1015. - Darren
  1016.  
  1017. #define    SND_BUFFER_SIZE        (15*11000)
  1018.  
  1019. typedef struct {
  1020.     short                    nbr_channels;
  1021.     Fixed                    sample_rate;
  1022.     short                    sample_size;
  1023.     OSType                    compression_type;
  1024. } snd_in_info;
  1025.  
  1026.  
  1027. ////////////////////////////////////////////////////////////////////////////
  1028. OSErr my_sound_start_recording () {
  1029.     OSErr                    myErr;
  1030.     long                    buff_size;
  1031.  
  1032.  
  1033.     if (!g_snd_dev_refNum)
  1034.         return -1;
  1035.         
  1036.     //    Find out default settings
  1037.     myErr= SPBGetDeviceInfo (g_snd_dev_refNum, siNumberChannels, (char*) &g_snd_info.nbr_channels);
  1038.     TST_MYERR_RTN ("calling SPBGetDeviceInfo")
  1039.     myErr= SPBGetDeviceInfo (g_snd_dev_refNum, siSampleRate, (char*) &g_snd_info.sample_rate);
  1040.     TST_MYERR_RTN ("calling SPBGetDeviceInfo")
  1041.     myErr= SPBGetDeviceInfo (g_snd_dev_refNum, siSampleSize, (char*) &g_snd_info.sample_size);
  1042.     TST_MYERR_RTN ("calling SPBGetDeviceInfo")
  1043.     myErr= SPBGetDeviceInfo (g_snd_dev_refNum, siCompressionType, (char*) &g_snd_info.compression_type);
  1044.     TST_MYERR_RTN ("calling SPBGetDeviceInfo")
  1045.     
  1046.     //    Set to record at 11kHz
  1047.     g_snd_info.sample_rate = rate11khz;
  1048.     myErr= SPBSetDeviceInfo (g_snd_dev_refNum, siSampleRate, (char*) &g_snd_info.sample_rate);
  1049.     TST_MYERR_RTN ("calling SPBSetDeviceInfo")
  1050.     myErr= SPBGetDeviceInfo (g_snd_dev_refNum, siSampleRate, (char*) &g_snd_info.sample_rate);
  1051.     TST_MYERR_RTN ("calling SPBGetDeviceInfo")
  1052.  
  1053.     //    Create new sound handle & setup for SND_RSRC_TYPE rsrc header
  1054.     g_snd_hdl= NewHandle (SND_BUFFER_SIZE);
  1055.     TST_NIL_RTN (g_snd_hdl, "allocating g_snd_hdl handle");
  1056.     myErr= SetupSndHeader (g_snd_hdl, g_snd_info.nbr_channels,
  1057.                 g_snd_info.sample_rate, g_snd_info.sample_size, 
  1058.                 g_snd_info.compression_type, 60, 0, &g_snd_header_len);
  1059.     TST_MYERR_RTN ("calling SetupSndHeader")
  1060.     buff_size= GetHandleSize (g_snd_hdl) - g_snd_header_len;
  1061.     HLockHi (g_snd_hdl);
  1062.     
  1063.     //    Setup & call sound input recording
  1064.     g_snd_PB.inRefNum=            g_snd_dev_refNum;
  1065.     g_snd_PB.count=                buff_size;
  1066.     g_snd_PB.milliseconds=        0;
  1067.     g_snd_PB.bufferLength=        buff_size;
  1068.     g_snd_PB.bufferPtr=            (Ptr) (*g_snd_hdl + g_snd_header_len);
  1069.     g_snd_PB.completionRoutine=    nil;
  1070.     g_snd_PB.interruptRoutine=    nil;
  1071.     g_snd_PB.userLong=            0;
  1072.     g_snd_PB.error=                noErr;
  1073.     g_snd_PB.unused1=            0;
  1074.     myErr= SPBRecord (&g_snd_PB, true);
  1075.     TST_MYERR_RTN ("calling SPBRecord")
  1076.  
  1077.     return noErr;
  1078. }
  1079.  
  1080.  
  1081. ////////////////////////////////////////////////////////////////////////////
  1082. OSErr my_sound_stop_recording () {
  1083.     OSErr                    myErr;
  1084.     long                    lead_size;
  1085.     uchar                    *sample;
  1086.  
  1087.  
  1088.     if (!g_snd_dev_refNum)
  1089.         return -1;
  1090.         
  1091.     //    Make sure we're done reading
  1092.     myErr= SPBStopRecording (g_snd_dev_refNum);
  1093.     TST_MYERR_RTN ("calling SPBStopRecording")
  1094.     
  1095.     //    Update snd info for # bytes actually kept
  1096.     HUnlock (g_snd_hdl);
  1097.     SetHandleSize (g_snd_hdl, g_snd_header_len+g_snd_PB.count);
  1098.     myErr= SetupSndHeader (g_snd_hdl, g_snd_info.nbr_channels,
  1099.                 g_snd_info.sample_rate, g_snd_info.sample_size, 
  1100.                 g_snd_info.compression_type, 60, g_snd_PB.count,
  1101.                 &g_snd_header_len);
  1102.     
  1103.     //    Play it back
  1104.     myErr= SndPlay (nil, g_snd_hdl, 0);
  1105.     TST_MYERR_RTN ("calling SndPlay")
  1106.     
  1107.     return noErr;
  1108. }
  1109.  
  1110.  
  1111. ////////////////////////////////////////////////////////////////////////////
  1112. OSErr my_sound_cancel_recording () {
  1113.     OSErr                    myErr;
  1114.  
  1115.  
  1116.     //    Make sure we're done reading
  1117.     if (g_snd_dev_refNum) {
  1118.         myErr= SPBStopRecording (g_snd_dev_refNum);
  1119.         TST_MYERR_RTN ("calling SPBStopRecording")
  1120.     }
  1121.     
  1122.     if (g_snd_hdl) {
  1123.         ReleaseResource (g_snd_hdl);
  1124.         DisposeHandle (g_snd_hdl);
  1125.         g_snd_hdl= nil;
  1126.     }
  1127.     
  1128.     return noErr;
  1129. }
  1130.  
  1131. +++++++++++++++++++++++++++
  1132.  
  1133. >From kenlong@netcom.com (Ken Long)
  1134. Date: Fri, 29 Jul 1994 20:25:21 GMT
  1135. Organization: NETCOM On-line Communication Services (408 261-4700 guest)
  1136.  
  1137. On AOL, in the MDV lib., theres an aiff recorder source.  Apple's 
  1138. SoundApp.pas source has some record routine (s), as I recall.
  1139.  
  1140. On AOL, go to the file search (keyword: quickfinder) click the developer 
  1141. box and type in: sound
  1142. and hit return.  That should lead you to some.
  1143.  
  1144. Also, there's source on AOL not listed in the MDV library.  Type in 
  1145. search word: source
  1146. in other directories than MDV, to track it down.
  1147.  
  1148. -Ken-
  1149.  
  1150. +++++++++++++++++++++++++++
  1151.  
  1152. >From Mark Hanrek <hanrek@cts.com>
  1153. Date: Fri, 29 Jul 1994 20:45:36 GMT
  1154. Organization: The Information Workshop
  1155.  
  1156. In article <319afm$sh@search01.news.aol.com> Smith Jim, smithjim@aol.com
  1157. writes:
  1158.  
  1159. >I am looking for source code in C that demonstrates how to record 
  1160. > sound with the microphone input port.  Any ideas?  Thanks.
  1161.  
  1162. Jim,
  1163.  
  1164. There should be at least one source code example in the Development File
  1165. Libraries.
  1166.  
  1167. There are lots and lots of examples, though, on the Developer CD.  If you
  1168. know someone with direct internet access, you can have them download a few
  1169. from ftp.apple.com.
  1170.  
  1171. Hope this helps.
  1172.  
  1173. Mark Hanrek
  1174.  
  1175. ---------------------------
  1176.  
  1177. >From AIKEN <INRA000@MUSICB.MCGILL.CA>
  1178. Subject: OpenPicture with temporary memory?
  1179. Date: Tue, 26 Jul 1994 20:00:30 GMT
  1180. Organization: McGill University
  1181.  
  1182. Hiya,
  1183.  
  1184.     Can anyone think of a reasonably robust way of coercing OpenPicture
  1185. into allocating its picture using temporary memory? I was surprised to
  1186. find no straightforward way of doing this, considering may QD features,
  1187. such as GWorlds, have support for temporary memory.
  1188.  
  1189.     Any help appreciated.
  1190.  
  1191.     Cheers,
  1192.  
  1193.     Mark Aiken
  1194.     inra@musicb.mcgill.ca
  1195.  
  1196.  
  1197. +++++++++++++++++++++++++++
  1198.  
  1199. >From giles@med.cornell.edu (Aaron Giles)
  1200. Date: Wed, 27 Jul 1994 01:56:18 -0400
  1201. Organization: Cornell University Medical College
  1202.  
  1203. In article <26JUL94.16209243.0081@VM1.MCGILL.CA>, AIKEN
  1204. <INRA000@MUSICB.MCGILL.CA> wrote:
  1205.  
  1206. >     Can anyone think of a reasonably robust way of coercing OpenPicture
  1207. > into allocating its picture using temporary memory? I was surprised to
  1208. > find no straightforward way of doing this, considering may QD features,
  1209. > such as GWorlds, have support for temporary memory.
  1210.  
  1211. I don't know how "kosher" this is, but I've done it successfully in a
  1212. shipping app without any apparent problems.  At least, it *seems* simple
  1213. enough. :-)  Here's the gist:
  1214.  
  1215. THz tempZone, oldZone;
  1216. PicHandle thePict;
  1217. OSErr theErr;
  1218.  
  1219. // allocate a handle in temp memory, and retrieve the temporary zone from that
  1220. thePict = (PicHandle)TempNewHandle(4, &theErr);
  1221. if (theErr == noErr && thePict) {
  1222.    tempZone = HandleZone((Handle)thePict);
  1223.    DisposeHandle((Handle)thePict);
  1224.  
  1225.    // open the picture
  1226.    oldZone = GetZone();
  1227.    SetZone(tempZone);
  1228.    thePict = OpenCPicture(&myParams);
  1229.    SetZone(oldZone);
  1230. }
  1231.  
  1232. Aaron
  1233. -- 
  1234. Aaron Giles (giles@med.cornell.edu)
  1235. Power Macintosh Developer, Cornell University Medical College
  1236. JPEGView home page: http://www.med.cornell.edu/jpegview.html
  1237. JPEGView FTP site:   ftp://ftp.med.cornell.edu/pub/aarong/jpegview/
  1238.  
  1239. +++++++++++++++++++++++++++
  1240.  
  1241. >From Jens Alfke <jens_alfke@powertalk.apple.com>
  1242. Date: Wed, 27 Jul 1994 20:28:49 GMT
  1243. Organization: Apple Computer
  1244.  
  1245. In article <26JUL94.16209243.0081@VM1.MCGILL.CA> AIKEN,
  1246. INRA000@MUSICB.MCGILL.CA writes:
  1247. >     Can anyone think of a reasonably robust way of coercing OpenPicture
  1248. > into allocating its picture using temporary memory?
  1249.  
  1250. Aaron Giles' solution of switching to the temp-mem zone is explicitly
  1251. non-kosher; IM warns not to do anything with the parent zone of temp handles.
  1252. I _think_ the only bad thing that will happen, pre-Copland, is that the
  1253. handle will not automatically be disposed when your app quits. If you make
  1254. sure it's always disposed, this shouldn't be a problem. In a modern-OS
  1255. system, though, this might break.
  1256.  
  1257. Other approaches I can think of:
  1258. * Call OpenPicture, then call NewTempHandle and copy the data from
  1259. thePort->picSave handle into the temp handle, then modify thePort->picSave to
  1260. point to the temp handle (and dispose the original one.)
  1261. * Temporarily patch NewHandle during the OpenPicture call, and have the patch
  1262. call NewTempHandle.
  1263.  
  1264.  
  1265. --Jens Alfke
  1266.   jens_alfke@powertalk              Rebel girl, rebel girl,
  1267.             .apple.com              Rebel girl you are the queen of my world
  1268.  
  1269. +++++++++++++++++++++++++++
  1270.  
  1271. >From giles@med.cornell.edu (Aaron Giles)
  1272. Date: Thu, 28 Jul 1994 11:02:18 -0400
  1273. Organization: Cornell University Medical College
  1274.  
  1275. In article <1994Jul27.202849.19507@gallant.apple.com>, Jens Alfke
  1276. <jens_alfke@powertalk.apple.com> wrote:
  1277.  
  1278. > Aaron Giles' solution of switching to the temp-mem zone is explicitly
  1279. > non-kosher; IM warns not to do anything with the parent zone of temp handles.
  1280.  
  1281. Must've missed that warning, but I figured what I was doing was bad
  1282. anyway. :-)  Thanks for the "cleaner" suggestions! (cleaner being a very
  1283. relative term here)
  1284.  
  1285. Aaron
  1286. -- 
  1287. Aaron Giles (giles@med.cornell.edu)
  1288. Power Macintosh Developer, Cornell University Medical College
  1289. JPEGView home page: http://www.med.cornell.edu/jpegview.html
  1290. JPEGView FTP site:   ftp://ftp.med.cornell.edu/pub/aarong/jpegview/
  1291.  
  1292. +++++++++++++++++++++++++++
  1293.  
  1294. >From jmunkki@beta.hut.fi (Juri Munkki)
  1295. Date: 29 Jul 1994 22:54:13 GMT
  1296. Organization: Helsinki University of Technology
  1297.  
  1298. In article <1994Jul27.202849.19507@gallant.apple.com> Jens Alfke <jens_alfke@powertalk.apple.com> writes:
  1299. >Aaron Giles' solution of switching to the temp-mem zone is explicitly
  1300. >non-kosher; IM warns not to do anything with the parent zone of temp handles.
  1301. >I _think_ the only bad thing that will happen, pre-Copland, is that the
  1302. >handle will not automatically be disposed when your app quits. If you make
  1303. >sure it's always disposed, this shouldn't be a problem. In a modern-OS
  1304. >system, though, this might break.
  1305.  
  1306. It probably couldn't be made very compatible with old versions of the
  1307. MultiFinder in any case and some of us (don't look at me though) want
  1308. to support System 6.
  1309.  
  1310. >Other approaches I can think of:
  1311. >* Call OpenPicture, then call NewTempHandle and copy the data from
  1312. >thePort->picSave handle into the temp handle, then modify thePort->picSave to
  1313. >point to the temp handle (and dispose the original one.)
  1314.  
  1315. Sounds dangerous to me, although I'm pretty sure this is safe at least now.
  1316.  
  1317. >* Temporarily patch NewHandle during the OpenPicture call, and have the patch
  1318. >call NewTempHandle.
  1319.  
  1320. Patch???? For something as simple as this? Patches are a necessary evil in
  1321. some cases, but should be avoided when there's a better solution. Besides,
  1322. this will break if QD decides that it needs to load a resource or create
  1323. some other handle when it does the OpenPicture, because the other handle will
  1324. also be temp memory even though it shouldn't.
  1325.  
  1326. In any case, why not just save the QD bottleneck that handles saving pictures.
  1327. You keep a regular handle for the header of the picture and write the data
  1328. into temporary memory. For example code on how this is done, just read the
  1329. IM chapter that has the example on how to write a picture to disk and replace
  1330. the file system calls with temporary memory calls.
  1331.  
  1332. -- 
  1333.   Juri Munkki            There ain't no such thing as a shareware lunch.
  1334.  jmunkki@hut.fi                Windsurfing: Faster than the wind.
  1335.  
  1336. ---------------------------
  1337.  
  1338. >From cabo@mi.aau.dk (Christian Orellana)
  1339. Subject: QuickTime 2.0 and MIDI
  1340. Date: Mon, 25 Jul 1994 21:34:49 GMT
  1341. Organization: aau
  1342.  
  1343.  
  1344. Hi!
  1345. I understand that some music extension is needed to make QuickTime 2.0 interact
  1346. with MIDI. Does anybody know the details of this product? like:
  1347.  
  1348. a) Is this an existing product?
  1349. b) Where do I get it?
  1350. c) How does it work; does it cooperate with the midi manager? 
  1351. d) Does it support general midi pacthes only, or can one add custom sounds?
  1352. e) Is it implemented as a component?
  1353.  
  1354. Best regards -
  1355. Christian A.Borlund Orellana
  1356. Institute of Physics and Astronomy Aarhus University.
  1357. ______________________________________________________
  1358. Internet e-mail:        muscabo@dfi.aau.dk
  1359. voice:                  +45-86102798
  1360. mail:                   Dr.Margrethesvej 11,3.th.
  1361.                         8200 Aarhus N, DENMARK.
  1362. ______________________________________________________
  1363.  
  1364.  
  1365. +++++++++++++++++++++++++++
  1366.  
  1367. >From rmah@panix.com (Robert Mah)
  1368. Date: 26 Jul 1994 20:51:28 GMT
  1369. Organization: One Step Beyond
  1370.  
  1371. cabo@mi.aau.dk (Christian Orellana) wrote:
  1372.  
  1373. ) I understand that some music extension is needed to make QuickTime 2.0
  1374. ) interact with MIDI. Does anybody know the details of this product? like:
  1375. ) a) Is this an existing product?
  1376.  
  1377. Has been announced.  Was on the latest developer CD.  I'm not sure if 
  1378. it's available to the general public or shipping with new machines yet.
  1379.  
  1380. ) b) Where do I get it?
  1381.  
  1382. Apple.  You can get the QT developer's kit from APDA.
  1383.  
  1384. ) c) How does it work; does it cooperate with the midi manager? 
  1385.  
  1386. I haven't looked at it closely, but from the general description, I think
  1387. it implements the General MIDI spec (or parts of it).  That is, it contains
  1388. samples for a variety of instruments at various pitches and probably allows
  1389. you to play them by note.
  1390.  
  1391. ) d) Does it support general midi pacthes only, or can one add custom sounds?
  1392. ) e) Is it implemented as a component?
  1393.  
  1394. Don't know.  Anyone looked at the extension on the CD closer yet?
  1395.  
  1396. Cheers,
  1397. Rob
  1398. _____________________________________________________________________
  1399. Robert S. Mah           Software Development          +1.212.947.6507
  1400. One Step Beyond        and Network Consulting          rmah@panix.com
  1401.  
  1402. +++++++++++++++++++++++++++
  1403.  
  1404. >From quesnel@sound.music.mcgill.ca (Rene Quesnel)
  1405. Date: Wed, 27 Jul 1994 11:44:47 GMT
  1406. Organization: Faculty of Music, McGill University
  1407.  
  1408. Christian Orellana (cabo@mi.aau.dk) wrote:
  1409.  
  1410. > Hi!
  1411. > I understand that some music extension is needed to make QuickTime 2.0 interact
  1412. > with MIDI. Does anybody know the details of this product? like:
  1413.  
  1414. > a) Is this an existing product?
  1415. > b) Where do I get it?
  1416. > c) How does it work; does it cooperate with the midi manager? 
  1417. > d) Does it support general midi pacthes only, or can one add custom sounds?
  1418. > e) Is it implemented as a component?
  1419.  
  1420. There is a short document "QuickTime 2.0 Information" available at
  1421. ftp.support.apple.com in directory 
  1422. /pub/Apple SW Updates /Macintosh/Supplemental System Software/.
  1423. It doesn't say much but it's a start.
  1424.  
  1425. Rene Quesnel
  1426.  
  1427. Music Technology and Sound Recording Areas
  1428. Faculty of Music, McGill University
  1429. Montreal, QC, Canada
  1430. e-mail: quesnel@music.mcgill.ca
  1431.  
  1432.  
  1433. +++++++++++++++++++++++++++
  1434.  
  1435. >From andreas@sctc.com (Glenn Andreas)
  1436. Date: Wed, 27 Jul 1994 15:37:11 GMT
  1437. Organization: SCTC
  1438.  
  1439. rmah@panix.com (Robert Mah) writes:
  1440.  
  1441. >cabo@mi.aau.dk (Christian Orellana) wrote:
  1442.  
  1443. >) I understand that some music extension is needed to make QuickTime 2.0
  1444. >) interact with MIDI. Does anybody know the details of this product? like:
  1445. >) 
  1446.  
  1447. >) c) How does it work; does it cooperate with the midi manager? 
  1448.  
  1449. >I haven't looked at it closely, but from the general description, I think
  1450. >it implements the General MIDI spec (or parts of it).  That is, it contains
  1451. >samples for a variety of instruments at various pitches and probably allows
  1452. >you to play them by note.
  1453.  
  1454. >) d) Does it support general midi pacthes only, or can one add custom sounds?
  1455. >) e) Is it implemented as a component?
  1456.  
  1457. >Don't know.  Anyone looked at the extension on the CD closer yet?
  1458.  
  1459. Actually, the "Music Component Architecture" (or something like that) isn't
  1460. MIDI.  However, with MoviePlayer 2.0 you can convert MIDI files to QuickTime
  1461. movies that just contain the (music) sound track.  Also, if you have a MIDI
  1462. output device, you can have QuickTime convert the music to play on the MIDI
  1463. device.  Don't know if there are any simple, direct ways to input from a
  1464. MIDI device, since I don't own one.
  1465.  
  1466. There are actually three different components - the Music Component (a low
  1467. level component that you aren't suppose to talk to), the Note Allocator, and
  1468. the Tune Player.  You basically set up a bunch of commands, similar to MIDI
  1469. (there are note commands, rest commands, knob commands, general commands,
  1470. control commands, etc...), and send them to the Tune Player.
  1471.  
  1472. The Music Component (there are actually two - built in synthesizer, and
  1473. "general MIDI device") is the thing that actually either plays them via
  1474. the sound manager, or converts them to MIDI.  The note allocator sits between
  1475. the two and figures out how to manage the music component based on the needs
  1476. of the tune player.
  1477.  
  1478. All in all, once you've figured it out, it works quite well, especially for
  1479. things such as adding background music to games (for example).  BTW, I've
  1480. recently written an article that will hopefully appear in an upcoming
  1481. MacTech explaining the basic format of music commands and the tune player.
  1482.  
  1483. Glenn Andreas
  1484.  
  1485.  
  1486. +++++++++++++++++++++++++++
  1487.  
  1488. >From rmah@panix.com (Robert Mah)
  1489. Date: 27 Jul 1994 20:47:57 GMT
  1490. Organization: One Step Beyond
  1491.  
  1492. andreas@sctc.com (Glenn Andreas) wrote:
  1493.  
  1494. ) Actually, the "Music Component Architecture" (or something like that)
  1495. ) isn't MIDI.  However, with MoviePlayer 2.0 you can convert MIDI files
  1496. ) to QuickTime movies that just contain the (music) sound track.  Also,
  1497. ) if you have a MIDI output device, you can have QuickTime convert the
  1498. ) music to play on the MIDI device.  Don't know if there are any simple,
  1499. ) [...]
  1500.  
  1501. Sounds cool, though it's too bad Apple didn't try harder to conform with
  1502. the General MIDI standard.  Oh well.
  1503.  
  1504. Do you know where I could pick up the docs on this stuff?  I searched
  1505. the latest developer CD with QT 2.0 on it, but couldn't find any info.
  1506. Some special, new Apple multimedia FTP site perchance?
  1507.  
  1508. Cheers,
  1509. Rob
  1510. _____________________________________________________________________
  1511. Robert S. Mah           Software Development          +1.212.947.6507
  1512. One Step Beyond        and Network Consulting          rmah@panix.com
  1513.  
  1514. +++++++++++++++++++++++++++
  1515.  
  1516. >From aclaasse@nyx.cs.du.edu (Arne Claassen)
  1517. Date: 27 Jul 1994 22:52:49 -0600
  1518. Organization: University of Denver, Dept. of Math & Comp. Sci.
  1519.  
  1520. In article <rmah-2707940250560001@rmah.dialup.access.net>,
  1521. Robert Mah <rmah@panix.com> wrote:
  1522. >Sounds cool, though it's too bad Apple didn't try harder to conform with
  1523. >the General MIDI standard.  Oh well.
  1524.  
  1525. In what respect? The story i got was that Roland liscensen them their GS
  1526. seris sounds for Quicktime 2.0. Only a subset of the entire GM set is supposed
  1527. to be in QT 2.0, but the rest can be added by developers if needed.
  1528. The internal format is not a standard midifile, but if a MIDI device is 
  1529. present (i'd have to assume that QT 2.0 works with MIDI Manager) it will
  1530. play through to the midi device. At least that's what the propaganda claimed.
  1531.  
  1532. Arne F. Claassen     claassen@ebs330.eb.uah.edu
  1533.  
  1534.  
  1535. +++++++++++++++++++++++++++
  1536.  
  1537. >From al@crucible.powertools.com (Al Evans)
  1538. Date: 29 Jul 94 14:35:21 GMT
  1539. Organization: PowerTools, Austin, Texas
  1540.  
  1541. In article <317dj1$b0h@nyx.cs.du.edu> aclaasse@nyx.cs.du.edu (Arne Claassen) writes:
  1542.  
  1543. >In article <rmah-2707940250560001@rmah.dialup.access.net>,
  1544. >Robert Mah <rmah@panix.com> wrote:
  1545. >>Sounds cool, though it's too bad Apple didn't try harder to conform with
  1546. >>the General MIDI standard.  Oh well.
  1547.  
  1548. >In what respect? The story i got was that Roland liscensen them their GS
  1549. >seris sounds for Quicktime 2.0. Only a subset of the entire GM set is supposed
  1550. >to be in QT 2.0, but the rest can be added by developers if needed.
  1551.  
  1552. If the QuickTime 2.0 music-playing routines "conformed with the General
  1553. MIDi standard," you would be able to play to a note-allocator 
  1554. NoteChannel just like you would to a real MIDI device. This is not
  1555. feasible beyond a certain elementary level (i.e., note-on, note-off,
  1556. and perhaps controller events). A simple example: using the built-in
  1557. synthesizer, a program change cannot be implemented in real time, since
  1558. it requires loading a new sound sample from the disk (which is slow)
  1559. and you can't do it at interrupt time.
  1560.  
  1561. Actually, according to *one* Apple tech support person, you're not 
  1562. allowed to make ANY note allocator calls at interrupt time. I dismissed
  1563. this as improbable, since the note allocator has no built-in timing
  1564. facilities (as does the Midi Manager, for example). So far, I have
  1565. had no trouble calling NAPlayNote(), at least, from an interrupt 
  1566. handler -- I was told by another Apple tech support person that this
  1567. was legal.
  1568.                     --Al Evans--
  1569. -- 
  1570. Al Evans        |   Graphic Elements: A new standard for 
  1571. ________________________|__ high-performance interactive Macintosh graphics.
  1572. al@crucible.powertools.com |  Available from mac.archive.umich.edu
  1573. - -------------------------| /mac/development/libraries/graphicelements2.sit.hqx
  1574.  
  1575. ---------------------------
  1576.  
  1577. >From rcostale@nmsu.edu (Raphael J. Costales)
  1578. Subject: Tab Patch for TextEdit
  1579. Date: 29 Jul 1994 05:22:07 GMT
  1580. Organization: New Mexico State University, Las Cruces, NM
  1581.  
  1582. /***************************************************************************
  1583.  
  1584.     tab_patch.c
  1585.  
  1586.     A while back, jesjones@stein.u.washington.edu posted some code written
  1587. in Modula-2 for three patches to TextEdit.  These patches enable TextEdit to
  1588. display tab characters as a run of spaces.  The three routines are:
  1589.  
  1590.     1.  DrawText
  1591.     2.  TextWidth
  1592.     3.  Pixel2Char (System 6)
  1593.         NPixel2Char (System 7)
  1594.  
  1595.     I rewritten the code in C in Think C ver. 4 using System 6 and tested it
  1596. on a Mac Plus - eight years old, but it still works fine!  I just wrote the
  1597. Pixel2Char, but NPixel2Char would be handled the same way.  The three patches
  1598. work the same way.  They expand tab characters into spaces then call the
  1599. original routine.
  1600.  
  1601.     Note, Pixel2Char & NPixel2Char are not real traps.  They use a generic
  1602. trap, ScriptUtil, after pushing a selector on the stack (see IM V).  Because
  1603. ScriptUtil takes a varying number of arguments, some assembly is required -
  1604. excuse the pun.
  1605.  
  1606.     Fell free to send any comments or suggestions other than buy a new Mac!
  1607.  
  1608.     rcostale@nmsu.edu
  1609.  
  1610. ***************************************************************************/
  1611.  
  1612. #define TABLEN      4           /* Tab length */
  1613. #define MAXSIZE     256         /* Size of Buffer.  Any text expanded beyond
  1614.                                  * the size of the buffer won't be displayed
  1615.                                  */
  1616.  
  1617. extern WindowPtr myWindow;      /* Of course, these would be your working */
  1618. extern TEHandle TEH;            /* Window pointer and TextEdit handle */
  1619.  
  1620. static pascal void  DoTrap();
  1621.  
  1622. pascal void newDrawText(char *, short, short);
  1623. pascal int  newTextWidth(char *, short, short);
  1624. pascal int  newPixel2Char(char *, short, short, short, Boolean *, long);
  1625.  
  1626. ProcPtr     oldDrawText, oldTextWidth, oldPixel2Char;
  1627.  
  1628. TabsOn()    /* Install patches */
  1629. {
  1630.     /* The first two patches are straight forward */
  1631.  
  1632.     oldDrawText = (ProcPtr) NGetTrapAddress(0xA885, ToolTrap);
  1633.     oldTextWidth = (ProcPtr) NGetTrapAddress(0xA886, ToolTrap);
  1634.  
  1635.     NSetTrapAddress((long) newDrawText, 0xA885, ToolTrap);
  1636.     NSetTrapAddress((long) newTextWidth, 0xA886, ToolTrap);
  1637.  
  1638.     /* The Pixel2Char uses the generic trap ScriptUtil.  We will patch in
  1639.      * an assembly routine that test the selector
  1640.      */
  1641.  
  1642.     oldPixel2Char = (ProcPtr) NGetTrapAddress(0xA8B5, ToolTrap);
  1643.     NSetTrapAddress((long) DoTrap, 0xA8B5, ToolTrap);
  1644. }
  1645.  
  1646. TabsOff()   /* Remove the patches when you're application finishes! */
  1647. {
  1648.     NSetTrapAddress((long) oldDrawText, 0xA885, ToolTrap);
  1649.     NSetTrapAddress((long) oldTextWidth, 0xA886, ToolTrap);
  1650.     NSetTrapAddress((long) oldPixel2Char, 0xA8B5, ToolTrap);
  1651. }
  1652.  
  1653. /* The assembly routine to check selector */
  1654. static pascal void DoTrap()
  1655. {
  1656.     long    selector = 0x820E0014;  /* or 0x8222002 for NPixel2Char */
  1657.  
  1658.     asm {
  1659.         move.l  selector, d0
  1660.         unlk    a6
  1661.         cmp.l   4(sp), d0           /* Is it the Pixel2Char selector? */
  1662.         bne.s   @old                /* No, do old oldPixel2Char */
  1663.         jmp     newPixel2Char       /* Yes, do patch */
  1664. @old
  1665.         move.l  oldPixel2Char, a0
  1666.         jmp     (a0)
  1667.     }
  1668. }
  1669.  
  1670. pascal void newDrawText(char textPtr[], short first, short count)
  1671. {
  1672.     char    buffPtr[MAXSIZE] = {0};
  1673.     int     buffCount;
  1674.  
  1675.     /* if were using my window then expand the text into the buffer and
  1676.      * call the original routine using the buffer.
  1677.      */
  1678.  
  1679.     if (FrontWindow() == myWindow) {
  1680.         buffCount = tab2spaces(textPtr + first, buffPtr, count);
  1681.         CallPascal(buffPtr, 0, buffCount, oldDrawText);
  1682.     }
  1683.     else
  1684.         CallPascal(textPtr, first, count, oldDrawText);
  1685. }
  1686.  
  1687. pascal int newTextWidth(char textPtr[], short first, short count)
  1688. {
  1689.     char    buffPtr[MAXSIZE] = {0};
  1690.     int     buffCount;
  1691.  
  1692.     /* same idea here */
  1693.  
  1694.     if (FrontWindow() == myWindow) {
  1695.         buffCount = tab2spaces(textPtr + first, buffPtr, count);
  1696.         return CallPascalW(buffPtr, 0, buffCount, oldTextWidth);
  1697.     }
  1698.     else
  1699.         return CallPascalW(textPtr, first, count, oldTextWidth);
  1700. }
  1701.  
  1702. /* This function converts tabs to spaces and places the text in a buffer.
  1703.  * It also returns the size of the buffer.
  1704.  */
  1705. int tab2spaces(char textPtr[], char buffPtr[], short count)
  1706. {
  1707.     char    chr;
  1708.     int     i, j, buffCount, spc;
  1709.  
  1710.     i = j = spc = 0;
  1711.     buffCount = offset(textPtr);
  1712.     for (i = 0; i < count; i++) {
  1713.         switch (chr = textPtr[i]) {
  1714.         case '\t':
  1715.             spc = TABLEN - (buffCount % TABLEN);
  1716.             while (spc--) {
  1717.                 buffPtr[j++] = ' ';
  1718.                 buffCount++;
  1719.             }
  1720.             break;
  1721.         case '\r':
  1722.             buffCount = 0;
  1723.         default:
  1724.             buffPtr[j++] = chr;
  1725.             buffCount++;
  1726.         }
  1727.     }
  1728.     return j;
  1729. }
  1730.  
  1731. /* This function finds the offset from the start of a line. */
  1732. int offset(char textPtr[])
  1733. {
  1734.     char   *linePtr, *charPtr;
  1735.     int     i = 0;
  1736.  
  1737.     linePtr = textPtr;
  1738.  
  1739.     /* find start of line */
  1740.  
  1741.     while ((linePtr > (*(**TEH).hText)) && (*linePtr != '\r'))
  1742.         linePtr--;
  1743.  
  1744.     /* find offset */
  1745.  
  1746.     for (charPtr = linePtr; charPtr < textPtr; charPtr++)
  1747.         switch (*charPtr) {
  1748.         case '\t':
  1749.             i = i + TABLEN - (i % TABLEN);
  1750.             break;
  1751.         case '\r':
  1752.             i = 0;
  1753.             break;
  1754.         default:
  1755.             i++;
  1756.         }
  1757.     return i;
  1758. }
  1759.  
  1760. /* Note, the selector is not an actual parameter. The selector is push on to
  1761.  * the stack before issuing the ScriptUtil trap.  Since the Pascal calling
  1762.  * convention pushes parametes from left-to-right, the selector is right above
  1763.  * the return address.  Use NPixel2Char declaration if you're using System 7.
  1764.  */
  1765. pascal int newPixel2Char(char textPtr[], short count, short slop, short width,
  1766.                          Boolean *leadingEdge, long selector)
  1767. {
  1768.     char    buffPtr[MAXSIZE] = {0};
  1769.     int     buffCount, pos;
  1770.  
  1771.     /* Again, we expand the text into a buffer and call the original trap */
  1772.  
  1773.     if (FrontWindow() == myWindow) {
  1774.         buffCount = tab2spaces(textPtr, buffPtr, count);
  1775.         pos = CallPascalW(buffPtr, buffCount, slop, width, &leadingEdge,
  1776.                           selector, oldPixel2Char);
  1777.         return charPos(textPtr, pos);
  1778.     }
  1779.     else
  1780.         return CallPascalW(textPtr, count, slop, width, &leadingEdge,
  1781.                            selector, oldPixel2Char);
  1782. }
  1783.  
  1784. /* returns the character position in the actual text corresponding to
  1785.  * position in the buffer.
  1786.  */
  1787. int charPos(char textPtr[], int pos)
  1788. {
  1789.     char   *linePtr;
  1790.     int i = 0, j =0 ;
  1791.  
  1792.     linePtr = textPtr;
  1793.     while ((linePtr > (*(**TEH).hText)) && (*linePtr != '\r'))
  1794.         linePtr--;
  1795.  
  1796.     while (i < pos) {
  1797.         switch (*linePtr) {
  1798.         case '\t':
  1799.             i = i + TABLEN - (i % TABLEN);
  1800.             j++;
  1801.             break;
  1802.         case '\r':
  1803.             i = j = 0;
  1804.             break;
  1805.         default:
  1806.             i++; j++;
  1807.         }
  1808.         linePtr++;
  1809.     }
  1810.     return j;
  1811. }
  1812.  
  1813. -- 
  1814. +------+
  1815. |      | Raphael J.S. Costales
  1816. | NMSU | rcostale@nmsu.edu
  1817. |  *___| New Mexico State University
  1818.  
  1819. ---------------------------
  1820.  
  1821. >From cshotton@oac.hsc.uth.tmc.edu (Chuck Shotton)
  1822. Subject: [Q] Increasing stack size?
  1823. Date: Fri, 29 Jul 1994 11:27:07 -0600
  1824. Organization: Academic Computing, UT-Houston
  1825.  
  1826. Can anyone think of a reason why a program that runs fine on most every Mac
  1827. model ends up with a stack (not heap) that runs out of space on a SE or
  1828. Plus? Is there something different that Think C (or CodeWarrior, for that
  1829. matter) must do on a 68K Mac that would cause it to eat significantly more
  1830. stack space? FWIW the app is MacHTTP, so it's playing with MacTCP,
  1831. AppleScript (if available), and AppleTalk (if required by MacTCP).
  1832.  
  1833. Stack space and heap space come out of the same chunk of memory allocated
  1834. to the application, correct? Is it possible that one of the aforementioned
  1835. software elements may eat up a bunch of memory on a Plus or SE? The
  1836. confusing thing is that frequent checks of available RAM show nothing amiss
  1837. while the program is running, yet it ends up with a corrupted stack
  1838. (because it runs out of space?)
  1839.  
  1840. --_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_\_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-
  1841. Chuck Shotton                             \ 
  1842. Assistant Director, Academic Computing     \   "Are we there yet?"
  1843. U. of Texas Health Science Center Houston   \ 
  1844. cshotton@oac.hsc.uth.tmc.edu  (713) 794-5650 \ 
  1845. _-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-\-_-_-_-_-_-_-_-_-_-_-_-_-
  1846.  
  1847. +++++++++++++++++++++++++++
  1848.  
  1849. >From larson@oahu.cs.ucla.edu (Christopher Larson)
  1850. Date: Fri, 29 Jul 94 18:36:15 GMT
  1851. Organization: UCLA, Computer Science Department
  1852.  
  1853. In article <cshotton-290794112707@oac2.hsc.uth.tmc.edu> cshotton@oac.hsc.uth.tmc.edu (Chuck Shotton) writes:
  1854. >Can anyone think of a reason why a program that runs fine on most every Mac
  1855. >model ends up with a stack (not heap) that runs out of space on a SE or
  1856. >Plus?
  1857.  
  1858. Sure. Neither of those machines has Color Quickdraw. On machines without CQD,
  1859. the default stack size is (I believe) 8K, but on a machine with CQD (as most
  1860. Macs out there today are) the default stack size is 32K. Your program must
  1861. use stack space larger than 8K and smaller than 32K -- hence it works on
  1862. CQD machines but not the old ones.
  1863.  
  1864. >Stack space and heap space come out of the same chunk of memory allocated
  1865. >to the application, correct?
  1866.  
  1867. Yup.
  1868.  
  1869. >Is it possible that one of the aforementioned
  1870. >software elements may eat up a bunch of memory on a Plus or SE?
  1871.  
  1872. I doubt they eat any _more_ on a Plus or SE than on other machines; whether
  1873. or not they eat up a 'bunch' is left as an exercise for the reader ;-).
  1874.  
  1875. >The
  1876. >confusing thing is that frequent checks of available RAM show nothing amiss
  1877. >while the program is running, yet it ends up with a corrupted stack
  1878. >(because it runs out of space?)
  1879.  
  1880. Are you checking the amount of free stack space during runtime (other than
  1881. by watching the stack sniffer inititate a system error)? During development,
  1882. you should try to max out the stack usage and then call StackSpace() to
  1883. determine your stack usage. If this usage is larger than the smallest default
  1884. stack size, you should expand the stack to accomidate for this difference.
  1885. (E.g. if you find that your program uses 20K of stack space, you should
  1886. expand the stack by at least 12K (perhaps a little more for cushioning) in
  1887. the initialization phase of your program.)
  1888.  
  1889. Techniques for expanding the stack and the details of the StackSpace() call
  1890. can be found in Inside Macintosh: Memory.
  1891.  
  1892. --Chris
  1893. _______________________________________________________________________________
  1894. Chris Larson -- Amateur Macintosh Geek, CoBase Research Assistant
  1895. L.A. Institute of Slowly and Painfully Working Out the Surprisingly Obvious
  1896. Death to the Trojans! Go Bruins!
  1897.  
  1898. (Insert disclaimer here)
  1899. Internet: larson@kingston.cs.ucla.edu
  1900.  
  1901. ---------------------------
  1902.  
  1903. End of C.S.M.P. Digest
  1904. **********************
  1905.  
  1906.  
  1907.