PageRenderTime 10ms CodeModel.GetById 1ms app.highlight 3ms RepoModel.GetById 1ms app.codeStats 1ms

/lib/CEditControl.ahk

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