ContainerInterThread.cs
上传用户:szltgg
上传日期:2019-05-16
资源大小:604k
文件大小:4k
源码类别:

Telnet服务器

开发平台:

C#

  1. /*
  2. * Copyright (c) 2005 Poderosa Project, All Rights Reserved.
  3. * $Id: ContainerInterThread.cs,v 1.2 2005/04/20 08:45:44 okajima Exp $
  4. */
  5. using System;
  6. using System.Threading;
  7. using System.Windows.Forms;
  8. using Poderosa.Connection;
  9. using Poderosa.ConnectionParam;
  10. using Poderosa.Communication;
  11. using Poderosa.Text;
  12. using Poderosa.Config;
  13. using Poderosa.Forms;
  14. namespace Poderosa
  15. {
  16. internal class ContainerInterThreadUIService : InterThreadUIService {
  17. private TerminalParam _terminalParam;
  18. private ConnectionTag _resultConnection;
  19. private PanePosition _destinationPanePosition;
  20. private string _shortcutFile;
  21. private TerminalConnection _connection;
  22. public enum CService {
  23. ActivateConnection = InterThreadUIService.Service.End+1,
  24. SetPanePosition,
  25. SetFrameStyle,
  26. CloseConnection,
  27. OpenConnection,
  28. OpenShortcut,
  29. MacroFinished
  30. }
  31. //SetFrameStyle
  32. private GFrameStyle _style;
  33. private int _width1;
  34. private int _height1;
  35. private int _width2;
  36. private int _height2;
  37. public void SetPanePosition(ConnectionTag tag, PanePosition pos) {
  38. lock(this) {
  39. _connection = tag.Connection;
  40. _destinationPanePosition = pos;
  41. SendMessageCore(CService.SetPanePosition);
  42. }
  43. }
  44. public void SetFrameStyle(GFrameStyle style, int w1, int h1, int w2, int h2) {
  45. lock(this) {
  46. _style = style;
  47. _width1 = w1;
  48. _height1 = h1;
  49. _width2 = w2;
  50. _height2 = h2;
  51. SendMessageCore(CService.SetFrameStyle);
  52. }
  53. }
  54. public void MacroFinished() {
  55. lock(this) {
  56. SendMessageCore(CService.MacroFinished);
  57. }
  58. }
  59. public ConnectionTag OpenConnection(TerminalParam param) {
  60. lock(this) {
  61. _terminalParam = param;
  62. SendMessageCore(CService.OpenConnection);
  63. }
  64. return _resultConnection;
  65. }
  66. public ConnectionTag OpenShortcut(string filename) {
  67. lock(this) {
  68. _shortcutFile = filename;
  69. SendMessageCore(CService.OpenShortcut);
  70. }
  71. return _resultConnection;
  72. }
  73. public void ActivateConnection(ConnectionTag tag) {
  74. lock(this) {
  75. _connection = tag.Connection;
  76. SendMessageCore(CService.ActivateConnection);
  77. }
  78. }
  79. public void CloseConnection(ConnectionTag tag) {
  80. _connection = tag.Connection;
  81. lock(this) {
  82. SendMessageCore(CService.CloseConnection);
  83. }
  84. }
  85. private void SendMessageCore(CService svc) {
  86. Win32.SendMessage(_mainFrameHandle, GConst.WMG_UIMESSAGE, new IntPtr((int)svc), IntPtr.Zero);
  87. }
  88. private void SetFrameStyle() {
  89. GApp.GlobalCommandTarget.SetFrameStyle(_style);
  90. GApp.Frame.PaneContainer.ResizeByChar(_width1, _height1, _width2, _height2);
  91. }
  92. public override void ProcessMessage(IntPtr wParam, IntPtr lParam) {
  93. switch((CService)(int)wParam) {
  94. case CService.SetPanePosition:
  95. GEnv.Frame.ActivateConnection(GEnv.Connections.FindTag(_connection));
  96. if(GApp.Options.FrameStyle==GFrameStyle.DivHorizontal)
  97. GApp.GlobalCommandTarget.MoveActivePane(_destinationPanePosition==PanePosition.First? Keys.Up : Keys.Down);
  98. else if(GApp.Options.FrameStyle==GFrameStyle.DivVertical)
  99. GApp.GlobalCommandTarget.MoveActivePane(_destinationPanePosition==PanePosition.First? Keys.Left : Keys.Right);
  100. break;
  101. case CService.SetFrameStyle:
  102. SetFrameStyle();
  103. break;
  104. case CService.MacroFinished:
  105. GApp.MacroManager.IndicateMacroFinished();
  106. break;
  107. case CService.OpenConnection:
  108. _resultConnection = GApp.GlobalCommandTarget.SilentNewConnection(_terminalParam);
  109. break;
  110. case CService.OpenShortcut:
  111. _resultConnection = GApp.GlobalCommandTarget.SilentOpenShortCut(_shortcutFile);
  112. break;
  113. case CService.ActivateConnection:
  114. GApp.GlobalCommandTarget.ActivateConnection(_connection);
  115. break;
  116. case CService.CloseConnection:
  117. GApp.GetConnectionCommandTarget(_connection).Close();
  118. break;
  119. default:
  120. base.ProcessMessage(wParam, lParam);
  121. break;
  122. }
  123. }
  124. }
  125. }