Commit eed5b662 authored by Frank Richter's avatar Frank Richter Committed by Alexandre Julliard

Implement "manual" image sharing(as opposed to using LoadImage() with

LR_SHARED) by keeping the loaded images in a list. This is needed for proper alpha support later on since once-per-image preparations will be needed then.
parent 49cd8a70
......@@ -212,13 +212,14 @@ static HRESULT UXTHEME_LoadImage(HTHEME hTheme, HDC hdc, int iPartId, int iState
int imagecount = 1;
BITMAP bmp;
WCHAR szPath[MAX_PATH];
BOOL hasAlpha;
PTHEME_PROPERTY tp = UXTHEME_SelectImage(hTheme, hdc, iPartId, iStateId, pRect, glyph);
if(!tp) {
FIXME("Couldn't determine image for part/state %d/%d, invalid theme?\n", iPartId, iStateId);
return E_PROP_ID_UNSUPPORTED;
}
lstrcpynW(szPath, tp->lpValue, min(tp->dwValueLen+1, sizeof(szPath)/sizeof(szPath[0])));
*hBmp = MSSTYLES_LoadBitmap(hdc, hTheme, szPath);
*hBmp = MSSTYLES_LoadBitmap(hTheme, szPath, &hasAlpha);
if(!*hBmp) {
TRACE("Failed to load bitmap %s\n", debugstr_w(szPath));
return HRESULT_FROM_WIN32(GetLastError());
......
......@@ -48,6 +48,7 @@ BOOL MSSTYLES_GetNextToken(LPCWSTR lpStringStart, LPCWSTR lpStringEnd, LPCWSTR *
void MSSTYLES_ParseThemeIni(PTHEME_FILE tf, BOOL setMetrics);
extern HINSTANCE hDllInst;
extern int alphaBlendMode;
#define MSSTYLES_VERSION 0x0003
......@@ -214,6 +215,13 @@ void MSSTYLES_CloseThemeFile(PTHEME_FILE tf)
HeapFree(GetProcessHeap(), 0, pcls);
}
}
while (tf->images)
{
PTHEME_IMAGE img = tf->images;
tf->images = img->next;
DeleteObject (img->image);
HeapFree (GetProcessHeap(), 0, img);
}
HeapFree(GetProcessHeap(), 0, tf);
}
}
......@@ -868,10 +876,11 @@ PTHEME_PROPERTY MSSTYLES_FindProperty(PTHEME_CLASS tc, int iPartId, int iStateId
return NULL;
}
HBITMAP MSSTYLES_LoadBitmap(HDC hdc, PTHEME_CLASS tc, LPCWSTR lpFilename)
HBITMAP MSSTYLES_LoadBitmap (PTHEME_CLASS tc, LPCWSTR lpFilename, BOOL* hasAlpha)
{
WCHAR szFile[MAX_PATH];
LPWSTR tmp;
PTHEME_IMAGE img;
lstrcpynW(szFile, lpFilename, sizeof(szFile)/sizeof(szFile[0]));
tmp = szFile;
do {
......@@ -879,7 +888,29 @@ HBITMAP MSSTYLES_LoadBitmap(HDC hdc, PTHEME_CLASS tc, LPCWSTR lpFilename)
if(*tmp == '/') *tmp = '_';
if(*tmp == '.') *tmp = '_';
} while(*tmp++);
return LoadImageW(tc->hTheme, szFile, IMAGE_BITMAP, 0, 0, LR_SHARED|LR_CREATEDIBSECTION);
/* Try to locate in list of loaded images */
img = tc->tf->images;
while (img)
{
if (lstrcmpiW (szFile, img->name) == 0)
{
TRACE ("found %p %s: %p\n", img, debugstr_w (img->name), img->image);
*hasAlpha = img->hasAlpha;
return img->image;
}
img = img->next;
}
/* Not found? Load from resources */
img = HeapAlloc (GetProcessHeap(), 0, sizeof (THEME_IMAGE));
img->image = LoadImageW(tc->hTheme, szFile, IMAGE_BITMAP, 0, 0, LR_CREATEDIBSECTION);
img->hasAlpha = *hasAlpha = FALSE; /* TODO: real check */
/* ...and stow away for later reuse. */
lstrcpyW (img->name, szFile);
img->next = tc->tf->images;
tc->tf->images = img;
TRACE ("new %p %s: %p\n", img, debugstr_w (img->name), img->image);
return img->image;
}
BOOL MSSTYLES_GetNextInteger(LPCWSTR lpStringStart, LPCWSTR lpStringEnd, LPCWSTR *lpValEnd, int *value)
......
......@@ -59,6 +59,14 @@ typedef struct _THEME_CLASS {
struct _THEME_CLASS *next;
} THEME_CLASS, *PTHEME_CLASS;
typedef struct _THEME_IMAGE {
WCHAR name[MAX_PATH];
HBITMAP image;
BOOL hasAlpha;
struct _THEME_IMAGE *next;
} THEME_IMAGE, *PTHEME_IMAGE;
typedef struct _THEME_FILE {
DWORD dwRefCount;
HMODULE hTheme;
......@@ -71,6 +79,7 @@ typedef struct _THEME_FILE {
PTHEME_CLASS classes;
PTHEME_PROPERTY metrics;
PTHEME_IMAGE images;
} THEME_FILE, *PTHEME_FILE;
typedef void* PUXINI_FILE;
......@@ -88,7 +97,7 @@ PTHEME_PARTSTATE MSSTYLES_FindPartState(PTHEME_CLASS tc, int iPartId, int iState
PTHEME_CLASS MSSTYLES_FindClass(PTHEME_FILE tf, LPCWSTR pszAppName, LPCWSTR pszClassName);
PTHEME_PROPERTY MSSTYLES_FindProperty(PTHEME_CLASS tc, int iPartId, int iStateId, int iPropertyPrimitive, int iPropertyId);
PTHEME_PROPERTY MSSTYLES_FindMetric(int iPropertyPrimitive, int iPropertyId);
HBITMAP MSSTYLES_LoadBitmap(HDC hdc, PTHEME_CLASS tc, LPCWSTR lpFilename);
HBITMAP MSSTYLES_LoadBitmap(PTHEME_CLASS tc, LPCWSTR lpFilename, BOOL* hasAlpha);
HRESULT MSSTYLES_GetPropertyBool(PTHEME_PROPERTY tp, BOOL *pfVal);
HRESULT MSSTYLES_GetPropertyColor(PTHEME_PROPERTY tp, COLORREF *pColor);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment