propsheet.c 104 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 21 22
 * 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
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 *
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 39
 *   - Wizard 97 header resizing
 *   - Enforcing of minimal wizard size
 *   - Messages:
 *     o PSM_GETRESULT
 *     o PSM_INSERTPAGE
 *     o PSM_RECALCPAGESIZES
 *     o PSM_SETHEADERSUBTITLE
 *     o PSM_SETHEADERTITLE
40 41
 *     o WM_HELP
 *     o WM_CONTEXTMENU
Filip Navara's avatar
Filip Navara committed
42 43 44 45 46 47 48 49 50 51 52 53
 *   - 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
54 55
 */

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

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

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

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

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

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

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

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

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

/******************************************************************************
 * Defines and global variables
 */
146

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

150 151
#define PSP_INTERNAL_UNICODE 0x80000000

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

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

Filip Navara's avatar
Filip Navara committed
158 159 160 161
/* Wizard metrics specified in DLUs */
#define WIZARD_PADDING 7
#define WIZARD_HEADER_HEIGHT 36
                         	
162 163 164
/******************************************************************************
 * Prototypes
 */
Frank Richter's avatar
Frank Richter committed
165
static INT_PTR PROPSHEET_CreateDialog(PropSheetInfo* psInfo);
166
static BOOL PROPSHEET_SizeMismatch(HWND hwndDlg, PropSheetInfo* psInfo);
167 168
static BOOL PROPSHEET_AdjustSize(HWND hwndDlg, PropSheetInfo* psInfo);
static BOOL PROPSHEET_AdjustButtons(HWND hwndParent, PropSheetInfo* psInfo);
169 170 171
static BOOL PROPSHEET_CollectSheetInfoA(LPCPROPSHEETHEADERA lppsh,
                                       PropSheetInfo * psInfo);
static BOOL PROPSHEET_CollectSheetInfoW(LPCPROPSHEETHEADERW lppsh,
172
                                       PropSheetInfo * psInfo);
173
static BOOL PROPSHEET_CollectPageInfo(LPCPROPSHEETPAGEW lppsp,
174 175
                                      PropSheetInfo * psInfo,
                                      int index);
176 177
static BOOL PROPSHEET_CreateTabControl(HWND hwndParent,
                                       PropSheetInfo * psInfo);
178
static BOOL PROPSHEET_CreatePage(HWND hwndParent, int index,
179
                                const PropSheetInfo * psInfo,
180
                                LPCPROPSHEETPAGEW ppshpage);
181 182
static BOOL PROPSHEET_ShowPage(HWND hwndDlg, int index, PropSheetInfo * psInfo);
static PADDING_INFO PROPSHEET_GetPaddingInfo(HWND hwndDlg);
183 184 185
static BOOL PROPSHEET_Back(HWND hwndDlg);
static BOOL PROPSHEET_Next(HWND hwndDlg);
static BOOL PROPSHEET_Finish(HWND hwndDlg);
Alexandre Julliard's avatar
Alexandre Julliard committed
186 187
static BOOL PROPSHEET_Apply(HWND hwndDlg, LPARAM lParam);
static void PROPSHEET_Cancel(HWND hwndDlg, LPARAM lParam);
188
static void PROPSHEET_Help(HWND hwndDlg);
189 190 191
static void PROPSHEET_Changed(HWND hwndDlg, HWND hwndDirtyPage);
static void PROPSHEET_UnChanged(HWND hwndDlg, HWND hwndCleanPage);
static void PROPSHEET_PressButton(HWND hwndDlg, int buttonID);
192
static void PROPSHEET_SetFinishTextA(HWND hwndDlg, LPCSTR lpszText);
193
static void PROPSHEET_SetFinishTextW(HWND hwndDlg, LPCWSTR lpszText);
194
static void PROPSHEET_SetTitleA(HWND hwndDlg, DWORD dwStyle, LPCSTR lpszText);
195
static void PROPSHEET_SetTitleW(HWND hwndDlg, DWORD dwStyle, LPCWSTR lpszText);
196
static BOOL PROPSHEET_CanSetCurSel(HWND hwndDlg);
197 198
static BOOL PROPSHEET_SetCurSel(HWND hwndDlg,
                                int index,
199
                                int skipdir,
200
                                HPROPSHEETPAGE hpage);
201
static void PROPSHEET_SetCurSelId(HWND hwndDlg, int id);
202 203 204 205 206 207 208 209
static LRESULT PROPSHEET_QuerySiblings(HWND hwndDlg,
                                       WPARAM wParam, LPARAM lParam);
static BOOL PROPSHEET_AddPage(HWND hwndDlg,
                              HPROPSHEETPAGE hpage);

static BOOL PROPSHEET_RemovePage(HWND hwndDlg,
                                 int index,
                                 HPROPSHEETPAGE hpage);
210
static void PROPSHEET_CleanUp(HWND hwndDlg);
211
static int PROPSHEET_GetPageIndex(HPROPSHEETPAGE hpage, PropSheetInfo* psInfo);
212
static void PROPSHEET_SetWizButtons(HWND hwndDlg, DWORD dwFlags);
213
static PADDING_INFO PROPSHEET_GetPaddingInfoWizard(HWND hwndDlg, const PropSheetInfo* psInfo);
Alexandre Julliard's avatar
Alexandre Julliard committed
214
static BOOL PROPSHEET_IsDialogMessage(HWND hwnd, LPMSG lpMsg);
215
static BOOL PROPSHEET_DoCommand(HWND hwnd, WORD wID);
216

217
INT_PTR CALLBACK
218 219
PROPSHEET_DialogProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);

220
WINE_DEFAULT_DEBUG_CHANNEL(propsheet);
221

222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246
#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);
}
247
#undef add_flag
248

249 250 251 252 253
/******************************************************************************
 *            PROPSHEET_GetPageRect
 *
 * Retrieve rect from tab control and map into the dialog for SetWindowPos
 */
Filip Navara's avatar
Filip Navara committed
254 255
static void PROPSHEET_GetPageRect(const PropSheetInfo * psInfo, HWND hwndDlg,
                                  RECT *rc, LPCPROPSHEETPAGEW ppshpage)
256
{
Filip Navara's avatar
Filip Navara committed
257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274
    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);
275

Filip Navara's avatar
Filip Navara committed
276 277 278 279 280 281 282 283 284 285 286 287 288 289 290
        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);
    }
291 292
}

293 294 295 296 297
/******************************************************************************
 *            PROPSHEET_FindPageByResId
 *
 * Find page index corresponding to page resource id.
 */
298
static INT PROPSHEET_FindPageByResId(PropSheetInfo * psInfo, LRESULT resId)
299 300 301 302 303 304 305 306 307 308 309 310 311 312 313
{
   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;
}

314 315 316 317 318 319 320 321 322 323 324
/******************************************************************************
 *            PROPSHEET_AtoW
 *
 * Convert ASCII to Unicode since all data is saved as Unicode.
 */
static void PROPSHEET_AtoW(LPCWSTR *tostr, LPCSTR frstr)
{
    INT len;

    TRACE("<%s>\n", frstr);
    len = MultiByteToWideChar(CP_ACP, 0, frstr, -1, 0, 0);
325
    *tostr = Alloc(len * sizeof(WCHAR));
326 327 328
    MultiByteToWideChar(CP_ACP, 0, frstr, -1, (LPWSTR)*tostr, len);
}

329
/******************************************************************************
330
 *            PROPSHEET_CollectSheetInfoA
331 332 333
 *
 * Collect relevant data.
 */
334
static BOOL PROPSHEET_CollectSheetInfoA(LPCPROPSHEETHEADERA lppsh,
335 336
                                       PropSheetInfo * psInfo)
{
337
  DWORD dwSize = min(lppsh->dwSize,sizeof(PROPSHEETHEADERA));
338 339 340 341
  DWORD dwFlags = lppsh->dwFlags;

  psInfo->hasHelp = dwFlags & PSH_HASHELP;
  psInfo->hasApply = !(dwFlags & PSH_NOAPPLYNOW);
342
  psInfo->hasFinish = dwFlags & PSH_WIZARDHASFINISH;
343
  psInfo->useCallback = (dwFlags & PSH_USECALLBACK )&& (lppsh->pfnCallback);
344
  psInfo->isModeless = dwFlags & PSH_MODELESS;
Alexandre Julliard's avatar
Alexandre Julliard committed
345

346
  memcpy(&psInfo->ppshheader,lppsh,dwSize);
347
  TRACE("\n** PROPSHEETHEADER **\ndwSize\t\t%ld\ndwFlags\t\t%08lx\nhwndParent\t%p\nhInstance\t%p\npszCaption\t'%s'\nnPages\t\t%d\npfnCallback\t%p\n",
348 349 350 351
	lppsh->dwSize, lppsh->dwFlags, lppsh->hwndParent, lppsh->hInstance,
	debugstr_a(lppsh->pszCaption), lppsh->nPages, lppsh->pfnCallback);

  PROPSHEET_UnImplementedFlags(lppsh->dwFlags);
Alexandre Julliard's avatar
Alexandre Julliard committed
352

353 354 355
  if (lppsh->dwFlags & INTRNL_ANY_WIZARD)
     psInfo->ppshheader.pszCaption = NULL;
  else
356
  {
357 358
     if (HIWORD(lppsh->pszCaption))
     {
359
        int len = MultiByteToWideChar(CP_ACP, 0, lppsh->pszCaption, -1, NULL, 0);
360
        psInfo->ppshheader.pszCaption = Alloc( len*sizeof (WCHAR) );
361
        MultiByteToWideChar(CP_ACP, 0, lppsh->pszCaption, -1, (LPWSTR) psInfo->ppshheader.pszCaption, len);
362
     }
363
  }
364
  psInfo->nPages = lppsh->nPages;
365 366 367

  if (dwFlags & PSH_USEPSTARTPAGE)
  {
368
    TRACE("PSH_USEPSTARTPAGE is on\n");
369 370 371 372 373
    psInfo->active_page = 0;
  }
  else
    psInfo->active_page = lppsh->u2.nStartPage;

Alexandre Julliard's avatar
Alexandre Julliard committed
374 375 376
  if (psInfo->active_page < 0 || psInfo->active_page >= psInfo->nPages)
     psInfo->active_page = 0;

377 378
  psInfo->restartWindows = FALSE;
  psInfo->rebootSystem = FALSE;
379
  psInfo->hImageList = 0;
Alexandre Julliard's avatar
Alexandre Julliard committed
380
  psInfo->activeValid = FALSE;
381 382 383 384 385

  return TRUE;
}

/******************************************************************************
386 387 388 389 390 391 392 393 394 395 396 397
 *            PROPSHEET_CollectSheetInfoW
 *
 * Collect relevant data.
 */
static BOOL PROPSHEET_CollectSheetInfoW(LPCPROPSHEETHEADERW lppsh,
                                       PropSheetInfo * psInfo)
{
  DWORD dwSize = min(lppsh->dwSize,sizeof(PROPSHEETHEADERW));
  DWORD dwFlags = lppsh->dwFlags;

  psInfo->hasHelp = dwFlags & PSH_HASHELP;
  psInfo->hasApply = !(dwFlags & PSH_NOAPPLYNOW);
398
  psInfo->hasFinish = dwFlags & PSH_WIZARDHASFINISH;
399
  psInfo->useCallback = (dwFlags & PSH_USECALLBACK) && (lppsh->pfnCallback);
400 401 402
  psInfo->isModeless = dwFlags & PSH_MODELESS;

  memcpy(&psInfo->ppshheader,lppsh,dwSize);
403
  TRACE("\n** PROPSHEETHEADER **\ndwSize\t\t%ld\ndwFlags\t\t%08lx\nhwndParent\t%p\nhInstance\t%p\npszCaption\t'%s'\nnPages\t\t%d\npfnCallback\t%p\n",
404 405 406 407
      lppsh->dwSize, lppsh->dwFlags, lppsh->hwndParent, lppsh->hInstance, debugstr_w(lppsh->pszCaption), lppsh->nPages, lppsh->pfnCallback);

  PROPSHEET_UnImplementedFlags(lppsh->dwFlags);

408 409 410
  if (lppsh->dwFlags & INTRNL_ANY_WIZARD)
     psInfo->ppshheader.pszCaption = NULL;
  else
411
  {
412
     if (HIWORD(lppsh->pszCaption))
413 414
     {
        int len = strlenW(lppsh->pszCaption);
415
        psInfo->ppshheader.pszCaption = Alloc( (len+1)*sizeof(WCHAR) );
416 417
        strcpyW( (WCHAR *)psInfo->ppshheader.pszCaption, lppsh->pszCaption );
     }
418 419 420 421 422
  }
  psInfo->nPages = lppsh->nPages;

  if (dwFlags & PSH_USEPSTARTPAGE)
  {
423
    TRACE("PSH_USEPSTARTPAGE is on\n");
424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440
    psInfo->active_page = 0;
  }
  else
    psInfo->active_page = lppsh->u2.nStartPage;

  if (psInfo->active_page < 0 || psInfo->active_page >= psInfo->nPages)
     psInfo->active_page = 0;

  psInfo->restartWindows = FALSE;
  psInfo->rebootSystem = FALSE;
  psInfo->hImageList = 0;
  psInfo->activeValid = FALSE;

  return TRUE;
}

/******************************************************************************
441
 *            PROPSHEET_CollectPageInfo
442 443 444 445
 *
 * Collect property sheet data.
 * With code taken from DIALOG_ParseTemplate32.
 */
446
BOOL PROPSHEET_CollectPageInfo(LPCPROPSHEETPAGEW lppsp,
447 448 449 450 451 452 453 454
                               PropSheetInfo * psInfo,
                               int index)
{
  DLGTEMPLATE* pTemplate;
  const WORD*  p;
  DWORD dwFlags;
  int width, height;

455 456 457
  if (!lppsp)
    return FALSE;

458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479
  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)
    pTemplate = (DLGTEMPLATE*)lppsp->u.pResource;
480
  else if(dwFlags & PSP_INTERNAL_UNICODE )
481 482 483
  {
    HRSRC hResource = FindResourceW(lppsp->hInstance,
                                    lppsp->u.pszTemplate,
484
                                    (LPWSTR)RT_DIALOG);
485 486 487 488
    HGLOBAL hTemplate = LoadResource(lppsp->hInstance,
                                     hResource);
    pTemplate = (LPDLGTEMPLATEW)LockResource(hTemplate);
  }
489 490 491 492
  else
  {
    HRSRC hResource = FindResourceA(lppsp->hInstance,
                                    (LPSTR)lppsp->u.pszTemplate,
493
                                    (LPSTR)RT_DIALOG);
494 495 496 497
    HGLOBAL hTemplate = LoadResource(lppsp->hInstance,
                                     hResource);
    pTemplate = (LPDLGTEMPLATEA)LockResource(hTemplate);
  }
