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.

184 lines
5.1 KiB

  1. /*************************************************
  2. * mystatus.cpp *
  3. * *
  4. * Copyright (C) 1995-1999 Microsoft Inc. *
  5. * *
  6. *************************************************/
  7. #include "stdafx.h"
  8. #include "mystatus.h"
  9. #define SBPF_UPDATE 0x0001 // pending update of text
  10. struct AFX_STATUSPANE
  11. {
  12. UINT nID; // IDC of indicator: 0 => normal text area
  13. int cxText; // width of string area in pixels
  14. // on both sides there is a 3 pixel gap and
  15. // a one pixel border, making a pane 6 pixels wider
  16. UINT nStyle; // style flags (SBPS_*)
  17. UINT nFlags; // state flags (SBPF_*)
  18. CString strText; // text in the pane
  19. };
  20. /*
  21. struct AFX_STATUSPANE
  22. {
  23. UINT nID; // IDC of indicator: 0 => normal text area
  24. UINT nStyle; // style flags (SBPS_*)
  25. int cxText; // width of string area in pixels
  26. // on both sides there is a 1 pixel gap and
  27. // a one pixel border, making a pane 4 pixels wider
  28. LPCTSTR lpszText; // text in the pane
  29. };
  30. */
  31. inline AFX_STATUSPANE* CStatusBar::_GetPanePtr(int nIndex) const
  32. {
  33. ASSERT((nIndex >= 0 && nIndex < m_nCount) || m_nCount == 0);
  34. return ((AFX_STATUSPANE*)m_pData) + nIndex;
  35. }
  36. /*
  37. BOOL CMyStatusBar::SetIndicators(const UINT* lpIDArray, int nIDCount)
  38. {
  39. ASSERT_VALID(this);
  40. ASSERT(nIDCount >= 1); // must be at least one of them
  41. ASSERT(lpIDArray == NULL ||
  42. AfxIsValidAddress(lpIDArray, sizeof(UINT) * nIDCount, FALSE));
  43. // free strings before freeing array of elements
  44. for (int i = 0; i < m_nCount; i++)
  45. VERIFY(SetPaneText(i, NULL, FALSE)); // no update
  46. // first allocate array for panes and copy initial data
  47. if (!AllocElements(nIDCount, sizeof(AFX_STATUSPANE)))
  48. return FALSE;
  49. ASSERT(nIDCount == m_nCount);
  50. BOOL bOK = TRUE;
  51. if (lpIDArray != NULL)
  52. {
  53. LOGFONT lf;
  54. memset(&lf,0,sizeof(LOGFONT));
  55. lstrcpy(lf.lfFaceName,TEXT("�ө���"));
  56. lf.lfHeight=12;
  57. lf.lfCharSet=DEFAULT_CHARSET;
  58. HFONT hFont = ::CreateFontIndirect(&lf);
  59. ASSERT(hFont != NULL); // must have a font !
  60. CString strText;
  61. CClientDC dcScreen(NULL);
  62. HGDIOBJ hOldFont = dcScreen.SelectObject(hFont);
  63. for (int i = 0; i < nIDCount; i++)
  64. {
  65. AFX_STATUSPANE* pSBP = _GetPanePtr(i);
  66. pSBP->nID = *lpIDArray++;
  67. if (pSBP->nID != 0)
  68. {
  69. if (!strText.LoadString(pSBP->nID))
  70. {
  71. TRACE1("Warning: failed to load indicator string 0x%04X.\n",
  72. pSBP->nID);
  73. bOK = FALSE;
  74. break;
  75. }
  76. pSBP->cxText = dcScreen.GetTextExtent(strText,
  77. strText.GetLength()).cx;
  78. ASSERT(pSBP->cxText >= 0);
  79. if (!SetPaneText(i, strText, FALSE))
  80. {
  81. bOK = FALSE;
  82. break;
  83. }
  84. }
  85. else
  86. {
  87. // no indicator (must access via index)
  88. // default to 1/4 the screen width (first pane is stretchy)
  89. if (!(pSBP->cxText = dcScreen.GetTextExtent(TEXT("0123456789"),lstrlen("0123456789")).cx))
  90. pSBP->cxText = ::GetSystemMetrics(SM_CXSCREEN)/4;
  91. if (i == 0)
  92. pSBP->nStyle |= (SBPS_STRETCH | SBPS_NOBORDERS);
  93. }
  94. }
  95. dcScreen.SelectObject(hOldFont);
  96. }
  97. return bOK;
  98. }
  99. */
  100. BOOL CMyStatusBar::SetIndicators(const UINT* lpIDArray, int nIDCount)
  101. {
  102. ASSERT_VALID(this);
  103. ASSERT(nIDCount >= 1); // must be at least one of them
  104. ASSERT(lpIDArray == NULL ||
  105. AfxIsValidAddress(lpIDArray, sizeof(UINT) * nIDCount, FALSE));
  106. ASSERT(::IsWindow(m_hWnd));
  107. // first allocate array for panes and copy initial data
  108. if (!AllocElements(nIDCount, sizeof(AFX_STATUSPANE)))
  109. return FALSE;
  110. ASSERT(nIDCount == m_nCount);
  111. // copy initial data from indicator array
  112. BOOL bResult = TRUE;
  113. if (lpIDArray != NULL)
  114. {
  115. // Code merge from 3.51 'cblocks'. weiwu 6/26
  116. LOGFONT lf;
  117. memset(&lf,0,sizeof(LOGFONT));
  118. lstrcpy(lf.lfFaceName,TEXT("�ө���"));
  119. lf.lfHeight=12;
  120. lf.lfCharSet=DEFAULT_CHARSET;
  121. HFONT hFont = ::CreateFontIndirect(&lf);
  122. // HFONT hFont = (HFONT)SendMessage(WM_GETFONT);
  123. CClientDC dcScreen(NULL);
  124. HGDIOBJ hOldFont = NULL;
  125. if (hFont != NULL)
  126. hOldFont = dcScreen.SelectObject(hFont);
  127. AFX_STATUSPANE* pSBP = _GetPanePtr(0);
  128. for (int i = 0; i < nIDCount; i++)
  129. {
  130. pSBP->nID = *lpIDArray++;
  131. pSBP->nFlags |= SBPF_UPDATE;
  132. if (pSBP->nID != 0)
  133. {
  134. if (!pSBP->strText.LoadString(pSBP->nID))
  135. {
  136. TRACE1("Warning: failed to load indicator string 0x%04X.\n",
  137. pSBP->nID);
  138. bResult = FALSE;
  139. break;
  140. }
  141. pSBP->cxText = dcScreen.GetTextExtent(pSBP->strText).cx;
  142. ASSERT(pSBP->cxText >= 0);
  143. if (!SetPaneText(i, pSBP->strText, FALSE))
  144. {
  145. bResult = FALSE;
  146. break;
  147. }
  148. }
  149. else
  150. {
  151. // no indicator (must access via index)
  152. // default to 1/4 the screen width (first pane is stretchy)
  153. // Code merge from 3.51 weiwu 6/26
  154. /*
  155. pSBP->cxText = ::GetSystemMetrics(SM_CXSCREEN)/4;
  156. */
  157. if (!(pSBP->cxText = dcScreen.GetTextExtent(TEXT("0123456789"),lstrlen("0123456789")).cx))
  158. pSBP->cxText = ::GetSystemMetrics(SM_CXSCREEN)/4;
  159. if (i == 0)
  160. pSBP->nStyle |= (SBPS_STRETCH | SBPS_NOBORDERS);
  161. }
  162. ++pSBP;
  163. }
  164. if (hOldFont != NULL)
  165. dcScreen.SelectObject(hOldFont);
  166. }
  167. UpdateAllPanes(TRUE, TRUE);
  168. return bResult;
  169. }