propsheet.c 63.5 KB
Newer Older
1 2 3 4
/*
 * Property Sheets
 *
 * Copyright 1998 Francis Beaudet
5
 * Copyright 1999 Thuy Nguyen
6 7
 *
 * TODO:
8
 *   - Tab order
9
 *   - Unicode property sheets
10 11
 */

12
#include <string.h>
13
#include "winbase.h"
14
#include "commctrl.h"
15
#include "prsht.h"
Alexandre Julliard's avatar
Alexandre Julliard committed
16 17
#include "dialog.h"
#include "win.h"
18
#include "winnls.h"
19
#include "comctl32.h"
20
#include "debugtools.h"
21
#include "heap.h"
22

23 24 25 26 27 28 29 30 31 32 33 34 35 36 37

/******************************************************************************
 * Data structures
 */
typedef struct
{
  WORD dlgVer;
  WORD signature;
  DWORD helpID;
  DWORD exStyle;
  DWORD style;
} MyDLGTEMPLATEEX;

typedef struct tagPropPageInfo
{
38
  HPROPSHEETPAGE hpage; /* to keep track of pages not passed to PropertySheet */
39 40 41 42 43
  HWND hwndPage;
  BOOL isDirty;
  LPCWSTR pszText;
  BOOL hasHelp;
  BOOL useCallback;
Alexandre Julliard's avatar
Alexandre Julliard committed
44
  BOOL hasIcon;
45 46 47 48
} PropPageInfo;

typedef struct tagPropSheetInfo
{
49 50
  HWND hwnd;
  PROPSHEETHEADERA ppshheader;
51
  LPSTR strPropertiesFor;
52
  int nPages;
53 54 55 56 57 58 59
  int active_page;
  BOOL isModeless;
  BOOL hasHelp;
  BOOL hasApply;
  BOOL useCallback;
  BOOL restartWindows;
  BOOL rebootSystem;
Alexandre Julliard's avatar
Alexandre Julliard committed
60
  BOOL activeValid;
61 62 63 64 65
  PropPageInfo* proppage;
  int x;
  int y;
  int width;
  int height;
66
  HIMAGELIST hImageList;
67 68 69 70 71 72 73 74 75 76 77
} PropSheetInfo;

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

/******************************************************************************
 * Defines and global variables
 */
78

79 80 81
const char * PropSheetInfoStr = "PropertySheetInfo";

#define MAX_CAPTION_LENGTH 255
82
#define MAX_TABTEXT_LENGTH 255
Alexandre Julliard's avatar
Alexandre Julliard committed
83
#define MAX_BUTTONTEXT_LENGTH 64
84 85 86 87 88

/******************************************************************************
 * Prototypes
 */
static BOOL PROPSHEET_CreateDialog(PropSheetInfo* psInfo);
89
static BOOL PROPSHEET_SizeMismatch(HWND hwndDlg, PropSheetInfo* psInfo);
90 91 92 93
static BOOL PROPSHEET_AdjustSize(HWND hwndDlg, PropSheetInfo* psInfo);
static BOOL PROPSHEET_AdjustButtons(HWND hwndParent, PropSheetInfo* psInfo);
static BOOL PROPSHEET_CollectSheetInfo(LPCPROPSHEETHEADERA lppsh,
                                       PropSheetInfo * psInfo);
94 95 96
static BOOL PROPSHEET_CollectPageInfo(LPCPROPSHEETPAGEA lppsp,
                                      PropSheetInfo * psInfo,
                                      int index);
97 98 99
static BOOL PROPSHEET_CreateTabControl(HWND hwndParent,
                                       PropSheetInfo * psInfo);
static int PROPSHEET_CreatePage(HWND hwndParent, int index,
100
                                const PropSheetInfo * psInfo,
Alexandre Julliard's avatar
Alexandre Julliard committed
101
                                LPCPROPSHEETPAGEA ppshpage);
102 103
static BOOL PROPSHEET_ShowPage(HWND hwndDlg, int index, PropSheetInfo * psInfo);
static PADDING_INFO PROPSHEET_GetPaddingInfo(HWND hwndDlg);
104 105 106
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
107 108
static BOOL PROPSHEET_Apply(HWND hwndDlg, LPARAM lParam);
static void PROPSHEET_Cancel(HWND hwndDlg, LPARAM lParam);
109
static void PROPSHEET_Help(HWND hwndDlg);
110 111 112
static void PROPSHEET_Changed(HWND hwndDlg, HWND hwndDirtyPage);
static void PROPSHEET_UnChanged(HWND hwndDlg, HWND hwndCleanPage);
static void PROPSHEET_PressButton(HWND hwndDlg, int buttonID);
113
static void PROPSHEET_SetFinishTextA(HWND hwndDlg, LPCSTR lpszText);
114
static void PROPSHEET_SetTitleA(HWND hwndDlg, DWORD dwStyle, LPCSTR lpszText);
115
static BOOL PROPSHEET_CanSetCurSel(HWND hwndDlg);
116 117 118 119 120 121 122 123 124 125 126 127
static BOOL PROPSHEET_SetCurSel(HWND hwndDlg,
                                int index,
                                HPROPSHEETPAGE hpage);
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);
static void PROPSHEET_CleanUp();
128
static int PROPSHEET_GetPageIndex(HPROPSHEETPAGE hpage, PropSheetInfo* psInfo);
129
static void PROPSHEET_SetWizButtons(HWND hwndDlg, DWORD dwFlags);
130
static PADDING_INFO PROPSHEET_GetPaddingInfoWizard(HWND hwndDlg, const PropSheetInfo* psInfo);
Alexandre Julliard's avatar
Alexandre Julliard committed
131 132
static BOOL PROPSHEET_IsDialogMessage(HWND hwnd, LPMSG lpMsg);
static INT PROPSHEET_DoDialogBox( HWND hwnd, HWND owner);
133 134 135 136

BOOL WINAPI
PROPSHEET_DialogProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);

137 138
DEFAULT_DEBUG_CHANNEL(propsheet)

139 140 141 142 143 144 145 146
/******************************************************************************
 *            PROPSHEET_CollectSheetInfo
 *
 * Collect relevant data.
 */
static BOOL PROPSHEET_CollectSheetInfo(LPCPROPSHEETHEADERA lppsh,
                                       PropSheetInfo * psInfo)
{
147
  DWORD dwSize = min(lppsh->dwSize,sizeof(PROPSHEETHEADERA));
148 149 150 151 152 153
  DWORD dwFlags = lppsh->dwFlags;

  psInfo->hasHelp = dwFlags & PSH_HASHELP;
  psInfo->hasApply = !(dwFlags & PSH_NOAPPLYNOW);
  psInfo->useCallback = dwFlags & PSH_USECALLBACK;
  psInfo->isModeless = dwFlags & PSH_MODELESS;
Alexandre Julliard's avatar
Alexandre Julliard committed
154

155
  memcpy(&psInfo->ppshheader,lppsh,dwSize);
Alexandre Julliard's avatar
Alexandre Julliard committed
156 157

  if (HIWORD(lppsh->pszCaption))
158
     psInfo->ppshheader.pszCaption = HEAP_strdupA( GetProcessHeap(),
Alexandre Julliard's avatar
Alexandre Julliard committed
159 160
                                                 0, lppsh->pszCaption );

161
  psInfo->nPages = lppsh->nPages;
162 163 164

  if (dwFlags & PSH_USEPSTARTPAGE)
  {
165
    TRACE("PSH_USEPSTARTPAGE is on");
166 167 168 169 170
    psInfo->active_page = 0;
  }
  else
    psInfo->active_page = lppsh->u2.nStartPage;

Alexandre Julliard's avatar
Alexandre Julliard committed
171 172 173
  if (psInfo->active_page < 0 || psInfo->active_page >= psInfo->nPages)
     psInfo->active_page = 0;

174 175
  psInfo->restartWindows = FALSE;
  psInfo->rebootSystem = FALSE;
176
  psInfo->hImageList = 0;
Alexandre Julliard's avatar
Alexandre Julliard committed
177
  psInfo->activeValid = FALSE;
178 179 180 181 182 183 184 185 186 187

  return TRUE;
}

/******************************************************************************
 *            PROPSHEET_CollectPageInfo
 *
 * Collect property sheet data.
 * With code taken from DIALOG_ParseTemplate32.
 */
188 189 190
BOOL PROPSHEET_CollectPageInfo(LPCPROPSHEETPAGEA lppsp,
                               PropSheetInfo * psInfo,
                               int index)