498 499 500 501 502 503 504 505 506 507 508

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

  p = (const WORD *)pTemplate;

  if (((MyDLGTEMPLATEEX*)pTemplate)->signature == 0xFFFF)
  {
509
    /* DLGTEMPLATEEX (not defined in any std. header file) */
510 511 512 513 514 515 516 517 518

    p++;       /* dlgVer    */
    p++;       /* signature */
    p += 2;    /* help ID   */
    p += 2;    /* ext style */
    p += 2;    /* style     */
  }
  else
  {
519
    /* DLGTEMPLATE */
520 521 522 523 524 525 526 527 528 529 530

    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
531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547
  /* 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;
  }

548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566
  /* remember the largest width and height */
  if (width > psInfo->width)
    psInfo->width = width;

  if (height > psInfo->height)
    psInfo->height = height;

  /* menu */
  switch ((WORD)*p)
  {
    case 0x0000:
      p++;
      break;
    case 0xffff:
      p += 2;
      break;
    default:
      p += lstrlenW( (LPCWSTR)p ) + 1;
      break;
567
  }
568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591

  /* class */
  switch ((WORD)*p)
  {
    case 0x0000:
      p++;
      break;
    case 0xffff:
      p += 2;
      break;
    default:
      p += lstrlenW( (LPCWSTR)p ) + 1;
      break;
  }

  /* Extract the caption */
  psInfo->proppage[index].pszText = (LPCWSTR)p;
  TRACE("Tab %d %s\n",index,debugstr_w((LPCWSTR)p));
  p += lstrlenW((LPCWSTR)p) + 1;

  if (dwFlags & PSP_USETITLE)
  {
    WCHAR szTitle[256];
    const WCHAR *pTitle;
592
    static const WCHAR pszNull[] = { '(','n','u','l','l',')',0 };
593 594 595 596
    int len;

    if ( !HIWORD( lppsp->pszTitle ) )
    {
Frank Richter's avatar
Frank Richter committed
597
      if (!LoadStringW( lppsp->hInstance, (DWORD_PTR)lppsp->pszTitle,szTitle,sizeof(szTitle) ))
598 599 600 601 602 603 604 605 606 607
      {
        pTitle = pszNull;
	FIXME("Could not load resource #%04x?\n",LOWORD(lppsp->pszTitle));
      }
      else
        pTitle = szTitle;
    }
    else
      pTitle = lppsp->pszTitle;

608
    len = strlenW(pTitle);
609
    psInfo->proppage[index].pszText = Alloc( (len+1)*sizeof (WCHAR) );
610 611 612 613 614 615
    strcpyW( (LPWSTR)psInfo->proppage[index].pszText,pTitle);
  }

  /*
   * Build the image list for icons
   */
616
  if ((dwFlags & PSP_USEHICON) || (dwFlags & PSP_USEICONID))
617 618 619 620 621 622
  {
    HICON hIcon;
    int icon_cx = GetSystemMetrics(SM_CXSMICON);
    int icon_cy = GetSystemMetrics(SM_CYSMICON);

    if (dwFlags & PSP_USEICONID)
623
      hIcon = LoadImageW(lppsp->hInstance, lppsp->u2.pszIcon, IMAGE_ICON,
624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639
                         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
640

641 642 643 644 645
/******************************************************************************
 *            PROPSHEET_CreateDialog
 *
 * Creates the actual property sheet.
 */
Frank Richter's avatar
Frank Richter committed
646
INT_PTR PROPSHEET_CreateDialog(PropSheetInfo* psInfo)
647 648 649
{
  LRESULT ret;
  LPCVOID template;
650
  LPVOID temp = 0;
651
  HRSRC hRes;
652
  DWORD resSize;
653 654
  WORD resID = IDD_PROPSHEET;

655
  TRACE("\n");
656
  if (psInfo->ppshheader.dwFlags & INTRNL_ANY_WIZARD)
657
    resID = IDD_WIZARD;
658

659 660 661
  if( psInfo->unicode )
  {
    if(!(hRes = FindResourceW(COMCTL32_hModule,
662
                            MAKEINTRESOURCEW(resID),
663
                            (LPWSTR)RT_DIALOG)))
664 665 666 667 668 669
      return -1;
  }
  else
  {
    if(!(hRes = FindResourceA(COMCTL32_hModule,
                            MAKEINTRESOURCEA(resID),
670
                            (LPSTR)RT_DIALOG)))
671 672
      return -1;
  }
673 674

  if(!(template = (LPVOID)LoadResource(COMCTL32_hModule, hRes)))
675
    return -1;
676

677 678 679 680 681
  /*
   * Make a copy of the dialog template.
   */
  resSize = SizeofResource(COMCTL32_hModule, hRes);

682
  temp = Alloc(resSize);
683 684

  if (!temp)
685
    return -1;
686 687 688

  memcpy(temp, template, resSize);

689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704
  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;
  }

705
  if (psInfo->useCallback)
706
    (*(psInfo->ppshheader.pfnCallback))(0, PSCB_PRECREATE, (LPARAM)temp);
707

708 709 710 711
  /* 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). */
712 713
  if( psInfo->unicode )
  {
Frank Richter's avatar
Frank Richter committed
714
    ret = (INT_PTR)CreateDialogIndirectParamW(psInfo->ppshheader.hInstance,
715 716 717 718 719
                                          (LPDLGTEMPLATEW) temp,
                                          psInfo->ppshheader.hwndParent,
                                          PROPSHEET_DialogProc,
                                          (LPARAM)psInfo);
    if ( !ret ) ret = -1;
720 721 722
  }
  else
  {
Frank Richter's avatar
Frank Richter committed
723
    ret = (INT_PTR)CreateDialogIndirectParamA(psInfo->ppshheader.hInstance,
724 725 726 727 728
                                          (LPDLGTEMPLATEA) temp,
                                          psInfo->ppshheader.hwndParent,
                                          PROPSHEET_DialogProc,
                                          (LPARAM)psInfo);
    if ( !ret ) ret = -1;
729
  }
730

731
  Free(temp);
732

733 734 735 736
  return ret;
}

/******************************************************************************
737
 *            PROPSHEET_SizeMismatch
738
 *
739 740
 *     Verify that the tab control and the "largest" property sheet page dlg. template
 *     match in size.
741
 */
742
static BOOL PROPSHEET_SizeMismatch(HWND hwndDlg, PropSheetInfo* psInfo)
743 744 745 746 747 748 749 750
{
  HWND hwndTabCtrl = GetDlgItem(hwndDlg, IDC_TABCONTROL);
  RECT rcOrigTab, rcPage;

  /*
   * Original tab size.
   */
  GetClientRect(hwndTabCtrl, &rcOrigTab);
751
  TRACE("orig tab %ld %ld %ld %ld\n", rcOrigTab.left, rcOrigTab.top,
752 753 754 755 756
        rcOrigTab.right, rcOrigTab.bottom);

  /*
   * Biggest page size.
   */
Filip Navara's avatar
Filip Navara committed
757 758
  rcPage.left   = 0;
  rcPage.top    = 0;
759 760 761 762
  rcPage.right  = psInfo->width;
  rcPage.bottom = psInfo->height;

  MapDialogRect(hwndDlg, &rcPage);
763
  TRACE("biggest page %ld %ld %ld %ld\n", rcPage.left, rcPage.top,
764 765
        rcPage.right, rcPage.bottom);

766
  if ( (rcPage.right - rcPage.left) != (rcOrigTab.right - rcOrigTab.left) )
767
    return TRUE;
768
  if ( (rcPage.bottom - rcPage.top) != (rcOrigTab.bottom - rcOrigTab.top) )
769 770 771 772 773 774 775 776 777 778 779 780 781 782
    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);
783
  RECT rc,tabRect;
784 785
  int tabOffsetX, tabOffsetY, buttonHeight;
  PADDING_INFO padding = PROPSHEET_GetPaddingInfo(hwndDlg);
786
  RECT units;
787 788 789 790 791 792 793 794

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

  /*
   * Biggest page size.
   */
Filip Navara's avatar
Filip Navara committed
795 796
  rc.left   = 0;
  rc.top    = 0;
797 798 799 800 801
  rc.right  = psInfo->width;
  rc.bottom = psInfo->height;

  MapDialogRect(hwndDlg, &rc);

802 803 804 805 806
  /* retrieve the dialog units */
  units.left = units.right = 4;
  units.top = units.bottom = 8;
  MapDialogRect(hwndDlg, &units);

807 808 809
  /*
   * Resize the tab control.
   */
810 811
  GetClientRect(hwndTabCtrl,&tabRect);

812
  SendMessageW(hwndTabCtrl, TCM_ADJUSTRECT, FALSE, (LPARAM)&tabRect);
813 814 815 816

  if ((rc.bottom - rc.top) < (tabRect.bottom - tabRect.top))
  {
      rc.bottom = rc.top + tabRect.bottom - tabRect.top;
817
      psInfo->height = MulDiv((rc.bottom - rc.top),8,units.top);
818
  }
819

820 821 822
  if ((rc.right - rc.left) < (tabRect.right - tabRect.left))
  {
      rc.right = rc.left + tabRect.right - tabRect.left;
823
      psInfo->width  = MulDiv((rc.right - rc.left),4,units.left);
824 825
  }

826
  SendMessageW(hwndTabCtrl, TCM_ADJUSTRECT, TRUE, (LPARAM)&rc);
827 828 829 830 831 832

  tabOffsetX = -(rc.left);
  tabOffsetY = -(rc.top);

  rc.right -= rc.left;
  rc.bottom -= rc.top;
Frank Richter's avatar
Frank Richter committed
833 834
  TRACE("setting tab %p, rc (0,0)-(%ld,%ld)\n",
        hwndTabCtrl, rc.right, rc.bottom);
835 836 837 838 839
  SetWindowPos(hwndTabCtrl, 0, 0, 0, rc.right, rc.bottom,
               SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE);

  GetClientRect(hwndTabCtrl, &rc);

840
  TRACE("tab client rc %ld %ld %ld %ld\n",
841 842 843 844 845 846 847 848
        rc.left, rc.top, rc.right, rc.bottom);

  rc.right += ((padding.x * 2) + tabOffsetX);
  rc.bottom += (buttonHeight + (3 * padding.y) + tabOffsetY);

  /*
   * Resize the property sheet.
   */
Frank Richter's avatar
Frank Richter committed
849 850
  TRACE("setting dialog %p, rc (0,0)-(%ld,%ld)\n",
        hwndDlg, rc.right, rc.bottom);
851 852 853 854 855
  SetWindowPos(hwndDlg, 0, 0, 0, rc.right, rc.bottom,
               SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE);
  return TRUE;
}

856 857 858 859 860 861 862 863
/******************************************************************************
 *            PROPSHEET_AdjustSizeWizard
 *
 * Resizes the property sheet to fit the largest page.
 */
static BOOL PROPSHEET_AdjustSizeWizard(HWND hwndDlg, PropSheetInfo* psInfo)
{
  HWND hwndLine = GetDlgItem(hwndDlg, IDC_SUNKEN_LINE);
Filip Navara's avatar
Filip Navara committed
864
  RECT rc, lineRect, dialogRect;
865

Filip Navara's avatar
Filip Navara committed
866 867 868
  /* Biggest page size */
  rc.left   = 0;
  rc.top    = 0;
869 870 871 872
  rc.right  = psInfo->width;
  rc.bottom = psInfo->height;
  MapDialogRect(hwndDlg, &rc);

873
  TRACE("Biggest page %ld %ld %ld %ld\n", rc.left, rc.top, rc.right, rc.bottom);
874

Filip Navara's avatar
Filip Navara committed
875 876 877 878 879
  /* 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;
880

Filip Navara's avatar
Filip Navara committed
881 882 883 884
  /* Convert the client coordinates to window coordinates */
  AdjustWindowRect(&rc, GetWindowLongW(hwndDlg, GWL_STYLE), FALSE);

  /* Resize the property sheet */
Frank Richter's avatar
Frank Richter committed
885 886
  TRACE("setting dialog %p, rc (0,0)-(%ld,%ld)\n",
        hwndDlg, rc.right, rc.bottom);
Filip Navara's avatar
Filip Navara committed
887
  SetWindowPos(hwndDlg, 0, 0, 0, rc.right - rc.left, rc.bottom - rc.top,
888
               SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE);
Filip Navara's avatar
Filip Navara committed
889

890 891 892
  return TRUE;
}

893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921
/******************************************************************************
 *            PROPSHEET_AdjustButtons
 *
 * Adjusts the buttons' positions.
 */
static BOOL PROPSHEET_AdjustButtons(HWND hwndParent, PropSheetInfo* psInfo)
{
  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.
922
   */
923 924
  GetClientRect(hwndParent, &rcSheet);

925
  /*
926 927 928 929 930
   * All buttons will be at this y coordinate.
   */
  y = rcSheet.bottom - (padding.y + buttonHeight);

  /*
931
   * Position OK button and make it default.
932 933 934 935 936 937 938 939
   */
  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);

940
  SendMessageW(hwndParent, DM_SETDEFID, IDOK, 0);
941 942


943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963
  /*
   * Position Cancel button.
   */
  hwndButton = GetDlgItem(hwndParent, IDCANCEL);

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

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

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

  if (psInfo->hasApply)
  {
    if (psInfo->hasHelp)
      x = rcSheet.right - ((padding.x + buttonWidth) * 2);
    else
      x = rcSheet.right - (padding.x + buttonWidth);
964

965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980
    SetWindowPos(hwndButton, 0, x, y, 0, 0,
                 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);

    EnableWindow(hwndButton, FALSE);
  }
  else
    ShowWindow(hwndButton, SW_HIDE);

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

  if (psInfo->hasHelp)
  {
    x = rcSheet.right - (padding.x + buttonWidth);
981

982 983 984 985 986 987 988 989 990
    SetWindowPos(hwndButton, 0, x, y, 0, 0,
                 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
  }
  else
    ShowWindow(hwndButton, SW_HIDE);

  return TRUE;
}

991 992 993 994 995 996 997 998 999 1000
/******************************************************************************
 *            PROPSHEET_AdjustButtonsWizard
 *
 * Adjusts the buttons' positions.
 */
static BOOL PROPSHEET_AdjustButtonsWizard(HWND hwndParent,
                                          PropSheetInfo* psInfo)
{
  HWND hwndButton = GetDlgItem(hwndParent, IDCANCEL);
  HWND hwndLine = GetDlgItem(hwndParent, IDC_SUNKEN_LINE);
1001
  HWND hwndLineHeader = GetDlgItem(hwndParent, IDC_SUNKEN_LINEHEADER);
1002 1003 1004 1005
  RECT rcSheet;
  int x, y;
  int num_buttons = 3;
  int buttonWidth, buttonHeight, lineHeight, lineWidth;
1006
  PADDING_INFO padding = PROPSHEET_GetPaddingInfoWizard(hwndParent, psInfo);
1007 1008 1009

  if (psInfo->hasHelp)
    num_buttons++;
1010 1011
  if (psInfo->hasFinish)
    num_buttons++;
1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031

  /*
   * 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);
1032
  
1033
  /*
1034
   * Position the Back button.
1035
   */
1036
  hwndButton = GetDlgItem(hwndParent, IDC_BACK_BUTTON);
1037

1038
  x = rcSheet.right - ((padding.x + buttonWidth) * (num_buttons - 1)) - buttonWidth;
1039 1040 1041 1042

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

1043 1044 1045 1046 1047 1048 1049
  /*
   * Position the Next button.
   */
  hwndButton = GetDlgItem(hwndParent, IDC_NEXT_BUTTON);
  
  x += buttonWidth;
  
1050 1051 1052 1053
  SetWindowPos(hwndButton, 0, x, y, 0, 0,
               SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);

  /*
1054
   * Position the Finish button.
1055
   */
1056 1057 1058 1059
  hwndButton = GetDlgItem(hwndParent, IDC_FINISH_BUTTON);
  
  if (psInfo->hasFinish)
    x += padding.x + buttonWidth;
1060 1061 1062 1063

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

1064 1065 1066
  if (!psInfo->hasFinish)
    ShowWindow(hwndButton, SW_HIDE);

1067 1068 1069 1070 1071
  /*
   * Position the Cancel button.
   */
  hwndButton = GetDlgItem(hwndParent, IDCANCEL);

1072
  x += padding.x + buttonWidth;
1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083

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

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

  if (psInfo->hasHelp)
  {
1084
    x += padding.x + buttonWidth;
1085 1086 1087 1088 1089 1090 1091

    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
1092 1093
  if (psInfo->ppshheader.dwFlags &
      (PSH_WIZARD97_OLD | PSH_WIZARD97_NEW | PSH_WIZARD_LITE)) 
1094 1095
      padding.x = 0;

1096 1097 1098 1099 1100 1101 1102 1103 1104 1105
  /*
   * 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);

1106 1107 1108 1109 1110 1111 1112 1113 1114
  /*
   * 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);

1115 1116 1117
  return TRUE;
}

1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142
/******************************************************************************
 *            PROPSHEET_GetPaddingInfo
 *
 * Returns the layout information.
 */
static PADDING_INFO PROPSHEET_GetPaddingInfo(HWND hwndDlg)
{
  HWND hwndTab = GetDlgItem(hwndDlg, IDC_TABCONTROL);
  RECT rcTab;
  POINT tl;
  PADDING_INFO padding;

  GetWindowRect(hwndTab, &rcTab);

  tl.x = rcTab.left;
  tl.y = rcTab.top;

  ScreenToClient(hwndDlg, &tl);

  padding.x = tl.x;
  padding.y = tl.y;

  return padding;
}

1143 1144 1145 1146 1147
/******************************************************************************
 *            PROPSHEET_GetPaddingInfoWizard
 *
 * Returns the layout information.
 * Vertical spacing is the distance between the line and the buttons.
1148 1149 1150 1151 1152 1153
 * 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.
1154
 */
1155 1156
static PADDING_INFO PROPSHEET_GetPaddingInfoWizard(HWND hwndDlg, const PropSheetInfo*
 psInfo)
1157 1158 1159 1160
{
  PADDING_INFO padding;
  RECT rc;
  HWND hwndControl;
1161 1162
  INT idButton;
  POINT ptButton, ptLine;
1163

1164
  TRACE("\n");
1165 1166 1167 1168 1169 1170
  if (psInfo->hasHelp)
  {
	idButton = IDHELP;
  }
  else
  {
1171
    if (psInfo->ppshheader.dwFlags & INTRNL_ANY_WIZARD)
1172 1173 1174 1175 1176 1177 1178 1179 1180
    {
	idButton = IDC_NEXT_BUTTON;
    }
    else
    {
	/* hopefully this is ok */
	idButton = IDCANCEL;
    }
  }
1181

1182
  hwndControl = GetDlgItem(hwndDlg, idButton);
1183 1184
  GetWindowRect(hwndControl, &rc);

1185 1186
  ptButton.x = rc.left;
  ptButton.y = rc.top;
1187

1188
  ScreenToClient(hwndDlg, &ptButton);
1189 1190 1191 1192 1193

  /* Line */
  hwndControl = GetDlgItem(hwndDlg, IDC_SUNKEN_LINE);
  GetWindowRect(hwndControl, &rc);

1194
  ptLine.x = rc.left;
1195 1196 1197 1198
  ptLine.y = rc.bottom;

  ScreenToClient(hwndDlg, &ptLine);

1199 1200 1201 1202
  padding.y = ptButton.y - ptLine.y;

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

1204 1205
  /* this is most probably not correct, but the best we have now */
  padding.x = padding.y;
1206 1207 1208
  return padding;
}

1209 1210 1211 1212 1213 1214 1215 1216 1217
/******************************************************************************
 *            PROPSHEET_CreateTabControl
 *
 * Insert the tabs in the tab control.
 */
static BOOL PROPSHEET_CreateTabControl(HWND hwndParent,
                                       PropSheetInfo * psInfo)
{
  HWND hwndTabCtrl = GetDlgItem(hwndParent, IDC_TABCONTROL);
1218
  TCITEMW item;
1219
  int i, nTabs;
Alexandre Julliard's avatar
Alexandre Julliard committed
1220
  int iImage = 0;
1221

1222
  TRACE("\n");
1223
  item.mask = TCIF_TEXT;
1224
  item.cchTextMax = MAX_TABTEXT_LENGTH;
1225

1226
  nTabs = psInfo->nPages;
1227

1228 1229 1230 1231 1232
  /*
   * Set the image list for icons.
   */
  if (psInfo->hImageList)
  {
1233
    SendMessageW(hwndTabCtrl, TCM_SETIMAGELIST, 0, (LPARAM)psInfo->hImageList);
1234 1235
  }

1236
  SendMessageW(GetDlgItem(hwndTabCtrl, IDC_TABCONTROL), WM_SETREDRAW, 0, 0);
1237 1238
  for (i = 0; i < nTabs; i++)
  {
Alexandre Julliard's avatar
Alexandre Julliard committed
1239 1240 1241 1242 1243 1244 1245 1246 1247
    if ( psInfo->proppage[i].hasIcon )
    {
      item.mask |= TCIF_IMAGE;
      item.iImage = iImage++;
    }
    else
    {
      item.mask &= ~TCIF_IMAGE;
    }
1248

1249 1250
    item.pszText = (LPWSTR) psInfo->proppage[i].pszText;
    SendMessageW(hwndTabCtrl, TCM_INSERTITEMW, (WPARAM)i, (LPARAM)&item);
1251
  }
1252
  SendMessageW(GetDlgItem(hwndTabCtrl, IDC_TABCONTROL), WM_SETREDRAW, 1, 0);
1253 1254 1255

  return TRUE;
}
1256 1257 1258 1259 1260 1261 1262

/******************************************************************************
 *            PROPSHEET_WizardSubclassProc
 *
 * Subclassing window procedure for wizard extrior pages to prevent drawing
 * background and so drawing above the watermark.
 */
1263
static LRESULT CALLBACK
1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278
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);
}

1279 1280 1281 1282
/*
 * Get the size of an in-memory Template
 *
 *( Based on the code of PROPSHEET_CollectPageInfo)
1283
 * See also dialog.c/DIALOG_ParseTemplate32().
1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294
 */

static UINT GetTemplateSize(DLGTEMPLATE* pTemplate)

{
  const WORD*  p = (const WORD *)pTemplate;
  BOOL  istemplateex = (((MyDLGTEMPLATEEX*)pTemplate)->signature == 0xFFFF);
  WORD nrofitems;

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

1297
    TRACE("is DLGTEMPLATEEX\n");
1298 1299 1300 1301 1302 1303 1304 1305
    p++;       /* dlgVer    */
    p++;       /* signature */
    p += 2;    /* help ID   */
    p += 2;    /* ext style */
    p += 2;    /* style     */
  }
  else
  {
1306
    /* DLGTEMPLATE */
1307

1308
    TRACE("is DLGTEMPLATE\n");
1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340
    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:
      TRACE("menu %s\n",debugstr_w((LPCWSTR)p));
      p += lstrlenW( (LPCWSTR)p ) + 1;
      break;
  }

  /* class */
  switch ((WORD)*p)
  {
    case 0x0000:
      p++;
      break;
    case 0xffff:
1341
      p += 2; /* 0xffff plus predefined window class ordinal value */
1342 1343 1344 1345 1346 1347 1348
      break;
    default:
      TRACE("class %s\n",debugstr_w((LPCWSTR)p));
      p += lstrlenW( (LPCWSTR)p ) + 1;
      break;
  }

1349
  /* title */
1350 1351 1352
  TRACE("title %s\n",debugstr_w((LPCWSTR)p));
  p += lstrlenW((LPCWSTR)p) + 1;

1353
  /* font, if DS_SETFONT set */
1354 1355 1356 1357 1358
  if ((DS_SETFONT & ((istemplateex)?  ((MyDLGTEMPLATEEX*)pTemplate)->style :
		     pTemplate->style)))
    {
      p+=(istemplateex)?3:1;
      TRACE("font %s\n",debugstr_w((LPCWSTR)p));
1359
      p += lstrlenW( (LPCWSTR)p ) + 1; /* the font name */
1360 1361
    }

1362 1363
  /* now process the DLGITEMTEMPLATE(EX) structs (plus custom data)
   * that are following the DLGTEMPLATE(EX) data */
1364 1365 1366
  TRACE("%d items\n",nrofitems);
  while (nrofitems > 0)
    {
Frank Richter's avatar
Frank Richter committed
1367
      p = (WORD*)(((DWORD_PTR)p + 3) & ~3); /* DWORD align */
1368
      
1369
      /* skip header */
1370 1371
      p += (istemplateex ? sizeof(MyDLGITEMTEMPLATEEX) : sizeof(DLGITEMTEMPLATE))/sizeof(WORD);
      
1372
      /* check class */
1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386
      switch ((WORD)*p)
	{
	case 0x0000:
	  p++;
	  break;
	case 0xffff:
	  TRACE("class ordinal 0x%08lx\n",*(DWORD*)p);
	  p += 2;
	  break;
	default:
	  TRACE("class %s\n",debugstr_w((LPCWSTR)p));
	  p += lstrlenW( (LPCWSTR)p ) + 1;
	  break;
	}
1387 1388

      /* check title text */
1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402
      switch ((WORD)*p)
	{
	case 0x0000:
	  p++;
	  break;
	case 0xffff:
	  TRACE("text ordinal 0x%08lx\n",*(DWORD*)p);
	  p += 2;
	  break;
	default:
	  TRACE("text %s\n",debugstr_w((LPCWSTR)p));
	  p += lstrlenW( (LPCWSTR)p ) + 1;
	  break;
	}
1403
      p += *p / sizeof(WORD) + 1;    /* Skip extra data */
1404 1405 1406 1407 1408 1409 1410
      --nrofitems;
    }
  
  TRACE("%p %p size 0x%08x\n",p, (WORD*)pTemplate,sizeof(WORD)*(p - (WORD*)pTemplate));
  return (p - (WORD*)pTemplate)*sizeof(WORD);
  
}
1411 1412 1413 1414

