Sync to Wine-20050628:
authorGé van Geldorp <ge@gse.nl>
Wed, 6 Jul 2005 22:40:35 +0000 (22:40 +0000)
committerGé van Geldorp <ge@gse.nl>
Wed, 6 Jul 2005 22:40:35 +0000 (22:40 +0000)
Juan Lang <juan_lang@yahoo.com>
- Fix return code abuse (don't use HRESULT when it isn't meant), make
  functions static where possible, remove unused prototypes.
Dmitry Timoshkov <dmitry@codeweavers.com>
- Make some of the OLE interface vtables const.
Michael Jung <mjung@iss.tu-darmstadt.de>
- Use IShellFolder::GetDisplayNameOf instead of SHGetPathFromIDList to
  be able to browse shell namespace extensions.
Vitaly Lipatov <lav@etersoft.ru>
- Add some descriptions for PageSetupDlg functions.
- Implement user paint hook support and PSD_ENABLEPAGEPAINTHOOK
  checking.
Huw Davies <huw@codeweavers.com>
- If a folder is selected on Open then browse into it, otherwise we
  should return the path in the edit box whether that be a folder or a
  file.
- Don't add extensions to a folder.
- Use DWLP_MSGRESULT to return values from the dialog proc.
- Send CDN_FOLDERCHANGE whenever we change folder.

svn path=/trunk/; revision=16473

reactos/lib/comdlg32/filedlg.c
reactos/lib/comdlg32/filedlgbrowser.c
reactos/lib/comdlg32/filedlgbrowser.h
reactos/lib/comdlg32/printdlg.c

index e1722de..2d8650d 100644 (file)
@@ -196,6 +196,9 @@ static BOOL    FILEDLG95_SHELL_ExecuteCommand(HWND hwnd, LPCSTR lpVerb);
 static void    FILEDLG95_SHELL_Clean(HWND hwnd);\r
 static BOOL    FILEDLG95_SHELL_BrowseToDesktop(HWND hwnd);\r
 \r
+/* Functions used by the EDIT box */\r
+static int FILEDLG95_FILENAME_GetFileNames (HWND hwnd, LPWSTR * lpstrFileList, UINT * sizeUsed, char separator);\r
+\r
 /* Functions used by the filetype combo box */\r
 static HRESULT FILEDLG95_FILETYPE_Init(HWND hwnd);\r
 static BOOL    FILEDLG95_FILETYPE_OnCommand(HWND hwnd, WORD wNotifyCode);\r
@@ -203,7 +206,7 @@ static int     FILEDLG95_FILETYPE_SearchExt(HWND hwnd,LPCWSTR lpstrExt);
 static void    FILEDLG95_FILETYPE_Clean(HWND hwnd);\r
 \r
 /* Functions used by the Look In combo box */\r
-static HRESULT FILEDLG95_LOOKIN_Init(HWND hwndCombo);\r
+static void    FILEDLG95_LOOKIN_Init(HWND hwndCombo);\r
 static LRESULT FILEDLG95_LOOKIN_DrawItem(LPDRAWITEMSTRUCT pDIStruct);\r
 static BOOL    FILEDLG95_LOOKIN_OnCommand(HWND hwnd, WORD wNotifyCode);\r
 static int     FILEDLG95_LOOKIN_AddItem(HWND hwnd,LPITEMIDLIST pidl, int iInsertId);\r
@@ -214,8 +217,7 @@ static int     FILEDLG95_LOOKIN_RemoveMostExpandedItem(HWND hwnd);
 static void    FILEDLG95_LOOKIN_Clean(HWND hwnd);\r
 \r
 /* Miscellaneous tool functions */\r
-HRESULT       GetName(LPSHELLFOLDER lpsf, LPITEMIDLIST pidl,DWORD dwFlags,LPSTR lpstrFileName);\r
-HRESULT       GetFileName(HWND hwnd, LPITEMIDLIST pidl, LPSTR lpstrFileName);\r
+static HRESULT GetName(LPSHELLFOLDER lpsf, LPITEMIDLIST pidl,DWORD dwFlags,LPSTR lpstrFileName);\r
 IShellFolder* GetShellFolderFromPidl(LPITEMIDLIST pidlAbs);\r
 LPITEMIDLIST  GetParentPidl(LPITEMIDLIST pidl);\r
 LPITEMIDLIST  GetPidlFromName(IShellFolder *psf,LPWSTR lpcstrFileName);\r
@@ -224,11 +226,10 @@ LPITEMIDLIST  GetPidlFromName(IShellFolder *psf,LPWSTR lpcstrFileName);
 static void *MemAlloc(UINT size);\r
 static void MemFree(void *mem);\r
 \r
-BOOL WINAPI GetFileName95(FileOpenDlgInfos *fodInfos);\r
 INT_PTR CALLBACK FileOpenDlgProc95(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);\r
-HRESULT SendCustomDlgNotificationMessage(HWND hwndParentDlg, UINT uCode);\r
-HRESULT FILEDLG95_HandleCustomDialogMessages(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);\r
-BOOL FILEDLG95_OnOpenMultipleFiles(HWND hwnd, LPWSTR lpstrFileList, UINT nFileCount, UINT sizeUsed);\r
+void SendCustomDlgNotificationMessage(HWND hwndParentDlg, UINT uCode);\r
+static INT_PTR FILEDLG95_HandleCustomDialogMessages(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);\r
+static BOOL FILEDLG95_OnOpenMultipleFiles(HWND hwnd, LPWSTR lpstrFileList, UINT nFileCount, UINT sizeUsed);\r
 static BOOL BrowseSelectedFolder(HWND hwnd);\r
 \r
 /***********************************************************************\r
@@ -241,7 +242,7 @@ static BOOL BrowseSelectedFolder(HWND hwnd);
  * OUT : TRUE on success\r
  *       FALSE on cancel, error, close or filename-does-not-fit-in-buffer.\r
  */\r
-BOOL WINAPI GetFileName95(FileOpenDlgInfos *fodInfos)\r
+static BOOL WINAPI GetFileName95(FileOpenDlgInfos *fodInfos)\r
 {\r
 \r
     LRESULT lRes;\r
@@ -511,6 +512,27 @@ BOOL  WINAPI GetFileDialog95W(LPOPENFILENAMEW ofn,UINT iDlgType)
   return ret;\r
 }\r
 \r
+/******************************************************************************\r
+ * COMDLG32_GetDisplayNameOf [internal]\r
+ *\r
+ * Helper function to get the display name for a pidl.\r
+ */\r
+static BOOL COMDLG32_GetDisplayNameOf(LPCITEMIDLIST pidl, LPWSTR pwszPath) {\r
+    LPSHELLFOLDER psfDesktop;\r
+    STRRET strret;\r
+        \r
+    if (FAILED(SHGetDesktopFolder(&psfDesktop)))\r
+        return FALSE;\r
+\r
+    if (FAILED(IShellFolder_GetDisplayNameOf(psfDesktop, pidl, SHGDN_FORPARSING, &strret))) {\r
+        IShellFolder_Release(psfDesktop);\r
+        return FALSE;\r
+    }\r
+\r
+    IShellFolder_Release(psfDesktop);\r
+    return SUCCEEDED(StrRetToBufW(&strret, pidl, pwszPath, MAX_PATH));\r
+}\r
+\r
 /***********************************************************************\r
  *      ArrangeCtrlPositions [internal]\r
  *\r
@@ -790,17 +812,16 @@ HWND CreateTemplateDialog(FileOpenDlgInfos *fodInfos, HWND hwnd)
 * Send CustomDialogNotification (CDN_FIRST -- CDN_LAST) message to the custom template dialog\r
 */\r
 \r
