From eed5b662b96b0ef8ef329bfc1d23c5c4146397a4 Mon Sep 17 00:00:00 2001 From: Frank Richter Date: Mon, 29 Aug 2005 09:30:17 +0000 Subject: [PATCH] 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. --- dlls/uxtheme/draw.c | 3 ++- dlls/uxtheme/msstyles.c | 35 +++++++++++++++++++++++++++++++++-- dlls/uxtheme/msstyles.h | 11 ++++++++++- 3 files changed, 45 insertions(+), 4 deletions(-) diff --git a/dlls/uxtheme/draw.c b/dlls/uxtheme/draw.c index 86d9478b92d..9961aca94cc 100644 --- a/dlls/uxtheme/draw.c +++ b/dlls/uxtheme/draw.c @@ -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()); diff --git a/dlls/uxtheme/msstyles.c b/dlls/uxtheme/msstyles.c index 81fcf62a129..f40a35e03aa 100644 --- a/dlls/uxtheme/msstyles.c +++ b/dlls/uxtheme/msstyles.c @@ -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) diff --git a/dlls/uxtheme/msstyles.h b/dlls/uxtheme/msstyles.h index 4767d4cf970..76b83f04c08 100644 --- a/dlls/uxtheme/msstyles.h +++ b/dlls/uxtheme/msstyles.h @@ -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); -- 2.11.4.GIT