blob: ccf80f36251326ff859ef8298f33c55a6ffca1f5 [file] [log] [blame]
Constantin Kaplinsky729598c2006-05-25 05:12:25 +00001/* Copyright (C) 2002-2005 RealVNC Ltd. All Rights Reserved.
2 *
3 * This is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation; either version 2 of the License, or
6 * (at your option) any later version.
7 *
8 * This software is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this software; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
16 * USA.
17 */
18
19#include <windows.h>
20#include <winsock2.h>
21#include <vncviewer/UserPasswdDialog.h>
22#include <vncviewer/CConn.h>
23#include <vncviewer/CConnThread.h>
24#include <vncviewer/resource.h>
25#include <rfb/encodings.h>
26#include <rfb/secTypes.h>
27#include <rfb/CSecurityNone.h>
28#include <rfb/CSecurityVncAuth.h>
29#include <rfb/CMsgWriter.h>
30#include <rfb/Configuration.h>
31#include <rfb/LogWriter.h>
32#include <rfb_win32/AboutDialog.h>
33
34using namespace rfb;
35using namespace rfb::win32;
36using namespace rdr;
37
38// - Statics & consts
39
40static LogWriter vlog("CConn");
41
42
43const int IDM_FULLSCREEN = ID_FULLSCREEN;
44const int IDM_SEND_MENU_KEY = ID_SEND_MENU_KEY;
45const int IDM_SEND_CAD = ID_SEND_CAD;
46const int IDM_SEND_CTLESC = ID_SEND_CTLESC;
47const int IDM_ABOUT = ID_ABOUT;
48const int IDM_OPTIONS = ID_OPTIONS;
49const int IDM_INFO = ID_INFO;
50const int IDM_NEWCONN = ID_NEW_CONNECTION;
51const int IDM_REQUEST_REFRESH = ID_REQUEST_REFRESH;
52const int IDM_CTRL_KEY = ID_CTRL_KEY;
53const int IDM_ALT_KEY = ID_ALT_KEY;
54const int IDM_FILE_TRANSFER = ID_FILE_TRANSFER;
55const int IDM_CONN_SAVE_AS = ID_CONN_SAVE_AS;
george824f72ab32006-09-10 05:13:45 +000056const int IDM_ZOOM_IN = ID_ZOOM_IN;
57const int IDM_ZOOM_OUT = ID_ZOOM_OUT;
58const int IDM_ACTUAL_SIZE = ID_ACTUAL_SIZE;
59const int IDM_AUTO_SIZE = ID_AUTO_SIZE;
Constantin Kaplinsky729598c2006-05-25 05:12:25 +000060
61
62static IntParameter debugDelay("DebugDelay","Milliseconds to display inverted "
63 "pixel data - a debugging feature", 0);
64
65
66//
67// -=- CConn implementation
68//
69
70RegKey CConn::userConfigKey;
71
72
73CConn::CConn()
74 : window(0), sock(0), sockEvent(CreateEvent(0, TRUE, FALSE, 0)), requestUpdate(false),
75 sameMachine(false), encodingChange(false), formatChange(false),
76 reverseConnection(false), lastUsedEncoding_(encodingRaw), isClosed_(false) {
77}
78
79CConn::~CConn() {
80 delete window;
81}
82
83bool CConn::initialise(network::Socket* s, bool reverse) {
84 // Set the server's name for MRU purposes
85 CharArray endpoint(s->getPeerEndpoint());
86 setServerName(endpoint.buf);
87 if (!options.host.buf)
88 options.setHost(endpoint.buf);
89
90 // Initialise the underlying CConnection
91 setStreams(&s->inStream(), &s->outStream());
92
93 // Enable processing of window messages while blocked on I/O
94 s->inStream().setBlockCallback(this);
95
96 // Initialise the viewer options
97 applyOptions(options);
98
99 // - Set which auth schemes we support, in order of preference
100 addSecType(secTypeVncAuth);
101 addSecType(secTypeNone);
102
103 // Start the RFB protocol
104 sock = s;
105 reverseConnection = reverse;
106 initialiseProtocol();
107
108 m_fileTransfer.initialize(&s->inStream(), &s->outStream());
109
110 return true;
111}
112
113
114void
115CConn::applyOptions(CConnOptions& opt) {
116 // - If any encoding-related settings have changed then we must
117 // notify the server of the new settings
118 encodingChange |= ((options.useLocalCursor != opt.useLocalCursor) ||
119 (options.useDesktopResize != opt.useDesktopResize) ||
120 (options.customCompressLevel != opt.customCompressLevel) ||
121 (options.compressLevel != opt.compressLevel) ||
122 (options.noJpeg != opt.noJpeg) ||
123 (options.qualityLevel != opt.qualityLevel) ||
124 (options.preferredEncoding != opt.preferredEncoding));
125
126 // - If the preferred pixel format has changed then notify the server
127 formatChange |= (options.fullColour != opt.fullColour);
128 if (!opt.fullColour)
129 formatChange |= (options.lowColourLevel != opt.lowColourLevel);
130
131 // - Save the new set of options
132 options = opt;
133
134 // - Set optional features in ConnParams
135 cp.supportsLocalCursor = options.useLocalCursor;
136 cp.supportsDesktopResize = options.useDesktopResize;
137 cp.customCompressLevel = options.customCompressLevel;
138 cp.compressLevel = options.compressLevel;
139 cp.noJpeg = options.noJpeg;
140 cp.qualityLevel = options.qualityLevel;
141
142 // - Configure connection sharing on/off
143 setShared(options.shared);
144
145 // - Whether to use protocol 3.3 for legacy compatibility
146 setProtocol3_3(options.protocol3_3);
147
148 // - Apply settings that affect the window, if it is visible
149 if (window) {
150 window->setMonitor(options.monitor.buf);
151 window->setFullscreen(options.fullScreen);
152 window->setEmulate3(options.emulate3);
153 window->setPointerEventInterval(options.pointerEventInterval);
154 window->setMenuKey(options.menuKey);
155 window->setDisableWinKeys(options.disableWinKeys);
156 window->setShowToolbar(options.showToolbar);
george82ffc14a62006-09-05 06:51:41 +0000157 if (options.autoScaling) {
158 window->setAutoScaling(true);
159 } else {
160 window->setAutoScaling(false);
161 window->setDesktopScale(options.scale);
162 }
Constantin Kaplinsky729598c2006-05-25 05:12:25 +0000163 if (!options.useLocalCursor)
164 window->setCursor(0, 0, Point(), 0, 0);
165 }
166}
167
168
169void
170CConn::displayChanged() {
171 // Display format has changed - recalculate the full-colour pixel format
172 calculateFullColourPF();
173}
174
175void
176CConn::paintCompleted() {
177 // A repaint message has just completed - request next update if necessary
178 requestNewUpdate();
179}
180
181bool
182CConn::sysCommand(WPARAM wParam, LPARAM lParam) {
183 // - If it's one of our (F8 Menu) messages
184 switch (wParam) {
185 case IDM_FULLSCREEN:
186 options.fullScreen = !window->isFullscreen();
187 window->setFullscreen(options.fullScreen);
188 return true;
george824f72ab32006-09-10 05:13:45 +0000189 case IDM_ZOOM_IN:
190 return true;
191 case IDM_ZOOM_OUT:
192 return true;
193 case IDM_ACTUAL_SIZE:
194 if (options.autoScaling) {
195 options.autoScaling = false;
196 window->setAutoScaling(false);
197 }
george824f72ab32006-09-10 05:13:45 +0000198 options.scale = 100;
199 window->setDesktopScale(100);
200 return true;
201 case IDM_AUTO_SIZE:
202 options.autoScaling = true;
203 window->setAutoScaling(true);
204 return true;
Constantin Kaplinsky729598c2006-05-25 05:12:25 +0000205 case IDM_SHOW_TOOLBAR:
206 options.showToolbar = !window->isToolbarEnabled();
207 window->setShowToolbar(options.showToolbar);
208 return true;
209 case IDM_CTRL_KEY:
210 window->kbd.keyEvent(this, VK_CONTROL, 0, !window->kbd.keyPressed(VK_CONTROL));
211 return true;
212 case IDM_ALT_KEY:
213 window->kbd.keyEvent(this, VK_MENU, 0, !window->kbd.keyPressed(VK_MENU));
214 return true;
215 case IDM_SEND_MENU_KEY:
216 window->kbd.keyEvent(this, options.menuKey, 0, true);
217 window->kbd.keyEvent(this, options.menuKey, 0, false);
218 return true;
219 case IDM_SEND_CAD:
220 window->kbd.keyEvent(this, VK_CONTROL, 0, true);
221 window->kbd.keyEvent(this, VK_MENU, 0, true);
222 window->kbd.keyEvent(this, VK_DELETE, 0x1000000, true);
223 window->kbd.keyEvent(this, VK_DELETE, 0x1000000, false);
224 window->kbd.keyEvent(this, VK_MENU, 0, false);
225 window->kbd.keyEvent(this, VK_CONTROL, 0, false);
226 return true;
227 case IDM_SEND_CTLESC:
228 window->kbd.keyEvent(this, VK_CONTROL, 0, true);
229 window->kbd.keyEvent(this, VK_ESCAPE, 0, true);
230 window->kbd.keyEvent(this, VK_ESCAPE, 0, false);
231 window->kbd.keyEvent(this, VK_CONTROL, 0, false);
232 return true;
233 case IDM_REQUEST_REFRESH:
234 try {
235 writer()->writeFramebufferUpdateRequest(Rect(0,0,cp.width,cp.height), false);
236 requestUpdate = false;
237 } catch (rdr::Exception& e) {
238 close(e.str());
239 }
240 return true;
241 case IDM_NEWCONN:
242 {
243 Thread* newThread = new CConnThread;
244 }
245 return true;
246 case IDM_OPTIONS:
247 // Update the monitor device name in the CConnOptions instance
248 options.monitor.replaceBuf(window->getMonitor());
249 showOptionsDialog();
250 return true;
251 case IDM_INFO:
252 infoDialog.showDialog(this);
253 return true;
254 case IDM_ABOUT:
255 AboutDialog::instance.showDialog();
256 return true;
257 case IDM_FILE_TRANSFER:
258 m_fileTransfer.show(window->getHandle());
259 return true;
260 case IDM_CONN_SAVE_AS:
261 return true;
Constantin Kaplinsky729598c2006-05-25 05:12:25 +0000262 };
263 return false;
264}
265
266
267void
268CConn::closeWindow() {
269 vlog.info("window closed");
270 close();
271}
272
273
274void
275CConn::refreshMenu(bool enableSysItems) {
276 HMENU menu = GetSystemMenu(window->getHandle(), FALSE);
277
278 if (!enableSysItems) {
279 // Gray out menu items that might cause a World Of Pain
280 EnableMenuItem(menu, SC_SIZE, MF_BYCOMMAND | MF_GRAYED);
281 EnableMenuItem(menu, SC_MOVE, MF_BYCOMMAND | MF_GRAYED);
282 EnableMenuItem(menu, SC_RESTORE, MF_BYCOMMAND | MF_ENABLED);
283 EnableMenuItem(menu, SC_MINIMIZE, MF_BYCOMMAND | MF_ENABLED);
284 EnableMenuItem(menu, SC_MAXIMIZE, MF_BYCOMMAND | MF_ENABLED);
285 }
286
287 // Update the modifier key menu items
288 UINT ctrlCheckFlags = window->kbd.keyPressed(VK_CONTROL) ? MF_CHECKED : MF_UNCHECKED;
289 UINT altCheckFlags = window->kbd.keyPressed(VK_MENU) ? MF_CHECKED : MF_UNCHECKED;
290 CheckMenuItem(menu, IDM_CTRL_KEY, MF_BYCOMMAND | ctrlCheckFlags);
291 CheckMenuItem(menu, IDM_ALT_KEY, MF_BYCOMMAND | altCheckFlags);
292
293 // Ensure that the Send <MenuKey> menu item has the correct text
294 if (options.menuKey) {
295 TCharArray menuKeyStr(options.menuKeyName());
296 TCharArray tmp(_tcslen(menuKeyStr.buf) + 6);
297 _stprintf(tmp.buf, _T("Send %s"), menuKeyStr.buf);
298 if (!ModifyMenu(menu, IDM_SEND_MENU_KEY, MF_BYCOMMAND | MF_STRING, IDM_SEND_MENU_KEY, tmp.buf))
299 InsertMenu(menu, IDM_SEND_CAD, MF_BYCOMMAND | MF_STRING, IDM_SEND_MENU_KEY, tmp.buf);
300 } else {
301 RemoveMenu(menu, IDM_SEND_MENU_KEY, MF_BYCOMMAND);
302 }
303
304 // Set the menu fullscreen option tick
305 CheckMenuItem(menu, IDM_FULLSCREEN, (window->isFullscreen() ? MF_CHECKED : 0) | MF_BYCOMMAND);
306
307 // Set the menu toolbar option tick
308 int toolbarFlags = window->isToolbarEnabled() ? MF_CHECKED : 0;
309 CheckMenuItem(menu, IDM_SHOW_TOOLBAR, MF_BYCOMMAND | toolbarFlags);
310
311 // In the full-screen mode, "Show toolbar" should be grayed.
312 toolbarFlags = window->isFullscreen() ? MF_GRAYED : MF_ENABLED;
313 EnableMenuItem(menu, IDM_SHOW_TOOLBAR, MF_BYCOMMAND | toolbarFlags);
314}
315
316
317void
318CConn::blockCallback() {
319 // - An InStream has blocked on I/O while processing an RFB message
320 // We re-enable socket event notifications, so we'll know when more
321 // data is available, then we sit and dispatch window events until
322 // the notification arrives.
323 if (!isClosed()) {
324 if (WSAEventSelect(sock->getFd(), sockEvent, FD_READ | FD_CLOSE) == SOCKET_ERROR)
325 throw rdr::SystemException("Unable to wait for sokcet data", WSAGetLastError());
326 }
327 while (true) {
328 // If we have closed then we can't block waiting for data
329 if (isClosed())
330 throw rdr::EndOfStream();
331
332 // Wait for socket data, or a message to process
333 DWORD result = MsgWaitForMultipleObjects(1, &sockEvent.h, FALSE, INFINITE, QS_ALLINPUT);
334 if (result == WAIT_OBJECT_0) {
335 // - Network event notification. Return control to I/O routine.
336 break;
337 } else if (result == WAIT_FAILED) {
338 // - The wait operation failed - raise an exception
339 throw rdr::SystemException("blockCallback wait error", GetLastError());
340 }
341
342 // - There should be a message in the message queue
343 MSG msg;
344 while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) {
345 // IMPORTANT: We mustn't call TranslateMessage() here, because instead we
346 // call ToAscii() in CKeyboard::keyEvent(). ToAscii() stores dead key
347 // state from one call to the next, which would be messed up by calls to
348 // TranslateMessage() (actually it looks like TranslateMessage() calls
349 // ToAscii() internally).
350 DispatchMessage(&msg);
351 }
352 }
353
354 // Before we return control to the InStream, reset the network event
355 WSAEventSelect(sock->getFd(), sockEvent, 0);
356 ResetEvent(sockEvent);
357}
358
359
360void CConn::keyEvent(rdr::U32 key, bool down) {
361 if (!options.sendKeyEvents) return;
362 try {
363 writer()->keyEvent(key, down);
364 } catch (rdr::Exception& e) {
365 close(e.str());
366 }
367}
368void CConn::pointerEvent(const Point& pos, int buttonMask) {
369 if (!options.sendPtrEvents) return;
370 try {
371 writer()->pointerEvent(pos, buttonMask);
372 } catch (rdr::Exception& e) {
373 close(e.str());
374 }
375}
376void CConn::clientCutText(const char* str, int len) {
377 if (!options.clientCutText) return;
378 if (state() != RFBSTATE_NORMAL) return;
379 try {
380 writer()->clientCutText(str, len);
381 } catch (rdr::Exception& e) {
382 close(e.str());
383 }
384}
385
386
387CSecurity* CConn::getCSecurity(int secType)
388{
389 switch (secType) {
390 case secTypeNone:
391 return new CSecurityNone();
392 case secTypeVncAuth:
393 return new CSecurityVncAuth(this);
394 default:
395 throw Exception("Unsupported secType?");
396 }
397}
398
399
400void
401CConn::setColourMapEntries(int first, int count, U16* rgbs) {
402 vlog.debug("setColourMapEntries: first=%d, count=%d", first, count);
403 int i;
404 for (i=0;i<count;i++)
405 window->setColour(i+first, rgbs[i*3], rgbs[i*3+1], rgbs[i*3+2]);
406 // *** change to 0, 256?
407 window->refreshWindowPalette(first, count);
408}
409
410void
411CConn::bell() {
412 if (options.acceptBell)
413 MessageBeep(-1);
414}
415
416
417void
418CConn::setDesktopSize(int w, int h) {
419 vlog.debug("setDesktopSize %dx%d", w, h);
420
421 // Resize the window's buffer
422 if (window)
423 window->setSize(w, h);
424
425 // Tell the underlying CConnection
426 CConnection::setDesktopSize(w, h);
427}
428
429void
430CConn::setCursor(int w, int h, const Point& hotspot, void* data, void* mask) {
431 if (!options.useLocalCursor) return;
432
433 // Set the window to use the new cursor
434 window->setCursor(w, h, hotspot, data, mask);
435}
436
437
438void
439CConn::close(const char* reason) {
440 // If already closed then ignore this
441 if (isClosed())
442 return;
443
444 // Hide the window, if it exists
445 if (window)
446 ShowWindow(window->getHandle(), SW_HIDE);
447
448 // Save the reason & flag that we're closed & shutdown the socket
449 isClosed_ = true;
450 closeReason_.replaceBuf(strDup(reason));
451 sock->shutdown();
452}
453
454
455void
456CConn::showOptionsDialog() {
457 optionsDialog.showDialog(this);
458}
459
460
461void
462CConn::framebufferUpdateEnd() {
463 if (debugDelay != 0) {
464 vlog.debug("debug delay %d",(int)debugDelay);
465 UpdateWindow(window->getHandle());
466 Sleep(debugDelay);
467 std::list<rfb::Rect>::iterator i;
468 for (i = debugRects.begin(); i != debugRects.end(); i++) {
469 window->invertRect(*i);
470 }
471 debugRects.clear();
472 }
473 if (options.autoSelect)
474 autoSelectFormatAndEncoding();
475
476 // Always request the next update
477 requestUpdate = true;
478
479 // Check that at least part of the window has changed
480 if (!GetUpdateRect(window->getHandle(), 0, FALSE)) {
481 if (!(GetWindowLong(window->getHandle(), GWL_STYLE) & WS_MINIMIZE))
482 requestNewUpdate();
483 }
484
485 // Make sure the local cursor is shown
486 window->showCursor();
487}
488
489
490// Note: The method below is duplicated in vncviewer_unix/CConn.cxx!
491
492// autoSelectFormatAndEncoding() chooses the format and encoding appropriate
493// to the connection speed:
494//
495// Above 16Mbps (timing for at least a second), switch to hextile
496// Otherwise, switch to ZRLE
497//
498// Above 256Kbps, use full colour mode
499//
500void
501CConn::autoSelectFormatAndEncoding() {
502 int kbitsPerSecond = sock->inStream().kbitsPerSecond();
503 unsigned int newEncoding = options.preferredEncoding;
504
505 bool newFullColour = options.fullColour;
506 unsigned int timeWaited = sock->inStream().timeWaited();
507
508 // Select best encoding
509 if (kbitsPerSecond > 16000 && timeWaited >= 10000) {
510 newEncoding = encodingHextile;
511 } else {
512 newEncoding = encodingZRLE;
513 }
514
515 if (newEncoding != options.preferredEncoding) {
516 vlog.info("Throughput %d kbit/s - changing to %s encoding",
517 kbitsPerSecond, encodingName(newEncoding));
518 options.preferredEncoding = newEncoding;
519 encodingChange = true;
520 }
521
522 if (kbitsPerSecond == 0) {
523 return;
524 }
525
526 if (cp.beforeVersion(3, 8)) {
527 // Xvnc from TightVNC 1.2.9 sends out FramebufferUpdates with
528 // cursors "asynchronously". If this happens in the middle of a
529 // pixel format change, the server will encode the cursor with
530 // the old format, but the client will try to decode it
531 // according to the new format. This will lead to a
532 // crash. Therefore, we do not allow automatic format change for
533 // old servers.
534 return;
535 }
536
537 // Select best color level
538 newFullColour = (kbitsPerSecond > 256);
539 if (newFullColour != options.fullColour) {
540 vlog.info("Throughput %d kbit/s - full color is now %s",
541 kbitsPerSecond,
542 newFullColour ? "enabled" : "disabled");
543 options.fullColour = newFullColour;
544 formatChange = true;
545 }
546}
547
548void
549CConn::requestNewUpdate() {
550 if (!requestUpdate) return;
551
552 if (formatChange) {
553 // Select the required pixel format
554 if (options.fullColour) {
555 window->setPF(fullColourPF);
556 } else {
557 switch (options.lowColourLevel) {
558 case 0:
559 window->setPF(PixelFormat(8,3,0,1,1,1,1,2,1,0));
560 break;
561 case 1:
562 window->setPF(PixelFormat(8,6,0,1,3,3,3,4,2,0));
563 break;
564 case 2:
565 window->setPF(PixelFormat(8,8,0,0,0,0,0,0,0,0));
566 break;
567 }
568 }
569
570 // Print the current pixel format
571 char str[256];
572 window->getPF().print(str, 256);
573 vlog.info("Using pixel format %s",str);
574
575 // Save the connection pixel format and tell server to use it
576 cp.setPF(window->getPF());
577 writer()->writeSetPixelFormat(cp.pf());
578
579 // Correct the local window's palette
580 if (!window->getNativePF().trueColour)
581 window->refreshWindowPalette(0, 1 << cp.pf().depth);
582 }
583
584 if (encodingChange) {
585 vlog.info("Using %s encoding",encodingName(options.preferredEncoding));
586 writer()->writeSetEncodings(options.preferredEncoding, true);
587 }
588
589 writer()->writeFramebufferUpdateRequest(Rect(0, 0, cp.width, cp.height),
590 !formatChange);
591
592 encodingChange = formatChange = requestUpdate = false;
593}
594
595
596void
597CConn::calculateFullColourPF() {
598 // If the server is palette based then use palette locally
599 // Also, don't bother doing bgr222
600 if (!serverDefaultPF.trueColour || (serverDefaultPF.depth < 6)) {
601 fullColourPF = serverDefaultPF;
602 options.fullColour = true;
603 } else {
604 // If server is trueColour, use lowest depth PF
605 PixelFormat native = window->getNativePF();
606 if ((serverDefaultPF.bpp < native.bpp) ||
607 ((serverDefaultPF.bpp == native.bpp) &&
608 (serverDefaultPF.depth < native.depth)))
609 fullColourPF = serverDefaultPF;
610 else
611 fullColourPF = window->getNativePF();
612 }
613 formatChange = true;
614}
615
616
617void
618CConn::setName(const char* name) {
619 if (window)
620 window->setName(name);
621 CConnection::setName(name);
622}
623
624
625void CConn::serverInit() {
626 CConnection::serverInit();
627
628 // If using AutoSelect with old servers, start in FullColor
629 // mode. See comment in autoSelectFormatAndEncoding.
630 if (cp.beforeVersion(3, 8) && options.autoSelect) {
631 options.fullColour = true;
632 }
633
634 // Show the window
635 window = new DesktopWindow(this);
636 window->setName(cp.name());
637 window->setSize(cp.width, cp.height);
george82d2c22522006-09-10 11:45:19 +0000638 applyOptions(options);
Constantin Kaplinsky729598c2006-05-25 05:12:25 +0000639
640 // Save the server's current format
641 serverDefaultPF = cp.pf();
642
643 // Calculate the full-colour format to use
644 calculateFullColourPF();
645
646 // Request the initial update
647 vlog.info("requesting initial update");
648 formatChange = encodingChange = requestUpdate = true;
649 requestNewUpdate();
650
651 // Update the window menu
652 HMENU wndmenu = GetSystemMenu(window->getHandle(), FALSE);
653 int toolbarChecked = options.showToolbar ? MF_CHECKED : 0;
654
655 AppendMenu(wndmenu, MF_SEPARATOR, 0, 0);
656 AppendMenu(wndmenu, MF_STRING, IDM_FULLSCREEN, _T("&Full screen"));
657 AppendMenu(wndmenu, MF_STRING | toolbarChecked, IDM_SHOW_TOOLBAR,
658 _T("Show tool&bar"));
659 AppendMenu(wndmenu, MF_SEPARATOR, 0, 0);
660 AppendMenu(wndmenu, MF_STRING, IDM_CTRL_KEY, _T("Ctr&l"));
661 AppendMenu(wndmenu, MF_STRING, IDM_ALT_KEY, _T("Al&t"));
662 AppendMenu(wndmenu, MF_STRING, IDM_SEND_CAD, _T("Send Ctrl-Alt-&Del"));
663 AppendMenu(wndmenu, MF_STRING, IDM_SEND_CTLESC, _T("Send Ctrl-&Esc"));
664 AppendMenu(wndmenu, MF_STRING, IDM_REQUEST_REFRESH, _T("Refres&h Screen"));
665 AppendMenu(wndmenu, MF_SEPARATOR, 0, 0);
666 AppendMenu(wndmenu, MF_STRING, IDM_NEWCONN, _T("Ne&w Connection..."));
667 AppendMenu(wndmenu, MF_STRING, IDM_OPTIONS, _T("&Options..."));
668 AppendMenu(wndmenu, MF_STRING, IDM_INFO, _T("Connection &Info..."));
669 AppendMenu(wndmenu, MF_STRING, IDM_ABOUT, _T("&About..."));
670}
671
672void
673CConn::serverCutText(const char* str, int len) {
674 if (!options.serverCutText) return;
675 window->serverCutText(str, len);
676}
677
678
679void CConn::beginRect(const Rect& r, unsigned int encoding) {
680 sock->inStream().startTiming();
681}
682
683void CConn::endRect(const Rect& r, unsigned int encoding) {
684 sock->inStream().stopTiming();
685 lastUsedEncoding_ = encoding;
686 if (debugDelay != 0) {
687 window->invertRect(r);
688 debugRects.push_back(r);
689 }
690}
691
692void CConn::fillRect(const Rect& r, Pixel pix) {
693 window->fillRect(r, pix);
694}
695void CConn::imageRect(const Rect& r, void* pixels) {
696 window->imageRect(r, pixels);
697}
698void CConn::copyRect(const Rect& r, int srcX, int srcY) {
699 window->copyRect(r, srcX, srcY);
700}
701
702void CConn::getUserPasswd(char** user, char** password) {
703 if (!user && options.passwordFile.buf[0]) {
704 FILE* fp = fopen(options.passwordFile.buf, "rb");
705 if (fp) {
706 char data[256];
707 int datalen = fread(data, 1, 256, fp);
708 fclose(fp);
709 if (datalen == 8) {
710 ObfuscatedPasswd obfPwd;
711 obfPwd.buf = data;
712 obfPwd.length = datalen;
713 PlainPasswd passwd(obfPwd);
714 *password = strDup(passwd.buf);
715 memset(data, 0, strlen(data));
716 }
717 }
718 }
719 if (user && options.userName.buf)
720 *user = strDup(options.userName.buf);
721 if (password && options.password.buf)
722 *password = strDup(options.password.buf);
723 if ((user && !*user) || (password && !*password)) {
724 // Missing username or password - prompt the user
725 UserPasswdDialog userPasswdDialog;
726 userPasswdDialog.setCSecurity(getCurrentCSecurity());
727 userPasswdDialog.getUserPasswd(user, password);
728 }
729 if (user) options.setUserName(*user);
730 if (password) options.setPassword(*password);
731}
732
733bool CConn::processFTMsg(int type) {
734 return m_fileTransfer.processFTMsg(type);
735}