#include "config.h"
#include "Icon.h"
#include "GraphicsContext.h"
#include "PlatformString.h"
#include <windows.h>
namespace WebCore {
Icon::Icon()
: m_hIcon(0)
{
}
Icon::Icon(HICON icon)
: m_hIcon(icon)
{
}
Icon::~Icon()
{
if (m_hIcon)
DestroyIcon(m_hIcon);
}
PassRefPtr<Icon> Icon::newIconForFile(const String& filename)
{
SHFILEINFO sfi;
memset(&sfi, 0, sizeof(sfi));
String tmpFilename = filename;
if (!SHGetFileInfo(tmpFilename.charactersWithNullTermination(), 0, &sfi, sizeof(sfi), SHGFI_ICON | SHGFI_SHELLICONSIZE | SHGFI_SMALLICON))
return 0;
Icon* icon = new Icon();
icon->m_hIcon = sfi.hIcon;
return icon;
}
void Icon::paint(GraphicsContext* context, const IntRect& r)
{
if (context->paintingDisabled())
return;
HDC hdc = context->getWindowsContext();
DrawIconEx(hdc, r.x(), r.y(), m_hIcon, r.width(), r.height(), 0, 0, DI_NORMAL);
context->releaseWindowsContext(hdc);
}
}