home *** CD-ROM | disk | FTP | other *** search
/ Tools / WinSN5.0Ver.iso / NETSCAP.50 / WIN1998.ZIP / ns / cmd / winfe / popup.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1998-04-08  |  42.7 KB  |  1,431 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. #include "stdafx.h"
  20.  
  21. #include "cntritem.h"
  22. #include "cxsave.h"
  23. #include "netsvw.h"
  24. #include "mainfrm.h"
  25. #include "shcut.h"
  26. #include "shcutdlg.h"
  27. #include "np.h"
  28. #include "feembed.h"
  29. #include "feimage.h"
  30. #include "prefInfo.h"
  31. #include "mailmisc.h"
  32. #include "libi18n.h"
  33.  
  34. //
  35. // If the mouse is over a link or an image, allow the user to copy the URL
  36. // to the clipboard
  37. //
  38. BOOL CNetscapeView::AddClipboardToPopup(CMenu * pMenu, LO_Element * pElement, BOOL bAddSeparator)
  39. {
  40.     BOOL    bLink, bImage, bCopy;
  41.  
  42.     // See if it can be copied
  43.     bCopy = GetContext()->CanCopySelection();
  44.  
  45.     //    See if it's a link
  46.     CString csURL = GetAnchorHref(pElement);
  47.     bLink = !csURL.IsEmpty();
  48.  
  49.     //    See if it's an image
  50.     csURL = GetImageHref(pElement);
  51.     bImage = !csURL.IsEmpty();
  52.  
  53.     if((bCopy || bLink || bImage) && bAddSeparator)
  54.         pMenu->AppendMenu(MF_SEPARATOR);
  55.  
  56.     
  57.     if(bCopy)
  58.     {
  59.         pMenu->AppendMenu(MF_ENABLED,
  60.                           ID_EDIT_COPY,
  61.                           szLoadString(ID_POPUP_COPY));
  62.     }
  63.  
  64.  
  65.     if (bLink) {
  66.         pMenu->AppendMenu(MF_ENABLED,
  67.                           ID_POPUP_COPYLINKCLIPBOARD,
  68.                           szLoadString(IDS_POPUP_COPYLINKCLIPBOARD));
  69.     }
  70.  
  71.     if (bImage) {
  72.         pMenu->AppendMenu(MF_ENABLED,
  73.                           ID_POPUP_COPYIMGLOC2CLIPBOARD,
  74.                           szLoadString(IDS_POPUP_COPYIMGLOC2CLIPBOARD));
  75.     }
  76.  
  77.  
  78.     return(bLink || bCopy || bImage || bAddSeparator);
  79. }
  80.  
  81. //
  82. // If the mouse is over a link, add the appropriate items to the list
  83. // If we're in a browser window then bBrowser is TRUE.
  84. BOOL CNetscapeView::AddLinkToPopup(CMenu * pMenu, LO_Element * pElement, BOOL bBrowser)
  85. {
  86.     UINT uState, uSaveAsState, uMailtoState;
  87.  
  88.     //    If there is no link just return
  89.     CString csAppend = m_csRBLink;
  90.     BOOL bLink = !csAppend.IsEmpty();
  91.     BOOL bFrame = FALSE;
  92.  
  93.     CString csEntry;
  94.  
  95.     if(bLink)    {
  96.         // We need slightly different text in menu to differentiate between
  97.         //  Browser and Editor windows
  98.         // "Browse to: "
  99.         csEntry.LoadString(IDS_POPUP_LOAD_LINK_EDT);
  100.         uState = MF_ENABLED;
  101.  
  102.         LPSTR    lpszSuggested = 
  103. #ifdef MOZ_MAIL_NEWS      
  104.          MimeGuessURLContentName(GetContext()->GetContext(), csAppend);
  105. #else
  106.          NULL;
  107. #endif                  
  108.         if (lpszSuggested) {
  109.             csEntry += "(";
  110.             csEntry += lpszSuggested;
  111.             csEntry += ")";
  112.             XP_FREE(lpszSuggested);
  113.  
  114.         } else {
  115.             WFE_CondenseURL(csAppend, 25);
  116.             csEntry += csAppend;        
  117.         }
  118.  
  119.         csAppend.Empty();
  120.  
  121.  
  122.         //    Need to figure out mailto state, and any other URLs
  123.         //        that won't make sense in a new window, or with
  124.         //        save as.
  125.         if(strnicmp(m_csRBLink, "mailto:", 7) == 0 || strnicmp(m_csRBLink, "telnet:", 7) == 0 ||
  126.             strnicmp(m_csRBLink, "tn3270:", 7) == 0 || strnicmp(m_csRBLink, "rlogin:", 7) == 0)    {
  127.             uMailtoState = MF_GRAYED;
  128.         }
  129.         else    {
  130.             uMailtoState = MF_ENABLED;
  131.         }
  132.  
  133.         //  Need to figure out if we can do a save as without interrupting the window.
  134.         //    But now, we don't need to!
  135.         uSaveAsState = MF_ENABLED;
  136.         if(uMailtoState == MF_GRAYED)   {
  137.             uSaveAsState = MF_GRAYED;
  138.         }
  139.     }
  140.  
  141.     // Add "Open in Editor" only if a Browser context
  142.     //  because of a bug (18428) in editing link in mail message
  143.     // TODO: Lou fixed mail bug -- remove this context check later
  144.     // "Open in &New Browser Window"
  145.  
  146.     CString cs;
  147.  
  148.     if(bLink)
  149.     {
  150.         if(bBrowser)
  151.             cs.LoadString(IDS_POPUP_LOADLINKNEWWINDOW);
  152.         else
  153.             cs.LoadString(IDS_POPUP_LOADLINKNAVIGATOR);
  154.  
  155.         pMenu->AppendMenu(uMailtoState, ID_POPUP_LOADLINKNEWWINDOW, cs);
  156.     }
  157.  
  158.  
  159.     if(GetContext() && GetContext()->IsGridCell())
  160.     {
  161.         cs.LoadString(IDS_POPUP_LOADFRAMENEWWINDOW);
  162.         bFrame = TRUE;
  163.         pMenu->AppendMenu(MF_ENABLED, ID_POPUP_LOADFRAMENEWWINDOW, cs);
  164.     }
  165.  
  166. #ifdef EDITOR
  167.     if(bLink)
  168.     {
  169.         int type = NET_URL_Type(m_csRBLink);
  170.         // Only add menu item if we are sure we can edit the link
  171.         if( type == FTP_TYPE_URL  ||
  172.             type == HTTP_TYPE_URL ||
  173.             type == SECURE_HTTP_TYPE_URL ||
  174.             type == FILE_TYPE_URL )
  175.         {
  176.             cs.LoadString(IDS_POPUP_EDIT_LINK);
  177.             pMenu->AppendMenu(uMailtoState,ID_POPUP_EDIT_LINK, cs);
  178.         }
  179.     }
  180. #endif /* EDITOR */
  181.  
  182.     return(bLink || bFrame);
  183. }
  184.  
  185.  
  186. //
  187. // If the mouse is over an embedded object, add the appropriate items to the list
  188. //
  189. BOOL CNetscapeView::AddEmbedToPopup(CMenu * pMenu, LO_Element * pElement, CL_Layer *layer, BOOL bAddSeparator)
  190. {
  191.     
  192.     UINT uState, uInlineState, uSaveAsState;
  193.     CString csAppend, csEntry;
  194.  
  195.     //    Inline
  196.     CNetscapeCntrItem *pItem = NULL;
  197.     if(pElement != NULL && pElement->type == LO_EMBED)  {
  198.         NPEmbeddedApp *pPluginShim = (NPEmbeddedApp *)((LO_EmbedStruct *)pElement)->FE_Data;
  199.         if(pPluginShim != NULL && wfe_IsTypePlugin(pPluginShim) == FALSE)    {
  200.             pItem = (CNetscapeCntrItem *)pPluginShim->fe_data;
  201.         }
  202.     }
  203.  
  204.     if(pItem != NULL && pItem->m_bLoading == FALSE && pItem->m_lpObject != NULL)  {
  205.         //  Embed rules!
  206.  
  207.         csAppend = m_csRBEmbed;
  208.  
  209.         // if there is no embeded element don't do anything
  210.         if(csAppend.IsEmpty())
  211.             return bAddSeparator;
  212.  
  213.         if(bAddSeparator)
  214.             pMenu->AppendMenu(MF_SEPARATOR);
  215.  
  216.         csEntry.LoadString(IDS_POPUP_LOADEMBED);
  217.  
  218.         if(csAppend.IsEmpty() == TRUE || pItem->m_bBroken == TRUE)  {
  219.             uState = MF_GRAYED;
  220.             uInlineState = MF_GRAYED;
  221.             uSaveAsState = MF_GRAYED;
  222.             csAppend.LoadString(IDS_POPUP_NOEMBED);
  223.             csEntry += csAppend;
  224.         }
  225.         else    {
  226.             CString csActivate;
  227.             csActivate.LoadString(IDS_POPUP_ACTIVATE_EMBED);
  228.             csEntry = csActivate + csEntry;
  229.             uState = MF_ENABLED;
  230.             WFE_CondenseURL(csAppend, 25);
  231.             csEntry += csAppend;
  232.             csAppend.Empty();
  233.  
  234.             //  Eventually, we'll need to do selective inline loading of embedded items.
  235.             uInlineState = MF_GRAYED;
  236.  
  237.             //  Need to figure out if we can do a save as without interrupting the window.
  238.             uSaveAsState = MF_ENABLED;
  239.         }
  240.         pMenu->AppendMenu(uState, ID_POPUP_ACTIVATEEMBED, csEntry);
  241.  
  242.         csEntry.LoadString(IDS_POPUP_SAVEEMBEDAS);
  243.         pMenu->AppendMenu(uSaveAsState, ID_POPUP_SAVEEMBEDAS, csEntry);
  244.  
  245.         csEntry.LoadString(IDS_POPUP_COPYEMBEDLOC);
  246.         pMenu->AppendMenu(MF_ENABLED, ID_POPUP_COPYEMBEDLOC, csEntry);
  247.  
  248.         CString csDescription;
  249.         if(pItem->m_bBroken == TRUE)    {
  250.             csDescription.LoadString(IDS_UNKNOWN_DOCTYPE);
  251.         }
  252.         else    {
  253.             pItem->GetUserType(USERCLASSTYPE_SHORT, csDescription);
  254.         }
  255.         csEntry.LoadString(IDS_POPUP_COPYEMBEDDATA);
  256.         csEntry += csDescription;
  257.         pMenu->AppendMenu(uState, ID_POPUP_COPYEMBEDDATA, csEntry);
  258.  
  259.         //  Selective inline loading to be done here.
  260.  
  261.         return TRUE;
  262.     }
  263.  
  264.     return bAddSeparator;
  265. }
  266.  
  267. BOOL CNetscapeView::AddSaveItemsToPopup(CMenu * pMenu, LO_Element * pElement, CL_Layer *layer, BOOL bAddSeparator)
  268. {
  269.     BOOL bLink, bImage;
  270.  
  271.     //    See if it's a link
  272.     CString csURL = m_csRBLink;
  273.     bLink = !csURL.IsEmpty();
  274.  
  275.     //    See if it's an image
  276.     CString imageURL = m_csRBImage;
  277.     bImage = !imageURL.IsEmpty();
  278.  
  279.     CString csEntry;
  280.  
  281.     if((bLink || bImage) && bAddSeparator)
  282.         pMenu->AppendMenu(MF_SEPARATOR);
  283.  
  284.     if(bLink)
  285.         pMenu->AppendMenu(MF_ENABLED, ID_POPUP_SAVELINKCONTENTS,
  286.                           szLoadString(IDS_POPUP_SAVELINKCONTENTS));
  287.  
  288.     if(bImage && pElement && pElement->type == LO_IMAGE)
  289.     {
  290.         LO_ImageStruct *pImage = (LO_ImageStruct *)pElement;
  291. #ifdef EDITOR
  292.         // Save the image object just like we do
  293.         //   during drag n drop so we can copy
  294.         //   all image data to clipboard
  295.         GetContext()->m_pLastImageObject = pImage;
  296. #endif
  297.  
  298.         // Allow them to save the image, or use it as wallpaper
  299.         //  Only, can't save internal icons.
  300.         csEntry.LoadString(IDS_POPUP_SAVEIMAGEAS);
  301.         IL_ImageReq *image_req = pImage->image_req;
  302.         IL_Pixmap *image = IL_GetImagePixmap(image_req);
  303.         if (image) {
  304.             FEBitmapInfo* imageInfo = (FEBitmapInfo*)image->client_data;
  305.             if (!image->bits && imageInfo && !imageInfo->hBitmap)
  306.                 pMenu->AppendMenu(MF_GRAYED,ID_POPUP_SAVEIMAGEAS, csEntry);
  307.             else
  308.                 pMenu->AppendMenu( MF_ENABLED,ID_POPUP_SAVEIMAGEAS, csEntry);
  309.         }
  310.  
  311.     } else {
  312.         LO_ImageStruct *pLOImage;
  313.         CL_Layer *parent_layer;
  314.         char *layer_name;
  315.         layer_name = CL_GetLayerName(layer);
  316.         if (layer_name && ((XP_STRCMP(layer_name, LO_BODY_LAYER_NAME) == 0) ||
  317.                     (XP_STRCMP(layer_name, LO_BACKGROUND_LAYER_NAME) == 0))) {
  318.             parent_layer = CL_GetLayerParent(layer);
  319.             pLOImage = LO_GetLayerBackdropImage(parent_layer);
  320.         }
  321.         else
  322.             pLOImage = LO_GetLayerBackdropImage(layer);
  323.  
  324.         if (pLOImage && pLOImage->image_req) {
  325.             CString    strEntry;
  326.            
  327.             m_csRBImage = (char *) pLOImage->image_url;
  328.             strEntry.LoadString(IDS_POPUP_SAVEBACKGROUNDAS);
  329.             pMenu->AppendMenu(MF_ENABLED, ID_POPUP_SAVEIMAGEAS, strEntry);
  330.             m_pRBElement = (LO_Element*)pLOImage;
  331.             PA_UNLOCK(pLOImage->image_url);
  332.             // Do your stuff here.
  333.         }
  334.     }
  335.  
  336.     return (bLink || bImage || bAddSeparator);
  337.   }
  338.  
  339. void CNetscapeView::AddBrowserItemsToPopup(CMenu * pMenu, LO_Element * pElement, CL_Layer *layer)
  340. {
  341.     CString imageURL = GetImageHref(pElement);
  342.     Bool bImage = !imageURL.IsEmpty();
  343.  
  344.     CString csEntry;
  345.  
  346.     if(bImage && pElement && pElement->type == LO_IMAGE)
  347.     {
  348.         LO_ImageStruct *pImage = (LO_ImageStruct *)pElement;
  349.  
  350.         #ifdef EDITOR
  351.         // Save the image object just like we do
  352.         //   during drag n drop so we can copy
  353.         //   all image data to clipboard
  354.             GetContext()->m_pLastImageObject = pImage;
  355.         #endif
  356.  
  357.         IL_ImageReq *image_req = pImage->image_req;
  358.         IL_Pixmap *image = IL_GetImagePixmap(image_req);
  359.         if (image) {
  360.             csEntry.LoadString(IDS_POPUP_SETASWALLPAPER);
  361.             pMenu->AppendMenu(GetContext()->CanWriteBitmapFile(pImage) ? MF_ENABLED : MF_GRAYED,
  362.                 ID_POPUP_SETASWALLPAPER, csEntry);
  363.         }
  364.  
  365.     } else {
  366.         // this is the case for saving backdrop image.
  367.         LO_ImageStruct *pLOImage;
  368.         CL_Layer *parent_layer;
  369.         char *layer_name;
  370.         layer_name = CL_GetLayerName(layer);
  371.         if (layer_name && ((XP_STRCMP(layer_name, LO_BODY_LAYER_NAME) == 0) ||
  372.                     (XP_STRCMP(layer_name, LO_BACKGROUND_LAYER_NAME) == 0))) {
  373.             parent_layer = CL_GetLayerParent(layer);
  374.             pLOImage = LO_GetLayerBackdropImage(parent_layer);
  375.         }
  376.         else
  377.             pLOImage = LO_GetLayerBackdropImage(layer);
  378.         if (pLOImage && pLOImage->image_req) {
  379.             CString    strEntry;
  380.             
  381.             m_csRBImage = (char*)pLOImage->image_url;
  382.             strEntry.LoadString(IDS_POPUP_SETASWALLPAPER);
  383.             pMenu->AppendMenu(MF_ENABLED, ID_POPUP_SETASWALLPAPER, strEntry);
  384.             m_pRBElement = (LO_Element*)pLOImage;
  385.             PA_UNLOCK(pLOImage->image_url);
  386.             // Do your stuff here.
  387.         }        
  388.     }
  389.  
  390.     MWContext *pContext = GetContext()->GetContext();
  391.  
  392.     csEntry.LoadString(IDS_POPUP_ADDLINK2BOOKMARKS);
  393.     pMenu->AppendMenu(                
  394.         (SHIST_GetCurrent(&(pContext->hist)) != NULL) ? MF_ENABLED : MF_GRAYED,
  395.         ID_POPUP_ADDLINK2BOOKMARKS, csEntry);
  396.  
  397.     // check for shell support and add shortcut item if available
  398.     CInternetShortcut InternetShortcut;
  399.     if (InternetShortcut.ShellSupport())
  400.     {
  401.         csEntry.LoadString(IDS_POPUP_SHORTCUT);
  402.            pMenu->AppendMenu(
  403.             (SHIST_GetCurrent(&(pContext->hist)) != NULL) ? MF_ENABLED : MF_GRAYED,
  404.             ID_POPUP_INTERNETSHORTCUT, csEntry );
  405.  
  406.     }
  407.  
  408.     pMenu->AppendMenu((SHIST_GetCurrent(&(pContext->hist)) != NULL) ? MF_ENABLED : MF_GRAYED,
  409.                        ID_POPUP_MAILTO, szLoadString(IDS_POPUP_SENDPAGE));
  410.  
  411. }
  412.  
  413. void CNetscapeView::AddNavigateItemsToPopup(CMenu *pMenu, LO_Element * pElement, CL_Layer *layer)
  414. {
  415.         CString csEntry;
  416.  
  417.         // Back
  418.         csEntry.LoadString(IDS_POPUP_BACK);
  419.         pMenu->AppendMenu(MF_STRING, ID_NAVIGATE_BACK, csEntry);
  420.     
  421.         //    Forward
  422.         csEntry.LoadString(IDS_POPUP_FORWARD);
  423.         pMenu->AppendMenu(MF_STRING, ID_NAVIGATE_FORWARD, csEntry);
  424.  
  425.         if(GetContext()->IsGridCell())
  426.         {
  427.             csEntry.LoadString(IDS_POPUP_RELOADFRAME);
  428.             pMenu->AppendMenu(MF_STRING, ID_NAVIGATE_RELOADCELL, csEntry);
  429.         }
  430.         else
  431.         {
  432.             csEntry.LoadString(IDS_POPUP_RELOAD);
  433.             pMenu->AppendMenu(MF_STRING, ID_NAVIGATE_RELOAD, csEntry);
  434.         }
  435.  
  436.         if(!prefInfo.m_bAutoLoadImages)
  437.         {
  438.             csEntry.LoadString(IDS_POPUP_SHOWIMAGE);
  439.             pMenu->AppendMenu(MF_ENABLED, ID_POPUP_LOADIMAGEINLINE, csEntry);
  440.         }
  441.  
  442.         csEntry.LoadString(IDS_POPUP_STOP);
  443.         pMenu->AppendMenu(MF_STRING, ID_NAVIGATE_INTERRUPT, csEntry);
  444.  
  445. }
  446.  
  447. //
  448. // If the mouse is over a frame, add the appropriate items to the list
  449. //
  450. void CNetscapeView::AddViewItemsToPopup(CMenu * pMenu, MWContext *pContex, LO_Element * pElement)
  451. {
  452.     if(GetContext()->IsGridCell())
  453.     {
  454.         pMenu->AppendMenu(MF_SEPARATOR);
  455.         pMenu->AppendMenu(                
  456.             MF_ENABLED,
  457.             ID_VIEW_FRAME_SOURCE, szLoadString(IDS_VIEWFRAMESOURCE));
  458.         pMenu->AppendMenu(MF_ENABLED, ID_VIEW_FRAME_INFO, szLoadString(IDS_VIEWFRAMEINFO));
  459.  
  460.     }
  461.     else
  462.     {
  463.         pMenu->AppendMenu(MF_SEPARATOR);
  464.         pMenu->AppendMenu(                
  465.             MF_ENABLED,
  466.             ID_FILE_VIEWSOURCE, szLoadString(IDS_VIEWSOURCE));
  467.         pMenu->AppendMenu(MF_ENABLED, ID_FILE_DOCINFO, szLoadString(IDS_VIEWINFO));
  468.  
  469.     }
  470.     CString csURL, csEntry;
  471.  
  472.     // Make sure we have an image to begin with
  473.     csURL = m_csRBImage;
  474.     if(!csURL.IsEmpty())
  475.     {
  476.         MWContextType contentType = GetContext()->GetContext()->type;
  477.  
  478.         if (contentType != MWContextDialog) {
  479.  
  480.             // Allow them to view the image by itself in a separate window
  481.             csEntry.LoadString(IDS_POPUP_LOAD_IMAGE);
  482.             csEntry += ' ';
  483.     
  484.             // Tack the name of the URL on to the end, but shorten it to something
  485.             // reasonable first
  486.             LPSTR    lpszSuggested = 
  487. #ifdef MOZ_MAIL_NEWS         
  488.             MimeGuessURLContentName(GetContext()->GetContext(), csURL);
  489. #else
  490.             NULL;
  491. #endif /* MOZ_MAIL_NEWS */                       
  492.             if (lpszSuggested) {
  493.                 csEntry += "(";
  494.                 csEntry += lpszSuggested;
  495.                 csEntry += ")";
  496.                 XP_FREE(lpszSuggested);
  497.  
  498.             } else {
  499.                 WFE_CondenseURL(csURL, 25);
  500.                 csEntry += csURL;
  501.             }
  502.  
  503.             pMenu->AppendMenu(MF_ENABLED, ID_POPUP_LOADIMAGE, csEntry);
  504.         }
  505.     }
  506.     pMenu->AppendMenu(MF_SEPARATOR);
  507. }
  508.  
  509. //
  510. // Add the entries to create the right mouse menu over a web
  511. //   browser window
  512. //
  513. void CNetscapeView::CreateWebPopup(CMenu * pMenu, LO_Element * pElement, CL_Layer *layer)
  514. {
  515.     //    Start adding relevant items to the menu.
  516.     MWContext *pContext = GetContext()->GetContext();
  517.  
  518.     // If editor view-source window, don't show any popup menu.
  519.     if (pContext->edit_view_source_hack)
  520.         return;
  521.  
  522.     //  Don't do anything else if we're in kiosk mode.
  523.     if(!theApp.m_bKioskMode)    {
  524.         //
  525.         // If we are over a link add the appropriate elements
  526.         //    
  527.         if(AddLinkToPopup(pMenu, pElement, TRUE))
  528.             pMenu->AppendMenu(MF_SEPARATOR);
  529.  
  530.         AddNavigateItemsToPopup(pMenu, pElement, layer);
  531.  
  532.         AddViewItemsToPopup(pMenu, pContext, pElement);
  533.  
  534.         AddBrowserItemsToPopup(pMenu, pElement, layer);
  535.         
  536.         // Add save image and link items
  537.         AddSaveItemsToPopup(pMenu, pElement, layer, TRUE);
  538.  
  539.         //
  540.         // If we are over an embedded object add the appropriate elements
  541.         //    
  542.         AddEmbedToPopup(pMenu, pElement, layer, TRUE);
  543.  
  544.         // Allow the user to copy URLs to the clipboard if appropriate
  545.         AddClipboardToPopup(pMenu, pElement, TRUE);
  546.     }
  547. }
  548.  
  549. //
  550. // Add the entries to create the right mouse menu over a news message
  551. //
  552.  
  553. class CTestCmdUI: public CCmdUI {
  554. public:
  555.     BOOL m_bEnabled;
  556.  
  557.     CTestCmdUI() { m_bEnabled = FALSE; }
  558.     virtual void Enable(BOOL bOn = TRUE) { m_bEnabled = bOn; }
  559.     virtual void SetCheck(int nCheck = 1) {}
  560.     virtual void SetRadio(BOOL bOn = TRUE) {}
  561.     virtual void SetText(LPCSTR lpszText) {}
  562. };
  563.  
  564. void CNetscapeView::CreateMessagePopup(CMenu * pMenu, LO_Element * pElement, CL_Layer *layer)
  565. {
  566.     BOOL bAddSeparator = FALSE;
  567.     //
  568.     // If we are over a link add the appropriate elements to the list
  569.     //
  570.     bAddSeparator = AddLinkToPopup(pMenu, pElement, FALSE);
  571.  
  572.  
  573.     // Add Save Items 
  574.     bAddSeparator = AddSaveItemsToPopup(pMenu, pElement, layer, bAddSeparator);
  575.     //
  576.     // If we are over an embedded object add the appropriate elements to the list
  577.     //
  578.     bAddSeparator = AddEmbedToPopup(pMenu, pElement, layer, bAddSeparator);
  579.  
  580.     // Allow the user to copy URLs to the clipboard if appropriate
  581.     bAddSeparator = AddClipboardToPopup(pMenu, pElement, bAddSeparator);
  582.  
  583.     if(bAddSeparator)
  584.         pMenu->AppendMenu(MF_SEPARATOR);
  585.  
  586.     // Start adding relevant items to the menu.
  587.     // Test to see if "Post Reply" is enabled
  588.     // If so, we're in a news message
  589.  
  590.     CTestCmdUI cmdUI;
  591.     cmdUI.m_nID = ID_MESSAGE_POSTREPLY;
  592.     cmdUI.DoUpdate( GetParentFrame(), FALSE );
  593.     BOOL bNews = cmdUI.m_bEnabled;
  594.  
  595. #ifdef MOZ_MAIL_NEWS
  596.     WFE_MSGBuildMessagePopup( pMenu->m_hMenu, bNews );
  597. #endif /* MOZ_MAIL_NEWS */
  598. }
  599.  
  600. void CNetscapeView::OnRButtonDown(UINT uFlags, CPoint cpPoint)    {
  601. //    Purpose:    Bring up the popup menu.
  602. //    Arguments:    uFlags    What meta keys are currently pressed, ignored.
  603. //                cpPoint    The point at which the mouse was clicked in relative to the upper left corner of the window.
  604. //    Returns:    void
  605. //    Comments:    Saves the point in a class member, so other handling can occur through messages generated in the popup.
  606. //    Revision History:
  607. //        01-20-94    rewritten GAB
  608. //
  609.  
  610.     //    Call the base class to handle the click.
  611.     CGenericView::OnRButtonDown(uFlags, cpPoint);
  612.  
  613.     MWContext *pContext = GetContext()->GetContext();
  614.  
  615.     if (!pContext->compositor) 
  616.         OnRButtonDownForLayer(uFlags, cpPoint, 
  617.                   (long)cpPoint.x, (long)cpPoint.y,
  618.                   NULL);
  619. }
  620.  
  621. BOOL CNetscapeView::OnRButtonDownForLayer(UINT uFlags, CPoint& cpPoint, 
  622.                       long lX, long lY, CL_Layer *layer)    {
  623.     LO_Element *pElement;
  624.     HDC pDC = GetContextDC();
  625.     MWContext *pContext = GetContext()->GetContext();
  626.  
  627.     if(pDC) 
  628.       pElement = LO_XYToElement(ABSTRACTCX(pContext)->GetDocumentContext(), lX, lY, layer);
  629.     else
  630.       pElement = NULL;
  631.  
  632.     m_pLayer = layer;
  633.     
  634.     //    Save the point of the click.
  635.     m_ptRBDown = cpPoint;
  636.     m_csRBLink = GetAnchorHref(pElement);
  637.     m_csRBImage = GetImageHref(pElement);
  638.     m_csRBEmbed = GetEmbedHref(pElement);
  639.     m_pRBElement = pElement;
  640.     
  641.     //    Create the popup.
  642.     CMenu cmPopup;
  643.     if(cmPopup.CreatePopupMenu() == 0)    {
  644.         return FALSE;
  645.     }
  646.     
  647.     switch(GetContext()->GetContext()->type) {
  648.     case MWContextMailMsg:
  649.     case MWContextMail:
  650.     // These two shouldn't occur
  651.     case MWContextNewsMsg:
  652.     case MWContextNews:
  653.         CreateMessagePopup(&cmPopup, pElement, layer);
  654.         break;
  655.     default:
  656.         // just fall through and show the browser popup even though it
  657.         //  will probably be useless
  658.     case MWContextBrowser:
  659.         CreateWebPopup(&cmPopup, pElement, layer);
  660.         break;
  661.     }
  662.     
  663.     //    Track the popup now.
  664.     ClientToScreen(&cpPoint);
  665.  
  666.     //  Certain types of contexts should not do this.
  667.     if(
  668.         GetFrame() &&
  669.         GetFrame()->GetMainContext() &&
  670.         GetFrame()->GetMainContext()->GetContext()->type != MWContextDialog) {
  671.         cmPopup.TrackPopupMenu(TPM_LEFTALIGN | TPM_RIGHTBUTTON, cpPoint.x, cpPoint.y, 
  672.                                GetParentFrame(), NULL);
  673.     }
  674.  
  675.     return TRUE;
  676. }
  677.  
  678. void CNetscapeView::GetLogicalPoint(CPoint cpPoint, long *pLX, long *pLY)
  679. {
  680.     //    Get the device context, and figure out the logical point.
  681.     HDC pDC = GetContextDC();
  682.     if(pDC)    {
  683.     CPoint cpLogical = cpPoint;
  684.     ::DPtoLP(pDC, &cpLogical, 1);
  685.     
  686.     //    Adjust the point further in context.
  687.     //    Go to longs, as ints will wrap since we're in twips.
  688.     MWContext *pContext = GetContext()->GetContext();
  689.     *pLX = (long)cpLogical.x + (long)WINCX(pContext)->GetOriginX();
  690.     *pLY = (long)cpLogical.y + (long)WINCX(pContext)->GetOriginY();
  691.     }
  692.     else {
  693.     *pLX = (long)cpPoint.x;
  694.     *pLY = (long)cpPoint.y;
  695.     }
  696. }
  697.  
  698. LO_Element *CNetscapeView::GetLayoutElement(CPoint cpPoint, CL_Layer *layer)    {
  699. //    Purpose:    Return the layout element under the device point.
  700. //    Arguments:    cpPoint The device point.
  701. //    Returns:    LO_Element *    The layout element under the point, or NULL if over nothing.
  702. //    Comments:    General utility function.
  703. //    Revision History:
  704. //        01-20-95    created GAB
  705. //
  706.  
  707.     //    Get the device context, and figure out the logical point.
  708.     HDC pDC = GetContextDC();
  709.     if(pDC)    {
  710.     long lX, lY;
  711.     MWContext *pContext = GetContext()->GetContext();
  712.  
  713.     XP_Rect bbox;
  714.  
  715.     GetLogicalPoint(cpPoint, &lX, &lY);
  716.     CL_GetLayerBbox(layer, &bbox);
  717.  
  718.     lX -= bbox.left;
  719.     lY -= bbox.top;
  720.  
  721.     //    Return the element that layout reports at this coordinate.
  722.         return(LO_XYToElement(ABSTRACTCX(pContext)->GetDocumentContext(), lX, lY, layer));
  723.     }
  724.     else    {
  725.         return(NULL);
  726.     }
  727. }
  728.  
  729. CString CNetscapeView::GetAnchorHref(LO_Element *pElement)    {
  730. //    Purpose:    Obtain the HREF to a layout element.
  731. //    Arguments:    pElement    The abstract layout element, can be NULL.
  732. //    Returns:    CString    The anchor, in full.
  733. //    Comments:    Should handle other anchor cases as they become evident.
  734. //    Revision History:
  735. //        01-20-95    created
  736. //
  737.  
  738.     CString csRetval;
  739.     
  740.     if(pElement != NULL)    {
  741.         switch(pElement->type)    {
  742.             case LO_TEXT:    {
  743.                 LO_TextStruct *pText = (LO_TextStruct *)pElement;
  744.                 if(pText->anchor_href && pText->anchor_href->anchor)    {
  745.                     csRetval = (char *)pText->anchor_href->anchor;
  746.                 }
  747.                 break;
  748.             }
  749.             case LO_IMAGE:    {
  750.                 LO_ImageStruct *pImage = (LO_ImageStruct *)pElement;
  751.                 if(pImage->image_attr->usemap_name != NULL)    {
  752.                     CPoint cpUsemap = m_ptRBDown;
  753.                     MWContext *pContext = GetContext()->GetContext();
  754.                     HDC pDC = GetContextDC();
  755.                     ::DPtoLP(pDC, &cpUsemap, 1);
  756.                     cpUsemap.x -= (int)(pImage->x + pImage->x_offset + pImage->border_width - WINCX(pContext)->GetOriginX());
  757.                     cpUsemap.y -= (int)(pImage->y + pImage->y_offset + pImage->border_width - WINCX(pContext)->GetOriginY());
  758.                     ::LPtoDP(pDC, &cpUsemap, 1);
  759.  
  760.                     LO_AnchorData *pAnchorData = LO_MapXYToAreaAnchor(ABSTRACTCX(pContext)->GetDocumentContext(),
  761.                         pImage, cpUsemap.x, cpUsemap.y);
  762.  
  763.                     if(pAnchorData != NULL && pAnchorData->anchor != NULL)    {
  764.                         csRetval = (char *)pAnchorData->anchor;
  765.                     }
  766.                 }
  767.                 else if(pImage->anchor_href && pImage->anchor_href->anchor)    {
  768.                     csRetval = (char *)pImage->anchor_href->anchor;
  769.                 
  770.                     //    Handle ismaps
  771.                     if(pImage->image_attr->attrmask & LO_ATTR_ISMAP)    {
  772.                         MWContext *pContext = GetContext()->GetContext();
  773.                         CPoint cpIsmap = m_ptRBDown;
  774.                         HDC pDC = GetContextDC();
  775.                         char aNumBuf[16];
  776.                     
  777.                         ::DPtoLP(pDC, &cpIsmap, 1);
  778.                         cpIsmap.x -= (int)(pImage->x + pImage->x_offset + pImage->border_width - WINCX(pContext)->GetOriginX());
  779.                         cpIsmap.y -= (int)(pImage->y + pImage->y_offset + pImage->border_width - WINCX(pContext)->GetOriginY());
  780.                         ::LPtoDP(pDC, &cpIsmap, 1);
  781.                     
  782.                         csRetval += '?';
  783.                         _itoa(cpIsmap.x, aNumBuf, 10);
  784.                         csRetval += aNumBuf;
  785.                         csRetval += ',';
  786.                         _itoa(cpIsmap.y, aNumBuf, 10);
  787.                         csRetval += aNumBuf;
  788.                     }
  789.                 }
  790.                 break;
  791.             }
  792.         }
  793.     }
  794.     
  795.     return(csRetval);
  796. }
  797.  
  798. CString CNetscapeView::GetImageHref(LO_Element *pElement)    {
  799. //    Purpose:    Obtain the HREF to a layout element.
  800. //    Arguments:    pElement    The abstract layout element, can be NULL.
  801. //    Returns:    CString    The image anchor, in full.
  802. //    Comments:
  803. //    Revision History:
  804. //        01-20-95    created
  805. //
  806.  
  807.     CString csRetval;
  808.     
  809.     if(pElement != NULL)    {
  810.         switch(pElement->type)    {
  811.             case LO_IMAGE:    {
  812.                 LO_ImageStruct *pImage = (LO_ImageStruct *)pElement;
  813.                 if(pImage->image_url != NULL)    {
  814.                     //    Check for that funky internal-external-reconnect jazz.
  815.                     char *Weird = "internal-external-reconnect:";
  816.                     int iWeirdLen = strlen(Weird);
  817.                     if(strncmp((char *)pImage->image_url, Weird, iWeirdLen) == 0)    {
  818.                         // Use everything after "internal-external-reconnect:"
  819.                         csRetval = ((char *) pImage->image_url) + iWeirdLen;
  820.                     }
  821.                     else    {
  822.                         csRetval = (char *)pImage->image_url;
  823.                     }
  824.                 }
  825.                 break;
  826.             }
  827.         }
  828.     }
  829.     
  830.     return(csRetval);
  831. }
  832.  
  833. CString CNetscapeView::GetEmbedHref(LO_Element *pElement)    {
  834. //    Purpose:    Obtain the HREF to a layout element.
  835. //    Arguments:    pElement    The abstract layout element, can be NULL.
  836. //    Returns:    CString    The embed anchor, in full.
  837. //    Comments:
  838. //    Revision History:
  839. //        03-05-95    created
  840. //
  841.  
  842.     CString csRetval;
  843.     
  844.     if(pElement != NULL)    {
  845.         switch(pElement->type)    {
  846.             case LO_EMBED:    {
  847.                 LO_EmbedStruct *pEmbed = (LO_EmbedStruct *)pElement;
  848.                 if(pEmbed->embed_src != NULL)    {
  849.                     csRetval = (char *)pEmbed->embed_src;
  850.                 }
  851.                 break;
  852.             }
  853.         }
  854.     }
  855.     
  856.     return(csRetval);
  857. }
  858.  
  859. void WFE_CondenseURL(CString& csURL, UINT uLength, BOOL bParens)    {
  860. //    Purpose:    Condense a URL to a given length.
  861. //    Arguments:    csURL    The URL to condense.
  862. //                uLength    The maximum length.
  863. //                bParens    Wether or not use parenthesis to surround the condesed form.
  864. //                        Also specifies wether or not we need to only extract the file name.
  865. //    Returns:    void
  866. //    Comments:
  867. //    Revision History:
  868. //        01-20-95    created GAB
  869. //        01-28-95    Modified to only take the filename off, previously left protocol and right of the URL.
  870. //        09-24-95    Well, now we're going back to cutting out the middle....
  871. //                    Parens code will only get the filename ending.
  872. //
  873.  
  874.     char *pSlash;
  875.     if(bParens == FALSE)    {
  876.         pSlash = (char *)(const char *)csURL;
  877.     }
  878.     else    {
  879.         //    Make it two shorter right now for the ().
  880.         uLength -= 2;
  881.  
  882.         //    Find out if we have a forward slash in the URL, backwards.
  883.         pSlash = strrchr(csURL, '/');
  884.         if(pSlash != NULL)    {
  885.             //    Make sure that this isn't just one character long (directory).
  886.             if(strlen(pSlash) == 1)    {
  887.                 //    this is a directory, attempt to use the whole URL, I guess.
  888.                 pSlash = (char *)(const char *)csURL;
  889.             }
  890.         }
  891.  
  892.         if(pSlash == NULL)    {
  893.             //    If there's no slash, attempt a : from the start (don't want to only show a port #!)
  894.             pSlash = strchr(csURL, ':');
  895.         }
  896.  
  897.         if(pSlash != NULL)    {
  898.             //    Go one past what we've found, only if we're not at the start of the URL.
  899.             if(pSlash != (char *)(const char *)csURL)    {
  900.                 pSlash++;
  901.             }
  902.         }
  903.         else    {
  904.             pSlash = (char *)(const char *)csURL;
  905.         }
  906.     }
  907.  
  908.     //    See if what we've found is longer than what we need.
  909.     if(strlen(pSlash) <= uLength)    {
  910.         //    No need to modify, just return what we have.
  911.         CString csTemp;
  912.         if(bParens == TRUE)    {
  913.             csTemp += "(";
  914.         }
  915.         csTemp += pSlash;
  916.         if(bParens == TRUE)    {
  917.             csTemp += ")";
  918.         }
  919.         csURL = csTemp;
  920.         return;
  921.     }
  922.  
  923.     // Currently, we cannot do multilingual Menu, so use just treat all the menu
  924.     // is in the resource csid.
  925.     int16 guicsid = INTL_CharSetNameToID(INTL_ResourceCharSet());
  926.     char truncated[120];
  927.     if(uLength > 120)
  928.         uLength = 120;
  929.  
  930.     INTL_MidTruncateString(guicsid, pSlash, truncated, uLength);
  931.     
  932.     if(bParens)    
  933.     {
  934.         csURL = "(";
  935.         csURL += truncated;
  936.         csURL += ")";
  937.     }
  938.     else
  939.     {
  940.         csURL = truncated;
  941.     }
  942.     
  943. }
  944.  
  945. void CNetscapeView::OnPopupLoadLink()    {
  946. //    Purpose:    Load the link
  947. //    Arguments:    void
  948. //    Returns:    void
  949. //    Comments:    Never get's called unless actually over a link.
  950. //    Revision History:
  951. //        01-21-95    created GAB
  952. //        01-24-95    modified to not query layout again for the element, in case a load occured in between.
  953. //      13-Feb-95   modified to just call builtin load function - chouck
  954. //
  955.     MWContext * context = GetContext()->GetContext();
  956.     History_entry *he = SHIST_GetCurrent (&context->hist);
  957.     m_pContext->NormalGetUrl(m_csRBLink, (he ? he->address : NULL));
  958. }
  959.  
  960. void CNetscapeView::OnPopupLoadLinkNewWindow()    {
  961. //    Purpose:    Load a link into a new window.
  962. //    Arguments:    void
  963. //    Returns:    void
  964. //    Comments:    Never gets called, unless actually over an image.
  965. //                Need to handle image maps also.
  966. //    Revision History:
  967. //        01-21-95    created GAB
  968. //        01-24-95    modified to not query layout again for the element, in case a load occured in between.
  969. //      05-Jun-95   send the referred field too - chouck
  970. //
  971.     MWContext * context = GetContext()->GetContext();
  972.     History_entry *he = SHIST_GetCurrent(&context->hist);
  973.  
  974.     //    Create the URL to load, assign a referrer field.
  975.     URL_Struct *pUrl = NET_CreateURLStruct(m_csRBLink, NET_DONT_RELOAD);
  976.     if(he->address != NULL)    {
  977.         pUrl->referer = XP_STRDUP(he->address);
  978.     }
  979.  
  980.     //    Always set the window_target for a new window.
  981.     pUrl->window_target = XP_STRDUP("");
  982.  
  983. #ifdef EDITOR
  984.     // Question: Does it matter if referer and window_target are set
  985.     //           if we are creating a new context?
  986.     if ( EDT_IS_EDITOR(context) ) {
  987.         if ( pUrl ) {
  988.             // Must clear this to correctly load URL into new context
  989.             pUrl->fe_data = NULL;
  990.             // Create new Context
  991.             CFE_CreateNewDocWindow(NULL, pUrl);
  992.         }
  993.     } else
  994. #endif
  995.     CFE_CreateNewDocWindow(GetContext()->GetContext(), pUrl);
  996. }
  997.  
  998. void CNetscapeView::OnPopupLoadFrameNewWindow()
  999. {
  1000.     MWContext *context = GetContext()->GetContext();
  1001.  
  1002.     History_entry *he = SHIST_GetCurrent(&context->hist);
  1003.  
  1004.     URL_Struct *pUrl;
  1005.     //    Create the URL to load, assign a referrer field.
  1006.     if(he->address != NULL)
  1007.     {
  1008.         pUrl = NET_CreateURLStruct(he->address, NET_NORMAL_RELOAD);
  1009.     }
  1010.  
  1011.     //    Always set the window_target for a new window.
  1012.     pUrl->window_target = XP_STRDUP("");
  1013.  
  1014. #ifdef EDITOR
  1015.     // Question: Does it matter if referer and window_target are set
  1016.     //           if we are creating a new context?
  1017.     if ( EDT_IS_EDITOR(context) ) {
  1018.         if ( pUrl ) {
  1019.             // Must clear this to correctly load URL into new context
  1020.             pUrl->fe_data = NULL;
  1021.             // Create new Context
  1022.             CFE_CreateNewDocWindow(NULL, pUrl);
  1023.         }
  1024.     } else
  1025. #endif
  1026.     if(pUrl)
  1027.         CFE_CreateNewDocWindow(GetContext()->GetContext(), pUrl);
  1028.  
  1029. }
  1030.  
  1031. #ifdef EDITOR
  1032. // Load link location in a Composer window
  1033. void CNetscapeView::OnPopupLoadLinkInEditor()
  1034. {
  1035.     if ( GetContext()->GetContext() && !m_csRBLink.IsEmpty() ) {
  1036.         FE_LoadUrl((char*)LPCSTR(m_csRBLink), LOAD_URL_COMPOSER);
  1037.     }
  1038. }
  1039.  
  1040. // Load image in user-specified editor
  1041. void CNetscapeView::OnPopupEditImage()
  1042. {
  1043.     if ( GetContext()->GetContext() && !m_csRBImage.IsEmpty() ) {
  1044.         EditImage((char*)LPCSTR(m_csRBImage));
  1045.     }
  1046. }
  1047. #endif
  1048.  
  1049. void CNetscapeView::OnPopupSaveLinkContentsAs()    {
  1050. //    Purpose:    Save a link.
  1051. //    Arguments:    void
  1052. //    Returns:    void
  1053. //    Comments:
  1054. //    Revision History:
  1055. //        01-22-95    created GAB
  1056. //        01-24-95    modified to not query layout again for the element, in case a load occured in between.
  1057. //
  1058.  
  1059.     CSaveCX::SaveAnchorObject(m_csRBLink, NULL);
  1060. }
  1061.  
  1062. void CNetscapeView::OnPopupCopyLinkToClipboard()    {
  1063. //    Purpose:    Copy a link to the clipboard.
  1064. //    Arguments:    void
  1065. //    Returns:    void
  1066. //    Comments:    Don't free the handle.
  1067. //    Revision History:
  1068. //        01-22-95    created GAB
  1069. //        01-24-95    modified to not query layout again for the element, in case a load occured in between.
  1070. //
  1071.  
  1072.     CopyLinkToClipboard(m_hWnd, m_csRBLink);
  1073. }
  1074.  
  1075. void CNetscapeView::CopyLinkToClipboard(HWND hWnd, CString url)
  1076. {
  1077.     CString csHref = url;
  1078.     HANDLE hData = GlobalAlloc(GMEM_MOVEABLE, csHref.GetLength() + 1);
  1079.     char *pCopy = (char *)GlobalLock(hData);    
  1080.     strcpy(pCopy, csHref);
  1081.     GlobalUnlock(hData);
  1082.  
  1083.     // Also copy bookmark-formatted data so we can paste full link,
  1084.     //  not just text, into the Editor or bookmark window
  1085.     ::OpenClipboard(hWnd);
  1086.     ::EmptyClipboard();
  1087.     ::SetClipboardData(CF_TEXT, hData);
  1088.  
  1089.     hData = GlobalAlloc(GMEM_DDESHARE | GMEM_ZEROINIT, sizeof(BOOKMARKITEM));
  1090.     if(hData){
  1091.         LPBOOKMARKITEM pBookmark = (LPBOOKMARKITEM)GlobalLock(hData);
  1092.         PR_snprintf(pBookmark->szAnchor, sizeof(pBookmark->szAnchor), "%s",
  1093.                     LPCSTR(csHref));
  1094.         PR_snprintf(pBookmark->szText, sizeof(pBookmark->szText), "%s",
  1095.                     LPCSTR(csHref));
  1096.         GlobalUnlock(hData);
  1097.         ::SetClipboardData(RegisterClipboardFormat(NETSCAPE_BOOKMARK_FORMAT), hData);
  1098.     }
  1099.     ::CloseClipboard();
  1100. }
  1101.  
  1102. void CNetscapeView::OnPopupLoadImage()    {
  1103. //    Purpose:    Load an image inline that was delayed.
  1104. //    Arguments:    void
  1105. //    Returns:    void
  1106. //    Comments:
  1107. //    Revision History:
  1108. //        01-22-95    created GAB
  1109. //      13-Feb-95   modified to just call builtin load function - chouck
  1110.  
  1111.     if(GetContext())    {
  1112.         MWContext * context = GetContext()->GetContext();
  1113.         History_entry *he = SHIST_GetCurrent (&context->hist);
  1114.  
  1115.         //    Go up to the parent context.
  1116.         CAbstractCX *pCX = ABSTRACTCX(context);
  1117.         while(pCX && pCX->IsGridCell())    {
  1118.             pCX = ABSTRACTCX(pCX->GetParentContext());
  1119.         }
  1120.  
  1121.         if(pCX && pCX->IsFrameContext())    {
  1122.             pCX->NormalGetUrl(m_csRBImage, (he ? he->address : NULL));
  1123.         }
  1124.     }
  1125. }
  1126.  
  1127. void CNetscapeView::OnPopupLoadImageInline()    {
  1128. //    Purpose:    Load an image inline that was delayed.
  1129. //    Arguments:    void
  1130. //    Returns:    void
  1131. //    Comments:
  1132. //    Revision History:
  1133. //        01-22-95    created GAB
  1134. //        01-24-95    modified to not query layout again for the element, in case a load occured in between.
  1135. //
  1136.     const char *pURL = m_csRBImage;
  1137.     
  1138.     // Tell layout which image is to be force loaded.
  1139.     LO_SetForceLoadImage((char*)pURL, FALSE);
  1140.  
  1141.     m_pContext->ExplicitlyLoadThisImage(m_csRBImage);
  1142. }
  1143.  
  1144. void CNetscapeView::OnPopupSaveImageAs()    {
  1145. //    Purpose:    Save the image we're over to a file.
  1146. //    Arguments:    void
  1147. //    Returns:    void
  1148. //    Comments:
  1149. //    Revision History:
  1150. //        01-22-94    created GAB
  1151. //        01-24-95    modified to not query layout again for the element, in case a load occured in between.
  1152. //
  1153.  
  1154.     CSaveCX::SaveAnchorObject(m_csRBImage, NULL);
  1155. }
  1156.  
  1157. void CNetscapeView::OnPopupSetAsWallpaper()
  1158. {
  1159.     ASSERT(m_pRBElement && m_pRBElement->type == LO_IMAGE);
  1160.     if (m_pRBElement->type == LO_IMAGE) {
  1161.         char    szFileName[_MAX_PATH + 25];
  1162.  
  1163.         // We need to create a .BMP file in the Windows directory
  1164.         GetWindowsDirectory(szFileName, sizeof(szFileName));
  1165. #ifdef XP_WIN32
  1166.         strcat(szFileName, "\\Netscape Wallpaper.bmp");
  1167. #else
  1168.         strcat(szFileName, "\\Netscape.bmp");
  1169. #endif
  1170.  
  1171.         // Go ahead and write out the file
  1172.         if (GetContext()->WriteBitmapFile(szFileName, &m_pRBElement->lo_image)) {
  1173.             // Now ask Windows to change the wallpaper
  1174.             SystemParametersInfo(SPI_SETDESKWALLPAPER, 0, szFileName, SPIF_UPDATEINIFILE);
  1175.         }
  1176.         
  1177.     }
  1178. }
  1179.  
  1180. void CNetscapeView::OnPopupCopyImageLocationToClipboard()    {
  1181. //    Purpose:    Copy the image's URL to the clipboard.
  1182. //    Arguments:    void
  1183. //    Returns:    void
  1184. //    Comments:    Don't free the handle.
  1185. //    Revision History:
  1186. //        01-22-95    created GAB
  1187. //        01-24-95    modified to not query layout again for the element, in case a load occured in between.
  1188. //
  1189.  
  1190.     CString csHref = m_csRBImage;
  1191.     HANDLE hData = GlobalAlloc(GMEM_MOVEABLE, csHref.GetLength() + 1);
  1192.     char *pCopy = (char *)GlobalLock(hData);    
  1193.     strcpy(pCopy, csHref);
  1194.     GlobalUnlock(hData);
  1195. #ifdef EDITOR
  1196.     // Also copy all data for pasting into Editor - just like drag and drop
  1197.     HGLOBAL hImageData = NULL;
  1198.     if ( GetContext() ) {
  1199.         hImageData = WFE_CreateCopyImageData(GetContext()->GetContext(),
  1200.                                             GetContext()->m_pLastImageObject);
  1201.     }
  1202.     GetContext()->m_pLastImageObject = NULL;
  1203. #endif    
  1204.  
  1205.     OpenClipboard();
  1206.     ::EmptyClipboard();
  1207.     ::SetClipboardData(CF_TEXT, hData);
  1208. #ifdef EDITOR
  1209.     if (hImageData ) {
  1210.         ::SetClipboardData(RegisterClipboardFormat(NETSCAPE_IMAGE_FORMAT), hImageData);
  1211.     }
  1212. #endif
  1213.     ::CloseClipboard();
  1214. }
  1215.  
  1216. void CNetscapeView::OnPopupActivateEmbed()    {
  1217. //    Purpose:    Activate an embedded item.
  1218. //    Arguments:    void
  1219. //    Returns:    void
  1220. //    Comments:   Just about the same code as OnLButtonDblClk
  1221. //    Revision History:
  1222. //      03-06-95    created GAB
  1223.  
  1224.     CPoint cpPoint = m_ptRBDown;
  1225.  
  1226.     //  See if we are already selected in this area.
  1227.     //  If not, then we need to deselect any currently selected item.
  1228.     CWinCX *pWinCX = GetContext();
  1229.     if(pWinCX && pWinCX->m_pSelected)   {
  1230.         //  Figure out the rect that the item covers.
  1231.         long lLeft = pWinCX->m_pSelected->x + pWinCX->m_pSelected->y_offset - pWinCX->GetOriginX();
  1232.         long lRight = lLeft + pWinCX->m_pSelected->width;
  1233.  
  1234.         long lTop = pWinCX->m_pSelected->y + pWinCX->m_pSelected->y_offset - pWinCX->GetOriginY();
  1235.         long lBottom = lTop + pWinCX->m_pSelected->height;
  1236.  
  1237.         HDC pDC = pWinCX->GetContextDC();
  1238.         RECT crBounds;
  1239.         ::SetRect(&crBounds, CASTINT(lLeft), CASTINT(lRight), CASTINT(lTop), CASTINT(lBottom));
  1240.         ::LPtoDP(pDC, (POINT*)&crBounds, 2);
  1241.  
  1242.         if(FALSE == ::PtInRect(&crBounds, cpPoint))  {
  1243.             OnDeactivateEmbed();
  1244.         }
  1245.         else    {
  1246.             //  Same item.  Don't do anything.
  1247.             return;
  1248.         }
  1249.     }
  1250.  
  1251.     if(m_pRBElement != NULL)    {
  1252.         if(m_pRBElement->type == LO_EMBED)  {
  1253.             LO_EmbedStruct *pLayoutData = (LO_EmbedStruct *)m_pRBElement;
  1254.             NPEmbeddedApp *pPluginShim = (NPEmbeddedApp *)pLayoutData->FE_Data;
  1255.             if(pPluginShim != NULL && wfe_IsTypePlugin(pPluginShim) == FALSE)    {
  1256.                 CNetscapeCntrItem *pItem = (CNetscapeCntrItem *)pPluginShim->fe_data;
  1257.  
  1258.                 //  Make sure we can load this.
  1259.                 if(pItem->m_bBroken == FALSE && pItem->m_bDelayed == FALSE && pItem->m_bLoading == FALSE)  {
  1260.                     //  We have an active selection.
  1261.                     pWinCX->m_pSelected = pLayoutData;
  1262.  
  1263.                     long lVerb = OLEIVERB_PRIMARY;
  1264.                     BeginWaitCursor();
  1265.                     pItem->Activate(lVerb, this);
  1266.                     EndWaitCursor();
  1267.  
  1268.                     //  If it's not in place active, then we don't care about it, as it's UI is being
  1269.                     //      handled elsewhere.
  1270.                     if(pItem->IsInPlaceActive() == FALSE)   {
  1271.                         pWinCX->m_pSelected = NULL;
  1272.                     }
  1273.                 }
  1274.             }
  1275.         }
  1276.     }
  1277. }
  1278.  
  1279. void CNetscapeView::OnPopupSaveEmbedAs()    {
  1280. //    Purpose:    Save the embed we're over to a file.
  1281. //    Arguments:    void
  1282. //    Returns:    void
  1283. //    Comments:
  1284. //    Revision History:
  1285. //        01-22-94    created GAB
  1286. //        01-24-95    modified to not query layout again for the element, in case a load occured in between.
  1287. //      02-06-95    modified to handle embeds.
  1288. //
  1289.     CSaveCX::SaveAnchorObject(m_csRBEmbed, NULL);
  1290. }
  1291.  
  1292. void CNetscapeView::OnPopupCopyEmbedLocationToClipboard()    {
  1293. //    Purpose:    Copy the embed's URL to the clipboard.
  1294. //    Arguments:    void
  1295. //    Returns:    void
  1296. //    Comments:    Don't free the handle.
  1297. //    Revision History:
  1298. //        01-22-95    created GAB
  1299. //        01-24-95    modified to not query layout again for the element, in case a load occured in between.
  1300. //      02-06-95    modified to handle embeds
  1301. //
  1302.  
  1303.     CString csHref = m_csRBEmbed;
  1304.     HANDLE hData = GlobalAlloc(GMEM_MOVEABLE, csHref.GetLength() + 1);
  1305.     char *pCopy = (char *)GlobalLock(hData);    
  1306.     strcpy(pCopy, csHref);
  1307.     GlobalUnlock(hData);
  1308.     
  1309.     OpenClipboard();
  1310.     ::EmptyClipboard();
  1311.     ::SetClipboardData(CF_TEXT, hData);
  1312.     ::CloseClipboard();
  1313. }
  1314.  
  1315. void CNetscapeView::OnPopupCopyEmbedToClipboard()   {
  1316. //    Purpose:    Copy the embed's data to the clipboard.
  1317. //    Arguments:    void
  1318. //    Returns:    void
  1319. //    Comments:
  1320. //    Revision History:
  1321. //      02-06-95    modified to handle embeds, created GAB
  1322. //
  1323.  
  1324.     if(m_pRBElement != NULL)    {
  1325.         if(m_pRBElement->type == LO_EMBED)  {
  1326.             LO_EmbedStruct *pLayoutData = (LO_EmbedStruct *)m_pRBElement;
  1327.             NPEmbeddedApp *pPluginShim = (NPEmbeddedApp *)pLayoutData->FE_Data;
  1328.             if(pPluginShim != NULL && wfe_IsTypePlugin(pPluginShim) == FALSE)    {
  1329.                 CNetscapeCntrItem *pItem = (CNetscapeCntrItem *)pPluginShim->fe_data;
  1330.  
  1331.                 //  Make sure we can copy this.
  1332.                 if(pItem->m_bBroken == FALSE && pItem->m_bDelayed == FALSE && pItem->m_bLoading == FALSE)  {
  1333.                     //  Do it.
  1334.                     pItem->CopyToClipboard(FALSE);
  1335.                 }
  1336.             }
  1337.         }
  1338.     }
  1339. }
  1340.  
  1341. void CNetscapeView::CreateTextAndAnchor(CString &csText, CString &csAnchor)
  1342. {
  1343. // Purpose: Merge common code from OnPopupAddLinkToBookmarks and OnPopupInternetShortCut
  1344. //
  1345. //
  1346. //    Revision History:
  1347. //        02-11-96    created
  1348. //        01-24-95    modified to not query layout again for the element, in case a load occured in between.
  1349. //
  1350.  
  1351.     // See if we are over some text that is a link
  1352.     LO_TextStruct * text_struct = (LO_TextStruct *) m_pRBElement;
  1353.     LO_ImageStruct * image_struct = (LO_ImageStruct *) m_pRBElement;
  1354.  
  1355.     CString csAppend = m_csRBLink;
  1356.  
  1357.     if(text_struct && text_struct->type == LO_TEXT && text_struct->anchor_href) 
  1358.     {
  1359.         csText = (char *)text_struct->text;        
  1360.         csAnchor = m_csRBLink;
  1361.     } 
  1362.     else if(image_struct && image_struct->type == LO_IMAGE && image_struct->anchor_href) 
  1363.     {
  1364.         WFE_CondenseURL(csAppend,25);
  1365.         csText = csAppend;
  1366.         csAnchor = m_csRBLink;
  1367.     }
  1368.     else
  1369.     {
  1370.         MWContext *context = GetContext()->GetContext();
  1371.  
  1372.         History_entry *h = SHIST_GetCurrent (&context->hist);
  1373.         URL_Struct *url = SHIST_CreateURLStructFromHistoryEntry (context, h);
  1374.         
  1375.         if ((h != NULL) && (url != NULL))
  1376.         {
  1377.             csText = h->title;
  1378.             csAnchor = url->address;
  1379.         }  /* end if */
  1380.     }
  1381.  
  1382.     if (!csText.GetLength() )
  1383.     {
  1384.         csText = csAnchor;
  1385.         WFE_CondenseURL(csText,25);
  1386.     }
  1387. }
  1388.  
  1389. void CNetscapeView::OnPopupAddLinkToBookmarks()    
  1390. {
  1391. //    Purpose:    Add the link we're under to the bookmarks.
  1392. //    Arguments:    void
  1393. //    Returns:    void
  1394. //    Comments:    Never gets called, unless actually over a link.
  1395. //              The bookmark is not going in the correct place
  1396. //    Revision History:
  1397. //        01-21-95    created
  1398. //        01-24-95    modified to not query layout again for the element, in case a load occured in between.
  1399. //
  1400.     CString csText, csAnchor;
  1401.     CreateTextAndAnchor(csText, csAnchor);
  1402.  
  1403.     if (csAnchor.GetLength()) {
  1404.         HT_AddBookmark((char*)(const char*)csAnchor, (char*)(const char*)csText);
  1405.     }
  1406. }
  1407.  
  1408. void CNetscapeView::OnPopupInternetShortcut() {
  1409.     CString csText, csAnchor;
  1410.     CreateTextAndAnchor(csText, csAnchor);
  1411.  
  1412.        if (csAnchor.GetLength()) {
  1413.         const char * szText = (const char *) csText;
  1414.         const char * szAnchor = (const char *) csAnchor;
  1415.         CShortcutDialog ShortcutDialog ( this, (char *)szText, (char *)szAnchor );
  1416.         if ( ShortcutDialog.DoModal ( ) == IDOK )
  1417.         {
  1418.             CInternetShortcut InternetShortcut ( 
  1419.                 ShortcutDialog.GetDescription ( ), 
  1420.                 (char *)szAnchor );
  1421.         }    
  1422.     }
  1423. }
  1424.  
  1425. void CNetscapeView::OnPopupMailTo() {
  1426.     // Pass this off to the context for handling.
  1427.     if(GetContext())        {
  1428.         GetContext()->MailDocument();
  1429.     }
  1430. }
  1431.