Kiln » TortoiseHg » TortoiseHg
Clone URL:  
Pushed to one repository · View In Graph Contained in 1.0, 1.0.1, and 1.0.2

shellext: extract GetTortoiseIconBitmap into new TortoiseIconBitmap.cpp

Changeset 31f4d2216a81

Parent 3c5afd3c0bbf

by Adrian Buehlmann

Changes to 6 files · Browse files at 31f4d2216a81 Showing diff from parent 3c5afd3c0bbf Diff from another changeset...

 
7
8
9
 
 
 
 
 
10
11
12
13
14
15
 
7
8
9
10
11
12
13
14
15
 
 
16
17
18
@@ -7,9 +7,12 @@
 #include "InitStatus.h"  #include "SysInfo.h"  #include "ShellExt.h" +#include "RegistryConfig.h" +#include "TortoiseIconBitmap.h" + +#include <map> +  #include "CShellExtCMenu.h" -#include "RegistryConfig.h" -#include <map>      struct MenuDescription
 
10
11
12
 
13
14
15
 
10
11
12
13
14
15
16
@@ -10,6 +10,7 @@
  InitStatus.obj \   CShellExtCMenu.obj \   CShellExtOverlay.obj \ + TortoiseIconBitmap.obj \   IconBitmapUtils.obj \   Registry.obj \   ShellExt.obj \
Change 1 of 1 Show Entire File win32/​shellext/​TortoiseIconBitmap.cpp Stacked
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
@@ -0,0 +1,45 @@
+#include "stdafx.h" +#include "TortoiseUtils.h" + +#include <map> + +#include "IconBitmapUtils.h" + + +HBITMAP GetTortoiseIconBitmap(const std::string& iconname) +{ + IconBitmapUtils bmpUtils; + typedef std::map<std::string, HBITMAP> BitmapCacheT; + static BitmapCacheT bmpcache_; + + BitmapCacheT::const_iterator i = bmpcache_.find(iconname); + if (i != bmpcache_.end()) + return i->second; + + if (bmpcache_.size() > 200) + { + TDEBUG_TRACE("**** GetTortoiseIconBitmap: error: too many bitmaps in cache"); + return 0; + } + + HICON hIcon = GetTortoiseIcon(iconname); + if (!hIcon) + return 0; + + HBITMAP hBmp = bmpUtils.IconToBitmapPARGB32(hIcon); + if (!hBmp) + { + TDEBUG_TRACE("**** GetTortoiseIconBitmap: error: something wrong in bmpUtils.ConvertToPARGB32(hIcon)"); + return 0; + } + + bmpcache_[iconname] = hBmp; + + TDEBUG_TRACE( + "GetTortoiseIconBitmap: added '" << iconname << "' to bmpcache_" + " (" << bmpcache_.size() << " bitmaps in cache)" + ); + + return hBmp; +} +
Change 1 of 1 Show Entire File win32/​shellext/​TortoiseIconBitmap.h Stacked
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
@@ -0,0 +1,9 @@
+#ifndef TORTOISE_ICON_BITMAP_H_ +#define TORTOISE_ICON_BITMAP_H_ + +#include <windows.h> +#include <string> + +HBITMAP GetTortoiseIconBitmap(const std::string& iconname); + +#endif
 
9
10
11
12
13
14
15
 
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
 
9
10
11
 
12
13
14
 
190
191
192
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
193
194
195
@@ -9,7 +9,6 @@
 #include "FCNTL.H"    #include "shlwapi.h" -#include "IconBitmapUtils.h"      LPWSTR hf_mbtowc(LPWSTR lpw, LPCSTR lpa, int nChars) @@ -191,43 +190,6 @@
  return h;  }   -HBITMAP GetTortoiseIconBitmap(const std::string& iconname) -{ - IconBitmapUtils bmpUtils; - typedef std::map<std::string, HBITMAP> BitmapCacheT; - static BitmapCacheT bmpcache_; - - BitmapCacheT::const_iterator i = bmpcache_.find(iconname); - if (i != bmpcache_.end()) - return i->second; - - if (bmpcache_.size() > 200) - { - TDEBUG_TRACE("**** GetTortoiseIconBitmap: error: too many bitmaps in cache"); - return 0; - } - - HICON hIcon = GetTortoiseIcon(iconname); - if (!hIcon) - return 0; - - HBITMAP hBmp = bmpUtils.IconToBitmapPARGB32(hIcon); - if (!hBmp) - { - TDEBUG_TRACE("**** GetTortoiseIconBitmap: error: something wrong in bmpUtils.ConvertToPARGB32(hIcon)"); - return 0; - } - - bmpcache_[iconname] = hBmp; - - TDEBUG_TRACE( - "GetTortoiseIconBitmap: added '" << iconname << "' to bmpcache_" - " (" << bmpcache_.size() << " bitmaps in cache)" - ); - - return hBmp; -} -    std::string GetHgRepoRoot(const std::string& path)  {
 
19
20
21
22
23
24
25
 
19
20
21
 
22
23
24
@@ -19,7 +19,6 @@
 std::string BaseName(const std::string&);  bool LaunchCommand(const std::string& command, const std::string& cwd);  HICON GetTortoiseIcon(const std::string & iconname); -HBITMAP GetTortoiseIconBitmap(const std::string& iconname);  std::string GetHgRepoRoot(const std::string& path);  bool IsHgRepo(const std::string& path);  FILE* fopenReadRenameAllowed(const char* path);