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.

394 lines
7.6 KiB

  1. //
  2. // TOOL.CPP
  3. // Drawing Tools
  4. //
  5. // Copyright Microsoft 1998-
  6. //
  7. // PRECOMP
  8. #include "precomp.h"
  9. #include "draw.hpp"
  10. //
  11. //
  12. // Function: WbTool
  13. //
  14. // Purpose: Constructors for tools
  15. //
  16. //
  17. WbTool::WbTool(int toolType)
  18. {
  19. COLORREF defColor;
  20. UINT defWidth;
  21. int iIndex;
  22. MLZ_EntryOut(ZONE_FUNCTION, "WbTool::WbTool");
  23. // Save the tool type
  24. m_toolType = toolType;
  25. m_selectedTool = TOOLTYPE_MAX;
  26. m_uiWidthIndexCur = 0;
  27. // Read the colors of the pen
  28. if (toolType == TOOLTYPE_HIGHLIGHT)
  29. defColor = DEF_HIGHLIGHTCOLOR;
  30. else
  31. defColor = DEF_PENCOLOR;
  32. m_clrCur = defColor;
  33. for (iIndex = 0; iIndex < NUM_OF_WIDTHS; iIndex++)
  34. {
  35. defWidth = (toolType == TOOLTYPE_HIGHLIGHT) ?
  36. g_HighlightWidths[iIndex] :
  37. g_PenWidths[iIndex];
  38. m_uiWidths[iIndex] = defWidth;
  39. }
  40. // Read the font details
  41. LOGFONT lfont;
  42. ::GetObject(::GetStockObject(DEFAULT_GUI_FONT), sizeof(LOGFONT), &lfont);
  43. lfont.lfClipPrecision |= CLIP_DFA_OVERRIDE;
  44. lfont.lfCharSet = DEFAULT_CHARSET;
  45. m_hFont = ::CreateFontIndirect(&lfont);
  46. }
  47. //
  48. // WbTool::~WbTool
  49. // Destructor
  50. //
  51. WbTool::~WbTool()
  52. {
  53. if (m_hFont != NULL)
  54. {
  55. ::DeleteFont(m_hFont);
  56. m_hFont = NULL;
  57. }
  58. }
  59. //
  60. //
  61. // Function: HasColor
  62. //
  63. // Purpose: Return TRUE if the tool supports colors
  64. //
  65. //
  66. BOOL WbTool::HasColor(void)
  67. {
  68. BOOL bResult = TRUE;
  69. switch (m_toolType)
  70. {
  71. case TOOLTYPE_ERASER:
  72. bResult = FALSE;
  73. break;
  74. }
  75. return bResult;
  76. }
  77. //
  78. //
  79. // Function: HasWidth
  80. //
  81. // Purpose: Return TRUE if the tool supports widths
  82. //
  83. //
  84. BOOL WbTool::HasWidth(void)
  85. {
  86. BOOL bResult = FALSE;
  87. switch (m_toolType)
  88. {
  89. case TOOLTYPE_PEN:
  90. case TOOLTYPE_HIGHLIGHT:
  91. case TOOLTYPE_LINE:
  92. case TOOLTYPE_BOX:
  93. case TOOLTYPE_ELLIPSE:
  94. bResult = TRUE;
  95. break;
  96. // For the selector tool, it depends on the selected object type
  97. case TOOLTYPE_SELECT:
  98. switch (m_selectedTool)
  99. {
  100. case TOOLTYPE_LINE:
  101. case TOOLTYPE_BOX:
  102. case TOOLTYPE_ELLIPSE:
  103. case TOOLTYPE_PEN:
  104. case TOOLTYPE_HIGHLIGHT:
  105. {
  106. bResult = TRUE;
  107. break;
  108. }
  109. }
  110. break;
  111. default:
  112. // The rest don't support widths, including filled tools
  113. break;
  114. }
  115. return bResult;
  116. }
  117. //
  118. //
  119. // Function: HasFont
  120. //
  121. // Purpose: Return TRUE if the tool supports fonts
  122. //
  123. //
  124. BOOL WbTool::HasFont(void)
  125. {
  126. BOOL bResult = FALSE;
  127. switch (m_toolType)
  128. {
  129. case TOOLTYPE_TEXT:
  130. bResult = TRUE;
  131. break;
  132. // For the selector tool, it depends on the selected object type
  133. case TOOLTYPE_SELECT:
  134. switch (m_selectedTool)
  135. {
  136. case TOOLTYPE_TEXT:
  137. bResult = TRUE;
  138. break;
  139. default:
  140. break;
  141. }
  142. break;
  143. default:
  144. break;
  145. }
  146. return bResult;
  147. }
  148. //
  149. //
  150. // Function: GetROP
  151. //
  152. // Purpose: Return the ROP for this tool
  153. //
  154. //
  155. int WbTool::GetROP(void)
  156. {
  157. // If this is a highlight tool we use MASKPEN, else we use the standard
  158. if (m_toolType == TOOLTYPE_HIGHLIGHT)
  159. return(R2_MASKPEN);
  160. else
  161. return(R2_COPYPEN);
  162. }
  163. //
  164. //
  165. // Function: GetCursorForTool
  166. //
  167. // Purpose: Return the handle to the cursor for the tool
  168. //
  169. //
  170. HCURSOR WbTool::GetCursorForTool(void)
  171. {
  172. int nName = -1;
  173. switch(m_toolType)
  174. {
  175. case TOOLTYPE_SELECT:
  176. break; // use default arrow for select cursor (bug 439)
  177. case TOOLTYPE_PEN:
  178. nName = PENFREEHANDCURSOR;
  179. break;
  180. case TOOLTYPE_LINE:
  181. case TOOLTYPE_BOX:
  182. case TOOLTYPE_FILLEDBOX:
  183. case TOOLTYPE_ELLIPSE:
  184. case TOOLTYPE_FILLEDELLIPSE:
  185. nName = PENCURSOR;
  186. break;
  187. case TOOLTYPE_HIGHLIGHT:
  188. nName = HIGHLIGHTFREEHANDCURSOR;
  189. break;
  190. case TOOLTYPE_TEXT:
  191. nName = TEXTCURSOR;
  192. break;
  193. case TOOLTYPE_ERASER:
  194. nName = DELETECURSOR;
  195. break;
  196. default:
  197. // Do nothing - the name pointer is NULL
  198. break;
  199. }
  200. HCURSOR hcursorResult = NULL;
  201. if (nName == -1)
  202. {
  203. // Return the standard arrow cursor as a default
  204. hcursorResult = ::LoadCursor(NULL, IDC_ARROW);
  205. }
  206. else
  207. {
  208. // Return the cursor for the tool
  209. hcursorResult = ::LoadCursor(g_hInstance, MAKEINTRESOURCE( nName ) );
  210. }
  211. return hcursorResult;
  212. }
  213. //
  214. //
  215. // Function: SetFont
  216. //
  217. // Purpoxse: Set the current font of the tool
  218. //
  219. //
  220. void WbTool::SetFont(HFONT hFont)
  221. {
  222. MLZ_EntryOut(ZONE_FUNCTION, "WbTool::SetFont");
  223. // Get the font details
  224. LOGFONT lfont;
  225. ::GetObject(hFont, sizeof(LOGFONT), &lfont);
  226. //zap FontAssociation mode (bug 3258)
  227. lfont.lfClipPrecision |= CLIP_DFA_OVERRIDE;
  228. // Set the local font
  229. if (m_hFont != NULL)
  230. {
  231. ::DeleteFont(m_hFont);
  232. m_hFont = NULL;
  233. }
  234. m_hFont = ::CreateFontIndirect(&lfont);
  235. }
  236. //
  237. //
  238. // Function: SelectGraphic
  239. //
  240. // Purpose: Set the current selected graphic type, and copy the colors,
  241. // widths and font into this tool's attributes.
  242. //
  243. //
  244. void WbTool::SelectGraphic(T126Obj* pGraphic)
  245. {
  246. UINT uiIndex;
  247. // Save the selected tool type
  248. m_selectedTool = pGraphic->GraphicTool();
  249. // Get the tool object for the selected tool type
  250. WbTool* pTool = g_pMain->m_ToolArray[m_selectedTool];
  251. if (HasColor())
  252. {
  253. pGraphic->GetPenColor(&m_clrCur);
  254. }
  255. if (HasWidth())
  256. {
  257. for (uiIndex = 0; uiIndex < NUM_OF_WIDTHS; uiIndex++)
  258. {
  259. SetWidthAtIndex(uiIndex, pTool->GetWidthAtIndex(uiIndex));
  260. }
  261. // See if the object's width matches any of the available colors
  262. // for this tool type
  263. for (uiIndex = 0; uiIndex < NUM_OF_WIDTHS; uiIndex++)
  264. {
  265. if (pGraphic->GetPenThickness() == m_uiWidths[uiIndex])
  266. {
  267. break;
  268. }
  269. }
  270. SetWidthIndex(uiIndex);
  271. }
  272. if (HasFont())
  273. {
  274. if (pGraphic->GraphicTool() == TOOLTYPE_TEXT)
  275. {
  276. SetFont(((TextObj *)pGraphic)->GetFont());
  277. }
  278. }
  279. }
  280. //
  281. // WbMainWindow::InitToolArray
  282. // Create the array of WB tools
  283. //
  284. //
  285. BOOL WbMainWindow::InitToolArray(void)
  286. {
  287. int tool;
  288. WbTool * pTool;
  289. for (tool = TOOLTYPE_FIRST; tool < TOOLTYPE_MAX; tool++)
  290. {
  291. // Add the new tool to the array
  292. DBG_SAVE_FILE_LINE
  293. pTool = new WbTool(tool);
  294. if (!pTool)
  295. {
  296. ERROR_OUT(("Can't create tool %d", tool));
  297. return(FALSE);
  298. }
  299. m_ToolArray[tool] = pTool;
  300. }
  301. return(TRUE);
  302. }
  303. //
  304. // WbMainWindow::DestroyToolAray()
  305. //
  306. // Free the array of WB tools
  307. //
  308. void WbMainWindow::DestroyToolArray(void)
  309. {
  310. int tool;
  311. WbTool * pTool;
  312. for (tool = TOOLTYPE_FIRST; tool < TOOLTYPE_MAX; tool++)
  313. {
  314. pTool = m_ToolArray[tool];
  315. if (pTool != NULL)
  316. {
  317. m_ToolArray[tool] = NULL;
  318. delete pTool;
  319. }
  320. }
  321. }