191 192 193 194 195 196
{
  DLGTEMPLATE* pTemplate;
  const WORD*  p;
  DWORD dwFlags;
  int width, height;

Alexandre Julliard's avatar
Alexandre Julliard committed
197
  psInfo->proppage[index].hpage = (HPROPSHEETPAGE)lppsp;
198 199
  psInfo->proppage[index].hwndPage = 0;
  psInfo->proppage[index].isDirty = FALSE;
200

201 202 203 204 205 206
  /*
   * Process property page flags.
   */
  dwFlags = lppsp->dwFlags;
  psInfo->proppage[index].useCallback = dwFlags & PSP_USECALLBACK;
  psInfo->proppage[index].hasHelp = dwFlags & PSP_HASHELP;
Alexandre Julliard's avatar
Alexandre Julliard committed
207
  psInfo->proppage[index].hasIcon = dwFlags & (PSP_USEHICON | PSP_USEICONID);
208 209 210 211 212 213 214 215 216 217 218

  /* 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->u1.pResource;
  else
219
  {
220 221 222 223 224 225 226
    HRSRC hResource = FindResourceA(lppsp->hInstance,
                                    lppsp->u1.pszTemplate,
                                    RT_DIALOGA);
    HGLOBAL hTemplate = LoadResource(lppsp->hInstance,
                                     hResource);
    pTemplate = (LPDLGTEMPLATEA)LockResource(hTemplate);
  }
227

228 229 230
  /*
   * Extract the size of the page and the caption.
   */
231 232 233
  if (!pTemplate)
      return FALSE;

234
  p = (const WORD *)pTemplate;
235

236 237 238
  if (((MyDLGTEMPLATEEX*)pTemplate)->signature == 0xFFFF)
  {
    /* DIALOGEX template */
239

240 241 242 243 244 245 246 247 248
    p++;       /* dlgVer    */
    p++;       /* signature */
    p += 2;    /* help ID   */
    p += 2;    /* ext style */
    p += 2;    /* style     */
  }
  else
  {
    /* DIALOG template */
249

250 251 252
    p += 2;    /* style     */
    p += 2;    /* ext style */
  }
253

254 255 256 257 258
  p++;    /* nb items */
  p++;    /*   x      */
  p++;    /*   y      */
  width  = (WORD)*p; p++;
  height = (WORD)*p; p++;
259

260 261 262
  /* remember the largest width and height */
  if (width > psInfo->width)
    psInfo->width = width;
263

264 265
  if (height > psInfo->height)
    psInfo->height = height;
266

267 268 269 270 271 272 273 274 275 276 277 278 279
  /* menu */
  switch ((WORD)*p)
  {
    case 0x0000:
      p++;
      break;
    case 0xffff:
      p += 2;
      break;
    default:
      p += lstrlenW( (LPCWSTR)p ) + 1;
      break;
  } 
280

281 282 283 284 285 286 287 288 289 290 291 292
  /* class */
  switch ((WORD)*p)
  {
    case 0x0000:
      p++;
      break;
    case 0xffff:
      p += 2;
      break;
    default:
      p += lstrlenW( (LPCWSTR)p ) + 1;
      break;
293 294
  }

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

300 301
  if (dwFlags & PSP_USETITLE)
  {
302 303 304 305 306 307 308 309 310 311 312 313 314 315
    if ( !HIWORD( lppsp->pszTitle ) )
    {
      char szTitle[256];
      
      if ( !LoadStringA( lppsp->hInstance, (UINT) lppsp->pszTitle, szTitle, 256 ) )
	return FALSE;
      
      psInfo->proppage[index].pszText = HEAP_strdupAtoW( GetProcessHeap(),
							 0, szTitle );
    }
    else
      psInfo->proppage[index].pszText = HEAP_strdupAtoW(GetProcessHeap(),
							0,
							lppsp->pszTitle);
316 317
  }

318 319 320
  /*
   * Build the image list for icons
   */
321
  if ((dwFlags & PSP_USEHICON) || (dwFlags & PSP_USEICONID)) 
322 323 324 325 326 327 328 329 330 331 332
  {
    HICON hIcon;
    int icon_cx = GetSystemMetrics(SM_CXSMICON);
    int icon_cy = GetSystemMetrics(SM_CYSMICON);

    if (dwFlags & PSP_USEICONID)
      hIcon = LoadImageA(lppsp->hInstance, lppsp->u2.pszIcon, IMAGE_ICON, 
                         icon_cx, icon_cy, LR_DEFAULTCOLOR);
    else
      hIcon = lppsp->u2.hIcon;

Alexandre Julliard's avatar
Alexandre Julliard committed
333 334 335 336 337 338 339
    if ( hIcon )
    {
      if (psInfo->hImageList == 0 )
	psInfo->hImageList = ImageList_Create(icon_cx, icon_cy, ILC_COLOR, 1, 1);

      ImageList_AddIcon(psInfo->hImageList, hIcon);
    }
340 341 342

  }

343 344 345
  return TRUE;
}

Alexandre Julliard's avatar
Alexandre Julliard committed
346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362
/******************************************************************************
 *            PROPSHEET_DoDialogBox
 *
 * Copied from windows/dialog.c:DIALOG_DoDialogBox
 */
static INT PROPSHEET_DoDialogBox( HWND hwnd, HWND owner)
{
   WND * wndPtr;
   DIALOGINFO * dlgInfo;
   MSG msg;
   INT retval;

     /* Owner must be a top-level window */
   owner = WIN_GetTopParent( owner );
   if (!(wndPtr = WIN_FindWndPtr( hwnd ))) return -1;
   dlgInfo = (DIALOGINFO *)wndPtr->wExtra;

363
   if (!(dlgInfo->flags & DF_END)) /* was EndDialog called in WM_INITDIALOG ? */
Alexandre Julliard's avatar
Alexandre Julliard committed
364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384
   {
       EnableWindow( owner, FALSE );
       ShowWindow( hwnd, SW_SHOW );
       while (GetMessageA(&msg, 0, 0, 0))
       {
           if (!PROPSHEET_IsDialogMessage( hwnd, &msg))
           {
               TranslateMessage( &msg );
               DispatchMessageA( &msg );
           }
           if (dlgInfo->flags & DF_END) break;
       }
       EnableWindow( owner, TRUE );
   }
   retval = dlgInfo->idResult; 
   WIN_ReleaseWndPtr(wndPtr);
   DestroyWindow( hwnd );
   return retval;
}


385 386 387 388 389 390 391 392 393
/******************************************************************************
 *            PROPSHEET_CreateDialog
 *
 * Creates the actual property sheet.
 */
BOOL PROPSHEET_CreateDialog(PropSheetInfo* psInfo)
{
  LRESULT ret;
  LPCVOID template;
394
  LPVOID temp = 0;
395
  HRSRC hRes;
396
  DWORD resSize;
397 398
  WORD resID = IDD_PROPSHEET;

399
  if (psInfo->ppshheader.dwFlags & PSH_WIZARD)
400
    resID = IDD_WIZARD;
401

402
  if(!(hRes = FindResourceA(COMCTL32_hModule,
403
                            MAKEINTRESOURCEA(resID),
404
                            RT_DIALOGA)))
405 406 407 408
    return FALSE;

  if(!(template = (LPVOID)LoadResource(COMCTL32_hModule, hRes)))
    return FALSE;
409

410 411 412 413 414 415 416 417 418 419 420 421
  /*
   * Make a copy of the dialog template.
   */
  resSize = SizeofResource(COMCTL32_hModule, hRes);

  temp = COMCTL32_Alloc(resSize);

  if (!temp)
    return FALSE;

  memcpy(temp, template, resSize);

422
  if (psInfo->useCallback)
423
    (*(psInfo->ppshheader.pfnCallback))(0, PSCB_PRECREATE, (LPARAM)temp);
424

425
  ret = CreateDialogIndirectParamA(psInfo->ppshheader.hInstance,
426
                                     (LPDLGTEMPLATEA) temp,
427
                                     psInfo->ppshheader.hwndParent,
428 429 430
                                     (DLGPROC) PROPSHEET_DialogProc,
                                     (LPARAM)psInfo);

431 432
  if (!(psInfo->ppshheader.dwFlags & PSH_MODELESS))
     ret = PROPSHEET_DoDialogBox((HWND)ret, psInfo->ppshheader.hwndParent);
Alexandre Julliard's avatar
Alexandre Julliard committed
433
 
434 435
  COMCTL32_Free(temp);

436 437 438 439
  return ret;
}

/******************************************************************************
440
 *            PROPSHEET_SizeMismatch
441
 * 
442 443
 *     Verify that the tab control and the "largest" property sheet page dlg. template
 *     match in size.
444
 */
445
static BOOL PROPSHEET_SizeMismatch(HWND hwndDlg, PropSheetInfo* psInfo)
446 447 448 449 450 451 452 453
{
  HWND hwndTabCtrl = GetDlgItem(hwndDlg, IDC_TABCONTROL);
  RECT rcOrigTab, rcPage;

  /*
   * Original tab size.
   */
  GetClientRect(hwndTabCtrl, &rcOrigTab);
454
  TRACE("orig tab %d %d %d %d\n", rcOrigTab.left, rcOrigTab.top,
455 456 457 458 459 460 461 462 463 464 465
        rcOrigTab.right, rcOrigTab.bottom);

  /*
   * Biggest page size.
   */
  rcPage.left   = psInfo->x;
  rcPage.top    = psInfo->y;
  rcPage.right  = psInfo->width;
  rcPage.bottom = psInfo->height;

  MapDialogRect(hwndDlg, &rcPage);
466
  TRACE("biggest page %d %d %d %d\n", rcPage.left, rcPage.top,
467 468
        rcPage.right, rcPage.bottom);

469
  if ( (rcPage.right - rcPage.left) != (rcOrigTab.right - rcOrigTab.left) )
470
    return TRUE;
471
  if ( (rcPage.bottom - rcPage.top) != (rcOrigTab.bottom - rcOrigTab.top) )
472 473 474 475 476
    return TRUE;

  return FALSE;
}

477 478 479 480 481 482 483 484 485
/******************************************************************************
 *            PROPSHEET_IsTooSmallWizard
 *
 * Verify that the default property sheet is big enough.
 */
static BOOL PROPSHEET_IsTooSmallWizard(HWND hwndDlg, PropSheetInfo* psInfo)
{
  RECT rcSheetRect, rcPage, rcLine, rcSheetClient;
  HWND hwndLine = GetDlgItem(hwndDlg, IDC_SUNKEN_LINE);
486
  PADDING_INFO padding = PROPSHEET_GetPaddingInfoWizard(hwndDlg, psInfo);
487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519

  GetClientRect(hwndDlg, &rcSheetClient);
  GetWindowRect(hwndDlg, &rcSheetRect);
  GetWindowRect(hwndLine, &rcLine);

  /* Remove the space below the sunken line */
  rcSheetClient.bottom -= (rcSheetRect.bottom - rcLine.top);

  /* Remove the buffer zone all around the edge */
  rcSheetClient.bottom -= (padding.y * 2);
  rcSheetClient.right -= (padding.x * 2);

  /*
   * Biggest page size.
   */
  rcPage.left   = psInfo->x;
  rcPage.top    = psInfo->y;
  rcPage.right  = psInfo->width;
  rcPage.bottom = psInfo->height;

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

  if (rcPage.right > rcSheetClient.right)
    return TRUE;

  if (rcPage.bottom > rcSheetClient.bottom)
    return TRUE;

  return FALSE;
}

520 521 522 523 524 525 526 527 528
/******************************************************************************
 *            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);
529
  RECT rc,tabRect;
530 531
  int tabOffsetX, tabOffsetY, buttonHeight;
  PADDING_INFO padding = PROPSHEET_GetPaddingInfo(hwndDlg);
532 533
  WND * wndPtr = WIN_FindWndPtr( hwndDlg );
  DIALOGINFO * dlgInfo = (DIALOGINFO *)wndPtr->wExtra;
534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551

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

  /*
   * Biggest page size.
   */
  rc.left   = psInfo->x;
  rc.top    = psInfo->y;
  rc.right  = psInfo->width;
  rc.bottom = psInfo->height;

  MapDialogRect(hwndDlg, &rc);

  /*
   * Resize the tab control.
   */
552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567
  GetClientRect(hwndTabCtrl,&tabRect);

  SendMessageA(hwndTabCtrl, TCM_ADJUSTRECT, FALSE, (LPARAM)&tabRect);

  if ((rc.bottom - rc.top) < (tabRect.bottom - tabRect.top))
  {
      rc.bottom = rc.top + tabRect.bottom - tabRect.top;
      psInfo->height = MulDiv((rc.bottom - rc.top),8,dlgInfo->yBaseUnit);
  }
  
  if ((rc.right - rc.left) < (tabRect.right - tabRect.left))
  {
      rc.right = rc.left + tabRect.right - tabRect.left;
      psInfo->width  = MulDiv((rc.right - rc.left),4,dlgInfo->xBaseUnit);
  }

568 569 570 571 572 573 574 575 576 577 578 579
  SendMessageA(hwndTabCtrl, TCM_ADJUSTRECT, TRUE, (LPARAM)&rc);

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

  rc.right -= rc.left;
  rc.bottom -= rc.top;
  SetWindowPos(hwndTabCtrl, 0, 0, 0, rc.right, rc.bottom,
               SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE);

  GetClientRect(hwndTabCtrl, &rc);

580
  TRACE("tab client rc %d %d %d %d\n",
581 582 583 584 585 586 587 588 589 590 591
        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.
   */
  SetWindowPos(hwndDlg, 0, 0, 0, rc.right, rc.bottom,
               SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE);

592
  WIN_ReleaseWndPtr(wndPtr);
593 594 595
  return TRUE;
}

596 597 598 599 600 601 602 603 604
/******************************************************************************
 *            PROPSHEET_AdjustSizeWizard
 *
 * Resizes the property sheet to fit the largest page.
 */
static BOOL PROPSHEET_AdjustSizeWizard(HWND hwndDlg, PropSheetInfo* psInfo)
{
  HWND hwndButton = GetDlgItem(hwndDlg, IDCANCEL);
  HWND hwndLine = GetDlgItem(hwndDlg, IDC_SUNKEN_LINE);
605 606
  HWND hwndTabCtrl = GetDlgItem(hwndDlg, IDC_TABCONTROL);
  RECT rc,tabRect;
607
  int buttonHeight, lineHeight;
608
  PADDING_INFO padding = PROPSHEET_GetPaddingInfoWizard(hwndDlg, psInfo);
609 610
  WND * wndPtr = WIN_FindWndPtr( hwndDlg );
  DIALOGINFO * dlgInfo = (DIALOGINFO *)wndPtr->wExtra;
611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628

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

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

  /*
   * Biggest page size.
   */
  rc.left   = psInfo->x;
  rc.top    = psInfo->y;
  rc.right  = psInfo->width;
  rc.bottom = psInfo->height;

  MapDialogRect(hwndDlg, &rc);

629 630 631 632 633 634 635 636 637 638 639 640 641 642
  GetClientRect(hwndTabCtrl,&tabRect);

  if ((rc.bottom - rc.top) < (tabRect.bottom - tabRect.top))
  {
      rc.bottom = rc.top + tabRect.bottom - tabRect.top;
      psInfo->height = MulDiv((rc.bottom - rc.top), 8, dlgInfo->yBaseUnit);
  }
  
  if ((rc.right - rc.left) < (tabRect.right - tabRect.left))
  {
      rc.right = rc.left + tabRect.right - tabRect.left;
      psInfo->width  = MulDiv((rc.right - rc.left), 4, dlgInfo->xBaseUnit);
  }

643 644 645 646 647 648 649 650 651 652 653 654
  TRACE("Biggest page %d %d %d %d\n", rc.left, rc.top, rc.right, rc.bottom);

  /* Make room */
  rc.right += (padding.x * 2);
  rc.bottom += (buttonHeight + (5 * padding.y) + lineHeight);

  /*
   * Resize the property sheet.
   */
  SetWindowPos(hwndDlg, 0, 0, 0, rc.right, rc.bottom,
               SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE);

655
  WIN_ReleaseWndPtr(wndPtr);
656 657 658
  return TRUE;
}

659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753
/******************************************************************************
 *            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.
   */ 
  GetClientRect(hwndParent, &rcSheet);

  /* 
   * All buttons will be at this y coordinate.
   */
  y = rcSheet.bottom - (padding.y + buttonHeight);

  /*
   * Position OK button.
   */
  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);

  /*
   * 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);
  
    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);
  
    SetWindowPos(hwndButton, 0, x, y, 0, 0,
                 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
  }
  else
    ShowWindow(hwndButton, SW_HIDE);

  return TRUE;
}

754 755 756 757 758 759 760 761 762 763 764 765 766 767
/******************************************************************************
 *            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);
  RECT rcSheet;
  int x, y;
  int num_buttons = 3;
  int buttonWidth, buttonHeight, lineHeight, lineWidth;
768
  PADDING_INFO padding = PROPSHEET_GetPaddingInfoWizard(hwndParent, psInfo);
769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859

  if (psInfo->hasHelp)
    num_buttons++;

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

  /*
   * Position the Next and the Finish buttons.
   */
  hwndButton = GetDlgItem(hwndParent, IDC_NEXT_BUTTON);

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

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

  hwndButton = GetDlgItem(hwndParent, IDC_FINISH_BUTTON);

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

  ShowWindow(hwndButton, SW_HIDE);

  /*
   * Position the Back button.
   */
  hwndButton = GetDlgItem(hwndParent, IDC_BACK_BUTTON);

  x -= buttonWidth;

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

  /*
   * Position the Cancel button.
   */
  hwndButton = GetDlgItem(hwndParent, IDCANCEL);

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

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

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

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

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

  /*
   * Position and resize the sunken line.
   */
  x = padding.x;
  y = rcSheet.bottom - ((padding.y * 2) + buttonHeight + lineHeight);

  GetClientRect(hwndParent, &rcSheet);
  lineWidth = rcSheet.right - (padding.x * 2);

  SetWindowPos(hwndLine, 0, x, y, lineWidth, 2,
               SWP_NOZORDER | SWP_NOACTIVATE);

  return TRUE;
}

860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884
/******************************************************************************
 *            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;
}

885 886 887 888 889
/******************************************************************************
 *            PROPSHEET_GetPaddingInfoWizard
 *
 * Returns the layout information.
 * Vertical spacing is the distance between the line and the buttons.
890 891 892 893 894 895
 * 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.
896
 */
897 898
static PADDING_INFO PROPSHEET_GetPaddingInfoWizard(HWND hwndDlg, const PropSheetInfo*
 psInfo)
899 900 901 902
{
  PADDING_INFO padding;
  RECT rc;
  HWND hwndControl;
903 904
  INT idButton;
  POINT ptButton, ptLine;
905

906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923
  if (psInfo->hasHelp)
  {
	idButton = IDHELP;
  }
  else
  {
    if (psInfo->ppshheader.dwFlags & PSH_WIZARD)
    {
	idButton = IDC_NEXT_BUTTON;
    }
    else
    {
	/* hopefully this is ok */
	idButton = IDCANCEL;
    }
  }
  
  hwndControl = GetDlgItem(hwndDlg, idButton);
924 925
  GetWindowRect(hwndControl, &rc);

926 927
  ptButton.x = rc.left;
  ptButton.y = rc.top;
928

929
  ScreenToClient(hwndDlg, &ptButton);
930 931 932 933 934 935 936 937 938 939

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

  ptLine.x = 0;
  ptLine.y = rc.bottom;

  ScreenToClient(hwndDlg, &ptLine);

940 941 942 943
  padding.y = ptButton.y - ptLine.y;

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

945 946
  /* this is most probably not correct, but the best we have now */
  padding.x = padding.y;
947 948 949
  return padding;
}

950 951 952 953 954 955 956 957 958 959 960
/******************************************************************************
 *            PROPSHEET_CreateTabControl
 *
 * Insert the tabs in the tab control.
 */
static BOOL PROPSHEET_CreateTabControl(HWND hwndParent,
                                       PropSheetInfo * psInfo)
{
  HWND hwndTabCtrl = GetDlgItem(hwndParent, IDC_TABCONTROL);
  TCITEMA item;
  int i, nTabs;
Alexandre Julliard's avatar
Alexandre Julliard committed
961
  int iImage = 0;
962
  char tabtext[MAX_TABTEXT_LENGTH] = "Tab text";
963 964 965

  item.mask = TCIF_TEXT;
  item.pszText = tabtext;
966
  item.cchTextMax = MAX_TABTEXT_LENGTH;
967

968
  nTabs = psInfo->nPages;
969

970 971 972 973 974 975 976 977
  /*
   * Set the image list for icons.
   */
  if (psInfo->hImageList)
  {
    SendMessageA(hwndTabCtrl, TCM_SETIMAGELIST, 0, (LPARAM)psInfo->hImageList);
  }

978 979
  for (i = 0; i < nTabs; i++)
  {
Alexandre Julliard's avatar
Alexandre Julliard committed
980 981 982 983 984 985 986 987 988
    if ( psInfo->proppage[i].hasIcon )
    {
      item.mask |= TCIF_IMAGE;
      item.iImage = iImage++;
    }
    else
    {
      item.mask &= ~TCIF_IMAGE;
    }
989

990 991
    WideCharToMultiByte(CP_ACP, 0,
                        (LPCWSTR)psInfo->proppage[i].pszText,
992
                        -1, tabtext, MAX_TABTEXT_LENGTH, NULL, NULL);
993 994 995 996 997 998 999 1000 1001 1002

    SendMessageA(hwndTabCtrl, TCM_INSERTITEMA, (WPARAM)i, (LPARAM)&item);
  }

  return TRUE;
}

/******************************************************************************
 *            PROPSHEET_CreatePage
 *
1003
 * Creates a page.
1004 1005 1006
 */
static int PROPSHEET_CreatePage(HWND hwndParent,
                                int index,
1007
                                const PropSheetInfo * psInfo,
Alexandre Julliard's avatar
Alexandre Julliard committed
1008
                                LPCPROPSHEETPAGEA ppshpage)
1009 1010 1011 1012 1013
{
  DLGTEMPLATE* pTemplate;
  HWND hwndPage;
  RECT rc;
  PropPageInfo* ppInfo = psInfo->proppage;
1014
  PADDING_INFO padding;
1015
  UINT pageWidth,pageHeight;
1016

1017
  TRACE("index %d\n", index);
1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031

  if (ppshpage->dwFlags & PSP_DLGINDIRECT)
    pTemplate = (DLGTEMPLATE*)ppshpage->u1.pResource;
  else
  {
    HRSRC hResource = FindResourceA(ppshpage->hInstance,
                                    ppshpage->u1.pszTemplate,
                                    RT_DIALOGA);
    HGLOBAL hTemplate = LoadResource(ppshpage->hInstance, hResource);
    pTemplate = (LPDLGTEMPLATEA)LockResource(hTemplate);
  }

  if (((MyDLGTEMPLATEEX*)pTemplate)->signature == 0xFFFF)
  {
Alexandre Julliard's avatar
Alexandre Julliard committed
1032
    ((MyDLGTEMPLATEEX*)pTemplate)->style |= WS_CHILD | DS_CONTROL;
1033 1034 1035 1036
    ((MyDLGTEMPLATEEX*)pTemplate)->style &= ~DS_MODALFRAME;
    ((MyDLGTEMPLATEEX*)pTemplate)->style &= ~WS_CAPTION;
    ((MyDLGTEMPLATEEX*)pTemplate)->style &= ~WS_SYSMENU;
    ((MyDLGTEMPLATEEX*)pTemplate)->style &= ~WS_POPUP;
1037
    ((MyDLGTEMPLATEEX*)pTemplate)->style &= ~WS_DISABLED;
Alexandre Julliard's avatar
Alexandre Julliard committed
1038
    ((MyDLGTEMPLATEEX*)pTemplate)->style &= ~WS_VISIBLE;
1039 1040 1041
  }
  else
  {
Alexandre Julliard's avatar
Alexandre Julliard committed
1042
    pTemplate->style |= WS_CHILD | DS_CONTROL;
1043 1044 1045 1046
    pTemplate->style &= ~DS_MODALFRAME;
    pTemplate->style &= ~WS_CAPTION;
    pTemplate->style &= ~WS_SYSMENU;
    pTemplate->style &= ~WS_POPUP;
1047
    pTemplate->style &= ~WS_DISABLED;
Alexandre Julliard's avatar
Alexandre Julliard committed
1048
    pTemplate->style &= ~WS_VISIBLE;
1049 1050 1051 1052 1053 1054 1055
  }

  if (psInfo->proppage[index].useCallback)
    (*(ppshpage->pfnCallback))(hwndParent,
                               PSPCB_CREATE,
                               (LPPROPSHEETPAGEA)ppshpage);

1056 1057 1058 1059
  hwndPage = CreateDialogIndirectParamA(ppshpage->hInstance,
					pTemplate,
					hwndParent,
					ppshpage->pfnDlgProc,
Marcus Meissner's avatar
Marcus Meissner committed
1060
					(LPARAM)ppshpage);
1061 1062 1063 1064 1065 1066 1067 1068 1069 1070

  ppInfo[index].hwndPage = hwndPage;

  rc.left = psInfo->x;
  rc.top = psInfo->y;
  rc.right = psInfo->width;
  rc.bottom = psInfo->height;

  MapDialogRect(hwndParent, &rc);

1071 1072 1073
  pageWidth = rc.right - rc.left;
  pageHeight = rc.bottom - rc.top;

1074
  if (psInfo->ppshheader.dwFlags & PSH_WIZARD)
1075
    padding = PROPSHEET_GetPaddingInfoWizard(hwndParent, psInfo);
1076 1077 1078 1079 1080 1081 1082 1083 1084 1085
  else
  {
    /*
     * Ask the Tab control to fit this page in.
     */

    HWND hwndTabCtrl = GetDlgItem(hwndParent, IDC_TABCONTROL);
    SendMessageA(hwndTabCtrl, TCM_ADJUSTRECT, FALSE, (LPARAM)&rc);
    padding = PROPSHEET_GetPaddingInfo(hwndParent);
  }
1086

1087
  SetWindowPos(hwndPage, HWND_TOP,
1088 1089
               rc.left + padding.x,
               rc.top + padding.y,
1090
               pageWidth, pageHeight, 0);
1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102

  return TRUE;
}

/******************************************************************************
 *            PROPSHEET_ShowPage
 *
 * Displays or creates the specified page.
 */
static BOOL PROPSHEET_ShowPage(HWND hwndDlg, int index, PropSheetInfo * psInfo)
{
  if (index == psInfo->active_page)
1103 1104
    {
      if (GetTopWindow(hwndDlg) != psInfo->proppage[index].hwndPage)
Alexandre Julliard's avatar
Alexandre Julliard committed
1105
          SetWindowPos(psInfo->proppage[index].hwndPage, HWND_TOP, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE);
1106 1107
    return TRUE;
    }
1108

Alexandre Julliard's avatar
Alexandre Julliard committed
1109
  if (psInfo->proppage[index].hwndPage == 0)
1110
  {
Alexandre Julliard's avatar
Alexandre Julliard committed
1111
     LPCPROPSHEETPAGEA ppshpage;
1112
     PSHNOTIFY psn;
Alexandre Julliard's avatar
Alexandre Julliard committed
1113 1114 1115 1116

     ppshpage = (LPCPROPSHEETPAGEA)psInfo->proppage[index].hpage;
     PROPSHEET_CreatePage(hwndDlg, index, psInfo, ppshpage);

1117 1118 1119 1120
     psn.hdr.hwndFrom = hwndDlg;
     psn.hdr.code     = PSN_SETACTIVE;
     psn.hdr.idFrom   = 0;
     psn.lParam       = 0;
Alexandre Julliard's avatar
Alexandre Julliard committed
1121

1122 1123 1124
     /* Send the notification before showing the page. */
     SendMessageA(psInfo->proppage[index].hwndPage,
                  WM_NOTIFY, 0, (LPARAM) &psn);
Alexandre Julliard's avatar
Alexandre Julliard committed
1125

1126 1127 1128 1129
     /*
      * TODO: check return value. 
      */
  }
Alexandre Julliard's avatar
Alexandre Julliard committed
1130

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

1134
  ShowWindow(psInfo->proppage[index].hwndPage, SW_SHOW);
1135

1136
  if (!(psInfo->ppshheader.dwFlags & PSH_WIZARD))
1137 1138 1139 1140 1141 1142 1143 1144
  {
     HWND hwndTabCtrl;

     /* Synchronize current selection with tab control */
     hwndTabCtrl = GetDlgItem(hwndDlg, IDC_TABCONTROL);
     SendMessageA(hwndTabCtrl, TCM_SETCURSEL, index, 0);
  }

1145
  psInfo->active_page = index;
Alexandre Julliard's avatar
Alexandre Julliard committed
1146
  psInfo->activeValid = TRUE;
1147 1148 1149 1150

  return TRUE;
}

1151 1152 1153 1154 1155 1156
/******************************************************************************
 *            PROPSHEET_Back
 */
static BOOL PROPSHEET_Back(HWND hwndDlg)
{
  BOOL res;
Alexandre Julliard's avatar
Alexandre Julliard committed
1157
  PSHNOTIFY psn;
1158 1159 1160 1161
  HWND hwndPage;
  PropSheetInfo* psInfo = (PropSheetInfo*) GetPropA(hwndDlg,
                                                    PropSheetInfoStr);

Alexandre Julliard's avatar
Alexandre Julliard committed
1162
  if (psInfo->active_page < 0)
1163 1164
     return FALSE;

Alexandre Julliard's avatar
Alexandre Julliard committed
1165 1166 1167 1168 1169
  psn.hdr.code     = PSN_WIZBACK;
  psn.hdr.hwndFrom = hwndDlg;
  psn.hdr.idFrom   = 0;
  psn.lParam       = 0;
 
1170 1171
  hwndPage = psInfo->proppage[psInfo->active_page].hwndPage;

Alexandre Julliard's avatar
Alexandre Julliard committed
1172
  if (SendMessageA(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn) == -1)
1173 1174
    return FALSE;

Alexandre Julliard's avatar
Alexandre Julliard committed
1175
  if (psInfo->active_page > 0)
1176
  {
Alexandre Julliard's avatar
Alexandre Julliard committed
1177 1178 1179 1180 1181
     res = PROPSHEET_CanSetCurSel(hwndDlg);
     if(res != FALSE)
     {
       res = PROPSHEET_SetCurSel(hwndDlg, psInfo->active_page - 1, 0);
     }
1182
  }
1183 1184 1185 1186 1187 1188 1189 1190 1191

  return TRUE;
}

/******************************************************************************
 *            PROPSHEET_Next
 */
static BOOL PROPSHEET_Next(HWND hwndDlg)
{
Alexandre Julliard's avatar
Alexandre Julliard committed
1192
  PSHNOTIFY psn;
1193 1194 1195 1196 1197
  HWND hwndPage;
  LRESULT msgResult = 0;
  PropSheetInfo* psInfo = (PropSheetInfo*) GetPropA(hwndDlg,
                                                    PropSheetInfoStr);

Alexandre Julliard's avatar
Alexandre Julliard committed
1198
  if (psInfo->active_page < 0)
1199 1200
     return FALSE;

Alexandre Julliard's avatar
Alexandre Julliard committed
1201 1202 1203 1204 1205
  psn.hdr.code     = PSN_WIZNEXT;
  psn.hdr.hwndFrom = hwndDlg;
  psn.hdr.idFrom   = 0;
  psn.lParam       = 0;
 
1206 1207
  hwndPage = psInfo->proppage[psInfo->active_page].hwndPage;

Alexandre Julliard's avatar
Alexandre Julliard committed
1208
  msgResult = SendMessageA(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn);
1209 1210 1211 1212 1213 1214

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

  if (msgResult == -1)
    return FALSE;

1215 1216 1217 1218
  if(PROPSHEET_CanSetCurSel(hwndDlg) != FALSE)
  {
    PROPSHEET_SetCurSel(hwndDlg, psInfo->active_page + 1, 0);
  }
1219 1220 1221 1222 1223 1224 1225 1226 1227

  return TRUE;
}

/******************************************************************************
 *            PROPSHEET_Finish
 */
static BOOL PROPSHEET_Finish(HWND hwndDlg)
{
Alexandre Julliard's avatar
Alexandre Julliard committed
1228
  PSHNOTIFY psn;
1229 1230 1231 1232 1233
  HWND hwndPage;
  LRESULT msgResult = 0;
  PropSheetInfo* psInfo = (PropSheetInfo*) GetPropA(hwndDlg,
                                                    PropSheetInfoStr);

1234 1235 1236
  if (psInfo->active_page < 0)
     return FALSE;

Alexandre Julliard's avatar
Alexandre Julliard committed
1237 1238 1239 1240 1241
  psn.hdr.code     = PSN_WIZFINISH;
  psn.hdr.hwndFrom = hwndDlg;
  psn.hdr.idFrom   = 0;
  psn.lParam       = 0;
 
1242 1243
  hwndPage = psInfo->proppage[psInfo->active_page].hwndPage;

Alexandre Julliard's avatar
Alexandre Julliard committed
1244
  msgResult = SendMessageA(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn);
1245 1246 1247 1248 1249 1250 1251

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

  if (msgResult != 0)
    return FALSE;

  if (psInfo->isModeless)
Alexandre Julliard's avatar
Alexandre Julliard committed
1252
    psInfo->activeValid = FALSE;
1253 1254 1255 1256 1257 1258
  else
    EndDialog(hwndDlg, TRUE);

  return TRUE;
}

1259 1260 1261
/******************************************************************************
 *            PROPSHEET_Apply
 */
