2002-08-29 20:28:13 +00:00
|
|
|
/*
|
2005-10-08 19:29:20 +00:00
|
|
|
* ReactOS zoomin
|
2002-08-29 20:28:13 +00:00
|
|
|
*
|
2005-10-08 19:29:20 +00:00
|
|
|
* framewnd.c
|
2002-08-29 20:28:13 +00:00
|
|
|
*
|
2005-10-08 19:29:20 +00:00
|
|
|
* Copyright (C) 2002 Robert Dickenson <robd@reactos.org>
|
|
|
|
* Copyright (C) 2005 Martin Fuchs <martin-fuchs@gmx.net>
|
2002-08-29 20:28:13 +00:00
|
|
|
*
|
2005-10-08 19:29:20 +00:00
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
2002-08-29 20:28:13 +00:00
|
|
|
*
|
2005-10-08 19:29:20 +00:00
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
2002-08-29 20:28:13 +00:00
|
|
|
*
|
2005-10-08 19:29:20 +00:00
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
2002-08-29 20:28:13 +00:00
|
|
|
*/
|
|
|
|
|
2005-10-08 19:29:20 +00:00
|
|
|
#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers
|
2002-08-29 20:28:13 +00:00
|
|
|
#include <windows.h>
|
2005-10-08 19:29:20 +00:00
|
|
|
#include <windowsx.h>
|
2002-08-29 20:28:13 +00:00
|
|
|
#include <tchar.h>
|
2005-05-07 21:24:31 +00:00
|
|
|
|
2002-08-29 20:28:13 +00:00
|
|
|
#include "main.h"
|
|
|
|
#include "framewnd.h"
|
|
|
|
|
2005-11-15 01:25:56 +00:00
|
|
|
extern void ExitInstance();
|
2002-08-29 20:28:13 +00:00
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
2005-10-08 19:29:20 +00:00
|
|
|
// Global Variables:
|
2002-08-29 20:28:13 +00:00
|
|
|
//
|
|
|
|
|
2005-10-08 19:29:20 +00:00
|
|
|
static int s_factor = 2; // zoom factor
|
|
|
|
|
2005-10-09 11:24:51 +00:00
|
|
|
static POINT s_srcPos = {0, 0}; // source rectangle position
|
|
|
|
static RECT s_lastSrc = {-1,-1,-1,-1}; // last cursor position
|
|
|
|
|
|
|
|
BOOL s_dragging = FALSE;
|
2005-10-08 19:29:20 +00:00
|
|
|
|
2002-08-29 20:28:13 +00:00
|
|
|
|
2005-10-12 20:20:18 +00:00
|
|
|
// zoom range
|
|
|
|
|
|
|
|
#define MIN_ZOOM 1
|
|
|
|
#define MAX_ZOOM 16
|
|
|
|
|
|
|
|
|
2002-08-29 20:28:13 +00:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
2005-10-12 20:20:18 +00:00
|
|
|
// FUNCTION: SetZoom()
|
|
|
|
//
|
|
|
|
// PURPOSE: Change zoom level
|
|
|
|
//
|
|
|
|
|
|
|
|
static void SetZoom(HWND hWnd, int factor)
|
|
|
|
{
|
|
|
|
TCHAR buffer[MAX_LOADSTRING];
|
|
|
|
|
|
|
|
if (factor>=MIN_ZOOM && factor<=MAX_ZOOM) {
|
|
|
|
s_factor = factor;
|
|
|
|
|
|
|
|
SetScrollPos(hWnd, SB_VERT, s_factor, TRUE);
|
|
|
|
|
|
|
|
wsprintf(buffer, TEXT("%s %dx"), szTitle, s_factor);
|
|
|
|
SetWindowText(hWnd, buffer);
|
|
|
|
}
|
|
|
|
}
|
2002-08-29 20:28:13 +00:00
|
|
|
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
2005-10-08 19:29:20 +00:00
|
|
|
// FUNCTION: _CmdWndProc(HWND, unsigned, WORD, LONG)
|
2002-08-29 20:28:13 +00:00
|
|
|
//
|
2005-10-08 19:29:20 +00:00
|
|
|
// PURPOSE: Processes WM_COMMAND messages for the main frame window.
|
2002-08-29 20:28:13 +00:00
|
|
|
//
|
|
|
|
//
|
|
|
|
|
|
|
|
static BOOL _CmdWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
|
|
|
|
{
|
|
|
|
switch (LOWORD(wParam)) {
|
2005-10-08 19:29:20 +00:00
|
|
|
// Parse the menu selections:
|
|
|
|
case ID_EDIT_EXIT:
|
|
|
|
DestroyWindow(hWnd);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ID_EDIT_COPY:
|
|
|
|
case ID_EDIT_REFRESH:
|
|
|
|
case ID_OPTIONS_REFRESH_RATE:
|
|
|
|
case ID_HELP_ABOUT:
|
|
|
|
// TODO:
|
|
|
|
break;
|
|
|
|
|
2005-10-12 20:20:18 +00:00
|
|
|
case ID_REFRESH:
|
|
|
|
InvalidateRect(hWnd, NULL, FALSE);
|
|
|
|
break;
|
|
|
|
|
2005-10-08 19:29:20 +00:00
|
|
|
default:
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2002-08-29 20:28:13 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
2005-10-08 19:29:20 +00:00
|
|
|
// FUNCTION: FrameWndProc(HWND, unsigned, WORD, LONG)
|
2002-08-29 20:28:13 +00:00
|
|
|
//
|
2005-10-08 19:29:20 +00:00
|
|
|
// PURPOSE: Processes messages for the main window.
|
2002-08-29 20:28:13 +00:00
|
|
|
//
|
|
|
|
|
|
|
|
LRESULT CALLBACK FrameWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
|
|
|
|
{
|
2005-10-08 19:29:20 +00:00
|
|
|
switch (message) {
|
|
|
|
case WM_CREATE:
|
|
|
|
SetTimer(hWnd, 0, 200, NULL); // refresh display all 200 ms
|
2005-10-12 20:20:18 +00:00
|
|
|
SetScrollRange(hWnd, SB_VERT, 1, MAX_ZOOM, FALSE);
|
|
|
|
SetZoom(hWnd, s_factor);
|
2005-10-08 19:29:20 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case WM_COMMAND:
|
|
|
|
if (!_CmdWndProc(hWnd, message, wParam, lParam)) {
|
|
|
|
return DefWindowProc(hWnd, message, wParam, lParam);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case WM_PAINT: {
|
|
|
|
PAINTSTRUCT ps;
|
|
|
|
HDC hdcMem;
|
2005-10-09 11:24:51 +00:00
|
|
|
RECT clnt;
|
2005-10-08 19:29:20 +00:00
|
|
|
SIZE size;
|
|
|
|
|
|
|
|
BeginPaint(hWnd, &ps);
|
|
|
|
hdcMem = GetDC(GetDesktopWindow());
|
|
|
|
|
2005-10-09 11:24:51 +00:00
|
|
|
GetClientRect(hWnd, &clnt);
|
2005-10-12 20:20:18 +00:00
|
|
|
size.cx = (clnt.right + s_factor-1) / s_factor;
|
|
|
|
size.cy = (clnt.bottom + s_factor-1) / s_factor;
|
2005-10-08 19:29:20 +00:00
|
|
|
|
2005-10-12 20:20:18 +00:00
|
|
|
StretchBlt(ps.hdc, 0, 0, size.cx*s_factor, size.cy*s_factor,
|
|
|
|
hdcMem, s_srcPos.x, s_srcPos.y, size.cx, size.cy, SRCCOPY);
|
2005-10-08 19:29:20 +00:00
|
|
|
|
|
|
|
ReleaseDC(GetDesktopWindow(), hdcMem);
|
|
|
|
EndPaint(hWnd, &ps);
|
|
|
|
break;}
|
|
|
|
|
|
|
|
case WM_TIMER:
|
2005-10-09 11:24:51 +00:00
|
|
|
if (s_dragging && GetCapture()==hWnd) {
|
|
|
|
RECT clnt, rect;
|
2005-10-08 19:29:20 +00:00
|
|
|
|
|
|
|
int width = GetSystemMetrics(SM_CXSCREEN);
|
|
|
|
int height = GetSystemMetrics(SM_CYSCREEN);
|
|
|
|
|
|
|
|
GetCursorPos(&s_srcPos);
|
|
|
|
|
2005-10-09 11:24:51 +00:00
|
|
|
GetClientRect(hWnd, &clnt);
|
|
|
|
|
|
|
|
s_srcPos.x -= clnt.right / s_factor / 2;
|
|
|
|
s_srcPos.y -= clnt.bottom / s_factor / 2;
|
2005-10-08 19:29:20 +00:00
|
|
|
|
|
|
|
if (s_srcPos.x < 0)
|
|
|
|
s_srcPos.x = 0;
|
2005-10-09 11:24:51 +00:00
|
|
|
else if (s_srcPos.x+clnt.right/s_factor > width)
|
|
|
|
s_srcPos.x = width - clnt.right/s_factor;
|
2005-10-08 19:29:20 +00:00
|
|
|
|
|
|
|
if (s_srcPos.y < 0)
|
|
|
|
s_srcPos.y = 0;
|
2005-10-09 11:24:51 +00:00
|
|
|
else if (s_srcPos.y+clnt.bottom/s_factor > height)
|
|
|
|
s_srcPos.y = height - clnt.bottom/s_factor;
|
|
|
|
|
|
|
|
if (memcmp(&rect, &s_lastSrc, sizeof(RECT))) {
|
|
|
|
HDC hdc = GetDC(0);
|
|
|
|
|
|
|
|
if (s_lastSrc.bottom != -1)
|
|
|
|
DrawFocusRect(hdc, &s_lastSrc);
|
|
|
|
|
|
|
|
rect.left = s_srcPos.x - 1;
|
|
|
|
rect.top = s_srcPos.y - 1;
|
|
|
|
rect.right = rect.left + clnt.right/s_factor + 2;
|
|
|
|
rect.bottom = rect.top + clnt.bottom/s_factor + 2;
|
|
|
|
DrawFocusRect(hdc, &rect);
|
|
|
|
|
|
|
|
ReleaseDC(0, hdc);
|
|
|
|
|
|
|
|
s_lastSrc = rect;
|
|
|
|
}
|
2005-10-08 19:29:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
InvalidateRect(hWnd, NULL, FALSE);
|
2005-10-09 11:24:51 +00:00
|
|
|
UpdateWindow(hWnd);
|
2002-08-29 20:28:13 +00:00
|
|
|
break;
|
2005-10-08 19:29:20 +00:00
|
|
|
|
|
|
|
case WM_LBUTTONDOWN:
|
2005-10-09 11:24:51 +00:00
|
|
|
s_dragging = TRUE;
|
2005-10-08 19:29:20 +00:00
|
|
|
SetCapture(hWnd);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case WM_LBUTTONUP:
|
2005-10-09 11:24:51 +00:00
|
|
|
case WM_CANCELMODE:
|
|
|
|
if (s_dragging) {
|
|
|
|
HDC hdc = GetDC(0);
|
|
|
|
DrawFocusRect(hdc, &s_lastSrc);
|
|
|
|
ReleaseDC(0, hdc);
|
|
|
|
|
|
|
|
s_lastSrc.bottom = -1;
|
|
|
|
|
|
|
|
s_dragging = FALSE;
|
|
|
|
ReleaseCapture();
|
|
|
|
}
|
2005-10-08 19:29:20 +00:00
|
|
|
break;
|
|
|
|
|
2005-10-12 20:20:18 +00:00
|
|
|
case WM_VSCROLL:
|
|
|
|
switch(wParam) {
|
|
|
|
case SB_LINEUP:
|
|
|
|
case SB_PAGEUP:
|
|
|
|
SetZoom(hWnd, s_factor-1);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SB_LINEDOWN:
|
|
|
|
case SB_PAGEDOWN:
|
|
|
|
SetZoom(hWnd, s_factor+1);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2005-10-08 19:29:20 +00:00
|
|
|
case WM_DESTROY:
|
|
|
|
KillTimer(hWnd, 0);
|
|
|
|
PostQuitMessage(0);
|
2005-11-15 01:25:56 +00:00
|
|
|
ExitInstance();
|
2005-10-08 19:29:20 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
return DefWindowProc(hWnd, message, wParam, lParam);
|
2002-08-29 20:28:13 +00:00
|
|
|
}
|
2005-10-08 19:29:20 +00:00
|
|
|
|
2002-08-29 20:28:13 +00:00
|
|
|
return 0;
|
|
|
|
}
|