home *** CD-ROM | disk | FTP | other *** search
/ Tools / WinSN5.0Ver.iso / NETSCAP.50 / WIN1998.ZIP / ns / lib / mac / UserInterface / Tables / LTableHeader.h < prev    next >
Encoding:
C/C++ Source or Header  |  1998-04-08  |  8.4 KB  |  262 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/18/96 - Tim Craycroft
  22.  
  23. */
  24.  
  25.  
  26. #pragma once
  27.  
  28.  
  29. #include <LView.h>
  30. #include "UStdBevels.h"
  31.  
  32.  
  33.  
  34. //======================================
  35. class LTableHeader
  36. //======================================
  37. :    public LView
  38. ,    public LBroadcaster
  39. {
  40. public:
  41.     enum    { class_ID = 'tblH'                 };
  42.     enum    { msg_SortedColumnChanged = 'srtC'    };
  43.     enum    { kColumnStateResourceType = 'Cols'    };
  44.     typedef UInt16 ColumnIndexT;
  45.  
  46.     // This is the ioParam in the message broadcast
  47.     // when the sort order is changed (msg_SortedColumnChanged).
  48.     struct SortChange
  49.     {
  50.         PaneIDT            sortColumnID;    // pane id of header of sort column
  51.         ColumnIndexT    sortColumn;        // physical sort column
  52.         Boolean            reverseSort;    // was reverse sort specified ?
  53.     };
  54.  
  55.     LTableHeader(LStream *inStream);
  56.     virtual ~LTableHeader();
  57.     
  58.     
  59.     // PowerPlant hooks
  60.     virtual void    FinishCreateSelf();
  61.     virtual void    DrawSelf();
  62.     virtual void    Click(SMouseDownEvent &inMouseDown);
  63.     
  64.     virtual void    AdjustCursor(    Point inPortPt,
  65.                                     const EventRecord &inMacEvent);
  66.  
  67.     virtual void    ResizeFrameBy(    Int16    inWidthDelta,
  68.                                     Int16    inHeightDelta,
  69.                                     Boolean    inRefresh);
  70.  
  71.     // Column info access
  72.     inline ColumnIndexT        CountColumns() const         { return mColumnCount;          };
  73.     inline ColumnIndexT        CountVisibleColumns() const { return mLastVisibleColumn;     };
  74.     void                    SetRightmostVisibleColumn(ColumnIndexT inLastDesiredColumn);
  75.     ColumnIndexT            SumOfVisibleResizableWidths() const;
  76.     ColumnIndexT            ColumnFromID(PaneIDT inPaneID)    const;
  77.     ColumnIndexT            GetSortedColumn(PaneIDT& outHeaderPane) const;
  78.     ColumnIndexT            GetMinWidthOfRange(
  79.                                 ColumnIndexT    inFromColumn,
  80.                                 ColumnIndexT    inToColumn    ) const;
  81.     ColumnIndexT            GetWidthOfRange(
  82.                                 ColumnIndexT    inFromColumn,
  83.                                 ColumnIndexT    inToColumn    ) const;
  84.     Boolean                    IsSortedBackwards() const { return mSortedBackwards; }
  85.     Boolean                    IsColumnVisible(PaneIDT inID) {
  86.                                 LPane *thePane = GetColumnPane(ColumnFromID(inID));
  87.                                 return (thePane != nil ) ? thePane->IsVisible() : false;
  88.                             }
  89.     virtual void             SetSortedColumn(ColumnIndexT inColumn, Boolean inReverse, Boolean inRefresh=true);
  90.     void                     SetWithoutSort(ColumnIndexT inColumn, Boolean inReverse ,Boolean inRefresh= true);
  91.     virtual void             SimulateClick(PaneIDT inID);
  92.     virtual void             SetSortOrder(Boolean inReverse);
  93.     virtual bool            CycleSortDirection ( ColumnIndexT & ioColumn ) ;
  94.     
  95.     inline PaneIDT            GetColumnPaneID(ColumnIndexT inColumn) const;    // returns PaneID of column's header
  96.     SInt16                    GetColumnWidth(ColumnIndexT inColumn) const;    // returns column's width
  97.     SInt16                    GetColumnPosition(ColumnIndexT inColumn) const;    // returns column's horiz position
  98.     UInt16                    GetHeaderWidth() const;    // returns width occupied by columns
  99.  
  100.  
  101.     typedef UInt32    HeaderFlags;
  102.     enum {    kHeaderCanHideColumns    =    0x1 };    
  103.  
  104.     //-----------------------------------
  105.     typedef UInt32 ColumnFlags;
  106.     struct SColumnData
  107.     // All column data is stored in an array kept in a handle (resource type 'Cols')
  108.     // This is the data we store for each column - an array element within the handle
  109.     //-----------------------------------
  110.     {
  111.         PaneIDT            GetPaneID() const
  112.             {
  113.                 return paneID;
  114.             }
  115.         Boolean            CanResize() const
  116.             {
  117.                 return (flags & kColumnDoesNotResize) == 0;
  118.             }
  119.         Boolean            CanResizeTo(UInt16 inNewSize) const
  120.             {
  121.                 return CanResize()
  122.                             && (inNewSize >= kMinWidth || inNewSize > columnWidth);
  123.             }
  124.         Boolean            CanResizeBy(SInt16 inDelta) const
  125.             {
  126.                 return CanResize()
  127.                     && (inDelta > 0 || columnWidth + inDelta >= kMinWidth);
  128.             }
  129.         Boolean            CanSort() const
  130.             {
  131.                 return (flags & kColumnDoesNotSort) == 0;
  132.             }
  133.         Boolean            HasSortIcon() const
  134.             {
  135.                 return (flags & (kColumnDoesNotSort | kColumnSuppressSortIcon)) == 0;
  136.             }
  137.         Boolean            CanDisplayTitle() const
  138.             {
  139.                 return (flags & kColumnDoesNotDisplayTitle) == 0;
  140.             }
  141.         private:
  142.             enum 
  143.             {
  144.                 kColumnDoesNotSort        =    1<<0
  145.             ,    kColumnDoesNotResize    =    1<<1
  146.             ,    kColumnSuppressSortIcon    =    1<<2
  147.             ,    kColumnDoesNotMove        =    1<<3
  148.             ,    kColumnDoesNotDisplayTitle    = 1<<4
  149.             };
  150.         public:
  151.             enum  { kMinWidth = 16 };
  152.         // ---- Data:
  153.         public:
  154.             PaneIDT            paneID;
  155.             SInt16            columnWidth;
  156.             SInt16            columnPosition;        // meaningless when saved/read to/from disk
  157.             ColumnFlags        flags;
  158.     };    // ----- struct SColumnData
  159.     
  160.     struct SavedHeaderState
  161.     {
  162.         ColumnIndexT        columnCount;
  163.         ColumnIndexT        lastVisibleColumn;
  164.         ColumnIndexT        sortedColumn;
  165.         UInt16                pad;
  166.         SColumnData            columnData[1];    
  167.     };
  168.  
  169.     virtual void    WriteColumnState(LStream * inStream);
  170.     virtual void    ReadColumnState(LStream * inStream, Boolean inMoveHeaders = true);
  171.     SColumnData*    GetColumnData(ColumnIndexT inColumn) const
  172.                             { return &(*mColumnData)[inColumn - 1]; }
  173.     
  174. protected:
  175.     // Column geometry
  176.     ColumnIndexT    FindColumn( Point inLocalPoint ) const;
  177.     void            LocateColumn( ColumnIndexT inColumn, Rect & outWhere) const;
  178.     void            InvalColumn( ColumnIndexT inColumn);
  179.     void            ComputeColumnPositions();
  180.     virtual void    PositionOneColumnHeader( ColumnIndexT inColumn, Boolean inRefresh = true);
  181.     void            PositionColumnHeaders(Boolean inRefresh = true);
  182.     void            ConvertWidthsToAbsolute();
  183.     Boolean            RedistributeSpace(    ColumnIndexT    inFromCol,
  184.                                         ColumnIndexT    inToCol,
  185.                                         SInt16    inNewSpace,
  186.                                         SInt16    inOldSpace);
  187.                                         
  188.     SInt16            GetFixedWidthInRange(    ColumnIndexT    inFromCol,
  189.                                             ColumnIndexT    inToCol    );
  190.                                         
  191.  
  192.     // Column resizing
  193.     Boolean            IsInHorizontalSizeArea(Point inLocalPt, ColumnIndexT& outLeftColumn);
  194.     void            TrackColumnResize(const SMouseDownEvent    &inEvent, ColumnIndexT inLeftColumn);
  195.     virtual void    ComputeResizeDragRect(ColumnIndexT inLeftColumn, Rect    &outDragRect);
  196.     virtual void    ResizeColumn(ColumnIndexT inLeftColumn, SInt16 inLeftColumnDelta);
  197.     
  198.     // Column dragging
  199.     void            TrackColumnDrag(const SMouseDownEvent &    inEvent, ColumnIndexT inColumn);
  200.     virtual void    ComputeColumnDragRect(ColumnIndexT inColumn, Rect& outDragRect);
  201.     virtual void    MoveColumn(ColumnIndexT inColumn, ColumnIndexT inMoveTo);
  202.  
  203.     
  204.     // Column drawing
  205.     virtual void    DrawColumnBackground(const Rect& inWhere, Boolean inSortColumn);
  206.     virtual void    RedrawColumns(ColumnIndexT inFrom, ColumnIndexT inTo);                                
  207.  
  208.     // Column hiding
  209.     virtual void    ShowHideRightmostColumn(Boolean inShow);
  210.     
  211.     
  212.     // Private Column info
  213.     //
  214.     // These are all excellent candidates for inlines, but we'll
  215.     // let the compiler decide...
  216.     //
  217.     Boolean            CanColumnResize(ColumnIndexT inColumn)             const;
  218.     Boolean            CanColumnSort(ColumnIndexT inColumn)             const;
  219.     Boolean            ColumnHasSortIcon(ColumnIndexT inColumn)         const;
  220.     Boolean            CanHideColumns()                                 const;
  221.  
  222.     void             CheckVisible(ColumnIndexT inIndex) const
  223.         {
  224.             Assert_(inIndex > 0 && inIndex <= mLastVisibleColumn);
  225.         }
  226.     void             CheckLegal(ColumnIndexT inIndex) const
  227.         {
  228.             Assert_(inIndex > 0 && inIndex <= mColumnCount);
  229.         }
  230.     void             CheckLegalHigh(ColumnIndexT inIndex) const
  231.         {
  232.             Assert_(inIndex >= 0 && inIndex <= mColumnCount);
  233.         }
  234.     
  235.     LPane*    GetColumnPane(ColumnIndexT inColumn);
  236.  
  237. protected:
  238.     enum    
  239.     { 
  240.          kColumnMargin                 = 2,
  241.          kColumnHidingWidgetWidth     = 15
  242.     };
  243.  
  244.     HeaderFlags            mHeaderFlags;
  245.     SColumnData **        mColumnData;
  246.     SBevelColorDesc        mUnsortedBevel;
  247.     SBevelColorDesc        mSortedBevel;
  248.  
  249.     ColumnIndexT        mColumnCount;        // 1-based count of all columns
  250.     ColumnIndexT        mLastVisibleColumn;    // 1-based index of rightmost visible column
  251.     ColumnIndexT        mSortedColumn;        // 1-based index of sorted columns
  252.     Boolean                mSortedBackwards;
  253.     UInt16                mReverseModifiers;    // key event modifier bit-mask for reverse-sort
  254.     SInt16                mFixedWidth;        // total width occupied by visible fixed-size columns
  255.     Int16                mColumnListResID;
  256.  
  257. };
  258.  
  259.  
  260.  
  261.  
  262.