diff --git a/reactos/base/applications/cmdutils/xcopy/xcopy.c b/reactos/base/applications/cmdutils/xcopy/xcopy.c index 273047c29ff..e89c404b2c2 100644 --- a/reactos/base/applications/cmdutils/xcopy/xcopy.c +++ b/reactos/base/applications/cmdutils/xcopy/xcopy.c @@ -43,6 +43,7 @@ #include #include #include +#include #include "xcopy.h" WINE_DEFAULT_DEBUG_CHANNEL(xcopy); @@ -999,9 +1000,8 @@ int XCOPY_wprintf(const WCHAR *format, ...) { return 0; } - /* Use wvsprintf to store output into unicode buffer */ va_start(parms, format); - len = vswprintf(output_bufW, format, parms); + len = vsnprintfW(output_bufW, MAX_WRITECONSOLE_SIZE/sizeof(WCHAR), format, parms); va_end(parms); /* Try to write as unicode all the time we think its a console */ diff --git a/reactos/base/applications/winhlp32/lex.yy.c b/reactos/base/applications/winhlp32/lex.yy.c index c644d1be831..c91bc9e2b9d 100644 --- a/reactos/base/applications/winhlp32/lex.yy.c +++ b/reactos/base/applications/winhlp32/lex.yy.c @@ -1670,7 +1670,7 @@ static LRESULT CALLBACK MACRO_TestDialogProc(HWND hDlg, UINT msg, WPARAM wParam, void macro_test(void) { WNDPROC lpfnDlg = MakeProcInstance(MACRO_TestDialogProc, Globals.hInstance); - DialogBox(Globals.hInstance, STRING_DIALOG_TEST, Globals.active_win->hMainWnd, lpfnDlg); + DialogBox(Globals.hInstance, STRING_DIALOG_TEST, Globals.active_win->hMainWnd, (DLGPROC)lpfnDlg); FreeProcInstance(lpfnDlg); macro = szTestMacro; } diff --git a/reactos/base/applications/winhlp32/winhelp.c b/reactos/base/applications/winhlp32/winhelp.c index 91f68c297cd..40b5fd8e52a 100644 --- a/reactos/base/applications/winhlp32/winhelp.c +++ b/reactos/base/applications/winhlp32/winhelp.c @@ -46,24 +46,99 @@ WINE_DEFAULT_DEBUG_CHANNEL(winhelp); -static BOOL WINHELP_RegisterWinClasses(void); -static LRESULT CALLBACK WINHELP_MainWndProc(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 BOOL WINHELP_CheckPopup(HWND, UINT, WPARAM, LPARAM, LRESULT*); -static void WINHELP_InitFonts(HWND hWnd); -static void WINHELP_DeleteWindow(WINHELP_WINDOW*); -static void WINHELP_DeleteButtons(WINHELP_WINDOW*); -static void WINHELP_SetupText(HWND hWnd, WINHELP_WINDOW *win, ULONG relative); -static void WINHELP_DeletePageLinks(HLPFILE_PAGE* page); - WINHELP_GLOBALS Globals = {3, NULL, TRUE, NULL, NULL, NULL, NULL, NULL, {{{NULL,NULL}},0}, NULL}; #define CTL_ID_BUTTON 0x700 #define CTL_ID_TEXT 0x701 + +/*********************************************************************** + * + * WINHELP_InitFonts + */ +static void WINHELP_InitFonts(HWND hWnd) +{ + WINHELP_WINDOW *win = (WINHELP_WINDOW*) GetWindowLongPtr(hWnd, 0); + LOGFONT logfontlist[] = { + {-10, 0, 0, 0, 400, 0, 0, 0, DEFAULT_CHARSET, 0, 0, 0, 32, "Helv"}, + {-12, 0, 0, 0, 700, 0, 0, 0, DEFAULT_CHARSET, 0, 0, 0, 32, "Helv"}, + {-12, 0, 0, 0, 700, 0, 0, 0, DEFAULT_CHARSET, 0, 0, 0, 32, "Helv"}, + {-12, 0, 0, 0, 400, 0, 0, 0, DEFAULT_CHARSET, 0, 0, 0, 32, "Helv"}, + {-12, 0, 0, 0, 700, 0, 0, 0, DEFAULT_CHARSET, 0, 0, 0, 32, "Helv"}, + {-10, 0, 0, 0, 700, 0, 0, 0, DEFAULT_CHARSET, 0, 0, 0, 32, "Helv"}, + { -8, 0, 0, 0, 400, 0, 0, 0, DEFAULT_CHARSET, 0, 0, 0, 32, "Helv"}}; +#define FONTS_LEN (sizeof(logfontlist)/sizeof(*logfontlist)) + + static HFONT fonts[FONTS_LEN]; + static BOOL init = 0; + + win->fonts_len = FONTS_LEN; + win->fonts = fonts; + + if (!init) + { + UINT i; + + for (i = 0; i < FONTS_LEN; i++) + { + fonts[i] = CreateFontIndirect(&logfontlist[i]); + } + + init = 1; + } +} + +static DWORD CALLBACK WINHELP_RtfStreamIn(DWORD_PTR cookie, BYTE* buff, + LONG cb, LONG* pcb) +{ + struct RtfData* rd = (struct RtfData*)cookie; + + if (rd->where >= rd->ptr) return 1; + if (rd->where + cb > rd->ptr) + cb = rd->ptr - rd->where; + memcpy(buff, rd->where, cb); + rd->where += cb; + *pcb = cb; + return 0; +} + +static void WINHELP_SetupText(HWND hTextWnd, WINHELP_WINDOW* win, ULONG relative) +{ + /* At first clear area - needed by EM_POSFROMCHAR/EM_SETSCROLLPOS */ + SendMessage(hTextWnd, WM_SETTEXT, 0, (LPARAM)""); + SendMessage(hTextWnd, WM_SETREDRAW, FALSE, 0); + SendMessage(hTextWnd, EM_SETBKGNDCOLOR, 0, (LPARAM)win->info->sr_color); + /* set word-wrap to window size (undocumented) */ + SendMessage(hTextWnd, EM_SETTARGETDEVICE, 0, 0); + if (win->page) + { + struct RtfData rd; + EDITSTREAM es; + unsigned cp = 0; + POINTL ptl; + POINT pt; + + + if (HLPFILE_BrowsePage(win->page, &rd, win->font_scale, relative)) + { + rd.where = rd.data; + es.dwCookie = (DWORD_PTR)&rd; + es.dwError = 0; + es.pfnCallback = WINHELP_RtfStreamIn; + + SendMessageW(hTextWnd, EM_STREAMIN, SF_RTF, (LPARAM)&es); + cp = rd.char_pos_rel; + } + /* FIXME: else leaking potentially the rd.first_link chain */ + HeapFree(GetProcessHeap(), 0, rd.data); + SendMessage(hTextWnd, EM_POSFROMCHAR, (WPARAM)&ptl, cp ? cp - 1 : 0); + pt.x = 0; pt.y = ptl.y; + SendMessage(hTextWnd, EM_SETSCROLLPOS, 0, (LPARAM)&pt); + } + SendMessage(hTextWnd, WM_SETREDRAW, TRUE, 0); + InvalidateRect(hTextWnd, NULL, TRUE); +} + /*********************************************************************** * * WINHELP_GetOpenFileName @@ -115,10 +190,19 @@ BOOL WINHELP_GetOpenFileName(LPSTR lpszFile, int len) return GetOpenFileName(&openfilename); } -static char* WINHELP_GetCaption(WINHELP_WNDPAGE* wpage) +/*********************************************************************** + * + * WINHELP_MessageBoxIDS_s + */ +static INT WINHELP_MessageBoxIDS_s(UINT ids_text, LPCSTR str, UINT ids_title, WORD type) { - if (wpage->wininfo->caption[0]) return wpage->wininfo->caption; - return wpage->page->file->lpszTitle; + CHAR text[MAX_STRING_LEN]; + CHAR newtext[MAX_STRING_LEN + MAX_PATH]; + + LoadString(Globals.hInstance, ids_text, text, sizeof(text)); + wsprintf(newtext, text, str); + + return MessageBox(0, newtext, MAKEINTRESOURCE(ids_title), type); } /*********************************************************************** @@ -238,142 +322,6 @@ static HLPFILE_WINDOWINFO* WINHELP_GetPopupWindowInfo(HLPFILE* hlpfile, return &wi; } -/*********************************************************************** - * - * WinMain - */ -int PASCAL WinMain(HINSTANCE hInstance, HINSTANCE prev, LPSTR cmdline, int show) -{ - MSG msg; - LONG lHash = 0; - HLPFILE* hlpfile; - static CHAR default_wndname[] = "main"; - LPSTR wndname = default_wndname; - WINHELP_DLL* dll; - - Globals.hInstance = hInstance; - - if (LoadLibrary("riched20.dll") == NULL) - return MessageBox(0, MAKEINTRESOURCE(STID_NO_RICHEDIT), - MAKEINTRESOURCE(STID_WHERROR), MB_OK); - - /* Get options */ - while (*cmdline && (*cmdline == ' ' || *cmdline == '-')) - { - CHAR option; - LPCSTR topic_id; - if (*cmdline++ == ' ') continue; - - option = *cmdline; - if (option) cmdline++; - while (*cmdline && *cmdline == ' ') cmdline++; - switch (option) - { - case 'i': - case 'I': - topic_id = cmdline; - while (*cmdline && *cmdline != ' ') cmdline++; - if (*cmdline) *cmdline++ = '\0'; - lHash = HLPFILE_Hash(topic_id); - break; - - case '3': - case '4': - Globals.wVersion = option - '0'; - break; - - case 'x': - show = SW_HIDE; - Globals.isBook = FALSE; - break; - - default: - WINE_FIXME("Unsupported cmd line: %s\n", cmdline); - break; - } - } - - /* Create primary window */ - if (!WINHELP_RegisterWinClasses()) - { - WINE_FIXME("Couldn't register classes\n"); - return 0; - } - - if (*cmdline) - { - char* ptr; - if ((*cmdline == '"') && (ptr = strchr(cmdline+1, '"'))) - { - cmdline++; - *ptr = '\0'; - } - if ((ptr = strchr(cmdline, '>'))) - { - *ptr = '\0'; - wndname = ptr + 1; - } - hlpfile = WINHELP_LookupHelpFile(cmdline); - if (!hlpfile) return 0; - } - else hlpfile = NULL; - WINHELP_OpenHelpWindow(HLPFILE_PageByHash, hlpfile, lHash, - WINHELP_GetWindowInfo(hlpfile, wndname), show); - - /* Message loop */ - while (GetMessage(&msg, 0, 0, 0)) - { - TranslateMessage(&msg); - DispatchMessage(&msg); - } - for (dll = Globals.dlls; dll; dll = dll->next) - { - if (dll->class & DC_INITTERM) dll->handler(DW_TERM, 0, 0); - } - return 0; -} - -/*********************************************************************** - * - * RegisterWinClasses - */ -static BOOL WINHELP_RegisterWinClasses(void) -{ - WNDCLASS class_main, class_button_box, class_shadow, class_history; - - class_main.style = CS_HREDRAW | CS_VREDRAW; - class_main.lpfnWndProc = WINHELP_MainWndProc; - class_main.cbClsExtra = 0; - class_main.cbWndExtra = sizeof(LONG); - class_main.hInstance = Globals.hInstance; - class_main.hIcon = LoadIcon(Globals.hInstance, MAKEINTRESOURCE(IDI_WINHELP)); - class_main.hCursor = LoadCursor(0, IDC_ARROW); - class_main.hbrBackground = (HBRUSH)(COLOR_WINDOW+1); - class_main.lpszMenuName = 0; - class_main.lpszClassName = MAIN_WIN_CLASS_NAME; - - class_button_box = class_main; - class_button_box.lpfnWndProc = WINHELP_ButtonBoxWndProc; - class_button_box.cbWndExtra = 0; - class_button_box.hbrBackground = (HBRUSH)(COLOR_BTNFACE+1); - class_button_box.lpszClassName = BUTTON_BOX_WIN_CLASS_NAME; - - class_shadow = class_main; - class_shadow.lpfnWndProc = WINHELP_ShadowWndProc; - class_shadow.cbWndExtra = 0; - class_shadow.hbrBackground = (HBRUSH)(COLOR_3DDKSHADOW+1); - class_shadow.lpszClassName = SHADOW_WIN_CLASS_NAME; - - class_history = class_main; - class_history.lpfnWndProc = WINHELP_HistoryWndProc; - class_history.lpszClassName = HISTORY_WIN_CLASS_NAME; - - return (RegisterClass(&class_main) && - RegisterClass(&class_button_box) && - RegisterClass(&class_shadow) && - RegisterClass(&class_history)); -} - typedef struct { WORD size; @@ -502,7 +450,104 @@ void WINHELP_LayoutMainWindow(WINHELP_WINDOW* win) } -static void WINHELP_RememberPage(WINHELP_WINDOW* win, WINHELP_WNDPAGE* wpage) +/****************************************************************** + * 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_DeleteBackSet + * + */ +void WINHELP_DeleteBackSet(WINHELP_WINDOW* win) +{ + unsigned int i; + + for (i = 0; i < win->back.index; i++) + { + HLPFILE_FreeHlpFile(win->back.set[i].page->file); + win->back.set[i].page = NULL; + } + win->back.index = 0; +} + +/****************************************************************** + * WINHELP_DeletePageLinks + * + */ +static void WINHELP_DeletePageLinks(HLPFILE_PAGE* page) +{ + HLPFILE_LINK* curr; + HLPFILE_LINK* next; + + for (curr = page->first_link; curr; curr = next) + { + next = curr->next; + HeapFree(GetProcessHeap(), 0, curr); + } +} + +/*********************************************************************** + * + * WINHELP_DeleteWindow + */ +static void WINHELP_DeleteWindow(WINHELP_WINDOW* win) +{ + WINHELP_WINDOW** w; + + for (w = &Globals.win_list; *w; w = &(*w)->next) + { + if (*w == win) + { + *w = win->next; + break; + } + } + + if (Globals.active_win == win) + { + Globals.active_win = Globals.win_list; + if (Globals.win_list) + SetActiveWindow(Globals.win_list->hMainWnd); + } + + if (win == Globals.active_popup) + Globals.active_popup = NULL; + + WINHELP_DeleteButtons(win); + + if (win->page) WINHELP_DeletePageLinks(win->page); + if (win->hShadowWnd) DestroyWindow(win->hShadowWnd); + if (win->hHistoryWnd) DestroyWindow(win->hHistoryWnd); + + DeleteObject(win->hBrush); + + WINHELP_DeleteBackSet(win); + + if (win->page) HLPFILE_FreeHlpFile(win->page->file); + HeapFree(GetProcessHeap(), 0, win); +} + +static char* WINHELP_GetCaption(WINHELP_WNDPAGE* wpage) +{ + if (wpage->wininfo->caption[0]) return wpage->wininfo->caption; + return wpage->page->file->lpszTitle; +} + +static void WINHELP_RememberPage(WINHELP_WINDOW* win, WINHELP_WNDPAGE* wpage) { unsigned num; @@ -826,6 +871,392 @@ static BOOL WINHELP_HandleTextMouse(WINHELP_WINDOW* win, UINT msg, LPARAM lParam return ret; } +/*********************************************************************** + * + * WINHELP_CheckPopup + */ +static BOOL WINHELP_CheckPopup(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam, LRESULT* lret) +{ + HWND hPopup; + + if (!Globals.active_popup) return FALSE; + + switch (msg) + { + case WM_NOTIFY: + { + MSGFILTER* msgf = (MSGFILTER*)lParam; + if (msgf->nmhdr.code == EN_MSGFILTER) + { + if (!WINHELP_CheckPopup(hWnd, msgf->msg, msgf->wParam, msgf->lParam, NULL)) + return FALSE; + if (lret) *lret = 1; + return TRUE; + } + } + break; + case WM_ACTIVATE: + if (wParam != WA_INACTIVE || (HWND)lParam == Globals.active_win->hMainWnd || + (HWND)lParam == Globals.active_popup->hMainWnd || + GetWindow((HWND)lParam, GW_OWNER) == Globals.active_win->hMainWnd) + break; + case WM_LBUTTONUP: + case WM_LBUTTONDOWN: + if (WINHELP_HandleTextMouse(Globals.active_popup, msg, lParam) && msg == WM_LBUTTONDOWN) + return FALSE; + /* fall through */ + case WM_MBUTTONDOWN: + case WM_RBUTTONDOWN: + case WM_NCLBUTTONDOWN: + case WM_NCMBUTTONDOWN: + case WM_NCRBUTTONDOWN: + hPopup = Globals.active_popup->hMainWnd; + Globals.active_popup = NULL; + DestroyWindow(hPopup); + return TRUE; + } + return FALSE; +} + +/*********************************************************************** + * + * WINHELP_ButtonWndProc + */ +static LRESULT CALLBACK WINHELP_ButtonWndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) +{ + if (WINHELP_CheckPopup(hWnd, msg, wParam, lParam, NULL)) return 0; + + if (msg == WM_KEYDOWN) + { + switch (wParam) + { + case VK_UP: + case VK_DOWN: + case VK_PRIOR: + case VK_NEXT: + case VK_ESCAPE: + return SendMessage(GetParent(hWnd), msg, wParam, lParam); + } + } + + return CallWindowProc(Globals.button_proc, hWnd, msg, wParam, lParam); +} + +/*********************************************************************** + * + * WINHELP_ButtonBoxWndProc + */ +static LRESULT CALLBACK WINHELP_ButtonBoxWndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) +{ + WINDOWPOS *winpos; + WINHELP_WINDOW *win; + WINHELP_BUTTON *button; + SIZE button_size; + INT x, y; + + if (WINHELP_CheckPopup(hWnd, msg, wParam, lParam, NULL)) return 0L; + + switch (msg) + { + case WM_WINDOWPOSCHANGING: + winpos = (WINDOWPOS*) lParam; + win = (WINHELP_WINDOW*) GetWindowLongPtr(GetParent(hWnd), 0); + + /* Update buttons */ + button_size.cx = 0; + button_size.cy = 0; + for (button = win->first_button; button; button = button->next) + { + HDC hDc; + SIZE textsize; + if (!button->hWnd) + { + button->hWnd = CreateWindow(STRING_BUTTON, button->lpszName, + WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON, + 0, 0, 0, 0, + hWnd, (HMENU) button->wParam, + Globals.hInstance, 0); + if (button->hWnd) + { + if (Globals.button_proc == NULL) + { + NONCLIENTMETRICSW ncm; + Globals.button_proc = (WNDPROC) GetWindowLongPtr(button->hWnd, GWLP_WNDPROC); + + ncm.cbSize = sizeof(NONCLIENTMETRICSW); + SystemParametersInfoW(SPI_GETNONCLIENTMETRICS, + sizeof(NONCLIENTMETRICSW), &ncm, 0); + Globals.hButtonFont = CreateFontIndirectW(&ncm.lfMenuFont); + } + SetWindowLongPtr(button->hWnd, GWLP_WNDPROC, (LONG_PTR) WINHELP_ButtonWndProc); + if (Globals.hButtonFont) + SendMessage(button->hWnd, WM_SETFONT, (WPARAM)Globals.hButtonFont, TRUE); + } + } + hDc = GetDC(button->hWnd); + GetTextExtentPoint(hDc, button->lpszName, + lstrlen(button->lpszName), &textsize); + ReleaseDC(button->hWnd, hDc); + + button_size.cx = max(button_size.cx, textsize.cx + BUTTON_CX); + button_size.cy = max(button_size.cy, textsize.cy + BUTTON_CY); + } + + x = 0; + y = 0; + for (button = win->first_button; button; button = button->next) + { + SetWindowPos(button->hWnd, HWND_TOP, x, y, button_size.cx, button_size.cy, 0); + + if (x + 2 * button_size.cx <= winpos->cx) + x += button_size.cx; + else + x = 0, y += button_size.cy; + } + winpos->cy = y + (x ? button_size.cy : 0); + break; + + case WM_COMMAND: + SendMessage(GetParent(hWnd), msg, wParam, lParam); + break; + + case WM_KEYDOWN: + switch (wParam) + { + case VK_UP: + case VK_DOWN: + case VK_PRIOR: + case VK_NEXT: + case VK_ESCAPE: + return SendMessage(GetParent(hWnd), msg, wParam, lParam); + } + break; + } + + return DefWindowProc(hWnd, msg, wParam, lParam); +} + +/****************************************************************** + * WINHELP_HistoryWndProc + * + * + */ +static LRESULT CALLBACK WINHELP_HistoryWndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) +{ + WINHELP_WINDOW* win; + PAINTSTRUCT ps; + HDC hDc; + TEXTMETRIC tm; + unsigned int i; + RECT r; + + switch (msg) + { + case WM_NCCREATE: + win = (WINHELP_WINDOW*)((LPCREATESTRUCT)lParam)->lpCreateParams; + SetWindowLongPtr(hWnd, 0, (ULONG_PTR)win); + win->hHistoryWnd = hWnd; + break; + case WM_CREATE: + win = (WINHELP_WINDOW*) GetWindowLongPtr(hWnd, 0); + hDc = GetDC(hWnd); + GetTextMetrics(hDc, &tm); + GetWindowRect(hWnd, &r); + + r.right = r.left + 30 * tm.tmAveCharWidth; + r.bottom = r.top + (sizeof(Globals.history.set) / sizeof(Globals.history.set[0])) * tm.tmHeight; + AdjustWindowRect(&r, GetWindowLong(hWnd, GWL_STYLE), FALSE); + if (r.left < 0) {r.right -= r.left; r.left = 0;} + if (r.top < 0) {r.bottom -= r.top; r.top = 0;} + + MoveWindow(hWnd, r.left, r.top, r.right, r.bottom, TRUE); + ReleaseDC(hWnd, hDc); + break; + case WM_LBUTTONDOWN: + win = (WINHELP_WINDOW*) GetWindowLongPtr(hWnd, 0); + hDc = GetDC(hWnd); + GetTextMetrics(hDc, &tm); + i = HIWORD(lParam) / tm.tmHeight; + if (i < Globals.history.index) + WINHELP_CreateHelpWindow(&Globals.history.set[i], SW_SHOW, TRUE); + ReleaseDC(hWnd, hDc); + break; + case WM_PAINT: + hDc = BeginPaint(hWnd, &ps); + win = (WINHELP_WINDOW*) GetWindowLongPtr(hWnd, 0); + GetTextMetrics(hDc, &tm); + + for (i = 0; i < Globals.history.index; i++) + { + if (Globals.history.set[i].page->file == Globals.active_win->page->file) + { + TextOut(hDc, 0, i * tm.tmHeight, + Globals.history.set[i].page->lpszTitle, + strlen(Globals.history.set[i].page->lpszTitle)); + } + else + { + char buffer[1024]; + const char* ptr1; + const char* ptr2; + unsigned len; + + ptr1 = strrchr(Globals.history.set[i].page->file->lpszPath, '\\'); + if (!ptr1) ptr1 = Globals.history.set[i].page->file->lpszPath; + else ptr1++; + ptr2 = strrchr(ptr1, '.'); + len = ptr2 ? ptr2 - ptr1 : strlen(ptr1); + if (len > sizeof(buffer)) len = sizeof(buffer); + memcpy(buffer, ptr1, len); + if (len < sizeof(buffer)) buffer[len++] = ':'; + strncpy(&buffer[len], Globals.history.set[i].page->lpszTitle, sizeof(buffer) - len); + buffer[sizeof(buffer) - 1] = '\0'; + TextOut(hDc, 0, i * tm.tmHeight, buffer, strlen(buffer)); + } + } + EndPaint(hWnd, &ps); + break; + case WM_DESTROY: + win = (WINHELP_WINDOW*) GetWindowLongPtr(hWnd, 0); + if (hWnd == win->hHistoryWnd) + win->hHistoryWnd = 0; + break; + } + return DefWindowProc(hWnd, msg, wParam, lParam); +} + +/*********************************************************************** + * + * WINHELP_ShadowWndProc + */ +static LRESULT CALLBACK WINHELP_ShadowWndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) +{ + if (WINHELP_CheckPopup(hWnd, msg, wParam, lParam, NULL)) return 0; + return WINHELP_CheckPopup(hWnd, msg, wParam, lParam, NULL) ? 0L : DefWindowProc(hWnd, msg, wParam, lParam); +} + +/************************************************************************** + * cb_KWBTree + * + * HLPFILE_BPTreeCallback enumeration function for '|KWBTREE' internal file. + * + */ +static void cb_KWBTree(void *p, void **next, void *cookie) +{ + HWND hListWnd = (HWND)cookie; + int count; + + WINE_TRACE("Adding '%s' to search list\n", (char *)p); + SendMessage(hListWnd, LB_INSERTSTRING, -1, (LPARAM)p); + count = SendMessage(hListWnd, LB_GETCOUNT, 0, 0); + SendMessage(hListWnd, LB_SETITEMDATA, count-1, (LPARAM)p); + *next = (char*)p + strlen((char*)p) + 7; +} + +struct index_data +{ + HLPFILE* hlpfile; + BOOL jump; + ULONG offset; +}; + +/************************************************************************** + * WINHELP_IndexDlgProc + * + */ +static INT_PTR CALLBACK WINHELP_IndexDlgProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) +{ + static struct index_data* id; + int sel; + + switch (msg) + { + case WM_INITDIALOG: + id = (struct index_data*)((PROPSHEETPAGE*)lParam)->lParam; + HLPFILE_BPTreeEnum(id->hlpfile->kwbtree, cb_KWBTree, + GetDlgItem(hWnd, IDC_INDEXLIST)); + id->jump = FALSE; + id->offset = 1; + return TRUE; + case WM_COMMAND: + switch (HIWORD(wParam)) + { + case LBN_DBLCLK: + if (LOWORD(wParam) == IDC_INDEXLIST) + SendMessage(GetParent(hWnd), PSM_PRESSBUTTON, PSBTN_OK, 0); + break; + } + break; + case WM_NOTIFY: + switch (((NMHDR*)lParam)->code) + { + case PSN_APPLY: + sel = SendDlgItemMessage(hWnd, IDC_INDEXLIST, LB_GETCURSEL, 0, 0); + if (sel != LB_ERR) + { + BYTE *p; + int count; + + p = (BYTE*)SendDlgItemMessage(hWnd, IDC_INDEXLIST, + LB_GETITEMDATA, sel, 0); + count = *(short*)((char *)p + strlen((char *)p) + 1); + if (count > 1) + { + MessageBox(hWnd, "count > 1 not supported yet", "Error", MB_OK | MB_ICONSTOP); + SetWindowLongPtr(hWnd, DWLP_MSGRESULT, PSNRET_INVALID); + return TRUE; + } + id->offset = *(ULONG*)((char *)p + strlen((char *)p) + 3); + id->offset = *(long*)(id->hlpfile->kwdata + id->offset + 9); + if (id->offset == 0xFFFFFFFF) + { + MessageBox(hWnd, "macro keywords not supported yet", "Error", MB_OK | MB_ICONSTOP); + SetWindowLongPtr(hWnd, DWLP_MSGRESULT, PSNRET_INVALID); + return TRUE; + } + id->jump = TRUE; + SetWindowLongPtr(hWnd, DWLP_MSGRESULT, PSNRET_NOERROR); + } + return TRUE; + default: + return FALSE; + } + break; + default: + break; + } + return FALSE; +} + +/************************************************************************** + * WINHELP_SearchDlgProc + * + */ +static INT_PTR CALLBACK WINHELP_SearchDlgProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) +{ + static struct index_data* id; + + switch (msg) + { + case WM_INITDIALOG: + id = (struct index_data*)((PROPSHEETPAGE*)lParam)->lParam; + return TRUE; + case WM_NOTIFY: + switch (((NMHDR*)lParam)->code) + { + case PSN_APPLY: + SetWindowLongPtr(hWnd, DWLP_MSGRESULT, PSNRET_NOERROR); + return TRUE; + default: + return FALSE; + } + break; + default: + break; + } + return FALSE; +} + /*********************************************************************** * * WINHELP_MainWndProc @@ -967,7 +1398,7 @@ static LRESULT CALLBACK WINHELP_MainWndProc(HWND hWnd, UINT msg, WPARAM wParam, GetScrollRange(hTextWnd, SB_VERT, &min, &max); if (keyDelta == 0) - { + { GetClientRect(hTextWnd, &rect); keyDelta = (rect.bottom - rect.top) / 2; if (wParam == VK_PRIOR) @@ -1086,585 +1517,6 @@ static LRESULT CALLBACK WINHELP_MainWndProc(HWND hWnd, UINT msg, WPARAM wParam, return DefWindowProc(hWnd, msg, wParam, lParam); } -static DWORD CALLBACK WINHELP_RtfStreamIn(DWORD_PTR cookie, BYTE* buff, - LONG cb, LONG* pcb) -{ - struct RtfData* rd = (struct RtfData*)cookie; - - if (rd->where >= rd->ptr) return 1; - if (rd->where + cb > rd->ptr) - cb = rd->ptr - rd->where; - memcpy(buff, rd->where, cb); - rd->where += cb; - *pcb = cb; - return 0; -} - -static void WINHELP_SetupText(HWND hTextWnd, WINHELP_WINDOW* win, ULONG relative) -{ - /* At first clear area - needed by EM_POSFROMCHAR/EM_SETSCROLLPOS */ - SendMessage(hTextWnd, WM_SETTEXT, 0, (LPARAM)""); - SendMessage(hTextWnd, WM_SETREDRAW, FALSE, 0); - SendMessage(hTextWnd, EM_SETBKGNDCOLOR, 0, (LPARAM)win->info->sr_color); - /* set word-wrap to window size (undocumented) */ - SendMessage(hTextWnd, EM_SETTARGETDEVICE, 0, 0); - if (win->page) - { - struct RtfData rd; - EDITSTREAM es; - unsigned cp = 0; - POINTL ptl; - POINT pt; - - - if (HLPFILE_BrowsePage(win->page, &rd, win->font_scale, relative)) - { - rd.where = rd.data; - es.dwCookie = (DWORD_PTR)&rd; - es.dwError = 0; - es.pfnCallback = WINHELP_RtfStreamIn; - - SendMessageW(hTextWnd, EM_STREAMIN, SF_RTF, (LPARAM)&es); - cp = rd.char_pos_rel; - } - /* FIXME: else leaking potentially the rd.first_link chain */ - HeapFree(GetProcessHeap(), 0, rd.data); - SendMessage(hTextWnd, EM_POSFROMCHAR, (WPARAM)&ptl, cp ? cp - 1 : 0); - pt.x = 0; pt.y = ptl.y; - SendMessage(hTextWnd, EM_SETSCROLLPOS, 0, (LPARAM)&pt); - } - SendMessage(hTextWnd, WM_SETREDRAW, TRUE, 0); - InvalidateRect(hTextWnd, NULL, TRUE); -} - -/*********************************************************************** - * - * WINHELP_ButtonBoxWndProc - */ -static LRESULT CALLBACK WINHELP_ButtonBoxWndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) -{ - WINDOWPOS *winpos; - WINHELP_WINDOW *win; - WINHELP_BUTTON *button; - SIZE button_size; - INT x, y; - - if (WINHELP_CheckPopup(hWnd, msg, wParam, lParam, NULL)) return 0L; - - switch (msg) - { - case WM_WINDOWPOSCHANGING: - winpos = (WINDOWPOS*) lParam; - win = (WINHELP_WINDOW*) GetWindowLongPtr(GetParent(hWnd), 0); - - /* Update buttons */ - button_size.cx = 0; - button_size.cy = 0; - for (button = win->first_button; button; button = button->next) - { - HDC hDc; - SIZE textsize; - if (!button->hWnd) - { - button->hWnd = CreateWindow(STRING_BUTTON, button->lpszName, - WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON, - 0, 0, 0, 0, - hWnd, (HMENU) button->wParam, - Globals.hInstance, 0); - if (button->hWnd) - { - if (Globals.button_proc == NULL) - { - NONCLIENTMETRICSW ncm; - Globals.button_proc = (WNDPROC) GetWindowLongPtr(button->hWnd, GWLP_WNDPROC); - - ncm.cbSize = sizeof(NONCLIENTMETRICSW); - SystemParametersInfoW(SPI_GETNONCLIENTMETRICS, - sizeof(NONCLIENTMETRICSW), &ncm, 0); - Globals.hButtonFont = CreateFontIndirectW(&ncm.lfMenuFont); - } - SetWindowLongPtr(button->hWnd, GWLP_WNDPROC, (LONG_PTR) WINHELP_ButtonWndProc); - if (Globals.hButtonFont) - SendMessage(button->hWnd, WM_SETFONT, (WPARAM)Globals.hButtonFont, TRUE); - } - } - hDc = GetDC(button->hWnd); - GetTextExtentPoint(hDc, button->lpszName, - lstrlen(button->lpszName), &textsize); - ReleaseDC(button->hWnd, hDc); - - button_size.cx = max(button_size.cx, textsize.cx + BUTTON_CX); - button_size.cy = max(button_size.cy, textsize.cy + BUTTON_CY); - } - - x = 0; - y = 0; - for (button = win->first_button; button; button = button->next) - { - SetWindowPos(button->hWnd, HWND_TOP, x, y, button_size.cx, button_size.cy, 0); - - if (x + 2 * button_size.cx <= winpos->cx) - x += button_size.cx; - else - x = 0, y += button_size.cy; - } - winpos->cy = y + (x ? button_size.cy : 0); - break; - - case WM_COMMAND: - SendMessage(GetParent(hWnd), msg, wParam, lParam); - break; - - case WM_KEYDOWN: - switch (wParam) - { - case VK_UP: - case VK_DOWN: - case VK_PRIOR: - case VK_NEXT: - case VK_ESCAPE: - return SendMessage(GetParent(hWnd), msg, wParam, lParam); - } - break; - } - - return DefWindowProc(hWnd, msg, wParam, lParam); -} - -/*********************************************************************** - * - * WINHELP_ButtonWndProc - */ -static LRESULT CALLBACK WINHELP_ButtonWndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) -{ - if (WINHELP_CheckPopup(hWnd, msg, wParam, lParam, NULL)) return 0; - - if (msg == WM_KEYDOWN) - { - switch (wParam) - { - case VK_UP: - case VK_DOWN: - case VK_PRIOR: - case VK_NEXT: - case VK_ESCAPE: - return SendMessage(GetParent(hWnd), msg, wParam, lParam); - } - } - - return CallWindowProc(Globals.button_proc, hWnd, msg, wParam, lParam); -} - -/****************************************************************** - * WINHELP_HistoryWndProc - * - * - */ -static LRESULT CALLBACK WINHELP_HistoryWndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) -{ - WINHELP_WINDOW* win; - PAINTSTRUCT ps; - HDC hDc; - TEXTMETRIC tm; - unsigned int i; - RECT r; - - switch (msg) - { - case WM_NCCREATE: - win = (WINHELP_WINDOW*)((LPCREATESTRUCT)lParam)->lpCreateParams; - SetWindowLongPtr(hWnd, 0, (ULONG_PTR)win); - win->hHistoryWnd = hWnd; - break; - case WM_CREATE: - win = (WINHELP_WINDOW*) GetWindowLongPtr(hWnd, 0); - hDc = GetDC(hWnd); - GetTextMetrics(hDc, &tm); - GetWindowRect(hWnd, &r); - - r.right = r.left + 30 * tm.tmAveCharWidth; - r.bottom = r.top + (sizeof(Globals.history.set) / sizeof(Globals.history.set[0])) * tm.tmHeight; - AdjustWindowRect(&r, GetWindowLong(hWnd, GWL_STYLE), FALSE); - if (r.left < 0) {r.right -= r.left; r.left = 0;} - if (r.top < 0) {r.bottom -= r.top; r.top = 0;} - - MoveWindow(hWnd, r.left, r.top, r.right, r.bottom, TRUE); - ReleaseDC(hWnd, hDc); - break; - case WM_LBUTTONDOWN: - win = (WINHELP_WINDOW*) GetWindowLongPtr(hWnd, 0); - hDc = GetDC(hWnd); - GetTextMetrics(hDc, &tm); - i = HIWORD(lParam) / tm.tmHeight; - if (i < Globals.history.index) - WINHELP_CreateHelpWindow(&Globals.history.set[i], SW_SHOW, TRUE); - ReleaseDC(hWnd, hDc); - break; - case WM_PAINT: - hDc = BeginPaint(hWnd, &ps); - win = (WINHELP_WINDOW*) GetWindowLongPtr(hWnd, 0); - GetTextMetrics(hDc, &tm); - - for (i = 0; i < Globals.history.index; i++) - { - if (Globals.history.set[i].page->file == Globals.active_win->page->file) - { - TextOut(hDc, 0, i * tm.tmHeight, - Globals.history.set[i].page->lpszTitle, - strlen(Globals.history.set[i].page->lpszTitle)); - } - else - { - char buffer[1024]; - const char* ptr1; - const char* ptr2; - unsigned len; - - ptr1 = strrchr(Globals.history.set[i].page->file->lpszPath, '\\'); - if (!ptr1) ptr1 = Globals.history.set[i].page->file->lpszPath; - else ptr1++; - ptr2 = strrchr(ptr1, '.'); - len = ptr2 ? ptr2 - ptr1 : strlen(ptr1); - if (len > sizeof(buffer)) len = sizeof(buffer); - memcpy(buffer, ptr1, len); - if (len < sizeof(buffer)) buffer[len++] = ':'; - strncpy(&buffer[len], Globals.history.set[i].page->lpszTitle, sizeof(buffer) - len); - buffer[sizeof(buffer) - 1] = '\0'; - TextOut(hDc, 0, i * tm.tmHeight, buffer, strlen(buffer)); - } - } - EndPaint(hWnd, &ps); - break; - case WM_DESTROY: - win = (WINHELP_WINDOW*) GetWindowLongPtr(hWnd, 0); - if (hWnd == win->hHistoryWnd) - win->hHistoryWnd = 0; - break; - } - return DefWindowProc(hWnd, msg, wParam, lParam); -} - -/*********************************************************************** - * - * WINHELP_ShadowWndProc - */ -static LRESULT CALLBACK WINHELP_ShadowWndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) -{ - if (WINHELP_CheckPopup(hWnd, msg, wParam, lParam, NULL)) return 0; - return WINHELP_CheckPopup(hWnd, msg, wParam, lParam, NULL) ? 0L : DefWindowProc(hWnd, msg, wParam, lParam); -} - -/*********************************************************************** - * - * WINHELP_CheckPopup - */ -static BOOL WINHELP_CheckPopup(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam, LRESULT* lret) -{ - HWND hPopup; - - if (!Globals.active_popup) return FALSE; - - switch (msg) - { - case WM_NOTIFY: - { - MSGFILTER* msgf = (MSGFILTER*)lParam; - if (msgf->nmhdr.code == EN_MSGFILTER) - { - if (!WINHELP_CheckPopup(hWnd, msgf->msg, msgf->wParam, msgf->lParam, NULL)) - return FALSE; - if (lret) *lret = 1; - return TRUE; - } - } - break; - case WM_ACTIVATE: - if (wParam != WA_INACTIVE || (HWND)lParam == Globals.active_win->hMainWnd || - (HWND)lParam == Globals.active_popup->hMainWnd || - GetWindow((HWND)lParam, GW_OWNER) == Globals.active_win->hMainWnd) - break; - case WM_LBUTTONUP: - case WM_LBUTTONDOWN: - if (WINHELP_HandleTextMouse(Globals.active_popup, msg, lParam) && msg == WM_LBUTTONDOWN) - return FALSE; - /* fall through */ - case WM_MBUTTONDOWN: - case WM_RBUTTONDOWN: - case WM_NCLBUTTONDOWN: - case WM_NCMBUTTONDOWN: - case WM_NCRBUTTONDOWN: - hPopup = Globals.active_popup->hMainWnd; - Globals.active_popup = NULL; - DestroyWindow(hPopup); - return TRUE; - } - return FALSE; -} - -/****************************************************************** - * 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_DeleteBackSet - * - */ -void WINHELP_DeleteBackSet(WINHELP_WINDOW* win) -{ - unsigned int i; - - for (i = 0; i < win->back.index; i++) - { - HLPFILE_FreeHlpFile(win->back.set[i].page->file); - win->back.set[i].page = NULL; - } - win->back.index = 0; -} - -/****************************************************************** - * WINHELP_DeletePageLinks - * - */ -static void WINHELP_DeletePageLinks(HLPFILE_PAGE* page) -{ - HLPFILE_LINK* curr; - HLPFILE_LINK* next; - - for (curr = page->first_link; curr; curr = next) - { - next = curr->next; - HeapFree(GetProcessHeap(), 0, curr); - } -} - -/*********************************************************************** - * - * WINHELP_DeleteWindow - */ -static void WINHELP_DeleteWindow(WINHELP_WINDOW* win) -{ - WINHELP_WINDOW** w; - - for (w = &Globals.win_list; *w; w = &(*w)->next) - { - if (*w == win) - { - *w = win->next; - break; - } - } - - if (Globals.active_win == win) - { - Globals.active_win = Globals.win_list; - if (Globals.win_list) - SetActiveWindow(Globals.win_list->hMainWnd); - } - - if (win == Globals.active_popup) - Globals.active_popup = NULL; - - WINHELP_DeleteButtons(win); - - if (win->page) WINHELP_DeletePageLinks(win->page); - if (win->hShadowWnd) DestroyWindow(win->hShadowWnd); - if (win->hHistoryWnd) DestroyWindow(win->hHistoryWnd); - - DeleteObject(win->hBrush); - - WINHELP_DeleteBackSet(win); - - if (win->page) HLPFILE_FreeHlpFile(win->page->file); - HeapFree(GetProcessHeap(), 0, win); -} - -/*********************************************************************** - * - * WINHELP_InitFonts - */ -static void WINHELP_InitFonts(HWND hWnd) -{ - WINHELP_WINDOW *win = (WINHELP_WINDOW*) GetWindowLongPtr(hWnd, 0); - LOGFONT logfontlist[] = { - {-10, 0, 0, 0, 400, 0, 0, 0, DEFAULT_CHARSET, 0, 0, 0, 32, "Helv"}, - {-12, 0, 0, 0, 700, 0, 0, 0, DEFAULT_CHARSET, 0, 0, 0, 32, "Helv"}, - {-12, 0, 0, 0, 700, 0, 0, 0, DEFAULT_CHARSET, 0, 0, 0, 32, "Helv"}, - {-12, 0, 0, 0, 400, 0, 0, 0, DEFAULT_CHARSET, 0, 0, 0, 32, "Helv"}, - {-12, 0, 0, 0, 700, 0, 0, 0, DEFAULT_CHARSET, 0, 0, 0, 32, "Helv"}, - {-10, 0, 0, 0, 700, 0, 0, 0, DEFAULT_CHARSET, 0, 0, 0, 32, "Helv"}, - { -8, 0, 0, 0, 400, 0, 0, 0, DEFAULT_CHARSET, 0, 0, 0, 32, "Helv"}}; -#define FONTS_LEN (sizeof(logfontlist)/sizeof(*logfontlist)) - - static HFONT fonts[FONTS_LEN]; - static BOOL init = 0; - - win->fonts_len = FONTS_LEN; - win->fonts = fonts; - - if (!init) - { - UINT i; - - for (i = 0; i < FONTS_LEN; i++) - { - fonts[i] = CreateFontIndirect(&logfontlist[i]); - } - - init = 1; - } -} - -/*********************************************************************** - * - * WINHELP_MessageBoxIDS_s - */ -INT WINHELP_MessageBoxIDS_s(UINT ids_text, LPCSTR str, UINT ids_title, WORD type) -{ - CHAR text[MAX_STRING_LEN]; - CHAR newtext[MAX_STRING_LEN + MAX_PATH]; - - LoadString(Globals.hInstance, ids_text, text, sizeof(text)); - wsprintf(newtext, text, str); - - return MessageBox(0, newtext, MAKEINTRESOURCE(ids_title), type); -} - -/************************************************************************** - * cb_KWBTree - * - * HLPFILE_BPTreeCallback enumeration function for '|KWBTREE' internal file. - * - */ -static void cb_KWBTree(void *p, void **next, void *cookie) -{ - HWND hListWnd = (HWND)cookie; - int count; - - WINE_TRACE("Adding '%s' to search list\n", (char *)p); - SendMessage(hListWnd, LB_INSERTSTRING, -1, (LPARAM)p); - count = SendMessage(hListWnd, LB_GETCOUNT, 0, 0); - SendMessage(hListWnd, LB_SETITEMDATA, count-1, (LPARAM)p); - *next = (char*)p + strlen((char*)p) + 7; -} - -struct index_data -{ - HLPFILE* hlpfile; - BOOL jump; - ULONG offset; -}; - -/************************************************************************** - * WINHELP_IndexDlgProc - * - */ -INT_PTR CALLBACK WINHELP_IndexDlgProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) -{ - static struct index_data* id; - int sel; - - switch (msg) - { - case WM_INITDIALOG: - id = (struct index_data*)((PROPSHEETPAGE*)lParam)->lParam; - HLPFILE_BPTreeEnum(id->hlpfile->kwbtree, cb_KWBTree, - GetDlgItem(hWnd, IDC_INDEXLIST)); - id->jump = FALSE; - id->offset = 1; - return TRUE; - case WM_COMMAND: - switch (HIWORD(wParam)) - { - case LBN_DBLCLK: - if (LOWORD(wParam) == IDC_INDEXLIST) - SendMessage(GetParent(hWnd), PSM_PRESSBUTTON, PSBTN_OK, 0); - break; - } - break; - case WM_NOTIFY: - switch (((NMHDR*)lParam)->code) - { - case PSN_APPLY: - sel = SendDlgItemMessage(hWnd, IDC_INDEXLIST, LB_GETCURSEL, 0, 0); - if (sel != LB_ERR) - { - BYTE *p; - int count; - - p = (BYTE*)SendDlgItemMessage(hWnd, IDC_INDEXLIST, - LB_GETITEMDATA, sel, 0); - count = *(short*)((char *)p + strlen((char *)p) + 1); - if (count > 1) - { - MessageBox(hWnd, "count > 1 not supported yet", "Error", MB_OK | MB_ICONSTOP); - SetWindowLongPtr(hWnd, DWLP_MSGRESULT, PSNRET_INVALID); - return TRUE; - } - id->offset = *(ULONG*)((char *)p + strlen((char *)p) + 3); - id->offset = *(long*)(id->hlpfile->kwdata + id->offset + 9); - if (id->offset == 0xFFFFFFFF) - { - MessageBox(hWnd, "macro keywords not supported yet", "Error", MB_OK | MB_ICONSTOP); - SetWindowLongPtr(hWnd, DWLP_MSGRESULT, PSNRET_INVALID); - return TRUE; - } - id->jump = TRUE; - SetWindowLongPtr(hWnd, DWLP_MSGRESULT, PSNRET_NOERROR); - } - return TRUE; - default: - return FALSE; - } - break; - default: - break; - } - return FALSE; -} - -/************************************************************************** - * WINHELP_SearchDlgProc - * - */ -INT_PTR CALLBACK WINHELP_SearchDlgProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) -{ - static struct index_data* id; - - switch (msg) - { - case WM_INITDIALOG: - id = (struct index_data*)((PROPSHEETPAGE*)lParam)->lParam; - return TRUE; - case WM_NOTIFY: - switch (((NMHDR*)lParam)->code) - { - case PSN_APPLY: - SetWindowLongPtr(hWnd, DWLP_MSGRESULT, PSNRET_NOERROR); - return TRUE; - default: - return FALSE; - } - break; - default: - break; - } - return FALSE; -} - /************************************************************************** * WINHELP_CreateIndexWindow * @@ -1730,3 +1582,139 @@ BOOL WINHELP_CreateIndexWindow(BOOL is_search) } return TRUE; } + +/*********************************************************************** + * + * RegisterWinClasses + */ +static BOOL WINHELP_RegisterWinClasses(void) +{ + WNDCLASS class_main, class_button_box, class_shadow, class_history; + + class_main.style = CS_HREDRAW | CS_VREDRAW; + class_main.lpfnWndProc = WINHELP_MainWndProc; + class_main.cbClsExtra = 0; + class_main.cbWndExtra = sizeof(LONG); + class_main.hInstance = Globals.hInstance; + class_main.hIcon = LoadIcon(Globals.hInstance, MAKEINTRESOURCE(IDI_WINHELP)); + class_main.hCursor = LoadCursor(0, IDC_ARROW); + class_main.hbrBackground = (HBRUSH)(COLOR_WINDOW+1); + class_main.lpszMenuName = 0; + class_main.lpszClassName = MAIN_WIN_CLASS_NAME; + + class_button_box = class_main; + class_button_box.lpfnWndProc = WINHELP_ButtonBoxWndProc; + class_button_box.cbWndExtra = 0; + class_button_box.hbrBackground = (HBRUSH)(COLOR_BTNFACE+1); + class_button_box.lpszClassName = BUTTON_BOX_WIN_CLASS_NAME; + + class_shadow = class_main; + class_shadow.lpfnWndProc = WINHELP_ShadowWndProc; + class_shadow.cbWndExtra = 0; + class_shadow.hbrBackground = (HBRUSH)(COLOR_3DDKSHADOW+1); + class_shadow.lpszClassName = SHADOW_WIN_CLASS_NAME; + + class_history = class_main; + class_history.lpfnWndProc = WINHELP_HistoryWndProc; + class_history.lpszClassName = HISTORY_WIN_CLASS_NAME; + + return (RegisterClass(&class_main) && + RegisterClass(&class_button_box) && + RegisterClass(&class_shadow) && + RegisterClass(&class_history)); +} + +/*********************************************************************** + * + * WinMain + */ +int PASCAL WinMain(HINSTANCE hInstance, HINSTANCE prev, LPSTR cmdline, int show) +{ + MSG msg; + LONG lHash = 0; + HLPFILE* hlpfile; + static CHAR default_wndname[] = "main"; + LPSTR wndname = default_wndname; + WINHELP_DLL* dll; + + Globals.hInstance = hInstance; + + if (LoadLibrary("riched20.dll") == NULL) + return MessageBox(0, MAKEINTRESOURCE(STID_NO_RICHEDIT), + MAKEINTRESOURCE(STID_WHERROR), MB_OK); + + /* Get options */ + while (*cmdline && (*cmdline == ' ' || *cmdline == '-')) + { + CHAR option; + LPCSTR topic_id; + if (*cmdline++ == ' ') continue; + + option = *cmdline; + if (option) cmdline++; + while (*cmdline && *cmdline == ' ') cmdline++; + switch (option) + { + case 'i': + case 'I': + topic_id = cmdline; + while (*cmdline && *cmdline != ' ') cmdline++; + if (*cmdline) *cmdline++ = '\0'; + lHash = HLPFILE_Hash(topic_id); + break; + + case '3': + case '4': + Globals.wVersion = option - '0'; + break; + + case 'x': + show = SW_HIDE; + Globals.isBook = FALSE; + break; + + default: + WINE_FIXME("Unsupported cmd line: %s\n", cmdline); + break; + } + } + + /* Create primary window */ + if (!WINHELP_RegisterWinClasses()) + { + WINE_FIXME("Couldn't register classes\n"); + return 0; + } + + if (*cmdline) + { + char* ptr; + if ((*cmdline == '"') && (ptr = strchr(cmdline+1, '"'))) + { + cmdline++; + *ptr = '\0'; + } + if ((ptr = strchr(cmdline, '>'))) + { + *ptr = '\0'; + wndname = ptr + 1; + } + hlpfile = WINHELP_LookupHelpFile(cmdline); + if (!hlpfile) return 0; + } + else hlpfile = NULL; + WINHELP_OpenHelpWindow(HLPFILE_PageByHash, hlpfile, lHash, + WINHELP_GetWindowInfo(hlpfile, wndname), show); + + /* Message loop */ + while (GetMessage(&msg, 0, 0, 0)) + { + TranslateMessage(&msg); + DispatchMessage(&msg); + } + for (dll = Globals.dlls; dll; dll = dll->next) + { + if (dll->class & DC_INITTERM) dll->handler(DW_TERM, 0, 0); + } + return 0; +} diff --git a/reactos/base/applications/winhlp32/winhelp.h b/reactos/base/applications/winhlp32/winhelp.h index ac3f874c792..c4bb00f8aa1 100644 --- a/reactos/base/applications/winhlp32/winhelp.h +++ b/reactos/base/applications/winhlp32/winhelp.h @@ -149,7 +149,6 @@ BOOL WINHELP_OpenHelpWindow(HLPFILE_PAGE* (*)(HLPFILE*, LONG, ULONG*), BOOL WINHELP_GetOpenFileName(LPSTR, int); BOOL WINHELP_CreateIndexWindow(BOOL); void WINHELP_DeleteBackSet(WINHELP_WINDOW*); -INT WINHELP_MessageBoxIDS_s(UINT, LPCSTR, UINT, WORD); HLPFILE* WINHELP_LookupHelpFile(LPCSTR lpszFile); HLPFILE_WINDOWINFO* WINHELP_GetWindowInfo(HLPFILE* hlpfile, LPCSTR name); void WINHELP_LayoutMainWindow(WINHELP_WINDOW* win);