| 1888 | |
| 1889 | |
| 1890 | ResultType GuiType::ControlSetDateTimeFormat(GuiControlType &aControl, LPTSTR aFormat, ResultToken &aResultToken) |
| 1891 | { |
| 1892 | bool use_custom_format = false; // Set default. |
| 1893 | // Reset style to "pure" so that new style (or custom format) can take effect. |
| 1894 | DWORD style = GetWindowLong(aControl.hwnd, GWL_STYLE) // DTS_SHORTDATEFORMAT==0 so can be omitted below. |
| 1895 | & ~(DTS_LONGDATEFORMAT | DTS_SHORTDATECENTURYFORMAT | DTS_TIMEFORMAT); |
| 1896 | if (*aFormat) |
| 1897 | { |
| 1898 | // DTS_SHORTDATEFORMAT and DTS_SHORTDATECENTURYFORMAT |
| 1899 | // seem to produce identical results (both display 4-digit year), at least on XP. Perhaps |
| 1900 | // DTS_SHORTDATECENTURYFORMAT is obsolete. In any case, it's uncommon so for simplicity, is |
| 1901 | // not a named style. It can always be applied numerically if desired. Update: |
| 1902 | // DTS_SHORTDATECENTURYFORMAT is now applied by default upon creation, which can be overridden |
| 1903 | // explicitly via -0x0C in the control's options. |
| 1904 | if (!_tcsicmp(aFormat, _T("LongDate"))) // LongDate seems more readable than "Long". It also matches the keyword used by FormatTime. |
| 1905 | style |= DTS_LONGDATEFORMAT; // Competing styles were already purged above. |
| 1906 | else if (!_tcsicmp(aFormat, _T("Time"))) |
| 1907 | style |= DTS_TIMEFORMAT; // Competing styles were already purged above. |
| 1908 | else if (!_tcsicmp(aFormat, _T("ShortDate"))) |
| 1909 | {} // No change needed since DTS_SHORTDATEFORMAT is 0 and competing styles were already purged above. |
| 1910 | else // Custom format. |
| 1911 | use_custom_format = true; |
| 1912 | } |
| 1913 | //else aText is blank and use_custom_format==false, which will put DTS_SHORTDATEFORMAT into effect. |
| 1914 | if (!use_custom_format) |
| 1915 | SetWindowLong(aControl.hwnd, GWL_STYLE, style); |
| 1916 | //else leave style unchanged so that if format is later removed, the underlying named style will |
| 1917 | // not have been altered. |
| 1918 | DateTime_SetFormat(aControl.hwnd, use_custom_format ? aFormat : NULL); // NULL removes any custom format so that the underlying style format is revealed. |
| 1919 | return OK; |
| 1920 | } |
| 1921 | |
| 1922 | |
| 1923 | ResultType GuiType::ControlGetDateTime(ResultToken &aResultToken, GuiControlType &aControl) |