[PATCH 01/45] [WinHelp]: now setting the text Window as a richedit one
Eric Pouech
eric.pouech at orange.fr
Sun Mar 23 04:16:23 CDT 2008
- all popups are now of MainWindow kind (and embed a richedit control)
A+
---
programs/winhelp/string.c | 1
programs/winhelp/winhelp.c | 932 ++------------------------------------------
programs/winhelp/winhelp.h | 42 --
3 files changed, 40 insertions(+), 935 deletions(-)
diff --git a/programs/winhelp/string.c b/programs/winhelp/string.c
index df85cf4..b931948 100644
--- a/programs/winhelp/string.c
+++ b/programs/winhelp/string.c
@@ -22,7 +22,6 @@
const char MAIN_WIN_CLASS_NAME[] = "MS_WINHELP";
const char BUTTON_BOX_WIN_CLASS_NAME[] = "WHButtonBox";
-const char TEXT_WIN_CLASS_NAME[] = "WHText";
const char SHADOW_WIN_CLASS_NAME[] = "WHShadow";
const char HISTORY_WIN_CLASS_NAME[] = "WHHistory";
const char STRING_BUTTON[] = "BUTTON";
diff --git a/programs/winhelp/winhelp.c b/programs/winhelp/winhelp.c
index 840fb8a..f628ccf 100644
--- a/programs/winhelp/winhelp.c
+++ b/programs/winhelp/winhelp.c
@@ -3,7 +3,7 @@
*
* Copyright 1996 Ulrich Schmid <uschmid at mail.hh.provi.de>
* 2002 Sylvain Petreolle <spetreolle at yahoo.fr>
- * 2002 Eric Pouech <eric.pouech at wanadoo.fr>
+ * 2002-2008 Eric Pouech <eric.pouech at wanadoo.fr>
* 2004 Ken Belleau <jamez at ivic.qc.ca>
*
* This library is free software; you can redistribute it and/or
@@ -35,6 +35,7 @@
#include "winhelp.h"
#include "winhelp_res.h"
#include "shellapi.h"
+#include "richedit.h"
#include "wine/debug.h"
@@ -42,21 +43,18 @@ WINE_DEFAULT_DEBUG_CHANNEL(winhelp);
static BOOL WINHELP_RegisterWinClasses(void);
static LRESULT CALLBACK WINHELP_MainWndProc(HWND, UINT, WPARAM, LPARAM);
-static LRESULT CALLBACK WINHELP_TextWndProc(HWND, UINT, WPARAM, LPARAM);
static LRESULT CALLBACK WINHELP_ButtonBoxWndProc(HWND, UINT, WPARAM, LPARAM);
static LRESULT CALLBACK WINHELP_ButtonWndProc(HWND, UINT, WPARAM, LPARAM);
static LRESULT CALLBACK WINHELP_HistoryWndProc(HWND, UINT, WPARAM, LPARAM);
static LRESULT CALLBACK WINHELP_ShadowWndProc(HWND, UINT, WPARAM, LPARAM);
static void WINHELP_CheckPopup(UINT);
-static BOOL WINHELP_SplitLines(HWND hWnd, LPSIZE);
static void WINHELP_InitFonts(HWND hWnd);
-static void WINHELP_DeleteLines(WINHELP_WINDOW*);
static void WINHELP_DeleteWindow(WINHELP_WINDOW*);
-static void WINHELP_SetupText(HWND hWnd);
-static WINHELP_LINE_PART* WINHELP_IsOverLink(WINHELP_WINDOW*, WPARAM, LPARAM);
WINHELP_GLOBALS Globals = {3, NULL, NULL, 0, TRUE, NULL, NULL, NULL, NULL};
+#define CTL_ID_BUTTON 0x700
+#define CTL_ID_TEXT 0x701
/***********************************************************************
*
@@ -184,42 +182,11 @@ HLPFILE_WINDOWINFO* WINHELP_GetWindowInfo(HLPFILE* hlpfile, LPCSTR name)
mwi.origin.x = mwi.origin.y = mwi.size.cx = mwi.size.cy = CW_USEDEFAULT;
mwi.style = SW_SHOW;
mwi.win_style = WS_OVERLAPPEDWINDOW;
- mwi.sr_color = mwi.sr_color = 0xFFFFFF;
+ mwi.sr_color = mwi.nsr_color = 0xFFFFFF;
}
return &mwi;
}
-/******************************************************************
- * HLPFILE_GetPopupWindowInfo
- *
- *
- */
-static HLPFILE_WINDOWINFO* WINHELP_GetPopupWindowInfo(HLPFILE* hlpfile, HWND hParentWnd, POINT* mouse)
-{
- static HLPFILE_WINDOWINFO wi;
-
- RECT parent_rect;
-
- wi.type[0] = wi.name[0] = wi.caption[0] = '\0';
-
- /* Calculate horizontal size and position of a popup window */
- GetWindowRect(hParentWnd, &parent_rect);
- wi.size.cx = (parent_rect.right - parent_rect.left) / 2;
- wi.size.cy = 10; /* need a non null value, so that border are taken into account while computing */
-
- wi.origin = *mouse;
- ClientToScreen(hParentWnd, &wi.origin);
- wi.origin.x -= wi.size.cx / 2;
- wi.origin.x = min(wi.origin.x, GetSystemMetrics(SM_CXSCREEN) - wi.size.cx);
- wi.origin.x = max(wi.origin.x, 0);
-
- wi.style = SW_SHOW;
- wi.win_style = WS_POPUP | WS_BORDER;
- wi.sr_color = wi.sr_color = 0xFFFFFF;
-
- return &wi;
-}
-
/***********************************************************************
*
* WinMain
@@ -235,6 +202,8 @@ int PASCAL WinMain(HINSTANCE hInstance, HINSTANCE prev, LPSTR cmdline, int show)
Globals.hInstance = hInstance;
+ LoadLibrary("riched20.dll");
+
/* Get options */
while (*cmdline && (*cmdline == ' ' || *cmdline == '-'))
{
@@ -295,6 +264,7 @@ int PASCAL WinMain(HINSTANCE hInstance, HINSTANCE prev, LPSTR cmdline, int show)
if (!hlpfile) return 0;
}
else hlpfile = NULL;
+
WINHELP_CreateHelpWindowByHash(hlpfile, lHash,
WINHELP_GetWindowInfo(hlpfile, wndname), show);
@@ -317,7 +287,7 @@ int PASCAL WinMain(HINSTANCE hInstance, HINSTANCE prev, LPSTR cmdline, int show)
*/
static BOOL WINHELP_RegisterWinClasses(void)
{
- WNDCLASS class_main, class_button_box, class_text, class_shadow, class_history;
+ WNDCLASS class_main, class_button_box, class_shadow, class_history;
class_main.style = CS_HREDRAW | CS_VREDRAW;
class_main.lpfnWndProc = WINHELP_MainWndProc;
@@ -335,11 +305,6 @@ static BOOL WINHELP_RegisterWinClasses(void)
class_button_box.hbrBackground = (HBRUSH)(COLOR_BTNFACE+1);
class_button_box.lpszClassName = BUTTON_BOX_WIN_CLASS_NAME;
- class_text = class_main;
- class_text.lpfnWndProc = WINHELP_TextWndProc;
- class_text.hbrBackground = 0;
- class_text.lpszClassName = TEXT_WIN_CLASS_NAME;
-
class_shadow = class_main;
class_shadow.lpfnWndProc = WINHELP_ShadowWndProc;
class_shadow.hbrBackground = (HBRUSH)(COLOR_3DDKSHADOW+1);
@@ -351,7 +316,6 @@ static BOOL WINHELP_RegisterWinClasses(void)
return (RegisterClass(&class_main) &&
RegisterClass(&class_button_box) &&
- RegisterClass(&class_text) &&
RegisterClass(&class_shadow) &&
RegisterClass(&class_history));
}
@@ -464,11 +428,9 @@ static BOOL WINHELP_ReuseWindow(WINHELP_WINDOW* win, WINHELP_WINDOW* oldwin,
win->hTextWnd = oldwin->hTextWnd;
win->hHistoryWnd = oldwin->hHistoryWnd;
oldwin->hMainWnd = oldwin->hButtonBoxWnd = oldwin->hTextWnd = oldwin->hHistoryWnd = 0;
- win->hBrush = CreateSolidBrush(win->info->sr_color);
SetWindowLong(win->hMainWnd, 0, (LONG)win);
SetWindowLong(win->hButtonBoxWnd, 0, (LONG)win);
- SetWindowLong(win->hTextWnd, 0, (LONG)win);
SetWindowLong(win->hHistoryWnd, 0, (LONG)win);
WINHELP_InitFonts(win->hMainWnd);
@@ -476,7 +438,6 @@ static BOOL WINHELP_ReuseWindow(WINHELP_WINDOW* win, WINHELP_WINDOW* oldwin,
if (page)
SetWindowText(win->hMainWnd, page->file->lpszTitle);
- WINHELP_SetupText(win->hTextWnd);
InvalidateRect(win->hTextWnd, NULL, TRUE);
SendMessage(win->hMainWnd, WM_USER, 0, 0);
ShowWindow(win->hMainWnd, nCmdShow);
@@ -555,7 +516,7 @@ BOOL WINHELP_CreateHelpWindow(HLPFILE_PAGE* page, HLPFILE_WINDOWINFO* wi,
DWORD ex_style;
bPrimary = !lstrcmpi(wi->name, "main");
- bPopup = wi->win_style & WS_POPUP;
+ bPopup = !bPrimary && (wi->win_style & WS_POPUP);
/* Initialize WINHELP_WINDOW struct */
win = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
@@ -627,12 +588,13 @@ BOOL WINHELP_CreateHelpWindow(HLPFILE_PAGE* page, HLPFILE_WINDOWINFO* wi,
ex_style = 0;
if (bPopup) ex_style = WS_EX_TOOLWINDOW;
- hWnd = CreateWindowEx(ex_style, bPopup ? TEXT_WIN_CLASS_NAME : MAIN_WIN_CLASS_NAME,
- wi->caption,
+ 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);
+ if (bPopup) Globals.hPopupWnd = hWnd;
ShowWindow(hWnd, nCmdShow);
UpdateWindow(hWnd);
@@ -693,7 +655,7 @@ static LRESULT CALLBACK WINHELP_MainWndProc(HWND hWnd, UINT msg, WPARAM wParam,
WINHELP_WINDOW *win;
WINHELP_BUTTON *button;
RECT rect, button_box_rect;
- INT text_top, curPos, min, max, dy, keyDelta;
+ INT text_top;
WINHELP_CheckPopup(msg);
@@ -709,11 +671,13 @@ static LRESULT CALLBACK WINHELP_MainWndProc(HWND hWnd, UINT msg, WPARAM wParam,
win = (WINHELP_WINDOW*) GetWindowLong(hWnd, 0);
/* Create button box and text Window */
- CreateWindow(BUTTON_BOX_WIN_CLASS_NAME, "", WS_CHILD | WS_VISIBLE,
- 0, 0, 0, 0, hWnd, 0, Globals.hInstance, win);
+ if (!(GetWindowLong(hWnd, GWL_STYLE) & WS_POPUP))
+ CreateWindow(BUTTON_BOX_WIN_CLASS_NAME, "", WS_CHILD | WS_VISIBLE,
+ 0, 0, 0, 0, hWnd, (HMENU)CTL_ID_BUTTON, Globals.hInstance, win);
- CreateWindow(TEXT_WIN_CLASS_NAME, "", WS_CHILD | WS_VISIBLE,
- 0, 0, 0, 0, hWnd, 0, Globals.hInstance, win);
+ win->hTextWnd = CreateWindow(RICHEDIT_CLASS, NULL,
+ ES_MULTILINE | ES_READONLY | WS_CHILD | WS_HSCROLL | WS_VSCROLL | WS_VISIBLE,
+ 0, 0, 0, 0, hWnd, (HMENU)CTL_ID_TEXT, Globals.hInstance, NULL);
/* Fall through */
case WM_USER:
@@ -766,7 +730,7 @@ static LRESULT CALLBACK WINHELP_MainWndProc(HWND hWnd, UINT msg, WPARAM wParam,
if (wParam == button->wParam) break;
if (button)
MACRO_ExecuteMacro(button->lpszMacro);
- else
+ else if (!HIWORD(wParam))
WINHELP_MessageBoxIDS(STID_NOT_IMPLEMENTED, 0x121, MB_OK);
break;
}
@@ -776,50 +740,32 @@ static LRESULT CALLBACK WINHELP_MainWndProc(HWND hWnd, UINT msg, WPARAM wParam,
break;
case WM_COPYDATA:
return WINHELP_HandleCommand((HWND)wParam, lParam);
-
case WM_KEYDOWN:
- keyDelta = 0;
-
- switch (wParam)
+ if (wParam == VK_ESCAPE)
{
- case VK_UP:
- case VK_DOWN:
- keyDelta = GetSystemMetrics(SM_CXVSCROLL);
- if (wParam == VK_UP)
- keyDelta = -keyDelta;
+ MACRO_Exit();
+ return 0;
+ }
+ break;
+ case WM_NCDESTROY:
+ {
+ BOOL bExit;
- case VK_PRIOR:
- case VK_NEXT:
- win = (WINHELP_WINDOW*) GetWindowLong(hWnd, 0);
- curPos = GetScrollPos(win->hTextWnd, SB_VERT);
- GetScrollRange(win->hTextWnd, SB_VERT, &min, &max);
-
- if (keyDelta == 0)
- {
- GetClientRect(win->hTextWnd, &rect);
- keyDelta = (rect.bottom - rect.top) / 2;
- if (wParam == VK_PRIOR)
- keyDelta = -keyDelta;
- }
+ win = (WINHELP_WINDOW*) GetWindowLong(hWnd, 0);
- curPos += keyDelta;
- if (curPos > max)
- curPos = max;
- else if (curPos < min)
- curPos = min;
+ if (hWnd == Globals.hPopupWnd) Globals.hPopupWnd = 0;
- dy = GetScrollPos(win->hTextWnd, SB_VERT) - curPos;
- SetScrollPos(win->hTextWnd, SB_VERT, curPos, TRUE);
- ScrollWindow(win->hTextWnd, 0, dy, NULL, NULL);
- UpdateWindow(win->hTextWnd);
- return 0;
+ bExit = (Globals.wVersion >= 4 && !lstrcmpi(win->lpszName, "main"));
- case VK_ESCAPE:
- MACRO_Exit();
- return 0;
- }
+ WINHELP_DeleteWindow(win);
+
+ if (bExit) MACRO_Exit();
+
+ if (!Globals.win_list)
+ PostQuitMessage(0);
break;
}
+ }
return DefWindowProc(hWnd, msg, wParam, lParam);
}
@@ -934,338 +880,6 @@ static LRESULT CALLBACK WINHELP_ButtonWndProc(HWND hWnd, UINT msg, WPARAM wParam
return CallWindowProc(Globals.button_proc, hWnd, msg, wParam, lParam);
}
-/***********************************************************************
- *
- * WINHELP_TextWndProc
- */
-static LRESULT CALLBACK WINHELP_TextWndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
-{
- WINHELP_WINDOW *win;
- WINHELP_LINE *line;
- WINHELP_LINE_PART *part;
- WINDOWPOS *winpos;
- PAINTSTRUCT ps;
- HDC hDc;
- POINT mouse;
- INT scroll_pos;
- HWND hPopupWnd;
- BOOL bExit;
-
- if (msg != WM_LBUTTONDOWN)
- WINHELP_CheckPopup(msg);
-
- switch (msg)
- {
- case WM_NCCREATE:
- win = (WINHELP_WINDOW*) ((LPCREATESTRUCT) lParam)->lpCreateParams;
- SetWindowLong(hWnd, 0, (LONG) win);
- win->hTextWnd = hWnd;
- win->hBrush = CreateSolidBrush(win->info->sr_color);
- if (win->info->win_style & WS_POPUP) Globals.hPopupWnd = win->hMainWnd = hWnd;
- WINHELP_InitFonts(hWnd);
- break;
-
- case WM_CREATE:
- win = (WINHELP_WINDOW*) GetWindowLong(hWnd, 0);
-
- /* Calculate vertical size and position of a popup window */
- if (win->info->win_style & WS_POPUP)
- {
- POINT origin;
- RECT old_window_rect;
- RECT old_client_rect;
- SIZE old_window_size;
- SIZE old_client_size;
- SIZE new_client_size;
- SIZE new_window_size;
-
- GetWindowRect(hWnd, &old_window_rect);
- origin.x = old_window_rect.left;
- origin.y = old_window_rect.top;
- old_window_size.cx = old_window_rect.right - old_window_rect.left;
- old_window_size.cy = old_window_rect.bottom - old_window_rect.top;
-
- GetClientRect(hWnd, &old_client_rect);
- old_client_size.cx = old_client_rect.right - old_client_rect.left;
- old_client_size.cy = old_client_rect.bottom - old_client_rect.top;
-
- new_client_size = old_client_size;
- WINHELP_SplitLines(hWnd, &new_client_size);
-
- if (origin.y + POPUP_YDISTANCE + new_client_size.cy <= GetSystemMetrics(SM_CYSCREEN))
- origin.y += POPUP_YDISTANCE;
- else
- origin.y -= POPUP_YDISTANCE + new_client_size.cy;
-
- new_window_size.cx = old_window_size.cx - old_client_size.cx + new_client_size.cx;
- new_window_size.cy = old_window_size.cy - old_client_size.cy + new_client_size.cy;
-
- win->hShadowWnd =
- CreateWindowEx(WS_EX_TOOLWINDOW, SHADOW_WIN_CLASS_NAME, "", WS_POPUP,
- origin.x + SHADOW_DX, origin.y + SHADOW_DY,
- new_window_size.cx, new_window_size.cy,
- 0, 0, Globals.hInstance, 0);
-
- SetWindowPos(hWnd, HWND_TOP, origin.x, origin.y,
- new_window_size.cx, new_window_size.cy,
- 0);
- SetWindowPos(win->hShadowWnd, hWnd, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE | SWP_NOACTIVATE);
- ShowWindow(win->hShadowWnd, SW_NORMAL);
- SetActiveWindow(hWnd);
- }
- break;
-
- case WM_WINDOWPOSCHANGED:
- winpos = (WINDOWPOS*) lParam;
-
- if (!(winpos->flags & SWP_NOSIZE)) WINHELP_SetupText(hWnd);
- break;
-
- case WM_MOUSEWHEEL:
- {
- int wheelDelta = 0;
- UINT scrollLines = 3;
- int curPos = GetScrollPos(hWnd, SB_VERT);
- int min, max;
-
- GetScrollRange(hWnd, SB_VERT, &min, &max);
-
- SystemParametersInfo(SPI_GETWHEELSCROLLLINES,0, &scrollLines, 0);
- if (wParam & (MK_SHIFT | MK_CONTROL))
- return DefWindowProc(hWnd, msg, wParam, lParam);
- wheelDelta -= GET_WHEEL_DELTA_WPARAM(wParam);
- if (abs(wheelDelta) >= WHEEL_DELTA && scrollLines) {
- int dy;
-
- curPos += wheelDelta;
- if (curPos > max)
- curPos = max;
- else if (curPos < min)
- curPos = min;
-
- dy = GetScrollPos(hWnd, SB_VERT) - curPos;
- SetScrollPos(hWnd, SB_VERT, curPos, TRUE);
- ScrollWindow(hWnd, 0, dy, NULL, NULL);
- UpdateWindow(hWnd);
- }
- }
- break;
-
- case WM_VSCROLL:
- {
- BOOL update = TRUE;
- RECT rect;
- INT Min, Max;
- INT CurPos = GetScrollPos(hWnd, SB_VERT);
- INT dy;
-
- GetScrollRange(hWnd, SB_VERT, &Min, &Max);
- GetClientRect(hWnd, &rect);
-
- switch (wParam & 0xffff)
- {
- case SB_THUMBTRACK:
- case SB_THUMBPOSITION: CurPos = wParam >> 16; break;
- case SB_TOP: CurPos = Min; break;
- case SB_BOTTOM: CurPos = Max; break;
- case SB_PAGEUP: CurPos -= (rect.bottom - rect.top) / 2; break;
- case SB_PAGEDOWN: CurPos += (rect.bottom - rect.top) / 2; break;
- case SB_LINEUP: CurPos -= GetSystemMetrics(SM_CXVSCROLL); break;
- case SB_LINEDOWN: CurPos += GetSystemMetrics(SM_CXVSCROLL); break;
- default: update = FALSE;
- }
- if (update)
- {
- if (CurPos > Max)
- CurPos = Max;
- else if (CurPos < Min)
- CurPos = Min;
- dy = GetScrollPos(hWnd, SB_VERT) - CurPos;
- SetScrollPos(hWnd, SB_VERT, CurPos, TRUE);
- ScrollWindow(hWnd, 0, dy, NULL, NULL);
- UpdateWindow(hWnd);
- }
- }
- break;
-
- case WM_PAINT:
- hDc = BeginPaint(hWnd, &ps);
- win = (WINHELP_WINDOW*) GetWindowLong(hWnd, 0);
- scroll_pos = GetScrollPos(hWnd, SB_VERT);
-
- /* No DPtoLP needed - MM_TEXT map mode */
- if (ps.fErase) FillRect(hDc, &ps.rcPaint, win->hBrush);
- for (line = win->first_line; line; line = line->next)
- {
- for (part = &line->first_part; part; part = part->next)
- {
- switch (part->cookie)
- {
- case hlp_line_part_text:
- SelectObject(hDc, part->u.text.hFont);
- SetTextColor(hDc, part->u.text.color);
- SetBkColor(hDc, win->info->sr_color);
- TextOut(hDc, part->rect.left, part->rect.top - scroll_pos,
- part->u.text.lpsText, part->u.text.wTextLen);
- if (part->u.text.wUnderline)
- {
- HPEN hPen;
-
- switch (part->u.text.wUnderline)
- {
- case 1: /* simple */
- case 2: /* double */
- hPen = CreatePen(PS_SOLID, 1, part->u.text.color);
- break;
- case 3: /* dotted */
- hPen = CreatePen(PS_DOT, 1, part->u.text.color);
- break;
- default:
- WINE_FIXME("Unknow underline type\n");
- continue;
- }
-
- SelectObject(hDc, hPen);
- MoveToEx(hDc, part->rect.left, part->rect.bottom - scroll_pos - 1, NULL);
- LineTo(hDc, part->rect.right, part->rect.bottom - scroll_pos - 1);
- if (part->u.text.wUnderline == 2)
- {
- MoveToEx(hDc, part->rect.left, part->rect.bottom - scroll_pos + 1, NULL);
- LineTo(hDc, part->rect.right, part->rect.bottom - scroll_pos + 1);
- }
- DeleteObject(hPen);
- }
- break;
- case hlp_line_part_bitmap:
- {
- HDC hMemDC;
-
- hMemDC = CreateCompatibleDC(hDc);
- SelectObject(hMemDC, part->u.bitmap.hBitmap);
- BitBlt(hDc, part->rect.left, part->rect.top - scroll_pos,
- part->rect.right - part->rect.left, part->rect.bottom - part->rect.top,
- hMemDC, 0, 0, SRCCOPY);
- DeleteDC(hMemDC);
- }
- break;
- case hlp_line_part_metafile:
- {
- HDC hMemDC;
- HBITMAP hBitmap;
- SIZE sz;
- RECT rc;
-
- sz.cx = part->rect.right - part->rect.left;
- sz.cy = part->rect.bottom - part->rect.top;
- hMemDC = CreateCompatibleDC(hDc);
- hBitmap = CreateCompatibleBitmap(hDc, sz.cx, sz.cy);
- SelectObject(hMemDC, hBitmap);
- SelectObject(hMemDC, win->hBrush);
- rc.left = 0;
- rc.top = 0;
- rc.right = sz.cx;
- rc.bottom = sz.cy;
- FillRect(hMemDC, &rc, win->hBrush);
- SetMapMode(hMemDC, part->u.metafile.mm);
- SetWindowExtEx(hMemDC, sz.cx, sz.cy, 0);
- SetViewportExtEx(hMemDC, sz.cx, sz.cy, 0);
- SetWindowOrgEx(hMemDC, 0, 0, 0);
- SetViewportOrgEx(hMemDC, 0, 0, 0);
- PlayMetaFile(hMemDC, part->u.metafile.hMetaFile);
- SetMapMode(hMemDC, MM_TEXT);
- SetWindowOrgEx(hMemDC, 0, 0, 0);
- SetViewportOrgEx(hMemDC, 0, 0, 0);
- BitBlt(hDc, part->rect.left, part->rect.top - scroll_pos,
- sz.cx, sz.cy, hMemDC, 0, 0, SRCCOPY);
- DeleteDC(hMemDC);
- DeleteObject(hBitmap);
- }
- break;
- }
- }
- }
-
- EndPaint(hWnd, &ps);
- break;
-
- case WM_MOUSEMOVE:
- win = (WINHELP_WINDOW*) GetWindowLong(hWnd, 0);
-
- if (WINHELP_IsOverLink(win, wParam, lParam))
- SetCursor(win->hHandCur); /* set to hand pointer cursor to indicate a link */
- else
- SetCursor(win->hArrowCur); /* set to hand pointer cursor to indicate a link */
-
- break;
-
- case WM_LBUTTONDOWN:
- win = (WINHELP_WINDOW*) GetWindowLong(hWnd, 0);
-
- hPopupWnd = Globals.hPopupWnd;
- Globals.hPopupWnd = 0;
-
- part = WINHELP_IsOverLink(win, wParam, lParam);
- if (part)
- {
- HLPFILE* hlpfile;
- HLPFILE_WINDOWINFO* wi;
-
- mouse.x = (short)LOWORD(lParam);
- mouse.y = (short)HIWORD(lParam);
-
- if (part->link) switch (part->link->cookie)
- {
- case hlp_link_link:
- hlpfile = WINHELP_LookupHelpFile(part->link->lpszString);
- if (part->link->window == -1)
- wi = win->info;
- else if (part->link->window < hlpfile->numWindows)
- wi = &hlpfile->windows[part->link->window];
- else
- {
- WINE_WARN("link to window %d/%d\n", part->link->window, hlpfile->numWindows);
- break;
- }
- WINHELP_CreateHelpWindowByHash(hlpfile, part->link->lHash, wi,
- SW_NORMAL);
- break;
- case hlp_link_popup:
- hlpfile = WINHELP_LookupHelpFile(part->link->lpszString);
- if (hlpfile) WINHELP_CreateHelpWindowByHash(hlpfile, part->link->lHash,
- WINHELP_GetPopupWindowInfo(hlpfile, hWnd, &mouse),
- SW_NORMAL);
- break;
- case hlp_link_macro:
- MACRO_ExecuteMacro(part->link->lpszString);
- break;
- default:
- WINE_FIXME("Unknown link cookie %d\n", part->link->cookie);
- }
- }
-
- if (hPopupWnd)
- DestroyWindow(hPopupWnd);
- break;
-
- case WM_NCDESTROY:
- win = (WINHELP_WINDOW*) GetWindowLong(hWnd, 0);
-
- if (hWnd == Globals.hPopupWnd) Globals.hPopupWnd = 0;
-
- bExit = (Globals.wVersion >= 4 && !lstrcmpi(win->lpszName, "main"));
-
- WINHELP_DeleteWindow(win);
-
- if (bExit) MACRO_Exit();
-
- if (!Globals.win_list)
- PostQuitMessage(0);
- break;
- }
-
- return DefWindowProc(hWnd, msg, wParam, lParam);
-}
-
/******************************************************************
* WINHELP_HistoryWndProc
*
@@ -1344,417 +958,6 @@ static LRESULT CALLBACK WINHELP_ShadowWndProc(HWND hWnd, UINT msg, WPARAM wParam
/***********************************************************************
*
- * SetupText
- */
-static void WINHELP_SetupText(HWND hWnd)
-{
- HDC hDc = GetDC(hWnd);
- RECT rect;
- SIZE newsize;
-
- ShowScrollBar(hWnd, SB_VERT, FALSE);
- if (!WINHELP_SplitLines(hWnd, NULL))
- {
- ShowScrollBar(hWnd, SB_VERT, TRUE);
- GetClientRect(hWnd, &rect);
-
- WINHELP_SplitLines(hWnd, &newsize);
- SetScrollRange(hWnd, SB_VERT, 0, rect.top + newsize.cy - rect.bottom, TRUE);
- }
- else
- {
- SetScrollPos(hWnd, SB_VERT, 0, FALSE);
- SetScrollRange(hWnd, SB_VERT, 0, 0, FALSE);
- }
-
- ReleaseDC(hWnd, hDc);
-}
-
-/***********************************************************************
- *
- * WINHELP_AppendText
- */
-static BOOL WINHELP_AppendText(WINHELP_LINE ***linep, WINHELP_LINE_PART ***partp,
- LPSIZE space, LPSIZE textsize,
- INT *line_ascent, INT ascent,
- LPCSTR text, UINT textlen,
- HFONT font, COLORREF color, HLPFILE_LINK *link,
- unsigned underline)
-{
- WINHELP_LINE *line;
- WINHELP_LINE_PART *part;
- LPSTR ptr;
-
- if (!*partp) /* New line */
- {
- *line_ascent = ascent;
-
- line = HeapAlloc(GetProcessHeap(), 0,
- sizeof(WINHELP_LINE) + textlen);
- if (!line) return FALSE;
-
- line->next = 0;
- part = &line->first_part;
- ptr = (char*)line + sizeof(WINHELP_LINE);
-
- line->rect.top = (**linep ? (**linep)->rect.bottom : 0) + space->cy;
- line->rect.bottom = line->rect.top;
- line->rect.left = space->cx;
- line->rect.right = space->cx;
-
- if (**linep) *linep = &(**linep)->next;
- **linep = line;
- space->cy = 0;
- }
- else /* Same line */
- {
- line = **linep;
-
- if (*line_ascent < ascent)
- {
- WINHELP_LINE_PART *p;
- for (p = &line->first_part; p; p = p->next)
- {
- p->rect.top += ascent - *line_ascent;
- p->rect.bottom += ascent - *line_ascent;
- }
- line->rect.bottom += ascent - *line_ascent;
- *line_ascent = ascent;
- }
-
- part = HeapAlloc(GetProcessHeap(), 0,
- sizeof(WINHELP_LINE_PART) + textlen);
- if (!part) return FALSE;
- **partp = part;
- ptr = (char*)part + sizeof(WINHELP_LINE_PART);
- }
-
- memcpy(ptr, text, textlen);
- part->cookie = hlp_line_part_text;
- part->rect.left = line->rect.right + (*partp ? space->cx : 0);
- part->rect.right = part->rect.left + textsize->cx;
- line->rect.right = part->rect.right;
- part->rect.top =
- ((*partp) ? line->rect.top : line->rect.bottom) + *line_ascent - ascent;
- part->rect.bottom = part->rect.top + textsize->cy;
- line->rect.bottom = max(line->rect.bottom, part->rect.bottom);
- part->u.text.lpsText = ptr;
- part->u.text.wTextLen = textlen;
- part->u.text.hFont = font;
- part->u.text.color = color;
- part->u.text.wUnderline = underline;
-
- WINE_TRACE("Appended text '%*.*s'[%d] @ (%d,%d-%d,%d)\n",
- part->u.text.wTextLen,
- part->u.text.wTextLen,
- part->u.text.lpsText,
- part->u.text.wTextLen,
- part->rect.left, part->rect.top, part->rect.right, part->rect.bottom);
-
- part->link = link;
- if (link) link->wRefCount++;
-
- part->next = 0;
- *partp = &part->next;
-
- space->cx = 0;
-
- return TRUE;
-}
-
-/***********************************************************************
- *
- * WINHELP_AppendGfxObject
- */
-static WINHELP_LINE_PART* WINHELP_AppendGfxObject(WINHELP_LINE ***linep, WINHELP_LINE_PART ***partp,
- LPSIZE space, LPSIZE gfxSize,
- HLPFILE_LINK *link, unsigned pos)
-{
- WINHELP_LINE *line;
- WINHELP_LINE_PART *part;
- LPSTR ptr;
-
- if (!*partp || pos == 1) /* New line */
- {
- line = HeapAlloc(GetProcessHeap(), 0, sizeof(WINHELP_LINE));
- if (!line) return NULL;
-
- line->next = NULL;
- part = &line->first_part;
-
- line->rect.top = (**linep ? (**linep)->rect.bottom : 0) + space->cy;
- line->rect.bottom = line->rect.top;
- line->rect.left = space->cx;
- line->rect.right = space->cx;
-
- if (**linep) *linep = &(**linep)->next;
- **linep = line;
- space->cy = 0;
- ptr = (char*)line + sizeof(WINHELP_LINE);
- }
- else /* Same line */
- {
- if (pos == 2) WINE_FIXME("Left alignment not handled\n");
- line = **linep;
-
- part = HeapAlloc(GetProcessHeap(), 0, sizeof(WINHELP_LINE_PART));
- if (!part) return NULL;
- **partp = part;
- ptr = (char*)part + sizeof(WINHELP_LINE_PART);
- }
-
- /* part->cookie should be set by caller (image or metafile) */
- part->rect.left = line->rect.right + (*partp ? space->cx : 0);
- part->rect.right = part->rect.left + gfxSize->cx;
- line->rect.right = part->rect.right;
- part->rect.top = (*partp) ? line->rect.top : line->rect.bottom;
- part->rect.bottom = part->rect.top + gfxSize->cy;
- line->rect.bottom = max(line->rect.bottom, part->rect.bottom);
-
- WINE_TRACE("Appended gfx @ (%d,%d-%d,%d)\n",
- part->rect.left, part->rect.top, part->rect.right, part->rect.bottom);
-
- part->link = link;
- if (link) link->wRefCount++;
-
- part->next = NULL;
- *partp = &part->next;
-
- space->cx = 0;
-
- return part;
-}
-
-
-/***********************************************************************
- *
- * WINHELP_SplitLines
- */
-static BOOL WINHELP_SplitLines(HWND hWnd, LPSIZE newsize)
-{
- WINHELP_WINDOW *win = (WINHELP_WINDOW*) GetWindowLong(hWnd, 0);
- HLPFILE_PARAGRAPH *p;
- WINHELP_LINE **line = &win->first_line;
- WINHELP_LINE_PART **part = 0;
- INT line_ascent = 0;
- SIZE space;
- RECT rect;
- HDC hDc;
-
- if (newsize) newsize->cx = newsize->cy = 0;
-
- if (!win->page) return TRUE;
-
- WINHELP_DeleteLines(win);
-
- GetClientRect(hWnd, &rect);
-
- rect.top += INTERNAL_BORDER_WIDTH;
- rect.left += INTERNAL_BORDER_WIDTH;
- rect.right -= INTERNAL_BORDER_WIDTH;
- rect.bottom -= INTERNAL_BORDER_WIDTH;
-
- space.cy = rect.top;
- space.cx = rect.left;
-
- hDc = GetDC(hWnd);
-
- for (p = win->page->first_paragraph; p; p = p->next)
- {
- switch (p->cookie)
- {
- case para_normal_text:
- case para_debug_text:
- {
- TEXTMETRIC tm;
- SIZE textsize = {0, 0};
- LPCSTR text = p->u.text.lpszText;
- UINT indent = 0;
- UINT len = strlen(text);
- unsigned underline = 0;
-
- HFONT hFont = 0;
- COLORREF color = RGB(0, 0, 0);
-
- if (p->u.text.wFont < win->page->file->numFonts)
- {
- HLPFILE* hlpfile = win->page->file;
-
- if (!hlpfile->fonts[p->u.text.wFont].hFont)
- hlpfile->fonts[p->u.text.wFont].hFont = CreateFontIndirect(&hlpfile->fonts[p->u.text.wFont].LogFont);
- hFont = hlpfile->fonts[p->u.text.wFont].hFont;
- color = hlpfile->fonts[p->u.text.wFont].color;
- }
- else
- {
- UINT wFont = (p->u.text.wFont < win->fonts_len) ? p->u.text.wFont : 0;
-
- hFont = win->fonts[wFont];
- }
-
- if (p->link && p->link->bClrChange)
- {
- underline = (p->link->cookie == hlp_link_popup) ? 3 : 1;
- color = RGB(0, 0x80, 0);
- }
- if (p->cookie == para_debug_text) color = RGB(0xff, 0, 0);
-
- SelectObject(hDc, hFont);
-
- GetTextMetrics(hDc, &tm);
-
- if (p->u.text.wIndent)
- {
- indent = p->u.text.wIndent * 5 * tm.tmAveCharWidth;
- if (!part)
- space.cx = rect.left + indent - 2 * tm.tmAveCharWidth;
- }
-
- if (p->u.text.wVSpace)
- {
- part = 0;
- space.cx = rect.left + indent;
- space.cy += (p->u.text.wVSpace - 1) * tm.tmHeight;
- }
-
- if (p->u.text.wHSpace)
- {
- space.cx += p->u.text.wHSpace * 2 * tm.tmAveCharWidth;
- }
-
- WINE_TRACE("splitting text %s\n", text);
-
- while (len)
- {
- INT free_width = rect.right - (part ? (*line)->rect.right : rect.left) - space.cx;
- UINT low = 0, curr = len, high = len, textlen = 0;
-
- if (free_width > 0)
- {
- while (1)
- {
- GetTextExtentPoint(hDc, text, curr, &textsize);
-
- if (textsize.cx <= free_width) low = curr;
- else high = curr;
-
- if (high <= low + 1) break;
-
- if (textsize.cx) curr = (curr * free_width) / textsize.cx;
- if (curr <= low) curr = low + 1;
- else if (curr >= high) curr = high - 1;
- }
- textlen = low;
- while (textlen && text[textlen] && text[textlen] != ' ') textlen--;
- }
- if (!part && !textlen) textlen = max(low, 1);
-
- if (free_width <= 0 || !textlen)
- {
- part = 0;
- space.cx = rect.left + indent;
- space.cx = min(space.cx, rect.right - rect.left - 1);
- continue;
- }
-
- WINE_TRACE("\t => %d %*s\n", textlen, textlen, text);
-
- if (!WINHELP_AppendText(&line, &part, &space, &textsize,
- &line_ascent, tm.tmAscent,
- text, textlen, hFont, color, p->link, underline) ||
- (!newsize && (*line)->rect.bottom > rect.bottom))
- {
- ReleaseDC(hWnd, hDc);
- return FALSE;
- }
-
- if (newsize)
- newsize->cx = max(newsize->cx, (*line)->rect.right + INTERNAL_BORDER_WIDTH);
-
- len -= textlen;
- text += textlen;
- if (text[0] == ' ') text++, len--;
- }
- }
- break;
- case para_bitmap:
- case para_metafile:
- {
- SIZE gfxSize;
- INT free_width;
- WINHELP_LINE_PART* ref_part;
-
- if (p->u.gfx.pos & 0x8000)
- {
- space.cx = rect.left;
- if (*line)
- space.cy += (*line)->rect.bottom - (*line)->rect.top;
- part = 0;
- }
-
- if (p->cookie == para_bitmap)
- {
- DIBSECTION dibs;
-
- GetObject(p->u.gfx.u.bmp.hBitmap, sizeof(dibs), &dibs);
- gfxSize.cx = dibs.dsBm.bmWidth;
- gfxSize.cy = dibs.dsBm.bmHeight;
- }
- else
- {
- LPMETAFILEPICT lpmfp = &p->u.gfx.u.mfp;
- if (lpmfp->mm == MM_ANISOTROPIC || lpmfp->mm == MM_ISOTROPIC)
- {
- gfxSize.cx = MulDiv(lpmfp->xExt, GetDeviceCaps(hDc, HORZRES),
- 100*GetDeviceCaps(hDc, HORZSIZE));
- gfxSize.cy = MulDiv(lpmfp->yExt, GetDeviceCaps(hDc, VERTRES),
- 100*GetDeviceCaps(hDc, VERTSIZE));
- }
- else
- {
- gfxSize.cx = lpmfp->xExt;
- gfxSize.cy = lpmfp->yExt;
- }
- }
-
- free_width = rect.right - ((part && *line) ? (*line)->rect.right : rect.left) - space.cx;
- if (free_width <= 0)
- {
- part = NULL;
- space.cx = rect.left;
- space.cx = min(space.cx, rect.right - rect.left - 1);
- }
- ref_part = WINHELP_AppendGfxObject(&line, &part, &space, &gfxSize,
- p->link, p->u.gfx.pos);
- if (!ref_part || (!newsize && (*line)->rect.bottom > rect.bottom))
- {
- return FALSE;
- }
- if (p->cookie == para_bitmap)
- {
- ref_part->cookie = hlp_line_part_bitmap;
- ref_part->u.bitmap.hBitmap = p->u.gfx.u.bmp.hBitmap;
- }
- else
- {
- ref_part->cookie = hlp_line_part_metafile;
- ref_part->u.metafile.hMetaFile = p->u.gfx.u.mfp.hMF;
- ref_part->u.metafile.mm = p->u.gfx.u.mfp.mm;
- }
- }
- break;
- }
- }
-
- if (newsize)
- newsize->cy = (*line)->rect.bottom + INTERNAL_BORDER_WIDTH;
-
- ReleaseDC(hWnd, hDc);
- return TRUE;
-}
-
-/***********************************************************************
- *
* WINHELP_CheckPopup
*/
static void WINHELP_CheckPopup(UINT msg)
@@ -1777,27 +980,6 @@ static void WINHELP_CheckPopup(UINT msg)
/***********************************************************************
*
- * WINHELP_DeleteLines
- */
-static void WINHELP_DeleteLines(WINHELP_WINDOW *win)
-{
- WINHELP_LINE *line, *next_line;
- WINHELP_LINE_PART *part, *next_part;
- for (line = win->first_line; line; line = next_line)
- {
- next_line = line->next;
- for (part = &line->first_part; part; part = next_part)
- {
- next_part = part->next;
- HLPFILE_FreeLink(part->link);
- HeapFree(GetProcessHeap(), 0, part);
- }
- }
- win->first_line = 0;
-}
-
-/***********************************************************************
- *
* WINHELP_DeleteWindow
*/
static void WINHELP_DeleteWindow(WINHELP_WINDOW* win)
@@ -1833,8 +1015,6 @@ static void WINHELP_DeleteWindow(WINHELP_WINDOW* win)
if (win->hShadowWnd) DestroyWindow(win->hShadowWnd);
if (win->hHistoryWnd) DestroyWindow(win->hHistoryWnd);
- DeleteObject(win->hBrush);
-
for (i = 0; i < win->histIndex; i++)
{
HLPFILE_FreeHlpFile(win->history[i]->file);
@@ -1844,7 +1024,6 @@ static void WINHELP_DeleteWindow(WINHELP_WINDOW* win)
HLPFILE_FreeHlpFile(win->back[i]->file);
if (win->page) HLPFILE_FreeHlpFile(win->page->file);
- WINHELP_DeleteLines(win);
HeapFree(GetProcessHeap(), 0, win);
}
@@ -1916,39 +1095,6 @@ INT WINHELP_MessageBoxIDS_s(UINT ids_text, LPCSTR str, UINT ids_title, WORD type
return MessageBox(0, newtext, title, type);
}
-/******************************************************************
- * WINHELP_IsOverLink
- *
- *
- */
-WINHELP_LINE_PART* WINHELP_IsOverLink(WINHELP_WINDOW* win, WPARAM wParam, LPARAM lParam)
-{
- POINT mouse;
- WINHELP_LINE *line;
- WINHELP_LINE_PART *part;
- int scroll_pos = GetScrollPos(win->hTextWnd, SB_VERT);
-
- mouse.x = LOWORD(lParam);
- mouse.y = HIWORD(lParam);
- for (line = win->first_line; line; line = line->next)
- {
- for (part = &line->first_part; part; part = part->next)
- {
- if (part->link &&
- part->link->lpszString &&
- part->rect.left <= mouse.x &&
- part->rect.right >= mouse.x &&
- part->rect.top <= mouse.y + scroll_pos &&
- part->rect.bottom >= mouse.y + scroll_pos)
- {
- return part;
- }
- }
- }
-
- return NULL;
-}
-
/**************************************************************************
* cb_KWBTree
*
diff --git a/programs/winhelp/winhelp.h b/programs/winhelp/winhelp.h
index abe68ea..f1ae31f 100644
--- a/programs/winhelp/winhelp.h
+++ b/programs/winhelp/winhelp.h
@@ -3,7 +3,7 @@
*
* Copyright 1996 Ulrich Schmid
* Copyright 2002 Sylvain Petreolle <spetreolle at yahoo.fr>
- * 2002 Eric Pouech
+ * 2002-2008 Eric Pouech
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@@ -40,42 +40,6 @@
#include "macro.h"
#include "winhelp_res.h"
-typedef struct tagHelpLinePart
-{
- RECT rect;
- enum {hlp_line_part_text, hlp_line_part_bitmap, hlp_line_part_metafile} cookie;
- union
- {
- struct
- {
- LPCSTR lpsText;
- HFONT hFont;
- COLORREF color;
- WORD wTextLen;
- WORD wUnderline; /* 0 None, 1 simple, 2 double, 3 dotted */
- } text;
- struct
- {
- HBITMAP hBitmap;
- } bitmap;
- struct
- {
- HMETAFILE hMetaFile;
- INT mm;
- } metafile;
- } u;
- HLPFILE_LINK* link;
-
- struct tagHelpLinePart *next;
-} WINHELP_LINE_PART;
-
-typedef struct tagHelpLine
-{
- RECT rect;
- WINHELP_LINE_PART first_part;
- struct tagHelpLine* next;
-} WINHELP_LINE;
-
typedef struct tagHelpButton
{
HWND hWnd;
@@ -97,7 +61,6 @@ typedef struct tagWinHelp
WINHELP_BUTTON* first_button;
HLPFILE_PAGE* page;
- WINHELP_LINE* first_line;
HWND hMainWnd;
HWND hButtonBoxWnd;
@@ -111,8 +74,6 @@ typedef struct tagWinHelp
HCURSOR hArrowCur;
HCURSOR hHandCur;
- HBRUSH hBrush;
-
HLPFILE_WINDOWINFO* info;
/* FIXME: for now it's a fixed size */
@@ -183,7 +144,6 @@ HLPFILE_WINDOWINFO* WINHELP_GetWindowInfo(HLPFILE* hlpfile, LPCSTR name);
extern const char MAIN_WIN_CLASS_NAME[];
extern const char BUTTON_BOX_WIN_CLASS_NAME[];
-extern const char TEXT_WIN_CLASS_NAME[];
extern const char SHADOW_WIN_CLASS_NAME[];
extern const char HISTORY_WIN_CLASS_NAME[];
extern const char STRING_BUTTON[];
More information about the wine-patches
mailing list