Skip to content

Commit

Permalink
Added a missing event handler to CChoiceControl.ahk
Browse files Browse the repository at this point in the history
Made some arguments in AddControl() optional
Modified x,y and Position properties to represent coordinates of window on screen instead of client
Added WindowWidth/WindowHeight/WindowSize
Added functions to convert points between client<->window and client<->screen.
  • Loading branch information
ChrisS85 committed Apr 24, 2012
1 parent a7588f8 commit 63022bb
Show file tree
Hide file tree
Showing 2 changed files with 117 additions and 23 deletions.
12 changes: 10 additions & 2 deletions CChoiceControl.ahk
Expand Up @@ -7,6 +7,7 @@ This control extends <CControl>. All basic properties and functions are implemen
Class CChoiceControl Extends CControl ;This class is a ComboBox, ListBox and DropDownList
{
SelectionChanged := new EventHandler()
DoubleClick := new EventHandler()
__New(Name, Options, Text, GUINum, Type)
{
Base.__New(Name, Options, Text, GUINum)
Expand Down Expand Up @@ -206,11 +207,18 @@ Class CChoiceControl Extends CControl ;This class is a ComboBox, ListBox and Dro
Event: SelectionChanged(SelectedItem)
Invoked when the selection was changed.
Event: DoubleClick(Item)
Invoked when an item in a ListBox is double-clicked.
*/
HandleEvent(Event)
{
this.ProcessSubControlState(this._.PreviouslySelectedItem, this.SelectedItem)
this.CallEvent("SelectionChanged", this.SelectedItem)
if(this._.PreviouslySelectedItem != this.SelectedItem)
this.ProcessSubControlState(this._.PreviouslySelectedItem, this.SelectedItem)
if(Event.GUIEvent = "DoubleClick")
this.CallEvent("DoubleClick", this.SelectedItem)
else
this.CallEvent("SelectionChanged", this.SelectedItem)
this._.PreviouslySelectedItem := this.SelectedItem
}
/*
Expand Down
128 changes: 107 additions & 21 deletions CGUI.ahk
Expand Up @@ -50,6 +50,17 @@ Class CGUI
;Used for keeping track of the window size. Until the window is shown for the first time or manual size is set
;it will keep updating the size of the (invisible) window when new controls are added.
_Initialized := false

/*
Event Handler: OnClose(Source)
Invoked when the window is closed (hidden or destroyed).
Event Handler: OnDestroy(Source)
Invoked when the window is destroyed.
*/
OnClose := new EventHandler()
OnDestroy := new EventHandler()

__New(instance)
{
if(!CGUI_Assert(IsObject(instance) && !instance.HasKey("hwnd"), "CGUI constructor must not be called!"))
Expand Down Expand Up @@ -238,7 +249,10 @@ Class CGUI
Gui, % this.GUINum ":Destroy"
;Call PostDestroy function
if(IsFunc(this.PostDestroy))
{
this.PostDestroy()
this.OnDestroy.(this)
}
}

/*
Expand Down Expand Up @@ -459,7 +473,7 @@ Class CGUI
Returns: The created control object
*/
AddControl(Control, Name, Options, Text, ControlList="", ParentControl = "")
AddControl(Control, Name, Options = "", Text = "", ControlList="", ParentControl = "")
{
local hControl, type, testHWND, vName, NeedsGLabel
if(this.IsDestroyed)
Expand Down Expand Up @@ -581,24 +595,33 @@ Class CGUI
Property: IsDestroyed
True if the window has been destroyed and this object is not usable anymore.
Property: x
x-Position of the window.
Property: X
x-Position of the window (including its border) in screen coordinates.
Property: y
y-Position of the window.
Property: Y
y-Position of the window (including its border) in screen coordinates.
Property: width
Width of the window.
Property: Width
Width of the client area of the window.
Property: height
Height of the window.
Property: Height
Height of the client area of the window.
Property: WindowWidth
Width of the window.
Property: WindowHeight
Height of the window.
Property: Position
An object containing the x and y values. They can not be set separately through this object, only both at once.
An object containing the X and Y properties. They can not be set separately through this object, only both at once.
Property: Size
An object containing the width and height values. They can not be set separately through this object, only both at once.
An object containing the Width and Height values. They can not be set separately through this object, only both at once.
Property: WindowSize
An object containing the WindowWidth and WindowHeight values. They can not be set separately through this object, only both at once.
Property: Title
The window title.
Expand Down Expand Up @@ -703,24 +726,38 @@ Class CGUI
}
else if(Name != "IsDestroyed" && !this.IsDestroyed)
{
if Name in x,y,width,height
if Name in width,height
{
VarSetCapacity(rc, 16)
DllCall("GetClientRect", "PTR", this.hwnd, "PTR", &rc, "UINT")
Value := NumGet(rc, {x : 0, y : 4, width : 8, height : 12}[Name], "int")
}
else if Name in X,Y
{
WinGetPos, X, Y, , , % "ahk_id " this.hwnd
return Name = "X" ? X : Y
}
else if(Name = "Position")
{
VarSetCapacity(rc, 16)
DllCall("GetClientRect", "PTR", this.hwnd, "PTRP", rc, "UINT")
Value := {x : NumGet(rc, 0, "int"), y : NumGet(rc, 4, "int")}
WinGetPos, X, Y, , , % "ahk_id " this.hwnd
Value := {x : X, y : Y}
}
else if Name in WindowWidth,WindowHeight
{
WinGetPos, , , Width, Height, % "ahk_id " this.hwnd
return Name = "WindowWidth" ? Width : Height
}
else if(Name = "Size")
{
VarSetCapacity(rc, 16)
DllCall("GetClientRect", "PTR", this.hwnd, "PTRP", rc, "UINT")
Value := {width : NumGet(rc, 8, "int"), height : NumGet(rc, 12, "int")}
}
else if(Name = "WindowSize")
{
WinGetPos, , , Width, Height, % "ahk_id " this.hwnd
return {Width : Width, Height : Height}
}
else if(Name = "Title")
WinGetTitle, Value, % "ahk_id " this.hwnd
else if Name in Style,ExStyle,TransColor,Transparent,MinMax
Expand Down Expand Up @@ -853,10 +890,10 @@ Class CGUI
WinSet, Region, %Value%, % "ahk_id " this.hwnd
this._.Region := Value
}
else if Name in x,y,width,height
else if Name in x,y,WindowWidth,WindowHeight
{
WinMove,% "ahk_id " this.hwnd,,% Name = "x" ? Value : "", % Name = "y" ? Value : "", % Name = "width" ? Value : "", % Name = "height" ? Value : ""
if(Name = "width" || Name = "height") ;Prevent recalculating size after it has been set manually
WinMove,% "ahk_id " this.hwnd,,% Name = "x" ? Value : "", % Name = "y" ? Value : "", % Name = "WindowWidth" ? Value : "", % Name = "WindowHeight" ? Value : ""
if(Name = "WindowWidth" || Name = "WindowHeight") ;Prevent recalculating size after it has been set manually
this.Remove("_Initialized")
else if(this.HasKey("_Initialized")) ;Mark that position was changed manually during recalculation phase
this._Initialized := true
Expand All @@ -869,9 +906,15 @@ Class CGUI
}
else if(Name = "Size")
{
WinMove,% "ahk_id " this.hwnd,,,, % Value.width, % Value.height
if(Name = "width" || Name = "height") ;Prevent recalculating size after it has been set manually
this.Remove("_Initialized")
Size := this.Size
WinSize := this.WindowSize
WinMove, % "ahk_id " this.hwnd,,,, % Value.width + WinSize.Width - Size.Width, % Value.height + WinSize.Height - Size.Height
this.Remove("_Initialized")
}
else if(Name = "WindowSize")
{
WinMove, % "ahk_id " this.hwnd,,,, % Value.width, % Value.height
this.Remove("_Initialized")
}
else if(Name = "Title")
WinSetTitle, % "ahk_id " this.hwnd,,%Value%
Expand Down Expand Up @@ -1007,6 +1050,9 @@ Class CGUI
}
if(!this.IsDestroyed)
{
;Call event handler
if(func = "PreClose")
this.OnClose.(this)
if(func = "PreClose" && !result && !GUI.DestroyOnClose) ;Hide the GUI if closing was not aborted and the GUI should not destroy itself on closing
GUI.Hide()
else if(func = "PreClose" && !result) ;Otherwise if not aborted destroy the GUI
Expand Down Expand Up @@ -1292,6 +1338,46 @@ CGUI_TypeOf(Object)
{
return Object.__Class
}

CGUI_ScreenToClient(hwnd, ByRef x, ByRef y)
{
VarSetCapacity(pt, 8)
NumPut(x, pt, 0)
NumPut(y, pt, 4)
DllCall("ScreenToClient", "PTR", hwnd, "PTR", &pt)
x := NumGet(pt, 0, "int")
y := NumGet(pt, 4, "int")
}

CGUI_ClientToScreen(hwnd, ByRef x, ByRef y)
{
VarSetCapacity(pt, 8)
NumPut(x, pt, 0)
NumPut(y, pt, 4)
DllCall("ClientToScreen", "PTR", hwnd, "PTR", &pt)
x := NumGet(pt, 0, "int")
y := NumGet(pt, 4, "int")
}
CGUI_WinToClient(hwnd, ByRef x, ByRef y)
{
WinGetPos, wx, wy,,, ahk_id %hwnd%
VarSetCapacity(pt, 8)
NumPut(x + wx, pt, 0)
NumPut(y + wy, pt, 4)
DllCall("ScreenToClient", "PTR", hwnd, "PTR", &pt)
x := NumGet(pt, 0, "int")
y := NumGet(pt, 4, "int")
}
CGUI_ClientToWin(hwnd, ByRef x, ByRef y)
{
VarSetCapacity(pt, 8)
NumPut(x, pt, 0)
NumPut(y, pt, 4)
DllCall("ClientToScreen", "PTR", hwnd, "PTR", &pt)
WinGetPos, wx, wy,,, ahk_id %hwnd%
x := NumGet(pt, 0, "int") - wx
y := NumGet(pt, 4, "int") - wy
}
#include <gdip>
#include <CControl>
#include <CFileDialog>
Expand Down

0 comments on commit 63022bb

Please sign in to comment.