home *** CD-ROM | disk | FTP | other *** search
/ Tools / WinSN5.0Ver.iso / NETSCAP.50 / WIN1998.ZIP / ns / cmd / xfe / src / NavCenterView.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1998-04-08  |  8.4 KB  |  306 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.    NavCenterView.h - Aurora/NavCenter view class
  20.    Created: Stephen Lamm <slamm@netscape.com>, 05-Nov-97.
  21.  */
  22.  
  23.  
  24.  
  25. #include "NavCenterView.h"
  26. #include "IconGroup.h"
  27.  
  28. #include <Xfe/XfeAll.h>
  29.  
  30. #if DEBUG_slamm
  31. #define D(x) x
  32. #else
  33. #define D(x)
  34. #endif
  35.  
  36. typedef struct _SelectorCBStruct {
  37.   XFE_NavCenterView *ncview;
  38.   HT_View view;
  39. } SelectorCBStruct;
  40.  
  41. XFE_NavCenterView::XFE_NavCenterView(XFE_Component *toplevel_component,
  42.                                      Widget parent, XFE_View *parent_view,
  43.                                      MWContext *context)
  44.   : XFE_View(toplevel_component, parent_view, context)
  45. {
  46.   D(printf("XFE_NavCenterView Constructor\n"););
  47.  
  48.   Widget pane = XtVaCreateManagedWidget("pane", xfePaneWidgetClass,
  49.                                         parent, NULL);
  50.   m_selector = XtVaCreateManagedWidget("selector",
  51.                                        xfeToolScrollWidgetClass,
  52.                                        pane, NULL);
  53.  
  54.   m_htview = NULL;
  55.   m_rdfview = new XFE_RDFView(this, pane, 
  56.                               NULL, context, m_htview);
  57.  
  58.   HT_Notification ns = new HT_NotificationStruct;
  59.   ns->notifyProc = notify_cb;
  60.   ns->data = this;
  61.  
  62.   m_pane = HT_NewPane(ns);
  63.   HT_SetPaneFEData(m_pane, this);
  64.  
  65.   // add our subviews to the list of subviews for command dispatching and
  66.   // deletion.
  67.   addView(m_rdfview);
  68.  
  69.   XtManageChild(m_selector);
  70.   m_rdfview->show();
  71.   XtManageChild(pane);
  72.  
  73.   setBaseWidget(pane);
  74. }
  75.  
  76.  
  77. XFE_NavCenterView::~XFE_NavCenterView()
  78. {
  79.     D(printf("XFE_NavCenterView DESTRUCTING\n"););
  80. }
  81.  
  82. //////////////////////////////////////////////////////////////////////////
  83. XP_Bool
  84. XFE_NavCenterView::isCommandEnabled(CommandType cmd,
  85.                                    void *calldata, XFE_CommandInfo*)
  86. {
  87.   if (cmd == xfeCmdChangeRDFView)
  88.     {
  89.       return TRUE;
  90.     }
  91.   else
  92.     {
  93.       return XFE_View::isCommandEnabled(cmd, calldata);
  94.     }
  95. }
  96.  
  97. void
  98. XFE_NavCenterView::doCommand(CommandType cmd, void *calldata, XFE_CommandInfo*info)
  99. {
  100.   if (cmd == xfeCmdChangeRDFView)
  101.     {
  102.       int viewNum = (int)calldata;
  103.       HT_View view = HT_GetNthView(m_pane,viewNum);
  104.  
  105.       setRDFView(view);
  106.  
  107.       return;
  108.     }
  109.   else
  110.     {
  111.       XFE_View::doCommand(cmd,calldata,info);
  112.     }
  113. }
  114.  
  115. Boolean
  116. XFE_NavCenterView::handlesCommand(CommandType cmd, void *calldata,
  117.                                   XFE_CommandInfo* info)
  118. {
  119.   if (cmd == xfeCmdChangeRDFView)
  120.     {
  121.       return TRUE;
  122.     }
  123.   else
  124.     {
  125.       return XFE_View::handlesCommand(cmd, calldata, info);
  126.     }
  127. }
  128.  
  129. XP_Bool
  130. XFE_NavCenterView::isCommandSelected(CommandType cmd,
  131.                                     void *calldata, XFE_CommandInfo* info)
  132. {
  133.     {
  134.       return XFE_View::isCommandSelected(cmd, calldata, info);
  135.     }
  136. }
  137.  
  138. char *
  139. XFE_NavCenterView::commandToString(CommandType cmd, void* calldata, 
  140.                                    XFE_CommandInfo* info)
  141. {
  142.   if (cmd == xfeCmdChangeRDFView)
  143.     {
  144.       int viewNum = (int)calldata;
  145.  
  146.       return HT_GetViewName(HT_GetNthView(m_pane, viewNum));
  147.     }
  148.   return NULL;
  149. }
  150.  
  151. //////////////////////////////////////////////////////////////////////////
  152. void notify_cb(HT_Notification ns, HT_Resource n, 
  153.                   HT_Event whatHappened)
  154. {
  155.   XFE_NavCenterView* theView = (XFE_NavCenterView*)ns->data;
  156.     
  157.   theView->notify(ns, n, whatHappened);
  158. }
  159.  
  160. void
  161. XFE_NavCenterView::notify(HT_Notification ns, HT_Resource n, 
  162.                   HT_Event whatHappened)
  163. {
  164.   switch (whatHappened) {
  165.   case HT_EVENT_NODE_ADDED:
  166.     D(printf("HT_Event: %s on %s\n","HT_EVENT_NODE_ADDED",
  167.              HT_GetNodeName(n)););
  168.     break;
  169.   case HT_EVENT_NODE_DELETED_DATA:
  170.     D(printf("HT_Event: %s on %s\n","HT_EVENT_NODE_DELETED_DATA",
  171.              HT_GetNodeName(n)););
  172.     break;
  173.   case HT_EVENT_NODE_DELETED_NODATA:
  174.     D(printf("HT_Event: %s on %s\n","HT_EVENT_NODE_DELETED_NODATA",
  175.              HT_GetNodeName(n)););
  176.     break;
  177.   case HT_EVENT_NODE_VPROP_CHANGED:
  178.     D(printf("HT_Event: %s on %s\n","HT_EVENT_NODE_VPROP_CHANGED",
  179.              HT_GetNodeName(n)););
  180.     break;
  181.   case HT_EVENT_NODE_SELECTION_CHANGED:
  182.     D(printf("HT_Event: %s on %s\n","HT_EVENT_NODE_SELECTION_CHANGED",
  183.              HT_GetNodeName(n)););
  184.     break;
  185.   case HT_EVENT_NODE_OPENCLOSE_CHANGED: 
  186.     {
  187.       D(printf("HT_Event: %s on %s\n","HT_EVENT_NODE_OPENCLOSE_CHANGED",
  188.                HT_GetNodeName(n)););
  189.       
  190.       m_rdfview->setRDFView(m_htview);
  191.       break;
  192.     }
  193.   case HT_EVENT_VIEW_CLOSED:
  194.     D(printf("HT_Event: %s on %s\n","HT_EVENT_VIEW_CLOSED",
  195.              HT_GetNodeName(n)););
  196.     break;
  197.   case HT_EVENT_VIEW_SELECTED:
  198.     D(printf("HT_Event: %s on %s\n","HT_EVENT_VIEW_SELECTED",
  199.              HT_GetNodeName(n)););
  200.     break;
  201.   case HT_EVENT_VIEW_ADDED: 
  202.     {
  203.       D(printf("HT_Event: %s on %s\n","HT_EVENT_VIEW_ADDED",
  204.                HT_GetNodeName(n)););
  205.       
  206.       HT_View view = HT_GetView(n);
  207.       
  208.       addRDFView(view);
  209.     }
  210.     break;
  211.   case HT_EVENT_NODE_OPENCLOSE_CHANGING:
  212.     D(printf("HT_Event: %s on %s\n","HT_EVENT_NODE_OPENCLOSE_CHANGING",
  213.              HT_GetNodeName(n)););
  214.     break;
  215.   default:
  216.     D(printf("HT_Event: Unknown type on %s\n",HT_GetNodeName(n)););
  217.     break;
  218.   }
  219. }
  220. //////////////////////////////////////////////////////////////////////
  221. void
  222. XFE_NavCenterView::setRDFView(HT_View view) 
  223. {
  224.   //m_htview = HT_GetNthView(m_pane, viewnum);
  225.   HT_SetSelectedView(m_pane, view);
  226.  
  227.   m_htview = view;
  228.   m_rdfview->setRDFView(view);
  229. }
  230. //////////////////////////////////////////////////////////////////////
  231. void
  232. XFE_NavCenterView::addRDFView(HT_View view) 
  233. {
  234.   XP_ASSERT(view);
  235.   if (!view) return;
  236.  
  237.   Widget toolbar;
  238.   //  WidgetList tool_items = NULL;
  239.  
  240.   XtVaGetValues(m_selector,XmNtoolBar,&toolbar,NULL);
  241.  
  242.   char *label = HT_GetViewName(view);
  243.   char *icon_url = HT_GetWorkspaceLargeIconURL(view);
  244.  
  245.   char name[8];
  246.   int ret = sscanf(icon_url, "icon/large:workspace,%s", name);
  247.   if (ret != 0) {
  248.     icon_url = XP_Cat("about:",name,".gif",NULL);
  249.  
  250.     // Load the icon here.
  251.     // copy windows(navcntr.cpp)? call IL_GetImage? or IL_GetImagePixmap?
  252.  
  253.     XP_FREE(icon_url);
  254.   }
  255.  
  256.   uint32 index = HT_GetViewIndex(view);
  257.  
  258.   char widget_name[128];
  259.   sprintf(widget_name,"button%d", index);
  260.   
  261.   Widget button = 
  262.       XtVaCreateManagedWidget(widget_name,
  263.                               xfeButtonWidgetClass,
  264.                               toolbar,
  265.                               XmNlabelAlignment, XmALIGNMENT_BEGINNING,
  266.                               NULL);
  267.  
  268.   XfeSetXmStringPSZ(button, XmNlabelString,
  269.                     XmFONTLIST_DEFAULT_TAG, label);
  270.   
  271.   SelectorCBStruct *cbdata = new SelectorCBStruct;
  272.   cbdata->ncview = this;
  273.   cbdata->view = view;
  274.   XtAddCallback(button,
  275.                 XmNactivateCallback,
  276.                 &XFE_NavCenterView::selector_activate_cb,
  277.                 (XtPointer) cbdata);
  278.   XtAddCallback(button,
  279.                 XmNdestroyCallback,
  280.                 &XFE_NavCenterView::selector_destroy_cb,
  281.                 (XtPointer) cbdata);
  282.  
  283. }
  284. //////////////////////////////////////////////////////////////////////
  285. void
  286. XFE_NavCenterView::selector_activate_cb(Widget        w,
  287.                                         XtPointer    clientData, 
  288.                                         XtPointer    callData)
  289. {    
  290.   SelectorCBStruct *cbdata = (SelectorCBStruct *)clientData;
  291.  
  292.   cbdata->ncview->setRDFView(cbdata->view);
  293. }
  294. //////////////////////////////////////////////////////////////////////
  295. void
  296. XFE_NavCenterView::selector_destroy_cb(Widget        w,
  297.                                         XtPointer    clientData, 
  298.                                         XtPointer    callData)
  299. {    
  300.   SelectorCBStruct *cbdata = (SelectorCBStruct *)clientData;
  301.  
  302.   printf("destroy selector cbdata\n");
  303.  
  304.   delete cbdata;
  305. }
  306.