PageRenderTime 16ms CodeModel.GetById 7ms app.highlight 6ms RepoModel.GetById 2ms app.codeStats 0ms

/win32/shellext/TortoiseIconBitmap.cpp

https://bitbucket.org/tortoisehg/hgtk/
C++ | 45 lines | 33 code | 12 blank | 0 comment | 5 complexity | ecce9db9bc2f2773c5d2e9fcf3cd55e6 MD5 | raw file
 1#include "stdafx.h"
 2#include "TortoiseUtils.h"
 3
 4#include <map>
 5
 6#include "IconBitmapUtils.h"
 7
 8
 9HBITMAP GetTortoiseIconBitmap(const std::string& iconname)
10{
11    IconBitmapUtils bmpUtils;
12    typedef std::map<std::string, HBITMAP> BitmapCacheT;
13    static BitmapCacheT bmpcache_;
14
15    BitmapCacheT::const_iterator i = bmpcache_.find(iconname);
16    if (i != bmpcache_.end())
17        return i->second;
18
19    if (bmpcache_.size() > 200)
20    {
21        TDEBUG_TRACE("**** GetTortoiseIconBitmap: error: too many bitmaps in cache");
22        return 0;
23    }
24
25    HICON hIcon = GetTortoiseIcon(iconname);
26    if (!hIcon)
27        return 0;
28
29    HBITMAP hBmp = bmpUtils.IconToBitmapPARGB32(hIcon);
30    if (!hBmp)
31    {
32        TDEBUG_TRACE("**** GetTortoiseIconBitmap: error: something wrong in bmpUtils.ConvertToPARGB32(hIcon)");
33        return 0;
34    }
35
36    bmpcache_[iconname] = hBmp;
37
38    TDEBUG_TRACE(
39        "GetTortoiseIconBitmap: added '" << iconname << "' to bmpcache_"
40        " (" << bmpcache_.size() << " bitmaps in cache)"
41    );
42
43    return hBmp;
44}
45