diff -u -N -r source-old/base/applications/wordpad/En.rc source/base/applications/wordpad/En.rc --- source-old/base/applications/wordpad/En.rc Sun Apr 18 12:56:14 2010 +++ source/base/applications/wordpad/En.rc Tue May 4 07:47:11 2010 @@ -240,6 +240,9 @@ STRING_PREVIEW_PAGE, "Page" STRING_PREVIEW_PAGES, "Pages" STRING_UNITS_CM, "cm" + STRING_UNITS_IN, "in" + STRING_UNITS_INCH, "inch" + STRING_UNITS_PT, "pt" END STRINGTABLE DISCARDABLE diff -u -N -r source-old/base/applications/wordpad/wordpad.c source/base/applications/wordpad/wordpad.c --- source-old/base/applications/wordpad/wordpad.c Sun Apr 18 12:56:14 2010 +++ source/base/applications/wordpad/wordpad.c Tue May 4 11:16:01 2010 @@ -76,11 +76,24 @@ static WCHAR wszDefaultFileName[MAX_STRING_LEN]; static WCHAR wszSaveChanges[MAX_STRING_LEN]; static WCHAR units_cmW[MAX_STRING_LEN]; +static WCHAR units_inW[MAX_STRING_LEN]; +static WCHAR units_inchW[MAX_STRING_LEN]; +static WCHAR units_ptW[MAX_STRING_LEN]; static char units_cmA[MAX_STRING_LEN]; +static char units_inA[MAX_STRING_LEN]; +static char units_inchA[MAX_STRING_LEN]; +static char units_ptA[MAX_STRING_LEN]; static LRESULT OnSize( HWND hWnd, WPARAM wParam, LPARAM lParam ); +typedef enum +{ + UNIT_CM, + UNIT_INCH, + UNIT_PT +} UNIT; + /* Load string resources */ static void DoLoadStrings(void) { @@ -117,6 +130,12 @@ LoadStringA(hInstance, STRING_UNITS_CM, units_cmA, MAX_STRING_LEN); LoadStringW(hInstance, STRING_UNITS_CM, units_cmW, MAX_STRING_LEN); + LoadStringA(hInstance, STRING_UNITS_IN, units_inA, MAX_STRING_LEN); + LoadStringW(hInstance, STRING_UNITS_IN, units_inW, MAX_STRING_LEN); + LoadStringA(hInstance, STRING_UNITS_INCH, units_inchA, MAX_STRING_LEN); + LoadStringW(hInstance, STRING_UNITS_INCH, units_inchW, MAX_STRING_LEN); + LoadStringA(hInstance, STRING_UNITS_PT, units_ptA, MAX_STRING_LEN); + LoadStringW(hInstance, STRING_UNITS_PT, units_ptW, MAX_STRING_LEN); } /* Show a message box with resource strings */ @@ -239,8 +258,10 @@ HeapFree(GetProcessHeap(), 0, wszCaption); } -static BOOL validate_endptr(LPCSTR endptr, BOOL units) +static BOOL validate_endptr(LPCSTR endptr, BOOL units, UNIT *punit) { + if (punit != NULL) + *punit = UNIT_CM; if(!endptr) return FALSE; if(!*endptr) @@ -252,25 +273,44 @@ if(!units) return *endptr == '\0'; - /* FIXME: Allow other units and convert between them */ if(!lstrcmpA(endptr, units_cmA)) + { + if (punit != NULL) *punit = UNIT_CM; + endptr += 2; + } + else if (!lstrcmpA(endptr, units_inA)) + { + if (punit != NULL) *punit = UNIT_INCH; + endptr += 2; + } + else if (!lstrcmpA(endptr, units_inchA)) + { + if (punit != NULL) *punit = UNIT_INCH; + endptr += 4; + } + else if (!lstrcmpA(endptr, units_ptA)) + { + if (punit != NULL) *punit = UNIT_PT; endptr += 2; + } return *endptr == '\0'; } -static BOOL number_from_string(LPCWSTR string, float *num, BOOL units) +static BOOL number_from_string(LPCWSTR string, float *num, BOOL units, UNIT *punit) { double ret; char buffer[MAX_STRING_LEN]; char *endptr = buffer; + if (punit != NULL) *punit = UNIT_CM; + WideCharToMultiByte(CP_ACP, 0, string, -1, buffer, MAX_STRING_LEN, NULL, NULL); *num = 0; errno = 0; ret = strtod(buffer, &endptr); - if((ret == 0 && errno != 0) || endptr == buffer || !validate_endptr(endptr, units)) + if((ret == 0 && errno != 0) || endptr == buffer || !validate_endptr(endptr, units, punit)) { return FALSE; } else @@ -304,7 +344,7 @@ if(lstrcmpW(sizeBuffer, wszNewFontSize)) { float size = 0; - if(number_from_string(wszNewFontSize, &size, FALSE) + if(number_from_string(wszNewFontSize, &size, FALSE, NULL) && size > 0) { set_size(size); @@ -1304,9 +1344,24 @@ hFindWnd = FindTextW(fr); } -static int current_units_to_twips(float number) +static int units_to_twips(UNIT unit, float number) { - int twips = (int)(number * 1000.0 / (float)CENTMM_PER_INCH * (float)TWIPS_PER_INCH); + int twips; + + switch(unit) + { + case UNIT_CM: + twips = (int)(number * 1000.0 / (float)CENTMM_PER_INCH * (float)TWIPS_PER_INCH); + break; + + case UNIT_INCH: + twips = (int)(number * (float)TWIPS_PER_INCH); + break; + + case UNIT_PT: + twips = (int)(number * (0.0138 * (float)TWIPS_PER_INCH)); + break; + } return twips; } @@ -1321,7 +1376,6 @@ { static const WCHAR fmt[] = {'%','.','2','f',' ','%','s','\0'}; float converted = (float)number / (float)TWIPS_PER_INCH *(float)CENTMM_PER_INCH / 1000.0; - sprintfW(buffer, fmt, converted, units_cmW); } @@ -1515,22 +1569,23 @@ float num; int ret = 0; PARAFORMAT pf; + UNIT unit; index = SendMessageW(hListWnd, CB_GETCURSEL, 0, 0); pf.wAlignment = ALIGNMENT_VALUES[index]; GetWindowTextW(hLeftWnd, buffer, MAX_STRING_LEN); - if(number_from_string(buffer, &num, TRUE)) + if(number_from_string(buffer, &num, TRUE, &unit)) ret++; - pf.dxOffset = current_units_to_twips(num); + pf.dxOffset = units_to_twips(unit, num); GetWindowTextW(hRightWnd, buffer, MAX_STRING_LEN); - if(number_from_string(buffer, &num, TRUE)) + if(number_from_string(buffer, &num, TRUE, &unit)) ret++; - pf.dxRightIndent = current_units_to_twips(num); + pf.dxRightIndent = units_to_twips(unit, num); GetWindowTextW(hFirstWnd, buffer, MAX_STRING_LEN); - if(number_from_string(buffer, &num, TRUE)) + if(number_from_string(buffer, &num, TRUE, &unit)) ret++; - pf.dxStartIndent = current_units_to_twips(num); + pf.dxStartIndent = units_to_twips(unit, num); if(ret != 3) { @@ -1636,6 +1691,7 @@ { HWND hTabWnd = GetDlgItem(hWnd, IDC_TABSTOPS); WCHAR buffer[MAX_STRING_LEN]; + UNIT unit; GetWindowTextW(hTabWnd, buffer, MAX_STRING_LEN); append_current_units(buffer); @@ -1645,7 +1701,7 @@ float number = 0; int item_count = SendMessage(hTabWnd, CB_GETCOUNT, 0, 0); - if(!number_from_string(buffer, &number, TRUE)) + if(!number_from_string(buffer, &number, TRUE, &unit)) { MessageBoxWithResStringW(hWnd, MAKEINTRESOURCEW(STRING_INVALID_NUMBER), wszAppTitle, MB_OK | MB_ICONINFORMATION); @@ -1656,14 +1712,14 @@ int i; float next_number = -1; int next_number_in_twips = -1; - int insert_number = current_units_to_twips(number); + int insert_number = units_to_twips(unit, number); /* linear search for position to insert the string */ for(i = 0; i < item_count; i++) { SendMessageW(hTabWnd, CB_GETLBTEXT, i, (LPARAM)&buffer); - number_from_string(buffer, &next_number, TRUE); - next_number_in_twips = current_units_to_twips(next_number); + number_from_string(buffer, &next_number, TRUE, &unit); + next_number_in_twips = units_to_twips(unit, next_number); if (insert_number <= next_number_in_twips) break; } @@ -1704,6 +1760,7 @@ WCHAR buffer[MAX_STRING_LEN]; PARAFORMAT pf; float number; + UNIT unit; pf.cbSize = sizeof(pf); pf.dwMask = PFM_TABSTOPS; @@ -1712,8 +1769,8 @@ (LPARAM)&buffer) != CB_ERR && i < MAX_TAB_STOPS; i++) { - number_from_string(buffer, &number, TRUE); - pf.rgxTabs[i] = current_units_to_twips(number); + number_from_string(buffer, &number, TRUE, &unit); + pf.rgxTabs[i] = units_to_twips(unit, number); } pf.cTabCount = i; SendMessageW(hEditorWnd, EM_SETPARAFORMAT, 0, (LPARAM)&pf); diff -u -N -r source-old/base/applications/wordpad/wordpad.h source/base/applications/wordpad/wordpad.h --- source-old/base/applications/wordpad/wordpad.h Sun Apr 18 12:56:14 2010 +++ source/base/applications/wordpad/wordpad.h Tue May 4 07:54:24 2010 @@ -222,6 +222,9 @@ #define STRING_PREVIEW_PAGES 1457 #define STRING_UNITS_CM 1458 +#define STRING_UNITS_IN 1459 +#define STRING_UNITS_INCH 1460 +#define STRING_UNITS_PT 1461 #define STRING_DEFAULT_FILENAME 1700 #define STRING_PROMPT_SAVE_CHANGES 1701