ReactOS 0.4.15-dev-6644-g539123c
misc.c File Reference
#include "intl.h"
Include dependency graph for misc.c:

Go to the source code of this file.

Functions

PWSTR InsSpacePos (PCWSTR szInsStr, const int nPos)
 
PWSTR InsSpacesFmt (PCWSTR szSourceStr, PCWSTR szFmtStr)
 
PWSTR ReplaceSubStr (PCWSTR szSourceStr, PCWSTR szStrToReplace, PCWSTR szTempl)
 
VOID GetSelectedComboBoxText (HWND hwndDlg, INT nIdDlgItem, PWSTR Buffer, UINT uSize)
 
VOID GetSelectedComboBoxIndex (HWND hwndDlg, INT nIdDlgItem, PINT pValue)
 

Function Documentation

◆ GetSelectedComboBoxIndex()

VOID GetSelectedComboBoxIndex ( HWND  hwndDlg,
INT  nIdDlgItem,
PINT  pValue 
)

Definition at line 223 of file misc.c.

227{
228 *pValue = SendDlgItemMessageW(hwndDlg, nIdDlgItem, CB_GETCURSEL, 0, 0);
229}
PWCHAR pValue
LRESULT WINAPI SendDlgItemMessageW(_In_ HWND, _In_ int, _In_ UINT, _In_ WPARAM, _In_ LPARAM)
#define CB_GETCURSEL
Definition: winuser.h:1933

Referenced by GetCurrencySetting(), and GetNumberSetting().

◆ GetSelectedComboBoxText()

VOID GetSelectedComboBoxText ( HWND  hwndDlg,
INT  nIdDlgItem,
PWSTR  Buffer,
UINT  uSize 
)

Definition at line 176 of file misc.c.

181{
182 HWND hChildWnd;
183 PWSTR tmp;
184 INT nIndex;
185 UINT uReqSize;
186
187 /* Get handle to time format control */
188 hChildWnd = GetDlgItem(hwndDlg, nIdDlgItem);
189 if (hChildWnd == NULL)
190 return;
191
192 /* Get index to selected time format */
193 nIndex = SendMessageW(hChildWnd, CB_GETCURSEL, 0, 0);
194 if (nIndex == CB_ERR)
195 {
196 /* No selection? Get content of the edit control */
197 SendMessageW(hChildWnd, WM_GETTEXT, uSize, (LPARAM)Buffer);
198 }
199 else
200 {
201 /* Get requested size, including the null terminator;
202 * it shouldn't be required because the previous CB_LIMITTEXT,
203 * but it would be better to check it anyways */
204 uReqSize = SendMessageW(hChildWnd, CB_GETLBTEXTLEN, (WPARAM)nIndex, 0) + 1;
205
206 /* Allocate enough space to be more safe */
207 tmp = (PWSTR)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, uReqSize * sizeof(WCHAR));
208 if (tmp != NULL)
209 {
210 /* Get selected time format text */
211 SendMessageW(hChildWnd, CB_GETLBTEXT, (WPARAM)nIndex, (LPARAM)tmp);
212
213 /* Finally, copy the result into the output */
214 wcsncpy(Buffer, tmp, uSize);
215
216 HeapFree(GetProcessHeap(), 0, tmp);
217 }
218 }
219}
Definition: bufpool.h:45
#define NULL
Definition: types.h:112
#define GetProcessHeap()
Definition: compat.h:736
#define HeapAlloc
Definition: compat.h:733
#define HeapFree(x, y, z)
Definition: compat.h:735
#define HEAP_ZERO_MEMORY
Definition: compat.h:134
unsigned int UINT
Definition: ndis.h:50
_CRTIMP wchar_t *__cdecl wcsncpy(wchar_t *_Dest, const wchar_t *_Source, size_t _Count)
uint16_t * PWSTR
Definition: typedefs.h:56
int32_t INT
Definition: typedefs.h:58
LONG_PTR LPARAM
Definition: windef.h:208
UINT_PTR WPARAM
Definition: windef.h:207
#define CB_GETLBTEXTLEN
Definition: winuser.h:1943
#define CB_GETLBTEXT
Definition: winuser.h:1942
#define CB_ERR
Definition: winuser.h:2425
#define WM_GETTEXT
Definition: winuser.h:1608
HWND WINAPI GetDlgItem(_In_opt_ HWND, _In_ int)
LRESULT WINAPI SendMessageW(_In_ HWND, _In_ UINT, _In_ WPARAM, _In_ LPARAM)
__wchar_t WCHAR
Definition: xmlstorage.h:180

Referenced by GetCurrencySetting(), GetNumberSetting(), and GetTimeSetting().

◆ InsSpacePos()

PWSTR InsSpacePos ( PCWSTR  szInsStr,
const int  nPos 
)

Definition at line 5 of file misc.c.

6{
7 PWSTR pszDestStr;
8 INT nDestStrCnt = 0;
9 INT nStrCnt;
10 INT nStrSize;
11
12 pszDestStr = (PWSTR)HeapAlloc(GetProcessHeap(), 0, MAX_SAMPLES_STR_SIZE * sizeof(WCHAR));
13 if (pszDestStr == NULL)
14 return NULL;
15
16 wcscpy(pszDestStr, szInsStr);
17
18 nStrSize = wcslen(szInsStr);
19
20 for (nStrCnt = 0; nStrCnt < nStrSize; nStrCnt++)
21 {
22 if (nStrCnt == nStrSize - nPos)
23 {
24 pszDestStr[nDestStrCnt] = L' ';
25 nDestStrCnt++;
26 }
27
28 pszDestStr[nDestStrCnt] = szInsStr[nStrCnt];
29 nDestStrCnt++;
30 }
31
32 pszDestStr[nDestStrCnt] = L'\0';
33
34 return pszDestStr;
35}
_CRTIMP size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
#define MAX_SAMPLES_STR_SIZE
Definition: intl.h:24
#define L(x)
Definition: ntvdm.h:50
_CRTIMP wchar_t *__cdecl wcscpy(_Out_writes_z_(_String_length_(_Source)+1) wchar_t *_Dest, _In_z_ const wchar_t *_Source)

