[PATCH 21/45] [WinHelp]: get rid of the reuse function, and do it properly
Eric Pouech
eric.pouech at orange.fr
Sun Mar 23 04:19:26 CDT 2008
- also fixing a couple of bugs in reuse function (like window size)
A+
---
programs/winhelp/winhelp.c | 253 ++++++++++++++++++++------------------------
1 files changed, 114 insertions(+), 139 deletions(-)
diff --git a/programs/winhelp/winhelp.c b/programs/winhelp/winhelp.c
index 91ef1f8..d944051 100644
--- a/programs/winhelp/winhelp.c
+++ b/programs/winhelp/winhelp.c
@@ -49,6 +49,7 @@ static LRESULT CALLBACK WINHELP_HistoryWndProc(HWND, UINT, WPARAM, LPARAM);
static LRESULT CALLBACK WINHELP_ShadowWndProc(HWND, UINT, WPARAM, LPARAM);
static BOOL WINHELP_CheckPopup(HWND, UINT, WPARAM, LPARAM, LRESULT*);
static void WINHELP_DeleteWindow(WINHELP_WINDOW*);
+static void WINHELP_DeleteButtons(WINHELP_WINDOW* win);
static void WINHELP_DeletePageLinks(WINHELP_WINDOW* win);
static void WINHELP_FillRichEdit(HWND hText, WINHELP_WINDOW *win);
@@ -474,92 +475,41 @@ void WINHELP_LayoutMainWindow(WINHELP_WINDOW* win)
rect.bottom - text_top, 0);
}
-/******************************************************************
- * WINHELP_ReuseWindow
- *
- *
- */
-static BOOL WINHELP_ReuseWindow(WINHELP_WINDOW* win, WINHELP_WINDOW* oldwin,
- HLPFILE_PAGE* page, int nCmdShow)
+static void WINHELP_AddHistory(WINHELP_WINDOW* win, HLPFILE_PAGE* page)
{
- unsigned int i;
- HWND hTextWnd;
-
- win->hMainWnd = oldwin->hMainWnd;
- win->hHistoryWnd = oldwin->hHistoryWnd;
- oldwin->hMainWnd = oldwin->hHistoryWnd = 0;
+ unsigned i, num;
- WINHELP_DeletePageLinks(oldwin);
- win->page_links = oldwin->page_links = NULL;
-
- SetWindowLong(win->hMainWnd, 0, (LONG)win);
- SetWindowLong(win->hHistoryWnd, 0, (LONG)win);
-
- if (page)
- SetWindowText(win->hMainWnd, page->file->lpszTitle);
-
- hTextWnd = GetDlgItem(win->hMainWnd, CTL_ID_TEXT);
- InvalidateRect(hTextWnd, NULL, TRUE);
- WINHELP_LayoutMainWindow(win);
- WINHELP_FillRichEdit(hTextWnd, win);
- ShowWindow(win->hMainWnd, nCmdShow);
+ /* FIXME: when using back, we shouldn't update the history... */
+ for (i = 0; i < win->histIndex; i++)
+ if (win->history[i] == page) break;
- if (!(win->info->win_style & WS_POPUP))
+ /* if the new page is already in the history, do nothing */
+ if (i == win->histIndex)
{
- unsigned 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)
+ num = sizeof(win->history) / sizeof(win->history[0]);
+ if (win->histIndex == num)
{
- for (i = 0; i < win->histIndex; i++)
- if (win->history[i] == page) break;
-
- /* if the new page is already in the history, do nothing */
- if (i == 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++;
+ /* 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);
}
- else
- win->backIndex = win->histIndex = 0;
- oldwin->histIndex = oldwin->backIndex = 0;
- WINHELP_DeleteWindow(oldwin);
- return TRUE;
+ 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++;
}
/***********************************************************************
@@ -569,34 +519,64 @@ static BOOL WINHELP_ReuseWindow(WINHELP_WINDOW* win, WINHELP_WINDOW* oldwin,
BOOL WINHELP_CreateHelpWindow(HLPFILE_PAGE* page, HLPFILE_WINDOWINFO* wi,
int nCmdShow)
{
- WINHELP_WINDOW *win, *oldwin;
- HWND hTextWnd;
- BOOL bPrimary;
- BOOL bPopup;
- LPSTR name;
+ WINHELP_WINDOW* win = NULL;
+ HWND hTextWnd;
+ BOOL bPrimary;
+ BOOL bPopup;
+ BOOL bReUsed = FALSE;
+ LPSTR name;
bPrimary = !lstrcmpi(wi->name, "main");
bPopup = !bPrimary && (wi->win_style & WS_POPUP);
- /* 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;
+ if (!bPopup)
+ {
+ for (win = Globals.win_list; win; win = win->next)
+ {
+ if (!lstrcmpi(win->lpszName, wi->name))
+ {
+ WINHELP_DeletePageLinks(win);
+ 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);
+ break;
+ }
+ }
+ }
- name = (char*)win + sizeof(WINHELP_WINDOW);
- lstrcpy(name, wi->name);
- win->lpszName = name;
+ if (!win)
+ {
+ /* 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->hHandCur = LoadCursorW(0, (LPWSTR)IDC_HAND);
-
win->info = wi;
win->page_links = NULL;
+ if (!bPopup && page)
+ {
+ WINHELP_AddHistory(win, page);
+ }
+
if (bPopup)
Globals.active_popup = win;
else
@@ -630,44 +610,27 @@ BOOL WINHELP_CreateHelpWindow(HLPFILE_PAGE* page, HLPFILE_WINDOWINFO* wi,
MACRO_ExecuteMacro(macro->lpszMacro);
}
- /* Reuse existing window */
- if (!bPopup)
+ if (!bReUsed)
{
- for (oldwin = win->next; oldwin; oldwin = oldwin->next)
- {
- if (!lstrcmpi(oldwin->lpszName, wi->name))
- {
- return WINHELP_ReuseWindow(win, oldwin, page, nCmdShow);
- }
- }
- if (page)
- {
- win->histIndex = win->backIndex = 1;
- win->history[0] = win->back[0] = page;
- page->file->wRefCount += 2;
- strcpy(wi->caption, page->file->lpszTitle);
- }
+ win->hMainWnd = CreateWindowEx((bPopup) ? WS_EX_TOOLWINDOW : 0, MAIN_WIN_CLASS_NAME,
+ wi->caption,
+ bPrimary ? WS_OVERLAPPEDWINDOW : wi->win_style,
+ wi->origin.x, wi->origin.y, wi->size.cx, wi->size.cy,
+ bPopup ? Globals.active_win->hMainWnd : NULL,
+ bPrimary ? LoadMenu(Globals.hInstance, MAKEINTRESOURCE(MAIN_MENU)) : 0,
+ Globals.hInstance, win);
+ if (!bPopup)
+ /* Create button box and text Window */
+ CreateWindow(BUTTON_BOX_WIN_CLASS_NAME, "", WS_CHILD | WS_VISIBLE,
+ 0, 0, 0, 0, win->hMainWnd, (HMENU)CTL_ID_BUTTON, Globals.hInstance, NULL);
+
+ hTextWnd = CreateWindow(RICHEDIT_CLASS, NULL,
+ ES_MULTILINE | ES_READONLY | WS_CHILD | WS_HSCROLL | WS_VSCROLL | WS_VISIBLE,
+ 0, 0, 0, 0, win->hMainWnd, (HMENU)CTL_ID_TEXT, Globals.hInstance, NULL);
+ SendMessage(hTextWnd, EM_SETEVENTMASK, 0,
+ SendMessage(hTextWnd, EM_GETEVENTMASK, 0, 0) | ENM_MOUSEEVENTS);
}
- win->hMainWnd = CreateWindowEx((bPopup) ? WS_EX_TOOLWINDOW : 0, MAIN_WIN_CLASS_NAME,
- wi->caption,
- bPrimary ? WS_OVERLAPPEDWINDOW : wi->win_style,
- wi->origin.x, wi->origin.y, wi->size.cx, wi->size.cy,
- bPopup ? Globals.active_win->hMainWnd : NULL,
- bPrimary ? LoadMenu(Globals.hInstance, MAKEINTRESOURCE(MAIN_MENU)) : 0,
- Globals.hInstance, win);
- if (!bPopup)
- /* Create button box and text Window */
- CreateWindow(BUTTON_BOX_WIN_CLASS_NAME, "", WS_CHILD | WS_VISIBLE,
- 0, 0, 0, 0, win->hMainWnd, (HMENU)CTL_ID_BUTTON, Globals.hInstance, NULL);
-
- hTextWnd = CreateWindow(RICHEDIT_CLASS, NULL,
- ES_MULTILINE | ES_READONLY | WS_CHILD | WS_HSCROLL | WS_VSCROLL | WS_VISIBLE,
- 0, 0, 0, 0, win->hMainWnd, (HMENU)CTL_ID_TEXT, Globals.hInstance, NULL);
-
- SendMessage(hTextWnd, EM_SETEVENTMASK, 0,
- SendMessage(hTextWnd, EM_GETEVENTMASK, 0, 0) | ENM_MOUSEEVENTS);
-
if (bPopup)
{
HWND hTextWnd = GetDlgItem(win->hMainWnd, CTL_ID_TEXT);
@@ -696,6 +659,7 @@ BOOL WINHELP_CreateHelpWindow(HLPFILE_PAGE* page, HLPFILE_WINDOWINFO* wi,
else
{
WINHELP_LayoutMainWindow(win);
+ WINHELP_FillRichEdit(GetDlgItem(win->hMainWnd, CTL_ID_TEXT), win);
ShowWindow(win->hMainWnd, nCmdShow);
}
@@ -1258,6 +1222,24 @@ static void WINHELP_DeletePageLinks(WINHELP_WINDOW* win)
}
}
+/******************************************************************
+ * 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
@@ -1266,8 +1248,6 @@ static void WINHELP_DeleteWindow(WINHELP_WINDOW* win)
{
WINHELP_WINDOW** w;
unsigned int i;
- WINHELP_BUTTON* b;
- WINHELP_BUTTON* bp;
for (w = &Globals.win_list; *w; w = &(*w)->next)
{
@@ -1287,12 +1267,7 @@ static void WINHELP_DeleteWindow(WINHELP_WINDOW* win)
if (win == Globals.active_popup)
Globals.active_popup = NULL;
- for (b = win->first_button; b; b = bp)
- {
- DestroyWindow(b->hWnd);
- bp = b->next;
- HeapFree(GetProcessHeap(), 0, b);
- }
+ WINHELP_DeleteButtons(win);
WINHELP_DeletePageLinks(win);
if (win->hShadowWnd) DestroyWindow(win->hShadowWnd);
More information about the wine-patches
mailing list