Source code of Windows XP (NT5)
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.

522 lines
12 KiB

  1. /**********************************************************************/
  2. /** Microsoft Windows/NT **/
  3. /** Copyright(c) Microsoft Corp., 1991 **/
  4. /**********************************************************************/
  5. /*
  6. sendmsg.cxx
  7. This file contains the SEND_MSG_USER_DIALOG class definition viz.
  8. used to send a message from the users dialog and
  9. SEND_MSG_SERVER_DIALOG viz used to send a message to all the users
  10. connected with the server.
  11. The 2 dialogs SEND_MSG_USER_DIALOG and SEND_MSG_SERVER_DIALOG are
  12. very similar and can easily be subclassed. The amount of code saved
  13. would be minimal if anything at all. Therefore this hs not been done.
  14. FILE HISTORY:
  15. NarenG 16-Oct-1992 Folded MSG_DIALOG_BASE and
  16. SEND_MESSAGE_DIALOG into one.
  17. */
  18. extern "C"
  19. {
  20. #include <nt.h>
  21. #include <ntrtl.h>
  22. #include <nturtl.h>
  23. }
  24. #define INCL_WINDOWS
  25. #define INCL_WINDOWS_GDI
  26. #define INCL_DOSERRORS
  27. #define INCL_NETERRORS
  28. #define INCL_NETCONS
  29. #define INCL_NETLIB
  30. #include <lmui.hxx>
  31. #define INCL_BLT_DIALOG
  32. #define INCL_BLT_CONTROL
  33. #define INCL_BLT_MSGPOPUP
  34. #include <blt.hxx>
  35. #if defined(DEBUG)
  36. static const CHAR szFileName[] = __FILE__;
  37. #define _FILENAME_DEFINED_ONCE szFileName
  38. #endif // DEBUG
  39. #include <uiassert.hxx>
  40. extern "C"
  41. {
  42. #include <afpmgr.h>
  43. #include <macfile.h>
  44. }
  45. #include <string.hxx>
  46. #include <senddlg.hxx>
  47. /*******************************************************************
  48. NAME: SEND_MSG_USER_DIALOG::SEND_MSG_USER_DIALOG
  49. SYNOPSIS: Constructor for AFP Manager Send Message Dialog
  50. ENTRY: Expects valid HWND for hDlg
  51. Must have server and user selection
  52. EXIT: Usual construction stuff, slt set to contain
  53. server of current focus.
  54. HISTORY:
  55. NarenG 16-Oct-1992 Created
  56. ********************************************************************/
  57. SEND_MSG_USER_DIALOG::SEND_MSG_USER_DIALOG(
  58. HWND hWndOwner,
  59. AFP_SERVER_HANDLE hServer,
  60. const TCHAR * pszServerName,
  61. const TCHAR * pszUserName,
  62. DWORD dwSessionId )
  63. : DIALOG_WINDOW( MAKEINTRESOURCE( IDD_SEND_MSG_USER_DIALOG ), hWndOwner ),
  64. _sltServerName( this, IDSM_DT_SERVER_NAME ),
  65. _sltUserName( this, IDSM_DT_USER_NAME ),
  66. _rgRecipients( this, IDSM_RB_SINGLE_USER, 2, IDSM_RB_SINGLE_USER ),
  67. _mleTextMsg( this, IDSM_ET_MESSAGE, AFP_MESSAGE_LEN ),
  68. _hServer( hServer ),
  69. _dwSessionId( dwSessionId )
  70. {
  71. //
  72. // Did everything construct properly ?
  73. //
  74. if ( QueryError() != NERR_Success )
  75. return;
  76. APIERR err;
  77. if ( (( err = _sltServerName.QueryError() ) != NERR_Success ) ||
  78. (( err = _sltUserName.QueryError() ) != NERR_Success ) ||
  79. (( err = _rgRecipients.QueryError() ) != NERR_Success ) ||
  80. (( err = _mleTextMsg.QueryError() ) != NERR_Success ) )
  81. {
  82. ReportError( err );
  83. return;
  84. }
  85. //
  86. // Must have a users and server selection
  87. //
  88. UIASSERT(pszServerName != NULL) ;
  89. UIASSERT(pszUserName != NULL) ;
  90. //
  91. // Set the server name after removing the backslashes
  92. //
  93. ALIAS_STR nlsServerName( pszServerName );
  94. UIASSERT( nlsServerName.QueryError() == NERR_Success );
  95. ISTR istr( nlsServerName );
  96. //
  97. // Skip the backslashes.
  98. //
  99. istr += 2;
  100. ALIAS_STR nlsWithoutPrefix( nlsServerName.QueryPch( istr ) );
  101. UIASSERT( nlsWithoutPrefix.QueryError() == NERR_Success );
  102. _sltServerName.SetText( nlsWithoutPrefix );
  103. _sltServerName.Enable( TRUE );
  104. //
  105. // Set the selected user's name
  106. //
  107. _sltUserName.SetText( pszUserName );
  108. _sltUserName.Enable( TRUE );
  109. //
  110. // Direct the message edit control not to add end-of-line
  111. // character from wordwrapped text lines.
  112. //
  113. _mleTextMsg.SetFmtLines(FALSE);
  114. }
  115. /*******************************************************************
  116. NAME: SEND_MSG_USER_DIALOG::~SEND_MSG_USER_DIALOG
  117. SYNOPSIS: this destructor does nothing
  118. HISTORY:
  119. NarenG 16-Oct-1992 Created
  120. ********************************************************************/
  121. SEND_MSG_USER_DIALOG::~SEND_MSG_USER_DIALOG()
  122. {
  123. //
  124. // This space intentionally left blank
  125. //
  126. }
  127. /*******************************************************************
  128. NAME: SEND_MSG_USER_DIALOG::QueryHelpContext
  129. SYNOPSIS: Query help text for SEND_MSG_USER_DIALOG
  130. HISTORY:
  131. NarenG 16-Oct-1992 Created
  132. ********************************************************************/
  133. ULONG SEND_MSG_USER_DIALOG::QueryHelpContext( void )
  134. {
  135. return HC_SEND_MSG_USER_DIALOG;
  136. }
  137. /*******************************************************************
  138. NAME: SEND_MSG_USER_DIALOG::OnOK
  139. SYNOPSIS: Replaces the OnOK in DIALOG_WINDOW. It gets the
  140. text from the MLE and sends it.
  141. HISTORY:
  142. NarenG 16-Oct-1992 Created
  143. ********************************************************************/
  144. BOOL SEND_MSG_USER_DIALOG::OnOK()
  145. {
  146. //
  147. // Set cursor to hour glass.
  148. //
  149. AUTO_CURSOR AutoCursor;
  150. AFP_MESSAGE_INFO AfpMsg;
  151. //
  152. // Find out whom to send the message to.
  153. //
  154. AfpMsg.afpmsg_session_id =
  155. ( _rgRecipients.QuerySelection() == IDSM_RB_ALL_USERS )
  156. ? 0 : _dwSessionId;
  157. //
  158. // Attempt to send the message
  159. //
  160. UINT cb = _mleTextMsg.QueryTextSize();
  161. //
  162. // Was there any text ?
  163. //
  164. if ( cb <= sizeof(TCHAR) ) // always has a terminating NULL
  165. {
  166. ::MsgPopup( this, IDS_NEED_TEXT_TO_SEND );
  167. _mleTextMsg.ClaimFocus();
  168. return(TRUE);
  169. }
  170. NLS_STR nlsMsgText( cb );
  171. APIERR err;
  172. if ( (( err = nlsMsgText.QueryError() ) != NERR_Success ) ||
  173. (( err = _mleTextMsg.QueryText( &nlsMsgText ) ) != NERR_Success ) )
  174. {
  175. ::MsgPopup( this, err );
  176. return(FALSE);
  177. }
  178. // MSKK HitoshiT modified to handle DBCS 94/09/01
  179. #ifdef DBCS
  180. UNICODE_STRING unistr;
  181. unistr.Length = nlsMsgText.QueryTextLength() * sizeof(WCHAR) ;
  182. unistr.MaximumLength = unistr.Length ;
  183. unistr.Buffer = (WCHAR *)nlsMsgText.QueryPch() ;
  184. if ( RtlUnicodeStringToOemSize( &unistr ) > AFP_MESSAGE_LEN )
  185. #else
  186. if ( nlsMsgText.QueryTextLength() > AFP_MESSAGE_LEN )
  187. #endif
  188. {
  189. ::MsgPopup( this, IDS_MESSAGE_TOO_LONG );
  190. _mleTextMsg.ClaimFocus();
  191. _mleTextMsg.SelectString();
  192. return(FALSE);
  193. }
  194. AfpMsg.afpmsg_text = (LPWSTR)(nlsMsgText.QueryPch());
  195. err = AfpAdminMessageSend( _hServer, &AfpMsg );
  196. switch( err )
  197. {
  198. case AFPERR_InvalidId:
  199. ::MsgPopup( this, IDS_SESSION_DELETED );
  200. Dismiss( FALSE );
  201. break;
  202. case NO_ERROR:
  203. ::MsgPopup( this, IDS_MESSAGE_SENT, MPSEV_INFO );
  204. Dismiss( TRUE );
  205. break;
  206. case AFPERR_InvalidSessionType:
  207. if ( _rgRecipients.QuerySelection() == IDSM_RB_ALL_USERS )
  208. ::MsgPopup( this, AFPERR_TO_STRINGID( err ) );
  209. else
  210. ::MsgPopup( this, IDS_NOT_RECEIVED );
  211. Dismiss( FALSE );
  212. break;
  213. default:
  214. ::MsgPopup( this, AFPERR_TO_STRINGID( err ) );
  215. Dismiss( FALSE );
  216. break;
  217. }
  218. return(TRUE);
  219. }
  220. /*******************************************************************
  221. NAME: SEND_MSG_SERVER_DIALOG::SEND_MSG_SERVER_DIALOG
  222. SYNOPSIS: Constructor for AFP Manager Send Message Dialog
  223. ENTRY: Expects valid HWND for hDlg
  224. Must have server selection
  225. EXIT: Usual construction stuff, slt set to contain
  226. server of current focus.
  227. HISTORY:
  228. NarenG 16-Oct-1992 Created
  229. ********************************************************************/
  230. SEND_MSG_SERVER_DIALOG::SEND_MSG_SERVER_DIALOG(
  231. HWND hWndOwner,
  232. AFP_SERVER_HANDLE hServer,
  233. const TCHAR * pszServerName )
  234. : DIALOG_WINDOW( MAKEINTRESOURCE( IDD_SEND_MSG_SERVER_DIALOG ), hWndOwner ),
  235. _sltServerName( this, IDSD_DT_SERVER_NAME ),
  236. _mleTextMsg( this, IDSD_ET_MESSAGE, AFP_MESSAGE_LEN ),
  237. _hServer( hServer )
  238. {
  239. //
  240. // Did everything construct properly ?
  241. //
  242. if ( QueryError() != NERR_Success )
  243. return;
  244. APIERR err;
  245. if ( (( err = _sltServerName.QueryError() ) != NERR_Success ) ||
  246. (( err = _mleTextMsg.QueryError() ) != NERR_Success ) )
  247. {
  248. ReportError( err );
  249. return;
  250. }
  251. //
  252. // Must have a users and server selection
  253. //
  254. UIASSERT(pszServerName != NULL) ;
  255. //
  256. // Set the server name after removing the backslashes
  257. //
  258. ALIAS_STR nlsServerName( pszServerName );
  259. UIASSERT( nlsServerName.QueryError() == NERR_Success );
  260. ISTR istr( nlsServerName );
  261. //
  262. // Skip the backslashes.
  263. //
  264. istr += 2;
  265. ALIAS_STR nlsWithoutPrefix( nlsServerName.QueryPch( istr ) );
  266. UIASSERT( nlsWithoutPrefix.QueryError() == NERR_Success );
  267. _sltServerName.SetText( nlsWithoutPrefix );
  268. _sltServerName.Enable( TRUE );
  269. //
  270. // Direct the message edit control not to add end-of-line
  271. // character from wordwrapped text lines.
  272. //
  273. _mleTextMsg.SetFmtLines(FALSE);
  274. }
  275. /*******************************************************************
  276. NAME: SEND_MSG_SERVER_DIALOG::~SEND_MSG_SERVER_DIALOG
  277. SYNOPSIS: this destructor does nothing
  278. HISTORY:
  279. NarenG 16-Oct-1992 Created
  280. ********************************************************************/
  281. SEND_MSG_SERVER_DIALOG::~SEND_MSG_SERVER_DIALOG()
  282. {
  283. //
  284. // This space intentionally left blank
  285. //
  286. }
  287. /*******************************************************************
  288. NAME: SEND_MSG_SERVER_DIALOG::QueryHelpContext
  289. SYNOPSIS: Query help text for SEND_MSG_SERVER_DIALOG
  290. HISTORY:
  291. NarenG 16-Oct-1992 Created
  292. ********************************************************************/
  293. ULONG SEND_MSG_SERVER_DIALOG::QueryHelpContext( void )
  294. {
  295. return HC_SEND_MSG_SERVER_DIALOG;
  296. }
  297. /*******************************************************************
  298. NAME: SEND_MSG_SERVER_DIALOG::OnOK
  299. SYNOPSIS: Replaces the OnOK in DIALOG_WINDOW. It gets the
  300. text from the MLE and sends it.
  301. HISTORY:
  302. NarenG 16-Oct-1992 Created
  303. ********************************************************************/
  304. BOOL SEND_MSG_SERVER_DIALOG::OnOK()
  305. {
  306. //
  307. // Set cursor to hour glass.
  308. //
  309. AUTO_CURSOR AutoCursor;
  310. AFP_MESSAGE_INFO AfpMsg;
  311. //
  312. // Send a message to all the users.
  313. //
  314. AfpMsg.afpmsg_session_id = 0;
  315. //
  316. // Attempt to send the message
  317. //
  318. UINT cb = _mleTextMsg.QueryTextSize();
  319. //
  320. // Was there any text ?
  321. //
  322. if ( cb <= sizeof(TCHAR) ) // always has a terminating NULL
  323. {
  324. ::MsgPopup( this, IDS_NEED_TEXT_TO_SEND );
  325. _mleTextMsg.ClaimFocus();
  326. return(FALSE);
  327. }
  328. NLS_STR nlsMsgText( cb );
  329. APIERR err;
  330. if ( (( err = nlsMsgText.QueryError() ) != NERR_Success ) ||
  331. (( err = _mleTextMsg.QueryText( &nlsMsgText ) ) != NERR_Success ) )
  332. {
  333. ::MsgPopup( this, err );
  334. return(FALSE);
  335. }
  336. // MSKK HitoshiT modified to handle DBCS 94/09/01
  337. #ifdef DBCS
  338. UNICODE_STRING unistr;
  339. unistr.Length = nlsMsgText.QueryTextLength() * sizeof(WCHAR) ;
  340. unistr.MaximumLength = unistr.Length ;
  341. unistr.Buffer = (WCHAR *)nlsMsgText.QueryPch() ;
  342. if ( RtlUnicodeStringToOemSize( &unistr ) > AFP_MESSAGE_LEN )
  343. #else
  344. if ( nlsMsgText.QueryTextLength() > AFP_MESSAGE_LEN )
  345. #endif
  346. {
  347. ::MsgPopup( this, IDS_MESSAGE_TOO_LONG );
  348. _mleTextMsg.ClaimFocus();
  349. _mleTextMsg.SelectString();
  350. return(FALSE);
  351. }
  352. AfpMsg.afpmsg_text = (LPWSTR)(nlsMsgText.QueryPch());
  353. DWORD error = AfpAdminMessageSend( _hServer, &AfpMsg );
  354. if ( error != NO_ERROR )
  355. {
  356. ::MsgPopup( this, AFPERR_TO_STRINGID(error) );
  357. Dismiss( FALSE );
  358. }
  359. else
  360. {
  361. ::MsgPopup( this, IDS_MESSAGE_SENT, MPSEV_INFO );
  362. Dismiss( TRUE );
  363. }
  364. return(TRUE);
  365. }