Juan Lang <juan_lang@yahoo.com>
authorGé van Geldorp <ge@gse.nl>
Tue, 21 Sep 2004 19:34:21 +0000 (19:34 +0000)
committerGé van Geldorp <ge@gse.nl>
Tue, 21 Sep 2004 19:34:21 +0000 (19:34 +0000)
- Correct some PIDL types and eliminate some magic numbers in PIDL
  allocation; correct a copy-pasto from a previous patch.

svn path=/trunk/; revision=10959

reactos/include/wine/shlguid.h
reactos/lib/shell32/cpanelfolder.c
reactos/lib/shell32/debughlp.c
reactos/lib/shell32/pidl.c
reactos/lib/shell32/pidl.h
reactos/w32api/include/shlguid.h

index ebdba27..cd3de54 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: shlguid.h,v 1.5 2004/09/20 19:47:13 gvg Exp $
+/* $Id: shlguid.h,v 1.6 2004/09/21 19:34:21 gvg Exp $
  *
  * Compatibility header
  *
@@ -43,6 +43,7 @@ DEFINE_GUID(CLSID_Internet, 0x871C5380, 0x42A0, 0x1069, 0xA2, 0xEA, 0x08, 0x00,
 DEFINE_GUID(CLSID_ShellFSFolder, 0xF3364BA0, 0x65B9, 0x11CE, 0xA9, 0xBA, 0x00, 0xAA, 0x00, 0x4A, 0xE8, 0x37);
 DEFINE_GUID(CLSID_RecycleBin, 0x645FF040, 0x5081, 0x101B, 0x9F, 0x08, 0x00, 0xAA, 0x00, 0x2F, 0x95, 0x4E);
 DEFINE_GUID(CLSID_ControlPanel, 0x21EC2020, 0x3AEA, 0x1069, 0xA2, 0xDD, 0x08, 0x00, 0x2B, 0x30, 0x30, 0x9D);
+DEFINE_GUID(CLSID_Printers, 0x2227A280, 0x3AEA, 0x1069, 0xA2, 0xDE, 0x08, 0x00, 0x2B, 0x30, 0x30, 0x9D);
 
 DEFINE_GUID(IID_IQueryAssociations, 0xc46ca590, 0x3c3f, 0x11d2, 0xbe, 0xe6, 0x00, 0x00, 0xf8, 0x05, 0xca, 0x57);
 
index a9eb1ec..82ec0bd 100644 (file)
@@ -238,7 +238,7 @@ static LPITEMIDLIST _ILCreateCPanelApplet(LPCSTR name, LPCSTR displayName,
     int size = size0;
     int l;
 
-    tmp.type = 0;
+    tmp.type = PT_CPLAPPLET;
     tmp.u.cpanel.dummy = 0;
     tmp.u.cpanel.iconIdx = iconIdx;
 
@@ -280,7 +280,7 @@ static PIDLCPanelStruct* _ILGetCPanelPointer(LPCITEMIDLIST pidl)
 {
     LPPIDLDATA pdata = _ILGetDataPointer(pidl);
 
-    if (pdata && pdata->type==0)
+    if (pdata && pdata->type==PT_CPLAPPLET)
         return (PIDLCPanelStruct*)&(pdata->u.cpanel);
 
     return NULL;
index 0423e17..1b0609a 100644 (file)
@@ -201,9 +201,7 @@ void pdump (LPCITEMIDLIST pidl)
              char szName[MAX_PATH];
 
              _dbg_ILSimpleGetText(pidltemp, szName, MAX_PATH);
-             if( PT_FOLDER == type)
-               dwAttrib = pData->u.folder.uFileAttribs;
-             else if( PT_VALUE == type)
+             if( PT_FOLDER == type || PT_VALUE == type)
                dwAttrib = pData->u.file.uFileAttribs;
 
              MESSAGE ("[%p] size=%04u type=%lx attr=0x%08lx name=\"%s\" (%s,%s)\n",
@@ -230,7 +228,7 @@ BOOL pcheck (LPCITEMIDLIST pidl)
         { do
           { type   = _dbg_ILGetDataPointer(pidltemp)->type;
             switch (type)
-           { case PT_DESKTOP:
+           { case PT_CPLAPPLET:
              case PT_GUID:
              case PT_SHELLEXT:
              case PT_DRIVE:
index 86b088c..eb12a90 100644 (file)
@@ -1440,9 +1440,38 @@ HRESULT WINAPI SHBindToParent(LPCITEMIDLIST pidl, REFIID riid, LPVOID *ppv, LPCI
  *
  *************************************************************************
  */
+LPITEMIDLIST _ILAlloc(PIDLTYPE type, size_t size)
+{
+    LPITEMIDLIST pidlOut = NULL;
+
+    if((pidlOut = SHAlloc(size + 5)))
+    {
+        LPPIDLDATA pData;
+        LPITEMIDLIST pidlNext;
+
+        ZeroMemory(pidlOut, size + 5);
+        pidlOut->mkid.cb = size + 3;
+
+        if ((pData = _ILGetDataPointer(pidlOut)))
+            pData->type = type;
+
+        if ((pidlNext = ILGetNext(pidlOut)))
+            pidlNext->mkid.cb = 0x00;
+        TRACE("-- (pidl=%p, size=%u)\n", pidlOut, size);
+    }
+
+    return pidlOut;
+}
+
 LPITEMIDLIST _ILCreateDesktop()
