hhctrl.ocx: Move more code from doWinMain.

This commit is contained in:
Jacek Caban 2007-02-28 03:48:45 +01:00 committed by Alexandre Julliard
parent bf34ca2d03
commit 1a2456cc4c
3 changed files with 47 additions and 27 deletions

View File

@ -151,7 +151,7 @@ static BOOL ReadChmSystem(CHMInfo *chm)
* FIXME: There may be more than one window type in the file, so
* add the ability to choose a certain window type
*/
BOOL CHM_LoadWinTypeFromCHM(CHMInfo *pChmInfo, HH_WINTYPEW *pHHWinType)
BOOL LoadWinTypeFromCHM(CHMInfo *pChmInfo, HH_WINTYPEW *pHHWinType)
{
LARGE_INTEGER liOffset;
IStorage *pStorage = pChmInfo->pStorage;
@ -209,7 +209,7 @@ CHMInfo *OpenCHM(LPCWSTR szFile)
CHMInfo *ret = hhctrl_alloc_zero(sizeof(CHMInfo));
ret->szFile = szFile;
ret->szFile = strdupW(szFile);
hres = CoCreateInstance(&CLSID_ITStorage, NULL, CLSCTX_INPROC_SERVER,
&IID_IITStorage, (void **) &ret->pITStorage) ;

View File

@ -24,7 +24,6 @@
#include "commctrl.h"
#include "wininet.h"
#include "wine/unicode.h"
#include "wine/debug.h"
#include "resource.h"
@ -737,7 +736,7 @@ static void HH_InitRequiredControls(DWORD dwControls)
}
/* Creates the whole package */
static BOOL HH_CreateViewer(HHInfo *pHHInfo)
static BOOL CreateViewer(HHInfo *pHHInfo)
{
HH_CreateFont(pHHInfo);
@ -765,7 +764,7 @@ static BOOL HH_CreateViewer(HHInfo *pHHInfo)
return TRUE;
}
static void HH_Close(HHInfo *info)
static void ReleaseHelpViewer(HHInfo *info)
{
if (!info)
return;
@ -786,43 +785,49 @@ static void HH_Close(HHInfo *info)
CloseCHM(info->pCHMInfo);
ReleaseWebBrowser(info);
hhctrl_free(info);
OleUninitialize();
}
static HHInfo *HH_OpenHH(LPWSTR filename)
static HHInfo *CreateHelpViewer(LPCWSTR filename)
{
HHInfo *pHHInfo = hhctrl_alloc_zero(sizeof(HHInfo));
HHInfo *info = hhctrl_alloc_zero(sizeof(HHInfo));
pHHInfo->pCHMInfo = OpenCHM(filename);
if(!pHHInfo->pCHMInfo) {
HH_Close(pHHInfo);
OleInitialize(NULL);
info->pCHMInfo = OpenCHM(filename);
if(!info->pCHMInfo) {
ReleaseHelpViewer(info);
return NULL;
}
if (!CHM_LoadWinTypeFromCHM(pHHInfo->pCHMInfo, &pHHInfo->WinType)) {
HH_Close(pHHInfo);
if (!LoadWinTypeFromCHM(info->pCHMInfo, &info->WinType)) {
ReleaseHelpViewer(info);
return NULL;
}
return pHHInfo;
if(!CreateViewer(info)) {
ReleaseHelpViewer(info);
return NULL;
}
return info;
}
/* FIXME: Check szCmdLine for bad arguments */
int WINAPI doWinMain(HINSTANCE hInstance, LPSTR szCmdLine)
{
MSG msg;
HHInfo *pHHInfo;
HHInfo *info;
LPWSTR filename = strdupAtoW(szCmdLine);
if (FAILED(OleInitialize(NULL)))
info = CreateHelpViewer(filename);
hhctrl_free(filename);
if(!info)
return -1;
pHHInfo = HH_OpenHH(strdupAtoW(szCmdLine));
if (!pHHInfo || !HH_CreateViewer(pHHInfo))
{
OleUninitialize();
return -1;
}
NavigateToChm(pHHInfo, pHHInfo->pCHMInfo->szFile, pHHInfo->WinType.pszFile);
NavigateToChm(info, info->pCHMInfo->szFile, info->WinType.pszFile);
while (GetMessageW(&msg, 0, 0, 0))
{
@ -830,9 +835,7 @@ int WINAPI doWinMain(HINSTANCE hInstance, LPSTR szCmdLine)
DispatchMessageW(&msg);
}
HH_Close(pHHInfo);
hhctrl_free(pHHInfo);
OleUninitialize();
ReleaseHelpViewer(info);
return 0;
}

View File

@ -1,5 +1,6 @@
/*
* Copyright 2005 James Hawkins
* Copyright 2007 Jacek Caban for CodeWeavers
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@ -37,6 +38,7 @@
#endif
#include "wine/itss.h"
#include "wine/unicode.h"
#define WB_GOBACK 0
#define WB_GOFORWARD 1
@ -75,7 +77,7 @@ void ResizeWebBrowser(HHInfo*,DWORD,DWORD);
void DoPageAction(HHInfo*,DWORD);
CHMInfo *OpenCHM(LPCWSTR szFile);
BOOL CHM_LoadWinTypeFromCHM(CHMInfo *pCHMInfo, HH_WINTYPEW *pHHWinType);
BOOL LoadWinTypeFromCHM(CHMInfo *pCHMInfo, HH_WINTYPEW *pHHWinType);
CHMInfo *CloseCHM(CHMInfo *pCHMInfo);
/* memory allocation functions */
@ -105,6 +107,21 @@ static inline BOOL hhctrl_free(void *mem)
return HeapFree(GetProcessHeap(), 0, mem);
}
static inline LPWSTR strdupW(LPCWSTR str)
{
LPWSTR ret;
int size;
if(!str)
return NULL;
size = (strlenW(str)+1)*sizeof(WCHAR);
ret = hhctrl_alloc(size);
memcpy(ret, str, size);
return ret;
}
static inline LPWSTR strdupAtoW(LPCSTR str)
{
LPWSTR ret;