Alexandre Julliard's avatar
Alexandre Julliard committed
1262
static BOOL PROPSHEET_Apply(HWND hwndDlg, LPARAM lParam)
1263 1264 1265
{
  int i;
  HWND hwndPage;
Alexandre Julliard's avatar
Alexandre Julliard committed
1266
  PSHNOTIFY psn;
1267 1268 1269 1270
  LRESULT msgResult;
  PropSheetInfo* psInfo = (PropSheetInfo*) GetPropA(hwndDlg,
                                                    PropSheetInfoStr);

1271 1272 1273
  if (psInfo->active_page < 0)
     return FALSE;

Alexandre Julliard's avatar
Alexandre Julliard committed
1274 1275 1276 1277
  psn.hdr.hwndFrom = hwndDlg;
  psn.hdr.idFrom   = 0;
  psn.lParam       = 0;
 
1278 1279 1280 1281

  /*
   * Send PSN_KILLACTIVE to the current page.
   */
Alexandre Julliard's avatar
Alexandre Julliard committed
1282
  psn.hdr.code = PSN_KILLACTIVE;
1283 1284 1285

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

Alexandre Julliard's avatar
Alexandre Julliard committed
1286
  if (SendMessageA(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn) != FALSE)
1287 1288 1289 1290 1291
    return FALSE;

  /*
   * Send PSN_APPLY to all pages.
   */
Alexandre Julliard's avatar
Alexandre Julliard committed
1292 1293 1294
  psn.hdr.code = PSN_APPLY;
  psn.lParam   = lParam;
 
1295
  for (i = 0; i < psInfo->nPages; i++)
1296 1297
  {
    hwndPage = psInfo->proppage[i].hwndPage;
Alexandre Julliard's avatar
Alexandre Julliard committed
1298 1299 1300 1301 1302 1303 1304
    if (hwndPage)
    {
       msgResult = SendMessageA(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn);
       if (msgResult == PSNRET_INVALID_NOCHANGEPAGE)
          return FALSE;
    }
  }
1305

Alexandre Julliard's avatar
Alexandre Julliard committed
1306 1307 1308 1309 1310 1311 1312 1313 1314 1315
  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;
     SendMessageA(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn);
1316 1317 1318 1319 1320 1321 1322 1323
  }

  return TRUE;
}

/******************************************************************************
 *            PROPSHEET_Cancel
 */
Alexandre Julliard's avatar
Alexandre Julliard committed
1324
static void PROPSHEET_Cancel(HWND hwndDlg, LPARAM lParam)
1325 1326 1327
{
  PropSheetInfo* psInfo = (PropSheetInfo*) GetPropA(hwndDlg,
                                                    PropSheetInfoStr);
1328
  HWND hwndPage;
Alexandre Julliard's avatar
Alexandre Julliard committed
1329 1330
  PSHNOTIFY psn;
  int i;
1331

1332 1333 1334 1335
  if (psInfo->active_page < 0)
     return;

  hwndPage = psInfo->proppage[psInfo->active_page].hwndPage;
Alexandre Julliard's avatar
Alexandre Julliard committed
1336 1337 1338 1339 1340 1341
  psn.hdr.code     = PSN_QUERYCANCEL;
  psn.hdr.hwndFrom = hwndDlg;
  psn.hdr.idFrom   = 0;
  psn.lParam       = 0;
 
  if (SendMessageA(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn))
1342 1343
    return;

Alexandre Julliard's avatar
Alexandre Julliard committed
1344 1345 1346 1347 1348 1349
  psn.hdr.code = PSN_RESET;
  psn.lParam   = lParam;
 
  for (i = 0; i < psInfo->nPages; i++)
  {
    hwndPage = psInfo->proppage[i].hwndPage;
1350

Alexandre Julliard's avatar
Alexandre Julliard committed
1351 1352 1353
    if (hwndPage)
       SendMessageA(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn);
  }
1354 1355

  if (psInfo->isModeless)
Alexandre Julliard's avatar
Alexandre Julliard committed
1356 1357 1358 1359
  {
     /* makes PSM_GETCURRENTPAGEHWND return NULL */
     psInfo->activeValid = FALSE;
  }
1360 1361 1362 1363
  else
    EndDialog(hwndDlg, FALSE);
}

1364 1365 1366 1367 1368 1369 1370
/******************************************************************************
 *            PROPSHEET_Help
 */
static void PROPSHEET_Help(HWND hwndDlg)
{
  PropSheetInfo* psInfo = (PropSheetInfo*) GetPropA(hwndDlg,
                                                    PropSheetInfoStr);
1371
  HWND hwndPage;
Alexandre Julliard's avatar
Alexandre Julliard committed
1372
  PSHNOTIFY psn;
1373

1374 1375 1376 1377
  if (psInfo->active_page < 0)
     return;

  hwndPage = psInfo->proppage[psInfo->active_page].hwndPage;
Alexandre Julliard's avatar
Alexandre Julliard committed
1378 1379 1380 1381 1382 1383
  psn.hdr.code     = PSN_HELP;
  psn.hdr.hwndFrom = hwndDlg;
  psn.hdr.idFrom   = 0;
  psn.lParam       = 0;
 
  SendMessageA(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn);
1384 1385
}

1386 1387 1388 1389 1390 1391 1392 1393 1394
/******************************************************************************
 *            PROPSHEET_Changed
 */
static void PROPSHEET_Changed(HWND hwndDlg, HWND hwndDirtyPage)
{
  int i;
  PropSheetInfo* psInfo = (PropSheetInfo*) GetPropA(hwndDlg,
                                                    PropSheetInfoStr);

1395
  if (!psInfo) return;
1396 1397 1398
  /*
   * Set the dirty flag of this page.
   */
1399
  for (i = 0; i < psInfo->nPages; i++)
1400 1401 1402 1403
  {
    if (psInfo->proppage[i].hwndPage == hwndDirtyPage)
      psInfo->proppage[i].isDirty = TRUE;
  }
1404

1405 1406 1407 1408 1409 1410
  /*
   * Enable the Apply button.
   */
  if (psInfo->hasApply)
  {
    HWND hwndApplyBtn = GetDlgItem(hwndDlg, IDC_APPLY_BUTTON);
1411

1412 1413 1414
    EnableWindow(hwndApplyBtn, TRUE);
  }
}
1415

1416 1417 1418 1419 1420 1421 1422 1423 1424 1425
/******************************************************************************
 *            PROPSHEET_UnChanged
 */
static void PROPSHEET_UnChanged(HWND hwndDlg, HWND hwndCleanPage)
{
  int i;
  BOOL noPageDirty = TRUE;
  HWND hwndApplyBtn = GetDlgItem(hwndDlg, IDC_APPLY_BUTTON);
  PropSheetInfo* psInfo = (PropSheetInfo*) GetPropA(hwndDlg,
                                                    PropSheetInfoStr);
1426

1427
  if ( !psInfo ) return;
1428
  for (i = 0; i < psInfo->nPages; i++)
1429 1430 1431 1432
  {
    /* set the specified page as clean */
    if (psInfo->proppage[i].hwndPage == hwndCleanPage)
      psInfo->proppage[i].isDirty = FALSE;
1433

1434 1435 1436 1437
    /* look to see if there's any dirty pages */
    if (psInfo->proppage[i].isDirty)
      noPageDirty = FALSE;
  }
1438

1439 1440 1441 1442 1443 1444
  /*
   * Disable Apply button.
   */
  if (noPageDirty)
    EnableWindow(hwndApplyBtn, FALSE);
}
1445

1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456
/******************************************************************************
 *            PROPSHEET_PressButton
 */
static void PROPSHEET_PressButton(HWND hwndDlg, int buttonID)
{
  switch (buttonID)
  {
    case PSBTN_APPLYNOW:
      SendMessageA(hwndDlg, WM_COMMAND, IDC_APPLY_BUTTON, 0);
      break;
    case PSBTN_BACK:
1457
      PROPSHEET_Back(hwndDlg);
1458 1459 1460 1461 1462
      break;
    case PSBTN_CANCEL:
      SendMessageA(hwndDlg, WM_COMMAND, IDCANCEL, 0);
      break;
    case PSBTN_FINISH:
1463
      PROPSHEET_Finish(hwndDlg);
1464 1465 1466 1467 1468
      break;
    case PSBTN_HELP:
      SendMessageA(hwndDlg, WM_COMMAND, IDHELP, 0);
      break;
    case PSBTN_NEXT:
1469
      PROPSHEET_Next(hwndDlg);
1470 1471 1472 1473 1474
      break;
    case PSBTN_OK:
      SendMessageA(hwndDlg, WM_COMMAND, IDOK, 0);
      break;
    default:
1475
      FIXME("Invalid button index %d\n", buttonID);
1476 1477
  }
}
1478

1479 1480 1481 1482

/*************************************************************************
 * BOOL PROPSHEET_CanSetCurSel [Internal] 
 *
1483
 * Test weither the current page can be changed by sending a PSN_KILLACTIVE
1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497
 *
 * PARAMS
 *     hwndDlg        [I] handle to a Dialog hWnd
 *
 * RETURNS
 *     TRUE if Current Selection can change
 *
 * NOTES
 */
static BOOL PROPSHEET_CanSetCurSel(HWND hwndDlg)
{
  PropSheetInfo* psInfo = (PropSheetInfo*) GetPropA(hwndDlg,
                                                    PropSheetInfoStr);
  HWND hwndPage;
Alexandre Julliard's avatar
Alexandre Julliard committed
1498
  PSHNOTIFY psn;
1499

Alexandre Julliard's avatar
Alexandre Julliard committed
1500
  if (!psInfo)
1501
     return FALSE;
Alexandre Julliard's avatar
Alexandre Julliard committed
1502 1503 1504 1505

  if (psInfo->active_page < 0)
     return TRUE;

1506 1507 1508 1509
  /*
   * Notify the current page.
   */
  hwndPage = psInfo->proppage[psInfo->active_page].hwndPage;
Alexandre Julliard's avatar
Alexandre Julliard committed
1510 1511 1512 1513
  psn.hdr.code     = PSN_KILLACTIVE;
  psn.hdr.hwndFrom = hwndDlg;
  psn.hdr.idFrom   = 0;
  psn.lParam       = 0;
1514

Alexandre Julliard's avatar
Alexandre Julliard committed
1515
  return !SendMessageA(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn);
1516 1517
}

1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529
/******************************************************************************
 *            PROPSHEET_SetCurSel
 */
static BOOL PROPSHEET_SetCurSel(HWND hwndDlg,
                                int index,
                                HPROPSHEETPAGE hpage)
{
  PropSheetInfo* psInfo = (PropSheetInfo*) GetPropA(hwndDlg,
                                                    PropSheetInfoStr);
  HWND hwndPage;
  HWND hwndHelp  = GetDlgItem(hwndDlg, IDHELP);

Alexandre Julliard's avatar
Alexandre Julliard committed
1530
  /* hpage takes precedence over index */
1531
  if (hpage != NULL)
Thuy Nguyen's avatar
Thuy Nguyen committed
1532 1533
    index = PROPSHEET_GetPageIndex(hpage, psInfo);

1534 1535 1536 1537
  if (index < 0 || index >= psInfo->nPages)
  {
    TRACE("Could not find page to select!\n");
    return FALSE;
Thuy Nguyen's avatar
Thuy Nguyen committed
1538 1539 1540
  }

  hwndPage = psInfo->proppage[index].hwndPage;
1541

1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562
  /*
   * Notify the new page if it's already created.
   * If not it will get created and notified in PROPSHEET_ShowPage.
   */
  if (hwndPage)
  {
    int result;
    PSHNOTIFY psn;

    psn.hdr.code     = PSN_SETACTIVE;
    psn.hdr.hwndFrom = hwndDlg;
    psn.hdr.idFrom   = 0;
    psn.lParam       = 0;

    result = SendMessageA(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn);

    /*
     * TODO: check return value. 
     */
  }

1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580
  /*
   * Display the new page.
   */
  PROPSHEET_ShowPage(hwndDlg, index, psInfo);

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

  return TRUE;
}

/******************************************************************************
 *            PROPSHEET_SetTitleA
 */
static void PROPSHEET_SetTitleA(HWND hwndDlg, DWORD dwStyle, LPCSTR lpszText)
{
1581 1582 1583 1584
  PropSheetInfo*	psInfo = (PropSheetInfo*) GetPropA(hwndDlg, PropSheetInfoStr);
  char 				szTitle[256];

  if (HIWORD(lpszText) == 0) {
1585
    if (!LoadStringA(psInfo->ppshheader.hInstance, 
1586 1587 1588 1589
                     LOWORD(lpszText), szTitle, sizeof(szTitle)-1))
      return;
    lpszText = szTitle;
  }
1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606
  if (dwStyle & PSH_PROPTITLE)
  {
    char* dest;
    int lentitle = strlen(lpszText);
    int lenprop  = strlen(psInfo->strPropertiesFor);

    dest = COMCTL32_Alloc(lentitle + lenprop + 1);
    strcpy(dest, psInfo->strPropertiesFor);
    strcat(dest, lpszText);

    SetWindowTextA(hwndDlg, dest);
    COMCTL32_Free(dest);
  }
  else
    SetWindowTextA(hwndDlg, lpszText);
}

1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630
/******************************************************************************
 *            PROPSHEET_SetFinishTextA
 */
static void PROPSHEET_SetFinishTextA(HWND hwndDlg, LPCSTR lpszText)
{
  HWND hwndButton = GetDlgItem(hwndDlg, IDC_FINISH_BUTTON);

  /* Set text, show and enable the Finish button */
  SetWindowTextA(hwndButton, lpszText);
  ShowWindow(hwndButton, SW_SHOW);
  EnableWindow(hwndButton, TRUE);

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

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

  /* Hide Next button */
  hwndButton = GetDlgItem(hwndDlg, IDC_NEXT_BUTTON);
  ShowWindow(hwndButton, SW_HIDE);
}

1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642
/******************************************************************************
 *            PROPSHEET_QuerySiblings
 */
static LRESULT PROPSHEET_QuerySiblings(HWND hwndDlg,
                                       WPARAM wParam, LPARAM lParam)
{
  int i = 0;
  HWND hwndPage;
  LRESULT msgResult = 0;
  PropSheetInfo* psInfo = (PropSheetInfo*) GetPropA(hwndDlg,
                                                    PropSheetInfoStr);

1643
  while ((i < psInfo->nPages) && (msgResult == 0))
1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659
  {
    hwndPage = psInfo->proppage[i].hwndPage;
    msgResult = SendMessageA(hwndPage, PSM_QUERYSIBLINGS, wParam, lParam);
    i++;
  }

  return msgResult;
}


/******************************************************************************
 *            PROPSHEET_AddPage
 */
static BOOL PROPSHEET_AddPage(HWND hwndDlg,
                              HPROPSHEETPAGE hpage)
{
1660
  PropSheetInfo * psInfo = (PropSheetInfo*) GetPropA(hwndDlg,
1661 1662
                                                     PropSheetInfoStr);
  HWND hwndTabControl = GetDlgItem(hwndDlg, IDC_TABCONTROL);
1663 1664 1665
  TCITEMA item;
  char tabtext[MAX_TABTEXT_LENGTH] = "Tab text";
  LPCPROPSHEETPAGEA ppsp = (LPCPROPSHEETPAGEA)hpage;
1666

1667 1668 1669
  /*
   * Allocate and fill in a new PropPageInfo entry.
   */
1670 1671 1672
  psInfo->proppage = (PropPageInfo*) COMCTL32_ReAlloc(psInfo->proppage,
                                                      sizeof(PropPageInfo) *
                                                      (psInfo->nPages + 1));
1673 1674
  if (!PROPSHEET_CollectPageInfo(ppsp, psInfo, psInfo->nPages))
      return FALSE;
1675

1676 1677
  psInfo->proppage[psInfo->nPages].hpage = hpage;

Alexandre Julliard's avatar
Alexandre Julliard committed
1678 1679 1680 1681 1682
  if (ppsp->dwFlags & PSP_PREMATURE)
  {
     /* Create the page but don't show it */
     PROPSHEET_CreatePage(hwndDlg, psInfo->nPages, psInfo, ppsp);
  }
1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699

  /*
   * Add a new tab to the tab control.
   */
  item.mask = TCIF_TEXT;
  item.pszText = tabtext;
  item.cchTextMax = MAX_TABTEXT_LENGTH;

  WideCharToMultiByte(CP_ACP, 0,
                      (LPCWSTR)psInfo->proppage[psInfo->nPages].pszText,
                      -1, tabtext, MAX_TABTEXT_LENGTH, NULL, NULL);

  SendMessageA(hwndTabControl, TCM_INSERTITEMA, psInfo->nPages + 1,
               (LPARAM)&item);

  psInfo->nPages++;

Alexandre Julliard's avatar
Alexandre Julliard committed
1700 1701 1702 1703
  /* If it is the only page - show it */
  if(psInfo->nPages == 1)
     PROPSHEET_ShowPage(hwndDlg, 0, psInfo);

1704
  return TRUE;
1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716
}

/******************************************************************************
 *            PROPSHEET_RemovePage
 */
static BOOL PROPSHEET_RemovePage(HWND hwndDlg,
                                 int index,
                                 HPROPSHEETPAGE hpage)
{
  PropSheetInfo * psInfo = (PropSheetInfo*) GetPropA(hwndDlg,
                                                     PropSheetInfoStr);
  HWND hwndTabControl = GetDlgItem(hwndDlg, IDC_TABCONTROL);
1717
  PropPageInfo* oldPages;
1718

1719 1720 1721 1722
  if (!psInfo) {
    return FALSE;
  }
  oldPages = psInfo->proppage;
1723 1724 1725 1726 1727 1728
  /*
   * hpage takes precedence over index.
   */
  if (hpage != 0)
  {
    index = PROPSHEET_GetPageIndex(hpage, psInfo);
1729
  }
1730

1731
  /* Make sure that index is within range */
1732
  if (index < 0 || index >= psInfo->nPages)
Alexandre Julliard's avatar
Alexandre Julliard committed
1733
  {
1734
      TRACE("Could not find page to remove!\n");
1735
      return FALSE;
Alexandre Julliard's avatar
Alexandre Julliard committed
1736
  }
1737

1738
  TRACE("total pages %d removing page %d active page %d\n",
1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755
        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  */
        PROPSHEET_ShowPage(hwndDlg, index - 1, psInfo);
      }
      else
      {
        /* activate the next page */
        PROPSHEET_ShowPage(hwndDlg, index + 1, psInfo);
1756
        psInfo->active_page = index;
1757 1758 1759 1760
      }
    }
    else
    {
Alexandre Julliard's avatar
Alexandre Julliard committed
1761 1762 1763 1764 1765 1766
      psInfo->active_page = -1;
      if (!psInfo->isModeless)
      {
         EndDialog(hwndDlg, FALSE);
         return TRUE;
      }
1767 1768
    }
  }
Alexandre Julliard's avatar
Alexandre Julliard committed
1769
  else if (index < psInfo->active_page)
1770 1771
    psInfo->active_page--;

Alexandre Julliard's avatar
Alexandre Julliard committed
1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785
  /* Destroy page dialog window */
  DestroyWindow(psInfo->proppage[index].hwndPage);

  /* Free page resources */
  if(psInfo->proppage[index].hpage)
  {
     PROPSHEETPAGEA* psp = (PROPSHEETPAGEA*)psInfo->proppage[index].hpage;

     if ((psp->dwFlags & PSP_USETITLE) && psInfo->proppage[index].pszText)
        HeapFree(GetProcessHeap(), 0, (LPVOID)psInfo->proppage[index].pszText);

     DestroyPropertySheetPage(psInfo->proppage[index].hpage);
  }
 
1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800
  /* Remove the tab */
  SendMessageA(hwndTabControl, TCM_DELETEITEM, index, 0);

  psInfo->nPages--;
  psInfo->proppage = COMCTL32_Alloc(sizeof(PropPageInfo) * psInfo->nPages);

  if (index > 0)  
    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));

  COMCTL32_Free(oldPages);

1801 1802 1803
  return FALSE;
}

1804 1805 1806 1807 1808 1809 1810 1811 1812 1813
/******************************************************************************
 *            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)
{
Alexandre Julliard's avatar
Alexandre Julliard committed
1814 1815 1816
  HWND hwndBack   = GetDlgItem(hwndDlg, IDC_BACK_BUTTON);
  HWND hwndNext   = GetDlgItem(hwndDlg, IDC_NEXT_BUTTON);
  HWND hwndFinish = GetDlgItem(hwndDlg, IDC_FINISH_BUTTON);
1817 1818 1819

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

Alexandre Julliard's avatar
Alexandre Julliard committed
1820 1821 1822 1823
  EnableWindow(hwndBack, FALSE);
  EnableWindow(hwndNext, FALSE);
  EnableWindow(hwndFinish, FALSE);

1824
  if (dwFlags & PSWIZB_BACK)
Alexandre Julliard's avatar
Alexandre Julliard committed
1825
    EnableWindow(hwndBack, TRUE);
1826 1827 1828 1829

  if (dwFlags & PSWIZB_NEXT)
  {
    /* Hide the Finish button */