/******************************************************************************
 *            PROPSHEET_CreatePage
 *
1415
 * Creates a page.
1416
 */
1417
static BOOL PROPSHEET_CreatePage(HWND hwndParent,
1418
                                int index,
1419
                                const PropSheetInfo * psInfo,
1420
                                LPCPROPSHEETPAGEW ppshpage)
1421 1422 1423
{
  DLGTEMPLATE* pTemplate;
  HWND hwndPage;
1424 1425
  DWORD resSize;
  LPVOID temp = NULL;
1426

1427
  TRACE("index %d\n", index);
1428

1429 1430 1431 1432 1433
  if (ppshpage == NULL)
  {
    return FALSE;
  }

1434
  if (ppshpage->dwFlags & PSP_DLGINDIRECT)
1435 1436 1437 1438
    {
      pTemplate = (DLGTEMPLATE*)ppshpage->u.pResource;
      resSize = GetTemplateSize(pTemplate);
    }
1439
  else if(ppshpage->dwFlags & PSP_INTERNAL_UNICODE)
1440
  {
1441 1442 1443
    HRSRC hResource;
    HANDLE hTemplate;

1444
    hResource = FindResourceW(ppshpage->hInstance,
1445
                                    ppshpage->u.pszTemplate,
1446
                                    (LPWSTR)RT_DIALOG);
1447 1448 1449 1450 1451 1452 1453 1454 1455
    if(!hResource)
	return FALSE;

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

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

1456
    pTemplate = (LPDLGTEMPLATEW)LockResource(hTemplate);
1457 1458 1459
    /*
     * Make a copy of the dialog template to make it writable
     */
1460
  }
1461 1462 1463 1464 1465 1466 1467
  else
  {
    HRSRC hResource;
    HANDLE hTemplate;

    hResource = FindResourceA(ppshpage->hInstance,
                                    (LPSTR)ppshpage->u.pszTemplate,
1468
                                    (LPSTR)RT_DIALOG);
1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482
    if(!hResource)
	return FALSE;

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

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

    pTemplate = (LPDLGTEMPLATEA)LockResource(hTemplate);
    /*
     * Make a copy of the dialog template to make it writable
     */
  }
1483
  temp = Alloc(resSize);
1484 1485 1486
  if (!temp)
    return FALSE;
  
1487
  TRACE("copying pTemplate %p into temp %p (%ld)\n", pTemplate, temp, resSize);
1488 1489
  memcpy(temp, pTemplate, resSize);
  pTemplate = temp;
1490 1491 1492

  if (((MyDLGTEMPLATEEX*)pTemplate)->signature == 0xFFFF)
  {
Filip Navara's avatar
Filip Navara committed
1493
    ((MyDLGTEMPLATEEX*)pTemplate)->style |= WS_CHILD | WS_TABSTOP | DS_CONTROL;
1494 1495 1496 1497
    ((MyDLGTEMPLATEEX*)pTemplate)->style &= ~DS_MODALFRAME;
    ((MyDLGTEMPLATEEX*)pTemplate)->style &= ~WS_CAPTION;
    ((MyDLGTEMPLATEEX*)pTemplate)->style &= ~WS_SYSMENU;
    ((MyDLGTEMPLATEEX*)pTemplate)->style &= ~WS_POPUP;
1498
    ((MyDLGTEMPLATEEX*)pTemplate)->style &= ~WS_DISABLED;
Alexandre Julliard's avatar
Alexandre Julliard committed
1499
    ((MyDLGTEMPLATEEX*)pTemplate)->style &= ~WS_VISIBLE;
1500
    ((MyDLGTEMPLATEEX*)pTemplate)->style &= ~WS_THICKFRAME;
1501 1502

    ((MyDLGTEMPLATEEX*)pTemplate)->exStyle |= WS_EX_CONTROLPARENT;
1503 1504 1505
  }
  else
  {
Filip Navara's avatar
Filip Navara committed
1506
    pTemplate->style |= WS_CHILD | WS_TABSTOP | DS_CONTROL;
1507 1508 1509 1510
    pTemplate->style &= ~DS_MODALFRAME;
    pTemplate->style &= ~WS_CAPTION;
    pTemplate->style &= ~WS_SYSMENU;
    pTemplate->style &= ~WS_POPUP;
1511
    pTemplate->style &= ~WS_DISABLED;
Alexandre Julliard's avatar
Alexandre Julliard committed
1512
    pTemplate->style &= ~WS_VISIBLE;
1513
    pTemplate->style &= ~WS_THICKFRAME;
1514 1515

    pTemplate->dwExtendedStyle |= WS_EX_CONTROLPARENT;
1516 1517 1518
  }

  if (psInfo->proppage[index].useCallback)
1519
    (*(ppshpage->pfnCallback))(0, PSPCB_CREATE,
1520
                               (LPPROPSHEETPAGEW)ppshpage);
1521

1522 1523 1524 1525 1526 1527 1528 1529
  if(ppshpage->dwFlags & PSP_INTERNAL_UNICODE)
     hwndPage = CreateDialogIndirectParamW(ppshpage->hInstance,
					pTemplate,
					hwndParent,
					ppshpage->pfnDlgProc,
					(LPARAM)ppshpage);
  else
     hwndPage = CreateDialogIndirectParamA(ppshpage->hInstance,
1530 1531 1532
					pTemplate,
					hwndParent,
					ppshpage->pfnDlgProc,
Marcus Meissner's avatar
Marcus Meissner committed
1533
					(LPARAM)ppshpage);
1534 1535
  /* Free a no more needed copy */
  if(temp)
1536
      Free(temp);
1537

1538
  psInfo->proppage[index].hwndPage = hwndPage;
1539

1540 1541 1542 1543 1544 1545 1546 1547
  /* 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);
  }
1548 1549
  if (!(psInfo->ppshheader.dwFlags & INTRNL_ANY_WIZARD))
      EnableThemeDialogTexture (hwndPage, ETDT_ENABLETAB);
1550

1551 1552 1553
  return TRUE;
}

1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569
/******************************************************************************
 *            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))
    {
      ((PropSheetInfo *)psInfo)->ppshheader.u4.hbmWatermark = 
Frank Richter's avatar
Frank Richter committed
1570
        CreateMappedBitmap(psInfo->ppshheader.hInstance, (INT_PTR)psInfo->ppshheader.u4.pszbmWatermark, 0, NULL, 0);
1571 1572 1573 1574 1575 1576 1577
    }

    /* Same behavior as for watermarks */
    if ((psInfo->ppshheader.dwFlags & PSH_HEADER) &&
        !(psInfo->ppshheader.dwFlags & PSH_USEHBMHEADER))
    {
      ((PropSheetInfo *)psInfo)->ppshheader.u5.hbmHeader = 
Frank Richter's avatar
Frank Richter committed
1578
        CreateMappedBitmap(psInfo->ppshheader.hInstance, (INT_PTR)psInfo->ppshheader.u5.pszbmHeader, 0, NULL, 0);
1579 1580 1581 1582 1583
    }
  }
}


