SubLabel.cpp 30 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364
  1. // Label.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "SubLabel.h"
  5. #ifdef _DEBUG
  6. #define new DEBUG_NEW
  7. #undef THIS_FILE
  8. static char THIS_FILE[] = __FILE__;
  9. #endif
  10. BEGIN_MESSAGE_MAP(CLabel, CStatic)
  11. //{{AFX_MSG_MAP(CLabel)
  12. ON_WM_TIMER()
  13. ON_WM_LBUTTONDOWN()
  14. ON_WM_SETCURSOR()
  15. ON_WM_SYSCOLORCHANGE()
  16. ON_WM_PAINT()
  17. ON_WM_ERASEBKGND()
  18. //}}AFX_MSG_MAP
  19. ON_WM_CTLCOLOR_REFLECT()
  20. END_MESSAGE_MAP()
  21. /////////////////////////////////////////////////////////////////////////////
  22. // CLabel Version 1.2
  23. //
  24. // From now on I'll try to keep a log of fixes and enhancements...
  25. //
  26. // The new feature were added due to the response of people.
  27. // All I ask is to all you programmers out there, is if you add, fix or
  28. // enhance this code, sent me a copy and I'll send the copy on to www.codeproject.com
  29. //
  30. // Happy Software Engineer :)
  31. //
  32. // New features include:
  33. //
  34. // A. Support for 3D Fonts
  35. // B. Support for background transparency
  36. // C. More comments provided
  37. // D. If alignment is 'centered' and the window text is seperated by '\r\n'
  38. // the will be centered accordingly - requested by someone @ nasa ;)
  39. // E. Support for font rotation.
  40. // F. Respond to System Color Change
  41. // G. OnPaint improved performance - using Double Buffering Technique
  42. //
  43. // Thanks to:
  44. // Mark McDowell - For suggestion on 'Increasing the flexibility of "hypertext" setting...'
  45. // Erich Ruth - For suggestion on 'Font Rotation'
  46. //
  47. /////////////////////////////////////////////////////////////////////////////
  48. // CLabel Version 1.3
  49. //
  50. // A. Added SS_LEFTNOWORDWRAP to include wordwrap
  51. // B. Fix repainting problem
  52. // C. Fix SetBkColor
  53. // D. Added SS_CENTER
  54. // Thanks to:
  55. // Marius - Added styling problem.
  56. // Azing Vondeling & Broker - Spotting painting Problem.
  57. // Mel Stober - Back Color & SS_CENTER
  58. //
  59. /////////////////////////////////////////////////////////////////////////////
  60. // CLabel Version 1.4
  61. //
  62. // A. Fix to transparency mode
  63. // B. Added new SetText3DHiliteColor to change the 3D Font face color - default is white.
  64. //
  65. // Thanks to:
  66. // michael.groeger - Spotting Transparency with other controls bug.
  67. //
  68. //
  69. /////////////////////////////////////////////////////////////////////////////
  70. // CLabel Version 1.5
  71. //
  72. // A. Sanity handle check
  73. // B. Support Interface Charset
  74. // C. Check compilition with _UNICODE
  75. // D. Fix hyperlink feature
  76. // E. Support default Dialog Font
  77. // F. Inclusion of SS_OWNERDRAW via control creation and subclassing
  78. // G. Modification to Text aligmnent code
  79. // H. New background gradient fill function
  80. //
  81. // Thanks to:
  82. // Steve Kowald - Using null handles
  83. // Alan Chan - Supporting International Windows
  84. // Dieter Fauth - Request for default Dialog font
  85. // Herb Illfelder - Text Alignment code
  86. //
  87. /////////////////////////////////////////////////////////////////////////////
  88. // CLabel Version 1.6
  89. // Jeroen Roosendaal - SetFont suggestion
  90. // Laurent - Spotting SelectObject bugs
  91. // Bernie - Fix PreCreateWindow bug
  92. // Jignesh I. Patel - Added expanded tabs feature
  93. // Jim Farmelant - Fix SetText crash
  94. //////////////////////////////////////////////////////////////////////////
  95. //
  96. // Function: CLabel::CLabel
  97. //
  98. // Description: Default contructor
  99. //
  100. // INPUTS:
  101. //
  102. // RETURNS:
  103. //
  104. // NOTES:
  105. //
  106. // MODIFICATIONS:
  107. //
  108. // Name Date Version Comments
  109. // NT ALMOND 26/08/98 1.0 Origin
  110. //
  111. //////////////////////////////////////////////////////////////////////////
  112. CLabel::CLabel()
  113. {
  114. m_crText = GetSysColor(COLOR_WINDOWTEXT);
  115. // 1.1
  116. m_hBackBrush = NULL;
  117. m_crHiColor = 0;
  118. m_crLoColor = 0;
  119. m_bTimer = FALSE;
  120. m_bState = FALSE;
  121. m_bTransparent = FALSE;
  122. m_Link = LinkNone;
  123. m_hCursor = NULL;
  124. m_Type = None;
  125. m_bFont3d = FALSE;
  126. m_bNotifyParent = FALSE;
  127. m_bToolTips = FALSE;
  128. m_bRotation = FALSE;
  129. m_fillmode = Normal;
  130. m_cr3DHiliteColor = RGB(255,255,255);
  131. m_strText = _T("");
  132. m_hwndBrush = ::CreateSolidBrush(GetSysColor(COLOR_3DFACE));
  133. }
  134. //////////////////////////////////////////////////////////////////////////
  135. //
  136. // Function: CLabel::~CLabel
  137. //
  138. // Description:
  139. //
  140. // INPUTS:
  141. //
  142. // RETURNS:
  143. //
  144. // NOTES:
  145. //
  146. // MODIFICATIONS:
  147. //
  148. // Name Date Version Comments
  149. // NT ALMOND 26/08/98 1.0 Origin
  150. // NT ALMOND 15092000 1.5 Handle Check
  151. //////////////////////////////////////////////////////////////////////////
  152. CLabel::~CLabel()
  153. {
  154. // Clean up
  155. m_font.DeleteObject();
  156. ::DeleteObject(m_hwndBrush);
  157. // Stop Checking complaining
  158. if (m_hBackBrush)
  159. ::DeleteObject(m_hBackBrush);
  160. }
  161. void CLabel::UpdateSurface()
  162. {
  163. CRect (rc);
  164. GetWindowRect(rc);
  165. RedrawWindow();
  166. GetParent()->ScreenToClient(rc);
  167. GetParent()->InvalidateRect(rc,TRUE);
  168. GetParent()->UpdateWindow();
  169. }
  170. //////////////////////////////////////////////////////////////////////////
  171. //
  172. // Function: CLabel::ReconstructFont
  173. //
  174. // Description: Helper function to build font after it was changed
  175. //
  176. // INPUTS:
  177. //
  178. // RETURNS:
  179. //
  180. // NOTES: PROTECTED
  181. //
  182. // MODIFICATIONS:
  183. //
  184. // Name Date Version Comments
  185. // NT ALMOND 26/08/98 1.0 Origin
  186. //
  187. //////////////////////////////////////////////////////////////////////////
  188. void CLabel::ReconstructFont()
  189. {
  190. m_font.DeleteObject();
  191. BOOL bCreated = m_font.CreateFontIndirect(&m_lf);
  192. ASSERT(bCreated);
  193. }
  194. //////////////////////////////////////////////////////////////////////////
  195. //
  196. // Function: CLabel::OnPaint
  197. //
  198. // Description: Handles all the drawing code for the label
  199. //
  200. // INPUTS:
  201. //
  202. // RETURNS:
  203. //
  204. // NOTES: Called by Windows... not by USER
  205. // Probably needs tiding up a some point.
  206. // Different states will require this code to be reworked.
  207. //
  208. //
  209. // MODIFICATIONS:
  210. //
  211. // Name Date Version Comments
  212. // NT ALMOND 22/10/98 1.0 Origin
  213. // NT ALMOND 15092000 1.5 Handle Check
  214. // NT ALMOND 15092000 1.5 Alignment mods
  215. // NT ALMOND 15092000 1.5 Gradient Fill Mode
  216. // NT ALMOND 02072002 1.6 Fill SelectObject bugs
  217. // NT ALMOND 02072002 1.6 Added to expand tabs
  218. //////////////////////////////////////////////////////////////////////////
  219. void CLabel::OnPaint()
  220. {
  221. CPaintDC dc(this); // device context for painting
  222. DWORD dwFlags = 0;
  223. CRect rc;
  224. GetClientRect(rc);
  225. if (m_strText.IsEmpty())
  226. GetWindowText(m_strText);
  227. CBitmap bmp;
  228. ///////////////////////////////////////////////////////
  229. //
  230. // Set up for double buffering...
  231. //
  232. CDC* pDCMem;
  233. CBitmap* pOldBitmap = NULL;
  234. if (!m_bTransparent)
  235. {
  236. pDCMem = new CDC;
  237. pDCMem->CreateCompatibleDC(&dc);
  238. bmp.CreateCompatibleBitmap(&dc,rc.Width(),rc.Height());
  239. pOldBitmap = pDCMem->SelectObject(&bmp);
  240. }
  241. else
  242. {
  243. pDCMem = &dc;
  244. }
  245. UINT nMode = pDCMem->SetBkMode(TRANSPARENT);
  246. COLORREF crText = pDCMem->SetTextColor(m_crText);
  247. CFont *pOldFont = pDCMem->SelectObject(&m_font);
  248. // Fill in backgound if not transparent
  249. if (!m_bTransparent)
  250. {
  251. if (m_fillmode == Normal)
  252. {
  253. CBrush br;
  254. if (m_hBackBrush != NULL)
  255. br.Attach(m_hBackBrush);
  256. else
  257. br.Attach(m_hwndBrush);
  258. pDCMem->FillRect(rc,&br);
  259. br.Detach();
  260. }
  261. else // Gradient Fill
  262. {
  263. DrawGradientFill(pDCMem, &rc, m_crLoColor, m_crHiColor, 100);
  264. }
  265. }
  266. // If the text is flashing turn the text color on
  267. // then to the color of the window background.
  268. LOGBRUSH lb;
  269. ZeroMemory(&lb,sizeof(lb));
  270. // Stop Checking complaining
  271. if (m_hBackBrush)
  272. ::GetObject(m_hBackBrush,sizeof(lb),&lb);
  273. // Something to do with flashing
  274. if (!m_bState && m_Type == Text)
  275. {
  276. //ZeroMemory(&lb,sizeof(lb));
  277. lb.lbColor = RGB(255,0,255);
  278. pDCMem->SetTextColor(lb.lbColor);
  279. }
  280. DWORD style = GetStyle();
  281. switch (style & SS_TYPEMASK)
  282. {
  283. case SS_RIGHT:
  284. dwFlags = DT_RIGHT | DT_WORDBREAK;
  285. break;
  286. case SS_CENTER:
  287. dwFlags = SS_CENTER | DT_WORDBREAK;
  288. break;
  289. case SS_LEFTNOWORDWRAP:
  290. dwFlags = DT_LEFT;
  291. break;
  292. default: // treat other types as left
  293. case SS_LEFT:
  294. dwFlags = DT_LEFT | DT_WORDBREAK;
  295. break;
  296. }
  297. // Added to expand tabs...
  298. if(m_strText.Find(_T('\t')) != -1)
  299. dwFlags |= DT_EXPANDTABS;
  300. // If the text centered make an assumtion that
  301. // the will want to center verticly as well
  302. if (style & SS_CENTERIMAGE)
  303. {
  304. dwFlags = DT_CENTER;
  305. // Apply
  306. if (m_strText.Find(_T("\r\n")) == -1)
  307. {
  308. dwFlags |= DT_VCENTER;
  309. // And because DT_VCENTER only works with single lines
  310. dwFlags |= DT_SINGLELINE;
  311. }
  312. }
  313. //
  314. // 3333 DDDDD
  315. // 3 D D
  316. // 33 D D E F X
  317. // 3 D D
  318. // 3333 DDDDD
  319. //
  320. //
  321. if (m_bRotation)
  322. {
  323. int nAlign = pDCMem->SetTextAlign (TA_BASELINE);
  324. CPoint pt;
  325. GetViewportOrgEx (pDCMem->m_hDC,&pt) ;
  326. SetViewportOrgEx (pDCMem->m_hDC,rc.Width() / 2, rc.Height() / 2, NULL) ;
  327. pDCMem->TextOut(0, 0, m_strText);
  328. SetViewportOrgEx (pDCMem->m_hDC,pt.x / 2, pt.y / 2, NULL) ;
  329. pDCMem->SetTextAlign (nAlign);
  330. }
  331. else
  332. {
  333. pDCMem->DrawText(m_strText, rc, dwFlags);
  334. if (m_bFont3d)
  335. {
  336. pDCMem->SetTextColor(m_cr3DHiliteColor);
  337. if (m_3dType == Raised)
  338. rc.OffsetRect(-1,-1);
  339. else
  340. rc.OffsetRect(1,1);
  341. pDCMem->DrawText(m_strText, rc, dwFlags);
  342. m_3dType;
  343. }
  344. }
  345. // Restore DC's State
  346. pDCMem->SetBkMode(nMode);
  347. pDCMem->SelectObject(pOldFont);
  348. pDCMem->SetTextColor(crText);
  349. if (!m_bTransparent)
  350. {
  351. dc.BitBlt(0, 0, rc.Width(), rc.Height(), pDCMem, 0, 0, SRCCOPY);
  352. // continue DC restore
  353. pDCMem->SelectObject ( pOldBitmap ) ;
  354. delete pDCMem;
  355. }
  356. }
  357. //////////////////////////////////////////////////////////////////////////
  358. //
  359. // Function: CLabel::OnTimer
  360. //
  361. // Description: Used in conjunction with 'FLASH' functions
  362. //
  363. // INPUTS: Windows API
  364. //
  365. // RETURNS: Windows API
  366. //
  367. // NOTES:
  368. //
  369. // MODIFICATIONS:
  370. //
  371. // Name Date Version Comments
  372. // NT ALMOND 26/08/98 1.0 Origin
  373. //
  374. //////////////////////////////////////////////////////////////////////////
  375. void CLabel::OnTimer(UINT nIDEvent)
  376. {
  377. m_bState = !m_bState;
  378. UpdateSurface();
  379. CStatic::OnTimer(nIDEvent);
  380. }
  381. //////////////////////////////////////////////////////////////////////////
  382. //
  383. // Function: CLabel::OnSetCursor
  384. //
  385. // Description: Used in conjunction with 'LINK' function
  386. //
  387. // INPUTS: Windows API
  388. //
  389. // RETURNS: Windows API
  390. //
  391. // NOTES:
  392. //
  393. // MODIFICATIONS:
  394. //
  395. // Name Date Version Comments
  396. // NT ALMOND 26/08/98 1.0 Origin
  397. //
  398. //////////////////////////////////////////////////////////////////////////
  399. BOOL CLabel::OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message)
  400. {
  401. if (m_hCursor)
  402. {
  403. ::SetCursor(m_hCursor);
  404. return TRUE;
  405. }
  406. return CStatic::OnSetCursor(pWnd, nHitTest, message);
  407. }
  408. //////////////////////////////////////////////////////////////////////////
  409. //
  410. // Function: CLabel::OnLButtonDown
  411. //
  412. // Description: Called when a link is click on
  413. //
  414. // INPUTS: Windows API
  415. //
  416. // RETURNS: Windows API
  417. //
  418. // NOTES:
  419. //
  420. // MODIFICATIONS:
  421. //
  422. // Name Date Version Comments
  423. // NT ALMOND 26/08/98 1.0 Origin
  424. // NT ALMOND 02072002 1.6 Added Mail support
  425. //////////////////////////////////////////////////////////////////////////
  426. void CLabel::OnLButtonDown(UINT nFlags, CPoint point)
  427. {
  428. if (!m_bNotifyParent) // Fix
  429. {
  430. CString strLink;
  431. GetWindowText(strLink);
  432. if (m_Link == HyperLink)
  433. {
  434. ShellExecute(NULL,_T("open"),m_sLink.IsEmpty() ? strLink : m_sLink,NULL,NULL,SW_SHOWNORMAL);
  435. }
  436. if (m_Link == MailLink)
  437. {
  438. strLink = _T("mailto:") + strLink;
  439. ShellExecute( NULL, NULL, strLink, NULL, NULL, SW_SHOWNORMAL );
  440. }
  441. }
  442. else
  443. {
  444. // To use notification in parent window
  445. // Respond to a OnNotify in parent and disassemble the message
  446. //
  447. NMHDR nm;
  448. nm.hwndFrom = GetSafeHwnd();
  449. nm.idFrom = GetDlgCtrlID();
  450. nm.code = NM_LINKCLICK;
  451. GetParent()->SendMessage(WM_NOTIFY,nm.idFrom,(LPARAM) &nm);
  452. }
  453. CStatic::OnLButtonDown(nFlags, point);
  454. }
  455. //////////////////////////////////////////////////////////////////////////
  456. //////////////////////////////////////////////////////////////////////////
  457. // THE FUNCTIONS START HERE :----
  458. //////////////////////////////////////////////////////////////////////////
  459. //////////////////////////////////////////////////////////////////////////
  460. //////////////////////////////////////////////////////////////////////////
  461. //
  462. // Function: CLabel::SetText
  463. //
  464. // Description: Short cut to set window text - caption - label
  465. //
  466. // INPUTS: Text to use
  467. //
  468. // RETURNS: Reference to this
  469. //
  470. // NOTES:
  471. //
  472. // MODIFICATIONS:
  473. //
  474. // Name Date Version Comments
  475. // NT ALMOND 26081998 1.0 Origin
  476. // NT ALMOND 02072002 1.6 Crash Fix
  477. //////////////////////////////////////////////////////////////////////////
  478. CLabel& CLabel::SetText(const CString& strText)
  479. {
  480. if(IsWindow(this->GetSafeHwnd()))
  481. {
  482. //SetWindowText(strText);
  483. m_strText = strText;
  484. UpdateSurface();
  485. }
  486. return *this;
  487. }
  488. //////////////////////////////////////////////////////////////////////////
  489. //
  490. // Function: CLabel::SetTextColor
  491. //
  492. // Description: Sets the text color
  493. //
  494. // INPUTS: True or false
  495. //
  496. // RETURNS: Reference to 'this' object
  497. //
  498. // NOTES:
  499. //
  500. // MODIFICATIONS:
  501. //
  502. // Name Date Version Comments
  503. // NT ALMOND 22/10/98 1.0 Origin
  504. //
  505. //////////////////////////////////////////////////////////////////////////
  506. CLabel& CLabel::SetTextColor(COLORREF crText)
  507. {
  508. m_crText = crText;
  509. UpdateSurface();
  510. return *this;
  511. }
  512. //////////////////////////////////////////////////////////////////////////
  513. //
  514. // Function: CLabel::SetFontBold
  515. //
  516. // Description: Sets the font ot bold
  517. //
  518. // INPUTS: True or false
  519. //
  520. // RETURNS: Reference to 'this' object
  521. //
  522. // NOTES:
  523. //
  524. // MODIFICATIONS:
  525. //
  526. // Name Date Version Comments
  527. // NT ALMOND 22/10/98 1.0 Origin
  528. //
  529. //////////////////////////////////////////////////////////////////////////
  530. CLabel& CLabel::SetFontBold(BOOL bBold)
  531. {
  532. m_lf.lfWeight = bBold ? FW_BOLD : FW_NORMAL;
  533. ReconstructFont();
  534. UpdateSurface();
  535. return *this;
  536. }
  537. //////////////////////////////////////////////////////////////////////////
  538. //
  539. // Function: CLabel::SetFontUnderline
  540. //
  541. // Description: Sets font underline attribue
  542. //
  543. // INPUTS: True of false
  544. //
  545. // RETURNS: Reference to 'this' object
  546. //
  547. // NOTES:
  548. //
  549. // MODIFICATIONS:
  550. //
  551. // Name Date Version Comments
  552. // NT ALMOND 26/08/98 1.0 Origin
  553. //
  554. //////////////////////////////////////////////////////////////////////////
  555. CLabel& CLabel::SetFontUnderline(BOOL bSet)
  556. {
  557. m_lf.lfUnderline = bSet;
  558. ReconstructFont();
  559. UpdateSurface();
  560. return *this;
  561. }
  562. //////////////////////////////////////////////////////////////////////////
  563. //
  564. // Function: CLabel::SetFontItalic
  565. //
  566. // Description: Sets font italic attribute
  567. //
  568. // INPUTS: True of false
  569. //
  570. // RETURNS: Reference to 'this' object
  571. //
  572. // NOTES:
  573. //
  574. // MODIFICATIONS:
  575. //
  576. // Name Date Version Comments
  577. // NT ALMOND 26/08/98 1.0 Origin
  578. //
  579. //////////////////////////////////////////////////////////////////////////
  580. CLabel& CLabel::SetFontItalic(BOOL bSet)
  581. {
  582. m_lf.lfItalic = bSet;
  583. ReconstructFont();
  584. UpdateSurface();
  585. return *this;
  586. }
  587. //////////////////////////////////////////////////////////////////////////
  588. //
  589. // Function: CLabel::SetSunken
  590. //
  591. // Description: Sets sunken effect on border
  592. //
  593. // INPUTS: True of false
  594. //
  595. // RETURNS: Reference to 'this' object
  596. //
  597. // NOTES:
  598. //
  599. // MODIFICATIONS:
  600. //
  601. // Name Date Version Comments
  602. // NT ALMOND 26/08/98 1.0 Origin
  603. //
  604. //////////////////////////////////////////////////////////////////////////
  605. CLabel& CLabel::SetSunken(BOOL bSet)
  606. {
  607. if (!bSet)
  608. ModifyStyleEx(WS_EX_STATICEDGE,0,SWP_DRAWFRAME);
  609. else
  610. ModifyStyleEx(0,WS_EX_STATICEDGE,SWP_DRAWFRAME);
  611. return *this;
  612. }
  613. //////////////////////////////////////////////////////////////////////////
  614. //
  615. // Function: CLabel::SetBorder
  616. //
  617. // Description: Toggles the border on/off
  618. //
  619. // INPUTS: True of false
  620. //
  621. // RETURNS: Reference to 'this' object
  622. //
  623. // NOTES:
  624. //
  625. // MODIFICATIONS:
  626. //
  627. // Name Date Version Comments
  628. // NT ALMOND 26/08/98 1.0 Origin
  629. //
  630. //////////////////////////////////////////////////////////////////////////
  631. CLabel& CLabel::SetBorder(BOOL bSet)
  632. {
  633. if (!bSet)
  634. ModifyStyle(WS_BORDER,0,SWP_DRAWFRAME);
  635. else
  636. ModifyStyle(0,WS_BORDER,SWP_DRAWFRAME);
  637. return *this;
  638. }
  639. //////////////////////////////////////////////////////////////////////////
  640. //
  641. // Function: CLabel::SetFontSize
  642. //
  643. // Description: Sets the font size
  644. //
  645. // INPUTS: True of false
  646. //
  647. // RETURNS: Reference to 'this' object
  648. //
  649. // NOTES:
  650. //
  651. // MODIFICATIONS:
  652. //
  653. // Name Date Version Comments
  654. // NT ALMOND 26/08/98 1.0 Origin
  655. //
  656. //////////////////////////////////////////////////////////////////////////
  657. CLabel& CLabel::SetFontSize(int nSize)
  658. {
  659. CFont cf;
  660. LOGFONT lf;
  661. cf.CreatePointFont(nSize * 10, m_lf.lfFaceName);
  662. cf.GetLogFont(&lf);
  663. m_lf.lfHeight = lf.lfHeight;
  664. m_lf.lfWidth = lf.lfWidth;
  665. // nSize*=-1;
  666. // m_lf.lfHeight = nSize;
  667. ReconstructFont();
  668. UpdateSurface();
  669. return *this;
  670. }
  671. //////////////////////////////////////////////////////////////////////////
  672. //
  673. // Function: CLabel::SetBkColor
  674. //
  675. // Description: Sets background color
  676. //
  677. // INPUTS: Colorref of background color
  678. //
  679. // RETURNS: Reference to 'this' object
  680. //
  681. // NOTES:
  682. //
  683. // MODIFICATIONS:
  684. //
  685. // Name Date Version Comments
  686. // NT ALMOND 26/08/98 1.0 Origin
  687. //
  688. //////////////////////////////////////////////////////////////////////////
  689. CLabel& CLabel::SetBkColor(COLORREF crBkgnd, COLORREF crBkgndHigh , BackFillMode mode)
  690. {
  691. m_crLoColor = crBkgnd;
  692. m_crHiColor = crBkgndHigh;
  693. m_fillmode = mode;
  694. if (m_hBackBrush)
  695. ::DeleteObject(m_hBackBrush);
  696. if (m_fillmode == Normal)
  697. m_hBackBrush = ::CreateSolidBrush(crBkgnd);
  698. UpdateSurface();
  699. return *this;
  700. }
  701. //////////////////////////////////////////////////////////////////////////
  702. //
  703. // Function: CLabel::SetFontName
  704. //
  705. // Description: Sets the fonts face name
  706. //
  707. // INPUTS: String containing font name
  708. //
  709. // RETURNS: Reference to 'this' object
  710. //
  711. // NOTES:
  712. //
  713. // MODIFICATIONS:
  714. //
  715. // Name Date Version Comments
  716. // NT ALMOND 26/08/98 1.0 Origin
  717. // NT ALMOND 15092000 1.5 Support internation windows
  718. //////////////////////////////////////////////////////////////////////////
  719. CLabel& CLabel::SetFontName(const CString& strFont, BYTE byCharSet /* Default = ANSI_CHARSET */)
  720. {
  721. m_lf.lfCharSet = byCharSet;
  722. _tcscpy_s(m_lf.lfFaceName,strFont);
  723. ReconstructFont();
  724. UpdateSurface();
  725. return *this;
  726. }
  727. //////////////////////////////////////////////////////////////////////////
  728. //
  729. // Function: CLabel::FlashText
  730. //
  731. // Description: As the function states
  732. //
  733. // INPUTS: True or false
  734. //
  735. // RETURNS: Reference to 'this' object
  736. //
  737. // NOTES:
  738. //
  739. // MODIFICATIONS:
  740. //
  741. // Name Date Version Comments
  742. // NT ALMOND 26/08/98 1.0 Origin
  743. //
  744. //////////////////////////////////////////////////////////////////////////
  745. CLabel& CLabel::FlashText(BOOL bActivate)
  746. {
  747. if (m_bTimer)
  748. KillTimer(1);
  749. if (bActivate)
  750. {
  751. m_bState = FALSE;
  752. m_bTimer = TRUE;
  753. SetTimer(1,500,NULL);
  754. m_Type = Text;
  755. }
  756. else
  757. m_Type = None; // Fix
  758. return *this;
  759. }
  760. //////////////////////////////////////////////////////////////////////////
  761. //
  762. // Function: CLabel::FlashBackground
  763. //
  764. // Description: As the function states
  765. //
  766. // INPUTS: True or false
  767. //
  768. // RETURNS: Reference to 'this' object
  769. //
  770. // NOTES:
  771. //
  772. // MODIFICATIONS:
  773. //
  774. // Name Date Version Comments
  775. // NT ALMOND 26/08/98 1.0 Origin
  776. //
  777. //////////////////////////////////////////////////////////////////////////
  778. CLabel& CLabel::FlashBackground(BOOL bActivate)
  779. {
  780. if (m_bTimer)
  781. KillTimer(1);
  782. if (bActivate)
  783. {
  784. m_bState = FALSE;
  785. m_bTimer = TRUE;
  786. SetTimer(1,500,NULL);
  787. m_Type = Background;
  788. }
  789. return *this;
  790. }
  791. //////////////////////////////////////////////////////////////////////////
  792. //
  793. // Function: CLabel::SetLink
  794. //
  795. // Description: Indicates the string is a link
  796. //
  797. // INPUTS: True or false
  798. //
  799. // RETURNS: Reference to 'this' object
  800. //
  801. // NOTES:
  802. //
  803. // MODIFICATIONS:
  804. //
  805. // Name Date Version Comments
  806. // NT ALMOND 26/08/98 1.0 Origin
  807. // NT ALMOND 26/08/99 1.2 Added flexbility of
  808. // Sending Click meessage to parent
  809. //
  810. //////////////////////////////////////////////////////////////////////////
  811. CLabel& CLabel::SetLink(BOOL bLink,BOOL bNotifyParent)
  812. {
  813. if (bLink)
  814. m_Link = HyperLink;
  815. else
  816. m_Link = LinkNone;
  817. m_bNotifyParent = bNotifyParent;
  818. if (m_Link != LinkNone)
  819. ModifyStyle(0,SS_NOTIFY);
  820. else
  821. ModifyStyle(SS_NOTIFY,0);
  822. return *this;
  823. }
  824. //////////////////////////////////////////////////////////////////////////
  825. //
  826. // Function: CLabel::SetLinkCursor
  827. //
  828. // Description: Sets the internet browers link
  829. //
  830. // INPUTS: Handle of cursor
  831. //
  832. // RETURNS: Reference to 'this' object
  833. //
  834. // NOTES:
  835. //
  836. // MODIFICATIONS:
  837. //
  838. // Name Date Version Comments
  839. // NT ALMOND 26/08/98 1.0 Origin
  840. //
  841. //////////////////////////////////////////////////////////////////////////
  842. CLabel& CLabel::SetLinkCursor(HCURSOR hCursor)
  843. {
  844. m_hCursor = hCursor;
  845. return *this;
  846. }
  847. //////////////////////////////////////////////////////////////////////////
  848. //
  849. // Function: CLabel::SetTransparent
  850. //
  851. // Description: Sets the Label window to be transpaent
  852. //
  853. // INPUTS: True or false
  854. //
  855. // RETURNS: Reference to 'this' object
  856. //
  857. // NOTES:
  858. //
  859. // MODIFICATIONS:
  860. //
  861. // Name Date Version Comments
  862. // NT ALMOND 22/10/98 1.0 Origin
  863. //
  864. //////////////////////////////////////////////////////////////////////////
  865. CLabel& CLabel::SetTransparent(BOOL bSet)
  866. {
  867. m_bTransparent = bSet;
  868. ModifyStyleEx(0,WS_EX_TRANSPARENT); // Fix for transparency
  869. UpdateSurface();
  870. return *this;
  871. }
  872. //////////////////////////////////////////////////////////////////////////
  873. //
  874. // Function: CLabel::SetFont3D
  875. //
  876. // Description: Sets the 3D attribute of the font.
  877. //
  878. // INPUTS: True or false, Raised or Sunken
  879. //
  880. // RETURNS: Reference to 'this' object
  881. //
  882. // NOTES:
  883. //
  884. // MODIFICATIONS:
  885. //
  886. // Name Date Version Comments
  887. // NT ALMOND 22/10/98 1.0 Origin
  888. //
  889. //////////////////////////////////////////////////////////////////////////
  890. CLabel& CLabel::SetFont3D(BOOL bSet,Type3D type)
  891. {
  892. m_bFont3d = bSet;
  893. m_3dType = type;
  894. UpdateSurface();
  895. return *this;
  896. }
  897. void CLabel::OnSysColorChange()
  898. {
  899. if (m_hwndBrush)
  900. ::DeleteObject(m_hwndBrush);
  901. m_hwndBrush = ::CreateSolidBrush(GetSysColor(COLOR_3DFACE));
  902. UpdateSurface();
  903. }
  904. //////////////////////////////////////////////////////////////////////////
  905. //
  906. // Function: CLabel::SetRotationAngle
  907. //
  908. // Description: Sets the rotation angle for the current font.
  909. //
  910. // INPUTS: Angle in Degress
  911. //
  912. // RETURNS: Reference to 'this' object
  913. //
  914. // NOTES:
  915. //
  916. // MODIFICATIONS:
  917. //
  918. // Name Date Version Comments
  919. // NT ALMOND 22/10/98 1.0 Origin
  920. //
  921. //////////////////////////////////////////////////////////////////////////
  922. CLabel& CLabel::SetRotationAngle(UINT nAngle,BOOL bRotation)
  923. {
  924. // Arrrrh...
  925. // Your looking in here why the font is rotating, aren't you?
  926. // Well try setting the font name to 'Arial' or 'Times New Roman'
  927. // Make the Angle 180 and set bRotation to true.
  928. //
  929. // Font rotation _ONLY_ works with TrueType fonts...
  930. //
  931. //
  932. m_lf.lfEscapement = m_lf.lfOrientation = (nAngle * 10);
  933. m_bRotation = bRotation;
  934. ReconstructFont();
  935. UpdateSurface();
  936. return *this;
  937. }
  938. //////////////////////////////////////////////////////////////////////////
  939. //
  940. // Function: CLabel::SetText3DHiliteColor
  941. //
  942. // Description: Sets the 3D font hilite color
  943. //
  944. // INPUTS: Color
  945. //
  946. // RETURNS: Reference to 'this' object
  947. //
  948. // NOTES:
  949. //
  950. // MODIFICATIONS:
  951. //
  952. // Name Date Version Comments
  953. // NT ALMOND 17/07/00 1.0 Origin
  954. //
  955. //////////////////////////////////////////////////////////////////////////
  956. CLabel& CLabel::SetText3DHiliteColor(COLORREF cr3DHiliteColor)
  957. {
  958. m_cr3DHiliteColor = cr3DHiliteColor;
  959. UpdateSurface();
  960. return *this;
  961. }
  962. //////////////////////////////////////////////////////////////////////////
  963. //
  964. // Function: CLabel::PreSubclassWindow
  965. //
  966. // Description: Assigns default dialog font
  967. //
  968. // INPUTS:
  969. //
  970. // RETURNS:
  971. //
  972. // NOTES:
  973. //
  974. // MODIFICATIONS:
  975. //
  976. // Name Date Version Comments
  977. // NT ALMOND 15092000 1.5 Origin
  978. // NT ALMOND 02072002 1.6 Fix crash when GetFont returns NULL
  979. //////////////////////////////////////////////////////////////////////////
  980. void CLabel::PreSubclassWindow()
  981. {
  982. CStatic::PreSubclassWindow();
  983. CFont* cf = GetFont();
  984. if(cf !=NULL)
  985. {
  986. cf->GetObject(sizeof(m_lf),&m_lf);
  987. }
  988. else
  989. {
  990. GetObject(GetStockObject(SYSTEM_FONT),sizeof(m_lf),&m_lf);
  991. }
  992. ReconstructFont();
  993. }
  994. //////////////////////////////////////////////////////////////////////////
  995. //
  996. // Function: CLabel::PreCreateWindow
  997. //
  998. // Description:
  999. //
  1000. // INPUTS:
  1001. //
  1002. // RETURNS:
  1003. //
  1004. // NOTES:
  1005. //
  1006. // MODIFICATIONS:
  1007. //
  1008. // Name Date Version Comments
  1009. // NT ALMOND 15092000 1.5 Origin
  1010. //////////////////////////////////////////////////////////////////////////
  1011. BOOL CLabel::PreCreateWindow(CREATESTRUCT& cs)
  1012. {
  1013. return CStatic::PreCreateWindow(cs);
  1014. }
  1015. //////////////////////////////////////////////////////////////////////////
  1016. //
  1017. // Function: CLabel::DrawGradientFill
  1018. //
  1019. // Description: Internal help function to gradient fill background
  1020. //
  1021. // INPUTS:
  1022. //
  1023. // RETURNS:
  1024. //
  1025. // NOTES:
  1026. //
  1027. // MODIFICATIONS:
  1028. //
  1029. // Name Date Version Comments
  1030. // NT ALMOND 15092000 1.5 Origin
  1031. //////////////////////////////////////////////////////////////////////////
  1032. void CLabel::DrawGradientFill(CDC* pDC, CRect* pRect, COLORREF crStart, COLORREF crEnd, int nSegments)
  1033. {
  1034. // Get the starting RGB values and calculate the incremental
  1035. // changes to be applied.
  1036. COLORREF cr;
  1037. int nR = GetRValue(crStart);
  1038. int nG = GetGValue(crStart);
  1039. int nB = GetBValue(crStart);
  1040. int neB = GetBValue(crEnd);
  1041. int neG = GetGValue(crEnd);
  1042. int neR = GetRValue(crEnd);
  1043. if(nSegments > pRect->Width())
  1044. nSegments = pRect->Width();
  1045. int nDiffR = (neR - nR);
  1046. int nDiffG = (neG - nG);
  1047. int nDiffB = (neB - nB);
  1048. int ndR = 256 * (nDiffR) / (max(nSegments,1));
  1049. int ndG = 256 * (nDiffG) / (max(nSegments,1));
  1050. int ndB = 256 * (nDiffB) / (max(nSegments,1));
  1051. nR *= 256;
  1052. nG *= 256;
  1053. nB *= 256;
  1054. neR *= 256;
  1055. neG *= 256;
  1056. neB *= 256;
  1057. int nCX = pRect->Width() / max(nSegments,1), nLeft = pRect->left, nRight;
  1058. pDC->SelectStockObject(NULL_PEN);
  1059. for (int i = 0; i < nSegments; i++, nR += ndR, nG += ndG, nB += ndB)
  1060. {
  1061. // Use special code for the last segment to avoid any problems
  1062. // with integer division.
  1063. if (i == (nSegments - 1))
  1064. nRight = pRect->right;
  1065. else
  1066. nRight = nLeft + nCX;
  1067. cr = RGB(nR / 256, nG / 256, nB / 256);
  1068. {
  1069. CBrush br(cr);
  1070. CBrush* pbrOld = pDC->SelectObject(&br);
  1071. pDC->Rectangle(nLeft, pRect->top, nRight + 1, pRect->bottom);
  1072. pDC->SelectObject(pbrOld);
  1073. }
  1074. // Reset the left side of the drawing rectangle.
  1075. nLeft = nRight;
  1076. }
  1077. }
  1078. //////////////////////////////////////////////////////////////////////////
  1079. //
  1080. // Function: CLabel::SetFont
  1081. //
  1082. // Description: Sets font with LOGFONT structure
  1083. //
  1084. // INPUTS:
  1085. //
  1086. // RETURNS:
  1087. //
  1088. // NOTES:
  1089. //
  1090. // MODIFICATIONS:
  1091. //
  1092. // Name Date Version Comments
  1093. // NT ALMOND 02072002 1.6 Origin
  1094. //////////////////////////////////////////////////////////////////////////
  1095. CLabel& CLabel::SetFont(LOGFONT lf)
  1096. {
  1097. CopyMemory(&m_lf, &lf, sizeof(m_lf));
  1098. ReconstructFont();
  1099. UpdateSurface();
  1100. return *this;
  1101. }
  1102. BOOL CLabel::OnEraseBkgnd(CDC* pDC)
  1103. {
  1104. // TODO: Add your message handler code here and/or call default
  1105. return TRUE;
  1106. }
  1107. //////////////////////////////////////////////////////////////////////////
  1108. //
  1109. // Function: CLabel::SetMailLink
  1110. //
  1111. // Description: Sets the label so it becomes Mail enabled
  1112. //
  1113. // INPUTS:
  1114. //
  1115. // RETURNS:
  1116. //
  1117. // NOTES:
  1118. //
  1119. // MODIFICATIONS:
  1120. //
  1121. // Name Date Version Comments
  1122. // NT ALMOND 02072002 1.6 Origin
  1123. //////////////////////////////////////////////////////////////////////////
  1124. CLabel& CLabel::SetMailLink(BOOL bEnable, BOOL bNotifyParent)
  1125. {
  1126. if (bEnable)
  1127. m_Link = MailLink;
  1128. else
  1129. m_Link = LinkNone;
  1130. m_bNotifyParent = bNotifyParent;
  1131. if (m_Link != LinkNone)
  1132. ModifyStyle(0,SS_NOTIFY);
  1133. else
  1134. ModifyStyle(SS_NOTIFY,0);
  1135. return *this;
  1136. }
  1137. //////////////////////////////////////////////////////////////////////////
  1138. //
  1139. // Function: CLabel::SetHyperLink
  1140. //
  1141. // Description: Sets the label so it becomes hyperlink enabled
  1142. //
  1143. // INPUTS:
  1144. //
  1145. // RETURNS:
  1146. //
  1147. // NOTES:
  1148. //
  1149. // MODIFICATIONS:
  1150. //
  1151. // Name Date Version Comments
  1152. // NT ALMOND 02072002 1.6 Origin
  1153. //////////////////////////////////////////////////////////////////////////
  1154. CLabel& CLabel::SetHyperLink(const CString& sLink)
  1155. {
  1156. m_sLink = sLink;
  1157. return *this;
  1158. }
  1159. /*************************************************************
  1160. *add at : 2014-08-11 by唐太闲
  1161. *describe: 设置背景透明,返回空画刷
  1162. *************************************************************/
  1163. HBRUSH CLabel::CtlColor(CDC* pDC, UINT /*nCtlColor*/)
  1164. {
  1165. // TODO: 在此更改 DC 的任何属性
  1166. // TODO: 如果不应调用父级的处理程序,则返回非 null 画笔
  1167. //return NULL;
  1168. pDC->SetBkMode(TRANSPARENT);
  1169. return (HBRUSH)GetStockObject(NULL_BRUSH);
  1170. }