2 * Copyright (C) 2006, 2007, 2008 Apple Inc. All rights reserved.
3 * Copyright (C) 2007-2009 Torch Mobile, Inc.
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Library General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Library General Public License for more details.
15 * You should have received a copy of the GNU Library General Public License
16 * along with this library; see the file COPYING.LIB. If not, write to
17 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 * Boston, MA 02110-1301, USA.
25 #include "GraphicsContext.h"
26 #include "LocalWindowsContext.h"
27 #include "PlatformString.h"
32 // SHGFI_SHELLICONSIZE is not available on WINCE
33 #define SHGFI_SHELLICONSIZE 0
38 static const int shell32MultipleFileIconIndex = 54;
40 Icon::Icon(HICON icon)
51 // FIXME: Move the code to ChromeClient::iconForFiles().
52 PassRefPtr<Icon> Icon::createIconForFiles(const Vector<String>& filenames)
54 if (filenames.isEmpty())
57 if (filenames.size() == 1) {
59 memset(&sfi, 0, sizeof(sfi));
61 String tmpFilename = filenames[0];
62 if (!SHGetFileInfo(tmpFilename.charactersWithNullTermination(), 0, &sfi, sizeof(sfi), SHGFI_ICON | SHGFI_SHELLICONSIZE | SHGFI_SMALLICON))
65 return adoptRef(new Icon(sfi.hIcon));
71 TCHAR buffer[MAX_PATH];
72 UINT length = ::GetSystemDirectory(buffer, WTF_ARRAY_LENGTH(buffer));
76 if (_tcscat_s(buffer, TEXT("\\shell32.dll")))
80 if (!::ExtractIconEx(buffer, shell32MultipleFileIconIndex, 0, &hIcon, 1))
82 return adoptRef(new Icon(hIcon));
86 void Icon::paint(GraphicsContext* context, const IntRect& r)
88 if (context->paintingDisabled())
92 context->drawIcon(m_hIcon, r, DI_NORMAL);
94 LocalWindowsContext windowContext(context, r);
95 DrawIconEx(windowContext.hdc(), r.x(), r.y(), m_hIcon, r.width(), r.height(), 0, 0, DI_NORMAL);