[CLIPBRD]

- Change SetDIBitsToDeviceFromClipboard to correctly use the requested format instead of always using CF_DIBV5
- Enable/Disable the menu point "Save as..." dynamically
- Remove unneeded import libraries
- Add WS_EX_ACCEPTFILES window style and handle WM_DROPFILES
- Add some defines and structures for handling clipboard files (work in progress)
- Add Open and Save dialogs
Patch by Ricardo Hanke. CORE-10520

svn path=/trunk/; revision=69890
This commit is contained in:
Hermès Bélusca-Maïto 2015-11-14 16:45:41 +00:00
parent 9bccd93655
commit 1ec8189e87
10 changed files with 191 additions and 13 deletions

View file

@ -3,10 +3,11 @@ list(APPEND SOURCE
clipbrd.c
cliputils.c
winutils.c
fileutils.c
precomp.h)
add_executable(clipbrd ${SOURCE} clipbrd.rc)
add_pch(clipbrd precomp.h SOURCE)
set_module_type(clipbrd win32gui UNICODE)
add_importlibs(clipbrd hhctrl user32 gdi32 comctl32 comdlg32 advapi32 shell32 msvcrt kernel32)
add_importlibs(clipbrd hhctrl user32 gdi32 comdlg32 shell32 msvcrt kernel32)
add_cd_file(TARGET clipbrd DESTINATION reactos/system32 FOR all)

View file

