mirror of
https://github.com/reactos/reactos.git
synced 2024-12-29 02:25:17 +00:00
[SHIMGVW] Refactor Part 3 (#6148)
Improve code flexibility. - Remove g_fnPrevProc, g_hDispWnd, g_hToolBar, and g_Anime global variables. - Declare PREVIEW_DATA structure and use it. - Encapsulate preview window by using user data. CORE-19358
This commit is contained in:
parent
045e9dee58
commit
2de6e7559e
2 changed files with 182 additions and 122 deletions
|
@ -13,16 +13,14 @@
|
||||||
#include <shlobj.h>
|
#include <shlobj.h>
|
||||||
#include <shellapi.h>
|
#include <shellapi.h>
|
||||||
|
|
||||||
|
/* Toolbar image size */
|
||||||
|
#define TB_IMAGE_WIDTH 16
|
||||||
|
#define TB_IMAGE_HEIGHT 16
|
||||||
|
|
||||||
HINSTANCE g_hInstance;
|
HINSTANCE g_hInstance;
|
||||||
SHIMGVW_SETTINGS g_Settings;
|
SHIMGVW_SETTINGS g_Settings;
|
||||||
SHIMGVW_FILENODE *g_pCurrentFile;
|
SHIMGVW_FILENODE *g_pCurrentFile;
|
||||||
GpImage *g_pImage = NULL;
|
GpImage *g_pImage = NULL;
|
||||||
WNDPROC g_fnPrevProc = NULL;
|
|
||||||
|
|
||||||
HWND g_hDispWnd = NULL;
|
|
||||||
HWND g_hToolBar = NULL;
|
|
||||||
|
|
||||||
ANIME g_Anime; /* Animation */
|
|
||||||
|
|
||||||
/* zooming */
|
/* zooming */
|
||||||
static UINT s_nZoomPercents = 100;
|
static UINT s_nZoomPercents = 100;
|
||||||
|
@ -92,31 +90,49 @@ static const TB_BUTTON_CONFIG s_ButtonConfig[] =
|
||||||
DEFINE_BTN_CONFIG(HELP_TOC)
|
DEFINE_BTN_CONFIG(HELP_TOC)
|
||||||
};
|
};
|
||||||
|
|
||||||
static VOID UpdateZoom(UINT NewZoom, BOOL bEnableBestFit, BOOL bEnableRealSize)
|
typedef struct tagPREVIEW_DATA
|
||||||
|
{
|
||||||
|
HWND m_hwnd;
|
||||||
|
HWND m_hwndZoom;
|
||||||
|
HWND m_hwndToolBar;
|
||||||
|
INT m_nZoomPercents;
|
||||||
|
WNDPROC m_fnPrevProc;
|
||||||
|
ANIME m_Anime; /* Animation */
|
||||||
|
} PREVIEW_DATA, *PPREVIEW_DATA;
|
||||||
|
|
||||||
|
PPREVIEW_DATA Preview_GetData(HWND hwnd)
|
||||||
|
{
|
||||||
|
return (PPREVIEW_DATA)GetWindowLongPtrW(hwnd, GWLP_USERDATA);
|
||||||
|
}
|
||||||
|
|
||||||
|
static VOID
|
||||||
|
Preview_UpdateZoom(PPREVIEW_DATA pData, UINT NewZoom, BOOL bEnableBestFit, BOOL bEnableRealSize)
|
||||||
{
|
{
|
||||||
BOOL bEnableZoomIn, bEnableZoomOut;
|
BOOL bEnableZoomIn, bEnableZoomOut;
|
||||||
|
HWND hToolBar = pData->m_hwndToolBar;
|
||||||
|
|
||||||
/* If zoom has not been changed, ignore it */
|
/* If zoom has not been changed, ignore it */
|
||||||
if (s_nZoomPercents == NewZoom)
|
if (pData->m_nZoomPercents == NewZoom)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
s_nZoomPercents = NewZoom;
|
pData->m_nZoomPercents = NewZoom;
|
||||||
|
|
||||||
/* Check if a zoom button of the toolbar must be grayed */
|
/* Check if a zoom button of the toolbar must be grayed */
|
||||||
bEnableZoomIn = (NewZoom < MAX_ZOOM);
|
bEnableZoomIn = (NewZoom < MAX_ZOOM);
|
||||||
bEnableZoomOut = (NewZoom > MIN_ZOOM);
|
bEnableZoomOut = (NewZoom > MIN_ZOOM);
|
||||||
|
|
||||||
/* Update toolbar buttons */
|
/* Update toolbar buttons */
|
||||||
SendMessageW(g_hToolBar, TB_ENABLEBUTTON, IDC_ZOOM_OUT, bEnableZoomOut);
|
SendMessageW(hToolBar, TB_ENABLEBUTTON, IDC_ZOOM_OUT, bEnableZoomOut);
|
||||||
SendMessageW(g_hToolBar, TB_ENABLEBUTTON, IDC_ZOOM_IN, bEnableZoomIn);
|
SendMessageW(hToolBar, TB_ENABLEBUTTON, IDC_ZOOM_IN, bEnableZoomIn);
|
||||||
SendMessageW(g_hToolBar, TB_ENABLEBUTTON, IDC_BEST_FIT, bEnableBestFit);
|
SendMessageW(hToolBar, TB_ENABLEBUTTON, IDC_BEST_FIT, bEnableBestFit);
|
||||||
SendMessageW(g_hToolBar, TB_ENABLEBUTTON, IDC_REAL_SIZE, bEnableRealSize);
|
SendMessageW(hToolBar, TB_ENABLEBUTTON, IDC_REAL_SIZE, bEnableRealSize);
|
||||||
|
|
||||||
/* Redraw the display window */
|
/* Redraw the display window */
|
||||||
InvalidateRect(g_hDispWnd, NULL, FALSE);
|
InvalidateRect(pData->m_hwndZoom, NULL, FALSE);
|
||||||
}
|
}
|
||||||
|
|
||||||
static VOID ZoomInOrOut(BOOL bZoomIn)
|
static VOID
|
||||||
|
Preview_ZoomInOrOut(PPREVIEW_DATA pData, BOOL bZoomIn)
|
||||||
{
|
{
|
||||||
UINT i, NewZoom;
|
UINT i, NewZoom;
|
||||||
|
|
||||||
|
@ -146,10 +162,11 @@ static VOID ZoomInOrOut(BOOL bZoomIn)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Update toolbar and refresh screen */
|
/* Update toolbar and refresh screen */
|
||||||
UpdateZoom(NewZoom, TRUE, TRUE);
|
Preview_UpdateZoom(pData, NewZoom, TRUE, TRUE);
|
||||||
}
|
}
|
||||||
|
|
||||||
static VOID ResetZoom(VOID)
|
static VOID
|
||||||
|
Preview_ResetZoom(PPREVIEW_DATA pData)
|
||||||
{
|
{
|
||||||
RECT Rect;
|
RECT Rect;
|
||||||
UINT ImageWidth, ImageHeight, NewZoom;
|
UINT ImageWidth, ImageHeight, NewZoom;
|
||||||
|
@ -158,7 +175,7 @@ static VOID ResetZoom(VOID)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
/* get disp window size and image size */
|
/* get disp window size and image size */
|
||||||
GetClientRect(g_hDispWnd, &Rect);
|
GetClientRect(pData->m_hwndZoom, &Rect);
|
||||||
GdipGetImageWidth(g_pImage, &ImageWidth);
|
GdipGetImageWidth(g_pImage, &ImageWidth);
|
||||||
GdipGetImageHeight(g_pImage, &ImageHeight);
|
GdipGetImageHeight(g_pImage, &ImageHeight);
|
||||||
|
|
||||||
|
@ -191,12 +208,31 @@ static VOID ResetZoom(VOID)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
UpdateZoom(NewZoom, FALSE, TRUE);
|
Preview_UpdateZoom(pData, NewZoom, FALSE, TRUE);
|
||||||
}
|
}
|
||||||
|
|
||||||
static VOID pLoadImage(LPCWSTR szOpenFileName)
|
static VOID
|
||||||
|
Preview_UpdateTitle(PPREVIEW_DATA pData, LPCWSTR FileName)
|
||||||
{
|
{
|
||||||
Anime_FreeInfo(&g_Anime);
|
WCHAR szText[MAX_PATH + 100];
|
||||||
|
LPWSTR pchFileTitle;
|
||||||
|
|
||||||
|
LoadStringW(g_hInstance, IDS_APPTITLE, szText, _countof(szText));
|
||||||
|
|
||||||
|
pchFileTitle = PathFindFileNameW(FileName);
|
||||||
|
if (pchFileTitle && *pchFileTitle)
|
||||||
|
{
|
||||||
|
StringCchCatW(szText, _countof(szText), L" - ");
|
||||||
|
StringCchCatW(szText, _countof(szText), pchFileTitle);
|
||||||
|
}
|
||||||
|
|
||||||
|
SetWindowTextW(pData->m_hwnd, szText);
|
||||||
|
}
|
||||||
|
|
||||||
|
static VOID
|
||||||
|
Preview_pLoadImage(PPREVIEW_DATA pData, LPCWSTR szOpenFileName)
|
||||||
|
{
|
||||||
|
Anime_FreeInfo(&pData->m_Anime);
|
||||||
|
|
||||||
if (g_pImage)
|
if (g_pImage)
|
||||||
{
|
{
|
||||||
|
@ -208,6 +244,7 @@ static VOID pLoadImage(LPCWSTR szOpenFileName)
|
||||||
if (!szOpenFileName || GetFileAttributesW(szOpenFileName) == 0xFFFFFFFF)
|
if (!szOpenFileName || GetFileAttributesW(szOpenFileName) == 0xFFFFFFFF)
|
||||||
{
|
{
|
||||||
DPRINT1("File %s not found!\n", szOpenFileName);
|
DPRINT1("File %s not found!\n", szOpenFileName);
|
||||||
|
Preview_UpdateTitle(pData, NULL);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -216,19 +253,29 @@ static VOID pLoadImage(LPCWSTR szOpenFileName)
|
||||||
if (!g_pImage)
|
if (!g_pImage)
|
||||||
{
|
{
|
||||||
DPRINT1("GdipLoadImageFromFile() failed\n");
|
DPRINT1("GdipLoadImageFromFile() failed\n");
|
||||||
|
Preview_UpdateTitle(pData, NULL);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Anime_LoadInfo(&g_Anime);
|
Anime_LoadInfo(&pData->m_Anime);
|
||||||
|
|
||||||
if (szOpenFileName && szOpenFileName[0])
|
if (szOpenFileName && szOpenFileName[0])
|
||||||
SHAddToRecentDocs(SHARD_PATHW, szOpenFileName);
|
SHAddToRecentDocs(SHARD_PATHW, szOpenFileName);
|
||||||
|
|
||||||
/* Reset zoom and redraw display */
|
/* Reset zoom and redraw display */
|
||||||
ResetZoom();
|
Preview_ResetZoom(pData);
|
||||||
|
|
||||||
|
Preview_UpdateTitle(pData, szOpenFileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
static VOID pSaveImageAs(HWND hwnd)
|
static VOID
|
||||||
|
Preview_pLoadImageFromNode(PPREVIEW_DATA pData, SHIMGVW_FILENODE *pNode)
|
||||||
|
{
|
||||||
|
Preview_pLoadImage(pData, (pNode ? pNode->FileName : NULL));
|
||||||
|
}
|
||||||
|
|
||||||
|
static VOID
|
||||||
|
Preview_pSaveImageAs(PPREVIEW_DATA pData)
|
||||||
{
|
{
|
||||||
OPENFILENAMEW sfn;
|
OPENFILENAMEW sfn;
|
||||||
ImageCodecInfo *codecInfo;
|
ImageCodecInfo *codecInfo;
|
||||||
|
@ -238,6 +285,7 @@ static VOID pSaveImageAs(HWND hwnd)
|
||||||
UINT num, size, j;
|
UINT num, size, j;
|
||||||
size_t sizeRemain;
|
size_t sizeRemain;
|
||||||
WCHAR *c;
|
WCHAR *c;
|
||||||
|
HWND hwnd = pData->m_hwnd;
|
||||||
|
|
||||||
if (g_pImage == NULL)
|
if (g_pImage == NULL)
|
||||||
return;
|
return;
|
||||||
|
@ -306,14 +354,14 @@ static VOID pSaveImageAs(HWND hwnd)
|
||||||
|
|
||||||
if (GetSaveFileNameW(&sfn))
|
if (GetSaveFileNameW(&sfn))
|
||||||
{
|
{
|
||||||
Anime_Pause(&g_Anime);
|
Anime_Pause(&pData->m_Anime);
|
||||||
|
|
||||||
if (GdipSaveImageToFile(g_pImage, szSaveFileName, &codecInfo[sfn.nFilterIndex - 1].Clsid, NULL) != Ok)
|
if (GdipSaveImageToFile(g_pImage, szSaveFileName, &codecInfo[sfn.nFilterIndex - 1].Clsid, NULL) != Ok)
|
||||||
{
|
{
|
||||||
DPRINT1("GdipSaveImageToFile() failed\n");
|
DPRINT1("GdipSaveImageToFile() failed\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
Anime_Start(&g_Anime, 0);
|
Anime_Start(&pData->m_Anime, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
QuickFree(szFilterMask);
|
QuickFree(szFilterMask);
|
||||||
|
@ -321,42 +369,18 @@ static VOID pSaveImageAs(HWND hwnd)
|
||||||
}
|
}
|
||||||
|
|
||||||
static VOID
|
static VOID
|
||||||
pPrintImage(HWND hwnd)
|
Preview_pPrintImage(PPREVIEW_DATA pData)
|
||||||
{
|
{
|
||||||
/* FIXME */
|
/* FIXME */
|
||||||
}
|
}
|
||||||
|
|
||||||
static VOID
|
static VOID
|
||||||
Preview_UpdateUI(HWND hwnd)
|
Preview_UpdateUI(PPREVIEW_DATA pData)
|
||||||
{
|
{
|
||||||
BOOL bEnable = (g_pImage != NULL);
|
BOOL bEnable = (g_pImage != NULL);
|
||||||
SendMessageW(g_hToolBar, TB_ENABLEBUTTON, IDC_SAVEAS, bEnable);
|
SendMessageW(pData->m_hwndToolBar, TB_ENABLEBUTTON, IDC_SAVEAS, bEnable);
|
||||||
SendMessageW(g_hToolBar, TB_ENABLEBUTTON, IDC_PRINT, bEnable);
|
SendMessageW(pData->m_hwndToolBar, TB_ENABLEBUTTON, IDC_PRINT, bEnable);
|
||||||
InvalidateRect(g_hDispWnd, NULL, FALSE);
|
InvalidateRect(pData->m_hwndZoom, NULL, FALSE);
|
||||||
}
|
|
||||||
|
|
||||||
static BOOL
|
|
||||||
pLoadImageFromNode(SHIMGVW_FILENODE *node, HWND hwnd)
|
|
||||||
{
|
|
||||||
WCHAR szText[MAX_PATH + 100];
|
|
||||||
LPWSTR pchFileTitle;
|
|
||||||
|
|
||||||
pLoadImage(node ? node->FileName : NULL);
|
|
||||||
|
|
||||||
if (node == NULL)
|
|
||||||
return FALSE;
|
|
||||||
|
|
||||||
LoadStringW(g_hInstance, IDS_APPTITLE, szText, _countof(szText));
|
|
||||||
|
|
||||||
pchFileTitle = PathFindFileNameW(node->FileName);
|
|
||||||
if (pchFileTitle && *pchFileTitle)
|
|
||||||
{
|
|
||||||
StringCchCatW(szText, _countof(szText), L" - ");
|
|
||||||
StringCchCatW(szText, _countof(szText), pchFileTitle);
|
|
||||||
}
|
|
||||||
SetWindowTextW(hwnd, szText);
|
|
||||||
|
|
||||||
return g_pImage != NULL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static SHIMGVW_FILENODE*
|
static SHIMGVW_FILENODE*
|
||||||
|
@ -670,43 +694,45 @@ ImageView_SaveSettings(VOID)
|
||||||
}
|
}
|
||||||
|
|
||||||
static BOOL
|
static BOOL
|
||||||
Preview_CreateToolBar(HWND hwnd)
|
Preview_CreateToolBar(PPREVIEW_DATA pData)
|
||||||
{
|
{
|
||||||
g_hToolBar = CreateWindowExW(0, TOOLBARCLASSNAMEW, NULL,
|
HWND hwndToolBar;
|
||||||
WS_CHILD | WS_VISIBLE | TBSTYLE_FLAT | CCS_BOTTOM | TBSTYLE_TOOLTIPS,
|
HIMAGELIST hImageList, hOldImageList;
|
||||||
0, 0, 0, 0, hwnd, NULL, g_hInstance, NULL);
|
const DWORD style = WS_CHILD | WS_VISIBLE | TBSTYLE_FLAT | CCS_BOTTOM | TBSTYLE_TOOLTIPS;
|
||||||
if (g_hToolBar != NULL)
|
|
||||||
|
hwndToolBar = CreateWindowExW(0, TOOLBARCLASSNAMEW, NULL, style,
|
||||||
|
0, 0, 0, 0, pData->m_hwnd, NULL, g_hInstance, NULL);
|
||||||
|
if (!hwndToolBar)
|
||||||
|
return FALSE;
|
||||||
|
|
||||||
|
pData->m_hwndToolBar = hwndToolBar;
|
||||||
|
|
||||||
|
SendMessageW(hwndToolBar, TB_BUTTONSTRUCTSIZE, sizeof(s_Buttons[0]), 0);
|
||||||
|
SendMessageW(hwndToolBar, TB_SETEXTENDEDSTYLE, 0, TBSTYLE_EX_HIDECLIPPEDBUTTONS);
|
||||||
|
|
||||||
|
hImageList = ImageList_Create(TB_IMAGE_WIDTH, TB_IMAGE_HEIGHT, ILC_MASK | ILC_COLOR24, 1, 1);
|
||||||
|
if (hImageList == NULL)
|
||||||
|
return FALSE;
|
||||||
|
|
||||||
|
for (UINT n = 0; n < _countof(s_ButtonConfig); n++)
|
||||||
{
|
{
|
||||||
HIMAGELIST hImageList;
|
HBITMAP hBitmap = LoadBitmapW(g_hInstance, MAKEINTRESOURCEW(s_ButtonConfig[n].idb));
|
||||||
|
ImageList_AddMasked(hImageList, hBitmap, RGB(255, 255, 255));
|
||||||
SendMessageW(g_hToolBar, TB_SETEXTENDEDSTYLE, 0, TBSTYLE_EX_HIDECLIPPEDBUTTONS);
|
DeleteObject(hBitmap);
|
||||||
|
|
||||||
SendMessageW(g_hToolBar, TB_BUTTONSTRUCTSIZE, sizeof(s_Buttons[0]), 0);
|
|
||||||
|
|
||||||
hImageList = ImageList_Create(TB_IMAGE_WIDTH, TB_IMAGE_HEIGHT, ILC_MASK | ILC_COLOR24, 1, 1);
|
|
||||||
if (hImageList == NULL)
|
|
||||||
return FALSE;
|
|
||||||
|
|
||||||
for (UINT n = 0; n < _countof(s_ButtonConfig); n++)
|
|
||||||
{
|
|
||||||
ImageList_AddMasked(hImageList, LoadImageW(g_hInstance, MAKEINTRESOURCEW(s_ButtonConfig[n].idb), IMAGE_BITMAP,
|
|
||||||
TB_IMAGE_WIDTH, TB_IMAGE_HEIGHT, LR_DEFAULTCOLOR), RGB(255, 255, 255));
|
|
||||||
}
|
|
||||||
|
|
||||||
ImageList_Destroy((HIMAGELIST)SendMessageW(g_hToolBar, TB_SETIMAGELIST,
|
|
||||||
0, (LPARAM)hImageList));
|
|
||||||
|
|
||||||
SendMessageW(g_hToolBar, TB_ADDBUTTONS, _countof(s_Buttons), (LPARAM)s_Buttons);
|
|
||||||
|
|
||||||
return TRUE;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return FALSE;
|
hOldImageList = (HIMAGELIST)SendMessageW(hwndToolBar, TB_SETIMAGELIST, 0, (LPARAM)hImageList);
|
||||||
|
ImageList_Destroy(hOldImageList);
|
||||||
|
|
||||||
|
SendMessageW(hwndToolBar, TB_ADDBUTTONS, _countof(s_Buttons), (LPARAM)s_Buttons);
|
||||||
|
|
||||||
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
LRESULT CALLBACK
|
LRESULT CALLBACK
|
||||||
ZoomWndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
|
ZoomWndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
|
||||||
{
|
{
|
||||||
|
PPREVIEW_DATA pData = (PPREVIEW_DATA)GetWindowLongPtrW(hwnd, GWLP_USERDATA);
|
||||||
switch (uMsg)
|
switch (uMsg)
|
||||||
{
|
{
|
||||||
case WM_PAINT:
|
case WM_PAINT:
|
||||||
|
@ -716,12 +742,14 @@ ZoomWndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
|
||||||
}
|
}
|
||||||
case WM_TIMER:
|
case WM_TIMER:
|
||||||
{
|
{
|
||||||
if (Anime_OnTimer(&g_Anime, wParam))
|
if (Anime_OnTimer(&pData->m_Anime, wParam))
|
||||||
InvalidateRect(hwnd, NULL, FALSE);
|
InvalidateRect(hwnd, NULL, FALSE);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
return CallWindowProcW(g_fnPrevProc, hwnd, uMsg, wParam, lParam);
|
{
|
||||||
|
return CallWindowProcW(pData->m_fnPrevProc, hwnd, uMsg, wParam, lParam);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -729,17 +757,35 @@ ZoomWndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
|
||||||
static BOOL
|
static BOOL
|
||||||
Preview_OnCreate(HWND hwnd, LPCREATESTRUCT pCS)
|
Preview_OnCreate(HWND hwnd, LPCREATESTRUCT pCS)
|
||||||
{
|
{
|
||||||
|
HWND hwndZoom;
|
||||||
|
PPREVIEW_DATA pData = QuickAlloc(sizeof(PREVIEW_DATA), TRUE);
|
||||||
|
pData->m_hwnd = hwnd;
|
||||||
|
SetWindowLongPtrW(hwnd, GWLP_USERDATA, (LONG_PTR)pData);
|
||||||
|
|
||||||
DragAcceptFiles(hwnd, TRUE);
|
DragAcceptFiles(hwnd, TRUE);
|
||||||
|
|
||||||
g_hDispWnd = CreateWindowExW(WS_EX_CLIENTEDGE, WC_STATIC, L"",
|
hwndZoom = CreateWindowExW(WS_EX_CLIENTEDGE, WC_STATIC, NULL, WS_CHILD | WS_VISIBLE,
|
||||||
WS_CHILD | WS_VISIBLE,
|
0, 0, 0, 0, hwnd, NULL, g_hInstance, NULL);
|
||||||
0, 0, 0, 0, hwnd, NULL, g_hInstance, NULL);
|
if (!hwndZoom)
|
||||||
|
{
|
||||||
|
QuickFree(pData);
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
SetClassLongPtr(g_hDispWnd, GCL_STYLE, CS_HREDRAW | CS_VREDRAW);
|
pData->m_hwndZoom = hwndZoom;
|
||||||
g_fnPrevProc = (WNDPROC)SetWindowLongPtr(g_hDispWnd, GWLP_WNDPROC, (LPARAM)ZoomWndProc);
|
SetWindowLongPtrW(hwndZoom, GWLP_USERDATA, (LONG_PTR)pData);
|
||||||
|
|
||||||
Preview_CreateToolBar(hwnd);
|
SetClassLongPtr(pData->m_hwndZoom, GCL_STYLE, CS_HREDRAW | CS_VREDRAW);
|
||||||
Anime_SetTimerWnd(&g_Anime, g_hDispWnd);
|
pData->m_fnPrevProc = (WNDPROC)SetWindowLongPtr(pData->m_hwndZoom,
|
||||||
|
GWLP_WNDPROC, (LPARAM)ZoomWndProc);
|
||||||
|
|
||||||
|
if (!Preview_CreateToolBar(pData))
|
||||||
|
{
|
||||||
|
QuickFree(pData);
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
Anime_SetTimerWnd(&pData->m_Anime, pData->m_hwndZoom);
|
||||||
|
|
||||||
if (pCS && pCS->lpCreateParams)
|
if (pCS && pCS->lpCreateParams)
|
||||||
{
|
{
|
||||||
|
@ -751,8 +797,8 @@ Preview_OnCreate(HWND hwnd, LPCREATESTRUCT pCS)
|
||||||
PathUnquoteSpacesW(szFile);
|
PathUnquoteSpacesW(szFile);
|
||||||
|
|
||||||
g_pCurrentFile = pBuildFileList(szFile);
|
g_pCurrentFile = pBuildFileList(szFile);
|
||||||
pLoadImageFromNode(g_pCurrentFile, hwnd);
|
Preview_pLoadImageFromNode(pData, g_pCurrentFile);
|
||||||
Preview_UpdateUI(hwnd);
|
Preview_UpdateUI(pData);
|
||||||
}
|
}
|
||||||
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
|
@ -761,10 +807,11 @@ Preview_OnCreate(HWND hwnd, LPCREATESTRUCT pCS)
|
||||||
static VOID
|
static VOID
|
||||||
Preview_OnMouseWheel(HWND hwnd, INT x, INT y, INT zDelta, UINT fwKeys)
|
Preview_OnMouseWheel(HWND hwnd, INT x, INT y, INT zDelta, UINT fwKeys)
|
||||||
{
|
{
|
||||||
|
PPREVIEW_DATA pData = Preview_GetData(hwnd);
|
||||||
if (zDelta != 0)
|
if (zDelta != 0)
|
||||||
{
|
{
|
||||||
if (GetKeyState(VK_CONTROL) < 0)
|
if (GetKeyState(VK_CONTROL) < 0)
|
||||||
ZoomInOrOut(zDelta > 0);
|
Preview_ZoomInOrOut(pData, zDelta > 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -792,23 +839,26 @@ static VOID
|
||||||
Preview_OnSize(HWND hwnd, UINT state, INT cx, INT cy)
|
Preview_OnSize(HWND hwnd, UINT state, INT cx, INT cy)
|
||||||
{
|
{
|
||||||
RECT rc;
|
RECT rc;
|
||||||
|
PPREVIEW_DATA pData = Preview_GetData(hwnd);
|
||||||
|
HWND hToolBar = pData->m_hwndToolBar;
|
||||||
|
|
||||||
SendMessageW(g_hToolBar, TB_AUTOSIZE, 0, 0);
|
SendMessageW(hToolBar, TB_AUTOSIZE, 0, 0);
|
||||||
|
|
||||||
GetWindowRect(g_hToolBar, &rc);
|
GetWindowRect(hToolBar, &rc);
|
||||||
|
|
||||||
MoveWindow(g_hDispWnd, 0, 0, cx, cy - (rc.bottom - rc.top), TRUE);
|
MoveWindow(pData->m_hwndZoom, 0, 0, cx, cy - (rc.bottom - rc.top), TRUE);
|
||||||
|
|
||||||
if (!IsIconic(hwnd)) /* Is it not minimized? */
|
if (!IsIconic(hwnd)) /* Is it not minimized? */
|
||||||
ResetZoom();
|
Preview_ResetZoom(pData);
|
||||||
|
|
||||||
Preview_OnMoveSize(hwnd);
|
Preview_OnMoveSize(hwnd);
|
||||||
}
|
}
|
||||||
|
|
||||||
static VOID
|
static VOID
|
||||||
Preview_Delete(HWND hwnd)
|
Preview_Delete(PPREVIEW_DATA pData)
|
||||||
{
|
{
|
||||||
WCHAR szCurFile[MAX_PATH + 1], szNextFile[MAX_PATH];
|
WCHAR szCurFile[MAX_PATH + 1], szNextFile[MAX_PATH];
|
||||||
|
HWND hwnd = pData->m_hwnd;
|
||||||
SHFILEOPSTRUCTW FileOp = { hwnd, FO_DELETE };
|
SHFILEOPSTRUCTW FileOp = { hwnd, FO_DELETE };
|
||||||
|
|
||||||
if (!g_pCurrentFile)
|
if (!g_pCurrentFile)
|
||||||
|
@ -836,14 +886,14 @@ Preview_Delete(HWND hwnd)
|
||||||
{
|
{
|
||||||
DPRINT("Preview_Delete: SHFileOperationW() failed or canceled\n");
|
DPRINT("Preview_Delete: SHFileOperationW() failed or canceled\n");
|
||||||
|
|
||||||
pLoadImage(szCurFile);
|
Preview_pLoadImage(pData, szCurFile);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Reload the file list and go next file */
|
/* Reload the file list and go next file */
|
||||||
pFreeFileList(g_pCurrentFile);
|
pFreeFileList(g_pCurrentFile);
|
||||||
g_pCurrentFile = pBuildFileList(szNextFile);
|
g_pCurrentFile = pBuildFileList(szNextFile);
|
||||||
pLoadImageFromNode(g_pCurrentFile, hwnd);
|
Preview_pLoadImageFromNode(pData, g_pCurrentFile);
|
||||||
}
|
}
|
||||||
|
|
||||||
static VOID
|
static VOID
|
||||||
|
@ -872,14 +922,16 @@ Preview_Edit(HWND hwnd)
|
||||||
static VOID
|
static VOID
|
||||||
Preview_OnCommand(HWND hwnd, UINT nCommandID)
|
Preview_OnCommand(HWND hwnd, UINT nCommandID)
|
||||||
{
|
{
|
||||||
|
PPREVIEW_DATA pData = Preview_GetData(hwnd);
|
||||||
|
|
||||||
switch (nCommandID)
|
switch (nCommandID)
|
||||||
{
|
{
|
||||||
case IDC_PREV_PIC:
|
case IDC_PREV_PIC:
|
||||||
if (g_pCurrentFile)
|
if (g_pCurrentFile)
|
||||||
{
|
{
|
||||||
g_pCurrentFile = g_pCurrentFile->Prev;
|
g_pCurrentFile = g_pCurrentFile->Prev;
|
||||||
pLoadImageFromNode(g_pCurrentFile, hwnd);
|
Preview_pLoadImageFromNode(pData, g_pCurrentFile);
|
||||||
Preview_UpdateUI(hwnd);
|
Preview_UpdateUI(pData);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
@ -887,17 +939,17 @@ Preview_OnCommand(HWND hwnd, UINT nCommandID)
|
||||||
if (g_pCurrentFile)
|
if (g_pCurrentFile)
|
||||||
{
|
{
|
||||||
g_pCurrentFile = g_pCurrentFile->Next;
|
g_pCurrentFile = g_pCurrentFile->Next;
|
||||||
pLoadImageFromNode(g_pCurrentFile, hwnd);
|
Preview_pLoadImageFromNode(pData, g_pCurrentFile);
|
||||||
Preview_UpdateUI(hwnd);
|
Preview_UpdateUI(pData);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case IDC_BEST_FIT:
|
case IDC_BEST_FIT:
|
||||||
ResetZoom();
|
Preview_ResetZoom(pData);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case IDC_REAL_SIZE:
|
case IDC_REAL_SIZE:
|
||||||
UpdateZoom(100, TRUE, FALSE);
|
Preview_UpdateZoom(pData, 100, TRUE, FALSE);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case IDC_SLIDE_SHOW:
|
case IDC_SLIDE_SHOW:
|
||||||
|
@ -905,19 +957,19 @@ Preview_OnCommand(HWND hwnd, UINT nCommandID)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case IDC_ZOOM_IN:
|
case IDC_ZOOM_IN:
|
||||||
ZoomInOrOut(TRUE);
|
Preview_ZoomInOrOut(pData, TRUE);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case IDC_ZOOM_OUT:
|
case IDC_ZOOM_OUT:
|
||||||
ZoomInOrOut(FALSE);
|
Preview_ZoomInOrOut(pData, FALSE);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case IDC_SAVEAS:
|
case IDC_SAVEAS:
|
||||||
pSaveImageAs(hwnd);
|
Preview_pSaveImageAs(pData);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case IDC_PRINT:
|
case IDC_PRINT:
|
||||||
pPrintImage(hwnd);
|
Preview_pPrintImage(pData);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case IDC_ROT_CLOCKW:
|
case IDC_ROT_CLOCKW:
|
||||||
|
@ -937,13 +989,13 @@ Preview_OnCommand(HWND hwnd, UINT nCommandID)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case IDC_DELETE:
|
case IDC_DELETE:
|
||||||
Preview_Delete(hwnd);
|
Preview_Delete(pData);
|
||||||
Preview_UpdateUI(hwnd);
|
Preview_UpdateUI(pData);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case IDC_MODIFY:
|
case IDC_MODIFY:
|
||||||
Preview_Edit(hwnd);
|
Preview_Edit(hwnd);
|
||||||
Preview_UpdateUI(hwnd);
|
Preview_UpdateUI(pData);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -967,6 +1019,8 @@ Preview_OnNotify(HWND hwnd, LPNMHDR pnmhdr)
|
||||||
static VOID
|
static VOID
|
||||||
Preview_OnDestroy(HWND hwnd)
|
Preview_OnDestroy(HWND hwnd)
|
||||||
{
|
{
|
||||||
|
PPREVIEW_DATA pData = Preview_GetData(hwnd);
|
||||||
|
|
||||||
pFreeFileList(g_pCurrentFile);
|
pFreeFileList(g_pCurrentFile);
|
||||||
g_pCurrentFile = NULL;
|
g_pCurrentFile = NULL;
|
||||||
|
|
||||||
|
@ -976,9 +1030,18 @@ Preview_OnDestroy(HWND hwnd)
|
||||||
g_pImage = NULL;
|
g_pImage = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
Anime_FreeInfo(&g_Anime);
|
Anime_FreeInfo(&pData->m_Anime);
|
||||||
|
|
||||||
|
SetWindowLongPtr(pData->m_hwndZoom, GWLP_WNDPROC, (LPARAM)pData->m_fnPrevProc);
|
||||||
|
SetWindowLongPtr(pData->m_hwndZoom, GWLP_USERDATA, 0);
|
||||||
|
DestroyWindow(pData->m_hwndZoom);
|
||||||
|
pData->m_hwndZoom = NULL;
|
||||||
|
|
||||||
|
DestroyWindow(pData->m_hwndToolBar);
|
||||||
|
pData->m_hwndToolBar = NULL;
|
||||||
|
|
||||||
|
QuickFree(pData);
|
||||||
|
|
||||||
SetWindowLongPtr(g_hDispWnd, GWLP_WNDPROC, (LPARAM)g_fnPrevProc);
|
|
||||||
PostQuitMessage(0);
|
PostQuitMessage(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -986,12 +1049,13 @@ static VOID
|
||||||
Preview_OnDropFiles(HWND hwnd, HDROP hDrop)
|
Preview_OnDropFiles(HWND hwnd, HDROP hDrop)
|
||||||
{
|
{
|
||||||
WCHAR szFile[MAX_PATH];
|
WCHAR szFile[MAX_PATH];
|
||||||
|
PPREVIEW_DATA pData = Preview_GetData(hwnd);
|
||||||
|
|
||||||
DragQueryFileW(hDrop, 0, szFile, _countof(szFile));
|
DragQueryFileW(hDrop, 0, szFile, _countof(szFile));
|
||||||
|
|
||||||
pFreeFileList(g_pCurrentFile);
|
pFreeFileList(g_pCurrentFile);
|
||||||
g_pCurrentFile = pBuildFileList(szFile);
|
g_pCurrentFile = pBuildFileList(szFile);
|
||||||
pLoadImageFromNode(g_pCurrentFile, hwnd);
|
Preview_pLoadImageFromNode(pData, g_pCurrentFile);
|
||||||
|
|
||||||
DragFinish(hDrop);
|
DragFinish(hDrop);
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,11 +29,7 @@
|
||||||
|
|
||||||
#include "resource.h"
|
#include "resource.h"
|
||||||
|
|
||||||
#define TB_IMAGE_WIDTH 16
|
|
||||||
#define TB_IMAGE_HEIGHT 16
|
|
||||||
|
|
||||||
extern HINSTANCE g_hInstance;
|
extern HINSTANCE g_hInstance;
|
||||||
extern HWND g_hDispWnd;
|
|
||||||
extern GpImage *g_pImage;
|
extern GpImage *g_pImage;
|
||||||
|
|
||||||
typedef struct
|
typedef struct
|
||||||
|
|
Loading…
Reference in a new issue