[MSPAINT_NEW] save/restore certain settings to/from registry
authorBenedikt Freisen <b.freisen@gmx.net>
Sun, 16 Aug 2015 19:52:37 +0000 (19:52 +0000)
committerBenedikt Freisen <b.freisen@gmx.net>
Sun, 16 Aug 2015 19:52:37 +0000 (19:52 +0000)
svn path=/trunk/; revision=68724

reactos/base/applications/mspaint_new/globalvar.h
reactos/base/applications/mspaint_new/history.cpp
reactos/base/applications/mspaint_new/imgarea.cpp
reactos/base/applications/mspaint_new/main.cpp
reactos/base/applications/mspaint_new/precomp.h
reactos/base/applications/mspaint_new/registry.cpp
reactos/base/applications/mspaint_new/registry.h
reactos/base/applications/mspaint_new/winproc.cpp

index 7961100..a341872 100644 (file)
@@ -20,6 +20,9 @@ extern int heightSetInDlg;
 
 extern STRETCHSKEW stretchSkew;
 
+class RegistrySettings;
+extern RegistrySettings registrySettings;
+
 class ImageModel;
 extern ImageModel imageModel;
 extern BOOL askBeforeEnlarging;
index 1aec2f5..76a44f9 100644 (file)
@@ -29,9 +29,9 @@ ImageModel::ImageModel()
     redoSteps = 0;
     imageSaved = TRUE;
 
-    // TODO: load dimensions from registry
-    int imgXRes = 400;
-    int imgYRes = 300;
+    // prepare a minimal usable bitmap
+    int imgXRes = 1;
+    int imgYRes = 1;
 
     hDrawingDC = CreateCompatibleDC(NULL);
     SelectObject(hDrawingDC, CreatePen(PS_SOLID, 0, paletteModel.GetFgColor()));
index a6cdf0b..ba883dd 100644 (file)
@@ -12,7 +12,6 @@
 #include "precomp.h"
 
 #include "dialogs.h"
-#include "registry.h"
 
 /* FUNCTIONS ********************************************************/
 
index 3a2793b..b18f858 100644 (file)
@@ -32,6 +32,8 @@ int textToolTextMaxLen = 0;
 
 PaletteModel paletteModel;
 
+RegistrySettings registrySettings;
+
 ImageModel imageModel;
 BOOL askBeforeEnlarging = FALSE;  // TODO: initialize from registry
 
@@ -134,13 +136,21 @@ _tWinMain (HINSTANCE hThisInstance, HINSTANCE hPrevInstance, LPTSTR lpszArgument
     _stprintf(progtitle, resstr, filename);
     LoadString(hThisInstance, IDS_MINIATURETITLE, miniaturetitle, SIZEOF(miniaturetitle));
 
+    /* load settings from registry */
+    registrySettings.Load();
+    showMiniature = registrySettings.ShowThumbnail;
+    imageModel.Crop(registrySettings.BMPWidth, registrySettings.BMPHeight);
+
     /* create main window */
     RECT mainWindowPos = {0, 0, 544, 375};     // FIXME: use equivalent of CW_USEDEFAULT for position
     hwnd = mainWindow.Create(HWND_DESKTOP, mainWindowPos, progtitle, WS_OVERLAPPEDWINDOW);
 
-    RECT miniaturePos = {180, 200, 180 + 120, 200 + 100};
+    RECT miniaturePos = {(LONG) registrySettings.ThumbXPos, (LONG) registrySettings.ThumbYPos,
+                         (LONG) registrySettings.ThumbXPos + (LONG) registrySettings.ThumbWidth,
+                         (LONG) registrySettings.ThumbYPos + (LONG) registrySettings.ThumbHeight};
     miniature.Create(hwnd, miniaturePos, miniaturetitle,
                      WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | WS_THICKFRAME, WS_EX_PALETTEWINDOW);
+    miniature.ShowWindow(showMiniature ? SW_SHOW : SW_HIDE);
 
     /* loading and setting the window menu from resource */
     menu = LoadMenu(hThisInstance, MAKEINTRESOURCE(ID_MENU));
@@ -276,7 +286,7 @@ _tWinMain (HINSTANCE hThisInstance, HINSTANCE hPrevInstance, LPTSTR lpszArgument
     imageArea.SendMessage(WM_SIZE, 0, 0);
 
     /* by moving the window, the things in WM_SIZE are done */
-    MoveWindow(hwnd, 100, 100, 600, 450, TRUE);
+    mainWindow.SetWindowPlacement(&(registrySettings.WindowPlacement));
 
     /* creating the text editor window for the text tool */
     RECT textEditWindowPos = {300, 0, 300 + 300, 0 + 200};
@@ -299,6 +309,12 @@ _tWinMain (HINSTANCE hThisInstance, HINSTANCE hPrevInstance, LPTSTR lpszArgument
         DispatchMessage(&messages);
     }
 
+    /* write back settings to registry */
+    registrySettings.ShowThumbnail = showMiniature;
+    registrySettings.BMPWidth = imageModel.GetWidth();
+    registrySettings.BMPHeight = imageModel.GetHeight();
+    registrySettings.Store();
+
     /* The program return-value is 0 - The value that PostQuitMessage() gave */
     return messages.wParam;
 }
index 960dfab..03c120a 100644 (file)
@@ -28,6 +28,7 @@
 #include "mouse.h"
 #include "palette.h"
 #include "palettemodel.h"
+#include "registry.h"
 #include "scrollbox.h"
 #include "selection.h"
 #include "selectionmodel.h"
index c7cee53..5f986c1 100644 (file)
@@ -14,8 +14,7 @@
 
 /* FUNCTIONS ********************************************************/
 
-void
-SetWallpaper(TCHAR * FileName, DWORD dwStyle, DWORD dwTile) //FIXME: Has to be called 2x to apply the pattern (tiled/stretched) too
+void RegistrySettings::SetWallpaper(TCHAR * FileName, DWORD dwStyle, DWORD dwTile) //FIXME: Has to be called 2x to apply the pattern (tiled/stretched) too
 {
     HKEY hDesktop;
     TCHAR szStyle[3], szTile[3];
@@ -42,3 +41,85 @@ SetWallpaper(TCHAR * FileName, DWORD dwStyle, DWORD dwTile) //FIXME: Has to be c
         RegCloseKey(hDesktop);
     }
 }