1584 1585 1586 1587 1588 1589 1590
/******************************************************************************
 *            PROPSHEET_ShowPage
 *
 * Displays or creates the specified page.
 */
static BOOL PROPSHEET_ShowPage(HWND hwndDlg, int index, PropSheetInfo * psInfo)
{
1591
  HWND hwndTabCtrl;
1592 1593
  HWND hwndLineHeader;
  LPCPROPSHEETPAGEW ppshpage;
1594 1595

  TRACE("active_page %d, index %d\n", psInfo->active_page, index);
1596
  if (index == psInfo->active_page)
1597
  {
1598
      if (GetTopWindow(hwndDlg) != psInfo->proppage[index].hwndPage)
Alexandre Julliard's avatar
Alexandre Julliard committed
1599
          SetWindowPos(psInfo->proppage[index].hwndPage, HWND_TOP, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE);
1600 1601
      return TRUE;
  }
1602

1603
  ppshpage = (LPCPROPSHEETPAGEW)psInfo->proppage[index].hpage;
Alexandre Julliard's avatar
Alexandre Julliard committed
1604
  if (psInfo->proppage[index].hwndPage == 0)
1605
  {
Alexandre Julliard's avatar
Alexandre Julliard committed
1606
     PROPSHEET_CreatePage(hwndDlg, index, psInfo, ppshpage);
1607
  }
Alexandre Julliard's avatar
Alexandre Julliard committed
1608

1609 1610
  if ((psInfo->ppshheader.dwFlags & INTRNL_ANY_WIZARD) &&
      (ppshpage->dwFlags & PSP_USETITLE))
1611 1612 1613 1614
  {
     PROPSHEET_SetTitleW(hwndDlg, psInfo->ppshheader.dwFlags,
                         psInfo->proppage[index].pszText);
  }
1615

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

1619
  ShowWindow(psInfo->proppage[index].hwndPage, SW_SHOW);
1620

1621 1622 1623
  /* 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);
1624
  SendMessageW(hwndTabCtrl, TCM_SETCURSEL, index, 0);
1625

1626
  psInfo->active_page = index;
Alexandre Julliard's avatar
Alexandre Julliard committed
1627
  psInfo->activeValid = TRUE;
1628

1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639
  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);
  }

1640 1641 1642
  return TRUE;
}

1643 1644 1645 1646 1647
/******************************************************************************
 *            PROPSHEET_Back
 */
static BOOL PROPSHEET_Back(HWND hwndDlg)
{
Alexandre Julliard's avatar
Alexandre Julliard committed
1648
  PSHNOTIFY psn;
1649
  HWND hwndPage;
1650
  PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwndDlg,
1651
                                                    PropSheetInfoStr);
1652
  LRESULT result;
1653
  int idx;
1654

1655
  TRACE("active_page %d\n", psInfo->active_page);
Alexandre Julliard's avatar
Alexandre Julliard committed
1656
  if (psInfo->active_page < 0)
1657 1658
     return FALSE;

Alexandre Julliard's avatar
Alexandre Julliard committed
1659 1660 1661 1662
  psn.hdr.code     = PSN_WIZBACK;
  psn.hdr.hwndFrom = hwndDlg;
  psn.hdr.idFrom   = 0;
  psn.lParam       = 0;
1663

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

1666
  result = SendMessageW(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn);
1667
  if (result == -1)
1668
    return FALSE;
1669 1670 1671 1672
  else if (result == 0)
     idx = psInfo->active_page - 1;
  else
     idx = PROPSHEET_FindPageByResId(psInfo, result);
1673

1674
  if (idx >= 0 && idx < psInfo->nPages)
1675
  {
1676 1677
     if (PROPSHEET_CanSetCurSel(hwndDlg))
        PROPSHEET_SetCurSel(hwndDlg, idx, -1, 0);
1678
  }
1679 1680 1681 1682 1683 1684 1685 1686
  return TRUE;
}

/******************************************************************************
 *            PROPSHEET_Next
 */
static BOOL PROPSHEET_Next(HWND hwndDlg)
{
Alexandre Julliard's avatar
Alexandre Julliard committed
1687
  PSHNOTIFY psn;
1688 1689
  HWND hwndPage;
  LRESULT msgResult = 0;
1690
  PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwndDlg,
1691
                                                    PropSheetInfoStr);
1692
  int idx;
1693

1694
  TRACE("active_page %d\n", psInfo->active_page);
Alexandre Julliard's avatar
Alexandre Julliard committed
1695
  if (psInfo->active_page < 0)
1696 1697
     return FALSE;

Alexandre Julliard's avatar
Alexandre Julliard committed
1698 1699 1700 1701
  psn.hdr.code     = PSN_WIZNEXT;
  psn.hdr.hwndFrom = hwndDlg;
  psn.hdr.idFrom   = 0;
  psn.lParam       = 0;
1702

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

1705
  msgResult = SendMessageW(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn);
1706 1707
  if (msgResult == -1)
    return FALSE;
1708 1709 1710 1711
  else if (msgResult == 0)
     idx = psInfo->active_page + 1;
  else
     idx = PROPSHEET_FindPageByResId(psInfo, msgResult);
1712

1713
  if (idx < psInfo->nPages )
1714
  {
1715 1716
     if (PROPSHEET_CanSetCurSel(hwndDlg) != FALSE)
        PROPSHEET_SetCurSel(hwndDlg, idx, 1, 0);
1717
  }
1718 1719 1720 1721 1722 1723 1724 1725 1726

  return TRUE;
}

/******************************************************************************
 *            PROPSHEET_Finish
 */
static BOOL PROPSHEET_Finish(HWND hwndDlg)
{
Alexandre Julliard's avatar
Alexandre Julliard committed
1727
  PSHNOTIFY psn;
1728 1729
  HWND hwndPage;
  LRESULT msgResult = 0;
1730
  PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwndDlg,
1731 1732
                                                    PropSheetInfoStr);

1733
  TRACE("active_page %d\n", psInfo->active_page);
1734 1735 1736
  if (psInfo->active_page < 0)
     return FALSE;

Alexandre Julliard's avatar
Alexandre Julliard committed
1737 1738 1739 1740
  psn.hdr.code     = PSN_WIZFINISH;
  psn.hdr.hwndFrom = hwndDlg;
  psn.hdr.idFrom   = 0;
  psn.lParam       = 0;
1741

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

1744
  msgResult = SendMessageW(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn);
1745 1746 1747 1748 1749 1750 1751

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

  if (msgResult != 0)
    return FALSE;

  if (psInfo->isModeless)
Alexandre Julliard's avatar
Alexandre Julliard committed
1752
    psInfo->activeValid = FALSE;
1753
  else
1754
    psInfo->ended = TRUE;
1755 1756 1757 1758

  return TRUE;
}

1759 1760 1761
/******************************************************************************
 *            PROPSHEET_Apply
 */
Alexandre Julliard's avatar
Alexandre Julliard committed
1762
static BOOL PROPSHEET_Apply(HWND hwndDlg, LPARAM lParam)
1763 1764 1765
{
  int i;
  HWND hwndPage;
Alexandre Julliard's avatar
Alexandre Julliard committed
1766
  PSHNOTIFY psn;
1767
  PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwndDlg,
1768 1769
                                                    PropSheetInfoStr);

1770
  TRACE("active_page %d\n", psInfo->active_page);
1771 1772 1773
  if (psInfo->active_page < 0)
     return FALSE;

Alexandre Julliard's avatar
Alexandre Julliard committed
1774 1775 1776
  psn.hdr.hwndFrom = hwndDlg;
  psn.hdr.idFrom   = 0;
  psn.lParam       = 0;
1777

1778 1779 1780 1781

  /*
   * Send PSN_KILLACTIVE to the current page.
   */
Alexandre Julliard's avatar
Alexandre Julliard committed
1782
  psn.hdr.code = PSN_KILLACTIVE;
1783 1784 1785

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

1786
  if (SendMessageW(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn) != FALSE)
1787 1788 1789 1790 1791
    return FALSE;

  /*
   * Send PSN_APPLY to all pages.
   */
Alexandre Julliard's avatar
Alexandre Julliard committed
1792 1793
  psn.hdr.code = PSN_APPLY;
  psn.lParam   = lParam;
1794

1795
  for (i = 0; i < psInfo->nPages; i++)
1796 1797
  {
    hwndPage = psInfo->proppage[i].hwndPage;
Alexandre Julliard's avatar
Alexandre Julliard committed
1798 1799
    if (hwndPage)
    {
1800
       switch (SendMessageW(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn))
1801 1802 1803 1804 1805 1806 1807
       {
       case PSNRET_INVALID:
           PROPSHEET_ShowPage(hwndDlg, i, psInfo);
           /* fall through */
       case PSNRET_INVALID_NOCHANGEPAGE:
           return FALSE;
       }
Alexandre Julliard's avatar
Alexandre Julliard committed
1808 1809
    }
  }
1810

Alexandre Julliard's avatar
Alexandre Julliard committed
1811 1812 1813 1814 1815 1816 1817 1818 1819
  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;
1820
     SendMessageW(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn);
1821 1822 1823 1824 1825 1826 1827 1828
  }

  return TRUE;
}

/******************************************************************************
 *            PROPSHEET_Cancel
 */
Alexandre Julliard's avatar
Alexandre Julliard committed
1829
static void PROPSHEET_Cancel(HWND hwndDlg, LPARAM lParam)
1830
{
1831
  PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwndDlg,
1832
                                                    PropSheetInfoStr);
1833
  HWND hwndPage;
Alexandre Julliard's avatar
Alexandre Julliard committed
1834 1835
  PSHNOTIFY psn;
  int i;
1836

1837
  TRACE("active_page %d\n", psInfo->active_page);
1838 1839 1840 1841
  if (psInfo->active_page < 0)
     return;

  hwndPage = psInfo->proppage[psInfo->active_page].hwndPage;
Alexandre Julliard's avatar
Alexandre Julliard committed
1842 1843 1844 1845
  psn.hdr.code     = PSN_QUERYCANCEL;
  psn.hdr.hwndFrom = hwndDlg;
  psn.hdr.idFrom   = 0;
  psn.lParam       = 0;
1846

1847
  if (SendMessageW(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn))
1848 1849
    return;

Alexandre Julliard's avatar
Alexandre Julliard committed
1850 1851
  psn.hdr.code = PSN_RESET;
  psn.lParam   = lParam;
1852

Alexandre Julliard's avatar
Alexandre Julliard committed
1853 1854 1855
  for (i = 0; i < psInfo->nPages; i++)
  {
    hwndPage = psInfo->proppage[i].hwndPage;
1856

Alexandre Julliard's avatar
Alexandre Julliard committed
1857
    if (hwndPage)
1858
       SendMessageW(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn);
Alexandre Julliard's avatar
Alexandre Julliard committed
1859
  }
1860 1861

  if (psInfo->isModeless)
Alexandre Julliard's avatar
Alexandre Julliard committed
1862 1863 1864 1865
  {
     /* makes PSM_GETCURRENTPAGEHWND return NULL */
     psInfo->activeValid = FALSE;
  }
1866
  else
1867
    psInfo->ended = TRUE;
1868 1869
}

1870 1871 1872 1873 1874
/******************************************************************************
 *            PROPSHEET_Help
 */
static void PROPSHEET_Help(HWND hwndDlg)
{
1875
  PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwndDlg,
1876
                                                    PropSheetInfoStr);
1877
  HWND hwndPage;
Alexandre Julliard's avatar
Alexandre Julliard committed
1878
  PSHNOTIFY psn;
1879

1880
  TRACE("active_page %d\n", psInfo->active_page);
1881 1882 1883 1884
  if (psInfo->active_page < 0)
     return;

  hwndPage = psInfo->proppage[psInfo->active_page].hwndPage;
Alexandre Julliard's avatar
Alexandre Julliard committed
1885 1886 1887 1888
  psn.hdr.code     = PSN_HELP;
  psn.hdr.hwndFrom = hwndDlg;
  psn.hdr.idFrom   = 0;
  psn.lParam       = 0;
1889

1890
  SendMessageW(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn);
1891 1892
}

1893 1894 1895 1896 1897 1898
/******************************************************************************
 *            PROPSHEET_Changed
 */
static void PROPSHEET_Changed(HWND hwndDlg, HWND hwndDirtyPage)
{
  int i;
1899
  PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwndDlg,
1900 1901
                                                    PropSheetInfoStr);

1902
  TRACE("\n");
1903
  if (!psInfo) return;
1904 1905 1906
  /*
   * Set the dirty flag of this page.
   */
1907
  for (i = 0; i < psInfo->nPages; i++)
1908 1909 1910 1911
  {
    if (psInfo->proppage[i].hwndPage == hwndDirtyPage)
      psInfo->proppage[i].isDirty = TRUE;
  }
1912

1913 1914 1915 1916 1917 1918
  /*
   * Enable the Apply button.
   */
  if (psInfo->hasApply)
  {
    HWND hwndApplyBtn = GetDlgItem(hwndDlg, IDC_APPLY_BUTTON);
1919

1920 1921 1922
    EnableWindow(hwndApplyBtn, TRUE);
  }
}
1923

1924 1925 1926 1927 1928 1929 1930 1931
/******************************************************************************
 *            PROPSHEET_UnChanged
 */
static void PROPSHEET_UnChanged(HWND hwndDlg, HWND hwndCleanPage)
{
  int i;
  BOOL noPageDirty = TRUE;
  HWND hwndApplyBtn = GetDlgItem(hwndDlg, IDC_APPLY_BUTTON);
1932
  PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwndDlg,
1933
                                                    PropSheetInfoStr);
1934

1935
  TRACE("\n");
1936
  if ( !psInfo ) return;
1937
  for (i = 0; i < psInfo->nPages; i++)
1938 1939 1940 1941
  {
    /* set the specified page as clean */
    if (psInfo->proppage[i].hwndPage == hwndCleanPage)
      psInfo->proppage[i].isDirty = FALSE;
1942

1943 1944 1945 1946
    /* look to see if there's any dirty pages */
    if (psInfo->proppage[i].isDirty)
      noPageDirty = FALSE;
  }
