/lib/CTextControl.ahk

http://github.com/Skiouros/Macro · AutoHotKey · 62 lines · 36 code · 0 blank · 26 comment · 3 complexity · 1e31d912346e09acca521175eae883e4 MD5 · raw file

  1. /*
  2. Class: CTextControl
  3. A static text control that can also be used as hyperlink.
  4. This control extends <CControl>. All basic properties and functions are implemented and documented in this class.
  5. */
  6. Class CTextControl Extends CControl
  7. {
  8. __New(Name, Options, Text, GUINum)
  9. {
  10. Base.__New(Name, Options, Text, GUINum)
  11. this.Type := "Text"
  12. this._.Insert("ControlStyles", {Center : 0x1, Left : 0, Right : 0x2, Wrap : -0xC})
  13. this._.Insert("Events", ["Click", "DoubleClick"])
  14. }
  15. /*
  16. Variable: Link
  17. If true, the control will appear like a hyperlink. To react to a click, implement the Click() event.
  18. */
  19. __Set(Name, Value)
  20. {
  21. ;~ global CGUI
  22. if(Name = "Link")
  23. {
  24. WM_SETCURSOR := 0x20
  25. WM_MOUSEMOVE := 0x200
  26. WM_NCMOUSELEAVE := 0x2A2
  27. WM_MOUSELEAVE := 0x2A3
  28. if(Value)
  29. {
  30. CGUI.GUIList[this.GUINum].OnMessage(WM_SETCURSOR, "HandleInternalMessage")
  31. CGUI.GUIList[this.GUINum].OnMessage(WM_MOUSEMOVE, "HandleInternalMessage")
  32. }
  33. this._.Link := Value > 0
  34. this.Font.Options := "cBlue"
  35. }
  36. }
  37. __Get(Name)
  38. {
  39. if(Name = "Link")
  40. return this._.Link
  41. }
  42. /*
  43. Event: Introduction
  44. To handle control events you need to create a function with this naming scheme in your window class: ControlName_EventName(params)
  45. The parameters depend on the event and there may not be params at all in some cases.
  46. Additionally it is required to create a label with this naming scheme: GUIName_ControlName
  47. GUIName is the name of the window class that extends CGUI. The label simply needs to call CGUI.HandleEvent().
  48. For better readability labels may be chained since they all execute the same code.
  49. Instead of using ControlName_EventName() you may also call <CControl.RegisterEvent> on a control instance to register a different event function name.
  50. Event: Click()
  51. Invoked when the user clicked on the control.
  52. Event: DoubleClick()
  53. Invoked when the user double-clicked on the control.
  54. */
  55. HandleEvent(Event)
  56. {
  57. this.CallEvent(Event.GUIEvent = "DoubleClick" ? "DoubleClick" : "Click")
  58. }
  59. }