-HRESULT SendCustomDlgNotificationMessage(HWND hwndParentDlg, UINT uCode)\r
+void SendCustomDlgNotificationMessage(HWND hwndParentDlg, UINT uCode)\r
 {\r
     FileOpenDlgInfos *fodInfos = (FileOpenDlgInfos *) GetPropA(hwndParentDlg,FileOpenDlgInfosStr);\r
 \r
     TRACE("%p 0x%04x\n",hwndParentDlg, uCode);\r
 \r
-    if(!fodInfos) return 0;\r
+    if(!fodInfos) return;\r
 \r
     if(fodInfos->DlgInfos.hwndCustomDlg)\r
     {\r
-       HRESULT ret;\r
        TRACE("CALL NOTIFY for %x\n", uCode);\r
         if(fodInfos->unicode)\r
         {\r
@@ -810,7 +831,7 @@ HRESULT SendCustomDlgNotificationMessage(HWND hwndParentDlg, UINT uCode)
             ofnNotify.hdr.code = uCode;\r
             ofnNotify.lpOFN = fodInfos->ofnInfos;\r
             ofnNotify.pszFile = NULL;\r
-           ret = SendMessageW(fodInfos->DlgInfos.hwndCustomDlg,WM_NOTIFY,0,(LPARAM)&ofnNotify);\r
+            SendMessageW(fodInfos->DlgInfos.hwndCustomDlg,WM_NOTIFY,0,(LPARAM)&ofnNotify);\r
         }\r
         else\r
         {\r
@@ -820,17 +841,15 @@ HRESULT SendCustomDlgNotificationMessage(HWND hwndParentDlg, UINT uCode)
             ofnNotify.hdr.code = uCode;\r
             ofnNotify.lpOFN = (LPOPENFILENAMEA)fodInfos->ofnInfos;\r
             ofnNotify.pszFile = NULL;\r
-           ret = SendMessageA(fodInfos->DlgInfos.hwndCustomDlg,WM_NOTIFY,0,(LPARAM)&ofnNotify);\r
+            SendMessageA(fodInfos->DlgInfos.hwndCustomDlg,WM_NOTIFY,0,(LPARAM)&ofnNotify);\r
         }\r
        TRACE("RET NOTIFY\n");\r
-       return ret;\r
     }\r
-    return TRUE;\r
 }\r
 \r
-HRESULT FILEDLG95_Handle_GetFilePath(HWND hwnd, DWORD size, LPVOID buffer)\r
+static INT_PTR FILEDLG95_Handle_GetFilePath(HWND hwnd, DWORD size, LPVOID buffer)\r
 {\r
-    UINT sizeUsed = 0, n, total;\r
+    INT_PTR sizeUsed = 0, n, total;\r
     LPWSTR lpstrFileList = NULL;\r
     WCHAR lpstrCurrentDir[MAX_PATH];\r
     FileOpenDlgInfos *fodInfos = (FileOpenDlgInfos *) GetPropA(hwnd,FileOpenDlgInfosStr);\r
@@ -841,7 +860,7 @@ HRESULT FILEDLG95_Handle_GetFilePath(HWND hwnd, DWORD size, LPVOID buffer)
         return -1;\r
 \r
     /* get path and filenames */\r
-    SHGetPathFromIDListW(fodInfos->ShellInfos.pidlAbsCurrent,lpstrCurrentDir);\r
+    COMDLG32_GetDisplayNameOf(fodInfos->ShellInfos.pidlAbsCurrent, lpstrCurrentDir);\r
     n = FILEDLG95_FILENAME_GetFileNames(hwnd, &lpstrFileList, &sizeUsed, ' ');\r
 \r
     TRACE("path >%s< filespec >%s< %d files\n",\r
@@ -890,9 +909,9 @@ HRESULT FILEDLG95_Handle_GetFilePath(HWND hwnd, DWORD size, LPVOID buffer)
     return total;\r
 }\r
 \r
-HRESULT FILEDLG95_Handle_GetFileSpec(HWND hwnd, DWORD size, LPVOID buffer)\r
+static INT_PTR FILEDLG95_Handle_GetFileSpec(HWND hwnd, DWORD size, LPVOID buffer)\r
 {\r
-    UINT sizeUsed = 0;\r
+    INT_PTR sizeUsed = 0;\r
     LPWSTR lpstrFileList = NULL;\r
     FileOpenDlgInfos *fodInfos = (FileOpenDlgInfos *) GetPropA(hwnd,FileOpenDlgInfosStr);\r
 \r
@@ -922,37 +941,37 @@ HRESULT FILEDLG95_Handle_GetFileSpec(HWND hwnd, DWORD size, LPVOID buffer)
 *\r
 * Handle Custom Dialog Messages (CDM_FIRST -- CDM_LAST) messages\r
 */\r
-HRESULT FILEDLG95_HandleCustomDialogMessages(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)\r
+static INT_PTR FILEDLG95_HandleCustomDialogMessages(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)\r
 {\r
     FileOpenDlgInfos *fodInfos = (FileOpenDlgInfos *) GetPropA(hwnd,FileOpenDlgInfosStr);\r
-    if(!fodInfos) return -1;\r
+    WCHAR lpstrPath[MAX_PATH];\r
+    INT_PTR retval;\r
+\r
+    if(!fodInfos) return FALSE;\r
 \r
     switch(uMsg)\r
     {\r
         case CDM_GETFILEPATH:\r
-            return FILEDLG95_Handle_GetFilePath(hwnd, (UINT)wParam, (LPVOID)lParam);\r
+            retval = FILEDLG95_Handle_GetFilePath(hwnd, (UINT)wParam, (LPVOID)lParam);\r
+            break;\r
 \r
         case CDM_GETFOLDERPATH:\r
             TRACE("CDM_GETFOLDERPATH:\n");\r
-            if( fodInfos->unicode )\r
-            {\r
-                WCHAR lpstrPath[MAX_PATH], *bufW = (LPWSTR)lParam;\r
-               SHGetPathFromIDListW(fodInfos->ShellInfos.pidlAbsCurrent,lpstrPath);\r
-                if (bufW)\r
-                    lstrcpynW(bufW,lpstrPath,(int)wParam);\r
-                return strlenW(lpstrPath);\r
-            }\r
-            else\r
+            COMDLG32_GetDisplayNameOf(fodInfos->ShellInfos.pidlAbsCurrent, lpstrPath);\r
+            if (lParam) \r
             {\r
-                char lpstrPath[MAX_PATH], *bufA = (LPSTR)lParam;\r
-               SHGetPathFromIDListA(fodInfos->ShellInfos.pidlAbsCurrent,lpstrPath);\r
-                if (bufA)\r
-                    lstrcpynA(bufA,lpstrPath,(int)wParam);\r
-                return strlen(lpstrPath);\r
-            }\r
+                if (fodInfos->unicode)\r
+                    lstrcpynW((LPWSTR)lParam, lpstrPath, (int)wParam);\r
+                else\r
+                    WideCharToMultiByte(CP_ACP, 0, lpstrPath, -1, \r
+                                        (LPSTR)lParam, (int)wParam, NULL, NULL);\r
+            }        \r
+            retval = strlenW(lpstrPath);\r
+            break;\r
 \r
         case CDM_GETSPEC:\r
-            return FILEDLG95_Handle_GetFileSpec(hwnd, (UINT)wParam, (LPSTR)lParam);\r
+            retval = FILEDLG95_Handle_GetFileSpec(hwnd, (UINT)wParam, (LPSTR)lParam);\r
+            break;\r
 \r
         case CDM_SETCONTROLTEXT:\r
             TRACE("CDM_SETCONTROLTEXT:\n");\r
@@ -963,13 +982,19 @@ HRESULT FILEDLG95_HandleCustomDialogMessages(HWND hwnd, UINT uMsg, WPARAM wParam
                 else\r
                    SetDlgItemTextA( hwnd, (UINT) wParam, (LPSTR) lParam );\r
             }\r
-           return TRUE;\r
+            retval = TRUE;\r
+            break;\r
 \r
         case CDM_HIDECONTROL:\r
         case CDM_SETDEFEXT:\r
             FIXME("CDM_HIDECONTROL,CDM_SETCONTROLTEXT,CDM_SETDEFEXT not implemented\n");\r
-            return -1;\r
+            retval =  -1;\r
+            break;\r
+\r
+        default:\r
+            return FALSE;\r
     }\r
+    SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, retval);\r
     return TRUE;\r
 }\r
 \r
