⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 vncoptions.cpp

📁 teamviewer source code vc++
💻 CPP
📖 第 1 页 / 共 2 页
字号:
//  Copyright (C) 2006 TeamViewer GmbH. All Rights Reserved.
//
//  TeamViewer 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.
//

// VnvConnOptions.cpp: implementation of the VNCOptions class. 

#include "stdhdrs.h"
#include "VNCOptions.h"
#include "vncviewer.h"
#include "CustomSettings.h"
#include "../winvnc/winvnc/localization.h"

VNCOptions::VNCOptions()
{
	m_resource = 0;
	m_SetFromCommandLine = false;

	m_ShowToolbar = true;							// display toolbar?
	m_FullScreen = false;							// use fullscreen?
	m_ActiveMode = rfbMC_TeamworkClient;			// Connection type
	m_Quality = 0;									// quality setting for remote control sessions
	m_ViewOnly = false;								// view only, do not send mouse/cursor actions
	m_clearPassword[0] = '\0';						// contains password if it was specified on command line
	m_RemoveWallpaper = false;							
	m_DisableInput = false;
	m_BlackScreen = false;

	// encoding
	m_PreferredEncoding = rfbEncodingZRLE;
	m_Use8Bit = rfbPFFullColors;
	m_compressLevel = DEFAULT_COMPRESSLEVEL;		// which compressionlevel?
	m_jpegQualityLevel = DEFAULT_JPEGLEVEL;			// which quality?
	m_Compression = 2;

	m_host[0] = '\0';
	m_port = 0;						

	// scaling	
	m_fAutoScaling = true;							// use autoscaling?
	m_scaling = true;								// use scaling?
	m_scale_num = 1;								// scaling numerator	
	m_scale_den = 1;								// scaling denumerator; scaling by numerator/denumerator
	m_nServerScale = 1;								// server scale factor 1/n, 1 <= n <= 9
	m_set_scale_num = 100;

	// mouse cursor settings
	//m_ignoreShapeUpdates = false;//true;
	//m_requestShapeUpdates = true;
	//show local and remote cursor in client mode
	ShowRemoteCursor(true);
	m_localCursor = NOCURSOR;//NORMALCURSOR;

	m_status_name[0] = '\0';
	m_status_encoding = 0;
	m_status_width = 0;
	m_status_height = 0;
	m_status_colors = 0;
	m_status_localcolors = 0;
	m_status_bytesread = 0;
	m_status_bytessent = 0;
}

VNCOptions::~VNCOptions()
{
	
}

VNCOptions& VNCOptions::operator=(VNCOptions& s)
{
	m_SetFromCommandLine = s.m_SetFromCommandLine;

	m_ShowToolbar = s.m_ShowToolbar;
	m_FullScreen = s.m_FullScreen;
	m_ActiveMode = s.m_ActiveMode;
	m_Quality = s.m_Quality;
	m_ViewOnly = s.m_ViewOnly;
	strncpy(m_clearPassword, s.m_clearPassword, MAXPWLEN);
	m_RemoveWallpaper = s.m_RemoveWallpaper;
	m_DisableInput = s.m_DisableInput;
	m_BlackScreen = s.m_BlackScreen;

	// encoding
	m_PreferredEncoding = s.m_PreferredEncoding;
	m_Use8Bit = s.m_Use8Bit;
	m_Compression = s.m_Compression;
	m_compressLevel = s.m_compressLevel;
	m_jpegQualityLevel = s.m_jpegQualityLevel;

	strncpy(m_host, s.m_host, 255);
	m_port = s.m_port;

	// scaling	
	m_fAutoScaling = s.m_fAutoScaling;
	m_scaling = s.m_scaling;
	m_scale_num = s.m_scale_num;
	m_scale_den = s.m_scale_den;
	m_nServerScale = s.m_nServerScale;
	m_set_scale_num = s.m_set_scale_num;

	// mouse cursor settings
	m_ignoreShapeUpdates = s.m_ignoreShapeUpdates;
	m_requestShapeUpdates = s.m_requestShapeUpdates;
	m_localCursor = s.m_localCursor;
	
	FixScaling();
	ApplyQuality();
	return *this;
}

void VNCOptions::ApplyQuality()
{
	switch(m_Quality)
	{
		case 0:		// autodetect
			m_PreferredEncoding = rfbEncodingTight;
			m_Use8Bit = rfbPF256Colors; 
			m_jpegQualityLevel = DEFAULT_JPEGLEVEL;
			m_compressLevel = DEFAULT_COMPRESSLEVEL;
			m_Compression = 1; // High Compression
			m_RemoveWallpaper = true;
			break;
		case 1:		// optimize quality
			m_PreferredEncoding = rfbEncodingZRLE;
			m_Use8Bit = rfbPFFullColors; 
			m_RemoveWallpaper = false;
			m_Compression = 2;  // Medium Compression
			break;
		case 2:		// optimize speed
			m_PreferredEncoding = rfbEncodingTight;
			m_Use8Bit = rfbPF256Colors; 
			m_jpegQualityLevel = DEFAULT_JPEGLEVEL;
			m_compressLevel = DEFAULT_COMPRESSLEVEL;
			m_Compression = 1; // High Compression
			m_RemoveWallpaper = true;
			break;

		default:	// custom settings
			CustomSettings::Compression2Encoding(m_Compression, &m_PreferredEncoding, &m_jpegQualityLevel, &m_compressLevel);
			break;
	}
}

