[CLIPBRD]

Start scrolling support, work in progress. By Ricardo Hanke
CORE-10679

svn path=/trunk/; revision=70331
This commit is contained in:
Hermès Bélusca-Maïto 2015-12-12 21:15:53 +00:00
parent 626de8ff8e
commit 0e0df7b9e6
6 changed files with 324 additions and 5 deletions

View file

@ -4,6 +4,7 @@ list(APPEND SOURCE
cliputils.c
winutils.c
fileutils.c
scrollutils.c
precomp.h)
add_executable(clipbrd ${SOURCE} clipbrd.rc)

View file

@ -11,6 +11,7 @@
static const WCHAR szClassName[] = L"ClipBookWClass";
CLIPBOARD_GLOBALS Globals;
SCROLLSTATE Scrollstate;
static void SaveClipboardToFile(void)
{
@ -124,8 +125,15 @@ static void SetDisplayFormat(UINT uFormat)
Globals.uDisplayFormat = uFormat;
}
if (Globals.hDspBmp)
{
DeleteObject(Globals.hDspBmp);
}
ZeroMemory(&Scrollstate, sizeof(Scrollstate));
UpdateWindowScrollState(Globals.hMainWnd, Globals.hDspBmp, &Scrollstate);
InvalidateRect(Globals.hMainWnd, NULL, TRUE);
UpdateWindow(Globals.hMainWnd);
}
static void InitMenuPopup(HMENU hMenu, LPARAM index)
@ -330,10 +338,40 @@ static LRESULT WINAPI MainWndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lP
break;
}
case WM_KEYDOWN:
{
HandleKeyboardScrollEvents(hWnd, uMsg, wParam, lParam);
break;
}
case WM_HSCROLL:
{
HandleHorizontalScrollEvents(hWnd, uMsg, wParam, lParam, &Scrollstate);
break;
}
case WM_VSCROLL:
{
HandleVerticalScrollEvents(hWnd, uMsg, wParam, lParam, &Scrollstate);
break;
}
case WM_SIZE:
{
InvalidateRect(hWnd, NULL, TRUE);
UpdateWindow(hWnd);
UpdateWindowScrollState(hWnd, Globals.hDspBmp, &Scrollstate);
if ((Globals.uDisplayFormat == CF_METAFILEPICT) ||
(Globals.uDisplayFormat == CF_ENHMETAFILE) ||
(Globals.uDisplayFormat == CF_DSPENHMETAFILE) ||
(Globals.uDisplayFormat == CF_DSPMETAFILEPICT))
{
InvalidateRect(Globals.hMainWnd, NULL, FALSE);
}
else if (!IsClipboardFormatSupported(Globals.uDisplayFormat))
{
InvalidateRect(Globals.hMainWnd, NULL, TRUE);
}
break;
}
@ -431,6 +469,12 @@ static LRESULT WINAPI MainWndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lP
break;
}
case WM_SYSCOLORCHANGE:
{
SetDisplayFormat(Globals.uDisplayFormat);
break;
}
default:
{
return DefWindowProc(hWnd, uMsg, wParam, lParam);
@ -510,5 +554,10 @@ int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmdLi
}
}
if (Globals.hDspBmp)
{
DeleteObject(Globals.hDspBmp);
}
return (int)msg.wParam;
}

View file

@ -1,7 +1,7 @@
/*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS Clipboard Viewer
* FILE: base/applications/clipbrd/fileutils.c
* FILE: base/applications/clipbrd/fileutils.h
* PURPOSE: Clipboard file format helper functions.
* PROGRAMMERS: Ricardo Hanke
*/

View file

@ -15,6 +15,7 @@
#include "cliputils.h"
#include "fileutils.h"
#include "winutils.h"
#include "scrollutils.h"
#define MAX_STRING_LEN 255
#define DISPLAY_MENU_POS 2
@ -28,6 +29,7 @@ typedef struct _CLIPBOARD_GLOBALS
HMENU hMenu;
UINT uDisplayFormat;
UINT uCheckedItem;
HBITMAP hDspBmp;
} CLIPBOARD_GLOBALS;
extern CLIPBOARD_GLOBALS Globals;

View file

@ -0,0 +1,267 @@
/*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS Clipboard Viewer
* FILE: base/applications/clipbrd/scrollutils.c
* PURPOSE: Scrolling releated helper functions.
* PROGRAMMERS: Ricardo Hanke
*/
#include "precomp.h"
static int InternalSetScrollInfo(HWND hWnd, int nMin, int nMax, UINT nPage, int nPos, int fnBar)
{
SCROLLINFO si;
ZeroMemory(&si, sizeof(si));
si.cbSize = sizeof(si);
si.fMask = SIF_RANGE | SIF_PAGE | SIF_POS | SIF_DISABLENOSCROLL;
si.nMin = nMin;
si.nMax = nMax;
si.nPage = nPage;
si.nPos = nPos;
return SetScrollInfo(hWnd, fnBar, &si, TRUE);
}
void HandleKeyboardScrollEvents(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
switch (wParam)
{
case VK_UP:
{
SendMessage(hWnd, WM_VSCROLL, MAKELONG(SB_LINEUP, 0), 0);
break;
}
case VK_DOWN:
{
SendMessage(hWnd, WM_VSCROLL, MAKELONG(SB_LINEDOWN, 0), 0);
break;
}
case VK_LEFT:
{
SendMessage(hWnd, WM_HSCROLL, MAKELONG(SB_LINEUP, 0), 0);
break;
}
case VK_RIGHT:
{
SendMessage(hWnd, WM_HSCROLL, MAKELONG(SB_LINEDOWN, 0), 0);
break;
}
case VK_PRIOR:
{
SendMessage(hWnd, WM_VSCROLL, MAKELONG(SB_PAGEUP, 0), 0);
break;
}
case VK_NEXT:
{
SendMessage(hWnd, WM_VSCROLL, MAKELONG(SB_PAGEDOWN, 0), 0);
break;
}
default:
{
break;
}
}
}
void HandleHorizontalScrollEvents(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam, LPSCROLLSTATE state)
{
SCROLLINFO si;
int Delta;
int NewPos;
ZeroMemory(&si, sizeof(si));
si.cbSize = sizeof(si);
si.fMask = SIF_PAGE | SIF_TRACKPOS;
GetScrollInfo(hWnd, SB_HORZ, &si);
switch (LOWORD(wParam))
{
case SB_THUMBPOSITION:
case SB_THUMBTRACK:
{
NewPos = si.nTrackPos;
break;
}
case SB_LINELEFT:
{
NewPos = state->CurrentX - 5;
break;
}
case SB_LINERIGHT:
{
NewPos = state->CurrentX + 5;
break;
}
case SB_PAGELEFT:
{
NewPos = state->CurrentX - si.nPage;
break;
}
case SB_PAGERIGHT:
{
NewPos = state->CurrentX + si.nPage;
break;
}
default:
{
NewPos = state->CurrentX;
break;
}
}
NewPos = min(state->MaxX, max(0, NewPos));
if (NewPos == state->CurrentX)
{
return;
}
Delta = NewPos - state->CurrentX;
state->CurrentX = NewPos;
ScrollWindowEx(hWnd, -Delta, 0, NULL, NULL, NULL, NULL, SW_INVALIDATE);
si.cbSize = sizeof(si);
si.fMask = SIF_POS;
si.nPos = state->CurrentX;
SetScrollInfo(hWnd, SB_HORZ, &si, TRUE);
}
void HandleVerticalScrollEvents(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam, LPSCROLLSTATE state)
{
SCROLLINFO si;
int Delta;
int NewPos;
ZeroMemory(&si, sizeof(si));
si.cbSize = sizeof(si);
si.fMask = SIF_PAGE | SIF_TRACKPOS;
GetScrollInfo(hWnd, SB_VERT, &si);
switch (LOWORD(wParam))
{
case SB_THUMBPOSITION:
case SB_THUMBTRACK:
{
NewPos = si.nTrackPos;
break;
}
case SB_LINEUP:
{
NewPos = state->CurrentY - 5;
break;
}
case SB_LINEDOWN:
{
NewPos = state->CurrentY + 5;
break;
}
case SB_PAGEUP:
{
NewPos = state->CurrentY - si.nPage;
break;
}
case SB_PAGEDOWN:
{
NewPos = state->CurrentY + si.nPage;
break;
}
default:
{
NewPos = state->CurrentY;
break;
}
}
NewPos = min(state->MaxY, max(0, NewPos));
if (NewPos == state->CurrentY)
{
return;
}
Delta = NewPos - state->CurrentY;
state->CurrentY = NewPos;
ScrollWindowEx(hWnd, 0, -Delta, NULL, NULL, NULL, NULL, SW_INVALIDATE);
si.cbSize = sizeof(si);
si.fMask = SIF_POS;
si.nPos = state->CurrentY;
SetScrollInfo(hWnd, SB_VERT, &si, TRUE);
}
void UpdateWindowScrollState(HWND hWnd, HBITMAP hBitmap, LPSCROLLSTATE lpState)
{
BITMAP bmp;
RECT rc;
if (!GetObject(hBitmap, sizeof(BITMAP), &bmp))
{
bmp.bmWidth = 0;
bmp.bmHeight = 0;
}
if (!GetClientRect(hWnd, &rc))
{
SetRectEmpty(&rc);
}
lpState->MaxX = max(bmp.bmWidth - rc.right, 0);
lpState->CurrentX = min(lpState->CurrentX, lpState->MaxX);
InternalSetScrollInfo(hWnd, 0, bmp.bmWidth, rc.right, lpState->CurrentX, SB_HORZ);
lpState->MaxY = max(bmp.bmHeight - rc.bottom, 0);
lpState->CurrentY = min(lpState->CurrentY, lpState->MaxY);
InternalSetScrollInfo(hWnd, 0, bmp.bmHeight, rc.bottom, lpState->CurrentY, SB_VERT);
}
BOOL ScrollBlt(PAINTSTRUCT ps, HBITMAP hBmp, SCROLLSTATE state)
{
RECT rect;
BOOL ret;
HDC hdc;
int xpos;
int ypos;
rect.left = ps.rcPaint.left;
rect.top = ps.rcPaint.top;
rect.right = (ps.rcPaint.right - ps.rcPaint.left);
rect.bottom = (ps.rcPaint.bottom - ps.rcPaint.top);
xpos = ps.rcPaint.left + state.CurrentX;
ypos = ps.rcPaint.top + state.CurrentY;
ret = FALSE;
hdc = CreateCompatibleDC(ps.hdc);
if (hdc)
{
if (SelectObject(hdc, hBmp))
{
ret = BitBlt(ps.hdc, rect.left, rect.top, rect.right, rect.bottom, hdc, xpos, ypos, SRCCOPY);
}
DeleteDC(hdc);
}
return ret;
}

View file

@ -1,7 +1,7 @@
/*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS Clipboard Viewer
* FILE: base/applications/clipbrd/winutils.c
* FILE: base/applications/clipbrd/winutils.h
* PURPOSE: Miscellaneous helper functions.
* PROGRAMMERS: Ricardo Hanke
*/