home *** CD-ROM | disk | FTP | other *** search
/ Tools / WinSN5.0Ver.iso / NETSCAP.50 / WIN1998.ZIP / ns / lib / mac / UserInterface / Tables / LFlexTableGeometry.cp < prev    next >
Encoding:
Text File  |  1998-04-08  |  4.6 KB  |  232 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/25/96 - Tim Craycroft
  22.  
  23. */
  24.  
  25. #include "LFlexTableGeometry.h"
  26.  
  27.  
  28. /*
  29.     LFlexTableGeometry::LFlexTableGeometry    
  30. */
  31. LFlexTableGeometry::LFlexTableGeometry(    LTableView        *inTableView,
  32.                                         LTableHeader    *inTableHeader)
  33.     : LTableGeometry(inTableView)
  34. {
  35.     mTableHeader = inTableHeader;
  36.     mRowCount      = 0;
  37.     
  38.     // set to a reasonable default
  39.     //
  40.     // this class has no other inteligence for determining this value
  41.     //
  42.     SetRowHeight(16, 0, 0);
  43. }
  44.  
  45.  
  46.  
  47. /*
  48.     LFlexTableGeometry::GetImageCellBounds    
  49.     
  50.     Get the column position from the header view and compute
  51.     the row position.
  52. */
  53. void        
  54. LFlexTableGeometry::GetImageCellBounds(    const STableCell    &inCell,
  55.                                         Int32                &outLeft,
  56.                                         Int32                &outTop,
  57.                                         Int32                &outRight,
  58.                                         Int32                &outBottom) const
  59. {    
  60.     if (inCell.col > 0 && inCell.col <= mTableHeader->CountColumns())
  61.     {
  62.         outLeft  = mTableHeader->GetColumnPosition(inCell.col);
  63.         outRight = outLeft + mTableHeader->GetColumnWidth(inCell.col);
  64.             
  65.         outTop         = (inCell.row-1) * mRowHeight;
  66.         outBottom    = outTop + mRowHeight;
  67.  
  68.         SDimension32 imageSize;
  69.         mTableView->GetImageSize(imageSize);
  70.         if ( outLeft < 0 ) outLeft = 0;
  71.         if ( outRight > imageSize.width ) outRight = imageSize.width;
  72.     }
  73.     else {
  74.         outLeft = outTop = outRight = outBottom = 0;
  75.     }
  76. }
  77.  
  78.  
  79.  
  80. /*
  81.     LFlexTableGeometry::GetRowHitBy    
  82. */
  83. TableIndexT    
  84. LFlexTableGeometry::GetRowHitBy(const SPoint32    &inImagePt) const
  85. {
  86.     return (inImagePt.v / mRowHeight) + 1;
  87. }
  88.                                 
  89.  
  90. /*
  91.     LFlexTableGeometry::GetColHitBy    
  92. */
  93. TableIndexT    
  94. LFlexTableGeometry::GetColHitBy(const SPoint32    &inImagePt) const
  95. {
  96.     UInt16    i, nColumns;
  97.     
  98.     nColumns = mTableHeader->CountVisibleColumns();
  99.     
  100.     for (i=2; i<=nColumns; i++)
  101.     {
  102.         if (inImagePt.h < mTableHeader->GetColumnPosition(i)) {
  103.             return i-1;
  104.         }
  105.     }
  106.     
  107.     return nColumns;
  108.  
  109. }
  110.  
  111.  
  112.  
  113. /*
  114.     LFlexTableGeometry::SetRowHeight
  115.     
  116.     Changes row height for ALL rows and sets the scroll
  117.     unit of the table view to the row height.    
  118. */
  119. void
  120. LFlexTableGeometry::SetRowHeight(    Uint16        inHeight,
  121.                                     TableIndexT    inFromRow,
  122.                                     TableIndexT    inToRow)
  123. {
  124.     #pragma unused(inFromRow, inToRow)
  125.     
  126.     mRowHeight = inHeight;
  127.     
  128.     SPoint32    scrollUnit;
  129.     scrollUnit.h = 0;
  130.     scrollUnit.v = mRowHeight;
  131.     mTableView->SetScrollUnit(scrollUnit);
  132. }
  133.  
  134.  
  135.  
  136. /*
  137.     LFlexTableGeometry::GetTableDimensions
  138. */
  139. void
  140. LFlexTableGeometry::GetTableDimensions(    Uint32        &outWidth,
  141.                                         Uint32        &outHeight) const
  142. {
  143.     outHeight     = CountRows() * mRowHeight;
  144.     outWidth    = mTableHeader->GetHeaderWidth();
  145. }                                        
  146.     
  147.  
  148.  
  149. /*
  150.     LFlexTableGeometry::GetRowHeight
  151. */
  152. Uint16
  153. LFlexTableGeometry::GetRowHeight(TableIndexT    inRow) const
  154. {
  155.     #pragma unused(inRow)
  156.     return mRowHeight;
  157. }
  158.                                 
  159.                                 
  160. /*
  161.     LFlexTableGeometry::GetColWidth
  162. */
  163. Uint16        
  164. LFlexTableGeometry::GetColWidth(TableIndexT    inCol) const
  165. {
  166.     return mTableHeader->GetColumnWidth(inCol);
  167. }
  168.                             
  169.                             
  170.  
  171. /*
  172.     LFlexTableGeometry::InsertRows
  173. */
  174. void        
  175. LFlexTableGeometry::InsertRows(    Uint32        inHowMany,
  176.                                 TableIndexT    inAfterRow )
  177. {
  178.     #pragma unused(inAfterRow)
  179.     
  180.     mRowCount += inHowMany;
  181. }                            
  182.  
  183.     
  184. /*
  185.     LFlexTableGeometry::RemoveRows
  186. */
  187. void        
  188. LFlexTableGeometry::RemoveRows(    Uint32        inHowMany,
  189.                                 TableIndexT    inFromRow)
  190. {
  191.     #pragma unused(inFromRow)
  192.  
  193.     mRowCount -= inHowMany;
  194. }
  195.                                 
  196.                             
  197.  
  198. /*
  199.     LFlexTableGeometry::CountRows
  200. */
  201. UInt32                
  202. LFlexTableGeometry::CountRows() const
  203. {
  204.     return mRowCount;
  205. }
  206.     
  207.     
  208.     
  209.     
  210. /*
  211.     LFlexTableGeometry::SetColWidth
  212.     
  213.     Invalid, since column widths are controlled by the mTableHeader
  214.     widget.
  215. */
  216. void        
  217. LFlexTableGeometry::SetColWidth(Uint16        inWidth,
  218.                                 TableIndexT inFromCol,
  219.                                 TableIndexT    inToCol)
  220. {
  221.     #pragma unused(inWidth, inFromCol, inToCol)
  222.     
  223.     // We get our widths from mTableHeader
  224.     SignalPStr_("\pLFlexTableGeometry does not support SetColWidth");
  225. }                                
  226.  
  227.  
  228.  
  229.  
  230.                                 
  231.                             
  232.