1947

1948 1949 1950 1951 1952 1953
  /*
   * Disable Apply button.
   */
  if (noPageDirty)
    EnableWindow(hwndApplyBtn, FALSE);
}
1954

1955 1956 1957 1958 1959
/******************************************************************************
 *            PROPSHEET_PressButton
 */
static void PROPSHEET_PressButton(HWND hwndDlg, int buttonID)
{
1960
  TRACE("buttonID %d\n", buttonID);
1961 1962 1963
  switch (buttonID)
  {
    case PSBTN_APPLYNOW:
1964
      PROPSHEET_DoCommand(hwndDlg, IDC_APPLY_BUTTON);
1965 1966
      break;
    case PSBTN_BACK:
1967
      PROPSHEET_Back(hwndDlg);
1968 1969
      break;
    case PSBTN_CANCEL:
1970
      PROPSHEET_DoCommand(hwndDlg, IDCANCEL);
1971 1972
      break;
    case PSBTN_FINISH:
1973
      PROPSHEET_Finish(hwndDlg);
1974 1975
      break;
    case PSBTN_HELP:
1976
      PROPSHEET_DoCommand(hwndDlg, IDHELP);
1977 1978
      break;
    case PSBTN_NEXT:
1979
      PROPSHEET_Next(hwndDlg);
1980 1981
      break;
    case PSBTN_OK:
1982
      PROPSHEET_DoCommand(hwndDlg, IDOK);
1983 1984
      break;
    default:
1985
      FIXME("Invalid button index %d\n", buttonID);
1986 1987
  }
}
1988

1989 1990

/*************************************************************************
1991
 * BOOL PROPSHEET_CanSetCurSel [Internal]
1992
 *
1993
 * Test whether the current page can be changed by sending a PSN_KILLACTIVE
1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004
 *
 * PARAMS
 *     hwndDlg        [I] handle to a Dialog hWnd
 *
 * RETURNS
 *     TRUE if Current Selection can change
 *
 * NOTES
 */
static BOOL PROPSHEET_CanSetCurSel(HWND hwndDlg)
{
2005
  PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwndDlg,
2006 2007
                                                    PropSheetInfoStr);
  HWND hwndPage;
Alexandre Julliard's avatar
Alexandre Julliard committed
2008
  PSHNOTIFY psn;
2009
  BOOL res = FALSE;
2010

2011
  TRACE("active_page %d\n", psInfo->active_page);
Alexandre Julliard's avatar
Alexandre Julliard committed
2012
  if (!psInfo)
2013 2014 2015 2016
  {
     res = FALSE;
     goto end;
  }
Alexandre Julliard's avatar
Alexandre Julliard committed
2017 2018

  if (psInfo->active_page < 0)
2019 2020 2021 2022
  {
     res = TRUE;
     goto end;
  }
Alexandre Julliard's avatar
Alexandre Julliard committed
2023

2024 2025 2026 2027
  /*
   * Notify the current page.
   */
  hwndPage = psInfo->proppage[psInfo->active_page].hwndPage;
Alexandre Julliard's avatar
Alexandre Julliard committed
2028 2029 2030 2031
  psn.hdr.code     = PSN_KILLACTIVE;
  psn.hdr.hwndFrom = hwndDlg;
  psn.hdr.idFrom   = 0;
  psn.lParam       = 0;
2032

2033
  res = !SendMessageW(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn);
2034 2035 2036 2037

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

2040 2041 2042 2043 2044
/******************************************************************************
 *            PROPSHEET_SetCurSel
 */
static BOOL PROPSHEET_SetCurSel(HWND hwndDlg,
                                int index,
2045 2046 2047
				int skipdir,
                                HPROPSHEETPAGE hpage
				)
2048
{
2049
  PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwndDlg, PropSheetInfoStr);
2050
  HWND hwndHelp  = GetDlgItem(hwndDlg, IDHELP);
2051
  HWND hwndTabControl = GetDlgItem(hwndDlg, IDC_TABCONTROL);
2052

2053
  TRACE("index %d, skipdir %d, hpage %p\n", index, skipdir, hpage);
Alexandre Julliard's avatar
Alexandre Julliard committed
2054
  /* hpage takes precedence over index */
2055
  if (hpage != NULL)
Thuy Nguyen's avatar
Thuy Nguyen committed
2056 2057
    index = PROPSHEET_GetPageIndex(hpage, psInfo);

2058 2059 2060 2061
  if (index < 0 || index >= psInfo->nPages)
  {
    TRACE("Could not find page to select!\n");
    return FALSE;
Thuy Nguyen's avatar
Thuy Nguyen committed
2062 2063
  }

2064
  while (1) {
2065 2066
    int result;
    PSHNOTIFY psn;
2067
    RECT rc;
Filip Navara's avatar
Filip Navara committed
2068
    LPCPROPSHEETPAGEW ppshpage = (LPCPROPSHEETPAGEW)psInfo->proppage[index].hpage;
2069

2070 2071 2072
    if (hwndTabControl)
	SendMessageW(hwndTabControl, TCM_SETCURSEL, index, 0);

2073 2074 2075 2076 2077
    psn.hdr.code     = PSN_SETACTIVE;
    psn.hdr.hwndFrom = hwndDlg;
    psn.hdr.idFrom   = 0;
    psn.lParam       = 0;

2078 2079 2080
    if (!psInfo->proppage[index].hwndPage) {
      PROPSHEET_CreatePage(hwndDlg, index, psInfo, ppshpage);
    }
2081

Filip Navara's avatar
Filip Navara committed
2082 2083 2084 2085
    /* 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
2086
     * not only when it's created (some applications depend on it). */
Filip Navara's avatar
Filip Navara committed
2087 2088 2089 2090 2091 2092 2093
    PROPSHEET_GetPageRect(psInfo, hwndDlg, &rc, ppshpage);
    TRACE("setting page %p, rc (%ld,%ld)-(%ld,%ld) w=%ld, h=%ld\n",
          psInfo->proppage[index].hwndPage, rc.left, rc.top, rc.right, rc.bottom,
          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);
2094

2095
    result = SendMessageW(psInfo->proppage[index].hwndPage, WM_NOTIFY, 0, (LPARAM) &psn);
2096 2097 2098 2099 2100 2101
    if (!result)
      break;
    if (result == -1) {
      index+=skipdir;
      if (index < 0) {
	index = 0;
2102
	WARN("Tried to skip before first property sheet page!\n");
2103 2104 2105
	break;
      }
      if (index >= psInfo->nPages) {
2106
	WARN("Tried to skip after last property sheet page!\n");
2107 2108 2109 2110
	index = psInfo->nPages-1;
	break;
      }
    }
2111 2112
    else if (result != 0)
    {
2113 2114 2115 2116 2117 2118 2119 2120
      int old_index = index;
      index = PROPSHEET_FindPageByResId(psInfo, result);
      if(index >= psInfo->nPages) {
        index = old_index;
        WARN("Tried to skip to nonexistant page by res id\n");
        break;
      }
      continue;
2121
    }
2122
  }
2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135
  /*
   * Display the new page.
   */
  PROPSHEET_ShowPage(hwndDlg, index, psInfo);

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

  return TRUE;
}

2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154
/******************************************************************************
 *            PROPSHEET_SetCurSelId
 *
 * Selects the page, specified by resource id.
 */
static void PROPSHEET_SetCurSelId(HWND hwndDlg, int id)
{
      int idx;
      PropSheetInfo* psInfo =
          (PropSheetInfo*) GetPropW(hwndDlg, PropSheetInfoStr);

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

2155 2156 2157 2158 2159
/******************************************************************************
 *            PROPSHEET_SetTitleA
 */
static void PROPSHEET_SetTitleA(HWND hwndDlg, DWORD dwStyle, LPCSTR lpszText)
{
2160 2161 2162
  if(HIWORD(lpszText))
  {
     WCHAR szTitle[256];
2163
     MultiByteToWideChar(CP_ACP, 0, lpszText, -1,
2164
                         szTitle, sizeof(szTitle)/sizeof(WCHAR));
2165 2166 2167 2168 2169 2170 2171
     PROPSHEET_SetTitleW(hwndDlg, dwStyle, szTitle);
  }
  else
  {
     PROPSHEET_SetTitleW(hwndDlg, dwStyle, (LPCWSTR)lpszText);
  }
}
2172

2173 2174 2175 2176 2177 2178 2179 2180 2181
/******************************************************************************
 *            PROPSHEET_SetTitleW
 */
static void PROPSHEET_SetTitleW(HWND hwndDlg, DWORD dwStyle, LPCWSTR lpszText)
{
  PropSheetInfo*	psInfo = (PropSheetInfo*) GetPropW(hwndDlg, PropSheetInfoStr);
  WCHAR			szTitle[256];

  TRACE("'%s' (style %08lx)\n", debugstr_w(lpszText), dwStyle);
2182
  if (HIWORD(lpszText) == 0) {
2183
    if (!LoadStringW(psInfo->ppshheader.hInstance,
2184
                     LOWORD(lpszText), szTitle, sizeof(szTitle)-sizeof(WCHAR)))
2185 2186 2187
      return;
    lpszText = szTitle;
  }
2188 2189
  if (dwStyle & PSH_PROPTITLE)
  {
2190 2191 2192
    WCHAR* dest;
    int lentitle = strlenW(lpszText);
    int lenprop  = strlenW(psInfo->strPropertiesFor);
2193

2194
    dest = Alloc( (lentitle + lenprop + 1)*sizeof (WCHAR));
2195 2196
    strcpyW(dest, psInfo->strPropertiesFor);
    strcatW(dest, lpszText);
2197

2198
    SetWindowTextW(hwndDlg, dest);
2199
    Free(dest);
2200 2201
  }
  else
2202
    SetWindowTextW(hwndDlg, lpszText);
2203 2204
}

2205 2206 2207 2208 2209
/******************************************************************************
 *            PROPSHEET_SetFinishTextA
 */
static void PROPSHEET_SetFinishTextA(HWND hwndDlg, LPCSTR lpszText)
{
2210
  PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwndDlg, PropSheetInfoStr);
2211 2212
  HWND hwndButton = GetDlgItem(hwndDlg, IDC_FINISH_BUTTON);

2213
  TRACE("'%s'\n", lpszText);
2214 2215 2216 2217 2218 2219
  /* Set text, show and enable the Finish button */
  SetWindowTextA(hwndButton, lpszText);
  ShowWindow(hwndButton, SW_SHOW);
  EnableWindow(hwndButton, TRUE);

  /* Make it default pushbutton */
2220
  SendMessageW(hwndDlg, DM_SETDEFID, IDC_FINISH_BUTTON, 0);
2221 2222 2223 2224 2225

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

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

2234 2235 2236 2237 2238
/******************************************************************************
 *            PROPSHEET_SetFinishTextW
 */
static void PROPSHEET_SetFinishTextW(HWND hwndDlg, LPCWSTR lpszText)
{
2239
  PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwndDlg, PropSheetInfoStr);
2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254
  HWND hwndButton = GetDlgItem(hwndDlg, IDC_FINISH_BUTTON);

  TRACE("'%s'\n", debugstr_w(lpszText));
  /* 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);

2255 2256 2257 2258 2259 2260
  if (!psInfo->hasFinish)
  {
    /* Hide Next button */
    hwndButton = GetDlgItem(hwndDlg, IDC_NEXT_BUTTON);
    ShowWindow(hwndButton, SW_HIDE);
  }
2261 2262
}

2263 2264 2265 2266 2267 2268 2269 2270 2271
/******************************************************************************
 *            PROPSHEET_QuerySiblings
 */
static LRESULT PROPSHEET_QuerySiblings(HWND hwndDlg,
                                       WPARAM wParam, LPARAM lParam)
{
  int i = 0;
  HWND hwndPage;
  LRESULT msgResult = 0;
2272
  PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwndDlg, PropSheetInfoStr);
2273

2274
  while ((i < psInfo->nPages) && (msgResult == 0))
2275 2276
  {
    hwndPage = psInfo->proppage[i].hwndPage;
2277
    msgResult = SendMessageW(hwndPage, PSM_QUERYSIBLINGS, wParam, lParam);
2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290
    i++;
  }

  return msgResult;
}


/******************************************************************************
 *            PROPSHEET_AddPage
 */
static BOOL PROPSHEET_AddPage(HWND hwndDlg,
                              HPROPSHEETPAGE hpage)
{
2291
  PropPageInfo * ppi;
2292
  PropSheetInfo * psInfo = (PropSheetInfo*) GetPropW(hwndDlg,
2293 2294
                                                     PropSheetInfoStr);
  HWND hwndTabControl = GetDlgItem(hwndDlg, IDC_TABCONTROL);
2295 2296
  TCITEMW item;
  LPCPROPSHEETPAGEW ppsp = (LPCPROPSHEETPAGEW)hpage;
2297

2298
  TRACE("hpage %p\n", hpage);
2299 2300 2301
  /*
   * Allocate and fill in a new PropPageInfo entry.
   */
2302 2303 2304 2305 2306 2307 2308
  ppi = (PropPageInfo*) ReAlloc(psInfo->proppage,
                                sizeof(PropPageInfo) *
                                (psInfo->nPages + 1));
  if (!ppi)
      return FALSE;

  psInfo->proppage = ppi;
2309
  if (!PROPSHEET_CollectPageInfo(ppsp, psInfo, psInfo->nPages))
2310
      return FALSE;
2311

2312 2313
  psInfo->proppage[psInfo->nPages].hpage = hpage;

Alexandre Julliard's avatar
Alexandre Julliard committed
2314 2315 2316 2317 2318
  if (ppsp->dwFlags & PSP_PREMATURE)
  {
     /* Create the page but don't show it */
     PROPSHEET_CreatePage(hwndDlg, psInfo->nPages, psInfo, ppsp);
  }
2319 2320 2321 2322 2323

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

2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337
  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;
  }

2338
  SendMessageW(hwndTabControl, TCM_INSERTITEMW, psInfo->nPages + 1,
2339 2340 2341 2342
               (LPARAM)&item);

  psInfo->nPages++;

Alexandre Julliard's avatar
Alexandre Julliard committed
2343 2344
  /* If it is the only page - show it */
  if(psInfo->nPages == 1)
2345
     PROPSHEET_SetCurSel(hwndDlg, 0, 1, 0);
2346
  return TRUE;
2347 2348 2349 2350 2351 2352 2353 2354 2355
}

/******************************************************************************
 *            PROPSHEET_RemovePage
 */
