OSDN Git Service

BUG: [ 1740106 ] Flicker when resizing location pane
authorKimmo Varis <kimmov@gmail.com>
Sun, 25 May 2008 21:29:53 +0000 (21:29 +0000)
committerKimmo Varis <kimmov@gmail.com>
Sun, 25 May 2008 21:29:53 +0000 (21:29 +0000)
Docs/Users/ChangeLog.txt
Src/Common/memdc.h [new file with mode: 0644]
Src/LocationView.cpp
Src/LocationView.h
Src/Merge.vcproj

index 08920fc..7dad092 100644 (file)
@@ -2,6 +2,9 @@ This file summarizes changes in WinMerge releases.
 Numbers in parentheses refer to SourceForge.net tracker item numbers (#XXXXX) or
 to Subversion revision numbers (rXXXXX).
 
+WinMerge 2.9.1.3
+  BugFix: Location Pane flickers when resizing (#1740106)
+
 WinMerge 2.9.1.2 - 2008-05-23 (r5362)
   Optimize location pane (r5341, r5342, r5346, r5351, r5355, r5356)
   BugFix: Version Control filter did not match all VSS files (#1881186)
diff --git a/Src/Common/memdc.h b/Src/Common/memdc.h
new file mode 100644 (file)
index 0000000..7d731a9
--- /dev/null
@@ -0,0 +1,110 @@
+#ifndef _MEMDC_H_
+#define _MEMDC_H_
+
+//////////////////////////////////////////////////
+// CMemDC - memory DC
+//
+// Author: Keith Rule
+// Email:  keithr@europa.com
+// Copyright 1996-2002, Keith Rule
+//
+// You may freely use or modify this code provided this
+// Copyright is included in all derived versions.
+//
+// History - 10/3/97 Fixed scrolling bug.
+//                   Added print support. - KR
+//
+//           11/3/99 Fixed most common complaint. Added
+//                   background color fill. - KR
+//
+//           11/3/99 Added support for mapping modes other than
+//                   MM_TEXT as suggested by Lee Sang Hun. - KR
+//
+//           02/11/02 Added support for CScrollView as supplied
+//                    by Gary Kirkham. - KR
+//
+// This class implements a memory Device Context which allows
+// flicker free drawing.
+
+class CMemDC : public CDC {
+private:       
+       CBitmap         m_bitmap;               // Offscreen bitmap
+       CBitmap*        m_oldBitmap;    // bitmap originally found in CMemDC
+       CDC*            m_pDC;                  // Saves CDC passed in constructor
+       CRect           m_rect;                 // Rectangle of drawing area.
+       BOOL            m_bMemDC;               // TRUE if CDC really is a Memory DC.
+public:
+       
+       CMemDC(CDC* pDC, const CRect* pRect = NULL) : CDC()
+       {
+               ASSERT(pDC != NULL); 
+
+               // Some initialization
+               m_pDC = pDC;
+               m_oldBitmap = NULL;
+               m_bMemDC = !pDC->IsPrinting();
+
+               // Get the rectangle to draw
+               if (pRect == NULL) {
+                       pDC->GetClipBox(&m_rect);
+               } else {
+                       m_rect = *pRect;
+               }
+
+               if (m_bMemDC) {
+                       // Create a Memory DC
+                       CreateCompatibleDC(pDC);
+                       pDC->LPtoDP(&m_rect);
+
+                       m_bitmap.CreateCompatibleBitmap(pDC, m_rect.Width(), m_rect.Height());
+                       m_oldBitmap = SelectObject(&m_bitmap);
+
+                       SetMapMode(pDC->GetMapMode());
+
+                       SetWindowExt(pDC->GetWindowExt());
+                       SetViewportExt(pDC->GetViewportExt());
+
+                       pDC->DPtoLP(&m_rect);
+                       SetWindowOrg(m_rect.left, m_rect.top);
+               } else {
+                       // Make a copy of the relevent parts of the current DC for printing
+                       m_bPrinting = pDC->m_bPrinting;
+                       m_hDC       = pDC->m_hDC;
+                       m_hAttribDC = pDC->m_hAttribDC;
+               }
+
+               // Fill background 
+               FillSolidRect(m_rect, pDC->GetBkColor());
+       }
+       
+       ~CMemDC()       
+       {               
+               if (m_bMemDC) {
+                       // Copy the offscreen bitmap onto the screen.
+                       m_pDC->BitBlt(m_rect.left, m_rect.top, m_rect.Width(), m_rect.Height(),
+                               this, m_rect.left, m_rect.top, SRCCOPY);                        
+                       
+                       //Swap back the original bitmap.
+                       SelectObject(m_oldBitmap);              
+               } else {
+                       // All we need to do is replace the DC with an illegal value,
+                       // this keeps us from accidently deleting the handles associated with
+                       // the CDC that was passed to the constructor.                  
+                       m_hDC = m_hAttribDC = NULL;
+               }       
+       }
+       
+       // Allow usage as a pointer     
+       CMemDC* operator->() 
+       {
+               return this;
+       }       
+
+       // Allow usage as a pointer     
+       operator CMemDC*() 
+       {
+               return this;
+       }
+};
+
+#endif
\ No newline at end of file
index 76ad545..a621fb7 100644 (file)
@@ -39,6 +39,7 @@
 #include "OptionsDef.h"
 #include "MergeLineFlags.h"
 #include "Bitmap.h"
+#include "memdc.h"
 
 #ifdef _DEBUG
 #define new DEBUG_NEW
@@ -163,11 +164,19 @@ void CLocationView::OnUpdate( CView* pSender, LPARAM lHint, CObject* pHint )
 }
 
 /** 
- * @brief Change the background color for a CView
- *        See http://support.microsoft.com/kb/103786
+ * @brief Override for CMemDC to work.
  */
 BOOL CLocationView::OnEraseBkgnd(CDC* pDC)
 {
+       return FALSE;
+}
+
+/**
+ * @brief Draw custom (non-white) background.
+ * @param [in] pDC Pointer to draw context.
+ */
+void CLocationView::DrawBackground(CDC* pDC)
+{
        // Set brush to desired background color
        CBrush backBrush(RGB(0xe8, 0xe8, 0xf4));
        
@@ -180,7 +189,6 @@ BOOL CLocationView::OnEraseBkgnd(CDC* pDC)
        pDC->PatBlt(rect.left, rect.top, rect.Width(), rect.Height(), PATCOPY);
 
        pDC->SelectObject(pOldBrush);
-       return TRUE;
 }
 
 /**
@@ -295,6 +303,8 @@ void CLocationView::OnDraw(CDC* pDC)
 
        if (!m_view[MERGE_VIEW_LEFT]->IsInitialized()) return;
 
+       CMemDC dc(pDC);
+
        COLORREF cr0 = CLR_NONE; // Left side color
        COLORREF cr1 = CLR_NONE; // Right side color
        COLORREF crt = CLR_NONE; // Text color
@@ -303,12 +313,13 @@ void CLocationView::OnDraw(CDC* pDC)
        m_movedLines.RemoveAll();
 
        CalculateBars();
+       DrawBackground(&dc);
 
        // Draw bar outlines
-       CPen* oldObj = (CPen*)pDC->SelectStockObject(BLACK_PEN);
-       pDC->Rectangle(m_leftBar);
-       pDC->Rectangle(m_rightBar);
-       pDC->SelectObject(oldObj);
+       CPen* oldObj = (CPen*)dc.SelectStockObject(BLACK_PEN);
+       dc.Rectangle(m_leftBar);
+       dc.Rectangle(m_rightBar);
+       dc.SelectObject(oldObj);
 
        // Iterate the differences list and draw differences as colored blocks.
 
@@ -334,12 +345,12 @@ void CLocationView::OnDraw(CDC* pDC)
                        // Draw left side block
                        m_view[MERGE_VIEW_LEFT]->GetLineColors2(block.top_line, 0, cr0, crt, bwh);
                        CRect r0(m_leftBar.left, block.top_coord, m_leftBar.right, block.bottom_coord);
-                       DrawRect(pDC, r0, cr0, bInsideDiff);
+                       DrawRect(&dc, r0, cr0, bInsideDiff);
 
                        // Draw right side block
                        m_view[MERGE_VIEW_RIGHT]->GetLineColors2(block.top_line, 0, cr1, crt, bwh);
                        CRect r1(m_rightBar.left, block.top_coord, m_rightBar.right, block.bottom_coord);
-                       DrawRect(pDC, r1, cr1, bInsideDiff);
+                       DrawRect(&dc, r1, cr1, bInsideDiff);
                }
                nPrevEndY = block.bottom_coord;
 
@@ -423,13 +434,13 @@ void CLocationView::OnDraw(CDC* pDC)
        }
 
        if (m_displayMovedBlocks != DISPLAY_MOVED_NONE)
-               DrawConnectLines(pDC);
+               DrawConnectLines(&dc);
 
        // Since we have invalidated locationbar there is no previous
        // arearect to remove
        m_visibleTop = -1;
        m_visibleBottom = -1;
-       DrawVisibleAreaRect(pDC);
+       DrawVisibleAreaRect(&dc);
 
        m_bDrawn = true;
 }
index 0e40175..c52444e 100644 (file)
@@ -94,6 +94,7 @@ protected:
        void DrawDiffMarker(CDC* pDC, int yCoord);
        void CalculateBars();
        void CalculateBlocks();
+       void DrawBackground(CDC* pDC);
 
 private:
        CMergeEditView* m_view[MERGE_VIEW_COUNT]; //*< Table for view pointers */
index b277eb5..c18135e 100644 (file)
                                RelativePath="Common\coretools.h">
                        </File>
                        <File
-                               RelativePath="Common\coretypes.h"
-                               >
+                               RelativePath="Common\coretypes.h">
                        </File>
                        <File
                                RelativePath="common\CShellFileOp.h">
                                RelativePath="Common\MDITabBar.h">
                        </File>
                        <File
+                               RelativePath=".\Common\memdc.h">
+                       </File>
+                       <File
                                RelativePath="Merge.h">
                        </File>
                        <File