home *** CD-ROM | disk | FTP | other *** search
/ Big Green CD 8 / BGCD_8_Dev.iso / YellowBox / Kits / MiscTableScroll-138.1 / Palettes / MiscTableScroll / Framework / MiscTableBorderSel.cc < prev    next >
Encoding:
C/C++ Source or Header  |  1998-03-31  |  5.3 KB  |  176 lines

  1. //=============================================================================
  2. //
  3. //    Copyright (C) 1995-1997 by Paul S. McCarthy and Eric Sunshine.
  4. //        Written by Paul S. McCarthy and Eric Sunshine.
  5. //                All Rights Reserved.
  6. //
  7. //    This notice may not be removed from this source code.
  8. //
  9. //    This object is included in the MiscKit by permission from the authors
  10. //    and its use is governed by the MiscKit license, found in the file
  11. //    "License.rtf" in the MiscKit distribution.  Please refer to that file
  12. //    for a list of all applicable permissions and restrictions.
  13. //    
  14. //=============================================================================
  15. //-----------------------------------------------------------------------------
  16. // MiscTableBorderSel.cc
  17. //
  18. //    Selection management methods for the MiscTableBorder class.
  19. //
  20. //-----------------------------------------------------------------------------
  21. //-----------------------------------------------------------------------------
  22. // $Id: MiscTableBorderSel.cc,v 1.2 97/11/24 03:03:48 sunshine Exp $
  23. // $Log:    MiscTableBorderSel.cc,v $
  24. // Revision 1.2  97/11/24  03:03:48  sunshine
  25. // v132.1: MiscTableBorder_sel --> MiscTableBorderSel
  26. // 
  27. // Revision 1.1  97/11/23  07:36:07  sunshine
  28. // v130.1: Selection management routines for MiscTableBorder.
  29. //-----------------------------------------------------------------------------
  30. #include "MiscTableBorder.h"
  31. extern "Objective-C" {
  32. #import <Foundation/NSArray.h>
  33. }
  34.  
  35. //-----------------------------------------------------------------------------
  36. // visualToPhysical
  37. //    Used to save the selection before sorting.
  38. //-----------------------------------------------------------------------------
  39. void MiscTableBorder::visualToPhysical( MiscSparseSet const& vset,
  40.                     MiscSparseSet& pset ) const
  41.     {
  42.     pset.empty();
  43.     unsigned int const lim = vset.numRanges();
  44.     for (unsigned int i = 0; i < lim; i++)
  45.     {
  46.     int lo, hi;
  47.     vset.getRangeAt( i, lo, hi );
  48.     for ( ; lo <= hi; lo++)
  49.         pset.add( visualToPhysical( lo ) );
  50.     }
  51.     }
  52.  
  53.  
  54. //-----------------------------------------------------------------------------
  55. // physicalToVisual
  56. //    Used to restore the selection after sorting.
  57. //-----------------------------------------------------------------------------
  58. void MiscTableBorder::physicalToVisual( MiscSparseSet const& pset,
  59.                     MiscSparseSet& vset ) const
  60.     {
  61.     vset.empty();
  62.     unsigned int const lim = pset.numRanges();
  63.     for (unsigned int i = 0; i < lim; i++)
  64.     {
  65.     int lo, hi;
  66.     pset.getRangeAt( i, lo, hi );
  67.     for ( ; lo <= hi; lo++)
  68.         vset.add( physicalToVisual( lo ) );
  69.     }
  70.     }
  71.  
  72.  
  73. //-----------------------------------------------------------------------------
  74. // hasMultipleSelection
  75. //-----------------------------------------------------------------------------
  76. bool MiscTableBorder::hasMultipleSelection() const
  77.     {
  78.     MiscCoord_V lo, hi;
  79.     selection.getTotalRange( lo, hi );
  80.     return hi > lo;
  81.     }
  82.  
  83.  
  84. //-----------------------------------------------------------------------------
  85. // selected_slots
  86. //-----------------------------------------------------------------------------
  87. NSArray* MiscTableBorder::selected_slots( bool do_tags ) const
  88.     {
  89.     NSMutableArray* array = [NSMutableArray array];
  90.     for (unsigned int i = 0, lim = selection.numRanges(); i < lim; i++)
  91.     {
  92.     MiscCoord_V lo, hi;
  93.     selection.getRangeAt( i, lo, hi );
  94.     for ( ; lo <= hi; lo++)
  95.         {
  96.         int n = (do_tags ? getTag(lo) : visualToPhysical(lo));
  97.         [array addObject:[NSNumber numberWithInt:n]];
  98.         }
  99.     }
  100.     return array;
  101.     }
  102.  
  103.  
  104. //-----------------------------------------------------------------------------
  105. // select_slots
  106. //-----------------------------------------------------------------------------
  107. void MiscTableBorder::select_slots( NSArray* list, bool clear, bool set )
  108.     {
  109.     if (clear)
  110.     selectNone();
  111.     int const lim = [list count];
  112.     if (lim > 0)
  113.     {
  114.     MiscCoord_V last_selected = -1;
  115.     for (int i = lim; i-- > 0; )
  116.         {
  117.         MiscCoord_P const p_slot = [[list objectAtIndex:i] intValue];
  118.         if (goodPos( p_slot ))
  119.         {
  120.         MiscCoord_V const v_slot = physicalToVisual( p_slot );
  121.         if (v_slot > last_selected) last_selected = v_slot;
  122.         if (set)
  123.             selection.add( v_slot );
  124.         else
  125.             selection.remove( v_slot );
  126.         }
  127.         }
  128.     if (set && last_selected != -1)
  129.         setSelectedSlot( last_selected );
  130.     else
  131.         fixSelectedSlot();
  132.     }
  133.     }
  134.  
  135.  
  136. //-----------------------------------------------------------------------------
  137. // select_tags
  138. //-----------------------------------------------------------------------------
  139. void MiscTableBorder::select_tags( NSArray* list, bool clear, bool set )
  140.     {
  141.     if (clear)
  142.     selectNone();
  143.     unsigned int const M = [list count];
  144.     if (M > 0)
  145.     {
  146.     MiscCoord_V last_selected = -1;
  147.     unsigned int i;
  148.     int* const v0 = (int*)malloc( M * sizeof(*v0) );
  149.     int const* const vM = v0 + M;
  150.  
  151.     for (i = 0; i < M; i++)
  152.         v0[i] = [[list objectAtIndex:i] intValue];
  153.     
  154.     unsigned int const N = count();
  155.     for (i = 0; i < N; i++)
  156.         {
  157.         int const t = getTag(i);        // MiscCoord_V
  158.         for (int const* v = v0; v < vM; v++)
  159.         if (*v == t)
  160.             {
  161.             if (int(i) > last_selected) last_selected = (MiscCoord_V)i;
  162.             if (set)
  163.             selection.add(i);
  164.             else
  165.             selection.remove(i);
  166.             break;
  167.             }
  168.         }
  169.     free( v0 );
  170.     if (set && last_selected != -1)
  171.         setSelectedSlot( last_selected );
  172.     else
  173.         fixSelectedSlot();
  174.     }
  175.     }
  176.