propsheet.c 103 KB
Newer Older
1 2 3 4
/*
 * Property Sheets
 *
 * Copyright 1998 Francis Beaudet
5
 * Copyright 1999 Thuy Nguyen
6
 * Copyright 2004 Maxime Bellenge
Filip Navara's avatar
Filip Navara committed
7
 * Copyright 2004 Filip Navara
8
 *
9 10 11 12 13 14 15 16 17 18 19 20
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
21
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
22
 *
Filip Navara's avatar
Filip Navara committed
23 24 25 26 27 28 29
 * This code was audited for completeness against the documented features
 * of Comctl32.dll version 6.0 on Sep. 12, 2004, by Filip Navara.
 * 
 * Unless otherwise noted, we believe this code to be complete, as per
 * the specification mentioned above.
 * If you discover missing features, or bugs, please note them below.
 *
30
 * TODO:
31
 *   - Tab order
Filip Navara's avatar
Filip Navara committed
32 33 34 35 36 37 38
 *   - Wizard 97 header resizing
 *   - Enforcing of minimal wizard size
 *   - Messages:
 *     o PSM_INSERTPAGE
 *     o PSM_RECALCPAGESIZES
 *     o PSM_SETHEADERSUBTITLE
 *     o PSM_SETHEADERTITLE
39 40
 *     o WM_HELP
 *     o WM_CONTEXTMENU
Filip Navara's avatar
Filip Navara committed
41 42 43 44 45 46 47 48 49 50 51 52
 *   - Notifications:
 *     o PSN_GETOBJECT
 *     o PSN_QUERYINITIALFOCUS
 *     o PSN_TRANSLATEACCELERATOR
 *   - Styles:
 *     o PSH_RTLREADING
 *     o PSH_STRETCHWATERMARK
 *     o PSH_USEPAGELANG
 *     o PSH_USEPSTARTPAGE
 *   - Page styles:
 *     o PSP_USEFUSIONCONTEXT
 *     o PSP_USEREFPARENT
53 54
 */

55
#include <stdarg.h>
56
#include <string.h>
57

58 59
#define NONAMELESSUNION
#define NONAMELESSSTRUCT
60
#include "windef.h"
61
#include "winbase.h"
62 63 64
#include "wingdi.h"
#include "winuser.h"
#include "winnls.h"
65
#include "commctrl.h"
66
#include "prsht.h"
67
#include "comctl32.h"
68
#include "uxtheme.h"
69

70 71
#include "wine/debug.h"
#include "wine/unicode.h"
72 73 74 75

/******************************************************************************
 * Data structures
 */
76 77
#include "pshpack2.h"

78 79 80 81 82 83 84 85 86
typedef struct
{
  WORD dlgVer;
  WORD signature;
  DWORD helpID;
  DWORD exStyle;
  DWORD style;
} MyDLGTEMPLATEEX;

87 88 89 90 91 92 93
typedef struct
{
  DWORD helpid;
  DWORD exStyle;
  DWORD style;
  short x;
  short y;
94
  short cx;
95 96 97 98 99
  short cy;
  DWORD id;
} MyDLGITEMTEMPLATEEX;
#include "poppack.h"

100 101
typedef struct tagPropPageInfo
{
102
  HPROPSHEETPAGE hpage; /* to keep track of pages not passed to PropertySheet */
103 104 105 106 107
  HWND hwndPage;
  BOOL isDirty;
  LPCWSTR pszText;
  BOOL hasHelp;
  BOOL useCallback;
Alexandre Julliard's avatar
Alexandre Julliard committed
108
  BOOL hasIcon;
109 110 111 112
} PropPageInfo;

typedef struct tagPropSheetInfo
{
113
  HWND hwnd;
114
  PROPSHEETHEADERW ppshheader;
115
  BOOL unicode;
116
  LPWSTR strPropertiesFor;
117
  int nPages;
118 119 120 121
  int active_page;
  BOOL isModeless;
  BOOL hasHelp;
  BOOL hasApply;
122
  BOOL hasFinish;
123
  BOOL usePropPage;
124
  BOOL useCallback;
Alexandre Julliard's avatar
Alexandre Julliard committed
125
  BOOL activeValid;
126
  PropPageInfo* proppage;
127 128
  HFONT hFont;
  HFONT hFontBold;
129 130
  int width;
  int height;
131
  HIMAGELIST hImageList;
132
  BOOL ended;
133
  INT result;
134 135 136 137 138 139 140 141 142 143 144
} PropSheetInfo;

typedef struct
{
  int x;
  int y;
} PADDING_INFO;

/******************************************************************************
 * Defines and global variables
 */
145

146
static const WCHAR PropSheetInfoStr[] =
147
    {'P','r','o','p','e','r','t','y','S','h','e','e','t','I','n','f','o',0 };
148

149 150
#define PSP_INTERNAL_UNICODE 0x80000000

151
#define MAX_CAPTION_LENGTH 255
152
#define MAX_TABTEXT_LENGTH 255
Alexandre Julliard's avatar
Alexandre Julliard committed
153
#define MAX_BUTTONTEXT_LENGTH 64
154

155 156
#define INTRNL_ANY_WIZARD (PSH_WIZARD | PSH_WIZARD97_OLD | PSH_WIZARD97_NEW | PSH_WIZARD_LITE)

Filip Navara's avatar
Filip Navara committed
157 158 159 160
/* Wizard metrics specified in DLUs */
#define WIZARD_PADDING 7
#define WIZARD_HEADER_HEIGHT 36
                         	
161 162 163 164
/******************************************************************************
 * Prototypes
 */
static PADDING_INFO PROPSHEET_GetPaddingInfo(HWND hwndDlg);
165
static void PROPSHEET_SetTitleW(HWND hwndDlg, DWORD dwStyle, LPCWSTR lpszText);
166
static BOOL PROPSHEET_CanSetCurSel(HWND hwndDlg);
167 168
static BOOL PROPSHEET_SetCurSel(HWND hwndDlg,
                                int index,
169
                                int skipdir,
170
                                HPROPSHEETPAGE hpage);
171
static int PROPSHEET_GetPageIndex(HPROPSHEETPAGE hpage, const PropSheetInfo* psInfo);
172
static PADDING_INFO PROPSHEET_GetPaddingInfoWizard(HWND hwndDlg, const PropSheetInfo* psInfo);
173
static BOOL PROPSHEET_DoCommand(HWND hwnd, WORD wID);
174
static BOOL PROPSHEET_RemovePage(HWND hwndDlg, int index, HPROPSHEETPAGE hpage);
175

176
static INT_PTR CALLBACK
177 178
PROPSHEET_DialogProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);

179
WINE_DEFAULT_DEBUG_CHANNEL(propsheet);
180

181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205
#define add_flag(a) if (dwFlags & a) {strcat(string, #a );strcat(string," ");}
/******************************************************************************
 *            PROPSHEET_UnImplementedFlags
 *
 * Document use of flags we don't implement yet.
 */
static VOID PROPSHEET_UnImplementedFlags(DWORD dwFlags)
{
    CHAR string[256];

    string[0] = '\0';

  /*
   * unhandled header flags:
   *  PSH_RTLREADING         0x00000800
   *  PSH_STRETCHWATERMARK   0x00040000
   *  PSH_USEPAGELANG        0x00200000
   */

    add_flag(PSH_RTLREADING);
    add_flag(PSH_STRETCHWATERMARK);
    add_flag(PSH_USEPAGELANG);
    if (string[0] != '\0')
	FIXME("%s\n", string);
}
206
#undef add_flag
207

208 209 210 211 212
/******************************************************************************
 *            PROPSHEET_GetPageRect
 *
 * Retrieve rect from tab control and map into the dialog for SetWindowPos
 */
Filip Navara's avatar
Filip Navara committed
213 214
static void PROPSHEET_GetPageRect(const PropSheetInfo * psInfo, HWND hwndDlg,
                                  RECT *rc, LPCPROPSHEETPAGEW ppshpage)
215
{
Filip Navara's avatar
Filip Navara committed
216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233
    if (psInfo->ppshheader.dwFlags & INTRNL_ANY_WIZARD) {     
        HWND hwndChild;
        RECT r;

        if (((psInfo->ppshheader.dwFlags & (PSH_WIZARD97_NEW | PSH_WIZARD97_OLD)) &&
             (psInfo->ppshheader.dwFlags & PSH_HEADER) &&
             !(ppshpage->dwFlags & PSP_HIDEHEADER)) ||
            (psInfo->ppshheader.dwFlags & PSH_WIZARD))
        {
            rc->left = rc->top = WIZARD_PADDING;
        }
        else
        {
            rc->left = rc->top = 0;
        }
        rc->right = psInfo->width - rc->left;
        rc->bottom = psInfo->height - rc->top;
        MapDialogRect(hwndDlg, rc);
234

Filip Navara's avatar
Filip Navara committed
235 236 237 238 239 240 241 242 243 244 245 246 247 248 249
        if ((psInfo->ppshheader.dwFlags & (PSH_WIZARD97_NEW | PSH_WIZARD97_OLD)) &&
            (psInfo->ppshheader.dwFlags & PSH_HEADER) &&
            !(ppshpage->dwFlags & PSP_HIDEHEADER))
        {
            hwndChild = GetDlgItem(hwndDlg, IDC_SUNKEN_LINEHEADER);
            GetClientRect(hwndChild, &r);
            MapWindowPoints(hwndChild, hwndDlg, (LPPOINT) &r, 2);
            rc->top += r.bottom + 1;
        }
    } else {
        HWND hwndTabCtrl = GetDlgItem(hwndDlg, IDC_TABCONTROL);
        GetClientRect(hwndTabCtrl, rc);
        SendMessageW(hwndTabCtrl, TCM_ADJUSTRECT, FALSE, (LPARAM)rc);
        MapWindowPoints(hwndTabCtrl, hwndDlg, (LPPOINT)rc, 2);
    }
250 251
}

252 253 254 255 256
/******************************************************************************
 *            PROPSHEET_FindPageByResId
 *
 * Find page index corresponding to page resource id.
 */
257
static INT PROPSHEET_FindPageByResId(const PropSheetInfo * psInfo, LRESULT resId)
258 259 260 261 262 263 264 265 266 267 268 269 270 271 272
{
   INT i;

   for (i = 0; i < psInfo->nPages; i++)
   {
      LPCPROPSHEETPAGEA lppsp = (LPCPROPSHEETPAGEA)psInfo->proppage[i].hpage;

      /* Fixme: if resource ID is a string shall we use strcmp ??? */
      if (lppsp->u.pszTemplate == (LPVOID)resId)
         break;
   }

   return i;
}

273 274 275 276 277 278 279 280
/******************************************************************************
 *            PROPSHEET_AtoW
 *
 * Convert ASCII to Unicode since all data is saved as Unicode.
 */
static void PROPSHEET_AtoW(LPCWSTR *tostr, LPCSTR frstr)
{
    INT len;
281
    WCHAR *to;
282 283 284

    TRACE("<%s>\n", frstr);
    len = MultiByteToWideChar(CP_ACP, 0, frstr, -1, 0, 0);
285 286 287
    to = Alloc(len * sizeof(WCHAR));
    MultiByteToWideChar(CP_ACP, 0, frstr, -1, to, len);
    *tostr = to;
288 289
}

290 291 292 293 294 295 296 297 298 299 300 301 302
/******************************************************************************
 *            PROPSHEET_CollectSheetInfoCommon
 *
 * Common code for PROPSHEET_CollectSheetInfoA/W
 */
static void PROPSHEET_CollectSheetInfoCommon(PropSheetInfo * psInfo, DWORD dwFlags)
{
  PROPSHEET_UnImplementedFlags(dwFlags);

  psInfo->hasHelp = dwFlags & PSH_HASHELP;
  psInfo->hasApply = !(dwFlags & PSH_NOAPPLYNOW);
  psInfo->hasFinish = dwFlags & PSH_WIZARDHASFINISH;
  psInfo->isModeless = dwFlags & PSH_MODELESS;
303
  psInfo->usePropPage = dwFlags & PSH_PROPSHEETPAGE;
304 305 306 307 308 309 310 311
  if (psInfo->active_page < 0 || psInfo->active_page >= psInfo->nPages)
     psInfo->active_page = 0;

  psInfo->result = 0;
  psInfo->hImageList = 0;
  psInfo->activeValid = FALSE;
}

312
/******************************************************************************
313
 *            PROPSHEET_CollectSheetInfoA
314 315 316
 *
 * Collect relevant data.
 */
317
static void PROPSHEET_CollectSheetInfoA(LPCPROPSHEETHEADERA lppsh,
318 319
                                       PropSheetInfo * psInfo)
{
320
  DWORD dwSize = min(lppsh->dwSize,sizeof(PROPSHEETHEADERA));
321 322
  DWORD dwFlags = lppsh->dwFlags;

323
  psInfo->useCallback = (dwFlags & PSH_USECALLBACK )&& (lppsh->pfnCallback);
Alexandre Julliard's avatar
Alexandre Julliard committed
324

325
  memcpy(&psInfo->ppshheader,lppsh,dwSize);
326
  TRACE("\n** PROPSHEETHEADER **\ndwSize\t\t%d\ndwFlags\t\t%08x\nhwndParent\t%p\nhInstance\t%p\npszCaption\t'%s'\nnPages\t\t%d\npfnCallback\t%p\n",
327 328 329
	lppsh->dwSize, lppsh->dwFlags, lppsh->hwndParent, lppsh->hInstance,
	debugstr_a(lppsh->pszCaption), lppsh->nPages, lppsh->pfnCallback);

330 331 332
  if (lppsh->dwFlags & INTRNL_ANY_WIZARD)
     psInfo->ppshheader.pszCaption = NULL;
  else
333
  {
334
     if (!IS_INTRESOURCE(lppsh->pszCaption))
335
     {
336
        int len = MultiByteToWideChar(CP_ACP, 0, lppsh->pszCaption, -1, NULL, 0);
337 338 339 340
        WCHAR *caption = Alloc( len*sizeof (WCHAR) );

        MultiByteToWideChar(CP_ACP, 0, lppsh->pszCaption, -1, caption, len);
        psInfo->ppshheader.pszCaption = caption;
341
     }
342
  }
343
  psInfo->nPages = lppsh->nPages;
344 345 346

  if (dwFlags & PSH_USEPSTARTPAGE)
  {
347
    TRACE("PSH_USEPSTARTPAGE is on\n");
348 349 350 351 352
    psInfo->active_page = 0;
  }
  else
    psInfo->active_page = lppsh->u2.nStartPage;

353
  PROPSHEET_CollectSheetInfoCommon(psInfo, dwFlags);
354 355 356
}

/******************************************************************************
357 358 359 360
 *            PROPSHEET_CollectSheetInfoW
 *
 * Collect relevant data.
 */
361
static void PROPSHEET_CollectSheetInfoW(LPCPROPSHEETHEADERW lppsh,
362 363 364 365 366
                                       PropSheetInfo * psInfo)
{
  DWORD dwSize = min(lppsh->dwSize,sizeof(PROPSHEETHEADERW));
  DWORD dwFlags = lppsh->dwFlags;

367
  psInfo->useCallback = (dwFlags & PSH_USECALLBACK) && (lppsh->pfnCallback);
368 369

  memcpy(&psInfo->ppshheader,lppsh,dwSize);
370
  TRACE("\n** PROPSHEETHEADER **\ndwSize\t\t%d\ndwFlags\t\t%08x\nhwndParent\t%p\nhInstance\t%p\npszCaption\t%s\nnPages\t\t%d\npfnCallback\t%p\n",
371 372
      lppsh->dwSize, lppsh->dwFlags, lppsh->hwndParent, lppsh->hInstance, debugstr_w(lppsh->pszCaption), lppsh->nPages, lppsh->pfnCallback);

373 374 375
  if (lppsh->dwFlags & INTRNL_ANY_WIZARD)
     psInfo->ppshheader.pszCaption = NULL;
  else
376
  {
377
     if (!IS_INTRESOURCE(lppsh->pszCaption))
378 379
     {
        int len = strlenW(lppsh->pszCaption);
380 381 382
        WCHAR *caption = Alloc( (len+1)*sizeof(WCHAR) );

        psInfo->ppshheader.pszCaption = strcpyW( caption, lppsh->pszCaption );
383
     }
384 385 386 387 388
  }
  psInfo->nPages = lppsh->nPages;

  if (dwFlags & PSH_USEPSTARTPAGE)
  {
389
    TRACE("PSH_USEPSTARTPAGE is on\n");
390 391 392 393 394
    psInfo->active_page = 0;
  }
  else
    psInfo->active_page = lppsh->u2.nStartPage;

395
  PROPSHEET_CollectSheetInfoCommon(psInfo, dwFlags);
396 397 398
}

/******************************************************************************
399
 *            PROPSHEET_CollectPageInfo
400 401 402 403
 *
 * Collect property sheet data.
 * With code taken from DIALOG_ParseTemplate32.
 */
404
static BOOL PROPSHEET_CollectPageInfo(LPCPROPSHEETPAGEW lppsp,
405
                               PropSheetInfo * psInfo,
406
                               int index, BOOL resize)
