Index: base/applications/clipbrd/CMakeLists.txt =================================================================== --- base/applications/clipbrd/CMakeLists.txt (revision 0) +++ base/applications/clipbrd/CMakeLists.txt (working copy) @@ -0,0 +1,10 @@ + +list(APPEND SOURCE + cliputils.c + winutils.c + clipbrd.c) + +add_executable(clipbrd ${SOURCE} resources.rc) +set_module_type(clipbrd win32gui UNICODE) +add_importlibs(clipbrd hhctrl user32 gdi32 comctl32 comdlg32 advapi32 shell32 msvcrt kernel32) +add_cd_file(TARGET clipbrd DESTINATION reactos/system32 FOR all) Index: base/applications/clipbrd/clipbrd.c =================================================================== --- base/applications/clipbrd/clipbrd.c (revision 0) +++ base/applications/clipbrd/clipbrd.c (working copy) @@ -0,0 +1,351 @@ +#include "clipbrd.h" + +CLIPBOARD_GLOBALS Globals; + + + +static void SetDisplayFormat(UINT uFormat) +{ + CheckMenuItem(Globals.hMenu, Globals.uCheckedItem, MF_BYCOMMAND | MF_UNCHECKED); + Globals.uCheckedItem = uFormat + CMD_AUTOMATIC; + CheckMenuItem(Globals.hMenu, Globals.uCheckedItem, MF_BYCOMMAND | MF_CHECKED); + + if (uFormat == 0) + { + Globals.uDisplayFormat = GetAutomaticClipboardFormat(); + } + else + { + Globals.uDisplayFormat = uFormat; + } + + InvalidateRect(Globals.hMainWnd, NULL, TRUE); + UpdateWindow(Globals.hMainWnd); +} + + + +static void InitMenuPopup(HMENU hMenu, LPARAM index) +{ + if (GetMenuItemID(hMenu, 0) == CMD_DELETE) + { + if (CountClipboardFormats() == 0) + { + EnableMenuItem(hMenu, CMD_DELETE, MF_GRAYED); + } + else + { + EnableMenuItem(hMenu, CMD_DELETE, MF_ENABLED); + } + } + + DrawMenuBar(Globals.hMainWnd); +} + + + +void UpdateDisplayMenu(void) +{ + UINT uFormat; + TCHAR szFormatName[MAX_STRING_LEN]; + HMENU hMenu; + + hMenu = GetSubMenu(Globals.hMenu, DISPLAY_MENU_POS); + + while (GetMenuItemCount(hMenu) > 1) + { + DeleteMenu(hMenu, 1, MF_BYPOSITION); + } + + if (CountClipboardFormats() == 0) + { + return; + } + + if (!OpenClipboard(NULL)) + { + return; + } + + AppendMenu(hMenu, MF_SEPARATOR, 0, NULL); + uFormat = EnumClipboardFormats(0); + + while (uFormat) + { + RetrieveClipboardFormatName(Globals.hInstance, uFormat, szFormatName, ARRAY_SIZE(szFormatName)); + + if (!IsClipboardFormatSupported(uFormat)) + { + AppendMenu(hMenu, MF_STRING | MF_GRAYED, 0, szFormatName); + } + else + { + AppendMenu(hMenu, MF_STRING, CMD_AUTOMATIC + uFormat, szFormatName); + } + + uFormat = EnumClipboardFormats(uFormat); + } + + CloseClipboard(); +} + + + +static int ClipboardCommandHandler(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) +{ + switch (LOWORD(wParam)) + { + case CMD_EXIT: + { + PostMessage(Globals.hMainWnd, WM_CLOSE, 0, 0); + break; + } + + case CMD_DELETE: + { + if (MessageBoxRes(Globals.hMainWnd, Globals.hInstance, STRING_DELETE_MSG, STRING_DELETE_TITLE, MB_ICONWARNING | MB_YESNO) == IDYES) + { + DeleteClipboardContent(); + } + break; + } + + case CMD_AUTOMATIC: + { + SetDisplayFormat(0); + break; + } + + case CMD_HELP: + { + HtmlHelp(Globals.hMainWnd, _T("clipbrd.chm"), 0, 0); + break; + } + + case CMD_ABOUT: + { + TCHAR szTitle[MAX_STRING_LEN]; + + LoadString(Globals.hInstance, STRING_CLIPBOARD, szTitle, ARRAY_SIZE(szTitle)); + ShellAbout(Globals.hMainWnd, szTitle, 0, NULL); + break; + } + + default: + { + break; + } + } + return 0; +} + + + +static void ClipboardPaintHandler(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) +{ + HDC hdc; + PAINTSTRUCT ps; + RECT rc; + + hdc = BeginPaint(hWnd, &ps); + GetClientRect(hWnd, &rc); + + switch (Globals.uDisplayFormat) + { + case CF_NONE: + { + break; + } + + case CF_UNICODETEXT: + { + DrawTextFromClipboard(hdc, &rc, DT_LEFT); + break; + } + + case CF_BITMAP: + { + BitBltFromClipboard(hdc, rc.left, rc.top, rc.right, rc.bottom, 0, 0, SRCCOPY); + break; + } + + case CF_ENHMETAFILE: + { + PlayEnhMetaFileFromClipboard(hdc, &rc); + break; + } + + case CF_METAFILEPICT: + { + PlayMetaFileFromClipboard(hdc, &rc); + break; + } + + default: + { + + DrawTextFromResource(Globals.hInstance, ERROR_UNSUPPORTED_FORMAT, hdc, &rc, DT_CENTER | DT_WORDBREAK); + break; + } + } + + EndPaint(hWnd, &ps); +} + + + +static LRESULT WINAPI MainWndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) +{ + switch(uMsg) + { + case WM_PAINT: + { + ClipboardPaintHandler(hWnd, uMsg, wParam, lParam); + break; + } + + case WM_SIZE: + { + InvalidateRect(hWnd, NULL, TRUE); + UpdateWindow(hWnd); + break; + } + + case WM_CREATE: + { + Globals.hMenu = GetMenu(hWnd); + Globals.hWndNext = SetClipboardViewer(hWnd); + UpdateDisplayMenu(); + SetDisplayFormat(0); + break; + } + + case WM_CLOSE: + { + DestroyWindow(hWnd); + break; + } + + case WM_DESTROY: + { + ChangeClipboardChain(hWnd, Globals.hWndNext); + PostQuitMessage(0); + break; + } + + case WM_CHANGECBCHAIN: + { + if ((HWND)wParam == Globals.hWndNext) + { + Globals.hWndNext = (HWND)lParam; + } + else if (Globals.hWndNext != NULL) + { + SendMessage(Globals.hWndNext, uMsg, wParam, lParam); + } + + break; + } + + case WM_DRAWCLIPBOARD: + { + UpdateDisplayMenu(); + SetDisplayFormat(0); + + SendMessage(Globals.hWndNext, uMsg, wParam, lParam); + break; + } + + case WM_COMMAND: + { + if ((LOWORD(wParam) > CMD_AUTOMATIC)) + { + SetDisplayFormat(LOWORD(wParam) - CMD_AUTOMATIC); + } + else + { + ClipboardCommandHandler(hWnd, uMsg, wParam, lParam); + } + break; + } + + case WM_INITMENUPOPUP: + { + InitMenuPopup((HMENU)wParam, lParam); + break; + } + + default: + { + return DefWindowProc(hWnd, uMsg, wParam, lParam); + } + } + return 0; +} + + + +int WINAPI _tWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow) +{ + MSG msg; + HACCEL hAccel; + WNDCLASSEX wndclass; + TCHAR szBuffer[MAX_STRING_LEN]; + + ZeroMemory(&Globals, sizeof(Globals)); + Globals.hInstance = hInstance; + + ZeroMemory(&wndclass, sizeof(wndclass)); + wndclass.cbSize = sizeof(wndclass); + wndclass.lpfnWndProc = MainWndProc; + wndclass.hInstance = hInstance; + wndclass.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(CLIP_ICON)); + wndclass.hCursor = LoadCursor(0, IDC_ARROW); + wndclass.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1); + wndclass.lpszMenuName = MAKEINTRESOURCE(MAIN_MENU); + wndclass.lpszClassName = szClassName; + + if (!RegisterClassEx(&wndclass)) + { + ShowLastWin32Error(NULL); + return 0; + } + + LoadString(hInstance, STRING_CLIPBOARD, szBuffer, ARRAY_SIZE(szBuffer)); + Globals.hMainWnd = CreateWindowEx(WS_EX_CLIENTEDGE, + szClassName, + szBuffer, + WS_OVERLAPPEDWINDOW | WS_HSCROLL | WS_VSCROLL, + CW_USEDEFAULT, + CW_USEDEFAULT, + 585, + 445, + NULL, + NULL, + Globals.hInstance, + NULL); + if (!Globals.hMainWnd) + { + ShowLastWin32Error(NULL); + return 0; + } + + ShowWindow(Globals.hMainWnd, nCmdShow); + UpdateWindow(Globals.hMainWnd); + + hAccel = LoadAccelerators(Globals.hInstance, MAKEINTRESOURCE(ID_ACCEL)); + if (!hAccel) + { + ShowLastWin32Error(Globals.hMainWnd); + } + + while (GetMessage(&msg, 0, 0, 0)) + { + if (!TranslateAccelerator(Globals.hMainWnd, hAccel, &msg)) + { + TranslateMessage(&msg); + DispatchMessage(&msg); + } + } + return (int)msg.wParam; +} Index: base/applications/clipbrd/clipbrd.h =================================================================== --- base/applications/clipbrd/clipbrd.h (revision 0) +++ base/applications/clipbrd/clipbrd.h (working copy) @@ -0,0 +1,33 @@ +#pragma once + +#include +#include +#include +#include +#include +#include +#include + +#include "resources.h" +#include "cliputils.h" +#include "winutils.h" + +#define ARRAY_SIZE(a) (sizeof(a)/sizeof((a)[0])) + +#define MAX_STRING_LEN 255 +#define DISPLAY_MENU_POS 2 +#define CF_NONE 0 + +typedef struct +{ + HINSTANCE hInstance; + HWND hMainWnd; + HWND hWndNext; + HMENU hMenu; + UINT uDisplayFormat; + UINT uCheckedItem; +} CLIPBOARD_GLOBALS; + +static const TCHAR szClassName[] = _T("CLIPBRDCLASS"); + +extern CLIPBOARD_GLOBALS Globals; Index: base/applications/clipbrd/cliputils.c =================================================================== --- base/applications/clipbrd/cliputils.c (revision 0) +++ base/applications/clipbrd/cliputils.c (working copy) @@ -0,0 +1,139 @@ +#include "clipbrd.h" + + +int GetPredefinedClipboardFormatName(HINSTANCE hInstance, UINT uFormat, LPTSTR lpszFormat, UINT cch) +{ + switch (uFormat) + { + case CF_TEXT: + { + return LoadString(hInstance, STRING_CF_TEXT, lpszFormat, cch); + } + + case CF_BITMAP: + { + return LoadString(hInstance, STRING_CF_BITMAP, lpszFormat, cch); + } + + case CF_OEMTEXT: + { + return LoadString(hInstance, STRING_CF_OEMTEXT, lpszFormat, cch); + } + + case CF_UNICODETEXT: + { + return LoadString(hInstance, STRING_CF_UNICODETEXT, lpszFormat, cch); + } + + case CF_DIB: + { + return LoadString(hInstance, STRING_CF_DIB, lpszFormat, cch); + } + + case CF_LOCALE: + { + return LoadString(hInstance, STRING_CF_LOCALE, lpszFormat, cch); + } + + case CF_ENHMETAFILE: + { + return LoadString(hInstance, STRING_CF_ENHMETAFILE, lpszFormat, cch); + } + + case CF_METAFILEPICT: + { + return LoadString(hInstance, STRING_CF_METAFILEPICT, lpszFormat, cch); + } + + case CF_PALETTE: + { + return LoadString(hInstance, STRING_CF_PALETTE, lpszFormat, cch); + } + + case CF_DIBV5: + { + return LoadString(hInstance, STRING_CF_DIBV5, lpszFormat, cch); + } + + default: + { + return 0; + } + } +} + + + +void RetrieveClipboardFormatName(HINSTANCE hInstance, UINT uFormat, LPTSTR lpszFormat, UINT cch) +{ + if (!GetPredefinedClipboardFormatName(hInstance, uFormat, lpszFormat, cch)) + { + if (!GetClipboardFormatName(uFormat, lpszFormat, cch)) + { + LoadString(hInstance, STRING_CF_UNKNOWN, lpszFormat, cch); + } + } +} + + + +void DeleteClipboardContent(void) +{ + if (!OpenClipboard(NULL)) + { + ShowLastWin32Error(Globals.hMainWnd); + return; + } + + if (!EmptyClipboard()) + { + ShowLastWin32Error(Globals.hMainWnd); + } + + if (!CloseClipboard()) + { + ShowLastWin32Error(Globals.hMainWnd); + } +} + + + +UINT GetAutomaticClipboardFormat(void) +{ + UINT uFormatList[] = {CF_UNICODETEXT, CF_ENHMETAFILE, CF_METAFILEPICT, CF_BITMAP}; + + return GetPriorityClipboardFormat(uFormatList, 4); +} + + + +BOOL IsClipboardFormatSupported(UINT uFormat) +{ + switch (uFormat) + { + case CF_UNICODETEXT: + { + return TRUE; + } + + case CF_BITMAP: + { + return TRUE; + } + + case CF_ENHMETAFILE: + { + return TRUE; + } + + case CF_METAFILEPICT: + { + return TRUE; + } + + default: + { + return FALSE; + } + } +} Index: base/applications/clipbrd/cliputils.h =================================================================== --- base/applications/clipbrd/cliputils.h (revision 0) +++ base/applications/clipbrd/cliputils.h (working copy) @@ -0,0 +1,5 @@ +int GetPredefinedClipboardFormatName(HINSTANCE hInstance, UINT uFormat, LPTSTR lpszFormat, UINT cch); +void RetrieveClipboardFormatName(HINSTANCE hInstance, UINT uFormat, LPTSTR lpszFormat, UINT cch); +void DeleteClipboardContent(void); +UINT GetAutomaticClipboardFormat(void); +BOOL IsClipboardFormatSupported(UINT uFormat); Index: base/applications/clipbrd/lang/de-DE.rc =================================================================== --- base/applications/clipbrd/lang/de-DE.rc (revision 0) +++ base/applications/clipbrd/lang/de-DE.rc (working copy) @@ -0,0 +1,62 @@ +LANGUAGE LANG_GERMAN, SUBLANG_NEUTRAL + +ID_ACCEL ACCELERATORS +BEGIN + VK_DELETE, CMD_DELETE, VIRTKEY +END + + +MAIN_MENU MENU +BEGIN + POPUP "&Datei" + BEGIN + MENUITEM "Ö&ffnen...", CMD_OPEN, GRAYED + MENUITEM "Speichern &unter...", CMD_SAVE_AS, GRAYED + MENUITEM SEPARATOR + MENUITEM "&Beenden", CMD_EXIT + END + POPUP "&Bearbeiten" + BEGIN + MENUITEM "&Löschen\tEntf", CMD_DELETE + END + POPUP "&Anzeige" + BEGIN + MENUITEM "&Automatisch", CMD_AUTOMATIC + END + POPUP "&Hilfe" + BEGIN + MENUITEM "&Hilfethemen", CMD_HELP + MENUITEM SEPARATOR + MENUITEM "Inf&o", CMD_ABOUT + END +END + + +STRINGTABLE +BEGIN + STRING_CLIPBOARD "Zwischenablage" + STRING_DELETE_MSG "Soll der Inhalt der Zwischenablage gelöscht werden?" + STRING_DELETE_TITLE "Zwischenablage löschen" +END + + +STRINGTABLE +BEGIN + STRING_CF_UNKNOWN "Unbekanntes Format" + STRING_CF_TEXT "Text" + STRING_CF_BITMAP "Bitmap" + STRING_CF_OEMTEXT "OEM-Text" + STRING_CF_UNICODETEXT "Unicodetext" + STRING_CF_DIB "DIB-Bitmap" + STRING_CF_LOCALE "Gebietsschema" + STRING_CF_ENHMETAFILE "Erweiterte Metadatei" + STRING_CF_METAFILEPICT "Metadatei" + STRING_CF_PALETTE "Farbpalette" + STRING_CF_DIBV5 "DIBV5-Bitmap" +END + + +STRINGTABLE +BEGIN + ERROR_UNSUPPORTED_FORMAT "Die Daten in der Zwischenablage liegen in einem Format vor, welches nicht angezeigt werden kann." +END Index: base/applications/clipbrd/lang/en-US.rc =================================================================== --- base/applications/clipbrd/lang/en-US.rc (revision 0) +++ base/applications/clipbrd/lang/en-US.rc (working copy) @@ -0,0 +1,62 @@ +LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US + +ID_ACCEL ACCELERATORS +BEGIN + VK_DELETE, CMD_DELETE, VIRTKEY +END + + +MAIN_MENU MENU +BEGIN + POPUP "&File" + BEGIN + MENUITEM "&Open...", CMD_OPEN, GRAYED + MENUITEM "Save &as...", CMD_SAVE_AS, GRAYED + MENUITEM SEPARATOR + MENUITEM "E&xit", CMD_EXIT + END + POPUP "&Edit" + BEGIN + MENUITEM "&Delete\tDel", CMD_DELETE + END + POPUP "&Display" + BEGIN + MENUITEM "&Automatic", CMD_AUTOMATIC + END + POPUP "&Help" + BEGIN + MENUITEM "&Help Topics", CMD_HELP + MENUITEM SEPARATOR + MENUITEM "&About", CMD_ABOUT + END +END + + +STRINGTABLE +BEGIN + STRING_CLIPBOARD "Clipboard" + STRING_DELETE_MSG "Clear contents of the Clipboard?" + STRING_DELETE_TITLE "Clear Clipboard" +END + + +STRINGTABLE +BEGIN + STRING_CF_UNKNOWN "Unknown Format" + STRING_CF_TEXT "Text" + STRING_CF_BITMAP "Bitmap" + STRING_CF_OEMTEXT "OEM Text" + STRING_CF_UNICODETEXT "Unicode Text" + STRING_CF_DIB "DIB Bitmap" + STRING_CF_LOCALE "Locale Data" + STRING_CF_ENHMETAFILE "Enhanced Metafile" + STRING_CF_METAFILEPICT "Metafile" + STRING_CF_PALETTE "Color Palette" + STRING_CF_DIBV5 "DIBV5 Bitmap" +END + + +STRINGTABLE +BEGIN + ERROR_UNSUPPORTED_FORMAT "The clipboard contains data in a format, that cannot be displayed." +END Index: base/applications/clipbrd/res/clipbrd.ico =================================================================== Cannot display: file marked as a binary type. svn:mime-type = application/octet-stream Index: base/applications/clipbrd/res/clipbrd.ico =================================================================== --- base/applications/clipbrd/res/clipbrd.ico (revision 0) +++ base/applications/clipbrd/res/clipbrd.ico (working copy) Property changes on: base/applications/clipbrd/res/clipbrd.ico ___________________________________________________________________ Added: svn:mime-type ## -0,0 +1 ## +application/octet-stream \ No newline at end of property Index: base/applications/clipbrd/resources.h =================================================================== --- base/applications/clipbrd/resources.h (revision 0) +++ base/applications/clipbrd/resources.h (working copy) @@ -0,0 +1,32 @@ +#pragma once + +#define MAIN_MENU 100 +#define CLIP_ICON 101 +#define ID_ACCEL 102 + +#define CMD_OPEN 100 +#define CMD_SAVE_AS 101 +#define CMD_EXIT 102 +#define CMD_DELETE 103 +#define CMD_HELP 105 +#define CMD_ABOUT 106 + +#define CMD_AUTOMATIC 1000 + +#define STRING_CLIPBOARD 100 +#define STRING_DELETE_MSG 101 +#define STRING_DELETE_TITLE 102 + +#define STRING_CF_UNKNOWN 200 +#define STRING_CF_TEXT 201 +#define STRING_CF_BITMAP 202 +#define STRING_CF_OEMTEXT 203 +#define STRING_CF_UNICODETEXT 204 +#define STRING_CF_DIB 205 +#define STRING_CF_LOCALE 206 +#define STRING_CF_ENHMETAFILE 207 +#define STRING_CF_METAFILEPICT 208 +#define STRING_CF_PALETTE 209 +#define STRING_CF_DIBV5 210 + +#define ERROR_UNSUPPORTED_FORMAT 300 Index: base/applications/clipbrd/resources.rc =================================================================== --- base/applications/clipbrd/resources.rc (revision 0) +++ base/applications/clipbrd/resources.rc (working copy) @@ -0,0 +1,23 @@ +#include +#include + +#include "resources.h" + +#define REACTOS_STR_FILE_DESCRIPTION "ReactOS Clipboard Viewer" +#define REACTOS_STR_INTERNAL_NAME "clipbrd" +#define REACTOS_STR_ORIGINAL_FILENAME "clipbrd.exe" +#include + +CLIP_ICON ICON "res/clipbrd.ico" + +#include + +/* UTF-8 */ +#pragma code_page(65001) + +#ifdef LANGUAGE_DE_DE + #include "lang/de-DE.rc" +#endif +#ifdef LANGUAGE_EN_US + #include "lang/en-US.rc" +#endif Index: base/applications/clipbrd/winutils.c =================================================================== --- base/applications/clipbrd/winutils.c (revision 0) +++ base/applications/clipbrd/winutils.c (working copy) @@ -0,0 +1,127 @@ +#include "clipbrd.h" + + + +void ShowLastWin32Error(HWND hwndParent) +{ + DWORD dwError; + + dwError = GetLastError(); + if (dwError != NO_ERROR) + { + LPTSTR lpMsgBuf = NULL; + + FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM, NULL, dwError, 0, (LPTSTR)&lpMsgBuf, 0, NULL); + MessageBox(hwndParent, lpMsgBuf, NULL, MB_OK | MB_ICONERROR); + LocalFree(lpMsgBuf); + } +} + + + +int DrawTextFromResource(HINSTANCE hInstance, UINT uID, HDC hDC, LPRECT lpRect, UINT uFormat) +{ + const TCHAR *lpBuffer; + int nCount; + + nCount = LoadString(hInstance, uID, (LPWSTR)&lpBuffer, 0); + if (nCount) + { + return DrawText(hDC, lpBuffer, nCount, lpRect, uFormat); + } + else + { + return 0; + } +} + + + +int MessageBoxRes(HWND hWnd, HINSTANCE hInstance, UINT uText, UINT uCaption, UINT uType) +{ + MSGBOXPARAMS mb; + + ZeroMemory(&mb, sizeof(mb)); + mb.cbSize = sizeof(mb); + mb.hwndOwner = hWnd; + mb.hInstance = hInstance; + mb.lpszText = MAKEINTRESOURCE(uText); + mb.lpszCaption = MAKEINTRESOURCE(uCaption); + mb.dwStyle = uType; + mb.dwLanguageId = MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT); + + return MessageBoxIndirect(&mb); +} + + + +void DrawTextFromClipboard(HDC hDC, LPRECT lpRect, UINT uFormat) +{ + if (OpenClipboard(NULL)) + { + HGLOBAL hGlobal; + LPWSTR lpchText; + + hGlobal = GetClipboardData(CF_UNICODETEXT); + lpchText = GlobalLock(hGlobal); + DrawText(hDC, lpchText, -1, lpRect, uFormat); + GlobalUnlock(hGlobal); + CloseClipboard(); + } +} + + + +void BitBltFromClipboard(HDC hdcDest, int nXDest, int nYDest, int nWidth, int nHeight, int nXSrc, int nYSrc, DWORD dwRop) +{ + if (OpenClipboard(NULL)) + { + HDC hdcMem; + + hdcMem = CreateCompatibleDC(hdcDest); + if (hdcMem) + { + HBITMAP hbm; + + hbm = (HBITMAP)GetClipboardData(CF_BITMAP); + SelectObject(hdcMem, hbm); + BitBlt(hdcDest, nXDest, nYDest, nWidth, nHeight, hdcMem, nXSrc, nYSrc, dwRop); + DeleteDC(hdcMem); + } + CloseClipboard(); + } +} + + + +void PlayMetaFileFromClipboard(HDC hdc, const RECT *lpRect) +{ + if (OpenClipboard(NULL)) + { + LPMETAFILEPICT mp; + HGLOBAL hGlobal; + + hGlobal = GetClipboardData(CF_METAFILEPICT); + mp = (LPMETAFILEPICT)GlobalLock(hGlobal); + SetMapMode(hdc, mp->mm); + SetViewportExtEx(hdc, lpRect->right, lpRect->bottom, NULL); + SetViewportOrgEx(hdc, lpRect->left, lpRect->top, NULL); + PlayMetaFile(hdc, mp->hMF); + GlobalUnlock(hGlobal); + CloseClipboard(); + } +} + + + +void PlayEnhMetaFileFromClipboard(HDC hdc, const RECT *lpRect) +{ + if (OpenClipboard(NULL)) + { + HENHMETAFILE hEmf; + + hEmf = GetClipboardData(CF_ENHMETAFILE); + PlayEnhMetaFile(hdc, hEmf, lpRect); + CloseClipboard(); + } +} Index: base/applications/clipbrd/winutils.h =================================================================== --- base/applications/clipbrd/winutils.h (revision 0) +++ base/applications/clipbrd/winutils.h (working copy) @@ -0,0 +1,7 @@ +void ShowLastWin32Error(HWND hwndParent); +int DrawTextFromResource(HINSTANCE hInstance, UINT uID, HDC hDC, LPRECT lpRect, UINT uFormat); +int MessageBoxRes(HWND hWnd, HINSTANCE hInstance, UINT uText, UINT uCaption, UINT uType); +void DrawTextFromClipboard(HDC hDC, LPRECT lpRect, UINT uFormat); +void BitBltFromClipboard(HDC hdcDest, int nXDest, int nYDest, int nWidth, int nHeight, int nXSrc, int nYSrc, DWORD dwRop); +void PlayMetaFileFromClipboard(HDC hdc, const RECT *lpRect); +void PlayEnhMetaFileFromClipboard(HDC hdc, const RECT *lpRect); Index: base/applications/clipbrd/clipbrd.c =================================================================== --- base/applications/clipbrd/clipbrd.c (revision 0) +++ base/applications/clipbrd/clipbrd.c (working copy) @@ -0,0 +1,351 @@ +#include "clipbrd.h" + +CLIPBOARD_GLOBALS Globals; + + + +static void SetDisplayFormat(UINT uFormat) +{ + CheckMenuItem(Globals.hMenu, Globals.uCheckedItem, MF_BYCOMMAND | MF_UNCHECKED); + Globals.uCheckedItem = uFormat + CMD_AUTOMATIC; + CheckMenuItem(Globals.hMenu, Globals.uCheckedItem, MF_BYCOMMAND | MF_CHECKED); + + if (uFormat == 0) + { + Globals.uDisplayFormat = GetAutomaticClipboardFormat(); + } + else + { + Globals.uDisplayFormat = uFormat; + } + + InvalidateRect(Globals.hMainWnd, NULL, TRUE); + UpdateWindow(Globals.hMainWnd); +} + + + +static void InitMenuPopup(HMENU hMenu, LPARAM index) +{ + if (GetMenuItemID(hMenu, 0) == CMD_DELETE) + { + if (CountClipboardFormats() == 0) + { + EnableMenuItem(hMenu, CMD_DELETE, MF_GRAYED); + } + else + { + EnableMenuItem(hMenu, CMD_DELETE, MF_ENABLED); + } + } + + DrawMenuBar(Globals.hMainWnd); +} + + + +void UpdateDisplayMenu(void) +{ + UINT uFormat; + TCHAR szFormatName[MAX_STRING_LEN]; + HMENU hMenu; + + hMenu = GetSubMenu(Globals.hMenu, DISPLAY_MENU_POS); + + while (GetMenuItemCount(hMenu) > 1) + { + DeleteMenu(hMenu, 1, MF_BYPOSITION); + } + + if (CountClipboardFormats() == 0) + { + return; + } + + if (!OpenClipboard(NULL)) + { + return; + } + + AppendMenu(hMenu, MF_SEPARATOR, 0, NULL); + uFormat = EnumClipboardFormats(0); + + while (uFormat) + { + RetrieveClipboardFormatName(Globals.hInstance, uFormat, szFormatName, ARRAY_SIZE(szFormatName)); + + if (!IsClipboardFormatSupported(uFormat)) + { + AppendMenu(hMenu, MF_STRING | MF_GRAYED, 0, szFormatName); + } + else + { + AppendMenu(hMenu, MF_STRING, CMD_AUTOMATIC + uFormat, szFormatName); + } + + uFormat = EnumClipboardFormats(uFormat); + } + + CloseClipboard(); +} + + + +static int ClipboardCommandHandler(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) +{ + switch (LOWORD(wParam)) + { + case CMD_EXIT: + { + PostMessage(Globals.hMainWnd, WM_CLOSE, 0, 0); + break; + } + + case CMD_DELETE: + { + if (MessageBoxRes(Globals.hMainWnd, Globals.hInstance, STRING_DELETE_MSG, STRING_DELETE_TITLE, MB_ICONWARNING | MB_YESNO) == IDYES) + { + DeleteClipboardContent(); + } + break; + } + + case CMD_AUTOMATIC: + { + SetDisplayFormat(0); + break; + } + + case CMD_HELP: + { + HtmlHelp(Globals.hMainWnd, _T("clipbrd.chm"), 0, 0); + break; + } + + case CMD_ABOUT: + { + TCHAR szTitle[MAX_STRING_LEN]; + + LoadString(Globals.hInstance, STRING_CLIPBOARD, szTitle, ARRAY_SIZE(szTitle)); + ShellAbout(Globals.hMainWnd, szTitle, 0, NULL); + break; + } + + default: + { + break; + } + } + return 0; +} + + + +static void ClipboardPaintHandler(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) +{ + HDC hdc; + PAINTSTRUCT ps; + RECT rc; + + hdc = BeginPaint(hWnd, &ps); + GetClientRect(hWnd, &rc); + + switch (Globals.uDisplayFormat) + { + case CF_NONE: + { + break; + } + + case CF_UNICODETEXT: + { + DrawTextFromClipboard(hdc, &rc, DT_LEFT); + break; + } + + case CF_BITMAP: + { + BitBltFromClipboard(hdc, rc.left, rc.top, rc.right, rc.bottom, 0, 0, SRCCOPY); + break; + } + + case CF_ENHMETAFILE: + { + PlayEnhMetaFileFromClipboard(hdc, &rc); + break; + } + + case CF_METAFILEPICT: + { + PlayMetaFileFromClipboard(hdc, &rc); + break; + } + + default: + { + + DrawTextFromResource(Globals.hInstance, ERROR_UNSUPPORTED_FORMAT, hdc, &rc, DT_CENTER | DT_WORDBREAK); + break; + } + } + + EndPaint(hWnd, &ps); +} + + + +static LRESULT WINAPI MainWndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) +{ + switch(uMsg) + { + case WM_PAINT: + { + ClipboardPaintHandler(hWnd, uMsg, wParam, lParam); + break; + } + + case WM_SIZE: + { + InvalidateRect(hWnd, NULL, TRUE); + UpdateWindow(hWnd); + break; + } + + case WM_CREATE: + { + Globals.hMenu = GetMenu(hWnd); + Globals.hWndNext = SetClipboardViewer(hWnd); + UpdateDisplayMenu(); + SetDisplayFormat(0); + break; + } + + case WM_CLOSE: + { + DestroyWindow(hWnd); + break; + } + + case WM_DESTROY: + { + ChangeClipboardChain(hWnd, Globals.hWndNext); + PostQuitMessage(0); + break; + } + + case WM_CHANGECBCHAIN: + { + if ((HWND)wParam == Globals.hWndNext) + { + Globals.hWndNext = (HWND)lParam; + } + else if (Globals.hWndNext != NULL) + { + SendMessage(Globals.hWndNext, uMsg, wParam, lParam); + } + + break; + } + + case WM_DRAWCLIPBOARD: + { + UpdateDisplayMenu(); + SetDisplayFormat(0); + + SendMessage(Globals.hWndNext, uMsg, wParam, lParam); + break; + } + + case WM_COMMAND: + { + if ((LOWORD(wParam) > CMD_AUTOMATIC)) + { + SetDisplayFormat(LOWORD(wParam) - CMD_AUTOMATIC); + } + else + { + ClipboardCommandHandler(hWnd, uMsg, wParam, lParam); + } + break; + } + + case WM_INITMENUPOPUP: + { + InitMenuPopup((HMENU)wParam, lParam); + break; + } + + default: + { + return DefWindowProc(hWnd, uMsg, wParam, lParam); + } + } + return 0; +} + + + +int WINAPI _tWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow) +{ + MSG msg; + HACCEL hAccel; + WNDCLASSEX wndclass; + TCHAR szBuffer[MAX_STRING_LEN]; + + ZeroMemory(&Globals, sizeof(Globals)); + Globals.hInstance = hInstance; + + ZeroMemory(&wndclass, sizeof(wndclass)); + wndclass.cbSize = sizeof(wndclass); + wndclass.lpfnWndProc = MainWndProc; + wndclass.hInstance = hInstance; + wndclass.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(CLIP_ICON)); + wndclass.hCursor = LoadCursor(0, IDC_ARROW); + wndclass.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1); + wndclass.lpszMenuName = MAKEINTRESOURCE(MAIN_MENU); + wndclass.lpszClassName = szClassName; + + if (!RegisterClassEx(&wndclass)) + { + ShowLastWin32Error(NULL); + return 0; + } + + LoadString(hInstance, STRING_CLIPBOARD, szBuffer, ARRAY_SIZE(szBuffer)); + Globals.hMainWnd = CreateWindowEx(WS_EX_CLIENTEDGE, + szClassName, + szBuffer, + WS_OVERLAPPEDWINDOW | WS_HSCROLL | WS_VSCROLL, + CW_USEDEFAULT, + CW_USEDEFAULT, + 585, + 445, + NULL, + NULL, + Globals.hInstance, + NULL); + if (!Globals.hMainWnd) + { + ShowLastWin32Error(NULL); + return 0; + } + + ShowWindow(Globals.hMainWnd, nCmdShow); + UpdateWindow(Globals.hMainWnd); + + hAccel = LoadAccelerators(Globals.hInstance, MAKEINTRESOURCE(ID_ACCEL)); + if (!hAccel) + { + ShowLastWin32Error(Globals.hMainWnd); + } + + while (GetMessage(&msg, 0, 0, 0)) + { + if (!TranslateAccelerator(Globals.hMainWnd, hAccel, &msg)) + { + TranslateMessage(&msg); + DispatchMessage(&msg); + } + } + return (int)msg.wParam; +} Index: base/applications/clipbrd/clipbrd.h =================================================================== --- base/applications/clipbrd/clipbrd.h (revision 0) +++ base/applications/clipbrd/clipbrd.h (working copy) @@ -0,0 +1,33 @@ +#pragma once + +#include +#include +#include +#include +#include +#include +#include + +#include "resources.h" +#include "cliputils.h" +#include "winutils.h" + +#define ARRAY_SIZE(a) (sizeof(a)/sizeof((a)[0])) + +#define MAX_STRING_LEN 255 +#define DISPLAY_MENU_POS 2 +#define CF_NONE 0 + +typedef struct +{ + HINSTANCE hInstance; + HWND hMainWnd; + HWND hWndNext; + HMENU hMenu; + UINT uDisplayFormat; + UINT uCheckedItem; +} CLIPBOARD_GLOBALS; + +static const TCHAR szClassName[] = _T("CLIPBRDCLASS"); + +extern CLIPBOARD_GLOBALS Globals; Index: base/applications/clipbrd/cliputils.c =================================================================== --- base/applications/clipbrd/cliputils.c (revision 0) +++ base/applications/clipbrd/cliputils.c (working copy) @@ -0,0 +1,139 @@ +#include "clipbrd.h" + + +int GetPredefinedClipboardFormatName(HINSTANCE hInstance, UINT uFormat, LPTSTR lpszFormat, UINT cch) +{ + switch (uFormat) + { + case CF_TEXT: + { + return LoadString(hInstance, STRING_CF_TEXT, lpszFormat, cch); + } + + case CF_BITMAP: + { + return LoadString(hInstance, STRING_CF_BITMAP, lpszFormat, cch); + } + + case CF_OEMTEXT: + { + return LoadString(hInstance, STRING_CF_OEMTEXT, lpszFormat, cch); + } + + case CF_UNICODETEXT: + { + return LoadString(hInstance, STRING_CF_UNICODETEXT, lpszFormat, cch); + } + + case CF_DIB: + { + return LoadString(hInstance, STRING_CF_DIB, lpszFormat, cch); + } + + case CF_LOCALE: + { + return LoadString(hInstance, STRING_CF_LOCALE, lpszFormat, cch); + } + + case CF_ENHMETAFILE: + { + return LoadString(hInstance, STRING_CF_ENHMETAFILE, lpszFormat, cch); + } + + case CF_METAFILEPICT: + { + return LoadString(hInstance, STRING_CF_METAFILEPICT, lpszFormat, cch); + } + + case CF_PALETTE: + { + return LoadString(hInstance, STRING_CF_PALETTE, lpszFormat, cch); + } + + case CF_DIBV5: + { + return LoadString(hInstance, STRING_CF_DIBV5, lpszFormat, cch); + } + + default: + { + return 0; + } + } +} + + + +void RetrieveClipboardFormatName(HINSTANCE hInstance, UINT uFormat, LPTSTR lpszFormat, UINT cch) +{ + if (!GetPredefinedClipboardFormatName(hInstance, uFormat, lpszFormat, cch)) + { + if (!GetClipboardFormatName(uFormat, lpszFormat, cch)) + { + LoadString(hInstance, STRING_CF_UNKNOWN, lpszFormat, cch); + } + } +} + + + +void DeleteClipboardContent(void) +{ + if (!OpenClipboard(NULL)) + { + ShowLastWin32Error(Globals.hMainWnd); + return; + } + + if (!EmptyClipboard()) + { + ShowLastWin32Error(Globals.hMainWnd); + } + + if (!CloseClipboard()) + { + ShowLastWin32Error(Globals.hMainWnd); + } +} + + + +UINT GetAutomaticClipboardFormat(void) +{ + UINT uFormatList[] = {CF_UNICODETEXT, CF_ENHMETAFILE, CF_METAFILEPICT, CF_BITMAP}; + + return GetPriorityClipboardFormat(uFormatList, 4); +} + + + +BOOL IsClipboardFormatSupported(UINT uFormat) +{ + switch (uFormat) + { + case CF_UNICODETEXT: + { + return TRUE; + } + + case CF_BITMAP: + { + return TRUE; + } + + case CF_ENHMETAFILE: + { + return TRUE; + } + + case CF_METAFILEPICT: + { + return TRUE; + } + + default: + { + return FALSE; + } + } +} Index: base/applications/clipbrd/cliputils.h =================================================================== --- base/applications/clipbrd/cliputils.h (revision 0) +++ base/applications/clipbrd/cliputils.h (working copy) @@ -0,0 +1,5 @@ +int GetPredefinedClipboardFormatName(HINSTANCE hInstance, UINT uFormat, LPTSTR lpszFormat, UINT cch); +void RetrieveClipboardFormatName(HINSTANCE hInstance, UINT uFormat, LPTSTR lpszFormat, UINT cch); +void DeleteClipboardContent(void); +UINT GetAutomaticClipboardFormat(void); +BOOL IsClipboardFormatSupported(UINT uFormat); Index: base/applications/clipbrd/CMakeLists.txt =================================================================== --- base/applications/clipbrd/CMakeLists.txt (revision 0) +++ base/applications/clipbrd/CMakeLists.txt (working copy) @@ -0,0 +1,10 @@ + +list(APPEND SOURCE + cliputils.c + winutils.c + clipbrd.c) + +add_executable(clipbrd ${SOURCE} resources.rc) +set_module_type(clipbrd win32gui UNICODE) +add_importlibs(clipbrd hhctrl user32 gdi32 comctl32 comdlg32 advapi32 shell32 msvcrt kernel32) +add_cd_file(TARGET clipbrd DESTINATION reactos/system32 FOR all) Index: base/applications/clipbrd/lang/de-DE.rc =================================================================== --- base/applications/clipbrd/lang/de-DE.rc (revision 0) +++ base/applications/clipbrd/lang/de-DE.rc (working copy) @@ -0,0 +1,62 @@ +LANGUAGE LANG_GERMAN, SUBLANG_NEUTRAL + +ID_ACCEL ACCELERATORS +BEGIN + VK_DELETE, CMD_DELETE, VIRTKEY +END + + +MAIN_MENU MENU +BEGIN + POPUP "&Datei" + BEGIN + MENUITEM "Ö&ffnen...", CMD_OPEN, GRAYED + MENUITEM "Speichern &unter...", CMD_SAVE_AS, GRAYED + MENUITEM SEPARATOR + MENUITEM "&Beenden", CMD_EXIT + END + POPUP "&Bearbeiten" + BEGIN + MENUITEM "&Löschen\tEntf", CMD_DELETE + END + POPUP "&Anzeige" + BEGIN + MENUITEM "&Automatisch", CMD_AUTOMATIC + END + POPUP "&Hilfe" + BEGIN + MENUITEM "&Hilfethemen", CMD_HELP + MENUITEM SEPARATOR + MENUITEM "Inf&o", CMD_ABOUT + END +END + + +STRINGTABLE +BEGIN + STRING_CLIPBOARD "Zwischenablage" + STRING_DELETE_MSG "Soll der Inhalt der Zwischenablage gelöscht werden?" + STRING_DELETE_TITLE "Zwischenablage löschen" +END + + +STRINGTABLE +BEGIN + STRING_CF_UNKNOWN "Unbekanntes Format" + STRING_CF_TEXT "Text" + STRING_CF_BITMAP "Bitmap" + STRING_CF_OEMTEXT "OEM-Text" + STRING_CF_UNICODETEXT "Unicodetext" + STRING_CF_DIB "DIB-Bitmap" + STRING_CF_LOCALE "Gebietsschema" + STRING_CF_ENHMETAFILE "Erweiterte Metadatei" + STRING_CF_METAFILEPICT "Metadatei" + STRING_CF_PALETTE "Farbpalette" + STRING_CF_DIBV5 "DIBV5-Bitmap" +END + + +STRINGTABLE +BEGIN + ERROR_UNSUPPORTED_FORMAT "Die Daten in der Zwischenablage liegen in einem Format vor, welches nicht angezeigt werden kann." +END Index: base/applications/clipbrd/lang/en-US.rc =================================================================== --- base/applications/clipbrd/lang/en-US.rc (revision 0) +++ base/applications/clipbrd/lang/en-US.rc (working copy) @@ -0,0 +1,62 @@ +LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US + +ID_ACCEL ACCELERATORS +BEGIN + VK_DELETE, CMD_DELETE, VIRTKEY +END + + +MAIN_MENU MENU +BEGIN + POPUP "&File" + BEGIN + MENUITEM "&Open...", CMD_OPEN, GRAYED + MENUITEM "Save &as...", CMD_SAVE_AS, GRAYED + MENUITEM SEPARATOR + MENUITEM "E&xit", CMD_EXIT + END + POPUP "&Edit" + BEGIN + MENUITEM "&Delete\tDel", CMD_DELETE + END + POPUP "&Display" + BEGIN + MENUITEM "&Automatic", CMD_AUTOMATIC + END + POPUP "&Help" + BEGIN + MENUITEM "&Help Topics", CMD_HELP + MENUITEM SEPARATOR + MENUITEM "&About", CMD_ABOUT + END +END + + +STRINGTABLE +BEGIN + STRING_CLIPBOARD "Clipboard" + STRING_DELETE_MSG "Clear contents of the Clipboard?" + STRING_DELETE_TITLE "Clear Clipboard" +END + + +STRINGTABLE +BEGIN + STRING_CF_UNKNOWN "Unknown Format" + STRING_CF_TEXT "Text" + STRING_CF_BITMAP "Bitmap" + STRING_CF_OEMTEXT "OEM Text" + STRING_CF_UNICODETEXT "Unicode Text" + STRING_CF_DIB "DIB Bitmap" + STRING_CF_LOCALE "Locale Data" + STRING_CF_ENHMETAFILE "Enhanced Metafile" + STRING_CF_METAFILEPICT "Metafile" + STRING_CF_PALETTE "Color Palette" + STRING_CF_DIBV5 "DIBV5 Bitmap" +END + + +STRINGTABLE +BEGIN + ERROR_UNSUPPORTED_FORMAT "The clipboard contains data in a format, that cannot be displayed." +END Index: base/applications/clipbrd/lang/de-DE.rc =================================================================== --- base/applications/clipbrd/lang/de-DE.rc (revision 0) +++ base/applications/clipbrd/lang/de-DE.rc (working copy) @@ -0,0 +1,62 @@ +LANGUAGE LANG_GERMAN, SUBLANG_NEUTRAL + +ID_ACCEL ACCELERATORS +BEGIN + VK_DELETE, CMD_DELETE, VIRTKEY +END + + +MAIN_MENU MENU +BEGIN + POPUP "&Datei" + BEGIN + MENUITEM "Ö&ffnen...", CMD_OPEN, GRAYED + MENUITEM "Speichern &unter...", CMD_SAVE_AS, GRAYED + MENUITEM SEPARATOR + MENUITEM "&Beenden", CMD_EXIT + END + POPUP "&Bearbeiten" + BEGIN + MENUITEM "&Löschen\tEntf", CMD_DELETE + END + POPUP "&Anzeige" + BEGIN + MENUITEM "&Automatisch", CMD_AUTOMATIC + END + POPUP "&Hilfe" + BEGIN + MENUITEM "&Hilfethemen", CMD_HELP + MENUITEM SEPARATOR + MENUITEM "Inf&o", CMD_ABOUT + END +END + + +STRINGTABLE +BEGIN + STRING_CLIPBOARD "Zwischenablage" + STRING_DELETE_MSG "Soll der Inhalt der Zwischenablage gelöscht werden?" + STRING_DELETE_TITLE "Zwischenablage löschen" +END + + +STRINGTABLE +BEGIN + STRING_CF_UNKNOWN "Unbekanntes Format" + STRING_CF_TEXT "Text" + STRING_CF_BITMAP "Bitmap" + STRING_CF_OEMTEXT "OEM-Text" + STRING_CF_UNICODETEXT "Unicodetext" + STRING_CF_DIB "DIB-Bitmap" + STRING_CF_LOCALE "Gebietsschema" + STRING_CF_ENHMETAFILE "Erweiterte Metadatei" + STRING_CF_METAFILEPICT "Metadatei" + STRING_CF_PALETTE "Farbpalette" + STRING_CF_DIBV5 "DIBV5-Bitmap" +END + + +STRINGTABLE +BEGIN + ERROR_UNSUPPORTED_FORMAT "Die Daten in der Zwischenablage liegen in einem Format vor, welches nicht angezeigt werden kann." +END Index: base/applications/clipbrd/lang/en-US.rc =================================================================== --- base/applications/clipbrd/lang/en-US.rc (revision 0) +++ base/applications/clipbrd/lang/en-US.rc (working copy) @@ -0,0 +1,62 @@ +LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US + +ID_ACCEL ACCELERATORS +BEGIN + VK_DELETE, CMD_DELETE, VIRTKEY +END + + +MAIN_MENU MENU +BEGIN + POPUP "&File" + BEGIN + MENUITEM "&Open...", CMD_OPEN, GRAYED + MENUITEM "Save &as...", CMD_SAVE_AS, GRAYED + MENUITEM SEPARATOR + MENUITEM "E&xit", CMD_EXIT + END + POPUP "&Edit" + BEGIN + MENUITEM "&Delete\tDel", CMD_DELETE + END + POPUP "&Display" + BEGIN + MENUITEM "&Automatic", CMD_AUTOMATIC + END + POPUP "&Help" + BEGIN + MENUITEM "&Help Topics", CMD_HELP + MENUITEM SEPARATOR + MENUITEM "&About", CMD_ABOUT + END +END + + +STRINGTABLE +BEGIN + STRING_CLIPBOARD "Clipboard" + STRING_DELETE_MSG "Clear contents of the Clipboard?" + STRING_DELETE_TITLE "Clear Clipboard" +END + + +STRINGTABLE +BEGIN + STRING_CF_UNKNOWN "Unknown Format" + STRING_CF_TEXT "Text" + STRING_CF_BITMAP "Bitmap" + STRING_CF_OEMTEXT "OEM Text" + STRING_CF_UNICODETEXT "Unicode Text" + STRING_CF_DIB "DIB Bitmap" + STRING_CF_LOCALE "Locale Data" + STRING_CF_ENHMETAFILE "Enhanced Metafile" + STRING_CF_METAFILEPICT "Metafile" + STRING_CF_PALETTE "Color Palette" + STRING_CF_DIBV5 "DIBV5 Bitmap" +END + + +STRINGTABLE +BEGIN + ERROR_UNSUPPORTED_FORMAT "The clipboard contains data in a format, that cannot be displayed." +END Index: base/applications/clipbrd/res/clipbrd.ico =================================================================== Cannot display: file marked as a binary type. svn:mime-type = application/octet-stream Index: base/applications/clipbrd/res/clipbrd.ico =================================================================== --- base/applications/clipbrd/res/clipbrd.ico (revision 0) +++ base/applications/clipbrd/res/clipbrd.ico (working copy) Property changes on: base/applications/clipbrd/res/clipbrd.ico ___________________________________________________________________ Added: svn:mime-type ## -0,0 +1 ## +application/octet-stream \ No newline at end of property Index: base/applications/clipbrd/res/clipbrd.ico =================================================================== Cannot display: file marked as a binary type. svn:mime-type = application/octet-stream Index: base/applications/clipbrd/res/clipbrd.ico =================================================================== --- base/applications/clipbrd/res/clipbrd.ico (revision 0) +++ base/applications/clipbrd/res/clipbrd.ico (working copy) Property changes on: base/applications/clipbrd/res/clipbrd.ico ___________________________________________________________________ Added: svn:mime-type ## -0,0 +1 ## +application/octet-stream \ No newline at end of property Index: base/applications/clipbrd/resources.h =================================================================== --- base/applications/clipbrd/resources.h (revision 0) +++ base/applications/clipbrd/resources.h (working copy) @@ -0,0 +1,32 @@ +#pragma once + +#define MAIN_MENU 100 +#define CLIP_ICON 101 +#define ID_ACCEL 102 + +#define CMD_OPEN 100 +#define CMD_SAVE_AS 101 +#define CMD_EXIT 102 +#define CMD_DELETE 103 +#define CMD_HELP 105 +#define CMD_ABOUT 106 + +#define CMD_AUTOMATIC 1000 + +#define STRING_CLIPBOARD 100 +#define STRING_DELETE_MSG 101 +#define STRING_DELETE_TITLE 102 + +#define STRING_CF_UNKNOWN 200 +#define STRING_CF_TEXT 201 +#define STRING_CF_BITMAP 202 +#define STRING_CF_OEMTEXT 203 +#define STRING_CF_UNICODETEXT 204 +#define STRING_CF_DIB 205 +#define STRING_CF_LOCALE 206 +#define STRING_CF_ENHMETAFILE 207 +#define STRING_CF_METAFILEPICT 208 +#define STRING_CF_PALETTE 209 +#define STRING_CF_DIBV5 210 + +#define ERROR_UNSUPPORTED_FORMAT 300 Index: base/applications/clipbrd/resources.rc =================================================================== --- base/applications/clipbrd/resources.rc (revision 0) +++ base/applications/clipbrd/resources.rc (working copy) @@ -0,0 +1,23 @@ +#include +#include + +#include "resources.h" + +#define REACTOS_STR_FILE_DESCRIPTION "ReactOS Clipboard Viewer" +#define REACTOS_STR_INTERNAL_NAME "clipbrd" +#define REACTOS_STR_ORIGINAL_FILENAME "clipbrd.exe" +#include + +CLIP_ICON ICON "res/clipbrd.ico" + +#include + +/* UTF-8 */ +#pragma code_page(65001) + +#ifdef LANGUAGE_DE_DE + #include "lang/de-DE.rc" +#endif +#ifdef LANGUAGE_EN_US + #include "lang/en-US.rc" +#endif Index: base/applications/clipbrd/winutils.c =================================================================== --- base/applications/clipbrd/winutils.c (revision 0) +++ base/applications/clipbrd/winutils.c (working copy) @@ -0,0 +1,127 @@ +#include "clipbrd.h" + + + +void ShowLastWin32Error(HWND hwndParent) +{ + DWORD dwError; + + dwError = GetLastError(); + if (dwError != NO_ERROR) + { + LPTSTR lpMsgBuf = NULL; + + FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM, NULL, dwError, 0, (LPTSTR)&lpMsgBuf, 0, NULL); + MessageBox(hwndParent, lpMsgBuf, NULL, MB_OK | MB_ICONERROR); + LocalFree(lpMsgBuf); + } +} + + + +int DrawTextFromResource(HINSTANCE hInstance, UINT uID, HDC hDC, LPRECT lpRect, UINT uFormat) +{ + const TCHAR *lpBuffer; + int nCount; + + nCount = LoadString(hInstance, uID, (LPWSTR)&lpBuffer, 0); + if (nCount) + { + return DrawText(hDC, lpBuffer, nCount, lpRect, uFormat); + } + else + { + return 0; + } +} + + + +int MessageBoxRes(HWND hWnd, HINSTANCE hInstance, UINT uText, UINT uCaption, UINT uType) +{ + MSGBOXPARAMS mb; + + ZeroMemory(&mb, sizeof(mb)); + mb.cbSize = sizeof(mb); + mb.hwndOwner = hWnd; + mb.hInstance = hInstance; + mb.lpszText = MAKEINTRESOURCE(uText); + mb.lpszCaption = MAKEINTRESOURCE(uCaption); + mb.dwStyle = uType; + mb.dwLanguageId = MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT); + + return MessageBoxIndirect(&mb); +} + + + +void DrawTextFromClipboard(HDC hDC, LPRECT lpRect, UINT uFormat) +{ + if (OpenClipboard(NULL)) + { + HGLOBAL hGlobal; + LPWSTR lpchText; + + hGlobal = GetClipboardData(CF_UNICODETEXT); + lpchText = GlobalLock(hGlobal); + DrawText(hDC, lpchText, -1, lpRect, uFormat); + GlobalUnlock(hGlobal); + CloseClipboard(); + } +} + + + +void BitBltFromClipboard(HDC hdcDest, int nXDest, int nYDest, int nWidth, int nHeight, int nXSrc, int nYSrc, DWORD dwRop) +{ + if (OpenClipboard(NULL)) + { + HDC hdcMem; + + hdcMem = CreateCompatibleDC(hdcDest); + if (hdcMem) + { + HBITMAP hbm; + + hbm = (HBITMAP)GetClipboardData(CF_BITMAP); + SelectObject(hdcMem, hbm); + BitBlt(hdcDest, nXDest, nYDest, nWidth, nHeight, hdcMem, nXSrc, nYSrc, dwRop); + DeleteDC(hdcMem); + } + CloseClipboard(); + } +} + + + +void PlayMetaFileFromClipboard(HDC hdc, const RECT *lpRect) +{ + if (OpenClipboard(NULL)) + { + LPMETAFILEPICT mp; + HGLOBAL hGlobal; + + hGlobal = GetClipboardData(CF_METAFILEPICT); + mp = (LPMETAFILEPICT)GlobalLock(hGlobal); + SetMapMode(hdc, mp->mm); + SetViewportExtEx(hdc, lpRect->right, lpRect->bottom, NULL); + SetViewportOrgEx(hdc, lpRect->left, lpRect->top, NULL); + PlayMetaFile(hdc, mp->hMF); + GlobalUnlock(hGlobal); + CloseClipboard(); + } +} + + + +void PlayEnhMetaFileFromClipboard(HDC hdc, const RECT *lpRect) +{ + if (OpenClipboard(NULL)) + { + HENHMETAFILE hEmf; + + hEmf = GetClipboardData(CF_ENHMETAFILE); + PlayEnhMetaFile(hdc, hEmf, lpRect); + CloseClipboard(); + } +} Index: base/applications/clipbrd/winutils.h =================================================================== --- base/applications/clipbrd/winutils.h (revision 0) +++ base/applications/clipbrd/winutils.h (working copy) @@ -0,0 +1,7 @@ +void ShowLastWin32Error(HWND hwndParent); +int DrawTextFromResource(HINSTANCE hInstance, UINT uID, HDC hDC, LPRECT lpRect, UINT uFormat); +int MessageBoxRes(HWND hWnd, HINSTANCE hInstance, UINT uText, UINT uCaption, UINT uType); +void DrawTextFromClipboard(HDC hDC, LPRECT lpRect, UINT uFormat); +void BitBltFromClipboard(HDC hdcDest, int nXDest, int nYDest, int nWidth, int nHeight, int nXSrc, int nYSrc, DWORD dwRop); +void PlayMetaFileFromClipboard(HDC hdc, const RECT *lpRect); +void PlayEnhMetaFileFromClipboard(HDC hdc, const RECT *lpRect); Index: base/applications/CMakeLists.txt =================================================================== --- base/applications/CMakeLists.txt (revision 69558) +++ base/applications/CMakeLists.txt (working copy) @@ -3,6 +3,7 @@ add_subdirectory(cacls) add_subdirectory(calc) add_subdirectory(charmap) +add_subdirectory(clipbrd) add_subdirectory(cmdutils) add_subdirectory(control) add_subdirectory(dxdiag)