2013-10-28 19:13:01 +00:00
using System ;
using System.Collections.Generic ;
2014-06-03 02:19:13 +00:00
using System.ComponentModel ;
2013-10-28 19:13:01 +00:00
using System.Drawing ;
using System.Linq ;
using System.Windows.Forms ;
2013-10-31 23:55:17 +00:00
using BizHawk.Client.Common ;
2014-01-26 16:15:45 +00:00
using LuaInterface ;
2013-10-28 19:13:01 +00:00
2013-11-03 03:54:37 +00:00
namespace BizHawk.Client.EmuHawk
2013-10-28 19:13:01 +00:00
{
2014-06-03 02:19:13 +00:00
[Description("A library for creating and managing custom dialogs")]
2014-06-01 22:02:59 +00:00
public sealed class FormsLuaLibrary : LuaLibraryBase
2013-10-28 19:13:01 +00:00
{
2014-05-21 00:17:35 +00:00
public FormsLuaLibrary ( Lua lua )
: base ( lua ) { }
public FormsLuaLibrary ( Lua lua , Action < string > logOutputCallback )
: base ( lua , logOutputCallback ) { }
2014-01-26 16:15:45 +00:00
// TODO: replace references to ConsoleLuaLibrary.Log with a callback that is passed in
2013-10-31 16:45:08 +00:00
public override string Name { get { return "forms" ; } }
2013-10-28 19:13:01 +00:00
#region Forms Library Helpers
2013-11-17 15:55:13 +00:00
private readonly List < LuaWinform > _luaForms = new List < LuaWinform > ( ) ;
2013-10-28 19:13:01 +00:00
public void WindowClosed ( IntPtr handle )
{
2014-01-26 16:15:45 +00:00
foreach ( var form in _luaForms )
2013-10-28 19:13:01 +00:00
{
if ( form . Handle = = handle )
{
2013-11-17 15:55:13 +00:00
_luaForms . Remove ( form ) ;
2013-10-28 19:13:01 +00:00
return ;
}
}
}
2014-01-27 03:16:05 +00:00
private LuaWinform GetForm ( int formHandle )
2013-10-28 19:13:01 +00:00
{
2014-01-27 03:16:05 +00:00
var ptr = new IntPtr ( formHandle ) ;
2013-11-17 15:55:13 +00:00
return _luaForms . FirstOrDefault ( form = > form . Handle = = ptr ) ;
2013-10-28 19:13:01 +00:00
}
2014-01-27 03:16:05 +00:00
private static void SetLocation ( Control control , int x , int y )
2013-10-28 19:13:01 +00:00
{
2014-01-27 03:16:05 +00:00
control . Location = new Point ( x , y ) ;
2013-10-28 19:13:01 +00:00
}
2014-01-27 03:16:05 +00:00
private static void SetSize ( Control control , int width , int height )
2013-10-28 19:13:01 +00:00
{
2014-01-27 03:16:05 +00:00
control . Size = new Size ( width , height ) ;
2013-10-28 19:13:01 +00:00
}
2014-01-27 03:16:05 +00:00
private static void SetText ( Control control , string caption )
2013-10-28 19:13:01 +00:00
{
2014-01-27 03:16:05 +00:00
control . Text = caption ? ? string . Empty ;
2013-10-28 19:13:01 +00:00
}
#endregion
2014-01-26 16:15:45 +00:00
[ LuaMethodAttributes (
"addclick" ,
2014-01-27 03:16:05 +00:00
"adds the given lua function as a click event to the given control"
2014-01-26 16:15:45 +00:00
) ]
2014-01-27 03:16:05 +00:00
public void AddClick ( int handle , LuaFunction clickEvent )
2013-10-28 19:13:01 +00:00
{
2014-01-27 03:16:05 +00:00
var ptr = new IntPtr ( handle ) ;
2014-01-26 16:15:45 +00:00
foreach ( var form in _luaForms )
2013-10-28 19:13:01 +00:00
{
foreach ( Control control in form . Controls )
{
if ( control . Handle = = ptr )
{
2014-01-26 16:15:45 +00:00
form . ControlEvents . Add ( new LuaWinform . LuaEvent ( control . Handle , clickEvent ) ) ;
2013-10-28 19:13:01 +00:00
}
}
}
}
2014-01-26 16:15:45 +00:00
[ LuaMethodAttributes (
"button" ,
2014-01-27 03:16:05 +00:00
"Creates a button control on the given form. The caption property will be the text value on the button. clickEvent is the name of a Lua function that will be invoked when the button is clicked. x, and y are the optional location parameters for the position of the button within the given form. The function returns the handle of the created button. Width and Height are optional, if not specified they will be a default size"
2014-01-26 16:15:45 +00:00
) ]
public int Button (
2014-01-27 03:16:05 +00:00
int formHandle ,
string caption ,
2014-01-26 16:15:45 +00:00
LuaFunction clickEvent ,
2014-01-27 03:16:05 +00:00
int? x = null ,
int? y = null ,
int? width = null ,
int? height = null )
2013-10-28 19:13:01 +00:00
{
2014-01-26 16:15:45 +00:00
var form = GetForm ( formHandle ) ;
2013-10-28 19:13:01 +00:00
if ( form = = null )
{
return 0 ;
}
2014-01-26 16:15:45 +00:00
var button = new LuaButton ( ) ;
2013-10-28 19:13:01 +00:00
SetText ( button , caption ) ;
form . Controls . Add ( button ) ;
2014-01-26 16:15:45 +00:00
form . ControlEvents . Add ( new LuaWinform . LuaEvent ( button . Handle , clickEvent ) ) ;
2013-10-28 19:13:01 +00:00
2014-01-27 03:16:05 +00:00
if ( x . HasValue & & y . HasValue )
{
SetLocation ( button , x . Value , y . Value ) ;
}
if ( width . HasValue & & height . HasValue )
{
SetSize ( button , width . Value , height . Value ) ;
}
2013-10-28 19:13:01 +00:00
return ( int ) button . Handle ;
}
2014-01-26 16:15:45 +00:00
[ LuaMethodAttributes (
"checkbox" ,
2014-01-27 03:16:05 +00:00
"Creates a checkbox control on the given form. The caption property will be the text of the checkbox. x and y are the optional location parameters for the position of the checkbox within the form"
2014-01-26 16:15:45 +00:00
) ]
2014-01-27 03:16:05 +00:00
public int Checkbox ( int formHandle , string caption , int? x = null , int? y = null )
2013-12-15 02:50:50 +00:00
{
2014-01-26 16:15:45 +00:00
var form = GetForm ( formHandle ) ;
2013-12-15 02:50:50 +00:00
if ( form = = null )
{
return 0 ;
}
2014-01-26 16:15:45 +00:00
var checkbox = new LuaCheckbox ( ) ;
2013-12-15 02:50:50 +00:00
form . Controls . Add ( checkbox ) ;
SetText ( checkbox , caption ) ;
2014-01-27 03:16:05 +00:00
if ( x . HasValue & & y . HasValue )
{
SetLocation ( checkbox , x . Value , y . Value ) ;
}
2013-12-15 02:50:50 +00:00
return ( int ) checkbox . Handle ;
}
2014-01-26 16:15:45 +00:00
[ LuaMethodAttributes (
"clearclicks" ,
2014-01-27 03:16:05 +00:00
"Removes all click events from the given widget at the specified handle"
2014-01-26 16:15:45 +00:00
) ]
2014-01-27 03:16:05 +00:00
public void ClearClicks ( int handle )
2013-10-28 19:13:01 +00:00
{
2014-01-27 03:16:05 +00:00
var ptr = new IntPtr ( handle ) ;
2014-01-26 16:15:45 +00:00
foreach ( var form in _luaForms )
2013-10-28 19:13:01 +00:00
{
foreach ( Control control in form . Controls )
{
if ( control . Handle = = ptr )
{
2014-01-26 16:15:45 +00:00
var luaEvents = form . ControlEvents . Where ( x = > x . Control = = ptr ) . ToList ( ) ;
foreach ( var luaEvent in luaEvents )
2013-10-28 19:13:01 +00:00
{
2014-01-26 16:15:45 +00:00
form . ControlEvents . Remove ( luaEvent ) ;
2013-10-28 19:13:01 +00:00
}
}
}
}
}
2014-01-26 16:15:45 +00:00
[ LuaMethodAttributes (
"destroy" ,
2014-01-27 03:16:05 +00:00
"Closes and removes a Lua created form with the specified handle. If a dialog was found and removed true is returned, else false"
2014-01-26 16:15:45 +00:00
) ]
2014-01-27 03:16:05 +00:00
public bool Destroy ( int handle )
2013-10-28 19:13:01 +00:00
{
2014-01-27 03:16:05 +00:00
var ptr = new IntPtr ( handle ) ;
2014-01-26 16:15:45 +00:00
foreach ( var form in _luaForms )
2013-10-28 19:13:01 +00:00
{
if ( form . Handle = = ptr )
{
form . Close ( ) ;
2013-11-17 15:55:13 +00:00
_luaForms . Remove ( form ) ;
2013-10-28 19:13:01 +00:00
return true ;
}
}
2014-01-26 16:15:45 +00:00
2013-10-28 19:13:01 +00:00
return false ;
}
2014-01-26 16:15:45 +00:00
[ LuaMethodAttributes (
"destroyall" ,
2014-01-27 03:16:05 +00:00
"Closes and removes all Lua created dialogs"
2014-01-26 16:15:45 +00:00
) ]
public void DestroyAll ( )
2013-10-28 19:13:01 +00:00
{
2015-11-06 15:08:44 +00:00
for ( var i = _luaForms . Count - 1 ; i > = 0 ; i - - )
2013-10-28 19:13:01 +00:00
{
2015-11-06 15:08:44 +00:00
_luaForms . ElementAt ( i ) . Close ( ) ;
2013-10-28 19:13:01 +00:00
}
}
2014-01-26 16:15:45 +00:00
[ LuaMethodAttributes (
"dropdown" ,
2014-01-27 03:16:05 +00:00
"Creates a dropdown (with a ComboBoxStyle of DropDownList) control on the given form. Dropdown items are passed via a lua table. Only the values will be pulled for the dropdown items, the keys are irrelevant. Items will be sorted alphabetically. x and y are the optional location parameters, and width and height are the optional size parameters."
2014-01-26 16:15:45 +00:00
) ]
public int Dropdown (
2014-01-27 03:16:05 +00:00
int formHandle ,
2014-01-26 16:15:45 +00:00
LuaTable items ,
2014-01-27 03:16:05 +00:00
int? x = null ,
int? y = null ,
int? width = null ,
int? height = null )
2013-12-15 02:50:50 +00:00
{
2014-01-26 16:15:45 +00:00
var form = GetForm ( formHandle ) ;
2013-12-15 02:50:50 +00:00
if ( form = = null )
{
return 0 ;
}
2014-01-26 16:15:45 +00:00
var dropdownItems = items . Values . Cast < string > ( ) . ToList ( ) ;
2013-12-15 02:50:50 +00:00
dropdownItems . Sort ( ) ;
2014-01-26 16:15:45 +00:00
var dropdown = new LuaDropDown ( dropdownItems ) ;
2013-12-15 02:50:50 +00:00
form . Controls . Add ( dropdown ) ;
2014-01-27 03:16:05 +00:00
if ( x . HasValue & & y . HasValue )
{
SetLocation ( dropdown , x . Value , y . Value ) ;
}
if ( width . HasValue & & height . HasValue )
{
SetSize ( dropdown , width . Value , height . Value ) ;
}
2013-12-15 02:50:50 +00:00
return ( int ) dropdown . Handle ;
}
2014-01-26 16:15:45 +00:00
[ LuaMethodAttributes (
"getproperty" ,
2014-01-27 03:16:05 +00:00
"returns a string representation of the value of a property of the widget at the given handle"
2014-01-26 16:15:45 +00:00
) ]
2014-01-27 03:16:05 +00:00
public string GetProperty ( int handle , string property )
2013-10-28 19:13:01 +00:00
{
try
{
2014-01-27 03:16:05 +00:00
var ptr = new IntPtr ( handle ) ;
2014-01-26 16:15:45 +00:00
foreach ( var form in _luaForms )
2013-10-28 19:13:01 +00:00
{
if ( form . Handle = = ptr )
{
2014-01-27 03:16:05 +00:00
return form . GetType ( ) . GetProperty ( property ) . GetValue ( form , null ) . ToString ( ) ;
2013-10-28 19:13:01 +00:00
}
2014-02-23 22:47:45 +00:00
foreach ( Control control in form . Controls )
2013-10-28 19:13:01 +00:00
{
2014-02-23 22:47:45 +00:00
if ( control . Handle = = ptr )
2013-10-28 19:13:01 +00:00
{
2014-02-23 22:47:45 +00:00
return control . GetType ( ) . GetProperty ( property ) . GetValue ( control , null ) . ToString ( ) ;
2013-10-28 19:13:01 +00:00
}
}
}
}
catch ( Exception ex )
{
2014-01-26 16:15:45 +00:00
ConsoleLuaLibrary . Log ( ex . Message ) ;
2013-10-28 19:13:01 +00:00
}
2014-02-23 22:47:45 +00:00
return string . Empty ;
2013-10-28 19:13:01 +00:00
}
2014-01-26 16:15:45 +00:00
[ LuaMethodAttributes (
"gettext" ,
2014-01-27 03:16:05 +00:00
"Returns the text property of a given form or control"
2014-01-26 16:15:45 +00:00
) ]
2014-01-27 03:16:05 +00:00
public string GetText ( int handle )
2013-10-28 19:13:01 +00:00
{
try
{
2014-01-27 03:16:05 +00:00
var ptr = new IntPtr ( handle ) ;
2014-01-26 16:15:45 +00:00
foreach ( var form in _luaForms )
2013-10-28 19:13:01 +00:00
{
if ( form . Handle = = ptr )
{
return form . Text ;
}
2014-02-23 22:47:45 +00:00
foreach ( Control control in form . Controls )
2013-10-28 19:13:01 +00:00
{
2014-02-23 22:47:45 +00:00
if ( control . Handle = = ptr )
2013-10-28 19:13:01 +00:00
{
2014-02-23 22:47:45 +00:00
if ( control is LuaDropDown )
2013-10-28 19:13:01 +00:00
{
2014-02-23 22:47:45 +00:00
return ( control as LuaDropDown ) . SelectedItem . ToString ( ) ;
2013-10-28 19:13:01 +00:00
}
2014-02-23 22:47:45 +00:00
return control . Text ;
2013-10-28 19:13:01 +00:00
}
}
}
}
catch ( Exception ex )
{
2014-01-26 16:15:45 +00:00
ConsoleLuaLibrary . Log ( ex . Message ) ;
2013-10-28 19:13:01 +00:00
}
2014-02-23 22:47:45 +00:00
return string . Empty ;
2013-10-28 19:13:01 +00:00
}
2014-01-26 16:15:45 +00:00
[ LuaMethodAttributes (
"ischecked" ,
2014-01-27 03:16:05 +00:00
"Returns the given checkbox's checked property"
2014-01-26 16:15:45 +00:00
) ]
2014-01-27 03:16:05 +00:00
public bool IsChecked ( int handle )
2013-12-15 02:50:50 +00:00
{
2014-01-27 03:16:05 +00:00
var ptr = new IntPtr ( handle ) ;
foreach ( var form in _luaForms )
2013-12-15 02:50:50 +00:00
{
2014-01-27 03:16:05 +00:00
if ( form . Handle = = ptr )
2013-12-15 02:50:50 +00:00
{
2014-01-27 03:16:05 +00:00
return false ;
}
2014-02-23 22:47:45 +00:00
foreach ( Control control in form . Controls )
2014-01-27 03:16:05 +00:00
{
2014-02-23 22:47:45 +00:00
if ( control . Handle = = ptr )
2013-12-15 02:50:50 +00:00
{
2014-02-23 22:47:45 +00:00
if ( control is LuaCheckbox )
2013-12-15 02:50:50 +00:00
{
2014-02-23 22:47:45 +00:00
return ( control as LuaCheckbox ) . Checked ;
2013-12-15 02:50:50 +00:00
}
2014-02-23 22:47:45 +00:00
return false ;
2013-12-15 02:50:50 +00:00
}
}
}
return false ;
}
2014-01-26 16:15:45 +00:00
[ LuaMethodAttributes (
"label" ,
2014-01-27 03:16:05 +00:00
"Creates a label control on the given form. The caption property is the text of the label. x, and y are the optional location parameters for the position of the label within the given form. The function returns the handle of the created label. Width and Height are optional, if not specified they will be a default size."
2014-01-26 16:15:45 +00:00
) ]
public int Label (
2014-01-27 03:16:05 +00:00
int formHandle ,
string caption ,
int? x = null ,
int? y = null ,
int? width = null ,
2014-09-07 02:42:44 +00:00
int? height = null ,
bool fixedWidth = false )
2013-10-28 19:13:01 +00:00
{
2014-01-26 16:15:45 +00:00
var form = GetForm ( formHandle ) ;
2013-10-28 19:13:01 +00:00
if ( form = = null )
{
return 0 ;
}
2014-01-26 16:15:45 +00:00
var label = new Label ( ) ;
2014-09-07 02:42:44 +00:00
if ( fixedWidth )
{
label . Font = new Font ( "Courier New" , 8 ) ;
}
2013-10-28 19:13:01 +00:00
SetText ( label , caption ) ;
form . Controls . Add ( label ) ;
2014-01-27 03:16:05 +00:00
if ( x . HasValue & & y . HasValue )
{
SetLocation ( label , x . Value , y . Value ) ;
}
if ( width . HasValue & & height . HasValue )
{
SetSize ( label , width . Value , height . Value ) ;
}
2013-10-28 19:13:01 +00:00
return ( int ) label . Handle ;
}
2014-01-26 16:15:45 +00:00
[ LuaMethodAttributes (
"newform" ,
2014-01-27 03:16:05 +00:00
"creates a new default dialog, if both width and height are specified it will create a dialog of the specified size. If title is specified it will be the caption of the dialog, else the dialog caption will be 'Lua Dialog'. The function will return an int representing the handle of the dialog created."
2014-01-26 16:15:45 +00:00
) ]
2015-08-05 00:17:04 +00:00
public int NewForm ( int? width = null , int? height = null , string title = null , LuaFunction onClose = null )
2013-10-28 19:13:01 +00:00
{
2014-01-26 16:15:45 +00:00
var form = new LuaWinform ( ) ;
_luaForms . Add ( form ) ;
2014-01-27 03:16:05 +00:00
if ( width . HasValue & & height . HasValue )
2013-10-28 19:13:01 +00:00
{
2014-02-23 22:47:45 +00:00
form . Size = new Size ( width . Value , height . Value ) ;
2013-10-28 19:13:01 +00:00
}
2014-01-26 16:15:45 +00:00
form . Text = title ;
2015-08-05 00:17:04 +00:00
form . MaximizeBox = false ;
form . FormBorderStyle = FormBorderStyle . FixedDialog ;
form . Icon = SystemIcons . Application ;
2014-01-26 16:15:45 +00:00
form . Show ( ) ;
2015-08-05 00:17:04 +00:00
form . FormClosed + = ( o , e ) = >
{
if ( onClose ! = null )
{
try
{
onClose . Call ( ) ;
}
catch ( Exception ex )
{
Log ( ex . ToString ( ) ) ;
}
}
} ;
2014-01-26 16:15:45 +00:00
return ( int ) form . Handle ;
2013-10-28 19:13:01 +00:00
}
2014-01-26 16:15:45 +00:00
[ LuaMethodAttributes (
"openfile" ,
2014-01-27 03:16:05 +00:00
"Creates a standard openfile dialog with optional parameters for the filename, directory, and filter. The return value is the directory that the user picked. If they chose to cancel, it will return an empty string"
2014-01-26 16:15:45 +00:00
) ]
public string OpenFile ( string fileName = null , string initialDirectory = null , string filter = "All files (*.*)|*.*" )
2013-10-28 19:13:01 +00:00
{
// filterext format ex: "Image Files(*.BMP;*.JPG;*.GIF)|*.BMP;*.JPG;*.GIF|All files (*.*)|*.*"
2014-01-26 16:15:45 +00:00
var openFileDialog1 = new OpenFileDialog ( ) ;
if ( initialDirectory ! = null )
2013-10-28 19:13:01 +00:00
{
2014-01-26 16:15:45 +00:00
openFileDialog1 . InitialDirectory = initialDirectory ;
2013-10-28 19:13:01 +00:00
}
2013-10-31 16:45:08 +00:00
2014-01-26 16:15:45 +00:00
if ( fileName ! = null )
2013-10-28 19:13:01 +00:00
{
2014-01-26 16:15:45 +00:00
openFileDialog1 . FileName = fileName ;
2013-10-28 19:13:01 +00:00
}
2013-10-31 16:45:08 +00:00
2014-01-26 16:15:45 +00:00
if ( filter ! = null )
2013-10-28 19:13:01 +00:00
{
openFileDialog1 . AddExtension = true ;
2014-01-26 16:15:45 +00:00
openFileDialog1 . Filter = filter ;
2013-10-28 19:13:01 +00:00
}
2013-10-31 16:45:08 +00:00
2013-10-28 19:13:01 +00:00
if ( openFileDialog1 . ShowDialog ( ) = = DialogResult . OK )
2013-10-31 16:45:08 +00:00
{
2013-10-28 19:13:01 +00:00
return openFileDialog1 . FileName ;
2013-10-31 16:45:08 +00:00
}
2014-02-23 22:47:45 +00:00
return string . Empty ;
2013-10-28 19:13:01 +00:00
}
2014-01-26 16:15:45 +00:00
[ LuaMethodAttributes (
"setlocation" ,
2014-01-27 03:16:05 +00:00
"Sets the location of a control or form by passing in the handle of the created object"
2014-01-26 16:15:45 +00:00
) ]
2014-01-27 03:16:05 +00:00
public void SetLocation ( int handle , int x , int y )
2013-10-28 19:13:01 +00:00
{
2014-01-27 03:16:05 +00:00
var ptr = new IntPtr ( handle ) ;
2014-01-26 16:15:45 +00:00
foreach ( var form in _luaForms )
2013-10-28 19:13:01 +00:00
{
if ( form . Handle = = ptr )
{
2014-01-26 16:15:45 +00:00
SetLocation ( form , x , y ) ;
2013-10-28 19:13:01 +00:00
}
else
{
foreach ( Control control in form . Controls )
{
if ( control . Handle = = ptr )
{
2014-01-26 16:15:45 +00:00
SetLocation ( control , x , y ) ;
2013-10-28 19:13:01 +00:00
}
}
}
}
}
2014-01-26 16:15:45 +00:00
[ LuaMethodAttributes (
"setproperty" ,
2014-01-27 03:16:05 +00:00
"Attempts to set the given property of the widget with the given value. Note: not all properties will be able to be represented for the control to accept"
2014-01-26 16:15:45 +00:00
) ]
2014-01-27 03:16:05 +00:00
public void SetProperty ( int handle , string property , object value )
2013-10-28 19:13:01 +00:00
{
2014-01-27 03:16:05 +00:00
var ptr = new IntPtr ( handle ) ;
2014-01-26 16:15:45 +00:00
foreach ( var form in _luaForms )
2013-10-28 19:13:01 +00:00
{
if ( form . Handle = = ptr )
{
2015-12-19 05:01:06 +00:00
if ( form . GetType ( ) . GetProperty ( property ) . PropertyType . IsEnum )
{
value = Enum . Parse ( form . GetType ( ) . GetProperty ( property ) . PropertyType , value . ToString ( ) , true ) ;
}
2014-01-27 03:16:05 +00:00
form
. GetType ( )
. GetProperty ( property )
. SetValue ( form , Convert . ChangeType ( value , form . GetType ( ) . GetProperty ( property ) . PropertyType ) , null ) ;
2013-10-28 19:13:01 +00:00
}
else
{
foreach ( Control control in form . Controls )
{
if ( control . Handle = = ptr )
{
2015-12-19 05:01:06 +00:00
if ( control . GetType ( ) . GetProperty ( property ) . PropertyType . IsEnum )
{
value = Enum . Parse ( control . GetType ( ) . GetProperty ( property ) . PropertyType , value . ToString ( ) , true ) ;
}
2014-01-27 03:16:05 +00:00
control
. GetType ( )
. GetProperty ( property )
2015-04-05 04:11:00 +00:00
. SetValue ( control , Convert . ChangeType ( value , control . GetType ( ) . GetProperty ( property ) . PropertyType ) , null ) ;
2013-10-28 19:13:01 +00:00
}
}
}
}
}
2014-01-26 16:15:45 +00:00
[ LuaMethodAttributes (
"setsize" ,
"TODO"
) ]
2014-01-27 03:16:05 +00:00
public void SetSize ( int handle , int width , int height )
2013-10-28 19:13:01 +00:00
{
2014-01-27 03:16:05 +00:00
var ptr = new IntPtr ( handle ) ;
2014-01-26 16:15:45 +00:00
foreach ( var form in _luaForms )
2013-10-28 19:13:01 +00:00
{
if ( form . Handle = = ptr )
{
2014-01-26 16:15:45 +00:00
SetSize ( form , width , height ) ;
2013-10-28 19:13:01 +00:00
}
else
{
foreach ( Control control in form . Controls )
{
if ( control . Handle = = ptr )
{
2014-01-26 16:15:45 +00:00
SetSize ( control , width , height ) ;
2013-10-28 19:13:01 +00:00
}
}
}
}
}
2014-01-26 16:15:45 +00:00
[ LuaMethodAttributes (
"settext" ,
2014-01-27 03:16:05 +00:00
"Sets the text property of a control or form by passing in the handle of the created object"
2014-01-26 16:15:45 +00:00
) ]
2014-01-27 03:16:05 +00:00
public void Settext ( int handle , string caption )
2013-10-28 19:13:01 +00:00
{
2014-01-27 03:16:05 +00:00
var ptr = new IntPtr ( handle ) ;
2014-01-26 16:15:45 +00:00
foreach ( var form in _luaForms )
2013-10-28 19:13:01 +00:00
{
if ( form . Handle = = ptr )
{
SetText ( form , caption ) ;
}
else
{
foreach ( Control control in form . Controls )
{
if ( control . Handle = = ptr )
{
SetText ( control , caption ) ;
}
}
}
}
}
2014-01-26 16:15:45 +00:00
[ LuaMethodAttributes (
"textbox" ,
2016-01-16 02:19:25 +00:00
"Creates a textbox control on the given form. The caption property will be the initial value of the textbox (default is empty). Width and Height are option, if not specified they will be a default size of 100, 20. Type is an optional property to restrict the textbox input. The available options are HEX, SIGNED, and UNSIGNED. Passing it null or any other value will set it to no restriction. x, and y are the optional location parameters for the position of the textbox within the given form. The function returns the handle of the created textbox. If true, the multiline will enable the standard winform multi-line property. If true, the fixedWidth options will create a fixed width font. Scrollbars is an optional property to specify which scrollbars to display. The available options are Vertical, Horizontal, Both, and None. Scrollbars are only shown on a multiline textbox"
2014-01-26 16:15:45 +00:00
) ]
public int Textbox (
2014-01-27 03:16:05 +00:00
int formHandle ,
string caption = null ,
int? width = null ,
int? height = null ,
string boxtype = null ,
int? x = null ,
int? y = null ,
2014-01-26 16:15:45 +00:00
bool multiline = false ,
2016-01-16 02:19:25 +00:00
bool fixedWidth = false ,
string scrollbars = null )
2013-10-28 19:13:01 +00:00
{
2014-01-26 16:15:45 +00:00
var form = GetForm ( formHandle ) ;
2013-10-28 19:13:01 +00:00
if ( form = = null )
{
return 0 ;
}
2014-01-26 16:15:45 +00:00
var textbox = new LuaTextBox ( ) ;
2013-12-30 14:58:09 +00:00
if ( fixedWidth )
{
textbox . Font = new Font ( "Courier New" , 8 ) ;
}
2013-12-02 03:41:29 +00:00
textbox . Multiline = multiline ;
2016-01-16 02:19:25 +00:00
if ( scrollbars ! = null )
{
switch ( scrollbars . ToUpper ( ) )
{
case "VERTICAL" :
textbox . ScrollBars = ScrollBars . Vertical ;
break ;
case "HORIZONTAL" :
textbox . ScrollBars = ScrollBars . Horizontal ;
textbox . WordWrap = false ;
break ;
case "BOTH" :
textbox . ScrollBars = ScrollBars . Both ;
textbox . WordWrap = false ;
break ;
case "NONE" :
textbox . ScrollBars = ScrollBars . None ;
break ;
}
}
2013-10-28 19:13:01 +00:00
SetText ( textbox , caption ) ;
2014-01-27 03:16:05 +00:00
if ( x . HasValue & & y . HasValue )
{
SetLocation ( textbox , x . Value , y . Value ) ;
}
if ( width . HasValue & & height . HasValue )
{
SetSize ( textbox , width . Value , height . Value ) ;
}
2013-10-28 19:13:01 +00:00
if ( boxtype ! = null )
{
2014-01-27 03:16:05 +00:00
switch ( boxtype . ToUpper ( ) )
2013-10-28 19:13:01 +00:00
{
case "HEX" :
case "HEXADECIMAL" :
2013-11-17 15:55:13 +00:00
textbox . SetType ( BoxType . Hex ) ;
2013-10-28 19:13:01 +00:00
break ;
case "UNSIGNED" :
case "UINT" :
2013-11-17 15:55:13 +00:00
textbox . SetType ( BoxType . Unsigned ) ;
2013-10-28 19:13:01 +00:00
break ;
case "NUMBER" :
case "NUM" :
case "SIGNED" :
case "INT" :
2013-11-17 15:55:13 +00:00
textbox . SetType ( BoxType . Signed ) ;
2013-10-28 19:13:01 +00:00
break ;
}
}
2014-01-26 16:15:45 +00:00
2013-10-28 19:13:01 +00:00
form . Controls . Add ( textbox ) ;
return ( int ) textbox . Handle ;
}
}
}