Browse Source

changes for putting the richtext box in the tooltip window
[SAB]


git-svn-id: svn://svn.code.sf.net/p/ditto-cp/code/trunk@169 595ec19a-5cb4-439b-94a8-42fb3063c22c

sabrogden 21 years ago
parent
commit
2fa04033bb
7 changed files with 271 additions and 65 deletions
  1. 1 0
      CP_Main.h
  2. 49 6
      QListCtrl.cpp
  3. 2 0
      QListCtrl.h
  4. 8 4
      QPasteWnd.cpp
  5. 186 42
      ToolTipEx.cpp
  6. 10 1
      ToolTipEx.h
  7. 15 12
      WndEx.cpp

+ 1 - 0
CP_Main.h

@@ -128,6 +128,7 @@ public:
 
 	bool	m_bShowingOptions;
 	bool	m_bShowingQuickPaste;
+	bool	m_bRefreshView;
 
 	CString m_Status;
 	CQPasteWnd* QPasteWnd() { return m_pMainFrame->QuickPaste.m_pwndPaste; }

+ 49 - 6
QListCtrl.cpp

@@ -770,7 +770,6 @@ int CQListCtrl::OnCreate(LPCREATESTRUCT lpCreateStruct)
 	m_pToolTip = new CToolTipEx;
 	m_pToolTip->Create(this);
 	
-	
 	return 0;
 }
 
@@ -917,13 +916,47 @@ void CQListCtrl::ShowFullDescription(bool bFromAuto)
 
 	if(m_pToolTip)
 	{
+		m_pToolTip->SetToolTipText(cs);
+
 		CClipFormat Clip;
-		Clip.m_cfType = CF_DIB;
-		static CBitmap *pBitMap = NULL;
+		
+		Clip.m_cfType = CF_TEXT;
+
+		if(GetClipData(nItem, Clip) && Clip.m_hgData)
+		{
+			LPVOID pvData = GlobalLock(Clip.m_hgData);
+			if(pvData)
+			{
+				CString csText = (char*)pvData;
+				m_pToolTip->SetToolTipText(csText);
+			}
+
+			GlobalUnlock(Clip.m_hgData);
+
+			Clip.Clear();
+		}
+		
+		Clip.m_cfType = RegisterClipboardFormat(CF_RTF);
+
+		if(GetClipData(nItem, Clip) && Clip.m_hgData)
+		{
+			LPVOID pvData = GlobalLock(Clip.m_hgData);
+			if(pvData)
+			{
+				CString csRTF = (char*)pvData;
+				m_pToolTip->SetRTFText(csRTF);
+			}
 
+			GlobalUnlock(Clip.m_hgData);
+
+			Clip.Clear();
+		}	
+			
+		Clip.m_cfType = CF_DIB;
+				
 		if(GetClipData(nItem, Clip) && Clip.m_hgData)
 		{			
-			pBitMap = new CBitmap;
+			CBitmap *pBitMap = new CBitmap;
 			if(pBitMap)
 			{
 				CRect rcItem;
@@ -935,11 +968,14 @@ void CQListCtrl::ShowFullDescription(bool bFromAuto)
 
 				ReleaseDC(pDC);
 
+				//Tooltip wnd will release
 				m_pToolTip->SetBitmap(pBitMap);
 			}
+
+			Clip.Clear();
 		}
+			
 		
-		m_pToolTip->SetToolTipText(cs);
 		m_pToolTip->Show(pt);
 	}
 }
@@ -1027,7 +1063,14 @@ void CQListCtrl::DestroyAndCreateAccelerator(BOOL bCreate)
 void CQListCtrl::OnKillFocus(CWnd* pNewWnd)
 {
 	CListCtrl::OnKillFocus(pNewWnd);
-	m_pToolTip->Hide();
+
+//	if(FocusOnToolTip() == FALSE)
+//		m_pToolTip->Hide();
+}
+
+HWND CQListCtrl::GetToolTipHWnd()
+{
+	return m_pToolTip->GetSafeHwnd();
 }
 
 BOOL CQListCtrl::SetItemCountEx(int iCount, DWORD dwFlags /* = LVSICF_NOINVALIDATEALL */)