-{      TRACE("()\n");
-       return _ILCreateWithTypeAndSize(PT_DESKTOP, 0);
+{
+    LPITEMIDLIST ret;
+
+    TRACE("()\n");
+    ret = SHAlloc(2);
+    if (ret)
+        ret->mkid.cb = 0;
+    return ret;
 }
 
 LPITEMIDLIST _ILCreateMyComputer()
@@ -1481,7 +1510,7 @@ LPITEMIDLIST _ILCreatePrinters()
     TRACE("()\n");
     if (parent)
     {
-        LPITEMIDLIST printers = _ILCreateGuid(PT_GUID, &CLSID_ControlPanel);
+        LPITEMIDLIST printers = _ILCreateGuid(PT_GUID, &CLSID_Printers);
 
         if (printers)
         {
@@ -1509,7 +1538,7 @@ LPITEMIDLIST _ILCreateGuid(PIDLTYPE type, REFIID guid)
 
     if (type == PT_SHELLEXT || type == PT_GUID)
     {
-        pidlOut = _ILCreateWithTypeAndSize(type, 2 + 2 + sizeof(GUID));
+        pidlOut = _ILAlloc(type, sizeof(GUIDStruct));
         if (pidlOut)
         {
             LPPIDLDATA pData = _ILGetDataPointer(pidlOut);
@@ -1539,30 +1568,11 @@ LPITEMIDLIST _ILCreateGuidFromStrA(LPCSTR szGUID)
        return _ILCreateGuid(PT_GUID, &iid);
 }
 
-LPITEMIDLIST _ILCreateWithTypeAndSize(PIDLTYPE type, UINT size)
-{
-    LPITEMIDLIST pidlOut = NULL, pidlTemp = NULL;
-    LPPIDLDATA   pData;
-
-    if(!(pidlOut = SHAlloc(size + 2))) return NULL;
-    ZeroMemory(pidlOut, size + 2);
-    pidlOut->mkid.cb = size;
-
-    if ((pData = _ILGetDataPointer(pidlOut)))
-        pData->type = type;
-
-    if ((pidlTemp = ILGetNext(pidlOut)))
-        pidlTemp->mkid.cb = 0x00;
-
-    TRACE("-- (pidl=%p, size=%u)\n", pidlOut, size);
-    return pidlOut;
-}
-
 LPITEMIDLIST _ILCreateFromFindDataA(WIN32_FIND_DATAA * stffile )
 {
     char       buff[MAX_PATH + 14 +1]; /* see WIN32_FIND_DATA */
     char *     pbuff = buff;
-    ULONG      len, len1;
+    size_t     len, len1;
     LPITEMIDLIST pidl;
     PIDLTYPE type;
 
@@ -1581,8 +1591,10 @@ LPITEMIDLIST _ILCreateFromFindDataA(WIN32_FIND_DATAA * stffile )
 
     type = (stffile->dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) ? PT_FOLDER : 
      PT_VALUE;
-    /* FIXME: magic #s! */
-    if ((pidl = _ILCreateWithTypeAndSize(type, 2 + 12 + len + len1)))
+    /* FileStruct already has one byte for the first name, so use len - 1 in
+     * size calculation
+     */
+    if ((pidl = _ILAlloc(type, sizeof(FileStruct) + (len - 1) + len1)))
     {
         LPPIDLDATA pData;
         LPSTR pszDest;
@@ -1591,9 +1603,9 @@ LPITEMIDLIST _ILCreateFromFindDataA(WIN32_FIND_DATAA * stffile )
         if ((pData = _ILGetDataPointer(pidl)))
         {
             pData->type = type;
-            FileTimeToDosDateTime(&(stffile->ftLastWriteTime),&pData->u.folder.uFileDate,&pData->u.folder.uFileTime);
-            pData->u.folder.dwFileSize = stffile->nFileSizeLow;
-            pData->u.folder.uFileAttribs = (WORD)stffile->dwFileAttributes;
+            FileTimeToDosDateTime(&(stffile->ftLastWriteTime),&pData->u.file.uFileDate,&pData->u.file.uFileTime);
+            pData->u.file.dwFileSize = stffile->nFileSizeLow;
+            pData->u.file.uFileAttribs = (WORD)stffile->dwFileAttributes;
         }
         if ((pszDest = _ILGetTextPointer(pidl)))
         {
@@ -1632,8 +1644,7 @@ LPITEMIDLIST _ILCreateDrive(LPCWSTR lpszNew)
     sTemp[3]=0x00;
     TRACE("(%s)\n",debugstr_w(sTemp));
 
-    /* FIXME: magic #s! */
-    if ((pidlOut = _ILCreateWithTypeAndSize(PT_DRIVE, 25)))
+    if ((pidlOut = _ILAlloc(PT_DRIVE, sizeof(DriveStruct))))
     {
         LPSTR pszDest;
 
@@ -1973,8 +1984,6 @@ BOOL _ILGetFileDateTime(LPCITEMIDLIST pidl, FILETIME *pFt)
     switch (pdata->type)
     {
         case PT_FOLDER:
-            DosDateTimeToFileTime(pdata->u.folder.uFileDate, pdata->u.folder.uFileTime, pFt);
-            break;
         case PT_VALUE:
             DosDateTimeToFileTime(pdata->u.file.uFileDate, pdata->u.file.uFileTime, pFt);
             break;
@@ -2132,8 +2141,6 @@ DWORD _ILGetFileAttributes(LPCITEMIDLIST pidl, LPSTR pOut, UINT uOutSize)
        switch(pData->type)
        {
          case PT_FOLDER:
-           wAttrib = pData->u.folder.uFileAttribs;
-           break;
          case PT_VALUE:
            wAttrib = pData->u.file.uFileAttribs;
            break;
index cd767da..337258e 100644 (file)
@@ -2,6 +2,7 @@
  * internal pidl functions
  *
  * Copyright 1998 Juergen Schmied
+ * Copyright 2004 Juan Lang
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -85,7 +86,7 @@
 *              GUID    871C5380-42A0-1069-A2EA-08002B30309D
 */
 
-#define PT_DESKTOP     0x00 /* internal */
+#define PT_CPLAPPLET   0x00
 #define PT_GUID                0x1F
 #define PT_DRIVE       0x23
 #define PT_DRIVE2      0x25
@@ -116,29 +117,37 @@ typedef struct tagPIDLCPanelStruct
     CHAR szName[1];            /*10*/ /* terminated by 0x00, followed by display name and comment string */
 } PIDLCPanelStruct;
 
+typedef struct tagGUIDStruct
+{
+    BYTE dummy; /* offset 01 is unknown */
+    GUID guid;  /* offset 02 */
+} GUIDStruct;
+
+typedef struct tagDriveStruct
+{
+    CHAR szDriveName[20];      /*01*/
+    WORD unknown;              /*21*/
+} DriveStruct;
+
+typedef struct tagFileStruct
+{
+    BYTE dummy;                        /*01 is 0x00 for files or dirs */
+    DWORD dwFileSize;          /*02*/
+    WORD uFileDate;            /*06*/
+    WORD uFileTime;            /*08*/
+    WORD uFileAttribs;         /*10*/
+    CHAR szNames[1];           /*12*/
+    /* Here are coming two strings. The first is the long name.
+    The second the dos name when needed or just 0x00 */
+} FileStruct;
+
 typedef struct tagPIDLDATA
 {      PIDLTYPE type;                  /*00*/
        union
-       { struct
-         { BYTE dummy;                 /*01*/
-           GUID guid;                  /*02*/
-           BYTE dummy1;                /*18*/
-         } guid;
-         struct
-         { CHAR szDriveName[20];       /*01*/
-           DWORD dwUnknown;            /*21*/
-           /* the drive seems to be 25 bytes every time */
-         } drive;
-         struct
-         { BYTE dummy;                 /*01 is 0x00 for files or dirs */
-           DWORD dwFileSize;           /*02*/
-           WORD uFileDate;             /*06*/
-           WORD uFileTime;             /*08*/
-           WORD uFileAttribs;          /*10*/
-           CHAR szNames[1];            /*12*/
-           /* Here are coming two strings. The first is the long name.
-           The second the dos name when needed or just 0x00 */
-         } file, folder, generic;
+       {
+         struct tagGUIDStruct guid;
+         struct tagDriveStruct drive;
+         struct tagFileStruct file;
          struct
          { WORD dummy;         /*01*/
            CHAR szNames[1];    /*03*/
@@ -183,10 +192,13 @@ BOOL      _ILIsCPanelStruct       (LPCITEMIDLIST pidl);
  * simple pidls
  */
 
-/* Basic PIDL constructor.  Allocates size + 2 bytes (to include space for the
- * NULL PIDL terminator), and sets type to type.
+/* Basic PIDL constructor.  Allocates size + 5 bytes, where:
+ * - two bytes are SHITEMID.cb
+ * - one byte is PIDLDATA.type
+ * - two bytes are the NULL PIDL terminator
+ * Sets type of the returned PIDL to type.
  */
-LPITEMIDLIST   _ILCreateWithTypeAndSize(PIDLTYPE type, UINT size);
+LPITEMIDLIST   _ILAlloc(PIDLTYPE type, size_t size);
 
 /* Creates a PIDL with guid format and type type, which must be either PT_GUID
  * or PT_SHELLEXT.
index d38299f..8cbbc01 100644 (file)
@@ -17,6 +17,7 @@ extern const GUID CLSID_Internet;
 extern const GUID CLSID_NetworkPlaces;
 extern const GUID CLSID_RecycleBin;
 extern const GUID CLSID_ShellFSFolder;
+extern const GUID CLSID_Printers;
 extern const GUID FMTID_Intshcut;
 extern const GUID FMTID_InternetSite;
 extern const GUID CGID_Explorer;