oledlg: Partially implement OleUIAddVerbMenuW(), with basic tests.

This commit is contained in:
Nikolay Sivov 2015-05-14 19:00:43 +03:00 committed by Alexandre Julliard
parent ec8e1df8a9
commit 04ed24fb79
5 changed files with 533 additions and 11 deletions

1
configure vendored
View File

@ -17488,6 +17488,7 @@ wine_fn_config_dll olecli32 enable_olecli32 implib
wine_fn_config_dll oledb32 enable_oledb32 clean
wine_fn_config_test dlls/oledb32/tests oledb32_test clean
wine_fn_config_dll oledlg enable_oledlg implib,po
wine_fn_config_test dlls/oledlg/tests oledlg_test
wine_fn_config_dll olepro32 enable_olepro32 implib
wine_fn_config_dll olesvr.dll16 enable_win16
wine_fn_config_dll olesvr32 enable_olesvr32 implib

View File

@ -3178,6 +3178,7 @@ WINE_CONFIG_DLL(olecli32,,[implib])
WINE_CONFIG_DLL(oledb32,,[clean])
WINE_CONFIG_TEST(dlls/oledb32/tests,[clean])
WINE_CONFIG_DLL(oledlg,,[implib,po])
WINE_CONFIG_TEST(dlls/oledlg/tests)
WINE_CONFIG_DLL(olepro32,,[implib])
WINE_CONFIG_DLL(olesvr.dll16,enable_win16)
WINE_CONFIG_DLL(olesvr32,,[implib])

View File

