Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

232 lines
5.9 KiB

  1. // watcherDoc.cpp : implementation of the CWatcherDoc class
  2. //
  3. #include "stdafx.h"
  4. #include "watcher.h"
  5. #include "watcherDoc.h"
  6. #ifdef _DEBUG
  7. #define new DEBUG_NEW
  8. #undef THIS_FILE
  9. static char THIS_FILE[] = __FILE__;
  10. #endif
  11. /////////////////////////////////////////////////////////////////////////////
  12. // CWatcherDoc
  13. IMPLEMENT_DYNCREATE(CWatcherDoc, CDocument)
  14. BEGIN_MESSAGE_MAP(CWatcherDoc, CDocument)
  15. //{{AFX_MSG_MAP(CWatcherDoc)
  16. // NOTE - the ClassWizard will add and remove mapping macros here.
  17. // DO NOT EDIT what you see in these blocks of generated code!
  18. //}}AFX_MSG_MAP
  19. END_MESSAGE_MAP()
  20. /////////////////////////////////////////////////////////////////////////////
  21. // CWatcherDoc construction/destruction
  22. CWatcherDoc::CWatcherDoc()
  23. {
  24. // TODO: add one-time construction code here
  25. COLORREF white = WHITE;
  26. COLORREF black = BLACK;
  27. int i,j,size;
  28. size = MAX_TERMINAL_WIDTH*MAX_TERMINAL_HEIGHT;
  29. INT_PTR nRet;
  30. nRet = Params.DoModal();
  31. if(nRet != IDOK){
  32. // kill document
  33. Params.DeleteValue = TRUE;
  34. return;
  35. }
  36. // TODO: add one-time construction code here
  37. memset(Data,0,MAX_TERMINAL_WIDTH*MAX_TERMINAL_HEIGHT*sizeof(TCHAR));
  38. for(i=0;i<size;i+=MAX_TERMINAL_WIDTH){
  39. for(j=0;j<MAX_TERMINAL_WIDTH;j++){
  40. Background[i+j] = black;
  41. Foreground[i+j] = white;
  42. }
  43. }
  44. return;
  45. }
  46. CWatcherDoc::CWatcherDoc(CString &machine, CString &command, UINT port,
  47. int tc, int lang,int hist, CString &lgnName, CString &lgnPasswd, CString &sess)
  48. {
  49. COLORREF white = WHITE;
  50. COLORREF black = BLACK;
  51. int i,j,size;
  52. size = MAX_TERMINAL_WIDTH*MAX_TERMINAL_HEIGHT;
  53. // TODO: add one-time construction code here
  54. Params.Machine = machine;
  55. Params.Command = command;
  56. Params.Port = port;
  57. Params.tcclnt = tc;
  58. Params.language = lang;
  59. Params.LoginName = lgnName;
  60. Params.LoginPasswd = lgnPasswd;
  61. Params.Session = sess;
  62. Params.history = hist;
  63. memset(Data,0,MAX_TERMINAL_WIDTH*MAX_TERMINAL_HEIGHT*sizeof(TCHAR));
  64. for(i=0;i<size;i+=MAX_TERMINAL_WIDTH){
  65. for(j=0;j<MAX_TERMINAL_WIDTH;j++){
  66. Background[i+j] = black;
  67. Foreground[i+j] = white;
  68. }
  69. }
  70. return;
  71. }
  72. CWatcherDoc::~CWatcherDoc()
  73. {
  74. }
  75. BOOL CWatcherDoc::OnNewDocument()
  76. {
  77. if (!CDocument::OnNewDocument())
  78. return FALSE;
  79. // TODO: add reinitialization code here
  80. // (SDI documents will reuse this document)
  81. return TRUE;
  82. }
  83. BOOL CWatcherDoc::OnOpenDocument(LPCTSTR lpszPathName)
  84. {
  85. return CDocument::OnOpenDocument(lpszPathName);
  86. }
  87. /////////////////////////////////////////////////////////////////////////////
  88. // CWatcherDoc serialization
  89. void CWatcherDoc::Serialize(CArchive& ar)
  90. {
  91. if (ar.IsStoring())
  92. {
  93. // TODO: add storing code here
  94. }
  95. else
  96. {
  97. // TODO: add loading code here
  98. }
  99. }
  100. /////////////////////////////////////////////////////////////////////////////
  101. // CWatcherDoc diagnostics
  102. #ifdef _DEBUG
  103. void CWatcherDoc::AssertValid() const
  104. {
  105. CDocument::AssertValid();
  106. }
  107. void CWatcherDoc::Dump(CDumpContext& dc) const
  108. {
  109. CDocument::Dump(dc);
  110. }
  111. #endif //_DEBUG
  112. /////////////////////////////////////////////////////////////////////////////
  113. // CWatcherDoc commands
  114. COLORREF * CWatcherDoc::GetBackground()
  115. {
  116. return (Background);
  117. }
  118. COLORREF * CWatcherDoc::GetForeground()
  119. {
  120. return (Foreground);
  121. }
  122. TCHAR * CWatcherDoc::GetData()
  123. {
  124. return (Data);
  125. }
  126. void CWatcherDoc::SetData(int x, int y, TCHAR byte,
  127. COLORREF foreground, COLORREF background)
  128. {
  129. if (x >= MAX_TERMINAL_WIDTH){
  130. return;
  131. }
  132. if (y>= MAX_TERMINAL_HEIGHT){
  133. return;
  134. }
  135. Data[x+y*MAX_TERMINAL_WIDTH] = byte;
  136. Foreground[x+y*MAX_TERMINAL_WIDTH] = foreground;
  137. Background[x+y*MAX_TERMINAL_WIDTH] = background;
  138. return;
  139. }
  140. void CWatcherDoc::SetData(int x, int y, BYTE byte, int n,
  141. COLORREF foreground, COLORREF background)
  142. {
  143. int i,j;
  144. i=MAX_TERMINAL_WIDTH*y + x;
  145. if (i+n > MAX_TERMINAL_WIDTH*MAX_TERMINAL_HEIGHT) {
  146. return;
  147. }
  148. memset(&(Data[i]),byte, n*sizeof(TCHAR));
  149. for(j=0;j<n;j++){
  150. Foreground[i+j] = foreground;
  151. Background[i+j] = background;
  152. }
  153. return;
  154. }
  155. TCHAR * CWatcherDoc::GetDataLine(int line)
  156. {
  157. return (&(Data[line*MAX_TERMINAL_WIDTH]));
  158. }
  159. BOOL CWatcherDoc::Lock()
  160. {
  161. return mutex.Lock(INFINITE);
  162. }
  163. BOOL CWatcherDoc::Unlock()
  164. {
  165. return mutex.Unlock();
  166. }
  167. void CWatcherDoc::ScrollData(BYTE byte, COLORREF foreground, COLORREF background,
  168. int ScrollTop, int ScrollBottom)
  169. {
  170. if ((ScrollTop < 1)||(ScrollBottom > MAX_TERMINAL_HEIGHT) || (ScrollTop > ScrollBottom)) {
  171. // error
  172. return;
  173. }
  174. int number = MAX_TERMINAL_WIDTH*(ScrollBottom - ScrollTop);
  175. int index1 = (ScrollTop-1)*MAX_TERMINAL_WIDTH;
  176. int index2 = index1 + MAX_TERMINAL_WIDTH;
  177. if (ScrollTop < ScrollBottom) {
  178. memmove(&(Data[index1]),&(Data[index2]), number*sizeof(TCHAR));
  179. memmove(&(Foreground[index1]),&(Foreground[index2]), number*sizeof(TCHAR));
  180. memmove(&(Background[index1]),&(Background[index2]), number*sizeof(TCHAR));
  181. }
  182. // number -= MAX_TERMINAL_WIDTH;
  183. index1 = MAX_TERMINAL_WIDTH*(ScrollBottom - 1);
  184. memset(&(Data[index1]), byte, MAX_TERMINAL_WIDTH*sizeof(TCHAR));
  185. for(int j=0;j<MAX_TERMINAL_WIDTH;j++){
  186. Foreground[index1+j] = foreground;
  187. Background[index1+j] = background;
  188. }
  189. return;
  190. }
  191. ParameterDialog & CWatcherDoc::GetParameters()
  192. {
  193. return Params;
  194. }