[PAINT]
authorBenedikt Freisen <b.freisen@gmx.net>
Sun, 10 Oct 2010 09:57:44 +0000 (09:57 +0000)
committerBenedikt Freisen <b.freisen@gmx.net>
Sun, 10 Oct 2010 09:57:44 +0000 (09:57 +0000)
- apply patch by Black_Fox (see bug 5434)
- fix minor bugs introduced by it
- generalize changes related to mirroring rectangular selections to free form selections
- solve problem regarding selection contents update

svn path=/trunk/; revision=49089

reactos/base/applications/paint/globalvar.h
reactos/base/applications/paint/lang/cs-CZ.rc
reactos/base/applications/paint/mouse.c
reactos/base/applications/paint/registry.c
reactos/base/applications/paint/selection.c
reactos/base/applications/paint/winproc.c

index ed73d41..9c884e4 100644 (file)
@@ -101,3 +101,5 @@ extern HWND hSizeboxRightBottom;
 
 extern POINT pointStack[256];
 extern short pointSP;
 
 extern POINT pointStack[256];
 extern short pointSP;
+extern POINT *ptStack;
+extern int ptSP;
index da0e84b..06b3f1b 100644 (file)
@@ -12,8 +12,8 @@ ID_MENU MENU
 BEGIN
     POPUP "&Soubor"
     BEGIN
 BEGIN
     POPUP "&Soubor"
     BEGIN
-        MENUITEM "Nový\tCtrl+N", IDM_FILENEW
-        MENUITEM "Otevøít...\tCtrl+O", IDM_FILEOPEN
+        MENUITEM "&Nový\tCtrl+N", IDM_FILENEW
+        MENUITEM "&Otevøít...\tCtrl+O", IDM_FILEOPEN
         MENUITEM "Ulo\9eit\tCtrl+S", IDM_FILESAVE
         MENUITEM "Ulo\9eit jako...", IDM_FILESAVEAS
         MENUITEM SEPARATOR
         MENUITEM "Ulo\9eit\tCtrl+S", IDM_FILESAVE
         MENUITEM "Ulo\9eit jako...", IDM_FILESAVEAS
         MENUITEM SEPARATOR
@@ -60,7 +60,7 @@ BEGIN
                 MENUITEM "800%", IDM_VIEWZOOM800
             END
             MENUITEM SEPARATOR
                 MENUITEM "800%", IDM_VIEWZOOM800
             END
             MENUITEM SEPARATOR
-            MENUITEM "Zobrazit møí\9eku", IDM_VIEWSHOWGRID
+            MENUITEM "Zobrazit møí\9eku\tCtrl+G", IDM_VIEWSHOWGRID
             MENUITEM "Zobrazit miniaturu", IDM_VIEWSHOWMINIATURE
         END
         MENUITEM "Celá obrazovka\tCtrl+F", IDM_VIEWFULLSCREEN
             MENUITEM "Zobrazit miniaturu", IDM_VIEWSHOWMINIATURE
         END
         MENUITEM "Celá obrazovka\tCtrl+F", IDM_VIEWFULLSCREEN
index d46bbe3..0cda187 100644 (file)
@@ -284,6 +284,10 @@ endPaintingL(HDC hdc, short x, short y, int fg, int bg)
 
                 placeSelWin();
                 ShowWindow(hSelection, SW_SHOW);
 
                 placeSelWin();
                 ShowWindow(hSelection, SW_SHOW);
+                /* force refresh of selection contents */
+                SendMessage(hSelection, WM_LBUTTONDOWN, 0, 0);
+                SendMessage(hSelection, WM_MOUSEMOVE, 0, 0);
+                SendMessage(hSelection, WM_LBUTTONUP, 0, 0);
             }
             HeapFree(GetProcessHeap(), 0, ptStack);
             ptStack = NULL;
             }
             HeapFree(GetProcessHeap(), 0, ptStack);
             ptStack = NULL;
@@ -310,6 +314,10 @@ endPaintingL(HDC hdc, short x, short y, int fg, int bg)
 
                 placeSelWin();
                 ShowWindow(hSelection, SW_SHOW);
 
                 placeSelWin();
                 ShowWindow(hSelection, SW_SHOW);
+                /* force refresh of selection contents */
+                SendMessage(hSelection, WM_LBUTTONDOWN, 0, 0);
+                SendMessage(hSelection, WM_MOUSEMOVE, 0, 0);
+                SendMessage(hSelection, WM_LBUTTONUP, 0, 0);
             }
             break;
         case TOOL_RUBBER:
             }
             break;
         case TOOL_RUBBER:
index 1134a71..392fc08 100644 (file)
 /* FUNCTIONS ********************************************************/
 
 void
 /* FUNCTIONS ********************************************************/
 
 void
-SetWallpaper(TCHAR * FileName, DWORD dwStyle, DWORD dwTile)     //FIXME: The pattern (tiled/stretched) is not set
+SetWallpaper(TCHAR * FileName, DWORD dwStyle, DWORD dwTile) //FIXME: Has to be called 2x to apply the pattern (tiled/stretched) too
 {
     SystemParametersInfo(SPI_SETDESKWALLPAPER, 0, (PVOID) FileName, SPIF_UPDATEINIFILE);
 
 {
     SystemParametersInfo(SPI_SETDESKWALLPAPER, 0, (PVOID) FileName, SPIF_UPDATEINIFILE);
 
-    /*HKEY hDesktop;
+    HKEY hDesktop;
     TCHAR szStyle[3], szTile[3];
 
     if ((dwStyle > 2) || (dwTile > 2))
     TCHAR szStyle[3], szTile[3];
 
     if ((dwStyle > 2) || (dwTile > 2))
@@ -39,5 +39,5 @@ SetWallpaper(TCHAR * FileName, DWORD dwStyle, DWORD dwTile)     //FIXME: The pat
                       _tcslen(szTile) * sizeof(TCHAR));
 
         RegCloseKey(hDesktop);
                       _tcslen(szTile) * sizeof(TCHAR));
 
         RegCloseKey(hDesktop);
-    }*/
+    }
 }
 }
index 5028f9e..03d7a18 100644 (file)
@@ -9,6 +9,8 @@
 /* INCLUDES *********************************************************/
 
 #include <windows.h>
 /* INCLUDES *********************************************************/
 
 #include <windows.h>
+#include <commctrl.h>
+#include <tchar.h>
 #include "globalvar.h"
 #include "drawing.h"
 #include "history.h"
 #include "globalvar.h"
 #include "drawing.h"
 #include "history.h"
@@ -87,6 +89,7 @@ SelectionWinProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
         case WM_MOUSEMOVE:
             if (moving)
             {
         case WM_MOUSEMOVE:
             if (moving)
             {
+                TCHAR sizeStr[100];
                 int xDelta;
                 int yDelta;
                 resetToU1();
                 int xDelta;
                 int yDelta;
                 resetToU1();
@@ -147,6 +150,9 @@ SelectionWinProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
                         break;
                 }
 
                         break;
                 }
 
+                _stprintf(sizeStr, _T("%d x %d"), rectSel_dest[2], rectSel_dest[3]);
+                SendMessage(hStatusBar, SB_SETTEXT, 2, (LPARAM) sizeStr);
+
                 if (action != 0)
                     StretchBlt(hDrawingDC, rectSel_dest[0], rectSel_dest[1], rectSel_dest[2], rectSel_dest[3], hSelDC, 0, 0, GetDIBWidth(hSelBm), GetDIBHeight(hSelBm), SRCCOPY);
                 else
                 if (action != 0)
                     StretchBlt(hDrawingDC, rectSel_dest[0], rectSel_dest[1], rectSel_dest[2], rectSel_dest[3], hSelDC, 0, 0, GetDIBWidth(hSelBm), GetDIBHeight(hSelBm), SRCCOPY);
                 else
@@ -182,6 +188,7 @@ SelectionWinProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
                 int h = rectSel_dest[3] * zoom / 1000 + 6;
                 xPos = LOWORD(lParam);
                 yPos = HIWORD(lParam);
                 int h = rectSel_dest[3] * zoom / 1000 + 6;
                 xPos = LOWORD(lParam);
                 yPos = HIWORD(lParam);
+                SendMessage(hStatusBar, SB_SETTEXT, 2, (LPARAM) NULL);
                 action = identifyCorner(xPos, yPos, w, h);
                 if (action != 0)
                     SetCursor(LoadCursor(NULL, cursors[action]));
                 action = identifyCorner(xPos, yPos, w, h);
                 if (action != 0)
                     SetCursor(LoadCursor(NULL, cursors[action]));
