ReactOS  0.4.14-dev-358-gbef841c
ole32_main.c
Go to the documentation of this file.
1 /*
2  * OLE32 Initialization
3  *
4  * Copyright 2000 Huw D M Davies for CodeWeavers
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19  */
20 
21 #include <stdarg.h>
22 #include <stdio.h>
23 
24 #include "windef.h"
25 #include "winbase.h"
26 #include "wingdi.h"
27 #include "winuser.h"
28 #include "winnls.h"
29 #include "objbase.h"
30 #include "ole2.h"
31 #include "wine/debug.h"
32 
34 
35 #define HIMETRIC_INCHES 2540
36 
37 /***********************************************************************
38  * OleMetafilePictFromIconAndLabel (OLE32.@)
39  */
41  LPOLESTR lpszSourceFile, UINT iIconIndex)
42 {
43  METAFILEPICT mfp;
44  HDC hdc;
45  HGLOBAL hmem = NULL;
46  LPVOID mfdata;
47  static const char szIconOnly[] = "IconOnly";
48  SIZE text_size = { 0, 0 };
49  INT width;
50  INT icon_width;
51  INT icon_height;
52  INT label_offset;
53  HDC hdcScreen;
54  LOGFONTW lf;
55  HFONT font;
56 
57  TRACE("%p %p %s %d\n", hIcon, lpszLabel, debugstr_w(lpszSourceFile), iIconIndex);
58 
59  if( !hIcon )
60  return NULL;
61 
62  if (!SystemParametersInfoW(SPI_GETICONTITLELOGFONT, sizeof(lf), &lf, 0))
63  return NULL;
64 
66  if (!font)
67  return NULL;
68 
70  if( !hdc )
71  {
73  return NULL;
74  }
75 
77 
78  ExtEscape(hdc, MFCOMMENT, sizeof(szIconOnly), szIconOnly, 0, NULL);
79 
80  icon_width = GetSystemMetrics(SM_CXICON);
81  icon_height = GetSystemMetrics(SM_CYICON);
82  /* FIXME: should we give the label a bit of padding here? */
83  label_offset = icon_height;
84  if (lpszLabel)
85  {
86  HFONT screen_old_font;
87  /* metafile DCs don't support GetTextExtentPoint32, so size the font
88  * using the desktop window DC */
89  hdcScreen = GetDC(NULL);
90  screen_old_font = SelectObject(hdcScreen, font);
91  GetTextExtentPoint32W(hdcScreen, lpszLabel, lstrlenW(lpszLabel), &text_size);
92  SelectObject(hdcScreen, screen_old_font);
93  ReleaseDC(NULL, hdcScreen);
94 
95  width = 3 * icon_width;
96  }
97  else
98  width = icon_width;
99 
101  SetWindowOrgEx(hdc, 0, 0, NULL);
102  SetWindowExtEx(hdc, width, label_offset + text_size.cy, NULL);
103 
104  /* draw the icon centered */
105  DrawIcon(hdc, (width-icon_width) / 2, 0, hIcon);
106  if(lpszLabel)
107  /* draw the label centered too, if provided */
108  TextOutW(hdc, (width-text_size.cx) / 2, label_offset, lpszLabel, lstrlenW(lpszLabel));
109 
110  if (lpszSourceFile)
111  {
112  char szIconIndex[10];
113  int path_length = WideCharToMultiByte(CP_ACP,0,lpszSourceFile,-1,NULL,0,NULL,NULL);
114  if (path_length > 1)
115  {
116  char * szPath = CoTaskMemAlloc(path_length * sizeof(CHAR));
117  if (szPath)
118  {
119  WideCharToMultiByte(CP_ACP,0,lpszSourceFile,-1,szPath,path_length,NULL,NULL);
122  }
123  }
124  snprintf(szIconIndex, 10, "%u", iIconIndex);
125  ExtEscape(hdc, MFCOMMENT, strlen(szIconIndex)+1, szIconIndex, 0, NULL);
126  }
127 
128  mfp.mm = MM_ANISOTROPIC;
129  hdcScreen = GetDC(NULL);
131  mfp.yExt = MulDiv(label_offset + text_size.cy, HIMETRIC_INCHES, GetDeviceCaps(hdcScreen, LOGPIXELSY));
132  ReleaseDC(NULL, hdcScreen);
133  mfp.hMF = CloseMetaFile(hdc);
135  if( !mfp.hMF )
136  return NULL;
137 
138  hmem = GlobalAlloc( GMEM_MOVEABLE, sizeof(mfp) );
139  if( !hmem )
140  {
141  DeleteMetaFile(mfp.hMF);
142  return NULL;
143  }
144 
145  mfdata = GlobalLock( hmem );
146  if( !mfdata )
147  {
148  GlobalFree( hmem );
149  DeleteMetaFile(mfp.hMF);
150  return NULL;
151  }
152 
153  memcpy(mfdata,&mfp,sizeof(mfp));
154  GlobalUnlock( hmem );
155 
156  TRACE("returning %p\n",hmem);
157 
158  return hmem;
159 }
160 
161 /***********************************************************************
162  * CoGetActivationState (ole32.@)
163  */
165 {
166  FIXME("%s, %x, %p\n", debugstr_guid(&guid), unknown, unknown2);
167  return E_NOTIMPL;
168 }
169 
170 /***********************************************************************
171  * CoGetCallState (ole32.@)
172  */
174 {
175  FIXME("%d, %p\n", unknown, unknown2);
176  return E_NOTIMPL;
177 }
GLint GLint GLsizei width
Definition: gl.h:1546
HMETAFILE hMF
Definition: wingdi.h:2603
#define LOGPIXELSX
Definition: wingdi.h:717
static HICON
Definition: imagelist.c:84
HGLOBAL NTAPI GlobalAlloc(UINT uFlags, SIZE_T dwBytes)
Definition: heapmem.c:368
BOOL WINAPI SetWindowExtEx(_In_ HDC, _In_ int, _In_ int, _Out_opt_ LPSIZE)
VOID WINAPI CoTaskMemFree(LPVOID ptr)
Definition: ifs.c:420
#define WideCharToMultiByte
Definition: compat.h:101
HDC WINAPI GetDC(_In_opt_ HWND)
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
Definition: mk_font.cpp:20
#define CP_ACP
Definition: compat.h:99
char CHAR
Definition: xmlstorage.h:175
HDC WINAPI CreateMetaFileW(_In_opt_ LPCWSTR)
static HDC
Definition: imagelist.c:92
HGDIOBJ WINAPI SelectObject(_In_ HDC, _In_ HGDIOBJ)
Definition: dc.c:1497
#define snprintf
Definition: wintirpc.h:48
BOOL WINAPI DeleteObject(_In_ HGDIOBJ)
HRESULT WINAPI CoGetCallState(int unknown, PULONG unknown2)
Definition: ole32_main.c:173
#define MFCOMMENT
Definition: wingdi.h:1007
static LPOLESTR
Definition: stg_prop.c:27
#define lstrlenW
Definition: compat.h:415
int32_t INT
Definition: typedefs.h:56
const GUID * guid
int WINAPI SetMapMode(_In_ HDC, _In_ int)
#define debugstr_w
Definition: kernel32.h:32
int WINAPI ReleaseDC(_In_opt_ HWND, _In_ HDC)
#define FIXME(fmt,...)
Definition: debug.h:110
#define SM_CXICON
Definition: winuser.h:962
smooth NULL
Definition: ftsmooth.c:416
HFONT WINAPI CreateFontIndirectW(_In_ const LOGFONTW *)
LONG cx
Definition: windef.h:319
HMETAFILE WINAPI CloseMetaFile(_In_ HDC hdc)
#define debugstr_guid
Definition: kernel32.h:35
BOOL WINAPI SystemParametersInfoW(_In_ UINT, _In_ UINT, _Inout_opt_ PVOID, _In_ UINT)
#define TRACE(s)
Definition: solgame.cpp:4
LONG HRESULT
Definition: typedefs.h:77
#define WINAPI
Definition: msvc.h:8
WINE_DEFAULT_DEBUG_CHANNEL(ole)
static long path_length
Definition: maze.c:116
int WINAPI GetSystemMetrics(_In_ int)
unsigned long DWORD
Definition: ntddk_ex.h:95
HGLOBAL NTAPI GlobalFree(HGLOBAL hMem)
Definition: heapmem.c:611
Definition: id3.c:18
#define SM_CYICON
Definition: winuser.h:963
LPVOID NTAPI GlobalLock(HGLOBAL hMem)
Definition: heapmem.c:755
HDC hdc
Definition: main.c:9
#define MM_ANISOTROPIC
Definition: wingdi.h:866
int WINAPI GetDeviceCaps(_In_opt_ HDC, _In_ int)
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
BOOL WINAPI TextOutW(_In_ HDC hdc, _In_ int x, _In_ int y, _In_reads_(c) LPCWSTR lpString, _In_ int c)
BOOL WINAPI DrawIcon(_In_ HDC, _In_ int, _In_ int, _In_ HICON)
Definition: cursoricon.c:1987
#define HIMETRIC_INCHES
Definition: ole32_main.c:35
HICON hIcon
Definition: msconfig.c:44
LPCWSTR szPath
Definition: env.c:35
#define E_NOTIMPL
Definition: ddrawi.h:99
unsigned int * PULONG
Definition: retypes.h:1
unsigned int UINT
Definition: ndis.h:50
BOOL NTAPI GlobalUnlock(HGLOBAL hMem)
Definition: heapmem.c:1190
#define SPI_GETICONTITLELOGFONT
Definition: winuser.h:1362
static DWORD *static HFONT(WINAPI *pCreateFontIndirectExA)(const ENUMLOGFONTEXDVA *)
BOOL WINAPI SetWindowOrgEx(_In_ HDC, _In_ int, _In_ int, _Out_opt_ LPPOINT)
Definition: coord.c:532
BOOL WINAPI DeleteMetaFile(_In_ HMETAFILE)
#define LOGPIXELSY
Definition: wingdi.h:718
HGLOBAL WINAPI OleMetafilePictFromIconAndLabel(HICON hIcon, LPOLESTR lpszLabel, LPOLESTR lpszSourceFile, UINT iIconIndex)
Definition: ole32_main.c:40
LONG cy
Definition: windef.h:320
LPVOID WINAPI CoTaskMemAlloc(SIZE_T size)
Definition: ifs.c:404
HRESULT WINAPI CoGetActivationState(GUID guid, DWORD unknown, DWORD *unknown2)
Definition: ole32_main.c:164
#define MulDiv(x, y, z)
Definition: gdifloat.h:86
#define GMEM_MOVEABLE
Definition: winbase.h:291
BOOL WINAPI GetTextExtentPoint32W(_In_ HDC hdc, _In_reads_(c) LPCWSTR lpString, _In_ int c, _Out_ LPSIZE psizl)
int WINAPI ExtEscape(_In_ HDC hdc, _In_ int iEscape, _In_ int cjInput, _In_reads_bytes_opt_(cjInput) LPCSTR lpInData, _In_ int cjOutput, _Out_writes_bytes_opt_(cjOutput) LPSTR lpOutData)