home *** CD-ROM | disk | FTP | other *** search
/ Tools / WinSN5.0Ver.iso / NETSCAP.50 / WIN1998.ZIP / ns / cmd / xfe / src / BookmarkMenu.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1998-04-08  |  7.3 KB  |  254 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.    BookmarkMenu.cpp -- class for doing the dynamic bookmark menus
  20.    Created: Chris Toshok <toshok@netscape.com>, 19-Dec-1996.
  21.  */
  22.  
  23.  
  24.  
  25. #include "BookmarkMenu.h"
  26. #include "BookmarkFrame.h"
  27. #include "BookmarkView.h"
  28. #include "PersonalToolbar.h"
  29. #include "bkmks.h"
  30.  
  31. #include <Xfe/XfeAll.h>
  32.  
  33. #define IS_CASCADE(w)    (XmIsCascadeButton(w) || XmIsCascadeButtonGadget(w))
  34. #define IS_PUSH(w)        (XmIsPushButton(w) || XmIsPushButtonGadget(w))
  35.  
  36. //////////////////////////////////////////////////////////////////////////
  37. XFE_BookmarkMenu::XFE_BookmarkMenu(MWContext *    bookmarkContext,
  38.                                    Widget        cascade,
  39.                                    XFE_Frame *    frame,
  40.                                    XP_Bool        onlyHeaders,
  41.                                    XP_Bool        fancyItems) :
  42.     XFE_BookmarkBase(bookmarkContext,frame,onlyHeaders,fancyItems),
  43.     _cascade(cascade),
  44.     _subMenu(NULL),
  45.     _firstSlot(0)
  46. {
  47.     // Obtain the submenu and the first available slot
  48.     XtVaGetValues(_cascade,XmNsubMenuId,&_subMenu,NULL);
  49.     XtVaGetValues(_subMenu,XmNnumChildren,&_firstSlot,NULL);
  50.  
  51.     // When the cascade is blown away, so are we
  52.     XtAddCallback(_cascade,
  53.                   XmNdestroyCallback,
  54.                   &XFE_BookmarkMenu::destroy_cb,
  55.                   (XtPointer) this);
  56.  
  57.     // make sure we initially install an update callback
  58.      XtAddCallback(_cascade,
  59.                   XmNcascadingCallback,
  60.                   &XFE_BookmarkMenu::update_cb,
  61.                   (XtPointer) this);
  62.  
  63.     // Keep track of the submenu mapping
  64.     trackSubmenuMapping(_subMenu);
  65. }
  66. //////////////////////////////////////////////////////////////////////////
  67. void
  68. XFE_BookmarkMenu::generate(Widget        cascade, 
  69.                            XtPointer    clientData,
  70.                            XFE_Frame *    frame)
  71. {
  72.     XFE_BookmarkMenu * object;
  73.  
  74.     object = new XFE_BookmarkMenu(XFE_BookmarkFrame::main_bm_context,
  75.                                   cascade,
  76.                                   frame,
  77.                                   (int) clientData,
  78.                                   True);
  79. }
  80. //////////////////////////////////////////////////////////////////////////
  81. /* static */ void
  82. XFE_BookmarkMenu::generateQuickfile(Widget        cascade, 
  83.                                     XtPointer    clientData,
  84.                                     XFE_Frame *    frame)
  85. {
  86.     XFE_BookmarkMenu * object;
  87.  
  88.     object = new XFE_BookmarkMenu(XFE_BookmarkFrame::main_bm_context,
  89.                                   cascade,
  90.                                   frame,
  91.                                   (int) clientData,
  92.                                   True);
  93.  
  94.     // Store the BookmarkMenu instance in the quickfile button 
  95.     // XmNinstancePointer.  This overrides the XmNinstancePointer 
  96.     // installed by the XFE_Button class
  97.     XtVaSetValues(cascade,XmNinstancePointer,(XtPointer) object,NULL);
  98. }
  99. //////////////////////////////////////////////////////////////////////////
  100. /* static */ void
  101. XFE_BookmarkMenu::destroy_cb(Widget        /* w */,
  102.                              XtPointer    client_data,
  103.                              XtPointer    /* call_data*/)
  104. {
  105.     XFE_BookmarkMenu * object = (XFE_BookmarkMenu *) client_data;
  106.  
  107.     delete object;
  108. }
  109. //////////////////////////////////////////////////////////////////////////
  110. /* static */ void
  111. XFE_BookmarkMenu::update_cb(Widget        cascade,
  112.                             XtPointer    client_data,
  113.                             XtPointer    /* call_data */)
  114. {
  115.     XFE_BookmarkMenu *    object = (XFE_BookmarkMenu *) client_data;
  116.     Widget                subMenu;
  117.  
  118.     XtVaGetValues(cascade,XmNsubMenuId,&subMenu,NULL);
  119.  
  120.     // Really update
  121.     object->reallyUpdateRoot();
  122.  
  123.     // Make sure the submenu is realized
  124.     XtRealizeWidget(subMenu);
  125.  
  126.     // Remove this callback now that we have been updated
  127.     XtRemoveCallback(cascade,
  128.                      XmNcascadingCallback,
  129.                      &XFE_BookmarkMenu::update_cb,
  130.                      (XtPointer) object);
  131. }
  132. //////////////////////////////////////////////////////////////////////////
  133. /* virtual */ void
  134. XFE_BookmarkMenu::prepareToUpdateRoot()
  135. {
  136.     // This may seem stupid, but it keeps us from having more than
  137.     // one reference to this particular callback without having
  138.     // to worry about other cascadingCallbacks.
  139.     
  140.     // remove it if it's already there
  141.     XtRemoveCallback(_cascade,
  142.                      XmNcascadingCallback,
  143.                      &XFE_BookmarkMenu::update_cb,
  144.                      (XtPointer) this);
  145.     
  146.     // and then add it back.
  147.     XtAddCallback(_cascade,
  148.                   XmNcascadingCallback,
  149.                   &XFE_BookmarkMenu::update_cb,
  150.                   (XtPointer) this);
  151. }
  152. //////////////////////////////////////////////////////////////////////////
  153. /* virtual */ void
  154. XFE_BookmarkMenu::reallyUpdateRoot()
  155. {
  156.      WidgetList        children;
  157.      Cardinal        numChildren;
  158.      BM_Entry *        root = getMenuFolder();
  159.  
  160.     // Ignore the root header (ie, "Joe's Bookmarks")
  161.     if (root && BM_IsHeader(root))
  162.     {
  163.         root = BM_GetChildren(root);
  164.     }
  165.  
  166.      XfeChildrenGet(_subMenu,&children,&numChildren);    
  167.     
  168.     //  XtUnrealizeWidget(m_subMenu);
  169.  
  170.      // Get rid of the previous items we created
  171.      if (children && numChildren)
  172.     {
  173.          children += _firstSlot;
  174.  
  175.          numChildren -= _firstSlot;
  176.  
  177.          if (children && numChildren)
  178.         {
  179.              XtUnmanageChildren(children,numChildren);
  180.       
  181.              fe_DestroyWidgetTree(children,numChildren);
  182.         }
  183.     }
  184.  
  185.      // Create the entries if any
  186.      if (root)
  187.      {
  188.          createItemTree(_subMenu,root);
  189.      }
  190. }
  191. //////////////////////////////////////////////////////////////////////////
  192. /* virtual */ void
  193. XFE_BookmarkMenu::enableDropping()
  194. {
  195.     // Gurantee that the popup and items and created and realized or
  196.     // else the setFixedSensitive() call will have no items to modify
  197.     update_cb(_cascade,(XtPointer) this,(XtPointer) NULL);
  198.  
  199.     // Chain
  200.     XFE_BookmarkBase::enableDropping();
  201.  
  202.     // Make all the fixed items insensitive
  203.     setFixedItemSensitive(False);
  204. }
  205. //////////////////////////////////////////////////////////////////////////
  206. /* virtual */ void
  207. XFE_BookmarkMenu::disableDropping()
  208. {
  209.     // Chain
  210.     XFE_BookmarkBase::disableDropping();
  211.  
  212.     // Make all the fixed items sensitive
  213.     setFixedItemSensitive(True);
  214. }
  215. //////////////////////////////////////////////////////////////////////////
  216. /* virtual */ void
  217. XFE_BookmarkMenu::enableFiling()
  218. {
  219.     XfeBmAccentSetFileMode(XmACCENT_FILE_SELF);
  220.     XfeBmAccentEnable();
  221. }
  222. //////////////////////////////////////////////////////////////////////////
  223. /* virtual */ void
  224. XFE_BookmarkMenu::disableFiling()
  225. {
  226.     XfeBmAccentSetFileMode(XmACCENT_FILE_ANYWHERE);
  227.     XfeBmAccentDisable();
  228. }
  229. //////////////////////////////////////////////////////////////////////////
  230. void
  231. XFE_BookmarkMenu::setFixedItemSensitive(XP_Bool state)
  232. {
  233.      WidgetList        children;
  234.      Cardinal        numChildren;
  235.  
  236.      XfeChildrenGet(_subMenu,&children,&numChildren);    
  237.     
  238.      // Make sure some fixed items exist
  239.      if (children && numChildren && _firstSlot && (_firstSlot < numChildren))
  240.     {
  241.         Cardinal i;
  242.  
  243.         // Set the sensitivity state for all the fixed push button items
  244.         for (i = 0; i < _firstSlot; i++)
  245.         {
  246.             if (IS_PUSH(children[i]) || IS_CASCADE(children[i]))
  247.             {
  248.                 XtSetSensitive(children[i],state);
  249.             }
  250.         }
  251.     }
  252. }
  253. //////////////////////////////////////////////////////////////////////////
  254.