home *** CD-ROM | disk | FTP | other *** search
/ Tools / WinSN5.0Ver.iso / NETSCAP.50 / WIN1998.ZIP / ns / lib / mac / UserInterface / Tables / CStandardFlexTable.h < prev    next >
Encoding:
C/C++ Source or Header  |  1998-04-08  |  14.1 KB  |  363 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 4/10/96 - Tim Craycroft
  22.  
  23. */
  24.  
  25. #pragma once
  26.  
  27. #include "CSpecialTableView.h"
  28. #include "CKeyUpReceiver.h"
  29.  
  30. #include <LCommander.h>
  31. #include <LListener.h>
  32. //#include <QAP_Assist.h>
  33.  
  34. #include "LTableViewHeader.h"
  35.     // Need LTableHeader here, need the whole thing in the .cp file.
  36.     // Might as well go the whole hog.
  37.  
  38. class CStandardFlexTable;
  39. class CClickTimer;
  40. class CInlineEditField;
  41.  
  42.  
  43. //========================================================================================
  44. class CTableHeaderListener : public LListener
  45. //========================================================================================
  46. {
  47.     friend class CStandardFlexTable;
  48.     CTableHeaderListener(CStandardFlexTable* inTable) : mTable(inTable) {}
  49.     void ListenToMessage(MessageT inMessage, void *ioParam);
  50. protected:
  51.     CStandardFlexTable* mTable;
  52. }; // class CTableHeaderListener
  53.  
  54.  
  55. class CInlineEditorListener : public LListener
  56. {
  57. public:
  58.     CInlineEditorListener ( CStandardFlexTable* inTable ) : mTable(inTable) { }
  59. protected:
  60.     void ListenToMessage(MessageT inMessage, void *ioParam);
  61.     CStandardFlexTable* mTable;
  62. }; // class CInlineEditorListener
  63.  
  64.  
  65. //========================================================================================
  66. class CStandardFlexTable
  67. // Base class of all our tables in Netscape.  Differs from LTableView in the essential
  68. // matter of allowing selection of an entire row only.
  69. //========================================================================================
  70. :    public CSpecialTableView
  71. ,    public LDragAndDrop
  72. ,    public LCommander
  73. ,    public LBroadcaster
  74. ,    public CKeyUpReceiver
  75. //,    public CQAPartnerTableMixin
  76. {
  77. private:
  78.     typedef CSpecialTableView Inherited;
  79.     friend class CTableHeaderListener;
  80.     friend class CClickTimer;
  81.     friend class CInlineEditorListener;
  82. public:
  83.     enum {
  84.         class_ID = 'sfTb',
  85.         msg_SelectionChanged = 'selC'
  86.     };
  87.     
  88.     PaneIDT                GetSortedColumn() const;
  89.     Boolean                IsSortedBackwards() const;
  90.     LTableViewHeader*    GetTableHeader() const { return mTableHeader; }
  91.     Boolean             IsColumnVisible(PaneIDT inID);
  92.     TableIndexT            GetSelectedRowCount() const;
  93.     virtual void        SelectionChanged();    
  94.     void                AddAttachmentFirst(
  95.                             LAttachment* inAttachment,
  96.                             Boolean inOwnsAttachment = true);
  97.                         // nb: AddAttachment adds at end.  But this can be called if you want the new attachment
  98.                         // to be executed before the existing ones.
  99.     virtual void        SetNotifyOnSelectionChange(Boolean inDoNotify);
  100.     virtual Boolean     GetNotifyOnSelectionChange();
  101.     void                SetRightmostVisibleColumn(UInt16 inLastDesiredColumn);
  102.  
  103.         // an externally public way to tell the table to begin an inplace edit. This is
  104.         // useful when handling menu commands, etc and not mouse clicks in the table.
  105.     void                DoInlineEditing ( const STableCell & inCell ) ;
  106.     
  107.     virtual void        RefreshCellRange(
  108.                             const STableCell    &inTopLeft,
  109.                             const STableCell    &inBotRight); // Overridden to fix a bug in PP.
  110.  
  111. protected:
  112.     enum { kMinRowHeight = 18, kDistanceFromIconToText = 5, kIconMargin = 4, kIndentPerLevel = 10,
  113.             kIconWidth = 16 };
  114.  
  115.     // for in-place editing, give the CInlineEditor this paneID.
  116.     enum { paneID_InlineEdit = 'EDIT' } ;
  117.     
  118. // ------------------------------------------------------------
  119. // Construction
  120. // ------------------------------------------------------------
  121.                         CStandardFlexTable(LStream *inStream);
  122.     virtual                ~CStandardFlexTable();
  123.     virtual void        SetUpTableHelpers();    
  124.     virtual void        SynchronizeColumnsWithHeader();
  125.  
  126. // ------------------------------------------------------------
  127. // Generic PowerPlant
  128. // ------------------------------------------------------------
  129.     virtual void        FinishCreateSelf();
  130.     virtual void        DrawSelf();        
  131.     virtual Boolean        HandleKeyPress(const EventRecord &inKeyEvent);
  132.  
  133.     virtual void        Click(SMouseDownEvent &inMouseDown);
  134.     virtual void        BeTarget();
  135.     virtual void        DontBeTarget();
  136.  
  137. // ------------------------------------------------------------
  138. // Sorting
  139. // ------------------------------------------------------------
  140.     virtual void        ChangeSort(const LTableHeader::SortChange* inSortChange);
  141.  
  142. // ------------------------------------------------------------
  143. // Selection, MouseDowns
  144. // ------------------------------------------------------------
  145.     virtual Boolean        ClickSelect(
  146.                                 const STableCell        &inCell,
  147.                                 const SMouseDownEvent    &inMouseDown);
  148.     virtual void        ClickSelf(const SMouseDownEvent &inMouseDown);
  149.     virtual Boolean        ClickDropFlag(
  150.                                 const STableCell    &inCell,
  151.                                 const SMouseDownEvent &inMouseDown);
  152.     virtual Boolean        CellSelects(const STableCell& inCell) const;
  153.     virtual Boolean        CellWantsClick ( const STableCell & /*inCell*/ ) const { return false; }
  154.     void                SetFancyDoubleClick(Boolean inFancy) { mFancyDoubleClick = inFancy; }
  155.     void                SetHiliteDisabled(Boolean inDisable) { mHiliteDisabled = inDisable; }
  156.     virtual void         HandleSelectionTracking ( const SMouseDownEvent & inMouseDown ) ;
  157.     virtual void        TrackSelection ( const SMouseDownEvent & inMouseDown ) ;
  158.     virtual Boolean     HitCellHotSpot ( const STableCell &inCell, 
  159.                                             const Rect &inTotalSelectionRect ) ;
  160.     virtual void        UnselectCellsNotInSelectionOutline ( const Rect & selectionRect ) ;
  161.         // override to turn off selection outline tracking
  162.     virtual Boolean        TableDesiresSelectionTracking ( ) { return true; }
  163.                                 
  164.     virtual const TableIndexT*    GetUpdatedSelectionList(TableIndexT& outSelectionSize);
  165.                             // Returns a ONE-BASED list of TableIndexT, as it should.
  166.                             // The result is const because this is not a copy, it is
  167.                             // the actual list cached in this object.  You probably want
  168.                             // to use CMailFlexTable::GetSelection() for messages stuff.
  169. public:
  170.     Boolean                GetNextSelectedRow(TableIndexT& inOutAfterRow) const;
  171.     Boolean                GetLastSelectedRow(TableIndexT& inOutBeforeRow) const;
  172. protected:
  173.     void                SelectRow(TableIndexT inRow);
  174.     void                ScrollRowIntoFrame(TableIndexT inRow);
  175.     void                ScrollSelectionIntoFrame();
  176.  
  177. // ------------------------------------------------------------
  178. // Drawing
  179. // ------------------------------------------------------------
  180. public:
  181.     void                HiliteRow(
  182.                             TableIndexT            inRow,
  183.                             Boolean                inHilite);
  184. protected:
  185.  
  186.         // Why don't we just overload DoHilite() to take two different params? Because
  187.         // of the scoping rules of C++, if you override a name in one scope, say by a
  188.         // derived class, it hides all other versions of that name. As a result, if anyone
  189.         // overloaded DrawHilite() in a derived class, it would give a warning that we're
  190.         // hiding the other versions of DrawHilite(). This is bad.
  191.     virtual void         DoHiliteRgn( RgnHandle inHiliteRgn ) const;
  192.     virtual void        DoHiliteRect( const Rect & inHiliteRect ) const;
  193.     
  194.         // override to do the right thing with what user types in in-place editor
  195.     virtual void        InlineEditorTextChanged( ) { }
  196.     virtual void        InlineEditorDone( ) { }
  197.     virtual void        DoInlineEditing( const STableCell &inCell, Rect & inTextRect );
  198.     virtual bool        CanDoInlineEditing( ) { return true; }
  199.     
  200.     virtual void        DrawCell(
  201.                             const STableCell        &inCell,
  202.                             const Rect                &inLocalRect);
  203.     virtual void        DrawCellContents(
  204.                             const STableCell        &inCell,
  205.                             const Rect                &inLocalRect);
  206.     virtual void        GetMainRowText(
  207.                             TableIndexT            inRow,
  208.                             char*                outText,
  209.                             UInt16                inMaxBufferLength) const;
  210.     virtual UInt16        GetNestedLevel(TableIndexT /*inRow*/) const
  211.                             { return 0; /* default, no indentation */ }
  212.                             
  213.     virtual Boolean        GetHiliteText(
  214.                             TableIndexT            inRow,
  215.                             char*                outText,
  216.                             UInt16                inMaxBufferLength,
  217.                             Rect*                ioRect) const;
  218.     virtual Boolean        GetHiliteTextRect(
  219.                             const TableIndexT    inRow,
  220.                             Rect&                outRect) const;
  221.     virtual void        GetHiliteRgn(
  222.                             RgnHandle            ioHiliteRgn);
  223.     virtual ResIDT        GetIconID(
  224.                             TableIndexT            /*inRow*/) const { return 0; }
  225.     virtual SInt16        DrawIcons(
  226.                             const STableCell&    inCell,
  227.                             const Rect&         inLocalRect) const; // don't override, use...
  228.     virtual void        DrawIconsSelf(
  229.                             const STableCell&    inCell,
  230.                             IconTransformType    inTransformType,
  231.                             const Rect&            inIconRect) const;
  232.     virtual Boolean        GetIconRect(
  233.                             const STableCell&    inCell,
  234.                             const Rect&            inLocalRect,
  235.                             Rect&                outRect) const;
  236.     virtual Boolean        GetRowHiliteRgn(TableIndexT inRow, RgnHandle ioHiliteRgn) const;
  237.     virtual Boolean        GetRowDragRgn(TableIndexT inRow, RgnHandle ioHiliteRgn) const;
  238.     virtual void        ApplyTextStyle(TableIndexT inRow) const;
  239.     
  240. // ------------------------------------------------------------
  241. // Row Expansion/Collapsing
  242. // ------------------------------------------------------------
  243. protected:
  244.     virtual void        SetCellExpansion(const STableCell& /* inCell */, Boolean /* inExpand */) {}
  245.     virtual Boolean        CellHasDropFlag(const STableCell& /* inCell */, Boolean& /* outIsExpanded */) const { return true; }                                            
  246.     virtual Boolean        CellInitiatesDrag(const STableCell& /* inCell */) const { return false; }                                            
  247.     virtual    void        GetDropFlagRect( const Rect& inLocalCellRect,
  248.                                          Rect&         outFlagRect) const;
  249.     virtual TableIndexT CountExtraRowsControlledByCell(const STableCell& inCell) const;
  250.                         // return zero if there are none.
  251.  
  252. // ------------------------------------------------------------
  253. // Drag Support
  254. // ------------------------------------------------------------
  255.     virtual void        DragSelection(const STableCell& inCell, const SMouseDownEvent &inMouseDown);
  256.     virtual void        AddSelectionToDrag(DragReference inDragRef, RgnHandle inDragRgn);
  257.     virtual void        AddRowDataToDrag(    TableIndexT        /* inRow */,
  258.                                             DragReference    /* inDragRef */    ) {};
  259.     virtual void        InsideDropArea(DragReference inDragRef);
  260.     virtual void        EnterDropArea(DragReference inDragRef, Boolean inDragHasLeftSender);
  261.     virtual void        LeaveDropArea(DragReference    inDragRef);
  262.     virtual Boolean        PointInDropArea(Point inGlobalPt); // add slop for autoscroll
  263.     virtual void        ScrollImageBy(
  264.                                 Int32                inLeftDelta,
  265.                                 Int32                inTopDelta,
  266.                                 Boolean                inRefresh);
  267.                                 // unhilite before and after.
  268.     // Specials
  269.     virtual void        HiliteDropRow(TableIndexT inRow, Boolean inDrawBarAbove);
  270.     virtual TableIndexT    GetHiliteColumn() const;
  271.     virtual Boolean        RowCanAcceptDrop(
  272.                             DragReference    inDragRef,
  273.                             TableIndexT        inDropRow);
  274.     virtual Boolean        RowCanAcceptDropBetweenAbove(
  275.                             DragReference    inDragRef,
  276.                             TableIndexT        inDropRow);
  277.     virtual Boolean        RowIsContainer ( const TableIndexT & /* inRow */ ) const { return false; }
  278.     void ComputeItemDropAreas ( const Rect & inLocalCellRect, Rect & oTop, Rect & oBottom ) ;
  279.     void ComputeFolderDropAreas ( const Rect & inLocalCellRect, Rect & oTop, Rect & oBottom ) ;
  280.  
  281. // ------------------------------------------------------------
  282. // Miscellany
  283. // ------------------------------------------------------------
  284.     PaneIDT                GetCellDataType(const STableCell &inCell) const;
  285.     void                ListenToHeaderMessage(MessageT inMessage, void *ioParam)
  286.                             { mTableHeaderListener.ListenToMessage(inMessage, ioParam); }
  287.                         
  288.     void                SetTextTraits(ResIDT inmTextTraitsID);    
  289.  
  290. //-----------------------------------
  291. // Commands
  292. //-----------------------------------
  293. protected:
  294.     virtual void        FindCommandStatus(
  295.                             CommandT    inCommand,
  296.                             Boolean        &outEnabled,
  297.                             Boolean        &outUsesMark,
  298.                             Char16        &outMark,
  299.                             Str255        outName);
  300.     virtual Boolean        ObeyCommand(
  301.                             CommandT    inCommand,
  302.                             void        *ioParam);
  303.  
  304.     virtual void        DeleteSelection() = 0;
  305.     virtual    void        OpenRow(TableIndexT /* inRow */) {}
  306.     virtual void        GetInfo();
  307.  
  308. public:
  309.     virtual    void        OpenSelection();
  310.  
  311.     // stuff that should go away, moved into a utility class
  312.     
  313.     static void DrawIconFamily(     ResIDT                inIconID,
  314.                                     SInt16                inIconWidth,
  315.                                     SInt16                inIconHeight,
  316.                                     IconTransformType    inTransform,
  317.                                     const Rect&            inBounds);
  318.     
  319.     static void DrawTextString(    const char*        inText, 
  320.                                 const FontInfo*    inFontInfo,
  321.                                 SInt16            inMargin,
  322.                                 const Rect&        inBounds,
  323.                                 SInt16            inJustification = teFlushLeft,
  324.                                 Boolean            doTruncate = true,
  325.                                 TruncCode        truncWhere = truncMiddle);
  326.  
  327. // ------------------------------------------------------------
  328. // QA Partner support
  329. // ------------------------------------------------------------
  330. #if defined(QAP_BUILD)        
  331. public:
  332.     virtual void        QapGetListInfo (PQAPLISTINFO pInfo);
  333.     virtual Ptr            QapAddCellToBuf(Ptr pBuf, Ptr pLimit, const STableCell& sTblCell);
  334.     virtual void        GetQapRowText(TableIndexT inRow, char* outText, UInt16 inMaxBufferLength) const;
  335. #endif
  336.  
  337. //-----------------------------------
  338. // Data
  339. //-----------------------------------
  340. protected:
  341.     CTableHeaderListener mTableHeaderListener;
  342.     ResIDT                mTextTraitsID;
  343.     FontInfo            mTextFontInfo;
  344.     PaneIDT                mTableHeaderPaneID;                                                                            
  345.     LTableViewHeader*    mTableHeader;
  346.     Int16                mClickCountToOpen;    
  347.     TableIndexT*        mSelectionList;
  348.     CClickTimer*        mClickTimer;
  349.     Boolean                mFancyDoubleClick;
  350.     Boolean                mHiliteDisabled;
  351.  
  352. // support for dragging, including dragging rows to new positions
  353.     TableIndexT            mDropRow;                                
  354.     RGBColor            mDropColor;    
  355.     Boolean                mIsInternalDrop;        // a drop of one row on another ?
  356.     Boolean                mIsDropBetweenRows;        // changing order
  357.     
  358.     CInlineEditField*    mNameEditor;            // used for inline editing
  359.     TableIndexT            mRowBeingEdited;
  360.     CInlineEditorListener mInlineListener;        // listens to the editor and tells us things
  361.     
  362. }; // class CStandardFlexTable
  363.