@ -18,6 +18,8 @@
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
*/
#define COBJMACROS
#include <stdarg.h>
#include "windef.h"
@ -30,6 +32,7 @@
#include "oledlg_private.h"
#include "wine/debug.h"
#include "wine/unicode.h"
WINE_DEFAULT_DEBUG_CHANNEL(ole);
@ -122,21 +125,120 @@ BOOL WINAPI OleUIAddVerbMenuA(IOleObject *object, LPCSTR shorttype,
return ret;
}
static inline BOOL is_verb_in_range(const OLEVERB *verb, UINT idmin, UINT idmax)
{
if (idmax == 0) return TRUE;
return (verb->lVerb + idmin <= idmax);
}
static HRESULT get_next_insertable_verb(IEnumOLEVERB *enumverbs, UINT idmin, UINT idmax, OLEVERB *verb)
{
memset(verb, 0, sizeof(*verb));
while (IEnumOLEVERB_Next(enumverbs, 1, verb, NULL) == S_OK) {
if (is_verb_in_range(verb, idmin, idmax) && (verb->grfAttribs & OLEVERBATTRIB_ONCONTAINERMENU))
return S_OK;
CoTaskMemFree(verb->lpszVerbName);
memset(verb, 0, sizeof(*verb));
}
return S_FALSE;
}
static void insert_verb_to_menu(HMENU menu, UINT idmin, const OLEVERB *verb)
{
InsertMenuW(menu, ~0, verb->fuFlags | MF_BYPOSITION | MF_STRING, verb->lVerb + idmin, verb->lpszVerbName);
}
/***********************************************************************
* OleUIAddVerbMenuW (OLEDLG.14)
*/
BOOL WINAPI OleUIAddVerbMenuW(
LPOLEOBJECT lpOleObj, LPCWSTR lpszShortType,
HMENU hMenu, UINT uPos, UINT uIDVerbMin, UINT uIDVerbMax,
BOOL bAddConvert, UINT idConvert, HMENU *lphMenu)
BOOL WINAPI OleUIAddVerbMenuW(IOleObject *object, LPCWSTR shorttype,
HMENU hMenu, UINT uPos, UINT idmin, UINT idmax, BOOL addConvert, UINT idConvert, HMENU *ret_submenu)
{
FIXME("(%p, %s, %p, %d, %d, %d, %d, %d, %p): stub\n",
lpOleObj, debugstr_w(lpszShortType),
hMenu, uPos, uIDVerbMin, uIDVerbMax,
bAddConvert, idConvert, lphMenu
);
SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
return FALSE;
static const WCHAR objectW[] = {'O','b','j','e','c','t',0}; /* FIXME: this should be localized */
static const WCHAR spaceW[] = {' ',0};
IEnumOLEVERB *enumverbs = NULL;
WCHAR *rootname, *objecttype;
LPOLESTR usertype = NULL;
OLEVERB firstverb, verb;
HMENU submenu;
TRACE("(%p, %s, %p, %d, %d, %d, %d, %d, %p)\n", object, debugstr_w(shorttype),
hMenu, uPos, idmin, idmax, addConvert, idConvert, ret_submenu);
if (addConvert)
FIXME("convert menu item is not supported.\n");
if (ret_submenu)
*ret_submenu = NULL;
if (!hMenu || !ret_submenu)
return FALSE;
/* check if we can get verbs at all */
if (object)
IOleObject_EnumVerbs(object, &enumverbs);
/* no object, or object without enumeration support */
if (!object || (object && !enumverbs)) {
InsertMenuW(hMenu, uPos, MF_BYPOSITION|MF_STRING|MF_GRAYED, idmin, objectW);
return FALSE;
}
/* root entry string */
if (!shorttype && (IOleObject_GetUserType(object, USERCLASSTYPE_SHORT, &usertype) == S_OK))
objecttype = usertype;
else
objecttype = (WCHAR*)shorttype;
rootname = CoTaskMemAlloc((strlenW(objecttype) + strlenW(objectW) + 2)*sizeof(WCHAR));
strcpyW(rootname, objecttype);
strcatW(rootname, spaceW);
strcatW(rootname, objectW);
CoTaskMemFree(usertype);
/* iterate through verbs */
/* find first suitable verb */
get_next_insertable_verb(enumverbs, idmin, idmax, &firstverb);
if (get_next_insertable_verb(enumverbs, idmin, idmax, &verb) != S_OK) {
WCHAR *str = CoTaskMemAlloc((strlenW(rootname) + strlenW(firstverb.lpszVerbName) + 2)*sizeof(WCHAR));
strcpyW(str, firstverb.lpszVerbName);
strcatW(str, spaceW);
strcatW(str, rootname);
RemoveMenu(hMenu, uPos, MF_BYPOSITION);
InsertMenuW(hMenu, uPos, MF_BYPOSITION|MF_STRING, idmin, str);
CoTaskMemFree(firstverb.lpszVerbName);
CoTaskMemFree(rootname);
CoTaskMemFree(str);
IEnumOLEVERB_Release(enumverbs);
return TRUE;
}
submenu = CreatePopupMenu();
insert_verb_to_menu(submenu, idmin, &firstverb);
insert_verb_to_menu(submenu, idmin, &verb);
CoTaskMemFree(firstverb.lpszVerbName);
CoTaskMemFree(verb.lpszVerbName);
while (get_next_insertable_verb(enumverbs, idmin, idmax, &verb) == S_OK) {
insert_verb_to_menu(submenu, idmin, &verb);
CoTaskMemFree(verb.lpszVerbName);
}
if (submenu)
*ret_submenu = submenu;
/* now submenu is ready, add root entry to original menu, attach submenu */
InsertMenuW(hMenu, uPos, MF_BYPOSITION|MF_POPUP|MF_STRING, (UINT_PTR)submenu, rootname);
IEnumOLEVERB_Release(enumverbs);
CoTaskMemFree(rootname);
return TRUE;
}
/***********************************************************************

View File

@ -0,0 +1,5 @@
TESTDLL = oledlg.dll
IMPORTS = oledlg ole32 user32
C_SRCS = \
main.c

413
dlls/oledlg/tests/main.c Normal file
View File

@ -0,0 +1,413 @@
/*
* oledlg tests
*
* Copyright 2015 Nikolay Sivov for CodeWeavers
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
*/
#define COBJMACROS
#include "wine/test.h"
#include <stdio.h>
#include "initguid.h"
#include "oledlg.h"
static HRESULT WINAPI enumverbs_QueryInterface(IEnumOLEVERB *iface, REFIID riid, void **ppv)
{
if (IsEqualIID(riid, &IID_IEnumOLEVERB) || IsEqualIID(riid, &IID_IUnknown)) {
*ppv = iface;
IEnumOLEVERB_AddRef(iface);
return S_OK;
}
*ppv = NULL;
return E_NOINTERFACE;
}
static ULONG WINAPI enumverbs_AddRef(IEnumOLEVERB *iface)
{
return 2;
}
static ULONG WINAPI enumverbs_Release(IEnumOLEVERB *iface)
{
return 1;
}
static int g_enumpos;
static const WCHAR verbW[] = {'v','e','r','b',0};
static HRESULT WINAPI enumverbs_Next(IEnumOLEVERB *iface, ULONG count, OLEVERB *verbs, ULONG *fetched)
{
ok(count == 1, "got %u\n", count);
ok(fetched == NULL, "got %p\n", fetched);
ok(g_enumpos == 0 || g_enumpos == 1, "got pos %d\n", g_enumpos);
if (g_enumpos++ == 0) {
verbs->lVerb = 123;
verbs->lpszVerbName = CoTaskMemAlloc(sizeof(verbW));
lstrcpyW(verbs->lpszVerbName, verbW);
verbs->fuFlags = MF_ENABLED;
verbs->grfAttribs = OLEVERBATTRIB_ONCONTAINERMENU;
if (fetched) *fetched = 1;
return S_OK;
}
return S_FALSE;
}
static HRESULT WINAPI enumverbs_Skip(IEnumOLEVERB *iface, ULONG count)
{
ok(0, "unexpected call\n");
return E_NOTIMPL;
}
static HRESULT WINAPI enumverbs_Reset(IEnumOLEVERB *iface)
{
ok(0, "unexpected call\n");
return E_NOTIMPL;
}
static HRESULT WINAPI enumverbs_Clone(IEnumOLEVERB *iface, IEnumOLEVERB **ppenum)
{
ok(0, "unexpected call\n");
return E_NOTIMPL;
}
static IEnumOLEVERBVtbl enumverbsvtbl = {
enumverbs_QueryInterface,
enumverbs_AddRef,
enumverbs_Release,
enumverbs_Next,
enumverbs_Skip,
enumverbs_Reset,
enumverbs_Clone
};
static IEnumOLEVERB enumverbs = { &enumverbsvtbl };
static HRESULT WINAPI oleobject_QueryInterface(IOleObject *iface, REFIID riid, void **ppv)
{
if (IsEqualIID(riid, &IID_IUnknown) || IsEqualIID(riid, &IID_IOleObject)) {
*ppv = iface;
IOleObject_AddRef(iface);
return S_OK;
}
*ppv = NULL;
return E_NOINTERFACE;
}
static ULONG WINAPI oleobject_AddRef(IOleObject *iface)
{
return 2;
}
static ULONG WINAPI oleobject_Release(IOleObject *iface)
{
return 1;
}
static HRESULT WINAPI oleobject_SetClientSite(IOleObject *iface, IOleClientSite *site)
{
ok(0, "unexpected call\n");
return E_NOTIMPL;
}
static HRESULT WINAPI oleobject_GetClientSite(IOleObject *iface, IOleClientSite **site)
{
ok(0, "unexpected call\n");
return E_NOTIMPL;
}
static HRESULT WINAPI oleobject_SetHostNames(IOleObject *iface, LPCOLESTR containerapp,
LPCOLESTR containerObj)
{
ok(0, "unexpected call\n");
return E_NOTIMPL;
}
static HRESULT WINAPI oleobject_Close(IOleObject *iface, DWORD saveopt)
{
ok(0, "unexpected call\n");
return E_NOTIMPL;
}
static HRESULT WINAPI oleobject_SetMoniker(IOleObject *iface, DWORD whichmoniker, IMoniker *mk)
{
ok(0, "unexpected call\n");
return E_NOTIMPL;
}
static HRESULT WINAPI oleobject_GetMoniker(IOleObject *iface, DWORD assign, DWORD whichmoniker,
IMoniker **mk)
{
ok(0, "unexpected call\n");
return E_NOTIMPL;
}
static HRESULT WINAPI oleobject_InitFromData(IOleObject *iface, IDataObject *dataobject,
BOOL creation, DWORD reserved)
{
ok(0, "unexpected call\n");
return E_NOTIMPL;
}
static HRESULT WINAPI oleobject_GetClipboardData(IOleObject *iface, DWORD reserved, IDataObject **dataobject)
{
ok(0, "unexpected call\n");
return E_NOTIMPL;
}
static HRESULT WINAPI oleobject_DoVerb(IOleObject *iface, LONG verb, MSG *msg, IOleClientSite *activesite,
LONG index, HWND hwndParent, LPCRECT rect)
{
ok(0, "unexpected call\n");
return E_NOTIMPL;
}
static BOOL g_enumverbsfail;
static HRESULT WINAPI oleobject_EnumVerbs(IOleObject *iface, IEnumOLEVERB **enumverb)
{
if (g_enumverbsfail) {
*enumverb = NULL;
return E_FAIL;
}
*enumverb = &enumverbs;
return S_OK;
}
static HRESULT WINAPI oleobject_Update(IOleObject *iface)
{
ok(0, "unexpected call\n");
return E_NOTIMPL;
}
static HRESULT WINAPI oleobject_IsUpToDate(IOleObject *iface)
{
ok(0, "unexpected call\n");
return E_NOTIMPL;
}
static HRESULT WINAPI oleobject_GetUserClassID(IOleObject *iface, CLSID *clsid)
{
ok(0, "unexpected call\n");
return E_NOTIMPL;
}
static const WCHAR testW[] = {'t','e','s','t',0};
static HRESULT WINAPI oleobject_GetUserType(IOleObject *iface, DWORD formoftype,
LPOLESTR *usertype)
{
ok(formoftype == USERCLASSTYPE_SHORT, "got %d\n", formoftype);
*usertype = CoTaskMemAlloc(sizeof(testW));
lstrcpyW(*usertype, testW);
return S_OK;
}
static HRESULT WINAPI oleobject_SetExtent(IOleObject *iface, DWORD aspect, SIZEL *size)
{
ok(0, "unexpected call\n");
return E_NOTIMPL;
}
static HRESULT WINAPI oleobject_GetExtent(IOleObject *iface, DWORD aspect, SIZEL *size)
{
ok(0, "unexpected call\n");
return E_NOTIMPL;
}
static HRESULT WINAPI oleobject_Advise(IOleObject *iface, IAdviseSink *sink, DWORD *connection)
{
ok(0, "unexpected call\n");
return E_NOTIMPL;
}
static HRESULT WINAPI oleobject_Unadvise(IOleObject *iface, DWORD connection)
{
ok(0, "unexpected call\n");
return E_NOTIMPL;
}
static HRESULT WINAPI oleobject_EnumAdvise(IOleObject *iface, IEnumSTATDATA **enumadvise)
{
ok(0, "unexpected call\n");
return E_NOTIMPL;
}
static HRESULT WINAPI oleobject_GetMiscStatus(IOleObject *iface, DWORD aspect, DWORD *status)
{
ok(0, "unexpected call\n");
return E_NOTIMPL;
}
static HRESULT WINAPI oleobject_SetColorScheme(IOleObject *iface, LOGPALETTE *pal)
{
ok(0, "unexpected call\n");
return E_NOTIMPL;
}
static IOleObjectVtbl oleobjectvtbl = {
oleobject_QueryInterface,
oleobject_AddRef,
oleobject_Release,
oleobject_SetClientSite,
oleobject_GetClientSite,
oleobject_SetHostNames,
oleobject_Close,
oleobject_SetMoniker,
oleobject_GetMoniker,
oleobject_InitFromData,
oleobject_GetClipboardData,
oleobject_DoVerb,
oleobject_EnumVerbs,
oleobject_Update,
oleobject_IsUpToDate,
oleobject_GetUserClassID,
oleobject_GetUserType,
oleobject_SetExtent,
oleobject_GetExtent,
oleobject_Advise,
oleobject_Unadvise,
oleobject_EnumAdvise,
oleobject_GetMiscStatus,
oleobject_SetColorScheme
};
static IOleObject oleobject = { &oleobjectvtbl };
static void test_OleUIAddVerbMenu(void)
{
HMENU hMenu, verbmenu;
MENUITEMINFOW info;
WCHAR buffW[50];
int count;
BOOL ret;
ret = OleUIAddVerbMenuW(NULL, NULL, NULL, 0, 0, 0, FALSE, 0, NULL);
ok(!ret, "got %d\n", ret);
verbmenu = (HMENU)0xdeadbeef;
ret = OleUIAddVerbMenuW(NULL, NULL, NULL, 0, 0, 0, FALSE, 0, &verbmenu);
ok(!ret, "got %d\n", ret);
ok(verbmenu == NULL, "got %p\n", verbmenu);
g_enumpos = 0;
ret = OleUIAddVerbMenuW(&oleobject, NULL, NULL, 0, 0, 0, FALSE, 0, NULL);
ok(!ret, "got %d\n", ret);
hMenu = CreatePopupMenu();
memset(&info, 0, sizeof(info));
info.cbSize = sizeof(info);
ret = InsertMenuItemW(hMenu, 0, TRUE, &info);
ok(ret, "got %d\n", ret);
count = GetMenuItemCount(hMenu);
ok(count == 1, "got %d\n", count);
g_enumpos = 0;
ret = OleUIAddVerbMenuW(&oleobject, NULL, hMenu, 0, 0, 0, FALSE, 0, NULL);
ok(!ret, "got %d\n", ret);
count = GetMenuItemCount(hMenu);
ok(count == 1, "got %d\n", count);
ret = InsertMenuItemW(hMenu, 0, TRUE, &info);
ok(ret, "got %d\n", ret);
count = GetMenuItemCount(hMenu);
ok(count == 2, "got %d\n", count);
verbmenu = (HMENU)0xdeadbeef;
g_enumpos = 0;
ret = OleUIAddVerbMenuW(&oleobject, NULL, hMenu, 1, 0, 0, FALSE, 0, &verbmenu);
ok(ret, "got %d\n", ret);
ok(verbmenu == NULL, "got %p\n", verbmenu);
count = GetMenuItemCount(hMenu);
ok(count == 2, "got %d\n", count);
/* object doesn't support EnumVerbs() */
g_enumverbsfail = TRUE;
g_enumpos = 0;
verbmenu = (HMENU)0xdeadbeef;
ret = OleUIAddVerbMenuW(&oleobject, NULL, hMenu, 2, 0, 0, FALSE, 0, &verbmenu);
ok(!ret, "got %d\n", ret);
ok(verbmenu == NULL, "got %p\n", verbmenu);
g_enumverbsfail = FALSE;
/* added disabled item */
memset(&info, 0, sizeof(info));
info.cbSize = sizeof(info);
info.fMask = MIIM_STATE|MIIM_SUBMENU;
ret = GetMenuItemInfoW(hMenu, 2, TRUE, &info);
ok(ret, "got %d\n", ret);
ok(info.fState & MFS_DISABLED, "got state 0x%08x\n", info.fState);
ok(info.hSubMenu == NULL, "got submenu %p\n", info.hSubMenu);
count = GetMenuItemCount(hMenu);
ok(count == 3, "got %d\n", count);
/* now without object */
verbmenu = (HMENU)0xdeadbeef;
ret = OleUIAddVerbMenuW(NULL, testW, hMenu, 3, 42, 0, FALSE, 0, &verbmenu);
ok(!ret, "got %d\n", ret);
ok(verbmenu == NULL, "got %p\n", verbmenu);
memset(&info, 0, sizeof(info));
info.cbSize = sizeof(info);
info.fMask = MIIM_STATE|MIIM_ID|MIIM_STRING|MIIM_SUBMENU;
info.dwTypeData = buffW;
info.cch = sizeof(buffW)/sizeof(WCHAR);
ret = GetMenuItemInfoW(hMenu, 3, TRUE, &info);
ok(ret, "got %d\n", ret);
ok(info.fState == MF_GRAYED, "got state 0x%08x\n", info.fState);
ok(info.wID == 42, "got id %d\n", info.wID);
ok(info.hSubMenu == NULL, "got submenu %p\n", info.hSubMenu);
count = GetMenuItemCount(hMenu);
ok(count == 4, "got %d\n", count);
verbmenu = (HMENU)0xdeadbeef;
g_enumpos = 0;
ret = OleUIAddVerbMenuW(&oleobject, NULL, hMenu, 4, 0, 0, FALSE, 0, &verbmenu);
ok(ret, "got %d\n", ret);
ok(verbmenu == NULL, "got %p\n", verbmenu);
/* check newly added item */
memset(&info, 0, sizeof(info));
info.cbSize = sizeof(info);
info.fMask = MIIM_STRING|MIIM_STATE|MIIM_SUBMENU;
info.dwTypeData = buffW;
info.cch = sizeof(buffW)/sizeof(WCHAR);
ret = GetMenuItemInfoW(hMenu, 4, TRUE, &info);
ok(ret, "got %d\n", ret);
/* item string has a form of '<verb> <usertype> <Object>', where Object is localized */
ok(!memcmp(buffW, verbW, sizeof(verbW) - sizeof(WCHAR)), "str %s\n", wine_dbgstr_w(buffW));
ok(info.fState == 0, "got state 0x%08x\n", info.fState);
ok(info.hSubMenu == NULL, "got submenu %p\n", info.hSubMenu);
count = GetMenuItemCount(hMenu);
ok(count == 5, "got %d\n", count);
DestroyMenu(hMenu);
}
START_TEST(main)
{
test_OleUIAddVerbMenu();
}