Alexandre Julliard's avatar
Alexandre Julliard committed
1830
    ShowWindow(hwndFinish, SW_HIDE);
1831 1832

    /* Show and enable the Next button */
Alexandre Julliard's avatar
Alexandre Julliard committed
1833 1834
    ShowWindow(hwndNext, SW_SHOW);
    EnableWindow(hwndNext, TRUE);
1835 1836 1837 1838 1839 1840 1841 1842

    /* Set the Next button as the default pushbutton  */
    SendMessageA(hwndDlg, DM_SETDEFID, IDC_NEXT_BUTTON, 0);
  }

  if ((dwFlags & PSWIZB_FINISH) || (dwFlags & PSWIZB_DISABLEDFINISH))
  {
    /* Hide the Next button */
Alexandre Julliard's avatar
Alexandre Julliard committed
1843
    ShowWindow(hwndNext, SW_HIDE);
1844 1845

    /* Show the Finish button */
Alexandre Julliard's avatar
Alexandre Julliard committed
1846
    ShowWindow(hwndFinish, SW_SHOW);
1847 1848

    if (dwFlags & PSWIZB_FINISH)
Alexandre Julliard's avatar
Alexandre Julliard committed
1849
      EnableWindow(hwndFinish, TRUE);
1850 1851 1852 1853 1854 1855

    /* Set the Finish button as the default pushbutton  */
    SendMessageA(hwndDlg, DM_SETDEFID, IDC_FINISH_BUTTON, 0);
  }
}

1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880
/******************************************************************************
 *            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;

  while ((index < psInfo->nPages) && (found == FALSE))
  {
    if (psInfo->proppage[index].hpage == hpage)
      found = TRUE;
    else
      index++;
  }

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

  return index;
}

1881 1882 1883 1884 1885
/******************************************************************************
 *            PROPSHEET_CleanUp
 */
static void PROPSHEET_CleanUp(HWND hwndDlg)
{
Alexandre Julliard's avatar
Alexandre Julliard committed
1886
  int i;
1887 1888
  PropSheetInfo* psInfo = (PropSheetInfo*) RemovePropA(hwndDlg,
                                                       PropSheetInfoStr);
1889 1890

  TRACE("\n");
1891 1892
  if (HIWORD(psInfo->ppshheader.pszCaption))
      HeapFree(GetProcessHeap(), 0, (LPVOID)psInfo->ppshheader.pszCaption);
Alexandre Julliard's avatar
Alexandre Julliard committed
1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909

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

     if(psInfo->proppage[i].hwndPage)
        DestroyWindow(psInfo->proppage[i].hwndPage);

     if(psp)
     {
        if ((psp->dwFlags & PSP_USETITLE) && psInfo->proppage[i].pszText)
           HeapFree(GetProcessHeap(), 0, (LPVOID)psInfo->proppage[i].pszText);

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

1910 1911
  COMCTL32_Free(psInfo->proppage);
  COMCTL32_Free(psInfo->strPropertiesFor);
1912
  ImageList_Destroy(psInfo->hImageList);
1913 1914 1915 1916 1917 1918

  GlobalFree((HGLOBAL)psInfo);
}

/******************************************************************************
 *            PropertySheetA   (COMCTL32.84)(COMCTL32.83)
1919
 */
1920
INT WINAPI PropertySheetA(LPCPROPSHEETHEADERA lppsh)
1921
{
1922 1923 1924
  int bRet = 0;
  PropSheetInfo* psInfo = (PropSheetInfo*) GlobalAlloc(GPTR,
                                                       sizeof(PropSheetInfo));
1925
  int i, n;
Alexandre Julliard's avatar
Alexandre Julliard committed
1926
  BYTE* pByte;
1927 1928

  PROPSHEET_CollectSheetInfo(lppsh, psInfo);
1929 1930 1931

  psInfo->proppage = (PropPageInfo*) COMCTL32_Alloc(sizeof(PropPageInfo) *
                                                    lppsh->nPages);
1932
  pByte = (BYTE*) psInfo->ppshheader.u3.ppsp;
1933

1934
  for (n = i = 0; i < lppsh->nPages; i++, n++)
1935 1936
  {
    if (!(lppsh->dwFlags & PSH_PROPSHEETPAGE))
1937
      psInfo->proppage[n].hpage = psInfo->ppshheader.u3.phpage[i];
Alexandre Julliard's avatar
Alexandre Julliard committed
1938 1939
    else
    {
1940
       psInfo->proppage[n].hpage = CreatePropertySheetPageA((LPCPROPSHEETPAGEA)pByte);
Alexandre Julliard's avatar
Alexandre Julliard committed
1941 1942 1943
       pByte += ((LPPROPSHEETPAGEA)pByte)->dwSize;
    }

1944 1945 1946 1947 1948 1949 1950 1951
    if (!PROPSHEET_CollectPageInfo((LPCPROPSHEETPAGEA)psInfo->proppage[n].hpage,
                               psInfo, n))
    {
	if (lppsh->dwFlags & PSH_PROPSHEETPAGE)
	    DestroyPropertySheetPage(psInfo->proppage[n].hpage);
	n--;
	psInfo->nPages--;
    }
1952
  }
1953

1954
  bRet = PROPSHEET_CreateDialog(psInfo);
1955

1956
  return bRet;
1957 1958
}

1959
/******************************************************************************
1960
 *            PropertySheetW   (COMCTL32.85)
1961
 */
1962
INT WINAPI PropertySheetW(LPCPROPSHEETHEADERW propertySheetHeader)
1963
{
1964
    FIXME("(%p): stub\n", propertySheetHeader);
1965 1966 1967 1968

    return -1;
}

1969
/******************************************************************************
1970
 *            CreatePropertySheetPageA   (COMCTL32.19)(COMCTL32.18)
1971
 */
1972 1973
HPROPSHEETPAGE WINAPI CreatePropertySheetPageA(
                          LPCPROPSHEETPAGEA lpPropSheetPage)
1974
{
1975
  PROPSHEETPAGEA* ppsp = COMCTL32_Alloc(sizeof(PROPSHEETPAGEA));
1976

1977 1978
  *ppsp = *lpPropSheetPage;

Alexandre Julliard's avatar
Alexandre Julliard committed
1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990
  if ( !(ppsp->dwFlags & PSP_DLGINDIRECT) && HIWORD( ppsp->u1.pszTemplate ) )
    ppsp->u1.pszTemplate = HEAP_strdupA( GetProcessHeap(), 0, lpPropSheetPage->u1.pszTemplate );

  if ( (ppsp->dwFlags & PSP_USEICONID) && HIWORD( ppsp->u2.pszIcon ) )
      ppsp->u2.pszIcon = HEAP_strdupA( GetProcessHeap(), 0, lpPropSheetPage->u2.pszIcon );
       

  if ((ppsp->dwFlags & PSP_USETITLE) && HIWORD( ppsp->pszTitle ))
      ppsp->pszTitle = HEAP_strdupA( GetProcessHeap(), 0, lpPropSheetPage->pszTitle );
  else if ( !(ppsp->dwFlags & PSP_USETITLE) )
      ppsp->pszTitle = NULL;

1991
  return (HPROPSHEETPAGE)ppsp;
1992 1993
}

1994
/******************************************************************************
1995
 *            CreatePropertySheetPageW   (COMCTL32.20)
1996
 */
1997
HPROPSHEETPAGE WINAPI CreatePropertySheetPageW(LPCPROPSHEETPAGEW lpPropSheetPage)
1998
{
1999
    FIXME("(%p): stub\n", lpPropSheetPage);
2000 2001 2002 2003

    return 0;
}

2004
/******************************************************************************
2005
 *            DestroyPropertySheetPage   (COMCTL32.24)
2006
 */
2007
BOOL WINAPI DestroyPropertySheetPage(HPROPSHEETPAGE hPropPage)
2008
{
Alexandre Julliard's avatar
Alexandre Julliard committed
2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022
  PROPSHEETPAGEA *psp = (PROPSHEETPAGEA *)hPropPage;

  if (!psp)
     return FALSE;

  if ( !(psp->dwFlags & PSP_DLGINDIRECT) && HIWORD( psp->u1.pszTemplate ) )
     HeapFree(GetProcessHeap(), 0, (LPVOID)psp->u1.pszTemplate);

  if ( (psp->dwFlags & PSP_USEICONID) && HIWORD( psp->u2.pszIcon ) )
     HeapFree(GetProcessHeap(), 0, (LPVOID)psp->u2.pszIcon);

  if ((psp->dwFlags & PSP_USETITLE) && HIWORD( psp->pszTitle ))
      HeapFree(GetProcessHeap(), 0, (LPVOID)psp->pszTitle);

2023 2024 2025
  COMCTL32_Free(hPropPage);

  return TRUE;
2026 2027
}

Alexandre Julliard's avatar
Alexandre Julliard committed
2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079
/******************************************************************************
 *            PROPSHEET_IsDialogMessage
 */
static BOOL PROPSHEET_IsDialogMessage(HWND hwnd, LPMSG lpMsg)
{
   PropSheetInfo* psInfo = (PropSheetInfo*) GetPropA(hwnd, PropSheetInfoStr);

   if (!psInfo || (hwnd != lpMsg->hwnd && !IsChild(hwnd, lpMsg->hwnd)))
      return FALSE;

   if (lpMsg->message == WM_KEYDOWN && (GetKeyState(VK_CONTROL) & 0x8000))
   {
      int new_page = 0;
      INT dlgCode = SendMessageA(lpMsg->hwnd, WM_GETDLGCODE, 0, (LPARAM)lpMsg);

      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;

            PROPSHEET_SetCurSel(hwnd, new_page, 0);
         }

         return TRUE;
      }
   }

   return IsDialogMessageA(hwnd, lpMsg);
}

2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092
/******************************************************************************
 *            PROPSHEET_DialogProc
 */
