Commit 93c68a7e authored by Thuy Nguyen's avatar Thuy Nguyen Committed by Alexandre Julliard

Added support for adding and removing pages dynamically from a

property sheet.
parent 9aded513
...@@ -7,9 +7,7 @@ ...@@ -7,9 +7,7 @@
* TODO: * TODO:
* - Modeless mode * - Modeless mode
* - Wizard mode * - Wizard mode
* - Adding and removing pages dynamically (PSM_ADDPAGE,etc) * - Unicode property sheets
* - CreatePropertySheetPage
* - DestroyPropertySheetPage
*/ */
#include <string.h> #include <string.h>
...@@ -17,11 +15,9 @@ ...@@ -17,11 +15,9 @@
#include "commctrl.h" #include "commctrl.h"
#include "prsht.h" #include "prsht.h"
#include "winnls.h" #include "winnls.h"
#include "resource.h" #include "propsheet.h"
#include "debug.h" #include "debug.h"
/* FIXME: this should be in a local header file */
extern HMODULE COMCTL32_hModule;
/****************************************************************************** /******************************************************************************
* Data structures * Data structures
...@@ -37,6 +33,8 @@ typedef struct ...@@ -37,6 +33,8 @@ typedef struct
typedef struct tagPropPageInfo typedef struct tagPropPageInfo
{ {
int index; /* corresponds to the index in ppshheader->ppsp */
HPROPSHEETPAGE hpage; /* to keep track of pages not passed to PropertySheet */
HWND hwndPage; HWND hwndPage;
BOOL isDirty; BOOL isDirty;
LPCWSTR pszText; LPCWSTR pszText;
...@@ -47,6 +45,7 @@ typedef struct tagPropPageInfo ...@@ -47,6 +45,7 @@ typedef struct tagPropPageInfo
typedef struct tagPropSheetInfo typedef struct tagPropSheetInfo
{ {
LPSTR strPropertiesFor; LPSTR strPropertiesFor;
int nPages;
int active_page; int active_page;
LPCPROPSHEETHEADERA ppshheader; LPCPROPSHEETHEADERA ppshheader;
BOOL isModeless; BOOL isModeless;
...@@ -71,12 +70,12 @@ typedef struct ...@@ -71,12 +70,12 @@ typedef struct
/****************************************************************************** /******************************************************************************
* Defines and global variables * Defines and global variables
*/ */
const char * PropSheetInfoStr = "PropertySheetInfo"; const char * PropSheetInfoStr = "PropertySheetInfo";
#define MAX_CAPTION_LENGTH 255 #define MAX_CAPTION_LENGTH 255
#define MAX_TABTEXT_LENGTH 255
#define IDC_TABCONTROL 12320
#define IDC_APPLY_BUTTON 12321
/****************************************************************************** /******************************************************************************
* Prototypes * Prototypes
...@@ -87,16 +86,20 @@ static BOOL PROPSHEET_AdjustSize(HWND hwndDlg, PropSheetInfo* psInfo); ...@@ -87,16 +86,20 @@ static BOOL PROPSHEET_AdjustSize(HWND hwndDlg, PropSheetInfo* psInfo);
static BOOL PROPSHEET_AdjustButtons(HWND hwndParent, PropSheetInfo* psInfo); static BOOL PROPSHEET_AdjustButtons(HWND hwndParent, PropSheetInfo* psInfo);
static BOOL PROPSHEET_CollectSheetInfo(LPCPROPSHEETHEADERA lppsh, static BOOL PROPSHEET_CollectSheetInfo(LPCPROPSHEETHEADERA lppsh,
PropSheetInfo * psInfo); PropSheetInfo * psInfo);
static BOOL PROPSHEET_CollectPageInfo(LPCPROPSHEETHEADERA lppsh, static BOOL PROPSHEET_CollectPageInfo(LPCPROPSHEETPAGEA lppsp,
PropSheetInfo * psInfo); PropSheetInfo * psInfo,
int index);
static BOOL PROPSHEET_CreateTabControl(HWND hwndParent, static BOOL PROPSHEET_CreateTabControl(HWND hwndParent,
PropSheetInfo * psInfo); PropSheetInfo * psInfo);
static int PROPSHEET_CreatePage(HWND hwndParent, int index, static int PROPSHEET_CreatePage(HWND hwndParent, int index,
const PropSheetInfo * psInfo); const PropSheetInfo * psInfo,
LPCPROPSHEETPAGEA ppshpage,
BOOL showPage);
static BOOL PROPSHEET_ShowPage(HWND hwndDlg, int index, PropSheetInfo * psInfo); static BOOL PROPSHEET_ShowPage(HWND hwndDlg, int index, PropSheetInfo * psInfo);
static PADDING_INFO PROPSHEET_GetPaddingInfo(HWND hwndDlg); static PADDING_INFO PROPSHEET_GetPaddingInfo(HWND hwndDlg);
static BOOL PROPSHEET_Apply(HWND hwndDlg); static BOOL PROPSHEET_Apply(HWND hwndDlg);
static void PROPSHEET_Cancel(HWND hwndDlg); static void PROPSHEET_Cancel(HWND hwndDlg);
static void PROPSHEET_Help(HWND hwndDlg);
static void PROPSHEET_Changed(HWND hwndDlg, HWND hwndDirtyPage); static void PROPSHEET_Changed(HWND hwndDlg, HWND hwndDirtyPage);
static void PROPSHEET_UnChanged(HWND hwndDlg, HWND hwndCleanPage); static void PROPSHEET_UnChanged(HWND hwndDlg, HWND hwndCleanPage);
static void PROPSHEET_PressButton(HWND hwndDlg, int buttonID); static void PROPSHEET_PressButton(HWND hwndDlg, int buttonID);
...@@ -106,7 +109,7 @@ static BOOL PROPSHEET_SetCurSel(HWND hwndDlg, ...@@ -106,7 +109,7 @@ static BOOL PROPSHEET_SetCurSel(HWND hwndDlg,
HPROPSHEETPAGE hpage); HPROPSHEETPAGE hpage);
static LRESULT PROPSHEET_QuerySiblings(HWND hwndDlg, static LRESULT PROPSHEET_QuerySiblings(HWND hwndDlg,
WPARAM wParam, LPARAM lParam); WPARAM wParam, LPARAM lParam);
static LPCPROPSHEETPAGEA PROPSHEET_GetPage(const PropSheetInfo * psInfo, static LPCPROPSHEETPAGEA PROPSHEET_GetPSPPage(const PropSheetInfo * psInfo,
int index); int index);
static BOOL PROPSHEET_AddPage(HWND hwndDlg, static BOOL PROPSHEET_AddPage(HWND hwndDlg,
HPROPSHEETPAGE hpage); HPROPSHEETPAGE hpage);
...@@ -115,6 +118,7 @@ static BOOL PROPSHEET_RemovePage(HWND hwndDlg, ...@@ -115,6 +118,7 @@ static BOOL PROPSHEET_RemovePage(HWND hwndDlg,
int index, int index,
HPROPSHEETPAGE hpage); HPROPSHEETPAGE hpage);
static void PROPSHEET_CleanUp(); static void PROPSHEET_CleanUp();
static int PROPSHEET_GetPageIndex(HPROPSHEETPAGE hpage, PropSheetInfo* psInfo);
BOOL WINAPI BOOL WINAPI
PROPSHEET_DialogProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam); PROPSHEET_DialogProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
...@@ -136,6 +140,7 @@ static BOOL PROPSHEET_CollectSheetInfo(LPCPROPSHEETHEADERA lppsh, ...@@ -136,6 +140,7 @@ static BOOL PROPSHEET_CollectSheetInfo(LPCPROPSHEETHEADERA lppsh,
psInfo->useCallback = dwFlags & PSH_USECALLBACK; psInfo->useCallback = dwFlags & PSH_USECALLBACK;
psInfo->isModeless = dwFlags & PSH_MODELESS; psInfo->isModeless = dwFlags & PSH_MODELESS;
psInfo->ppshheader = lppsh; psInfo->ppshheader = lppsh;
psInfo->nPages = lppsh->nPages;
if (dwFlags & PSH_USEPSTARTPAGE) if (dwFlags & PSH_USEPSTARTPAGE)
{ {
...@@ -157,35 +162,29 @@ static BOOL PROPSHEET_CollectSheetInfo(LPCPROPSHEETHEADERA lppsh, ...@@ -157,35 +162,29 @@ static BOOL PROPSHEET_CollectSheetInfo(LPCPROPSHEETHEADERA lppsh,
* Collect property sheet data. * Collect property sheet data.
* With code taken from DIALOG_ParseTemplate32. * With code taken from DIALOG_ParseTemplate32.
*/ */
BOOL PROPSHEET_CollectPageInfo(LPCPROPSHEETHEADERA lppsh, BOOL PROPSHEET_CollectPageInfo(LPCPROPSHEETPAGEA lppsp,
PropSheetInfo * psInfo) PropSheetInfo * psInfo,
int index)
{ {
DLGTEMPLATE* pTemplate; DLGTEMPLATE* pTemplate;
UINT i;
const WORD* p; const WORD* p;
DWORD dwFlags; DWORD dwFlags;
LPCPROPSHEETPAGEA lppsp;
int width, height; int width, height;
psInfo->proppage = (PropPageInfo*) COMCTL32_Alloc(sizeof(PropPageInfo) * if (psInfo->ppshheader->dwFlags & PSH_PROPSHEETPAGE)
lppsh->nPages); psInfo->proppage[index].hpage = 0;
psInfo->proppage[index].hwndPage = 0;
for (i = 0; i < lppsh->nPages; i++) psInfo->proppage[index].isDirty = FALSE;
{
lppsp = PROPSHEET_GetPage(psInfo, i);
psInfo->proppage[i].hwndPage = 0;
psInfo->proppage[i].isDirty = FALSE;
/* /*
* Process property page flags. * Process property page flags.
*/ */
dwFlags = lppsp->dwFlags; dwFlags = lppsp->dwFlags;
psInfo->proppage[i].useCallback = dwFlags & PSP_USECALLBACK; psInfo->proppage[index].useCallback = dwFlags & PSP_USECALLBACK;
psInfo->proppage[i].hasHelp = dwFlags & PSP_HASHELP; psInfo->proppage[index].hasHelp = dwFlags & PSP_HASHELP;
/* as soon as we have a page with the help flag, set the sheet flag on */ /* as soon as we have a page with the help flag, set the sheet flag on */
if (psInfo->proppage[i].hasHelp) if (psInfo->proppage[index].hasHelp)
psInfo->hasHelp = TRUE; psInfo->hasHelp = TRUE;
/* /*
...@@ -268,10 +267,9 @@ BOOL PROPSHEET_CollectPageInfo(LPCPROPSHEETHEADERA lppsh, ...@@ -268,10 +267,9 @@ BOOL PROPSHEET_CollectPageInfo(LPCPROPSHEETHEADERA lppsh,
} }
/* Extract the caption */ /* Extract the caption */
psInfo->proppage[i].pszText = (LPCWSTR)p; psInfo->proppage[index].pszText = (LPCWSTR)p;
TRACE(propsheet, "Tab %d %s\n",i,debugstr_w((LPCWSTR)p)); TRACE(propsheet, "Tab %d %s\n",index,debugstr_w((LPCWSTR)p));
p += lstrlenW((LPCWSTR)p) + 1; p += lstrlenW((LPCWSTR)p) + 1;
}
return TRUE; return TRUE;
} }
...@@ -287,7 +285,9 @@ BOOL PROPSHEET_CreateDialog(PropSheetInfo* psInfo) ...@@ -287,7 +285,9 @@ BOOL PROPSHEET_CreateDialog(PropSheetInfo* psInfo)
LPCVOID template; LPCVOID template;
HRSRC hRes; HRSRC hRes;
if(!(hRes = FindResourceA(COMCTL32_hModule, "PROPSHEET", RT_DIALOGA))) if(!(hRes = FindResourceA(COMCTL32_hModule,
MAKEINTRESOURCEA(IDD_PROPSHEET),
RT_DIALOGA)))
return FALSE; return FALSE;
if(!(template = (LPVOID)LoadResource(COMCTL32_hModule, hRes))) if(!(template = (LPVOID)LoadResource(COMCTL32_hModule, hRes)))
...@@ -538,11 +538,11 @@ static BOOL PROPSHEET_CreateTabControl(HWND hwndParent, ...@@ -538,11 +538,11 @@ static BOOL PROPSHEET_CreateTabControl(HWND hwndParent,
HWND hwndTabCtrl = GetDlgItem(hwndParent, IDC_TABCONTROL); HWND hwndTabCtrl = GetDlgItem(hwndParent, IDC_TABCONTROL);
TCITEMA item; TCITEMA item;
int i, nTabs; int i, nTabs;
char tabtext[255] = "Tab text"; char tabtext[MAX_TABTEXT_LENGTH] = "Tab text";
item.mask = TCIF_TEXT; item.mask = TCIF_TEXT;
item.pszText = tabtext; item.pszText = tabtext;
item.cchTextMax = 255; item.cchTextMax = MAX_TABTEXT_LENGTH;
nTabs = psInfo->ppshheader->nPages; nTabs = psInfo->ppshheader->nPages;
...@@ -550,7 +550,7 @@ static BOOL PROPSHEET_CreateTabControl(HWND hwndParent, ...@@ -550,7 +550,7 @@ static BOOL PROPSHEET_CreateTabControl(HWND hwndParent,
{ {
WideCharToMultiByte(CP_ACP, 0, WideCharToMultiByte(CP_ACP, 0,
(LPCWSTR)psInfo->proppage[i].pszText, (LPCWSTR)psInfo->proppage[i].pszText,
-1, tabtext, 255, NULL, NULL); -1, tabtext, MAX_TABTEXT_LENGTH, NULL, NULL);
SendMessageA(hwndTabCtrl, TCM_INSERTITEMA, (WPARAM)i, (LPARAM)&item); SendMessageA(hwndTabCtrl, TCM_INSERTITEMA, (WPARAM)i, (LPARAM)&item);
} }
...@@ -561,17 +561,18 @@ static BOOL PROPSHEET_CreateTabControl(HWND hwndParent, ...@@ -561,17 +561,18 @@ static BOOL PROPSHEET_CreateTabControl(HWND hwndParent,
/****************************************************************************** /******************************************************************************
* PROPSHEET_CreatePage * PROPSHEET_CreatePage
* *
* Creates the pages. * Creates a page.
*/ */
static int PROPSHEET_CreatePage(HWND hwndParent, static int PROPSHEET_CreatePage(HWND hwndParent,
int index, int index,
const PropSheetInfo * psInfo) const PropSheetInfo * psInfo,
LPCPROPSHEETPAGEA ppshpage,
BOOL showPage)
{ {
DLGTEMPLATE* pTemplate; DLGTEMPLATE* pTemplate;
HWND hwndPage; HWND hwndPage;
RECT rc; RECT rc;
PropPageInfo* ppInfo = psInfo->proppage; PropPageInfo* ppInfo = psInfo->proppage;
LPCPROPSHEETPAGEA ppshpage = PROPSHEET_GetPage(psInfo, index);
PADDING_INFO padding = PROPSHEET_GetPaddingInfo(hwndParent); PADDING_INFO padding = PROPSHEET_GetPaddingInfo(hwndParent);
HWND hwndTabCtrl = GetDlgItem(hwndParent, IDC_TABCONTROL); HWND hwndTabCtrl = GetDlgItem(hwndParent, IDC_TABCONTROL);
...@@ -634,7 +635,10 @@ static int PROPSHEET_CreatePage(HWND hwndParent, ...@@ -634,7 +635,10 @@ static int PROPSHEET_CreatePage(HWND hwndParent,
rc.top + padding.y, rc.top + padding.y,
0, 0, SWP_NOSIZE); 0, 0, SWP_NOSIZE);
if (showPage)
ShowWindow(hwndPage, SW_SHOW); ShowWindow(hwndPage, SW_SHOW);
else
ShowWindow(hwndPage, SW_HIDE);
return TRUE; return TRUE;
} }
...@@ -654,7 +658,10 @@ static BOOL PROPSHEET_ShowPage(HWND hwndDlg, int index, PropSheetInfo * psInfo) ...@@ -654,7 +658,10 @@ static BOOL PROPSHEET_ShowPage(HWND hwndDlg, int index, PropSheetInfo * psInfo)
if (psInfo->proppage[index].hwndPage != 0) if (psInfo->proppage[index].hwndPage != 0)
ShowWindow(psInfo->proppage[index].hwndPage, SW_SHOW); ShowWindow(psInfo->proppage[index].hwndPage, SW_SHOW);
else else
PROPSHEET_CreatePage(hwndDlg, index, psInfo); {
LPCPROPSHEETPAGEA ppshpage = PROPSHEET_GetPSPPage(psInfo, index);
PROPSHEET_CreatePage(hwndDlg, index, psInfo, ppshpage, TRUE);
}
psInfo->active_page = index; psInfo->active_page = index;
...@@ -690,7 +697,7 @@ static BOOL PROPSHEET_Apply(HWND hwndDlg) ...@@ -690,7 +697,7 @@ static BOOL PROPSHEET_Apply(HWND hwndDlg)
*/ */
hdr.code = PSN_APPLY; hdr.code = PSN_APPLY;
for (i = 0; i < psInfo->ppshheader->nPages; i++) for (i = 0; i < psInfo->nPages; i++)
{ {
hwndPage = psInfo->proppage[i].hwndPage; hwndPage = psInfo->proppage[i].hwndPage;
msgResult = SendMessageA(hwndPage, WM_NOTIFY, 0, (LPARAM) &hdr); msgResult = SendMessageA(hwndPage, WM_NOTIFY, 0, (LPARAM) &hdr);
...@@ -729,6 +736,22 @@ static void PROPSHEET_Cancel(HWND hwndDlg) ...@@ -729,6 +736,22 @@ static void PROPSHEET_Cancel(HWND hwndDlg)
} }
/****************************************************************************** /******************************************************************************
* PROPSHEET_Help
*/
static void PROPSHEET_Help(HWND hwndDlg)
{
PropSheetInfo* psInfo = (PropSheetInfo*) GetPropA(hwndDlg,
PropSheetInfoStr);
HWND hwndPage = psInfo->proppage[psInfo->active_page].hwndPage;
NMHDR hdr;
hdr.hwndFrom = hwndDlg;
hdr.code = PSN_HELP;
SendMessageA(hwndPage, WM_NOTIFY, 0, (LPARAM) &hdr);
}
/******************************************************************************
* PROPSHEET_Changed * PROPSHEET_Changed
*/ */
static void PROPSHEET_Changed(HWND hwndDlg, HWND hwndDirtyPage) static void PROPSHEET_Changed(HWND hwndDlg, HWND hwndDirtyPage)
...@@ -740,7 +763,7 @@ static void PROPSHEET_Changed(HWND hwndDlg, HWND hwndDirtyPage) ...@@ -740,7 +763,7 @@ static void PROPSHEET_Changed(HWND hwndDlg, HWND hwndDirtyPage)
/* /*
* Set the dirty flag of this page. * Set the dirty flag of this page.
*/ */
for (i = 0; i < psInfo->ppshheader->nPages; i++) for (i = 0; i < psInfo->nPages; i++)
{ {
if (psInfo->proppage[i].hwndPage == hwndDirtyPage) if (psInfo->proppage[i].hwndPage == hwndDirtyPage)
psInfo->proppage[i].isDirty = TRUE; psInfo->proppage[i].isDirty = TRUE;
...@@ -768,7 +791,7 @@ static void PROPSHEET_UnChanged(HWND hwndDlg, HWND hwndCleanPage) ...@@ -768,7 +791,7 @@ static void PROPSHEET_UnChanged(HWND hwndDlg, HWND hwndCleanPage)
PropSheetInfo* psInfo = (PropSheetInfo*) GetPropA(hwndDlg, PropSheetInfo* psInfo = (PropSheetInfo*) GetPropA(hwndDlg,
PropSheetInfoStr); PropSheetInfoStr);
for (i = 0; i < psInfo->ppshheader->nPages; i++) for (i = 0; i < psInfo->nPages; i++)
{ {
/* set the specified page as clean */ /* set the specified page as clean */
if (psInfo->proppage[i].hwndPage == hwndCleanPage) if (psInfo->proppage[i].hwndPage == hwndCleanPage)
...@@ -904,7 +927,7 @@ static LRESULT PROPSHEET_QuerySiblings(HWND hwndDlg, ...@@ -904,7 +927,7 @@ static LRESULT PROPSHEET_QuerySiblings(HWND hwndDlg,
PropSheetInfo* psInfo = (PropSheetInfo*) GetPropA(hwndDlg, PropSheetInfo* psInfo = (PropSheetInfo*) GetPropA(hwndDlg,
PropSheetInfoStr); PropSheetInfoStr);
while ((i < psInfo->ppshheader->nPages) && (msgResult == 0)) while ((i < psInfo->nPages) && (msgResult == 0))
{ {
hwndPage = psInfo->proppage[i].hwndPage; hwndPage = psInfo->proppage[i].hwndPage;
msgResult = SendMessageA(hwndPage, PSM_QUERYSIBLINGS, wParam, lParam); msgResult = SendMessageA(hwndPage, PSM_QUERYSIBLINGS, wParam, lParam);
...@@ -915,16 +938,28 @@ static LRESULT PROPSHEET_QuerySiblings(HWND hwndDlg, ...@@ -915,16 +938,28 @@ static LRESULT PROPSHEET_QuerySiblings(HWND hwndDlg,
} }
/****************************************************************************** /******************************************************************************
* PROPSHEET_GetPage * PROPSHEET_GetPSPPage
*/ */
static LPCPROPSHEETPAGEA PROPSHEET_GetPage(const PropSheetInfo * psInfo, static LPCPROPSHEETPAGEA PROPSHEET_GetPSPPage(const PropSheetInfo * psInfo,
int index) int index)
{ {
LPCPROPSHEETPAGEA lppsp = psInfo->ppshheader->u3.ppsp; BOOL usePSP = psInfo->ppshheader->dwFlags & PSH_PROPSHEETPAGE;
BYTE* pByte = (BYTE*) lppsp; LPCPROPSHEETPAGEA lppsp;
int realIndex = psInfo->proppage[index].index;
if (usePSP)
{
BYTE* pByte;
lppsp = psInfo->ppshheader->u3.ppsp;
pByte += (lppsp->dwSize * index); pByte = (BYTE*) lppsp;
pByte += (lppsp->dwSize * realIndex);
lppsp = (LPCPROPSHEETPAGEA)pByte; lppsp = (LPCPROPSHEETPAGEA)pByte;
}
else
lppsp = (LPCPROPSHEETPAGEA) psInfo->ppshheader->u3.phpage[realIndex];
return lppsp; return lppsp;
} }
...@@ -935,16 +970,45 @@ static LPCPROPSHEETPAGEA PROPSHEET_GetPage(const PropSheetInfo * psInfo, ...@@ -935,16 +970,45 @@ static LPCPROPSHEETPAGEA PROPSHEET_GetPage(const PropSheetInfo * psInfo,
static BOOL PROPSHEET_AddPage(HWND hwndDlg, static BOOL PROPSHEET_AddPage(HWND hwndDlg,
HPROPSHEETPAGE hpage) HPROPSHEETPAGE hpage)
{ {
/* PropSheetInfo * psInfo = (PropSheetInfo*) GetPropA(hwndDlg, PropSheetInfo * psInfo = (PropSheetInfo*) GetPropA(hwndDlg,
PropSheetInfoStr); PropSheetInfoStr);
HWND hwndTabControl = GetDlgItem(hwndDlg, IDC_TABCONTROL); HWND hwndTabControl = GetDlgItem(hwndDlg, IDC_TABCONTROL);
TCITEMA item;
char tabtext[MAX_TABTEXT_LENGTH] = "Tab text";
LPCPROPSHEETPAGEA ppsp = (LPCPROPSHEETPAGEA)hpage;
/*
* Allocate and fill in a new PropPageInfo entry.
*/
psInfo->proppage = (PropPageInfo*) COMCTL32_ReAlloc(psInfo->proppage, psInfo->proppage = (PropPageInfo*) COMCTL32_ReAlloc(psInfo->proppage,
sizeof(PropPageInfo) * sizeof(PropPageInfo) *
(psInfo->nPages + 1)); (psInfo->nPages + 1));
PROPSHEET_CollectPageInfo(ppsp, psInfo, psInfo->nPages);
psInfo->proppage[psInfo->nPages].index = -1;
psInfo->proppage[psInfo->nPages].hpage = hpage;
/*
* Create the page but don't show it.
*/
PROPSHEET_CreatePage(hwndDlg, psInfo->nPages, psInfo, ppsp, FALSE);
/*
* 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++;
*/
return FALSE; return FALSE;
} }
...@@ -955,16 +1019,105 @@ static BOOL PROPSHEET_RemovePage(HWND hwndDlg, ...@@ -955,16 +1019,105 @@ static BOOL PROPSHEET_RemovePage(HWND hwndDlg,
int index, int index,
HPROPSHEETPAGE hpage) HPROPSHEETPAGE hpage)
{ {
/*
PropSheetInfo * psInfo = (PropSheetInfo*) GetPropA(hwndDlg, PropSheetInfo * psInfo = (PropSheetInfo*) GetPropA(hwndDlg,
PropSheetInfoStr); PropSheetInfoStr);
HWND hwndTabControl = GetDlgItem(hwndDlg, IDC_TABCONTROL); HWND hwndTabControl = GetDlgItem(hwndDlg, IDC_TABCONTROL);
*/ PropPageInfo* oldPages = psInfo->proppage;
/*
* hpage takes precedence over index.
*/
if (hpage != 0)
{
index = PROPSHEET_GetPageIndex(hpage, psInfo);
if (index == -1)
{
TRACE(propsheet, "Could not find page to remove!\n");
return FALSE;
}
}
TRACE(propsheet, "total pages %d removing page %d active page %d\n",
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);
}
}
else
{
TRACE(propsheet, "Removing the only page, close the dialog!\n");
if (psInfo->isModeless)
psInfo->active_page = -1;
else
EndDialog(hwndDlg, FALSE);
return TRUE;
}
}
if (index < psInfo->active_page)
psInfo->active_page--;
/* 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);
return FALSE; return FALSE;
} }
/****************************************************************************** /******************************************************************************
* 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;
}
/******************************************************************************
* PROPSHEET_CleanUp * PROPSHEET_CleanUp
*/ */
static void PROPSHEET_CleanUp(HWND hwndDlg) static void PROPSHEET_CleanUp(HWND hwndDlg)
...@@ -985,9 +1138,22 @@ INT WINAPI PropertySheetA(LPCPROPSHEETHEADERA lppsh) ...@@ -985,9 +1138,22 @@ INT WINAPI PropertySheetA(LPCPROPSHEETHEADERA lppsh)
int bRet = 0; int bRet = 0;
PropSheetInfo* psInfo = (PropSheetInfo*) GlobalAlloc(GPTR, PropSheetInfo* psInfo = (PropSheetInfo*) GlobalAlloc(GPTR,
sizeof(PropSheetInfo)); sizeof(PropSheetInfo));
LPCPROPSHEETPAGEA lppsp;
int i;
PROPSHEET_CollectSheetInfo(lppsh, psInfo); PROPSHEET_CollectSheetInfo(lppsh, psInfo);
PROPSHEET_CollectPageInfo(lppsh, psInfo);
psInfo->proppage = (PropPageInfo*) COMCTL32_Alloc(sizeof(PropPageInfo) *
lppsh->nPages);
for (i = 0; i < lppsh->nPages; i++)
{
psInfo->proppage[i].index = i;
if (!(lppsh->dwFlags & PSH_PROPSHEETPAGE))
psInfo->proppage[i].hpage = psInfo->ppshheader->u3.phpage[i];
lppsp = PROPSHEET_GetPSPPage(psInfo, i);
PROPSHEET_CollectPageInfo(lppsp, psInfo, i);
}
bRet = PROPSHEET_CreateDialog(psInfo); bRet = PROPSHEET_CreateDialog(psInfo);
...@@ -1005,17 +1171,20 @@ INT WINAPI PropertySheetW(LPCPROPSHEETHEADERW propertySheetHeader) ...@@ -1005,17 +1171,20 @@ INT WINAPI PropertySheetW(LPCPROPSHEETHEADERW propertySheetHeader)
} }
/****************************************************************************** /******************************************************************************
* CreatePropertySheetPage32A (COMCTL32.19)(COMCTL32.18) * CreatePropertySheetPageA (COMCTL32.19)(COMCTL32.18)
*/ */
HPROPSHEETPAGE WINAPI CreatePropertySheetPageA(LPCPROPSHEETPAGEA lpPropSheetPage) HPROPSHEETPAGE WINAPI CreatePropertySheetPageA(
LPCPROPSHEETPAGEA lpPropSheetPage)
{ {
FIXME(propsheet, "(%p): stub\n", lpPropSheetPage); PROPSHEETPAGEA* ppsp = COMCTL32_Alloc(sizeof(PROPSHEETPAGEA));
return 0; *ppsp = *lpPropSheetPage;
return (HPROPSHEETPAGE)ppsp;
} }
/****************************************************************************** /******************************************************************************
* CreatePropertySheetPage32W (COMCTL32.20) * CreatePropertySheetPageW (COMCTL32.20)
*/ */
HPROPSHEETPAGE WINAPI CreatePropertySheetPageW(LPCPROPSHEETPAGEW lpPropSheetPage) HPROPSHEETPAGE WINAPI CreatePropertySheetPageW(LPCPROPSHEETPAGEW lpPropSheetPage)
{ {
...@@ -1025,12 +1194,13 @@ HPROPSHEETPAGE WINAPI CreatePropertySheetPageW(LPCPROPSHEETPAGEW lpPropSheetPage ...@@ -1025,12 +1194,13 @@ HPROPSHEETPAGE WINAPI CreatePropertySheetPageW(LPCPROPSHEETPAGEW lpPropSheetPage
} }
/****************************************************************************** /******************************************************************************
* DestroyPropertySheetPage32 (COMCTL32.24) * DestroyPropertySheetPage (COMCTL32.24)
*/ */
BOOL WINAPI DestroyPropertySheetPage(HPROPSHEETPAGE hPropPage) BOOL WINAPI DestroyPropertySheetPage(HPROPSHEETPAGE hPropPage)
{ {
FIXME(propsheet, "(0x%08lx): stub\n", (DWORD)hPropPage); COMCTL32_Free(hPropPage);
return FALSE;
return TRUE;
} }
/****************************************************************************** /******************************************************************************
...@@ -1046,6 +1216,7 @@ PROPSHEET_DialogProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) ...@@ -1046,6 +1216,7 @@ PROPSHEET_DialogProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
PropSheetInfo* psInfo = (PropSheetInfo*) lParam; PropSheetInfo* psInfo = (PropSheetInfo*) lParam;
char* strCaption = (char*)COMCTL32_Alloc(MAX_CAPTION_LENGTH); char* strCaption = (char*)COMCTL32_Alloc(MAX_CAPTION_LENGTH);
HWND hwndTabCtrl = GetDlgItem(hwnd, IDC_TABCONTROL); HWND hwndTabCtrl = GetDlgItem(hwnd, IDC_TABCONTROL);
LPCPROPSHEETPAGEA ppshpage;
psInfo->strPropertiesFor = strCaption; psInfo->strPropertiesFor = strCaption;
...@@ -1059,7 +1230,8 @@ PROPSHEET_DialogProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) ...@@ -1059,7 +1230,8 @@ PROPSHEET_DialogProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
PROPSHEET_AdjustButtons(hwnd, psInfo); PROPSHEET_AdjustButtons(hwnd, psInfo);
} }
PROPSHEET_CreatePage(hwnd, psInfo->active_page, psInfo); ppshpage = PROPSHEET_GetPSPPage(psInfo, psInfo->active_page);
PROPSHEET_CreatePage(hwnd, psInfo->active_page, psInfo, ppshpage, TRUE);
SendMessageA(hwndTabCtrl, TCM_SETCURSEL, psInfo->active_page, 0); SendMessageA(hwndTabCtrl, TCM_SETCURSEL, psInfo->active_page, 0);
SetPropA(hwnd, PropSheetInfoStr, (HANDLE)psInfo); SetPropA(hwnd, PropSheetInfoStr, (HANDLE)psInfo);
...@@ -1122,12 +1294,9 @@ PROPSHEET_DialogProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) ...@@ -1122,12 +1294,9 @@ PROPSHEET_DialogProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
break; break;
case IDHELP: case IDHELP:
{ PROPSHEET_Help(hwnd);
PROPSHEET_RemovePage(hwnd, 1, 0);
FIXME(propsheet, "Help!\n");
break; break;
} }
}
return TRUE; return TRUE;
} }
...@@ -1249,9 +1418,17 @@ PROPSHEET_DialogProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) ...@@ -1249,9 +1418,17 @@ PROPSHEET_DialogProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
return TRUE; return TRUE;
} }
case PSM_ADDPAGE:
PROPSHEET_AddPage(hwnd, (HPROPSHEETPAGE)lParam);
return TRUE;
case PSM_REMOVEPAGE:
PROPSHEET_RemovePage(hwnd, (int)wParam, (HPROPSHEETPAGE)lParam);
return TRUE;
case PSM_ISDIALOGMESSAGE: case PSM_ISDIALOGMESSAGE:
{ {
FIXME (propsheet, "Unimplemented msg PSM_REMOVEPAGE\n"); FIXME (propsheet, "Unimplemented msg PSM_ISDIALOGMESSAGE\n");
return 0; return 0;
} }
...@@ -1259,14 +1436,6 @@ PROPSHEET_DialogProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) ...@@ -1259,14 +1436,6 @@ PROPSHEET_DialogProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
PROPSHEET_PressButton(hwnd, (int)wParam); PROPSHEET_PressButton(hwnd, (int)wParam);
return TRUE; return TRUE;
case PSM_REMOVEPAGE:
FIXME (propsheet, "Unimplemented msg PSM_REMOVEPAGE\n");
PROPSHEET_RemovePage(hwnd, (int)wParam, (HPROPSHEETPAGE)lParam);
return 0;
case PSM_ADDPAGE:
FIXME (propsheet, "Unimplemented msg PSM_ADDPAGE\n");
PROPSHEET_AddPage(hwnd, (HPROPSHEETPAGE)lParam);
return 0;
case PSM_SETTITLEW: case PSM_SETTITLEW:
FIXME (propsheet, "Unimplemented msg PSM_SETTITLE32W\n"); FIXME (propsheet, "Unimplemented msg PSM_SETTITLE32W\n");
return 0; return 0;
......
/******************************************************************************
*
* Property Sheets
*
* Copyright 1999 Thuy Nguyen
*
*/
extern HMODULE COMCTL32_hModule;
#define IDD_PROPSHEET 1006
#define IDD_WIZARD 1020
#define IDC_TABCONTROL 12320
#define IDC_APPLY_BUTTON 12321
#include "winuser.h" #include "winuser.h"
#include "propsheet.h"
PROPSHEET DIALOG DISCARDABLE 0, 0, 292, 159
IDD_PROPSHEET DIALOG DISCARDABLE 0, 0, 292, 159
STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU
CAPTION "Properties for " CAPTION "Properties for "
FONT 8, "MS Sans Serif" FONT 8, "MS Sans Serif"
BEGIN BEGIN
DEFPUSHBUTTON "OK", IDOK,72,138,50,14 DEFPUSHBUTTON "OK", IDOK,72,138,50,14
PUSHBUTTON "Cancel", IDCANCEL,127,138,50,14 PUSHBUTTON "Cancel", IDCANCEL,127,138,50,14
PUSHBUTTON "&Apply", 12321,181,138,50,14 PUSHBUTTON "&Apply", IDC_APPLY_BUTTON,181,138,50,14
PUSHBUTTON "Help", IDHELP,235,138,50,14 PUSHBUTTON "Help", IDHELP,235,138,50,14
CONTROL "Tab", 12320,"SysTabControl32",WS_CLIPSIBLINGS,7,7,278,125 CONTROL "Tab", IDC_TABCONTROL,"SysTabControl32",WS_CLIPSIBLINGS,7,7,278,125
END END
...@@ -1422,6 +1422,22 @@ TAB_DeleteItem (HWND hwnd, WPARAM wParam, LPARAM lParam) ...@@ -1422,6 +1422,22 @@ TAB_DeleteItem (HWND hwnd, WPARAM wParam, LPARAM lParam)
(infoPtr->uNumItem - iItem) * sizeof(TAB_ITEM)); (infoPtr->uNumItem - iItem) * sizeof(TAB_ITEM));
COMCTL32_Free (oldItems); COMCTL32_Free (oldItems);
/*
* Readjust the selected index.
*/
if ((iItem == infoPtr->iSelected) && (iItem > 0))
infoPtr->iSelected--;
if (iItem < infoPtr->iSelected)
infoPtr->iSelected--;
/*
* Reposition and repaint tabs.
*/
TAB_SetItemBounds(hwnd);
TAB_InvalidateTabArea(hwnd,infoPtr);
bResult = TRUE; bResult = TRUE;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment