| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878 | 
							- #include "stdafx.h"
 
- #include "cp_main.h"
 
- #include "ToolTipEx.h"
 
- #include "BitmapHelper.h"
 
- #include "Options.h"
 
- #include <Richedit.h>
 
- #ifdef _DEBUG
 
-     #define new DEBUG_NEW
 
-     #undef THIS_FILE
 
-     static char THIS_FILE[] = __FILE__;
 
- #endif 
 
- #define DELETE_BITMAP	if(m_imageViewer.m_pBitmap)					\
 
- {								\
 
- m_imageViewer.m_pBitmap->DeleteObject();	\
 
- delete m_imageViewer.m_pBitmap;		\
 
- m_imageViewer.m_pBitmap = NULL;		\
 
- }
 
- /////////////////////////////////////////////////////////////////////////////
 
- // CToolTipEx
 
- CToolTipEx::CToolTipEx(): m_dwTextStyle(DT_EXPANDTABS | DT_EXTERNALLEADING |
 
-                        DT_NOPREFIX | DT_WORDBREAK), m_rectMargin(2, 2, 3, 3),
 
-                         m_pNotifyWnd(NULL), m_clipId(0){}
 
- CToolTipEx::~CToolTipEx()
 
- {
 
-     DELETE_BITMAP 
 
-     m_Font.DeleteObject();
 
- }
 
- BEGIN_MESSAGE_MAP(CToolTipEx, CWnd)
 
- //{{AFX_MSG_MAP(CToolTipEx)
 
- ON_WM_PAINT()
 
- ON_WM_SIZE()
 
- ON_WM_NCHITTEST()
 
- ON_WM_ACTIVATE()
 
- ON_WM_TIMER()
 
- ON_WM_NCPAINT()
 
- ON_WM_NCCALCSIZE()
 
- ON_WM_NCLBUTTONDOWN()
 
- ON_WM_NCMOUSEMOVE()
 
- ON_WM_NCLBUTTONUP()
 
- ON_WM_ERASEBKGND()
 
- ON_COMMAND(ID_FIRST_REMEMBERWINDOWPOSITION, &CToolTipEx::OnRememberwindowposition)
 
- ON_COMMAND(ID_FIRST_SIZEWINDOWTOCONTENT, &CToolTipEx::OnSizewindowtocontent)
 
- ON_COMMAND(ID_FIRST_SCALEIMAGESTOFITWINDOW, &CToolTipEx::OnScaleimagestofitwindow)
 
- ON_COMMAND(2, OnOptions)
 
- ON_WM_RBUTTONDOWN()
 
- ON_WM_SETFOCUS()
 
- ON_COMMAND(ID_FIRST_HIDEDESCRIPTIONWINDOWONM, &CToolTipEx::OnFirstHidedescriptionwindowonm)
 
- ON_COMMAND(ID_FIRST_WRAPTEXT, &CToolTipEx::OnFirstWraptext)
 
- END_MESSAGE_MAP()
 
- /////////////////////////////////////////////////////////////////////////////
 
- // CToolTipEx message handlers
 
- BOOL CToolTipEx::Create(CWnd *pParentWnd)
 