407
{
408
  const DLGTEMPLATE* pTemplate;
409 410 411 412
  const WORD*  p;
  DWORD dwFlags;
  int width, height;

413 414 415
  if (!lppsp)
    return FALSE;

416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436
  TRACE("\n");
  psInfo->proppage[index].hpage = (HPROPSHEETPAGE)lppsp;
  psInfo->proppage[index].hwndPage = 0;
  psInfo->proppage[index].isDirty = FALSE;

  /*
   * Process property page flags.
   */
  dwFlags = lppsp->dwFlags;
  psInfo->proppage[index].useCallback = (dwFlags & PSP_USECALLBACK) && (lppsp->pfnCallback);
  psInfo->proppage[index].hasHelp = dwFlags & PSP_HASHELP;
  psInfo->proppage[index].hasIcon = dwFlags & (PSP_USEHICON | PSP_USEICONID);

  /* as soon as we have a page with the help flag, set the sheet flag on */
  if (psInfo->proppage[index].hasHelp)
    psInfo->hasHelp = TRUE;

  /*
   * Process page template.
   */
  if (dwFlags & PSP_DLGINDIRECT)
437
    pTemplate = lppsp->u.pResource;
438
  else if(dwFlags & PSP_INTERNAL_UNICODE )
439 440 441
  {
    HRSRC hResource = FindResourceW(lppsp->hInstance,
                                    lppsp->u.pszTemplate,
442
                                    (LPWSTR)RT_DIALOG);
443 444
    HGLOBAL hTemplate = LoadResource(lppsp->hInstance,
                                     hResource);
445
    pTemplate = LockResource(hTemplate);
446
  }
447 448 449
  else
  {
    HRSRC hResource = FindResourceA(lppsp->hInstance,
450
                                    (LPCSTR)lppsp->u.pszTemplate,
451
                                    (LPSTR)RT_DIALOG);
452 453
    HGLOBAL hTemplate = LoadResource(lppsp->hInstance,
                                     hResource);
454
    pTemplate = LockResource(hTemplate);
455
  }
456 457 458 459 460 461 462 463 464

  /*
   * Extract the size of the page and the caption.
   */
  if (!pTemplate)
      return FALSE;

  p = (const WORD *)pTemplate;

465
  if (((const MyDLGTEMPLATEEX*)pTemplate)->signature == 0xFFFF)
466
  {
467
    /* DLGTEMPLATEEX (not defined in any std. header file) */
468 469 470 471 472 473 474 475 476

    p++;       /* dlgVer    */
    p++;       /* signature */
    p += 2;    /* help ID   */
    p += 2;    /* ext style */
    p += 2;    /* style     */
  }
  else
  {
477
    /* DLGTEMPLATE */
478 479 480 481 482 483 484 485 486 487 488

    p += 2;    /* style     */
    p += 2;    /* ext style */
  }

  p++;    /* nb items */
  p++;    /*   x      */
  p++;    /*   y      */
  width  = (WORD)*p; p++;
  height = (WORD)*p; p++;

Filip Navara's avatar
Filip Navara committed
489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505
  /* Special calculation for interior wizard pages so the largest page is
   * calculated correctly. We need to add all the padding and space occupied
   * by the header so the width and height sums up to the whole wizard client
   * area. */
  if ((psInfo->ppshheader.dwFlags & (PSH_WIZARD97_OLD | PSH_WIZARD97_NEW)) &&
      (psInfo->ppshheader.dwFlags & PSH_HEADER) &&
      !(dwFlags & PSP_HIDEHEADER))
  {
      height += 2 * WIZARD_PADDING + WIZARD_HEADER_HEIGHT;
      width += 2 * WIZARD_PADDING;
  }
  if (psInfo->ppshheader.dwFlags & PSH_WIZARD)
  {
      height += 2 * WIZARD_PADDING;
      width += 2 * WIZARD_PADDING;
  }

506
  /* remember the largest width and height */
507 508 509 510
  if (resize)
  {
      if (width > psInfo->width)
        psInfo->width = width;
511

512 513 514
      if (height > psInfo->height)
        psInfo->height = height;
  }
515 516 517 518 519 520 521 522 523 524 525

  /* menu */
  switch ((WORD)*p)
  {
    case 0x0000:
      p++;
      break;
    case 0xffff:
      p += 2;
      break;
    default:
526
      p += lstrlenW( p ) + 1;
527
      break;
528
  }
529 530 531 532 533 534 535 536 537 538 539

  /* class */
  switch ((WORD)*p)
  {
    case 0x0000:
      p++;
      break;
    case 0xffff:
      p += 2;
      break;
    default:
540
      p += lstrlenW( p ) + 1;
541 542 543 544
      break;
  }

  /* Extract the caption */
545 546
  psInfo->proppage[index].pszText = p;
  TRACE("Tab %d %s\n",index,debugstr_w( p ));
547 548 549 550 551

  if (dwFlags & PSP_USETITLE)
  {
    WCHAR szTitle[256];
    const WCHAR *pTitle;
552
    static const WCHAR pszNull[] = { '(','n','u','l','l',')',0 };
553
    WCHAR *text;
554 555
    int len;

556
    if (IS_INTRESOURCE( lppsp->pszTitle ))
557
    {
558
      if (!LoadStringW( lppsp->hInstance, (DWORD_PTR)lppsp->pszTitle,szTitle,sizeof(szTitle)/sizeof(szTitle[0]) ))
559 560 561 562 563 564 565 566 567 568
      {
        pTitle = pszNull;
	FIXME("Could not load resource #%04x?\n",LOWORD(lppsp->pszTitle));
      }
      else
        pTitle = szTitle;
    }
    else
      pTitle = lppsp->pszTitle;

569
    len = strlenW(pTitle);
570 571
    text = Alloc( (len+1)*sizeof (WCHAR) );
    psInfo->proppage[index].pszText = strcpyW( text, pTitle);
572 573 574 575 576
  }

  /*
   * Build the image list for icons
   */
577
  if ((dwFlags & PSP_USEHICON) || (dwFlags & PSP_USEICONID))
578 579 580 581 582 583
  {
    HICON hIcon;
    int icon_cx = GetSystemMetrics(SM_CXSMICON);
    int icon_cy = GetSystemMetrics(SM_CYSMICON);

    if (dwFlags & PSP_USEICONID)
584
      hIcon = LoadImageW(lppsp->hInstance, lppsp->u2.pszIcon, IMAGE_ICON,
585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600
                         icon_cx, icon_cy, LR_DEFAULTCOLOR);
    else
      hIcon = lppsp->u2.hIcon;

    if ( hIcon )
    {
      if (psInfo->hImageList == 0 )
	psInfo->hImageList = ImageList_Create(icon_cx, icon_cy, ILC_COLOR, 1, 1);

      ImageList_AddIcon(psInfo->hImageList, hIcon);
    }

  }

  return TRUE;
}
Alexandre Julliard's avatar
Alexandre Julliard committed
601

602 603 604 605 606
/******************************************************************************
 *            PROPSHEET_CreateDialog
 *
 * Creates the actual property sheet.
 */
607
static INT_PTR PROPSHEET_CreateDialog(PropSheetInfo* psInfo)
608 609 610
{
  LRESULT ret;
  LPCVOID template;
611
  LPVOID temp = 0;
612
  HRSRC hRes;
613
  DWORD resSize;
614 615
  WORD resID = IDD_PROPSHEET;

616
  TRACE("(%p)\n", psInfo);
617
  if (psInfo->ppshheader.dwFlags & INTRNL_ANY_WIZARD)
618
    resID = IDD_WIZARD;
619

620 621 622
  if( psInfo->unicode )
  {
    if(!(hRes = FindResourceW(COMCTL32_hModule,
623
                            MAKEINTRESOURCEW(resID),
624
                            (LPWSTR)RT_DIALOG)))
625 626 627 628 629 630
      return -1;
  }
  else
  {
    if(!(hRes = FindResourceA(COMCTL32_hModule,
                            MAKEINTRESOURCEA(resID),
631
                            (LPSTR)RT_DIALOG)))
632 633
      return -1;
  }
634

635
  if(!(template = LoadResource(COMCTL32_hModule, hRes)))
636
    return -1;
637

638 639 640 641 642
  /*
   * Make a copy of the dialog template.
   */
  resSize = SizeofResource(COMCTL32_hModule, hRes);

643
  temp = Alloc(resSize);
644 645

  if (!temp)
646
    return -1;
647 648 649

  memcpy(temp, template, resSize);

650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665
  if (psInfo->ppshheader.dwFlags & PSH_NOCONTEXTHELP)
  {
    if (((MyDLGTEMPLATEEX*)temp)->signature == 0xFFFF)
      ((MyDLGTEMPLATEEX*)temp)->style &= ~DS_CONTEXTHELP;
    else
      ((DLGTEMPLATE*)temp)->style &= ~DS_CONTEXTHELP;
  }
  if ((psInfo->ppshheader.dwFlags & INTRNL_ANY_WIZARD) &&
      (psInfo->ppshheader.dwFlags & PSH_WIZARDCONTEXTHELP))
  {
    if (((MyDLGTEMPLATEEX*)temp)->signature == 0xFFFF)
      ((MyDLGTEMPLATEEX*)temp)->style |= DS_CONTEXTHELP;
    else
      ((DLGTEMPLATE*)temp)->style |= DS_CONTEXTHELP;
  }

666
  if (psInfo->useCallback)
667
    (*(psInfo->ppshheader.pfnCallback))(0, PSCB_PRECREATE, (LPARAM)temp);
668

669 670 671 672
  /* NOTE: MSDN states "Returns a positive value if successful, or -1
   * otherwise for modal property sheets.", but this is wrong. The
   * actual return value is either TRUE (success), FALSE (cancel) or
   * -1 (error). */
673 674
  if( psInfo->unicode )
  {
Frank Richter's avatar
Frank Richter committed
675
    ret = (INT_PTR)CreateDialogIndirectParamW(psInfo->ppshheader.hInstance,
676 677
                                          temp, psInfo->ppshheader.hwndParent,
                                          PROPSHEET_DialogProc, (LPARAM)psInfo);
678
    if ( !ret ) ret = -1;
679 680 681
  }
  else
  {
Frank Richter's avatar
Frank Richter committed
682
    ret = (INT_PTR)CreateDialogIndirectParamA(psInfo->ppshheader.hInstance,
683 684
                                          temp, psInfo->ppshheader.hwndParent,
                                          PROPSHEET_DialogProc, (LPARAM)psInfo);
685
    if ( !ret ) ret = -1;
686
  }
687

688
  Free(temp);
689

690 691 692 693
  return ret;
}

/******************************************************************************
694
 *            PROPSHEET_SizeMismatch
695
 *
696 697
 *     Verify that the tab control and the "largest" property sheet page dlg. template
 *     match in size.
698
 */
699
static BOOL PROPSHEET_SizeMismatch(HWND hwndDlg, const PropSheetInfo* psInfo)
700 701 702 703 704 705 706 707
{
  HWND hwndTabCtrl = GetDlgItem(hwndDlg, IDC_TABCONTROL);
  RECT rcOrigTab, rcPage;

  /*
   * Original tab size.
   */
  GetClientRect(hwndTabCtrl, &rcOrigTab);
708
  TRACE("orig tab %s\n", wine_dbgstr_rect(&rcOrigTab));
709 710 711 712

  /*
   * Biggest page size.
   */
Filip Navara's avatar
Filip Navara committed
713 714
  rcPage.left   = 0;
  rcPage.top    = 0;
715 716 717 718
  rcPage.right  = psInfo->width;
  rcPage.bottom = psInfo->height;

  MapDialogRect(hwndDlg, &rcPage);
719
  TRACE("biggest page %s\n", wine_dbgstr_rect(&rcPage));
720

721
  if ( (rcPage.right - rcPage.left) != (rcOrigTab.right - rcOrigTab.left) )
722
    return TRUE;
723
  if ( (rcPage.bottom - rcPage.top) != (rcOrigTab.bottom - rcOrigTab.top) )
724 725 726 727 728 729 730 731 732 733 734 735 736 737
    return TRUE;

  return FALSE;
}

/******************************************************************************
 *            PROPSHEET_AdjustSize
 *
 * Resizes the property sheet and the tab control to fit the largest page.
 */
static BOOL PROPSHEET_AdjustSize(HWND hwndDlg, PropSheetInfo* psInfo)
{
  HWND hwndTabCtrl = GetDlgItem(hwndDlg, IDC_TABCONTROL);
  HWND hwndButton = GetDlgItem(hwndDlg, IDOK);
738
  RECT rc,tabRect;
739
  int buttonHeight;
740
  PADDING_INFO padding = PROPSHEET_GetPaddingInfo(hwndDlg);
741
  RECT units;
742
  LONG style;
743 744 745 746 747 748 749 750

  /* Get the height of buttons */
  GetClientRect(hwndButton, &rc);
  buttonHeight = rc.bottom;

  /*
   * Biggest page size.
   */
Filip Navara's avatar
Filip Navara committed
751 752
  rc.left   = 0;
  rc.top    = 0;
753 754 755 756 757
  rc.right  = psInfo->width;
  rc.bottom = psInfo->height;

  MapDialogRect(hwndDlg, &rc);

758 759 760 761 762
  /* retrieve the dialog units */
  units.left = units.right = 4;
  units.top = units.bottom = 8;
  MapDialogRect(hwndDlg, &units);

763 764 765
  /*
   * Resize the tab control.
   */
766 767
  GetClientRect(hwndTabCtrl,&tabRect);

768
  SendMessageW(hwndTabCtrl, TCM_ADJUSTRECT, FALSE, (LPARAM)&tabRect);
769 770 771 772

  if ((rc.bottom - rc.top) < (tabRect.bottom - tabRect.top))
  {
      rc.bottom = rc.top + tabRect.bottom - tabRect.top;
773
      psInfo->height = MulDiv((rc.bottom - rc.top),8,units.top);
774
  }
775

776 777 778
  if ((rc.right - rc.left) < (tabRect.right - tabRect.left))
  {
      rc.right = rc.left + tabRect.right - tabRect.left;
779
      psInfo->width  = MulDiv((rc.right - rc.left),4,units.left);
780 781
  }

782
  SendMessageW(hwndTabCtrl, TCM_ADJUSTRECT, TRUE, (LPARAM)&rc);
783 784 785

  rc.right -= rc.left;
  rc.bottom -= rc.top;
786
  TRACE("setting tab %p, rc (0,0)-(%d,%d)\n",
Frank Richter's avatar
Frank Richter committed
787
        hwndTabCtrl, rc.right, rc.bottom);
788 789 790 791 792
  SetWindowPos(hwndTabCtrl, 0, 0, 0, rc.right, rc.bottom,
               SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE);

  GetClientRect(hwndTabCtrl, &rc);

793
  TRACE("tab client rc %s\n", wine_dbgstr_rect(&rc));
794

795 796 797
  rc.right += (padding.x * 2);
  rc.bottom += buttonHeight + (3 * padding.y);

798 799 800
  style = GetWindowLongW(hwndDlg, GWL_STYLE);
  if (!(style & WS_CHILD))
    AdjustWindowRect(&rc, style, FALSE);
801 802 803

  rc.right -= rc.left;
  rc.bottom -= rc.top;
804 805 806 807

  /*
   * Resize the property sheet.
   */
808
  TRACE("setting dialog %p, rc (0,0)-(%d,%d)\n",
Frank Richter's avatar
Frank Richter committed
809
        hwndDlg, rc.right, rc.bottom);
810 811 812 813 814
  SetWindowPos(hwndDlg, 0, 0, 0, rc.right, rc.bottom,
               SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE);
  return TRUE;
}

815 816 817 818 819
/******************************************************************************
 *            PROPSHEET_AdjustSizeWizard
 *
 * Resizes the property sheet to fit the largest page.
 */
820
static BOOL PROPSHEET_AdjustSizeWizard(HWND hwndDlg, const PropSheetInfo* psInfo)
821 822
{
  HWND hwndLine = GetDlgItem(hwndDlg, IDC_SUNKEN_LINE);
Filip Navara's avatar
Filip Navara committed
823
  RECT rc, lineRect, dialogRect;
824

Filip Navara's avatar
Filip Navara committed
825 826 827
  /* Biggest page size */
  rc.left   = 0;
  rc.top    = 0;
828 829 830 831
  rc.right  = psInfo->width;
  rc.bottom = psInfo->height;
  MapDialogRect(hwndDlg, &rc);

832
  TRACE("Biggest page %s\n", wine_dbgstr_rect(&rc));
833

Filip Navara's avatar
Filip Navara committed
834 835 836 837 838
  /* Add space for the buttons row */
  GetWindowRect(hwndLine, &lineRect);
  MapWindowPoints(NULL, hwndDlg, (LPPOINT)&lineRect, 2);
  GetClientRect(hwndDlg, &dialogRect);
  rc.bottom += dialogRect.bottom - lineRect.top - 1;
839

Filip Navara's avatar
Filip Navara committed
840 841 842 843
  /* Convert the client coordinates to window coordinates */
  AdjustWindowRect(&rc, GetWindowLongW(hwndDlg, GWL_STYLE), FALSE);

  /* Resize the property sheet */
844
  TRACE("setting dialog %p, rc (0,0)-(%d,%d)\n",
Frank Richter's avatar
Frank Richter committed
845
        hwndDlg, rc.right, rc.bottom);
Filip Navara's avatar
Filip Navara committed
846
  SetWindowPos(hwndDlg, 0, 0, 0, rc.right - rc.left, rc.bottom - rc.top,
847
               SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE);
Filip Navara's avatar
Filip Navara committed
848

849 850 851
  return TRUE;
}

852 853 854 855 856
/******************************************************************************
 *            PROPSHEET_AdjustButtons
 *
 * Adjusts the buttons' positions.
 */
