1 /*
2 * PROJECT: ReactOS Picture and Fax Viewer
3 * LICENSE: GPL-2.0 (https://spdx.org/licenses/GPL-2.0)
4 * PURPOSE: Image file browsing and manipulation
5 * COPYRIGHT: Copyright Dmitry Chapyshev (dmitry@reactos.org)
6 * Copyright 2018-2023 Katayama Hirofumi MZ (katayama.hirofumi.mz@gmail.com)
7 */
8
9 #pragma once
10
11 #define WIN32_NO_STATUS
12 #define _INC_WINDOWS
13 #define COM_NO_WINDOWS_H
14 #define INITGUID
15 #define COBJMACROS
16
17 #include <windef.h>
18 #include <winbase.h>
19 #include <winnls.h>
20 #include <winreg.h>
21 #include <wingdi.h>
22 #include <wincon.h>
23 #include <objbase.h>
24 #include <gdiplus.h>
25 #include <shlwapi.h>
26 #include <strsafe.h>
27 #include <shobjidl.h>
28
29 #include <debug.h>
30
31 #include "resource.h"
32
33 extern HINSTANCE g_hInstance;
34 extern GpImage *g_pImage;
35
36 typedef struct
37 {
38 BOOL Maximized;
39 INT X;
40 INT Y;
41 INT Width;
42 INT Height;
43 } SHIMGVW_SETTINGS;
44
45 typedef struct tagSHIMGVW_FILENODE
46 {
47 WCHAR FileName[MAX_PATH];
48 struct tagSHIMGVW_FILENODE *Prev;
49 struct tagSHIMGVW_FILENODE *Next;
50 } SHIMGVW_FILENODE;
51
52 #define WC_PREVIEW L"ShImgVw:CPreviewWnd"
53 #define WC_ZOOM L"ShImgVw:CZoomWnd"
54
55 /* Animation */
56 typedef struct tagANIME
57 {
58 UINT m_nFrameIndex;
59 UINT m_nFrameCount;
60 UINT m_nLoopIndex;
61 UINT m_nLoopCount;
62 PropertyItem *m_pDelayItem;
63 HWND m_hwndTimer;
64 } ANIME, *PANIME;
65
66 void Anime_FreeInfo(PANIME pAnime);
67 BOOL Anime_LoadInfo(PANIME pAnime);
68 void Anime_SetTimerWnd(PANIME pAnime, HWND hwndTimer);
69 void Anime_SetFrameIndex(PANIME pAnime, UINT nFrameIndex);
70 void Anime_Start(PANIME pAnime, DWORD dwDelay);
71 void Anime_Pause(PANIME pAnime);
72 BOOL Anime_OnTimer(PANIME pAnime, WPARAM wParam);
73
74 void DoShellContextMenuOnFile(HWND hwnd, PCWSTR File, LPARAM lParam);
75 void DisplayHelp(HWND hwnd);
76
QuickAlloc(SIZE_T cbSize,BOOL bZero)77 static inline LPVOID QuickAlloc(SIZE_T cbSize, BOOL bZero)
78 {
79 return HeapAlloc(GetProcessHeap(), (bZero ? HEAP_ZERO_MEMORY : 0), cbSize);
80 }
81
QuickFree(LPVOID ptr)82 static inline VOID QuickFree(LPVOID ptr)
83 {
84 HeapFree(GetProcessHeap(), 0, ptr);
85 }
86
Swap16(WORD v)87 static inline WORD Swap16(WORD v)
88 {
89 return MAKEWORD(HIBYTE(v), LOBYTE(v));
90 }
91
Swap32(UINT v)92 static inline UINT Swap32(UINT v)
93 {
94 return MAKELONG(Swap16(HIWORD(v)), Swap16(LOWORD(v)));
95 }
96
97 #ifdef _WIN32
98 #define BigToHost32 Swap32
99 #endif
100
MakeULargeInteger(UINT64 value)101 static inline ULARGE_INTEGER MakeULargeInteger(UINT64 value)
102 {
103 ULARGE_INTEGER ret;
104 ret.QuadPart = value;
105 return ret;
106 }
107
SHIMGVW_HResultFromWin32(DWORD hr)108 static inline HRESULT SHIMGVW_HResultFromWin32(DWORD hr)
109 {
110 // HRESULT_FROM_WIN32 will evaluate its parameter twice, this function will not.
111 return HRESULT_FROM_WIN32(hr);
112 }
113
HResultFromGdiplus(Status status)114 static inline HRESULT HResultFromGdiplus(Status status)
115 {
116 switch ((UINT)status)
117 {
118 case Ok: return S_OK;
119 case InvalidParameter: return E_INVALIDARG;
120 case OutOfMemory: return E_OUTOFMEMORY;
121 case NotImplemented: return HRESULT_FROM_WIN32(ERROR_CALL_NOT_IMPLEMENTED);
122 case Win32Error: return SHIMGVW_HResultFromWin32(GetLastError());
123 case FileNotFound: return HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND);
124 case AccessDenied: return HRESULT_FROM_WIN32(ERROR_ACCESS_DENIED);
125 case UnknownImageFormat: return HRESULT_FROM_WIN32(ERROR_BAD_FORMAT);
126 }
127 return E_FAIL;
128 }
129