/lib/CEditControl.ahk

http://github.com/Skiouros/Macro · AutoHotKey · 109 lines · 43 code · 4 blank · 62 comment · 9 complexity · 7df5603c5af2ca2cedd6ab5e308f401b MD5 · raw file

  1. /*
  2. Class: CEditControl
  3. An edit control.
  4. This control extends <CControl>. All basic properties and functions are implemented and documented in this class.
  5. */
  6. Class CEditControl Extends CControl
  7. {
  8. __New(Name, Options, Text, GUINum)
  9. {
  10. Base.__New(Name, Options, Text, GUINum)
  11. this.Type := "Edit"
  12. this._.Insert("ControlStyles", {Center : 0x1, LowerCase : 0x10, Number : 0x2000, Multi : 0x4, Password : 0x20, ReadOnly : 0x800, Right : 0x2, Uppercase : 0x8, WantReturn : 0x1000})
  13. this._.Insert("Events", ["TextChanged"])
  14. this._.Insert("Messages", {0x200 : "KillFocus", 0x100 : "SetFocus" }) ;Used for automatically registering message callbacks
  15. }
  16. /*
  17. Function: AddUpDown
  18. Adds an UpDown control to this text field. This function needs to be called immediately after adding the edit control to the window.
  19. Parameters:
  20. Min - The minimum value of the UpDown control.
  21. Max - The maximum value of the UpDown control.
  22. */
  23. AddUpDown(Min, Max)
  24. {
  25. WM_USER := 0x0400
  26. UDM_SETBUDDY := WM_USER + 105
  27. ;If this edit control belongs to a tab, set the correct tab first and unset it afterwards
  28. if(this.hParentControl && CGUI.GUIList[this.GUINum].Controls[this.hParentControl].Type = "Tab")
  29. Gui, % this.GUINum ":Tab", % this.TabNumber, % CGUI.GUIList[this.GUINum].Controls[this.hParentControl]._.TabIndex
  30. Gui, % this.GUINum ":Add", UpDown, Range%Min%-%Max% hwndhUpDown, % this.Text
  31. if(this.hParentControl && CGUI.GUIList[this.GUINum].Controls[this.hParentControl].Type = "Tab")
  32. Gui, % this.GUINum ":Tab"
  33. hwnd := this.hwnd
  34. ;~ SendMessage, UDM_SETBUDDY, hwnd, 0,, % "ahk_id " hwnd
  35. this._.UpDownHwnd := hUpDown
  36. this._.Min := Min
  37. this._.Max := Max
  38. }
  39. ;~ HWND CreateControl(const ustring& classname,const HWND hParent,DWORD extstyle, const HINSTANCE hInst,DWORD dwStyle, const RECT& rc,const int id)
  40. ;~ {
  41. ;~ dwStyle|=WS_CHILD|WS_VISIBLE;
  42. ;~ DllCall("CreateWindowEx", "UINT", extStyle, "Str", classname, "Str", "", "UINT", dwStyle, "UINT", x, "UINT", y, "UINT", w, "UINT", h, "PTR", this.hwnd, "PTR", 0, "PTR", 0, "UINT", 0
  43. ;~ return CreateWindowEx(extstyle, //extended styles
  44. ;~ classname.c_str(), //control 'class' name
  45. ;~ 0, //control caption
  46. ;~ dwStyle, //wnd style
  47. ;~ rc.left, //position: left
  48. ;~ rc.top, //position: top
  49. ;~ rc.right, //width
  50. ;~ rc.bottom, //height
  51. ;~ hParent, //parent window handle
  52. ;~ //control's ID
  53. ;~ reinterpret_cast<HMENU>(static_cast<INT_PTR>(id)),
  54. ;~ hInst, //instance
  55. ;~ 0); //user defined info
  56. ;~ }
  57. __Get(Name)
  58. {
  59. ;~ global CGUI
  60. ;~ if(Name != "GUINum" && !CGUI.GUIList[this.GUINum].IsDestroyed)
  61. ;~ {
  62. ;~ if(Name = "Text" && this._.UpDownHwnd) ;Use text from UpDown control if possible
  63. ;~ GuiControlGet, Value, % this.GUINum ":", % this.ClassNN
  64. ;~ }
  65. ;~ if(Value)
  66. ;~ return Value
  67. }
  68. /*
  69. Variable: Min
  70. If AddUpDown() has been called befored, the minimum value can be changed here.
  71. Variable: Max
  72. If AddUpDown() has been called befored, the maximum value can be changed here.
  73. */
  74. __Set(Name, Value)
  75. {
  76. ;~ global CGUI
  77. if(Name != "GUINum" && !CGUI.GUIList[this.GUINum].IsDestroyed)
  78. {
  79. if(this._.UpDownHwnd && this._.HasKey({Min : "Min", Max : "Max"}[Name]))
  80. {
  81. SendMessage, 0x400 + 111, this._.Min := (Name = "Min" ? Value : this._.Min), this._.Max := (Name = "Max" ? Value : this._.Max),,% "ahk_id " this._.UpDownHwnd
  82. return Value
  83. }
  84. }
  85. }
  86. /*
  87. Event: Introduction
  88. To handle control events you need to create a function with this naming scheme in your window class: ControlName_EventName(params)
  89. The parameters depend on the event and there may not be params at all in some cases.
  90. Additionally it is required to create a label with this naming scheme: GUIName_ControlName
  91. GUIName is the name of the window class that extends CGUI. The label simply needs to call CGUI.HandleEvent().
  92. For better readability labels may be chained since they all execute the same code.
  93. Instead of using ControlName_EventName() you may also call <CControl.RegisterEvent> on a control instance to register a different event function name.
  94. Event: TextChanged()
  95. Invoked when the text of the control is changed.
  96. */
  97. HandleEvent(Event)
  98. {
  99. this.CallEvent("TextChanged")
  100. }
  101. }