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.

181 lines
5.3 KiB

  1. // datedial.cpp : implementation file
  2. //
  3. // This is a part of the Microsoft Foundation Classes C++ library.
  4. // Copyright (C) 1992-1995 Microsoft Corporation
  5. // All rights reserved.
  6. //
  7. // This source code is only intended as a supplement to the
  8. // Microsoft Foundation Classes Reference and related
  9. // electronic documentation provided with the library.
  10. // See these sources for detailed information regarding the
  11. // Microsoft Foundation Classes product.
  12. #include "stdafx.h"
  13. #include "wordpad.h"
  14. #include "datedial.h"
  15. #include "helpids.h"
  16. #include <winnls.h>
  17. #ifdef _DEBUG
  18. #undef THIS_FILE
  19. static char BASED_CODE THIS_FILE[] = __FILE__;
  20. #endif
  21. SYSTEMTIME CDateDialog::m_time;
  22. LCID CDateDialog::m_id;
  23. CListBox* CDateDialog::m_pListBox = NULL;
  24. PARAFORMAT CDateDialog::m_pf;
  25. /////////////////////////////////////////////////////////////////////////////
  26. // CDateDialog dialog
  27. const DWORD CDateDialog::m_nHelpIDs[] =
  28. {
  29. IDC_DATEDIALOG_LIST, IDH_WORDPAD_TIMEDATE,
  30. IDC_STATIC_HEADING, IDH_WORDPAD_TIMEDATE,
  31. 0, 0
  32. };
  33. CDateDialog::CDateDialog(CWnd* pParent , PARAFORMAT& pf)
  34. : CCSDialog(CDateDialog::IDD, pParent)
  35. {
  36. m_pf = pf;
  37. //{{AFX_DATA_INIT(CDateDialog)
  38. m_strSel = _T("");
  39. //}}AFX_DATA_INIT
  40. }
  41. void CDateDialog::DoDataExchange(CDataExchange* pDX)
  42. {
  43. CCSDialog::DoDataExchange(pDX);
  44. //{{AFX_DATA_MAP(CDateDialog)
  45. DDX_Control(pDX, IDC_DATEDIALOG_LIST, m_listBox);
  46. DDX_LBString(pDX, IDC_DATEDIALOG_LIST, m_strSel);
  47. //}}AFX_DATA_MAP
  48. }
  49. BEGIN_MESSAGE_MAP(CDateDialog, CCSDialog)
  50. //{{AFX_MSG_MAP(CDateDialog)
  51. ON_LBN_DBLCLK(IDC_DATEDIALOG_LIST, OnDblclkDatedialogList)
  52. //}}AFX_MSG_MAP
  53. END_MESSAGE_MAP()
  54. /////////////////////////////////////////////////////////////////////////////
  55. // CDateDialog message handlers
  56. BOOL CDateDialog::OnInitDialog()
  57. {
  58. CCSDialog::OnInitDialog();
  59. m_pListBox = &m_listBox; // set static member
  60. GetLocalTime(&m_time);
  61. m_id = GetUserDefaultLCID();
  62. // if we have Arabic/Hebrew locale
  63. if ((PRIMARYLANGID(LANGIDFROMLCID(m_id))== LANG_ARABIC) ||
  64. (PRIMARYLANGID(LANGIDFROMLCID(m_id))== LANG_HEBREW))
  65. {
  66. if(
  67. (m_pf.wEffects & PFE_RTLPARA) &&
  68. !(GetWindowLongPtr(m_pListBox->m_hWnd,GWL_EXSTYLE) & WS_EX_LAYOUTRTL)
  69. )
  70. {
  71. ::SetWindowLongPtr (m_pListBox->m_hWnd , GWL_EXSTYLE ,
  72. ::GetWindowLongPtr (m_pListBox->m_hWnd , GWL_EXSTYLE)|
  73. WS_EX_RTLREADING | WS_EX_RIGHT | WS_EX_LEFTSCROLLBAR);
  74. }
  75. }
  76. EnumDateFormats(DateFmtEnumProc, m_id, DATE_SHORTDATE);
  77. EnumDateFormats(DateFmtEnumProc, m_id, DATE_LONGDATE);
  78. EnumTimeFormats(TimeFmtEnumProc, m_id, 0);
  79. m_pListBox = NULL;
  80. m_listBox.SetCurSel(0);
  81. return TRUE; // return TRUE unless you set the focus to a control
  82. // EXCEPTION: OCX Property Pages should return FALSE
  83. }
  84. // The following masks are defined in WinNls.h under #ifdef WINVER>=0x0500. so
  85. // even we included the header file, still we don't see it. I defined it as
  86. // follows.
  87. #ifndef DATE_LTRREADING
  88. #define DATE_LTRREADING 0x00000010
  89. #endif //!DATE_LTRREADING
  90. #ifndef DATE_RTLREADING
  91. #define DATE_RTLREADING 0x00000020
  92. #endif //!DATE_RTLREADING
  93. BOOL CALLBACK CDateDialog::DateFmtEnumProc(LPTSTR lpszFormatString)
  94. {
  95. ASSERT(m_pListBox != NULL);
  96. TCHAR buffer[256];
  97. DWORD dwFlags = 0;
  98. // if we have Arabic/Hebrew locale
  99. if ((PRIMARYLANGID(LANGIDFROMLCID(m_id))== LANG_ARABIC) ||
  100. (PRIMARYLANGID(LANGIDFROMLCID(m_id))== LANG_HEBREW))
  101. {
  102. if (m_pf.wEffects & PFE_RTLPARA)
  103. dwFlags |= DATE_RTLREADING;
  104. else
  105. dwFlags |= DATE_LTRREADING;
  106. }
  107. VERIFY(GetDateFormat(m_id, dwFlags, &m_time, lpszFormatString, buffer, ARRAYSIZE(buffer)));
  108. if ((PRIMARYLANGID(LANGIDFROMLCID(m_id))== LANG_ARABIC) ||
  109. (PRIMARYLANGID(LANGIDFROMLCID(m_id))== LANG_HEBREW))
  110. {
  111. StringCchCat(buffer, ARRAYSIZE(buffer), (m_pf.wEffects & PFE_RTLPARA) ? L"\x200F" : L"\x200E");
  112. // For display purposes only - ok to ignore return value.
  113. }
  114. // Strip leading blanks
  115. TCHAR *buf = buffer;
  116. while (_istspace(*buf))
  117. ++buf;
  118. // we can end up with same format because a format with leading
  119. // zeroes may be the same as one without when a number is big enough
  120. // e.g. 09/10/94 9/10/94 are different but 10/10/94 and 10/10/94 are
  121. // the same
  122. if (m_pListBox->FindStringExact(-1,buf) == CB_ERR)
  123. m_pListBox->AddString(buf);
  124. return TRUE;
  125. }
  126. BOOL CALLBACK CDateDialog::TimeFmtEnumProc(LPTSTR lpszFormatString)
  127. {
  128. ASSERT(m_pListBox != NULL);
  129. TCHAR buffer[256];
  130. TCHAR *buf = buffer;
  131. VERIFY(GetTimeFormat(m_id, 0, &m_time, lpszFormatString, buf, 256));
  132. // Strip leading blanks
  133. while (_istspace(*buf))
  134. ++buf;
  135. // we can end up with same format because a format with leading
  136. // zeroes may be the same as one without when a number is big enough
  137. // e.g. 09/10/94 9/10/94 are different but 10/10/94 and 10/10/94 are
  138. // the same
  139. if (m_pListBox->FindStringExact(-1,buf) == CB_ERR)
  140. m_pListBox->AddString(buf);
  141. return TRUE;
  142. }
  143. void CDateDialog::OnDblclkDatedialogList()
  144. {
  145. OnOK();
  146. }