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.

413 lines
11 KiB

  1. #ifndef __NMCHATCTL_H_
  2. #define __NMCHATCTL_H_
  3. // Includes
  4. #include "resource.h"
  5. #include "richedit.h"
  6. #include "message.h"
  7. #include <confreg.h>
  8. #include <gencontrols.h>
  9. #include <gencontainers.h>
  10. #include "Chatldr.h"
  11. typedef ULONG_PTR MEMBER_ID; // loword = node_id, hiword = user_id
  12. extern HINSTANCE g_hInstance;
  13. #define STRING_RESOURCE_MODULE g_hInstance
  14. #define RES2T(uID, psz ) ( Res2THelper( uID, psz, RES_CH_MAX ) )
  15. #include <standrd.h>
  16. #define DECLARE_NMAPPLET_FILE_OPEN_FILTER(idStringResourceFilter, idStringResourceExt) \
  17. static HRESULT _GetNmAppletFileOpenFilter( LPTSTR szFilter, int cchMaxFilter, LPTSTR szExtension, int cchMaxExtension )\
  18. { HRESULT hr = S_OK;\
  19. DBGENTRY(_GetNmAppletFileOpenFilter);\
  20. if( SUCCEEDED( hr = NmCtlLoadString( idStringResourceFilter, szFilter, cchMaxFilter ) ) )\
  21. {\
  22. hr = NmCtlLoadString( idStringResourceExt, szExtension, cchMaxExtension );\
  23. }\
  24. DBGEXIT_HR(_GetNmAppletFileOpenFilter,hr);\
  25. return hr;\
  26. }
  27. //
  28. // Extra windows messages for the chat
  29. //
  30. enum
  31. {
  32. WM_USER_BRING_TO_FRONT_WINDOW = WM_USER,
  33. };
  34. #define RES_CH_MAX 256
  35. #define MAX_FONT_SIZE 20
  36. #define STATUSBAR_HEIGHT (MAX_FONT_SIZE + 2*::GetSystemMetrics(SM_CYEDGE))
  37. // Forward Decls
  38. class CNmChatCtl;
  39. class CChatOptionsDlg;
  40. #define PIX_FROM_DLGU_X( XDLGU, XDBU ) MulDiv(XDLGU, XDBU, 4 )
  41. #define PIX_FROM_DLGU_Y( YDLGU, YDBU ) MulDiv(YDLGU, YDBU, 8 )
  42. #define CHAT_FLAG_NONE 0
  43. #define CHAT_PRINT_FLAG_PRINTING 1
  44. #define CHAT_PRINT_FLAG_PRINTDLG_INITIALIZED 2
  45. #define CHAT_PRINT_FLAG_ABORT 4
  46. #define CHAT_FLAG_DIRTYBIT 8
  47. #define TWIPSPERINCH 1440
  48. #define ICON_BIG_SIZE 32
  49. #define ICON_SMALL_SIZE 16
  50. #define INVALIDATE_BACKGROUND FALSE
  51. void _SetWindowRectOption(LPCRECT pcRect);
  52. void _GetWindowRectOption(LPRECT pRect);
  53. /////////////////////////////////////////////////////////////////////////////
  54. /////////////////////////////////////////////////////////////////////////////
  55. // CChatOptionsDlg
  56. /////////////////////////////////////////////////////////////////////////////
  57. /////////////////////////////////////////////////////////////////////////////
  58. class CChatOptionsDlg
  59. {
  60. friend CNmChatCtl;
  61. private:
  62. enum { FONT_MSGOUT,
  63. FONT_MSGIN,
  64. FONT_PRIVATEOUT,
  65. FONT_PRIVATEIN,
  66. FONT_MSGSYSTEM,
  67. FONT_COUNT
  68. };
  69. CNmChatCtl *m_pChatCtl;
  70. LOGFONT m_hMsgLogFonts[ FONT_COUNT ];
  71. COLORREF m_hMsgColors[ FONT_COUNT ];
  72. BOOL m_bDirtyFonts[ FONT_COUNT ];
  73. public:
  74. static WORD IDD;
  75. private:
  76. public:
  77. CChatOptionsDlg( CNmChatCtl *pChatCtl );
  78. static INT_PTR CALLBACK _OptionsDlgProc( HWND hDlg,UINT uiMsg, WPARAM wParam, LPARAM lParam );
  79. void OnCommand(WPARAM wParam);
  80. private:
  81. HWND m_hOptionsDlg;
  82. LRESULT OnInit(HWND hDlg);
  83. LRESULT OnHelp(LPARAM lParam);
  84. LRESULT OnHelpWhatsThis(WPARAM wParam);
  85. LRESULT OnOkClicked();
  86. LRESULT OnCancelClicked();
  87. LRESULT OnFontClicked(WORD wID);
  88. void _DisplayFontNameAndSize( int iFont );
  89. };
  90. /////////////////////////////////////////////////////////////////////////////
  91. /////////////////////////////////////////////////////////////////////////////
  92. // CNmChatCtl
  93. /////////////////////////////////////////////////////////////////////////////
  94. /////////////////////////////////////////////////////////////////////////////
  95. struct MEMBER_CHANNEL_ID;
  96. class CNmChatCtl
  97. {
  98. friend CChatOptionsDlg;
  99. public: // Data Decls
  100. enum eWndIDs{ MsgWndID = 1,
  101. MemberListWndID,
  102. EditWndID,
  103. SendWndID,
  104. StaticMessageID,
  105. StaticSendToID
  106. };
  107. enum eStates { state_Idle,
  108. state_MessageWaiting
  109. };
  110. enum eMenuPos { MENUPOS_FILE = 0,
  111. MENUPOS_EDIT,
  112. MENUPOS_VIEW,
  113. MENUPOS_HELP
  114. };
  115. private: // Data Decls
  116. // Constants
  117. enum {DXP_ICON_SMALL = 16 };
  118. enum {DYP_ICON_SMALL = 16 };
  119. enum {DYP_CHAT_EDIT = 46 };
  120. enum {DYP_CHAT_USERS = 46 };
  121. enum {DXP_CHAT_SEND = 46 };
  122. enum {DYP_CHAT_SEND = 46 };
  123. enum {DXP_CHAT_DEST = 100 };
  124. enum {CCHMAX_CHAT_MSG = 2048 };
  125. enum {CB_NM2_HDR = 8 };
  126. enum {ILV_NAME = 0 };
  127. enum {ILV_TIME = 1 };
  128. enum {ILV_TEXT = 2 };
  129. enum {MSG_EXTRA = 4 };
  130. enum {MAX_DATE = 10 };
  131. enum {DATE_EXTRA = 1 };
  132. enum {TIME_EXTRA = 1 };
  133. enum {MAX_NAME = 15 };
  134. enum {NAME_EXTRA = 1 };
  135. enum {MULTILINE_MSG_OFFSET = 5 };
  136. enum {MSGLIST_DLU_Y = 14 };
  137. enum {MSGLIST_VISMEMBERS = 5 };
  138. enum {SPACING_DLU_X = 4 };
  139. enum {STATIC_DLU_Y = 4 };
  140. // menu item group constants
  141. CONSTANT( CHAT_WITH_FILEMENU_NUM_EDITGROUP_ITEMS = 3 );
  142. CONSTANT( CHAT_WITH_FILEMENU_NUM_OBJECTGROUP_ITEMS = 0 );
  143. CONSTANT( CHAT_WITH_FILEMENU_NUM_HELPGROUP_ITEMS = 1 );
  144. CONSTANT( CHAT_WITHOUT_FILEMENU_NUM_EDITGROUP_ITEMS = 1 );
  145. CONSTANT( CHAT_WITHOUT_FILEMENU_NUM_OBJECTGROUP_ITEMS = CHAT_WITH_FILEMENU_NUM_OBJECTGROUP_ITEMS );
  146. CONSTANT( CHAT_WITHOUT_FILEMENU_NUM_HELPGROUP_ITEMS = CHAT_WITH_FILEMENU_NUM_HELPGROUP_ITEMS );
  147. // These are the icon indices for the listview icon bitmaps
  148. enum { II_PERSON_PERSON = 1,
  149. II_EXCLAMATION = 14,
  150. II_USER = 16
  151. };
  152. typedef enum eMsgStyles
  153. {
  154. MSGSTYLE_2_LINE_WRAP,
  155. MSGSTYLE_1_LINE_WRAP,
  156. MSGSTYLE_NO_WRAP
  157. } MSGSTYLE;
  158. protected: // Data
  159. HWND m_hWnd;
  160. HACCEL m_hAccelTable;
  161. static CNmChatCtl *ms_pThis;
  162. ULONG m_cchBufferSize;
  163. HIMAGELIST m_himlIconSmall;
  164. HINSTANCE m_hInstRichEd32;
  165. LPTSTR m_lpszOwnName;
  166. LPTSTR m_szPrivate;
  167. LPTSTR m_szTo;
  168. int m_iExtra;
  169. int m_iNameLen;
  170. LPTSTR m_lpszRichEdEOL;
  171. LPTSTR m_lpszRichEd;
  172. // Msg fonts and colors
  173. COLORREF m_hMsgColors[ CChatOptionsDlg::FONT_COUNT ];
  174. HFONT m_hMsgFonts[ CChatOptionsDlg::FONT_COUNT ];
  175. LOGFONT m_hMsgLogFonts[ CChatOptionsDlg::FONT_COUNT ];
  176. // UI sizing
  177. int m_iStaticLen;
  178. int m_iDLGUY;
  179. int m_iDLGUX;
  180. int m_iStaticY;
  181. // Msg style formats
  182. PARAFORMAT m_paraLine1;
  183. PARAFORMAT m_paraLine2;
  184. DWORD m_dwChatFlags;
  185. // For printing
  186. PRINTDLG m_PrintDlg;
  187. HWND m_hWndPrint;
  188. // Count of messages in conference for whether or not to display conference ended
  189. ULONG m_cMessages;
  190. // Saving
  191. LPTSTR m_lpszSaveFile;
  192. WORD m_wFileOffset;
  193. // Window stuff
  194. HWND m_hWndMsg; // Message window alias
  195. HWND m_hWndMemberList; // Destination (0=everyone)
  196. HWND m_hWndEdit; // Edit control
  197. HWND m_hWndSend; // Send Button
  198. HWND m_hWndStaticMessage;
  199. HWND m_hWndStaticSendTo;
  200. HWND m_hwndSB; // Status bar
  201. CBitmapButton * m_pButton;
  202. BOOL m_bWeAreActiveApp;
  203. HMENU m_hMenuShared;
  204. BOOL m_bStatusBarVisible;
  205. // Properties
  206. short m_bUseName;
  207. short m_bTimeStamp;
  208. short m_bUseDate;
  209. MSGSTYLE m_style;
  210. public: // Construction/destruction and initialization
  211. CNmChatCtl();
  212. ~CNmChatCtl();
  213. ULONG m_cOtherMembers;
  214. HWND GetMemberList(){return m_hWndMemberList;}
  215. protected:
  216. static LRESULT ChatMainWindowProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam);
  217. // Window Message and Command Handling functions for Main Window
  218. LRESULT OnCreate(WPARAM wParam, LPARAM lParam);
  219. LRESULT OnMenuSelect(UINT uMsg, WPARAM wParam, LPARAM lParam);
  220. LRESULT OnCharEditWnd(UINT uMsg, WPARAM wParam, LPARAM lParam);
  221. LRESULT OnInitMenuPopup(WPARAM wParam, LPARAM lParam);
  222. void OnSendClicked(void);
  223. LRESULT SaveDialog(LPTSTR lpszFile, DWORD dwFlags, LPWORD pnFileOffset );
  224. void cmdFileSave(void);
  225. void cmdFileSaveAs(void);
  226. void cmdFilePrint(void);
  227. void cmdFileExit(WPARAM wparam);
  228. void cmdViewStatusBar(void);
  229. LRESULT OnNotifyEnLink(ENLINK *pEnLink);
  230. LRESULT OnContextMenu(short, short);
  231. void cmdViewEditWindow(void);
  232. void cmdViewOptions(void);
  233. void cmdEditCut(void);
  234. void cmdEditCopy(void);
  235. void cmdEditPaste(void);
  236. void cmdEditClearAll(void);
  237. void cmdHelpHelpTopics(void);
  238. void cmdHelpAboutChat(void);
  239. protected:
  240. STDMETHOD(OnMenuSelect)( IN DWORD wParam, IN DWORD lParam );
  241. STDMETHOD(OnCommand)( IN WPARAM wParam, IN LPARAM lParam );
  242. protected:
  243. // INmChatCtl Interface implementation
  244. STDMETHOD(ResetView)();
  245. // These may be in the interface is the future...
  246. STDMETHOD(put_ShowName)(/*[in]*/ short bShowName );
  247. STDMETHOD(get_ShowName)(/*[out]*/ short *pbShowName );
  248. STDMETHOD(put_Timestamp)(/*[in]*/ short bUseTimeStamp );
  249. STDMETHOD(get_Timestamp)(/*[out]*/ short *pbUseTimeStamp );
  250. STDMETHOD(put_Date)(/*[in]*/ short bUseDate );
  251. STDMETHOD(get_Date)(/*[out]*/ short *pbUseDate );
  252. STDMETHOD(put_MsgStyle)(/*[in]*/ MSGSTYLE iStyle );
  253. MSGSTYLE get_MsgStyle();
  254. private: // Helper Fns
  255. static BOOL CALLBACK _AbortProc( HDC hdcPrinter, int iCode );
  256. static INT_PTR CALLBACK _PrintDlgProc( HWND hDlg, UINT uiMsg, WPARAM wParam, LPARAM lParam );
  257. static INT_PTR CALLBACK _AboutDlgProc( HWND hDlg, UINT uiMsg, WPARAM wParam, LPARAM lParam );
  258. // Notifitation helpers
  259. void _CalculateFontMetrics();
  260. void _DecrementNumOtherMembers( void );
  261. void _DeleteFonts( void );
  262. HRESULT _DeleteMemberListItem( int iIndex );
  263. void _DisplayMsg( CChatMessage *pChatMsg, BOOL bBatchRedraw = TRUE );
  264. bool _FCreate(HWND hwndParent);
  265. void _FreeView(void);
  266. HBITMAP _GetHBITMAP( DWORD dwID );
  267. HRESULT _GetOwnName();
  268. void _IncrementNumOtherMembers( void );
  269. bool _IsEditWindowVisibleFlagSet(void);
  270. bool _IsStatusBarVisibleFlagSet(void);
  271. void _InitFontsAndColors();
  272. void _FreeIconImages( void );
  273. void _LoadIconImages( void );
  274. void _LoadStrings();
  275. HRESULT _Print();
  276. void _PrintIt(HDC hPrinterDC );
  277. void _ReDisplayMessages();
  278. void _Redraw(void);
  279. void _Resize(int x, int y, int cx, int cy);
  280. HRESULT _SendChatText(void);
  281. void _SetContainerStatusText( UINT uID );
  282. HRESULT _SetMenuItemCheck( UINT idItem, BOOL bChecked = TRUE );
  283. void _SaveWindowPosition();
  284. void _SaveChatOptions();
  285. BOOL _LoadChatOptions();
  286. void _Save();
  287. int _SaveAs();
  288. void _ShiftFocus(HWND hwndCur, BOOL fForward);
  289. HRESULT _UpdateContainerStatusText( void );
  290. inline BOOL _IsPrinting();
  291. inline void _Write_Msg( LPTSTR pszText );
  292. inline void _Write_Msg_Range_Format( LPTSTR pszText, CHARRANGE& charRange, CHARFORMAT& charFormat );
  293. inline void _Write_Date_And_Time( LPTSTR pszText, CHARRANGE& charRange, CHARFORMAT& charFormat, CChatMessage *pChatMsg );
  294. inline void _Write_Name( LPTSTR pszText, CHARRANGE& charRange, CHARFORMAT& charFormat, CChatMessage *pChatMsg );
  295. inline void _Write_Own_Name( LPTSTR pszText, CHARRANGE& charRange, CHARFORMAT& charFormat );
  296. inline void _Write_Message( LPTSTR pszText, CHARRANGE& charRange, CHARFORMAT& charFormat, CChatMessage *pChatMsg );
  297. inline void _Write_Private_In( LPTSTR pszText, CHARRANGE& charRange, CHARFORMAT& charFormat, CChatMessage *pChatMsg );
  298. inline void _Write_Private_Out( LPTSTR pszText, CHARRANGE& charRange, CHARFORMAT& charFormat, CChatMessage *pChatMsg );
  299. inline void _Write_New_Line_If_Needed( CHARRANGE& charRange, CHARFORMAT& chatFormat );
  300. inline void _AddFontToCharFormat( CHARFORMAT& chatFormat, int i );
  301. public:
  302. BOOL FilterMessage(MSG* pMsg);
  303. void BringToFront(void);
  304. void _UpdateContainerCaption( void );
  305. void OnGetMinMaxInfo (LPMINMAXINFO lpmmi);
  306. HWND GetHandle(void){return m_hWnd;}
  307. int QueryEndSession(void);
  308. CChatOptionsDlg * m_pChatOptions;
  309. void _DataReceived(ULONG uSize, LPBYTE pb, T120ChannelID destinationID, T120UserID senderID);
  310. HRESULT _AddEveryoneInChat();
  311. MEMBER_ID _GetSelectedMember();
  312. HRESULT _AddMember(MEMBER_CHANNEL_ID *pMemberID);
  313. HRESULT _RemoveMember(MEMBER_CHANNEL_ID *pMemberID);
  314. void _DeleteAllListItems( void );
  315. DECLARE_NMAPPLET_FILE_OPEN_FILTER(IDS_CHAT_SAVE_FILTER_STRING, IDS_CHAT_SAVE_DEF_EXT )
  316. };
  317. #endif //__NMCHATCTL_H_