SymbolEdit.cpp 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975
  1. // AeroEdit.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "SymbolEdit.h"
  5. #include "cp_main.h"
  6. #include "QListCtrl.h"
  7. #include "Shared\TextConvert.h"
  8. // CSymbolEdit
  9. #define RANGE_START 3000
  10. #define CLEAR_LIST 3050
  11. #define LIST_MAX_COUNT 50
  12. #define MAX_SAVED_SEARCH_LENGTH 1000
  13. IMPLEMENT_DYNAMIC(CSymbolEdit, CEdit)
  14. CSymbolEdit::CSymbolEdit() :
  15. m_hSymbolIcon(NULL),
  16. m_bInternalIcon(false),
  17. m_colorPromptText(RGB(127, 127, 127)),
  18. m_centerTextDiff(0)
  19. {
  20. m_fontPrompt.CreateFont(
  21. 16, // nHeight
  22. 0, // nWidth
  23. 0, // nEscapement
  24. 0, // nOrientation
  25. FW_NORMAL, // nWeight
  26. TRUE, // bItalic
  27. FALSE, // bUnderline
  28. 0, // cStrikeOut
  29. DEFAULT_CHARSET, // nCharSet
  30. OUT_DEFAULT_PRECIS, // nOutPrecision
  31. CLIP_DEFAULT_PRECIS, // nClipPrecision
  32. DEFAULT_QUALITY, // nQuality
  33. DEFAULT_PITCH | FF_SWISS, // nPitchAndFamily
  34. _T("Calibri"));
  35. m_mouseDownOnSearches = false;
  36. m_mouseHoveringOverSearches = false;
  37. m_mouseDownOnClose = false;
  38. m_mouseHoveringOverClose = false;
  39. m_windowDpi = NULL;
  40. //m_searchButton.LoadStdImageDPI(Search_16, Search_20, Search_24, Search_32, _T("PNG"));
  41. }
  42. CSymbolEdit::~CSymbolEdit()
  43. {
  44. DestroyIcon();
  45. }
  46. BEGIN_MESSAGE_MAP(CSymbolEdit, CEdit)
  47. ON_WM_PAINT()
  48. ON_MESSAGE(WM_SETFONT, OnSetFont)
  49. //ON_MESSAGE(WM_EXITMENULOOP, OnMenuExit)
  50. ON_WM_CTLCOLOR_REFLECT()
  51. ON_WM_SETFOCUS()
  52. ON_WM_KILLFOCUS()
  53. ON_WM_SETCURSOR()
  54. ON_WM_LBUTTONUP()
  55. ON_WM_LBUTTONDOWN()
  56. ON_WM_MOUSEMOVE()
  57. ON_COMMAND_RANGE(RANGE_START, (RANGE_START+ LIST_MAX_COUNT), OnSelectSearchString)
  58. ON_WM_EXITSIZEMOVE()
  59. //ON_WM_ERASEBKGND()
  60. ON_WM_NCCALCSIZE()
  61. ON_WM_NCPAINT()
  62. ON_WM_TIMER()
  63. END_MESSAGE_MAP()
  64. BOOL CSymbolEdit::PreTranslateMessage(MSG* pMsg)
  65. {
  66. // TODO: Add your specialized code here and/or call the base class
  67. // Intercept Ctrl + Z (Undo), Ctrl + X (Cut), Ctrl + C (Copy), Ctrl + V (Paste) and Ctrl + A (Select All)
  68. // before CEdit base class gets a hold of them.
  69. if (pMsg->message == WM_KEYDOWN &&
  70. CONTROL_PRESSED)
  71. {
  72. switch (pMsg->wParam)
  73. {
  74. case 'Z':
  75. Undo();
  76. return TRUE;
  77. case 'X':
  78. Cut();
  79. return TRUE;
  80. case 'C':
  81. {
  82. int startChar;
  83. int endChar;
  84. this->GetSel(startChar, endChar);
  85. if (startChar == endChar)
  86. {
  87. CWnd *pWnd = GetParent();
  88. if (pWnd)
  89. {
  90. pWnd->SendMessage(NM_COPY_CLIP, pMsg->wParam, pMsg->lParam);
  91. }
  92. }
  93. else
  94. {
  95. Copy();
  96. }
  97. }
  98. return TRUE;
  99. case 'V':
  100. Paste();
  101. return TRUE;
  102. case 'A':
  103. SetSel(0, -1);
  104. return TRUE;
  105. }
  106. }
  107. switch (pMsg->message)
  108. {
  109. case WM_KEYDOWN:
  110. {
  111. if (pMsg->wParam == VK_RETURN)
  112. {
  113. CWnd *pWnd = GetParent();
  114. if (pWnd)
  115. {
  116. if (g_Opt.m_bFindAsYouType)
  117. {
  118. pWnd->SendMessage(NM_SEARCH_ENTER_PRESSED, 0, 0);
  119. }
  120. else
  121. {
  122. //Send a message to the parent to refill the lb from the search
  123. pWnd->PostMessage(CB_SEARCH, 0, 0);
  124. }
  125. AddToSearchHistory();
  126. }
  127. return TRUE;
  128. }
  129. else if (pMsg->wParam == VK_DOWN &&
  130. ((GetKeyState(VK_CONTROL) & 0x8000) || ((GetKeyState(VK_CONTROL) & 0x8000) && (GetKeyState(VK_SHIFT) & 0x8000))))
  131. {
  132. if (ShowSearchHistoryMenu())
  133. {
  134. return TRUE;
  135. }
  136. }
  137. else if (pMsg->wParam == VK_DOWN ||
  138. pMsg->wParam == VK_UP ||
  139. pMsg->wParam == VK_PRIOR ||
  140. pMsg->wParam == VK_NEXT)
  141. {
  142. CWnd *pWnd = GetParent();
  143. if (pWnd)
  144. {
  145. pWnd->SendMessage(CB_UPDOWN, pMsg->wParam, pMsg->lParam);
  146. return TRUE;
  147. }
  148. }
  149. else if (pMsg->wParam == VK_DELETE)
  150. {
  151. int startChar;
  152. int endChar;
  153. this->GetSel(startChar, endChar);
  154. CString cs;
  155. this->GetWindowText(cs);
  156. //if selection is at the end then forward this on to the parent to delete the selected clip
  157. if(startChar == cs.GetLength() &&
  158. endChar == cs.GetLength())
  159. {
  160. CWnd *pWnd = GetParent();
  161. if (pWnd)
  162. {
  163. pWnd->SendMessage(NM_DELETE, pMsg->wParam, pMsg->lParam);
  164. return TRUE;
  165. }
  166. }
  167. }
  168. break;
  169. }
  170. }
  171. return CEdit::PreTranslateMessage(pMsg);
  172. }
  173. CString CSymbolEdit::SavePastSearches()
  174. {
  175. TiXmlDocument doc;
  176. TiXmlElement* outer = new TiXmlElement("PastSearches");
  177. doc.LinkEndChild(outer);
  178. int count = (int)m_searches.GetCount();
  179. for (int i = 0; i < count; i++)
  180. {
  181. TiXmlElement* searchElement = new TiXmlElement("Search");
  182. CStringA t;
  183. CTextConvert::ConvertToUTF8(m_searches[i], t);
  184. searchElement->SetAttribute("text", t);
  185. outer->LinkEndChild(searchElement);
  186. }
  187. TiXmlPrinter printer;
  188. printer.SetLineBreak("");
  189. doc.Accept(&printer);
  190. CString cs = printer.CStr();
  191. return cs;
  192. }
  193. void CSymbolEdit::LoadPastSearches(CString values)
  194. {
  195. m_searches.RemoveAll();
  196. TiXmlDocument doc;
  197. CStringA xmlA;
  198. CTextConvert::ConvertToUTF8(values, xmlA);
  199. doc.Parse(xmlA);
  200. TiXmlElement *ItemHeader = doc.FirstChildElement("PastSearches");
  201. if (ItemHeader != NULL)
  202. {
  203. TiXmlElement *ItemElement = ItemHeader->FirstChildElement();
  204. while (ItemElement)
  205. {
  206. CString item = ItemElement->Attribute("text");
  207. m_searches.Add(item.Left(MAX_SAVED_SEARCH_LENGTH));
  208. ItemElement = ItemElement->NextSiblingElement();
  209. }
  210. }
  211. }
  212. void CSymbolEdit::AddToSearchHistory()
  213. {
  214. CString cs;
  215. this->GetWindowText(cs);
  216. if (cs != _T(""))
  217. {
  218. //only save up to 1000, had reports of somehow getting extremely large amounts of junk text
  219. //save and causing memory issues.
  220. cs = cs.Left(MAX_SAVED_SEARCH_LENGTH);
  221. if (m_searches.GetCount() >= LIST_MAX_COUNT)
  222. {
  223. m_searches.RemoveAt(0);
  224. }
  225. bool existing = false;
  226. int count = (int)m_searches.GetCount();
  227. for (int i = 0; i < count; i++)
  228. {
  229. if (m_searches[i] == cs)
  230. {
  231. m_searches.RemoveAt(i);
  232. m_searches.Add(cs);
  233. existing = true;
  234. break;
  235. }
  236. }
  237. if (existing == false)
  238. {
  239. m_searches.Add(cs);
  240. }
  241. }
  242. }
  243. bool CSymbolEdit::ShowSearchHistoryMenu()
  244. {
  245. if (m_searches.GetCount() == 0)
  246. {
  247. return false;
  248. }
  249. CMenu cmPopUp;
  250. cmPopUp.CreatePopupMenu();
  251. int count = min((int)m_searches.GetCount(), LIST_MAX_COUNT);
  252. for (int i = count-1; i >= 0; i--)
  253. {
  254. CString text = m_searches[i];
  255. if (i == count - 1 &&
  256. m_lastSearchShortCut.Key > 0)
  257. {
  258. CString cmdShortcutText = CHotKey::GetHotKeyDisplayStatic(m_lastSearchShortCut.Key);
  259. if (m_lastSearchShortCut.Key2 != 0)
  260. {
  261. CString cmdShortcutText2 = CHotKey::GetHotKeyDisplayStatic(m_lastSearchShortCut.Key2);
  262. if (cmdShortcutText2.GetLength() > 0)
  263. {
  264. cmdShortcutText += _T(" - ");
  265. cmdShortcutText += cmdShortcutText2;
  266. }
  267. }
  268. text += "\t";
  269. text += cmdShortcutText;
  270. }
  271. cmPopUp.AppendMenuW(MF_STRING, (RANGE_START + i), text);
  272. }
  273. cmPopUp.AppendMenu(MF_SEPARATOR);
  274. cmPopUp.AppendMenuW(MF_STRING, CLEAR_LIST, _T("Clear List"));
  275. CRect windowRect;
  276. this->GetWindowRect(&windowRect);
  277. POINT pp;
  278. GetCursorPos(&pp);
  279. POINT x = this->GetCaretPos();
  280. ClientToScreen(&x);
  281. x.y += windowRect.Height();
  282. cmPopUp.TrackPopupMenu(TPM_LEFTALIGN | TPM_TOPALIGN | TPM_RIGHTBUTTON, x.x, x.y, this, NULL);
  283. Invalidate();
  284. return true;
  285. }
  286. void CSymbolEdit::DestroyIcon()
  287. {
  288. // if icon was loaded internally, destroy it
  289. if (m_bInternalIcon || m_hSymbolIcon != NULL)
  290. ::DestroyIcon(m_hSymbolIcon);
  291. }
  292. void CSymbolEdit::PreSubclassWindow()
  293. {
  294. RecalcLayout();
  295. }
  296. void CSymbolEdit::SetSymbolIcon(HICON hIcon, BOOL redraw)
  297. {
  298. DestroyIcon();
  299. m_hSymbolIcon = hIcon;
  300. // icon was not loaded internally
  301. m_bInternalIcon = false;
  302. RecalcLayout();
  303. if (redraw)
  304. Invalidate(TRUE);
  305. }
  306. void CSymbolEdit::SetSymbolIcon(UINT id, BOOL redraw)
  307. {
  308. DestroyIcon();
  309. m_hSymbolIcon = (HICON)::LoadImage(
  310. AfxGetResourceHandle(),
  311. MAKEINTRESOURCE(id),
  312. IMAGE_ICON,
  313. 16,
  314. 16,
  315. LR_DEFAULTCOLOR | LR_LOADTRANSPARENT);
  316. ASSERT(m_hSymbolIcon != NULL);
  317. // icon was loaded internally
  318. m_bInternalIcon = true;
  319. RecalcLayout();
  320. if (redraw)
  321. Invalidate(TRUE);
  322. }
  323. void CSymbolEdit::SetPromptText(CString text, BOOL redraw)
  324. {
  325. m_strPromptText = text;
  326. if (redraw)
  327. Invalidate(TRUE);
  328. }
  329. void CSymbolEdit::SetPromptText(LPCTSTR szText, BOOL redraw)
  330. {
  331. m_strPromptText = szText;
  332. if (redraw)
  333. Invalidate(TRUE);
  334. }
  335. void CSymbolEdit::SetPromptTextColor(COLORREF color, BOOL redraw)
  336. {
  337. m_colorPromptText = color;
  338. if (redraw)
  339. Invalidate(TRUE);
  340. }
  341. void CSymbolEdit::SetPromptFont(CFont& font, BOOL redraw)
  342. {
  343. LOGFONT lf;
  344. memset(&lf, 0, sizeof(LOGFONT));
  345. font.GetLogFont(&lf);
  346. SetPromptFont(&lf);
  347. if (redraw)
  348. Invalidate(TRUE);
  349. }
  350. void CSymbolEdit::SetPromptFont(const LOGFONT* lpLogFont, BOOL redraw)
  351. {
  352. m_fontPrompt.DeleteObject();
  353. m_fontPrompt.CreateFontIndirect(lpLogFont);
  354. if (redraw)
  355. Invalidate(TRUE);
  356. }
  357. void CSymbolEdit::RecalcLayout()
  358. {
  359. int width = GetSystemMetrics(SM_CXSMICON);
  360. if (m_hSymbolIcon)
  361. {
  362. DWORD dwMargins = GetMargins();
  363. SetMargins(LOWORD(dwMargins), width + 6);
  364. }
  365. else
  366. {
  367. if (m_windowDpi != NULL)
  368. {
  369. SetMargins(m_windowDpi->Scale(4), m_windowDpi->Scale(34));
  370. }
  371. }
  372. }
  373. void CSymbolEdit::OnPaint()
  374. {
  375. CPaintDC dc(this);
  376. CRect rect;
  377. GetClientRect(&rect);
  378. DWORD margins = GetMargins();
  379. CRect textRect(rect);
  380. textRect.left += LOWORD(margins);
  381. textRect.right -= HIWORD(margins);
  382. // Clearing the background
  383. dc.FillSolidRect(rect, GetSysColor(COLOR_WINDOW));
  384. if (m_hSymbolIcon)
  385. {
  386. // Drawing the icon
  387. int width = GetSystemMetrics(SM_CXSMICON);
  388. int height = GetSystemMetrics(SM_CYSMICON);
  389. ::DrawIconEx(
  390. dc.m_hDC,
  391. rect.right - width - 1,
  392. 1,
  393. m_hSymbolIcon,
  394. width,
  395. height,
  396. 0,
  397. NULL,
  398. DI_NORMAL);
  399. rect.left += LOWORD(margins) + 1;
  400. rect.right -= (width + 7);
  401. }
  402. else
  403. {
  404. //rect.left += (LOWORD(dwMargins) + 1);
  405. //rect.right -= (HIWORD(dwMargins) + 1);
  406. }
  407. CString text;
  408. GetWindowText(text);
  409. CFont* oldFont = NULL;
  410. //rect.top += 1;
  411. if(this == GetFocus() || text.GetLength() > 0)
  412. {
  413. dc.FillSolidRect(rect, g_Opt.m_Theme.SearchTextBoxFocusBG());
  414. //CBrush borderBrush(g_Opt.m_Theme.SearchTextBoxFocusBorder());
  415. //dc.FrameRect(rect, &borderBrush);
  416. //rect.DeflateRect(1, 1, 1, 1);
  417. //textRect.DeflateRect(0, 1, 1, 1);
  418. oldFont = dc.SelectObject(GetFont());
  419. COLORREF oldColor = dc.GetTextColor();
  420. dc.SetTextColor(g_Opt.m_Theme.SearchTextBoxFocusText());
  421. dc.DrawText(text, textRect, DT_SINGLELINE | DT_INTERNAL | DT_EDITCONTROL | DT_NOPREFIX);
  422. dc.SelectObject(oldFont);
  423. dc.SetTextColor(oldColor);
  424. }
  425. else
  426. {
  427. dc.FillSolidRect(rect, g_Opt.m_Theme.MainWindowBG());
  428. }
  429. if (text.GetLength() == 0 && m_strPromptText.GetLength() > 0)
  430. {
  431. //if we aren't showing the close icon, then use the full space
  432. textRect.right += m_windowDpi->Scale(16);
  433. //textRect.right -= LOWORD(margins);
  434. oldFont = dc.SelectObject(&m_fontPrompt);
  435. COLORREF color = dc.GetTextColor();
  436. dc.SetTextColor(m_colorPromptText);
  437. dc.DrawText(m_strPromptText, textRect, DT_LEFT | DT_SINGLELINE | DT_EDITCONTROL | DT_VCENTER | DT_NOPREFIX);
  438. dc.SetTextColor(color);
  439. dc.SelectObject(oldFont);
  440. }
  441. int right = rect.right;
  442. if ((text.GetLength() > 0 || this == GetFocus()))
  443. {
  444. m_searchesButtonRect.SetRect(rect.right - m_windowDpi->Scale(18), 0, rect.right, rect.bottom);
  445. right = rect.right - m_windowDpi->Scale(18);
  446. m_searchesButton.Draw(&dc, *m_windowDpi, this, m_searchesButtonRect.left, 4, m_mouseHoveringOverSearches, m_mouseDownOnSearches);
  447. }
  448. else
  449. {
  450. m_searchesButtonRect.SetRect(0, 0, 0, 0);
  451. //m_searchButton.Draw(&dc, this, rect.right - 22, 4, false, false);
  452. }
  453. if (text.GetLength() > 0)
  454. {
  455. OutputDebugString(_T("showing close button\n"));
  456. m_closeButtonRect.SetRect(right - m_windowDpi->Scale(16), 0, right, rect.bottom);
  457. m_closeButton.Draw(&dc, *m_windowDpi, this, m_closeButtonRect.left, 4, m_mouseHoveringOverClose, m_mouseDownOnClose);
  458. }
  459. else
  460. {
  461. OutputDebugString(_T("not showing close button\n"));
  462. m_closeButtonRect.SetRect(0, 0, 0, 0);
  463. //m_searchButton.Draw(&dc, this, rect.right - 22, 4, false, false);
  464. }
  465. //OutputDebugString(_T("OnPaint"));
  466. if (text != m_lastTextOnPaint &&
  467. text == _T(""))
  468. {
  469. ::SetWindowPos(m_hWnd, NULL, 0, 0, 0, 0, SWP_DRAWFRAME | SWP_NOSIZE | SWP_NOMOVE | SWP_NOACTIVATE);
  470. }
  471. m_lastTextOnPaint = text;
  472. OutputDebugString(_T("OnPaint \r\n"));
  473. }
  474. void CSymbolEdit::OnSize(UINT nType, int cx, int cy)
  475. {
  476. CEdit::OnSize(nType, cx, cy);
  477. RecalcLayout();
  478. }
  479. LRESULT CSymbolEdit::OnSetFont(WPARAM wParam, LPARAM lParam)
  480. {
  481. DefWindowProc(WM_SETFONT, wParam, lParam);
  482. RecalcLayout();
  483. return 0;
  484. }
  485. HBRUSH CSymbolEdit::CtlColor(CDC* pDC, UINT n)
  486. {
  487. OutputDebugString(_T("CtlColor \r\n"));
  488. if (::GetFocus() == m_hWnd)
  489. {
  490. pDC->SetTextColor(g_Opt.m_Theme.SearchTextBoxFocusText());
  491. pDC->SetBkColor(g_Opt.m_Theme.SearchTextBoxFocusBG());
  492. return CreateSolidBrush(g_Opt.m_Theme.SearchTextBoxFocusBG());
  493. }
  494. else
  495. {
  496. pDC->SetBkColor(g_Opt.m_Theme.MainWindowBG());
  497. return CreateSolidBrush(g_Opt.m_Theme.MainWindowBG());
  498. }
  499. }
  500. void CSymbolEdit::OnSetFocus(CWnd* pOldWnd)
  501. {
  502. OutputDebugString(_T("OnSetFocus \r\n"));
  503. //was seeing issues when refreshing non client area inline, do it delayed
  504. SetTimer(1, 500, NULL);
  505. CWnd *pWnd = GetParent();
  506. if (pWnd)
  507. {
  508. if (g_Opt.m_bFindAsYouType)
  509. {
  510. pWnd->SendMessage(NM_FOCUS_ON_SEARCH, 0, 0);
  511. }
  512. }
  513. CEdit::OnSetFocus(pOldWnd);
  514. }
  515. void CSymbolEdit::OnKillFocus(CWnd* pNewWnd)
  516. {
  517. OutputDebugString(_T("OnKillFocus \r\n"));
  518. AddToSearchHistory();
  519. //was seeing issues when refreshing non client area inline, do it delayed
  520. SetTimer(1, 500, NULL);
  521. CEdit::OnKillFocus(pNewWnd);
  522. }
  523. BOOL CSymbolEdit::OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message)
  524. {
  525. CPoint pntCursor;
  526. GetCursorPos(&pntCursor);
  527. ScreenToClient(&pntCursor);
  528. if(m_closeButtonRect.PtInRect(pntCursor))
  529. {
  530. HCURSOR h = ::LoadCursor(NULL, IDC_ARROW);
  531. ::SetCursor(h);
  532. return TRUE;
  533. }
  534. if (m_searchesButtonRect.PtInRect(pntCursor))
  535. {
  536. HCURSOR h = ::LoadCursor(NULL, IDC_ARROW);
  537. ::SetCursor(h);
  538. return TRUE;
  539. }
  540. return CEdit::OnSetCursor(pWnd, nHitTest, message);
  541. }
  542. void CSymbolEdit::OnLButtonUp(UINT nFlags, CPoint point)
  543. {
  544. if (m_mouseDownOnClose)
  545. {
  546. ReleaseCapture();
  547. InvalidateRect(m_closeButtonRect);
  548. }
  549. if (m_mouseDownOnSearches)
  550. {
  551. ReleaseCapture();
  552. InvalidateRect(m_searchesButtonRect);
  553. }
  554. m_mouseDownOnClose = false;
  555. m_mouseDownOnSearches = false;
  556. if (m_closeButtonRect.PtInRect(point))
  557. {
  558. if ((GetWindowTextLength() > 0))
  559. {
  560. CWnd *pOwner = GetOwner();
  561. if (pOwner)
  562. {
  563. pOwner->SendMessage(NM_CANCEL_SEARCH, 0, 0);
  564. }
  565. }
  566. }
  567. if (m_searchesButtonRect.PtInRect(point))
  568. {
  569. this->ShowSearchHistoryMenu();
  570. }
  571. CEdit::OnLButtonUp(nFlags, point);
  572. }
  573. void CSymbolEdit::OnLButtonDown(UINT nFlags, CPoint point)
  574. {
  575. if (m_closeButtonRect.PtInRect(point))
  576. {
  577. m_mouseDownOnClose = true;
  578. SetCapture();
  579. InvalidateRect(m_closeButtonRect);
  580. }
  581. else
  582. {
  583. m_mouseDownOnClose = false;
  584. }
  585. if (m_searchesButtonRect.PtInRect(point))
  586. {
  587. m_mouseDownOnSearches = true;
  588. SetCapture();
  589. InvalidateRect(m_searchesButtonRect);
  590. }
  591. else
  592. {
  593. m_mouseDownOnSearches = false;
  594. }
  595. CEdit::OnLButtonDown(nFlags, point);
  596. Invalidate();
  597. }
  598. void CSymbolEdit::OnMouseMove(UINT nFlags, CPoint point)
  599. {
  600. if (m_closeButtonRect.PtInRect(point))
  601. {
  602. if (m_mouseHoveringOverClose == false)
  603. {
  604. m_mouseHoveringOverClose = true;
  605. InvalidateRect(m_closeButtonRect);
  606. }
  607. }
  608. else if(m_mouseHoveringOverClose)
  609. {
  610. m_mouseHoveringOverClose = false;
  611. InvalidateRect(m_closeButtonRect);
  612. }
  613. if (m_searchesButtonRect.PtInRect(point))
  614. {
  615. if (m_mouseHoveringOverSearches == false)
  616. {
  617. m_mouseHoveringOverSearches = true;
  618. InvalidateRect(m_searchesButtonRect);
  619. }
  620. }
  621. else if (m_mouseHoveringOverSearches)
  622. {
  623. m_mouseHoveringOverSearches = false;
  624. InvalidateRect(m_searchesButtonRect);
  625. }
  626. CEdit::OnMouseMove(nFlags, point);
  627. }
  628. void CSymbolEdit::OnSelectSearchString(UINT idIn)
  629. {
  630. int index = idIn - RANGE_START;
  631. if (idIn == CLEAR_LIST)
  632. {
  633. m_searches.RemoveAll();
  634. }
  635. else if (index >= 0 &&
  636. index < m_searches.GetCount())
  637. {
  638. CString cs = m_searches[index];
  639. this->SetWindowTextW(cs);
  640. this->SetFocus();
  641. this->SetSel(-1);
  642. this->Invalidate();
  643. m_searches.RemoveAt(index);
  644. m_searches.Add(cs);
  645. }
  646. }
  647. bool CSymbolEdit::ApplyLastSearch()
  648. {
  649. bool ret = false;
  650. if (m_searches.GetCount() > 0)
  651. {
  652. CString cs = m_searches[m_searches.GetCount()-1];
  653. this->SetWindowTextW(cs);
  654. this->SetFocus();
  655. this->SetSel(-1);
  656. this->Invalidate();
  657. ret = true;
  658. }
  659. return ret;
  660. }
  661. void CSymbolEdit::OnDpiChanged()
  662. {
  663. SetDpiInfo(m_windowDpi);
  664. }
  665. void CSymbolEdit::SetDpiInfo(CDPI *dpi)
  666. {
  667. m_windowDpi = dpi;
  668. m_closeButton.Reset();
  669. m_closeButton.LoadStdImageDPI(m_windowDpi->GetDPI(), search_close_16, search_close_20, search_close_24, search_close_28, search_close_32, _T("PNG"));
  670. m_searchesButton.Reset();
  671. m_searchesButton.LoadStdImageDPI(m_windowDpi->GetDPI(), down_16, down_20, down_24, down_28, down_32, _T("PNG"));
  672. RecalcLayout();
  673. Invalidate();
  674. }
  675. BOOL CSymbolEdit::OnEraseBkgnd(CDC* pDC)
  676. {
  677. // TODO: Add your message handler code here and/or call default
  678. //return CEdit::OnEraseBkgnd(pDC);
  679. return FALSE;
  680. }
  681. void CSymbolEdit::OnNcCalcSize(BOOL bCalcValidRects, NCCALCSIZE_PARAMS* lpncsp)
  682. {
  683. CString text;
  684. GetWindowText(text);
  685. //if (text.GetLength() > 0 || this == GetFocus())
  686. if (m_windowDpi != NULL)
  687. {
  688. lpncsp->rgrc[0].left += m_windowDpi->Scale(1);
  689. lpncsp->rgrc[0].top += m_windowDpi->Scale(1);
  690. lpncsp->rgrc[0].right -= m_windowDpi->Scale(1);
  691. lpncsp->rgrc[0].bottom -= m_windowDpi->Scale(1);
  692. CRect rectWnd, rectClient;
  693. ////calculate client area height needed for a font
  694. CFont *pFont = GetFont();
  695. CRect rectText;
  696. CDC *pDC = GetDC();
  697. CFont *pOld = pDC->SelectObject(pFont);
  698. pDC->DrawText("Ky", rectText, DT_CALCRECT | DT_LEFT);
  699. UINT uiVClientHeight = rectText.Height();
  700. pDC->SelectObject(pOld);
  701. ReleaseDC(pDC);
  702. ////calculate NC area to center text.
  703. //GetClientRect(rectClient);
  704. GetWindowRect(rectWnd);
  705. rectWnd.DeflateRect(m_windowDpi->Scale(1), m_windowDpi->Scale(1));
  706. m_centerTextDiff = (rectWnd.Height() - uiVClientHeight) / 2;
  707. if (m_centerTextDiff < 0 || m_centerTextDiff > uiVClientHeight)
  708. {
  709. m_centerTextDiff = 0;
  710. }
  711. lpncsp->rgrc[0].top += m_centerTextDiff;
  712. lpncsp->rgrc[0].bottom -= m_centerTextDiff;
  713. }
  714. //ClientToScreen(rectClient);
  715. //UINT uiCenterOffset = (rectWnd.Height() - uiVClientHeight) / 2;
  716. //UINT uiCY = (rectWnd.Heig%ht() - rectClient.Height()) / 2;
  717. //UINT uiCX = (rectWnd.Width() - rectClient.Width()) / 2;
  718. //rectWnd.OffsetRect(-rectWnd.left, -rectWnd.top);
  719. //m_rectNCTop = rectWnd;
  720. //m_rectNCTop.DeflateRect(uiCX, uiCY, uiCX, uiCenterOffset + uiVClientHeight + uiCY);
  721. //m_rectNCBottom = rectWnd;
  722. //m_rectNCBottom.DeflateRect(uiCX, uiCenterOffset + uiVClientHeight + uiCY, uiCX, uiCY);
  723. //lpncsp->rgrc[0].top += uiCenterOffset;
  724. //lpncsp->rgrc[0].bottom -= uiCenterOffset;
  725. //lpncsp->rgrc[0].left += uiCX;
  726. //lpncsp->rgrc[0].right -= uiCY;
  727. //CEdit::OnNcCalcSize(bCalcValidRects, lpncsp);
  728. }
  729. void CSymbolEdit::OnNcPaint()
  730. {
  731. CString text;
  732. GetWindowText(text);
  733. CWindowDC dc(this);
  734. CRect r;
  735. this->GetWindowRect(r);
  736. this->ScreenToClient(r);
  737. CRect t(0, 0, r.Width(), m_centerTextDiff+ m_windowDpi->Scale(1));
  738. CRect b(0, r.Height() - m_centerTextDiff- m_windowDpi->Scale(1), r.Width(), r.Height());
  739. COLORREF c = g_Opt.m_Theme.MainWindowBG();
  740. if (this == GetFocus() || text.GetLength() > 0)
  741. {
  742. dc.FillSolidRect(t, g_Opt.m_Theme.SearchTextBoxFocusBG());
  743. dc.FillSolidRect(b, g_Opt.m_Theme.SearchTextBoxFocusBG());
  744. c = g_Opt.m_Theme.SearchTextBoxFocusBorder();
  745. }
  746. else
  747. {
  748. dc.FillSolidRect(t, g_Opt.m_Theme.MainWindowBG());
  749. dc.FillSolidRect(b, g_Opt.m_Theme.MainWindowBG());
  750. }
  751. //if ((text.GetLength() > 0 || this == GetFocus()) && m_windowDpi)
  752. {
  753. CWindowDC dc(this);
  754. CRect rcFrame;
  755. this->GetWindowRect(rcFrame);
  756. this->ScreenToClient(rcFrame);
  757. CRect rcBorder(0, 0, rcFrame.Width(), rcFrame.Height());
  758. int border = m_windowDpi->Scale(1);
  759. CBrush borderBrush(c);
  760. for (int x = 0; x < border; x++)
  761. {
  762. dc.FrameRect(rcBorder, &borderBrush);
  763. rcBorder.DeflateRect(1, 1, 1, 1);
  764. }
  765. }
  766. OutputDebugString(_T("OnNCPaint \r\n"));
  767. }
  768. void CSymbolEdit::OnTimer(UINT_PTR nIDEvent)
  769. {
  770. switch (nIDEvent)
  771. {
  772. case 1:
  773. KillTimer(1);
  774. //Invalidate();
  775. ::SetWindowPos(m_hWnd, NULL, 0, 0, 0, 0, SWP_DRAWFRAME | SWP_NOSIZE | SWP_NOMOVE | SWP_NOACTIVATE);
  776. break;
  777. }
  778. CEdit::OnTimer(nIDEvent);
  779. }