+ 2 - 0
QListCtrl.h

@@ -101,6 +101,8 @@ public:
 
 	void SetLogFont(LOGFONT &font);
 
+	HWND GetToolTipHWnd();
+
 protected:
 	void SendSelection(int nItem);;
 	void SendSelection(ARRAY &arrItems);

+ 8 - 4
QPasteWnd.cpp

@@ -316,7 +316,7 @@ void CQPasteWnd::OnActivate(UINT nState, CWnd* pWndOther, BOOL bMinimized)
 {
 	CWndEx::OnActivate(nState, pWndOther, bMinimized);
 	
-	if(m_bHideWnd == false)
+	if(m_bHideWnd == false || m_lstHeader.GetToolTipHWnd() == pWndOther->GetSafeHwnd())
 		return;
 	
 	if (nState == WA_INACTIVE)
@@ -328,6 +328,8 @@ void CQPasteWnd::OnActivate(UINT nState, CWnd* pWndOther, BOOL bMinimized)
 		//re register the global hot keys for the last ten
 		if(theApp.m_bAppExiting == false)
 			g_HotKeys.RegisterAll();
+
+		m_lstHeader.HidePopup();
 	}
 	else if (nState == WA_ACTIVE || nState == WA_CLICKACTIVE)
 	{
@@ -593,7 +595,9 @@ LRESULT CQPasteWnd::OnRefreshView(WPARAM wParam, LPARAM lParam)
 	}
 	if( theApp.m_bShowingQuickPaste )
 	{
-		FillList();
+		HWND hFocus = GetFocus()->GetSafeHwnd();
+		if(hFocus == NULL || hFocus == m_lstHeader.GetSafeHwnd())
+			FillList();
 	}
 	
 	return TRUE;
@@ -2020,7 +2024,7 @@ void CQPasteWnd::OnWindowPosChanging(WINDOWPOS* lpwndpos)
 {
 	CWndEx::OnWindowPosChanging(lpwndpos);
 
-	m_lstHeader.HidePopup();
+//	m_lstHeader.HidePopup();
 	
 	CRect rcScreen;
 	
@@ -2228,4 +2232,4 @@ LRESULT CQPasteWnd::OnUpDown(WPARAM wParam, LPARAM lParam)
 	}
 
 	return TRUE;
-}
+}

+ 186 - 42
ToolTipEx.cpp

@@ -40,6 +40,8 @@ CToolTipEx::~CToolTipEx()
 BEGIN_MESSAGE_MAP(CToolTipEx, CWnd)
 	//{{AFX_MSG_MAP(CToolTipEx)
 	ON_WM_PAINT()
+	ON_WM_SIZE()
+	ON_WM_NCHITTEST()
 	//}}AFX_MSG_MAP
 END_MESSAGE_MAP()
 
@@ -62,6 +64,11 @@ BOOL CToolTipEx::Create(CWnd* pParentWnd)
         return FALSE;
 	}
 
+	m_RichEdit.Create(WS_CHILD|WS_VISIBLE|WS_VSCROLL|WS_HSCROLL|ES_MULTILINE|ES_AUTOVSCROLL|ES_AUTOHSCROLL, CRect(10,10,100,200), this, 1);
+
+	m_RichEdit.SetReadOnly();
+	m_RichEdit.SetBackgroundColor(FALSE, GetSysColor(COLOR_INFOBK));
+
 	SetLogFont(GetSystemToolTipFont(), FALSE);
    
     return TRUE;