BOOL WINAPI
PROPSHEET_DialogProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
  switch (uMsg)
  {
    case WM_INITDIALOG:
    {
      PropSheetInfo* psInfo = (PropSheetInfo*) lParam;
      char* strCaption = (char*)COMCTL32_Alloc(MAX_CAPTION_LENGTH);
      HWND hwndTabCtrl = GetDlgItem(hwnd, IDC_TABCONTROL);
2093
      LPCPROPSHEETPAGEA ppshpage;
Alexandre Julliard's avatar
Alexandre Julliard committed
2094
      int idx;
2095

2096 2097
      SetPropA(hwnd, PropSheetInfoStr, (HANDLE)psInfo);

2098 2099 2100 2101 2102 2103 2104 2105 2106
      /*
       * psInfo->hwnd is not being used by WINE code - it exists 
       * for compatibility with "real" Windoze. The same about 
       * SetWindowLong - WINE is only using the PropSheetInfoStr
       * property.
       */
      psInfo->hwnd = hwnd;
      SetWindowLongA(hwnd,DWL_USER,(LONG)psInfo);

2107 2108 2109
      /*
       * Small icon in the title bar.
       */
2110 2111
      if ((psInfo->ppshheader.dwFlags & PSH_USEICONID) ||
          (psInfo->ppshheader.dwFlags & PSH_USEHICON))
2112 2113 2114 2115 2116
      {
        HICON hIcon;
        int icon_cx = GetSystemMetrics(SM_CXSMICON);
        int icon_cy = GetSystemMetrics(SM_CYSMICON);

2117 2118 2119
        if (psInfo->ppshheader.dwFlags & PSH_USEICONID)
          hIcon = LoadImageA(psInfo->ppshheader.hInstance,
                             psInfo->ppshheader.u1.pszIcon,
2120 2121 2122 2123
                             IMAGE_ICON,
                             icon_cx, icon_cy,
                             LR_DEFAULTCOLOR);
        else
2124
          hIcon = psInfo->ppshheader.u1.hIcon;
2125 2126 2127 2128

        SendMessageA(hwnd, WM_SETICON, 0, hIcon);
      }
      
2129 2130
      if (psInfo->ppshheader.dwFlags & PSH_USEHICON)
        SendMessageA(hwnd, WM_SETICON, 0, psInfo->ppshheader.u1.hIcon);
2131

2132 2133 2134 2135
      psInfo->strPropertiesFor = strCaption;

      GetWindowTextA(hwnd, psInfo->strPropertiesFor, MAX_CAPTION_LENGTH);

2136 2137
      PROPSHEET_CreateTabControl(hwnd, psInfo);

2138
      if (psInfo->ppshheader.dwFlags & PSH_WIZARD)
2139 2140 2141 2142 2143 2144 2145 2146
      {
        if (PROPSHEET_IsTooSmallWizard(hwnd, psInfo))
        {
          PROPSHEET_AdjustSizeWizard(hwnd, psInfo);
          PROPSHEET_AdjustButtonsWizard(hwnd, psInfo);
        }
      }
      else
2147
      {
2148
        if (PROPSHEET_SizeMismatch(hwnd, psInfo))
2149 2150 2151 2152
        {
          PROPSHEET_AdjustSize(hwnd, psInfo);
          PROPSHEET_AdjustButtons(hwnd, psInfo);
        }
2153 2154
      }

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

Alexandre Julliard's avatar
Alexandre Julliard committed
2159 2160 2161 2162 2163
      idx = psInfo->active_page;
      ppshpage = (LPCPROPSHEETPAGEA)psInfo->proppage[idx].hpage;
      psInfo->active_page = -1;
 
      PROPSHEET_SetCurSel(hwnd, idx, psInfo->proppage[idx].hpage);
2164

2165
      if (!(psInfo->ppshheader.dwFlags & PSH_WIZARD))
2166
        SendMessageA(hwndTabCtrl, TCM_SETCURSEL, psInfo->active_page, 0);
2167

2168 2169
      if (!HIWORD(psInfo->ppshheader.pszCaption) &&
              psInfo->ppshheader.hInstance)
2170 2171 2172
      {
         char szText[256];

2173 2174 2175
         if (LoadStringA(psInfo->ppshheader.hInstance, 
                 (UINT)psInfo->ppshheader.pszCaption, szText, 255))
            PROPSHEET_SetTitleA(hwnd, psInfo->ppshheader.dwFlags, szText);
2176 2177 2178
      }
      else
      {
2179 2180
         PROPSHEET_SetTitleA(hwnd, psInfo->ppshheader.dwFlags,
                         psInfo->ppshheader.pszCaption);
2181
      }
2182 2183 2184 2185 2186 2187 2188 2189 2190

      return TRUE;
    }

    case WM_DESTROY:
      PROPSHEET_CleanUp(hwnd);
      return TRUE;

    case WM_CLOSE:
Alexandre Julliard's avatar
Alexandre Julliard committed
2191
      PROPSHEET_Cancel(hwnd, 1);
2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204
      return TRUE;

    case WM_COMMAND:
    {
      WORD wID = LOWORD(wParam);

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

Alexandre Julliard's avatar
Alexandre Julliard committed
2205
          if (PROPSHEET_Apply(hwnd, wID == IDOK ? 1: 0) == FALSE)
2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221
            break;

          if (wID == IDOK)
          {
            PropSheetInfo* psInfo = (PropSheetInfo*) GetPropA(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)
Alexandre Julliard's avatar
Alexandre Julliard committed
2222
              psInfo->activeValid = FALSE;
2223 2224 2225
            else
              EndDialog(hwnd, result);
          }
Alexandre Julliard's avatar
Alexandre Julliard committed
2226 2227
          else
             EnableWindow(hwndApplyBtn, FALSE);
2228 2229 2230 2231

          break;
        }

2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243
        case IDC_BACK_BUTTON:
          PROPSHEET_Back(hwnd);
          break;

        case IDC_NEXT_BUTTON:
          PROPSHEET_Next(hwnd);
          break;

        case IDC_FINISH_BUTTON:
          PROPSHEET_Finish(hwnd);
          break;

2244
        case IDCANCEL:
Alexandre Julliard's avatar
Alexandre Julliard committed
2245
          PROPSHEET_Cancel(hwnd, 0);
2246 2247 2248
          break;

        case IDHELP:
2249
          PROPSHEET_Help(hwnd);
2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262
          break;
      }

      return TRUE;
    }

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

      if (pnmh->code == TCN_SELCHANGE)
      {
        int index = SendMessageA(pnmh->hwndFrom, TCM_GETCURSEL, 0, 0);
Thuy Nguyen's avatar
Thuy Nguyen committed
2263
        PROPSHEET_SetCurSel(hwnd, index, 0);
2264 2265
      }

2266 2267 2268 2269 2270 2271 2272 2273
      if(pnmh->code == TCN_SELCHANGING)
      {
        BOOL bRet = PROPSHEET_CanSetCurSel(hwnd);
        SetWindowLongA(hwnd, DWL_MSGRESULT, !bRet);
        return TRUE;
      }


2274 2275 2276 2277 2278 2279 2280 2281 2282
      return 0;
    }

    case PSM_GETCURRENTPAGEHWND:
    {
      PropSheetInfo* psInfo = (PropSheetInfo*) GetPropA(hwnd,
                                                        PropSheetInfoStr);
      HWND hwndPage = 0;

Alexandre Julliard's avatar
Alexandre Julliard committed
2283
      if (psInfo->activeValid && psInfo->active_page != -1)
2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311
        hwndPage = psInfo->proppage[psInfo->active_page].hwndPage;

      SetWindowLongA(hwnd, DWL_MSGRESULT, hwndPage);

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

      SetWindowLongA(hwnd, DWL_MSGRESULT, hwndTabCtrl);

      return TRUE;
    }

    case PSM_SETCURSEL:
    {
      BOOL msgResult;

2312 2313 2314 2315 2316 2317 2318
      msgResult = PROPSHEET_CanSetCurSel(hwnd);
      if(msgResult != FALSE)
      {
        msgResult = PROPSHEET_SetCurSel(hwnd,
                                       (int)wParam,
                                       (HPROPSHEETPAGE)lParam);
      }
2319 2320 2321 2322 2323 2324 2325 2326

      SetWindowLongA(hwnd, DWL_MSGRESULT, msgResult);

      return TRUE;
    }

    case PSM_CANCELTOCLOSE:
    {
Alexandre Julliard's avatar
Alexandre Julliard committed
2327
      char buf[MAX_BUTTONTEXT_LENGTH];
2328 2329 2330 2331
      HWND hwndOK = GetDlgItem(hwnd, IDOK);
      HWND hwndCancel = GetDlgItem(hwnd, IDCANCEL);

      EnableWindow(hwndCancel, FALSE);
Alexandre Julliard's avatar
Alexandre Julliard committed
2332 2333 2334 2335
      if (LoadStringA(COMCTL32_hModule, IDS_CLOSE, buf, sizeof(buf)))
         SetWindowTextA(hwndOK, buf);
 
      return FALSE;
2336
    }
2337

2338 2339 2340 2341
    case PSM_RESTARTWINDOWS:
    {
      PropSheetInfo* psInfo = (PropSheetInfo*) GetPropA(hwnd,
                                                        PropSheetInfoStr);
2342

2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361
      psInfo->restartWindows = TRUE;
      return TRUE;
    }

    case PSM_REBOOTSYSTEM:
    {
      PropSheetInfo* psInfo = (PropSheetInfo*) GetPropA(hwnd, 
                                                        PropSheetInfoStr);

      psInfo->rebootSystem = TRUE;
      return TRUE;
    }

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

    case PSM_APPLY:
    {
Alexandre Julliard's avatar
Alexandre Julliard committed
2362
      BOOL msgResult = PROPSHEET_Apply(hwnd, 0);
2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377

      SetWindowLongA(hwnd, DWL_MSGRESULT, msgResult);

      return TRUE;
    }

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

      SetWindowLongA(hwnd, DWL_MSGRESULT, msgResult);

      return TRUE;
    }

2378
    case PSM_ADDPAGE:
2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391
    {
      /*
       * 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);

      SetWindowLongA(hwnd, DWL_MSGRESULT, msgResult);

2392
      return TRUE;
2393
    }
2394 2395 2396 2397 2398

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

2399 2400
    case PSM_ISDIALOGMESSAGE:
    {
Alexandre Julliard's avatar
Alexandre Julliard committed
2401 2402 2403
       BOOL msgResult = PROPSHEET_IsDialogMessage(hwnd, (LPMSG)lParam);
       SetWindowLongA(hwnd, DWL_MSGRESULT, msgResult);
       return TRUE;
2404 2405 2406 2407 2408 2409
    }

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

2410 2411 2412 2413 2414 2415 2416 2417
    case PSM_SETFINISHTEXTA:
      PROPSHEET_SetFinishTextA(hwnd, (LPCSTR) lParam);        
      return TRUE;

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

2418
    case PSM_SETTITLEW:
2419
        FIXME("Unimplemented msg PSM_SETTITLE32W\n");
2420 2421
        return 0;
    case PSM_SETCURSELID:
2422
        FIXME("Unimplemented msg PSM_SETCURSELID\n");
2423 2424
        return 0;
    case PSM_SETFINISHTEXTW:
2425
        FIXME("Unimplemented msg PSM_SETFINISHTEXT32W\n");
2426 2427 2428 2429 2430
        return 0;

    default:
      return FALSE;
  }
2431
}
2432