OSDN Git Service

- Fix some cppcheck warnings
authorsdottaka <sdottaka@sourceforge.net>
Tue, 16 Sep 2014 10:43:17 +0000 (19:43 +0900)
committersdottaka <sdottaka@sourceforge.net>
Tue, 16 Sep 2014 10:43:17 +0000 (19:43 +0900)
- Improve zoom

src/CImgMergeWindow.hpp
src/CImgWindow.hpp
src/WinIMerge.cpp

index f7f7088..210cfb5 100644 (file)
@@ -49,29 +49,32 @@ template <class T> struct Array2D
                memset(m_data, 0, m_width * m_height * sizeof(T));\r
        }\r
 \r
-       Array2D(const Array2D<T>& other) : m_width(other.m_width), m_height(other.m_height), m_data(new T[other.m_width * other.m_height])\r
+       Array2D(const Array2D& other) : m_width(other.m_width), m_height(other.m_height), m_data(new T[other.m_width * other.m_height])\r
        {\r
                memcpy(m_data, other.m_data, m_width * m_height * sizeof(T));\r
        }\r
 \r
        Array2D& operator=(const Array2D& other)\r
        {\r
-               delete m_data;\r
-               m_width  = other.m_width;\r
-               m_height = other.m_height;\r
-               m_data = new T[other.m_width * other.m_height];\r
-               memcpy(m_data, other.m_data, m_width * m_height * sizeof(T));\r
+               if (this != &other)\r
+               {\r
+                       delete[] m_data;\r
+                       m_width  = other.m_width;\r
+                       m_height = other.m_height;\r
+                       m_data = new T[other.m_width * other.m_height];\r
+                       memcpy(m_data, other.m_data, m_width * m_height * sizeof(T));\r
+               }\r
                return *this;\r
        }\r
 \r
        ~Array2D()\r
        {\r
-               delete m_data;\r
+               delete[] m_data;\r
        }\r
 \r
        void resize(size_t width, size_t height)\r
        {\r
-               delete m_data;\r
+               delete[] m_data;\r
                m_data = new T[width * height];\r
                m_width  = width;\r
                m_height = height;\r
@@ -90,7 +93,7 @@ template <class T> struct Array2D
 \r
        void clear()\r
        {\r
-               delete m_data;\r
+               delete[] m_data;\r
                m_data = NULL;\r
                m_width = 0;\r
                m_height = 0;\r
@@ -146,8 +149,11 @@ public:
                , m_diffColorAlpha(0.7)\r
                , m_diffCount(0)\r
                , m_currentDiffIndex(-1)\r
+               , m_oldSplitPosX(-4)\r
+               , m_oldSplitPosY(-4)\r
        {\r
                memset(m_ChildWndProc, 0, sizeof(m_ChildWndProc));\r
+               memset(m_currentPage, 0, sizeof(m_currentPage));\r
        }\r
 \r
        ~CImgMergeWindow()\r
@@ -277,7 +283,7 @@ public:
 \r
        void SetBackColor(RGBQUAD backColor)\r
        {\r
-               for (int i = 0; i < m_nImages; ++i)\r
+               for (int i = 0; i < 3; ++i)\r
                        m_imgWindow[i].SetBackColor(backColor);\r
        }\r
 \r
@@ -288,7 +294,7 @@ public:
 \r
        void SetUseBackColor(bool useBackColor)\r
        {\r
-               for (int i = 0; i < m_nImages; ++i)\r
+               for (int i = 0; i < 3; ++i)\r
                        m_imgWindow[i].SetUseBackColor(useBackColor);\r
        }\r
 \r
@@ -299,7 +305,7 @@ public:
 \r
        void SetZoom(double zoom)\r
        {\r
-               for (int i = 0; i < m_nImages; ++i)\r
+               for (int i = 0; i < 3; ++i)\r
                        m_imgWindow[i].SetZoom(zoom);\r
        }\r
 \r
@@ -484,7 +490,7 @@ public:
 \r
        bool LastConflict()\r
        {\r
-               for (int i = m_diffInfos.size() - 1; i >= 0; --i)\r
+               for (int i = static_cast<int>(m_diffInfos.size() - 1); i >= 0; --i)\r
                {\r
                        if (m_diffInfos[i].op == DiffInfo::OP_DIFF)\r
                        {\r
@@ -499,11 +505,11 @@ public:
 \r
        bool NextConflict()\r
        {\r
-               for (int i = m_currentDiffIndex + 1; i < m_diffInfos.size(); ++i)\r
+               for (size_t i = m_currentDiffIndex + 1; i < m_diffInfos.size(); ++i)\r
                {\r
                        if (m_diffInfos[i].op == DiffInfo::OP_DIFF)\r
                        {\r
-                               m_currentDiffIndex = i;\r
+                               m_currentDiffIndex = static_cast<int>(i);\r
                                break;\r
                        }\r
                }\r
@@ -551,15 +557,15 @@ public:
 \r
        int  GetNextConflictIndex() const\r
        {\r
-               for (int i = m_currentDiffIndex + 1; i < m_diffInfos.size(); ++i)\r
+               for (size_t i = m_currentDiffIndex + 1; i < m_diffInfos.size(); ++i)\r
                        if (m_diffInfos[i].op == DiffInfo::OP_DIFF)\r
-                               return i;\r
+                               return static_cast<int>(i);\r
                return -1;\r
        }\r
 \r
        int  GetPrevConflictIndex() const\r
        {\r
-               for (int i = m_currentDiffIndex - 1; i >= 0; --i)\r
+               for (int i = static_cast<int>(m_currentDiffIndex - 1); i >= 0; --i)\r
                        if (m_diffInfos[i].op == DiffInfo::OP_DIFF)\r
                                return i;\r
                return -1;\r
@@ -570,30 +576,27 @@ public:
                if (m_nImages <= 1)\r
                        return;\r
                InitializeDiff();\r
-               if (m_showDifferences)\r
+               if (m_nImages == 2)\r
                {\r
-                       if (m_nImages == 2)\r
-                       {\r
-                               CompareImages2(0, 1, m_diff);\r
-                               m_diffCount = MarkDiffIndex(m_diff);\r
-                       }\r
-                       else if (m_nImages == 3)\r
-                       {\r
-                               CompareImages2(0, 1, m_diff01);\r
-                               CompareImages2(2, 1, m_diff21);\r
-                               CompareImages2(0, 2, m_diff02);\r
-                               Make3WayDiff(m_diff01, m_diff21, m_diff);\r
-                               m_diffCount = MarkDiffIndex3way(m_diff01, m_diff21, m_diff02, m_diff);\r
-                       }\r
-                       if (m_currentDiffIndex >= m_diffCount)\r
-                               m_currentDiffIndex = m_diffCount - 1;\r
+                       CompareImages2(0, 1, m_diff);\r
+                       m_diffCount = MarkDiffIndex(m_diff);\r
+               }\r
+               else if (m_nImages == 3)\r
+               {\r
+                       CompareImages2(0, 1, m_diff01);\r
+                       CompareImages2(2, 1, m_diff21);\r
+                       CompareImages2(0, 2, m_diff02);\r
+                       Make3WayDiff(m_diff01, m_diff21, m_diff);\r
+                       m_diffCount = MarkDiffIndex3way(m_diff01, m_diff21, m_diff02, m_diff);\r
                }\r
+               if (m_currentDiffIndex >= m_diffCount)\r
+                       m_currentDiffIndex = m_diffCount - 1;\r
                RefreshImages();\r
        }\r
 \r
        void ScrollToDiff(int diffIndex)\r
        {\r
-               if (diffIndex >= 0 && diffIndex < m_diffInfos.size())\r
+               if (diffIndex >= 0 && diffIndex < static_cast<int>(m_diffInfos.size()))\r
                {\r
                        for (int i = 0; i < m_nImages; ++i)\r
                                m_imgWindow[i].ScrollTo(m_diffInfos[diffIndex].pt.x * m_diffBlockSize, m_diffInfos[diffIndex].pt.y * m_diffBlockSize);\r
@@ -956,10 +959,10 @@ private:
                        if (data(x, y) != -1)\r
                                continue;\r
                        data(x, y) = val;\r
-                       if (x + 1 < data.width())\r
+                       if (x + 1 < static_cast<int>(data.width()))\r
                        {\r
                                stack.push_back(Point<int>(x + 1, y));\r
-                               if (y + 1 < data.height())\r
+                               if (y + 1 < static_cast<int>(data.height()))\r
                                        stack.push_back(Point<int>(x + 1, y + 1));\r
                                if (y - 1 >= 0)\r
                                        stack.push_back(Point<int>(x + 1, y - 1));\r
@@ -967,12 +970,12 @@ private:
                        if (x - 1 >= 0)\r
                        {\r
                                stack.push_back(Point<int>(x - 1, y));\r
-                               if (y + 1 < data.height())\r
+                               if (y + 1 < static_cast<int>(data.height()))\r
                                        stack.push_back(Point<int>(x - 1, y + 1));\r
                                if (y - 1 >= 0)\r
                                        stack.push_back(Point<int>(x - 1, y - 1));\r
                        }\r
-                       if (y + 1 < data.height())\r
+                       if (y + 1 < static_cast<int>(data.height()))\r
                                stack.push_back(Point<int>(x, y + 1));\r
                        if (y - 1 >= 0)\r
                                stack.push_back(Point<int>(x, y - 1));\r
@@ -1020,7 +1023,7 @@ private:
                        }\r
                }\r
                \r
-               for (int i = 0; i < m_diffInfos.size(); ++i)\r
+               for (size_t i = 0; i < m_diffInfos.size(); ++i)\r
                {\r
                        int op;\r
                        if (counter[i][0] != 0 && counter[i][1] == 0 && counter[i][2] == 0 && counter[i][3] == 0)\r
@@ -1284,7 +1287,7 @@ private:
        {\r
                if (iMsg == WM_NCCREATE)\r
                        SetWindowLongPtr(hwnd, GWLP_USERDATA, reinterpret_cast<LONG_PTR>(reinterpret_cast<LPCREATESTRUCT>(lParam)->lpCreateParams));\r
-               CImgMergeWindow *pImgWnd = (CImgMergeWindow *)GetWindowLongPtr(hwnd, GWLP_USERDATA);\r
+               CImgMergeWindow *pImgWnd = reinterpret_cast<CImgMergeWindow *>(GetWindowLongPtr(hwnd, GWLP_USERDATA));\r
                LRESULT lResult = pImgWnd->OnWndMsg(hwnd, iMsg, wParam, lParam);\r
                return lResult;\r
        }\r
@@ -1293,7 +1296,7 @@ private:
        {\r
                Event evt;\r
                int i;\r
-               CImgMergeWindow *pImgWnd = (CImgMergeWindow *)GetWindowLongPtr(GetParent(hwnd), GWLP_USERDATA);\r
+               CImgMergeWindow *pImgWnd = reinterpret_cast<CImgMergeWindow *>(GetWindowLongPtr(GetParent(hwnd), GWLP_USERDATA));\r
                for (i = 0; i < pImgWnd->m_nImages; ++i)\r
                        if (pImgWnd->m_imgWindow[i].GetHWND() == hwnd)\r
                                break;\r
index dea5a94..25655df 100644 (file)
@@ -139,8 +139,10 @@ public:
        {\r
                m_backColor = backColor;\r
                if (m_fip)\r
+               {\r
                        m_fip->setModified(true);\r
-               InvalidateRect(m_hWnd, NULL, TRUE);\r
+                       InvalidateRect(m_hWnd, NULL, TRUE);\r
+               }\r
        }\r
 \r
        bool GetUseBackColor() const\r
@@ -152,8 +154,10 @@ public:
        {\r
                m_useBackColor = useBackColor;\r
                if (m_fip)\r
+               {\r
                        m_fip->setModified(true);\r
-               InvalidateRect(m_hWnd, NULL, TRUE);\r
+                       InvalidateRect(m_hWnd, NULL, TRUE);\r
+               }\r
        }\r
 \r
        double GetZoom() const\r
@@ -163,11 +167,17 @@ public:
 \r
        void SetZoom(double zoom)\r
        {\r
+               double oldZoom = m_zoom;\r
                m_zoom = zoom;\r
-               m_nVScrollPos = 0;\r
-               m_nHScrollPos = 0;\r
-               CalcScrollBarRange();\r
-               InvalidateRect(m_hWnd, NULL, TRUE);\r
+               if (m_zoom < 0.1)\r
+                       m_zoom = 0.1;\r
+               m_nVScrollPos = static_cast<int>(m_nVScrollPos / oldZoom * m_zoom);\r
+               m_nHScrollPos = static_cast<int>(m_nHScrollPos / oldZoom * m_zoom);\r
+               if (m_fip)\r
+               {\r
+                       CalcScrollBarRange();\r
+                       InvalidateRect(m_hWnd, NULL, TRUE);\r
+               }\r
        }\r
 \r
        void Invalidate()\r
@@ -376,9 +386,9 @@ private:
                else\r
                {\r
                        if (zDelta > 0)\r
-                               SetZoom(m_zoom * 1.2);\r
+                               SetZoom(m_zoom + 0.1);\r
                        else\r
-                               SetZoom(m_zoom * 0.8);\r
+                               SetZoom(m_zoom - 0.1);\r
                }\r
        }\r
 \r
@@ -462,7 +472,7 @@ private:
        {\r
                if (iMsg == WM_NCCREATE)\r
                        SetWindowLongPtr(hwnd, GWLP_USERDATA, reinterpret_cast<LONG_PTR>(reinterpret_cast<LPCREATESTRUCT>(lParam)->lpCreateParams));\r
-               CImgWindow *pImgWnd = (CImgWindow *)GetWindowLongPtr(hwnd, GWLP_USERDATA);\r
+               CImgWindow *pImgWnd = reinterpret_cast<CImgWindow *>(GetWindowLongPtr(hwnd, GWLP_USERDATA));\r
                LRESULT lResult = pImgWnd->OnWndMsg(hwnd, iMsg, wParam, lParam);\r
                return lResult;\r
        }\r
@@ -474,4 +484,4 @@ private:
        double m_zoom;\r
        bool m_useBackColor;\r
        RGBQUAD m_backColor;\r
-};
\ No newline at end of file
+};\r
index af99c86..b72f79f 100644 (file)
@@ -186,7 +186,6 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
        case WM_COMMAND:\r
        {\r
                int wmId    = LOWORD(wParam); \r
-               int wmEvent = HIWORD(wParam); \r
                switch (wmId)\r
                {\r
                case ID_FILE_OPEN:\r