Browse Source

fixed issue with window size not showing correct, caused window to be hidden

git-svn-id: svn://svn.code.sf.net/p/ditto-cp/code/trunk@733 595ec19a-5cb4-439b-94a8-42fb3063c22c
sabrogden 11 years ago
parent
commit
3627def00c
4 changed files with 44 additions and 18 deletions
  1. 11 1
      Misc.cpp
  2. 2 6
      QPasteWnd.cpp
  3. 1 1
      QPasteWnd.h
  4. 30 10
      QuickPaste.cpp

+ 11 - 1
Misc.cpp

@@ -802,6 +802,8 @@ BOOL EnsureWindowVisible(CRect *pcrRect)
 		return TRUE;
 	}
 
+	BOOL ret = FALSE;
+
 	CRect crMonitor;
 	GetMonitorRect(nMonitor, crMonitor);
 
@@ -810,13 +812,17 @@ BOOL EnsureWindowVisible(CRect *pcrRect)
 	if(lDiff < 0)
 	{
 		pcrRect->left += abs(lDiff);
+		pcrRect->right += abs(lDiff);
+		ret = TRUE;
 	}
 
 	//Right side
 	lDiff = pcrRect->right - crMonitor.right;
 	if(lDiff > 0)
 	{
+		pcrRect->left -= abs(lDiff);
 		pcrRect->right -= abs(lDiff);
+		ret = TRUE;
 	}
 
 	//Top
@@ -824,16 +830,20 @@ BOOL EnsureWindowVisible(CRect *pcrRect)
 	if(lDiff < 0)
 	{
 		pcrRect->top += abs(lDiff);
+		pcrRect->bottom += abs(lDiff);
+		ret = TRUE;
 	}
 
 	//Bottom
 	lDiff = pcrRect->bottom - crMonitor.bottom;
 	if(lDiff > 0)
 	{
+		pcrRect->top -= abs(lDiff);
 		pcrRect->bottom -= abs(lDiff);
+		ret = TRUE;
 	}
 
-	return TRUE;
+	return ret;
 }
 
 __int64 GetLastWriteTime(const CString &csFile)

+ 2 - 6
QPasteWnd.cpp

@@ -231,13 +231,9 @@ HBRUSH CQPasteWnd::CtlColor(CDC *pDC, UINT nCtlColor)
     return (HBRUSH)GetStockObject(NULL_BRUSH);
 }
 
-BOOL CQPasteWnd::Create(const POINT &ptStart, CWnd *pParentWnd)
+BOOL CQPasteWnd::Create(CRect rect, CWnd *pParentWnd)
 {
-    // Get the previous size of the QPaste window
-    CSize szWnd;
-    CGetSetOptions::GetQuickPasteSize(szWnd);
-
-    return CWndEx::Create(CRect(ptStart, szWnd), pParentWnd);
+    return CWndEx::Create(rect, pParentWnd);
 }
 
 int CQPasteWnd::OnCreate(LPCREATESTRUCT lpCreateStruct)

+ 1 - 1
QPasteWnd.h

@@ -111,7 +111,7 @@ public:
     // ClassWizard generated virtual function overrides
     //{{AFX_VIRTUAL(CQPasteWnd)
 public:
-    virtual BOOL Create(const POINT &ptStart, CWnd *pParentWnd);
+    virtual BOOL Create(CRect rect, CWnd *pParentWnd);
     virtual BOOL PreTranslateMessage(MSG *pMsg);
 
 	bool CheckActions(MSG * pMsg);

+ 30 - 10
QuickPaste.cpp

@@ -43,8 +43,10 @@ void CQuickPaste::Create(CWnd *pParent)
 	// load previous position and size
 	CGetSetOptions::GetQuickPastePoint(point);
 	CGetSetOptions::GetQuickPasteSize(csSize);
+
+	CRect crRect = CRect(point, csSize);
 	// Create the window
-	ASSERT( m_pwndPaste->Create(point, pParent) );
+	ASSERT( m_pwndPaste->Create(crRect, pParent) );
 	// place it at the previous position and size
 	m_pwndPaste->MoveWindow(CRect(point, csSize));
 
@@ -166,6 +168,28 @@ void CQuickPaste::ShowQPasteWnd(CWnd *pParent, bool bAtPrevPos, bool bFromKeyboa
 		GetCursorPos(&point);
 	else if(nPosition == POS_AT_PREVIOUS)
 		CGetSetOptions::GetQuickPastePoint(point);
+
+	CRect crRect = CRect(point, csSize);
+
+	bool forceMoveWindow = false;
+
+	if(g_Opt.m_bEnsureEntireWindowCanBeSeen)
+	{
+		if(EnsureWindowVisible(&crRect))
+		{
+			forceMoveWindow = true;
+		}
+	}
+	
+	if((crRect.left >= (crRect.right - 20)) ||
+		(crRect.top >= (crRect.bottom - 20)))
+	{
+		CRect orig = crRect;
+		crRect = CRect(ptCaret, CSize(300, 300));
+		forceMoveWindow = true;
+
+		Log(StrF(_T("Invalid initial size %d %d %d %d, Centered Window %d %d %d %d"), orig.left, orig.top, orig.right, orig.bottom, crRect.left, crRect.top, crRect.right, crRect.bottom));
+	}
 	
 	if( !IsWindow(m_pwndPaste->m_hWnd) )
 	{
@@ -176,17 +200,13 @@ void CQuickPaste::ShowQPasteWnd(CWnd *pParent, bool bAtPrevPos, bool bFromKeyboa
 			pLocalParent = NULL;
 		}
 
-		VERIFY( m_pwndPaste->Create(point, pLocalParent) );
-	}
-
-	CRect crRect = CRect(point, csSize);
-
-	if(g_Opt.m_bEnsureEntireWindowCanBeSeen)
-		EnsureWindowVisible(&crRect);
+		VERIFY( m_pwndPaste->Create(crRect, pLocalParent) );
+	}	
 	
 	if((nPosition == POS_AT_CARET) ||
 		(nPosition == POS_AT_CURSOR) ||
-		(bAtPrevPos))
+		bAtPrevPos ||
+		forceMoveWindow)
 	{
 		m_pwndPaste->MoveWindow(crRect);
 	}
@@ -201,7 +221,7 @@ void CQuickPaste::ShowQPasteWnd(CWnd *pParent, bool bAtPrevPos, bool bFromKeyboa
 	}
 	m_pwndPaste->SetForegroundWindow();
 
-	Log(StrF(_T("END of ShowQPasteWnd, AtPrevPos: %d, FromKeyboard: %d, RefillList: %d"), bAtPrevPos, bFromKeyboard, bReFillList));
+	Log(StrF(_T("END of ShowQPasteWnd, AtPrevPos: %d, FromKeyboard: %d, RefillList: %d, Position, %d %d %d %d"), bAtPrevPos, bFromKeyboard, bReFillList, crRect.left, crRect.top, crRect.right, crRect.bottom));
 }
 
 void CQuickPaste::MoveSelection(bool down)