home *** CD-ROM | disk | FTP | other *** search
/ Tools / WinSN5.0Ver.iso / NETSCAP.50 / WIN1998.ZIP / ns / lib / mac / UserInterface / Tables / CTableKeyAttachment.cp < prev    next >
Encoding:
Text File  |  1998-04-08  |  4.7 KB  |  166 lines

  1. /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
  2.  *
  3.  * The contents of this file are subject to the Netscape Public License
  4.  * Version 1.0 (the "NPL"); you may not use this file except in
  5.  * compliance with the NPL.  You may obtain a copy of the NPL at
  6.  * http://www.mozilla.org/NPL/
  7.  *
  8.  * Software distributed under the NPL is distributed on an "AS IS" basis,
  9.  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
  10.  * for the specific language governing rights and limitations under the
  11.  * NPL.
  12.  *
  13.  * The Initial Developer of this code under the NPL is Netscape
  14.  * Communications Corporation.  Portions created by Netscape are
  15.  * Copyright (C) 1998 Netscape Communications Corporation.  All Rights
  16.  * Reserved.
  17.  */
  18.  
  19. #include "CTableKeyAttachment.h"
  20.  
  21. #include <PP_KeyCodes.h>
  22. #include <CSpecialTableView.h>
  23.  
  24. //testing
  25. #include "XP_Trace.h"
  26.  
  27.  
  28. CTableKeyAttachment::CTableKeyAttachment(CSpecialTableView* inView)
  29.     :    LKeyScrollAttachment(inView)
  30. {
  31.     mTableView = dynamic_cast<CSpecialTableView*>(mViewToScroll);
  32.     Assert_(mTableView);
  33. }
  34.  
  35. CTableKeyAttachment::~CTableKeyAttachment()
  36. {
  37. }
  38.  
  39.     
  40. void CTableKeyAttachment::ExecuteSelf(
  41.     MessageT        inMessage,
  42.     void            *ioParam)
  43. {
  44.     // In communicator, keyup events are turned on.  This is for the benefit of Java
  45.     // applets, and we don't want to handle them for key scrolling in tables.
  46.     
  47.     // Well, we do actually. If we get a keyDown event, or autokey events, we don't
  48.     // want to update the list until the user lets go. So we turn off broadcasting
  49.     // until we get a keyUp. We also don't want to change the selection on the keyup,
  50.     // since we've already done that for the corresponding keyDown/autoKey.
  51.     
  52.     if (inMessage != msg_KeyPress)
  53.         return;
  54.     
  55.     EventRecord*    eventParam = (EventRecord *)ioParam;
  56.         
  57.     mExecuteHost = false;
  58.     Int16 theKey = eventParam->message & charCodeMask;
  59.     //Boolean bCommandDown = (eventParam->modifiers & cmdKey) != 0;
  60.     Boolean bShiftDown = (eventParam->modifiers & shiftKey) != 0;
  61.     //Boolean bOptionDown = (eventParam->modifiers & optionKey) != 0;
  62.     Boolean bControlDown = (eventParam->modifiers & controlKey) != 0;
  63.     // get the table dimensions
  64.     TableIndexT theRowCount, theColCount;        
  65.     mTableView->GetTableSize(theRowCount, theColCount);
  66.     
  67.     if (theKey == char_DownArrow || theKey == char_UpArrow) {
  68.         if (eventParam->what == keyDown || eventParam->what == autoKey) {
  69.             mTableView->SetNotifyOnSelectionChange(false);
  70.         } else if (eventParam->what == keyUp)
  71.         {
  72.             mTableView->SetNotifyOnSelectionChange(true);
  73.             mTableView->SelectionChanged();
  74.             return;
  75.         }
  76.     }
  77.     
  78.     switch (theKey)
  79.     {
  80.         case char_PageUp:
  81.         case char_PageDown:
  82.             LKeyScrollAttachment::ExecuteSelf(inMessage, ioParam);
  83.             break;
  84.         case char_DownArrow:
  85.         if (!bControlDown)
  86.         {
  87.             // Get the last currently selected cell
  88.             STableCell afterLastSelectedCell, theCell; // inited to 0,0 in constructor
  89.             // Keep a copy of theCell, because GetNextSelectedCell clobbers it if
  90.             // there are no more selected cells.
  91.             while (mTableView->GetNextSelectedCell(theCell))
  92.             {
  93.                 theCell.row++;
  94.                 afterLastSelectedCell = theCell;
  95.             }
  96.             if (afterLastSelectedCell.row == 0) // there were none selected
  97.             {
  98.                 theCell.row = theRowCount;
  99.                 theCell.col = 1;
  100.             }
  101.             else
  102.             {
  103.                 theCell = afterLastSelectedCell;
  104.             }
  105.             if (mTableView->IsValidCell(theCell))
  106.                 SelectCell(theCell, bShiftDown);
  107.             break;
  108.         }
  109.         // else falls through
  110.         
  111.         case char_End:
  112.             {
  113.             STableCell theLastCell(theRowCount, theColCount);
  114.             SelectCell(theLastCell, bShiftDown);
  115.             }
  116.             break;
  117.         
  118.         case char_UpArrow:
  119.         if (!bControlDown)
  120.             {
  121.             // Get the first currently selected cell
  122.             STableCell theCell; // inited to 0,0 in constructor
  123.             if (mTableView->GetNextSelectedCell(theCell))
  124.                 theCell.row--;
  125.             else
  126.             {
  127.                 theCell.row = 1;
  128.                 theCell.col = 1;
  129.             }
  130.             if (mTableView->IsValidCell(theCell))
  131.                 SelectCell(theCell, bShiftDown);
  132.             break;
  133.             }
  134.         // else falls through
  135.         
  136.         case char_Home:
  137.             {
  138.             STableCell theFirstCell(1,1);
  139.             if (mTableView->IsValidCell(theFirstCell))
  140.                 SelectCell(theFirstCell, bShiftDown);
  141.             }
  142.             break;
  143.         
  144.         default:
  145.             mExecuteHost = true;    // Some other key, let host respond
  146.             break;
  147.         }
  148. }
  149.  
  150.  
  151.  
  152. void
  153. CTableKeyAttachment::SelectCell( const STableCell& inCell, Boolean multiple)
  154. {
  155.     if (!multiple)
  156.     {
  157.         Boolean        oldNotify = mTableView->GetNotifyOnSelectionChange();
  158.         
  159.         mTableView->SetNotifyOnSelectionChange(false);
  160.         mTableView->UnselectAllCells();
  161.         mTableView->SetNotifyOnSelectionChange(oldNotify);
  162.     }
  163.     mTableView->ScrollCellIntoFrame(inCell); // Do this before selecting (avoids turds)
  164.     mTableView->SelectCell(inCell);
  165. }
  166.