winhelp: Get rid of the reuse concept for Windows and refactor the code a bit for window creation / deletion.
This commit is contained in:
parent
faaccca59b
commit
7a608ea627
|
@ -52,6 +52,7 @@ static BOOL WINHELP_SplitLines(HWND hWnd, LPSIZE);
|
||||||
static void WINHELP_InitFonts(HWND hWnd);
|
static void WINHELP_InitFonts(HWND hWnd);
|
||||||
static void WINHELP_DeleteLines(WINHELP_WINDOW*);
|
static void WINHELP_DeleteLines(WINHELP_WINDOW*);
|
||||||
static void WINHELP_DeleteWindow(WINHELP_WINDOW*);
|
static void WINHELP_DeleteWindow(WINHELP_WINDOW*);
|
||||||
|
static void WINHELP_DeleteButtons(WINHELP_WINDOW*);
|
||||||
static void WINHELP_SetupText(HWND hWnd);
|
static void WINHELP_SetupText(HWND hWnd);
|
||||||
static WINHELP_LINE_PART* WINHELP_IsOverLink(WINHELP_WINDOW*, WPARAM, LPARAM);
|
static WINHELP_LINE_PART* WINHELP_IsOverLink(WINHELP_WINDOW*, WPARAM, LPARAM);
|
||||||
|
|
||||||
|
@ -478,93 +479,41 @@ void WINHELP_LayoutMainWindow(WINHELP_WINDOW* win)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/******************************************************************
|
static void WINHELP_AddHistory(WINHELP_WINDOW* win, HLPFILE_PAGE* page)
|
||||||
* WINHELP_ReuseWindow
|
|
||||||
*
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
static BOOL WINHELP_ReuseWindow(WINHELP_WINDOW* win, WINHELP_WINDOW* oldwin,
|
|
||||||
HLPFILE_PAGE* page, int nCmdShow)
|
|
||||||
{
|
{
|
||||||
HWND hTextWnd = GetDlgItem(oldwin->hMainWnd, CTL_ID_TEXT);
|
unsigned i, num;
|
||||||
unsigned int i;
|
|
||||||
|
|
||||||
win->hMainWnd = oldwin->hMainWnd;
|
/* FIXME: when using back, we shouldn't update the history... */
|
||||||
win->hHistoryWnd = oldwin->hHistoryWnd;
|
for (i = 0; i < win->histIndex; i++)
|
||||||
oldwin->hMainWnd = oldwin->hHistoryWnd = 0;
|
if (win->history[i] == page) break;
|
||||||
win->hBrush = CreateSolidBrush(win->info->sr_color);
|
|
||||||
|
|
||||||
SetWindowLongPtr(win->hMainWnd, 0, (ULONG_PTR)win);
|
/* if the new page is already in the history, do nothing */
|
||||||
SetWindowLongPtr(hTextWnd, 0, (ULONG_PTR)win);
|
if (i == win->histIndex)
|
||||||
SetWindowLongPtr(win->hHistoryWnd, 0, (ULONG_PTR)win);
|
|
||||||
|
|
||||||
WINHELP_InitFonts(win->hMainWnd);
|
|
||||||
|
|
||||||
if (page)
|
|
||||||
SetWindowText(win->hMainWnd, page->file->lpszTitle);
|
|
||||||
|
|
||||||
WINHELP_SetupText(hTextWnd);
|
|
||||||
InvalidateRect(hTextWnd, NULL, TRUE);
|
|
||||||
WINHELP_LayoutMainWindow(win);
|
|
||||||
ShowWindow(win->hMainWnd, nCmdShow);
|
|
||||||
UpdateWindow(hTextWnd);
|
|
||||||
|
|
||||||
if (!(win->info->win_style & WS_POPUP))
|
|
||||||
{
|
{
|
||||||
unsigned num;
|
num = sizeof(win->history) / sizeof(win->history[0]);
|
||||||
|
if (win->histIndex == num)
|
||||||
memcpy(win->history, oldwin->history, sizeof(win->history));
|
|
||||||
win->histIndex = oldwin->histIndex;
|
|
||||||
|
|
||||||
/* FIXME: when using back, we shouldn't update the history... */
|
|
||||||
|
|
||||||
if (page)
|
|
||||||
{
|
{
|
||||||
for (i = 0; i < win->histIndex; i++)
|
/* we're full, remove latest entry */
|
||||||
if (win->history[i] == page) break;
|
HLPFILE_FreeHlpFile(win->history[0]->file);
|
||||||
|
memmove(&win->history[0], &win->history[1],
|
||||||
/* if the new page is already in the history, do nothing */
|
(num - 1) * sizeof(win->history[0]));
|
||||||
if (i == win->histIndex)
|
win->histIndex--;
|
||||||
{
|
|
||||||
num = sizeof(win->history) / sizeof(win->history[0]);
|
|
||||||
if (win->histIndex == num)
|
|
||||||
{
|
|
||||||
/* we're full, remove latest entry */
|
|
||||||
HLPFILE_FreeHlpFile(win->history[0]->file);
|
|
||||||
memmove(&win->history[0], &win->history[1],
|
|
||||||
(num - 1) * sizeof(win->history[0]));
|
|
||||||
win->histIndex--;
|
|
||||||
}
|
|
||||||
win->history[win->histIndex++] = page;
|
|
||||||
page->file->wRefCount++;
|
|
||||||
if (win->hHistoryWnd) InvalidateRect(win->hHistoryWnd, NULL, TRUE);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
memcpy(win->back, oldwin->back, sizeof(win->back));
|
|
||||||
win->backIndex = oldwin->backIndex;
|
|
||||||
|
|
||||||
if (page)
|
|
||||||
{
|
|
||||||
num = sizeof(win->back) / sizeof(win->back[0]);
|
|
||||||
if (win->backIndex == num)
|
|
||||||
{
|
|
||||||
/* we're full, remove latest entry */
|
|
||||||
HLPFILE_FreeHlpFile(win->back[0]->file);
|
|
||||||
memmove(&win->back[0], &win->back[1],
|
|
||||||
(num - 1) * sizeof(win->back[0]));
|
|
||||||
win->backIndex--;
|
|
||||||
}
|
|
||||||
win->back[win->backIndex++] = page;
|
|
||||||
page->file->wRefCount++;
|
|
||||||
}
|
}
|
||||||
|
win->history[win->histIndex++] = page;
|
||||||
|
page->file->wRefCount++;
|
||||||
|
if (win->hHistoryWnd) InvalidateRect(win->hHistoryWnd, NULL, TRUE);
|
||||||
}
|
}
|
||||||
else
|
|
||||||
win->backIndex = win->histIndex = 0;
|
|
||||||
|
|
||||||
oldwin->histIndex = oldwin->backIndex = 0;
|
num = sizeof(win->back) / sizeof(win->back[0]);
|
||||||
WINHELP_DeleteWindow(oldwin);
|
if (win->backIndex == num)
|
||||||
return TRUE;
|
{
|
||||||
|
/* we're full, remove latest entry */
|
||||||
|
HLPFILE_FreeHlpFile(win->back[0]->file);
|
||||||
|
memmove(&win->back[0], &win->back[1], (num - 1) * sizeof(win->back[0]));
|
||||||
|
win->backIndex--;
|
||||||
|
}
|
||||||
|
win->back[win->backIndex++] = page;
|
||||||
|
page->file->wRefCount++;
|
||||||
}
|
}
|
||||||
|
|
||||||
/***********************************************************************
|
/***********************************************************************
|
||||||
|
@ -574,38 +523,72 @@ static BOOL WINHELP_ReuseWindow(WINHELP_WINDOW* win, WINHELP_WINDOW* oldwin,
|
||||||
BOOL WINHELP_CreateHelpWindow(HLPFILE_PAGE* page, HLPFILE_WINDOWINFO* wi,
|
BOOL WINHELP_CreateHelpWindow(HLPFILE_PAGE* page, HLPFILE_WINDOWINFO* wi,
|
||||||
int nCmdShow)
|
int nCmdShow)
|
||||||
{
|
{
|
||||||
WINHELP_WINDOW *win, *oldwin;
|
WINHELP_WINDOW* win = NULL;
|
||||||
HWND hWnd;
|
BOOL bPrimary, bPopup, bReUsed = FALSE;
|
||||||
BOOL bPrimary;
|
LPSTR name;
|
||||||
BOOL bPopup;
|
|
||||||
LPSTR name;
|
|
||||||
DWORD ex_style;
|
|
||||||
|
|
||||||
bPrimary = !lstrcmpi(wi->name, "main");
|
bPrimary = !lstrcmpi(wi->name, "main");
|
||||||
bPopup = !bPrimary && (wi->win_style & WS_POPUP);
|
bPopup = !bPrimary && (wi->win_style & WS_POPUP);
|
||||||
|
|
||||||
if (page && !page->first_paragraph) HLPFILE_BrowsePage(page);
|
if (page && !page->first_paragraph) HLPFILE_BrowsePage(page);
|
||||||
|
|
||||||
/* Initialize WINHELP_WINDOW struct */
|
if (!bPopup)
|
||||||
win = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
|
{
|
||||||
sizeof(WINHELP_WINDOW) + strlen(wi->name) + 1);
|
for (win = Globals.win_list; win; win = win->next)
|
||||||
if (!win) return FALSE;
|
{
|
||||||
|
if (!lstrcmpi(win->lpszName, wi->name))
|
||||||
|
{
|
||||||
|
WINHELP_DeleteButtons(win);
|
||||||
|
bReUsed = TRUE;
|
||||||
|
SetWindowText(win->hMainWnd, wi->caption);
|
||||||
|
if (wi->origin.x != CW_USEDEFAULT &&
|
||||||
|
wi->origin.y != CW_USEDEFAULT)
|
||||||
|
SetWindowPos(win->hMainWnd, HWND_TOP,
|
||||||
|
wi->origin.x, wi->origin.y, 0, 0, SWP_NOSIZE);
|
||||||
|
if (wi->size.cx != CW_USEDEFAULT &&
|
||||||
|
wi->size.cy != CW_USEDEFAULT)
|
||||||
|
SetWindowPos(win->hMainWnd, HWND_TOP,
|
||||||
|
0, 0, wi->size.cx, wi->size.cy, SWP_NOMOVE);
|
||||||
|
WINHELP_InitFonts(win->hMainWnd);
|
||||||
|
|
||||||
win->next = Globals.win_list;
|
win->page = page;
|
||||||
Globals.win_list = win;
|
win->info = wi;
|
||||||
|
WINHELP_SetupText(GetDlgItem(win->hMainWnd, CTL_ID_TEXT));
|
||||||
|
InvalidateRect(win->hMainWnd, NULL, TRUE);
|
||||||
|
if (win->hHistoryWnd) InvalidateRect(win->hHistoryWnd, NULL, TRUE);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
name = (char*)win + sizeof(WINHELP_WINDOW);
|
if (!win)
|
||||||
lstrcpy(name, wi->name);
|
{
|
||||||
win->lpszName = name;
|
/* Initialize WINHELP_WINDOW struct */
|
||||||
|
win = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
|
||||||
|
sizeof(WINHELP_WINDOW) + strlen(wi->name) + 1);
|
||||||
|
if (!win) return FALSE;
|
||||||
|
win->next = Globals.win_list;
|
||||||
|
Globals.win_list = win;
|
||||||
|
|
||||||
|
name = (char*)win + sizeof(WINHELP_WINDOW);
|
||||||
|
lstrcpy(name, wi->name);
|
||||||
|
win->lpszName = name;
|
||||||
|
win->hHandCur = LoadCursorW(0, (LPWSTR)IDC_HAND);
|
||||||
|
win->histIndex = win->backIndex = 0;
|
||||||
|
}
|
||||||
win->page = page;
|
win->page = page;
|
||||||
|
win->info = wi;
|
||||||
|
|
||||||
win->hArrowCur = LoadCursorA(0, (LPSTR)IDC_ARROW);
|
win->hArrowCur = LoadCursorA(0, (LPSTR)IDC_ARROW);
|
||||||
win->hHandCur = LoadCursorA(0, (LPSTR)IDC_HAND);
|
win->hHandCur = LoadCursorA(0, (LPSTR)IDC_HAND);
|
||||||
|
|
||||||
win->info = wi;
|
if (!bPopup && page)
|
||||||
|
{
|
||||||
|
WINHELP_AddHistory(win, page);
|
||||||
|
}
|
||||||
|
|
||||||
Globals.active_win = win;
|
if (!bPopup)
|
||||||
|
Globals.active_win = win;
|
||||||
|
|
||||||
/* Initialize default pushbuttons */
|
/* Initialize default pushbuttons */
|
||||||
if (bPrimary && page)
|
if (bPrimary && page)
|
||||||
|
@ -635,46 +618,29 @@ BOOL WINHELP_CreateHelpWindow(HLPFILE_PAGE* page, HLPFILE_WINDOWINFO* wi,
|
||||||
MACRO_ExecuteMacro(macro->lpszMacro);
|
MACRO_ExecuteMacro(macro->lpszMacro);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Reuse existing window */
|
if (!bReUsed)
|
||||||
if (!bPopup)
|
|
||||||
{
|
{
|
||||||
for (oldwin = win->next; oldwin; oldwin = oldwin->next)
|
win->hMainWnd = CreateWindowEx((bPopup) ? WS_EX_TOOLWINDOW : 0, MAIN_WIN_CLASS_NAME,
|
||||||
{
|
wi->caption,
|
||||||
if (!lstrcmpi(oldwin->lpszName, wi->name))
|
bPrimary ? WS_OVERLAPPEDWINDOW : wi->win_style,
|
||||||
{
|
wi->origin.x, wi->origin.y, wi->size.cx, wi->size.cy,
|
||||||
return WINHELP_ReuseWindow(win, oldwin, page, nCmdShow);
|
bPopup ? Globals.active_win->hMainWnd : NULL,
|
||||||
}
|
bPrimary ? LoadMenu(Globals.hInstance, MAKEINTRESOURCE(MAIN_MENU)) : 0,
|
||||||
}
|
Globals.hInstance, win);
|
||||||
if (page)
|
if (!bPopup)
|
||||||
{
|
/* Create button box and text Window */
|
||||||
win->histIndex = win->backIndex = 1;
|
CreateWindow(BUTTON_BOX_WIN_CLASS_NAME, "", WS_CHILD | WS_VISIBLE,
|
||||||
win->history[0] = win->back[0] = page;
|
0, 0, 0, 0, win->hMainWnd, (HMENU)CTL_ID_BUTTON, Globals.hInstance, NULL);
|
||||||
page->file->wRefCount += 2;
|
|
||||||
strcpy(wi->caption, page->file->lpszTitle);
|
CreateWindow(TEXT_WIN_CLASS_NAME, "", WS_CHILD | WS_VISIBLE,
|
||||||
}
|
0, 0, 0, 0, win->hMainWnd, (HMENU)CTL_ID_TEXT, Globals.hInstance, win);
|
||||||
}
|
}
|
||||||
|
|
||||||
ex_style = 0;
|
|
||||||
if (bPopup) ex_style = WS_EX_TOOLWINDOW;
|
|
||||||
hWnd = CreateWindowEx(ex_style, MAIN_WIN_CLASS_NAME,
|
|
||||||
wi->caption,
|
|
||||||
bPrimary ? WS_OVERLAPPEDWINDOW : wi->win_style,
|
|
||||||
wi->origin.x, wi->origin.y, wi->size.cx, wi->size.cy,
|
|
||||||
NULL, bPrimary ? LoadMenu(Globals.hInstance, MAKEINTRESOURCE(MAIN_MENU)) : 0,
|
|
||||||
Globals.hInstance, win);
|
|
||||||
/* Create button box and text Window */
|
|
||||||
if (!bPopup)
|
|
||||||
CreateWindow(BUTTON_BOX_WIN_CLASS_NAME, "", WS_CHILD | WS_VISIBLE,
|
|
||||||
0, 0, 0, 0, hWnd, (HMENU)CTL_ID_BUTTON, Globals.hInstance, NULL);
|
|
||||||
|
|
||||||
CreateWindow(TEXT_WIN_CLASS_NAME, "", WS_CHILD | WS_VISIBLE,
|
|
||||||
0, 0, 0, 0, hWnd, (HMENU)CTL_ID_TEXT, Globals.hInstance, win);
|
|
||||||
|
|
||||||
WINHELP_LayoutMainWindow(win);
|
WINHELP_LayoutMainWindow(win);
|
||||||
if (bPopup) Globals.hPopupWnd = hWnd;
|
if (bPopup) Globals.hPopupWnd = win->hMainWnd;
|
||||||
|
|
||||||
ShowWindow(hWnd, nCmdShow);
|
ShowWindow(win->hMainWnd, nCmdShow);
|
||||||
UpdateWindow(hWnd);
|
UpdateWindow(win->hMainWnd);
|
||||||
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
@ -1802,6 +1768,24 @@ static void WINHELP_DeleteLines(WINHELP_WINDOW *win)
|
||||||
win->first_line = 0;
|
win->first_line = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/******************************************************************
|
||||||
|
* WINHELP_DeleteButtons
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
static void WINHELP_DeleteButtons(WINHELP_WINDOW* win)
|
||||||
|
{
|
||||||
|
WINHELP_BUTTON* b;
|
||||||
|
WINHELP_BUTTON* bp;
|
||||||
|
|
||||||
|
for (b = win->first_button; b; b = bp)
|
||||||
|
{
|
||||||
|
DestroyWindow(b->hWnd);
|
||||||
|
bp = b->next;
|
||||||
|
HeapFree(GetProcessHeap(), 0, b);
|
||||||
|
}
|
||||||
|
win->first_button = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
/***********************************************************************
|
/***********************************************************************
|
||||||
*
|
*
|
||||||
* WINHELP_DeleteWindow
|
* WINHELP_DeleteWindow
|
||||||
|
@ -1810,8 +1794,6 @@ static void WINHELP_DeleteWindow(WINHELP_WINDOW* win)
|
||||||
{
|
{
|
||||||
WINHELP_WINDOW** w;
|
WINHELP_WINDOW** w;
|
||||||
unsigned int i;
|
unsigned int i;
|
||||||
WINHELP_BUTTON* b;
|
|
||||||
WINHELP_BUTTON* bp;
|
|
||||||
|
|
||||||
for (w = &Globals.win_list; *w; w = &(*w)->next)
|
for (w = &Globals.win_list; *w; w = &(*w)->next)
|
||||||
{
|
{
|
||||||
|
@ -1829,12 +1811,7 @@ static void WINHELP_DeleteWindow(WINHELP_WINDOW* win)
|
||||||
SetActiveWindow(Globals.win_list->hMainWnd);
|
SetActiveWindow(Globals.win_list->hMainWnd);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (b = win->first_button; b; b = bp)
|
WINHELP_DeleteButtons(win);
|
||||||
{
|
|
||||||
DestroyWindow(b->hWnd);
|
|
||||||
bp = b->next;
|
|
||||||
HeapFree(GetProcessHeap(), 0, b);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (win->hShadowWnd) DestroyWindow(win->hShadowWnd);
|
if (win->hShadowWnd) DestroyWindow(win->hShadowWnd);
|
||||||
if (win->hHistoryWnd) DestroyWindow(win->hHistoryWnd);
|
if (win->hHistoryWnd) DestroyWindow(win->hHistoryWnd);
|
||||||
|
|
Loading…
Reference in New Issue