- {
 
-     // Get the class name and create the window
 
-     CString szClassName = AfxRegisterWndClass(CS_CLASSDC | CS_SAVEBITS, LoadCursor(NULL, IDC_ARROW));
 
-     // Create the window - just don't show it yet.
 
-     if( !CWnd::CreateEx(WS_EX_TOPMOST, szClassName, _T(""), WS_POPUP,
 
-        0, 0, 0, 0, pParentWnd->GetSafeHwnd(), 0, NULL))
 
-     {
 
-         return FALSE;
 
-     }	
 
- 	//CString szClassName2 = AfxRegisterWndClass(CS_CLASSDC | CS_SAVEBITS, LoadCursor(NULL, IDC_ARROW));
 
- 	//BOOL b = m_imageViewer.Create(_T(""), szClassName2, WS_CHILD | WS_VISIBLE | WS_VSCROLL | WS_HSCROLL, CRect(0, 0, 0, 0), this, 3);
 
- 	m_imageViewer.Create(this);
 
- 	
 
- 	
 
- 	m_DittoWindow.DoCreate(this);
 
- 	m_DittoWindow.SetCaptionColors(g_Opt.m_Theme.CaptionLeft(), g_Opt.m_Theme.CaptionRight(), g_Opt.m_Theme.Border());
 
- 	m_DittoWindow.SetCaptionOn(this, CGetSetOptions::GetCaptionPos(), true);
 
- 	m_DittoWindow.m_bDrawMaximize = false;
 
- 	m_DittoWindow.m_bDrawMinimize = false;
 
- 	m_DittoWindow.m_bDrawChevron = false;
 
- 	m_DittoWindow.m_sendWMClose = false;
 
-     m_RichEdit.Create(_T(""), _T(""), WS_CHILD | WS_VISIBLE | WS_VSCROLL |
 
- 		WS_HSCROLL | ES_MULTILINE | ES_AUTOVSCROLL | ES_NOHIDESEL |
 
-                       ES_AUTOHSCROLL, CRect(10, 10, 100, 200), this, 1);
 
-     m_RichEdit.SetReadOnly();
 
-     m_RichEdit.SetBackgroundColor(FALSE, GetSysColor(COLOR_INFOBK));
 
- 	ApplyWordWrap();
 
-     SetLogFont(GetSystemToolTipFont(), FALSE);
 
- 	m_optionsButton.Create(NULL, WS_CHILD | BS_OWNERDRAW | WS_TABSTOP, CRect(0, 0, 0, 0), this, 2);
 
- 	m_optionsButton.LoadStdImageDPI(IDB_COG_16_16, IDB_COG_20_20, IDB_COG_24_24, cog_28, IDB_COG_32_32, _T("PNG"));
 
- 	m_optionsButton.SetToolTipText(theApp.m_Language.GetString(_T("DescriptionOptionsTooltip"), _T("Description Options")));
 
- 	m_optionsButton.ShowWindow(SW_SHOW);
 
-     return TRUE;
 
- }
 
- BOOL CToolTipEx::Show(CPoint point)
 
- {
 
- 	m_reducedWindowSize = false;
 
-     if(m_imageViewer.m_pBitmap)
 
-     {
 
-         m_RichEdit.ShowWindow(SW_HIDE);
 
- 		m_imageViewer.ShowWindow(SW_SHOW);
 
- 		m_imageViewer.UpdateBitmapSize();
 
-     }
 
-     else
 
-     {
 
-         m_RichEdit.ShowWindow(SW_SHOW);
 
- 		m_imageViewer.ShowWindow(SW_HIDE);
 
-     }
 
- 	CRect rect;
 
- 	if(CGetSetOptions::GetSizeDescWindowToContent() == FALSE)
 
- 	{
 
- 		rect.left = point.x;
 
- 		rect.top = point.y;
 
- 		CSize size;
 
- 		CGetSetOptions::GetDescWndSize(size);
 
- 		rect.right = rect.left + size.cx;
 
- 		rect.bottom = rect.top + size.cy;
 
- 		EnsureWindowVisible(&rect);
 
- 	}
 
- 	else
 
- 	{
 
- 		rect = GetBoundsRect();
 
- 		//account for the scroll bars
 
- 		rect.right += 20;
 
- 		rect.bottom += 20;
 
- 		if (m_imageViewer.m_pBitmap)
 
- 		{
 
- 			int nWidth = CBitmapHelper::GetCBitmapWidth(*m_imageViewer.m_pBitmap) + ::GetSystemMetrics(SM_CXVSCROLL);
 
- 			int nHeight = CBitmapHelper::GetCBitmapHeight(*m_imageViewer.m_pBitmap) + ::GetSystemMetrics(SM_CYHSCROLL);
 
- 			rect.right = rect.left + nWidth;
 
- 			rect.bottom = rect.top + nHeight;
 
- 		}
 
- 		else if(m_csRTF != "")
 
- 		{
 
- 			//if showing rtf then increase the size because
 
- 			//rtf will probably draw bigger
 
- 			long lNewWidth = (long)rect.Width() + (long)(rect.Width() *1.5);
 
- 			rect.right = rect.left + lNewWidth;
 
- 			long lNewHeight = (long)rect.Height() + (long)(rect.Height() *1.5);
 
- 			rect.bottom = rect.top + lNewHeight;
 
- 		}
 
- 		rect.right += CAPTION_BORDER * 2;
 
- 		rect.bottom += CAPTION_BORDER * 2;
 
- 		
 
- 		CRect rcScreen;
 
- 		ClientToScreen(rect);
 
- 		CRect cr(point, point);
 
- 		int nMonitor = GetMonitorFromRect(&cr);
 
- 		GetMonitorRect(nMonitor, &rcScreen);
 
- 		//ensure that we don't go outside the screen
 
- 		if(point.x < 0)
 
- 		{
 
- 			point.x = 5;
 
- 			m_reducedWindowSize = true;
 
- 		}
 
- 		if(point.y < 0)
 
- 		{
 
- 			point.y = 5;
 
- 			m_reducedWindowSize = true;
 
- 		}
 
- 		rcScreen.DeflateRect(0, 0, 5, 5);
 
- 		long lWidth = rect.Width();
 
- 		long lHeight = rect.Height();
 
- 		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;
 
- 			m_reducedWindowSize = true;
 
- 		}
 
- 		if (rect.bottom > rcScreen.bottom)
 
- 		{
 
- 			rect.bottom = rcScreen.bottom;
 
- 			m_reducedWindowSize = true;
 
- 		}
 
- 	}
 
-     SetWindowPos(&CWnd::wndTopMost, rect.left, rect.top, rect.Width(), rect.Height
 
-                  (), SWP_SHOWWINDOW | SWP_NOCOPYBITS | SWP_NOACTIVATE |
 
-                  SWP_NOZORDER);
 
-     return TRUE;
 
- }
 
- BOOL CToolTipEx::Hide()
 
- {
 
-     DELETE_BITMAP 
 
- 	if(::IsWindowVisible(m_hWnd))
 
- 	{
 
- 		CRect rect;
 
- 		this->GetWindowRect(&rect);
 
- 		CGetSetOptions::SetDescWndSize(rect.Size());
 
- 		CGetSetOptions::SetDescWndPoint(rect.TopLeft());
 
- 	}
 
-     ShowWindow(SW_HIDE);
 
-     m_csRTF = "";
 
-     m_csText = "";
 
- 	m_clipId = 0;
 
- 	m_searchText = _T("");	
 
-     return TRUE;
 
- }
 
- void CToolTipEx::PostNcDestroy()
 
- {
 
-     CWnd::PostNcDestroy();
 
-     delete this;
 
- }
 
- BOOL CToolTipEx::PreTranslateMessage(MSG *pMsg)
 
- {
 
- 	m_DittoWindow.DoPreTranslateMessage(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;
 
- 			case VK_F3:
 
- 			{
 
- 				DoSearch();
 
- 			}
 
- 			break;
 
-             }
 
- 			break;
 
- 		case WM_RBUTTONDOWN:
 
- 			{
 
- 				if (m_RichEdit.m_hWnd == GetFocus()->m_hWnd ||
 
- 					m_imageViewer.m_hWnd == GetFocus()->m_hWnd)
 
- 				{
 
- 					OnOptions();
 
- 					return TRUE;
 
- 				}
 
- 			}
 
- 			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 (CGetSetOptions::GetMouseClickHidesDescription())
 
- 				{
 
- 					if (!IsCursorInToolTip())
 
- 					{
 
- 						Hide();
 
- 					}
 
- 				}
 
-             }
 
- 			break;
 
-         case WM_KEYDOWN:
 
-             {
 
-                 WPARAM vk = pMsg->wParam;
 
-                 if(vk == VK_ESCAPE)
 
-                 {
 
-                     Hide();
 
-                     return TRUE;
 
-                 }
 
-                 else if(vk == VK_TAB)
 
-                 {
 
-                     m_RichEdit.SetFocus();
 
-                     return TRUE;
 
-                 }
 
- 				else if(vk == 'N')
 
- 				{
 
- 					return FALSE;
 
- 				}
 
- 				else if (vk == 'P')
 
- 				{
 
- 					return FALSE;
 
- 				}
 
- 				else if (vk == VK_UP)
 
- 				{
 
- 					return FALSE;
 
- 				}
 
- 				else if (vk == VK_DOWN)
 
- 				{
 
- 					return FALSE;
 
- 				}
 
- 				else if(vk == VK_F3)
 
- 				{
 
- 					DoSearch();
 
- 					return TRUE;
 
- 				}
 
- 				else if(vk == VK_SHIFT)
 
- 				{
 
- 					return FALSE;
 
- 				}
 
- 				else if(vk == VK_NEXT)
 
- 				{
 
- 					return FALSE;
 
- 				}
 
- 				else if (vk == VK_PRIOR)
 
- 				{
 
- 					return FALSE;
 
- 				}
 
-                 Hide();
 
-                 break;
 
-             }
 
-         case WM_LBUTTONDBLCLK:
 
-         case WM_RBUTTONDBLCLK:
 
-         case WM_MBUTTONDOWN:
 
-         case WM_MBUTTONDBLCLK:
 
-         case WM_NCLBUTTONDOWN:
 
-         case WM_NCLBUTTONDBLCLK:
 
-         case WM_NCRBUTTONDOWN:
 
-         case WM_NCRBUTTONDBLCLK:
 
-         case WM_NCMBUTTONDOWN:
 
-         case WM_NCMBUTTONDBLCLK:
 
-             {
 
-                 Hide();
 
-                 break;
 
-             }
 
-     }
 
-     return FALSE;
 
- }
 
- CRect CToolTipEx::GetBoundsRect()
 
- {
 
-     CWindowDC dc(NULL);
 
-     CFont *pOldFont = (CFont*)dc.SelectObject((CFont*) &m_Font);
 
-     int nLineWidth = 0;
 
-     if(nLineWidth == 0)
 
-     {
 
-         // Count the number of lines of text
 
-         int nStart = 0, nNumLines = 0;
 
-         CString strTextCopy = m_csText;
 
-         do
 
-         {
 
-             nStart = strTextCopy.Find(_T("\n"));
 
-             // skip found character 
 
-             if(nStart >= 0)
 
-             {
 
-                 strTextCopy = strTextCopy.Mid(nStart + 1);
 
-             }
 
-             nNumLines++;
 
-         }
 
-         while(nStart >= 0);
 
-         // Find the widest line
 
-         for(int i = 0; i < nNumLines; i++)
 
-         {
 
-             CString strLine = GetFieldFromString(m_csText, i, _T('\n')) + _T(
 
-                 "  ");
 
-             nLineWidth = max(nLineWidth, dc.GetTextExtent(strLine).cx);
 
-         }
 
-     }
 
-     CRect rect(0, 0, max(0, nLineWidth), 0);
 
-     dc.DrawText(m_csText, rect, DT_CALCRECT | m_dwTextStyle);
 
-     dc.SelectObject(pOldFont);
 
-     rect.bottom += m_rectMargin.top + m_rectMargin.bottom;
 
-     rect.right += m_rectMargin.left + m_rectMargin.right + 2;
 
-     if(m_imageViewer.m_pBitmap)
 
-     {
 
-         int nWidth = CBitmapHelper::GetCBitmapWidth(*m_imageViewer.m_pBitmap);
 
-         int nHeight = CBitmapHelper::GetCBitmapHeight(*m_imageViewer.m_pBitmap);
 
-         rect.bottom += nHeight;
 
-         if((rect.left + nWidth) > rect.right)
 
-         {
 
-             rect.right = rect.left + nWidth;
 
-         }
 
-     }
 
-     return rect;
 
- }
 
- CString CToolTipEx::GetFieldFromString(CString ref, int nIndex, TCHAR ch)
 
- {
 
-     CString strReturn;
 
-     LPCTSTR pstrStart = ref.LockBuffer();
 
-     LPCTSTR pstrBuffer = pstrStart;
 
-     int nCurrent = 0;
 
-     int nStart = 0;
 
-     int nEnd = 0;
 
-     int nOldStart = 0;
 
-     while(nCurrent <= nIndex &&  *pstrBuffer != _T('\0'))
 
-     {
 
-         if(*pstrBuffer == ch)
 
-         {
 
-             nOldStart = nStart;
 
-             nStart = nEnd + 1;
 
-             nCurrent++;
 
-         }
 
-         nEnd++;
 
-         pstrBuffer++;
 
-     }
 
-     // May have reached the end of the string
 
-     if(*pstrBuffer == _T('\0'))
 
-     {
 
-         nOldStart = nStart;
 
-         nEnd++;
 
-     }
 
-     ref.UnlockBuffer();
 
-     if(nCurrent < nIndex)
 
-     {
 
-         //TRACE1("Warning: GetStringField - Couldn't find field %d.\n", nIndex);
 
-         return strReturn;
 
-     }
 
-     return ref.Mid(nOldStart, nEnd - nOldStart - 1);
 
- }
 
- LPLOGFONT CToolTipEx::GetSystemToolTipFont()
 
- {
 
-     static LOGFONT LogFont;
 
-     NONCLIENTMETRICS ncm;
 
-     ncm.cbSize = sizeof(NONCLIENTMETRICS);
 
-     if(!SystemParametersInfo(SPI_GETNONCLIENTMETRICS, sizeof(NONCLIENTMETRICS),
 
-        &ncm, 0))
 
-     {
 
-         return FALSE;
 
-     }
 
-     memcpy(&LogFont, &(ncm.lfStatusFont), sizeof(LOGFONT));
 
-     return  &LogFont;
 
- }
 
- BOOL CToolTipEx::SetLogFont(LPLOGFONT lpLogFont, BOOL bRedraw /*=TRUE*/)
 
- {
 
-     ASSERT(lpLogFont);
 
-     if(!lpLogFont)
 
-     {
 
-         return FALSE;
 
-     }
 
-     LOGFONT LogFont;
 
-     // Store font as the global default
 
-     memcpy(&LogFont, lpLogFont, sizeof(LOGFONT));
 
-     // Create the actual font object
 
-     m_Font.DeleteObject();
 
-     m_Font.CreateFontIndirect(&LogFont);
 
-     if(bRedraw && ::IsWindow(GetSafeHwnd()))
 
-     {
 
-         Invalidate();
 
-     }
 
-     return TRUE;
 
- }
 
- void CToolTipEx::SetBitmap(CBitmap *pBitmap)
 
- {
 
-     DELETE_BITMAP 
 
- 	m_imageViewer.m_pBitmap = pBitmap;
 
- 	m_imageViewer.UpdateBitmapSize();
 
- 	if (m_imageViewer.m_pBitmap != NULL)
 
- 	{
 
- 		int nWidth = CBitmapHelper::GetCBitmapWidth(*m_imageViewer.m_pBitmap);
 
- 		int nHeight = CBitmapHelper::GetCBitmapHeight(*m_imageViewer.m_pBitmap);
 
- 		Invalidate();
 
- 	}
 
- }
 
- 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, 0, theApp.m_metrics.ScaleY(21));
 
-     m_RichEdit.MoveWindow(cr);
 
- 	m_imageViewer.MoveWindow(cr);
 
