home *** CD-ROM | disk | FTP | other *** search
/ Tools / WinSN5.0Ver.iso / NETSCAP.50 / WIN1998.ZIP / ns / cmd / xfe / src / TaskBarDrop.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1998-04-08  |  6.9 KB  |  257 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.    TaskBarDrop.cpp -- class definition for the task bar drop class
  20.    Created: Alastair Gourlay <sgidev@netscape.com>, 1-Jan-96.
  21.  */
  22.  
  23.  
  24.  
  25. #include "TaskBarDrop.h"
  26. #include "Command.h"
  27. #include "BrowserFrame.h"
  28. #ifdef MOZ_MAIL_NEWS
  29. #include "ComposeFrame.h"
  30. #include "ComposeAttachFolderView.h"
  31. #endif
  32. #ifdef EDITOR
  33. #include "EditorFrame.h"
  34. #endif
  35. #include <Xfe/Xfe.h>
  36. #include "xfe2_extern.h"
  37.  
  38. #ifdef DEBUG_sgidev
  39. #define XDEBUG(x) x
  40. #else
  41. #define XDEBUG(x)
  42. #endif
  43.  
  44. //
  45. // XFE_TaskBarDrop class
  46. //
  47.  
  48. // constructor
  49.  
  50. XFE_TaskBarDrop::XFE_TaskBarDrop(Widget parent,const char *command)
  51.     : XFE_DropNetscape(parent)
  52. {
  53.     _command=command;
  54.  
  55.     // Configure the drop site
  56.     Arg            xargs[1];
  57.     Cardinal    n = 0;
  58.     
  59.     XtSetArg(xargs[n],XmNanimationStyle,    XmDRAG_UNDER_NONE);        n++;
  60.     
  61.     update(xargs,n);
  62. }
  63.  
  64. XFE_TaskBarDrop::~XFE_TaskBarDrop()
  65. {
  66. }
  67.  
  68. void XFE_TaskBarDrop::targets()
  69. {
  70.     _numTargets=2;
  71.     _targets=new Atom[_numTargets];
  72.  
  73.     _targets[0]=_XA_NETSCAPE_URL;
  74.     _targets[1]=XA_STRING;
  75.  
  76.     acceptFileTargets();
  77. }
  78.  
  79. void XFE_TaskBarDrop::operations()
  80. {
  81.     // always copy - move/link irrelevant
  82.     _operations=(unsigned int)XmDROP_COPY;
  83. }
  84.  
  85. /* virtual */ void
  86. XFE_TaskBarDrop::dragIn()
  87. {
  88.     XtVaSetValues(_widget,XmNraised,True,NULL);
  89. }
  90.  
  91. /* virtual */ void
  92. XFE_TaskBarDrop::dragOut()
  93. {
  94.     XtVaSetValues(_widget,XmNraised,False,NULL);
  95. }
  96.  
  97.  
  98. int XFE_TaskBarDrop::processTargets(Atom *targets,const char **data,int numItems)
  99. {
  100.     XDEBUG(printf("XFE_TaskBarDrop::processTargets()\n"));
  101.     
  102.     if (!targets || !data || numItems==0)
  103.         return FALSE;
  104.  
  105.     int i;
  106.  
  107.     int urlCount=0;
  108.     
  109.     // count # of items in list (need to expand multi-item NetscapeURL data)
  110.     for (i=0;i<numItems;i++) {
  111.         if (targets[i]==None || data[i]==NULL || strlen(data[i])==0)
  112.             continue;
  113.         if (targets[i]==_XA_FILE_NAME) urlCount++;
  114.         else if (targets[i]==XA_STRING) urlCount++;
  115.         else if (targets[i]==_XA_NETSCAPE_URL) {
  116.             XFE_URLDesktopType urlData(data[i]);
  117.             urlCount+=urlData.numItems();
  118.         }
  119.     }
  120.  
  121.     char **urlList=new char*[urlCount];
  122.     
  123.     // create list of urls for dropped documents
  124.  
  125.     int j;
  126.     for (i=0,j=0;i<numItems;i++) {
  127.         if (targets[i]==None || data[i]==NULL || strlen(data[i])==0)
  128.             continue;
  129.  
  130.         XDEBUG(printf("  [%d] %s: \"%s\"\n",i,XmGetAtomName(XtDisplay(_widget),targets[i]),data[i]));
  131.  
  132.         if (targets[i]==_XA_FILE_NAME)
  133.             urlList[j++]=XP_STRDUP(data[i]);
  134.         else if (targets[i]==XA_STRING)
  135.             urlList[j++]=XP_STRDUP(data[i]);
  136.         else if (targets[i]==_XA_NETSCAPE_URL) {
  137.             XFE_URLDesktopType urlData(data[i]);
  138.             for (int k=0;k<urlData.numItems();k++)
  139.                 urlList[j++]=XP_STRDUP(urlData.url(k));
  140.         }
  141.     }
  142.  
  143.     // execute command on url list
  144.  
  145.     // Browser or Editor drop - open each document in a new window
  146.     if (_command==xfeCmdOpenOrBringUpBrowser
  147. #ifdef EDITOR
  148.     || _command==xfeCmdOpenEditor
  149. #endif
  150.        ) {
  151.         for (i=0;i<urlCount;i++)
  152.             openDocument(urlList[i]);
  153.     }
  154.  
  155. #ifdef MOZ_MAIL_NEWS
  156.     // Mail or News drop - open one compose window with documents attached
  157.     if (_command==xfeCmdOpenInboxAndGetNewMessages ||
  158.         _command==xfeCmdOpenNewsgroups) {
  159.         openComposeWindow((const char**)urlList,urlCount);
  160.     }
  161. #endif
  162.     
  163.     // free url list
  164.     for (j=0;j<urlCount;j++)
  165.         if (urlList[j]) XP_FREE((void*)urlList[j]);
  166.     
  167.     delete urlList;
  168.     
  169.     return TRUE;
  170. }
  171.  
  172. // process drop on browser or editor task icons
  173.  
  174. void XFE_TaskBarDrop::openDocument(const char *url)
  175. {
  176.     if (!url) return;
  177.  
  178.     URL_Struct *urlStruct = NET_CreateURLStruct (url,NET_DONT_RELOAD);
  179.  
  180.     if (!urlStruct)
  181.         return;
  182.  
  183. #ifdef MOZ_MAIL_NEWS
  184.     // Don't open a window if this is not a document URL
  185.     if (!MSG_RequiresBrowserWindow(urlStruct->address)) {
  186.         MWContext *context=XP_GetNonGridContext(fe_all_MWContexts->context);
  187.         if (context)
  188.             fe_GetURL(context,urlStruct, FALSE);
  189.         else
  190.             NET_FreeURLStruct(urlStruct);
  191.         return;
  192.     }
  193. #endif
  194.  
  195.     // Open a new window with this URL
  196.     if (_command==xfeCmdOpenOrBringUpBrowser) {
  197.         fe_showBrowser(FE_GetToplevelWidget(),
  198.                        NULL,
  199.                        NULL,
  200.                        urlStruct);
  201.     }
  202. #ifdef EDITOR
  203.     else if (_command==xfeCmdOpenEditor) {
  204.         fe_showEditor(XfeAncestorFindApplicationShell(_widget),
  205.                       NULL,
  206.                       NULL,
  207.                       urlStruct);
  208.     }
  209. #endif
  210. }
  211.  
  212. #ifdef MOZ_MAIL_NEWS
  213. // process drop on mail or news taskbar icons
  214.  
  215. void XFE_TaskBarDrop::openComposeWindow(const char **urlList,int urlCount)
  216. {
  217.     MWContext *context=XP_GetNonGridContext(fe_all_MWContexts->context);
  218.     if (!context)
  219.         return;
  220.  
  221.     MSG_Pane* pane = fe_showCompose(XtParent(CONTEXT_WIDGET(context)),
  222.                                     NULL,
  223.                                     context,
  224.                                     NULL,
  225.                                     NULL,
  226.                                     MSG_DEFAULT,
  227.                                     (_command==xfeCmdOpenNewsgroups ? True : False)
  228.                                     );
  229.  
  230.     // add urlList as attachments
  231.     MSG_AttachmentData *attachments=new struct MSG_AttachmentData[urlCount+1];
  232.     int i;
  233.     int numAttachments=0;
  234.  
  235.     for (i=0;i<urlCount;i++) {
  236.         if (XFE_ComposeAttachFolderView::validateAttachment(_widget,urlList[i])) {
  237.             struct MSG_AttachmentData m = { 0 };
  238.             m.url=XP_STRDUP(urlList[i]);
  239.             m.desired_type=NULL;
  240.             attachments[numAttachments++]=m;
  241.         }
  242.     }
  243.  
  244.     if (numAttachments>0) {
  245.         attachments[numAttachments].url=NULL; // terminate list
  246.         MSG_SetAttachmentList(pane,attachments);
  247.     }
  248.     
  249.     // delete list
  250.     for (i=0;i<numAttachments;i++) {
  251.         if (attachments[i].url)
  252.             XP_FREE((void*)attachments[i].url);
  253.     }
  254.     delete attachments;
  255. }
  256. #endif  // MOZ_MAIL_NEWS
  257.