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.

771 lines
18 KiB

  1. //-----------------------------------------------------------------------------
  2. // File: uiglobals.cpp
  3. //
  4. // Desc: CUIGlobals is a class that packs and holds most information
  5. // relevent to a UI session. Many classes make reference to
  6. // CUIGlobals all the time.
  7. //
  8. // CPaintHelper encapsulates GDI calls, simplifying GDI operations.
  9. //
  10. // Copyright (C) 1999-2000 Microsoft Corporation. All Rights Reserved.
  11. //-----------------------------------------------------------------------------
  12. #include "common.hpp"
  13. #define __DEFINE_ELEMENT_STRUCTURES__
  14. #include "uielements.h"
  15. static const GUID GUID_DIConfigAppEditLayout =
  16. { 0xfd4ace13, 0x7044, 0x4204, { 0x8b, 0x15, 0x9, 0x52, 0x86, 0xb1, 0x2e, 0xad } };
  17. CUIGlobals::CUIGlobals(UIG_PARAMS_DEFINE) :
  18. // globals...
  19. m_hrInit(S_OK),
  20. m_hrFinalResult(S_OK),
  21. m_hInst(NULL),
  22. m_lpDI(NULL),
  23. m_dwFlags(0),
  24. m_wszUserNames(NULL),
  25. m_pSurface(NULL),
  26. m_pSurface3D(NULL),
  27. m_lpCallback(NULL),
  28. m_pvRefData(NULL),
  29. m_bAllowEditLayout(FALSE),
  30. m_bUseColorSet(FALSE),
  31. // ui...
  32. m_pElement(NULL),
  33. m_nElements(0),
  34. m_pFont(NULL),
  35. m_nFonts(0),
  36. m_pBrush(NULL),
  37. m_nBrushes(0),
  38. m_pPen(NULL),
  39. m_nPens(0),
  40. m_pColor(NULL),
  41. m_nColors(0)
  42. {
  43. tracescope(__ts,_T("CUIGlobals::CUIGlobals()\n"));
  44. m_hrInit = Init(UIG_PARAMS_DEFINE_PASS);
  45. }
  46. void CUIGlobals::SetTableColor(UICOLOR uic, COLORREF c)
  47. {
  48. UICOLORINFO *info = GetColorInfo(uic);
  49. assert(info != NULL);
  50. if (info == NULL)
  51. return;
  52. info->rgb = c;
  53. }
  54. HRESULT CUIGlobals::Init(UIG_PARAMS_DEFINE)
  55. {tracescope(__ts,_T("CUIGlobals::Init(...)\n"));
  56. HRESULT hr = S_OK;
  57. // get instance handle
  58. m_hInst = (HINSTANCE)g_hModule;
  59. if (m_hInst == NULL)
  60. {
  61. etrace(_T("hInst NULL\n"));
  62. return E_FAIL;
  63. }
  64. // create direct input
  65. DWORD dwVer = DIRECTINPUT_VERSION;
  66. hr = DirectInput8Create(m_hInst, dwVer, IID_IDirectInput8W, (LPVOID *)&m_lpDI, NULL);
  67. if (FAILED(hr) || m_lpDI == NULL)
  68. {
  69. m_lpDI = NULL;
  70. etrace2(_T("Could not create DirectInput ver 0x%08x\n -> DirectInputCreateEx() returned 0x%08x\n"), dwVer, hr);
  71. return hr;
  72. }
  73. // save flags
  74. m_dwFlags = dwFlags;
  75. #ifdef CFGUI__FORCE_NON_NULL_WSZUSERNAMES
  76. if (wszUserNames == NULL)
  77. wszUserNames = _T("Forced Non-NULL Username");
  78. #endif
  79. if (wszUserNames == NULL)
  80. {
  81. etrace(_T("wszUserNames was passed NULL\n"));
  82. return E_FAIL;
  83. }
  84. // save user names
  85. m_wszUserNames = DupSuperString(wszUserNames);
  86. if (m_wszUserNames == NULL)
  87. {
  88. etrace(_T("Could not duplicate user names\n"));
  89. return E_FAIL;
  90. }
  91. // make sure we were passed an action format
  92. if (lpAcFor == NULL)
  93. {
  94. etrace(_T("lpAcFor param NULL\n"));
  95. return E_INVALIDARG;
  96. }
  97. // copy the acfor to the master
  98. hr = InitMasterAcForArray(lpAcFor, int(dwNumAcFor));
  99. if (FAILED(hr))
  100. {
  101. etrace1(_T("InitMasterAcForArray() failed, returning 0x%08x\n"), hr);
  102. return hr;
  103. }
  104. // get surface
  105. if (lpSurface != NULL)
  106. {
  107. hr = lpSurface->QueryInterface(IID_IDirect3DSurface8, (void **)&m_pSurface3D);
  108. if (FAILED(hr) || m_pSurface3D == NULL)
  109. {
  110. m_pSurface3D = NULL;
  111. }
  112. hr = lpSurface->QueryInterface(IID_IDirectDrawSurface, (void **)&m_pSurface);
  113. if (FAILED(hr) || m_pSurface == NULL)
  114. {
  115. m_pSurface = NULL;
  116. }
  117. if (m_pSurface == NULL && m_pSurface3D == NULL)
  118. etrace(_T("lpSurface was non-NULL but could not get IDirect3DSurface8 or IID_IDirectDrawSurface from it"));
  119. }
  120. // save callback and ref data
  121. m_lpCallback = lpCallback;
  122. m_pvRefData = pvRefData;
  123. // see whether or not we're allowing edit layout mode
  124. m_bAllowEditLayout = IsEqualGUID(RefMasterAcFor(0).guidActionMap,
  125. GUID_DIConfigAppEditLayout);
  126. // init a bunch of stuff necessary for painting
  127. if (!InitColorsAndTablesAndObjects(lpDIColorSet))
  128. return E_FAIL;
  129. // dump info if debug
  130. #ifdef DBG
  131. Dump();
  132. #endif
  133. // return success if we got here
  134. return S_OK;
  135. }
  136. BOOL CUIGlobals::InitColorsAndTablesAndObjects(LPDICOLORSET lpDIColorSet)
  137. {tracescope(__ts,_T("CUIGlobals::InitColorsAndTablesAndObjects()\n"));
  138. // init ui tables
  139. if (!InitTables())
  140. {
  141. etrace(_T("Could not initialize tables\n"));
  142. return FALSE;
  143. }
  144. // decide whether or not to use the passed colorset
  145. if (lpDIColorSet != NULL)
  146. {
  147. m_ColorSet = *lpDIColorSet;
  148. m_bUseColorSet = !IsZeroOrInvalidColorSet(m_ColorSet);
  149. }
  150. else
  151. m_bUseColorSet = FALSE;
  152. // use it, or use defaults
  153. if (m_bUseColorSet)
  154. {
  155. // transfer colors from passed colorset
  156. SetTableColor(UIC_TEXTFORE, D3DCOLOR2COLORREF(m_ColorSet.cTextFore));
  157. SetTableColor(UIC_TEXTHIGHLIGHT, D3DCOLOR2COLORREF(m_ColorSet.cTextHighlight));
  158. SetTableColor(UIC_CALLOUTLINE, D3DCOLOR2COLORREF(m_ColorSet.cCalloutLine));
  159. SetTableColor(UIC_CALLOUTHIGHLIGHT, D3DCOLOR2COLORREF(m_ColorSet.cCalloutHighlight));
  160. SetTableColor(UIC_BORDER, D3DCOLOR2COLORREF(m_ColorSet.cBorder));
  161. SetTableColor(UIC_CONTROLFILL, D3DCOLOR2COLORREF(m_ColorSet.cControlFill));
  162. SetTableColor(UIC_HIGHLIGHTFILL, D3DCOLOR2COLORREF(m_ColorSet.cHighlightFill));
  163. SetTableColor(UIC_AREAFILL, D3DCOLOR2COLORREF(m_ColorSet.cAreaFill));
  164. }
  165. else
  166. {
  167. // use default colors
  168. SetTableColor(UIC_TEXTFORE, RGB(255, 255, 255));
  169. SetTableColor(UIC_TEXTHIGHLIGHT, RGB( 0, 255, 0));
  170. SetTableColor(UIC_CALLOUTLINE, RGB(255, 255, 255));
  171. SetTableColor(UIC_CALLOUTHIGHLIGHT, RGB( 0, 255, 0));
  172. SetTableColor(UIC_BORDER, RGB(255, 255, 0));
  173. SetTableColor(UIC_CONTROLFILL, RGB( 0, 191, 0));
  174. SetTableColor(UIC_HIGHLIGHTFILL, RGB( 0, 0, 0));
  175. SetTableColor(UIC_AREAFILL, RGB( 0, 0, 0));
  176. }
  177. // create the table objects
  178. CreateObjects();
  179. return TRUE;
  180. }
  181. CUIGlobals::~CUIGlobals()
  182. {
  183. tracescope(__ts,_T("CUIGlobals::~CUIGlobals()\n"));
  184. if (m_wszUserNames != NULL)
  185. free((LPVOID)m_wszUserNames);
  186. m_wszUserNames = NULL;
  187. if (m_lpDI != NULL)
  188. m_lpDI->Release();
  189. m_lpDI = NULL;
  190. if (m_pSurface != NULL)
  191. m_pSurface->Release();
  192. m_pSurface = NULL;
  193. if (m_pSurface3D != NULL)
  194. m_pSurface3D->Release();
  195. m_pSurface3D = NULL;
  196. ClearMasterAcForArray();
  197. ClearTables();
  198. }
  199. void CUIGlobals::Dump()
  200. {
  201. tracescope(ts, _T("UIGlobals...\n\n"));
  202. traceHEXPTR(m_hInst);
  203. traceHEXPTR(m_lpDI);
  204. LPTSTR str = AllocConfigureFlagStr(m_dwFlags);
  205. trace1(_T("m_dwFlags = %s\n"), str);
  206. free(str);
  207. traceSUPERSTR(m_wszUserNames);
  208. traceHEXPTR(m_pSurface);
  209. traceHEXPTR(m_pSurface3D);
  210. traceHEXPTR(m_lpCallback);
  211. traceBOOL(m_bAllowEditLayout);
  212. {
  213. tracescope(__csts, _T("m_ColorSet...\n"));
  214. traceHEX(m_ColorSet.cTextFore);
  215. traceHEX(m_ColorSet.cTextHighlight);
  216. traceHEX(m_ColorSet.cCalloutLine);
  217. traceHEX(m_ColorSet.cCalloutHighlight);
  218. traceHEX(m_ColorSet.cBorder);
  219. traceHEX(m_ColorSet.cControlFill);
  220. traceHEX(m_ColorSet.cHighlightFill);
  221. traceHEX(m_ColorSet.cAreaFill);
  222. }
  223. traceBOOL(m_bUseColorSet);
  224. trace(_T("\n"));
  225. TraceActionFormat(_T("Master ActionFormat 0:"), RefMasterAcFor(0));
  226. trace(_T("\n\n"));
  227. }
  228. LPDIRECTINPUT8W CUIGlobals::GetDI()
  229. {
  230. if (m_lpDI == NULL)
  231. return NULL;
  232. m_lpDI->AddRef();
  233. return m_lpDI;
  234. }
  235. IDirectDrawSurface *CUIGlobals::GetSurface()
  236. {
  237. if (m_pSurface == NULL)
  238. return NULL;
  239. m_pSurface->AddRef();
  240. return m_pSurface;
  241. }
  242. IDirect3DSurface8 *CUIGlobals::GetSurface3D()
  243. {
  244. if (m_pSurface3D == NULL)
  245. return NULL;
  246. m_pSurface3D->AddRef();
  247. return m_pSurface3D;
  248. }
  249. void CUIGlobals::DeleteObjects()
  250. {
  251. // make sure all our gdi objects are deleted
  252. int i;
  253. if (m_pFont != NULL)
  254. for (i = 0; i < m_nFonts; i++)
  255. {
  256. UIFONTINFO &info = m_pFont[i];
  257. if (info.hFont != NULL)
  258. DeleteObject(info.hFont);
  259. info.hFont = NULL;
  260. }
  261. if (m_pBrush != NULL)
  262. for (i = 0; i < m_nBrushes; i++)
  263. {
  264. UIBRUSHINFO &info = m_pBrush[i];
  265. if (info.hBrush != NULL)
  266. DeleteObject(info.hBrush);
  267. info.hBrush = NULL;
  268. if (info.hPen != NULL)
  269. DeleteObject(info.hPen);
  270. info.hPen = NULL;
  271. }
  272. if (m_pPen != NULL)
  273. for (i = 0; i < m_nPens; i++)
  274. {
  275. UIPENINFO &info = m_pPen[i];
  276. if (info.hPen != NULL)
  277. DeleteObject(info.hPen);
  278. info.hPen = NULL;
  279. }
  280. }
  281. void CUIGlobals::ClearTables()
  282. {
  283. // make sure all our gdi objects are deleted
  284. DeleteObjects();
  285. // delete the tables, null the pointers, and zero the counters
  286. #define FREETABLE(member, memnum) \
  287. { \
  288. if (member != NULL) \
  289. delete [] member; \
  290. member = NULL; \
  291. memnum = 0; \
  292. }
  293. FREETABLE(m_pElement, m_nElements);
  294. FREETABLE(m_pFont, m_nFonts);
  295. FREETABLE(m_pBrush, m_nBrushes);
  296. FREETABLE(m_pPen, m_nPens);
  297. FREETABLE(m_pColor, m_nColors);
  298. }
  299. BOOL CUIGlobals::InitTables()
  300. {
  301. BOOL bSuccess = TRUE;
  302. // make sure the tables have been cleared
  303. ClearTables();
  304. // allocate our own copies of all the tables
  305. #define ALLOCTABLE(member, memnum, type, init, num) \
  306. { \
  307. member = new type [memnum = num]; \
  308. if (member == NULL) \
  309. { \
  310. memnum = 0; \
  311. bSuccess = FALSE; \
  312. } \
  313. else \
  314. memcpy(member, init, sizeof(type) * memnum); \
  315. }
  316. ALLOCTABLE(m_pElement, m_nElements, UIELEMENTINFO, uielement, NUMUIELEMENTS);
  317. ALLOCTABLE(m_pFont, m_nFonts, UIFONTINFO, uifont, NUMUIFONTS);
  318. ALLOCTABLE(m_pBrush, m_nBrushes, UIBRUSHINFO, uibrush, NUMUIBRUSHES);
  319. ALLOCTABLE(m_pPen, m_nPens, UIPENINFO, uipen, NUMUIPENS);
  320. ALLOCTABLE(m_pColor, m_nColors, UICOLORINFO, uicolor, NUMUICOLORS);
  321. return bSuccess;
  322. }
  323. void CUIGlobals::RecreateObjects()
  324. {
  325. DeleteObjects();
  326. CreateObjects();
  327. }
  328. void CUIGlobals::CreateObjects()
  329. {
  330. // make sure all our gdi objects are created
  331. int i;
  332. if (m_pFont != NULL)
  333. {
  334. HDC hDC = GetDC(NULL);
  335. for (i = 0; i < m_nFonts; i++)
  336. {
  337. UIFONTINFO &info = m_pFont[i];
  338. if (info.hFont == NULL)
  339. {
  340. LOGFONT lf;
  341. lf.lfHeight = -MulDiv(info.nPointSize, GetDeviceCaps(hDC, LOGPIXELSY), 72);
  342. lf.lfWidth = 0;
  343. lf.lfEscapement = 0;
  344. lf.lfOrientation = 0;
  345. lf.lfWeight = info.bBold ? FW_BOLD : FW_NORMAL;
  346. lf.lfItalic = FALSE;
  347. lf.lfUnderline = FALSE;
  348. lf.lfStrikeOut = FALSE;
  349. lf.lfCharSet = DEFAULT_CHARSET;
  350. lf.lfOutPrecision = OUT_DEFAULT_PRECIS;
  351. lf.lfClipPrecision = CLIP_DEFAULT_PRECIS;
  352. lf.lfQuality = PROOF_QUALITY;
  353. lf.lfPitchAndFamily = DEFAULT_PITCH | FF_DONTCARE;
  354. _tcscpy(lf.lfFaceName, info.lfFaceName);
  355. info.hFont = (HGDIOBJ)CreateFontIndirect(&lf);
  356. }
  357. }
  358. ReleaseDC(NULL, hDC);
  359. }
  360. if (m_pBrush != NULL)
  361. for (i = 0; i < m_nBrushes; i++)
  362. {
  363. UIBRUSHINFO &info = m_pBrush[i];
  364. if (info.hBrush == NULL)
  365. info.hBrush = (HGDIOBJ)CreateSolidBrush(GetColor(info.eColor));
  366. if (info.hPen == NULL)
  367. info.hPen = (HGDIOBJ)CreatePen(PS_SOLID, 1, GetColor(info.eColor));
  368. }
  369. if (m_pPen != NULL)
  370. for (i = 0; i < m_nPens; i++)
  371. {
  372. UIPENINFO &info = m_pPen[i];
  373. if (info.hPen == NULL)
  374. info.hPen = (HGDIOBJ)CreatePen(info.fnPenStyle, info.nWidth, GetColor(info.eColor));
  375. }
  376. }
  377. #define IMPLGETINFO(Type, TYPE, Types, t) \
  378. UI##TYPE##INFO *CUIGlobals::Get##Type##Info(UI##TYPE t) \
  379. { \
  380. if (m_p##Type != NULL) \
  381. for (int i = 0; i < m_n##Types; i++) \
  382. if (m_p##Type[i].e##Type == t) \
  383. return &(m_p##Type[i]); \
  384. return NULL; \
  385. }
  386. IMPLGETINFO(Element, ELEMENT, Elements, e)
  387. IMPLGETINFO(Font, FONT, Fonts, f)
  388. IMPLGETINFO(Brush, BRUSH, Brushes, b)
  389. IMPLGETINFO(Pen, PEN, Pens, p)
  390. IMPLGETINFO(Color, COLOR, Colors, c)
  391. #undef IMPLGETINFO
  392. #define IMPLGET(T, Name, Type, TYPE, v, def, ret) \
  393. T CUIGlobals::Get##Name(UI##TYPE ui##v) \
  394. { \
  395. UI##TYPE##INFO *v = Get##Type##Info(ui##v); \
  396. if (!v) \
  397. return def; \
  398. return ret; \
  399. }
  400. IMPLGET(HGDIOBJ, Font, Element, ELEMENT, e, NULL, GetFont(e->eFont))
  401. IMPLGET(HGDIOBJ, Font, Font, FONT, f, NULL, f->hFont)
  402. IMPLGET(HGDIOBJ, Brush, Element, ELEMENT, e, NULL, GetBrush(e->eBrush))
  403. IMPLGET(HGDIOBJ, Brush, Brush, BRUSH, b, NULL, b->hBrush)
  404. IMPLGET(HGDIOBJ, Pen, Element, ELEMENT, e, NULL, GetPen(e->ePen))
  405. IMPLGET(HGDIOBJ, Pen, Brush, BRUSH, b, NULL, b->hPen)
  406. IMPLGET(HGDIOBJ, Pen, Pen, PEN, p, NULL, p->hPen)
  407. IMPLGET(COLORREF, BrushColor, Element, ELEMENT, e, RGB(255, 127, 127), GetColor(e->eBrush))
  408. IMPLGET(COLORREF, PenColor, Element, ELEMENT, e, RGB(255, 127, 127), GetColor(e->ePen))
  409. IMPLGET(COLORREF, TextColor, Element, ELEMENT, e, RGB(255, 127, 127), GetColor(e->eText))
  410. IMPLGET(COLORREF, BkColor, Element, ELEMENT, e, RGB(255, 127, 127), GetColor(e->eBk))
  411. IMPLGET(COLORREF, Color, Brush, BRUSH, b, RGB(255, 127, 127), GetColor(b->eColor))
  412. IMPLGET(COLORREF, Color, Pen, PEN, p, RGB(255, 127, 127), GetColor(p->eColor))
  413. IMPLGET(COLORREF, Color, Color, COLOR, c, RGB(255, 127, 127), c->rgb)
  414. #undef IMPLGET
  415. CPaintHelper::CPaintHelper(CUIGlobals &uig, HDC hDC) :
  416. m_uig(uig), m_priv_hDC(hDC), m_hDC(m_priv_hDC),
  417. m_eFont(UIF_VOID),
  418. m_eBrush(UIB_VOID),
  419. m_ePen(UIP_VOID),
  420. m_eText(UIC_VOID),
  421. m_eBk(UIC_VOID),
  422. m_hOldFont(NULL), m_hOldBrush(NULL), m_hOldPen(NULL),
  423. m_bOldFont(FALSE), m_bOldBrush(FALSE), m_bOldPen(FALSE)
  424. {
  425. if (m_hDC != NULL)
  426. {
  427. m_oldtextcolor = GetTextColor(m_hDC);
  428. m_oldbkcolor = GetBkColor(m_hDC);
  429. m_oldbkmode = GetBkMode(m_hDC);
  430. }
  431. }
  432. CPaintHelper::~CPaintHelper()
  433. {
  434. if (m_hDC != NULL)
  435. {
  436. if (m_bOldFont)
  437. SelectObject(m_hDC, m_hOldFont);
  438. if (m_bOldBrush)
  439. SelectObject(m_hDC, m_hOldBrush);
  440. if (m_bOldPen)
  441. SelectObject(m_hDC, m_hOldPen);
  442. SetTextColor(m_hDC, m_oldtextcolor);
  443. SetBkColor(m_hDC, m_oldbkcolor);
  444. SetBkMode(m_hDC, m_oldbkmode);
  445. }
  446. }
  447. void CPaintHelper::SetElement(UIELEMENT eElement)
  448. {
  449. UIELEMENTINFO *info = m_uig.GetElementInfo(eElement);
  450. if (!info)
  451. return;
  452. if (info->eFont != UIF_LAST)
  453. SetFont(info->eFont);
  454. if (info->eBrush != UIB_LAST)
  455. SetBrush(info->eBrush);
  456. if (info->ePen != UIP_LAST)
  457. SetPen(info->ePen);
  458. SetText(info->eText, info->eBk);
  459. }
  460. void CPaintHelper::SetFont(UIFONT eFont)
  461. {
  462. if (m_eFont == eFont || eFont == UIF_LAST)
  463. return;
  464. HGDIOBJ hObj = m_uig.GetFont(eFont);
  465. if (hObj == NULL)
  466. return;
  467. if (m_hDC != NULL)
  468. {
  469. HGDIOBJ hOld = NULL;
  470. hOld = SelectObject(m_hDC, hObj);
  471. if (!m_bOldFont)
  472. m_hOldFont = hOld;
  473. m_bOldFont = TRUE;
  474. }
  475. m_eFont = eFont;
  476. }
  477. void CPaintHelper::SetBrush(UIBRUSH eBrush)
  478. {
  479. if (m_eBrush == eBrush || eBrush == UIB_LAST)
  480. return;
  481. HGDIOBJ hObj = eBrush == UIB_NULL ?
  482. GetStockObject(NULL_BRUSH) :
  483. m_uig.GetBrush(eBrush);
  484. if (hObj == NULL)
  485. return;
  486. if (m_hDC != NULL)
  487. {
  488. HGDIOBJ hOld = NULL;
  489. hOld = SelectObject(m_hDC, hObj);
  490. if (!m_bOldBrush)
  491. m_hOldBrush = hOld;
  492. m_bOldBrush = TRUE;
  493. }
  494. m_eBrush = eBrush;
  495. }
  496. void CPaintHelper::SetPen(UIPEN ePen)
  497. {
  498. if (m_ePen == ePen || ePen == UIP_LAST)
  499. return;
  500. HGDIOBJ hObj = ePen == UIB_NULL ?
  501. GetStockObject(NULL_PEN) :
  502. m_uig.GetPen(ePen);
  503. if (hObj == NULL)
  504. return;
  505. if (m_hDC != NULL)
  506. {
  507. HGDIOBJ hOld = NULL;
  508. hOld = SelectObject(m_hDC, hObj);
  509. if (!m_bOldPen)
  510. m_hOldPen = hOld;
  511. m_bOldPen = TRUE;
  512. }
  513. m_ePen = ePen;
  514. }
  515. void CPaintHelper::SetText(UICOLOR eText, UICOLOR eBk)
  516. {
  517. if (m_eText != eText && eText != UIC_LAST)
  518. {
  519. if (m_hDC != NULL)
  520. SetTextColor(m_hDC, m_uig.GetColor(eText));
  521. m_eText = eText;
  522. }
  523. if (m_eBk != eBk && eBk != UIC_LAST)
  524. {
  525. if (m_hDC != NULL)
  526. {
  527. if (eBk == UIC_NULL)
  528. SetBkMode(m_hDC, TRANSPARENT);
  529. else
  530. {
  531. SetBkColor(m_hDC, m_uig.GetColor(eBk));
  532. SetBkMode(m_hDC, OPAQUE);
  533. }
  534. }
  535. m_eBk = eBk;
  536. }
  537. }
  538. BOOL CPaintHelper::LineTo(int x, int y)
  539. {
  540. if (m_hDC == NULL)
  541. return FALSE;
  542. return ::LineTo(m_hDC, x, y);
  543. }
  544. BOOL CPaintHelper::MoveTo(int x, int y, SPOINT *last)
  545. {
  546. if (m_hDC == NULL)
  547. return FALSE;
  548. POINT p;
  549. BOOL bRet = MoveToEx(m_hDC, x, y, &p);
  550. if (last)
  551. *last = p;
  552. return bRet;
  553. }
  554. BOOL CPaintHelper::Rectangle(SRECT r, UIRECTTYPE eType)
  555. {
  556. // fail on no dc
  557. if (m_hDC == NULL)
  558. return FALSE;
  559. // see if we lack a pen or brush (might add more checks later)
  560. BOOL bNoPen = m_ePen == UIP_NULL;
  561. BOOL bNoBrush = m_eBrush == UIB_NULL;
  562. // fail if trying to do an outline without a pen
  563. if (eType == UIR_OUTLINE && bNoPen)
  564. return FALSE;
  565. // fail if trying to do a solid without a brush
  566. if (eType == UIR_SOLID && bNoBrush)
  567. return FALSE;
  568. // save old objects if we change anything...
  569. HGDIOBJ hOldBrush = NULL, hOldPen = NULL;
  570. // select a null brush if we're doing an outline and we're not already null brushed
  571. if (eType == UIR_OUTLINE && m_eBrush != UIB_NULL)
  572. hOldBrush = SelectObject(m_hDC, GetStockObject(NULL_BRUSH));
  573. // select a pen the same color as the current brush if doing solid
  574. if (eType == UIR_SOLID || m_ePen == UIP_NULL)
  575. {
  576. HGDIOBJ hPen = m_uig.GetPen(m_eBrush);
  577. if (hPen == NULL)
  578. return FALSE;
  579. hOldPen = SelectObject(m_hDC, hPen);
  580. }
  581. // draw the rect
  582. BOOL bRet = ::Rectangle(m_hDC, r.left, r.top, r.right, r.bottom);
  583. // restore whatever changed
  584. if (eType == UIR_OUTLINE && m_eBrush != UIB_NULL)
  585. SelectObject(m_hDC, hOldBrush);
  586. if (eType == UIR_SOLID || m_ePen == UIP_NULL)
  587. SelectObject(m_hDC, hOldPen);
  588. return bRet;
  589. }
  590. const DIACTIONFORMATW &CUIGlobals::RefMasterAcFor(int i)
  591. {
  592. assert(IsValidMasterAcForIndex(i));
  593. return m_MasterAcForArray[i];
  594. }
  595. BOOL CUIGlobals::IsValidMasterAcForIndex(int i)
  596. {
  597. if (i < 0 || i >= m_MasterAcForArray.GetSize())
  598. return FALSE;
  599. return TRUE;
  600. }
  601. HRESULT CUIGlobals::InitMasterAcForArray(const DIACTIONFORMATW *af, int n)
  602. {
  603. if (n < 1)
  604. return E_FAIL;
  605. ClearMasterAcForArray();
  606. m_MasterAcForArray.SetSize(n);
  607. for (int i = 0; i < n; i++)
  608. {
  609. HRESULT hr = CopyActionFormat(m_MasterAcForArray[i], af[i]);
  610. if (FAILED(hr))
  611. {
  612. m_MasterAcForArray.SetSize(i);
  613. ClearMasterAcForArray();
  614. return hr;
  615. }
  616. }
  617. return S_OK;
  618. }
  619. void CUIGlobals::ClearMasterAcForArray()
  620. {
  621. int s = m_MasterAcForArray.GetSize();
  622. for (int i = 0; i < s; i++)
  623. CleanupActionFormatCopy(m_MasterAcForArray[i]);
  624. m_MasterAcForArray.RemoveAll();
  625. assert(m_MasterAcForArray.GetSize() == 0);
  626. }
  627. LPCWSTR CUIGlobals::GetUserName(int i)
  628. {
  629. return GetSubString(m_wszUserNames, i);
  630. }
  631. int CUIGlobals::GetNumUserNames()
  632. {
  633. return CountSubStrings(m_wszUserNames);
  634. }
  635. void CUIGlobals::SetFinalResult(HRESULT hr)
  636. {
  637. m_hrFinalResult = hr;
  638. }
  639. HRESULT CUIGlobals::GetFinalResult()
  640. {
  641. return m_hrFinalResult;
  642. }
  643. int CUIGlobals::GetUserNameIndex(LPCWSTR wsz)
  644. {
  645. for (int i = 0; i < GetNumUserNames(); i++)
  646. if (_wcsicmp(wsz, GetUserName(i)) == 0)
  647. return i;
  648. return -1;
  649. }