@@ -1597,7 +1622,7 @@ BOOL FILEDLG95_OnOpenMultipleFiles(HWND hwnd, LPWSTR lpstrFileList, UINT nFileCo
      ofn->lpstrFile[0] = '\0';\r
   }\r
 \r
-  SHGetPathFromIDListW( fodInfos->ShellInfos.pidlAbsCurrent, lpstrPathSpec );\r
+  COMDLG32_GetDisplayNameOf( fodInfos->ShellInfos.pidlAbsCurrent, lpstrPathSpec );\r
 \r
   if ( !(fodInfos->ofnInfos->Flags & OFN_NOVALIDATE) &&\r
       ( fodInfos->ofnInfos->Flags & OFN_FILEMUSTEXIST) &&\r
@@ -1685,9 +1710,8 @@ BOOL FILEDLG95_OnOpenMultipleFiles(HWND hwnd, LPWSTR lpstrFileList, UINT nFileCo
  *\r
  * If the function succeeds, the return value is nonzero.\r
  */\r
-#define ONOPEN_BROWSE 1\r
-#define ONOPEN_OPEN   2\r
-#define ONOPEN_SEARCH 3\r
+#define ONOPEN_OPEN   1\r
+#define ONOPEN_SEARCH 2\r
 static void FILEDLG95_OnOpenMessage(HWND hwnd, int idCaption, int idText)\r
 {\r
   WCHAR strMsgTitle[MAX_PATH];\r
@@ -1714,15 +1738,15 @@ BOOL FILEDLG95_OnOpen(HWND hwnd)
 \r
   TRACE("hwnd=%p\n", hwnd);\r
 \r
+  if(BrowseSelectedFolder(hwnd))\r
+      return FALSE;\r
+\r
   /* get the files from the edit control */\r
   nFileCount = FILEDLG95_FILENAME_GetFileNames(hwnd, &lpstrFileList, &sizeUsed, '\0');\r
 \r
   /* try if the user selected a folder in the shellview */\r
   if(nFileCount == 0)\r
-  {\r
-      BrowseSelectedFolder(hwnd);\r
       return FALSE;\r
-  }\r
 \r
   if(nFileCount > 1)\r
   {\r
@@ -1742,14 +1766,10 @@ BOOL FILEDLG95_OnOpen(HWND hwnd)
 */\r
 \r
   /* Get the current directory name */\r
-  if (!SHGetPathFromIDListW(fodInfos->ShellInfos.pidlAbsCurrent, lpstrPathAndFile))\r
+  if (!COMDLG32_GetDisplayNameOf(fodInfos->ShellInfos.pidlAbsCurrent, lpstrPathAndFile))\r
   {\r
-    /* we are in a special folder, default to desktop */\r
-    if(FAILED(COMDLG32_SHGetFolderPathW(hwnd, CSIDL_DESKTOPDIRECTORY|CSIDL_FLAG_CREATE, 0, 0, lpstrPathAndFile)))\r
-    {\r
-      /* last fallback */\r
-      GetCurrentDirectoryW(MAX_PATH, lpstrPathAndFile);\r
-    }\r
+    /* last fallback */\r
+    GetCurrentDirectoryW(MAX_PATH, lpstrPathAndFile);\r
   }\r
   PathAddBackslashW(lpstrPathAndFile);\r
 \r
@@ -1787,7 +1807,7 @@ BOOL FILEDLG95_OnOpen(HWND hwnd)
     lpstrPathAndFile: cleaned up path\r
  */\r
 \r
-  nOpenAction = ONOPEN_BROWSE;\r
+  nOpenAction = ONOPEN_OPEN;\r
 \r
   /* don't apply any checks with OFN_NOVALIDATE */\r
   {\r
@@ -1920,6 +1940,7 @@ BOOL FILEDLG95_OnOpen(HWND hwnd)
         int iPos;\r
         LPWSTR lpszTemp = PathFindFileNameW(lpstrPathAndFile);\r
         DWORD len;\r
+       IPersistFolder2 * ppf2;\r
 \r
         /* replace the current filter */\r
         if(fodInfos->ShellInfos.lpstrCurrentFilter)\r
@@ -1931,12 +1952,7 @@ BOOL FILEDLG95_OnOpen(HWND hwnd)
         /* set the filter cb to the extension when possible */\r
         if(-1 < (iPos = FILEDLG95_FILETYPE_SearchExt(fodInfos->DlgInfos.hwndFileTypeCB, lpszTemp)))\r
         CBSetCurSel(fodInfos->DlgInfos.hwndFileTypeCB, iPos);\r
-      }\r
-      /* fall through */\r
-    case ONOPEN_BROWSE:   /* browse to the highest folder we could bind to */\r
-      TRACE("ONOPEN_BROWSE\n");\r
-      {\r
-       IPersistFolder2 * ppf2;\r
+\r
         if(SUCCEEDED(IShellFolder_QueryInterface( lpsf, &IID_IPersistFolder2, (LPVOID*)&ppf2)))\r
         {\r
           LPITEMIDLIST pidlCurrent;\r
@@ -1946,10 +1962,11 @@ BOOL FILEDLG95_OnOpen(HWND hwnd)
          {\r
            IShellBrowser_BrowseObject(fodInfos->Shell.FOIShellBrowser, pidlCurrent, SBSP_ABSOLUTE);\r
          }\r
-         else if( nOpenAction == ONOPEN_SEARCH )\r
+         else\r
          {\r
             IShellView_Refresh(fodInfos->Shell.FOIShellView);\r
          }\r
+          SendCustomDlgNotificationMessage(hwnd, CDN_FOLDERCHANGE);\r
           COMDLG32_SHFree(pidlCurrent);\r
         }\r
       }\r
@@ -1967,48 +1984,51 @@ BOOL FILEDLG95_OnOpen(HWND hwnd)
          fodInfos->ofnInfos->Flags &= ~OFN_READONLY;\r
 \r
         /* Attach the file extension with file name*/\r
-        ext = PathFindExtensionW(lpstrPathAndFile);\r
-        if (! *ext)\r
+\r
+        if(!PathIsDirectoryW(lpstrPathAndFile))\r
         {\r
-            /* if no extension is specified with file name, then */\r
-            /* attach the extension from file filter or default one */\r
+            if((ext = PathFindExtensionW(lpstrPathAndFile)) == NULL)\r
+            {\r
+                /* if no extension is specified with file name, then */\r
+                /* attach the extension from file filter or default one */\r
             \r
-            WCHAR *filterExt = NULL;\r
-            LPWSTR lpstrFilter = NULL;\r
-            static const WCHAR szwDot[] = {'.',0};\r
-            int PathLength = strlenW(lpstrPathAndFile);\r
+                WCHAR *filterExt = NULL;\r
+                LPWSTR lpstrFilter = NULL;\r
+                static const WCHAR szwDot[] = {'.',0};\r
+                int PathLength = strlenW(lpstrPathAndFile);\r
 \r
-            /* Attach the dot*/\r
-            strcatW(lpstrPathAndFile, szwDot);\r
+                /* Attach the dot*/\r
+                strcatW(lpstrPathAndFile, szwDot);\r
     \r
-            /*Get the file extension from file type filter*/\r
-            lpstrFilter = (LPWSTR) CBGetItemDataPtr(fodInfos->DlgInfos.hwndFileTypeCB,\r
-                                             fodInfos->ofnInfos->nFilterIndex-1);\r
+                /*Get the file extension from file type filter*/\r
+                lpstrFilter = (LPWSTR) CBGetItemDataPtr(fodInfos->DlgInfos.hwndFileTypeCB,\r
+                                                        fodInfos->ofnInfos->nFilterIndex-1);\r
 \r
-            if (lpstrFilter != (LPWSTR)CB_ERR)  /* control is not empty */\r
-                filterExt = PathFindExtensionW(lpstrFilter);\r
+                if (lpstrFilter != (LPWSTR)CB_ERR)  /* control is not empty */\r
+                    filterExt = PathFindExtensionW(lpstrFilter);\r
 \r
-            if ( filterExt && *filterExt ) /* attach the file extension from file type filter*/\r
-                strcatW(lpstrPathAndFile, filterExt + 1);\r
-            else if ( fodInfos->defext ) /* attach the default file extension*/\r
-                strcatW(lpstrPathAndFile, fodInfos->defext);\r
+                if ( filterExt && *filterExt ) /* attach the file extension from file type filter*/\r
+                    strcatW(lpstrPathAndFile, filterExt + 1);\r
+                else if ( fodInfos->defext ) /* attach the default file extension*/\r
+                    strcatW(lpstrPathAndFile, fodInfos->defext);\r
 \r
-            /* In Open dialog: if file does not exist try without extension */\r
-            if (!(fodInfos->DlgInfos.dwDlgProp & FODPROP_SAVEDLG) && !PathFileExistsW(lpstrPathAndFile))\r
-                  lpstrPathAndFile[PathLength] = '\0';\r
+                /* In Open dialog: if file does not exist try without extension */\r
+                if (!(fodInfos->DlgInfos.dwDlgProp & FODPROP_SAVEDLG) && !PathFileExistsW(lpstrPathAndFile))\r
+                    lpstrPathAndFile[PathLength] = '\0';\r
+            }\r
+        \r
+            if (fodInfos->defext) /* add default extension */\r
+            {\r
+                /* Set/clear the output OFN_EXTENSIONDIFFERENT flag */\r
+                if (*ext)\r
+                    ext++;\r
+                if (!lstrcmpiW(fodInfos->defext, ext))\r
+                    fodInfos->ofnInfos->Flags &= ~OFN_EXTENSIONDIFFERENT;\r
+                else\r
+                    fodInfos->ofnInfos->Flags |= OFN_EXTENSIONDIFFERENT;\r
+            }\r
         }\r
 \r
-       if (fodInfos->defext) /* add default extension */\r
-       {\r
-         /* Set/clear the output OFN_EXTENSIONDIFFERENT flag */\r
-         if (*ext)\r
-           ext++;\r
-         if (!lstrcmpiW(fodInfos->defext, ext))\r
-           fodInfos->ofnInfos->Flags &= ~OFN_EXTENSIONDIFFERENT;\r
-         else\r
-           fodInfos->ofnInfos->Flags |= OFN_EXTENSIONDIFFERENT;\r
-       }\r
-\r
        /* In Save dialog: check if the file already exists */\r
        if (fodInfos->DlgInfos.dwDlgProp & FODPROP_SAVEDLG\r
            && fodInfos->ofnInfos->Flags & OFN_OVERWRITEPROMPT\r
@@ -2208,6 +2228,7 @@ static BOOL FILEDLG95_SHELL_UpFolder(HWND hwnd)
                                           NULL,\r
                                           SBSP_PARENT)))\r
   {\r
+    SendCustomDlgNotificationMessage(hwnd, CDN_FOLDERCHANGE);\r
     return TRUE;\r
   }\r
   return FALSE;\r
@@ -2229,6 +2250,7 @@ static BOOL FILEDLG95_SHELL_BrowseToDesktop(HWND hwnd)
 \r
   SHGetSpecialFolderLocation(0,CSIDL_DESKTOP,&pidl);\r
   hres = IShellBrowser_BrowseObject(fodInfos->Shell.FOIShellBrowser, pidl, SBSP_ABSOLUTE);\r
+  SendCustomDlgNotificationMessage(hwnd, CDN_FOLDERCHANGE);\r
   COMDLG32_SHFree(pidl);\r
   return SUCCEEDED(hres);\r
 }\r
@@ -2361,8 +2383,7 @@ static HRESULT FILEDLG95_FILETYPE_Init(HWND hwnd)
     }\r
   } else\r
       fodInfos->ofnInfos->nFilterIndex = 0;\r
