SymbolEdit.cpp 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990
  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 10
  12. #define MAX_SAVED_SEARCH_LENGTH 50
  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. int count = 0;
  205. while (ItemElement)
  206. {
  207. if (count < LIST_MAX_COUNT)
  208. {
  209. CString item = ItemElement->Attribute("text");
  210. CString toAdd = item.Left(MAX_SAVED_SEARCH_LENGTH);
  211. if (toAdd != _T(""))
  212. {
  213. m_searches.Add(toAdd);
  214. }
  215. ItemElement = ItemElement->NextSiblingElement();
  216. }
  217. else
  218. {
  219. break;
  220. }
  221. count++;
  222. }
  223. }
  224. }
  225. void CSymbolEdit::AddToSearchHistory()
  226. {
  227. CString cs;
  228. this->GetWindowText(cs);
  229. if (cs != _T(""))
  230. {
  231. //only save up to 50, had reports of somehow getting extremely large amounts of junk text
  232. //save and causing memory issues.
  233. cs = cs.Left(MAX_SAVED_SEARCH_LENGTH);
  234. if (m_searches.GetCount() >= LIST_MAX_COUNT)
  235. {
  236. m_searches.RemoveAt(0);
  237. }
  238. bool existing = false;
  239. int count = (int)m_searches.GetCount();
  240. for (int i = 0; i < count; i++)
  241. {
  242. if (m_searches[i] == cs)
  243. {
  244. m_searches.RemoveAt(i);
  245. m_searches.Add(cs);
  246. existing = true;
  247. break;
  248. }
  249. }
  250. if (existing == false)
  251. {
  252. m_searches.Add(cs);
  253. }
  254. }
  255. }
  256. bool CSymbolEdit::ShowSearchHistoryMenu()
  257. {
  258. if (m_searches.GetCount() == 0)
  259. {
  260. return false;
  261. }
  262. CMenu cmPopUp;
  263. cmPopUp.CreatePopupMenu();
  264. int count = min((int)m_searches.GetCount(), LIST_MAX_COUNT);
  265. for (int i = count-1; i >= 0; i--)
  266. {
  267. CString text = m_searches[i];
  268. if (i == count - 1 &&
  269. m_lastSearchShortCut.Key > 0)
  270. {
  271. CString cmdShortcutText = CHotKey::GetHotKeyDisplayStatic(m_lastSearchShortCut.Key);
  272. if (m_lastSearchShortCut.Key2 != 0)
  273. {
  274. CString cmdShortcutText2 = CHotKey::GetHotKeyDisplayStatic(m_lastSearchShortCut.Key2);
  275. if (cmdShortcutText2.GetLength() > 0)
  276. {
  277. cmdShortcutText += _T(" - ");
  278. cmdShortcutText += cmdShortcutText2;
  279. }
  280. }
  281. text += "\t";
  282. text += cmdShortcutText;
  283. }
  284. cmPopUp.AppendMenuW(MF_STRING, (RANGE_START + i), text);
  285. }
  286. cmPopUp.AppendMenu(MF_SEPARATOR);
  287. cmPopUp.AppendMenuW(MF_STRING, CLEAR_LIST, _T("Clear List"));
  288. CRect windowRect;
  289. this->GetWindowRect(&windowRect);
  290. POINT pp;
  291. GetCursorPos(&pp);
  292. POINT x = this->GetCaretPos();
  293. ClientToScreen(&x);
  294. x.y += windowRect.Height();
  295. cmPopUp.TrackPopupMenu(TPM_LEFTALIGN | TPM_TOPALIGN | TPM_RIGHTBUTTON, x.x, x.y, this, NULL);
  296. Invalidate();
  297. return true;
  298. }
  299. void CSymbolEdit::DestroyIcon()
  300. {
  301. // if icon was loaded internally, destroy it
  302. if (m_bInternalIcon || m_hSymbolIcon != NULL)
  303. ::DestroyIcon(m_hSymbolIcon);
  304. }
  305. void CSymbolEdit::PreSubclassWindow()
  306. {
  307. RecalcLayout();
  308. }
  309. void CSymbolEdit::SetSymbolIcon(HICON hIcon, BOOL redraw)
  310. {
  311. DestroyIcon();
  312. m_hSymbolIcon = hIcon;
  313. // icon was not loaded internally
  314. m_bInternalIcon = false;
  315. RecalcLayout();
  316. if (redraw)
  317. Invalidate(TRUE);
  318. }
  319. void CSymbolEdit::SetSymbolIcon(UINT id, BOOL redraw)
  320. {
  321. DestroyIcon();
  322. m_hSymbolIcon = (HICON)::LoadImage(
  323. AfxGetResourceHandle(),
  324. MAKEINTRESOURCE(id),
  325. IMAGE_ICON,
  326. 16,
  327. 16,
  328. LR_DEFAULTCOLOR | LR_LOADTRANSPARENT);
  329. ASSERT(m_hSymbolIcon != NULL);
  330. // icon was loaded internally
  331. m_bInternalIcon = true;
  332. RecalcLayout();
  333. if (redraw)
  334. Invalidate(TRUE);
  335. }
  336. void CSymbolEdit::SetPromptText(CString text, BOOL redraw)
  337. {
  338. m_strPromptText = text;
  339. if (redraw)
  340. Invalidate(TRUE);
  341. }
  342. void CSymbolEdit::SetPromptText(LPCTSTR szText, BOOL redraw)
  343. {
  344. m_strPromptText = szText;
  345. if (redraw)
  346. Invalidate(TRUE);
  347. }
  348. void CSymbolEdit::SetPromptTextColor(COLORREF color, BOOL redraw)
  349. {
  350. m_colorPromptText = color;
  351. if (redraw)
  352. Invalidate(TRUE);
  353. }
  354. void CSymbolEdit::SetPromptFont(CFont& font, BOOL redraw)
  355. {
  356. LOGFONT lf;
  357. memset(&lf, 0, sizeof(LOGFONT));
  358. font.GetLogFont(&lf);
  359. SetPromptFont(&lf);
  360. if (redraw)
  361. Invalidate(TRUE);
  362. }
  363. void CSymbolEdit::SetPromptFont(const LOGFONT* lpLogFont, BOOL redraw)
  364. {
  365. m_fontPrompt.DeleteObject();
  366. m_fontPrompt.CreateFontIndirect(lpLogFont);
  367. if (redraw)
  368. Invalidate(TRUE);
  369. }
  370. void CSymbolEdit::RecalcLayout()
  371. {
  372. int width = GetSystemMetrics(SM_CXSMICON);
  373. if (m_hSymbolIcon)
  374. {
  375. DWORD dwMargins = GetMargins();
  376. SetMargins(LOWORD(dwMargins), width + 6);
  377. }
  378. else
  379. {
  380. if (m_windowDpi != NULL)
  381. {
  382. SetMargins(m_windowDpi->Scale(4), m_windowDpi->Scale(34));
  383. }
  384. }
  385. }
  386. void CSymbolEdit::OnPaint()
  387. {
  388. CPaintDC dc(this);
  389. CRect rect;
  390. GetClientRect(&rect);
  391. DWORD margins = GetMargins();
  392. CRect textRect(rect);
  393. textRect.left += LOWORD(margins);
  394. textRect.right -= HIWORD(margins);
  395. // Clearing the background
  396. dc.FillSolidRect(rect, GetSysColor(COLOR_WINDOW));
  397. if (m_hSymbolIcon)
  398. {
  399. // Drawing the icon
  400. int width = GetSystemMetrics(SM_CXSMICON);
  401. int height = GetSystemMetrics(SM_CYSMICON);
  402. ::DrawIconEx(
  403. dc.m_hDC,
  404. rect.right - width - 1,
  405. 1,
  406. m_hSymbolIcon,
  407. width,
  408. height,
  409. 0,
  410. NULL,
  411. DI_NORMAL);
  412. rect.left += LOWORD(margins) + 1;
  413. rect.right -= (width + 7);
  414. }
  415. else
  416. {
  417. //rect.left += (LOWORD(dwMargins) + 1);
  418. //rect.right -= (HIWORD(dwMargins) + 1);
  419. }
  420. CString text;
  421. GetWindowText(text);
  422. CFont* oldFont = NULL;
  423. //rect.top += 1;
  424. if(this == GetFocus() || text.GetLength() > 0)
  425. {
  426. dc.FillSolidRect(rect, g_Opt.m_Theme.SearchTextBoxFocusBG());
  427. //CBrush borderBrush(g_Opt.m_Theme.SearchTextBoxFocusBorder());
  428. //dc.FrameRect(rect, &borderBrush);
  429. //rect.DeflateRect(1, 1, 1, 1);
  430. //textRect.DeflateRect(0, 1, 1, 1);
  431. oldFont = dc.SelectObject(GetFont());
  432. COLORREF oldColor = dc.GetTextColor();
  433. dc.SetTextColor(g_Opt.m_Theme.SearchTextBoxFocusText());
  434. dc.DrawText(text, textRect, DT_SINGLELINE | DT_INTERNAL | DT_EDITCONTROL | DT_NOPREFIX);
  435. dc.SelectObject(oldFont);
  436. dc.SetTextColor(oldColor);
  437. }
  438. else
  439. {
  440. dc.FillSolidRect(rect, g_Opt.m_Theme.MainWindowBG());
  441. }
  442. if (text.GetLength() == 0 && m_strPromptText.GetLength() > 0)
  443. {
  444. //if we aren't showing the close icon, then use the full space
  445. textRect.right += m_windowDpi->Scale(16);
  446. //textRect.right -= LOWORD(margins);
  447. oldFont = dc.SelectObject(&m_fontPrompt);
  448. COLORREF color = dc.GetTextColor();
  449. dc.SetTextColor(m_colorPromptText);
  450. dc.DrawText(m_strPromptText, textRect, DT_LEFT | DT_SINGLELINE | DT_EDITCONTROL | DT_VCENTER | DT_NOPREFIX);
  451. dc.SetTextColor(color);
  452. dc.SelectObject(oldFont);
  453. }
  454. int right = rect.right;
  455. if ((text.GetLength() > 0 || this == GetFocus()))
  456. {
  457. m_searchesButtonRect.SetRect(rect.right - m_windowDpi->Scale(18), 0, rect.right, rect.bottom);
  458. right = rect.right - m_windowDpi->Scale(18);
  459. m_searchesButton.Draw(&dc, *m_windowDpi, this, m_searchesButtonRect.left, 4, m_mouseHoveringOverSearches, m_mouseDownOnSearches);
  460. }
  461. else
  462. {
  463. m_searchesButtonRect.SetRect(0, 0, 0, 0);
  464. //m_searchButton.Draw(&dc, this, rect.right - 22, 4, false, false);
  465. }
  466. if (text.GetLength() > 0)
  467. {
  468. OutputDebugString(_T("showing close button\n"));
  469. m_closeButtonRect.SetRect(right - m_windowDpi->Scale(16), 0, right, rect.bottom);
  470. m_closeButton.Draw(&dc, *m_windowDpi, this, m_closeButtonRect.left, 4, m_mouseHoveringOverClose, m_mouseDownOnClose);
  471. }
  472. else
  473. {
  474. OutputDebugString(_T("not showing close button\n"));
  475. m_closeButtonRect.SetRect(0, 0, 0, 0);
  476. //m_searchButton.Draw(&dc, this, rect.right - 22, 4, false, false);
  477. }
  478. //OutputDebugString(_T("OnPaint"));
  479. if (text != m_lastTextOnPaint &&
  480. text == _T(""))
  481. {
  482. ::SetWindowPos(m_hWnd, NULL, 0, 0, 0, 0, SWP_DRAWFRAME | SWP_NOSIZE | SWP_NOMOVE | SWP_NOACTIVATE);
  483. }
  484. m_lastTextOnPaint = text;
  485. OutputDebugString(_T("OnPaint \r\n"));
  486. }
  487. void CSymbolEdit::OnSize(UINT nType, int cx, int cy)
  488. {
  489. CEdit::OnSize(nType, cx, cy);
  490. RecalcLayout();
  491. }
  492. LRESULT CSymbolEdit::OnSetFont(WPARAM wParam, LPARAM lParam)
  493. {
  494. DefWindowProc(WM_SETFONT, wParam, lParam);
  495. RecalcLayout();
  496. return 0;
  497. }
  498. HBRUSH CSymbolEdit::CtlColor(CDC* pDC, UINT n)
  499. {
  500. OutputDebugString(_T("CtlColor \r\n"));
  501. if (::GetFocus() == m_hWnd)
  502. {
  503. pDC->SetTextColor(g_Opt.m_Theme.SearchTextBoxFocusText());
  504. pDC->SetBkColor(g_Opt.m_Theme.SearchTextBoxFocusBG());
  505. return CreateSolidBrush(g_Opt.m_Theme.SearchTextBoxFocusBG());
  506. }
  507. else
  508. {
  509. pDC->SetBkColor(g_Opt.m_Theme.MainWindowBG());
  510. return CreateSolidBrush(g_Opt.m_Theme.MainWindowBG());
  511. }
  512. }
  513. void CSymbolEdit::OnSetFocus(CWnd* pOldWnd)
  514. {
  515. OutputDebugString(_T("OnSetFocus \r\n"));
  516. //was seeing issues when refreshing non client area inline, do it delayed
  517. SetTimer(1, 500, NULL);
  518. CWnd *pWnd = GetParent();
  519. if (pWnd)
  520. {
  521. if (g_Opt.m_bFindAsYouType)
  522. {
  523. pWnd->SendMessage(NM_FOCUS_ON_SEARCH, 0, 0);
  524. }
  525. }
  526. CEdit::OnSetFocus(pOldWnd);
  527. }
  528. void CSymbolEdit::OnKillFocus(CWnd* pNewWnd)
  529. {
  530. OutputDebugString(_T("OnKillFocus \r\n"));
  531. AddToSearchHistory();
  532. //was seeing issues when refreshing non client area inline, do it delayed
  533. SetTimer(1, 500, NULL);
  534. CEdit::OnKillFocus(pNewWnd);
  535. }
  536. BOOL CSymbolEdit::OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message)
  537. {
  538. CPoint pntCursor;
  539. GetCursorPos(&pntCursor);
  540. ScreenToClient(&pntCursor);
  541. if(m_closeButtonRect.PtInRect(pntCursor))
  542. {
  543. HCURSOR h = ::LoadCursor(NULL, IDC_ARROW);
  544. ::SetCursor(h);
  545. return TRUE;
  546. }
  547. if (m_searchesButtonRect.PtInRect(pntCursor))
  548. {
  549. HCURSOR h = ::LoadCursor(NULL, IDC_ARROW);
  550. ::SetCursor(h);
  551. return TRUE;
  552. }
  553. return CEdit::OnSetCursor(pWnd, nHitTest, message);
  554. }
  555. void CSymbolEdit::OnLButtonUp(UINT nFlags, CPoint point)
  556. {
  557. if (m_mouseDownOnClose)
  558. {
  559. ReleaseCapture();
  560. InvalidateRect(m_closeButtonRect);
  561. }
  562. if (m_mouseDownOnSearches)
  563. {
  564. ReleaseCapture();
  565. InvalidateRect(m_searchesButtonRect);
  566. }
  567. m_mouseDownOnClose = false;
  568. m_mouseDownOnSearches = false;
  569. if (m_closeButtonRect.PtInRect(point))
  570. {
  571. if ((GetWindowTextLength() > 0))
  572. {
  573. CWnd *pOwner = GetOwner();
  574. if (pOwner)
  575. {
  576. pOwner->SendMessage(NM_CANCEL_SEARCH, 0, 0);
  577. }
  578. }
  579. }
  580. if (m_searchesButtonRect.PtInRect(point))
  581. {
  582. this->ShowSearchHistoryMenu();
  583. }
  584. CEdit::OnLButtonUp(nFlags, point);
  585. }
  586. void CSymbolEdit::OnLButtonDown(UINT nFlags, CPoint point)
  587. {
  588. if (m_closeButtonRect.PtInRect(point))
  589. {
  590. m_mouseDownOnClose = true;
  591. SetCapture();
  592. InvalidateRect(m_closeButtonRect);
  593. }
  594. else
  595. {
  596. m_mouseDownOnClose = false;
  597. }
  598. if (m_searchesButtonRect.PtInRect(point))
  599. {
  600. m_mouseDownOnSearches = true;
  601. SetCapture();
  602. InvalidateRect(m_searchesButtonRect);
  603. }
  604. else
  605. {
  606. m_mouseDownOnSearches = false;
  607. }
  608. CEdit::OnLButtonDown(nFlags, point);
  609. Invalidate();
  610. }
  611. void CSymbolEdit::OnMouseMove(UINT nFlags, CPoint point)
  612. {
  613. if (m_closeButtonRect.PtInRect(point))
  614. {
  615. if (m_mouseHoveringOverClose == false)
  616. {
  617. m_mouseHoveringOverClose = true;
  618. InvalidateRect(m_closeButtonRect);
  619. }
  620. }
  621. else if(m_mouseHoveringOverClose)
  622. {
  623. m_mouseHoveringOverClose = false;
  624. InvalidateRect(m_closeButtonRect);
  625. }
  626. if (m_searchesButtonRect.PtInRect(point))
  627. {
  628. if (m_mouseHoveringOverSearches == false)
  629. {
  630. m_mouseHoveringOverSearches = true;
  631. InvalidateRect(m_searchesButtonRect);
  632. }
  633. }
  634. else if (m_mouseHoveringOverSearches)
  635. {
  636. m_mouseHoveringOverSearches = false;
  637. InvalidateRect(m_searchesButtonRect);
  638. }
  639. CEdit::OnMouseMove(nFlags, point);
  640. }
  641. void CSymbolEdit::OnSelectSearchString(UINT idIn)
  642. {
  643. int index = idIn - RANGE_START;
  644. if (idIn == CLEAR_LIST)
  645. {
  646. m_searches.RemoveAll();
  647. }
  648. else if (index >= 0 &&
  649. index < m_searches.GetCount())
  650. {
  651. CString cs = m_searches[index];
  652. this->SetWindowTextW(cs);
  653. this->SetFocus();
  654. this->SetSel(-1);
  655. this->Invalidate();
  656. m_searches.RemoveAt(index);
  657. m_searches.Add(cs);
  658. }
  659. }
  660. bool CSymbolEdit::ApplyLastSearch()
  661. {
  662. bool ret = false;
  663. if (m_searches.GetCount() > 0)
  664. {
  665. CString cs = m_searches[m_searches.GetCount()-1];
  666. this->SetWindowTextW(cs);
  667. this->SetFocus();
  668. this->SetSel(-1);
  669. this->Invalidate();
  670. ret = true;
  671. }
  672. return ret;
  673. }
  674. void CSymbolEdit::OnDpiChanged()
  675. {
  676. SetDpiInfo(m_windowDpi);
  677. }
  678. void CSymbolEdit::SetDpiInfo(CDPI *dpi)
  679. {
  680. m_windowDpi = dpi;
  681. m_closeButton.Reset();
  682. m_closeButton.LoadStdImageDPI(m_windowDpi->GetDPI(), search_close_16, search_close_20, search_close_24, search_close_28, search_close_32, _T("PNG"));
  683. m_searchesButton.Reset();
  684. m_searchesButton.LoadStdImageDPI(m_windowDpi->GetDPI(), down_16, down_20, down_24, down_28, down_32, _T("PNG"));
  685. RecalcLayout();
  686. Invalidate();
  687. }
  688. BOOL CSymbolEdit::OnEraseBkgnd(CDC* pDC)
  689. {
  690. // TODO: Add your message handler code here and/or call default
  691. //return CEdit::OnEraseBkgnd(pDC);
  692. return FALSE;
  693. }
  694. void CSymbolEdit::OnNcCalcSize(BOOL bCalcValidRects, NCCALCSIZE_PARAMS* lpncsp)
  695. {
  696. CString text;
  697. GetWindowText(text);
  698. //if (text.GetLength() > 0 || this == GetFocus())
  699. if (m_windowDpi != NULL)
  700. {
  701. lpncsp->rgrc[0].left += m_windowDpi->Scale(1);
  702. lpncsp->rgrc[0].top += m_windowDpi->Scale(1);
  703. lpncsp->rgrc[0].right -= m_windowDpi->Scale(1);
  704. lpncsp->rgrc[0].bottom -= m_windowDpi->Scale(1);
  705. CRect rectWnd, rectClient;
  706. ////calculate client area height needed for a font
  707. CFont *pFont = GetFont();
  708. CRect rectText;
  709. CDC *pDC = GetDC();
  710. CFont *pOld = pDC->SelectObject(pFont);
  711. pDC->DrawText("Ky", rectText, DT_CALCRECT | DT_LEFT);
  712. UINT uiVClientHeight = rectText.Height();
  713. pDC->SelectObject(pOld);
  714. ReleaseDC(pDC);
  715. ////calculate NC area to center text.
  716. //GetClientRect(rectClient);
  717. GetWindowRect(rectWnd);
  718. rectWnd.DeflateRect(m_windowDpi->Scale(1), m_windowDpi->Scale(1));
  719. m_centerTextDiff = (rectWnd.Height() - uiVClientHeight) / 2;
  720. if (m_centerTextDiff < 0 || m_centerTextDiff > uiVClientHeight)
  721. {
  722. m_centerTextDiff = 0;
  723. }
  724. lpncsp->rgrc[0].top += m_centerTextDiff;
  725. lpncsp->rgrc[0].bottom -= m_centerTextDiff;
  726. }
  727. //ClientToScreen(rectClient);
  728. //UINT uiCenterOffset = (rectWnd.Height() - uiVClientHeight) / 2;
  729. //UINT uiCY = (rectWnd.Heig%ht() - rectClient.Height()) / 2;
  730. //UINT uiCX = (rectWnd.Width() - rectClient.Width()) / 2;
  731. //rectWnd.OffsetRect(-rectWnd.left, -rectWnd.top);
  732. //m_rectNCTop = rectWnd;
  733. //m_rectNCTop.DeflateRect(uiCX, uiCY, uiCX, uiCenterOffset + uiVClientHeight + uiCY);
  734. //m_rectNCBottom = rectWnd;
  735. //m_rectNCBottom.DeflateRect(uiCX, uiCenterOffset + uiVClientHeight + uiCY, uiCX, uiCY);
  736. //lpncsp->rgrc[0].top += uiCenterOffset;
  737. //lpncsp->rgrc[0].bottom -= uiCenterOffset;
  738. //lpncsp->rgrc[0].left += uiCX;
  739. //lpncsp->rgrc[0].right -= uiCY;
  740. //CEdit::OnNcCalcSize(bCalcValidRects, lpncsp);
  741. }
  742. void CSymbolEdit::OnNcPaint()
  743. {
  744. CString text;
  745. GetWindowText(text);
  746. CWindowDC dc(this);
  747. CRect r;
  748. this->GetWindowRect(r);
  749. this->ScreenToClient(r);
  750. CRect t(0, 0, r.Width(), m_centerTextDiff+ m_windowDpi->Scale(1));
  751. CRect b(0, r.Height() - m_centerTextDiff- m_windowDpi->Scale(1), r.Width(), r.Height());
  752. COLORREF c = g_Opt.m_Theme.MainWindowBG();
  753. if (this == GetFocus() || text.GetLength() > 0)
  754. {
  755. dc.FillSolidRect(t, g_Opt.m_Theme.SearchTextBoxFocusBG());
  756. dc.FillSolidRect(b, g_Opt.m_Theme.SearchTextBoxFocusBG());
  757. c = g_Opt.m_Theme.SearchTextBoxFocusBorder();
  758. }
  759. else
  760. {
  761. dc.FillSolidRect(t, g_Opt.m_Theme.MainWindowBG());
  762. dc.FillSolidRect(b, g_Opt.m_Theme.MainWindowBG());
  763. }
  764. //if ((text.GetLength() > 0 || this == GetFocus()) && m_windowDpi)
  765. {
  766. CWindowDC dc(this);
  767. CRect rcFrame;
  768. this->GetWindowRect(rcFrame);
  769. this->ScreenToClient(rcFrame);
  770. CRect rcBorder(0, 0, rcFrame.Width(), rcFrame.Height());
  771. int border = m_windowDpi->Scale(1);
  772. CBrush borderBrush(c);
  773. for (int x = 0; x < border; x++)
  774. {
  775. dc.FrameRect(rcBorder, &borderBrush);
  776. rcBorder.DeflateRect(1, 1, 1, 1);
  777. }
  778. }
  779. OutputDebugString(_T("OnNCPaint \r\n"));
  780. }
  781. void CSymbolEdit::OnTimer(UINT_PTR nIDEvent)
  782. {
  783. switch (nIDEvent)
  784. {
  785. case 1:
  786. KillTimer(1);
  787. //Invalidate();
  788. ::SetWindowPos(m_hWnd, NULL, 0, 0, 0, 0, SWP_DRAWFRAME | SWP_NOSIZE | SWP_NOMOVE | SWP_NOACTIVATE);
  789. break;
  790. }
  791. CEdit::OnTimer(nIDEvent);
  792. }