Referenced by InsSpacesFmt().

◆ InsSpacesFmt()

PWSTR InsSpacesFmt ( PCWSTR  szSourceStr,
PCWSTR  szFmtStr 
)

Definition at line 39 of file misc.c.

40{
41 PWSTR pszDestStr;
42 PWSTR pszTempStr;
43 WCHAR szFmtVal[255];
44 UINT nFmtCount = 0;
45 INT nValCount = 0;
46 INT nLastVal = 0;
47 INT nSpaceOffset = 0;
48 BOOL wasNul=FALSE;
49
50 pszDestStr = (PWSTR)HeapAlloc(GetProcessHeap(), 0, 255 * sizeof(WCHAR));
51 if (pszDestStr == NULL)
52 return NULL;
53
54 wcscpy(pszDestStr, szSourceStr);
55
56 /* If format is clean return source string */
57 if (!*szFmtStr)
58 return pszDestStr;
59
60 /* Search for all format values */
61 for (nFmtCount = 0; nFmtCount <= wcslen(szFmtStr); nFmtCount++)
62 {
63 if (szFmtStr[nFmtCount] == L';' || szFmtStr[nFmtCount] == L'\0')
64 {
65 if (_wtoi(szFmtVal) == 0 && !wasNul)
66 {
67 wasNul=TRUE;
68 break;
69 }
70
71 /* If was 0, repeat spaces */
72 if (wasNul)
73 {
74 nSpaceOffset += nLastVal;
75 }
76 else
77 {
78 nSpaceOffset += _wtoi(szFmtVal);
79 }
80
81 szFmtVal[nValCount] = L'\0';
82 nValCount=0;
83
84 /* Insert space to finded position plus all pos before */
85 pszTempStr = InsSpacePos(pszDestStr, nSpaceOffset);
86 wcscpy(pszDestStr,pszTempStr);
87 HeapFree(GetProcessHeap(), 0, pszTempStr);
88
89 /* Num of spaces total increment */
90 if (!wasNul)
91 {
92 nSpaceOffset++;
93 nLastVal = _wtoi(szFmtVal);
94 }
95 }
96 else
97 {
98 szFmtVal[nValCount++] = szFmtStr[nFmtCount];
99 }
100 }
101
102 /* Create spaces for rest part of string */
103 if (wasNul && nLastVal != 0)
104 {
105 for (nFmtCount = nSpaceOffset + nLastVal; nFmtCount < wcslen(pszDestStr); nFmtCount += nLastVal + 1)
106 {
107 pszTempStr = InsSpacePos(pszDestStr, nFmtCount);
108 wcscpy(pszDestStr, pszTempStr);
109 HeapFree(GetProcessHeap(), 0, pszTempStr);
110 }
111 }
112
113 return pszDestStr;
114}
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
PWSTR InsSpacePos(PCWSTR szInsStr, const int nPos)
Definition: misc.c:5
unsigned int BOOL
Definition: ntddk_ex.h:94
_Check_return_ _CRTIMP int __cdecl _wtoi(_In_z_ const wchar_t *_Str)

Referenced by InitFieldDigNumCB().

◆ ReplaceSubStr()

PWSTR ReplaceSubStr ( PCWSTR  szSourceStr,
PCWSTR  szStrToReplace,
PCWSTR  szTempl 
)

Definition at line 118 of file misc.c.

121{
122 PWSTR szDestStr;
123 UINT nCharCnt;
124 UINT nSubStrCnt;
125 UINT nDestStrCnt;
126 UINT nFirstCharCnt;
127
128 szDestStr = (PWSTR)HeapAlloc(GetProcessHeap(), 0, MAX_SAMPLES_STR_SIZE * sizeof(WCHAR));
129 if (szDestStr == NULL)
130 return NULL;
131
132 nDestStrCnt = 0;
133 nFirstCharCnt = 0;
134
135 wcscpy(szDestStr, L"");
136
137 while (nFirstCharCnt < wcslen(szSourceStr))
138 {
139 if (szSourceStr[nFirstCharCnt] == szTempl[0])
140 {
141 nSubStrCnt = 0;
142 for (nCharCnt = nFirstCharCnt; nCharCnt < nFirstCharCnt + wcslen(szTempl); nCharCnt++)
143 {
144 if (szSourceStr[nCharCnt] == szTempl[nSubStrCnt])
145 {
146 nSubStrCnt++;
147 }
148 else
149 {
150 break;
151 }
152
153 if (wcslen(szTempl) == nSubStrCnt)
154 {
155 wcscat(szDestStr, szStrToReplace);
156 nDestStrCnt = wcslen(szDestStr);
157 nFirstCharCnt += wcslen(szTempl) - 1;
158 break;
159 }
160 }
161 }
162 else
163 {
164 szDestStr[nDestStrCnt++] = szSourceStr[nFirstCharCnt];
165 szDestStr[nDestStrCnt] = L'\0';
166 }
167
168 nFirstCharCnt++;
169 }
170
171 return szDestStr;
172}
_CRTIMP wchar_t *__cdecl wcscat(_Inout_updates_z_(_String_length_(_Dest)+_String_length_(_Source)+1) wchar_t *_Dest, _In_z_ const wchar_t *_Source)

Referenced by InitLeadingZeroesCB(), InitNegNumFmtCB(), and SetShortDateFormat().