-\r
-  return NOERROR;\r
+  return S_OK;\r
 }\r
 \r
 /***********************************************************************\r
@@ -2465,7 +2486,7 @@ static void FILEDLG95_FILETYPE_Clean(HWND hwnd)
  *\r
  * Initialisation of the look in combo box\r
  */\r
-static HRESULT FILEDLG95_LOOKIN_Init(HWND hwndCombo)\r
+static void FILEDLG95_LOOKIN_Init(HWND hwndCombo)\r
 {\r
   IShellFolder *psfRoot, *psfDrives;\r
   IEnumIDList  *lpeRoot, *lpeDrives;\r
@@ -2532,7 +2553,6 @@ static HRESULT FILEDLG95_LOOKIN_Init(HWND hwndCombo)
   }\r
 \r
   COMDLG32_SHFree(pidlDrives);\r
-  return NOERROR;\r
 }\r
 \r
 /***********************************************************************\r
@@ -2680,6 +2700,7 @@ static BOOL FILEDLG95_LOOKIN_OnCommand(HWND hwnd, WORD wNotifyCode)
                                               tmpFolder->pidlItem,\r
                                               SBSP_ABSOLUTE)))\r
       {\r
+        SendCustomDlgNotificationMessage(hwnd, CDN_FOLDERCHANGE);\r
         return TRUE;\r
       }\r
       break;\r
@@ -3009,7 +3030,9 @@ void FILEDLG95_FILENAME_FillFromSelection (HWND hwnd)
 }\r
 \r
 \r
-/* copied from shell32 to avoid linking to it */\r
+/* copied from shell32 to avoid linking to it\r
+ * FIXME: why?  shell32 is already linked\r
+ */\r
 static HRESULT COMDLG32_StrRetToStrNA (LPVOID dest, DWORD len, LPSTRRET src, LPITEMIDLIST pidl)\r
 {\r
        switch (src->uType)\r
@@ -3033,7 +3056,7 @@ static HRESULT COMDLG32_StrRetToStrNA (LPVOID dest, DWORD len, LPSTRRET src, LPI
            {\r
              *(LPSTR)dest = '\0';\r
            }\r
-           return(FALSE);\r
+           return(E_FAIL);\r
        }\r
        return S_OK;\r
 }\r