857
static BOOL PROPSHEET_AdjustButtons(HWND hwndParent, const PropSheetInfo* psInfo)
858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880
{
  HWND hwndButton = GetDlgItem(hwndParent, IDOK);
  RECT rcSheet;
  int x, y;
  int num_buttons = 2;
  int buttonWidth, buttonHeight;
  PADDING_INFO padding = PROPSHEET_GetPaddingInfo(hwndParent);

  if (psInfo->hasApply)
    num_buttons++;

  if (psInfo->hasHelp)
    num_buttons++;

  /*
   * Obtain the size of the buttons.
   */
  GetClientRect(hwndButton, &rcSheet);
  buttonWidth = rcSheet.right;
  buttonHeight = rcSheet.bottom;

  /*
   * Get the size of the property sheet.
881
   */
882 883
  GetClientRect(hwndParent, &rcSheet);

884
  /*
885 886 887 888 889
   * All buttons will be at this y coordinate.
   */
  y = rcSheet.bottom - (padding.y + buttonHeight);

  /*
890
   * Position OK button and make it default.
891 892 893 894 895 896 897 898
   */
  hwndButton = GetDlgItem(hwndParent, IDOK);

  x = rcSheet.right - ((padding.x + buttonWidth) * num_buttons);

  SetWindowPos(hwndButton, 0, x, y, 0, 0,
               SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);

899
  SendMessageW(hwndParent, DM_SETDEFID, IDOK, 0);
900 901


902 903 904 905 906
  /*
   * Position Cancel button.
   */
  hwndButton = GetDlgItem(hwndParent, IDCANCEL);

907
  x += padding.x + buttonWidth;
908 909 910 911 912 913 914 915 916

  SetWindowPos(hwndButton, 0, x, y, 0, 0,
               SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);

  /*
   * Position Apply button.
   */
  hwndButton = GetDlgItem(hwndParent, IDC_APPLY_BUTTON);

917 918
  if(psInfo->hasApply)
    x += padding.x + buttonWidth;
919 920 921
  else
    ShowWindow(hwndButton, SW_HIDE);

922 923 924 925
  SetWindowPos(hwndButton, 0, x, y, 0, 0,
              SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
  EnableWindow(hwndButton, FALSE);

926 927 928 929 930
  /*
   * Position Help button.
   */
  hwndButton = GetDlgItem(hwndParent, IDHELP);

931 932 933
  x += padding.x + buttonWidth;
  SetWindowPos(hwndButton, 0, x, y, 0, 0,
              SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
934

935
  if(!psInfo->hasHelp)
936 937 938 939 940
    ShowWindow(hwndButton, SW_HIDE);

  return TRUE;
}

941 942 943 944 945 946
/******************************************************************************
 *            PROPSHEET_AdjustButtonsWizard
 *
 * Adjusts the buttons' positions.
 */
static BOOL PROPSHEET_AdjustButtonsWizard(HWND hwndParent,
947
                                          const PropSheetInfo* psInfo)
948 949 950
{
  HWND hwndButton = GetDlgItem(hwndParent, IDCANCEL);
  HWND hwndLine = GetDlgItem(hwndParent, IDC_SUNKEN_LINE);
951
  HWND hwndLineHeader = GetDlgItem(hwndParent, IDC_SUNKEN_LINEHEADER);
952 953 954 955
  RECT rcSheet;
  int x, y;
  int num_buttons = 3;
  int buttonWidth, buttonHeight, lineHeight, lineWidth;
956
  PADDING_INFO padding = PROPSHEET_GetPaddingInfoWizard(hwndParent, psInfo);
957 958 959

  if (psInfo->hasHelp)
    num_buttons++;
960 961
  if (psInfo->hasFinish)
    num_buttons++;
962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981

  /*
   * Obtain the size of the buttons.
   */
  GetClientRect(hwndButton, &rcSheet);
  buttonWidth = rcSheet.right;
  buttonHeight = rcSheet.bottom;

  GetClientRect(hwndLine, &rcSheet);
  lineHeight = rcSheet.bottom;

  /*
   * Get the size of the property sheet.
   */
  GetClientRect(hwndParent, &rcSheet);

  /*
   * All buttons will be at this y coordinate.
   */
  y = rcSheet.bottom - (padding.y + buttonHeight);
982
  
983
  /*
984
   * Position the Back button.
985
   */
986
  hwndButton = GetDlgItem(hwndParent, IDC_BACK_BUTTON);
987

988
  x = rcSheet.right - ((padding.x + buttonWidth) * (num_buttons - 1)) - buttonWidth;
989 990 991 992

  SetWindowPos(hwndButton, 0, x, y, 0, 0,
               SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);

993 994 995 996 997 998 999
  /*
   * Position the Next button.
   */
  hwndButton = GetDlgItem(hwndParent, IDC_NEXT_BUTTON);
  
  x += buttonWidth;
  
1000 1001 1002 1003
  SetWindowPos(hwndButton, 0, x, y, 0, 0,
               SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);

  /*
1004
   * Position the Finish button.
1005
   */
1006 1007 1008 1009
  hwndButton = GetDlgItem(hwndParent, IDC_FINISH_BUTTON);
  
  if (psInfo->hasFinish)
    x += padding.x + buttonWidth;
1010 1011 1012 1013

  SetWindowPos(hwndButton, 0, x, y, 0, 0,
               SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);

1014 1015 1016
  if (!psInfo->hasFinish)
    ShowWindow(hwndButton, SW_HIDE);

1017 1018 1019 1020 1021
  /*
   * Position the Cancel button.
   */
  hwndButton = GetDlgItem(hwndParent, IDCANCEL);

1022
  x += padding.x + buttonWidth;
1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033

  SetWindowPos(hwndButton, 0, x, y, 0, 0,
               SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);

  /*
   * Position Help button.
   */
  hwndButton = GetDlgItem(hwndParent, IDHELP);

  if (psInfo->hasHelp)
  {
1034
    x += padding.x + buttonWidth;
1035 1036 1037 1038 1039 1040 1041

    SetWindowPos(hwndButton, 0, x, y, 0, 0,
                 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
  }
  else
    ShowWindow(hwndButton, SW_HIDE);

Filip Navara's avatar
Filip Navara committed
1042 1043
  if (psInfo->ppshheader.dwFlags &
      (PSH_WIZARD97_OLD | PSH_WIZARD97_NEW | PSH_WIZARD_LITE)) 
1044 1045
      padding.x = 0;

1046 1047 1048 1049 1050 1051 1052 1053 1054 1055
  /*
   * Position and resize the sunken line.
   */
  x = padding.x;
  y = rcSheet.bottom - ((padding.y * 2) + buttonHeight + lineHeight);

  lineWidth = rcSheet.right - (padding.x * 2);
  SetWindowPos(hwndLine, 0, x, y, lineWidth, 2,
               SWP_NOZORDER | SWP_NOACTIVATE);

1056 1057 1058 1059 1060 1061 1062 1063 1064
  /*
   * Position and resize the header sunken line.
   */
  
  SetWindowPos(hwndLineHeader, 0, 0, 0, rcSheet.right, 2,
	       SWP_NOZORDER | SWP_NOMOVE | SWP_NOACTIVATE);
  if (!(psInfo->ppshheader.dwFlags & (PSH_WIZARD97_OLD | PSH_WIZARD97_NEW)))
      ShowWindow(hwndLineHeader, SW_HIDE);

1065 1066 1067
  return TRUE;
}

1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079
/******************************************************************************
 *            PROPSHEET_GetPaddingInfo
 *
 * Returns the layout information.
 */
static PADDING_INFO PROPSHEET_GetPaddingInfo(HWND hwndDlg)
{
  HWND hwndTab = GetDlgItem(hwndDlg, IDC_TABCONTROL);
  RECT rcTab;
  PADDING_INFO padding;

  GetWindowRect(hwndTab, &rcTab);
1080
  MapWindowPoints( 0, hwndDlg, (POINT *)&rcTab, 2 );
1081

1082 1083
  padding.x = rcTab.left;
  padding.y = rcTab.top;
1084 1085 1086 1087

  return padding;
}

1088 1089 1090 1091 1092
/******************************************************************************
 *            PROPSHEET_GetPaddingInfoWizard
 *
 * Returns the layout information.
 * Vertical spacing is the distance between the line and the buttons.
1093 1094 1095 1096 1097 1098
 * Do NOT use the Help button to gather padding information when it isn't mapped
 * (PSH_HASHELP), as app writers aren't forced to supply correct coordinates
 * for it in this case !
 * FIXME: I'm not sure about any other coordinate problems with these evil
 * buttons. Fix it in case additional problems appear or maybe calculate
 * a padding in a completely different way, as this is somewhat messy.
1099
 */
1100 1101
static PADDING_INFO PROPSHEET_GetPaddingInfoWizard(HWND hwndDlg, const PropSheetInfo*
 psInfo)
1102 1103 1104 1105
{
  PADDING_INFO padding;
  RECT rc;
  HWND hwndControl;
1106 1107
  INT idButton;
  POINT ptButton, ptLine;
1108

1109
  TRACE("\n");
1110 1111 1112 1113 1114 1115
  if (psInfo->hasHelp)
  {
	idButton = IDHELP;
  }
  else
  {
1116
    if (psInfo->ppshheader.dwFlags & INTRNL_ANY_WIZARD)
1117 1118 1119 1120 1121 1122 1123 1124 1125
    {
	idButton = IDC_NEXT_BUTTON;
    }
    else
    {
	/* hopefully this is ok */
	idButton = IDCANCEL;
    }
  }
1126

1127
  hwndControl = GetDlgItem(hwndDlg, idButton);
1128
  GetWindowRect(hwndControl, &rc);
1129
  MapWindowPoints( 0, hwndDlg, (POINT *)&rc, 2 );
1130 1131
  ptButton.x = rc.left;
  ptButton.y = rc.top;
1132 1133 1134 1135

  /* Line */
  hwndControl = GetDlgItem(hwndDlg, IDC_SUNKEN_LINE);
  GetWindowRect(hwndControl, &rc);
1136
  MapWindowPoints( 0, hwndDlg, (POINT *)&rc, 2 );
1137
  ptLine.x = rc.left;
1138 1139
  ptLine.y = rc.bottom;

1140 1141 1142 1143
  padding.y = ptButton.y - ptLine.y;

  if (padding.y < 0)
	  ERR("padding negative ! Please report this !\n");
1144

1145 1146
  /* this is most probably not correct, but the best we have now */
  padding.x = padding.y;
1147 1148 1149
  return padding;
}

1150 1151 1152 1153 1154 1155
/******************************************************************************
 *            PROPSHEET_CreateTabControl
 *
 * Insert the tabs in the tab control.
 */
static BOOL PROPSHEET_CreateTabControl(HWND hwndParent,
1156
                                       const PropSheetInfo * psInfo)
1157 1158
{
  HWND hwndTabCtrl = GetDlgItem(hwndParent, IDC_TABCONTROL);
1159
  TCITEMW item;
1160
  int i, nTabs;
Alexandre Julliard's avatar
Alexandre Julliard committed
1161
  int iImage = 0;
1162

1163
  TRACE("\n");
1164
  item.mask = TCIF_TEXT;
1165
  item.cchTextMax = MAX_TABTEXT_LENGTH;
1166

1167
  nTabs = psInfo->nPages;
1168

1169 1170 1171 1172 1173
  /*
   * Set the image list for icons.
   */
  if (psInfo->hImageList)
  {
1174
    SendMessageW(hwndTabCtrl, TCM_SETIMAGELIST, 0, (LPARAM)psInfo->hImageList);
1175 1176
  }

1177
  SendMessageW(hwndTabCtrl, WM_SETREDRAW, 0, 0);
1178 1179
  for (i = 0; i < nTabs; i++)
  {
Alexandre Julliard's avatar
Alexandre Julliard committed
1180 1181 1182 1183 1184 1185 1186 1187 1188
    if ( psInfo->proppage[i].hasIcon )
    {
      item.mask |= TCIF_IMAGE;
      item.iImage = iImage++;
    }
    else
    {
      item.mask &= ~TCIF_IMAGE;
    }
1189

1190
    item.pszText = (LPWSTR) psInfo->proppage[i].pszText;
1191
    SendMessageW(hwndTabCtrl, TCM_INSERTITEMW, i, (LPARAM)&item);
1192
  }
1193
  SendMessageW(hwndTabCtrl, WM_SETREDRAW, 1, 0);
1194 1195 1196

  return TRUE;
}
1197 1198 1199 1200

/******************************************************************************
 *            PROPSHEET_WizardSubclassProc
 *
1201
 * Subclassing window procedure for wizard exterior pages to prevent drawing
1202 1203
 * background and so drawing above the watermark.
 */
1204
static LRESULT CALLBACK
1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219
PROPSHEET_WizardSubclassProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam, UINT_PTR uID, DWORD_PTR dwRef)
{
  switch (uMsg)
  {
    case WM_ERASEBKGND:
      return TRUE;

    case WM_CTLCOLORSTATIC:
      SetBkColor((HDC)wParam, GetSysColor(COLOR_WINDOW));
      return (INT_PTR)GetSysColorBrush(COLOR_WINDOW);
  }

  return DefSubclassProc(hwnd, uMsg, wParam, lParam);
}

1220 1221 1222 1223
/*
 * Get the size of an in-memory Template
 *
 *( Based on the code of PROPSHEET_CollectPageInfo)
1224
 * See also dialog.c/DIALOG_ParseTemplate32().
1225 1226
 */

1227
static UINT GetTemplateSize(const DLGTEMPLATE* pTemplate)
1228 1229 1230

{
  const WORD*  p = (const WORD *)pTemplate;
1231
  BOOL  istemplateex = (((const MyDLGTEMPLATEEX*)pTemplate)->signature == 0xFFFF);
1232
  WORD nrofitems;
1233
  UINT ret;
1234 1235 1236

  if (istemplateex)
  {
1237
    /* DLGTEMPLATEEX (not defined in any std. header file) */
1238

1239
    TRACE("is DLGTEMPLATEEX\n");
1240 1241 1242 1243 1244 1245 1246 1247
    p++;       /* dlgVer    */
    p++;       /* signature */
    p += 2;    /* help ID   */
    p += 2;    /* ext style */
    p += 2;    /* style     */
  }
  else
  {
1248
    /* DLGTEMPLATE */
1249

1250
    TRACE("is DLGTEMPLATE\n");
1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270
    p += 2;    /* style     */
    p += 2;    /* ext style */
  }

  nrofitems =   (WORD)*p; p++;    /* nb items */
  p++;    /*   x      */
  p++;    /*   y      */
  p++;    /*   width  */
  p++;    /*   height */

  /* menu */
  switch ((WORD)*p)
  {
    case 0x0000:
      p++;
      break;
    case 0xffff:
      p += 2;
      break;
    default:
1271 1272
      TRACE("menu %s\n",debugstr_w( p ));
      p += lstrlenW( p ) + 1;
1273 1274 1275 1276 1277 1278 1279 1280 1281 1282
      break;
  }

  /* class */
  switch ((WORD)*p)
  {
    case 0x0000:
      p++;
      break;
    case 0xffff:
1283
      p += 2; /* 0xffff plus predefined window class ordinal value */
1284 1285
      break;
    default:
1286 1287
      TRACE("class %s\n",debugstr_w( p ));
      p += lstrlenW( p ) + 1;
1288 1289 1290
      break;
  }

1291
  /* title */
1292 1293
  TRACE("title %s\n",debugstr_w( p ));
  p += lstrlenW( p ) + 1;
1294

1295
  /* font, if DS_SETFONT set */
1296
  if ((DS_SETFONT & ((istemplateex)?  ((const MyDLGTEMPLATEEX*)pTemplate)->style :
1297 1298 1299
		     pTemplate->style)))
    {
      p+=(istemplateex)?3:1;
1300 1301
      TRACE("font %s\n",debugstr_w( p ));
      p += lstrlenW( p ) + 1; /* the font name */
1302 1303
    }

1304 1305
  /* now process the DLGITEMTEMPLATE(EX) structs (plus custom data)
   * that are following the DLGTEMPLATE(EX) data */
1306 1307 1308
  TRACE("%d items\n",nrofitems);
  while (nrofitems > 0)
    {
Frank Richter's avatar
Frank Richter committed
1309
      p = (WORD*)(((DWORD_PTR)p + 3) & ~3); /* DWORD align */
1310
      
1311
      /* skip header */
1312 1313
      p += (istemplateex ? sizeof(MyDLGITEMTEMPLATEEX) : sizeof(DLGITEMTEMPLATE))/sizeof(WORD);
      
1314
      /* check class */
1315 1316 1317 1318 1319 1320
      switch ((WORD)*p)
	{
	case 0x0000:
	  p++;
	  break;
	case 0xffff:
1321
          TRACE("class ordinal 0x%08x\n",*(const DWORD*)p);
1322 1323 1324
	  p += 2;
	  break;
	default:
1325 1326
	  TRACE("class %s\n",debugstr_w( p ));
	  p += lstrlenW( p ) + 1;
1327 1328
	  break;
	}
1329 1330

      /* check title text */
1331 1332 1333 1334 1335 1336
      switch ((WORD)*p)
	{
	case 0x0000:
	  p++;
	  break;
	case 0xffff:
1337
          TRACE("text ordinal 0x%08x\n",*(const DWORD*)p);
1338 1339 1340
	  p += 2;
	  break;
	default:
1341 1342
	  TRACE("text %s\n",debugstr_w( p ));
	  p += lstrlenW( p ) + 1;
1343 1344
	  break;
	}
1345
      p += *p / sizeof(WORD) + 1;    /* Skip extra data */
1346 1347 1348
      --nrofitems;
    }
  
1349
  ret = (p - (const WORD*)pTemplate) * sizeof(WORD);
1350 1351
  TRACE("%p %p size 0x%08x\n", p, pTemplate, ret);
  return ret;
1352
}
1353 1354 1355 1356

/******************************************************************************
 *            PROPSHEET_CreatePage
 *
1357
 * Creates a page.
1358
 */
1359
static BOOL PROPSHEET_CreatePage(HWND hwndParent,
1360
                                int index,
1361
                                const PropSheetInfo * psInfo,
1362
                                LPCPROPSHEETPAGEW ppshpage)
1363
{
1364
  const DLGTEMPLATE* pTemplate;
1365
  HWND hwndPage;
1366
  DWORD resSize;
1367
  DLGTEMPLATE* pTemplateCopy = NULL;
1368

1369
  TRACE("index %d\n", index);
1370

1371 1372 1373 1374 1375
  if (ppshpage == NULL)
  {
    return FALSE;
  }

1376
  if (ppshpage->dwFlags & PSP_DLGINDIRECT)
1377
    {
1378
      pTemplate = ppshpage->u.pResource;
1379 1380
      resSize = GetTemplateSize(pTemplate);
    }
1381
  else if(ppshpage->dwFlags & PSP_INTERNAL_UNICODE)
1382
  {
1383 1384 1385
    HRSRC hResource;
    HANDLE hTemplate;

1386
    hResource = FindResourceW(ppshpage->hInstance,
1387
                                    ppshpage->u.pszTemplate,
1388
                                    (LPWSTR)RT_DIALOG);
1389 1390 1391 1392 1393 1394 1395 1396 1397
    if(!hResource)
	return FALSE;

    resSize = SizeofResource(ppshpage->hInstance, hResource);

    hTemplate = LoadResource(ppshpage->hInstance, hResource);
    if(!hTemplate)
	return FALSE;

1398
    pTemplate = LockResource(hTemplate);
1399 1400 1401
    /*
     * Make a copy of the dialog template to make it writable
     */
1402
  }
1403 1404 1405 1406 1407 1408
  else
  {
    HRSRC hResource;
    HANDLE hTemplate;

    hResource = FindResourceA(ppshpage->hInstance,
1409
                                    (LPCSTR)ppshpage->u.pszTemplate,
1410
                                    (LPSTR)RT_DIALOG);
1411 1412 1413 1414 1415 1416 1417 1418 1419
    if(!hResource)
	return FALSE;

    resSize = SizeofResource(ppshpage->hInstance, hResource);

    hTemplate = LoadResource(ppshpage->hInstance, hResource);
    if(!hTemplate)
	return FALSE;

1420
    pTemplate = LockResource(hTemplate);
1421 1422 1423 1424
    /*
     * Make a copy of the dialog template to make it writable
     */
  }
1425 1426
  pTemplateCopy = Alloc(resSize);
  if (!pTemplateCopy)
1427 1428
    return FALSE;
  
1429 1430
  TRACE("copying pTemplate %p into pTemplateCopy %p (%d)\n", pTemplate, pTemplateCopy, resSize);
  memcpy(pTemplateCopy, pTemplate, resSize);
1431

1432
  if (((MyDLGTEMPLATEEX*)pTemplateCopy)->signature == 0xFFFF)
1433
  {
1434 1435 1436 1437 1438 1439 1440 1441 1442 1443
    ((MyDLGTEMPLATEEX*)pTemplateCopy)->style |= WS_CHILD | WS_TABSTOP | DS_CONTROL;
    ((MyDLGTEMPLATEEX*)pTemplateCopy)->style &= ~DS_MODALFRAME;
    ((MyDLGTEMPLATEEX*)pTemplateCopy)->style &= ~WS_CAPTION;
    ((MyDLGTEMPLATEEX*)pTemplateCopy)->style &= ~WS_SYSMENU;
    ((MyDLGTEMPLATEEX*)pTemplateCopy)->style &= ~WS_POPUP;
    ((MyDLGTEMPLATEEX*)pTemplateCopy)->style &= ~WS_DISABLED;
    ((MyDLGTEMPLATEEX*)pTemplateCopy)->style &= ~WS_VISIBLE;
    ((MyDLGTEMPLATEEX*)pTemplateCopy)->style &= ~WS_THICKFRAME;

    ((MyDLGTEMPLATEEX*)pTemplateCopy)->exStyle |= WS_EX_CONTROLPARENT;
1444 1445 1446
  }
  else
  {
1447 1448 1449 1450 1451 1452 1453 1454 1455 1456
    pTemplateCopy->style |= WS_CHILD | WS_TABSTOP | DS_CONTROL;
    pTemplateCopy->style &= ~DS_MODALFRAME;
    pTemplateCopy->style &= ~WS_CAPTION;
    pTemplateCopy->style &= ~WS_SYSMENU;
    pTemplateCopy->style &= ~WS_POPUP;
    pTemplateCopy->style &= ~WS_DISABLED;
    pTemplateCopy->style &= ~WS_VISIBLE;
    pTemplateCopy->style &= ~WS_THICKFRAME;

    pTemplateCopy->dwExtendedStyle |= WS_EX_CONTROLPARENT;
1457 1458 1459
  }

  if (psInfo->proppage[index].useCallback)
1460
    (*(ppshpage->pfnCallback))(0, PSPCB_CREATE,
1461
                               (LPPROPSHEETPAGEW)ppshpage);
1462

1463 1464
  if(ppshpage->dwFlags & PSP_INTERNAL_UNICODE)
     hwndPage = CreateDialogIndirectParamW(ppshpage->hInstance,
1465
					pTemplateCopy,
1466 1467 1468 1469 1470
					hwndParent,
					ppshpage->pfnDlgProc,
					(LPARAM)ppshpage);
  else
     hwndPage = CreateDialogIndirectParamA(ppshpage->hInstance,
1471
					pTemplateCopy,
1472 1473
					hwndParent,
					ppshpage->pfnDlgProc,
Marcus Meissner's avatar
Marcus Meissner committed
1474
					(LPARAM)ppshpage);
1475
  /* Free a no more needed copy */
1476
  Free(pTemplateCopy);
1477

1478 1479 1480
  if(!hwndPage)
      return FALSE;

1481
  psInfo->proppage[index].hwndPage = hwndPage;
1482

1483 1484 1485 1486 1487 1488 1489 1490
  /* Subclass exterior wizard pages */
  if((psInfo->ppshheader.dwFlags & (PSH_WIZARD97_NEW | PSH_WIZARD97_OLD)) &&
     (psInfo->ppshheader.dwFlags & PSH_WATERMARK) &&
     (ppshpage->dwFlags & PSP_HIDEHEADER))
  {
      SetWindowSubclass(hwndPage, PROPSHEET_WizardSubclassProc, 1,
                        (DWORD_PTR)ppshpage);
  }
1491 1492
  if (!(psInfo->ppshheader.dwFlags & INTRNL_ANY_WIZARD))
      EnableThemeDialogTexture (hwndPage, ETDT_ENABLETAB);
1493

1494 1495 1496
  return TRUE;
}

1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511
/******************************************************************************
 *            PROPSHEET_LoadWizardBitmaps
 *
 * Loads the watermark and header bitmaps for a wizard.
 */
static VOID PROPSHEET_LoadWizardBitmaps(PropSheetInfo *psInfo)
{
  if (psInfo->ppshheader.dwFlags & (PSH_WIZARD97_NEW | PSH_WIZARD97_OLD))
  {
    /* if PSH_USEHBMWATERMARK is not set, load the resource from pszbmWatermark 
       and put the HBITMAP in hbmWatermark. Thus all the rest of the code always 
       considers hbmWatermark as valid. */
    if ((psInfo->ppshheader.dwFlags & PSH_WATERMARK) &&
        !(psInfo->ppshheader.dwFlags & PSH_USEHBMWATERMARK))
    {
1512
      psInfo->ppshheader.u4.hbmWatermark =
Frank Richter's avatar
Frank Richter committed
1513
        CreateMappedBitmap(psInfo->ppshheader.hInstance, (INT_PTR)psInfo->ppshheader.u4.pszbmWatermark, 0, NULL, 0);
1514 1515 1516 1517 1518 1519
    }

    /* Same behavior as for watermarks */
    if ((psInfo->ppshheader.dwFlags & PSH_HEADER) &&
        !(psInfo->ppshheader.dwFlags & PSH_USEHBMHEADER))
    {
1520
      psInfo->ppshheader.u5.hbmHeader =
Frank Richter's avatar
Frank Richter committed
1521
        CreateMappedBitmap(psInfo->ppshheader.hInstance, (INT_PTR)psInfo->ppshheader.u5.pszbmHeader, 0, NULL, 0);
1522 1523 1524 1525 1526
    }
  }
}


1527 1528 1529 1530 1531 1532 1533
/******************************************************************************
 *            PROPSHEET_ShowPage
 *
 * Displays or creates the specified page.
 */
static BOOL PROPSHEET_ShowPage(HWND hwndDlg, int index, PropSheetInfo * psInfo)
{
1534
  HWND hwndTabCtrl;
1535
  HWND hwndLineHeader;
1536
  HWND control;
1537
  LPCPROPSHEETPAGEW ppshpage;
1538 1539

  TRACE("active_page %d, index %d\n", psInfo->active_page, index);
1540
  if (index == psInfo->active_page)
1541
  {
1542
      if (GetTopWindow(hwndDlg) != psInfo->proppage[index].hwndPage)
Alexandre Julliard's avatar
Alexandre Julliard committed
1543
          SetWindowPos(psInfo->proppage[index].hwndPage, HWND_TOP, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE);
1544 1545
      return TRUE;
  }
1546

1547
  ppshpage = (LPCPROPSHEETPAGEW)psInfo->proppage[index].hpage;
Alexandre Julliard's avatar
Alexandre Julliard committed
1548
  if (psInfo->proppage[index].hwndPage == 0)
1549
  {
Alexandre Julliard's avatar
Alexandre Julliard committed
1550
     PROPSHEET_CreatePage(hwndDlg, index, psInfo, ppshpage);
1551
  }
Alexandre Julliard's avatar
Alexandre Julliard committed
1552

1553
  if (psInfo->ppshheader.dwFlags & INTRNL_ANY_WIZARD)
1554 1555 1556
  {
     PROPSHEET_SetTitleW(hwndDlg, psInfo->ppshheader.dwFlags,
                         psInfo->proppage[index].pszText);
1557 1558 1559 1560

     control = GetNextDlgTabItem(psInfo->proppage[index].hwndPage, NULL, FALSE);
     if(control != NULL)
         SetFocus(control);
1561
  }
1562

1563 1564
  if (psInfo->active_page != -1)
     ShowWindow(psInfo->proppage[psInfo->active_page].hwndPage, SW_HIDE);
Alexandre Julliard's avatar
Alexandre Julliard committed
1565

1566
  ShowWindow(psInfo->proppage[index].hwndPage, SW_SHOW);
1567

1568 1569 1570
  /* Synchronize current selection with tab control
   * It seems to be needed even in case of PSH_WIZARD (no tab controls there) */
  hwndTabCtrl = GetDlgItem(hwndDlg, IDC_TABCONTROL);
1571
  SendMessageW(hwndTabCtrl, TCM_SETCURSEL, index, 0);
1572

1573
  psInfo->active_page = index;
Alexandre Julliard's avatar
Alexandre Julliard committed
1574
  psInfo->activeValid = TRUE;
1575

1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586
  if (psInfo->ppshheader.dwFlags & (PSH_WIZARD97_OLD | PSH_WIZARD97_NEW) )
  {
      hwndLineHeader = GetDlgItem(hwndDlg, IDC_SUNKEN_LINEHEADER);
      ppshpage = (LPCPROPSHEETPAGEW)psInfo->proppage[index].hpage;
      
      if ((ppshpage->dwFlags & PSP_HIDEHEADER) || (!(psInfo->ppshheader.dwFlags & PSH_HEADER)) )
	  ShowWindow(hwndLineHeader, SW_HIDE);
      else
	  ShowWindow(hwndLineHeader, SW_SHOW);
  }

1587 1588 1589
  return TRUE;
}

1590 1591 1592 1593 1594
/******************************************************************************
 *            PROPSHEET_Back
 */
static BOOL PROPSHEET_Back(HWND hwndDlg)
{
Alexandre Julliard's avatar
Alexandre Julliard committed
1595
  PSHNOTIFY psn;
1596
  HWND hwndPage;
1597
  PropSheetInfo* psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
1598
  LRESULT result;
1599
  int idx;
1600

1601
  TRACE("active_page %d\n", psInfo->active_page);
Alexandre Julliard's avatar
Alexandre Julliard committed
1602
  if (psInfo->active_page < 0)
1603 1604
     return FALSE;

Alexandre Julliard's avatar
Alexandre Julliard committed
1605 1606 1607 1608
  psn.hdr.code     = PSN_WIZBACK;
  psn.hdr.hwndFrom = hwndDlg;
  psn.hdr.idFrom   = 0;
  psn.lParam       = 0;
1609

1610 1611
  hwndPage = psInfo->proppage[psInfo->active_page].hwndPage;

1612
  result = SendMessageW(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn);
1613
  if (result == -1)
1614
    return FALSE;
1615 1616 1617 1618
  else if (result == 0)
     idx = psInfo->active_page - 1;
  else
     idx = PROPSHEET_FindPageByResId(psInfo, result);
1619

1620
  if (idx >= 0 && idx < psInfo->nPages)
1621
  {
1622
     if (PROPSHEET_CanSetCurSel(hwndDlg))
1623 1624 1625
     {
        SetFocus(GetDlgItem(hwndDlg, IDC_BACK_BUTTON));
        SendMessageW(hwndDlg, DM_SETDEFID, IDC_BACK_BUTTON, 0);
1626
        PROPSHEET_SetCurSel(hwndDlg, idx, -1, 0);
1627
     }
1628
  }
1629 1630 1631 1632 1633 1634 1635 1636
  return TRUE;
}

/******************************************************************************
 *            PROPSHEET_Next
 */
static BOOL PROPSHEET_Next(HWND hwndDlg)
{
Alexandre Julliard's avatar
Alexandre Julliard committed
1637
  PSHNOTIFY psn;
1638 1639
  HWND hwndPage;
  LRESULT msgResult = 0;
1640
  PropSheetInfo* psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
1641
  int idx;
1642

1643
  TRACE("active_page %d\n", psInfo->active_page);
Alexandre Julliard's avatar
Alexandre Julliard committed
1644
  if (psInfo->active_page < 0)
1645 1646
     return FALSE;

Alexandre Julliard's avatar
Alexandre Julliard committed
1647 1648 1649 1650
  psn.hdr.code     = PSN_WIZNEXT;
  psn.hdr.hwndFrom = hwndDlg;
  psn.hdr.idFrom   = 0;
  psn.lParam       = 0;
1651

1652 1653
  hwndPage = psInfo->proppage[psInfo->active_page].hwndPage;

1654
  msgResult = SendMessageW(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn);
1655 1656
  if (msgResult == -1)
    return FALSE;
1657 1658 1659 1660
  else if (msgResult == 0)
     idx = psInfo->active_page + 1;
  else
     idx = PROPSHEET_FindPageByResId(psInfo, msgResult);
1661

1662
  if (idx < psInfo->nPages )
1663
  {
1664
     if (PROPSHEET_CanSetCurSel(hwndDlg) != FALSE)
1665 1666 1667
     {
        SetFocus(GetDlgItem(hwndDlg, IDC_NEXT_BUTTON));
        SendMessageW(hwndDlg, DM_SETDEFID, IDC_NEXT_BUTTON, 0);
1668
        PROPSHEET_SetCurSel(hwndDlg, idx, 1, 0);
1669
     }
1670
  }
1671 1672 1673 1674 1675 1676 1677 1678 1679

  return TRUE;
}

/******************************************************************************
 *            PROPSHEET_Finish
 */
static BOOL PROPSHEET_Finish(HWND hwndDlg)
{
Alexandre Julliard's avatar
Alexandre Julliard committed
1680
  PSHNOTIFY psn;
1681 1682
  HWND hwndPage;
  LRESULT msgResult = 0;
1683
  PropSheetInfo* psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
1684

1685
  TRACE("active_page %d\n", psInfo->active_page);
1686 1687 1688
  if (psInfo->active_page < 0)
     return FALSE;

Alexandre Julliard's avatar
Alexandre Julliard committed
1689 1690 1691 1692
  psn.hdr.code     = PSN_WIZFINISH;
  psn.hdr.hwndFrom = hwndDlg;
  psn.hdr.idFrom   = 0;
  psn.lParam       = 0;
1693

1694 1695
  hwndPage = psInfo->proppage[psInfo->active_page].hwndPage;

1696
  msgResult = SendMessageW(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn);
1697 1698 1699 1700 1701 1702

  TRACE("msg result %ld\n", msgResult);

  if (msgResult != 0)
    return FALSE;

1703 1704
  if (psInfo->result == 0)
      psInfo->result = IDOK;
1705
  if (psInfo->isModeless)
Alexandre Julliard's avatar
Alexandre Julliard committed
1706
    psInfo->activeValid = FALSE;
1707
  else
1708
    psInfo->ended = TRUE;
1709 1710 1711 1712

  return TRUE;
}

1713 1714 1715
/******************************************************************************
 *            PROPSHEET_Apply
 */
Alexandre Julliard's avatar
Alexandre Julliard committed
1716
static BOOL PROPSHEET_Apply(HWND hwndDlg, LPARAM lParam)
1717 1718 1719
{
  int i;
  HWND hwndPage;
Alexandre Julliard's avatar
Alexandre Julliard committed
1720
  PSHNOTIFY psn;
1721
  PropSheetInfo* psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
1722

1723
  TRACE("active_page %d\n", psInfo->active_page);
1724 1725 1726
  if (psInfo->active_page < 0)
     return FALSE;

Alexandre Julliard's avatar
Alexandre Julliard committed
1727 1728 1729
  psn.hdr.hwndFrom = hwndDlg;
  psn.hdr.idFrom   = 0;
  psn.lParam       = 0;
1730

1731 1732 1733 1734

  /*
   * Send PSN_KILLACTIVE to the current page.
   */
Alexandre Julliard's avatar
Alexandre Julliard committed
1735
  psn.hdr.code = PSN_KILLACTIVE;
1736 1737 1738

  hwndPage = psInfo->proppage[psInfo->active_page].hwndPage;

1739
  if (SendMessageW(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn) != FALSE)
1740 1741 1742 1743 1744
    return FALSE;

  /*
   * Send PSN_APPLY to all pages.
   */
Alexandre Julliard's avatar
Alexandre Julliard committed
1745 1746
  psn.hdr.code = PSN_APPLY;
  psn.lParam   = lParam;
1747

1748
  for (i = 0; i < psInfo->nPages; i++)
1749 1750
  {
    hwndPage = psInfo->proppage[i].hwndPage;
Alexandre Julliard's avatar
Alexandre Julliard committed
1751 1752
    if (hwndPage)
    {
1753
       switch (SendMessageW(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn))
1754 1755 1756 1757 1758 1759 1760
       {
       case PSNRET_INVALID:
           PROPSHEET_ShowPage(hwndDlg, i, psInfo);
           /* fall through */
       case PSNRET_INVALID_NOCHANGEPAGE:
           return FALSE;
       }
Alexandre Julliard's avatar
Alexandre Julliard committed
1761 1762
    }
  }
1763

Alexandre Julliard's avatar
Alexandre Julliard committed
1764 1765 1766 1767 1768 1769 1770 1771 1772
  if(lParam)
  {
     psInfo->activeValid = FALSE;
  }
  else if(psInfo->active_page >= 0)
  {
     psn.hdr.code = PSN_SETACTIVE;
     psn.lParam   = 0;
     hwndPage = psInfo->proppage[psInfo->active_page].hwndPage;
1773
     SendMessageW(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn);
1774 1775 1776 1777 1778 1779 1780 1781
  }

  return TRUE;
}

/******************************************************************************
 *            PROPSHEET_Cancel
 */
Alexandre Julliard's avatar
Alexandre Julliard committed
1782
static void PROPSHEET_Cancel(HWND hwndDlg, LPARAM lParam)
1783
{
1784
  PropSheetInfo* psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
1785
  HWND hwndPage;
Alexandre Julliard's avatar
Alexandre Julliard committed
1786 1787
  PSHNOTIFY psn;
  int i;
1788

1789
  TRACE("active_page %d\n", psInfo->active_page);
1790 1791 1792 1793
  if (psInfo->active_page < 0)
     return;

  hwndPage = psInfo->proppage[psInfo->active_page].hwndPage;
Alexandre Julliard's avatar
Alexandre Julliard committed
1794 1795 1796 1797
  psn.hdr.code     = PSN_QUERYCANCEL;
  psn.hdr.hwndFrom = hwndDlg;
  psn.hdr.idFrom   = 0;
  psn.lParam       = 0;
1798

1799
  if (SendMessageW(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn))
1800 1801
    return;

Alexandre Julliard's avatar
Alexandre Julliard committed
1802 1803
  psn.hdr.code = PSN_RESET;
  psn.lParam   = lParam;
1804

Alexandre Julliard's avatar
Alexandre Julliard committed
1805 1806 1807
  for (i = 0; i < psInfo->nPages; i++)
  {
    hwndPage = psInfo->proppage[i].hwndPage;
1808

Alexandre Julliard's avatar
Alexandre Julliard committed
1809
    if (hwndPage)
1810
       SendMessageW(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn);
Alexandre Julliard's avatar
Alexandre Julliard committed
1811
  }
1812 1813

  if (psInfo->isModeless)
Alexandre Julliard's avatar
Alexandre Julliard committed
1814 1815 1816 1817
  {
     /* makes PSM_GETCURRENTPAGEHWND return NULL */
     psInfo->activeValid = FALSE;
  }
1818
  else
1819
    psInfo->ended = TRUE;
1820 1821
}

1822 1823 1824 1825 1826
/******************************************************************************
 *            PROPSHEET_Help
 */
static void PROPSHEET_Help(HWND hwndDlg)
{
1827
  PropSheetInfo* psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
1828
  HWND hwndPage;
Alexandre Julliard's avatar
Alexandre Julliard committed
1829
  PSHNOTIFY psn;
1830

1831
  TRACE("active_page %d\n", psInfo->active_page);
1832 1833 1834 1835
  if (psInfo->active_page < 0)
     return;

  hwndPage = psInfo->proppage[psInfo->active_page].hwndPage;
Alexandre Julliard's avatar
Alexandre Julliard committed
1836 1837 1838 1839
  psn.hdr.code     = PSN_HELP;
  psn.hdr.hwndFrom = hwndDlg;
  psn.hdr.idFrom   = 0;
  psn.lParam       = 0;
1840

1841
  SendMessageW(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn);
1842 1843
}

1844 1845 1846 1847 1848 1849
/******************************************************************************
 *            PROPSHEET_Changed
 */
static void PROPSHEET_Changed(HWND hwndDlg, HWND hwndDirtyPage)
{
  int i;
1850
  PropSheetInfo* psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
1851

1852
  TRACE("\n");
1853
  if (!psInfo) return;
1854 1855 1856
  /*
   * Set the dirty flag of this page.
   */
1857
  for (i = 0; i < psInfo->nPages; i++)
1858 1859 1860 1861
  {
    if (psInfo->proppage[i].hwndPage == hwndDirtyPage)
      psInfo->proppage[i].isDirty = TRUE;
  }
1862

1863 1864 1865 1866 1867 1868
  /*
   * Enable the Apply button.
   */
  if (psInfo->hasApply)
  {
    HWND hwndApplyBtn = GetDlgItem(hwndDlg, IDC_APPLY_BUTTON);
1869

1870 1871 1872
    EnableWindow(hwndApplyBtn, TRUE);
  }
}
1873

1874 1875 1876 1877 1878 1879 1880 1881
/******************************************************************************
 *            PROPSHEET_UnChanged
 */
static void PROPSHEET_UnChanged(HWND hwndDlg, HWND hwndCleanPage)
{
  int i;
  BOOL noPageDirty = TRUE;
  HWND hwndApplyBtn = GetDlgItem(hwndDlg, IDC_APPLY_BUTTON);
1882
  PropSheetInfo* psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
1883

1884
  TRACE("\n");
1885
  if ( !psInfo ) return;
1886
  for (i = 0; i < psInfo->nPages; i++)
1887 1888 1889 1890
  {
    /* set the specified page as clean */
    if (psInfo->proppage[i].hwndPage == hwndCleanPage)
      psInfo->proppage[i].isDirty = FALSE;
1891

1892 1893 1894 1895
    /* look to see if there's any dirty pages */
    if (psInfo->proppage[i].isDirty)
      noPageDirty = FALSE;
  }
1896

1897 1898 1899 1900 1901 1902
  /*
   * Disable Apply button.
   */
  if (noPageDirty)
    EnableWindow(hwndApplyBtn, FALSE);
}
1903

1904 1905 1906 1907 1908
/******************************************************************************
 *            PROPSHEET_PressButton
 */
static void PROPSHEET_PressButton(HWND hwndDlg, int buttonID)
{
1909
  TRACE("buttonID %d\n", buttonID);
1910 1911 1912
  switch (buttonID)
  {
    case PSBTN_APPLYNOW:
1913
      PROPSHEET_DoCommand(hwndDlg, IDC_APPLY_BUTTON);
1914 1915
      break;
    case PSBTN_BACK:
1916
      PROPSHEET_Back(hwndDlg);
1917 1918
      break;
    case PSBTN_CANCEL:
1919
      PROPSHEET_DoCommand(hwndDlg, IDCANCEL);
1920 1921
      break;
    case PSBTN_FINISH:
1922
      PROPSHEET_Finish(hwndDlg);
1923 1924
      break;
    case PSBTN_HELP:
1925
      PROPSHEET_DoCommand(hwndDlg, IDHELP);
1926 1927
      break;
    case PSBTN_NEXT:
1928
      PROPSHEET_Next(hwndDlg);
1929 1930
      break;
    case PSBTN_OK:
1931
      PROPSHEET_DoCommand(hwndDlg, IDOK);
1932 1933
      break;
    default:
1934
      FIXME("Invalid button index %d\n", buttonID);
1935 1936
  }
}
1937

1938 1939

/*************************************************************************
1940
 * BOOL PROPSHEET_CanSetCurSel [Internal]
1941
 *
1942
 * Test whether the current page can be changed by sending a PSN_KILLACTIVE
1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953
 *
 * PARAMS
 *     hwndDlg        [I] handle to a Dialog hWnd
 *
 * RETURNS
 *     TRUE if Current Selection can change
 *
 * NOTES
 */
static BOOL PROPSHEET_CanSetCurSel(HWND hwndDlg)
{
1954
  PropSheetInfo* psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
1955
  HWND hwndPage;
Alexandre Julliard's avatar
Alexandre Julliard committed
1956
  PSHNOTIFY psn;
1957
  BOOL res = FALSE;
1958

Alexandre Julliard's avatar
Alexandre Julliard committed
1959
  if (!psInfo)
1960 1961 1962 1963
  {
     res = FALSE;
     goto end;
  }
Alexandre Julliard's avatar
Alexandre Julliard committed
1964

1965
  TRACE("active_page %d\n", psInfo->active_page);
Alexandre Julliard's avatar
Alexandre Julliard committed
1966
  if (psInfo->active_page < 0)
1967 1968 1969 1970
  {
     res = TRUE;
     goto end;
  }
Alexandre Julliard's avatar
Alexandre Julliard committed
1971

1972 1973 1974 1975
  /*
   * Notify the current page.
   */
  hwndPage = psInfo->proppage[psInfo->active_page].hwndPage;
Alexandre Julliard's avatar
Alexandre Julliard committed
1976 1977 1978 1979
  psn.hdr.code     = PSN_KILLACTIVE;
  psn.hdr.hwndFrom = hwndDlg;
  psn.hdr.idFrom   = 0;
  psn.lParam       = 0;
1980

1981
  res = !SendMessageW(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn);
1982 1983 1984 1985

end:
  TRACE("<-- %d\n", res);
  return res;
1986 1987
}

1988 1989 1990 1991 1992
/******************************************************************************
 *            PROPSHEET_SetCurSel
 */
static BOOL PROPSHEET_SetCurSel(HWND hwndDlg,
                                int index,
1993 1994 1995
				int skipdir,
                                HPROPSHEETPAGE hpage
				)
1996
{
1997
  PropSheetInfo* psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
1998
  HWND hwndHelp  = GetDlgItem(hwndDlg, IDHELP);
1999
  HWND hwndTabControl = GetDlgItem(hwndDlg, IDC_TABCONTROL);
2000

2001
  TRACE("index %d, skipdir %d, hpage %p\n", index, skipdir, hpage);
Alexandre Julliard's avatar
Alexandre Julliard committed
2002
  /* hpage takes precedence over index */
2003
  if (hpage != NULL)
Thuy Nguyen's avatar
Thuy Nguyen committed
2004 2005
    index = PROPSHEET_GetPageIndex(hpage, psInfo);

2006 2007 2008 2009
  if (index < 0 || index >= psInfo->nPages)
  {
    TRACE("Could not find page to select!\n");
    return FALSE;
Thuy Nguyen's avatar
Thuy Nguyen committed
2010 2011
  }

2012 2013 2014 2015 2016
  /* unset active page while doing this transition. */
  if (psInfo->active_page != -1)
     ShowWindow(psInfo->proppage[psInfo->active_page].hwndPage, SW_HIDE);
  psInfo->active_page = -1;

2017
  while (1) {
2018 2019
    int result;
    PSHNOTIFY psn;
2020
    RECT rc;
Filip Navara's avatar
Filip Navara committed
2021
    LPCPROPSHEETPAGEW ppshpage = (LPCPROPSHEETPAGEW)psInfo->proppage[index].hpage;
2022

2023 2024 2025
    if (hwndTabControl)
	SendMessageW(hwndTabControl, TCM_SETCURSEL, index, 0);

2026 2027 2028 2029 2030
    psn.hdr.code     = PSN_SETACTIVE;
    psn.hdr.hwndFrom = hwndDlg;
    psn.hdr.idFrom   = 0;
    psn.lParam       = 0;

2031
    if (!psInfo->proppage[index].hwndPage) {
2032 2033 2034 2035 2036 2037 2038 2039
      if(!PROPSHEET_CreatePage(hwndDlg, index, psInfo, ppshpage)) {
        PROPSHEET_RemovePage(hwndDlg, index, NULL);
        if(index >= psInfo->nPages)
          index--;
        if(index < 0)
            return FALSE;
        continue;
      }
2040
    }
2041

Filip Navara's avatar
Filip Navara committed
2042 2043 2044 2045
    /* Resize the property sheet page to the fit in the Tab control
     * (for regular property sheets) or to fit in the client area (for
     * wizards).
     * NOTE: The resizing happens every time the page is selected and
2046
     * not only when it's created (some applications depend on it). */
Filip Navara's avatar
Filip Navara committed
2047
    PROPSHEET_GetPageRect(psInfo, hwndDlg, &rc, ppshpage);
2048 2049
    TRACE("setting page %p, rc (%s) w=%d, h=%d\n",
          psInfo->proppage[index].hwndPage, wine_dbgstr_rect(&rc),
Filip Navara's avatar
Filip Navara committed
2050 2051 2052 2053
          rc.right - rc.left, rc.bottom - rc.top);
    SetWindowPos(psInfo->proppage[index].hwndPage, HWND_TOP,
                 rc.left, rc.top,
                 rc.right - rc.left, rc.bottom - rc.top, 0);
2054

2055
    result = SendMessageW(psInfo->proppage[index].hwndPage, WM_NOTIFY, 0, (LPARAM) &psn);
2056 2057 2058 2059 2060 2061
    if (!result)
      break;
    if (result == -1) {
      index+=skipdir;
      if (index < 0) {
	index = 0;
2062
	WARN("Tried to skip before first property sheet page!\n");
2063 2064 2065
	break;
      }
      if (index >= psInfo->nPages) {
2066
	WARN("Tried to skip after last property sheet page!\n");
2067 2068 2069 2070
	index = psInfo->nPages-1;
	break;
      }
    }
2071 2072
    else if (result != 0)
    {
2073 2074 2075 2076
      int old_index = index;
      index = PROPSHEET_FindPageByResId(psInfo, result);
      if(index >= psInfo->nPages) {
        index = old_index;
2077
        WARN("Tried to skip to nonexistent page by res id\n");
2078 2079 2080
        break;
      }
      continue;
2081
    }
2082
  }
2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097

  /* Invalidate the header area */
  if ( (psInfo->ppshheader.dwFlags & (PSH_WIZARD97_OLD | PSH_WIZARD97_NEW)) &&
       (psInfo->ppshheader.dwFlags & PSH_HEADER) )
  {
    HWND hwndLineHeader = GetDlgItem(hwndDlg, IDC_SUNKEN_LINEHEADER);
    RECT r;

    GetClientRect(hwndLineHeader, &r);
    MapWindowPoints(hwndLineHeader, hwndDlg, (LPPOINT) &r, 2);
    SetRect(&r, 0, 0, r.right + 1, r.top - 1);

    InvalidateRect(hwndDlg, &r, TRUE);
  }

2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110
  /*
   * Display the new page.
   */
  PROPSHEET_ShowPage(hwndDlg, index, psInfo);

  if (psInfo->proppage[index].hasHelp)
    EnableWindow(hwndHelp, TRUE);
  else
    EnableWindow(hwndHelp, FALSE);

  return TRUE;
}

2111 2112 2113 2114 2115 2116 2117 2118
/******************************************************************************
 *            PROPSHEET_SetCurSelId
 *
 * Selects the page, specified by resource id.
 */
static void PROPSHEET_SetCurSelId(HWND hwndDlg, int id)
{
      int idx;
2119
      PropSheetInfo* psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
2120 2121 2122 2123 2124 2125 2126 2127 2128

      idx = PROPSHEET_FindPageByResId(psInfo, id);
      if (idx < psInfo->nPages )
      {
          if (PROPSHEET_CanSetCurSel(hwndDlg) != FALSE)
              PROPSHEET_SetCurSel(hwndDlg, idx, 1, 0);
      }
}

2129 2130 2131 2132 2133
/******************************************************************************
 *            PROPSHEET_SetTitleA
 */
static void PROPSHEET_SetTitleA(HWND hwndDlg, DWORD dwStyle, LPCSTR lpszText)
{
2134
  if(!IS_INTRESOURCE(lpszText))
2135 2136
  {
     WCHAR szTitle[256];
2137
     MultiByteToWideChar(CP_ACP, 0, lpszText, -1,
2138
                         szTitle, sizeof(szTitle)/sizeof(WCHAR));
2139 2140 2141 2142 2143 2144 2145
     PROPSHEET_SetTitleW(hwndDlg, dwStyle, szTitle);
  }
  else
  {
     PROPSHEET_SetTitleW(hwndDlg, dwStyle, (LPCWSTR)lpszText);
  }
}
2146

2147 2148 2149 2150 2151
/******************************************************************************
 *            PROPSHEET_SetTitleW
 */
static void PROPSHEET_SetTitleW(HWND hwndDlg, DWORD dwStyle, LPCWSTR lpszText)
{
2152 2153
  PropSheetInfo* psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
  WCHAR szTitle[256];
2154

2155
  TRACE("%s (style %08x)\n", debugstr_w(lpszText), dwStyle);
2156
  if (IS_INTRESOURCE(lpszText)) {
2157
    if (!LoadStringW(psInfo->ppshheader.hInstance,
2158
                     LOWORD(lpszText), szTitle, sizeof(szTitle)/sizeof(szTitle[0])))
2159 2160 2161
      return;
    lpszText = szTitle;
  }
2162 2163
  if (dwStyle & PSH_PROPTITLE)
  {
2164 2165 2166
    WCHAR* dest;
    int lentitle = strlenW(lpszText);
    int lenprop  = strlenW(psInfo->strPropertiesFor);
2167

2168
    dest = Alloc( (lentitle + lenprop + 1)*sizeof (WCHAR));
2169
    wsprintfW(dest, psInfo->strPropertiesFor, lpszText);
2170

2171
    SetWindowTextW(hwndDlg, dest);
2172
    Free(dest);
2173 2174
  }
  else
2175
    SetWindowTextW(hwndDlg, lpszText);
2176 2177
}

2178 2179 2180 2181 2182
/******************************************************************************
 *            PROPSHEET_SetFinishTextA
 */
static void PROPSHEET_SetFinishTextA(HWND hwndDlg, LPCSTR lpszText)
{
2183
  PropSheetInfo* psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
2184 2185
  HWND hwndButton = GetDlgItem(hwndDlg, IDC_FINISH_BUTTON);

2186
  TRACE("'%s'\n", lpszText);
2187 2188 2189 2190 2191 2192
  /* Set text, show and enable the Finish button */
  SetWindowTextA(hwndButton, lpszText);
  ShowWindow(hwndButton, SW_SHOW);
  EnableWindow(hwndButton, TRUE);

  /* Make it default pushbutton */
2193
  SendMessageW(hwndDlg, DM_SETDEFID, IDC_FINISH_BUTTON, 0);
2194 2195 2196 2197 2198

  /* Hide Back button */
  hwndButton = GetDlgItem(hwndDlg, IDC_BACK_BUTTON);
  ShowWindow(hwndButton, SW_HIDE);

2199 2200 2201 2202 2203 2204
  if (!psInfo->hasFinish)
  {
    /* Hide Next button */
    hwndButton = GetDlgItem(hwndDlg, IDC_NEXT_BUTTON);
    ShowWindow(hwndButton, SW_HIDE);
  }
2205 2206
}

2207 2208 2209 2210 2211
/******************************************************************************
 *            PROPSHEET_SetFinishTextW
 */
static void PROPSHEET_SetFinishTextW(HWND hwndDlg, LPCWSTR lpszText)
{
2212
  PropSheetInfo* psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
2213 2214
  HWND hwndButton = GetDlgItem(hwndDlg, IDC_FINISH_BUTTON);

2215
  TRACE("%s\n", debugstr_w(lpszText));
2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227
  /* Set text, show and enable the Finish button */
  SetWindowTextW(hwndButton, lpszText);
  ShowWindow(hwndButton, SW_SHOW);
  EnableWindow(hwndButton, TRUE);

  /* Make it default pushbutton */
  SendMessageW(hwndDlg, DM_SETDEFID, IDC_FINISH_BUTTON, 0);

  /* Hide Back button */
  hwndButton = GetDlgItem(hwndDlg, IDC_BACK_BUTTON);
  ShowWindow(hwndButton, SW_HIDE);

2228 2229 2230 2231 2232 2233
  if (!psInfo->hasFinish)
  {
    /* Hide Next button */
    hwndButton = GetDlgItem(hwndDlg, IDC_NEXT_BUTTON);
    ShowWindow(hwndButton, SW_HIDE);
  }
2234 2235
}

2236 2237 2238 2239 2240 2241 2242 2243 2244
/******************************************************************************
 *            PROPSHEET_QuerySiblings
 */
static LRESULT PROPSHEET_QuerySiblings(HWND hwndDlg,
                                       WPARAM wParam, LPARAM lParam)
{
  int i = 0;
  HWND hwndPage;
  LRESULT msgResult = 0;
2245
  PropSheetInfo* psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
2246

2247
  while ((i < psInfo->nPages) && (msgResult == 0))
2248 2249
  {
    hwndPage = psInfo->proppage[i].hwndPage;
2250
    msgResult = SendMessageW(hwndPage, PSM_QUERYSIBLINGS, wParam, lParam);
2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263
    i++;
  }

  return msgResult;
}


/******************************************************************************
 *            PROPSHEET_AddPage
 */
static BOOL PROPSHEET_AddPage(HWND hwndDlg,
                              HPROPSHEETPAGE hpage)
{
2264
  PropPageInfo * ppi;
2265
  PropSheetInfo * psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
2266
  HWND hwndTabControl = GetDlgItem(hwndDlg, IDC_TABCONTROL);
2267 2268
  TCITEMW item;
  LPCPROPSHEETPAGEW ppsp = (LPCPROPSHEETPAGEW)hpage;
2269

2270
  TRACE("hpage %p\n", hpage);
2271 2272 2273
  /*
   * Allocate and fill in a new PropPageInfo entry.
   */
2274
  ppi = ReAlloc(psInfo->proppage, sizeof(PropPageInfo) * (psInfo->nPages + 1));
2275 2276 2277 2278
  if (!ppi)
      return FALSE;

  psInfo->proppage = ppi;
2279
  if (!PROPSHEET_CollectPageInfo(ppsp, psInfo, psInfo->nPages, FALSE))
2280
      return FALSE;
2281

2282 2283
  psInfo->proppage[psInfo->nPages].hpage = hpage;

Alexandre Julliard's avatar
Alexandre Julliard committed
2284 2285 2286
  if (ppsp->dwFlags & PSP_PREMATURE)
  {
     /* Create the page but don't show it */
2287 2288
     if(!PROPSHEET_CreatePage(hwndDlg, psInfo->nPages, psInfo, ppsp))
         return FALSE;
Alexandre Julliard's avatar
Alexandre Julliard committed
2289
  }
2290 2291 2292 2293 2294

  /*
   * Add a new tab to the tab control.
   */
  item.mask = TCIF_TEXT;
2295
  item.pszText = (LPWSTR) psInfo->proppage[psInfo->nPages].pszText;
2296 2297
  item.cchTextMax = MAX_TABTEXT_LENGTH;

2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308
  if (psInfo->hImageList)
  {
    SendMessageW(hwndTabControl, TCM_SETIMAGELIST, 0, (LPARAM)psInfo->hImageList);
  }

  if ( psInfo->proppage[psInfo->nPages].hasIcon )
  {
    item.mask |= TCIF_IMAGE;
    item.iImage = psInfo->nPages;
  }

2309
  SendMessageW(hwndTabControl, TCM_INSERTITEMW, psInfo->nPages + 1,
2310 2311 2312 2313
               (LPARAM)&item);

  psInfo->nPages++;

Alexandre Julliard's avatar
Alexandre Julliard committed
2314 2315
  /* If it is the only page - show it */
  if(psInfo->nPages == 1)
2316
     PROPSHEET_SetCurSel(hwndDlg, 0, 1, 0);
2317
  return TRUE;
2318 2319 2320 2321 2322 2323 2324 2325 2326
}

/******************************************************************************
 *            PROPSHEET_RemovePage
 */
static BOOL PROPSHEET_RemovePage(HWND hwndDlg,
                                 int index,
                                 HPROPSHEETPAGE hpage)
{
2327
  PropSheetInfo * psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
2328
  HWND hwndTabControl = GetDlgItem(hwndDlg, IDC_TABCONTROL);
2329
  PropPageInfo* oldPages;
2330

2331
  TRACE("index %d, hpage %p\n", index, hpage);
2332 2333 2334
  if (!psInfo) {
    return FALSE;
  }
2335 2336 2337 2338 2339 2340
  /*
   * hpage takes precedence over index.
   */
  if (hpage != 0)
  {
    index = PROPSHEET_GetPageIndex(hpage, psInfo);
2341
  }
2342

2343
  /* Make sure that index is within range */
2344
  if (index < 0 || index >= psInfo->nPages)
Alexandre Julliard's avatar
Alexandre Julliard committed
2345
  {
2346
      TRACE("Could not find page to remove!\n");
2347
      return FALSE;
Alexandre Julliard's avatar
Alexandre Julliard committed
2348
  }
2349

2350
  TRACE("total pages %d removing page %d active page %d\n",
2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361
        psInfo->nPages, index, psInfo->active_page);
  /*
   * Check if we're removing the active page.
   */
  if (index == psInfo->active_page)
  {
    if (psInfo->nPages > 1)
    {
      if (index > 0)
      {
        /* activate previous page  */
2362
        PROPSHEET_SetCurSel(hwndDlg, index - 1, -1, 0);
2363 2364 2365 2366
      }
      else
      {
        /* activate the next page */
2367
        PROPSHEET_SetCurSel(hwndDlg, index + 1, 1, 0);
2368
        psInfo->active_page = index;
2369 2370 2371 2372
      }
    }
    else
    {
Alexandre Julliard's avatar
Alexandre Julliard committed
2373 2374 2375
      psInfo->active_page = -1;
      if (!psInfo->isModeless)
      {
2376
         psInfo->ended = TRUE;
Alexandre Julliard's avatar
Alexandre Julliard committed
2377 2378
         return TRUE;
      }
2379 2380
    }
  }
Alexandre Julliard's avatar
Alexandre Julliard committed
2381
  else if (index < psInfo->active_page)
2382 2383
    psInfo->active_page--;

2384 2385 2386 2387 2388 2389 2390 2391 2392
  /* Unsubclass the page dialog window */
  if((psInfo->ppshheader.dwFlags & (PSH_WIZARD97_NEW | PSH_WIZARD97_OLD) &&
     (psInfo->ppshheader.dwFlags & PSH_WATERMARK) &&
     ((PROPSHEETPAGEW*)psInfo->proppage[index].hpage)->dwFlags & PSP_HIDEHEADER))
  {
     RemoveWindowSubclass(psInfo->proppage[index].hwndPage,
                          PROPSHEET_WizardSubclassProc, 1);
  }

Alexandre Julliard's avatar
Alexandre Julliard committed
2393 2394 2395 2396 2397 2398
  /* Destroy page dialog window */
  DestroyWindow(psInfo->proppage[index].hwndPage);

  /* Free page resources */
  if(psInfo->proppage[index].hpage)
  {
2399
     PROPSHEETPAGEW* psp = (PROPSHEETPAGEW*)psInfo->proppage[index].hpage;
Alexandre Julliard's avatar
Alexandre Julliard committed
2400

2401
     if (psp->dwFlags & PSP_USETITLE)
2402
        Free ((LPVOID)psInfo->proppage[index].pszText);
Alexandre Julliard's avatar
Alexandre Julliard committed
2403 2404 2405

     DestroyPropertySheetPage(psInfo->proppage[index].hpage);
  }
2406

2407
  /* Remove the tab */
2408
  SendMessageW(hwndTabControl, TCM_DELETEITEM, index, 0);
2409

2410
  oldPages = psInfo->proppage;
2411
  psInfo->nPages--;
2412
  psInfo->proppage = Alloc(sizeof(PropPageInfo) * psInfo->nPages);
2413

2414
  if (index > 0)
2415 2416 2417 2418 2419 2420
    memcpy(&psInfo->proppage[0], &oldPages[0], index * sizeof(PropPageInfo));

  if (index < psInfo->nPages)
    memcpy(&psInfo->proppage[index], &oldPages[index + 1],
           (psInfo->nPages - index) * sizeof(PropPageInfo));

2421
  Free(oldPages);
2422

2423 2424 2425
  return FALSE;
}

2426 2427 2428 2429 2430 2431 2432 2433 2434 2435
/******************************************************************************
 *            PROPSHEET_SetWizButtons
 *
 * This code will work if (and assumes that) the Next button is on top of the
 * Finish button. ie. Finish comes after Next in the Z order.
 * This means make sure the dialog template reflects this.
 *
 */
static void PROPSHEET_SetWizButtons(HWND hwndDlg, DWORD dwFlags)
{
2436
  PropSheetInfo* psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
Alexandre Julliard's avatar
Alexandre Julliard committed
2437 2438 2439
  HWND hwndBack   = GetDlgItem(hwndDlg, IDC_BACK_BUTTON);
  HWND hwndNext   = GetDlgItem(hwndDlg, IDC_NEXT_BUTTON);
  HWND hwndFinish = GetDlgItem(hwndDlg, IDC_FINISH_BUTTON);
2440

2441
  TRACE("%d\n", dwFlags);
2442

Alexandre Julliard's avatar
Alexandre Julliard committed
2443 2444 2445 2446
  EnableWindow(hwndBack, FALSE);
  EnableWindow(hwndNext, FALSE);
  EnableWindow(hwndFinish, FALSE);

2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457
  /* set the default pushbutton to an enabled button */
  if (((dwFlags & PSWIZB_FINISH) || psInfo->hasFinish) && !(dwFlags & PSWIZB_DISABLEDFINISH))
    SendMessageW(hwndDlg, DM_SETDEFID, IDC_FINISH_BUTTON, 0);
  else if (dwFlags & PSWIZB_NEXT)
    SendMessageW(hwndDlg, DM_SETDEFID, IDC_NEXT_BUTTON, 0);
  else if (dwFlags & PSWIZB_BACK)
    SendMessageW(hwndDlg, DM_SETDEFID, IDC_BACK_BUTTON, 0);
  else
    SendMessageW(hwndDlg, DM_SETDEFID, IDCANCEL, 0);


2458
  if (dwFlags & PSWIZB_BACK)
Alexandre Julliard's avatar
Alexandre Julliard committed
2459
    EnableWindow(hwndBack, TRUE);
2460 2461

  if (dwFlags & PSWIZB_NEXT)
Alexandre Julliard's avatar
Alexandre Julliard committed
2462
    EnableWindow(hwndNext, TRUE);
2463

2464
  if (!psInfo->hasFinish)
2465
  {
2466 2467 2468 2469 2470 2471 2472
    if ((dwFlags & PSWIZB_FINISH) || (dwFlags & PSWIZB_DISABLEDFINISH))
    {
      /* Hide the Next button */
      ShowWindow(hwndNext, SW_HIDE);
      
      /* Show the Finish button */
      ShowWindow(hwndFinish, SW_SHOW);
2473

2474 2475 2476
      if (!(dwFlags & PSWIZB_DISABLEDFINISH))
        EnableWindow(hwndFinish, TRUE);
    }
2477 2478 2479 2480 2481 2482 2483
    else
    {
      /* Hide the Finish button */
      ShowWindow(hwndFinish, SW_HIDE);
      /* Show the Next button */
      ShowWindow(hwndNext, SW_SHOW);
    }
2484
  }
2485 2486
  else if (!(dwFlags & PSWIZB_DISABLEDFINISH))
    EnableWindow(hwndFinish, TRUE);
2487 2488
}

2489 2490 2491 2492 2493
/******************************************************************************
 *            PROPSHEET_InsertPage
 */
static BOOL PROPSHEET_InsertPage(HWND hwndDlg, HPROPSHEETPAGE hpageInsertAfter, HPROPSHEETPAGE hpage)
{
2494
    if (IS_INTRESOURCE(hpageInsertAfter))
2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537
        FIXME("(%p, %d, %p): stub\n", hwndDlg, LOWORD(hpageInsertAfter), hpage);
    else
        FIXME("(%p, %p, %p): stub\n", hwndDlg, hpageInsertAfter, hpage);
    return FALSE;
}

/******************************************************************************
 *            PROPSHEET_SetHeaderTitleW
 */
static void PROPSHEET_SetHeaderTitleW(HWND hwndDlg, int iPageIndex, LPCWSTR pszHeaderTitle)
{
    FIXME("(%p, %d, %s): stub\n", hwndDlg, iPageIndex, debugstr_w(pszHeaderTitle));
}

/******************************************************************************
 *            PROPSHEET_SetHeaderTitleA
 */
static void PROPSHEET_SetHeaderTitleA(HWND hwndDlg, int iPageIndex, LPCSTR pszHeaderTitle)
{
    FIXME("(%p, %d, %s): stub\n", hwndDlg, iPageIndex, debugstr_a(pszHeaderTitle));
}

/******************************************************************************
 *            PROPSHEET_SetHeaderSubTitleW
 */
static void PROPSHEET_SetHeaderSubTitleW(HWND hwndDlg, int iPageIndex, LPCWSTR pszHeaderSubTitle)
{
    FIXME("(%p, %d, %s): stub\n", hwndDlg, iPageIndex, debugstr_w(pszHeaderSubTitle));
}

/******************************************************************************
 *            PROPSHEET_SetHeaderSubTitleA
 */
static void PROPSHEET_SetHeaderSubTitleA(HWND hwndDlg, int iPageIndex, LPCSTR pszHeaderSubTitle)
{
    FIXME("(%p, %d, %s): stub\n", hwndDlg, iPageIndex, debugstr_a(pszHeaderSubTitle));
}

/******************************************************************************
 *            PROPSHEET_HwndToIndex
 */
static LRESULT PROPSHEET_HwndToIndex(HWND hwndDlg, HWND hPageDlg)
{
2538
    int index;
2539
    PropSheetInfo * psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
2540 2541 2542 2543 2544 2545 2546

    TRACE("(%p, %p)\n", hwndDlg, hPageDlg);

    for (index = 0; index < psInfo->nPages; index++)
        if (psInfo->proppage[index].hwndPage == hPageDlg)
            return index;
    WARN("%p not found\n", hPageDlg);
2547 2548 2549 2550 2551 2552 2553 2554
    return -1;
}

/******************************************************************************
 *            PROPSHEET_IndexToHwnd
 */
static LRESULT PROPSHEET_IndexToHwnd(HWND hwndDlg, int iPageIndex)
{
2555
    PropSheetInfo * psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
2556
    TRACE("(%p, %d)\n", hwndDlg, iPageIndex);
2557 2558
    if (!psInfo)
        return 0;
2559 2560 2561 2562 2563
    if (iPageIndex<0 || iPageIndex>=psInfo->nPages) {
        WARN("%d out of range.\n", iPageIndex);
	return 0;
    }
    return (LRESULT)psInfo->proppage[iPageIndex].hwndPage;
2564 2565 2566 2567 2568 2569 2570
}

/******************************************************************************
 *            PROPSHEET_PageToIndex
 */
static LRESULT PROPSHEET_PageToIndex(HWND hwndDlg, HPROPSHEETPAGE hPage)
{
2571
    int index;
2572
    PropSheetInfo * psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
2573 2574 2575 2576 2577 2578 2579

    TRACE("(%p, %p)\n", hwndDlg, hPage);

    for (index = 0; index < psInfo->nPages; index++)
        if (psInfo->proppage[index].hpage == hPage)
            return index;
    WARN("%p not found\n", hPage);
2580 2581 2582 2583 2584 2585 2586 2587
    return -1;
}

/******************************************************************************
 *            PROPSHEET_IndexToPage
 */
static LRESULT PROPSHEET_IndexToPage(HWND hwndDlg, int iPageIndex)
{
2588
    PropSheetInfo * psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
2589 2590 2591 2592 2593 2594
    TRACE("(%p, %d)\n", hwndDlg, iPageIndex);
    if (iPageIndex<0 || iPageIndex>=psInfo->nPages) {
        WARN("%d out of range.\n", iPageIndex);
	return 0;
    }
    return (LRESULT)psInfo->proppage[iPageIndex].hpage;
2595 2596 2597 2598 2599 2600 2601
}

/******************************************************************************
 *            PROPSHEET_IdToIndex
 */
static LRESULT PROPSHEET_IdToIndex(HWND hwndDlg, int iPageId)
{
2602 2603
    int index;
    LPCPROPSHEETPAGEW psp;
2604
    PropSheetInfo * psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
2605 2606 2607
    TRACE("(%p, %d)\n", hwndDlg, iPageId);
    for (index = 0; index < psInfo->nPages; index++) {
        psp = (LPCPROPSHEETPAGEW)psInfo->proppage[index].hpage;
Frank Richter's avatar
Frank Richter committed
2608
        if (psp->u.pszTemplate == MAKEINTRESOURCEW(iPageId))
2609 2610 2611
            return index;
    }

2612 2613 2614 2615 2616 2617 2618 2619
    return -1;
}

/******************************************************************************
 *            PROPSHEET_IndexToId
 */
static LRESULT PROPSHEET_IndexToId(HWND hwndDlg, int iPageIndex)
{
2620
    PropSheetInfo * psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
2621 2622 2623 2624 2625 2626 2627
    LPCPROPSHEETPAGEW psp;
    TRACE("(%p, %d)\n", hwndDlg, iPageIndex);
    if (iPageIndex<0 || iPageIndex>=psInfo->nPages) {
        WARN("%d out of range.\n", iPageIndex);
	return 0;
    }
    psp = (LPCPROPSHEETPAGEW)psInfo->proppage[iPageIndex].hpage;
2628
    if (psp->dwFlags & PSP_DLGINDIRECT || !IS_INTRESOURCE(psp->u.pszTemplate)) {
2629 2630 2631
        return 0;
    }
    return (LRESULT)psp->u.pszTemplate;
2632 2633 2634 2635 2636 2637 2638
}

/******************************************************************************
 *            PROPSHEET_GetResult
 */
static LRESULT PROPSHEET_GetResult(HWND hwndDlg)
{
2639
    PropSheetInfo * psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
2640
    return psInfo->result;
2641 2642 2643 2644 2645 2646 2647 2648 2649 2650 2651
}

/******************************************************************************
 *            PROPSHEET_RecalcPageSizes
 */
static BOOL PROPSHEET_RecalcPageSizes(HWND hwndDlg)
{
    FIXME("(%p): stub\n", hwndDlg);
    return FALSE;
}

2652 2653 2654 2655 2656 2657
/******************************************************************************
 *            PROPSHEET_GetPageIndex
 *
 * Given a HPROPSHEETPAGE, returns the index of the corresponding page from
 * the array of PropPageInfo.
 */
2658
static int PROPSHEET_GetPageIndex(HPROPSHEETPAGE hpage, const PropSheetInfo* psInfo)
2659 2660 2661 2662
{
  BOOL found = FALSE;
  int index = 0;

2663
  TRACE("hpage %p\n", hpage);
2664 2665 2666 2667 2668 2669 2670 2671 2672 2673 2674 2675 2676 2677
  while ((index < psInfo->nPages) && (found == FALSE))
  {
    if (psInfo->proppage[index].hpage == hpage)
      found = TRUE;
    else
      index++;
  }

  if (found == FALSE)
    index = -1;

  return index;
}

2678 2679 2680 2681 2682
/******************************************************************************
 *            PROPSHEET_CleanUp
 */
static void PROPSHEET_CleanUp(HWND hwndDlg)
{
Alexandre Julliard's avatar
Alexandre Julliard committed
2683
  int i;
2684
  PropSheetInfo* psInfo = RemovePropW(hwndDlg, PropSheetInfoStr);
2685 2686

  TRACE("\n");
2687
  if (!psInfo) return;
2688
  if (!IS_INTRESOURCE(psInfo->ppshheader.pszCaption))
2689
      Free ((LPVOID)psInfo->ppshheader.pszCaption);
Alexandre Julliard's avatar
Alexandre Julliard committed
2690 2691 2692 2693 2694

  for (i = 0; i < psInfo->nPages; i++)
  {
     PROPSHEETPAGEA* psp = (PROPSHEETPAGEA*)psInfo->proppage[i].hpage;

2695 2696 2697 2698 2699 2700 2701 2702 2703
     /* Unsubclass the page dialog window */
     if((psInfo->ppshheader.dwFlags & (PSH_WIZARD97_NEW | PSH_WIZARD97_OLD)) &&
        (psInfo->ppshheader.dwFlags & PSH_WATERMARK) &&
        (psp->dwFlags & PSP_HIDEHEADER))
     {
        RemoveWindowSubclass(psInfo->proppage[i].hwndPage,
                             PROPSHEET_WizardSubclassProc, 1);
     }

Alexandre Julliard's avatar
Alexandre Julliard committed
2704 2705 2706 2707 2708
     if(psInfo->proppage[i].hwndPage)
        DestroyWindow(psInfo->proppage[i].hwndPage);

     if(psp)
     {
2709
        if (psp->dwFlags & PSP_USETITLE)
2710
           Free ((LPVOID)psInfo->proppage[i].pszText);
Alexandre Julliard's avatar
Alexandre Julliard committed
2711 2712 2713 2714 2715

        DestroyPropertySheetPage(psInfo->proppage[i].hpage);
     }
  }

2716 2717 2718 2719 2720 2721 2722 2723 2724 2725
  DeleteObject(psInfo->hFont);
  DeleteObject(psInfo->hFontBold);
  /* If we created the bitmaps, destroy them */
  if ((psInfo->ppshheader.dwFlags & PSH_WATERMARK) &&
      (!(psInfo->ppshheader.dwFlags & PSH_USEHBMWATERMARK)) )
      DeleteObject(psInfo->ppshheader.u4.hbmWatermark);
  if ((psInfo->ppshheader.dwFlags & PSH_HEADER) &&
      (!(psInfo->ppshheader.dwFlags & PSH_USEHBMHEADER)) )
      DeleteObject(psInfo->ppshheader.u5.hbmHeader);

2726 2727
  Free(psInfo->proppage);
  Free(psInfo->strPropertiesFor);
2728
  ImageList_Destroy(psInfo->hImageList);
2729

2730
  GlobalFree(psInfo);
2731 2732
}

2733
static INT do_loop(const PropSheetInfo *psInfo)
2734 2735 2736 2737 2738 2739 2740 2741 2742 2743 2744 2745 2746 2747 2748 2749 2750 2751 2752 2753 2754 2755 2756
{
    MSG msg;
    INT ret = -1;
    HWND hwnd = psInfo->hwnd;

    while(IsWindow(hwnd) && !psInfo->ended && (ret = GetMessageW(&msg, NULL, 0, 0)))
    {
        if(ret == -1)
            break;

        if(!IsDialogMessageW(hwnd, &msg))
        {
            TranslateMessage(&msg);
            DispatchMessageW(&msg);
        }
    }

    if(ret == 0)
    {
        PostQuitMessage(msg.wParam);
        ret = -1;
    }

2757 2758 2759
    if(ret != -1)
        ret = psInfo->result;

2760 2761 2762 2763
    DestroyWindow(hwnd);
    return ret;
}

2764 2765 2766 2767 2768 2769 2770 2771
/******************************************************************************
 *            PROPSHEET_PropertySheet
 *
 * Common code between PropertySheetA/W
 */
static INT_PTR PROPSHEET_PropertySheet(PropSheetInfo* psInfo, BOOL unicode)
{
  INT_PTR bRet = 0;
2772
  HWND parent = NULL;
2773 2774 2775 2776 2777 2778 2779 2780
  if (psInfo->active_page >= psInfo->nPages) psInfo->active_page = 0;
  TRACE("startpage: %d of %d pages\n", psInfo->active_page, psInfo->nPages);

  psInfo->unicode = unicode;
  psInfo->ended = FALSE;

  if(!psInfo->isModeless)
  {
2781
      parent = psInfo->ppshheader.hwndParent;
2782
      if (parent) EnableWindow(parent, FALSE);
2783 2784 2785 2786
  }
  bRet = PROPSHEET_CreateDialog(psInfo);
  if(!psInfo->isModeless)
  {
2787 2788 2789 2790 2791 2792
      bRet = do_loop(psInfo);
      if (parent) EnableWindow(parent, TRUE);
  }
  return bRet;
}

2793
/******************************************************************************
2794 2795
 *            PropertySheet    (COMCTL32.@)
 *            PropertySheetA   (COMCTL32.@)
2796 2797 2798 2799 2800 2801 2802 2803 2804
 *
 * Creates a property sheet in the specified property sheet header.
 *
 * RETURNS
 *     Modal property sheets: Positive if successful or -1 otherwise.
 *     Modeless property sheets: Property sheet handle.
 *     Or:
 *| ID_PSREBOOTSYSTEM - The user must reboot the computer for the changes to take effect.
 *| ID_PSRESTARTWINDOWS - The user must restart Windows for the changes to take effect.
2805
 */
Frank Richter's avatar
Frank Richter committed
2806
INT_PTR WINAPI PropertySheetA(LPCPROPSHEETHEADERA lppsh)
2807
{
2808
  PropSheetInfo* psInfo = GlobalAlloc(GPTR, sizeof(PropSheetInfo));
2809
  UINT i, n;
2810
  const BYTE* pByte;
2811

2812 2813 2814
  TRACE("(%p)\n", lppsh);

  PROPSHEET_CollectSheetInfoA(lppsh, psInfo);
2815

2816
  psInfo->proppage = Alloc(sizeof(PropPageInfo) * lppsh->nPages);
2817
  pByte = (const BYTE*) psInfo->ppshheader.u3.ppsp;
2818

2819
  for (n = i = 0; i < lppsh->nPages; i++, n++)
2820
  {
2821
    if (!psInfo->usePropPage)
2822
      psInfo->proppage[n].hpage = psInfo->ppshheader.u3.phpage[i];
Alexandre Julliard's avatar
Alexandre Julliard committed
2823 2824
    else
    {
2825
       psInfo->proppage[n].hpage = CreatePropertySheetPageA((LPCPROPSHEETPAGEA)pByte);
2826
       pByte += ((LPCPROPSHEETPAGEA)pByte)->dwSize;
Alexandre Julliard's avatar
Alexandre Julliard committed
2827 2828
    }

2829
    if (!PROPSHEET_CollectPageInfo((LPCPROPSHEETPAGEW)psInfo->proppage[n].hpage,
2830
                               psInfo, n, TRUE))
2831
    {
2832
	if (psInfo->usePropPage)
2833 2834 2835 2836
	    DestroyPropertySheetPage(psInfo->proppage[n].hpage);
	n--;
	psInfo->nPages--;
    }
2837
  }
2838

2839
  return PROPSHEET_PropertySheet(psInfo, FALSE);
2840 2841
}

2842
/******************************************************************************
2843
 *            PropertySheetW   (COMCTL32.@)
2844 2845
 *
 * See PropertySheetA.
2846
 */
Frank Richter's avatar
Frank Richter committed
2847
INT_PTR WINAPI PropertySheetW(LPCPROPSHEETHEADERW lppsh)
2848
{
2849
  PropSheetInfo* psInfo = GlobalAlloc(GPTR, sizeof(PropSheetInfo));
2850
  UINT i, n;
2851
  const BYTE* pByte;
2852 2853 2854 2855 2856

  TRACE("(%p)\n", lppsh);

  PROPSHEET_CollectSheetInfoW(lppsh, psInfo);

2857
  psInfo->proppage = Alloc(sizeof(PropPageInfo) * lppsh->nPages);
2858
  pByte = (const BYTE*) psInfo->ppshheader.u3.ppsp;
2859

2860 2861
  for (n = i = 0; i < lppsh->nPages; i++, n++)
  {
2862
    if (!psInfo->usePropPage)
2863 2864 2865 2866
      psInfo->proppage[n].hpage = psInfo->ppshheader.u3.phpage[i];
    else
    {
       psInfo->proppage[n].hpage = CreatePropertySheetPageW((LPCPROPSHEETPAGEW)pByte);
2867
       pByte += ((LPCPROPSHEETPAGEW)pByte)->dwSize;
2868 2869
    }

2870
    if (!PROPSHEET_CollectPageInfo((LPCPROPSHEETPAGEW)psInfo->proppage[n].hpage,
2871
                               psInfo, n, TRUE))
2872
    {
2873
	if (psInfo->usePropPage)
2874 2875 2876 2877 2878 2879
	    DestroyPropertySheetPage(psInfo->proppage[n].hpage);
	n--;
	psInfo->nPages--;
    }
  }

2880
  return PROPSHEET_PropertySheet(psInfo, TRUE);
2881 2882
}

2883 2884 2885 2886 2887 2888 2889 2890 2891 2892
static LPWSTR load_string( HINSTANCE instance, LPCWSTR str )
{
    LPWSTR ret;

    if (IS_INTRESOURCE(str))
    {
        HRSRC hrsrc;
        HGLOBAL hmem;
        WCHAR *ptr;
        WORD i, id = LOWORD(str);
2893
        UINT len;
2894 2895 2896 2897 2898 2899 2900 2901 2902 2903 2904 2905 2906 2907 2908 2909 2910 2911 2912 2913 2914 2915 2916 2917 2918

        if (!(hrsrc = FindResourceW( instance, MAKEINTRESOURCEW((id >> 4) + 1), (LPWSTR)RT_STRING )))
            return NULL;
        if (!(hmem = LoadResource( instance, hrsrc ))) return NULL;
        if (!(ptr = LockResource( hmem ))) return NULL;
        for (i = id & 0x0f; i > 0; i--) ptr += *ptr + 1;
        len = *ptr;
        if (!len) return NULL;
        ret = Alloc( (len + 1) * sizeof(WCHAR) );
        if (ret)
        {
            memcpy( ret, ptr + 1, len * sizeof(WCHAR) );
            ret[len] = 0;
        }
    }
    else
    {
        int len = (strlenW(str) + 1) * sizeof(WCHAR);
        ret = Alloc( len );
        if (ret) memcpy( ret, str, len );
    }
    return ret;
}


2919
/******************************************************************************
2920 2921
 *            CreatePropertySheetPage    (COMCTL32.@)
 *            CreatePropertySheetPageA   (COMCTL32.@)
2922 2923 2924 2925 2926 2927 2928 2929 2930 2931
 *
 * Creates a new property sheet page.
 *
 * RETURNS
 *     Success: Handle to new property sheet page.
 *     Failure: NULL.
 *
 * NOTES
 *     An application must use the PSM_ADDPAGE message to add the new page to
 *     an existing property sheet.
2932
 */
2933 2934
HPROPSHEETPAGE WINAPI CreatePropertySheetPageA(
                          LPCPROPSHEETPAGEA lpPropSheetPage)
2935
{
2936
  PROPSHEETPAGEW* ppsp = Alloc(sizeof(PROPSHEETPAGEW));
2937

2938
  memcpy(ppsp,lpPropSheetPage,min(lpPropSheetPage->dwSize,sizeof(PROPSHEETPAGEA)));
2939

2940 2941
  ppsp->dwFlags &= ~ PSP_INTERNAL_UNICODE;

2942 2943
    if ( !(ppsp->dwFlags & PSP_DLGINDIRECT) )
    {
2944
        if (!IS_INTRESOURCE( ppsp->u.pszTemplate ))
2945 2946
        {
            int len = strlen(lpPropSheetPage->u.pszTemplate) + 1;
2947 2948 2949
            char *template = Alloc( len );

            ppsp->u.pszTemplate = (LPWSTR)strcpy( template, lpPropSheetPage->u.pszTemplate );
2950 2951
        }
    }
Alexandre Julliard's avatar
Alexandre Julliard committed
2952

2953 2954
    if (ppsp->dwFlags & PSP_USEICONID)
    {
2955
        if (!IS_INTRESOURCE( ppsp->u2.pszIcon ))
2956 2957 2958 2959 2960
            PROPSHEET_AtoW(&ppsp->u2.pszIcon, lpPropSheetPage->u2.pszIcon);
    }

    if (ppsp->dwFlags & PSP_USETITLE)
    {
2961
        if (!IS_INTRESOURCE( ppsp->pszTitle ))
2962 2963
            PROPSHEET_AtoW( &ppsp->pszTitle, lpPropSheetPage->pszTitle );
        else
2964
            ppsp->pszTitle = load_string( ppsp->hInstance, ppsp->pszTitle );
2965 2966 2967
    }
    else
        ppsp->pszTitle = NULL;
Alexandre Julliard's avatar
Alexandre Julliard committed
2968

2969 2970 2971 2972 2973
    if (ppsp->dwFlags & PSP_HIDEHEADER)
        ppsp->dwFlags &= ~(PSP_USEHEADERTITLE | PSP_USEHEADERSUBTITLE);

    if (ppsp->dwFlags & PSP_USEHEADERTITLE)
    {
2974
        if (!IS_INTRESOURCE( ppsp->pszHeaderTitle ))
2975 2976
            PROPSHEET_AtoW(&ppsp->pszHeaderTitle, lpPropSheetPage->pszHeaderTitle);
        else
2977
            ppsp->pszHeaderTitle = load_string( ppsp->hInstance, ppsp->pszHeaderTitle );
2978 2979 2980 2981 2982 2983
    }
    else
        ppsp->pszHeaderTitle = NULL;

    if (ppsp->dwFlags & PSP_USEHEADERSUBTITLE)
    {
2984
        if (!IS_INTRESOURCE( ppsp->pszHeaderSubTitle ))
2985 2986
            PROPSHEET_AtoW(&ppsp->pszHeaderSubTitle, lpPropSheetPage->pszHeaderSubTitle);
        else
2987
            ppsp->pszHeaderSubTitle = load_string( ppsp->hInstance, ppsp->pszHeaderSubTitle );
2988 2989 2990 2991 2992
    }
    else
        ppsp->pszHeaderSubTitle = NULL;

    return (HPROPSHEETPAGE)ppsp;
2993 2994
}

2995
/******************************************************************************
2996
 *            CreatePropertySheetPageW   (COMCTL32.@)
2997 2998
 *
 * See CreatePropertySheetA.
2999
 */
3000
HPROPSHEETPAGE WINAPI CreatePropertySheetPageW(LPCPROPSHEETPAGEW lpPropSheetPage)
3001
{
3002
  PROPSHEETPAGEW* ppsp = Alloc(sizeof(PROPSHEETPAGEW));
3003 3004 3005

  memcpy(ppsp,lpPropSheetPage,min(lpPropSheetPage->dwSize,sizeof(PROPSHEETPAGEW)));

3006 3007
  ppsp->dwFlags |= PSP_INTERNAL_UNICODE;

3008 3009
    if ( !(ppsp->dwFlags & PSP_DLGINDIRECT) )
    {
3010
        if (!IS_INTRESOURCE( ppsp->u.pszTemplate ))
3011 3012
        {
            int len = strlenW(lpPropSheetPage->u.pszTemplate) + 1;
3013 3014 3015
            WCHAR *template = Alloc( len * sizeof (WCHAR) );

            ppsp->u.pszTemplate = strcpyW( template, lpPropSheetPage->u.pszTemplate );
3016 3017
        }
    }
3018

3019 3020
    if ( ppsp->dwFlags & PSP_USEICONID )
    {
3021
        if (!IS_INTRESOURCE( ppsp->u2.pszIcon ))
3022 3023
        {
            int len = strlenW(lpPropSheetPage->u2.pszIcon) + 1;
3024 3025 3026
            WCHAR *icon = Alloc( len * sizeof (WCHAR) );

            ppsp->u2.pszIcon = strcpyW( icon, lpPropSheetPage->u2.pszIcon );
3027 3028
        }
    }
3029

3030
    if (ppsp->dwFlags & PSP_USETITLE)
3031
        ppsp->pszTitle = load_string( ppsp->hInstance, ppsp->pszTitle );
3032 3033 3034 3035 3036 3037 3038
    else
        ppsp->pszTitle = NULL;

    if (ppsp->dwFlags & PSP_HIDEHEADER)
        ppsp->dwFlags &= ~(PSP_USEHEADERTITLE | PSP_USEHEADERSUBTITLE);

    if (ppsp->dwFlags & PSP_USEHEADERTITLE)
3039
        ppsp->pszHeaderTitle = load_string( ppsp->hInstance, ppsp->pszHeaderTitle );
3040 3041 3042 3043
    else
        ppsp->pszHeaderTitle = NULL;

    if (ppsp->dwFlags & PSP_USEHEADERSUBTITLE)
3044
        ppsp->pszHeaderSubTitle = load_string( ppsp->hInstance, ppsp->pszHeaderSubTitle );
3045 3046
    else
        ppsp->pszHeaderSubTitle = NULL;
3047

3048
    return (HPROPSHEETPAGE)ppsp;
3049 3050
}

3051
/******************************************************************************
3052
 *            DestroyPropertySheetPage   (COMCTL32.@)
3053 3054 3055 3056 3057 3058 3059 3060
 *
 * Destroys a property sheet page previously created with
 * CreatePropertySheetA() or CreatePropertySheetW() and frees the associated
 * memory.
 *
 * RETURNS
 *     Success: TRUE
 *     Failure: FALSE
3061
 */
3062
BOOL WINAPI DestroyPropertySheetPage(HPROPSHEETPAGE hPropPage)
3063
{
3064
  PROPSHEETPAGEW *psp = (PROPSHEETPAGEW *)hPropPage;
Alexandre Julliard's avatar
Alexandre Julliard committed
3065 3066 3067 3068

  if (!psp)
     return FALSE;

3069
  if (!(psp->dwFlags & PSP_DLGINDIRECT) && !IS_INTRESOURCE( psp->u.pszTemplate ))
3070
     Free ((LPVOID)psp->u.pszTemplate);
Alexandre Julliard's avatar
Alexandre Julliard committed
3071

3072
  if ((psp->dwFlags & PSP_USEICONID) && !IS_INTRESOURCE( psp->u2.pszIcon ))
3073
     Free ((LPVOID)psp->u2.pszIcon);
Alexandre Julliard's avatar
Alexandre Julliard committed
3074

3075
  if ((psp->dwFlags & PSP_USETITLE) && !IS_INTRESOURCE( psp->pszTitle ))
3076
     Free ((LPVOID)psp->pszTitle);
Alexandre Julliard's avatar
Alexandre Julliard committed
3077

3078 3079 3080 3081 3082 3083
  if ((psp->dwFlags & PSP_USEHEADERTITLE) && !IS_INTRESOURCE( psp->pszHeaderTitle ))
     Free ((LPVOID)psp->pszHeaderTitle);

  if ((psp->dwFlags & PSP_USEHEADERSUBTITLE) && !IS_INTRESOURCE( psp->pszHeaderSubTitle ))
     Free ((LPVOID)psp->pszHeaderSubTitle);

3084
  Free(hPropPage);
3085 3086

  return TRUE;
3087 3088
}

Alexandre Julliard's avatar
Alexandre Julliard committed
3089 3090 3091 3092 3093
/******************************************************************************
 *            PROPSHEET_IsDialogMessage
 */
static BOOL PROPSHEET_IsDialogMessage(HWND hwnd, LPMSG lpMsg)
{
3094
   PropSheetInfo* psInfo = GetPropW(hwnd, PropSheetInfoStr);
Alexandre Julliard's avatar
Alexandre Julliard committed
3095

3096
   TRACE("\n");
Alexandre Julliard's avatar
Alexandre Julliard committed
3097 3098 3099 3100 3101 3102
   if (!psInfo || (hwnd != lpMsg->hwnd && !IsChild(hwnd, lpMsg->hwnd)))
      return FALSE;

   if (lpMsg->message == WM_KEYDOWN && (GetKeyState(VK_CONTROL) & 0x8000))
   {
      int new_page = 0;
3103
      INT dlgCode = SendMessageW(lpMsg->hwnd, WM_GETDLGCODE, 0, (LPARAM)lpMsg);
Alexandre Julliard's avatar
Alexandre Julliard committed
3104 3105 3106 3107 3108 3109 3110 3111 3112 3113 3114 3115 3116 3117 3118 3119 3120 3121 3122 3123 3124 3125 3126 3127 3128 3129 3130 3131

      if (!(dlgCode & DLGC_WANTMESSAGE))
      {
         switch (lpMsg->wParam)
         {
            case VK_TAB:
               if (GetKeyState(VK_SHIFT) & 0x8000)
                   new_page = -1;
                else
                   new_page = 1;
               break;

            case VK_NEXT:   new_page = 1;  break;
            case VK_PRIOR:  new_page = -1; break;
         }
      }

      if (new_page)
      {
         if (PROPSHEET_CanSetCurSel(hwnd) != FALSE)
         {
            new_page += psInfo->active_page;

            if (new_page < 0)
               new_page = psInfo->nPages - 1;
            else if (new_page >= psInfo->nPages)
               new_page = 0;

3132
            PROPSHEET_SetCurSel(hwnd, new_page, 1, 0);
Alexandre Julliard's avatar
Alexandre Julliard committed
3133 3134 3135 3136 3137 3138
         }

         return TRUE;
      }
   }

3139
   return IsDialogMessageW(hwnd, lpMsg);
Alexandre Julliard's avatar
Alexandre Julliard committed
3140 3141
}

3142 3143 3144 3145 3146 3147 3148 3149 3150 3151 3152 3153 3154 3155 3156 3157 3158 3159
/******************************************************************************
 *            PROPSHEET_DoCommand
 */
static BOOL PROPSHEET_DoCommand(HWND hwnd, WORD wID)
{

    switch (wID) {

    case IDOK:
    case IDC_APPLY_BUTTON:
	{
	    HWND hwndApplyBtn = GetDlgItem(hwnd, IDC_APPLY_BUTTON);

	    if (PROPSHEET_Apply(hwnd, wID == IDOK ? 1: 0) == FALSE)
		break;

	    if (wID == IDOK)
		{
3160
                    PropSheetInfo* psInfo = GetPropW(hwnd, PropSheetInfoStr);
3161

3162 3163 3164
                    /* don't overwrite ID_PSRESTARTWINDOWS or ID_PSREBOOTSYSTEM */
                    if (psInfo->result == 0)
                        psInfo->result = IDOK;
3165 3166 3167 3168

		    if (psInfo->isModeless)
			psInfo->activeValid = FALSE;
		    else
3169
                        psInfo->ended = TRUE;
3170 3171 3172 3173 3174 3175 3176 3177 3178 3179 3180 3181 3182 3183 3184 3185 3186 3187 3188 3189 3190 3191 3192 3193 3194 3195
		}
	    else
		EnableWindow(hwndApplyBtn, FALSE);

	    break;
	}

    case IDC_BACK_BUTTON:
	PROPSHEET_Back(hwnd);
	break;

    case IDC_NEXT_BUTTON:
	PROPSHEET_Next(hwnd);
	break;

    case IDC_FINISH_BUTTON:
	PROPSHEET_Finish(hwnd);
	break;

    case IDCANCEL:
	PROPSHEET_Cancel(hwnd, 0);
	break;

    case IDHELP:
	PROPSHEET_Help(hwnd);
	break;
3196 3197 3198

    default:
        return FALSE;
3199 3200 3201 3202 3203
    }

    return TRUE;
}

3204 3205 3206
/******************************************************************************
 *            PROPSHEET_Paint
 */
3207
static LRESULT PROPSHEET_Paint(HWND hwnd, HDC hdcParam)
3208
{
3209
    PropSheetInfo* psInfo = GetPropW(hwnd, PropSheetInfoStr);
3210 3211 3212 3213 3214 3215 3216
    PAINTSTRUCT ps;
    HDC hdc, hdcSrc;
    BITMAP bm;
    HBITMAP hbmp;
    HPALETTE hOldPal = 0;
    int offsety = 0;
    HBRUSH hbr;
3217
    RECT r, rzone;
3218
    LPCPROPSHEETPAGEW ppshpage;
3219 3220
    WCHAR szBuffer[256];
    int nLength;
3221

3222
    hdc = hdcParam ? hdcParam : BeginPaint(hwnd, &ps);
3223 3224 3225 3226 3227 3228 3229
    if (!hdc) return 1;

    hdcSrc = CreateCompatibleDC(0);

    if (psInfo->ppshheader.dwFlags & PSH_USEHPLWATERMARK) 
	hOldPal = SelectPalette(hdc, psInfo->ppshheader.hplWatermark, FALSE);

3230 3231 3232 3233 3234 3235
    if (psInfo->active_page < 0)
        ppshpage = NULL;
    else
        ppshpage = (LPCPROPSHEETPAGEW)psInfo->proppage[psInfo->active_page].hpage;

    if ( (ppshpage && !(ppshpage->dwFlags & PSP_HIDEHEADER)) &&
3236 3237
	 (psInfo->ppshheader.dwFlags & (PSH_WIZARD97_OLD | PSH_WIZARD97_NEW)) &&
	 (psInfo->ppshheader.dwFlags & PSH_HEADER) ) 
3238 3239 3240 3241 3242 3243 3244
    {
	HWND hwndLineHeader = GetDlgItem(hwnd, IDC_SUNKEN_LINEHEADER);
	HFONT hOldFont;
	COLORREF clrOld = 0;
	int oldBkMode = 0;

	hbmp = SelectObject(hdcSrc, psInfo->ppshheader.u5.hbmHeader);
3245
	hOldFont = SelectObject(hdc, psInfo->hFontBold);
3246 3247 3248

	GetClientRect(hwndLineHeader, &r);
	MapWindowPoints(hwndLineHeader, hwnd, (LPPOINT) &r, 2);
3249
	SetRect(&rzone, 0, 0, r.right + 1, r.top - 1);
3250

3251
	GetObjectW(psInfo->ppshheader.u5.hbmHeader, sizeof(BITMAP), &bm);
3252

3253 3254 3255 3256 3257 3258 3259 3260 3261 3262 3263 3264 3265 3266 3267 3268 3269 3270 3271 3272 3273 3274
 	if (psInfo->ppshheader.dwFlags & PSH_WIZARD97_OLD)
 	{
 	    /* Fill the unoccupied part of the header with color of the
 	     * left-top pixel, but do it only when needed.
 	     */
 	    if (bm.bmWidth < r.right || bm.bmHeight < r.bottom)
 	    {
 	        hbr = CreateSolidBrush(GetPixel(hdcSrc, 0, 0));
 	        CopyRect(&r, &rzone);
 	        if (bm.bmWidth < r.right)
 	        {
 	            r.left = bm.bmWidth;
 	            FillRect(hdc, &r, hbr);
 	        }
 	        if (bm.bmHeight < r.bottom)
 	        {
 	            r.left = 0;
 	            r.top = bm.bmHeight;
 	            FillRect(hdc, &r, hbr);
 	        }
 	        DeleteObject(hbr);
 	    }
3275 3276 3277 3278 3279

 	    /* Draw the header itself. */
 	    BitBlt(hdc, 0, 0,
 	           bm.bmWidth, min(bm.bmHeight, rzone.bottom),
 	           hdcSrc, 0, 0, SRCCOPY);
3280 3281 3282
 	}
 	else
 	{
3283
            int margin;
3284
 	    hbr = GetSysColorBrush(COLOR_WINDOW);
3285
 	    FillRect(hdc, &rzone, hbr);
3286 3287 3288

 	    /* Draw the header bitmap. It's always centered like a
 	     * common 49 x 49 bitmap. */
3289 3290 3291 3292
            margin = (rzone.bottom - 49) / 2;
 	    BitBlt(hdc, rzone.right - 49 - margin, margin,
                   min(bm.bmWidth, 49), min(bm.bmHeight, 49),
                   hdcSrc, 0, 0, SRCCOPY);
3293 3294 3295 3296 3297

 	    /* NOTE: Native COMCTL32 draws a white stripe over the bitmap
 	     * if its height is smaller than 49 pixels. Because the reason
 	     * for this bug is unknown the current code doesn't try to
 	     * replicate it. */
3298
 	}
3299

3300 3301 3302
	clrOld = SetTextColor (hdc, 0x00000000);
	oldBkMode = SetBkMode (hdc, TRANSPARENT); 

3303
	if (ppshpage->dwFlags & PSP_USEHEADERTITLE) {
3304
	    SetRect(&r, 20, 10, 0, 0);
3305
            if (!IS_INTRESOURCE(ppshpage->pszHeaderTitle))
3306
                DrawTextW(hdc, ppshpage->pszHeaderTitle, -1, &r, DT_LEFT | DT_SINGLELINE | DT_NOCLIP);
3307
	    else
3308
	    {
Frank Richter's avatar
Frank Richter committed
3309
		nLength = LoadStringW(ppshpage->hInstance, (UINT_PTR)ppshpage->pszHeaderTitle,
3310 3311 3312
				      szBuffer, 256);
		if (nLength != 0)
		{
3313
		    DrawTextW(hdc, szBuffer, nLength, &r, DT_LEFT | DT_SINGLELINE | DT_NOCLIP);
3314 3315
		}
	    }
3316 3317 3318 3319
	}

	if (ppshpage->dwFlags & PSP_USEHEADERSUBTITLE) {
	    SelectObject(hdc, psInfo->hFont);
3320
	    SetRect(&r, 40, 25, rzone.right - 69, rzone.bottom);
3321
            if (!IS_INTRESOURCE(ppshpage->pszHeaderTitle))
3322
                DrawTextW(hdc, ppshpage->pszHeaderSubTitle, -1, &r, DT_LEFT | DT_WORDBREAK);
3323
	    else
3324
	    {
Frank Richter's avatar
Frank Richter committed
3325
		nLength = LoadStringW(ppshpage->hInstance, (UINT_PTR)ppshpage->pszHeaderSubTitle,
3326 3327 3328
				      szBuffer, 256);
		if (nLength != 0)
		{
3329
		    DrawTextW(hdc, szBuffer, nLength, &r, DT_LEFT | DT_WORDBREAK);
3330 3331
		}
	    }
3332 3333 3334 3335 3336 3337 3338 3339 3340 3341
	}

	offsety = rzone.bottom + 2;

	SetTextColor(hdc, clrOld);
	SetBkMode(hdc, oldBkMode);
	SelectObject(hdc, hOldFont);
	SelectObject(hdcSrc, hbmp);
    }

3342
    if ( (ppshpage && (ppshpage->dwFlags & PSP_HIDEHEADER)) &&
3343 3344
	 (psInfo->ppshheader.dwFlags & (PSH_WIZARD97_OLD | PSH_WIZARD97_NEW)) &&
	 (psInfo->ppshheader.dwFlags & PSH_WATERMARK) ) 
3345
    {
3346 3347 3348 3349 3350
	HWND hwndLine = GetDlgItem(hwnd, IDC_SUNKEN_LINE);	    

	GetClientRect(hwndLine, &r);
	MapWindowPoints(hwndLine, hwnd, (LPPOINT) &r, 2);

3351 3352 3353 3354 3355 3356 3357 3358
	rzone.left = 0;
	rzone.top = 0;
	rzone.right = r.right;
	rzone.bottom = r.top - 1;

	hbr = GetSysColorBrush(COLOR_WINDOW);
	FillRect(hdc, &rzone, hbr);

3359
	GetObjectW(psInfo->ppshheader.u4.hbmWatermark, sizeof(BITMAP), &bm);
3360 3361
	hbmp = SelectObject(hdcSrc, psInfo->ppshheader.u4.hbmWatermark);

3362 3363
        /* The watermark is truncated to a width of 164 pixels */
        r.right = min(r.right, 164);
3364 3365 3366 3367 3368 3369 3370 3371 3372 3373 3374 3375 3376
	BitBlt(hdc, 0, offsety, min(bm.bmWidth, r.right),
	       min(bm.bmHeight, r.bottom), hdcSrc, 0, 0, SRCCOPY);

	/* If the bitmap is not big enough, fill the remaining area
	   with the color of pixel (0,0) of bitmap - see MSDN */
	if (r.top > bm.bmHeight) {
	    r.bottom = r.top - 1;
	    r.top = bm.bmHeight;
	    r.left = 0;
	    r.right = bm.bmWidth;
	    hbr = CreateSolidBrush(GetPixel(hdcSrc, 0, 0));
	    FillRect(hdc, &r, hbr);
	    DeleteObject(hbr);
3377
	}
3378 3379

	SelectObject(hdcSrc, hbmp);	    
3380 3381 3382 3383 3384 3385 3386
    }

    if (psInfo->ppshheader.dwFlags & PSH_USEHPLWATERMARK) 
	SelectPalette(hdc, hOldPal, FALSE);

    DeleteDC(hdcSrc);

3387
    if (!hdcParam) EndPaint(hwnd, &ps);
3388 3389 3390 3391

    return 0;
}

3392 3393 3394
/******************************************************************************
 *            PROPSHEET_DialogProc
 */
3395
static INT_PTR CALLBACK
3396 3397
PROPSHEET_DialogProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
3398
  TRACE("hwnd=%p msg=0x%04x wparam=%lx lparam=%lx\n",
3399 3400
	hwnd, uMsg, wParam, lParam);

3401 3402 3403 3404 3405
  switch (uMsg)
  {
    case WM_INITDIALOG:
    {
      PropSheetInfo* psInfo = (PropSheetInfo*) lParam;
3406
      WCHAR* strCaption = Alloc(MAX_CAPTION_LENGTH*sizeof(WCHAR));
3407
      HWND hwndTabCtrl = GetDlgItem(hwnd, IDC_TABCONTROL);
Alexandre Julliard's avatar
Alexandre Julliard committed
3408
      int idx;
3409
      LOGFONTW logFont;
3410

3411 3412 3413
      /* Using PropSheetInfoStr to store extra data doesn't match the native
       * common control: native uses TCM_[GS]ETITEM
       */
3414
      SetPropW(hwnd, PropSheetInfoStr, psInfo);
3415

3416
      /*
3417 3418
       * psInfo->hwnd is not being used by WINE code - it exists
       * for compatibility with "real" Windoze. The same about
3419
       * SetWindowLongPtr - WINE is only using the PropSheetInfoStr
3420 3421 3422
       * property.
       */
      psInfo->hwnd = hwnd;
3423
      SetWindowLongPtrW(hwnd, DWLP_USER, (DWORD_PTR)psInfo);
3424

3425 3426 3427 3428 3429
      if (psInfo->ppshheader.dwFlags & INTRNL_ANY_WIZARD)
      {
        /* set up the Next and Back buttons by default */
        PROPSHEET_SetWizButtons(hwnd, PSWIZB_BACK|PSWIZB_NEXT);
      }
3430

3431
      /* Set up fonts */
3432 3433
      SystemParametersInfoW (SPI_GETICONTITLELOGFONT, 0, &logFont, 0);
      psInfo->hFont = CreateFontIndirectW (&logFont);
3434
      logFont.lfWeight = FW_BOLD;
3435
      psInfo->hFontBold = CreateFontIndirectW (&logFont);
3436
      
3437 3438 3439
      /*
       * Small icon in the title bar.
       */
3440 3441
      if ((psInfo->ppshheader.dwFlags & PSH_USEICONID) ||
          (psInfo->ppshheader.dwFlags & PSH_USEHICON))
3442 3443 3444 3445 3446
      {
        HICON hIcon;
        int icon_cx = GetSystemMetrics(SM_CXSMICON);
        int icon_cy = GetSystemMetrics(SM_CYSMICON);

3447
        if (psInfo->ppshheader.dwFlags & PSH_USEICONID)
3448
          hIcon = LoadImageW(psInfo->ppshheader.hInstance,
3449
                             psInfo->ppshheader.u.pszIcon,
3450 3451 3452 3453
                             IMAGE_ICON,
                             icon_cx, icon_cy,
                             LR_DEFAULTCOLOR);
        else
3454
          hIcon = psInfo->ppshheader.u.hIcon;
3455

3456
        SendMessageW(hwnd, WM_SETICON, 0, (LPARAM)hIcon);
3457
      }
3458

3459
      if (psInfo->ppshheader.dwFlags & PSH_USEHICON)
3460
        SendMessageW(hwnd, WM_SETICON, 0, (LPARAM)psInfo->ppshheader.u.hIcon);
3461

3462 3463
      psInfo->strPropertiesFor = strCaption;

3464
      GetWindowTextW(hwnd, psInfo->strPropertiesFor, MAX_CAPTION_LENGTH);
3465

3466 3467
      PROPSHEET_CreateTabControl(hwnd, psInfo);

3468 3469
      PROPSHEET_LoadWizardBitmaps(psInfo);

3470
      if (psInfo->ppshheader.dwFlags & INTRNL_ANY_WIZARD)
3471
      {
3472
        ShowWindow(hwndTabCtrl, SW_HIDE);
Filip Navara's avatar
Filip Navara committed
3473 3474
        PROPSHEET_AdjustSizeWizard(hwnd, psInfo);
        PROPSHEET_AdjustButtonsWizard(hwnd, psInfo);
3475
        SetFocus(GetDlgItem(hwnd, IDC_NEXT_BUTTON));
3476 3477
      }
      else
3478
      {
3479
        if (PROPSHEET_SizeMismatch(hwnd, psInfo))
3480 3481 3482 3483
        {
          PROPSHEET_AdjustSize(hwnd, psInfo);
          PROPSHEET_AdjustButtons(hwnd, psInfo);
        }
3484
        SetFocus(GetDlgItem(hwnd, IDOK));
3485 3486
      }

3487
      if (IS_INTRESOURCE(psInfo->ppshheader.pszCaption) &&
3488
              psInfo->ppshheader.hInstance)
3489
      {
3490
         WCHAR szText[256];
3491

3492
         if (LoadStringW(psInfo->ppshheader.hInstance,
Frank Richter's avatar
Frank Richter committed
3493
                         (UINT_PTR)psInfo->ppshheader.pszCaption, szText, 255))
3494
            PROPSHEET_SetTitleW(hwnd, psInfo->ppshheader.dwFlags, szText);
3495 3496 3497
      }
      else
      {
3498
         PROPSHEET_SetTitleW(hwnd, psInfo->ppshheader.dwFlags,
3499
                         psInfo->ppshheader.pszCaption);
3500
      }
3501

3502 3503

      if (psInfo->useCallback)
3504
             (*(psInfo->ppshheader.pfnCallback))(hwnd, PSCB_INITIALIZED, 0);
3505 3506 3507 3508 3509 3510 3511 3512 3513 3514 3515

      idx = psInfo->active_page;
      psInfo->active_page = -1;

      PROPSHEET_SetCurSel(hwnd, idx, 1, psInfo->proppage[idx].hpage);

      /* doing TCM_SETCURSEL seems to be needed even in case of PSH_WIZARD,
       * as some programs call TCM_GETCURSEL to get the current selection
       * from which to switch to the next page */
      SendMessageW(hwndTabCtrl, TCM_SETCURSEL, psInfo->active_page, 0);

3516
      PROPSHEET_UnChanged(hwnd, NULL);
3517

3518 3519 3520 3521
      /* wizards set their focus during init */
      if (psInfo->ppshheader.dwFlags & INTRNL_ANY_WIZARD)
          return FALSE;

3522 3523 3524
      return TRUE;
    }

3525
    case WM_PRINTCLIENT:
3526
    case WM_PAINT:
3527
      PROPSHEET_Paint(hwnd, (HDC)wParam);
3528 3529
      return TRUE;

3530 3531 3532 3533 3534
    case WM_DESTROY:
      PROPSHEET_CleanUp(hwnd);
      return TRUE;

    case WM_CLOSE:
Alexandre Julliard's avatar
Alexandre Julliard committed
3535
      PROPSHEET_Cancel(hwnd, 1);
3536
      return FALSE; /* let DefDlgProc post us WM_COMMAND/IDCANCEL */
3537 3538

    case WM_COMMAND:
3539 3540
      if (!PROPSHEET_DoCommand(hwnd, LOWORD(wParam)))
      {
3541
          PropSheetInfo* psInfo = GetPropW(hwnd, PropSheetInfoStr);
3542

3543 3544 3545
          if (!psInfo)
              return FALSE;

3546 3547 3548 3549 3550 3551 3552 3553
          /* No default handler, forward notification to active page */
          if (psInfo->activeValid && psInfo->active_page != -1)
          {
             HWND hwndPage = psInfo->proppage[psInfo->active_page].hwndPage;
             SendMessageW(hwndPage, WM_COMMAND, wParam, lParam);
          }
      }
      return TRUE;
3554 3555 3556 3557 3558 3559 3560

    case WM_NOTIFY:
    {
      NMHDR* pnmh = (LPNMHDR) lParam;

      if (pnmh->code == TCN_SELCHANGE)
      {
3561
        int index = SendMessageW(pnmh->hwndFrom, TCM_GETCURSEL, 0, 0);
3562
        PROPSHEET_SetCurSel(hwnd, index, 1, 0);
3563 3564
      }

3565 3566 3567
      if(pnmh->code == TCN_SELCHANGING)
      {
        BOOL bRet = PROPSHEET_CanSetCurSel(hwnd);
3568
        SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, !bRet);
3569 3570 3571
        return TRUE;
      }

3572
      return FALSE;
3573
    }
3574 3575 3576 3577
  
    case WM_SYSCOLORCHANGE:
      COMCTL32_RefreshSysColors();
      return FALSE;
3578 3579 3580

    case PSM_GETCURRENTPAGEHWND:
    {
3581
      PropSheetInfo* psInfo = GetPropW(hwnd, PropSheetInfoStr);
3582 3583
      HWND hwndPage = 0;

3584 3585 3586
      if (!psInfo)
        return FALSE;

Alexandre Julliard's avatar
Alexandre Julliard committed
3587
      if (psInfo->activeValid && psInfo->active_page != -1)
3588 3589
        hwndPage = psInfo->proppage[psInfo->active_page].hwndPage;

3590
      SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, (DWORD_PTR)hwndPage);
3591 3592 3593 3594 3595 3596 3597 3598 3599 3600 3601 3602 3603 3604 3605 3606

      return TRUE;
    }

    case PSM_CHANGED:
      PROPSHEET_Changed(hwnd, (HWND)wParam);
      return TRUE;

    case PSM_UNCHANGED:
      PROPSHEET_UnChanged(hwnd, (HWND)wParam);
      return TRUE;

    case PSM_GETTABCONTROL:
    {
      HWND hwndTabCtrl = GetDlgItem(hwnd, IDC_TABCONTROL);

3607
      SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, (DWORD_PTR)hwndTabCtrl);
3608 3609 3610 3611 3612 3613 3614 3615

      return TRUE;
    }

    case PSM_SETCURSEL:
    {
      BOOL msgResult;

3616 3617 3618 3619 3620
      msgResult = PROPSHEET_CanSetCurSel(hwnd);
      if(msgResult != FALSE)
      {
        msgResult = PROPSHEET_SetCurSel(hwnd,
                                       (int)wParam,
3621
				       1,
3622 3623
                                       (HPROPSHEETPAGE)lParam);
      }
3624

3625
      SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);
