home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 October: Mac OS SDK / Dev.CD Oct 96 SDK / Dev.CD Oct 96 SDK2.toast / Development Kits (Disc 2) / OpenDoc / OpenDoc Development / Debugging Support / OpenDoc Source Code / UI / FocusSet.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1996-04-22  |  7.0 KB  |  314 lines  |  [TEXT/MPS ]

  1. /*
  2.     File:        FocusSet.cpp
  3.  
  4.     Contains:    ODFocusSet implementation
  5.  
  6.     Owned by:    Richard Rodseth
  7.  
  8.     Copyright:    © 1994 - 1995 by Apple Computer, Inc., all rights reserved.
  9.  
  10.     Change History (most recent first):
  11.  
  12.         <11>      8/3/95    RR        #1257260: Collapse B classes. Remove
  13.                                     somInit methods. Don't call IsInitialized
  14.                                     or SubclassResponsibility
  15.         <10>     7/25/95    VL        1270320: DeleteAllLinks on _fImplementation
  16.                                     in somUninit.
  17.          <9>     5/26/95    RR        #1251403: Multithreading naming support
  18.          <8>     5/25/95    jpa        List.h --> LinkList.h [1253324]
  19.          <7>     4/28/95    RR        1211085 Remove 5$ comments
  20.          <6>     4/13/95    RR        # 1216618 Added ODVolatile, ODDeleteObject
  21.          <5>      4/7/95    RR        #1216618 Added SOM_TRY etc.
  22.          <4>     2/22/95    RR        #1209427 Changed private api between
  23.                                     iterator and iteratee
  24.          <3>     9/29/94    RA        1189812: Mods for 68K build.
  25.          <2>     9/26/94    RR        Include ArbUtils
  26.          <1>     9/26/94    RR        first checked in
  27.  
  28.     To Do:
  29.     In Progress:
  30. */
  31.  
  32.  
  33. #define ODFocusSet_Class_Source
  34. #define VARIABLE_MACROS
  35. #include <FocusSet.xih>
  36.  
  37. #ifndef SOM_ODFocusSetIterator_xh
  38. #include "FocusItr.xh"
  39. #endif
  40.  
  41. #ifndef SOM_Module_OpenDoc_Foci_defined
  42. #include "Foci.xh"    // For kODNULLFocus. Returned by iterator, but ignored
  43. #endif
  44.  
  45. #ifndef _LINKLIST_
  46. #include <LinkList.h>
  47. #endif
  48.  
  49. #ifndef _ARBUTILS_
  50. #include "ArbUtils.h"
  51. #endif
  52.  
  53. #ifndef _EXCEPT_
  54. #include "Except.h"
  55. #endif
  56.  
  57. #ifndef _ODDEBUG_
  58. #include "ODDebug.h"    // Adkins -- added
  59. #endif
  60.  
  61.  
  62. #pragma segment ODFocusSet
  63.  
  64.  
  65. //======================================================================================
  66. // Method Implementations for ODFocusSet
  67. //======================================================================================
  68.  
  69.  
  70. SOM_Scope void  SOMLINK ODFocusSetInitFocusSet(ODFocusSet *somSelf, Environment *ev)
  71. {
  72.     ODFocusSetData *somThis = ODFocusSetGetData(somSelf);
  73.     ODFocusSetMethodDebug("ODFocusSet","ODFocusSetInitFocusSet");
  74.     
  75.     /* Moved from somInit. SOM itself sets fields to zero
  76.     _fImplementation = kODNULL;
  77.     */
  78.  
  79.     if (_fImplementation == kODNULL)
  80.     {
  81.         LinkedList* linkedList = kODNULL; ODVolatile(linkedList);
  82.  
  83.         SOM_TRY
  84.         
  85.             
  86.             somSelf->InitObject(ev);
  87.     
  88.             linkedList = new LinkedList;
  89.             _fImplementation = linkedList;
  90.             
  91.         SOM_CATCH_ALL
  92.             
  93.             ODDeleteObject(linkedList);
  94.             
  95.         SOM_ENDTRY
  96.     }
  97. }
  98.  
  99. SOM_Scope void  SOMLINK ODFocusSetAdd(ODFocusSet *somSelf, Environment *ev,
  100.         ODTypeToken focus)
  101. {
  102.     ODFocusSetData *somThis = ODFocusSetGetData(somSelf);
  103.     ODFocusSetMethodDebug("ODFocusSet","ODFocusSetAdd");
  104.  
  105.     FocusLink* focusLink = kODNULL; ODVolatile(focusLink);
  106.         
  107.     SOM_TRY
  108.     
  109.         ASSERT(_fImplementation != kODNULL,kODErrUndefined); // Note: Undefined error code
  110.     
  111.         if (!somSelf->Contains(ev,focus))
  112.         {
  113.             focusLink = new FocusLink(focus);        
  114.             _fImplementation->AddLast(focusLink);
  115.         }
  116.  
  117.     SOM_CATCH_ALL
  118.     
  119.         ODDeleteObject(focusLink);
  120.         
  121.     SOM_ENDTRY
  122. }
  123.  
  124. SOM_Scope void  SOMLINK ODFocusSetRemove(ODFocusSet *somSelf, Environment *ev,
  125.         ODTypeToken focus)
  126. {
  127.     ODFocusSetData *somThis = ODFocusSetGetData(somSelf);
  128.     ODFocusSetMethodDebug("ODFocusSet","ODFocusSetRemove");
  129.  
  130.     SOM_TRY
  131.     
  132.         ASSERT(_fImplementation != kODNULL,kODErrUndefined);
  133.     
  134.         LinkedListIterator iter(_fImplementation);
  135.         ODTypeToken foundFocus;
  136.         
  137.         FocusLink* link = (FocusLink*) iter.First();
  138.         while (link != kODNULL)
  139.         {
  140.             foundFocus = link->fFocus;
  141.             if (foundFocus == focus) 
  142.             {
  143.                 _fImplementation->Remove(*link);
  144.                 delete link;
  145.                 link = kODNULL;
  146.             }
  147.             else
  148.                 link = (FocusLink*) iter.Next();
  149.         }    
  150.  
  151.     SOM_CATCH_ALL
  152.     SOM_ENDTRY
  153.  
  154. }
  155.  
  156. SOM_Scope ODBoolean  SOMLINK ODFocusSetContains(ODFocusSet *somSelf, Environment *ev,
  157.         ODTypeToken focus)
  158. {
  159.     ODFocusSetData *somThis = ODFocusSetGetData(somSelf);
  160.     ODFocusSetMethodDebug("ODFocusSet","ODFocusSetContains");
  161.     
  162.     ODBoolean containsFocus = kODFalse;
  163.  
  164.     SOM_TRY
  165.     
  166.         ASSERT(_fImplementation != kODNULL,kODErrUndefined);
  167.     
  168.         LinkedListIterator iter(_fImplementation);
  169.         ODTypeToken foundFocus;
  170.     
  171.         FocusLink* link = (FocusLink*) iter.First();
  172.         while (link != kODNULL)
  173.         {
  174.             foundFocus = link->fFocus;
  175.     
  176.             if (foundFocus == focus) 
  177.             {
  178.                 containsFocus = kODTrue;
  179.                 break;    
  180.             }
  181.             else
  182.                 link = (FocusLink*) iter.Next();
  183.         }    
  184.  
  185.     SOM_CATCH_ALL
  186.     SOM_ENDTRY
  187.     
  188.     return containsFocus;
  189. }
  190.  
  191. SOM_Scope ODFocusSetIterator*  SOMLINK ODFocusSetCreateIterator(ODFocusSet *somSelf, Environment *ev)
  192. {
  193.     ODFocusSetData *somThis = ODFocusSetGetData(somSelf);
  194.     ODFocusSetMethodDebug("ODFocusSet","ODFocusSetCreateIterator");
  195.  
  196.     ODFocusSetIterator* iterator = kODNULL; ODVolatile(iterator);
  197.     
  198.     SOM_TRY
  199.     
  200.         iterator = new ODFocusSetIterator;
  201.         THROW_IF_NULL(iterator);
  202.         iterator->InitFocusSetIterator(ev,somSelf);
  203.         
  204.     SOM_CATCH_ALL
  205.     
  206.         ODDeleteObject(iterator);
  207.         
  208.     SOM_ENDTRY
  209.     
  210.     return iterator;
  211. }
  212.  
  213. SOM_Scope ODULong  SOMLINK ODFocusSetAddIterator(ODFocusSet *somSelf, Environment *ev,
  214.         ODFocusSetIterator* iterator)
  215. {
  216.     ODFocusSetData *somThis = ODFocusSetGetData(somSelf);
  217.     ODFocusSetMethodDebug("ODFocusSet","ODFocusSetAddIterator");
  218.  
  219.     LinkedListIterator* iter = kODNULL; ODVolatile(iter);
  220.  
  221.     SOM_TRY
  222.     
  223.         iter = new LinkedListIterator(_fImplementation);
  224.         
  225.     SOM_CATCH_ALL
  226.     
  227.         ODDeleteObject(iter);
  228.         
  229.     SOM_ENDTRY
  230.  
  231.     return (ODULong) iter;
  232. }
  233.  
  234. SOM_Scope ODTypeToken  SOMLINK ODFocusSetFirst(ODFocusSet *somSelf, Environment *ev,
  235.         ODULong iteratorID)
  236. {
  237.     ODFocusSetData *somThis = ODFocusSetGetData(somSelf);
  238.     ODFocusSetMethodDebug("ODFocusSet","ODFocusSetFirst");
  239.  
  240.     ODTypeToken focus = kODNullFocus;
  241.  
  242.     SOM_TRY
  243.     
  244.         LinkedListIterator* iterator = (LinkedListIterator*) iteratorID; 
  245.         FocusLink* link = (FocusLink*) iterator->First();
  246.         if (link)
  247.             focus = link->fFocus;
  248.  
  249.     SOM_CATCH_ALL
  250.     SOM_ENDTRY
  251.     
  252.     return focus;
  253. }
  254.  
  255. SOM_Scope ODTypeToken  SOMLINK ODFocusSetNext(ODFocusSet *somSelf, Environment *ev,
  256.         ODULong iteratorID)
  257. {
  258.     ODFocusSetData *somThis = ODFocusSetGetData(somSelf);
  259.     ODFocusSetMethodDebug("ODFocusSet","ODFocusSetNext");
  260.  
  261.     ODTypeToken focus = kODNullFocus;
  262.  
  263.     SOM_TRY
  264.  
  265.         LinkedListIterator* iterator = (LinkedListIterator*) iteratorID; 
  266.         FocusLink* link = (FocusLink*) iterator->Next();
  267.         if (link)
  268.             focus = link->fFocus;
  269.             
  270.     SOM_CATCH_ALL
  271.     SOM_ENDTRY
  272.     
  273.     return focus;
  274. }
  275.  
  276. SOM_Scope ODBoolean  SOMLINK ODFocusSetIsNotComplete(ODFocusSet *somSelf, Environment *ev,
  277.         ODULong iteratorID)
  278. {
  279.     ODFocusSetData *somThis = ODFocusSetGetData(somSelf);
  280.     ODFocusSetMethodDebug("ODFocusSet","ODFocusSetIsNotComplete");
  281.     
  282.     ODBoolean isNotComplete = kODFalse;
  283.  
  284.     SOM_TRY
  285.  
  286.         LinkedListIterator* iterator = (LinkedListIterator*) iteratorID; 
  287.         isNotComplete = iterator->IsNotComplete();
  288.     
  289.     SOM_CATCH_ALL
  290.     SOM_ENDTRY
  291.  
  292.     return isNotComplete;
  293. }
  294.  
  295. SOM_Scope void  SOMLINK ODFocusSetRemoveIterator(ODFocusSet *somSelf, Environment *ev,
  296.         ODULong iteratorID)
  297. {
  298.     ODFocusSetData *somThis = ODFocusSetGetData(somSelf);
  299.     ODFocusSetMethodDebug("ODFocusSet","ODFocusSetRemoveIterator");
  300.     
  301.     LinkedListIterator* iterator = (LinkedListIterator*) iteratorID; 
  302.     ODDeleteObject(iterator);
  303. }
  304.  
  305. SOM_Scope void  SOMLINK ODFocusSetsomUninit(ODFocusSet *somSelf)
  306. {
  307.     ODFocusSetData *somThis = ODFocusSetGetData(somSelf);
  308.     ODFocusSetMethodDebug("ODFocusSet","ODFocusSetsomUninit");
  309.  
  310.     _fImplementation->DeleteAllLinks();
  311.     ODDeleteObject(_fImplementation);
  312.     parent_somUninit(somSelf);
  313. }
  314.