@@ -69,35 +76,64 @@ BOOL CToolTipEx::Create(CWnd* pParentWnd)
 
 BOOL CToolTipEx::Show(CPoint point)
 {
+	if(m_pBitmap)
+	{
+		m_RichEdit.ShowWindow(SW_HIDE);
+	}
+	else
+	{
+		m_RichEdit.ShowWindow(SW_SHOW);
+	}
+
 	CRect rect = GetBoundsRect();
 
+	//account for the scroll bars
+	rect.right += 20;
+	rect.bottom += 20;
+
+	//if showing rtf then increase the size because
+	//rtf will probably draw bigger
+	if(m_csRTF != "")
+	{
+		long lNewWidth = rect.Width() + (rect.Width() * .3);
+		rect.right = rect.left + lNewWidth;
+
+		long lNewHeight = rect.Height() + (rect.Height() * 1);
+		rect.bottom = rect.top + lNewHeight;
+	}
+
 	CRect rcScreen;
-	
-	CRect crRectToScreen(point, CPoint(point.x + rect.right, point.y + rect.bottom));
 
-	int nMonitor = GetMonitorFromRect(&crRectToScreen);
+	ClientToScreen(rect);
+
+	int nMonitor = GetMonitorFromRect(&rect);
 	GetMonitorRect(nMonitor, &rcScreen);
 		
-	if(crRectToScreen.right > rcScreen.right)
-	{
-		point.x -= (crRectToScreen.right - rcScreen.right);
-		///Add a border
-		point.x -= 2;
-	}
+	//ensure that we don't go outside the screen
+	if(point.x < 0)
+		point.x = 5;
+	if(point.y < 0)
+		point.y = 5;
 
-	if(crRectToScreen.bottom > rcScreen.bottom)
-	{
-		point.y -= (crRectToScreen.bottom - rcScreen.bottom);
-		//add a border
-		point.y -= 2;
-	}
+	rcScreen.DeflateRect(0, 0, 5, 5);
 
+	long lWidth = rect.Width();
+	long lHeight = rect.Height();
 
-	ShowWindow(SW_HIDE);
-    SetWindowPos(NULL,
-                 point.x, point.y,
-                 rect.Width(), rect.Height(),
-                 SWP_SHOWWINDOW|SWP_NOCOPYBITS|SWP_NOACTIVATE|SWP_NOZORDER);
+	rect.left = point.x;
+	rect.top = point.y;
+	rect.right = rect.left + lWidth;
+	rect.bottom = rect.top + lHeight;
+
+	if(rect.right > rcScreen.right)
+		rect.right = rcScreen.right;
+	if(rect.bottom > rcScreen.bottom)
+		rect.bottom = rcScreen.bottom;
+
+	SetWindowPos(NULL,
+		         point.x, point.y,
+			     rect.Width(), rect.Height(),
+				 SWP_SHOWWINDOW|SWP_NOCOPYBITS|SWP_NOACTIVATE|SWP_NOZORDER);
 
 	return TRUE;
 }
@@ -108,6 +144,9 @@ BOOL CToolTipEx::Hide()
 
 	ShowWindow(SW_HIDE);
 
+	m_csRTF = "";
+	m_csText = "";
+
 	return TRUE;
 }
 
@@ -116,19 +155,19 @@ void CToolTipEx::OnPaint()
 	CPaintDC dc(this); // device context for painting
 
 	CRect rect;
-    GetClientRect(rect);
+	GetClientRect(rect);
 
-	CBrush  Brush, *pOldBrush;
-	Brush.CreateSolidBrush(GetSysColor(COLOR_INFOBK));
+//	CBrush  Brush, *pOldBrush;
+//	Brush.CreateSolidBrush(GetSysColor(COLOR_INFOBK));
 
-	pOldBrush = dc.SelectObject(&Brush);
-	CFont *pOldFont = dc.SelectObject(&m_Font);
+//	pOldBrush = dc.SelectObject(&Brush);
+//	CFont *pOldFont = dc.SelectObject(&m_Font);
 
-    dc.FillRect(&rect, &Brush);
+  //  dc.FillRect(&rect, &Brush);
 
 	// Draw Text
-    dc.SetBkMode(TRANSPARENT);
-    rect.DeflateRect(m_rectMargin);
+//    dc.SetBkMode(TRANSPARENT);
+//    rect.DeflateRect(m_rectMargin);
 
 	if(m_pBitmap)
 	{
@@ -147,11 +186,11 @@ void CToolTipEx::OnPaint()
 		rect.top += nHeight;
 	}
 
-    dc.DrawText(m_csText, rect, m_dwTextStyle);
+    //dc.DrawText(m_csText, rect, m_dwTextStyle);
 
 	// Cleanup
-    dc.SelectObject(pOldBrush);
-	dc.SelectObject(pOldFont);
+//  dc.SelectObject(pOldBrush);
+//	dc.SelectObject(pOldFont);
 }
 
 void CToolTipEx::PostNcDestroy() 