+
+void RegistrySettings::LoadPresets()
+{
+    BMPHeight = 300;
+    BMPWidth = 400;
+    GridExtent = 1;
+    NoStretching = 0;
+    ShowThumbnail = 0;
+    SnapToGrid = 0;
+    ThumbHeight = 100;
+    ThumbWidth = 120;
+    ThumbXPos = 180;
+    ThumbYPos = 200;
+    UnitSetting = 0;
+    const WINDOWPLACEMENT DefaultWindowPlacement = {
+        sizeof(WINDOWPLACEMENT), 
+        0,
+        SW_SHOWNORMAL,
+        {0, 0},
+        {-1, -1},
+        {100, 100, 700, 550}
+    };
+    WindowPlacement = DefaultWindowPlacement;
+}
+
+void RegistrySettings::Load()
+{
+    HKEY hView;
+    LoadPresets();
+    if (RegOpenKeyEx(HKEY_CURRENT_USER,
+                     _T("Software\\Microsoft\\Windows\\CurrentVersion\\Applets\\Paint\\View"),
+                     0, KEY_READ | KEY_SET_VALUE, &hView) == ERROR_SUCCESS)
+    {
+        DWORD cbData;
+        cbData = sizeof(DWORD);
+        RegQueryValueEx(hView, _T("BMPHeight"), 0, NULL, (LPBYTE) &BMPHeight, &cbData);
+        cbData = sizeof(DWORD);
+        RegQueryValueEx(hView, _T("BMPWidth"), 0, NULL, (LPBYTE) &BMPWidth, &cbData);
+        cbData = sizeof(DWORD);
+        RegQueryValueEx(hView, _T("GridExtent"), 0, NULL, (LPBYTE) &GridExtent, &cbData);
+        cbData = sizeof(DWORD);
+        RegQueryValueEx(hView, _T("NoStretching"), 0, NULL, (LPBYTE) &NoStretching, &cbData);
+        cbData = sizeof(DWORD);
+        RegQueryValueEx(hView, _T("ShowThumbnail"), 0, NULL, (LPBYTE) &ShowThumbnail, &cbData);
+        cbData = sizeof(DWORD);
+        RegQueryValueEx(hView, _T("SnapToGrid"), 0, NULL, (LPBYTE) &SnapToGrid, &cbData);
+        cbData = sizeof(DWORD);
+        RegQueryValueEx(hView, _T("ThumbHeight"), 0, NULL, (LPBYTE) &ThumbHeight, &cbData);
+        cbData = sizeof(DWORD);
+        RegQueryValueEx(hView, _T("ThumbWidth"), 0, NULL, (LPBYTE) &ThumbWidth, &cbData);
+        cbData = sizeof(DWORD);
+        RegQueryValueEx(hView, _T("ThumbXPos"), 0, NULL, (LPBYTE) &ThumbXPos, &cbData);
+        cbData = sizeof(DWORD);
+        RegQueryValueEx(hView, _T("ThumbYPos"), 0, NULL, (LPBYTE) &ThumbYPos, &cbData);
+        cbData = sizeof(DWORD);
+        RegQueryValueEx(hView, _T("UnitSetting"), 0, NULL, (LPBYTE) &UnitSetting, &cbData);
+        cbData = sizeof(WINDOWPLACEMENT);
+        RegQueryValueEx(hView, _T("WindowPlacement"), 0, NULL, (LPBYTE) &WindowPlacement, &cbData);
+    }
+}
+
+void RegistrySettings::Store()
+{
+    HKEY hView;
+    if (RegCreateKeyEx(HKEY_CURRENT_USER,
+                       _T("Software\\Microsoft\\Windows\\CurrentVersion\\Applets\\Paint\\View"),
+                       0, NULL, 0, KEY_READ | KEY_SET_VALUE, NULL, &hView, NULL) == ERROR_SUCCESS)
+    {
+        RegSetValueEx(hView, _T("BMPHeight"), 0, REG_DWORD, (LPBYTE) &BMPHeight, sizeof(DWORD));
+        RegSetValueEx(hView, _T("BMPWidth"), 0, REG_DWORD, (LPBYTE) &BMPWidth, sizeof(DWORD));
+        RegSetValueEx(hView, _T("GridExtent"), 0, REG_DWORD, (LPBYTE) &GridExtent, sizeof(DWORD));
+        RegSetValueEx(hView, _T("NoStretching"), 0, REG_DWORD, (LPBYTE) &NoStretching, sizeof(DWORD));
+        RegSetValueEx(hView, _T("ShowThumbnail"), 0, REG_DWORD, (LPBYTE) &ShowThumbnail, sizeof(DWORD));
+        RegSetValueEx(hView, _T("SnapToGrid"), 0, REG_DWORD, (LPBYTE) &SnapToGrid, sizeof(DWORD));
+        RegSetValueEx(hView, _T("ThumbHeight"), 0, REG_DWORD, (LPBYTE) &ThumbHeight, sizeof(DWORD));
+        RegSetValueEx(hView, _T("ThumbWidth"), 0, REG_DWORD, (LPBYTE) &ThumbWidth, sizeof(DWORD));
+        RegSetValueEx(hView, _T("ThumbXPos"), 0, REG_DWORD, (LPBYTE) &ThumbXPos, sizeof(DWORD));
+        RegSetValueEx(hView, _T("ThumbYPos"), 0, REG_DWORD, (LPBYTE) &ThumbYPos, sizeof(DWORD));
+        RegSetValueEx(hView, _T("UnitSetting"), 0, REG_DWORD, (LPBYTE) &UnitSetting, sizeof(DWORD));
+        RegSetValueEx(hView, _T("WindowPlacement"), 0, REG_BINARY, (LPBYTE) &WindowPlacement, sizeof(WINDOWPLACEMENT));
+    }
+}
index 9a4a992..e16dd0f 100644 (file)
@@ -6,4 +6,27 @@
  * PROGRAMMERS: Benedikt Freisen
  */
 