3626 3627 3628 3629 3630 3631

      return TRUE;
    }

    case PSM_CANCELTOCLOSE:
    {
3632
      WCHAR buf[MAX_BUTTONTEXT_LENGTH];
3633 3634 3635 3636
      HWND hwndOK = GetDlgItem(hwnd, IDOK);
      HWND hwndCancel = GetDlgItem(hwnd, IDCANCEL);

      EnableWindow(hwndCancel, FALSE);
3637
      if (LoadStringW(COMCTL32_hModule, IDS_CLOSE, buf, sizeof(buf)/sizeof(buf[0])))
3638
         SetWindowTextW(hwndOK, buf);
3639

Alexandre Julliard's avatar
Alexandre Julliard committed
3640
      return FALSE;
3641
    }
3642

3643 3644
    case PSM_RESTARTWINDOWS:
    {
3645
      PropSheetInfo* psInfo = GetPropW(hwnd, PropSheetInfoStr);
3646

3647 3648 3649
      if (!psInfo)
        return FALSE;

3650 3651 3652 3653
      /* reboot system takes precedence over restart windows */
      if (psInfo->result != ID_PSREBOOTSYSTEM)
          psInfo->result = ID_PSRESTARTWINDOWS;

3654 3655 3656 3657 3658
      return TRUE;
    }

    case PSM_REBOOTSYSTEM:
    {
3659
      PropSheetInfo* psInfo = GetPropW(hwnd, PropSheetInfoStr);
3660

3661 3662 3663
      if (!psInfo)
        return FALSE;

3664 3665
      psInfo->result = ID_PSREBOOTSYSTEM;

3666 3667 3668 3669 3670 3671
      return TRUE;
    }

    case PSM_SETTITLEA:
      PROPSHEET_SetTitleA(hwnd, (DWORD) wParam, (LPCSTR) lParam);
      return TRUE;
