home *** CD-ROM | disk | FTP | other *** search
/ Tools / WinSN5.0Ver.iso / NETSCAP.50 / WIN1998.ZIP / ns / cmd / winfe / rdfliner.h < prev    next >
Encoding:
C/C++ Source or Header  |  1998-04-08  |  15.7 KB  |  423 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. // RDF Tree View for Aurora.  Created by Dave Hyatt.
  20.  
  21. #ifndef __RDFLINER_H
  22. #define __RDFLINER_H
  23.  
  24. #include "outliner.h"
  25. #include "property.h"
  26. #include "cxstubs.h"
  27. #include "statbar.h"
  28. #include "navfram.h"
  29. #include "htrdf.h"
  30. #include "rdfglobal.h"
  31. #include "rdfacc.h"
  32.  
  33. // array of indexes for IDB_BOOKMARKS
  34. #define IDX_BOOKMARKOPEN                0
  35. #define IDX_BOOKMARKCLOSED                1
  36. #define IDX_BOOKMARKMENUOPEN            2
  37. #define IDX_BOOKMARKMENUCLOSED            3
  38. #define IDX_BOOKMARKFOLDEROPEN            4
  39. #define IDX_BOOKMARKFOLDERCLOSED        5
  40. #define IDX_BOOKMARKTOOLBARCLOSED        6
  41. #define IDX_BOOKMARKTOOLBAROPEN            7
  42. #define IDX_BOOKMARKFOLDERMENUOPEN        8
  43. #define IDX_BOOKMARKFOLDERMENUCLOSED    9
  44. #define IDX_BOOKMARKMENUTOOLBARCLOSED    10
  45. #define IDX_BOOKMARKMENUTOOLBAROPEN        11
  46. #define IDX_BOOKMARKFOLDERTOOLBARCLOSED    12
  47. #define IDX_BOOKMARKFOLDERTOOLBAROPEN    13
  48. #define IDX_BOOKMARKALLCLOSED            14
  49. #define IDX_BOOKMARKALLOPEN                15
  50. #define IDX_BOOKMARKCHANGED                16
  51. #define IDX_BOOKMARK                    17
  52. #define IDX_BOOKMARKUNKNOWN                18
  53.  
  54. class CRDFOutlinerParent;
  55.  
  56. class CRDFOutliner : public COutliner, public CCustomImageObject
  57. {
  58. private:
  59.     HT_Pane m_Pane;        // The pane that owns this view
  60.     HT_View m_View;        // The view as registered in the hypertree
  61.     HT_Resource m_Node;    // The currently acquired node
  62.     int m_nSortType;    // The type of sort (none, ascending, descending)
  63.     int m_nSortColumn;  // The current column used for sort (none, or the UINT of the column)
  64.     UINT m_hEditTimer;    // The Edit Timer (for editing in place)
  65.     UINT m_hSpringloadTimer; // The Springload timer (for popping open springloaded folders on drag)
  66.     UINT m_hDragRectTimer; // Timer for scrolling on a multiple select drag rectangle
  67.     BOOL m_bNeedToClear; // Used to determine if selection needs to be wiped on a mouse up
  68.     BOOL m_bNeedToEdit;  // Used to determine if an edit field needs to be displayed on a node
  69.     BOOL m_bDoubleClick;  // Used to prevent an edit field from popping up on a double click
  70.     BOOL m_bDataSourceInWindow; // TRUE when something is being dragged around inside the window.
  71.                                 // Use this to keep springloaded folders behaving properly
  72.     CPtrList m_SpringloadStack; // A list of current OPEN springloaded folders (so that we can close
  73.                                 // them back up again)
  74.     
  75.     DROPEFFECT m_iCurrentDropAction; // Cache the current drop action
  76.  
  77.     BOOL m_bCheckForDragRect; // Used to distinguish the dragging of an item from the drawing of a drag
  78.                               // rect for multiple selection
  79.     CRect m_LastDragRect;      // Position of the last drag rect
  80.     CPoint m_MovePoint;          // Last position of mouse on a move (Used for drag rect stuff)
  81.     int m_nRectYDisplacement; // Used for scrolling the drag rect
  82.  
  83.     OutlinerAncestorInfo* m_pAncestor; // Used for drawing the pipes in the tree.
  84.     BOOL m_bPaintingFirstObject; // Used to perform an optimization on the line-drawing part of the tree.
  85.     int m_nSizeOfAncestorArray;    // Also used for the optimization.
  86.     
  87.     CRDFOutlinerParent* m_Parent; // A pointer to the parent container.
  88.  
  89.     int m_nSelectedColumn; // The currently selected column
  90.     CRDFEditWnd* m_EditField; // The current edit window (if one exists).
  91.  
  92.     int m_iSpringloadSelection; // Cached last drag-selection to determine springload on drag
  93.  
  94.     // CLIPFORMATS for drag & drop. 
  95.     CLIPFORMAT m_clipFormatArray[5]; // The list of acceptable formats
  96.     CLIPFORMAT m_cfHTNode;         // Format for HT nodes.
  97.     CLIPFORMAT m_cfBookmark;     // Bookmark format (title/URL)
  98.     
  99.     CRDFCommandMap m_MenuCommandMap;  // The command mapping for menus
  100.  
  101.     CNavMenuBar* m_NavMenuBar;    // A pointer to the title nav menu. NULL if no menu button is present.
  102.  
  103. public:
  104.     CRDFOutliner (HT_Pane thePane, HT_View theView, CRDFOutlinerParent* theParent);
  105.     ~CRDFOutliner ( );
  106.  
  107.     // Inspectors
  108.     HT_View GetHTView() { return m_View; } // Return a handle to the hypertree view
  109.     HT_Resource GetAcquiredNode() { return m_Node; } // Return handle to the acquired HT node
  110.     CRDFOutlinerParent* GetRDFParent() { return m_Parent; } // RDFOutlinerParent handle
  111.     UINT GetSelectedColumn() { return m_nSelectedColumn; } // Returns selected column
  112.     int GetSortColumn() { return m_nSortColumn; }
  113.     int GetSortType() { return m_nSortType; }
  114.     
  115.     // Setters
  116.     void SetSortType(int sortType) { m_nSortType = sortType; }
  117.     void SetSortColumn(int sortColumn) { m_nSortColumn = sortColumn; }
  118.     void SetSelectedColumn(int nColumn) { m_nSelectedColumn = nColumn; }
  119.     void SetDockedMenuBar(CNavMenuBar* bar) { m_NavMenuBar = bar; }
  120.  
  121. // I am explicitly labeling as virtual any functions that have been
  122. // overridden.  That is, unless I state otherwise, all virtual functions
  123. // are overridden versions of COutliner functions.
  124.     
  125.     void FocusCheck(CWnd* pWnd, BOOL gotFocus);  
  126.         // Called to potentially update the embedded menu bar in the docked view.
  127.  
  128.     BOOL IsSelectedColumn(int i) { return m_nSelectedColumn == i; }
  129.  
  130.     virtual LPCTSTR GetColumnText ( UINT iColumn, void * pLineData );  
  131.         // Grab the text for a particular column.  
  132.  
  133.     virtual void * AcquireLineData ( int iLine );
  134.         // Acquire (nice spelling, heh) the node for a given line.
  135.  
  136.     virtual void ReleaseLineData ( void * pLineData );
  137.         // Release the line data for a given line.
  138.  
  139.     virtual void GetTreeInfo( int iLine, uint32 * pFlags, int * iDepth, 
  140.                       OutlinerAncestorInfo ** pAncestor );
  141.         // Get information about the node at iLine.
  142.  
  143.     virtual HFONT GetLineFont ( void * pLineData );
  144.         // Get the font (e.g., regular, italic, bold) for the given line.
  145.  
  146.     virtual int TranslateIcon ( void * pData );
  147.         // Figures out which icon should be used.
  148.  
  149.     virtual int TranslateIconFolder( void *pData );
  150.         // Don't have a damn clue what this does.
  151.  
  152.     virtual int ToggleExpansion(int iLine);
  153.         // Called to expand a node.
  154.     
  155.     void FinishExpansion(int parentIndex);
  156.         // Called by the notifyProc to complete the expansion
  157.  
  158.     virtual void SelectItem(int iSel, int mode, UINT flags);
  159.         // Called to select an item... handles single/double click...everything...
  160.  
  161.     void OnSelDblClk(int iLine);
  162.         // Different from base class.  Line info is passed as arg.
  163.  
  164.     virtual void PropertyMenu(int iLine, UINT flags);
  165.         // Displays the context-sensitive menu (when the user right-clicks on a node)
  166.  
  167.     virtual BOOL IsSelected(int iLine);
  168.         // Used by base class to determine if a line is selected.  Function
  169.         // queries RDF backend instead of relying on the m_Selection member
  170.         // variable in COutliner.
  171.  
  172.     void EditTextChanged(char* text);
  173.         // Function is called when a column's data has been edited in place.  This
  174.         // function talks to the back end and makes sure the node gets changed.
  175.  
  176.     char* GetTextEditText();
  177.         // Copies the edit field's text to a char*.  The text must be deleted by the
  178.         // caller of this function.
  179.  
  180.     void AddTextEdit();
  181.         // Creates a text edit on the selected item and column.
  182.  
  183.     void RemoveTextEdit();
  184.         // Kills the text edit control.
  185.  
  186.     void MoveToNextColumn();
  187.         // Called when the user tabs in the edit field to move to the next column.
  188.  
  189.     CRect GetColumnRect(int lineNo, int columnNo);
  190.         // Gets the rect associated with a specific column and line
  191.  
  192.     virtual void ColumnsSwapped();
  193.         // Called when the columns' positions have changed (e.g., the user dragged one column to the
  194.         // left of another column).  Added this function so that RDFOutliner (unlike Outliner) will
  195.         // force the tree images to remain on the left.
  196.  
  197.     int DetermineClickLocation(CPoint point);
  198.         // The master click function.  Determines whether the user clicked on a trigger, on the item itelf,
  199.         // or on the background.
  200.  
  201.     virtual BOOL TestRowCol(POINT point, int &, int &); 
  202.         // Overridden because Outliner doesn't set the column hit if the row doesn't contain data.
  203.  
  204.     void copyAncestorValues(HT_Resource r, int numItems, OutlinerAncestorInfo* oldInfo, OutlinerAncestorInfo* newInfo);
  205.         // Used for drawing the lines in the tree.
  206.  
  207.     void HandleEvent(HT_Notification ns, HT_Resource n, HT_Event whatHappened);
  208.         // The function which handles all the events which occur in the view.
  209.     
  210.     void DisplayURL();
  211.         // Called to display a URL for a non-container node.
  212.     
  213.     BOOL IsDocked();
  214.         // True if the RDF view is docked.
  215.  
  216.     virtual void LoadComplete(HT_Resource pResource); 
  217.         // Overridden from CCustomObject.  Called when a custom URL image has finished loading.
  218.  
  219.     virtual BOOL DeleteItem(int iSel);
  220.         // Called when the user decides to delete an item.  The selection argument is completely
  221.         // ignored. (We rely on HT's selection when performing the deletion.)
  222.  
  223.     virtual int DrawPipes ( int iLineNo, int iColNo, int offset, HDC hdc, void * pLineData );
  224.         // Overridden to handle the drawing of custom icons.
  225.  
  226.     void PaintLine ( int iLineNo, HDC hdc, LPRECT lpPaintRect, COLORREF sortColor, HBRUSH hHighlightBrush,
  227.                                HPEN hHighlightPen );
  228.         // This PaintLine is used instead of the one in the outliner base class. Overridden so
  229.         // that individual columns can be selected (instead of an entire line).
  230.  
  231.     void PaintColumn(int iLineNo, int iColumn, LPRECT lpColumnRect, 
  232.                                HDC hdc, void * pLineData, HBRUSH hHighlightBrush,
  233.                                HPEN hHighlightPen);
  234.         // Used instead of the outliner PaintColumn.  Same reason as above.
  235.  
  236.     void DrawColumn(HDC hdc, LPRECT lpColumnRect, LPCTSTR lpszString,
  237.                     CropType_t cropping, AlignType_t alignment, HBRUSH theBrush = NULL, 
  238.                     BOOL hasFocus = FALSE);
  239.         // Used instead of the outliner DrawColumnText.  Same reason.
  240.  
  241.     CRect ConstructDragRect(const CPoint& pt1, const CPoint& pt2);
  242.         // Constructs a new rectangle with the two points specified as opposing corners.
  243.  
  244.     void EraseDragRect(CDC* pDC, CRect rect);
  245.         // Helper to blow away the drag rect
  246.  
  247.     void DragRectScroll(BOOL bBackwards);
  248.         // Function to scroll the drag rect
  249.  
  250.     virtual void InitializeClipFormats();
  251.         // Registers the formats we accept (drag/drop) when the window is created.
  252.  
  253.     virtual CLIPFORMAT * GetClipFormatList();
  254.         // Returns an array of CLIPFORMATS that we are willing to handle.  Used
  255.         // for drag over feedback.
  256.  
  257.     virtual DROPEFFECT DropSelect (int iLineNo, COleDataObject *object );
  258.         // Used to determine type of drop.
  259.  
  260.     virtual int GetDragHeartbeat();
  261.         // Speed at which the tree scrolls on a drag.  Overridden to be faster than COutliner.
  262.  
  263.     virtual void AcceptDrop( int iLineNo, COleDataObject *pDataObject, DROPEFFECT dropEffect );
  264.         // Called when a drop occurs on a given line in the view.  This function actually
  265.         // handles the drop.
  266.  
  267.     virtual BOOL HighlightIfDragging(void);
  268.         // Called to determine whether or not a node should be highlighted when an item is dragged
  269.         // OVER it.  We only highlight containers (folders).
  270.  
  271.     virtual void PaintDragLine(HDC hdc, CRect &rectColumn);
  272.         // Called to draw the drag line that indicates the drop will occur AFTER this item in the tree.
  273.  
  274.     virtual COleDataSource * GetDataSource();
  275.         // Called when a drag is initiated in this view to copy the node.
  276.  
  277.     COleDropTarget* GetDropTarget() { return (COleDropTarget*)m_pDropTarget; }
  278.         // Returns the drop target associated with the COutliner base class
  279.  
  280.     virtual COutlinerDropTarget* CreateDropTarget();
  281.         // Called to create the RDF drop target.
  282.  
  283.     afx_msg int OnCreate ( LPCREATESTRUCT );
  284.         // Overridden to allow for special create stuff.
  285.  
  286.     afx_msg void OnPaint();
  287.         // Overridden to perform a drawing optimization (not performed by Outliner)
  288.  
  289.     afx_msg void OnLButtonDown ( UINT nFlags, CPoint point );
  290.     afx_msg void OnLButtonUp (UINT nFlags, CPoint point );
  291.     afx_msg void OnMouseMove( UINT nFlags, CPoint point );
  292.     afx_msg void OnRButtonDown ( UINT nFlags, CPoint point );
  293.     afx_msg void OnRButtonUp ( UINT nFlags, CPoint point );
  294.         // All overridden to allow the drawing of a drag rectangle for multiple selection
  295.         // and to implement improved hit testing.
  296.  
  297.     afx_msg void OnTimer(UINT id);
  298.         // Used for editing columns and what-not.
  299.  
  300.     afx_msg void OnSetFocus(CWnd* pOldWnd);
  301.     afx_msg void OnKillFocus(CWnd* pNewWnd);
  302.         // Overridden to update the nav title caption colors (in a docked Aurora view).
  303.  
  304.  
  305.     afx_msg BOOL OnCommand(UINT wParam, LONG lParam);
  306.         // Menu commands are handled by the rdfliner.
  307.  
  308.     DECLARE_MESSAGE_MAP();
  309.  
  310.     friend class CRDFDropTarget;
  311.     friend class CRDFOutlinerParent;
  312. };
  313.  
  314. class CRDFDropTarget: public COutlinerDropTarget
  315. {
  316. public:
  317.     DROPEFFECT OnDragEnter(CWnd* pWnd, COleDataObject* pDataObject, DWORD dwKeyState, CPoint point);
  318.     BOOL OnDrop(CWnd* pWnd, COleDataObject* pDataObject, DROPEFFECT dropEffect, CPoint point);
  319.     DROPEFFECT OnDragOver(CWnd* pWnd, COleDataObject* pDataObject, DWORD dwKeyState, CPoint point);
  320.     void OnDragLeave(CWnd* pWnd);
  321.  
  322.     CRDFDropTarget(COutliner* pOutliner) :COutlinerDropTarget(pOutliner) {};
  323. };
  324.  
  325. class CRDFOutlinerParent : public COutlinerParent 
  326. {
  327. private:
  328.     CRDFCommandMap columnMap;
  329.  
  330. public:
  331.     CRDFOutlinerParent(HT_Pane thePane, HT_View theView);
  332.  
  333.     BOOL PreCreateWindow(CREATESTRUCT& cs);
  334.     COutliner* GetOutliner();
  335.     void CreateColumns();
  336.     BOOL RenderData( int iColumn, CRect & rect, CDC &dc, LPCTSTR text );
  337.     BOOL ColumnCommand( int iColumn );
  338.     void Initialize();
  339.     CRDFCommandMap& GetColumnCommandMap() { return columnMap; }
  340.  
  341. protected:
  342.     afx_msg void OnDestroy();
  343.     DECLARE_MESSAGE_MAP()
  344. };
  345.  
  346.  
  347. class CRDFContentView : public CContentView
  348. {
  349. public:
  350.     COutlinerParent * m_pOutlinerParent;
  351.  
  352. // Construction
  353. public:
  354.     CRDFContentView(CRDFOutlinerParent* outlinerStuff)
  355.     { m_pOutlinerParent = outlinerStuff; };
  356.  
  357.     ~CRDFContentView() 
  358.     {
  359.         delete m_pOutlinerParent;
  360.     }
  361.  
  362.     COutlinerParent* GetOutlinerParent() { return m_pOutlinerParent; }
  363.  
  364. // This functionality has been folded in from COutlinerView. I no longer derive from this class
  365. // but instead come off of CContentView.
  366.  
  367.     void CreateColumns ( )
  368.     {
  369.         m_pOutlinerParent->CreateColumns ( );
  370.     }
  371.  
  372.     void InvalidateOutlinerParent();
  373.  
  374.     static void DisplayRDFTree(CWnd* pParent, int width, int height, RDF_Resource rdfResource);
  375.         // This function can be called to create an embedded RDF tree view inside another window.
  376.         // Used to embed the tree in HTML.
  377.  
  378. protected:
  379.     virtual void OnDraw(CDC *pDC);
  380.     virtual BOOL PreCreateWindow(CREATESTRUCT& cs);
  381.  
  382.     DECLARE_DYNCREATE(CRDFContentView)
  383.     //{{AFX_MSG(CMainFrame)
  384.     afx_msg LRESULT OnNavCenterQueryPosition(WPARAM wParam, LPARAM lParam);
  385.     afx_msg int OnCreate ( LPCREATESTRUCT );
  386.     afx_msg void OnSize ( UINT, int, int );
  387.     afx_msg void OnSetFocus ( CWnd * pOldWnd );
  388.     //}}AFX_MSG
  389.     DECLARE_MESSAGE_MAP()
  390. };
  391.  
  392. class FAR CExportRDF : public CDialog
  393. {
  394. protected:
  395.     CString m_csCaption;
  396.  
  397. // Construction
  398. public:
  399.     CExportRDF(CWnd* pParent = NULL);  // standard constructor
  400.  
  401.     void SetSecureTitle( CString &csTitle ) { m_csTitle = csTitle; }
  402.     
  403. // Dialog Data
  404.     //{{AFX_DATA(CExportRDF)
  405.     enum { IDD = IDD_EXPORTRDF };
  406.     CString m_csAsk;
  407.     CString m_csAns;
  408.     //}}AFX_DATA
  409.  
  410.     CString m_csTitle;
  411.     
  412. // Implementation
  413. protected:
  414.     virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
  415.     DECLARE_MESSAGE_MAP()
  416. };
  417.  
  418.  
  419. // Functions that will be used by the Personal Toolbar and Quickfile.  Allow the
  420. // display of arbitrary icons (or local file system icons)
  421.  
  422. #endif
  423.