home *** CD-ROM | disk | FTP | other *** search
/ Tools / WinSN5.0Ver.iso / NETSCAP.50 / WIN1998.ZIP / ns / cmd / macfe / rdfui / CNavCenterContextMenuAtt.cp < prev    next >
Encoding:
Text File  |  1998-04-08  |  4.0 KB  |  144 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. //
  20. // Mike Pinkerton, Netscape Communications
  21. //
  22. // A version of the contextual menu attachment that generates the menu from 
  23. // the RDF backend.
  24. //
  25.  
  26. #include "CNavCenterContextMenuAtt.h"
  27. #include "CHyperTreeFlexTable.h"
  28. #include "Netscape_constants.h"
  29. #include "CNavCenterSelectorPane.h"
  30.  
  31.  
  32. //
  33. // ConvertHTCommandToPPCommand
  34. //
  35. // The HyperTree has its own constants that represent the commands supplied by the
  36. // backend. In order to make the HT commands live in a powerplant world, we have to 
  37. // convert them.  This (simply) involves adding a base constant to the HT command to make the 
  38. // appropriate PP command.
  39. //
  40. CommandT 
  41. CNavCenterContextMenuAttachment :: ConvertHTCommandToPPCommand ( HT_MenuCmd inCmd )
  42. {
  43.     return inCmd + cmd_NavCenterBase;
  44.     
  45. } // ConvertHTCommandToPPCommand
  46.  
  47.  
  48. //
  49. // BuildMenu
  50. //
  51. // Overridden to create the menu from the RDF backend instead of from a resource.
  52. //
  53. LMenu*
  54. CNavCenterContextMenuAttachment :: BuildMenu ( ) 
  55. {
  56.     LMenu* menu = new LMenu(32001);        // load empty menu to fill in
  57.     HT_Cursor curs = NewHTContextMenuCursor();
  58.  
  59.     if ( !curs || !menu )
  60.         return NULL;
  61.         
  62.     HT_MenuCmd menuItem;
  63.     short after = 0;
  64.     while ( HT_NextContextMenuItem(curs, &menuItem) ) {
  65.         LStr255 itemName;
  66.         if ( menuItem == HT_CMD_SEPARATOR )
  67.             itemName = "\p-";
  68.         else
  69.             itemName = HT_GetMenuCmdName(menuItem);
  70.         menu->InsertCommand ( itemName, ConvertHTCommandToPPCommand(menuItem),
  71.                                 after );
  72.         after++;        
  73.     }
  74.     HT_DeleteContextMenuCursor ( curs );
  75.     
  76.     return menu;
  77.     
  78. } // BuildMenu
  79.  
  80.  
  81. //
  82. // NewHTContextMenuCursor
  83. //
  84. // Create the HT context menu cursor that is appropriate for this tree view
  85. //
  86. HT_Cursor
  87. CNavCenterContextMenuAttachment :: NewHTContextMenuCursor ( )
  88. {
  89.     PRBool clickInBackground = PR_TRUE;
  90.     CHyperTreeFlexTable* table = dynamic_cast<CHyperTreeFlexTable*>(mOwnerHost);
  91.     Assert_(table != NULL);
  92.     if ( table ) {
  93.         TableIndexT selectedRow = 0;
  94.         if ( table->GetNextSelectedRow(selectedRow) )
  95.             clickInBackground = PR_FALSE;
  96.     }
  97.         
  98.     return HT_NewContextualMenuCursor ( table->GetHTView(), PR_FALSE, clickInBackground );
  99.  
  100. } // NewHTContextMenuCursor
  101.  
  102.  
  103. //
  104. // PruneMenu
  105. //
  106. // Override to not do anything, since HT already prunes the list for us. The return
  107. // value is used as the default item, and we don't care about a default (as long as
  108. // this value is > 0).
  109. //
  110. UInt16
  111. CNavCenterContextMenuAttachment :: PruneMenu ( LMenu* /*inMenu*/ )
  112. {
  113.     return 1;
  114.  
  115. } // PruneMenu
  116.  
  117.  
  118. #pragma mark -- class CNavCenterSelectorContextMenuAttachment --
  119.  
  120.  
  121. //
  122. // NewHTContextMenuCursor
  123. //
  124. // Create the HT context menu cursor that is appropriate for this view
  125. //
  126. HT_Cursor
  127. CNavCenterSelectorContextMenuAttachment :: NewHTContextMenuCursor ( )
  128. {
  129.     CNavCenterSelectorPane* selectorPane = dynamic_cast<CNavCenterSelectorPane*>(mOwnerHost);
  130.     Assert_(selectorPane != NULL);
  131.     
  132.     // check if mouse is in background
  133.     Point where;
  134.     ::GetMouse(&where);
  135.     bool inBackground = selectorPane->FindSelectorForPoint(where) == NULL;
  136.     
  137.     HT_View currView = NULL;
  138.     if ( !inBackground )
  139.         currView = selectorPane->GetActiveWorkspace();
  140.     return HT_NewContextualMenuCursor ( currView, PR_TRUE, inBackground ? PR_TRUE : PR_FALSE );
  141.  
  142. } // NewHTContextMenuCursor
  143.  
  144.