-void SetWallpaper(TCHAR *szFileName, DWORD dwStyle, DWORD dwTile);
+class RegistrySettings
+{
+private:
+    void LoadPresets();
+
+public:
+    DWORD BMPHeight;
+    DWORD BMPWidth;
+    DWORD GridExtent;
+    DWORD NoStretching;
+    DWORD ShowThumbnail;
+    DWORD SnapToGrid;
+    DWORD ThumbHeight;
+    DWORD ThumbWidth;
+    DWORD ThumbXPos;
+    DWORD ThumbYPos;
+    DWORD UnitSetting;
+    WINDOWPLACEMENT WindowPlacement;
+
+    static void SetWallpaper(TCHAR *szFileName, DWORD dwStyle, DWORD dwTile);
+
+    void Load();
+    void Store();
+};
index e5f0568..f86d21e 100644 (file)
@@ -12,7 +12,6 @@
 #include "precomp.h"
 
 #include "dialogs.h"
-#include "registry.h"
 
 /* FUNCTIONS ********************************************************/
 
@@ -188,6 +187,7 @@ LRESULT CMainWindow::OnCreate(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHa
 
 LRESULT CMainWindow::OnDestroy(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
 {
+    GetWindowPlacement(&(registrySettings.WindowPlacement));
     PostQuitMessage(0); /* send a WM_QUIT to the message queue */
     return 0;
 }
@@ -428,13 +428,13 @@ LRESULT CMainWindow::OnCommand(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bH
                 GlobalFree(pd.hDevNames);
             break;
         case IDM_FILEASWALLPAPERPLANE:
-            SetWallpaper(filepathname, 1, 1);
+            RegistrySettings::SetWallpaper(filepathname, 1, 1);
             break;
         case IDM_FILEASWALLPAPERCENTERED:
-            SetWallpaper(filepathname, 1, 0);
+            RegistrySettings::SetWallpaper(filepathname, 1, 0);
             break;
         case IDM_FILEASWALLPAPERSTRETCHED:
-            SetWallpaper(filepathname, 2, 0);
+            RegistrySettings::SetWallpaper(filepathname, 2, 0);
             break;
         case IDM_EDITUNDO:
             imageModel.Undo();