2000-11-05 21:16:15 +01:00
|
|
|
/*
|
|
|
|
* OLE32 Initialization
|
|
|
|
*
|
2003-09-08 21:38:45 +02:00
|
|
|
* Copyright 2000 Huw D M Davies for CodeWeavers
|
2002-03-10 00:29:33 +01:00
|
|
|
*
|
|
|
|
* 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
|
2006-05-18 14:49:52 +02:00
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
2000-11-05 21:16:15 +01:00
|
|
|
*/
|
2002-03-10 00:29:33 +01:00
|
|
|
|
2003-09-06 01:08:26 +02:00
|
|
|
#include <stdarg.h>
|
2003-12-08 23:46:08 +01:00
|
|
|
#include <stdio.h>
|
2003-09-06 01:08:26 +02:00
|
|
|
|
2000-11-05 21:16:15 +01:00
|
|
|
#include "windef.h"
|
2003-05-19 20:50:36 +02:00
|
|
|
#include "winbase.h"
|
|
|
|
#include "wingdi.h"
|
|
|
|
#include "winuser.h"
|
2003-12-08 23:46:08 +01:00
|
|
|
#include "winnls.h"
|
2005-05-16 16:12:53 +02:00
|
|
|
#include "objbase.h"
|
2002-03-10 00:29:33 +01:00
|
|
|
#include "wine/debug.h"
|
2000-11-05 21:16:15 +01:00
|
|
|
|
2002-03-10 00:29:33 +01:00
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(ole);
|
2000-11-05 21:16:15 +01:00
|
|
|
|
2006-12-01 16:05:30 +01:00
|
|
|
#define HIMETRIC_INCHES 2540
|
|
|
|
|
2000-11-26 05:03:10 +01:00
|
|
|
/***********************************************************************
|
2003-09-11 05:06:25 +02:00
|
|
|
* OleMetafilePictFromIconAndLabel (OLE32.@)
|
2000-11-05 21:16:15 +01:00
|
|
|
*/
|
2003-05-19 20:50:36 +02:00
|
|
|
HGLOBAL WINAPI OleMetafilePictFromIconAndLabel(HICON hIcon, LPOLESTR lpszLabel,
|
|
|
|
LPOLESTR lpszSourceFile, UINT iIconIndex)
|
|
|
|
{
|
2003-12-08 23:46:08 +01:00
|
|
|
METAFILEPICT mfp;
|
2003-05-19 20:50:36 +02:00
|
|
|
HDC hdc;
|
2003-12-08 23:46:08 +01:00
|
|
|
HGLOBAL hmem = NULL;
|
2003-05-19 20:50:36 +02:00
|
|
|
LPVOID mfdata;
|
2003-12-08 23:46:08 +01:00
|
|
|
static const char szIconOnly[] = "IconOnly";
|
2006-12-01 16:04:41 +01:00
|
|
|
SIZE text_size = { 0, 0 };
|
|
|
|
INT width;
|
|
|
|
INT icon_width;
|
|
|
|
INT icon_height;
|
|
|
|
INT label_offset;
|
|
|
|
HDC hdcScreen;
|
2006-12-01 16:05:17 +01:00
|
|
|
LOGFONTW lf;
|
|
|
|
HFONT font;
|
2003-05-19 20:50:36 +02:00
|
|
|
|
2003-12-08 23:46:08 +01:00
|
|
|
TRACE("%p %p %s %d\n", hIcon, lpszLabel, debugstr_w(lpszSourceFile), iIconIndex);
|
2003-05-19 20:50:36 +02:00
|
|
|
|
|
|
|
if( !hIcon )
|
2003-12-08 23:46:08 +01:00
|
|
|
return NULL;
|
2003-05-19 20:50:36 +02:00
|
|
|
|
2006-12-01 16:05:17 +01:00
|
|
|
if (!SystemParametersInfoW(SPI_GETICONTITLELOGFONT, sizeof(lf), &lf, 0))
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
font = CreateFontIndirectW(&lf);
|
|
|
|
if (!font)
|
|
|
|
return NULL;
|
|
|
|
|
2003-05-19 20:50:36 +02:00
|
|
|
hdc = CreateMetaFileW(NULL);
|
|
|
|
if( !hdc )
|
2006-12-01 16:05:17 +01:00
|
|
|
{
|
|
|
|
DeleteObject(font);
|
2003-12-08 23:46:08 +01:00
|
|
|
return NULL;
|
2006-12-01 16:05:17 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
SelectObject(hdc, font);
|
2003-12-08 23:46:08 +01:00
|
|
|
|
|
|
|
ExtEscape(hdc, MFCOMMENT, sizeof(szIconOnly), szIconOnly, 0, NULL);
|
2003-05-19 20:50:36 +02:00
|
|
|
|
2006-12-01 16:04:41 +01:00
|
|
|
icon_width = GetSystemMetrics(SM_CXICON);
|
|
|
|
icon_height = GetSystemMetrics(SM_CYICON);
|
|
|
|
/* FIXME: should we give the label a bit of padding here? */
|
|
|
|
label_offset = icon_height;
|
|
|
|
if (lpszLabel)
|
|
|
|
{
|
2006-12-01 16:05:17 +01:00
|
|
|
HFONT screen_old_font;
|
2006-12-01 16:04:41 +01:00
|
|
|
/* metafile DCs don't support GetTextExtentPoint32, so size the font
|
|
|
|
* using the desktop window DC */
|
|
|
|
hdcScreen = GetDC(NULL);
|
2006-12-01 16:05:17 +01:00
|
|
|
screen_old_font = SelectObject(hdcScreen, font);
|
2006-12-01 16:04:41 +01:00
|
|
|
GetTextExtentPoint32W(hdcScreen, lpszLabel, lstrlenW(lpszLabel), &text_size);
|
2006-12-01 16:05:17 +01:00
|
|
|
SelectObject(hdcScreen, screen_old_font);
|
2006-12-01 16:04:41 +01:00
|
|
|
ReleaseDC(NULL, hdcScreen);
|
2006-12-01 16:05:38 +01:00
|
|
|
|
|
|
|
width = 3 * icon_width;
|
2006-12-01 16:04:41 +01:00
|
|
|
}
|
2006-12-01 16:05:38 +01:00
|
|
|
else
|
|
|
|
width = icon_width;
|
2006-12-01 16:04:41 +01:00
|
|
|
|
2006-12-01 16:05:45 +01:00
|
|
|
SetMapMode(hdc, MM_ANISOTROPIC);
|
2006-12-01 16:04:41 +01:00
|
|
|
SetWindowOrgEx(hdc, 0, 0, NULL);
|
|
|
|
SetWindowExtEx(hdc, width, label_offset + text_size.cy, NULL);
|
|
|
|
|
|
|
|
/* draw the icon centred */
|
|
|
|
DrawIcon(hdc, (width-icon_width) / 2, 0, hIcon);
|
2003-05-19 20:50:36 +02:00
|
|
|
if(lpszLabel)
|
2006-12-01 16:04:41 +01:00
|
|
|
/* draw the label centred too, if provided */
|
|
|
|
TextOutW(hdc, (width-text_size.cx) / 2, label_offset, lpszLabel, lstrlenW(lpszLabel));
|
2003-05-19 20:50:36 +02:00
|
|
|
|
2003-12-08 23:46:08 +01:00
|
|
|
if (lpszSourceFile)
|
|
|
|
{
|
|
|
|
char szIconIndex[10];
|
|
|
|
int path_length = WideCharToMultiByte(CP_ACP,0,lpszSourceFile,-1,NULL,0,NULL,NULL);
|
|
|
|
if (path_length > 1)
|
|
|
|
{
|
|
|
|
char * szPath = CoTaskMemAlloc(path_length * sizeof(CHAR));
|
|
|
|
if (szPath)
|
|
|
|
{
|
|
|
|
WideCharToMultiByte(CP_ACP,0,lpszSourceFile,-1,szPath,path_length,NULL,NULL);
|
|
|
|
ExtEscape(hdc, MFCOMMENT, path_length, szPath, 0, NULL);
|
|
|
|
CoTaskMemFree(szPath);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
snprintf(szIconIndex, 10, "%u", iIconIndex);
|
|
|
|
ExtEscape(hdc, MFCOMMENT, strlen(szIconIndex)+1, szIconIndex, 0, NULL);
|
|
|
|
}
|
2003-05-19 20:50:36 +02:00
|
|
|
|
2006-12-01 16:04:49 +01:00
|
|
|
mfp.mm = MM_ANISOTROPIC;
|
2006-12-01 16:05:30 +01:00
|
|
|
hdcScreen = GetDC(NULL);
|
|
|
|
mfp.xExt = MulDiv(width, HIMETRIC_INCHES, GetDeviceCaps(hdcScreen, LOGPIXELSX));
|
|
|
|
mfp.yExt = MulDiv(label_offset + text_size.cy, HIMETRIC_INCHES, GetDeviceCaps(hdcScreen, LOGPIXELSY));
|
|
|
|
ReleaseDC(NULL, hdcScreen);
|
2003-12-08 23:46:08 +01:00
|
|
|
mfp.hMF = CloseMetaFile(hdc);
|
2006-12-01 16:05:17 +01:00
|
|
|
DeleteObject(font);
|
2003-12-08 23:46:08 +01:00
|
|
|
if( !mfp.hMF )
|
|
|
|
return NULL;
|
2003-05-19 20:50:36 +02:00
|
|
|
|
2003-12-08 23:46:08 +01:00
|
|
|
hmem = GlobalAlloc( GMEM_MOVEABLE, sizeof(mfp) );
|
2003-05-19 20:50:36 +02:00
|
|
|
if( !hmem )
|
2003-12-08 23:46:08 +01:00
|
|
|
{
|
|
|
|
DeleteMetaFile(mfp.hMF);
|
|
|
|
return NULL;
|
|
|
|
}
|
2000-11-05 21:16:15 +01:00
|
|
|
|
2003-05-19 20:50:36 +02:00
|
|
|
mfdata = GlobalLock( hmem );
|
|
|
|
if( !mfdata )
|
|
|
|
{
|
|
|
|
GlobalFree( hmem );
|
2003-12-08 23:46:08 +01:00
|
|
|
DeleteMetaFile(mfp.hMF);
|
|
|
|
return NULL;
|
2003-05-19 20:50:36 +02:00
|
|
|
}
|
|
|
|
|
2003-12-08 23:46:08 +01:00
|
|
|
memcpy(mfdata,&mfp,sizeof(mfp));
|
2003-05-19 20:50:36 +02:00
|
|
|
GlobalUnlock( hmem );
|
|
|
|
|
|
|
|
TRACE("returning %p\n",hmem);
|
|
|
|
|
|
|
|
return hmem;
|
|
|
|
}
|