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.

475 lines
12 KiB

  1. //
  2. // MAIN.CPP
  3. // Whiteboard Windows App Code
  4. //
  5. // Copyright Microsoft 1998-
  6. //
  7. // PRECOMP
  8. #include "precomp.h"
  9. WbMainWindow * g_pMain;
  10. HINSTANCE g_hInstance;
  11. IWbClient* g_pwbCore;
  12. UINT g_uConfShutdown;
  13. WbPrinter * g_pPrinter;
  14. BOOL g_bPalettesInitialized;
  15. BOOL g_bUsePalettes;
  16. HPALETTE g_hRainbowPaletteDisplay;
  17. HINSTANCE g_hImmLib;
  18. IGC_PROC g_fnImmGetContext;
  19. INI_PROC g_fnImmNotifyIME;
  20. //
  21. // Arrays
  22. //
  23. COLORREF g_ColorTable[NUM_COLOR_ENTRIES] =
  24. {
  25. RGB( 0, 255, 255), // Cyan
  26. RGB(255, 255, 0), // Yellow
  27. RGB(255, 0, 255), // Magenta
  28. RGB( 0, 0, 255), // Blue
  29. RGB(192, 192, 192), // Grey
  30. RGB(255, 0, 0), // Red
  31. RGB( 0, 0, 128), // Dark blue
  32. RGB( 0, 128, 128), // Dark cyan
  33. RGB( 0, 255, 0), // Green
  34. RGB( 0, 128, 0), // Dark green
  35. RGB(128, 0, 0), // Dark red
  36. RGB(128, 0, 128), // Purple
  37. RGB(128, 128, 0), // Olive
  38. RGB(128, 128, 128), // Grey
  39. RGB(255, 255, 255), // White
  40. RGB( 0, 0, 0), // Black
  41. RGB(255, 128, 0), // Orange
  42. RGB(128, 255, 255), // Turquoise
  43. RGB( 0, 128, 255), // Mid blue
  44. RGB( 0, 255, 128), // Pale green
  45. RGB(255, 0, 128) // Dark pink
  46. };
  47. int g_ClipboardFormats[CLIPBOARD_ACCEPTABLE_FORMATS] =
  48. {
  49. 0, // CLIPBOARD_PRIVATE_SINGLE_OBJ - Reserved for the
  50. // Whiteboard private format
  51. 0,
  52. CF_DIB, // Standard formats
  53. CF_ENHMETAFILE, // move metafiles to lower pri than bitmaps (bug NM4db:411)
  54. CF_TEXT
  55. };
  56. // Default widths for all tools except for highlighters
  57. UINT g_PenWidths[NUM_OF_WIDTHS] = { 2, 4, 8, 16 };
  58. // Default widths for highlight tools
  59. UINT g_HighlightWidths[NUM_OF_WIDTHS] = { 4, 8, 16, 32 };
  60. //
  61. // Objects
  62. //
  63. WbUserList * g_pUsers;
  64. WbDrawingArea * g_pDraw;
  65. DCWbColorToIconMap * g_pIcons;
  66. #ifdef _DEBUG
  67. HDBGZONE ghZoneWb;
  68. PTCHAR g_rgZonesWb[] = // CHECK ZONE_WBxxx CONSTANTS IF THESE CHANGE
  69. {
  70. "OldWB",
  71. DEFAULT_ZONES
  72. "DEBUG",
  73. "MSG",
  74. "TIMER",
  75. "EVENT"
  76. };
  77. #endif // _DEBUG
  78. ///////////////////////////////////////////////////////////////////////////
  79. /* D L L M A I N */
  80. /*-------------------------------------------------------------------------
  81. %%Function: DllMain
  82. -------------------------------------------------------------------------*/
  83. BOOL WINAPI DllMain(HINSTANCE hDllInst, DWORD fdwReason, LPVOID lpv)
  84. {
  85. switch (fdwReason)
  86. {
  87. case DLL_PROCESS_ATTACH:
  88. {
  89. #ifdef _DEBUG
  90. MLZ_DbgInit((PSTR *) &g_rgZonesWb[0],
  91. (sizeof(g_rgZonesWb) / sizeof(g_rgZonesWb[0])) - 1);
  92. #endif
  93. g_hInstance = hDllInst;
  94. DisableThreadLibraryCalls(g_hInstance);
  95. DBG_INIT_MEMORY_TRACKING(hDllInst);
  96. break;
  97. }
  98. case DLL_PROCESS_DETACH:
  99. {
  100. g_hInstance = NULL;
  101. DBG_CHECK_MEMORY_TRACKING(hDllInst);
  102. #ifdef _DEBUG
  103. MLZ_DbgDeInit();
  104. #endif
  105. break;
  106. }
  107. default:
  108. break;
  109. }
  110. return TRUE;
  111. }
  112. //
  113. // Whiteboard's init routine
  114. //
  115. BOOL WINAPI InitWB(void)
  116. {
  117. BOOL fInited = FALSE;
  118. ASSERT(!g_pMain);
  119. ASSERT(!g_hImmLib);
  120. ASSERT(!g_fnImmGetContext);
  121. ASSERT(!g_fnImmNotifyIME);
  122. //
  123. // Load IMM32 if this is FE
  124. //
  125. if (GetSystemMetrics(SM_DBCSENABLED))
  126. {
  127. g_hImmLib = NmLoadLibrary("imm32.dll",TRUE);
  128. if (!g_hImmLib)
  129. {
  130. ERROR_OUT(("Failed to load imm32.dll"));
  131. }
  132. else
  133. {
  134. g_fnImmGetContext = (IGC_PROC)GetProcAddress(g_hImmLib, "ImmGetContext");
  135. if (!g_fnImmGetContext)
  136. {
  137. ERROR_OUT(("Failed to get ImmGetContext pointer"));
  138. }
  139. g_fnImmNotifyIME = (INI_PROC)GetProcAddress(g_hImmLib, "ImmNotifyIME");
  140. if (!g_fnImmNotifyIME)
  141. {
  142. ERROR_OUT(("Failed to get ImmNotifyIME pointer"));
  143. }
  144. }
  145. }
  146. g_pMain = new WbMainWindow();
  147. if (!g_pMain)
  148. {
  149. ERROR_OUT(("Can't create WbMainWindow"));
  150. goto Done;
  151. }
  152. //
  153. // OK, now we're ready to create our HWND
  154. //
  155. if (!g_pMain->Open(SW_SHOWDEFAULT))
  156. {
  157. ERROR_OUT(("Can't create WB windows"));
  158. goto Done;
  159. }
  160. fInited = TRUE;
  161. Done:
  162. return(fInited);
  163. }
  164. //
  165. // Whiteboard's term routine
  166. //
  167. void WINAPI TermWB(void)
  168. {
  169. if (g_pMain != NULL)
  170. {
  171. delete g_pMain;
  172. g_pMain = NULL;
  173. }
  174. g_fnImmNotifyIME = NULL;
  175. g_fnImmGetContext = NULL;
  176. if (g_hImmLib)
  177. {
  178. FreeLibrary(g_hImmLib);
  179. g_hImmLib = NULL;
  180. }
  181. }
  182. //
  183. // Whiteboard's thread handler
  184. //
  185. void WINAPI RunWB(void)
  186. {
  187. ASSERT(g_pMain != NULL);
  188. //
  189. // Try to join call
  190. //
  191. //
  192. // Find out if we're in a call and join if so.
  193. //
  194. if (!g_pMain->JoinDomain())
  195. {
  196. ERROR_OUT(("WB couldn't start up and join call"));
  197. return;
  198. }
  199. //
  200. // MESSAGE LOOP
  201. //
  202. MSG msg;
  203. while (::GetMessage(&msg, NULL, NULL, NULL))
  204. {
  205. if (!g_pMain->FilterMessage(&msg))
  206. {
  207. ::TranslateMessage(&msg);
  208. ::DispatchMessage(&msg);
  209. }
  210. }
  211. }
  212. //
  213. // Mapping of internal return codes to string resources
  214. //
  215. typedef struct tagERROR_MAP
  216. {
  217. UINT uiFEReturnCode;
  218. UINT uiDCGReturnCode;
  219. UINT uiCaption;
  220. UINT uiMessage;
  221. }
  222. ERROR_MAP;
  223. ERROR_MAP g_ErrorStringID[] =
  224. {
  225. { WBFE_RC_JOIN_CALL_FAILED, // Registration failed
  226. 0,
  227. IDS_MSG_CAPTION,
  228. IDS_MSG_JOIN_CALL_FAILED
  229. },
  230. { WBFE_RC_WINDOWS, // A windows error has occurred
  231. 0,
  232. IDS_MSG_CAPTION,
  233. IDS_MSG_WINDOWS_RESOURCES
  234. },
  235. { WBFE_RC_WB, // Page limit exceeded
  236. WB_RC_TOO_MANY_PAGES,
  237. IDS_MSG_CAPTION,
  238. IDS_MSG_TOO_MANY_PAGES
  239. },
  240. { WBFE_RC_WB, // Another user has the contents lock
  241. WB_RC_LOCKED,
  242. IDS_MSG_CAPTION,
  243. IDS_MSG_LOCKED
  244. },
  245. { WBFE_RC_WB, // Another user has the graphic locked
  246. WB_RC_GRAPHIC_LOCKED,
  247. IDS_MSG_CAPTION,
  248. IDS_MSG_GRAPHIC_LOCKED,
  249. },
  250. { WBFE_RC_WB, // The local user does not have the lock
  251. WB_RC_NOT_LOCKED,
  252. IDS_MSG_CAPTION,
  253. IDS_MSG_NOT_LOCKED
  254. },
  255. { WBFE_RC_WB, // File is not in expected format
  256. WB_RC_BAD_FILE_FORMAT,
  257. IDS_MSG_CAPTION,
  258. IDS_MSG_BAD_FILE_FORMAT
  259. },
  260. { WBFE_RC_WB, // Whiteboard busy (exhausted page cache)
  261. WB_RC_BUSY,
  262. IDS_MSG_CAPTION,
  263. IDS_MSG_BUSY
  264. },
  265. { WBFE_RC_CM, // Failed to access call manager
  266. 0,
  267. IDS_MSG_CAPTION,
  268. IDS_MSG_CM_ERROR
  269. },
  270. { WBFE_RC_AL, // Failed to register with application loader
  271. 0,
  272. IDS_MSG_CAPTION,
  273. IDS_MSG_AL_ERROR
  274. },
  275. { WBFE_RC_PRINTER, // Failed to register with application loader
  276. 0,
  277. IDS_MSG_CAPTION,
  278. IDS_MSG_PRINTER_ERROR
  279. },
  280. { 0, // Catch-all default
  281. 0,
  282. IDS_MSG_CAPTION,
  283. IDS_MSG_DEFAULT
  284. }
  285. };
  286. //
  287. //
  288. // Function: Message
  289. //
  290. // Purpose: Display an error message box with string resources specified
  291. // as parameters, with the WB main window as the modal window.
  292. //
  293. //
  294. int Message
  295. (
  296. HWND hwnd,
  297. UINT uiCaption,
  298. UINT uiMessage,
  299. UINT uiStyle
  300. )
  301. {
  302. TCHAR message[256];
  303. TCHAR caption[256];
  304. //make sure we're on top
  305. ASSERT(g_pMain);
  306. if (!hwnd)
  307. hwnd = g_pMain->m_hwnd;
  308. if (hwnd != NULL)
  309. {
  310. ::SetForegroundWindow(hwnd);
  311. }
  312. LoadString(g_hInstance, uiMessage, message, 256);
  313. LoadString(g_hInstance, uiCaption, caption, 256);
  314. //
  315. // BOGUS LAURABU:
  316. // Make use of MessageBoxEx() and just pass the string IDs along,
  317. // rather than doing the LoadString() ourself.
  318. //
  319. // Display a message box with the relevant text
  320. return(::MessageBox(hwnd, message, caption, uiStyle));
  321. }
  322. //
  323. //
  324. // Function: ErrorMessage
  325. //
  326. // Purpose: Display an error based on return codes from Whiteboard
  327. // processing.
  328. //
  329. //
  330. void ErrorMessage(UINT uiFEReturnCode, UINT uiDCGReturnCode)
  331. {
  332. MLZ_EntryOut(ZONE_FUNCTION, "::ErrorMessage (codes)");
  333. TRACE_MSG(("FE return code = %hd", uiFEReturnCode));
  334. TRACE_MSG(("DCG return code = %hd", uiDCGReturnCode));
  335. // check for special OM_RC_OBJECT_DELETED case
  336. if (uiDCGReturnCode == OM_RC_OBJECT_DELETED)
  337. {
  338. // don't complain, just cancel drawing
  339. g_pMain->m_drawingArea.CancelDrawingMode();
  340. return;
  341. }
  342. // Find the associated string resource IDS
  343. int iIndex;
  344. for (iIndex = 0; ; iIndex++)
  345. {
  346. // If we have come to the end of the list, stop
  347. if (g_ErrorStringID[iIndex].uiFEReturnCode == 0)
  348. {
  349. break;
  350. }
  351. // Check for a match
  352. if (g_ErrorStringID[iIndex].uiFEReturnCode == uiFEReturnCode)
  353. {
  354. if ( (g_ErrorStringID[iIndex].uiDCGReturnCode == uiDCGReturnCode)
  355. || (g_ErrorStringID[iIndex].uiDCGReturnCode == 0))
  356. {
  357. break;
  358. }
  359. }
  360. }
  361. // Display the message
  362. Message(NULL, g_ErrorStringID[iIndex].uiCaption, g_ErrorStringID[iIndex].uiMessage);
  363. }
  364. //
  365. //
  366. // Function: DefaultExceptionHandler
  367. //
  368. // Purpose: Default exception processing. This can be called in an
  369. // exception handler to get a message relevant to the
  370. // exception. The message is generated by posting a message to
  371. // the applications main window.
  372. //
  373. //
  374. void DefaultExceptionHandler(UINT uiFEReturnCode, UINT uiDCGReturnCode)
  375. {
  376. MLZ_EntryOut(ZONE_FUNCTION, "DefaultExceptionHandler");
  377. // Post a message to the main window to get the error displayed
  378. if (g_pMain != NULL)
  379. {
  380. // check for special OM_RC_OBJECT_DELETED case
  381. if (uiDCGReturnCode == OM_RC_OBJECT_DELETED)
  382. {
  383. // don't complain, just cancel drawing
  384. g_pMain->m_drawingArea.CancelDrawingMode();
  385. return;
  386. }
  387. if (g_pMain->m_hwnd)
  388. ::PostMessage(g_pMain->m_hwnd, WM_USER_DISPLAY_ERROR, uiFEReturnCode, uiDCGReturnCode);
  389. }
  390. }