ReactOS Fundraising Campaign 2012
 
€ 4,410 / € 30,000

Information | Donate

Home | Info | Community | Development | myReactOS | Contact Us

  1. Home
  2. Community
  3. Development
  4. myReactOS
  5. Fundraiser 2012

  1. Main Page
  2. Alphabetical List
  3. Data Structures
  4. Directories
  5. File List
  6. Data Fields
  7. Globals
  8. Related Pages

ReactOS Development > Doxygen

time.c
Go to the documentation of this file.
00001 /*
00002  *  ReactOS
00003  *  Copyright (C) 2004 ReactOS Team
00004  *
00005  *  This program is free software; you can redistribute it and/or modify
00006  *  it under the terms of the GNU General Public License as published by
00007  *  the Free Software Foundation; either version 2 of the License, or
00008  *  (at your option) any later version.
00009  *
00010  *  This program is distributed in the hope that it will be useful,
00011  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013  *  GNU General Public License for more details.
00014  *
00015  *  You should have received a copy of the GNU General Public License along
00016  *  with this program; if not, write to the Free Software Foundation, Inc.,
00017  *  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
00018  */
00019 /*
00020  * PROJECT:         ReactOS International Control Panel
00021  * FILE:            dll/cpl/intl/time.c
00022  * PURPOSE:         Time property page
00023  * PROGRAMMER:      Eric Kohl
00024  */
00025 
00026 #include "intl.h"
00027 
00028 static HWND hwndEnum = NULL;
00029 
00030 static BOOL CALLBACK
00031 TimeFormatEnumProc(LPTSTR lpTimeFormatString)
00032 {
00033     SendMessage(hwndEnum,
00034                 CB_ADDSTRING,
00035                 0,
00036                 (LPARAM)lpTimeFormatString);
00037 
00038     return TRUE;
00039 }
00040 
00041 static VOID
00042 UpdateTimeSample(HWND hWnd, LCID lcid)
00043 {
00044     TCHAR szBuffer[80];
00045 
00046     GetTimeFormat(lcid, 0, NULL, NULL, szBuffer, 80);
00047     SendMessage(hWnd, WM_SETTEXT, 0, (LPARAM)szBuffer);
00048 }
00049 
00050 
00051 static VOID
00052 GetSelectedComboEntry(HWND hwndDlg, DWORD dwIdc, TCHAR *Buffer, UINT uSize)
00053 {
00054     int nIndex;
00055     HWND hChildWnd;
00056 
00057     /* Get handle to time format control */
00058     hChildWnd = GetDlgItem(hwndDlg, dwIdc);
00059     /* Get index to selected time format */
00060     nIndex = SendMessage(hChildWnd, CB_GETCURSEL, 0, 0);
00061     if (nIndex == CB_ERR)
00062         /* No selection? Get content of the edit control */
00063         SendMessage(hChildWnd, WM_GETTEXT, uSize, (LPARAM)Buffer);
00064     else {
00065         LPTSTR tmp;
00066         UINT   uReqSize;
00067 
00068         /* Get requested size, including the null terminator;
00069          * it shouldn't be required because the previous CB_LIMITTEXT,
00070          * but it would be better to check it anyways */
00071         uReqSize = SendMessage(hChildWnd, CB_GETLBTEXTLEN, (WPARAM)nIndex, 0) + 1;
00072         /* Allocate enough space to be more safe */
00073         tmp = (LPTSTR)_alloca(uReqSize*sizeof(TCHAR));
00074         /* Get selected time format text */
00075         SendMessage(hChildWnd, CB_GETLBTEXT, (WPARAM)nIndex, (LPARAM)tmp);
00076         /* Finally, copy the result into the output */
00077         _tcsncpy(Buffer, tmp, uSize);
00078     }
00079 }
00080 
00081 /* Property page dialog callback */
00082 INT_PTR CALLBACK
00083 TimePageProc(HWND hwndDlg,
00084              UINT uMsg,
00085              WPARAM wParam,
00086              LPARAM lParam)
00087 {
00088     PGLOBALDATA pGlobalData;
00089 
00090     pGlobalData = (PGLOBALDATA)GetWindowLongPtr(hwndDlg, DWLP_USER);
00091 
00092     switch (uMsg)
00093     {
00094         case WM_INITDIALOG:
00095         {
00096             TCHAR Buffer[80];
00097             int nLen;
00098 
00099             pGlobalData = (PGLOBALDATA)((LPPROPSHEETPAGE)lParam)->lParam;
00100             SetWindowLongPtr(hwndDlg, DWLP_USER, (LONG_PTR)pGlobalData);
00101 
00102             /* Update the time format sample */
00103             UpdateTimeSample(GetDlgItem(hwndDlg, IDC_TIMESAMPLE), pGlobalData->lcid);
00104 
00105             /* Get the time format */
00106             SendMessage(GetDlgItem(hwndDlg, IDC_TIMEFORMAT),
00107                         CB_LIMITTEXT, MAX_TIMEFORMAT, 0);
00108 
00109             /* Add available time formats to the list */
00110             hwndEnum = GetDlgItem(hwndDlg, IDC_TIMEFORMAT);
00111             EnumTimeFormats(TimeFormatEnumProc, pGlobalData->lcid, 0);
00112 
00113             GetLocaleInfo(pGlobalData->lcid, LOCALE_STIMEFORMAT, Buffer, sizeof(Buffer)/sizeof(TCHAR));
00114             SendMessage(GetDlgItem(hwndDlg, IDC_TIMEFORMAT),
00115                         CB_SELECTSTRING,
00116                         -1,
00117                         (LPARAM)Buffer);
00118 
00119             /* Get the time separator */
00120             SendMessage(GetDlgItem(hwndDlg, IDC_TIMESEPARATOR),
00121                         CB_LIMITTEXT, MAX_TIMESEPARATOR, 0);
00122             GetLocaleInfo(pGlobalData->lcid, LOCALE_STIME, Buffer, sizeof(Buffer)/sizeof(TCHAR));
00123             SendMessage(GetDlgItem(hwndDlg, IDC_TIMESEPARATOR),
00124                         CB_ADDSTRING,
00125                         0,
00126                         (LPARAM)Buffer);
00127             SendMessage(GetDlgItem(hwndDlg, IDC_TIMESEPARATOR),
00128                         CB_SETCURSEL,
00129                         0, /* Index */
00130                         0);
00131 
00132             /* Get the AM symbol */
00133             SendMessage(GetDlgItem(hwndDlg, IDC_TIMEAMSYMBOL),
00134                         CB_LIMITTEXT, MAX_TIMEAMSYMBOL, 0);
00135             nLen = GetLocaleInfo(pGlobalData->lcid, LOCALE_S1159, Buffer, sizeof(Buffer)/sizeof(TCHAR));
00136             SendMessage(GetDlgItem(hwndDlg, IDC_TIMEAMSYMBOL),
00137                         CB_ADDSTRING,
00138                         0,
00139                         (LPARAM)Buffer);
00140             if (nLen != 0)
00141             {
00142                 SendMessage(GetDlgItem(hwndDlg, IDC_TIMEAMSYMBOL),
00143                             CB_ADDSTRING,
00144                             0,
00145                             (LPARAM)_T(""));
00146             }
00147             SendMessage(GetDlgItem(hwndDlg, IDC_TIMEAMSYMBOL),
00148                         CB_SETCURSEL,
00149                         0, /* Index */
00150                         0);
00151 
00152             /* Get the PM symbol */
00153             SendMessage(GetDlgItem(hwndDlg, IDC_TIMEPMSYMBOL),
00154                         CB_LIMITTEXT, MAX_TIMEPMSYMBOL, 0);
00155             nLen = GetLocaleInfo(pGlobalData->lcid, LOCALE_S2359, Buffer, sizeof(Buffer)/sizeof(TCHAR));
00156             SendMessage(GetDlgItem(hwndDlg, IDC_TIMEPMSYMBOL),
00157                         CB_ADDSTRING,
00158                         0,
00159                         (LPARAM)Buffer);
00160             if (nLen != 0)
00161             {
00162                 SendMessage(GetDlgItem(hwndDlg, IDC_TIMEPMSYMBOL),
00163                            CB_ADDSTRING,
00164                            0,
00165                            (LPARAM)_T(""));
00166             }
00167             SendMessage(GetDlgItem(hwndDlg, IDC_TIMEPMSYMBOL),
00168                         CB_SETCURSEL,
00169                         0, /* Index */
00170                         0);
00171         }
00172         break;
00173 
00174         case WM_COMMAND:
00175             switch (LOWORD(wParam))
00176             {
00177                 case IDC_TIMEFORMAT:
00178                 case IDC_TIMESEPARATOR:
00179                 case IDC_TIMEAMSYMBOL:
00180                 case IDC_TIMEPMSYMBOL:
00181                     if (HIWORD(wParam) == CBN_SELCHANGE ||
00182                         HIWORD(wParam) == CBN_EDITCHANGE)
00183                     {
00184                         PropSheet_Changed(GetParent(hwndDlg), hwndDlg);
00185                     }
00186                 break;
00187             }
00188             break;
00189 
00190         case WM_NOTIFY:
00191         {
00192             LPNMHDR lpnm = (LPNMHDR)lParam;
00193 
00194             if (lpnm->code == (UINT)PSN_APPLY)
00195             {
00196                 TCHAR Buffer[80];
00197 
00198                 /* Get selected/typed time format text */
00199                 GetSelectedComboEntry(hwndDlg, IDC_TIMEFORMAT, Buffer, sizeof(Buffer)/sizeof(TCHAR));
00200 
00201                 /* Set time format */
00202                 SetLocaleInfo(pGlobalData->lcid, LOCALE_STIMEFORMAT, Buffer);
00203 
00204                 /* Get selected/typed time separator text */
00205                 GetSelectedComboEntry(hwndDlg, IDC_TIMESEPARATOR, Buffer, sizeof(Buffer)/sizeof(TCHAR));
00206 
00207                 /* Set time separator */
00208                 SetLocaleInfo(pGlobalData->lcid, LOCALE_STIME, Buffer);
00209 
00210                 /* Get selected/typed AM symbol text */
00211                 GetSelectedComboEntry(hwndDlg, IDC_TIMEAMSYMBOL, Buffer, sizeof(Buffer)/sizeof(TCHAR));
00212 
00213                 /* Set the AM symbol */
00214                 SetLocaleInfo(pGlobalData->lcid, LOCALE_S1159, Buffer);
00215 
00216                 /* Get selected/typed PM symbol text */
00217                 GetSelectedComboEntry(hwndDlg, IDC_TIMEPMSYMBOL, Buffer, sizeof(Buffer)/sizeof(TCHAR));
00218 
00219                 /* Set the PM symbol */
00220                 SetLocaleInfo(pGlobalData->lcid, LOCALE_S2359, Buffer);
00221 
00222                 /* Update the time format sample */
00223                 UpdateTimeSample(GetDlgItem(hwndDlg, IDC_TIMESAMPLE), pGlobalData->lcid);
00224             }
00225         }
00226         break;
00227     }
00228 
00229     return FALSE;
00230 }
00231 
00232 /* EOF */

Generated on Sun May 27 2012 04:18:15 for ReactOS by doxygen 1.7.6.1

ReactOS is a registered trademark or a trademark of ReactOS Foundation in the United States and other countries.