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.

397 lines
8.0 KiB

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