home *** CD-ROM | disk | FTP | other *** search
/ Big Green CD 8 / BGCD_8_Dev.iso / YellowBox / Kits / MiscTableScroll-138.1 / Palettes / MiscTableScroll / Framework / MiscTableScrollSel.M < prev    next >
Encoding:
Text File  |  1998-03-31  |  12.4 KB  |  365 lines

  1. //=============================================================================
  2. //
  3. //  Copyright (C) 1995,1996,1997,1998 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. // MiscTableScrollSel.M
  17. //
  18. //    Selection management methods for MiscTableScroll.
  19. //
  20. //-----------------------------------------------------------------------------
  21. //-----------------------------------------------------------------------------
  22. // $Id: MiscTableScrollSel.M,v 1.2 98/03/29 23:57:42 sunshine Exp $
  23. // $Log:    MiscTableScrollSel.M,v $
  24. // Revision 1.2  98/03/29  23:57:42  sunshine
  25. // v138.1: #import was missing "MiscTableScroll/" for public header.
  26. // 
  27. // Revision 1.1  97/11/23  07:39:13  sunshine
  28. // v130.1: Selection, keyboard and mouse routines for MiscTableScroll.
  29. //-----------------------------------------------------------------------------
  30. #import <MiscTableScroll/MiscTableScroll.h>
  31. #import "MiscColView.h"
  32. #import "MiscRowView.h"
  33. #import "MiscTableView.h"
  34. #import "MiscTableBorder.h"
  35.  
  36. @implementation MiscTableScroll(Selection)
  37. //-----------------------------------------------------------------------------
  38. // Enabled
  39. //-----------------------------------------------------------------------------
  40. - (BOOL)isEnabled            { return enabled; }
  41. - (void)setEnabled:(BOOL)flag        { enabled = flag; }
  42.  
  43.  
  44. //-----------------------------------------------------------------------------
  45. // Selection
  46. //-----------------------------------------------------------------------------
  47. - (void)selectionChanged
  48.     {
  49.     [rowInfo.view selectionChanged];
  50.     [colInfo.view selectionChanged];
  51.     [tableView selectionChanged];
  52.     }
  53.  
  54. - (void)resetSelection
  55.     {
  56.     [tableView resetSelection];
  57.     [rowInfo.view resetSelection];
  58.     [colInfo.view resetSelection];
  59.     }
  60.  
  61. - (void)trackBy:(MiscBorderType)b { [tableView trackBy:b]; }
  62. - (MiscBorderType)trackingBy { return [tableView trackingBy]; }
  63. - (BOOL)tracking { return tracking; }
  64. - (void)setTracking:(BOOL)flag { tracking = flag; }
  65.  
  66. - (MiscSelectionMode)selectionMode { return mode; }
  67. - (void)setSelectionMode:(MiscSelectionMode)x
  68.     {
  69.     if (x != mode)
  70.     {
  71.     [self clearSelection];
  72.     mode = x;
  73.     [colInfo.view setSelectionMode:mode];
  74.     [rowInfo.view setSelectionMode:mode];
  75.     [tableView setSelectionMode:mode];
  76.     }
  77.     }
  78.  
  79. - (id)selectedCell
  80.     {
  81.     MiscCoord_P const col = [self selectedColumn];
  82.     MiscCoord_P const row = [self selectedRow];
  83.     return (col >= 0 && row >= 0) ? [self cellAtRow:row column:col] : 0;
  84.     }
  85.  
  86. - (BOOL)hasSlotSelection:(MiscBorderType)b
  87.     { return info[b]->border->hasSelection(); }
  88. - (BOOL)hasRowSelection { return [self hasSlotSelection:MISC_ROW_BORDER]; }
  89. - (BOOL)hasColumnSelection { return [self hasSlotSelection:MISC_COL_BORDER]; }
  90.  
  91. - (BOOL)hasMultipleSlotSelection:(MiscBorderType)b
  92.     { return info[b]->border->hasMultipleSelection(); }
  93. - (BOOL)hasMultipleRowSelection
  94.     { return [self hasMultipleSlotSelection:MISC_ROW_BORDER]; }
  95. - (BOOL)hasMultipleColumnSelection
  96.     { return [self hasMultipleSlotSelection:MISC_COL_BORDER]; }
  97.  
  98. - (unsigned int)numberOfSelectedSlots:(MiscBorderType)b
  99.     { return info[b]->border->numSelected(); }
  100. - (unsigned int)numberOfSelectedRows
  101.     { return [self numberOfSelectedSlots:MISC_ROW_BORDER]; }
  102. - (unsigned int)numberOfSelectedColumns
  103.     { return [self numberOfSelectedSlots:MISC_COL_BORDER]; }
  104.  
  105. - (BOOL)border:(MiscBorderType)b slotIsSelected:(MiscCoord_P)slot
  106.     {
  107.     MiscTableBorder const* bp = info[b]->border;
  108.     return bp->goodPos( slot ) && bp->isSelected_P( slot );
  109.     }
  110. - (BOOL)rowIsSelected:(MiscCoord_P)row
  111.     { return [self border:MISC_ROW_BORDER slotIsSelected:row]; }
  112. - (BOOL)columnIsSelected:(MiscCoord_P)col
  113.     { return [self border:MISC_COL_BORDER slotIsSelected:col]; }
  114. - (BOOL)cellIsSelectedAtRow:(MiscCoord_P)r column:(MiscCoord_P)c
  115.     { return ([self rowIsSelected:r] || [self columnIsSelected:c]); }
  116.  
  117. - (MiscCoord_P)selectedSlot:(MiscBorderType)b
  118.     { return info[b]->border->selectedSlot_P(); }
  119. - (MiscCoord_P)selectedRow
  120.     { return [self selectedSlot:MISC_ROW_BORDER]; }
  121. - (MiscCoord_P)selectedColumn
  122.     { return [self selectedSlot:MISC_COL_BORDER]; }
  123.  
  124. - (NSArray*)selectedSlotTags:(MiscBorderType)b
  125.     { return info[b]->border->selectedTags(); }
  126. - (NSArray*)selectedRowTags
  127.     { return [self selectedSlotTags:MISC_ROW_BORDER]; }
  128. - (NSArray*)selectedColumnTags
  129.     { return [self selectedSlotTags:MISC_COL_BORDER]; }
  130.  
  131. - (NSArray*)selectedSlots:(MiscBorderType)b
  132.     { return info[b]->border->selectedSlots(); }
  133. - (NSArray*)selectedRows { return [self selectedSlots:MISC_ROW_BORDER]; }
  134. - (NSArray*)selectedColumns { return [self selectedSlots:MISC_COL_BORDER]; }
  135.  
  136. - (void)border:(MiscBorderType)b selectSlot:(MiscCoord_P)p_slot
  137.     byExtension:(BOOL)extend
  138.     {
  139.     BOOL changed = NO;
  140.     MiscTableBorder* const ob = info[ MISC_OTHER_BORDER(b) ]->border;
  141.     if (ob->hasSelection())
  142.         {
  143.         ob->selectNone();
  144.         changed = YES;
  145.         }
  146.     MiscTableBorder* const bp = info[b]->border;
  147.     if (!extend && bp->numSelected() > 0)
  148.         {
  149.         bp->selectNone();
  150.         changed = YES;
  151.         }
  152.     if (bp->goodPos( p_slot ))
  153.         {
  154.         MiscCoord_V const v_slot = bp->physicalToVisual( p_slot );
  155.         if (!bp->isSelected( v_slot ))
  156.         {
  157.         if (mode == MISC_RADIO_MODE)
  158.             bp->selectOne( v_slot );
  159.         else
  160.             bp->select( v_slot );
  161.         changed = YES;
  162.         }
  163.         }
  164.     if (changed)
  165.         [self selectionChanged];
  166.     }
  167. - (void)border:(MiscBorderType)b selectSlot:(MiscCoord_P)p_slot
  168.     { [self border:b selectSlot:p_slot byExtension:NO]; }
  169. - (void)selectRow:(MiscCoord_P)row byExtension:(BOOL)extend
  170.     { [self border:MISC_ROW_BORDER selectSlot:row byExtension:extend]; }
  171. - (void)selectRow:(MiscCoord_P)row
  172.     { [self selectRow:row byExtension:NO]; }
  173. - (void)selectColumn:(MiscCoord_P)col byExtension:(BOOL)extend
  174.     { [self border:MISC_COL_BORDER selectSlot:col byExtension:extend]; }
  175. - (void)selectColumn:(MiscCoord_P)col
  176.     { [self selectColumn:col byExtension:NO]; }
  177.  
  178. - (void)border:(MiscBorderType)b selectSlotTags:(NSArray*)tags
  179.     byExtension:(BOOL)extend
  180.     {
  181.     info[b]->border->selectTags( tags, extend );
  182.     [self selectionChanged];
  183.     }
  184. - (void)border:(MiscBorderType)b selectSlotTags:(NSArray*)tags
  185.     { [self border:b selectSlotTags:tags byExtension:NO]; }
  186. - (void)selectRowTags:(NSArray*)tags byExtension:(BOOL)flag
  187.     { [self border:MISC_ROW_BORDER selectSlotTags:tags byExtension:flag]; }
  188. - (void)selectRowTags:(NSArray*)tags
  189.     { [self selectRowTags:tags byExtension:NO]; }
  190. - (void)selectColumnTags:(NSArray*)tags byExtension:(BOOL)flag
  191.     { [self border:MISC_COL_BORDER selectSlotTags:tags byExtension:flag]; }
  192. - (void)selectColumnTags:(NSArray*)tags
  193.     { [self selectColumnTags:tags byExtension:NO]; }
  194.  
  195. - (void)border:(MiscBorderType)b selectSlots:(NSArray*)slots
  196.     byExtension:(BOOL)extend
  197.     {
  198.     info[b]->border->selectSlots( slots, extend );
  199.     [self selectionChanged];
  200.     }
  201. - (void)border:(MiscBorderType)b selectSlots:(NSArray*)slots
  202.     { [self border:b selectSlots:slots byExtension:NO]; }
  203. - (void)selectRows:(NSArray*)rows byExtension:(BOOL)extend
  204.     { [self border:MISC_ROW_BORDER selectSlots:rows byExtension:extend]; }
  205. - (void)selectRows:(NSArray*)rows
  206.     { [self selectRows:rows byExtension:NO]; }
  207. - (void)selectColumns:(NSArray*)cols byExtension:(BOOL)extend
  208.     { [self border:MISC_COL_BORDER selectSlots:cols byExtension:extend]; }
  209. - (void)selectColumns:(NSArray*)cols
  210.     { [self selectColumns:cols byExtension:NO]; }
  211.  
  212. - (void)selectAllSlots:(MiscBorderType)b
  213.     {
  214.     if (mode == MISC_LIST_MODE || mode == MISC_HIGHLIGHT_MODE)
  215.         {
  216.         info[b]->border->selectAll();
  217.         [self selectionChanged];
  218.         }
  219.     }
  220. - (void)selectAllRows { [self selectAllSlots:MISC_ROW_BORDER]; }
  221. - (void)selectAllColumns { [self selectAllSlots:MISC_COL_BORDER]; }
  222. - (void)selectAll:(id)sender
  223.     {
  224.     [self selectAllRows];
  225.     [self sendActionIfEnabled];
  226.     }
  227.  
  228. - (void)border:(MiscBorderType)b deselectSlot:(MiscCoord_P)p_slot
  229.     {
  230.     MiscTableBorder* const bp = info[b]->border;
  231.     if (bp->goodPos( p_slot ))
  232.         {
  233.         MiscCoord_V const v_slot = bp->physicalToVisual( p_slot );
  234.         if (bp->isSelected( v_slot ))
  235.         {
  236.         bp->unselect( v_slot );
  237.         [self selectionChanged];
  238.         }
  239.         }
  240.     }
  241. - (void)deselectRow:(MiscCoord_P)row
  242.     { [self border:MISC_ROW_BORDER deselectSlot:row]; }
  243. - (void)deselectColumn:(MiscCoord_P)col
  244.     { [self border:MISC_COL_BORDER deselectSlot:col]; }
  245.  
  246. - (void)border:(MiscBorderType)b deselectSlotTags:(NSArray*)tags
  247.     {
  248.     info[b]->border->unselectTags( tags );
  249.     [self selectionChanged];
  250.     }
  251. - (void)deselectRowTags:(NSArray*)tags
  252.     { [self border:MISC_ROW_BORDER deselectSlotTags:tags]; }
  253. - (void)deselectColumnTags:(NSArray*)tags
  254.     { [self border:MISC_COL_BORDER deselectSlotTags:tags]; }
  255.  
  256. - (void)border:(MiscBorderType)b deselectSlots:(NSArray*)slots
  257.     {
  258.     info[b]->border->unselectSlots( slots );
  259.     [self selectionChanged];
  260.     }
  261. - (void)deselectRows:(NSArray*)rows
  262.     { [self border:MISC_ROW_BORDER deselectSlots:rows]; }
  263. - (void)deselectColumns:(NSArray*)cols
  264.     { [self border:MISC_COL_BORDER deselectSlots:cols]; }
  265.  
  266. - (void)clearSlotSelection:(MiscBorderType)b
  267.     {
  268.     info[b]->border->selectNone();
  269.     [self selectionChanged];
  270.     }
  271. - (void)clearRowSelection { [self clearSlotSelection:MISC_ROW_BORDER]; }
  272. - (void)clearColumnSelection { [self clearSlotSelection:MISC_COL_BORDER]; }
  273. - (void)clearSelection
  274.     {
  275.     [self clearRowSelection];
  276.     [self clearColumnSelection];
  277.     }
  278. - (void)deselectAll:(id)sender
  279.     {
  280.     [self clearSelection];
  281.     [self sendActionIfEnabled];
  282.     }
  283.  
  284.  
  285. //-----------------------------------------------------------------------------
  286. // Clicked slot stuff
  287. //-----------------------------------------------------------------------------
  288. - (MiscCoord_P)clickedSlot:(MiscBorderType)b
  289.     { return info[b]->border->clickedSlot_P(); }
  290. - (MiscCoord_P)clickedRow
  291.     { return [self clickedSlot:MISC_ROW_BORDER]; }
  292. - (MiscCoord_P)clickedColumn
  293.     { return [self clickedSlot:MISC_COL_BORDER]; }
  294. - (id)clickedCell
  295.     {
  296.     MiscCoord_P const r = [self clickedRow];
  297.     MiscCoord_P const c = [self clickedColumn];
  298.     return (r >= 0 && c >= 0 ? [self cellAtRow:r column:c] : 0);
  299.     }
  300.  
  301. - (void)border:(MiscBorderType)b setClickedSlot:(MiscCoord_P)n
  302.     { info[b]->border->setClickedSlot_P(n); }
  303. - (void)setClickedRow:(MiscCoord_P)r column:(MiscCoord_P)c
  304.     {
  305.     [self border:MISC_ROW_BORDER setClickedSlot:r];
  306.     [self border:MISC_COL_BORDER setClickedSlot:c];
  307.     }
  308.  
  309. - (void)borderClearClickedSlot:(MiscBorderType)b
  310.     { info[b]->border->clearClickedSlot(); }
  311. - (void)clearClicked
  312.     {
  313.     [self borderClearClickedSlot:MISC_ROW_BORDER];
  314.     [self borderClearClickedSlot:MISC_COL_BORDER];
  315.     }
  316.  
  317.  
  318. //-----------------------------------------------------------------------------
  319. // Keyboard cursor stuff
  320. //-----------------------------------------------------------------------------
  321. - (void)reflectCursor { [tableView reflectCursor]; }
  322. - (MiscCoord_P)cursorSlot:(MiscBorderType)b
  323.     { return info[b]->border->getCursor_P(); }
  324. - (MiscCoord_P)cursorRow { return [self cursorSlot:MISC_ROW_BORDER]; }
  325. - (MiscCoord_P)cursorColumn { return [self cursorSlot:MISC_COL_BORDER]; }
  326.  
  327. - (void)border:(MiscBorderType)b setCursorSlot:(MiscCoord_P)slot
  328.     { info[b]->border->setCursor_P( slot ); [self reflectCursor]; }
  329. - (void)setCursorRow:(MiscCoord_P)row
  330.     { [self border:MISC_ROW_BORDER setCursorSlot:row]; }
  331. - (void)setCursorColumn:(MiscCoord_P)col
  332.     { [self border:MISC_COL_BORDER setCursorSlot:col]; }
  333.  
  334. - (void)clearCursorSlot:(MiscBorderType)b
  335.     { info[b]->border->clearCursor(); [self reflectCursor]; }
  336. - (void)clearCursorRow { [self clearCursorSlot:MISC_ROW_BORDER]; }
  337. - (void)clearCursorColumn { [self clearCursorSlot:MISC_COL_BORDER]; }
  338. - (void)clearCursor { [self clearCursorRow]; [self clearCursorColumn]; }
  339.  
  340. - (BOOL)hasValidCursorSlot:(MiscBorderType)b
  341.     { return info[b]->border->hasValidCursor(); }
  342. - (BOOL)hasValidCursorRow
  343.     { return [self hasValidCursorSlot:MISC_ROW_BORDER]; }
  344. - (BOOL)hasValidCursorColumn
  345.     { return [self hasValidCursorSlot:MISC_COL_BORDER]; }
  346.  
  347. - (BOOL)isCursorEnabled { return [tableView isCursorEnabled]; }
  348. - (void)disableCursor
  349.     {
  350.     if ([self isCursorEnabled] && [tableView shouldDrawCursor])
  351.     [tableView eraseCursor];
  352.     [tableView disableCursor];
  353.     [self displayIfNeeded];
  354.     }
  355.  
  356. - (void)enableCursor
  357.     {
  358.     [tableView enableCursor];
  359.     if ([self isCursorEnabled] && [tableView shouldDrawCursor])
  360.     [tableView drawCursor];
  361.     [self displayIfNeeded];
  362.     }
  363.  
  364. @end
  365.