3672

3673 3674 3675
    case PSM_SETTITLEW:
      PROPSHEET_SetTitleW(hwnd, (DWORD) wParam, (LPCWSTR) lParam);
      return TRUE;
3676 3677 3678

    case PSM_APPLY:
    {
Alexandre Julliard's avatar
Alexandre Julliard committed
3679
      BOOL msgResult = PROPSHEET_Apply(hwnd, 0);
3680

3681
      SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);
3682 3683 3684 3685 3686 3687 3688 3689

      return TRUE;
    }

    case PSM_QUERYSIBLINGS:
    {
      LRESULT msgResult = PROPSHEET_QuerySiblings(hwnd, wParam, lParam);

3690
      SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);
3691 3692 3693 3694

      return TRUE;
    }

3695
    case PSM_ADDPAGE:
3696 3697 3698 3699 3700 3701 3702 3703 3704 3705 3706
    {
      /*
       * Note: MSVC++ 6.0 documentation says that PSM_ADDPAGE does not have
       *       a return value. This is not true. PSM_ADDPAGE returns TRUE
       *       on success or FALSE otherwise, as specified on MSDN Online.
       *       Also see the MFC code for
       *       CPropertySheet::AddPage(CPropertyPage* pPage).
       */

      BOOL msgResult = PROPSHEET_AddPage(hwnd, (HPROPSHEETPAGE)lParam);

3707
      SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);