index 18bbaa6..23e1855 100644 (file)
@@ -151,6 +151,11 @@ WindowProcedure(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
 {
     switch (message)            /* handle the messages */
     {
 {
     switch (message)            /* handle the messages */
     {
+        case WM_CREATE:
+            ptStack = NULL;
+            ptSP = 0;
+            break;
+
         case WM_DESTROY:
             PostQuitMessage(0); /* send a WM_QUIT to the message queue */
             break;
         case WM_DESTROY:
             PostQuitMessage(0); /* send a WM_QUIT to the message queue */
             break;
@@ -446,9 +451,7 @@ WindowProcedure(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
                 HDC hdc;
                 GetClientRect(hwndMiniature, (LPRECT) &mclient);
                 hdc = GetDC(hwndMiniature);
                 HDC hdc;
                 GetClientRect(hwndMiniature, (LPRECT) &mclient);
                 hdc = GetDC(hwndMiniature);
-                BitBlt(hdc, -min(imgXRes * GetScrollPos(hScrollbox, SB_HORZ) / 10000, imgXRes - mclient[2]),
-                       -min(imgYRes * GetScrollPos(hScrollbox, SB_VERT) / 10000, imgYRes - mclient[3]),
-                       imgXRes, imgYRes, hDrawingDC, 0, 0, SRCCOPY);
+                BitBlt(hdc, 0, 0, imgXRes, imgYRes, hDrawingDC, 0, 0, SRCCOPY);
                 ReleaseDC(hwndMiniature, hdc);
             }
             break;
                 ReleaseDC(hwndMiniature, hdc);
             }
             break;
@@ -565,6 +568,24 @@ WindowProcedure(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
             }
             break;
 
             }
             break;
 
+        case WM_KEYDOWN:
+            if (wParam == VK_ESCAPE)
+            {
+                if (!drawing)
+                {
+                    /* Deselect */
+                    if ((activeTool == TOOL_RECTSEL) || (activeTool == TOOL_FREESEL))
+                    {
+                        startPaintingL(hDrawingDC, 0, 0, fgColor, bgColor);
+                        whilePaintingL(hDrawingDC, 0, 0, fgColor, bgColor);
+                        endPaintingL(hDrawingDC, 0, 0, fgColor, bgColor);
+                        ShowWindow(hSelection, SW_HIDE);
+                    }
+                }
+                /* FIXME: also cancel current drawing underway */
+            }
+            break;
+
         case WM_MOUSEMOVE:
             if (hwnd == hImageArea)
             {
         case WM_MOUSEMOVE:
             if (hwnd == hImageArea)
             {
@@ -640,6 +661,8 @@ WindowProcedure(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
                         if ((activeTool >= TOOL_TEXT) || (activeTool == TOOL_RECTSEL) || (activeTool == TOOL_FREESEL))
                         {
                             TCHAR sizeStr[100];
                         if ((activeTool >= TOOL_TEXT) || (activeTool == TOOL_RECTSEL) || (activeTool == TOOL_FREESEL))
                         {
                             TCHAR sizeStr[100];
+                            if ((activeTool >= TOOL_LINE) && (GetAsyncKeyState(VK_SHIFT) < 0))
+                                yRel = xRel;
                             _stprintf(sizeStr, _T("%d x %d"), xRel, yRel);
                             SendMessage(hStatusBar, SB_SETTEXT, 2, (LPARAM) sizeStr);
                         }
                             _stprintf(sizeStr, _T("%d x %d"), xRel, yRel);
                             SendMessage(hStatusBar, SB_SETTEXT, 2, (LPARAM) sizeStr);
                         }
@@ -651,6 +674,8 @@ WindowProcedure(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
                         if (activeTool >= TOOL_TEXT)
                         {
                             TCHAR sizeStr[100];
                         if (activeTool >= TOOL_TEXT)
                         {
                             TCHAR sizeStr[100];
+                            if ((activeTool >= TOOL_LINE) && (GetAsyncKeyState(VK_SHIFT) < 0))
+                                yRel = xRel;
                             _stprintf(sizeStr, _T("%d x %d"), xRel, yRel);
                             SendMessage(hStatusBar, SB_SETTEXT, 2, (LPARAM) sizeStr);
                         }
                             _stprintf(sizeStr, _T("%d x %d"), xRel, yRel);
                             SendMessage(hStatusBar, SB_SETTEXT, 2, (LPARAM) sizeStr);
                         }
@@ -783,7 +808,7 @@ WindowProcedure(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
                 case IDM_EDITDELETESELECTION:
                 {
                     /* remove selection window and already painted content using undo(),
                 case IDM_EDITDELETESELECTION:
                 {
                     /* remove selection window and already painted content using undo(),
-                    paint Rect for rectangular selections and nothing for freeform selections */
+                    paint Rect for rectangular selections and Poly for freeform selections */
                     undo();
                     if (activeTool == TOOL_RECTSEL)
                     {
                     undo();
                     if (activeTool == TOOL_RECTSEL)
                     {
@@ -791,16 +816,23 @@ WindowProcedure(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
                         Rect(hDrawingDC, rectSel_dest[0], rectSel_dest[1], rectSel_dest[2] + rectSel_dest[0],
                              rectSel_dest[3] + rectSel_dest[1], bgColor, bgColor, 0, TRUE);
                     }
                         Rect(hDrawingDC, rectSel_dest[0], rectSel_dest[1], rectSel_dest[2] + rectSel_dest[0],
                              rectSel_dest[3] + rectSel_dest[1], bgColor, bgColor, 0, TRUE);
                     }
+                    if (activeTool == TOOL_FREESEL)
+                    {
+                        newReversible();
+                        Poly(hDrawingDC, ptStack, ptSP + 1, 0, 0, 2, 0, FALSE);
+                    }
                     break;
                 }
                 case IDM_EDITSELECTALL:
                     break;
                 }
                 case IDM_EDITSELECTALL:
-                    if (activeTool == TOOL_RECTSEL)
-                    {
-                        startPaintingL(hDrawingDC, 0, 0, fgColor, bgColor);
-                        whilePaintingL(hDrawingDC, imgXRes, imgYRes, fgColor, bgColor);
-                        endPaintingL(hDrawingDC, imgXRes, imgYRes, fgColor, bgColor);
-                    }
+                {
+                    HWND hToolbar = FindWindowEx(hToolBoxContainer, NULL, TOOLBARCLASSNAME, NULL);
+                    SendMessage(hToolbar, TB_CHECKBUTTON, ID_RECTSEL, MAKELONG(TRUE, 0));
+                    SendMessage(hwnd, WM_COMMAND, ID_RECTSEL, 0);
+                    startPaintingL(hDrawingDC, 0, 0, fgColor, bgColor);
+                    whilePaintingL(hDrawingDC, imgXRes, imgYRes, fgColor, bgColor);
+                    endPaintingL(hDrawingDC, imgXRes, imgYRes, fgColor, bgColor);
                     break;
                     break;
+                }
                 case IDM_EDITCOPYTO:
                     if (GetSaveFileName(&ofn) != 0)
                         SaveDIBToFile(hSelBm, ofn.lpstrFile, hDrawingDC, NULL, NULL, fileHPPM, fileVPPM);
                 case IDM_EDITCOPYTO:
                     if (GetSaveFileName(&ofn) != 0)
                         SaveDIBToFile(hSelBm, ofn.lpstrFile, hDrawingDC, NULL, NULL, fileHPPM, fileVPPM);
@@ -829,23 +861,73 @@ WindowProcedure(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
                 case IDM_IMAGEROTATEMIRROR:
                     switch (mirrorRotateDlg())
                     {
                 case IDM_IMAGEROTATEMIRROR:
                     switch (mirrorRotateDlg())
                     {
-                        case 1:
-                            newReversible();
-                            StretchBlt(hDrawingDC, imgXRes - 1, 0, -imgXRes, imgYRes, hDrawingDC, 0, 0,
-                                       imgXRes, imgYRes, SRCCOPY);
-                            SendMessage(hImageArea, WM_PAINT, 0, 0);
+                        case 1: /* flip horizontally */
+                            if (IsWindowVisible(hSelection))
+                            {
+                                SelectObject(hSelDC, hSelMask);
+                                StretchBlt(hSelDC, rectSel_dest[2] - 1, 0, -rectSel_dest[2], rectSel_dest[3], hSelDC,
+                                           0, 0, rectSel_dest[2], rectSel_dest[3], SRCCOPY);
+                                SelectObject(hSelDC, hSelBm);
+                                StretchBlt(hSelDC, rectSel_dest[2] - 1, 0, -rectSel_dest[2], rectSel_dest[3], hSelDC,
+                                           0, 0, rectSel_dest[2], rectSel_dest[3], SRCCOPY);
+                                /* force refresh of selection contents, used also in case 2 and case 4 */
+                                SendMessage(hSelection, WM_LBUTTONDOWN, 0, 0);
+                                SendMessage(hSelection, WM_MOUSEMOVE, 0, 0);
+                                SendMessage(hSelection, WM_LBUTTONUP, 0, 0);
+                            }
+                            else
+                            {
+                                newReversible();
+                                StretchBlt(hDrawingDC, imgXRes - 1, 0, -imgXRes, imgYRes, hDrawingDC, 0, 0,
+                                           imgXRes, imgYRes, SRCCOPY);
+                                SendMessage(hImageArea, WM_PAINT, 0, 0);
+                            }
+                            break;
+                        case 2: /* flip vertically */
+                            if (IsWindowVisible(hSelection))
+                            {
+                                SelectObject(hSelDC, hSelMask);
+                                StretchBlt(hSelDC, 0, rectSel_dest[3] - 1, rectSel_dest[2], -rectSel_dest[3], hSelDC,
+                                           0, 0, rectSel_dest[2], rectSel_dest[3], SRCCOPY);
+                                SelectObject(hSelDC, hSelBm);
+                                StretchBlt(hSelDC, 0, rectSel_dest[3] - 1, rectSel_dest[2], -rectSel_dest[3], hSelDC,
+                                           0, 0, rectSel_dest[2], rectSel_dest[3], SRCCOPY);
+                                SendMessage(hSelection, WM_LBUTTONDOWN, 0, 0);
+                                SendMessage(hSelection, WM_MOUSEMOVE, 0, 0);
+                                SendMessage(hSelection, WM_LBUTTONUP, 0, 0);
+                            }
+                            else
+                            {
+                                newReversible();
+                                StretchBlt(hDrawingDC, 0, imgYRes - 1, imgXRes, -imgYRes, hDrawingDC, 0, 0,
+                                           imgXRes, imgYRes, SRCCOPY);
+                                SendMessage(hImageArea, WM_PAINT, 0, 0);
+                            }
                             break;
                             break;
-                        case 2:
-                            newReversible();
-                            StretchBlt(hDrawingDC, 0, imgYRes - 1, imgXRes, -imgYRes, hDrawingDC, 0, 0,
-                                       imgXRes, imgYRes, SRCCOPY);
-                            SendMessage(hImageArea, WM_PAINT, 0, 0);
+                        case 3: /* rotate 90 degrees */
                             break;
                             break;
-                        case 4:
-                            newReversible();
-                            StretchBlt(hDrawingDC, imgXRes - 1, imgYRes - 1, -imgXRes, -imgYRes, hDrawingDC,
-                                       0, 0, imgXRes, imgYRes, SRCCOPY);
-                            SendMessage(hImageArea, WM_PAINT, 0, 0);
+                        case 4: /* rotate 180 degrees */
+                            if (IsWindowVisible(hSelection))
+                            {
+                                SelectObject(hSelDC, hSelMask);
+                                StretchBlt(hSelDC, rectSel_dest[2] - 1, rectSel_dest[3] - 1, -rectSel_dest[2], -rectSel_dest[3], hSelDC,
+                                           0, 0, rectSel_dest[2], rectSel_dest[3], SRCCOPY);
+                                SelectObject(hSelDC, hSelBm);
+                                StretchBlt(hSelDC, rectSel_dest[2] - 1, rectSel_dest[3] - 1, -rectSel_dest[2], -rectSel_dest[3], hSelDC,
+                                           0, 0, rectSel_dest[2], rectSel_dest[3], SRCCOPY);
+                                SendMessage(hSelection, WM_LBUTTONDOWN, 0, 0);
+                                SendMessage(hSelection, WM_MOUSEMOVE, 0, 0);
+                                SendMessage(hSelection, WM_LBUTTONUP, 0, 0);
+                            }
+                            else
+                            {
+                                newReversible();
+                                StretchBlt(hDrawingDC, imgXRes - 1, imgYRes - 1, -imgXRes, -imgYRes, hDrawingDC,
+                                           0, 0, imgXRes, imgYRes, SRCCOPY);
+                                SendMessage(hImageArea, WM_PAINT, 0, 0);
+                            }
+                            break;
+                        case 5: /* rotate 270 degrees */
                             break;
                     }
                     break;
                             break;
                     }
                     break;
@@ -895,6 +977,7 @@ WindowProcedure(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
 
                 case IDM_VIEWSHOWGRID:
                     showGrid = !showGrid;
 
                 case IDM_VIEWSHOWGRID:
                     showGrid = !showGrid;
+                    SendMessage(hImageArea, WM_PAINT, 0, 0);
                     break;
                 case IDM_VIEWSHOWMINIATURE:
                     showMiniature = !showMiniature;
                     break;
                 case IDM_VIEWSHOWMINIATURE:
                     showMiniature = !showMiniature;