📄 sessdlg.cs
字号:
// Copyright (C) 2004-2005, 2007 Rocky Lo. All Rights Reserved.
// Copyright (C) 2002 Ultr@VNC Team Members. All Rights Reserved.
// Copyright (C) 1999 AT&T Laboratories Cambridge. All Rights Reserved.
//
// This file is part of the VNC system.
//
// The VNC system is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
// USA.
//
// If the source code for the VNC system is not available from the place
// whence you received this file, check http://www.uk.research.att.com/vnc or contact
// the authors on vnc@uk.research.att.com for information on obtaining it.
using System;
using System.IO;
using System.Xml;
using System.Windows.Forms;
namespace Vnc.Viewer
{
/// <remarks>Prompts the user for connection details.</remarks>
internal abstract class SessDlg : Form
{
/// <summary>This is default port to connect to.</summary>
private const UInt16 VncPort = 5900;
/// <summary>This is default port to listen on.</summary>
private const UInt16 VncListenPort = 5500;
private ConnMode connMode = ConnMode.Active;
private string host = null;
private int port = -1;
private string passwd = null;
protected ViewOpts viewOpts = null;
protected Label servLbl = new Label();
protected TextBox remoteEndPt = new TextBox();
protected Label remoteEndPtLbl = new Label();
protected Label passwdLbl = new Label();
protected TextBox passwdBox = new TextBox();
protected Label recentLbl = new Label();
protected CheckBox listenBox = new CheckBox();
protected Label listenPortLbl = new Label();
protected TextBox listenPortBox = new TextBox();
protected CheckBox fullScrnBox = new CheckBox();
protected Label rotateLbl = new Label();
protected ComboBox rotateBox = new ComboBox();
protected Label pixelSizeLbl = new Label();
protected ComboBox pixelSizeBox = new ComboBox();
protected Label cliScalingLbl = new Label();
protected ComboBox cliScalingBox = new ComboBox();
protected Label cliScalingWidthLbl = new Label();
protected TextBox cliScalingWidthBox = new TextBox();
protected Label cliScalingHeightLbl = new Label();
protected TextBox cliScalingHeightBox = new TextBox();
protected Label servScalingLbl = new Label();
protected ComboBox servScalingBox = new ComboBox();
protected CheckBox viewOnlyBox = new CheckBox();
protected CheckBox shareServBox = new CheckBox();
protected CheckBox scrnUpdAlgoBox = new CheckBox();
protected EventHandler okHdr = null;
protected EventHandler cancelHdr = null;
protected EventHandler aboutHdr = null;
protected EventHandler saveDefsHdr = null;
protected EventHandler restoreDefsHdr = null;
internal SessDlg() : base()
{
viewOpts = new ViewOpts();
SetupHdrs();
}
internal SessDlg(ViewOpts viewOpts) : base()
{
this.viewOpts = viewOpts;
SetupHdrs();
}
private void SetupHdrs()
{
okHdr = new EventHandler(OkClicked);
cancelHdr = new EventHandler(CancelClicked);
aboutHdr = new EventHandler(AboutClicked);
saveDefsHdr = new EventHandler(SaveDefsClicked);
restoreDefsHdr = new EventHandler(RestoreDefsClicked);
}
internal ConnOpts ConnOpts
{
get
{
if(connMode == ConnMode.Active)
return new ConnOpts(host, port, passwd, viewOpts);
else
return new ConnOpts(port, passwd, viewOpts);
}
}
protected ConnMode ConnMode
{
get
{
return listenBox.Checked? ConnMode.Passive : ConnMode.Active;
}
}
private void AboutClicked(object sender, EventArgs e)
{
App.AboutBox();
}
protected void Ok()
{
if(!ValidateCliScaling())
return;
GetConnMode();
if(connMode == ConnMode.Active)
{
if(!ValidateHostPort())
return;
}
else
{
if(!ValidateListenPort())
return;
}
GetPasswd();
GetOptions();
if(connMode == ConnMode.Active)
SaveConnHist();
DialogResult = DialogResult.OK;
}
private void OkClicked(object sender, EventArgs e)
{
Ok();
}
protected void Cancel()
{
DialogResult = DialogResult.Cancel;
}
private void CancelClicked(object sender, EventArgs e)
{
Cancel();
}
protected bool ValidateCliScaling()
{
if(cliScalingBox.Text != App.GetStr("Custom"))
return true;
try
{
if(UInt16.Parse(cliScalingWidthBox.Text) > 0 && UInt16.Parse(cliScalingHeightBox.Text) > 0)
return true;
else
return false;
}
catch(FormatException)
{
MessageBox.Show(App.GetStr("Customized client-side scaling width or height is invalid!"),
Text,
MessageBoxButtons.OK,
MessageBoxIcon.Exclamation,
MessageBoxDefaultButton.Button1);
return false;
}
catch(OverflowException)
{
// TODO: Something more descriptive.
MessageBox.Show(App.GetStr("Customized client-side scaling width or height is invalid!"),
Text,
MessageBoxButtons.OK,
MessageBoxIcon.Exclamation,
MessageBoxDefaultButton.Button1);
return false;
}
}
protected void GetConnMode()
{
connMode = listenBox.Checked? ConnMode.Passive : ConnMode.Active;
}
protected bool ValidateHostPort()
{
int indexOfColon = remoteEndPt.Text.IndexOf(':');
if(indexOfColon < 0) // Colon not found.
{
if(remoteEndPt.Text.Length > 0)
{
host = remoteEndPt.Text;
port = VncPort;
}
else // Empty string.
{
MessageBox.Show(App.GetStr("Please specify the VNC server to connect to!"),
Text,
MessageBoxButtons.OK,
MessageBoxIcon.Exclamation,
MessageBoxDefaultButton.Button1);
return false;
}
}
// Colon at the beginning or at the end.
else if(indexOfColon == 0 || indexOfColon == remoteEndPt.Text.Length - 1)
{
MessageBox.Show(App.GetStr("Please specify the host and/or the display/port to connect to!"),
Text,
MessageBoxButtons.OK,
MessageBoxIcon.Exclamation,
MessageBoxDefaultButton.Button1);
return false;
}
else
{
// Double colon at the end.
if(indexOfColon == remoteEndPt.Text.Length - 2 && remoteEndPt.Text[indexOfColon + 1] == ':')
{
MessageBox.Show(App.GetStr("Please specify the port to connect to!"),
Text,
MessageBoxButtons.OK,
MessageBoxIcon.Exclamation,
MessageBoxDefaultButton.Button1);
return false;
}
else
{
int portOffset = VncPort;
int portStart = indexOfColon + 1;
if(remoteEndPt.Text[indexOfColon + 1] == ':') // Double colon.
{
portOffset = 0;
portStart = indexOfColon + 2;
}
string portStr = remoteEndPt.Text.Substring(portStart);
try
{
port = Int32.Parse(portStr);
if(port < 0)
throw new OverflowException();
}
catch(FormatException)
{
MessageBox.Show(App.GetStr("The port is invalid!"),
Text,
MessageBoxButtons.OK,
MessageBoxIcon.Exclamation,
MessageBoxDefaultButton.Button1);
return false;
}
catch(OverflowException)
{
MessageBox.Show(App.GetStr("The port is invalid!"),
Text,
MessageBoxButtons.OK,
MessageBoxIcon.Exclamation,
MessageBoxDefaultButton.Button1);
return false;
}
port += portOffset;
// TODO: Compare this with min/max port numbers.
host = remoteEndPt.Text.Substring(0, indexOfColon);
}
}
return true;
}
protected bool ValidateListenPort()
{
if(listenPortBox.Text.Length > 0)
{
try
{
port = Int32.Parse(listenPortBox.Text);
if(port < 0)
throw new OverflowException();
}
catch(FormatException)
{
MessageBox.Show(App.GetStr("The listening port is invalid!"),
Text,
MessageBoxButtons.OK,
MessageBoxIcon.Exclamation,
MessageBoxDefaultButton.Button1);
return false;
}
catch(OverflowException)
{
MessageBox.Show(App.GetStr("The listening port is invalid!"),
Text,
MessageBoxButtons.OK,
MessageBoxIcon.Exclamation,
MessageBoxDefaultButton.Button1);
return false;
}
}
else
port = VncListenPort;
return true;
}
protected void GetPasswd()
{
passwd = passwdBox.Text;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -