Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

CMsgWriter.cxx 3.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. /* 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. #include <stdio.h>
  19. #include <rdr/OutStream.h>
  20. #include <rfb/msgTypes.h>
  21. #include <rfb/PixelFormat.h>
  22. #include <rfb/Rect.h>
  23. #include <rfb/ConnParams.h>
  24. #include <rfb/Decoder.h>
  25. #include <rfb/CMsgWriter.h>
  26. using namespace rfb;
  27. CMsgWriter::CMsgWriter(ConnParams* cp_, rdr::OutStream* os_)
  28. : cp(cp_), os(os_)
  29. {
  30. }
  31. CMsgWriter::~CMsgWriter()
  32. {
  33. }
  34. void CMsgWriter::writeSetPixelFormat(const PixelFormat& pf)
  35. {
  36. startMsg(msgTypeSetPixelFormat);
  37. os->pad(3);
  38. pf.write(os);
  39. endMsg();
  40. }
  41. void CMsgWriter::writeSetEncodings(int nEncodings, rdr::U32* encodings)
  42. {
  43. startMsg(msgTypeSetEncodings);
  44. os->skip(1);
  45. os->writeU16(nEncodings);
  46. for (int i = 0; i < nEncodings; i++)
  47. os->writeU32(encodings[i]);
  48. endMsg();
  49. }
  50. // Ask for encodings based on which decoders are supported. Assumes higher
  51. // encoding numbers are more desirable.
  52. void CMsgWriter::writeSetEncodings(int preferredEncoding, bool useCopyRect)
  53. {
  54. int nEncodings = 0;
  55. rdr::U32 encodings[encodingMax+3];
  56. if (cp->supportsLocalCursor)
  57. encodings[nEncodings++] = pseudoEncodingCursor;
  58. if (cp->supportsDesktopResize)
  59. encodings[nEncodings++] = pseudoEncodingDesktopSize;
  60. if (cp->supportsDesktopRename)
  61. encodings[nEncodings++] = pseudoEncodingDesktopName;
  62. if (Decoder::supported(preferredEncoding)) {
  63. encodings[nEncodings++] = preferredEncoding;
  64. }
  65. if (useCopyRect) {
  66. encodings[nEncodings++] = encodingCopyRect;
  67. }
  68. for (int i = encodingMax; i >= 0; i--) {
  69. if (i != preferredEncoding && Decoder::supported(i)) {
  70. encodings[nEncodings++] = i;
  71. }
  72. }
  73. encodings[nEncodings++] = pseudoEncodingLastRect;
  74. if (cp->customCompressLevel && cp->compressLevel >= 0 && cp->compressLevel <= 9)
  75. encodings[nEncodings++] = pseudoEncodingCompressLevel0 + cp->compressLevel;
  76. if (!cp->noJpeg && cp->qualityLevel >= 1 && cp->qualityLevel <= 9)
  77. encodings[nEncodings++] = pseudoEncodingQualityLevel0 + cp->qualityLevel;
  78. writeSetEncodings(nEncodings, encodings);
  79. }
  80. void CMsgWriter::writeFramebufferUpdateRequest(const Rect& r, bool incremental)
  81. {
  82. startMsg(msgTypeFramebufferUpdateRequest);
  83. os->writeU8(incremental);
  84. os->writeU16(r.tl.x);
  85. os->writeU16(r.tl.y);
  86. os->writeU16(r.width());
  87. os->writeU16(r.height());
  88. endMsg();
  89. }
  90. void CMsgWriter::keyEvent(rdr::U32 key, bool down)
  91. {
  92. startMsg(msgTypeKeyEvent);
  93. os->writeU8(down);
  94. os->pad(2);
  95. os->writeU32(key);
  96. endMsg();
  97. }
  98. void CMsgWriter::pointerEvent(const Point& pos, int buttonMask)
  99. {
  100. Point p(pos);
  101. if (p.x < 0) p.x = 0;
  102. if (p.y < 0) p.y = 0;
  103. if (p.x >= cp->width) p.x = cp->width - 1;
  104. if (p.y >= cp->height) p.y = cp->height - 1;
  105. startMsg(msgTypePointerEvent);
  106. os->writeU8(buttonMask);
  107. os->writeU16(p.x);
  108. os->writeU16(p.y);
  109. endMsg();
  110. }
  111. void CMsgWriter::clientCutText(const char* str, int len)
  112. {
  113. startMsg(msgTypeClientCutText);
  114. os->pad(3);
  115. os->writeU32(len);
  116. os->writeBytes(str, len);
  117. endMsg();
  118. }