home *** CD-ROM | disk | FTP | other *** search
/ Tools / WinSN5.0Ver.iso / NETSCAP.50 / WIN1998.ZIP / ns / cmd / xfe / src / RDFView.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1998-04-08  |  9.8 KB  |  428 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.    RDFView.h -- view of rdf data
  20.    Created: Stephen Lamm <slamm@netscape.com>, 5-Nov-97.
  21.  */
  22.  
  23.  
  24.  
  25. #include "RDFView.h"
  26. #include "Frame.h" // for xfe_ExecuteCommand
  27. #include "xfe2_extern.h"
  28. #ifdef DEBUG_slamm
  29. #define D(x) x
  30. #else
  31. #define D(x)
  32. #endif
  33.  
  34. // pixmaps for use in the bookmark window.
  35. fe_icon XFE_RDFView::bookmark = { 0 };
  36. fe_icon XFE_RDFView::closedFolder = { 0 };
  37. fe_icon XFE_RDFView::openedFolder = { 0 };
  38.  
  39. XFE_RDFView::XFE_RDFView(XFE_Component *toplevel, Widget parent,
  40.                          XFE_View *parent_view, MWContext *context,
  41.                          HT_View htview)
  42.   : XFE_View(toplevel, parent_view, context)
  43. {
  44.   // xxx Pull this info out of rdf
  45.   int num_columns = 1;
  46.   static int column_widths[] = {40};
  47.  
  48.   m_toplevel = getToplevel();
  49.   m_widget = getBaseWidget();
  50. #ifdef DEBUG_spence
  51.   if (m_toplevel != toplevel) {
  52.     printf ("m_toplevel != toplevel\n");
  53.   }
  54. #endif
  55.  
  56.   m_outliner = new XFE_Outliner("rdfList",
  57.                                 this, 
  58.                                 getToplevel(),
  59.                                 parent,
  60.                                 False, // constantSize 
  61.                                 True,  // hasHeadings
  62.                                 1, //num_columns, // Number of columns.
  63.                                 1, //num_columns, // Number of visible columns.
  64.                                 column_widths, 
  65.                                 NULL /*BOOKMARK_OUTLINER_GEOMETRY_PREF*/);
  66.  
  67.   m_outliner->setHideColumnsAllowed( TRUE );
  68.   m_outliner->setPipeColumn( 0 /*OUTLINER_COLUMN_NAME*/ );
  69.   m_outliner->setMultiSelectAllowed( TRUE );
  70.   setBaseWidget(m_outliner->getBaseWidget());
  71.  
  72.   {
  73.     Pixel bg_pixel;
  74.     
  75.     XtVaGetValues(m_widget, XmNbackground, &bg_pixel, 0);
  76.  
  77.     if (!bookmark.pixmap)
  78.       fe_NewMakeIcon(m_widget,
  79.              BlackPixelOfScreen(XtScreen(m_widget)),
  80.              bg_pixel,
  81.              &bookmark,
  82.              NULL,
  83.              BM_Bookmark.width, BM_Bookmark.height,
  84.              BM_Bookmark.mono_bits, BM_Bookmark.color_bits, BM_Bookmark.mask_bits, FALSE);
  85.     if (!closedFolder.pixmap)
  86.       fe_NewMakeIcon(m_widget,
  87.              BlackPixelOfScreen(XtScreen(m_widget)),
  88.              bg_pixel,
  89.              &closedFolder,
  90.              NULL,
  91.              BM_Folder.width, BM_Folder.height,
  92.              BM_Folder.mono_bits, BM_Folder.color_bits, BM_Folder.mask_bits, FALSE);
  93.  
  94.     if (!openedFolder.pixmap)
  95.       fe_NewMakeIcon(m_widget,
  96.              BlackPixelOfScreen(XtScreen(m_widget)),
  97.              bg_pixel,
  98.              &openedFolder,
  99.              NULL,
  100.              BM_FolderO.width, BM_FolderO.height,
  101.              BM_FolderO.mono_bits, BM_FolderO.color_bits, BM_FolderO.mask_bits, FALSE);
  102.   }
  103.  
  104.   setRDFView(htview);
  105. }
  106.  
  107. XFE_RDFView::~XFE_RDFView()
  108. {
  109.   //xxx what to delete?
  110. }
  111.  
  112. Boolean
  113. XFE_RDFView::isCommandEnabled(CommandType cmd, void *calldata,
  114.                               XFE_CommandInfo* info)
  115. {
  116.     {
  117.       return XFE_View::isCommandEnabled(cmd, calldata, info);
  118.     }
  119. }
  120.  
  121. void
  122. XFE_RDFView::doCommand(CommandType cmd, void *calldata, XFE_CommandInfo*info)
  123. {
  124.   const int *    selected;
  125.   int            count;
  126.   
  127.   m_outliner->getSelection(&selected, &count);
  128.         
  129.     {
  130.       XFE_View::doCommand(cmd,calldata,info);
  131.     }
  132. }
  133.  
  134. Boolean
  135. XFE_RDFView::handlesCommand(CommandType cmd, void *calldata,
  136.                             XFE_CommandInfo* info)
  137. {
  138.     {
  139.       return XFE_View::handlesCommand(cmd, calldata, info);
  140.     }
  141. }
  142.  
  143. XP_Bool
  144. XFE_RDFView::isCommandSelected(CommandType cmd,
  145.                                     void *calldata, XFE_CommandInfo* info)
  146. {
  147.     {
  148.       XFE_View *view = getParent();
  149.       return (view && view->isCommandSelected(cmd, calldata, info));
  150.     }
  151. }
  152.  
  153. char *
  154. XFE_RDFView::commandToString(CommandType cmd, void*, XFE_CommandInfo*)
  155. {
  156.     return NULL;
  157. }
  158.  
  159.  
  160. // Methods from the outlinable interface.
  161. void *
  162. XFE_RDFView::ConvFromIndex(int /*index*/)
  163. {
  164.   XP_ASSERT(0);
  165.   return 0;
  166. }
  167.  
  168. int
  169. XFE_RDFView::ConvToIndex(void */*item*/)
  170. {
  171.   XP_ASSERT(0);
  172.   return 0;
  173. }
  174.  
  175. void *
  176. XFE_RDFView::acquireLineData(int line)
  177. {
  178.   m_node = HT_GetNthItem(m_rdfview, line /*+ 1*/);
  179.  
  180.   if (!m_node)
  181.     return NULL;
  182.  
  183.   m_nodeDepth = HT_GetItemIndentation(m_node);
  184.   m_ancestorInfo = new OutlinerAncestorInfo[ m_nodeDepth + 1];
  185.  
  186.   if (m_nodeDepth)
  187.     {
  188.       HT_Resource tmp;
  189.       int i;
  190.           
  191.       for (tmp = m_node, i = m_nodeDepth;
  192.            tmp != NULL;
  193.            tmp = HT_GetParent(tmp), i --)
  194.         {
  195.           m_ancestorInfo[i].has_prev = HT_ItemHasBackwardSibling(tmp);
  196.           m_ancestorInfo[i].has_next = HT_ItemHasForwardSibling(tmp);
  197.         }
  198.     }
  199.   else
  200.     {
  201.       m_ancestorInfo[0].has_prev = HT_ItemHasBackwardSibling(m_node);
  202.       m_ancestorInfo[0].has_next = HT_ItemHasForwardSibling(m_node);
  203.     }
  204.   
  205.   return m_node;
  206. }
  207.  
  208. void
  209. XFE_RDFView::getTreeInfo(XP_Bool *expandable,
  210.                   XP_Bool *is_expanded,
  211.                   int *depth,
  212.                   OutlinerAncestorInfo **ancestor)
  213. {
  214.   XP_Bool is_node_expandable = False;
  215.   XP_Bool is_node_expanded = False;
  216.  
  217.   XP_ASSERT(m_node);
  218.  
  219.   if (!m_node)
  220.   {
  221.       return;
  222.   }
  223.  
  224.   is_node_expandable = HT_IsContainer(m_node);
  225.   if (is_node_expandable)
  226.     is_node_expanded = HT_IsContainerOpen(m_node);
  227.  
  228.   if (expandable)
  229.     *expandable = is_node_expandable;
  230.  
  231.   if (is_expanded)
  232.     *is_expanded = is_node_expanded;
  233.  
  234.   if (depth)
  235.     *depth = m_nodeDepth;
  236.  
  237.   if (ancestor)
  238.     *ancestor = m_ancestorInfo;
  239. }
  240.  
  241. EOutlinerTextStyle
  242. XFE_RDFView::getColumnStyle(int /*column*/)
  243. {
  244.   XP_ASSERT(m_node);
  245.  
  246.   return OUTLINER_Default;
  247.   //return BM_IsAlias(m_node) ? OUTLINER_Italic : OUTLINER_Default;
  248. }
  249.  
  250. char *
  251. XFE_RDFView::getColumnText(int /*column*/)
  252. {
  253.   static char node_buf[2048]; // does this need to be thread safe???
  254.   void *data;
  255.  
  256.   XP_ASSERT(m_node);
  257.  
  258.   // xxx Need error handling and column switching
  259.   HT_NodeDisplayString(m_node, node_buf, sizeof(node_buf));
  260.   return node_buf;
  261. }
  262.  
  263. fe_icon *
  264. XFE_RDFView::getColumnIcon(int column)
  265. {
  266.     XP_ASSERT(m_node);
  267.  
  268.     if (column != 0) {
  269.       return NULL;
  270.     }
  271.     if (HT_IsContainer(m_node)) {
  272.       if (HT_IsContainerOpen(m_node)) {
  273.         return &openedFolder;
  274.       } else {
  275.         return &closedFolder;
  276.       }
  277.     } else {
  278.       return &bookmark;
  279.     }
  280. }
  281.  
  282. char *
  283. XFE_RDFView::getColumnName(int /*column*/)
  284. {
  285.   // xxx Widget name
  286.   return "Name";
  287. }
  288.  
  289. char *
  290. XFE_RDFView::getColumnHeaderText(int /*column*/)
  291. {
  292.   // xxx Column Label
  293.   return "Name";
  294. }
  295.  
  296. fe_icon *
  297. XFE_RDFView::getColumnHeaderIcon(int /*column*/)
  298. {
  299.   return 0;
  300. }
  301.  
  302. EOutlinerTextStyle
  303. XFE_RDFView::getColumnHeaderStyle(int /*column*/)
  304. {
  305.   return OUTLINER_Default;
  306. }
  307.  
  308. void
  309. XFE_RDFView::releaseLineData()
  310. {
  311.   delete [] m_ancestorInfo;
  312.   m_ancestorInfo = NULL;
  313. }
  314.  
  315. void
  316. XFE_RDFView::Buttonfunc(const OutlineButtonFuncData *data)
  317. {
  318.   if (data->row == -1) 
  319.     {
  320.       // Click on Column header
  321.  
  322.       // data->column has the column
  323.       return;
  324.     }
  325.  
  326.   HT_Resource node = HT_GetNthItem(m_rdfview, data->row);
  327.  
  328.   if (!node) return;
  329.  
  330.   if (data->clicks == 1)
  331.     {
  332.       if (data->ctrl) 
  333.         {
  334.           HT_ToggleSelection(node);    
  335.           m_outliner->toggleSelected(data->row);
  336.         } 
  337.       else if (data->shift) 
  338.         {
  339.           HT_SetSelectionRange(node, m_node);
  340.           m_outliner->trimOrExpandSelection(data->row);
  341.         } 
  342.       else 
  343.         {
  344.           HT_SetSelection(node);
  345.           m_outliner->selectItemExclusive(data->row);
  346.  
  347.           if (data->button == Button2) 
  348.             {
  349.               // Dispatch in new window (same as double click)
  350.           char *s = HT_GetNodeURL (node);
  351.           URL_Struct *url = NET_CreateURLStruct (s, NET_DONT_RELOAD);
  352.           url->window_target = "_rdf_target";
  353.           fe_reuseBrowser (m_contextData, url);
  354.             }
  355.         }
  356.     }
  357.   else if (data->clicks == 2) 
  358.     {
  359.       HT_SetSelection(node);
  360.       m_outliner->selectItemExclusive(data->row);
  361.       
  362.       if (HT_IsContainer(node))
  363.         {
  364.           PRBool isOpen;
  365.  
  366.           HT_GetOpenState(node, &isOpen);
  367.           if (isOpen)
  368.             {
  369.               //BM_ClearAllChildSelection(m_contextData, node, TRUE);
  370.             }
  371.           
  372.           HT_SetOpenState(m_node, (PRBool)!isOpen);
  373.         }
  374.       else
  375.         {
  376.           // Dispatch in new window (same as button2 above)
  377.       char *s = HT_GetNodeURL (node);
  378.       URL_Struct *url = NET_CreateURLStruct (s, NET_DONT_RELOAD);
  379.       url->window_target = "_rdf_target";
  380.       fe_reuseBrowser (m_contextData, url);
  381.         }
  382.     }
  383.   
  384.   getToplevel()->notifyInterested(XFE_View::chromeNeedsUpdating);
  385. }
  386.  
  387. void
  388. XFE_RDFView::Flippyfunc(const OutlineFlippyFuncData *data)
  389. {
  390.   HT_Resource node = HT_GetNthItem(m_rdfview, data->row);
  391.   if (node && HT_IsContainer(node)) 
  392.     {
  393.       PRBool isOpen;
  394.       
  395.       HT_GetOpenState(node, &isOpen);
  396.       if (isOpen)
  397.         {
  398.           //BM_ClearAllChildSelection(m_contextData, node, TRUE);
  399.         }
  400.       
  401.       HT_SetOpenState(m_node, (PRBool)!isOpen);
  402.     }
  403. }
  404.  
  405. XFE_Outliner *
  406. XFE_RDFView::getOutliner()
  407. {
  408.   return m_outliner;
  409. }
  410.  
  411. void
  412. XFE_RDFView::setRDFView(HT_View htview)
  413. {
  414.   m_rdfview = htview;
  415.  
  416.   if (!m_rdfview) return;
  417.   
  418.   int itemCount =  HT_GetItemListCount(htview);
  419.  
  420.   m_outliner->change(0, itemCount,
  421.                      (itemCount > 0 ? itemCount : 0));
  422. }
  423.  
  424.  
  425.  
  426.  
  427.  
  428.