home *** CD-ROM | disk | FTP | other *** search
/ Tools / WinSN5.0Ver.iso / NETSCAP.50 / WIN1998.ZIP / ns / cmd / macfe / central / mfinder.h < prev    next >
Encoding:
C/C++ Source or Header  |  1998-04-08  |  10.4 KB  |  296 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. // mfinder.h
  20.  
  21. #pragma once
  22. #include "PascalString.h"
  23. #include "prtypes.h"
  24.  
  25. #define WIGLY_LEFT_OFFSET        0
  26. #define ICON_WIDTH                16
  27. #define ICON_HEIGHT                16
  28. #define LEVEL_OFFSET            10
  29.  
  30. #define NO_COLUMN                -1
  31. #define HEADER_ROW                -2
  32.  
  33. #define NO_CELL                    0
  34. #define LAST_CELL                0xFFFF
  35.  
  36. #define HIER_COLUMN                0
  37.  
  38. #define WIGLY_CLOSED_ICON        3060
  39. #define WIGLY_OPEN_ICON            3061
  40. #define WIGLY_INBETWEEN_ICON    3062
  41. #define FOLDER_ICON                3064
  42.  
  43. #define SETFLAG( x, f )        ((x)|=(f))
  44. #define CLEARFLAG( x, f )    ((x)&=~(f))
  45.  
  46. #define    NUM_COLUMNS            10
  47.  
  48. #define DRAG_NONE            0
  49. #define DRAG_INSIDE            1
  50. #define DRAG_AFTER            2
  51. #define DRAG_BEFORE            3
  52.  
  53.  
  54. // Gets around horrible bug in Apple's ::TruncText call
  55. // that manifests itself in certain cases if you try to
  56. // truncate in the middle
  57. #define    CUSTOM_MIDDLE_TRUNCATION    666
  58. void MiddleTruncationThatWorks(char *s, Int16 &ioLength, Int16 availableSpace);
  59. void MiddleTruncationThatWorks(StringPtr s, SInt16 availableSpace);
  60.  
  61. class LFinderView;
  62.  
  63. typedef Point        Cell;
  64.  
  65. #include <LView.h>
  66. #include <LDragAndDrop.h>
  67. #include <LCommander.h>
  68.  
  69. class LFinderHeader: public LView
  70. {
  71. public:
  72.     enum { class_ID = 'FNHD' };
  73.     
  74.                         LFinderHeader();
  75.                         LFinderHeader( LStream* inStream );
  76.  
  77.     virtual void        SetFinderView( LFinderView* finder ) { fFinder = finder; }
  78.     
  79.     virtual void        DrawSelf();
  80.     virtual void        ClickSelf( const SMouseDownEvent& where );
  81.     virtual void        AdjustCursorSelf( Point inPortPt, const EventRecord& inMacEvent );
  82.  
  83.     virtual void        DrawColumn( UInt16 column );
  84.     virtual void        TrackReorderColumns( const SMouseDownEvent& where, UInt16 column );
  85. protected:
  86.     LFinderView*        fFinder;
  87.     ResIDT                fTextTraits;
  88. };
  89.  
  90. class LFinderView: public LView,
  91.     public LDragAndDrop,
  92.     public LCommander
  93. {
  94. public:
  95.     friend class        LFinderHeader;
  96.     
  97.     enum { class_ID = 'FDTA' };
  98.     
  99.                         LFinderView( LStream* inStream );
  100.     virtual void        FinishCreateSelf();
  101.  
  102.     virtual void        CaculateFontRect();
  103.     
  104.     virtual Boolean        IsCellSelected( Int32 /* cell */ ) { return FALSE; }
  105.     virtual UInt32        CellIndentLevel( Int32 /* cell */ ) { return 0; }
  106.     virtual ResIDT        CellIcon( Int32 /* cell */ ) { return 0; }
  107.     virtual Boolean        IsCellHeader( Int32 /* cell */ ) { return FALSE; }
  108.     virtual Boolean        IsHeaderFolded( Int32 /* cell */ ) { return FALSE; }
  109.     virtual void        CellText( Int32 /* cell */, CStr255& text ) 
  110.                         { text = CStr255::sEmptyString; }
  111.     virtual Style        CellTextStyle( Int32 /* cell */ ) { return normal; }
  112.     virtual Style        ColumnTextStyle( UInt16 /* column */ ) { return normal; }
  113.     virtual TruncCode    ColumnTruncationStyle( UInt16 /* column */ ) { return smTruncEnd; }
  114.     
  115.     // ÑÑ╩override
  116.     virtual void*        GetCellData( UInt32 /* cell */ ) { return NULL; }
  117.     
  118.     virtual Boolean        SyncDisplay( UInt32 /* visCells */ ) { return FALSE; }        // Resize the view to the number of bookmarks
  119.     virtual void        SelectItem( const EventRecord& /* rec */, UInt32 /* cell */, Boolean /* refresh */ ) { }
  120.     virtual void        FoldHeader( UInt32 /* cell */, Boolean /* fold */, Boolean /* refresh */, Boolean /* foldAll */ ) { }
  121.     virtual void        DoDoubleClick( UInt32 cell, const EventRecord &event );
  122.     virtual void        ClearSelection() { }
  123.     virtual UInt32        GetVisibleCount() { return 0; }
  124.     virtual UInt32        FirstSelectedCell() { return 0; }
  125.     virtual void        GetCellRect( UInt32 cell, Rect& rect );
  126.     virtual void        GetColumnRect( UInt32 cell, UInt16 columnID, Rect& r );
  127.     virtual void        RevealCell( UInt32 cell );
  128.     virtual UInt16        GetNumberOfColumns() { return fNumberColumns; }
  129.     virtual void        GetColumnTitle( UInt16 column, CStr255& title );
  130.     
  131.     virtual UInt16        GetColumnHeight() { return fCellHeight; }
  132.     
  133.     virtual void        RefreshCells( Int32 first, Int32 last,
  134.                                 Boolean rightAway );    // Using refresh, or right away?
  135.  
  136.     virtual void        SwapColumns( UInt16 columnA, UInt16 columnB );
  137.     virtual void        SortByColumnNumber( UInt16 column, Boolean switchOrder );
  138.     
  139.     virtual Int16        InResizableColumnBar( const Point where );
  140.     virtual Int16        InColumn( const Point where );
  141.     virtual void        TrackResizeColumn( const SMouseDownEvent& where, UInt32 cell, Int16 column );
  142.  
  143.     // ÑÑ PowerPlant overrides
  144.     virtual void        ActivateSelf();
  145.     virtual void        DeactivateSelf();
  146.     virtual void        DrawSelf();
  147.     virtual Boolean        FocusDraw(LPane* inSubPane = nil);
  148.     virtual Boolean        HandleKeyPress( const EventRecord& inEvent );
  149.     virtual Boolean        ObeyCommand( CommandT inCommand, void* ioParam );
  150.     virtual void         ClickSelf( const SMouseDownEvent& where );
  151.     virtual void        ResizeFrameBy( Int16 inWidthDelta, Int16 inHeightDelta, Boolean inRefresh );
  152.     virtual void        PutOnDuty( LCommander* inNewTarget );
  153.     virtual void        TakeOffDuty();
  154.             
  155.     // ÑÑ╩drag & drop
  156.     virtual void        AddFlavors( DragReference inDragRef );
  157.     virtual void        MakeDragRegion( DragReference inDragRef, RgnHandle dragRegion );
  158.  
  159.     virtual void        InsideDropArea( DragReference inDragRef );
  160.     virtual void        LeaveDropArea( DragReference inDragRef );
  161.     virtual void        DoDragSendData( FlavorType /* flavor */, ItemReference /* itemRef */, DragReference /* dragRef */ ) { }
  162.     virtual Boolean        ItemIsAcceptable( DragReference /* inDragRef */, ItemReference /* inItemRef */ ) { return FALSE; }
  163.     virtual void        ReceiveDragItem( DragReference /* inDragRef */, DragAttributes /* inDragAttrs */,
  164.                             ItemReference /* inItemRef */, Rect& /* inItemBounds */ ) { }
  165.  
  166.     virtual void        HiliteDropArea( DragReference /* inDragRef */ ) { }
  167.             
  168.     
  169.     void                SetForeColor( const RGBColor& fore );
  170.     void                SetBackColor( const RGBColor& back );
  171.  
  172.     virtual void        DrawIcon( Handle iconSuite,
  173.                             Boolean selected,
  174.                             const Rect& where );
  175.                             
  176.     virtual void        DrawText( const Style& style, 
  177.                             const CStr255& text,
  178.                             const Rect& where,
  179.                             const TruncCode& trunc );
  180.  
  181.     virtual void        SavePlace( LStream* inStream );
  182.     virtual void        RestorePlace( LStream* inStream );
  183.  
  184.     virtual void        RefreshHeader();
  185.  
  186.     virtual void        DragScroll(DragReference /* theDragRef */) { }
  187.             
  188. protected:
  189.     struct DropLocation
  190.     {
  191.         UInt32        cell;
  192.         UInt32        where;
  193.     };
  194.  
  195.     // ÑÑ cell drawing
  196.     // override
  197.     virtual UInt32        FetchCellAt( SPoint32& imagePt );    // Cell at this coordinate
  198.  
  199.     virtual void        KeyUp( const EventRecord& event );
  200.     virtual void        KeyDown( const EventRecord& event );
  201.     virtual void        KeyEnter( const EventRecord& event );
  202.     virtual void        KeyHome( const EventRecord& event );
  203.     virtual void        KeyEnd( const EventRecord& event );
  204.     virtual void        KeyPageUp( const EventRecord& event );
  205.     virtual void        KeyPageDown( const EventRecord& event );
  206.         
  207.     virtual void        RefreshSelectedCells();
  208.  
  209.     // ÑÑ access    
  210.     virtual void        GetVisibleCells( UInt32& top, UInt32& bottom );    // Get visible cells
  211.     virtual void        DrawCellAt( UInt32 cell );            // Draw the cell
  212.     virtual void        DrawCellColumn( UInt32 cell, UInt16 column );
  213.  
  214.     virtual Int16        GetClickKind( const SMouseDownEvent& where, UInt32 cell, 
  215.                             Boolean& inBar );    // Where did we click?
  216.     virtual void        DoResizeColumn( Int16 column, Int16 delta, Boolean inRefresh );
  217.     virtual Boolean        DispatchClick( const SMouseDownEvent& where, UInt32 cell, Int16 column );
  218.     
  219.     virtual Boolean        TrackHeader( const SMouseDownEvent& where, UInt16 column );
  220.                             
  221.     void                LocalToGlobalRect( Rect& r );
  222.     Boolean                SectCellRect( UInt32 cell, Rect r );    // Does cell intersect this local rect?
  223.  
  224.     virtual void        HighlightDropLocation( Boolean show );    // TRUE to show highlight, FALSE to hide
  225.     virtual void        MakeDragTask( const SMouseDownEvent & /* where */ ) { }
  226.     
  227.     virtual Boolean        ResizeTo( UInt32 newHeight, UInt32 newWidth );
  228.  
  229.     virtual void        DrawHierarchy( UInt32 cell );
  230.     virtual Boolean        CanDrawHierarchy( UInt32 cell );
  231.     
  232.     virtual void        TrackWigly( const SMouseDownEvent& where, UInt32 cell );
  233.     virtual void        TrackCell( const SMouseDownEvent& where, UInt32 cell );
  234.     virtual void        TrackSpace( const SMouseDownEvent& where, UInt32 cell );
  235.     virtual Boolean        TrackMark( UInt16 columnID, const SMouseDownEvent& where, UInt32 cell,
  236.                             UInt16 drawIconID, UInt16 notDrawIconID );
  237.  
  238.     virtual void        GetWiglyRect( UInt32 cell, Rect& rect );
  239.     virtual void        GetIconRect( UInt32 cell, Rect& rect );
  240.     virtual void        GetTextRect( UInt32 cell, Rect& rect );
  241.     virtual void        HighlightCell( UInt32 cell );
  242.  
  243.     virtual Boolean        ColumnText( UInt32 cell, UInt16 column, CStr255& text );
  244.  
  245.     virtual void        AdjustCursorSelf( Point inPortPt, const EventRecord& inMacEvent );
  246.  
  247.     virtual void        RemoveColumn( UInt16 column );
  248.     virtual void        InsertColumn( UInt16 before, UInt16 columnID, UInt16 width );
  249.  
  250.     virtual void        DrawText( const Style& style, 
  251.                             const CStr255& text,
  252.                             const Rect& where,
  253.                             const TruncCode& trunc,
  254.                             ResIDT inTextTraits,
  255.                             Int16 baseline );
  256.     
  257.     Boolean                fClipImage;
  258.     Boolean                fAllowsRectSelection;
  259.     Boolean                fAllowsKeyNavigation;
  260.     Boolean                fHighlightRow;
  261.     
  262.     UInt16                fCellHeight;
  263.     UInt16                fBaseline;
  264.     ResIDT                fTextTraits;    // Font
  265.     RGBColor            fForeColor;
  266.     RGBColor            fBackColor;
  267.     
  268.     Int16                fNumberColumns;
  269.     Int16                fColumnOffsets[ NUM_COLUMNS ];
  270.     Int16                fColumnIDs[ NUM_COLUMNS ];
  271.     LFinderHeader*        fHeader;
  272.         
  273.     DropLocation        fDragTarget;
  274.     SBooleanRect        fDragLeaveDirection;
  275. };
  276.  
  277. class LDragFinderTask: public LDragTask
  278. {
  279. public:
  280.                         LDragFinderTask( const EventRecord& inEventRecord, LFinderView* view );
  281.     virtual                ~LDragFinderTask();
  282.     
  283.     virtual void        AddFlavors( DragReference inDragRef );
  284.     virtual void        MakeDragRegion( DragReference inDragRef, RgnHandle inDragRegion );
  285.     
  286. protected:
  287.  
  288.     static pascal OSErr    ScrollingTracker(    DragTrackingMessage     message, 
  289.                                             WindowPtr                 theWindow, 
  290.                                             void                 *    handlerRefCon, 
  291.                                             DragReference             theDragRef        );
  292.  
  293.     DragTrackingHandlerUPP    fTrackerProc;
  294.     LFinderView*            fView;
  295. };
  296.