static BOOL PROPSHEET_RemovePage(HWND hwndDlg,
                                 int index,
                                 HPROPSHEETPAGE hpage)
{
2356
  PropSheetInfo * psInfo = (PropSheetInfo*) GetPropW(hwndDlg,
2357 2358
                                                     PropSheetInfoStr);
  HWND hwndTabControl = GetDlgItem(hwndDlg, IDC_TABCONTROL);
2359
  PropPageInfo* oldPages;
2360

2361
  TRACE("index %d, hpage %p\n", index, hpage);
2362 2363 2364
  if (!psInfo) {
    return FALSE;
  }
2365 2366 2367 2368 2369 2370
  /*
   * hpage takes precedence over index.
   */
  if (hpage != 0)
  {
    index = PROPSHEET_GetPageIndex(hpage, psInfo);
2371
  }
2372

2373
  /* Make sure that index is within range */
2374
  if (index < 0 || index >= psInfo->nPages)
Alexandre Julliard's avatar
Alexandre Julliard committed
2375
  {
2376
      TRACE("Could not find page to remove!\n");
2377
      return FALSE;
Alexandre Julliard's avatar
Alexandre Julliard committed
2378
  }
2379

2380
  TRACE("total pages %d removing page %d active page %d\n",
2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391
        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  */
2392
        PROPSHEET_SetCurSel(hwndDlg, index - 1, -1, 0);
2393 2394 2395 2396
      }
      else
      {
        /* activate the next page */
2397
        PROPSHEET_SetCurSel(hwndDlg, index + 1, 1, 0);
2398
        psInfo->active_page = index;
2399 2400 2401 2402
      }
    }
    else
    {
Alexandre Julliard's avatar
Alexandre Julliard committed
2403 2404 2405
      psInfo->active_page = -1;
      if (!psInfo->isModeless)
      {
2406
         psInfo->ended = TRUE;
Alexandre Julliard's avatar
Alexandre Julliard committed
2407 2408
         return TRUE;
      }
2409 2410
    }
  }
Alexandre Julliard's avatar
Alexandre Julliard committed
2411
  else if (index < psInfo->active_page)
2412 2413
    psInfo->active_page--;

2414 2415 2416 2417 2418 2419 2420 2421 2422
  /* 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
2423 2424 2425 2426 2427 2428
  /* Destroy page dialog window */
  DestroyWindow(psInfo->proppage[index].hwndPage);

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

     if ((psp->dwFlags & PSP_USETITLE) && psInfo->proppage[index].pszText)
2432
        Free ((LPVOID)psInfo->proppage[index].pszText);
Alexandre Julliard's avatar
Alexandre Julliard committed
2433 2434 2435

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

2437
  /* Remove the tab */
2438
  SendMessageW(hwndTabControl, TCM_DELETEITEM, index, 0);
2439

2440
  oldPages = psInfo->proppage;
2441
  psInfo->nPages--;
2442
  psInfo->proppage = Alloc(sizeof(PropPageInfo) * psInfo->nPages);
2443

2444
  if (index > 0)
2445 2446 2447 2448 2449 2450
    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));

2451
  Free(oldPages);
2452

2453 2454 2455
  return FALSE;
}

2456 2457 2458 2459 2460 2461 2462 2463 2464 2465
/******************************************************************************
 *            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)
{
2466 2467
  PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwndDlg,
                                                    PropSheetInfoStr);
Alexandre Julliard's avatar
Alexandre Julliard committed
2468 2469 2470
  HWND hwndBack   = GetDlgItem(hwndDlg, IDC_BACK_BUTTON);
  HWND hwndNext   = GetDlgItem(hwndDlg, IDC_NEXT_BUTTON);
  HWND hwndFinish = GetDlgItem(hwndDlg, IDC_FINISH_BUTTON);
2471 2472 2473

  TRACE("%ld\n", dwFlags);

Alexandre Julliard's avatar
Alexandre Julliard committed
2474 2475 2476 2477
  EnableWindow(hwndBack, FALSE);
  EnableWindow(hwndNext, FALSE);
  EnableWindow(hwndFinish, FALSE);

2478
  if (dwFlags & PSWIZB_BACK)
Alexandre Julliard's avatar
Alexandre Julliard committed
2479
    EnableWindow(hwndBack, TRUE);
2480 2481 2482

  if (dwFlags & PSWIZB_NEXT)
  {
2483 2484 2485 2486 2487
    if (!psInfo->hasFinish)
    {
      /* Hide the Finish button */
      ShowWindow(hwndFinish, SW_HIDE);
    }
2488 2489

    /* Show and enable the Next button */
Alexandre Julliard's avatar
Alexandre Julliard committed
2490 2491
    ShowWindow(hwndNext, SW_SHOW);
    EnableWindow(hwndNext, TRUE);
2492 2493

    /* Set the Next button as the default pushbutton  */
2494
    SendMessageW(hwndDlg, DM_SETDEFID, IDC_NEXT_BUTTON, 0);
2495 2496
  }

2497
  if (!psInfo->hasFinish)
2498
  {
2499 2500 2501 2502 2503 2504 2505
    if ((dwFlags & PSWIZB_FINISH) || (dwFlags & PSWIZB_DISABLEDFINISH))
    {
      /* Hide the Next button */
      ShowWindow(hwndNext, SW_HIDE);
      
      /* Show the Finish button */
      ShowWindow(hwndFinish, SW_SHOW);
2506

2507 2508 2509
      if (!(dwFlags & PSWIZB_DISABLEDFINISH))
      {
        EnableWindow(hwndFinish, TRUE);
2510

2511 2512 2513 2514
        /* Set the Finish button as the default pushbutton  */
        SendMessageW(hwndDlg, DM_SETDEFID, IDC_FINISH_BUTTON, 0);
      }
    }
2515
  }
2516 2517
  else if (!(dwFlags & PSWIZB_DISABLEDFINISH))
    EnableWindow(hwndFinish, TRUE);
2518 2519
}

2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568
/******************************************************************************
 *            PROPSHEET_InsertPage
 */
static BOOL PROPSHEET_InsertPage(HWND hwndDlg, HPROPSHEETPAGE hpageInsertAfter, HPROPSHEETPAGE hpage)
{
    if (!HIWORD(hpageInsertAfter))
        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)
{
2569 2570 2571 2572 2573 2574 2575 2576 2577 2578
    int index;
    PropSheetInfo * psInfo = (PropSheetInfo*) GetPropW(hwndDlg,
                                                       PropSheetInfoStr);

    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);
2579 2580 2581 2582 2583 2584 2585 2586
    return -1;
}

/******************************************************************************
 *            PROPSHEET_IndexToHwnd
 */
static LRESULT PROPSHEET_IndexToHwnd(HWND hwndDlg, int iPageIndex)
{
2587 2588 2589 2590 2591 2592 2593 2594
    PropSheetInfo * psInfo = (PropSheetInfo*) GetPropW(hwndDlg,
                                                       PropSheetInfoStr);
    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].hwndPage;
2595 2596 2597 2598 2599 2600 2601
}

/******************************************************************************
 *            PROPSHEET_PageToIndex
 */
static LRESULT PROPSHEET_PageToIndex(HWND hwndDlg, HPROPSHEETPAGE hPage)
{
2602 2603 2604 2605 2606 2607 2608 2609 2610 2611
    int index;
    PropSheetInfo * psInfo = (PropSheetInfo*) GetPropW(hwndDlg,
                                                       PropSheetInfoStr);

    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);
2612 2613 2614 2615 2616 2617 2618 2619
    return -1;
}

/******************************************************************************
 *            PROPSHEET_IndexToPage
 */
static LRESULT PROPSHEET_IndexToPage(HWND hwndDlg, int iPageIndex)
{
2620 2621 2622 2623 2624 2625 2626 2627
    PropSheetInfo * psInfo = (PropSheetInfo*) GetPropW(hwndDlg,
                                                       PropSheetInfoStr);
    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;
2628 2629 2630 2631 2632 2633 2634
}

/******************************************************************************
 *            PROPSHEET_IdToIndex
 */
static LRESULT PROPSHEET_IdToIndex(HWND hwndDlg, int iPageId)
{
2635 2636 2637 2638 2639 2640 2641
    int index;
    LPCPROPSHEETPAGEW psp;
    PropSheetInfo * psInfo = (PropSheetInfo*) GetPropW(hwndDlg,
                                                       PropSheetInfoStr);
    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
2642
        if (psp->u.pszTemplate == MAKEINTRESOURCEW(iPageId))
2643 2644 2645
            return index;
    }

2646 2647 2648 2649 2650 2651 2652 2653
    return -1;
}

/******************************************************************************
 *            PROPSHEET_IndexToId
 */
static LRESULT PROPSHEET_IndexToId(HWND hwndDlg, int iPageIndex)
{
2654 2655 2656 2657 2658 2659 2660 2661 2662 2663 2664 2665 2666
    PropSheetInfo * psInfo = (PropSheetInfo*) GetPropW(hwndDlg,
                                                       PropSheetInfoStr);
    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;
    if (psp->dwFlags & PSP_DLGINDIRECT || HIWORD(psp->u.pszTemplate)) {
        return 0;
    }
    return (LRESULT)psp->u.pszTemplate;
2667 2668 2669 2670 2671 2672 2673 2674 2675 2676 2677 2678 2679 2680 2681 2682 2683 2684 2685 2686
}

/******************************************************************************
 *            PROPSHEET_GetResult
 */
static LRESULT PROPSHEET_GetResult(HWND hwndDlg)
{
    FIXME("(%p): stub\n", hwndDlg);
    return -1;
}

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

2687 2688 2689 2690 2691 2692 2693 2694 2695 2696 2697
/******************************************************************************
 *            PROPSHEET_GetPageIndex
 *
 * Given a HPROPSHEETPAGE, returns the index of the corresponding page from
 * the array of PropPageInfo.
 */
static int PROPSHEET_GetPageIndex(HPROPSHEETPAGE hpage, PropSheetInfo* psInfo)
{
  BOOL found = FALSE;
  int index = 0;

2698
  TRACE("hpage %p\n", hpage);
2699 2700 2701 2702 2703 2704 2705 2706 2707 2708 2709 2710 2711 2712
  while ((index < psInfo->nPages) && (found == FALSE))
  {
    if (psInfo->proppage[index].hpage == hpage)
      found = TRUE;
    else
      index++;
  }

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

  return index;
}

2713 2714 2715 2716 2717
/******************************************************************************
 *            PROPSHEET_CleanUp
 */
