home *** CD-ROM | disk | FTP | other *** search
/ Tools / WinSN5.0Ver.iso / NETSCAP.50 / WIN1998.ZIP / ns / lib / mac / UserInterface / Tables / LTableViewHeader.cp < prev    next >
Encoding:
Text File  |  1998-04-08  |  4.9 KB  |  206 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. /*
  20.     
  21.     Created 3/20/96 - Tim Craycroft
  22.  
  23.     To Do:
  24.     
  25. */
  26.  
  27. #include "LTableViewHeader.h"
  28. #include "CSpecialTableView.h"
  29.  
  30. #include "LIconPane.h"
  31.  
  32. /*    LTableViewHeader::LTableViewHeader    */
  33. LTableViewHeader::LTableViewHeader(LStream *inStream)
  34. :    LTableHeader(inStream)
  35. ,    mTableViewID(0)
  36. ,    mTableView(NULL)
  37. {    
  38.     *inStream >> mTableViewID;
  39. }
  40.  
  41. /*    
  42.     LTableViewHeader::FinishCreateSelf
  43.     
  44.     Find the LTableView we're using    
  45. */
  46. void
  47. LTableViewHeader::FinishCreateSelf()
  48. {
  49.     LTableHeader::FinishCreateSelf();
  50.     LView *super = GetSuperView();
  51.     ThrowIfNULL_(super);    
  52.     mTableView = (CSpecialTableView *) super->FindPaneByID(mTableViewID);
  53.     Assert_(mTableView != NULL);
  54.     // NOTE: CStandardFlexTable must be created second.  Its FinishCreateSelf
  55.     // queries our mTableView member to make sure that this is true.
  56. }
  57.  
  58. /*    
  59.     LTableViewHeader::ChangeIconOfColumn
  60.     
  61.     Sets the icon id of the LIconPane inColumn to be inIconID. You'd better be
  62.     sure that inColumn really is an LIconPane if you're gonna do this
  63. */
  64. void LTableViewHeader::ChangeIconOfColumn( PaneIDT    inColumn, ResIDT    inIconID)
  65.     UInt16        col = ColumnFromID(inColumn);
  66.     LIconPane    *iconPane = dynamic_cast<LIconPane *>(GetColumnPane(col));
  67.     Assert_(iconPane);
  68. #ifdef DEBUG
  69.     if (iconPane)
  70. #endif
  71.         iconPane->SetIconID(inIconID);
  72. }
  73.  
  74. /*    
  75.     LTableViewHeader::ComputeResizeDragRect
  76.     
  77.     Extend the bottom of the rect to the bottom of the table
  78. */
  79. void
  80. LTableViewHeader::ComputeResizeDragRect(UInt16 inLeftColumn, Rect &outDragRect)
  81. {
  82.     LTableHeader::ComputeResizeDragRect(inLeftColumn, outDragRect);
  83.     outDragRect.bottom = GetGlobalBottomOfTable();    
  84. }
  85.  
  86.  
  87. /*    
  88.     LTableViewHeader::ComputeColumnDragRect
  89.     
  90.     Extend the bottom of the rect to the bottom of the table
  91. */
  92. void
  93. LTableViewHeader::ComputeColumnDragRect(UInt16 inLeftColumn, Rect &outDragRect)
  94. {
  95.     LTableHeader::ComputeColumnDragRect(inLeftColumn, outDragRect);
  96.     outDragRect.bottom = GetGlobalBottomOfTable();    
  97. }
  98.  
  99.  
  100. /*    
  101.     LTableViewHeader::GetGlobalBottomOfTable
  102.     
  103.     Returns bottom of the table in global coords
  104. */
  105. SInt16
  106. LTableViewHeader::GetGlobalBottomOfTable() const
  107. {
  108.     Rect    r;
  109.     
  110.     mTableView->CalcPortFrameRect(r);
  111.     
  112.     PortToGlobalPoint((botRight(r)));
  113.     return r.bottom;
  114. }
  115.  
  116.  
  117. /*    
  118.     LTableViewHeader::RedrawColumns
  119.     
  120.     Refreshes the appropriate cells in the table.
  121. */
  122. void
  123. LTableViewHeader::RedrawColumns(UInt16 inFrom, UInt16 inTo)
  124. {
  125.     LTableHeader::RedrawColumns(inFrom, inTo);
  126.     
  127.     Boolean        active;
  128.     TableIndexT    rows, cols;
  129.     STableCell    fromCell, toCell;
  130.     
  131.     active = mTableView->IsActive();
  132.  
  133.     mTableView->GetTableSize(rows,cols);
  134.     
  135.     
  136.     SPoint32        cellPt;
  137.     SDimension16    frameSize;
  138.  
  139.     mTableView->GetScrollPosition(cellPt);
  140.     mTableView->GetFrameSize(frameSize);
  141.     
  142.     mTableView->GetCellHitBy(cellPt, fromCell);
  143.     fromCell.col = inFrom;
  144.     
  145.     cellPt.v += frameSize.height - 1;
  146.     mTableView->GetCellHitBy(cellPt, toCell);
  147.     toCell.col = inTo;
  148.         
  149.     mTableView->RefreshCellRange(fromCell, toCell);
  150. }
  151.  
  152.  
  153. /*    
  154.     LTableViewHeader::ShowHideRightmostColumn
  155.     
  156.     Adds or removes a column in the table.
  157. */
  158. void    
  159. LTableViewHeader::ShowHideRightmostColumn(Boolean inShow)
  160. {
  161.     ColumnIndexT initialVisibleColumnCount = CountVisibleColumns();
  162.     LTableHeader::ShowHideRightmostColumn(inShow); // can fail, eg when no resizable columns left
  163.     if (initialVisibleColumnCount != CountVisibleColumns())
  164.     {
  165.         if (inShow)
  166.             mTableView->InsertCols(1, initialVisibleColumnCount, NULL, 0, true);
  167.         else
  168.             mTableView->RemoveCols(1, initialVisibleColumnCount, true);
  169.     }
  170. }
  171.  
  172.  
  173. /*    
  174.     LTableViewHeader::ResizeImageBy
  175.     
  176.     Adjust the table's image size.
  177. */
  178. void    
  179. LTableViewHeader::ResizeImageBy(    Int32    inWidthDelta, 
  180.                                     Int32     inHeightDelta,
  181.                                     Boolean inRefresh        )
  182. {
  183.     LView::ResizeImageBy(inWidthDelta, inHeightDelta, inRefresh);
  184.     if (mTableView) // warning: this can be called before FinishCreate!
  185.         mTableView->AdjustImageSize(inRefresh);
  186. }
  187.  
  188.  
  189. /*    
  190.     LTableViewHeader::ReadColumnState
  191.     
  192.     Adjust the table's image size.
  193. */
  194. void    
  195. LTableViewHeader::ReadColumnState(LStream * inStream, Boolean inMoveHeaders)
  196. {
  197.     LTableHeader::ReadColumnState(inStream, inMoveHeaders);    
  198.     if ( mTableView )
  199.     {
  200.         mTableView->SynchronizeColumnsWithHeader();
  201.     }
  202. }
  203.  
  204.  
  205.