diff --git a/.gitignore b/.gitignore index 82ab9f9..bc36587 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,3 @@ __history/ +*.local +*.identcache diff --git a/Packages/DXE2/X2Utils.dpk b/Packages/DXE2/X2Utils.dpk index 374d151..f40834b 100644 --- a/Packages/DXE2/X2Utils.dpk +++ b/Packages/DXE2/X2Utils.dpk @@ -60,6 +60,11 @@ contains X2UtPersistXMLBinding in '..\..\X2UtPersistXMLBinding.pas', XMLDataBindingUtils in '..\..\XMLDataBindingUtils.pas', X2UtDelphiCompatibility in '..\..\X2UtDelphiCompatibility.pas', - X2UtCursors in '..\..\X2UtCursors.pas'; + X2UtCursors in '..\..\X2UtCursors.pas', + X2UtService.GUIContext.Form in '..\..\X2UtService.GUIContext.Form.pas' {X2ServiceContextGUIForm}, + X2UtService.GUIContext in '..\..\X2UtService.GUIContext.pas', + X2UtService.Intf in '..\..\X2UtService.Intf.pas', + X2UtService in '..\..\X2UtService.pas', + X2UtService.ServiceContext in '..\..\X2UtService.ServiceContext.pas'; end. diff --git a/Packages/DXE2/X2Utils.dproj b/Packages/DXE2/X2Utils.dproj index a73503a..31e80d1 100644 --- a/Packages/DXE2/X2Utils.dproj +++ b/Packages/DXE2/X2Utils.dproj @@ -206,6 +206,13 @@ + +
X2ServiceContextGUIForm
+
+ + + + Cfg_2 Base diff --git a/X2UtService.GUIContext.Form.dfm b/X2UtService.GUIContext.Form.dfm index 94aedca..b0cf4a8 100644 --- a/X2UtService.GUIContext.Form.dfm +++ b/X2UtService.GUIContext.Form.dfm @@ -4,8 +4,8 @@ object X2ServiceContextGUIForm: TX2ServiceContextGUIForm BorderIcons = [biSystemMenu, biMinimize] BorderStyle = bsSingle Caption = 'X2ServiceContextGUIForm' - ClientHeight = 177 - ClientWidth = 285 + ClientHeight = 204 + ClientWidth = 439 Color = clBtnFace Font.Charset = DEFAULT_CHARSET Font.Color = clWindowText @@ -15,14 +15,15 @@ object X2ServiceContextGUIForm: TX2ServiceContextGUIForm OldCreateOrder = False Position = poScreenCenter OnCloseQuery = FormCloseQuery + OnCreate = FormCreate DesignSize = ( - 285 - 177) + 439 + 204) PixelsPerInch = 96 TextHeight = 13 object btnClose: TButton - Left = 107 - Top = 144 + Left = 8 + Top = 171 Width = 75 Height = 25 Anchors = [akLeft, akBottom] @@ -34,7 +35,7 @@ object X2ServiceContextGUIForm: TX2ServiceContextGUIForm AlignWithMargins = True Left = 8 Top = 8 - Width = 269 + Width = 423 Height = 57 Margins.Left = 8 Margins.Top = 8 @@ -43,6 +44,7 @@ object X2ServiceContextGUIForm: TX2ServiceContextGUIForm Align = alTop Caption = ' Status ' TabOrder = 1 + ExplicitWidth = 358 object lblStatus: TLabel Left = 34 Top = 26 @@ -63,8 +65,8 @@ object X2ServiceContextGUIForm: TX2ServiceContextGUIForm AlignWithMargins = True Left = 8 Top = 73 - Width = 269 - Height = 60 + Width = 423 + Height = 88 Margins.Left = 8 Margins.Top = 8 Margins.Right = 8 @@ -72,9 +74,10 @@ object X2ServiceContextGUIForm: TX2ServiceContextGUIForm Align = alTop Caption = ' Custom control ' TabOrder = 2 + ExplicitWidth = 358 DesignSize = ( - 269 - 60) + 423 + 88) object lblControlCode: TLabel Left = 12 Top = 27 @@ -85,15 +88,16 @@ object X2ServiceContextGUIForm: TX2ServiceContextGUIForm object edtControlCode: TEdit Left = 72 Top = 24 - Width = 102 + Width = 256 Height = 21 Anchors = [akLeft, akTop, akRight] TabOrder = 0 Text = '128' OnChange = edtControlCodeChange + ExplicitWidth = 191 end object btnSend: TButton - Left = 180 + Left = 334 Top = 24 Width = 75 Height = 21 @@ -101,6 +105,28 @@ object X2ServiceContextGUIForm: TX2ServiceContextGUIForm Caption = '&Send' TabOrder = 1 OnClick = btnSendClick + ExplicitLeft = 269 + end + object cmbControlCodePredefined: TComboBox + Left = 72 + Top = 51 + Width = 256 + Height = 21 + Style = csDropDownList + Anchors = [akLeft, akTop, akRight] + TabOrder = 2 + ExplicitWidth = 220 + end + object btnSendPredefined: TButton + Left = 334 + Top = 51 + Width = 75 + Height = 21 + Anchors = [akTop, akRight] + Caption = '&Send' + TabOrder = 3 + OnClick = btnSendPredefinedClick + ExplicitLeft = 269 end end end diff --git a/X2UtService.GUIContext.Form.pas b/X2UtService.GUIContext.Form.pas index 9f03b10..8821114 100644 --- a/X2UtService.GUIContext.Form.pas +++ b/X2UtService.GUIContext.Form.pas @@ -23,10 +23,14 @@ type lblControlCode: TLabel; edtControlCode: TEdit; btnSend: TButton; + cmbControlCodePredefined: TComboBox; + btnSendPredefined: TButton; + procedure FormCreate(Sender: TObject); procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean); procedure edtControlCodeChange(Sender: TObject); procedure btnSendClick(Sender: TObject); + procedure btnSendPredefinedClick(Sender: TObject); procedure btnCloseClick(Sender: TObject); private FContext: IX2ServiceContext; @@ -36,6 +40,8 @@ type protected procedure DoShow; override; + procedure UpdatePredefinedControlCodes; virtual; + function GetControlCode: Byte; procedure SetStatus(const AMessage: string; AColor: TColor); @@ -101,6 +107,12 @@ type { TX2ServiceContextGUIForm } +procedure TX2ServiceContextGUIForm.FormCreate(Sender: TObject); +begin + btnClose.Left := (ClientWidth - btnClose.Width) div 2; +end; + + procedure TX2ServiceContextGUIForm.DoShow; var serviceThread: TX2ServiceThread; @@ -109,6 +121,8 @@ begin if not Assigned(FServiceThread) then begin + UpdatePredefinedControlCodes; + SetStatus('Starting...', StatusColorStarting); serviceThread := TX2ServiceThread.Create(Context, Service); serviceThread.OnStarted := @@ -158,6 +172,19 @@ begin end; +procedure TX2ServiceContextGUIForm.btnSendPredefinedClick(Sender: TObject); +var + code: Byte; + +begin + if cmbControlCodePredefined.ItemIndex > -1 then + begin + code := Byte(cmbControlCodePredefined.Items.Objects[cmbControlCodePredefined.ItemIndex]); + (ServiceThread as TX2ServiceThread).SendControlCode(code); + end; +end; + + procedure TX2ServiceContextGUIForm.btnCloseClick(Sender: TObject); begin Close; @@ -176,6 +203,32 @@ begin end; +procedure TX2ServiceContextGUIForm.UpdatePredefinedControlCodes; +var + serviceCustomControl: IX2ServiceCustomControl; + +begin + cmbControlCodePredefined.Items.Clear; + + if Supports(Service, IX2ServiceCustomControl, serviceCustomControl) then + begin + serviceCustomControl.EnumCustomControlCodes( + procedure(ACode: Byte; const ADescription: string) + begin + cmbControlCodePredefined.Items.AddObject(Format('%s (%d)', [ADescription, ACode]), TObject(ACode)); + end); + + cmbControlCodePredefined.Enabled := True; + cmbControlCodePredefined.ItemIndex := 0; + btnSendPredefined.Enabled := cmbControlCodePredefined.Items.Count > 0; + end else + begin + cmbControlCodePredefined.Enabled := False; + btnSendPredefined.Enabled := False; + end; +end; + + function TX2ServiceContextGUIForm.GetControlCode: Byte; begin Result := Byte(Min(Max(StrToIntDef(edtControlCode.Text, 0), 128), 255)); diff --git a/X2UtService.Intf.pas b/X2UtService.Intf.pas index a843268..635dad5 100644 --- a/X2UtService.Intf.pas +++ b/X2UtService.Intf.pas @@ -40,6 +40,17 @@ type end; + + TX2ServiceCustomControlProc = reference to procedure(ACode: Byte; const ADescription: string); + + { Implement this to enable discovery of supported custom control codes + for use in interactive contexts. } + IX2ServiceCustomControl = interface + ['{D6363AC5-3DD5-4897-90A7-6F63D82B6A74}'] + procedure EnumCustomControlCodes(Yield: TX2ServiceCustomControlProc); + end; + + TX2CustomService = class(TInterfacedObject, IX2Service) private FContext: IX2ServiceContext;