@@ -161,30 +200,61 @@ void CToolTipEx::PostNcDestroy()
     delete this;
 }
 
+BOOL CToolTipEx::PreTranslateMessage(MSG* pMsg) 
+{
+	switch(pMsg->message) 
+	{
+	case WM_KEYDOWN:
+		
+		switch( pMsg->wParam )
+		{
+		case VK_ESCAPE:
+			Hide();
+			return TRUE;
+		case 'C':
+			if(GetKeyState(VK_CONTROL) & 0x8000)
+			{
+				m_RichEdit.Copy();
+			}
+			break;
+		}
+	}
+
+	return CWnd::PreTranslateMessage(pMsg);
+}
+
 BOOL CToolTipEx::OnMsg(MSG* pMsg)
 {
+	if(FALSE == IsWindowVisible())
+	{
+		return FALSE;
+	}
+
 	switch(pMsg->message) 
 	{
 		case WM_WINDOWPOSCHANGING:
 		case WM_LBUTTONDOWN:
 		{
-			//if (!IsCursorInToolTip())
-			Hide();
+			if (!IsCursorInToolTip())
+				Hide();
 			break;
 		}
 		case WM_KEYDOWN:
 		{
-			if(IsWindowVisible())
+			WPARAM vk = pMsg->wParam;
+			if(vk == VK_ESCAPE)
 			{
 				Hide();
-				WPARAM vk = pMsg->wParam;
-				if(vk == VK_ESCAPE)
-				{
-					return TRUE;
-				}
+				return TRUE;
 			}
-			else
-				Hide();
+			else if(vk == VK_TAB)
+			{
+				m_RichEdit.SetFocus();
+				return TRUE;
+			}
+
+			Hide();
+
 			break;
 		}
 		case WM_LBUTTONDBLCLK:
@@ -339,4 +409,78 @@ void CToolTipEx::SetBitmap(CBitmap *pBitmap)
 	DELETE_BITMAP
 
 	m_pBitmap = pBitmap;
-}
+}
+
+void CToolTipEx::OnSize(UINT nType, int cx, int cy) 
+{
+	CWnd::OnSize(nType, cx, cy);
+	
+	if(::IsWindow(m_RichEdit.GetSafeHwnd()) == FALSE)
+		return;
+
+	CRect cr;
+	GetClientRect(cr);
+//	cr.DeflateRect(0, 0, 15, 0);
+	m_RichEdit.MoveWindow(cr);
+}
+
+BOOL CToolTipEx::IsCursorInToolTip()
+{
+	CRect cr;
+	GetWindowRect(cr);
+
+	CPoint cursorPos;
+	GetCursorPos(&cursorPos);
+
+	return cr.PtInRect(cursorPos);
+}
+
+void CToolTipEx::SetRTFText(const CString &csRTF)
+{
+	m_RichEdit.SetRTF(csRTF);
+	m_csRTF = csRTF;
+}
+
+void CToolTipEx::SetToolTipText(const CString &csText)
+{
+	m_RichEdit.SetText(csText);
+	m_csText = csText;
+
+	m_RichEdit.SetFont(&m_Font);
+}
+
+
+UINT CToolTipEx::OnNcHitTest(CPoint point) 
+{
+	CRect crWindow;
+	GetWindowRect(crWindow);
+	
+	const static int nBorder = 10;
+
+	if((point.y < crWindow.top + nBorder) &&
+		(point.x < crWindow.left + nBorder))
+		return HTTOPLEFT;
+	else if((point.y < crWindow.top + nBorder) &&
+		(point.x > crWindow.right - nBorder))
+		return HTTOPRIGHT;
+	else if((point.y > crWindow.bottom - nBorder) &&
+		(point.x > crWindow.right - nBorder))
+		return HTBOTTOMRIGHT;
+	else if((point.y > crWindow.bottom - nBorder) &&
+		(point.x < crWindow.left + nBorder))
+		return HTBOTTOMLEFT;
+
+	if(point.y < crWindow.top + nBorder)
+		return HTTOP;
+	else if(point.y > crWindow.bottom - nBorder)
+		return HTBOTTOM;
+	else if(point.x > crWindow.right - nBorder)
+		return HTRIGHT;
+	else if(point.x < crWindow.left + nBorder)
+		return HTLEFT;
+
+//	if(point.x > crWindow.right - 15)
+//		return HTCAPTION;
+
+	return CWnd::OnNcHitTest(point);
+}