- 	m_optionsButton.MoveWindow(cr.left, cr.bottom + theApp.m_metrics.ScaleY(2), theApp.m_metrics.ScaleX(17), theApp.m_metrics.ScaleY(17));
 
- 	this->Invalidate();
 
- 	m_DittoWindow.DoSetRegion(this);
 
- }
 
- BOOL CToolTipEx::IsCursorInToolTip()
 
- {
 
-     CRect cr;
 
-     GetWindowRect(cr);
 
-     CPoint cursorPos;
 
-     GetCursorPos(&cursorPos);
 
-     return cr.PtInRect(cursorPos);
 
- }
 
- void CToolTipEx::SetRTFText(const char *pRTF)
 
- {
 
-     m_RichEdit.SetRTF(pRTF);
 
-     m_csRTF = pRTF;
 
- 	m_RichEdit.SetSel(0, 0);
 
- 	HighlightSearchText();
 
- }
 
- //void CToolTipEx::SetRTFText(const CString &csRTF)
 
- //{
 
- //	m_RichEdit.SetRTF(csRTF);
 
- //	m_csRTF = csRTF;
 
- //}
 
- void CToolTipEx::SetToolTipText(const CString &csText)
 
- {
 
-     m_csText = csText;
 
-     m_RichEdit.SetFont(&m_Font);
 
-     m_RichEdit.SetText(csText);
 
- 	m_RichEdit.SetSel(0, 0);
 
- 	HighlightSearchText();
 
- }
 
- void CToolTipEx::HighlightSearchText()
 
- {
 
- 	if (m_searchText.GetLength() <= 0)
 
- 		return;
 
- 	FINDTEXTEX ft;
 
- 	long n = -1;
 
- 	ft.lpstrText = m_searchText;
 
- 	
 
- 	ft.chrg.cpMin = 0;
 
- 	ft.chrg.cpMax = -1;
 
- 	CHARFORMAT cf;
 
- 	cf.cbSize = sizeof(cf);
 
- 	cf.dwMask = CFM_COLOR;
 
- 	cf.dwEffects = CFE_BOLD | ~CFE_AUTOCOLOR;
 
- 	cf.crTextColor = RGB(255, 0, 0);
 
- 	do 
 
- 	{
 
- 		ft.chrg.cpMin = n+1;
 
- 		n = m_RichEdit.FindText(FR_DOWN, &ft);
 
- 		if (n != -1)
 
- 		{
 
- 			m_RichEdit.SetSel(ft.chrgText);
 
- 			m_RichEdit.SetSelectionCharFormat(cf);
 
- 		}
 
- 	} while (n != -1);	
 
- 	m_RichEdit.SetSel(0, 0);
 
- }
 
- void CToolTipEx::DoSearch()
 
- {
 
- 	if (m_searchText.GetLength() <= 0)
 
- 		return;
 
- 	FINDTEXTEX ft;
 
- 	long n = -1;
 
- 	ft.lpstrText = m_searchText;
 
- 	long start;
 
- 	long end;
 
- 	m_RichEdit.GetSel(start, end);
 
- 	ft.chrg.cpMin = end;
 
- 	ft.chrg.cpMax = -1;
 
- 	int searchDirection = FR_DOWN;
 
- 	if (GetKeyState(VK_SHIFT) & 0x8000)
 
- 	{
 
- 		searchDirection = 0;
 
- 		ft.chrg.cpMin = start;
 
- 	}
 
- 	n = m_RichEdit.FindText(searchDirection, &ft);
 
- 	if (n != -1)
 
- 	{
 
- 		m_RichEdit.SetSel(ft.chrgText);
 
- 	}
 
- 	else
 
- 	{
 
- 		if (searchDirection == 0)
 
- 		{
 
- 			ft.chrg.cpMin = m_RichEdit.GetTextLength();
 
- 		}
 
- 		else
 
- 		{
 
- 			ft.chrg.cpMin = 0;
 
- 		}
 
- 		ft.chrg.cpMax = -1;
 
- 		n = m_RichEdit.FindText(searchDirection, &ft);
 
- 		if (n != -1)
 
- 		{
 
- 			m_RichEdit.SetSel(ft.chrgText);
 
- 		}
 
- 	}
 
- }
 
