home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #20 / NN_1992_20.iso / spool / comp / sys / next / programm / 6156 < prev    next >
Encoding:
Text File  |  1992-09-14  |  4.2 KB  |  77 lines

  1. Newsgroups: comp.sys.next.programmer
  2. Path: sparky!uunet!nwnexus!sounds!brianw
  3. From: BrianW@SoundS.WA.com (Brian Willoughby)
  4. Subject: Re: the big demo / matrices
  5. Message-ID: <BuL3zL.K2y@sounds.wa.com>
  6. Sender: brianw@sounds.wa.com (Brian Willoughby)
  7. Reply-To: BrianW@SoundS.WA.com
  8. Cc: andrew_abernathy@wire.gwinnett.com
  9. Organization: SoundSoftware, Bellevue, WA, USA
  10. References: <1992Sep5.040934.8445@wire.gwinnett.com>
  11. Date: Mon, 14 Sep 1992 20:09:21 GMT
  12. Lines: 63
  13.  
  14. andrew abernathy writes
  15. |     I have a (hopefully) quick question about matrices, cells and  
  16. | tags.  I use browsers in several places to allow the user to select some  
  17. | entity.  When I load the matrices, I set the cells tags to unique values  
  18. | so that I can easily identify a selected cell.  Well, I can get the cell  
  19. | that is being selected, but it's tag always returns as -1.  I'm having to  
  20. | identify cell by their stringValues, which is very inconvenient.  Does  
  21. | anyone have any ideas why I might be getting the behavious I am?
  22. | -- 
  23. | andrew_abernathy@wire.gwinnett.com (NeXTmail gleefully accepted)
  24.  
  25. I am very familiar with this NXBrowser problem and I know exactly what the  
  26. cause is (although I don't know why NeXT designed it this way).  If you look  
  27. closely at the NeXTstep References for the AppKit classes, you'll see that  
  28. NXBrowserCell is a subclass of Cell.  If you read the -tag and -setTag: methods  
  29. for the Cell class, you'll note that they are not implemented for some reason.   
  30. Instead, they are designed to be overridden and implemented in subclasses of  
  31. Cell.  If NeXT had written NXBrowserCell as a subclass of ActionCell instead of  
  32. Cell, then your code would work as you wrote it.
  33.  
  34. The solution, which I have working under System 2.2a, is to subclass both  
  35. NXBrowserCell and NXBrowser.
  36.  
  37. You can't make a category of NXBrowserCell since you need to add an instance  
  38. variable to hold the tag.  So, in your subclass of NXBrowserCell, just add an  
  39. instance variable named "tag" and write the (obvious) code for the -tag and  
  40. -setTag: methods.  You should also override the -initTextCell: method and  
  41. initialize this instance variable to something predictable like -1.  I skipped  
  42. the implementation of -read: and -write: since I never archive my browsers  
  43. (other programmers may need to fill in these last two methods as well).
  44.  
  45. You also need to write a subclass of NXBrowser because I have found no other  
  46. reliable method of setting the cell class and cell prototype (i.e. one that  
  47. doesn't eventually cause the program to crash).  You must call -setCellClass  
  48. with the name of your NXBrowserCell subclass within the +initialize method for  
  49. your NXBrowser subclass.
  50.  
  51. #mount _soap_box
  52. This is a prime example of how NeXTanswers is nearly useless.  appkit.827 says  
  53. to -setCellClass inside -initFrame:, appkit.816 says to -setCellClass in  
  54. -appDidInit:, appkit.761 says that you must -setCellClass in +initialize  
  55. because -init is too late, implying that -appDidInit would be far too late.  It  
  56. took a great deal of experimentation and searching to figure out what worked.   
  57. Of course the simpler approaches didn't work and they were what I tried first.
  58. #dismount _soap_box
  59.  
  60. Within my main program, I call -setCellPrototype before using the browser.   
  61. This can probably be done in -appDidInit, but since I have several .nib files I  
  62. use the -setBrowserOutlet initialization method for the nib owner to accomplish  
  63. this (where browserOutlet would be the name of my instance variable).  My only  
  64. remaining problem is determining whether I should worry about -free'ing the  
  65. cell prototype when I free the nib instance.  I could assume that NXBrowser  
  66. will free its cell prototype within its own -free method since the program  
  67. crashes when I -free the cell prototype myself.  If anyone reads this far and  
  68. can offer a hint, I would appreciate it.  MallocDebug finds so many other  
  69. memory leaks that I can't tell whether NXBrowser is freeing the prototype cell.
  70.  
  71. Sorry I didn't post source code, but this stuff is not packaged as an example.   
  72. It is hidden deep within a program that I am currently writing.
  73. -- 
  74. Brian Willoughby    Software Design Engineer, BSEE NCSU
  75. BrianW@SoundS.WA.com    Sound Signal Processing Software and Consulting
  76. NeXTmail welcome    - NO EMAIL SOLICITATION without prior permission
  77.