IBottomNameStrip.cs 48 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550
  1. using PaintDotNet.SystemLayer;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.ComponentModel;
  5. using System.Drawing;
  6. using System.Drawing.Drawing2D;
  7. using System.Windows.Forms;
  8. using System.Windows.Forms.VisualStyles;
  9. namespace PaintDotNet
  10. {
  11. public class IBottomNameStrip : Control
  12. {
  13. public enum ItemPart
  14. {
  15. None,
  16. Image,
  17. CloseButton
  18. }
  19. public sealed class Item
  20. {
  21. private Rectangle rectangle;
  22. private PushButtonState imageRenderState;
  23. /// <summary>
  24. /// 图片
  25. /// </summary>
  26. private Image image;
  27. /// <summary>
  28. ///
  29. /// </summary>
  30. private string name;
  31. /// <summary>
  32. /// 文字颜色
  33. /// </summary>
  34. private Color nColor;
  35. private bool selected;
  36. private PushButtonState checkRenderState;
  37. private CheckState checkState;
  38. private PushButtonState closeRenderState;
  39. private bool dirty;
  40. private bool lockedDirtyValue;
  41. private int dirtyValueLockCount = 0;
  42. /// <summary>
  43. /// Tag
  44. /// </summary>
  45. private object tag;
  46. public event EventHandler Changed;
  47. private void OnChanged()
  48. {
  49. if (Changed != null)
  50. {
  51. Changed(this, EventArgs.Empty);
  52. }
  53. }
  54. /// <summary>
  55. /// checkbox的被选中/取消选中事件
  56. /// 实际上没有用checkbox,而是自己画的,自己控制的逻辑
  57. /// </summary>
  58. public event EventHandler CheckChanged;
  59. private void OnCheckChanged()
  60. {
  61. if (CheckChanged != null)
  62. {
  63. CheckChanged(this, EventArgs.Empty);
  64. }
  65. }
  66. public Rectangle Rectangle
  67. {
  68. get
  69. {
  70. return this.rectangle;
  71. }
  72. set
  73. {
  74. this.rectangle = value;
  75. }
  76. }
  77. public string Name
  78. {
  79. get
  80. {
  81. return this.name;
  82. }
  83. set
  84. {
  85. this.name = value;
  86. OnChanged();
  87. }
  88. }
  89. public Color NColor
  90. {
  91. get
  92. {
  93. return this.nColor;
  94. }
  95. set
  96. {
  97. this.nColor = value;
  98. OnChanged();
  99. }
  100. }
  101. public Image Image
  102. {
  103. get
  104. {
  105. return this.image;
  106. }
  107. set
  108. {
  109. this.image = value;
  110. OnChanged();
  111. }
  112. }
  113. public PushButtonState ImageRenderState
  114. {
  115. get
  116. {
  117. return this.imageRenderState;
  118. }
  119. set
  120. {
  121. if (this.imageRenderState != value)
  122. {
  123. this.imageRenderState = value;
  124. OnChanged();
  125. }
  126. }
  127. }
  128. public bool Selected
  129. {
  130. get
  131. {
  132. return this.selected;
  133. }
  134. set
  135. {
  136. if (this.selected != value)
  137. {
  138. this.selected = value;
  139. OnChanged();
  140. }
  141. }
  142. }
  143. public bool Dirty
  144. {
  145. get
  146. {
  147. if (this.dirtyValueLockCount > 0)
  148. {
  149. return this.lockedDirtyValue;
  150. }
  151. else
  152. {
  153. return this.dirty;
  154. }
  155. }
  156. set
  157. {
  158. if (this.dirty != value)
  159. {
  160. this.dirty = value;
  161. if (this.dirtyValueLockCount <= 0)
  162. {
  163. OnChanged();
  164. }
  165. }
  166. }
  167. }
  168. public void LockDirtyValue(bool forceValue)
  169. {
  170. ++this.dirtyValueLockCount;
  171. if (this.dirtyValueLockCount == 1)
  172. {
  173. this.lockedDirtyValue = forceValue;
  174. }
  175. }
  176. public void UnlockDirtyValue()
  177. {
  178. --this.dirtyValueLockCount;
  179. if (this.dirtyValueLockCount == 0)
  180. {
  181. OnChanged();
  182. }
  183. else if (this.dirtyValueLockCount < 0)
  184. {
  185. throw new InvalidOperationException("Calls to UnlockDirtyValue() must be matched by a preceding call to LockDirtyValue()");
  186. }
  187. }
  188. public bool Checked
  189. {
  190. get
  191. {
  192. return (CheckState == CheckState.Checked);
  193. }
  194. set
  195. {
  196. if (value)
  197. {
  198. CheckState = CheckState.Checked;
  199. }
  200. else
  201. {
  202. CheckState = CheckState.Unchecked;
  203. }
  204. }
  205. }
  206. public CheckState CheckState
  207. {
  208. get
  209. {
  210. return this.checkState;
  211. }
  212. set
  213. {
  214. if (this.checkState != value)
  215. {
  216. this.checkState = value;
  217. OnChanged();
  218. OnCheckChanged();
  219. }
  220. }
  221. }
  222. public PushButtonState CheckRenderState
  223. {
  224. get
  225. {
  226. return this.checkRenderState;
  227. }
  228. set
  229. {
  230. if (this.checkRenderState != value)
  231. {
  232. this.checkRenderState = value;
  233. OnChanged();
  234. }
  235. }
  236. }
  237. public PushButtonState CloseRenderState
  238. {
  239. get
  240. {
  241. return this.closeRenderState;
  242. }
  243. set
  244. {
  245. if (this.closeRenderState != value)
  246. {
  247. this.closeRenderState = value;
  248. OnChanged();
  249. }
  250. }
  251. }
  252. public void SetPartRenderState(ItemPart itemPart, PushButtonState renderState)
  253. {
  254. switch (itemPart)
  255. {
  256. case ItemPart.None:
  257. break;
  258. case ItemPart.CloseButton:
  259. CloseRenderState = renderState;
  260. break;
  261. case ItemPart.Image:
  262. ImageRenderState = renderState;
  263. break;
  264. default:
  265. throw new InvalidEnumArgumentException();
  266. }
  267. }
  268. public object Tag
  269. {
  270. get
  271. {
  272. return this.tag;
  273. }
  274. set
  275. {
  276. this.tag = value;
  277. OnChanged();
  278. }
  279. }
  280. public void Update()
  281. {
  282. OnChanged();
  283. }
  284. public Item()
  285. {
  286. }
  287. public Item(Image image)
  288. {
  289. this.image = image;
  290. }
  291. }
  292. private bool managedFocus = false;
  293. private bool showScrollButtons = true;//false;
  294. private bool allowMultiChoise = true;//模式是多选模式
  295. private ArrowButton leftScrollButton;
  296. private ArrowButton rightScrollButton;
  297. private int scrollOffset = 0;
  298. private bool showCheckButtons = false;
  299. private bool showCloseButtons = false;
  300. private const int closeButtonLength = 13;
  301. private int imagePadding = 2;
  302. private int closeButtonPadding = 2;
  303. private int mouseOverIndex = -1;
  304. private ItemPart mouseOverItemPart = ItemPart.None;
  305. private bool mouseOverApplyRendering = false;
  306. private int mouseDownIndex = -1;
  307. private MouseButtons mouseDownButton = MouseButtons.None;
  308. private ItemPart mouseDownItemPart = ItemPart.None;
  309. private bool mouseDownApplyRendering = false;
  310. private bool showCheckedColor = true;
  311. private bool drawDirtyOverlay = true;
  312. public bool ShowCheckedColor
  313. {
  314. get
  315. {
  316. return this.showCheckedColor;
  317. }
  318. set
  319. {
  320. if (this.showCheckedColor != value)
  321. {
  322. this.showCheckedColor = value;
  323. Refresh();
  324. }
  325. }
  326. }
  327. public bool DrawDirtyOverlay
  328. {
  329. get
  330. {
  331. return this.drawDirtyOverlay;
  332. }
  333. set
  334. {
  335. if (this.drawDirtyOverlay != value)
  336. {
  337. this.drawDirtyOverlay = value;
  338. Refresh();
  339. }
  340. }
  341. }
  342. // This is done as an optimization: otherwise we're getting flooded with MouseMove events
  343. // and constantly refreshing our rendering. So CPU usage goes to heck.
  344. private Point lastMouseMovePt = new Point(-32000, -32000);
  345. public List<Item> items = new List<Item>();
  346. protected ArrowButton LeftScrollButton
  347. {
  348. get
  349. {
  350. return this.leftScrollButton;
  351. }
  352. }
  353. protected ArrowButton RightScrollButton
  354. {
  355. get
  356. {
  357. return this.rightScrollButton;
  358. }
  359. }
  360. private void MouseStatesToItemStates()
  361. {
  362. UI.SuspendControlPainting(this);
  363. for (int i = 0; i < this.items.Count; ++i)
  364. {
  365. this.items[i].CheckRenderState = PushButtonState.Normal;
  366. this.items[i].CloseRenderState = PushButtonState.Normal;
  367. this.items[i].ImageRenderState = PushButtonState.Normal;
  368. this.items[i].Selected = false;
  369. }
  370. if (this.mouseDownApplyRendering)
  371. {
  372. if (this.mouseDownIndex < 0 || this.mouseDownIndex >= this.items.Count)
  373. {
  374. this.mouseDownApplyRendering = false;
  375. }
  376. else
  377. {
  378. this.items[this.mouseDownIndex].SetPartRenderState(this.mouseDownItemPart, PushButtonState.Pressed);
  379. this.items[this.mouseDownIndex].Selected = true;
  380. }
  381. }
  382. else if (this.mouseOverApplyRendering)
  383. {
  384. if (this.mouseOverIndex < 0 || this.mouseOverIndex >= this.items.Count)
  385. {
  386. this.mouseOverApplyRendering = false;
  387. }
  388. else
  389. {
  390. this.items[this.mouseOverIndex].SetPartRenderState(this.mouseOverItemPart, PushButtonState.Hot);
  391. this.items[this.mouseOverIndex].Selected = true;
  392. }
  393. }
  394. UI.ResumeControlPainting(this);
  395. Invalidate();
  396. }
  397. public IBottomNameStrip()
  398. {
  399. SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.UserPaint, true);
  400. SetStyle(ControlStyles.Selectable, false);
  401. DoubleBuffered = true;
  402. ResizeRedraw = true;
  403. InitializeComponent();
  404. }
  405. private void InitializeComponent()
  406. {
  407. this.leftScrollButton = new ArrowButton();
  408. this.rightScrollButton = new ArrowButton();
  409. SuspendLayout();
  410. //
  411. // leftScrollButton
  412. //
  413. this.leftScrollButton.Name = "leftScrollButton";
  414. this.leftScrollButton.drawTransparentBackColor = false;
  415. this.leftScrollButton.ArrowDirection = ArrowDirection.Left;
  416. this.leftScrollButton.ArrowOutlineWidth = 1.0f;
  417. this.leftScrollButton.Click += new EventHandler(LeftScrollButton_Click);
  418. this.leftScrollButton.DrawWithGradient = true;
  419. //
  420. // rightScrollButton
  421. //
  422. this.rightScrollButton.Name = "rightScrollButton";
  423. this.rightScrollButton.drawTransparentBackColor = false;
  424. this.rightScrollButton.ArrowDirection = ArrowDirection.Right;
  425. this.rightScrollButton.ArrowOutlineWidth = 1.0f;
  426. this.rightScrollButton.Click += new EventHandler(RightScrollButton_Click);
  427. this.rightScrollButton.DrawWithGradient = true;
  428. //
  429. // ImageStrip
  430. //
  431. this.Name = "ImageStrip";
  432. this.TabStop = false;
  433. this.Controls.Add(this.leftScrollButton);
  434. this.Controls.Add(this.rightScrollButton);
  435. ResumeLayout();
  436. PerformLayout();
  437. }
  438. public event EventHandler<EventArgs<ArrowDirection>> ScrollArrowClicked;
  439. protected virtual void OnScrollArrowClicked(ArrowDirection arrowDirection)
  440. {
  441. if (ScrollArrowClicked != null)
  442. {
  443. ScrollArrowClicked(this, new EventArgs<ArrowDirection>(arrowDirection));
  444. }
  445. }
  446. private void LeftScrollButton_Click(object sender, EventArgs e)
  447. {
  448. Focus();
  449. OnScrollArrowClicked(ArrowDirection.Left);
  450. }
  451. private void RightScrollButton_Click(object sender, EventArgs e)
  452. {
  453. Focus();
  454. OnScrollArrowClicked(ArrowDirection.Right);
  455. }
  456. /// <summary>
  457. /// This event is raised when this control wishes to relinquish focus.
  458. /// </summary>
  459. public event EventHandler RelinquishFocus;
  460. private void OnRelinquishFocus()
  461. {
  462. if (RelinquishFocus != null)
  463. {
  464. RelinquishFocus(this, EventArgs.Empty);
  465. }
  466. }
  467. /// <summary>
  468. /// Gets or sets whether the control manages focus.
  469. /// </summary>
  470. /// <remarks>
  471. /// If this is true, the toolstrip will capture focus when the mouse enters its client area. It will then
  472. /// relinquish focus (via the RelinquishFocus event) when the mouse leaves. It will not capture or
  473. /// attempt to relinquish focus if MenuStripEx.IsAnyMenuActive returns true.
  474. /// </remarks>
  475. public bool ManagedFocus
  476. {
  477. get
  478. {
  479. return this.managedFocus;
  480. }
  481. set
  482. {
  483. this.managedFocus = value;
  484. }
  485. }
  486. public void AddItem(Item newItem)
  487. {
  488. if (this.items.Contains(newItem))
  489. {
  490. throw new ArgumentException("newItem was already added to this control");
  491. }
  492. //在这里计算名称的宽度开始 zyh
  493. //需要保证名称不能为空
  494. Size textSize = TextRenderer.MeasureText(newItem.Name, new Font(SystemFonts.DefaultFont.Name, 10, FontStyle.Regular));
  495. newItem.Rectangle = new Rectangle(0, 0, textSize.Width + 33, ClientSize.Height);
  496. //在这里计算名称的宽度结束 zyh
  497. newItem.Changed += Item_Changed;
  498. this.items.Add(newItem);
  499. PerformLayout();
  500. Invalidate();
  501. }
  502. public void RemoveItem(Item item)
  503. {
  504. if (!this.items.Contains(item))
  505. {
  506. throw new ArgumentException("item was never added to this control");
  507. }
  508. item.Changed -= Item_Changed;
  509. this.items.Remove(item);
  510. PerformLayout();
  511. Invalidate();
  512. }
  513. public void ClearItems()
  514. {
  515. SuspendLayout();
  516. UI.SuspendControlPainting(this);
  517. while (this.items.Count > 0)
  518. {
  519. RemoveItem(this.items[this.items.Count - 1]);
  520. }
  521. UI.ResumeControlPainting(this);
  522. ResumeLayout(true);
  523. Invalidate();
  524. }
  525. private void Item_Changed(object sender, EventArgs e)
  526. {
  527. Invalidate();
  528. }
  529. /// <summary>
  530. /// Raised when an item is clicked on.
  531. /// </summary>
  532. /// <remarks>
  533. /// e.Data.First is a reference to the Item.
  534. /// e.Data.Second is the ItemPart.
  535. /// e.Data.Third is the MouseButtons that was used to click on the ItemPart.
  536. /// </remarks>
  537. public event EventHandler<EventArgs<Triple<Item, ItemPart, MouseButtons>>> ItemClicked;
  538. protected virtual void OnItemClicked(Item item, ItemPart itemPart, MouseButtons mouseButtons)
  539. {
  540. if (ItemClicked != null)
  541. {
  542. ItemClicked(this, new EventArgs<Triple<Item, ItemPart, MouseButtons>>(
  543. Triple.Create(item, itemPart, mouseButtons)));
  544. }
  545. }
  546. public void PerformItemClick(int itemIndex, ItemPart itemPart, MouseButtons mouseButtons)
  547. {
  548. PerformItemClick(this.items[itemIndex], itemPart, mouseButtons);
  549. }
  550. public void PerformItemClick(Item item, ItemPart itemPart, MouseButtons mouseButtons)
  551. {
  552. OnItemClicked(item, itemPart, mouseButtons);
  553. }
  554. public Item[] Items
  555. {
  556. get
  557. {
  558. return this.items.ToArray();
  559. }
  560. }
  561. public int ItemCount
  562. {
  563. get
  564. {
  565. return this.items.Count;
  566. }
  567. }
  568. public bool AllowMultiChoise
  569. {
  570. get
  571. {
  572. return this.allowMultiChoise;
  573. }
  574. set
  575. {
  576. if (this.allowMultiChoise != value)
  577. {
  578. this.allowMultiChoise = value;
  579. PerformLayout();
  580. Invalidate(true);
  581. }
  582. }
  583. }
  584. public int MinScrollOffset
  585. {
  586. get
  587. {
  588. return 0;
  589. }
  590. }
  591. public int MaxScrollOffset
  592. {
  593. get
  594. {
  595. int itemsLength = GetAllItemWidth();//itemSize.Width * this.items.Count;
  596. int viewLength = itemsLength - ClientSize.Width;
  597. int maxScrollOffset = Math.Max(0, viewLength);
  598. return maxScrollOffset;
  599. }
  600. }
  601. public int ScrollOffset
  602. {
  603. get
  604. {
  605. return this.scrollOffset;
  606. }
  607. set
  608. {
  609. int clampedValue = Utility.Clamp(value, MinScrollOffset, MaxScrollOffset);
  610. if (this.scrollOffset != clampedValue)
  611. {
  612. this.scrollOffset = clampedValue;
  613. OnScrollOffsetChanged();
  614. Invalidate(true);
  615. }
  616. }
  617. }
  618. public event EventHandler ScrollOffsetChanged;
  619. protected virtual void OnScrollOffsetChanged()
  620. {
  621. PerformLayout();
  622. if (ScrollOffsetChanged != null)
  623. {
  624. ScrollOffsetChanged(this, EventArgs.Empty);
  625. }
  626. }
  627. /// <summary>
  628. /// 获取所有item的宽度和,
  629. /// 因为每个item和原来不一样了
  630. /// 原本item是等宽
  631. /// </summary>
  632. /// <returns></returns>
  633. public int GetAllItemWidth()
  634. {
  635. int widths = 0;
  636. for (int y = 0; y < items.Count; y++)
  637. {
  638. widths += items[y].Rectangle.Width;
  639. }
  640. return widths;
  641. }
  642. /// <summary>
  643. /// Gets the viewable area, in View coordinate space.
  644. /// </summary>
  645. public Rectangle ViewRectangle
  646. {
  647. get
  648. {
  649. Size itemSize = ItemSize;
  650. return new Rectangle(0, 0, GetAllItemWidth(), itemSize.Height);
  651. }
  652. }
  653. protected override void OnLayout(LayoutEventArgs levent)
  654. {
  655. int arrowWidth = UI.ScaleWidth(16);
  656. ScrollOffset = Utility.Clamp(this.scrollOffset, MinScrollOffset, MaxScrollOffset);
  657. // Determine arrow visibility / position
  658. this.leftScrollButton.Size = new Size(arrowWidth, ClientSize.Height);
  659. this.leftScrollButton.Location = new Point(0, 0);
  660. this.rightScrollButton.Size = new Size(arrowWidth, ClientSize.Height);
  661. this.rightScrollButton.Location = new Point(ClientSize.Width - this.rightScrollButton.Width, 0);
  662. bool showEitherButton = this.showScrollButtons && (this.ViewRectangle.Width > ClientRectangle.Width);
  663. bool showRightButton = (this.scrollOffset < MaxScrollOffset) && showEitherButton;
  664. bool showLeftButton = (this.scrollOffset > MinScrollOffset) && showEitherButton;
  665. this.rightScrollButton.Enabled = showRightButton;
  666. this.rightScrollButton.Visible = showRightButton;
  667. this.leftScrollButton.Enabled = showLeftButton;
  668. this.leftScrollButton.Visible = showLeftButton;
  669. base.OnLayout(levent);
  670. }
  671. public bool ShowCheckButtons
  672. {
  673. get
  674. {
  675. return this.showCheckButtons;
  676. }
  677. set
  678. {
  679. if (this.showCheckButtons != value)
  680. {
  681. this.showCheckButtons = value;
  682. PerformLayout();
  683. Invalidate();
  684. }
  685. }
  686. }
  687. public bool ShowCloseButtons
  688. {
  689. get
  690. {
  691. return this.showCloseButtons;
  692. }
  693. set
  694. {
  695. if (this.showCloseButtons != value)
  696. {
  697. this.showCloseButtons = value;
  698. PerformLayout();
  699. Invalidate();
  700. }
  701. }
  702. }
  703. public int PreferredMinClientWidth
  704. {
  705. get
  706. {
  707. if (this.items.Count == 0)
  708. {
  709. return 0;
  710. }
  711. int minWidth = ItemSize.Width;
  712. if (this.leftScrollButton.Visible || this.rightScrollButton.Visible)
  713. {
  714. minWidth += this.leftScrollButton.Width;
  715. minWidth += this.rightScrollButton.Width;
  716. }
  717. minWidth = Math.Min(minWidth, ViewRectangle.Width);
  718. return minWidth;
  719. }
  720. }
  721. public Size PreferredImageSize
  722. {
  723. get
  724. {
  725. Rectangle itemRect;
  726. MeasureItemPartRectangles(out itemRect, null);
  727. return new Size(itemRect.Width - imagePadding * 2, itemRect.Height - imagePadding * 2);
  728. }
  729. }
  730. public Size ItemSize
  731. {
  732. get
  733. {
  734. Rectangle itemRect;
  735. MeasureItemPartRectangles(out itemRect, null);
  736. return itemRect.Size;
  737. }
  738. }
  739. protected virtual void DrawItemBackground(Graphics g, Item item, Rectangle itemRect)
  740. {
  741. }
  742. protected virtual void DrawItemHighlight(
  743. Graphics g,
  744. Item item,
  745. Rectangle itemRect,
  746. Rectangle highlightRect)
  747. {
  748. Color backFillColor;
  749. Color outlineColor;
  750. Color textColor;
  751. if (item.Checked && this.showCheckedColor)
  752. {
  753. backFillColor = Color.FromArgb(192, SystemColors.Highlight);
  754. outlineColor = backFillColor;
  755. textColor = Color.White;
  756. }
  757. else if (item.Selected)
  758. {
  759. backFillColor = Color.FromArgb(64, SystemColors.HotTrack);
  760. outlineColor = Color.FromArgb(64, SystemColors.HotTrack);
  761. textColor = Color.Black;
  762. }
  763. else
  764. {
  765. backFillColor = Color.Transparent;
  766. outlineColor = Color.Transparent;
  767. textColor = Color.Black;
  768. }
  769. using (SolidBrush backFillBrush = new SolidBrush(backFillColor))
  770. {
  771. g.FillRectangle(backFillBrush, highlightRect);
  772. }
  773. using (Pen outlinePen = new Pen(outlineColor))
  774. {
  775. g.DrawRectangle(outlinePen, highlightRect.X, highlightRect.Y, highlightRect.Width - 1, highlightRect.Height - 1);
  776. }
  777. CheckBoxRenderer.DrawCheckBox(g, new Point(itemRect.X + 10, itemRect.Y + 10), (item.Checked && !this.showCheckedColor) ? CheckBoxState.CheckedNormal : CheckBoxState.UncheckedNormal);
  778. //CheckBoxRenderer.dr
  779. g.DrawString(item.Name, new Font(SystemFonts.DefaultFont.Name, 10, FontStyle.Regular), new SolidBrush(item.NColor != null ? item.NColor : textColor), new PointF(itemRect.X + 24, itemRect.Y + 10));
  780. g.DrawLine(new Pen(Color.FromArgb(189, 189, 189)), itemRect.X + itemRect.Width - 1, itemRect.Y, itemRect.X + itemRect.Width - 1, itemRect.Y + 25);
  781. }
  782. protected virtual void DrawItemCloseButton(
  783. Graphics g,
  784. Item item,
  785. Rectangle itemRect,
  786. Rectangle closeButtonRect)
  787. {
  788. if (item.Checked && item.Selected)
  789. {
  790. const string resourceNamePrefix = "Images.ImageStrip.CloseButton.";
  791. const string resourceNameSuffix = ".png";
  792. string resourceNameInfix = item.CloseRenderState.ToString();
  793. string resourceName = resourceNamePrefix + resourceNameInfix + resourceNameSuffix;
  794. ImageResource imageResource = PdnResources.GetImageResource(resourceName);
  795. Image image = imageResource.Reference;
  796. g.SmoothingMode = SmoothingMode.AntiAlias;
  797. g.InterpolationMode = InterpolationMode.HighQualityBicubic;
  798. g.DrawImage(image, closeButtonRect, new Rectangle(0, 0, image.Width, image.Width), GraphicsUnit.Pixel);
  799. }
  800. }
  801. protected virtual void DrawItemDirtyOverlay(
  802. Graphics g,
  803. Item item,
  804. Rectangle itemRect,
  805. Rectangle dirtyOverlayRect)
  806. {
  807. Color outerPenColor = Color.White;
  808. Color innerPenColor = Color.Orange;
  809. const int xInset = 2;
  810. int scaledXInset = UI.ScaleWidth(xInset);
  811. const float outerPenWidth = 4.0f;
  812. const float innerPenWidth = 2.0f;
  813. float scaledOuterPenWidth = UI.ScaleWidth(outerPenWidth);
  814. float scaledInnerPenWidth = UI.ScaleWidth(innerPenWidth);
  815. SmoothingMode oldSM = g.SmoothingMode;
  816. g.SmoothingMode = SmoothingMode.AntiAlias;
  817. int left = dirtyOverlayRect.Left + scaledXInset;
  818. int top = dirtyOverlayRect.Top + scaledXInset;
  819. int right = dirtyOverlayRect.Right - scaledXInset;
  820. int bottom = dirtyOverlayRect.Bottom - scaledXInset;
  821. float r = Math.Min((right - left) / 2.0f, (bottom - top) / 2.0f);
  822. PointF centerPt = new PointF((left + right) / 2.0f, (top + bottom) / 2.0f);
  823. float twoPiOver5 = (float)(Math.PI * 0.4);
  824. PointF a = new PointF(centerPt.X + r * (float)Math.Sin(twoPiOver5), centerPt.Y - r * (float)Math.Cos(twoPiOver5));
  825. PointF b = new PointF(centerPt.X + r * (float)Math.Sin(2 * twoPiOver5), centerPt.Y - r * (float)Math.Cos(2 * twoPiOver5));
  826. PointF c = new PointF(centerPt.X + r * (float)Math.Sin(3 * twoPiOver5), centerPt.Y - r * (float)Math.Cos(3 * twoPiOver5));
  827. PointF d = new PointF(centerPt.X + r * (float)Math.Sin(4 * twoPiOver5), centerPt.Y - r * (float)Math.Cos(4 * twoPiOver5));
  828. PointF e = new PointF(centerPt.X + r * (float)Math.Sin(5 * twoPiOver5), centerPt.Y - r * (float)Math.Cos(5 * twoPiOver5));
  829. PointF[] lines =
  830. new PointF[]
  831. {
  832. centerPt, a,
  833. centerPt, b,
  834. centerPt, c,
  835. centerPt, d,
  836. centerPt, e
  837. };
  838. using (Pen outerPen = new Pen(outerPenColor, scaledOuterPenWidth))
  839. {
  840. for (int i = 0; i < lines.Length; i += 2)
  841. {
  842. g.DrawLine(outerPen, lines[i], lines[i + 1]);
  843. }
  844. }
  845. using (Pen innerPen = new Pen(innerPenColor, scaledInnerPenWidth))
  846. {
  847. for (int i = 0; i < lines.Length; i += 2)
  848. {
  849. g.DrawLine(innerPen, lines[i], lines[i + 1]);
  850. }
  851. }
  852. g.SmoothingMode = oldSM;
  853. }
  854. private void DrawItem(Graphics g, Item item, Point offset)
  855. {
  856. Rectangle itemRect;
  857. //Rectangle checkButtonRect;
  858. Rectangle closeButtonRect;
  859. Rectangle dirtyOverlayRect;
  860. MeasureItemPartRectangles(
  861. item,
  862. out itemRect,
  863. out closeButtonRect,
  864. out dirtyOverlayRect);
  865. itemRect.X += offset.X;
  866. itemRect.Y += offset.Y;
  867. closeButtonRect.X += offset.X;
  868. closeButtonRect.Y += offset.Y;
  869. dirtyOverlayRect.X += offset.X;
  870. dirtyOverlayRect.Y += offset.Y;
  871. DrawItemBackground(g, item, itemRect);
  872. Rectangle highlightRect = itemRect;
  873. DrawItemHighlight(g, item, itemRect, highlightRect);
  874. if (this.showCloseButtons)
  875. {
  876. DrawItemCloseButton(g, item, itemRect, closeButtonRect);
  877. }
  878. if (this.drawDirtyOverlay && item.Dirty)
  879. {
  880. DrawItemDirtyOverlay(g, item, itemRect, dirtyOverlayRect);
  881. }
  882. }
  883. public Point ClientPointToViewPoint(Point clientPt)
  884. {
  885. int viewX = clientPt.X + this.scrollOffset;
  886. return new Point(viewX, clientPt.Y);
  887. }
  888. public Rectangle ClientRectangleToViewRectangle(Rectangle clientRect)
  889. {
  890. Point viewPt = ClientPointToViewPoint(clientRect.Location);
  891. return new Rectangle(viewPt, clientRect.Size);
  892. }
  893. public Point ViewPointToClientPoint(Point viewPt)
  894. {
  895. int clientX = viewPt.X - this.scrollOffset;
  896. return new Point(clientX, viewPt.Y);
  897. }
  898. public Rectangle ViewRectangleToClientRectangle(Rectangle viewRect)
  899. {
  900. Point clientPt = ViewPointToClientPoint(viewRect.Location);
  901. return new Rectangle(clientPt, viewRect.Size);
  902. }
  903. private Point ViewPointToItemPoint(int itemIndex, Point viewPt)
  904. {
  905. Rectangle itemRect = ItemIndexToItemViewRectangle(itemIndex);
  906. Point itemPt = new Point(viewPt.X - itemRect.X, viewPt.Y);
  907. return itemPt;
  908. }
  909. private Rectangle ItemIndexToItemViewRectangle(int itemIndex)
  910. {
  911. return items[itemIndex].Rectangle;
  912. //Size itemSize = ItemSize;
  913. //return new Rectangle(itemSize.Width * itemIndex, itemSize.Height, itemSize.Width, itemSize.Height);
  914. }
  915. public int ViewPointToItemIndex(Point viewPt)
  916. {
  917. if (!ViewRectangle.Contains(viewPt))
  918. {
  919. return -1;
  920. }
  921. int index = -1;// viewPt.X / itemSize.Width;
  922. int width = 0;
  923. //循环所有item,判断是第几个
  924. for (int i = 0; i < items.Count; i++)
  925. {
  926. if (viewPt.X >= items[i].Rectangle.X + width &&
  927. viewPt.X < items[i].Rectangle.X + width + items[i].Rectangle.Width)
  928. {
  929. index = i;
  930. break;
  931. }
  932. width += items[i].Rectangle.Width;
  933. }
  934. return index;
  935. }
  936. private void MeasureItemPartRectangles(
  937. out Rectangle itemRect,
  938. Item item)
  939. {
  940. //CheckBoxRenderer
  941. Size textSize = new Size(0, 0);
  942. if (item != null)
  943. textSize = /*CheckBoxRenderer*/TextRenderer.MeasureText(item.Name, new Font(SystemFonts.DefaultFont.Name, 10, FontStyle.Regular));
  944. itemRect = new Rectangle(
  945. 0,
  946. 0,
  947. textSize.Width == 0 ? 120 : textSize.Width + 33,//120,//ClientSize.Height
  948. ClientSize.Height);
  949. if (item != null)
  950. item.Rectangle = itemRect;
  951. }
  952. /// <summary>
  953. /// 计算位置,关闭按钮、修改标记
  954. /// </summary>
  955. /// <param name="item"></param>
  956. /// <param name="itemRect"></param>
  957. /// <param name="closeButtonRect"></param>
  958. /// <param name="dirtyOverlayRect"></param>
  959. private void MeasureItemPartRectangles(
  960. Item item,
  961. out Rectangle itemRect,
  962. out Rectangle closeButtonRect,
  963. out Rectangle dirtyOverlayRect)
  964. {
  965. MeasureItemPartRectangles(out itemRect, item);
  966. int scaledCloseButtonLength = UI.ScaleWidth(closeButtonLength);
  967. int scaledCloseButtonPadding = UI.ScaleWidth(closeButtonPadding);
  968. closeButtonRect = new Rectangle(
  969. itemRect.Width - scaledCloseButtonLength - scaledCloseButtonPadding,
  970. scaledCloseButtonPadding,
  971. scaledCloseButtonLength,
  972. scaledCloseButtonLength);
  973. dirtyOverlayRect = new Rectangle(
  974. scaledCloseButtonPadding,
  975. scaledCloseButtonPadding,
  976. scaledCloseButtonLength,
  977. scaledCloseButtonLength);
  978. }
  979. private ItemPart ItemPointToItemPart(Item item, Point pt)
  980. {
  981. Rectangle itemRect;
  982. Rectangle closeButtonRect;
  983. Rectangle dirtyOverlayRect;
  984. MeasureItemPartRectangles(
  985. item,
  986. out itemRect,
  987. out closeButtonRect,
  988. out dirtyOverlayRect);
  989. //判断是否是点击了关闭按钮
  990. int dhud = 0;
  991. int index = items.FindIndex(a => a == item);
  992. if (index > 0)
  993. {
  994. dhud = GetZeroToIndexWidth(index - 1);
  995. }
  996. closeButtonRect.X += dhud;
  997. if (closeButtonRect.Contains(pt))
  998. {
  999. return ItemPart.CloseButton;
  1000. }
  1001. int width = 0;
  1002. bool isPart = false;
  1003. //循环所有item,判断是第几个
  1004. for (int i = 0; i < items.Count; i++)
  1005. {
  1006. if (pt.X >= items[i].Rectangle.X + width &&
  1007. pt.X < items[i].Rectangle.X + width + items[i].Rectangle.Width)
  1008. {
  1009. isPart = true;
  1010. break;
  1011. }
  1012. width += items[i].Rectangle.Width;
  1013. }
  1014. if (isPart)
  1015. {
  1016. return ItemPart.Image;
  1017. }
  1018. return ItemPart.None;
  1019. }
  1020. private int GetZeroToIndexWidth(int index)
  1021. {
  1022. int m = 0;
  1023. for (int i = 0; i < items.Count; i++)
  1024. {
  1025. if (i <= index)
  1026. m += items[i].Rectangle.Width;
  1027. }
  1028. return m;
  1029. }
  1030. private Rectangle ItemIndexToClientRect(int itemIndex)
  1031. {
  1032. Size itemSize = ItemSize;
  1033. Rectangle clientRect = new Rectangle(
  1034. GetZeroToIndexWidth(itemIndex),//itemSize.Width * itemIndex,
  1035. 0,
  1036. itemIndex < 0 ? itemSize.Width : items[itemIndex].Rectangle.Width,//itemSize.Width,
  1037. itemSize.Height);
  1038. return clientRect;
  1039. }
  1040. /// <summary>
  1041. /// 计算偏移量
  1042. /// </summary>
  1043. /// <param name="itemIndex">下标</param>
  1044. /// <param name="minOffset">最小偏移</param>
  1045. /// <param name="maxOffset">最大偏移</param>
  1046. /// <param name="minFullyShownOffset"></param>
  1047. /// <param name="maxFullyShownOffset"></param>
  1048. private void CalculateVisibleScrollOffsets(
  1049. int itemIndex,
  1050. out int minOffset,
  1051. out int maxOffset,
  1052. out int minFullyShownOffset,
  1053. out int maxFullyShownOffset)
  1054. {
  1055. Rectangle itemClientRect = ItemIndexToClientRect(itemIndex);
  1056. minOffset = itemClientRect.Left + 1 - ClientSize.Width;
  1057. maxOffset = itemClientRect.Right - 1;
  1058. minFullyShownOffset = itemClientRect.Right - ClientSize.Width;
  1059. maxFullyShownOffset = itemClientRect.Left;
  1060. if (this.leftScrollButton.Visible)
  1061. {
  1062. maxOffset -= this.leftScrollButton.Width;
  1063. maxFullyShownOffset -= this.leftScrollButton.Width;
  1064. }
  1065. if (this.rightScrollButton.Visible)
  1066. {
  1067. minOffset += this.rightScrollButton.Width;
  1068. minFullyShownOffset += this.rightScrollButton.Width;
  1069. }
  1070. }
  1071. public Rectangle ScrolledViewRect
  1072. {
  1073. get
  1074. {
  1075. return new Rectangle(this.scrollOffset, 0, ClientSize.Width, ClientSize.Height);
  1076. }
  1077. }
  1078. /// <summary>
  1079. /// 判断item是否显示
  1080. /// </summary>
  1081. /// <param name="index"></param>
  1082. /// <returns></returns>
  1083. public bool IsItemVisible(int index)
  1084. {
  1085. Rectangle itemRect = ItemIndexToClientRect(index);
  1086. Rectangle intersect = Rectangle.Intersect(itemRect, ScrolledViewRect);
  1087. return (intersect.Width > 0 || intersect.Height > 0);
  1088. }
  1089. public bool IsItemFullyVisible(int index)
  1090. {
  1091. Rectangle itemRect = ItemIndexToClientRect(index);
  1092. Rectangle svRect = ScrolledViewRect;
  1093. if (this.leftScrollButton.Visible)
  1094. {
  1095. svRect.X += this.leftScrollButton.Width;
  1096. svRect.Width -= this.leftScrollButton.Width;
  1097. }
  1098. if (this.rightScrollButton.Visible)
  1099. {
  1100. svRect.Width -= this.rightScrollButton.Width;
  1101. }
  1102. Rectangle intersect = Rectangle.Intersect(itemRect, svRect);
  1103. return (intersect == itemRect);
  1104. }
  1105. public void EnsureItemFullyVisible(Item item)
  1106. {
  1107. int index = this.items.IndexOf(item);
  1108. EnsureItemFullyVisible(index);
  1109. }
  1110. public void EnsureItemFullyVisible(int index)
  1111. {
  1112. if (IsItemFullyVisible(index))
  1113. {
  1114. return;
  1115. }
  1116. int minOffset;
  1117. int maxOffset;
  1118. int minFullyShownOffset;
  1119. int maxFullyShownOffset;
  1120. CalculateVisibleScrollOffsets(index, out minOffset, out maxOffset,
  1121. out minFullyShownOffset, out maxFullyShownOffset);
  1122. // Pick the offset that moves the image the fewest number of pixels
  1123. int oldOffset = this.scrollOffset;
  1124. int dxMin = Math.Abs(oldOffset - minFullyShownOffset);
  1125. int dxMax = Math.Abs(oldOffset - maxFullyShownOffset);
  1126. if (dxMin <= dxMax)
  1127. {
  1128. this.ScrollOffset = minFullyShownOffset;
  1129. }
  1130. else
  1131. {
  1132. this.ScrollOffset = maxFullyShownOffset;
  1133. }
  1134. }
  1135. private void ForceMouseMove()
  1136. {
  1137. Point clientPt = PointToClient(Control.MousePosition);
  1138. this.lastMouseMovePt = new Point(this.lastMouseMovePt.X + 1, this.lastMouseMovePt.Y + 1);
  1139. MouseEventArgs me = new MouseEventArgs(MouseButtons.None, 0, clientPt.X, clientPt.Y, 0);
  1140. OnMouseMove(me);
  1141. }
  1142. private void GetFocus()
  1143. {
  1144. if (this.managedFocus && !MenuStripEx.IsAnyMenuActive && UI.IsOurAppActive)
  1145. {
  1146. this.Focus();
  1147. }
  1148. }
  1149. #region 绘制、鼠标进入、离开、按下、移动、抬起、滚轮事件
  1150. protected override void OnPaint(PaintEventArgs e)
  1151. {
  1152. if (UI.IsControlPaintingEnabled(this))
  1153. {
  1154. if (this.items != null && this.items.Count > 0)
  1155. {
  1156. Size itemSize = ItemSize;
  1157. Rectangle firstItemRect = new Rectangle(-this.scrollOffset, 0, items[0].Rectangle.Width, itemSize.Height);
  1158. for (int i = 0; i < this.items.Count; ++i)
  1159. {
  1160. //if (IsItemVisible(i)) //暂时注释掉,在观察
  1161. {
  1162. Point itemOffset = new Point(firstItemRect.X + GetZeroToIndexWidth(i - 1), firstItemRect.Y);
  1163. //Point itemOffset = new Point(firstItemRect.X + itemSize.Width * i, firstItemRect.Y);
  1164. DrawItem(e.Graphics, this.items[i], itemOffset);
  1165. }
  1166. }
  1167. }
  1168. }
  1169. base.OnPaint(e);
  1170. }
  1171. protected override void OnMouseDown(MouseEventArgs e)
  1172. {
  1173. if (this.mouseDownButton == MouseButtons.None)
  1174. {
  1175. Point clientPt = new Point(e.X, e.Y);
  1176. Point viewPt = ClientPointToViewPoint(clientPt);
  1177. int itemIndex = ViewPointToItemIndex(viewPt);
  1178. if (itemIndex >= 0 && itemIndex < this.items.Count)
  1179. {
  1180. Item item = this.items[itemIndex];
  1181. Point itemPt = ViewPointToItemPoint(itemIndex, viewPt);
  1182. ItemPart itemPart = ItemPointToItemPart(item, itemPt);
  1183. if (itemPart == ItemPart.Image)
  1184. {
  1185. OnItemClicked(item, itemPart, e.Button);
  1186. this.mouseDownApplyRendering = false;
  1187. this.mouseOverIndex = itemIndex;
  1188. this.mouseOverItemPart = itemPart;
  1189. this.mouseOverApplyRendering = true;
  1190. }
  1191. else
  1192. {
  1193. this.mouseDownIndex = itemIndex;
  1194. this.mouseDownItemPart = itemPart;
  1195. this.mouseDownButton = e.Button;
  1196. this.mouseDownApplyRendering = true;
  1197. this.mouseOverApplyRendering = false;
  1198. }
  1199. MouseStatesToItemStates();
  1200. Refresh();
  1201. }
  1202. }
  1203. base.OnMouseDown(e);
  1204. }
  1205. protected override void OnMouseMove(MouseEventArgs e)
  1206. {
  1207. GetFocus();
  1208. Point clientPt = new Point(e.X, e.Y);
  1209. if (clientPt != this.lastMouseMovePt)
  1210. {
  1211. Point viewPt = ClientPointToViewPoint(clientPt);
  1212. int itemIndex = ViewPointToItemIndex(viewPt);
  1213. if (this.mouseDownButton == MouseButtons.None)
  1214. {
  1215. if (itemIndex >= 0 && itemIndex < this.items.Count)
  1216. {
  1217. Item item = this.items[itemIndex];
  1218. Point itemPt = ViewPointToItemPoint(itemIndex, viewPt);
  1219. ItemPart itemPart = ItemPointToItemPart(item, itemPt);
  1220. this.mouseOverIndex = itemIndex;
  1221. this.mouseOverItemPart = itemPart;
  1222. this.mouseOverApplyRendering = true;
  1223. }
  1224. else
  1225. {
  1226. this.mouseOverApplyRendering = false;
  1227. }
  1228. }
  1229. else
  1230. {
  1231. this.mouseOverApplyRendering = false;
  1232. if (itemIndex != this.mouseDownIndex)
  1233. {
  1234. this.mouseDownApplyRendering = false;
  1235. }
  1236. else if (itemIndex < 0 || itemIndex >= this.items.Count)
  1237. {
  1238. this.mouseDownApplyRendering = false;
  1239. }
  1240. else
  1241. {
  1242. Item item = this.Items[itemIndex];
  1243. Point itemPt = ViewPointToItemPoint(itemIndex, viewPt);
  1244. ItemPart itemPart = ItemPointToItemPart(item, itemPt);
  1245. if (itemPart != this.mouseDownItemPart)
  1246. {
  1247. this.mouseDownApplyRendering = false;
  1248. }
  1249. }
  1250. }
  1251. MouseStatesToItemStates();
  1252. Refresh();
  1253. }
  1254. this.lastMouseMovePt = clientPt;
  1255. base.OnMouseMove(e);
  1256. }
  1257. protected override void OnMouseUp(MouseEventArgs e)
  1258. {
  1259. bool raisedClickEvent = false;
  1260. if (this.mouseDownButton == e.Button)
  1261. {
  1262. Point clientPt = new Point(e.X, e.Y);
  1263. Point viewPt = ClientPointToViewPoint(clientPt);
  1264. int itemIndex = ViewPointToItemIndex(viewPt);
  1265. if (itemIndex >= 0 && itemIndex < this.items.Count)
  1266. {
  1267. Item item = this.items[itemIndex];
  1268. Point itemPt = ViewPointToItemPoint(itemIndex, viewPt);
  1269. ItemPart itemPart = ItemPointToItemPart(item, itemPt);
  1270. if (itemIndex == this.mouseDownIndex && itemPart == this.mouseDownItemPart)
  1271. {
  1272. if (itemPart == ItemPart.CloseButton && !item.Checked)
  1273. {
  1274. // Can only close 'checked' images, just like how tab switching+closing works in IE7
  1275. itemPart = ItemPart.Image;
  1276. }
  1277. OnItemClicked(item, itemPart, this.mouseDownButton);
  1278. raisedClickEvent = true;
  1279. }
  1280. this.mouseOverApplyRendering = true;
  1281. this.mouseOverItemPart = itemPart;
  1282. this.mouseOverIndex = itemIndex;
  1283. }
  1284. this.mouseDownApplyRendering = false;
  1285. this.mouseDownButton = MouseButtons.None;
  1286. MouseStatesToItemStates();
  1287. Refresh();
  1288. }
  1289. if (raisedClickEvent)
  1290. {
  1291. ForceMouseMove();
  1292. }
  1293. base.OnMouseUp(e);
  1294. }
  1295. protected override void OnMouseWheel(MouseEventArgs e)
  1296. {
  1297. float count = (float)e.Delta / SystemInformation.MouseWheelScrollDelta;
  1298. int pixels = GetAllItemWidth();//(int)(count * ItemSize.Width);
  1299. int newSO = ScrollOffset - pixels;
  1300. ScrollOffset = newSO;
  1301. ForceMouseMove();
  1302. base.OnMouseWheel(e);
  1303. }
  1304. protected override void OnMouseEnter(EventArgs e)
  1305. {
  1306. GetFocus();
  1307. base.OnMouseEnter(e);
  1308. }
  1309. protected override void OnMouseLeave(EventArgs e)
  1310. {
  1311. this.mouseDownApplyRendering = false;
  1312. this.mouseOverApplyRendering = false;
  1313. MouseStatesToItemStates();
  1314. Refresh();
  1315. if (this.managedFocus && !MenuStripEx.IsAnyMenuActive && UI.IsOurAppActive)
  1316. {
  1317. OnRelinquishFocus();
  1318. }
  1319. base.OnMouseLeave(e);
  1320. }
  1321. #endregion
  1322. }
  1323. }