Changeset 618


Ignore:
Timestamp:
Apr 20, 2007, 9:19:03 PM (18 years ago)
Author:
Steven Levine
Message:

Add more drag/drop error checking
Use FreeDragInfoData
Sync with NumItemsToUnhilite AcceptOneDrop GetOneDrop mods

Location:
trunk/dll
Files:
15 edited

Legend:

Unmodified
Added
Removed
  • trunk/dll/arccnrs.c

    r606 r618  
    3333  14 Mar 07 SHL ArcObjWndProc/UM_ENTER: delay before starting viewer
    3434  30 Mar 07 GKY Remove GetPString for window class names
    35    06 Apr 07 GKY Work around PM DragInfo and DrgFreeISH limit
     35  06 Apr 07 GKY Work around PM DragInfo and DrgFreeISH limit
    3636  06 Apr 07 GKY Add some error checking in drag/drop
     37  20 Apr 07 SHL Sync with NumItemsToUnhilite mods
     38
    3739***********************************************************************/
    3840
     
    950952      switch (msg) {
    951953      case DM_DRAGOVER:
    952         if (AcceptOneDrop(mp1, mp2))
     954        if (AcceptOneDrop(hwnd, mp1, mp2))
    953955          return MRFROM2SHORT(DOR_DROP, DO_MOVE);
    954956        return MRFROM2SHORT(DOR_NODROP, 0);     /* Drop not valid */
     
    964966            DrawTargetEmphasis(hwnd, emphasized);
    965967          }
    966           if (GetOneDrop(mp1, mp2, szFrom, sizeof(szFrom)))
     968          if (GetOneDrop(hwnd, mp1, mp2, szFrom, sizeof(szFrom)))
    967969            WinSendMsg(WinWindowFromID(WinQueryWindow(hwnd, QW_PARENT),
    968970                                       ARC_CNR),
     
    11301132      li = DoFileDrop(dcd->hwndCnr,
    11311133                      dcd->directory, FALSE, MPVOID, MPFROMP(&cni));
    1132       if (fExceedPMDrgLimit)
     1134      if (NumItemsToUnhilite)
    11331135             saymsg(MB_CANCEL | MB_ICONEXCLAMATION,
    11341136                                   hwnd,
     
    30063008                             dcd->hwndObject,
    30073009                             mp2, dcd->arcname, NULL, TRUE)) {
    3008                 if ((fUnHilite && wasemphasized) || fExceedPMDrgLimit)
     3010                if ((fUnHilite && wasemphasized) || NumItemsToUnhilite)
    30093011                  UnHilite(hwnd, TRUE, &dcd->lastselection);
    30103012              }
     
    30363038          li = DoFileDrop(hwnd, dcd->arcname, FALSE, mp1, mp2);
    30373039          DosBeep(50, 100);             // fixme to know why beep?
    3038           if (fExceedPMDrgLimit)
     3040          if (NumItemsToUnhilite)
    30393041            saymsg(MB_CANCEL | MB_ICONEXCLAMATION,
    30403042                                  hwnd,
  • trunk/dll/assoc.c

    r552 r618  
    1212  10 Sep 06 GKY Add Move to last, Okay adds if new, Replace Current in Listbox Dialog
    1313  19 Oct 06 GKY Rework replace logic
    14   18 Feb 07 GKY Movw error messages etc to string file
     14  18 Feb 07 GKY Move error messages etc to string file
     15  19 Apr 07 SHL Sync with AcceptOneDrop GetOneDrop mods
    1516
    1617**************************************************************************************/
     
    7475      DrawTargetEmphasis(hwnd, emphasized);
    7576    }
    76     if (AcceptOneDrop(mp1, mp2))
     77    if (AcceptOneDrop(hwnd, mp1, mp2))
    7778      return MRFROM2SHORT(DOR_DROP, DO_MOVE);
    7879    return MRFROM2SHORT(DOR_NEVERDROP, 0);
     
    9798        DrawTargetEmphasis(hwnd, emphasized);
    9899      }
    99       if (GetOneDrop(mp1, mp2, szFrom, CCHMAXPATH)) {
     100      if (GetOneDrop(hwnd, mp1, mp2, szFrom, CCHMAXPATH)) {
    100101        strcat(szFrom, " %a");
    101102        WinSetWindowText(hwnd, szFrom);
  • trunk/dll/avl.c

    r603 r618  
    2626  01 Nov 06 SHL Turn off leftover debug code
    2727  06 Apr 07 GKY Work around PM DragInfo and DrgFreeDISH limit
     28  19 Apr 07 SHL Use FreeDragInfoData
     29  19 Apr 07 SHL Add more drag/drop error checking
    2830
    2931***********************************************************************/
     
    548550  PFNWP pfnOldProc = (PFNWP) WinQueryWindowPtr(hwnd, QWL_USER);
    549551
    550   PDRAGITEM pditem;
    551   PDRAGINFO pdinfo;
     552  PDRAGITEM pDItem;
     553  PDRAGINFO pDInfo;
    552554  BOOL ok;
    553555
     
    568570
    569571      if (cur_ndx != LIT_NONE) {
    570         pdinfo = DrgAllocDraginfo(1);
    571         if (pdinfo) {
    572           pdinfo->usOperation = DO_DEFAULT;
    573           pdinfo->hwndSource = hwnd;
     572        pDInfo = DrgAllocDraginfo(1);
     573        if (pDInfo) {
     574          pDInfo->usOperation = DO_DEFAULT;
     575          pDInfo->hwndSource = hwnd;
    574576
    575577          memset(&ditem, 0, sizeof(DRAGITEM));
     
    593595          dimage.cxOffset = -16;
    594596          dimage.cyOffset = 0;
    595           DrgSetDragitem(pdinfo, &ditem, sizeof(DRAGITEM), 0);  /* Index of DRAGITEM */
    596           hwndDrop = DrgDrag(hwnd, pdinfo, &dimage, 1,  /* One DRAGIMAGE */
     597          DrgSetDragitem(pDInfo, &ditem, sizeof(DRAGITEM), 0);  /* Index of DRAGITEM */
     598          hwndDrop = DrgDrag(hwnd, pDInfo, &dimage, 1,  /* One DRAGIMAGE */
    597599                             VK_ENDDRAG, NULL);
    598600          if (!hwndDrop)
    599601            Win_Error(hwnd, hwnd, pszSrcFile, __LINE__, "DrgDrag");
    600602
    601           DrgFreeDraginfo(pdinfo);
     603          DrgFreeDraginfo(pDInfo);
    602604          // WinSetWindowPos(hwnd,HWND_TOP,0,0,0,0,SWP_ACTIVATE);
    603605        }
     
    623625      // fprintf(stderr, "DRAGOVER posted 0x%x WM_BUTTON1CLICK x y %d %d\n", hwnd, ptl2.x, ptl2.y);
    624626    }
    625     pdinfo = (PDRAGINFO) mp1;           /* Get DRAGINFO pointer */
    626     if (pdinfo) {
    627       DrgAccessDraginfo(pdinfo);
    628       pditem = DrgQueryDragitemPtr(pdinfo, 0);
    629       /* Check valid rendering mechanisms and data format */
    630       ok = DrgVerifyRMF(pditem, DRM_LBOX, NULL);
    631       DrgFreeDraginfo(pdinfo);
    632       if (ok) {
    633       }
    634     }
    635     return ok ? MRFROM2SHORT(DOR_DROP, DO_MOVE) : MRFROM2SHORT(DOR_NEVERDROP,
    636                                                                0);
     627    pDInfo = (PDRAGINFO) mp1;           /* Get DRAGINFO pointer */
     628    if (pDInfo) {
     629      if (!DrgAccessDraginfo(pDInfo)) {
     630        Win_Error(HWND_DESKTOP, HWND_DESKTOP, pszSrcFile, __LINE__,
     631                  "DrgAccessDraginfo");
     632      }
     633      else {
     634        pDItem = DrgQueryDragitemPtr(pDInfo, 0);
     635        /* Check valid rendering mechanisms and data format */
     636        ok = DrgVerifyRMF(pDItem, DRM_LBOX, NULL);
     637        DrgFreeDraginfo(pDInfo);
     638      }
     639    }
     640    return ok ? MRFROM2SHORT(DOR_DROP, DO_MOVE) :
     641                MRFROM2SHORT(DOR_NEVERDROP, 0);
    637642
    638643  case DM_DRAGLEAVE:
     
    652657  case DM_DROP:
    653658    ok = FALSE;
    654     // fprintf(stderr, "DROP\n");
    655     fflush(stderr);
    656659    if (emphasized) {
    657660      emphasized = FALSE;
    658661      // DrawTargetEmphasis(hwnd, emphasized);
    659662    }
    660     pdinfo = (PDRAGINFO) mp1;           /* Get DRAGINFO pointer */
    661     if (pdinfo) {
    662       DrgAccessDraginfo(pdinfo);
    663       pditem = DrgQueryDragitemPtr(pdinfo, 0);
    664       if (!pditem)
    665         Win_Error(hwnd, hwnd, pszSrcFile, __LINE__, "DM_DROP");
    666       /* Check valid rendering mechanisms and data */
    667       ok = DrgVerifyRMF(pditem, DRM_LBOX, NULL)
    668         && ~pditem->fsControl & DC_PREPARE;
    669       if (ok) {
    670         // ret = FullDrgName(pditem,buffer,buflen);
    671         /* note: targetfail is returned to source for all items */
    672         DrgSendTransferMsg(pdinfo->hwndSource, DM_ENDCONVERSATION,
    673                            MPFROMLONG(pditem->ulItemID),
    674                            MPFROMLONG(DMFL_TARGETSUCCESSFUL));
    675       }
    676       DeleteDragitemStrHandles(pdinfo); //
    677       DrgDeleteDraginfoStrHandles(pdinfo);
    678       DrgFreeDraginfo(pdinfo);
     663    pDInfo = (PDRAGINFO) mp1;           /* Get DRAGINFO pointer */
     664    if (pDInfo) {
     665      if (!DrgAccessDraginfo(pDInfo)) {
     666        Win_Error(HWND_DESKTOP, HWND_DESKTOP, pszSrcFile, __LINE__,
     667                  "DrgAccessDraginfo");
     668      }
     669      else {
     670        pDItem = DrgQueryDragitemPtr(pDInfo, 0);
     671        if (!pDItem)
     672          Win_Error(hwnd, hwnd, pszSrcFile, __LINE__, "DM_DROP");
     673        /* Check valid rendering mechanisms and data */
     674        ok = DrgVerifyRMF(pDItem, DRM_LBOX, NULL)
     675                          && ~pDItem->fsControl & DC_PREPARE;
     676        if (ok) {
     677          // ret = FullDrgName(pDItem,buffer,buflen);
     678          /* note: targetfail is returned to source for all items */
     679          DrgSendTransferMsg(pDInfo->hwndSource, DM_ENDCONVERSATION,
     680                             MPFROMLONG(pDItem->ulItemID),
     681                             MPFROMLONG(DMFL_TARGETSUCCESSFUL));
     682        }
     683        FreeDragInfoData(hwnd, pDInfo);
     684      }
    679685    }
    680686    return 0;
    681   }                                     // switch
     687  } // switch
    682688  return pfnOldProc ? pfnOldProc(hwnd, msg, mp1, mp2) :
    683689    WinDefWindowProc(hwnd, msg, mp1, mp2);
  • trunk/dll/collect.c

    r606 r618  
    3333  06 Apr 07 GKY Work around PM DragInfo and DrgFreeDISH limits
    3434  06 Apr 07 GKY Add some error checking in drag/drop
     35  19 Apr 07 SHL Use FreeDragInfoData.  Add more drag/drop error checks.
    3536
    3637***********************************************************************/
     
    459460      cni.pDragInfo = (PDRAGINFO) mp1;
    460461      li = DoFileDrop(dcd->hwndCnr, NULL, FALSE, MPVOID, MPFROMP(&cni));
    461       if (fExceedPMDrgLimit)
    462         saymsg(MB_CANCEL | MB_ICONEXCLAMATION,
    463                              hwnd,
    464                              GetPString(IDS_ERRORTEXT),
    465                    GetPString(IDS_EXCEEDPMDRGLMT));
     462      if (NumItemsToUnhilite)
     463        saymsg(MB_CANCEL | MB_ICONEXCLAMATION,
     464                             hwnd,
     465                             GetPString(IDS_ERRORTEXT),
     466                   GetPString(IDS_EXCEEDPMDRGLMT));
    466467      if (li) {
    467468        li->type = (fDefaultDeletePerm) ? IDM_PERMDELETE : IDM_DELETE;
     
    21132114          ULONG numitems;
    21142115          USHORT usOperation;
    2115                 APIRET rc;
     2116                APIRET rc;
    21162117
    21172118          pci = (PCNRITEM) ((PCNRDRAGINFO) mp2)->pRecord;
     
    21192120          if (!DrgAccessDraginfo(pDInfo)) {
    21202121            Win_Error(hwnd, hwnd, pszSrcFile, __LINE__,
    2121                       "%s", GetPString(IDS_DROPERRORTEXT));
    2122             break;
     2122                      "DrgAccessDraginfo");
     2123            return 0;
    21232124          }
    21242125          numitems = DrgQueryDragitemCount(pDInfo);
    21252126          usOperation = pDInfo->usOperation;
    2126           rc = DeleteDragitemStrHandles(pDInfo); //
    2127           if(!rc)
    2128           Win_Error(HWND_DESKTOP, HWND_DESKTOP, pszSrcFile, __LINE__,
    2129                     "DeleteDragitemStrHandles");
    2130           DrgDeleteDraginfoStrHandles (pDInfo);
    2131           rc = DrgFreeDraginfo(pDInfo);
    2132           if(!rc)
    2133           Win_Error(HWND_DESKTOP, HWND_DESKTOP, pszSrcFile, __LINE__,
    2134                  "DrgFreeDraginfo");
     2127          FreeDragInfoData(hwnd, pDInfo);
    21352128          saymsg(MB_ENTER | MB_ICONASTERISK,
    21362129                 hwnd,
     
    21542147          PDRAGINFO pDInfo;
    21552148
     2149          // fixme to know why needed
    21562150          pDInfo = ((PCNRDRAGINFO) mp2)->pDragInfo;
    2157           DrgAccessDraginfo(pDInfo);    /* Access DRAGINFO       */
    2158           DrgFreeDraginfo(pDInfo);      /* Free DRAGINFO         */
     2151          DrgAccessDraginfo(pDInfo);    /* Access DRAGINFO */
     2152          DrgFreeDraginfo(pDInfo);      /* Free DRAGINFO */
    21592153        }
    21602154        return 0;
     
    21632157      case CN_DRAGOVER:
    21642158        if (mp2) {
    2165           PDRAGITEM pDItem;     /* Pointer to DRAGITEM   */
    2166           PDRAGINFO pDInfo;     /* Pointer to DRAGINFO   */
     2159          PDRAGITEM pDItem;     /* Pointer to DRAGITEM */
     2160          PDRAGINFO pDInfo;     /* Pointer to DRAGINFO */
    21672161          PCNRITEM pci;
    21682162          USHORT uso;
    21692163
    21702164          pci = (PCNRITEM) ((PCNRDRAGINFO) mp2)->pRecord;
    2171 //            if(SHORT1FROMMP(mp1) == CN_DRAGAFTER)
    2172           //            pci = NULL;
     2165          // if(SHORT1FROMMP(mp1) == CN_DRAGAFTER)
     2166          //    pci = NULL;
    21732167          pDInfo = ((PCNRDRAGINFO) mp2)->pDragInfo;
    2174           DrgAccessDraginfo(pDInfo);    /* Access DRAGINFO       */
     2168          if (!DrgAccessDraginfo(pDInfo)) {
     2169            Win_Error(hwnd, hwnd, pszSrcFile, __LINE__,
     2170                      "DrgAccessDraginfo");
     2171            return (MRFROM2SHORT(DOR_NODROP, 0));       /* Drop not valid */
     2172          }
    21752173          if (pci) {
    21762174            if (pci->rc.flRecordAttr & CRA_SOURCE) {
     
    22052203            }
    22062204          }
    2207           pDItem = DrgQueryDragitemPtr(pDInfo,  /* Access DRAGITEM       */
    2208                                        0);      /* Index to DRAGITEM     */
     2205          pDItem = DrgQueryDragitemPtr(pDInfo,  /* Access DRAGITEM */
     2206                                       0);      /* Index to DRAGITEM */
    22092207          if (DrgVerifyRMF(pDItem,      /* Check valid rendering */
    2210                            DRM_OS2FILE, /* mechanisms and data   */
     2208                           DRM_OS2FILE, /* mechanisms and data */
    22112209                           NULL)) {
    2212             DrgFreeDraginfo(pDInfo);    /* Free DRAGINFO         */
     2210            DrgFreeDraginfo(pDInfo);    /* Free DRAGINFO */
    22132211            if (pci) {
    22142212              if (driveflags[toupper(*pci->szFileName) - 'A'] &
     
    22172215              if (toupper(*pci->szFileName) < 'C')
    22182216                return MRFROM2SHORT(DOR_DROP, DO_COPY);
    2219               return MRFROM2SHORT(DOR_DROP,     /* Return okay to drop   */
     2217              return MRFROM2SHORT(DOR_DROP,     /* Return okay to drop */
    22202218                                  ((fCopyDefault) ? DO_COPY : DO_MOVE));
    22212219            }
    22222220            else
    2223               return MRFROM2SHORT(DOR_DROP,     /* Return okay to drop   */
     2221              return MRFROM2SHORT(DOR_DROP,     /* Return okay to drop */
    22242222                                  DO_COPY);
    22252223          }
    2226           DrgFreeDraginfo(pDInfo);      /* Free DRAGINFO         */
    2227         }
    2228         return (MRFROM2SHORT(DOR_NODROP, 0));   /* Drop not valid       */
     2224          DrgFreeDraginfo(pDInfo);      /* Free DRAGINFO */
     2225        }
     2226        return (MRFROM2SHORT(DOR_NODROP, 0));   /* Drop not valid */
    22292227
    22302228      case CN_INITDRAG:
     
    22452243                                 GetPString(IDS_DRAGFILEOBJTEXT));
    22462244              if (DoFileDrag(hwnd, dcd->hwndObject, mp2, NULL, NULL, TRUE)) {
    2247                 if ((fUnHilite && wasemphasized) || fExceedPMDrgLimit)
     2245                if ((fUnHilite && wasemphasized) || NumItemsToUnhilite)
    22482246                  UnHilite(hwnd, TRUE, &dcd->lastselection);
    22492247              }
     
    22602258          ULONG action = UM_ACTION;
    22612259
    2262           li = DoFileDrop(hwnd, NULL, TRUE, mp1, mp2);
    2263           if (fExceedPMDrgLimit)
    2264             saymsg(MB_CANCEL | MB_ICONEXCLAMATION,
    2265                                 hwnd,
    2266                                 GetPString(IDS_ERRORTEXT),
    2267                        GetPString(IDS_EXCEEDPMDRGLMT));
     2260          li = DoFileDrop(hwnd, NULL, TRUE, mp1, mp2);
     2261          if (NumItemsToUnhilite)
     2262            saymsg(MB_CANCEL | MB_ICONEXCLAMATION,
     2263                                hwnd,
     2264                                GetPString(IDS_ERRORTEXT),
     2265                       GetPString(IDS_EXCEEDPMDRGLMT));
    22682266          if (li) {
    22692267            if (!*li->targetpath) {
     
    22852283                li->type = WinDlgBox(HWND_DESKTOP, dcd->hwndParent,
    22862284                                     DropListProc, FM3ModHandle,
    2287                                      DND_FRAME, MPFROMP(&cl));
    2288                 if (li->type == DID_ERROR)
    2289                   Win_Error(DND_FRAME, HWND_DESKTOP, pszSrcFile, __LINE__,
    2290                             "Drag & Drop Dialog");
    2291                 if (!li->type) {
     2285                                     DND_FRAME, MPFROMP(&cl));
     2286                if (li->type == DID_ERROR)
     2287                  Win_Error(DND_FRAME, HWND_DESKTOP, pszSrcFile, __LINE__,
     2288                            "Drag & Drop Dialog");
     2289                if (!li->type) {
    22922290                  FreeListInfo(li);
    22932291                  return 0;
    22942292                }
    22952293                li->list = cl.list;
    2296                 if (!li->list || !li->list[0]) {
     2294                if (!li->list || !li->list[0]) {
    22972295                  FreeListInfo(li);
    22982296                  return 0;
  • trunk/dll/command.c

    r574 r618  
    1919  23 Mar 07 GKY Replace doesn't change item position
    2020  23 Mar 07 GKY Okay fails silently when item not changed
     21  19 Apr 07 SHL Sync with AcceptOneDrop GetOneDrop mods
    2122
    2223***********************************************************************/
     
    6364      DrawTargetEmphasis(hwnd, emphasized);
    6465    }
    65     if (AcceptOneDrop(mp1, mp2))
     66    if (AcceptOneDrop(hwnd, mp1, mp2))
    6667      return MRFROM2SHORT(DOR_DROP, DO_MOVE);
    6768    return MRFROM2SHORT(DOR_NEVERDROP, 0);
     
    8687        DrawTargetEmphasis(hwnd, emphasized);
    8788      }
    88       if (GetOneDrop(mp1, mp2, szFrom, CCHMAXPATH)) {
     89      if (GetOneDrop(hwnd, mp1, mp2, szFrom, CCHMAXPATH)) {
    8990        strcat(szFrom, " %a");
    9091        WinSetWindowText(hwnd, szFrom);
  • trunk/dll/dircnrs.c

    r606 r618  
    2424  06 Apr 07 GKY Work around PM DragInfo and DrgFreeDISH limits
    2525  06 Apr 07 GKY Add some error checking in drag/drop
     26  19 Apr 07 SHL Use FreeDragInfoData.  Add more drag/drop error checking.
    2627
    2728***********************************************************************/
     
    386387      switch (msg) {
    387388      case DM_DRAGOVER:
    388         if (AcceptOneDrop(mp1, mp2))
     389        if (AcceptOneDrop(hwnd, mp1, mp2))
    389390          return MRFROM2SHORT(DOR_DROP, DO_MOVE);
    390         return (MRFROM2SHORT(DOR_NODROP, 0));   /* Drop not valid        */
     391        return (MRFROM2SHORT(DOR_NODROP, 0));   /* Drop not valid */
    391392      case DM_DROPHELP:
    392393        DropHelp(mp1, mp2, hwnd, GetPString(IDS_DIRCNRFOLDERDROPHELP));
     
    400401            DrawTargetEmphasis(hwnd, emphasized);
    401402          }
    402           if (GetOneDrop(mp1, mp2, szFrom, sizeof(szFrom)))
     403          if (GetOneDrop(hwnd, mp1, mp2, szFrom, sizeof(szFrom)))
    403404            WinSendMsg(WinWindowFromID(WinQueryWindow(hwnd, QW_PARENT),
    404405                                       DIR_CNR),
     
    589590        DoFileDrop(dcd->hwndCnr, dcd->directory, FALSE, MPVOID,
    590591                   MPFROMP(&cni));
    591       if (fExceedPMDrgLimit)
    592         saymsg(MB_CANCEL | MB_ICONEXCLAMATION,
    593                              hwnd,
    594                              GetPString(IDS_ERRORTEXT),
    595                    GetPString(IDS_EXCEEDPMDRGLMT));
     592      if (NumItemsToUnhilite)
     593        saymsg(MB_CANCEL | MB_ICONEXCLAMATION,
     594                             hwnd,
     595                             GetPString(IDS_ERRORTEXT),
     596                   GetPString(IDS_EXCEEDPMDRGLMT));
    596597      if (li) {
    597598        li->type = (fDefaultDeletePerm) ? IDM_PERMDELETE : IDM_DELETE;
     
    26342635
    26352636/*
    2636           case CN_PICKUP:
    2637             return PickUp(hwnd,dcd->hwndObject,mp2);
     2637          case CN_PICKUP:
     2638            return PickUp(hwnd,dcd->hwndObject,mp2);
    26382639*/
    26392640
     
    26942695            Win_Error(hwnd, hwnd, pszSrcFile, __LINE__,
    26952696                      GetPString(IDS_DROPERRORTEXT));
    2696             break;
    2697           }
    2698           numitems = DrgQueryDragitemCount(pDInfo);
    2699           usOperation = pDInfo->usOperation;
    2700           rc = DeleteDragitemStrHandles(pDInfo); //
    2701           if(!rc)
    2702           Win_Error(HWND_DESKTOP, HWND_DESKTOP, pszSrcFile, __LINE__,
    2703                     "DeleteDragitemStrHandles");
    2704           DrgDeleteDraginfoStrHandles (pDInfo);
    2705           rc = DrgFreeDraginfo(pDInfo);
    2706           if(!rc)
    2707           Win_Error(HWND_DESKTOP, HWND_DESKTOP, pszSrcFile, __LINE__,
    2708                  "DrgFreeDraginfo");
    2709           saymsg(MB_ENTER | MB_ICONASTERISK,
    2710                  hwnd,
    2711                  GetPString(IDS_DROPHELPHDRTEXT),
    2712                  GetPString(IDS_DROPHELPTEXT),
    2713                  numitems,
    2714                  &"s"[numitems == 1L],
    2715                  (pci) ? NullStr : GetPString(IDS_NOTEXT),
    2716                  (pci) ? NullStr : " ",
    2717                  (pci) ? pci->szFileName : NullStr,
    2718                  (pci) ? " " : NullStr,
    2719                  GetPString((usOperation == DO_COPY) ?
    2720                             IDS_COPYTEXT :
    2721                             (usOperation == DO_LINK) ?
    2722                             IDS_LINKTEXT : IDS_MOVETEXT));
     2697          }
     2698          else {
     2699            numitems = DrgQueryDragitemCount(pDInfo);
     2700            usOperation = pDInfo->usOperation;
     2701            FreeDragInfoData(hwnd, pDInfo);
     2702            saymsg(MB_ENTER | MB_ICONASTERISK,
     2703                   hwnd,
     2704                   GetPString(IDS_DROPHELPHDRTEXT),
     2705                   GetPString(IDS_DROPHELPTEXT),
     2706                   numitems,
     2707                   &"s"[numitems == 1L],
     2708                   pci ? NullStr : GetPString(IDS_NOTEXT),
     2709                   pci ? NullStr : " ",
     2710                   pci ? pci->szFileName : NullStr,
     2711                   pci ? " " : NullStr,
     2712                   GetPString((usOperation == DO_COPY) ?
     2713                              IDS_COPYTEXT :
     2714                              (usOperation == DO_LINK) ?
     2715                              IDS_LINKTEXT : IDS_MOVETEXT));
     2716          }
    27232717        }
    27242718        return 0;
    27252719
    27262720      case CN_DRAGLEAVE:
    2727 #ifdef NEVER
    2728         if (mp2) {
    2729 
    2730           PDRAGINFO pDInfo;
    2731 
    2732           pDInfo = ((PCNRDRAGINFO) mp2)->pDragInfo;
    2733           DrgAccessDraginfo(pDInfo);    /* Access DRAGINFO       */
    2734           DrgFreeDraginfo(pDInfo);      /* Free DRAGINFO         */
    2735         }
    2736 #endif
    27372721        return 0;
    27382722
     
    27412725        if (mp2) {
    27422726
    2743           PDRAGITEM pDItem;     /* Pointer to DRAGITEM   */
    2744           PDRAGINFO pDInfo;     /* Pointer to DRAGINFO   */
     2727          PDRAGITEM pDItem;     /* Pointer to DRAGITEM */
     2728          PDRAGINFO pDInfo;     /* Pointer to DRAGINFO */
    27452729          PCNRITEM pci;
    27462730          USHORT uso;
     
    27482732          pci = (PCNRITEM) ((PCNRDRAGINFO) mp2)->pRecord;
    27492733          pDInfo = ((PCNRDRAGINFO) mp2)->pDragInfo;
    2750           DrgAccessDraginfo(pDInfo);    /* Access DRAGINFO */
     2734          if (!DrgAccessDraginfo(pDInfo)) {
     2735            Win_Error(HWND_DESKTOP, HWND_DESKTOP, pszSrcFile, __LINE__,
     2736                      "DrgAccessDraginfo");
     2737              return (MRFROM2SHORT(DOR_NEVERDROP, 0));
     2738          }
    27512739          if (*dcd->directory &&
    27522740              (driveflags[toupper(*dcd->directory) - 'A'] &
     
    27542742            DrgFreeDraginfo(pDInfo);
    27552743            return MRFROM2SHORT(DOR_DROP,       /* Return okay to link */
    2756                                 DO_LINK);       /* (compare) only      */
     2744                                DO_LINK);       /* (compare) only */
    27572745          }
    27582746          if (pci) {
     
    27632751            uso = pDInfo->usOperation;
    27642752            if (uso == DO_DEFAULT)
    2765               uso = (fCopyDefault) ? DO_COPY : DO_MOVE;
     2753              uso = fCopyDefault ? DO_COPY : DO_MOVE;
    27662754            if (!(pci->attrFile & FILE_DIRECTORY)) {
    27672755              if (uso != DO_LINK && uso != DO_COPY && uso != DO_MOVE) {
     
    27972785              ((!pci || (pci->attrFile & FILE_DIRECTORY)) &&
    27982786               DrgVerifyRMF(pDItem, DRM_FM2ARCMEMBER, DRF_FM2ARCHIVE))) {
    2799             /* Free DRAGINFO */
    28002787            DrgFreeDraginfo(pDInfo);
    28012788            if (driveflags[toupper(*dcd->directory) - 'A'] &
     
    28042791            if (toupper(*dcd->directory) < 'C')
    28052792              return MRFROM2SHORT(DOR_DROP, DO_COPY);
    2806             return MRFROM2SHORT(DOR_DROP,       /* Return okay to drop  */
     2793            return MRFROM2SHORT(DOR_DROP,       /* Return okay to drop */
    28072794                                ((fCopyDefault) ? DO_COPY : DO_MOVE));
    28082795          }
    2809           DrgFreeDraginfo(pDInfo);      /* Free DRAGINFO         */
    2810         }
    2811         return MRFROM2SHORT(DOR_NODROP, 0);     /* Drop not valid        */
     2796          DrgFreeDraginfo(pDInfo);      /* Free DRAGINFO */
     2797        }
     2798        return MRFROM2SHORT(DOR_NODROP, 0);     /* Drop not valid */
    28122799
    28132800      case CN_INITDRAG:
     
    28302817            }
    28312818            else if (IsRoot(dcd->directory)) {
    2832                 saymsg(MB_ENTER, hwnd, GetPString(IDS_ERRORTEXT),
    2833                        GetPString(IDS_CANTDRAGROOTDIR));
     2819                saymsg(MB_ENTER, hwnd, GetPString(IDS_ERRORTEXT),
     2820                       GetPString(IDS_CANTDRAGROOTDIR));
    28342821              break;
    28352822            }
     
    28452832                           mp2,
    28462833                           NULL,
    2847                            (pci) ? NULL : dcd->directory,
    2848                            (pci) ? TRUE : FALSE)) {
    2849               if ((pci && fUnHilite && wasemphasized) || fExceedPMDrgLimit)
     2834                           pci ? NULL : dcd->directory,
     2835                           pci ? TRUE : FALSE)) {
     2836              if ((pci && fUnHilite && wasemphasized) || NumItemsToUnhilite) {
    28502837                UnHilite(hwnd, TRUE, &dcd->lastselection);
     2838              }
    28512839            }
    28522840            if (hwndStatus2) {
     
    28642852          ULONG action = UM_ACTION;
    28652853
    2866           li = DoFileDrop(hwnd, dcd->directory, TRUE, mp1, mp2);
    2867           if (fExceedPMDrgLimit)
    2868             saymsg(MB_CANCEL | MB_ICONEXCLAMATION,
    2869                                  hwnd,
    2870                                  GetPString(IDS_ERRORTEXT),
    2871                        GetPString(IDS_EXCEEDPMDRGLMT));
     2854          li = DoFileDrop(hwnd, dcd->directory, TRUE, mp1, mp2);
     2855          if (NumItemsToUnhilite) {
     2856            saymsg(MB_CANCEL | MB_ICONEXCLAMATION,
     2857                                 hwnd,
     2858                                 GetPString(IDS_ERRORTEXT),
     2859                                 GetPString(IDS_EXCEEDPMDRGLMT));
     2860          }
    28722861          if (li) {
    28732862            if (li->list && li->list[0] && IsRoot(li->list[0]))
     
    28852874              li->type = WinDlgBox(HWND_DESKTOP, dcd->hwndParent,
    28862875                                   DropListProc, FM3ModHandle,
    2887                                    DND_FRAME, MPFROMP(&cl));
    2888               if (li->type == DID_ERROR)
    2889                   Win_Error(DND_FRAME, HWND_DESKTOP, pszSrcFile, __LINE__,
    2890                             "Drag & Drop Dialog");
    2891               if (!li->type) {
     2876                                   DND_FRAME, MPFROMP(&cl));
     2877              if (li->type == DID_ERROR)
     2878                  Win_Error(DND_FRAME, HWND_DESKTOP, pszSrcFile, __LINE__,
     2879                            "Drag & Drop Dialog");
     2880              if (!li->type) {
    28922881                FreeListInfo(li);
    28932882                return 0;
    28942883              }
    28952884              li->list = cl.list;
    2896               if (!li->list || !li->list[0]) {
     2885              if (!li->list || !li->list[0]) {
    28972886                FreeListInfo(li);
    28982887                return 0;
  • trunk/dll/draglist.c

    r606 r618  
    1414  06 Apr 07 GKY Add DeleteDragitemStrHandles
    1515  06 Apr 07 GKY Add some error checking in drag/drop
     16  19 Apr 07 SHL Rework DeleteDragitemStrHandles to be FreeDragInfoData
     17  19 Apr 07 SHL Add more drag/drop error checking
     18  19 Apr 07 SHL Optimize DRAGITEM DRAGIMAGE array access
    1619
    1720***********************************************************************/
     
    1922#define INCL_DOS
    2023#define INCL_WIN
     24#define INCL_SHLERRORS
    2125#include <os2.h>
    2226
     
    3034static PSZ pszSrcFile = __FILE__;
    3135
    32 #pragma alloc_text(DRAGLIST,DragOne,DoFileDrag,DragList,PickUp,DeleteDragitemStrHandles)
    33 /* work around for DrgDeleteDraginfoStrHandles
    34 which seems to fail with a large number of strings */
    35 BOOL DeleteDragitemStrHandles (PDRAGINFO pDInfo)
     36#pragma alloc_text(DRAGLIST,DragOne,DoFileDrag,DragList,PickUp,FreeDragInfoData)
     37
     38/**
     39 * Delete drag item string handles.
     40 * Work around for DrgDeleteDraginfoStrHandles
     41 * which seems to fail with a large number of strings
     42 * Assume called after successful DrgAccessDraginfo
     43 */
     44
     45
     46// #define USE_FAST_FREE                // Define to let PM do free
     47
     48VOID FreeDragInfoData (HWND hwnd, PDRAGINFO pDInfo)
    3649{
    37     PDRAGITEM  pDItem;
    38     ULONG cDitem;
    39     UINT  i = 0;
    40     APIRET rc;
    41 
    42     cDitem = DrgQueryDragitemCount(pDInfo);
    43      for (; i < (UINT)cDitem; i++){
    44          pDItem = DrgQueryDragitemPtr(pDInfo, i);
    45      if (!pDItem)
    46         return FALSE;
    47      else {
    48         DrgDeleteStrHandle(pDItem->hstrType);
    49         DrgDeleteStrHandle(pDItem->hstrRMF);
    50         DrgDeleteStrHandle(pDItem->hstrContainerName);
    51         rc = DrgDeleteStrHandle(pDItem->hstrSourceName);
    52         if (!rc)
    53                Win_Error(HWND_DESKTOP, HWND_DESKTOP, pszSrcFile, __LINE__,
    54                         "DrgDeleteStrHandle");
    55         DrgDeleteStrHandle(pDItem->hstrTargetName);
    56      }
    57    } // for
    58    return TRUE;
     50  PDRAGITEM pDItem;
     51  ULONG cDitem;
     52  ULONG curitem;
     53  APIRET ok;
     54
     55# ifdef USE_FAST_FREE
     56  if (!DrgDeleteDraginfoStrHandles(pDInfo)) {
     57    Win_Error(hwnd, hwnd, pszSrcFile, __LINE__,
     58              "DrgDeleteDraginfoStrHandles");
     59  }
     60# else // The slow way
     61  cDitem = DrgQueryDragitemCount(pDInfo);
     62  for (curitem = 0; curitem < cDitem; curitem++) {
     63    pDItem = DrgQueryDragitemPtr(pDInfo, curitem);
     64    if (!pDItem) {
     65      Win_Error(hwnd, hwnd, pszSrcFile, __LINE__,
     66                "DrgQueryDragitemPtr(%u)", curitem);
     67    }
     68    else {
     69      ok = DrgDeleteStrHandle(pDItem->hstrType);
     70      if (!ok) {
     71        Win_Error(hwnd, hwnd, pszSrcFile, __LINE__,
     72                      "DrgDeleteStrHandle(0x%x) hstrType",pDItem->hstrType);
     73      }
     74      ok = DrgDeleteStrHandle(pDItem->hstrRMF);
     75      if (!ok) {
     76        Win_Error(hwnd, hwnd, pszSrcFile, __LINE__,
     77                      "DrgDeleteStrHandle(0x%x) hstrRMF",pDItem->hstrRMF);
     78      }
     79      ok = DrgDeleteStrHandle(pDItem->hstrContainerName);
     80      if (!ok) {
     81        Win_Error(hwnd, hwnd, pszSrcFile, __LINE__,
     82                      "DrgDeleteStrHandle(0x%x) hstrContainerName",pDItem->hstrContainerName);
     83      }
     84      ok = DrgDeleteStrHandle(pDItem->hstrSourceName);
     85      if (!ok) {
     86        Win_Error(hwnd, hwnd, pszSrcFile, __LINE__,
     87                      "DrgDeleteStrHandle(0x%x) hstrSourceName",pDItem->hstrSourceName);
     88      }
     89      ok = DrgDeleteStrHandle(pDItem->hstrTargetName);
     90      if (!ok) {
     91        Win_Error(hwnd, hwnd, pszSrcFile, __LINE__,
     92                      "DrgDeleteStrHandle(0x%x) hstrTargetName",pDItem->hstrTargetName);
     93      }
     94    }
     95  } // for
     96# endif
     97  if (!DrgFreeDraginfo(pDInfo)) {
     98    // fixme to find callers responsible for PMERR_SOURCE_SAME_AS_TARGET
     99    if ((WinGetLastError(WinQueryAnchorBlock(hwnd)) & 0xffff) != PMERR_SOURCE_SAME_AS_TARGET) {
     100      Win_Error(hwnd, hwnd, pszSrcFile, __LINE__,
     101               "DrgFreeDraginfo");
     102    }
     103    else
     104      DbgMsg(pszSrcFile, __LINE__, "DrgFreeDraginfo PMERR_SOURCE_SAME_AS_TARGET");
     105  }
    59106}
    60107
     
    95142        hptrDir : hptrFile;
    96143      memset(&DItem, 0, sizeof(DRAGITEM));
    97       DItem.hwndItem = (hwndObj) ? hwndObj : hwndCnr;   /* Initialize DRAGITEM */
     144      DItem.hwndItem = (hwndObj) ? hwndObj : hwndCnr;   // Initialize DRAGITEM
    98145      // DItem.hwndItem = hwndCnr;
    99146      DItem.ulItemID = 1;
     
    103150      DItem.hstrSourceName = DrgAddStrHandle(szFile);
    104151      if (!DItem.hstrSourceName)
    105         Win_Error(HWND_DESKTOP, HWND_DESKTOP, pszSrcFile, __LINE__,
    106         "DrgQueryStrName");
     152        Win_Error(HWND_DESKTOP, HWND_DESKTOP, pszSrcFile, __LINE__,
     153        "DrgQueryStrName");
    107154      DItem.hstrTargetName = DrgAddStrHandle(szFile);
    108155      DItem.fsControl = 0;
     
    125172      fakeicon.cxOffset = -16;
    126173      fakeicon.cyOffset = 0;
    127       pDInfo = DrgAllocDraginfo(1);     /* Allocate DRAGINFO */
     174      pDInfo = DrgAllocDraginfo(1);
    128175      if (pDInfo) {
    129176        if (IsFullName(filename) &&
     
    136183        pDInfo->hwndSource = (hwndObj) ? hwndObj : hwndCnr;
    137184        // pDInfo->hwndSource = hwndCnr;
    138         DrgSetDragitem(pDInfo,          /* Set item in DRAGINFO  */
    139                        &DItem,          /* Pointer to DRAGITEM   */
    140                        sizeof(DRAGITEM),        /* Size of DRAGITEM      */
    141                        0);              /* Index of DRAGITEM     */
     185        DrgSetDragitem(pDInfo, &DItem, sizeof(DRAGITEM), 0);
    142186        WinSetFocus(HWND_DESKTOP, HWND_DESKTOP);
    143         hDrop = DrgDrag(hwndCnr,        /* Initiate drag         */
    144                         pDInfo,         /* DRAGINFO structure    */
    145                         &fakeicon, 1L, VK_ENDDRAG,      /* End of drag indicator */
    146                         (PVOID) NULL);  /* Reserved              */
    147         //if (hDrop == NULLHANDLE)
    148         if (!DeleteDragitemStrHandles(pDInfo)) //)
    149             Win_Error(HWND_DESKTOP, HWND_DESKTOP, pszSrcFile, __LINE__,
    150                       "DeleteDragistr");
    151         DrgDeleteDraginfoStrHandles (pDInfo);
    152         DrgFreeDraginfo(pDInfo);        /* Free DRAGINFO struct  */
     187        hDrop = DrgDrag(hwndCnr,
     188                        pDInfo,
     189                        &fakeicon,
     190                        1,              // DragImage count
     191                        VK_ENDDRAG,     // Drag end button
     192                        NULL);
     193        if (hDrop == NULLHANDLE)
     194          FreeDragInfoData(hwndCnr, pDInfo);
    153195        WinSetWindowPos(hwndCnr, HWND_TOP, 0, 0, 0, 0, SWP_ACTIVATE);
    154196      }
     
    161203                CHAR * directory, BOOL moveok)
    162204{
    163   /* drag files from a container */
     205  // Drag files from a container
    164206
    165207  BOOL isdir, rooting = FALSE;
    166208  PCNRITEM pci;
    167   register CHAR *p;
     209  CHAR *p;
    168210  INT attribute = CRA_CURSORED;
    169211  PDRAGINFO pDInfo = NULL;
    170   DRAGITEM **ppDItem = NULL, **ppTest;
     212  DRAGITEM **ppDItem = NULL, **ppDITest;
     213  DRAGITEM *pDItem;
    171214  PCNRITEM pciRec = (PCNRITEM) pcd->pRecord;
    172   HWND hDrop = 0;
    173   register ULONG ulNumfiles = 0L, numdragalloc = 0L, Select, ulNumIcon = 0;
     215  HWND hDrop = NULLHANDLE;
     216  ULONG ulNumfiles = 0, ulNumDIAlloc = 0, ulSelect, ulNumIcon = 0;
    174217  CHAR szFile[CCHMAXPATH], szBuffer[CCHMAXPATH];
    175   DRAGIMAGE *padiIcon = NULL, *padiTest, diFakeIcon;
    176   APIRET rc;
    177 
    178   fExceedPMDrgLimit = 0;
     218  DRAGIMAGE *paDImgIcons = NULL, *pDImg, dimgFakeIcon;
     219  BOOL ok;
     220
     221  // fixme to be multi-drag safe - count needs to be in DCD etc. and passed to UnHilite
     222  NumItemsToUnhilite = 0;
    179223  if (!pciRec && directory && *directory)
    180224    return DragOne(hwndCnr, hwndObj, directory, moveok);
     
    202246  }
    203247
    204   Select = 0L;
     248  ulSelect = 0;
    205249  while (pci && (INT) pci > -1) {
    206250    if (!(pci->rc.flRecordAttr & CRA_FILTERED)) {
     
    223267    if (!arcfile) {
    224268      // Filesystem object
    225       isdir = ((pci->attrFile & FILE_DIRECTORY) != 0);
    226       if (ulNumfiles + 2L > numdragalloc) {
    227         if (!padiIcon) {
    228           padiTest =
    229             xrealloc(padiIcon, sizeof(DRAGIMAGE) * (numdragalloc + 4L),
     269      isdir = pci->attrFile & FILE_DIRECTORY;
     270      // fixme to expand smarter - expand fast at first - do same for similar code
     271      if (ulNumfiles + 2 > ulNumDIAlloc) {
     272        // Expand
     273        if (!paDImgIcons) {
     274          pDImg =
     275            xrealloc(paDImgIcons, sizeof(DRAGIMAGE) * (ulNumDIAlloc + 4L),
    230276                     pszSrcFile, __LINE__);
    231           if (padiTest)
    232             padiIcon = padiTest;
    233           else
     277          if (!pDImg)
    234278            break;
     279          paDImgIcons = pDImg;
    235280        }
    236281        else if (!ulNumIcon) {
    237           padiIcon[ulNumfiles].cb = sizeof(DRAGIMAGE);
    238           padiIcon[ulNumfiles].cptl = 0;
    239           padiIcon[ulNumfiles].hImage = hptrLast;
    240           padiIcon[ulNumfiles].fl = DRG_ICON;
    241           padiIcon[ulNumfiles].sizlStretch.cx = 32;
    242           padiIcon[ulNumfiles].sizlStretch.cy = 32;
    243           padiIcon[ulNumfiles].cxOffset = -16 + (ulNumfiles * 4);
    244           padiIcon[ulNumfiles].cyOffset = 0 + (ulNumfiles * 7);
     282          pDImg = &paDImgIcons[ulNumfiles];
     283          pDImg->cb = sizeof(DRAGIMAGE);
     284          pDImg->cptl = 0;
     285          pDImg->hImage = hptrLast;
     286          pDImg->fl = DRG_ICON;
     287          pDImg->sizlStretch.cx = 32;
     288          pDImg->sizlStretch.cy = 32;
     289          pDImg->cxOffset = -16 + (ulNumfiles * 4);
     290          pDImg->cyOffset = 0 + (ulNumfiles * 7);
    245291          ulNumIcon = ulNumfiles + 1;
    246292        }
    247         ppTest =
    248           xrealloc(ppDItem, sizeof(DRAGITEM *) * (numdragalloc + 4L),
     293        ppDITest =
     294          xrealloc(ppDItem, sizeof(DRAGITEM *) * (ulNumDIAlloc + 4L),
    249295                   pszSrcFile, __LINE__);
    250         if (ppTest) {
    251           ppDItem = ppTest;
    252           numdragalloc += 4L;
    253         }
    254         else
     296        if (!ppDITest)
    255297          break;
    256       }
    257       ppDItem[ulNumfiles] = xmalloc(sizeof(DRAGITEM), pszSrcFile, __LINE__);
    258       if (ppDItem[ulNumfiles]) {
    259         if (!ulNumIcon) {
    260           padiIcon[ulNumfiles].cb = sizeof(DRAGIMAGE);
    261           padiIcon[ulNumfiles].cptl = 0;
    262           padiIcon[ulNumfiles].hImage = pci->rc.hptrIcon;
    263           if (!padiIcon[ulNumfiles].hImage)
    264             padiIcon[ulNumfiles].hImage = (isdir) ? hptrDir : hptrFile;
    265           padiIcon[ulNumfiles].fl = DRG_ICON;
    266           padiIcon[ulNumfiles].sizlStretch.cx = 32;
    267           padiIcon[ulNumfiles].sizlStretch.cy = 32;
    268           padiIcon[ulNumfiles].cxOffset = -16 + (ulNumfiles * 3);
    269           padiIcon[ulNumfiles].cyOffset = 0 + (ulNumfiles * 6);
    270         }
    271         memset(ppDItem[ulNumfiles], 0, sizeof(DRAGITEM));
    272         ppDItem[ulNumfiles]->hwndItem = (hwndObj) ? hwndObj : hwndCnr;  /* Initialize DRAGITEM   */
    273         ppDItem[ulNumfiles]->hwndItem = hwndCnr;
    274         ppDItem[ulNumfiles]->ulItemID = (ULONG) pci;
    275         ppDItem[ulNumfiles]->hstrType = DrgAddStrHandle(DRT_UNKNOWN);
    276         ppDItem[ulNumfiles]->hstrRMF = DrgAddStrHandle(DRMDRFLIST);
    277         ppDItem[ulNumfiles]->hstrContainerName = DrgAddStrHandle(szBuffer);
    278              ppDItem[ulNumfiles]->hstrSourceName = DrgAddStrHandle(szFile);
    279         if (!ppDItem[ulNumfiles]->hstrSourceName){
    280             DrgDeleteStrHandle(ppDItem[ulNumfiles]->hstrType);
    281             DrgDeleteStrHandle(ppDItem[ulNumfiles]->hstrRMF);
    282             DrgDeleteStrHandle(ppDItem[ulNumfiles]->hstrContainerName);
    283             DrgDeleteStrHandle(ppDItem[ulNumfiles]->hstrSourceName);
    284             xfree(ppDItem[ulNumfiles]);
    285             fExceedPMDrgLimit = ulNumfiles - 1;
    286             break;
    287         }
    288         /*Win_Error(HWND_DESKTOP, HWND_DESKTOP, pszSrcFile, __LINE__,
    289                   "DrgAddStrHandle");*/
    290         ppDItem[ulNumfiles]->hstrTargetName = DrgAddStrHandle(szFile);
    291         ppDItem[ulNumfiles]->fsControl = (isdir) ? DC_CONTAINER : 0;
    292         if (IsFullName(pci->szFileName) &&
    293             (driveflags[toupper(*pci->szFileName) - 'A'] & DRIVE_REMOVABLE))
    294           ppDItem[ulNumfiles]->fsControl |= DC_REMOVEABLEMEDIA;
    295         ppDItem[ulNumfiles]->fsSupportedOps = DO_COPYABLE | DO_LINKABLE;
    296         if (moveok && IsFullName(pci->szFileName) &&
    297             !(driveflags[toupper(*pci->szFileName) - 'A'] &
    298               DRIVE_NOTWRITEABLE))
    299           ppDItem[ulNumfiles]->fsSupportedOps |= DO_MOVEABLE;
    300         if (IsRoot(pci->szFileName)) {
    301           ppDItem[ulNumfiles]->fsSupportedOps = DO_LINKABLE;
    302           rooting = TRUE;
    303         }
    304    //if (ulNumfiles >= 2000){
    305      // pDInfo = DrgAllocDraginfo(ulNumfiles);
    306      // fExceedPMDrgLimit = TRUE;
    307      // goto Thatsall;
    308      //   }
    309         ulNumfiles++;
    310         ppDItem[ulNumfiles] = NULL;
    311       }
    312       else
     298        ppDItem = ppDITest;
     299        ulNumDIAlloc += 4L;
     300      }
     301      pDItem = xmalloc(sizeof(DRAGITEM), pszSrcFile, __LINE__);
     302      if (!pDItem)
     303        break;                          // Already complained
     304      ppDItem[ulNumfiles] = pDItem;
     305      if (!ulNumIcon) {
     306        pDImg = &paDImgIcons[ulNumfiles];
     307        pDImg->cb = sizeof(DRAGIMAGE);
     308        pDImg->cptl = 0;
     309        pDImg->hImage = pci->rc.hptrIcon;
     310        if (!pDImg->hImage)
     311          pDImg->hImage = isdir ? hptrDir : hptrFile;
     312        pDImg->fl = DRG_ICON;
     313        pDImg->sizlStretch.cx = 32;
     314        pDImg->sizlStretch.cy = 32;
     315        pDImg->cxOffset = -16 + (ulNumfiles * 3);
     316        pDImg->cyOffset = 0 + (ulNumfiles * 6);
     317      }
     318      // Initialize DRAGITEM
     319      memset(pDItem, 0, sizeof(DRAGITEM));
     320      pDItem->hwndItem = (hwndObj) ? hwndObj : hwndCnr;
     321      pDItem->hwndItem = hwndCnr;
     322      pDItem->ulItemID = (ULONG) pci;
     323      pDItem->hstrType = DrgAddStrHandle(DRT_UNKNOWN);
     324      ok = pDItem->hstrType;
     325      pDItem->hstrRMF = DrgAddStrHandle(DRMDRFLIST);
     326      ok = ok && pDItem->hstrRMF;
     327      pDItem->hstrContainerName = DrgAddStrHandle(szBuffer);
     328      ok = ok && pDItem->hstrContainerName;
     329      pDItem->hstrSourceName = DrgAddStrHandle(szFile);
     330      ok = ok && pDItem->hstrSourceName;
     331      pDItem->hstrTargetName = DrgAddStrHandle(szFile);
     332      ok = ok && pDItem->hstrTargetName;
     333      if (!ok) {
     334        DbgMsg(pszSrcFile, __LINE__, "DrgAddStrHandle failed at %lu for %s", ulNumfiles, szFile);
     335        // Win_Error(HWND_DESKTOP, HWND_DESKTOP, pszSrcFile, __LINE__,"DrgAddStrHandle");
     336        if (pDItem->hstrType)
     337          DrgDeleteStrHandle(pDItem->hstrType);
     338        if (pDItem->hstrRMF)
     339          DrgDeleteStrHandle(pDItem->hstrRMF);
     340        if (pDItem->hstrContainerName)
     341          DrgDeleteStrHandle(pDItem->hstrContainerName);
     342        if (pDItem->hstrSourceName)
     343          DrgDeleteStrHandle(pDItem->hstrSourceName);
     344        if (pDItem->hstrTargetName)
     345          DrgDeleteStrHandle(pDItem->hstrTargetName);
     346        xfree(pDItem);
     347        // ppDItem[ulNumfiles] = NULL;  // Why bother - we can count - fixme to be gone
     348        NumItemsToUnhilite = ulNumfiles + 1;    // Use +1 to ensure non-zero on any failure
    313349        break;
     350      }
     351      pDItem->fsControl = isdir ? DC_CONTAINER : 0;
     352      if (IsFullName(pci->szFileName) &&
     353          (driveflags[toupper(*pci->szFileName) - 'A'] & DRIVE_REMOVABLE))
     354        pDItem->fsControl |= DC_REMOVEABLEMEDIA;
     355      pDItem->fsSupportedOps = DO_COPYABLE | DO_LINKABLE;
     356      if (moveok && IsFullName(pci->szFileName) &&
     357          !(driveflags[toupper(*pci->szFileName) - 'A'] &
     358            DRIVE_NOTWRITEABLE))
     359        pDItem->fsSupportedOps |= DO_MOVEABLE;
     360      if (IsRoot(pci->szFileName)) {
     361        pDItem->fsSupportedOps = DO_LINKABLE;
     362        rooting = TRUE;
     363      }
     364      ulNumfiles++;
     365      // ppDItem[ulNumfiles] = NULL;    // Why bother - can't we count - fixme to be gone?
    314366    }
    315367    else {
    316368      // Archive object
    317       if (ulNumfiles + 3L > numdragalloc) {
    318         ppTest =
    319           xrealloc(ppDItem, sizeof(DRAGITEM *) * (numdragalloc + 5L),
     369      if (ulNumfiles + 3L > ulNumDIAlloc) {
     370        ppDITest =
     371          xrealloc(ppDItem, sizeof(DRAGITEM *) * (ulNumDIAlloc + 5L),
    320372                   pszSrcFile, __LINE__);
    321         if (!ppTest)
     373        if (!ppDITest)
    322374          break;
    323         else {
    324           ppDItem = ppTest;
    325           numdragalloc += 5L;
    326         }
    327       }
    328       ppDItem[ulNumfiles] = xmalloc(sizeof(DRAGITEM), pszSrcFile, __LINE__);
    329       if (!ppDItem[ulNumfiles])
     375        ppDItem = ppDITest;
     376        ulNumDIAlloc += 5L;
     377      }
     378      pDItem = xmalloc(sizeof(DRAGITEM), pszSrcFile, __LINE__);
     379      if (!pDItem)
    330380        break;
    331       else {
    332         diFakeIcon.hImage = hptrFile;
    333         memset(ppDItem[ulNumfiles], 0, sizeof(DRAGITEM));
    334         ppDItem[ulNumfiles]->hwndItem = (hwndObj) ? hwndObj : hwndCnr;  /* Initialize DRAGITEM   */
    335         ppDItem[ulNumfiles]->hwndItem = hwndCnr;
    336         ppDItem[ulNumfiles]->ulItemID = (ULONG) pci;
    337         ppDItem[ulNumfiles]->hstrType = DrgAddStrHandle(DRT_UNKNOWN);
    338         ppDItem[ulNumfiles]->hstrRMF = DrgAddStrHandle(DRMDRFOS2FILE);
    339         ppDItem[ulNumfiles]->hstrContainerName = DrgAddStrHandle(arcfile);
    340         ppDItem[ulNumfiles]->hstrSourceName = DrgAddStrHandle(szFile);
    341         if (!ppDItem[ulNumfiles]->hstrSourceName){
    342           DrgDeleteStrHandle(ppDItem[ulNumfiles]->hstrType);
    343           DrgDeleteStrHandle(ppDItem[ulNumfiles]->hstrRMF);
    344           DrgDeleteStrHandle(ppDItem[ulNumfiles]->hstrContainerName);
    345           DrgDeleteStrHandle(ppDItem[ulNumfiles]->hstrSourceName);
    346           xfree(ppDItem[ulNumfiles]);
    347           fExceedPMDrgLimit = ulNumfiles - 1;
    348           break;
    349        }
    350         ppDItem[ulNumfiles]->hstrTargetName = DrgAddStrHandle(szFile);
    351         ppDItem[ulNumfiles]->fsControl = DC_PREPARE;
     381      ppDItem[ulNumfiles] = pDItem;
     382      dimgFakeIcon.hImage = hptrFile;
     383      // Initialize DRAGITEM
     384      memset(pDItem, 0, sizeof(DRAGITEM));
     385      pDItem->hwndItem = (hwndObj) ? hwndObj : hwndCnr;
     386      pDItem->hwndItem = hwndCnr;
     387      pDItem->ulItemID = (ULONG) pci;
     388      pDItem->hstrType = DrgAddStrHandle(DRT_UNKNOWN);
     389      ok = pDItem->hstrType;
     390      pDItem->hstrRMF = DrgAddStrHandle(DRMDRFOS2FILE);
     391      ok = ok && pDItem->hstrRMF;
     392      pDItem->hstrContainerName = DrgAddStrHandle(arcfile);
     393      ok = ok && pDItem->hstrContainerName;
     394      pDItem->hstrSourceName = DrgAddStrHandle(szFile);
     395      ok = ok && pDItem->hstrSourceName;
     396      pDItem->hstrTargetName = DrgAddStrHandle(szFile);
     397      ok = ok && pDItem->hstrTargetName;
     398      if (!ok){
     399        if (pDItem->hstrType)
     400          DrgDeleteStrHandle(pDItem->hstrType);
     401        if (pDItem->hstrRMF)
     402          DrgDeleteStrHandle(pDItem->hstrRMF);
     403        if (pDItem->hstrContainerName)
     404          DrgDeleteStrHandle(pDItem->hstrContainerName);
     405        if (pDItem->hstrSourceName)
     406          DrgDeleteStrHandle(pDItem->hstrSourceName);
     407        if (pDItem->hstrTargetName)
     408          DrgDeleteStrHandle(pDItem->hstrTargetName);
     409        xfree(pDItem);
     410        NumItemsToUnhilite = ulNumfiles + 1;    // +1 to ensure non-zero
     411        break;
     412     }
     413      pDItem->fsControl = DC_PREPARE;
     414      if (IsFullName(arcfile) &&
     415          (driveflags[toupper(*arcfile) - 'A'] & DRIVE_REMOVABLE))
     416        pDItem->fsControl |= DC_REMOVEABLEMEDIA;
     417      pDItem->fsSupportedOps = DO_COPYABLE;
     418      ulNumfiles++;
     419
     420      pDItem = xmalloc(sizeof(DRAGITEM), pszSrcFile, __LINE__);
     421      if (pDItem) {
     422        ppDItem[ulNumfiles] = pDItem;
     423        dimgFakeIcon.hImage = hptrFile;
     424        // Initialize DRAGITEM
     425        memset(pDItem, 0, sizeof(DRAGITEM));
     426        pDItem->hwndItem = (hwndObj) ? hwndObj : hwndCnr;
     427        pDItem->hwndItem = hwndCnr;
     428        pDItem->ulItemID = ulSelect++;
     429        pDItem->hstrType = DrgAddStrHandle(DRT_UNKNOWN);
     430        ok = ok && pDItem->hstrType;
     431        pDItem->hstrRMF = DrgAddStrHandle(DRMDRFFM2ARC);
     432        ok = ok && pDItem->hstrRMF;
     433        pDItem->hstrContainerName = DrgAddStrHandle(arcfile);
     434        ok = ok && pDItem->hstrContainerName;
     435        pDItem->hstrSourceName = DrgAddStrHandle(szFile);
     436        ok = ok && pDItem->hstrSourceName;
     437        pDItem->hstrTargetName = DrgAddStrHandle(szFile);
     438        ok = ok && pDItem->hstrTargetName;
     439        if (!ok) {
     440          DbgMsg(pszSrcFile, __LINE__, "DrgAddStrHandle failed at %lu for %s", ulNumfiles, szFile);
     441          if (pDItem->hstrType)
     442            DrgDeleteStrHandle(pDItem->hstrType);
     443          if (pDItem->hstrRMF)
     444            DrgDeleteStrHandle(pDItem->hstrRMF);
     445          if (pDItem->hstrContainerName)
     446            DrgDeleteStrHandle(pDItem->hstrContainerName);
     447          if (pDItem->hstrSourceName)
     448            DrgDeleteStrHandle(pDItem->hstrSourceName);
     449          if (pDItem->hstrTargetName)
     450            DrgDeleteStrHandle(pDItem->hstrTargetName);
     451          xfree(pDItem);
     452          // pDItem = NULL;             // Why bother - fixme to be gone?
     453          NumItemsToUnhilite = ulNumfiles + 1;
     454          break;
     455        }
     456        pDItem->fsControl = 0;
    352457        if (IsFullName(arcfile) &&
    353458            (driveflags[toupper(*arcfile) - 'A'] & DRIVE_REMOVABLE))
    354           ppDItem[ulNumfiles]->fsControl |= DC_REMOVEABLEMEDIA;
    355         ppDItem[ulNumfiles]->fsSupportedOps = DO_COPYABLE;
     459          pDItem->fsControl |= DC_REMOVEABLEMEDIA;
     460        pDItem->fsSupportedOps = DO_COPYABLE;
    356461        ulNumfiles++;
    357         ppDItem[ulNumfiles] = xmalloc(sizeof(DRAGITEM), pszSrcFile, __LINE__);
    358         if (ppDItem[ulNumfiles]) {
    359           diFakeIcon.hImage = hptrFile;
    360           memset(ppDItem[ulNumfiles], 0, sizeof(DRAGITEM));
    361           ppDItem[ulNumfiles]->hwndItem = (hwndObj) ? hwndObj : hwndCnr;        /* Initialize DRAGITEM   */
    362           ppDItem[ulNumfiles]->hwndItem = hwndCnr;
    363           ppDItem[ulNumfiles]->ulItemID = Select++;
    364           ppDItem[ulNumfiles]->hstrType = DrgAddStrHandle(DRT_UNKNOWN);
    365           ppDItem[ulNumfiles]->hstrRMF = DrgAddStrHandle(DRMDRFFM2ARC);
    366           ppDItem[ulNumfiles]->hstrContainerName = DrgAddStrHandle(arcfile);
    367           ppDItem[ulNumfiles]->hstrSourceName = DrgAddStrHandle(szFile);
    368           if (!ppDItem[ulNumfiles]->hstrSourceName){
    369             DrgDeleteStrHandle(ppDItem[ulNumfiles]->hstrType);
    370             DrgDeleteStrHandle(ppDItem[ulNumfiles]->hstrRMF);
    371             DrgDeleteStrHandle(ppDItem[ulNumfiles]->hstrContainerName);
    372             DrgDeleteStrHandle(ppDItem[ulNumfiles]->hstrSourceName);
    373             xfree(ppDItem[ulNumfiles]);
    374             fExceedPMDrgLimit = ulNumfiles - 1;
    375             break;
    376         }
    377           ppDItem[ulNumfiles]->hstrTargetName = DrgAddStrHandle(szFile);
    378           ppDItem[ulNumfiles]->fsControl = 0;
    379           if (IsFullName(arcfile) &&
    380               (driveflags[toupper(*arcfile) - 'A'] & DRIVE_REMOVABLE))
    381             ppDItem[ulNumfiles]->fsControl |= DC_REMOVEABLEMEDIA;
    382           ppDItem[ulNumfiles]->fsSupportedOps = DO_COPYABLE;
    383      //if (ulNumfiles >= 1000){
    384        // pDInfo = DrgAllocDraginfo(ulNumfiles);
    385        // fexceedpmdrglimit = TRUE;
    386        // goto Thatsall;
    387        //   }
    388           ulNumfiles++;
    389         }
    390         ppDItem[ulNumfiles] = NULL;
    391       }
     462      }
     463      // ppDItem[ulNumfiles] = NULL;    // Why bother - fixme to be gone?
    392464    }
    393465    WinSendMsg(hwndCnr, CM_SETRECORDEMPHASIS, MPFROMP(pci),
     
    400472    pci = WinSendMsg(hwndCnr, CM_QUERYRECORDEMPHASIS, MPFROMP(pci),
    401473                     MPFROMSHORT(attribute));
    402   }                                     // while
    403   if (fExceedPMDrgLimit)
    404     ulNumfiles = ulNumfiles - 1;
     474  } // while
     475
    405476  if (ulNumfiles) {
    406     pDInfo = DrgAllocDraginfo(ulNumfiles);      /* Allocate DRAGINFO */
     477    pDInfo = DrgAllocDraginfo(ulNumfiles);
    407478    if (pDInfo) {
    408479      if ((arcfile && *arcfile) || (IsFullName(szBuffer) &&
     
    416487      pDInfo->hwndSource = (hwndObj) ? hwndObj : hwndCnr;
    417488      // pDInfo->hwndSource = hwndCnr;
    418       for (Select = 0L; Select < ulNumfiles; Select++) {
    419         DrgSetDragitem(pDInfo,          /* Set item in DRAGINFO  */
    420                        ppDItem[Select], /* Pointer to DRAGITEM   */
    421                        sizeof(DRAGITEM),        /* Size of DRAGITEM      */
    422                        Select);         /* Index of DRAGITEM     */
    423         xfree(ppDItem[Select]);
     489      for (ulSelect = 0; ulSelect < ulNumfiles; ulSelect++) {
     490        DrgSetDragitem(pDInfo, ppDItem[ulSelect], sizeof(DRAGITEM), ulSelect);
     491        xfree(ppDItem[ulSelect]);
    424492      }
    425493#ifdef __DEBUG_ALLOC__
     
    427495#endif
    428496      xfree(ppDItem);
    429       ppDItem = NULL;
     497      ppDItem = NULL;                   // Remember gone
    430498      DosPostEventSem(CompactSem);
    431499
    432500      if (arcfile) {
    433         diFakeIcon.cb = sizeof(DRAGIMAGE);
    434         diFakeIcon.cptl = 0;
     501        dimgFakeIcon.cb = sizeof(DRAGIMAGE);
     502        dimgFakeIcon.cptl = 0;
    435503        if (ulNumfiles > 1)
    436           diFakeIcon.hImage = hptrFile;
    437         diFakeIcon.fl = DRG_ICON;
    438         diFakeIcon.sizlStretch.cx = 32;
    439         diFakeIcon.sizlStretch.cy = 32;
    440         diFakeIcon.cxOffset = -16;
    441         diFakeIcon.cyOffset = 0;
    442         padiIcon = &diFakeIcon;
     504          dimgFakeIcon.hImage = hptrFile;
     505        dimgFakeIcon.fl = DRG_ICON;
     506        dimgFakeIcon.sizlStretch.cx = 32;
     507        dimgFakeIcon.sizlStretch.cy = 32;
     508        dimgFakeIcon.cxOffset = -16;
     509        dimgFakeIcon.cyOffset = 0;
     510        paDImgIcons = &dimgFakeIcon;
    443511      }
    444512      if (!arcfile) {
     
    447515      }
    448516      else
    449         ulNumIcon = 1L;
     517        ulNumIcon = 1;
    450518
    451519      WinSetFocus(HWND_DESKTOP, HWND_DESKTOP);
    452       hDrop = DrgDrag(hwndCnr,          /* Initiate drag         */
    453                       pDInfo,           /* DRAGINFO structure    */
    454                       padiIcon, ulNumIcon, VK_ENDDRAG,  /* End of drag indicator */
    455                       (PVOID) NULL);    /* Reserved              */
    456       rc = DeleteDragitemStrHandles(pDInfo);
    457       if (!rc)
    458           Win_Error(HWND_DESKTOP, HWND_DESKTOP, pszSrcFile, __LINE__,
    459                     "DeleteDragistr");
    460       DrgDeleteDraginfoStrHandles (pDInfo);
    461       rc = DrgFreeDraginfo(pDInfo);             /* Free DRAGINFO struct  */
    462       if (!rc)
    463       Win_Error(HWND_DESKTOP, HWND_DESKTOP, pszSrcFile, __LINE__,
    464                 "DrgFreeDraginfo");
    465       if (padiIcon && padiIcon != &diFakeIcon)
    466         xfree(padiIcon);
    467       padiIcon = NULL;
     520      hDrop = DrgDrag(hwndCnr,
     521                      pDInfo,
     522                      paDImgIcons,
     523                      ulNumIcon,
     524                      VK_ENDDRAG,       // Drag end button
     525                      NULL);
    468526      WinSetWindowPos(hwndCnr, HWND_TOP, 0, 0, 0, 0, SWP_ACTIVATE);
    469       DosPostEventSem(CompactSem);
    470527    }
    471528  }
     529
     530  if (hDrop == NULLHANDLE ) {
     531    NumItemsToUnhilite = 0;
     532    if (pDInfo)
     533      FreeDragInfoData(hwndCnr, pDInfo);
     534  }
     535
    472536  if (ppDItem)
    473537    xfree(ppDItem);
    474   if (padiIcon && padiIcon != &diFakeIcon)
    475     xfree(padiIcon);
     538  if (paDImgIcons && paDImgIcons != &dimgFakeIcon)
     539    xfree(paDImgIcons);
     540  DosPostEventSem(CompactSem);
    476541  MarkAll(hwndCnr, TRUE, FALSE, TRUE);
    477542  return hDrop;
     
    480545HWND DragList(HWND hwnd, HWND hwndObj, CHAR ** list, BOOL moveok)
    481546{
    482 
    483   /* drag a linked list of files */
     547  // Drag a linked list of files
    484548
    485549  BOOL isdir;
    486550  register CHAR *p;
    487551  PDRAGINFO pDInfo = NULL;
    488   DRAGITEM **ppDItem = NULL, **ppTest;
     552  DRAGITEM **ppDItem = NULL, **ppDITest;
     553  DRAGITEM *pDItem;
    489554  HWND hDrop = (HWND) 0;
    490   register ULONG ulNumfiles = 0L, numdragalloc = 0L, Select, ulNumIcon = 0;
     555  ULONG ulNumfiles = 0, ulNumDIAlloc = 0, ulSelect, ulNumIcon = 0;
    491556  CHAR szFile[CCHMAXPATH], szBuffer[CCHMAXPATH];
    492   DRAGIMAGE *padiIcon = NULL, *padiTest;
     557  DRAGIMAGE *paDImgIcons = NULL, *pDImg;
    493558  FILESTATUS3 fs3;
     559  BOOL ok;
    494560
    495561  if (!list || !list[0])
    496562    return hDrop;
    497   for (Select = 0; list[Select]; Select++) {
    498     if ((!IsRoot(list[Select]) || !IsValidDrive(*list[Select])) &&
    499         DosQueryPathInfo(list[Select], FIL_STANDARD, &fs3, sizeof(fs3)))
     563  for (ulSelect = 0; list[ulSelect]; ulSelect++) {
     564    if ((!IsRoot(list[ulSelect]) || !IsValidDrive(*list[ulSelect])) &&
     565        DosQueryPathInfo(list[ulSelect], FIL_STANDARD, &fs3, sizeof(fs3)))
    500566      continue;
    501     strcpy(szBuffer, list[Select]);
     567    strcpy(szBuffer, list[ulSelect]);
    502568    p = strrchr(szBuffer, '\\');
    503569    if (p) {
     
    509575      continue;
    510576    if (*szFile) {
    511       isdir = (IsRoot(list[Select])) ? TRUE :
    512         ((fs3.attrFile & FILE_DIRECTORY) != 0);
    513       if (ulNumfiles + 2L > numdragalloc) {
    514         if (!padiIcon) {
    515           padiTest =
    516             xrealloc(padiIcon, sizeof(DRAGIMAGE) * (numdragalloc + 4L),
     577      isdir = IsRoot(list[ulSelect]) || fs3.attrFile & FILE_DIRECTORY;
     578      // fixme to expand smarter - expand fast at first - do same for similar code
     579      if (ulNumfiles + 2 > ulNumDIAlloc) {
     580        if (!paDImgIcons) {
     581          pDImg =
     582            xrealloc(paDImgIcons, sizeof(DRAGIMAGE) * (ulNumDIAlloc + 4L),
    517583                     pszSrcFile, __LINE__);
    518           if (!padiTest)
     584          if (!pDImg)
    519585            break;
    520           else
    521             padiIcon = padiTest;
     586          paDImgIcons = pDImg;
    522587        }
    523588        else if (!ulNumIcon) {
    524           padiIcon[ulNumfiles].cb = sizeof(DRAGIMAGE);
    525           padiIcon[ulNumfiles].cptl = 0;
    526           padiIcon[ulNumfiles].hImage = hptrLast;
    527           padiIcon[ulNumfiles].fl = DRG_ICON;
    528           padiIcon[ulNumfiles].sizlStretch.cx = 32;
    529           padiIcon[ulNumfiles].sizlStretch.cy = 32;
    530           padiIcon[ulNumfiles].cxOffset = -16 + (ulNumfiles * 4);
    531           padiIcon[ulNumfiles].cyOffset = 0 + (ulNumfiles * 7);
     589          pDImg = &paDImgIcons[ulNumfiles];
     590          pDImg->cb = sizeof(DRAGIMAGE);
     591          pDImg->cptl = 0;
     592          pDImg->hImage = hptrLast;
     593          pDImg->fl = DRG_ICON;
     594          pDImg->sizlStretch.cx = 32;
     595          pDImg->sizlStretch.cy = 32;
     596          pDImg->cxOffset = -16 + (ulNumfiles * 4);
     597          pDImg->cyOffset = 0 + (ulNumfiles * 7);
    532598          ulNumIcon = ulNumfiles + 1;
    533599        }
    534         ppTest =
    535           xrealloc(ppDItem, sizeof(DRAGITEM *) * (numdragalloc + 4L),
     600        ppDITest =
     601          xrealloc(ppDItem, sizeof(DRAGITEM *) * (ulNumDIAlloc + 4L),
    536602                   pszSrcFile, __LINE__);
    537         if (!ppTest)
     603        if (!ppDITest)
    538604          break;
    539         else {
    540           ppDItem = ppTest;
    541           numdragalloc += 4L;
    542         }
    543       }
    544       ppDItem[ulNumfiles] = xmalloc(sizeof(DRAGITEM), pszSrcFile, __LINE__);
    545       if (!ppDItem[ulNumfiles])
     605        ppDItem = ppDITest;
     606        ulNumDIAlloc += 4L;
     607      }
     608      pDItem = xmalloc(sizeof(DRAGITEM), pszSrcFile, __LINE__);
     609      if (!pDItem)
    546610        break;
    547       else {
    548         if (!ulNumIcon) {
    549           padiIcon[ulNumfiles].cb = sizeof(DRAGIMAGE);
    550           padiIcon[ulNumfiles].cptl = 0;
    551           padiIcon[ulNumfiles].hImage = (isdir) ? hptrDir : hptrFile;
    552           padiIcon[ulNumfiles].fl = DRG_ICON;
    553           padiIcon[ulNumfiles].sizlStretch.cx = 32;
    554           padiIcon[ulNumfiles].sizlStretch.cy = 32;
    555           padiIcon[ulNumfiles].cxOffset = -16 + (ulNumfiles * 3);
    556           padiIcon[ulNumfiles].cyOffset = 0 + (ulNumfiles * 6);
    557         }
    558         memset(ppDItem[ulNumfiles], 0, sizeof(DRAGITEM));
    559         ppDItem[ulNumfiles]->hwndItem = (hwndObj) ? hwndObj : hwnd;     /* Initialize DRAGITEM */
    560         // ppDItem[ulNumfiles]->hwndItem = hwnd;
    561         ppDItem[ulNumfiles]->ulItemID = (ULONG) Select;
    562         ppDItem[ulNumfiles]->hstrType = DrgAddStrHandle(DRT_UNKNOWN);
    563         ppDItem[ulNumfiles]->hstrRMF = DrgAddStrHandle(DRMDRFLIST);
    564         ppDItem[ulNumfiles]->hstrContainerName = DrgAddStrHandle(szBuffer);
    565         ppDItem[ulNumfiles]->hstrSourceName = DrgAddStrHandle(szFile);
    566         if (!ppDItem[ulNumfiles]->hstrSourceName){
    567             DrgDeleteStrHandle(ppDItem[ulNumfiles]->hstrType);
    568             DrgDeleteStrHandle(ppDItem[ulNumfiles]->hstrRMF);
    569             DrgDeleteStrHandle(ppDItem[ulNumfiles]->hstrContainerName);
    570             DrgDeleteStrHandle(ppDItem[ulNumfiles]->hstrSourceName);
    571             xfree(ppDItem[ulNumfiles]);
    572             fExceedPMDrgLimit = ulNumfiles - 1;
    573             break;
    574         }
    575         ppDItem[ulNumfiles]->hstrTargetName = DrgAddStrHandle(szFile);
    576         ppDItem[ulNumfiles]->fsControl = (isdir) ? DC_CONTAINER : 0;
    577         if (IsFullName(list[Select]) &&
    578             (driveflags[toupper(*list[Select]) - 'A'] & DRIVE_REMOVABLE))
    579           ppDItem[ulNumfiles]->fsControl |= DC_REMOVEABLEMEDIA;
    580         ppDItem[ulNumfiles]->fsSupportedOps = DO_COPYABLE | DO_LINKABLE;
    581         if (moveok && IsFullName(list[Select]) &&
    582             !(driveflags[toupper(*list[Select]) - 'A'] & DRIVE_NOTWRITEABLE))
    583           ppDItem[ulNumfiles]->fsSupportedOps |= DO_MOVEABLE;
    584         if (IsRoot(list[Select]))
    585           ppDItem[ulNumfiles]->fsControl = DO_LINKABLE;
    586         ulNumfiles++;
    587         ppDItem[ulNumfiles] = NULL;
    588       }
    589     }
    590   }                                     // for
    591   if (fExceedPMDrgLimit)
    592     ulNumfiles = ulNumfiles - 1;
     611      ppDItem[ulNumfiles] = pDItem;
     612      if (!ulNumIcon) {
     613        pDImg = &paDImgIcons[ulNumfiles];
     614        pDImg->cb = sizeof(DRAGIMAGE);
     615        pDImg->cptl = 0;
     616        pDImg->hImage = isdir ? hptrDir : hptrFile;
     617        pDImg->fl = DRG_ICON;
     618        pDImg->sizlStretch.cx = 32;
     619        pDImg->sizlStretch.cy = 32;
     620        pDImg->cxOffset = -16 + (ulNumfiles * 3);
     621        pDImg->cyOffset = 0 + (ulNumfiles * 6);
     622      }
     623      memset(pDItem, 0, sizeof(DRAGITEM));
     624      pDItem->hwndItem = (hwndObj) ? hwndObj : hwnd;
     625      // pDItem->hwndItem = hwnd;
     626      pDItem->ulItemID = (ULONG) ulSelect;
     627      pDItem->hstrType = DrgAddStrHandle(DRT_UNKNOWN);
     628      ok = pDItem->hstrType;
     629      pDItem->hstrRMF = DrgAddStrHandle(DRMDRFLIST);
     630      ok = ok && pDItem->hstrRMF;
     631      pDItem->hstrContainerName = DrgAddStrHandle(szBuffer);
     632      ok = ok && pDItem->hstrContainerName;
     633      pDItem->hstrSourceName = DrgAddStrHandle(szFile);
     634      ok = ok && pDItem->hstrSourceName;
     635      pDItem->hstrTargetName = DrgAddStrHandle(szFile);
     636      ok = ok && pDItem->hstrTargetName;
     637      if (!ok) {
     638        if (pDItem->hstrType)
     639          DrgDeleteStrHandle(pDItem->hstrType);
     640        if (pDItem->hstrRMF)
     641          DrgDeleteStrHandle(pDItem->hstrRMF);
     642        if (pDItem->hstrContainerName)
     643          DrgDeleteStrHandle(pDItem->hstrContainerName);
     644        if (pDItem->hstrSourceName)
     645          DrgDeleteStrHandle(pDItem->hstrSourceName);
     646        if (pDItem->hstrTargetName)
     647          DrgDeleteStrHandle(pDItem->hstrTargetName);
     648        xfree(pDItem);
     649        // pDItem = NULL;       // Why bother, we can count - fixme to be gone
     650        NumItemsToUnhilite = ulNumfiles + 1;
     651        break;
     652      }
     653      pDItem->fsControl = isdir ? DC_CONTAINER : 0;
     654      if (IsFullName(list[ulSelect]) &&
     655          (driveflags[toupper(*list[ulSelect]) - 'A'] & DRIVE_REMOVABLE))
     656        pDItem->fsControl |= DC_REMOVEABLEMEDIA;
     657      pDItem->fsSupportedOps = DO_COPYABLE | DO_LINKABLE;
     658      if (moveok && IsFullName(list[ulSelect]) &&
     659          !(driveflags[toupper(*list[ulSelect]) - 'A'] & DRIVE_NOTWRITEABLE))
     660        pDItem->fsSupportedOps |= DO_MOVEABLE;
     661      if (IsRoot(list[ulSelect]))
     662        pDItem->fsControl = DO_LINKABLE;
     663      ulNumfiles++;
     664      // ppDItem[ulNumfiles] = NULL;    // Why bother - fixme to be gone
     665    }
     666  } // for
    593667  if (ulNumfiles) {
    594     pDInfo = DrgAllocDraginfo(ulNumfiles);      /* Allocate DRAGINFO */
     668    pDInfo = DrgAllocDraginfo(ulNumfiles);
    595669    if (pDInfo) {
    596670      if ((IsFullName(szBuffer) &&
     
    601675      if (IsRoot(list[0]))
    602676        pDInfo->usOperation = DO_LINK;
    603       pDInfo->hwndSource = (hwndObj) ? hwndObj : hwnd;
     677      pDInfo->hwndSource = hwndObj ? hwndObj : hwnd;
    604678      // pDInfo->hwndSource = hwnd;
    605       for (Select = 0L; Select < ulNumfiles; Select++) {
    606         DrgSetDragitem(pDInfo,          /* Set item in DRAGINFO  */
    607                        ppDItem[Select], /* Pointer to DRAGITEM   */
    608                        sizeof(DRAGITEM),        /* Size of DRAGITEM      */
    609                        Select);         /* Index of DRAGITEM     */
    610         free(ppDItem[Select]);
    611       }                                 // for
     679      for (ulSelect = 0; ulSelect < ulNumfiles; ulSelect++) {
     680        if (!DrgSetDragitem(pDInfo, ppDItem[ulSelect], sizeof(DRAGITEM), ulSelect)) {
     681          Win_Error(HWND_DESKTOP, HWND_DESKTOP, pszSrcFile, __LINE__,
     682                   "DrgSetDragitem");
     683        }
     684        free(ppDItem[ulSelect]);
     685      } // for
    612686#ifdef __DEBUG_ALLOC__
    613687      _heap_check();
    614688#endif
    615689      free(ppDItem);
    616       ppDItem = NULL;
     690      ppDItem = NULL;                   // Remember gone
    617691      DosPostEventSem(CompactSem);
    618692
     
    621695
    622696      WinSetFocus(HWND_DESKTOP, HWND_DESKTOP);
    623       hDrop = DrgDrag(hwnd,             /* Initiate drag         */
    624                       pDInfo,           /* DRAGINFO structure    */
    625                       padiIcon, ulNumIcon, VK_ENDDRAG,  /* End of drag indicator */
    626                       (PVOID) NULL);    /* Reserved              */
    627       if (!DeleteDragitemStrHandles(pDInfo))
    628         Win_Error(HWND_DESKTOP, HWND_DESKTOP, pszSrcFile, __LINE__,
    629                   "DeleteDragistr");
    630       DrgDeleteDraginfoStrHandles (pDInfo);
    631       if (!DrgFreeDraginfo(pDInfo));            /* Free DRAGINFO struct  */
    632         Win_Error(HWND_DESKTOP, HWND_DESKTOP, pszSrcFile, __LINE__,
    633                   "DrgFreeDraginfo");
    634       xfree(padiIcon);
    635       padiIcon = NULL;
     697      hDrop = DrgDrag(hwnd,
     698                      pDInfo,
     699                      paDImgIcons,
     700                      ulNumIcon,
     701                      VK_ENDDRAG,       // Drag end button
     702                      (PVOID) NULL);
     703      if (hDrop == NULLHANDLE) {
     704        NumItemsToUnhilite = 0;
     705        FreeDragInfoData(hwnd, pDInfo);
     706      }
     707      xfree(paDImgIcons);
     708      paDImgIcons = NULL;               // Remember gone
    636709      WinSetWindowPos(hwnd, HWND_TOP, 0, 0, 0, 0, SWP_ACTIVATE);
    637710      DosPostEventSem(CompactSem);
     
    640713  if (ppDItem)
    641714    free(ppDItem);
    642   if (padiIcon)
    643     free(padiIcon);
     715  if (paDImgIcons)
     716    free(paDImgIcons);
    644717  return hDrop;
    645718}
    646719
    647 #ifdef NEVER
     720#ifdef NEVER                            // fixme to be enabled someday?
    648721
    649722BOOL PickUp(HWND hwndCnr, HWND hwndObj, PCNRDRAGINIT pcd)
     
    655728  ULONG cditem = 0;
    656729  DRAGITEM ditem;
    657   DRAGIMAGE diFakeIcon;
     730  DRAGIMAGE dimgFakeIcon;
    658731  CHAR szDir[CCHMAXPATH], szFile[CCHMAXPATH], *p;
    659732
     
    702775        ditem.hstrContainerName = DrgAddStrHandle(szDir);
    703776        ditem.hstrSourceName = DrgAddStrHandle(szFile);
    704         if (!ditem.hstrSourceName)
    705         Win_Error(HWND_DESKTOP, HWND_DESKTOP, pszSrcFile, __LINE__,
    706                  "DrgAddStrHandle");
     777        // fixme to check better if code ever enabled
     778        if (!ditem.hstrSourceName) {
     779          Win_Error(HWND_DESKTOP, HWND_DESKTOP, pszSrcFile, __LINE__,
     780                   "DrgAddStrHandle");
     781        }
    707782        ditem.hstrTargetName = DrgAddStrHandle(szFile);
    708783        ditem.fsControl = 0;
     
    719794        if (IsRoot(pci->szFileName))
    720795          ditem.fsSupportedOps = DO_LINKABLE;
    721         memset(&diFakeIcon, 0, sizeof(DRAGIMAGE));
    722         diFakeIcon.hImage = pci->rc.hptrIcon;
    723         diFakeIcon.cb = sizeof(DRAGIMAGE);
    724         diFakeIcon.cptl = 0;
    725         diFakeIcon.fl = DRG_ICON;
    726         diFakeIcon.sizlStretch.cx = 32;
    727         diFakeIcon.sizlStretch.cy = 32;
    728         diFakeIcon.cxOffset = -16;
    729         diFakeIcon.cyOffset = 0;
     796        memset(&dimgFakeIcon, 0, sizeof(DRAGIMAGE));
     797        dimgFakeIcon.hImage = pci->rc.hptrIcon;
     798        dimgFakeIcon.cb = sizeof(DRAGIMAGE);
     799        dimgFakeIcon.cptl = 0;
     800        dimgFakeIcon.fl = DRG_ICON;
     801        dimgFakeIcon.sizlStretch.cx = 32;
     802        dimgFakeIcon.sizlStretch.cy = 32;
     803        dimgFakeIcon.cxOffset = -16;
     804        dimgFakeIcon.cyOffset = 0;
    730805        if (IsFullName(pci->szFileName) &&
    731806            (driveflags[toupper(*pci->szFileName) - 'A'] &
     
    743818      pci = WinSendMsg(hwndCnr, CM_QUERYRECORDEMPHASIS,
    744819                       MPFROMP(pci), MPFROMSHORT(CRA_SELECTED));
    745     }
     820    } // while
    746821    if (pdinfoCurrent)
    747       return DrgLazyDrag(hwndCnr, pdinfoCurrent, &diFakeIcon, 1, NULL);
     822      return DrgLazyDrag(hwndCnr, pdinfoCurrent, &dimgFakeIcon, 1, NULL);
    748823  }
    749824  return FALSE;
  • trunk/dll/droplist.c

    r603 r618  
    1515  06 Apr 07 GKY Work around PM DragInfo and DrgFreeDISH limits
    1616  06 Apr 07 GKY Add some error checking in drag/drop
     17  19 Apr 07 SHL Use FreeDragInfoData
     18  19 Apr 07 SHL Add more drag/drop error checking
    1719
    1820***********************************************************************/
     
    3133
    3234static PSZ pszSrcFile = __FILE__;
     35
     36static ULONG GetDropCount(HWND hwnd, MPARAM mp1);
    3337
    3438#pragma alloc_text(DROPLIST,DoFileDrop,FullDrgName,TwoDrgNames,GetOneDrop)
     
    102106    blen = DrgQueryStrName(pDItem->hstrContainerName, buflen, buffer);
    103107    if(!blen)
    104         Win_Error(HWND_DESKTOP, HWND_DESKTOP, pszSrcFile, __LINE__,
     108        Win_Error(HWND_DESKTOP, HWND_DESKTOP, pszSrcFile, __LINE__,
    105109              "DrgQueryStrName");
    106110    else {
     
    112116    buffer[blen] = 0;
    113117    len = DrgQueryStrName(pDItem->hstrSourceName,
    114                           buflen - blen, buffer + blen);
    115     if(!len)
    116        // printf("%s %d\n %s\n %d %X\n", pszSrcFile, __LINE__,  pDItem->hstrSourceName,
    117         //                  buflen - blen, buffer + blen); fflush(stdout);
    118        // Win_Error(HWND_DESKTOP, HWND_DESKTOP, pszSrcFile, __LINE__,
    119          //         "DrgQueryStrName");
     118                          buflen - blen, buffer + blen);
     119    if(!len) {
     120      // DbgMsg(pszSrcFile, __LINE__, "0x%x %d %d", pDItem->hstrSourceName,
     121      //           buflen - blen, buffer + blen);
     122      // Win_Error(HWND_DESKTOP, HWND_DESKTOP, pszSrcFile, __LINE__,
     123      //         "DrgQueryStrName");
     124    }
    120125    buffer[blen + len] = 0;
    121126    {                                   /* be sure we get full pathname of file/directory */
     
    125130      if (!rc) {
    126131        strncpy(buffer, szTemp, buflen);
    127         buffer[buflen - 1] = 0;
     132        buffer[buflen - 1] = 0;
    128133      }
    129134      else
     
    132137    }
    133138    {                                   /* be sure that file/directory is accessible */
    134         FILESTATUS3 fsa3;
     139        FILESTATUS3 fsa3;
    135140
    136141      rc = DosQueryPathInfo(buffer, FIL_STANDARD, &fsa3, sizeof(fsa3));
     
    138143        ret = TRUE;
    139144      else {
    140           Dos_Error(MB_CANCEL, rc, HWND_DESKTOP, pszSrcFile, __LINE__,
    141                     "DosQueryPathInfo");
    142           *buffer = 0;
     145          Dos_Error(MB_CANCEL, rc, HWND_DESKTOP, pszSrcFile, __LINE__,
     146                    "DosQueryPathInfo");
     147          *buffer = 0;
    143148      }
    144149    }
     
    147152}
    148153
    149 BOOL GetOneDrop(MPARAM mp1, MPARAM mp2, char *buffer, ULONG buflen)
    150 {
    151   PDRAGITEM pDItem;             /* DRAGITEM struct ptr  */
    152   PDRAGINFO pDInfo;             /* DRAGINFO struct ptr  */
     154BOOL GetOneDrop(HWND hwnd, MPARAM mp1, MPARAM mp2, char *buffer, ULONG buflen)
     155{
     156  PDRAGITEM pDItem;                     /* DRAGITEM struct ptr */
     157  PDRAGINFO pDInfo;                     /* DRAGINFO struct ptr */
    153158  ULONG numitems;
    154   register ULONG x;
     159  register ULONG curitem;
    155160  BOOL ret = FALSE;
    156   APIRET rc;
    157161
    158162  if (buffer && buflen)
    159     *buffer = 0;                        /* zero buffer field     */
    160 
    161   pDInfo = (PDRAGINFO) mp1;             /* Get DRAGINFO pointer  */
     163    *buffer = 0;                        /* zero buffer field */
     164
     165  pDInfo = (PDRAGINFO) mp1;             /* Get DRAGINFO pointer */
    162166  if (pDInfo) {
    163     DrgAccessDraginfo(pDInfo);          /* Access DRAGINFO       */
    164     numitems = DrgQueryDragitemCount(pDInfo);
    165     pDItem = DrgQueryDragitemPtr(pDInfo,        /* Access DRAGITEM       */
    166                                  0);    /* Index to DRAGITEM     */
    167     if (buflen && buffer) {
    168       if (DrgVerifyRMF(pDItem,          /* Check valid rendering */
    169                        DRM_OS2FILE,     /* mechanisms and data   */
    170                        NULL) && !(pDItem->fsControl & DC_PREPARE))
    171         ret = FullDrgName(pDItem, buffer, buflen);
    172     }
    173     /* note:  targetfail is returned to source for all items */
    174     for (x = 0; x < numitems; x++) {
    175       pDItem = DrgQueryDragitemPtr(pDInfo,      /* Access DRAGITEM   */
    176                                    x);  /* Index to DRAGITEM */
    177       DrgSendTransferMsg(pDInfo->hwndSource, DM_ENDCONVERSATION,
    178                          MPFROMLONG(pDItem->ulItemID),
    179                          MPFROMLONG(DMFL_TARGETFAIL));
    180     }
    181     rc = DeleteDragitemStrHandles(pDInfo); //
    182     if(!rc)
    183         Win_Error(HWND_DESKTOP, HWND_DESKTOP, pszSrcFile, __LINE__,
    184                   "DeleteDragitemStrHandles");
    185     DrgDeleteDraginfoStrHandles (pDInfo);
    186     rc = DrgFreeDraginfo(pDInfo);               /* Free DRAGINFO */
    187     if(!rc)
    188           Win_Error(HWND_DESKTOP, HWND_DESKTOP, pszSrcFile, __LINE__,
    189                  "DrgFreeDraginfo");
     167    if (!DrgAccessDraginfo(pDInfo)) {
     168      Win_Error(HWND_DESKTOP, HWND_DESKTOP, pszSrcFile, __LINE__,
     169                "DrgAccessDraginfo");
     170    }
     171    else {
     172      numitems = DrgQueryDragitemCount(pDInfo);
     173      pDItem = DrgQueryDragitemPtr(pDInfo,0);
     174      if (buflen && buffer) {
     175        if (DrgVerifyRMF(pDItem,        /* Check valid rendering */
     176                         DRM_OS2FILE,   /* mechanisms and data */
     177                         NULL) && !(pDItem->fsControl & DC_PREPARE))
     178          ret = FullDrgName(pDItem, buffer, buflen);
     179      }
     180      // Return targetfail to source for all items - fixme to know why
     181      for (curitem = 0; curitem < numitems; curitem++) {
     182        pDItem = DrgQueryDragitemPtr(pDInfo,curitem);
     183        DrgSendTransferMsg(pDInfo->hwndSource, DM_ENDCONVERSATION,
     184                           MPFROMLONG(pDItem->ulItemID),
     185                           MPFROMLONG(DMFL_TARGETFAIL));
     186      }
     187      FreeDragInfoData(hwnd, pDInfo);
     188    }
    190189  }
    191190
     
    193192}
    194193
    195 BOOL AcceptOneDrop(MPARAM mp1, MPARAM mp2)
    196 {
    197   PDRAGITEM pDItem;             /* Pointer to DRAGITEM  */
    198   PDRAGINFO pDInfo;             /* Pointer to DRAGINFO  */
     194BOOL AcceptOneDrop(HWND hwnd, MPARAM mp1, MPARAM mp2)
     195{
     196  PDRAGITEM pDItem;                     /* Pointer to DRAGITEM */
     197  PDRAGINFO pDInfo;                     /* Pointer to DRAGINFO */
    199198  BOOL ret = FALSE;
    200   APIRET rc;
    201 
    202   pDInfo = (PDRAGINFO) mp1;             /* Get DRAGINFO pointer  */
     199
     200  pDInfo = (PDRAGINFO) mp1;             /* Get DRAGINFO pointer */
    203201  if (pDInfo) {
    204     DrgAccessDraginfo(pDInfo);          /* Access DRAGINFO       */
    205     pDItem = DrgQueryDragitemPtr(pDInfo,        /* Access DRAGITEM       */
    206                                  0);    /* Index to DRAGITEM     */
    207     if (DrgVerifyRMF(pDItem,            /* Check valid rendering */
    208                      DRM_OS2FILE,       /* mechanisms and data   */
    209                      NULL))             /* formats               */
    210       ret = TRUE;
    211     rc = DeleteDragitemStrHandles(pDInfo); //
    212     if(!rc)
    213          Win_Error(HWND_DESKTOP, HWND_DESKTOP, pszSrcFile, __LINE__,
    214                    "DeleteDragitemStrHandles");
    215     DrgDeleteDraginfoStrHandles(pDInfo);
    216     rc = DrgFreeDraginfo(pDInfo);
    217     if(!rc)
    218           Win_Error(HWND_DESKTOP, HWND_DESKTOP, pszSrcFile, __LINE__,
    219                  "DrgFreeDraginfo");
     202    if (!DrgAccessDraginfo(pDInfo)) {
     203      Win_Error(HWND_DESKTOP, HWND_DESKTOP, pszSrcFile, __LINE__,
     204                "DrgAccessDraginfo");
     205    }
     206    else {
     207      pDItem = DrgQueryDragitemPtr(pDInfo, 0);
     208
     209      /* Check valid rendering mechanisms and data formats */
     210      if (DrgVerifyRMF(pDItem, DRM_OS2FILE, NULL))
     211        ret = TRUE;
     212
     213      // FreeDragInfoData(hwnd, pDInfo);        // 20 Apr 07 SHL
     214      DrgFreeDraginfo(pDInfo);
     215    }
    220216  }
    221217  return ret;
    222218}
    223219
    224 ULONG FreeDrop(MPARAM mp1, MPARAM mp2)
     220static ULONG GetDropCount(HWND hwnd, MPARAM mp1)
    225221{
    226222  PDRAGINFO pDInfo;
    227223  ULONG numitems;
    228   APIRET rc;
    229224
    230225  pDInfo = mp1;
    231226  if (pDInfo) {
    232     DrgAccessDraginfo(pDInfo);
    233     numitems = DrgQueryDragitemCount(pDInfo);
    234     rc = DeleteDragitemStrHandles(pDInfo); //
    235     if(!rc)
    236          Win_Error(HWND_DESKTOP, HWND_DESKTOP, pszSrcFile, __LINE__,
    237                    "DeleteDragitemStrHandles");
    238     DrgDeleteDraginfoStrHandles(pDInfo);
    239     rc = DrgFreeDraginfo(pDInfo);
    240     if(!rc)
    241           Win_Error(HWND_DESKTOP, HWND_DESKTOP, pszSrcFile, __LINE__,
    242                  "DrgFreeDraginfo");
     227    if (!DrgAccessDraginfo(pDInfo)) {
     228      Win_Error(HWND_DESKTOP, HWND_DESKTOP, pszSrcFile, __LINE__,
     229              "DrgAccessDraginfo");
     230      numitems = 0;                     // Oh well
     231    }
     232    else {
     233      numitems = DrgQueryDragitemCount(pDInfo);
     234      FreeDragInfoData(hwnd, pDInfo);
     235    }
    243236  }
    244237  return numitems;
     
    249242  ULONG numitems;
    250243
    251   numitems = FreeDrop(mp1, mp2);
     244  numitems = GetDropCount(hwnd, mp1);
    252245  saymsg(MB_ENTER | MB_ICONASTERISK,
    253246         hwnd, GetPString(IDS_FM2DROPHELPTEXT), text, numitems, numitems);
     
    265258  PCNRITEM pci;
    266259  CHAR szFrom[CCHMAXPATH + 1], szArc[CCHMAXPATH + 1];
    267   register CHAR **files = NULL;
     260  CHAR **files = NULL;
    268261  INT numfiles = 0, numalloc = 0;
    269   register ULONG curitem = 0L, numitems, *cbFile = NULL, *ulitemID = NULL;
     262  ULONG curitem, numitems, *cbFile = NULL, *ulitemID = NULL;
    270263  LISTINFO *li = NULL;
    271264  ARC_TYPE *arcinfo = NULL;
    272265  USHORT Operation;
    273   APIRET rc;
    274266
    275267  *szArc = 0;
     
    278270  if (!pDInfo)
    279271    return NULL;
    280   rc = DrgAccessDraginfo(pDInfo);
    281   if(!rc)
    282       Win_Error(HWND_DESKTOP, HWND_DESKTOP, pszSrcFile, __LINE__,
    283               "DrgAccessDraginfo");
    284   Operation = pDInfo->usOperation;
    285   pDItem = DrgQueryDragitemPtr(pDInfo, 0L);
    286   if(!pDItem)
    287       Win_Error(HWND_DESKTOP, HWND_DESKTOP, pszSrcFile, __LINE__,
    288               "DrgQueryDragitemPtr");
    289   if (Operation == DO_MOVE && !(pDItem->fsSupportedOps & DO_MOVEABLE)) {
    290     saymsg(MB_ENTER, HWND_DESKTOP, GetPString(IDS_WARNINGTEXT),
    291            GetPString(IDS_FORCINGCOPYTEXT));
    292     Operation = DO_COPY;
    293   }
    294   numitems = DrgQueryDragitemCount(pDInfo);
    295   while (curitem < numitems) {
     272  if (!DrgAccessDraginfo(pDInfo)) {
     273    Win_Error(HWND_DESKTOP, HWND_DESKTOP, pszSrcFile, __LINE__,
     274            "DrgAccessDraginfo");
     275    numitems = 0;                       // Avoid death
     276  }
     277  else {
     278    numitems = DrgQueryDragitemCount(pDInfo);
     279    Operation = pDInfo->usOperation;
     280    pDItem = DrgQueryDragitemPtr(pDInfo, 0);
     281    if (!pDItem) {
     282        Win_Error(HWND_DESKTOP, HWND_DESKTOP, pszSrcFile, __LINE__,
     283                "DrgQueryDragitemPtr");
     284    }
     285    else {
     286      if (Operation == DO_MOVE && !(pDItem->fsSupportedOps & DO_MOVEABLE)) {
     287        saymsg(MB_ENTER, HWND_DESKTOP, GetPString(IDS_WARNINGTEXT),
     288               GetPString(IDS_FORCINGCOPYTEXT));
     289        Operation = DO_COPY;
     290      }
     291    }
     292  }
     293
     294  for (curitem = 0; curitem < numitems; curitem++) {
    296295    pDItem = DrgQueryDragitemPtr(pDInfo, curitem);
    297     if (!pDItem)
     296    if (!pDItem) {
     297      Win_Error(hwndCnr, hwndCnr, pszSrcFile, __LINE__,
     298                "DrgQueryDragitemPtr(%u)", curitem);
    298299      break;
     300    }
    299301
    300302    /* ambiguous drop request -- see what's allowed */
     
    309311    else {
    310312      /* ignore object if selected command not allowed for it */
     313      BOOL ok;
    311314      switch (Operation) {
    312315      case DO_MOVE:
    313         if (pDItem->fsSupportedOps & DO_MOVEABLE)
    314           goto Okay;
     316        ok = pDItem->fsSupportedOps & DO_MOVEABLE;
    315317        break;
    316318      case DO_COPY:
    317         if (pDItem->fsSupportedOps & DO_COPYABLE)
    318           goto Okay;
     319        ok = pDItem->fsSupportedOps & DO_COPYABLE;
    319320        break;
    320321      case DO_LINK:
    321         if (pDItem->fsSupportedOps & DO_LINKABLE)
    322           goto Okay;
     322        ok = pDItem->fsSupportedOps & DO_LINKABLE;
    323323        break;
    324       }
    325       // Fail request
    326       DrgSendTransferMsg(pDItem->hwndItem,
    327                          DM_ENDCONVERSATION,
    328                          MPFROMLONG(pDItem->ulItemID),
    329                          MPFROMLONG(DMFL_TARGETFAIL));
    330       curitem++;
    331       continue;
    332     }
    333 
    334   Okay:
     324      default:
     325        ok = FALSE;
     326      }
     327      if (!ok) {
     328        // Fail request
     329        DrgSendTransferMsg(pDItem->hwndItem,
     330                           DM_ENDCONVERSATION,
     331                           MPFROMLONG(pDItem->ulItemID),
     332                           MPFROMLONG(DMFL_TARGETFAIL));
     333        continue;
     334      }
     335    }
    335336
    336337    if (DrgVerifyRMF(pDItem,
     
    346347                           MPFROMLONG(pDItem->ulItemID),
    347348                           MPFROMLONG(DMFL_TARGETFAIL));
    348         curitem++;
    349349        continue;
    350350      }
     
    375375                           MPFROMLONG(pDItem->ulItemID),
    376376                           MPFROMLONG(DMFL_TARGETFAIL));
    377         curitem++;
    378377        continue;
    379378      }
     
    388387          xrealloc(files, numalloc * sizeof(CHAR *), pszSrcFile, __LINE__);
    389388        if (!test)
    390           goto AbortDrop;
     389          break;
    391390        files = test;
    392391        ltest =
    393392          xrealloc(cbFile, numalloc * sizeof(ULONG), pszSrcFile, __LINE__);
    394393        if (!ltest)
    395           goto AbortDrop;
     394          break;
    396395        cbFile = ltest;
    397396        ltest =
    398397          xrealloc(ulitemID, numalloc * sizeof(ULONG), pszSrcFile, __LINE__);
    399398        if (!ltest)
    400           goto AbortDrop;
     399          break;
    401400        ulitemID = ltest;
    402401      }
     
    413412      files[numfiles + 1] = NULL;
    414413      if (!files[numfiles])
    415         goto AbortDrop;
     414        break;
    416415      numfiles++;
    417416      DrgSendTransferMsg(pDItem->hwndItem,
     
    425424                         MPFROMLONG(pDItem->ulItemID),
    426425                         MPFROMLONG(DMFL_TARGETFAIL));
    427     curitem++;
    428   }
    429 
    430 AbortDrop:
     426  } // for
    431427
    432428  if (files && numfiles && files[0] && cbFile && ulitemID) {
     
    466462      FreeList(files);
    467463  }
    468   rc = DeleteDragitemStrHandles(pDInfo);  //
    469   if(!rc)
    470         Win_Error(HWND_DESKTOP, HWND_DESKTOP, pszSrcFile, __LINE__,
    471                  "DeleteDragitemStrHandles");
    472   DrgDeleteDraginfoStrHandles(pDInfo);
    473   DrgFreeDraginfo(pDInfo);
     464
     465  FreeDragInfoData(hwndCnr, pDInfo);
     466
    474467  return li;
    475468}
  • trunk/dll/extract.c

    r574 r618  
    1212  20 Dec 06 GKY Added checkbox to make default extract with directories
    1313  22 Mar 07 GKY Use QWL_USER
     14  19 Apr 07 SHL Sync with AcceptOneDrop GetOneDrop mods
    1415
    1516***********************************************************************/
     
    4647      DrawTargetEmphasis(hwnd, emphasized);
    4748    }
    48     if (AcceptOneDrop(mp1, mp2))
     49    if (AcceptOneDrop(hwnd, mp1, mp2))
    4950      return MRFROM2SHORT(DOR_DROP, DO_MOVE);
    5051    return MRFROM2SHORT(DOR_NEVERDROP, 0);
     
    6970        DrawTargetEmphasis(hwnd, emphasized);
    7071      }
    71       if (GetOneDrop(mp1, mp2, szFrom, sizeof(szFrom)))
     72      if (GetOneDrop(hwnd, mp1, mp2, szFrom, sizeof(szFrom)))
    7273        WinSendMsg(WinQueryWindow(hwnd, QW_PARENT), WM_COMMAND,
    7374                   MPFROM2SHORT(IDM_SWITCH, 0), MPFROMP(szFrom));
  • trunk/dll/fm3dll.h

    r606 r618  
    4040  18 Mar 07 GKY Add MM import typedefines for fix for files misindentified as multimedia
    4141  30 Mar 07 GKY Defined golbals for removing GetPString for window class names
    42   06 Apr 07 GKY Work around PM DragInfo and DrgFreeDISH limits fExceedPMDrgLimit & DeleteDragitemStrHandles
     42  06 Apr 07 GKY Work around PM DragInfo and DrgFreeDISH limits NumItemsToUnhilite & DeleteDragitemStrHandles
    4343  06 Apr 07 GKY Add some error checking in drag/drop
     44  19 Apr 07 SHL Rework DeleteDragitemStrHandles to be FreeDragInfoData
     45  19 Apr 07 SHL Add DbgMsg.  Sync with AcceptOneDrop GetOneDrop mods.
    4446
    4547***********************************************************************/
     
    641643VOID Runtime_Error2(PCSZ pszSrcFile, UINT uSrcLineNo, UINT idMsg);
    642644APIRET saymsg(ULONG mb_type, HWND hwnd, PCSZ pszTitle, PCSZ pszFmt, ...);
     645VOID DbgMsg(PCSZ pszSrcFile, UINT uSrcLineNo, PCSZ pszFmt, ...);
    643646
    644647/* valid.c */
     
    10491052
    10501053/* droplist.c */
    1051 ULONG FreeDrop(MPARAM mp1, MPARAM mp2);
    10521054void DropHelp(MPARAM mp1, MPARAM mp2, HWND hwnd, char *text);
    1053 BOOL AcceptOneDrop(MPARAM mp1, MPARAM mp2);
    1054 BOOL GetOneDrop(MPARAM mp1, MPARAM mp2, char *buffer, ULONG buflen);
     1055BOOL AcceptOneDrop(HWND hwnd, MPARAM mp1, MPARAM mp2);
     1056BOOL GetOneDrop(HWND hwnd, MPARAM mp1, MPARAM mp2, char *buffer, ULONG buflen);
    10551057BOOL FullDrgName(PDRAGITEM pDItem, CHAR * buffer, ULONG buflen);
    10561058BOOL TwoDrgNames(PDRAGITEM pDItem, CHAR * buffer1, ULONG buflen1,
     
    10581060LISTINFO *DoFileDrop(HWND hwndCnr, CHAR * directory, BOOL arcfilesok,
    10591061                     MPARAM mp1, MPARAM mp2);
    1060 BOOL DeleteDragitemStrHandles (PDRAGINFO pDInfo);
     1062VOID FreeDragInfoData (HWND hwnd, PDRAGINFO pDInfo);
    10611063
    10621064/* shadow.c */
     
    13511353DATADEF PID mypid;
    13521354DATADEF INT driveflags[26], driveserial[26];
    1353 DATADEF ULONG NoBrokenNotify, fwsAnimate, OS2ver[2], DriveLines, fExceedPMDrgLimit;
     1355DATADEF ULONG NoBrokenNotify, fwsAnimate, OS2ver[2], DriveLines, NumItemsToUnhilite;
    13541356DATADEF HINI fmprof;
    13551357DATADEF HELPINIT hini;
  • trunk/dll/info.c

    r576 r618  
    1818  24 Mar 07 SHL Correct FileInfoProc binary file detect
    1919  24 Mar 07 SHL Correct FileInfoProc/IconProc race crash
     20  19 Apr 07 SHL Sync with AcceptOneDrop GetOneDrop mods
    2021
    2122***********************************************************************/
     
    368369      DrawTargetEmphasis(hwnd, emphasized);
    369370    }
    370     if (AcceptOneDrop(mp1, mp2))
     371    if (AcceptOneDrop(hwnd, mp1, mp2))
    371372      return MRFROM2SHORT(DOR_DROP, DO_MOVE);
    372373    return MRFROM2SHORT(DOR_NEVERDROP, 0);
     
    389390      emphasized = FALSE;
    390391      DrawTargetEmphasis(hwnd, emphasized);
    391       if (GetOneDrop(mp1, mp2, szFrom, sizeof(szFrom))) {
     392      if (GetOneDrop(hwnd, mp1, mp2, szFrom, sizeof(szFrom))) {
    392393        memset(&ici, 0, sizeof(ICONINFO));
    393394        ici.cb = sizeof(ICONINFO);
  • trunk/dll/inis.c

    r603 r618  
    1818  06 Apr 07 GKY Work around PM DragInfo and DrgFreeDISH limits
    1919  06 Apr 07 GKY Add some error checking in drag/drop
     20  19 Apr 07 SHL Use FreeDragInfoData.  Add more drag/drop error checks.
    2021
    2122***********************************************************************/
     
    15721573      DrgSetDragitem(pDInfo, &DItem, sizeof(DRAGITEM), 0L);
    15731574      hDrop = DrgDrag(hwnd, pDInfo, &DIcon, 1L, VK_ENDDRAG, (PVOID) NULL);
    1574       DeleteDragitemStrHandles(pDInfo); //
    1575       DrgDeleteDraginfoStrHandles (pDInfo);
    1576       DrgFreeDraginfo(pDInfo);
     1575      if (hDrop == NULLHANDLE)
     1576        FreeDragInfoData(hwnd, pDInfo);
    15771577      WinDestroyPointer(hptrINI);
    15781578    }
     
    15821582    {
    15831583      PDRAGINFO pDInfo = (PDRAGINFO) mp1;
    1584       PDRAGITEM pDItem;         /* Pointer to DRAGITEM   */
    1585 
    1586       DrgAccessDraginfo(pDInfo);        /* Access DRAGINFO       */
    1587       pDItem = DrgQueryDragitemPtr(pDInfo,      /* Access DRAGITEM       */
    1588                                    0);  /* Index to DRAGITEM     */
    1589       if (DrgVerifyRMF(pDItem,          /* Check valid rendering */
    1590                        DRM_OS2FILE,     /* mechanisms and data   */
    1591                        NULL)) {
    1592         DrgFreeDraginfo(pDInfo);        /* Free DRAGINFO         */
    1593         return (MRFROM2SHORT(DOR_DROP,  /* Return okay to drop   */
    1594                              DO_LINK));
    1595       }
    1596       else if (DrgVerifyRMF(pDItem, DRM_FM2INIRECORD, DRF_FM2INI)) {
    1597         if (WinQueryWindow(pDInfo->hwndSource, QW_PARENT) ==
    1598             WinQueryWindow(hwnd, QW_PARENT)) {
     1584      PDRAGITEM pDItem;
     1585
     1586      if (!DrgAccessDraginfo(pDInfo)) {
     1587        Win_Error(HWND_DESKTOP, HWND_DESKTOP, pszSrcFile, __LINE__,
     1588                  "DrgAccessDraginfo");
     1589      }
     1590      else {
     1591        pDItem = DrgQueryDragitemPtr(pDInfo,0);
     1592        /* Check valid rendering mechanisms and data */
     1593        if (DrgVerifyRMF(pDItem, DRM_OS2FILE, NULL)) {
    15991594          DrgFreeDraginfo(pDInfo);
    1600           return MRFROM2SHORT(DOR_NEVERDROP, 0);
    1601         }
    1602         DrgFreeDraginfo(pDInfo);        /* Free DRAGINFO         */
    1603         return (MRFROM2SHORT(DOR_DROP, ((fCopyDefault) ? DO_COPY : DO_MOVE)));
    1604       }
    1605       DrgFreeDraginfo(pDInfo);          /* Free DRAGINFO         */
    1606       return MRFROM2SHORT(DOR_NEVERDROP, 0);
    1607     }
     1595          return (MRFROM2SHORT(DOR_DROP, DO_LINK));     /* OK to drop */
     1596        }
     1597        else if (DrgVerifyRMF(pDItem, DRM_FM2INIRECORD, DRF_FM2INI)) {
     1598          if (WinQueryWindow(pDInfo->hwndSource, QW_PARENT) !=
     1599              WinQueryWindow(hwnd, QW_PARENT))
     1600          {
     1601            DrgFreeDraginfo(pDInfo);
     1602            return (MRFROM2SHORT(DOR_DROP, ((fCopyDefault) ? DO_COPY : DO_MOVE)));
     1603          }
     1604        }
     1605        DrgFreeDraginfo(pDInfo);
     1606      }
     1607    }
     1608    return MRFROM2SHORT(DOR_NEVERDROP, 0);
    16081609
    16091610  case DM_DRAGLEAVE:
     
    16151616      PDRAGINFO pDInfo = (PDRAGINFO) mp1;
    16161617      PDRAGITEM pDItem;         /* Pointer to DRAGITEM   */
    1617       ULONG numitems, curitem = 0L, len;
     1618      ULONG numitems, curitem, len;
    16181619      USHORT action;
    16191620      CHAR szFrom[CCHMAXPATH + 2], szDir[CCHMAXPATH + 1],
     
    16221623      INIREC inirec;
    16231624
    1624       DrgAccessDraginfo(pDInfo);        /* Access DRAGINFO       */
     1625      if (!DrgAccessDraginfo(pDInfo)) {
     1626        Win_Error(HWND_DESKTOP, HWND_DESKTOP, pszSrcFile, __LINE__,
     1627                  "DrgAccessDraginfo");
     1628        return 0;
     1629      }
    16251630      numitems = DrgQueryDragitemCount(pDInfo);
    1626       while (curitem < numitems) {
     1631      for (curitem = 0; curitem < numitems; curitem++) {
    16271632        pDItem = DrgQueryDragitemPtr(pDInfo, curitem);
    16281633        if (DrgVerifyRMF(pDItem, DRM_OS2FILE, NULL)) {
     
    16771682                             MPFROMLONG(DMFL_TARGETFAIL));
    16781683        }
    1679         curitem++;
    1680       }
    1681       rc = DeleteDragitemStrHandles(pDInfo); //
    1682 
    1683       if(!rc)
    1684           Win_Error(HWND_DESKTOP, HWND_DESKTOP, pszSrcFile, __LINE__,
    1685                     "DrgDeleteDraginfoStrHandles");
    1686       DrgDeleteDraginfoStrHandles(pDInfo);
    1687       rc = DrgFreeDraginfo(pDInfo);
    1688       if(!rc)
    1689           Win_Error(HWND_DESKTOP, HWND_DESKTOP, pszSrcFile, __LINE__,
    1690                  "DrgFreeDraginfo");
     1684      } // for
     1685      FreeDragInfoData(hwnd, pDInfo);
    16911686    }
    16921687    return 0;
     
    16971692    hwndPopup = (HWND) 0;
    16981693    break;
    1699   }
     1694  } // switch
    17001695  if (oldproc)
    17011696    return oldproc(hwnd, msg, mp1, mp2);
  • trunk/dll/mainwnd.c

    r606 r618  
    3030  06 Apr 07 GKY Work around PM DragInfo and DrgFreeDISH limits
    3131  06 Apr 07 GKY Add some error checking in drag/drop
     32  15 Apr 07 SHL mainwnd MAIN_SETUPLIST restore state not found reporting
     33  19 Apr 07 SHL Sync with AcceptOneDrop GetOneDrop mods
     34  20 Apr 07 SHL Avoid spurious add_udir error reports
    3235
    3336***********************************************************************/
     
    3538#define INCL_DOS
    3639#define INCL_WIN
     40// #define INCL_WINERRORS
     41#define INCL_SHLERRORS
    3742#define INCL_WINHELP
    3843#define INCL_GPI
     
    628633        DrawTargetEmphasis(hwnd, emphasized);
    629634      }
    630       if (AcceptOneDrop(mp1, mp2))
     635      if (AcceptOneDrop(hwnd, mp1, mp2))
    631636        return MRFROM2SHORT(DOR_DROP, DO_MOVE);
    632637      return MRFROM2SHORT(DOR_NEVERDROP, 0);
     
    662667        DrawTargetEmphasis(hwnd, emphasized);
    663668      }
    664       if (GetOneDrop(mp1, mp2, szFrom, sizeof(szFrom))) {
     669      if (GetOneDrop(hwnd, mp1, mp2, szFrom, sizeof(szFrom))) {
    665670        MakeValidDir(szFrom);
    666671        WinSetWindowText(hwnd, szFrom);
     
    12331238      cdi.pDragInfo = mp1;
    12341239      li = DoFileDrop(hwnd, NULL, FALSE, mp1, MPFROMP(&cdi));
    1235       if (fExceedPMDrgLimit)
     1240      if (NumItemsToUnhilite)
    12361241        saymsg(MB_CANCEL | MB_ICONEXCLAMATION,
    12371242                             hwnd,
     
    17521757        DrawTargetEmphasis(hwnd, emphasized);
    17531758      }
    1754       if (AcceptOneDrop(mp1, mp2))
     1759      if (AcceptOneDrop(hwnd, mp1, mp2))
    17551760        return MRFROM2SHORT(DOR_DROP, DO_MOVE);
    17561761      return MRFROM2SHORT(DOR_NEVERDROP, 0);
     
    18061811                      NULL,
    18071812                      TRUE, MPFROM2SHORT(TREE_CNR, CN_DROP), MPFROMP(&cnd));
    1808       if (fExceedPMDrgLimit)
     1813      if (NumItemsToUnhilite)
    18091814        saymsg(MB_CANCEL | MB_ICONEXCLAMATION,
    18101815                             hwnd,
     
    34563461        DrawTargetEmphasis(hwnd, emphasized);
    34573462      }
    3458       if (AcceptOneDrop(mp1, mp2))
     3463      if (AcceptOneDrop(hwnd, mp1, mp2))
    34593464        return MRFROM2SHORT(DOR_DROP, DO_MOVE);
    34603465    }
     
    34803485        DrawTargetEmphasis(hwnd, emphasized);
    34813486      }
    3482       if (GetOneDrop(mp1, mp2, szFrom, sizeof(szFrom))) {
     3487      if (GetOneDrop(hwnd, mp1, mp2, szFrom, sizeof(szFrom))) {
    34833488        if (MakeValidDir(szFrom) && !FindDirCnrByName(szFrom, TRUE)) {
    34843489          OpenDirCnr((HWND) 0, hwndMain, hwndTree, FALSE, szFrom);
     
    41514156          !DosQueryPathInfo(temp, FIL_QUERYFULLNAME, path, sizeof(path))) {
    41524157        if (SHORT1FROMMP(mp1) == IDM_ADDTOUSERLIST) {
    4153           if (!add_udir(TRUE, path))
    4154             Runtime_Error(pszSrcFile, __LINE__, "add_udir");
    4155           else {
    4156             if (fUdirsChanged)
    4157               save_udirs();
    4158             WinSendMsg(hwnd, UM_FILLUSERLIST, MPVOID, MPVOID);
    4159           }
     4158          add_udir(TRUE, path);
     4159          if (fUdirsChanged)
     4160            save_udirs();
     4161          WinSendMsg(hwnd, UM_FILLUSERLIST, MPVOID, MPVOID);
    41604162        }
    41614163        else {
     
    41804182      WinQueryWindowText(hwndStatelist, 13, szStateName);
    41814183      bstrip(szStateName);
    4182       if (*szStateName) {
     4184      // Ignore request if blank or attempting to using illegal name
     4185      if (*szStateName && stricmp(szStateName, GetPString(IDS_STATETEXT))) {
    41834186        if (SHORT1FROMMP(mp1) == IDM_SAVEDIRCNRSTATE) {
    41844187          // Save
     
    41894192              save_setups();
    41904193            }
     4194            else {
     4195              saymsg(MB_ENTER | MB_ICONASTERISK, hwnd,
     4196                     GetPString(IDS_WARNINGTEXT),
     4197                     GetPString(IDS_EXISTSASATEXT), szStateName, "state name");
     4198              WinSetWindowText(hwndStatelist, GetPString(IDS_STATETEXT));
     4199            }
    41914200          }
    4192           WinSetWindowText(hwndStatelist, GetPString(IDS_STATETEXT));
     4201          else {
     4202            saymsg(MB_ENTER | MB_ICONASTERISK, hwnd,
     4203                   GetPString(IDS_WARNINGTEXT),
     4204                   "\"%s\" state save failed", szStateName);    // 15 Apr 07 SHL failed
     4205            WinSetWindowText(hwndStatelist, GetPString(IDS_STATETEXT));
     4206          }
    41934207        }
    41944208        else {
     
    53075321                         (CHAR *) mp1);
    53085322      if (add_udir(FALSE, (CHAR *) mp1)) {
    5309         if (fUserComboBox) {
    5310           if (fAutoAddDirs)
    5311             WinSendMsg(hwndUserlist, LM_INSERTITEM,
    5312                        MPFROM2SHORT(LIT_SORTASCENDING, 0),
    5313                        MPFROMP((CHAR *) mp1));
     5323        if (fUserComboBox && fAutoAddDirs) {
     5324          WinSendMsg(hwndUserlist, LM_INSERTITEM,
     5325                     MPFROM2SHORT(LIT_SORTASCENDING, 0),
     5326                     MPFROMP((CHAR *) mp1));
    53145327        }
    53155328      }
     
    54345447    WinSendMsg(hwndStatelist, LM_DELETEALL, MPVOID, MPVOID);
    54355448    if (fUserComboBox) {
    5436 
    54375449      INT x;
    54385450
     
    57045716              SetShiftState();
    57055717              size = sizeof(ULONG);
    5706               sprintf(s, "%s.NumDirsLastTime", path);
     5718              sprintf(s, "%s.NumDirsLastTime", path);   // path is state name
    57075719              if (!PrfQueryProfileData
    57085720                  (fmprof, FM3Str, s, (PVOID) & numsaves, &size))
    5709                 Win_Error2(hwnd, hwnd, __FILE__, __LINE__,
    5710                            IDS_PRFQUERYPROFILEDATA);
     5721              {
     5722                if ((WinGetLastError(WinQueryAnchorBlock(hwnd)) & 0xffff) == PMERR_NOT_IN_IDX) {
     5723                  saymsg(MB_ENTER | MB_ICONASTERISK, hwnd,
     5724                         GetPString(IDS_WARNINGTEXT),
     5725                         GetPString(IDS_DOESNTEXISTTEXT), path);
     5726                }
     5727                else {
     5728                  Win_Error2(hwnd, hwnd, __FILE__, __LINE__,
     5729                             IDS_PRFQUERYPROFILEDATA);
     5730                }
     5731              }
    57115732              else if (!numsaves)
    57125733                Runtime_Error2(pszSrcFile, __LINE__, IDS_NODATATEXT);
     
    57305751                }
    57315752              }
    5732               WinSetWindowText(hwndStatelist, GetPString(IDS_STATETEXT));
     5753              // fixme to hold restored state name for a while
     5754              // WinSetWindowText(hwndStatelist, GetPString(IDS_STATETEXT));    // 15 Apr 07 SHL
    57335755            }
    57345756            else if (SHORT1FROMMP(mp1) == MAIN_CMDLIST) {
  • trunk/dll/select.c

    r606 r618  
    1717  15 Aug 06 SHL Rework SetMask args and logic
    1818  06 Apr 07 GKY Work around PM DragInfo and DrgFreeDISH limits
     19  19 Apr 07 SHL Sync with NumItemsToUnhilite mods
    1920
    2021***********************************************************************/
     
    6263      if (!all)
    6364          break;
    64       if(fExceedPMDrgLimit && x == fExceedPMDrgLimit - 1){
    65           fExceedPMDrgLimit = 0;
    66           break;
     65      // Count is one extra to ensure non-zero elsewhere
     66      if (NumItemsToUnhilite && x + 2 == NumItemsToUnhilite){
     67        NumItemsToUnhilite = 0;
     68        break;
    6769      }
    6870      if (list)
     
    421423
    422424  if (quitit)
    423     attribute = (target) ? CRA_TARGET : (source) ? CRA_SOURCE : CRA_INUSE;
     425    attribute = target ? CRA_TARGET : source ? CRA_SOURCE : CRA_INUSE;
    424426  pci = (PCNRITEM) WinSendMsg(hwndCnr, CM_QUERYRECORDEMPHASIS,
    425427                              MPFROMLONG(CMA_FIRST), MPFROMSHORT(attribute));
     
    437439    WinSendMsg(hwndCnr, CM_SETRECORDEMPHASIS, MPFROMP(pci),
    438440               MPFROM2SHORT(!quitit,
    439                             ((target) ? CRA_TARGET : (source) ? CRA_SOURCE :
    440                              CRA_INUSE)));
     441                            target ? CRA_TARGET : source ? CRA_SOURCE :
     442                             CRA_INUSE));
    441443    pci =
    442444      WinSendMsg(hwndCnr, CM_QUERYRECORDEMPHASIS, MPFROMP(pci),
  • trunk/dll/treecnr.c

    r606 r618  
    2828  06 Apr 07 GKY Work around PM DragInfo and DrgFreeDISH limits
    2929  06 Apr 07 GKY Add some error checking in drag/drop
     30  19 Apr 07 SHL Sync with AcceptOneDrop GetOneDrop mods
     31  19 Apr 07 SHL Add more drag/drop error checking
    3032
    3133***********************************************************************/
     
    99101      EmphasizeButton(hwnd, emphasized);
    100102    }
    101     if (AcceptOneDrop(mp1, mp2))
     103    if (AcceptOneDrop(hwnd, mp1, mp2))
    102104      return MRFROM2SHORT(DOR_DROP, DO_MOVE);
    103105    return MRFROM2SHORT(DOR_NEVERDROP, 0);
     
    122124        EmphasizeButton(hwnd, emphasized);
    123125      }
    124       if (GetOneDrop(mp1, mp2, szFrom, sizeof(szFrom))) {
     126      if (GetOneDrop(hwnd, mp1, mp2, szFrom, sizeof(szFrom))) {
    125127        MakeValidDir(szFrom);
    126128        WinSendMsg(WinQueryWindow(hwnd, QW_PARENT),
     
    544546      cni.pDragInfo = (PDRAGINFO) mp1;
    545547      li = DoFileDrop(dcd->hwndCnr,
    546                       dcd->directory, FALSE, MPVOID, MPFROMP(&cni));
    547       if (fExceedPMDrgLimit)
    548         saymsg(MB_CANCEL | MB_ICONEXCLAMATION,
    549                              hwnd,
    550                              GetPString(IDS_ERRORTEXT),
    551                    GetPString(IDS_EXCEEDPMDRGLMT));
     548                      dcd->directory, FALSE, MPVOID, MPFROMP(&cni));
     549      if (NumItemsToUnhilite)
     550        saymsg(MB_CANCEL | MB_ICONEXCLAMATION,
     551                             hwnd,
     552                             GetPString(IDS_ERRORTEXT),
     553                   GetPString(IDS_EXCEEDPMDRGLMT));
    552554      if (li) {
    553555        li->type = ((fDefaultDeletePerm) ? IDM_PERMDELETE : IDM_DELETE);
     
    12541256          PDRAGINFO pDInfo;
    12551257
     1258          // fixme to know why - seems superfluous
    12561259          pDInfo = ((PCNRDRAGINFO) mp2)->pDragInfo;
    12571260          DrgAccessDraginfo(pDInfo);
     
    12701273
    12711274          pDInfo = ((PCNRDRAGINFO) mp2)->pDragInfo;
    1272           DrgAccessDraginfo(pDInfo);
     1275          if (!DrgAccessDraginfo(pDInfo)) {
     1276            Win_Error(hwnd, hwnd, pszSrcFile, __LINE__,
     1277                      "DrgAccessDraginfo");
     1278            return (MRFROM2SHORT(DOR_NODROP, 0));       /* Drop not valid */
     1279          }
    12731280          pci = (PCNRITEM) ((PCNRDRAGINFO) mp2)->pRecord;
    12741281          if ((INT) pci == -1)
    12751282            pci = NULL;
    12761283          if (pci && (pci->flags & (RECFLAGS_ENV | RECFLAGS_NODROP))) {
    1277             DrgFreeDraginfo(pDInfo);
    1278             return MRFROM2SHORT(DOR_NODROP, 0);
    1279           }
    1280           if (!pDInfo) {
    12811284            DrgFreeDraginfo(pDInfo);
    12821285            return MRFROM2SHORT(DOR_NODROP, 0);
     
    13151318            }
    13161319          }
    1317           pDItem = DrgQueryDragitemPtr(pDInfo,  /* Access DRAGITEM       */
    1318                                        0);      /* Index to DRAGITEM     */
     1320          pDItem = DrgQueryDragitemPtr(pDInfo,  /* Access DRAGITEM */
     1321                                       0);      /* Index to DRAGITEM */
    13191322          if (DrgVerifyRMF(pDItem,      /* Check valid rendering */
    1320                            DRM_OS2FILE, /* mechanisms and data   */
    1321                            NULL) || DrgVerifyRMF(pDItem, DRM_FM2ARCMEMBER, DRF_FM2ARCHIVE)) {   /* formats               */
    1322             DrgFreeDraginfo(pDInfo);    /* Free DRAGINFO         */
     1323                           DRM_OS2FILE, /* mechanisms and data */
     1324                           NULL) || DrgVerifyRMF(pDItem, DRM_FM2ARCMEMBER, DRF_FM2ARCHIVE)) {   /* formats */
     1325            DrgFreeDraginfo(pDInfo);    /* Free DRAGINFO */
    13231326            if (!pci || (INT) pci == -1)
    13241327              return MRFROM2SHORT(DOR_DROP, DO_MOVE);
     
    13281331            if (toupper(*pci->szFileName) < 'C')
    13291332              return MRFROM2SHORT(DOR_DROP, DO_COPY);
    1330             return MRFROM2SHORT(DOR_DROP,       /* Return okay to drop   */
     1333            return MRFROM2SHORT(DOR_DROP,       /* Return okay to drop */
    13311334                                ((fCopyDefault) ? DO_COPY : DO_MOVE));
    13321335          }
    1333           DrgFreeDraginfo(pDInfo);      /* Free DRAGINFO         */
    1334         }
    1335         return MRFROM2SHORT(DOR_NODROP, 0);     /* Drop not valid        */
     1336          DrgFreeDraginfo(pDInfo);      /* Free DRAGINFO */
     1337        }
     1338        return MRFROM2SHORT(DOR_NODROP, 0);     /* Drop not valid */
    13361339
    13371340      case CN_INITDRAG:
     
    13741377          ULONG action = UM_ACTION;
    13751378
    1376           li = DoFileDrop(hwnd, NULL, TRUE, mp1, mp2);
    1377           if (fExceedPMDrgLimit)
    1378             saymsg(MB_CANCEL | MB_ICONEXCLAMATION,
    1379                                 hwnd,
    1380                                 GetPString(IDS_ERRORTEXT),
    1381                        GetPString(IDS_EXCEEDPMDRGLMT));
     1379          li = DoFileDrop(hwnd, NULL, TRUE, mp1, mp2);
     1380          if (NumItemsToUnhilite)
     1381            saymsg(MB_CANCEL | MB_ICONEXCLAMATION,
     1382                                hwnd,
     1383                                GetPString(IDS_ERRORTEXT),
     1384                       GetPString(IDS_EXCEEDPMDRGLMT));
    13821385          if (li) {
    13831386            if (!*li->targetpath) {
     
    14021405                                   dcd->hwndParent,
    14031406                                   DropListProc,
    1404                                    FM3ModHandle, DND_FRAME, MPFROMP(&cl));
    1405               if (li->type == DID_ERROR)
    1406                   Win_Error(hwnd, HWND_DESKTOP, pszSrcFile, __LINE__,
    1407                             "Drag & Drop Dialog");
    1408               if (!li->type) {
     1407                                   FM3ModHandle, DND_FRAME, MPFROMP(&cl));
     1408              if (li->type == DID_ERROR)
     1409                  Win_Error(hwnd, HWND_DESKTOP, pszSrcFile, __LINE__,
     1410                            "Drag & Drop Dialog");
     1411              if (!li->type) {
    14091412                FreeListInfo(li);
    14101413                return 0;
    14111414              }
    14121415              li->list = cl.list;
    1413               if (!li->list || !li->list[0]) {
     1416              if (!li->list || !li->list[0]) {
    14141417                FreeListInfo(li);
    14151418                return 0;
     
    17981801              if (drvtype & DRIVE_REMOTE)
    17991802                driveflags[x] |= DRIVE_REMOTE;
    1800               if (!strcmp(FileSystem, CBSIFS)) {
     1803              if (!strcmp(FileSystem, CBSIFS)) {
    18011804                driveflags[x] |= DRIVE_ZIPSTREAM;
    1802                 driveflags[x] &= (~DRIVE_REMOTE);
    1803               }
    1804               if(!strcmp(FileSystem,NDFS32)) {
    1805                 driveflags[x] |= DRIVE_VIRTUAL;
    1806                 driveflags[x] &= (~DRIVE_REMOTE);
    1807               }
    1808               if(!strcmp(FileSystem,RAMFS)) {
    1809                 driveflags[x] |= DRIVE_RAMDISK;
    1810                 driveflags[x] &= (~DRIVE_REMOTE);
    1811               }
     1805                driveflags[x] &= (~DRIVE_REMOTE);
     1806              }
     1807              if(!strcmp(FileSystem,NDFS32)) {
     1808                driveflags[x] |= DRIVE_VIRTUAL;
     1809                driveflags[x] &= (~DRIVE_REMOTE);
     1810              }
     1811              if(!strcmp(FileSystem,RAMFS)) {
     1812                driveflags[x] |= DRIVE_RAMDISK;
     1813                driveflags[x] &= (~DRIVE_REMOTE);
     1814              }
    18121815              if (!strcmp(FileSystem, CDFS) || !strcmp(FileSystem, ISOFS))
    18131816                driveflags[x] |= (DRIVE_REMOVABLE |
    1814                                   DRIVE_NOTWRITEABLE | DRIVE_CDROM);
    1815               if(!strcmp(FileSystem,NTFS))
    1816                 driveflags[x] |= DRIVE_NOTWRITEABLE;
     1817                                  DRIVE_NOTWRITEABLE | DRIVE_CDROM);
     1818              if(!strcmp(FileSystem,NTFS))
     1819                driveflags[x] |= DRIVE_NOTWRITEABLE;
    18171820              if (strcmp(FileSystem, HPFS) &&
    18181821                  strcmp(FileSystem, JFS) &&
    18191822                  strcmp(FileSystem, CDFS) &&
    1820                   strcmp(FileSystem, ISOFS) &&
    1821                   strcmp(FileSystem, RAMFS) &&
     1823                  strcmp(FileSystem, ISOFS) &&
     1824                  strcmp(FileSystem, RAMFS) &&
    18221825                  strcmp(FileSystem, FAT32) &&
    1823                   strcmp(FileSystem, NDFS32) &&
    1824                   strcmp(FileSystem, NTFS) &&
    1825                   strcmp(FileSystem, HPFS386)) {
     1826                  strcmp(FileSystem, NDFS32) &&
     1827                  strcmp(FileSystem, NTFS) &&
     1828                  strcmp(FileSystem, HPFS386)) {
    18261829                driveflags[x] |= DRIVE_NOLONGNAMES;
    1827               }
    1828               SelectDriveIcon(pciP);
     1830              }
     1831              SelectDriveIcon(pciP);
    18291832              WinSendMsg(hwnd,
    18301833                         CM_INVALIDATERECORD,
     
    25632566              // Check if drive type might need update
    25642567              if ((driveflag & (DRIVE_INVALID | DRIVE_NOPRESCAN)) ||
    2565                   (~driveflag & DRIVE_NOPRESCAN && pci->rc.hptrIcon == hptrDunno))
     2568                  (~driveflag & DRIVE_NOPRESCAN && pci->rc.hptrIcon == hptrDunno))
    25662569              {
    25672570                driveflags[toupper(*pci->szFileName) - 'A'] &=
     
    25692572                   DRIVE_NOLOADSUBJS | DRIVE_NOLOADLONGS | DRIVE_NOSTATS);
    25702573                DriveFlagsOne(toupper(*pci->szFileName) - 'A');
    2571                 driveflag = driveflags[toupper(*pci->szFileName) - 'A'];
     2574                driveflag = driveflags[toupper(*pci->szFileName) - 'A'];
    25722575                if (driveflag & DRIVE_INVALID)
    25732576                  pci->rc.hptrIcon = hptrDunno;
    25742577                else {
    2575                   SelectDriveIcon(pci);
     2578                  SelectDriveIcon(pci);
    25762579                }
    25772580                WinSendMsg(hwnd,
Note: See TracChangeset for help on using the changeset viewer.