- void CToolTipEx::OnActivate(UINT nState, CWnd *pWndOther, BOOL bMinimized)
 
- {
 
-     CWnd::OnActivate(nState, pWndOther, bMinimized);
 
- 	if (nState == WA_INACTIVE)
 
- 	{		
 
-         if(m_pNotifyWnd)
 
-         {
 
-             m_pNotifyWnd->PostMessage(NM_INACTIVE_TOOLTIPWND, 0, 0);
 
-         }
 
-     }
 
- }
 
- void CToolTipEx::OnTimer(UINT_PTR nIDEvent)
 
- {
 
-     switch(nIDEvent)
 
-     {
 
-         case HIDE_WINDOW_TIMER:
 
-             Hide();
 
-             PostMessage(WM_DESTROY, 0, 0);
 
-             break;
 
-     }
 
-     CWnd::OnTimer(nIDEvent);
 
- }
 
- void CToolTipEx::OnNcPaint()
 
- {
 
- 	m_DittoWindow.DoNcPaint(this);
 
- }
 
- void CToolTipEx::OnNcCalcSize(BOOL bCalcValidRects, NCCALCSIZE_PARAMS FAR* lpncsp) 
 
- {
 
- 	CWnd::OnNcCalcSize(bCalcValidRects, lpncsp);
 
- 	m_DittoWindow.DoNcCalcSize(bCalcValidRects, lpncsp);
 
- }
 
- HITTEST_RET CToolTipEx::OnNcHitTest(CPoint point) 
 
- {
 
- 	UINT Ret = m_DittoWindow.DoNcHitTest(this, point);
 
- 	if(Ret == -1)
 
- 		return CWnd::OnNcHitTest(point);
 
- 	return Ret;
 
- }
 
- void CToolTipEx::OnNcLButtonDown(UINT nHitTest, CPoint point) 
 
- {
 
- 	m_DittoWindow.DoNcLButtonDown(this, nHitTest, point);
 
- 	CWnd::OnNcLButtonDown(nHitTest, point);
 
- }
 
- void CToolTipEx::OnNcLButtonUp(UINT nHitTest, CPoint point) 
 
- {
 
- 	long lRet = m_DittoWindow.DoNcLButtonUp(this, nHitTest, point);
 
- 	switch(lRet)
 
- 	{
 
- 	case BUTTON_CLOSE:
 
- 		Hide();
 
- 		break;
 
- 	}
 
- 	CWnd::OnNcLButtonUp(nHitTest, point);
 
- }
 
- void CToolTipEx::OnNcMouseMove(UINT nHitTest, CPoint point) 
 
- {
 
- 	m_DittoWindow.DoNcMouseMove(this, nHitTest, point);
 
- 	CWnd::OnNcMouseMove(nHitTest, point);
 
- }
 
- void CToolTipEx::OnOptions()
 
- {
 
- 	POINT pp;
 
- 	CMenu cmPopUp;
 
- 	CMenu *cmSubMenu = NULL;
 
- 	GetCursorPos(&pp);
 
- 	if(cmPopUp.LoadMenu(IDR_DESC_OPTIONS_MENU) != 0)
 
- 	{
 
- 		cmSubMenu = cmPopUp.GetSubMenu(0);
 
- 		if(!cmSubMenu)
 
- 		{
 
- 			return ;
 
- 		}
 
- 		GetCursorPos(&pp);
 
- 		if(CGetSetOptions::GetRememberDescPos())
 
- 			cmSubMenu->CheckMenuItem(ID_FIRST_REMEMBERWINDOWPOSITION, MF_CHECKED);
 
- 		if(CGetSetOptions::GetSizeDescWindowToContent())
 
- 			cmSubMenu->CheckMenuItem(ID_FIRST_SIZEWINDOWTOCONTENT, MF_CHECKED);
 
- 		if(CGetSetOptions::GetScaleImagesToDescWindow())
 
- 			cmSubMenu->CheckMenuItem(ID_FIRST_SCALEIMAGESTOFITWINDOW, MF_CHECKED);
 
- 		if (CGetSetOptions::GetMouseClickHidesDescription())
 
- 			cmSubMenu->CheckMenuItem(ID_FIRST_HIDEDESCRIPTIONWINDOWONM, MF_CHECKED);
 
- 		if (CGetSetOptions::GetWrapDescriptionText())
 
- 			cmSubMenu->CheckMenuItem(ID_FIRST_WRAPTEXT, MF_CHECKED);
 
- 		
 
- 		//theApp.m_Language.UpdateRightClickMenu(cmSubMenu);
 
- 		
 
- 		cmSubMenu->TrackPopupMenu(TPM_LEFTALIGN | TPM_TOPALIGN | TPM_RIGHTBUTTON, pp.x, pp.y, this, NULL);
 
- 	}
 
- }
 
- void CToolTipEx::OnRememberwindowposition()
 
- {
 
- 	CGetSetOptions::SetRememberDescPos(!CGetSetOptions::GetRememberDescPos());
 
- }
 
- void CToolTipEx::OnSizewindowtocontent()
 
- {
 
- 	CGetSetOptions::SetSizeDescWindowToContent(!CGetSetOptions::GetSizeDescWindowToContent());
 
- 	CRect rect;
 
- 	this->GetWindowRect(&rect);
 
- 	Show(rect.TopLeft());
 
- }
 
- void CToolTipEx::OnScaleimagestofitwindow()
 
- {
 
- 	CGetSetOptions::SetScaleImagesToDescWindow(!CGetSetOptions::GetScaleImagesToDescWindow());
 
- 	m_imageViewer.UpdateBitmapSize();
 
- 	Invalidate();
 
- }
 
- void CToolTipEx::OnRButtonDown(UINT nFlags, CPoint point)
 
- {
 
- 	OnOptions();
 
- 	CWnd::OnRButtonDown(nFlags, point);
 
- }
 
- void CToolTipEx::OnSetFocus(CWnd* pOldWnd)
 
- {
 
- 	CWnd::OnSetFocus(pOldWnd);
 
- 	m_RichEdit.SetFocus();
 
- }
 
- void CToolTipEx::OnPaint()
 
- {
 
- 	CPaintDC dc(this); // device context for painting
 
- 	CRect rect;
 
- 	GetClientRect(rect);
 
- 	
 
- 	CBrush  Brush, *pOldBrush;
 
- 	Brush.CreateSolidBrush(GetSysColor(COLOR_INFOBK));
 
- 	pOldBrush = dc.SelectObject(&Brush);
 
- 	dc.FillRect(&rect, &Brush);
 
- 	// Cleanup
 
- 	dc.SelectObject(pOldBrush);
 
- }
 
- void CToolTipEx::OnFirstHidedescriptionwindowonm()
 
- {
 
- 	CGetSetOptions::SetMouseClickHidesDescription(!CGetSetOptions::GetMouseClickHidesDescription());
 
- }
 
- void CToolTipEx::OnFirstWraptext()
 
- {
 
- 	CGetSetOptions::SetWrapDescriptionText(!CGetSetOptions::GetWrapDescriptionText());	
 
- 	ApplyWordWrap();
 
- }
 
- void CToolTipEx::ApplyWordWrap()
 
- {
 
- 	if (CGetSetOptions::GetWrapDescriptionText())
 
- 	{
 
- 		m_RichEdit.SetTargetDevice(NULL, 0);
 
- 	}
 
- 	else
 
- 	{
 
- 		m_RichEdit.SetTargetDevice(NULL, 1);
 
- 	}
 
- }
 
 
  |