@@ -3045,7 +3068,7 @@ static HRESULT COMDLG32_StrRetToStrNA (LPVOID dest, DWORD len, LPSTRRET src, LPI
  * The delimiter is specified by the parameter 'separator',\r
  *  usually either a space or a nul\r
  */\r
-int FILEDLG95_FILENAME_GetFileNames (HWND hwnd, LPWSTR * lpstrFileList, UINT * sizeUsed, char separator)\r
+static int FILEDLG95_FILENAME_GetFileNames (HWND hwnd, LPWSTR * lpstrFileList, UINT * sizeUsed, char separator)\r
 {\r
        FileOpenDlgInfos *fodInfos  = (FileOpenDlgInfos *) GetPropA(hwnd,FileOpenDlgInfosStr);\r
        UINT nStrCharCount = 0; /* index in src buffer */\r
@@ -3211,7 +3234,7 @@ UINT GetNumSelected( IDataObject *doSelected )
  * E_FAIL otherwise\r
  */\r
 \r
-HRESULT GetName(LPSHELLFOLDER lpsf, LPITEMIDLIST pidl,DWORD dwFlags,LPSTR lpstrFileName)\r
+static HRESULT GetName(LPSHELLFOLDER lpsf, LPITEMIDLIST pidl,DWORD dwFlags,LPSTR lpstrFileName)\r
 {\r
   STRRET str;\r
   HRESULT hRes;\r
@@ -3351,8 +3374,8 @@ static BOOL BrowseSelectedFolder(HWND hwnd)
                                    ' ','n','o','t',' ','e','x','i','s','t',0};\r
                MessageBoxW( hwnd, notexist, fodInfos->title, MB_OK | MB_ICONEXCLAMATION );\r
           }\r
-\r
-         bBrowseSelFolder = TRUE;\r
+          bBrowseSelFolder = TRUE;\r
+          SendCustomDlgNotificationMessage(hwnd,CDN_FOLDERCHANGE);\r
       }\r
       COMDLG32_SHFree( pidlSelection );\r
   }\r
index 51bca31..7b9173a 100644 (file)
@@ -47,9 +47,9 @@ WINE_DEFAULT_DEBUG_CHANNEL(commdlg);
 typedef struct\r
 {\r
 \r
-    IShellBrowserVtbl   * lpVtbl;\r
-    ICommDlgBrowserVtbl * lpVtblCommDlgBrowser;\r
-    IServiceProviderVtbl* lpVtblServiceProvider;\r
+    const IShellBrowserVtbl *lpVtbl;\r
+    const ICommDlgBrowserVtbl *lpVtblCommDlgBrowser;\r
+    const IServiceProviderVtbl *lpVtblServiceProvider;\r
     DWORD ref;                                  /* Reference counter */\r
     HWND hwndOwner;                             /* Owner dialog of the interface */\r
 \r
@@ -58,9 +58,9 @@ typedef struct
 /**************************************************************************\r
 *   vtable\r
 */\r
-static IShellBrowserVtbl IShellBrowserImpl_Vtbl;\r
-static ICommDlgBrowserVtbl IShellBrowserImpl_ICommDlgBrowser_Vtbl;\r
-static IServiceProviderVtbl IShellBrowserImpl_IServiceProvider_Vtbl;\r
+static const IShellBrowserVtbl IShellBrowserImpl_Vtbl;\r
+static const ICommDlgBrowserVtbl IShellBrowserImpl_ICommDlgBrowser_Vtbl;\r
+static const IServiceProviderVtbl IShellBrowserImpl_IServiceProvider_Vtbl;\r
 \r
 /**************************************************************************\r
 *   Local Prototypes\r
@@ -76,19 +76,12 @@ LPITEMIDLIST GetSelectedPidl(IShellView *ppshv);
 */\r
 extern const char *FileOpenDlgInfosStr;\r
 \r
-extern HRESULT          GetName(LPSHELLFOLDER lpsf, LPITEMIDLIST pidl,DWORD dwFlags,LPSTR lpstrFileName);\r
-extern HRESULT          GetFileName(HWND hwnd, LPITEMIDLIST pidl, LPSTR lpstrFileName);\r
 extern IShellFolder*    GetShellFolderFromPidl(LPITEMIDLIST pidlAbs);\r
 extern LPITEMIDLIST     GetParentPidl(LPITEMIDLIST pidl);\r
 extern LPITEMIDLIST     GetPidlFromName(IShellFolder *psf,LPCSTR lpcstrFileName);\r
 \r
-extern BOOL    FILEDLG95_SHELL_FillIncludedItemList(HWND hwnd,\r
-                                                        LPITEMIDLIST pidlCurrentFolder,\r
-                                                        LPSTR lpstrMask);\r
-\r
 extern int     FILEDLG95_LOOKIN_SelectItem(HWND hwnd,LPITEMIDLIST pidl);\r
-extern BOOL    FILEDLG95_OnOpen(HWND hwnd);\r
-extern HRESULT SendCustomDlgNotificationMessage(HWND hwndParentDlg, UINT uCode);\r
+extern void    SendCustomDlgNotificationMessage(HWND hwndParentDlg, UINT uCode);\r
 \r
 \r
 /*\r
@@ -140,11 +133,25 @@ static void COMDLG32_DumpSBSPFlags(UINT uflags)
 \r
 static void COMDLG32_UpdateCurrentDir(FileOpenDlgInfos *fodInfos)\r
 {\r
-    char lpstrPath[MAX_PATH];\r
-    if(SHGetPathFromIDListA(fodInfos->ShellInfos.pidlAbsCurrent,lpstrPath)) {\r
-        SetCurrentDirectoryA(lpstrPath);\r
-        TRACE("new current folder %s\n", lpstrPath);\r
+    LPSHELLFOLDER psfDesktop;\r
+    STRRET strret;\r
+    HRESULT res;\r
+\r
+    res = SHGetDesktopFolder(&psfDesktop);\r
+    if (FAILED(res))\r
+        return;\r
+    \r
+    res = IShellFolder_GetDisplayNameOf(psfDesktop, fodInfos->ShellInfos.pidlAbsCurrent,\r
+                                        SHGDN_FORPARSING, &strret);\r
+    if (SUCCEEDED(res)) {\r
+        WCHAR wszCurrentDir[MAX_PATH];\r
+        \r
+        res = StrRetToBufW(&strret, fodInfos->ShellInfos.pidlAbsCurrent, wszCurrentDir, MAX_PATH);\r
+        if (SUCCEEDED(res))\r
+            SetCurrentDirectoryW(wszCurrentDir);\r
     }\r
+    \r
+    IShellFolder_Release(psfDesktop);\r
 }\r
 \r
 /* copied from shell32 to avoid linking to it */\r
@@ -675,7 +682,7 @@ HRESULT WINAPI IShellBrowserImpl_TranslateAcceleratorSB(IShellBrowser *iface,
     return E_NOTIMPL;\r
 }\r
 \r
-static IShellBrowserVtbl IShellBrowserImpl_Vtbl =\r
+static const IShellBrowserVtbl IShellBrowserImpl_Vtbl =\r
 {\r
         /* IUnknown */\r
         IShellBrowserImpl_QueryInterface,\r
@@ -900,7 +907,7 @@ HRESULT IShellBrowserImpl_ICommDlgBrowser_OnSelChange(ICommDlgBrowser *iface, IS
     return S_OK;\r
 }\r
 \r
-static ICommDlgBrowserVtbl IShellBrowserImpl_ICommDlgBrowser_Vtbl =\r
+static const ICommDlgBrowserVtbl IShellBrowserImpl_ICommDlgBrowser_Vtbl =\r
 {\r
         /* IUnknown */\r
         IShellBrowserImpl_ICommDlgBrowser_QueryInterface,\r
@@ -989,7 +996,7 @@ HRESULT WINAPI IShellBrowserImpl_IServiceProvider_QueryService(
 \r
 }\r
 \r
-static IServiceProviderVtbl IShellBrowserImpl_IServiceProvider_Vtbl =\r
+static const IServiceProviderVtbl IShellBrowserImpl_IServiceProvider_Vtbl =\r
 {\r
         /* IUnknown */\r
         IShellBrowserImpl_IServiceProvider_QueryInterface,\r
index 93543cf..f537045 100644 (file)
@@ -161,6 +161,5 @@ BOOL IsPidlFolder (LPSHELLFOLDER psf, LPCITEMIDLIST pidl);
 \r
 /* Functions used by the EDIT box */\r
 void FILEDLG95_FILENAME_FillFromSelection (HWND hwnd);\r
-int FILEDLG95_FILENAME_GetFileNames (HWND hwnd, LPWSTR * lpstrFileList, UINT * sizeUsed, char separator);\r
 \r
 #endif /*SHBROWSER_H*/\r
index 322b3d1..c763513 100644 (file)
@@ -1945,11 +1945,6 @@ static BOOL PRINTDLG_CreateDCW(LPPRINTDLGW lppd)
  *  PrintDlg:\r
  *  * The Collate Icons do not display, even though they are in the code.\r
  *  * The Properties Button(s) should call DocumentPropertiesA().\r
- *  PrintSetupDlg:\r
- *  * The Paper Orientation Icons are not implemented yet.\r
- *  * The Properties Button(s) should call DocumentPropertiesA().\r
- *  * Settings are not yet taken from a provided DevMode or\r
- *    default printer settings.\r
  */\r
 \r
 BOOL WINAPI PrintDlgA(\r
@@ -2266,6 +2261,7 @@ BOOL WINAPI PrintDlgW(
  *          PageSetupDlg\r
  * rad1 - portrait\r
  * rad2 - landscape\r
+ * cmb1 - printer select (not in standart dialog template)\r
  * cmb2 - paper size\r
  * cmb3 - source (tray?)\r
  * edt4 - border left\r
@@ -2609,24 +2605,153 @@ PRINTDLG_PS_WMCommandW(
 }\r
 \r
 \r
+/***********************************************************************\r
+ *           DefaultPagePaintHook\r
+ * Default hook paint procedure that receives WM_PSD_* messages from the dialog box \r
+ * whenever the sample page is redrawn.\r
+*/\r
+\r
+static UINT_PTR\r
+PRINTDLG_DefaultPagePaintHook(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam, PageSetupDataA *pda)\r
+{\r
+    LPRECT lprc = (LPRECT) lParam;\r
+    HDC hdc = (HDC) wParam;\r
+    HPEN hpen, holdpen;\r
+    LOGFONTW lf;\r
+    HFONT hfont, holdfont;\r
+    INT oldbkmode;\r
+    TRACE("uMsg: WM_USER+%d\n",uMsg-WM_USER);\r
+\r
+    /* Call user paint hook if enable */\r
+    if (pda->dlga->Flags & PSD_ENABLEPAGEPAINTHOOK)\r
+        if (pda->dlga->lpfnPagePaintHook(hwndDlg, uMsg, wParam, lParam))\r
+            return TRUE;\r
+\r
+    switch (uMsg) {\r
+       /* LPPAGESETUPDLG in lParam */\r
+       case WM_PSD_PAGESETUPDLG:\r
+       /* Inform about the sample page rectangle */\r
+       case WM_PSD_FULLPAGERECT:\r
+       /* Inform about the margin rectangle */\r
+       case WM_PSD_MINMARGINRECT:\r
+            return FALSE;\r
+\r
+        /* Draw dashed rectangle showing margins */\r
+        case WM_PSD_MARGINRECT:\r
+            hpen = CreatePen(PS_DASH, 1, GetSysColor(COLOR_3DSHADOW));\r
+            holdpen = SelectObject(hdc, hpen);\r
+            Rectangle(hdc, lprc->left, lprc->top, lprc->right, lprc->bottom);\r
+            DeleteObject(SelectObject(hdc, holdpen));\r
+            return TRUE;\r
+\r
+\r
+        /* Draw the fake document */\r
+        case WM_PSD_GREEKTEXTRECT:\r
+            /* select a nice scalable font, because we want the text really small */\r
+            SystemParametersInfoW(SPI_GETICONTITLELOGFONT, sizeof(lf), &lf, 0);\r
+            lf.lfHeight = 6; /* value chosen based on visual effect */\r
+            hfont = CreateFontIndirectW(&lf);\r
+            holdfont = SelectObject(hdc, hfont);\r
+\r
+            /* if text not loaded, then do so now */\r
+            if (wszFakeDocumentText[0] == '\0')\r
+                 LoadStringW(COMDLG32_hInstance,\r
+                        IDS_FAKEDOCTEXT,\r
+                        wszFakeDocumentText,\r
+                        sizeof(wszFakeDocumentText)/sizeof(wszFakeDocumentText[0]));\r
+\r
+            oldbkmode = SetBkMode(hdc, TRANSPARENT);\r
+            DrawTextW(hdc, wszFakeDocumentText, -1, lprc, DT_TOP|DT_LEFT|DT_NOPREFIX|DT_WORDBREAK);\r
+            SetBkMode(hdc, oldbkmode);\r
+\r
+            DeleteObject(SelectObject(hdc, holdfont));\r
+            return TRUE;\r
+\r
+        /* Envelope stamp */\r
+        case WM_PSD_ENVSTAMPRECT:\r
+        /* Return address */\r
+        case WM_PSD_YAFULLPAGERECT:\r
+            FIXME("envelope/stamp is not implemented\n");\r
+            return FALSE;\r
+        default:\r
+            FIXME("Unknown message %x\n",uMsg);\r
+            return FALSE;\r
+    }\r
+    return TRUE;\r
+}\r
+\r
+/***********************************************************************\r
+ *           PagePaintProc\r
+ * The main paint procedure for the PageSetupDlg function.\r
+ * The Page Setup dialog box includes an image of a sample page that shows how\r
+ * the user's selections affect the appearance of the printed output.\r
+ * The image consists of a rectangle that represents the selected paper\r
+ * or envelope type, with a dotted-line rectangle representing\r
+ * the current margins, and partial (Greek text) characters\r
+ * to show how text looks on the printed page. \r
+ *\r
+ * The following messages in the order sends to user hook procedure:\r
+ *   WM_PSD_PAGESETUPDLG    Draw the contents of the sample page\r
+ *   WM_PSD_FULLPAGERECT    Inform about the bounding rectangle\r
+ *   WM_PSD_MINMARGINRECT   Inform about the margin rectangle (min margin?)\r
+ *   WM_PSD_MARGINRECT      Draw the margin rectangle\r
+ *   WM_PSD_GREEKTEXTRECT   Draw the Greek text inside the margin rectangle\r
+ * If any of first three messages returns TRUE, painting done.\r
+ *\r
+ * PARAMS:\r
+ *   hWnd   [in] Handle to the Page Setup dialog box\r
+ *   uMsg   [in] Received message\r
+ *\r
+ * TODO:\r
+ *   WM_PSD_ENVSTAMPRECT    Draw in the envelope-stamp rectangle (for envelopes only)\r
+ *   WM_PSD_YAFULLPAGERECT  Draw the return address portion (for envelopes and other paper sizes)\r
+ *\r
+ * RETURNS:\r
+ *   FALSE if all done correctly\r
+ *\r
+ */\r
 static LRESULT CALLBACK\r
-PagePaintProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)\r
+PRINTDLG_PagePaintProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)\r
 {\r
-    if (uMsg == WM_PAINT)\r
-    {\r
-        PAINTSTRUCT ps;\r
-        RECT rcClient;\r
-        HPEN hpen, holdpen;\r
-        HDC hdc;\r
-        HFONT hfont, holdfont;\r
-        LOGFONTW lf;\r
-        HBRUSH hbrush, holdbrush;\r
-        INT oldbkmode;\r
+    PAINTSTRUCT ps;\r
+    RECT rcClient, rcMargin;\r
+    HPEN hpen, holdpen;\r
+    HDC hdc;\r
+    HBRUSH hbrush, holdbrush;\r
+    PageSetupDataA *pda;\r
+    int papersize=0, orientation=0; /* FIXME: set this values */\r
+\r
+#define CALLPAINTHOOK(msg,lprc) PRINTDLG_DefaultPagePaintHook( hWnd, msg, (WPARAM)hdc, (LPARAM)lprc, pda)\r
+\r
+    if (uMsg != WM_PAINT)\r
+        return CallWindowProcA(lpfnStaticWndProc, hWnd, uMsg, wParam, lParam);\r
+\r
+    /* Processing WM_PAINT message */\r
+    pda = (PageSetupDataA*)GetPropA(hWnd, "__WINE_PAGESETUPDLGDATA");\r
+    if (!pda) {\r
+        WARN("__WINE_PAGESETUPDLGDATA prop not set?\n");\r
+        return FALSE;\r
+    }\r
+    if (PRINTDLG_DefaultPagePaintHook(hWnd, WM_PSD_PAGESETUPDLG, MAKELONG(papersize, orientation), (LPARAM)pda->dlga, pda))\r
+        return FALSE;\r
 \r
-        hdc = BeginPaint(hWnd, &ps);\r
+    hdc = BeginPaint(hWnd, &ps);\r
+    GetClientRect(hWnd, &rcClient);\r
 \r
-        GetClientRect(hWnd, &rcClient);\r
+    /* FIXME: use real margin values */\r
+    rcMargin = rcClient;\r
+    rcMargin.left += 5;\r
+    rcMargin.top += 5;\r
+    rcMargin.right -= 5;\r
+    rcMargin.bottom -= 5;\r
 \r
+    /* if the space is too small then we make sure to not draw anything */\r
+    rcMargin.left = min(rcMargin.left, rcMargin.right);\r
+    rcMargin.top = min(rcMargin.top, rcMargin.bottom);\r
+\r
+    if (!CALLPAINTHOOK(WM_PSD_FULLPAGERECT, &rcClient) &&\r
+        !CALLPAINTHOOK(WM_PSD_MINMARGINRECT, &rcMargin) )\r
+    {\r
         /* fill background */\r
         hbrush = GetSysColorBrush(COLOR_3DHIGHLIGHT);\r
         FillRect(hdc, &rcClient, hbrush);\r
@@ -2635,6 +2760,7 @@ PagePaintProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
         hpen = CreatePen(PS_SOLID, 1, GetSysColor(COLOR_3DSHADOW));\r
         holdpen = SelectObject(hdc, hpen);\r
 \r
+        \r
         /* paint left edge */\r
         MoveToEx(hdc, rcClient.left, rcClient.top, NULL);\r
         LineTo(hdc, rcClient.left, rcClient.bottom-1);\r
@@ -2654,79 +2780,51 @@ PagePaintProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
         MoveToEx(hdc, rcClient.left, rcClient.bottom-1, NULL);\r
         LineTo(hdc, rcClient.right, rcClient.bottom-1);\r
 \r
-        hpen = CreatePen(PS_DASH, 1, GetSysColor(COLOR_3DSHADOW));\r
-        DeleteObject(SelectObject(hdc, hpen));\r
-\r
-        /* draw dashed rectangle showing margins */\r
-\r
-        /* FIXME: use real margin values */\r
-        rcClient.left += 5;\r
-        rcClient.top += 5;\r
-        rcClient.right -= 5;\r
-        rcClient.bottom -= 5;\r
-\r
-        /* if the space is too small then we make sure to not draw anything */\r
-        rcClient.left = min(rcClient.left,rcClient.right);\r
-        rcClient.top = min(rcClient.top,rcClient.bottom);\r
+        DeleteObject(SelectObject(hdc, holdpen));\r
+        DeleteObject(SelectObject(hdc, holdbrush));\r
 \r
-        Rectangle(hdc, rcClient.left, rcClient.top, rcClient.right, rcClient.bottom);\r
 \r
-        DeleteObject(SelectObject(hdc, holdpen));\r
+        CALLPAINTHOOK(WM_PSD_MARGINRECT, &rcMargin);\r
 \r
-        /* draw the fake document */\r
 \r
         /* give text a bit of a space from the frame */\r
-        rcClient.left += 2;\r
-        rcClient.top += 2;\r
-        rcClient.right -= 2;\r
-        rcClient.bottom -= 2;\r
-\r
+        rcMargin.left += 2;\r
+        rcMargin.top += 2;\r
+        rcMargin.right -= 2;\r
+        rcMargin.bottom -= 2;\r
+        \r
         /* if the space is too small then we make sure to not draw anything */\r
-        rcClient.left = min(rcClient.left,rcClient.right);\r
-        rcClient.top = min(rcClient.top,rcClient.bottom);\r
-\r
-        /* select a nice scalable font, because we want the text really small */\r
-        SystemParametersInfoW(SPI_GETICONTITLELOGFONT, sizeof(lf), &lf, 0);\r
-        lf.lfHeight = 6; /* value chosen based on visual effect */\r
-        hfont = CreateFontIndirectW(&lf);\r
-        holdfont = SelectObject(hdc, hfont);\r
-\r
-        /* if text not loaded, then do so now */\r
-        if (wszFakeDocumentText[0] == '\0')\r
-            LoadStringW(COMDLG32_hInstance,\r
-                        IDS_FAKEDOCTEXT,\r
-                        wszFakeDocumentText,\r
-                        sizeof(wszFakeDocumentText)/sizeof(wszFakeDocumentText[0]));\r
-\r
-        oldbkmode = SetBkMode(hdc, TRANSPARENT);\r
-        DrawTextW(hdc, wszFakeDocumentText, -1, &rcClient, DT_TOP|DT_LEFT|DT_NOPREFIX|DT_WORDBREAK);\r
-        SetBkMode(hdc, oldbkmode);\r
-\r
-        DeleteObject(SelectObject(hdc, holdfont));\r
+        rcMargin.left = min(rcMargin.left, rcMargin.right);\r
+        rcMargin.top = min(rcMargin.top, rcMargin.bottom);\r
 \r
-        SelectObject(hdc, holdbrush);\r
-\r
-        EndPaint(hWnd, &ps);\r
-        return 0;\r
+        CALLPAINTHOOK(WM_PSD_GREEKTEXTRECT, &rcMargin);\r
     }\r
-    else\r
-        return CallWindowProcW(lpfnStaticWndProc, hWnd, uMsg, wParam, lParam);\r
+\r
+    EndPaint(hWnd, &ps);\r
+    return FALSE;\r
+#undef CALLPAINTHOOK\r
 }\r
 \r
+/***********************************************************************\r
+ *           PRINTDLG_PageDlgProcA\r
+ * Message handler \r
+ */\r
 static INT_PTR CALLBACK\r
-PageDlgProcA(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)\r
+PRINTDLG_PageDlgProcA(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)\r
 {\r
     PageSetupDataA     *pda;\r
     INT_PTR            res = FALSE;\r
 \r
-    if (uMsg==WM_INITDIALOG) {\r
+    if (uMsg == WM_INITDIALOG) {\r
+        pda = (PageSetupDataA*)lParam;\r
+        TRACE("set property to %p", pda);\r
+        SetPropA(hDlg, "__WINE_PAGESETUPDLGDATA", pda);\r
+        SetPropA(GetDlgItem(hDlg, rct1), "__WINE_PAGESETUPDLGDATA", pda);\r
         lpfnStaticWndProc = (WNDPROC)SetWindowLongPtrW(\r
             GetDlgItem(hDlg, rct1),\r
             GWLP_WNDPROC,\r
-            (ULONG_PTR)PagePaintProc);\r
+            (ULONG_PTR)PRINTDLG_PagePaintProc);\r
        res = TRUE;\r
-        pda = (PageSetupDataA*)lParam;\r
-       SetPropA(hDlg,"__WINE_PAGESETUPDLGDATA",pda);\r
        if (pda->dlga->Flags & PSD_ENABLEPAGESETUPHOOK) {\r
            res = pda->dlga->lpfnPageSetupHook(hDlg,uMsg,wParam,(LPARAM)pda->dlga);\r
            if (!res) {\r
@@ -2734,9 +2832,7 @@ PageDlgProcA(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
                res = TRUE;\r
            }\r
        }\r
-       if (pda->dlga->Flags & PSD_ENABLEPAGEPAINTHOOK) {\r
-           FIXME("PagePaintHook not yet implemented!\n");\r
-       }\r
+\r
        if (pda->dlga->Flags & PSD_DISABLEPRINTER)\r
             EnableWindow(GetDlgItem(hDlg, psh3), FALSE);\r
        if (pda->dlga->Flags & PSD_DISABLEMARGINS) {\r
@@ -2886,7 +2982,29 @@ PageDlgProcW(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
 \r
 /***********************************************************************\r
  *            PageSetupDlgA  (COMDLG32.@)\r
+ *\r
+ *  Displays the the PAGE SETUP dialog box, which enables the user to specify\r
+ *  specific properties of a printed page such as\r
+ *  size, source, orientation and the width of the page margins.\r
+ *\r
+ * PARAMS\r
+ *  setupdlg [in] PAGESETUPDLGA struct\r
+ *\r
+ * RETURNS\r
+ *  TRUE    if the user pressed the OK button\r
+ *  FALSE   if the user cancelled the window or an error occurred\r
+ *\r
+ * NOTES\r
+ *    The values of hDevMode and hDevNames are filled on output and can be\r
+ *    changed in PAGESETUPDLG when they are passed in PageSetupDlg.\r
+ * BUGS\r
+ *  PrintSetupDlg:\r
+ *  * The Paper Orientation Icons are not implemented yet.\r
+ *  * The Properties Button(s) should call DocumentPropertiesA().\r
+ *  * Settings are not yet taken from a provided DevMode or\r
+ *    default printer settings.\r
  */\r
+\r
 BOOL WINAPI PageSetupDlgA(LPPAGESETUPDLGA setupdlg) {\r
     HGLOBAL            hDlgTmpl;\r
     LPVOID             ptr;\r
@@ -2909,6 +3027,11 @@ BOOL WINAPI PageSetupDlgA(LPPAGESETUPDLGA setupdlg) {
              setupdlg->hDevNames,\r
              setupdlg->hInstance, setupdlg->Flags, flagstr);\r
     }\r
+    if (setupdlg->Flags & PSD_ENABLEPAGEPAINTHOOK)\r
+        if (setupdlg->lpfnPagePaintHook == NULL) {\r
+            COMDLG32_SetCommDlgExtendedError(CDERR_NOHOOK);\r
+            return FALSE;\r
+        }\r
 \r
     /* First get default printer data, we need it right after that. */\r
     memset(&pdlg,0,sizeof(pdlg));\r
@@ -2945,7 +3068,7 @@ BOOL WINAPI PageSetupDlgA(LPPAGESETUPDLGA setupdlg) {
                setupdlg->hInstance,\r
                ptr,\r
                setupdlg->hwndOwner,\r
-               PageDlgProcA,\r
+               PRINTDLG_PageDlgProcA,\r
                (LPARAM)pda)\r
     );\r
     return bRet;\r
@@ -2959,7 +3082,7 @@ BOOL WINAPI PageSetupDlgW(LPPAGESETUPDLGW setupdlg) {
     BOOL               bRet;\r
     PageSetupDataW     *pdw;\r
     PRINTDLGW          pdlg;\r
-\r
+    FIXME("Unicode implementation is not done yet\n");\r
     if(TRACE_ON(commdlg)) {\r
         char flagstr[1000] = "";\r
        struct pd_flags *pflag = psd_flags;\r