3708

3709
      return TRUE;
3710
    }
3711 3712 3713 3714 3715

    case PSM_REMOVEPAGE:
      PROPSHEET_RemovePage(hwnd, (int)wParam, (HPROPSHEETPAGE)lParam);
      return TRUE;

3716 3717
    case PSM_ISDIALOGMESSAGE:
    {
Alexandre Julliard's avatar
Alexandre Julliard committed
3718
       BOOL msgResult = PROPSHEET_IsDialogMessage(hwnd, (LPMSG)lParam);
3719
       SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);
Alexandre Julliard's avatar
Alexandre Julliard committed
3720
       return TRUE;
3721 3722 3723 3724 3725 3726
    }

    case PSM_PRESSBUTTON:
      PROPSHEET_PressButton(hwnd, (int)wParam);
      return TRUE;

3727
    case PSM_SETFINISHTEXTA:
3728
      PROPSHEET_SetFinishTextA(hwnd, (LPCSTR) lParam);
3729 3730 3731 3732 3733 3734
      return TRUE;

    case PSM_SETWIZBUTTONS:
      PROPSHEET_SetWizButtons(hwnd, (DWORD)lParam);
      return TRUE;

3735
    case PSM_SETCURSELID:
3736 3737
        PROPSHEET_SetCurSelId(hwnd, (int)lParam);
        return TRUE;