static void PROPSHEET_CleanUp(HWND hwndDlg)
{
Alexandre Julliard's avatar
Alexandre Julliard committed
2718
  int i;
2719
  PropSheetInfo* psInfo = (PropSheetInfo*) RemovePropW(hwndDlg,
2720
                                                       PropSheetInfoStr);
2721 2722

  TRACE("\n");
2723
  if (!psInfo) return;
2724
  if (HIWORD(psInfo->ppshheader.pszCaption))
2725
      Free ((LPVOID)psInfo->ppshheader.pszCaption);
Alexandre Julliard's avatar
Alexandre Julliard committed
2726 2727 2728 2729 2730

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

2731 2732 2733 2734 2735 2736 2737 2738 2739
     /* 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
2740 2741 2742 2743 2744 2745
     if(psInfo->proppage[i].hwndPage)
        DestroyWindow(psInfo->proppage[i].hwndPage);

     if(psp)
     {
        if ((psp->dwFlags & PSP_USETITLE) && psInfo->proppage[i].pszText)
2746
           Free ((LPVOID)psInfo->proppage[i].pszText);
Alexandre Julliard's avatar
Alexandre Julliard committed
2747 2748 2749 2750 2751

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

2752 2753 2754 2755 2756 2757 2758 2759 2760 2761
  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);

2762 2763
  Free(psInfo->proppage);
  Free(psInfo->strPropertiesFor);
2764
  ImageList_Destroy(psInfo->hImageList);
2765 2766 2767 2768

  GlobalFree((HGLOBAL)psInfo);
}

2769 2770 2771 2772 2773 2774 2775 2776 2777 2778 2779 2780 2781 2782 2783 2784 2785 2786 2787 2788 2789 2790 2791 2792 2793 2794 2795 2796
static INT do_loop(PropSheetInfo *psInfo)
{
    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;
    }

    DestroyWindow(hwnd);
    return ret;
}

2797
/******************************************************************************
2798 2799
 *            PropertySheet    (COMCTL32.@)
 *            PropertySheetA   (COMCTL32.@)
2800 2801 2802 2803 2804 2805 2806 2807 2808
 *
 * 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.
2809
 */
Frank Richter's avatar
Frank Richter committed
2810
INT_PTR WINAPI PropertySheetA(LPCPROPSHEETHEADERA lppsh)
2811
{
Frank Richter's avatar
Frank Richter committed
2812
  INT_PTR bRet = 0;
2813 2814
  PropSheetInfo* psInfo = (PropSheetInfo*) GlobalAlloc(GPTR,
                                                       sizeof(PropSheetInfo));
2815
  UINT i, n;
Alexandre Julliard's avatar
Alexandre Julliard committed
2816
  BYTE* pByte;
2817

2818 2819 2820
  TRACE("(%p)\n", lppsh);

  PROPSHEET_CollectSheetInfoA(lppsh, psInfo);
2821

2822
  psInfo->proppage = (PropPageInfo*) Alloc(sizeof(PropPageInfo) *
2823
                                                    lppsh->nPages);
2824
  pByte = (BYTE*) psInfo->ppshheader.u3.ppsp;
2825

2826
  for (n = i = 0; i < lppsh->nPages; i++, n++)
2827 2828
  {
    if (!(lppsh->dwFlags & PSH_PROPSHEETPAGE))
2829
      psInfo->proppage[n].hpage = psInfo->ppshheader.u3.phpage[i];
Alexandre Julliard's avatar
Alexandre Julliard committed
2830 2831
    else
    {
2832
       psInfo->proppage[n].hpage = CreatePropertySheetPageA((LPCPROPSHEETPAGEA)pByte);
Alexandre Julliard's avatar
Alexandre Julliard committed
2833 2834 2835
       pByte += ((LPPROPSHEETPAGEA)pByte)->dwSize;
    }

2836
    if (!PROPSHEET_CollectPageInfo((LPCPROPSHEETPAGEW)psInfo->proppage[n].hpage,
2837 2838 2839 2840 2841 2842 2843
                               psInfo, n))
    {
	if (lppsh->dwFlags & PSH_PROPSHEETPAGE)
	    DestroyPropertySheetPage(psInfo->proppage[n].hpage);
	n--;
	psInfo->nPages--;
    }
2844
  }
2845

2846
  psInfo->unicode = FALSE;
2847 2848
  psInfo->ended = FALSE;

2849
  bRet = PROPSHEET_CreateDialog(psInfo);
2850 2851
  if(!psInfo->isModeless)
      bRet = do_loop(psInfo);
2852

2853
  return bRet;
2854 2855
}

2856
/******************************************************************************
2857
 *            PropertySheetW   (COMCTL32.@)
2858 2859
 *
 * See PropertySheetA.
2860
 */
Frank Richter's avatar
Frank Richter committed
2861
INT_PTR WINAPI PropertySheetW(LPCPROPSHEETHEADERW lppsh)
2862
{
Frank Richter's avatar
Frank Richter committed
2863
  INT_PTR bRet = 0;
2864 2865
  PropSheetInfo* psInfo = (PropSheetInfo*) GlobalAlloc(GPTR,
                                                       sizeof(PropSheetInfo));
2866
  UINT i, n;
2867 2868 2869 2870 2871 2872
  BYTE* pByte;

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

  PROPSHEET_CollectSheetInfoW(lppsh, psInfo);

2873
  psInfo->proppage = (PropPageInfo*) Alloc(sizeof(PropPageInfo) *
2874 2875
                                                    lppsh->nPages);
  pByte = (BYTE*) psInfo->ppshheader.u3.ppsp;
2876

2877 2878 2879 2880 2881 2882 2883 2884 2885 2886
  for (n = i = 0; i < lppsh->nPages; i++, n++)
  {
    if (!(lppsh->dwFlags & PSH_PROPSHEETPAGE))
      psInfo->proppage[n].hpage = psInfo->ppshheader.u3.phpage[i];
    else
    {
       psInfo->proppage[n].hpage = CreatePropertySheetPageW((LPCPROPSHEETPAGEW)pByte);
       pByte += ((LPPROPSHEETPAGEW)pByte)->dwSize;
    }

2887
    if (!PROPSHEET_CollectPageInfo((LPCPROPSHEETPAGEW)psInfo->proppage[n].hpage,
2888 2889 2890 2891 2892 2893 2894 2895 2896
                               psInfo, n))
    {
	if (lppsh->dwFlags & PSH_PROPSHEETPAGE)
	    DestroyPropertySheetPage(psInfo->proppage[n].hpage);
	n--;
	psInfo->nPages--;
    }
  }

2897
  psInfo->unicode = TRUE;
2898 2899
  psInfo->ended = FALSE;

2900
  bRet = PROPSHEET_CreateDialog(psInfo);
2901 2902
  if(!psInfo->isModeless)
      bRet = do_loop(psInfo);
2903 2904

  return bRet;
2905 2906
}

2907
/******************************************************************************
2908 2909
 *            CreatePropertySheetPage    (COMCTL32.@)
 *            CreatePropertySheetPageA   (COMCTL32.@)
2910 2911 2912 2913 2914 2915 2916 2917 2918 2919
 *
 * 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.
2920
 */
2921 2922
HPROPSHEETPAGE WINAPI CreatePropertySheetPageA(
                          LPCPROPSHEETPAGEA lpPropSheetPage)
2923
{
2924
  PROPSHEETPAGEW* ppsp = Alloc(sizeof(PROPSHEETPAGEW));
2925

2926
  memcpy(ppsp,lpPropSheetPage,min(lpPropSheetPage->dwSize,sizeof(PROPSHEETPAGEA)));
2927

2928
  ppsp->dwFlags &= ~ PSP_INTERNAL_UNICODE;
2929
  if ( !(ppsp->dwFlags & PSP_DLGINDIRECT) && HIWORD( ppsp->u.pszTemplate ) )
2930
  {
2931 2932
     int len = strlen(lpPropSheetPage->u.pszTemplate);

2933
     ppsp->u.pszTemplate = Alloc( len+1 );
2934
     strcpy( (LPSTR)ppsp->u.pszTemplate, lpPropSheetPage->u.pszTemplate );
2935
  }
Alexandre Julliard's avatar
Alexandre Julliard committed
2936
  if ( (ppsp->dwFlags & PSP_USEICONID) && HIWORD( ppsp->u2.pszIcon ) )
2937
  {
2938
      PROPSHEET_AtoW(&ppsp->u2.pszIcon, lpPropSheetPage->u2.pszIcon);
2939
  }
Alexandre Julliard's avatar
Alexandre Julliard committed
2940 2941

  if ((ppsp->dwFlags & PSP_USETITLE) && HIWORD( ppsp->pszTitle ))
2942
  {
2943
      PROPSHEET_AtoW(&ppsp->pszTitle, lpPropSheetPage->pszTitle);
2944
  }
Alexandre Julliard's avatar
Alexandre Julliard committed
2945 2946 2947
  else if ( !(ppsp->dwFlags & PSP_USETITLE) )
      ppsp->pszTitle = NULL;

2948
  return (HPROPSHEETPAGE)ppsp;
2949 2950
}

2951
/******************************************************************************
2952
 *            CreatePropertySheetPageW   (COMCTL32.@)
2953 2954
 *
 * See CreatePropertySheetA.
2955
 */
2956
HPROPSHEETPAGE WINAPI CreatePropertySheetPageW(LPCPROPSHEETPAGEW lpPropSheetPage)
2957
{
2958
  PROPSHEETPAGEW* ppsp = Alloc(sizeof(PROPSHEETPAGEW));
2959 2960 2961

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

2962 2963
  ppsp->dwFlags |= PSP_INTERNAL_UNICODE;

2964 2965 2966
  if ( !(ppsp->dwFlags & PSP_DLGINDIRECT) && HIWORD( ppsp->u.pszTemplate ) )
  {
    int len = strlenW(lpPropSheetPage->u.pszTemplate);
2967

2968
    ppsp->u.pszTemplate = Alloc( (len+1)*sizeof (WCHAR) );
2969 2970 2971 2972 2973
    strcpyW( (WCHAR *)ppsp->u.pszTemplate, lpPropSheetPage->u.pszTemplate );
  }
  if ( (ppsp->dwFlags & PSP_USEICONID) && HIWORD( ppsp->u2.pszIcon ) )
  {
      int len = strlenW(lpPropSheetPage->u2.pszIcon);
2974
      ppsp->u2.pszIcon = Alloc( (len+1)*sizeof (WCHAR) );
2975 2976 2977 2978 2979 2980
      strcpyW( (WCHAR *)ppsp->u2.pszIcon, lpPropSheetPage->u2.pszIcon );
  }

  if ((ppsp->dwFlags & PSP_USETITLE) && HIWORD( ppsp->pszTitle ))
  {
      int len = strlenW(lpPropSheetPage->pszTitle);
2981
      ppsp->pszTitle = Alloc( (len+1)*sizeof (WCHAR) );
2982 2983 2984 2985 2986 2987
      strcpyW( (WCHAR *)ppsp->pszTitle, lpPropSheetPage->pszTitle );
  }
  else if ( !(ppsp->dwFlags & PSP_USETITLE) )
      ppsp->pszTitle = NULL;

  return (HPROPSHEETPAGE)ppsp;
2988 2989
}

2990
/******************************************************************************
2991
 *            DestroyPropertySheetPage   (COMCTL32.@)
2992 2993 2994 2995 2996 2997 2998 2999
 *
 * Destroys a property sheet page previously created with
 * CreatePropertySheetA() or CreatePropertySheetW() and frees the associated
 * memory.
 *
 * RETURNS
 *     Success: TRUE
 *     Failure: FALSE
3000
 */
3001
BOOL WINAPI DestroyPropertySheetPage(HPROPSHEETPAGE hPropPage)
3002
{
3003
  PROPSHEETPAGEW *psp = (PROPSHEETPAGEW *)hPropPage;
Alexandre Julliard's avatar
Alexandre Julliard committed
3004 3005 3006 3007

  if (!psp)
     return FALSE;

3008
  if ( !(psp->dwFlags & PSP_DLGINDIRECT) && HIWORD( psp->u.pszTemplate ) )
3009
     Free ((LPVOID)psp->u.pszTemplate);
Alexandre Julliard's avatar
Alexandre Julliard committed
3010 3011

  if ( (psp->dwFlags & PSP_USEICONID) && HIWORD( psp->u2.pszIcon ) )
3012
     Free ((LPVOID)psp->u2.pszIcon);
Alexandre Julliard's avatar
Alexandre Julliard committed
3013 3014

  if ((psp->dwFlags & PSP_USETITLE) && HIWORD( psp->pszTitle ))
3015
     Free ((LPVOID)psp->pszTitle);
Alexandre Julliard's avatar
Alexandre Julliard committed
3016

3017
  Free(hPropPage);
3018 3019

  return TRUE;
3020 3021
}

Alexandre Julliard's avatar
Alexandre Julliard committed
3022 3023 3024 3025 3026
/******************************************************************************
 *            PROPSHEET_IsDialogMessage
 */
static BOOL PROPSHEET_IsDialogMessage(HWND hwnd, LPMSG lpMsg)
{
3027
   PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwnd, PropSheetInfoStr);
Alexandre Julliard's avatar
Alexandre Julliard committed
3028

3029
   TRACE("\n");
Alexandre Julliard's avatar
Alexandre Julliard committed
3030 3031 3032 3033 3034 3035
   if (!psInfo || (hwnd != lpMsg->hwnd && !IsChild(hwnd, lpMsg->hwnd)))
      return FALSE;

   if (lpMsg->message == WM_KEYDOWN && (GetKeyState(VK_CONTROL) & 0x8000))
   {
      int new_page = 0;
3036
      INT dlgCode = SendMessageW(lpMsg->hwnd, WM_GETDLGCODE, 0, (LPARAM)lpMsg);
Alexandre Julliard's avatar
Alexandre Julliard committed
3037 3038 3039 3040 3041 3042 3043 3044 3045 3046 3047 3048 3049 3050 3051 3052 3053 3054 3055 3056 3057 3058 3059 3060 3061 3062 3063 3064

      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;

3065
            PROPSHEET_SetCurSel(hwnd, new_page, 1, 0);
Alexandre Julliard's avatar
Alexandre Julliard committed
3066 3067 3068 3069 3070 3071
         }

         return TRUE;
      }
   }

3072
   return IsDialogMessageW(hwnd, lpMsg);
Alexandre Julliard's avatar
Alexandre Julliard committed
3073 3074
}

3075 3076 3077 3078 3079 3080 3081 3082 3083 3084 3085 3086 3087 3088 3089 3090 3091 3092 3093 3094 3095 3096 3097 3098 3099 3100 3101 3102 3103 3104 3105 3106
/******************************************************************************
 *            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)
		{
		    PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwnd,
								      PropSheetInfoStr);
		    int result = TRUE;

		    if (psInfo->restartWindows)
			result = ID_PSRESTARTWINDOWS;

		    /* reboot system takes precedence over restart windows */
		    if (psInfo->rebootSystem)
			result = ID_PSREBOOTSYSTEM;

		    if (psInfo->isModeless)
			psInfo->activeValid = FALSE;
		    else
3107
                        psInfo->ended = TRUE;
3108 3109 3110 3111 3112 3113 3114 3115 3116 3117 3118 3119 3120 3121 3122 3123 3124 3125 3126 3127 3128 3129 3130 3131 3132 3133
		}
	    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;
3134 3135 3136

    default:
        return FALSE;
3137 3138 3139 3140 3141
    }

    return TRUE;
}

3142 3143 3144
/******************************************************************************
 *            PROPSHEET_Paint
 */
3145
static LRESULT PROPSHEET_Paint(HWND hwnd, HDC hdcParam)
3146 3147 3148 3149 3150 3151 3152 3153 3154
{
    PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwnd, PropSheetInfoStr);
    PAINTSTRUCT ps;
    HDC hdc, hdcSrc;
    BITMAP bm;
    HBITMAP hbmp;
    HPALETTE hOldPal = 0;
    int offsety = 0;
    HBRUSH hbr;
3155
    RECT r, rzone;
3156
    LPCPROPSHEETPAGEW ppshpage;
3157 3158
    WCHAR szBuffer[256];
    int nLength;
3159

3160
    hdc = hdcParam ? hdcParam : BeginPaint(hwnd, &ps);
3161 3162 3163 3164 3165 3166 3167 3168 3169
    if (!hdc) return 1;

    hdcSrc = CreateCompatibleDC(0);
    ppshpage = (LPCPROPSHEETPAGEW)psInfo->proppage[psInfo->active_page].hpage;

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

    if ( (!(ppshpage->dwFlags & PSP_HIDEHEADER)) &&
3170 3171
	 (psInfo->ppshheader.dwFlags & (PSH_WIZARD97_OLD | PSH_WIZARD97_NEW)) &&
	 (psInfo->ppshheader.dwFlags & PSH_HEADER) ) 
3172 3173 3174 3175 3176 3177 3178
    {
	HWND hwndLineHeader = GetDlgItem(hwnd, IDC_SUNKEN_LINEHEADER);
	HFONT hOldFont;
	COLORREF clrOld = 0;
	int oldBkMode = 0;

	hbmp = SelectObject(hdcSrc, psInfo->ppshheader.u5.hbmHeader);
3179
	hOldFont = SelectObject(hdc, psInfo->hFontBold);
3180 3181 3182

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

3185
	GetObjectW(psInfo->ppshheader.u5.hbmHeader, sizeof(BITMAP), (LPVOID)&bm);		
3186

3187 3188 3189 3190 3191 3192 3193 3194 3195 3196 3197 3198 3199 3200 3201 3202 3203 3204 3205 3206 3207 3208
 	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);
 	    }
3209 3210 3211 3212 3213

 	    /* Draw the header itself. */
 	    BitBlt(hdc, 0, 0,
 	           bm.bmWidth, min(bm.bmHeight, rzone.bottom),
 	           hdcSrc, 0, 0, SRCCOPY);
3214 3215 3216
 	}
 	else
 	{
3217
 	    hbr = GetSysColorBrush(COLOR_WINDOW);
3218
 	    FillRect(hdc, &rzone, hbr);
3219 3220 3221 3222 3223 3224 3225 3226 3227 3228 3229 3230

 	    /* Draw the header bitmap. It's always centered like a
 	     * common 49 x 49 bitmap. */
 	    BitBlt(hdc, rzone.right - 49 - ((rzone.bottom - 49) / 2),
 	           (rzone.bottom - 49) / 2,
 	           bm.bmWidth, bm.bmHeight,
 	           hdcSrc, 0, 0, SRCCOPY);

 	    /* 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. */
3231
 	}
3232

3233 3234 3235
	clrOld = SetTextColor (hdc, 0x00000000);
	oldBkMode = SetBkMode (hdc, TRANSPARENT); 

3236
	if (ppshpage->dwFlags & PSP_USEHEADERTITLE) {
3237
	    SetRect(&r, 20, 10, 0, 0);
3238 3239 3240 3241 3242 3243 3244 3245 3246
	    if (HIWORD(ppshpage->pszHeaderTitle))
	    {
		if (psInfo->unicode)
		    DrawTextW(hdc, (LPWSTR)ppshpage->pszHeaderTitle,
			      -1, &r, DT_LEFT | DT_SINGLELINE | DT_NOCLIP);
		else
		    DrawTextA(hdc, (LPCSTR)ppshpage->pszHeaderTitle,
			      -1, &r, DT_LEFT | DT_SINGLELINE | DT_NOCLIP);
	    }
3247
	    else
3248
	    {
Frank Richter's avatar
Frank Richter committed
3249
		nLength = LoadStringW(ppshpage->hInstance, (UINT_PTR)ppshpage->pszHeaderTitle,
3250 3251 3252 3253 3254 3255 3256
				      szBuffer, 256);
		if (nLength != 0)
		{
		    DrawTextW(hdc, szBuffer, nLength,
			      &r, DT_LEFT | DT_SINGLELINE | DT_NOCLIP);
		}
	    }
3257 3258 3259 3260
	}

	if (ppshpage->dwFlags & PSP_USEHEADERSUBTITLE) {
	    SelectObject(hdc, psInfo->hFont);
3261
	    SetRect(&r, 40, 25, rzone.right - 69, rzone.bottom);
3262 3263 3264 3265 3266 3267 3268 3269 3270
	    if (HIWORD(ppshpage->pszHeaderTitle))
	    {
		if (psInfo->unicode)
		    DrawTextW(hdc, (LPWSTR)ppshpage->pszHeaderSubTitle,
			      -1, &r, DT_LEFT | DT_SINGLELINE);
		else
		    DrawTextA(hdc, (LPCSTR)ppshpage->pszHeaderSubTitle,
			      -1, &r, DT_LEFT | DT_SINGLELINE);
	    }
3271
	    else
3272
	    {
Frank Richter's avatar
Frank Richter committed
3273
		nLength = LoadStringW(ppshpage->hInstance, (UINT_PTR)ppshpage->pszHeaderSubTitle,
3274 3275 3276 3277
				      szBuffer, 256);
		if (nLength != 0)
		{
		    DrawTextW(hdc, szBuffer, nLength,
3278
			      &r, DT_LEFT | DT_SINGLELINE);
3279 3280
		}
	    }
3281 3282 3283 3284 3285 3286 3287 3288 3289 3290
	}

	offsety = rzone.bottom + 2;

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