void VNCOptions::FixScaling()
{
	if(m_scaling)
	{
		if(!m_fAutoScaling)
		{
			m_scale_num = m_set_scale_num;
			m_scale_den = 100;
		}
	}
	else
		m_scale_num = m_scale_den = 1;

	int g = gcd(m_scale_num, m_scale_den);
	m_scale_num /= g;
	m_scale_den /= g;	

	if (m_nServerScale < 1 || m_nServerScale > 9) 
	  m_nServerScale = 1;
}

// The dialog box allows you to change the session-specific parameters
int VNCOptions::DoDialog(HWND parent, int resource)
{
	m_resource = resource;
	return DialogBoxParam(pApp->m_instance, DIALOG_MAKEINTRESOURCE(m_resource), 
						parent, (DLGPROC) OptDlgProc, (LONG) this);
}


void VNCOptions::InitDialog(HWND hwnd)
{
	// Initialise the controls
	HWND hDisplayQuality = GetDlgItem(hwnd, IDC_CONN_QUALITY);

	SendMessage(hDisplayQuality, CB_ADDSTRING, 0, (LPARAM)sz_IDS_AUTOMATIC_QUALITY_SELECTION);
	SendMessage(hDisplayQuality, CB_ADDSTRING, 0, (LPARAM)sz_IDS_OPTIMIZE_QUALITY);
	SendMessage(hDisplayQuality, CB_ADDSTRING, 0, (LPARAM)sz_IDS_OPTIMIZE_SPEED);
	SendMessage(hDisplayQuality, CB_ADDSTRING, 0, (LPARAM)sz_IDS_CUSTOM_QUALITY);
	SendMessage(hDisplayQuality, CB_SETCURSEL, m_Quality, 0);
	EnableWindow(GetDlgItem(hwnd, IDC_CONN_CUSTOM), m_Quality == 3);

	CheckDlgButton(hwnd, IDC_CONN_VIEWONLY, m_ViewOnly);
	CheckDlgButton(hwnd, IDC_CONN_DINPUT, m_DisableInput);
	EnableWindow(GetDlgItem(hwnd, IDC_CONN_BLACKSCREEN), m_DisableInput);
	CheckDlgButton(hwnd, IDC_CONN_BLACKSCREEN, m_BlackScreen);

	SetDlgItemInt(hwnd, IDC_CONN_SERVERSCALE, m_nServerScale, FALSE);
	CheckDlgButton(hwnd, IDC_CONN_SCALING, m_scaling);
	CheckDlgButton(hwnd, IDC_CONN_AUTOSCALING, m_fAutoScaling);
	CheckDlgButton(hwnd, IDC_CONN_SCALE_CONSTANT, !m_fAutoScaling);
	CheckDlgButton(hwnd, IDC_SHOWREMOTECURSOR, !m_requestShapeUpdates);
//--
	AddDefaultScalings(GetDlgItem(hwnd, IDC_CONN_SCALEBY));
	SetDlgItemInt(hwnd, IDC_CONN_SCALEBY, m_set_scale_num, FALSE);
	EnableWindow(GetDlgItem(hwnd, IDC_CONN_AUTOSCALING), m_scaling);
	EnableWindow(GetDlgItem(hwnd, IDC_CONN_SCALE_CONSTANT), m_scaling);
	EnableWindow(GetDlgItem(hwnd, IDC_CONN_SCALEBY), m_scaling && !m_fAutoScaling);
	EnableWindow(GetDlgItem(hwnd, IDC_CONN_SCALE_LABEL), m_scaling && !m_fAutoScaling);

	// Status display
	SetDlgItemText(hwnd, IDC_STATUS_CONNECTEDTO, m_status_name);
	switch(m_PreferredEncoding)
	{
		case rfbEncodingZRLE: 
			SetDlgItemText(hwnd, IDC_STATUS_ENCODING, sz_IDS_ENC_ZRLE);
			break;
		case rfbEncodingHextile:
			SetDlgItemText(hwnd, IDC_STATUS_ENCODING, sz_IDS_ENC_HEXTILE);
			break;
		case rfbEncodingTight:
			SetDlgItemText(hwnd, IDC_STATUS_ENCODING, sz_IDS_ENC_TIGHT);
			break;
		case rfbEncodingRaw:
			SetDlgItemText(hwnd, IDC_STATUS_ENCODING, sz_IDS_ENC_NONE);
			break;
		default:
			SetDlgItemText(hwnd, IDC_STATUS_ENCODING, "unknown");
			break;
	}

	//SetDlgItemText(hwnd, IDC_STATUS_ENCODING, m_status_encoding);
	char s[100];
	if(m_status_width == 0 || m_status_height == 0)
		strcpy(s, "unknown");
	else
		sprintf(s, "%d x %d x %d", m_status_width, m_status_height, m_status_colors);
	SetDlgItemText(hwnd, IDC_STATUS_GEOMETRY, s);

	switch(m_Use8Bit)
	{
		case 0: strcpy(s, "Maximum"); break;
		case 1: strcpy(s, "256"); break;
		case 2: strcpy(s, "64"); break;
		case 3: strcpy(s, "8"); break;
		default: strcpy(s, "unknown");
	}
	SetDlgItemText(hwnd, IDC_STATUS_COLORS, s);

	if(m_status_bytesread < 1024)
		sprintf(s, "%d Bytes", m_status_bytesread);
	else
		sprintf(s, "%I64d K", m_status_bytesread/1024);
	SetDlgItemText(hwnd, IDC_STATUS_BYTESREAD, s);

	if(m_status_bytessent < 1024)
		sprintf(s, "%d Bytes", m_status_bytessent);
	else
		sprintf(s, "%I64d K", m_status_bytessent/1024);
	SetDlgItemText(hwnd, IDC_STATUS_BYTESSENT, s);

	if(m_status_readmax == 0)
		s[0] = '\0';
	else
		sprintf(s, "%d (%d/%d/%d)", m_status_readlast, m_status_readmin, m_status_readavg, m_status_readmax);
	SetDlgItemText(hwnd, IDC_STATUS_KBITS, s);

	HWND label = GetDlgItem(hwnd, IDC_CONN_HELPTEXT);
	WNDPROC oldHelpLabelProc = (WNDPROC) SetWindowLong(label, GWL_WNDPROC, (LONG)HelpTextProc);
	SetWindowLong(label, GWL_USERDATA, (LONG)oldHelpLabelProc);
	helptexts[GetDlgItem(hwnd, IDC_CONN_QUALITY)] = sz_IDS_HELP_REMOTE_QUALITY;
	helptexts[GetDlgItem(hwnd, IDC_CONN_SERVERSCALE)] = sz_IDS_HELP_REMOTE_SERVERSCALE;
	helptexts[GetDlgItem(hwnd, IDC_CONN_LABEL_SERVERSCALE)] = sz_IDS_HELP_REMOTE_SERVERSCALE;
	helptexts[GetDlgItem(hwnd, IDC_CONN_VIEWONLY)] = sz_IDS_HELP_REMOTE_VIEWONLY;
	helptexts[GetDlgItem(hwnd, IDC_CONN_DINPUT)] = sz_IDS_HELP_REMOTE_DINPUT;
	helptexts[GetDlgItem(hwnd, IDC_CONN_BLACKSCREEN)] = sz_IDS_HELP_REMOTE_BLACK;
	helptexts[GetDlgItem(hwnd, IDC_CONN_SCALING)] = sz_IDS_HELP_REMOTE_SCALING;
	helptexts[GetDlgItem(hwnd, IDC_CONN_AUTOSCALING)] = sz_IDS_HELP_REMOTE_AUTOSCALING;
	helptexts[GetDlgItem(hwnd, IDC_SHOWREMOTECURSOR)] = sz_IDS_HELP_REMOTE_SHOWREMOTECURSOR;
	helptexts[GetDlgItem(hwnd, IDC_CONN_SCALE_CONSTANT)] = sz_IDS_HELP_REMOTE_CONSTSCALING;

	CentreWindow(hwnd);
	SetWindowPos(hwnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_SHOWWINDOW|SWP_NOMOVE|SWP_NOSIZE);
	SetForegroundWindow(hwnd);
}

/*
ShowRemoteCursor shows or hides the local cursor.
This is only relevant for the client. It determines if the local cursor should be 
displayed additionaly to the remote cursor. In a weak connection this can improve
cursor aiming.
This function does not affect server mode!
The standard value TRUE is set in constructor VNCOptions::VNCOptions().

parameter doShow Shows (true) or hides (false) the local cursor in client mode.
return: returns the boolean value before this function was called.
*/
bool VNCOptions::ShowRemoteCursor(bool doShow)
{
	bool result = (!m_ignoreShapeUpdates && !m_requestShapeUpdates);
	if (doShow)
	{//ret true
		m_ignoreShapeUpdates = false;
		m_requestShapeUpdates = false;
		m_localCursor = NORMALCURSOR;
	}
	else

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -