Changeset 9364 for trunk/src


Ignore:
Timestamp:
Oct 28, 2002, 6:55:09 PM (23 years ago)
Author:
sandervl
Message:

Use Wine printer dialog

Location:
trunk/src/comdlg32
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/comdlg32/makefile

    r7397 r9364  
    1 # $Id: makefile,v 1.31 2001-11-19 12:32:00 sandervl Exp $
     1# $Id: makefile,v 1.32 2002-10-28 17:55:09 sandervl Exp $
    22
    33#
     
    3636$(OBJDIR)\filedlg.obj \
    3737$(OBJDIR)\filedlg95.obj \
    38 $(OBJDIR)\comdlg32.obj \
     38##$(OBJDIR)\comdlg32.obj \
    3939$(OBJDIR)\filedlgbrowser.obj \
    40 ##$(OBJDIR)\printdlg.obj \
     40$(OBJDIR)\printdlg.obj \
    4141$(OBJDIR)\rsrc.obj
    4242
  • trunk/src/comdlg32/printdlg.c

    r6709 r9364  
    66 * Copyright 1999 Klaas van Gend
    77 * Copyright 2000 Huw D M Davies
     8 *
     9 * This library is free software; you can redistribute it and/or
     10 * modify it under the terms of the GNU Lesser General Public
     11 * License as published by the Free Software Foundation; either
     12 * version 2.1 of the License, or (at your option) any later version.
     13 *
     14 * This library is distributed in the hope that it will be useful,
     15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
     16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
     17 * Lesser General Public License for more details.
     18 *
     19 * You should have received a copy of the GNU Lesser General Public
     20 * License along with this library; if not, write to the Free Software
     21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    822 */
    923#include <ctype.h>
     
    1933#include "commdlg.h"
    2034#include "dlgs.h"
    21 #include "debugtools.h"
     35#include "wine/debug.h"
    2236#include "cderr.h"
    2337#include "winspool.h"
    2438#include "winerror.h"
    2539
    26 DEFAULT_DEBUG_CHANNEL(commdlg);
     40WINE_DEFAULT_DEBUG_CHANNEL(commdlg);
    2741
    2842#include "cdlg.h"
     
    3044/* This PRINTDLGA internal structure stores
    3145 * pointers to several throughout useful structures.
    32  * 
     46 *
    3347 */
    34 typedef struct 
     48typedef struct
    3549{
    3650  LPDEVMODEA        lpDevMode;
     
    4862  HWND              hwndUpDown;
    4963} PRINT_PTRA;
     64
     65typedef struct
     66{
     67  LPDEVMODEW        lpDevMode;
     68  struct {
     69      LPPRINTDLGW       lpPrintDlg;
     70  } dlg;
     71  LPPRINTER_INFO_2W lpPrinterInfo;
     72  LPDRIVER_INFO_3W  lpDriverInfo;
     73  UINT              HelpMessageID;
     74  HICON             hCollateIcon;    /* PrintDlg only */
     75  HICON             hNoCollateIcon;  /* PrintDlg only */
     76  HICON             hPortraitIcon;   /* PrintSetupDlg only */
     77  HICON             hLandscapeIcon;  /* PrintSetupDlg only */
     78  HWND              hwndUpDown;
     79} PRINT_PTRW;
    5080
    5181/* Debugging info */
     
    108138 *
    109139 * Returns the default printer name in buf.
    110  * Even under WinNT/2000 default printer is retrieved via GetProfileString - 
     140 * Even under WinNT/2000 default printer is retrieved via GetProfileString -
    111141 * these entries are mapped somewhere in the registry rather than win.ini.
    112142 *
    113143 * Returns TRUE on success else FALSE
    114144 */
    115 static BOOL PRINTDLG_GetDefaultPrinterName(LPSTR buf, DWORD len)
     145static BOOL PRINTDLG_GetDefaultPrinterNameA(LPSTR buf, DWORD len)
    116146{
    117147    char *ptr;
     
    129159}
    130160
     161static BOOL PRINTDLG_GetDefaultPrinterNameW(LPWSTR buf, DWORD len)
     162{
     163    LPSTR ptr, bufA = (LPSTR)HeapAlloc(GetProcessHeap(),0,len+1);
     164
     165
     166    if(!GetProfileStringA("windows", "device", "", bufA, len)) {
     167        TRACE("No profile entry for default printer found.\n");
     168        HeapFree(GetProcessHeap(),0,bufA);
     169        return FALSE;
     170    }
     171    if((ptr = strchr(bufA, ',')) == NULL) {
     172        FIXME("bad format for default printer (%s)!\n",bufA);
     173        HeapFree(GetProcessHeap(),0,bufA);
     174        return FALSE;
     175    }
     176    *ptr = '\0';
     177    MultiByteToWideChar( CP_ACP, 0, bufA, -1, buf, len );
     178    HeapFree(GetProcessHeap(),0,bufA);
     179    return TRUE;
     180}
     181
    131182/***********************************************************************
    132183 *    PRINTDLG_OpenDefaultPrinter
     
    141192    char buf[260];
    142193    BOOL res;
    143     if(!PRINTDLG_GetDefaultPrinterName(buf, sizeof(buf)))
     194    if(!PRINTDLG_GetDefaultPrinterNameA(buf, sizeof(buf)))
    144195        return FALSE;
    145196    res = OpenPrinterA(buf, hprn, NULL);
     
    162213 * Returns number of printers added to list.
    163214 */
    164 static INT PRINTDLG_SetUpPrinterListCombo(HWND hDlg, UINT id, LPCSTR name)
     215static INT PRINTDLG_SetUpPrinterListComboA(HWND hDlg, UINT id, LPCSTR name)
    165216{
    166217    DWORD needed, num;
     
    169220    EnumPrintersA(PRINTER_ENUM_LOCAL, NULL, 2, NULL, 0, &needed, &num);
    170221    pi = HeapAlloc(GetProcessHeap(), 0, needed);
    171     EnumPrintersA(PRINTER_ENUM_LOCAL, NULL, 2, (LPBYTE)pi, needed, &needed, 
     222    EnumPrintersA(PRINTER_ENUM_LOCAL, NULL, 2, (LPBYTE)pi, needed, &needed,
    172223                  &num);
    173224
     
    184235        FIXME("Can't find '%s' in printer list so trying to find default\n",
    185236              name);
    186         if(!PRINTDLG_GetDefaultPrinterName(buf, sizeof(buf)))
     237        if(!PRINTDLG_GetDefaultPrinterNameA(buf, sizeof(buf)))
    187238            return num;
    188239        i = SendDlgItemMessageA(hDlg, id, CB_FINDSTRINGEXACT, -1, (LPARAM)buf);
     
    194245}
    195246
     247static INT PRINTDLG_SetUpPrinterListComboW(HWND hDlg, UINT id, LPCWSTR name)
     248{
     249    DWORD needed, num;
     250    INT i;
     251    LPPRINTER_INFO_2W pi;
     252    EnumPrintersW(PRINTER_ENUM_LOCAL, NULL, 2, NULL, 0, &needed, &num);
     253    pi = HeapAlloc(GetProcessHeap(), 0, needed);
     254    EnumPrintersW(PRINTER_ENUM_LOCAL, NULL, 2, (LPBYTE)pi, needed, &needed,
     255                  &num);
     256
     257    for(i = 0; i < num; i++) {
     258        SendDlgItemMessageW(hDlg, id, CB_ADDSTRING, 0,
     259                            (LPARAM)pi[i].pPrinterName );
     260    }
     261    HeapFree(GetProcessHeap(), 0, pi);
     262    if(!name ||
     263       (i = SendDlgItemMessageW(hDlg, id, CB_FINDSTRINGEXACT, -1,
     264                                (LPARAM)name)) == CB_ERR) {
     265
     266        /* ansi is ok */
     267        char buf[260];
     268        FIXME("Can't find '%s' in printer list so trying to find default\n",
     269              debugstr_w(name));
     270        if(!PRINTDLG_GetDefaultPrinterNameA(buf, sizeof(buf)))
     271            return num;
     272        i = SendDlgItemMessageA(hDlg, id, CB_FINDSTRINGEXACT, -1, (LPARAM)buf);
     273        if(i == CB_ERR)
     274            FIXME("Can't find default printer in printer list\n");
     275    }
     276    SendDlgItemMessageW(hDlg, id, CB_SETCURSEL, i, 0);
     277    return num;
     278}
     279
    196280/***********************************************************************
    197281 *             PRINTDLG_CreateDevNames          [internal]
     
    202286 *  (NB. when we handle unicode the offsets will be in wchars).
    203287 */
    204 static BOOL PRINTDLG_CreateDevNames(HGLOBAL *hmem, char* DeviceDriverName, 
     288static BOOL PRINTDLG_CreateDevNames(HGLOBAL *hmem, char* DeviceDriverName,
    205289                                    char* DeviceName, char* OutputPort)
    206290{
     
    215299            + strlen(OutputPort) + 1
    216300            + sizeof(DEVNAMES);
    217            
     301
    218302    if(*hmem)
    219303        *hmem = GlobalReAlloc(*hmem, size, GMEM_MOVEABLE);
     
    233317    strcpy(pTempPtr, DeviceName);
    234318    lpDevNames->wDeviceOffset = pTempPtr - pDevNamesSpace;
    235        
     319
    236320    pTempPtr += strlen(DeviceName) + 1;
    237321    strcpy(pTempPtr, OutputPort);
    238322    lpDevNames->wOutputOffset = pTempPtr - pDevNamesSpace;
    239323
    240     PRINTDLG_GetDefaultPrinterName(buf, sizeof(buf));
     324    PRINTDLG_GetDefaultPrinterNameA(buf, sizeof(buf));
    241325    lpDevNames->wDefault = (strcmp(buf, DeviceName) == 0) ? 1 : 0;
    242326    GlobalUnlock(*hmem);
    243327    return TRUE;
    244328}
     329
     330static BOOL PRINTDLG_CreateDevNamesW(HGLOBAL *hmem, LPCWSTR DeviceDriverName,
     331                                    LPCWSTR DeviceName, LPCWSTR OutputPort)
     332{
     333    long size;
     334    LPWSTR   pDevNamesSpace;
     335    LPWSTR   pTempPtr;
     336    LPDEVNAMES lpDevNames;
     337    WCHAR bufW[260];
     338    char buf[260];
     339
     340    size = sizeof(WCHAR)*lstrlenW(DeviceDriverName) + 2
     341            + sizeof(WCHAR)*lstrlenW(DeviceName) + 2
     342            + sizeof(WCHAR)*lstrlenW(OutputPort) + 2
     343            + sizeof(DEVNAMES);
     344
     345    if(*hmem)
     346        *hmem = GlobalReAlloc(*hmem, size, GMEM_MOVEABLE);
     347    else
     348        *hmem = GlobalAlloc(GMEM_MOVEABLE, size);
     349    if (*hmem == 0)
     350        return FALSE;
     351
     352    pDevNamesSpace = GlobalLock(*hmem);
     353    lpDevNames = (LPDEVNAMES) pDevNamesSpace;
     354
     355    pTempPtr = (LPWSTR)((LPDEVNAMES)pDevNamesSpace + 1);
     356    lstrcpyW(pTempPtr, DeviceDriverName);
     357    lpDevNames->wDriverOffset = pTempPtr - pDevNamesSpace;
     358
     359    pTempPtr += lstrlenW(DeviceDriverName) + 1;
     360    lstrcpyW(pTempPtr, DeviceName);
     361    lpDevNames->wDeviceOffset = pTempPtr - pDevNamesSpace;
     362
     363    pTempPtr += lstrlenW(DeviceName) + 1;
     364    lstrcpyW(pTempPtr, OutputPort);
     365    lpDevNames->wOutputOffset = pTempPtr - pDevNamesSpace;
     366
     367    PRINTDLG_GetDefaultPrinterNameA(buf, sizeof(buf));
     368    MultiByteToWideChar(CP_ACP, 0, buf, -1, bufW, -1);
     369    lpDevNames->wDefault = (lstrcmpW(bufW, DeviceName) == 0) ? 1 : 0;
     370    GlobalUnlock(*hmem);
     371    return TRUE;
     372}
     373
     374
    245375#ifndef __WIN32OS2__
    246 static BOOL PRINTDLG_CreateDevNames16(HGLOBAL16 *hmem, char* DeviceDriverName, 
     376static BOOL PRINTDLG_CreateDevNames16(HGLOBAL16 *hmem, char* DeviceDriverName,
    247377                                      char* DeviceName, char* OutputPort)
    248378{
     
    257387            + strlen(OutputPort) + 1
    258388            + sizeof(DEVNAMES);
    259            
     389
    260390    if(*hmem)
    261391        *hmem = GlobalReAlloc16(*hmem, size, GMEM_MOVEABLE);
     
    275405    strcpy(pTempPtr, DeviceName);
    276406    lpDevNames->wDeviceOffset = pTempPtr - pDevNamesSpace;
    277        
     407
    278408    pTempPtr += strlen(DeviceName) + 1;
    279409    strcpy(pTempPtr, OutputPort);
    280410    lpDevNames->wOutputOffset = pTempPtr - pDevNamesSpace;
    281411
    282     PRINTDLG_GetDefaultPrinterName(buf, sizeof(buf));
     412    PRINTDLG_GetDefaultPrinterNameA(buf, sizeof(buf));
    283413    lpDevNames->wDefault = (strcmp(buf, DeviceName) == 0) ? 1 : 0;
    284414    GlobalUnlock16(*hmem);
     
    292422 *
    293423 *   updates the PrintDlg structure for returnvalues.
    294  *     
     424 *
    295425 * RETURNS
    296426 *   FALSE if user is not allowed to close (i.e. wrong nTo or nFrom values)
    297427 *   TRUE  if succesful.
    298428 */
    299 static BOOL PRINTDLG_UpdatePrintDlg(HWND hDlg,
     429static BOOL PRINTDLG_UpdatePrintDlgA(HWND hDlg,
    300430                                    PRINT_PTRA* PrintStructures)
    301431{
     
    324454                char resourcestr[256];
    325455                char resultstr[256];
    326                 LoadStringA(COMDLG32_hInstance, PD32_INVALID_PAGE_RANGE, 
     456                LoadStringA(COMDLG32_hInstance, PD32_INVALID_PAGE_RANGE,
    327457                            resourcestr, 255);
    328458                sprintf(resultstr,resourcestr, lppd->nMinPage, lppd->nMaxPage);
    329                 LoadStringA(COMDLG32_hInstance, PD32_PRINT_TITLE, 
     459                LoadStringA(COMDLG32_hInstance, PD32_PRINT_TITLE,
    330460                            resourcestr, 255);
    331461                MessageBoxA(hDlg, resultstr, resourcestr,
     
    335465            lppd->nFromPage = nFromPage;
    336466            lppd->nToPage   = nToPage;
    337         }
     467            lppd->Flags |= PD_PAGENUMS;
     468        }
     469        else
     470            lppd->Flags &= ~PD_PAGENUMS;
    338471
    339472        if (IsDlgButtonChecked(hDlg, chx1) == BST_CHECKED) {/* Print to file */
     
    356489           */
    357490            if (lpdm->dmFields & DM_COLLATE)
    358                 lpdm->dmCollate = 
     491                lpdm->dmCollate =
    359492                  (IsDlgButtonChecked(hDlg, chx2) == BST_CHECKED);
    360493            if (lpdm->dmFields & DM_COPIES)
     
    371504}
    372505
    373 static BOOL PRINTDLG_PaperSize(
     506static BOOL PRINTDLG_UpdatePrintDlgW(HWND hDlg,
     507                                    PRINT_PTRW* PrintStructures)
     508{
     509    LPPRINTDLGW       lppd = PrintStructures->dlg.lpPrintDlg;
     510    PDEVMODEW         lpdm = PrintStructures->lpDevMode;
     511    LPPRINTER_INFO_2W pi = PrintStructures->lpPrinterInfo;
     512
     513
     514    if(!lpdm) {
     515        FIXME("No lpdm ptr?\n");
     516        return FALSE;
     517    }
     518
     519
     520    if(!(lppd->Flags & PD_PRINTSETUP)) {
     521        /* check whether nFromPage and nToPage are within range defined by
     522         * nMinPage and nMaxPage
     523         */
     524        if (IsDlgButtonChecked(hDlg, rad3) == BST_CHECKED) { /* Pages */
     525            WORD nToPage;
     526            WORD nFromPage;
     527            nFromPage = GetDlgItemInt(hDlg, edt1, NULL, FALSE);
     528            nToPage   = GetDlgItemInt(hDlg, edt2, NULL, FALSE);
     529            if (nFromPage < lppd->nMinPage || nFromPage > lppd->nMaxPage ||
     530                nToPage < lppd->nMinPage || nToPage > lppd->nMaxPage) {
     531                char resourcestr[256];
     532                char resultstr[256];
     533                LoadStringA(COMDLG32_hInstance, PD32_INVALID_PAGE_RANGE,
     534                            resourcestr, 255);
     535                sprintf(resultstr,resourcestr, lppd->nMinPage, lppd->nMaxPage);
     536                LoadStringA(COMDLG32_hInstance, PD32_PRINT_TITLE,
     537                            resourcestr, 255);
     538                MessageBoxA(hDlg, resultstr, resourcestr,
     539                            MB_OK | MB_ICONWARNING);
     540                return FALSE;
     541            }
     542            lppd->nFromPage = nFromPage;
     543            lppd->nToPage   = nToPage;
     544        }
     545
     546        if (IsDlgButtonChecked(hDlg, chx1) == BST_CHECKED) {/* Print to file */
     547            static WCHAR file[] = {'F','I','L','E',':',0};
     548            lppd->Flags |= PD_PRINTTOFILE;
     549            pi->pPortName = file;
     550        }
     551
     552        if (IsDlgButtonChecked(hDlg, chx2) == BST_CHECKED) { /* Collate */
     553            FIXME("Collate lppd not yet implemented as output\n");
     554        }
     555
     556        /* set PD_Collate and nCopies */
     557        if (lppd->Flags & PD_USEDEVMODECOPIESANDCOLLATE) {
     558          /*  The application doesn't support multiple copies or collate...
     559           */
     560            lppd->Flags &= ~PD_COLLATE;
     561            lppd->nCopies = 1;
     562          /* if the printer driver supports it... store info there
     563           * otherwise no collate & multiple copies !
     564           */
     565            if (lpdm->dmFields & DM_COLLATE)
     566                lpdm->dmCollate =
     567                  (IsDlgButtonChecked(hDlg, chx2) == BST_CHECKED);
     568            if (lpdm->dmFields & DM_COPIES)
     569                lpdm->dmCopies = GetDlgItemInt(hDlg, edt3, NULL, FALSE);
     570        } else {
     571            if (IsDlgButtonChecked(hDlg, chx2) == BST_CHECKED)
     572                lppd->Flags |= PD_COLLATE;
     573            else
     574               lppd->Flags &= ~PD_COLLATE;
     575            lppd->nCopies = GetDlgItemInt(hDlg, edt3, NULL, FALSE);
     576        }
     577    }
     578    return TRUE;
     579}
     580
     581static BOOL PRINTDLG_PaperSizeA(
    374582        PRINTDLGA       *pdlga,const char *PaperSize,LPPOINT size
    375583) {
     
    378586    LPSTR       devname,portname;
    379587    int         i;
    380     DWORD       NrOfEntries,ret;
     588    INT         NrOfEntries,ret;
    381589    char        *Names = NULL;
    382590    POINT       *points = NULL;
    383591    BOOL        retval = FALSE;
    384    
     592
    385593    dn = GlobalLock(pdlga->hDevNames);
    386594    dm = GlobalLock(pdlga->hDevMode);
     
    394602        goto out;
    395603    }
     604    if (NrOfEntries == -1) {
     605        ERR("Hmm ? DeviceCapabilities() DC_PAPERNAMES failed, ret -1 !\n");
     606        goto out;
     607    }
     608
    396609    Names = (char*)HeapAlloc(GetProcessHeap(),0,NrOfEntries*64);
    397610    if (NrOfEntries != (ret=DeviceCapabilitiesA(devname,portname,DC_PAPERNAMES,Names,dm))) {
    398         FIXME("Number of returned vals %ld is not %ld\n",NrOfEntries,ret);
     611        FIXME("Number of returned vals %d is not %d\n",NrOfEntries,ret);
    399612        goto out;
    400613    }
     
    409622    points = HeapAlloc(GetProcessHeap(),0,sizeof(points[0])*NrOfEntries);
    410623    if (NrOfEntries!=(ret=DeviceCapabilitiesA(devname,portname,DC_PAPERSIZE,(LPBYTE)points,dm))) {
    411         FIXME("Number of returned sizes %ld is not %ld?\n",NrOfEntries,ret);
     624        FIXME("Number of returned sizes %d is not %d?\n",NrOfEntries,ret);
    412625        goto out;
    413626    }
     
    415628    size->x=points[i].x;
    416629    size->y=points[i].y;
    417     FIXME("papersize is %ld x %ld\n",size->x,size->y);
    418630    retval = TRUE;
    419631out:
     
    425637}
    426638
     639static BOOL PRINTDLG_PaperSizeW(
     640        PRINTDLGW       *pdlga,const WCHAR *PaperSize,LPPOINT size
     641) {
     642    DEVNAMES    *dn;
     643    DEVMODEW    *dm;
     644    LPWSTR      devname,portname;
     645    int         i;
     646    INT         NrOfEntries,ret;
     647    WCHAR       *Names = NULL;
     648    POINT       *points = NULL;
     649    BOOL        retval = FALSE;
     650
     651    dn = GlobalLock(pdlga->hDevNames);
     652    dm = GlobalLock(pdlga->hDevMode);
     653    devname     = ((WCHAR*)dn)+dn->wDeviceOffset;
     654    portname    = ((WCHAR*)dn)+dn->wOutputOffset;
     655
     656
     657    NrOfEntries = DeviceCapabilitiesW(devname,portname,DC_PAPERNAMES,NULL,dm);
     658    if (!NrOfEntries) {
     659        FIXME("No papernames found for %s/%s\n",debugstr_w(devname),debugstr_w(portname));
     660        goto out;
     661    }
     662    if (NrOfEntries == -1) {
     663        ERR("Hmm ? DeviceCapabilities() DC_PAPERNAMES failed, ret -1 !\n");
     664        goto out;
     665    }
     666
     667    Names = (WCHAR*)HeapAlloc(GetProcessHeap(),0,sizeof(WCHAR)*NrOfEntries*64);
     668    if (NrOfEntries != (ret=DeviceCapabilitiesW(devname,portname,DC_PAPERNAMES,Names,dm))) {
     669        FIXME("Number of returned vals %d is not %d\n",NrOfEntries,ret);
     670        goto out;
     671    }
     672    for (i=0;i<NrOfEntries;i++)
     673        if (!lstrcmpW(PaperSize,Names+(64*i)))
     674            break;
     675    HeapFree(GetProcessHeap(),0,Names);
     676    if (i==NrOfEntries) {
     677        FIXME("Papersize %s not found in list?\n",debugstr_w(PaperSize));
     678        goto out;
     679    }
     680    points = HeapAlloc(GetProcessHeap(),0,sizeof(points[0])*NrOfEntries);
     681    if (NrOfEntries!=(ret=DeviceCapabilitiesW(devname,portname,DC_PAPERSIZE,(LPWSTR)points,dm))) {
     682        FIXME("Number of returned sizes %d is not %d?\n",NrOfEntries,ret);
     683        goto out;
     684    }
     685    /* this is _10ths_ of a millimeter */
     686    size->x=points[i].x;
     687    size->y=points[i].y;
     688    retval = TRUE;
     689out:
     690    GlobalUnlock(pdlga->hDevNames);
     691    GlobalUnlock(pdlga->hDevMode);
     692    if (Names) HeapFree(GetProcessHeap(),0,Names);
     693    if (points) HeapFree(GetProcessHeap(),0,points);
     694    return retval;
     695}
     696
    427697
    428698/************************************************************************
     
    433703 * We also try to re-select the old selection.
    434704 */
    435 static BOOL PRINTDLG_SetUpPaperComboBox(HWND hDlg,
     705static BOOL PRINTDLG_SetUpPaperComboBoxA(HWND hDlg,
    436706                                        int   nIDComboBox,
    437                                         char* PrinterName, 
     707                                        char* PrinterName,
    438708                                        char* PortName,
    439709                                        LPDEVMODEA dm)
    440710{
    441711    int     i;
    442     DWORD   NrOfEntries;
     712    int     NrOfEntries;
    443713    char*   Names;
    444714    WORD*   Words;
     
    448718    int     fwCapability_Names;
    449719    int     fwCapability_Words;
    450    
    451     TRACE(" Printer: %s, ComboID: %d\n",PrinterName,nIDComboBox);
    452    
     720
     721    TRACE(" Printer: %s, Port: %s, ComboID: %d\n",PrinterName,PortName,nIDComboBox);
     722
    453723    /* query the dialog box for the current selected value */
    454724    Sel = SendDlgItemMessageA(hDlg, nIDComboBox, CB_GETCURSEL, 0, 0);
     
    462732        if (dm) {
    463733            if (nIDComboBox == cmb2)
    464 #ifdef __WIN32OS2__
    465                 dm->dmPaperSize = oldWord;
    466 #else
    467734                dm->u1.s1.dmPaperSize = oldWord;
    468 #endif
    469735            else
    470736                dm->dmDefaultSource = oldWord;
     
    478744        if (dm) {
    479745            if (nIDComboBox == cmb2)
    480 #ifdef __WIN32OS2__
    481                 oldWord = dm->dmPaperSize;
    482 #else
    483746                oldWord = dm->u1.s1.dmPaperSize;
    484 #endif
    485747            else
    486748                oldWord = dm->dmDefaultSource;
     
    498760         fwCapability_Words = DC_BINS;
    499761    }
    500    
    501     /* for some printer drivers, DeviceCapabilities calls a VXD to obtain the 
     762
     763    /* for some printer drivers, DeviceCapabilities calls a VXD to obtain the
    502764     * paper settings. As Wine doesn't allow VXDs, this results in a crash.
    503765     */
     
    507769    if (NrOfEntries == 0)
    508770         WARN("no Name Entries found!\n");
     771    else if (NrOfEntries < 0)
     772         return FALSE;
    509773
    510774    if(DeviceCapabilitiesA(PrinterName, PortName, fwCapability_Words, NULL, dm)
     
    514778    }
    515779
    516     Names = HeapAlloc(GetProcessHeap(),0, NrOfEntries*NamesSize);
     780    Names = HeapAlloc(GetProcessHeap(),0, NrOfEntries*sizeof(char)*NamesSize);
    517781    Words = HeapAlloc(GetProcessHeap(),0, NrOfEntries*sizeof(WORD));
    518782    NrOfEntries = DeviceCapabilitiesA(PrinterName, PortName,
     
    523787    /* reset any current content in the combobox */
    524788    SendDlgItemMessageA(hDlg, nIDComboBox, CB_RESETCONTENT, 0, 0);
    525    
     789
    526790    /* store new content */
    527791    for (i = 0; i < NrOfEntries; i++) {
    528792        DWORD pos = SendDlgItemMessageA(hDlg, nIDComboBox, CB_ADDSTRING, 0,
    529793                                        (LPARAM)(&Names[i*NamesSize]) );
    530         SendDlgItemMessageA(hDlg, nIDComboBox, CB_SETITEMDATA, pos, 
     794        SendDlgItemMessageA(hDlg, nIDComboBox, CB_SETITEMDATA, pos,
    531795                            Words[i]);
    532796    }
     
    549813}
    550814
     815static BOOL PRINTDLG_SetUpPaperComboBoxW(HWND hDlg,
     816                                        int   nIDComboBox,
     817                                        WCHAR* PrinterName,
     818                                        WCHAR* PortName,
     819                                        LPDEVMODEW dm)
     820{
     821    int     i;
     822    int     NrOfEntries;
     823    WCHAR*  Names;
     824    WORD*   Words;
     825    DWORD   Sel;
     826    WORD    oldWord = 0;
     827    int     NamesSize;
     828    int     fwCapability_Names;
     829    int     fwCapability_Words;
     830
     831    TRACE(" Printer: %s, Port: %s, ComboID: %d\n",debugstr_w(PrinterName),debugstr_w(PortName),nIDComboBox);
     832
     833    /* query the dialog box for the current selected value */
     834    Sel = SendDlgItemMessageA(hDlg, nIDComboBox, CB_GETCURSEL, 0, 0);
     835    if(Sel != CB_ERR) {
     836        /* we enter here only if a different printer is selected after
     837         * the Print Setup dialog is opened. The current settings are
     838         * stored into the newly selected printer.
     839         */
     840        oldWord = SendDlgItemMessageA(hDlg, nIDComboBox, CB_GETITEMDATA,
     841                                      Sel, 0);
     842        if (dm) {
     843            if (nIDComboBox == cmb2)
     844                dm->u1.s1.dmPaperSize = oldWord;
     845            else
     846                dm->dmDefaultSource = oldWord;
     847        }
     848    }
     849    else {
     850        /* we enter here only when the Print setup dialog is initially
     851         * opened. In this case the settings are restored from when
     852         * the dialog was last closed.
     853         */
     854        if (dm) {
     855            if (nIDComboBox == cmb2)
     856                oldWord = dm->u1.s1.dmPaperSize;
     857            else
     858                oldWord = dm->dmDefaultSource;
     859        }
     860    }
     861
     862    if (nIDComboBox == cmb2) {
     863         NamesSize          = 64;
     864         fwCapability_Names = DC_PAPERNAMES;
     865         fwCapability_Words = DC_PAPERS;
     866    } else {
     867         nIDComboBox        = cmb3;
     868         NamesSize          = 24;
     869         fwCapability_Names = DC_BINNAMES;
     870         fwCapability_Words = DC_BINS;
     871    }
     872
     873    /* for some printer drivers, DeviceCapabilities calls a VXD to obtain the
     874     * paper settings. As Wine doesn't allow VXDs, this results in a crash.
     875     */
     876    WARN(" if your printer driver uses VXDs, expect a crash now!\n");
     877    NrOfEntries = DeviceCapabilitiesW(PrinterName, PortName,
     878                                      fwCapability_Names, NULL, dm);
     879    if (NrOfEntries == 0)
     880         WARN("no Name Entries found!\n");
     881    else if (NrOfEntries < 0)
     882         return FALSE;
     883
     884    if(DeviceCapabilitiesW(PrinterName, PortName, fwCapability_Words, NULL, dm)
     885       != NrOfEntries) {
     886        ERR("Number of caps is different\n");
     887        NrOfEntries = 0;
     888    }
     889
     890    Names = HeapAlloc(GetProcessHeap(),0, NrOfEntries*sizeof(WCHAR)*NamesSize);
     891    Words = HeapAlloc(GetProcessHeap(),0, NrOfEntries*sizeof(WORD));
     892    NrOfEntries = DeviceCapabilitiesW(PrinterName, PortName,
     893                                      fwCapability_Names, Names, dm);
     894    NrOfEntries = DeviceCapabilitiesW(PrinterName, PortName,
     895                                      fwCapability_Words, (LPWSTR)Words, dm);
     896
     897    /* reset any current content in the combobox */
     898    SendDlgItemMessageA(hDlg, nIDComboBox, CB_RESETCONTENT, 0, 0);
     899
     900    /* store new content */
     901    for (i = 0; i < NrOfEntries; i++) {
     902        DWORD pos = SendDlgItemMessageW(hDlg, nIDComboBox, CB_ADDSTRING, 0,
     903                                        (LPARAM)(&Names[i*NamesSize]) );
     904        SendDlgItemMessageW(hDlg, nIDComboBox, CB_SETITEMDATA, pos,
     905                            Words[i]);
     906    }
     907
     908    /* Look for old selection - can't do this is previous loop since
     909       item order will change as more items are added */
     910    Sel = 0;
     911    for (i = 0; i < NrOfEntries; i++) {
     912        if(SendDlgItemMessageA(hDlg, nIDComboBox, CB_GETITEMDATA, i, 0) ==
     913           oldWord) {
     914            Sel = i;
     915            break;
     916        }
     917    }
     918    SendDlgItemMessageA(hDlg, nIDComboBox, CB_SETCURSEL, Sel, 0);
     919
     920    HeapFree(GetProcessHeap(),0,Words);
     921    HeapFree(GetProcessHeap(),0,Names);
     922    return TRUE;
     923}
     924
     925
    551926/***********************************************************************
    552927 *               PRINTDLG_UpdatePrinterInfoTexts               [internal]
    553928 */
    554 static void PRINTDLG_UpdatePrinterInfoTexts(HWND hDlg, LPPRINTER_INFO_2A pi)
     929static void PRINTDLG_UpdatePrinterInfoTextsA(HWND hDlg, LPPRINTER_INFO_2A pi)
    555930{
    556931    char   StatusMsg[256];
     
    564939    for (i = 0; i < 25; i++) {
    565940        if (pi->Status & (1<<i)) {
    566             LoadStringA(COMDLG32_hInstance, PD32_PRINTER_STATUS_PAUSED+i, 
     941            LoadStringA(COMDLG32_hInstance, PD32_PRINTER_STATUS_PAUSED+i,
    567942                        ResourceString, 255);
    568943            strcat(StatusMsg,ResourceString);
     
    570945    }
    571946    /* append "ready" */
    572     /* FIXME: status==ready must only be appended if really so. 
     947    /* FIXME: status==ready must only be appended if really so.
    573948              but how to detect? */
    574     LoadStringA(COMDLG32_hInstance, PD32_PRINTER_STATUS_READY, 
     949    LoadStringA(COMDLG32_hInstance, PD32_PRINTER_STATUS_READY,
    575950                ResourceString, 255);
    576951    strcat(StatusMsg,ResourceString);
    577  
     952
    578953    SendDlgItemMessageA(hDlg, stc12, WM_SETTEXT, 0, (LPARAM)StatusMsg);
    579954
     
    589964}
    590965
     966static void PRINTDLG_UpdatePrinterInfoTextsW(HWND hDlg, LPPRINTER_INFO_2W pi)
     967{
     968    WCHAR   StatusMsg[256];
     969    WCHAR   ResourceString[256];
     970    int    i;
     971
     972    /* Status Message */
     973    StatusMsg[0]='\0';
     974
     975    /* add all status messages */
     976    for (i = 0; i < 25; i++) {
     977        if (pi->Status & (1<<i)) {
     978            LoadStringW(COMDLG32_hInstance, PD32_PRINTER_STATUS_PAUSED+i,
     979                        ResourceString, 255);
     980            lstrcatW(StatusMsg,ResourceString);
     981        }
     982    }
     983    /* append "ready" */
     984    /* FIXME: status==ready must only be appended if really so.
     985              but how to detect? */
     986    LoadStringW(COMDLG32_hInstance, PD32_PRINTER_STATUS_READY,
     987                ResourceString, 255);
     988    lstrcatW(StatusMsg,ResourceString);
     989
     990    SendDlgItemMessageW(hDlg, stc12, WM_SETTEXT, 0, (LPARAM)StatusMsg);
     991
     992    /* set all other printer info texts */
     993    SendDlgItemMessageW(hDlg, stc11, WM_SETTEXT, 0, (LPARAM)pi->pDriverName);
     994    if (pi->pLocation != NULL && pi->pLocation[0] != '\0')
     995        SendDlgItemMessageW(hDlg, stc14, WM_SETTEXT, 0,(LPARAM)pi->pLocation);
     996    else
     997        SendDlgItemMessageW(hDlg, stc14, WM_SETTEXT, 0,(LPARAM)pi->pPortName);
     998    SendDlgItemMessageW(hDlg, stc13, WM_SETTEXT, 0, (LPARAM)(pi->pComment ?
     999                        pi->pComment : (LPCWSTR)"\0\0"));
     1000    return;
     1001}
     1002
    5911003
    5921004/*******************************************************************
     
    5951007 *
    5961008 */
    597 static BOOL PRINTDLG_ChangePrinter(HWND hDlg, char *name,
     1009static BOOL PRINTDLG_ChangePrinterA(HWND hDlg, char *name,
    5981010                                   PRINT_PTRA *PrintStructures)
    5991011{
     
    6251037    ClosePrinter(hprn);
    6261038
    627     PRINTDLG_UpdatePrinterInfoTexts(hDlg, PrintStructures->lpPrinterInfo);
     1039    PRINTDLG_UpdatePrinterInfoTextsA(hDlg, PrintStructures->lpPrinterInfo);
    6281040
    6291041    if(PrintStructures->lpDevMode) {
     
    6761088            char        resourcestr[64];
    6771089            char        result[64];
    678             LoadStringA(COMDLG32_hInstance, PD32_PRINT_ALL_X_PAGES, 
     1090            LoadStringA(COMDLG32_hInstance, PD32_PRINT_ALL_X_PAGES,
    6791091                        resourcestr, 49);
    6801092            sprintf(result,resourcestr,lppd->nMaxPage - lppd->nMinPage + 1);
    6811093            SendDlgItemMessageA(hDlg, rad1, WM_SETTEXT, 0, (LPARAM) result);
    6821094        }
    683        
    684         /* Collate pages 
     1095
     1096        /* Collate pages
    6851097         *
    6861098         * FIXME: The ico3 is not displayed for some reason. I don't know why.
    6871099         */
    6881100        if (lppd->Flags & PD_COLLATE) {
    689             SendDlgItemMessageA(hDlg, ico3, STM_SETIMAGE, (WPARAM) IMAGE_ICON, 
     1101            SendDlgItemMessageA(hDlg, ico3, STM_SETIMAGE, (WPARAM) IMAGE_ICON,
    6901102                                (LPARAM)PrintStructures->hCollateIcon);
    6911103            CheckDlgButton(hDlg, chx2, 1);
    6921104        } else {
    693             SendDlgItemMessageA(hDlg, ico3, STM_SETIMAGE, (WPARAM) IMAGE_ICON, 
     1105            SendDlgItemMessageA(hDlg, ico3, STM_SETIMAGE, (WPARAM) IMAGE_ICON,
    6941106                                (LPARAM)PrintStructures->hNoCollateIcon);
    6951107            CheckDlgButton(hDlg, chx2, 0);
     
    6991111          /* if printer doesn't support it: no Collate */
    7001112            if (!(lpdm->dmFields & DM_COLLATE)) {
    701                 EnableWindow(GetDlgItem(hDlg, chx2), FALSE);   
    702                 EnableWindow(GetDlgItem(hDlg, ico3), FALSE);   
     1113                EnableWindow(GetDlgItem(hDlg, chx2), FALSE);
     1114                EnableWindow(GetDlgItem(hDlg, ico3), FALSE);
    7031115            }
    7041116        }
     
    7191131          /* if printer doesn't support it: no nCopies */
    7201132            if (!(lpdm->dmFields & DM_COPIES)) {
    721                 EnableWindow(GetDlgItem(hDlg, edt3), FALSE);   
    722                 EnableWindow(GetDlgItem(hDlg, stc5), FALSE);   
     1133                EnableWindow(GetDlgItem(hDlg, edt3), FALSE);
     1134                EnableWindow(GetDlgItem(hDlg, stc5), FALSE);
    7231135            }
    7241136        }
     
    7271139        CheckDlgButton(hDlg, chx1, (lppd->Flags & PD_PRINTTOFILE) ? 1 : 0);
    7281140        if (lppd->Flags & PD_DISABLEPRINTTOFILE)
    729             EnableWindow(GetDlgItem(hDlg, chx1), FALSE);   
     1141            EnableWindow(GetDlgItem(hDlg, chx1), FALSE);
    7301142        if (lppd->Flags & PD_HIDEPRINTTOFILE)
    7311143            ShowWindow(GetDlgItem(hDlg, chx1), SW_HIDE);
    7321144
    7331145    } else { /* PD_PRINTSETUP */
    734 #ifdef __WIN32OS2__
    735       BOOL bPortrait = (lpdm->dmOrientation == DMORIENT_PORTRAIT);
    736 #else
    7371146      BOOL bPortrait = (lpdm->u1.s1.dmOrientation == DMORIENT_PORTRAIT);
    738 #endif
    739 
    740       PRINTDLG_SetUpPaperComboBox(hDlg, cmb2,
     1147
     1148      PRINTDLG_SetUpPaperComboBoxA(hDlg, cmb2,
    7411149                                  PrintStructures->lpPrinterInfo->pPrinterName,
    7421150                                  PrintStructures->lpPrinterInfo->pPortName,
    7431151                                  lpdm);
    744       PRINTDLG_SetUpPaperComboBox(hDlg, cmb3,
     1152      PRINTDLG_SetUpPaperComboBoxA(hDlg, cmb3,
    7451153                                  PrintStructures->lpPrinterInfo->pPrinterName,
    7461154                                  PrintStructures->lpPrinterInfo->pPortName,
     
    7501158                          (LPARAM)(bPortrait ? PrintStructures->hPortraitIcon :
    7511159                                   PrintStructures->hLandscapeIcon));
    752      
     1160
    7531161    }
    7541162
     
    7561164    if ((lppd->Flags & PD_SHOWHELP)==0) {
    7571165        /* hide if PD_SHOWHELP not specified */
    758         ShowWindow(GetDlgItem(hDlg, pshHelp), SW_HIDE);         
     1166        ShowWindow(GetDlgItem(hDlg, pshHelp), SW_HIDE);
     1167    }
     1168    return TRUE;
     1169}
     1170
     1171static BOOL PRINTDLG_ChangePrinterW(HWND hDlg, WCHAR *name,
     1172                                   PRINT_PTRW *PrintStructures)
     1173{
     1174    LPPRINTDLGW lppd = PrintStructures->dlg.lpPrintDlg;
     1175    LPDEVMODEW lpdm = NULL;
     1176    LONG dmSize;
     1177    DWORD needed;
     1178    HANDLE hprn;
     1179
     1180    if(PrintStructures->lpPrinterInfo)
     1181        HeapFree(GetProcessHeap(),0, PrintStructures->lpPrinterInfo);
     1182    if(PrintStructures->lpDriverInfo)
     1183        HeapFree(GetProcessHeap(),0, PrintStructures->lpDriverInfo);
     1184    if(!OpenPrinterW(name, &hprn, NULL)) {
     1185        ERR("Can't open printer %s\n", debugstr_w(name));
     1186        return FALSE;
     1187    }
     1188    GetPrinterW(hprn, 2, NULL, 0, &needed);
     1189    PrintStructures->lpPrinterInfo = HeapAlloc(GetProcessHeap(),0,sizeof(WCHAR)*needed);
     1190    GetPrinterW(hprn, 2, (LPBYTE)PrintStructures->lpPrinterInfo, needed,
     1191                &needed);
     1192    GetPrinterDriverW(hprn, NULL, 3, NULL, 0, &needed);
     1193    PrintStructures->lpDriverInfo = HeapAlloc(GetProcessHeap(),0,sizeof(WCHAR)*needed);
     1194    if (!GetPrinterDriverW(hprn, NULL, 3, (LPBYTE)PrintStructures->lpDriverInfo,
     1195            needed, &needed)) {
     1196        ERR("GetPrinterDriverA failed for %s, fix your config!\n",debugstr_w(PrintStructures->lpPrinterInfo->pPrinterName));
     1197        return FALSE;
     1198    }
     1199    ClosePrinter(hprn);
     1200
     1201    PRINTDLG_UpdatePrinterInfoTextsW(hDlg, PrintStructures->lpPrinterInfo);
     1202
     1203    if(PrintStructures->lpDevMode) {
     1204        HeapFree(GetProcessHeap(), 0, PrintStructures->lpDevMode);
     1205        PrintStructures->lpDevMode = NULL;
     1206    }
     1207
     1208    dmSize = DocumentPropertiesW(0, 0, name, NULL, NULL, 0);
     1209    if(dmSize == -1) {
     1210        ERR("DocumentProperties fails on %s\n", debugstr_w(name));
     1211        return FALSE;
     1212    }
     1213    PrintStructures->lpDevMode = HeapAlloc(GetProcessHeap(), 0, dmSize);
     1214    dmSize = DocumentPropertiesW(0, 0, name, PrintStructures->lpDevMode, NULL,
     1215                                 DM_OUT_BUFFER);
     1216    if(lppd->hDevMode && (lpdm = GlobalLock(lppd->hDevMode)) &&
     1217                          !lstrcmpW(lpdm->dmDeviceName,
     1218                                  PrintStructures->lpDevMode->dmDeviceName)) {
     1219      /* Supplied devicemode matches current printer so try to use it */
     1220        DocumentPropertiesW(0, 0, name, PrintStructures->lpDevMode, lpdm,
     1221                            DM_OUT_BUFFER | DM_IN_BUFFER);
     1222    }
     1223    if(lpdm)
     1224        GlobalUnlock(lppd->hDevMode);
     1225
     1226    lpdm = PrintStructures->lpDevMode;  /* use this as a shortcut */
     1227
     1228    if(!(lppd->Flags & PD_PRINTSETUP)) {
     1229      /* Print range (All/Range/Selection) */
     1230        SetDlgItemInt(hDlg, edt1, lppd->nFromPage, FALSE);
     1231        SetDlgItemInt(hDlg, edt2, lppd->nToPage, FALSE);
     1232        CheckRadioButton(hDlg, rad1, rad3, rad1);               /* default */
     1233        if (lppd->Flags & PD_NOSELECTION)
     1234            EnableWindow(GetDlgItem(hDlg, rad2), FALSE);
     1235        else
     1236            if (lppd->Flags & PD_SELECTION)
     1237                CheckRadioButton(hDlg, rad1, rad3, rad2);
     1238        if (lppd->Flags & PD_NOPAGENUMS) {
     1239            EnableWindow(GetDlgItem(hDlg, rad3), FALSE);
     1240            EnableWindow(GetDlgItem(hDlg, stc2),FALSE);
     1241            EnableWindow(GetDlgItem(hDlg, edt1), FALSE);
     1242            EnableWindow(GetDlgItem(hDlg, stc3),FALSE);
     1243            EnableWindow(GetDlgItem(hDlg, edt2), FALSE);
     1244        } else {
     1245            if (lppd->Flags & PD_PAGENUMS)
     1246                CheckRadioButton(hDlg, rad1, rad3, rad3);
     1247        }
     1248        /* "All xxx pages"... */
     1249        {
     1250            /* ansi is ok */
     1251            char        resourcestr[64];
     1252            char        result[64];
     1253            LoadStringA(COMDLG32_hInstance, PD32_PRINT_ALL_X_PAGES,
     1254                        resourcestr, 49);
     1255            sprintf(result,resourcestr,lppd->nMaxPage - lppd->nMinPage + 1);
     1256            SendDlgItemMessageA(hDlg, rad1, WM_SETTEXT, 0, (LPARAM) result);
     1257        }
     1258
     1259        /* Collate pages
     1260         *
     1261         * FIXME: The ico3 is not displayed for some reason. I don't know why.
     1262         */
     1263        if (lppd->Flags & PD_COLLATE) {
     1264            SendDlgItemMessageA(hDlg, ico3, STM_SETIMAGE, (WPARAM) IMAGE_ICON,
     1265                                (LPARAM)PrintStructures->hCollateIcon);
     1266            CheckDlgButton(hDlg, chx2, 1);
     1267        } else {
     1268            SendDlgItemMessageA(hDlg, ico3, STM_SETIMAGE, (WPARAM) IMAGE_ICON,
     1269                                (LPARAM)PrintStructures->hNoCollateIcon);
     1270            CheckDlgButton(hDlg, chx2, 0);
     1271        }
     1272
     1273        if (lppd->Flags & PD_USEDEVMODECOPIESANDCOLLATE) {
     1274          /* if printer doesn't support it: no Collate */
     1275            if (!(lpdm->dmFields & DM_COLLATE)) {
     1276                EnableWindow(GetDlgItem(hDlg, chx2), FALSE);
     1277                EnableWindow(GetDlgItem(hDlg, ico3), FALSE);
     1278            }
     1279        }
     1280
     1281        /* nCopies */
     1282        {
     1283          INT copies;
     1284          if (lppd->hDevMode == 0)
     1285              copies = lppd->nCopies;
     1286          else
     1287              copies = lpdm->dmCopies;
     1288          if(copies == 0) copies = 1;
     1289          else if(copies < 0) copies = MAX_COPIES;
     1290          SetDlgItemInt(hDlg, edt3, copies, FALSE);
     1291        }
     1292
     1293        if (lppd->Flags & PD_USEDEVMODECOPIESANDCOLLATE) {
     1294          /* if printer doesn't support it: no nCopies */
     1295            if (!(lpdm->dmFields & DM_COPIES)) {
     1296                EnableWindow(GetDlgItem(hDlg, edt3), FALSE);
     1297                EnableWindow(GetDlgItem(hDlg, stc5), FALSE);
     1298            }
     1299        }
     1300
     1301        /* print to file */
     1302        CheckDlgButton(hDlg, chx1, (lppd->Flags & PD_PRINTTOFILE) ? 1 : 0);
     1303        if (lppd->Flags & PD_DISABLEPRINTTOFILE)
     1304            EnableWindow(GetDlgItem(hDlg, chx1), FALSE);
     1305        if (lppd->Flags & PD_HIDEPRINTTOFILE)
     1306            ShowWindow(GetDlgItem(hDlg, chx1), SW_HIDE);
     1307
     1308    } else { /* PD_PRINTSETUP */
     1309      BOOL bPortrait = (lpdm->u1.s1.dmOrientation == DMORIENT_PORTRAIT);
     1310
     1311      PRINTDLG_SetUpPaperComboBoxW(hDlg, cmb2,
     1312                                  PrintStructures->lpPrinterInfo->pPrinterName,
     1313                                  PrintStructures->lpPrinterInfo->pPortName,
     1314                                  lpdm);
     1315      PRINTDLG_SetUpPaperComboBoxW(hDlg, cmb3,
     1316                                  PrintStructures->lpPrinterInfo->pPrinterName,
     1317                                  PrintStructures->lpPrinterInfo->pPortName,
     1318                                  lpdm);
     1319      CheckRadioButton(hDlg, rad1, rad2, bPortrait ? rad1: rad2);
     1320      SendDlgItemMessageA(hDlg, ico1, STM_SETIMAGE, (WPARAM) IMAGE_ICON,
     1321                          (LPARAM)(bPortrait ? PrintStructures->hPortraitIcon :
     1322                                   PrintStructures->hLandscapeIcon));
     1323
     1324    }
     1325
     1326    /* help button */
     1327    if ((lppd->Flags & PD_SHOWHELP)==0) {
     1328        /* hide if PD_SHOWHELP not specified */
     1329        ShowWindow(GetDlgItem(hDlg, pshHelp), SW_HIDE);
    7591330    }
    7601331    return TRUE;
     
    7741345
    7751346    /* load Collate ICONs */
    776     /* We load these with LoadImage becasue they are not a standard
     1347    /* We load these with LoadImage because they are not a standard
    7771348       size and we don't want them rescaled */
    7781349    PrintStructures->hCollateIcon =
    7791350      LoadImageA(COMDLG32_hInstance, "PD32_COLLATE", IMAGE_ICON, 0, 0, 0);
    780     PrintStructures->hNoCollateIcon = 
     1351    PrintStructures->hNoCollateIcon =
    7811352      LoadImageA(COMDLG32_hInstance, "PD32_NOCOLLATE", IMAGE_ICON, 0, 0, 0);
    7821353
     
    8011372     */
    8021373    if (lppd->Flags & PD_SHOWHELP) {
    803         if((PrintStructures->HelpMessageID = 
     1374        if((PrintStructures->HelpMessageID =
    8041375            RegisterWindowMessageA(HELPMSGSTRINGA)) == 0) {
    8051376            COMDLG32_SetCommDlgExtendedError(CDERR_REGISTERMSGFAIL);
     
    8241395    if (lppd->nMaxPage < lppd->nMinPage)
    8251396        lppd->nMaxPage = lppd->nMinPage;
    826     if (lppd->nMinPage == lppd->nMaxPage) 
    827         lppd->Flags |= PD_NOPAGENUMS;       
     1397    if (lppd->nMinPage == lppd->nMaxPage)
     1398        lppd->Flags |= PD_NOPAGENUMS;
    8281399    if (lppd->nToPage < lppd->nMinPage)
    8291400        lppd->nToPage = lppd->nMinPage;
     
    8371408    /* if we have the combo box, fill it */
    8381409    if (GetDlgItem(hDlg,comboID)) {
    839         /* Fill Combobox 
     1410        /* Fill Combobox
    8401411         */
    8411412        pdn = GlobalLock(lppd->hDevNames);
     
    8451416        else if(pdm)
    8461417            name = pdm->dmDeviceName;
    847         PRINTDLG_SetUpPrinterListCombo(hDlg, comboID, name);
     1418        PRINTDLG_SetUpPrinterListComboA(hDlg, comboID, name);
    8481419        if(pdm) GlobalUnlock(lppd->hDevMode);
    8491420        if(pdn) GlobalUnlock(lppd->hDevNames);
     
    8521423        name = HeapAlloc(GetProcessHeap(),0,256);
    8531424        if (GetDlgItemTextA(hDlg, comboID, name, 255))
    854             PRINTDLG_ChangePrinter(hDlg, name, PrintStructures);
     1425            PRINTDLG_ChangePrinterA(hDlg, name, PrintStructures);
    8551426        HeapFree(GetProcessHeap(),0,name);
    8561427    } else {
    8571428        /* else use default printer */
    8581429        char name[200];
    859         BOOL ret = PRINTDLG_GetDefaultPrinterName(name, sizeof(name));
     1430        BOOL ret = PRINTDLG_GetDefaultPrinterNameA(name, sizeof(name));
    8601431
    8611432        if (ret)
    862             PRINTDLG_ChangePrinter(hDlg, name, PrintStructures);
     1433            PRINTDLG_ChangePrinterA(hDlg, name, PrintStructures);
     1434        else
     1435            FIXME("No default printer found, expect problems!\n");
     1436    }
     1437    return TRUE;
     1438}
     1439
     1440static LRESULT PRINTDLG_WMInitDialogW(HWND hDlg, WPARAM wParam,
     1441                                     PRINT_PTRW* PrintStructures)
     1442{
     1443    LPPRINTDLGW lppd = PrintStructures->dlg.lpPrintDlg;
     1444    DEVNAMES *pdn;
     1445    DEVMODEW *pdm;
     1446    WCHAR *name = NULL;
     1447    UINT comboID = (lppd->Flags & PD_PRINTSETUP) ? cmb1 : cmb4;
     1448
     1449    /* load Collate ICONs */
     1450    /* We load these with LoadImage because they are not a standard
     1451       size and we don't want them rescaled */
     1452    PrintStructures->hCollateIcon =
     1453      LoadImageA(COMDLG32_hInstance, "PD32_COLLATE", IMAGE_ICON, 0, 0, 0);
     1454    PrintStructures->hNoCollateIcon =
     1455      LoadImageA(COMDLG32_hInstance, "PD32_NOCOLLATE", IMAGE_ICON, 0, 0, 0);
     1456
     1457    /* These can be done with LoadIcon */
     1458    PrintStructures->hPortraitIcon =
     1459      LoadIconA(COMDLG32_hInstance, "PD32_PORTRAIT");
     1460    PrintStructures->hLandscapeIcon =
     1461      LoadIconA(COMDLG32_hInstance, "PD32_LANDSCAPE");
     1462
     1463    if(PrintStructures->hCollateIcon == 0 ||
     1464       PrintStructures->hNoCollateIcon == 0 ||
     1465       PrintStructures->hPortraitIcon == 0 ||
     1466       PrintStructures->hLandscapeIcon == 0) {
     1467        ERR("no icon in resourcefile\n");
     1468        COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
     1469        EndDialog(hDlg, FALSE);
     1470    }
     1471
     1472    /*
     1473     * if lppd->Flags PD_SHOWHELP is specified, a HELPMESGSTRING message
     1474     * must be registered and the Help button must be shown.
     1475     */
     1476    if (lppd->Flags & PD_SHOWHELP) {
     1477        if((PrintStructures->HelpMessageID =
     1478            RegisterWindowMessageA(HELPMSGSTRINGA)) == 0) {
     1479            COMDLG32_SetCommDlgExtendedError(CDERR_REGISTERMSGFAIL);
     1480            return FALSE;
     1481        }
     1482    } else
     1483        PrintStructures->HelpMessageID = 0;
     1484
     1485    if(!(lppd->Flags &PD_PRINTSETUP)) {
     1486        PrintStructures->hwndUpDown =
     1487          CreateUpDownControl(WS_CHILD | WS_VISIBLE | WS_BORDER |
     1488                              UDS_NOTHOUSANDS | UDS_ARROWKEYS |
     1489                              UDS_ALIGNRIGHT | UDS_SETBUDDYINT, 0, 0, 0, 0,
     1490                              hDlg, UPDOWN_ID, COMDLG32_hInstance,
     1491                              GetDlgItem(hDlg, edt3), MAX_COPIES, 1, 1);
     1492    }
     1493
     1494    /* FIXME: I allow more freedom than either Win95 or WinNT,
     1495     *        which do not agree to what errors should be thrown or not
     1496     *        in case nToPage or nFromPage is out-of-range.
     1497     */
     1498    if (lppd->nMaxPage < lppd->nMinPage)
     1499        lppd->nMaxPage = lppd->nMinPage;
     1500    if (lppd->nMinPage == lppd->nMaxPage)
     1501        lppd->Flags |= PD_NOPAGENUMS;
     1502    if (lppd->nToPage < lppd->nMinPage)
     1503        lppd->nToPage = lppd->nMinPage;
     1504    if (lppd->nToPage > lppd->nMaxPage)
     1505        lppd->nToPage = lppd->nMaxPage;
     1506    if (lppd->nFromPage < lppd->nMinPage)
     1507        lppd->nFromPage = lppd->nMinPage;
     1508    if (lppd->nFromPage > lppd->nMaxPage)
     1509        lppd->nFromPage = lppd->nMaxPage;
     1510
     1511    /* if we have the combo box, fill it */
     1512    if (GetDlgItem(hDlg,comboID)) {
     1513        /* Fill Combobox
     1514         */
     1515        pdn = GlobalLock(lppd->hDevNames);
     1516        pdm = GlobalLock(lppd->hDevMode);
     1517        if(pdn)
     1518            name = (WCHAR*)pdn + pdn->wDeviceOffset;
     1519        else if(pdm)
     1520            name = pdm->dmDeviceName;
     1521        PRINTDLG_SetUpPrinterListComboW(hDlg, comboID, name);
     1522        if(pdm) GlobalUnlock(lppd->hDevMode);
     1523        if(pdn) GlobalUnlock(lppd->hDevNames);
     1524
     1525        /* Now find selected printer and update rest of dlg */
     1526        /* ansi is ok here */
     1527        name = HeapAlloc(GetProcessHeap(),0,256*sizeof(WCHAR));
     1528        if (GetDlgItemTextW(hDlg, comboID, name, 255))
     1529            PRINTDLG_ChangePrinterW(hDlg, name, PrintStructures);
     1530        HeapFree(GetProcessHeap(),0,name);
     1531    } else {
     1532        /* else use default printer */
     1533        WCHAR name[200];
     1534        BOOL ret = PRINTDLG_GetDefaultPrinterNameW(name, sizeof(name));
     1535
     1536        if (ret)
     1537            PRINTDLG_ChangePrinterW(hDlg, name, PrintStructures);
    8631538        else
    8641539            FIXME("No default printer found, expect problems!\n");
     
    8831558    PrintStructures->hCollateIcon =
    8841559      LoadIconA(COMDLG32_hInstance, "PD32_COLLATE");
    885     PrintStructures->hNoCollateIcon = 
     1560    PrintStructures->hNoCollateIcon =
    8861561      LoadIconA(COMDLG32_hInstance, "PD32_NOCOLLATE");
    8871562    if(PrintStructures->hCollateIcon == 0 ||
     
    9001575     */
    9011576    if (lppd->Flags & PD_SHOWHELP) {
    902         if((PrintStructures->HelpMessageID = 
     1577        if((PrintStructures->HelpMessageID =
    9031578            RegisterWindowMessageA(HELPMSGSTRINGA)) == 0) {
    9041579            COMDLG32_SetCommDlgExtendedError(CDERR_REGISTERMSGFAIL);
     
    9261601                }
    9271602                GlobalUnlock16(lppd->hDevMode);
    928             } else 
     1603            } else
    9291604                strcpy(buf,"Default");
    9301605            SendDlgItemMessageA(hDlg,cmb1,CB_ADDSTRING,0,(LPARAM)buf);
     
    9401615    if (lppd->nMaxPage < lppd->nMinPage)
    9411616        lppd->nMaxPage = lppd->nMinPage;
    942     if (lppd->nMinPage == lppd->nMaxPage) 
    943         lppd->Flags |= PD_NOPAGENUMS;       
     1617    if (lppd->nMinPage == lppd->nMaxPage)
     1618        lppd->Flags |= PD_NOPAGENUMS;
    9441619    if (lppd->nToPage < lppd->nMinPage)
    9451620        lppd->nToPage = lppd->nMinPage;
     
    9531628    /* If the printer combo box is in the dialog, fill it */
    9541629    if (GetDlgItem(hDlg,comboID)) {
    955         /* Fill Combobox 
     1630        /* Fill Combobox
    9561631         */
    9571632        pdn = GlobalLock16(lppd->hDevNames);
     
    9611636        else if(pdm)
    9621637            name = pdm->dmDeviceName;
    963         PRINTDLG_SetUpPrinterListCombo(hDlg, comboID, name);
     1638        PRINTDLG_SetUpPrinterListComboA(hDlg, comboID, name);
    9641639        if(pdm) GlobalUnlock16(lppd->hDevMode);
    9651640        if(pdn) GlobalUnlock16(lppd->hDevNames);
     
    9681643        name = HeapAlloc(GetProcessHeap(),0,256);
    9691644        if (GetDlgItemTextA(hDlg, comboID, name, 255))
    970             PRINTDLG_ChangePrinter(hDlg, name, PrintStructures);
     1645            PRINTDLG_ChangePrinterA(hDlg, name, PrintStructures);
    9711646    } else {
    9721647        /* else just use default printer */
    9731648        char name[200];
    974         BOOL ret = PRINTDLG_GetDefaultPrinterName(name, sizeof(name));
     1649        BOOL ret = PRINTDLG_GetDefaultPrinterNameA(name, sizeof(name));
    9751650
    9761651        if (ret)
    977             PRINTDLG_ChangePrinter(hDlg, name, PrintStructures);
     1652            PRINTDLG_ChangePrinterA(hDlg, name, PrintStructures);
    9781653        else
    9791654            FIXME("No default printer found, expect problems!\n");
     
    9841659}
    9851660#endif
    986 
    9871661/***********************************************************************
    9881662 *                              PRINTDLG_WMCommand               [internal]
    9891663 */
    990 static LRESULT PRINTDLG_WMCommand(HWND hDlg, WPARAM wParam,
     1664static LRESULT PRINTDLG_WMCommandA(HWND hDlg, WPARAM wParam,
    9911665                        LPARAM lParam, PRINT_PTRA* PrintStructures)
    9921666{
     
    9981672    case IDOK:
    9991673        TRACE(" OK button was hit\n");
    1000         if (PRINTDLG_UpdatePrintDlg(hDlg, PrintStructures)!=TRUE) {
     1674        if (PRINTDLG_UpdatePrintDlgA(hDlg, PrintStructures)!=TRUE) {
    10011675            FIXME("Update printdlg was not successful!\n");
    10021676            return(FALSE);
     
    10121686     case pshHelp:
    10131687        TRACE(" HELP button was hit\n");
    1014         SendMessageA(lppd->hwndOwner, PrintStructures->HelpMessageID, 
     1688        SendMessageA(lppd->hwndOwner, PrintStructures->HelpMessageID,
    10151689                                (WPARAM) hDlg, (LPARAM) lppd);
    10161690        break;
     
    10181692     case chx2:                         /* collate pages checkbox */
    10191693        if (IsDlgButtonChecked(hDlg, chx2) == BST_CHECKED)
    1020             SendDlgItemMessageA(hDlg, ico3, STM_SETIMAGE, (WPARAM) IMAGE_ICON, 
     1694            SendDlgItemMessageA(hDlg, ico3, STM_SETIMAGE, (WPARAM) IMAGE_ICON,
    10211695                                    (LPARAM)PrintStructures->hCollateIcon);
    10221696        else
    1023             SendDlgItemMessageA(hDlg, ico3, STM_SETIMAGE, (WPARAM) IMAGE_ICON, 
     1697            SendDlgItemMessageA(hDlg, ico3, STM_SETIMAGE, (WPARAM) IMAGE_ICON,
    10241698                                    (LPARAM)PrintStructures->hNoCollateIcon);
    1025         break;       
     1699        break;
    10261700     case edt1:                         /* from page nr editbox */
    10271701     case edt2:                         /* to page nr editbox */
     
    10501724        {
    10511725            PRINTDLG16  pdlg;
    1052            
     1726
    10531727            if (!PrintStructures->dlg.lpPrintDlg16) {
    10541728                FIXME("The 32bit print dialog does not have this button!?\n");
     
    10581732            memcpy(&pdlg,PrintStructures->dlg.lpPrintDlg16,sizeof(pdlg));
    10591733            pdlg.Flags |= PD_PRINTSETUP;
    1060             pdlg.hwndOwner = hDlg;
     1734            pdlg.hwndOwner = HWND_16(hDlg);
    10611735            if (!PrintDlg16(&pdlg))
    10621736                break;
     
    10751749             break;
    10761750         }
    1077          DocumentPropertiesA(hDlg, hPrinter, PrinterName, 
     1751         DocumentPropertiesA(hDlg, hPrinter, PrinterName,
    10781752                             PrintStructures->lpDevMode,
    10791753                             PrintStructures->lpDevMode,
     
    10861760        if (lppd->Flags & PD_PRINTSETUP)
    10871761        {
    1088 #ifdef __WIN32OS2__
    1089               lpdm->dmOrientation = DMORIENT_PORTRAIT;
    1090 #else
    10911762              lpdm->u1.s1.dmOrientation = DMORIENT_PORTRAIT;
    1092 #endif
    10931763              SendDlgItemMessageA(hDlg, ico1, STM_SETIMAGE, (WPARAM) IMAGE_ICON,
    10941764                          (LPARAM)(PrintStructures->hPortraitIcon));
    10951765        }
    10961766        break;
    1097            
     1767
    10981768    case rad2: /* Paperorientation */
    10991769        if (lppd->Flags & PD_PRINTSETUP)
    11001770        {
    1101 #ifdef __WIN32OS2__
    1102               lpdm->dmOrientation = DMORIENT_LANDSCAPE;
    1103 #else
    11041771              lpdm->u1.s1.dmOrientation = DMORIENT_LANDSCAPE;
    1105 #endif
    11061772              SendDlgItemMessageA(hDlg, ico1, STM_SETIMAGE, (WPARAM) IMAGE_ICON,
    11071773                          (LPARAM)(PrintStructures->hLandscapeIcon));
    11081774        }
    11091775        break;
    1110            
     1776
    11111777    case cmb1: /* Printer Combobox in PRINT SETUP, quality combobox in PRINT */
    11121778         if (PrinterComboID != wParam) {
     
    11191785             char   PrinterName[256];
    11201786             GetDlgItemTextA(hDlg, LOWORD(wParam), PrinterName, 255);
    1121              PRINTDLG_ChangePrinter(hDlg, PrinterName, PrintStructures);
     1787             PRINTDLG_ChangePrinterA(hDlg, PrinterName, PrintStructures);
    11221788         }
    11231789         break;
     
    11271793          DWORD Sel = SendDlgItemMessageA(hDlg, cmb2, CB_GETCURSEL, 0, 0);
    11281794          if(Sel != CB_ERR)
    1129 #ifdef __WIN32OS2__
    1130               lpdm->dmPaperSize = SendDlgItemMessageA(hDlg, cmb2,
    1131 #else
    11321795              lpdm->u1.s1.dmPaperSize = SendDlgItemMessageA(hDlg, cmb2,
    1133 #endif
    11341796                                                            CB_GETITEMDATA,
    11351797                                                            Sel, 0);
     
    11451807                                                          0);
    11461808      }
    1147       break; 
     1809      break;
    11481810    }
    11491811    if(lppd->Flags & PD_PRINTSETUP) {
     
    11521814        case rad2:
    11531815            if (IsDlgButtonChecked(hDlg, rad1) == BST_CHECKED) {
    1154 #ifdef __WIN32OS2__
    1155                 if(lpdm->dmOrientation != DMORIENT_PORTRAIT) {
    1156                     lpdm->dmOrientation = DMORIENT_PORTRAIT;
    1157 #else
    11581816                if(lpdm->u1.s1.dmOrientation != DMORIENT_PORTRAIT) {
    11591817                    lpdm->u1.s1.dmOrientation = DMORIENT_PORTRAIT;
    1160 #endif
    11611818                    SendDlgItemMessageA(hDlg, stc10, STM_SETIMAGE,
    11621819                                        (WPARAM)IMAGE_ICON,
     
    11671824                }
    11681825            } else {
    1169 #ifdef __WIN32OS2__
    1170                 if(lpdm->dmOrientation != DMORIENT_LANDSCAPE) {
    1171                     lpdm->dmOrientation = DMORIENT_LANDSCAPE;
    1172 #else
    11731826                if(lpdm->u1.s1.dmOrientation != DMORIENT_LANDSCAPE) {
    11741827                    lpdm->u1.s1.dmOrientation = DMORIENT_LANDSCAPE;
    1175 #endif
    11761828                    SendDlgItemMessageA(hDlg, stc10, STM_SETIMAGE,
    11771829                                        (WPARAM)IMAGE_ICON,
     
    11861838    }
    11871839    return FALSE;
    1188 }   
     1840}
     1841
     1842static LRESULT PRINTDLG_WMCommandW(HWND hDlg, WPARAM wParam,
     1843                        LPARAM lParam, PRINT_PTRW* PrintStructures)
     1844{
     1845    LPPRINTDLGW lppd = PrintStructures->dlg.lpPrintDlg;
     1846    UINT PrinterComboID = (lppd->Flags & PD_PRINTSETUP) ? cmb1 : cmb4;
     1847    LPDEVMODEW lpdm = PrintStructures->lpDevMode;
     1848
     1849    switch (LOWORD(wParam))  {
     1850    case IDOK:
     1851        TRACE(" OK button was hit\n");
     1852        if (PRINTDLG_UpdatePrintDlgW(hDlg, PrintStructures)!=TRUE) {
     1853            FIXME("Update printdlg was not successful!\n");
     1854            return(FALSE);
     1855        }
     1856        EndDialog(hDlg, TRUE);
     1857        return(TRUE);
     1858
     1859    case IDCANCEL:
     1860        TRACE(" CANCEL button was hit\n");
     1861        EndDialog(hDlg, FALSE);
     1862        return(FALSE);
     1863
     1864     case pshHelp:
     1865        TRACE(" HELP button was hit\n");
     1866        SendMessageW(lppd->hwndOwner, PrintStructures->HelpMessageID,
     1867                                (WPARAM) hDlg, (LPARAM) lppd);
     1868        break;
     1869
     1870     case chx2:                         /* collate pages checkbox */
     1871        if (IsDlgButtonChecked(hDlg, chx2) == BST_CHECKED)
     1872            SendDlgItemMessageA(hDlg, ico3, STM_SETIMAGE, (WPARAM) IMAGE_ICON,
     1873                                    (LPARAM)PrintStructures->hCollateIcon);
     1874        else
     1875            SendDlgItemMessageA(hDlg, ico3, STM_SETIMAGE, (WPARAM) IMAGE_ICON,
     1876                                    (LPARAM)PrintStructures->hNoCollateIcon);
     1877        break;
     1878     case edt1:                         /* from page nr editbox */
     1879     case edt2:                         /* to page nr editbox */
     1880        if (HIWORD(wParam)==EN_CHANGE) {
     1881            WORD nToPage;
     1882            WORD nFromPage;
     1883            nFromPage = GetDlgItemInt(hDlg, edt1, NULL, FALSE);
     1884            nToPage   = GetDlgItemInt(hDlg, edt2, NULL, FALSE);
     1885            if (nFromPage != lppd->nFromPage || nToPage != lppd->nToPage)
     1886                CheckRadioButton(hDlg, rad1, rad3, rad3);
     1887        }
     1888        break;
     1889
     1890    case edt3:
     1891        if(HIWORD(wParam) == EN_CHANGE) {
     1892            INT copies = GetDlgItemInt(hDlg, edt3, NULL, FALSE);
     1893            if(copies <= 1)
     1894                EnableWindow(GetDlgItem(hDlg, chx2), FALSE);
     1895            else
     1896                EnableWindow(GetDlgItem(hDlg, chx2), TRUE);
     1897        }
     1898        break;
     1899
     1900     case psh1:                       /* Print Setup */
     1901        {
     1902                ERR("psh1 is called from 16bit code only, we should not get here.\n");
     1903        }
     1904        break;
     1905     case psh2:                       /* Properties button */
     1906       {
     1907         HANDLE hPrinter;
     1908         WCHAR  PrinterName[256];
     1909
     1910         GetDlgItemTextW(hDlg, PrinterComboID, PrinterName, 255);
     1911         if (!OpenPrinterW(PrinterName, &hPrinter, NULL)) {
     1912             FIXME(" Call to OpenPrinter did not succeed!\n");
     1913             break;
     1914         }
     1915         DocumentPropertiesW(hDlg, hPrinter, PrinterName,
     1916                             PrintStructures->lpDevMode,
     1917                             PrintStructures->lpDevMode,
     1918                             DM_IN_BUFFER | DM_OUT_BUFFER | DM_IN_PROMPT);
     1919         ClosePrinter(hPrinter);
     1920         break;
     1921       }
     1922
     1923    case rad1: /* Paperorientation */
     1924        if (lppd->Flags & PD_PRINTSETUP)
     1925        {
     1926              lpdm->u1.s1.dmOrientation = DMORIENT_PORTRAIT;
     1927              SendDlgItemMessageA(hDlg, ico1, STM_SETIMAGE, (WPARAM) IMAGE_ICON,
     1928                          (LPARAM)(PrintStructures->hPortraitIcon));
     1929        }
     1930        break;
     1931
     1932    case rad2: /* Paperorientation */
     1933        if (lppd->Flags & PD_PRINTSETUP)
     1934        {
     1935              lpdm->u1.s1.dmOrientation = DMORIENT_LANDSCAPE;
     1936              SendDlgItemMessageA(hDlg, ico1, STM_SETIMAGE, (WPARAM) IMAGE_ICON,
     1937                          (LPARAM)(PrintStructures->hLandscapeIcon));
     1938        }
     1939        break;
     1940
     1941    case cmb1: /* Printer Combobox in PRINT SETUP, quality combobox in PRINT */
     1942         if (PrinterComboID != wParam) {
     1943             FIXME("No handling for print quality combo box yet.\n");
     1944             break;
     1945         }
     1946         /* FALLTHROUGH */
     1947    case cmb4:                         /* Printer combobox */
     1948         if (HIWORD(wParam)==CBN_SELCHANGE) {
     1949             WCHAR   PrinterName[256];
     1950             GetDlgItemTextW(hDlg, LOWORD(wParam), PrinterName, 255);
     1951             PRINTDLG_ChangePrinterW(hDlg, PrinterName, PrintStructures);
     1952         }
     1953         break;
     1954
     1955    case cmb2: /* Papersize */
     1956      {
     1957          DWORD Sel = SendDlgItemMessageA(hDlg, cmb2, CB_GETCURSEL, 0, 0);
     1958          if(Sel != CB_ERR)
     1959              lpdm->u1.s1.dmPaperSize = SendDlgItemMessageA(hDlg, cmb2,
     1960                                                            CB_GETITEMDATA,
     1961                                                            Sel, 0);
     1962      }
     1963      break;
     1964
     1965    case cmb3: /* Bin */
     1966      {
     1967          DWORD Sel = SendDlgItemMessageA(hDlg, cmb3, CB_GETCURSEL, 0, 0);
     1968          if(Sel != CB_ERR)
     1969              lpdm->dmDefaultSource = SendDlgItemMessageW(hDlg, cmb3,
     1970                                                          CB_GETITEMDATA, Sel,
     1971                                                          0);
     1972      }
     1973      break;
     1974    }
     1975    if(lppd->Flags & PD_PRINTSETUP) {
     1976        switch (LOWORD(wParam)) {
     1977        case rad1:                         /* orientation */
     1978        case rad2:
     1979            if (IsDlgButtonChecked(hDlg, rad1) == BST_CHECKED) {
     1980                if(lpdm->u1.s1.dmOrientation != DMORIENT_PORTRAIT) {
     1981                    lpdm->u1.s1.dmOrientation = DMORIENT_PORTRAIT;
     1982                    SendDlgItemMessageA(hDlg, stc10, STM_SETIMAGE,
     1983                                        (WPARAM)IMAGE_ICON,
     1984                                        (LPARAM)PrintStructures->hPortraitIcon);
     1985                    SendDlgItemMessageA(hDlg, ico1, STM_SETIMAGE,
     1986                                        (WPARAM)IMAGE_ICON,
     1987                                        (LPARAM)PrintStructures->hPortraitIcon);
     1988                }
     1989            } else {
     1990                if(lpdm->u1.s1.dmOrientation != DMORIENT_LANDSCAPE) {
     1991                    lpdm->u1.s1.dmOrientation = DMORIENT_LANDSCAPE;
     1992                    SendDlgItemMessageA(hDlg, stc10, STM_SETIMAGE,
     1993                                        (WPARAM)IMAGE_ICON,
     1994                                        (LPARAM)PrintStructures->hLandscapeIcon);
     1995                    SendDlgItemMessageA(hDlg, ico1, STM_SETIMAGE,
     1996                                        (WPARAM)IMAGE_ICON,
     1997                                        (LPARAM)PrintStructures->hLandscapeIcon);
     1998                }
     1999            }
     2000            break;
     2001        }
     2002    }
     2003    return FALSE;
     2004}
    11892005
    11902006/***********************************************************************
    11912007 *           PrintDlgProcA                      [internal]
    11922008 */
    1193 #ifdef __WIN32OS2__
    1194 LRESULT WINAPI PrintDlgProcA(HWND hDlg, UINT uMsg, WPARAM wParam,
    1195                              LPARAM lParam)
    1196 #else
    11972009BOOL WINAPI PrintDlgProcA(HWND hDlg, UINT uMsg, WPARAM wParam,
    11982010                          LPARAM lParam)
    1199 #endif
    12002011{
    12012012    PRINT_PTRA* PrintStructures;
     
    12032014
    12042015    if (uMsg!=WM_INITDIALOG) {
    1205         PrintStructures = (PRINT_PTRA*) GetWindowLongA(hDlg, DWL_USER);   
     2016        PrintStructures = (PRINT_PTRA*)GetPropA(hDlg,"__WINE_PRINTDLGDATA");
    12062017        if (!PrintStructures)
    12072018            return FALSE;
    12082019    } else {
    12092020        PrintStructures = (PRINT_PTRA*) lParam;
    1210         SetWindowLongA(hDlg, DWL_USER, lParam);
     2021        SetPropA(hDlg,"__WINE_PRINTDLGDATA",lParam);
    12112022        res = PRINTDLG_WMInitDialog(hDlg, wParam, PrintStructures);
    12122023
     
    12142025            res = PrintStructures->dlg.lpPrintDlg->lpfnPrintHook(
    12152026                hDlg, uMsg, wParam, (LPARAM)PrintStructures->dlg.lpPrintDlg
    1216             ); 
     2027            );
    12172028        return res;
    12182029    }
    1219  
     2030
    12202031    if(PrintStructures->dlg.lpPrintDlg->Flags & PD_ENABLEPRINTHOOK) {
    12212032        res = PrintStructures->dlg.lpPrintDlg->lpfnPrintHook(hDlg,uMsg,wParam,
     
    12262037    switch (uMsg) {
    12272038    case WM_COMMAND:
    1228         return PRINTDLG_WMCommand(hDlg, wParam, lParam, PrintStructures);
     2039        return PRINTDLG_WMCommandA(hDlg, wParam, lParam, PrintStructures);
    12292040
    12302041    case WM_DESTROY:
     
    12362047            DestroyWindow(PrintStructures->hwndUpDown);
    12372048        return FALSE;
    1238     }   
     2049    }
     2050    return res;
     2051}
     2052
     2053BOOL WINAPI PrintDlgProcW(HWND hDlg, UINT uMsg, WPARAM wParam,
     2054                          LPARAM lParam)
     2055{
     2056    PRINT_PTRW* PrintStructures;
     2057    LRESULT res=FALSE;
     2058
     2059    if (uMsg!=WM_INITDIALOG) {
     2060        PrintStructures = (PRINT_PTRW*) GetWindowLongA(hDlg, DWL_USER);
     2061        if (!PrintStructures)
     2062            return FALSE;
     2063    } else {
     2064        PrintStructures = (PRINT_PTRW*) lParam;
     2065        SetWindowLongA(hDlg, DWL_USER, lParam);
     2066        res = PRINTDLG_WMInitDialogW(hDlg, wParam, PrintStructures);
     2067
     2068        if(PrintStructures->dlg.lpPrintDlg->Flags & PD_ENABLEPRINTHOOK)
     2069            res = PrintStructures->dlg.lpPrintDlg->lpfnPrintHook(
     2070                hDlg, uMsg, wParam, (LPARAM)PrintStructures->dlg.lpPrintDlg
     2071            );
     2072        return res;
     2073    }
     2074
     2075    if(PrintStructures->dlg.lpPrintDlg->Flags & PD_ENABLEPRINTHOOK) {
     2076        res = PrintStructures->dlg.lpPrintDlg->lpfnPrintHook(hDlg,uMsg,wParam,
     2077                                                         lParam);
     2078        if(res) return res;
     2079    }
     2080
     2081    switch (uMsg) {
     2082    case WM_COMMAND:
     2083        return PRINTDLG_WMCommandW(hDlg, wParam, lParam, PrintStructures);
     2084
     2085    case WM_DESTROY:
     2086        DestroyIcon(PrintStructures->hCollateIcon);
     2087        DestroyIcon(PrintStructures->hNoCollateIcon);
     2088        DestroyIcon(PrintStructures->hPortraitIcon);
     2089        DestroyIcon(PrintStructures->hLandscapeIcon);
     2090        if(PrintStructures->hwndUpDown)
     2091            DestroyWindow(PrintStructures->hwndUpDown);
     2092        return FALSE;
     2093    }
    12392094    return res;
    12402095}
     
    12502105static HGLOBAL16 PRINTDLG_Get16TemplateFrom32(char *PrintResourceName)
    12512106{
    1252         HANDLE hResInfo, hDlgTmpl32;
     2107        HRSRC hResInfo;
     2108        HGLOBAL hDlgTmpl32;
    12532109        LPCVOID template32;
    12542110        DWORD size;
    12552111        HGLOBAL16 hGlobal16;
    12562112        LPVOID template;
    1257  
     2113
    12582114        if (!(hResInfo = FindResourceA(COMMDLG_hInstance32,
    12592115               PrintResourceName, RT_DIALOGA)))
     
    12952151 *
    12962152 */
    1297 static HGLOBAL PRINTDLG_GetDlgTemplate(PRINTDLGA *lppd)
    1298 {
    1299     HGLOBAL hDlgTmpl, hResInfo;
     2153static HGLOBAL PRINTDLG_GetDlgTemplateA(PRINTDLGA *lppd)
     2154{
     2155    HRSRC hResInfo;
     2156    HGLOBAL hDlgTmpl;
    13002157
    13012158    if (lppd->Flags & PD_PRINTSETUP) {
    13022159        if(lppd->Flags & PD_ENABLESETUPTEMPLATEHANDLE) {
    13032160            hDlgTmpl = lppd->hSetupTemplate;
    1304         } else if(lppd->Flags & PD_ENABLESETUPTEMPLATE) {       
     2161        } else if(lppd->Flags & PD_ENABLESETUPTEMPLATE) {
    13052162            hResInfo = FindResourceA(lppd->hInstance,
    13062163                                     lppd->lpSetupTemplateName, RT_DIALOGA);
     
    13282185}
    13292186
    1330 
    1331 #ifndef __WIN32OS2__
    1332 /************************************************************
    1333  *
    1334  *      PRINTDLG_GetDlgTemplate
    1335  *
    1336  */
    1337 static HGLOBAL16 PRINTDLG_GetDlgTemplate16(PRINTDLG16 *lppd)
    1338 {
    1339     HGLOBAL16 hDlgTmpl, hResInfo;
     2187static HGLOBAL PRINTDLG_GetDlgTemplateW(PRINTDLGW *lppd)
     2188{
     2189    HRSRC hResInfo;
     2190    HGLOBAL hDlgTmpl;
     2191    const WCHAR xpsetup[] = { 'P','R','I','N','T','3','2','_','S','E','T','U','P',0};
     2192    const WCHAR xprint[] = { 'P','R','I','N','T','3','2',0};
    13402193
    13412194    if (lppd->Flags & PD_PRINTSETUP) {
    13422195        if(lppd->Flags & PD_ENABLESETUPTEMPLATEHANDLE) {
    13432196            hDlgTmpl = lppd->hSetupTemplate;
    1344         } else if(lppd->Flags & PD_ENABLESETUPTEMPLATE) {       
     2197        } else if(lppd->Flags & PD_ENABLESETUPTEMPLATE) {
     2198            hResInfo = FindResourceW(lppd->hInstance,
     2199                                     lppd->lpSetupTemplateName, RT_DIALOGW);
     2200            hDlgTmpl = LoadResource(lppd->hInstance, hResInfo);
     2201        } else {
     2202            hResInfo = FindResourceW(COMDLG32_hInstance, xpsetup, RT_DIALOGW);
     2203            hDlgTmpl = LoadResource(COMDLG32_hInstance, hResInfo);
     2204        }
     2205    } else {
     2206        if(lppd->Flags & PD_ENABLEPRINTTEMPLATEHANDLE) {
     2207            hDlgTmpl = lppd->hPrintTemplate;
     2208        } else if(lppd->Flags & PD_ENABLEPRINTTEMPLATE) {
     2209            hResInfo = FindResourceW(lppd->hInstance,
     2210                                     lppd->lpPrintTemplateName,
     2211                                     RT_DIALOGW);
     2212            hDlgTmpl = LoadResource(lppd->hInstance, hResInfo);
     2213        } else {
     2214            hResInfo = FindResourceW(COMDLG32_hInstance, xprint, RT_DIALOGW);
     2215            hDlgTmpl = LoadResource(COMDLG32_hInstance, hResInfo);
     2216        }
     2217    }
     2218    return hDlgTmpl;
     2219}
     2220
     2221
     2222#ifndef __WIN32OS2__
     2223/************************************************************
     2224 *
     2225 *      PRINTDLG_GetDlgTemplate
     2226 *
     2227 */
     2228static HGLOBAL16 PRINTDLG_GetDlgTemplate16(PRINTDLG16 *lppd)
     2229{
     2230    HGLOBAL16 hDlgTmpl, hResInfo;
     2231
     2232    if (lppd->Flags & PD_PRINTSETUP) {
     2233        if(lppd->Flags & PD_ENABLESETUPTEMPLATEHANDLE) {
     2234            hDlgTmpl = lppd->hSetupTemplate;
     2235        } else if(lppd->Flags & PD_ENABLESETUPTEMPLATE) {
    13452236            hResInfo = FindResource16(lppd->hInstance,
    13462237                                     MapSL(lppd->lpSetupTemplateName), RT_DIALOGA);
     
    13702261 *
    13712262 */
    1372 static BOOL PRINTDLG_CreateDC(LPPRINTDLGA lppd)
     2263static BOOL PRINTDLG_CreateDCA(LPPRINTDLGA lppd)
    13732264{
    13742265    DEVNAMES *pdn = GlobalLock(lppd->hDevNames);
     
    13912282}
    13922283
     2284static BOOL PRINTDLG_CreateDCW(LPPRINTDLGW lppd)
     2285{
     2286    DEVNAMES *pdn = GlobalLock(lppd->hDevNames);
     2287    DEVMODEW *pdm = GlobalLock(lppd->hDevMode);
     2288
     2289    if(lppd->Flags & PD_RETURNDC) {
     2290        lppd->hDC = CreateDCW((WCHAR*)pdn + pdn->wDriverOffset,
     2291                              (WCHAR*)pdn + pdn->wDeviceOffset,
     2292                              (WCHAR*)pdn + pdn->wOutputOffset,
     2293                              pdm );
     2294    } else if(lppd->Flags & PD_RETURNIC) {
     2295        lppd->hDC = CreateICW((WCHAR*)pdn + pdn->wDriverOffset,
     2296                              (WCHAR*)pdn + pdn->wDeviceOffset,
     2297                              (WCHAR*)pdn + pdn->wOutputOffset,
     2298                              pdm );
     2299    }
     2300    GlobalUnlock(lppd->hDevNames);
     2301    GlobalUnlock(lppd->hDevMode);
     2302    return lppd->hDC ? TRUE : FALSE;
     2303}
     2304
    13932305#ifndef __WIN32OS2__
    13942306static BOOL PRINTDLG_CreateDC16(LPPRINTDLG16 lppd)
     
    14312343 *  * The Paper Orientation Icons are not implemented yet.
    14322344 *  * The Properties Button(s) should call DocumentPropertiesA().
    1433  *  * Settings are not yet taken from a provided DevMode or 
     2345 *  * Settings are not yet taken from a provided DevMode or
    14342346 *    default printer settings.
    14352347 */
     2348
    14362349BOOL WINAPI PrintDlgA(
    14372350                      LPPRINTDLGA lppd /* [in/out] ptr to PRINTDLG32 struct */
     
    14412354    LPVOID   ptr;
    14422355    HINSTANCE hInst = GetWindowLongA( lppd->hwndOwner, GWL_HINSTANCE );
    1443 
    1444 #ifdef __WIN32OS2__
    1445     dprintf(("PrintDlgA %x", lppd));
    1446 #endif
    14472356
    14482357    if(TRACE_ON(commdlg)) {
     
    14642373        WARN("structure size failure !!!\n");
    14652374        COMDLG32_SetCommDlgExtendedError(CDERR_STRUCTSIZE);
    1466         return FALSE; 
     2375        return FALSE;
    14672376    }
    14682377
     
    14752384        if(lppd->hDevMode || lppd->hDevNames) {
    14762385            WARN("hDevMode or hDevNames non-zero for PD_RETURNDEFAULT\n");
    1477             COMDLG32_SetCommDlgExtendedError(PDERR_RETDEFFAILURE); 
     2386            COMDLG32_SetCommDlgExtendedError(PDERR_RETDEFFAILURE);
    14782387            return FALSE;
    14792388        }
    14802389        if(!PRINTDLG_OpenDefaultPrinter(&hprn)) {
    14812390            WARN("Can't find default printer\n");
    1482             COMDLG32_SetCommDlgExtendedError(PDERR_NODEFAULTPRN); 
     2391            COMDLG32_SetCommDlgExtendedError(PDERR_NODEFAULTPRN);
    14832392            return FALSE;
    14842393        }
     
    14922401        if (!GetPrinterDriverA(hprn, NULL, 3, (LPBYTE)dbuf, needed, &needed)) {
    14932402            ERR("GetPrinterDriverA failed, le %ld, fix your config for printer %s!\n",GetLastError(),pbuf->pPrinterName);
    1494             COMDLG32_SetCommDlgExtendedError(PDERR_RETDEFFAILURE); 
     2403            COMDLG32_SetCommDlgExtendedError(PDERR_RETDEFFAILURE);
    14952404            return FALSE;
    14962405        }
     
    15142423        PRINT_PTRA *PrintStructures;
    15152424
    1516     /* load Dialog resources, 
    1517      * depending on Flags indicates Print32 or Print32_setup dialog 
     2425    /* load Dialog resources,
     2426     * depending on Flags indicates Print32 or Print32_setup dialog
    15182427     */
    1519         hDlgTmpl = PRINTDLG_GetDlgTemplate(lppd);
     2428        hDlgTmpl = PRINTDLG_GetDlgTemplateA(lppd);
    15202429        if (!hDlgTmpl) {
    15212430            COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
     
    15852494    }
    15862495    if(bRet && (lppd->Flags & PD_RETURNDC || lppd->Flags & PD_RETURNIC))
    1587         bRet = PRINTDLG_CreateDC(lppd);
    1588 
    1589     TRACE("exit! (%d)\n", bRet);       
    1590     return bRet;   
    1591 }
    1592 
    1593 #ifndef __WIN32OS2__
     2496        bRet = PRINTDLG_CreateDCA(lppd);
     2497
     2498    TRACE("exit! (%d)\n", bRet);
     2499    return bRet;
     2500}
     2501
    15942502/***********************************************************************
    1595  *           PrintDlg   (COMMDLG.20)
    1596  *
    1597  *  Displays the the PRINT dialog box, which enables the user to specify
    1598  *  specific properties of the print job.
    1599  *
    1600  * RETURNS
    1601  *  nonzero if the user pressed the OK button
    1602  *  zero    if the user cancelled the window or an error occurred
    1603  *
    1604  * BUGS
    1605  *  * calls up to the 32-bit versions of the Dialogs, which look different
    1606  *  * Customizing is *not* implemented.
     2503 *           PrintDlgW   (COMDLG32.@)
    16072504 */
    1608 
    1609 BOOL16 WINAPI PrintDlg16(
    1610               LPPRINTDLG16 lppd /* [in/out] ptr to PRINTDLG struct */
    1611 ) {
     2505BOOL WINAPI PrintDlgW(
     2506                      LPPRINTDLGW lppd /* [in/out] ptr to PRINTDLG32 struct */
     2507                      )
     2508{
    16122509    BOOL      bRet = FALSE;
    16132510    LPVOID   ptr;
     
    16292526    }
    16302527
     2528    if(lppd->lStructSize != sizeof(PRINTDLGW)) {
     2529        WARN("structure size failure !!!\n");
     2530        COMDLG32_SetCommDlgExtendedError(CDERR_STRUCTSIZE);
     2531        return FALSE;
     2532    }
     2533
     2534    if(lppd->Flags & PD_RETURNDEFAULT) {
     2535        PRINTER_INFO_2W *pbuf;
     2536        DRIVER_INFO_3W  *dbuf;
     2537        HANDLE hprn;
     2538        DWORD needed;
     2539
     2540        if(lppd->hDevMode || lppd->hDevNames) {
     2541            WARN("hDevMode or hDevNames non-zero for PD_RETURNDEFAULT\n");
     2542            COMDLG32_SetCommDlgExtendedError(PDERR_RETDEFFAILURE);
     2543            return FALSE;
     2544        }
     2545        if(!PRINTDLG_OpenDefaultPrinter(&hprn)) {
     2546            WARN("Can't find default printer\n");
     2547            COMDLG32_SetCommDlgExtendedError(PDERR_NODEFAULTPRN);
     2548            return FALSE;
     2549        }
     2550
     2551        GetPrinterW(hprn, 2, NULL, 0, &needed);
     2552        pbuf = HeapAlloc(GetProcessHeap(), 0, sizeof(WCHAR)*needed);
     2553        GetPrinterW(hprn, 2, (LPBYTE)pbuf, needed, &needed);
     2554
     2555        GetPrinterDriverW(hprn, NULL, 3, NULL, 0, &needed);
     2556        dbuf = HeapAlloc(GetProcessHeap(),0,sizeof(WCHAR)*needed);
     2557        if (!GetPrinterDriverW(hprn, NULL, 3, (LPBYTE)dbuf, needed, &needed)) {
     2558            ERR("GetPrinterDriverA failed, le %ld, fix your config for printer %s!\n",GetLastError(),debugstr_w(pbuf->pPrinterName));
     2559            COMDLG32_SetCommDlgExtendedError(PDERR_RETDEFFAILURE);
     2560            return FALSE;
     2561        }
     2562        ClosePrinter(hprn);
     2563
     2564        PRINTDLG_CreateDevNamesW(&(lppd->hDevNames),
     2565                                  dbuf->pDriverPath,
     2566                                  pbuf->pPrinterName,
     2567                                  pbuf->pPortName);
     2568        lppd->hDevMode = GlobalAlloc(GMEM_MOVEABLE, pbuf->pDevMode->dmSize +
     2569                                     pbuf->pDevMode->dmDriverExtra);
     2570        ptr = GlobalLock(lppd->hDevMode);
     2571        memcpy(ptr, pbuf->pDevMode, pbuf->pDevMode->dmSize +
     2572               pbuf->pDevMode->dmDriverExtra);
     2573        GlobalUnlock(lppd->hDevMode);
     2574        HeapFree(GetProcessHeap(), 0, pbuf);
     2575        HeapFree(GetProcessHeap(), 0, dbuf);
     2576        bRet = TRUE;
     2577    } else {
     2578        HGLOBAL hDlgTmpl;
     2579        PRINT_PTRW *PrintStructures;
     2580
     2581    /* load Dialog resources,
     2582     * depending on Flags indicates Print32 or Print32_setup dialog
     2583     */
     2584        hDlgTmpl = PRINTDLG_GetDlgTemplateW(lppd);
     2585        if (!hDlgTmpl) {
     2586            COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
     2587            return FALSE;
     2588        }
     2589        ptr = LockResource( hDlgTmpl );
     2590        if (!ptr) {
     2591            COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
     2592            return FALSE;
     2593        }
     2594
     2595        PrintStructures = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
     2596                                    sizeof(PRINT_PTRW));
     2597        PrintStructures->dlg.lpPrintDlg = lppd;
     2598
     2599        /* and create & process the dialog .
     2600         * -1 is failure, 0 is broken hwnd, everything else is ok.
     2601         */
     2602        bRet = (0<DialogBoxIndirectParamW(hInst, ptr, lppd->hwndOwner,
     2603                                           PrintDlgProcW,
     2604                                           (LPARAM)PrintStructures));
     2605
     2606        if(bRet) {
     2607            DEVMODEW *lpdm = PrintStructures->lpDevMode, *lpdmReturn;
     2608            PRINTER_INFO_2W *pi = PrintStructures->lpPrinterInfo;
     2609            DRIVER_INFO_3W *di = PrintStructures->lpDriverInfo;
     2610
     2611            if (lppd->hDevMode == 0) {
     2612                TRACE(" No hDevMode yet... Need to create my own\n");
     2613                lppd->hDevMode = GlobalAlloc(GMEM_MOVEABLE,
     2614                                        lpdm->dmSize + lpdm->dmDriverExtra);
     2615            } else {
     2616                WORD locks;
     2617                if((locks = (GlobalFlags(lppd->hDevMode) & GMEM_LOCKCOUNT))) {
     2618                    WARN("hDevMode has %d locks on it. Unlocking it now\n", locks);
     2619                    while(locks--) {
     2620                        GlobalUnlock(lppd->hDevMode);
     2621                        TRACE("Now got %d locks\n", locks);
     2622                    }
     2623                }
     2624                lppd->hDevMode = GlobalReAlloc(lppd->hDevMode,
     2625                                               lpdm->dmSize + lpdm->dmDriverExtra,
     2626                                               GMEM_MOVEABLE);
     2627            }
     2628            lpdmReturn = GlobalLock(lppd->hDevMode);
     2629            memcpy(lpdmReturn, lpdm, lpdm->dmSize + lpdm->dmDriverExtra);
     2630
     2631            if (lppd->hDevNames != 0) {
     2632                WORD locks;
     2633                if((locks = (GlobalFlags(lppd->hDevNames) & GMEM_LOCKCOUNT))) {
     2634                    WARN("hDevNames has %d locks on it. Unlocking it now\n", locks);
     2635                    while(locks--)
     2636                        GlobalUnlock(lppd->hDevNames);
     2637                }
     2638            }
     2639            PRINTDLG_CreateDevNamesW(&(lppd->hDevNames),
     2640                    di->pDriverPath,
     2641                    pi->pPrinterName,
     2642                    pi->pPortName
     2643            );
     2644            GlobalUnlock(lppd->hDevMode);
     2645        }
     2646        HeapFree(GetProcessHeap(), 0, PrintStructures->lpDevMode);
     2647        HeapFree(GetProcessHeap(), 0, PrintStructures->lpPrinterInfo);
     2648        HeapFree(GetProcessHeap(), 0, PrintStructures->lpDriverInfo);
     2649        HeapFree(GetProcessHeap(), 0, PrintStructures);
     2650    }
     2651    if(bRet && (lppd->Flags & PD_RETURNDC || lppd->Flags & PD_RETURNIC))
     2652        bRet = PRINTDLG_CreateDCW(lppd);
     2653
     2654    TRACE("exit! (%d)\n", bRet);
     2655    return bRet;
     2656}
     2657
     2658#ifndef __WIN32OS2__
     2659/***********************************************************************
     2660 *           PrintDlg   (COMMDLG.20)
     2661 *
     2662 *  Displays the the PRINT dialog box, which enables the user to specify
     2663 *  specific properties of the print job.
     2664 *
     2665 * RETURNS
     2666 *  nonzero if the user pressed the OK button
     2667 *  zero    if the user cancelled the window or an error occurred
     2668 *
     2669 * BUGS
     2670 *  * calls up to the 32-bit versions of the Dialogs, which look different
     2671 *  * Customizing is *not* implemented.
     2672 */
     2673
     2674BOOL16 WINAPI PrintDlg16(
     2675              LPPRINTDLG16 lppd /* [in/out] ptr to PRINTDLG struct */
     2676) {
     2677    BOOL      bRet = FALSE;
     2678    LPVOID   ptr;
     2679    HINSTANCE hInst = GetWindowLongA( HWND_32(lppd->hwndOwner), GWL_HINSTANCE );
     2680
     2681    if(TRACE_ON(commdlg)) {
     2682        char flagstr[1000] = "";
     2683        struct pd_flags *pflag = pd_flags;
     2684        for( ; pflag->name; pflag++) {
     2685            if(lppd->Flags & pflag->flag)
     2686                strcat(flagstr, pflag->name);
     2687        }
     2688        TRACE("(%p): hwndOwner = %08x, hDevMode = %08x, hDevNames = %08x\n"
     2689              "pp. %d-%d, min p %d, max p %d, copies %d, hinst %08x\n"
     2690              "flags %08lx (%s)\n",
     2691              lppd, lppd->hwndOwner, lppd->hDevMode, lppd->hDevNames,
     2692              lppd->nFromPage, lppd->nToPage, lppd->nMinPage, lppd->nMaxPage,
     2693              lppd->nCopies, lppd->hInstance, lppd->Flags, flagstr);
     2694    }
     2695
    16312696    if(lppd->lStructSize != sizeof(PRINTDLG16)) {
    16322697        ERR("structure size (%ld/%d)\n",lppd->lStructSize,sizeof(PRINTDLG16));
     
    16432708        if(lppd->hDevMode || lppd->hDevNames) {
    16442709            WARN("hDevMode or hDevNames non-zero for PD_RETURNDEFAULT\n");
    1645             COMDLG32_SetCommDlgExtendedError(PDERR_RETDEFFAILURE); 
     2710            COMDLG32_SetCommDlgExtendedError(PDERR_RETDEFFAILURE);
    16462711            return FALSE;
    16472712        }
    16482713        if(!PRINTDLG_OpenDefaultPrinter(&hprn)) {
    16492714            WARN("Can't find default printer\n");
    1650             COMDLG32_SetCommDlgExtendedError(PDERR_NODEFAULTPRN); 
     2715            COMDLG32_SetCommDlgExtendedError(PDERR_NODEFAULTPRN);
    16512716            return FALSE;
    16522717        }
     
    16602725            ERR("GetPrinterDriverA failed for %s, le %ld, fix your config!\n",
    16612726                    pbuf->pPrinterName,GetLastError());
    1662             COMDLG32_SetCommDlgExtendedError(PDERR_RETDEFFAILURE); 
     2727            COMDLG32_SetCommDlgExtendedError(PDERR_RETDEFFAILURE);
    16632728            return FALSE;
    16642729        }
     
    16812746        PRINT_PTRA *PrintStructures;
    16822747
    1683     /* load Dialog resources, 
    1684      * depending on Flags indicates Print32 or Print32_setup dialog 
     2748    /* load Dialog resources,
     2749     * depending on Flags indicates Print32 or Print32_setup dialog
    16852750     */
    16862751        hDlgTmpl = PRINTDLG_GetDlgTemplate16(lppd);
     
    16952760#define CVAL(x) PrintStructures->dlg.lpPrintDlg->x = lppd->x;
    16962761#define MVAL(x) PrintStructures->dlg.lpPrintDlg->x = MapSL(lppd->x);
    1697         CVAL(Flags);CVAL(hwndOwner);CVAL(hDC);
     2762        CVAL(Flags);
     2763        PrintStructures->dlg.lpPrintDlg->hwndOwner = HWND_32(lppd->hwndOwner);
     2764        CVAL(hDC);
    16982765        CVAL(nFromPage);CVAL(nToPage);CVAL(nMinPage);CVAL(nMaxPage);
    16992766        CVAL(nCopies);CVAL(hInstance);CVAL(lCustData);
     
    17652832        bRet = PRINTDLG_CreateDC16(lppd);
    17662833
    1767     TRACE("exit! (%d)\n", bRet);       
    1768     return bRet;   
     2834    TRACE("exit! (%d)\n", bRet);
     2835    return bRet;
    17692836}
    17702837#endif
    1771 
    1772 
    1773 /***********************************************************************
    1774  *           PrintDlgW   (COMDLG32.@)
    1775  */
    1776 BOOL WINAPI PrintDlgW( LPPRINTDLGW printdlg )
    1777 {
    1778 #ifdef __WIN32OS2__
    1779     dprintf(("PrintDlgW %x NOT IMPLEMENTED", printdlg));
    1780 #endif
    1781     FIXME("A really empty stub\n" );
    1782     return FALSE;
    1783 }
    17842838
    17852839/***********************************************************************
     
    17992853typedef struct {
    18002854    LPPAGESETUPDLGA     dlga;
    1801 
    18022855    PRINTDLGA           pdlg;
    1803 } PageSetupData;
    1804 
    1805 static HGLOBAL PRINTDLG_GetPGSTemplate(PAGESETUPDLGA *lppd)
    1806 {
    1807     HGLOBAL hDlgTmpl, hResInfo;
     2856} PageSetupDataA;
     2857
     2858typedef struct {
     2859    LPPAGESETUPDLGW     dlga;
     2860    PRINTDLGW           pdlg;
     2861} PageSetupDataW;
     2862
     2863static HGLOBAL PRINTDLG_GetPGSTemplateA(PAGESETUPDLGA *lppd)
     2864{
     2865    HRSRC hResInfo;
     2866    HGLOBAL hDlgTmpl;
    18082867
    18092868    if(lppd->Flags & PSD_ENABLEPAGESETUPTEMPLATEHANDLE) {
    18102869        hDlgTmpl = lppd->hPageSetupTemplate;
    1811     } else if(lppd->Flags & PSD_ENABLEPAGESETUPTEMPLATE) {     
     2870    } else if(lppd->Flags & PSD_ENABLEPAGESETUPTEMPLATE) {
    18122871        hResInfo = FindResourceA(lppd->hInstance,
    18132872                                 lppd->lpPageSetupTemplateName, RT_DIALOGA);
     
    18152874    } else {
    18162875        hResInfo = FindResourceA(COMDLG32_hInstance,(LPCSTR)PAGESETUPDLGORD,RT_DIALOGA);
     2876        hDlgTmpl = LoadResource(COMDLG32_hInstance,hResInfo);
     2877    }
     2878    return hDlgTmpl;
     2879}
     2880
     2881static HGLOBAL PRINTDLG_GetPGSTemplateW(PAGESETUPDLGW *lppd)
     2882{
     2883    HRSRC hResInfo;
     2884    HGLOBAL hDlgTmpl;
     2885
     2886    if(lppd->Flags & PSD_ENABLEPAGESETUPTEMPLATEHANDLE) {
     2887        hDlgTmpl = lppd->hPageSetupTemplate;
     2888    } else if(lppd->Flags & PSD_ENABLEPAGESETUPTEMPLATE) {
     2889        hResInfo = FindResourceW(lppd->hInstance,
     2890                                 lppd->lpPageSetupTemplateName, RT_DIALOGW);
     2891        hDlgTmpl = LoadResource(lppd->hInstance, hResInfo);
     2892    } else {
     2893        hResInfo = FindResourceW(COMDLG32_hInstance,(LPCWSTR)PAGESETUPDLGORD,RT_DIALOGW);
    18172894        hDlgTmpl = LoadResource(COMDLG32_hInstance,hResInfo);
    18182895    }
     
    18282905     */
    18292906    dlga->Flags |= PSD_INHUNDREDTHSOFMILLIMETERS;
    1830     FIXME("returning %ld/100 mm \n",size);
    18312907    return 10*size;
    18322908}
     
    18472923
    18482924static void
    1849 _c_size2str(PageSetupData *pda,DWORD size,LPSTR strout) {
     2925_c_size2strA(PageSetupDataA *pda,DWORD size,LPSTR strout) {
    18502926    strcpy(strout,"<undef>");
    18512927    if (pda->dlga->Flags & PSD_INHUNDREDTHSOFMILLIMETERS) {
     
    18612937    return;
    18622938}
     2939static void
     2940_c_size2strW(PageSetupDataW *pda,DWORD size,LPSTR strout) {
     2941    strcpy(strout,"<undef>");
     2942    if (pda->dlga->Flags & PSD_INHUNDREDTHSOFMILLIMETERS) {
     2943        sprintf(strout,"%.2fmm",(size*1.0)/100.0);
     2944        return;
     2945    }
     2946    if (pda->dlga->Flags & PSD_INTHOUSANDTHSOFINCHES) {
     2947        sprintf(strout,"%.2fin",(size*1.0)/1000.0);
     2948        return;
     2949    }
     2950    pda->dlga->Flags |= PSD_INHUNDREDTHSOFMILLIMETERS;
     2951    sprintf(strout,"%.2fmm",(size*1.0)/100.0);
     2952    return;
     2953}
    18632954
    18642955static DWORD
    1865 _c_str2size(PageSetupData *pda,LPCSTR strin) {
     2956_c_str2size(PAGESETUPDLGA *dlga,LPCSTR strin) {
    18662957    float       val;
    18672958    char        rest[200];
     
    18722963
    18732964    if (!strcmp(rest,"in") || !strcmp(rest,"inch")) {
    1874         if (pda->dlga->Flags & PSD_INTHOUSANDTHSOFINCHES)
     2965        if (dlga->Flags & PSD_INTHOUSANDTHSOFINCHES)
    18752966            return 1000*val;
    18762967        else
     
    18812972
    18822973    if (!strcmp(rest,"mm")) {
    1883         if (pda->dlga->Flags & PSD_INHUNDREDTHSOFMILLIMETERS)
     2974        if (dlga->Flags & PSD_INHUNDREDTHSOFMILLIMETERS)
    18842975            return 100*val;
    18852976        else
     
    18882979    if (rest[0]=='\0') {
    18892980        /* use application supplied default */
    1890         if (pda->dlga->Flags & PSD_INHUNDREDTHSOFMILLIMETERS) {
     2981        if (dlga->Flags & PSD_INHUNDREDTHSOFMILLIMETERS) {
    18912982            /* 100*mm */
    18922983            return 100.0*val;
    18932984        }
    1894         if (pda->dlga->Flags & PSD_INTHOUSANDTHSOFINCHES) {
     2985        if (dlga->Flags & PSD_INTHOUSANDTHSOFINCHES) {
    18952986            /* 1000*inch */
    18962987            return 1000.0*val;
     
    19072998 */
    19082999static BOOL
    1909 PRINTDLG_PS_UpdateDlgStruct(HWND hDlg, PageSetupData *pda) {
     3000PRINTDLG_PS_UpdateDlgStructA(HWND hDlg, PageSetupDataA *pda) {
    19103001    DEVNAMES    *dn;
    19113002    DEVMODEA    *dm;
     
    19133004    char        papername[64];
    19143005    char        buf[200];
    1915    
     3006
    19163007    dn = GlobalLock(pda->pdlg.hDevNames);
    19173008    dm = GlobalLock(pda->pdlg.hDevMode);
    19183009    devname     = ((char*)dn)+dn->wDeviceOffset;
    19193010    portname    = ((char*)dn)+dn->wOutputOffset;
    1920     PRINTDLG_SetUpPaperComboBox(hDlg,cmb2,devname,portname,dm);
    1921     PRINTDLG_SetUpPaperComboBox(hDlg,cmb3,devname,portname,dm);
     3011    PRINTDLG_SetUpPaperComboBoxA(hDlg,cmb2,devname,portname,dm);
     3012    PRINTDLG_SetUpPaperComboBoxA(hDlg,cmb3,devname,portname,dm);
    19223013
    19233014    if (GetDlgItemTextA(hDlg,cmb2,papername,sizeof(papername))>0) {
    1924         PRINTDLG_PaperSize(&(pda->pdlg),papername,&(pda->dlga->ptPaperSize));
     3015        PRINTDLG_PaperSizeA(&(pda->pdlg),papername,&(pda->dlga->ptPaperSize));
    19253016        pda->dlga->ptPaperSize.x = _c_10mm2size(pda->dlga,pda->dlga->ptPaperSize.x);
    19263017        pda->dlga->ptPaperSize.y = _c_10mm2size(pda->dlga,pda->dlga->ptPaperSize.y);
    19273018    } else
    19283019        FIXME("could not get dialog text for papersize cmbbox?\n");
    1929 #define GETVAL(id,val) if (GetDlgItemTextA(hDlg,id,buf,sizeof(buf))>0) { val = _c_str2size(pda,buf); } else { FIXME("could not get dlgitemtexta for %x\n",id); }
     3020#define GETVAL(id,val) if (GetDlgItemTextA(hDlg,id,buf,sizeof(buf))>0) { val = _c_str2size(pda->dlga,buf); } else { FIXME("could not get dlgitemtexta for %x\n",id); }
    19303021    GETVAL(edt4,pda->dlga->rtMargin.left);
    19313022    GETVAL(edt5,pda->dlga->rtMargin.top);
     
    19463037}
    19473038
     3039static BOOL
     3040PRINTDLG_PS_UpdateDlgStructW(HWND hDlg, PageSetupDataW *pda) {
     3041    DEVNAMES    *dn;
     3042    DEVMODEW    *dm;
     3043    LPWSTR      devname,portname;
     3044    WCHAR       papername[64];
     3045
     3046    char        buf[200];
     3047
     3048    dn = GlobalLock(pda->pdlg.hDevNames);
     3049    dm = GlobalLock(pda->pdlg.hDevMode);
     3050    devname     = ((WCHAR*)dn)+dn->wDeviceOffset;
     3051    portname    = ((WCHAR*)dn)+dn->wOutputOffset;
     3052    PRINTDLG_SetUpPaperComboBoxW(hDlg,cmb2,devname,portname,dm);
     3053    PRINTDLG_SetUpPaperComboBoxW(hDlg,cmb3,devname,portname,dm);
     3054
     3055    if (GetDlgItemTextW(hDlg,cmb2,papername,sizeof(papername))>0) {
     3056        PRINTDLG_PaperSizeW(&(pda->pdlg),papername,&(pda->dlga->ptPaperSize));
     3057        pda->dlga->ptPaperSize.x = _c_10mm2size((LPPAGESETUPDLGA)pda->dlga,pda->dlga->ptPaperSize.x);
     3058        pda->dlga->ptPaperSize.y = _c_10mm2size((LPPAGESETUPDLGA)pda->dlga,pda->dlga->ptPaperSize.y);
     3059    } else
     3060        FIXME("could not get dialog text for papersize cmbbox?\n");
     3061#define GETVAL(id,val) if (GetDlgItemTextA(hDlg,id,buf,sizeof(buf))>0) { val = _c_str2size((LPPAGESETUPDLGA)pda->dlga,buf); } else { FIXME("could not get dlgitemtexta for %x\n",id); }
     3062    GETVAL(edt4,pda->dlga->rtMargin.left);
     3063    GETVAL(edt5,pda->dlga->rtMargin.top);
     3064    GETVAL(edt6,pda->dlga->rtMargin.right);
     3065    GETVAL(edt7,pda->dlga->rtMargin.bottom);
     3066#undef GETVAL
     3067
     3068    /* If we are in landscape, swap x and y of page size */
     3069    if (IsDlgButtonChecked(hDlg, rad2)) {
     3070        DWORD tmp;
     3071        tmp = pda->dlga->ptPaperSize.x;
     3072        pda->dlga->ptPaperSize.x = pda->dlga->ptPaperSize.y;
     3073        pda->dlga->ptPaperSize.y = tmp;
     3074    }
     3075    GlobalUnlock(pda->pdlg.hDevNames);
     3076    GlobalUnlock(pda->pdlg.hDevMode);
     3077    return TRUE;
     3078}
     3079
    19483080/*
    19493081 * This is called after returning from PrintDlg().
    19503082 */
    19513083static BOOL
    1952 PRINTDLG_PS_ChangePrinter(HWND hDlg, PageSetupData *pda) {
     3084PRINTDLG_PS_ChangePrinterA(HWND hDlg, PageSetupDataA *pda) {
    19533085    DEVNAMES    *dn;
    19543086    DEVMODEA    *dm;
    19553087    LPSTR       devname,portname;
    1956    
     3088
    19573089    dn = GlobalLock(pda->pdlg.hDevNames);
    19583090    dm = GlobalLock(pda->pdlg.hDevMode);
    19593091    devname     = ((char*)dn)+dn->wDeviceOffset;
    19603092    portname    = ((char*)dn)+dn->wOutputOffset;
    1961     PRINTDLG_SetUpPaperComboBox(hDlg,cmb2,devname,portname,dm);
    1962     PRINTDLG_SetUpPaperComboBox(hDlg,cmb3,devname,portname,dm);
     3093    PRINTDLG_SetUpPaperComboBoxA(hDlg,cmb2,devname,portname,dm);
     3094    PRINTDLG_SetUpPaperComboBoxA(hDlg,cmb3,devname,portname,dm);
    19633095    GlobalUnlock(pda->pdlg.hDevNames);
    19643096    GlobalUnlock(pda->pdlg.hDevMode);
     
    19673099
    19683100static BOOL
    1969 PRINTDLG_PS_WMCommand(
    1970     HWND hDlg, WPARAM wParam, LPARAM lParam, PageSetupData *pda
     3101PRINTDLG_PS_ChangePrinterW(HWND hDlg, PageSetupDataW *pda) {
     3102    DEVNAMES    *dn;
     3103    DEVMODEW    *dm;
     3104    LPWSTR      devname,portname;
     3105
     3106    dn = GlobalLock(pda->pdlg.hDevNames);
     3107    dm = GlobalLock(pda->pdlg.hDevMode);
     3108    devname     = ((WCHAR*)dn)+dn->wDeviceOffset;
     3109    portname    = ((WCHAR*)dn)+dn->wOutputOffset;
     3110    PRINTDLG_SetUpPaperComboBoxW(hDlg,cmb2,devname,portname,dm);
     3111    PRINTDLG_SetUpPaperComboBoxW(hDlg,cmb3,devname,portname,dm);
     3112    GlobalUnlock(pda->pdlg.hDevNames);
     3113    GlobalUnlock(pda->pdlg.hDevMode);
     3114    return TRUE;
     3115}
     3116
     3117static BOOL
     3118PRINTDLG_PS_WMCommandA(
     3119    HWND hDlg, WPARAM wParam, LPARAM lParam, PageSetupDataA *pda
    19713120) {
    19723121    switch (LOWORD(wParam))  {
    19733122    case IDOK:
    1974         if (!PRINTDLG_PS_UpdateDlgStruct(hDlg, pda))
     3123        if (!PRINTDLG_PS_UpdateDlgStructA(hDlg, pda))
    19753124            return(FALSE);
    19763125        EndDialog(hDlg, TRUE);
     
    19853134        pda->pdlg.hwndOwner     = hDlg;
    19863135        if (PrintDlgA(&(pda->pdlg)))
    1987             PRINTDLG_PS_ChangePrinter(hDlg,pda);
     3136            PRINTDLG_PS_ChangePrinterA(hDlg,pda);
    19883137        return TRUE;
    19893138    }
     
    19953144}
    19963145
     3146static BOOL
     3147PRINTDLG_PS_WMCommandW(
     3148    HWND hDlg, WPARAM wParam, LPARAM lParam, PageSetupDataW *pda
     3149) {
     3150    switch (LOWORD(wParam))  {
     3151    case IDOK:
     3152        if (!PRINTDLG_PS_UpdateDlgStructW(hDlg, pda))
     3153            return(FALSE);
     3154        EndDialog(hDlg, TRUE);
     3155        return TRUE ;
     3156
     3157    case IDCANCEL:
     3158        EndDialog(hDlg, FALSE);
     3159        return FALSE ;
     3160
     3161    case psh3: {
     3162        pda->pdlg.Flags         = 0;
     3163        pda->pdlg.hwndOwner     = hDlg;
     3164        if (PrintDlgW(&(pda->pdlg)))
     3165            PRINTDLG_PS_ChangePrinterW(hDlg,pda);
     3166        return TRUE;
     3167    }
     3168    }
     3169    FIXME("loword (lparam) %d, wparam 0x%x, lparam %08lx, STUB mostly.\n",
     3170            LOWORD(lParam),wParam,lParam
     3171    );
     3172    return FALSE;
     3173}
     3174
    19973175
    19983176static BOOL WINAPI
    19993177PageDlgProcA(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
    20003178{
    2001     PageSetupData       *pda;
     3179    PageSetupDataA      *pda;
    20023180    BOOL                res = FALSE;
    20033181
    20043182    if (uMsg==WM_INITDIALOG) {
    20053183        res = TRUE;
    2006         pda = (PageSetupData*)lParam;
     3184        pda = (PageSetupDataA*)lParam;
    20073185        SetPropA(hDlg,"__WINE_PAGESETUPDLGDATA",lParam);
    20083186        if (pda->dlga->Flags & PSD_ENABLEPAGESETUPHOOK) {
     
    20173195        }
    20183196        if (pda->dlga->Flags & PSD_DISABLEPRINTER)
    2019             EnableWindow(GetDlgItem(hDlg, psh3), FALSE);   
     3197            EnableWindow(GetDlgItem(hDlg, psh3), FALSE);
    20203198        if (pda->dlga->Flags & PSD_DISABLEMARGINS) {
    2021             EnableWindow(GetDlgItem(hDlg, edt4), FALSE);   
    2022             EnableWindow(GetDlgItem(hDlg, edt5), FALSE);   
    2023             EnableWindow(GetDlgItem(hDlg, edt6), FALSE);   
    2024             EnableWindow(GetDlgItem(hDlg, edt7), FALSE);   
     3199            EnableWindow(GetDlgItem(hDlg, edt4), FALSE);
     3200            EnableWindow(GetDlgItem(hDlg, edt5), FALSE);
     3201            EnableWindow(GetDlgItem(hDlg, edt6), FALSE);
     3202            EnableWindow(GetDlgItem(hDlg, edt7), FALSE);
    20253203        }
    20263204        /* width larger as height -> landscape */
     
    20363214        if (pda->dlga->Flags & PSD_MARGINS) {
    20373215            char str[100];
    2038             _c_size2str(pda,pda->dlga->rtMargin.left,str);
     3216            _c_size2strA(pda,pda->dlga->rtMargin.left,str);
    20393217            SetDlgItemTextA(hDlg,edt4,str);
    2040             _c_size2str(pda,pda->dlga->rtMargin.top,str);
     3218            _c_size2strA(pda,pda->dlga->rtMargin.top,str);
    20413219            SetDlgItemTextA(hDlg,edt5,str);
    2042             _c_size2str(pda,pda->dlga->rtMargin.right,str);
     3220            _c_size2strA(pda,pda->dlga->rtMargin.right,str);
    20433221            SetDlgItemTextA(hDlg,edt6,str);
    2044             _c_size2str(pda,pda->dlga->rtMargin.bottom,str);
     3222            _c_size2strA(pda,pda->dlga->rtMargin.bottom,str);
    20453223            SetDlgItemTextA(hDlg,edt7,str);
    20463224        } else {
     
    20483226            DWORD size = _c_inch2size(pda->dlga,1000);
    20493227            char        str[20];
    2050             _c_size2str(pda,size,str);
     3228            _c_size2strA(pda,size,str);
    20513229            SetDlgItemTextA(hDlg,edt4,str);
    20523230            SetDlgItemTextA(hDlg,edt5,str);
     
    20543232            SetDlgItemTextA(hDlg,edt7,str);
    20553233        }
    2056         PRINTDLG_PS_ChangePrinter(hDlg,pda);
     3234        PRINTDLG_PS_ChangePrinterA(hDlg,pda);
    20573235        if (pda->dlga->Flags & PSD_DISABLEPAPER) {
    20583236            EnableWindow(GetDlgItem(hDlg,cmb2),FALSE);
     
    20613239        return TRUE;
    20623240    } else {
    2063         pda = (PageSetupData*)GetPropA(hDlg,"__WINE_PAGESETUPDLGDATA");
     3241        pda = (PageSetupDataA*)GetPropA(hDlg,"__WINE_PAGESETUPDLGDATA");
    20643242        if (!pda) {
    20653243            WARN("__WINE_PAGESETUPDLGDATA prop not set?\n");
     
    20733251    switch (uMsg) {
    20743252    case WM_COMMAND:
    2075         return PRINTDLG_PS_WMCommand(hDlg, wParam, lParam, pda);
     3253        return PRINTDLG_PS_WMCommandA(hDlg, wParam, lParam, pda);
     3254    }
     3255    return FALSE;
     3256}
     3257
     3258static BOOL WINAPI
     3259PageDlgProcW(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
     3260{
     3261    PageSetupDataW      *pda;
     3262    BOOL                res = FALSE;
     3263
     3264    if (uMsg==WM_INITDIALOG) {
     3265        res = TRUE;
     3266        pda = (PageSetupDataW*)lParam;
     3267        SetPropA(hDlg,"__WINE_PAGESETUPDLGDATA",lParam);
     3268        if (pda->dlga->Flags & PSD_ENABLEPAGESETUPHOOK) {
     3269            res = pda->dlga->lpfnPageSetupHook(hDlg,uMsg,wParam,lParam);
     3270            if (!res) {
     3271                FIXME("Setup page hook failed?\n");
     3272                res = TRUE;
     3273            }
     3274        }
     3275        if (pda->dlga->Flags & PSD_ENABLEPAGEPAINTHOOK) {
     3276            FIXME("PagePaintHook not yet implemented!\n");
     3277        }
     3278        if (pda->dlga->Flags & PSD_DISABLEPRINTER)
     3279            EnableWindow(GetDlgItem(hDlg, psh3), FALSE);
     3280        if (pda->dlga->Flags & PSD_DISABLEMARGINS) {
     3281            EnableWindow(GetDlgItem(hDlg, edt4), FALSE);
     3282            EnableWindow(GetDlgItem(hDlg, edt5), FALSE);
     3283            EnableWindow(GetDlgItem(hDlg, edt6), FALSE);
     3284            EnableWindow(GetDlgItem(hDlg, edt7), FALSE);
     3285        }
     3286        /* width larger as height -> landscape */
     3287        if (pda->dlga->ptPaperSize.x > pda->dlga->ptPaperSize.y)
     3288            CheckRadioButton(hDlg, rad1, rad2, rad2);
     3289        else /* this is default if papersize is not set */
     3290            CheckRadioButton(hDlg, rad1, rad2, rad1);
     3291        if (pda->dlga->Flags & PSD_DISABLEORIENTATION) {
     3292            EnableWindow(GetDlgItem(hDlg,rad1),FALSE);
     3293            EnableWindow(GetDlgItem(hDlg,rad2),FALSE);
     3294        }
     3295        /* We fill them out enabled or not */
     3296        if (pda->dlga->Flags & PSD_MARGINS) {
     3297            char str[100];
     3298            _c_size2strW(pda,pda->dlga->rtMargin.left,str);
     3299            SetDlgItemTextA(hDlg,edt4,str);
     3300            _c_size2strW(pda,pda->dlga->rtMargin.top,str);
     3301            SetDlgItemTextA(hDlg,edt5,str);
     3302            _c_size2strW(pda,pda->dlga->rtMargin.right,str);
     3303            SetDlgItemTextA(hDlg,edt6,str);
     3304            _c_size2strW(pda,pda->dlga->rtMargin.bottom,str);
     3305            SetDlgItemTextA(hDlg,edt7,str);
     3306        } else {
     3307            /* default is 1 inch */
     3308            DWORD size = _c_inch2size((LPPAGESETUPDLGA)pda->dlga,1000);
     3309            char        str[20];
     3310            _c_size2strW(pda,size,str);
     3311            SetDlgItemTextA(hDlg,edt4,str);
     3312            SetDlgItemTextA(hDlg,edt5,str);
     3313            SetDlgItemTextA(hDlg,edt6,str);
     3314            SetDlgItemTextA(hDlg,edt7,str);
     3315        }
     3316        PRINTDLG_PS_ChangePrinterW(hDlg,pda);
     3317        if (pda->dlga->Flags & PSD_DISABLEPAPER) {
     3318            EnableWindow(GetDlgItem(hDlg,cmb2),FALSE);
     3319            EnableWindow(GetDlgItem(hDlg,cmb3),FALSE);
     3320        }
     3321        return TRUE;
     3322    } else {
     3323        pda = (PageSetupDataW*)GetPropA(hDlg,"__WINE_PAGESETUPDLGDATA");
     3324        if (!pda) {
     3325            WARN("__WINE_PAGESETUPDLGDATA prop not set?\n");
     3326            return FALSE;
     3327        }
     3328        if (pda->dlga->Flags & PSD_ENABLEPAGESETUPHOOK) {
     3329            res = pda->dlga->lpfnPageSetupHook(hDlg,uMsg,wParam,lParam);
     3330            if (res) return res;
     3331        }
     3332    }
     3333    switch (uMsg) {
     3334    case WM_COMMAND:
     3335        return PRINTDLG_PS_WMCommandW(hDlg, wParam, lParam, pda);
    20763336    }
    20773337    return FALSE;
     
    20853345    LPVOID              ptr;
    20863346    BOOL                bRet;
    2087     PageSetupData       *pda;
     3347    PageSetupDataA      *pda;
    20883348    PRINTDLGA           pdlg;
    2089 
    2090 #ifdef __WIN32OS2__
    2091     dprintf(("PageSetupDlgA %x", setupdlg));
    2092 #endif
    20933349
    20943350    if(TRACE_ON(commdlg)) {
     
    21043360              "hinst %08x, flags %08lx (%s)\n",
    21053361              setupdlg, setupdlg->hwndOwner, setupdlg->hDevMode,
    2106               setupdlg->hDevNames, 
     3362              setupdlg->hDevNames,
    21073363              setupdlg->hInstance, setupdlg->Flags, flagstr);
    21083364    }
     
    21203376        setupdlg->hDevNames     = pdlg.hDevNames;
    21213377        /* FIXME: Just return "A4" for now. */
    2122         PRINTDLG_PaperSize(&pdlg,"A4",&setupdlg->ptPaperSize);
     3378        PRINTDLG_PaperSizeA(&pdlg,"A4",&setupdlg->ptPaperSize);
    21233379        setupdlg->ptPaperSize.x=_c_10mm2size(setupdlg,setupdlg->ptPaperSize.x);
    21243380        setupdlg->ptPaperSize.y=_c_10mm2size(setupdlg,setupdlg->ptPaperSize.y);
    21253381        return TRUE;
    21263382    }
    2127     hDlgTmpl = PRINTDLG_GetPGSTemplate(setupdlg);
     3383    hDlgTmpl = PRINTDLG_GetPGSTemplateA(setupdlg);
    21283384    if (!hDlgTmpl) {
    21293385        COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
     
    21523408 */
    21533409BOOL WINAPI PageSetupDlgW(LPPAGESETUPDLGW setupdlg) {
    2154 #ifdef __WIN32OS2__
    2155     dprintf(("PageSetupDlgA %x NOT IMPLEMENTED", setupdlg));
    2156 #endif
    2157         FIXME("(%p), stub!\n",setupdlg);
     3410    HGLOBAL             hDlgTmpl;
     3411    LPVOID              ptr;
     3412    BOOL                bRet;
     3413    PageSetupDataW      *pdw;
     3414    PRINTDLGW           pdlg;
     3415
     3416    if(TRACE_ON(commdlg)) {
     3417        char flagstr[1000] = "";
     3418        struct pd_flags *pflag = psd_flags;
     3419        for( ; pflag->name; pflag++) {
     3420            if(setupdlg->Flags & pflag->flag) {
     3421                strcat(flagstr, pflag->name);
     3422                strcat(flagstr, "|");
     3423            }
     3424        }
     3425        TRACE("(%p): hwndOwner = %08x, hDevMode = %08x, hDevNames = %08x\n"
     3426              "hinst %08x, flags %08lx (%s)\n",
     3427              setupdlg, setupdlg->hwndOwner, setupdlg->hDevMode,
     3428              setupdlg->hDevNames,
     3429              setupdlg->hInstance, setupdlg->Flags, flagstr);
     3430    }
     3431
     3432    /* First get default printer data, we need it right after that. */
     3433    memset(&pdlg,0,sizeof(pdlg));
     3434    pdlg.lStructSize    = sizeof(pdlg);
     3435    pdlg.Flags          = PD_RETURNDEFAULT;
     3436    bRet = PrintDlgW(&pdlg);
     3437    if (!bRet) return FALSE;
     3438
     3439    /* short cut exit, just return default values */
     3440    if (setupdlg->Flags & PSD_RETURNDEFAULT) {
     3441        const WCHAR a4[] = {'A','4',0};
     3442        setupdlg->hDevMode      = pdlg.hDevMode;
     3443        setupdlg->hDevNames     = pdlg.hDevNames;
     3444        /* FIXME: Just return "A4" for now. */
     3445        PRINTDLG_PaperSizeW(&pdlg,a4,&setupdlg->ptPaperSize);
     3446        setupdlg->ptPaperSize.x=_c_10mm2size((LPPAGESETUPDLGA)setupdlg,setupdlg->ptPaperSize.x);
     3447        setupdlg->ptPaperSize.y=_c_10mm2size((LPPAGESETUPDLGA)setupdlg,setupdlg->ptPaperSize.y);
     3448        return TRUE;
     3449    }
     3450    hDlgTmpl = PRINTDLG_GetPGSTemplateW(setupdlg);
     3451    if (!hDlgTmpl) {
     3452        COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
    21583453        return FALSE;
     3454    }
     3455    ptr = LockResource( hDlgTmpl );
     3456    if (!ptr) {
     3457        COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
     3458        return FALSE;
     3459    }
     3460    pdw = HeapAlloc(GetProcessHeap(),0,sizeof(*pdw));
     3461    pdw->dlga = setupdlg;
     3462    memcpy(&pdw->pdlg,&pdlg,sizeof(pdlg));
     3463
     3464    bRet = (0<DialogBoxIndirectParamW(
     3465                setupdlg->hInstance,
     3466                ptr,
     3467                setupdlg->hwndOwner,
     3468                PageDlgProcW,
     3469                (LPARAM)pdw)
     3470    );
     3471    return bRet;
    21593472}
    21603473
     
    21683481 *           PrintDlgProc   (COMMDLG.21)
    21693482 */
    2170 LRESULT WINAPI PrintDlgProc16(HWND16 hDlg, UINT16 uMsg, WPARAM16 wParam,
     3483LRESULT WINAPI PrintDlgProc16(HWND16 hDlg16, UINT16 uMsg, WPARAM16 wParam,
    21713484                            LPARAM lParam)
    21723485{
     3486    HWND hDlg = HWND_32(hDlg16);
    21733487    PRINT_PTRA* PrintStructures;
    21743488    LRESULT res=FALSE;
    21753489
    21763490    if (uMsg!=WM_INITDIALOG) {
    2177         PrintStructures = (PRINT_PTRA*) GetWindowLongA(hDlg, DWL_USER);   
     3491        PrintStructures = (PRINT_PTRA*)GetPropA(hDlg,"__WINE_PRINTDLGDATA");
    21783492        if (!PrintStructures)
    21793493            return FALSE;
    21803494    } else {
    21813495        PrintStructures = (PRINT_PTRA*) lParam;
    2182         SetWindowLongA(hDlg, DWL_USER, lParam);
     3496        SetPropA(hDlg,"__WINE_PRINTDLGDATA",lParam);
    21833497        res = PRINTDLG_WMInitDialog16(hDlg, wParam, PrintStructures);
    21843498
     
    21863500            res = CallWindowProc16(
    21873501                (WNDPROC16)PrintStructures->dlg.lpPrintDlg16->lpfnPrintHook,
    2188                 hDlg, uMsg, wParam, (LPARAM)PrintStructures->dlg.lpPrintDlg16
     3502                hDlg16, uMsg, wParam, (LPARAM)PrintStructures->dlg.lpPrintDlg16
    21893503            );
    21903504        }
    21913505        return res;
    21923506    }
    2193  
     3507
    21943508    if(PrintStructures->dlg.lpPrintDlg16->Flags & PD_ENABLEPRINTHOOK) {
    21953509        res = CallWindowProc16(
    21963510                (WNDPROC16)PrintStructures->dlg.lpPrintDlg16->lpfnPrintHook,
    2197                 hDlg,uMsg, wParam, lParam
     3511                hDlg16,uMsg, wParam, lParam
    21983512        );
    21993513        if(LOWORD(res)) return res;
     
    22053519          * with 32Ato16 mapper in winproc.c
    22063520          */
    2207         return PRINTDLG_WMCommand(
     3521        return PRINTDLG_WMCommandA(
    22083522                hDlg,
    22093523                MAKEWPARAM(wParam,HIWORD(lParam)),
     
    22183532
    22193533        return FALSE;
    2220     }   
     3534    }
    22213535    return res;
    22223536}
     
    22263540 *           PrintSetupDlgProc   (COMMDLG.22)
    22273541 */
    2228 LRESULT WINAPI PrintSetupDlgProc16(HWND16 hWnd, UINT16 wMsg, WPARAM16 wParam,
     3542LRESULT WINAPI PrintSetupDlgProc16(HWND16 hWnd16, UINT16 wMsg, WPARAM16 wParam,
    22293543                                   LPARAM lParam)
    22303544{
     3545  HWND hWnd = HWND_32(hWnd16);
    22313546  switch (wMsg)
    22323547    {
Note: See TracChangeset for help on using the changeset viewer.