+ 10 - 1
ToolTipEx.h

@@ -7,6 +7,7 @@
 // ToolTipEx.h : header file
 //
 #include "RichEditCtrlEx.h"
+#include "WndEx.h"
 /////////////////////////////////////////////////////////////////////////////
 // CToolTipEx window
 
@@ -25,7 +26,8 @@ public:
 	BOOL Create(CWnd* pParentWnd);
 	BOOL Show(CPoint point);
 	BOOL Hide();
-	void SetToolTipText(CString csText)	{ m_csText = csText; Invalidate(); }
+	void SetToolTipText(const CString &csText);
+	void SetRTFText(const CString &csRTF);
 	void SetBitmap(CBitmap *pBitmap);
 
 // Overrides
@@ -33,6 +35,7 @@ public:
 	//{{AFX_VIRTUAL(CToolTipEx)
 	protected:
 	virtual void PostNcDestroy();
+	virtual BOOL PreTranslateMessage(MSG* pMsg);
 	//}}AFX_VIRTUAL
 
 // Implementation
@@ -45,6 +48,9 @@ protected:
 	CString m_csText;
 	CFont m_Font;
 	CBitmap *m_pBitmap;
+	CString m_csRTF;
+
+	CRichEditCtrlEx m_RichEdit;
 
 	
 
@@ -53,11 +59,14 @@ protected:
 	CRect GetBoundsRect();
 	BOOL SetLogFont(LPLOGFONT lpLogFont, BOOL bRedraw /*=TRUE*/);
 	LPLOGFONT GetSystemToolTipFont();
+	BOOL IsCursorInToolTip();
 
 	// Generated message map functions
 protected:
 	//{{AFX_MSG(CToolTipEx)
 	afx_msg void OnPaint();
+	afx_msg void OnSize(UINT nType, int cx, int cy);
+	afx_msg UINT OnNcHitTest(CPoint point);
 	//}}AFX_MSG
 	DECLARE_MESSAGE_MAP()
 };

+ 15 - 12
WndEx.cpp

@@ -31,6 +31,11 @@ CWndEx::CWndEx()
 	m_bMouseDownOnMinimize = false;
 	m_bMinimized = false;
 	m_bMaxSetTimer = false;
+
+	m_lTopBorder = BORDER;
+	m_lRightBorder = BORDER;
+	m_lBottomBorder = BORDER;
+	m_lLeftBorder = BORDER;
 	
 	SetCaptionColorActive(false, theApp.GetConnectCV());
 }
@@ -88,19 +93,17 @@ bool CWndEx::SetCaptionColorActive(bool bActive, bool ConnectedToClipboard)
 
 BEGIN_MESSAGE_MAP(CWndEx, CWnd)
 //{{AFX_MSG_MAP(CWndEx)
-ON_WM_CREATE()
-ON_WM_NCPAINT()
-ON_WM_NCCALCSIZE()
-ON_WM_NCHITTEST()
-ON_WM_NCLBUTTONDOWN()
-ON_WM_NCMOUSEMOVE()
-ON_WM_NCLBUTTONUP()
-ON_WM_ERASEBKGND()
-ON_WM_TIMER()
-ON_WM_WINDOWPOSCHANGING()
+	ON_WM_CREATE()
+	ON_WM_NCPAINT()
+	ON_WM_NCCALCSIZE()
+	ON_WM_NCHITTEST()
+	ON_WM_NCLBUTTONDOWN()
+	ON_WM_NCMOUSEMOVE()
+	ON_WM_NCLBUTTONUP()
+	ON_WM_ERASEBKGND()
+	ON_WM_TIMER()
+	ON_WM_WINDOWPOSCHANGING()
 //}}AFX_MSG_MAP
-//	ON_WM_NCLBUTTONDBLCLK()
-//	ON_WM_NCACTIVATE()
 ON_WM_SIZE()
 END_MESSAGE_MAP()