3291
    if ( (ppshpage->dwFlags & PSP_HIDEHEADER) &&
3292 3293
	 (psInfo->ppshheader.dwFlags & (PSH_WIZARD97_OLD | PSH_WIZARD97_NEW)) &&
	 (psInfo->ppshheader.dwFlags & PSH_WATERMARK) ) 
3294
    {
3295 3296 3297 3298 3299
	HWND hwndLine = GetDlgItem(hwnd, IDC_SUNKEN_LINE);	    

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

3300 3301 3302 3303 3304 3305 3306 3307
	rzone.left = 0;
	rzone.top = 0;
	rzone.right = r.right;
	rzone.bottom = r.top - 1;

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

3308
	GetObjectW(psInfo->ppshheader.u4.hbmWatermark, sizeof(BITMAP), (LPVOID)&bm);
3309 3310 3311 3312 3313 3314 3315 3316 3317 3318 3319 3320 3321 3322 3323
	hbmp = SelectObject(hdcSrc, psInfo->ppshheader.u4.hbmWatermark);

	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);
3324
	}
3325 3326

	SelectObject(hdcSrc, hbmp);	    
3327 3328 3329 3330 3331 3332 3333
    }

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

    DeleteDC(hdcSrc);

3334
    if (!hdcParam) EndPaint(hwnd, &ps);
3335 3336 3337 3338

    return 0;
}

3339 3340 3341
/******************************************************************************
 *            PROPSHEET_DialogProc
 */
3342
INT_PTR CALLBACK
3343 3344
PROPSHEET_DialogProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
3345
  TRACE("hwnd=%p msg=0x%04x wparam=%x lparam=%lx\n",
3346 3347
	hwnd, uMsg, wParam, lParam);

3348 3349 3350 3351 3352
  switch (uMsg)
  {
    case WM_INITDIALOG:
    {
      PropSheetInfo* psInfo = (PropSheetInfo*) lParam;
3353
      WCHAR* strCaption = (WCHAR*)Alloc(MAX_CAPTION_LENGTH*sizeof(WCHAR));
3354
      HWND hwndTabCtrl = GetDlgItem(hwnd, IDC_TABCONTROL);
3355
      LPCPROPSHEETPAGEW ppshpage;
Alexandre Julliard's avatar
Alexandre Julliard committed
3356
      int idx;
3357
      LOGFONTW logFont;
3358

3359 3360 3361
      /* Using PropSheetInfoStr to store extra data doesn't match the native
       * common control: native uses TCM_[GS]ETITEM
       */
3362
      SetPropW(hwnd, PropSheetInfoStr, (HANDLE)psInfo);
3363

3364
      /*
3365 3366
       * psInfo->hwnd is not being used by WINE code - it exists
       * for compatibility with "real" Windoze. The same about
3367
       * SetWindowLongPtr - WINE is only using the PropSheetInfoStr
3368 3369 3370
       * property.
       */
      psInfo->hwnd = hwnd;
3371
      SetWindowLongPtrW(hwnd, DWLP_USER, (DWORD_PTR)psInfo);
3372

3373 3374 3375
      /* set up the Next and Back buttons by default */
      PROPSHEET_SetWizButtons(hwnd, PSWIZB_BACK|PSWIZB_NEXT);

3376
      /* Set up fonts */
3377 3378
      SystemParametersInfoW (SPI_GETICONTITLELOGFONT, 0, &logFont, 0);
      psInfo->hFont = CreateFontIndirectW (&logFont);
3379
      logFont.lfWeight = FW_BOLD;
3380
      psInfo->hFontBold = CreateFontIndirectW (&logFont);
3381
      
3382 3383 3384
      /*
       * Small icon in the title bar.
       */
3385 3386
      if ((psInfo->ppshheader.dwFlags & PSH_USEICONID) ||
          (psInfo->ppshheader.dwFlags & PSH_USEHICON))
3387 3388 3389 3390 3391
      {
        HICON hIcon;
        int icon_cx = GetSystemMetrics(SM_CXSMICON);
        int icon_cy = GetSystemMetrics(SM_CYSMICON);

3392
        if (psInfo->ppshheader.dwFlags & PSH_USEICONID)
3393
          hIcon = LoadImageW(psInfo->ppshheader.hInstance,
3394
                             psInfo->ppshheader.u.pszIcon,
3395 3396 3397 3398
                             IMAGE_ICON,
                             icon_cx, icon_cy,
                             LR_DEFAULTCOLOR);
        else
3399
          hIcon = psInfo->ppshheader.u.hIcon;
3400

3401
        SendMessageW(hwnd, WM_SETICON, 0, (LPARAM)hIcon);
3402
      }
3403

3404
      if (psInfo->ppshheader.dwFlags & PSH_USEHICON)
3405
        SendMessageW(hwnd, WM_SETICON, 0, (LPARAM)psInfo->ppshheader.u.hIcon);
3406

3407 3408
      psInfo->strPropertiesFor = strCaption;

3409
      GetWindowTextW(hwnd, psInfo->strPropertiesFor, MAX_CAPTION_LENGTH);
3410

3411 3412
      PROPSHEET_CreateTabControl(hwnd, psInfo);

3413 3414
      PROPSHEET_LoadWizardBitmaps(psInfo);

3415
      if (psInfo->ppshheader.dwFlags & INTRNL_ANY_WIZARD)
3416
      {
3417
        ShowWindow(hwndTabCtrl, SW_HIDE);
Filip Navara's avatar
Filip Navara committed
3418 3419
        PROPSHEET_AdjustSizeWizard(hwnd, psInfo);
        PROPSHEET_AdjustButtonsWizard(hwnd, psInfo);
3420 3421
      }
      else
3422
      {
3423
        if (PROPSHEET_SizeMismatch(hwnd, psInfo))
3424 3425 3426 3427
        {
          PROPSHEET_AdjustSize(hwnd, psInfo);
          PROPSHEET_AdjustButtons(hwnd, psInfo);
        }
3428 3429
      }

3430 3431
      if (!HIWORD(psInfo->ppshheader.pszCaption) &&
              psInfo->ppshheader.hInstance)
3432
      {
3433
         WCHAR szText[256];
3434

3435
         if (LoadStringW(psInfo->ppshheader.hInstance,
Frank Richter's avatar
Frank Richter committed
3436
                         (UINT_PTR)psInfo->ppshheader.pszCaption, szText, 255))
3437
            PROPSHEET_SetTitleW(hwnd, psInfo->ppshheader.dwFlags, szText);
3438 3439 3440
      }
      else
      {
3441
         PROPSHEET_SetTitleW(hwnd, psInfo->ppshheader.dwFlags,
3442
                         psInfo->ppshheader.pszCaption);
3443
      }
3444

3445 3446 3447 3448 3449 3450 3451 3452 3453 3454 3455 3456 3457 3458 3459 3460

      if (psInfo->useCallback)
             (*(psInfo->ppshheader.pfnCallback))(hwnd,
					      PSCB_INITIALIZED, (LPARAM)0);

      idx = psInfo->active_page;
      ppshpage = (LPCPROPSHEETPAGEW)psInfo->proppage[idx].hpage;
      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);

3461 3462 3463
      return TRUE;
    }

3464
    case WM_PRINTCLIENT:
3465
    case WM_PAINT:
3466
      PROPSHEET_Paint(hwnd, (HDC)wParam);
3467 3468
      return TRUE;

3469 3470 3471 3472 3473
    case WM_DESTROY:
      PROPSHEET_CleanUp(hwnd);
      return TRUE;

    case WM_CLOSE:
Alexandre Julliard's avatar
Alexandre Julliard committed
3474
      PROPSHEET_Cancel(hwnd, 1);
3475 3476 3477
      return TRUE;

    case WM_COMMAND:
3478 3479 3480 3481
      if (!PROPSHEET_DoCommand(hwnd, LOWORD(wParam)))
      {
          PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwnd, PropSheetInfoStr);

3482 3483 3484
          if (!psInfo)
              return FALSE;

3485 3486 3487 3488 3489 3490 3491 3492
          /* 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;
3493

3494 3495 3496 3497 3498 3499 3500 3501 3502 3503 3504
    case WM_SYSCOMMAND:
      switch(wParam & 0xfff0)
      {
        case SC_CLOSE:
          PROPSHEET_Cancel(hwnd, 1);
          return TRUE;

        default:
          return FALSE;
      }

3505 3506 3507 3508 3509 3510
    case WM_NOTIFY:
    {
      NMHDR* pnmh = (LPNMHDR) lParam;

      if (pnmh->code == TCN_SELCHANGE)
      {
3511
        int index = SendMessageW(pnmh->hwndFrom, TCM_GETCURSEL, 0, 0);
3512
        PROPSHEET_SetCurSel(hwnd, index, 1, 0);
3513 3514
      }

3515 3516 3517
      if(pnmh->code == TCN_SELCHANGING)
      {
        BOOL bRet = PROPSHEET_CanSetCurSel(hwnd);
3518
        SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, !bRet);
3519 3520 3521
        return TRUE;
      }

3522
      return FALSE;
3523
    }
3524 3525 3526 3527
  
    case WM_SYSCOLORCHANGE:
      COMCTL32_RefreshSysColors();
      return FALSE;
3528 3529 3530

    case PSM_GETCURRENTPAGEHWND:
    {
3531
      PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwnd,
3532 3533 3534
                                                        PropSheetInfoStr);
      HWND hwndPage = 0;

3535 3536 3537
      if (!psInfo)
        return FALSE;

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

3541
      SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, (DWORD_PTR)hwndPage);
3542 3543 3544 3545 3546 3547 3548 3549 3550 3551 3552 3553 3554 3555 3556 3557

      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);

3558
      SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, (DWORD_PTR)hwndTabCtrl);
3559 3560 3561 3562 3563 3564 3565 3566

      return TRUE;
    }

    case PSM_SETCURSEL:
    {
      BOOL msgResult;

3567 3568 3569 3570 3571
      msgResult = PROPSHEET_CanSetCurSel(hwnd);
      if(msgResult != FALSE)
      {
        msgResult = PROPSHEET_SetCurSel(hwnd,
                                       (int)wParam,
3572
				       1,
3573 3574
                                       (HPROPSHEETPAGE)lParam);
      }
3575

3576
      SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);
3577 3578 3579 3580 3581 3582

      return TRUE;
    }

    case PSM_CANCELTOCLOSE:
    {
3583
      WCHAR buf[MAX_BUTTONTEXT_LENGTH];
3584 3585 3586 3587
      HWND hwndOK = GetDlgItem(hwnd, IDOK);
      HWND hwndCancel = GetDlgItem(hwnd, IDCANCEL);

      EnableWindow(hwndCancel, FALSE);
3588 3589
      if (LoadStringW(COMCTL32_hModule, IDS_CLOSE, buf, sizeof(buf)))
         SetWindowTextW(hwndOK, buf);
3590

Alexandre Julliard's avatar
Alexandre Julliard committed
3591
      return FALSE;
3592
    }
3593

3594 3595
    case PSM_RESTARTWINDOWS:
    {
3596
      PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwnd,
3597
                                                        PropSheetInfoStr);
3598

3599 3600 3601
      if (!psInfo)
        return FALSE;

3602 3603 3604 3605 3606 3607
      psInfo->restartWindows = TRUE;
      return TRUE;
    }

    case PSM_REBOOTSYSTEM:
    {
3608
      PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwnd,
3609 3610
                                                        PropSheetInfoStr);

3611 3612 3613
      if (!psInfo)
        return FALSE;

3614 3615 3616 3617 3618 3619 3620
      psInfo->rebootSystem = TRUE;
      return TRUE;
    }

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

3622 3623 3624
    case PSM_SETTITLEW:
      PROPSHEET_SetTitleW(hwnd, (DWORD) wParam, (LPCWSTR) lParam);
      return TRUE;
3625 3626 3627

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

3630
      SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);
3631 3632 3633 3634 3635 3636 3637 3638

      return TRUE;
    }

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

3639
      SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);
3640 3641 3642 3643

      return TRUE;
    }

3644
    case PSM_ADDPAGE:
3645 3646 3647 3648 3649 3650 3651 3652 3653 3654 3655
    {
      /*
       * 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);

3656
      SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);
3657

3658
      return TRUE;
3659
    }
3660 3661 3662 3663 3664

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

3665 3666
    case PSM_ISDIALOGMESSAGE:
    {
Alexandre Julliard's avatar
Alexandre Julliard committed
3667
       BOOL msgResult = PROPSHEET_IsDialogMessage(hwnd, (LPMSG)lParam);
3668
       SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);
Alexandre Julliard's avatar
Alexandre Julliard committed
3669
       return TRUE;
3670 3671 3672 3673 3674 3675
    }

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

3676
    case PSM_SETFINISHTEXTA:
3677
      PROPSHEET_SetFinishTextA(hwnd, (LPCSTR) lParam);
3678 3679 3680 3681 3682 3683
      return TRUE;

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

3684
    case PSM_SETCURSELID:
3685 3686
        PROPSHEET_SetCurSelId(hwnd, (int)lParam);
        return TRUE;
3687

3688
    case PSM_SETFINISHTEXTW:
3689
        PROPSHEET_SetFinishTextW(hwnd, (LPCWSTR) lParam);
3690
        return FALSE;
3691

3692 3693 3694
    case PSM_INSERTPAGE:
    {
        BOOL msgResult = PROPSHEET_InsertPage(hwnd, (HPROPSHEETPAGE)wParam, (HPROPSHEETPAGE)lParam);
3695
        SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);
3696 3697 3698 3699 3700 3701 3702 3703 3704 3705 3706 3707 3708 3709 3710 3711 3712 3713 3714 3715 3716 3717
        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);
3718
        SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);
3719 3720 3721 3722 3723 3724
        return TRUE;
    }

    case PSM_INDEXTOHWND:
    {
        LRESULT msgResult = PROPSHEET_IndexToHwnd(hwnd, (int)wParam);
3725
        SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);
3726 3727 3728 3729 3730 3731
        return TRUE;
    }

    case PSM_PAGETOINDEX:
    {
        LRESULT msgResult = PROPSHEET_PageToIndex(hwnd, (HPROPSHEETPAGE)wParam);
3732
        SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);
3733 3734 3735 3736 3737 3738
        return TRUE;
    }

    case PSM_INDEXTOPAGE:
    {
        LRESULT msgResult = PROPSHEET_IndexToPage(hwnd, (int)wParam);
3739
        SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);
3740 3741 3742 3743 3744 3745
        return TRUE;
    }

    case PSM_IDTOINDEX:
    {
        LRESULT msgResult = PROPSHEET_IdToIndex(hwnd, (int)lParam);
3746
        SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);
3747 3748 3749 3750 3751 3752
        return TRUE;
    }

    case PSM_INDEXTOID:
    {
        LRESULT msgResult = PROPSHEET_IndexToId(hwnd, (int)wParam);
3753
        SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);
3754 3755 3756 3757 3758 3759
        return TRUE;
    }

    case PSM_GETRESULT:
    {
        LRESULT msgResult = PROPSHEET_GetResult(hwnd);
3760
        SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);
3761 3762 3763 3764 3765 3766
        return TRUE;
    }

    case PSM_RECALCPAGESIZES:
    {
        LRESULT msgResult = PROPSHEET_RecalcPageSizes(hwnd);
3767
        SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);
3768 3769 3770
        return TRUE;
    }

3771 3772 3773
    default:
      return FALSE;
  }
3774
}