Author: bfreisen
Date: Tue Jan 28 15:46:28 2014
New Revision: 61860
URL:
http://svn.reactos.org/svn/reactos?rev=61860&view=rev
Log:
[MSPAINT]
Apply patches from
CORE-7551 (Drag and Drop between Paint and the shell) and
CORE-7561 (insert from file)
Modified:
trunk/reactos/base/applications/mspaint/dib.c
trunk/reactos/base/applications/mspaint/dib.h
trunk/reactos/base/applications/mspaint/main.c
trunk/reactos/base/applications/mspaint/precomp.h
trunk/reactos/base/applications/mspaint/winproc.c
Modified: trunk/reactos/base/applications/mspaint/dib.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/applications/mspaint/…
==============================================================================
--- trunk/reactos/base/applications/mspaint/dib.c [iso-8859-1] (original)
+++ trunk/reactos/base/applications/mspaint/dib.c [iso-8859-1] Tue Jan 28 15:46:28 2014
@@ -95,6 +95,17 @@
HeapFree(GetProcessHeap(), 0, buffer);
}
+void ShowFileLoadError(LPTSTR name)
+{
+ TCHAR programname[20];
+ TCHAR loaderrortext[100];
+ TCHAR temptext[500];
+ LoadString(hProgInstance, IDS_PROGRAMNAME, programname, SIZEOF(programname));
+ LoadString(hProgInstance, IDS_LOADERRORTEXT, loaderrortext, SIZEOF(loaderrortext));
+ _stprintf(temptext, loaderrortext, name);
+ MessageBox(hMainWnd, temptext, programname, MB_OK | MB_ICONEXCLAMATION);
+}
+
void
LoadDIBFromFile(HBITMAP * hBitmap, LPTSTR name, LPSYSTEMTIME time, int *size, int *hRes,
int *vRes)
{
@@ -105,18 +116,25 @@
HANDLE hFile;
if (!hBitmap)
+ {
+ ShowFileLoadError(name);
return;
+ }
hFile =
CreateFile(name, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING,
FILE_FLAG_SEQUENTIAL_SCAN, NULL);
if (hFile == INVALID_HANDLE_VALUE)
+ {
+ ShowFileLoadError(name);
return;
+ }
/* read header and check for 'BM' magic */
ReadFile(hFile, &bfh, sizeof(BITMAPFILEHEADER), &dwBytesRead, NULL);
if (bfh.bfType != 0x4d42)
{
CloseHandle(hFile);
+ ShowFileLoadError(name);
return;
}
@@ -133,6 +151,7 @@
if (!bi)
{
CloseHandle(hFile);
+ ShowFileLoadError(name);
return;
}
Modified: trunk/reactos/base/applications/mspaint/dib.h
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/applications/mspaint/…
==============================================================================
--- trunk/reactos/base/applications/mspaint/dib.h [iso-8859-1] (original)
+++ trunk/reactos/base/applications/mspaint/dib.h [iso-8859-1] Tue Jan 28 15:46:28 2014
@@ -16,3 +16,5 @@
int vRes);
void LoadDIBFromFile(HBITMAP *hBitmap, LPTSTR name, LPSYSTEMTIME time, int *size, int
*hRes, int *vRes);
+
+void ShowFileLoadError(LPTSTR name);
Modified: trunk/reactos/base/applications/mspaint/main.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/applications/mspaint/…
==============================================================================
--- trunk/reactos/base/applications/mspaint/main.c [iso-8859-1] (original)
+++ trunk/reactos/base/applications/mspaint/main.c [iso-8859-1] Tue Jan 28 15:46:28 2014
@@ -409,6 +409,10 @@
clearHistory();
isAFile = TRUE;
}
+ else
+ {
+ exit(0);
+ }
}
/* initializing the CHOOSECOLOR structure for use with ChooseColor */
@@ -489,6 +493,9 @@
/* Make the window visible on the screen */
ShowWindow (hwnd, nFunsterStil);
+ /* inform the system, that the main window accepts dropped files */
+ DragAcceptFiles(hwnd, TRUE);
+
/* Run the message loop. It will run until GetMessage() returns 0 */
while (GetMessage(&messages, NULL, 0, 0))
{
Modified: trunk/reactos/base/applications/mspaint/precomp.h
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/applications/mspaint/…
==============================================================================
--- trunk/reactos/base/applications/mspaint/precomp.h [iso-8859-1] (original)
+++ trunk/reactos/base/applications/mspaint/precomp.h [iso-8859-1] Tue Jan 28 15:46:28
2014
@@ -9,6 +9,7 @@
#include <commctrl.h>
#include <tchar.h>
#include <stdlib.h>
+#include <shellapi.h>
#include "definitions.h"
#include "drawing.h"
Modified: trunk/reactos/base/applications/mspaint/winproc.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/applications/mspaint/…
==============================================================================
--- trunk/reactos/base/applications/mspaint/winproc.c [iso-8859-1] (original)
+++ trunk/reactos/base/applications/mspaint/winproc.c [iso-8859-1] Tue Jan 28 15:46:28
2014
@@ -10,8 +10,6 @@
/* INCLUDES *********************************************************/
#include "precomp.h"
-
-#include <shellapi.h>
#include "dialogs.h"
#include "registry.h"
@@ -162,6 +160,43 @@
}
}
+void
+UpdateApplicationProperties(HBITMAP bitmap, LPTSTR newfilename, LPTSTR newfilepathname)
+{
+ TCHAR tempstr[1000];
+ TCHAR resstr[100];
+ insertReversible(bitmap);
+ updateCanvasAndScrollbars();
+ CopyMemory(filename, newfilename, sizeof(filename));
+ CopyMemory(filepathname, newfilepathname, sizeof(filepathname));
+ LoadString(hProgInstance, IDS_WINDOWTITLE, resstr, SIZEOF(resstr));
+ _stprintf(tempstr, resstr, filename);
+ SetWindowText(hMainWnd, tempstr);
+ clearHistory();
+ isAFile = TRUE;
+}
+
+void
+InsertSelectionFromHBITMAP(HBITMAP bitmap, HWND window)
+{
+ HWND hToolbar = FindWindowEx(hToolBoxContainer, NULL, TOOLBARCLASSNAME, NULL);
+ SendMessage(hToolbar, TB_CHECKBUTTON, ID_RECTSEL, MAKELONG(TRUE, 0));
+ SendMessage(window, WM_COMMAND, ID_RECTSEL, 0);
+
+ DeleteObject(SelectObject(hSelDC, hSelBm = CopyImage(bitmap,
+ IMAGE_BITMAP, 0, 0,
+ LR_COPYRETURNORG)));
+ newReversible();
+ rectSel_src[0] = rectSel_src[1] = rectSel_src[2] = rectSel_src[3] = 0;
+ rectSel_dest[0] = rectSel_dest[1] = 0;
+ rectSel_dest[2] = GetDIBWidth(hSelBm);
+ rectSel_dest[3] = GetDIBHeight(hSelBm);
+ BitBlt(hDrawingDC, rectSel_dest[0], rectSel_dest[1], rectSel_dest[2],
rectSel_dest[3],
+ hSelDC, 0, 0, SRCCOPY);
+ placeSelWin();
+ ShowWindow(hSelection, SW_SHOW);
+}
+
BOOL drawing;
LRESULT CALLBACK
@@ -169,6 +204,25 @@
{
switch (message) /* handle the messages */
{
+ case WM_DROPFILES:
+ {
+ HDROP drophandle;
+ TCHAR droppedfile[MAX_PATH];
+ drophandle = (HDROP)wParam;
+ DragQueryFile(drophandle, 0, droppedfile, sizeof(droppedfile));
+ DragFinish(drophandle);
+ HBITMAP bmNew = NULL;
+ LoadDIBFromFile(&bmNew, droppedfile, &fileTime, &fileSize,
&fileHPPM, &fileVPPM);
+ if (bmNew != NULL)
+ {
+ TCHAR *pathend;
+ pathend = _tcsrchr(droppedfile, '\\');
+ pathend++;
+ UpdateApplicationProperties(bmNew, pathend, pathend);
+ }
+ break;
+ }
+
case WM_CREATE:
ptStack = NULL;
ptSP = 0;
@@ -785,27 +839,7 @@
LoadDIBFromFile(&bmNew, ofn.lpstrFile, &fileTime,
&fileSize, &fileHPPM, &fileVPPM);
if (bmNew != NULL)
{
- TCHAR tempstr[1000];
- TCHAR resstr[100];
- insertReversible(bmNew);
- updateCanvasAndScrollbars();
- CopyMemory(filename, ofn.lpstrFileTitle, sizeof(filename));
- CopyMemory(filepathname, ofn.lpstrFileTitle,
sizeof(filepathname));
- LoadString(hProgInstance, IDS_WINDOWTITLE, resstr,
SIZEOF(resstr));
- _stprintf(tempstr, resstr, filename);
- SetWindowText(hMainWnd, tempstr);
- clearHistory();
- isAFile = TRUE;
- }
- else
- {
- TCHAR programname[20];
- TCHAR loaderrortext[100];
- TCHAR temptext[500];
- LoadString(hProgInstance, IDS_PROGRAMNAME, programname,
SIZEOF(programname));
- LoadString(hProgInstance, IDS_LOADERRORTEXT, loaderrortext,
SIZEOF(loaderrortext));
- _stprintf(temptext, loaderrortext, ofn.lpstrFile);
- MessageBox(hwnd, temptext, programname, MB_OK |
MB_ICONEXCLAMATION);
+ UpdateApplicationProperties(bmNew, ofn.lpstrFileTitle,
ofn.lpstrFileTitle);
}
}
break;
@@ -848,22 +882,7 @@
OpenClipboard(hMainWnd);
if (GetClipboardData(CF_BITMAP) != NULL)
{
- HWND hToolbar = FindWindowEx(hToolBoxContainer, NULL,
TOOLBARCLASSNAME, NULL);
- SendMessage(hToolbar, TB_CHECKBUTTON, ID_RECTSEL, MAKELONG(TRUE,
0));
- SendMessage(hwnd, WM_COMMAND, ID_RECTSEL, 0);
-
- DeleteObject(SelectObject(hSelDC, hSelBm =
CopyImage(GetClipboardData(CF_BITMAP),
-
IMAGE_BITMAP, 0, 0,
-
LR_COPYRETURNORG)));
- newReversible();
- rectSel_src[0] = rectSel_src[1] = rectSel_src[2] = rectSel_src[3]
= 0;
- rectSel_dest[0] = rectSel_dest[1] = 0;
- rectSel_dest[2] = GetDIBWidth(hSelBm);
- rectSel_dest[3] = GetDIBHeight(hSelBm);
- BitBlt(hDrawingDC, rectSel_dest[0], rectSel_dest[1],
rectSel_dest[2], rectSel_dest[3],
- hSelDC, 0, 0, SRCCOPY);
- placeSelWin();
- ShowWindow(hSelection, SW_SHOW);
+ InsertSelectionFromHBITMAP(GetClipboardData(CF_BITMAP), hwnd);
}
CloseClipboard();
break;
@@ -898,6 +917,18 @@
case IDM_EDITCOPYTO:
if (GetSaveFileName(&ofn) != 0)
SaveDIBToFile(hSelBm, ofn.lpstrFile, hDrawingDC, NULL, NULL,
fileHPPM, fileVPPM);
+ break;
+ case IDM_EDITPASTEFROM:
+ if (GetOpenFileName(&ofn) != 0)
+ {
+ HBITMAP bmNew = NULL;
+ LoadDIBFromFile(&bmNew, ofn.lpstrFile, &fileTime,
&fileSize, &fileHPPM, &fileVPPM);
+ if (bmNew != NULL)
+ {
+ InsertSelectionFromHBITMAP(bmNew, hwnd);
+ DeleteObject(bmNew);
+ }
+ }
break;
case IDM_COLORSEDITPALETTE:
if (ChooseColor(&choosecolor))