3738

3739
    case PSM_SETFINISHTEXTW:
3740
        PROPSHEET_SetFinishTextW(hwnd, (LPCWSTR) lParam);
3741
        return FALSE;
3742

3743 3744 3745
    case PSM_INSERTPAGE:
    {
        BOOL msgResult = PROPSHEET_InsertPage(hwnd, (HPROPSHEETPAGE)wParam, (HPROPSHEETPAGE)lParam);
3746
        SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);
3747 3748 3749 3750 3751 3752 3753 3754 3755 3756 3757 3758 3759 3760 3761 3762 3763 3764 3765 3766 3767 3768
        return TRUE;
    }

    case PSM_SETHEADERTITLEW:
        PROPSHEET_SetHeaderTitleW(hwnd, (int)wParam, (LPCWSTR)lParam);
        return TRUE;

    case PSM_SETHEADERTITLEA:
        PROPSHEET_SetHeaderTitleA(hwnd, (int)wParam, (LPCSTR)lParam);
        return TRUE;

    case PSM_SETHEADERSUBTITLEW:
        PROPSHEET_SetHeaderSubTitleW(hwnd, (int)wParam, (LPCWSTR)lParam);
        return TRUE;

    case PSM_SETHEADERSUBTITLEA:
        PROPSHEET_SetHeaderSubTitleA(hwnd, (int)wParam, (LPCSTR)lParam);
        return TRUE;

    case PSM_HWNDTOINDEX:
    {
        LRESULT msgResult = PROPSHEET_HwndToIndex(hwnd, (HWND)wParam);
3769
        SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);
3770 3771 3772 3773 3774 3775
        return TRUE;
    }

    case PSM_INDEXTOHWND:
    {
        LRESULT msgResult = PROPSHEET_IndexToHwnd(hwnd, (int)wParam);
3776
        SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);
3777 3778 3779 3780 3781 3782
        return TRUE;
    }

    case PSM_PAGETOINDEX:
    {
        LRESULT msgResult = PROPSHEET_PageToIndex(hwnd, (HPROPSHEETPAGE)wParam);
3783
        SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);
3784 3785 3786 3787 3788 3789
        return TRUE;
    }

    case PSM_INDEXTOPAGE:
    {
        LRESULT msgResult = PROPSHEET_IndexToPage(hwnd, (int)wParam);
3790
        SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);
3791 3792 3793 3794 3795 3796
        return TRUE;
    }

    case PSM_IDTOINDEX:
    {
        LRESULT msgResult = PROPSHEET_IdToIndex(hwnd, (int)lParam);
3797
        SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);
3798 3799 3800 3801 3802 3803
        return TRUE;
    }

    case PSM_INDEXTOID:
    {
        LRESULT msgResult = PROPSHEET_IndexToId(hwnd, (int)wParam);
3804
        SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);
3805 3806 3807 3808 3809 3810
        return TRUE;
    }

    case PSM_GETRESULT:
    {
        LRESULT msgResult = PROPSHEET_GetResult(hwnd);
3811
        SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);
3812 3813 3814 3815 3816 3817
        return TRUE;
    }

    case PSM_RECALCPAGESIZES:
    {
        LRESULT msgResult = PROPSHEET_RecalcPageSizes(hwnd);
3818
        SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);
3819 3820 3821
        return TRUE;
    }

3822 3823 3824
    default:
      return FALSE;
  }
3825
}