@ -12,6 +12,103 @@ static const WCHAR szClassName[] = L"ClipBookWClass";
CLIPBOARD_GLOBALS Globals;
static void SaveClipboardToFile(void)
{
OPENFILENAMEW sfn;
WCHAR szFileName[MAX_PATH];
WCHAR szFilterMask[MAX_STRING_LEN + 10];
LPWSTR c;
ZeroMemory(&szFilterMask, sizeof(szFilterMask));
c = szFilterMask + LoadStringW(Globals.hInstance, STRING_FORMAT_NT, szFilterMask, MAX_STRING_LEN) + 1;
wcscpy(c, L"*.clp");
ZeroMemory(&szFileName, sizeof(szFileName));
ZeroMemory(&sfn, sizeof(sfn));
sfn.lStructSize = sizeof(sfn);
sfn.hwndOwner = Globals.hMainWnd;
sfn.hInstance = Globals.hInstance;
sfn.lpstrFilter = szFilterMask;
sfn.lpstrFile = szFileName;
sfn.nMaxFile = ARRAYSIZE(szFileName);
sfn.Flags = OFN_PATHMUSTEXIST | OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT;
sfn.lpstrDefExt = L"clp";
if (!GetSaveFileNameW(&sfn))
return;
if (!OpenClipboard(NULL))
{
ShowLastWin32Error(Globals.hMainWnd);
return;
}
WriteClipboardFile(szFileName);
CloseClipboard();
}
static void LoadClipboardFromFile(void)
{
OPENFILENAMEW ofn;
WCHAR szFileName[MAX_PATH];
WCHAR szFilterMask[MAX_STRING_LEN + 10];
LPWSTR c;
ZeroMemory(&szFilterMask, sizeof(szFilterMask));
c = szFilterMask + LoadStringW(Globals.hInstance, STRING_FORMAT_GEN, szFilterMask, MAX_STRING_LEN) + 1;
wcscpy(c, L"*.clp");
ZeroMemory(&szFileName, sizeof(szFileName));
ZeroMemory(&ofn, sizeof(ofn));
ofn.lStructSize = sizeof(ofn);
ofn.hwndOwner = Globals.hMainWnd;
ofn.hInstance = Globals.hInstance;
ofn.lpstrFilter = szFilterMask;
ofn.lpstrFile = szFileName;
ofn.nMaxFile = ARRAYSIZE(szFileName);
ofn.Flags = OFN_PATHMUSTEXIST | OFN_HIDEREADONLY | OFN_FILEMUSTEXIST;
if (!GetOpenFileNameW(&ofn))
return;
if (!OpenClipboard(NULL))
{
ShowLastWin32Error(Globals.hMainWnd);
return;
}
if (MessageBoxRes(Globals.hMainWnd, Globals.hInstance, STRING_DELETE_MSG, STRING_DELETE_TITLE, MB_ICONWARNING | MB_YESNO) == IDYES)
{
EmptyClipboard();
ReadClipboardFile(szFileName);
}
CloseClipboard();
}
static void LoadClipboardFromDrop(HDROP hDrop)
{
WCHAR szFileName[MAX_PATH];
DragQueryFileW(hDrop, 0, szFileName, ARRAYSIZE(szFileName));
DragFinish(hDrop);
if (!OpenClipboard(NULL))
{
ShowLastWin32Error(Globals.hMainWnd);
return;
}
if (MessageBoxRes(Globals.hMainWnd, Globals.hInstance, STRING_DELETE_MSG, STRING_DELETE_TITLE, MB_ICONWARNING | MB_YESNO) == IDYES)
{
EmptyClipboard();
ReadClipboardFile(szFileName);
}
CloseClipboard();
}
static void SetDisplayFormat(UINT uFormat)
{
CheckMenuItem(Globals.hMenu, Globals.uCheckedItem, MF_BYCOMMAND | MF_UNCHECKED);
@ -33,15 +130,17 @@ static void SetDisplayFormat(UINT uFormat)
static void InitMenuPopup(HMENU hMenu, LPARAM index)
{
if (GetMenuItemID(hMenu, 0) == CMD_DELETE)
if ((GetMenuItemID(hMenu, 0) == CMD_DELETE) || (GetMenuItemID(hMenu, 1) == CMD_SAVE_AS))
{
if (CountClipboardFormats() == 0)
{
EnableMenuItem(hMenu, CMD_DELETE, MF_GRAYED);
EnableMenuItem(hMenu, CMD_SAVE_AS, MF_GRAYED);
}
else
{
EnableMenuItem(hMenu, CMD_DELETE, MF_ENABLED);
EnableMenuItem(hMenu, CMD_SAVE_AS, MF_ENABLED);
}
}
@ -51,7 +150,7 @@ static void InitMenuPopup(HMENU hMenu, LPARAM index)
void UpdateDisplayMenu(void)
{
UINT uFormat;
WCHAR szFormatName[MAX_STRING_LEN];
WCHAR szFormatName[MAX_FMT_NAME_LEN + 1];
HMENU hMenu;
hMenu = GetSubMenu(Globals.hMenu, DISPLAY_MENU_POS);
@ -93,6 +192,18 @@ static int ClipboardCommandHandler(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM l
{
switch (LOWORD(wParam))
{
case CMD_OPEN:
{
LoadClipboardFromFile();
break;
}
case CMD_SAVE_AS:
{
SaveClipboardToFile();
break;
}
case CMD_EXIT:
{
PostMessageW(Globals.hMainWnd, WM_CLOSE, 0, 0);
@ -280,6 +391,12 @@ static LRESULT WINAPI MainWndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lP
break;
}
case WM_DROPFILES:
{
LoadClipboardFromDrop((HDROP)wParam);
break;
}
default:
{
return DefWindowProc(hWnd, uMsg, wParam, lParam);
@ -323,7 +440,7 @@ int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmdLi
}
LoadStringW(hInstance, STRING_CLIPBOARD, szBuffer, ARRAYSIZE(szBuffer));
Globals.hMainWnd = CreateWindowExW(WS_EX_CLIENTEDGE,
Globals.hMainWnd = CreateWindowExW(WS_EX_CLIENTEDGE | WS_EX_ACCEPTFILES,
szClassName,
szBuffer,
WS_OVERLAPPEDWINDOW | WS_HSCROLL | WS_VSCROLL,

View file

@ -0,0 +1,21 @@
/*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS Clipboard Viewer
* FILE: base/applications/clipbrd/fileutils.c
* PURPOSE: Clipboard file format helper functions.
* PROGRAMMERS: Ricardo Hanke
*/
#include "precomp.h"
void ReadClipboardFile(LPCWSTR lpFileName)
{
MessageBoxW(Globals.hMainWnd, L"This function is currently not implemented.", L"Clipboard", MB_OK | MB_ICONINFORMATION);
return;
}
void WriteClipboardFile(LPCWSTR lpFileName)
{
MessageBoxW(Globals.hMainWnd, L"This function is currently not implemented.", L"Clipboard", MB_OK | MB_ICONINFORMATION);
return;
}

View file

@ -0,0 +1,29 @@
/*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS Clipboard Viewer
* FILE: base/applications/clipbrd/fileutils.c
* PURPOSE: Clipboard file format helper functions.
* PROGRAMMERS: Ricardo Hanke
*/
#define CLIPBOARD_FORMAT_31 0xC350
#define CLIPBOARD_FORMAT_NT 0xC351
#define CLIPBOARD_FORMAT_BK 0xC352
#define MAX_FMT_NAME_LEN 79
typedef struct _CLIPBOARDFILEHEADER
{
WORD wFileIdentifier;
WORD wFormatCount;
} CLIPBOARDFILEHEADER;
typedef struct _CLIPBOARDFORMATHEADER
{
DWORD dwFormatID;
DWORD dwLenData;
DWORD dwOffData;
WCHAR szName[MAX_FMT_NAME_LEN];
} CLIPBOARDFORMATHEADER;
void ReadClipboardFile(LPCWSTR lpFileName);
void WriteClipboardFile(LPCWSTR lpFileName);

View file

@ -9,8 +9,8 @@ MAIN_MENU MENU
BEGIN
POPUP "&Datei"
BEGIN
MENUITEM "Ö&ffnen...", CMD_OPEN, GRAYED
MENUITEM "Speichern &unter...", CMD_SAVE_AS, GRAYED
MENUITEM "Ö&ffnen...", CMD_OPEN
MENUITEM "Speichern &unter...", CMD_SAVE_AS
MENUITEM SEPARATOR
MENUITEM "&Beenden", CMD_EXIT
END
@ -35,6 +35,8 @@ BEGIN
STRING_CLIPBOARD "Zwischenablage"
STRING_DELETE_MSG "Soll der Inhalt der Zwischenablage gelöscht werden?"
STRING_DELETE_TITLE "Zwischenablage löschen"
STRING_FORMAT_NT "Zwischenablagedateien für ReactOS (*.clp)"
STRING_FORMAT_GEN "Zwischenablagedateien (*.clp)"
END
STRINGTABLE

View file

@ -9,8 +9,8 @@ MAIN_MENU MENU
BEGIN
POPUP "&File"
BEGIN
MENUITEM "&Open...", CMD_OPEN, GRAYED
MENUITEM "Save &as...", CMD_SAVE_AS, GRAYED
MENUITEM "&Open...", CMD_OPEN
MENUITEM "Save &as...", CMD_SAVE_AS
MENUITEM SEPARATOR
MENUITEM "E&xit", CMD_EXIT
END
@ -35,6 +35,8 @@ BEGIN
STRING_CLIPBOARD "Clipboard"
STRING_DELETE_MSG "Clear contents of the Clipboard?"
STRING_DELETE_TITLE "Clear Clipboard"
STRING_FORMAT_NT "Clipboard files for ReactOS (*.clp)"
STRING_FORMAT_GEN "Clipboard files (*.clp)"
END
STRINGTABLE
@ -57,5 +59,5 @@ END
STRINGTABLE
BEGIN
ERROR_UNSUPPORTED_FORMAT "The clipboard contains data in a format, that cannot be displayed."
ERROR_UNSUPPORTED_FORMAT "The Clipboard contains data in a format, that cannot be displayed."
END

View file

@ -9,8 +9,8 @@ MAIN_MENU MENU
BEGIN
POPUP "&Fichier"
BEGIN
MENUITEM "&Ouvrir...", CMD_OPEN, GRAYED
MENUITEM "&Enregistrer sous...", CMD_SAVE_AS, GRAYED
MENUITEM "&Ouvrir...", CMD_OPEN
MENUITEM "&Enregistrer sous...", CMD_SAVE_AS
MENUITEM SEPARATOR
MENUITEM "&Quitter", CMD_EXIT
END
@ -35,6 +35,8 @@ BEGIN
STRING_CLIPBOARD "Presse-papiers"
STRING_DELETE_MSG "Voulez-vous effacer le contenu du Presse-papiers ?"
STRING_DELETE_TITLE "Effacer le Presse-papiers"
STRING_FORMAT_NT "Fichiers du Presse-papiers ReactOS (*.clp)"
STRING_FORMAT_GEN "Fichiers du Presse-papiers (*.clp)"
END
STRINGTABLE
@ -57,5 +59,5 @@ END
STRINGTABLE
BEGIN
ERROR_UNSUPPORTED_FORMAT "Le Presse-Papiers contient des données dans un format qui ne peut être affiché."
ERROR_UNSUPPORTED_FORMAT "Le Presse-papiers contient des données dans un format qui ne peut être affiché."
END

View file

@ -9,9 +9,11 @@
#include <wingdi.h>
#include <shellapi.h>
#include <htmlhelp.h>
#include <commdlg.h>
#include "resources.h"
#include "cliputils.h"
#include "fileutils.h"
#include "winutils.h"
#define MAX_STRING_LEN 255

View file

@ -16,6 +16,8 @@
#define STRING_CLIPBOARD 100
#define STRING_DELETE_MSG 101
#define STRING_DELETE_TITLE 102
#define STRING_FORMAT_NT 103
#define STRING_FORMAT_GEN 104
#define STRING_CF_UNKNOWN 200
#define STRING_CF_TEXT 201

View file

@ -118,7 +118,7 @@ void SetDIBitsToDeviceFromClipboard(UINT uFormat, HDC hdc, int XDest, int YDest,
if (!OpenClipboard(NULL))
return;
hGlobal = GetClipboardData(CF_DIBV5);
hGlobal = GetClipboardData(uFormat);
if (!hGlobal)
return;