home *** CD-ROM | disk | FTP | other *** search
/ Tools / WinSN5.0Ver.iso / NETSCAP.50 / WIN1998.ZIP / ns / cmd / xfe / src / Outliner.h < prev    next >
Encoding:
C/C++ Source or Header  |  1998-04-08  |  12.6 KB  |  443 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.    Outliner.h -- class definition for the Outliner object
  20.    Created: Chris Toshok <toshok@netscape.com>, 7-Aug-96.
  21.  */
  22.  
  23.  
  24.  
  25. #ifndef _xfe_outliner_h
  26. #define _xfe_outliner_h
  27.  
  28. #include "Component.h"
  29.  
  30. #include "mozilla.h"
  31. #if !defined(USE_MOTIF_DND)
  32. #include "dragdrop.h"
  33. #endif /* USE_MOTIF_DND */
  34. #include "msgcom.h"
  35. #include "icons.h"
  36. #if defined(USE_MOTIF_DND)
  37. #include "icons/icondata.h"
  38. #endif /* USE_MOTIF_DND */
  39. #include "xp_list.h"
  40.  
  41. #include "XmL/Grid.h"
  42.  
  43. typedef enum {
  44.   OUTLINER_Leaf,
  45.   OUTLINER_Folded,
  46.   OUTLINER_Expanded
  47. } EOutlinerFlippyType;
  48.  
  49. typedef enum {
  50.   OUTLINER_Default,
  51.   OUTLINER_Bold,
  52.   OUTLINER_Italic
  53. } EOutlinerTextStyle;
  54.  
  55. typedef enum 
  56. {
  57.   PIPE_OPENTOPPARENT,
  58.   PIPE_OPENMIDDLEPARENT,
  59.   PIPE_OPENBOTTOMPARENT,
  60.   PIPE_OPENSINGLEPARENT,
  61.  
  62.   PIPE_CLOSEDTOPPARENT,
  63.   PIPE_CLOSEDMIDDLEPARENT,
  64.   PIPE_CLOSEDBOTTOMPARENT,
  65.   PIPE_CLOSEDSINGLEPARENT,
  66.  
  67.   PIPE_TOPITEM,
  68.   PIPE_MIDDLEITEM,
  69.   PIPE_BOTTOMITEM,
  70.   PIPE_EMPTYITEM
  71. } EOutlinerPipeType;
  72.  
  73. typedef enum
  74. {
  75.     OUTLINER_SortAscending,
  76.     OUTLINER_SortDescending
  77. } EOutlinerSortDirection;
  78.  
  79. class XFE_Outlinable;
  80. #if defined(USE_MOTIF_DND)
  81. class XFE_OutlinerDrop;
  82. class XFE_OutlinerDrag;
  83. #endif /* USE_MOTIF_DND */
  84.  
  85. struct OutlineButtonFuncData;
  86. struct OutlineFlippyFuncData;
  87. struct OutlinerAncestorInfo;
  88.  
  89. #if defined(USE_MOTIF_DND)
  90. typedef void (*FEGetDropTargetFunc)(void *,
  91.                                     Atom **targets, int *numtargets);
  92. typedef void (*FEGetDragTargetFunc)(void *,
  93.                                     int row, int col,
  94.                                     Atom **targets, int *numtargets);
  95. typedef fe_icon_data* (*FEGetDragIconDataFunc)(void *,
  96.                                                int row, int col);
  97. typedef char* (*FEConvertDragDataFunc)(void *,
  98.                                        Atom atom);
  99. typedef int (*FEProcessTargetsFunc)(void *,
  100.                                     int row, int col,
  101.                                     Atom *targets,
  102.                                     const char **data,
  103.                                     int numItems);
  104. #endif /* USE_MOTIF_DND */
  105.  
  106. class XFE_Outliner : public XFE_Component
  107. {
  108. public:
  109.   XFE_Outliner(const char *name,
  110.            XFE_Outlinable *o, 
  111.            XFE_Component *toplevel_component,
  112.            Widget widget_parent,
  113.            XP_Bool constantSize,
  114.            XP_Bool hasHeadings,
  115.            int num_columns,
  116.            int num_visible,
  117.            int *column_widths,
  118.            char *geom_prefname);
  119.  
  120.   XFE_Outliner();
  121.  
  122.   virtual ~XFE_Outliner();
  123.  
  124. #if !defined(USE_MOTIF_DND)
  125.   void setOutlinable(XFE_Outlinable *o);
  126. #endif /* USE_MOTIF_DND */
  127.  
  128.   XFE_Outlinable *getOutlinable();
  129.  
  130.   void setSortColumn(int column, EOutlinerSortDirection direction);
  131.   int getSortColumn();
  132.   void toggleSortDirection();
  133.   EOutlinerSortDirection getSortDirection();
  134.  
  135.   XP_Bool isColTextFit(char *str, int row, int col);
  136.   int textStart(int col, int maxX);
  137.  
  138.   void setPipeColumn(int column);
  139.   int getPipeColumn();
  140.  
  141.   void setColumnResizable(int column, XP_Bool resizable);
  142.   XP_Bool getColumnResizable(int column);
  143.  
  144.   void setColumnWidth(int column, int width);
  145.   int getColumnWidth(int column);
  146.  
  147.   int getNumContextAndHeaderRows();
  148.  
  149.   void showAllRowsWithRange(int minRows, int maxRows);
  150.   
  151.   void setDescendantSelectAllowed(XP_Bool flag);
  152.   XP_Bool getDescendantSelectAllowed();
  153.  
  154.   void setMultiSelectAllowed(XP_Bool flag);
  155.   XP_Bool getMultiSelectAllowed();
  156.  
  157.   void setHideColumnsAllowed(XP_Bool flag);
  158.   XP_Bool getHideColumnsAllowed();
  159.  
  160. #if !defined(USE_MOTIF_DND)
  161.   void setDragType(fe_dnd_Type dragtype, fe_icon *drag_icon = NULL, 
  162.            XFE_Component *dragsource = NULL, fe_dnd_SourceDropFunc func = NULL);
  163.  
  164.   fe_dnd_Type getDragType();
  165.   fe_icon *getDragIcon();
  166.   fe_dnd_SourceDropFunc getSourceDropFunc();
  167.  
  168. #else
  169.   void enableDragDrop(void *this_ptr = NULL,
  170.                       FEGetDropTargetFunc drop_target_func = NULL,
  171.                       FEGetDragTargetFunc drag_target_func = NULL,
  172.                       FEGetDragIconDataFunc drag_icon_func = NULL,
  173.                       FEConvertDragDataFunc drag_conv_func = NULL,
  174.                       FEProcessTargetsFunc process_targets_func = NULL);
  175.  
  176.   fe_icon_data* getDragIconData(int row, int col);
  177.   void getDragTargets(int row, int col, Atom **targets, int *numTargets);
  178.   void getDropTargets(Atom **targets, int *numTargets);
  179.   char *dragConvert(Atom atom);
  180.   int processTargets(int row, int col,
  181.                      Atom *targets, const char **data, int numItems);
  182.  
  183. #endif /* USE_MOTIF_DND */
  184.   /* set selection blocked or not
  185.    */
  186.   void setBlockSel(XP_Bool b);
  187.   void scroll2Item(int index);
  188.  
  189.   void selectAllItems();
  190.   void selectItem(int index);
  191.   void selectRangeByIndices(int start_index, int end_index);
  192.   void selectItemExclusive(int index);
  193.   void deselectItem(int index);
  194.   void deselectAllItems();
  195.   /* set Focus selection
  196.    */
  197.   void setInFocus(XP_Bool infocus);
  198.   XP_Bool isFocus();
  199.  
  200.   /* timOrExpandSelection - pretty funky.  look at Outliner.cpp */
  201.   void trimOrExpandSelection(int new_index); 
  202.   void deselectRangeByIndices(int selection_begin, int selection_end);
  203.   void toggleSelected(int index);    
  204.   XP_Bool isSelected(int line);
  205.  
  206.   int getSelection(const int **indices, int *count);
  207.  
  208.   int getTotalLines();
  209.   int XYToRow(int x, int y, XP_Bool *nearbottom = NULL);
  210.  
  211.   void makeVisible(int index);
  212.  
  213.   void change(int index, int num, int total_lines);
  214.  
  215.   /* use these when we need to force the redraw of a line or a group of
  216.      lines. */
  217.   void invalidate();
  218.   void invalidateLine(int line);
  219.   void invalidateLines(int start, int count);
  220.   void invalidateHeaders();
  221.  
  222.   /* used to give dnd feedback. */
  223.   void outlineLine(int line);
  224.   void underlineLine(int line);
  225.  
  226.   /* hide/show the right-most column */
  227.   void hideColumn();
  228.   void showColumn();
  229.  
  230.   /* apply a delta across all columns.  Returns the actual delta applied. */
  231.   int applyDelta(int delta, int starting_at = 0);
  232.  
  233.   /* move a particular column to another place. */
  234.   void moveColumn(int column_to_move, int destination);
  235.  
  236. #if !defined(USE_MOTIF_DND)
  237.   void handleDragEvent(XEvent *event, fe_dnd_Event type, fe_dnd_Source *source);
  238. #endif /* USE_MOTIF_DND */
  239.   /* these are needed by the libmsg stuff, and probably should
  240.      be used by the bookmark/history/address book/etc stuff
  241.      so that sorting is consistent. */
  242.  
  243.   /* Tao_16dec96
  244.    * Make them virtual to perform some customization
  245.    */
  246.   int getListChangeDepth();
  247.  
  248.   virtual void listChangeStarting(XP_Bool asynchronous, 
  249.                   MSG_NOTIFY_CODE notify,
  250.                   MSG_ViewIndex where, 
  251.                   int32 num, 
  252.                   int32 total_lines);
  253.   virtual void listChangeFinished(XP_Bool asynchronous,
  254.                   MSG_NOTIFY_CODE notify,
  255.                   MSG_ViewIndex where, 
  256.                   int32 num, 
  257.                   int32 total_lines);
  258.  
  259.   Widget getScroller();
  260.  
  261. private:
  262.   XFE_Outlinable *m_outlinable;
  263.  
  264. #if defined(USE_MOTIF_DND)
  265.   XFE_OutlinerDrop *m_outlinerdrop;
  266.   XFE_OutlinerDrag *m_outlinerdrag;
  267. #endif /* USE_MOTIF_DND */
  268.  
  269.   XP_Bool setDefaultGeometry();
  270.  
  271.   /* used to maintain cached selection information */
  272.   void addSelection(int selected_line);
  273.   void removeSelection(int selected_line);
  274.   XP_Bool insertLines(int start, int count);
  275.   XP_Bool deleteLines(int start, int count);
  276.   void deselectAll();
  277.  
  278.   /* used to save off and restore the selection when our list
  279.      is going to get screwed up (as in mail/news sorting) */
  280.   void saveSelection();
  281.   void restoreSelection();
  282.  
  283.   /* used to restore a column on the right hand side. */
  284.   void hideColumn(int column_number);
  285.   void showColumn(int column_numder);
  286.  
  287.   void showHeaderDraw(XmLGridCallbackStruct *call);
  288.   void hideHeaderDraw(XmLGridCallbackStruct *call);
  289.   void showHeaderClick();
  290.   void hideHeaderClick();
  291.  
  292.   int numResizableVisibleColumns(int starting_at = 0);
  293.  
  294.   /* used to maintain the selection information */
  295.   int *m_selectedIndices;
  296.   int m_selectedItemCount;
  297.   int m_selectedSize;
  298.   int m_selectedCount;
  299.   int m_firstSelectedIndex;
  300.   int m_lastSelectedIndex;
  301.   int m_selectionDirection;  /* -1 for bottom-to-top, and 1 for top-to-bottom.
  302.                                 see the command in selectRangeByIndices */
  303.   /* this one is only used by listChange{Starting,Finished} */
  304.   void **m_selectedItems; 
  305.   XP_Bool m_selBlocked; /* False (default): can't select; True, otherwise */
  306.  
  307.   int m_totalLines;
  308.  
  309.     XP_Bool m_descendantSelectAllowed;
  310.   XP_Bool m_hideColumnsAllowed;
  311.  
  312.   // pointers used in calls to the flippyfunc and buttonfunc portions
  313.   // of the Outlinable interface.
  314.   OutlineButtonFuncData *m_buttonfunc_data;
  315.   OutlineFlippyFuncData *m_flippyfunc_data;
  316.  
  317.   int m_numcolumns;
  318.   int m_numvisible;
  319.   char *m_prefname;
  320.   char *m_geominfo;
  321.   void *m_visibleTimer;
  322.   int m_visibleLine;
  323.   int m_DataRow;
  324.   Time m_lastuptime;
  325.   Time m_lastdowntime;
  326.   int m_lastx;
  327.   int m_lasty;
  328.   int *m_columnwidths;
  329.   XP_Bool *m_columnResizable;
  330.   int *m_columnIndex;
  331.  
  332.   /* drag specific stuff. */
  333. #if !defined(USE_MOTIF_DND)
  334.   int m_lastmotionx;
  335.   int m_lastmotiony;
  336.   int m_hotSpot_x;
  337.   int m_hotSpot_y;
  338. #endif /* USE_MOTIF_DND */
  339.   XP_Bool m_ignoreevents;
  340. #if !defined(USE_MOTIF_DND)
  341.   fe_dnd_Type m_dragtype;
  342.   fe_icon *m_dragicon;
  343.   XFE_Component *m_source;
  344.   fe_dnd_SourceDropFunc m_sourcedropfunc;
  345.   void makeDragWidget(int x, int y, fe_dnd_Type type);
  346.   void destroyDragWidget();
  347. #endif /* USE_MOTIF_DND */
  348.  
  349. #if defined(USE_MOTIF_DND)
  350.   /* the pointer to the outlinable. */
  351.   void *m_dragsource;
  352.   FEGetDragTargetFunc m_dragTargetFunc;
  353.   FEGetDropTargetFunc m_dropTargetFunc;
  354.   FEGetDragIconDataFunc m_dragIconDataFunc;
  355.   FEConvertDragDataFunc m_dragConvFunc;
  356.   FEProcessTargetsFunc m_processTargetsFunc;
  357. #endif /* USE_MOTIF_DND */
  358.  
  359.   // XXX
  360.   XP_Bool m_dragrowbox;
  361.   void* m_dragscrolltimer;
  362.   int m_dragscrolldir;
  363.   int m_dragrow;
  364. #if !defined(USE_MOTIF_DND)
  365.   int m_dragcolumn;
  366. #endif /* USE_MOTIF_DND */
  367.   GC m_draggc;
  368.  
  369.   EventMask m_activity;
  370.  
  371.   /* the column that displays the sort indicator. */
  372.   int m_sortColumn; 
  373.   /* the direction of the sort. */
  374.   EOutlinerSortDirection m_sortDirection;
  375.  
  376.   /* the column that displays the pipes. */
  377.   int m_pipeColumn; 
  378.  
  379.   /* the column that resizes when the outliner resizes wider */
  380.   int m_resizeColumn; 
  381.  
  382.   /* used by the listChange{Starting,Finished} machinery to restore
  383.      the selection at the proper time. */
  384.   int m_listChangeDepth; 
  385.  
  386.   const char *styleToTag(EOutlinerTextStyle style);
  387.  
  388.   static fe_icon closedParentIcon;
  389.   static fe_icon openParentIcon;
  390.   static fe_icon showColumnIcon;
  391.   static fe_icon showColumnInsensIcon;
  392.   static fe_icon hideColumnIcon;
  393.   static fe_icon hideColumnInsensIcon;
  394.  
  395.   void setColumnResizableByIndex(int column_index, XP_Bool resizable);
  396.   XP_Bool getColumnResizableByIndex(int column_index);
  397.  
  398.   void setColumnWidthByIndex(int column_index, int width);
  399.   int getColumnWidthByIndex(int column_index);
  400.  
  401.   void rememberGeometry();
  402.   int getNumVisible(int default_visible);
  403.  
  404.   void drawDottedLine(GC gc, XRectangle *clipRect, int x1, int y1, int x2, int y2);
  405.  
  406.   void PixmapDraw(Pixmap pixmap, Pixmap mask,
  407.           int pixmapWidth, int pixmapHeight, unsigned char alignment, GC gc,
  408.           XRectangle *rect, XRectangle *clipRect, Pixel bg_color);
  409.  
  410.   EOutlinerPipeType getPipeType(XP_Bool expandable,
  411.                 XP_Bool expanded,
  412.                 int depth,
  413.                 OutlinerAncestorInfo *ancestorInfo);
  414.  
  415.   void pipeDraw(XmLGridCallbackStruct *call);
  416.   void headerCellDraw(XmLGridCallbackStruct *call);
  417.   void contentCellDraw(XmLGridCallbackStruct *call);
  418.   void celldraw(XtPointer callData);
  419.   void resize(XtPointer callData);
  420.   void sendClick(XEvent *event, Boolean only_if_not_selected);
  421.   void buttonEvent(XEvent *event, Boolean *c);
  422.  
  423.   static void celldrawCallback(Widget, XtPointer, XtPointer);
  424.   static void resizeCallback(Widget, XtPointer, XtPointer);
  425.   static void buttonEventHandler(Widget, XtPointer, XEvent *, Boolean *);
  426.  
  427.     /* tooltips
  428.      */
  429.   int     m_lastRow;
  430.   int     m_lastCol;
  431.   XP_Bool m_inGrid;
  432.   XP_Bool m_isFocus;
  433.     
  434.   char    *m_tip_msg_buf;
  435.   char    *m_doc_msg_buf;
  436.  
  437.   static  void tip_cb(Widget, XtPointer, XtPointer cb_data);
  438.   virtual void tipCB(Widget, XtPointer cb_data);
  439.  
  440. };
  441.  
  442. #endif /* _xfe_outliner_h */
  443.