1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 #ifndef THUMBVIEWER_HXX_INCLUDED
25 #define THUMBVIEWER_HXX_INCLUDED
26 
27 #if defined _MSC_VER
28 #pragma warning(push, 1)
29 #pragma warning(disable:4917)
30 #endif
31 #include <objidl.h>
32 #include <shlobj.h>
33 #ifdef __MINGW32__
34 #include <algorithm>
35 using std::min;
36 using std::max;
37 #endif
38 #include <gdiplus.h>
39 #if defined _MSC_VER
40 #pragma warning(pop)
41 #endif
42 #include <string>
43 
44 class CThumbviewer : public IPersistFile, public IExtractImage
45 {
46 public:
47 	CThumbviewer(long RefCnt = 1);
48 	virtual ~CThumbviewer();
49 
50 	//-----------------------------
51 	// IUnknown methods
52 	//-----------------------------
53 
54 	virtual HRESULT STDMETHODCALLTYPE QueryInterface(
55             REFIID riid,
56             void __RPC_FAR *__RPC_FAR *ppvObject);
57 
58     virtual ULONG STDMETHODCALLTYPE AddRef( void);
59 
60     virtual ULONG STDMETHODCALLTYPE Release( void);
61 
62 	//----------------------------
63 	// IExtractImage methods
64 	//----------------------------
65 
66 	virtual HRESULT STDMETHODCALLTYPE Extract(HBITMAP *phBmpImage);
67 
68     virtual HRESULT STDMETHODCALLTYPE GetLocation(
69         LPWSTR pszPathBuffer,
70         DWORD cchMax,
71         DWORD *pdwPriority,
72         const SIZE *prgSize,
73         DWORD dwRecClrDepth,
74         DWORD *pdwFlags);
75 
76 	//----------------------------
77 	// IPersist methods
78 	//----------------------------
79 
80 	virtual HRESULT STDMETHODCALLTYPE GetClassID(CLSID* pClassID);
81 
82 	//----------------------------
83 	// IPersistFile methods
84 	//----------------------------
85 
86 	virtual HRESULT STDMETHODCALLTYPE IsDirty();
87 
88     virtual HRESULT STDMETHODCALLTYPE Load(
89             /* [in] */ LPCOLESTR pszFileName,
90             /* [in] */ DWORD dwMode);
91 
92     virtual HRESULT STDMETHODCALLTYPE Save(
93             /* [unique][in] */ LPCOLESTR pszFileName,
94             /* [in] */ BOOL fRemember);
95 
96     virtual HRESULT STDMETHODCALLTYPE SaveCompleted(
97             /* [unique][in] */ LPCOLESTR pszFileName);
98 
99     virtual HRESULT STDMETHODCALLTYPE GetCurFile(
100             /* [out] */ LPOLESTR __RPC_FAR *ppszFileName);
101 
102 private:
103     Gdiplus::Rect CalcScaledAspectRatio(Gdiplus::Rect src, Gdiplus::Rect dest);
104 
105 private:
106 	long		 ref_count_;
107 	std::wstring filename_;
108 	SIZE         thumbnail_size_;
109 	DWORD        color_depth_;
110 	ULONG_PTR    gdiplus_token_;
111 	Gdiplus::Bitmap* signet_;
112 };
113 
114 #endif
115